Upgrade to devkitPro v29 and reorganize
This commit is contained in:
parent
c431bce8dc
commit
b59ef61113
7
Makefile
7
Makefile
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define FS_DEFS_H
|
||||
|
||||
#include "types.h"
|
||||
#include "kernel_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -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;
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
17
src/entry.c
17
src/entry.c
@ -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();
|
||||
@ -25,3 +24,7 @@ int __entry_menu(int argc, char **argv) {
|
||||
//! *******************************************************************
|
||||
return Menu_Main();
|
||||
}
|
||||
|
||||
int __entry_menu(int argc, char **argv) {
|
||||
return entry();
|
||||
}
|
@ -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;
|
||||
@ -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;
|
||||
@ -108,7 +112,8 @@ 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) {
|
||||
r->_errno = ENODEV;
|
||||
@ -158,7 +163,8 @@ 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) {
|
||||
@ -180,7 +186,8 @@ 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) {
|
||||
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;
|
||||
@ -193,14 +200,16 @@ 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) {
|
||||
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;
|
||||
@ -209,7 +218,8 @@ static off_t sd_fat_seek_r(struct _reent *r, int fd, off_t pos, int dir) {
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
@ -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) {
|
||||
}
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
@ -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,7 +363,8 @@ 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) {
|
||||
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;
|
||||
@ -373,7 +401,8 @@ 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) {
|
||||
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;
|
||||
@ -394,7 +423,8 @@ 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) {
|
||||
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;
|
||||
@ -415,7 +445,8 @@ 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) {
|
||||
r->_errno = ENODEV;
|
||||
@ -465,12 +496,14 @@ 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) {
|
||||
r->_errno = ENODEV;
|
||||
@ -501,7 +534,8 @@ 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) {
|
||||
r->_errno = ENODEV;
|
||||
@ -531,7 +565,8 @@ 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) {
|
||||
r->_errno = ENODEV;
|
||||
@ -570,7 +605,8 @@ 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) {
|
||||
r->_errno = ENODEV;
|
||||
@ -600,7 +636,8 @@ 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) {
|
||||
r->_errno = ENODEV;
|
||||
@ -663,7 +700,8 @@ 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) {
|
||||
r->_errno = ENODEV;
|
||||
@ -681,7 +719,7 @@ static DIR_ITER *sd_fat_diropen_r(struct _reent *r, DIR_ITER *dirState, const ch
|
||||
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,7 +739,8 @@ 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) {
|
||||
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;
|
||||
@ -713,14 +753,16 @@ 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) {
|
||||
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;
|
||||
@ -733,14 +775,16 @@ 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) {
|
||||
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;
|
||||
@ -752,7 +796,8 @@ static int sd_fat_dirnext_r(struct _reent *r, DIR_ITER *dirState, char *filename
|
||||
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,7 +828,7 @@ 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),
|
||||
@ -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;
|
||||
@ -835,7 +884,11 @@ static int sd_fat_add_device(const char *name, const char *mount_path, void *pCl
|
||||
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);
|
||||
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;
|
||||
@ -843,7 +896,9 @@ static int sd_fat_add_device(const char *name, const char *mount_path, void *pCl
|
||||
}
|
||||
|
||||
devpath = (char*)(priv+1);
|
||||
if(mount_path != NULL){
|
||||
strcpy(devpath, mount_path);
|
||||
}
|
||||
|
||||
// setup private data
|
||||
priv->mount_path = devpath;
|
||||
@ -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,13 +980,16 @@ 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) {
|
||||
if(devoptab->deviceData)
|
||||
{
|
||||
sd_fat_private_t *priv = (sd_fat_private_t *)devoptab->deviceData;
|
||||
*pClient = priv->pClient;
|
||||
*pCmd = priv->pCmd;
|
||||
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);
|
||||
@ -922,7 +1004,8 @@ 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
|
||||
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include "address.h"
|
||||
#include "../dynamic_libs/os_functions.h"
|
||||
|
||||
int validateAddressRange(int starting_address, int ending_address) {
|
@ -1,8 +1,6 @@
|
||||
#ifndef TCPGECKO_STACK_H
|
||||
#define TCPGECKO_STACK_H
|
||||
|
||||
#include "kernel_types.h"
|
||||
|
||||
typedef struct OSThread;
|
||||
|
||||
typedef struct OSThreadLink {
|
@ -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;
|
@ -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
|
@ -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
|
@ -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;
|
@ -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
561
src/tcpgecko/net.c
Normal 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);
|
||||
}
|
@ -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"
|
@ -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);
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "sd_ip_reader.hpp"
|
||||
#include "sd_ip_reader.h"
|
||||
|
||||
char ipFromSd[16];
|
||||
bool hasReadIP = false;
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "logger.h"
|
||||
#include "../utils/logger.h"
|
||||
#include "../common/common.h"
|
||||
#include "../fs/CFile.hpp"
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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;
|
@ -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);
|
@ -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"
|
||||
|
@ -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) {
|
@ -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);
|
@ -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");
|
@ -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"
|
||||
|
561
src/utils/net.c
561
src/utils/net.c
@ -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);
|
||||
}
|
BIN
tcpgecko.elf
BIN
tcpgecko.elf
Binary file not shown.
Loading…
Reference in New Issue
Block a user