-
Notifications
You must be signed in to change notification settings - Fork 0
/
namescrabbler
executable file
·164 lines (139 loc) · 4.75 KB
/
namescrabbler
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python
"""namescrabbler.py: Helper utility that encrypts a directory requested by the
user.It assumes a pre compiled picrypt binary is located at /usr/bin/picrypt"""
__author__ = "Minos Galanakis"
__license__ = "GPL v3"
__version__ = "0.0.1"
__email__ = "[email protected]"
__project__ = "PiCrypt"
__date__ = "20-09-2016"
import os
import sys
from random import randint
from subprocess import call, Popen, PIPE
from pprint import pprint
methods = ["sh_array_to_header",
"sh_encrypt_string",
"sh_decrypt_string",
"sh_compare_encrypted_str",
"ab_gb_det",
"ab_breakp_det",
"ab_lvpreld_det",
"hw_msg_init",
"hw_msg_add",
"hw_get",
"hw_free",
"hw_delete",
"hw_cat",
"pc_pi_serial",
"pc_string_slice_from_file",
"pc_soft_machine_id",
"pc_sha1_from_file",
"pc_sha1_from_en_buf",
"pc_sha1_from_en_buf_to_en_buff",
"pc_hash_str",
"pc_hash_enc",
"pc_ram_key",
"hash_low",
"hash_high",
"usr_anti_tamper",
"pc_validate_key",
"sh_print_array",
"sh_parse_header",
"lk_mount",
"lk_encrypt",
"lk_add_keyhcain",
"lk_check_root",
"lk_sanitize_input"]
variables = ["pc_brpoint_det_d",
"pc_serial_rt_d",
"pc_serial_hd_d",
"pc_hardware_id_e",
"pc_hardware_id_d",
"pc_machine_id_hd_e",
"pc_machine_id_rt_e",
"pc_machine_id_rt_d",
"pc_file_seed_hd_e",
"pc_file_sha_hd_e",
"pc_file_sha_rt_e",
"pc_sha_hash_rt_d",
"pc_flag_permitted_d",
"pc_flag_permitted_d",
"pc_hardware_info_d",
"pc_hash_key_e",
"pc_hash_key_d",
"pc_input_token_hd_e",
"pc_tken_sz",
"pc_input_token_rt_e"]
files = ["adb.h",
"authorized_hwd.h",
"hwinfo.h",
"picrypt.h",
"strhide.c",
"strhide.h",
"strhide_test.c",
"adb.c",
"hwinfo.c",
"picrypt.c",
"picrypt.h",
"picrypt_main.c",
"lock.h",
"lock.c",
"strhide.c",
"usr_set_keygen.c",
"ppprocessor.c"]
# Create a pool of allowed characters in random pool
str_int_pool = [chr(n) for n in (range(48, 58) +
range(65, 91) +
range(97, 123))]
str_pool = [chr(n) for n in (range(65, 91) + range(97, 123))]
def sed(fl, string, replace):
""" Call inline sed on file, replacing string with replace argument """
return not call(r'sed -i "s:%s:%s:g" %s' % (string, replace, fl),
shell=True)
def randm_name(prefix):
""" Create a random printable string """
return prefix + "".join([str_int_pool[randint(0, 61)] for x in range(21)])
def random_key_value(input_list):
""" Return a dictionaly with input_list as key and
a random string as value"""
# Ensure the first char is not a number
prefix = str_pool[randint(0, 51)]
rv = ({k: randm_name(prefix) for k in input_list})
while True:
if len(rv) != len(set(rv)):
print("Found conflicts")
# Find the double elements
cnflcts = set([n for n in rv.values() if rv.values().count(n) > 1])
# Find the keys coresponding to the values
conficting_keys = [k for k in rv.keys() if rv[k] in cnflcts]
# Recreate the random names and test again
for ck in conficting_keys:
rv[ck] = randm_name(prefix)
continue
else:
break
return rv
def random_vars():
""" Get the random key-value dictionary for variables """
return random_key_value(variables)
def random_fn():
""" Get the random key-value dictionary for functions """
return random_key_value(methods)
def random_everything():
""" Get the random key-value dictionary for everything """
return random_key_value(variables + methods)
if __name__ == "__main__":
random_seeds = random_everything()
print("%s Changing Symbol Names: %s" % ("*" * 21, "*" * 21))
for pre, post in random_seeds.iteritems():
print("%s%s-->%s%s" % (pre, " " * (30 - len(pre)), " " * 10, post))
# Inline edit the files
for f in files:
for k, v in random_seeds.iteritems():
if not (sed(f, k, v)):
print("Failed setting %s %s at %s" % (k, v, f))
# Create an emtpy status file
with open("namescrabbler_done", "w") as F:
F.write("\n")
print "%s Done! %s" % ("*" * 29, "*" * 29)