mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
I posted this about 3 years ago, and I notice that it has long since left these forums... but with the advice of a few people in #mIRC, I'm posting it again.

I would like permission to access mIRC's callstack. That is, like $event and $ctimer, I want to be able to tell what Alias called the current alias/function. This is mainly for debugging purposes, but also for Anti-viral purposes in assisting a user with the detection and removal of undesirable code/scripts.

Certainly, mIRC must already keep a callstack, or else it wouldn't know what alias and line number to return to after it finishes processing a called sub-alias. So accessing this information doesn't seem as if it should be very difficult.

___ HELP ENTRY: ___

$calias
Returns the name of the alias presently being executed.
example: echo -s DEBUG! Alias: $calias - Line: $scriptline

$calias(N)
Returns the Nth parent alias in the callstack hierarchy. If N = 0 then the number of nested alias generations is returned. If a negative value is given, then the callstack is read in reverse.
$calias(-1) would return the present alias's immediate parent.

Properties: .fname, .ln, .local, .rcsv, .type

fname - returns the name of the script file
ln - returns the line number of the file in which the alias is presently stopped on, until the child alias returns
local - returns $true if ALIAS -l was used, making the alias local
rcsv - returns $true if ALIAS -r was used, making the alias recursive wink
type - returns 'remote' or 'alias' depending on which section the alias resides in

Examples:

echo -s *** $iif($ctimer,Timer: $ctimer,$iif($event, Event: $event, User Input)) -> $calias(1) -> $calias(2) -> $calias(3)

Alias UNSETALL { echo 4 -s *** UNSETALL attempt by $calias(-1) on line $calias(-1).ln in file $calias(-1).fname loaded under the $calias(-1).type section. | BEEP 99 | HALT }

- Raccoon

What do you think?


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Feb 2003
Posts: 309
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Feb 2003
Posts: 309
That would be very usefull - but viruii could get around it easily. I can think of a million other uses for it... like... well... its still a great idea...

Joined: Jan 2003
Posts: 52
L
Babel fish
Offline
Babel fish
L
Joined: Jan 2003
Posts: 52
This is a great idea and should be implemented as the "main" new feature in the next mIRC, just as SIGNALS or Multi Server were in the past in their respective version releases.

This could be very useful for any scripter, beginner to advanced. As a solution to not being able to sufficiently catch internel mIRC Errors, this script could be used to process a custom alias (such as echo) to do checks to see if it will error the internal /!echo once it is called, and if it will error, then to echo an appropriate error about the alias which called the custom alias (echo).

Example:
/alias test echo $1-
/alias echo !echo $1-
-
* Added 'test' alias
-
/test 8
-
* /echo: insufficient parameters (line 2, aliases.ini)
-
In this example, it errors where the internal echo is called, on line 2 of the aliases file, when it should error on line 1. This reveals nothing in the way of debugging a script, if the custom alias is used in several hundreds of places. With Raccoon's idea, the echo alias could be checked for proper syntax and if it did not have the proper syntax then to echo an error with the line that called that alias:

alias test echo $1-
alias echo {
if (PROPER SYNTAX CHECKS) { !echo $1- }
else { !echo -a / $+ $calias Insufficient parameters ($calias(-1).fname $+ , $calias(-1).ln) }
}

OFF TOPIC: As an extension to the "PROPER SYNTAX CHECKS" maybe an alias to check if calling an alias with certain parameters will return an error or not?

As for the virus detection idea, It is a very good use for this, although the $calias would need to support returning if the alias was called via DDE or a DLL I suppose.





Last edited by lordares; 08/05/03 11:12 PM.
Joined: Feb 2003
Posts: 309
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Feb 2003
Posts: 309
mIRC doesn't deal with overloading very well, infact it only does in a very limted (perhaps unintention) manner.

Local aliases (in remotes) overwrite all other aliases
Aliases overwrite all other aliases bar local aliases
Remote aliases overwrite commands
Commands don't overwrite nuffn.

So, you can do this:
alias -l script_name {
return Coool Addon by LamerDood
}
and in aliases have:
script_name {
return Coool Script by LamerDood
}

So any other code that uses $script_name gets a default alias or a local alias.

But what if you want to call the default script_name alias? You can't as mIRC sees this as recursion (whihc is a no no).
alias -l script_name {
;This is a no no
;We'd expect this to return
;Coool Addon by LamerDood; using Coool Script by LamerDood
return Coool Addon by LamerDood; using $script_name
}

Same problem with exists with vars, but *shrug*, this isn't about them.

So, maybe we could have $calias().type, and some prefix or command for calling the ORIGINAL alias. But, there is a workaround too:
mydo { $1- }

Its not perfect though. Far from it. $calias().type would be useful for:
alias monkey {
if ($calias().type == local) {
return This method can only be called from PUBLIC methods!
}
}
alias monkey2 {
if ($calias().type == global) {
return This method can only be called from PRIVATE methods!
}
}
You would have much more flexibility in controlling what can and can't play with your script.

Joined: Dec 2003
Posts: 61
A
Babel fish
Offline
Babel fish
A
Joined: Dec 2003
Posts: 61
Or something like "referance alias ($ralais)" and "referance scriptline ($rscriptline)" and "referance script ($rscript)" from the alias + script + scriptline that activated the alias.
That would be nice smile

Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Naa, I like my version better. smile

It would allow you to traverse the entire call-stack, giving access to all of this info and more.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Feb 2004
Posts: 10
K
Pikka bird
Offline
Pikka bird
K
Joined: Feb 2004
Posts: 10
well, apparently it's not on the priority list... :tongue:


Link Copied to Clipboard