Skip to content

Commit

Permalink
Do not perform temporary register selection if we don't need to
Browse files Browse the repository at this point in the history
Fixes #847
  • Loading branch information
zachriggle committed Jan 12, 2017
1 parent 9c2f0f4 commit abff5da
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pwnlib/regsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def regsort(in_out, all_regs, tmp = None, xchg = True, randomize = None):
('mov', 'b', 'c'),
('mov', 'c', 'x'),
('mov', 'x', '1')]
>>> regsort({'a': 'b', 'b': 'c'}, ['a','b','c'], xchg=0)
[('mov', 'a', 'b'), ('mov', 'b', 'c')]
"""
if randomize is None:
randomize = context.randomize
Expand Down Expand Up @@ -333,7 +335,9 @@ def regsort(in_out, all_regs, tmp = None, xchg = True, randomize = None):
# If XCHG is expressly disabled, and there is no temporary register,
# try to see if there is any register which can be used as a temp
# register instead.
if not (xchg or tmp):
#
# If there are no cycles, there's no need for a temporary register.
if in_cycle and not (xchg or tmp):
for reg in in_out:
if not depends_on_cycle(reg, in_out, in_cycle):
tmp = reg
Expand Down

0 comments on commit abff5da

Please sign in to comment.