當前位置: 首頁>>代碼示例>>Python>>正文


Python Struct.uint32方法代碼示例

本文整理匯總了Python中Struct.Struct.uint32方法的典型用法代碼示例。如果您正苦於以下問題:Python Struct.uint32方法的具體用法?Python Struct.uint32怎麽用?Python Struct.uint32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Struct.Struct的用法示例。


在下文中一共展示了Struct.uint32方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: PAI1

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint32 [as 別名]
	def PAI1(self, data):
		pos = 8
		header = self.PAI1Header()
		header.unpack(data[pos:pos+len(header)])
		pos = header.Off
		
		for i in xrange(header.Count):
			off = nameOff = Struct.uint32(data[pos:pos+4], endian='>')
			pos += 4
			
			name = data[off:].split('\0', 1)[0]
			
			off += 0x14
			numAtoms = ord(data[off])
			off += 4
			
			#print name
			
			for i in xrange(numAtoms):
				sub = Struct.uint32(data[off:off+4], endian='>')
				off += 4
				fourcc = data[nameOff+sub:nameOff+sub+4]
				
				#if fourcc == 'RLTS': 
				#	print 'RLTS unknown'
				#else:
				self.Atom(name, fourcc, data[nameOff+sub:])
開發者ID:HACKERCHANNEL,項目名稱:benzin,代碼行數:29,代碼來源:Alameda.py

示例2: Unpack

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint32 [as 別名]
	def Unpack(self, data, out_file, debug=False):
		file = open(out_file, 'wb')
		if file:
			pos = 0

			count = Struct.uint32(data[pos:pos+4], endian='>')
			pos += 4
			if debug == True:
				print "Count: %08x" % count
				print "\n%08x\n" % pos

			offset_list = []
			for x in xrange(count):
				offset = Struct.uint32(data[pos:pos+4], endian='>')
				pos += 4
				if debug == True:
					print "Offset: %08x" % offset
				offset_list.append(offset)

			if debug == True:
				print "\n%08x\n" % pos

			for x in xrange(count):
				pos = offset_list[x]
				string = nullterm(data[pos:])
				string = unicode(string, 'utf_16_be')
				if debug == True:
					print "String: %s" % string.encode('utf-8')
				pos += len(string)
				file.write(string.encode('utf-8'))
				file.write('\n')
			file.close()
		else:
			print "Could not open file for writing"
			sys.exit(1)
開發者ID:HACKERCHANNEL,項目名稱:Wii.py,代碼行數:37,代碼來源:znd.py

示例3: MAT1

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint32 [as 別名]
	def MAT1(self, data):
		pos = 8
		matCount = Struct.uint16(data[pos:pos+2], endian='>')
		pos += 4
		
		for i in xrange(matCount):
			nameOff = Struct.uint32(data[pos:pos+4], endian='>')
			pos += 4
			
			name = data[nameOff:].split('\0', 1)[0]
			wii.chexdump(data[nameOff:nameOff+0x60])
			texid = Struct.uint16(data[nameOff + 0x40:nameOff + 0x42], endian='>')
			wrap_s = Struct.uint8(data[nameOff + 0x42:nameOff + 0x43], endian='>')
			wrap_t = Struct.uint8(data[nameOff + 0x43:nameOff + 0x44], endian='>')
			texid2 = Struct.uint16(data[nameOff + 0x44:nameOff + 0x46], endian='>')
			colorA = [Struct.uint16(data[nameOff + 0x1c + x:nameOff + 0x20 + x], endian='>')/255.0 for x in range(0,8,2)]
			colorB = [Struct.uint16(data[nameOff + 0x22 + x:nameOff + 0x24 + x], endian='>')/255.0 for x in range(0,8,2)]
			flags = Struct.uint32(data[nameOff + 0x3c:nameOff + 0x40], endian='>')
			
			#numtex = 1 # Hardcoded for her pleasure #(flags>>8) & 0xf #guess
			numtex = bit_extract(flags, 28, 31)
			if numtex == 1:
				img = self.Textures[texid]
				tex = img[1].create_texture(Texture)
				#print 'Material 0x%02x (%s) maps to texture %s' % (i, name, img[0])
			elif numtex == 2:
				img = self.Textures[texid]
				alpha = self.Textures[texid2]
				combo = self.ApplyMask(img[1],alpha[1])
				tex = combo.create_texture(Texture)
				#print 'Material 0x%02x (%s) maps to texture %s and mask %s' % (i, name, img[0], alpha[0])
			else:
				print "Bad num textures: %d"%numtex
			
			self.Materials.append((name, tex, (colorA,colorB)))
開發者ID:HACKERCHANNEL,項目名稱:benzin,代碼行數:37,代碼來源:Alameda.py

