Skip to content

Commit a5c6952

Browse files
committed
ARM: handle function pointer as function argument
1 parent 9bff3f4 commit a5c6952

File tree

7 files changed

+37
-23
lines changed

7 files changed

+37
-23
lines changed

chb/app/CHVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
chbversion: str = "0.3.0-20250709"
1+
chbversion: str = "0.3.0-20250714

chb/app/FunctionsData.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,26 @@ def is_unique_app_function_name(self, name: str) -> bool:
196196
return False
197197
return False
198198

199+
def is_library_stub_name(self, name: str) -> bool:
200+
if (name in self.functionnames
201+
and len(self.functionnames[name]) == 1):
202+
faddr = self.functionnames[name][0]
203+
return faddr in self.library_stubs()
204+
return False
205+
206+
def is_unique_function_name(self, name: str) -> bool:
207+
return (
208+
self.is_unique_app_function_name(name)
209+
and len(self.functionnames[name]) == 1)
210+
199211
def function_address_from_name(self, name: str) -> str:
200-
if self.is_unique_app_function_name(name):
212+
if name in self.functionnames and len(self.functionnames[name]) == 1:
201213
return self.functionnames[name][0]
214+
elif name in self.functionnames:
215+
raise UF.CHBError("Functionnames length: "
216+
+ str(len(self.functionnames[name]))
217+
+ ": "
218+
+ ", ".join(self.functionnames[name]))
202219
else:
203220
raise UF.CHBError("No function found with name " + name)
204221

chb/app/InstrXData.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
if TYPE_CHECKING:
5555
from chb.api.CallTarget import CallTarget
5656
from chb.api.InterfaceDictionary import InterfaceDictionary
57+
from chb.app.AppAccess import AppAccess
5758
from chb.app.Function import Function
5859
from chb.app.FunctionDictionary import FunctionDictionary
5960
from chb.invariants.FnVarDictionary import FnVarDictionary
@@ -94,6 +95,10 @@ def functiondictionary(self) -> "FunctionDictionary":
9495
def function(self) -> "Function":
9596
return self.functiondictionary.function
9697

98+
@property
99+
def app(self) -> "AppAccess":
100+
return self.function.app
101+
97102
@property
98103
def bdictionary(self) -> "BDictionary":
99104
return self.function.bd

chb/arm/ARMOpcode.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,12 @@ def get_instruction_c_condition(self) -> "XXpr":
201201
def add_instruction_condition(self, s: str) -> str:
202202
if self.xdata.has_unknown_instruction_condition():
203203
return "if ? then " + s
204-
elif self.xdata.has_instruction_condition():
205-
c = str(self.xdata.get_instruction_condition())
204+
if self.has_valid_instruction_c_condition():
205+
ccond = "(C: " + str(self.get_instruction_c_condition()) + ")"
206+
else:
207+
ccond = "(C: none)"
208+
if self.xdata.has_instruction_condition():
209+
c = str(self.xdata.get_instruction_condition()) + ccond
206210
return "if " + c + " then " + s
207211
else:
208212
return s

chb/arm/opcodes/ARMPop.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,7 @@ def ast_condition_prov(
224224
reverse: bool
225225
) -> Tuple[Optional[AST.ASTExpr], Optional[AST.ASTExpr]]:
226226

227-
ll_astcond = self.ast_cc_expr(astree)
228-
229-
if xdata.has_instruction_condition():
230-
pcond = xdata.get_instruction_condition()
231-
hl_astcond = XU.xxpr_to_ast_def_expr(pcond, xdata, iaddr, astree)
232-
233-
astree.add_expr_mapping(hl_astcond, ll_astcond)
234-
astree.add_expr_reachingdefs(hl_astcond, xdata.reachingdefs)
235-
astree.add_flag_expr_reachingdefs(ll_astcond, xdata.flag_reachingdefs)
236-
astree.add_condition_address(ll_astcond, [iaddr])
237-
238-
return (hl_astcond, ll_astcond)
239-
240-
else:
241-
chklogger.logger.error(
242-
"No condition found at address %s", iaddr)
243-
hl_astcond = astree.mk_temp_lval_expression()
244-
return (hl_astcond, ll_astcond)
227+
return self.ast_cc_condition_prov(astree, iaddr, bytestring, xdata)
245228

246229
def ast_prov(
247230
self,

chb/ast/ASTSymbolTable.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ def __str__(self) -> str:
117117
lines.append("Variables:")
118118
lines.append("-" * 80)
119119
for vinfo in self.table.values():
120-
lines.append(" - " + str(vinfo.vtype) + " " + vinfo.vname)
120+
gaddr = (
121+
" (" + hex(vinfo.globaladdress) + ")"
122+
if vinfo.globaladdress is not None else "")
123+
lines.append(" - " + str(vinfo.vtype) + " " + vinfo.vname + gaddr)
121124
return "\n".join(lines)
122125

123126

chb/cmdline/astcmds.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ def buildast(args: argparse.Namespace) -> NoReturn:
255255
gaddr = int("0x" + vname[4:(index+4)], 16)
256256
else:
257257
gaddr = int("0x" + vname[4:], 16)
258+
elif app.functionsdata.is_unique_function_name(vname):
259+
gaddr = int(app.functionsdata.function_address_from_name(vname), 16)
258260
elif vname.startswith("gv_"):
259261
if "_" in vname[3:]:
260262
index = vname[3:].index("_")

0 commit comments

Comments
 (0)