forked from cryptax/misc-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb64script.py
More file actions
41 lines (33 loc) · 1.55 KB
/
b64script.py
File metadata and controls
41 lines (33 loc) · 1.55 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
from com.pnfsoftware.jeb.client.api import IScript, IGraphicalClientContext, IUnitView
from com.pnfsoftware.jeb.core.units import IUnit, IXmlUnit
from com.pnfsoftware.jeb.core.units.code.android import IDexUnit
from com.pnfsoftware.jeb.core import RuntimeProjectUtil
from com.pnfsoftware.jeb.core.units import IInteractiveUnit
import base64
'''
This is a JEB script to automatically perform Base64 decoding of a selected string
in the disassembly / decompiled class
Adds the decoded string as comment
Coded with inspiration from https://github.com/pnfsoftware/jeb2-samplecode/blob/master/scripts/TranslateString.py :)
'''
class b64script(IScript):
def run(self, ctx):
f = ctx.getFocusedFragment()
if not f:
print("[-] Select a text (no focused fragment)")
return
sel = f.getSelectedText() or f.getActiveItemAsText()
if not sel:
print("[-] Select a text (no selected text)")
return
b64encoded_string = sel.strip(' \'\"')
b64decoded_string = self.decode(b64encoded_string)
print("Base64 decoding: {} --> {}".format(b64encoded_string, b64decoded_string))
a = f.getActiveAddress()
if a and isinstance(f.getUnit(), IInteractiveUnit):
comment0 = f.getUnit().getComment(a)
comment = b64decoded_string + '\n' + comment0 if comment0 else b64decoded_string
f.getUnit().setComment(a, comment)
def decode(self, thestring):
# print("Base64 decoding: {}".format(thestring)
return base64.b64decode(thestring)