程序想将一个filebuffer存盘,但是在win32下面出现c000005错误,调试一天,无果,感到很是奇怪,想请大神能帮一下,为什么会出错加密程序代码:
VOID jiam()
{
void* pshellbuffer=NULL;
void* pfilebuffer=NULL;
//取壳子路径
TCHAR filename[100];
memset(filename,0,100);
GetWindowText(wen1,filename,100);
//把壳子程序读到内存
DWORD filesize=peread(filename,&pshellbuffer);
//取文件路径
memset(filename,0,100);
GetWindowText(wen2,filename,100);
//将程序读到内存
DWORD filesize1=peread(filename,&pfilebuffer);
PIMAGE_DOS_HEADER pdos=NULL;
PIMAGE_FILE_HEADER pfile=NULL;
PIMAGE_OPTIONAL_HEADER32 poptional=NULL;
PIMAGE_SECTION_HEADER psection=NULL;
pdos=(PIMAGE_DOS_HEADER)pshellbuffer;
pfile=(PIMAGE_FILE_HEADER)((DWORD)pshellbuffer+pdos->e_lfanew+4);
poptional=(PIMAGE_OPTIONAL_HEADER32)((DWORD)pfile+20);
psection=(PIMAGE_SECTION_HEADER)((DWORD)poptional+pfile->SizeOfOptionalHeader);
psection=psection+pfile->NumberOfSections-1;
DWORD size=poptional->SizeOfImage;
char* src=(char*)(psection->PointerToRawData+(DWORD)pshellbuffer);
//加密程序
for(DWORD i=0;i<filesize1;i++)
{
BYTE key=51;
((char*)pfilebuffer)[i]=((char*)pfilebuffer)[i]^key;
}
memcpy((char*)src,(char*)pfilebuffer,filesize1);
//存盘
memtofile(pshellbuffer,filesize,outfile);
free(pfilebuffer);
free(pshellbuffer);
return;
}
pe读取代码
DWORD peread(char* arr,void** pfilebuffer)
{
FILE* fp=NULL;
void* filebuffer=NULL;
int filesize=0;
fp=fopen(arr,"rb");
if(!fp)
{
printf("文件读取失败!\n");
fclose(fp);
return 0;
}
fseek(fp,0,SEEK_END);
filesize=ftell(fp);
fseek(fp,0,SEEK_SET);
filebuffer=malloc(filesize);
if(!filebuffer)
{
printf("内存分配失败!\n");
fclose(fp);
return 0;
}
int n=fread(filebuffer,filesize,1,fp);
if(!n)
{
printf("内存读取失败!\n");
free(filebuffer);
fclose(fp);
return 0;
}
*pfilebuffer=filebuffer;
filebuffer=NULL;
fclose(fp);
return filesize;
}
存盘代码
int memtofile(void*pnewbuffer,DWORD size,char* lpfile)
{
FILE* fp=NULL;
fp=fopen(lpfile,"wb+");
int n=fwrite(pnewbuffer,size,1,fp);
if(!n)
{
return 0;
}
else
{
return 1;
}
}
声明:本站所有资源均由网友分享,如有侵权内容,请在文章下方留言,本站会立即处理。