Homebrew [Project] Injecting any app into Health and Safety?

  • Thread starter d0k3
  • Start date
  • Views 44,235
  • Replies 149
  • Likes 6

Shadowtrance

Well-Known Member
Member
Joined
May 9, 2014
Messages
2,493
Trophies
0
Location
Hervey Bay, Queensland
XP
1,807
Country
... AND IT WORKS!!!

Decrypt9 now includes two new features (four, actually, because everything is available for SysNAND & EmuNAND), one for dumping the H&S app, the other for injecting it. You need to compile from source, there's no binary release yet. And I suggest you use my last batch script to generate the inject .app (yup, .tmd / .xorpads not required!), because the .app to inject needs to be the exact same size as the original H&S app (that requirement will most likely be removed later), and I'm not sure if @Syphurith's script makes sure of that.

I will most likely refine some of how this works now. And, btw, we can easily inject to other system apps, too, but I'm unsure if that would be a good idea.

Now, although the Decrypt9 way might be the more noob friendly in the long run, we still need @Syphurith's script - because only with Syphuriths method, the .app to inject can be bigger than the original H&S app (that would never work in Decrypt9). If @Shadowtrance makes that GUI, it best includes both ways (with / without D9).


Advantages of the Decrypt9 method:
  • Faster, needs only 3 steps (dump hs.app via D9, create inject app on PC, inject hs.app via D9).
  • You only need to handle the .app file, no .tmd or .xorpads.
  • Less room for error, much more noob friendly.
  • Also, safer. Injecting files into FAT images using tools like OSFmount might lead to fragmentation, which in turn might lead to unexpected results. With Decrypt9 that will never happen, as it will leave everything untouched but the actual files space.
@Syphurith, could you add the Decrypt9 method to your nodeJS script (as an alternative)? It is the same as the other one, just with an already decrypted hs.app, no .tmd and no xorpads.
So do you have an updated batch/pack or is 0.2 that i have the latest?
Messing with 0.2 now, it's throwing some errors at me but still generates the hs.app file at the end....strange. Nevermind that...just dumped a clean file straight from sysnand and no errors...
And how do we handle the n3ds version having 2 files? Just ignore the 2nd one like i did when i did it manually earlier i guess?
 
Last edited by Shadowtrance,

d0k3

3DS Homebrew Legend
OP
Member
Joined
Dec 3, 2004
Messages
2,786
Trophies
1
XP
3,896
Country
Germany
So do you have an updated batch/pack or is 0.2 that i have the latest?
Messing with 0.2 now, it's throwing some errors at me but still generates the hs.app file at the end....strange. Nevermind that...just dumped a clean file straight from sysnand and no errors...
And how do we handle the n3ds version having 2 files? Just ignore the 2nd one like i did when i did it manually earlier i guess?
Just ignore the second one. The only one you really need to use is the one dumped by Decrypt9.
 

Shadowtrance

Well-Known Member
Member
Joined
May 9, 2014
Messages
2,493
Trophies
0
Location
Hervey Bay, Queensland
XP
1,807
Country
Just ignore the second one. The only one you really need to use is the one dumped by Decrypt9.
Yeah i figured as much. :)

And i just tried injecting one i just created with devmenu as the cia (420KB), and the resulting file is 4KB larger than the original and i get app size mismatch...hmm
Original hs.app - 1016KB, generated hs.app - 1020KB
I only commented out the fixtmd line in the batch as it isn't needed, everything else is untouched.
 
Last edited by Shadowtrance,

d0k3

3DS Homebrew Legend
OP
Member
Joined
Dec 3, 2004
Messages
2,786
Trophies
1
XP
3,896
Country
Germany
Use the one attached here. This has some rather small changes, but I'm pretty sure this will fix it. I'll also at least try to enable injecting smaller .app files.
 

Attachments

  • UniversalInjectGen_v0.2.1.zip
    429.6 KB · Views: 340
  • Like
Reactions: Syphurith

Shadowtrance

Well-Known Member
Member
Joined
May 9, 2014
Messages
2,493
Trophies
0
Location
Hervey Bay, Queensland
XP
1,807
Country
Use the one attached here. This has some rather small changes, but I'm pretty sure this will fix it. I'll also at least try to enable injecting smaller .app files.
I'll check that in a minute...
Oddly enough, i just tried it again but after commenting out the fix dummy romfs size and the resulting hs.app is exactly the same size as the original.
Same with the new version, if i comment out the fix dummy romfs size AND remove the - 3952 from this line... set /A DUMMY_SIZE=(%HS_EXEFS_SIZE% + %HS_ROMFS_SIZE%) - (%HS_MOD_EXEFS_SIZE% + (16 * 1024) - 3952)
i get a resulting file the same size as the original, if i don't do those 2 things (or 1 in previous version) the resulting file is larger than the original.
And i now have devmenu injected into emunand H&S. haha :D
 
Last edited by Shadowtrance,
  • Like
Reactions: Syphurith

Syphurith

Beginner
Member
Joined
Mar 8, 2013
Messages
641
Trophies
0
Location
Xi'an, Shaanxi Province
XP
364
Country
Switzerland
Yup, that's what Decrypt9 does :). It handles the complete encryption stuff so that users don't have to care.
Quite good news. Yup. Don't need to care about those Xorpads any more! Oh wait does it do the Fix NCCH Crypto keys, Encryption, FixTmd all along?

Yup, that's exactly what I meant! As I said, the complete package may still make sense to keep, or at least offer as an alternative.
Good, I'm already on it. Since that's not hard for me, i would try to add some other arguements along.

And, @everyone, there's more testing required. Just be sure to make backups of your (Emu-)NAND. I already tried this on EmuNAND (ReiNAND) with FBI 1.4.15. Tests with different homebrew apps are still required. Also, testing it on SysNAND (only for those with hardmods until properly tested!) would be a good thing.
Hope this could be confirmed stable soon.. Oh not SOON(TM). (lol)

Oh finally the support should be done. See here: http://pan.baidu.com/s/1hqEsBWw

Since it now accepts Arguement you could edit the DO.bat to let it automatically use the arguements, or use a console.
Note: What in {} is optional.
node DO {A/H/9 {<MyHS> {<MyXor> {<MyCIA.cia>}}}}
node:nodejs executable. If another name just replace this
DO:the script is Do.js. If you renamed it, change this.
A/H/9:Just choose one. A: All steps(Normal), H: Show Help Only, 9: Decrypt9 Mode.
Note: Those arguements can be stubbed using '#' if don't want to use.
MyHS:Yes you can change the folder of H&S original files. This would clear ori folder.
MyXor: Yes you can tell it where to copy the xorpads from.
MyCIA.cia: To inject this CIA. if not the name, change it. This would clear Cia folder.
Well I'm too lazy to use/implement a real arguement selection.
So, for example i wanna use Xorpads as Xor, Dev.cia as CIA and do all those things, without changing the ori folder:
node DO A # Xorpads Dev.cia
 
Last edited by Syphurith,
  • Like
Reactions: d0k3

d0k3

3DS Homebrew Legend
OP
Member
Joined
Dec 3, 2004
Messages
2,786
Trophies
1
XP
3,896
Country
Germany
I'll check that in a minute...
Oddly enough, i just tried it again but after commenting out the fix dummy romfs size and the resulting hs.app is exactly the same size as the original.
Same with the new version, if i comment out the fix dummy romfs size AND remove the - 3952 from this line... set /A DUMMY_SIZE=(%HS_EXEFS_SIZE% + %HS_ROMFS_SIZE%) - (%HS_MOD_EXEFS_SIZE% + (16 * 1024) - 3952)
i get a resulting file the same size as the original, if i don't do those 2 things (or 1 in previous version) the resulting file is larger than the original.
And i now have devmenu injected into emunand H&S. haha :D
If you're feeling adventurous, you can also disable the size check in InjectHealthAndSafety(). Just don't inject anything bigger than the original H&S app. I'd also like to go further and try and see what happens if we also replace the banner and icon in H&S.

EDIT: The fix you proposed doesn't work in all cases. I already tried it.
 
Last edited by d0k3,

Shadowtrance

Well-Known Member
Member
Joined
May 9, 2014
Messages
2,493
Trophies
0
Location
Hervey Bay, Queensland
XP
1,807
Country
If you're feeling adventurous, you can also disable the size check in InjectHealthAndSafety(). Just don't inject anything bigger than the original H&S app. I'd also like to go further and try and see what happens if we also replace the banner and icon in H&S,
Well as it stands now (at least for me), the size of the original main app file is 1016KB (00000002.app), i assume that's the main executable anyway, the other one 00000003.app is 1884KB i assume is the banner or something (i have no idea what), but if it isn't there the banner doesn't show up and it won't run. Old3ds doesn't have the 2nd file as far as i can see either (i extracted every regions cia of H&S earlier for both old and new 3ds.)
 
