Update dsd to v0.12.0; dsprot OK (#135)

* `Actor::mType` field

* Remove fake symbol `data_027e0254`

* `dsd format`

* eur: Enable dsprot decomp

* jp: Enable dsprot decomp

* dsprot OK

* `dsd format`

* Use new `weak` attribute

* Add relocations for exception table link-time constants

* Add exception table symbols

* Bump dsd to v0.12.0

* `#define FALSE 1` ???
Why did I make it 1?

* Truncate `data_ov001_020c27a8`
That data belongs to dsprot
This commit is contained in:
Aetias
2026-08-15 01:07:14 +02:00
committed by GitHub
parent ce24ddfc4e
commit 521100caed
104 changed files with 4547 additions and 2014 deletions
+127
View File
@@ -0,0 +1,127 @@
//=================================================================================================
/**
* dsprot.h
*
* Header file for the DS Protect library
* Version 1.23z
*/
//=================================================================================================
#ifndef DSPROT_H
#define DSPROT_H
#define DSP_VERSION (123)
#define DSP_VERSION_STR "1.23z"
#ifndef SDK_ASM
#ifndef DSP_NO_NITRO
#include <nitro/types.h> // For u32
#else /* DSP_NO_NITRO */
// Assumption for convenience-- make sure this is matching if you use it!
typedef unsigned long __dsp_u32;
#define u32 __dsp_u32
#endif /* DSP_NO_NITRO */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
//=================================================================================================
/**
* Detect if the current environment is a flashcart.
*
* @param callback Function to be called if the environment is determined to be a flashcart.
* May be NULL.
*
* @return 1 if the environment is determined to be a flashcart, 0 otherwise
*/
//=================================================================================================
extern u32 DSProt_DetectFlashcart(void *callback);
//=================================================================================================
/**
* Detect if the current environment is NOT a flashcart.
*
* @param callback Function to be called if the environment is determined to NOT be a flashcart.
* May be NULL.
*
* @return 1 if the environment is determined to NOT be a flashcart, 0 otherwise
*/
//=================================================================================================
extern u32 DSProt_DetectNotFlashcart(void *callback);
//=================================================================================================
/**
* Detect if the current environment is an emulator.
*
* @param callback Function to be called if the environment is determined to be an emulator.
* May be NULL.
*
* @return 1 if the environment is determined to be an emulator, 0 otherwise
*/
//=================================================================================================
extern u32 DSProt_DetectEmulator(void *callback);
//=================================================================================================
/**
* Detect if the current environment is NOT an emulator.
*
* @param callback Function to be called if the environment is determined to NOT be an emulator.
* May be NULL.
*
* @return 1 if the environment is determined to NOT be an emulator, 0 otherwise
*/
//=================================================================================================
extern u32 DSProt_DetectNotEmulator(void *callback);
//=================================================================================================
/**
* Dummy environment detection function that does not do anything. Will always fail.
*
* @param callback Dummy callback function which will never be called. May be NULL.
*
* @return 0
*/
//=================================================================================================
extern u32 DSProt_DetectDummy(void *callback);
//=================================================================================================
/**
* Dummy environment detection function that does not do anything. Will always succeed.
*
* @param callback Dummy callback function which will always be called. May be NULL.
*
* @return 1
*/
//=================================================================================================
extern u32 DSProt_DetectNotDummy(void *callback);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#ifdef DSP_NO_NITRO
#undef u32
#endif /* DSP_NO_NITRO */
#else /* SDK_ASM */
// clang-format off
.public DSProt_DetectFlashcart
.public DSProt_DetectNotFlashcart
.public DSProt_DetectEmulator
.public DSProt_DetectNotEmulator
.public DSProt_DetectDummy
.public DSProt_DetectNotDummy
// clang-format on
#endif /* SDK_ASM */
#endif /* DSPROT_H */
+91
View File
@@ -0,0 +1,91 @@
#pragma once
#include "dsprot/encoding_constants.h"
.macro arm_func_start name
.balign 4, 0
.global \name
.type \name, @function
.arm
.endm
.macro local_arm_func_start name
.balign 4, 0
.type \name, @function
.arm
.endm
.macro arm_func_end name
.size \name, .-\name
.endm
.macro sinit sinit_func
.type NitroStaticInit_\@, @object
NitroStaticInit_\@:
.word \sinit_func
.size NitroStaticInit_\@, .-NitroStaticInit_\@
.endm
.public DSProt_BSS
.public Encryptor_DecryptFunction
.public Encryptor_EncryptFunction
.macro run_encrypted_func func, length, key
stmfd sp!, {r4-r7} ; `r0`-`r3` contain the arguments that must be passed into the inner function.
stmfd sp!, {r0-r3} ; Stack manipulation to move `r0`-`r3` into `r4`-`r7` for storage.
ldmfd sp!, {r4-r7} ; Original values of `r4`-`r7` get pushed onto the stack.
ldr r1, func_\@ ; Get second function decrypter argument, obfuscated function address.
adr r3, storage_\@ ; `lr` cannot be stored on the stack when we call the inner function,
str lr, [r3] ; so it is stored in the pool below.
ldr r2, length_\@ ; Get third function decrypter argument, obfuscated length.
ldr r0, key_\@ ; Get first function decrypter argument, obfuscated key.
bl Encryptor_DecryptFunction ; Call function decrypter with args (key, addr, len).
mov ip, r0 ; Function decrypter returns the de-obfuscated function address. Save it in `ip`.
stmfd sp!, {r4-r7} ; Stack manipulation again to restore the original `r0`-`r3`.
ldmfd sp!, {r0-r3} ;
ldmfd sp!, {r4-r7} ; Stack is now restored, so `sp` is correct for the inner function call.
blx ip ; Call inner function.
stmfd sp!, {r4} ; `r4` about to be used as storage space for the inner function return, so save it on the stack.
mov r4, r0 ; Copy the return from the inner function into `r4` so we can can run the function re-encrypter.
ldr r1, func_\@ ; Get second function encrypter argument, obfuscated function address.
ldr r2, length_\@ ; Get third function encrypter argument, obfuscated length.
ldr r0, key_\@ ; Get first function encrypter argument, obfuscated key.
bl Encryptor_EncryptFunction ; Call function encrypter.
str r0, key_\@ ; Function encrypter returns the new key it used, store this back into the pool for next time.
mov r0, r4 ; Restore the return value from the inner function from `r4` to `r0`.
ldmfd sp!, {r4} ; Restore the original value of `r4` from the stack.
ldr lr, storage_\@ ; Load `lr` return address back from the storage space in the pool.
str pc, storage_\@ ; Store `pc` in its place, presumably just to overwrite the return address.
bx lr ; Return with return value from inner function.
storage_\@:
.word DSProt_BSS + 1
length_\@:
.word DSProt_BSS + \length + ENC_VAL_1
key_\@:
.word DSProt_BSS + \key + ENC_VAL_1
func_\@:
.word \func + ENC_VAL_1
.endm
.public Encryptor_DecodeFunctionTable
.macro decode_func_table table
stmdb sp!, {lr}
adr r0, \table
bl Encryptor_DecodeFunctionTable
ldmia sp!, {pc}
.endm
.macro func_table_entry func, size
.word \func + ENC_VAL_1, DSProt_BSS + \size + ENC_VAL_1
.endm
.macro func_table_end
.word 0, 0
.endm
.macro garbage_ref ref
.word \ref + ENC_VAL_1
.endm
+8
View File
@@ -0,0 +1,8 @@
#ifndef BSS_H
#define BSS_H
#include <nitro/types.h>
extern u8 DSProt_BSS[4];
#endif
@@ -0,0 +1,21 @@
#ifndef ENCODING_CONSTANTS_H
#define ENCODING_CONSTANTS_H
#define INS_OPCODE_LINKBIT (0x01)
#define INS_OPCODE_MASK (0xFF000000)
#define INS_OPCODE_SHIFT (24)
#define INS_OPERANDS_MASK (0x00FFFFFF)
#define ADDR_PLUS_ADDEND(ref, addend) ((u32) (&ref + ((addend) / sizeof(ref))))
#define ENC_VAL_1 (0x1400)
#define ENC_VAL_2 ((ENC_VAL_1 >> 2) + 2)
#define ENC_BYTE_A (0x65)
#define ENC_BYTE_B (0x56)
#define ENC_BYTE_C (0x68)
#define ENC_BYTE_D (0xD0)
#define ENC_SBOX_XOR (0x01)
#endif
+23
View File
@@ -0,0 +1,23 @@
#ifndef ENCRYPTOR_H
#define ENCRYPTOR_H
#include <nitro/types.h>
typedef struct {
u32 obfs_addr;
u32 obfs_size;
} FuncInfo;
enum {
INS_TYPE_OTHER = 0,
INS_TYPE_BLXIMM,
INS_TYPE_BL,
INS_TYPE_B
};
u32 Encryptor_CategorizeInstruction(u32 instruction);
void Encryptor_DecodeFunctionTable(FuncInfo *functions);
void *Encryptor_DecryptFunction(u32 key, u32 func_addr, u32 size);
u32 Encryptor_EncryptFunction(u32 key, u32 func_addr, u32 size);
#endif
+8
View File
@@ -0,0 +1,8 @@
#ifndef GARBAGE_H
#define GARBAGE_H
#include <nitro/types.h>
extern const u32 DSProt_Garbage[6];
#endif
+12
View File
@@ -0,0 +1,12 @@
#ifndef INTEGRITY_H
#define INTEGRITY_H
#include <nitro/types.h>
// Assembly decryption wrappers
extern u32 RunEncrypted_Integrity_MACOwner_IsBad(void);
extern u32 RunEncrypted_Integrity_MACOwner_IsGood(void);
extern u32 RunEncrypted_Integrity_ROMTest_IsBad(void);
extern u32 RunEncrypted_Integrity_ROMTest_IsGood(void);
#endif
+10
View File
@@ -0,0 +1,10 @@
#ifndef MAC_OWNER_H
#define MAC_OWNER_H
#include <nitro/types.h>
// Assembly decryption wrappers
extern u32 RunEncrypted_MACOwner_IsBad(void);
extern u32 RunEncrypted_MACOwner_IsGood(void);
#endif
+9
View File
@@ -0,0 +1,9 @@
#ifndef RC4_H
#define RC4_H
#include <nitro/types.h>
u32 RC4_InitAndEncryptInstructions(void *key, void *dst, void *src, u32 size);
u32 RC4_InitAndDecryptInstructions(void *key, void *dst, void *src, u32 size);
#endif
+10
View File
@@ -0,0 +1,10 @@
#ifndef ROM_TEST_H
#define ROM_TEST_H
#include <nitro/types.h>
// Assembly decryption wrappers
extern u32 RunEncrypted_ROMTest_IsBad(void);
extern u32 RunEncrypted_ROMTest_IsGood(void);
#endif
+10
View File
@@ -0,0 +1,10 @@
#ifndef ROM_UTIL_H
#define ROM_UTIL_H
#include <nitro/types.h>
// Assembly decryption wrappers
extern void RunEncrypted_ROMUtil_Read(void *dest, u32 addr, s32 num_bytes);
extern u32 RunEncrypted_ROMUtil_CRC32(void *buf, u32 size);
#endif