~joshrig/dumppef

eb62ee0942d3eae561dec8635aed016d416151f2 — Joshua Lynch 1 year, 6 months ago be133da
prettied up output a bit
2 files changed, 86 insertions(+), 170 deletions(-)

M README.md
M dumppef.c
M README.md => README.md +68 -156
@@ 31,7 31,7 @@ sample output

```
$ ./dumppef libs/MenusLib
Container Header
```Container Header
 tag1:             Joy!
 tag2:             peff
 architecture:     pwpc


@@ 71,161 71,73 @@ Container Header
   exportHashTablePower:     1      (0x1)
   exportSymbolCount:        19     (0x13)

hash index[000] -> chainCount: 7    firstIndex: 0
hash index[001] -> chainCount: 12   firstIndex: 7
key index[0000] -> symbolLength: 21   encodedSymbolName: 0xbf83
key index[0001] -> symbolLength: 16   encodedSymbolName: 0xd594
key index[0002] -> symbolLength: 18   encodedSymbolName: 0x9b30
key index[0003] -> symbolLength: 25   encodedSymbolName: 0xa25c
key index[0004] -> symbolLength: 18   encodedSymbolName: 0xac80
key index[0005] -> symbolLength: 22   encodedSymbolName: 0xafa8
key index[0006] -> symbolLength: 14   encodedSymbolName: 0x4b0f
key index[0007] -> symbolLength: 23   encodedSymbolName: 0xce7d
key index[0008] -> symbolLength: 11   encodedSymbolName: 0xd391
key index[0009] -> symbolLength: 18   encodedSymbolName: 0x9ccd
key index[0010] -> symbolLength: 11   encodedSymbolName: 0x9475
key index[0011] -> symbolLength: 11   encodedSymbolName: 0xbf91
key index[0012] -> symbolLength: 11   encodedSymbolName: 0xc475
key index[0013] -> symbolLength: 15   encodedSymbolName: 0x18b2
key index[0014] -> symbolLength: 17   encodedSymbolName: 0xace2
key index[0015] -> symbolLength: 25   encodedSymbolName: 0x525d
key index[0016] -> symbolLength: 19   encodedSymbolName: 0x8875
key index[0017] -> symbolLength: 19   encodedSymbolName: 0x51d9
key index[0018] -> symbolLength: 19   encodedSymbolName: 0x4fe9
sym index[0000]
 classAndName: 0x0200000b
  symbolClass:       Vect symbol
  stringTableOffset: 11
 symbolValue:  0
 sectionIndex: -2
sym index[0001]
 classAndName: 0x02000020
  symbolClass:       Vect symbol
  stringTableOffset: 32
 symbolValue:  0
 sectionIndex: -2
sym index[0002]
 classAndName: 0x0200008f
  symbolClass:       Vect symbol
  stringTableOffset: 143
 symbolValue:  0
 sectionIndex: -2
sym index[0003]
 classAndName: 0x02000030
  symbolClass:       Vect symbol
  stringTableOffset: 48
 symbolValue:  0
 sectionIndex: -2
sym index[0004]
 classAndName: 0x020000ec
  symbolClass:       Vect symbol
  stringTableOffset: 236
 symbolValue:  0
 sectionIndex: -2
sym index[0005]
 classAndName: 0x02000137
  symbolClass:       Vect symbol
  stringTableOffset: 311
 symbolValue:  0
 sectionIndex: -2
sym index[0006]
 classAndName: 0x020000be
  symbolClass:       Vect symbol
  stringTableOffset: 190
 symbolValue:  0
 sectionIndex: -2
sym index[0007]
 classAndName: 0x02000049
  symbolClass:       Vect symbol
  stringTableOffset: 73
 symbolValue:  0
 sectionIndex: -2
sym index[0008]
 classAndName: 0x02000000
  symbolClass:       Vect symbol
  stringTableOffset: 0
 symbolValue:  0
 sectionIndex: -2
sym index[0009]
 classAndName: 0x020000a1
  symbolClass:       Vect symbol
  stringTableOffset: 161
 symbolValue:  0
 sectionIndex: -2
sym index[0010]
 classAndName: 0x02000060
  symbolClass:       Vect symbol
  stringTableOffset: 96
 symbolValue:  0
 sectionIndex: -2
sym index[0011]
 classAndName: 0x020000b3
  symbolClass:       Vect symbol
  stringTableOffset: 179
 symbolValue:  0
 sectionIndex: -2
sym index[0012]
 classAndName: 0x0200006b
  symbolClass:       Vect symbol
  stringTableOffset: 107
 symbolValue:  0
 sectionIndex: -2
sym index[0013]
 classAndName: 0x020000cc
  symbolClass:       Vect symbol
  stringTableOffset: 204
 symbolValue:  0
 sectionIndex: -2
