From d6e56d487f4624237407c395b93d53bfa6e44cf6 Mon Sep 17 00:00:00 2001 From: fincs Date: Wed, 9 May 2018 18:18:18 +0200 Subject: [PATCH] Build NPDM from JSON configuration file (with enhancements), see details: - Granted access to all FS permissions. - Granted user/host access to all services. - Kernel caps application type set to applet (2) in order to allow nx-hbloader to run while official apps are suspended. This fixes fatal error 2144-0001 during nx-hbloader startup. **CAVEAT**: This reduces maximum heap size to around 500MB. For this reason this change may be *reverted* or worked around in the future. - Revise handle-duplication workaround to allow official apps to run after having used and closed nx-hbloader. --- .gitignore | 3 ++ Makefile | 24 +++++++-- exefs_src/main.npdm | Bin 1452 -> 0 bytes hbl.json | 128 ++++++++++++++++++++++++++++++++++++++++++++ source/main.c | 12 ++--- 5 files changed, 157 insertions(+), 10 deletions(-) delete mode 100644 exefs_src/main.npdm create mode 100644 hbl.json diff --git a/.gitignore b/.gitignore index 1d1f008..b4e359f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ build/ *.elf *.nso +*.npdm +*.nsp *.pfs0 *.db +*.zip *~ diff --git a/Makefile b/Makefile index 629d2b3..1c669aa 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,19 @@ export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC) +ifeq ($(strip $(CONFIG_JSON)),) + jsons := $(wildcard *.json) + ifneq (,$(findstring $(TARGET).json,$(jsons))) + export APP_JSON := $(TOPDIR)/$(TARGET).json + else + ifneq (,$(findstring config.json,$(jsons))) + export APP_JSON := $(TOPDIR)/config.json + endif + endif +else + export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) +endif + .PHONY: $(BUILD) clean all #--------------------------------------------------------------------------------- @@ -107,8 +120,7 @@ $(BUILD): #--------------------------------------------------------------------------------- clean: @echo clean ... - @rm -fr $(BUILD) $(TARGET).pfs0 $(TARGET).nso $(TARGET).elf - + @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).npdm $(TARGET).nso $(TARGET).elf #--------------------------------------------------------------------------------- else @@ -119,9 +131,13 @@ DEPENDS := $(OFILES:.o=.d) #--------------------------------------------------------------------------------- # main targets #--------------------------------------------------------------------------------- -all : $(OUTPUT).pfs0 +all : $(OUTPUT).nsp -$(OUTPUT).pfs0 : $(OUTPUT).nso +ifeq ($(strip $(APP_JSON)),) +$(OUTPUT).nsp : $(OUTPUT).nso +else +$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm +endif $(OUTPUT).nso : $(OUTPUT).elf diff --git a/exefs_src/main.npdm b/exefs_src/main.npdm deleted file mode 100644 index 17c73a302f88dbbe8ca687632bd1040cf80cd58b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1452 zcmeHGy-ve05WeQ8nGlQ&Nbmq4I%lC3bYMU%>@*}!YbkLopB+Z}06an^cncnjoh5v3 ziG+|4s3YQ{%bj!n&gc6sSJRsbeMm^hz58MJXrgr`^UTUdeTi+iJc@`O2SiK2SK)R! z{!xFY1C#U1i&e0>55|Ia_SXKOw`0WoRBG5aZ!t5Ur_^JP@Ic1?^^*iFY_PC-qRKpV zEKF2OnYtj;b&|QFaW-|al4YH`(6X+>7SRv@UL)!j;v#iXRUkuB8YvW(!;ES8Kx}0#P>-(QSA|JU6Xk5wJi@`qhdNU$R2!+bFfA(9>pO-uuCwXPYu6n@ z&!D%j9nE%W`E*M3{K6D;w?y69K6MZ9yA3JeXY{$JJum&YF`NVF4C?urfspU`@%y~= M*8Bf_{FV=*cN0_PumAu6 diff --git a/hbl.json b/hbl.json new file mode 100644 index 0000000..2200f19 --- /dev/null +++ b/hbl.json @@ -0,0 +1,128 @@ +{ + "name" : "hbloader", + "title_id" : "0x010000000000100D", + "title_id_range_min" : "0x010000000000100D", + "title_id_range_max" : "0x010000000000100D", + "main_thread_stack_size" : "0x100000", + "main_thread_priority" : 44, + "default_cpu_id" : 0, + "process_category" : 0, + "pool_partition" : 0, + "is_64_bit" : true, + "address_space_type" : 1, + "is_retail" : true, + "filesystem_access" : { + "permissions" : "0xFFFFFFFFFFFFFFFF" + }, + "service_access" : { + "*" : false, + "*" : true + }, + "kernel_capabilities" : { + "kernel_flags" : { + "highest_thread_priority" : 59, + "lowest_thread_priority" : 28, + "highest_cpu_id" : 3, + "lowest_cpu_id" : 0 + }, + "syscalls" : { + "svcUnknown00" : "0x00", + "svcSetHeapSize" : "0x01", + "svcSetMemoryPermission" : "0x02", + "svcSetMemoryAttribute" : "0x03", + "svcMapMemory" : "0x04", + "svcUnmapMemory" : "0x05", + "svcQueryMemory" : "0x06", + "svcExitProcess" : "0x07", + "svcCreateThread" : "0x08", + "svcStartThread" : "0x09", + "svcExitThread" : "0x0A", + "svcSleepThread" : "0x0B", + "svcGetThreadPriority" : "0x0C", + "svcSetThreadPriority" : "0x0D", + "svcGetThreadCoreMask" : "0x0E", + "svcSetThreadCoreMask" : "0x0F", + "svcGetCurrentProcessorNumber" : "0x10", + "svcSignalEvent" : "0x11", + "svcClearEvent" : "0x12", + "svcMapSharedMemory" : "0x13", + "svcUnmapSharedMemory" : "0x14", + "svcCreateTransferMemory" : "0x15", + "svcCloseHandle" : "0x16", + "svcResetSignal" : "0x17", + "svcWaitSynchronization" : "0x18", + "svcCancelSynchronization" : "0x19", + "svcArbitrateLock" : "0x1A", + "svcArbitrateUnlock" : "0x1B", + "svcWaitProcessWideKeyAtomic" : "0x1C", + "svcSignalProcessWideKey" : "0x1D", + "svcGetSystemTick" : "0x1E", + "svcConnectToNamedPort" : "0x1F", + "svcSendSyncRequestLight" : "0x20", + "svcSendSyncRequest" : "0x21", + "svcSendSyncRequestWithUserBuffer" : "0x22", + "svcSendAsyncRequestWithUserBuffer" : "0x23", + "svcGetProcessId" : "0x24", + "svcGetThreadId" : "0x25", + "svcBreak" : "0x26", + "svcOutputDebugString" : "0x27", + "svcReturnFromException" : "0x28", + "svcGetInfo" : "0x29", + "svcFlushEntireDataCache" : "0x2A", + "svcFlushDataCache" : "0x2B", + "svcMapPhysicalMemory" : "0x2C", + "svcUnmapPhysicalMemory" : "0x2D", + "svcGetFutureThreadInfo" : "0x2E", + "svcGetLastThreadInfo" : "0x2F", + "svcGetResourceLimitLimitValue" : "0x30", + "svcGetResourceLimitCurrentValue" : "0x31", + "svcSetThreadActivity" : "0x32", + "svcGetThreadContext3" : "0x33", + "svcWaitForAddress" : "0x34", + "svcSignalToAddress" : "0x35", + "svcUnknown36" : "0x36", + "svcUnknown37" : "0x37", + "svcUnknown38" : "0x38", + "svcUnknown39" : "0x39", + "svcUnknown3a" : "0x3A", + "svcUnknown3b" : "0x3B", + "svcDumpInfo" : "0x3C", + "svcDumpInfoNew" : "0x3D", + "svcUnknown3e" : "0x3E", + "svcUnknown3f" : "0x3F", + "svcCreateSession" : "0x40", + "svcAcceptSession" : "0x41", + "svcReplyAndReceiveLight" : "0x42", + "svcReplyAndReceive" : "0x43", + "svcReplyAndReceiveWithUserBuffer" : "0x44", + "svcCreateEvent" : "0x45", + "svcUnknown46" : "0x46", + "svcUnknown47" : "0x47", + "svcMapPhysicalMemoryUnsafe" : "0x48", + "svcUnmapPhysicalMemoryUnsafe" : "0x49", + "svcSetUnsafeLimit" : "0x4A", + "svcCreateCodeMemory" : "0x4B", + "svcControlCodeMemory" : "0x4C", + "svcSleepSystem" : "0x4D", + "svcReadWriteRegister" : "0x4E", + "svcSetProcessActivity" : "0x4F", + "svcCreateSharedMemory" : "0x50", + "svcMapTransferMemory" : "0x51", + "svcUnmapTransferMemory" : "0x52", + "svcConnectToPort" : "0x72", + "svcSetProcessMemoryPermission" : "0x73", + "svcMapProcessMemory" : "0x74", + "svcUnmapProcessMemory" : "0x75", + "svcQueryProcessMemory" : "0x76", + "svcMapProcessCodeMemory" : "0x77", + "svcUnmapProcessCodeMemory" : "0x78" + }, + "application_type" : 2, + "min_kernel_version" : "0x30", + "handle_table_size" : 512, + "debug_flags" : { + "allow_debug" : true, + "force_debug" : true + } + } +} diff --git a/source/main.c b/source/main.c index 317d0d4..b7bb6e7 100644 --- a/source/main.c +++ b/source/main.c @@ -124,11 +124,7 @@ void getOwnProcessHandle(void) if (R_FAILED(rc)) fatalSimple(MAKERESULT(MODULE_HBL, 10)); - rc = smUnregisterService("appletOE"); - if (R_FAILED(rc)) - fatalSimple(MAKERESULT(MODULE_HBL, 11)); - - rc = smRegisterService(&g_port, "appletOE", false, 1); + rc = smRegisterService(&g_port, "hb:ldr", false, 1); if (R_FAILED(rc)) fatalSimple(MAKERESULT(MODULE_HBL, 12)); @@ -137,7 +133,7 @@ void getOwnProcessHandle(void) fatalSimple(MAKERESULT(MODULE_HBL, 13)); Service srv; - rc = smGetService(&srv, "appletOE"); + rc = smGetService(&srv, "hb:ldr"); if (R_FAILED(rc)) fatalSimple(MAKERESULT(MODULE_HBL, 23)); @@ -160,6 +156,10 @@ void getOwnProcessHandle(void) serviceClose(&srv); svcCloseHandle(g_port); + rc = smUnregisterService("hb:ldr"); + if (R_FAILED(rc)) + fatalSimple(MAKERESULT(MODULE_HBL, 11)); + smExit(); }