├── .gitignore ├── LICENSE ├── Makefile ├── data └── launch_image.tga ├── ios_bsp ├── Makefile ├── link.ld └── source │ ├── fsa.c │ ├── fsa.h │ ├── seeprom.c │ ├── seeprom_asm.s │ ├── svc.h │ ├── svc.s │ └── types.h ├── ios_fs ├── Makefile ├── link.ld └── source │ ├── devices.c │ ├── devices.h │ ├── dumper.c │ ├── dumper.h │ ├── fat │ ├── fat_access.c │ ├── fat_access.h │ ├── fat_cache.c │ ├── fat_cache.h │ ├── fat_defs.h │ ├── fat_filelib.c │ ├── fat_filelib.h │ ├── fat_format.c │ ├── fat_format.h │ ├── fat_list.h │ ├── fat_misc.c │ ├── fat_misc.h │ ├── fat_opts.h │ ├── fat_string.c │ ├── fat_string.h │ ├── fat_table.c │ ├── fat_table.h │ ├── fat_types.h │ ├── fat_write.c │ └── fat_write.h │ ├── font.c │ ├── font_bin.h │ ├── fs_config.h │ ├── function_hooks.s │ ├── hardware_registers.h │ ├── imports.h │ ├── main.c │ ├── mlcio.c │ ├── mlcio.h │ ├── sd_fat.c │ ├── sd_fat.h │ ├── sdio.c │ ├── sdio.h │ ├── svc.h │ ├── svc.s │ ├── text.c │ ├── text.h │ └── types.h ├── ios_kernel ├── Makefile ├── link.ld └── source │ ├── config.h │ ├── crt0.s │ ├── elf_abi.h │ ├── elf_patcher.c │ ├── elf_patcher.h │ ├── exception_handler.c │ ├── exception_handler.h │ ├── font_bin.h │ ├── fsa.c │ ├── fsa.h │ ├── instant_patches.c │ ├── instant_patches.h │ ├── ios_bsp_patches.c │ ├── ios_bsp_patches.h │ ├── ios_fs_patches.c │ ├── ios_fs_patches.h │ ├── ios_fs_patches_asm.s │ ├── ios_mcp_patches.c │ ├── ios_mcp_patches.h │ ├── ios_mcp_patches_asm.s │ ├── kernel_patches.c │ ├── kernel_patches.h │ ├── kernel_patches_asm.s │ ├── main.c │ ├── redirection_setup.c │ ├── redirection_setup.h │ ├── text.c │ ├── text.h │ ├── types.h │ ├── utils.c │ └── utils.h ├── ios_mcp ├── Makefile ├── link.ld ├── source │ ├── crt0.s │ ├── font.c │ ├── font_bin.h │ ├── fsa.c │ ├── fsa.h │ ├── imports.c │ ├── imports.h │ ├── ipc.c │ ├── ipc.h │ ├── ipc_types.h │ ├── logger.c │ ├── logger.h │ ├── main.c │ ├── net_ifmgr_ncl.c │ ├── net_ifmgr_ncl.h │ ├── socket.c │ ├── socket.h │ ├── svc.h │ ├── svc.s │ ├── text.c │ ├── text.h │ └── types.h └── wupclient.py ├── ios_usb ├── Makefile ├── link.ld └── source │ ├── crt0.s │ └── main.c ├── libs ├── libc.a └── libgcc.a └── src ├── cfw_config.c ├── cfw_config.h ├── common ├── common.h ├── fs_defs.h ├── os_defs.h └── types.h ├── dynamic_libs ├── .gitattributes ├── .gitignore ├── README.md ├── fs_defs.h ├── fs_functions.c ├── fs_functions.h ├── gx2_functions.c ├── gx2_functions.h ├── gx2_types.h ├── os_functions.c ├── os_functions.h ├── os_types.h ├── socket_functions.c ├── socket_functions.h ├── sys_functions.c ├── sys_functions.h ├── vpad_functions.c └── vpad_functions.h ├── entry.c ├── fs ├── fs_utils.c ├── fs_utils.h ├── sd_fat_devoptab.c └── sd_fat_devoptab.h ├── ios_exploit.c ├── ios_exploit.h ├── link.ld ├── main.c ├── main.h ├── menu.c ├── menu.h ├── system ├── exception_handler.c ├── exception_handler.h ├── memory.c └── memory.h └── utils ├── logger.c ├── logger.h └── utils.h /.gitignore: -------------------------------------------------------------------------------- 1 | /*.elf 2 | /build 3 | /ios_bsp/build 4 | /ios_bsp/ios_bsp.bin.h 5 | /ios_bsp/ios_bsp_syms.h 6 | /ios_bsp/*.elf 7 | /ios_bsp/*.bin 8 | /ios_fs/build 9 | /ios_mcp/build 10 | /ios_mcp/*.elf 11 | /ios_mcp/ios_mcp_syms.h 12 | /ios_mcp/ios_mcp.bin.h 13 | /ios_mcp/*.bin 14 | /ios_fs/ios_fs_syms.h 15 | /ios_fs/ios_fs.bin.h 16 | /ios_fs/*.elf 17 | /ios_fs/*.bin 18 | /ios_kernel/*.bin 19 | /ios_kernel/ios_kernel.bin.h 20 | /ios_kernel/*.elf 21 | /ios_kernel/ios_kernel_syms.h 22 | /ios_kernel/build 23 | /ios_usb/*.bin 24 | /ios_usb/ios_usb.bin.h 25 | /ios_usb/*.elf 26 | /ios_usb/ios_usb_syms.h 27 | /ios_usb/build -------------------------------------------------------------------------------- /data/launch_image.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koolkdev/wiiu-nanddumper/70e8eed02045d9c7a87c8018f4c005896c83ae47/data/launch_image.tga -------------------------------------------------------------------------------- /ios_bsp/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(strip $(DEVKITARM)),) 2 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 3 | endif 4 | 5 | ifeq ($(filter $(DEVKITARM)/bin,$(PATH)),) 6 | export PATH:=$(DEVKITARM)/bin:$(PATH) 7 | endif 8 | 9 | CC = arm-none-eabi-gcc 10 | LINK = arm-none-eabi-gcc 11 | AS = arm-none-eabi-as 12 | OBJCOPY = arm-none-eabi-objcopy 13 | OBJDUMP = arm-none-eabi-objdump 14 | CFLAGS += -Wall -mbig-endian -std=gnu11 -mcpu=arm926ej-s -msoft-float -mfloat-abi=soft -Os 15 | LDFLAGS += -nostartfiles -nodefaultlibs -mbig-endian -Wl,-T,link.ld 16 | LIBDIRS += -L$(CURDIR)/../libs 17 | LIBS += -lgcc 18 | 19 | CFILES = $(wildcard source/*.c) 20 | BINFILES = $(wildcard data/*.bin) 21 | OFILES = $(BINFILES:data/%.bin=build/%.bin.o) 22 | OFILES += $(CFILES:source/%.c=build/%.o) 23 | DFILES = $(CFILES:source/%.c=build/%.d) 24 | SFILES = $(wildcard source/*.s) 25 | OFILES += $(SFILES:source/%.s=build/%.o) 26 | PROJECTNAME = ${shell basename "$(CURDIR)"} 27 | CWD = "$(CURDIR)"" 28 | 29 | #--------------------------------------------------------------------------------- 30 | # canned command sequence for binary data, taken from devkitARM 31 | #--------------------------------------------------------------------------------- 32 | define bin2o 33 | bin2s $< | $(AS) -EB -o $(@) 34 | endef 35 | 36 | .PHONY:=all dirs 37 | 38 | all: dirs $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 39 | 40 | dirs: 41 | @mkdir -p build 42 | 43 | $(PROJECTNAME).elf: $(OFILES) 44 | @echo "LD $@" 45 | @$(LINK) $(LDFLAGS) -o $(PROJECTNAME).elf $(sort $(filter-out build/crt0.o, $(OFILES))) $(LIBDIRS) $(LIBS) 46 | 47 | $(PROJECTNAME).bin: $(PROJECTNAME).elf 48 | @echo "OBJCOPY $@\n" 49 | @$(OBJCOPY) -j .text -j .rodata -j .data -O binary $(PROJECTNAME).elf $@ 50 | 51 | $(PROJECTNAME).bin.h: $(PROJECTNAME).bin 52 | @xxd -i $< | sed "s/unsigned/static const unsigned/g;s/$(PROJECTNAME)$*/$(PROJECTNAME)/g" > $@ 53 | 54 | $(PROJECTNAME)_syms.h: 55 | @echo "#ifndef $(PROJECTNAME)_SYMS_H" > $@ 56 | @echo "#define $(PROJECTNAME)_SYMS_H" >> $@ 57 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep 'g F .text' | grep -v '.hidden' | awk '{print "#define " $$6 " 0x" $$1}' >> $@ 58 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep -e 'g .text' -e '_bss_' -e "_seeprom_buffer_start" | awk '{print "#define " $$5 " 0x" $$1}' >> $@ 59 | @echo "#endif" >> $@ 60 | 61 | clean: 62 | @rm -f build/*.o build/*.d 63 | @rm -f $(PROJECTNAME).elf $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 64 | @echo "all cleaned up !" 65 | 66 | -include $(DFILES) 67 | 68 | build/%.o: source/%.c 69 | @echo "CC $(notdir $<)" 70 | @$(CC) $(CFLAGS) -c $< -o $@ 71 | @$(CC) -MM $< > build/$*.d 72 | 73 | build/%.o: source/%.s 74 | @echo "CC $(notdir $<)" 75 | @$(CC) $(CFLAGS) -xassembler-with-cpp -c $< -o $@ 76 | @$(CC) -MM $< > build/$*.d 77 | 78 | build/%.bin.o: data/%.bin 79 | @echo "BIN $(notdir $<)" 80 | @$(bin2o) 81 | -------------------------------------------------------------------------------- /ios_bsp/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(arm) 2 | 3 | SECTIONS 4 | { 5 | .text 0xE6010A80 : { 6 | _text_start = .; 7 | *(.text*); 8 | *(.rodata*); 9 | } 10 | _text_end = .; 11 | 12 | .bss 0xE60481F0 : { 13 | _bss_start = .; 14 | *(.bss*); 15 | *(COMMON); 16 | } 17 | .seeprom_buffer : { 18 | _seeprom_buffer_start = .; 19 | *(.seeprom_buffer*); 20 | } 21 | _bss_end = .; 22 | 23 | /DISCARD/ : { 24 | *(*); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /ios_bsp/source/fsa.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "svc.h" 4 | #include "fsa.h" 5 | 6 | #define BSP_memcpy ((void *(*)(void*, void*, unsigned int))0xE600EA18) 7 | #define BSP_memset ((void *(*)(void*, int, unsigned int))0xE600EAB4) 8 | #define BSP_strncpy ((char *(*)(char*, const char*, unsigned int))0xE600F4AC) 9 | 10 | static void* allocIobuf() 11 | { 12 | void* ptr = svcAlloc(0xCAFF, 0x828); 13 | BSP_memset(ptr, 0x00, 0x828); 14 | 15 | return ptr; 16 | } 17 | 18 | static void freeIobuf(void* ptr) 19 | { 20 | svcFree(0xCAFF, ptr); 21 | } 22 | 23 | int FSA_RawOpen(int fd, const char* device_path, int* outHandle) 24 | { 25 | u8* iobuf = allocIobuf(); 26 | u32* inbuf = (u32*)iobuf; 27 | u32* outbuf = (u32*)&iobuf[0x520]; 28 | 29 | BSP_strncpy((char*)&inbuf[0x01], device_path, 0x27F); 30 | 31 | int ret = svcIoctl(fd, 0x6A, inbuf, 0x520, outbuf, 0x293); 32 | 33 | if(outHandle) *outHandle = outbuf[1]; 34 | 35 | freeIobuf(iobuf); 36 | return ret; 37 | } 38 | 39 | int FSA_RawClose(int fd, int device_handle) 40 | { 41 | u8* iobuf = allocIobuf(); 42 | u32* inbuf = (u32*)iobuf; 43 | u32* outbuf = (u32*)&iobuf[0x520]; 44 | 45 | inbuf[1] = device_handle; 46 | 47 | int ret = svcIoctl(fd, 0x6D, inbuf, 0x520, outbuf, 0x293); 48 | 49 | freeIobuf(iobuf); 50 | return ret; 51 | } 52 | 53 | int FSA_RawWrite(int fd, void* data, u32 size_bytes, u32 cnt, u64 blocks_offset, int device_handle) 54 | { 55 | u8* iobuf = allocIobuf(); 56 | u8* inbuf8 = iobuf; 57 | u8* outbuf8 = &iobuf[0x520]; 58 | iovec_s* iovec = (iovec_s*)&iobuf[0x7C0]; 59 | u32* inbuf = (u32*)inbuf8; 60 | u32* outbuf = (u32*)outbuf8; 61 | 62 | inbuf[0x08 / 4] = (blocks_offset >> 32); 63 | inbuf[0x0C / 4] = (blocks_offset & 0xFFFFFFFF); 64 | inbuf[0x10 / 4] = cnt; 65 | inbuf[0x14 / 4] = size_bytes; 66 | inbuf[0x18 / 4] = device_handle; 67 | 68 | iovec[0].ptr = inbuf; 69 | iovec[0].len = 0x520; 70 | 71 | iovec[1].ptr = data; 72 | iovec[1].len = size_bytes * cnt; 73 | 74 | iovec[2].ptr = outbuf; 75 | iovec[2].len = 0x293; 76 | 77 | int ret = svcIoctlv(fd, 0x6C, 2, 1, iovec); 78 | 79 | freeIobuf(iobuf); 80 | return ret; 81 | } 82 | -------------------------------------------------------------------------------- /ios_bsp/source/fsa.h: -------------------------------------------------------------------------------- 1 | #ifndef FSA_H 2 | #define FSA_H 3 | 4 | #include "types.h" 5 | 6 | int FSA_RawOpen(int fd, const char* device_path, int* outHandle); 7 | int FSA_RawWrite(int fd, void* data, u32 size_bytes, u32 cnt, u64 sector_offset, int device_handle); 8 | int FSA_RawClose(int fd, int device_handle); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ios_bsp/source/seeprom.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "svc.h" 25 | #include "fsa.h" 26 | 27 | #define SD_SEEPROM_SECTOR 0x4FF 28 | 29 | #define BSP_MEMCPY ((void * (*)(void *, void *, unsigned int size))0xE600EA18) 30 | 31 | static int writeEnabled = 0; 32 | static int dirty = 0; 33 | 34 | unsigned char seeprom_buffer[512] __attribute__((section(".seeprom_buffer"))); 35 | 36 | extern int orig_EEPROM_SPI_ReadWord(int handle_index, unsigned char index, unsigned short *outbuf); 37 | 38 | static int SD_EEPROM_WriteAll(void) 39 | { 40 | int fsa = svcOpen("/dev/fsa", 0); 41 | if(fsa < 0) 42 | return fsa; 43 | 44 | int fd; 45 | int res = FSA_RawOpen(fsa, "/dev/sdcard01", &fd); 46 | if(res >= 0) 47 | { 48 | void *buffer = svcAllocAlign(0xCAFF, 0x200, 0x40); 49 | if(buffer) 50 | { 51 | // user global buffer for FSA to be able to access it 52 | BSP_MEMCPY(buffer, seeprom_buffer, 0x200); 53 | res = FSA_RawWrite(fsa, buffer, 0x200, 1, SD_SEEPROM_SECTOR, fd); 54 | svcFree(0xCAFF, buffer); 55 | } 56 | else 57 | res = -1; 58 | 59 | FSA_RawClose(fsa, fd); 60 | } 61 | svcClose(fsa); 62 | return res; 63 | } 64 | 65 | static void EEPROM_InitializeCache(int handle_index) 66 | { 67 | int i; 68 | for(i = 0; i < 0x100; i++) 69 | { 70 | orig_EEPROM_SPI_ReadWord(handle_index, i, (unsigned short*)(seeprom_buffer + (i << 1))); 71 | } 72 | } 73 | 74 | int EEPROM_SPI_ReadWord(int handle_index, unsigned char index, unsigned short *outbuf) 75 | { 76 | unsigned int offset = ((unsigned int)index) << 1; 77 | 78 | // check for valid eeprom dump and initialize if none was on sd card 79 | if(*(u32*)(seeprom_buffer + 0x20) != 0x70010201) // PPC PVR 80 | { 81 | EEPROM_InitializeCache(handle_index); // could actually just use 0 for handle index 82 | dirty = 1; 83 | } 84 | 85 | // don't redirect the drive key as it is specific for the drive on the wii u 86 | // the seeprom key is the same for all wiiu's it seems so nothing to re-encrypt here 87 | if(offset >= 0x80 && offset < 0x90) 88 | { 89 | return orig_EEPROM_SPI_ReadWord(handle_index, index, outbuf); 90 | } 91 | 92 | if(!outbuf || (offset >= 512)) 93 | { 94 | return -5; 95 | } 96 | 97 | *outbuf = *(unsigned short*)(seeprom_buffer + offset); 98 | 99 | if(dirty && SD_EEPROM_WriteAll() == 0) 100 | { 101 | dirty = 0; 102 | } 103 | return 0; 104 | } 105 | 106 | int EEPROM_SPI_WriteWord(int handle_index, unsigned char index, unsigned short data) 107 | { 108 | if(writeEnabled == 0) 109 | { 110 | return -5; 111 | } 112 | 113 | // check for valid eeprom dump and initialize if none was on sd card 114 | if(*(u32*)(seeprom_buffer + 0x20) != 0x70010201) // PPC PVR 115 | { 116 | EEPROM_InitializeCache(handle_index); // could actually just use 0 for handle index 117 | } 118 | 119 | unsigned int offset = ((unsigned int)index) << 1; 120 | 121 | if(offset >= 512) 122 | { 123 | return -5; 124 | } 125 | 126 | *(unsigned short*)(seeprom_buffer + offset) = data; 127 | dirty = 1; 128 | 129 | if(SD_EEPROM_WriteAll() == 0) 130 | { 131 | dirty = 0; 132 | } 133 | 134 | return 0; 135 | } 136 | 137 | int EEPROM_WriteControl(int handle_index, int type) 138 | { 139 | if(type == 1) 140 | { 141 | writeEnabled = 0; 142 | } 143 | else if(type == 2) 144 | { 145 | writeEnabled = 1; 146 | } 147 | else if(type == 3) 148 | { 149 | // erase all -> skip that part...its actually never used but would be only a memset with 0xFF 150 | } 151 | else 152 | { 153 | return -4; 154 | } 155 | return 0; 156 | } 157 | -------------------------------------------------------------------------------- /ios_bsp/source/seeprom_asm.s: -------------------------------------------------------------------------------- 1 | .section ".text" 2 | .arm 3 | 4 | .globl orig_EEPROM_SPI_ReadWord 5 | orig_EEPROM_SPI_ReadWord: 6 | cmp r0, #0 7 | ldr r3, [pc] 8 | bx r3 9 | .word 0xE600D090 10 | -------------------------------------------------------------------------------- /ios_bsp/source/svc.h: -------------------------------------------------------------------------------- 1 | #ifndef SVC_H 2 | #define SVC_H 3 | 4 | #include "types.h" 5 | 6 | typedef struct 7 | { 8 | void* ptr; 9 | u32 len; 10 | u32 unk; 11 | }iovec_s; 12 | 13 | void* svcAlloc(u32 heapid, u32 size); 14 | void* svcAllocAlign(u32 heapid, u32 size, u32 align); 15 | void svcFree(u32 heapid, void* ptr); 16 | int svcOpen(char* name, int mode); 17 | int svcClose(int fd); 18 | int svcIoctl(int fd, u32 request, void* input_buffer, u32 input_buffer_len, void* output_buffer, u32 output_buffer_len); 19 | int svcIoctlv(int fd, u32 request, u32 vector_count_in, u32 vector_count_out, iovec_s* vector); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /ios_bsp/source/svc.s: -------------------------------------------------------------------------------- 1 | .section ".text" 2 | .arm 3 | .align 4 4 | 5 | .global svcAlloc 6 | .type svcAlloc, %function 7 | svcAlloc: 8 | .word 0xE7F027F0 9 | bx lr 10 | 11 | .global svcAllocAlign 12 | .type svcAllocAlign, %function 13 | svcAllocAlign: 14 | .word 0xE7F028F0 15 | bx lr 16 | 17 | .global svcFree 18 | .type svcFree, %function 19 | svcFree: 20 | .word 0xE7F029F0 21 | bx lr 22 | 23 | .global svcOpen 24 | .type svcOpen, %function 25 | svcOpen: 26 | .word 0xE7F033F0 27 | bx lr 28 | 29 | .global svcClose 30 | .type svcClose, %function 31 | svcClose: 32 | .word 0xE7F034F0 33 | bx lr 34 | 35 | .global svcIoctl 36 | .type svcIoctl, %function 37 | svcIoctl: 38 | .word 0xE7F038F0 39 | bx lr 40 | 41 | .global svcIoctlv 42 | .type svcIoctlv, %function 43 | svcIoctlv: 44 | .word 0xE7F039F0 45 | bx lr 46 | -------------------------------------------------------------------------------- /ios_bsp/source/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPES_H 2 | #define TYPES_H 3 | 4 | #include 5 | #include 6 | 7 | #define U64_MAX UINT64_MAX 8 | 9 | typedef uint8_t u8; 10 | typedef uint16_t u16; 11 | typedef uint32_t u32; 12 | typedef uint64_t u64; 13 | 14 | typedef int8_t s8; 15 | typedef int16_t s16; 16 | typedef int32_t s32; 17 | typedef int64_t s64; 18 | 19 | typedef volatile u8 vu8; 20 | typedef volatile u16 vu16; 21 | typedef volatile u32 vu32; 22 | typedef volatile u64 vu64; 23 | 24 | typedef volatile s8 vs8; 25 | typedef volatile s16 vs16; 26 | typedef volatile s32 vs32; 27 | typedef volatile s64 vs64; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ios_fs/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(strip $(DEVKITARM)),) 2 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 3 | endif 4 | 5 | ifeq ($(filter $(DEVKITARM)/bin,$(PATH)),) 6 | export PATH:=$(DEVKITARM)/bin:$(PATH) 7 | endif 8 | 9 | CC = arm-none-eabi-gcc 10 | LINK = arm-none-eabi-gcc 11 | AS = arm-none-eabi-as 12 | OBJCOPY = arm-none-eabi-objcopy 13 | OBJDUMP = arm-none-eabi-objdump 14 | CFLAGS += -Wall -mbig-endian -std=gnu11 -mcpu=arm926ej-s -msoft-float -mfloat-abi=soft -Os 15 | LDFLAGS += -nostartfiles -nodefaultlibs -mbig-endian -Wl,-T,link.ld 16 | LIBDIRS += -L$(CURDIR)/../libs 17 | LIBS += -lgcc 18 | 19 | CFILES = $(wildcard source/*.c) 20 | FAT_CFILES += $(wildcard source/fat/*.c) 21 | BINFILES = $(wildcard data/*.bin) 22 | OFILES = $(BINFILES:data/%.bin=build/%.bin.o) 23 | OFILES += $(CFILES:source/%.c=build/%.o) 24 | OFILES += $(FAT_CFILES:source/fat/%.c=build/%.o) 25 | DFILES = $(CFILES:source/%.c=build/%.d) 26 | DFILES += $(FAT_CFILES:source/fat/%.c=build/%.d) 27 | SFILES = $(wildcard source/*.s) 28 | OFILES += $(SFILES:source/%.s=build/%.o) 29 | PROJECTNAME = ${shell basename "$(CURDIR)"} 30 | CWD = "$(CURDIR)"" 31 | 32 | #--------------------------------------------------------------------------------- 33 | # canned command sequence for binary data, taken from devkitARM 34 | #--------------------------------------------------------------------------------- 35 | define bin2o 36 | bin2s $< | $(AS) -EB -o $(@) 37 | endef 38 | 39 | .PHONY:=all dirs 40 | 41 | all: dirs $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 42 | 43 | dirs: 44 | @mkdir -p build 45 | 46 | $(PROJECTNAME).elf: $(OFILES) 47 | @echo "LD $@" 48 | @$(LINK) $(LDFLAGS) -o $(PROJECTNAME).elf $(sort $(filter-out build/crt0.o, $(OFILES))) $(LIBDIRS) $(LIBS) 49 | 50 | $(PROJECTNAME).bin: $(PROJECTNAME).elf 51 | @echo "OBJCOPY $@\n" 52 | @$(OBJCOPY) -j .text -j .rodata -j .data -O binary $(PROJECTNAME).elf $@ 53 | 54 | $(PROJECTNAME).bin.h: $(PROJECTNAME).bin 55 | @xxd -i $< | sed "s/unsigned/static const unsigned/g;s/$(PROJECTNAME)$*/$(PROJECTNAME)/g" > $@ 56 | 57 | $(PROJECTNAME)_syms.h: 58 | @echo "#ifndef $(PROJECTNAME)_SYMS_H" > $@ 59 | @echo "#define $(PROJECTNAME)_SYMS_H" >> $@ 60 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep 'g F .text' | grep -v '.hidden' | awk '{print "#define " $$6 " 0x" $$1}' >> $@ 61 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep -e 'g .text' -e '_bss_' | awk '{print "#define " $$5 " 0x" $$1}' >> $@ 62 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep -e 'g O .dumper_config' | awk '{print "#define " $$6 " 0x" $$1}' >> $@ 63 | @echo "#endif" >> $@ 64 | 65 | clean: 66 | @rm -f build/*.o build/*.d 67 | @rm -f $(PROJECTNAME).elf $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 68 | @echo "all cleaned up !" 69 | 70 | -include $(DFILES) 71 | 72 | build/%.o: source/%.c 73 | @echo "CC $(notdir $<)" 74 | @$(CC) $(CFLAGS) -c $< -o $@ 75 | @$(CC) -MM $< > build/$*.d 76 | 77 | build/%.o: source/fat/%.c 78 | @echo "CC $(notdir $<)" 79 | @$(CC) $(CFLAGS) -c $< -o $@ 80 | @$(CC) -MM $< > build/$*.d 81 | 82 | build/%.o: source/%.s 83 | @echo "CC $(notdir $<)" 84 | @$(CC) $(CFLAGS) -xassembler-with-cpp -c $< -o $@ 85 | @$(CC) -MM $< > build/$*.d 86 | 87 | build/%.bin.o: data/%.bin 88 | @echo "BIN $(notdir $<)" 89 | @$(bin2o) 90 | -------------------------------------------------------------------------------- /ios_fs/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(arm) 2 | 3 | SECTIONS 4 | { 5 | .text (0x10700000 + 0x000F8200) : { 6 | _text_start = .; 7 | *(.text*); 8 | *(.rodata*); 9 | } 10 | _text_end = .; 11 | .dumper_config : { 12 | *(.dumper_config*); 13 | } 14 | 15 | .bss (0x10835000 + 0x1406554) : { 16 | _bss_start = .; 17 | *(.bss*); 18 | *(COMMON); 19 | } 20 | .io_buffer : ALIGN(0x40) { 21 | *(.io_buffer*); 22 | } 23 | _bss_end = .; 24 | 25 | /DISCARD/ : { 26 | *(*); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /ios_fs/source/devices.h: -------------------------------------------------------------------------------- 1 | #ifndef DEVICES_H_ 2 | #define DEVICES_H_ 3 | 4 | #define DEVICE_TYPE_SDCARD 0x06 5 | 6 | #define DEVICE_ID_SDCARD_REAL 0x43 7 | #define DEVICE_ID_SDCARD_PATCHED 0xDA 8 | 9 | #define DEVICE_ID_MLC 0xAB 10 | 11 | #define SDIO_BYTES_PER_SECTOR 512 12 | #define MLC_BYTES_PER_SECTOR 512 13 | #define SLC_BYTES_PER_SECTOR (2048+64) 14 | 15 | #define SLC_BASE_SECTORS (0x000500) 16 | #define SLCCMPT_BASE_SECTORS (0x100500) 17 | #define MLC_BASE_SECTORS (0x200500) 18 | 19 | #define USB_BASE_SECTORS (0x2720000) 20 | #define SYSLOG_BASE_SECTORS (0x6D00000) 21 | #define DUMPDATA_BASE_SECTORS (SYSLOG_BASE_SECTORS + (0x40000 / SDIO_BYTES_PER_SECTOR)) 22 | 23 | #define SLC_SECTOR_COUNT 0x40000 24 | #define MLC_8GB_SECTOR_COUNT 0xE90000 25 | #define MLC_32GB_SECTOR_COUNT 0x3A3E000 //0x3A20000 26 | 27 | #define MLC_NAND_TYPE_32GB 0 28 | #define MLC_NAND_TYPE_8GB 1 29 | 30 | #define NAND_DUMP_SIGNATURE_SECTOR 0x01 31 | #define NAND_DUMP_SIGNATURE 0x4841585844554d50ULL // HAXXDUMP 32 | 33 | #define NAND_DESC_TYPE_SLC 0x534c4320 // 'SLC ' 34 | #define NAND_DESC_TYPE_SLCCMPT 0x534c4332 // 'SLC2' 35 | #define NAND_DESC_TYPE_MLC 0x4d4c4320 // 'MLC ' 36 | 37 | typedef struct _stdio_nand_desc_t 38 | { 39 | u32 nand_type; // nand type 40 | u32 base_sector; // base sector of dump 41 | u32 sector_count; // sector count in SDIO sectors 42 | } __attribute__((packed))stdio_nand_desc_t; 43 | 44 | typedef struct _sdio_nand_signature_sector_t 45 | { 46 | u64 signature; // HAXXDUMP 47 | stdio_nand_desc_t nand_descriptions[3]; 48 | } __attribute__((packed)) sdio_nand_signature_sector_t; 49 | 50 | 51 | typedef void (*read_write_callback_t)(int, int); 52 | 53 | int getPhysicalDeviceHandle(u32 device); 54 | 55 | int slcRead1_original(void *physical_device_info, u32 offset_high, u32 offset_low, u32 cnt, u32 block_size, void *data_outptr, read_write_callback_t callback, int callback_parameter); 56 | int sdcardRead_original(void *physical_device_info, u32 offset_high, u32 offset_low, u32 cnt, u32 block_size, void *data_outptr, read_write_callback_t callback, int callback_parameter); 57 | 58 | #endif // DEVICES_H_ 59 | -------------------------------------------------------------------------------- /ios_fs/source/dumper.h: -------------------------------------------------------------------------------- 1 | #ifndef _DUMPER_H_ 2 | #define _DUMPER_H_ 3 | 4 | //! debug dumps 5 | //void dump_syslog(); 6 | //void dump_data(void* data_ptr, u32 size); 7 | //void dump_lots_data(u8* addr, u32 size); 8 | 9 | int check_nand_type(void); 10 | void slc_dump(int deviceId, const char* format, char* filename); 11 | void mlc_dump(u32 mlc_end, int y_offset); 12 | void dump_nand_complete(); 13 | 14 | #endif // _DUMPER_H_ 15 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_cache.c: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | //----------------------------------------------------------------------------- 3 | // FAT16/32 File IO Library 4 | // V2.6 5 | // Ultra-Embedded.com 6 | // Copyright 2003 - 2012 7 | // 8 | // Email: admin@ultra-embedded.com 9 | // 10 | // License: GPL 11 | // If you would like a version with a more permissive license for use in 12 | // closed source commercial applications please contact me for details. 13 | //----------------------------------------------------------------------------- 14 | // 15 | // This file is part of FAT File IO Library. 16 | // 17 | // FAT File IO Library is free software; you can redistribute it and/or modify 18 | // it under the terms of the GNU General Public License as published by 19 | // the Free Software Foundation; either version 2 of the License, or 20 | // (at your option) any later version. 21 | // 22 | // FAT File IO Library is distributed in the hope that it will be useful, 23 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | // GNU General Public License for more details. 26 | // 27 | // You should have received a copy of the GNU General Public License 28 | // along with FAT File IO Library; if not, write to the Free Software 29 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30 | //----------------------------------------------------------------------------- 31 | //----------------------------------------------------------------------------- 32 | #include "../imports.h" 33 | #include "fat_cache.h" 34 | 35 | // Per file cluster chain caching used to improve performance. 36 | // This does not have to be enabled for architectures with low 37 | // memory space. 38 | 39 | //----------------------------------------------------------------------------- 40 | // fatfs_cache_init: 41 | //----------------------------------------------------------------------------- 42 | int fatfs_cache_init(struct fatfs *fs, FL_FILE *file) 43 | { 44 | #ifdef FAT_CLUSTER_CACHE_ENTRIES 45 | int i; 46 | 47 | for (i=0;icluster_cache_idx[i] = 0xFFFFFFFF; // Not used 50 | file->cluster_cache_data[i] = 0; 51 | } 52 | #endif 53 | 54 | return 1; 55 | } 56 | //----------------------------------------------------------------------------- 57 | // fatfs_cache_get_next_cluster: 58 | //----------------------------------------------------------------------------- 59 | int fatfs_cache_get_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 *pNextCluster) 60 | { 61 | #ifdef FAT_CLUSTER_CACHE_ENTRIES 62 | uint32 slot = clusterIdx % FAT_CLUSTER_CACHE_ENTRIES; 63 | 64 | if (file->cluster_cache_idx[slot] == clusterIdx) 65 | { 66 | *pNextCluster = file->cluster_cache_data[slot]; 67 | return 1; 68 | } 69 | #endif 70 | 71 | return 0; 72 | } 73 | //----------------------------------------------------------------------------- 74 | // fatfs_cache_set_next_cluster: 75 | //----------------------------------------------------------------------------- 76 | int fatfs_cache_set_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 nextCluster) 77 | { 78 | #ifdef FAT_CLUSTER_CACHE_ENTRIES 79 | uint32 slot = clusterIdx % FAT_CLUSTER_CACHE_ENTRIES; 80 | 81 | if (file->cluster_cache_idx[slot] == clusterIdx) 82 | file->cluster_cache_data[slot] = nextCluster; 83 | else 84 | { 85 | file->cluster_cache_idx[slot] = clusterIdx; 86 | file->cluster_cache_data[slot] = nextCluster; 87 | } 88 | #endif 89 | 90 | return 1; 91 | } 92 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_CACHE_H__ 2 | #define __FAT_CACHE_H__ 3 | 4 | #include "fat_filelib.h" 5 | 6 | //----------------------------------------------------------------------------- 7 | // Prototypes 8 | //----------------------------------------------------------------------------- 9 | int fatfs_cache_init(struct fatfs *fs, FL_FILE *file); 10 | int fatfs_cache_get_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 *pNextCluster); 11 | int fatfs_cache_set_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 nextCluster); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_filelib.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_FILELIB_H__ 2 | #define __FAT_FILELIB_H__ 3 | 4 | #include "fat_opts.h" 5 | #include "fat_access.h" 6 | #include "fat_list.h" 7 | 8 | //----------------------------------------------------------------------------- 9 | // Defines 10 | //----------------------------------------------------------------------------- 11 | #ifndef SEEK_CUR 12 | #define SEEK_CUR 1 13 | #endif 14 | 15 | #ifndef SEEK_END 16 | #define SEEK_END 2 17 | #endif 18 | 19 | #ifndef SEEK_SET 20 | #define SEEK_SET 0 21 | #endif 22 | 23 | #ifndef EOF 24 | #define EOF (-1) 25 | #endif 26 | 27 | //----------------------------------------------------------------------------- 28 | // Structures 29 | //----------------------------------------------------------------------------- 30 | struct sFL_FILE; 31 | 32 | struct cluster_lookup 33 | { 34 | uint32 ClusterIdx; 35 | uint32 CurrentCluster; 36 | }; 37 | 38 | typedef struct sFL_FILE 39 | { 40 | uint32 parentcluster; 41 | uint32 startcluster; 42 | uint32 bytenum; 43 | uint32 filelength; 44 | int filelength_changed; 45 | char path[FATFS_MAX_LONG_FILENAME]; 46 | char filename[FATFS_MAX_LONG_FILENAME]; 47 | uint8 shortfilename[11]; 48 | 49 | #ifdef FAT_CLUSTER_CACHE_ENTRIES 50 | uint32 cluster_cache_idx[FAT_CLUSTER_CACHE_ENTRIES]; 51 | uint32 cluster_cache_data[FAT_CLUSTER_CACHE_ENTRIES]; 52 | #endif 53 | 54 | // Cluster Lookup 55 | struct cluster_lookup last_fat_lookup; 56 | 57 | // Read/Write sector buffer 58 | uint8 file_data_sector[FAT_SECTOR_SIZE]; 59 | uint32 file_data_address; 60 | int file_data_dirty; 61 | 62 | // File fopen flags 63 | uint8 flags; 64 | #define FILE_READ (1 << 0) 65 | #define FILE_WRITE (1 << 1) 66 | #define FILE_APPEND (1 << 2) 67 | #define FILE_BINARY (1 << 3) 68 | #define FILE_ERASE (1 << 4) 69 | #define FILE_CREATE (1 << 5) 70 | 71 | struct fat_node list_node; 72 | } FL_FILE; 73 | 74 | //----------------------------------------------------------------------------- 75 | // Prototypes 76 | //----------------------------------------------------------------------------- 77 | 78 | // External 79 | void fl_init(void); 80 | void fl_attach_locks(void (*lock)(void), void (*unlock)(void)); 81 | int fl_attach_media(fn_diskio_read rd, fn_diskio_write wr); 82 | void fl_shutdown(void); 83 | 84 | // Standard API 85 | void* fl_fopen(const char *path, const char *modifiers); 86 | void fl_fclose(void *file); 87 | int fl_fflush(void *file); 88 | int fl_fgetc(void *file); 89 | char * fl_fgets(char *s, int n, void *f); 90 | int fl_fputc(int c, void *file); 91 | int fl_fputs(const char * str, void *file); 92 | int fl_fwrite(const void * data, int size, int count, void *file ); 93 | int fl_fread(void * data, int size, int count, void *file ); 94 | int fl_fseek(void *file , long offset , int origin ); 95 | int fl_fgetpos(void *file , uint32 * position); 96 | long fl_ftell(void *f); 97 | int fl_feof(void *f); 98 | int fl_remove(const char * filename); 99 | 100 | // Equivelant dirent.h 101 | typedef struct fs_dir_list_status FL_DIR; 102 | typedef struct fs_dir_ent fl_dirent; 103 | 104 | FL_DIR* fl_opendir(const char* path, FL_DIR *dir); 105 | int fl_readdir(FL_DIR *dirls, fl_dirent *entry); 106 | int fl_closedir(FL_DIR* dir); 107 | 108 | // Extensions 109 | void fl_listdirectory(const char *path); 110 | int fl_createdirectory(const char *path); 111 | int fl_is_dir(const char *path); 112 | 113 | int fl_format(uint32 volume_sectors, const char *name); 114 | 115 | // Test hooks 116 | #ifdef FATFS_INC_TEST_HOOKS 117 | struct fatfs* fl_get_fs(void); 118 | #endif 119 | 120 | //----------------------------------------------------------------------------- 121 | // Stdio file I/O names 122 | //----------------------------------------------------------------------------- 123 | #ifdef USE_FILELIB_STDIO_COMPAT_NAMES 124 | 125 | #define FILE FL_FILE 126 | 127 | #define fopen(a,b) fl_fopen(a, b) 128 | #define fclose(a) fl_fclose(a) 129 | #define fflush(a) fl_fflush(a) 130 | #define fgetc(a) fl_fgetc(a) 131 | #define fgets(a,b,c) fl_fgets(a, b, c) 132 | #define fputc(a,b) fl_fputc(a, b) 133 | #define fputs(a,b) fl_fputs(a, b) 134 | #define fwrite(a,b,c,d) fl_fwrite(a, b, c, d) 135 | #define fread(a,b,c,d) fl_fread(a, b, c, d) 136 | #define fseek(a,b,c) fl_fseek(a, b, c) 137 | #define fgetpos(a,b) fl_fgetpos(a, b) 138 | #define ftell(a) fl_ftell(a) 139 | #define feof(a) fl_feof(a) 140 | #define remove(a) fl_remove(a) 141 | #define mkdir(a) fl_createdirectory(a) 142 | #define rmdir(a) 0 143 | 144 | #endif 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_format.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_FORMAT_H__ 2 | #define __FAT_FORMAT_H__ 3 | 4 | #include "fat_defs.h" 5 | #include "fat_opts.h" 6 | #include "fat_access.h" 7 | 8 | //----------------------------------------------------------------------------- 9 | // Prototypes 10 | //----------------------------------------------------------------------------- 11 | int fatfs_format(struct fatfs *fs, uint32 volume_sectors, const char *name); 12 | int fatfs_format_fat16(struct fatfs *fs, uint32 volume_sectors, const char *name); 13 | int fatfs_format_fat32(struct fatfs *fs, uint32 volume_sectors, const char *name); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_list.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_LIST_H__ 2 | #define __FAT_LIST_H__ 3 | 4 | #ifndef FAT_ASSERT 5 | #define FAT_ASSERT(x) 6 | #endif 7 | 8 | #ifndef FAT_INLINE 9 | #define FAT_INLINE 10 | #endif 11 | 12 | //----------------------------------------------------------------- 13 | // Types 14 | //----------------------------------------------------------------- 15 | struct fat_list; 16 | 17 | struct fat_node 18 | { 19 | struct fat_node *previous; 20 | struct fat_node *next; 21 | }; 22 | 23 | struct fat_list 24 | { 25 | struct fat_node *head; 26 | struct fat_node *tail; 27 | }; 28 | 29 | //----------------------------------------------------------------- 30 | // Macros 31 | //----------------------------------------------------------------- 32 | #define fat_list_entry(p, t, m) p ? ((t *)((char *)(p)-(char*)(&((t *)0)->m))) : 0 33 | #define fat_list_next(l, p) (p)->next 34 | #define fat_list_prev(l, p) (p)->previous 35 | #define fat_list_first(l) (l)->head 36 | #define fat_list_last(l) (l)->tail 37 | #define fat_list_for_each(l, p) for ((p) = (l)->head; (p); (p) = (p)->next) 38 | 39 | //----------------------------------------------------------------- 40 | // Inline Functions 41 | //----------------------------------------------------------------- 42 | 43 | //----------------------------------------------------------------- 44 | // fat_list_init: 45 | //----------------------------------------------------------------- 46 | static FAT_INLINE void fat_list_init(struct fat_list *list) 47 | { 48 | FAT_ASSERT(list); 49 | 50 | list->head = list->tail = 0; 51 | } 52 | //----------------------------------------------------------------- 53 | // fat_list_remove: 54 | //----------------------------------------------------------------- 55 | static FAT_INLINE void fat_list_remove(struct fat_list *list, struct fat_node *node) 56 | { 57 | FAT_ASSERT(list); 58 | FAT_ASSERT(node); 59 | 60 | if(!node->previous) 61 | list->head = node->next; 62 | else 63 | node->previous->next = node->next; 64 | 65 | if(!node->next) 66 | list->tail = node->previous; 67 | else 68 | node->next->previous = node->previous; 69 | } 70 | //----------------------------------------------------------------- 71 | // fat_list_insert_after: 72 | //----------------------------------------------------------------- 73 | static FAT_INLINE void fat_list_insert_after(struct fat_list *list, struct fat_node *node, struct fat_node *new_node) 74 | { 75 | FAT_ASSERT(list); 76 | FAT_ASSERT(node); 77 | FAT_ASSERT(new_node); 78 | 79 | new_node->previous = node; 80 | new_node->next = node->next; 81 | if (!node->next) 82 | list->tail = new_node; 83 | else 84 | node->next->previous = new_node; 85 | node->next = new_node; 86 | } 87 | //----------------------------------------------------------------- 88 | // fat_list_insert_before: 89 | //----------------------------------------------------------------- 90 | static FAT_INLINE void fat_list_insert_before(struct fat_list *list, struct fat_node *node, struct fat_node *new_node) 91 | { 92 | FAT_ASSERT(list); 93 | FAT_ASSERT(node); 94 | FAT_ASSERT(new_node); 95 | 96 | new_node->previous = node->previous; 97 | new_node->next = node; 98 | if (!node->previous) 99 | list->head = new_node; 100 | else 101 | node->previous->next = new_node; 102 | node->previous = new_node; 103 | } 104 | //----------------------------------------------------------------- 105 | // fat_list_insert_first: 106 | //----------------------------------------------------------------- 107 | static FAT_INLINE void fat_list_insert_first(struct fat_list *list, struct fat_node *node) 108 | { 109 | FAT_ASSERT(list); 110 | FAT_ASSERT(node); 111 | 112 | if (!list->head) 113 | { 114 | list->head = node; 115 | list->tail = node; 116 | node->previous = 0; 117 | node->next = 0; 118 | } 119 | else 120 | fat_list_insert_before(list, list->head, node); 121 | } 122 | //----------------------------------------------------------------- 123 | // fat_list_insert_last: 124 | //----------------------------------------------------------------- 125 | static FAT_INLINE void fat_list_insert_last(struct fat_list *list, struct fat_node *node) 126 | { 127 | FAT_ASSERT(list); 128 | FAT_ASSERT(node); 129 | 130 | if (!list->tail) 131 | fat_list_insert_first(list, node); 132 | else 133 | fat_list_insert_after(list, list->tail, node); 134 | } 135 | //----------------------------------------------------------------- 136 | // fat_list_is_empty: 137 | //----------------------------------------------------------------- 138 | static FAT_INLINE int fat_list_is_empty(struct fat_list *list) 139 | { 140 | FAT_ASSERT(list); 141 | 142 | return !list->head; 143 | } 144 | //----------------------------------------------------------------- 145 | // fat_list_pop_head: 146 | //----------------------------------------------------------------- 147 | static FAT_INLINE struct fat_node * fat_list_pop_head(struct fat_list *list) 148 | { 149 | struct fat_node * node; 150 | 151 | FAT_ASSERT(list); 152 | 153 | node = fat_list_first(list); 154 | if (node) 155 | fat_list_remove(list, node); 156 | 157 | return node; 158 | } 159 | 160 | #endif 161 | 162 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_misc.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_MISC_H__ 2 | #define __FAT_MISC_H__ 3 | 4 | #include "fat_defs.h" 5 | #include "fat_opts.h" 6 | 7 | //----------------------------------------------------------------------------- 8 | // Defines 9 | //----------------------------------------------------------------------------- 10 | #define MAX_LONGFILENAME_ENTRIES 20 11 | #define MAX_LFN_ENTRY_LENGTH 13 12 | 13 | //----------------------------------------------------------------------------- 14 | // Macros 15 | //----------------------------------------------------------------------------- 16 | #define GET_32BIT_WORD(buffer, location) ( ((uint32)buffer[location+3]<<24) + ((uint32)buffer[location+2]<<16) + ((uint32)buffer[location+1]<<8) + (uint32)buffer[location+0] ) 17 | #define GET_16BIT_WORD(buffer, location) ( ((uint16)buffer[location+1]<<8) + (uint16)buffer[location+0] ) 18 | 19 | #define SET_32BIT_WORD(buffer, location, value) { buffer[location+0] = (uint8)((value)&0xFF); \ 20 | buffer[location+1] = (uint8)((value>>8)&0xFF); \ 21 | buffer[location+2] = (uint8)((value>>16)&0xFF); \ 22 | buffer[location+3] = (uint8)((value>>24)&0xFF); } 23 | 24 | #define SET_16BIT_WORD(buffer, location, value) { buffer[location+0] = (uint8)((value)&0xFF); \ 25 | buffer[location+1] = (uint8)((value>>8)&0xFF); } 26 | 27 | //----------------------------------------------------------------------------- 28 | // Structures 29 | //----------------------------------------------------------------------------- 30 | struct lfn_cache 31 | { 32 | #if FATFS_INC_LFN_SUPPORT 33 | // Long File Name Structure (max 260 LFN length) 34 | uint8 String[MAX_LONGFILENAME_ENTRIES][MAX_LFN_ENTRY_LENGTH]; 35 | uint8 Null; 36 | #endif 37 | uint8 no_of_strings; 38 | }; 39 | 40 | //----------------------------------------------------------------------------- 41 | // Prototypes 42 | //----------------------------------------------------------------------------- 43 | void fatfs_lfn_cache_init(struct lfn_cache *lfn, int wipeTable); 44 | void fatfs_lfn_cache_entry(struct lfn_cache *lfn, uint8 *entryBuffer); 45 | char* fatfs_lfn_cache_get(struct lfn_cache *lfn); 46 | int fatfs_entry_lfn_text(struct fat_dir_entry *entry); 47 | int fatfs_entry_lfn_invalid(struct fat_dir_entry *entry); 48 | int fatfs_entry_lfn_exists(struct lfn_cache *lfn, struct fat_dir_entry *entry); 49 | int fatfs_entry_sfn_only(struct fat_dir_entry *entry); 50 | int fatfs_entry_is_dir(struct fat_dir_entry *entry); 51 | int fatfs_entry_is_file(struct fat_dir_entry *entry); 52 | int fatfs_lfn_entries_required(char *filename); 53 | void fatfs_filename_to_lfn(char *filename, uint8 *buffer, int entry, uint8 sfnChk); 54 | void fatfs_sfn_create_entry(char *shortfilename, uint32 size, uint32 startCluster, struct fat_dir_entry *entry, int dir); 55 | int fatfs_lfn_create_sfn(char *sfn_output, char *filename); 56 | int fatfs_lfn_generate_tail(char *sfn_output, char *sfn_input, uint32 tailNum); 57 | void fatfs_convert_from_fat_time(uint16 fat_time, int *hours, int *minutes, int *seconds); 58 | void fatfs_convert_from_fat_date(uint16 fat_date, int *day, int *month, int *year); 59 | uint16 fatfs_convert_to_fat_time(int hours, int minutes, int seconds); 60 | uint16 fatfs_convert_to_fat_date(int day, int month, int year); 61 | void fatfs_print_sector(uint32 sector, uint8 *data); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_opts.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_OPTS_H__ 2 | #define __FAT_OPTS_H__ 3 | 4 | #ifdef FATFS_USE_CUSTOM_OPTS_FILE 5 | #include "fat_custom.h" 6 | #endif 7 | 8 | //------------------------------------------------------------- 9 | // Configuration 10 | //------------------------------------------------------------- 11 | 12 | // Is the processor little endian (1) or big endian (0) 13 | #ifndef FATFS_IS_LITTLE_ENDIAN 14 | #define FATFS_IS_LITTLE_ENDIAN 0 15 | #endif 16 | 17 | // Max filename Length 18 | #ifndef FATFS_MAX_LONG_FILENAME 19 | #define FATFS_MAX_LONG_FILENAME 260 20 | #endif 21 | 22 | // Max open files (reduce to lower memory requirements) 23 | #ifndef FATFS_MAX_OPEN_FILES 24 | #define FATFS_MAX_OPEN_FILES 2 25 | #endif 26 | 27 | // Number of sectors per FAT_BUFFER (min 1) 28 | #ifndef FAT_BUFFER_SECTORS 29 | #define FAT_BUFFER_SECTORS 1 30 | #endif 31 | 32 | // Max FAT sectors to buffer (min 1) 33 | // (mem used is FAT_BUFFERS * FAT_BUFFER_SECTORS * FAT_SECTOR_SIZE) 34 | #ifndef FAT_BUFFERS 35 | #define FAT_BUFFERS 64 36 | #endif 37 | 38 | // Size of cluster chain cache (can be undefined) 39 | // Mem used = FAT_CLUSTER_CACHE_ENTRIES * 4 * 2 40 | // Improves access speed considerably 41 | #define FAT_CLUSTER_CACHE_ENTRIES 128 42 | 43 | // Include support for writing files (1 / 0)? 44 | #ifndef FATFS_INC_WRITE_SUPPORT 45 | #define FATFS_INC_WRITE_SUPPORT 1 46 | #endif 47 | 48 | // Support long filenames (1 / 0)? 49 | // (if not (0) only 8.3 format is supported) 50 | #ifndef FATFS_INC_LFN_SUPPORT 51 | #define FATFS_INC_LFN_SUPPORT 1 52 | #endif 53 | 54 | // Support directory listing (1 / 0)? 55 | #ifndef FATFS_DIR_LIST_SUPPORT 56 | #define FATFS_DIR_LIST_SUPPORT 0 57 | #endif 58 | 59 | // Support time/date (1 / 0)? 60 | #ifndef FATFS_INC_TIME_DATE_SUPPORT 61 | #define FATFS_INC_TIME_DATE_SUPPORT 0 62 | #endif 63 | 64 | // Include support for formatting disks (1 / 0)? 65 | #ifndef FATFS_INC_FORMAT_SUPPORT 66 | #define FATFS_INC_FORMAT_SUPPORT 0 67 | #endif 68 | 69 | // Sector size used 70 | #define FAT_SECTOR_SIZE 512 71 | 72 | // Printf output (directory listing / debug) 73 | #define FAT_PRINTF(a) 74 | #ifndef FAT_PRINTF 75 | // Don't include stdio, but there is a printf function available 76 | #ifdef FAT_PRINTF_NOINC_STDIO 77 | extern int printf(const char* ctrl1, ... ); 78 | #define FAT_PRINTF(a) printf a 79 | // Include stdio to use printf 80 | #else 81 | #include 82 | #define FAT_PRINTF(a) printf a 83 | #endif 84 | #endif 85 | 86 | // Time/Date support requires time.h 87 | #if FATFS_INC_TIME_DATE_SUPPORT 88 | #include 89 | #endif 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_string.h: -------------------------------------------------------------------------------- 1 | #ifndef __FILESTRING_H__ 2 | #define __FILESTRING_H__ 3 | 4 | //----------------------------------------------------------------------------- 5 | // Prototypes 6 | //----------------------------------------------------------------------------- 7 | int fatfs_total_path_levels(char *path); 8 | int fatfs_get_substring(char *Path, int levelreq, char *output, int max_len); 9 | int fatfs_split_path(char *FullPath, char *Path, int max_path, char *FileName, int max_filename); 10 | int fatfs_compare_names(char* strA, char* strB); 11 | int fatfs_string_ends_with_slash(char *path); 12 | int fatfs_get_sfn_display_name(char* out, char* in); 13 | int fatfs_get_extension(char* filename, char* out, int maxlen); 14 | int fatfs_create_path_string(char* path, char *filename, char* out, int maxlen); 15 | 16 | #ifndef NULL 17 | #define NULL 0 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_table.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_TABLE_H__ 2 | #define __FAT_TABLE_H__ 3 | 4 | #include "fat_opts.h" 5 | #include "fat_misc.h" 6 | 7 | //----------------------------------------------------------------------------- 8 | // Prototypes 9 | //----------------------------------------------------------------------------- 10 | void fatfs_fat_init(struct fatfs *fs); 11 | int fatfs_fat_purge(struct fatfs *fs); 12 | uint32 fatfs_find_next_cluster(struct fatfs *fs, uint32 current_cluster); 13 | void fatfs_set_fs_info_next_free_cluster(struct fatfs *fs, uint32 newValue); 14 | int fatfs_find_blank_cluster(struct fatfs *fs, uint32 start_cluster, uint32 *free_cluster); 15 | int fatfs_fat_set_cluster(struct fatfs *fs, uint32 cluster, uint32 next_cluster); 16 | int fatfs_fat_add_cluster_to_chain(struct fatfs *fs, uint32 start_cluster, uint32 newEntry); 17 | int fatfs_free_cluster_chain(struct fatfs *fs, uint32 start_cluster); 18 | uint32 fatfs_count_free_clusters(struct fatfs *fs); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_types.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_TYPES_H__ 2 | #define __FAT_TYPES_H__ 3 | 4 | // Detect 64-bit compilation on GCC 5 | #if defined(__GNUC__) && defined(__SIZEOF_LONG__) 6 | #if __SIZEOF_LONG__ == 8 7 | #define FATFS_DEF_UINT32_AS_INT 8 | #endif 9 | #endif 10 | 11 | //------------------------------------------------------------- 12 | // System specific types 13 | //------------------------------------------------------------- 14 | #ifndef FATFS_NO_DEF_TYPES 15 | typedef unsigned char uint8; 16 | typedef unsigned short uint16; 17 | 18 | // If compiling on a 64-bit machine, use int as 32-bits 19 | #ifdef FATFS_DEF_UINT32_AS_INT 20 | typedef unsigned int uint32; 21 | // Else for 32-bit machines & embedded systems, use long... 22 | #else 23 | typedef unsigned long uint32; 24 | #endif 25 | #endif 26 | 27 | #ifndef NULL 28 | #define NULL 0 29 | #endif 30 | 31 | //------------------------------------------------------------- 32 | // Endian Macros 33 | //------------------------------------------------------------- 34 | // FAT is little endian so big endian systems need to swap words 35 | 36 | // Little Endian - No swap required 37 | #if FATFS_IS_LITTLE_ENDIAN == 1 38 | 39 | #define FAT_HTONS(n) (n) 40 | #define FAT_HTONL(n) (n) 41 | 42 | // Big Endian - Swap required 43 | #else 44 | 45 | #define FAT_HTONS(n) ((((uint16)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8)) 46 | #define FAT_HTONL(n) (((((uint32)(n) & 0xFF)) << 24) | \ 47 | ((((uint32)(n) & 0xFF00)) << 8) | \ 48 | ((((uint32)(n) & 0xFF0000)) >> 8) | \ 49 | ((((uint32)(n) & 0xFF000000)) >> 24)) 50 | 51 | #endif 52 | 53 | //------------------------------------------------------------- 54 | // Structure Packing Compile Options 55 | //------------------------------------------------------------- 56 | #ifdef __GNUC__ 57 | #define STRUCT_PACK 58 | #define STRUCT_PACK_BEGIN 59 | #define STRUCT_PACK_END 60 | #define STRUCT_PACKED __attribute__ ((packed)) 61 | #else 62 | // Other compilers may require other methods of packing structures 63 | #define STRUCT_PACK 64 | #define STRUCT_PACK_BEGIN 65 | #define STRUCT_PACK_END 66 | #define STRUCT_PACKED 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /ios_fs/source/fat/fat_write.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_WRITE_H__ 2 | #define __FAT_WRITE_H__ 3 | 4 | #include "fat_defs.h" 5 | #include "fat_opts.h" 6 | 7 | //----------------------------------------------------------------------------- 8 | // Prototypes 9 | //----------------------------------------------------------------------------- 10 | int fatfs_add_file_entry(struct fatfs *fs, uint32 dirCluster, char *filename, char *shortfilename, uint32 startCluster, uint32 size, int dir); 11 | int fatfs_add_free_space(struct fatfs *fs, uint32 *startCluster, uint32 clusters); 12 | int fatfs_allocate_free_space(struct fatfs *fs, int newFile, uint32 *startCluster, uint32 size); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /ios_fs/source/font.c: -------------------------------------------------------------------------------- 1 | const unsigned char font_bin[] = { 2 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x18, 0x18, 0x00, 0x0C, 0x00, 3 | 0x00, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0xFF, 0x66, 0xFF, 0x66, 0x66, 4 | 0x00, 0x18, 0x7C, 0x06, 0x3C, 0x60, 0x3E, 0x18, 0x10, 0x46, 0x66, 0x30, 0x18, 0x0C, 0x66, 0x62, 5 | 0x00, 0x3C, 0x66, 0x3C, 0x1C, 0xE6, 0x66, 0xFC, 0x00, 0x18, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 6 | 0x00, 0x30, 0x18, 0x0C, 0x0C, 0x18, 0x30, 0x00, 0x00, 0x0C, 0x18, 0x30, 0x30, 0x18, 0x0C, 0x00, 7 | 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 8 | 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 9 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x40, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00, 10 | 0x00, 0x3C, 0x66, 0x76, 0x6E, 0x66, 0x3C, 0x00, 0x00, 0x18, 0x1C, 0x18, 0x18, 0x18, 0x7E, 0x00, 11 | 0x00, 0x3C, 0x62, 0x30, 0x0C, 0x06, 0x7E, 0x00, 0x00, 0x3C, 0x62, 0x38, 0x60, 0x66, 0x3C, 0x00, 12 | 0x00, 0x6C, 0x6C, 0x66, 0xFE, 0x60, 0x60, 0x00, 0x00, 0x7E, 0x06, 0x7E, 0x60, 0x66, 0x3C, 0x00, 13 | 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x7E, 0x30, 0x30, 0x18, 0x18, 0x18, 0x00, 14 | 0x00, 0x3C, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x3C, 0x66, 0x7C, 0x60, 0x66, 0x3C, 0x00, 15 | 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x0C, 0x00, 16 | 0x00, 0x70, 0x1C, 0x06, 0x06, 0x1C, 0x70, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 17 | 0x00, 0x0E, 0x38, 0x60, 0x60, 0x38, 0x0E, 0x00, 0x00, 0x3C, 0x66, 0x30, 0x18, 0x00, 0x18, 0x00, 18 | 0x00, 0x3C, 0x66, 0x76, 0x76, 0x06, 0x46, 0x3C, 0x00, 0x3C, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, 19 | 0x00, 0x3E, 0x66, 0x3E, 0x66, 0x66, 0x3E, 0x00, 0x00, 0x3C, 0x66, 0x06, 0x06, 0x66, 0x3C, 0x00, 20 | 0x00, 0x1E, 0x36, 0x66, 0x66, 0x36, 0x1E, 0x00, 0x00, 0x7E, 0x06, 0x1E, 0x06, 0x06, 0x7E, 0x00, 21 | 0x00, 0x3E, 0x06, 0x1E, 0x06, 0x06, 0x06, 0x00, 0x00, 0x3C, 0x66, 0x06, 0x76, 0x66, 0x3C, 0x00, 22 | 0x00, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 23 | 0x00, 0x78, 0x30, 0x30, 0x30, 0x36, 0x1C, 0x00, 0x00, 0x66, 0x36, 0x1E, 0x1E, 0x36, 0x66, 0x00, 24 | 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7E, 0x00, 0x00, 0x46, 0x6E, 0x7E, 0x56, 0x46, 0x46, 0x00, 25 | 0x00, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x66, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 26 | 0x00, 0x3E, 0x66, 0x3E, 0x06, 0x06, 0x06, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x70, 0x00, 27 | 0x00, 0x3E, 0x66, 0x3E, 0x1E, 0x36, 0x66, 0x00, 0x00, 0x3C, 0x66, 0x0C, 0x30, 0x66, 0x3C, 0x00, 28 | 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 29 | 0x00, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x46, 0x46, 0x56, 0x7E, 0x6E, 0x46, 0x00, 30 | 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00, 0x00, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x00, 31 | 0x00, 0x7E, 0x30, 0x18, 0x0C, 0x06, 0x7E, 0x00, 0x00, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 32 | 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00, 0x00, 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 33 | 0x00, 0x18, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 34 | 0x00, 0x0C, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x60, 0x7C, 0x66, 0x7C, 0x00, 35 | 0x00, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E, 0x00, 0x00, 0x00, 0x3C, 0x06, 0x06, 0x06, 0x3C, 0x00, 36 | 0x00, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x06, 0x3C, 0x00, 37 | 0x00, 0x38, 0x0C, 0x3E, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x7C, 0x66, 0x7C, 0x40, 0x3C, 0x00, 38 | 0x00, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x18, 0x00, 0x1C, 0x18, 0x18, 0x3C, 0x00, 39 | 0x00, 0x30, 0x00, 0x30, 0x30, 0x30, 0x1E, 0x00, 0x00, 0x06, 0x06, 0x36, 0x1E, 0x36, 0x66, 0x00, 40 | 0x00, 0x1C, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x66, 0xFE, 0xFE, 0xD6, 0xC6, 0x00, 41 | 0x00, 0x00, 0x3E, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00, 42 | 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x00, 43 | 0x00, 0x00, 0x3E, 0x66, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x7C, 0x06, 0x3C, 0x60, 0x3E, 0x00, 44 | 0x00, 0x18, 0x7E, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x00, 45 | 0x00, 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00, 0xC6, 0xD6, 0xFE, 0x7C, 0x6C, 0x00, 46 | 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x66, 0x66, 0x7C, 0x60, 0x3C, 0x00, 47 | 0x00, 0x00, 0x7E, 0x30, 0x18, 0x0C, 0x7E, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x04, 0x08, 0x08, 48 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x0C, 0x08, 0x08, 0x10, 0x08, 0x08, 49 | }; 50 | -------------------------------------------------------------------------------- /ios_fs/source/font_bin.h: -------------------------------------------------------------------------------- 1 | extern const u8 font_bin[]; -------------------------------------------------------------------------------- /ios_fs/source/fs_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _FS_CONFIG_H 2 | #define _FS_CONFIG_H 3 | 4 | typedef struct { 5 | int dump_slc; 6 | int dump_slccmpt; 7 | int dump_mlc; 8 | int dump_otp; 9 | int dump_seeprom; 10 | char otp_buffer[0x400]; 11 | char seeprom_buffer[0x200]; 12 | } fs_config; 13 | 14 | #endif -------------------------------------------------------------------------------- /ios_fs/source/function_hooks.s: -------------------------------------------------------------------------------- 1 | 2 | ############################################################################################# 3 | # FS main thread hook 4 | ############################################################################################# 5 | .extern createDevThread_entry 6 | .globl createDevThread_hook 7 | createDevThread_hook: 8 | push {r0,lr} 9 | ldr r0, [r4, #0x8] 10 | bl createDevThread_entry 11 | pop {r0,lr} 12 | # restore original instruction 13 | pop {r4-r8,pc} 14 | 15 | ############################################################################################# 16 | # devices handle hooks 17 | ############################################################################################# 18 | .extern getMdDeviceById 19 | .globl getMdDeviceById_hook 20 | getMdDeviceById_hook: 21 | mov r4, r0 22 | push {lr} 23 | bl getMdDeviceById 24 | pop {lr} 25 | cmp r0, #0 26 | moveq r0, r4 27 | bxeq lr 28 | pop {r4,r5,pc} 29 | 30 | 31 | ############################################################################################# 32 | # syslog hook 33 | ############################################################################################# 34 | .globl syslogOutput_hook 35 | syslogOutput_hook: 36 | # push {r0,lr} 37 | # bl dump_syslog 38 | # pop {r0,lr} 39 | # restore original instruction 40 | pop {r4-r8,r10,pc} 41 | 42 | ############################################################################################# 43 | # Original NAND read functions 44 | ############################################################################################# 45 | .globl slcRead1_original 46 | slcRead1_original: 47 | push {r4-r8,lr} 48 | ldr r4, [pc] 49 | bx r4 50 | .word 0x107B9990 51 | 52 | .globl sdcardRead_original 53 | sdcardRead_original: 54 | push {r4,lr} 55 | ldr r4, [pc] 56 | bx r4 57 | .word 0x107BDDD4 58 | 59 | ############################################################################################# 60 | # DEBUG STUFF 61 | ############################################################################################# 62 | # # # # # # # # # # 63 | # DEBUG STUFF # 64 | # # # # # # # # # # 65 | #mlcRead1_dbg: 66 | # mlcRead1_dbg_stackframe equ (4*6) 67 | # mov r12, r0 68 | # push {r0-r3,r12,lr} 69 | # adr r0, mlcRead1_dbg_format 70 | # ldr r1, [sp, #mlcRead1_dbg_stackframe+9*4] 71 | # bl FS_SYSLOG_OUTPUT 72 | # pop {r0-r3,lr,pc} # replaces mov lr, r0 73 | # mlcRead1_dbg_format: 74 | # .ascii "mlcRead1 : %08X %08X %08X" 75 | # .byte 0x0a 76 | # .byte 0x00 77 | # .align 0x4 78 | # 79 | #mlcRead1_end_hook: 80 | # mlcRead1_end_hook_stackframe equ (4*10) 81 | # push {r0} 82 | # mov r0, #50 83 | # bl FS_SLEEP 84 | # ldr r0, =sdcard_read_buffer 85 | # ldr r1, [sp, #mlcRead1_end_hook_stackframe+4*1] 86 | # mov r2, #0x200 87 | # bl FS_MEMCPY 88 | # ldr r0, =sdcard_read_buffer 89 | # str r6, [r0] 90 | # mov r1, #0x200 91 | # bl dump_data 92 | # pop {r0,r4-r11,pc} 93 | -------------------------------------------------------------------------------- /ios_fs/source/hardware_registers.h: -------------------------------------------------------------------------------- 1 | #ifndef HARDWARE_REGISTERS_H_ 2 | #define HARDWARE_REGISTERS_H_ 3 | 4 | #define LT_GPIO_IN 0x0d8000e8 5 | 6 | 7 | #define GPIO_IN_POWER_BUTTON 0x01 8 | 9 | #endif // HARDWARE_REGISTERS_H_ 10 | -------------------------------------------------------------------------------- /ios_fs/source/imports.h: -------------------------------------------------------------------------------- 1 | #ifndef IMPORTS_H_ 2 | #define IMPORTS_H_ 3 | 4 | #include "types.h" 5 | 6 | #define FS_IOS_SHUTDOWN ((void (*)(int))0x107F6C94) 7 | 8 | #define FS_SVC_CREATEMUTEX ((int (*)(int, int))0x107F6BBC) 9 | #define FS_SVC_ACQUIREMUTEX ((int (*)(int, int))0x107F6BC4) 10 | #define FS_SVC_RELEASEMUTEX ((int (*)(int))0x107F6BCC) 11 | #define FS_SVC_DESTROYMUTEX ((int (*)(int))0x107F6BD4) 12 | 13 | #define FS_SLEEP ((void (*)(int))0x1071D668) 14 | #define FS_MEMCMP ((int (*)(const void*, const void*, u32))0x107F4E94) 15 | #define FS_MEMCPY ((void* (*)(void*, const void*, u32))0x107F4F7C) 16 | #define FS_MEMSET ((void* (*)(void*, int, u32))0x107F5018) 17 | #define FS_VSNPRINTF ((int (*)(char * s, size_t n, const char * format, va_list arg))0x107F5F68) 18 | #define FS_SNPRINTF ((int (*)(char * s, size_t n, const char * format, ...))0x107F5FB4) 19 | #define FS_STRNCPY ((void* (*)(char*, const char*, u32))0x107F60DC) 20 | #define FS_STRNCMP ((int (*)(const char*, const char*, u32))0x107F6138) 21 | #define FS_SAFE_STRLEN ((int (*)(const char*, u32))0x107F61BC) 22 | 23 | #define FS_RAW_READ1 ((int (*)(int handle, u32 offset_high, u32 offset_low, u32 size, void* buf, void *callback, int callback_arg))0x10732BC0) 24 | #define FS_SDIO_DOREADWRITECOMMAND ((int (*)(int, void*, u32, void*, void*))0x10718A8C) 25 | 26 | #define FS_REGISTERMDPHYSICALDEVICE ((int (*)(void*, int, int))0x10718860) 27 | 28 | #define memcmp FS_MEMCMP 29 | #define memcpy FS_MEMCPY 30 | #define memset FS_MEMSET 31 | #define strncpy FS_STRNCPY 32 | #define strncmp FS_STRNCMP 33 | #define strlen(x) FS_SAFE_STRLEN(x, 0x1000) 34 | 35 | #define FS_MMC_SDCARD_STRUCT ((vu32*)0x1089B9F8) 36 | #define FS_MMC_MLC_STRUCT ((vu32*)0x1089B948) 37 | 38 | #define FS_MLC_PHYS_DEV_STRUCT ((void*)0x11C3A14C) 39 | #define FS_SLC_PHYS_DEV_STRUCT ((void*)0x11C381CC) 40 | #define FS_SLCCMPT_PHYS_DEV_STRUCT ((void*)0x11C37668) 41 | 42 | #define le16(i) ((((u16) ((i) & 0xFF)) << 8) | ((u16) (((i) & 0xFF00) >> 8))) 43 | #define le32(i) ((((u32)le16((i) & 0xFFFF)) << 16) | ((u32)le16(((i) & 0xFFFF0000) >> 16))) 44 | #define le64(i) ((((u64)le32((i) & 0xFFFFFFFFLL)) << 32) | ((u64)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) 45 | 46 | #endif // IMPORTS_H_ 47 | -------------------------------------------------------------------------------- /ios_fs/source/main.c: -------------------------------------------------------------------------------- 1 | #include "text.h" 2 | #include "sdio.h" 3 | #include "dumper.h" 4 | #include "imports.h" 5 | 6 | #define INITIALIZING_FLA 0x07 7 | #define INITIALIZING_MMC 0x0D 8 | 9 | 10 | int getPhysicalDeviceHandle(u32 device); 11 | 12 | void createDevThread_entry(int initialization_type) 13 | { 14 | if(initialization_type == INITIALIZING_MMC) 15 | { 16 | sdcard_init(); 17 | } 18 | 19 | //if(initialization_type == INITIALIZING_FLA) 20 | //{ 21 | //dump_nand_complete(); 22 | //} 23 | 24 | if(initialization_type == 0x01) // unknown but after SLC init no read/write done at this point yet 25 | { 26 | //if(check_nand_dump() == 0) 27 | //{ 28 | clearScreen(0x000000FF); 29 | _printf(20, 20, "welcome to NAND dumper!"); 30 | 31 | dump_nand_complete(); 32 | //} 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ios_fs/source/mlcio.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "imports.h" 3 | 4 | void mlc_init(void) 5 | { 6 | FS_MMC_MLC_STRUCT[0x24/4] = FS_MMC_MLC_STRUCT[0x24/4] | 0x20; 7 | FS_MMC_MLC_STRUCT[0x28/4] = FS_MMC_MLC_STRUCT[0x28/4] & (~0x04); 8 | } 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ios_fs/source/mlcio.h: -------------------------------------------------------------------------------- 1 | #ifndef _MLCIO_H_ 2 | #define _MLCIO_H_ 3 | 4 | void mlc_init(void); 5 | 6 | #endif // _MLCIO_H_ 7 | -------------------------------------------------------------------------------- /ios_fs/source/sd_fat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "types.h" 3 | #include "imports.h" 4 | #include "devices.h" 5 | #include "sdio.h" 6 | #include "text.h" 7 | #include "sd_fat.h" 8 | 9 | unsigned char sd_io_buffer[0x40000] __attribute__((aligned(0x40))) __attribute__((section(".io_buffer"))); 10 | 11 | int sd_fat_read(unsigned long sector, unsigned char *buffer, unsigned long sector_count) 12 | { 13 | // It seems that sdcard_readwrite overwrite more bytes than requested with 0xff.... So I use io_buffer to read it. 14 | if (sector_count * SDIO_BYTES_PER_SECTOR > sizeof(sd_io_buffer)) return 0; 15 | int result = sdcard_readwrite(SDIO_READ, sd_io_buffer, sector_count, SDIO_BYTES_PER_SECTOR, sector, NULL, DEVICE_ID_SDCARD_PATCHED); 16 | if (result) return 0; 17 | memcpy(buffer, sd_io_buffer, sector_count * SDIO_BYTES_PER_SECTOR); 18 | return 1; 19 | } 20 | 21 | int sd_fat_write(unsigned long sector, unsigned char *buffer, unsigned long sector_count) 22 | { 23 | if (sector_count * SDIO_BYTES_PER_SECTOR > sizeof(sd_io_buffer)) return 0; 24 | int result = sdcard_readwrite(SDIO_WRITE, buffer, sector_count, SDIO_BYTES_PER_SECTOR, sector, NULL, DEVICE_ID_SDCARD_PATCHED); 25 | return result ? 0 : 1; 26 | } 27 | 28 | int InitSDCardFAT32() 29 | { 30 | fl_init(); 31 | 32 | int result = fl_attach_media(sd_fat_read, sd_fat_write); 33 | if (result != FAT_INIT_OK) 34 | { 35 | _printf(20, 40, "FAT32 attach failed %d", result); 36 | return result; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /ios_fs/source/sd_fat.h: -------------------------------------------------------------------------------- 1 | #ifndef _DS_FAT_H_ 2 | #define _DS_FAT_H_ 3 | 4 | #include "fat/fat_filelib.h" 5 | 6 | int InitSDCardFAT32(); 7 | 8 | #endif // _FAT32_FORMAT_H_ 9 | -------------------------------------------------------------------------------- /ios_fs/source/sdio.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "imports.h" 3 | 4 | static int sdcard_access_mutex = 0; 5 | static u32 dumpdata_offset = 0; 6 | 7 | typedef struct _sd_command_block_t 8 | { 9 | u32 cnt; 10 | u32 block_size; 11 | u32 command_type; 12 | void * data_ptr; 13 | u64 offset; 14 | void *callback; 15 | void *callback_arg; 16 | int minus_one; 17 | } __attribute__((packed)) sd_command_block_t; 18 | 19 | void sdcard_init(void) 20 | { 21 | // this should run *after* /dev/mmc thread is created 22 | // first we create our synchronization stuff 23 | sdcard_access_mutex = FS_SVC_CREATEMUTEX(1, 1); 24 | 25 | dumpdata_offset = 0; 26 | 27 | // then we sleep until /dev/mmc is done initializing sdcard (TODO : better synchronization here) 28 | FS_SLEEP(1000); 29 | 30 | // finally we set some flags to indicate sdcard is ready for use 31 | FS_MMC_SDCARD_STRUCT[0x24/4] = FS_MMC_SDCARD_STRUCT[0x24/4] | 0x20; 32 | FS_MMC_SDCARD_STRUCT[0x28/4] = FS_MMC_SDCARD_STRUCT[0x28/4] & (~0x04); 33 | } 34 | 35 | static void sdcard_readwrite_callback(void *priv_data, int result) 36 | { 37 | int *private_data = (int*)priv_data; 38 | 39 | private_data[1] = result; 40 | 41 | FS_SVC_RELEASEMUTEX(private_data[0]); 42 | } 43 | 44 | void sdcard_lock_mutex(void) 45 | { 46 | FS_SVC_ACQUIREMUTEX(sdcard_access_mutex, 0); 47 | } 48 | 49 | void sdcard_unlock_mutex(void) 50 | { 51 | FS_SVC_RELEASEMUTEX(sdcard_access_mutex); 52 | } 53 | 54 | int sdcard_readwrite(int is_read, void *data, u32 cnt, u32 block_size, u32 offset_blocks, int * out_callback_arg, int device_id) 55 | { 56 | // first of all, grab sdcard mutex 57 | sdcard_lock_mutex(); 58 | 59 | //also create a mutex for synchronization with end of operation... 60 | int sync_mutex = FS_SVC_CREATEMUTEX(1, 1); 61 | 62 | // ...and acquire it 63 | FS_SVC_ACQUIREMUTEX(sync_mutex, 0); 64 | 65 | // block_size needs to be equal to sector_size (0x200) 66 | while(block_size > 0x200) 67 | { 68 | block_size >>= 1; 69 | cnt <<= 1; 70 | offset_blocks <<= 1; 71 | } 72 | 73 | // build rw command paramstruct 74 | sd_command_block_t command; 75 | command.cnt = cnt; 76 | command.block_size = block_size; 77 | command.command_type = (is_read ? 0x03 : 0x00); 78 | command.data_ptr = data; 79 | command.offset = offset_blocks; 80 | command.callback = 0x00; 81 | command.callback_arg = 0x00; 82 | command.minus_one = (u32)-1; 83 | 84 | // setup parameters 85 | int private_data[2]; 86 | private_data[0] = sync_mutex; 87 | private_data[1] = 0; 88 | 89 | // call readwrite function 90 | int result = FS_SDIO_DOREADWRITECOMMAND(device_id, &command, offset_blocks, sdcard_readwrite_callback, (void*)private_data); 91 | if(result == 0) 92 | { 93 | // wait for callback to give the go-ahead 94 | FS_SVC_ACQUIREMUTEX(sync_mutex, 0); 95 | 96 | if(out_callback_arg) 97 | { 98 | *out_callback_arg = private_data[1]; 99 | } 100 | } 101 | 102 | // finally, release sdcard mutexes 103 | FS_SVC_DESTROYMUTEX(sync_mutex); 104 | sdcard_unlock_mutex(); 105 | 106 | return result; 107 | } 108 | -------------------------------------------------------------------------------- /ios_fs/source/sdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _SDIO_H_ 2 | #define _SDIO_H_ 3 | 4 | #define SDIO_WRITE 0 5 | #define SDIO_READ 1 6 | 7 | void sdcard_init(void); 8 | void sdcard_lock_mutex(void); 9 | void sdcard_unlock_mutex(void); 10 | int sdcard_readwrite(int is_read, void *data, u32 cnt, u32 block_size, u32 offset_blocks, int * out_callback_arg, int device_id); 11 | 12 | #endif // _SDIO_H_ 13 | -------------------------------------------------------------------------------- /ios_fs/source/svc.h: -------------------------------------------------------------------------------- 1 | #ifndef SVC_H 2 | #define SVC_H 3 | 4 | #include "types.h" 5 | 6 | #define SHUTDOWN_TYPE_POWER_OFF 0 7 | #define SHUTDOWN_TYPE_REBOOT 1 8 | 9 | typedef struct 10 | { 11 | void* ptr; 12 | u32 len; 13 | u32 unk; 14 | }iovec_s; 15 | 16 | void* svcAlloc(u32 heapid, u32 size); 17 | void* svcAllocAlign(u32 heapid, u32 size, u32 align); 18 | void svcFree(u32 heapid, void* ptr); 19 | int svcOpen(char* name, int mode); 20 | int svcClose(int fd); 21 | int svcIoctl(int fd, u32 request, void* input_buffer, u32 input_buffer_len, void* output_buffer, u32 output_buffer_len); 22 | int svcIoctlv(int fd, u32 request, u32 vector_count_in, u32 vector_count_out, iovec_s* vector); 23 | int svcInvalidateDCache(void* address, u32 size); 24 | int svcFlushDCache(void* address, u32 size); 25 | 26 | void svcShutdown(int shutdown_type); 27 | u32 svcRead32(u32 addr); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ios_fs/source/svc.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .align 4 3 | 4 | .global svcAlloc 5 | .type svcAlloc, %function 6 | svcAlloc: 7 | .word 0xE7F027F0 8 | bx lr 9 | 10 | .global svcAllocAlign 11 | .type svcAllocAlign, %function 12 | svcAllocAlign: 13 | .word 0xE7F028F0 14 | bx lr 15 | 16 | .global svcFree 17 | .type svcFree, %function 18 | svcFree: 19 | .word 0xE7F029F0 20 | bx lr 21 | 22 | .global svcOpen 23 | .type svcOpen, %function 24 | svcOpen: 25 | .word 0xE7F033F0 26 | bx lr 27 | 28 | .global svcClose 29 | .type svcClose, %function 30 | svcClose: 31 | .word 0xE7F034F0 32 | bx lr 33 | 34 | .global svcIoctl 35 | .type svcIoctl, %function 36 | svcIoctl: 37 | .word 0xE7F038F0 38 | bx lr 39 | 40 | .global svcIoctlv 41 | .type svcIoctlv, %function 42 | svcIoctlv: 43 | .word 0xE7F039F0 44 | bx lr 45 | 46 | .global svcInvalidateDCache 47 | .type svcInvalidateDCache, %function 48 | svcInvalidateDCache: 49 | .word 0xE7F051F0 50 | bx lr 51 | 52 | .global svcFlushDCache 53 | .type svcFlushDCache, %function 54 | svcFlushDCache: 55 | .word 0xE7F052F0 56 | bx lr 57 | 58 | .global svcShutdown 59 | .type svcShutdown, %function 60 | svcShutdown: 61 | .word 0xE7F072F0 62 | bx lr 63 | 64 | .global svcRead32 65 | .type svcRead32, %function 66 | svcRead32: 67 | .word 0xE7F081F0 68 | bx lr 69 | -------------------------------------------------------------------------------- /ios_fs/source/text.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "imports.h" 6 | #include "types.h" 7 | #include "font_bin.h" 8 | 9 | #define FRAMEBUFFER_ADDRESS (0x14000000+0x38C0000) 10 | #define FRAMEBUFFER_STRIDE (0xE00) 11 | #define FRAMEBUFFER_STRIDE_WORDS (FRAMEBUFFER_STRIDE >> 2) 12 | 13 | #define CHAR_SIZE_X (8) 14 | #define CHAR_SIZE_Y (8) 15 | 16 | u32* const framebuffer = (u32*)FRAMEBUFFER_ADDRESS; 17 | 18 | void clearScreen(u32 color) 19 | { 20 | int i; 21 | for(i = 0; i < ((FRAMEBUFFER_STRIDE * 504)/4); i++) 22 | { 23 | framebuffer[i] = color; 24 | } 25 | } 26 | 27 | void clearLine(int y, u32 color) 28 | { 29 | u32* fb = &framebuffer[y * FRAMEBUFFER_STRIDE_WORDS]; 30 | u32* fb_end = &framebuffer[(y+CHAR_SIZE_Y) * FRAMEBUFFER_STRIDE_WORDS]; 31 | 32 | while(fb < fb_end) 33 | { 34 | *fb = color; 35 | fb++; 36 | } 37 | } 38 | 39 | void drawCharacter(char c, int x, int y) 40 | { 41 | if(c < 32)return; 42 | c -= 32; 43 | u8* charData = (u8*)&font_bin[(CHAR_SIZE_X * CHAR_SIZE_Y * c) / 8]; 44 | u32* fb = &framebuffer[x + y * FRAMEBUFFER_STRIDE_WORDS]; 45 | int i, j; 46 | for(i = 0; i < CHAR_SIZE_Y; i++) 47 | { 48 | u8 v= *(charData++); 49 | for(j = 0; j < CHAR_SIZE_X; j++) 50 | { 51 | if(v & 1) *fb = 0x00000000; 52 | else *fb = 0xFFFFFFFF; 53 | v >>= 1; 54 | fb++; 55 | } 56 | fb += FRAMEBUFFER_STRIDE_WORDS - CHAR_SIZE_X; 57 | } 58 | } 59 | 60 | void drawString(char* str, int x, int y) 61 | { 62 | if(!str) return; 63 | int k; 64 | int dx = 0, dy = 0; 65 | for(k = 0; str[k]; k++) 66 | { 67 | if(str[k] >= 32 && str[k] < 128) drawCharacter(str[k], x + dx, y + dy); 68 | 69 | dx += 8; 70 | 71 | if(str[k] == '\n') 72 | { 73 | dx = 0; 74 | dy -= 8; 75 | } 76 | } 77 | } 78 | 79 | void _printf(int x, int y, const char *format, ...) 80 | { 81 | va_list args; 82 | va_start(args, format); 83 | 84 | char buffer[0x100]; 85 | 86 | FS_VSNPRINTF(buffer, sizeof(buffer), format, args); 87 | drawString(buffer, x, y); 88 | 89 | va_end(args); 90 | } 91 | -------------------------------------------------------------------------------- /ios_fs/source/text.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXT_H 2 | #define TEXT_H 3 | 4 | #include "types.h" 5 | 6 | void clearScreen(u32 color); 7 | void clearLine(int y, u32 color); 8 | void drawString(char* str, int x, int y); 9 | void _printf(int x, int y, const char *format, ...); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /ios_fs/source/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPES_H 2 | #define TYPES_H 3 | 4 | #include 5 | #include 6 | 7 | #define U64_MAX UINT64_MAX 8 | 9 | typedef uint8_t u8; 10 | typedef uint16_t u16; 11 | typedef uint32_t u32; 12 | typedef uint64_t u64; 13 | 14 | typedef int8_t s8; 15 | typedef int16_t s16; 16 | typedef int32_t s32; 17 | typedef int64_t s64; 18 | 19 | typedef volatile u8 vu8; 20 | typedef volatile u16 vu16; 21 | typedef volatile u32 vu32; 22 | typedef volatile u64 vu64; 23 | 24 | typedef volatile s8 vs8; 25 | typedef volatile s16 vs16; 26 | typedef volatile s32 vs32; 27 | typedef volatile s64 vs64; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ios_kernel/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(strip $(DEVKITARM)),) 2 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 3 | endif 4 | 5 | ifeq ($(filter $(DEVKITARM)/bin,$(PATH)),) 6 | export PATH:=$(DEVKITARM)/bin:$(PATH) 7 | endif 8 | 9 | CC = arm-none-eabi-gcc 10 | LINK = arm-none-eabi-gcc 11 | AS = arm-none-eabi-as 12 | OBJCOPY = arm-none-eabi-objcopy 13 | OBJDUMP = arm-none-eabi-objdump 14 | CFLAGS += -Wall -mbig-endian -std=gnu11 -mcpu=arm926ej-s -msoft-float -mfloat-abi=soft -Os 15 | LDFLAGS += -nostartfiles -nodefaultlibs -mbig-endian -Wl,-T,link.ld 16 | LIBDIRS += -L$(CURDIR)/../libs 17 | LIBS += -lgcc 18 | 19 | CFILES = $(wildcard source/*.c) 20 | BINFILES = $(wildcard data/*.bin) 21 | OFILES = $(BINFILES:data/%.bin=build/%.bin.o) 22 | OFILES += $(CFILES:source/%.c=build/%.o) 23 | DFILES = $(CFILES:source/%.c=build/%.d) 24 | SFILES = $(wildcard source/*.s) 25 | OFILES += $(SFILES:source/%.s=build/%.o) 26 | PROJECTNAME = ${shell basename "$(CURDIR)"} 27 | CWD = "$(CURDIR)"" 28 | 29 | #--------------------------------------------------------------------------------- 30 | # canned command sequence for binary data, taken from devkitARM 31 | #--------------------------------------------------------------------------------- 32 | define bin2o 33 | bin2s $< | $(AS) -EB -o $(@) 34 | endef 35 | 36 | .PHONY:=all dirs 37 | 38 | all: dirs $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 39 | 40 | dirs: 41 | @mkdir -p build 42 | 43 | $(PROJECTNAME).elf: $(OFILES) 44 | @echo "LD $@" 45 | @$(LINK) $(LDFLAGS) -o $(PROJECTNAME).elf $(sort $(filter-out build/crt0.o, $(OFILES))) $(LIBDIRS) $(LIBS) 46 | 47 | $(PROJECTNAME).bin: $(PROJECTNAME).elf 48 | @echo "OBJCOPY $@\n" 49 | @$(OBJCOPY) -j .text -j .rodata -j .data -O binary $(PROJECTNAME).elf $@ 50 | 51 | $(PROJECTNAME).bin.h: $(PROJECTNAME).bin 52 | @xxd -i $< | sed "s/unsigned/static const unsigned/g;s/$(PROJECTNAME)$*/$(PROJECTNAME)/g" > $@ 53 | 54 | $(PROJECTNAME)_syms.h: 55 | @echo "#ifndef $(PROJECTNAME)_SYMS_H" > $@ 56 | @echo "#define $(PROJECTNAME)_SYMS_H" >> $@ 57 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep 'g F .text' | grep -v '.hidden' | awk '{print "#define " $$6 " 0x" $$1}' >> $@ 58 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep -e 'g .text' -e '_bss_' | awk '{print "#define " $$5 " 0x" $$1}' >> $@ 59 | @echo "#endif" >> $@ 60 | 61 | clean: 62 | @rm -f build/*.o build/*.d 63 | @rm -f $(PROJECTNAME).elf $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 64 | @echo "all cleaned up !" 65 | 66 | -include $(DFILES) 67 | 68 | build/%.o: source/%.c 69 | @echo "CC $(notdir $<)" 70 | @$(CC) $(CFLAGS) -c $< -o $@ 71 | @$(CC) -MM $< > build/$*.d 72 | 73 | build/%.o: source/%.s 74 | @echo "CC $(notdir $<)" 75 | @$(CC) $(CFLAGS) -xassembler-with-cpp -c $< -o $@ 76 | @$(CC) -MM $< > build/$*.d 77 | 78 | build/%.bin.o: data/%.bin 79 | @echo "BIN $(notdir $<)" 80 | @$(bin2o) 81 | -------------------------------------------------------------------------------- /ios_kernel/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(arm) 2 | 3 | SECTIONS 4 | { 5 | . = (0x08135000); 6 | 7 | __KERNEL_CODE_START = .; 8 | .text : { 9 | build/crt0.o(.init) 10 | *(.text*); 11 | } 12 | .rodata : { 13 | *(.rodata*) 14 | } 15 | .data : { 16 | *(.data*) 17 | } 18 | .bss : { 19 | *(.bss*) 20 | *(COMMON*) 21 | } 22 | __KERNEL_CODE_END = .; 23 | 24 | /DISCARD/ : { 25 | *(*); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /ios_kernel/source/config.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __CONFIG_H_ 25 | #define __CONFIG_H_ 26 | 27 | #include "../../src/cfw_config.h" 28 | 29 | extern cfw_config_t cfw_config; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ios_kernel/source/crt0.s: -------------------------------------------------------------------------------- 1 | .section ".init" 2 | .arm 3 | .align 4 4 | 5 | .extern _main 6 | .type _main, %function 7 | 8 | _start: 9 | b _main 10 | -------------------------------------------------------------------------------- /ios_kernel/source/elf_patcher.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "types.h" 25 | #include "elf_abi.h" 26 | #include "utils.h" 27 | 28 | static Elf32_Phdr * get_section(u32 data, u32 vaddr) 29 | { 30 | Elf32_Ehdr *ehdr = (Elf32_Ehdr *) data; 31 | 32 | if ( !IS_ELF (*ehdr) 33 | || (ehdr->e_type != ET_EXEC) 34 | || (ehdr->e_machine != EM_ARM)) 35 | { 36 | return 0; 37 | } 38 | 39 | Elf32_Phdr *phdr = 0; 40 | 41 | u32 i; 42 | for(i = 0; i < ehdr->e_phnum; i++) 43 | { 44 | phdr = (Elf32_Phdr *) (data + ehdr->e_phoff + ehdr->e_phentsize * i); 45 | 46 | if((vaddr >= phdr[0].p_vaddr) && ((i == ehdr->e_phnum) || (vaddr < phdr[1].p_vaddr))) 47 | { 48 | break; 49 | } 50 | } 51 | return phdr; 52 | } 53 | 54 | void section_write_bss(u32 ios_elf_start, u32 address, u32 size) 55 | { 56 | Elf32_Phdr *phdr = get_section(ios_elf_start, address); 57 | if(!phdr) 58 | return; 59 | 60 | if((address - phdr->p_vaddr + size) > phdr->p_memsz) 61 | { 62 | phdr->p_memsz = (address - phdr->p_vaddr + size); 63 | } 64 | } 65 | 66 | void section_write(u32 ios_elf_start, u32 address, const void *data, u32 size) 67 | { 68 | Elf32_Phdr *phdr = get_section(ios_elf_start, address); 69 | if(!phdr) 70 | return; 71 | 72 | u32 *addr = (u32*)(ios_elf_start + address - phdr->p_vaddr + phdr->p_offset); 73 | 74 | if((address - phdr->p_vaddr + size) > phdr->p_filesz) 75 | { 76 | u32 additionalSize = address - phdr->p_vaddr + size - phdr->p_filesz; 77 | 78 | Elf32_Ehdr *ehdr = (Elf32_Ehdr *) ios_elf_start; 79 | Elf32_Phdr * tmpPhdr; 80 | u32 i; 81 | for(i = (ehdr->e_phnum-1); i >= 0; i--) 82 | { 83 | tmpPhdr = (Elf32_Phdr *) (ios_elf_start + ehdr->e_phoff + ehdr->e_phentsize * i); 84 | 85 | if(phdr->p_offset < tmpPhdr->p_offset) 86 | { 87 | reverse_memcpy((u8*)ios_elf_start + tmpPhdr->p_offset + additionalSize, (u8*)ios_elf_start + tmpPhdr->p_offset, tmpPhdr->p_filesz); 88 | tmpPhdr->p_offset += additionalSize; 89 | } 90 | else { 91 | break; 92 | } 93 | } 94 | phdr->p_filesz += additionalSize; 95 | if(phdr->p_memsz < phdr->p_filesz) 96 | { 97 | phdr->p_memsz = phdr->p_filesz; 98 | } 99 | } 100 | 101 | // in most cases only a word is copied to an aligned address so do a short cut for performance 102 | if(size == 4 && !((unsigned int)addr & 3) && !((unsigned int)data & 3)) 103 | { 104 | *(u32*)addr = *(u32*)data; 105 | } 106 | else 107 | { 108 | kernel_memcpy(addr, data, size); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /ios_kernel/source/elf_patcher.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _ELF_PATCHER_H 25 | #define _ELF_PATCHER_H 26 | 27 | #include "types.h" 28 | 29 | #define ARM_B(addr, func) (0xEA000000 | ((((u32)(func) - (u32)(addr) - 8) >> 2) & 0x00FFFFFF)) 30 | #define ARM_BL(addr, func) (0xEB000000 | ((((u32)(func) - (u32)(addr) - 8) >> 2) & 0x00FFFFFF)) 31 | 32 | typedef struct 33 | { 34 | u32 address; 35 | void* data; 36 | u32 size; 37 | } patch_table_t; 38 | 39 | void section_write(u32 ios_elf_start, u32 address, const void *data, u32 size); 40 | void section_write_bss(u32 ios_elf_start, u32 address, u32 size); 41 | 42 | static inline void section_write_word(u32 ios_elf_start, u32 address, u32 word) 43 | { 44 | section_write(ios_elf_start, address, &word, sizeof(word)); 45 | } 46 | 47 | 48 | static inline void patch_table_entries(u32 ios_elf_start, const patch_table_t * patch_table, u32 patch_count) 49 | { 50 | u32 i; 51 | for(i = 0; i < patch_count; i++) 52 | { 53 | section_write(ios_elf_start, patch_table[i].address, patch_table[i].data, patch_table[i].size); 54 | } 55 | } 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /ios_kernel/source/exception_handler.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "text.h" 25 | #include "types.h" 26 | 27 | void crash_handler(unsigned int *context, int type) 28 | { 29 | clearScreen(0xFFFFFFFF); 30 | 31 | if(type == 0) 32 | { 33 | _printf(0, 0, "GURU MEDITATION ERROR (prefetch abort)"); 34 | } 35 | else if(type == 1) 36 | { 37 | _printf(0, 0, "GURU MEDITATION ERROR (data abort)"); 38 | } 39 | else 40 | { 41 | _printf(0, 0, "GURU MEDITATION ERROR (undefined instruction)"); 42 | } 43 | 44 | int reg = 0; 45 | while(reg < 16) 46 | { 47 | if(reg < 10) 48 | { 49 | _printf(20, 40 + reg * 20, "r%d = %08X", reg, context[1 + reg]); 50 | } 51 | else 52 | { 53 | _printf(20, 40 + reg * 20, "r%d = %08X", reg, context[1 + reg]); 54 | } 55 | 56 | reg++; 57 | } 58 | 59 | _printf(400, 20, "%08X", *(u32*)context[0x10]); 60 | 61 | for(;;); 62 | } 63 | -------------------------------------------------------------------------------- /ios_kernel/source/exception_handler.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _EXCEPTION_HANDLER_H 25 | #define _EXCEPTION_HANDLER_H 26 | 27 | void crash_handler(unsigned int *context, int type); 28 | 29 | static inline void crash_handler_prefetch(unsigned int *context, int unused1, int unused2) 30 | { 31 | crash_handler(context, 0); 32 | } 33 | 34 | static inline void crash_handler_data(unsigned int *context, int unused1, int unused2) 35 | { 36 | crash_handler(context, 1); 37 | } 38 | 39 | static inline void crash_handler_undef_instr(unsigned int *context, int unused1, int unused2) 40 | { 41 | crash_handler(context, 2); 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /ios_kernel/source/font_bin.h: -------------------------------------------------------------------------------- 1 | static const unsigned char font_bin[] = { 2 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x18, 3 | 0x18, 0x00, 0x0c, 0x00, 0x00, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 4 | 0x00, 0x66, 0x66, 0xff, 0x66, 0xff, 0x66, 0x66, 0x00, 0x18, 0x7c, 0x06, 5 | 0x3c, 0x60, 0x3e, 0x18, 0x10, 0x46, 0x66, 0x30, 0x18, 0x0c, 0x66, 0x62, 6 | 0x00, 0x3c, 0x66, 0x3c, 0x1c, 0xe6, 0x66, 0xfc, 0x00, 0x18, 0x0c, 0x06, 7 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x18, 0x30, 0x00, 8 | 0x00, 0x0c, 0x18, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x66, 0x3c, 0xff, 9 | 0x3c, 0x66, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 10 | 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x3e, 11 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 12 | 0x00, 0x40, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x3c, 0x66, 0x76, 13 | 0x6e, 0x66, 0x3c, 0x00, 0x00, 0x18, 0x1c, 0x18, 0x18, 0x18, 0x7e, 0x00, 14 | 0x00, 0x3c, 0x62, 0x30, 0x0c, 0x06, 0x7e, 0x00, 0x00, 0x3c, 0x62, 0x38, 15 | 0x60, 0x66, 0x3c, 0x00, 0x00, 0x6c, 0x6c, 0x66, 0xfe, 0x60, 0x60, 0x00, 16 | 0x00, 0x7e, 0x06, 0x7e, 0x60, 0x66, 0x3c, 0x00, 0x00, 0x3c, 0x06, 0x3e, 17 | 0x66, 0x66, 0x3c, 0x00, 0x00, 0x7e, 0x30, 0x30, 0x18, 0x18, 0x18, 0x00, 18 | 0x00, 0x3c, 0x66, 0x3c, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x3c, 0x66, 0x7c, 19 | 0x60, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 20 | 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x0c, 0x00, 0x00, 0x70, 0x1c, 0x06, 21 | 0x06, 0x1c, 0x70, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x00, 0x00, 22 | 0x00, 0x0e, 0x38, 0x60, 0x60, 0x38, 0x0e, 0x00, 0x00, 0x3c, 0x66, 0x30, 23 | 0x18, 0x00, 0x18, 0x00, 0x00, 0x3c, 0x66, 0x76, 0x76, 0x06, 0x46, 0x3c, 24 | 0x00, 0x3c, 0x66, 0x7e, 0x66, 0x66, 0x66, 0x00, 0x00, 0x3e, 0x66, 0x3e, 25 | 0x66, 0x66, 0x3e, 0x00, 0x00, 0x3c, 0x66, 0x06, 0x06, 0x66, 0x3c, 0x00, 26 | 0x00, 0x1e, 0x36, 0x66, 0x66, 0x36, 0x1e, 0x00, 0x00, 0x7e, 0x06, 0x1e, 27 | 0x06, 0x06, 0x7e, 0x00, 0x00, 0x3e, 0x06, 0x1e, 0x06, 0x06, 0x06, 0x00, 28 | 0x00, 0x3c, 0x66, 0x06, 0x76, 0x66, 0x3c, 0x00, 0x00, 0x66, 0x66, 0x7e, 29 | 0x66, 0x66, 0x66, 0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 30 | 0x00, 0x78, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x66, 0x36, 0x1e, 31 | 0x1e, 0x36, 0x66, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7e, 0x00, 32 | 0x00, 0x46, 0x6e, 0x7e, 0x56, 0x46, 0x46, 0x00, 0x00, 0x66, 0x6e, 0x7e, 33 | 0x76, 0x66, 0x66, 0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 34 | 0x00, 0x3e, 0x66, 0x3e, 0x06, 0x06, 0x06, 0x00, 0x00, 0x3c, 0x66, 0x66, 35 | 0x66, 0x3c, 0x70, 0x00, 0x00, 0x3e, 0x66, 0x3e, 0x1e, 0x36, 0x66, 0x00, 36 | 0x00, 0x3c, 0x66, 0x0c, 0x30, 0x66, 0x3c, 0x00, 0x00, 0x7e, 0x18, 0x18, 37 | 0x18, 0x18, 0x18, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 38 | 0x00, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x46, 0x46, 0x56, 39 | 0x7e, 0x6e, 0x46, 0x00, 0x00, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0x66, 0x00, 40 | 0x00, 0x66, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x00, 0x00, 0x7e, 0x30, 0x18, 41 | 0x0c, 0x06, 0x7e, 0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 42 | 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x40, 0x00, 0x00, 0x3c, 0x30, 0x30, 43 | 0x30, 0x30, 0x30, 0x3c, 0x00, 0x18, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x0c, 0x18, 0x30, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x60, 0x7c, 0x66, 0x7c, 0x00, 46 | 0x00, 0x06, 0x06, 0x3e, 0x66, 0x66, 0x3e, 0x00, 0x00, 0x00, 0x3c, 0x06, 47 | 0x06, 0x06, 0x3c, 0x00, 0x00, 0x60, 0x60, 0x7c, 0x66, 0x66, 0x7c, 0x00, 48 | 0x00, 0x00, 0x3c, 0x66, 0x7e, 0x06, 0x3c, 0x00, 0x00, 0x38, 0x0c, 0x3e, 49 | 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x7c, 0x66, 0x7c, 0x40, 0x3c, 0x00, 50 | 0x00, 0x06, 0x06, 0x3e, 0x66, 0x66, 0x66, 0x00, 0x00, 0x18, 0x00, 0x1c, 51 | 0x18, 0x18, 0x3c, 0x00, 0x00, 0x30, 0x00, 0x30, 0x30, 0x30, 0x1e, 0x00, 52 | 0x00, 0x06, 0x06, 0x36, 0x1e, 0x36, 0x66, 0x00, 0x00, 0x1c, 0x18, 0x18, 53 | 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x66, 0xfe, 0xfe, 0xd6, 0xc6, 0x00, 54 | 0x00, 0x00, 0x3e, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x3c, 0x66, 55 | 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x3e, 0x66, 0x66, 0x3e, 0x06, 0x00, 56 | 0x00, 0x00, 0x7c, 0x66, 0x66, 0x7c, 0x60, 0x00, 0x00, 0x00, 0x3e, 0x66, 57 | 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x7c, 0x06, 0x3c, 0x60, 0x3e, 0x00, 58 | 0x00, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x66, 0x66, 59 | 0x66, 0x66, 0x7c, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x00, 60 | 0x00, 0x00, 0xc6, 0xd6, 0xfe, 0x7c, 0x6c, 0x00, 0x00, 0x00, 0x66, 0x3c, 61 | 0x18, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x66, 0x66, 0x7c, 0x60, 0x3c, 0x00, 62 | 0x00, 0x00, 0x7e, 0x30, 0x18, 0x0c, 0x7e, 0x00, 0x00, 0x00, 0x18, 0x08, 63 | 0x08, 0x04, 0x08, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 64 | 0x00, 0x00, 0x0c, 0x08, 0x08, 0x10, 0x08, 0x08 65 | }; 66 | -------------------------------------------------------------------------------- /ios_kernel/source/fsa.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef FSA_H 25 | #define FSA_H 26 | 27 | #include "types.h" 28 | 29 | #define NAND_DUMP_SIGNATURE_SECTOR 0x01 30 | #define NAND_MAX_DESC_TYPES 5 31 | 32 | #define NAND_DUMP_SIGNATURE 0x4841585844554d50ULL // HAXXDUMP 33 | 34 | #define NAND_DESC_TYPE_SLC 0x534c4320 // 'SLC ' 35 | #define NAND_DESC_TYPE_SLCCMPT 0x534c4332 // 'SLC2' 36 | #define NAND_DESC_TYPE_MLC 0x4d4c4320 // 'MLC ' 37 | #define NAND_DESC_TYPE_SEEPROM 0x45455052 // 'EEPR' 38 | #define NAND_DESC_TYPE_OTP 0x4f545020 // 'OTP ' 39 | 40 | typedef struct _stdio_nand_desc_t 41 | { 42 | u32 nand_type; // nand type 43 | u32 base_sector; // base sector of dump 44 | u32 sector_count; // sector count in SDIO sectors 45 | } __attribute__((packed))stdio_nand_desc_t; 46 | 47 | typedef struct _sdio_nand_signature_sector_t 48 | { 49 | u64 signature; // HAXXDUMP 50 | stdio_nand_desc_t nand_descriptions[NAND_MAX_DESC_TYPES]; 51 | } __attribute__((packed)) sdio_nand_signature_sector_t; 52 | 53 | int FSA_SDReadRawSectors(void *buffer, u32 sector, u32 num_sectors); 54 | int FSA_SDWriteRawSectors(const void *buffer, u32 sector, u32 num_sectors); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /ios_kernel/source/instant_patches.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "config.h" 25 | #include "utils.h" 26 | #include "types.h" 27 | #include "elf_patcher.h" 28 | #include "kernel_patches.h" 29 | #include "ios_mcp_patches.h" 30 | #include "../../ios_mcp/ios_mcp_syms.h" 31 | 32 | typedef struct 33 | { 34 | u32 paddr; 35 | u32 vaddr; 36 | u32 size; 37 | u32 domain; 38 | u32 type; 39 | u32 cached; 40 | } ios_map_shared_info_t; 41 | 42 | void instant_patches_setup(void) 43 | { 44 | // apply IOS ELF launch hook 45 | *(volatile u32*)0x0812A120 = ARM_BL(0x0812A120, kernel_launch_ios); 46 | 47 | // patch FSA raw access 48 | *(volatile u32*)0x1070FAE8 = 0x05812070; 49 | *(volatile u32*)0x1070FAEC = 0xEAFFFFF9; 50 | 51 | /*if(cfw_config.noIosReload) 52 | { 53 | int (*_iosMapSharedUserExecution)(void *descr) = (void*)0x08124F88; 54 | 55 | // patch kernel dev node registration 56 | *(volatile u32*)0x081430B4 = 1; 57 | 58 | // fix 10 minute timeout that crashes MCP after 10 minutes of booting 59 | *(volatile u32*)(0x05022474 - 0x05000000 + 0x081C0000) = 0xFFFFFFFF; // NEW_TIMEOUT 60 | 61 | // patch cached cert check 62 | // start our MCP thread directly on first title change 63 | kernel_memset((void*)(0x050BD000 - 0x05000000 + 0x081C0000), 0, 0x3000); 64 | *(volatile u32*)(0x05054D6C - 0x05000000 + 0x081C0000) = ARM_B(0x05054D6C, _startMainThread); 65 | 66 | // patch MCP authentication check 67 | *(volatile u32*)(0x05014CAC - 0x05000000 + 0x081C0000) = 0x20004770; // mov r0, #0; bx lr 68 | 69 | // patch IOSC_VerifyPubkeySign to always succeed 70 | *(volatile u32*)(0x05052C44 - 0x05000000 + 0x081C0000) = 0xE3A00000; // mov r0, #0 71 | *(volatile u32*)(0x05052C48 - 0x05000000 + 0x081C0000) = 0xE12FFF1E; // bx lr 72 | 73 | // allow custom bootLogoTex and bootMovie.h264 74 | *(volatile u32*)(0xE0030D68 - 0xE0000000 + 0x12900000) = 0xE3A00000; // mov r0, #0 75 | *(volatile u32*)(0xE0030D34 - 0xE0000000 + 0x12900000) = 0xE3A00000; // mov r0, #0 76 | 77 | // allow any region title launch 78 | *(volatile u32*)(0xE0030498 - 0xE0000000 + 0x12900000) = 0xE3A00000; // mov r0, #0 79 | 80 | // set zero to start thread directly on first title change 81 | *(volatile u32*)(0x050BC580 - 0x05000000 + 0x081C0000) = 0; 82 | // down display launch image at this state 83 | *(volatile u32*)(_text_start - 4 - 0x05100000 + 0x13D80000) = 0; 84 | 85 | ios_map_shared_info_t map_info; 86 | map_info.paddr = 0x050BD000 - 0x05000000 + 0x081C0000; 87 | map_info.vaddr = 0x050BD000; 88 | map_info.size = 0x3000; 89 | map_info.domain = 1; // MCP 90 | map_info.type = 3; // 0 = undefined, 1 = kernel only, 2 = read only, 3 = read/write 91 | map_info.cached = 0xFFFFFFFF; 92 | _iosMapSharedUserExecution(&map_info); // actually a bss section but oh well it will have read/write 93 | 94 | map_info.paddr = 0x05116000 - 0x05100000 + 0x13D80000; 95 | map_info.vaddr = 0x05116000; 96 | map_info.size = 0x4000; 97 | map_info.domain = 1; // MCP 98 | map_info.type = 3; // 0 = undefined, 1 = kernel only, 2 = read only, 3 = read write 99 | map_info.cached = 0xFFFFFFFF; 100 | _iosMapSharedUserExecution(&map_info); 101 | }*/ 102 | } 103 | -------------------------------------------------------------------------------- /ios_kernel/source/instant_patches.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _INSTANT_PATCHES_SETUP_H_ 25 | #define _INSTANT_PATCHES_SETUP_H_ 26 | 27 | void instant_patches_setup(void); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ios_kernel/source/ios_bsp_patches.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "types.h" 25 | #include "elf_patcher.h" 26 | #include "ios_bsp_patches.h" 27 | #include "../../ios_bsp/ios_bsp_syms.h" 28 | #include "fsa.h" 29 | #include "utils.h" 30 | 31 | #define BSP_PHYS_DIFF (-0xE6000000 + 0x13CC0000) 32 | 33 | extern const patch_table_t fs_patches_table[]; 34 | extern const patch_table_t fs_patches_table_end[]; 35 | 36 | u32 bsp_get_phys_code_base(void) 37 | { 38 | return _text_start + BSP_PHYS_DIFF; 39 | } 40 | 41 | int bsp_init_seeprom_buffer(u32 baseSector, int dumpFound) 42 | { 43 | void *tmpBuffer = (void*)0x00140000; 44 | 45 | if(dumpFound) 46 | { 47 | int res = FSA_SDReadRawSectors(tmpBuffer, baseSector, 1); 48 | if(res < 0) 49 | return res; 50 | } 51 | else 52 | { 53 | //! just clear out the seeprom and it will be re-initialized on BSP module 54 | //! TODO: maybe read in the seeprom here from SPI or BSP module 55 | kernel_memset(tmpBuffer, 0, 0x200); 56 | } 57 | 58 | int level = disable_interrupts(); 59 | unsigned int control_register = disable_mmu(); 60 | 61 | kernel_memcpy((void*)(_seeprom_buffer_start - 0xE6047000 + 0x13D07000), tmpBuffer, 0x200); 62 | 63 | restore_mmu(control_register); 64 | enable_interrupts(level); 65 | 66 | return 0; 67 | } 68 | 69 | void bsp_run_patches(u32 ios_elf_start) 70 | { 71 | section_write(ios_elf_start, _text_start, (void*)bsp_get_phys_code_base(), _text_end - _text_start); 72 | section_write_bss(ios_elf_start, _bss_start, _bss_end - _bss_start); 73 | 74 | section_write(ios_elf_start, _seeprom_buffer_start, (void*)(_seeprom_buffer_start - 0xE6047000 + 0x13D07000), 0x200); 75 | 76 | section_write_word(ios_elf_start, 0xE600D08C, ARM_B(0xE600D08C, EEPROM_SPI_ReadWord)); 77 | section_write_word(ios_elf_start, 0xE600D010, ARM_B(0xE600D010, EEPROM_SPI_WriteWord)); 78 | section_write_word(ios_elf_start, 0xE600CF5C, ARM_B(0xE600CF5C, EEPROM_WriteControl)); 79 | } 80 | -------------------------------------------------------------------------------- /ios_kernel/source/ios_bsp_patches.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _BSP_PATCHES_H_ 25 | #define _BSP_PATCHES_H_ 26 | 27 | u32 bsp_get_phys_code_base(void); 28 | void bsp_run_patches(u32 ios_elf_start); 29 | int bsp_init_seeprom_buffer(u32 baseSector, int dumpFound); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ios_kernel/source/ios_fs_patches.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _FS_PATCHES_H_ 25 | #define _FS_PATCHES_H_ 26 | 27 | u32 fs_get_phys_code_base(void); 28 | void fs_run_patches(u32 ios_elf_start); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /ios_kernel/source/ios_fs_patches_asm.s: -------------------------------------------------------------------------------- 1 | .arm 2 | 3 | # patch out sdcard deinitialization 4 | patch_mdExit: 5 | bx lr 6 | 7 | # patch out FSRawOpen access 8 | patch_FSRawOpen: 9 | streq r2, [r1, #0x70] 10 | .word 0xEAFFFFF9 11 | 12 | # nop out hmac memcmp 13 | patch_hmac_check: 14 | mov r0, #0 15 | 16 | # null out references to slcSomething1 and slcSomething2 17 | # (nulling them out is apparently ok; more importantly, i'm not sure what they do and would rather get a crash than unwanted slc-writing) 18 | slcSomething1: 19 | .word 0x00000000 20 | slcSomething2: 21 | .word 0x00000000 22 | 23 | #syslogOutput_hook: 24 | # push {r0,lr} 25 | # bl dump_syslog 26 | # pop {r0,lr} 27 | # restore original instruction 28 | # pop {r4-r8,r10,pc} 29 | 30 | 31 | .globl fs_patches_table, fs_patches_table_end 32 | fs_patches_table: 33 | # origin data size 34 | .word 0x107BD374, patch_mdExit, 4 35 | .word 0x1070FAE8, patch_FSRawOpen, 8 36 | .word 0x107B96B8, slcSomething1, 8 37 | .word 0x107206F0, patch_hmac_check, 4 38 | # .word 0x107F0B68, syslogOutput_hook, 4 39 | fs_patches_table_end: 40 | 41 | -------------------------------------------------------------------------------- /ios_kernel/source/ios_mcp_patches.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "types.h" 25 | #include "elf_patcher.h" 26 | #include "config.h" 27 | #include "ios_mcp_patches.h" 28 | #include "../../ios_mcp/ios_mcp.bin.h" 29 | #include "../../ios_mcp/ios_mcp_syms.h" 30 | 31 | #define MCP_CODE_BASE_PHYS_ADDR (-0x05100000 + 0x13D80000) 32 | 33 | extern const patch_table_t mcp_patches_table[]; 34 | extern const patch_table_t mcp_patches_table_end[]; 35 | 36 | u32 mcp_get_phys_code_base(void) 37 | { 38 | return _text_start + MCP_CODE_BASE_PHYS_ADDR; 39 | } 40 | 41 | void mcp_run_patches(u32 ios_elf_start) 42 | { 43 | // write ios_mcp code and bss 44 | section_write_bss(ios_elf_start, _bss_start, _bss_end - _bss_start); 45 | section_write(ios_elf_start, _text_start, (void*)mcp_get_phys_code_base(), _text_end - _text_start); 46 | 47 | section_write_word(ios_elf_start, 0x05056718, ARM_BL(0x05056718, _text_start)); 48 | 49 | /*if(cfw_config.syshaxXml) 50 | { 51 | section_write(ios_elf_start, 0x050600DC, "/vol/system/config/syshax.xml", 0x20); 52 | section_write(ios_elf_start, 0x050600FC, "/vol/system_slc/config/syshax.xml", 0x24); 53 | }*/ 54 | 55 | //section_write_word(ios_elf_start, (_text_start - 4), cfw_config.launchImage); 56 | 57 | u32 patch_count = (u32)(((u8*)mcp_patches_table_end) - ((u8*)mcp_patches_table)) / sizeof(patch_table_t); 58 | patch_table_entries(ios_elf_start, mcp_patches_table, patch_count); 59 | } 60 | -------------------------------------------------------------------------------- /ios_kernel/source/ios_mcp_patches.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _MCP_PATCHES_H_ 25 | #define _MCP_PATCHES_H_ 26 | 27 | #define MCP_LAUNCH_IMG_PHYS_ADDR (0x27000000) 28 | 29 | u32 mcp_get_phys_code_base(void); 30 | void mcp_run_patches(u32 ios_elf_start); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /ios_kernel/source/ios_mcp_patches_asm.s: -------------------------------------------------------------------------------- 1 | .arm 2 | 3 | #patch_os_launch_sig_check: 4 | # .thumb 5 | # mov r0, #0 6 | # mov r0, #0 7 | 8 | patch_MCP_authentication_check: 9 | .thumb 10 | mov r0, #0 11 | bx lr 12 | 13 | patch_IOSC_VerifyPubkeySign: 14 | patch_cert_verification: 15 | patch_cached_cert_check: 16 | patch_bootMovie_check: 17 | patch_bootLogoTex_check: 18 | patch_region_launch_check: 19 | .arm 20 | mov r0, #0 21 | bx lr 22 | 23 | 24 | .globl mcp_patches_table, mcp_patches_table_end 25 | mcp_patches_table: 26 | # origin data size 27 | # .word 0x0500A818, patch_os_launch_sig_check, 4 28 | .word 0x05014CAC, patch_MCP_authentication_check, 4 29 | .word 0x05052C44, patch_IOSC_VerifyPubkeySign, 8 30 | .word 0x05052A90, patch_cert_verification, 8 31 | .word 0x05054D6C, patch_cached_cert_check, 8 32 | # over an hour, MCP crash prevention 33 | .word 0x05022474, 0xFFFFFFFF, 4 34 | # MCP patches end here actually but lets tread the ACP patches as MCP as there are only patches 35 | .word 0xE0030D68, patch_bootMovie_check, 4 36 | .word 0xE0030D34, patch_bootLogoTex_check, 4 37 | .word 0xE0030498, patch_region_launch_check, 4 38 | mcp_patches_table_end: 39 | 40 | -------------------------------------------------------------------------------- /ios_kernel/source/kernel_patches.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _KERNEL_PATCHES_H 25 | #define _KERNEL_PATCHES_H 26 | 27 | int kernel_init_otp_buffer(u32 sd_sector, int tagValid); 28 | void kernel_launch_ios(u32 launch_address, u32 L, u32 C, u32 H); 29 | void kernel_run_patches(u32 ios_elf_start); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ios_kernel/source/kernel_patches_asm.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .align 4 3 | patch_kernel_domains: 4 | str r3, [r7,#0x10] 5 | str r3, [r7,#0x0C] 6 | str r3, [r7,#0x04] 7 | str r3, [r7,#0x14] 8 | str r3, [r7,#0x08] 9 | str r3, [r7,#0x34] 10 | patch_kernel_domains_end: 11 | 12 | .globl kernel_patches_table, kernel_patches_table_end 13 | kernel_patches_table: 14 | # origin data size 15 | .word 0x081253C4, patch_kernel_domains, (kernel_patches_table_end - kernel_patches_table) 16 | kernel_patches_table_end: 17 | 18 | -------------------------------------------------------------------------------- /ios_kernel/source/redirection_setup.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "config.h" 25 | #include "utils.h" 26 | #include "fsa.h" 27 | #include "kernel_patches.h" 28 | #include "ios_bsp_patches.h" 29 | 30 | void redirection_setup(void) 31 | { 32 | int seepromDumpFound = 0; 33 | u32 seepromDumpBaseSector = 0x4FF; 34 | int otpDumpFound = 0; 35 | u32 otpDumpBaseSector = 0x4FD; 36 | int writeInfoSector = 0; 37 | sdio_nand_signature_sector_t *infoSector = (sdio_nand_signature_sector_t*)0x00141000; 38 | kernel_memset(infoSector, 0x00, 0x200); 39 | 40 | int result = FSA_SDReadRawSectors(infoSector, NAND_DUMP_SIGNATURE_SECTOR, 1); 41 | if(result < 0) 42 | return; 43 | 44 | if(infoSector->signature == NAND_DUMP_SIGNATURE) 45 | { 46 | int i; 47 | for(i = 0; i < NAND_MAX_DESC_TYPES; i++) 48 | { 49 | if(infoSector->nand_descriptions[i].nand_type == NAND_DESC_TYPE_SEEPROM) 50 | { 51 | seepromDumpFound = 1; 52 | seepromDumpBaseSector = infoSector->nand_descriptions[i].base_sector; 53 | } 54 | if(infoSector->nand_descriptions[i].nand_type == NAND_DESC_TYPE_OTP) 55 | { 56 | otpDumpFound = 1; 57 | otpDumpBaseSector = infoSector->nand_descriptions[i].base_sector; 58 | } 59 | } 60 | } 61 | 62 | /*if(cfw_config.seeprom_red) 63 | { 64 | bsp_init_seeprom_buffer(seepromDumpBaseSector, seepromDumpFound); 65 | 66 | if(seepromDumpFound == 0) 67 | { 68 | infoSector->nand_descriptions[3].nand_type = NAND_DESC_TYPE_SEEPROM; 69 | infoSector->nand_descriptions[3].base_sector = seepromDumpBaseSector; 70 | infoSector->nand_descriptions[3].sector_count = 1; 71 | writeInfoSector++; 72 | } 73 | } 74 | 75 | if(cfw_config.otp_red) 76 | { 77 | kernel_init_otp_buffer(otpDumpBaseSector, otpDumpFound); 78 | 79 | if(otpDumpFound == 0) 80 | { 81 | infoSector->nand_descriptions[4].nand_type = NAND_DESC_TYPE_OTP; 82 | infoSector->nand_descriptions[4].base_sector = otpDumpBaseSector; 83 | infoSector->nand_descriptions[4].sector_count = 2; 84 | writeInfoSector++; 85 | } 86 | }*/ 87 | 88 | if(writeInfoSector > 0) 89 | { 90 | FSA_SDWriteRawSectors(infoSector, NAND_DUMP_SIGNATURE_SECTOR, 1); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /ios_kernel/source/redirection_setup.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _REDIRECTION_SETUP_H_ 25 | #define _REDIRECTION_SETUP_H_ 26 | 27 | void redirection_setup(void); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ios_kernel/source/text.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "types.h" 7 | #include "font_bin.h" 8 | 9 | #define FRAMEBUFFER_ADDRESS (0x14000000+0x38C0000) 10 | #define FRAMEBUFFER_STRIDE (0xE00) 11 | #define FRAMEBUFFER_STRIDE_WORDS (FRAMEBUFFER_STRIDE >> 2) 12 | 13 | #define CHAR_MULT 2 14 | #define CHAR_SIZE_X 8 15 | #define CHAR_SIZE_Y 8 16 | 17 | 18 | u32* const framebuffer = (u32*)FRAMEBUFFER_ADDRESS; 19 | 20 | void clearScreen(u32 color) 21 | { 22 | int i; 23 | for(i = 0; i < 896 * 504; i++) 24 | { 25 | framebuffer[i] = color; 26 | } 27 | } 28 | 29 | void drawCharacter(char c, int x, int y) 30 | { 31 | if(c < 32)return; 32 | c -= 32; 33 | u8* charData = (u8*)&font_bin[(int)c << 3]; 34 | u32* fb = &framebuffer[x + y * FRAMEBUFFER_STRIDE_WORDS]; 35 | int i, j, n, k; 36 | for(i = 0; i < CHAR_SIZE_Y; i++) 37 | { 38 | for(k = 0; k < CHAR_MULT; k++) 39 | { 40 | u8 v = *charData; 41 | 42 | for(j = 0; j < CHAR_SIZE_X; j++) 43 | { 44 | for(n = 0; n < CHAR_MULT; n++) 45 | { 46 | if(v & 1) 47 | { 48 | *fb = 0x00000000; 49 | } 50 | else 51 | { 52 | *fb = 0xFFFFFFFF; 53 | } 54 | fb++; 55 | } 56 | v >>= 1; 57 | } 58 | fb += FRAMEBUFFER_STRIDE_WORDS - CHAR_SIZE_X * CHAR_MULT; 59 | } 60 | charData++; 61 | } 62 | } 63 | 64 | void drawString(char* str, int x, int y) 65 | { 66 | if(!str) return; 67 | int k; 68 | int dx = 0, dy = 0; 69 | for(k = 0; str[k]; k++) 70 | { 71 | if(str[k] >= 32 && str[k] < 128) 72 | drawCharacter(str[k], x + dx, y + dy); 73 | 74 | dx += CHAR_SIZE_X * CHAR_MULT; 75 | 76 | if(str[k] == '\n') 77 | { 78 | dx = 0; 79 | dy -= CHAR_SIZE_Y * CHAR_MULT; 80 | } 81 | } 82 | } 83 | 84 | void _printf(int x, int y, const char *format, ...) 85 | { 86 | void (*kernel_vsnprintf)(char * s, size_t n, const char * format, va_list arg) = (void*)0x0813293C; 87 | 88 | va_list args; 89 | va_start(args, format); 90 | static char buffer[0x100]; 91 | 92 | kernel_vsnprintf(buffer, 0xFF, format, args); 93 | drawString(buffer, x, y); 94 | 95 | va_end(args); 96 | } 97 | -------------------------------------------------------------------------------- /ios_kernel/source/text.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXT_H 2 | #define TEXT_H 3 | 4 | #include "types.h" 5 | 6 | void drawSplashScreen(void); 7 | void clearScreen(u32 color); 8 | void drawString(char* str, int x, int y); 9 | void _printf(int x, int y, const char *format, ...); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /ios_kernel/source/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _TYPES_H 2 | #define _TYPES_H 3 | 4 | #include 5 | 6 | typedef uint8_t u8; 7 | typedef uint16_t u16; 8 | typedef uint32_t u32; 9 | typedef uint64_t u64; 10 | 11 | typedef int8_t s8; 12 | typedef int16_t s16; 13 | typedef int32_t s32; 14 | typedef int64_t s64; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /ios_kernel/source/utils.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | 25 | // this memcpy is optimized for speed and to work with MEM1 32 bit access alignment requirement 26 | void reverse_memcpy(void* dst, const void* src, unsigned int size) 27 | { 28 | const unsigned char *src_p; 29 | unsigned char *dst_p; 30 | 31 | if((size >= 4) && !((dst - src) & 3)) 32 | { 33 | const unsigned int *src_p32; 34 | unsigned int *dst_p32; 35 | unsigned int endDst = ((unsigned int)dst) + size; 36 | unsigned int endRest = endDst & 3; 37 | 38 | if(endRest) 39 | { 40 | src_p = ((const unsigned char*)(src + size)) - 1; 41 | dst_p = ((unsigned char*)endDst) - 1; 42 | size -= endRest; 43 | 44 | while(endRest--) 45 | *dst_p-- = *src_p--; 46 | } 47 | 48 | src_p32 = ((const unsigned int*)(src + size)) - 1; 49 | dst_p32 = ((unsigned int*)(dst + size)) - 1; 50 | 51 | unsigned int size32 = size >> 5; 52 | if(size32) 53 | { 54 | size &= 0x1F; 55 | 56 | while(size32--) 57 | { 58 | src_p32 -= 8; 59 | dst_p32 -= 8; 60 | 61 | dst_p32[8] = src_p32[8]; 62 | dst_p32[7] = src_p32[7]; 63 | dst_p32[6] = src_p32[6]; 64 | dst_p32[5] = src_p32[5]; 65 | dst_p32[4] = src_p32[4]; 66 | dst_p32[3] = src_p32[3]; 67 | dst_p32[2] = src_p32[2]; 68 | dst_p32[1] = src_p32[1]; 69 | } 70 | } 71 | 72 | unsigned int size4 = size >> 2; 73 | if(size4) 74 | { 75 | size &= 3; 76 | 77 | while(size4--) 78 | *dst_p32-- = *src_p32--; 79 | } 80 | 81 | dst_p = ((unsigned char*)dst_p32) + 3; 82 | src_p = ((const unsigned char*)src_p32) + 3; 83 | } 84 | else 85 | { 86 | dst_p = ((unsigned char*)dst) + size - 1; 87 | src_p = ((const unsigned char*)src) + size - 1; 88 | } 89 | 90 | while(size--) 91 | *dst_p-- = *src_p--; 92 | } 93 | -------------------------------------------------------------------------------- /ios_kernel/source/utils.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _UTILS_H 25 | #define _UTILS_H 26 | 27 | #define ALIGN4(x) (((x) + 3) & ~3) 28 | 29 | #define kernel_memcpy ((void * (*)(void*, const void*, int))0x08131D04) 30 | #define kernel_memset ((void *(*)(void*, int, unsigned int))0x08131DA0) 31 | #define kernel_strncpy ((char *(*)(char*, const char*, unsigned int))0x081329B8) 32 | #define disable_interrupts ((int(*)())0x0812E778) 33 | #define enable_interrupts ((int(*)(int))0x0812E78C) 34 | #define kernel_bsp_command_5 ((int (*)(const char*, int offset, const char*, int size, void *buffer))0x0812EC40) 35 | 36 | void reverse_memcpy(void* dest, const void* src, unsigned int size); 37 | 38 | static inline unsigned int disable_mmu(void) 39 | { 40 | unsigned int control_register = 0; 41 | asm volatile("MRC p15, 0, %0, c1, c0, 0" : "=r" (control_register)); 42 | asm volatile("MCR p15, 0, %0, c1, c0, 0" : : "r" (control_register & 0xFFFFEFFA)); 43 | return control_register; 44 | } 45 | 46 | static inline void restore_mmu(unsigned int control_register) 47 | { 48 | asm volatile("MCR p15, 0, %0, c1, c0, 0" : : "r" (control_register)); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /ios_mcp/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(strip $(DEVKITARM)),) 2 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 3 | endif 4 | 5 | ifeq ($(filter $(DEVKITARM)/bin,$(PATH)),) 6 | export PATH:=$(DEVKITARM)/bin:$(PATH) 7 | endif 8 | 9 | CC = arm-none-eabi-gcc 10 | LINK = arm-none-eabi-gcc 11 | AS = arm-none-eabi-as 12 | OBJCOPY = arm-none-eabi-objcopy 13 | OBJDUMP = arm-none-eabi-objdump 14 | CFLAGS += -Wall -mbig-endian -std=gnu11 -mcpu=arm926ej-s -msoft-float -mfloat-abi=soft -Os 15 | LDFLAGS += -nostartfiles -nodefaultlibs -mbig-endian -Wl,-T,link.ld 16 | LIBDIRS += -L$(CURDIR)/../libs 17 | LIBS += -lgcc 18 | 19 | CFILES = $(wildcard source/*.c) 20 | BINFILES = $(wildcard data/*.bin) 21 | OFILES = $(BINFILES:data/%.bin=build/%.bin.o) 22 | OFILES += $(CFILES:source/%.c=build/%.o) 23 | DFILES = $(CFILES:source/%.c=build/%.d) 24 | SFILES = $(wildcard source/*.s) 25 | OFILES += $(SFILES:source/%.s=build/%.o) 26 | PROJECTNAME = ${shell basename "$(CURDIR)"} 27 | CWD = "$(CURDIR)"" 28 | 29 | #--------------------------------------------------------------------------------- 30 | # canned command sequence for binary data, taken from devkitARM 31 | #--------------------------------------------------------------------------------- 32 | define bin2o 33 | bin2s $< | $(AS) -EB -o $(@) 34 | endef 35 | 36 | .PHONY:=all dirs 37 | 38 | all: dirs $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 39 | 40 | dirs: 41 | @mkdir -p build 42 | 43 | $(PROJECTNAME).elf: $(OFILES) 44 | @echo "LD $@" 45 | @$(LINK) $(LDFLAGS) -o $(PROJECTNAME).elf $(sort $(filter-out build/crt0.o, $(OFILES))) $(LIBDIRS) $(LIBS) 46 | 47 | $(PROJECTNAME).bin: $(PROJECTNAME).elf 48 | @echo "OBJCOPY $@\n" 49 | @$(OBJCOPY) -j .text -j .rodata -j .data -O binary $(PROJECTNAME).elf $@ 50 | 51 | $(PROJECTNAME).bin.h: $(PROJECTNAME).bin 52 | @xxd -i $< | sed "s/unsigned/static const unsigned/g;s/$(PROJECTNAME)$*/$(PROJECTNAME)/g" > $@ 53 | 54 | $(PROJECTNAME)_syms.h: 55 | @echo "#ifndef $(PROJECTNAME)_SYMS_H" > $@ 56 | @echo "#define $(PROJECTNAME)_SYMS_H" >> $@ 57 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep 'g F .text' | grep -v '.hidden' | awk '{print "#define " $$6 " 0x" $$1}' >> $@ 58 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep -e 'g .text' -e '_bss_' | awk '{print "#define " $$5 " 0x" $$1}' >> $@ 59 | @echo "#endif" >> $@ 60 | 61 | clean: 62 | @rm -f build/*.o build/*.d 63 | @rm -f $(PROJECTNAME).elf $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 64 | @echo "all cleaned up !" 65 | 66 | -include $(DFILES) 67 | 68 | build/%.o: source/%.c 69 | @echo "CC $(notdir $<)" 70 | @$(CC) $(CFLAGS) -c $< -o $@ 71 | @$(CC) -MM $< > build/$*.d 72 | 73 | build/%.o: source/%.s 74 | @echo "CC $(notdir $<)" 75 | @$(CC) $(CFLAGS) -xassembler-with-cpp -c $< -o $@ 76 | @$(CC) -MM $< > build/$*.d 77 | 78 | build/%.bin.o: data/%.bin 79 | @echo "BIN $(notdir $<)" 80 | @$(bin2o) 81 | -------------------------------------------------------------------------------- /ios_mcp/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(arm) 2 | 3 | SECTIONS 4 | { 5 | .text 0x05116000 : { 6 | _text_start = .; 7 | build/crt0.o(.init) 8 | *(.text*) 9 | *(.rodata*) 10 | } 11 | _text_end = .; 12 | 13 | .bss 0x050BE000 : { 14 | _bss_start = .; 15 | *(.bss*); 16 | } 17 | _bss_end = .; 18 | 19 | /DISCARD/ : { 20 | *(*); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /ios_mcp/source/crt0.s: -------------------------------------------------------------------------------- 1 | .section ".init" 2 | .arm 3 | .align 4 4 | 5 | .extern _startMainThread 6 | .type _startMainThread, %function 7 | 8 | mcpMainThread_hook: 9 | mov r11, r0 10 | push {r0-r11,lr} 11 | 12 | bl _startMainThread 13 | 14 | pop {r0-r11,pc} 15 | -------------------------------------------------------------------------------- /ios_mcp/source/font.c: -------------------------------------------------------------------------------- 1 | const unsigned char font_bin[] = { 2 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x18, 0x18, 0x00, 0x0C, 0x00, 3 | 0x00, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0xFF, 0x66, 0xFF, 0x66, 0x66, 4 | 0x00, 0x18, 0x7C, 0x06, 0x3C, 0x60, 0x3E, 0x18, 0x10, 0x46, 0x66, 0x30, 0x18, 0x0C, 0x66, 0x62, 5 | 0x00, 0x3C, 0x66, 0x3C, 0x1C, 0xE6, 0x66, 0xFC, 0x00, 0x18, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 6 | 0x00, 0x30, 0x18, 0x0C, 0x0C, 0x18, 0x30, 0x00, 0x00, 0x0C, 0x18, 0x30, 0x30, 0x18, 0x0C, 0x00, 7 | 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 8 | 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 9 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x40, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00, 10 | 0x00, 0x3C, 0x66, 0x76, 0x6E, 0x66, 0x3C, 0x00, 0x00, 0x18, 0x1C, 0x18, 0x18, 0x18, 0x7E, 0x00, 11 | 0x00, 0x3C, 0x62, 0x30, 0x0C, 0x06, 0x7E, 0x00, 0x00, 0x3C, 0x62, 0x38, 0x60, 0x66, 0x3C, 0x00, 12 | 0x00, 0x6C, 0x6C, 0x66, 0xFE, 0x60, 0x60, 0x00, 0x00, 0x7E, 0x06, 0x7E, 0x60, 0x66, 0x3C, 0x00, 13 | 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x7E, 0x30, 0x30, 0x18, 0x18, 0x18, 0x00, 14 | 0x00, 0x3C, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x3C, 0x66, 0x7C, 0x60, 0x66, 0x3C, 0x00, 15 | 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x0C, 0x00, 16 | 0x00, 0x70, 0x1C, 0x06, 0x06, 0x1C, 0x70, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 17 | 0x00, 0x0E, 0x38, 0x60, 0x60, 0x38, 0x0E, 0x00, 0x00, 0x3C, 0x66, 0x30, 0x18, 0x00, 0x18, 0x00, 18 | 0x00, 0x3C, 0x66, 0x76, 0x76, 0x06, 0x46, 0x3C, 0x00, 0x3C, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, 19 | 0x00, 0x3E, 0x66, 0x3E, 0x66, 0x66, 0x3E, 0x00, 0x00, 0x3C, 0x66, 0x06, 0x06, 0x66, 0x3C, 0x00, 20 | 0x00, 0x1E, 0x36, 0x66, 0x66, 0x36, 0x1E, 0x00, 0x00, 0x7E, 0x06, 0x1E, 0x06, 0x06, 0x7E, 0x00, 21 | 0x00, 0x3E, 0x06, 0x1E, 0x06, 0x06, 0x06, 0x00, 0x00, 0x3C, 0x66, 0x06, 0x76, 0x66, 0x3C, 0x00, 22 | 0x00, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 23 | 0x00, 0x78, 0x30, 0x30, 0x30, 0x36, 0x1C, 0x00, 0x00, 0x66, 0x36, 0x1E, 0x1E, 0x36, 0x66, 0x00, 24 | 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7E, 0x00, 0x00, 0x46, 0x6E, 0x7E, 0x56, 0x46, 0x46, 0x00, 25 | 0x00, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x66, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 26 | 0x00, 0x3E, 0x66, 0x3E, 0x06, 0x06, 0x06, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x70, 0x00, 27 | 0x00, 0x3E, 0x66, 0x3E, 0x1E, 0x36, 0x66, 0x00, 0x00, 0x3C, 0x66, 0x0C, 0x30, 0x66, 0x3C, 0x00, 28 | 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 29 | 0x00, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x46, 0x46, 0x56, 0x7E, 0x6E, 0x46, 0x00, 30 | 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00, 0x00, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x00, 31 | 0x00, 0x7E, 0x30, 0x18, 0x0C, 0x06, 0x7E, 0x00, 0x00, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 32 | 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00, 0x00, 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 33 | 0x00, 0x18, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 34 | 0x00, 0x0C, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x60, 0x7C, 0x66, 0x7C, 0x00, 35 | 0x00, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E, 0x00, 0x00, 0x00, 0x3C, 0x06, 0x06, 0x06, 0x3C, 0x00, 36 | 0x00, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x06, 0x3C, 0x00, 37 | 0x00, 0x38, 0x0C, 0x3E, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x7C, 0x66, 0x7C, 0x40, 0x3C, 0x00, 38 | 0x00, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x18, 0x00, 0x1C, 0x18, 0x18, 0x3C, 0x00, 39 | 0x00, 0x30, 0x00, 0x30, 0x30, 0x30, 0x1E, 0x00, 0x00, 0x06, 0x06, 0x36, 0x1E, 0x36, 0x66, 0x00, 40 | 0x00, 0x1C, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x66, 0xFE, 0xFE, 0xD6, 0xC6, 0x00, 41 | 0x00, 0x00, 0x3E, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00, 42 | 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x00, 43 | 0x00, 0x00, 0x3E, 0x66, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x7C, 0x06, 0x3C, 0x60, 0x3E, 0x00, 44 | 0x00, 0x18, 0x7E, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x00, 45 | 0x00, 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00, 0xC6, 0xD6, 0xFE, 0x7C, 0x6C, 0x00, 46 | 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x66, 0x66, 0x7C, 0x60, 0x3C, 0x00, 47 | 0x00, 0x00, 0x7E, 0x30, 0x18, 0x0C, 0x7E, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x04, 0x08, 0x08, 48 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x0C, 0x08, 0x08, 0x10, 0x08, 0x08, 49 | }; 50 | -------------------------------------------------------------------------------- /ios_mcp/source/font_bin.h: -------------------------------------------------------------------------------- 1 | extern const u8 font_bin[]; -------------------------------------------------------------------------------- /ios_mcp/source/fsa.h: -------------------------------------------------------------------------------- 1 | #ifndef FSA_H 2 | #define FSA_H 3 | 4 | typedef struct 5 | { 6 | u32 flag; 7 | u32 permission; 8 | u32 owner_id; 9 | u32 group_id; 10 | u32 size; // size in bytes 11 | u32 physsize; // physical size on disk in bytes 12 | u32 unk[3]; 13 | u32 id; 14 | u32 ctime; 15 | u32 mtime; 16 | u32 unk2[0x0D]; 17 | }fileStat_s; 18 | 19 | typedef struct 20 | { 21 | fileStat_s stat; 22 | char name[0x100]; 23 | }directoryEntry_s; 24 | 25 | #define DIR_ENTRY_IS_DIRECTORY 0x80000000 26 | 27 | #define FSA_MOUNTFLAGS_BINDMOUNT (1 << 0) 28 | #define FSA_MOUNTFLAGS_GLOBAL (1 << 1) 29 | 30 | int FSA_Open(); 31 | 32 | int FSA_Mount(int fd, char* device_path, char* volume_path, u32 flags, char* arg_string, int arg_string_len); 33 | int FSA_Unmount(int fd, char* path, u32 flags); 34 | 35 | int FSA_GetDeviceInfo(int fd, char* device_path, int type, u32* out_data); 36 | 37 | int FSA_MakeDir(int fd, char* path, u32 flags); 38 | int FSA_OpenDir(int fd, char* path, int* outHandle); 39 | int FSA_ReadDir(int fd, int handle, directoryEntry_s* out_data); 40 | int FSA_RewindDir(int fd, int handle); 41 | int FSA_CloseDir(int fd, int handle); 42 | int FSA_ChangeDir(int fd, char* path); 43 | 44 | int FSA_OpenFile(int fd, char* path, char* mode, int* outHandle); 45 | int FSA_ReadFile(int fd, void* data, u32 size, u32 cnt, int fileHandle, u32 flags); 46 | int FSA_WriteFile(int fd, void* data, u32 size, u32 cnt, int fileHandle, u32 flags); 47 | int FSA_StatFile(int fd, int handle, fileStat_s* out_data); 48 | int FSA_CloseFile(int fd, int fileHandle); 49 | int FSA_SetPosFile(int fd, int fileHandle, u32 position); 50 | int FSA_GetStat(int fd, char *path, fileStat_s* out_data); 51 | int FSA_Remove(int fd, char *path); 52 | int FSA_ChangeMode(int fd, char *path, int mode); 53 | 54 | int FSA_RawOpen(int fd, char* device_path, int* outHandle); 55 | int FSA_RawRead(int fd, void* data, u32 size_bytes, u32 cnt, u64 sector_offset, int device_handle); 56 | int FSA_RawWrite(int fd, void* data, u32 size_bytes, u32 cnt, u64 sector_offset, int device_handle); 57 | int FSA_RawClose(int fd, int device_handle); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /ios_mcp/source/imports.c: -------------------------------------------------------------------------------- 1 | #include "imports.h" 2 | 3 | void usleep(u32 time) 4 | { 5 | ((void (*const)(u32))0x050564E4)(time); 6 | } 7 | 8 | void* memset(void* dst, int val, size_t size) 9 | { 10 | char* _dst = dst; 11 | 12 | int i; 13 | for(i = 0; i < size; i++) _dst[i] = val; 14 | 15 | return dst; 16 | } 17 | 18 | void* (*const _memcpy)(void* dst, void* src, int size) = (void*)0x05054E54; 19 | 20 | void* memcpy(void* dst, const void* src, size_t size) 21 | { 22 | return _memcpy(dst, (void*)src, size); 23 | } 24 | 25 | int strlen(const char* str) 26 | { 27 | unsigned int i = 0; 28 | while (str[i]) { 29 | i++; 30 | } 31 | return i; 32 | } 33 | 34 | char* strncpy(char* dst, const char* src, size_t size) 35 | { 36 | int i; 37 | for(i = 0; i < size; i++) 38 | { 39 | dst[i] = src[i]; 40 | if(src[i] == '\0') return dst; 41 | } 42 | 43 | return dst; 44 | } 45 | 46 | int vsnprintf(char * s, size_t n, const char * format, va_list arg) 47 | { 48 | return ((int (*const)(char*, size_t, const char *, va_list))0x05055C40)(s, n, format, arg); 49 | } 50 | -------------------------------------------------------------------------------- /ios_mcp/source/imports.h: -------------------------------------------------------------------------------- 1 | #ifndef IMPORTS_H 2 | #define IMPORTS_H 3 | 4 | #include 5 | #include 6 | #include "types.h" 7 | 8 | #define MCP_SVC_BASE ((void*)0x050567EC) 9 | 10 | void usleep(u32 time); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /ios_mcp/source/ipc.h: -------------------------------------------------------------------------------- 1 | #ifndef _IPC_H_ 2 | #define _IPC_H_ 3 | 4 | void ipc_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /ios_mcp/source/ipc_types.h: -------------------------------------------------------------------------------- 1 | #ifndef _IPC_TYPES_H_ 2 | #define _IPC_TYPES_H_ 3 | 4 | #include "types.h" 5 | 6 | #define IOS_COMMAND_INVALID 0x00 7 | #define IOS_OPEN 0x01 8 | #define IOS_CLOSE 0x02 9 | #define IOS_READ 0x03 10 | #define IOS_WRITE 0x04 11 | #define IOS_SEEK 0x05 12 | #define IOS_IOCTL 0x06 13 | #define IOS_IOCTLV 0x07 14 | #define IOS_REPLY 0x08 15 | #define IOS_IPC_MSG0 0x09 16 | #define IOS_IPC_MSG1 0x0A 17 | #define IOS_IPC_MSG2 0x0B 18 | #define IOS_SUSPEND 0x0C 19 | #define IOS_RESUME 0x0D 20 | #define IOS_SVCMSG 0x0E 21 | 22 | 23 | /* IPC message */ 24 | typedef struct ipcmessage 25 | { 26 | u32 command; 27 | u32 result; 28 | u32 fd; 29 | u32 flags; 30 | u32 client_cpu; 31 | u32 client_pid; 32 | u64 client_gid; 33 | u32 server_handle; 34 | 35 | union 36 | { 37 | u32 args[5]; 38 | 39 | struct 40 | { 41 | char *device; 42 | u32 mode; 43 | u32 resultfd; 44 | } open; 45 | 46 | struct 47 | { 48 | void *data; 49 | u32 length; 50 | } read, write; 51 | 52 | struct 53 | { 54 | s32 offset; 55 | s32 origin; 56 | } seek; 57 | 58 | struct 59 | { 60 | u32 command; 61 | 62 | u32 *buffer_in; 63 | u32 length_in; 64 | u32 *buffer_io; 65 | u32 length_io; 66 | } ioctl; 67 | struct _ioctlv 68 | { 69 | u32 command; 70 | 71 | u32 num_in; 72 | u32 num_io; 73 | struct _ioctlv *vector; 74 | } ioctlv; 75 | }; 76 | 77 | u32 prev_command; 78 | u32 prev_fd; 79 | u32 virt0; 80 | u32 virt1; 81 | } __attribute__((packed)) ipcmessage; 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /ios_mcp/source/logger.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "types.h" 4 | #include "imports.h" 5 | #include "socket.h" 6 | #include "logger.h" 7 | 8 | #ifdef DEBUG_LOGGER 9 | static int log_socket = 0; 10 | 11 | int log_init(unsigned int ipAddress) 12 | { 13 | log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 14 | if (log_socket < 0) 15 | return log_socket; 16 | 17 | struct sockaddr_in connect_addr; 18 | memset(&connect_addr, 0, sizeof(connect_addr)); 19 | connect_addr.sin_family = AF_INET; 20 | connect_addr.sin_port = 4405; 21 | connect_addr.sin_addr.s_addr = ipAddress; 22 | 23 | if(connect(log_socket, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) 24 | { 25 | closesocket(log_socket); 26 | log_socket = -1; 27 | } 28 | 29 | return log_socket; 30 | } 31 | 32 | void log_deinit() 33 | { 34 | if(log_socket >= 0) 35 | { 36 | closesocket(log_socket); 37 | log_socket = -1; 38 | } 39 | } 40 | 41 | static void log_print(const char *str, int len) 42 | { 43 | int ret; 44 | while (len > 0) { 45 | int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet 46 | ret = send(log_socket, str, block, 0); 47 | if(ret < 0) 48 | break; 49 | 50 | len -= ret; 51 | str += ret; 52 | } 53 | } 54 | 55 | void log_printf(const char *format, ...) 56 | { 57 | if(log_socket < 0) { 58 | return; 59 | } 60 | 61 | va_list args; 62 | va_start(args, format); 63 | 64 | char buffer[0x100]; 65 | 66 | int len = vsnprintf(buffer, sizeof(buffer), format, args); 67 | log_print(buffer, len); 68 | 69 | va_end(args); 70 | } 71 | #endif // DEBUG_LOGGER 72 | -------------------------------------------------------------------------------- /ios_mcp/source/logger.h: -------------------------------------------------------------------------------- 1 | #ifndef __LOGGER_H_ 2 | #define __LOGGER_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | //#define DEBUG_LOGGER 1 9 | 10 | #ifdef DEBUG_LOGGER 11 | int log_init(unsigned int ip); 12 | void log_deinit(); 13 | void log_printf(const char *format, ...); 14 | #else 15 | #define log_init(x) 16 | #define log_deinit() 17 | #define log_printf(x, ...) 18 | #endif 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /ios_mcp/source/net_ifmgr_ncl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "net_ifmgr_ncl.h" 4 | #include "imports.h" 5 | #include "svc.h" 6 | 7 | static int ifmgrncl_handle = 0; 8 | 9 | int ifmgrnclInit() 10 | { 11 | if(ifmgrncl_handle) return ifmgrncl_handle; 12 | 13 | int ret = svcOpen("/dev/net/ifmgr/ncl", 0); 14 | 15 | if(ret > 0) 16 | { 17 | ifmgrncl_handle = ret; 18 | return ifmgrncl_handle; 19 | } 20 | 21 | return ret; 22 | } 23 | 24 | int ifmgrnclExit() 25 | { 26 | int ret = svcClose(ifmgrncl_handle); 27 | 28 | ifmgrncl_handle = 0; 29 | 30 | return ret; 31 | } 32 | 33 | static void* allocIobuf(u32 size) 34 | { 35 | void* ptr = svcAlloc(0xCAFF, size); 36 | 37 | if(ptr) memset(ptr, 0x00, size); 38 | 39 | return ptr; 40 | } 41 | 42 | static void freeIobuf(void* ptr) 43 | { 44 | svcFree(0xCAFF, ptr); 45 | } 46 | 47 | int IFMGRNCL_GetInterfaceStatus(u16 interface_id, u16* out_status) 48 | { 49 | u8* iobuf1 = allocIobuf(0x2); 50 | u16* inbuf = (u16*)iobuf1; 51 | u8* iobuf2 = allocIobuf(0x8); 52 | u16* outbuf = (u16*)iobuf2; 53 | 54 | inbuf[0] = interface_id; 55 | 56 | int ret = svcIoctl(ifmgrncl_handle, 0x14, inbuf, 0x2, outbuf, 0x8); 57 | 58 | if(!ret && out_status) *out_status = outbuf[2]; 59 | 60 | freeIobuf(iobuf1); 61 | freeIobuf(iobuf2); 62 | return ret; 63 | } 64 | -------------------------------------------------------------------------------- /ios_mcp/source/net_ifmgr_ncl.h: -------------------------------------------------------------------------------- 1 | #ifndef NET_IFMGR_NCL 2 | #define NET_IFMGR_NCL 3 | 4 | #include "types.h" 5 | 6 | int ifmgrnclInit(); 7 | int ifmgrnclExit(); 8 | 9 | int IFMGRNCL_GetInterfaceStatus(u16 interface_id, u16* out_status); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /ios_mcp/source/socket.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "socket.h" 5 | #include "svc.h" 6 | #include "text.h" 7 | #include "imports.h" 8 | 9 | static int socket_handle = 0; 10 | 11 | int socketInit() 12 | { 13 | if(socket_handle) return socket_handle; 14 | 15 | int ret = svcOpen("/dev/socket", 0); 16 | 17 | if(ret > 0) 18 | { 19 | socket_handle = ret; 20 | return socket_handle; 21 | } 22 | 23 | return ret; 24 | } 25 | 26 | int socketExit() 27 | { 28 | int ret = svcClose(socket_handle); 29 | 30 | socket_handle = 0; 31 | 32 | return ret; 33 | } 34 | 35 | static void* allocIobuf(u32 size) 36 | { 37 | void* ptr = svcAlloc(0xCAFF, size); 38 | 39 | if(ptr) memset(ptr, 0x00, size); 40 | 41 | return ptr; 42 | } 43 | 44 | static void freeIobuf(void* ptr) 45 | { 46 | svcFree(0xCAFF, ptr); 47 | } 48 | 49 | int socket(int domain, int type, int protocol) 50 | { 51 | u8* iobuf = allocIobuf(0xC); 52 | u32* inbuf = (u32*)iobuf; 53 | 54 | inbuf[0] = domain; 55 | inbuf[1] = type; 56 | inbuf[2] = protocol; 57 | 58 | int ret = svcIoctl(socket_handle, 0x11, inbuf, 0xC, NULL, 0); 59 | 60 | freeIobuf(iobuf); 61 | return ret; 62 | } 63 | 64 | int closesocket(int sockfd) 65 | { 66 | u8* iobuf = allocIobuf(0x4); 67 | u32* inbuf = (u32*)iobuf; 68 | 69 | inbuf[0] = sockfd; 70 | 71 | int ret = svcIoctl(socket_handle, 0x3, inbuf, 0x4, NULL, 0); 72 | 73 | freeIobuf(iobuf); 74 | return ret; 75 | } 76 | 77 | int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) 78 | { 79 | u8* iobuf = allocIobuf(0x18); 80 | u32* inbuf = (u32*)iobuf; 81 | u32* outbuf = (u32*)inbuf; 82 | 83 | inbuf[0] = sockfd; 84 | 85 | int ret = -1; 86 | 87 | if(addr && addrlen && *addrlen == 0x10) 88 | { 89 | inbuf[5] = *addrlen; 90 | 91 | ret = svcIoctl(socket_handle, 0x1, inbuf, 0x18, outbuf, 0x18); 92 | 93 | if(ret >= 0) 94 | { 95 | memcpy(addr, &outbuf[1], outbuf[5]); 96 | *addrlen = outbuf[5]; 97 | } 98 | }else{ 99 | inbuf[5] = 0x10; 100 | 101 | ret = svcIoctl(socket_handle, 0x1, inbuf, 0x18, outbuf, 0x18); 102 | } 103 | 104 | freeIobuf(iobuf); 105 | return ret; 106 | } 107 | 108 | int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) 109 | { 110 | if(addrlen != 0x10) return -1; 111 | 112 | u8* iobuf = allocIobuf(0x18); 113 | u32* inbuf = (u32*)iobuf; 114 | 115 | inbuf[0] = sockfd; 116 | memcpy(&inbuf[1], addr, addrlen); 117 | inbuf[5] = addrlen; 118 | 119 | int ret = svcIoctl(socket_handle, 0x2, inbuf, 0x18, NULL, 0); 120 | 121 | freeIobuf(iobuf); 122 | return ret; 123 | } 124 | 125 | int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) 126 | { 127 | if(addrlen != 0x10) return -1; 128 | 129 | u8* iobuf = allocIobuf(0x18); 130 | u32* inbuf = (u32*)iobuf; 131 | 132 | inbuf[0] = sockfd; 133 | memcpy(&inbuf[1], addr, addrlen); 134 | inbuf[5] = addrlen; 135 | 136 | int ret = svcIoctl(socket_handle, 0x4, inbuf, 0x18, NULL, 0); 137 | 138 | freeIobuf(iobuf); 139 | return ret; 140 | } 141 | 142 | int listen(int sockfd, int backlog) 143 | { 144 | u8* iobuf = allocIobuf(0x8); 145 | u32* inbuf = (u32*)iobuf; 146 | 147 | inbuf[0] = sockfd; 148 | inbuf[1] = backlog; 149 | 150 | int ret = svcIoctl(socket_handle, 0xA, inbuf, 0x8, NULL, 0); 151 | 152 | freeIobuf(iobuf); 153 | return ret; 154 | } 155 | 156 | int recv(int sockfd, void *buf, size_t len, int flags) 157 | { 158 | if(!len) return -101; 159 | 160 | // TODO : size checks, split up data into multiple vectors if necessary 161 | void* data_buf = svcAllocAlign(0xCAFF, len, 0x40); 162 | if(!data_buf) return -100; 163 | 164 | u8* iobuf = allocIobuf(0x38); 165 | iovec_s* iovec = (iovec_s*)iobuf; 166 | u32* inbuf = (u32*)&iobuf[0x30]; 167 | 168 | inbuf[0] = sockfd; 169 | inbuf[1] = flags; 170 | 171 | iovec[0].ptr = inbuf; 172 | iovec[0].len = 0x8; 173 | iovec[1].ptr = (void*)data_buf; 174 | iovec[1].len = len; 175 | 176 | int ret = svcIoctlv(socket_handle, 0xC, 1, 3, iovec); 177 | 178 | if(ret > 0 && buf) 179 | { 180 | memcpy(buf, data_buf, ret); 181 | } 182 | 183 | freeIobuf(data_buf); 184 | freeIobuf(iobuf); 185 | return ret; 186 | } 187 | 188 | int send(int sockfd, const void *buf, size_t len, int flags) 189 | { 190 | if(!buf || !len) return -101; 191 | 192 | // TODO : size checks, split up data into multiple vectors if necessary 193 | void* data_buf = svcAllocAlign(0xCAFF, len, 0x40); 194 | if(!data_buf) return -100; 195 | 196 | u8* iobuf = allocIobuf(0x38); 197 | iovec_s* iovec = (iovec_s*)iobuf; 198 | u32* inbuf = (u32*)&iobuf[0x30]; 199 | 200 | memcpy(data_buf, buf, len); 201 | 202 | inbuf[0] = sockfd; 203 | inbuf[1] = flags; 204 | 205 | iovec[0].ptr = inbuf; 206 | iovec[0].len = 0x8; 207 | iovec[1].ptr = (void*)data_buf; 208 | iovec[1].len = len; 209 | 210 | int ret = svcIoctlv(socket_handle, 0xE, 4, 0, iovec); 211 | 212 | freeIobuf(data_buf); 213 | freeIobuf(iobuf); 214 | return ret; 215 | } 216 | -------------------------------------------------------------------------------- /ios_mcp/source/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef SOCKET_H 2 | #define SOCKET_H 3 | 4 | // slightly stolen from ctrulib 5 | #include 6 | #include 7 | 8 | #define SOL_SOCKET 0xFFFF 9 | 10 | #define PF_UNSPEC 0 11 | #define PF_INET 2 12 | #define PF_INET6 10 13 | 14 | #define AF_UNSPEC PF_UNSPEC 15 | #define AF_INET PF_INET 16 | #define AF_INET6 PF_INET6 17 | 18 | #define SOCK_STREAM 1 19 | #define SOCK_DGRAM 2 20 | 21 | #define MSG_CTRUNC 0x01000000 22 | #define MSG_DONTROUTE 0x02000000 23 | #define MSG_EOR 0x04000000 24 | #define MSG_OOB 0x08000000 25 | #define MSG_PEEK 0x10000000 26 | #define MSG_TRUNC 0x20000000 27 | #define MSG_WAITALL 0x40000000 28 | 29 | #define SHUT_RD 0 30 | #define SHUT_WR 1 31 | #define SHUT_RDWR 2 32 | 33 | #define SO_DEBUG 0x0001 34 | #define SO_ACCEPTCONN 0x0002 35 | #define SO_REUSEADDR 0x0004 36 | #define SO_KEEPALIVE 0x0008 37 | #define SO_DONTROUTE 0x0010 38 | #define SO_BROADCAST 0x0020 39 | #define SO_USELOOPBACK 0x0040 40 | #define SO_LINGER 0x0080 41 | #define SO_OOBINLINE 0x0100 42 | #define SO_REUSEPORT 0x0200 43 | #define SO_SNDBUF 0x1001 44 | #define SO_RCVBUF 0x1002 45 | #define SO_SNDLOWAT 0x1003 46 | #define SO_RCVLOWAT 0x1004 47 | #define SO_SNDTIMEO 0x1005 48 | #define SO_RCVTIMEO 0x1006 49 | #define SO_ERROR 0x1007 50 | #define SO_TYPE 0x1008 51 | 52 | #define INADDR_ANY 0x00000000 53 | #define INADDR_BROADCAST 0xFFFFFFFF 54 | #define INADDR_NONE 0xFFFFFFFF 55 | 56 | #define INET_ADDRSTRLEN 16 57 | 58 | #define INADDR_LOOPBACK 0x7f000001 59 | #define INADDR_ANY 0x00000000 60 | #define INADDR_BROADCAST 0xFFFFFFFF 61 | #define INADDR_NONE 0xFFFFFFFF 62 | 63 | #define INET_ADDRSTRLEN 16 64 | 65 | #define IPPROTO_IP 0 /* dummy for IP */ 66 | #define IPPROTO_UDP 17 /* user datagram protocol */ 67 | #define IPPROTO_TCP 6 /* tcp */ 68 | 69 | #define IP_TOS 7 70 | #define IP_TTL 8 71 | #define IP_MULTICAST_LOOP 9 72 | #define IP_MULTICAST_TTL 10 73 | #define IP_ADD_MEMBERSHIP 11 74 | #define IP_DROP_MEMBERSHIP 12 75 | 76 | typedef uint32_t socklen_t; 77 | typedef uint16_t sa_family_t; 78 | 79 | struct sockaddr 80 | { 81 | sa_family_t sa_family; 82 | char sa_data[]; 83 | }; 84 | 85 | struct sockaddr_storage 86 | { 87 | sa_family_t ss_family; 88 | char __ss_padding[14]; 89 | }; 90 | 91 | typedef uint16_t in_port_t; 92 | typedef uint32_t in_addr_t; 93 | 94 | struct in_addr { 95 | in_addr_t s_addr; 96 | }; 97 | 98 | struct sockaddr_in { 99 | sa_family_t sin_family; 100 | in_port_t sin_port; 101 | struct in_addr sin_addr; 102 | unsigned char sin_zero[8]; 103 | }; 104 | 105 | struct linger 106 | { 107 | int l_onoff; 108 | int l_linger; 109 | }; 110 | 111 | int socketInit(); 112 | int socketExit(); 113 | 114 | int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); 115 | int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); 116 | int closesocket(int sockfd); 117 | int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); 118 | int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen); 119 | int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen); 120 | int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); 121 | int listen(int sockfd, int backlog); 122 | ssize_t recv(int sockfd, void *buf, size_t len, int flags); 123 | ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); 124 | ssize_t send(int sockfd, const void *buf, size_t len, int flags); 125 | ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); 126 | int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); 127 | int shutdown(int sockfd, int how); 128 | int socket(int domain, int type, int protocol); 129 | int sockatmark(int sockfd); 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /ios_mcp/source/svc.h: -------------------------------------------------------------------------------- 1 | #ifndef SVC_H 2 | #define SVC_H 3 | 4 | #include "ipc_types.h" 5 | 6 | typedef struct 7 | { 8 | void* ptr; 9 | u32 len; 10 | u32 unk; 11 | }iovec_s; 12 | 13 | void* svcAlloc(u32 heapid, u32 size); 14 | void* svcAllocAlign(u32 heapid, u32 size, u32 align); 15 | void svcFree(u32 heapid, void* ptr); 16 | int svcOpen(char* name, int mode); 17 | int svcClose(int fd); 18 | int svcIoctl(int fd, u32 request, void* input_buffer, u32 input_buffer_len, void* output_buffer, u32 output_buffer_len); 19 | int svcIoctlv(int fd, u32 request, u32 vector_count_in, u32 vector_count_out, iovec_s* vector); 20 | int svcInvalidateDCache(void* address, u32 size); 21 | int svcFlushDCache(void* address, u32 size); 22 | 23 | int svcCreateThread(int (*callback)(void* arg), void* arg, u32* stack_top, u32 stacksize, int priority, int detached); 24 | int svcStartThread(int threadId); 25 | int svcCreateMessageQueue(u32 *ptr, u32 n_msgs); 26 | int svcRegisterResourceManager(const char* device, int queueid); 27 | int svcReceiveMessage(int queueid, ipcmessage ** ipc_buf, u32 flags); 28 | int svcResourceReply(ipcmessage * ipc_message, u32 result); 29 | u32 svcRead32(u32 addr); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ios_mcp/source/svc.s: -------------------------------------------------------------------------------- 1 | .section ".text" 2 | .arm 3 | .align 4 4 | 5 | .global svcCreateThread 6 | .type svcCreateThread, %function 7 | svcCreateThread: 8 | .word 0xE7F000F0 9 | bx lr 10 | 11 | .global svcStartThread 12 | .type svcStartThread, %function 13 | svcStartThread: 14 | .word 0xE7F007F0 15 | bx lr 16 | 17 | .global svcCreateMessageQueue 18 | .type svcCreateMessageQueue, %function 19 | svcCreateMessageQueue: 20 | .word 0xE7F00CF0 21 | bx lr 22 | 23 | .global svcReceiveMessage 24 | .type svcReceiveMessage, %function 25 | svcReceiveMessage: 26 | .word 0xE7F010F0 27 | bx lr 28 | 29 | .global svcAlloc 30 | .type svcAlloc, %function 31 | svcAlloc: 32 | .word 0xE7F027F0 33 | bx lr 34 | 35 | .global svcAllocAlign 36 | .type svcAllocAlign, %function 37 | svcAllocAlign: 38 | .word 0xE7F028F0 39 | bx lr 40 | 41 | .global svcFree 42 | .type svcFree, %function 43 | svcFree: 44 | .word 0xE7F029F0 45 | bx lr 46 | 47 | .global svcRegisterResourceManager 48 | .type svcRegisterResourceManager, %function 49 | svcRegisterResourceManager: 50 | .word 0xE7F02CF0 51 | bx lr 52 | 53 | .global svcOpen 54 | .type svcOpen, %function 55 | svcOpen: 56 | .word 0xE7F033F0 57 | bx lr 58 | 59 | .global svcClose 60 | .type svcClose, %function 61 | svcClose: 62 | .word 0xE7F034F0 63 | bx lr 64 | 65 | .global svcIoctl 66 | .type svcIoctl, %function 67 | svcIoctl: 68 | .word 0xE7F038F0 69 | bx lr 70 | 71 | .global svcIoctlv 72 | .type svcIoctlv, %function 73 | svcIoctlv: 74 | .word 0xE7F039F0 75 | bx lr 76 | 77 | .global svcResourceReply 78 | .type svcResourceReply, %function 79 | svcResourceReply: 80 | .word 0xE7F049F0 81 | bx lr 82 | 83 | .global svcInvalidateDCache 84 | .type svcInvalidateDCache, %function 85 | svcInvalidateDCache: 86 | .word 0xE7F051F0 87 | bx lr 88 | 89 | .global svcFlushDCache 90 | .type svcFlushDCache, %function 91 | svcFlushDCache: 92 | .word 0xE7F052F0 93 | bx lr 94 | 95 | .global svcRead32 96 | .type svcRead32, %function 97 | svcRead32: 98 | .word 0xE7F081F0 99 | bx lr 100 | -------------------------------------------------------------------------------- /ios_mcp/source/text.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "imports.h" 5 | #include "font_bin.h" 6 | 7 | #define FRAMEBUFFER_ADDRESS (0x14000000+0x38C0000) 8 | #define FRAMEBUFFER_STRIDE (0xE00) 9 | #define FRAMEBUFFER_STRIDE_WORDS (FRAMEBUFFER_STRIDE >> 2) 10 | 11 | #define CHAR_SIZE_X (8) 12 | #define CHAR_SIZE_Y (8) 13 | 14 | static const u8 *launch_image_tga = (const u8*)0x27000000; 15 | 16 | u32* const framebuffer = (u32*)FRAMEBUFFER_ADDRESS; 17 | 18 | void drawSplashScreen(void) 19 | { 20 | // check if it is an unmapped RGB tga 21 | if(*(u32*)launch_image_tga != 0x00000200) 22 | return; 23 | 24 | int i; 25 | for(i = 0; i < (896 * 504); i++) 26 | { 27 | u32 pixel; 28 | u32 pixelOffset = 0x12 + i * 2; 29 | // access only 4 byte aligned data as the file is in code section 30 | u32 dualPixel = *(u32*)(launch_image_tga + (pixelOffset & ~3)); 31 | 32 | if((pixelOffset & 3) == 0) 33 | { 34 | pixel = ((dualPixel >> 24) & 0xFF) | (((dualPixel >> 16) & 0xFF) << 8); 35 | } 36 | else 37 | { 38 | pixel = ((dualPixel >> 8) & 0xFF) | ((dualPixel & 0xFF) << 8); 39 | } 40 | 41 | framebuffer[i] = (((pixel >> 10) & 0x1F) << (3 + 24)) | (((pixel >> 5) & 0x1F) << (3 + 16)) | ((pixel & 0x1F) << (3 + 8)) | 0xFF; 42 | } 43 | } 44 | 45 | void clearScreen(u32 color) 46 | { 47 | int i; 48 | for(i = 0; i < 896 * 504; i++) 49 | { 50 | framebuffer[i] = color; 51 | } 52 | } 53 | 54 | void drawCharacter(char c, int x, int y) 55 | { 56 | if(c < 32)return; 57 | c -= 32; 58 | u8* charData = (u8*)&font_bin[(CHAR_SIZE_X * CHAR_SIZE_Y * c) / 8]; 59 | u32* fb = &framebuffer[x + y * FRAMEBUFFER_STRIDE_WORDS]; 60 | int i, j; 61 | for(i = 0; i < CHAR_SIZE_Y; i++) 62 | { 63 | u8 v= *(charData++); 64 | for(j = 0; j < CHAR_SIZE_X; j++) 65 | { 66 | if(v & 1) *fb = 0x00000000; 67 | else *fb = 0xFFFFFFFF; 68 | v >>= 1; 69 | fb++; 70 | } 71 | fb += FRAMEBUFFER_STRIDE_WORDS - CHAR_SIZE_X; 72 | } 73 | } 74 | 75 | void drawString(char* str, int x, int y) 76 | { 77 | if(!str) return; 78 | int k; 79 | int dx = 0, dy = 0; 80 | for(k = 0; str[k]; k++) 81 | { 82 | if(str[k] >= 32 && str[k] < 128) drawCharacter(str[k], x + dx, y + dy); 83 | 84 | dx += 8; 85 | 86 | if(str[k] == '\n') 87 | { 88 | dx = 0; 89 | dy -= 8; 90 | } 91 | } 92 | } 93 | 94 | void print(int x, int y, const char *format, ...) 95 | { 96 | va_list args; 97 | va_start(args, format); 98 | 99 | static char buffer[0x100]; 100 | 101 | vsnprintf(buffer, 0xFF, format, args); 102 | drawString(buffer, x, y); 103 | 104 | va_end(args); 105 | } 106 | -------------------------------------------------------------------------------- /ios_mcp/source/text.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXT_H 2 | #define TEXT_H 3 | 4 | #include "types.h" 5 | 6 | void drawSplashScreen(void); 7 | void clearScreen(u32 color); 8 | void drawString(char* str, int x, int y); 9 | void print(int x, int y, const char *format, ...); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /ios_mcp/source/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPES_H 2 | #define TYPES_H 3 | 4 | #include 5 | #include 6 | 7 | #define U64_MAX UINT64_MAX 8 | 9 | typedef uint8_t u8; 10 | typedef uint16_t u16; 11 | typedef uint32_t u32; 12 | typedef uint64_t u64; 13 | 14 | typedef int8_t s8; 15 | typedef int16_t s16; 16 | typedef int32_t s32; 17 | typedef int64_t s64; 18 | 19 | typedef volatile u8 vu8; 20 | typedef volatile u16 vu16; 21 | typedef volatile u32 vu32; 22 | typedef volatile u64 vu64; 23 | 24 | typedef volatile s8 vs8; 25 | typedef volatile s16 vs16; 26 | typedef volatile s32 vs32; 27 | typedef volatile s64 vs64; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ios_usb/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(strip $(DEVKITARM)),) 2 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 3 | endif 4 | 5 | ifeq ($(filter $(DEVKITARM)/bin,$(PATH)),) 6 | export PATH:=$(DEVKITARM)/bin:$(PATH) 7 | endif 8 | 9 | CC = arm-none-eabi-gcc 10 | LINK = arm-none-eabi-gcc 11 | AS = arm-none-eabi-as 12 | OBJCOPY = arm-none-eabi-objcopy 13 | OBJDUMP = arm-none-eabi-objdump 14 | CFLAGS += -Wall -mbig-endian -std=gnu11 -mcpu=arm926ej-s -msoft-float -mfloat-abi=soft -Os 15 | LDFLAGS += -nostartfiles -nodefaultlibs -mbig-endian -Wl,-T,link.ld 16 | LIBDIRS += -L$(CURDIR)/../libs 17 | LIBS += -lgcc 18 | 19 | CFILES = $(wildcard source/*.c) 20 | BINFILES = $(wildcard data/*.bin) 21 | OFILES = $(BINFILES:data/%.bin=build/%.bin.o) 22 | OFILES += $(CFILES:source/%.c=build/%.o) 23 | DFILES = $(CFILES:source/%.c=build/%.d) 24 | SFILES = $(wildcard source/*.s) 25 | OFILES += $(SFILES:source/%.s=build/%.o) 26 | PROJECTNAME = ${shell basename "$(CURDIR)"} 27 | CWD = "$(CURDIR)"" 28 | 29 | #--------------------------------------------------------------------------------- 30 | # canned command sequence for binary data, taken from devkitARM 31 | #--------------------------------------------------------------------------------- 32 | define bin2o 33 | bin2s $< | $(AS) -EB -o $(@) 34 | endef 35 | 36 | .PHONY:=all dirs 37 | 38 | all: dirs $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 39 | 40 | dirs: 41 | @mkdir -p build 42 | 43 | $(PROJECTNAME).elf: $(OFILES) 44 | @echo "LD $@" 45 | @$(LINK) $(LDFLAGS) -o $(PROJECTNAME).elf $(sort $(filter-out build/crt0.o, $(OFILES))) $(LIBDIRS) $(LIBS) 46 | 47 | $(PROJECTNAME).bin: $(PROJECTNAME).elf 48 | @echo "OBJCOPY $@\n" 49 | @$(OBJCOPY) -j .text -j .rodata -j .data -O binary $(PROJECTNAME).elf $@ 50 | 51 | $(PROJECTNAME).bin.h: $(PROJECTNAME).bin 52 | @xxd -i $< | sed "s/unsigned/static const unsigned/g;s/$(PROJECTNAME)$*/$(PROJECTNAME)/g" > $@ 53 | 54 | $(PROJECTNAME)_syms.h: 55 | @echo "#ifndef $(PROJECTNAME)_SYMS_H" > $@ 56 | @echo "#define $(PROJECTNAME)_SYMS_H" >> $@ 57 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep 'g F .text' | grep -v '.hidden' | awk '{print "#define " $$6 " 0x" $$1}' >> $@ 58 | @$(OBJDUMP) -EB -t -marm $(PROJECTNAME).elf | grep -e 'g .text' -e '_bss_' | awk '{print "#define " $$5 " 0x" $$1}' >> $@ 59 | @echo "#endif" >> $@ 60 | 61 | clean: 62 | @rm -f build/*.o build/*.d 63 | @rm -f $(PROJECTNAME).elf $(PROJECTNAME).bin $(PROJECTNAME)_syms.h $(PROJECTNAME).bin $(PROJECTNAME).bin.h 64 | @echo "all cleaned up !" 65 | 66 | -include $(DFILES) 67 | 68 | build/%.o: source/%.c 69 | @echo "CC $(notdir $<)" 70 | @$(CC) $(CFLAGS) -c $< -o $@ 71 | @$(CC) -MM $< > build/$*.d 72 | 73 | build/%.o: source/%.s 74 | @echo "CC $(notdir $<)" 75 | @$(CC) $(CFLAGS) -xassembler-with-cpp -c $< -o $@ 76 | @$(CC) -MM $< > build/$*.d 77 | 78 | build/%.bin.o: data/%.bin 79 | @echo "BIN $(notdir $<)" 80 | @$(bin2o) 81 | -------------------------------------------------------------------------------- /ios_usb/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(arm) 2 | 3 | SECTIONS 4 | { 5 | .text 0x101312D0 : { 6 | _text_start = .; 7 | build/crt0.o(.init) 8 | *(.text*); 9 | *(.rodata*); 10 | } 11 | _text_end = .; 12 | 13 | /DISCARD/ : { 14 | *(*); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /ios_usb/source/crt0.s: -------------------------------------------------------------------------------- 1 | .section ".init" 2 | .arm 3 | .align 4 4 | 5 | .extern _main 6 | .type _main, %function 7 | 8 | _start: 9 | b _main 10 | -------------------------------------------------------------------------------- /ios_usb/source/main.c: -------------------------------------------------------------------------------- 1 | void _main() 2 | { 3 | 4 | void(*ios_shutdown)(int) = (void(*)(int))0x1012EE4C; 5 | 6 | int(*reply)(int, int) = (int(*)(int, int))0x1012ED04; 7 | 8 | int saved_handle = *(volatile int*)0x0012F000; 9 | int myret = reply(saved_handle, 0); 10 | if (myret != 0) 11 | ios_shutdown(1); 12 | 13 | // stack pointer will be 0x1016AE30 14 | // link register will be 0x1012EACC 15 | asm("LDR SP, newsp\n" 16 | "LDR R0, newr0\n" 17 | "LDR LR, newlr\n" 18 | "LDR PC, newpc\n" 19 | "newsp: .word 0x1016AE30\n" 20 | "newlr: .word 0x1012EACC\n" 21 | "newr0: .word 0x10146080\n" 22 | "newpc: .word 0x10111164\n"); 23 | 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /libs/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koolkdev/wiiu-nanddumper/70e8eed02045d9c7a87c8018f4c005896c83ae47/libs/libc.a -------------------------------------------------------------------------------- /libs/libgcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koolkdev/wiiu-nanddumper/70e8eed02045d9c7a87c8018f4c005896c83ae47/libs/libgcc.a -------------------------------------------------------------------------------- /src/cfw_config.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "cfw_config.h" 31 | #include "fs/fs_utils.h" 32 | 33 | static int split_string(const char *string, char splitChar, char *left, char *right, int size) 34 | { 35 | int cnt = 0; 36 | char *writePtr = left; 37 | 38 | while(*string != '\0' && *string != '\n' && *string != '\r' && *string != splitChar && (cnt+1) < size) 39 | { 40 | *writePtr++ = *string++; 41 | cnt++; 42 | } 43 | 44 | *writePtr = 0; 45 | *right = 0; 46 | 47 | writePtr--; 48 | 49 | // remove trailing spaces 50 | while(writePtr > left && *writePtr == ' ') 51 | *writePtr-- = 0; 52 | 53 | if(*string == splitChar) 54 | { 55 | string++; 56 | writePtr = right; 57 | 58 | // skip spaces after split character 59 | while(*string == ' ') 60 | string++; 61 | 62 | cnt = 0; 63 | while(*string != '\0' && *string != '\n' && *string != '\r' && (cnt+1) < size) 64 | { 65 | *writePtr++ = *string++; 66 | } 67 | *writePtr = 0; 68 | return 1; 69 | } 70 | else 71 | { 72 | return -1; 73 | } 74 | } 75 | 76 | void default_config(cfw_config_t * config) 77 | { 78 | memset(config, 0, sizeof(cfw_config_t)); 79 | //config->viewMode = 0; 80 | //config->directLaunch = 0; 81 | //config->launchImage = 1; 82 | //config->noIosReload = 0; 83 | //config->launchSysMenu = 1; 84 | //config->redNAND = 0; 85 | //config->seeprom_red = 0; 86 | //config->otp_red = 0; 87 | //config->syshaxXml = 0; 88 | config->dumpSlc = 1; 89 | config->dumpSlccmpt = 1; 90 | config->dumpMlc = 0; 91 | config->dumpOtp = 1; 92 | config->dumpSeeprom = 1; 93 | } 94 | 95 | /*int read_config(cfw_config_t * config) 96 | { 97 | FILE *pFile = fopen(CONFIG_PATH, "rb"); 98 | if(!pFile) 99 | return -1; 100 | 101 | char option[64]; 102 | char value[64]; 103 | char line[0x100]; 104 | 105 | while(fgets(line, sizeof(line), pFile) != 0) 106 | { 107 | if(line[0] == '#' || line[0] == '[') 108 | continue; 109 | 110 | if(split_string(line, '=', option, value, sizeof(option)) == 1) 111 | { 112 | if(strcmp(option, "directLaunch") == 0) 113 | config->directLaunch = atoi(value); 114 | else if(strcmp(option, "launchImage") == 0) 115 | config->launchImage = atoi(value); 116 | else if(strcmp(option, "redNAND") == 0) 117 | config->redNAND = atoi(value); 118 | else if(strcmp(option, "seeprom_red") == 0) 119 | config->seeprom_red = atoi(value); 120 | else if(strcmp(option, "otp_red") == 0) 121 | config->otp_red = atoi(value); 122 | else if(strcmp(option, "syshaxXml") == 0) 123 | config->syshaxXml = atoi(value); 124 | else if(strcmp(option, "viewMode") == 0) 125 | config->viewMode = atoi(value); 126 | else if(strcmp(option, "noIosReload") == 0) 127 | config->noIosReload = atoi(value); 128 | else if(strcmp(option, "launchSysMenu") == 0) 129 | config->launchSysMenu = atoi(value); 130 | } 131 | } 132 | 133 | fclose(pFile); 134 | return 0; 135 | }*/ 136 | 137 | /*int write_config(cfw_config_t * config) 138 | { 139 | CreateSubfolder(APP_PATH); 140 | 141 | FILE *pFile = fopen(CONFIG_PATH, "wb"); 142 | if(!pFile) 143 | return -1; 144 | 145 | fprintf(pFile, "[MOCHA]\n"); 146 | fprintf(pFile, "viewMode=%i\n", config->viewMode); 147 | fprintf(pFile, "directLaunch=%i\n", config->directLaunch); 148 | fprintf(pFile, "launchImage=%i\n", config->launchImage); 149 | fprintf(pFile, "noIosReload=%i\n", config->noIosReload); 150 | fprintf(pFile, "launchSysMenu=%i\n", config->launchSysMenu); 151 | fprintf(pFile, "redNAND=%i\n", config->redNAND); 152 | fprintf(pFile, "seeprom_red=%i\n", config->seeprom_red); 153 | fprintf(pFile, "otp_red=%i\n", config->otp_red); 154 | fprintf(pFile, "syshaxXml=%i\n", config->syshaxXml); 155 | fclose(pFile); 156 | return 0; 157 | }*/ 158 | -------------------------------------------------------------------------------- /src/cfw_config.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef CFW_CONFIG_H_ 25 | #define CFW_CONFIG_H_ 26 | 27 | //#define APP_VERSION "v0.2" 28 | //#define APP_PATH "sd:/wiiu/apps/mocha" 29 | //#define CONFIG_PATH (APP_PATH "/config.ini") 30 | 31 | typedef struct 32 | { 33 | //int viewMode; 34 | //int directLaunch; 35 | //int launchImage; 36 | //int noIosReload; 37 | //int launchSysMenu; 38 | //int redNAND; 39 | //int seeprom_red; 40 | //int otp_red; 41 | //int syshaxXml; 42 | int dumpSlc; 43 | int dumpSlccmpt; 44 | int dumpMlc; 45 | int dumpOtp; 46 | int dumpSeeprom; 47 | } cfw_config_t; 48 | 49 | void default_config(cfw_config_t * config); 50 | //int read_config(cfw_config_t * config); 51 | //int write_config(cfw_config_t * config); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/common/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "os_defs.h" 9 | 10 | #define CAFE_OS_SD_PATH "/vol/external01" 11 | #define SD_PATH "sd:" 12 | #define WIIU_PATH "/wiiu" 13 | 14 | #ifndef MEM_BASE 15 | #define MEM_BASE (0x00800000) 16 | #endif 17 | 18 | #define ELF_DATA_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x00)) 19 | #define ELF_DATA_SIZE (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x04)) 20 | #define MAIN_ENTRY_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1400 + 0x00)) 21 | #define OS_FIRMWARE (*(volatile unsigned int*)(MEM_BASE + 0x1400 + 0x04)) 22 | 23 | #define OS_SPECIFICS ((OsSpecifics*)(MEM_BASE + 0x1500)) 24 | 25 | #ifndef EXIT_SUCCESS 26 | #define EXIT_SUCCESS 0 27 | #endif 28 | #define EXIT_HBL_EXIT 0xFFFFFFFE 29 | #define EXIT_RELAUNCH_ON_LOAD 0xFFFFFFFD 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* COMMON_H */ 36 | 37 | -------------------------------------------------------------------------------- /src/common/fs_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef FS_DEFS_H 2 | #define FS_DEFS_H 3 | 4 | #include "types.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | 11 | /* FS defines and types */ 12 | #define FS_MAX_LOCALPATH_SIZE 511 13 | #define FS_MAX_MOUNTPATH_SIZE 128 14 | #define FS_MAX_FULLPATH_SIZE (FS_MAX_LOCALPATH_SIZE + FS_MAX_MOUNTPATH_SIZE) 15 | #define FS_MAX_ARGPATH_SIZE FS_MAX_FULLPATH_SIZE 16 | 17 | #define FS_STATUS_OK 0 18 | #define FS_RET_UNSUPPORTED_CMD 0x0400 19 | #define FS_RET_NO_ERROR 0x0000 20 | #define FS_RET_ALL_ERROR (unsigned int)(-1) 21 | 22 | #define FS_STAT_FLAG_IS_DIRECTORY 0x80000000 23 | 24 | /* max length of file/dir name */ 25 | #define FS_MAX_ENTNAME_SIZE 256 26 | 27 | #define FS_SOURCETYPE_EXTERNAL 0 28 | #define FS_SOURCETYPE_HFIO 1 29 | #define FS_SOURCETYPE_HFIO 1 30 | 31 | #define FS_MOUNT_SOURCE_SIZE 0x300 32 | #define FS_CLIENT_SIZE 0x1700 33 | #define FS_CMD_BLOCK_SIZE 0xA80 34 | 35 | typedef struct 36 | { 37 | uint32_t flag; 38 | uint32_t permission; 39 | uint32_t owner_id; 40 | uint32_t group_id; 41 | uint32_t size; 42 | uint32_t alloc_size; 43 | uint64_t quota_size; 44 | uint32_t ent_id; 45 | uint64_t ctime; 46 | uint64_t mtime; 47 | uint8_t attributes[48]; 48 | } __attribute__((packed)) FSStat; 49 | 50 | typedef struct 51 | { 52 | FSStat stat; 53 | char name[FS_MAX_ENTNAME_SIZE]; 54 | } FSDirEntry; 55 | 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* FS_DEFS_H */ 62 | 63 | -------------------------------------------------------------------------------- /src/common/os_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef __OS_DEFS_H_ 2 | #define __OS_DEFS_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef struct _OsSpecifics 9 | { 10 | unsigned int addr_OSDynLoad_Acquire; 11 | unsigned int addr_OSDynLoad_FindExport; 12 | unsigned int addr_OSTitle_main_entry; 13 | 14 | unsigned int addr_KernSyscallTbl1; 15 | unsigned int addr_KernSyscallTbl2; 16 | unsigned int addr_KernSyscallTbl3; 17 | unsigned int addr_KernSyscallTbl4; 18 | unsigned int addr_KernSyscallTbl5; 19 | } OsSpecifics; 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif // __OS_DEFS_H_ 26 | -------------------------------------------------------------------------------- /src/common/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPES_H 2 | #define TYPES_H 3 | 4 | #include 5 | 6 | #endif /* TYPES_H */ 7 | 8 | -------------------------------------------------------------------------------- /src/dynamic_libs/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /src/dynamic_libs/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /src/dynamic_libs/README.md: -------------------------------------------------------------------------------- 1 | # dynamic_libs 2 | Dynamic libs for WiiU homebrew 3 | -------------------------------------------------------------------------------- /src/dynamic_libs/fs_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef FS_DEFS_H 2 | #define FS_DEFS_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | 11 | /* FS defines and types */ 12 | #define FS_MAX_LOCALPATH_SIZE 511 13 | #define FS_MAX_MOUNTPATH_SIZE 128 14 | #define FS_MAX_FULLPATH_SIZE (FS_MAX_LOCALPATH_SIZE + FS_MAX_MOUNTPATH_SIZE) 15 | #define FS_MAX_ARGPATH_SIZE FS_MAX_FULLPATH_SIZE 16 | 17 | #define FS_STATUS_OK 0 18 | #define FS_RET_UNSUPPORTED_CMD 0x0400 19 | #define FS_RET_NO_ERROR 0x0000 20 | #define FS_RET_ALL_ERROR (unsigned int)(-1) 21 | 22 | #define FS_STAT_FLAG_IS_DIRECTORY 0x80000000 23 | 24 | /* max length of file/dir name */ 25 | #define FS_MAX_ENTNAME_SIZE 256 26 | 27 | #define FS_SOURCETYPE_EXTERNAL 0 28 | #define FS_SOURCETYPE_HFIO 1 29 | 30 | #define FS_MOUNT_SOURCE_SIZE 0x300 31 | #define FS_CLIENT_SIZE 0x1700 32 | #define FS_CMD_BLOCK_SIZE 0xA80 33 | 34 | typedef struct 35 | { 36 | uint32_t flag; 37 | uint32_t permission; 38 | uint32_t owner_id; 39 | uint32_t group_id; 40 | uint32_t size; 41 | uint32_t alloc_size; 42 | uint64_t quota_size; 43 | uint32_t ent_id; 44 | uint64_t ctime; 45 | uint64_t mtime; 46 | uint8_t attributes[48]; 47 | } __attribute__((packed)) FSStat; 48 | 49 | typedef struct 50 | { 51 | FSStat stat; 52 | char name[FS_MAX_ENTNAME_SIZE]; 53 | } FSDirEntry; 54 | 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* FS_DEFS_H */ 61 | 62 | -------------------------------------------------------------------------------- /src/dynamic_libs/os_types.h: -------------------------------------------------------------------------------- 1 | #ifndef _OS_TYPES_H_ 2 | #define _OS_TYPES_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | typedef struct _OSCalendarTime { 11 | int sec; 12 | int min; 13 | int hour; 14 | int mday; 15 | int mon; 16 | int year; 17 | int wday; 18 | int yday; 19 | int msec; 20 | int usec; 21 | } OSCalendarTime; 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/dynamic_libs/socket_functions.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "os_functions.h" 25 | #include "socket_functions.h" 26 | 27 | u32 hostIpAddress = 0; 28 | 29 | unsigned int nsysnet_handle __attribute__((section(".data"))) = 0; 30 | 31 | EXPORT_DECL(void, socket_lib_init, void); 32 | EXPORT_DECL(int, socket, int domain, int type, int protocol); 33 | EXPORT_DECL(int, socketclose, int s); 34 | EXPORT_DECL(int, connect, int s, void *addr, int addrlen); 35 | EXPORT_DECL(int, bind, s32 s,struct sockaddr *name,s32 namelen); 36 | EXPORT_DECL(int, listen, s32 s,u32 backlog); 37 | EXPORT_DECL(int, accept, s32 s,struct sockaddr *addr,s32 *addrlen); 38 | EXPORT_DECL(int, send, int s, const void *buffer, int size, int flags); 39 | EXPORT_DECL(int, recv, int s, void *buffer, int size, int flags); 40 | EXPORT_DECL(int, recvfrom,int sockfd, void *buf, int len, int flags,struct sockaddr *src_addr, int *addrlen); 41 | EXPORT_DECL(int, sendto, int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len); 42 | EXPORT_DECL(int, setsockopt, int s, int level, int optname, void *optval, int optlen); 43 | EXPORT_DECL(char *, inet_ntoa, struct in_addr in); 44 | EXPORT_DECL(int, inet_aton, const char *cp, struct in_addr *inp); 45 | 46 | EXPORT_DECL(int, NSSLWrite, int connection, const void* buf, int len,int * written); 47 | EXPORT_DECL(int, NSSLRead, int connection, const void* buf, int len,int * read); 48 | EXPORT_DECL(int, NSSLCreateConnection, int context, const char* host, int hotlen,int options,int sock,int block); 49 | 50 | void InitAcquireSocket(void) 51 | { 52 | OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle); 53 | } 54 | 55 | void InitSocketFunctionPointers(void) 56 | { 57 | unsigned int *funcPointer = 0; 58 | 59 | InitAcquireSocket(); 60 | 61 | OS_FIND_EXPORT(nsysnet_handle, socket_lib_init); 62 | OS_FIND_EXPORT(nsysnet_handle, socket); 63 | OS_FIND_EXPORT(nsysnet_handle, socketclose); 64 | OS_FIND_EXPORT(nsysnet_handle, connect); 65 | OS_FIND_EXPORT(nsysnet_handle, bind); 66 | OS_FIND_EXPORT(nsysnet_handle, listen); 67 | OS_FIND_EXPORT(nsysnet_handle, accept); 68 | OS_FIND_EXPORT(nsysnet_handle, send); 69 | OS_FIND_EXPORT(nsysnet_handle, recv); 70 | OS_FIND_EXPORT(nsysnet_handle, recvfrom); 71 | OS_FIND_EXPORT(nsysnet_handle, sendto); 72 | OS_FIND_EXPORT(nsysnet_handle, setsockopt); 73 | OS_FIND_EXPORT(nsysnet_handle, inet_ntoa); 74 | OS_FIND_EXPORT(nsysnet_handle, inet_aton); 75 | 76 | OS_FIND_EXPORT(nsysnet_handle, NSSLWrite); 77 | OS_FIND_EXPORT(nsysnet_handle, NSSLRead); 78 | OS_FIND_EXPORT(nsysnet_handle, NSSLCreateConnection); 79 | 80 | socket_lib_init(); 81 | } 82 | -------------------------------------------------------------------------------- /src/dynamic_libs/socket_functions.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __SOCKET_FUNCTIONS_H_ 25 | #define __SOCKET_FUNCTIONS_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | extern unsigned int nsysnet_handle; 32 | 33 | #include 34 | 35 | #define INADDR_ANY 0 36 | 37 | #define AF_INET 2 38 | 39 | #define SOCK_STREAM 1 40 | #define SOCK_DGRAM 2 41 | 42 | #define IPPROTO_IP 0 43 | #define IPPROTO_TCP 6 44 | #define IPPROTO_UDP 17 45 | 46 | #define TCP_NODELAY 0x2004 47 | 48 | #define SOL_SOCKET -1 49 | #define SO_REUSEADDR 0x0004 50 | #define SO_NONBLOCK 0x1016 51 | #define SO_MYADDR 0x1013 52 | #define SO_RCVTIMEO 0x1006 53 | 54 | #define SOL_SOCKET -1 55 | #define MSG_DONTWAIT 32 56 | 57 | #define htonl(x) x 58 | #define htons(x) x 59 | #define ntohl(x) x 60 | #define ntohs(x) x 61 | 62 | 63 | struct in_addr { 64 | unsigned int s_addr; 65 | }; 66 | struct sockaddr_in { 67 | short sin_family; 68 | unsigned short sin_port; 69 | struct in_addr sin_addr; 70 | char sin_zero[8]; 71 | }; 72 | 73 | struct sockaddr 74 | { 75 | unsigned short sa_family; 76 | char sa_data[14]; 77 | }; 78 | 79 | 80 | void InitSocketFunctionPointers(void); 81 | void InitAcquireSocket(void); 82 | 83 | extern void (*socket_lib_init)(void); 84 | extern int (*socket)(int domain, int type, int protocol); 85 | extern int (*socketclose)(int s); 86 | extern int (*connect)(int s, void *addr, int addrlen); 87 | extern int (*bind)(s32 s,struct sockaddr *name,s32 namelen); 88 | extern int (*listen)(s32 s,u32 backlog); 89 | extern int (*accept)(s32 s,struct sockaddr *addr,s32 *addrlen); 90 | extern int (*send)(int s, const void *buffer, int size, int flags); 91 | extern int (*recv)(int s, void *buffer, int size, int flags); 92 | extern int (*recvfrom)(int sockfd, void *buf, int len, int flags,struct sockaddr *src_addr, int *addrlen); 93 | 94 | extern int (*sendto)(int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len); 95 | extern int (*setsockopt)(int s, int level, int optname, void *optval, int optlen); 96 | 97 | extern int (* NSSLWrite)(int connection, const void* buf, int len,int * written); 98 | extern int (* NSSLRead)(int connection, const void* buf, int len,int * read); 99 | extern int (* NSSLCreateConnection)(int context, const char* host, int hotlen,int options,int sock,int block); 100 | 101 | extern char * (*inet_ntoa)(struct in_addr in); 102 | extern int (*inet_aton)(const char *cp, struct in_addr *inp); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif // __SOCKET_FUNCTIONS_H_ 109 | -------------------------------------------------------------------------------- /src/dynamic_libs/sys_functions.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "os_functions.h" 25 | 26 | unsigned int sysapp_handle __attribute__((section(".data"))) = 0; 27 | 28 | EXPORT_DECL(int, _SYSLaunchTitleByPathFromLauncher, const char* path, int len, int zero); 29 | EXPORT_DECL(int, SYSRelaunchTitle, int argc, char** argv); 30 | EXPORT_DECL(int, SYSLaunchMenu, void); 31 | EXPORT_DECL(int, SYSCheckTitleExists, u64 titleId); 32 | EXPORT_DECL(int, SYSLaunchTitle, u64 titleId); 33 | EXPORT_DECL(int, SYSLaunchSettings, int unk); 34 | 35 | void InitAcquireSys(void) 36 | { 37 | OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle); 38 | } 39 | 40 | void InitSysFunctionPointers(void) 41 | { 42 | unsigned int *funcPointer = 0; 43 | InitAcquireSys(); 44 | 45 | OS_FIND_EXPORT(sysapp_handle, _SYSLaunchTitleByPathFromLauncher); 46 | OS_FIND_EXPORT(sysapp_handle, SYSRelaunchTitle); 47 | OS_FIND_EXPORT(sysapp_handle, SYSLaunchMenu); 48 | OS_FIND_EXPORT(sysapp_handle, SYSCheckTitleExists); 49 | OS_FIND_EXPORT(sysapp_handle, SYSLaunchTitle); 50 | OS_FIND_EXPORT(sysapp_handle, SYSLaunchSettings); 51 | } 52 | -------------------------------------------------------------------------------- /src/dynamic_libs/sys_functions.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __SYS_FUNCTIONS_H_ 25 | #define __SYS_FUNCTIONS_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | extern unsigned int sysapp_handle; 32 | 33 | void InitSysFunctionPointers(void); 34 | void InitAcquireSys(void); 35 | 36 | extern int(*_SYSLaunchTitleByPathFromLauncher)(const char* path, int len, int zero); 37 | extern int (* SYSRelaunchTitle)(int argc, char** argv); 38 | extern int (* SYSLaunchMenu)(void); 39 | extern int (* SYSCheckTitleExists)(u64 titleId); 40 | extern int (* SYSLaunchTitle)(u64 titleId); 41 | extern int (* SYSLaunchSettings)(int unk); 42 | 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif // __SYS_FUNCTIONS_H_ 49 | -------------------------------------------------------------------------------- /src/dynamic_libs/vpad_functions.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "os_functions.h" 25 | #include "vpad_functions.h" 26 | 27 | unsigned int vpad_handle __attribute__((section(".data"))) = 0; 28 | unsigned int vpadbase_handle __attribute__((section(".data"))) = 0; 29 | 30 | EXPORT_DECL(void, VPADInit, void); 31 | EXPORT_DECL(int, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error); 32 | EXPORT_DECL(int, VPADGetLcdMode, int padnum, int *lcdmode); 33 | EXPORT_DECL(int, VPADSetLcdMode, int padnum, int lcdmode); 34 | EXPORT_DECL(int, VPADBASEGetMotorOnRemainingCount, int padnum); 35 | EXPORT_DECL(int, VPADBASESetMotorOnRemainingCount, int padnum, int counter); 36 | 37 | void InitAcquireVPad(void) 38 | { 39 | OSDynLoad_Acquire("vpad.rpl", &vpad_handle); 40 | OSDynLoad_Acquire("vpadbase.rpl", &vpadbase_handle); 41 | } 42 | 43 | void InitVPadFunctionPointers(void) 44 | { 45 | unsigned int *funcPointer = 0; 46 | 47 | InitAcquireVPad(); 48 | 49 | OS_FIND_EXPORT(vpad_handle, VPADInit); 50 | OS_FIND_EXPORT(vpad_handle, VPADRead); 51 | OS_FIND_EXPORT(vpad_handle, VPADGetLcdMode); 52 | OS_FIND_EXPORT(vpad_handle, VPADSetLcdMode); 53 | OS_FIND_EXPORT(vpadbase_handle, VPADBASEGetMotorOnRemainingCount); 54 | OS_FIND_EXPORT(vpadbase_handle, VPADBASESetMotorOnRemainingCount); 55 | } 56 | -------------------------------------------------------------------------------- /src/dynamic_libs/vpad_functions.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __VPAD_FUNCTIONS_H_ 25 | #define __VPAD_FUNCTIONS_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | extern unsigned int vpad_handle; 32 | extern unsigned int vpadbase_handle; 33 | 34 | #include 35 | 36 | #define VPAD_BUTTON_A 0x8000 37 | #define VPAD_BUTTON_B 0x4000 38 | #define VPAD_BUTTON_X 0x2000 39 | #define VPAD_BUTTON_Y 0x1000 40 | #define VPAD_BUTTON_LEFT 0x0800 41 | #define VPAD_BUTTON_RIGHT 0x0400 42 | #define VPAD_BUTTON_UP 0x0200 43 | #define VPAD_BUTTON_DOWN 0x0100 44 | #define VPAD_BUTTON_ZL 0x0080 45 | #define VPAD_BUTTON_ZR 0x0040 46 | #define VPAD_BUTTON_L 0x0020 47 | #define VPAD_BUTTON_R 0x0010 48 | #define VPAD_BUTTON_PLUS 0x0008 49 | #define VPAD_BUTTON_MINUS 0x0004 50 | #define VPAD_BUTTON_HOME 0x0002 51 | #define VPAD_BUTTON_SYNC 0x0001 52 | #define VPAD_BUTTON_STICK_R 0x00020000 53 | #define VPAD_BUTTON_STICK_L 0x00040000 54 | #define VPAD_BUTTON_TV 0x00010000 55 | 56 | #define VPAD_STICK_R_EMULATION_LEFT 0x04000000 57 | #define VPAD_STICK_R_EMULATION_RIGHT 0x02000000 58 | #define VPAD_STICK_R_EMULATION_UP 0x01000000 59 | #define VPAD_STICK_R_EMULATION_DOWN 0x00800000 60 | 61 | #define VPAD_STICK_L_EMULATION_LEFT 0x40000000 62 | #define VPAD_STICK_L_EMULATION_RIGHT 0x20000000 63 | #define VPAD_STICK_L_EMULATION_UP 0x10000000 64 | #define VPAD_STICK_L_EMULATION_DOWN 0x08000000 65 | 66 | //! Own definitions 67 | #define VPAD_BUTTON_TOUCH 0x00080000 68 | #define VPAD_MASK_EMULATED_STICKS 0x7F800000 69 | #define VPAD_MASK_BUTTONS ~VPAD_MASK_EMULATED_STICKS 70 | 71 | typedef struct 72 | { 73 | f32 x,y; 74 | } Vec2D; 75 | 76 | typedef struct 77 | { 78 | u16 x, y; /* Touch coordinates */ 79 | u16 touched; /* 1 = Touched, 0 = Not touched */ 80 | u16 invalid; /* 0 = All valid, 1 = X invalid, 2 = Y invalid, 3 = Both invalid? */ 81 | } VPADTPData; 82 | 83 | typedef struct 84 | { 85 | u32 btns_h; /* Held buttons */ 86 | u32 btns_d; /* Buttons that are pressed at that instant */ 87 | u32 btns_r; /* Released buttons */ 88 | Vec2D lstick, rstick; /* Each contains 4-byte X and Y components */ 89 | char unknown1c[0x52 - 0x1c]; /* Contains accelerometer and gyroscope data somewhere */ 90 | VPADTPData tpdata; /* Normal touchscreen data */ 91 | VPADTPData tpdata1; /* Modified touchscreen data 1 */ 92 | VPADTPData tpdata2; /* Modified touchscreen data 2 */ 93 | char unknown6a[0xa0 - 0x6a]; 94 | uint8_t volume; 95 | uint8_t battery; /* 0 to 6 */ 96 | uint8_t unk_volume; /* One less than volume */ 97 | char unknowna4[0xac - 0xa4]; 98 | } VPADData; 99 | 100 | void InitVPadFunctionPointers(void); 101 | void InitAcquireVPad(void); 102 | 103 | extern int (* VPADRead)(int chan, VPADData *buffer, u32 buffer_size, s32 *error); 104 | extern int (* VPADGetLcdMode)(int padnum, int *lcdmode); 105 | extern int (* VPADSetLcdMode)(int padnum, int lcdmode); 106 | extern void (* VPADInit)(void); 107 | extern int (* VPADBASEGetMotorOnRemainingCount)(int lcdmode); 108 | extern int (* VPADBASESetMotorOnRemainingCount)(int lcdmode,int counter); 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif // __VPAD_FUNCTIONS_H_ 115 | -------------------------------------------------------------------------------- /src/entry.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dynamic_libs/os_functions.h" 3 | #include "dynamic_libs/sys_functions.h" 4 | #include "common/common.h" 5 | #include "utils/utils.h" 6 | #include "main.h" 7 | 8 | int __entry_menu(int argc, char **argv) 9 | { 10 | //! ******************************************************************* 11 | //! * Jump to our application * 12 | //! ******************************************************************* 13 | return Menu_Main(); 14 | } 15 | -------------------------------------------------------------------------------- /src/fs/fs_utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "common/fs_defs.h" 7 | #include "dynamic_libs/fs_functions.h" 8 | 9 | 10 | int MountFS(void *pClient, void *pCmd, char **mount_path) 11 | { 12 | int result = -1; 13 | 14 | void *mountSrc = malloc(FS_MOUNT_SOURCE_SIZE); 15 | if(!mountSrc) 16 | return -3; 17 | 18 | char* mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE); 19 | if(!mountPath) { 20 | free(mountSrc); 21 | return -4; 22 | } 23 | 24 | memset(mountSrc, 0, FS_MOUNT_SOURCE_SIZE); 25 | memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE); 26 | 27 | // Mount sdcard 28 | if (FSGetMountSource(pClient, pCmd, FS_SOURCETYPE_EXTERNAL, mountSrc, -1) == 0) 29 | { 30 | result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1); 31 | if((result == 0) && mount_path) { 32 | *mount_path = (char*)malloc(strlen(mountPath) + 1); 33 | if(*mount_path) 34 | strcpy(*mount_path, mountPath); 35 | } 36 | } 37 | 38 | free(mountPath); 39 | free(mountSrc); 40 | return result; 41 | } 42 | 43 | int UmountFS(void *pClient, void *pCmd, const char *mountPath) 44 | { 45 | int result = -1; 46 | result = FSUnmount(pClient, pCmd, mountPath, -1); 47 | 48 | return result; 49 | } 50 | 51 | int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size) 52 | { 53 | //! always initialze input 54 | *inbuffer = NULL; 55 | if(size) 56 | *size = 0; 57 | 58 | int iFd = open(filepath, O_RDONLY); 59 | if (iFd < 0) 60 | return -1; 61 | 62 | u32 filesize = lseek(iFd, 0, SEEK_END); 63 | lseek(iFd, 0, SEEK_SET); 64 | 65 | u8 *buffer = (u8 *) malloc(filesize); 66 | if (buffer == NULL) 67 | { 68 | close(iFd); 69 | return -2; 70 | } 71 | 72 | u32 blocksize = 0x4000; 73 | u32 done = 0; 74 | int readBytes = 0; 75 | 76 | while(done < filesize) 77 | { 78 | if(done + blocksize > filesize) { 79 | blocksize = filesize - done; 80 | } 81 | readBytes = read(iFd, buffer + done, blocksize); 82 | if(readBytes <= 0) 83 | break; 84 | done += readBytes; 85 | } 86 | 87 | close(iFd); 88 | 89 | if (done != filesize) 90 | { 91 | free(buffer); 92 | return -3; 93 | } 94 | 95 | *inbuffer = buffer; 96 | 97 | //! sign is optional input 98 | if(size) 99 | *size = filesize; 100 | 101 | return filesize; 102 | } 103 | 104 | int CheckFile(const char * filepath) 105 | { 106 | if(!filepath) 107 | return 0; 108 | 109 | struct stat filestat; 110 | 111 | char dirnoslash[strlen(filepath)+2]; 112 | snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); 113 | 114 | while(dirnoslash[strlen(dirnoslash)-1] == '/') 115 | dirnoslash[strlen(dirnoslash)-1] = '\0'; 116 | 117 | char * notRoot = strrchr(dirnoslash, '/'); 118 | if(!notRoot) 119 | { 120 | strcat(dirnoslash, "/"); 121 | } 122 | 123 | if (stat(dirnoslash, &filestat) == 0) 124 | return 1; 125 | 126 | return 0; 127 | } 128 | 129 | int CreateSubfolder(const char * fullpath) 130 | { 131 | if(!fullpath) 132 | return 0; 133 | 134 | int result = 0; 135 | 136 | char dirnoslash[strlen(fullpath)+1]; 137 | strcpy(dirnoslash, fullpath); 138 | 139 | int pos = strlen(dirnoslash)-1; 140 | while(dirnoslash[pos] == '/') 141 | { 142 | dirnoslash[pos] = '\0'; 143 | pos--; 144 | } 145 | 146 | if(CheckFile(dirnoslash)) 147 | { 148 | return 1; 149 | } 150 | else 151 | { 152 | char parentpath[strlen(dirnoslash)+2]; 153 | strcpy(parentpath, dirnoslash); 154 | char * ptr = strrchr(parentpath, '/'); 155 | 156 | if(!ptr) 157 | { 158 | //!Device root directory (must be with '/') 159 | strcat(parentpath, "/"); 160 | struct stat filestat; 161 | if (stat(parentpath, &filestat) == 0) 162 | return 1; 163 | 164 | return 0; 165 | } 166 | 167 | ptr++; 168 | ptr[0] = '\0'; 169 | 170 | result = CreateSubfolder(parentpath); 171 | } 172 | 173 | if(!result) 174 | return 0; 175 | 176 | if (mkdir(dirnoslash, 0777) == -1) 177 | { 178 | return 0; 179 | } 180 | 181 | return 1; 182 | } 183 | -------------------------------------------------------------------------------- /src/fs/fs_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __FS_UTILS_H_ 2 | #define __FS_UTILS_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | int MountFS(void *pClient, void *pCmd, char **mount_path); 11 | int UmountFS(void *pClient, void *pCmd, const char *mountPath); 12 | 13 | int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size); 14 | 15 | //! todo: C++ class 16 | int CreateSubfolder(const char * fullpath); 17 | int CheckFile(const char * filepath); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif // __FS_UTILS_H_ 24 | -------------------------------------------------------------------------------- /src/fs/sd_fat_devoptab.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __SD_FAT_DEVOPTAB_H_ 25 | #define __SD_FAT_DEVOPTAB_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | int mount_sd_fat(const char *path); 32 | int unmount_sd_fat(const char *path); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif // __SD_FAT_DEVOPTAB_H_ 39 | -------------------------------------------------------------------------------- /src/ios_exploit.h: -------------------------------------------------------------------------------- 1 | #ifndef _IOS_EXPLOIT_H_ 2 | #define _IOS_EXPLOIT_H_ 3 | 4 | #include "cfw_config.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | int ExecuteIOSExploit(cfw_config_t * config); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT(ftpiiu.elf); 2 | 3 | /* Tell linker where our application entry is so the garbage collect can work correct */ 4 | ENTRY(__entry_menu); 5 | 6 | SECTIONS { 7 | . = 0x00802000; 8 | .text : { 9 | *(.text*); 10 | } 11 | .rodata : { 12 | *(.rodata*); 13 | } 14 | .data : { 15 | *(.data*); 16 | 17 | __sdata_start = .; 18 | *(.sdata*); 19 | __sdata_end = .; 20 | 21 | __sdata2_start = .; 22 | *(.sdata2*); 23 | __sdata2_end = .; 24 | } 25 | .bss : { 26 | __bss_start = .; 27 | *(.bss*); 28 | *(.sbss*); 29 | *(COMMON); 30 | __bss_end = .; 31 | } 32 | __CODE_END = .; 33 | 34 | /DISCARD/ : { 35 | *(*); 36 | } 37 | } 38 | 39 | /******************************************************** FS ********************************************************/ 40 | /* coreinit.rpl difference in addresses 0xFE3C00 */ 41 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "dynamic_libs/os_functions.h" 9 | #include "dynamic_libs/fs_functions.h" 10 | #include "dynamic_libs/gx2_functions.h" 11 | #include "dynamic_libs/sys_functions.h" 12 | #include "dynamic_libs/vpad_functions.h" 13 | #include "dynamic_libs/socket_functions.h" 14 | #include "fs/fs_utils.h" 15 | #include "fs/sd_fat_devoptab.h" 16 | #include "system/memory.h" 17 | #include "utils/logger.h" 18 | #include "utils/utils.h" 19 | #include "common/common.h" 20 | #include "menu.h" 21 | #include "main.h" 22 | #include "ios_exploit.h" 23 | 24 | static int exitToHBLOnLaunch = 0; 25 | 26 | int Menu_Main(void) 27 | { 28 | //!---------INIT--------- 29 | InitOSFunctionPointers(); 30 | InitSysFunctionPointers(); 31 | InitFSFunctionPointers(); 32 | InitSocketFunctionPointers(); 33 | InitVPadFunctionPointers(); 34 | 35 | u64 currenTitleId = OSGetTitleID(); 36 | 37 | // in case we are not in mii maker or HBL channel but in system menu or another channel we need to exit here 38 | if (currenTitleId != 0x000500101004A200 && // mii maker eur 39 | currenTitleId != 0x000500101004A100 && // mii maker usa 40 | currenTitleId != 0x000500101004A000 && // mii maker jpn 41 | currenTitleId != 0x0005000013374842) // HBL channel 42 | { 43 | return EXIT_RELAUNCH_ON_LOAD; 44 | } 45 | else if(exitToHBLOnLaunch) 46 | { 47 | return 0; 48 | } 49 | 50 | VPADInit(); 51 | /*int forceMenu = 0; 52 | 53 | { 54 | VPADData vpad; 55 | int vpadError = -1; 56 | VPADRead(0, &vpad, 1, &vpadError); 57 | 58 | if(vpadError == 0) 59 | { 60 | forceMenu = (vpad.btns_d | vpad.btns_h) & VPAD_BUTTON_B; 61 | } 62 | }*/ 63 | 64 | //mount_sd_fat("sd"); 65 | 66 | cfw_config_t config; 67 | default_config(&config); 68 | //read_config(&config); 69 | 70 | int launch = 1; 71 | 72 | //if(forceMenu || config.directLaunch == 0) 73 | //{ 74 | launch = ShowMenu(&config); 75 | //} 76 | 77 | int returnCode = 0; 78 | 79 | if(launch) 80 | { 81 | int res = ExecuteIOSExploit(&config); 82 | if(res == 0) 83 | { 84 | //if(config.noIosReload == 0) 85 | //{ 86 | OSForceFullRelaunch(); 87 | SYSLaunchMenu(); 88 | returnCode = EXIT_RELAUNCH_ON_LOAD; 89 | //} 90 | //else if(config.launchSysMenu) 91 | //{ 92 | // SYSLaunchMenu(); 93 | // exitToHBLOnLaunch = 1; 94 | // returnCode = EXIT_RELAUNCH_ON_LOAD; 95 | //} 96 | } 97 | } 98 | 99 | //unmount_sd_fat("sd"); 100 | 101 | return returnCode; 102 | } 103 | -------------------------------------------------------------------------------- /src/main.h: -------------------------------------------------------------------------------- 1 | //Main.h 2 | #ifndef _MAIN_H_ 3 | #define _MAIN_H_ 4 | 5 | #include "common/types.h" 6 | #include "dynamic_libs/os_functions.h" 7 | 8 | /* Main */ 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | //! C wrapper for our C++ functions 14 | int Menu_Main(void); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/menu.h: -------------------------------------------------------------------------------- 1 | #ifndef _MENU_H_ 2 | #define _MENU_H_ 3 | 4 | #include "cfw_config.h" 5 | 6 | int ShowMenu(cfw_config_t * config); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/system/exception_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef __EXCEPTION_HANDLER_H_ 2 | #define __EXCEPTION_HANDLER_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void setup_os_exceptions(void); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/system/memory.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #ifndef __MEMORY_H_ 18 | #define __MEMORY_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include 25 | 26 | void memoryInitialize(void); 27 | void memoryRelease(void); 28 | 29 | void * MEM2_alloc(unsigned int size, unsigned int align); 30 | void MEM2_free(void *ptr); 31 | 32 | void * MEM1_alloc(unsigned int size, unsigned int align); 33 | void MEM1_free(void *ptr); 34 | 35 | void * MEMBucket_alloc(unsigned int size, unsigned int align); 36 | void MEMBucket_free(void *ptr); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif // __MEMORY_H_ 43 | -------------------------------------------------------------------------------- /src/utils/logger.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "common/common.h" 7 | #include "dynamic_libs/os_functions.h" 8 | #include "dynamic_libs/socket_functions.h" 9 | #include "logger.h" 10 | 11 | #ifdef DEBUG_LOGGER 12 | static int log_socket = -1; 13 | static volatile int log_lock = 0; 14 | 15 | 16 | void log_init(const char * ipString) 17 | { 18 | log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 19 | if (log_socket < 0) 20 | return; 21 | 22 | struct sockaddr_in connect_addr; 23 | memset(&connect_addr, 0, sizeof(connect_addr)); 24 | connect_addr.sin_family = AF_INET; 25 | connect_addr.sin_port = 4405; 26 | inet_aton(ipString, &connect_addr.sin_addr); 27 | 28 | if(connect(log_socket, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) 29 | { 30 | socketclose(log_socket); 31 | log_socket = -1; 32 | } 33 | } 34 | 35 | void log_deinit(void) 36 | { 37 | if(log_socket >= 0) 38 | { 39 | socketclose(log_socket); 40 | log_socket = -1; 41 | } 42 | } 43 | 44 | void log_print(const char *str) 45 | { 46 | // socket is always 0 initially as it is in the BSS 47 | if(log_socket < 0) { 48 | return; 49 | } 50 | 51 | while(log_lock) 52 | usleep(1000); 53 | log_lock = 1; 54 | 55 | int len = strlen(str); 56 | int ret; 57 | while (len > 0) { 58 | int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet 59 | ret = send(log_socket, str, block, 0); 60 | if(ret < 0) 61 | break; 62 | 63 | len -= ret; 64 | str += ret; 65 | } 66 | 67 | log_lock = 0; 68 | } 69 | 70 | void log_printf(const char *format, ...) 71 | { 72 | if(log_socket < 0) { 73 | return; 74 | } 75 | 76 | char * tmp = NULL; 77 | 78 | va_list va; 79 | va_start(va, format); 80 | if((vasprintf(&tmp, format, va) >= 0) && tmp) 81 | { 82 | log_print(tmp); 83 | } 84 | va_end(va); 85 | 86 | if(tmp) 87 | free(tmp); 88 | } 89 | #endif 90 | -------------------------------------------------------------------------------- /src/utils/logger.h: -------------------------------------------------------------------------------- 1 | #ifndef __LOGGER_H_ 2 | #define __LOGGER_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define DEBUG_LOGGER 1 9 | 10 | #ifdef DEBUG_LOGGER 11 | void log_init(const char * ip); 12 | void log_deinit(void); 13 | void log_print(const char *str); 14 | void log_printf(const char *format, ...); 15 | #else 16 | #define log_init(x) 17 | #define log_deinit() 18 | #define log_print(x) 19 | #define log_printf(x, ...) 20 | #endif 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/utils/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTILS_H_ 2 | #define __UTILS_H_ 3 | 4 | #include 5 | #include "../common/types.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define FlushBlock(addr) asm volatile("dcbf %0, %1\n" \ 12 | "icbi %0, %1\n" \ 13 | "sync\n" \ 14 | "eieio\n" \ 15 | "isync\n" \ 16 | : \ 17 | :"r"(0), "r"(((addr) & ~31)) \ 18 | :"memory", "ctr", "lr", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" \ 19 | ); 20 | 21 | #define LIMIT(x, min, max) \ 22 | ({ \ 23 | typeof( x ) _x = x; \ 24 | typeof( min ) _min = min; \ 25 | typeof( max ) _max = max; \ 26 | ( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ 27 | }) 28 | 29 | #define DegToRad(a) ( (a) * 0.01745329252f ) 30 | #define RadToDeg(a) ( (a) * 57.29577951f ) 31 | 32 | #define ALIGN4(x) (((x) + 3) & ~3) 33 | #define ALIGN32(x) (((x) + 31) & ~31) 34 | 35 | // those work only in powers of 2 36 | #define ROUNDDOWN(val, align) ((val) & ~(align-1)) 37 | #define ROUNDUP(val, align) ROUNDDOWN(((val) + (align-1)), align) 38 | 39 | #define le16(i) ((((u16) ((i) & 0xFF)) << 8) | ((u16) (((i) & 0xFF00) >> 8))) 40 | #define le32(i) ((((u32)le16((i) & 0xFFFF)) << 16) | ((u32)le16(((i) & 0xFFFF0000) >> 16))) 41 | #define le64(i) ((((u64)le32((i) & 0xFFFFFFFFLL)) << 32) | ((u64)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // __UTILS_H_ 48 | --------------------------------------------------------------------------------