Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. def extract():
  2.     print 'Extracting %s...' % sys.argv[2]
  3.     filedata = get_data(sys.argv[2])
  4.     newfiledata = ''
  5.     decomplen = struct.unpack('<I',filedata[:4])[0]
  6.     filedata = filedata[0x4:]
  7.     ringbuff = []
  8.     for i in range(0,0x1000):
  9.         ringbuff.append('\x00')
  10.     ringpos = 0xfee
  11.    
  12.     i = 0
  13.     control = 0
  14.     while len(newfiledata) < decomplen:
  15.         control >>= 1
  16.         oldcontrol = control
  17.         if (control & 0x100) == 0:
  18.             control = ord(filedata[i]) | 0xFF00
  19.             i += 1
  20.             oldcontrol = control
  21.         ecx = ord(filedata[i])
  22.         if (control & 1) != 0:
  23.             ringbuff[ringpos] = chr(ecx)
  24.             ringpos += 1
  25.             ringpos &= 0xFFF
  26.             newfiledata += chr(ecx)
  27.             i += 1
  28.            
  29.         else:
  30.             #003E672D - read from ring buff
  31.             edx = ord(filedata[i+1])
  32.             ebx = (edx & 0xF0) << 4
  33.             ecx |= ebx
  34.             edx &= 0xF
  35.             ebx = ecx + edx + 2
  36.             i += 2
  37.             edx = ecx
  38.             while edx <= ebx:
  39.                 ecx = edx
  40.                 ecx &= 0xFFF
  41.                 ecx = ord(ringbuff[ecx])
  42.                 ringbuff[ringpos] = chr(ecx)
  43.                 ringpos += 1
  44.                 ringpos &= 0xFFF
  45.                 newfiledata += chr(ecx)
  46.                 if len(newfiledata) >= decomplen:
  47.                     break;
  48.                 edx += 1
  49.             control = oldcontrol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement