Hacking [WIP] Wii U Development Tutorial

What do you think?

  • Nah, it's easy enough to learn as-is.

    Votes: 0 0.0%
  • Nah, people don't really want to learn.

    Votes: 0 0.0%

  • Total voters
    28
  • Poll closed .

oumoumad

Well-Known Member
Member
Joined
Apr 20, 2015
Messages
798
Trophies
0
Age
31
XP
890
Country
France
Dimok's code is awesome but I can't make heads or tails of it. Sorry.

If you have a hard time understanding his work, then this is why it would be a good idea to contact him, I believe he won't have a problem writing paragraphs himself.
Many developers (dibas, onion knight, Maschell, nighty....) picked up with his work easily and it's quiet efficient . It can only be misleading if you direct people to a less efficient way for Wii U development. Why not follow the best example when it's already established? (Loadiine GX2, DDD, homebrew launcher, FTPU...) he even gave a good example on working with GX2. But anyway, this is your doc, you decide what you put in it. I just find it sad how many people could miss a batter way of making applications following this.
 
  • Like
Reactions: fukseliten

QuarkTheAwesome

🦊
OP
Member
Joined
Apr 19, 2015
Messages
1,023
Trophies
1
Location
Stuck in the PowerPC
Website
heyquark.com
XP
3,909
Country
Australia
Why not follow the best example when it's already established?

I've been thinking about this, and you might have a point. Is it best to teach based on programs designed for a limited environment, especially considering the environment (hopefully) won't be limited forever?
If we can somehow teach in such a way that allows you to understand the more complex code of projects like Loadiine, why wouldn't you? Is there truly a difference between the projects (other than the experience of the writer?)
They're a lot of questions, and I feel like the answers may be dictating whether I continue this project. Personally I think that (other than complexity) there isn't a huge difference between the libwiiu examples and the projects mentioned on a conceptual, teaching level. However, I'm not really sure of this, I'm just sort of leaning in that direction. If I can get some input on this from people (especially @dimok) that'd be awesome.
 
  • Like
Reactions: oumoumad

dimok

Well-Known Member
Member
Joined
Jan 11, 2009
Messages
728
Trophies
3
XP
2,635
Country
United States
Hey,

I've read several parts of your documentation to give you a better answer.

What is good is that you point out in "Chapter 4: Browserhax, Kernel, and IOSU" that this is not the "normal" coding and that you get a way cleaner environment if you have an entry point at the beginning of an application. Unfortunately it requires kernel exploit to have the access to do that kind of entry point at the moment.

But there are quite a few points that are gonna misslead people on how to code for WiiU as those are not common ways to do it. Those are mostly true only for the browser exploit environment.

You chapter "The Mystery of the Missing Standard Libraries" is wrong. You do have those and you can use them. You just dont do it because you dont link them. Linking that code actually increases the binary size by a lot. That is one reason why not many use those. Also some parts require a proper definition of a malloc, memalign and free function and those require a re-implementation with a wrapper inside your code as those were written for the Wii.
My applications do actually use the C and C++ STL libaries. They are all compiled or included as headers in devkitPPC (some C++11 stuff are missing but thats because devkitPPC is old already and no one does update it anymore). Stuff like stdout and stderr have to be adjusted to something different like on screen console manually in your program but even that is quite easily doable and you can use printf() for example to output text to the on screen console or to a network connection. You just need to know hot to work with devoptabs on devkitPPC to make that possible. Thats what I did for the FS access to actually be able to use FILE* in C or std::fstream in C++ to access the sd card. Would work similar for console but on devoptab STDERR and STDOUT with less functions required than on FS (you could also see SNES9xGX for an example).

Another point which is also not "normal" programming are all those function pointers from the RPLs. We only use them out of convience because they give us the hardware access we need. Nintendo made those great dynamic libaries which allow you to use their code very easily for your purpose. That is also the reason why we don't have to rewrite all those IOS ioctlv accesses and other implementations of hardware accesses (through IOS or direct hw registers). It's way simpler to use the ready to use code. You have the symbols of the functions and even a function to find the symbols. Its all served on a silver plate and cant get easier :).
So that is the only reason we need those function pointers. We need them for hardware access (even just console output on screen which accesses the graphic hardware in a way). In normal applications you would not code with function pointers (mostly only for callbacks). They need 3-4 instructions where you would usually only need 1 instruction. Functions like __os_snprintf are actually not needed and the normal snprintf from libgcc can be used (C libraries can be used as described above).

The most missleading parts to "coding for WiiU" are those stuff:

These two assembly lines of code are something way out of the ordinary programming most people do. They forcefully change the stack pointer to a different position. This is required on the browser exploit because it has no clean stack on entrance and that enviroment does not have access to many memory regions. So it is set to some region where it has access to overwritting some (luckily) unused regions. To be honest I cant even tell how much stack we have there as I never made looked it up or made tests.

asm(
"lis %r1, 0x1ab5 ;"
"ori %r1, %r1, 0xd138 ;"
);


Those lines signal the foreground application that you want to shut it down:
IM_SetDeviceState(fd, mem, 3, 0, 0);
IM_Close(fd);
OSFreeToSystem(mem);


The application then starts to stops its running threads on core0 and core2. Core1 threads are most likely not shutdown as the exploit application is occupying it. Only threads whith higher priority on core1 could theoretically shutdown if the scheduler switches context to them (which it should).

In normal application you would not need that.

Same goes for these lines:
OSScreenSetBufferEx(0, (void *)0xF4000000);
OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);

You assign the screen buffer hardcoded MEM1 addresses. Of course this will cause crashes if GX2 for is still running on the browser which is using those MEM1 addresses. Thats why you shut down the running threads with the above command.
Normally you would cleanly allocate that memory marking it as "occupied".

Another point which I didnt find in your documentation is that usually you dont have any kind of static or global variables in the browser exploit code. This results from the fact that it just doesnt copy .data section with the exploit as it doesnt know where to. You could actually achieve it with loading the .data and .bss sections after the exploit is running but thats also nasty hack like the stack pointer change too. On normal applications you just can use those.

Well those are main points that came into my mind when I read your doc.

To tell you the truth, writing a WiiU application isn't much different than writting any other standard C/C++ application for a linux system. You just have to use different functions to access hardware or communication with the I/O processor but a lot is the same. The parts where it is not the same because you access some specific memory region or doing changes to stack is where hacking starts and homebrew "application" ends.
 

QuarkTheAwesome

🦊
OP
Member
Joined
Apr 19, 2015
Messages
1,023
Trophies
1
Location
Stuck in the PowerPC
Website
heyquark.com
XP
3,909
Country
Australia
Hey,

I've read several parts of your documentation to give you a better answer.

What is good is that you point out in "Chapter 4: Browserhax, Kernel, and IOSU" that this is not the "normal" coding and that you get a way cleaner environment if you have an entry point at the beginning of an application. Unfortunately it requires kernel exploit to have the access to do that kind of entry point at the moment.

But there are quite a few points that are gonna misslead people on how to code for WiiU as those are not common ways to do it. Those are mostly true only for the browser exploit environment.

You chapter "The Mystery of the Missing Standard Libraries" is wrong. You do have those and you can use them. You just dont do it because you dont link them. Linking that code actually increases the binary size by a lot. That is one reason why not many use those. Also some parts require a proper definition of a malloc, memalign and free function and those require a re-implementation with a wrapper inside your code as those were written for the Wii.
My applications do actually use the C and C++ STL libaries. They are all compiled or included as headers in devkitPPC (some C++11 stuff are missing but thats because devkitPPC is old already and no one does update it anymore). Stuff like stdout and stderr have to be adjusted to something different like on screen console manually in your program but even that is quite easily doable and you can use printf() for example to output text to the on screen console or to a network connection. You just need to know hot to work with devoptabs on devkitPPC to make that possible. Thats what I did for the FS access to actually be able to use FILE* in C or std::fstream in C++ to access the sd card. Would work similar for console but on devoptab STDERR and STDOUT with less functions required than on FS (you could also see SNES9xGX for an example).

