我所做的就是
ExitProcess地址__asm__ ("jmp %%ecx"::"c"(opcode));执行修改后的操作码这是我的代码:
#include <windows.h>
#include <stdio.h>
int main()
{
char addr[4];
*(int*)addr = GetProcAddress(GetModuleHandle("kernel32.dll"),"ExitProcess");
//push 0 == 0x6a 0x00
//call ExitProcess == 0xe8 0xd8 0x79 0xa2 0x75
char opcode[400] = {0x6a, 0x00, 0xe8,addr[0], addr[1],addr[2],addr[3]};
__asm__ ("jmp %%ecx" ::"c"(opcode));
//never be here
printf("never get here");
getchar();
return 0;
}我希望程序正常退出,但程序以分段故障结束。
它似乎会跳到某个地方,但不会跳到我想要它跳的地方。
我怎么才能解决呢?
发布于 2015-01-02 09:03:35
把你想做的奇怪的事放在一边.
您的问题是操作码e8是一个相对跳转。因此,您需要说明您正在存储它的地址。可能是这样的:
更新:每台云,帐户长度x。
#include <windows.h>
#include <stdio.h>
#pragma pack(1)
struct mfoo {
unsigned char x[3] = {0x6a, 0x00, 0xe8};
void *addr;
} foo;
int main()
{
unsigned char *a = (unsigned char *)GetProcAddress(GetModuleHandle("kernel32.dll"),"ExitProcess");
foo.addr = (void *)(a - sizeof(foo) - (unsigned char *)foo.x);
__asm__ ("jmp *%%ecx" ::"c"(&foo));
//never be here
printf("never get here");
getchar();
return 0;
}https://stackoverflow.com/questions/27739030
复制相似问题