【发布时间】:2020-10-28 22:05:30
【问题描述】:
我编写了一个程序,将函数写入文件,然后加载所述文件并执行该函数。当我为 32 位编译时,这段代码没有问题,但是当我将编译器设置为 64 位时,程序崩溃了。
#include <stdio.h>
#include <windows.h>
#include <Filez.h>
void shellc(FARPROC p,char* x)
{
(int (WINAPI *)(HWND,LPCSTR,LPCSTR,UINT))p(NULL,x,x,MB_OK);
}
void stub()
{
}
int main(int argc, char **argv)
{
int size = stub - shellc;
CryptMemoryToFile(shellc,size,"somepassword","shellcodefile");
int sz;
char * x = DeCryptFileToMemory("shellcodefile","somepassword",&sz);
void (*shellcode)(FARPROC,char*) = x;
FARPROC p = GetProcAddress(LoadLibraryA("user32.dll"),"MessageBoxA");
shellcode(p,"test");
getchar();
}
Filez.h 中定义的 2 个 (De)Cryption 函数
char * DeCryptFileToMemory(char * File,char * Pw,int * Size)
{
int PWL = strlen(Pw);
char * Data = LoadFile(File,Size);
if (Data == NULL) return 0;
int y = 0;
for (int x = 0; x <= *Size;x++)
{
Data[x] = Data[x] - Pw[y];
y++;
if (y > PWL) y = 0;
}
return Data;
}
int CryptMemoryToFile(char * Memory,int Size,char * Pw,char * File)
{
int PWL = strlen(Pw);
char * Memory2 = malloc(Size);
memcpy(Memory2,Memory,Size);
if (Memory2 == NULL) return 0;
int y = 0;
for (int x = 0; x <= Size;x++)
{
Memory2[x] = Memory2[x] + Pw[y];
y++;
if (y > PWL) y = 0;
}
FILE * f = fopen(File,"wb");
if (f == NULL) return 0;
int w = fwrite(Memory2,1,Size,f);
if (w != Size) return 0;
fclose(f);
free(Memory2);
return 1;
}
【问题讨论】:
-
当您将其放入调试器并逐步执行时,您是否发现任何异常?会发生什么样的崩溃?