Skip to content

Commit 46464c3

Browse files
committed
Refactor a lot of the code, also make more portable by not relying on so many other dependencies
1 parent 08ef5b9 commit 46464c3

File tree

9 files changed

+122
-337
lines changed

9 files changed

+122
-337
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.ko
77
*.obj
88
*.elf
9+
*.dol
910

1011
# Linker output
1112
*.ilk

hbc/boot.dol

-293 KB
Binary file not shown.

source/globals.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// "Config"
2+
#define VERSION "v1.0.1"
3+
4+
// everything but a "config"
5+
#define AHBPROT_DISABLED (*(vu32*)0xcd800064 == 0xFFFFFFFF)

source/ios.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include <stdint.h>
2+
#include <string.h>
3+
#include <malloc.h>
4+
#include <unistd.h>
5+
6+
// libogc files
7+
#include <ogc/machine/processor.h>
8+
#include <ogc/ipc.h>
9+
#include <ogc/cache.h>
10+
11+
// Local Files
12+
#include "globals.h"
13+
14+
const uint8_t disable_ahbprot_payload[] = {
15+
0xF0, 0x00, 0xF8, 0x02, // bl #8
16+
0xE7, 0xFE, // b #0, keep looping main thread
17+
0x00, 0x00, // padding
18+
// actual disabling. it loads, and stores the value in 0xd800064 or'ed with 0x80000dfe
19+
// this gives the PPC access to the starlet's AHB devices
20+
0x4A, 0x06, // ldr r2, [DAT_00000024] = 0x0d800064
21+
0x4B, 0x07, // ldr r3, [DAT_00000028] = 0x80000dfe
22+
0x68, 0x11, // ldr r1, [r2,#0x0] => 0x0d800064
23+
0x43, 0x0B, // orrs r3, r1
24+
0x60, 0x13, // str r3, [r2,#0x0] => 0x0d800064
25+
// disable HW_MEMMIRR (0xd800060) by orring with 0x00000008
26+
0x4A, 0x06, // ldr r2, [DAT_0000002c] = 0x0d800060
27+
0x23, 0x08, // movs r3, #0x8
28+
0x68, 0x11, // ldr r1, [r2,#0x0] => 0x0d800060
29+
0x43, 0x0B, // orrs r3, r1
30+
0x60, 0x13, // str r3, [r2,#0x0] => 0x0d800060
31+
// and finish up with setting MEM_PROT_REG(0xd804202)
32+
0x4B, 0x04, // ldr r3, [DAT_00008030] = 0x0d804202
33+
0x22, 0x00, // movs r2, #0x0
34+
0x80, 0x1A, // strh r2, [r3,#0x0] => 0x0d804202
35+
0x47, 0x70, // bx lr
36+
// data used by above code
37+
0x0D, 0x80, 0x00, 0x64, // DAT_00000024
38+
0x80, 0x00, 0x0D, 0xFE, // DAT_00000028
39+
0x0D, 0x80, 0x00, 0x60, // DAT_0000002c
40+
0x0D, 0x80, 0x42, 0x02 // DAT_00000030
41+
};
42+
43+
#define DISABLE_AHBPROT_PAYLOAD_SIZE (sizeof(disable_ahbprot_payload) / sizeof(disable_ahbprot_payload[0]))
44+
45+
bool is_dolphin()
46+
{
47+
// /dev/dolphin will never exist in an official IOS
48+
s32 fd = IOS_Open("/dev/dolphin", 0);
49+
if (fd >= 0)
50+
{
51+
IOS_Close(fd);
52+
return true;
53+
}
54+
return false;
55+
}
56+
57+
// time to exploit /dev/sha!
58+
bool disable_ahbprot()
59+
{
60+
if (AHBPROT_DISABLED || is_dolphin()) {
61+
return true; // AHBPROT is already disabled, likely via launching through HBC or the user is using Dolphin. Dolphin always has it disabled however :)
62+
}
63+
64+
// We proceed to exploit /dev/sha
65+
// Good amount of this is from Priiloader but ported to C from C++ lol
66+
s32 fd = -1;
67+
ioctlv* params = NULL;
68+
69+
fd = IOS_Open("/dev/sha", 0);
70+
if (fd < 0)
71+
return false;
72+
73+
params = (ioctlv*)memalign(sizeof(ioctlv) * 4, 32);
74+
if (params == NULL)
75+
return false;
76+
77+
// Overwrite the thread 0 state with address 0 (0x80000000)
78+
memset(params, 0, sizeof(ioctlv) * 4);
79+
params[1].data = (void*)0xFFFE0028;
80+
params[1].len = 0;
81+
DCFlushRange(params, sizeof(ioctlv) *4);
82+
83+
// Set code to disable AHBPROT and stay in loop
84+
85+
memcpy((void*)0x80000000, disable_ahbprot_payload, DISABLE_AHBPROT_PAYLOAD_SIZE);
86+
DCFlushRange((void*)0x80000000, DISABLE_AHBPROT_PAYLOAD_SIZE);
87+
ICInvalidateRange((void*)0x80000000, DISABLE_AHBPROT_PAYLOAD_SIZE);
88+
89+
s32 callRet = IOS_Ioctlv(fd, 0x00, 1, 2, params);
90+
if (callRet < 0)
91+
return false;
92+
93+
// wait for it to have processed the sha init and given a timeslice to the mainthread :)
94+
usleep(50000);
95+
return true;
96+
}

