Skip to content

Commit

Permalink
Dump segment names and sectio names.
Browse files Browse the repository at this point in the history
  • Loading branch information
nico committed Sep 20, 2011
1 parent 2624f3b commit cebc0f9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lssym.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ static void fatal(const char* msg, ...) {
exit(1);
}

static void dump_segment(struct segment_command_64* cmd, uint8_t* data0) {
uint8_t* data = (uint8_t*)cmd;

printf(" ");
for (int i = 0; i < sizeof(cmd->segname) && cmd->segname[i]; ++i)
printf("%c", cmd->segname[i]);
printf("\n");

struct section_64* sect =
(struct section_64*)(((uint8_t*)cmd) + sizeof(struct segment_command_64));
for (int i = 0; i < cmd->nsects; ++i, ++sect) {
printf(" ");
for (int i = 0; i < sizeof(sect->sectname) && sect->sectname[i]; ++i)
printf("%c", sect->sectname[i]);
printf(":");

for (int i = 0; i < sizeof(sect->segname) && sect->segname[i]; ++i)
printf("%c", sect->segname[i]);
printf("\n");
}
}

static void dump_symtab(struct symtab_command* symtab, uint8_t* data) {
struct nlist_64* nlist = (struct nlist_64*)(data + symtab->symoff);

Expand Down Expand Up @@ -174,6 +196,9 @@ static void dump(struct mach_header* header) {
printf("cmd %s (0x%x), size %d\n", cmdnam, cmd->cmd, cmd->cmdsize);

switch(cmd->cmd) {
case LC_SEGMENT_64:
dump_segment((struct segment_command_64*)cmd, (uint8_t*)header);
break;
case LC_SYMTAB:
dump_symtab((struct symtab_command*)cmd, (uint8_t*)header);
break;
Expand Down

0 comments on commit cebc0f9

Please sign in to comment.