Homebrew JNUSLib - Java NUS Library

Maschell

Well-Known Member
OP
Member
Joined
Jun 14, 2008
Messages
1,090
Trophies
2
XP
4,643
Country
Germany

JNUSLib - All in one library to handle NUS content


JNUSLib is a library written in Java to handle NUS Contents (.app, tmd, tik, cert files) from different sources. It can be easily used in other Applications and
is directed to devolpers. It's based on JNUSTool, but is heavily rewritten and extented with even more features.

Features

Loading NUS Contents from different sources. Currently implemented:


For files loaded from one of the sources, the following features can be used.
  • Only on-the-fly actions. Files will be downloaded only on demand, splitted files can be handled natively, and .wux have to be decompressed!
  • Extracting all files. Needed decryption will be done on the fly.
  • Extracting single files. Needed decryption will be done on the fly.
  • Extracting the content files (.app, .h3, tmd, etc.) Useful for all sources except "local".
  • This means title downloading, and .woomy, .wux, .wud and splitted .wud extracting into the "installable" format.
  • Providing a InputStream to the decrypted data of a file.
  • Decrypt a full content (.app) file.

For WUD files, following additional operations are possible:
  • Compressing into .wux file format (from .wud and splitted .wud)
  • Verifing (comparing) two different wud images.

How to use it

At first you have to import the jnuslib.jar and the common key in the Settings class.
Code:
Settings.commonKey = Utils.StringToByteArray("12345678901234567890123456789012");
Then for each different source type, you need to use a an own NUSTitleLoader.

Code:
//REMOTE

  //Loading a title with a public ticket
  NUSTitle nusRemote = NUSTitleLoaderRemote.loadNUSTitle(0x0005000E12345678L);
 
  //Loading a title with an own ticket (key, titleid)
  Ticket ticket = Ticket.createTicket(Utils.StringToByteArray("12345678901234567890123456789012"), 0x0005000E12345678L);
  NUSTitle nusRemoteWithTicket = NUSTitleLoaderRemote.loadNUSTitle(0x0005000E12345678L);
//LOCAL

  //With ticket on disk
  NUSTitle nusLocal = NUSTitleLoaderLocal.loadNUSTitle("path-to-app-files");
 
  //Loading a title with an own ticket (key, titleid)
  Ticket ticket = Ticket.createTicket(Utils.StringToByteArray("12345678901234567890123456789012"), 0x0005000E12345678L);
  NUSTitle nusRemoteWithTicket = NUSTitleLoaderLocal.loadNUSTitle("path-to-app-files");

//Loading a .woomy file
  NUSTitle nusWoomy = NUSTitleLoaderWoomy.loadNUSTitle("testfile.woomy");
 
//WUD
  //Loading a uncompressed WUD
  NUSTitle nusWUD = NUSTitleLoaderWUD.loadNUSTitle("game.wud");
  //Loading a compressed WUD (WUX)
  NUSTitle nusWUX = NUSTitleLoaderWUD.loadNUSTitle("game.wux");
  //Loading a uncompressed splitted WUD (2gb parts)
  NUSTitle nusWUDSplitted = NUSTitleLoaderWUD.loadNUSTitle("game_part1.wud");

Once the title is loaded, you can use one of the services to extract and decrypt files.
Here are some of the operations you can do. Look at the code for the full list of methods.

Decryption:

Code:
DecryptionService decrypt = DecryptionService.getInstance(title);

//Decrypt the whole FST into a folder called "DecryptedTitle"
decrypt.decryptAllFSTEntriesTo("DecryptedTitle");

//Decrypt the code folder into a folder called "code_folder"
decrypt.decryptFSTEntriesTo("/code/.*", code_folder);

//Decrypt all .js files into a folder called "js_files"
decrypt.decryptFSTEntriesTo(".*.js", js_files);


//Decrypt all .app files into a folder called "decrypted_contents"
decrypt.decryptAllPlainContents("decrypted_contents");


//Use decrypting inputstream. Data will be only loaded/decrypted on demand.

//Display the app.xml as hey dump
FSTEntry appXMLEntry = title.getFSTEntryByFullPath("code/app.xml");
decrypt.getDecryptedOutputAsInputStream(appXMLEntry);
//Lets just print the app.xml as hex data
int BUFFER_SIZE = 0x40;
byte[] buffer = new byte[BUFFER_SIZE];
int i = 0; 
while(in.read(buffer) > 0){
  System.out.println(String.format("0x%04X: ", (i++ * BUFFER_SIZE)) + Utils.ByteArrayToString(buffer));
}
in.close();
[...]

Extraction:
Code:
//Get the Service for the NUSTitle
ExtractionService extract = ExtractionService.getInstance(title);

//Saving all .app/.h3/tmd/tik/cert files into the folder "encryptedFiles"
extract.extractAll("encryptedFiles");

//Save all .h3 files into "contentHashes"
extract.extractAllEncrpytedContentFileHashes("contentHashes");

//Save all -.app files into "contents"
extract.extractAllEncryptedContentFilesWithoutHashesTo("contents");

//Save tmd, cert and ticket
extract.extractTMDTo(output);
extract.extractTickeTo(output);
extract.extractCertTo(output);

[...]

Example for compressing and verifing into .wux files.

Code:
  WUDImage imageUncompressed = new WUDImage(new File("game_part1.wud")); //Splitted and not splitted .wud possible here
 
  WUDService.compressWUDToWUX(imageUncompressed, "compressedImage","game.wux");
 
  WUDImage imageCompressed = new WUDImage(new File("compressedImage" + File.separator + "game.wux"));
 
  //Verify compression
  WUDService.compareWUDImage(imageUncompressed, imageCompressed);