Another point which is also not "normal" programming are all those function pointers from the RPLs. We only use them out of convience because they give us the hardware access we need. Nintendo made those great dynamic libaries which allow you to use their code very easily for your purpose. That is also the reason why we don't have to rewrite all those IOS ioctlv accesses and other implementations of hardware accesses (through IOS or direct hw registers). It's way simpler to use the ready to use code. You have the symbols of the functions and even a function to find the symbols. Its all served on a silver plate and cant get easier :).
So that is the only reason we need those function pointers. We need them for hardware access (even just console output on screen which accesses the graphic hardware in a way). In normal applications you would not code with function pointers (mostly only for callbacks). They need 3-4 instructions where you would usually only need 1 instruction. Functions like __os_snprintf are actually not needed and the normal snprintf from libgcc can be used (C libraries can be used as described above).

The most missleading parts to "coding for WiiU" are those stuff:

These two assembly lines of code are something way out of the ordinary programming most people do. They forcefully change the stack pointer to a different position. This is required on the browser exploit because it has no clean stack on entrance and that enviroment does not have access to many memory regions. So it is set to some region where it has access to overwritting some (luckily) unused regions. To be honest I cant even tell how much stack we have there as I never made looked it up or made tests.

asm(
"lis %r1, 0x1ab5 ;"
"ori %r1, %r1, 0xd138 ;"
);


Those lines signal the foreground application that you want to shut it down:
IM_SetDeviceState(fd, mem, 3, 0, 0);
IM_Close(fd);
OSFreeToSystem(mem);


The application then starts to stops its running threads on core0 and core2. Core1 threads are most likely not shutdown as the exploit application is occupying it. Only threads whith higher priority on core1 could theoretically shutdown if the scheduler switches context to them (which it should).

In normal application you would not need that.

Same goes for these lines:
OSScreenSetBufferEx(0, (void *)0xF4000000);
OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);

You assign the screen buffer hardcoded MEM1 addresses. Of course this will cause crashes if GX2 for is still running on the browser which is using those MEM1 addresses. Thats why you shut down the running threads with the above command.
Normally you would cleanly allocate that memory marking it as "occupied".

Another point which I didnt find in your documentation is that usually you dont have any kind of static or global variables in the browser exploit code. This results from the fact that it just doesnt copy .data section with the exploit as it doesnt know where to. You could actually achieve it with loading the .data and .bss sections after the exploit is running but thats also nasty hack like the stack pointer change too. On normal applications you just can use those.

Well those are main points that came into my mind when I read your doc.

To tell you the truth, writing a WiiU application isn't much different than writting any other standard C/C++ application for a linux system. You just have to use different functions to access hardware or communication with the I/O processor but a lot is the same. The parts where it is not the same because you access some specific memory region or doing changes to stack is where hacking starts and homebrew "application" ends.

Would you recommend changing the current doc to point out these abnormalities or holding out for the kernel exploit and writing something like this for that environment? I'm leaning towards waiting...
Thanks for the awesome write-up by the way. I had no idea you could port the standard libraries!
 

dimok

Well-Known Member
Member
Joined
Jan 11, 2009
Messages
728
Trophies
3
XP
2,635
Country
United States
Would you recommend changing the current doc to point out these abnormalities or holding out for the kernel exploit and writing something like this for that environment? I'm leaning towards waiting...
Thanks for the awesome write-up by the way. I had no idea you could port the standard libraries!
Yeah I would recommend to wait till you are able to actually use that environment. Especially since you dont have experience with a clean environment on the WiiU yet.

You could also just message MN1 and ask him if he would share the kexploit with you so you can actually do some work and tests and maybe even write some homebrews. You would be able to do some good work with it for all users < 5.5.0 and future 5.5.x kexploit users and in the process you would learn the actual things that matter in the WiiU application coding and could write about it. Things like for example how to setup a console (yep you have that already done), setup and use the GX2 engine, all the WPAD variants or AX. A step by step documentation how to properly use those things in code is actually what would be really usefull and not a coding tutorial. There are tons of coding tutorials on the internet which do apply for WiiU as well in most of the points.
 
  • Like
Reactions: oumoumad

QuarkTheAwesome

🦊
OP
Member
Joined
Apr 19, 2015
Messages
1,023
Trophies
1
Location
Stuck in the PowerPC
Website
heyquark.com
XP
3,909
Country
Australia
Yeah I would recommend to wait till you are able to actually use that environment. Especially since you dont have experience with a clean environment on the WiiU yet.

You could also just message MN1 and ask him if he would share the kexploit with you so you can actually do some work and tests and maybe even write some homebrews. You would be able to do some good work with it for all users < 5.5.0 and future 5.5.x kexploit users and in the process you would learn the actual things that matter in the WiiU application coding and could write about it. Things like for example how to setup a console (yep you have that already done), setup and use the GX2 engine, all the WPAD variants or AX. A step by step documentation how to properly use those things in code is actually what would be really usefull and not a coding tutorial. There are tons of coding tutorials on the internet which do apply for WiiU as well in most of the points.

Yeah, you're probably right. I still think there's value in explaining the basics,however.

I'm semi-officially putting this on hold until further notice (me getting used to the kexploit). Sorry, but it's time for the waiting game.

As for the kernel exploit, while I'd like it (I still think there's potential in userspace, but I've conceded that there's not much point using it at this time), I've heard MN1 is pretty busy lately and isn't responding to PM's or anything. He also probably doesn't know I exist ;D

I suppose I could mindlessly tag @NWPlayer123 and see if something comes of that :3
 
  • Like
Reactions: KiiWii

vgmoose

Well-Known Member
Member
Joined
Jan 31, 2016
Messages
360
Trophies
1
Website
github.com
XP
3,065
Country
United States
Hey, so I think a lot of this is still relevant, at least for getting started.

These would be cool additional topics:
- First HBL App
- Running elfs via wiiload
- Logging via a socket
- Intro to GX2-based apps (although I still believe OSScreen based ones have value and are less complicated)

Maybe it's also worth switching from a google doc to another format (such as Wiiubrew.org wiki pages?) to make navigating a bit easier.
 

QuarkTheAwesome

🦊
OP
Member
Joined
Apr 19, 2015
Messages
1,023
Trophies
1
Location
Stuck in the PowerPC
Website
heyquark.com
XP
3,909
Country
Australia
Hey, so I think a lot of this is still relevant, at least for getting started.

These would be cool additional topics:
- First HBL App
- Running elfs via wiiload
- Logging via a socket
- Intro to GX2-based apps (although I still believe OSScreen based ones have value and are less complicated)

Maybe it's also worth switching from a google doc to another format (such as Wiiubrew.org wiki pages?) to make navigating a bit easier.
I might start working on this again soon, but it'll need basically a complete rewrite. WiiUBrew might be a good idea.
 

vgmoose

Well-Known Member
Member
Joined
Jan 31, 2016
Messages
360
Trophies
1
Website
github.com
XP
3,065
Country
United States
Another suggestion I have for the format would be a github repo with code examples and a wiki (similar to this: https://github.com/Plailect/Guide/wiki/Part-1-(Homebrew) ). This could also allow you to add inline code examples easier, and add other collaborators on github to help contribute code+documentation.

And I don't think at all that it needs to be completely rewritten! The more thorough a guide the better, even if some of the mp4 hack instructions can be updated.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: @Psionic Roshambo, I always see this dude's shorts, he sounds pretty annoying.