Last active
May 27, 2022 20:33
-
-
Save n0samu/67c4867db4697fdc7cb25cd83352ec23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SWF scanner by nosamu | |
# Dumps a CSV file with the filename, width and height (in pixels), | |
# and AS3 flag of each SWF in the current folder. | |
# Requires Flasm: http://www.nowrap.de/flasm.html | |
import os | |
import shutil | |
import subprocess | |
import re | |
import csv | |
CSV_FILENAME = 'swf_info.csv' | |
csv_fields = ['filename', 'width', 'height', 'has AS3'] | |
csv_data = [] | |
# If you specify the path to Flasm below, the script won't need to prompt you for it. | |
# Remember to double up any backslashes! Example: 'C:\\FlasmFolder'. Relative paths also work. | |
# Another option is to edit your PATH variable to include the folder path to Flasm. | |
flasm_path = '' | |
while not os.path.isfile(flasm_path): | |
flasm_path = shutil.which('flasm', path=flasm_path) or shutil.which('flasm') | |
if not flasm_path: | |
flasm_path = input('Enter the path to the Flasm executable: ') | |
filenames = os.listdir() | |
for filename in filenames: | |
if os.path.splitext(filename)[1] == '.swf': | |
print("Scanning", filename, '...') | |
flasm_command = [flasm_path, '-d', filename] | |
try: | |
disassembly = subprocess.check_output(flasm_command, errors='ignore', timeout=10, text=True) | |
except (subprocess.CalledProcessError, subprocess.TimeoutExpired): | |
disassembly = None | |
if disassembly: | |
disassembly_lines = disassembly.splitlines() | |
header = disassembly_lines[0] | |
attributes = disassembly_lines[2] | |
header_regex = ', (\\d*\\.?\\d+)x(\\d*\\.?\\d+) px' | |
width, height = re.search(header_regex, header).group(1, 2) | |
hasAS3 = (attributes.find('attrActionScript3') != -1) | |
else: | |
width, height, hasAS3 = ('Unknown', 'Unknown', 'Unknown') | |
print(filename, width, height, hasAS3) | |
csv_data.append([filename, width, height, hasAS3]) | |
if os.path.isfile('flasm.tmp'): | |
os.remove('flasm.tmp') | |
with open(CSV_FILENAME, 'w', encoding='utf-8', newline='') as csvfile: | |
csvwriter = csv.writer(csvfile) | |
csvwriter.writerow(csv_fields) | |
csvwriter.writerows(csv_data) | |
print(f'Info exported to {CSV_FILENAME}.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment