mirror of
https://wiilab.wiimart.org/wiimart/SWF-Checker
synced 2025-09-02 19:41:06 +02:00
143 lines
4.1 KiB
Python
143 lines
4.1 KiB
Python
from __future__ import print_function
|
|
import os
|
|
import zlib
|
|
from sys import version, exit
|
|
import platform
|
|
|
|
platf = platform.system()
|
|
if platf == "Windows":
|
|
os.system("title SWF Checker v3.0")
|
|
os.system("cls")
|
|
else:
|
|
os.system("clear")
|
|
|
|
print(f"SWF Version Checker v3.0\nPython {version}")
|
|
print(f"made by idkwh")
|
|
|
|
try:
|
|
swf = input("SWF Filename: ").strip()
|
|
except KeyboardInterrupt:
|
|
print("\nExiting...")
|
|
exit()
|
|
|
|
def parsetags(data):
|
|
pos = 8 # start after signature & header
|
|
rect_bits = (data[pos] >> 3) & 0x1F
|
|
pos += int((5 + rect_bits * 4 + 7) / 8) # skip RECT
|
|
pos += 4 # skip frame rate/count
|
|
|
|
tags = []
|
|
|
|
while pos + 2 <= len(data):
|
|
tag_header = int.from_bytes(data[pos:pos + 2], 'little')
|
|
pos += 2
|
|
|
|
tag_code = tag_header >> 6
|
|
tag_length = tag_header & 0x3F
|
|
|
|
if tag_length == 0x3F:
|
|
if pos + 4 > len(data):
|
|
break
|
|
tag_length = int.from_bytes(data[pos:pos + 4], 'little')
|
|
pos += 4
|
|
|
|
if pos + tag_length > len(data):
|
|
break
|
|
|
|
tag_data = data[pos:pos + tag_length]
|
|
tags.append((tag_code, tag_data))
|
|
pos += tag_length
|
|
|
|
return tags
|
|
|
|
|
|
def CheckSWF(swf_path):
|
|
if not os.path.exists(swf_path):
|
|
print("File not found. Please check the filename and try again.")
|
|
if platf == "Windows":
|
|
os.system("pause")
|
|
exit()
|
|
else:
|
|
os.system("/bin/bash -c 'read -s -n 1 -p \"Press any key to exit.\"'")
|
|
exit()
|
|
return None, None, None
|
|
|
|
with open(swf_path, "rb") as f:
|
|
data = f.read()
|
|
|
|
if data[:3] == b"CWS":
|
|
print("SWF is compressed. Decompressing...")
|
|
data = b"FWS" + data[3:8] + zlib.decompress(data[8:])
|
|
|
|
flashver = data[3]
|
|
tags = parsetags(data)
|
|
|
|
has_as3 = False
|
|
has_doabc = False
|
|
has_doaction = False
|
|
|
|
for tag_code, tag_data in tags:
|
|
if tag_code == 69: # fileattributes
|
|
if len(tag_data) >= 1:
|
|
flags = tag_data[0]
|
|
if flags & 0x08:
|
|
has_as3 = True
|
|
elif tag_code == 82: # doabc (AS3.0 Only)
|
|
has_doabc = True
|
|
elif tag_code == 12: # doaction (AS1/2.0)
|
|
has_doaction = True
|
|
|
|
if has_as3 or has_doabc:
|
|
is_as3 = True
|
|
elif has_doaction:
|
|
is_as3 = False
|
|
else:
|
|
is_as3 = False
|
|
|
|
asver = "ActionScript 3.0 (incompatible)" if is_as3 else "ActionScript 1.0/2.0 (compatible)"
|
|
return flashver, asver, data
|
|
|
|
def GetStageWH(obj):
|
|
rectS = 8
|
|
nbits = (obj[rectS] >> 3) & 0x1F
|
|
bOffset = rectS * 8 + 5
|
|
|
|
def ReadBit(offset, bits_Num):
|
|
ByteOffs = offset // 8
|
|
BShift = offset % 8
|
|
val = int.from_bytes(obj[ByteOffs:ByteOffs + 4], "big")
|
|
return (val >> (32 - bits_Num - BShift)) & ((1 << bits_Num) - 1)
|
|
|
|
XMin = ReadBit(bOffset, nbits)
|
|
XMax = ReadBit(bOffset + nbits, nbits)
|
|
YMin = ReadBit(bOffset + 2 * nbits, nbits)
|
|
YMax = ReadBit(bOffset + 3 * nbits, nbits)
|
|
|
|
w = round((XMax - XMin) / 20, 2)
|
|
h = round((YMax - YMin) / 20, 2)
|
|
return w, h # w=width, h=height, px
|
|
|
|
flashver, asver, SWFDAT = CheckSWF(swf)
|
|
|
|
if flashver is not None:
|
|
w, h = GetStageWH(SWFDAT)
|
|
print(f"SWF Dimensions: {w}x{h} pixels")
|
|
if flashver <= 8: # compatible
|
|
print(f"Flash version: {flashver}, this SWF is compatible with the Wii.")
|
|
elif flashver == 9: # kirby tv notice
|
|
print(f"Flash version: {flashver}, this SWF may be compatible if injected inside the Kirby TV Channel")
|
|
else: # too new
|
|
print(f"Flash version: {flashver}, this SWF is not compatible with the Wii.")
|
|
|
|
print(f"ActionScript version: {asver}")
|
|
if w > 700 and h > 500:
|
|
print("WARNING: The given SWF might overlap/clip on the Wii.")
|
|
else:
|
|
print("The SWF shouldn't overlap and/or clip on the Wii.")
|
|
|
|
if platf == "Windows":
|
|
os.system("pause")
|
|
exit()
|
|
else:
|
|
os.system("/bin/bash -c 'read -s -n 1 -p \"Press any key to exit.\"'")
|
|
exit() |