Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int8 read_pe(struct DOS_HEADER *dos_header, struct NT_HEADERS *nt_headers, char *filename) {
- FILE *in;
- in = fopen(filename, "rb");
- fread(dos_header, sizeof(struct DOS_HEADER), 1, in);
- if((dos_header->e_magic & 0xFF) != 'M' || (dos_header->e_magic >> 8) != 'Z') return -1;
- fseek(in, dos_header->e_lfanew, SEEK_SET);
- printf("e_lfanew %d\n", dos_header->e_lfanew);
- fread(nt_headers, sizeof(struct NT_HEADERS), 1, in);
- if((nt_headers->signature & 0xFF) != 'P' || (nt_headers->signature >> 8) != 'E') return -1;
- uint32 rva, isize;
- rva = nt_headers->optional_header.data_directory[1].virtual_address;
- isize = nt_headers->optional_header.data_directory[1].isize;
- printf("VirtualAddress %d isize: %d\n", rva, isize);
- fseek(in, dos_header->e_lfanew+sizeof(struct NT_HEADERS), SEEK_SET);
- struct SECTION_HEADER *section_headers = (struct SECTION_HEADER *) malloc(nt_headers->file_header.number_of_sections);
- int i;
- for(i = 1; i <= nt_headers->file_header.number_of_sections; i++) {
- fread(§ion_headers[i], sizeof(struct SECTION_HEADER), 1, in);
- printf("%d %d\n", i, section_headers[i].virtual_address);
- }
- free(section_headers);
- fclose(in);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement