Compare commits
1 Commits
cleanup/co
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c48447efc |
@@ -99,19 +99,25 @@ struct SOAddrInfo {
|
||||
u32 addrLen; // 0x10
|
||||
char* canonName; // 0x14
|
||||
void* addr; // 0x18
|
||||
SOAddrInfo* next; // 0x20
|
||||
SOAddrInfo* next; // 0x1C
|
||||
};
|
||||
|
||||
int SOSocket(int pf, int type, int protocol);
|
||||
int SOClose(int s);
|
||||
|
||||
int SOConnect(int s, void* sockAddr);
|
||||
int SOBind(int s, SOSockAddr* sockAddr);
|
||||
int SOConnect(int s, SOSockAddr* sockAddr);
|
||||
int SOGetSockName(int s, SOSockAddr* sockAddr);
|
||||
|
||||
int SORecvFrom(int s, void* buf, int len, int flags, SOSockAddr* sockAddr);
|
||||
int SORecv(int s, void* buf, int len, int flags);
|
||||
int SORead(int s, void* buf, int len);
|
||||
int SOSendTo(int s, const void* buf, int len, int flags, const SOSockAddr* sockAddr);
|
||||
int SOSend(int s, void* buf, int len, int flags);
|
||||
int SOFcntl(int s, int cmd, ...);
|
||||
|
||||
int SOShutdown(int s, int how);
|
||||
int SOPoll(SOPollFD* fds, int nfds, OSTime timeout);
|
||||
|
||||
int SOInetAtoN(const char* cp, SOInAddr* inp);
|
||||
char* SOInetNtoA(SOInAddr in);
|
||||
|
||||
@@ -14,6 +14,7 @@ typedef struct IPAddrEntry {
|
||||
} IPAddrEntry;
|
||||
|
||||
int SOGetInterfaceOpt(void* unk, int level, int optname, void* optval, int* optlen);
|
||||
int SOSetInterfaceOpt(void* unk, int level, int optname, const void* optval, int optlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
557
libs/RevoEX/src/so/SOBasic.c
Normal file
557
libs/RevoEX/src/so/SOBasic.c
Normal file
@@ -0,0 +1,557 @@
|
||||
#include <revolution/os.h>
|
||||
#include <revolution/soex.h>
|
||||
|
||||
#include <private/ios.h>
|
||||
#include <private/os/OSTime.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct SOSysWork {
|
||||
SOAlloc allocFunc;
|
||||
SOFree freeFunc;
|
||||
s32 rmState;
|
||||
s32 rmFd;
|
||||
u32 unk10;
|
||||
s32 allocCount;
|
||||
} SOSysWork;
|
||||
|
||||
enum {
|
||||
SO_SUCCESS = 0,
|
||||
SO_EFATAL = (s32)0x80000000,
|
||||
SO_EINVAL = -28,
|
||||
SO_ENOMEM = -49,
|
||||
};
|
||||
|
||||
enum {
|
||||
NET_SO_SOCKET = 0xF,
|
||||
};
|
||||
|
||||
typedef struct NETSoSocket {
|
||||
int af;
|
||||
int type;
|
||||
int protocol;
|
||||
} NETSoSocket;
|
||||
|
||||
void* SOiAlloc(u32 name, s32 size);
|
||||
void SOiFree(u32 name, void* ptr, s32 size);
|
||||
int SOiPrepare(const char* funcName, s32* pRmId);
|
||||
int SOiConclude(const char* funcName, int result);
|
||||
int SOiPrepareTempRm(const char* funcName, s32* pRmId, int* pIsTempRm);
|
||||
int SOiConcludeTempRm(const char* funcName, int result, int isTempRm);
|
||||
SOSysWork* SOiGetSysWork(void);
|
||||
int SOiIsInitialized(void);
|
||||
int SOiIsBufferAddrCheck(void);
|
||||
|
||||
const char* __SOCKETVersion =
|
||||
"<< RVL_SDK - SOCKET \trelease build: Dec 12 2008 03:06:17 (0x4199_60831) >>";
|
||||
static int soSocketRegistered[2];
|
||||
|
||||
static int RecvFrom(const char* funcName, int s, void* buf, int len, int flags, SOSockAddr* addr);
|
||||
static int SendTo(const char* funcName, int s, const void* buf, int len, int flags,
|
||||
const SOSockAddr* addr);
|
||||
|
||||
int SOSocket(int pf, int type, int protocol) {
|
||||
s32 rmId;
|
||||
NETSoSocket* soc;
|
||||
int result;
|
||||
|
||||
if (!soSocketRegistered[0]) {
|
||||
OSRegisterVersion(__SOCKETVersion);
|
||||
soSocketRegistered[0] = 1;
|
||||
}
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
if (pf == 0x17) {
|
||||
result = -5;
|
||||
} else {
|
||||
soc = (NETSoSocket*)SOiAlloc(0xC, 0x20);
|
||||
if (soc == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
soc->af = pf;
|
||||
soc->type = type;
|
||||
soc->protocol = protocol;
|
||||
result = IOS_Ioctl(rmId, NET_SO_SOCKET, soc, 0xC, NULL, 0);
|
||||
SOiFree(0xC, soc, 0x20);
|
||||
}
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOClose(int s) {
|
||||
s32 rmId;
|
||||
int result;
|
||||
u32* buf;
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
buf = (u32*)SOiAlloc(0xC, 0x20);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
buf[0] = s;
|
||||
result = IOS_Ioctl(rmId, 3, buf, 4, NULL, 0);
|
||||
SOiFree(0xC, buf, 0x20);
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOBind(int s, SOSockAddr* addr) {
|
||||
s32 rmId;
|
||||
int result;
|
||||
u8* buf;
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
if (addr == NULL || addr->len > 8 || addr->len < 8) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
buf = (u8*)SOiAlloc(0xC, 0x40);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
((u32*)buf)[0] = s;
|
||||
((u32*)buf)[1] = 1;
|
||||
memcpy(buf + 8, addr, addr->len);
|
||||
result = IOS_Ioctl(rmId, 2, buf, 0x24, NULL, 0);
|
||||
SOiFree(0xC, buf, 0x40);
|
||||
}
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOConnect(int s, SOSockAddr* addr) {
|
||||
s32 rmId;
|
||||
int result;
|
||||
u8* buf;
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
if (addr == NULL || addr->len > 8 || addr->len < 8) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
buf = (u8*)SOiAlloc(0xC, 0x40);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
((u32*)buf)[0] = s;
|
||||
((u32*)buf)[1] = 1;
|
||||
memcpy(buf + 8, addr, addr->len);
|
||||
result = IOS_Ioctl(rmId, 4, buf, 0x24, NULL, 0);
|
||||
SOiFree(0xC, buf, 0x40);
|
||||
}
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOGetSockName(int s, SOSockAddr* addr) {
|
||||
s32 rmId;
|
||||
u32 size;
|
||||
int result;
|
||||
u8* buf;
|
||||
SOSockAddr* out;
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
if (addr == NULL || addr->len > 8 || addr->len < 8) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
size = (addr->len + 0x3F) & ~0x1F;
|
||||
buf = (u8*)SOiAlloc(0xC, size);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
out = (SOSockAddr*)(buf + 0x20);
|
||||
((u32*)buf)[0] = s;
|
||||
memcpy(out, addr, addr->len);
|
||||
result = IOS_Ioctl(rmId, 7, buf, 4, out, addr->len);
|
||||
if (result >= 0) {
|
||||
memcpy(addr, out, out->len);
|
||||
}
|
||||
SOiFree(0xC, buf, size);
|
||||
}
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SORecvFrom(int s, void* buf, int len, int flags, SOSockAddr* sockAddr) {
|
||||
return RecvFrom(NULL, s, buf, len, flags, sockAddr);
|
||||
}
|
||||
|
||||
int SORecv(int s, void* buf, int len, int flags) {
|
||||
return RecvFrom(NULL, s, buf, len, flags, NULL);
|
||||
}
|
||||
|
||||
int SORead(int s, void* buf, int len) {
|
||||
return RecvFrom(NULL, s, buf, len, 0, NULL);
|
||||
}
|
||||
|
||||
int SOSendTo(int s, const void* buf, int len, int flags, const SOSockAddr* sockAddr) {
|
||||
return SendTo(NULL, s, buf, len, flags, sockAddr);
|
||||
}
|
||||
|
||||
int SOSend(int s, void* buf, int len, int flags) {
|
||||
return SendTo(NULL, s, buf, len, flags, NULL);
|
||||
}
|
||||
|
||||
int SOFcntl(int s, int cmd, ...) {
|
||||
s32 rmId;
|
||||
int result;
|
||||
va_list ap;
|
||||
int arg;
|
||||
u32* buf;
|
||||
|
||||
va_start(ap, cmd);
|
||||
arg = va_arg(ap, int);
|
||||
va_end(ap);
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
buf = (u32*)SOiAlloc(0xC, 0x20);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
buf[0] = s;
|
||||
buf[1] = cmd;
|
||||
buf[2] = arg;
|
||||
result = IOS_Ioctl(rmId, 5, buf, 0xC, NULL, 0);
|
||||
SOiFree(0xC, buf, 0x20);
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOShutdown(int s, int how) {
|
||||
s32 rmId;
|
||||
int result;
|
||||
u32* buf;
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
buf = (u32*)SOiAlloc(0xC, 0x20);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
buf[0] = s;
|
||||
buf[1] = how;
|
||||
result = IOS_Ioctl(rmId, 0xE, buf, 8, NULL, 0);
|
||||
SOiFree(0xC, buf, 0x20);
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOPoll(SOPollFD* fds, int nfds, OSTime timeout) {
|
||||
s32 rmId;
|
||||
u32 size;
|
||||
int len;
|
||||
int result;
|
||||
u8* buf;
|
||||
SOPollFD* pfd;
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
if (fds == NULL) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
len = nfds * sizeof(SOPollFD);
|
||||
size = (len + 0x3F) & ~0x1F;
|
||||
buf = (u8*)SOiAlloc(0xC, size);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
pfd = (SOPollFD*)(buf + 0x20);
|
||||
if (timeout <= -1) {
|
||||
memcpy(buf, &timeout, sizeof(timeout));
|
||||
} else {
|
||||
*(OSTime*)buf = timeout / (OS_TIMER_CLOCK / 1000);
|
||||
}
|
||||
memcpy(pfd, fds, len);
|
||||
result = IOS_Ioctl(rmId, 0xB, buf, 8, pfd, len);
|
||||
if (result >= 0) {
|
||||
memcpy(fds, pfd, len);
|
||||
}
|
||||
SOiFree(0xC, buf, size);
|
||||
}
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOInetAtoN(const char* cp, SOInAddr* inp) {
|
||||
s32 rmId;
|
||||
int isTempRm;
|
||||
int result;
|
||||
u8* in;
|
||||
u32 size;
|
||||
u8* buf;
|
||||
|
||||
if ((result = SOiPrepareTempRm(NULL, &rmId, &isTempRm)) == SO_SUCCESS) {
|
||||
if (cp == NULL) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
size = (strlen(cp) + 0x40) & ~0x1F;
|
||||
buf = (u8*)SOiAlloc(0xC, size);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
in = buf + 0x20;
|
||||
if (cp != NULL) {
|
||||
strcpy((char*)in, cp);
|
||||
}
|
||||
result = IOS_Ioctl(rmId, 0x15, in, strlen(cp), buf, 4);
|
||||
if (result >= 0 && inp != NULL) {
|
||||
memcpy(inp, buf, 4);
|
||||
}
|
||||
SOiFree(0xC, buf, size);
|
||||
}
|
||||
}
|
||||
result = SOiConcludeTempRm(NULL, result, isTempRm);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
char* SOInetNtoA(SOInAddr in) {
|
||||
static char ascii[40];
|
||||
sprintf(ascii, "%d.%d.%d.%d", ((u8*)&in)[0], ((u8*)&in)[1], ((u8*)&in)[2],
|
||||
((u8*)&in)[3]);
|
||||
return ascii;
|
||||
}
|
||||
|
||||
int SOInetPtoN(int af, const char* src, void* dst) {
|
||||
s32 rmId;
|
||||
int isTempRm;
|
||||
u32 size;
|
||||
int result;
|
||||
int addrLen;
|
||||
u8* buf;
|
||||
|
||||
if ((result = SOiPrepareTempRm(NULL, &rmId, &isTempRm)) == SO_SUCCESS) {
|
||||
switch (af) {
|
||||
default:
|
||||
addrLen = 0;
|
||||
break;
|
||||
case SO_PF_INET:
|
||||
addrLen = 4;
|
||||
break;
|
||||
}
|
||||
if (addrLen == 0) {
|
||||
result = -5;
|
||||
} else if (src == NULL) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
size = (strlen(src) + 0x40) & ~0x1F;
|
||||
buf = (u8*)SOiAlloc(0xC, size);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
strcpy((char*)buf + 0x20, src);
|
||||
((u32*)buf)[0] = af;
|
||||
memset(buf + 4, 0, addrLen);
|
||||
result =
|
||||
IOS_Ioctl(rmId, 0x16, (void*)src, strlen(src) + 1, buf, 0x14);
|
||||
if (result >= 0 && dst != NULL) {
|
||||
memcpy(dst, buf + 4, addrLen);
|
||||
}
|
||||
SOiFree(0xC, buf, size);
|
||||
}
|
||||
}
|
||||
result = SOiConcludeTempRm(NULL, result, isTempRm);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
u32 SONtoHl(u32 netlong) { return netlong; }
|
||||
|
||||
u16 SONtoHs(u16 netshort) { return netshort; }
|
||||
|
||||
u32 SOHtoNl(u32 hostlong) { return hostlong; }
|
||||
|
||||
u16 SOHtoNs(u16 hostshort) { return hostshort; }
|
||||
|
||||
static int RecvFrom(const char* funcName, int s, void* buf, int len, int flags,
|
||||
SOSockAddr* addr) {
|
||||
s32 rmId;
|
||||
int result;
|
||||
int aligned;
|
||||
u8* databuf;
|
||||
u8* vec;
|
||||
u8* addrbuf;
|
||||
u32 vecsize;
|
||||
int mem1;
|
||||
u32 bufsize;
|
||||
u8 retlen;
|
||||
u8 cplen;
|
||||
|
||||
if (len > 0x8000) {
|
||||
len = 0x8000;
|
||||
}
|
||||
|
||||
if ((result = SOiPrepare(funcName, &rmId)) == SO_SUCCESS) {
|
||||
if (addr != NULL && (addr->len > 8 || addr->len < 8)) {
|
||||
result = SO_EINVAL;
|
||||
} else if (len < 0 || (len > 0 && buf == NULL)) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
aligned = 1;
|
||||
if (len != 0) {
|
||||
int ok;
|
||||
int bufOk;
|
||||
int memOk;
|
||||
ok = 0;
|
||||
bufOk = (((u32)buf & 0x1F) == 0) && (len % 32 == 0);
|
||||
if (bufOk != 0) {
|
||||
memOk = 1;
|
||||
if (SOiIsBufferAddrCheck()) {
|
||||
int in = ((u32)buf & 0x1FFFFFFF) >= 0x10000000 &&
|
||||
((u32)buf & 0x1FFFFFFF) < 0x18000000;
|
||||
if (!in) {
|
||||
memOk = 0;
|
||||
}
|
||||
}
|
||||
if (memOk != 0) {
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
if (ok == 0) {
|
||||
aligned = 0;
|
||||
}
|
||||
}
|
||||
|
||||
vecsize = (((addr == NULL) ? 0 : addr->len) + 0x5F) & ~0x1F;
|
||||
vec = (u8*)SOiAlloc(0xC, vecsize);
|
||||
if (aligned == 0) {
|
||||
bufsize = (len + 0x1F) & ~0x1F;
|
||||
databuf = (u8*)SOiAlloc(0xD, bufsize);
|
||||
} else {
|
||||
databuf = (u8*)buf;
|
||||
}
|
||||
if (vec == NULL || databuf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
((u32*)vec)[0x8] = s;
|
||||
((u32*)vec)[0x9] = flags;
|
||||
addrbuf = vec + 0x40;
|
||||
((IOSIoVector*)vec)[0].base = vec + 0x20;
|
||||
((IOSIoVector*)vec)[0].length = 8;
|
||||
((IOSIoVector*)vec)[1].base = databuf;
|
||||
((IOSIoVector*)vec)[1].length = len;
|
||||
if (addr == NULL) {
|
||||
((IOSIoVector*)vec)[2].base = NULL;
|
||||
((IOSIoVector*)vec)[2].length = 0;
|
||||
result = IOS_Ioctlv(rmId, 0xC, 1, 2, (IOSIoVector*)vec);
|
||||
} else {
|
||||
memcpy(addrbuf, addr, addr->len);
|
||||
((IOSIoVector*)vec)[2].base = addrbuf;
|
||||
((IOSIoVector*)vec)[2].length = addr->len;
|
||||
result = IOS_Ioctlv(rmId, 0xC, 1, 2, (IOSIoVector*)vec);
|
||||
if (result >= 0) {
|
||||
cplen = addr->len;
|
||||
retlen = addrbuf[0];
|
||||
if (cplen > retlen) {
|
||||
cplen = retlen;
|
||||
}
|
||||
memcpy(addr, addrbuf, cplen);
|
||||
}
|
||||
}
|
||||
if (result >= 0 && aligned == 0) {
|
||||
memcpy(buf, databuf, len);
|
||||
}
|
||||
}
|
||||
if (aligned == 0) {
|
||||
SOiFree(0xD, databuf, (len + 0x1F) & ~0x1F);
|
||||
}
|
||||
SOiFree(0xC, vec, vecsize);
|
||||
}
|
||||
result = SOiConclude(funcName, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int SendTo(const char* funcName, int s, const void* buf, int len, int flags,
|
||||
const SOSockAddr* addr) {
|
||||
s32 rmId;
|
||||
u8* vec;
|
||||
int result;
|
||||
int aligned;
|
||||
u8* databuf;
|
||||
u32 bufsize;
|
||||
u8* hdr;
|
||||
|
||||
if ((result = SOiPrepare(funcName, &rmId)) == SO_SUCCESS) {
|
||||
if (addr != NULL && (addr->len > 8 || addr->len < 8)) {
|
||||
result = SO_EINVAL;
|
||||
} else if (len < 0 || (len > 0 && buf == NULL)) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
aligned = 1;
|
||||
if (len != 0) {
|
||||
int ok;
|
||||
int bufOk;
|
||||
int memOk;
|
||||
ok = 0;
|
||||
bufOk = (((u32)buf & 0x1F) == 0) && (len % 32 == 0);
|
||||
if (bufOk != 0) {
|
||||
memOk = 1;
|
||||
if (SOiIsBufferAddrCheck()) {
|
||||
int in = ((u32)buf & 0x1FFFFFFF) >= 0x10000000 &&
|
||||
((u32)buf & 0x1FFFFFFF) < 0x18000000;
|
||||
if (!in) {
|
||||
memOk = 0;
|
||||
}
|
||||
}
|
||||
if (memOk != 0) {
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
if (ok == 0) {
|
||||
aligned = 0;
|
||||
}
|
||||
}
|
||||
|
||||
vec = (u8*)SOiAlloc(0xC, 0x60);
|
||||
if (aligned == 0) {
|
||||
bufsize = (len + 0x1F) & ~0x1F;
|
||||
databuf = (u8*)SOiAlloc(0xE, bufsize);
|
||||
} else {
|
||||
databuf = (u8*)buf;
|
||||
}
|
||||
|
||||
if (vec == NULL || databuf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
hdr = vec + 0x20;
|
||||
((u32*)vec)[0x8] = s;
|
||||
((u32*)vec)[0x9] = flags;
|
||||
if (addr == NULL) {
|
||||
((u32*)hdr)[2] = 0;
|
||||
} else {
|
||||
((u32*)hdr)[2] = 1;
|
||||
memcpy(hdr + 0xC, addr, addr->len);
|
||||
}
|
||||
if (aligned == 0) {
|
||||
memcpy(databuf, buf, len);
|
||||
}
|
||||
((IOSIoVector*)vec)[0].base = databuf;
|
||||
((IOSIoVector*)vec)[0].length = len;
|
||||
((IOSIoVector*)vec)[1].base = hdr;
|
||||
((IOSIoVector*)vec)[1].length = 0x28;
|
||||
result = IOS_Ioctlv(rmId, 0xD, 2, 0, (IOSIoVector*)vec);
|
||||
}
|
||||
if (aligned == 0) {
|
||||
SOiFree(0xE, databuf, bufsize);
|
||||
}
|
||||
SOiFree(0xC, vec, 0x60);
|
||||
}
|
||||
result = SOiConclude(funcName, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
185
libs/RevoEX/src/so/SOInformation.c
Normal file
185
libs/RevoEX/src/so/SOInformation.c
Normal file
@@ -0,0 +1,185 @@
|
||||
#include <revolution/os.h>
|
||||
#include <revolution/soex.h>
|
||||
|
||||
#include <private/ios.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef struct SOSysWork {
|
||||
SOAlloc allocFunc;
|
||||
SOFree freeFunc;
|
||||
s32 rmState;
|
||||
s32 rmFd;
|
||||
u32 unk10;
|
||||
s32 allocCount;
|
||||
} SOSysWork;
|
||||
|
||||
enum {
|
||||
SO_SUCCESS = 0,
|
||||
SO_EINVAL = -28,
|
||||
SO_ENOMEM = -49,
|
||||
};
|
||||
|
||||
void* SOiAlloc(u32 name, s32 size);
|
||||
void SOiFree(u32 name, void* ptr, s32 size);
|
||||
int SOiPrepare(const char* funcName, s32* pRmId);
|
||||
int SOiConclude(const char* funcName, int result);
|
||||
SOSysWork* SOiGetSysWork(void);
|
||||
int SOiIsInitialized(void);
|
||||
|
||||
s32 SOGetHostID(void) {
|
||||
s32 rmId;
|
||||
s32 err;
|
||||
s32 result = 0;
|
||||
|
||||
if ((err = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
result = IOS_Ioctl(rmId, 0x10, NULL, 0, NULL, 0);
|
||||
(void)SOiConclude(NULL, err);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
SOHostEnt* SOGetHostByName(const char* name) {
|
||||
s32 rmId;
|
||||
SOHostEnt* result = NULL;
|
||||
s32 err;
|
||||
|
||||
if (SOiPrepare(NULL, &rmId) == SO_SUCCESS) {
|
||||
if (name == NULL) {
|
||||
err = SO_EINVAL;
|
||||
} else {
|
||||
SOHostEnt* hostEnt = (SOHostEnt*)SOiGetSysWork()->unk10;
|
||||
u32 len = strlen(name);
|
||||
u32 size = (len + 0x20) & ~0x1F;
|
||||
char* buf = (char*)SOiAlloc(0xC, size);
|
||||
|
||||
if (buf == NULL) {
|
||||
err = SO_ENOMEM;
|
||||
} else {
|
||||
strcpy(buf, name);
|
||||
err = IOS_Ioctl(rmId, 0x11, buf, len + 1, hostEnt, 0x460);
|
||||
if (err >= 0) {
|
||||
u8* base = (u8*)hostEnt;
|
||||
s32 delta = (s32)(base + 0x10) - (s32)hostEnt->name;
|
||||
u32* list = (u32*)(base + 0x340);
|
||||
while (*list != 0) {
|
||||
*list += delta;
|
||||
list++;
|
||||
}
|
||||
*(u32*)&hostEnt->aliases += delta;
|
||||
*(u32*)&hostEnt->name += delta;
|
||||
*(u32*)&hostEnt->addrList += delta;
|
||||
result = hostEnt;
|
||||
}
|
||||
SOiFree(0xC, buf, size);
|
||||
}
|
||||
}
|
||||
(void)SOiConclude(NULL, err);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOGetAddrInfo(const char* nodeName, const char* servName,
|
||||
const SOAddrInfo* hints, SOAddrInfo** res) {
|
||||
s32 rmId;
|
||||
int result;
|
||||
u32 nameLen;
|
||||
u32 servLen;
|
||||
u32 vecsize;
|
||||
u8* vec;
|
||||
u8* hostBuf;
|
||||
char* nameArea;
|
||||
char* servArea;
|
||||
SOAddrInfo* hintsArea;
|
||||
SOAddrInfo* ai;
|
||||
u8* addrData;
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
servLen = (servName == NULL) ? 0 : strlen(nodeName) + 1;
|
||||
nameLen = (nodeName == NULL) ? 0 : strlen(nodeName) + 1;
|
||||
vecsize = (((nameLen + 0x1F) & ~0x1F) + ((servLen + 0x1F) & ~0x1F) +
|
||||
0x5F) & ~0x1F;
|
||||
vec = (u8*)SOiAlloc(0xC, vecsize);
|
||||
if (vec == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
hostBuf = (u8*)SOiAlloc(0xA, 0x840);
|
||||
if (hostBuf == NULL) {
|
||||
SOiFree(0xC, vec, vecsize);
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
nameArea = (char*)(vec + 0x20);
|
||||
servArea =
|
||||
nameArea +
|
||||
(((nodeName == NULL) ? 0 : strlen(nodeName) + 1) + 0x1F &
|
||||
~0x1F);
|
||||
hintsArea =
|
||||
(SOAddrInfo*)(servArea +
|
||||
(((servName == NULL) ? 0 : strlen(nodeName) + 1) +
|
||||
0x1F &
|
||||
~0x1F));
|
||||
|
||||
if (nodeName != NULL) {
|
||||
strcpy(nameArea, nodeName);
|
||||
}
|
||||
((u32*)vec)[0] =
|
||||
(u32)((nodeName != NULL) ? nameArea : NULL);
|
||||
((u32*)vec)[1] =
|
||||
(nodeName == NULL) ? 0 : strlen(nodeName);
|
||||
if (servName != NULL) {
|
||||
strcpy(servArea, servName);
|
||||
}
|
||||
((u32*)vec)[2] =
|
||||
(u32)((servName != NULL) ? servArea : NULL);
|
||||
((u32*)vec)[3] =
|
||||
(servName == NULL) ? 0 : strlen(servName);
|
||||
if (hints != NULL) {
|
||||
memcpy(hintsArea, hints, sizeof(SOAddrInfo));
|
||||
} else {
|
||||
memset(hintsArea, 0, sizeof(SOAddrInfo));
|
||||
}
|
||||
if (hintsArea->family == 0) {
|
||||
hintsArea->family = SO_PF_INET;
|
||||
}
|
||||
if (hintsArea->family == 0x17) {
|
||||
*res = NULL;
|
||||
result = -0x44;
|
||||
SOiFree(0xA, hostBuf, 0x840);
|
||||
} else {
|
||||
((u32*)vec)[4] = (u32)hintsArea;
|
||||
((u32*)vec)[5] = sizeof(SOAddrInfo);
|
||||
((u32*)vec)[6] = (u32)hostBuf;
|
||||
((u32*)vec)[7] = 0x834;
|
||||
result = IOS_Ioctlv(rmId, 0x18, 3, 1, (IOSIoVector*)vec);
|
||||
if (result >= 0) {
|
||||
*res = (SOAddrInfo*)hostBuf;
|
||||
addrData = hostBuf + 0x460;
|
||||
ai = (SOAddrInfo*)hostBuf;
|
||||
while (ai != NULL) {
|
||||
ai->addr = addrData;
|
||||
if (ai->next != NULL) {
|
||||
ai->next = ai + 1;
|
||||
}
|
||||
ai = ai->next;
|
||||
addrData += 0x1C;
|
||||
}
|
||||
} else {
|
||||
*res = NULL;
|
||||
SOiFree(0xA, hostBuf, 0x840);
|
||||
}
|
||||
}
|
||||
SOiFree(0xC, vec, vecsize);
|
||||
}
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void SOFreeAddrInfo(SOAddrInfo* head) {
|
||||
int enabled = OSDisableInterrupts();
|
||||
if (SOiIsInitialized() == 1 && head != NULL) {
|
||||
SOiFree(0xA, head, 0x840);
|
||||
}
|
||||
OSRestoreInterrupts(enabled);
|
||||
}
|
||||
177
libs/RevoEX/src/so/SOOption.c
Normal file
177
libs/RevoEX/src/so/SOOption.c
Normal file
@@ -0,0 +1,177 @@
|
||||
#include <revolution/os.h>
|
||||
#include <revolution/soex.h>
|
||||
|
||||
#include <private/ios.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
enum {
|
||||
SO_SUCCESS = 0,
|
||||
SO_EINVAL = -28,
|
||||
SO_ENOMEM = -49,
|
||||
};
|
||||
|
||||
void* SOiAlloc(u32 name, s32 size);
|
||||
void SOiFree(u32 name, void* ptr, s32 size);
|
||||
int SOiPrepare(const char* funcName, s32* pRmId);
|
||||
int SOiConclude(const char* funcName, int result);
|
||||
int SOiPrepareTempRm(const char* funcName, s32* pRmId, int* pIsTempRm);
|
||||
int SOiConcludeTempRm(const char* funcName, int result, int isTempRm);
|
||||
|
||||
int SOGetSockOpt(int s, int level, int optname, void* optval, int* optlen) {
|
||||
s32 rmId;
|
||||
int result;
|
||||
s32* buf;
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
buf = (s32*)SOiAlloc(0xC, 0x20);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
buf[0] = s;
|
||||
buf[1] = level;
|
||||
buf[2] = optname;
|
||||
result = IOS_Ioctl(rmId, 8, NULL, 0, buf, 0x18);
|
||||
if (result >= 0 && optlen != NULL) {
|
||||
if (*optlen >= buf[3]) {
|
||||
if (optval != NULL) {
|
||||
memcpy(optval, buf + 4, buf[3]);
|
||||
}
|
||||
*optlen = buf[3];
|
||||
} else {
|
||||
*optlen = buf[3];
|
||||
result = SO_EINVAL;
|
||||
}
|
||||
}
|
||||
SOiFree(0xC, buf, 0x20);
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOSetSockOpt(int s, int level, int optname, const void* optval, int optlen) {
|
||||
s32 rmId;
|
||||
int result;
|
||||
s32* buf;
|
||||
|
||||
if ((result = SOiPrepare(NULL, &rmId)) == SO_SUCCESS) {
|
||||
if (optlen < 0 || optlen > 0x14) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
buf = (s32*)SOiAlloc(0xC, 0x40);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
buf[0] = s;
|
||||
buf[1] = level;
|
||||
buf[2] = optname;
|
||||
buf[3] = optlen;
|
||||
if (optval != NULL) {
|
||||
memcpy(buf + 4, optval, optlen);
|
||||
} else {
|
||||
memset(buf + 4, 0, optlen);
|
||||
}
|
||||
result = IOS_Ioctl(rmId, 9, buf, 0x24, NULL, 0);
|
||||
SOiFree(0xC, buf, 0x40);
|
||||
}
|
||||
}
|
||||
result = SOiConclude(NULL, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOGetInterfaceOpt(void* unk, int level, int optname, void* optval,
|
||||
int* optlen) {
|
||||
s32 rmId;
|
||||
int isTempRm;
|
||||
int result;
|
||||
u8* buf;
|
||||
u32 size;
|
||||
u8* p;
|
||||
s32* outlen;
|
||||
u8* data;
|
||||
s32 len;
|
||||
|
||||
if ((result = SOiPrepareTempRm(NULL, &rmId, &isTempRm)) == SO_SUCCESS) {
|
||||
if (optname == 0x1001 || optname == 0x1002) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
size = (((optlen == NULL || *optlen < 0) ? 0 : *optlen) + 0x7F) &
|
||||
~0x1F;
|
||||
buf = (u8*)SOiAlloc(0xC, size);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
((u32*)buf)[8] = level;
|
||||
p = buf + 0x20;
|
||||
outlen = (s32*)(p + 0x20);
|
||||
data = (u8*)(outlen + 8);
|
||||
*outlen =
|
||||
(optlen == NULL || *optlen < 0) ? 0 : *optlen;
|
||||
((u32*)buf)[9] = optname;
|
||||
((IOSIoVector*)buf)[0].base = p;
|
||||
((IOSIoVector*)buf)[0].length = 8;
|
||||
((IOSIoVector*)buf)[1].base = data;
|
||||
((IOSIoVector*)buf)[1].length =
|
||||
(optlen == NULL || *optlen < 0) ? 0 : *optlen;
|
||||
((IOSIoVector*)buf)[2].base = (u8*)outlen;
|
||||
((IOSIoVector*)buf)[2].length = 4;
|
||||
result =
|
||||
IOS_Ioctlv(rmId, 0x1C, 1, 2, (IOSIoVector*)buf);
|
||||
if (result >= 0 && optlen != NULL) {
|
||||
if (*optlen >= *outlen) {
|
||||
if (optval != NULL) {
|
||||
memcpy(optval, data, *outlen);
|
||||
}
|
||||
*optlen = *outlen;
|
||||
} else {
|
||||
*optlen = *outlen;
|
||||
result = SO_EINVAL;
|
||||
}
|
||||
}
|
||||
SOiFree(0xC, buf, size);
|
||||
}
|
||||
}
|
||||
result = SOiConcludeTempRm(NULL, result, isTempRm);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int SOSetInterfaceOpt(void* unk, int level, int optname, const void* optval,
|
||||
int optlen) {
|
||||
s32 rmId;
|
||||
int isTempRm;
|
||||
u32 size;
|
||||
int result;
|
||||
u8* buf;
|
||||
|
||||
if ((result = SOiPrepareTempRm(NULL, &rmId, &isTempRm)) == SO_SUCCESS) {
|
||||
if (optname == 0x1001 || optname == 0x1002 || optlen < 0) {
|
||||
result = SO_EINVAL;
|
||||
} else {
|
||||
size = (optlen + 0x5F) & ~0x1F;
|
||||
buf = (u8*)SOiAlloc(0xC, size);
|
||||
if (buf == NULL) {
|
||||
result = SO_ENOMEM;
|
||||
} else {
|
||||
((u32*)buf)[8] = level;
|
||||
((u32*)buf)[9] = optname;
|
||||
if (optval != NULL) {
|
||||
memcpy(buf + 0x40, optval, optlen);
|
||||
} else {
|
||||
memset(buf + 0x40, 0, optlen);
|
||||
}
|
||||
((IOSIoVector*)buf)[0].base = buf + 0x20;
|
||||
((IOSIoVector*)buf)[0].length = 8;
|
||||
((IOSIoVector*)buf)[1].base = buf + 0x40;
|
||||
((IOSIoVector*)buf)[1].length = optlen;
|
||||
result =
|
||||
IOS_Ioctlv(rmId, 0x1D, 2, 0, (IOSIoVector*)buf);
|
||||
SOiFree(0xC, buf, size);
|
||||
}
|
||||
}
|
||||
result = SOiConcludeTempRm(NULL, result, isTempRm);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user