mirror of
https://github.com/pret/pokeplatinum.git
synced 2026-03-21 17:55:13 -05:00
decompile crypto utils (#994)
This commit is contained in:
parent
cae54c6ca1
commit
69521b0bee
|
|
@ -5,9 +5,9 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <crypto/util.h>
|
|
||||||
#include <crypto/sign.h>
|
|
||||||
#include <crypto/rc4.h>
|
#include <crypto/rc4.h>
|
||||||
|
#include <crypto/sign.h>
|
||||||
|
#include <crypto/util.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <nitro/types.h>
|
||||||
|
|
||||||
typedef struct CRYPTORC4Context_t {
|
typedef struct CRYPTORC4Context_t {
|
||||||
u8 i, j;
|
u8 i, j;
|
||||||
u8 padd[2];
|
u8 padd[2];
|
||||||
|
|
@ -21,24 +23,24 @@ void CRYPTO_RC4Encrypt(CRYPTORC4Context *, const void *, u32, void *);
|
||||||
void CRYPTO_RC4FastInit(CRYPTORC4FastContext *, const void *, u32);
|
void CRYPTO_RC4FastInit(CRYPTORC4FastContext *, const void *, u32);
|
||||||
void CRYPTO_RC4FastEncrypt(CRYPTORC4FastContext *, const void *, u32, void *);
|
void CRYPTO_RC4FastEncrypt(CRYPTORC4FastContext *, const void *, u32, void *);
|
||||||
|
|
||||||
static inline void CRYPTO_RC4Decrypt (CRYPTORC4Context * param0, const void * param1, u32 param2, void * param3)
|
static inline void CRYPTO_RC4Decrypt(CRYPTORC4Context *param0, const void *param1, u32 param2, void *param3)
|
||||||
{
|
{
|
||||||
CRYPTO_RC4Encrypt(param0, param1, param2, param3);
|
CRYPTO_RC4Encrypt(param0, param1, param2, param3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void CRYPTO_RC4 (const void * param0, u32 param1, void * param2, u32 param3)
|
static inline void CRYPTO_RC4(const void *param0, u32 param1, void *param2, u32 param3)
|
||||||
{
|
{
|
||||||
CRYPTORC4Context v0;
|
CRYPTORC4Context v0;
|
||||||
CRYPTO_RC4Init(&v0, param0, param1);
|
CRYPTO_RC4Init(&v0, param0, param1);
|
||||||
CRYPTO_RC4Encrypt(&v0, param2, param3, param2);
|
CRYPTO_RC4Encrypt(&v0, param2, param3, param2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void CRYPTO_RC4FastDecrypt (CRYPTORC4FastContext * param0, const void * param1, u32 param2, void * param3)
|
static inline void CRYPTO_RC4FastDecrypt(CRYPTORC4FastContext *param0, const void *param1, u32 param2, void *param3)
|
||||||
{
|
{
|
||||||
CRYPTO_RC4FastEncrypt(param0, param1, param2, param3);
|
CRYPTO_RC4FastEncrypt(param0, param1, param2, param3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void CRYPTO_RC4Fast (const void * param0, u32 param1, void * param2, u32 param3)
|
static inline void CRYPTO_RC4Fast(const void *param0, u32 param1, void *param2, u32 param3)
|
||||||
{
|
{
|
||||||
CRYPTORC4FastContext v0;
|
CRYPTORC4FastContext v0;
|
||||||
CRYPTO_RC4FastInit(&v0, param0, param1);
|
CRYPTO_RC4FastInit(&v0, param0, param1);
|
||||||
16
lib/crypto/include/crypto/util.h
Normal file
16
lib/crypto/include/crypto/util.h
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef POKEPLATINUM_CRYPTO_UTIL_H
|
||||||
|
#define POKEPLATINUM_CRYPTO_UTIL_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <nitro/types.h>
|
||||||
|
|
||||||
|
void CRYPTO_SetAllocator(void *(*allocFunc)(u32), void (*freeFunc)(void *));
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // POKEPLATINUM_CRYPTO_UTIL_H
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
project('libcrypto', ['c', 'nasm'])
|
|
||||||
|
|
||||||
asm_args = [
|
asm_args = [
|
||||||
'-proc', 'arm5TE',
|
'-proc', 'arm5TE',
|
||||||
'-16',
|
'-16',
|
||||||
'-gccinc'
|
'-gccinc'
|
||||||
]
|
]
|
||||||
|
|
||||||
public_includes = include_directories('include')
|
libcrypto_c_args = [
|
||||||
|
'-nothumb',
|
||||||
|
'-wrap:sdk', '1.2/sp2p3',
|
||||||
|
'-wrap:noipa'
|
||||||
|
]
|
||||||
|
|
||||||
|
libcrypto_public_includes = include_directories('include')
|
||||||
|
|
||||||
libcrypto_static_srcs = files(
|
libcrypto_static_srcs = files(
|
||||||
'asm/rc4.s',
|
'asm/rc4.s',
|
||||||
|
|
@ -16,7 +20,7 @@ libcrypto_static_srcs = files(
|
||||||
libcrypto_ov97_srcs = files(
|
libcrypto_ov97_srcs = files(
|
||||||
'asm/rc4s-arm4cw.s',
|
'asm/rc4s-arm4cw.s',
|
||||||
'asm/sign.s',
|
'asm/sign.s',
|
||||||
'asm/util.s'
|
'src/util.c'
|
||||||
)
|
)
|
||||||
|
|
||||||
libcrypto_static = static_library('crypto_static',
|
libcrypto_static = static_library('crypto_static',
|
||||||
|
|
@ -27,8 +31,11 @@ libcrypto_static = static_library('crypto_static',
|
||||||
|
|
||||||
libcrypto_ov97 = static_library('crypto_ov97',
|
libcrypto_ov97 = static_library('crypto_ov97',
|
||||||
sources: libcrypto_ov97_srcs,
|
sources: libcrypto_ov97_srcs,
|
||||||
|
c_args: libcrypto_c_args,
|
||||||
nasm_args: asm_args,
|
nasm_args: asm_args,
|
||||||
pic: false
|
pic: false,
|
||||||
|
include_directories: libcrypto_public_includes,
|
||||||
|
dependencies: nitrosdk_dep
|
||||||
)
|
)
|
||||||
|
|
||||||
libcrypto_dep = declare_dependency(
|
libcrypto_dep = declare_dependency(
|
||||||
4
lib/crypto/src/crypto_internal.h
Normal file
4
lib/crypto/src/crypto_internal.h
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#include <nitro/types.h>
|
||||||
|
|
||||||
|
void *CRYPTOi_MyAlloc(u32 size);
|
||||||
|
void CRYPTOi_MyFree(void *ptr);
|
||||||
33
lib/crypto/src/util.c
Normal file
33
lib/crypto/src/util.c
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#include "crypto/util.h"
|
||||||
|
|
||||||
|
#include <nitro/os.h>
|
||||||
|
#include <nitro/types.h>
|
||||||
|
|
||||||
|
#include "crypto_internal.h"
|
||||||
|
|
||||||
|
static void (*sFreeFunc)(void *ptr);
|
||||||
|
static void *(*sAllocFunc)(u32 size);
|
||||||
|
|
||||||
|
void *CRYPTOi_MyAlloc(u32 size)
|
||||||
|
{
|
||||||
|
if (sAllocFunc) {
|
||||||
|
return sAllocFunc(size);
|
||||||
|
} else {
|
||||||
|
return OS_AllocFromHeap(OS_ARENA_MAIN, OS_CURRENT_HEAP_HANDLE, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRYPTOi_MyFree(void *ptr)
|
||||||
|
{
|
||||||
|
if (sFreeFunc) {
|
||||||
|
sFreeFunc(ptr);
|
||||||
|
} else {
|
||||||
|
OS_FreeToHeap(OS_ARENA_MAIN, OS_CURRENT_HEAP_HANDLE, ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRYPTO_SetAllocator(void *(*allocFunc)(u32), void (*freeFunc)(void *))
|
||||||
|
{
|
||||||
|
sAllocFunc = allocFunc;
|
||||||
|
sFreeFunc = freeFunc;
|
||||||
|
}
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
|
subdir('crypto')
|
||||||
subdir('gds')
|
subdir('gds')
|
||||||
subdir('spl')
|
subdir('spl')
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,6 @@ nitrodwc_dep = dependency('NitroDWC',
|
||||||
)
|
)
|
||||||
|
|
||||||
libvct_dep = dependency('libvct')
|
libvct_dep = dependency('libvct')
|
||||||
libcrypto_dep = dependency('libcrypto')
|
|
||||||
libsyscall_dep = dependency('libsyscall')
|
libsyscall_dep = dependency('libsyscall')
|
||||||
ppwlobby_dep = dependency('ppwlobby')
|
ppwlobby_dep = dependency('ppwlobby')
|
||||||
|
|
||||||
|
|
@ -187,6 +186,7 @@ main = executable('main',
|
||||||
c_pch: 'include/pch/global_pch.h',
|
c_pch: 'include/pch/global_pch.h',
|
||||||
include_directories: [
|
include_directories: [
|
||||||
public_includes,
|
public_includes,
|
||||||
|
libcrypto_public_includes,
|
||||||
libgds_public_includes,
|
libgds_public_includes,
|
||||||
libspl_public_includes,
|
libspl_public_includes,
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
.public OS_AllocFromHeap
|
|
||||||
.public OS_FreeToHeap
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
.include "macros/function.inc"
|
|
||||||
.include "include/util.inc"
|
|
||||||
|
|
||||||
|
|
||||||
.text
|
|
||||||
|
|
||||||
|
|
||||||
arm_func_start CRYPTO_SetAllocator
|
|
||||||
CRYPTO_SetAllocator: ; 0x0223D5C8
|
|
||||||
ldr r3, _0223D5DC ; =0x02240AF4
|
|
||||||
ldr r2, _0223D5E0 ; =0x02240AF8
|
|
||||||
str r0, [r3, #0]
|
|
||||||
str r1, [r2, #0]
|
|
||||||
bx lr
|
|
||||||
; .align 2, 0
|
|
||||||
_0223D5DC: .word 0x02240AF4
|
|
||||||
_0223D5E0: .word 0x02240AF8
|
|
||||||
arm_func_end CRYPTO_SetAllocator
|
|
||||||
|
|
||||||
arm_func_start CRYPTOi_MyFree
|
|
||||||
CRYPTOi_MyFree: ; 0x0223D5E4
|
|
||||||
stmdb sp!, {lr}
|
|
||||||
sub sp, sp, #4
|
|
||||||
ldr r1, _0223D628 ; =0x02240AF8
|
|
||||||
mov r2, r0
|
|
||||||
ldr r1, [r1, #0]
|
|
||||||
cmp r1, #0
|
|
||||||
beq _0223D610
|
|
||||||
blx r1
|
|
||||||
add sp, sp, #4
|
|
||||||
ldmia sp!, {lr}
|
|
||||||
bx lr
|
|
||||||
_0223D610:
|
|
||||||
mov r0, #0
|
|
||||||
mvn r1, #0
|
|
||||||
bl OS_FreeToHeap
|
|
||||||
add sp, sp, #4
|
|
||||||
ldmia sp!, {lr}
|
|
||||||
bx lr
|
|
||||||
; .align 2, 0
|
|
||||||
_0223D628: .word 0x02240AF8
|
|
||||||
arm_func_end CRYPTOi_MyFree
|
|
||||||
|
|
||||||
arm_func_start CRYPTOi_MyAlloc
|
|
||||||
CRYPTOi_MyAlloc: ; 0x0223D62C
|
|
||||||
stmdb sp!, {lr}
|
|
||||||
sub sp, sp, #4
|
|
||||||
ldr r1, _0223D670 ; =0x02240AF4
|
|
||||||
mov r2, r0
|
|
||||||
ldr r1, [r1, #0]
|
|
||||||
cmp r1, #0
|
|
||||||
beq _0223D658
|
|
||||||
blx r1
|
|
||||||
add sp, sp, #4
|
|
||||||
ldmia sp!, {lr}
|
|
||||||
bx lr
|
|
||||||
_0223D658:
|
|
||||||
mov r0, #0
|
|
||||||
mvn r1, #0
|
|
||||||
bl OS_AllocFromHeap
|
|
||||||
add sp, sp, #4
|
|
||||||
ldmia sp!, {lr}
|
|
||||||
bx lr
|
|
||||||
; .align 2, 0
|
|
||||||
_0223D670: .word 0x02240AF4
|
|
||||||
arm_func_end CRYPTOi_MyAlloc
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
#ifndef POKEPLATINUM_UTIL_H
|
|
||||||
#define POKEPLATINUM_UTIL_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void CRYPTO_SetAllocator(void *(* param0)(u32), void (* param1)(void *));
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // POKEPLATINUM_UTIL_H
|
|
||||||
|
|
@ -203,33 +203,6 @@ libvct_c_commands = [
|
||||||
for file in (homedir / "subprojects/libvct-1.3.1").rglob("*.c")
|
for file in (homedir / "subprojects/libvct-1.3.1").rglob("*.c")
|
||||||
]
|
]
|
||||||
|
|
||||||
libcrypto_c_commands = [
|
|
||||||
{
|
|
||||||
"directory": builddir,
|
|
||||||
"arguments": arm9_c_flags
|
|
||||||
+ [
|
|
||||||
f"-I{cwlibcdir}",
|
|
||||||
f"-I{cwextrasdir}",
|
|
||||||
f"-I{cwlibcarmdir}",
|
|
||||||
f"-I{cwextrasarmdir}",
|
|
||||||
f"-I{homedir}/subprojects/NitroSDK-4.2.30001/include",
|
|
||||||
f"-I{builddir}/subprojects/NitroSDK-4.2.30001/gen",
|
|
||||||
f"-I{homedir}/subprojects/NitroSystem-071126.1/include",
|
|
||||||
f"-I{homedir}/subprojects/NitroWiFi-2.1.30003/include",
|
|
||||||
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include",
|
|
||||||
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/gs",
|
|
||||||
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/base",
|
|
||||||
f"-I{homedir}/subprojects/libvct-1.3.1/include",
|
|
||||||
f"-I{homedir}/subprojects/libcrypto/include",
|
|
||||||
"-o",
|
|
||||||
file.with_suffix(".o"),
|
|
||||||
file.resolve(),
|
|
||||||
],
|
|
||||||
"file": file.resolve(),
|
|
||||||
}
|
|
||||||
for file in (homedir / "subprojects/libcrypto").rglob("*.c")
|
|
||||||
]
|
|
||||||
|
|
||||||
ppwlobby_c_commands = [
|
ppwlobby_c_commands = [
|
||||||
{
|
{
|
||||||
"directory": builddir,
|
"directory": builddir,
|
||||||
|
|
@ -247,7 +220,7 @@ ppwlobby_c_commands = [
|
||||||
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/gs",
|
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/gs",
|
||||||
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/base",
|
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/base",
|
||||||
f"-I{homedir}/subprojects/libvct-1.3.1/include",
|
f"-I{homedir}/subprojects/libvct-1.3.1/include",
|
||||||
f"-I{homedir}/subprojects/libcrypto/include",
|
f"-I{homedir}/lib/crypto/include",
|
||||||
f"-I{homedir}/subprojects/ppwlobby/include",
|
f"-I{homedir}/subprojects/ppwlobby/include",
|
||||||
"-o",
|
"-o",
|
||||||
file.with_suffix(".o"),
|
file.with_suffix(".o"),
|
||||||
|
|
@ -276,8 +249,8 @@ c_commands = [
|
||||||
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/gs",
|
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/gs",
|
||||||
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/base",
|
f"-I{homedir}/subprojects/NitroDWC-2.2.30008/include/base",
|
||||||
f"-I{homedir}/subprojects/libvct-1.3.1/include",
|
f"-I{homedir}/subprojects/libvct-1.3.1/include",
|
||||||
f"-I{homedir}/subprojects/libcrypto/include",
|
|
||||||
f"-I{homedir}/subprojects/ppwlobby/include",
|
f"-I{homedir}/subprojects/ppwlobby/include",
|
||||||
|
f"-I{homedir}/lib/crypto/include",
|
||||||
f"-I{homedir}/lib/gds/include",
|
f"-I{homedir}/lib/gds/include",
|
||||||
f"-I{homedir}/lib/spl/include",
|
f"-I{homedir}/lib/spl/include",
|
||||||
f"-iquote{homedir}",
|
f"-iquote{homedir}",
|
||||||
|
|
@ -346,7 +319,6 @@ with open("compile_commands.json", "w") as ofp:
|
||||||
+ nitrowifi_c_commands
|
+ nitrowifi_c_commands
|
||||||
+ nitrodwc_c_commands
|
+ nitrodwc_c_commands
|
||||||
+ libvct_c_commands
|
+ libvct_c_commands
|
||||||
+ libcrypto_c_commands
|
|
||||||
+ ppwlobby_c_commands
|
+ ppwlobby_c_commands
|
||||||
+ c_commands
|
+ c_commands
|
||||||
+ datagen_cpp_commands
|
+ datagen_cpp_commands
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ OUT_FILE=ctx.c
|
||||||
|
|
||||||
GCC=gcc
|
GCC=gcc
|
||||||
FLAGS="-E -P -dD -undef"
|
FLAGS="-E -P -dD -undef"
|
||||||
INCLUDES="-Itools/cw/include -Isubprojects/NitroSDK-4.2.30001/include -Ibuild/subprojects/NitroSDK-4.2.30001/gen -Isubprojects/NitroSystem-071126.1/include -Isubprojects/NitroWiFi-2.1.30003/include -Isubprojects/NitroDWC-2.2.30008/include -Isubprojects/libvct-1.3.1/include -Isubprojects/libcrypto/include -Isubprojects/ppwlobby/include -Iinclude -Iasm -Ires -Ilib/gds/include -Ilib/spl/include -Ibuild -Ibuild/res/text -include pch/global_pch.h"
|
INCLUDES="-Itools/cw/include -Isubprojects/NitroSDK-4.2.30001/include -Ibuild/subprojects/NitroSDK-4.2.30001/gen -Isubprojects/NitroSystem-071126.1/include -Isubprojects/NitroWiFi-2.1.30003/include -Isubprojects/NitroDWC-2.2.30008/include -Isubprojects/libvct-1.3.1/include -Isubprojects/ppwlobby/include -Iinclude -Iasm -Ires -Ilib/crypto/include -Ilib/gds/include -Ilib/spl/include -Ibuild -Ibuild/res/text -include pch/global_pch.h"
|
||||||
DEFINES="-DGAME_VERSION=VERSION_PLATINUM -DGAME_LANGUAGE=ENGLISH -DPM_KEEP_ASSERTS -D_NITRO -DLINK_PPWLOBBY -DNNS_FINALROM -DSDK_4M -DSDK_ARM9 -DSDK_CODE_ARM -DSDK_CW -DSDK_CW_FORCE_EXPORT_SUPPORT -DSDK_FINALROM -DSDK_TS"
|
DEFINES="-DGAME_VERSION=VERSION_PLATINUM -DGAME_LANGUAGE=ENGLISH -DPM_KEEP_ASSERTS -D_NITRO -DLINK_PPWLOBBY -DNNS_FINALROM -DSDK_4M -DSDK_ARM9 -DSDK_CODE_ARM -DSDK_CW -DSDK_CW_FORCE_EXPORT_SUPPORT -DSDK_FINALROM -DSDK_TS"
|
||||||
|
|
||||||
generate-ctx () {
|
generate-ctx () {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user