diff --git a/.gitignore b/.gitignore index 8fb487ba..68cfaa78 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ modules.order Module.symvers Mkfile.old dkms.conf +build diff --git a/3ds.ld b/3ds.ld index e034cc7a..9bc29a93 100644 --- a/3ds.ld +++ b/3ds.ld @@ -30,6 +30,7 @@ SECTIONS . = ALIGN(4); .bss : { *(.__bss_start) + *(.bss.*) *(.bss COMMON) *(.__bss_end) } diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..b55335ed --- /dev/null +++ b/Makefile @@ -0,0 +1,142 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") +endif + +TOPDIR ?= $(CURDIR) +include $(DEVKITARM)/3ds_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +#--------------------------------------------------------------------------------- +TARGET := ntr_payload +BUILD := build +SOURCES := source source/dsp source/jpeg source/ns source/libctru +DATA := +INCLUDES := include include/jpeg + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -O3 + +CFLAGS := -Wall \ + -fomit-frame-pointer -ffunction-sections -fdata-sections \ + $(ARCH) + +CFLAGS += $(INCLUDE) -DHAS_JPEG=1 + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 + +ASFLAGS := -g $(ARCH) +LDFLAGS = -pie -nostartfiles -T$(TOPDIR)/3ds.ld -g $(ARCH) -Wl,--gc-sections -Wl,-Map,$(notdir $*.map) + +LIBS := -lm + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) + +export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) + +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).bin: $(OUTPUT).elf + @echo "creating $(notdir $@)" + @$(OBJCOPY) -O binary $< $@ -S + +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SOURCES) : $(HFILES) + + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/README.md b/README.md index 34890c3d..16c9d49b 100644 --- a/README.md +++ b/README.md @@ -1 +1,11 @@ -# NTR \ No newline at end of file +# NTR + + +# TODO LIST + +0. Fix the build system first. +1. The printf impl. (xprintf.c) is not thread-safe, it should be replaced with a thread-safe one. + +# LICENSE + +GPLv2 diff --git a/build-jpeg.py b/build-jpeg.py deleted file mode 100644 index 37116aaa..00000000 --- a/build-jpeg.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python -import sys -import os -import ftplib -import glob - - -BASE_ADDRESS = 0x080C3EE0 -CC = "arm-none-eabi-gcc" -CP = "arm-none-eabi-g++" -OC = "arm-none-eabi-objcopy" -LD = "arm-none-eabi-ld" -CTRULIB = '../libctru' -DEVKITARM = 'c:/devkitPro/devkitARM' -LIBPATH = '-L .' - -with open('include/gen.h', 'w') as f: - f.write('#define HAS_JPEG (1)'); - -def allFile(pattern): - s = ""; - for file in glob.glob(pattern): - s += file + " "; - return s; - -def run(cmd): - os.system(cmd) - -cwd = os.getcwd() -run("rm obj/*.o") -run("rm bin/*.elf") -run(CC+ " -O3 -s -g -I include -I include/jpeg -I/c/devkitPro/portlibs/armv6k/include " + allFile('source/dsp/*.c') + allFile('source/jpeg/*.c') + allFile('source/ns/*.c') + allFile('source/*.c') + allFile('source/libctru/*.c') + " -c -march=armv6 -mlittle-endian -fomit-frame-pointer -ffast-math -march=armv6k -mtune=mpcore -mfloat-abi=hard "); -run(CC+" -O3 " + allFile('source/ns/*.s') + allFile('source/*.s') + allFile('source/libctru/*.s') + " -c -s -march=armv6 -mlittle-endian -fomit-frame-pointer -ffast-math -march=armv6k -mtune=mpcore -mfloat-abi=hard "); - -run(LD + ' ' + LIBPATH + " -g -A armv6k -pie --print-gc-sections -T 3ds.ld -Map=test.map " + allFile("*.o") + " -lc -lm -lgcc --nostdlib" ) -run("cp -r *.o obj/ ") -run("cp a.out bin/homebrew.elf ") -run(OC+" -O binary a.out payload.bin -S") -run("rm *.o") -run("rm *.out") -# run('copy payload.bin \\\\3DS-8141\\microSD\\ntr.bin'); -run('copy payload.bin release\\ntr.n3ds.bin'); diff --git a/build.py b/build.py deleted file mode 100644 index 2b14ad72..00000000 --- a/build.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/python -import sys -import os -import ftplib -import glob - - -BASE_ADDRESS = 0x080C3EE0 -CC = "arm-none-eabi-gcc" -CP = "arm-none-eabi-g++" -OC = "arm-none-eabi-objcopy" -LD = "arm-none-eabi-ld" -CTRULIB = '../libctru' -DEVKITARM = 'c:/devkitPro/devkitARM' -LIBPATH = '-L .' - -def allFile(pattern): - s = ""; - for file in glob.glob(pattern): - s += file + " "; - return s; - -def run(cmd): - os.system(cmd) - -with open('include/gen.h', 'w') as f: - f.write(''); - -cwd = os.getcwd() -run("rm obj/*.o") -run("rm bin/*.elf") -run(CC+ " -O3 -s -g -I include -I include/jpeg -I/c/devkitPro/portlibs/armv6k/include " + allFile('source/dsp/*.c') + " -c -march=armv6 -mlittle-endian -fomit-frame-pointer -ffast-math -march=armv6k -mtune=mpcore -mfloat-abi=hard "); -run(CC+ " -Os -s -g -I include -I include/jpeg -I/c/devkitPro/portlibs/armv6k/include " + allFile('source/ns/*.c') + allFile('source/*.c') + allFile('source/libctru/*.c') + " -c -march=armv6 -mlittle-endian -fomit-frame-pointer -ffast-math -march=armv6k -mtune=mpcore -mfloat-abi=hard "); -run(CC+" -Os " + allFile('source/ns/*.s') + allFile('source/*.s') + allFile('source/libctru/*.s') + " -c -s -march=armv6 -mlittle-endian -fomit-frame-pointer -ffast-math -march=armv6k -mtune=mpcore -mfloat-abi=hard "); - -run(LD + ' ' + LIBPATH + " -g -A armv6k -pie --print-gc-sections -T 3ds.ld -Map=test.map " + allFile("*.o") + " -lc -lm -lgcc --nostdlib" ) -run("cp -r *.o obj/ ") -run("cp a.out bin/homebrew.elf ") -run(OC+" -O binary a.out payload.bin -S") -run("rm *.o") -run("rm *.out") -# run('copy payload.bin \\\\3DS-8141\\microSD\\ntr.bin'); -run('copy payload.bin release\\ntr.o3ds.bin'); diff --git a/include/2d.h b/include/2d.h index 5d48b584..12caf35e 100644 --- a/include/2d.h +++ b/include/2d.h @@ -23,16 +23,20 @@ void paint_pixel(u32 x, u32 y, char r, char g, char b, int screen); void paint_word(char* word, int x,int y, char r, char g, char b, int screen); -void paint_word_vert(char* word, int x,int y, char r, char g, char b, int screen); -void paint_buffer(u8* file, point f_dim, point offset, int screen); -void paint_byte_pixel(unsigned char byte, int x, int y, int screen); -void paint_sprite(unsigned char* sheet, point f_dim, point offset, int screen, int height, int width, int xstart, int ystart); void paint_square(int x, int y, char r, char g, char b, int h, int w, int screen); +void paint_letter(u8 letter, int x, int y, char r, char g, char b, int screen); +//Unused paint functions. +//void paint_word_vert(char* word, int x,int y, char r, char g, char b, int screen); +//void paint_buffer(u8* file, point f_dim, point offset, int screen); +//void paint_byte_pixel(unsigned char byte, int x, int y, int screen); +//void paint_sprite(unsigned char* sheet, point f_dim, point offset, int screen, int height, int width, int xstart, int ystart); //DLH void blank(int x, int y, int xs, int ys); -void square(int x, int y, int xs, int ys); + +//Unused function for DLH. +//void square(int x, int y, int xs, int ys); extern u32 bottomFrameBuffer; #endif \ No newline at end of file diff --git a/include/ctr/srv.h b/include/ctr/srv.h index c585ad50..0b1a6a29 100644 --- a/include/ctr/srv.h +++ b/include/ctr/srv.h @@ -2,7 +2,7 @@ #define SRV_H Result initSrv(); -Result exitSrv(); +void exitSrv(); Result srv_RegisterClient(Handle* handleptr); Result srv_getServiceHandle(Handle* handleptr, Handle* out, char* server); diff --git a/include/ctr/svc.h b/include/ctr/svc.h index 76af455a..cbfc0917 100644 --- a/include/ctr/svc.h +++ b/include/ctr/svc.h @@ -37,6 +37,7 @@ typedef enum{ Result svc_createThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stacktop, s32 threadpriority, s32 processorid); void svc_exitThread(); void svc_sleepThread(s64 ns); + Result svc_openThread(Handle* thread, Handle process, u32 threadId); Result svc_createMutex(Handle* mutex, bool initialLocked); Result svc_releaseMutex(Handle handle); Result svc_releaseSemaphore(s32* count, Handle semaphore, s32 releaseCount); @@ -60,12 +61,12 @@ typedef enum{ Result svc_restartDma(Handle h, void * dst, void const* src, unsigned int size, signed char flag); Result svc_kernelSetState(unsigned int Type, unsigned int Param0, unsigned int Param1, unsigned int Param2); - /** - * @brief Maps a block of process memory. - * @param process Handle of the process. - * @param destAddress Address of the mapped block in the current process. - * @param srcAddress Address of the mapped block in the source process. - * @param size Size of the block of the memory to map (truncated to a multiple of 0x1000 bytes). - */ + /** + * @brief Maps a block of process memory. + * @param process Handle of the process. + * @param destAddress Address of the mapped block in the current process. + * @param srcAddress Address of the mapped block in the source process. + * @param size Size of the block of the memory to map (truncated to a multiple of 0x1000 bytes). + */ Result svcMapProcessMemoryEx(Handle process, u32 destAddr, u32 srcAddr, u32 size); #endif diff --git a/include/gen.h b/include/gen.h deleted file mode 100644 index e69de29b..00000000 diff --git a/include/global.h b/include/global.h index 6c09fe64..302d6e88 100644 --- a/include/global.h +++ b/include/global.h @@ -1,6 +1,6 @@ #define IS_PLUGIN 0 -#define NTR_CFW_VERSION "NTR 3.6" +#define NTR_CFW_VERSION ((u8*)"NTR 3.6") #include "main.h" #include "memory.h" @@ -25,5 +25,5 @@ #include "func.h" #include "sharedfunc.h" -#include -#include \ No newline at end of file +#include "ns/ns.h" +#include "sys/socket.h" \ No newline at end of file diff --git a/include/main.h b/include/main.h index e72b0932..1aa590c9 100644 --- a/include/main.h +++ b/include/main.h @@ -2,7 +2,66 @@ #define MAIN_H #include "3dstypes.h" -#include "..\..\BootNTR\source\ntr_config.h" + +#define NTR_MEMMODE_DEFAULT (0) +#define NTR_MEMMODE_BASE (3) + +typedef struct NTR_CONFIG { + //NTR related configuration information. + u32 bootNTRVersion; + u32 isNew3DS; + u32 firmVersion; //3DS Firmware Version. (o3DS and n3DS firmware, not NTR version!) + u32 InterProcessDmaFinishState; //Interprocess Direct Memory Access Finish State. + u32 fsUserHandle; //File System Userland Application Process Handle, presumably? + u8 ntrFilePath[32]; //File path string, up to 32 characters long, null-terminating? + + //ARMv11 payload + u32 arm11BinStart; //Start address. + u32 arm11BinSize; //Payload size. + + //Input/Output + u32 IoBasePad; //Pad, as in the touchpad? + u32 IoBaseLcd; + u32 IoBasePdc; //I/O Base pointer to the device context. + + //Process Manager + u32 PMSvcRunAddr; //Process manager Service Run address. + u32 PMPid; //Process manager Process ID. + + //Home Menu + u32 HomeMenuPid; + u32 HomeMenuVersion; + + //NOTE(wedr): CSND:FlushDataCache and DSP:FlushDataCache both calls on this svc function. (CSND: CSound/CTRSound, DSP: Digital Signal Processor) + //CSND flushes the data within LINEAR virtual memory. DSP flushes within the application GSP (graphics system processor?) heap. + u32 HomeMenuInjectAddr; //Points to the svcFlushProcessDataCache function, according to Reisyukaku. + + //Home Screen + u32 HomeFSReadAddr; //Home File System Read Address. + u32 HomeFSUHandleAddr; //Home File System Userland Handle address. (Based on NS:U and APT:U, this is a guess. APT:A may be Applet:Admin, APT:S may be Applet:Service.) + u32 HomeCardUpdateInitAddr; + u32 HomeAptStartAppletAddr; //Home Applet Start Applet Address. + + //Control Memory Patch + u32 ControlMemoryPatchAddr1; + u32 ControlMemoryPatchAddr2; + + //Kernel Process + u32 KProcessHandleDataOffset; + u32 KProcessPIDOffset; + u32 KProcessCodesetOffset; + + //Kernel related + u32 KernelFreeSpaceAddr_Optional; + + //MMU Hack related + u32 KMMUHaxAddr; //Kernal MMU Hack Address + u32 KMMUHaxSize; //Kernel MMU Hack Size + + //Debugging purposes + u32 ShowDbgFunc; + u32 memMode; +} NTR_CONFIG; void createpad(void *counter, void *keyY, void *filename, u32 megabytes, u8 padnum); int main(); diff --git a/include/xprintf.h b/include/xprintf.h index ebccb580..1322b3e6 100644 --- a/include/xprintf.h +++ b/include/xprintf.h @@ -13,6 +13,7 @@ #if _USE_XFUNC_OUT +#include #define xdev_out(func) xfunc_out = (void(*)(unsigned char))(func) extern void (*xfunc_out)(unsigned char); void xputc (char c); @@ -21,6 +22,7 @@ void xfputs (void (*func)(unsigned char), const char* str); void xprintf (const char* fmt, ...); void xsprintf (char* buff, const char* fmt, ...); void xfprintf (void (*func)(unsigned char), const char* fmt, ...); +void xvprintf(const char* fmt, va_list arp); void put_dump (const void* buff, unsigned long addr, int len, int width); #define DW_CHAR sizeof(char) #define DW_SHORT sizeof(short) diff --git a/libc.a b/libc.a deleted file mode 100644 index 2887e5f2..00000000 Binary files a/libc.a and /dev/null differ diff --git a/libgcc.a b/libgcc.a deleted file mode 100644 index 34a74755..00000000 Binary files a/libgcc.a and /dev/null differ diff --git a/libm.a b/libm.a deleted file mode 100644 index db0b7780..00000000 Binary files a/libm.a and /dev/null differ diff --git a/source/2d.c b/source/2d.c index 4bf8c726..97b897d0 100644 --- a/source/2d.c +++ b/source/2d.c @@ -37,7 +37,10 @@ void paint_letter(u8 letter, int x, int y, char r, char g, char b, int screen){ int k; int c; unsigned char mask; - unsigned char* _letter; + + //Unused. + //unsigned char* _letter; + unsigned char l; if ((letter < 32) || (letter > 127)) { letter = '?'; @@ -57,6 +60,7 @@ void paint_letter(u8 letter, int x, int y, char r, char g, char b, int screen){ } } } + void paint_word(char* word, int x,int y, char r, char g, char b, int screen){ int tmp_x =x; int i; diff --git a/source/dsp/nightshift.c b/source/dsp/nightshift.c index d3dfa1d5..1c750d3e 100644 --- a/source/dsp/nightshift.c +++ b/source/dsp/nightshift.c @@ -94,29 +94,29 @@ BGRB GRBG RBGR /* #define NIGHT_SHIFT_TEMPLATE_B(name, level) static u32 name(u32 addr, u32 stride, u32 height, u32 format) { \ format &= 0x0f; \ - if (addr % 4 != 0) return 1; \ - u32 r; \ + if (addr % 4 != 0) return 1; \ + u32 r; \ if (format == 2) { \ - for (r = 0; r < height; r++) { \ - u16* sp = (u16*)addr; \ - u16* spEnd = (u16*)(addr + 240 * 2); \ - while (sp < spEnd) { \ - u32 pix; \ - REPEAT_8(NIGHT_SHIFT_RGB565_B(level)) \ - } \ - addr += stride; \ - } \ + for (r = 0; r < height; r++) { \ + u16* sp = (u16*)addr; \ + u16* spEnd = (u16*)(addr + 240 * 2); \ + while (sp < spEnd) { \ + u32 pix; \ + REPEAT_8(NIGHT_SHIFT_RGB565_B(level)) \ + } \ + addr += stride; \ + } \ } \ else if (format == 1) { \ - for (r = 0; r < height; r++) { \ - u8* sp = (u8*)addr; \ - u8* spEnd = (u8*)(addr + 240 * 3); \ - while (sp < spEnd) { \ - u32 pix; \ - REPEAT_4(NIGHT_SHIFT_RGB888_B(level)) \ - } \ - addr += stride; \ - } \ + for (r = 0; r < height; r++) { \ + u8* sp = (u8*)addr; \ + u8* spEnd = (u8*)(addr + 240 * 3); \ + while (sp < spEnd) { \ + u32 pix; \ + REPEAT_4(NIGHT_SHIFT_RGB888_B(level)) \ + } \ + addr += stride; \ + } \ } \ svc_flushProcessDataCache(0xffff8001, (u32)addr, stride * height); \ return 0; \ @@ -124,29 +124,29 @@ BGRB GRBG RBGR #define NIGHT_SHIFT_TEMPLATE_B_G(name, levelb, levelg) static u32 name(u32 addr, u32 stride, u32 height, u32 format) { \ format &= 0x0f; \ - if (addr % 4 != 0) return 1; \ - u32 r; \ + if (addr % 4 != 0) return 1; \ + u32 r; \ if (format == 2) { \ - for (r = 0; r < height; r++) { \ - u16* sp = (u16*)addr; \ - u16* spEnd = (u16*)(addr + 240 * 2); \ - while (sp < spEnd) { \ - u32 pix; \ - REPEAT_8(NIGHT_SHIFT_RGB565_B_G(levelb, levelg)) \ - } \ - addr += stride; \ - } \ + for (r = 0; r < height; r++) { \ + u16* sp = (u16*)addr; \ + u16* spEnd = (u16*)(addr + 240 * 2); \ + while (sp < spEnd) { \ + u32 pix; \ + REPEAT_8(NIGHT_SHIFT_RGB565_B_G(levelb, levelg)) \ + } \ + addr += stride; \ + } \ } \ else if (format == 1) { \ - for (r = 0; r < height; r++) { \ - u8* sp = (u8*)addr; \ - u8* spEnd = (u8*)(addr + 240 * 3); \ - while (sp < spEnd) { \ - u32 pix; \ - REPEAT_4(NIGHT_SHIFT_RGB888_B_G_UNALIGNED(levelb, levelg)); \ - } \ - addr += stride; \ - } \ + for (r = 0; r < height; r++) { \ + u8* sp = (u8*)addr; \ + u8* spEnd = (u8*)(addr + 240 * 3); \ + while (sp < spEnd) { \ + u32 pix; \ + REPEAT_4(NIGHT_SHIFT_RGB888_B_G_UNALIGNED(levelb, levelg)); \ + } \ + addr += stride; \ + } \ } \ svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32)addr, stride * height); \ return 0; \ @@ -158,57 +158,61 @@ NIGHT_SHIFT_TEMPLATE_B(plgNightShiftFramebufferLevel3, 3); NIGHT_SHIFT_TEMPLATE_B(plgNightShiftFramebufferLevel2, 2); NIGHT_SHIFT_TEMPLATE_B(plgNightShiftFramebufferLevel1, 1);*/ -static inline __attribute__((always_inline)) u32 plgNightShift3(u32 addr, u32 stride, u32 height, u32 format, u32 levelb, u32 levelg, u32 isAligned) { - format &= 0x0f; - u32 r; - if (format == 2) { - for (r = 0; r < height; r++) { - u16* sp = (u16*)addr; - u16* spEnd = (u16*)(addr + 240 * 2); - while (sp < spEnd) { - - if (isAligned) { - if (levelg) { - u32 pix; - REPEAT_8(NIGHT_SHIFT_RGB565_B_G(levelb, levelg)); - } else { - u32 pix; - REPEAT_8(NIGHT_SHIFT_RGB565_B(levelb)); - } - } else { - if (levelg) { - u16 pix, b, g; - REPEAT_8(NIGHT_SHIFT_RGB565_B_G_UNALIGNED(levelb, levelg)); - REPEAT_8(NIGHT_SHIFT_RGB565_B_G_UNALIGNED(levelb, levelg)); - } else { - u16 pix, b, g; - REPEAT_8(NIGHT_SHIFT_RGB565_B_UNALIGNED(levelb)); - REPEAT_8(NIGHT_SHIFT_RGB565_B_UNALIGNED(levelb)); - } - } +static inline __attribute__((always_inline)) u32 plgNightShift3(u32 addr, u32 stride, u32 height, u32 format, u32 levelb, u32 levelg, u32 isAligned) { + format &= 0x0f; + u32 r; + if (format == 2) { + for (r = 0; r < height; r++) { + u16* sp = (u16*) addr; + u16* spEnd = (u16*) (addr + 240 * 2); + while (sp < spEnd) { + + if (isAligned) { + if (levelg) { + u32 pix; + REPEAT_8(NIGHT_SHIFT_RGB565_B_G(levelb, levelg)); + } + else { + u32 pix; + REPEAT_8(NIGHT_SHIFT_RGB565_B(levelb)); + } + } + else { + if (levelg) { + u16 pix, b, g; + REPEAT_8(NIGHT_SHIFT_RGB565_B_G_UNALIGNED(levelb, levelg)); + REPEAT_8(NIGHT_SHIFT_RGB565_B_G_UNALIGNED(levelb, levelg)); + } + else { + u16 pix, b; // , g; + REPEAT_8(NIGHT_SHIFT_RGB565_B_UNALIGNED(levelb)); + REPEAT_8(NIGHT_SHIFT_RGB565_B_UNALIGNED(levelb)); + } + } + + } + addr += stride; + } + } + else if (format == 1) { + for (r = 0; r < height; r++) { + u8* sp = (u8*) addr; + u8* spEnd = (u8*) (addr + 240 * 3); + while (sp < spEnd) { + if (isAligned && (levelg == 0)) { + u32 pix; + REPEAT_4(NIGHT_SHIFT_RGB888_B(levelb)); + } + else { + REPEAT_4(NIGHT_SHIFT_RGB888_B_G_UNALIGNED(levelb, levelg)); + } - } - addr += stride; - } - } - else if (format == 1) { - for (r = 0; r < height; r++) { - u8* sp = (u8*)addr; - u8* spEnd = (u8*)(addr + 240 * 3); - while (sp < spEnd) { - if (isAligned && (levelg == 0)) { - u32 pix; - REPEAT_4(NIGHT_SHIFT_RGB888_B(levelb)); - } else { - REPEAT_4(NIGHT_SHIFT_RGB888_B_G_UNALIGNED(levelb, levelg)); - } - - } - addr += stride; - } - } - svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32)addr, stride * height); - return 0; + } + addr += stride; + } + } + svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32) addr, stride * height); + return 0; } static inline __attribute__((always_inline)) u32 plgScreenFilter(u32 addr, u32 stride, u32 height, u32 format, u32 type) { @@ -216,10 +220,10 @@ static inline __attribute__((always_inline)) u32 plgScreenFilter(u32 addr, u32 s u32 r; if (format == 2) { for (r = 0; r < height; r++) { - u16* sp = (u16*)addr; - u16* spEnd = (u16*)(addr + 240 * 2); + u16* sp = (u16*) addr; + u16* spEnd = (u16*) (addr + 240 * 2); while (sp < spEnd) { - u16 pix, b, g, r, gray; + u16 pix, gray; //g, b, r; if (type == 1) { REPEAT_4(INVERT_RGB565_UNALIGNED()); REPEAT_4(INVERT_RGB565_UNALIGNED()); @@ -237,8 +241,8 @@ static inline __attribute__((always_inline)) u32 plgScreenFilter(u32 addr, u32 s } else if (format == 1) { for (r = 0; r < height; r++) { - u8* sp = (u8*)addr; - u8* spEnd = (u8*)(addr + 240 * 3); + u8* sp = (u8*) addr; + u8* spEnd = (u8*) (addr + 240 * 3); while (sp < spEnd) { u16 gray; if (type == 1) { @@ -254,26 +258,26 @@ static inline __attribute__((always_inline)) u32 plgScreenFilter(u32 addr, u32 s addr += stride; } } - svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32)addr, stride * height); + svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32) addr, stride * height); return 0; } static inline __attribute__((always_inline)) u32 plgNightShift2(u32 addr, u32 stride, u32 height, u32 format, u32 isAligned) { if (g_plgInfo->nightShiftLevel == 1) { - return plgNightShift3(addr, stride, height, format, 1, 0, isAligned); + return plgNightShift3(addr, stride, height, format, 1, 0, isAligned); } if (g_plgInfo->nightShiftLevel == 2) { - return plgNightShift3(addr, stride, height, format, 2, 0, isAligned); + return plgNightShift3(addr, stride, height, format, 2, 0, isAligned); } if (g_plgInfo->nightShiftLevel == 3) { - return plgNightShift3(addr, stride, height, format, 3, 0, isAligned); + return plgNightShift3(addr, stride, height, format, 3, 0, isAligned); } if (g_plgInfo->nightShiftLevel == 4) { - return plgNightShift3(addr, stride, height, format, 3, 1, isAligned); + return plgNightShift3(addr, stride, height, format, 3, 1, isAligned); } if (g_plgInfo->nightShiftLevel == 5) { - return plgNightShift3(addr, stride, height, format, 4, 1, isAligned); + return plgNightShift3(addr, stride, height, format, 4, 1, isAligned); } if (g_plgInfo->nightShiftLevel == 6) { return plgScreenFilter(addr, stride, height, format, 1); @@ -285,8 +289,8 @@ static inline __attribute__((always_inline)) u32 plgNightShift2(u32 addr, u32 st } u32 plgNightShiftFramebuffer(u32 addr, u32 stride, u32 height, u32 format) { - if ((addr % 4 == 0) && (stride % 4 == 0)) { - return plgNightShift2(addr, stride, height, format, 1); - } - return plgNightShift2(addr, stride, height, format, 0); + if ((addr % 4 == 0) && (stride % 4 == 0)) { + return plgNightShift2(addr, stride, height, format, 1); + } + return plgNightShift2(addr, stride, height, format, 0); } \ No newline at end of file diff --git a/source/jpeg/jdatadst.c b/source/jpeg/jdatadst.c index c05bc559..02c910b7 100644 --- a/source/jpeg/jdatadst.c +++ b/source/jpeg/jdatadst.c @@ -69,13 +69,13 @@ typedef my_mem_destination_mgr *my_mem_dest_ptr; METHODDEF(void) init_destination(j_compress_ptr cinfo) { - showDbg("init_destination", 0, 0); - my_dest_ptr dest = (my_dest_ptr)cinfo->dest; + showDbg((u8*) "init_destination", 0, 0); + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; /* Allocate the output buffer --- it will be released when done with image */ dest->buffer = (JOCTET *) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - OUTPUT_BUF_SIZE * sizeof(JOCTET)); + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + OUTPUT_BUF_SIZE * sizeof(JOCTET)); dest->pub.next_output_byte = dest->buffer; dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; @@ -116,9 +116,9 @@ init_mem_destination(j_compress_ptr cinfo) METHODDEF(boolean) empty_output_buffer(j_compress_ptr cinfo) { - my_dest_ptr dest = (my_dest_ptr)cinfo->dest; + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + - /* if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) != (size_t)OUTPUT_BUF_SIZE) @@ -128,7 +128,7 @@ empty_output_buffer(j_compress_ptr cinfo) dest->pub.next_output_byte = dest->buffer; dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; - + return TRUE; } @@ -138,14 +138,14 @@ empty_mem_output_buffer(j_compress_ptr cinfo) { size_t nextsize; JOCTET *nextbuffer; - my_mem_dest_ptr dest = (my_mem_dest_ptr)cinfo->dest; + my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; /* Try to allocate new buffer with double size */ nextsize = dest->bufsize * 2; - nextbuffer = (JOCTET *)malloc(nextsize); + nextbuffer = (JOCTET *) malloc(nextsize); if (nextbuffer == NULL) ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); @@ -180,20 +180,19 @@ empty_mem_output_buffer(j_compress_ptr cinfo) METHODDEF(void) term_destination(j_compress_ptr cinfo) { - my_dest_ptr dest = (my_dest_ptr)cinfo->dest; + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; - /* - /* Write any data remaining in the buffer + /* Write any data remaining in the buffer */ if (datacount > 0) { if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount) ERREXIT(cinfo, JERR_FILE_WRITE); } fflush(dest->outfile); - /* Make sure we wrote the output file OK + /* Make sure we wrote the output file OK if (ferror(dest->outfile)) ERREXIT(cinfo, JERR_FILE_WRITE); - */ + */ if (datacount > 0) { rpSendBuffer(dest->buffer, datacount, 0x10); @@ -201,17 +200,16 @@ term_destination(j_compress_ptr cinfo) else { rpSendBuffer(dest->buffer, 1, 0x10); } - } #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) METHODDEF(void) term_mem_destination(j_compress_ptr cinfo) { - my_mem_dest_ptr dest = (my_mem_dest_ptr)cinfo->dest; + my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; *dest->outbuffer = dest->buffer; - *dest->outsize = (unsigned long)(dest->bufsize - dest->pub.free_in_buffer); + *dest->outsize = (unsigned long) (dest->bufsize - dest->pub.free_in_buffer); } #endif @@ -235,11 +233,11 @@ jpeg_stdio_dest(j_compress_ptr cinfo, FILE *outfile) */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */ cinfo->dest = (struct jpeg_destination_mgr *) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT, - sizeof(my_destination_mgr)); + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + sizeof(my_destination_mgr)); } - dest = (my_dest_ptr)cinfo->dest; + dest = (my_dest_ptr) cinfo->dest; dest->pub.init_destination = init_destination; dest->pub.empty_output_buffer = empty_output_buffer; dest->pub.term_destination = term_destination; @@ -264,7 +262,7 @@ jpeg_stdio_dest(j_compress_ptr cinfo, FILE *outfile) GLOBAL(void) jpeg_mem_dest(j_compress_ptr cinfo, -unsigned char **outbuffer, unsigned long *outsize) + unsigned char **outbuffer, unsigned long *outsize) { my_mem_dest_ptr dest; @@ -276,11 +274,11 @@ unsigned char **outbuffer, unsigned long *outsize) */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */ cinfo->dest = (struct jpeg_destination_mgr *) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT, - sizeof(my_mem_destination_mgr)); + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + sizeof(my_mem_destination_mgr)); } - dest = (my_mem_dest_ptr)cinfo->dest; + dest = (my_mem_dest_ptr) cinfo->dest; dest->pub.init_destination = init_mem_destination; dest->pub.empty_output_buffer = empty_mem_output_buffer; dest->pub.term_destination = term_mem_destination; @@ -290,7 +288,7 @@ unsigned char **outbuffer, unsigned long *outsize) if (*outbuffer == NULL || *outsize == 0) { /* Allocate initial buffer */ - dest->newbuffer = *outbuffer = (unsigned char *)malloc(OUTPUT_BUF_SIZE); + dest->newbuffer = *outbuffer = (unsigned char *) malloc(OUTPUT_BUF_SIZE); if (dest->newbuffer == NULL) ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); *outsize = OUTPUT_BUF_SIZE; diff --git a/source/jpeg/jerror.c b/source/jpeg/jerror.c index 4e14e2d8..9da9c38b 100644 --- a/source/jpeg/jerror.c +++ b/source/jpeg/jerror.c @@ -69,7 +69,7 @@ const char * const jpeg_std_message_table[] = { METHODDEF(void) error_exit (j_common_ptr cinfo) { - showDbg("error_exit", 0, 0); + showDbg((u8*) "error_exit", 0, 0); /* Always display the message */ (*cinfo->err->output_message) (cinfo); @@ -98,7 +98,7 @@ error_exit (j_common_ptr cinfo) METHODDEF(void) output_message (j_common_ptr cinfo) { - showDbg("output_message", 0, 0); + showDbg((u8*) "output_message", 0, 0); char buffer[JMSG_LENGTH_MAX]; /* Create the message */ @@ -110,8 +110,8 @@ output_message (j_common_ptr cinfo) MB_OK | MB_ICONERROR); #else /* Send it to stderr, adding a newline */ - nsDbgPrint("%s\n", buffer); - showDbg("%s\n", buffer, 0); + nsDbgPrint((const char*) "%s\n", buffer); + showDbg((u8*) "%s\n", (u32) buffer, 0); #endif } diff --git a/source/libctru/srv.c b/source/libctru/srv.c index a81cf596..083d8d51 100644 --- a/source/libctru/srv.c +++ b/source/libctru/srv.c @@ -14,7 +14,7 @@ Result initSrv() return srv_RegisterClient(&srvHandle); } -Result exitSrv() +void exitSrv() { if(srvHandle)svc_closeHandle(srvHandle); srvHandle = 0; diff --git a/source/main.c b/source/main.c index 2e569334..7059fa28 100644 --- a/source/main.c +++ b/source/main.c @@ -6,6 +6,12 @@ u32 nsDefaultMemRegion = 0x200; void sleep(s64 ns); +void nsInit(); +void nsInitDebug(); +void kDoKernelHax(); +void plgShowMainMenu(); +void remotePlayMain(); +int screenshotMain(); u32* threadStack = 0; NTR_CONFIG backupNtrConfig = { 0 }; @@ -62,7 +68,7 @@ u32 initValuesFromFIRM() { u32 initValuesFromHomeMenu() { u32 t = 0; - u32 hProcess, ret; + u32 hProcess; // , ret; ntrConfig->HomeMenuVersion = 0; svc_openProcess(&hProcess, ntrConfig->HomeMenuPid); copyRemoteMemory(CURRENT_PROCESS_HANDLE, &t, hProcess, (void*)0x00200000, 4); @@ -99,7 +105,10 @@ u32 initValuesFromHomeMenu() { ntrConfig->HomeFSUHandleAddr = 0x00278E4C; ntrConfig->HomeAptStartAppletAddr = 0x00129BFC; } -final: + + //Unused label. + //final: + svc_closeHandle(hProcess); return ntrConfig->HomeMenuVersion; } @@ -121,7 +130,7 @@ void setExitFlag() { void onFatalError(u32 lr) { acquireVideo(); -showDbg("fatal. LR: %08x", lr, 0); +showDbg((u8*) "fatal. LR: %08x", lr, 0); releaseVideo(); } @@ -136,12 +145,12 @@ void viewFile(FS_archive arc, u8 * path) { u32 entryCount = 0; buf[0] = 0; - FS_path dirPath = (FS_path){ PATH_CHAR, strlen(path) + 1, path }; + FS_path dirPath = (FS_path){ PATH_CHAR, strlen((const char*) path) + 1, path }; Handle dirHandle = 0; u32 ret; ret = FSUSER_OpenDirectory(fsUserHandle, &dirHandle, arc, dirPath); if (ret != 0) { - xsprintf(buf, "FSUSER_OpenDirectory failed, ret=%08x", ret); + xsprintf((char*) buf, (const char*) "FSUSER_OpenDirectory failed, ret=%08x", ret); showMsg(buf); return; } @@ -163,7 +172,7 @@ void viewFile(FS_archive arc, u8 * path) { entryCount += 1; } if (entryCount == 0) { - showMsg("no file found."); + showMsg((u8*) "no file found."); return; } while (1) { @@ -171,7 +180,7 @@ void viewFile(FS_archive arc, u8 * path) { if (r == -1) { break; } - xsprintf((u8*)entry, "%s%s", path, captions[r]); + xsprintf((char*) entry, (const char*) "%s%s", path, captions[r]); viewFile(arc, (u8*)entry); } FSDIR_Close(dirHandle); @@ -184,11 +193,11 @@ void fileManager() { arc = (FS_archive){ 0x567890AB, (FS_path){ PATH_EMPTY, 1, (u8*)"" } }; u32 ret = FSUSER_OpenArchive(fsUserHandle, &arc); if (ret != 0) { - xsprintf(buf, "openArchive failed, ret=%08x", ret); + xsprintf((char*) buf, (const char*) "openArchive failed, ret=%08x", ret); showMsg(buf); return; } - viewFile(arc, "/"); + viewFile(arc, (u8*) "/"); FSUSER_CloseArchive(fsUserHandle, &arc); } @@ -205,7 +214,7 @@ u32 HomeFSReadCallback(u32 a1, u32 a2, u32 a3, u32 a4, u32 buffer, u32 size) { ret = ((FSReadTypeDef)((void*)HomeFSReadHook.callCode))(a1, a2, a3, a4, buffer, size); if (size == 0x36C0) { if ((*((u32*)(buffer))) == 0x48444d53) { // 'SMDH' - nsDbgPrint("patching smdh\n"); + nsDbgPrint((const char*) "patching smdh\n"); *((u32*)(buffer + 0x2018)) = 0x7fffffff; } } @@ -221,7 +230,7 @@ u32 isFileExist(char* fileName) { Handle hFile = 0; u32 ret; - FS_path testPath = (FS_path){ PATH_CHAR, strlen(fileName) + 1, fileName }; + FS_path testPath = (FS_path){ PATH_CHAR, strlen((const char*) fileName) + 1, (u8*) fileName }; ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 1, 0); if (ret != 0) { return 0; @@ -239,10 +248,12 @@ void magicKillProcess(u32 pid) { } u32 KProcess = kGetKProcessByHandle(hProcess); u32 t = 0; - kmemcpy(&t, KProcess + 4, 4); - //showDbg("refcount: %08x", t, 0); + kmemcpy(&t, (void*) (KProcess + 4), 4); + //showDbg((u8*) "refcount: %08x", t, 0); t = 1; - kmemcpy(KProcess + 4, &t, 4); + volatile uintptr_t temp = (KProcess + 4); + void* vPtr = (void*) temp; + kmemcpy(vPtr, &t, 4); svc_closeHandle(hProcess); } @@ -275,9 +286,11 @@ u32 HomeSetMemorySizeCallback(u32 size) { } void threadStart() { - volatile vu32* ptr; - Handle testFileHandle = 0; - u32 i, ret; + //Unused + //volatile vu32* ptr; + //Handle testFileHandle = 0; + + u32 ret; // , i; int waitCnt = 0; rtInitHook(&HomeFSReadHook, ntrConfig->HomeFSReadAddr, (u32)HomeFSReadCallback); @@ -336,7 +349,7 @@ void initConfigureMemory() { ret = svc_controlMemory(&outAddr, NS_CONFIGURE_ADDR, 0, 0x1000, 3, 3); if (ret != 0) { - showMsg("init cfg memory failed"); + showMsg((u8*) "init cfg memory failed"); return; } @@ -367,7 +380,8 @@ void injectToHomeMenu() { Handle hProcess = 0; svc_openProcess(&hProcess, ntrConfig->HomeMenuPid); - u32* bootArgs = arm11BinStart + 4; + volatile uintptr_t temp = (arm11BinStart + 4); + u32* bootArgs = (u32*) temp; bootArgs[0] = 1; nsAttachProcess(hProcess, ntrConfig->HomeMenuInjectAddr, &cfg, 1); @@ -452,7 +466,7 @@ void initFromSoc() { int main() { StartMode = _BootArgs[0]; - //showDbg("", 0, sizeof(NS_CONFIG)); + //showDbg((u8*) "", 0, sizeof(NS_CONFIG)); if (StartMode == 0) { // load from bootNTR if (_BootArgs[1] == 0xb00d) { @@ -465,18 +479,19 @@ int main() { if ((ntrConfig->HomeMenuVersion == 0) || (ntrConfig->firmVersion == 0)) { - showMsg("firmware or homemenu version not supported"); - dumpCode(0xdff80000, 0x80000, "/axiwram.dmp"); + showMsg((u8*) "firmware or homemenu version not supported"); + dumpCode(0xdff80000, 0x80000, (u8*) "/axiwram.dmp"); svc_sleepThread(1000000000); - dumpRemoteProcess(0, "/pid0.dmp", 0x00100000); - dumpRemoteProcess(2, "/pid2.dmp", 0x00100000); - dumpRemoteProcess(3, "/pid3.dmp", 0x00100000); - dumpRemoteProcess(0xf, "/pidf.dmp", 0x00100000); - showMsg("current firmware not supported. \n" + dumpRemoteProcess(0, (u8*) "/pid0.dmp", 0x00100000); + dumpRemoteProcess(2, (u8*) "/pid2.dmp", 0x00100000); + dumpRemoteProcess(3, (u8*) "/pid3.dmp", 0x00100000); + dumpRemoteProcess(0xf, (u8*) "/pidf.dmp", 0x00100000); + showMsg((u8*) "current firmware not supported. \n" "please send feedback to\n" " cell9@yandex.com."); - u32 kversion = *(unsigned int *)0x1FF80000; - showDbg("kversion: %08x", kversion, 0); + volatile uintptr_t temp = 0x1FF80000; + u32 kversion = *(u32*) temp; + showDbg((u8*) "kversion: %08x", kversion, 0); if ((_BootArgs[1] != 0xb00d)) { while (1) { @@ -487,12 +502,12 @@ int main() { return 0; } else { - showMsg("do kernelhax"); + showMsg((u8*) "do kernelhax"); kDoKernelHax(); - showMsg("kernelhax done"); + showMsg((u8*) "kernelhax done"); doSomethingInitSrv(); disp(100, 0x1ff0000); - showDbg("homemenu ver: %08x", ntrConfig->HomeMenuVersion, 0); + showDbg((u8*) "homemenu ver: %08x", ntrConfig->HomeMenuVersion, 0); injectToHomeMenu(); } diff --git a/source/memory.c b/source/memory.c index bd045331..378f38ae 100644 --- a/source/memory.c +++ b/source/memory.c @@ -63,7 +63,7 @@ u32 byte_to_bit_string(u8 byte, char* ret, int max_len){ }*/ u32 byte_to_string(u8 byte, char* ret, int max_len){ - if (max_len < 3) return; + if (max_len < 3) return 0; u32 mask = 0x0F; u32 i; @@ -77,7 +77,7 @@ u32 byte_to_string(u8 byte, char* ret, int max_len){ } u32 u32_to_string(u32 byte, char* ret, int max_len){ - if (max_len < 9) return; + if (max_len < 9) return 0; u32 mask = 0x0000000F; u32 i; diff --git a/source/ns/ns.c b/source/ns/ns.c index 79e8786c..c44d3d5c 100644 --- a/source/ns/ns.c +++ b/source/ns/ns.c @@ -7,14 +7,13 @@ #include #include "fastlz.h" #include "jpeglib.h" -#include "gen.h" NS_CONTEXT* g_nsCtx = 0; NS_CONFIG* g_nsConfig; - u32 heapStart, heapEnd; +void disp(u32 t, u32 cl); void doSendDelay(u32 time) { vu32 i; @@ -24,7 +23,7 @@ void doSendDelay(u32 time) { } void tje_log(char* str) { - nsDbgPrint("tje: %s\n", str); + nsDbgPrint((const char*) "tje: %s\n", str); } #define RP_MODE_TOP_BOT_10X 0 @@ -54,7 +53,7 @@ u64 rpMinIntervalBetweenPacketsInTick = 0; -void* rpMalloc( u32 size) +void* rpMalloc(u32 size) { void* ret = rpAllocBuff + rpAllocBuffOffset; @@ -63,25 +62,25 @@ void* rpMalloc( u32 size) totalSize += 32 - (totalSize % 32); } if (rpAllocBuffRemainSize < totalSize) { - nsDbgPrint("bad alloc, size: %d\n", size); + nsDbgPrint((const char*) "bad alloc, size: %d\n", size); if (rpAllocDebug) { - showDbg("bad alloc, size: %d\n", size, 0); + showDbg((u8*) "bad alloc, size: %d\n", size, 0); } return 0; } rpAllocBuffOffset += totalSize; rpAllocBuffRemainSize -= totalSize; memset(ret, 0, totalSize); - nsDbgPrint("alloc size: %d, ptr: %08x\n", size, ret); + nsDbgPrint((const char*) "alloc size: %d, ptr: %08x\n", size, ret); if (rpAllocDebug) { - showDbg("alloc size: %d, ptr: %08x\n", size, ret); + showDbg((u8*) "alloc size: %d, ptr: %08x\n", size, (u32) ret); } return ret; } void rpFree(void* ptr) { - nsDbgPrint("free: %08x\n", ptr); + nsDbgPrint((const char*) "free: %08x\n", ptr); return; } @@ -98,7 +97,7 @@ void nsDbgPutc(char ch) { void nsDbgPrint( /* Put a formatted string to the default device */ const char* fmt, /* Pointer to the format string */ ... /* Optional arguments */ - ) +) { va_list arp; @@ -117,27 +116,29 @@ void nsDbgPrint( /* Put a formatted string to the default device */ } int nsSendPacketHeader() { - g_nsCtx->remainDataLen = g_nsCtx->packetBuf.dataLen; rtSendSocket(g_nsCtx->hSocket, (u8*)&(g_nsCtx->packetBuf), sizeof(NS_PACKET)); + return 0; } int nsSendPacketData(u8* buf, u32 size) { if (g_nsCtx->remainDataLen < size) { - showDbg("send remain < size: %08x, %08x", g_nsCtx->remainDataLen, size); + showDbg((u8*) "send remain < size: %08x, %08x", g_nsCtx->remainDataLen, size); return -1; } g_nsCtx->remainDataLen -= size; rtSendSocket(g_nsCtx->hSocket, buf, size); + return 0; } int nsRecvPacketData(u8* buf, u32 size) { if (g_nsCtx->remainDataLen < size) { - showDbg("recv remain < size: %08x, %08x", g_nsCtx->remainDataLen, size); + showDbg((u8*) "recv remain < size: %08x, %08x", g_nsCtx->remainDataLen, size); return -1; } g_nsCtx->remainDataLen -= size; rtRecvSocket(g_nsCtx->hSocket, buf, size); + return 0; } extern u8 *image_buf; @@ -145,41 +146,41 @@ void allocImageBuf(); /* void remotePlayMain2() { -int udp_sock = socket(AF_INET, SOCK_DGRAM, 0); -struct sockaddr_in addr; -int ret, i; + int udp_sock = socket(AF_INET, SOCK_DGRAM, 0); + struct sockaddr_in addr; + int ret, i; -if (udp_sock < 0) { -nsDbgPrint("socket failed: %d", udp_sock); -return; -} -addr.sin_family = AF_INET; -addr.sin_port = rtIntToPortNumber(9001); -addr.sin_addr.s_addr = 0x6602a8c0; // __builtin_bswap32(0xc0a80266); - -nsDbgPrint("bind done 22"); -allocImageBuf(); -while (1) { -ret = sendto(udp_sock, image_buf, 1300, 0, &addr, sizeof(addr)); -} + if (udp_sock < 0) { + nsDbgPrint((const char*) "socket failed: %d", udp_sock); + return; + } + addr.sin_family = AF_INET; + addr.sin_port = rtIntToPortNumber(9001); + addr.sin_addr.s_addr = 0x6602a8c0; // __builtin_bswap32(0xc0a80266); + + nsDbgPrint((const char*) "bind done 22"); + allocImageBuf(); + while (1) { + ret = sendto(udp_sock, image_buf, 1300, 0, &addr, sizeof(addr)); + } -final: -closesocket(udp_sock); + final: + closesocket(udp_sock); } u32 nwmSocPutFrameRaw(Handle handle, u8* frame, u32 size) { -u32* cmdbuf = getThreadCommandBuffer(); -u32 ret; -cmdbuf[0] = 0x10042; -cmdbuf[1] = size; -cmdbuf[2] = (((u32)size) << 14) | 2; -cmdbuf[3] = frame; -ret = svc_sendSyncRequest(handle); -if (ret != 0) { -return ret; -} -return cmdbuf[1]; + u32* cmdbuf = getThreadCommandBuffer(); + u32 ret; + cmdbuf[0] = 0x10042; + cmdbuf[1] = size; + cmdbuf[2] = (((u32)size) << 14) | 2; + cmdbuf[3] = frame; + ret = svc_sendSyncRequest(handle); + if (ret != 0) { + return ret; + } + return cmdbuf[1]; }*/ RT_HOOK nwmValParamHook; @@ -208,7 +209,7 @@ sendPacketTypedef nwmSendPacket = 0; uint16_t ip_checksum(void* vdata, size_t length) { // Cast the data pointer to one that can be indexed. - char* data = (char*)vdata; + char* data = (char*) vdata; size_t i; // Initialise the accumulator. uint32_t acc = 0xffff; @@ -239,21 +240,21 @@ uint16_t ip_checksum(void* vdata, size_t length) { int initUDPPacket(int dataLen) { dataLen += 8; - *(u16*)(remotePlayBuffer + 0x22 + 8) = htons(8000); // src port - *(u16*)(remotePlayBuffer + 0x24 + 8) = htons(8001); // dest port - *(u16*)(remotePlayBuffer + 0x26 + 8) = htons(dataLen); - *(u16*)(remotePlayBuffer + 0x28 + 8) = 0; // no checksum + *(u16*) (remotePlayBuffer + 0x22 + 8) = htons(8000); // src port + *(u16*) (remotePlayBuffer + 0x24 + 8) = htons(8001); // dest port + *(u16*) (remotePlayBuffer + 0x26 + 8) = htons(dataLen); + *(u16*) (remotePlayBuffer + 0x28 + 8) = 0; // no checksum dataLen += 20; - *(u16*)(remotePlayBuffer + 0x10 + 8) = htons(dataLen); - *(u16*)(remotePlayBuffer + 0x12 + 8) = 0xaf01; // packet id is a random value since we won't use the fragment - *(u16*)(remotePlayBuffer + 0x14 + 8) = 0x0040; // no fragment - *(u16*)(remotePlayBuffer + 0x16 + 8) = 0x1140; // ttl 64, udp - *(u16*)(remotePlayBuffer + 0x18 + 8) = 0; - *(u16*)(remotePlayBuffer + 0x18 + 8) = ip_checksum(remotePlayBuffer + 0xE + 8, 0x14); + *(u16*) (remotePlayBuffer + 0x10 + 8) = htons(dataLen); + *(u16*) (remotePlayBuffer + 0x12 + 8) = 0xaf01; // packet id is a random value since we won't use the fragment + *(u16*) (remotePlayBuffer + 0x14 + 8) = 0x0040; // no fragment + *(u16*) (remotePlayBuffer + 0x16 + 8) = 0x1140; // ttl 64, udp + *(u16*) (remotePlayBuffer + 0x18 + 8) = 0; + *(u16*) (remotePlayBuffer + 0x18 + 8) = ip_checksum(remotePlayBuffer + 0xE + 8, 0x14); dataLen += 22; - *(u16*)(remotePlayBuffer + 12) = htons(dataLen); + *(u16*) (remotePlayBuffer + 12) = htons(dataLen); return dataLen; } @@ -273,13 +274,13 @@ int getBppForFormat(int format) { int bpp; format &= 0x0f; - if (format == 0){ + if (format == 0) { bpp = 4; } - else if (format == 1){ + else if (format == 1) { bpp = 3; } - else{ + else { bpp = 2; } return bpp; @@ -287,9 +288,9 @@ int getBppForFormat(int format) { typedef struct _BLIT_CONTEXT { int width, height, format, src_pitch; int x, y; - u8* src; + u8* src; int outformat, bpp; - u32 bytesInColumn ; + u32 bytesInColumn; u32 blankInColumn; u8* transformDst; @@ -309,13 +310,13 @@ typedef struct _BLIT_CONTEXT { void remotePlayBlitInit(BLIT_CONTEXT* ctx, int width, int height, int format, int src_pitch, u8* src) { format &= 0x0f; - if (format == 0){ + if (format == 0) { ctx->bpp = 4; } - else if (format == 1){ + else if (format == 1) { ctx->bpp = 3; } - else{ + else { ctx->bpp = 2; } ctx->bytesInColumn = ctx->bpp * height; @@ -334,7 +335,7 @@ void remotePlayBlitInit(BLIT_CONTEXT* ctx, int width, int height, int format, in ctx->outformat = GL_RGB565_LE; } ctx->compressDst = 0; - ctx->compressedSize; + ctx->compressedSize = 0; ctx->frameCount = 0; ctx->lastSize = 0; } @@ -346,7 +347,7 @@ vu64 rpLastSendTick = 0; void rpSendBuffer(u8* buf, u32 size, u32 flag) { if (rpAllocDebug) { - showDbg("sendbuf: %08x, %d", buf, size); + showDbg((u8*) "sendbuf: %08x, %d", (u32) &buf[0], size); return; } vu64 tickDiff; @@ -376,24 +377,26 @@ void rpSendBuffer(u8* buf, u32 size, u32 flag) { int remotePlayBlitCompressed(BLIT_CONTEXT* ctx) { - int blockSize = 16; int bpp = ctx->bpp; int width = ctx->width; int height = ctx->height; - int pitch = ctx->src_pitch; - u32 px; - u16 tmp; - u8* blitBuffer = ctx->src; u8* sp = ctx->src; u8* dp = ctx->transformDst; - int x = 0, y = 0, i, j; - u8* rowp = ctx->src; - u8* blkp; - u8* pixp; + int x = 0, y = 0; // , i, j; + + //Unused. + //int blockSize = 16; + //int pitch = ctx->src_pitch; + //u32 px; + //u16 tmp; + //u8* blitBuffer = ctx->src; + //u8* rowp = ctx->src; + //u8* blkp; + //u8* pixp; ctx->directCompress = 0; - if ((bpp == 3) || (bpp == 4)){ + if ((bpp == 3) || (bpp == 4)) { ctx->directCompress = 1; return 0; /* @@ -413,7 +416,7 @@ int remotePlayBlitCompressed(BLIT_CONTEXT* ctx) { svc_sleepThread(500000); for (x = 0; x < width; x++) { for (y = 0; y < height; y++) { - u16 pix = *(u16*)sp; + u16 pix = *(u16*) sp; dp[0] = ((pix >> 11) & 0x1f) << 3; dp[1] = ((pix >> 5) & 0x3f) << 2; dp[2] = (pix & 0x1f) << 3; @@ -459,7 +462,7 @@ void rpCompressAndSendPacket(BLIT_CONTEXT* ctx) { dataBuf[1] = ctx->isTop; dataBuf[2] = 2; dataBuf[3] = 0; - + cinfo.image_width = ctx->height; /* image width and height, in pixels */ cinfo.image_height = ctx->width; cinfo.input_components = 3; @@ -506,8 +509,10 @@ int remotePlayBlit(BLIT_CONTEXT* ctx) { int width = ctx->width; int height = ctx->height; u8 *dp; - u32 px; - u16 tmp; + + //Unused + //u32 px; + //u16 tmp; /* if (blankInColumn == 0) { @@ -528,19 +533,19 @@ int remotePlayBlit(BLIT_CONTEXT* ctx) { dp[0] = ctx->src[0]; dp[1] = ctx->src[1]; dp += 2; - ctx->src+= bpp; + ctx->src += bpp; ctx->y += 1; } } else { - + while (ctx->y < height) { if (dp - dataBuf >= PACKET_SIZE) { return dp - dataBuf; } - *((u16*)(dp)) = ((u16)((ctx->src[2] >> 3) & 0x1f) << 11) | - ((u16)((ctx->src[1] >> 2) & 0x3f) << 5) | - ((u16)((ctx->src[0] >> 3) & 0x1f)); + *((u16*) (dp)) = ((u16) ((ctx->src[2] >> 3) & 0x1f) << 11) | + ((u16) ((ctx->src[1] >> 2) & 0x3f) << 5) | + ((u16) ((ctx->src[0] >> 3) & 0x1f)); dp += 2; ctx->src += bpp; ctx->y += 1; @@ -555,13 +560,12 @@ int remotePlayBlit(BLIT_CONTEXT* ctx) { void remotePlayKernelCallback() { - - - - u32 ret; - u32 fbP2VOffset = 0xc0000000; u32 current_fb; + //Unused + //u32 ret; + //u32 fbP2VOffset = 0xc0000000; + tl_fbaddr[0] = REG(IoBasePdc + 0x468); tl_fbaddr[1] = REG(IoBasePdc + 0x46c); bl_fbaddr[0] = REG(IoBasePdc + 0x568); @@ -606,9 +610,9 @@ Handle rpHDma[2], rpHandleHome, rpHandleGame; u32 rpGameFCRAMBase = 0; void rpInitDmaHome() { - u32 dmaConfig[20] = { 0 }; + //u32 dmaConfig[20] = { 0 }; svc_openProcess(&rpHandleHome, 0xf); - + return; } Handle rpGetGameHandle() { @@ -618,7 +622,7 @@ Handle rpGetGameHandle() { for (i = 0x28; i < 0x38; i++) { int ret = svc_openProcess(&hProcess, i); if (ret == 0) { - nsDbgPrint("game process: %x\n", i); + nsDbgPrint((const char*) "game process: %x\n", i); rpHandleGame = hProcess; break; } @@ -661,35 +665,38 @@ int isInFCRAM(u32 phys) { void rpCaptureScreen(int isTop) { u8 dmaConfig[80] = { 0, 0, 4 }; - u32 bufSize = isTop? (tl_pitch * 400) : (bl_pitch * 320); - u32 phys = isTop ? tl_current : bl_current; - u32 dest = imgBuffer; + u32 bufSize = isTop ? (tl_pitch * 400) : (bl_pitch * 320); + uintptr_t phys = isTop ? tl_current : bl_current; + uintptr_t dest = *(uintptr_t*) imgBuffer; Handle hProcess = rpHandleHome; + uintptr_t temp = 0x0; - int ret; svc_invalidateProcessDataCache(CURRENT_PROCESS_HANDLE, dest, bufSize); svc_closeHandle(rpHDma[isTop]); rpHDma[isTop] = 0; + //Unused + //int ret; + if (isInVRAM(phys)) { - svc_startInterProcessDma(&rpHDma[isTop], CURRENT_PROCESS_HANDLE, - dest, hProcess, 0x1F000000 + (phys - 0x18000000), bufSize, dmaConfig); + temp = 0x1F000000 + (phys - 0x18000000); + svc_startInterProcessDma(&rpHDma[isTop], CURRENT_PROCESS_HANDLE, + (void*) dest, hProcess, (void*) temp, bufSize, (u32*) dmaConfig); return; } else if (isInFCRAM(phys)) { hProcess = rpGetGameHandle(); if (hProcess) { - ret = svc_startInterProcessDma(&rpHDma[isTop], CURRENT_PROCESS_HANDLE, - dest, hProcess, rpGameFCRAMBase + (phys - 0x20000000), bufSize, dmaConfig); + temp = rpGameFCRAMBase + (phys - 0x20000000); + svc_startInterProcessDma(&rpHDma[isTop], CURRENT_PROCESS_HANDLE, + (void*) dest, hProcess, (void*) temp, bufSize, (u32*) dmaConfig); } return; } svc_sleepThread(1000000000); - - } @@ -706,7 +713,10 @@ void remotePlaySendFrames() { u32 currentUpdating = isPriorityTop; u32 frameCount = 0; - u8 cnt; + + //Unused + //u8 cnt; + BLIT_CONTEXT topContext = { 0 }, botContext = { 0 }; while (1) { @@ -729,7 +739,7 @@ void remotePlaySendFrames() { topContext.compressDst = 0; topContext.transformDst = imgBuffer + 0x00150000; topContext.reset = 1; - topContext.id = (u8)currentTopId; + topContext.id = (u8) currentTopId; topContext.isTop = 1; remotePlayBlitCompressed(&topContext); rpCompressAndSendPacket(&topContext); @@ -742,7 +752,7 @@ void remotePlaySendFrames() { botContext.compressDst = 0; botContext.transformDst = imgBuffer + 0x00150000; botContext.reset = 1; - botContext.id = (u8)currentBottomId; + botContext.id = (u8) currentBottomId; botContext.isTop = 0; remotePlayBlitCompressed(&botContext); rpCompressAndSendPacket(&botContext); @@ -751,7 +761,8 @@ void remotePlaySendFrames() { } void remotePlayThreadStart() { - u32 i, ret; + //Unused + //u32 i, ret; rpCurrentMode = g_nsConfig->startupInfo[8]; rpQuality = g_nsConfig->startupInfo[9]; @@ -761,12 +772,15 @@ void remotePlayThreadStart() { } rpMinIntervalBetweenPacketsInTick = (1000000 / (rpQosValueInBytes / PACKET_SIZE)) * SYSTICK_PER_US; - u8* dataBuf = remotePlayBuffer + 0x2a + 8; - u32 remainSize; + //Unused + //uintptr_t temp = (uintptr_t) &remotePlayBuffer[0]; + //u8* dataBuf = (u8*) (temp + 0x2a + 8); - imgBuffer = plgRequestMemorySpecifyRegion(0x00200000, 1); + //Unused + //u32 remainSize; - rpAllocBuff = plgRequestMemorySpecifyRegion(0x00100000, 1); + imgBuffer = (u8*) ((uintptr_t) plgRequestMemorySpecifyRegion(0x00200000, 1)); + rpAllocBuff = (u8*) ((uintptr_t) plgRequestMemorySpecifyRegion(0x00100000, 1)); if (rpAllocBuff) { rpAllocBuffRemainSize = 0x00100000; } @@ -775,7 +789,7 @@ void remotePlayThreadStart() { } rpInitJpegCompress(); - nsDbgPrint("imgBuffer: %08x\n", imgBuffer); + nsDbgPrint((const char*) "imgBuffer: %08x\n", imgBuffer); if (!imgBuffer) { goto final; } @@ -788,18 +802,21 @@ void remotePlayThreadStart() { svc_exitThread(); } -int nwmValParamCallback(u8* buf, int buflen) { +u32 nwmValParamCallback(u8* buf, int buflen) { //rtDisableHook(&nwmValParamHook); - int i; + + //Unused + //int i; + u32* threadStack; int stackSize = 0x10000; int ret; Handle hThread; /* if (buf[31] != 6) { - nsDbgPrint("buflen: %d\n", buflen); + nsDbgPrint((const char*) "buflen: %d\n", buflen); for (i = 0; i < buflen; i++) { - nsDbgPrint("%02x ", buf[i]); + nsDbgPrint((const char*) "%02x ", buf[i]); } }*/ @@ -807,14 +824,14 @@ int nwmValParamCallback(u8* buf, int buflen) { return 0; } if (buf[0x17 + 0x8] == 6) { - if ((*(u16*)(&buf[0x22 + 0x8])) == 0x401f) { // src port 8000 + if ((*(u16*) (&buf[0x22 + 0x8])) == 0x401f) { // src port 8000 remotePlayInited = 1; memcpy(remotePlayBuffer, buf, 0x22 + 8); packetLen = initUDPPacket(PACKET_SIZE); - threadStack = plgRequestMemory(stackSize); - ret = svc_createThread(&hThread, (void*)remotePlayThreadStart, 0, &threadStack[(stackSize / 4) - 10], 0x10, 2); + threadStack = (u32*) ((uintptr_t) plgRequestMemory(stackSize)); + ret = svc_createThread(&hThread, &remotePlayThreadStart, 0, &threadStack[(stackSize / 4) - 10], 0x10, 2); if (ret != 0) { - nsDbgPrint("Create RemotePlay Thread Failed: %08x\n", ret); + nsDbgPrint((const char*) "Create RemotePlay Thread Failed: %08x\n", ret); } } } @@ -822,10 +839,9 @@ int nwmValParamCallback(u8* buf, int buflen) { } void remotePlayMain() { - nwmSendPacket = g_nsConfig->startupInfo[12]; - rtInitHookThumb(&nwmValParamHook, g_nsConfig->startupInfo[11], nwmValParamCallback); + memcpy(&nwmSendPacket, &g_nsConfig->startupInfo[12], sizeof(sendPacketTypedef)); + rtInitHookThumb(&nwmValParamHook, (u32) ((uintptr_t) &g_nsConfig->startupInfo[11]), (u32) ((uintptr_t) nwmValParamCallback)); rtEnableHook(&nwmValParamHook); - } @@ -850,7 +866,7 @@ void testJpeg() { cinfo.image_width = 240; cinfo.image_height = 400; cinfo.input_components = 3; - showDbg("start compress", 0, 0); + showDbg((u8*) "start compress", 0, 0); jpeg_start_compress(&cinfo, TRUE); } @@ -862,7 +878,7 @@ void tickTest() { u32 time1 = svc_getSystemTick(); svc_sleepThread(1000000000); u32 time2 = svc_getSystemTick(); - nsDbgPrint("%08x, %08x\n", time1, time2); + nsDbgPrint((const char*) "%08x, %08x\n", time1, time2); } */ @@ -871,15 +887,15 @@ int nsHandleRemotePlay() { NS_PACKET* pac = &(g_nsCtx->packetBuf); u32 mode = pac->args[0]; u32 quality = pac->args[1]; - u32 qosValue = pac->args[2]; - + u32 qosValue = pac->args[2]; + if (!((quality >= 10) && (quality <= 100))) { - nsDbgPrint("illegal quality\n"); + nsDbgPrint((const char*) "illegal quality\n"); goto final; } if (nsIsRemotePlayStarted) { - nsDbgPrint("remote play already started\n"); + nsDbgPrint((const char*) "remote play already started\n"); goto final; } nsIsRemotePlayStarted = 1; @@ -887,7 +903,7 @@ int nsHandleRemotePlay() { Handle hProcess; u32 ret; u32 pid = 0x1a; - u32 remotePC = 0x001231d0; + uintptr_t remotePC = 0x001231d0; NS_CONFIG cfg; memset(&cfg, 0, sizeof(NS_CONFIG)); @@ -897,7 +913,7 @@ int nsHandleRemotePlay() { cfg.startupInfo[10] = qosValue; ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - nsDbgPrint("openProcess failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "openProcess failed: %08x\n", ret, 0); hProcess = 0; goto final; } @@ -906,7 +922,7 @@ int nsHandleRemotePlay() { u8 desiredHeader[16] = { 0x04, 0x00, 0x2D, 0xE5, 0x4F, 0x00, 0x00, 0xEF, 0x00, 0x20, 0x9D, 0xE5, 0x00, 0x10, 0x82, 0xE5 }; u8 buf[16] = { 0 }; if (!(ntrConfig->isNew3DS)) { - nsDbgPrint("remoteplay is available on new3ds only\n"); + nsDbgPrint((const char*) "remoteplay is available on new3ds only\n"); goto final; } @@ -924,7 +940,7 @@ int nsHandleRemotePlay() { remotePC = 0x123394; } - copyRemoteMemory(CURRENT_PROCESS_HANDLE, buf, hProcess, remotePC, 16); + copyRemoteMemory(CURRENT_PROCESS_HANDLE, buf, hProcess, (void*) remotePC, 16); svc_sleepThread(100000000); if (memcmp(buf, desiredHeader, sizeof(desiredHeader)) == 0) { isFirmwareSupported = 1; @@ -932,18 +948,21 @@ int nsHandleRemotePlay() { } } if (!isFirmwareSupported) { - nsDbgPrint("remoteplay is not supported on current firmware\n"); + nsDbgPrint((const char*) "remoteplay is not supported on current firmware\n"); goto final; } setCpuClockLock(3); - nsDbgPrint("cpu was locked on 804MHz, L2 Enabled\n"); - nsDbgPrint("starting remoteplay...\n"); + nsDbgPrint((const char*) "cpu was locked on 804MHz, L2 Enabled\n"); + nsDbgPrint((const char*) "starting remoteplay...\n"); nsAttachProcess(hProcess, remotePC, &cfg, 1); final: if (hProcess != 0) { svc_closeHandle(hProcess); } + + //Does nothing other than return 0. + return 0; } void nsHandleSaveFile() { @@ -957,10 +976,10 @@ void nsHandleSaveFile() { buf[0x200] = 0; remain -= 0x200; - FS_path testPath = (FS_path){ PATH_CHAR, strlen(buf) + 1, buf }; + FS_path testPath = (FS_path) { PATH_CHAR, strlen((const char*) buf) + 1, buf }; ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 7, 0); if (ret != 0) { - showDbg("openFile failed: %08x", ret, 0); + showDbg((u8*) "openFile failed: %08x", ret, 0); return; } @@ -970,13 +989,13 @@ void nsHandleSaveFile() { t = remain; } nsRecvPacketData(g_nsCtx->gBuff, t); - FSFILE_Write(hFile, &tmp, off, (u32*)g_nsCtx->gBuff, t, 0); + FSFILE_Write(hFile, &tmp, off, (u32*) g_nsCtx->gBuff, t, 0); remain -= t; off += t; } svc_closeHandle(hFile); - nsDbgPrint("saved to %s successfully\n", buf); + nsDbgPrint((const char*) "saved to %s successfully\n", buf); } int nsFindFreeBreakPoint() { @@ -991,27 +1010,27 @@ int nsFindFreeBreakPoint() { void nsEnableBreakPoint(int id) { NS_BREAKPOINT* bp = &(g_nsCtx->breakPoint[id]); if (bp->isEnabled) { - nsDbgPrint("bp %d already enabled\n", id); + nsDbgPrint((const char*) "bp %d already enabled\n", id); return; } bp->isEnabled = 1; if ((bp->type == NS_BPTYPE_CODE) || (bp->type == NS_BPTYPE_CODEONESHOT)) { rtEnableHook(&bp->hook); } - nsDbgPrint("bp %d enabled\n", id); + nsDbgPrint((const char*) "bp %d enabled\n", id); } void nsDisableBreakPoint(int id) { NS_BREAKPOINT* bp = &(g_nsCtx->breakPoint[id]); if (!bp->isEnabled) { - nsDbgPrint("bp %d already disabled\n", id); + nsDbgPrint((const char*) "bp %d already disabled\n", id); return; } bp->isEnabled = 0; if ((bp->type == NS_BPTYPE_CODE) || (bp->type == NS_BPTYPE_CODEONESHOT)) { rtDisableHook(&bp->hook); } - nsDbgPrint("bp %d disabled\n", id); + nsDbgPrint((const char*) "bp %d disabled\n", id); } void nsBreakPointCallback(u32 regs, u32 bpid, u32 regs2) { @@ -1027,7 +1046,7 @@ void nsBreakPointCallback(u32 regs, u32 bpid, u32 regs2) { //update bp status rtAcquireLock(&(g_nsCtx->breakPointStatusLock)); - bpStatus->regs = (vu32*)regs; + bpStatus->regs = (vu32*) regs; bpStatus->bpid = bpid; bpStatus->resumeFlag = 0; rtReleaseLock(&(g_nsCtx->breakPointStatusLock)); @@ -1073,13 +1092,13 @@ u32 nsInitCodeBreakPoint(int id) { u32 pos = (sizeof(buf) / 4); ret = rtCheckRemoteMemoryRegionSafeForWrite(getCurrentProcessHandle(), bp->addr, 8); - if (ret != 0){ - nsDbgPrint("rtCheckRemoteMemoryRegionSafeForWrite failed :%08x\n", ret); + if (ret != 0) { + nsDbgPrint((const char*) "rtCheckRemoteMemoryRegionSafeForWrite failed :%08x\n", ret); return ret; } if (bp->type == NS_BPTYPE_CODE) { - retAddr = (u32)hk->callCode; + retAddr = (u32) hk->callCode; } if (bp->type == NS_BPTYPE_CODEONESHOT) { @@ -1088,12 +1107,12 @@ u32 nsInitCodeBreakPoint(int id) { memcpy(bp->stubCode, buf, sizeof(buf)); bp->stubCode[pos] = id; - bp->stubCode[pos + 1] = (u32)nsBreakPointCallback; - bp->stubCode[pos + 2] = (u32)retAddr; + bp->stubCode[pos + 1] = (u32) nsBreakPointCallback; + bp->stubCode[pos + 2] = (u32) retAddr; rtFlushInstructionCache(bp->stubCode, 16 * 4); - rtInitHook(&(bp->hook), bp->addr, (u32)(bp->stubCode)); + rtInitHook(&(bp->hook), bp->addr, (u32) (bp->stubCode)); svc_sleepThread(100000000); return 0; } @@ -1109,13 +1128,13 @@ void nsInitBreakPoint(int id, u32 addr, int type) { if ((type == NS_BPTYPE_CODE) || (type == NS_BPTYPE_CODEONESHOT)) { ret = nsInitCodeBreakPoint(id); if (ret == 0) { - nsDbgPrint("code breakpoint, id: %d, addr: %08x\n", id, addr); + nsDbgPrint((const char*) "code breakpoint, id: %d, addr: %08x\n", id, addr); nsEnableBreakPoint(id); return; } } bp->type = NS_BPTYPE_UNUSED; - nsDbgPrint("init breakpoint failed.\n"); + nsDbgPrint((const char*) "init breakpoint failed.\n"); } void nsHandleQueryHandle() { @@ -1127,25 +1146,27 @@ void nsHandleQueryHandle() { ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - nsDbgPrint("openprocess failed.\n"); + nsDbgPrint((const char*) "openprocess failed.\n"); return; } - //showDbg("hprocess: %08x", hProcess, 0); + //showDbg((u8*) "hprocess: %08x", hProcess, 0); u32 pKProcess = kGetKProcessByHandle(hProcess); u32 pHandleTable; - kmemcpy(&pHandleTable, pKProcess + KProcessHandleDataOffset, 4); - //showDbg("pHandleTable: %08x", pHandleTable, 0); - kmemcpy(buf, pHandleTable, sizeof(buf)); + uintptr_t temp = pKProcess + KProcessHandleDataOffset; + kmemcpy(&pHandleTable, (void*) temp, 4); + //showDbg((u8*) "pHandleTable: %08x", pHandleTable, 0); + kmemcpy(buf, &pHandleTable, sizeof(buf)); for (i = 0; i < 400; i += 2) { u32 ptr = buf[i + 1]; if (ptr) { - u32 handleHigh = *((u16*)&(buf[i])); - u32 handleLow = i / 2; + uintptr_t temp = (uintptr_t) &buf[i]; + u16 handleHigh = (u16) temp; + u16 handleLow = i / 2; u32 handle = (handleHigh << 15) | handleLow; - nsDbgPrint("h: %08x, p: %08x\n", handle, ptr); + nsDbgPrint((const char*) "h: %08x, p: %08x\n", handle, ptr); } } - nsDbgPrint("done"); + nsDbgPrint((const char*) "done"); svc_closeHandle(hProcess); } @@ -1159,20 +1180,20 @@ void nsHandleBreakPoint() { if (method == 1) { // add id = nsFindFreeBreakPoint(); - nsDbgPrint("freeid: %d\n", id); + nsDbgPrint((const char*) "freeid: %d\n", id); if (id == -1) { return; } nsInitBreakPoint(id, addr, type); } if (method == 4) { // resume - nsDbgPrint("set resume flag"); + nsDbgPrint((const char*) "set resume flag"); g_nsCtx->breakPointStatus.resumeFlag = 1; g_nsCtx->isBreakPointHandled = 0; } if (bpid >= MAX_BREAKPOINT) { - nsDbgPrint("invalid bpid\n"); + nsDbgPrint((const char*) "invalid bpid\n"); return; } @@ -1191,43 +1212,43 @@ void nsHandleReload() { u32 ret, outAddr; u32 hFile, size; u64 size64; - u8* fileName = "/arm11.bin"; + u8* fileName = (u8*) "/arm11.bin"; u32 tmp; - typedef (*funcType)(); + typedef void(*funcType)(); g_nsConfig->initMode = 1; closesocket(g_nsCtx->hSocket); closesocket(g_nsCtx->hListenSocket); - FS_path testPath = (FS_path){ PATH_CHAR, strlen(fileName) + 1, fileName }; + FS_path testPath = (FS_path) { PATH_CHAR, strlen((const char*) fileName) + 1, fileName }; ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 7, 0); if (ret != 0) { - showDbg("openFile failed: %08x", ret, 0); + showDbg((u8*) "openFile failed: %08x", ret, 0); return; } ret = FSFILE_GetSize(hFile, &size64); if (ret != 0) { - showDbg("FSFILE_GetSize failed: %08x", ret, 0); + showDbg((u8*) "FSFILE_GetSize failed: %08x", ret, 0); return; } size = size64; size = rtAlignToPageSize(size); - ret = svc_controlMemory((u32*)&outAddr, 0, 0, size, 0x10003, 3); + ret = svc_controlMemory((u32*) &outAddr, 0, 0, size, 0x10003, 3); if (ret != 0) { - showDbg("svc_controlMemory failed: %08x", ret, 0); + showDbg((u8*) "svc_controlMemory failed: %08x", ret, 0); return; } - ret = FSFILE_Read(hFile, &tmp, 0, (u32*)outAddr, size); + ret = FSFILE_Read(hFile, &tmp, 0, (u32*) outAddr, size); if (ret != 0) { - showDbg("FSFILE_Read failed: %08x", ret, 0); + showDbg((u8*) "FSFILE_Read failed: %08x", ret, 0); return; } - ret = protectMemory((u32*)outAddr, size); + ret = protectMemory((u32*) outAddr, size); if (ret != 0) { - showDbg("protectMemory failed: %08x", ret, 0); + showDbg((u8*) "protectMemory failed: %08x", ret, 0); return; } - ((funcType)outAddr)(); + ((funcType) outAddr)(); svc_exitThread(); } @@ -1235,34 +1256,35 @@ void nsHandleListProcess() { u32 pids[100]; u8 pname[20]; u32 tid[4]; - u32 pidCount; - u32 i, ret; + s32 pidCount; + u32 ret; + s32 i; u32 kpobj; ret = svc_getProcessList(&pidCount, pids, 100); if (ret != 0) { - nsDbgPrint("getProcessList failed: %08x\n", ret); + nsDbgPrint((const char*) "getProcessList failed: %08x\n", ret); return; } for (i = 0; i < pidCount; i++) { ret = getProcessInfo(pids[i], pname, tid, &kpobj); if (ret != 0) { - nsDbgPrint("getProcessInfo failed: %08x\n", ret); + nsDbgPrint((const char*) "getProcessInfo failed: %08x\n", ret); } - nsDbgPrint("pid: 0x%08x, pname: %8s, tid: %08x%08x, kpobj: %08x\n", pids[i], pname, tid[1], tid[0], kpobj); + nsDbgPrint((const char*) "pid: 0x%08x, pname: %8s, tid: %08x%08x, kpobj: %08x\n", pids[i], pname, tid[1], tid[0], kpobj); } - nsDbgPrint("end of process list.\n"); + nsDbgPrint((const char*) "end of process list.\n"); } void printMemLayout(Handle hProcess, u32 base, u32 limit) { u32 ret, isValid = 0, isLastValid = 0; u32 lastAddr = 0; while (base < limit) { - ret = protectRemoteMemory(hProcess, (void*)base, 0x1000); + ret = protectRemoteMemory(hProcess, (void*) base, 0x1000); isValid = (ret == 0); if (isValid != isLastValid) { if (isLastValid) { - nsDbgPrint("%08x - %08x , size: %08x\n", lastAddr, base - 1, base - lastAddr); + nsDbgPrint((const char*) "%08x - %08x , size: %08x\n", lastAddr, base - 1, base - lastAddr); } lastAddr = base; @@ -1274,21 +1296,24 @@ void printMemLayout(Handle hProcess, u32 base, u32 limit) { void nsHandleMemLayout() { NS_PACKET* pac = &(g_nsCtx->packetBuf); u32 pid = pac->args[0]; - u32 isLastValid = 0, lastAddr = 0; - u32 isValid; - u32 base = 0x00100000; + + //Unused + //u32 isLastValid = 0, lastAddr = 0; + //u32 isValid; + //u32 base = 0x00100000; + u32 ret, hProcess; ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - nsDbgPrint("openProcess failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "openProcess failed: %08x\n", ret, 0); hProcess = 0; goto final; } - nsDbgPrint("valid memregions:\n"); + nsDbgPrint((const char*) "valid memregions:\n"); printMemLayout(hProcess, 0x00100000, 0x1F601000); printMemLayout(hProcess, 0x30000000, 0x40000000); - nsDbgPrint("end of memlayout.\n"); + nsDbgPrint((const char*) "end of memlayout.\n"); final: if (hProcess != 0) { svc_closeHandle(hProcess); @@ -1301,9 +1326,12 @@ void nsHandleWriteMem() { u32 pid = pac->args[0]; u32 addr = pac->args[1]; u32 size = pac->args[2]; - u32 isLastValid = 0, lastAddr = 0; - u32 isValid; - u32 base, remain; + + //Unused + //u32 isLastValid = 0, lastAddr = 0; + //u32 isValid; + + u32 remain; //, base; u32 ret, hProcess; if (pid == -1) { @@ -1312,7 +1340,7 @@ void nsHandleWriteMem() { else { ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - nsDbgPrint("openProcess failed: %08x, pid: %08x\n", ret, pid); + nsDbgPrint((const char*) "openProcess failed: %08x, pid: %08x\n", ret, pid); hProcess = 0; goto final; } @@ -1320,7 +1348,7 @@ void nsHandleWriteMem() { if (addr < 0x20000000) { ret = rtCheckRemoteMemoryRegionSafeForWrite(hProcess, addr, size); if (ret != 0) { - nsDbgPrint("rtCheckRemoteMemoryRegionSafeForWrite failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "rtCheckRemoteMemoryRegionSafeForWrite failed: %08x\n", ret, 0); goto final; } } @@ -1333,23 +1361,23 @@ void nsHandleWriteMem() { nsRecvPacketData(g_nsCtx->gBuff, tmpsize); if (pid == -1) { if (addr > 0x20000000) { - kmemcpy((void*)addr, g_nsCtx->gBuff, tmpsize); + kmemcpy((void*) addr, g_nsCtx->gBuff, tmpsize); } else { - memcpy((void*)addr, g_nsCtx->gBuff, tmpsize); + memcpy((void*) addr, g_nsCtx->gBuff, tmpsize); } } else { - ret = copyRemoteMemory(hProcess, (void*)addr, 0xffff8001, g_nsCtx->gBuff, tmpsize); + ret = copyRemoteMemory(hProcess, (void*) addr, 0xffff8001, g_nsCtx->gBuff, tmpsize); if (ret != 0) { - nsDbgPrint("copyRemoteMemory failed: %08x, addr: %08x\n", ret, addr); + nsDbgPrint((const char*) "copyRemoteMemory failed: %08x, addr: %08x\n", ret, addr); } } addr += tmpsize; remain -= tmpsize; } - nsDbgPrint("finished"); + nsDbgPrint((const char*) "finished"); final: if (hProcess != 0) { if (pid != -1) { @@ -1363,9 +1391,12 @@ void nsHandleReadMem() { u32 pid = pac->args[0]; u32 addr = pac->args[1]; u32 size = pac->args[2]; - u32 isLastValid = 0, lastAddr = 0; - u32 isValid; - u32 base, remain; + + //Unused + //u32 isLastValid = 0, lastAddr = 0; + //u32 isValid; + + u32 remain; //, base u32 ret, hProcess; if (pid == -1) { @@ -1374,7 +1405,7 @@ void nsHandleReadMem() { else { ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - nsDbgPrint("openProcess failed: %08x, pid: %08x\n", ret, pid); + nsDbgPrint((const char*) "openProcess failed: %08x, pid: %08x\n", ret, pid); hProcess = 0; goto final; } @@ -1382,7 +1413,7 @@ void nsHandleReadMem() { if (addr < 0x20000000) { ret = rtCheckRemoteMemoryRegionSafeForWrite(hProcess, addr, size); if (ret != 0) { - nsDbgPrint("rtCheckRemoteMemoryRegionSafeForWrite failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "rtCheckRemoteMemoryRegionSafeForWrite failed: %08x\n", ret, 0); goto final; } } @@ -1396,24 +1427,24 @@ void nsHandleReadMem() { } if (pid == -1) { if (addr > 0x20000000) { - kmemcpy(g_nsCtx->gBuff, (void*)addr, tmpsize); + kmemcpy(g_nsCtx->gBuff, (void*) addr, tmpsize); } - else{ - memcpy(g_nsCtx->gBuff, (void*)addr, tmpsize); + else { + memcpy(g_nsCtx->gBuff, (void*) addr, tmpsize); } } else { - ret = copyRemoteMemory(0xffff8001, g_nsCtx->gBuff, hProcess, (void*)addr, tmpsize); + ret = copyRemoteMemory(0xffff8001, g_nsCtx->gBuff, hProcess, (void*) addr, tmpsize); if (ret != 0) { - nsDbgPrint("copyRemoteMemory failed: %08x, addr: %08x\n", ret, addr); + nsDbgPrint((const char*) "copyRemoteMemory failed: %08x, addr: %08x\n", ret, addr); } } nsSendPacketData(g_nsCtx->gBuff, tmpsize); addr += tmpsize; remain -= tmpsize; } - nsDbgPrint("finished"); + nsDbgPrint((const char*) "finished"); final: if (hProcess != 0) { if (pid != -1) { @@ -1425,9 +1456,13 @@ void nsHandleReadMem() { u32 nsGetPCToAttachProcess(u32 hProcess) { - u32 handle, ret; - NS_PACKET* pac = &(g_nsCtx->packetBuf); - u32 pid = pac->args[0]; + u32 ret; + + //Unused + //NS_PACKET* pac = &(g_nsCtx->packetBuf); + //u32 handle; + //u32 pid = pac->args[0]; + u32 tids[100]; u32 tidCount, i, j; u32 ctx[400]; @@ -1437,7 +1472,7 @@ u32 nsGetPCToAttachProcess(u32 hProcess) { ret = svc_getThreadList(&tidCount, tids, 100, hProcess); if (ret != 0) { - nsDbgPrint("getThreadList failed: %08x\n", ret); + nsDbgPrint((const char*) "getThreadList failed: %08x\n", ret); return 0; } for (i = 0; i < tidCount; i++) { @@ -1448,24 +1483,24 @@ u32 nsGetPCToAttachProcess(u32 hProcess) { lr[i] = ctx[14]; } - nsDbgPrint("recommend pc:\n"); + nsDbgPrint((const char*) "recommend pc:\n"); for (i = 0; i < tidCount; i++) { for (j = 0; j < tidCount; j++) { if ((i != j) && (pc[i] == pc[j])) break; } if (j >= tidCount) { - nsDbgPrint("%08x\n", pc[i]); + nsDbgPrint((const char*) "%08x\n", pc[i]); if (!addr) addr = pc[i]; } } - nsDbgPrint("recommend lr:\n"); + nsDbgPrint((const char*) "recommend lr:\n"); for (i = 0; i < tidCount; i++) { for (j = 0; j < tidCount; j++) { if ((i != j) && (lr[i] == lr[j])) break; } if (j >= tidCount) { - nsDbgPrint("%08x\n", lr[i]); + nsDbgPrint((const char*) "%08x\n", lr[i]); if (!addr) addr = lr[i]; } } @@ -1473,39 +1508,42 @@ u32 nsGetPCToAttachProcess(u32 hProcess) { } void nsHandleListThread() { - u32 handle, ret; + //Unused + //u32 handle; + //u32 pKThread; + //u32 pContext; + + u32 ret = 0; NS_PACKET* pac = &(g_nsCtx->packetBuf); Handle hProcess; u32 pid = pac->args[0]; u32 tids[100]; u32 tidCount, i, j; u32 ctx[400]; - u32 hThread; - u32 pKThread; - u32 pContext; + u32 hThread = 0; ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - nsDbgPrint("openProcess failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "openProcess failed: %08x\n", ret, 0); hProcess = 0; goto final; } ret = svc_getThreadList(&tidCount, tids, 100, hProcess); if (ret != 0) { - nsDbgPrint("getThreadList failed: %08x\n", ret); + nsDbgPrint((const char*) "getThreadList failed: %08x\n", ret); return; } for (i = 0; i < tidCount; i++) { u32 tid = tids[i]; - nsDbgPrint("tid: 0x%08x\n", tid); + nsDbgPrint((const char*) "tid: 0x%08x\n", tid); memset(ctx, 0x33, sizeof(ctx)); rtGetThreadReg(hProcess, tid, ctx); - nsDbgPrint("pc: %08x, lr: %08x\n", ctx[15], ctx[14]); + nsDbgPrint((const char*) "pc: %08x, lr: %08x\n", ctx[15], ctx[14]); for (j = 0; j < 32; j++) { - nsDbgPrint("%08x ", ctx[j]); + nsDbgPrint((const char*) "%08x ", ctx[j]); } - nsDbgPrint("\n"); + nsDbgPrint((const char*) "\n"); svc_closeHandle(hThread); } @@ -1525,19 +1563,23 @@ u32 nsAttachProcess(Handle hProcess, u32 remotePC, NS_CONFIG *cfg, int sysRegion u32 baseAddr = NS_CONFIGURE_ADDR; u32 stackSize = 0x4000; u32 totalSize; - u32 handle, ret, outAddr; + u32 ret; + + //Unused + //u32 handle, outAddr; + u32 tmp[20]; u32 arm11StartAddress; arm11StartAddress = baseAddr + 0x1000 + stackSize; - buf = (u32*)arm11BinStart; + buf = (u32*) arm11BinStart; size = arm11BinSize; - nsDbgPrint("buf: %08x, size: %08x\n", buf, size); + nsDbgPrint((const char*) "buf: %08x, size: %08x\n", buf, size); if (!buf) { - nsDbgPrint("arm11 not loaded\n"); - return; + nsDbgPrint((const char*) "arm11 not loaded\n"); + return 0; } totalSize = size + stackSize + 0x1000; @@ -1551,31 +1593,31 @@ u32 nsAttachProcess(Handle hProcess, u32 remotePC, NS_CONFIG *cfg, int sysRegion } if (ret != 0) { - nsDbgPrint("mapRemoteMemory failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "mapRemoteMemory failed: %08x\n", ret, 0); } // set rwx - ret = protectRemoteMemory(hProcess, (void*)baseAddr, totalSize); + ret = protectRemoteMemory(hProcess, (void*) baseAddr, totalSize); if (ret != 0) { - nsDbgPrint("protectRemoteMemory failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "protectRemoteMemory failed: %08x\n", ret, 0); goto final; } // load arm11.bin code at arm11StartAddress - ret = copyRemoteMemory(hProcess, (void*)arm11StartAddress, arm11BinProcess, buf, size); + ret = copyRemoteMemory(hProcess, (void*) arm11StartAddress, arm11BinProcess, buf, size); if (ret != 0) { - nsDbgPrint("copyRemoteMemory(1) failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "copyRemoteMemory(1) failed: %08x\n", ret, 0); goto final; } if (remotePC == 0) { remotePC = nsGetPCToAttachProcess(hProcess); } - nsDbgPrint("remotePC: %08x\n", remotePC, 0); + nsDbgPrint((const char*) "remotePC: %08x\n", remotePC, 0); if (remotePC == 0) { goto final; } ret = rtCheckRemoteMemoryRegionSafeForWrite(hProcess, remotePC, 8); if (ret != 0) { - nsDbgPrint("rtCheckRemoteMemoryRegionSafeForWrite failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "rtCheckRemoteMemoryRegionSafeForWrite failed: %08x\n", ret, 0); goto final; } @@ -1584,26 +1626,26 @@ u32 nsAttachProcess(Handle hProcess, u32 remotePC, NS_CONFIG *cfg, int sysRegion cfg->initMode = NS_INITMODE_FROMHOOK; // store original 8-byte code - ret = copyRemoteMemory(0xffff8001, &(cfg->startupInfo[0]), hProcess, (void*)remotePC, 8); + ret = copyRemoteMemory(0xffff8001, &(cfg->startupInfo[0]), hProcess, (void*) remotePC, 8); if (ret != 0) { - nsDbgPrint("copyRemoteMemory(3) failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "copyRemoteMemory(3) failed: %08x\n", ret, 0); goto final; } cfg->startupInfo[2] = remotePC; memcpy(&(cfg->ntrConfig), ntrConfig, sizeof(NTR_CONFIG)); // copy cfg structure to remote process - ret = copyRemoteMemory(hProcess, (void*)baseAddr, 0xffff8001, cfg, sizeof(NS_CONFIG)); + ret = copyRemoteMemory(hProcess, (void*) baseAddr, 0xffff8001, cfg, sizeof(NS_CONFIG)); if (ret != 0) { - nsDbgPrint("copyRemoteMemory(2) failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "copyRemoteMemory(2) failed: %08x\n", ret, 0); goto final; } // write hook instructions to remote process tmp[0] = 0xe51ff004; tmp[1] = arm11StartAddress; - ret = copyRemoteMemory(hProcess, (void*)remotePC, 0xffff8001, &tmp, 8); + ret = copyRemoteMemory(hProcess, (void*) remotePC, 0xffff8001, &tmp, 8); if (ret != 0) { - nsDbgPrint("copyRemoteMemory(4) failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "copyRemoteMemory(4) failed: %08x\n", ret, 0); goto final; } @@ -1628,12 +1670,12 @@ void nsHandleAttachProcess() { } ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - nsDbgPrint("openProcess failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "openProcess failed: %08x\n", ret, 0); hProcess = 0; goto final; } nsAttachProcess(hProcess, remotePC, &cfg, 0); - nsDbgPrint("will listen at port %d \n", pid + 5000); + nsDbgPrint((const char*) "will listen at port %d \n", pid + 5000); final: if (hProcess != 0) { svc_closeHandle(hProcess); @@ -1644,12 +1686,12 @@ void nsHandleAttachProcess() { void nsPrintRegs(u32* regs) { u32 i; - nsDbgPrint("cpsr:%08x ", regs[0]); - nsDbgPrint("lr:%08x sp:%08x\n", regs[14], (u32)(regs)+14 * 4); + nsDbgPrint((const char*) "cpsr:%08x ", regs[0]); + nsDbgPrint((const char*) "lr:%08x sp:%08x\n", regs[14], (u32) (regs) +14 * 4); for (i = 0; i <= 12; i++) { - nsDbgPrint("r%d:%08x ", i, regs[1 + i]); + nsDbgPrint((const char*) "r%d:%08x ", i, regs[1 + i]); } - nsDbgPrint("\n"); + nsDbgPrint((const char*) "\n"); } void nsUpdateDebugStatus() { @@ -1665,8 +1707,8 @@ void nsUpdateDebugStatus() { } if ((isActived) && (!g_nsCtx->isBreakPointHandled)) { - nsDbgPrint("breakpoint %d hit\n", bpStatus.bpid); - nsPrintRegs((u32*)bpStatus.regs); + nsDbgPrint((const char*) "breakpoint %d hit\n", bpStatus.bpid); + nsPrintRegs((u32*) bpStatus.regs); } g_nsCtx->isBreakPointHandled = isActived; } @@ -1676,7 +1718,7 @@ void nsHandlePacket() { g_nsCtx->remainDataLen = pac->dataLen; if (pac->cmd == NS_CMD_SAYHELLO) { disp(100, 0x100ff00); - nsDbgPrint("hello"); + nsDbgPrint((const char*) "hello"); return; } @@ -1749,7 +1791,7 @@ void nsHandlePacket() { void nsMainLoop() { - s32 listen_sock, ret, tmp, sockfd; + s32 listen_sock, ret, sockfd; //, tmp struct sockaddr_in addr; @@ -1772,12 +1814,12 @@ void nsMainLoop() { ret = bind(listen_sock, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { - showDbg("bind failed: %08x", ret, 0); + showDbg((u8*) "bind failed: %08x", ret, 0); return; } ret = listen(listen_sock, 1); if (ret < 0) { - showDbg("listen failed: %08x", ret, 0); + showDbg((u8*) "listen failed: %08x", ret, 0); return; } @@ -1796,12 +1838,12 @@ void nsMainLoop() { while (1) { ret = rtRecvSocket(sockfd, (u8*)&(g_nsCtx->packetBuf), sizeof(NS_PACKET)); if (ret != sizeof(NS_PACKET)) { - nsDbgPrint("rtRecvSocket failed: %08x", ret, 0); + nsDbgPrint((const char*) "rtRecvSocket failed: %08x", ret, 0); break; } NS_PACKET* pac = &(g_nsCtx->packetBuf); if (pac->magic != 0x12345678) { - nsDbgPrint("broken protocol: %08x, %08x", pac->magic, pac->seq); + nsDbgPrint((const char*) "broken protocol: %08x, %08x", pac->magic, pac->seq); break; } nsUpdateDebugStatus(); @@ -1819,15 +1861,15 @@ void nsThreadStart() { #define STACK_SIZE 0x4000 void nsInitDebug() { - xfunc_out = (void*)nsDbgPutc; + xfunc_out = (void*) nsDbgPutc; rtInitLock(&(g_nsConfig->debugBufferLock)); - g_nsConfig->debugBuf = (u8*)(NS_CONFIGURE_ADDR + 0x0900); + g_nsConfig->debugBuf = (u8*) (NS_CONFIGURE_ADDR + 0x0900); g_nsConfig->debugBufSize = 0xf0; g_nsConfig->debugPtr = 0; g_nsConfig->debugReady = 1; } -void nsInit(u32 initType) { +void nsInit() { u32 socuSharedBufferSize; u32 bufferSize; u32 ret, outAddr; @@ -1839,7 +1881,7 @@ void nsInit(u32 initType) { - //showDbg("nsInit", 0, 0); + //showDbg((u8*) "nsInit", 0, 0); /* while(1) { @@ -1861,22 +1903,22 @@ void nsInit(u32 initType) { ret = svc_controlMemory(&outAddr, base, 0, bufferSize, NS_DEFAULT_MEM_REGION + 3, 3); } if (ret != 0) { - showDbg("svc_controlMemory failed: %08x", ret, 0); + showDbg((u8*) "svc_controlMemory failed: %08x", ret, 0); return; } } ret = rtCheckRemoteMemoryRegionSafeForWrite(getCurrentProcessHandle(), base, bufferSize); if (ret != 0) { - showDbg("rtCheckRemoteMemoryRegionSafeForWrite failed: %08x", ret, 0); + showDbg((u8*) "rtCheckRemoteMemoryRegionSafeForWrite failed: %08x", ret, 0); } if (!srvHandle) { initSrv(); } if (g_nsConfig->hSOCU == 0) { - ret = SOC_Initialize((u32*)outAddr, socuSharedBufferSize); + ret = SOC_Initialize((u32*) outAddr, socuSharedBufferSize); if (ret != 0) { - showDbg("SOC_Initialize failed: %08x", ret, 0); + showDbg((u8*) "SOC_Initialize failed: %08x", ret, 0); return; } g_nsConfig->hSOCU = SOCU_handle; @@ -1886,7 +1928,7 @@ void nsInit(u32 initType) { } - g_nsCtx = (void*)(outAddr + socuSharedBufferSize); + g_nsCtx = (void*) (outAddr + socuSharedBufferSize); memset(g_nsCtx, 0, sizeof(NS_CONTEXT)); @@ -1911,13 +1953,12 @@ void nsInit(u32 initType) { return; } - threadStack = (u32*)(outAddr + socuSharedBufferSize + rtAlignToPageSize(sizeof(NS_CONTEXT))); + threadStack = (u32*) (outAddr + socuSharedBufferSize + rtAlignToPageSize(sizeof(NS_CONTEXT))); u32 affinity = 0x10; - ret = svc_createThread(&handle, (void*)nsThreadStart, 0, &threadStack[(STACK_SIZE / 4) - 10], affinity, 0xFFFFFFFE); + ret = svc_createThread(&handle, (void*) nsThreadStart, 0, &threadStack[(STACK_SIZE / 4) - 10], affinity, 0xFFFFFFFE); if (ret != 0) { - showDbg("svc_createThread failed: %08x", ret, 0); + showDbg((u8*) "svc_createThread failed: %08x", ret, 0); return; } - } \ No newline at end of file diff --git a/source/ns/rt.c b/source/ns/rt.c index 1b350023..25ada7cb 100644 --- a/source/ns/rt.c +++ b/source/ns/rt.c @@ -122,22 +122,22 @@ u16 rtIntToPortNumber(u16 x) { } u32 rtGetFileSize(u8* fileName) { - u32 hFile, size, ret; - u64 size64 ; + u32 hFile, size = 0, ret; + u64 size64 = 0; - FS_path testPath = (FS_path){PATH_CHAR, strlen(fileName) + 1, fileName}; + FS_path testPath = (FS_path){PATH_CHAR, strlen((const char*) fileName) + 1, fileName}; ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 7, 0); if (ret != 0) { - nsDbgPrint("openFile failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "openFile failed: %08x\n", ret, 0); hFile = 0; goto final; } ret = FSFILE_GetSize(hFile, &size64); if (ret != 0) { - nsDbgPrint("FSFILE_GetSize failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "FSFILE_GetSize failed: %08x\n", ret, 0); goto final; } - size = size64; + size = (u32) size64; final: if (hFile != 0) { @@ -151,44 +151,44 @@ u32 rtGetFileSize(u8* fileName) { u32 rtLoadFileToBuffer(u8* fileName, u32* pBuf, u32 bufSize) { u32 ret; - u32 hFile, size; + u32 hFile, size = 0; u64 size64; u32 tmp; - FS_path testPath = (FS_path){PATH_CHAR, strlen(fileName) + 1, fileName}; + FS_path testPath = (FS_path){PATH_CHAR, strlen((const char*) fileName) + 1, fileName}; ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 7, 0); if (ret != 0) { - nsDbgPrint("openFile failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "openFile failed: %08x\n", ret, 0); hFile = 0; goto final; } ret = FSFILE_GetSize(hFile, &size64); if (ret != 0) { - nsDbgPrint("FSFILE_GetSize failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "FSFILE_GetSize failed: %08x\n", ret, 0); goto final; } - size = size64; + size = (u32) size64; /* if (bufSize == 0) { ret = svc_controlMemory((u32*)&outAddr, 0, 0, size , 0x10003, 3); if(ret != 0) { - nsDbgPrint("svc_controlMemory failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "svc_controlMemory failed: %08x\n", ret, 0); goto final; } *ppBuf = (u32*)outAddr; }*/ if (bufSize < size) { - nsDbgPrint("rtLoadFileToBuffer: buffer too small\n"); + nsDbgPrint((const char*) "rtLoadFileToBuffer: buffer too small\n"); ret = -1; goto final; } ret = FSFILE_Read(hFile, &tmp, 0, (u32*)pBuf, size); if(ret != 0) { - nsDbgPrint("FSFILE_Read failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "FSFILE_Read failed: %08x\n", ret, 0); goto final; } @@ -210,7 +210,7 @@ u32 rtGetThreadReg(Handle hProcess, u32 tid, u32* ctx) { ret = svc_openThread(&hThread, hProcess, tid); if (ret != 0) { - nsDbgPrint("openThread failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "openThread failed: %08x\n", ret, 0); return ret; } pKThread = kGetKProcessByHandle(hThread); @@ -234,7 +234,7 @@ u32 rtGenerateJumpCodeThumbR3(u32 src, u32 dst, u32* buf) { } void rtInitHook(RT_HOOK* hook, u32 funcAddr, u32 callbackAddr) { - hook->model = 0; + hook->model = 0; hook->isEnabled = 0; hook->funcAddr = funcAddr; diff --git a/source/plg.c b/source/plg.c index b28d4453..65477f6c 100644 --- a/source/plg.c +++ b/source/plg.c @@ -38,6 +38,8 @@ drawStringTypeDef plgDrawStringCallback = 0; void plgInitScreenOverlay(); +void nsInit(); +u32 isInDebugMode(); int isVRAMAccessible = 0; int plgOverlayStatus = 0; @@ -53,7 +55,7 @@ u32 plgRegisterCallback(u32 type, void* callback, u32 param0) { } pluginEntry[pluginEntryCount][0] = CALLBACK_OVERLAY; pluginEntry[pluginEntryCount][1] = (u32)"overlay"; - pluginEntry[pluginEntryCount][2] = (u32)callback; + pluginEntry[pluginEntryCount][2] = (u32) callback; pluginEntryCount++; return 0; } @@ -69,7 +71,7 @@ u32 plgRequestMemory(u32 size) { u32 plgRequestMemorySpecifyRegion(u32 size, int sysRegion) { u32 ret, outAddr, addr; - if (size & 0xfff != 0) { + if ((size & 0xfff) != 0) { return 0; } if (!plgMemoryPoolEnd) { @@ -92,8 +94,8 @@ u32 plgRequestMemorySpecifyRegion(u32 size, int sysRegion) { u32 plgGetSharedServiceHandle(char* servName, u32* handle) { if (strcmp(servName, "fs:USER") == 0) { *handle = fsUserHandle; - return 0; } + return 0; } u32 plgGetIoBase(u32 IoBase) { @@ -112,7 +114,7 @@ u32 plgGetIoBase(u32 IoBase) { if (IoBase == IO_BASE_HOME_MENU_PID) { return ntrConfig->HomeMenuPid; } - if (IoBase = VALUE_CURRENT_LANGUAGE) { + if (IoBase == VALUE_CURRENT_LANGUAGE) { return g_plgInfo->currentLanguage; } return 0; @@ -121,13 +123,13 @@ u32 plgGetIoBase(u32 IoBase) { void plgSetHotkeyUi() { u8* entries[8]; u32 r; - entries[0] = "NTR Menu: X+Y"; - entries[1] = "NTR Menu: L+START"; - entries[2] = "Screenshot: disabled"; - entries[3] = "Screenshot: SELECT+START"; - entries[4] = "Screenshot: L+R"; - while (1){ - r = showMenu(NTR_CFW_VERSION, 5, entries); + entries[0] = (u8*) "NTR Menu: X+Y"; + entries[1] = (u8*) "NTR Menu: L+START"; + entries[2] = (u8*) "Screenshot: disabled"; + entries[3] = (u8*) "Screenshot: SELECT+START"; + entries[4] = (u8*) "Screenshot: L+R"; + while (1) { + r = showMenu(((u8*) NTR_CFW_VERSION), 5, entries); if (r == -1) { break; } @@ -170,7 +172,31 @@ int plgTryLoadGamePluginMenu() { if (ret != 0) { return ret; } - ret = copyRemoteMemory(CURRENT_PROCESS_HANDLE, &plgCurrentGamePluginMenu, hProcess, gamePluginMenuAddr, sizeof(GAME_PLUGIN_MENU)); + ret = copyRemoteMemory(CURRENT_PROCESS_HANDLE, &plgCurrentGamePluginMenu, hProcess, (void*) gamePluginMenuAddr, sizeof(GAME_PLUGIN_MENU)); + if (ret != 0) { + goto final; + } + final: + svc_closeHandle(hProcess); + return ret; +} + +int plgUpdateGamePluginMenuState() { + u32 gamePid = g_plgInfo->gamePluginPid; + u32 gamePluginMenuAddr = g_plgInfo->gamePluginMenuAddr; + if (gamePid == 0) { + return 1; + } + if (gamePluginMenuAddr == 0) { + return 1; + } + u32 ret = 0; + u32 hProcess; + ret = svc_openProcess(&hProcess, gamePid); + if (ret != 0) { + return ret; + } + ret = copyRemoteMemory(hProcess, (void*) gamePluginMenuAddr, CURRENT_PROCESS_HANDLE, &plgCurrentGamePluginMenu, sizeof(plgCurrentGamePluginMenu.state)); if (ret != 0) { goto final; } @@ -181,8 +207,8 @@ int plgTryLoadGamePluginMenu() { void plgShowGamePluginMenu() { u8* entries[70], ret; - u8* description[70]; - u8* buf; + u8* description[70]; + u8* buf; int i, j; while (1) { @@ -193,7 +219,7 @@ void plgShowGamePluginMenu() { buf = &(plgCurrentGamePluginMenu.buf[plgCurrentGamePluginMenu.offsetInBuffer[i]]); description[i] = 0; entries[i] = buf; - for (j = 0; j < strlen(buf); j++) { + for (j = 0; j < strlen((const char*) buf); j++) { if (buf[j] == 0xff) { buf[j] = 0; description[i] = &(buf[j + 1]); @@ -202,8 +228,8 @@ void plgShowGamePluginMenu() { } } int r; - r = showMenuEx(plgTranslate("Game Plugin Config"), plgCurrentGamePluginMenu.count, entries, description, - lastGamePluginMenuSelect); + r = showMenuEx((u8*) plgTranslate("Game Plugin Config"), plgCurrentGamePluginMenu.count, entries, description, + lastGamePluginMenuSelect); if (r == -1) { return; } @@ -224,7 +250,7 @@ void plgShowGamePluginMenu() { int plgTryUpdateConfig() { u32 gamePid = g_plgInfo->gamePluginPid; - u32 configStart = &(g_plgInfo->nightShiftLevel); + u32 configStart = (u32) &(g_plgInfo->nightShiftLevel); u32 configSize = 4; if (gamePid == 0) { @@ -235,30 +261,7 @@ int plgTryUpdateConfig() { if (ret != 0) { return ret; } - ret = copyRemoteMemory(hProcess, configStart, CURRENT_PROCESS_HANDLE, configStart, configSize); - if (ret != 0) { - goto final; - } - final: - svc_closeHandle(hProcess); - return ret; -} -int plgUpdateGamePluginMenuState() { - u32 gamePid = g_plgInfo->gamePluginPid; - u32 gamePluginMenuAddr = g_plgInfo->gamePluginMenuAddr; - if (gamePid == 0) { - return 1; - } - if (gamePluginMenuAddr == 0) { - return 1; - } - u32 ret = 0; - u32 hProcess; - ret = svc_openProcess(&hProcess, gamePid); - if (ret != 0) { - return ret; - } - ret = copyRemoteMemory(hProcess, gamePluginMenuAddr, CURRENT_PROCESS_HANDLE, &plgCurrentGamePluginMenu, sizeof(plgCurrentGamePluginMenu.state)); + ret = copyRemoteMemory(hProcess, (void*) configStart, CURRENT_PROCESS_HANDLE, (void*) configStart, configSize); if (ret != 0) { goto final; } @@ -273,31 +276,33 @@ void plgShowMainMenu() { u32 entid[70]; u32 pos = 0, i; u32 mainEntries = 3; - u8 requestUpdateState = 0; + //Unused + //u8 requestUpdateState = 0; debounceKey(); - entries[0] = plgTranslate("Process Manager"); - entries[1] = plgTranslate("Enable Debugger"); - entries[2] = plgTranslate("Set Hotkey"); + entries[0] = (u8*) plgTranslate("Process Manager"); + entries[1] = (u8*) plgTranslate("Enable Debugger"); + entries[2] = (u8*) plgTranslate("Set Hotkey"); pos = mainEntries; for (i = 0; i < pluginEntryCount; i++) { if (pluginEntry[i][0] == 1) { - entries[pos] = (u8*)pluginEntry[i][1]; + entries[pos] = (u8*) pluginEntry[i][1]; entid[pos] = i; pos++; } } if (plgTryLoadGamePluginMenu() == 0) { - entries[pos] = plgTranslate("Game Plugin"); + entries[pos] = (u8*) plgTranslate("Game Plugin"); pos++; } acquireVideo(); + //Unused + //u8 buf[200]; while (1) { s32 r; - u8 buf[200]; - r = showMenu(NTR_CFW_VERSION, pos, entries); + r = showMenu(((u8*) NTR_CFW_VERSION), pos, entries); if (r == -1) { break; } @@ -306,11 +311,11 @@ void plgShowMainMenu() { } if (r == 1) { if (g_nsConfig->hSOCU) { - showMsg(plgTranslate("Debugger has already been enabled.")); + showMsg((u8*) plgTranslate("Debugger has already been enabled.")); break; } else { - nsInit(); + nsInit((u32) NULL); break; } } @@ -323,13 +328,12 @@ void plgShowMainMenu() { break; } else { - u32 ret = ((funcType)((void*)(pluginEntry[entid[r]][2])))(); + u32 ret = ((funcType) ((void*) (pluginEntry[entid[r]][2])))(); if (ret) { break; } } } - } releaseVideo(); @@ -342,9 +346,10 @@ u32 plgRegisterMenuEntry(u32 catalog, char* title, void* callback) { return -1; } pluginEntry[pluginEntryCount][0] = catalog; - pluginEntry[pluginEntryCount][1] = (u32)title; - pluginEntry[pluginEntryCount][2] = (u32)callback; + pluginEntry[pluginEntryCount][1] = (u32) title; + pluginEntry[pluginEntryCount][2] = (u32) callback; pluginEntryCount++; + return 0; } u32 plgEnsurePoolEnd(u32 end) { @@ -359,11 +364,11 @@ u32 plgEnsurePoolEnd(u32 end) { if (end <= plgPoolEnd) { return 0; } - nsDbgPrint("expand pool addr: %08x, size: %08x\n", addr, size); + nsDbgPrint((const char*) "expand pool addr: %08x, size: %08x\n", addr, size); ret = controlMemoryInSysRegion(&outAddr, addr, addr, size, NS_DEFAULT_MEM_REGION + 3, 3); if (ret != 0) { if (rtCheckRemoteMemoryRegionSafeForWrite(0xffff8001, addr, size) != 0) { - nsDbgPrint("alloc plg memory failed: %08x\n", ret); + nsDbgPrint((const char*) "alloc plg memory failed: %08x\n", ret); return ret; } } @@ -383,9 +388,9 @@ void tryInitFS() { srv_getServiceHandle(0, &fsUserHandle, "fs:REG"); ret = FSUSER_Initialize(fsUserHandle); if (ret != 0) { - nsDbgPrint("FSUSER_Initialize failed: %08x\n", ret); + nsDbgPrint((const char*) "FSUSER_Initialize failed: %08x\n", ret); } - nsDbgPrint("fsUserHandle: %08x\n", fsUserHandle); + nsDbgPrint((const char*) "fsUserHandle: %08x\n", fsUserHandle); } u32 plgLoadPluginToRemoteProcess(u32 hProcess) { @@ -403,31 +408,31 @@ u32 plgLoadPluginToRemoteProcess(u32 hProcess) { ret = svc_openProcess(&hMenuProcess, ntrConfig->HomeMenuPid); if (ret != 0) { hMenuProcess = 0; - nsDbgPrint("open menu process failed: %08x\n", ret); + nsDbgPrint((const char*) "open menu process failed: %08x\n", ret); return ret; } } - nsDbgPrint("hMenuProcess:%08x\n", hMenuProcess); + nsDbgPrint((const char*) "hMenuProcess:%08x\n", hMenuProcess); memset(&cfg, 0, sizeof(NS_CONFIG)); - ret = copyRemoteMemory(0xffff8001, &plgInfo, hMenuProcess, (void*)plgPoolStart, sizeof(PLGLOADER_INFO)); + ret = copyRemoteMemory(0xffff8001, &plgInfo, hMenuProcess, (void*) plgPoolStart, sizeof(PLGLOADER_INFO)); if (ret != 0) { - nsDbgPrint("load plginfo failed:%08x\n", ret); + nsDbgPrint((const char*) "load plginfo failed:%08x\n", ret); return ret; } getProcessTIDByHandle(hProcess, procTid); - nsDbgPrint("procTid: %08x%08x\n", procTid[1], procTid[0]); + nsDbgPrint((const char*) "procTid: %08x%08x\n", procTid[1], procTid[0]); if (!((procTid[0] == plgInfo.tid[0]) && (procTid[1] == plgInfo.tid[1]))) { - nsDbgPrint("tid mismatch\n"); + nsDbgPrint((const char*) "tid mismatch\n"); return -1; } u32 pid = 0; svc_getProcessId(&pid, hProcess); plgInfo.gamePluginPid = pid; - copyRemoteMemory(hMenuProcess, (void*)plgPoolStart, 0xffff8001, &plgInfo, sizeof(PLGLOADER_INFO)); + copyRemoteMemory(hMenuProcess, (void*) plgPoolStart, 0xffff8001, &plgInfo, sizeof(PLGLOADER_INFO)); if (plgInfo.plgCount == 0) { if (!isInDebugMode()) { @@ -453,89 +458,96 @@ u32 plgLoadPluginToRemoteProcess(u32 hProcess) { totalSize += size; base += size; } - u32 newKP = 0; - u32 oldKP = 0; - u32 hPMProcess = getCurrentProcessHandle(); + //Unused + //u32 newKP = 0; + //u32 oldKP = 0; + //u32 hPMProcess = getCurrentProcessHandle(); ret = mapRemoteMemoryInSysRegion(hProcess, plgPoolStart, totalSize); - + if (ret != 0) { - nsDbgPrint("alloc plugin memory failed: %08x\n", ret); + nsDbgPrint((const char*) "alloc plugin memory failed: %08x\n", ret); return ret; } ret = rtCheckRemoteMemoryRegionSafeForWrite(hProcess, plgPoolStart, totalSize); if (ret != 0) { - nsDbgPrint("rwx failed: %08x\n", ret); + nsDbgPrint((const char*) "rwx failed: %08x\n", ret); return ret; } - ret = copyRemoteMemory(hProcess, (void*)plgPoolStart, 0xffff8001, &targetPlgInfo, sizeof(PLGLOADER_INFO)); + ret = copyRemoteMemory(hProcess, (void*) plgPoolStart, 0xffff8001, &targetPlgInfo, sizeof(PLGLOADER_INFO)); if (ret != 0) { - nsDbgPrint("copy plginfo failed: %08x\n", ret); + nsDbgPrint((const char*) "copy plginfo failed: %08x\n", ret); return ret; } for (i = 0; i < targetPlgInfo.plgCount; i++) { - ret = copyRemoteMemory(hProcess, (void*)targetPlgInfo.plgBufferPtr[i], hMenuProcess, (void*)plgInfo.plgBufferPtr[i], + ret = copyRemoteMemory(hProcess, (void*) targetPlgInfo.plgBufferPtr[i], hMenuProcess, (void*) plgInfo.plgBufferPtr[i], targetPlgInfo.plgSize[i]); if (ret != 0) { - nsDbgPrint("load plg failed: %08x\n", ret); + nsDbgPrint((const char*) "load plg failed: %08x\n", ret); return ret; } } ret = nsAttachProcess(hProcess, 0x00100000, &cfg, 1); if (ret != 0) { - nsDbgPrint("attach process failed: %08x\n", ret); + nsDbgPrint((const char*) "attach process failed: %08x\n", ret); return ret; } return 0; } u32 svc_RunCallback(Handle hProcess, u32* startInfo) { - u32 ret; + //Unused + //u32 ret; plgLoadPluginToRemoteProcess(hProcess); /* ret = copyRemoteMemory(hProcess, 0x00100000, 0xffff8001, buf, sizeof(buf)); - nsDbgPrint("copyRemoteMemory ret: %08x\n", ret);*/ - final: - return ((svc_RunTypeDef)((void*)(svc_RunHook.callCode)))(hProcess, startInfo); + nsDbgPrint((const char*) "copyRemoteMemory ret: %08x\n", ret);*/ + + //Unused label + //final: + + return ((svc_RunTypeDef) ((void*) (svc_RunHook.callCode)))(hProcess, startInfo); } void initFromInjectPM() { - u32 ret; + //Unused + //u32 ret; - rtInitHook(&svc_RunHook, ntrConfig->PMSvcRunAddr, (u32)svc_RunCallback); + rtInitHook(&svc_RunHook, ntrConfig->PMSvcRunAddr, (u32) svc_RunCallback); rtEnableHook(&svc_RunHook); } -u32 plgListPlugins(u32* entries, u8* buf, u8* path) { - u32 maxPlugins = 32; +u32 plgListPlugins(u32* entries, u8* buf, u8* path) { + //Unused. This should be #defined constant. + //u32 maxPlugins = 32; u32 off = 0; u16 entry[0x228]; u32 i = 0; u32 entryCount = 0; u32 dirHandle; u32 ret = 0; - FS_path dirPath = (FS_path){ PATH_CHAR, strlen(path) + 1, path }; + FS_path dirPath = (FS_path) { PATH_CHAR, strlen((const char*) path) + 1, path }; ret = FSUSER_OpenDirectory(fsUserHandle, &dirHandle, plgSdmcArchive, dirPath); if (ret != 0) { - nsDbgPrint("FSUSER_OpenDirectory failed, ret=%08x", ret); + nsDbgPrint((const char*) "FSUSER_OpenDirectory failed, ret=%08x", ret); return 0; } while (1) { u32 nread = 0; - FSDIR_Read(dirHandle, &nread, 1, (u16*)entry); + FSDIR_Read(dirHandle, &nread, 1, (u16*) entry); if (!nread) break; - entries[entryCount] = (u32)&buf[off]; + entries[entryCount] = (u32) &buf[off]; for (i = 0; i < 0x228; i++) { u16 t = entry[i]; if (t == 0) { break; } - buf[off] = (u8)t; + buf[off] = (u8) t; off += 1; } buf[off] = 0; @@ -551,6 +563,7 @@ u32 plgStartPluginLoad() { plgNextLoadAddr = plgLoadStart; g_plgInfo->arm11BinStart = arm11BinStart; g_plgInfo->arm11BinSize = arm11BinSize; + return 0; } @@ -568,24 +581,24 @@ u32 plgSetValue(u32 index, u32 value) { g_plgInfo->currentLanguage = value; } if (index == VALUE_DRAWSTRING_CALLBACK) { - plgDrawStringCallback = (void*)value; + plgDrawStringCallback = (void*) value; } - if (index == VALUE_TRANSLATE_CALLBACK){ - plgTranslateCallback = (void*)value; + if (index == VALUE_TRANSLATE_CALLBACK) { + plgTranslateCallback = (void*) value; } return 0; } int plgIsValidPluginFile(u8* filename) { int len; - len = strlen(filename); + len = strlen((const char*) filename); if (len < 5) { return 0; } if (filename[0] == '.') { return 0; } - if (strcmp(filename + len - 4, ".plg") != 0) { + if (strcmp(((const char*) filename) + len - 4, ".plg") != 0) { return 0; } return 1; @@ -599,25 +612,25 @@ u32 plgLoadPluginsFromDirectory(u8* dir) { u32 bufSize; u32 validCount = 0; - xsprintf(path, "/plugin/%s", dir); + xsprintf((char*) path, "/plugin/%s", dir); cnt = plgListPlugins(entries, buf, path); for (i = 0; i < cnt; i++) { - if (!plgIsValidPluginFile(entries[i])) { + if (!plgIsValidPluginFile((u8*) entries[i])) { continue; } - xsprintf(pluginPath, "%s/%s", path, entries[i]); + xsprintf((char*) pluginPath, "%s/%s", path, entries[i]); bufSize = rtAlignToPageSize(rtGetFileSize(pluginPath)); - nsDbgPrint("loading plugin: %s, size: %08x, addr: %08x\n", pluginPath, bufSize, plgNextLoadAddr); + nsDbgPrint((const char*) "loading plugin: %s, size: %08x, addr: %08x\n", pluginPath, bufSize, plgNextLoadAddr); ret = plgEnsurePoolEnd(plgNextLoadAddr + bufSize); if (ret != 0) { - nsDbgPrint("alloc plugin memory failed\n"); + nsDbgPrint((const char*) "alloc plugin memory failed\n"); continue; } - ret = rtLoadFileToBuffer(pluginPath, (u32*)plgNextLoadAddr, bufSize); + ret = rtLoadFileToBuffer(pluginPath, (u32*) plgNextLoadAddr, bufSize); if (ret == 0) { - nsDbgPrint("rtLoadFileToBuffer failed\n"); + nsDbgPrint((const char*) "rtLoadFileToBuffer failed\n"); continue; } g_plgInfo->plgBufferPtr[g_plgInfo->plgCount] = plgNextLoadAddr; @@ -634,12 +647,13 @@ RT_HOOK aptPrepareToStartApplicationHook; typedef u32(*aptPrepareToStartApplicationTypeDef) (u32 a1, u32 a2, u32 a3); u32 aptPrepareToStartApplicationCallback(u32 a1, u32 a2, u32 a3) { - u32* tid = (u32*)a1; - nsDbgPrint("starting app: %08x%08x\n", tid[1], tid[0]); + volatile uintptr_t temp = a1; + u32* tid = (u32*) temp; + nsDbgPrint((const char*) "starting app: %08x%08x\n", tid[1], tid[0]); plgStartPluginLoad(); - plgLoadPluginsFromDirectory("game"); + plgLoadPluginsFromDirectory((u8*) "game"); u8 buf[32]; - xsprintf(buf, "%08x%08x", tid[1], tid[0]); + xsprintf((char*) buf, "%08x%08x", tid[1], tid[0]); plgLoadPluginsFromDirectory(buf); g_plgInfo->tid[0] = tid[0]; g_plgInfo->tid[1] = tid[1]; @@ -647,7 +661,7 @@ u32 aptPrepareToStartApplicationCallback(u32 a1, u32 a2, u32 a3) { g_plgInfo->gamePluginMenuAddr = 0; lastGamePluginMenuSelect = 0; - return ((aptPrepareToStartApplicationTypeDef)((void*)(aptPrepareToStartApplicationHook.callCode)))(a1, a2, a3); + return ((aptPrepareToStartApplicationTypeDef) ((void*) (aptPrepareToStartApplicationHook.callCode)))(a1, a2, a3); } void injectPM() { @@ -660,7 +674,7 @@ void injectPM() { cfg.startupCommand = NS_STARTCMD_INJECTPM; ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - nsDbgPrint("openProcess failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "openProcess failed: %08x\n", ret, 0); hProcess = 0; goto final; } @@ -677,12 +691,12 @@ void startHomePlugin() { totalSize = plgNextLoadAddr - plgLoadStart; u32 ret = rtCheckRemoteMemoryRegionSafeForWrite(getCurrentProcessHandle(), plgLoadStart, totalSize); if (ret != 0) { - nsDbgPrint("rwx failed: %08x\n", ret); + nsDbgPrint((const char*) "rwx failed: %08x\n", ret); return; } for (i = 0; i < g_plgInfo->plgCount; i++) { - nsDbgPrint("plg: %08x\n", g_plgInfo->plgBufferPtr[i]); - ((funcType)(g_plgInfo->plgBufferPtr[i]))(); + nsDbgPrint((const char*) "plg: %08x\n", g_plgInfo->plgBufferPtr[i]); + ((funcType) (g_plgInfo->plgBufferPtr[i]))(); } } @@ -694,46 +708,47 @@ void plgInitFromInjectHOME() { u32 ret; initSharedFunc(); - plgSdmcArchive = (FS_archive){ 9, (FS_path){ PATH_EMPTY, 1, (u8*)"" } }; + plgSdmcArchive = (FS_archive) { 9, (FS_path) { PATH_EMPTY, 1, (u8*)"" } }; ret = FSUSER_OpenArchive(fsUserHandle, &plgSdmcArchive); if (ret != 0) { - nsDbgPrint("FSUSER_OpenArchive failed: %08x\n", ret); + nsDbgPrint((const char*) "FSUSER_OpenArchive failed: %08x\n", ret); return; } - g_plgInfo = (PLGLOADER_INFO*)base; + g_plgInfo = (PLGLOADER_INFO*) base; base += rtAlignToPageSize(sizeof(PLGLOADER_INFO)); - u8* arm11BinPath = ntrConfig->ntrFilePath; + u8* arm11BinPath = (u8*) ntrConfig->ntrFilePath; arm11BinSize = rtAlignToPageSize(rtGetFileSize(arm11BinPath)); - nsDbgPrint("arm11 bin size: %08x\n", arm11BinSize); + nsDbgPrint((const char*) "arm11 bin size: %08x\n", arm11BinSize); ret = plgEnsurePoolEnd(base + arm11BinSize); if (ret != 0) { - nsDbgPrint("alloc memory for arm11bin failed\n"); + nsDbgPrint((const char*) "alloc memory for arm11bin failed\n"); } - ret = rtLoadFileToBuffer(arm11BinPath, (u32*)base, arm11BinSize); + ret = rtLoadFileToBuffer(arm11BinPath, (u32*) base, arm11BinSize); if (ret == 0) { - nsDbgPrint("load arm11bin failed\n"); + nsDbgPrint((const char*) "load arm11bin failed\n"); return; } arm11BinStart = base; base += arm11BinSize; if (arm11BinSize > 32) { - u32* bootArgs = arm11BinStart + 4; + volatile uintptr_t temp = (arm11BinStart + 4); + u32* bootArgs = (u32*) temp; bootArgs[0] = 1; } memset(g_plgInfo, 0, sizeof(PLGLOADER_INFO)); plgLoadStart = base; plgStartPluginLoad(); - plgLoadPluginsFromDirectory("home"); + plgLoadPluginsFromDirectory((u8*) "home"); startHomePlugin(); plgLoadStart = plgNextLoadAddr; plgStartPluginLoad(); - rtInitHook(&aptPrepareToStartApplicationHook, ntrConfig->HomeAptStartAppletAddr, (u32)aptPrepareToStartApplicationCallback); + rtInitHook(&aptPrepareToStartApplicationHook, ntrConfig->HomeAptStartAppletAddr, (u32) aptPrepareToStartApplicationCallback); rtEnableHook(&aptPrepareToStartApplicationHook); injectPM(); @@ -745,7 +760,7 @@ u32 plgSearchReverse(u32 endAddr, u32 startAddr, u32 pat) { return 0; } while (endAddr >= startAddr) { - if (*(u32*)(endAddr) == pat) { + if (*(u32*) (endAddr) == pat) { return endAddr; } endAddr -= 4; @@ -771,7 +786,7 @@ u32 plgSearchBytes(u32 startAddr, u32 endAddr, u32* pat, int patlen) { return 0; } } - if (*((u32*)(startAddr)) == pat0) { + if (*((u32*) (startAddr)) == pat0) { if (memcmp((u32*) startAddr, pat, patlen) == 0) { return startAddr; } @@ -834,11 +849,11 @@ u32 plgOverlayNightShift(u32 isDisplay1, u32 addr, u32 addrB, u32 width, u32 for return 0; } -typedef u32 (*OverlayFnTypedef) (u32 isDisplay1, u32 addr, u32 addrB, u32 width, u32 format); +typedef u32(*OverlayFnTypedef) (u32 isDisplay1, u32 addr, u32 addrB, u32 width, u32 format); u32 plgSetBufferSwapCallback(u32 isDisplay1, u32 a2, u32 addr, u32 addrB, u32 width, u32 format, u32 a7) { u32 height = isDisplay1 ? 320 : 400; - u32 ret; + u32 ret = 0; int isDirty = 0; if ((addr >= 0x1f000000) && (addr < 0x1f600000)) { @@ -846,15 +861,15 @@ u32 plgSetBufferSwapCallback(u32 isDisplay1, u32 a2, u32 addr, u32 addrB, u32 wi goto final; } } - - svc_invalidateProcessDataCache(CURRENT_PROCESS_HANDLE, (u32)addr, width * height); + + svc_invalidateProcessDataCache(CURRENT_PROCESS_HANDLE, (u32) addr, width * height); if ((isDisplay1 == 0) && (addrB) && (addrB != addr)) { - svc_invalidateProcessDataCache(CURRENT_PROCESS_HANDLE, (u32)addrB, width * height); + svc_invalidateProcessDataCache(CURRENT_PROCESS_HANDLE, (u32) addrB, width * height); } int i; for (i = 0; i < pluginEntryCount; i++) { if (pluginEntry[i][0] == CALLBACK_OVERLAY) { - ret = ((OverlayFnTypedef)((void*) pluginEntry[i][2]))(isDisplay1, addr, addrB, width, format); + ret = ((OverlayFnTypedef) ((void*) pluginEntry[i][2]))(isDisplay1, addr, addrB, width, format); } if (ret == 0) { isDirty = 1; @@ -864,17 +879,14 @@ u32 plgSetBufferSwapCallback(u32 isDisplay1, u32 a2, u32 addr, u32 addrB, u32 wi plgOverlayNightShift(isDisplay1, addr, addrB, width, format); } else if (isDirty) { - svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32)addr, width * height); + svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32) addr, width * height); if ((isDisplay1 == 0) && (addrB) && (addrB != addr)) { - svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32)addrB, width * height); + svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32) addrB, width * height); } } - - -final: - ret = ((SetBufferSwapTypedef)((void*)SetBufferSwapHook.callCode))(isDisplay1, a2, addr, addrB, width, format, a7); - + final: + ret = ((SetBufferSwapTypedef) ((void*) SetBufferSwapHook.callCode))(isDisplay1, a2, addr, addrB, width, format, a7); return ret; } @@ -887,11 +899,11 @@ void plgInitScreenOverlay() { if (rtCheckRemoteMemoryRegionSafeForWrite(getCurrentProcessHandle(), 0x1F000000, 0x00600000) == 0) { isVRAMAccessible = 1; } - nsDbgPrint("vram accessible: %d\n", isVRAMAccessible); + nsDbgPrint((const char*) "vram accessible: %d\n", isVRAMAccessible); static u32 pat[] = { 0xe1833000, 0xe2044cff, 0xe3c33cff, 0xe1833004, 0xe1824f93 }; static u32 pat2[] = { 0xe8830e60, 0xee078f9a, 0xe3a03001, 0xe7902104 }; - static u32 pat3[] = { 0xee076f9a, 0xe3a02001, 0xe7901104, 0xe1911f9f, 0xe3c110ff}; + static u32 pat3[] = { 0xee076f9a, 0xe3a02001, 0xe7901104, 0xe1911f9f, 0xe3c110ff }; u32 addr = plgSearchBytes(0x00100000, 0, pat, sizeof(pat)); if (!addr) { @@ -902,13 +914,13 @@ void plgInitScreenOverlay() { addr = plgSearchBytes(0x00100000, 0, pat3, sizeof(pat3)); fp = plgSearchReverse(addr, addr - 0x400, 0xe92d47f0); } - nsDbgPrint("overlay addr: %08x, %08x\n", addr, fp); - + nsDbgPrint((const char*) "overlay addr: %08x, %08x\n", addr, fp); + if (!fp) { - + return; } - rtInitHook(&SetBufferSwapHook, fp, plgSetBufferSwapCallback); + rtInitHook(&SetBufferSwapHook, fp, (u32) plgSetBufferSwapCallback); rtEnableHook(&SetBufferSwapHook); plgOverlayStatus = 1; @@ -916,19 +928,19 @@ void plgInitScreenOverlay() { void initFromInjectGame() { typedef void(*funcType)(); - u32 i, ret; + u32 i; + //Unused + //u32 ret; initSharedFunc(); - - - g_plgInfo = (PLGLOADER_INFO*)plgPoolStart; + g_plgInfo = (PLGLOADER_INFO*) plgPoolStart; if (g_plgInfo->nightShiftLevel) { plgInitScreenOverlay(); } for (i = 0; i < g_plgInfo->plgCount; i++) { - nsDbgPrint("plg: %08x\n", g_plgInfo->plgBufferPtr[i]); - ((funcType)(g_plgInfo->plgBufferPtr[i]))(); + nsDbgPrint((const char*) "plg: %08x\n", g_plgInfo->plgBufferPtr[i]); + ((funcType) (g_plgInfo->plgBufferPtr[i]))(); } } diff --git a/source/pm.c b/source/pm.c index 9e4c83bb..9e7f6266 100644 --- a/source/pm.c +++ b/source/pm.c @@ -1,8 +1,13 @@ + + #include "global.h" -void dumpKernel() { +void print(char* s, int x, int y, char r, char g, char b); -} +//Unused +//void dumpKernel() { +// +//} Handle hCurrentProcess = 0; u32 currentPid = 0; @@ -22,7 +27,7 @@ u32 getCurrentProcessHandle() { svc_getProcessId(¤tPid, 0xffff8001); ret = svc_openProcess(&handle, currentPid); if (ret != 0) { - showDbg("openProcess failed, ret: %08x", ret, 0); + showDbg((u8*) "openProcess failed, ret: %08x", ret, 0); return 0; } hCurrentProcess = handle; @@ -47,14 +52,14 @@ u32 mapRemoteMemory(Handle hProcess, u32 addr, u32 size) { kSetCurrentKProcess(oldKP); //kSwapProcessPid(newKP, oldPid); if (ret != 0) { - showDbg("svc_controlMemory failed: %08x", ret, 0); + showDbg((u8*) "svc_controlMemory failed: %08x", ret, 0); return ret; } if (outAddr != addr) { - showDbg("outAddr: %08x, addr: %08x", outAddr, addr); + showDbg((u8*) "outAddr: %08x, addr: %08x", outAddr, addr); return 0; } - //showMsg("mapremote done"); + //showMsg((u8*) "mapremote done"); return 0; } @@ -71,14 +76,14 @@ u32 mapRemoteMemoryInSysRegion(Handle hProcess, u32 addr, u32 size) { kSetCurrentKProcess(oldKP); kSwapProcessPid(newKP, oldPid); if (ret != 0) { - showDbg("svc_controlMemory failed: %08x", ret, 0); + showDbg((u8*) "svc_controlMemory failed: %08x", ret, 0); return ret; } if (outAddr != addr) { - showDbg("outAddr: %08x, addr: %08x", outAddr, addr); + showDbg((u8*) "outAddr: %08x, addr: %08x", outAddr, addr); return 0; } - //showMsg("mapremote done"); + //showMsg((u8*) "mapremote done"); return 0; } @@ -91,7 +96,8 @@ u32 controlMemoryInSysRegion(u32* outAddr, u32 addr0, u32 addr1, u32 size, u32 o } u32 protectRemoteMemory(Handle hProcess, void* addr, u32 size) { - u32 outAddr = 0; + //Unused + //u32 outAddr = 0; return svc_controlProcessMemory(hProcess, addr, addr, size, 6, 7); } @@ -107,16 +113,16 @@ u32 copyRemoteMemory(Handle hDst, void* ptrDst, Handle hSrc, void* ptrSrc, u32 s ret = svc_flushProcessDataCache(hSrc, (u32)ptrSrc, size); if (ret != 0) { - nsDbgPrint("svc_flushProcessDataCache(hSrc) failed.\n"); + nsDbgPrint((const char*) "svc_flushProcessDataCache(hSrc) failed.\n"); return ret; } ret = svc_flushProcessDataCache(hDst, (u32)ptrDst, size); if (ret != 0) { - nsDbgPrint("svc_flushProcessDataCache(hDst) failed.\n"); + nsDbgPrint((const char*) "svc_flushProcessDataCache(hDst) failed.\n"); return ret; } - ret = svc_startInterProcessDma(&hdma, hDst, ptrDst, hSrc, ptrSrc, size, dmaConfig); + ret = svc_startInterProcessDma(&hdma, hDst, ptrDst, hSrc, ptrSrc, size, (u32*) dmaConfig); if (ret != 0) { return ret; } @@ -138,7 +144,7 @@ u32 copyRemoteMemory(Handle hDst, void* ptrDst, Handle hSrc, void* ptrSrc, u32 s } if (i >= 10000) { - showDbg("readRemoteMemory time out %08x", state, 0); + showDbg((u8*) "readRemoteMemory time out %08x", state, 0); return 1; } @@ -152,40 +158,50 @@ u32 copyRemoteMemory(Handle hDst, void* ptrDst, Handle hSrc, void* ptrSrc, u32 s u32 getProcessTIDByHandle(u32 hProcess, u32 tid[]) { u8 bufKProcess[0x100], bufKCodeSet[0x100]; - u32 pKCodeSet, pKProcess, ret; + //u32 pKProcess, pKCodeSet; // , ret; + + uintptr_t pKProcess; + uintptr_t pKCodeSet; + pKProcess = (uintptr_t) kGetKProcessByHandle(hProcess); + kmemcpy((void*) bufKProcess, (void*) pKProcess, 0x100); + pKCodeSet = (uintptr_t) &bufKProcess[KProcessCodesetOffset]; + kmemcpy((void*) bufKCodeSet, (void*)pKCodeSet, 0x100); - pKProcess = kGetKProcessByHandle(hProcess); - kmemcpy(bufKProcess, (void*)pKProcess, 0x100); - pKCodeSet = *(u32*)(&bufKProcess[KProcessCodesetOffset]); - kmemcpy(bufKCodeSet, (void*)pKCodeSet, 0x100); u32* pTid = (u32*)(&bufKCodeSet[0x5c]); tid[0] = pTid[0]; tid[1] = pTid[1]; + + return 0; } u32 getProcessInfo(u32 pid, u8* pname, u32 tid[], u32* kpobj) { u8 bufKProcess[0x100], bufKCodeSet[0x100]; - u32 hProcess, pKCodeSet, pKProcess, ret; - u8 buf[300]; + u32 ret, hProcess; + + //Unused. + //u32 pKCodeSet, pKProcess; + //u8 buf[300]; + + uintptr_t pKCodeSet, pKProcess; ret = 0; ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - nsDbgPrint("openProcess failed: %08x\n", ret, 0); + nsDbgPrint((const char*) "openProcess failed: %08x\n", ret, 0); goto final; } - pKProcess = kGetKProcessByHandle(hProcess); + pKProcess = (uintptr_t) kGetKProcessByHandle(hProcess); kmemcpy(bufKProcess, (void*)pKProcess, 0x100); - pKCodeSet = *(u32*)(&bufKProcess[KProcessCodesetOffset]); + pKCodeSet = (uintptr_t) &bufKProcess[KProcessCodesetOffset]; kmemcpy(bufKCodeSet, (void*)pKCodeSet, 0x100); bufKCodeSet[0x5A] = 0; u8* pProcessName = &bufKCodeSet[0x50]; u32* pTid = (u32*)(&bufKCodeSet[0x5c]); tid[0] = pTid[0]; tid[1] = pTid[1]; - strcpy(pname, pProcessName); + strcpy((char*) pname, (const char*) pProcessName); *kpobj = pKProcess; final: @@ -197,39 +213,41 @@ u32 getProcessInfo(u32 pid, u8* pname, u32 tid[], u32* kpobj) { void dumpRemoteProcess(u32 pid, u8* fileName, u32 startAddr) { - u32 hProcess, hFile, ret, i, state, t; + u32 hProcess, hFile, ret, t; u8 buf[0x1020]; - u32 dmaConfig[20] = {0}; u32 base = startAddr; u32 off = 0, addr; - u32 kProcess = 0; + //Unused + //u32 state, i; + //u32 dmaConfig[20] = {0}; + //u32 kProcess = 0; - FS_path testPath = (FS_path){PATH_CHAR, strlen(fileName) + 1, fileName}; + FS_path testPath = (FS_path){PATH_CHAR, strlen((const char*) fileName) + 1, fileName}; ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 7, 0); if (ret != 0) { - showDbg("openFile failed: %08x", ret, 0); + showDbg((u8*) "openFile failed: %08x", ret, 0); goto final; } ret = svc_openProcess(&hProcess, pid); if (ret != 0) { - showDbg("openProcess failed: %08x", ret, 0); + showDbg((u8*) "openProcess failed: %08x", ret, 0); goto final; } while(1) { addr = base + off; - xsprintf(buf, "addr: %08x", base + off); + xsprintf((char*) buf, "addr: %08x", base + off); showMsgNoPause(buf); memset(buf, 0, sizeof(buf)); ret = protectRemoteMemory(hProcess, (void*)addr, 0x1000); if (ret != 0) { - showDbg("dump finished at addr: %08x", addr, 0); + showDbg((u8*) "dump finished at addr: %08x", addr, 0); goto final; } ret = copyRemoteMemory(0xffff8001, buf, hProcess, (void*)addr, 0x1000); if (ret != 0) { - showDbg("readRemoteMemory failed: %08x", ret, 0); + showDbg((u8*) "readRemoteMemory failed: %08x", ret, 0); } FSFILE_Write(hFile, &t, off, (u32*)buf, 0x1000, 0); off += 0x1000; @@ -247,35 +265,38 @@ void dumpRemoteProcess(u32 pid, u8* fileName, u32 startAddr) { void dumpRemoteProcess2(u32 pid, u8* fileName) { u32 hdebug = 0, hfile = 0; u32 ret; - u32 hprocess = 0; + + //Unused + //u32 hprocess = 0; + u32 t, off, base = 0x00100000; u8 buf[0x1020]; - FS_path testPath = (FS_path){PATH_CHAR, strlen(fileName) + 1, fileName}; + FS_path testPath = (FS_path){PATH_CHAR, strlen((const char*) fileName) + 1, fileName}; ret = FSUSER_OpenFileDirectly(fsUserHandle, &hfile, sdmcArchive, testPath, 7, 0); if (ret != 0) { - showDbg("openFile failed: %08x", ret, 0); + showDbg((u8*) "openFile failed: %08x", ret, 0); goto final; } - showDbg("hfile: %08x", hfile, 0); + showDbg((u8*) "hfile: %08x", hfile, 0); - ret = svc_debugActiveProcess(&hdebug, pid); + ret = svc_debugActiveProcess((s32*) &hdebug, pid); if (ret != 0) { - showDbg("debugActiveProcess failed: %08x", ret, 0); + showDbg((u8*) "debugActiveProcess failed: %08x", ret, 0); goto final; } - showDbg("hdebug: %08x", hdebug, 0); + showDbg((u8*) "hdebug: %08x", hdebug, 0); off = 0; while(1) { - xsprintf(buf, "addr: %08x", base + off); - print(buf, 10, 10, 255, 0, 0); + xsprintf((char*) buf, "addr: %08x", base + off); + print((char*) buf, 10, 10, 255, 0, 0); updateScreen(); ret = svc_readProcessMemory(buf, hdebug, off + base, 0x1000); if (ret != 0) { - showDbg("readmemory addr = %08x, ret = %08x", base + off, ret); + showDbg((u8*) "readmemory addr = %08x, ret = %08x", base + off, ret); goto final; } FSFILE_Write(hfile, &t, off, (u32*)buf, 0x1000, 0); @@ -299,24 +320,26 @@ void dumpCode(u32 base, u32 size, u8* fileName) { u32 t = 0; vu32 i; - showMsg("dumpcode"); - FS_path testPath = (FS_path){PATH_CHAR, strlen(fileName) + 1, fileName}; - showMsg("testpath"); + showMsg((u8*) "dumpcode"); + FS_path testPath = (FS_path){PATH_CHAR, strlen((const char*) fileName) + 1, fileName}; + showMsg((u8*) "testpath"); FSUSER_OpenFileDirectly(fsUserHandle, &handle, sdmcArchive, testPath, 7, 0); - showMsg("openfile"); + showMsg((u8*) "openfile"); if (handle == 0) { - showMsg("open file failed"); + showMsg((u8*) "open file failed"); return; } while(off < size) { - xsprintf(buf, "addr: %08x", base + off); + xsprintf((char*) &buf[0], "addr: %08x", base + off); showMsgNoPause(buf); for (i = 0; i < 1000000; i++) { } - kmemcpy(tmpBuffer, (void*)(base + off), 0x1000); - FSFILE_Write(handle, &t, off, tmpBuffer, 0x1000, 0); + kmemcpy((void*) tmpBuffer, (void*)(base + off), 0x1000); + + uintptr_t temp = (uintptr_t) &tmpBuffer[0]; + FSFILE_Write(handle, &t, off, (u32*) temp, 0x1000, 0); off += 0x1000; } } @@ -344,25 +367,25 @@ u32 writeRemoteProcessMemory(int pid, u32 addr, u32 size, u32* buf) { } void initSMPatch() { - u32 hProcess = 0, ret; + u32 ret; //, hProcess = 0; u32 buf[20]; //write(0x101820,(0x01,0x00,0xA0,0xE3,0x1E,0xFF,0x2F,0xE1),pid=0x3) buf[0] = 0xe3a00001; buf[1] = 0xe12fff1e; ret = writeRemoteProcessMemory(3, 0x101820, 8, buf); if (ret != 0) { - showDbg("patch sm failed: %08x", ret, 0); + showDbg((u8*) "patch sm failed: %08x", ret, 0); } } u32 showStartAddrMenu() { u8* entries[8]; u32 r; - entries[0] = "0x00100000"; - entries[1] = "0x08000000"; - entries[2] = "0x14000000"; + entries[0] = (u8*) "0x00100000"; + entries[1] = (u8*) "0x08000000"; + entries[2] = (u8*) "0x14000000"; while (1){ - r = showMenu("set addr", 3, entries); + r = showMenu((u8*) "set addr", 3, entries); if (r == 0) { return 0x00100000; break; @@ -380,48 +403,48 @@ u32 showStartAddrMenu() { void processManager() { u32 pids[100]; - u32 ret, off, i, t; - u32 pidCount = 0; + u32 ret, off, t; + s32 pidCount = 0, i; u8 buf[800]; u8* captions[100]; u8 pidbuf[50]; u8 pname[20]; - u32 tid[4]; - static dumpCnt = 0; + u32 tid[4] = {}; + static u32 dumpCnt = 0; u32 startAddr; ret = svc_getProcessList(&pidCount, pids, 100); if (ret != 0) { - showDbg("getProcessList failed: %08x", ret, 0); + showDbg((u8*) "getProcessList failed: %08x", ret, 0); return; } buf[0] = 0; off = 0; for (i = 0; i < pidCount; i++) { - xsprintf(pidbuf, "%08x", pids[i]); + xsprintf((char*) &pidbuf[0], "%08x", pids[i]); captions[i] = &buf[off]; - strcpy(&buf[off], pidbuf); - off += strlen(pidbuf) + 1; + strcpy((char*) &buf[off], (const char*) pidbuf); + off += strlen((const char*) pidbuf) + 1; } while(1) { - u32 r = showMenu("processList", pidCount, captions); + u32 r = showMenu((u8*) "processList", pidCount, captions); if (r == -1) { return; } - u8* actCaptions[] = {"dump", "info"}; + u8* actCaptions[] = {(u8*) "dump", (u8*) "info"}; u32 act = showMenu(captions[r], 2, actCaptions); if (act == 0) { - xsprintf(pidbuf, "/dump_pid%x_%d.dmp", pids[r], dumpCnt); + xsprintf((char*) &pidbuf[0], "/dump_pid%x_%d.dmp", pids[r], dumpCnt); dumpCnt += 1; startAddr = showStartAddrMenu(); dumpRemoteProcess(pids[r], pidbuf, startAddr); } if (act == 1) { pname[10] = 0; - getProcessInfo(pids[r], pname, tid, &t); - showDbg("pname: %s", (u32)pname, 0); - showDbg("tid: %08x%08x", tid[1], tid[0]); + getProcessInfo(pids[r], pname, &tid[0], &t); + showDbg((u8*) "pname: %s", (u32)pname, 0); + showDbg((u8*) "tid: %08x%08x", tid[1], tid[0]); } } diff --git a/source/svc7b.c b/source/svc7b.c index ebb5a72c..9717788c 100644 --- a/source/svc7b.c +++ b/source/svc7b.c @@ -1,11 +1,13 @@ #include "global.h" u32 kernelArgs[32]; -void backdoorHandler(void); u32 KProcessHandleDataOffset; u32 KProcessPIDOffset; u32 KProcessCodesetOffset; +void backdoorHandler(void); +void InvalidateEntireInstructionCache(void); +void InvalidateEntireDataCache(void); void* currentBackdoorHandler = backdoorHandler; @@ -15,17 +17,17 @@ u32 keRefHandle(u32 pHandleTable, u32 handle) { return ptr; } -void keDumpHandle(u32 pKProcess, u32* buf){ - u32 pHandleTable = pKProcess + KProcessHandleDataOffset; - -} +//Unused function. +//void keDumpHandle(u32 pKProcess, u32* buf){ +// u32 pHandleTable = pKProcess + KProcessHandleDataOffset; +// return; +//} u32* translateAddress(u32 addr) { if (addr < 0x1ff00000) { - return addr - 0x1f3f8000 + 0xfffdc000; + return (u32*) (addr - 0x1f3f8000 + 0xfffdc000); } return (u32*)(addr - 0x1ff00000 + 0xdff00000); - } void set_kmmu_rw(int cpu, u32 addr, u32 size) @@ -83,10 +85,10 @@ void set_kmmu_rw(int cpu, u32 addr, u32 size) } void set_remoteplay_mmu(u32 addr, u32 size) { - int i, j; + int i; // , j; u32 mmu_p; - u32 p1, p2; - u32 v1, v2; + u32 p1; // , p2; + u32 v1; // , v2; u32 end; mmu_p = 0x1f3f8000; @@ -123,11 +125,12 @@ void keDoKernelHax() { *(u32*)(ntrConfig->ControlMemoryPatchAddr2) = 0; if (ntrConfig->KernelFreeSpaceAddr_Optional) { - u32* addr = ntrConfig->KernelFreeSpaceAddr_Optional; + volatile uintptr_t tempIntPtr = ntrConfig->KernelFreeSpaceAddr_Optional; + u32* addr = (u32*) tempIntPtr; addr[0] = 0xe10f0000; addr[1] = 0xe38000c0; addr[2] = 0xe129f000; - rtGenerateJumpCode(kernelCallback, &addr[3]); + rtGenerateJumpCode((u32) kernelCallback, &addr[3]); currentBackdoorHandler = (void*)(addr); } @@ -135,13 +138,11 @@ void keDoKernelHax() { InvalidateEntireDataCache(); } - - void remotePlayKernelCallback(); void kernelCallback(u32 msr) { - typedef (*keRefHandleType)(u32, u32); - + //Unused + //typedef u32 (*keRefHandleType)(u32, u32); //keRefHandleType keRefHandle = (keRefHandleType)0xFFF67D9C; u32 t = kernelArgs[0]; diff --git a/source/tools.c b/source/tools.c index 1b9207ea..d26071c4 100644 --- a/source/tools.c +++ b/source/tools.c @@ -10,9 +10,8 @@ u8 *image_buf = NULL; - - - +void disp(u32 t, u32 cl); +void print(char* s, int x, int y, char r, char g, char b); int sdf_open(char *filename, int mode) { @@ -225,7 +224,7 @@ void allocImageBuf() { return; } u32 out_addr = plgRequestMemory(0x00100000); - nsDbgPrint(" out_addr: %08x", out_addr); + nsDbgPrint((const char*) " out_addr: %08x", out_addr); image_buf = (u8*)out_addr; } @@ -239,9 +238,11 @@ void do_screen_shoot(void) u32 tl_pitch, bl_pitch; u8 *rev_buf; u32 fbP2VOffset = 0xc0000000; - u32 out_addr; - u32 workingBuffer; + //Unused + //u32 out_addr; + + uintptr_t workingBuffer = 0; char name[64]; @@ -252,10 +253,10 @@ void do_screen_shoot(void) if (image_buf == NULL) { return; } - workingBuffer = image_buf; + workingBuffer = (uintptr_t) image_buf; } else { - workingBuffer = plgRequestTempBuffer(0xA0000); + workingBuffer = (uintptr_t) plgRequestTempBuffer(0xA0000); } if (workingBuffer == 0) { @@ -277,10 +278,10 @@ void do_screen_shoot(void) current_fb &= 1; kmemcpy((void*)(workingBuffer + 0x50000), (void*)tl_fbaddr[current_fb], 240 * 400 * 3); - rev_buf = workingBuffer + sizeof(struct BitmapHeader); - rev_image(rev_buf, 400, 240, workingBuffer + 0x50000, tl_pitch, tl_format); + rev_buf = ((u8*)workingBuffer) + sizeof(struct BitmapHeader); + rev_image(rev_buf, 400, 240, (u8*)(workingBuffer + 0x50000), tl_pitch, tl_format); xsprintf(name, "/top_%04d.bmp", bmp_index); - bmp_write(workingBuffer, 400, 240, name); + bmp_write((u8*) workingBuffer, 400, 240, name); // Bottom screen @@ -288,10 +289,10 @@ void do_screen_shoot(void) current_fb &= 1; kmemcpy((void*)(workingBuffer + 0x50000), (void*)bl_fbaddr[current_fb], 240 * 320 * 3); - rev_buf = workingBuffer + sizeof(struct BitmapHeader); - rev_image(rev_buf, 320, 240, workingBuffer + 0x50000, bl_pitch, bl_format); + rev_buf = ((u8*)workingBuffer) + sizeof(struct BitmapHeader); + rev_image(rev_buf, 320, 240, (u8*)(workingBuffer + 0x50000), bl_pitch, bl_format); xsprintf(name, "/bot_%04d.bmp", bmp_index); - bmp_write(workingBuffer, 320, 240, name); + bmp_write((u8*) workingBuffer, 320, 240, name); disp(100, 0x01ff00ff); bmp_index += 1; @@ -299,7 +300,9 @@ void do_screen_shoot(void) u32 takeScreenShot() { vu32 i; - u32 ret, out_addr; + + //Unused + //u32 ret, out_addr; for (i = 0; i < 0x1000000; i++) { } @@ -324,13 +327,15 @@ u32 getRegionSize(Handle hProcess, u32 addr) { u32 fastCopyMemory(Handle hDst, u32 ptrDst, Handle hSrc, u32 ptrSrc, u32 size) { u32 ret = 0; - ret = copyRemoteMemory(hDst, ptrDst, hSrc, ptrSrc, size); + uintptr_t tempSrc = ptrSrc; + uintptr_t tempDst = ptrDst; + ret = copyRemoteMemory(hDst, (void*) tempDst, hSrc, (void*) tempSrc, size); if (ret == 0) { return 0; } u32 off = 0; for (off = 0; off < size; off += 0x1000) { - ret = copyRemoteMemory(hDst, ptrDst + off, hSrc, ptrSrc + off, 0x1000); + ret = copyRemoteMemory(hDst, (void*) (tempDst + off), hSrc, (void*) (tempSrc + off), 0x1000); if (ret != 0) { return ret; } @@ -349,11 +354,15 @@ u32 loadSaveVRAM(int fd, int isLoad) { if (isLoad) { ret = sdf_read(fd, off, image_buf, 0x00100000); if (ret >= 0) { - memcpy(VRAM_ADDR + off, image_buf, 0x00100000); + uintptr_t temp = VRAM_ADDR; + uintptr_t temp_buf = (uintptr_t) image_buf; + memcpy((void*) (temp + off), (void*) temp_buf, 0x00100000); } } else { - memcpy(image_buf, VRAM_ADDR + off, 0x00100000); + uintptr_t temp = VRAM_ADDR + off; + uintptr_t temp_buf = (uintptr_t) image_buf; + memcpy((void*) temp_buf, (void*) temp, 0x00100000); ret = sdf_write(fd, off, image_buf, 0x00100000); } if (ret < 0) { @@ -375,7 +384,8 @@ u32 saveRegion(Handle hProcess, u32 addr, int fd, u32 offsetInFile, u32 size) { if (currentRead > 0x00100000) { currentRead = 0x00100000; } - ret = fastCopyMemory(CURRENT_PROCESS_HANDLE, image_buf, hProcess, addr + off, currentRead); + uintptr_t temp = (uintptr_t) image_buf; + ret = fastCopyMemory(CURRENT_PROCESS_HANDLE, (u32) temp, hProcess, addr + off, currentRead); if (ret != 0) { return ret; } @@ -395,7 +405,8 @@ u32 loadRegion(Handle hProcess, u32 addr, int fd, u32 offsetInFile, u32 size) { currentRead = 0x00100000; } sdf_read(fd, off + offsetInFile, image_buf, currentRead); - ret = fastCopyMemory(hProcess, addr + off, CURRENT_PROCESS_HANDLE, image_buf, currentRead); + uintptr_t temp = (uintptr_t) image_buf; + ret = fastCopyMemory(hProcess, addr + off, CURRENT_PROCESS_HANDLE, (u32) temp, currentRead); if (ret != 0) { return ret; } @@ -413,7 +424,7 @@ u32 instantSave(int id, int isLoad) { delayUi(); u32 gamePid = g_plgInfo->gamePluginPid; if (gamePid == 0) { - showDbg("game not running", 0, 0); + showDbg((u8*) "game not running", 0, 0); return 0; } Handle hProcess = 0, hGSPProcess = 0; @@ -421,27 +432,27 @@ u32 instantSave(int id, int isLoad) { int fd = 0; ret = svc_openProcess(&hProcess, gamePid); if (ret != 0) { - showDbg("open Game Process failed: %08x", ret, 0); + showDbg((u8*) "open Game Process failed: %08x", ret, 0); return 0; } ret = svc_openProcess(&hGSPProcess, 0x14); if (ret != 0) { - showDbg("open GSP Process failed: %08x", ret, 0); + showDbg((u8*) "open GSP Process failed: %08x", ret, 0); goto final; } u8 buf[40]; - xsprintf(buf, "/save_%08x_%d.rts", g_plgInfo->tid[0], id); - fd = sdf_open(buf, isLoad ? O_RDWR : (O_RDWR | O_CREAT)); + xsprintf((char*) buf, "/save_%08x_%d.rts", g_plgInfo->tid[0], id); + fd = sdf_open((char*) buf, isLoad ? O_RDWR : (O_RDWR | O_CREAT)); if (fd <= 0) { - showDbg("open file failed: %08x", fd, 0); + showDbg((u8*) "open file failed: %08x", fd, 0); goto final; } u32 addrIdx, regionSize, offsetInFile = 0, addr; ret = loadSaveVRAM(fd, isLoad); if (ret != 0) { - showDbg("VRAM failed: %08x", ret, 0); + showDbg((u8*) "VRAM failed: %08x", ret, 0); goto final; } offsetInFile += VRAM_SIZE; @@ -454,7 +465,7 @@ u32 instantSave(int id, int isLoad) { ret = saveRegion(hGSPProcess, addr, fd, offsetInFile, VRAM_SIZE); } if (ret != 0) { - showDbg("GSP VRAM failed: %08x", ret, 0); + showDbg((u8*) "GSP VRAM failed: %08x", ret, 0); goto final; } offsetInFile += VRAM_SIZE; @@ -470,13 +481,13 @@ u32 instantSave(int id, int isLoad) { ret = saveRegion(hProcess, addr, fd, offsetInFile, regionSize); } if (ret != 0) { - showDbg("region %08x failed: %08x", addr, ret); + showDbg((u8*) "region %08x failed: %08x", addr, ret); goto final; } } offsetInFile += regionSize; } - showDbg(isLoad ? "Load %d OK, GamePID: %08x." : "Save %d OK, GamePID: %08x.", id, gamePid); + showDbg((u8*) (isLoad ? "Load %d OK, GamePID: %08x." : "Save %d OK, GamePID: %08x."), id, gamePid); final: if (fd > 0) { sdf_close(fd); @@ -490,14 +501,16 @@ u32 instantSave(int id, int isLoad) { u32 instantSaveMenu() { if (ntrConfig->memMode != NTR_MEMMODE_DEFAULT) { - showMsg("RTS is not compatitable with extended memory mode."); - return; + showMsg((u8*) "RTS is not compatitable with extended memory mode."); + //Do nothing + return 0; } if (!image_buf) { allocImageBuf(); } if (image_buf == NULL){ - return; + //Do nothing + return 0; } u8* entries[7]; @@ -506,14 +519,14 @@ u32 instantSaveMenu() { u32 r; int i; for (i = 0; i < 3; i++) { - xsprintf(buf[i], plgTranslate("Save %d"), i); - xsprintf(buf[i + 3], plgTranslate("Load %d"), i); + xsprintf((char*) buf[i], plgTranslate("Save %d"), i); + xsprintf((char*) buf[i + 3], plgTranslate("Load %d"), i); entries[i] = buf[i]; entries[i + 3] = buf[i + 3]; } - entries[6] = plgTranslate("Hint: Back to Home Menu before Load/Save."); + entries[6] = (u8*) plgTranslate("Hint: Back to Home Menu before Load/Save."); while (1){ - r = showMenu(plgTranslate("Instant Save"), 7, entries); + r = showMenu((u8*) plgTranslate("Instant Save"), 7, entries); if (r == -1) { break; } @@ -533,24 +546,26 @@ u32 instantSaveMenu() { u32 cpuClockUi() { - u8 buf[200]; + //Unused + //u8 buf[200]; + acquireVideo(); u8* entries[8]; u32 r; - entries[0] = plgTranslate("268MHz, L2 Disabled (Default)"); - entries[1] = plgTranslate("804MHz, L2 Disabled"); - entries[2] = plgTranslate("268MHz, L2 Enabled"); - entries[3] = plgTranslate("804MHz, L2 Enabled (Best)"); + entries[0] = (u8*) plgTranslate("268MHz, L2 Disabled (Default)"); + entries[1] = (u8*) plgTranslate("804MHz, L2 Disabled"); + entries[2] = (u8*) plgTranslate("268MHz, L2 Enabled"); + entries[3] = (u8*) plgTranslate("804MHz, L2 Enabled (Best)"); while (1) { blank(0, 0, 320, 240); - r = showMenu(plgTranslate("CPU Clock"), 4, entries); + r = showMenu((u8*) plgTranslate("CPU Clock"), 4, entries); if (r == -1) { break; } if ((r >= 0) && (r <= 3)) { u32 ret = svc_kernelSetState(10, r, 0, 0); if (ret != 0) { - showDbg("kernelSetState failed: %08x", ret, 0); + showDbg((u8*) "kernelSetState failed: %08x", ret, 0); } setCpuClockLock(r); break; @@ -566,7 +581,7 @@ void plgDoReboot() { u32 ret; ret = srv_getServiceHandle(NULL, &hNSS, "ns:s"); if (ret != 0) { - showDbg("open ns:s failed: %08x", ret, 0); + showDbg((u8*) "open ns:s failed: %08x", ret, 0); return; } u32* cmdbuf = getThreadCommandBuffer(); @@ -587,7 +602,7 @@ void plgDoPowerOff() { u32 ret; ret = srv_getServiceHandle(NULL, &hNSS, "ns:s"); if (ret != 0) { - showDbg("open ns:s failed: %08x", ret, 0); + showDbg((u8*) "open ns:s failed: %08x", ret, 0); return; } u32* cmdbuf = getThreadCommandBuffer(); @@ -609,10 +624,10 @@ u32 powerMenu() { u8* entries[8]; u32 r; vu32 i; - entries[0] = plgTranslate("Reboot"); - entries[1] = plgTranslate("Power Off"); + entries[0] = (u8*) plgTranslate("Reboot"); + entries[1] = (u8*) plgTranslate("Power Off"); while (1) { - r = showMenu(plgTranslate("Power"), 2, entries); + r = showMenu((u8*) plgTranslate("Power"), 2, entries); if (r == -1) { break; } @@ -635,7 +650,7 @@ u32 powerMenu() { int GSPPid = 0x14; int isGSPPatchRequired = 0; -u32 gspPatchAddr = 0; +uintptr_t gspPatchAddr = 0; int bklightValue = 50; int checkBacklightSupported() { @@ -655,7 +670,7 @@ int checkBacklightSupported() { return 0; } gspPatchAddr = 0x0010740C; - copyRemoteMemory(getCurrentProcessHandle(), buf, hGSPProcess, gspPatchAddr, 16); + copyRemoteMemory(getCurrentProcessHandle(), buf, hGSPProcess, (void*) gspPatchAddr, 16); if (memcmp(buf, desiredHeader, 16) == 0) { goto requirePatch; @@ -663,7 +678,7 @@ int checkBacklightSupported() { // 11.3.0 gspPatchAddr = 0x0010743C; - copyRemoteMemory(getCurrentProcessHandle(), buf, hGSPProcess, gspPatchAddr, 16); + copyRemoteMemory(getCurrentProcessHandle(), buf, hGSPProcess, (void*) gspPatchAddr, 16); if (memcmp(buf, desiredHeader, 16) == 0) { goto requirePatch; @@ -694,7 +709,10 @@ int patchGSP() { return 0; } u32 ret; - Handle hGSPProcess = 0; + + //Unused + //Handle hGSPProcess = 0; + u32 buf[4] = { 0, 0 }; ret = writeRemoteProcessMemory(GSPPid, gspPatchAddr + 0x68, 4, buf); ret = writeRemoteProcessMemory(GSPPid, gspPatchAddr + 0xC8, 4, buf); @@ -742,8 +760,8 @@ u32 backlightMenu() { u8 buf[50]; while (1) { blank(0, 0, 320, 240); - xsprintf(buf, "backlight: %d", bklightValue); - print(buf, 10, 10, 255, 0, 0); + xsprintf((char*) buf, "backlight: %d", bklightValue); + print((char*) buf, 10, 10, 255, 0, 0); print(plgTranslate("Press Up/Down/Left/Right to adjust."), 10, 220, 0, 0, 255); updateScreen(); u32 key = waitKey(); @@ -768,22 +786,25 @@ u32 backlightMenu() { u32 nightShiftUi() { int configUpdated = 0; - u8 buf[200]; + + //Unused + //u8 buf[200]; + acquireVideo(); u8* entries[11]; u32 r; - entries[0] = plgTranslate("Disabled"); - entries[1] = plgTranslate("Reduce Blue Light Level 1"); - entries[2] = plgTranslate("Reduce Blue Light Level 2"); - entries[3] = plgTranslate("Reduce Blue Light Level 3"); - entries[4] = plgTranslate("Reduce Blue Light Level 4"); - entries[5] = plgTranslate("Reduce Blue Light Level 5"); - entries[6] = plgTranslate("Invert Colors"); - entries[7] = plgTranslate("Grayscale"); - entries[8] = plgTranslate("Hint: Must be enabled before starting game. Will set CPU to L2+804MHz on New3DS."); + entries[0] = (u8*) plgTranslate("Disabled"); + entries[1] = (u8*) plgTranslate("Reduce Blue Light Level 1"); + entries[2] = (u8*) plgTranslate("Reduce Blue Light Level 2"); + entries[3] = (u8*) plgTranslate("Reduce Blue Light Level 3"); + entries[4] = (u8*) plgTranslate("Reduce Blue Light Level 4"); + entries[5] = (u8*) plgTranslate("Reduce Blue Light Level 5"); + entries[6] = (u8*) plgTranslate("Invert Colors"); + entries[7] = (u8*) plgTranslate("Grayscale"); + entries[8] = (u8*) plgTranslate("Hint: Must be enabled before starting game. Will set CPU to L2+804MHz on New3DS."); while (1) { blank(0, 0, 320, 240); - r = showMenu(plgTranslate("Screen Filter"), 8, entries); + r = showMenu((u8*) plgTranslate("Screen Filter"), 8, entries); if (r == -1) { break; @@ -805,17 +826,18 @@ u32 nightShiftUi() { } return 1; } -int screenshotMain() { - u32 retv; +int screenshotMain() { + //Unused + //u32 retv; - nsDbgPrint("initializing screenshot plugin\n"); + nsDbgPrint((const char*) "initializing screenshot plugin\n"); plgRegisterMenuEntry(1, plgTranslate("Take Screenshot"), takeScreenShot); plgRegisterMenuEntry(1, plgTranslate("Real-Time Save (Experimental)"), instantSaveMenu); - nsDbgPrint("fsUserHandle: %08x\n", fsUserHandle); + nsDbgPrint((const char*) "fsUserHandle: %08x\n", fsUserHandle); bmp_index = get_file_index(); - nsDbgPrint("bmp index is: %d", bmp_index); + nsDbgPrint((const char*) "bmp index is: %d", bmp_index); if (ntrConfig->isNew3DS) { plgRegisterMenuEntry(1, plgTranslate("CPU Clock (New3DS Only)"), cpuClockUi); @@ -827,6 +849,8 @@ int screenshotMain() { plgRegisterMenuEntry(1, plgTranslate("Screen Filter"), nightShiftUi); + //Does nothing. + return 0; } diff --git a/source/ui.c b/source/ui.c index 920be046..24822867 100644 --- a/source/ui.c +++ b/source/ui.c @@ -12,7 +12,7 @@ u32 hGSPProcess = 0; int builtinDrawString(u8* str, int x, int y, char r, char g, char b, int newLine) { - int len = strlen(str); + int len = strlen((const char*) str); int i, chWidth, currentX = x, totalLen = 0; for (i = 0; i < len; i++) { @@ -44,7 +44,7 @@ int drawString(u8* str, int x, int y, char r, char g, char b, int newLine) { } void print(char* s, int x, int y, char r, char g, char b){ - drawString(s, x, y, r, g, b, 1); + drawString((u8*) s, x, y, r, g, b, 1); } @@ -53,12 +53,14 @@ u32 getPhysAddr(u32 vaddr) { if(vaddr >= 0x30000000 && vaddr<0x40000000)return vaddr - 0x10000000;//Only available under system-version v8.0 for certain processes, see here: http://3dbrew.org/wiki/SVC#enum_MemoryOperation if(vaddr >= 0x1F000000 && vaddr<0x1F600000)return vaddr - 0x07000000;//VRAM + //TODO(Thompson): What to return?? + return 0; } u32 initDirectScreenAccess() { - u32 outAddr, ret; - - ret = protectMemory(0x1F000000, 0x600000); + u32 ret; //, outAddr + uintptr_t temp = 0x1F000000; + ret = protectMemory((void*) temp, 0x600000); if (ret != 0) { return ret; } @@ -88,6 +90,7 @@ u32 controlVideo(u32 cmd, u32 arg1, u32 arg2, u32 arg3) { updateScreen(); return 0; } + return 0; } @@ -122,17 +125,13 @@ void updateScreen() { svc_flushProcessDataCache(0xffff8001, BOTTOM_FRAME1, BOTTOM_FRAME_SIZE); } -s32 showMenu(u8* title, u32 entryCount, u8* captions[]) { - return showMenuEx(title, entryCount, captions, 0, 0); -} - s32 showMenuEx(u8* title, u32 entryCount, u8* captions[], u8* descriptions[], u32 selectOn) { u32 maxCaptions = 10; u32 i; s32 select = 0; u8 buf[200]; u32 pos; - u32 x = 10, y = 10, key = 0; + u32 x = 10, key = 0; //y = 10; u32 drawStart, drawEnd; if (selectOn < entryCount) { @@ -142,7 +141,7 @@ s32 showMenuEx(u8* title, u32 entryCount, u8* captions[], u8* descriptions[], u while(1) { blank(0, 0, 320, 240); pos = 10; - print(title, x, pos, 255, 0, 0); + print((char*) title, x, pos, 255, 0, 0); print("http://44670.org/ntr", 10, 220, 0, 0, 255); pos += 20; drawStart = (select / maxCaptions) * maxCaptions; @@ -151,14 +150,14 @@ s32 showMenuEx(u8* title, u32 entryCount, u8* captions[], u8* descriptions[], u drawEnd = entryCount; } for (i = drawStart; i < drawEnd; i++) { - strcpy(buf, (i == select) ? " * " : " "); - strcat(buf, captions[i]); - print(buf, x, pos, 0, 0, 0); + strcpy((char*) buf, (i == select) ? " * " : " "); + strcat((char*) buf, *((char**) captions[i])); + print((char*) buf, x, pos, 0, 0, 0); pos += 13; } if (descriptions) { if (descriptions[select]) { - print(descriptions[select], x, pos, 0, 0, 255); + print(*((char**) descriptions[select]), x, pos, 0, 0, 255); } } updateScreen(); @@ -184,17 +183,21 @@ s32 showMenuEx(u8* title, u32 entryCount, u8* captions[], u8* descriptions[], u } } +s32 showMenu(u8* title, u32 entryCount, u8* captions[]) { + return showMenuEx(title, entryCount, captions, 0, 0); +} + int showMsgNoPause(u8* msg) { if (ShowDbgFunc) { - typedef void(*funcType)(char*); + typedef void(*funcType)(u8*); ((funcType)(ShowDbgFunc))(msg); - return 0; } + return 0; } int showMsg(u8* msg) { if (ShowDbgFunc) { - typedef void(*funcType)(char*); + typedef void(*funcType)(u8*); ((funcType)(ShowDbgFunc))(msg); svc_sleepThread(1000000000); return 0; @@ -207,7 +210,7 @@ int showMsg(u8* msg) { while(1) { blank(0, 0, 320, 240); - print(msg, 10, 10, 255, 0, 0); + print((char*) msg, 10, 10, 255, 0, 0); print(plgTranslate("Press [B] to close."), 10, 220, 0, 0, 255); updateScreen(); u32 key = waitKey(); @@ -222,8 +225,8 @@ int showMsg(u8* msg) { void showDbg(u8* fmt, u32 v1, u32 v2) { u8 buf[400]; - nsDbgPrint(fmt, v1, v2); - xsprintf(buf, fmt, v1, v2); + nsDbgPrint((const char*) fmt, v1, v2); + xsprintf((char*) buf, (const char*) fmt, v1, v2); showMsg(buf); } diff --git a/source/util.c b/source/util.c index 0618d6e4..9db51ea0 100644 --- a/source/util.c +++ b/source/util.c @@ -31,11 +31,11 @@ void dbg(u8* key, u32 value) { u8 buf[200], buf2[20]; u32 t = 0; buf[0] = 0; - mystrcat(buf, "/dbg"); + mystrcat(buf, (u8*) "/dbg"); mystrcat(buf, key); myitoa(value, buf2); mystrcat(buf, buf2); - FS_path testPath = (FS_path){PATH_CHAR, strlen(buf) + 1, buf}; + FS_path testPath = (FS_path){PATH_CHAR, strlen((const char*) buf) + 1, buf}; FSUSER_OpenFileDirectly(fsUserHandle, &t, sdmcArchive, testPath, 7, 0); if (t != 0) { FSFILE_Close(t); diff --git a/source/xprintf.c b/source/xprintf.c index 69d2c392..dfc82617 100644 --- a/source/xprintf.c +++ b/source/xprintf.c @@ -15,7 +15,6 @@ #if _USE_XFUNC_OUT -#include void (*xfunc_out)(unsigned char); /* Pointer to the output stream */ static char *outptr;