Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module.enumerateSymbols missed lots of local symbols from iOS dyld_shared_cache #770

Open
ChiChou opened this issue Jan 11, 2024 · 0 comments

Comments

@ChiChou
Copy link
Contributor

ChiChou commented Jan 11, 2024

Test case

// search by iteration. Doesn't work on iOS

Module.enumerateSymbols('libxpc.dylib', {
    onMatch(symbol) {
        if (symbol.name == '_xpc_connection_call_event_handler') {
            console.log(symbol.address);
            return 'stop';
        }
    },
    onError() {
        console.error('error');
    },
    onComplete() {
        console.log('complete');
    }
})

// This works
console.log(DebugSymbol.getFunctionByName('_xpc_connection_call_event_handler'))

// on macOS, they both work, but the second approach is slower

So this function reads LC_SYMTAB from mach header, and parses nlist to get symbols:

gum_darwin_module_enumerate_symbols (GumDarwinModule * self,

However, many symbols are stored locally in dyld_shared_cache (or more recent versions, they are moved to .symbols file)

struct dyld_cache_header
{
	char		magic[16];				// e.g. "dyld_v0    i386"
        // ...
	uint64_t	localSymbolsOffset;		// file offset of where local symbols are stored
	uint64_t	localSymbolsSize;		// size of local symbols information
	uint8_t		uuid[16];				// unique value for each shared cache file
};

Here are some references:

https://github.com/jmpews/Dobby/blob/b0176de574104726bb68dff3b77ee666300fc338/builtin-plugin/SymbolResolver/macho/shared_cache_ctx.cpp#L46

https://github.com/blacktop/ipsw/blob/f03db0abba66f0af93d55344b791f57fde39db42/pkg/dyld/image.go#L795

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant