-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.py
49 lines (43 loc) · 1.36 KB
/
helpers.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
from string import ascii_uppercase, ascii_lowercase, digits
def pattern_gen(length):
pattern = ""
for upper in ascii_uppercase:
for lower in ascii_lowercase:
for digit in digits:
if len(pattern) < length:
pattern += upper + lower + digit
else:
out = pattern[:length]
return out
return pattern[:length]
def pattern_search(search_pattern):
needle = search_pattern
try:
if needle.startswith("0x"):
needle = needle[2:]
needle = bytearray.fromhex(needle).decode("ascii")
needle = needle[::-1]
except (ValueError, TypeError) as e:
raise
haystack = ""
for upper in ascii_uppercase:
for lower in ascii_lowercase:
for digit in digits:
haystack += upper + lower + digit
found_at = haystack.find(needle)
if found_at > -1:
return found_at
def return_pretty_hex(data):
prettier = ""
for char in data:
is_missing = False
if type(char) != int:
char = ord(char)
if char < 16:
is_missing = True
char = hex(char)
char = char[1:]
if is_missing:
char = char[0] + '0' + char[1:]
prettier += '\\' + str(char)
return prettier