-
Notifications
You must be signed in to change notification settings - Fork 163
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
mach: Some loaded dylibs type aren't handled by parse() #73
Comments
Hi @codido! Thanks for the report. So if the parser ever panics, it’s a serious bug. Can you provide backtrace and perhaps either name of file you tried to parse (eg like a lib in /use/lib or something) Thanks ! |
Thanks for the prompt response, @m4b!
Running examples/dyldinfo on the resulting test would result in:
Simply handling LoadWeakDylib similar to other dylib type in parse() seems to resolve this. There might be other missing types, not sure. Thanks! |
@codido Sorry for the delay; yes this was a simple oversight :/ Should be fixed now, but I haven't tested just yet, will probably be able to confirm in a couple hours, or if you see its fixed, feel free to close |
@m4b Thanks for the fix! That being said, shouldn't all *Dylib be handled similarly? |
I think they're all handled now except prebound dylibs, which can be fixed via: load_command::CommandVariant::PreboundDylib(command) => {
let lib = bytes.pread::<&str>(cmd.offset + command.name as usize)?;
libs.push(lib);
}, Except I don't know if this is correct. I believe prebound dylibs are added by statically linking the lib, in which case the imports cannot reference this dylib, since they've been statically linked, and hence not needed by the dynamic linker. I need to do some research, unless you know offhand what the answer is here? I can't even recall if I've seen a mach-o binary with a prebound library... |
I don't know much, but I can say that |
Ok then I don’t think we need to add it to imports vector; otherwise will likely cause off by one errors for imports in a binary with prebound. Thanks @willglynn for the info! |
Looks like prebinding is an obsolete mechanism (from ld(1)):
I guess only old binaries will include this command. By the way, while the patch above will fix valid binaries, goblin would still panic for invalid ones (e.g. with out of bounds ordinals or segment indices), no? |
Ahh, this takes me back. And yes, everything about this is obsoleted by the If somebody has a backup from 14 years ago (everything was prebound in <= 10.3), it ought to contain executables with this header. |
If you're really motivated you can download old software update packages from Apple manually. Here's the download for the 10.3.7 Combined Update, for example: It's sort of a pain to unpack their update files (they're a bunch of nested archives in really obscure formats) but I have scripts that can do it. Most of the useful bits are in here: (we use these scripts to download and unpack macOS software updates to extract symbols for system libraries for Firefox crash reporting.) |
@luser Prebinding is a thing that happens on the end user's machine, much like The "optimized" binaries are specific to the user's machine, and I think it's unlikely that we'll find examples in Apple downloads. |
FWIW, it seems one of the samples in https://objective-see.com/malware.html (OpinionSpy (Premier Opinion)) contains a prebound load command in the ppc's mach-o of JavaApplicationStub. Just don't run it :) |
Ok, I think this was sufficiently resolved? Closing, please re-open if I've misunderstood |
load_command::CommandVariant::LoadWeakDylib isn't handled, which may result in a panic when retrieving imports.
The text was updated successfully, but these errors were encountered: