Process multiple file blocks
(text)
| 27 | |
| 28 | |
| 29 | def process_code_blocks(text): |
| 30 | """Process multiple file blocks""" |
| 31 | |
| 32 | results = {"paths": [], "data": []} |
| 33 | |
| 34 | split_pattern = r'\$\w+\s*=\s*Join-Path\s+\$\w+\s+([\'"])(.+?)\1;?' |
| 35 | base64_pattern = r'\$\w+\s*\+=\s*[\'"](.+?)[\'"]' |
| 36 | |
| 37 | parts = re.split(split_pattern, text) |
| 38 | |
| 39 | for i in range(0, len(parts) - 2, 3): |
| 40 | base64_block = parts[i].strip() |
| 41 | filename = parts[i + 2] |
| 42 | |
| 43 | if base64_block: |
| 44 | # Extract all base64 values from the block |
| 45 | base64_values = re.findall(base64_pattern, base64_block) |
| 46 | combined_base64 = ''.join(base64_values) |
| 47 | |
| 48 | if not base64_values or not filename: |
| 49 | continue |
| 50 | |
| 51 | results["paths"].append(filename) |
| 52 | results["data"].append(combined_base64) |
| 53 | |
| 54 | # If file names are associated with a map, map them |
| 55 | map_pattern = r'[\'"](.+?)[\'"]\s*=\s*[\'"](.+?)[\'"]' |
| 56 | mappings = {} |
| 57 | for match in re.finditer(map_pattern, text): |
| 58 | fake_name = match.group(1) |
| 59 | real_name = match.group(2) |
| 60 | results["paths"] = [path.replace(fake_name, real_name) for path in results["paths"]] |
| 61 | |
| 62 | return results |
| 63 | |
| 64 | |
| 65 | def extract_zip_bytes_from_byte_arrays(text): |