Last edited by Shadowtrance,
  • Like
Reactions: Syphurith

d0k3

3DS Homebrew Legend
OP
Member
Joined
Dec 3, 2004
Messages
2,786
Trophies
1
XP
3,896
Country
Germany
Well as it stands now (at least for me), the size of the original main app file is 1016KB (00000002.app), i assume that's the main executable anyway, the other one 00000003.app is 1884KB i assume is the banner or something (i have no idea what), but if it isn't there the banner doesn't show up and it won't run.
No, the banner and icon is actually inside the exefs of 00000002.app. go.bat, at the moment, only replaces the .code inside the exefs and leaves everything else vanilla H&S. And no idea what that second .app is. In theory it is a e-manual, but an e-manual for something that's considered a documentation itself? :?
 
Last edited by d0k3,

Syphurith

Beginner
Member
Joined
Mar 8, 2013
Messages
641
Trophies
0
Location
Xi'an, Shaanxi Province
XP
364
Country
Switzerland
Well as it stands now (at least for me), the size of the original main app file is 1016KB (00000002.app), i assume that's the main executable anyway, the other one 00000003.app is 1884KB i assume is the banner or something (i have no idea what), but if it isn't there the banner doesn't show up and it won't run. Old3ds doesn't have the 2nd file as far as i can see either (i extracted every regions cia of H&S earlier for both old and new 3ds.)
00000003.app may be a manual. Try ctrtool -i -y and view its content type.
Well if you rebuild a TMD with only one content.. Not too hard if you like to view the TMD page on 3dbrew.
 

Shadowtrance

Well-Known Member
Member
Joined
May 9, 2014
Messages
2,493
Trophies
0
Location
Hervey Bay, Queensland
XP
1,807
Country
No, the banner and icon is actually inside the exefs of 00000002.app. go.bat, at the moment, only replaces the .code inside the exefs and leaves everything else vanilla H&S.
hmm well what the hell is the other one then? I figured the banner etc would be in the 02 but who knows, nintendo does some strange shit sometimes. haha

--------------------- MERGED ---------------------------

00000003.app may be a manual. Try ctrtool -i -y and view its content type.
Well if you rebuild a TMD with only one content.. Not too hard if you like to view the TMD page on 3dbrew.
Ahh true...a manual for a err manual...wtf nintendo!

--------------------- MERGED ---------------------------

Yeah just checked it with ctrtool...
Simple Content
Manual

GOOD JOB NINTENDO! :glare:
 
  • Like
Reactions: Syphurith

Syphurith

Beginner
Member
Joined
Mar 8, 2013
Messages
641
Trophies
0
Location
Xi'an, Shaanxi Province
XP
364
Country
Switzerland
hmm well what the hell is the other one then? I figured the banner etc would be in the 02 but who knows, nintendo does some strange shit sometimes. haha
--------------------- MERGED ---------------------------
Ahh true...a manual for a err manual...wtf nintendo!
Yes you found that. Manual for Manual, Menu of Menu!
If you don't like it, you can edit the TMD following the TMD page on 3dbrew, and fixtmd, replace it.
Then try delete the 00000003.app, you are free!
 

d0k3

3DS Homebrew Legend
OP
Member
Joined
Dec 3, 2004
Messages
2,786
Trophies
1
XP
3,896
Country
Germany
Quite good news. Yup. Don't need to care about those Xorpads any more! Oh wait does it do the Fix NCCH Crypto keys, Encryption, FixTmd all along?

Good, I'm already on it. Since that's not hard for me, i would try to add some other arguements along.

Hope this could be confirmed stable soon.. Oh not SOON(TM). (lol)

Oh finally the support should be done. See here: http://pan.baidu.com/s/1hqEsBWw

