-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextractDJI.py
More file actions
73 lines (62 loc) · 1.92 KB
/
extractDJI.py
File metadata and controls
73 lines (62 loc) · 1.92 KB
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
# python3
# writer : Mingyu Seong
# 2022 12 05
import zlib, struct, os
###################################
INPUT_FILENAME = "mini2_dji.DAT"
OUTPUT_PATH = "./output/"
###################################
def isDJIDat(buf):
if(buf[0] == 0x78 and buf[1] == 0x9c):
return True
else:
return False
def getStrings(buf, offset):
bStringData = ""
while True:
if buf[offset] == 0:
break
else:
bStringData += chr(buf[offset])
offset += 1
return bStringData
def mkdirFromFilename(outputBase, filename):
a = filename.split("/")
a.pop()
fileDirPath = "/".join(a)
os.makedirs(outputBase+fileDirPath, exist_ok=True)
def extractDJI_main(INPUT_FILENAME, OUTPUT_PATH, strResult):
with open(INPUT_FILENAME, "rb") as f:
data = f.read()
if(isDJIDat(data)):
dedata = zlib.decompress(data)
#f = open('test.dat', "wb")
#f.write(dedata)
#f.close
remain = len(dedata)
while(remain > 0):
try:
uncompressedFileLength = struct.unpack("<I",dedata[1:5])[0]
#print(uncompressedFileLength)
filename = getStrings(dedata, 7)
print(filename)
mkdirFromFilename(OUTPUT_PATH, filename)
payload = dedata[283:uncompressedFileLength+283]
f = open(OUTPUT_PATH+filename, "wb")
f.write(payload)
f.close
dedata = dedata[uncompressedFileLength+283:]
remain = len(dedata)
#print(len(remain))
except Exception as e:
print(e)
raise
strResult += "Done.\n"
print("Done.")
else:
strResult += "This is not DJI DAT.\n"
print("This is not DJI DAT.")
exit()
return strResult
if __name__ == '__main__':
extractDJI_main(INPUT_FILENAME, OUTPUT_PATH)