Skip to content

Instantly share code, notes, and snippets.

@J4ckKn1ght
Created Feb 22, 2019
Embed
What would you like to do?
def detectR26(i):
for i in range(i - 1, -1, -1):
if 'ldi r26' in data[i]:
tmp = data[i].split()
return int(tmp[2].strip().replace('0x',''), 16)
for n in range(1, 17):
with open("part" + str(n) + ".txt", "r") as f:
data = f.readlines()
data = [line.strip() for line in data]
expression = []
signature = {'char[0]': ['r12'], 'char[1]': ['0x21', '0x3C'], 'char[2]':['r8'], 'char[3]': ['0x31'], 'char[4]':['0x29'], 'char[5]':['1', '0x3C'], 'char[6]':['5', '0x3C'], 'char[7]':['0xD', '0x3C'], 'char[8]':['0x19', '0x3C'], 'char[9]':['0x35'], 'char[10]':['9','0x3C'], 'char[11]':['0x25'], 'char[12]':['0x11', '0x3C'], 'char[13]':['0x15', '0x3C'], 'char[14]':['0x39'], 'char[15]':['0x1D', '0x3C']}
used_char = 0
count = 0
for i in range(len(data)):
pattern = []
if 'call sub_E28' in data[i]:
if ('ldd r21' in data[i - 1]):
pattern.append(data[i - 4].split()[2].replace('Y+',''))
elif 'sbiw r28' in data[i - 1]:
pattern.append(data[i - 1].split()[2])
pattern.append(data[i - 5].split()[2].replace('Y+',''))
else:
pattern.append(data[i - 1].split()[2])
for char, pat in signature.items():
if pat == pattern:
expression += ['(' + char + ' * ' + str(detectR26(i)) + ')']
if 'lsl' in data[i]:
r = data[i].split()[1]
if 'ldi' in data[i - 1]:
value = data[i - 1].split()[2]
if 'sbiw' in data[i - 2]:
pattern.append(data[i - 2].split()[2])
else:
value = '1'
if 'sbiw' in data[i - 1]:
pattern.append(data[i - 1].split()[2])
for j in range(i - 1, -1, -1):
if (('ldd ' + r) in data[j]) or (('movw ' + r) in data[j]):
pattern.append(data[j].split()[2].replace('Y+',''))
break
for char, pat in signature.items():
if pat == pattern:
expression += ['(' + char + ' << ' + value + ')']
print ' + '.join(expr for expr in expression)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment