-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhxdump.py
56 lines (43 loc) · 1.32 KB
/
hxdump.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
from curses.ascii import isascii
import enum
import os
def read_bin(filename: str):
print('BINARY CONTENT OF ' + filename)
size = os.stat(filename).st_size
print('SIZE OF FILE ' + str(size))
with open(filename, "rb") as file:
row = file.read(16)
big = 2 << 28
prev_size = 0
while row:
print(hex(big + prev_size)[3:] + ': ', end='')
prev_size += len(row)
str_content = ' |'
delim = ['', ' ']
i = 0
for byte in row:
out = hex(byte + 256)[3:]
print(out, end=delim[i])
i ^= 1
ch = chr(byte)
if ch.isascii() and ch.isprintable():
str_content += ch
else:
str_content += '.'
str_content += '|'
print(str_content)
row = file.read(16)
# Prints content of local files with extension .sdocx
working_dir = os.getenv("pwd")
print(working_dir)
aboba = os.scandir(working_dir)
todos = []
for f in aboba:
_, ext = os.path.splitext(f)
if f.is_file() and ext == ".sdocx":
todos.append(os.path.abspath(f))
for idx, el in enumerate(todos):
print(idx, el)
choice = int(input())
#read_bin(todos[choice])
read_bin('text.txt')