示例#1
0
文件: App.py 项目: renyxa/re-lab
	def fload(self,buf="",parent=None,package=None):
		self.pname = os.path.split(self.fname)[1]
		f = None
		if buf == "":
			offset = 0
			f = open(self.fname,"rb")
			buf = f.read()

		if buf[0:7] == "\0\0IIXPR" or buf[0:7] == "\0\0MMXPR":
			self.type = qxp.open(self, buf, parent)
			return 0

		if buf[:8] == "\x89PNG\x0d\x0a\x1a\x0a":
			self.type = pngot.open(self, buf, parent)
			return 0

		if buf[0:6] == "\x1aWLF10":
			self.type = vfb.open(self, buf, parent)
			return 0

		if buf[0:6] == "<?xml " or buf[0:14] == "\xff\xfe<\0?\0x\0m\0l\0 \0" or buf[0:14] == "\xfe\xff\0<\0?\0x\0m\0l\0 ":
			self.type = otxml.open(buf, self, parent)
			return 0

		if buf[0:8] == "CPT9FILE":
			self.type = cpt.open(buf, self, parent)
			return 0

		if buf[0:8] == "VjCD0100":
			self.type = chdraw.open(self, buf, parent)
			return 0

		if buf[0:4] == "EVHD":
			self.type = yep.parse(self, buf, parent)
			return 0

		if buf[0:4] == "XPIH":
			self.type = yep.parse_ppi(self, buf, parent)
			return 0

		if buf[0:5].lower() == "{\\rtf":
			self.type = rtf.open(buf, self, parent)
			return 0

		if buf[0:8] == "\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1":
			self.type = ole.ole_open(buf, self, parent)
			return 0

		if buf[0:18] == "Visio (TM) Drawing":
			self.type = vsd.parse(self, buf, parent)
			return 0

		if buf[0:2] == "\x50\xc3":
			self.type = "CLP"
			clp.open (buf,self, parent)
			return 0

		if buf[0:6] == "VCLMTF":
			self.type = "SVM"
			svm.open (buf,self, parent)
			return 0

		if buf[:4] == "\x12\x90\xa8\x7f":
			nki.open(self,buf,parent)
			return 0

