Upgrade to devkitPro v29 and reorganize

This commit is contained in:
BullyWiiPlaza 2017-09-28 22:02:23 +02:00
parent c431bce8dc
commit b59ef61113
59 changed files with 905 additions and 820 deletions

View File

@ -38,7 +38,8 @@ SOURCES := src \
src/kernel \
src/patcher \
src/system \
src/utils
src/utils \
src/tcpgecko
DATA :=
INCLUDES := src
@ -47,9 +48,9 @@ INCLUDES := src
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \
-O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
-O3 -Wall -Wextra -D_GNU_SOURCE -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
CXXFLAGS := -std=gnu++11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \
-O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
-O3 -Wall -Wextra -D_GNU_SOURCE -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
ASFLAGS := -mregnames
LDFLAGS := -nostartfiles -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,--gc-sections

View File

@ -11,10 +11,7 @@ No, you will run into incompatibility problems. It's not supported anymore but f
No. Both projects are fundamentally different.
# How do I compile?
Just like described [here](https://github.com/dimok789/homebrew_launcher/blob/master/README.md#building-the-homebrew-launcher).
Also note that you need `devkitPro r27` and not the latest version. Older versions like `r27` can be downloaded from [here](https://sourceforge.net/projects/devkitpro/files/devkitPPC/).
Furthermore, you need to `make install` [`iosuhax`](https://github.com/dimok789/libiosuhax) since it is a dependency as well.
Just like described [here](https://github.com/dimok789/homebrew_launcher/blob/master/README.md#building-the-homebrew-launcher). Furthermore, you need to `make install` [`iosuhax`](https://github.com/dimok789/libiosuhax) since it is a dependency as well.
# Credits
**dimok** for Homebrew Launcher project engine/base

View File

@ -3,7 +3,7 @@
<app>
<name>TCP Gecko</name>
<coder>BullyWiiPlaza, wj44, dimok, Chadderz, Marionumber1</coder>
<version>2.5</version>
<version>2.51</version>
<short_description>WiiU RAM Hacking</short_description>
<long_description>A memory editor that does magical things to your games. In order to develop and apply real-time
cheats use JGecko U.

View File

@ -2,7 +2,6 @@
#define FS_DEFS_H
#include "types.h"
#include "kernel_types.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,10 +0,0 @@
#pragma once
// typedef unsigned char u8;
// typedef unsigned int uint8_t;
// typedef unsigned short u16;
// typedef unsigned int uint16_t;
// typedef unsigned int u32;
// typedef unsigned int uint32_t;
// typedef unsigned long uint64_t;
// typedef unsigned long long u64;

View File

@ -1,7 +1,6 @@
#ifndef RETAINS_VARS_H_
#define RETAINS_VARS_H_
#include <gctypes.h>
#include "kernel_types.h"
extern u8 gSettingLaunchPyGecko;
extern u8 gSettingUseUpdatepath;

View File

@ -33,7 +33,7 @@ EXPORT_DECL(s32, AOC_CloseTitle, void * title);
void InitAocFunctionPointers(void)
{
unsigned int aoc_handle = 0;
u32 aoc_handle = 0;
OSDynLoad_Acquire("nn_aoc.rpl", &aoc_handle);
if(aoc_handle == 0)

View File

@ -48,7 +48,7 @@ EXPORT_DECL(void, AXSetVoiceLoopOffset, void *v, u32 offset);
void InitAXFunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int sound_handle;
u32 sound_handle;
OSDynLoad_Acquire("sndcore2.rpl", &sound_handle);
OS_FIND_EXPORT(sound_handle, AXInitWithParams);

View File

@ -70,12 +70,12 @@ EXPORT_DECL(int, FSRollbackQuota, void *pClient, void *pCmd, const char *path, i
EXPORT_DECL(int, FSRollbackQuotaAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
EXPORT_DECL(int, FSOpenDir, void *pClient, void *pCmd, const char *path, int *dh, int errHandling);
EXPORT_DECL(int, FSOpenDir, void *pClient, void *pCmd, const char *path, s32 *dh, int errHandling);
EXPORT_DECL(int, FSOpenDirAsync, void *pClient, void *pCmd, const char *path, int *handle, int error,
void *asyncParams);
EXPORT_DECL(int, FSReadDir, void *pClient, void *pCmd, int dh, FSDirEntry * dir_entry, int errHandling);
EXPORT_DECL(int, FSReadDir, void *pClient, void *pCmd, s32 dh, FSDirEntry * dir_entry, int errHandling);
EXPORT_DECL(int, FSRewindDir, void *pClient, void *pCmd, int dh, int errHandling);

View File

@ -80,11 +80,11 @@ extern int (*FSRollbackQuota)(void *pClient, void *pCmd, const char *path, int e
extern int (*FSRollbackQuotaAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
extern int (*FSOpenDir)(void *pClient, void *pCmd, const char *path, int *dh, int errHandling);
extern int (*FSOpenDir)(void *pClient, void *pCmd, const char *path, s32 *dh, int errHandling);
extern int (*FSOpenDirAsync)(void *pClient, void *pCmd, const char *path, int *handle, int error, void *asyncParams);
extern int (*FSReadDir)(void *pClient, void *pCmd, int dh, FSDirEntry *dir_entry, int errHandling);
extern int (*FSReadDir)(void *pClient, void *pCmd, s32 dh, FSDirEntry *dir_entry, int errHandling);
extern int (*FSRewindDir)(void *pClient, void *pCmd, int dh, int errHandling);

View File

@ -94,7 +94,7 @@ EXPORT_DECL(void, GX2RSetAllocator, void * (* allocFunc)(u32, u32, u32), void (*
void InitGX2FunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int gx2_handle;
u32 gx2_handle;
OSDynLoad_Acquire("gx2.rpl", &gx2_handle);
OS_FIND_EXPORT(gx2_handle, GX2Init);

View File

@ -24,7 +24,7 @@
#include "common/common.h"
#include "os_functions.h"
unsigned int coreinit_handle = 0;
u32 coreinit_handle = 0;
// unsigned int zlib_handle = 0;
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -96,7 +96,7 @@ typedef void *(*DisasmGetSym)(u32 addr, u8 *symbolName, u32 nameBufSize);
#define OS_MUTEX_SIZE 44
/* Handle for coreinit */
extern unsigned int coreinit_handle;
extern u32 coreinit_handle;
void InitOSFunctionPointers(void);

View File

@ -34,7 +34,7 @@ EXPORT_DECL(s32, KPADRead, s32 chan, void * data, u32 size);
void InitPadScoreFunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int padscore_handle;
u32 padscore_handle;
OSDynLoad_Acquire("padscore.rpl", &padscore_handle);
OS_FIND_EXPORT(padscore_handle, KPADInit);

View File

@ -43,11 +43,11 @@ EXPORT_DECL(int, inet_aton, const char *cp, struct in_addr *inp);
void InitSocketFunctionPointers(void)
{
unsigned int nsysnet_handle;
u32 nsysnet_handle;
unsigned int *funcPointer = 0;
OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);
unsigned int nn_ac_handle;
u32 nn_ac_handle;
int(*ACInitialize)();
int(*ACGetStartupId) (unsigned int *id);
int(*ACConnectWithConfigId) (unsigned int id);

View File

@ -31,7 +31,7 @@ EXPORT_DECL(int, SYSCheckTitleExists, u64 titleId);
void InitSysFunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int sysapp_handle;
u32 sysapp_handle;
OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);
OS_FIND_EXPORT(sysapp_handle, _SYSLaunchTitleByPathFromLauncher);

View File

@ -30,7 +30,7 @@ EXPORT_DECL(void, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *er
void InitVPadFunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int vpad_handle;
u32 vpad_handle;
OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
OS_FIND_EXPORT(vpad_handle, VPADInit);

View File

@ -1,13 +1,12 @@
#include "dynamic_libs/os_functions.h"
#include "dynamic_libs/gx2_functions.h"
#include "tcpgecko/main.h"
#include "tcpgecko/title.h"
#include "dynamic_libs/socket_functions.h"
#include "common/common.h"
#include "tcp_gecko.h"
#include "main.h"
#include "dynamic_libs/gx2_functions.h"
#include "utils/logger.h"
#include "title.h"
#include "tcpgecko/tcp_gecko.h"
#include "common/common.h"
int __entry_menu(int argc, char **argv) {
int entry() {
if (isRunningAllowedTitleID()) {
InitOSFunctionPointers();
InitSocketFunctionPointers();
@ -24,4 +23,8 @@ int __entry_menu(int argc, char **argv) {
//! * Jump to our application *
//! *******************************************************************
return Menu_Main();
}
int __entry_menu(int argc, char **argv) {
return entry();
}

View File

@ -29,10 +29,12 @@
#include <malloc.h>
#include <fcntl.h>
#include <stdio.h>
#include "dynamic_libs/fs_functions.h"
#include "dynamic_libs/os_functions.h"
#include "fs_utils.h"
#include "utils/logger.h"
#include "../dynamic_libs/fs_functions.h"
#include "../dynamic_libs/os_functions.h"
#include "fs_utils.h"
#include "../utils/logger.h"
#define FS_ALIGNMENT 0x40
#define FS_ALIGN(x) (((x) + FS_ALIGNMENT - 1) & ~(FS_ALIGNMENT - 1))
@ -62,7 +64,8 @@ typedef struct _sd_fat_dir_entry_t {
int dirHandle;
} sd_fat_dir_entry_t;
static sd_fat_private_t *sd_fat_get_device_data(const char *path) {
static sd_fat_private_t *sd_fat_get_device_data(const char *path)
{
const devoptab_t *devoptab = NULL;
char name[128] = {0};
int i;
@ -79,7 +82,7 @@ static sd_fat_private_t *sd_fat_get_device_data(const char *path) {
devoptab = devoptab_list[i];
if (devoptab && devoptab->name) {
if (strcmp(name, devoptab->name) == 0) {
return (sd_fat_private_t *) devoptab->deviceData;
return (sd_fat_private_t *)devoptab->deviceData;
}
}
}
@ -87,7 +90,8 @@ static sd_fat_private_t *sd_fat_get_device_data(const char *path) {
return NULL;
}
static char *sd_fat_real_path(const char *path, sd_fat_private_t *dev) {
static char *sd_fat_real_path (const char *path, sd_fat_private_t *dev)
{
// Sanity check
if (!path)
return NULL;
@ -99,8 +103,8 @@ static char *sd_fat_real_path(const char *path, sd_fat_private_t *dev) {
int mount_len = strlen(dev->mount_path);
char *new_name = (char *) malloc(mount_len + strlen(path) + 1);
if (new_name) {
char *new_name = (char*)malloc(mount_len + strlen(path) + 1);
if(new_name) {
strcpy(new_name, dev->mount_path);
strcpy(new_name + mount_len, path);
return new_name;
@ -108,14 +112,15 @@ static char *sd_fat_real_path(const char *path, sd_fat_private_t *dev) {
return new_name;
}
static int sd_fat_open_r(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) {
static int sd_fat_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode)
{
sd_fat_private_t *dev = sd_fat_get_device_data(path);
if (!dev) {
if(!dev) {
r->_errno = ENODEV;
return -1;
}
sd_fat_file_state_t *file = (sd_fat_file_state_t *) fileStruct;
sd_fat_file_state_t *file = (sd_fat_file_state_t *)fileStruct;
file->dev = dev;
// Determine which mode the file is opened for
@ -148,7 +153,7 @@ static int sd_fat_open_r(struct _reent *r, void *fileStruct, const char *path, i
OSLockMutex(dev->pMutex);
char *real_path = sd_fat_real_path(path, dev);
if (!path) {
if(!path) {
r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex);
return -1;
@ -158,10 +163,11 @@ static int sd_fat_open_r(struct _reent *r, void *fileStruct, const char *path, i
free(real_path);
if (result == 0) {
if(result == 0)
{
FSStat stats;
result = FSGetStatFile(dev->pClient, dev->pCmd, fd, &stats, -1);
if (result != 0) {
if(result != 0) {
FSCloseFile(dev->pClient, dev->pCmd, fd, -1);
r->_errno = result;
OSUnlockMutex(dev->pMutex);
@ -171,7 +177,7 @@ static int sd_fat_open_r(struct _reent *r, void *fileStruct, const char *path, i
file->pos = 0;
file->len = stats.size;
OSUnlockMutex(dev->pMutex);
return (int) file;
return (int)file;
}
r->_errno = result;
@ -180,9 +186,10 @@ static int sd_fat_open_r(struct _reent *r, void *fileStruct, const char *path, i
}
static int sd_fat_close_r(struct _reent *r, int fd) {
sd_fat_file_state_t *file = (sd_fat_file_state_t *) fd;
if (!file->dev) {
static int sd_fat_close_r (struct _reent *r, void *fd)
{
sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd;
if(!file->dev) {
r->_errno = ENODEV;
return -1;
}
@ -193,23 +200,26 @@ static int sd_fat_close_r(struct _reent *r, int fd) {
OSUnlockMutex(file->dev->pMutex);
if (result < 0) {
if(result < 0)
{
r->_errno = result;
return -1;
}
return 0;
}
static off_t sd_fat_seek_r(struct _reent *r, int fd, off_t pos, int dir) {
sd_fat_file_state_t *file = (sd_fat_file_state_t *) fd;
if (!file->dev) {
static off_t sd_fat_seek_r (struct _reent *r, void* fd, off_t pos, int dir)
{
sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd;
if(!file->dev) {
r->_errno = ENODEV;
return 0;
}
OSLockMutex(file->dev->pMutex);
switch (dir) {
switch(dir)
{
case SEEK_SET:
file->pos = pos;
break;
@ -228,21 +238,24 @@ static off_t sd_fat_seek_r(struct _reent *r, int fd, off_t pos, int dir) {
OSUnlockMutex(file->dev->pMutex);
if (result == 0) {
if(result == 0)
{
return file->pos;
}
return result;
}
static ssize_t sd_fat_write_r(struct _reent *r, int fd, const char *ptr, size_t len) {
sd_fat_file_state_t *file = (sd_fat_file_state_t *) fd;
if (!file->dev) {
static ssize_t sd_fat_write_r (struct _reent *r, void *fd, const char *ptr, size_t len)
{
sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd;
if(!file->dev) {
r->_errno = ENODEV;
return 0;
}
if (!file->write) {
if(!file->write)
{
r->_errno = EACCES;
return 0;
}
@ -250,11 +263,11 @@ static ssize_t sd_fat_write_r(struct _reent *r, int fd, const char *ptr, size_t
OSLockMutex(file->dev->pMutex);
size_t len_aligned = FS_ALIGN(len);
if (len_aligned > 0x4000)
if(len_aligned > 0x4000)
len_aligned = 0x4000;
unsigned char *tmpBuf = (unsigned char *) memalign(FS_ALIGNMENT, len_aligned);
if (!tmpBuf) {
unsigned char *tmpBuf = (unsigned char *)memalign(FS_ALIGNMENT, len_aligned);
if(!tmpBuf) {
r->_errno = ENOMEM;
OSUnlockMutex(file->dev->pMutex);
return 0;
@ -262,19 +275,25 @@ static ssize_t sd_fat_write_r(struct _reent *r, int fd, const char *ptr, size_t
size_t done = 0;
while (done < len) {
while(done < len)
{
size_t write_size = (len_aligned < (len - done)) ? len_aligned : (len - done);
memcpy(tmpBuf, ptr + done, write_size);
int result = FSWriteFile(file->dev->pClient, file->dev->pCmd, tmpBuf, 0x01, write_size, file->fd, 0, -1);
if (result < 0) {
if(result < 0)
{
r->_errno = result;
break;
} else if (result == 0) {
if (write_size > 0)
}
else if(result == 0)
{
if(write_size > 0)
done = 0;
break;
} else {
}
else
{
done += result;
file->pos += result;
}
@ -285,14 +304,16 @@ static ssize_t sd_fat_write_r(struct _reent *r, int fd, const char *ptr, size_t
return done;
}
static ssize_t sd_fat_read_r(struct _reent *r, int fd, char *ptr, size_t len) {
sd_fat_file_state_t *file = (sd_fat_file_state_t *) fd;
if (!file->dev) {
static ssize_t sd_fat_read_r (struct _reent *r, void* fd, char *ptr, size_t len)
{
sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd;
if(!file->dev) {
r->_errno = ENODEV;
return 0;
}
if (!file->read) {
if(!file->read)
{
r->_errno = EACCES;
return 0;
}
@ -300,11 +321,11 @@ static ssize_t sd_fat_read_r(struct _reent *r, int fd, char *ptr, size_t len) {
OSLockMutex(file->dev->pMutex);
size_t len_aligned = FS_ALIGN(len);
if (len_aligned > 0x4000)
if(len_aligned > 0x4000)
len_aligned = 0x4000;
unsigned char *tmpBuf = (unsigned char *) memalign(FS_ALIGNMENT, len_aligned);
if (!tmpBuf) {
unsigned char *tmpBuf = (unsigned char *)memalign(FS_ALIGNMENT, len_aligned);
if(!tmpBuf) {
r->_errno = ENOMEM;
OSUnlockMutex(file->dev->pMutex);
return 0;
@ -312,18 +333,24 @@ static ssize_t sd_fat_read_r(struct _reent *r, int fd, char *ptr, size_t len) {
size_t done = 0;
while (done < len) {
while(done < len)
{
size_t read_size = (len_aligned < (len - done)) ? len_aligned : (len - done);
int result = FSReadFile(file->dev->pClient, file->dev->pCmd, tmpBuf, 0x01, read_size, file->fd, 0, -1);
if (result < 0) {
if(result < 0)
{
r->_errno = result;
done = 0;
break;
} else if (result == 0) {
}
else if(result == 0)
{
//! TODO: error on read_size > 0
break;
} else {
}
else
{
memcpy(ptr + done, tmpBuf, read_size);
done += result;
file->pos += result;
@ -336,9 +363,10 @@ static ssize_t sd_fat_read_r(struct _reent *r, int fd, char *ptr, size_t len) {
}
static int sd_fat_fstat_r(struct _reent *r, int fd, struct stat *st) {
sd_fat_file_state_t *file = (sd_fat_file_state_t *) fd;
if (!file->dev) {
static int sd_fat_fstat_r (struct _reent *r, void* fd, struct stat *st)
{
sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd;
if(!file->dev) {
r->_errno = ENODEV;
return -1;
}
@ -350,7 +378,7 @@ static int sd_fat_fstat_r(struct _reent *r, int fd, struct stat *st) {
FSStat stats;
int result = FSGetStatFile(file->dev->pClient, file->dev->pCmd, file->fd, &stats, -1);
if (result != 0) {
if(result != 0) {
r->_errno = result;
OSUnlockMutex(file->dev->pMutex);
return -1;
@ -373,9 +401,10 @@ static int sd_fat_fstat_r(struct _reent *r, int fd, struct stat *st) {
return 0;
}
static int sd_fat_ftruncate_r(struct _reent *r, int fd, off_t len) {
sd_fat_file_state_t *file = (sd_fat_file_state_t *) fd;
if (!file->dev) {
static int sd_fat_ftruncate_r (struct _reent *r, void* fd, off_t len)
{
sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd;
if(!file->dev) {
r->_errno = ENODEV;
return -1;
}
@ -386,7 +415,7 @@ static int sd_fat_ftruncate_r(struct _reent *r, int fd, off_t len) {
OSUnlockMutex(file->dev->pMutex);
if (result < 0) {
if(result < 0) {
r->_errno = result;
return -1;
}
@ -394,9 +423,10 @@ static int sd_fat_ftruncate_r(struct _reent *r, int fd, off_t len) {
return 0;
}
static int sd_fat_fsync_r(struct _reent *r, int fd) {
sd_fat_file_state_t *file = (sd_fat_file_state_t *) fd;
if (!file->dev) {
static int sd_fat_fsync_r (struct _reent *r, void* fd)
{
sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd;
if(!file->dev) {
r->_errno = ENODEV;
return -1;
}
@ -407,7 +437,7 @@ static int sd_fat_fsync_r(struct _reent *r, int fd) {
OSUnlockMutex(file->dev->pMutex);
if (result < 0) {
if(result < 0) {
r->_errno = result;
return -1;
}
@ -415,9 +445,10 @@ static int sd_fat_fsync_r(struct _reent *r, int fd) {
return 0;
}
static int sd_fat_stat_r(struct _reent *r, const char *path, struct stat *st) {
static int sd_fat_stat_r (struct _reent *r, const char *path, struct stat *st)
{
sd_fat_private_t *dev = sd_fat_get_device_data(path);
if (!dev) {
if(!dev) {
r->_errno = ENODEV;
return -1;
}
@ -428,7 +459,7 @@ static int sd_fat_stat_r(struct _reent *r, const char *path, struct stat *st) {
memset(st, 0, sizeof(struct stat));
char *real_path = sd_fat_real_path(path, dev);
if (!real_path) {
if(!real_path) {
r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex);
return -1;
@ -440,14 +471,14 @@ static int sd_fat_stat_r(struct _reent *r, const char *path, struct stat *st) {
free(real_path);
if (result < 0) {
if(result < 0) {
r->_errno = result;
OSUnlockMutex(dev->pMutex);
return -1;
}
// mark root also as directory
st->st_mode = ((stats.flag & 0x80000000) || (strlen(dev->mount_path) + 1 == strlen(real_path))) ? S_IFDIR : S_IFREG;
st->st_mode = ((stats.flag & 0x80000000) || (strlen(dev->mount_path) + 1 == strlen(real_path)))? S_IFDIR : S_IFREG;
st->st_nlink = 1;
st->st_size = stats.size;
st->st_blocks = (stats.size + 511) >> 9;
@ -465,14 +496,16 @@ static int sd_fat_stat_r(struct _reent *r, const char *path, struct stat *st) {
return 0;
}
static int sd_fat_link_r(struct _reent *r, const char *existing, const char *newLink) {
static int sd_fat_link_r (struct _reent *r, const char *existing, const char *newLink)
{
r->_errno = ENOTSUP;
return -1;
}
static int sd_fat_unlink_r(struct _reent *r, const char *name) {
static int sd_fat_unlink_r (struct _reent *r, const char *name)
{
sd_fat_private_t *dev = sd_fat_get_device_data(name);
if (!dev) {
if(!dev) {
r->_errno = ENODEV;
return -1;
}
@ -480,7 +513,7 @@ static int sd_fat_unlink_r(struct _reent *r, const char *name) {
OSLockMutex(dev->pMutex);
char *real_path = sd_fat_real_path(name, dev);
if (!real_path) {
if(!real_path) {
r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex);
return -1;
@ -493,7 +526,7 @@ static int sd_fat_unlink_r(struct _reent *r, const char *name) {
OSUnlockMutex(dev->pMutex);
if (result < 0) {
if(result < 0) {
r->_errno = result;
return -1;
}
@ -501,9 +534,10 @@ static int sd_fat_unlink_r(struct _reent *r, const char *name) {
return 0;
}
static int sd_fat_chdir_r(struct _reent *r, const char *name) {
static int sd_fat_chdir_r (struct _reent *r, const char *name)
{
sd_fat_private_t *dev = sd_fat_get_device_data(name);
if (!dev) {
if(!dev) {
r->_errno = ENODEV;
return -1;
}
@ -511,7 +545,7 @@ static int sd_fat_chdir_r(struct _reent *r, const char *name) {
OSLockMutex(dev->pMutex);
char *real_path = sd_fat_real_path(name, dev);
if (!real_path) {
if(!real_path) {
r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex);
return -1;
@ -523,7 +557,7 @@ static int sd_fat_chdir_r(struct _reent *r, const char *name) {
OSUnlockMutex(dev->pMutex);
if (result < 0) {
if(result < 0) {
r->_errno = result;
return -1;
}
@ -531,9 +565,10 @@ static int sd_fat_chdir_r(struct _reent *r, const char *name) {
return 0;
}
static int sd_fat_rename_r(struct _reent *r, const char *oldName, const char *newName) {
static int sd_fat_rename_r (struct _reent *r, const char *oldName, const char *newName)
{
sd_fat_private_t *dev = sd_fat_get_device_data(oldName);
if (!dev) {
if(!dev) {
r->_errno = ENODEV;
return -1;
}
@ -541,13 +576,13 @@ static int sd_fat_rename_r(struct _reent *r, const char *oldName, const char *ne
OSLockMutex(dev->pMutex);
char *real_oldpath = sd_fat_real_path(oldName, dev);
if (!real_oldpath) {
if(!real_oldpath) {
r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex);
return -1;
}
char *real_newpath = sd_fat_real_path(newName, dev);
if (!real_newpath) {
if(!real_newpath) {
r->_errno = ENOMEM;
free(real_oldpath);
OSUnlockMutex(dev->pMutex);
@ -561,7 +596,7 @@ static int sd_fat_rename_r(struct _reent *r, const char *oldName, const char *ne
OSUnlockMutex(dev->pMutex);
if (result < 0) {
if(result < 0) {
r->_errno = result;
return -1;
}
@ -570,9 +605,10 @@ static int sd_fat_rename_r(struct _reent *r, const char *oldName, const char *ne
}
static int sd_fat_mkdir_r(struct _reent *r, const char *path, int mode) {
static int sd_fat_mkdir_r (struct _reent *r, const char *path, int mode)
{
sd_fat_private_t *dev = sd_fat_get_device_data(path);
if (!dev) {
if(!dev) {
r->_errno = ENODEV;
return -1;
}
@ -580,7 +616,7 @@ static int sd_fat_mkdir_r(struct _reent *r, const char *path, int mode) {
OSLockMutex(dev->pMutex);
char *real_path = sd_fat_real_path(path, dev);
if (!real_path) {
if(!real_path) {
r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex);
return -1;
@ -592,7 +628,7 @@ static int sd_fat_mkdir_r(struct _reent *r, const char *path, int mode) {
OSUnlockMutex(dev->pMutex);
if (result < 0) {
if(result < 0) {
r->_errno = result;
return -1;
}
@ -600,9 +636,10 @@ static int sd_fat_mkdir_r(struct _reent *r, const char *path, int mode) {
return 0;
}
static int sd_fat_statvfs_r(struct _reent *r, const char *path, struct statvfs *buf) {
static int sd_fat_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf)
{
sd_fat_private_t *dev = sd_fat_get_device_data(path);
if (!dev) {
if(!dev) {
r->_errno = ENODEV;
return -1;
}
@ -613,7 +650,7 @@ static int sd_fat_statvfs_r(struct _reent *r, const char *path, struct statvfs *
memset(buf, 0, sizeof(struct statvfs));
char *real_path = sd_fat_real_path(path, dev);
if (!real_path) {
if(!real_path) {
r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex);
return -1;
@ -625,7 +662,7 @@ static int sd_fat_statvfs_r(struct _reent *r, const char *path, struct statvfs *
free(real_path);
if (result < 0) {
if(result < 0) {
r->_errno = result;
OSUnlockMutex(dev->pMutex);
return -1;
@ -650,7 +687,7 @@ static int sd_fat_statvfs_r(struct _reent *r, const char *path, struct statvfs *
buf->f_ffree = 0xffffffff;
// File system id
buf->f_fsid = (int) dev;
buf->f_fsid = (int)dev;
// Bit mask of f_flag values.
buf->f_flag = 0;
@ -663,25 +700,26 @@ static int sd_fat_statvfs_r(struct _reent *r, const char *path, struct statvfs *
return 0;
}
static DIR_ITER *sd_fat_diropen_r(struct _reent *r, DIR_ITER *dirState, const char *path) {
static DIR_ITER *sd_fat_diropen_r (struct _reent *r, DIR_ITER *dirState, const char *path)
{
sd_fat_private_t *dev = sd_fat_get_device_data(path);
if (!dev) {
if(!dev) {
r->_errno = ENODEV;
return NULL;
}
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *) dirState->dirStruct;
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct;
OSLockMutex(dev->pMutex);
char *real_path = sd_fat_real_path(path, dev);
if (!real_path) {
if(!real_path) {
r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex);
return NULL;
}
int dirHandle;
s32 dirHandle;
int result = FSOpenDir(dev->pClient, dev->pCmd, real_path, &dirHandle, -1);
@ -689,7 +727,8 @@ static DIR_ITER *sd_fat_diropen_r(struct _reent *r, DIR_ITER *dirState, const ch
OSUnlockMutex(dev->pMutex);
if (result < 0) {
if(result < 0)
{
r->_errno = result;
return NULL;
}
@ -700,9 +739,10 @@ static DIR_ITER *sd_fat_diropen_r(struct _reent *r, DIR_ITER *dirState, const ch
return dirState;
}
static int sd_fat_dirclose_r(struct _reent *r, DIR_ITER *dirState) {
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *) dirState->dirStruct;
if (!dirIter->dev) {
static int sd_fat_dirclose_r (struct _reent *r, DIR_ITER *dirState)
{
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct;
if(!dirIter->dev) {
r->_errno = ENODEV;
return -1;
}
@ -713,16 +753,18 @@ static int sd_fat_dirclose_r(struct _reent *r, DIR_ITER *dirState) {
OSUnlockMutex(dirIter->dev->pMutex);
if (result < 0) {
if(result < 0)
{
r->_errno = result;
return -1;
}
return 0;
}
static int sd_fat_dirreset_r(struct _reent *r, DIR_ITER *dirState) {
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *) dirState->dirStruct;
if (!dirIter->dev) {
static int sd_fat_dirreset_r (struct _reent *r, DIR_ITER *dirState)
{
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct;
if(!dirIter->dev) {
r->_errno = ENODEV;
return -1;
}
@ -733,26 +775,29 @@ static int sd_fat_dirreset_r(struct _reent *r, DIR_ITER *dirState) {
OSUnlockMutex(dirIter->dev->pMutex);
if (result < 0) {
if(result < 0)
{
r->_errno = result;
return -1;
}
return 0;
}
static int sd_fat_dirnext_r(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *st) {
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *) dirState->dirStruct;
if (!dirIter->dev) {
static int sd_fat_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *st)
{
sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct;
if(!dirIter->dev) {
r->_errno = ENODEV;
return -1;
}
OSLockMutex(dirIter->dev->pMutex);
FSDirEntry *dir_entry = malloc(sizeof(FSDirEntry));
FSDirEntry * dir_entry = malloc(sizeof(FSDirEntry));
int result = FSReadDir(dirIter->dev->pClient, dirIter->dev->pCmd, dirIter->dirHandle, dir_entry, -1);
if (result < 0) {
if(result < 0)
{
free(dir_entry);
r->_errno = result;
OSUnlockMutex(dirIter->dev->pMutex);
@ -762,7 +807,8 @@ static int sd_fat_dirnext_r(struct _reent *r, DIR_ITER *dirState, char *filename
// Fetch the current entry
strcpy(filename, dir_entry->name);
if (st) {
if(st)
{
memset(st, 0, sizeof(struct stat));
st->st_mode = (dir_entry->stat.flag & 0x80000000) ? S_IFDIR : S_IFREG;
st->st_nlink = 1;
@ -782,10 +828,10 @@ static int sd_fat_dirnext_r(struct _reent *r, DIR_ITER *dirState, char *filename
return 0;
}
// NTFS device driver devoptab
// SD device driver devoptab
static const devoptab_t devops_sd_fat = {
NULL, /* Device name */
sizeof(sd_fat_file_state_t),
sizeof (sd_fat_file_state_t),
sd_fat_open_r,
sd_fat_close_r,
sd_fat_write_r,
@ -798,7 +844,7 @@ static const devoptab_t devops_sd_fat = {
sd_fat_chdir_r,
sd_fat_rename_r,
sd_fat_mkdir_r,
sizeof(sd_fat_dir_entry_t),
sizeof (sd_fat_dir_entry_t),
sd_fat_diropen_r,
sd_fat_dirreset_r,
sd_fat_dirnext_r,
@ -806,12 +852,15 @@ static const devoptab_t devops_sd_fat = {
sd_fat_statvfs_r,
sd_fat_ftruncate_r,
sd_fat_fsync_r,
NULL, /* Device data */
NULL, /* sd_fat_chmod_r */
NULL, /* sd_fat_fchmod_r */
NULL /* Device data */
NULL /* sd_fat_rmdir_r */
};
static int sd_fat_add_device(const char *name, const char *mount_path, void *pClient, void *pCmd) {
static int sd_fat_add_device (const char *name, const char *mount_path, void *pClient, void *pCmd)
{
devoptab_t *dev = NULL;
char *devname = NULL;
char *devpath = NULL;
@ -831,19 +880,25 @@ static int sd_fat_add_device(const char *name, const char *mount_path, void *pCl
}
// Use the space allocated at the end of the devoptab for storing the device name
devname = (char *) (dev + 1);
devname = (char*)(dev + 1);
strcpy(devname, name);
// create private data
sd_fat_private_t *priv = (sd_fat_private_t *) malloc(sizeof(sd_fat_private_t) + strlen(mount_path) + 1);
if (!priv) {
int mount_path_len = 0;
if(mount_path != NULL){
mount_path_len = strlen(mount_path);
}
sd_fat_private_t *priv = (sd_fat_private_t *)malloc(sizeof(sd_fat_private_t) + mount_path_len + 1);
if(!priv) {
free(dev);
errno = ENOMEM;
return -1;
}
devpath = (char *) (priv + 1);
strcpy(devpath, mount_path);
devpath = (char*)(priv+1);
if(mount_path != NULL){
strcpy(devpath, mount_path);
}
// setup private data
priv->mount_path = devpath;
@ -851,7 +906,7 @@ static int sd_fat_add_device(const char *name, const char *mount_path, void *pCl
priv->pCmd = pCmd;
priv->pMutex = malloc(OS_MUTEX_SIZE);
if (!priv->pMutex) {
if(!priv->pMutex) {
free(dev);
free(priv);
errno = ENOMEM;
@ -882,7 +937,31 @@ static int sd_fat_add_device(const char *name, const char *mount_path, void *pCl
return -1;
}
static int sd_fat_remove_device(const char *path, void **pClient, void **pCmd, char **mountPath) {
/*
Because of some weird reason unmounting doesn't work properly.
This fix if mainly when a usb drive is connected.
It resets the devoptab_list, otherwise mounting again would throw an exception (in strlen).
No memory is free'd here. Maybe a problem?!?!?
*/
void deleteDevTabsNames(){
const devoptab_t * devoptab = NULL;
u32 last_entry = (u32) devoptab_list[STD_MAX-1];
for (int i = 3; i < STD_MAX; i++) {
devoptab = devoptab_list[i];
if (devoptab) {
//log_printf("check devotab %d %08X\n",i,devoptab);
if((u32) devoptab != last_entry){
devoptab_list[i] = (const devoptab_t *)last_entry;
//log_printf("Removed devotab %d %08X %08X %08X\n",i,devoptab,devoptab->name,devoptab->deviceData);
}
}
}
}
static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd, char **mountPath)
{
const devoptab_t *devoptab = NULL;
char name[128] = {0};
int i;
@ -901,19 +980,22 @@ static int sd_fat_remove_device(const char *path, void **pClient, void **pCmd, c
if (strcmp(name, devoptab->name) == 0) {
devoptab_list[i] = devoptab_list[0];
if (devoptab->deviceData) {
sd_fat_private_t *priv = (sd_fat_private_t *) devoptab->deviceData;
*pClient = priv->pClient;
*pCmd = priv->pCmd;
*mountPath = (char *) malloc(strlen(priv->mount_path) + 1);
if (*mountPath)
strcpy(*mountPath, priv->mount_path);
if (priv->pMutex)
if(devoptab->deviceData)
{
sd_fat_private_t *priv = (sd_fat_private_t *)devoptab->deviceData;
if(pClient != NULL) *pClient = priv->pClient;
if(pCmd != NULL) *pCmd = priv->pCmd;
if(mountPath != NULL){
*mountPath = (char*) malloc(strlen(priv->mount_path)+1);
if(*mountPath)
strcpy(*mountPath, priv->mount_path);
}
if(priv->pMutex)
free(priv->pMutex);
free(devoptab->deviceData);
}
free((devoptab_t *) devoptab);
free((devoptab_t*)devoptab);
return 0;
}
}
@ -922,18 +1004,19 @@ static int sd_fat_remove_device(const char *path, void **pClient, void **pCmd, c
return -1;
}
int mount_sd_fat(const char *path) {
int mount_sd_fat(const char *path)
{
int result = -1;
// get command and client
void *pClient = malloc(FS_CLIENT_SIZE);
void *pCmd = malloc(FS_CMD_BLOCK_SIZE);
void* pClient = malloc(FS_CLIENT_SIZE);
void* pCmd = malloc(FS_CMD_BLOCK_SIZE);
if (!pClient || !pCmd) {
if(!pClient || !pCmd) {
// just in case free if not 0
if (pClient)
if(pClient)
free(pClient);
if (pCmd)
if(pCmd)
free(pCmd);
return -2;
}
@ -944,26 +1027,23 @@ int mount_sd_fat(const char *path) {
char *mountPath = NULL;
result = MountFS(pClient, pCmd, &mountPath);
if (result == 0) {
log_print("MountFS success\n");
if(MountFS(pClient, pCmd, &mountPath) == 0) {
result = sd_fat_add_device(path, mountPath, pClient, pCmd);
log_printf("sd_fat_add_device result: %i\n", result);
free(mountPath);
} else {
log_printf("MountFS error: %i\n", result);
}
return result;
}
int unmount_sd_fat(const char *path) {
int unmount_sd_fat(const char *path)
{
void *pClient = 0;
void *pCmd = 0;
char *mountPath = 0;
int result = sd_fat_remove_device(path, &pClient, &pCmd, &mountPath);
if (result == 0) {
if(result == 0)
{
UmountFS(pClient, pCmd, mountPath);
FSDelClient(pClient);
free(pClient);
@ -973,3 +1053,11 @@ int unmount_sd_fat(const char *path) {
}
return result;
}
int mount_fake(){
return sd_fat_add_device("fake", NULL, NULL, NULL);
}
int unmount_fake(){
return sd_fat_remove_device ("fake", NULL,NULL,NULL);
}

View File

@ -40,4 +40,4 @@ SECTIONS {
}
/******************************************************** FS ********************************************************/
/* coreinit.rpl difference in addresses 0xFE3C00 */
/* coreinit.rpl difference in addresses 0xFE3C00 */

View File

@ -11,7 +11,7 @@ declareFunctionHook(int, FSOpenFileAsync, void *pClient, void *pCmd, const char
return real_FSOpenFileAsync(pClient, pCmd, path, mode, handle, error, asyncParams);
}
declareFunctionHook(int, FSOpenDir, void *pClient, void *pCmd, const char *path, int *dh, int errHandling) {
declareFunctionHook(int, FSOpenDir, void *pClient, void *pCmd, const char *path, s32 *dh, int errHandling) {
log_printf("FSOpenDir(): %s", path);
return real_FSOpenDir(pClient, pCmd, path, dh, errHandling);
}

View File

@ -77,7 +77,7 @@ static unsigned char exceptionCallback(void *c, unsigned char exception_type) {
register frame_rec_t l, p = (frame_rec_t) lr;
l = p;
p = r1;
p = (frame_rec_t) r1;
if (!p)
asm volatile("mr %0,%%r1" : "=r"(p));

View File

@ -5,8 +5,7 @@
extern "C" {
#endif
#include "../utils/stringify.h"
#include "../common/kernel_types.h"
#include "../tcpgecko/stringify.h"
#define OS_EXCEPTION_DSI 2
#define OS_EXCEPTION_ISI 3

View File

@ -1,4 +1,3 @@
#include "address.h"
#include "../dynamic_libs/os_functions.h"
int validateAddressRange(int starting_address, int ending_address) {

View File

@ -1,8 +1,6 @@
#ifndef TCPGECKO_STACK_H
#define TCPGECKO_STACK_H
#include "kernel_types.h"
typedef struct OSThread;
typedef struct OSThreadLink {

View File

@ -1,10 +1,9 @@
#include "disassembler.h"
#include "../utils/assertions.h"
#include "../dynamic_libs/os_functions.h"
#include "assertions.h"
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
char *disassemblerBuffer;
void *disassemblerBufferPointer;
@ -13,7 +12,7 @@ void *disassemblerBufferPointer;
void formatDisassembled(char *format, ...) {
if (!disassemblerBuffer) {
disassemblerBuffer = malloc(DISASSEMBLER_BUFFER_SIZE);
disassemblerBuffer = (char *) malloc(DISASSEMBLER_BUFFER_SIZE);
ASSERT_ALLOCATED(disassemblerBuffer, "Disassembler buffer")
disassemblerBufferPointer = disassemblerBuffer;
}
@ -27,7 +26,7 @@ void formatDisassembled(char *format, ...) {
va_end(variableArguments);
// Do not smash the buffer
long projectedSize = (void *) disassemblerBuffer - disassemblerBufferPointer + printedBytesCount;
long projectedSize = disassemblerBuffer - (char *) disassemblerBufferPointer + printedBytesCount;
if (projectedSize < DISASSEMBLER_BUFFER_SIZE) {
memcpy(disassemblerBuffer, temporaryBuffer, printedBytesCount);
disassemblerBuffer += printedBytesCount;

View File

@ -1,11 +1,10 @@
#include "../utils/stringify.h"
#include "stringify.h"
#include "../dynamic_libs/os_functions.h"
#include "threads.h"
#include "../utils/logger.h"
#include "../main.h"
#include "main.h"
#include "utilities.h"
#include "software_breakpoints.h"
#include "../common/kernel_types.h"
#ifndef TCPGECKO_BREAKPOINTS_H
#define TCPGECKO_BREAKPOINTS_H

View File

@ -1,9 +1,9 @@
#pragma once
#include "../kernel/syscalls.h"
#include "../utils/assertions.h"
#include "assertions.h"
#include "../dynamic_libs/os_functions.h"
#include "../tcp_gecko.h"
#include "tcp_gecko.h"
#include "../utils/logger.h"
// TODO Variable size, not hard-coded

View File

@ -5,21 +5,23 @@
#include <malloc.h>
#include <unistd.h>
#include <fcntl.h>
#include "dynamic_libs/os_functions.h"
#include "dynamic_libs/fs_functions.h"
#include "dynamic_libs/sys_functions.h"
#include "dynamic_libs/vpad_functions.h"
#include "dynamic_libs/socket_functions.h"
#include "kernel/kernel_functions.h"
#include "system/memory.h"
#include "common/common.h"
#include "../dynamic_libs/os_functions.h"
#include "../dynamic_libs/fs_functions.h"
#include "../dynamic_libs/sys_functions.h"
#include "../dynamic_libs/vpad_functions.h"
#include "../dynamic_libs/socket_functions.h"
#include "../kernel/kernel_functions.h"
#include "../system/memory.h"
#include "../common/common.h"
#include "main.h"
#include "code_handler.h"
#include "utils/logger.h"
#include "utils/function_patcher.h"
#include "patcher/function_patcher_gx2.h"
#include "patcher/function_patcher_coreinit.h"
#include "utils/sd_ip_reader.hpp"
#include "../utils/logger.h"
#include "../utils/function_patcher.h"
#include "../patcher/function_patcher_gx2.h"
#include "../patcher/function_patcher_coreinit.h"
#include "sd_ip_reader.h"
#include "title.h"
#include "tcp_gecko.h"
bool isCodeHandlerInstalled = false;
bool areSDCheatsEnabled = false;

View File

@ -1,8 +1,8 @@
#ifndef _MAIN_H_
#define _MAIN_H_
#include "common/types.h"
#include "dynamic_libs/os_functions.h"
#include "../common/types.h"
#include "../dynamic_libs/os_functions.h"
/* Main */
#ifdef __cplusplus

561
src/tcpgecko/net.c Normal file
View File

@ -0,0 +1,561 @@
#include <string.h>
#include <malloc.h>
#include "../dynamic_libs/os_functions.h"
#include "../dynamic_libs/socket_functions.h"
#include "net.h"
static volatile int iLock = 0;
#define CHECK_ERROR(cond) if (cond) { goto error; }
void cafiine_connect(int *psock, u32 server_ip) {
struct sockaddr_in addr;
int sock, ret;
socket_lib_init();
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
CHECK_ERROR(sock == -1);
addr.sin_family = AF_INET;
addr.sin_port = 7332;
addr.sin_addr.s_addr = server_ip;
ret = connect(sock, (void *) &addr, sizeof(addr));
CHECK_ERROR(ret < 0);
ret = cafiine_handshake(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret == BYTE_NORMAL);
*psock = sock;
return;
error:
if (sock != -1)
socketclose(sock);
*psock = -1;
return;
}
void cafiine_disconnect(int sock) {
CHECK_ERROR(sock == -1);
socketclose(sock);
error:
return;
}
int cafiine_handshake(int sock) {
int ret;
unsigned char buffer[16];
u64 title_id = OSGetTitleID();
memcpy(buffer, &title_id, 16);
ret = sendwait(sock, buffer, sizeof(buffer));
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
return ret;
error:
return ret;
}
int getMode(int sock, int *result) {
while (iLock)
usleep(5000);
iLock = 1;
int ret = 0;
CHECK_ERROR(sock == -1);
// create and send buffer with : [cmd id][fd][size][buffer data ...]
{
ret = sendbyte(sock, BYTE_G_MODE);
// wait reply
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
if (ret == BYTE_MODE_D) *result = BYTE_MODE_D;
if (ret == BYTE_MODE_I) *result = BYTE_MODE_I;
ret = 1;
}
error:
iLock = 0;
return ret;
}
int cafiine_fsetpos(int sock, int *result, int fd, int set) {
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
int ret;
char buffer[1 + 8];
buffer[0] = BYTE_SETPOS;
*(int *) (buffer + 1) = fd;
*(int *) (buffer + 5) = set;
ret = sendwait(sock, buffer, 1 + 8);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret == BYTE_NORMAL);
ret = recvwait(sock, result, 4);
CHECK_ERROR(ret < 0);
iLock = 0;
return 0;
error:
iLock = 0;
return -1;
}
int cafiine_send_handle(int sock, const char *path, int handle) {
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
// create and send buffer with : [cmd id][handle][path length][path data ...]
{
int ret;
int len_path = 0;
while (path[len_path++]);
char buffer[1 + 4 + 4 + len_path];
buffer[0] = BYTE_HANDLE;
*(int *) (buffer + 1) = handle;
*(int *) (buffer + 5) = len_path;
for (ret = 0; ret < len_path; ret++)
buffer[9 + ret] = path[ret];
// send buffer, wait for reply
ret = sendwait(sock, buffer, 1 + 4 + 4 + len_path);
CHECK_ERROR(ret < 0);
// wait reply
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret == BYTE_SPECIAL);
if (ret == BYTE_REQUEST) {
ret = 1;
} else {
ret = 2;
}
// wait reply
int special_ret = recvbyte(sock);
CHECK_ERROR(special_ret < 0);
CHECK_ERROR(special_ret != BYTE_SPECIAL);
iLock = 0;
return ret;
}
error:
iLock = 0;
return -1;
}
int cafiine_fopen(int sock, int *result, const char *path, const char *mode, int *handle) {
while (iLock)
usleep(5000);
iLock = 1;
int final_result = -1;
CHECK_ERROR(sock == -1);
int ret;
int len_path = 0;
len_path++;
// while (path[len_path++]);
int len_mode = 0;
len_mode++;
// while (mode[len_mode++]);
//
{
char buffer[1 + 8 + len_path + len_mode];
buffer[0] = BYTE_OPEN;
*(int *) (buffer + 1) = len_path;
*(int *) (buffer + 5) = len_mode;
for (ret = 0; ret < len_path; ret++)
buffer[9 + ret] = path[ret];
for (ret = 0; ret < len_mode; ret++)
buffer[9 + len_path + ret] = mode[ret];
ret = sendwait(sock, buffer, 1 + 8 + len_path + len_mode);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret == BYTE_NORMAL);
ret = recvwait(sock, result, 4);
CHECK_ERROR(ret < 0);
ret = recvwait(sock, handle, 4);
CHECK_ERROR(ret < 0);
}
final_result = 0;
error:
iLock = 0;
return final_result;
}
void cafiine_send_file(int sock, char *file, int size, int fd) {
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
int ret;
// create and send buffer with : [cmd id][fd][size][buffer data ...]
{
char buffer[1 + 4 + 4 + size];
buffer[0] = BYTE_DUMP;
*(int *) (buffer + 1) = fd;
*(int *) (buffer + 5) = size;
for (ret = 0; ret < size; ret++)
buffer[9 + ret] = file[ret];
// send buffer, wait for reply
ret = sendwait(sock, buffer, 1 + 4 + 4 + size);
CHECK_ERROR(ret < 0);
// wait reply
ret = recvbyte(sock);
CHECK_ERROR(ret != BYTE_SPECIAL);
}
error:
iLock = 0;
return;
}
int cafiine_fread(int sock, int *result, void *ptr, int size, int fd) {
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
int ret;
char buffer[1 + 8];
buffer[0] = BYTE_READ;
*(int *) (buffer + 1) = size;
*(int *) (buffer + 5) = fd;
ret = sendwait(sock, buffer, 1 + 8);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret == BYTE_NORMAL);
int sz;
ret = recvwait(sock, &sz, 4);
CHECK_ERROR(ret < 0);
ret = recvwaitlen(sock, ptr, sz);
*result = sz - ret;
ret = sendbyte(sock, BYTE_OK);
CHECK_ERROR(ret < 0);
iLock = 0;
return 0;
error:
iLock = 0;
return -1;
}
int cafiine_fclose(int sock, int *result, int fd, int dumpclose) {
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
int ret;
char buffer[1 + 4];
buffer[0] = BYTE_CLOSE;
if (dumpclose)buffer[0] = BYTE_CLOSE_DUMP;
*(int *) (buffer + 1) = fd;
ret = sendwait(sock, buffer, 1 + 4);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret == BYTE_NORMAL);
ret = recvwait(sock, result, 4);
CHECK_ERROR(ret < 0);
iLock = 0;
return 0;
error:
iLock = 0;
return -1;
}
int saviine_start_injection(int sock, long persistentID, int *mask) {
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
{
char buffer[1 + 4];
buffer[0] = BYTE_INJECTSTART;
*(long *) (buffer + 1) = persistentID;
ret = sendwait(sock, buffer, 1 + 4);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
ret = recvwait(sock, mask, 4);
CHECK_ERROR(ret < 0);
CHECK_ERROR((*mask & MASK_NORMAL) != MASK_NORMAL);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
result = 1;
}
error:
iLock = 0;
return result;
}
int saviine_end_injection(int sock) {
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
{
ret = sendbyte(sock, BYTE_INJECTEND);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_OK);
result = 1;
}
error:
iLock = 0;
return result;
}
int saviine_start_dump(int sock, long persistentID, int *mask) {
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
{
char buffer[1 + 4];
buffer[0] = BYTE_DUMPSTART;
*(long *) (buffer + 1) = persistentID;
ret = sendwait(sock, buffer, 1 + 4);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
ret = recvwait(sock, mask, 4);
CHECK_ERROR(ret < 0);
CHECK_ERROR((*mask & MASK_NORMAL) != MASK_NORMAL);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
result = 1;
}
error:
iLock = 0;
return result;
}
int saviine_end_dump(int sock) {
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
{
ret = sendbyte(sock, BYTE_DUMPEND);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_OK);
result = 1;
}
error:
iLock = 0;
return result;
}
int saviine_readdir(int sock, char *path, char *resultname, int *resulttype, int *filesize) {
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
// create and send buffer with : [cmd id][len_path][path][filesize]
{
int size = 0;
while (path[size++]);
char buffer[1 + 4 + size];
buffer[0] = BYTE_READ_DIR;
*(int *) (buffer + 1) = size;
for (ret = 0; ret < size; ret++)
buffer[5 + ret] = path[ret];
// send buffer, wait for reply
ret = sendwait(sock, buffer, 1 + 4 + size);
CHECK_ERROR(ret < 0);
// wait reply
ret = recvbyte(sock);
CHECK_ERROR(ret != BYTE_OK);
ret = recvbyte(sock);
CHECK_ERROR(ret != BYTE_FILE && ret != BYTE_FOLDER);
*resulttype = ret;
size = 0;
ret = recvwait(sock, &size, 4);
CHECK_ERROR(ret < 0);
ret = recvwait(sock, resultname, size + 1);
CHECK_ERROR(ret < 0);
size = 0;
ret = recvwait(sock, &size, 4);
CHECK_ERROR(ret < 0);
*filesize = size;
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
result = 1;
}
error:
iLock = 0;
return result;
}
void cafiine_send_ping(int sock, int val1, int val2) {
while (iLock)
usleep(5000);
iLock = 1;
int ret;
char buffer[1 + 4 + 4];
buffer[0] = BYTE_PING;
*(int *) (buffer + 1) = val1;
*(int *) (buffer + 5) = val2;
ret = sendwait(sock, buffer, 1 + 4 + 4);
CHECK_ERROR(ret < 0);
error:
iLock = 0;
return;
}
int recvwait(int sock, void *buffer, int len) {
int ret;
while (len > 0) {
ret = recv(sock, buffer, len, 0);
CHECK_ERROR(ret < 0);
len -= ret;
buffer += ret;
}
return 0;
error:
return ret;
}
int recvwaitlen(int sock, void *buffer, int len) {
int ret;
while (len > 0) {
ret = recv(sock, buffer, len, 0);
CHECK_ERROR(ret < 0);
len -= ret;
buffer += ret;
}
return 0;
error:
return len;
}
int recvbyte(int sock) {
unsigned char buffer[1];
int ret;
ret = recvwait(sock, buffer, 1);
if (ret < 0) return ret;
return buffer[0];
}
int sendwait(int sock, const void *buffer, int len) {
int ret;
while (len > 0) {
ret = send(sock, buffer, len, 0);
CHECK_ERROR(ret < 0);
len -= ret;
buffer += ret;
}
return 0;
error:
return ret;
}
void log_string(int sock, const char *str, char flag_byte) {
if (sock == -1) {
return;
}
while (iLock)
usleep(5000);
iLock = 1;
int i;
int len_str = 0;
len_str++;
// while (str[len_str++]);
//
{
char buffer[1 + 4 + len_str];
buffer[0] = flag_byte;
*(int *) (buffer + 1) = len_str;
for (i = 0; i < len_str; i++)
buffer[5 + i] = str[i];
buffer[5 + i] = 0;
sendwait(sock, buffer, 1 + 4 + len_str);
}
iLock = 0;
}
int sendbyte(int sock, unsigned char byte) {
unsigned char buffer[1];
buffer[0] = byte;
return sendwait(sock, buffer, 1);
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "../utils/logger.h"
#include "../utils/assertions.h"
#include "assertions.h"
#include "../dynamic_libs/os_functions.h"
#include "../common/fs_defs.h"
#include "kernel.h"

View File

@ -1,11 +1,11 @@
#include <stdio.h> // snprintf
#include <string.h> // memcpy, memset
#include "utils/logger.h"
#include "fs/sd_fat_devoptab.h"
#include "fs/fs_utils.h"
#include "dynamic_libs/os_functions.h"
#include "../utils/logger.h"
#include "../fs/sd_fat_devoptab.h"
#include "../fs/fs_utils.h"
#include "../dynamic_libs/os_functions.h"
#include "tcp_gecko.h"
#include "kernel/syscalls.h"
#include "../kernel/syscalls.h"
#include <fat.h>
#include <iosuhax.h>
@ -103,7 +103,7 @@ void considerApplyingSDCheats() {
}
log_print("Copying...\n");
kernelCopyData2((unsigned char *) CODE_LIST_START_ADDRESS, codes, codesSize);
kernelCopyData2((unsigned char *) CODE_LIST_START_ADDRESS, codes, (unsigned int) codesSize);
log_print("Copied!\n");
setCodeHandlerEnabled(true);

View File

@ -1,4 +1,4 @@
#include "sd_ip_reader.hpp"
#include "sd_ip_reader.h"
char ipFromSd[16];
bool hasReadIP = false;

View File

@ -1,6 +1,6 @@
#pragma once
#include "logger.h"
#include "../utils/logger.h"
#include "../common/common.h"
#include "../fs/CFile.hpp"

View File

@ -4,7 +4,7 @@
#define TCPGECKO_BREAKPOINT_EXECUTE_H
#include "utilities.h"
#include "exception_handler.h"
#include "../system/exception_handler.h"
#define OS_EXCEPTION_DSI 2
#define OS_EXCEPTION_ISI 3
@ -77,7 +77,7 @@ struct Breakpoint *getBreakpoint(u32 address, int size) {
}
void pokeRegisters(OSContext context, uint32_t gpr[32], double fpr[32]) {
memcpy(&context.gpr, &gpr, sizeof(gpr));
memcpy(&context.gpr, &gpr, 32 * sizeof(uint32_t));
// memcpy(&context.fpr, &fpr, sizeof(fpr));
}

View File

@ -1,8 +1,8 @@
#ifndef TCPGECKO_STACK_H
#define TCPGECKO_STACK_H
#include "../utils/linked_list.h"
#include "../common/cafe.h"
#include "linked_list.h"
#include "cafe.h"
bool isValidStackPointer(u32 stackPointer) {
return stackPointer >= 0x10000000 && stackPointer < 0x20000000;

View File

@ -4,24 +4,24 @@
#include <stdlib.h>
#include <stdio.h>
// #include <inttypes.h>
#include "common/common.h"
#include "../common/common.h"
#include <zlib.h> // Actually must be included before os_functions
#include "dynamic_libs/os_functions.h"
#include "../dynamic_libs/os_functions.h"
#include <string.h>
#include <malloc.h>
#include "main.h"
#include "dynamic_libs/socket_functions.h"
#include "dynamic_libs/gx2_functions.h"
#include "dynamic_libs/fs_functions.h"
#include "utils/logger.h"
#include "system/hardware_breakpoints.h"
#include "utils/linked_list.h"
#include "system/address.h"
#include "system/stack.h"
#include "system/pause.h"
#include "utils/sd_ip_reader.hpp"
#include "patcher/function_patcher_gx2.h"
#include "system/raw_assembly_cheats.h"
#include "../dynamic_libs/socket_functions.h"
#include "../dynamic_libs/gx2_functions.h"
#include "../dynamic_libs/fs_functions.h"
#include "../utils/logger.h"
#include "hardware_breakpoints.hpp"
#include "linked_list.h"
#include "address.h"
#include "stack.h"
#include "pause.h"
#include "sd_ip_reader.h"
#include "../patcher/function_patcher_gx2.h"
#include "raw_assembly_cheats.h"
#include "sd_cheats.h"
void *client;
@ -81,9 +81,9 @@ struct pygecko_bss_t {
#define COMMAND_CLEAR_ASSEMBLY 0xE2
#define CHECK_ERROR(cond) if (cond) { bss->line = __LINE__; goto error; }
#define errno (*__gh_errno_ptr())
#define errno2 (*__gh_errno_ptr())
#define MSG_DONT_WAIT 32
#define EWOULDBLOCK 6
#define E_WOULD_BLOCK 6
// #define WRITE_SCREEN_MESSAGE_BUFFER_SIZE 100
#define SERVER_VERSION "06/03/2017"
#define ONLY_ZEROS_READ 0xB0
@ -242,8 +242,9 @@ static int processCommands(struct pygecko_bss_t *bss, int clientfd) {
ret = checkbyte(clientfd);
if (ret < 0) {
CHECK_ERROR(errno != EWOULDBLOCK);
CHECK_ERROR(errno2 != E_WOULD_BLOCK);
GX2WaitForVsync();
continue;
}
@ -729,8 +730,11 @@ static int processCommands(struct pygecko_bss_t *bss, int clientfd) {
break;
}
case COMMAND_GET_DATA_BUFFER_SIZE: {
log_printf("COMMAND_GET_DATA_BUFFER_SIZE...\n");
((int *) buffer)[0] = DATA_BUFFER_SIZE;
log_printf("Sending buffer size...\n");
ret = sendwait(bss, clientfd, buffer, sizeof(int));
log_printf("Sent: %i\n", ret);
CHECK_ERROR(ret < 0)
break;
@ -798,7 +802,7 @@ static int processCommands(struct pygecko_bss_t *bss, int clientfd) {
considerInitializingFileSystem();
int handle;
s32 handle;
FSDirEntry entry;
ret = FSOpenDir(client, commandBlock, directory_path, &handle, FS_RET_ALL_ERROR);
@ -1136,13 +1140,14 @@ static int processCommands(struct pygecko_bss_t *bss, int clientfd) {
break;
}
case COMMAND_REMOTE_PROCEDURE_CALL: {
long long (*function)(int, int, int, int, int, int, int, int);
int r3, r4, r5, r6, r7, r8, r9, r10;
long long result;
ret = recvwait(bss, clientfd, buffer, 4 + 8 * 4);
CHECK_ERROR(ret < 0);
log_print("Receiving RPC information...\n");
ret = recvwait(bss, clientfd, buffer, sizeof(int) + 8 * sizeof(int));
ASSERT_FUNCTION_SUCCEEDED(ret, "revcwait() Receiving RPC information")
log_print("RPC information received...\n");
long long (*function)(int, int, int, int, int, int, int, int);
function = (long long int (*)(int, int, int, int, int, int, int, int)) ((void **) buffer)[0];
r3 = ((int *) buffer)[1];
r4 = ((int *) buffer)[2];
@ -1153,11 +1158,16 @@ static int processCommands(struct pygecko_bss_t *bss, int clientfd) {
r9 = ((int *) buffer)[7];
r10 = ((int *) buffer)[8];
result = function(r3, r4, r5, r6, r7, r8, r9, r10);
log_print("Calling function...\n");
long long result = function(r3, r4, r5, r6, r7, r8, r9, r10);
log_printf("Function successfully called with return value: 0x%08x 0x%08x\n", (int) (result >> 32),
(int) result);
log_print("Sending result...\n");
((long long *) buffer)[0] = result;
ret = sendwait(bss, clientfd, buffer, 8);
CHECK_ERROR(ret < 0)
ret = sendwait(bss, clientfd, buffer, sizeof(long long));
ASSERT_FUNCTION_SUCCEEDED(ret, "sendwait() Sending return value")
log_print("Result successfully sent...\n");
break;
}
@ -1457,9 +1467,10 @@ static int runTCPGeckoServer(int argc, void *argv) {
CHECK_ERROR(ret < 0)
while (true) {
log_printf("accept()...\n");
len = 16;
log_printf("before accept()...\n");
clientfd = accept(sockfd, (struct sockaddr *) &socketAddress, (s32 * ) & len);
log_printf("after accept()...\n");
CHECK_ERROR(clientfd == -1)
log_printf("commands()...\n");
ret = processCommands(bss, clientfd);

View File

@ -1,5 +1,5 @@
#include "threads.h"
#include "../utils/linked_list.h"
#include "linked_list.h"
#include "../dynamic_libs/os_functions.h"
#include "../utils/logger.h"

View File

@ -1,4 +1,4 @@
#include "dynamic_libs/os_functions.h"
#include "../dynamic_libs/os_functions.h"
#include "title.h"
bool isRunningTitleID(unsigned long long int japaneseTitleID) {

View File

@ -4,7 +4,6 @@
#include "../dynamic_libs/os_functions.h"
#include "../utils/logger.h"
#include "kernel.h"
#include "../common/kernel_types.h"
void writeCode(u32 address, u32 instruction) {
u32 *pointer = (u32 *) (address + 0xA0000000);

View File

@ -215,6 +215,7 @@ bool isDynamicFunction(unsigned int physicalAddress) {
unsigned int getRPLHandle(int library, const char *functionName) {
unsigned int rplHandle = 0;
u32 gx2_handle = 0;
switch (library) {
case LIB_CORE_INIT:
@ -228,7 +229,6 @@ unsigned int getRPLHandle(int library, const char *functionName) {
case LIB_GX2:
if (DEBUG_LOG_DYN)log_printf("FindExport of %s! From LIB_GX2\n", functionName);
unsigned int gx2_handle = 0;
OSDynLoad_Acquire("gx2.rpl", &gx2_handle);
if (gx2_handle == 0) {
log_print("LIB_GX2 not acquired\n");

View File

@ -1,7 +1,9 @@
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <gctypes.h>
#include "../dynamic_libs/os_functions.h"
#include "../dynamic_libs/socket_functions.h"
#include "logger.h"

View File

@ -1,561 +0,0 @@
#include <string.h>
#include <malloc.h>
#include "../common/common.h"
#include "../dynamic_libs/os_functions.h"
#include "../dynamic_libs/socket_functions.h"
#include "net.h"
static volatile int iLock = 0;
#define CHECK_ERROR(cond) if (cond) { goto error; }
void cafiine_connect(int *psock,u32 server_ip) {
struct sockaddr_in addr;
int sock, ret;
socket_lib_init();
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
CHECK_ERROR(sock == -1);
addr.sin_family = AF_INET;
addr.sin_port = 7332;
addr.sin_addr.s_addr = server_ip;
ret = connect(sock, (void *)&addr, sizeof(addr));
CHECK_ERROR(ret < 0);
ret = cafiine_handshake(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret == BYTE_NORMAL);
*psock = sock;
return;
error:
if (sock != -1)
socketclose(sock);
*psock = -1;
return;
}
void cafiine_disconnect(int sock) {
CHECK_ERROR(sock == -1);
socketclose(sock);
error:
return;
}
int cafiine_handshake(int sock) {
int ret;
unsigned char buffer[16];
u64 title_id = OSGetTitleID();
memcpy(buffer, &title_id, 16);
ret = sendwait(sock, buffer, sizeof(buffer));
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
return ret;
error:
return ret;
}
int getMode(int sock,int * result)
{
while (iLock)
usleep(5000);
iLock = 1;
int ret = 0;
CHECK_ERROR(sock == -1);
// create and send buffer with : [cmd id][fd][size][buffer data ...]
{
ret = sendbyte(sock, BYTE_G_MODE);
// wait reply
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
if(ret == BYTE_MODE_D) *result = BYTE_MODE_D;
if(ret == BYTE_MODE_I) *result = BYTE_MODE_I;
ret = 1;
}
error:
iLock = 0;
return ret;
}
int cafiine_fsetpos(int sock, int *result, int fd, int set) {
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
int ret;
char buffer[1 + 8];
buffer[0] = BYTE_SETPOS;
*(int *)(buffer + 1) = fd;
*(int *)(buffer + 5) = set;
ret = sendwait(sock, buffer, 1 + 8);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret == BYTE_NORMAL);
ret = recvwait(sock, result, 4);
CHECK_ERROR(ret < 0);
iLock = 0;
return 0;
error:
iLock = 0;
return -1;
}
int cafiine_send_handle(int sock, const char *path, int handle)
{
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
// create and send buffer with : [cmd id][handle][path length][path data ...]
{
int ret;
int len_path = 0;
while (path[len_path++]);
char buffer[1 + 4 + 4 + len_path];
buffer[0] = BYTE_HANDLE;
*(int *)(buffer + 1) = handle;
*(int *)(buffer + 5) = len_path;
for (ret = 0; ret < len_path; ret++)
buffer[9 + ret] = path[ret];
// send buffer, wait for reply
ret = sendwait(sock, buffer, 1 + 4 + 4 + len_path);
CHECK_ERROR(ret < 0);
// wait reply
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret == BYTE_SPECIAL);
if(ret == BYTE_REQUEST){
ret = 1;
}else{
ret = 2;
}
// wait reply
int special_ret = recvbyte(sock);
CHECK_ERROR(special_ret < 0);
CHECK_ERROR(special_ret != BYTE_SPECIAL);
iLock = 0;
return ret;
}
error:
iLock = 0;
return -1;
}
int cafiine_fopen(int sock, int *result, const char *path, const char *mode, int *handle) {
while (iLock)
usleep(5000);
iLock = 1;
int final_result = -1;
CHECK_ERROR(sock == -1);
int ret;
int len_path = 0;
while (path[len_path++]);
int len_mode = 0;
while (mode[len_mode++]);
//
{
char buffer[1 + 8 + len_path + len_mode];
buffer[0] = BYTE_OPEN;
*(int *)(buffer + 1) = len_path;
*(int *)(buffer + 5) = len_mode;
for (ret = 0; ret < len_path; ret++)
buffer[9 + ret] = path[ret];
for (ret = 0; ret < len_mode; ret++)
buffer[9 + len_path + ret] = mode[ret];
ret = sendwait(sock, buffer, 1 + 8 + len_path + len_mode);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret == BYTE_NORMAL);
ret = recvwait(sock, result, 4);
CHECK_ERROR(ret < 0);
ret = recvwait(sock, handle, 4);
CHECK_ERROR(ret < 0);
}
final_result = 0;
error:
iLock = 0;
return final_result;
}
void cafiine_send_file(int sock, char *file, int size, int fd) {
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
int ret;
// create and send buffer with : [cmd id][fd][size][buffer data ...]
{
char buffer[1 + 4 + 4 + size];
buffer[0] = BYTE_DUMP;
*(int *)(buffer + 1) = fd;
*(int *)(buffer + 5) = size;
for (ret = 0; ret < size; ret++)
buffer[9 + ret] = file[ret];
// send buffer, wait for reply
ret = sendwait(sock, buffer, 1 + 4 + 4 + size);
CHECK_ERROR(ret < 0);
// wait reply
ret = recvbyte(sock);
CHECK_ERROR(ret != BYTE_SPECIAL);
}
error:
iLock = 0;
return;
}
int cafiine_fread(int sock, int *result, void *ptr, int size, int fd) {
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
int ret;
char buffer[1 + 8];
buffer[0] = BYTE_READ;
*(int *)(buffer + 1) = size;
*(int *)(buffer + 5) = fd;
ret = sendwait(sock, buffer, 1 + 8);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret == BYTE_NORMAL);
int sz;
ret = recvwait(sock, &sz, 4);
CHECK_ERROR(ret < 0);
ret = recvwaitlen(sock, ptr, sz);
*result = sz - ret;
ret = sendbyte(sock, BYTE_OK);
CHECK_ERROR(ret < 0);
iLock = 0;
return 0;
error:
iLock = 0;
return -1;
}
int cafiine_fclose(int sock, int *result, int fd,int dumpclose) {
while (iLock)
usleep(5000);
iLock = 1;
CHECK_ERROR(sock == -1);
int ret;
char buffer[1 + 4];
buffer[0] = BYTE_CLOSE;
if(dumpclose)buffer[0] = BYTE_CLOSE_DUMP;
*(int *)(buffer + 1) = fd;
ret = sendwait(sock, buffer, 1 + 4);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret == BYTE_NORMAL);
ret = recvwait(sock, result, 4);
CHECK_ERROR(ret < 0);
iLock = 0;
return 0;
error:
iLock = 0;
return -1;
}
int saviine_start_injection(int sock, long persistentID,int * mask){
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
{
char buffer[1+4];
buffer[0] = BYTE_INJECTSTART;
*(long *)(buffer + 1) = persistentID;
ret = sendwait(sock, buffer, 1 + 4);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
ret = recvwait(sock, mask, 4);
CHECK_ERROR(ret < 0);
CHECK_ERROR((*mask & MASK_NORMAL) != MASK_NORMAL);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
result = 1;
}
error:
iLock = 0;
return result;
}
int saviine_end_injection(int sock){
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
{
ret = sendbyte(sock, BYTE_INJECTEND);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_OK);
result = 1;
}
error:
iLock = 0;
return result;
}
int saviine_start_dump(int sock, long persistentID,int * mask){
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
{
char buffer[1+4];
buffer[0] = BYTE_DUMPSTART;
*(long *)(buffer + 1) = persistentID;
ret = sendwait(sock, buffer, 1 + 4);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
ret = recvwait(sock, mask, 4);
CHECK_ERROR(ret < 0);
CHECK_ERROR((*mask & MASK_NORMAL) != MASK_NORMAL);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
result = 1;
}
error:
iLock = 0;
return result;
}
int saviine_end_dump(int sock){
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
{
ret = sendbyte(sock, BYTE_DUMPEND);
CHECK_ERROR(ret < 0);
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_OK);
result = 1;
}
error:
iLock = 0;
return result;
}
int saviine_readdir(int sock, char * path,char * resultname, int * resulttype, int * filesize){
while (iLock)
usleep(5000);
iLock = 1;
int result = 0;
CHECK_ERROR(sock == -1);
int ret;
// create and send buffer with : [cmd id][len_path][path][filesize]
{
int size = 0;
while (path[size++]);
char buffer[1+4+size];
buffer[0] = BYTE_READ_DIR;
*(int *)(buffer + 1) = size;
for (ret = 0; ret < size; ret++)
buffer[5 + ret] = path[ret];
// send buffer, wait for reply
ret = sendwait(sock, buffer, 1+4+size);
CHECK_ERROR(ret < 0);
// wait reply
ret = recvbyte(sock);
CHECK_ERROR(ret != BYTE_OK);
ret = recvbyte(sock);
CHECK_ERROR(ret != BYTE_FILE && ret != BYTE_FOLDER);
*resulttype = ret;
size = 0;
ret = recvwait(sock, &size, 4);
CHECK_ERROR(ret < 0);
ret = recvwait(sock, resultname, size+1);
CHECK_ERROR(ret < 0);
size = 0;
ret = recvwait(sock, &size, 4);
CHECK_ERROR(ret < 0);
*filesize = size;
ret = recvbyte(sock);
CHECK_ERROR(ret < 0);
CHECK_ERROR(ret != BYTE_SPECIAL);
result = 1;
}
error:
iLock = 0;
return result;
}
void cafiine_send_ping(int sock, int val1, int val2) {
while (iLock)
usleep(5000);
iLock = 1;
int ret;
char buffer[1 + 4 + 4];
buffer[0] = BYTE_PING;
*(int *)(buffer + 1) = val1;
*(int *)(buffer + 5) = val2;
ret = sendwait(sock, buffer, 1 + 4 + 4);
CHECK_ERROR(ret < 0);
error:
iLock = 0;
return;
}
int recvwait(int sock, void *buffer, int len) {
int ret;
while (len > 0) {
ret = recv(sock, buffer, len, 0);
CHECK_ERROR(ret < 0);
len -= ret;
buffer += ret;
}
return 0;
error:
return ret;
}
int recvwaitlen(int sock, void *buffer, int len) {
int ret;
while (len > 0) {
ret = recv(sock, buffer, len, 0);
CHECK_ERROR(ret < 0);
len -= ret;
buffer += ret;
}
return 0;
error:
return len;
}
int recvbyte(int sock) {
unsigned char buffer[1];
int ret;
ret = recvwait(sock, buffer, 1);
if (ret < 0) return ret;
return buffer[0];
}
int sendwait(int sock, const void *buffer, int len) {
int ret;
while (len > 0) {
ret = send(sock, buffer, len, 0);
CHECK_ERROR(ret < 0);
len -= ret;
buffer += ret;
}
return 0;
error:
return ret;
}
void log_string(int sock, const char* str, char flag_byte) {
if(sock == -1) {
return;
}
while (iLock)
usleep(5000);
iLock = 1;
int i;
int len_str = 0;
while (str[len_str++]);
//
{
char buffer[1 + 4 + len_str];
buffer[0] = flag_byte;
*(int *)(buffer + 1) = len_str;
for (i = 0; i < len_str; i++)
buffer[5 + i] = str[i];
buffer[5 + i] = 0;
sendwait(sock, buffer, 1 + 4 + len_str);
}
iLock = 0;
}
int sendbyte(int sock, unsigned char byte) {
unsigned char buffer[1];
buffer[0] = byte;
return sendwait(sock, buffer, 1);
}

Binary file not shown.