-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiff.py
More file actions
120 lines (100 loc) · 3.34 KB
/
iff.py
File metadata and controls
120 lines (100 loc) · 3.34 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Copyright (C) 2001 - 2019 David Fillmore
#
# This file is part of buffle.
#
# buffle is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# buffle is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
from string import *
class chunk:
ID = ' '
subID = ' '
length = 0
data = []
def dowrite(self, input=0):
if input != 0:
self.input = input
self.write()
self.length = len(self.data)
if self.length % 2 == 1:
self.data.append(0)
def writeID(self):
return list(self.ID)
def writelen(self):
clen = []
clen.append((self.length >> 24) & 0xff)
clen.append((self.length >> 16) & 0xff)
clen.append((self.length >> 8) & 0xff)
clen.append(self.length & 0xff)
return clen
def readID(self):
id = []
for a in range(4):
id.append(chr(self.data[a]))
id2 = ''.join(id)
return id2
def readlen(self):
string = self.data
len = (((((string[4] << 8) + string[5]) << 8) + string[6]) << 8) + string[7]
return len
def fbnum(self, string):
num = (((((ord(string[0]) << 8) + ord(string[1])) << 8) + ord(string[2])) << 8) + ord(string[3])
return num
def doread(self, data):
len = self.readlen(data)
self.data = []
for a in range(len):
self.data.append(data[a])
self.read()
def read(self):
pass
def write(self):
pass
class authchunk(chunk):
ID = 'AUTH'
class annochunk(chunk):
ID = 'ANNO'
class copychunk(chunk):
ID = '(c) '
class formchunk(chunk):
ID = 'FORM'
data = []
wchunks = []
def write(self):
self.data.append(ord(self.subID[0]))
self.data.append(ord(self.subID[1]))
self.data.append(ord(self.subID[2]))
self.data.append(ord(self.subID[3]))
chunks = self.wchunks # chunks to write
for a in chunks:
cchunk = a() # set cchunk to current chunk
cchunk.dowrite(self.input) # write current chunk's data
id = cchunk.writeID() # set id to current chunk's ID
for b in range(len(id)):
self.data.append(ord(id[b])) # write current chunk's ID to data
clen = cchunk.writelen() # write current
for b in clen:
self.data.append(b)
for b in cchunk.data:
self.data.append(b)
def read(self):
place = 0
datachunk = self.data[8:len(self.data)]
while place < len(self.data):
clen = self.readlen(datachunk)
id = self.readID(datachunk)
datachunk = datachunk[place+8:clen]
try:
cchunk = self.chunks[id]()
except:
cchunk = chunk()
cchunk.read(datachunk)
place += clen
if clen % 2 == 1:
place += 1