示例4: icolor

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint32 [as 別名]
	def icolor(self,a,b,fa,fb,fc):
		c = 0
		for i in xrange(0,32,8):
			xa = (a>>i)&0xff
			xb = (b>>i)&0xff
			xc = min(255,max(0,int((xa*fa + xb*fb)/fc)))
			if c == xc< texel2:
							rgb[2] = self.icolor (rgb[0], rgb[1], 0.5, 0.5, 1) | 0xff000000
							rgb[3] = 0
			else:
							rgb[2] = self.icolor (rgb[0], rgb[1], 2, 1, 3) | 0xff000000
							rgb[3] = self.icolor (rgb[1], rgb[0], 2, 1, 3) | 0xff000000
						
			# color selection (00, 01, 10, 11)
			cm = map(ord,data[inp+4:inp+8])
			ofs = l*4
			for n in range(4):
				if (ofs + outp)<(x*y):
				# one row (4 texels)
					if maxw > (0 + l*4):
						out[ofs + 0 + outp] = rgb[(cm[n] & 0xc0) >> 6];
					if maxw > (1 + l*4):
						out[ofs + 1 + outp] = rgb[(cm[n] & 0x30) >> 4];
					if maxw > (2 + l*4):
						out[ofs + 2 + outp] = rgb[(cm[n] & 0x0c) >> 2];
					if maxw > (3 + l*4):
						out[ofs + 3 + outp] = rgb[(cm[n] & 0x03) >> 0];
			ofs += x
			inp += 8
			outp += x * 4
			outp += maxw - x * 8
			outp += x * (TILE_HEIGHT - 1)
		
		return ''.join(Struct.uint32(p) for p in out)
開發者ID:HACKERCHANNEL,項目名稱:benzin,代碼行數:36,代碼來源:Alameda.py

示例5: TXL1

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint32 [as 別名]
	def TXL1(self, data):
		pos = 8
		texCount = Struct.uint16(data[pos:pos+2], endian='>')
		pos += 4
		
		for i in xrange(texCount):
			fnOff = Struct.uint32(data[pos:pos+4], endian='>')
			pos += 8
			
			fn = data[fnOff+0xC:].split('\0', 1)[0]
			tex = TPL(self.Archive.Files['./arc/timg/' + fn]).Textures[0]
			self.Textures.append((fn, tex))
開發者ID:HACKERCHANNEL,項目名稱:benzin,代碼行數:14,代碼來源:Alameda.py

示例6: xrange

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint32 [as 別名]
						for m in xrange(j, j + 4, 1):
							texel = Struct.uint8(data[inp:inp + 1], endian = '>')
							inp += 1
							texel2 = Struct.uint8(data[inp:inp + 1], endian = '>')
							inp += 1
							if (m >= x) or (l >= y):
								continue
							if k == 0: # ARARARAR
								a = (texel) & 0xff
								r = (texel2) & 0xff
								out[m + (l * x)] |= ((r << 0) | (a << 24))
							else: # GBGBGBGB
								g = (texel) & 0xff
								b = (texel2) & 0xff
								out[m + (l * x)] |= ((g << 8) | (b << 16))
		return ''.join(Struct.uint32(p) for p in out)
	def RGB5A3(self, (w, h), jar):
		out = [0 for i in xrange(w * h)]
		i = 0
		for y in xrange(0, h, 4):
			for x in xrange(0, w, 4):
				for y1 in xrange(y, y + 4):
					for x1 in xrange(x, x + 4):
						pixel = Struct.uint16(jar[i * 2:i * 2 + 2], endian='>')
						i += 1
						
						if(y1 >= h or x1 >= w):
							continue
						
						if(pixel & (1 << 15)): #RGB555
							b = (((pixel >> 10) & 0x1F) * 255) / 31
開發者ID:delguoqing,項目名稱:LMDumper,代碼行數:33,代碼來源:image.py

示例7: xrange

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint32 [as 別名]
            out = [0 for i in xrange(x * y)]
            inp = 0
            for i in xrange(0, y, 4):
              for j in xrange(0, x, 4):
                for k in xrange(i, i + 4, 1):
                  for l in xrange(j, j + 4, 1):
                    texel = Struct.uint16(data[inp*2:inp*2+2], endian='>')
                    inp += 1
                    if (l>=x) or (k>=y):
                      continue
                    b = texel >> 8
                    g = texel >> 8
                    r = texel >> 8
                    a = texel & 0xff
                    out[l + (k * x)] = (r << 0) | (g << 8) | (b << 16) | (a << 24)
            return ''.join(Struct.uint32(p) for p in out)

        def I8(self, data, (y, x)):
                        out = [0 for i in xrange(x * y)]
                        outp = 0
                        inp = 0
                        for i in xrange(0, y, 4):
                                for j in xrange(0, x, 4):
                                        ofs = 0
                                        for k in xrange(4):
                                                off = min(x - j, 4)
                                                for sub in xrange(off):
                                                        texel = ord(data[inp])
                                                        out[outp + ofs + sub] = (texel << 24) | (texel << 16) | (texel << 8) | 0xFF
                                                        inp += 1
                                                ofs += x
開發者ID:HACKERCHANNEL,項目名稱:benzin,代碼行數:33,代碼來源:Alameda.py

示例8: Unpack

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint32 [as 別名]
	def Unpack(self, data):
		pos = 0
		header = self.BREFT_Header()
		header.unpack(data[pos:pos+len(header)])
		pos += len(header)
		print header
		assert header.magic == "REFT"
		assert header.version == 0xfeff0004
		reft = self.BREFT_REFT()
		reft.unpack(data[pos:pos+len(reft)])
		pos += len(reft)
		print reft
		assert reft.magic == "REFT"
		
		print "\n%08x\n" % pos

		reft_project = self.BREFT_REFT_Project()
		reft_project.unpack(data[pos:pos+len(reft_project)])
		pos += len(reft_project)
		print reft_project
		string = nullterm(data[pos:pos+reft_project.str_length])
		pos += reft_project.str_length
		print "String: %s\n" % string

		while pos %2:
			unknown = Struct.uint8(data[pos:pos+1])
			pos += 1
			print "Padding: %02x" % unknown

		print "\n%08x\n" % pos

		for x in xrange(0x30):
			pad = Struct.uint8(data[pos:pos+1])
			pos += 1
			#print "Padding: %08x" % pad

		print "\n%08x\n" % pos
		temp = pos

		reft_string_header = self.BREFT_REFT_StringHeader()
		reft_string_header.unpack(data[pos:pos+len(reft_string_header)])
		pos += len(reft_string_header)
		print reft_string_header

		print "\n%08x\n" % pos

		string_groups = []
		for x in xrange(reft_string_header.string_cnt):
			str_length = Struct.uint16(data[pos:pos+2], endian='>')
			pos += 2
			print "String Length with null added: %04x" % str_length
			string = nullterm(data[pos:pos+str_length])
			pos += str_length
			print "String: %s" % string
			string_section1 = self.BREFT_REFT_StringSection1()
			string_section1.unpack(data[pos:pos+len(string_section1)])
			pos += len(string_section1)
			print string_section1
			string_groups.append(string_section1)

		for x in xrange(reft_string_header.string_cnt):
			pos = temp + string_groups[x].offset
			print "\n%08x\n" % pos
			reft_section2 = self.BREFT_REFT_Section2()
			reft_section2.unpack(data[pos:pos+len(reft_section2)])
			pos += len(reft_section2)
			print reft_section2

		print "\n%08x\n" % pos

		#''' BEGIN TEST DATA  
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
		print "Unknown: %08x" % unknown
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
		print "Unknown: %08x" % unknown
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
		print "Unknown: %08x" % unknown
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
		print "Unknown: %08x" % unknown
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
		print "Unknown: %08x" % unknown
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
		print "Unknown: %08x" % unknown
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
		print "Unknown: %08x" % unknown
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
		print "Unknown: %08x" % unknown
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
		print "Unknown: %08x" % unknown
		unknown = Struct.uint32(data[pos:pos+4], endian='>')
		pos += 4
#.........這裏部分代碼省略.........
開發者ID:HACKERCHANNEL,項目名稱:Wii.py,代碼行數:103,代碼來源:breft.py

示例9: Unpack

# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import uint32 [as 別名]
	def Unpack(self, data, out_file, debug):
		file = open(out_file, 'wb')
		if file:
			pos = 0
			header = self.BMG_Header()
			header.unpack(data[pos:pos+len(header)])
			pos += len(header)
			if debug == True:
				print header
				print "\n%08x\n" % pos

			info = self.BMG_INF1()
			info.unpack(data[pos:pos+len(info)])
			pos += len(info)
			if debug == True:
				print info

			unknown = Struct.uint32(data[pos:pos+4], endian='>')
			pos += 4
			if debug == True:
				print "Unknown: %08x" % unknown
				print "\n%08x\n" % pos

			offset_list = []
			for x in xrange(info.count):
				offset = Struct.uint32(data[pos:pos+4], endian='>')
				pos +=  4
				if debug == True:
					print "Offset: %08x" % offset
				offset_list.append(offset)

			while pos % 0x10:
				padding = Struct.uint32(data[pos:pos+4], endian='>')
				pos += 4
				if debug == True:
					print "Padding: %08x" % padding

			if debug == True:
				print "\n%08x\n" % pos

			dat1 = self.BMG_DAT1()
			dat1.unpack(data[pos:pos+len(dat1)])
			pos += len(dat1)
			if debug == True:
				print dat1

			if debug == True:
				print "\n%08x\n" % pos
			temp = pos

			unknown = Struct.uint16(data[pos:pos+2], endian='>')
			pos += 2
			if debug == True:
				print "Unknown: %04x" % unknown

			for x in xrange(info.count):
				pos = temp + offset_list[x]
				string = nullterm(data[pos:])
				string = unicode(string, 'utf_16_be')
				file.write(string.encode('utf-8'))
				file.write('\r')
				file.write('\n')
				if debug == True:
					print "String: %s" % string.encode('utf-8')
			file.close()
		else:
			print "Could not open file for writing"
			sys.exit(1)
開發者ID:HACKERCHANNEL,項目名稱:Wii.py,代碼行數:70,代碼來源:bmg.py


注:本文中的Struct.Struct.uint32方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。