mirror of
https://github.com/wiiu-env/MochaPayload.git
synced 2025-01-09 06:49:23 +01:00
Formatting
This commit is contained in:
parent
78d8526363
commit
ed4ad86a9c
@ -19,6 +19,7 @@ extern const uint8_t launch_image_tga[];
|
||||
extern const uint32_t launch_image_tga_size;
|
||||
|
||||
static void uhs_exploit_init(int uhs_handle);
|
||||
|
||||
static int uhs_write32(int uhs_handle, int arm_addr, int val);
|
||||
|
||||
//!------Variables used in exploit------
|
||||
|
@ -25,86 +25,71 @@
|
||||
#include "elf_abi.h"
|
||||
#include "utils.h"
|
||||
|
||||
static Elf32_Phdr * get_section(u32 data, u32 vaddr)
|
||||
{
|
||||
static Elf32_Phdr *get_section(u32 data, u32 vaddr) {
|
||||
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) data;
|
||||
|
||||
if (!IS_ELF (*ehdr)
|
||||
|| (ehdr->e_type != ET_EXEC)
|
||||
|| (ehdr->e_machine != EM_ARM))
|
||||
{
|
||||
|| (ehdr->e_machine != EM_ARM)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Elf32_Phdr *phdr = 0;
|
||||
|
||||
u32 i;
|
||||
for(i = 0; i < ehdr->e_phnum; i++)
|
||||
{
|
||||
for (i = 0; i < ehdr->e_phnum; i++) {
|
||||
phdr = (Elf32_Phdr *) (data + ehdr->e_phoff + ehdr->e_phentsize * i);
|
||||
|
||||
if((vaddr >= phdr[0].p_vaddr) && ((i == ehdr->e_phnum) || (vaddr < phdr[1].p_vaddr)))
|
||||
{
|
||||
if ((vaddr >= phdr[0].p_vaddr) && ((i == ehdr->e_phnum) || (vaddr < phdr[1].p_vaddr))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return phdr;
|
||||
}
|
||||
|
||||
void section_write_bss(u32 ios_elf_start, u32 address, u32 size)
|
||||
{
|
||||
void section_write_bss(u32 ios_elf_start, u32 address, u32 size) {
|
||||
Elf32_Phdr *phdr = get_section(ios_elf_start, address);
|
||||
if (!phdr)
|
||||
return;
|
||||
|
||||
if((address - phdr->p_vaddr + size) > phdr->p_memsz)
|
||||
{
|
||||
if ((address - phdr->p_vaddr + size) > phdr->p_memsz) {
|
||||
phdr->p_memsz = (address - phdr->p_vaddr + size);
|
||||
}
|
||||
}
|
||||
|
||||
void section_write(u32 ios_elf_start, u32 address, const void *data, u32 size)
|
||||
{
|
||||
void section_write(u32 ios_elf_start, u32 address, const void *data, u32 size) {
|
||||
Elf32_Phdr *phdr = get_section(ios_elf_start, address);
|
||||
if (!phdr)
|
||||
return;
|
||||
|
||||
u32 *addr = (u32 *) (ios_elf_start + address - phdr->p_vaddr + phdr->p_offset);
|
||||
|
||||
if((address - phdr->p_vaddr + size) > phdr->p_filesz)
|
||||
{
|
||||
if ((address - phdr->p_vaddr + size) > phdr->p_filesz) {
|
||||
u32 additionalSize = address - phdr->p_vaddr + size - phdr->p_filesz;
|
||||
|
||||
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) ios_elf_start;
|
||||
Elf32_Phdr *tmpPhdr;
|
||||
u32 i;
|
||||
for(i = (ehdr->e_phnum-1); i >= 0; i--)
|
||||
{
|
||||
for (i = (ehdr->e_phnum - 1); i >= 0; i--) {
|
||||
tmpPhdr = (Elf32_Phdr *) (ios_elf_start + ehdr->e_phoff + ehdr->e_phentsize * i);
|
||||
|
||||
if(phdr->p_offset < tmpPhdr->p_offset)
|
||||
{
|
||||
if (phdr->p_offset < tmpPhdr->p_offset) {
|
||||
reverse_memcpy((u8 *) ios_elf_start + tmpPhdr->p_offset + additionalSize, (u8 *) ios_elf_start + tmpPhdr->p_offset, tmpPhdr->p_filesz);
|
||||
tmpPhdr->p_offset += additionalSize;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
phdr->p_filesz += additionalSize;
|
||||
if(phdr->p_memsz < phdr->p_filesz)
|
||||
{
|
||||
if (phdr->p_memsz < phdr->p_filesz) {
|
||||
phdr->p_memsz = phdr->p_filesz;
|
||||
}
|
||||
}
|
||||
|
||||
// in most cases only a word is copied to an aligned address so do a short cut for performance
|
||||
if(size == 4 && !((unsigned int)addr & 3) && !((unsigned int)data & 3))
|
||||
{
|
||||
if (size == 4 && !((unsigned int) addr & 3) && !((unsigned int) data & 3)) {
|
||||
*(u32 *) addr = *(u32 *) data;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
kernel_memcpy(addr, data, size);
|
||||
}
|
||||
}
|
||||
|
@ -31,27 +31,24 @@
|
||||
#define THUMB_B(addr, func) ((0xE000 | ((((u32)(func) - (u32)(addr) - 4) >> 1) & 0x7FF))) // +-2KB
|
||||
#define THUMB_BL(addr, func) ((0xF000F800 | ((((u32)(func) - (u32)(addr) - 4) >> 1) & 0x0FFF)) | ((((u32)(func) - (u32)(addr) - 4) << 4) & 0x7FFF000)) // +-4MB
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
u32 address;
|
||||
void *data;
|
||||
u32 size;
|
||||
} patch_table_t;
|
||||
|
||||
void section_write(u32 ios_elf_start, u32 address, const void *data, u32 size);
|
||||
|
||||
void section_write_bss(u32 ios_elf_start, u32 address, u32 size);
|
||||
|
||||
static inline void section_write_word(u32 ios_elf_start, u32 address, u32 word)
|
||||
{
|
||||
static inline void section_write_word(u32 ios_elf_start, u32 address, u32 word) {
|
||||
section_write(ios_elf_start, address, &word, sizeof(word));
|
||||
}
|
||||
|
||||
|
||||
static inline void patch_table_entries(u32 ios_elf_start, const patch_table_t * patch_table, u32 patch_count)
|
||||
{
|
||||
static inline void patch_table_entries(u32 ios_elf_start, const patch_table_t *patch_table, u32 patch_count) {
|
||||
u32 i;
|
||||
for(i = 0; i < patch_count; i++)
|
||||
{
|
||||
for (i = 0; i < patch_count; i++) {
|
||||
section_write(ios_elf_start, patch_table[i].address, patch_table[i].data, patch_table[i].size);
|
||||
}
|
||||
}
|
||||
|
@ -24,32 +24,22 @@
|
||||
#include "text.h"
|
||||
#include "types.h"
|
||||
|
||||
void crash_handler(unsigned int *context, int type)
|
||||
{
|
||||
void crash_handler(unsigned int *context, int type) {
|
||||
clearScreen(0xFFFFFFFF);
|
||||
|
||||
if(type == 0)
|
||||
{
|
||||
if (type == 0) {
|
||||
_printf(0, 0, "GURU MEDITATION ERROR (prefetch abort)");
|
||||
}
|
||||
else if(type == 1)
|
||||
{
|
||||
} else if (type == 1) {
|
||||
_printf(0, 0, "GURU MEDITATION ERROR (data abort)");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_printf(0, 0, "GURU MEDITATION ERROR (undefined instruction)");
|
||||
}
|
||||
|
||||
int reg = 0;
|
||||
while(reg < 16)
|
||||
{
|
||||
if(reg < 10)
|
||||
{
|
||||
while (reg < 16) {
|
||||
if (reg < 10) {
|
||||
_printf(20, 40 + reg * 20, "r%d = %08X", reg, context[1 + reg]);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_printf(20, 40 + reg * 20, "r%d = %08X", reg, context[1 + reg]);
|
||||
}
|
||||
|
||||
|
@ -26,18 +26,15 @@
|
||||
|
||||
void crash_handler(unsigned int *context, int type);
|
||||
|
||||
static inline void crash_handler_prefetch(unsigned int *context, int unused1, int unused2)
|
||||
{
|
||||
static inline void crash_handler_prefetch(unsigned int *context, int unused1, int unused2) {
|
||||
crash_handler(context, 0);
|
||||
}
|
||||
|
||||
static inline void crash_handler_data(unsigned int *context, int unused1, int unused2)
|
||||
{
|
||||
static inline void crash_handler_data(unsigned int *context, int unused1, int unused2) {
|
||||
crash_handler(context, 1);
|
||||
}
|
||||
|
||||
static inline void crash_handler_undef_instr(unsigned int *context, int unused1, int unused2)
|
||||
{
|
||||
static inline void crash_handler_undef_instr(unsigned int *context, int unused1, int unused2) {
|
||||
crash_handler(context, 2);
|
||||
}
|
||||
|
||||
|
@ -32,28 +32,24 @@
|
||||
#define svcIoctl ((int (*)(int fd, u32 request, void* input_buffer, u32 input_buffer_len, void* output_buffer, u32 output_buffer_len))0x081290E0)
|
||||
#define svcIoctlv ((int (*)(int fd, u32 request, u32 vector_count_in, u32 vector_count_out, iovec_s* vector))0x0812903C)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
void *ptr;
|
||||
u32 len;
|
||||
u32 unk;
|
||||
} iovec_s;
|
||||
|
||||
static void* allocIobuf()
|
||||
{
|
||||
static void *allocIobuf() {
|
||||
void *ptr = svcAlloc(0xCAFF, 0x828);
|
||||
kernel_memset(ptr, 0x00, 0x828);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void freeIobuf(void* ptr)
|
||||
{
|
||||
static void freeIobuf(void *ptr) {
|
||||
svcFree(0xCAFF, ptr);
|
||||
}
|
||||
|
||||
static int IOS_Open(const char * dev, int mode)
|
||||
{
|
||||
static int IOS_Open(const char *dev, int mode) {
|
||||
// put string into a good location
|
||||
char *devStr = (char *) svcAlloc(0xCAFF, 0x20);
|
||||
if (!devStr)
|
||||
@ -68,18 +64,15 @@ static int IOS_Open(const char * dev, int mode)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int FSA_Open(void)
|
||||
{
|
||||
static int FSA_Open(void) {
|
||||
return IOS_Open("/dev/fsa", 0);
|
||||
}
|
||||
|
||||
static int FSA_Close(int fd)
|
||||
{
|
||||
static int FSA_Close(int fd) {
|
||||
return svcClose(fd);
|
||||
}
|
||||
|
||||
static int FSA_RawOpen(int fd, const char* device_path, int* outHandle)
|
||||
{
|
||||
static int FSA_RawOpen(int fd, const char *device_path, int *outHandle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -94,8 +87,7 @@ static int FSA_RawOpen(int fd, const char* device_path, int* outHandle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int FSA_RawClose(int fd, int device_handle)
|
||||
{
|
||||
static int FSA_RawClose(int fd, int device_handle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -108,8 +100,7 @@ static int FSA_RawClose(int fd, int device_handle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int FSA_RawRead(int fd, void* data, u32 size_bytes, u32 cnt, u64 blocks_offset, int device_handle)
|
||||
{
|
||||
static int FSA_RawRead(int fd, void *data, u32 size_bytes, u32 cnt, u64 blocks_offset, int device_handle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u8 *inbuf8 = iobuf;
|
||||
u8 *outbuf8 = &iobuf[0x520];
|
||||
@ -139,8 +130,7 @@ static int FSA_RawRead(int fd, void* data, u32 size_bytes, u32 cnt, u64 blocks_o
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int FSA_RawWrite(int fd, void* data, u32 size_bytes, u32 cnt, u64 blocks_offset, int device_handle)
|
||||
{
|
||||
static int FSA_RawWrite(int fd, void *data, u32 size_bytes, u32 cnt, u64 blocks_offset, int device_handle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u8 *inbuf8 = iobuf;
|
||||
u8 *outbuf8 = &iobuf[0x520];
|
||||
@ -169,23 +159,20 @@ static int FSA_RawWrite(int fd, void* data, u32 size_bytes, u32 cnt, u64 blocks_
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_SDReadRawSectors(void *buffer, u32 sector, u32 num_sectors)
|
||||
{
|
||||
int FSA_SDReadRawSectors(void *buffer, u32 sector, u32 num_sectors) {
|
||||
int fsa = FSA_Open();
|
||||
if (fsa < 0)
|
||||
return fsa;
|
||||
|
||||
int fd;
|
||||
int res = FSA_RawOpen(fsa, "/dev/sdcard01", &fd);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
FSA_Close(fsa);
|
||||
return res;
|
||||
}
|
||||
|
||||
void *buf = svcAllocAlign(0xCAFF, num_sectors << 9, 0x40);
|
||||
if(!buf)
|
||||
{
|
||||
if (!buf) {
|
||||
FSA_RawClose(fsa, fd);
|
||||
FSA_Close(fsa);
|
||||
return -2;
|
||||
@ -202,23 +189,20 @@ int FSA_SDReadRawSectors(void *buffer, u32 sector, u32 num_sectors)
|
||||
return res;
|
||||
}
|
||||
|
||||
int FSA_SDWriteRawSectors(const void *buffer, u32 sector, u32 num_sectors)
|
||||
{
|
||||
int FSA_SDWriteRawSectors(const void *buffer, u32 sector, u32 num_sectors) {
|
||||
int fsa = FSA_Open();
|
||||
if (fsa < 0)
|
||||
return fsa;
|
||||
|
||||
int fd;
|
||||
int res = FSA_RawOpen(fsa, "/dev/sdcard01", &fd);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
FSA_Close(fsa);
|
||||
return res;
|
||||
}
|
||||
|
||||
void *buf = svcAllocAlign(0xCAFF, num_sectors << 9, 0x40);
|
||||
if(!buf)
|
||||
{
|
||||
if (!buf) {
|
||||
FSA_RawClose(fsa, fd);
|
||||
FSA_Close(fsa);
|
||||
return -2;
|
||||
|
@ -37,20 +37,19 @@
|
||||
#define NAND_DESC_TYPE_SEEPROM 0x45455052 // 'EEPR'
|
||||
#define NAND_DESC_TYPE_OTP 0x4f545020 // 'OTP '
|
||||
|
||||
typedef struct _stdio_nand_desc_t
|
||||
{
|
||||
typedef struct _stdio_nand_desc_t {
|
||||
u32 nand_type; // nand type
|
||||
u32 base_sector; // base sector of dump
|
||||
u32 sector_count; // sector count in SDIO sectors
|
||||
} __attribute__((packed)) stdio_nand_desc_t;
|
||||
|
||||
typedef struct _sdio_nand_signature_sector_t
|
||||
{
|
||||
typedef struct _sdio_nand_signature_sector_t {
|
||||
u64 signature; // HAXXDUMP
|
||||
stdio_nand_desc_t nand_descriptions[NAND_MAX_DESC_TYPES];
|
||||
} __attribute__((packed)) sdio_nand_signature_sector_t;
|
||||
|
||||
int FSA_SDReadRawSectors(void *buffer, u32 sector, u32 num_sectors);
|
||||
|
||||
int FSA_SDWriteRawSectors(const void *buffer, u32 sector, u32 num_sectors);
|
||||
|
||||
#endif
|
||||
|
@ -32,13 +32,11 @@
|
||||
extern const patch_table_t mcp_patches_table[];
|
||||
extern const patch_table_t mcp_patches_table_end[];
|
||||
|
||||
u32 mcp_get_phys_code_base(void)
|
||||
{
|
||||
u32 mcp_get_phys_code_base(void) {
|
||||
return _text_start + MCP_CODE_BASE_PHYS_ADDR;
|
||||
}
|
||||
|
||||
void mcp_run_patches(u32 ios_elf_start)
|
||||
{
|
||||
void mcp_run_patches(u32 ios_elf_start) {
|
||||
// write ios_mcp code and bss
|
||||
section_write_bss(ios_elf_start, _bss_start, _bss_end - _bss_start);
|
||||
section_write(ios_elf_start, _text_start, (void *) mcp_get_phys_code_base(), _text_end - _text_start);
|
||||
|
@ -27,6 +27,7 @@
|
||||
#define MCP_LAUNCH_IMG_PHYS_ADDR (0x27000000)
|
||||
|
||||
u32 mcp_get_phys_code_base(void);
|
||||
|
||||
void mcp_run_patches(u32 ios_elf_start);
|
||||
|
||||
#endif
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "utils.h"
|
||||
|
||||
extern void __KERNEL_CODE_START(void);
|
||||
|
||||
extern void __KERNEL_CODE_END(void);
|
||||
|
||||
extern const patch_table_t kernel_patches_table[];
|
||||
@ -51,27 +52,21 @@ static const u32 KERNEL_MCP_IOMAPPINGS_STRUCT[] =
|
||||
0x00000001 // pid (MCP)
|
||||
};
|
||||
|
||||
static int kernel_syscall_0x81(u32 command, u32 arg1, u32 arg2, u32 arg3)
|
||||
{
|
||||
switch(command)
|
||||
{
|
||||
case KERNEL_READ32:
|
||||
{
|
||||
static int kernel_syscall_0x81(u32 command, u32 arg1, u32 arg2, u32 arg3) {
|
||||
switch (command) {
|
||||
case KERNEL_READ32: {
|
||||
return *(volatile u32 *) arg1;
|
||||
}
|
||||
case KERNEL_WRITE32:
|
||||
{
|
||||
case KERNEL_WRITE32: {
|
||||
*(volatile u32 *) arg1 = arg2;
|
||||
break;
|
||||
}
|
||||
case KERNEL_MEMCPY:
|
||||
{
|
||||
case KERNEL_MEMCPY: {
|
||||
//set_domain_register(0xFFFFFFFF);
|
||||
kernel_memcpy((void *) arg1, (void *) arg2, arg3);
|
||||
break;
|
||||
}
|
||||
case KERNEL_GET_CFW_CONFIG:
|
||||
{
|
||||
case KERNEL_GET_CFW_CONFIG: {
|
||||
//set_domain_register(0xFFFFFFFF);
|
||||
//kernel_memcpy((void*)arg1, &cfw_config, sizeof(cfw_config));
|
||||
break;
|
||||
@ -82,12 +77,10 @@ static int kernel_syscall_0x81(u32 command, u32 arg1, u32 arg2, u32 arg3)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kernel_launch_ios(u32 launch_address, u32 L, u32 C, u32 H)
|
||||
{
|
||||
void kernel_launch_ios(u32 launch_address, u32 L, u32 C, u32 H) {
|
||||
void (*kernel_launch_bootrom)(u32 launch_address, u32 L, u32 C, u32 H) = (void *) 0x0812A050;
|
||||
|
||||
if(*(u32*)(launch_address - 0x300 + 0x1AC) == 0x00DFD000)
|
||||
{
|
||||
if (*(u32 *) (launch_address - 0x300 + 0x1AC) == 0x00DFD000) {
|
||||
int level = disable_interrupts();
|
||||
unsigned int control_register = disable_mmu();
|
||||
|
||||
@ -104,8 +97,7 @@ void kernel_launch_ios(u32 launch_address, u32 L, u32 C, u32 H)
|
||||
kernel_launch_bootrom(launch_address, L, C, H);
|
||||
}
|
||||
|
||||
void kernel_run_patches(u32 ios_elf_start)
|
||||
{
|
||||
void kernel_run_patches(u32 ios_elf_start) {
|
||||
section_write(ios_elf_start, (u32) __KERNEL_CODE_START, __KERNEL_CODE_START, __KERNEL_CODE_END - __KERNEL_CODE_START);
|
||||
section_write_word(ios_elf_start, 0x0812A120, ARM_BL(0x0812A120, kernel_launch_ios));
|
||||
|
||||
|
@ -25,7 +25,9 @@
|
||||
#define _KERNEL_PATCHES_H
|
||||
|
||||
int kernel_init_otp_buffer(u32 sd_sector, int tagValid);
|
||||
|
||||
void kernel_launch_ios(u32 launch_address, u32 L, u32 C, u32 H);
|
||||
|
||||
void kernel_run_patches(u32 ios_elf_start);
|
||||
|
||||
#endif
|
||||
|
@ -28,8 +28,7 @@
|
||||
|
||||
#define USB_PHYS_CODE_BASE 0x101312D0
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
u32 size;
|
||||
u8 data[0];
|
||||
} payload_info_t;
|
||||
@ -58,8 +57,7 @@ static const char repairData_usb_root_thread[] = {
|
||||
0xE5, 0x9F, 0x0E, 0x68, 0xEB, 0x00, 0xB3, 0x20,
|
||||
};
|
||||
|
||||
int _main()
|
||||
{
|
||||
int _main() {
|
||||
void (*invalidate_icache)() = (void (*)()) 0x0812DCF0;
|
||||
void (*invalidate_dcache)(unsigned int, unsigned int) = (void (*)()) 0x08120164;
|
||||
void (*flush_dcache)(unsigned int, unsigned int) = (void (*)()) 0x08120160;
|
||||
|
@ -17,38 +17,28 @@
|
||||
|
||||
u32 *const framebuffer = (u32 *) FRAMEBUFFER_ADDRESS;
|
||||
|
||||
void clearScreen(u32 color)
|
||||
{
|
||||
void clearScreen(u32 color) {
|
||||
int i;
|
||||
for(i = 0; i < 896 * 504; i++)
|
||||
{
|
||||
for (i = 0; i < 896 * 504; i++) {
|
||||
framebuffer[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
void drawCharacter(char c, int x, int y)
|
||||
{
|
||||
void drawCharacter(char c, int x, int y) {
|
||||
if (c < 32)return;
|
||||
c -= 32;
|
||||
u8 *charData = (u8 *) &font_bin[(int) c << 3];
|
||||
u32 *fb = &framebuffer[x + y * FRAMEBUFFER_STRIDE_WORDS];
|
||||
int i, j, n, k;
|
||||
for(i = 0; i < CHAR_SIZE_Y; i++)
|
||||
{
|
||||
for(k = 0; k < CHAR_MULT; k++)
|
||||
{
|
||||
for (i = 0; i < CHAR_SIZE_Y; i++) {
|
||||
for (k = 0; k < CHAR_MULT; k++) {
|
||||
u8 v = *charData;
|
||||
|
||||
for(j = 0; j < CHAR_SIZE_X; j++)
|
||||
{
|
||||
for(n = 0; n < CHAR_MULT; n++)
|
||||
{
|
||||
if(v & 1)
|
||||
{
|
||||
for (j = 0; j < CHAR_SIZE_X; j++) {
|
||||
for (n = 0; n < CHAR_MULT; n++) {
|
||||
if (v & 1) {
|
||||
*fb = 0x00000000;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*fb = 0xFFFFFFFF;
|
||||
}
|
||||
fb++;
|
||||
@ -61,28 +51,24 @@ void drawCharacter(char c, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
void drawString(char* str, int x, int y)
|
||||
{
|
||||
void drawString(char *str, int x, int y) {
|
||||
if (!str) return;
|
||||
int k;
|
||||
int dx = 0, dy = 0;
|
||||
for(k = 0; str[k]; k++)
|
||||
{
|
||||
for (k = 0; str[k]; k++) {
|
||||
if (str[k] >= 32 && str[k] < 128)
|
||||
drawCharacter(str[k], x + dx, y + dy);
|
||||
|
||||
dx += CHAR_SIZE_X * CHAR_MULT;
|
||||
|
||||
if(str[k] == '\n')
|
||||
{
|
||||
if (str[k] == '\n') {
|
||||
dx = 0;
|
||||
dy -= CHAR_SIZE_Y * CHAR_MULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _printf(int x, int y, const char *format, ...)
|
||||
{
|
||||
void _printf(int x, int y, const char *format, ...) {
|
||||
void (*kernel_vsnprintf)(char *s, size_t n, const char *format, va_list arg) = (void *) 0x0813293C;
|
||||
|
||||
va_list args;
|
||||
|
@ -4,8 +4,11 @@
|
||||
#include "types.h"
|
||||
|
||||
void drawSplashScreen(void);
|
||||
|
||||
void clearScreen(u32 color);
|
||||
|
||||
void drawString(char *str, int x, int y);
|
||||
|
||||
void _printf(int x, int y, const char *format, ...);
|
||||
|
||||
#endif
|
||||
|
@ -23,20 +23,17 @@
|
||||
***************************************************************************/
|
||||
|
||||
// this memcpy is optimized for speed and to work with MEM1 32 bit access alignment requirement
|
||||
void reverse_memcpy(void* dst, const void* src, unsigned int size)
|
||||
{
|
||||
void reverse_memcpy(void *dst, const void *src, unsigned int size) {
|
||||
const unsigned char *src_p;
|
||||
unsigned char *dst_p;
|
||||
|
||||
if((size >= 4) && !((dst - src) & 3))
|
||||
{
|
||||
if ((size >= 4) && !((dst - src) & 3)) {
|
||||
const unsigned int *src_p32;
|
||||
unsigned int *dst_p32;
|
||||
unsigned int endDst = ((unsigned int) dst) + size;
|
||||
unsigned int endRest = endDst & 3;
|
||||
|
||||
if(endRest)
|
||||
{
|
||||
if (endRest) {
|
||||
src_p = ((const unsigned char *) (src + size)) - 1;
|
||||
dst_p = ((unsigned char *) endDst) - 1;
|
||||
size -= endRest;
|
||||
@ -49,12 +46,10 @@ void reverse_memcpy(void* dst, const void* src, unsigned int size)
|
||||
dst_p32 = ((unsigned int *) (dst + size)) - 1;
|
||||
|
||||
unsigned int size32 = size >> 5;
|
||||
if(size32)
|
||||
{
|
||||
if (size32) {
|
||||
size &= 0x1F;
|
||||
|
||||
while(size32--)
|
||||
{
|
||||
while (size32--) {
|
||||
src_p32 -= 8;
|
||||
dst_p32 -= 8;
|
||||
|
||||
@ -70,8 +65,7 @@ void reverse_memcpy(void* dst, const void* src, unsigned int size)
|
||||
}
|
||||
|
||||
unsigned int size4 = size >> 2;
|
||||
if(size4)
|
||||
{
|
||||
if (size4) {
|
||||
size &= 3;
|
||||
|
||||
while (size4--)
|
||||
@ -80,9 +74,7 @@ void reverse_memcpy(void* dst, const void* src, unsigned int size)
|
||||
|
||||
dst_p = ((unsigned char *) dst_p32) + 3;
|
||||
src_p = ((const unsigned char *) src_p32) + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dst_p = ((unsigned char *) dst) + size - 1;
|
||||
src_p = ((const unsigned char *) src) + size - 1;
|
||||
}
|
||||
|
@ -35,21 +35,18 @@
|
||||
|
||||
void reverse_memcpy(void *dest, const void *src, unsigned int size);
|
||||
|
||||
static inline unsigned int disable_mmu(void)
|
||||
{
|
||||
static inline unsigned int disable_mmu(void) {
|
||||
unsigned int control_register = 0;
|
||||
asm volatile("MRC p15, 0, %0, c1, c0, 0" : "=r" (control_register));
|
||||
asm volatile("MCR p15, 0, %0, c1, c0, 0" : : "r" (control_register & 0xFFFFEFFA));
|
||||
return control_register;
|
||||
}
|
||||
|
||||
static inline void restore_mmu(unsigned int control_register)
|
||||
{
|
||||
static inline void restore_mmu(unsigned int control_register) {
|
||||
asm volatile("MCR p15, 0, %0, c1, c0, 0" : : "r" (control_register));
|
||||
}
|
||||
|
||||
static inline void set_domain_register(unsigned int domain_register)
|
||||
{
|
||||
static inline void set_domain_register(unsigned int domain_register) {
|
||||
asm volatile("MCR p15, 0, %0, c3, c0, 0" : : "r" (domain_register));
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,7 @@
|
||||
#include "imports.h"
|
||||
#include "fsa.h"
|
||||
|
||||
static void* allocIobuf()
|
||||
{
|
||||
static void *allocIobuf() {
|
||||
void *ptr = svcAlloc(0xCAFF, 0x828);
|
||||
|
||||
memset(ptr, 0x00, 0x828);
|
||||
@ -14,13 +13,11 @@ static void* allocIobuf()
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void freeIobuf(void* ptr)
|
||||
{
|
||||
static void freeIobuf(void *ptr) {
|
||||
svcFree(0xCAFF, ptr);
|
||||
}
|
||||
|
||||
int FSA_Mount(int fd, char* device_path, char* volume_path, u32 flags, char* arg_string, int arg_string_len)
|
||||
{
|
||||
int FSA_Mount(int fd, char *device_path, char *volume_path, u32 flags, char *arg_string, int arg_string_len) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u8 *inbuf8 = iobuf;
|
||||
u8 *outbuf8 = &iobuf[0x520];
|
||||
@ -46,8 +43,7 @@ int FSA_Mount(int fd, char* device_path, char* volume_path, u32 flags, char* arg
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_Unmount(int fd, char* path, u32 flags)
|
||||
{
|
||||
int FSA_Unmount(int fd, char *path, u32 flags) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -61,8 +57,7 @@ int FSA_Unmount(int fd, char* path, u32 flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_MakeDir(int fd, char* path, u32 flags)
|
||||
{
|
||||
int FSA_MakeDir(int fd, char *path, u32 flags) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -76,8 +71,7 @@ int FSA_MakeDir(int fd, char* path, u32 flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_OpenDir(int fd, char* path, int* outHandle)
|
||||
{
|
||||
int FSA_OpenDir(int fd, char *path, int *outHandle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -92,8 +86,7 @@ int FSA_OpenDir(int fd, char* path, int* outHandle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_ReadDir(int fd, int handle, directoryEntry_s* out_data)
|
||||
{
|
||||
int FSA_ReadDir(int fd, int handle, directoryEntry_s *out_data) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -108,8 +101,7 @@ int FSA_ReadDir(int fd, int handle, directoryEntry_s* out_data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_RewindDir(int fd, int handle)
|
||||
{
|
||||
int FSA_RewindDir(int fd, int handle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -122,8 +114,7 @@ int FSA_RewindDir(int fd, int handle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_CloseDir(int fd, int handle)
|
||||
{
|
||||
int FSA_CloseDir(int fd, int handle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -136,8 +127,7 @@ int FSA_CloseDir(int fd, int handle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_ChangeDir(int fd, char* path)
|
||||
{
|
||||
int FSA_ChangeDir(int fd, char *path) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -150,8 +140,7 @@ int FSA_ChangeDir(int fd, char* path)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_OpenFile(int fd, char* path, char* mode, int* outHandle)
|
||||
{
|
||||
int FSA_OpenFile(int fd, char *path, char *mode, int *outHandle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -167,8 +156,7 @@ int FSA_OpenFile(int fd, char* path, char* mode, int* outHandle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _FSA_ReadWriteFile(int fd, void* data, u32 size, u32 cnt, int fileHandle, u32 flags, bool read)
|
||||
{
|
||||
int _FSA_ReadWriteFile(int fd, void *data, u32 size, u32 cnt, int fileHandle, u32 flags, bool read) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u8 *inbuf8 = iobuf;
|
||||
u8 *outbuf8 = &iobuf[0x520];
|
||||
@ -198,18 +186,15 @@ int _FSA_ReadWriteFile(int fd, void* data, u32 size, u32 cnt, int fileHandle, u3
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_ReadFile(int fd, void* data, u32 size, u32 cnt, int fileHandle, u32 flags)
|
||||
{
|
||||
int FSA_ReadFile(int fd, void *data, u32 size, u32 cnt, int fileHandle, u32 flags) {
|
||||
return _FSA_ReadWriteFile(fd, data, size, cnt, fileHandle, flags, true);
|
||||
}
|
||||
|
||||
int FSA_WriteFile(int fd, void* data, u32 size, u32 cnt, int fileHandle, u32 flags)
|
||||
{
|
||||
int FSA_WriteFile(int fd, void *data, u32 size, u32 cnt, int fileHandle, u32 flags) {
|
||||
return _FSA_ReadWriteFile(fd, data, size, cnt, fileHandle, flags, false);
|
||||
}
|
||||
|
||||
int FSA_StatFile(int fd, int handle, fileStat_s* out_data)
|
||||
{
|
||||
int FSA_StatFile(int fd, int handle, fileStat_s *out_data) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -224,8 +209,7 @@ int FSA_StatFile(int fd, int handle, fileStat_s* out_data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_CloseFile(int fd, int fileHandle)
|
||||
{
|
||||
int FSA_CloseFile(int fd, int fileHandle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -238,8 +222,7 @@ int FSA_CloseFile(int fd, int fileHandle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_SetPosFile(int fd, int fileHandle, u32 position)
|
||||
{
|
||||
int FSA_SetPosFile(int fd, int fileHandle, u32 position) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -253,8 +236,7 @@ int FSA_SetPosFile(int fd, int fileHandle, u32 position)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_GetStat(int fd, char *path, fileStat_s* out_data)
|
||||
{
|
||||
int FSA_GetStat(int fd, char *path, fileStat_s *out_data) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -270,8 +252,7 @@ int FSA_GetStat(int fd, char *path, fileStat_s* out_data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_Remove(int fd, char *path)
|
||||
{
|
||||
int FSA_Remove(int fd, char *path) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -284,8 +265,7 @@ int FSA_Remove(int fd, char *path)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_ChangeMode(int fd, char *path, int mode)
|
||||
{
|
||||
int FSA_ChangeMode(int fd, char *path, int mode) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -303,8 +283,7 @@ int FSA_ChangeMode(int fd, char *path, int mode)
|
||||
// type 4 :
|
||||
// 0x08 : device size in sectors (u64)
|
||||
// 0x10 : device sector size (u32)
|
||||
int FSA_GetDeviceInfo(int fd, char* device_path, int type, u32* out_data)
|
||||
{
|
||||
int FSA_GetDeviceInfo(int fd, char *device_path, int type, u32 *out_data) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -316,9 +295,10 @@ int FSA_GetDeviceInfo(int fd, char* device_path, int type, u32* out_data)
|
||||
|
||||
int size = 0;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case 0: case 1: case 7:
|
||||
switch (type) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 7:
|
||||
size = 0x8;
|
||||
break;
|
||||
case 2:
|
||||
@ -333,7 +313,8 @@ int FSA_GetDeviceInfo(int fd, char* device_path, int type, u32* out_data)
|
||||
case 5:
|
||||
size = 0x64;
|
||||
break;
|
||||
case 6: case 8:
|
||||
case 6:
|
||||
case 8:
|
||||
size = 0x14;
|
||||
break;
|
||||
}
|
||||
@ -344,8 +325,7 @@ int FSA_GetDeviceInfo(int fd, char* device_path, int type, u32* out_data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_RawOpen(int fd, char* device_path, int* outHandle)
|
||||
{
|
||||
int FSA_RawOpen(int fd, char *device_path, int *outHandle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -360,8 +340,7 @@ int FSA_RawOpen(int fd, char* device_path, int* outHandle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_RawClose(int fd, int device_handle)
|
||||
{
|
||||
int FSA_RawClose(int fd, int device_handle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) &iobuf[0x520];
|
||||
@ -375,8 +354,7 @@ int FSA_RawClose(int fd, int device_handle)
|
||||
}
|
||||
|
||||
// offset in blocks of 0x1000 bytes
|
||||
int FSA_RawRead(int fd, void* data, u32 size_bytes, u32 cnt, u64 blocks_offset, int device_handle)
|
||||
{
|
||||
int FSA_RawRead(int fd, void *data, u32 size_bytes, u32 cnt, u64 blocks_offset, int device_handle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u8 *inbuf8 = iobuf;
|
||||
u8 *outbuf8 = &iobuf[0x520];
|
||||
@ -406,8 +384,7 @@ int FSA_RawRead(int fd, void* data, u32 size_bytes, u32 cnt, u64 blocks_offset,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FSA_RawWrite(int fd, void* data, u32 size_bytes, u32 cnt, u64 blocks_offset, int device_handle)
|
||||
{
|
||||
int FSA_RawWrite(int fd, void *data, u32 size_bytes, u32 cnt, u64 blocks_offset, int device_handle) {
|
||||
u8 *iobuf = allocIobuf();
|
||||
u8 *inbuf8 = iobuf;
|
||||
u8 *outbuf8 = &iobuf[0x520];
|
||||
|
@ -1,8 +1,7 @@
|
||||
#ifndef FSA_H
|
||||
#define FSA_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
u32 flag;
|
||||
u32 permission;
|
||||
u32 owner_id;
|
||||
@ -16,8 +15,7 @@ typedef struct
|
||||
u32 unk2[0x0D];
|
||||
} fileStat_s;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
fileStat_s stat;
|
||||
char name[0x100];
|
||||
} directoryEntry_s;
|
||||
@ -30,30 +28,47 @@ typedef struct
|
||||
int FSA_Open();
|
||||
|
||||
int FSA_Mount(int fd, char *device_path, char *volume_path, u32 flags, char *arg_string, int arg_string_len);
|
||||
|
||||
int FSA_Unmount(int fd, char *path, u32 flags);
|
||||
|
||||
int FSA_GetDeviceInfo(int fd, char *device_path, int type, u32 *out_data);
|
||||
|
||||
int FSA_MakeDir(int fd, char *path, u32 flags);
|
||||
|
||||
int FSA_OpenDir(int fd, char *path, int *outHandle);
|
||||
|
||||
int FSA_ReadDir(int fd, int handle, directoryEntry_s *out_data);
|
||||
|
||||
int FSA_RewindDir(int fd, int handle);
|
||||
|
||||
int FSA_CloseDir(int fd, int handle);
|
||||
|
||||
int FSA_ChangeDir(int fd, char *path);
|
||||
|
||||
int FSA_OpenFile(int fd, char *path, char *mode, int *outHandle);
|
||||
|
||||
int FSA_ReadFile(int fd, void *data, u32 size, u32 cnt, int fileHandle, u32 flags);
|
||||
|
||||
int FSA_WriteFile(int fd, void *data, u32 size, u32 cnt, int fileHandle, u32 flags);
|
||||
|
||||
int FSA_StatFile(int fd, int handle, fileStat_s *out_data);
|
||||
|
||||
int FSA_CloseFile(int fd, int fileHandle);
|
||||
|
||||
int FSA_SetPosFile(int fd, int fileHandle, u32 position);
|
||||
|
||||
int FSA_GetStat(int fd, char *path, fileStat_s *out_data);
|
||||
|
||||
int FSA_Remove(int fd, char *path);
|
||||
|
||||
int FSA_ChangeMode(int fd, char *path, int mode);
|
||||
|
||||
int FSA_RawOpen(int fd, char *device_path, int *outHandle);
|
||||
|
||||
int FSA_RawRead(int fd, void *data, u32 size_bytes, u32 cnt, u64 sector_offset, int device_handle);
|
||||
|
||||
int FSA_RawWrite(int fd, void *data, u32 size_bytes, u32 cnt, u64 sector_offset, int device_handle);
|
||||
|
||||
int FSA_RawClose(int fd, int device_handle);
|
||||
|
||||
#endif
|
||||
|
@ -77,44 +77,30 @@
|
||||
static int ipcNodeKilled;
|
||||
static u8 threadStack[0x1000] __attribute__((aligned(0x20)));
|
||||
|
||||
static int ipc_ioctl(ipcmessage *message)
|
||||
{
|
||||
static int ipc_ioctl(ipcmessage *message) {
|
||||
int res = 0;
|
||||
|
||||
switch(message->ioctl.command)
|
||||
{
|
||||
case IOCTL_MEM_WRITE:
|
||||
{
|
||||
if(message->ioctl.length_in < 4)
|
||||
{
|
||||
switch (message->ioctl.command) {
|
||||
case IOCTL_MEM_WRITE: {
|
||||
if (message->ioctl.length_in < 4) {
|
||||
res = IOS_ERROR_INVALID_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
memcpy((void *) message->ioctl.buffer_in[0], message->ioctl.buffer_in + 1, message->ioctl.length_in - 4);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IOCTL_MEM_READ:
|
||||
{
|
||||
if(message->ioctl.length_in < 4)
|
||||
{
|
||||
case IOCTL_MEM_READ: {
|
||||
if (message->ioctl.length_in < 4) {
|
||||
res = IOS_ERROR_INVALID_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
memcpy(message->ioctl.buffer_io, (void *) message->ioctl.buffer_in[0], message->ioctl.length_io);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IOCTL_SVC:
|
||||
{
|
||||
if((message->ioctl.length_in < 4) || (message->ioctl.length_io < 4))
|
||||
{
|
||||
case IOCTL_SVC: {
|
||||
if ((message->ioctl.length_in < 4) || (message->ioctl.length_io < 4)) {
|
||||
res = IOS_ERROR_INVALID_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int svc_id = message->ioctl.buffer_in[0];
|
||||
int size_arguments = message->ioctl.length_in - 4;
|
||||
|
||||
@ -123,36 +109,28 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
memcpy(arguments, message->ioctl.buffer_in + 1, (size_arguments < 8 * 4) ? size_arguments : (8 * 4));
|
||||
|
||||
// return error code as data
|
||||
message->ioctl.buffer_io[0] = ((int (*const)(u32, u32, u32, u32, u32, u32, u32, u32))(MCP_SVC_BASE + svc_id * 8))(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7]);
|
||||
message->ioctl.buffer_io[0] = ((int (*const)(u32, u32, u32, u32, u32, u32, u32, u32)) (MCP_SVC_BASE + svc_id * 8))(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6],
|
||||
arguments[7]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IOCTL_KILL_SERVER:
|
||||
{
|
||||
case IOCTL_KILL_SERVER: {
|
||||
ipcNodeKilled = 1;
|
||||
wupserver_deinit();
|
||||
break;
|
||||
}
|
||||
case IOCTL_MEMCPY:
|
||||
{
|
||||
if(message->ioctl.length_in < 12)
|
||||
{
|
||||
case IOCTL_MEMCPY: {
|
||||
if (message->ioctl.length_in < 12) {
|
||||
res = IOS_ERROR_INVALID_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
memcpy((void *) message->ioctl.buffer_in[0], (void *) message->ioctl.buffer_in[1], message->ioctl.buffer_in[2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IOCTL_REPEATED_WRITE:
|
||||
{
|
||||
if(message->ioctl.length_in < 12)
|
||||
{
|
||||
case IOCTL_REPEATED_WRITE: {
|
||||
if (message->ioctl.length_in < 12) {
|
||||
res = IOS_ERROR_INVALID_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
u32 *dst = (u32 *) message->ioctl.buffer_in[0];
|
||||
u32 *cache_range = (u32 *) (message->ioctl.buffer_in[0] & ~0xFF);
|
||||
u32 value = message->ioctl.buffer_in[1];
|
||||
@ -160,19 +138,15 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
|
||||
u32 old = *dst;
|
||||
int i;
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
if(*dst != old)
|
||||
{
|
||||
for (i = 0; i < n; i++) {
|
||||
if (*dst != old) {
|
||||
if (*dst == 0x0) old = *dst;
|
||||
else
|
||||
{
|
||||
else {
|
||||
*dst = value;
|
||||
svcFlushDCache(cache_range, 0x100);
|
||||
break;
|
||||
}
|
||||
}else
|
||||
{
|
||||
} else {
|
||||
svcInvalidateDCache(cache_range, 0x100);
|
||||
usleep(50);
|
||||
}
|
||||
@ -180,23 +154,17 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IOCTL_KERN_READ32:
|
||||
{
|
||||
if((message->ioctl.length_in < 4) || (message->ioctl.length_io < 4))
|
||||
{
|
||||
case IOCTL_KERN_READ32: {
|
||||
if ((message->ioctl.length_in < 4) || (message->ioctl.length_io < 4)) {
|
||||
res = IOS_ERROR_INVALID_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(u32 i = 0; i < (message->ioctl.length_io/4); i++)
|
||||
{
|
||||
} else {
|
||||
for (u32 i = 0; i < (message->ioctl.length_io / 4); i++) {
|
||||
message->ioctl.buffer_io[i] = svcCustomKernelCommand(KERNEL_READ32, message->ioctl.buffer_in[0] + i * 4);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IOCTL_KERN_WRITE32:
|
||||
{
|
||||
case IOCTL_KERN_WRITE32: {
|
||||
//! TODO: add syscall as on kern_read32
|
||||
res = IOS_ERROR_NOEXISTS;
|
||||
break;
|
||||
@ -205,19 +173,16 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
//! FSA handles for better performance
|
||||
//!--------------------------------------------------------------------------------------------------------------
|
||||
//! TODO: add checks for i/o buffer length
|
||||
case IOCTL_FSA_OPEN:
|
||||
{
|
||||
case IOCTL_FSA_OPEN: {
|
||||
message->ioctl.buffer_io[0] = svcOpen("/dev/fsa", 0);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_CLOSE:
|
||||
{
|
||||
case IOCTL_FSA_CLOSE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
message->ioctl.buffer_io[0] = svcClose(fd);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_MOUNT:
|
||||
{
|
||||
case IOCTL_FSA_MOUNT: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *device_path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
char *volume_path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[2];
|
||||
@ -228,8 +193,7 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_Mount(fd, device_path, volume_path, flags, arg_string, arg_string_len);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_UNMOUNT:
|
||||
{
|
||||
case IOCTL_FSA_UNMOUNT: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *device_path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
u32 flags = message->ioctl.buffer_in[2];
|
||||
@ -237,8 +201,7 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_Unmount(fd, device_path, flags);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_GETDEVICEINFO:
|
||||
{
|
||||
case IOCTL_FSA_GETDEVICEINFO: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *device_path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
int type = message->ioctl.buffer_in[2];
|
||||
@ -246,32 +209,28 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_GetDeviceInfo(fd, device_path, type, message->ioctl.buffer_io + 1);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_OPENDIR:
|
||||
{
|
||||
case IOCTL_FSA_OPENDIR: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_OpenDir(fd, path, (int *) message->ioctl.buffer_io + 1);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_READDIR:
|
||||
{
|
||||
case IOCTL_FSA_READDIR: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
int handle = message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_ReadDir(fd, handle, (directoryEntry_s *) (message->ioctl.buffer_io + 1));
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_CLOSEDIR:
|
||||
{
|
||||
case IOCTL_FSA_CLOSEDIR: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
int handle = message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_CloseDir(fd, handle);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_MAKEDIR:
|
||||
{
|
||||
case IOCTL_FSA_MAKEDIR: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
u32 flags = message->ioctl.buffer_in[2];
|
||||
@ -279,8 +238,7 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_MakeDir(fd, path, flags);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_OPENFILE:
|
||||
{
|
||||
case IOCTL_FSA_OPENFILE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
char *mode = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[2];
|
||||
@ -288,8 +246,7 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_OpenFile(fd, path, mode, (int *) message->ioctl.buffer_io + 1);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_READFILE:
|
||||
{
|
||||
case IOCTL_FSA_READFILE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
u32 size = message->ioctl.buffer_in[1];
|
||||
u32 cnt = message->ioctl.buffer_in[2];
|
||||
@ -299,8 +256,7 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_ReadFile(fd, ((u8 *) message->ioctl.buffer_io) + 0x40, size, cnt, fileHandle, flags);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_WRITEFILE:
|
||||
{
|
||||
case IOCTL_FSA_WRITEFILE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
u32 size = message->ioctl.buffer_in[1];
|
||||
u32 cnt = message->ioctl.buffer_in[2];
|
||||
@ -310,24 +266,21 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_WriteFile(fd, ((u8 *) message->ioctl.buffer_in) + 0x40, size, cnt, fileHandle, flags);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_STATFILE:
|
||||
{
|
||||
case IOCTL_FSA_STATFILE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
int fileHandle = message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_StatFile(fd, fileHandle, (fileStat_s *) (message->ioctl.buffer_io + 1));
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_CLOSEFILE:
|
||||
{
|
||||
case IOCTL_FSA_CLOSEFILE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
int fileHandle = message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_CloseFile(fd, fileHandle);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_SETFILEPOS:
|
||||
{
|
||||
case IOCTL_FSA_SETFILEPOS: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
int fileHandle = message->ioctl.buffer_in[1];
|
||||
u32 position = message->ioctl.buffer_in[2];
|
||||
@ -335,48 +288,42 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_SetPosFile(fd, fileHandle, position);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_GETSTAT:
|
||||
{
|
||||
case IOCTL_FSA_GETSTAT: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_GetStat(fd, path, (fileStat_s *) (message->ioctl.buffer_io + 1));
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_REMOVE:
|
||||
{
|
||||
case IOCTL_FSA_REMOVE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_Remove(fd, path);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_REWINDDIR:
|
||||
{
|
||||
case IOCTL_FSA_REWINDDIR: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
int dirFd = message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_RewindDir(fd, dirFd);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_CHDIR:
|
||||
{
|
||||
case IOCTL_FSA_CHDIR: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_ChangeDir(fd, path);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_RAW_OPEN:
|
||||
{
|
||||
case IOCTL_FSA_RAW_OPEN: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_RawOpen(fd, path, (int *) (message->ioctl.buffer_io + 1));
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_RAW_READ:
|
||||
{
|
||||
case IOCTL_FSA_RAW_READ: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
u32 block_size = message->ioctl.buffer_in[1];
|
||||
u32 cnt = message->ioctl.buffer_in[2];
|
||||
@ -386,8 +333,7 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_RawRead(fd, ((u8 *) message->ioctl.buffer_io) + 0x40, block_size, cnt, sector_offset, deviceHandle);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_RAW_WRITE:
|
||||
{
|
||||
case IOCTL_FSA_RAW_WRITE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
u32 block_size = message->ioctl.buffer_in[1];
|
||||
u32 cnt = message->ioctl.buffer_in[2];
|
||||
@ -397,16 +343,14 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
message->ioctl.buffer_io[0] = FSA_RawWrite(fd, ((u8 *) message->ioctl.buffer_in) + 0x40, block_size, cnt, sector_offset, deviceHandle);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_RAW_CLOSE:
|
||||
{
|
||||
case IOCTL_FSA_RAW_CLOSE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
int deviceHandle = message->ioctl.buffer_in[1];
|
||||
|
||||
message->ioctl.buffer_io[0] = FSA_RawClose(fd, deviceHandle);
|
||||
break;
|
||||
}
|
||||
case IOCTL_FSA_CHANGEMODE:
|
||||
{
|
||||
case IOCTL_FSA_CHANGEMODE: {
|
||||
int fd = message->ioctl.buffer_in[0];
|
||||
char *path = ((char *) message->ioctl.buffer_in) + message->ioctl.buffer_in[1];
|
||||
int mode = message->ioctl.buffer_in[2];
|
||||
@ -422,53 +366,43 @@ static int ipc_ioctl(ipcmessage *message)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int ipc_thread(void *arg)
|
||||
{
|
||||
static int ipc_thread(void *arg) {
|
||||
int res;
|
||||
ipcmessage *message;
|
||||
u32 messageQueue[0x10];
|
||||
|
||||
int queueId = svcCreateMessageQueue(messageQueue, sizeof(messageQueue) / 4);
|
||||
|
||||
if(svcRegisterResourceManager("/dev/iosuhax", queueId) == 0)
|
||||
{
|
||||
while(!ipcNodeKilled)
|
||||
{
|
||||
if (svcRegisterResourceManager("/dev/iosuhax", queueId) == 0) {
|
||||
while (!ipcNodeKilled) {
|
||||
res = svcReceiveMessage(queueId, &message, 0);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
usleep(10000);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(message->command)
|
||||
{
|
||||
case IOS_OPEN:
|
||||
{
|
||||
switch (message->command) {
|
||||
case IOS_OPEN: {
|
||||
log_printf("IOS_OPEN\n");
|
||||
res = 0;
|
||||
break;
|
||||
}
|
||||
case IOS_CLOSE:
|
||||
{
|
||||
case IOS_CLOSE: {
|
||||
log_printf("IOS_CLOSE\n");
|
||||
res = 0;
|
||||
break;
|
||||
}
|
||||
case IOS_IOCTL:
|
||||
{
|
||||
case IOS_IOCTL: {
|
||||
log_printf("IOS_IOCTL\n");
|
||||
res = ipc_ioctl(message);
|
||||
break;
|
||||
}
|
||||
case IOS_IOCTLV:
|
||||
{
|
||||
case IOS_IOCTLV: {
|
||||
log_printf("IOS_IOCTLV\n");
|
||||
res = 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
log_printf("unexpected command 0x%X\n", message->command);
|
||||
res = IOS_ERROR_UNKNOWN_VALUE;
|
||||
break;
|
||||
@ -483,8 +417,7 @@ static int ipc_thread(void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ipc_init(void)
|
||||
{
|
||||
void ipc_init(void) {
|
||||
ipcNodeKilled = 0;
|
||||
|
||||
int threadId = svcCreateThread(ipc_thread, 0, (u32 *) (threadStack + sizeof(threadStack)), sizeof(threadStack), 0x78, 1);
|
||||
@ -492,11 +425,9 @@ void ipc_init(void)
|
||||
svcStartThread(threadId);
|
||||
}
|
||||
|
||||
void ipc_deinit(void)
|
||||
{
|
||||
void ipc_deinit(void) {
|
||||
int fd = svcOpen("/dev/iosuhax", 0);
|
||||
if(fd >= 0)
|
||||
{
|
||||
if (fd >= 0) {
|
||||
int dummy = 0;
|
||||
svcIoctl(fd, IOCTL_KILL_SERVER, &dummy, sizeof(dummy), &dummy, sizeof(dummy));
|
||||
svcClose(fd);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define _IPC_H_
|
||||
|
||||
void ipc_init();
|
||||
|
||||
void ipc_deinit();
|
||||
|
||||
#endif
|
||||
|
@ -21,8 +21,7 @@
|
||||
|
||||
|
||||
/* IPC message */
|
||||
typedef struct ipcmessage
|
||||
{
|
||||
typedef struct ipcmessage {
|
||||
u32 command;
|
||||
u32 result;
|
||||
u32 fd;
|
||||
@ -32,31 +31,26 @@ typedef struct ipcmessage
|
||||
u64 client_gid;
|
||||
u32 server_handle;
|
||||
|
||||
union
|
||||
{
|
||||
union {
|
||||
u32 args[5];
|
||||
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
char *device;
|
||||
u32 mode;
|
||||
u32 resultfd;
|
||||
} open;
|
||||
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
void *data;
|
||||
u32 length;
|
||||
} read, write;
|
||||
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
s32 offset;
|
||||
s32 origin;
|
||||
} seek;
|
||||
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
u32 command;
|
||||
|
||||
u32 *buffer_in;
|
||||
@ -64,8 +58,7 @@ typedef struct ipcmessage
|
||||
u32 *buffer_io;
|
||||
u32 length_io;
|
||||
} ioctl;
|
||||
struct _ioctlv
|
||||
{
|
||||
struct _ioctlv {
|
||||
u32 command;
|
||||
|
||||
u32 num_in;
|
||||
|
@ -9,10 +9,8 @@
|
||||
|
||||
static int threadsStarted = 0;
|
||||
|
||||
int _startMainThread(void)
|
||||
{
|
||||
if(threadsStarted == 0)
|
||||
{
|
||||
int _startMainThread(void) {
|
||||
if (threadsStarted == 0) {
|
||||
threadsStarted = 1;
|
||||
|
||||
wupserver_init();
|
||||
|
@ -25,9 +25,11 @@
|
||||
|
||||
int (*const real_MCP_LoadFile)(ipcmessage *msg) = (void *) 0x0501CAA8 + 1; //+1 for thumb
|
||||
int (*const MCP_DoLoadFile)(const char *path, const char *path2, void *outputBuffer, uint32_t outLength, uint32_t pos, int *bytesRead, uint32_t unk) = (void *) 0x05017248 + 1;
|
||||
|
||||
int (*const MCP_UnknownStuff)(const char *path, uint32_t pos, void *outputBuffer, uint32_t outLength, uint32_t outLength2, uint32_t unk) = (void *) 0x05014CAC + 1;
|
||||
|
||||
static int MCP_LoadCustomFile(int target, char *path, int filesize, int fileoffset, void *out_buffer, int buffer_len, int pos);
|
||||
|
||||
static bool skipPPCSetup = false;
|
||||
static bool didrpxfirstchunk = false;
|
||||
static bool doWantReplaceRPX = false;
|
||||
|
@ -6,14 +6,12 @@
|
||||
|
||||
static int ifmgrncl_handle = 0;
|
||||
|
||||
int ifmgrnclInit()
|
||||
{
|
||||
int ifmgrnclInit() {
|
||||
if (ifmgrncl_handle) return ifmgrncl_handle;
|
||||
|
||||
int ret = svcOpen("/dev/net/ifmgr/ncl", 0);
|
||||
|
||||
if(ret > 0)
|
||||
{
|
||||
if (ret > 0) {
|
||||
ifmgrncl_handle = ret;
|
||||
return ifmgrncl_handle;
|
||||
}
|
||||
@ -21,8 +19,7 @@ int ifmgrnclInit()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ifmgrnclExit()
|
||||
{
|
||||
int ifmgrnclExit() {
|
||||
int ret = svcClose(ifmgrncl_handle);
|
||||
|
||||
ifmgrncl_handle = 0;
|
||||
@ -30,8 +27,7 @@ int ifmgrnclExit()
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void* allocIobuf(u32 size)
|
||||
{
|
||||
static void *allocIobuf(u32 size) {
|
||||
void *ptr = svcAlloc(0xCAFF, size);
|
||||
|
||||
if (ptr) memset(ptr, 0x00, size);
|
||||
@ -39,13 +35,11 @@ static void* allocIobuf(u32 size)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void freeIobuf(void* ptr)
|
||||
{
|
||||
static void freeIobuf(void *ptr) {
|
||||
svcFree(0xCAFF, ptr);
|
||||
}
|
||||
|
||||
int IFMGRNCL_GetInterfaceStatus(u16 interface_id, u16* out_status)
|
||||
{
|
||||
int IFMGRNCL_GetInterfaceStatus(u16 interface_id, u16 *out_status) {
|
||||
u8 *iobuf1 = allocIobuf(0x2);
|
||||
u16 *inbuf = (u16 *) iobuf1;
|
||||
u8 *iobuf2 = allocIobuf(0x8);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "types.h"
|
||||
|
||||
int ifmgrnclInit();
|
||||
|
||||
int ifmgrnclExit();
|
||||
|
||||
int IFMGRNCL_GetInterfaceStatus(u16 interface_id, u16 *out_status);
|
||||
|
@ -8,14 +8,12 @@
|
||||
|
||||
static int socket_handle = 0;
|
||||
|
||||
int socketInit()
|
||||
{
|
||||
int socketInit() {
|
||||
if (socket_handle) return socket_handle;
|
||||
|
||||
int ret = svcOpen("/dev/socket", 0);
|
||||
|
||||
if(ret > 0)
|
||||
{
|
||||
if (ret > 0) {
|
||||
socket_handle = ret;
|
||||
return socket_handle;
|
||||
}
|
||||
@ -23,8 +21,7 @@ int socketInit()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int socketExit()
|
||||
{
|
||||
int socketExit() {
|
||||
int ret = svcClose(socket_handle);
|
||||
|
||||
socket_handle = 0;
|
||||
@ -32,8 +29,7 @@ int socketExit()
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void* allocIobuf(u32 size)
|
||||
{
|
||||
static void *allocIobuf(u32 size) {
|
||||
void *ptr = svcAlloc(0xCAFF, size);
|
||||
|
||||
if (ptr) memset(ptr, 0x00, size);
|
||||
@ -41,13 +37,11 @@ static void* allocIobuf(u32 size)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void freeIobuf(void* ptr)
|
||||
{
|
||||
static void freeIobuf(void *ptr) {
|
||||
svcFree(0xCAFF, ptr);
|
||||
}
|
||||
|
||||
int socket(int domain, int type, int protocol)
|
||||
{
|
||||
int socket(int domain, int type, int protocol) {
|
||||
u8 *iobuf = allocIobuf(0xC);
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
|
||||
@ -61,8 +55,7 @@ int socket(int domain, int type, int protocol)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int closesocket(int sockfd)
|
||||
{
|
||||
int closesocket(int sockfd) {
|
||||
u8 *iobuf = allocIobuf(0x4);
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
|
||||
@ -74,8 +67,7 @@ int closesocket(int sockfd)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
||||
{
|
||||
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
|
||||
u8 *iobuf = allocIobuf(0x18);
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
u32 *outbuf = (u32 *) inbuf;
|
||||
@ -84,14 +76,12 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
||||
|
||||
int ret = -1;
|
||||
|
||||
if(addr && addrlen && *addrlen == 0x10)
|
||||
{
|
||||
if (addr && addrlen && *addrlen == 0x10) {
|
||||
inbuf[5] = *addrlen;
|
||||
|
||||
ret = svcIoctl(socket_handle, 0x1, inbuf, 0x18, outbuf, 0x18);
|
||||
|
||||
if(ret >= 0)
|
||||
{
|
||||
if (ret >= 0) {
|
||||
memcpy(addr, &outbuf[1], outbuf[5]);
|
||||
*addrlen = outbuf[5];
|
||||
}
|
||||
@ -105,8 +95,7 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
if (addrlen != 0x10) return -1;
|
||||
|
||||
u8 *iobuf = allocIobuf(0x18);
|
||||
@ -122,8 +111,7 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
if (addrlen != 0x10) return -1;
|
||||
|
||||
u8 *iobuf = allocIobuf(0x18);
|
||||
@ -139,8 +127,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int listen(int sockfd, int backlog)
|
||||
{
|
||||
int listen(int sockfd, int backlog) {
|
||||
u8 *iobuf = allocIobuf(0x8);
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
|
||||
@ -153,8 +140,7 @@ int listen(int sockfd, int backlog)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int shutdown(int sockfd, int how)
|
||||
{
|
||||
int shutdown(int sockfd, int how) {
|
||||
u8 *iobuf = allocIobuf(0x8);
|
||||
u32 *inbuf = (u32 *) iobuf;
|
||||
|
||||
@ -167,8 +153,7 @@ int shutdown(int sockfd, int how)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int recv(int sockfd, void *buf, size_t len, int flags)
|
||||
{
|
||||
int recv(int sockfd, void *buf, size_t len, int flags) {
|
||||
if (!len) return -101;
|
||||
|
||||
// TODO : size checks, split up data into multiple vectors if necessary
|
||||
@ -189,8 +174,7 @@ int recv(int sockfd, void *buf, size_t len, int flags)
|
||||
|
||||
int ret = svcIoctlv(socket_handle, 0xC, 1, 3, iovec);
|
||||
|
||||
if(ret > 0 && buf)
|
||||
{
|
||||
if (ret > 0 && buf) {
|
||||
memcpy(buf, data_buf, ret);
|
||||
}
|
||||
|
||||
@ -199,8 +183,7 @@ int recv(int sockfd, void *buf, size_t len, int flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int send(int sockfd, const void *buf, size_t len, int flags)
|
||||
{
|
||||
int send(int sockfd, const void *buf, size_t len, int flags) {
|
||||
if (!buf || !len) return -101;
|
||||
|
||||
// TODO : size checks, split up data into multiple vectors if necessary
|
||||
|
@ -76,14 +76,12 @@
|
||||
typedef uint32_t socklen_t;
|
||||
typedef uint16_t sa_family_t;
|
||||
|
||||
struct sockaddr
|
||||
{
|
||||
struct sockaddr {
|
||||
sa_family_t sa_family;
|
||||
char sa_data[];
|
||||
};
|
||||
|
||||
struct sockaddr_storage
|
||||
{
|
||||
struct sockaddr_storage {
|
||||
sa_family_t ss_family;
|
||||
char __ss_padding[14];
|
||||
};
|
||||
@ -102,30 +100,45 @@ struct sockaddr_in {
|
||||
unsigned char sin_zero[8];
|
||||
};
|
||||
|
||||
struct linger
|
||||
{
|
||||
struct linger {
|
||||
int l_onoff;
|
||||
int l_linger;
|
||||
};
|
||||
|
||||
int socketInit();
|
||||
|
||||
int socketExit();
|
||||
|
||||
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
int closesocket(int sockfd);
|
||||
|
||||
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
|
||||
|
||||
int listen(int sockfd, int backlog);
|
||||
|
||||
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
|
||||
|
||||
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
|
||||
|
||||
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
|
||||
|
||||
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
|
||||
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
|
||||
|
||||
int shutdown(int sockfd, int how);
|
||||
|
||||
int socket(int domain, int type, int protocol);
|
||||
|
||||
int sockatmark(int sockfd);
|
||||
|
||||
#endif
|
||||
|
@ -3,30 +3,44 @@
|
||||
|
||||
#include "ipc_types.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
void *ptr;
|
||||
u32 len;
|
||||
u32 unk;
|
||||
} iovec_s;
|
||||
|
||||
void *svcAlloc(u32 heapid, u32 size);
|
||||
|
||||
void *svcAllocAlign(u32 heapid, u32 size, u32 align);
|
||||
|
||||
void svcFree(u32 heapid, void *ptr);
|
||||
|
||||
int svcOpen(char *name, int mode);
|
||||
|
||||
int svcClose(int fd);
|
||||
|
||||
int svcIoctl(int fd, u32 request, void *input_buffer, u32 input_buffer_len, void *output_buffer, u32 output_buffer_len);
|
||||
|
||||
int svcIoctlv(int fd, u32 request, u32 vector_count_in, u32 vector_count_out, iovec_s *vector);
|
||||
|
||||
int svcInvalidateDCache(void *address, u32 size);
|
||||
|
||||
int svcFlushDCache(void *address, u32 size);
|
||||
|
||||
int svcCreateThread(int (*callback)(void *arg), void *arg, u32 *stack_top, u32 stacksize, int priority, int detached);
|
||||
|
||||
int svcStartThread(int threadId);
|
||||
|
||||
int svcCreateMessageQueue(u32 *ptr, u32 n_msgs);
|
||||
|
||||
int svcDestroyMessageQueue(int queueid);
|
||||
|
||||
int svcRegisterResourceManager(const char *device, int queueid);
|
||||
|
||||
int svcReceiveMessage(int queueid, ipcmessage **ipc_buf, u32 flags);
|
||||
|
||||
int svcResourceReply(ipcmessage *ipc_message, u32 result);
|
||||
|
||||
int svcCustomKernelCommand(u32 command, ...);
|
||||
|
||||
#endif
|
||||
|
@ -15,26 +15,21 @@ static const u8 *launch_image_tga = (const u8*)0x27000000;
|
||||
|
||||
u32 *const framebuffer = (u32 *) FRAMEBUFFER_ADDRESS;
|
||||
|
||||
void drawSplashScreen(void)
|
||||
{
|
||||
void drawSplashScreen(void) {
|
||||
// check if it is an unmapped RGB tga
|
||||
if (*(u32 *) launch_image_tga != 0x00000200)
|
||||
return;
|
||||
|
||||
int i;
|
||||
for(i = 0; i < (896 * 504); i++)
|
||||
{
|
||||
for (i = 0; i < (896 * 504); i++) {
|
||||
u32 pixel;
|
||||
u32 pixelOffset = 0x12 + i * 2;
|
||||
// access only 4 byte aligned data as the file is in code section
|
||||
u32 dualPixel = *(u32 *) (launch_image_tga + (pixelOffset & ~3));
|
||||
|
||||
if((pixelOffset & 3) == 0)
|
||||
{
|
||||
if ((pixelOffset & 3) == 0) {
|
||||
pixel = ((dualPixel >> 24) & 0xFF) | (((dualPixel >> 16) & 0xFF) << 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pixel = ((dualPixel >> 8) & 0xFF) | ((dualPixel & 0xFF) << 8);
|
||||
}
|
||||
|
||||
@ -42,27 +37,22 @@ void drawSplashScreen(void)
|
||||
}
|
||||
}
|
||||
|
||||
void clearScreen(u32 color)
|
||||
{
|
||||
void clearScreen(u32 color) {
|
||||
int i;
|
||||
for(i = 0; i < 896 * 504; i++)
|
||||
{
|
||||
for (i = 0; i < 896 * 504; i++) {
|
||||
framebuffer[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
void drawCharacter(char c, int x, int y)
|
||||
{
|
||||
void drawCharacter(char c, int x, int y) {
|
||||
if (c < 32)return;
|
||||
c -= 32;
|
||||
u8 *charData = (u8 *) &font_bin[(CHAR_SIZE_X * CHAR_SIZE_Y * c) / 8];
|
||||
u32 *fb = &framebuffer[x + y * FRAMEBUFFER_STRIDE_WORDS];
|
||||
int i, j;
|
||||
for(i = 0; i < CHAR_SIZE_Y; i++)
|
||||
{
|
||||
for (i = 0; i < CHAR_SIZE_Y; i++) {
|
||||
u8 v = *(charData++);
|
||||
for(j = 0; j < CHAR_SIZE_X; j++)
|
||||
{
|
||||
for (j = 0; j < CHAR_SIZE_X; j++) {
|
||||
if (v & 1) *fb = 0x00000000;
|
||||
else *fb = 0xFFFFFFFF;
|
||||
v >>= 1;
|
||||
@ -72,27 +62,23 @@ void drawCharacter(char c, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
void drawString(char* str, int x, int y)
|
||||
{
|
||||
void drawString(char *str, int x, int y) {
|
||||
if (!str) return;
|
||||
int k;
|
||||
int dx = 0, dy = 0;
|
||||
for(k = 0; str[k]; k++)
|
||||
{
|
||||
for (k = 0; str[k]; k++) {
|
||||
if (str[k] >= 32 && str[k] < 128) drawCharacter(str[k], x + dx, y + dy);
|
||||
|
||||
dx += 8;
|
||||
|
||||
if(str[k] == '\n')
|
||||
{
|
||||
if (str[k] == '\n') {
|
||||
dx = 0;
|
||||
dy -= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print(int x, int y, const char *format, ...)
|
||||
{
|
||||
void print(int x, int y, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
|
@ -4,8 +4,11 @@
|
||||
#include "types.h"
|
||||
|
||||
void drawSplashScreen(void);
|
||||
|
||||
void clearScreen(u32 color);
|
||||
|
||||
void drawString(char *str, int x, int y);
|
||||
|
||||
void print(int x, int y, const char *format, ...);
|
||||
|
||||
#endif
|
||||
|
@ -16,14 +16,12 @@ static u8 threadStack[0x1000] __attribute__((aligned(0x20)));
|
||||
|
||||
// overwrites command_buffer with response
|
||||
// returns length of response (or 0 for no response, negative for error)
|
||||
static int serverCommandHandler(u32* command_buffer, u32 length)
|
||||
{
|
||||
static int serverCommandHandler(u32 *command_buffer, u32 length) {
|
||||
if (!command_buffer || !length) return -1;
|
||||
|
||||
int out_length = 4;
|
||||
|
||||
switch(command_buffer[0])
|
||||
{
|
||||
switch (command_buffer[0]) {
|
||||
case 0:
|
||||
// write
|
||||
// [cmd_id][addr]
|
||||
@ -90,19 +88,15 @@ static int serverCommandHandler(u32* command_buffer, u32 length)
|
||||
|
||||
u32 old = *dst;
|
||||
int i;
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
if(*dst != old)
|
||||
{
|
||||
for (i = 0; i < n; i++) {
|
||||
if (*dst != old) {
|
||||
if (*dst == 0x0) old = *dst;
|
||||
else
|
||||
{
|
||||
else {
|
||||
*dst = value;
|
||||
svcFlushDCache(cache_range, 0x100);
|
||||
break;
|
||||
}
|
||||
}else
|
||||
{
|
||||
} else {
|
||||
svcInvalidateDCache(cache_range, 0x100);
|
||||
usleep(50);
|
||||
}
|
||||
@ -120,23 +114,19 @@ static int serverCommandHandler(u32* command_buffer, u32 length)
|
||||
return out_length;
|
||||
}
|
||||
|
||||
static void serverClientHandler(int sock)
|
||||
{
|
||||
static void serverClientHandler(int sock) {
|
||||
u32 command_buffer[0x180];
|
||||
|
||||
while(!serverKilled)
|
||||
{
|
||||
while (!serverKilled) {
|
||||
int ret = recv(sock, command_buffer, sizeof(command_buffer), 0);
|
||||
|
||||
if (ret <= 0) break;
|
||||
|
||||
ret = serverCommandHandler(command_buffer, ret);
|
||||
|
||||
if(ret > 0)
|
||||
{
|
||||
if (ret > 0) {
|
||||
send(sock, command_buffer, ret, 0);
|
||||
}else if(ret < 0)
|
||||
{
|
||||
} else if (ret < 0) {
|
||||
send(sock, &ret, sizeof(int), 0);
|
||||
}
|
||||
}
|
||||
@ -144,8 +134,7 @@ static void serverClientHandler(int sock)
|
||||
closesocket(sock);
|
||||
}
|
||||
|
||||
static void serverListenClients()
|
||||
{
|
||||
static void serverListenClients() {
|
||||
serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
struct sockaddr_in server;
|
||||
@ -156,20 +145,17 @@ static void serverListenClients()
|
||||
server.sin_port = 1337;
|
||||
server.sin_addr.s_addr = 0;
|
||||
|
||||
if(bind(serverSocket, (struct sockaddr *)&server, sizeof(server)) < 0)
|
||||
{
|
||||
if (bind(serverSocket, (struct sockaddr *) &server, sizeof(server)) < 0) {
|
||||
closesocket(serverSocket);
|
||||
return;
|
||||
}
|
||||
|
||||
if(listen(serverSocket, 1) < 0)
|
||||
{
|
||||
if (listen(serverSocket, 1) < 0) {
|
||||
closesocket(serverSocket);
|
||||
return;
|
||||
}
|
||||
|
||||
while(!serverKilled)
|
||||
{
|
||||
while (!serverKilled) {
|
||||
int csock = accept(serverSocket, NULL, NULL);
|
||||
if (csock < 0)
|
||||
break;
|
||||
@ -181,16 +167,13 @@ static void serverListenClients()
|
||||
serverSocket = -1;
|
||||
}
|
||||
|
||||
static int wupserver_thread(void *arg)
|
||||
{
|
||||
while(ifmgrnclInit() <= 0)
|
||||
{
|
||||
static int wupserver_thread(void *arg) {
|
||||
while (ifmgrnclInit() <= 0) {
|
||||
//print(0, 0, "opening /dev/net/ifmgr/ncl...");
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
while(true)
|
||||
{
|
||||
while (true) {
|
||||
u16 out0, out1;
|
||||
|
||||
int ret0 = IFMGRNCL_GetInterfaceStatus(0, &out0);
|
||||
@ -204,8 +187,7 @@ static int wupserver_thread(void *arg)
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
while(socketInit() <= 0)
|
||||
{
|
||||
while (socketInit() <= 0) {
|
||||
//print(0, 0, "opening /dev/socket...");
|
||||
usleep(1000);
|
||||
}
|
||||
@ -220,14 +202,10 @@ static int wupserver_thread(void *arg)
|
||||
usleep(5 * 1000 * 1000);
|
||||
//print(0, 10, "attempting sockets !");
|
||||
|
||||
while(1)
|
||||
{
|
||||
if(!serverKilled)
|
||||
{
|
||||
while (1) {
|
||||
if (!serverKilled) {
|
||||
serverListenClients();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
usleep(1000 * 1000);
|
||||
@ -237,8 +215,7 @@ static int wupserver_thread(void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wupserver_init(void)
|
||||
{
|
||||
void wupserver_init(void) {
|
||||
serverSocket = -1;
|
||||
serverKilled = 0;
|
||||
|
||||
@ -247,8 +224,7 @@ void wupserver_init(void)
|
||||
svcStartThread(threadId);
|
||||
}
|
||||
|
||||
void wupserver_deinit(void)
|
||||
{
|
||||
void wupserver_deinit(void) {
|
||||
serverKilled = 1;
|
||||
shutdown(serverSocket, SHUT_RDWR);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define WUPSERVER_H
|
||||
|
||||
void wupserver_init(void);
|
||||
|
||||
void wupserver_deinit(void);
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,4 @@
|
||||
void _main()
|
||||
{
|
||||
void _main() {
|
||||
|
||||
void (*ios_shutdown)(int) = (void (*)(int)) 0x1012EE4C;
|
||||
|
||||
@ -22,5 +21,4 @@ void _main()
|
||||
"newpc: .word 0x10111164\n");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user