Skip to content

Commit

Permalink
Handle stack frame offset for x86 stack vars (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
zolutal authored Jun 2, 2022
1 parent a3093f3 commit 5798361
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions decompilers/d2d_binja/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from xmlrpc.server import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler

from binaryninja import SymbolType
from binaryninja import SymbolType, EntryRegisterValue
from binaryninja.binaryview import BinaryDataNotification

#
Expand Down Expand Up @@ -102,10 +102,20 @@ def function_data(self, addr: int):

func = funcs[0]

# get stack frame offset for x86
frame_offset = 0
if self.bv.arch.name == 'x86_64':
frame_offset -= self.bv.arch.address_size
elif self.bv.arch.name == 'x86':
# handle inconsistent stack frame offsets
current_frame = func.get_reg_value_at(addr, 'ebp')
if current_frame.type != EntryRegisterValue.type:
frame_offset = current_frame.value

# get stack vars
stack_vars = {}
for stack_var in func.stack_layout:
offset = abs(stack_var.storage)
offset = frame_offset - stack_var.storage
stack_vars[str(offset)] = {
"name": stack_var.name,
"type": str(stack_var.type)
Expand Down

0 comments on commit 5798361

Please sign in to comment.