-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAnnotate_Stack_Strings_In_Selection.py
More file actions
54 lines (41 loc) · 1.21 KB
/
Annotate_Stack_Strings_In_Selection.py
File metadata and controls
54 lines (41 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# vim: set fileencoding=utf-8 :
# «Annotate Stack Strings In Selection» for Hopper 4
# Copyright (c) 2018, Daniel Roethlisberger <daniel@roe.ch>
# https://github.com/droe/hopper-scripts
#
# Annotate stack strings in the current selection with their decoded string
# form. Supports XOR decryption using a single or multi-byte key and no
# feedback.
import hopper_api as api
import binascii
from itertools import cycle
def unhexlify(s):
if len(s) % 2 != 0:
s = '0' + s
return binascii.unhexlify(s)
def xorcrypt(buf, key):
if len(key) == 0:
return buf
k = cycle(key)
return bytes(b ^ next(k) for b in buf)
def main():
ans = api.ask_hex("XOR key in hex (optional)")
if ans == None:
return
if len(ans) == 0:
key = '\x00'
else:
key = unhexlify(ans)
for ins in api.selection().instructions():
if ins.op in ('mov', 'movabs'):
data = ins.arg(1)
else:
continue
if not data.startswith('0x'):
continue
data = unhexlify(data[2:])
data = reversed(data)
data = xorcrypt(data, key)
api.set_icomment(ins.addr, repr(data))
if __name__ == '__main__':
api.run(main)