-
Notifications
You must be signed in to change notification settings - Fork 288
Improve compatibility with iOS / macOS 27 shared caches #8260
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
Merged
+222
−26
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5bf826b
[DSC] Reduce log noise when loading iOS / macOS 27 shared caches
bdash 1f509da
[DSC] Handle changes to how objc_msgSend is called in iOS / macOS 27 …
bdash 9a3859f
[ObjC] Add support for method type strings that are pointers relative…
bdash 639e929
[ObjC] Introduce a new activity to rename objc_msgSend stub functions
bdash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| use binaryninja::{ | ||
| low_level_il::instruction::{InstructionHandler as _, LowLevelILInstructionKind}, | ||
| symbol::{Symbol, SymbolType}, | ||
| variable::PossibleValueSet, | ||
| workflow::AnalysisContext, | ||
| }; | ||
|
|
||
| use crate::{ | ||
| activities::objc_msg_send_calls::{call_target_type, selector_from_call, MessageSendType}, | ||
| error::ILLevel, | ||
| metadata::GlobalState, | ||
| Error, | ||
| }; | ||
|
|
||
| // Reconstruct names for Objective-C selector stubs, e.g. `_objc_msgSend$length`. | ||
| // The compiler emits one of these stubs per selector. Each one does nothing but load the selector and tail-call | ||
| // `objc_msgSend`. | ||
| pub fn process(ac: &AnalysisContext) -> Result<(), Error> { | ||
| let view = ac.view(); | ||
| if GlobalState::should_ignore_view(&view) { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let func = ac.function(); | ||
| let func_start = func.start(); | ||
|
|
||
| // Don't override a name the user has assigned to this function. | ||
| if let Some(symbol) = view.symbol_by_address(func_start) { | ||
| if !symbol.auto_defined() { | ||
| return Ok(()); | ||
| } | ||
| } | ||
|
|
||
| // Bail out early for functions that do not look like a stub: a single basic block of a few instructions. | ||
| const MAX_STUB_SIZE: u64 = 32; | ||
| if func.highest_address().saturating_sub(func_start) > MAX_STUB_SIZE | ||
| || func.basic_blocks().len() != 1 | ||
| { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let Some(llil) = (unsafe { ac.llil_function() }) else { | ||
| return Err(Error::MissingIL { | ||
| level: ILLevel::Low, | ||
| func_start, | ||
| }); | ||
| }; | ||
| let Some(ssa) = llil.ssa_form() else { | ||
| return Err(Error::MissingSsaForm { | ||
| level: ILLevel::Low, | ||
| func_start, | ||
| }); | ||
| }; | ||
|
|
||
| // The tail call terminates the stub's single basic block, so it can only be the last instruction. | ||
| let blocks = ssa.basic_blocks(); | ||
| let Some(block) = blocks.iter().next() else { | ||
| return Ok(()); | ||
| }; | ||
| let Some(insn) = block.iter().last() else { | ||
| return Ok(()); | ||
| }; | ||
| let LowLevelILInstructionKind::TailCallSsa(call_op) = insn.kind() else { | ||
|
emesare marked this conversation as resolved.
|
||
| return Ok(()); | ||
| }; | ||
|
|
||
| // A selector stub does nothing besides load a selector and tail-call objc_msgSend. | ||
| // Reject any function that performs a regular call or memory write before the tail call. | ||
| if block.iter().any(|insn| { | ||
| matches!( | ||
| insn.kind(), | ||
| LowLevelILInstructionKind::CallSsa(_) | ||
| | LowLevelILInstructionKind::Store(_) | ||
| | LowLevelILInstructionKind::StoreSsa(_) | ||
| ) | ||
| }) { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let call_target = match call_op.target().possible_values() { | ||
| PossibleValueSet::ConstantValue { value } | ||
| | PossibleValueSet::ConstantPointerValue { value } | ||
| | PossibleValueSet::ImportedAddressValue { value } => value as u64, | ||
| _ => return Ok(()), | ||
| }; | ||
|
|
||
| if call_target_type(&view, call_target) != Some(MessageSendType::Normal) { | ||
| return Ok(()); | ||
| } | ||
| let Some(selector) = selector_from_call(&view, &ssa, &call_op) else { | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| let name = format!("_objc_msgSend${}", selector.name); | ||
| let symbol = Symbol::builder(SymbolType::Function, &name, func_start).create(); | ||
| view.define_auto_symbol(&symbol); | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to update
AnalysisContext::functionto be anOption<Ref<Function>>, since it can be executed in the context of the binary view for a module level workflow.This isn't an issue with your PR I just noticed it when reviewing.