Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. int8 read_pe(struct DOS_HEADER *dos_header, struct NT_HEADERS *nt_headers, char *filename) {
  2. FILE *in;
  3.  
  4. in = fopen(filename, "rb");
  5. fread(dos_header, sizeof(struct DOS_HEADER), 1, in);
  6. if((dos_header->e_magic & 0xFF) != 'M' || (dos_header->e_magic >> 8) != 'Z') return -1;
  7. fseek(in, dos_header->e_lfanew, SEEK_SET);
  8. printf("e_lfanew %d\n", dos_header->e_lfanew);
  9. fread(nt_headers, sizeof(struct NT_HEADERS), 1, in);
  10. if((nt_headers->signature & 0xFF) != 'P' || (nt_headers->signature >> 8) != 'E') return -1;
  11.  
  12. uint32 rva, isize;
  13. rva = nt_headers->optional_header.data_directory[1].virtual_address;
  14.  
  15. isize = nt_headers->optional_header.data_directory[1].isize;
  16. printf("VirtualAddress %d isize: %d\n", rva, isize);
  17.  
  18. fseek(in, dos_header->e_lfanew+sizeof(struct NT_HEADERS), SEEK_SET);
  19. struct SECTION_HEADER *section_headers = (struct SECTION_HEADER *) malloc(nt_headers->file_header.number_of_sections);
  20. int i;
  21. for(i = 1; i <= nt_headers->file_header.number_of_sections; i++) {
  22. fread(&section_headers[i], sizeof(struct SECTION_HEADER), 1, in);
  23. printf("%d %d\n", i, section_headers[i].virtual_address);
  24. }
  25.  
  26. free(section_headers);
  27. fclose(in);
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement