Commit 2ddca8a3d66683b4a3536c29c5398d37baec6f46
Committed by
GitHub
Merge pull request #239 from mrichard91/speedup_bytes
convert byte concat to bytearray
Showing
1 changed file
with
5 additions
and
5 deletions
oletools/olevba3.py
100644 → 100755
| @@ -1174,7 +1174,7 @@ def decompress_stream(compressed_container): | @@ -1174,7 +1174,7 @@ def decompress_stream(compressed_container): | ||
| 1174 | # DecompressedChunkStart: The location of the first byte of the DecompressedChunk (section 2.4.1.1.3) within the | 1174 | # DecompressedChunkStart: The location of the first byte of the DecompressedChunk (section 2.4.1.1.3) within the |
| 1175 | # DecompressedBuffer (section 2.4.1.1.2). | 1175 | # DecompressedBuffer (section 2.4.1.1.2). |
| 1176 | 1176 | ||
| 1177 | - decompressed_container = b'' # result | 1177 | + decompressed_container = bytearray() # result |
| 1178 | compressed_current = 0 | 1178 | compressed_current = 0 |
| 1179 | 1179 | ||
| 1180 | sig_byte = compressed_container[compressed_current] | 1180 | sig_byte = compressed_container[compressed_current] |
| @@ -1223,7 +1223,7 @@ def decompress_stream(compressed_container): | @@ -1223,7 +1223,7 @@ def decompress_stream(compressed_container): | ||
| 1223 | # MS-OVBA 2.4.1.3.3 Decompressing a RawChunk | 1223 | # MS-OVBA 2.4.1.3.3 Decompressing a RawChunk |
| 1224 | # uncompressed chunk: read the next 4096 bytes as-is | 1224 | # uncompressed chunk: read the next 4096 bytes as-is |
| 1225 | #TODO: check if there are at least 4096 bytes left | 1225 | #TODO: check if there are at least 4096 bytes left |
| 1226 | - decompressed_container += bytes([compressed_container[compressed_current:compressed_current + 4096]]) | 1226 | + decompressed_container.extend([compressed_container[compressed_current:compressed_current + 4096]]) |
| 1227 | compressed_current += 4096 | 1227 | compressed_current += 4096 |
| 1228 | else: | 1228 | else: |
| 1229 | # MS-OVBA 2.4.1.3.2 Decompressing a CompressedChunk | 1229 | # MS-OVBA 2.4.1.3.2 Decompressing a CompressedChunk |
| @@ -1246,7 +1246,7 @@ def decompress_stream(compressed_container): | @@ -1246,7 +1246,7 @@ def decompress_stream(compressed_container): | ||
| 1246 | #log.debug('bit_index=%d: flag_bit=%d' % (bit_index, flag_bit)) | 1246 | #log.debug('bit_index=%d: flag_bit=%d' % (bit_index, flag_bit)) |
| 1247 | if flag_bit == 0: # LiteralToken | 1247 | if flag_bit == 0: # LiteralToken |
| 1248 | # copy one byte directly to output | 1248 | # copy one byte directly to output |
| 1249 | - decompressed_container += bytes([compressed_container[compressed_current]]) | 1249 | + decompressed_container.extend([compressed_container[compressed_current]]) |
| 1250 | compressed_current += 1 | 1250 | compressed_current += 1 |
| 1251 | else: # CopyToken | 1251 | else: # CopyToken |
| 1252 | # MS-OVBA 2.4.1.3.19.2 Unpack CopyToken | 1252 | # MS-OVBA 2.4.1.3.19.2 Unpack CopyToken |
| @@ -1262,9 +1262,9 @@ def decompress_stream(compressed_container): | @@ -1262,9 +1262,9 @@ def decompress_stream(compressed_container): | ||
| 1262 | #log.debug('offset=%d length=%d' % (offset, length)) | 1262 | #log.debug('offset=%d length=%d' % (offset, length)) |
| 1263 | copy_source = len(decompressed_container) - offset | 1263 | copy_source = len(decompressed_container) - offset |
| 1264 | for index in range(copy_source, copy_source + length): | 1264 | for index in range(copy_source, copy_source + length): |
| 1265 | - decompressed_container += bytes([decompressed_container[index]]) | 1265 | + decompressed_container.extend([decompressed_container[index]]) |
| 1266 | compressed_current += 2 | 1266 | compressed_current += 2 |
| 1267 | - return decompressed_container | 1267 | + return bytes(decompressed_container) |
| 1268 | 1268 | ||
| 1269 | 1269 | ||
| 1270 | def _extract_vba(ole, vba_root, project_path, dir_path, relaxed=False): | 1270 | def _extract_vba(ole, vba_root, project_path, dir_path, relaxed=False): |