Skip to content

Commit bd374b1

Browse files
committed
Updated.
1 parent 8a0d65d commit bd374b1

File tree

5 files changed

+90
-77
lines changed

5 files changed

+90
-77
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
env/
2+
keys.reg

bluetooth_fix.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import configparser
2+
import argparse
3+
4+
5+
def _parse_args():
6+
"""Parse arguments."""
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument(
9+
'--reg_path', help='Path to reg file.', default='keys.reg')
10+
11+
return parser.parse_args()
12+
13+
14+
def _open_reg_file(file_path):
15+
""" Open file at given path and return as config option."""
16+
config = configparser.ConfigParser()
17+
config.read_file(open(file_path))
18+
19+
return config
20+
21+
22+
def _insert_mac_colons(mac):
23+
""" Bluetooth Mac directory file name."""
24+
mac = mac.upper()
25+
mac_parts = [mac[i:i + 2] for i in range(0, len(mac), 2)]
26+
# import pdb; pdb.set_trace()
27+
return ':'.join(mac_parts)
28+
29+
30+
def _bluetooth_dir_name(section_name):
31+
""" Return the bluetooth directory name."""
32+
full_path = section_name.split('\\')
33+
last_two_macs = full_path[-2:]
34+
path_parts = []
35+
for mac in last_two_macs:
36+
path_parts.append(_insert_mac_colons(mac))
37+
38+
return '/'.join(path_parts)
39+
40+
41+
def _format_ltk(ltk):
42+
""" Convert LTK to uppercase and remove commas."""
43+
return ltk.lstrip('hex:').upper().replace(',', '')
44+
45+
46+
def _process_reg_file(config):
47+
""" Process the reg file."""
48+
sections = config.sections()
49+
for section in sections:
50+
if len(config[section]) != 10:
51+
continue
52+
print('\n')
53+
print('Dir Name: /usr/lib/bluetooth/{}'.format(
54+
_bluetooth_dir_name(section)))
55+
print('LongTermKey: {}'.format(_format_ltk(config[section]['LTK'])))
56+
print('\n====================================\n')
57+
58+
59+
def main():
60+
""" Main entrypoint to script. """
61+
args = _parse_args()
62+
config = _open_reg_file(args.reg_path)
63+
_process_reg_file(config)
64+
65+
66+
if __name__ == '__main__':
67+
main()
68+
69+
70+
# reg_str = reg_file_to_str('/home/mark/Desktop/BTKeys.reg')
71+
# file_path_to_dict(reg_str)
72+
73+
74+
75+
# Print

bluetooth_sort.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

convert_file_encoding.py renamed to clean_reg_file.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ def _reg_file_to_str(file_path):
1919
return file_str
2020

2121

22+
def _clean(contents):
23+
""" Clean contents and return."""
24+
contents = contents.replace('"', '')
25+
lines = contents.split('\r\n')
26+
del lines[0]
27+
new_lines = []
28+
for line in lines:
29+
new_lines.append(line.strip())
30+
31+
return '\n'.join(new_lines)
32+
33+
34+
2235
def _save_str_to_file(contents, file_path):
2336
"""Save the string as a file."""
2437
with open(file_path, 'wb') as f:
@@ -29,6 +42,7 @@ def main():
2942
"""Main entrypoint to script."""
3043
args = _parse_args()
3144
file_contents = _reg_file_to_str(args.file_path)
45+
file_contents = _clean(file_contents)
3246
_save_str_to_file(file_contents, args.output)
3347

3448

output.txt

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)