Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void EnumSections(char* file) {
- FILE *hFile = fopen(file, "rb");
- if (hFile != NULL) {
- if (fgetc(hFile) == 'M' && fgetc(hFile) == 'Z') {
- unsigned int e_lfanew = 0;
- unsigned int NumberOfRvaAndSizes = 0;
- unsigned int ExportVirtualAddress = 0;
- unsigned int ExportSize = 0;
- int i = 0;
- fseek(hFile, 0x3C, SEEK_SET);
- fread(&e_lfanew, 4, 1, hFile);
- fseek(hFile, e_lfanew + 6, SEEK_SET);
- fread(&NumberOfSections, 2, 1, hFile);
- fseek(hFile, 108, SEEK_CUR);
- fread(&NumberOfRvaAndSizes, 4, 1, hFile);
- if (NumberOfRvaAndSizes == 16) {
- fread(&ExportVirtualAddress, 4, 1, hFile);
- fread(&ExportSize, 4, 1, hFile);
- if (ExportVirtualAddress > 0 && ExportSize > 0) {
- fseek(hFile, 120, SEEK_CUR);
- if (NumberOfSections > 0) {
- printf("addr size section\n");
- sections = (sectionHeader *)malloc(NumberOfSections * sizeof(sectionHeader));
- for (i = 0; i < NumberOfSections; i++) {
- fread(sections[i].Name, 8, 1, hFile);
- fread(§ions[i].VirtualSize, 4, 1, hFile);
- fread(§ions[i].VirtualAddress, 4, 1, hFile);
- fread(§ions[i].SizeOfRawData, 4, 1, hFile);
- fread(§ions[i].PointerToRawData, 4, 1, hFile);
- fread(§ions[i].PointerToRelocations, 4, 1, hFile);
- fread(§ions[i].PointerToLineNumbers, 4, 1, hFile);
- fread(§ions[i].NumberOfRelocations, 2, 1, hFile);
- fread(§ions[i].NumberOfLineNumbers, 2, 1, hFile);
- fread(§ions[i].Characteristics, 4, 1, hFile);
- printf("0x%07x %07d %s\n", sections[i].VirtualAddress, sections[i].VirtualSize, sections[i].Name);
- }
- }
- }
- }
- }
- fclose(hFile);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement