Formatting

This commit is contained in:
Maschell 2018-03-11 16:44:04 +01:00
parent ab456c08c9
commit 94d64db894
24 changed files with 1273 additions and 1300 deletions

View File

@ -3,39 +3,33 @@
#include <stdio.h>
#include "CFile.hpp"
CFile::CFile()
{
CFile::CFile() {
iFd = -1;
mem_file = NULL;
filesize = 0;
pos = 0;
}
CFile::CFile(const std::string & filepath, eOpenTypes mode)
{
CFile::CFile(const std::string & filepath, eOpenTypes mode) {
iFd = -1;
this->open(filepath, mode);
}
CFile::CFile(const u8 * mem, s32 size)
{
CFile::CFile(const u8 * mem, s32 size) {
iFd = -1;
this->open(mem, size);
}
CFile::~CFile()
{
CFile::~CFile() {
this->close();
}
s32 CFile::open(const std::string & filepath, eOpenTypes mode)
{
s32 CFile::open(const std::string & filepath, eOpenTypes mode) {
this->close();
s32 openMode = 0;
switch(mode)
{
switch(mode) {
default:
case ReadOnly:
openMode = O_RDONLY;
@ -66,8 +60,7 @@ s32 CFile::open(const std::string & filepath, eOpenTypes mode)
return 0;
}
s32 CFile::open(const u8 * mem, s32 size)
{
s32 CFile::open(const u8 * mem, s32 size) {
this->close();
mem_file = mem;
@ -76,8 +69,7 @@ s32 CFile::open(const u8 * mem, s32 size)
return 0;
}
void CFile::close()
{
void CFile::close() {
if(iFd >= 0)
::close(iFd);
@ -87,10 +79,8 @@ void CFile::close()
pos = 0;
}
s32 CFile::read(u8 * ptr, size_t size)
{
if(iFd >= 0)
{
s32 CFile::read(u8 * ptr, size_t size) {
if(iFd >= 0) {
s32 ret = ::read(iFd, ptr,size);
if(ret > 0)
pos += ret;
@ -105,8 +95,7 @@ s32 CFile::read(u8 * ptr, size_t size)
if(readsize <= 0)
return readsize;
if(mem_file != NULL)
{
if(mem_file != NULL) {
memcpy(ptr, mem_file+pos, readsize);
pos += readsize;
return readsize;
@ -115,13 +104,10 @@ s32 CFile::read(u8 * ptr, size_t size)
return -1;
}
s32 CFile::write(const u8 * ptr, size_t size)
{
if(iFd >= 0)
{
s32 CFile::write(const u8 * ptr, size_t size) {
if(iFd >= 0) {
size_t done = 0;
while(done < size)
{
while(done < size) {
s32 ret = ::write(iFd, ptr, size - done);
if(ret <= 0)
return ret;
@ -136,39 +122,29 @@ s32 CFile::write(const u8 * ptr, size_t size)
return -1;
}
s32 CFile::seek(long int offset, s32 origin)
{
s32 CFile::seek(long int offset, s32 origin) {
s32 ret = 0;
s64 newPos = pos;
if(origin == SEEK_SET)
{
if(origin == SEEK_SET) {
newPos = offset;
}
else if(origin == SEEK_CUR)
{
} else if(origin == SEEK_CUR) {
newPos += offset;
}
else if(origin == SEEK_END)
{
} else if(origin == SEEK_END) {
newPos = filesize+offset;
}
if(newPos < 0)
{
if(newPos < 0) {
pos = 0;
}
else {
} else {
pos = newPos;
}
if(iFd >= 0)
ret = ::lseek(iFd, pos, SEEK_SET);
if(mem_file != NULL)
{
if(pos > filesize)
{
if(mem_file != NULL) {
if(pos > filesize) {
pos = filesize;
}
}
@ -176,15 +152,13 @@ s32 CFile::seek(long int offset, s32 origin)
return ret;
}
s32 CFile::fwrite(const char *format, ...)
{
s32 CFile::fwrite(const char *format, ...) {
s32 result = -1;
char * tmp = NULL;
va_list va;
va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp)
{
if((vasprintf(&tmp, format, va) >= 0) && tmp) {
result = this->write((u8 *)tmp, strlen(tmp));
}
va_end(va);

View File

@ -8,11 +8,9 @@
#include <dynamic_libs/os_types.h>
#include <unistd.h>
class CFile
{
class CFile {
public:
enum eOpenTypes
{
enum eOpenTypes {
ReadOnly,
WriteOnly,
ReadWrite,
@ -43,9 +41,15 @@ class CFile
s32 write(const u8 * ptr, size_t size);
s32 fwrite(const char *format, ...);
s32 seek(long int offset, s32 origin);
u64 tell() { return pos; };
u64 size() { return filesize; };
void rewind() { this->seek(0, SEEK_SET); };
u64 tell() {
return pos;
};
u64 size() {
return filesize;
};
void rewind() {
this->seek(0, SEEK_SET);
};
protected:
s32 iFd;

View File

@ -35,26 +35,22 @@
#include "DirList.h"
#include "utils/StringTools.h"
DirList::DirList()
{
DirList::DirList() {
Flags = 0;
Filter = 0;
Depth = 0;
}
DirList::DirList(const std::string & path, const char *filter, u32 flags, u32 maxDepth)
{
DirList::DirList(const std::string & path, const char *filter, u32 flags, u32 maxDepth) {
this->LoadPath(path, filter, flags, maxDepth);
this->SortList();
}
DirList::~DirList()
{
DirList::~DirList() {
ClearList();
}
bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags, u32 maxDepth)
{
bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags, u32 maxDepth) {
if(folder.empty()) return false;
Flags = flags;
@ -79,8 +75,7 @@ bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags
return InternalLoadPath(folderpath);
}
bool DirList::InternalLoadPath(std::string &folderpath)
{
bool DirList::InternalLoadPath(std::string &folderpath) {
if(folderpath.size() < 3)
return false;
@ -91,18 +86,15 @@ bool DirList::InternalLoadPath(std::string &folderpath)
if (dir == NULL)
return false;
while ((dirent = readdir(dir)) != 0)
{
while ((dirent = readdir(dir)) != 0) {
bool isDir = dirent->d_type & DT_DIR;
const char *filename = dirent->d_name;
if(isDir)
{
if(isDir) {
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
continue;
if((Flags & CheckSubfolders) && (Depth > 0))
{
if((Flags & CheckSubfolders) && (Depth > 0)) {
s32 length = folderpath.size();
if(length > 2 && folderpath[length-1] != '/') {
folderpath += '/';
@ -117,23 +109,18 @@ bool DirList::InternalLoadPath(std::string &folderpath)
if(!(Flags & Dirs))
continue;
}
else if(!(Flags & Files))
{
} else if(!(Flags & Files)) {
continue;
}
if(Filter)
{
if(Filter) {
char * fileext = strrchr(filename, '.');
if(!fileext)
continue;
if(StringTools::strtokcmp(fileext, Filter, ",") == 0)
AddEntrie(folderpath, filename, isDir);
}
else
{
} else {
AddEntrie(folderpath, filename, isDir);
}
}
@ -142,8 +129,7 @@ bool DirList::InternalLoadPath(std::string &folderpath)
return true;
}
void DirList::AddEntrie(const std::string &filepath, const char * filename, bool isDir)
{
void DirList::AddEntrie(const std::string &filepath, const char * filename, bool isDir) {
if(!filename)
return;
@ -152,8 +138,7 @@ void DirList::AddEntrie(const std::string &filepath, const char * filename, bool
FileInfo.resize(pos+1);
FileInfo[pos].FilePath = (char *) malloc(filepath.size()+strlen(filename)+2);
if(!FileInfo[pos].FilePath)
{
if(!FileInfo[pos].FilePath) {
FileInfo.resize(pos);
return;
}
@ -162,10 +147,8 @@ void DirList::AddEntrie(const std::string &filepath, const char * filename, bool
FileInfo[pos].isDir = isDir;
}
void DirList::ClearList()
{
for(u32 i = 0; i < FileInfo.size(); ++i)
{
void DirList::ClearList() {
for(u32 i = 0; i < FileInfo.size(); ++i) {
if(FileInfo[i].FilePath) {
free(FileInfo[i].FilePath);
FileInfo[i].FilePath = NULL;
@ -176,16 +159,14 @@ void DirList::ClearList()
std::vector<DirEntry>().swap(FileInfo);
}
const char * DirList::GetFilename(s32 ind) const
{
const char * DirList::GetFilename(s32 ind) const {
if (!valid(ind))
return "";
return StringTools::FullpathToFilename(FileInfo[ind].FilePath);
}
static bool SortCallback(const DirEntry & f1, const DirEntry & f2)
{
static bool SortCallback(const DirEntry & f1, const DirEntry & f2) {
if(f1.isDir && !(f2.isDir)) return true;
if(!(f1.isDir) && f2.isDir) return false;
@ -198,20 +179,17 @@ static bool SortCallback(const DirEntry & f1, const DirEntry & f2)
return true;
}
void DirList::SortList()
{
void DirList::SortList() {
if(FileInfo.size() > 1)
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
}
void DirList::SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b))
{
void DirList::SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
if(FileInfo.size() > 1)
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
}
u64 DirList::GetFilesize(s32 index) const
{
u64 DirList::GetFilesize(s32 index) const {
struct stat st;
const char *path = GetFilepath(index);
@ -221,13 +199,11 @@ u64 DirList::GetFilesize(s32 index) const
return st.st_size;
}
s32 DirList::GetFileIndex(const char *filename) const
{
s32 DirList::GetFileIndex(const char *filename) const {
if(!filename)
return -1;
for (u32 i = 0; i < FileInfo.size(); ++i)
{
for (u32 i = 0; i < FileInfo.size(); ++i) {
if (strcasecmp(GetFilename(i), filename) == 0)
return i;
}

View File

@ -31,14 +31,12 @@
#include <string>
#include <dynamic_libs/os_types.h>
typedef struct
{
typedef struct {
char * FilePath;
bool isDir;
} DirEntry;
class DirList
{
class DirList {
public:
//!Constructor
DirList(void);
@ -55,15 +53,23 @@ public:
const char * GetFilename(s32 index) const;
//! Get the a filepath of the list
//!\param list index
const char *GetFilepath(s32 index) const { if (!valid(index)) return ""; else return FileInfo[index].FilePath; }
const char *GetFilepath(s32 index) const {
if (!valid(index)) return "";
else return FileInfo[index].FilePath;
}
//! Get the a filesize of the list
//!\param list index
u64 GetFilesize(s32 index) const;
//! Is index a dir or a file
//!\param list index
bool IsDir(s32 index) const { if(!valid(index)) return false; return FileInfo[index].isDir; };
bool IsDir(s32 index) const {
if(!valid(index)) return false;
return FileInfo[index].isDir;
};
//! Get the filecount of the whole list
s32 GetFilecount() const { return FileInfo.size(); };
s32 GetFilecount() const {
return FileInfo.size();
};
//! Sort list by filepath
void SortList();
//! Custom sort command for custom sort functions definitions
@ -71,8 +77,7 @@ public:
//! Get the index of the specified filename
s32 GetFileIndex(const char *filename) const;
//! Enum for search/filter flags
enum
{
enum {
Files = 0x01,
Dirs = 0x02,
CheckSubfolders = 0x08,
@ -85,7 +90,9 @@ protected:
//! Clear the list
void ClearList();
//! Check if valid pos is requested
inline bool valid(u32 pos) const { return (pos < FileInfo.size()); };
inline bool valid(u32 pos) const {
return (pos < FileInfo.size());
};
u32 Flags;
u32 Depth;

View File

@ -28,8 +28,7 @@ s32 FSOSUtils::MountFS(void *pClient, void *pCmd, char **mount_path){
memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE);
// Mount sdcard
if (FSGetMountSource(pClient, pCmd, FS_SOURCETYPE_EXTERNAL, mountSrc, -1) == 0)
{
if (FSGetMountSource(pClient, pCmd, FS_SOURCETYPE_EXTERNAL, mountSrc, -1) == 0) {
result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1);
if((result == 0) && mount_path) {
*mount_path = (char*)malloc(strlen(mountPath) + 1);

View File

@ -21,8 +21,7 @@ s32 FSUtils::LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size){
lseek(iFd, 0, SEEK_SET);
u8 *buffer = (u8 *) malloc(filesize);
if (buffer == NULL)
{
if (buffer == NULL) {
close(iFd);
return -2;
}
@ -31,8 +30,7 @@ s32 FSUtils::LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size){
u32 done = 0;
s32 readBytes = 0;
while(done < filesize)
{
while(done < filesize) {
if(done + blocksize > filesize) {
blocksize = filesize - done;
}
@ -44,8 +42,7 @@ s32 FSUtils::LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size){
close(iFd);
if (done != filesize)
{
if (done != filesize) {
free(buffer);
buffer = NULL;
return -3;
@ -74,8 +71,7 @@ s32 FSUtils::CheckFile(const char * filepath){
dirnoslash[strlen(dirnoslash)-1] = '\0';
char * notRoot = strrchr(dirnoslash, '/');
if(!notRoot)
{
if(!notRoot) {
strcat(dirnoslash, "/");
}
@ -95,24 +91,19 @@ s32 FSUtils::CreateSubfolder(const char * fullpath){
strcpy(dirnoslash, fullpath);
s32 pos = strlen(dirnoslash)-1;
while(dirnoslash[pos] == '/')
{
while(dirnoslash[pos] == '/') {
dirnoslash[pos] = '\0';
pos--;
}
if(CheckFile(dirnoslash))
{
if(CheckFile(dirnoslash)) {
return 1;
}
else
{
} else {
char parentpath[strlen(dirnoslash)+2];
strcpy(parentpath, dirnoslash);
char * ptr = strrchr(parentpath, '/');
if(!ptr)
{
if(!ptr) {
//!Device root directory (must be with '/')
strcat(parentpath, "/");
struct stat filestat;
@ -131,8 +122,7 @@ s32 FSUtils::CreateSubfolder(const char * fullpath){
if(!result)
return 0;
if (mkdir(dirnoslash, 0777) == -1)
{
if (mkdir(dirnoslash, 0777) == -1) {
return 0;
}

View File

@ -65,8 +65,7 @@ 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;
@ -91,8 +90,7 @@ 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;
@ -113,8 +111,7 @@ 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;
@ -164,8 +161,7 @@ static int sd_fat_open_r (struct _reent *r, void *fileStruct, const char *path,
free(real_path);
if(result == 0)
{
if(result == 0) {
FSStat stats;
result = FSGetStatFile(dev->pClient, dev->pCmd, fd, &stats, -1);
if(result != 0) {
@ -187,8 +183,7 @@ static int sd_fat_open_r (struct _reent *r, void *fileStruct, const char *path,
}
static int sd_fat_close_r (struct _reent *r, void *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;
@ -201,16 +196,14 @@ static int sd_fat_close_r (struct _reent *r, void *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, void* 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;
@ -219,8 +212,7 @@ static off_t sd_fat_seek_r (struct _reent *r, void* fd, off_t pos, int dir)
OSLockMutex(file->dev->pMutex);
switch(dir)
{
switch(dir) {
case SEEK_SET:
file->pos = pos;
break;
@ -239,24 +231,21 @@ static off_t sd_fat_seek_r (struct _reent *r, void* 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, void *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;
}
@ -276,25 +265,19 @@ static ssize_t sd_fat_write_r (struct _reent *r, void *fd, const char *ptr, size
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;
}
@ -305,16 +288,14 @@ static ssize_t sd_fat_write_r (struct _reent *r, void *fd, const char *ptr, size
return done;
}
static ssize_t sd_fat_read_r (struct _reent *r, void* 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;
}
@ -334,24 +315,18 @@ static ssize_t sd_fat_read_r (struct _reent *r, void* 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;
@ -364,8 +339,7 @@ static ssize_t sd_fat_read_r (struct _reent *r, void* fd, char *ptr, size_t len)
}
static int sd_fat_fstat_r (struct _reent *r, void* 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;
@ -402,8 +376,7 @@ static int sd_fat_fstat_r (struct _reent *r, void* fd, struct stat *st)
return 0;
}
static int sd_fat_ftruncate_r (struct _reent *r, void* 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;
@ -424,8 +397,7 @@ static int sd_fat_ftruncate_r (struct _reent *r, void* fd, off_t len)
return 0;
}
static int sd_fat_fsync_r (struct _reent *r, void* 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;
@ -446,8 +418,7 @@ static int sd_fat_fsync_r (struct _reent *r, void* 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;
@ -497,14 +468,12 @@ 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;
@ -535,8 +504,7 @@ 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;
@ -566,8 +534,7 @@ 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;
@ -606,8 +573,7 @@ static int sd_fat_rename_r (struct _reent *r, const char *oldName, const char *n
}
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;
@ -637,8 +603,7 @@ 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;
@ -701,8 +666,7 @@ 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;
@ -728,8 +692,7 @@ static DIR_ITER *sd_fat_diropen_r (struct _reent *r, DIR_ITER *dirState, const c
OSUnlockMutex(dev->pMutex);
if(result < 0)
{
if(result < 0) {
r->_errno = result;
return NULL;
}
@ -740,8 +703,7 @@ static DIR_ITER *sd_fat_diropen_r (struct _reent *r, DIR_ITER *dirState, const c
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;
@ -754,16 +716,14 @@ 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;
@ -776,16 +736,14 @@ 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;
@ -797,8 +755,7 @@ static int sd_fat_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filenam
FSDirEntry * dir_entry = (FSDirEntry *)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);
@ -808,8 +765,7 @@ static int sd_fat_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filenam
// 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;
@ -860,8 +816,7 @@ static const devoptab_t devops_sd_fat = {
};
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;
@ -961,8 +916,7 @@ void deleteDevTabsNames(){
}
}
static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd, char **mountPath)
{
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;
@ -981,8 +935,7 @@ static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd,
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;
if(pClient != NULL) *pClient = priv->pClient;
if(pCmd != NULL) *pCmd = priv->pCmd;
@ -1041,8 +994,7 @@ s32 unmount_sd_fat(const char *path){
char *mountPath = 0;
int result = sd_fat_remove_device(path, &pClient, &pCmd, &mountPath);
if(result == 0)
{
if(result == 0) {
FSOSUtils::UmountFS(pClient, pCmd, mountPath);
FSDelClient(pClient);
free(pClient);

View File

@ -9,8 +9,7 @@ extern "C" {
#endif
// original structure in the kernel that is originally 0x1270 long
typedef struct
{
typedef struct {
uint32_t version_cos_xml; // version tag from cos.xml
uint64_t os_version; // os_version from app.xml
uint64_t title_id; // title_id tag from app.xml
@ -71,8 +70,7 @@ typedef struct
// Our own cos/app.xml struct which uses only uses as much memory as really needed, since many things are just zeros in the above structure
// This structure is only 0x64 bytes long + RPX name length (dynamic up to 0x1000 theoretically)
typedef struct
{
typedef struct {
uint32_t version_cos_xml; // version tag from cos.xml
uint64_t os_version; // os_version from app.xml
uint64_t title_id; // title_id tag from app.xml

View File

@ -24,8 +24,7 @@
#include "fs/CFile.hpp"
#include "utils/StringTools.h"
typedef struct _MSG
{
typedef struct _MSG {
u32 id;
char* msgstr;
struct _MSG *next;
@ -37,20 +36,17 @@ static MSG *baseMSG = 0;
/* Defines the so called `hashpjw' function by P.J. Weinberger
[see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
1986, 1987 Bell Telephone Laboratories, Inc.] */
static inline u32 hash_string(const char *str_param)
{
static inline u32 hash_string(const char *str_param) {
u32 hval, g;
const char *str = str_param;
/* Compute the hash value for the given string. */
hval = 0;
while (*str != '\0')
{
while (*str != '\0') {
hval <<= 4;
hval += (u8) *str++;
g = hval & ((u32) 0xf << (HASHWORDBITS - 4));
if (g != 0)
{
if (g != 0) {
hval ^= g >> (HASHWORDBITS - 8);
hval ^= g;
}
@ -60,8 +56,7 @@ static inline u32 hash_string(const char *str_param)
/* Expand some escape sequences found in the argument string. */
static char *
expand_escape(const char *str)
{
expand_escape(const char *str) {
char *retval, *rp;
const char *cp = str;
@ -72,12 +67,10 @@ expand_escape(const char *str)
while (cp[0] != '\0' && cp[0] != '\\')
*rp++ = *cp++;
if (cp[0] == '\0') goto terminate;
do
{
do {
/* Here cp[0] == '\\'. */
switch (*++cp)
{
switch (*++cp) {
case '\"': /* " */
*rp++ = '\"';
++cp;
@ -121,17 +114,14 @@ expand_escape(const char *str)
case '4':
case '5':
case '6':
case '7':
{
case '7': {
int ch = *cp++ - '0';
if (*cp >= '0' && *cp <= '7')
{
if (*cp >= '0' && *cp <= '7') {
ch *= 8;
ch += *cp++ - '0';
if (*cp >= '0' && *cp <= '7')
{
if (*cp >= '0' && *cp <= '7') {
ch *= 8;
ch += *cp++ - '0';
}
@ -149,36 +139,31 @@ expand_escape(const char *str)
} while (cp[0] != '\0');
/* Terminate string. */
terminate: *rp = '\0';
terminate:
*rp = '\0';
return retval;
}
static MSG *findMSG(u32 id)
{
static MSG *findMSG(u32 id) {
MSG *msg;
for (msg = baseMSG; msg; msg = msg->next)
{
for (msg = baseMSG; msg; msg = msg->next) {
if (msg->id == id) return msg;
}
return NULL;
}
static MSG *setMSG(const char *msgid, const char *msgstr)
{
static MSG *setMSG(const char *msgid, const char *msgstr) {
u32 id = hash_string(msgid);
MSG *msg = findMSG(id);
if (!msg)
{
if (!msg) {
msg = (MSG *) malloc(sizeof(MSG));
msg->id = id;
msg->msgstr = NULL;
msg->next = baseMSG;
baseMSG = msg;
}
if (msg)
{
if (msgstr)
{
if (msg) {
if (msgstr) {
if (msg->msgstr) free(msg->msgstr);
//msg->msgstr = strdup(msgstr);
msg->msgstr = expand_escape(msgstr);
@ -188,10 +173,8 @@ static MSG *setMSG(const char *msgid, const char *msgstr)
return NULL;
}
extern "C" void gettextCleanUp(void)
{
while (baseMSG)
{
extern "C" void gettextCleanUp(void) {
while (baseMSG) {
MSG *nextMsg = baseMSG->next;
free(baseMSG->msgstr);
free(baseMSG);
@ -199,8 +182,7 @@ extern "C" void gettextCleanUp(void)
}
}
extern "C" bool gettextLoadLanguage(const char* langFile)
{
extern "C" bool gettextLoadLanguage(const char* langFile) {
char *lastID = NULL;
gettextCleanUp();
@ -215,8 +197,7 @@ extern "C" bool gettextLoadLanguage(const char* langFile)
//! remove all windows crap signs
size_t position;
while(1)
{
while(1) {
position = strBuffer.find('\r');
if(position == std::string::npos)
break;
@ -230,38 +211,31 @@ extern "C" bool gettextLoadLanguage(const char* langFile)
if(lines.empty())
return false;
for(unsigned int i = 0; i < lines.size(); i++)
{
for(unsigned int i = 0; i < lines.size(); i++) {
std::string & line = lines[i];
// lines starting with # are comments
if (line[0] == '#')
continue;
else if (strncmp(line.c_str(), "msgid \"", 7) == 0)
{
else if (strncmp(line.c_str(), "msgid \"", 7) == 0) {
char *msgid, *end;
if (lastID)
{
if (lastID) {
free(lastID);
lastID = NULL;
}
msgid = &line[7];
end = strrchr(msgid, '"');
if (end && end - msgid > 1)
{
if (end && end - msgid > 1) {
*end = 0;
lastID = strdup(msgid);
}
}
else if (strncmp(line.c_str(), "msgstr \"", 8) == 0)
{
} else if (strncmp(line.c_str(), "msgstr \"", 8) == 0) {
char *msgstr, *end;
if (lastID == NULL) continue;
msgstr = &line[8];
end = strrchr(msgstr, '"');
if (end && end - msgstr > 1)
{
if (end && end - msgstr > 1) {
*end = 0;
setMSG(lastID, msgstr);
}
@ -273,8 +247,7 @@ extern "C" bool gettextLoadLanguage(const char* langFile)
return true;
}
extern "C" const char *gettext(const char *msgid)
{
extern "C" const char *gettext(const char *msgid) {
if(!msgid) return NULL;
MSG *msg = findMSG(hash_string(msgid));
if (msg && msg->msgstr) return msg->msgstr;

View File

@ -20,27 +20,22 @@ AsyncDeleter * AsyncDeleter::deleterInstance = NULL;
AsyncDeleter::AsyncDeleter()
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff)
, exitApplication(false)
{
, exitApplication(false) {
}
AsyncDeleter::~AsyncDeleter()
{
AsyncDeleter::~AsyncDeleter() {
exitApplication = true;
}
void AsyncDeleter::triggerDeleteProcess(void)
{
void AsyncDeleter::triggerDeleteProcess(void) {
if(!deleterInstance)
deleterInstance = new AsyncDeleter;
//! to trigger the event after GUI process is finished execution
//! this function is used to swap elements from one to next array
if(!deleterInstance->deleteElements.empty())
{
if(!deleterInstance->deleteElements.empty()) {
deleterInstance->deleteMutex.lock();
while(!deleterInstance->deleteElements.empty())
{
while(!deleterInstance->deleteElements.empty()) {
deleterInstance->realDeleteElements.push(deleterInstance->deleteElements.front());
deleterInstance->deleteElements.pop();
}
@ -49,15 +44,12 @@ void AsyncDeleter::triggerDeleteProcess(void)
}
}
void AsyncDeleter::executeThread(void)
{
while(!exitApplication || !realDeleteElements.empty())
{
void AsyncDeleter::executeThread(void) {
while(!exitApplication || !realDeleteElements.empty()) {
if(realDeleteElements.empty()) suspendThread();
//! delete elements that require post process deleting
//! because otherwise they would block or do invalid access on GUI thread
while(!realDeleteElements.empty())
{
while(!realDeleteElements.empty()) {
deleteMutex.lock();
AsyncDeleter::Element *element = realDeleteElements.front();
realDeleteElements.pop();

View File

@ -21,47 +21,42 @@
#include "CThread.h"
#include "CMutex.h"
class AsyncDeleter : public CThread
{
class AsyncDeleter : public CThread {
public:
static void destroyInstance()
{
static void destroyInstance() {
if(deleterInstance != NULL) {
delete deleterInstance;
deleterInstance = NULL;
}
}
class Element
{
class Element {
public:
Element() {}
virtual ~Element() {}
};
static void pushForDelete(AsyncDeleter::Element *e)
{
if(!deleterInstance)
static void pushForDelete(AsyncDeleter::Element *e) {
if(!deleterInstance) {
deleterInstance = new AsyncDeleter;
}
deleterInstance->deleteElements.push(e);
}
static bool deleteListEmpty()
{
if(!deleterInstance)
static bool deleteListEmpty() {
if(!deleterInstance) {
return true;
}
return deleterInstance->deleteElements.empty();
}
static bool realListEmpty()
{
if(!deleterInstance)
static bool realListEmpty() {
if(!deleterInstance) {
return true;
}
return deleterInstance->realDeleteElements.empty();
}
static void triggerDeleteProcess(void);
private:

View File

@ -20,8 +20,7 @@
#include <malloc.h>
#include <dynamic_libs/os_functions.h>
class CMutex
{
class CMutex {
public:
CMutex() {
pMutex = malloc(OS_MUTEX_SIZE);
@ -53,8 +52,7 @@ private:
void *pMutex;
};
class CMutexLock
{
class CMutexLock {
public:
CMutexLock() {
mutex.lock();

View File

@ -23,8 +23,7 @@
#include <dynamic_libs/os_functions.h>
#include "utils/logger.h"
class CThread
{
class CThread {
public:
typedef void (* Callback)(CThread *thread, void *arg);
@ -33,8 +32,7 @@ public:
: pThread(NULL)
, pThreadStack(NULL)
, pCallback(callback)
, pCallbackArg(callbackArg)
{
, pCallbackArg(callbackArg) {
//! save attribute assignment
iAttributes = iAttr;
//! allocate the thread
@ -42,44 +40,61 @@ public:
//! allocate the stack
pThreadStack = (u8 *) memalign(0x20, iStackSize);
//! create the thread
if(pThread && pThreadStack)
if(pThread && pThreadStack) {
OSCreateThread(pThread, &CThread::threadCallback, 1, this, (u32)pThreadStack+iStackSize, iStackSize, iPriority, iAttributes);
}
}
//! destructor
virtual ~CThread() { shutdownThread(); }
virtual ~CThread() {
shutdownThread();
}
static CThread *create(CThread::Callback callback, void *callbackArg, s32 iAttr = eAttributeNone, s32 iPriority = 16, s32 iStackSize = 0x8000)
{
static CThread *create(CThread::Callback callback, void *callbackArg, s32 iAttr = eAttributeNone, s32 iPriority = 16, s32 iStackSize = 0x8000) {
return ( new CThread(iAttr, iPriority, iStackSize, callback, callbackArg) );
}
//! Get thread ID
virtual void* getThread() const { return pThread; }
virtual void* getThread() const {
return pThread;
}
//! Thread entry function
virtual void executeThread(void)
{
virtual void executeThread(void) {
if(pCallback)
pCallback(this, pCallbackArg);
}
//! Suspend thread
virtual void suspendThread(void) { if(isThreadSuspended()) return; if(pThread) OSSuspendThread(pThread); }
virtual void suspendThread(void) {
if(isThreadSuspended()) return;
if(pThread) OSSuspendThread(pThread);
}
//! Resume thread
virtual void resumeThread(void) { if(!isThreadSuspended()) return; if(pThread) OSResumeThread(pThread); }
virtual void resumeThread(void) {
if(!isThreadSuspended()) return;
if(pThread) OSResumeThread(pThread);
}
//! Set thread priority
virtual void setThreadPriority(s32 prio) { if(pThread) OSSetThreadPriority(pThread, prio); }
virtual void setThreadPriority(s32 prio) {
if(pThread) OSSetThreadPriority(pThread, prio);
}
//! Check if thread is suspended
virtual bool isThreadSuspended(void) const { if(pThread) return OSIsThreadSuspended(pThread); return false; }
virtual bool isThreadSuspended(void) const {
if(pThread) return OSIsThreadSuspended(pThread);
return false;
}
//! Check if thread is terminated
virtual bool isThreadTerminated(void) const { if(pThread) return OSIsThreadTerminated(pThread); return false; }
virtual bool isThreadTerminated(void) const {
if(pThread) return OSIsThreadTerminated(pThread);
return false;
}
//! Check if thread is running
virtual bool isThreadRunning(void) const { return !isThreadSuspended() && !isThreadRunning(); }
virtual bool isThreadRunning(void) const {
return !isThreadSuspended() && !isThreadRunning();
}
//! Shutdown thread
virtual void shutdownThread(void)
{
virtual void shutdownThread(void) {
//! wait for thread to finish
if(pThread && !(iAttributes & eAttributeDetach))
{
if(pThread && !(iAttributes & eAttributeDetach)) {
while(isThreadSuspended()) {
resumeThread();
}
@ -89,14 +104,14 @@ public:
if(pThreadStack) {
free(pThreadStack);
}
if(pThread)
if(pThread) {
free(pThread);
}
pThread = NULL;
pThreadStack = NULL;
}
//! Thread attributes
enum eCThreadAttributes
{
enum eCThreadAttributes {
eAttributeNone = 0x07,
eAttributeAffCore0 = 0x01,
eAttributeAffCore1 = 0x02,
@ -105,8 +120,7 @@ public:
eAttributePinnedAff = 0x10
};
private:
static s32 threadCallback(s32 argc, void *arg)
{
static s32 threadCallback(s32 argc, void *arg) {
//! After call to start() continue with the internal function
((CThread *) arg)->executeThread();
return 0;

View File

@ -49,8 +49,7 @@ extern void (* MEMFreeToExpHeap)(s32 heap, void* ptr);
static s32 mem1_heap = -1;
static s32 bucket_heap = -1;
void memoryInitialize(void)
{
void memoryInitialize(void) {
s32 mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1);
u32 mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4);
void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4);
@ -64,8 +63,7 @@ void memoryInitialize(void)
bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0);
}
void memoryRelease(void)
{
void memoryRelease(void) {
MEMDestroyExpHeap(mem1_heap);
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3);
mem1_heap = -1;
@ -78,14 +76,12 @@ void memoryRelease(void)
//!-------------------------------------------------------------------------------------------
//! wraps
//!-------------------------------------------------------------------------------------------
void *__wrap_malloc(size_t size)
{
void *__wrap_malloc(size_t size) {
// pointer to a function resolve
return ((void * (*)(size_t))(*pMEMAllocFromDefaultHeap))(size);
}
void *__wrap_memalign(size_t align, size_t size)
{
void *__wrap_memalign(size_t align, size_t size) {
if (align < 4)
align = 4;
@ -93,15 +89,13 @@ void *__wrap_memalign(size_t align, size_t size)
return ((void * (*)(size_t, size_t))(*pMEMAllocFromDefaultHeapEx))(size, align);
}
void __wrap_free(void *p)
{
void __wrap_free(void *p) {
// pointer to a function resolve
if(p != 0)
((void (*)(void *))(*pMEMFreeToDefaultHeap))(p);
}
void *__wrap_calloc(size_t n, size_t size)
{
void *__wrap_calloc(size_t n, size_t size) {
void *p = __wrap_malloc(n * size);
if (p != 0) {
memset(p, 0, n * size);
@ -109,22 +103,24 @@ void *__wrap_calloc(size_t n, size_t size)
return p;
}
size_t __wrap_malloc_usable_size(void *p)
{
size_t __wrap_malloc_usable_size(void *p) {
//! TODO: this is totally wrong and needs to be addressed
return 0x7FFFFFFF;
}
void *__wrap_realloc(void *ptr, size_t size)
{
void *__wrap_realloc(void *ptr, size_t size) {
void *newPtr;
if (!ptr) {
newPtr = __wrap_malloc(size);
if (!newPtr) { goto error; }
if (!newPtr) {
goto error;
}
} else {
newPtr = __wrap_malloc(size);
if (!newPtr) { goto error; }
if (!newPtr) {
goto error;
}
memcpy(newPtr, ptr, size);
@ -148,69 +144,57 @@ error:
//!-------------------------------------------------------------------------------------------
//! reent versions
//!-------------------------------------------------------------------------------------------
void *__wrap__malloc_r(struct _reent *r, size_t size)
{
void *__wrap__malloc_r(struct _reent *r, size_t size) {
return __wrap_malloc(size);
}
void *__wrap__calloc_r(struct _reent *r, size_t n, size_t size)
{
void *__wrap__calloc_r(struct _reent *r, size_t n, size_t size) {
return __wrap_calloc(n, size);
}
void *__wrap__memalign_r(struct _reent *r, size_t align, size_t size)
{
void *__wrap__memalign_r(struct _reent *r, size_t align, size_t size) {
return __wrap_memalign(align, size);
}
void __wrap__free_r(struct _reent *r, void *p)
{
void __wrap__free_r(struct _reent *r, void *p) {
__wrap_free(p);
}
size_t __wrap__malloc_usable_size_r(struct _reent *r, void *p)
{
size_t __wrap__malloc_usable_size_r(struct _reent *r, void *p) {
return __wrap_malloc_usable_size(p);
}
void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
{
void *__wrap__realloc_r(struct _reent *r, void *p, size_t size) {
return __wrap_realloc(p, size);
}
//!-------------------------------------------------------------------------------------------
//! some wrappers
//!-------------------------------------------------------------------------------------------
void * MEM2_alloc(u32 size, u32 align)
{
void * MEM2_alloc(u32 size, u32 align) {
return __wrap_memalign(align, size);
}
void MEM2_free(void *ptr)
{
void MEM2_free(void *ptr) {
__wrap_free(ptr);
}
void * MEM1_alloc(u32 size, u32 align)
{
void * MEM1_alloc(u32 size, u32 align) {
if (align < 4)
align = 4;
return MEMAllocFromExpHeapEx(mem1_heap, size, align);
}
void MEM1_free(void *ptr)
{
void MEM1_free(void *ptr) {
MEMFreeToExpHeap(mem1_heap, ptr);
}
void * MEMBucket_alloc(u32 size, u32 align)
{
void * MEMBucket_alloc(u32 size, u32 align) {
if (align < 4)
align = 4;
return MEMAllocFromExpHeapEx(bucket_heap, size, align);
}
void MEMBucket_free(void *ptr)
{
void MEMBucket_free(void *ptr) {
MEMFreeToExpHeap(bucket_heap, ptr);
}

View File

@ -43,8 +43,7 @@ const char * StringTools::byte_to_binary(s32 x){
b[0] = '\0';
s32 z;
for (z = 128; z > 0; z >>= 1)
{
for (z = 128; z > 0; z >>= 1) {
strcat(b, ((x & z) == z) ? "1" : "0");
}
@ -70,8 +69,7 @@ const char * StringTools::fmt(const char * format, ...){
va_list va;
va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp)
{
if((vasprintf(&tmp, format, va) >= 0) && tmp) {
snprintf(strChar, sizeof(strChar), tmp);
free(tmp);
va_end(va);
@ -99,16 +97,14 @@ const wchar_t * StringTools::wfmt(const char * format, ...){
va_list va;
va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp)
{
if((vasprintf(&tmp, format, va) >= 0) && tmp) {
int bt;
s32 strlength = strlen(tmp);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512 );
free(tmp);
tmp = 0;
if(bt > 0)
{
if(bt > 0) {
strWChar[bt] = 0;
return (const wchar_t *) strWChar;
}
@ -127,8 +123,7 @@ s32 StringTools::strprintf(std::string &str, const char * format, ...){
va_list va;
va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp)
{
if((vasprintf(&tmp, format, va) >= 0) && tmp) {
str = tmp;
result = str.size();
}
@ -146,8 +141,7 @@ std::string StringTools::strfmt(const char * format, ...){
va_list va;
va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp)
{
if((vasprintf(&tmp, format, va) >= 0) && tmp) {
str = tmp;
}
va_end(va);
@ -182,10 +176,8 @@ s32 StringTools::strtokcmp(const char * string, const char * compare, const char
char * strTok = strtok(TokCopy, separator);
while (strTok != NULL)
{
if (strcasecmp(string, strTok) == 0)
{
while (strTok != NULL) {
if (strcasecmp(string, strTok) == 0) {
return 0;
}
strTok = strtok(NULL,separator);

View File

@ -21,17 +21,17 @@ TCPServer::TCPServer(s32 port,s32 priority) {
TCPServer::~TCPServer() {
CloseSockets();
DEBUG_FUNCTION_LINE("Thread will be closed\n");
//DEBUG_FUNCTION_LINE("Thread will be closed\n");
exitThread = 1;
ICInvalidateRange((void*)&exitThread, 4);
DCFlushRange((void*)&exitThread, 4);
if(pThread != NULL) {
DEBUG_FUNCTION_LINE("Deleting it!\n");
//DEBUG_FUNCTION_LINE("Deleting it!\n");
delete pThread;
}
DEBUG_FUNCTION_LINE("Thread done\n");
//DEBUG_FUNCTION_LINE("Thread done\n");
pThread = NULL;
}

View File

@ -69,8 +69,7 @@ void PatchInvidualMethodHooks(hooks_magic_t method_hooks[],s32 hook_information_
u32 my_instr_len = 6;
u32 instr_len = my_instr_len + skip_instr;
u32 flush_len = 4*instr_len;
for(s32 i = 0; i < method_hooks_count; i++)
{
for(s32 i = 0; i < method_hooks_count; i++) {
DEBUG_FUNCTION_LINE("Patching %s ...",method_hooks[i].functionName);
if(method_hooks[i].functionType == STATIC_FUNCTION && method_hooks[i].alreadyPatched == 1) {
if(isDynamicFunction((u32)OSEffectiveToPhysical((void*)method_hooks[i].realAddr))) {
@ -96,7 +95,9 @@ void PatchInvidualMethodHooks(hooks_magic_t method_hooks[],s32 hook_information_
continue;
}
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("%s is located at %08X!\n", method_hooks[i].functionName,real_addr);}
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("%s is located at %08X!\n", method_hooks[i].functionName,real_addr);
}
physical = (u32)OSEffectiveToPhysical((void*)real_addr);
if(!physical) {
@ -105,7 +106,9 @@ void PatchInvidualMethodHooks(hooks_magic_t method_hooks[],s32 hook_information_
continue;
}
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("%s physical is located at %08X!\n", method_hooks[i].functionName,physical);}
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("%s physical is located at %08X!\n", method_hooks[i].functionName,physical);
}
*(volatile u32 *)(call_addr) = (u32)(space) - CODE_RW_BASE_OFFSET;
@ -118,10 +121,13 @@ void PatchInvidualMethodHooks(hooks_magic_t method_hooks[],s32 hook_information_
// fill the restore instruction section
method_hooks[i].realAddr = real_addr;
method_hooks[i].restoreInstruction = *(space-1);
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("method_hooks[i].realAddr = %08X!\n", method_hooks[i].realAddr);}
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("method_hooks[i].restoreInstruction = %08X!\n",method_hooks[i].restoreInstruction) ;}
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("method_hooks[i].realAddr = %08X!\n", method_hooks[i].realAddr);
}
else{
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("method_hooks[i].restoreInstruction = %08X!\n",method_hooks[i].restoreInstruction) ;
}
} else {
log_printf("Error. Can't save %s for restoring!\n", method_hooks[i].functionName);
}
@ -170,8 +176,7 @@ void RestoreInvidualInstructions(hooks_magic_t method_hooks[],s32 hook_informati
resetLibs();
DEBUG_FUNCTION_LINE("Restoring given functions!\n");
s32 method_hooks_count = hook_information_size;
for(s32 i = 0; i < method_hooks_count; i++)
{
for(s32 i = 0; i < method_hooks_count; i++) {
DEBUG_FUNCTION_LINE("Restoring %s... ",method_hooks[i].functionName);
if(method_hooks[i].restoreInstruction == 0 || method_hooks[i].realAddr == 0) {
log_printf("I dont have the information for the restore =( skip\n");
@ -191,16 +196,17 @@ void RestoreInvidualInstructions(hooks_magic_t method_hooks[],s32 hook_informati
continue;
}
if(isDynamicFunction(physical))
{
if(isDynamicFunction(physical)) {
log_printf("Its a dynamic function. We don't need to restore it!\n",method_hooks[i].functionName);
}
else
{
} else {
physical = (u32)OSEffectiveToPhysical((void*)method_hooks[i].realAddr); //When its an static function, we need to use the old location
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("Restoring %08X to %08X\n",(u32)method_hooks[i].restoreInstruction,physical);}
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("Restoring %08X to %08X\n",(u32)method_hooks[i].restoreInstruction,physical);
}
SC0x25_KernelCopyData(physical,(u32)&method_hooks[i].restoreInstruction , 4);
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("ICInvalidateRange %08X\n",(void*)method_hooks[i].realAddr);}
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("ICInvalidateRange %08X\n",(void*)method_hooks[i].realAddr);
}
ICInvalidateRange((void*)method_hooks[i].realAddr, 4);
log_printf("done\n");
}
@ -220,18 +226,13 @@ s32 isDynamicFunction(u32 physicalAddress){
u32 GetAddressOfFunction(const char * functionName,u32 library) {
u32 real_addr = 0;
if(strcmp(functionName, "OSDynLoad_Acquire") == 0)
{
if(strcmp(functionName, "OSDynLoad_Acquire") == 0) {
memcpy(&real_addr, &OSDynLoad_Acquire, 4);
return real_addr;
}
else if(strcmp(functionName, "LiWaitOneChunk") == 0)
{
} else if(strcmp(functionName, "LiWaitOneChunk") == 0) {
real_addr = (u32)addr_LiWaitOneChunk;
return real_addr;
}
else if(strcmp(functionName, "LiBounceOneChunk") == 0)
{
} else if(strcmp(functionName, "LiBounceOneChunk") == 0) {
//! not required on firmwares above 3.1.0
if(OS_FIRMWARE >= 400)
return 0;
@ -243,129 +244,256 @@ u32 GetAddressOfFunction(const char * functionName,u32 library){
u32 rpl_handle = 0;
if(library == LIB_CORE_INIT) {
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_CORE_INIT\n", functionName);}
if(coreinit_handle_internal == 0){OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle_internal);}
if(coreinit_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_CORE_INIT failed to acquire\n"); return 0;}
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_CORE_INIT\n", functionName);
}
if(coreinit_handle_internal == 0) {
OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle_internal);
}
if(coreinit_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_CORE_INIT failed to acquire\n");
return 0;
}
rpl_handle = coreinit_handle_internal;
} else if(library == LIB_NSYSNET) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_NSYSNET\n", functionName);
}
if(nsysnet_handle_internal == 0) {
OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle_internal);
}
if(nsysnet_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_NSYSNET failed to acquire\n");
return 0;
}
else if(library == LIB_NSYSNET){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_NSYSNET\n", functionName);}
if(nsysnet_handle_internal == 0){OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle_internal);}
if(nsysnet_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_NSYSNET failed to acquire\n"); return 0;}
rpl_handle = nsysnet_handle_internal;
} else if(library == LIB_GX2) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_GX2\n", functionName);
}
if(gx2_handle_internal == 0) {
OSDynLoad_Acquire("gx2.rpl", &gx2_handle_internal);
}
if(gx2_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_GX2 failed to acquire\n");
return 0;
}
else if(library == LIB_GX2){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_GX2\n", functionName);}
if(gx2_handle_internal == 0){OSDynLoad_Acquire("gx2.rpl", &gx2_handle_internal);}
if(gx2_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_GX2 failed to acquire\n"); return 0;}
rpl_handle = gx2_handle_internal;
} else if(library == LIB_AOC) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_AOC\n", functionName);
}
if(aoc_handle_internal == 0) {
OSDynLoad_Acquire("nn_aoc.rpl", &aoc_handle_internal);
}
if(aoc_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_AOC failed to acquire\n");
return 0;
}
else if(library == LIB_AOC){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_AOC\n", functionName);}
if(aoc_handle_internal == 0){OSDynLoad_Acquire("nn_aoc.rpl", &aoc_handle_internal);}
if(aoc_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_AOC failed to acquire\n"); return 0;}
rpl_handle = aoc_handle_internal;
} else if(library == LIB_AX) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_AX\n", functionName);
}
if(sound_handle_internal == 0) {
OSDynLoad_Acquire("sndcore2.rpl", &sound_handle_internal);
}
if(sound_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_AX failed to acquire\n");
return 0;
}
else if(library == LIB_AX){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_AX\n", functionName);}
if(sound_handle_internal == 0){OSDynLoad_Acquire("sndcore2.rpl", &sound_handle_internal);}
if(sound_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_AX failed to acquire\n"); return 0;}
rpl_handle = sound_handle_internal;
} else if(library == LIB_AX_OLD) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_AX_OLD\n", functionName);
}
if(sound_handle_internal_old == 0) {
OSDynLoad_Acquire("snd_core.rpl", &sound_handle_internal_old);
}
if(sound_handle_internal_old == 0) {
DEBUG_FUNCTION_LINE("LIB_AX_OLD failed to acquire\n");
return 0;
}
else if(library == LIB_AX_OLD){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_AX_OLD\n", functionName);}
if(sound_handle_internal_old == 0){OSDynLoad_Acquire("snd_core.rpl", &sound_handle_internal_old);}
if(sound_handle_internal_old == 0){DEBUG_FUNCTION_LINE("LIB_AX_OLD failed to acquire\n"); return 0;}
rpl_handle = sound_handle_internal_old;
} else if(library == LIB_FS) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_FS\n", functionName);
}
if(coreinit_handle_internal == 0) {
OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle_internal);
}
if(coreinit_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_FS failed to acquire\n");
return 0;
}
else if(library == LIB_FS){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_FS\n", functionName);}
if(coreinit_handle_internal == 0){OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle_internal);}
if(coreinit_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_FS failed to acquire\n"); return 0;}
rpl_handle = coreinit_handle_internal;
} else if(library == LIB_OS) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_OS\n", functionName);
}
if(coreinit_handle_internal == 0) {
OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle_internal);
}
if(coreinit_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_OS failed to acquire\n");
return 0;
}
else if(library == LIB_OS){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_OS\n", functionName);}
if(coreinit_handle_internal == 0){OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle_internal);}
if(coreinit_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_OS failed to acquire\n"); return 0;}
rpl_handle = coreinit_handle_internal;
} else if(library == LIB_PADSCORE) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_PADSCORE\n", functionName);
}
if(padscore_handle_internal == 0) {
OSDynLoad_Acquire("padscore.rpl", &padscore_handle_internal);
}
if(padscore_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_PADSCORE failed to acquire\n");
return 0;
}
else if(library == LIB_PADSCORE){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_PADSCORE\n", functionName);}
if(padscore_handle_internal == 0){OSDynLoad_Acquire("padscore.rpl", &padscore_handle_internal);}
if(padscore_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_PADSCORE failed to acquire\n"); return 0;}
rpl_handle = padscore_handle_internal;
} else if(library == LIB_SOCKET) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_SOCKET\n", functionName);
}
if(nsysnet_handle_internal == 0) {
OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle_internal);
}
if(nsysnet_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_SOCKET failed to acquire\n");
return 0;
}
else if(library == LIB_SOCKET){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_SOCKET\n", functionName);}
if(nsysnet_handle_internal == 0){OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle_internal);}
if(nsysnet_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_SOCKET failed to acquire\n"); return 0;}
rpl_handle = nsysnet_handle_internal;
} else if(library == LIB_SYS) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_SYS\n", functionName);
}
if(sysapp_handle_internal == 0) {
OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle_internal);
}
if(sysapp_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_SYS failed to acquire\n");
return 0;
}
else if(library == LIB_SYS){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_SYS\n", functionName);}
if(sysapp_handle_internal == 0){OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle_internal);}
if(sysapp_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_SYS failed to acquire\n"); return 0;}
rpl_handle = sysapp_handle_internal;
} else if(library == LIB_VPAD) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_VPAD\n", functionName);
}
if(vpad_handle_internal == 0) {
OSDynLoad_Acquire("vpad.rpl", &vpad_handle_internal);
}
if(vpad_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_VPAD failed to acquire\n");
return 0;
}
else if(library == LIB_VPAD){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_VPAD\n", functionName);}
if(vpad_handle_internal == 0){ OSDynLoad_Acquire("vpad.rpl", &vpad_handle_internal);}
if(vpad_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_VPAD failed to acquire\n"); return 0;}
rpl_handle = vpad_handle_internal;
} else if(library == LIB_NN_ACP) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_NN_ACP\n", functionName);
}
if(acp_handle_internal == 0) {
OSDynLoad_Acquire("nn_acp.rpl", &acp_handle_internal);
}
if(acp_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_NN_ACP failed to acquire\n");
return 0;
}
else if(library == LIB_NN_ACP){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_NN_ACP\n", functionName);}
if(acp_handle_internal == 0){OSDynLoad_Acquire("nn_acp.rpl", &acp_handle_internal);}
if(acp_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_NN_ACP failed to acquire\n"); return 0;}
rpl_handle = acp_handle_internal;
} else if(library == LIB_SYSHID) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_SYSHID\n", functionName);
}
if(syshid_handle_internal == 0) {
OSDynLoad_Acquire("nsyshid.rpl", &syshid_handle_internal);
}
if(syshid_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_SYSHID failed to acquire\n");
return 0;
}
else if(library == LIB_SYSHID){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_SYSHID\n", functionName);}
if(syshid_handle_internal == 0){OSDynLoad_Acquire("nsyshid.rpl", &syshid_handle_internal);}
if(syshid_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_SYSHID failed to acquire\n"); return 0;}
rpl_handle = syshid_handle_internal;
} else if(library == LIB_VPADBASE) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_VPADBASE\n", functionName);
}
if(vpadbase_handle_internal == 0) {
OSDynLoad_Acquire("vpadbase.rpl", &vpadbase_handle_internal);
}
if(vpadbase_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_VPADBASE failed to acquire\n");
return 0;
}
else if(library == LIB_VPADBASE){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_VPADBASE\n", functionName);}
if(vpadbase_handle_internal == 0){OSDynLoad_Acquire("vpadbase.rpl", &vpadbase_handle_internal);}
if(vpadbase_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_VPADBASE failed to acquire\n"); return 0;}
rpl_handle = vpadbase_handle_internal;
} else if(library == LIB_PROC_UI) {
if(DEBUG_LOG_DYN) {
DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_PROC_UI\n", functionName);
}
if(proc_ui_handle_internal == 0) {
OSDynLoad_Acquire("proc_ui.rpl", &proc_ui_handle_internal);
}
if(proc_ui_handle_internal == 0) {
DEBUG_FUNCTION_LINE("LIB_PROC_UI failed to acquire\n");
return 0;
}
else if(library == LIB_PROC_UI){
if(DEBUG_LOG_DYN){DEBUG_FUNCTION_LINE("FindExport of %s! From LIB_PROC_UI\n", functionName);}
if(proc_ui_handle_internal == 0){OSDynLoad_Acquire("proc_ui.rpl", &proc_ui_handle_internal);}
if(proc_ui_handle_internal == 0){DEBUG_FUNCTION_LINE("LIB_PROC_UI failed to acquire\n"); return 0;}
rpl_handle = proc_ui_handle_internal;
} else if(library == LIB_NTAG) {
if(DEBUG_LOG_DYN) {
log_printf("FindExport of %s! From LIB_NTAG\n", functionName);
}
if(ntag_handle_internal == 0) {
OSDynLoad_Acquire("ntag.rpl", &ntag_handle_internal);
}
if(ntag_handle_internal == 0) {
log_print("LIB_NTAG failed to acquire\n");
return 0;
}
else if(library == LIB_NTAG){
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_NTAG\n", functionName);}
if(ntag_handle_internal == 0){OSDynLoad_Acquire("ntag.rpl", &ntag_handle_internal);}
if(ntag_handle_internal == 0){log_print("LIB_NTAG failed to acquire\n"); return 0;}
rpl_handle = ntag_handle_internal;
} else if(library == LIB_NFP) {
if(DEBUG_LOG_DYN) {
log_printf("FindExport of %s! From LIB_NFP\n", functionName);
}
if(nfp_handle_internal == 0) {
OSDynLoad_Acquire("nn_nfp.rpl", &nfp_handle_internal);
}
if(nfp_handle_internal == 0) {
log_print("LIB_NFP failed to acquire\n");
return 0;
}
else if(library == LIB_NFP){
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_NFP\n", functionName);}
if(nfp_handle_internal == 0){OSDynLoad_Acquire("nn_nfp.rpl", &nfp_handle_internal);}
if(nfp_handle_internal == 0){log_print("LIB_NFP failed to acquire\n"); return 0;}
rpl_handle = nfp_handle_internal;
} else if(library == LIB_SAVE) {
if(DEBUG_LOG_DYN) {
log_printf("FindExport of %s! From LIB_SAVE\n", functionName);
}
if(nn_save_handle_internal == 0) {
OSDynLoad_Acquire("nn_save.rpl", &nn_save_handle_internal);
}
if(nn_save_handle_internal == 0) {
log_print("LIB_SAVE failed to acquire\n");
return 0;
}
else if(library == LIB_SAVE){
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_SAVE\n", functionName);}
if(nn_save_handle_internal == 0){OSDynLoad_Acquire("nn_save.rpl", &nn_save_handle_internal);}
if(nn_save_handle_internal == 0){log_print("LIB_SAVE failed to acquire\n"); return 0;}
rpl_handle = nn_save_handle_internal;
} else if(library == LIB_ACT) {
if(DEBUG_LOG_DYN) {
log_printf("FindExport of %s! From LIB_ACT\n", functionName);
}
if(nn_act_handle_internal == 0) {
OSDynLoad_Acquire("nn_act.rpl", &nn_act_handle_internal);
}
if(nn_act_handle_internal == 0) {
log_print("LIB_ACT failed to acquire\n");
return 0;
}
else if(library == LIB_ACT){
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_ACT\n", functionName);}
if(nn_act_handle_internal == 0){OSDynLoad_Acquire("nn_act.rpl", &nn_act_handle_internal);}
if(nn_act_handle_internal == 0){log_print("LIB_ACT failed to acquire\n"); return 0;}
rpl_handle = nn_act_handle_internal;
} else if(library == LIB_NIM) {
if(DEBUG_LOG_DYN) {
log_printf("FindExport of %s! From LIB_NIM\n", functionName);
}
if(nn_nim_handle_internal == 0) {
OSDynLoad_Acquire("nn_nim.rpl", &nn_nim_handle_internal);
}
if(nn_nim_handle_internal == 0) {
log_print("LIB_NIM failed to acquire\n");
return 0;
}
else if(library == LIB_NIM){
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_NIM\n", functionName);}
if(nn_nim_handle_internal == 0){OSDynLoad_Acquire("nn_nim.rpl", &nn_nim_handle_internal);}
if(nn_nim_handle_internal == 0){log_print("LIB_NIM failed to acquire\n"); return 0;}
rpl_handle = nn_nim_handle_internal;
}
@ -384,8 +512,7 @@ u32 GetAddressOfFunction(const char * functionName,u32 library){
}
}
if((library == LIB_NN_ACP) && (u32)(*(volatile u32*)(real_addr) & 0x48000002) == 0x48000000)
{
if((library == LIB_NN_ACP) && (u32)(*(volatile u32*)(real_addr) & 0x48000002) == 0x48000000) {
u32 address_diff = (u32)(*(volatile u32*)(real_addr) & 0x03FFFFFC);
if((address_diff & 0x03000000) == 0x03000000) {
address_diff |= 0xFC000000;

View File

@ -63,8 +63,7 @@ void OSFatal_printf(const char *format, ...){
va_end(va);
}
void log_printf_(const char *format, ...)
{
void log_printf_(const char *format, ...) {
if(log_socket < 0) {
return;
}
@ -74,8 +73,7 @@ void log_printf_(const char *format, ...)
va_list va;
va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp)
{
if((vasprintf(&tmp, format, va) >= 0) && tmp) {
log_print_(tmp);
}
va_end(va);