creating an asm opcode - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Skype & Technology (/forumdisplay.php?fid=9) +---- Forum: Tech Talk (/forumdisplay.php?fid=17) +----- Thread: creating an asm opcode (/showthread.php?tid=75626) creating an asm opcode by effection on 06-25-2007 at 12:25 PM Im injecting some code into a msn, but i need to be able to create a "call" and a "jmp" op code to the address that its located at as it is all dynamically allocated work and im not sure how to do this in x86 im a MIPS guy RE: creating an asm opcode by Verte on 06-25-2007 at 03:26 PM
Take a look at how the call naturally happens. Even if the function is dynamically allocated, you should see a heap of steps for working out the location of the function and loading that into the registers for the call. RE: creating an asm opcode by effection on 06-25-2007 at 08:03 PM i said x86 as in Intel x86 used by 90% of the worlds PCs...I have my code already written and i am able to inject it by dynamically allocating memory and get the pointer (which will always change), therefore i must be able to create a "jmp" instruction for this address pointing to the function RE: creating an asm opcode by TheSteve on 06-26-2007 at 12:21 AM
The easiest solution is to use a program such as ollydbg and find a random spot to construct some temporary asm. The actual bytes for the command will be next to the character representation for the command. RE: RE: creating an asm opcode by Verte on 06-26-2007 at 09:17 AM
quote: call is not always a simple jmp, depending on the original language it may be the caller or the callee that sets up the new stack, saves the register state, etc. Pick a compiler and compile C code only to ASM, and have it call your function. In the resulting ASM, it should have something like "call <function@whatever>", with the @ meaning it's linked somewhere to be determined at runtime. I'm not entirely sure how it works. I know what you mean by x86 and MIPS, but it's not a processor specific feature that finds the pointer to your function- it's one of calling convention, which is language specific. You could make up any crazy call functionality you like, for example, passing input or output values in registers, just as easily on either architecture [well, not quite true, MIPS having more registers IIRC], but what you want is the ASM calling convention of the function you've written, which should be obvious from the ASM you're reading now. or if not, ASM you can easily generate by compiling an example. Having never used Ollydbg myself, I can only agree with TheSteve's comment, as you're less likely to get yourself into trouble using a program that's designed specifically for what you're trying to do. But I think it might be good for you, effection, to work out the calling convention used by your function. RE: creating an asm opcode by effection on 06-26-2007 at 10:04 AM
well thing is im overwriting an op code with an opcode that is bigger so its overwriting the following line which is a "call whereever" so at the end of my code it must be placed so the function is called. RE: RE: creating an asm opcode by Verte on 06-26-2007 at 10:24 AM
quote: The way I would think to do it is replace the last two operations you were doing with an operation to save the instruction pointer and an unconditional jump into free space. At the free space, do the two instructions you replaced before calling the function, which you can do now that you're not disturbing the regular instruction sequence. RE: creating an asm opcode by effection on 06-27-2007 at 03:45 PM
well im pushing and poping the registers im using anyway so i dont think it will affect it, but i am however having trouble creating these instructions in javascript i think i can create one of the needed jumps okay but the other 2 are very very incorrect code:*i found out that this method wont work since its 64 aligned RE: creating an asm opcode by CookieRevised on 06-27-2007 at 11:48 PM
I'm not sure if this is what Verte means (if so slap me), but can't you overwrite the original opcode (the one you overwrite now anyways) with an unconditional jump to your instructions and at the end of your instructions unconditionally jump back to the opcode after the one you've overwritten? In that way you only need to replace 1 opcode and don't need to call anything else... RE: creating an asm opcode by Verte on 06-28-2007 at 01:39 AM
I almost drew that exact diagram myself, although I thought you may need an extra operation to resolve the address of the function [but I think maybe I'm being pedantic]. RE: creating an asm opcode by effection on 06-28-2007 at 11:28 AM
non of you understand this at all code:this works fine and well but now i have to create a JMP to this FunctionBuffer.DataPtr so it can execute my code and IT CANNOT BE HARD CODED which you have all obviously got wrong even though you have read it is dynamically allocated! to create the jump ive done this code:I think the bytes have to be reversed thats why ive put the in a temp buffer then read it backwards but i am unsure. OBVIOUSLY since its dynamic memory i can just use "asm (jmp $0xE900000000)" RE: creating an asm opcode by Verte on 06-28-2007 at 01:57 PM
Oh no, I understood what you meant. I just thought you said you had the function there. If the location of the function is variable, then you will need to jump to the first instruction to be executed, for example, asm(jmp pointer_to_my_function). RE: creating an asm opcode by effection on 06-28-2007 at 03:18 PM Okay I can access the location of the allocated function ( using interop.alloc) i have viewed it will Ollydbg and it is definitely copied there correctly. The way i am calling it is as you say replacing a current opp with a JMP to the allocated function. The problem comes in creating the JMP code. If you could possibly give me some help in creating this as my attempts so far have failed, even if its C or C++ code i dont mind as i can easily implement this into a dll that i can call with the interop object RE: creating an asm opcode by CookieRevised on 06-29-2007 at 02:40 AM
I'm not quite sure if using the Interop.Allocate function is safe enough for this though. Maybe you're better of using the memory allocation APIs from windows directly. In that way you know exactly where you're doing what. And you can perfectly control the scope and lifetime of the allocated memory. quote:Sorry for saying this and certainly no offense, but I think we all understood your very good. And seeing what you finaly did in that other thread, it confirms what we were saying all this time though.... RE: creating an asm opcode by Verte on 06-29-2007 at 10:07 AM Dynamic linking is not something I've done by hand before, but I don't think it will be much fun. Still, there's bound to be a dll interface definition on the internet somewhere. RE: creating an asm opcode by effection on 06-29-2007 at 05:49 PM ive got it all sorted thanks to some help from deAd RE: creating an asm opcode by Verte on 06-29-2007 at 11:42 PM Nice! What did you end up doing? RE: creating an asm opcode by effection on 06-30-2007 at 12:15 AM I just did what i was always doing but there was something originally wrong with my Call creation code which i never could work out but it fixed itself eventually |