1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <windows.h>
#include <stdio.h>
#include <winnt.h>
int main(int argc, char *argv[])
{
char FilePath[MAX_PATH];
HANDLE hFile, hMapping;
IMAGE_DOS_HEADER *image_dos_header;
printf("Enter the path of the PE file: ");
scanf_s("%[^\n]",FilePath);
fflush(stdin);
getchar();
if ( (hFile = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0)) == INVALID_HANDLE_VALUE)
{
puts("(CreateFile API: opening of the file failed!)");
return EXIT_FAILURE;
}
if (!(hMapping = CreateFileMapping(hFile, 0, PAGE_READONLY | SEC_COMMIT, 0, 0, 0)))
{
puts("(CreateFileMapping API failed)");
CloseHandle(hFile);
return EXIT_FAILURE;
}
if (!(image_dos_header = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, sizeof(IMAGE_DOS_HEADER))))
{
puts("(MapViewOfFile API failed!)");
CloseHandle(hMapping);
CloseHandle(hFile);
return EXIT_FAILURE;
}
printf("-------------------------TEST-------------------------\n");
getchar();
printf("0x5A4D\nimage_dos_header->e_magic = %x\nIMAGE_DOS_SIGNATURE = %x\n",image_dos_header->e_magic, IMAGE_DOS_SIGNATURE);
UnmapViewOfFile(image_dos_header);
CloseHandle(hMapping);
CloseHandle(hFile);
return EXIT_SUCCESS;
} |
Partager