This repository was archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathniraimarshal.py
81 lines (64 loc) · 2.07 KB
/
niraimarshal.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from cStringIO import StringIO
import marshal
import struct
import types
# For obfuscation, we prepend 0x45 to the code so the interpreter knows it's obfuscated.
# Note 0x45 isn't a valid opcode.
def niraicall_obfuscate(code):
print '''Error:
niraicall_obfuscate not implemented
Add it to your make file:
def niraicall_obfuscate(code):
...
niraimarshal.niraicall_obfuscate = niraicall_obfuscate
Input: string
Output: (bool, string)
bool indicates whether the string has been obfuscated or not
if True, OBFS is prepend to string
if False, string is ignored
See sample project for help
'''
raise NotImplementedError('niraicall_obfuscate not implemented')
def obfuscate(x):
obfuscated, code = niraicall_obfuscate(x)
if obfuscated:
return '\x45' + code
else:
return x
def dump(value, file):
if isinstance(value, types.CodeType):
dump_code(value, file)
elif type(value) in (list, tuple):
# print 'list or tuple'
file.write('[' if type(value) == list else '(')
file.write(struct.pack('<I', len(value)))
for x in value:
dump(x, file)
elif type(value) == dict:
print 'dict'
file.write('{')
for k, v in value.items():
dump(k, file)
dump(v, file)
file.write('0')
else:
file.write(marshal.dumps(value))
def dump_code(value, file):
file.write(struct.pack(
'<cIIII', 'c', value.co_argcount, value.co_nlocals,
value.co_stacksize, value.co_flags))
code = value.co_code
dump(obfuscate(code), file)
dump(value.co_consts, file)
dump(value.co_names, file)
dump(value.co_varnames, file)
dump(value.co_freevars, file)
dump(value.co_cellvars, file)
dump(value.co_filename, file)
dump(value.co_name, file)
file.write(struct.pack('<I', value.co_firstlineno))
dump(value.co_lnotab, file)
def dumps(value):
sio = StringIO()
dump(value, sio)
return sio.getvalue()