mirror of
https://github.com/zeldaret/ph
synced 2026-07-11 06:34:51 -04:00
Fix BLX Thumb-to-ARM bug in the assembler
This commit is contained in:
+2
-2
@@ -6,10 +6,10 @@ Contents:
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. Install Python 3.7 or higher
|
||||
1. Install Python 3.11 or higher
|
||||
2. Install the Python dependencies:
|
||||
```shell
|
||||
python3 -m pip install -r tools/requirements.txt
|
||||
python -m pip install -r tools/requirements.txt
|
||||
```
|
||||
3. Run the setup script:
|
||||
```shell
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import hashlib
|
||||
import sys
|
||||
|
||||
class Patch:
|
||||
def __init__(self, name: str, version: str, sha1: str, desc: str, offset: int, write: list[int]) -> None:
|
||||
self.name = name
|
||||
self.version = version
|
||||
self.sha1 = sha1
|
||||
self.desc = desc
|
||||
self.offset = offset
|
||||
self.write = write
|
||||
|
||||
VERSION = '1.0'
|
||||
PATCHES = [
|
||||
Patch(
|
||||
'mwasmarm', '2.0/sp1p5', '448cb0c7f1ace4393e9a9562f819f7a9f049be83',
|
||||
'Fix 2-aligned Thumb BLX where ARM call target was off by 1',
|
||||
offset=0x1b45b, write=[0xc2]
|
||||
),
|
||||
]
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print(f'patch_mwcc {VERSION}')
|
||||
print()
|
||||
print(f'Usage: {sys.argv[0]} <exe>')
|
||||
print(' <exe>\tPath to mwasmarm.exe')
|
||||
exit()
|
||||
|
||||
filename = sys.argv[1]
|
||||
|
||||
with open(filename, 'rb', buffering=0) as file:
|
||||
sha1 = hashlib.file_digest(file, 'sha1').hexdigest()
|
||||
file.seek(0, 2)
|
||||
length = file.tell()
|
||||
file.seek(0, 0)
|
||||
file_bytes = bytearray(file.read(length))
|
||||
|
||||
num_patches = 0
|
||||
for patch in PATCHES:
|
||||
if sha1 == patch.sha1:
|
||||
num_patches += 1
|
||||
print(f'{patch.name} version {patch.version}')
|
||||
print(patch.desc)
|
||||
for i in range(len(patch.write)):
|
||||
file_bytes[patch.offset + i] = patch.write[i]
|
||||
print()
|
||||
|
||||
with open(filename, 'wb') as file:
|
||||
file.write(file_bytes)
|
||||
|
||||
print(f'Applied {num_patches} patch(es)')
|
||||
@@ -2,10 +2,15 @@ import requests
|
||||
import zipfile
|
||||
import io
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
tools_path = Path(__file__).parent
|
||||
|
||||
print('\nInstalling toolchain...')
|
||||
response = requests.get('https://cdn.discordapp.com/attachments/698589325620936736/845499146982129684/mwccarm.zip')
|
||||
zip_file = zipfile.ZipFile(io.BytesIO(response.content))
|
||||
zip_file.extractall(tools_path)
|
||||
|
||||
print('\nPatching...')
|
||||
subprocess.run([sys.executable, 'patch_mwcc.py', 'mwccarm/2.0/sp1p5/mwasmarm.exe'], cwd=tools_path)
|
||||
|
||||
Reference in New Issue
Block a user