#		This one should be before CDR to properly handle v17
		if parent != None:
			parname = self.model.get_value(parent,0)
			if parname == "[content]/dataFileList.dat":
				print "Found XMLish CDR version"
				self.wtable = self.model.get_value(parent,3).split("\n")
			#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("/")
				self.wdata[parname[p+1:]] = parent

		if buf[0:4] == "RIFF" and buf[8:11].lower() == "cdr":
			self.type = "CDR%x"%(ord(buf[11])-0x30)
			print ('Probably CDR')
			cdr.cdr_open(buf,self, parent)
			print (self.version)
			return 0

		if buf[0:4] == "RIFF" and buf[8:11] == "CMX":
			self.type = "CMX"
			cdr.cdr_open(buf,self, parent,"cmx")
			return 0

		if buf[0:2] == "WL":
			self.type = "CDR2"
			wld.open (buf,self, parent)
			return 0

		if buf[0:2] == "\xcc\xdc":
			self.type = "CPL"
			cpl.open (buf,self, parent)
			return 0

		if buf[0:4] == "8BGR":
			self.type = "BGR"
			abr.abr_open(buf,self, parent,"bgr")
			return 0

		if buf[4:8] == "8BIM":
			self.type = "ABR"
			abr.abr_open(buf,self, parent,"abr")
			return 0

		if buf[0:4] == "\xd7\xcd\xc6\x9a":
			self.type = "APWMF"
			mf.mf_open(buf,self, parent)
			print ("Aldus Placeable WMF")
			return 0

		if buf[0:8] == "\x4c\x00\x52\x00\x46\x00\x00\x00":
			self.type = "LRF"
			lrf.open(buf, self, parent)
			print ("LRF")
			return 0

		if buf[0:6] == "\x01\x00\x09\x00\x00\x03":
			self.type = "WMF"
			print ("Probably WMF")
			mf.mf_open(buf,self, parent)
			return 0

		if buf[40:44] == "\x20\x45\x4d\x46":
			self.type = "EMF"
			print ("Probably EMF")
			mf.mf_open(buf,self, parent)
			return 0

		if buf[0:2] =="KF" and buf[2] != "\x00":
			self.type = "CDW"
			print ("Probably CDW")
			cdw.open(buf,self, parent)
			return 0

		if buf[0:4] == "CAT " and buf[0x8:0xc] == "REX2":
			self.type = "REX2"
			print ("Probably REX2")
			rx2.open(buf,self, parent)
			return 0

		if buf[0:20] == "Kaydara FBX Binary  ":
			self.type = "FBX"
			print ("Probably FBX")
			fbx.open(buf,self, parent)
			return 0

		if buf[4:19] == "Standard Jet DB" or buf[4:19] == "Standard ACE DB":
			self.type = "MDB"
			print ("Probably MDB")
			mdb.parse (buf,self, parent)
			return 0

		if buf[0:4] == "\x50\x4b\x03\x04":
			self.type = "PKZIP"
			print ("Probably PK-ZIP")
			if f:
				f.close()
			pkzip.open (self.fname,self, parent)
			return 0

		palmtype = buf[0x3c:0x44]
		if palmtype in palm.palm_types.keys():
			self.type = "PALM"
			print ("Probably Palm e-book")
			palm.open(buf, self, parent, palmtype)
			return 0

		if buf[2:10] == 'BOOKDOUG':
			self.type = 'IMP'
			print ('Probably SoftBook e-book')
			sbimp.open(buf, self, parent)
			return 0

		if buf[0:8] == 'ITOLITLS':
			self.type = 'LIT'
			print ('Probably LIT')
			lit.open(buf,self,parent)
			return 0

		if buf[0:6] == 'bplist':
			self.type = 'PLIST'
			print ('Probably PLIST')
			plist.open(buf,self,parent)
			return 0

		fh_off = buf.find('FreeHand')
		if buf[0:3] == 'AGD':
			agd_off = 0
			agd_ver = ord(buf[agd_off+3])
			try:
				self.type = "FH"
				print ("Probably Freehand")
				fh.fh_open(buf,self)
				return 0
			except:
				print ("Check for Freehand failed...")
		elif fh_off != -1:
			agd_off = buf.find('AGD')
			if agd_off > fh_off:
				agd_ver = ord(buf[agd_off+3])
				try:
					self.type = "FH"
					print ("Probably Freehand 9+")
					fh.fh_open(buf,self, parent)
					return 0
				except:
					print ("Check for Freehand 9+ failed...")
		if buf[0:4] == "FHD2" or buf[0:4] == "acf3":
			self.type = "FH12"
			fh12.fh_open(buf, self, parent, 0)
			return 0
		if buf[0:2] == "FH":
			fh_off = buf.find('FHDocHeader')
			if fh_off != -1:
				try:
					self.type = "FH"
					print ("Probably Freehand <5")
					fh.fh_open(buf, self, parent, 0)
					return 0
				except:
					print ("Check for Freehand <5 failed...")
		if buf[8:11] == 'xV4':
			self.type = 'ZMF'
			print ('Probably Zoner Draw 4+')
			zmf.zmf4_open(buf, self, parent)
			return 0

		# NOTE: 0x29a is 666 in decimal .-)
		if buf[0:2] == '\x9a\x02' and buf[2:4] in ['\01\0', '\02\0', '\03\0', '\04\0']:
			self.type = 'ZBR'
			print ('Probably Zebra Metafile')
			zbr.open(buf, self, parent)
			return 0

		if buf[0:9] == 'ZonerBMIa':
			self.type = 'BMI'
			print ('Probably Zoner Bitmap')
			bmi.open(buf, self, parent)
			return 0

		size = (ord(buf[1]) | (ord(buf[2]) << 8)) + 4
		if buf[0] == '\0' and (size == len(buf) or (size < len(buf) and buf[4:7] == "\x80\x80\x04")):
			self.type = 'IWA'
			if not self.subtype:
				self.subtype = iwa.detect(package)
			print('Probably Apple iWork file')
			iwa.open(buf, self, parent, self.subtype)
			return 0

		if buf[0:0x17] == 'Software602\r\nCalc602 v.' and (buf[0x1c:0x24] == 'Tabulka\x1a' or buf[0x1c:0x21] == 'Graf\x1a'):
			self.type = 'C602'
			print('Probably C602 file')
			if buf[0x1c] == 'T':
				c602.parse_spreadsheet(buf, self, parent)
			else:
				c602.parse_chart(buf, self, parent)
			return 0

		if re.match('@[A-Z]{2} .*?\\r\\n', buf) and buf[-1] == '\x1a':
			self.type = 'T602'
			print('Probably T602 file')
			t602.parse(buf, self, parent)
			return 0
		if buf[0:4] == "\0\0\x02\0":
			if (buf[4]=='\x20' or buf[4]=='\x21') and buf[5]=='\x51':
				self.type = 'QUWQ'
				print('Probably Quattro Wq file')
				quattro_wq.wq_open(self, buf, parent)
				return 0

		# QuarkXPress 1.x data fork
		if buf[0:4] == '\x00\x1c\x00\x1c' or buf[0:4] == '\x00\x20\x00\x20':
			try:
				qxp.open_v1(self,buf,parent)
				self.type = 'QXP5'
				return 0
			except:
				print ("Failed after attempt to parse as QXP1...")
		if buf[0:4] == '\x00\x26\x00\x26':
			try:
				qxp.open_v2(self,buf,parent)
				self.type = 'QXP5'
				return 0
			except:
				print ("Failed after attempt to parse as QXP2...")

		if parent == None:
			parent = add_pgiter(self, "File", "file","unknown",buf)

		# Likely false detection for DRW
		if buf[0:3] == "\x01\xff\x02":
			try:
				drw.open(self,buf,parent)
				self.model.set_value(parent, 0, "DRW")
			except:
				print ("Failed after attempt to parse as DRW...")
		if buf[0:4] == "\xe7\xac\x2c\x00":
			self.type = 'pub1'
			print('Probably publisher 1 file')
			publisher1.publisher_open(self, buf, parent)

		return 0
