Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Arguments ordered now
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl OS committed May 15, 2020
1 parent 68a4186 commit 55999bd
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions FIDL/decompiler_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import random
import traceback
import networkx as nx
from collections import namedtuple, defaultdict
from collections import namedtuple, defaultdict, OrderedDict
from six.moves import xrange

DEBUG = False
Expand Down Expand Up @@ -742,14 +742,30 @@ def get_function_vars(c=None, ea=0, only_args=False, only_locals=False):
# Successful decompilation at `ea` point
# `cf.lvars` is an array of `lvars_t`
# `idx` is the index into this array to be used later
#
# I need to re-order the list of arguments.
# No idea why, but IDA does not spit the arguments in order.
# It keeps however a list of how the indexes are messed up in ``c.cf.argidx``
ordered_vars = [None] * len(cf.lvars)

for i, v in enumerate(cf.lvars):
if v.is_arg_var:
# Need to fix order
idx = cf.argidx[i]
else:
# Local vars seem to be fine
idx = i

ordered_vars[idx] = v

if only_args:
return {idx: my_var_t(v) for idx, v in enumerate(cf.lvars)
if v.is_arg_var and v.name}
return OrderedDict({idx: my_var_t(v) for idx, v in enumerate(ordered_vars)
if v.is_arg_var and v.name})
elif only_locals:
return {idx: my_var_t(v) for idx, v in enumerate(cf.lvars)
if not v.is_arg_var and v.name}
return OrderedDict({idx: my_var_t(v) for idx, v in enumerate(ordered_vars)
if not v.is_arg_var and v.name})
else:
return {idx: my_var_t(v) for idx, v in enumerate(cf.lvars)}
return OrderedDict({idx: my_var_t(v) for idx, v in enumerate(ordered_vars)})


def ref2var(ref, c=None, cf=None):
Expand Down

0 comments on commit 55999bd

Please sign in to comment.