Advertisement
Guest User

Untitled

a guest
Jun 11th, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.63 KB | None | 0 0
  1. def tableNUNO(filedata,tablestart):
  2.     tablelen = struct.unpack('>I',filedata[tablestart+0x8:tablestart+0xc])[0]
  3.     table = ''
  4.  
  5.     for i in range(tablestart,tablestart+0x8,0x4):
  6.         table += filedata[i+0x3:i+0x4] + filedata[i+0x2:i+0x3] + filedata[i+0x1:i+0x2] + filedata[i:i+0x1]
  7.     #table += 'ONUN4200'
  8.  
  9.     table += struct.pack('<I',tablelen)
  10.     tablecount = struct.unpack('>I',filedata[tablestart+0xc:tablestart+0x10])[0]
  11.     table += struct.pack('<I',tablecount)
  12.     pos = tablestart+0x10
  13.     cntr = 0
  14.     for i in range(0,tablecount):
  15.         tabletype = struct.unpack('>H',filedata[pos+0x2:pos+0x4])[0]
  16.         table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  17.         subtablelen = struct.unpack('>I',filedata[pos+0x4:pos+0x8])[0]
  18.         table += struct.pack('<I',subtablelen)
  19.         subentrycount = struct.unpack('>I',filedata[pos+0x8:pos+0xc])[0]
  20.         table += struct.pack('<I',subentrycount)
  21.         pos += 0xc
  22.        
  23.         for a in range(0,subentrycount):
  24.             if tabletype == 0x1:
  25.                 for b in range(0x0,0x19): #0x64 bytes
  26.                     if b == 0x1:
  27.                         subsubentrycount = struct.unpack('>I',filedata[pos:pos+0x4])[0]
  28.                         subsubentrycount1 = subsubentrycount
  29.                         subsubentrycount *= 0x10
  30.                         subsubentrycount /= 0x4
  31.                     elif b == 0x2:
  32.                         subsubentrycount2 = struct.unpack('>I',filedata[pos:pos+0x4])[0]
  33.                         subsubentrycount2 = (subsubentrycount2*0x2)+subsubentrycount2
  34.                         subsubentrycount2 *= 0x10
  35.                         subsubentrycount2 /= 0x4
  36.                     elif b == 0x3:
  37.                         subsubentrycount3 = struct.unpack('>I',filedata[pos:pos+0x4])[0]
  38.                         subsubentrycount3 += struct.unpack('>I',filedata[pos+0x4:pos+0x8])[0]
  39.                         subsubentrycount3 += subsubentrycount3
  40.                         subsubentrycount3 += subsubentrycount3
  41.                         subsubentrycount3 /= 0x4
  42.                     elif b == 0x5:
  43.                         subsubentrycount4 = struct.unpack('>I',filedata[pos:pos+0x4])[0]
  44.                         subsubentrycount4 += subsubentrycount4
  45.                         subsubentrycount4 += subsubentrycount4
  46.                         subsubentrycount4 /= 0x4
  47.  
  48.                     if b == 0x12:
  49.                         table += struct.pack('<H',struct.unpack('>H',filedata[pos:pos+0x2])[0])
  50.                         table += struct.pack('<B',struct.unpack('>B',filedata[pos+0x2:pos+0x3])[0])
  51.                         table += struct.pack('<B',struct.unpack('>B',filedata[pos+0x3:pos+0x4])[0])
  52.                     else:
  53.                         table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  54.                     pos += 0x4
  55.  
  56.                 for b in range(0,subsubentrycount):
  57.                     table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  58.                     pos += 0x4
  59.  
  60.                
  61.                 subsubentrycount1 = (subsubentrycount1*0x2)+subsubentrycount1
  62.                 subsubentrycount1 += subsubentrycount1
  63.                 subsubentrycount1 += subsubentrycount1
  64.                 subsubentrycount1 += subsubentrycount1
  65.                 subsubentrycount1 /= 0x4
  66.                 for b in range(0,subsubentrycount1):
  67.                     table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  68.                     pos += 0x4
  69.  
  70.                 for b in range(0,subsubentrycount2):
  71.                     table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  72.                     pos += 0x4
  73.  
  74.                 for b in range(0,subsubentrycount3):
  75.                     table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  76.                     pos += 0x4
  77.  
  78.                 for b in range(0,subsubentrycount4):
  79.                     table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  80.                     pos += 0x4
  81.                
  82.  
  83.             elif tabletype == 0x2:
  84.                 for b in range(0x0,0x14): #0x50 bytes
  85.                     if b == 0x2:
  86.                         subsubentrycount = struct.unpack('>I',filedata[pos:pos+0x4])[0]
  87.                         subsubentrycount *= 0x20
  88.                         subsubentrycount /= 0x4
  89.                     elif b == 0x3:
  90.                         subsubentrycount1 = struct.unpack('>I',filedata[pos:pos+0x4])[0]
  91.                         subsubentrycount1 += subsubentrycount1
  92.                         subsubentrycount1 += subsubentrycount1
  93.                         subsubentrycount1 /= 0x4
  94.                     if b == 0xd:
  95.                         table += struct.pack('>B',struct.unpack('>B',filedata[pos:pos+0x1])[0])
  96.                         table += struct.pack('>B',struct.unpack('>B',filedata[pos+0x1:pos+0x2])[0])
  97.                         table += struct.pack('>B',struct.unpack('>B',filedata[pos+0x2:pos+0x3])[0])
  98.                         table += struct.pack('>B',struct.unpack('>B',filedata[pos+0x3:pos+0x4])[0])
  99.                     else:
  100.                         table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  101.                     pos += 0x4
  102.                    
  103.                 for b in range(0,subsubentrycount):
  104.                     table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  105.                     pos += 0x4
  106.                    
  107.                 for b in range(0,subsubentrycount1):
  108.                     table += struct.pack('<I',struct.unpack('>I',filedata[pos:pos+0x4])[0])
  109.                     pos += 0x4
  110.  
  111.     return table
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement