mirror of
https://github.com/pmret/papermario.git
synced 2024-11-09 12:32:38 +01:00
ae66312d8c
* Add Python linter to github actions * wip * Add back splat_ext * Format files * C++ -> C * format 2 files * split workflow into separate file, line length 120, fix excludes * -l 120 in ci * update black locally and apply formatting changes * pyproject.toject --------- Co-authored-by: Ethan Roseman <ethteck@gmail.com>
48 lines
1.1 KiB
Python
Executable File
48 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
||
|
||
|
||
def decode(data):
|
||
length = 0
|
||
is_dbl_char = False
|
||
for byte in data:
|
||
if byte == 0 and not is_dbl_char:
|
||
break
|
||
|
||
# ignore null terminator when reading double-byte char
|
||
is_dbl_char = False
|
||
if byte & 0xF0 == 0x80:
|
||
is_dbl_char = True
|
||
if byte & 0xF0 == 0x90:
|
||
is_dbl_char = True
|
||
if byte & 0xF0 == 0xE0:
|
||
is_dbl_char = True
|
||
if byte & 0xF0 == 0xF0:
|
||
is_dbl_char = True
|
||
|
||
length += 1
|
||
|
||
return data[:length].decode("shift-jis")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
import sys
|
||
|
||
if len(sys.argv) <= 1:
|
||
print("usage: ./sjis.py <bytes...>")
|
||
print("decodes zero-terminated SJIS from arbitrary hex bytes.")
|
||
print("e.g.")
|
||
print(" ./sjis.py 80072F64 80072F90 80072FA8 00000000")
|
||
print(" エリア KMR その1")
|
||
exit(1)
|
||
|
||
s = "".join(sys.argv[1:])
|
||
|
||
data = bytearray()
|
||
for i in range(0, len(s), 2):
|
||
byte = eval(f"0x{s[i]}{s[i + 1]}")
|
||
data.append(byte)
|
||
|
||
print(data)
|
||
|
||
print(decode(data))
|