示例#2
0
文件: cmd.py 项目: rgwan/re-lab
def parse (cmd, entry, page):
	if cmd[0] == "$":
		pos = cmd.find("@")
		if pos != -1:
			chtype = cmd[1:pos]
			chaddr = cmd[pos+1:]
		else:
			chtype = cmd[1:]
			chaddr = "0"
		print "Command: ",chtype,chaddr
		
		treeSelection = page.view.get_selection()
		model, iter1 = treeSelection.get_selected()
		if iter1 == None:
			page.view.set_cursor_on_cell(0)
			treeSelection = page.view.get_selection()
			model, iter1 = treeSelection.get_selected()
		buf = model.get_value(iter1,3)

		if "ole" == chtype.lower():
			if buf[int(chaddr,16):int(chaddr,16)+8] == "\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1":
				ole.ole_open (buf[int(chaddr,16):],page,iter1)
			else:
				print "OLE stream not found at ",chaddr
		elif "bmp" == chtype.lower():
			#try:
			if 1:
				addr,bpp,w,h = chaddr.split(":")
				dib_data = "\x28\x00\x00\x00"+struct.pack("<I",int(w))+struct.pack("<I",int(h))+"\x01\x00"
				dib_data += struct.pack("<H",int(bpp))+"\x00"*8+struct.pack("<I",160)*2+"\x00"*8
				dib_data += buf[int(addr,16):]
				iter2 = add_pgiter (page,"[BMP]","escher","Blip",dib2bmp(dib_data),iter1)
				model.set_value(iter2,1,("escher","odraw","Blip"))
			#except:
			#	print 'Failed to construct DIB data'
		elif "b64" == chtype.lower():
			b64decode (page,buf[int(chaddr,16):],iter1)
		elif "cvx" == chtype.lower():
			cvx.parse (page,buf[int(chaddr,16):],iter1)
		elif "esc" == chtype.lower():
			escher.parse (model,buf[int(chaddr,16):],iter1)
		elif "cmx" == chtype.lower():
			cdr.cdr_open (buf[int(chaddr,16):],page,iter1)
		elif "icc" == chtype.lower():
			icc.parse (page,buf[int(chaddr,16):],iter1)
		elif "cdx" == chtype.lower():
			chdraw.open (page,buf[int(chaddr,16):],iter1)
		elif "yep" == chtype.lower():
			yep.parse (page,buf[int(chaddr,16):],iter1)
		elif "yep0" == chtype.lower():
			yep.parse (page,buf[int(chaddr,16):],iter1,0)
			
		elif "emf" == chtype.lower():
			pt = page.type
			page.type = "EMF"
			mf.mf_open (buf[int(chaddr,16):],page,iter1)
			page.type = pt
		elif "pix" == chtype.lower():
