Reputation: 181
I'm trying to inject some ASM code into a Win32 program with C++. Is there a way to do this, avoiding DLL injection ?
This, for instance :
__asm{}
is only for the current program. Is there something similar used to generate hex code I could inject with WriteProcessMemory ?
Thanks in advance !
Upvotes: 0
Views: 3454
Reputation: 12918
In MSVC it may look like this:
void* shellcodeStart;
void* shellcodeEnd;
__asm {
mov shellcodeStart, offset shellcode_start
mov shellcodeEnd, offset shellcode_end
jmp shellcode_end
shellcode_start:
... // your code
shellcode_end:
}
size_t cb = shellcodeEnd - shellcodeStart;
WriteProcessMemory(hProcess, remoteAddress, shellcodeStart, cb, NULL);
Upvotes: 3
Reputation: 24867
One technique is to hand-assembly and put the code in an array, then copy the code where it should go. But this is straying into hacking land which I don't know much about.
Upvotes: 1