Browse Source

Cleanup; arg support increased from 256 to 256**2

master
Ben Kurtovic 9 years ago
parent
commit
1b3fe66c42
2 changed files with 12 additions and 7 deletions
  1. +1
    -0
      .gitignore
  2. +11
    -7
      func_smash.py

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
*.pyc

+ 11
- 7
func_smash.py View File

@@ -43,10 +43,14 @@ def print_chain(chain):
targets[target] += 1
except KeyError:
targets[target] = 1
targs = [t if targets[t] == 1 else "{0}x {1}".format(targets[t], t) for t in targets]
targs = []
for optarget, count in targets.iteritems():
if count == 1:
targs.append(optarget)
else:
targs.append("{0}x {1}".format(count, optarget))
targs.sort()
tstring = ", ".join(targs)
print op.rjust(20), "=> [{0}]".format(tstring)
print op.rjust(20), "=> [{0}]".format(", ".join(targs))
print "}"

def print_function(func):
@@ -57,11 +61,11 @@ def print_function(func):
while i < n:
op = ord(code[i])
i += 1
print " " * 8 + opcode.opname[op].ljust(18),
print opcode.opname[op].rjust(20),
if op >= opcode.HAVE_ARGUMENT:
arg = _get_argument(co, code, i, op)
i += 2
print arg
print " ({0})".format(arg)
else:
print

@@ -121,8 +125,8 @@ def _make_codes(chain):
args = opcode.cmp_op
else:
raise NotImplementedError(op, opcode.opname[op])
codes.append(args.index(arg))
codes.append(0)
codes.append(args.index(arg) % 256)
codes.append(args.index(arg) // 256)
code = random.choice(chain[op])
return codes, tuple(constants), tuple(varnames)



Loading…
Cancel
Save