PDA

View Full Version : [plugin] OllyScript v0.2


psyCK0
January 14th, 2004, 10:04
Hello all,

Now its time to release the first version of my scripting plugin.
If it is buggy please bear with it. I have some exams this weekend
but I will fix the bugs (that are certain to appear) next week.

Go to http://ollyscript.apsvans.com ("http://ollyscript.apsvans.com") for information and download.

TBD: please put a link to the page in the plugins section, not
the .zip. The reason for this is that I want to see the download counter. =)

sgdt
January 14th, 2004, 11:28
I was wondering about a couple of potential features.

I guess first would be the ability to set (and unset) HW Breaks, and the second would be continuing from exception.

It was unclear from the documentation on how to go interactive from the script. I assume it would just be end of script (maybe a label at the end that could be jumped to). This is important to mention, as then the user can execute the OllyDump plug-in or what not.

psyCK0
January 14th, 2004, 12:06
Yep, a small mistake:

EOB example:
eob SOME_LABEL // jump to label
eob $ // go interactive

Hmm, this will be changed/improved.

focht
January 14th, 2004, 12:14
Greetings,

if one is looking for extension/scripting languages there are lots of options.
For lightweight choices there are:

lua - http://www.lua.org/
("http://www.lua.org/
")
angelscript - http://www.angelcode.com/angelscript/ ("http://www.angelcode.com/angelscript/")
nasal - http://www.plausible.org/nasal/
("http://www.plausible.org/nasal/
")
io - http://www.iolanguage.com/
("http://www.iolanguage.com/
")
tinyscheme - http://tinyscheme.sourceforge.net/home.html
("http://tinyscheme.sourceforge.net/home.html
")

When a new project starts, i always look for "tools of trade" ... frameworks, tools, libraries that can be (re)used/extended with minimal work (if oss license permits).
Though i appreciate your work i suggest to have a look at the stuff to learn from.

Embrace and extend

Regards,

A. Focht

psyCK0
January 14th, 2004, 12:36
I was thinking of using lua for this, but it felt like an overkill...

So now, because I dont want to rewrite all this a third time, I'll have to continue with this notation I invented. I hope it will be adequate for the purpose. =)

TBD
January 15th, 2004, 00:47
psyCK0: very nice !

some suggestions:
* some commands to inform users about progress/actions/...
e.g. log "text" -> display in Log Window "OllyScript: text"
* cannot see .osc files on Run script. must switch to All files. i will do more tests.
* toolbar/window with latest plugins used
* editor with debugging for writing scripts

that's it for start.

one more thing: if you want i can create a separate forum for OllyScript.
i know you want to have a separate board but it is more easier for users and you to keep track (i hate to have to look on 10 forums a day

once again, very nice and keep up the good work.

psyCK0
January 15th, 2004, 03:35
TBD I really dont think there is enough interest for a separate forum. I will remove my forum from my site, and use this thread instead. =) Thank you for your suggestions!

TBD
January 15th, 2004, 03:40
psyCK0: your call. i was thinking a place in this board to gather scripts for OllyScript [ODS] and place for sharing and not start searching on the entire board: "where was that nice script that does ..."

i hope that you work on ODS and not get tired it has potential.

psyCK0
January 15th, 2004, 05:18
TBD ok, you are the board admin. =) Maybe we can try to set up a board section and see if it is used? Anyway, I will post the "incredible UPX OEP finder script!" =)

I will continue developing this plugin for some time at least, there seems to
be an interest in it...

TBD
January 15th, 2004, 08:08
psyCK0: here ya go

Anonymous
January 18th, 2004, 04:39
I tried the following but it gave me an error:
var x
reg x,esp
lable1:
sti
cmp x,esp
je lable1
ret
the error msg. was "esp" isn't declared and isn't a number.

psyCK0
January 18th, 2004, 05:54
Hey!

At the moment the plugin can't handle register names in cmp.
This will be fixed in 0.3 or 0.4.

For the time being, please use something like:
<pre>var x
var y
reg x,esp
lable1:
sti
reg y,esp
cmp x,y
je lable1
ret </pre>

Anonymous
January 18th, 2004, 05:54
Greetings,

the "compare" operator currently accecpts either op1=var,op2=var or op1=var,op2=constant.
You must declare/load a second variable to work around this limitation.

Well script line on error would be needed feature too...

Regards,

A. Focht

psyCK0
January 18th, 2004, 06:00
Script line on error is also in the implementation queue. =)
I hope to get this plugin more useful till the next version,
0.2 was released mostly to see if there is any interest in such
a plugin.

focht
January 18th, 2004, 06:16
hehe ... nice intersection

Anyway i noticed the input trimming stuff needs to be reworked.
Especially trim() is prone to access violations.
Your are using iterators without checking its validity.

<pre>
string trim(const string& sData)
{
if (sData.size() > 0)
{
size_t iFirst = sData.find_first_not_of(" &#92;t";
size_t iLast = sData.find_last_not_of(" &#92;t";
return (sData.substr( iFirst, iLast - iFirst + 1));
}
else
return "";
}
</pre>

Image if i input a single line with a space " " in it. It will break for sure...

Here is how i would code this (accepts even more whitespace stuff)
<pre>
std::string trim(const std::string& s)
{
std::string::size_type left = s.find_first_not_of(" &#92;t&#92;f&#92;n&#92;r";
if( left == std::string::npos )
{
return std::string();
}

std::string::size_type right = s.find_last_not_of(" &#92;t&#92;f&#92;n&#92;r";
return s.substr( left, right-left+1 );
}
</pre>

Regards,

A. Focht

focht
January 18th, 2004, 06:35
Another one ...

the conditional jumps return script error in Process() function if jump condition is not met.
Is this intended? Probaly not.

Another Hint .. you are using "0" and "1" integer return values from most functions to use them as bools.
e.g. int xxx() { if( ..) return 0; else return 1; }

if( xxx())

This is dangerous and slightly misleading because the meaning of "TRUE" is not always "1" (i've seen compilers that emit "-1" code for 'true'). One might safely assume that any non-0 is "true".

Nowadays every modern compiler has "bool" type ... if a function returns a bool value i would make it explicit
ex: bool foo() { if( ..) return true; else return false; }

Regards,

A. Focht

psyCK0
January 18th, 2004, 07:38
focht Thank you for the tips!

Especially trim() is prone to access violations
trim will be reimplemented as you suggested.

the conditional jumps return script error in Process() function if jump condition is not met.
Yeah, thats a bug that is already fixed. Will be OK in 0.3

Nowadays every modern compiler has "bool" type
Thats what comes out of not doing a proper analysis/design.
I started using integers because I thought I'd use them as
status codes, which I never did. I've been thinking of changing
them to bools. I think I'll do it for 0.3.

Also the REG command is plain stupid. In the next ver MOV will
be able to do all REG does and more. REG will stay for backward
compatibility only.

Any more good suggestions on design?

focht
January 18th, 2004, 12:54
Uhm well ...

usually i would point out a good lexical scanner/parser framework (including dynamic BNF) ...
But i know you dont have time and want results
If you still interested you might look into boost's "spirit" library at http://spirit.sourceforge.net/
("http://spirit.sourceforge.net/
")

Boost is IMHO the best OO framework around ... http://www.boost.org/
("http://www.boost.org/
")
I use it regularly in my projects (i code for a living).

For other suggestions .. well.
In every project turn compiler warn level to 4.
This catches most of the bugs usually encountered (uninit vars, control paths ...)
I even use "treat warnings as errors" in my projects (i disable too noisy ones with pragmas).

For the "processing" of commands itself i would simply use a function pointer table or map.
Not that i dont like if( command == xxx) .. else if( ...) ... approach but the more commands you implement the more the function will grow.

example (simplified version):

<pre>
// declare function ptr with one arg
typedef bool (*PFCOMMAND)(const std::string& arg1);
// prototype our command lookup map
typedef std::map< std::string, PFCOMMAND> command_map;
// instance of command map
command_map commands;

// insert entries into "commands"
void addCommand( const std::string& name, PFCOMMAND routine)
{
commands[name] = routine;
}

// call subroutines via "commands" lookup
bool callCommand( const std::string& name, const std::string& arg)
{
bool result( false);

// use the string to look up the pointer to subroutine
command_map::const_iterator citer = commands.find( name);
if( citer != commands.end())
{
// we found it, get function pointer
PFCOMMAND cmd = citer->second;
// call subroutine
result = cmd( arg);
}
else
{
// no match for given name, use error callback
....
}

return result;
}

You can now

addCommand( "cmp", &CompareHandler)
....

result = callCommand( command_str, arg1) ...
...

and so on..

</pre>

I hope you get the idea

Regards,

A. Focht

PS: remove REG there arent that many scripts written to keep zombies alive forever...

psyCK0
January 18th, 2004, 16:03
Hey Focht,

usually i would point out a good lexical scanner/parser framework (including dynamic BNF)

I felt it'd be an overkill for this project... I've never done it before,
so it'd take me too much time just to learn (even though I've taken a
course in compiler theory =)). I don't even write C/C++ that much, I work
with Java mostly...

For the "processing" of commands itself i would simply use a function pointer table or map

Great idea! I was getting tired of this ugly giant if. =)

Thanks for your ideas!