-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharX.py
51 lines (40 loc) · 1.39 KB
/
harX.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
import os
import sys
def find_png_chunks(file_path):
with open(file_path, 'rb') as file:
data = file.read()
magic = b'\x89\x50\x4E\x47' # PNG magic value
start = 0
chunk_count = 1
while True:
# Find the next occurrence of the PNG magic
chunk_start = data.find(magic, start)
if chunk_start == -1:
break
# Find the end of the chunk
chunk_end = data.find(magic, chunk_start + 1)
if chunk_end == -1:
chunk_end = len(data)
# Extract the chunk
chunk = data[chunk_start:chunk_end]
start = chunk_end
# Save the chunk as a PNG file
filename = f"extracted{chunk_count}.png"
with open(filename, 'wb') as output_file:
output_file.write(chunk)
chunk_count += 1
# If the chunk end is the end of the file, break the loop
if chunk_end == len(data):
break
# Check if the file path is provided as a command-line argument
if len(sys.argv) < 2:
print("== HAR eXtractor ==")
print("Usage: python harX.py file_path")
else:
file_path = sys.argv[1]
with open(file_path, 'rb') as file:
header = file.read(4)
if header == b'\x48\x41\x52\x43':
find_png_chunks(file_path)
else:
print("Invalid file.")