#			try:
				off = int(chaddr,16)
				ntype = model.get_value(iter1,1)
				if off:
					iter2 = add_pgiter(page,"Picture","escher","Blip",buf[off:],iter1)
					model.set_value(iter2,1,("escher","odraw","Blip"))
				else:
					model.set_value(iter1,1,("escher","odraw","Blip"))
					page.hd.hv.parent.on_row_activated(page.hd.hv,model.get_path(iter1),None)
#			except:
#				print "Failed to add as a picture"
		elif "dump" == chtype.lower():
			dlg = gtk.FileChooserDialog('Save...', action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK,gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL))
			dlg.set_local_only(True)
			resp = dlg.run()
			fname = dlg.get_filename()
			dlg.hide()
			if resp != gtk.RESPONSE_CANCEL:
				nlen = model.get_value(iter1,2)
				if chaddr != 0:
					pos = chaddr.find(":")
					if pos != -1:
						endaddr = chaddr[pos+1:]
						chaddr = chaddr[:pos]
						value = model.get_value(iter1,3)[int(chaddr,16):int(endaddr,16)]
					else:
						value = model.get_value(iter1,3)[int(chaddr,16):]
				else:
					value = model.get_value(iter1,3)[int(chaddr,16):]

				if nlen != None:
					f = open(fname,'wb')
					f.write(value)
					f.close()
				else:
					print "Nothing to save"
		elif "wmf" == chtype.lower() or "apwmf" == chtype.lower():
			pt = page.type
			page.type = chtype.upper()
			mf.mf_open (buf[int(chaddr,16):],page,iter1)
			page.type = pt
		elif "xls" == chtype.lower():
			ch2 = chaddr[1]
			if ch2.isdigit():
				coladdr = ord(chaddr[0].lower()) - 97
				rowaddr = int(chaddr[1:]) - 1
			else:
				coladdr = 26*(ord(chaddr[0].lower()) - 96)+ ord(chaddr[1].lower()) - 97
				rowaddr = int(chaddr[2:]) - 1
			page.search = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_INT)
			model.foreach(xlsfind,(page,rowaddr,coladdr))
			page.show_search("XLS: cell %s"%chaddr)
		elif "rx2" == chtype.lower():
			newL = struct.unpack('>I', buf[int(chaddr,16)+4:int(chaddr,16)+8])[0]
			rx2.parse (model,buf[int(chaddr,16):int(chaddr,16)+newL],0,iter1)
		elif "dib" == chtype.lower():
			iter2 = add_pgiter (page,"[BMP]","",0,dib2bmp(buf[int(chaddr,16):]),iter1)
			model.set_value(iter2,1,("escher","odraw","Blip"))
		elif "pct" == chtype.lower():
			pict.parse (page,buf,iter1)
		elif "pm6" == chtype.lower():
			off = int(chaddr,16)
			pm6.open (page,buf,iter1,off)
		elif "vba" == chtype.lower():
			# off = int(chaddr,16)
			vba.parse (page,buf,iter1)
		elif "zip" == chtype.lower():
			try:
				print int(chaddr,16)
				decobj = zlib.decompressobj()
				output = decobj.decompress(buf[int(chaddr,16):])
				add_pgiter (page,"[Decompressed data]","",0,output,iter1)
				tail = decobj.unused_data
				if len(tail) > 0:
					add_pgiter (page,"[Tail]","",0,tail,iter1)
			except:
				print "Failed to decompress"

	elif cmd[0] == "?":
		ctype = cmd[1]
		carg = cmd[2:]
		# convert line to hex or unicode if required
		data = arg_conv(ctype,carg)
		model = page.view.get_model()
		page.search = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_INT)
		if ctype == 'r' or ctype == 'R':
			model.foreach(recfind,(page,data))
		else:
			model.foreach(cmdfind,(page,data))
		page.show_search(carg)
示例#3
0
文件: viewCmd.py 项目: renyxa/re-lab
def parse (cmd, entry, page):
	if cmd[0] == "$":
		pos = cmd.find("@")
		if pos != -1:
			chtype = cmd[1:pos]
			chaddr = cmd[pos+1:]
		else:
			chtype = cmd[1:]
			chaddr = "0"
		print("Command: ",chtype,chaddr)
		
		treeSelection = page.view.get_selection()
		model, iter1 = treeSelection.get_selected()
		if iter1 == None:
			page.view.set_cursor_on_cell(0)
			treeSelection = page.view.get_selection()
			model, iter1 = treeSelection.get_selected()
		buf = model.get_value(iter1,3)

		if "ole" == chtype.lower():
			if buf[int(chaddr,16):int(chaddr,16)+8] == "\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1":
				ole.ole_open (buf[int(chaddr,16):],page,iter1)
			else:
				print("OLE stream not found at ",chaddr)
		elif "bmp" == chtype.lower():
			#try:
			if 1:
				addr,bpp,w,h = chaddr.split(":")
				dib_data = "\x28\x00\x00\x00"+struct.pack("<I",int(w))+struct.pack("<I",int(h))+"\x01\x00"
				dib_data += struct.pack("<H",int(bpp))+"\x00"*8+struct.pack("<I",160)*2+"\x00"*8
				dib_data += buf[int(addr,16):]
				iter2 = add_pgiter (page,"[BMP]","escher","Blip",dib2bmp(dib_data),iter1)
				model.set_value(iter2,1,("escher","odraw","Blip"))
			#except:
			#	print 'Failed to construct DIB data'
		elif "b64" == chtype.lower():
			b64decode (page,buf[int(chaddr,16):],iter1)
		elif "cvx" == chtype.lower():
			cvx.parse (page,buf[int(chaddr,16):],iter1)
		elif "esc" == chtype.lower():
			escher.parse (model,buf[int(chaddr,16):],iter1)
		elif "cmx" == chtype.lower():
			cdr.cdr_open (buf[int(chaddr,16):],page,iter1)
		elif "icc" == chtype.lower():
			icc.parse (page,buf[int(chaddr,16):],iter1)
		elif "cdx" == chtype.lower():
			chdraw.open (page,buf[int(chaddr,16):],iter1)
		elif "yep" == chtype.lower():
			yep.parse (page,buf[int(chaddr,16):],iter1)
		elif "yep0" == chtype.lower():
			yep.parse (page,buf[int(chaddr,16):],iter1,0)

		elif "emf" == chtype.lower():
			pt = page.type
			page.type = "EMF"
			mf.mf_open (buf[int(chaddr,16):],page,iter1)
			page.type = pt
		elif "pix" == chtype.lower():
#			try:
				off = int(chaddr,16)
				ntype = model.get_value(iter1,1)
				if off:
					iter2 = add_pgiter(page,"Picture","escher","Blip",buf[off:],iter1)
					model.set_value(iter2,1,("escher","odraw","Blip"))
				else:
					model.set_value(iter1,1,("escher","odraw","Blip"))
					page.hd.hv.parent.on_row_activated(page.hd.hv,model.get_path(iter1),None)
