mirror of
https://github.com/ApacheThunder/NTR_Launcher.git
synced 2025-06-19 03:25:38 -04:00

* Added DSOnei kernel to included nds files for Stage2 menu. * Added N-Card rom dump to included nds files for Stage2 menu. * Added CycloDS, and DSTWo bootloader dumps to included nds files for Stage2 menu. * DSTwo now boots correctly from cart launcher. * R4 SDHC Gold and other similar DEMON time bomb DSTTi clones now boot correctly from cart launcher. * Added back option for enabling/disabling TWL ram. * Added fixes to allow DS only carts to run with TWL ram enabled. * Initial modcrypt code added for TWL carts. Currently works in emulation however TWL carts will fail to boot on hardware (when twl mode, ram, etc is enabled). * If TWL mode and ram is enabled, cart loader will now load the DSi extended binaries into ram. Currently however they will only boot in emulation. Have not resolved why it's not working on hardware yet. * Stage2 menu now allowed to load dsi extended binaries of SRLs if TWL mode and TWL ram is enabled. Booting rom dumps as a method of booting into TWL carts is confirmed working. At least for System Flaw it does. :D * Despite the improvents Acekard 2i still appears to require using the stage2 menu to boot into. * Fixes that allowed Demon timebomb carts to boot from cart launcher/autoboot may allow other non working carts to work. Further testing needed.
113 lines
2.8 KiB
C
Executable File
113 lines
2.8 KiB
C
Executable File
/*
|
|
NitroHax -- Cheat tool for the Nintendo DS
|
|
Copyright (C) 2008 Michael "Chishm" Chisholm
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include "encryption.h"
|
|
#include "key1.h"
|
|
#include "key2.h"
|
|
#include "tonccpy.h"
|
|
|
|
#define KEYSIZE 0x1048
|
|
|
|
static u32 keycode [3];
|
|
static u32 keybuf [KEYSIZE/sizeof(u32)];
|
|
|
|
void crypt_64bit_up (u32* ptr) {
|
|
u32 x = ptr[1];
|
|
u32 y = ptr[0];
|
|
u32 z;
|
|
int i;
|
|
|
|
for (i = 0; i < 0x10; i++) {
|
|
z = keybuf[i] ^ x;
|
|
x = keybuf[0x012 + ((z>>24)&0xff)];
|
|
x = keybuf[0x112 + ((z>>16)&0xff)] + x;
|
|
x = keybuf[0x212 + ((z>> 8)&0xff)] ^ x;
|
|
x = keybuf[0x312 + ((z>> 0)&0xff)] + x;
|
|
x = y ^ x;
|
|
y = z;
|
|
}
|
|
|
|
ptr[0] = x ^ keybuf[0x10];
|
|
ptr[1] = y ^ keybuf[0x11];
|
|
}
|
|
|
|
void crypt_64bit_down (u32* ptr) {
|
|
u32 x = ptr[1];
|
|
u32 y = ptr[0];
|
|
u32 z;
|
|
int i;
|
|
|
|
for (i = 0x11; i > 0x01; i--) {
|
|
z = keybuf[i] ^ x;
|
|
x = keybuf[0x012 + ((z>>24)&0xff)];
|
|
x = keybuf[0x112 + ((z>>16)&0xff)] + x;
|
|
x = keybuf[0x212 + ((z>> 8)&0xff)] ^ x;
|
|
x = keybuf[0x312 + ((z>> 0)&0xff)] + x;
|
|
x = y ^ x;
|
|
y = z;
|
|
}
|
|
|
|
ptr[0] = x ^ keybuf[0x01];
|
|
ptr[1] = y ^ keybuf[0x00];
|
|
}
|
|
|
|
static u32 bswap_32bit (u32 in) {
|
|
u8 a,b,c,d;
|
|
a = (u8)((in >> 0) & 0xff);
|
|
b = (u8)((in >> 8) & 0xff);
|
|
c = (u8)((in >> 16) & 0xff);
|
|
d = (u8)((in >> 24) & 0xff);
|
|
|
|
u32 out = (a << 24) | (b << 16) | (c << 8) | (d << 0);
|
|
|
|
return out;
|
|
}
|
|
|
|
void apply_keycode (u32 modulo) {
|
|
u32 scratch[2];
|
|
int i;
|
|
modulo = modulo / sizeof(*keycode);
|
|
|
|
crypt_64bit_up (&keycode[1]);
|
|
crypt_64bit_up (&keycode[0]);
|
|
toncset (scratch, 0, 8);
|
|
|
|
for (i = 0; i < 0x12; i+=1) {
|
|
keybuf[i] = keybuf[i] ^ bswap_32bit (keycode[i % modulo]);
|
|
}
|
|
for (i = 0; i < 0x412; i+=2) {
|
|
crypt_64bit_up (scratch);
|
|
keybuf[i] = scratch[1];
|
|
keybuf[i+1] = scratch[0];
|
|
}
|
|
}
|
|
|
|
void init_keycode (u32 idcode, u32 level, u32 modulo, int iCardDevice) {
|
|
tonccpy ((u8*)keybuf, (iCardDevice ? gEncrDataTwl : gEncrData), KEYSIZE);
|
|
keycode[0] = idcode;
|
|
keycode[1] = idcode/2;
|
|
keycode[2] = idcode*2;
|
|
|
|
if (level >= 1) apply_keycode (modulo); // first apply (always)
|
|
if (level >= 2) apply_keycode (modulo); // second apply (optional)
|
|
keycode[1] = keycode[1] * 2;
|
|
keycode[2] = keycode[2] / 2;
|
|
if (level >= 3) apply_keycode (modulo); // third apply (optional)
|
|
}
|