读写文件的问题,请哪位高手帮看看!
代码如下:
hFile=CreateFile(FileName,GENERIC_ALL,NULL,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(INVALID_HANDLE_VALUE != hFile)
{
dwFileSize=GetFileSize(hFile,0);
lpAddr = (BYTE *)VirtualAlloc(0, dwFileSize,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
CloseHandle(hFile);
}
pFile=fopen(FileName,"rb");
if (NULL==pFile)
{
printf("Open xmlcore.dat failed.");
return result;
}
nCount=fread(lpAddr,dwFileSize,1,pFile);
if (!nCount)
{
printf("GetShellcode failed.");
return result;
}
result = lpAddr;
#include <stdio.h>
unsigned int ReadByteFile(const char* name, unsigned char* buff, unsigned int len)
{
FILE* fp = fopen(name, "rb");
if (NULL == fp)
{
return 0;
}
unsigned int size;
fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, 0 ,SEEK_SET);
if (size>len)
{
return 0;
}
unsigned int reads = fread(buff, sizeof(unsigned char), len, fp);
fclose(fp);
return reads;
}
void main()
{
unsigned char arr[200] = {0};
unsigned int reads = ReadByteFile("test.bat", arr, 200);
return ;
}