-
Notifications
You must be signed in to change notification settings - Fork 1
/
encode.py
65 lines (50 loc) · 1.37 KB
/
encode.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
63
64
import sys
import pprint
import struct
from conv import TypeConv
def encode(decodedfile,outfile,size):
utags = []
te = TypeConv()
data = None
with open(decodedfile,'r') as f:
data = f.read()
if not data:
print "Bad input data"
return 2
try:
data = eval(data)
except SyntexError, e:
print "Parse issues"
print str(e)
return 3
pprint.pprint(data)
with open(outfile,'wb') as f:
#initialize file with all zeros
f.write('\x00'*size)
f.seek(0)
# write the Header
te.encodeName(f,"__UTAG_HEAD__")
f.write('\x00'*12) #blank size,flags or utility
#write utags
for utag in data:
te.encode(utag,f)
# write the Tail
te.encodeName(f,"__UTAG_TAIL__")
f.write('\x00'*12) #blank size,flags or utility
return 0
def usage():
print "Usage: python",__file__,"<decodeddata> <outfile> <size>"
print "\tdecodeddata: decoded data file"
print "\t outfile: resultant filname for the encoded image"
print "\t size: size of image\n"
def main():
try:
infile = sys.argv[1]
outfile = sys.argv[2]
size = int(sys.argv[3])
except IndexError,TypeError:
usage()
return 1
return encode(infile,outfile,size)
if __name__=='__main__':
sys.exit(main())