Since it now accepts Arguement you could edit the DO.bat to let it automatically use the arguements, or use a console.
Note: What in {} is optional.
node DO {A/H/9 {<MyHS> {<MyXor> {<MyCIA.cia>}}}}
node:nodejs executable. If another name just replace this
DO:the script is Do.js. If you renamed it, change this.
A/H/9:Just choose one. A: All steps(Normal), H: Show Help Only, 9: Decrypt9 Mode.
Note: Those arguements can be stubbed using '#' if don't want to use.
MyHS:Yes you can change the folder of H&S original files. This would clear ori folder.
MyXor: Yes you can tell it where to copy the xorpads from.
MyCIA.cia: To inject this CIA. if not the name, change it. This would clear Cia folder.
Well I'm too lazy to use/implement a real arguement selection.
So, for example i wanna use Xorpads as Xor, Dev.cia as CIA and do all those things, without changing the ori folder:
node DO A # Xorpads Dev.cia
If everything can be done via arguments now (and I'm sure, we'll have some other ideas for arguments later, fe. specificy H&S input file/folder / inject CIA, ...), it should be possible to base a GUI around the script alone, right? Can the script be included in a GUI in such a way that users don't have to download any additional stuff (ie. pack the nodejs and everything else with it)?
 

Shadowtrance

Well-Known Member
Member
Joined
May 9, 2014
Messages
2,493
Trophies
0
Location
Hervey Bay, Queensland
XP
1,807
Country
If everything can be done via arguments now (and I'm sure, we'll have some other ideas for arguments later, fe. specificy H&S input file/folder / inject CIA, ...), it should be possible to base a GUI around the script alone, right? Can the script be included in a GUI in such a way that users don't have to download any additional stuff (ie. pack the nodejs and everything else with it)?
Don't see why not, you can pack just about any file/s in as resources into one exe and have them write out to the folder when the program is loaded. :)

For example...i have 3dstool, ctrtool, MergeExheader set as resources and copy them out like so when the program is loaded...
Then just call CopyExes(); on program load. :)

Code:
string[] path = { "cia", "tools", "orig", "out", "work" }; // 0 - 4
string[] tools = { "3dstool.exe", "ctrtool.exe", "MergeExHeader.exe" }; // 0 - 4

//Copy all our tools from embedded resources to tools folder if they don't already exist.
public void CopyExes()
{
    //3dstool.exe
    if (!File.Exists(path[1] + "\\" + tools[0]))
    {
        File.WriteAllBytes(path[1] + "\\" + tools[0], Properties.Resources._3dstool);
    }

    //ctrtool.exe
    if (!File.Exists(path[1] + "\\" + tools[1]))
    {
        File.WriteAllBytes(path[1] + "\\" + tools[1], Properties.Resources.ctrtool);
    }

    //MergeExheader.exe
    if (!File.Exists(path[1] + "\\" + tools[2]))
    {
        File.WriteAllBytes(path[1] + "\\" + tools[2], Properties.Resources.MergeExHeader);
    }
}
 
Last edited by Shadowtrance,

d0k3

3DS Homebrew Legend
OP
Member
Joined
Dec 3, 2004
Messages
2,786
Trophies
1
XP
3,896
Country
Germany
Alright, another new version of my script is attached. That's most likely the last one - @Syphurith has this covered more elegantly (although I personally don't like having to download additional software). Also, this includes code by Syphurith, CTRtool and 3DStool.

This is how it works:
  • You'll be using the attached download and most recent Decrypt9's "Dump Health&Safety" and "Inject Health&Safety" features
  • Put hs.app (dumped via Decrypt9) plus as many homebrew CIAs as you like into the input folder
  • Run go.bat, you'll get one inject-ready .app per CIA
  • If the last one for some reason doesn't work, you may try deep-decrypting (via Decrypt9) your CIAs first.
  • To inject, rename inject-ready .app to hs.app, put it into the root of your 3DS SD card and inject via Decrypt9
One thing to note: It is possible to have a proper banner with this (instead of the ugly Health & Safety one). Will lead to a slightly larger file though, which is hopefully still below the H&S app size. For more info, check out (inside the tools\process.bat file) the comments ("rem") under "echo [+] GENERATE NEW EXEFS". Would be a great (optional) feature for a GUI ;).

EDIT: And, also, you can inject smaller .apps now without trouble. Bigger (than H&S) .apps will be automatically rejected, though.

EDIT2: I guess it's best to add that you should always generate your inject-ready .apps yourself and never take ones from other persons. There might be a version mismatch in the H&S app, leading to it not working otherwise.

EDIT3: You may also follow this on Github now, see here.
 

Attachments

  • UniversalInjectGen_v0.3.zip
    343.1 KB · Views: 690
Last edited by d0k3,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    BakerMan @ BakerMan: well then show them how to scratch it (this is a verbalase joke)