|
21 | 21 | import ctypes |
22 | 22 | from typing import Optional, List, Iterator, Callable, Tuple |
23 | 23 | import traceback |
24 | | -from dataclasses import dataclass |
| 24 | +from dataclasses import dataclass, field |
25 | 25 |
|
26 | 26 | # Binary Ninja components |
27 | 27 | import binaryninja |
|
32 | 32 | from . import binaryview |
33 | 33 | from . import filemetadata |
34 | 34 | from . import typecontainer |
| 35 | +from .variable import VariableNameAndType |
35 | 36 |
|
36 | 37 | _debug_info_parsers = {} |
37 | 38 | ProgressFuncType = Callable[[int, int], bool] |
@@ -263,7 +264,8 @@ class DebugFunctionInfo(object): |
263 | 264 | raw_name: Optional[str] = None |
264 | 265 | function_type: Optional[_types.Type] = None |
265 | 266 | platform: Optional['_platform.Platform'] = None |
266 | | - components: Optional[List[str]] = None |
| 267 | + components: List[str] = field(default_factory=list) |
| 268 | + local_variables: List[VariableNameAndType] = field(default_factory=list) |
267 | 269 |
|
268 | 270 | def __repr__(self) -> str: |
269 | 271 | suffix = f"@{self.address:#x}>" if self.address != 0 else ">" |
@@ -359,9 +361,19 @@ def functions_from_parser(self, name: Optional[str] = None) -> Iterator[DebugFun |
359 | 361 | for c in range(0, function.componentN): |
360 | 362 | components.append(function.components[c]) |
361 | 363 |
|
| 364 | + local_variables = [] |
| 365 | + for c in range(0, function.localVariableN): |
| 366 | + local_var = function.localVariables[c] |
| 367 | + local_var_type = _types.Type.create(core.BNNewTypeReference(local_var.type), confidence=local_var.typeConfidence) |
| 368 | + local_variables.append(VariableNameAndType.from_core_variable( |
| 369 | + local_var.var, |
| 370 | + local_var.name, |
| 371 | + local_var_type, |
| 372 | + )) |
| 373 | + |
362 | 374 | yield DebugFunctionInfo( |
363 | 375 | function.address, function.shortName, function.fullName, function.rawName, |
364 | | - function_type, func_platform, components |
| 376 | + function_type, func_platform, components, local_variables |
365 | 377 | ) |
366 | 378 | finally: |
367 | 379 | core.BNFreeDebugFunctions(functions, count.value) |
@@ -525,6 +537,26 @@ def add_function(self, new_func: DebugFunctionInfo) -> bool: |
525 | 537 | func_info.components = component_list |
526 | 538 | func_info.componentN = len(components) |
527 | 539 |
|
| 540 | + if new_func.local_variables is None: |
| 541 | + local_variables = [] |
| 542 | + elif isinstance(new_func.local_variables, list): |
| 543 | + local_variables = new_func.local_variables |
| 544 | + else: |
| 545 | + return NotImplemented |
| 546 | + |
| 547 | + local_variables_list = (core.BNVariableNameAndType * len(local_variables))() |
| 548 | + for (i,v) in enumerate(local_variables): |
| 549 | + core_var = core.BNVariableNameAndType() |
| 550 | + core_var.name = v.name |
| 551 | + core_var.type = v.type.handle |
| 552 | + core_var.var = v.to_BNVariable() |
| 553 | + core_var.autoDefined = False # TODO |
| 554 | + core_var.typeConfidence = v.type.confidence |
| 555 | + |
| 556 | + local_variables_list[i] = core_var |
| 557 | + func_info.localVariables = local_variables_list |
| 558 | + func_info.localVariableN = len(local_variables) |
| 559 | + |
528 | 560 | func_info.shortName = new_func.short_name |
529 | 561 | func_info.fullName = new_func.full_name |
530 | 562 | func_info.rawName = new_func.raw_name |
|
0 commit comments