diff options
| author | Rusty Wagner <rusty.wagner@gmail.com> | 2024-08-06 13:49:01 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty.wagner@gmail.com> | 2024-08-06 18:29:20 -0400 |
| commit | 102c3b87334c8f8a3e3c570eb9aeaa33746f38d9 (patch) | |
| tree | 81d5885519b24c2186ac1ef9a34702173b4ce9eb | |
| parent | 3eb83fb1710b9256ea84630212776d41dbd56069 (diff) | |
Add flag role for carry flag when subtraction is implemented with addition
| -rw-r--r-- | arch/arm64/arch_arm64.cpp | 2 | ||||
| -rw-r--r-- | arch/armv7/arch_armv7.cpp | 2 | ||||
| -rw-r--r-- | binaryninjacore.h | 5 | ||||
| -rw-r--r-- | python/examples/nes.py | 17 |
4 files changed, 9 insertions, 17 deletions
diff --git a/arch/arm64/arch_arm64.cpp b/arch/arm64/arch_arm64.cpp index 13198af9..9020b99b 100644 --- a/arch/arm64/arch_arm64.cpp +++ b/arch/arm64/arch_arm64.cpp @@ -1511,7 +1511,7 @@ class Arm64Architecture : public Architecture case IL_FLAG_Z: return ZeroFlagRole; case IL_FLAG_C: - return CarryFlagRole; + return CarryFlagWithInvertedSubtractRole; case IL_FLAG_V: return OverflowFlagRole; default: diff --git a/arch/armv7/arch_armv7.cpp b/arch/armv7/arch_armv7.cpp index d14641d8..57ed3057 100644 --- a/arch/armv7/arch_armv7.cpp +++ b/arch/armv7/arch_armv7.cpp @@ -1734,7 +1734,7 @@ BNFlagRole ArmCommonArchitecture::GetFlagRole(uint32_t flag, uint32_t) case IL_FLAG_Z: return ZeroFlagRole; case IL_FLAG_C: - return CarryFlagRole; + return CarryFlagWithInvertedSubtractRole; case IL_FLAG_V: return OverflowFlagRole; default: diff --git a/binaryninjacore.h b/binaryninjacore.h index 45ef79f2..5f631827 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -37,7 +37,7 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 72 +#define BN_CURRENT_CORE_ABI_VERSION 73 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and @@ -671,7 +671,8 @@ extern "C" EvenParityFlagRole = 7, OddParityFlagRole = 8, OrderedFlagRole = 9, - UnorderedFlagRole = 10 + UnorderedFlagRole = 10, + CarryFlagWithInvertedSubtractRole = 11, } BNFlagRole; typedef enum BNFunctionGraphType diff --git a/python/examples/nes.py b/python/examples/nes.py index 64a33d22..b12a616d 100644 --- a/python/examples/nes.py +++ b/python/examples/nes.py @@ -87,7 +87,7 @@ class M6502(Architecture): flags = [c_flag, z_flag, i_flag, d_flag, b_flag, v_flag, s_flag] flag_write_types = [FlagWriteTypeName("*"), FlagWriteTypeName("czs"), FlagWriteTypeName("zvs"),FlagWriteTypeName( "zs")] flag_roles = { - c_flag: FlagRole.SpecialFlagRole, # Not a normal carry flag, subtract result is inverted + c_flag: FlagRole.CarryFlagWithInvertedSubtractRole, z_flag: FlagRole.ZeroFlagRole, v_flag: FlagRole.OverflowFlagRole, s_flag: FlagRole.NegativeSignFlagRole } flags_required_for_flag_condition = { @@ -104,8 +104,8 @@ class M6502(Architecture): Mnemonic("asl"):lambda il, operand: il.store(1, operand, il.shift_left(1, il.load(1, operand), il.const(1, 1), flags=FlagName("czs"))), Mnemonic("asl@"):lambda il, operand: il.set_reg(1, a_reg, il.shift_left(1, operand, il.const(1, 1), flags=FlagName("czs"))), Mnemonic("and"):lambda il, operand: il.set_reg(1, a_reg, il.and_expr(1, il.reg(1, a_reg), operand, flags=FlagName("zs"))), - Mnemonic("bcc"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_UGE), operand), - Mnemonic("bcs"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_ULT), operand), + Mnemonic("bcc"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_ULT), operand), + Mnemonic("bcs"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_UGE), operand), Mnemonic("beq"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_E), operand), Mnemonic("bit"):lambda il, operand: il.and_expr(1, il.reg(1, a_reg), operand, flags=FlagName("czs")), Mnemonic("bmi"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_NEG), operand), @@ -528,15 +528,6 @@ class M6502(Architecture): il.append(i) return length - def get_flag_write_low_level_il(self, op: LowLevelILOperation, size: int, write_type: Optional[FlagWriteTypeName], flag: FlagType, operands: List[ILRegisterType], il: LowLevelILFunction) -> ExpressionIndex: - if flag == 'c': - if (op == LowLevelILOperation.LLIL_SUB) or (op == LowLevelILOperation.LLIL_SBB): - # Subtraction carry flag is inverted from the commom implementation - return il.not_expr(0, self.get_default_flag_write_low_level_il(op, size, FlagRole.CarryFlagRole, operands, il)) - # Other operations use a normal carry flag - return self.get_default_flag_write_low_level_il(op, size, FlagRole.CarryFlagRole, operands, il) - return Architecture.get_flag_write_low_level_il(self, op, size, write_type, flag, operands, il) - def is_never_branch_patch_available(self, data:bytes, addr:int) -> bool: if (data[0:1] == b"\x10") or (data[0:1] == b"\x30") or (data[0:1] == b"\x50") or (data[0:1] == b"\x70") or ( data[0:1] == b"\x90" @@ -708,7 +699,7 @@ class NESView(BinaryView): return True def perform_get_address_size(self) -> int: - return self.address_size + return 2 def perform_get_entry_point(self) -> int: return struct.unpack("<H", self.read(0xfffc, 2))[0] |
