From 7a525174fd59204330690a8f9d65fe2a3046cd38 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Thu, 10 Jul 2025 01:35:51 -0400 Subject: [WARP] Add `IsInstructionComputedVariant` API Was previously not exposed, we want it for unit tests. --- plugins/warp/api/python/_warpcore.py | 19 +++++++++++++++++++ plugins/warp/api/python/warp.py | 6 ++++++ plugins/warp/api/warp.cpp | 5 +++++ plugins/warp/api/warpcore.h | 1 + 4 files changed, 31 insertions(+) (limited to 'plugins') diff --git a/plugins/warp/api/python/_warpcore.py b/plugins/warp/api/python/_warpcore.py index c53feefa..740072ab 100644 --- a/plugins/warp/api/python/_warpcore.py +++ b/plugins/warp/api/python/_warpcore.py @@ -955,6 +955,25 @@ def BNWARPIsLiftedInstructionVariant( return _BNWARPIsLiftedInstructionVariant(liftedFunction, idx) +# ------------------------------------------------------- +# _BNWARPIsLowLevelInstructionComputedVariant + +_BNWARPIsLowLevelInstructionComputedVariant = core.BNWARPIsLowLevelInstructionComputedVariant +_BNWARPIsLowLevelInstructionComputedVariant.restype = ctypes.c_bool +_BNWARPIsLowLevelInstructionComputedVariant.argtypes = [ + ctypes.POINTER(BNLowLevelILFunction), + ctypes.c_ulonglong, + ] + + +# noinspection PyPep8Naming +def BNWARPIsLowLevelInstructionComputedVariant( + llilFunction: ctypes.POINTER(BNLowLevelILFunction), + idx: int + ) -> bool: + return _BNWARPIsLowLevelInstructionComputedVariant(llilFunction, idx) + + # ------------------------------------------------------- # _BNWARPNewContainerReference diff --git a/plugins/warp/api/python/warp.py b/plugins/warp/api/python/warp.py index e0500215..c761c323 100644 --- a/plugins/warp/api/python/warp.py +++ b/plugins/warp/api/python/warp.py @@ -365,6 +365,12 @@ def is_instruction_variant(function: LowLevelILFunction, variant: LowLevelILInst def is_instruction_blacklisted(function: LowLevelILFunction, variant: LowLevelILInstruction) -> bool: return warpcore.BNWARPIsLiftedInstructionBlacklisted(function.handle, variant.instr_index) +def is_instruction_computed_variant(function: LowLevelILFunction, variant: LowLevelILInstruction) -> bool: + """ + Checks to see if the instruction is variant due to some computed value. **Must use LLIL.** + """ + return warpcore.BNWARPIsLowLevelInstructionComputedVariant(function.handle, variant.instr_index) + def get_function_guid(function: Function) -> Optional[FunctionGUID]: guid = warpcore.BNWARPUUID() if not warpcore.BNWARPGetAnalysisFunctionGUID(function.handle, guid): diff --git a/plugins/warp/api/warp.cpp b/plugins/warp/api/warp.cpp index 7d91c6e2..147add8e 100644 --- a/plugins/warp/api/warp.cpp +++ b/plugins/warp/api/warp.cpp @@ -319,6 +319,11 @@ bool IsInstructionBlacklisted(const BinaryNinja::LowLevelILFunction &function, B return BNWARPIsLiftedInstructionBlacklisted(function.m_object, idx); } +bool IsInstructionComputedVariant(const BinaryNinja::LowLevelILFunction &function, BinaryNinja::ExprId idx) +{ + return BNWARPIsLowLevelInstructionComputedVariant(function.m_object, idx); +} + std::optional Warp::GetAnalysisFunctionGUID(const BinaryNinja::Function &function) { FunctionGUID guid; diff --git a/plugins/warp/api/warpcore.h b/plugins/warp/api/warpcore.h index d12c6b98..09190126 100644 --- a/plugins/warp/api/warpcore.h +++ b/plugins/warp/api/warpcore.h @@ -87,6 +87,7 @@ extern "C" WARP_FFI_API bool BNWARPGetAnalysisFunctionGUID(BNFunction* analysisFunction, BNWARPFunctionGUID* result); WARP_FFI_API bool BNWARPIsLiftedInstructionVariant(BNLowLevelILFunction* liftedFunction, size_t idx); WARP_FFI_API bool BNWARPIsLiftedInstructionBlacklisted(BNLowLevelILFunction* liftedFunction, size_t idx); + WARP_FFI_API bool BNWARPIsLowLevelInstructionComputedVariant(BNLowLevelILFunction* llilFunction, size_t idx); WARP_FFI_API BNWARPFunction* BNWARPGetFunction(BNFunction* analysisFunction); WARP_FFI_API BNWARPFunction* BNWARPGetMatchedFunction(BNFunction* analysisFunction); -- cgit v1.3.1