This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmenuhax_loader.s
62 lines (45 loc) · 1.93 KB
/
menuhax_loader.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@ This is intended to be included by an exploit .s stage0/stage1.
#define menuhaxloader_tmpdata 0x0FFF0000
#define menuhaxloader_IFile_ctx (menuhaxloader_tmpdata+4)
#ifndef STAGE1
CALLFUNC_NOSP FS_MountSdmc, ROPBUFLOC(menuhaxloader_sd_archivename), 0, 0, 0
#endif
#ifdef STAGE1
@ Close the file-ctx from stage0, then clear the ctx.
ROPMACRO_IFile_Close menuhaxloader_IFile_ctx
CALLFUNC_NOSP MEMSET32_OTHER, menuhaxloader_IFile_ctx, 0x20, 0, 0
#endif
@ Load the file into the buffer.
CALLFUNC_NOSP IFile_Open, menuhaxloader_IFile_ctx, ROPBUFLOC(menuhaxloader_sdfile_path), 1, 0
CALLFUNC_NOSP IFile_Read, menuhaxloader_IFile_ctx, menuhaxloader_tmpdata, MENUHAXLOADER_LOAD_BINADDR, MENUHAXLOADER_LOAD_SIZE
#ifdef STAGE1
ROPMACRO_IFile_Close menuhaxloader_IFile_ctx
#endif
#ifdef STAGE1
@ Verify that the file was loaded successfully, on failure(first word in buf is 0x0) jump to menuhaxloader_returnaddr.
ROPMACRO_CMPDATA MENUHAXLOADER_LOAD_BINADDR, 0x0, ROPBUFLOC(menuhaxloader_bootrop)
ROPMACRO_STACKPIVOT ROPBUFLOC(menuhaxloader_returnaddr), ROP_POPPC
#endif
menuhaxloader_bootrop:
#ifdef STAGE1
@ Write the sp return-addr(menuhaxloader_returnaddr) used during ret2menu to buffer+4.
ROPMACRO_WRITEWORD (MENUHAXLOADER_LOAD_BINADDR+4), ROPBUFLOC(menuhaxloader_returnaddr)
@ Write the sp jump-addr(menuhaxloader_beforethreadexit) used right before the menuhax-thread exits, to buffer+8.
ROPMACRO_WRITEWORD (MENUHAXLOADER_LOAD_BINADDR+8), ROPBUFLOC(menuhaxloader_beforethreadexit)
#endif
@ Jump to the buffer.
ROPMACRO_STACKPIVOT MENUHAXLOADER_LOAD_BINADDR, ROP_POPPC
#ifndef STAGE1
menuhaxloader_sd_archivename:
.string "sd:"
.align 2
#endif
menuhaxloader_sdfile_path:
.string16 MENUHAXLOADER_BINPAYLOAD_PATH
.align 2
#ifdef STAGE1
ropkit_cmpobject:
.word (ROPBUFLOC(ropkit_cmpobject) + 0x4) @ Vtable-ptr
.fill (0x40 / 4), 4, STACKPIVOT_ADR @ Vtable
#endif
menuhaxloader_returnaddr: @ The RET2MENU ROP starts here in the .s which included this menuhax_loader.s.