Cleanup:
Call the method cleanup() for a NUSTitle to cleanup/close all opened ressources.

Sources

https://github.com/Maschell/JNUSLib
Credits

Maschell

Thanks to:
Crediar for CDecrypt (https://github.com/crediar/cdecrypt)
All people who have contributed to vgmtoolbox (https://sourceforge.net/projects/vgmtoolbox/)
Exzap for the .wux file format (https://gbatemp.net/threads/wii-u-image-wud-compression-tool.397901/)
FIX94 for wudump (https://gbatemp.net/threads/wudump-dump-raw-images-from-a-wiiu-game-disc.451736/)
The creators of lombok for lombok https://projectlombok.org/index.html
 
Last edited by Maschell,

Maschell

Well-Known Member
OP
Member
Joined
Jun 14, 2008
Messages
1,090
Trophies
2
XP
4,643
Country
Germany
Thats the current state of the library I'm currently working on.

I hope everything works as expected, but its definitally still in developement and just a library.

My plan is to make JNUSTool 1.0 based on this lib (Does anyone want to help me with the GUI :>)

I hope some people/devs can actually test it,find bugs, give feedback and contribute!

(I didn't check all features in all possible scenarios/sources/operationen, so probably this still has bug!)
 
Last edited by Maschell,

datahoarder

Organized.
Member
Joined
Jul 7, 2007
Messages
567
Trophies
1
XP
749
Country
United States
@Maschell

I know you've mentioned going JNUSTool 1.0 with this.
I had originally used JNUSTool to download the encrypted app files -dlEncrypted.
Now I have a couple of games that are encrypted, with their .tik files in their respective tmp_[ID] folders.
With FAT32 coming up, I'm going to need to decrypt all of these versus letting the Wii U/wupinstaller do it.

When I run:
java -jar JNUSTool.jar 00050000101C5d00
java -jar JNUSTool.jar 00050000101B4600
Unfortunately I have to wait to select the root and click download and repeat for /each/ title.
I'm looking to batch decrypt these encrypted game files that I've already downloaded without interaction,
provided they have their appropriate .tik files in place. Will this be in your JNUSTool 1.0?

or can I go ahead and request an addition [option] to:
java -jar JNUSTool.jar 00050000101B4600 -silent
Which would auto-select the root of each game and extract them without me clicking root and download and repeating?
 

TheSeaofTesseract

Member
Newcomer
Joined
Jun 21, 2018
Messages
10
Trophies
0
Age
23
XP
62
Country
United States
Hello.

So, I flat out have no idea how to use this, but I do think I have to use it to use JNUSTool or JWUDTool, as both seem to require files from JNUSLib and neither seems to work for my purposes when I use them exactly as instructed. That said, I have no idea how to "import the jnuslib.jar and the common key in the Settings class" (nor do I know how else to say that phrase), so I cannot use it until I know how to do so, it seems (although I am pretty sure I have the correct jnuslib.jar from github and somewhat sure I have the correct common key, I'll post the file I got it from). And it's not so much the instructions, but rather that I don't have any idea what I'm doing. May I have some assistance? I can give more details if needed, of course.
 

BullyWiiPlaza

Nintendo Hacking <3
Member
Joined
Aug 2, 2014
Messages
1,932
Trophies
0
XP
2,467
Country
Germany
Hello.

So, I flat out have no idea how to use this, but I do think I have to use it to use JNUSTool or JWUDTool, as both seem to require files from JNUSLib and neither seems to work for my purposes when I use them exactly as instructed. That said, I have no idea how to "import the jnuslib.jar and the common key in the Settings class" (nor do I know how else to say that phrase), so I cannot use it until I know how to do so, it seems (although I am pretty sure I have the correct jnuslib.jar from github and somewhat sure I have the correct common key, I'll post the file I got it from). And it's not so much the instructions, but rather that I don't have any idea what I'm doing. May I have some assistance? I can give more details if needed, of course.
This is for Java programmers to add support to new applications and you're most likely just a "user" so you can't do that. JNUSTool and JWUDTool are what you should use, as @nexusmtz already said.
 
Last edited by BullyWiiPlaza,

TheSeaofTesseract

Member
Newcomer
Joined
Jun 21, 2018
Messages
10
Trophies
0
Age
23
XP
62
Country
United States
Ah ok. I’ll go back to one of those then. Thanks to you both.

Though I am kind of curious about something. In the error messages the command prompt was giving me, I saw files that I also found while looking through JNUSLib. Are those integrated into JNUSTool and JWUDTool?
 
Last edited by TheSeaofTesseract,

nexusmtz

Well-Known Member
Member
Joined
Feb 17, 2016
Messages
1,386
Trophies
0
XP
1,425
Country
United States
Are those integrated into JNUSTool and JWUDTool?
A developer could write a library first and then write utilities that call that library, but I think it's more common that a utility gets written, then the reusable parts are extracted, cleaned up, and extended to make a library. Then that library gets used in other utilities. So, yes, you'll see commonality within the three.
 
  • Like
Reactions: BullyWiiPlaza

jenchen12

New Member
Newbie
Joined
Dec 2, 2019
Messages
4
Trophies
0
Age
33
XP
54
Country
Ukraine
Hello. I've tried to use the lib in my project, and faced with the issue when title.tik and title.cert are not found on the server, does solution exist to solve the issue? Maybe generate these files somehow or find them in another source?
 

jeannotte

Well-Known Member
Member
Joined
Jun 15, 2016
Messages
4,517
Trophies
1
Age
53
XP
4,894
Country
France

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: I hate myself