Call ASM routine from your script (with example) - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: Call ASM routine from your script (with example) (/showthread.php?tid=97508) Call ASM routine from your script (with example) by CookieRevised on 05-02-2011 at 07:21 AM
There are times that you have a binary string inside a (Plus!) DataBloc. js code: Now, this will work, but it will be dead slow. So, in many cases it is realy useless. For example, think about outputting a memory dump of 10000 bytes with the above code. But what if we can replace that slow loop function with assembler code (you can't go any faster than that)? Wouldn't that be cool? Well, you can: js code:This code will run as good as instantly because of the used ASM: js code: --------- EDIT: Apparently there was already another nice example of using ASM in scripting, created by Mnjul some time ago here (note: thread is in beta testing section, so only beta testers can access it) and Matty used it to create this script. The principle is just the same: write the ASM code and use the opcodes (=the hexadecimal values) to make a binary data string and place that in memory. His script uses the WriteProcessMemory API to inject (asm) code into the process memory (but not yet run it!), rerouting the default call to the WinProc procedure to this code instead, and calling the 'old' WinProc procedure after the new injected code has finished. RE: Call ASM routine from your script (with example) by SmokingCookie on 05-02-2011 at 01:46 PM
Wow, nice explanation JScript code: Then the debugger output is an empty string for the first method, and an H for the second. RE: RE: Call ASM routine from your script (with example) by CookieRevised on 05-02-2011 at 05:17 PM
[actually off topic as it will be more about explaining what unicode is and how strings are stored than about using ASM in scripting] quote:It does work... If the debug output showed an empty string for the first method then you've made an error in your code. In both cases it should show just an 'H' ! It is the correct output for your 'hello world' example. This because you already starting from a unicode string (note: it is not meant to be used like that). In JScript strings are always already unicode. Hence the very exact reason for this conversion example. So essentially, what you did was converting an unicode string to an unicode string. In other words the second character will always be a null character in that case. And a null character can not be shown in the debug output (but that doesn't mean it isn't there or that there isn't more stuff after that). In other words, what you did was converting this binary data: 48 00 65 00 6C 00 6C 00 6F 00 20 00 57 00 6F 00 72 00 6C 00 64 00 21 00 (This is the actual content of your variable Text, a unicode string "Hello World!") into this: 48 00 00 00 65 00 00 00 6C 00 00 00 6C 00 00 00 6F 00 00 00 20 00 00 00 57 00 00 00 6F 00 00 00 72 00 00 00 6C 00 00 00 64 00 00 00 21 00 00 00 The bold part shows the first character in the string before conversion and where those same bytes are after the conversion. The underlined part is what makes the second (unicode) character in the string before and after the conversion. The blue bytes are the original bytes shown where they are before and after the conversation. The black 0x00 bytes are what is added (actually skipped) by the function to make the original binary data (eg: binary data you read from the registry) into a real (unicode) string which you can use in JScript to manipulate (eg: to search for certain characters, to extract a certain substring, etc, using the conventional JScript functions and methods). As you can see, the second (unicode) character after the conversion is a null character, which you can not display, and the output will stop after encountering a null character. So, instead of displaying the entire string as a whole, I suggest you use JScript's string.charAt() method to examine what is going on in the strings before and after the conversion. (charAt() shows the character code of the unicode character). And/or use this string to start with (it is the "Hello World!" in ansi): js code:Or change your test code to: JScript code: [/actually off topic] RE: Call ASM routine from your script (with example) by SmokingCookie on 05-02-2011 at 06:45 PM
Okay, you win (again...) JScript code: And how did you make that up? RE: Call ASM routine from your script (with example) by CookieRevised on 05-02-2011 at 07:07 PM
See the comment at the end of the script in the first post. RE: RE: Call ASM routine from your script (with example) by segosa on 05-02-2011 at 07:07 PM
quote: Look at each hex value next to the assembly, and compare. It's the machine code/shellcode/opcodes/whatever you want to call it. CookieRevised: I have no useful input to add to this thread, so all I can say is that I really like this. If code could turn me on, this would. RE: Call ASM routine from your script (with example) by matty on 05-02-2011 at 07:07 PM
This is the actual thread... RE: Call ASM routine from your script (with example) by SmokingCookie on 05-02-2011 at 07:18 PM
I see what y'all mean, but I was actually wondering what the effect of the ASM stuff is on the "Hello world!" string. I mean: the input is the same as the output? And I think this ASM is quite a bit too abstract to make up yourself, right? RE: Call ASM routine from your script (with example) by CookieRevised on 05-02-2011 at 08:04 PM
quote:Ah, thanks... added. quote:thanks... I think as long as you don't cum.... quote:Nope, the output is completely different than the input. See my previous post where I explain what the effect is using your "hello world" example. quote:Although I got help from wtbw, there is nothing magic about it. It is just a matter of knowing your commands. (eg: how to write x++, or x=5 in asm). If you wouldn't know JScript, then any JScript code would be "abstract" to you too, won't it? So, that goes for any programming language code, including asm. The only difference is that asm is as low as you can go, it is (almost) pure machine code. So it doesn't have fancy (and human readable) commands which actually automatically do 1000 other things under the hood for you. You need to write those 1000 commands yourself in that case, using a set of simple and basic (cryptic, but still understandable in a way) commands. eg: mov ax, [cx] means move (or rather copy) the value found in the address pointed to by the register CX, to the register AX. inc ax means increment the value in AX and store that new value again in AX If you wanna know more about those mnemonics I suggest to Google assembler language and such things. Plenty info around, but not for the faint-hearted (or old people like me who cba anymore to learn it properly ). quote:That thread is in beta testing forum. See OP for a link to matty's implementation of that code in the public forum. RE: Call ASM routine from your script (with example) by Mnjul on 05-03-2011 at 01:00 AM
quote:If you're interested, the script is available here: http://www.msgplus.net/Downloads/Download-Details/DocumentID/8127/ but without the nice discussions in the beta forum RE: Call ASM routine from your script (with example) by whiz on 05-04-2011 at 07:25 AM This is actually quite interesting for me, since I'm doing a Computing A-level and there's a bit about assembly and machine code in it... good to actually see it in use. |