#			except:
#				print "Failed to add as a picture"
		elif "dump" == chtype.lower():
			dlg = gtk.FileChooserDialog('Save...', action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK,gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL))
			dlg.set_local_only(True)
			resp = dlg.run()
			fname = dlg.get_filename()
			dlg.hide()
			if resp != gtk.RESPONSE_CANCEL:
				nlen = model.get_value(iter1,2)
				if chaddr != 0:
					pos = chaddr.find(":")
					if pos != -1:
						endaddr = chaddr[pos+1:]
						chaddr = chaddr[:pos]
						value = model.get_value(iter1,3)[int(chaddr,16):int(endaddr,16)]
					else:
						value = model.get_value(iter1,3)[int(chaddr,16):]
				else:
					value = model.get_value(iter1,3)[int(chaddr,16):]

				if nlen != None:
					f = open(fname,'wb')
					f.write(value)
					f.close()
				else:
					print("Nothing to save")
		elif "wmf" == chtype.lower() or "apwmf" == chtype.lower():
			pt = page.type
			page.type = chtype.upper()
			mf.mf_open (buf[int(chaddr,16):],page,iter1)
			page.type = pt
		elif "xls" == chtype.lower():
			ch2 = chaddr[1]
			if ch2.isdigit():
				coladdr = ord(chaddr[0].lower()) - 97
				rowaddr = int(chaddr[1:]) - 1
			else:
				coladdr = 26*(ord(chaddr[0].lower()) - 96)+ ord(chaddr[1].lower()) - 97
				rowaddr = int(chaddr[2:]) - 1
			page.search = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_INT)
			model.foreach(xlsfind,(page,rowaddr,coladdr))
			page.show_search("XLS: cell %s"%chaddr)
		elif "rx2" == chtype.lower():
			newL = struct.unpack('>I', buf[int(chaddr,16)+4:int(chaddr,16)+8])[0]
			rx2.parse (model,buf[int(chaddr,16):int(chaddr,16)+newL],0,iter1)
		elif "dib" == chtype.lower():
			iter2 = add_pgiter (page,"[BMP]","",0,dib2bmp(buf[int(chaddr,16):]),iter1)
			model.set_value(iter2,1,("escher","odraw","Blip"))
		elif "pct" == chtype.lower():
			pict.parse (page,buf,iter1)
		elif "pm6" == chtype.lower():
			off = int(chaddr,16)
			pm6.open (page,buf,iter1,off)
		elif "vba" == chtype.lower():
			# off = int(chaddr,16)
			vba.parse (page,buf,iter1)
		elif "zip" == chtype.lower():
			try:
				print(int(chaddr,16))
				decobj = zlib.decompressobj()
				output = decobj.decompress(buf[int(chaddr,16):])
				add_pgiter (page,"[Decompressed data]","",0,output,iter1)
				tail = decobj.unused_data
				if len(tail) > 0:
					add_pgiter (page,"[Tail]","",0,tail,iter1)
			except:
				print("Failed to decompress as zlib")
				try:
					f = StringIO.StringIO(buf[int(chaddr,16):])
					pkzip.open(f, page, iter1)
					f.close()
				except:
					print("Failed to decompress as pkzip")

	elif cmd[0] == "?":
		ctype = cmd[1]
		carg = cmd[2:]
		# convert line to hex or unicode if required
		data = arg_conv(ctype,carg)
		model = page.view.get_model()
		page.search = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_INT)
		if ctype == 'r' or ctype == 'R':
			model.foreach(recfind,(page,data))
		else:
			model.foreach(cmdfind,(page,data))
		page.show_search(carg)
