| 1 | |
| 2 | #include "3ds.h" |
| 3 | #include "libkhax/khax.h" |
| 4 | |
| 5 | static int ninjhax_version = 0; |
| 6 | |
| 7 | typedef s32 (*ctr_callback_type)(void); |
| 8 | |
| 9 | static void ctr_enable_all_svc_kernel(void) |
| 10 | { |
| 11 | __asm__ volatile("cpsid aif"); |
| 12 | |
| 13 | u32* svc_access_control = *(*(u32***)0xFFFF9000 + 0x22) - 0x6; |
| 14 | |
| 15 | svc_access_control[0]=0xFFFFFFFE; |
| 16 | svc_access_control[1]=0xFFFFFFFF; |
| 17 | svc_access_control[2]=0xFFFFFFFF; |
| 18 | svc_access_control[3]=0x3FFFFFFF; |
| 19 | } |
| 20 | |
| 21 | |
| 22 | static void ctr_invalidate_ICache_kernel(void) |
| 23 | { |
| 24 | __asm__ volatile( |
| 25 | "cpsid aif\n\t" |
| 26 | "mov r0, #0\n\t" |
| 27 | "mcr p15, 0, r0, c7, c5, 0\n\t"); |
| 28 | } |
| 29 | |
| 30 | static void ctr_flush_DCache_kernel(void) |
| 31 | { |
| 32 | __asm__ volatile( |
| 33 | "cpsid aif\n\t" |
| 34 | "mov r0, #0\n\t" |
| 35 | "mcr p15, 0, r0, c7, c10, 0\n\t"); |
| 36 | |
| 37 | } |
| 38 | |
| 39 | |
| 40 | static void ctr_enable_all_svc(void) |
| 41 | { |
| 42 | svcBackdoor((ctr_callback_type)ctr_enable_all_svc_kernel); |
| 43 | } |
| 44 | |
| 45 | void ctr_invalidate_ICache(void) |
| 46 | { |
| 47 | // __asm__ volatile("svc 0x2E\n\t"); |
| 48 | svcBackdoor((ctr_callback_type)ctr_invalidate_ICache_kernel); |
| 49 | |
| 50 | } |
| 51 | |
| 52 | void ctr_flush_DCache(void) |
| 53 | { |
| 54 | // __asm__ volatile("svc 0x4B\n\t"); |
| 55 | svcBackdoor((ctr_callback_type)ctr_flush_DCache_kernel); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | void ctr_flush_invalidate_cache(void) |
| 60 | { |
| 61 | ctr_flush_DCache(); |
| 62 | ctr_invalidate_ICache(); |
| 63 | } |
| 64 | |
| 65 | int ctr_svchack_init(void) |
| 66 | { |
| 67 | Handle tempHandle; |
| 68 | Result res = srvGetServiceHandle(&tempHandle, "am:u"); |
| 69 | if(res == 0) |
| 70 | { |
| 71 | /* CFW */ |
| 72 | svcCloseHandle(tempHandle); |
| 73 | ninjhax_version = 0; |
| 74 | ctr_enable_all_svc(); |
| 75 | return 1; |
| 76 | } |
| 77 | else if(hbInit() == 0) |
| 78 | { |
| 79 | /* ninjhax 1.0 */ |
| 80 | ninjhax_version = 1; |
| 81 | hbExit(); |
| 82 | khaxInit(); |
| 83 | return 1; |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | /* ninjhax 2.0 */ |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | |
| 94 | void ctr_svchack_exit(void) |
| 95 | { |
| 96 | if (ninjhax_version == 1) |
| 97 | khaxExit(); |
| 98 | } |