Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CFLAGS := -g -Wall -Wextra -O3 -mword-relocations \
-fomit-frame-pointer -ffast-math \
$(ARCH)

CFLAGS += $(INCLUDE) -DARM11 -D_3DS -DARM_ARCH -w
CFLAGS += $(INCLUDE) -DARM11 -D__3DS__ -DARM_ARCH -w

ifdef PAYLOAD_PATH
CFLAGS += -DPAYLOAD_PATH=\"$(PAYLOAD_PATH)\"
Expand Down
1 change: 1 addition & 0 deletions include/brahma.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

u32 brahma_init (void);
u32 brahma_exit (void);
s32 load_arm9_payload (char *filename, u32 offset, u32 max_psize);
s32 load_arm9_payload_offset (char *filename, u32 offset, u32 max_psize);
s32 load_arm9_payload_from_mem (u8* data, u32 dsize);
void redirect_codeflow (u32 *dst_addr, u32 *src_addr);
Expand Down
7 changes: 7 additions & 0 deletions include/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

void InvalidateEntireInstructionCache(void);
void CleanEntireDataCache(void);
void dsb(void);
void DisableInterrupts(void);
void EnableInterrupts(void);
18 changes: 10 additions & 8 deletions source/brahma.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#include <string.h>
#include <malloc.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/_default_fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "brahma.h"
#include "exploitdata.h"
#include "utils.h"
#include "libkhax/khax.h"

static u8 *g_ext_arm9_buf;
Expand Down Expand Up @@ -37,7 +39,7 @@ u32 brahma_exit (void) {
/* overwrites two instructions (8 bytes in total) at src_addr
with code that redirects execution to dst_addr */
void redirect_codeflow (u32 *dst_addr, u32 *src_addr) {
*(src_addr + 1) = dst_addr;
*(src_addr + 1) = (u32)dst_addr;
*src_addr = ARM_JUMPOUT;
}

Expand All @@ -46,7 +48,7 @@ void redirect_codeflow (u32 *dst_addr, u32 *src_addr) {
returns: 0 on failure, 1 on success */
s32 get_exploit_data (struct exploit_data *data) {
u32 fversion = 0;
u8 isN3DS = 0;
bool isN3DS = false;
s32 i;
s32 result = 0;
u32 sysmodel = SYS_MODEL_NONE;
Expand Down Expand Up @@ -314,13 +316,13 @@ void exploit_arm9_race_condition (void) {
/* patch ARM11 kernel to force it to execute
our code (hook1 and hook2) as soon as a
"firmlaunch" is triggered */
redirect_codeflow(g_expdata.va_exc_handler_base_X +
OFFS_EXC_HANDLER_UNUSED,
g_expdata.va_patch_hook1);
redirect_codeflow((u32 *)(g_expdata.va_exc_handler_base_X +
OFFS_EXC_HANDLER_UNUSED),
(u32 *)g_expdata.va_patch_hook1);

redirect_codeflow(PA_EXC_HANDLER_BASE +
OFFS_EXC_HANDLER_UNUSED + 4,
g_expdata.va_patch_hook2);
redirect_codeflow((u32 *)(PA_EXC_HANDLER_BASE +
OFFS_EXC_HANDLER_UNUSED + 4),
(u32 *)g_expdata.va_patch_hook2);

CleanEntireDataCache();
dsb();
Expand Down
1 change: 1 addition & 0 deletions source/hid.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <3ds.h>
#include <stdio.h>

/* loop until key is pressed */
u32 wait_key (void) {
Expand Down