-
Notifications
You must be signed in to change notification settings - Fork 0
/
SD_recovery_other.py
62 lines (58 loc) · 2.11 KB
/
SD_recovery_other.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
57
58
59
60
61
62
max_bytes = 4000000000 # 4GB
with open("image.dd","r") as inputFile, open("otherRaw.txt","a") as outputFile:
#
#inputFile.seek(17884811,0)
#
total_bytes = 0
megaBytes = 0
totalReadBytes = 0
totalReadMB = 0
while True:
totalReadBytes += 1
if (totalReadBytes / 1000000) >= 1:
totalReadMB += 1
totalReadBytes = 0
print("SCANNED : ",totalReadMB,"MB")
workingChar = inputFile.read(1)
lastRead = inputFile.tell()
if workingChar == "":
if inputFile.tell() > max_bytes:
inputFile.close()
outputFile.close()
sys.exit("end of file reached, terminating program")
elif workingChar == "+":
#print(lastRead)
inputFile.seek(-22,1)
beginFound = False
for x in range(22):
c = inputFile.read(1)
if c == "%":
if inputFile.read(2) == "%\n":
beginFound = True
break
if beginFound:
otherBegin = inputFile.tell()
endFound = False
index = 0
for x in range(175):
index = index + 1
if inputFile.read(1) == "%":
endFound = True
break;
if endFound:
index = index + 1
inputFile.seek(-index,1)
otherSentence = inputFile.read(index)
#print(otherSentence)
outputFile.write(otherSentence)
outputFile.write("\n")
total_bytes += len(otherSentence)
totalReadBytes += len(otherSentence)
if (total_bytes / 1000000) >= 1:
megaBytes += 1
total_bytes = 0
print("FOUND : ",megaBytes,"MB")
else:
inputFile.seek(lastRead + 1,0)
else:
inputFile.seek(lastRead + 1,0)