source/ios.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bool disable_ahbprot();

source/libpatcher.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

source/main.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
#include <di/di.h>
88

99
// Local Files
10-
#include "libpatcher.h"
11-
#include "patches.h"
10+
#include "globals.h"
11+
#include "ios.h"
1212

1313
static void *xfb = NULL;
1414
static GXRModeObj *rmode = NULL;
1515

16+
void return_to_loader()
17+
{
18+
printf("\n\nExiting...");
19+
exit(0);
20+
}
21+
1622
void get_drive_date(char *drivedate) {
1723
DI_Init(); // Requires ahbprot access
1824
DI_DriveID id;
@@ -28,7 +34,9 @@ void get_drive_date(char *drivedate) {
2834
//---------------------------------------------------------------------------------
2935
int main(int argc, char **argv) {
3036
//---------------------------------------------------------------------------------
31-
if (!apply_patches()) {
37+
// we might need to have a bit of fun with IOS!
38+
if (!disable_ahbprot())
39+
{
3240
sleep(5);
3341
return -1;
3442
}
@@ -74,16 +82,17 @@ int main(int argc, char **argv) {
7482
// e.g. printf ("\x1b[%d;%dH", row, column );
7583
printf("\x1b[2;0H");
7684

77-
printf("Wii Disc Drive Date Checker by Aep v1.0.0\n");
85+
printf("Wii Disc Drive Date Checker by Aep %s\n", VERSION);
7886
printf("Press HOME (or START on GameCube Controller) to exit.\n\n");
7987

8088
char drivedate[11] = {0};
81-
get_drive_date(drivedate);
82-
if (drivedate[0]) {
83-
printf("Drive Date: %s\n", drivedate);
89+
get_drive_date(drivedate);
90+
91+
if (drivedate[0]) {
92+
printf("Drive Date: %s\n", drivedate);
8493
}
8594
else {
86-
printf("Could not get the drive date? Is the disc drive plugged into the Wii?");
95+
printf("Could not get the drive date! Is the disc drive plugged into the Wii?\nReport this on the GitHub issues page.");
8796
}
8897

8998
while(1) {
@@ -98,11 +107,11 @@ int main(int argc, char **argv) {
98107
u32 pressed = WPAD_ButtonsDown(0);
99108

100109
// We return to the launcher application via exit
101-
if ( pressed & WPAD_BUTTON_HOME || pressed_gc & PAD_BUTTON_START ) exit(0);
110+
if ( pressed & WPAD_BUTTON_HOME || pressed_gc & PAD_BUTTON_START ) return_to_loader();
102111

103112
// Wait for the next frame
104113
VIDEO_WaitVSync();
105114
}
106115

107116
return 0;
108-
}
117+
}

0 commit comments

Comments
 (0)