sym index[0014]
 classAndName: 0x020000db
  symbolClass:       Vect symbol
  stringTableOffset: 219
 symbolValue:  0
 sectionIndex: -2
sym index[0015]
 classAndName: 0x02000076
  symbolClass:       Vect symbol
  stringTableOffset: 118
 symbolValue:  0
 sectionIndex: -2
sym index[0016]
 classAndName: 0x020000fe
  symbolClass:       Vect symbol
  stringTableOffset: 254
 symbolValue:  0
 sectionIndex: -2
sym index[0017]
 classAndName: 0x02000111
  symbolClass:       Vect symbol
  stringTableOffset: 273
 symbolValue:  0
 sectionIndex: -2
sym index[0018]
 classAndName: 0x02000124
  symbolClass:       Vect symbol
  stringTableOffset: 292
 symbolValue:  0
 sectionIndex: -2
IsMenuItemIconEnabled
IsMenuBarVisible
AppendMenuItemText
GetMenuExcludesMarkColumn
EnableMenuItemIcon
RemoveMenuItemProperty
EnableMenuItem
GetMenuItemPropertySize
ShowMenuBar
InsertMenuItemText
GetMenuFont
HideMenuBar
SetMenuFont
DisableMenuItem
IsMenuItemEnabled
SetMenuExcludesMarkColumn
DisableMenuItemIcon
GetMenuItemProperty
SetMenuItemProperty
```

  Hash table
   hash index[000] -> chainCount: 7    firstIndex: 0
   hash index[001] -> chainCount: 12   firstIndex: 7

  Export key table
   key index[0000] -> symbolLength: 21   encodedSymbolName: 0xbf83
   key index[0001] -> symbolLength: 16   encodedSymbolName: 0xd594
   key index[0002] -> symbolLength: 18   encodedSymbolName: 0x9b30
   key index[0003] -> symbolLength: 25   encodedSymbolName: 0xa25c
   key index[0004] -> symbolLength: 18   encodedSymbolName: 0xac80
   key index[0005] -> symbolLength: 22   encodedSymbolName: 0xafa8
   key index[0006] -> symbolLength: 14   encodedSymbolName: 0x4b0f
   key index[0007] -> symbolLength: 23   encodedSymbolName: 0xce7d
   key index[0008] -> symbolLength: 11   encodedSymbolName: 0xd391
   key index[0009] -> symbolLength: 18   encodedSymbolName: 0x9ccd
   key index[0010] -> symbolLength: 11   encodedSymbolName: 0x9475
   key index[0011] -> symbolLength: 11   encodedSymbolName: 0xbf91
   key index[0012] -> symbolLength: 11   encodedSymbolName: 0xc475
   key index[0013] -> symbolLength: 15   encodedSymbolName: 0x18b2
   key index[0014] -> symbolLength: 17   encodedSymbolName: 0xace2
   key index[0015] -> symbolLength: 25   encodedSymbolName: 0x525d
   key index[0016] -> symbolLength: 19   encodedSymbolName: 0x8875
   key index[0017] -> symbolLength: 19   encodedSymbolName: 0x51d9
   key index[0018] -> symbolLength: 19   encodedSymbolName: 0x4fe9

  Export symbol table
   sym index[0000] -> symbolClass: Vect symbol     stringTableOffset: 11
   sym index[0001] -> symbolClass: Vect symbol     stringTableOffset: 32
   sym index[0002] -> symbolClass: Vect symbol     stringTableOffset: 143
   sym index[0003] -> symbolClass: Vect symbol     stringTableOffset: 48
   sym index[0004] -> symbolClass: Vect symbol     stringTableOffset: 236
   sym index[0005] -> symbolClass: Vect symbol     stringTableOffset: 311
   sym index[0006] -> symbolClass: Vect symbol     stringTableOffset: 190
   sym index[0007] -> symbolClass: Vect symbol     stringTableOffset: 73
   sym index[0008] -> symbolClass: Vect symbol     stringTableOffset: 0
   sym index[0009] -> symbolClass: Vect symbol     stringTableOffset: 161
   sym index[0010] -> symbolClass: Vect symbol     stringTableOffset: 96
   sym index[0011] -> symbolClass: Vect symbol     stringTableOffset: 179
   sym index[0012] -> symbolClass: Vect symbol     stringTableOffset: 107
   sym index[0013] -> symbolClass: Vect symbol     stringTableOffset: 204
   sym index[0014] -> symbolClass: Vect symbol     stringTableOffset: 219
   sym index[0015] -> symbolClass: Vect symbol     stringTableOffset: 118
   sym index[0016] -> symbolClass: Vect symbol     stringTableOffset: 254
   sym index[0017] -> symbolClass: Vect symbol     stringTableOffset: 273
   sym index[0018] -> symbolClass: Vect symbol     stringTableOffset: 292

  Exported symbol names
   IsMenuItemIconEnabled
   IsMenuBarVisible
   AppendMenuItemText
   GetMenuExcludesMarkColumn
   EnableMenuItemIcon
   RemoveMenuItemProperty
   EnableMenuItem
   GetMenuItemPropertySize
   ShowMenuBar
   InsertMenuItemText
   GetMenuFont
   HideMenuBar
   SetMenuFont
   DisableMenuItem
   IsMenuItemEnabled
   SetMenuExcludesMarkColumn
   DisableMenuItemIcon
   GetMenuItemProperty
   SetMenuItemProperty

references
----------

M dumppef.c => dumppef.c +18 -14
@@ 350,46 350,47 @@ int main(int argc, char **argv)
            lseek(fd, loader_header_abs_offset + loadheader.exportHashOffset, SEEK_SET);

            // gather up the list of export hash table entries
            printf("\n  Hash table\n");
            nhashents = powl(2, loadheader.exportHashTablePower);
            hashents  = malloc(sizeof(struct PEFHashTableEntry) * nhashents);
            for (int j = 0; j < nhashents; ++j)
            {
                uint32_t entry;

                read(fd, buf, 4);
                read(fd, buf, sizeof(uint32_t));

                unpack(buf, "I", &entry);
                hashents[j].chainCount = entry >> 18;
                hashents[j].firstIndex = entry & 0x0003FFFF;
                
                printf("hash index[%03d] -> chainCount: %-4d firstIndex: %-4d\n", j, hashents[j].chainCount, hashents[j].firstIndex);

                printf("   hash index[%03d] -> chainCount: %-4d firstIndex: %-4d\n", j, hashents[j].chainCount, hashents[j].firstIndex);
            }

            // gather up the list of export key table entries
            printf("\n  Export key table\n");
            keyents = malloc(sizeof(struct PEFExportKeyTableEntry) * loadheader.exportedSymbolCount);
            for (int j = 0; j < loadheader.exportedSymbolCount; j++)
            {
                read(fd, buf, 4);
                read(fd, buf, sizeof(struct PEFExportKeyTableEntry));

                unpack(buf, "HH", &keyents[j].symbolLength, &keyents[j].encodedSymbolName);

                printf("key index[%04d] -> symbolLength: %-4d encodedSymbolName: 0x%-4x\n", j, keyents[j].symbolLength, keyents[j].encodedSymbolName);
                printf("   key index[%04d] -> symbolLength: %-4d encodedSymbolName: 0x%-4x\n", j, keyents[j].symbolLength, keyents[j].encodedSymbolName);
            }

            // gather up the list of export key table entries
            printf("\n  Export symbol table\n");
            syments = malloc(sizeof(struct PEFExportSymbolTableEntry) * loadheader.exportedSymbolCount);
            for (int j = 0; j < loadheader.exportedSymbolCount; j++)
            {
                read(fd, buf, 10);
                read(fd, buf, sizeof(struct PEFExportSymbolTableEntry));

                unpack(buf, "IIh", &syments[j].classAndName, &syments[j].symbolValue, &syments[j].sectionIndex);

                printf("sym index[%04d]\n", j);
                printf(" classAndName: 0x%08x\n", syments[j].classAndName);
                printf("  symbolClass:       %s\n", symbol_class_to_str(syments[j].classAndName >> 24));
                printf("  stringTableOffset: %d\n", syments[j].classAndName & 0x00FFFFFF);
                printf(" symbolValue:  %d\n", syments[j].symbolValue);
                printf(" sectionIndex: %d\n", syments[j].sectionIndex);
                printf("   sym index[%04d] -> symbolClass: %-15s stringTableOffset: %d\n", j, symbol_class_to_str(syments[j].classAndName >> 24), syments[j].classAndName & 0x00FFFFFF);
                // printf("    classAndName: 0x%08x\n", syments[j].classAndName);
                // printf("    symbolValue:  %2d\n", syments[j].symbolValue);
                // printf("    sectionIndex: %2d\n", syments[j].sectionIndex);
            }




@@ 398,13 399,16 @@ int main(int argc, char **argv)

            lseek(fd, loader_header_abs_offset + loadheader.loaderStringsOffset, SEEK_SET);
            read(fd, string_table, string_table_len);

            // dump out the exported symbols from the string table
            printf("\n  Exported symbol names\n");
            for (int j = 0; j < loadheader.exportedSymbolCount; j++)
            {
                uint32_t  offset = syments[j].classAndName & 0x00FFFFFF;
                uint32_t  len    = keyents[j].symbolLength;
                uint8_t  *p      = string_table + offset;
                    
                printf("%s\n", make_terminated_string(p, len));

                printf("   %s\n", make_terminated_string(p, len));
            }

            free(string_table);