Support IPS32 patches

This commit is contained in:
Boris Timofeev 2017-01-23 15:41:04 +03:00
parent c47334e71b
commit 22543f0710
28 changed files with 173 additions and 20 deletions

View file

@ -4,7 +4,7 @@
UniPatcher
----------
UniPatcher is a ROM patcher for Android that supports IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patch types.
UniPatcher is a ROM patcher for Android that supports IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patch types.
### Additional features:

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 2013, 2016 Boris Timofeev
Copyright (C) 2013, 2016, 2017 Boris Timofeev
This file is part of UniPatcher.
@ -36,7 +36,12 @@ import java.util.Arrays;
public class IPS extends Patcher {
private static final byte[] MAGIC_NUMBER = {0x50, 0x41, 0x54, 0x43, 0x48}; // "PATCH"
public static final int NOT_IPS_PATCH = 0;
public static final int IPS_PATCH = 1;
public static final int IPS32_PATCH = 2;
private static final byte[] MAGIC_NUMBER_IPS = {0x50, 0x41, 0x54, 0x43, 0x48}; // "PATCH"
private static final byte[] MAGIC_NUMBER_IPS32 = {0x49, 0x50, 0x53, 0x33, 0x32}; // "IPS32"
public IPS(Context context, File patch, File rom, File output) {
super(context, patch, rom, output);
@ -44,6 +49,19 @@ public class IPS extends Patcher {
@Override
public void apply() throws PatchException, IOException {
switch (checkIPS(patchFile)) {
case IPS_PATCH:
applyIPS();
break;
case IPS32_PATCH:
applyIPS32();
break;
case NOT_IPS_PATCH:
throw new PatchException(context.getString(R.string.notify_error_not_ips_patch));
}
}
public void applyIPS() throws PatchException, IOException {
BufferedInputStream romStream = null;
BufferedInputStream patchStream = null;
@ -67,17 +85,17 @@ public class IPS extends Patcher {
// check magic string
byte[] magic = new byte[5];
size = patchStream.read(magic);
if (size != 5 || !Arrays.equals(magic, MAGIC_NUMBER))
if (size != 5 || !Arrays.equals(magic, MAGIC_NUMBER_IPS))
throw new PatchException(context.getString(R.string.notify_error_not_ips_patch));
while (true) {
offset = readOffset(patchStream, 3);
offset = (int)readOffset(patchStream, 3);
if (offset < 0)
throw new PatchException(context.getString(R.string.notify_error_patch_corrupted));
if (offset == 0x454f46) { // EOF
// truncate file or copy tail
if (romPos < romSize) {
offset = readOffset(patchStream, 3);
offset = (int)readOffset(patchStream, 3);
if (offset != -1 && offset >= romPos) {
size = offset - romPos;
} else {
@ -142,8 +160,119 @@ public class IPS extends Patcher {
}
}
private int readOffset(InputStream stream, int numBytes) throws IOException {
int offset = 0;
public void applyIPS32() throws PatchException, IOException {
BufferedInputStream romStream = null;
BufferedInputStream patchStream = null;
BufferedOutputStream outputStream = null;
try {
romStream = new BufferedInputStream(new FileInputStream(romFile));
patchStream = new BufferedInputStream(new FileInputStream(patchFile));
outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
long romSize = romFile.length();
long romPos = 0;
long outPos = 0;
long offset;
long size;
if (patchFile.length() < 16) {
throw new PatchException(context.getString(R.string.notify_error_patch_corrupted));
}
byte[] magic = new byte[5];
size = patchStream.read(magic);
if (size != 5 || !Arrays.equals(magic, MAGIC_NUMBER_IPS32))
throw new PatchException(context.getString(R.string.notify_error_not_ips_patch));
while (true) {
offset = readOffset(patchStream, 4);
if (offset < 0)
throw new PatchException(context.getString(R.string.notify_error_patch_corrupted));
if (offset == 0x45454f46) { // EEOF
// copy tail
if (romPos < romSize) {
size = romSize - romPos;
Utils.copy(romStream, outputStream, size);
}
break;
}
if (offset <= romSize) {
if (outPos < offset) {
size = offset - outPos;
Utils.copy(romStream, outputStream, size);
romPos += size;
outPos += size;
}
} else {
if (outPos < romSize) {
size = romSize - outPos;
Utils.copy(romStream, outputStream, size);
romPos += size;
outPos += size;
}
if (outPos < offset) {
size = offset - outPos;
Utils.copy(size, (byte) 0x0, outputStream);
outPos += size;
}
}
size = (patchStream.read() << 8) + patchStream.read();
if (size != 0) {
byte[] data = new byte[(int)size];
patchStream.read(data);
outputStream.write(data);
outPos += size;
} else { // RLE
size = (patchStream.read() << 8) + patchStream.read();
byte val = (byte) patchStream.read();
byte[] data = new byte[(int)size];
Arrays.fill(data, val);
outputStream.write(data);
outPos += size;
}
if (offset <= romSize) {
if (romPos + size > romSize) {
romPos = (int) romSize;
} else {
byte[] buf = new byte[(int)size];
romStream.read(buf);
romPos += size;
}
}
}
} finally {
IOUtils.closeQuietly(romStream);
IOUtils.closeQuietly(patchStream);
IOUtils.closeQuietly(outputStream);
}
}
public int checkIPS(File file) throws PatchException, IOException {
FileInputStream stream = null;
try {
stream = new FileInputStream(file);
byte[] magic = new byte[5];
int count = stream.read(magic);
if (count < 5)
throw new PatchException(context.getString(R.string.notify_error_not_ips_patch));
if (Arrays.equals(magic, MAGIC_NUMBER_IPS)) {
return IPS_PATCH;
} else if (Arrays.equals(magic, MAGIC_NUMBER_IPS32)) {
return IPS32_PATCH;
}
} finally {
IOUtils.closeQuietly(stream);
}
return NOT_IPS_PATCH;
}
private long readOffset(InputStream stream, int numBytes) throws IOException {
long offset = 0;
while (numBytes-- != 0) {
int b = stream.read();
if (b == -1)

View file

@ -1,4 +1,4 @@
UniPatcher è un patcher che supporta i tipi di patch IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP e XDelta3.
UniPatcher è un patcher che supporta i tipi di patch IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP e XDelta3.
Funzioni aggiuntive:

View file

@ -6,7 +6,7 @@ UniPatcher è uno strumento per Android per applicare delle patch alle ROM di va
#### Quali formati di patch sono supportati?
L'app supporta le patch IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP e XDelta3.
L'app supporta le patch IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP e XDelta3.
#### Posso hackerare o crackare i giochi di Android con questa app?

View file

@ -1,4 +1,4 @@
UniPatcher jest programem do łatkowania ROM-ów. Wsparcie dla typów łatek: IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP i XDelta3.
UniPatcher jest programem do łatkowania ROM-ów. Wsparcie dla typów łatek: IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP i XDelta3.
Dodatkowe funkcje:

View file

@ -6,7 +6,7 @@ UniPatcher jest narzędziem do łatkowania ROM-ów różnych konsol
#### Jakie formaty łatek są obsługiwane?
The app supports IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patches.
The app supports IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patches.
#### Czy mogę hakować albo crackować gry Android za pomocą tej aplikacji?

View file

@ -1,4 +1,4 @@
UniPatcher это ROM патчер поддерживающий патчи в форматах IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP и XDelta3.
UniPatcher это ROM патчер поддерживающий патчи в форматах IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP и XDelta3.
Дополнительные функции:

View file

@ -6,7 +6,7 @@
#### Какие форматы патчей поддерживаются?
Приложение поддерживает патчи в форматах IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP и XDelta3.
Приложение поддерживает патчи в форматах IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP и XDelta3.
#### Возможно ли с помощью этого приложения взломать игру для Android?

View file

@ -1,4 +1,4 @@
UniPatcher is a ROM patcher that supports IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patch types.
UniPatcher is a ROM patcher that supports IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patch types.
Additional features:

View file

@ -6,7 +6,7 @@ UniPatcher is an Android tool for applying patches to ROM images of various vide
#### What patch formats are supported?
The app supports IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patches.
The app supports IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patches.
#### Can I hack or crack Android game using this app?

View file

@ -131,7 +131,7 @@
<string name="send_feedback_error_no_email_apps">Non ci sono client email installati</string>
<string name="share_dialog_title">Condividi UniPatcher</string>
<string name="share_text">Scarica il miglior patcher di ROM per Android. Supporta i formati IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP e XDelta3.\\n\\n
<string name="share_text">Scarica il miglior patcher di ROM per Android. Supporta i formati IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP e XDelta3.\\n\\n
</string>
<!-- Navigation list -->

View file

@ -131,7 +131,7 @@
<string name="send_feedback_error_no_email_apps">Tu nie ma żadnych klientów E-Mail zainstalowanych</string>
<string name="share_dialog_title">Udostępnij UniPatcher-a swoim znajomym</string>
<string name="share_text">Pobierz najlepszy program do łatkowania ROM-ów. Wspiera typy łatek: IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP i XDelta3.\n\n</string>
<string name="share_text">Pobierz najlepszy program do łatkowania ROM-ów. Wspiera typy łatek: IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP i XDelta3.\n\n</string>
<!-- Navigation list -->
<string name="nav_apply_patch">Zastosuj łatkę</string>

View file

@ -131,7 +131,7 @@
<string name="send_feedback_error_no_email_apps">Не установлен email клиент</string>
<string name="share_dialog_title">Рассказать о UniPatcher</string>
<string name="share_text">Скачай лучший ROM патчер для Android. Поддерживает патчи в форматах IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP и XDelta3.\\n\\n
<string name="share_text">Скачай лучший ROM патчер для Android. Поддерживает патчи в форматах IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP и XDelta3.\\n\\n
</string>
<!-- Navigation list -->

View file

@ -131,7 +131,7 @@
<string name="send_feedback_error_no_email_apps">There are no email clients installed</string>
<string name="share_dialog_title">Share UniPatcher</string>
<string name="share_text">Download the best ROM patcher for Android. It supports IPS, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patch types.\n\n</string>
<string name="share_text">Download the best ROM patcher for Android. It supports IPS, IPS32, UPS, BPS, APS (GBA), APS (N64), PPF, DPS, EBP and XDelta3 patch types.\n\n</string>
<!-- Navigation list -->
<string name="nav_apply_patch">Apply patch</string>

View file

@ -74,6 +74,21 @@ public class IPSTest {
assertTrue(ApplyPatch("/ips/truncate.ips", "/ips/truncate.bin", "/ips/truncate_modified.bin"));
}
@Test
public void IPS32_MinPatch() throws Exception {
assertTrue(ApplyPatch("/ips/min_ips32.ips", "/ips/min_ips32.bin", "/ips/min_ips32_mod.bin"));
}
@Test
public void IPS32_RlePatch() throws Exception {
assertTrue(ApplyPatch("/ips/rle_ips32.ips", "/ips/rle_ips32.bin", "/ips/rle_ips32_mod.bin"));
}
@Test
public void IPS32_ExtendPatch() throws Exception {
assertTrue(ApplyPatch("/ips/extend_ips32.ips", "/ips/extend_ips32.bin", "/ips/extend_ips32_mod.bin"));
}
private boolean ApplyPatch(String patchName, String origName, String modifiedName) throws Exception {
File patch = new File(this.getClass().getResource(patchName).getPath());
File in = new File(getClass().getResource(origName).getPath());

View file

@ -0,0 +1 @@
7I57P‰'9R0H—… #u€r4… rCYrƒW—rW9E4u˜4 X#—X #G…#u˜# W#˜u 4u#…rW ˜C…G#u 0•x#—P4…G#…—#•r4 W 2G`tC TTeWFT‡FThFT„eHFTteAgHTeAhteAet˜FTWHtEcT˜yeEFWFThv†Te

Binary file not shown.

View file

@ -0,0 +1 @@
7Ie57P‰'9R0˙—… #u€r4… r222#—rW9E˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙u 4u#…rW <20>C…#B#u #C$2B—P4…G#…—#•r4 W 2G`tC TTeWFT‡FThFT„eHFTteAgHTe#B4eAet<65>FTWHtEcT<63>yeEFWFThv†TETeFCeA<65>te$<24>t25v‡F14eFC‡F5Tv„cQCVThFTeHFTe˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙ö”eGhCT„5„v5WFTeI‡

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1 @@
<EFBFBD>

View file

@ -0,0 +1 @@
<EFBFBD>!7I#d@<40>#Y†0G 6Y7—)€P‰#xP†E '<27> W#€”W #u<>#P—# …b0—… #P<>'0•r0…`<60>#u

Binary file not shown.

View file

@ -0,0 +1 @@
<EFBFBD>!7I#d@<40>#Y†0G 6Y7—)€P‰#xP†E '<27>˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙#u

View file

@ -8,6 +8,7 @@ Utility to apply patches to game rom.
<b>UniPatcher supports the most popular formats patches</b> used in Nintendo, Super Nintendo, Sega MegaDrive / Sega Genesis, Gameboy, Game Boy Advance, Sony PlayStation and other games:
&bull; IPS
&bull; IPS32
&bull; UPS
&bull; BPS
&bull; APS (GBA)

View file

@ -8,6 +8,7 @@ Utilità per applicare le patch alle ROM dei giochi.
<b>UniPatcher supporta i più popolari formati di patch</b> usati da Nintendo, Super Nintendo, Sega Mega Drive / Sega Genesis, Gameboy, Game Boy Advance, Sony PlayStation e altri giochi:
&bull; IPS
&bull; IPS32
&bull; UPS
&bull; BPS
&bull; APS (GBA)

View file

@ -8,6 +8,7 @@ Narzędzie do aplikowania łatek do ROM-ów
<b>UniPatcher wspiera najbardziej popularne łatki</b> używane w Nintendo, Super Nintendo, Sega MegaDrive / Sega Genesis, Gameboy, Game Boy Advance, Sony PlayStation i innych grach:
&bull; IPS
&bull; IPS32
&bull; UPS
&bull; BPS
&bull; APS (GBA)

View file

@ -8,6 +8,7 @@
<b>Unipatcher поддерживает самые популярные форматы патчей</b> используемые в играх Nintendo, Sega MegaDrive, Gameboy, Sony PlayStation и многих других:
&bull; IPS
&bull; IPS32
&bull; UPS
&bull; BPS
&bull; APS (GBA)