Skip to content

Commit

Permalink
CDR: don't depend on file order in zip.
Browse files Browse the repository at this point in the history
  • Loading branch information
ketseh authored and fridrich committed Mar 28, 2021
1 parent 33f408a commit b4dce97
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
3 changes: 2 additions & 1 deletion oletoy/App.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def fload(self,buf="",parent=None,package=None):
if parname == "[content]/dataFileList.dat":
print "Found XMLish CDR version"
self.wtable = self.model.get_value(parent,3).split("\n")
elif "[content/" in parname and ".dat" in parname:
#elif ("[content/" in parname or "[font]/" in parname) and ".dat" in parname:
elif ".dat" in parname:
if self.wdata == None:
self.wdata = {}
p = parname.rfind("/")
Expand Down
25 changes: 15 additions & 10 deletions oletoy/cdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import icc,cmx
from utils import *
import traceback

ri = {0:"Per", 1:"Rel.clr",2:"Sat",3:"Abs.clr"}


Expand Down Expand Up @@ -1949,6 +1950,7 @@ def txsm (hd,size,data):
# 6 -- 0/3, all other versions are 8/x
# 7 -- 2, 8 -- 3, 8bidi,9 -- 4
# 10,11 -- 5; 12 -- 6; 13 -- 8; 14 -- 9; 15 -- b; 16 -- c; 17-21 -- d;
# 22, 23 -- e

off = 0
frameflag = struct.unpack('<i', data[off:off + 4])[0]
Expand Down Expand Up @@ -2350,6 +2352,7 @@ def stlt(data,page,parent):
except:
add_pgiter(page,"Tail","cdr","",data[bkpoff:],parent)
print("stlt exception, see 'tail'")
traceback.print_exc()

cdr_ids = {
"arrw":arrw,
Expand Down Expand Up @@ -2545,6 +2548,7 @@ def load(self, buf, page, parent, offset=0, blocksizes=(),fmttype="cdr"):
print(lcid2txt(lid))
except:
print("Failed to parse 'sumi'")
traceback.print_exc()
if page.version < 16 and (self.fourcc == "outl" or self.fourcc == "fild" or self.fourcc == "fill" or self.fourcc == "arrw" or self.fourcc == "bmpf"):
d_iter = add_dictiter(page,f_iter,d2hex(self.data[0:4]),self.fourcc)
if self.fourcc == "fild" or self.fourcc == "fill":
Expand All @@ -2563,7 +2567,8 @@ def load(self, buf, page, parent, offset=0, blocksizes=(),fmttype="cdr"):
page.hd.width = struct.unpack("<H",self.data[0x1c:0x20])[0]*0.0254
page.hd.height = struct.unpack("<H",self.data[0x20:0x24])[0]*0.0254
except:
print("Oops")
print("Something failed in mcfg v < 16.")
traceback.print_exc()
else:
page.hd.width = struct.unpack("<I",self.data[4:8])[0]/10000
page.hd.height = struct.unpack("<I",self.data[8:12])[0]/10000
Expand All @@ -2574,8 +2579,8 @@ def load(self, buf, page, parent, offset=0, blocksizes=(),fmttype="cdr"):
if self.fourcc == 'page' and fmttype == "cmx":
cmx.parse_page(page,self.data,self.offset+8,f_iter)
if self.fourcc == 'vrsn' and len(self.data) == 2: # ver 16
page.version = struct.unpack("<H",self.data)[0]/100.
print(page.version)
page.version = struct.unpack("<H",self.data)[0]/100.
print(page.version)

page.hd.version = page.version

Expand All @@ -2598,10 +2603,10 @@ def load(self, buf, page, parent, offset=0, blocksizes=(),fmttype="cdr"):
chunk.load(self.data[16:],page,parent,0,(),"cmx")
if name == 'stlt' and page.version >= 7:
try:
# print 'stlt'
stlt(self.data,page,parent)
except:
print("Something failed in 'stlt'.")
traceback.print_exc()
elif name == 'cmpr':
self.cmpr(page,parent,fmttype)
else:
Expand All @@ -2611,8 +2616,7 @@ def load(self, buf, page, parent, offset=0, blocksizes=(),fmttype="cdr"):
chunk.load(buf, page, parent, offset, blocksizes, fmttype)
offset += 8 + chunk.size
elif page.version >= 16:
#try:
if 1:
try:
strid = struct.unpack("<i",self.data[:4])[0]
off1 = struct.unpack("<I",self.data[8:12])[0]
off2 = off1 + struct.unpack("<I",self.data[4:8])[0]
Expand All @@ -2636,7 +2640,8 @@ def load(self, buf, page, parent, offset=0, blocksizes=(),fmttype="cdr"):
try:
stlt("stlt"+data,page,p_iter)
except:
print("Something failed in 'stlt'.")
print "Something failed in 'stlt'."
traceback.print_exc()

if self.fourcc == 'mcfg':
if page.version == 6:
Expand All @@ -2648,6 +2653,6 @@ def load(self, buf, page, parent, offset=0, blocksizes=(),fmttype="cdr"):
else:
page.hd.width = struct.unpack("<I",data[4:8])[0]/10000
page.hd.height = struct.unpack("<I",data[8:12])[0]/10000
#except:
# traceback.print_exc()
# print 'Failed in v16 or v17 dat'
except:
print("Failed in v16 or v17 dat")
traceback.print_exc()
29 changes: 14 additions & 15 deletions oletoy/pkzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
def open(fname,page,parent=None):
try:
dirstruct = {}
iters = []
root_itr = None
z = zipfile.ZipFile(fname,"r")
page.fdata = {}
for i in z.filelist:
Expand All @@ -28,23 +30,20 @@ def open(fname,page,parent=None):
print(fn)
pos = fn.rfind("/")
if pos == -1:
iter = add_pgiter(page,fn,"pkzip",0,data,parent)
name = fn
else:
iter = add_pgiter(page,"[%s]%s"%(fn[:pos],fn[pos:]),"pkzip",0,data,parent)
if "[%s]%s"%(fn[:pos],fn[pos:]) == "[content]/dataFileList.dat":
print("Found XMLish CDR version")
page.wtable = data.split("\n")
elif ".dat" in fn[-4:]:
if page.wdata == None:
page.wdata = {}
page.wdata[fn[pos+1:]] = iter
else:
page.fdata[fn] = iter
for i in page.fdata.values():
data = page.model.get_value(i,3)
name = "[%s]%s"%(fn[:pos],fn[pos:])
itr = add_pgiter(page,name,"pkzip",0,data)
if len(data) > 0:
page.fload(data,i,z)

if "root.dat" in name:
root_itr = (data, itr)
else:
iters.append((data, itr))
if root_itr:
iters.append(root_itr)
for (data, itr) in iters:
page.fload(data, itr)

except zipfile.BadZipfile:
print("Open as PKZIP failed")
except zipfile.LargeZipFile:
Expand Down

0 comments on commit b4dce97

Please sign in to comment.