Merge pull request #8 from jugeeya/master

PM load module; add file related core functions
This commit is contained in:
Max Thomas 2019-07-22 09:39:42 -07:00 committed by GitHub
commit d626a04018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 285 additions and 170 deletions

View File

@ -9,12 +9,12 @@ endif
TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/devkitA64/base_rules
all: libnx_min/nx/lib/libnx_min.a sdcard_out/SaltySD/saltysd_core.elf sdcard_out/SaltySD/saltysd_proc.elf sdcard_out/atmosphere/kips/saltysd_spawner.kip saltysd_plugin_example/saltysd_plugin_example.elf
all: libnx_min/nx/lib/libnx_min.a sdcard_out/SaltySD/saltysd_core.elf sdcard_out/SaltySD/saltysd_proc.elf sdcard_out/atmosphere/titles/0100000000534C56/exefs.nsp saltysd_plugin_example/saltysd_plugin_example.elf
libnx_min/nx/lib/libnx_min.a:
@cd libnx_min && make
saltysd_spawner/saltysd_spawner.kip:
saltysd_spawner/saltysd_spawner.nsp:
@cd saltysd_spawner && make
saltysd_proc/saltysd_proc.elf: saltysd_proc/data/saltysd_bootstrap.elf
@ -41,9 +41,10 @@ sdcard_out/SaltySD/saltysd_proc.elf: saltysd_proc/saltysd_proc.elf
@mkdir -p sdcard_out/SaltySD/
@cp $< $@
sdcard_out/atmosphere/kips/saltysd_spawner.kip: saltysd_spawner/saltysd_spawner.kip
@mkdir -p sdcard_out/atmosphere/kips/
sdcard_out/atmosphere/titles/0100000000534C56/exefs.nsp: saltysd_spawner/saltysd_spawner.nsp
@mkdir -p sdcard_out/atmosphere/titles/0100000000534C56/flags
@cp $< $@
@touch sdcard_out/atmosphere/titles/0100000000534C56/flags/boot2.flag
clean:
@rm -f saltysd_proc/data/*

View File

@ -1,6 +1,7 @@
#include "saltysd_core.h"
#include "bm.h"
#include <errno.h>
extern void _start();
u64 code_start = 0;
@ -94,3 +95,40 @@ int SaltySDCore_fclose(FILE* stream)
{
return fclose(stream);
}
int SaltySDCore_fseek(FILE* stream, int64_t offset, int origin)
{
int ret = fseek(stream, offset, origin);
if (ret)
return errno;
return 0;
}
long int SaltySDCore_ftell(FILE* stream) {
return ftell(stream);
}
int SaltySDCore_remove(const char* filename) {
return remove(filename);
}
size_t SaltySDCore_fwrite(const void* ptr, size_t size, size_t count, FILE* stream)
{
return fwrite(ptr, size, count, stream);
}
DIR* SaltySDCore_opendir(const char* dirname)
{
return opendir(dirname);
}
struct dirent* SaltySDCore_readdir(DIR* dirp)
{
return readdir(dirp);
}
int SaltySDCore_closedir(DIR *dirp)
{
return closedir(dirp);
}

View File

@ -2,6 +2,7 @@
#define SALTYSD_CORE_H
#include <switch_min.h>
#include <dirent.h>
#include "useful.h"
@ -15,6 +16,13 @@ extern u64 SaltySDCore_findCode(u8* code, size_t size) LINKABLE;
extern FILE* SaltySDCore_fopen(const char* filename, const char* mode) LINKABLE;
extern size_t SaltySDCore_fread(void* ptr, size_t size, size_t count, FILE* stream) LINKABLE;
extern int SaltySDCore_fclose(FILE* stream) LINKABLE;
extern int SaltySDCore_fseek(FILE* stream, int64_t offset, int origin) LINKABLE;
extern int64_t SaltySDCore_ftell(FILE* stream) LINKABLE;
extern int SaltySDCore_remove(const char* filename) LINKABLE;
extern size_t SaltySDCore_fwrite(const void* ptr, size_t size, size_t count, FILE* stream) LINKABLE;
extern DIR* SaltySDCore_opendir(const char* dirname) LINKABLE;
extern struct dirent* SaltySDCore_readdir(DIR* dirp) LINKABLE;
extern int SaltySDCore_closedir(DIR *dirp) LINKABLE;
#ifdef __cplusplus
}

View File

@ -108,6 +108,9 @@ void hijack_pid(u64 pid)
if (ret)
{
SaltySD_printf("SaltySD: svcGetDebugEventInfo returned %x, breaking\n", ret);
// Invalid Handle
if (ret == 0xe401)
goto abort_bootstrap;
break;
}

View File

@ -16,6 +16,7 @@ include $(DEVKITPRO)/libnx/switch_rules
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm".
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
#
# NO_ICON: if set to anything, do not use icon.
# NO_NACP: if set to anything, no .nacp file is generated.
@ -29,23 +30,23 @@ include $(DEVKITPRO)/libnx/switch_rules
# - icon.jpg
# - <libnx folder>/default_icon.jpg
#---------------------------------------------------------------------------------
TARGET := saltysd_spawner
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include source
EXEFS_SRC := exefs_src
#ROMFS := romfs
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := -g -Wall -O2 \
-ffast-math \
CFLAGS := -g -Wall -O2 -ffunction-sections -ffast-math \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -DSWITCH
CFLAGS += $(INCLUDE) -D__SWITCH__ -DSWITCH
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
@ -106,6 +107,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
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.jpg)
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
@ -131,6 +145,10 @@ ifneq ($(APP_TITLEID),)
export NACPFLAGS += --titleid=$(APP_TITLEID)
endif
ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
@ -143,7 +161,7 @@ $(BUILD):
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(OUTPUT).kip $(TARGET).nsp $(TARGET).nacp $(TARGET).elf $(DATA)/*.elf
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(OUTPUT).kip $(TARGET).nsp $(TARGET).nacp $(TARGET).elf $(DATA)/*.elf
#---------------------------------------------------------------------------------
@ -155,15 +173,17 @@ DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT).pfs0 $(OUTPUT).nro $(OUTPUT).kip
all : $(OUTPUT).pfs0 $(OUTPUT).nsp $(OUTPUT).nro $(OUTPUT).kip
$(OUTPUT).pfs0 : $(OUTPUT).nso
$(OUTPUT).nso : $(OUTPUT).elf
ifeq ($(strip $(APP_JSON)),)
$(OUTPUT).nsp : $(OUTPUT).nso
else
$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
endif
$(OUTPUT).kip : $(OUTPUT).elf
@elf2kip $< $(OUTPUT).json $@
@echo built ... $(notdir $@)
$(OUTPUT).nso : $(OUTPUT).elf
ifeq ($(strip $(NO_NACP)),)
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
@ -173,10 +193,14 @@ endif
$(OUTPUT).elf : $(OFILES)
$(OUTPUT).kip : $(OUTPUT).elf
@elf2kip $< $(OUTPUT).json $@
@echo built ... $(notdir $@)
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
%.bin.o %_bin.h : %.bin
%.elf.o : %.elf
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@ -186,4 +210,4 @@ $(OUTPUT).elf : $(OFILES)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------

View File

@ -1,155 +1,196 @@
{
"name" : "saltysdspwn",
"title_id" : "0x0100000000534C56",
"main_thread_stack_size" : "0x100000",
"main_thread_priority" : 49,
"default_cpu_id" : 3,
"process_category" : 1,
"is_64_bit" : true,
"address_space_type" : 3,
"kernel_capabilities" : {
"handle_table_size" : 256,
"debug_flags": {
"allow_debug": false,
"force_debug": true
},
"syscalls" : {
"svcSetHeapSize": 1,
"svcSetMemoryPermission": 2,
"svcSetMemoryAttribute": 3,
"svcMapMemory": 4,
"svcUnmapMemory": 5,
"svcQueryMemory": 6,
"svcExitProcess": 7,
"svcCreateThread": 8,
"svcStartThread": 9,
"svcExitThread": 10,
"svcSleepThread": 11,
"svcGetThreadPriority": 12,
"svcSetThreadPriority": 13,
"svcGetThreadCoreMask": 14,
"svcSetThreadCoreMask": 15,
"svcGetCurrentProcessorNumber": 16,
"svcSignalEvent": 17,
"svcClearEvent": 18,
"svcMapSharedMemory": 19,
"svcUnmapSharedMemory": 20,
"svcCreateTransferMemory": 21,
"svcCloseHandle": 22,
"svcResetSignal": 23,
"svcWaitSynchronization": 24,
"svcCancelSynchronization": 25,
"svcArbitrateLock": 26,
"svcArbitrateUnlock": 27,
"svcWaitProcessWideKeyAtomic": 28,
"svcSignalProcessWideKey": 29,
"svcGetSystemTick": 30,
"svcConnectToNamedPort": 31,
"svcSendSyncRequestLight": 32,
"svcSendSyncRequest": 33,
"svcSendSyncRequestWithUserBuffer": 34,
"svcSendAsyncRequestWithUserBuffer": 35,
"svcGetProcessId": 36,
"svcGetThreadId": 37,
"svcBreak": 38,
"svcOutputDebugString": 39,
"svcReturnFromException": 40,
"svcGetInfo": 41,
"svcFlushEntireDataCache": 42,
"svcFlushDataCache": 43,
"svcMapPhysicalMemory": 44,
"svcUnmapPhysicalMemory": 45,
"svcGetFutureThreadInfo": 46,
"svcGetLastThreadInfo": 47,
"svcGetResourceLimitLimitValue": 48,
"svcGetResourceLimitCurrentValue": 49,
"svcSetThreadActivity": 50,
"svcGetThreadContext3": 51,
"svcWaitForAddress": 52,
"svcSignalToAddress": 53,
"svcDumpInfo": 60,
"svcDumpInfoNew": 61,
"svcCreateSession": 64,
"svcAcceptSession": 65,
"svcReplyAndReceiveLight": 66,
"svcReplyAndReceive": 67,
"svcReplyAndReceiveWithUserBuffer": 68,
"svcCreateEvent": 69,
"svcMapPhysicalMemoryUnsafe": 72,
"svcUnmapPhysicalMemoryUnsafe": 73,
"svcSetUnsafeLimit": 74,
"svcCreateCodeMemory": 75,
"svcControlCodeMemory": 76,
"svcSleepSystem": 77,
"svcReadWriteRegister": 78,
"svcSetProcessActivity": 79,
"svcCreateSharedMemory": 80,
"svcMapTransferMemory": 81,
"svcUnmapTransferMemory": 82,
"vcCreateInterruptEvent": 83,
"svcQueryPhysicalAddress": 84,
"svcQueryIoMapping": 85,
"svcCreateDeviceAddressSpace": 86,
"svcAttachDeviceAddressSpace": 87,
"svcDetachDeviceAddressSpace": 88,
"svcMapDeviceAddressSpaceByForce": 89,
"svcMapDeviceAddressSpaceAligned": 90,
"svcMapDeviceAddressSpace": 91,
"svcUnmapDeviceAddressSpace": 92,
"svcInvalidateProcessDataCache": 93,
"svcStoreProcessDataCache": 94,
"svcFlushProcessDataCache": 95,
"svcDebugActiveProcess": 96,
"svcBreakDebugProcess": 97,
"svcTerminateDebugProcess": 98,
"svcGetDebugEvent": 99,
"svcContinueDebugEvent": 100,
"svcGetProcessList": 101,
"svcGetThreadList": 102,
"svcGetDebugThreadContext": 103,
"svcSetDebugThreadContext": 104,
"svcQueryDebugProcessMemory": 105,
"svcReadDebugProcessMemory": 106,
"svcWriteDebugProcessMemory": 107,
"svcSetHardwareBreakPoint": 108,
"svcGetDebugThreadParam": 109,
"svcGetSystemInfo": 111,
"svcCreatePort": 112,
"svcManageNamedPort": 113,
"svcConnectToPort": 114,
"svcSetProcessMemoryPermission": 115,
"svcMapProcessMemory": 116,
"svcUnmapProcessMemory": 117,
"svcQueryProcessMemory": 118,
"svcMapProcessCodeMemory": 119,
"svcUnmapProcessCodeMemory": 120,
"svcCreateProcess": 121,
"svcStartProcess": 122,
"svcTerminateProcess": 123,
"svcGetProcessInfo": 124,
"svcCreateResourceLimit": 125,
"svcSetResourceLimitLimitValue": 126,
"svcCallSecureMonitor": 127
},
"map" : {
"address" : "0x702d0000",
"size" : "0x30000",
"is_ro" : false,
"is_io" : true
},
"map" : {
"address" : "0x60006000",
"size" : "0x1000",
"is_ro" : false,
"is_io" : true
},
"map" : {
"address" : "0x70003000",
"size" : "0x1000",
"is_ro" : false,
"is_io" : true
}
}
}
"name": "saltysdspwn",
"title_id": "0x0100000000534C56",
"title_id_range_min": "0x0100000000534C56",
"title_id_range_max": "0x0100000000534C56",
"main_thread_stack_size": "0x100000",
"main_thread_priority": 49,
"default_cpu_id": 3,
"process_category": 1,
"is_retail": true,
"pool_partition": 0,
"is_64_bit": true,
"address_space_type": 3,
"filesystem_access": {
"permissions": "0xffffffffffffffff"
},
"service_access": ["*"],
"service_host": ["*"],
"kernel_capabilities": [{
"type": "kernel_flags",
"value": {
"highest_thread_priority": 63,
"lowest_thread_priority": 24,
"lowest_cpu_id": 3,
"highest_cpu_id": 3
}
}, {
"type": "syscalls",
"value": {
"svcUnknown": "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",
"svcUnknown": "0x36",
"svcUnknown": "0x37",
"svcUnknown": "0x38",
"svcUnknown": "0x39",
"svcUnknown": "0x3a",
"svcUnknown": "0x3b",
"svcDumpInfo": "0x3c",
"svcDumpInfoNew": "0x3d",
"svcUnknown": "0x3e",
"svcUnknown": "0x3f",
"svcCreateSession": "0x40",
"svcAcceptSession": "0x41",
"svcReplyAndReceiveLight": "0x42",
"svcReplyAndReceive": "0x43",
"svcReplyAndReceiveWithUserBuffer": "0x44",
"svcCreateEvent": "0x45",
"svcUnknown": "0x46",
"svcUnknown": "0x47",
"svcMapPhysicalMemoryUnsafe": "0x48",
"svcUnmapPhysicalMemoryUnsafe": "0x49",
"svcSetUnsafeLimit": "0x4a",
"svcCreateCodeMemory": "0x4b",
"svcControlCodeMemory": "0x4c",
"svcSleepSystem": "0x4d",
"svcReadWriteRegister": "0x4e",
"svcSetProcessActivity": "0x4f",
"svcCreateSharedMemory": "0x50",
"svcMapTransferMemory": "0x51",
"svcUnmapTransferMemory": "0x52",
"svcCreateInterruptEvent": "0x53",
"svcQueryPhysicalAddress": "0x54",
"svcQueryIoMapping": "0x55",
"svcCreateDeviceAddressSpace": "0x56",
"svcAttachDeviceAddressSpace": "0x57",
"svcDetachDeviceAddressSpace": "0x58",
"svcMapDeviceAddressSpaceByForce": "0x59",
"svcMapDeviceAddressSpaceAligned": "0x5a",
"svcMapDeviceAddressSpace": "0x5b",
"svcUnmapDeviceAddressSpace": "0x5c",
"svcInvalidateProcessDataCache": "0x5d",
"svcStoreProcessDataCache": "0x5e",
"svcFlushProcessDataCache": "0x5f",
"svcDebugActiveProcess": "0x60",
"svcBreakDebugProcess": "0x61",
"svcTerminateDebugProcess": "0x62",
"svcGetDebugEvent": "0x63",
"svcContinueDebugEvent": "0x64",
"svcGetProcessList": "0x65",
"svcGetThreadList": "0x66",
"svcGetDebugThreadContext": "0x67",
"svcSetDebugThreadContext": "0x68",
"svcQueryDebugProcessMemory": "0x69",
"svcReadDebugProcessMemory": "0x6a",
"svcWriteDebugProcessMemory": "0x6b",
"svcSetHardwareBreakPoint": "0x6c",
"svcGetDebugThreadParam": "0x6d",
"svcUnknown": "0x6e",
"svcGetSystemInfo": "0x6f",
"svcCreatePort": "0x70",
"svcManageNamedPort": "0x71",
"svcConnectToPort": "0x72",
"svcSetProcessMemoryPermission": "0x73",
"svcMapProcessMemory": "0x74",
"svcUnmapProcessMemory": "0x75",
"svcQueryProcessMemory": "0x76",
"svcMapProcessCodeMemory": "0x77",
"svcUnmapProcessCodeMemory": "0x78",
"svcCreateProcess": "0x79",
"svcStartProcess": "0x7a",
"svcTerminateProcess": "0x7b",
"svcGetProcessInfo": "0x7c",
"svcCreateResourceLimit": "0x7d",
"svcSetResourceLimitLimitValue": "0x7e",
"svcCallSecureMonitor": "0x7f"
}
}, {
"type": "min_kernel_version",
"value": "0x0030"
}, {
"type": "handle_table_size",
"value": 256
}, {
"type": "debug_flags",
"value": {
"allow_debug": false,
"force_debug": true
}
}, {
"type": "map",
"value": {
"address" : "0x702d0000",
"size" : "0x30000",
"is_ro" : false,
"is_io" : true
}
}, {
"type": "map",
"value": {
"address" : "0x60006000",
"size" : "0x1000",
"is_ro" : false,
"is_io" : true
}
}, {
"type": "map",
"value": {
"address" : "0x70003000",
"size" : "0x1000",
"is_ro" : false,
"is_io" : true
}
}]
}