Accessing the symbol table of a mach-o file

KennyTM~ kennytm at gmail.com
Wed Mar 3 09:54:57 PST 2010


On Mar 4, 10 00:02, Jacob Carlborg wrote:
> I posted this message in the learn newsgroup without any response, I'm
> now hoping to have better response here.
>
> I'm trying to access the symbol table of a mach-o file. I've managed to
> access the symbol table but I have two problems:
>
> 1. It seems I can't access the whole symbol table if I compare my output
> to the output of nm. For example, I have a global struct in the file I'm
> examining which doesn't show up in my output. I have a global class that
> does show up but not the methods in the class.
>
> 2. When I'm printing the string representation (accessed from the string
> table) of some of the symbols they don't seem to be complete. For
> example "inte" instead of "internal". Then the next symbol I print is
> the rest of the previous symbol.
>
> This is the code I have so far, in some kind of pseudo code format:
>
> header = the header of the mach-o file
> cmd = cast(load_command*) (cast(byte*) header + size of header)
>
> loop (number of load commands)
> {
> cmd = cast(type of command) (cast(byte*) cmd + size of command)
>
> if (cmd == symbol table command)
> break
> }
>
> symbolTable = cast(nlist*) (cast(byte*) header + symbol table offset)
> stringTable = cast(char*) (cast(byte*) header + string table offset)
>
> foreach (entry in symbolTable)
> {
> symbol = stringTable + string table index
> print symbol
> }
>
> Does anyone have any idea what I can do about the above two problems?

If the Mach-O file is from Mac OS X 10.6 or iPhone OS 3.1, your method 
won't work because the symbol table format is changed. See 
http://developer.apple.com/mac/library/releasenotes/DeveloperTools/RN-dyld/index.html.



More information about the Digitalmars-d mailing list