示例#4
0
文件: App.py 项目: rgwan/re-lab
	def fload(self,buf="",parent=None,package=None):
		self.pname = os.path.split(self.fname)[1]
		if buf == "":
			offset = 0
			f = open(self.fname,"rb")
			buf = f.read()

		if buf[2:8] == "IIXPR3":
			self.type = qxp.open(self, buf, parent)
			return 0

		if buf[:8] == "\x89PNG\x0d\x0a\x1a\x0a":
			self.type = pngot.open(self, buf, parent)
			return 0

		if buf[0:6] == "\x1aWLF10":
			self.type = vfb.open(self, buf, parent)
			return 0

		if buf[0:6] == "<?xml " or buf[0:14] == "\xff\xfe<\0?\0x\0m\0l\0 \0" or buf[0:14] == "\xfe\xff\0<\0?\0x\0m\0l\0 ":
			self.type = otxml.open(buf, self, parent)
			return 0

		if buf[0:8] == "CPT9FILE":
			self.type = cpt.open(buf, self, parent)
			return 0

		if buf[0:8] == "VjCD0100":
			self.type = chdraw.open(self, buf, parent)
			return 0

		if buf[0:4] == "EVHD":
			self.type = yep.parse(self, buf, parent)
			return 0

		if buf[0:4] == "XPIH":
			self.type = yep.parse_ppi(self, buf, parent)
			return 0

		if buf[0:5].lower() == "{\\rtf":
			self.type = rtf.open(buf, self, parent)
			return 0

		if buf[0:8] == "\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1":
			self.type = ole.ole_open(buf, self, parent)
			return 0

		if buf[0:18] == "Visio (TM) Drawing":
			self.type = vsd.parse(self, buf, parent)
			return 0

		if buf[0:2] == "\x50\xc3":
			self.type = "CLP"
			clp.open (buf,self, parent)
			return 0

		if buf[0:6] == "VCLMTF":
			self.type = "SVM"
			svm.open (buf,self, parent)
			return 0

		if buf[:4] == "\x12\x90\xa8\x7f":
			nki.open(self,buf,parent)
			return 0

