-
Notifications
You must be signed in to change notification settings - Fork 3
/
pageSeparator.py
executable file
·51 lines (40 loc) · 1.09 KB
/
pageSeparator.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
#!/usr/bin/python
import sys
import os
if len(sys.argv) != 2 or sys.argv[1]=="-h":
print "Error, missing parameter"
print sys.argv[0] + " dir "
print "Divide pages-1.img in pages of 4096 Byte."
exit()
dir = sys.argv[1]
os.system("mkdir pages_separated_" + dir)
os.system("cp pages-1.img " + "pages_separated_" + dir)
os.chdir("pages_separated_" + dir)
f = open("pages-1.img", "rb")
i = -1
npage = 0
emptyByte = 0
emptyPages = 0
try:
byte = f.read(1)
while byte != b"":
i+=1
#print str(i)
if i == 0:
#print str(npage)
fw = open("page-%06d" %(npage), "w")
npage += 1
emptyByte = 0
fw.write(byte)
if ord(byte) | 0x0 == 0x0:
emptyByte += 1
if i == 4095:
i = -1
fw.close()
if emptyByte == 4096:
os.system("mv page-%06d" %(npage-1) + " page-%06d" %(npage-1) + "_empty")
emptyPages +=1
byte = f.read(1)
finally:
f.close()
print "Total Pages: " + str(npage) + " Empty Pages: " + str(emptyPages)