Created
November 17, 2009 04:30
-
-
Save mattn/236644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
typedef unsigned char byte; | |
typedef unsigned short uint16; | |
typedef unsigned int uint32; | |
void* get_proc_addr(byte *base, byte *name) | |
{ | |
byte *pe_header = base+*(uint32*)(base+0x3c); | |
byte *exports = base+*(uint32*)(pe_header+0x78); | |
uint32 entries = *(uint32*)(exports+0x18); | |
uint32 *addr = (uint32*)(base+*(uint32*)(exports+0x1c)); | |
uint32 *names = (uint32*)(base+*(uint32*)(exports+0x20)); | |
uint16 *ordinals = (uint16*)(base+*(uint32*)(exports+0x24)); | |
uint32 i; | |
for (i=0; i<entries; i++) { | |
byte *s = base+names[i]; | |
if (!strcmp(name, s)) break; | |
} | |
if (i == entries) return 0; | |
return base+addr[ordinals[i]]; | |
} | |
int main(void) { | |
HANDLE hUser32 = LoadLibrary("user32.dll"); | |
void* proc = get_proc_addr(hUser32, "MessageBoxA"); | |
int r; | |
char *msg = "綺麗なお姉さんは好きですか?", *title = "質問"; | |
_asm { | |
push 4 | |
push title | |
push msg | |
push 0 | |
call proc | |
mov r, eax | |
} | |
puts(r == 6 ? "はい!" : "いいえ!"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment