Skip to content

Commit 42fd642

Browse files
committed
CHB:ARM: record presence of instruction predicates in analysis results
1 parent 733bd84 commit 42fd642

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

CodeHawk/CHB/bchlib/bCHVersion.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ end
9595

9696

9797
let version = new version_info_t
98-
~version:"0.6.0_20250623"
99-
~date:"2025-06-23"
98+
~version:"0.6.0_20250625"
99+
~date:"2025-06-25"
100100
~licensee: None
101101
~maxfilesize: None
102102
()

CodeHawk/CHB/bchlibarm32/bCHARMAnalysisResults.ml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,32 @@ object (self)
7272
let loc = ctxt_string_to_location faddr ctxtiaddr in
7373
let floc = get_floc loc in
7474
let espoffset = floc#get_stackpointer_offset "arm" in
75+
let has_control_flow =
76+
instr#has_opcode_condition
77+
&& (match instr#get_opcode with
78+
| Branch _ | BranchExchange _ -> false
79+
| _ -> true)
80+
&& (Option.is_none instr#is_in_aggregate) in
7581
begin
7682
arm_dictionary#write_xml_arm_opcode node instr#get_opcode;
7783
id#write_xml_instr node instr floc;
7884
id#write_xml_sp_offset node espoffset;
7985
arm_dictionary#write_xml_arm_bytestring
80-
node (byte_string_to_printed_string instr#get_instruction_bytes)
86+
node (byte_string_to_printed_string instr#get_instruction_bytes);
87+
(if has_control_flow then
88+
let optcc = instr#get_opcode_condition in
89+
match optcc with
90+
| Some cc ->
91+
let pcc = BCHARMOpcodeRecords.get_cond_mnemonic_extension cc in
92+
let _ = node#setAttribute "brcc" pcc in
93+
if floc#has_test_expr then
94+
let csetter = floc#f#get_associated_cc_setter floc#cia in
95+
node#setAttribute "brsetter" csetter
96+
else
97+
()
98+
| _ -> ()
99+
else
100+
())
81101
end
82102

83103
method private write_xml_instructions (node:xml_element_int) =

CodeHawk/CHB/bchlibarm32/bCHARMAssemblyInstruction.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
------------------------------------------------------------------------------
55
The MIT License (MIT)
66
7-
Copyright (c) 2021-2024 Aarno Labs, LLC
7+
Copyright (c) 2021-2025 Aarno Labs, LLC
88
99
Permission is hereby granted, free of charge, to any person obtaining a copy
1010
of this software and associated documentation files (the "Software"), to deal
@@ -87,8 +87,16 @@ object (self)
8787

8888
method is_in_aggregate = in_aggregate
8989

90+
method has_opcode_condition =
91+
BCHARMOpcodeRecords.is_opcode_conditional opcode
92+
93+
method get_opcode_condition =
94+
BCHARMOpcodeRecords.get_arm_opcode_condition opcode
95+
96+
(* applies only to Thumb IT instruction *)
9097
method set_block_condition = blockcondition <- true
9198

99+
(* applies only to Thumb IT instruction *)
92100
method is_block_condition = blockcondition
93101

94102
method set_condition_covered_by (iaddr: doubleword_int) =

CodeHawk/CHB/bchlibarm32/bCHARMOpcodeRecords.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ let get_record (opc:arm_opcode_t): 'a opcode_record_t =
198198
operands = [ rd; rn; imm ];
199199
flags_set = if s then [APSR_N; APSR_Z; APSR_C] else [];
200200
ccode = Some c;
201-
ida_asm = (fun f -> f#opscc ~thumbw:tw "AND" c [rd; rn; imm])
201+
ida_asm = (fun f -> f#opscc ~thumbw:tw "AND" ~writeback:s c [rd; rn; imm])
202202
}
203203
| BitwiseBitClear (s, c, rd, rn, rm, tw) -> {
204204
mnemonic = "BIC";

CodeHawk/CHB/bchlibarm32/bCHARMTypes.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,7 @@ class type arm_assembly_instruction_int =
14231423
method get_instruction_bytes: string
14241424
method get_bytes_ashexstring: string
14251425
method get_non_code_block: not_code_t
1426+
method get_opcode_condition: arm_opcode_cc_t option
14261427
method condition_covered_by: doubleword_int
14271428

14281429
(* predicates *)
@@ -1438,6 +1439,7 @@ class type arm_assembly_instruction_int =
14381439
method is_aggregate_entry: bool
14391440
method is_aggregate_exit: bool
14401441
method is_aggregate_anchor: bool
1442+
method has_opcode_condition: bool
14411443

14421444
(* i/o *)
14431445
method write_xml: xml_element_int -> unit

CodeHawk/CHB/bchlibarm32/bCHFnARMTypeConstraints.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,23 @@ object (self)
393393

394394
end
395395

396+
| BitwiseNot (_, _, rd, rm, _) ->
397+
let rdreg = rd#to_register in
398+
let lhstypevar = mk_reglhs_typevar rdreg faddr iaddr in
399+
let rmdefs = get_variable_rdefs_r (rm#to_variable floc) in
400+
let rmreg = rm#to_register in
401+
begin
402+
List.iter (fun rmsym ->
403+
let rmaddr = rmsym#getBaseName in
404+
let rmtypevar = mk_reglhs_typevar rmreg faddr rmaddr in
405+
let rmtypeterm = mk_vty_term rmtypevar in
406+
let lhstypeterm = mk_vty_term lhstypevar in
407+
begin
408+
log_subtype_constraint __LINE__ "MVN-rdef" rmtypeterm lhstypeterm;
409+
store#add_subtype_constraint rmtypeterm lhstypeterm
410+
end) rmdefs
411+
end
412+
396413
| BitwiseOr (_, _, rd, rn, _, _) ->
397414
let rdreg = rd#to_register in
398415
let lhstypevar = mk_reglhs_typevar rdreg faddr iaddr in

0 commit comments

Comments
 (0)