#		This one should be before CDR to properly handle v17
		if parent != None:
			parname = self.model.get_value(parent,0)
			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:
				if self.wdata == None:
					self.wdata = {}
				p = parname.rfind("/")
				self.wdata[parname[p+1:]] = parent
			
		if buf[0:4] == "RIFF" and buf[8:11].lower() == "cdr":
			self.type = "CDR%x"%(ord(buf[11])-0x30)
			print 'Probably CDR',
			cdr.cdr_open(buf,self, parent)
			print self.version
			return 0

		if buf[0:4] == "RIFF" and buf[8:11] == "CMX":
			self.type = "CMX"
			cdr.cdr_open(buf,self, parent,"cmx")
			return 0

		if buf[0:2] == "WL":
			self.type = "CDR2"
			wld.open (buf,self, parent)
			return 0

		if buf[0:2] == "\xcc\xdc":
			self.type = "CPL"
			cpl.open (buf,self, parent)
			return 0

		if buf[0:4] == "8BGR":
			self.type = "BGR"
			abr.abr_open(buf,self, parent,"bgr")
			return 0

		if buf[4:8] == "8BIM":
			self.type = "ABR"
			abr.abr_open(buf,self, parent,"abr")
			return 0

		if buf[0:4] == "\xd7\xcd\xc6\x9a":
			self.type = "APWMF"
			mf.mf_open(buf,self, parent)
			print "Aldus Placeable WMF"
			return 0

		if buf[0:8] == "\x4c\x00\x52\x00\x46\x00\x00\x00":
			self.type = "LRF"
			lrf.open(buf, self, parent)
			print "LRF"
			return 0

		if buf[0:6] == "\x01\x00\x09\x00\x00\x03":
			self.type = "WMF"
			print "Probably WMF"
			mf.mf_open(buf,self, parent)
			return 0

		if buf[40:44] == "\x20\x45\x4d\x46":
			self.type = "EMF"
			print "Probably EMF"
			mf.mf_open(buf,self, parent)
			return 0

		if buf[0:2] =="KF" and buf[2] != "\x00":
			self.type = "CDW"
			print "Probably CDW"
			cdw.open(buf,self, parent)
			return 0

		if buf[0:4] == "CAT " and buf[0x8:0xc] == "REX2":
			self.type = "REX2"
			print "Probably REX2"
			rx2.open(buf,self, parent)
			return 0
		
		if buf[0:20] == "Kaydara FBX Binary  ":
			self.type = "FBX"
			print "Probably FBX"
			fbx.open(buf,self, parent)
			return 0
		
		if buf[4:19] == "Standard Jet DB" or buf[4:19] == "Standard ACE DB":
			self.type = "MDB"
			print "Probably MDB"
			mdb.parse (buf,self, parent)
			return 0
		
		if buf[0:4] == "\x50\x4b\x03\x04":
			self.type = "PKZIP"
			print "Probably PK-ZIP"
			f.close()
			pkzip.open (self.fname,self, parent)
			return 0

		pdbtype = buf[0x3c:0x44]
                if pdbtype in pdb.pdb_types.keys():
			self.type = "PDB"
			print "Probably Palm e-book"
			pdb.open(buf, self, parent, pdbtype)
			return 0

		if buf[2:10] == 'BOOKDOUG':
			self.type = 'IMP'
			print 'Probably SoftBook e-book'
			sbimp.open(buf, self, parent)
			return 0

		if buf[0:8] == 'ITOLITLS':
			self.type = 'LIT'
			print 'Probably LIT'
			lit.open(buf,self,parent)
			return 0

		if buf[0:6] == 'bplist':
			self.type = 'PLIST'
			print 'Probably PLIST'
			plist.open(buf,self,parent)
			return 0

		fh_off = buf.find('FreeHand')
		if buf[0:3] == 'AGD':
			agd_off = 0
			agd_ver = ord(buf[agd_off+3])
			try:
				self.type = "FH"
				print "Probably Freehand"
				fh.fh_open(buf,self)
				return 0
			except:
				print "Check for Freehand failed..."
		elif fh_off != -1:
			agd_off = buf.find('AGD')
			if agd_off > fh_off:
				agd_ver = ord(buf[agd_off+3])
				try:
					self.type = "FH"
					print "Probably Freehand 9+"
					fh.fh_open(buf,self, parent)
					return 0
				except:
					print "Check for Freehand 9+ failed..."
		else:
			fh_off = buf.find('FHDocHeader')
			if fh_off != -1:
				if buf[0:2] == "FH":
					self.type = "FH"
					print "Probably Freehand <5"
					fh.fh_open(buf, self, parent, 0)
					return 0
		if buf[0:4] == "FHD2" or buf[0:4] == "acf3":
			self.type = "FH12"
			fh12.fh_open(buf, self, parent, 0)
			return 0
		if buf[8:11] == 'xV4':
			self.type = 'ZMF'
			print 'Probably Zoner Draw 4+'
			zmf.zmf4_open(buf, self, parent)
			return 0

		# NOTE: 0x29a is 666 in decimal .-)
		if buf[0:2] == '\x9a\x02' and buf[2:4] in ['\01\0', '\02\0', '\03\0', '\04\0']:
			self.type = 'ZBR'
			print 'Probably Zebra Metafile'
			zbr.open(buf, self, parent)
			return 0

		size = (ord(buf[1]) | (ord(buf[2]) << 8)) + 4
		if buf[0] == '\0' and (size == len(buf) or (size < len(buf) and buf[4:7] == "\x80\x80\x04")):
			self.type = 'IWA'
			if not self.subtype:
				self.subtype = iwa.detect(package)
			print('Probably Apple iWork file')
			iwa.open(buf, self, parent, self.subtype)
			return 0
			
		if buf[0:0x17] == 'Software602\r\nCalc602 v.' and (buf[0x1c:0x24] == 'Tabulka\x1a' or buf[0x1c:0x21] == 'Graf\x1a'):
			self.type = 'C602'
			print('Probably C602 file')
			if buf[0x1c] == 'T':
				c602.parse_spreadsheet(buf, self, parent)
			else:
				c602.parse_chart(buf, self, parent)
			return 0

		if parent == None:
			parent = add_pgiter(self, "File", "file","unknown",buf) 

		# Likely false detection for DRW
		if buf[0:3] == "\x01\xff\x02":
			try:
				drw.open(self,buf,parent)
				self.model.set_value(parent, 0, "DRW")
			except:
				print "Failed after attempt to parse as DRW..."

		return 0