83 lines
2.9 KiB
Python
83 lines
2.9 KiB
Python
"""
|
|
Debug: compare raw bytes and re-encoded bytes.
|
|
Also try to interpret the file as a regular PNG by skipping the BOM.
|
|
"""
|
|
import sys
|
|
|
|
path = r"D:\Yuzu-GCA\screen.png"
|
|
|
|
with open(path, 'rb') as f:
|
|
raw = f.read()
|
|
|
|
print(f"Total size: {len(raw)} bytes")
|
|
|
|
# Decode as UTF-16 LE
|
|
text = raw.decode('utf-16-le')
|
|
print(f"Decoded text length: {len(text)} chars")
|
|
|
|
# Re-encode
|
|
reencoded = text.encode('utf-16-le')
|
|
print(f"Re-encoded size: {len(reencoded)} bytes")
|
|
|
|
# Compare
|
|
if raw == reencoded:
|
|
print("raw == reencoded: EXACT MATCH")
|
|
else:
|
|
print(f"raw == reencoded: DIFFER")
|
|
# Find first difference
|
|
for i in range(min(len(raw), len(reencoded))):
|
|
if raw[i] != reencoded[i]:
|
|
print(f"First diff at byte {i}: raw={raw[i]:02x}, reencoded={reencoded[i]:02x}")
|
|
print(f" Context raw: {raw[max(0,i-5):i+10].hex(' ')}")
|
|
print(f" Context re: {reencoded[max(0,i-5):i+10].hex(' ')}")
|
|
break
|
|
|
|
# Check if raw starts with BOM
|
|
if raw[:2] == b'\xff\xfe':
|
|
print("\nFile starts with UTF-16 LE BOM")
|
|
elif raw[:2] == b'\xfe\xff':
|
|
print("\nFile starts with UTF-16 BE BOM")
|
|
|
|
# Check reencoded start
|
|
if reencoded[:2] == b'\xff\xfe':
|
|
print("Re-encoded starts with UTF-16 LE BOM")
|
|
elif reencoded[:2] == b'\xfe\xff':
|
|
print("Re-encoded starts with UTF-16 BE BOM")
|
|
|
|
# Try: what if we treat raw[2:] as the UTF-16 LE data (without the BOM)?
|
|
# This would be the case if the file had BOM added later
|
|
print(f"\nraw[2:4] = {raw[2:4].hex(' ')}")
|
|
text2 = raw[2:].decode('utf-16-le')
|
|
print(f"Decoded text2 (skipping BOM) length: {len(text2)} chars")
|
|
print(f"text2 first 50 chars: {text2[:50]}")
|
|
|
|
# Try: what if the entire file is just raw PNG with a bogus BOM?
|
|
# PNG magic: 89 50 4E 47 0D 0A 1A 0A
|
|
# Our file: ff fe 52 58 4e 00 47 00 0d 00 0a 00 ...
|
|
# Maybe each byte X became X*256 + something?
|
|
# Or maybe the file is a hex dump?
|
|
print("\n=== Trying hex dump interpretation ===")
|
|
# Check if the text looks like a hex dump (pairs of hex digits)
|
|
hex_pattern = all(c in '0123456789abcdefABCDEF \n\r\t' for c in text[:1000])
|
|
print(f"First 1000 chars look like hex dump: {hex_pattern}")
|
|
|
|
# Final: Is there any actual readable content?
|
|
# Let's look for sequences of Latin chars that might form words
|
|
import re
|
|
# Words with 5+ letters
|
|
real_words = re.findall(r'[A-Za-z]{5,}', text)
|
|
# Filter out those that look like random binary
|
|
likely_real = [w for w in real_words if w.lower() in [
|
|
'update', 'download', 'install', 'error', 'success', 'failed',
|
|
'system', 'android', 'version', 'checking', 'package', 'verify'
|
|
] or w in ['IHDR', 'IDAT', 'IEND', 'sRGB', 'sBIT', 'pHYs', 'iTXt', 'tEXt', 'zTXt']]
|
|
print(f"\nKnown words found: {likely_real}")
|
|
|
|
# Check for PNG chunk names
|
|
png_chunks = ['IHDR', 'PLTE', 'IDAT', 'IEND', 'cHRM', 'gAMA', 'iCCP', 'sBIT', 'sRGB',
|
|
'bKGD', 'hIST', 'tRNS', 'pHYs', 'sPLT', 'tIME', 'iTXt', 'tEXt', 'zTXt']
|
|
for chunk in png_chunks:
|
|
cnt = text.count(chunk)
|
|
if cnt > 0:
|
|
print(f" PNG chunk '{chunk}': {cnt} times")
|