From 6e50ceda4e65e5952e59449fad4953ea6c5aaf37 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 18 Nov 2025 15:45:15 -0800 Subject: Allow controlling which address is used for instructions created when inlining during analysis Previously the address of the instruction in the function being inlined was used as the new instruction's address when copying it during inlining. Now there is an additional option: use the address of the call instruction that is being replaced as the new instruction's address. This new mode is useful when inlining thunks or stub functions, but care must be taken if using it beyond that. The benefit is that it ensures that when a function contains multiple calls to the same stub function, each inlined copy ends up with distinct addresses. This ensures that call type adjustments and other overrides that are stored on the function and keyed by address can be applied independently to each callsite that was inlined. The trade-off is that if the function being inlined contains non-trivial logic, all of the inlined instructions sharing an address will limit what type of adjustments can be applied to them. The Objective-C and shared cache workflows are updated to take advantage of this new mode when they enable inlining of stub functions. This will make it possible for multiple calls to the same runtime function within a single function to have separate call type adjustments applied in the future. --- binaryninjaapi.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index db54a9a8..e28ebfb1 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -13139,6 +13139,8 @@ namespace BinaryNinja { bool GetInstructionContainingAddress(Architecture* arch, uint64_t addr, uint64_t* start); Confidence IsInlinedDuringAnalysis(); + Confidence GetInlinedDuringAnalysis(); + /*! Set whether the function should be inlined during analysis. This will take effect if the new confidence level is higher than the confidence @@ -13148,8 +13150,30 @@ namespace BinaryNinja { \param inlined Whether the function should be inlined. */ - void SetAutoInlinedDuringAnalysis(Confidence inlined); - void SetUserInlinedDuringAnalysis(Confidence inlined); + void SetAutoInlinedDuringAnalysis(Confidence inlined); + void SetUserInlinedDuringAnalysis(Confidence inlined); + + // These overloads are needed to disambiguate calls that pass enum values directly. + void SetAutoInlinedDuringAnalysis(BNInlineDuringAnalysis inlined) { SetAutoInlinedDuringAnalysis(Confidence(inlined)); } + void SetUserInlinedDuringAnalysis(BNInlineDuringAnalysis inlined) { SetUserInlinedDuringAnalysis(Confidence(inlined)); } + + /*! + \deprecated Use the overload that takes `BNInlineDuringAnalysis`. + */ + void SetAutoInlinedDuringAnalysis(Confidence inlined) + { + BNInlineDuringAnalysis value = inlined.GetValue() ? InlinePreservingTargetInstructionAddresses : DoNotInlineCall; + SetAutoInlinedDuringAnalysis(Confidence(value, inlined.GetConfidence())); + }; + + /*! + \deprecated Use the overload that takes `BNInlineDuringAnalysis`. + */ + void SetUserInlinedDuringAnalysis(Confidence inlined) + { + BNInlineDuringAnalysis value = inlined.GetValue() ? InlinePreservingTargetInstructionAddresses : DoNotInlineCall; + SetUserInlinedDuringAnalysis(Confidence(value, inlined.GetConfidence())); + }; // TODO: Documentation bool IsInstructionCollapsed(const HighLevelILInstruction& instr, uint64_t designator = 0) const; -- cgit v1.3.1