Skip to content

Commit

Permalink
Removed unnecessary code and added required files.
Browse files Browse the repository at this point in the history
Added banner files, .bin file and .3dsx file
  • Loading branch information
Rohul1997 committed Mar 1, 2016
1 parent 5fbe504 commit ee770a9
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 489 deletions.
Binary file added Cia_shortcut/Gateway_cia.bin
Binary file not shown.
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ SOURCES := source
DATA := data
INCLUDES := include

VERSION := v1.1
VERSION := v1.2

APP_TITLE := hblauncher_loader $(VERSION)
APP_DESCRIPTION := This boots the hblauncher-payload.
APP_AUTHOR := yellows8
APP_TITLE := Gateway CIA $(VERSION)
APP_DESCRIPTION := This is a shortcut to launch Gateway
APP_AUTHOR := Gateway

#---------------------------------------------------------------------------------
# options for code generation
Expand Down Expand Up @@ -135,7 +135,7 @@ $(BUILD):
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(OUTPUT).cia Resources/hblauncher_loader.icn Resources/hblauncher_loader.bnr
@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(OUTPUT).cia Resources/Gateway_cia.icn Resources/Gateway_cia.bnr


#---------------------------------------------------------------------------------
Expand All @@ -154,15 +154,15 @@ endif

$(OUTPUT).elf : $(OFILES)

../Resources/hblauncher_loader.icn : $(APP_ICON)
@bannertool makesmdh -i "$(APP_ICON)" -o "$@" -s "$(APP_TITLE)" -l "$(APP_TITLE)" -p "$(APP_AUTHOR)"
../Resources/Gateway_cia.icn : $(APP_ICON)
../bannertool makesmdh -i "$(APP_ICON)" -o "$@" -s "$(APP_TITLE)" -l "$(APP_TITLE)" -p "$(APP_AUTHOR)"

../Resources/hblauncher_loader.bnr : ../banner.png
@bannertool makebanner -i "$<" -ca ../Resources/hblauncher_loader.cwav -o "$@"
../Resources/Gateway_cia.bnr :
../bannertool makebanner -i "$<" -ca ../Resources/Gateway_cia.cwav -o "$@" -ci ../Resources/Gateway_cia.cgfx -o "$@"

$(OUTPUT).cia : $(OUTPUT).elf ../Resources/hblauncher_loader.icn ../Resources/hblauncher_loader.bnr
@makerom -f cia -o "$@" -elf $(OUTPUT).elf -rsf ../Resources/hblauncher_loader.rsf -icon ../Resources/hblauncher_loader.icn -banner ../Resources/hblauncher_loader.bnr -exefslogo -ver 1040
@echo "built ... hblauncher_loader.cia"
$(OUTPUT).cia : $(OUTPUT).elf ../Resources/Gateway_cia.icn ../Resources/Gateway_cia.bnr
../makerom -f cia -o "$@" -elf $(OUTPUT).elf -rsf ../Resources/Gateway_cia.rsf -icon ../Resources/Gateway_cia.icn -banner ../Resources/Gateway_cia.bnr -exefslogo -ver 1040
@echo "built ... Gateway_cia.cia"

#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
Expand Down
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
This is a 3DS homebrew application intended for running under a NCCH(which can be installed via .cia), for booting the *hax payloads. https://smealum.github.io/3ds/

This app was mostly finished in October 2015, this was finally released on November 25, 2015, due to the custom logo being finished.

This will first attempt to load the payload from SD, if that isn't successful it will then automatically download the payload for your system with HTTP. SD payload loading can be skipped if you hold down the X button. If you don't hold down the Y button, this will write the downloaded payload from HTTP to SD, if it actually downloaded it via HTTP.

The exact filepath used for the SD payload depends on your system. Since this app can handle writing the payload here itself, writing the payload here manually isn't really needed. Example SD filepath with New3DS 10.1.0-27U: "/hblauncherloader_otherapp_payload_NEW-10-1-0-27-USA.bin". The Old3DS filepath for the same system-version and region as that example is the same, except that "OLD" is used instead of "NEW".

If you want to manually build this, you'll need this: https://github.com/Steveice10/bannertool

Credits:
* 3DSGuy for originally converting the CWAV used by this app's banner, years ago(which seems to be originally from the Wii HBC banner audio?).
* @Substance12 For the icon/banner(#4).

This is just a CIA shortcut that opens Gateway Launcher.
Run make and then put gate.3dsx onto the root of your SD card along with the Cia_shortcut folder.
Also put the Gateway_cia.cia file and install it on your sysNAND.
Binary file added Resources/Gateway_cia.cgfx
Binary file not shown.
Binary file added Resources/Gateway_cia.cwav
Binary file not shown.
4 changes: 2 additions & 2 deletions Resources/hblauncher_loader.rsf → Resources/Gateway_cia.rsf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BasicInfo:
Title : Gateway Launcher
Title : Gateway CIA
ProductCode : 3DS Chaos
Logo : Homebrew

Expand All @@ -9,7 +9,7 @@ RomFs:

TitleInfo:
Category : Application
UniqueId : 0xd921e
UniqueId : 0xd921d

Option:
UseOnSD : true # true if App is to be installed to SD
Expand Down
Binary file removed Resources/hblauncher_loader.cwav
Binary file not shown.
Binary file removed banner.png
Binary file not shown.
Binary file added bannertool.exe
Binary file not shown.
Binary file added gate.3dsx
Binary file not shown.
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added makerom.exe
Binary file not shown.
270 changes: 270 additions & 0 deletions source/Gateway_cia.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <3ds.h>

extern u32 PAYLOAD_TEXTADDR[];
extern u32 PAYLOAD_TEXTMAXSIZE;

extern Handle gspGpuHandle;

u8 *filebuffer;
u32 filebuffer_maxsize;

char regionids_table[7][4] = {//http://3dbrew.org/wiki/Nandrw/sys/SecureInfo_A
"JPN",
"USA",
"EUR",
"JPN", //"AUS"
"CHN",
"KOR",
"TWN"
};

void gxlowcmd_4(u32* inadr, u32* outadr, u32 size, u32 width0, u32 height0, u32 width1, u32 height1, u32 flags)
{
GX_TextureCopy(inadr, width0 | (height0<<16), outadr, width1 | (height1<<16), size, flags);
}

Result gsp_flushdcache(u8* adr, u32 size)
{
return GSPGPU_FlushDataCache(adr, size);
}

Result loadsd_payload(char *filepath, u32 *payloadsize)
{
struct stat filestats;
FILE *f;
size_t readsize=0;

if(stat(filepath, &filestats)==-1)return errno;

*payloadsize = filestats.st_size;

if(filestats.st_size==0 || filestats.st_size>PAYLOAD_TEXTMAXSIZE)
{
printf("Invalid SD payload size: 0x%08x.\n", (unsigned int)filestats.st_size);
return -3;
}

f = fopen(filepath, "r");
if(f==NULL)return errno;

readsize = fread(filebuffer, 1, filestats.st_size, f);
fclose(f);

if(readsize!=filestats.st_size)
{
printf("fread() failed with the SD payload.\n");
return -2;
}

return 0;
}

Result savesd_payload(char *filepath, u32 payloadsize)
{
FILE *f;
size_t writesize=0;

unlink(filepath);

f = fopen(filepath, "w+");
if(f==NULL)
{
printf("Failed to open the SD payload for writing.\n");
return errno;
}

writesize = fwrite(filebuffer, 1, payloadsize, f);
fclose(f);

if(writesize!=payloadsize)
{
printf("fwrite() failed with the SD payload.\n");
return -2;
}

return 0;
}

Result load_gateway()
{
Result ret = 0;
u8 region=0;
u8 new3dsflag = 0;

OS_VersionBin nver_versionbin;
OS_VersionBin cver_versionbin;

u32 payloadsize = 0, payloadsize_aligned = 0;
u32 payload_src = 0;

char payload_sysver[32];
char payloadurl[0x80];
char payload_sdpath[0x80];

void (*funcptr)(u32*, u32*) = NULL;
u32 *paramblk = NULL;

memset(&nver_versionbin, 0, sizeof(OS_VersionBin));
memset(&cver_versionbin, 0, sizeof(OS_VersionBin));

memset(payload_sysver, 0, sizeof(payload_sysver));
memset(payloadurl, 0, sizeof(payloadurl));
memset(payload_sdpath, 0, sizeof(payload_sdpath));

ret = cfguInit();
if(ret!=0)
{
printf("Failed to init cfgu: 0x%08x.\n", (unsigned int)ret);
return ret;
}
ret = CFGU_SecureInfoGetRegion(&region);
if(ret!=0)
{
printf("Failed to get region from cfgu: 0x%08x.\n", (unsigned int)ret);
return ret;
}
if(region>=7)
{
printf("Region value from cfgu is invalid: 0x%02x.\n", (unsigned int)region);
ret = -9;
return ret;
}
cfguExit();

APT_CheckNew3DS(&new3dsflag);

snprintf(payload_sdpath, sizeof(payload_sdpath)-1, "sdmc:/Cia_shortcut/Gateway_cia.bin", payload_sysver);

memset(filebuffer, 0, filebuffer_maxsize);

printf("Loading payload on SD, with the following filepath: \n", payload_sdpath);
ret = loadsd_payload(payload_sdpath, &payloadsize);

if(ret==0)
{
payload_src = 0;
}
else
{
printf("Can't find \n");
}

printf("Initializing payload data etc...\n");

payloadsize_aligned = (payloadsize + 0xfff) & ~0xfff;
if(payloadsize_aligned > PAYLOAD_TEXTMAXSIZE)
{
printf("Invalid payload size: 0x%08x.\n", (unsigned int)payloadsize);
ret = -3;
return ret;
}

memcpy(PAYLOAD_TEXTADDR, filebuffer, payloadsize_aligned);
memset(filebuffer, 0, filebuffer_maxsize);

ret = svcFlushProcessDataCache(0xffff8001, PAYLOAD_TEXTADDR, payloadsize_aligned);//Flush dcache for the payload which was copied into .text. Since that area was never executed, icache shouldn't be an issue.
if(ret!=0)
{
printf("svcFlushProcessDataCache failed: 0x%08x.\n", (unsigned int)ret);
return ret;
}

paramblk = linearMemAlign(0x10000, 0x1000);
if(paramblk==NULL)
{
ret = 0xfe;
printf("Failed to alloc the paramblk.\n");
return ret;
}

memset(paramblk, 0, 0x10000);

paramblk[0x1c>>2] = (u32)gxlowcmd_4;
paramblk[0x20>>2] = (u32)gsp_flushdcache;
paramblk[0x48>>2] = 0x8d;//flags
paramblk[0x58>>2] = (u32)&gspGpuHandle;

printf("Jumping into the payload...\n");

funcptr = (void*)PAYLOAD_TEXTADDR;
funcptr(paramblk, (u32*)(0x10000000-0x1000));

ret = 0xff;
printf("The payload returned back into the app.\n");

return ret;
}

int main(int argc, char **argv)
{
Result ret = 0;
u32 pos;
Handle kproc_handledup=0;

// Initialize services
gfxInitDefault();

consoleInit(GFX_BOTTOM, NULL);

printf("Gateway Cia\n", VERSION);

ret = svcDuplicateHandle(&kproc_handledup, 0xffff8001);
if(ret!=0)printf("svcDuplicateHandle() with the current proc-handle failed: 0x%08x.\n", (unsigned int)ret);

if(ret==0)
{
for(pos=0; pos<PAYLOAD_TEXTMAXSIZE; pos+=0x1000)
{
ret = svcControlProcessMemory(kproc_handledup, (u32)&PAYLOAD_TEXTADDR[pos >> 2], 0x0, 0x1000, MEMOP_PROT, MEMPERM_READ | MEMPERM_WRITE | MEMPERM_EXECUTE);
if(ret!=0)
{
printf("svcControlProcessMemory with pos=0x%x failed: 0x%08x.\n", (unsigned int)pos, (unsigned int)ret);
break;
}
}
}

if(ret==0)
{
filebuffer_maxsize = PAYLOAD_TEXTMAXSIZE;

filebuffer = (u8*)malloc(filebuffer_maxsize);
if(filebuffer==NULL)
{
printf("Failed to allocate memory.\n");
ret = -1;
}
else
{
memset(filebuffer, 0, filebuffer_maxsize);
}
}

ret = load_gateway();

free(filebuffer);

if(ret!=0 && ret!=0xd8a0a046)printf("An error occured\n");

printf("Press the START button to exit.\n");
// Main loop
while (aptMainLoop())
{
gspWaitForVBlank();
hidScanInput();

u32 kDown = hidKeysDown();
if (kDown & KEY_START)
break;
}

// Exit services
gfxExit();
return 0;
}
Loading

0 comments on commit ee770a9

Please sign in to comment.