Skip to content

Commit e75d64a

Browse files
committed
Expose DebugFunctionInfo.local_variables to python api
1 parent 1765feb commit e75d64a

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

python/debuginfo.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import ctypes
2222
from typing import Optional, List, Iterator, Callable, Tuple
2323
import traceback
24-
from dataclasses import dataclass
24+
from dataclasses import dataclass, field
2525

2626
# Binary Ninja components
2727
import binaryninja
@@ -32,6 +32,7 @@
3232
from . import binaryview
3333
from . import filemetadata
3434
from . import typecontainer
35+
from .variable import VariableNameAndType
3536

3637
_debug_info_parsers = {}
3738
ProgressFuncType = Callable[[int, int], bool]
@@ -263,7 +264,8 @@ class DebugFunctionInfo(object):
263264
raw_name: Optional[str] = None
264265
function_type: Optional[_types.Type] = None
265266
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)
267269

268270
def __repr__(self) -> str:
269271
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
359361
for c in range(0, function.componentN):
360362
components.append(function.components[c])
361363

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+
362374
yield DebugFunctionInfo(
363375
function.address, function.shortName, function.fullName, function.rawName,
364-
function_type, func_platform, components
376+
function_type, func_platform, components, local_variables
365377
)
366378
finally:
367379
core.BNFreeDebugFunctions(functions, count.value)
@@ -525,6 +537,26 @@ def add_function(self, new_func: DebugFunctionInfo) -> bool:
525537
func_info.components = component_list
526538
func_info.componentN = len(components)
527539

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+
528560
func_info.shortName = new_func.short_name
529561
func_info.fullName = new_func.full_name
530562
func_info.rawName = new_func.raw_name

0 commit comments

Comments
 (0)