diff --git a/README.md b/README.md index 94c34c68..e5e62736 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 92.00% | 81.18% | 57.21% | 88.79% | +| 92.68% | 81.48% | 57.21% | 88.99% | -units 768/1027 complete, functions 11668/12563 matched. +units 768/1027 complete, functions 11731/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data diff --git a/libs/RevoEX/src/ncd/ncdsleep.c b/libs/RevoEX/src/ncd/ncdsleep.c new file mode 100644 index 00000000..c386ff7c --- /dev/null +++ b/libs/RevoEX/src/ncd/ncdsleep.c @@ -0,0 +1,18 @@ +#include + +static void SleepStart(OSAlarm* alarm, OSContext* context) { + OSResumeThread((OSThread*)alarm->tag); +} + +void NCDSleep(OSTime ticks) { + OSAlarm alarm; + BOOL enabled=OSDisableInterrupts(); + OSThread* thread=OSGetCurrentThread(); + if(!thread) { OSRestoreInterrupts(enabled); return; } + OSCreateAlarm(&alarm); + OSSetAlarmTag(&alarm,(u32)thread); + OSSetAlarm(&alarm,ticks,SleepStart); + OSSuspendThread(thread); + OSCancelAlarm(&alarm); + OSRestoreInterrupts(enabled); +} diff --git a/libs/RevoEX/src/net/aes.c b/libs/RevoEX/src/net/aes.c new file mode 100644 index 00000000..19d727a3 --- /dev/null +++ b/libs/RevoEX/src/net/aes.c @@ -0,0 +1,318 @@ +#include +#include +#include + +typedef struct AESContext AESContext; +typedef struct AESBlockMode { + void (*encrypt)(AESContext*, u32*, const u32*); + void (*decrypt)(AESContext*, u32*, const u32*); +} AESBlockMode; + +struct AESContext { + u32 chain[4]; + u32 keys[60]; + u32 rounds : 8; + u32 needsTransform : 1; + u32 options : 23; + const AESBlockMode* mode; +}; + +static void NETiAESEncryptoBlock(AESContext*, u32*, const u32*); +static void NETiAESDecryptoBlock(AESContext*, u32*, const u32*); +const AESBlockMode NET_AES_BLOCK_MODE_CBC = {NETiAESEncryptoBlock, NETiAESDecryptoBlock}; + +static const u8 AESiSubShiftTable[] = { + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, + 0x30, 0x1, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, + 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, + 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, + 0x4, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x5, 0x9a, + 0x7, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, + 0x9, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, + 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, + 0x53, 0xd1, 0x0, 0xed, 0x20, 0xfc, 0xb1, 0x5b, + 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, + 0x45, 0xf9, 0x2, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, + 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, + 0xcd, 0xc, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, + 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, + 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0xb, 0xdb, + 0xe0, 0x32, 0x3a, 0xa, 0x49, 0x6, 0x24, 0x5c, + 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, + 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x8, + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, + 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x3, 0xf6, 0xe, + 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, + 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, + 0x8c, 0xa1, 0x89, 0xd, 0xbf, 0xe6, 0x42, 0x68, + 0x41, 0x99, 0x2d, 0xf, 0xb0, 0x54, 0xbb, 0x16 +}; + +static const u8 AESiInvSubShiftTable[] = { + 0x52, 0x9, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, + 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, + 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, + 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, + 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, + 0xee, 0x4c, 0x95, 0xb, 0x42, 0xfa, 0xc3, 0x4e, + 0x8, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, + 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, + 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, + 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, + 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, + 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, + 0x90, 0xd8, 0xab, 0x0, 0x8c, 0xbc, 0xd3, 0xa, + 0xf7, 0xe4, 0x58, 0x5, 0xb8, 0xb3, 0x45, 0x6, + 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0xf, 0x2, + 0xc1, 0xaf, 0xbd, 0x3, 0x1, 0x13, 0x8a, 0x6b, + 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, + 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, + 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, + 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, + 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, + 0x6f, 0xb7, 0x62, 0xe, 0xaa, 0x18, 0xbe, 0x1b, + 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, + 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, + 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x7, 0xc7, 0x31, + 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, + 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0xd, + 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, + 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, + 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2b, 0x4, 0x7e, 0xba, 0x77, 0xd6, 0x26, + 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0xc, 0x7d +}; + +static const u8 AESiRoundKeyRcon0[] = { + 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, + 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, + 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, + 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 +}; + +static const u32 AESiEncryptTable[] = { + 0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, + 0x30305060, 0x1010302, 0x6767a9ce, 0x2b2b7d56, 0xfefe19e7, 0xd7d762b5, 0xababe64d, 0x76769aec, + 0xcaca458f, 0x82829d1f, 0xc9c94089, 0x7d7d87fa, 0xfafa15ef, 0x5959ebb2, 0x4747c98e, 0xf0f00bfb, + 0xadadec41, 0xd4d467b3, 0xa2a2fd5f, 0xafafea45, 0x9c9cbf23, 0xa4a4f753, 0x727296e4, 0xc0c05b9b, + 0xb7b7c275, 0xfdfd1ce1, 0x9393ae3d, 0x26266a4c, 0x36365a6c, 0x3f3f417e, 0xf7f702f5, 0xcccc4f83, + 0x34345c68, 0xa5a5f451, 0xe5e534d1, 0xf1f108f9, 0x717193e2, 0xd8d873ab, 0x31315362, 0x15153f2a, + 0x4040c08, 0xc7c75295, 0x23236546, 0xc3c35e9d, 0x18182830, 0x9696a137, 0x5050f0a, 0x9a9ab52f, + 0x707090e, 0x12123624, 0x80809b1b, 0xe2e23ddf, 0xebeb26cd, 0x2727694e, 0xb2b2cd7f, 0x75759fea, + 0x9091b12, 0x83839e1d, 0x2c2c7458, 0x1a1a2e34, 0x1b1b2d36, 0x6e6eb2dc, 0x5a5aeeb4, 0xa0a0fb5b, + 0x5252f6a4, 0x3b3b4d76, 0xd6d661b7, 0xb3b3ce7d, 0x29297b52, 0xe3e33edd, 0x2f2f715e, 0x84849713, + 0x5353f5a6, 0xd1d168b9, 0x0, 0xeded2cc1, 0x20206040, 0xfcfc1fe3, 0xb1b1c879, 0x5b5bedb6, + 0x6a6abed4, 0xcbcb468d, 0xbebed967, 0x39394b72, 0x4a4ade94, 0x4c4cd498, 0x5858e8b0, 0xcfcf4a85, + 0xd0d06bbb, 0xefef2ac5, 0xaaaae54f, 0xfbfb16ed, 0x4343c586, 0x4d4dd79a, 0x33335566, 0x85859411, + 0x4545cf8a, 0xf9f910e9, 0x2020604, 0x7f7f81fe, 0x5050f0a0, 0x3c3c4478, 0x9f9fba25, 0xa8a8e34b, + 0x5151f3a2, 0xa3a3fe5d, 0x4040c080, 0x8f8f8a05, 0x9292ad3f, 0x9d9dbc21, 0x38384870, 0xf5f504f1, + 0xbcbcdf63, 0xb6b6c177, 0xdada75af, 0x21216342, 0x10103020, 0xffff1ae5, 0xf3f30efd, 0xd2d26dbf, + 0xcdcd4c81, 0xc0c1418, 0x13133526, 0xecec2fc3, 0x5f5fe1be, 0x9797a235, 0x4444cc88, 0x1717392e, + 0xc4c45793, 0xa7a7f255, 0x7e7e82fc, 0x3d3d477a, 0x6464acc8, 0x5d5de7ba, 0x19192b32, 0x737395e6, + 0x6060a0c0, 0x81819819, 0x4f4fd19e, 0xdcdc7fa3, 0x22226644, 0x2a2a7e54, 0x9090ab3b, 0x8888830b, + 0x4646ca8c, 0xeeee29c7, 0xb8b8d36b, 0x14143c28, 0xdede79a7, 0x5e5ee2bc, 0xb0b1d16, 0xdbdb76ad, + 0xe0e03bdb, 0x32325664, 0x3a3a4e74, 0xa0a1e14, 0x4949db92, 0x6060a0c, 0x24246c48, 0x5c5ce4b8, + 0xc2c25d9f, 0xd3d36ebd, 0xacacef43, 0x6262a6c4, 0x9191a839, 0x9595a431, 0xe4e437d3, 0x79798bf2, + 0xe7e732d5, 0xc8c8438b, 0x3737596e, 0x6d6db7da, 0x8d8d8c01, 0xd5d564b1, 0x4e4ed29c, 0xa9a9e049, + 0x6c6cb4d8, 0x5656faac, 0xf4f407f3, 0xeaea25cf, 0x6565afca, 0x7a7a8ef4, 0xaeaee947, 0x8081810, + 0xbabad56f, 0x787888f0, 0x25256f4a, 0x2e2e725c, 0x1c1c2438, 0xa6a6f157, 0xb4b4c773, 0xc6c65197, + 0xe8e823cb, 0xdddd7ca1, 0x74749ce8, 0x1f1f213e, 0x4b4bdd96, 0xbdbddc61, 0x8b8b860d, 0x8a8a850f, + 0x707090e0, 0x3e3e427c, 0xb5b5c471, 0x6666aacc, 0x4848d890, 0x3030506, 0xf6f601f7, 0xe0e121c, + 0x6161a3c2, 0x35355f6a, 0x5757f9ae, 0xb9b9d069, 0x86869117, 0xc1c15899, 0x1d1d273a, 0x9e9eb927, + 0xe1e138d9, 0xf8f813eb, 0x9898b32b, 0x11113322, 0x6969bbd2, 0xd9d970a9, 0x8e8e8907, 0x9494a733, + 0x9b9bb62d, 0x1e1e223c, 0x87879215, 0xe9e920c9, 0xcece4987, 0x5555ffaa, 0x28287850, 0xdfdf7aa5, + 0x8c8c8f03, 0xa1a1f859, 0x89898009, 0xd0d171a, 0xbfbfda65, 0xe6e631d7, 0x4242c684, 0x6868b8d0, + 0x4141c382, 0x9999b029, 0x2d2d775a, 0xf0f111e, 0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c +}; + +static const u32 AESiDecryptTable[] = { + 0xf4a75051, 0x4165537e, 0x17a4c31a, 0x275e963a, 0xab6bcb3b, 0x9d45f11f, 0xfa58abac, 0xe303934b, + 0x30fa5520, 0x766df6ad, 0xcc769188, 0x24c25f5, 0xe5d7fc4f, 0x2acbd7c5, 0x35448026, 0x62a38fb5, + 0xb15a49de, 0xba1b6725, 0xea0e9845, 0xfec0e15d, 0x2f7502c3, 0x4cf01281, 0x4697a38d, 0xd3f9c66b, + 0x8f5fe703, 0x929c9515, 0x6d7aebbf, 0x5259da95, 0xbe832dd4, 0x7421d358, 0xe0692949, 0xc9c8448e, + 0xc2896a75, 0x8e7978f4, 0x583e6b99, 0xb971dd27, 0xe14fb6be, 0x88ad17f0, 0x20ac66c9, 0xce3ab47d, + 0xdf4a1863, 0x1a3182e5, 0x51336097, 0x537f4562, 0x6477e0b1, 0x6bae84bb, 0x81a01cfe, 0x82b94f9, + 0x48685870, 0x45fd198f, 0xde6c8794, 0x7bf8b752, 0x73d323ab, 0x4b02e272, 0x1f8f57e3, 0x55ab2a66, + 0xeb2807b2, 0xb5c2032f, 0xc57b9a86, 0x3708a5d3, 0x2887f230, 0xbfa5b223, 0x36aba02, 0x16825ced, + 0xcf1c2b8a, 0x79b492a7, 0x7f2f0f3, 0x69e2a14e, 0xdaf4cd65, 0x5bed506, 0x34621fd1, 0xa6fe8ac4, + 0x2e539d34, 0xf355a0a2, 0x8ae13205, 0xf6eb75a4, 0x83ec390b, 0x60efaa40, 0x719f065e, 0x6e1051bd, + 0x218af93e, 0xdd063d96, 0x3e05aedd, 0xe6bd464d, 0x548db591, 0xc45d0571, 0x6d46f04, 0x5015ff60, + 0x98fb2419, 0xbde997d6, 0x4043cc89, 0xd99e7767, 0xe842bdb0, 0x898b8807, 0x195b38e7, 0xc8eedb79, + 0x7c0a47a1, 0x420fe97c, 0x841ec9f8, 0x0, 0x80868309, 0x2bed4832, 0x1170ac1e, 0x5a724e6c, + 0xefffbfd, 0x8538560f, 0xaed51e3d, 0x2d392736, 0xfd9640a, 0x5ca62168, 0x5b54d19b, 0x362e3a24, + 0xa67b10c, 0x57e70f93, 0xee96d2b4, 0x9b919e1b, 0xc0c54f80, 0xdc20a261, 0x774b695a, 0x121a161c, + 0x93ba0ae2, 0xa02ae5c0, 0x22e0433c, 0x1b171d12, 0x90d0b0e, 0x8bc7adf2, 0xb6a8b92d, 0x1ea9c814, + 0xf1198557, 0x75074caf, 0x99ddbbee, 0x7f60fda3, 0x1269ff7, 0x72f5bc5c, 0x663bc544, 0xfb7e345b, + 0x4329768b, 0x23c6dccb, 0xedfc68b6, 0xe4f163b8, 0x31dccad7, 0x63851042, 0x97224013, 0xc6112084, + 0x4a247d85, 0xbb3df8d2, 0xf93211ae, 0x29a16dc7, 0x9e2f4b1d, 0xb230f3dc, 0x8652ec0d, 0xc1e3d077, + 0xb3166c2b, 0x70b999a9, 0x9448fa11, 0xe9642247, 0xfc8cc4a8, 0xf03f1aa0, 0x7d2cd856, 0x3390ef22, + 0x494ec787, 0x38d1c1d9, 0xcaa2fe8c, 0xd40b3698, 0xf581cfa6, 0x7ade28a5, 0xb78e26da, 0xadbfa43f, + 0x3a9de42c, 0x78920d50, 0x5fcc9b6a, 0x7e466254, 0x8d13c2f6, 0xd8b8e890, 0x39f75e2e, 0xc3aff582, + 0x5d80be9f, 0xd0937c69, 0xd52da96f, 0x2512b3cf, 0xac993bc8, 0x187da710, 0x9c636ee8, 0x3bbb7bdb, + 0x267809cd, 0x5918f46e, 0x9ab701ec, 0x4f9aa883, 0x956e65e6, 0xffe67eaa, 0xbccf0821, 0x15e8e6ef, + 0xe79bd9ba, 0x6f36ce4a, 0x9f09d4ea, 0xb07cd629, 0xa4b2af31, 0x3f23312a, 0xa59430c6, 0xa266c035, + 0x4ebc3774, 0x82caa6fc, 0x90d0b0e0, 0xa7d81533, 0x4984af1, 0xecdaf741, 0xcd500e7f, 0x91f62f17, + 0x4dd68d76, 0xefb04d43, 0xaa4d54cc, 0x9604dfe4, 0xd1b5e39e, 0x6a881b4c, 0x2c1fb8c1, 0x65517f46, + 0x5eea049d, 0x8c355d01, 0x877473fa, 0xb412efb, 0x671d5ab3, 0xdbd25292, 0x105633e9, 0xd647136d, + 0xd7618c9a, 0xa10c7a37, 0xf8148e59, 0x133c89eb, 0xa927eece, 0x61c935b7, 0x1ce5ede1, 0x47b13c7a, + 0xd2df599c, 0xf2733f55, 0x14ce7918, 0xc737bf73, 0xf7cdea53, 0xfdaa5b5f, 0x3d6f14df, 0x44db8678, + 0xaff381ca, 0x68c43eb9, 0x24342c38, 0xa3405fc2, 0x1dc37216, 0xe2250cbc, 0x3c498b28, 0xd9541ff, + 0xa8017139, 0xcb3de08, 0xb4e49cd8, 0x56c19064, 0xcb84617b, 0x32b670d5, 0x6c5c7448, 0xb85742d0 +}; + +#define ROTATE(x,n) (((x) << (n)) | ((x) >> (32 - (n)))) +#define ENCRYPT(a,b,c,d) (ROTATE(AESiEncryptTable[(a)>>24],24) ^ ROTATE(AESiEncryptTable[((b)>>16)&255],16) ^ ROTATE(AESiEncryptTable[((c)>>8)&255],8) ^ AESiEncryptTable[(d)&255]) +#define DECRYPT(a,b,c,d) (ROTATE(AESiDecryptTable[(a)>>24],24) ^ ROTATE(AESiDecryptTable[((b)>>16)&255],16) ^ ROTATE(AESiDecryptTable[((c)>>8)&255],8) ^ AESiDecryptTable[(d)&255]) +#define SUBSTITUTE(table,a,b,c,d) (((u32)table[(a)>>24]<<24) | ((u32)table[((b)>>16)&255]<<16) | ((u32)table[((c)>>8)&255]<<8) | table[(d)&255]) + +void AESiEncryptBlock(AESContext* context, u32* output, const u32* input) { + u32 rounds = context->rounds; + const u32* key = context->keys + 4; + u32 a=input[0]^context->keys[0], b=input[1]^context->keys[1], c=input[2]^context->keys[2], d=input[3]^context->keys[3]; + while (--rounds != 0) { + u32 nextA=ENCRYPT(a,b,c,d)^key[0]; + u32 nextB=ENCRYPT(b,c,d,a)^key[1]; + u32 nextC=ENCRYPT(c,d,a,b)^key[2]; + u32 nextD=ENCRYPT(d,a,b,c)^key[3]; + a=nextA; b=nextB; c=nextC; d=nextD; + key += 4; + } + output[0] = SUBSTITUTE(AESiSubShiftTable,a,b,c,d)^key[0]; + output[1] = SUBSTITUTE(AESiSubShiftTable,b,c,d,a)^key[1]; + output[2] = SUBSTITUTE(AESiSubShiftTable,c,d,a,b)^key[2]; + output[3] = SUBSTITUTE(AESiSubShiftTable,d,a,b,c)^key[3]; +} + +#define DOUBLE_BYTES(x) ((((x)&0x7f7f7f7f)<<1) ^ ((((x)&0x80808080)>>7)*0x1b)) + +void AESiDecryptBlock(AESContext* context, u32* output, const u32* input) { + u32 rounds=context->rounds; + u32* key=context->keys + rounds*4; + u32 a,b,c,d; + if (context->needsTransform) { + u32 round; + for (round=1; roundrounds; ++round) { + u32 word; + for (word=0; word<4; ++word) { + u32 value=context->keys[round*4+word]; + u32 twice=DOUBLE_BYTES(value); + u32 four=DOUBLE_BYTES(twice); + u32 eight=DOUBLE_BYTES(four)^value; + u32 mixed=eight ^ (four ^ ROTATE(eight,8)); + mixed ^= twice ^ ROTATE(mixed,8); + mixed ^= value ^ ROTATE(mixed,8); + context->keys[round*4+word]=mixed; + } + } + context->needsTransform=0; + } + a=input[0]^key[0]; b=input[1]^key[1]; c=input[2]^key[2]; d=input[3]^key[3]; + key-=4; + while (--rounds != 0) { + u32 nextA=DECRYPT(a,d,c,b)^key[0]; + u32 nextB=DECRYPT(b,a,d,c)^key[1]; + u32 nextC=DECRYPT(c,b,a,d)^key[2]; + u32 nextD=DECRYPT(d,c,b,a)^key[3]; + a=nextA; b=nextB; c=nextC; d=nextD; + key-=4; + } + output[0]=SUBSTITUTE(AESiInvSubShiftTable,a,d,c,b)^key[0]; + output[1]=SUBSTITUTE(AESiInvSubShiftTable,b,a,d,c)^key[1]; + output[2]=SUBSTITUTE(AESiInvSubShiftTable,c,b,a,d)^key[2]; + output[3]=SUBSTITUTE(AESiInvSubShiftTable,d,c,b,a)^key[3]; +} + +BOOL NETAESCreateEx(AESContext* context, const void* key, u32 keyLength, const void* iv, const AESBlockMode* mode) { + BOOL result=FALSE; + u32 words,index,value; + u32* schedule; + if (keyLength != 16 && keyLength != 24 && keyLength != 32) { + OSReport("NETAESCreateEx() failed! (key-length is allowed only 16, 20, 24 BYTEs)"); + } else { + context->rounds=keyLength/4+6; + context->needsTransform=1; + context->mode=mode; + memcpy(context->chain, iv, 16); + schedule=context->keys; + words=keyLength/4; + memcpy(schedule,key,keyLength); + value=schedule[words-1]; + for(index=words; index<(context->rounds+1)*4; ++index) { + if (index%words == 0) { + value=SUBSTITUTE(AESiSubShiftTable,value<<8,value<<8,value<<8, value>>24) ^ ((u32)AESiRoundKeyRcon0[index/words-1]<<24); + } else if(words>6 && index%words==4) { + value=SUBSTITUTE(AESiSubShiftTable,value,value,value,value); + } + value ^= schedule[index-words]; + schedule[index]=value; + } + result=TRUE; + } + return result; +} + +BOOL NETAESCreate(AESContext* context, const void* key, u32 keyLength, const void* iv) { + return NETAESCreateEx(context,key,keyLength,iv,&NET_AES_BLOCK_MODE_CBC); +} + +void NETAESDelete(AESContext* context) { +} + +BOOL NETAESEncrypt(AESContext* context, u32* output, const u32* input, u32 length) { + BOOL result=FALSE; + void (*encrypt)(AESContext*,u32*,const u32*)=context->mode->encrypt; + if (encrypt==NULL) OSReport("this mode cannot support encryption!"); + else if (length&15) OSReport("length has not suited to AES block alignment!"); + else { + while(length!=0) { + encrypt(context,output,input); + input+=4; + output+=4; + length-=16; + } + result=TRUE; + } + return result; +} + +BOOL NETAESDecrypt(AESContext* context, u32* output, const u32* input, u32 length) { + BOOL result=FALSE; + void (*decrypt)(AESContext*,u32*,const u32*)=context->mode->decrypt; + if (decrypt==NULL) OSReport("this mode cannot support decryption!"); + else if (length&15) OSReport("length has not suited to AES block alignment!"); + else { + while(length!=0) { + decrypt(context,output,input); + input+=4; + output+=4; + length-=16; + } + result=TRUE; + } + return result; +} + +static void NETiAESEncryptoBlock(AESContext* context, u32* output, const u32* input) { + u32 block[4]; + block[0]=input[0]^context->chain[0]; + block[1]=input[1]^context->chain[1]; + block[2]=input[2]^context->chain[2]; + block[3]=input[3]^context->chain[3]; + AESiEncryptBlock(context,output,block); + context->chain[0]=output[0]; context->chain[1]=output[1]; context->chain[2]=output[2]; context->chain[3]=output[3]; +} + +static void NETiAESDecryptoBlock(AESContext* context, u32* output, const u32* input) { + u32 a=context->chain[0], b=context->chain[1], c=context->chain[2], d=context->chain[3]; + context->chain[0]=input[0]; context->chain[1]=input[1]; context->chain[2]=input[2]; context->chain[3]=input[3]; + AESiDecryptBlock(context,output,input); + output[0]^=a; output[1]^=b; output[2]^=c; output[3]^=d; +} diff --git a/libs/RevoEX/src/net/hmac.c b/libs/RevoEX/src/net/hmac.c new file mode 100644 index 00000000..10918c1d --- /dev/null +++ b/libs/RevoEX/src/net/hmac.c @@ -0,0 +1,69 @@ +#include +#include +#include + +typedef struct DigestInterface { + u32 digestSize; + u32 blockSize; + u32 contextSize; + u32 flags; + void (*init)(void*); + void (*update)(void*, const void*, u32); + void (*getDigest)(void*, void*); +} DigestInterface; + +typedef struct HMACContext { + DigestInterface interface; + s32 keyLength; + u8 digestContext[96]; + u8 key[64]; +} HMACContext; + +void NETHMACInit(HMACContext* context, const DigestInterface* interface, const void* key, u32 length) { + const char* function = "NETHMACInit"; + u8 innerKey[64]; + u32 i; + u32 keyLength; + void* work = context->digestContext; + context->interface = *interface; + if (context->interface.contextSize > 96 || context->interface.blockSize > 64) { + OSReport("%s(%d):[warning in %s]", "hmac.c", 100, function); + OSReport("specified interface needs too large workmemory."); + OSReport("\n"); + return; + } + if (length <= context->interface.blockSize) { + memcpy(context->key, key, length); + context->keyLength = length; + } else { + context->interface.init(work); + context->interface.update(work, key, length); + context->interface.getDigest(work, context->key); + context->keyLength = context->interface.digestSize; + } + keyLength = context->keyLength; + for (i=0; ikey[i] ^ 0x36; + memset(innerKey + keyLength, 0x36, context->interface.blockSize - keyLength); + context->interface.init(context->digestContext); + context->interface.update(context->digestContext, innerKey, context->interface.blockSize); +} + +void NETHMACUpdate(HMACContext* context, const void* data, u32 length) { + context->interface.update(context->digestContext, data, length); +} + +void NETHMACGetDigest(HMACContext* context, void* digest) { + u8 innerDigest[64]; + u8 outerKey[64]; + u32 i; + u32 keyLength; + void* work = context->digestContext; + context->interface.getDigest(work, innerDigest); + keyLength = context->keyLength; + for (i=0; ikey[i] ^ 0x5c; + memset(outerKey + keyLength, 0x5c, context->interface.blockSize - keyLength); + context->interface.init(context->digestContext); + context->interface.update(context->digestContext, outerKey, context->interface.blockSize); + context->interface.update(work, innerDigest, context->interface.digestSize); + context->interface.getDigest(work, digest); +} diff --git a/libs/RevoEX/src/net/md5.c b/libs/RevoEX/src/net/md5.c new file mode 100644 index 00000000..b50075a6 --- /dev/null +++ b/libs/RevoEX/src/net/md5.c @@ -0,0 +1,111 @@ +#include +#include + +static void ProcessBlock(NETMD5Context* context); + +void NETMD5Init(NETMD5Context* context) { + context->a = 0x67452301; + context->b = 0xefcdab89; + context->c = 0x98badcfe; + context->d = 0x10325476; + context->length = 0; +} + +void NETMD5Update(NETMD5Context* context, const void* input, u32 length) { + u32 available; + const u8* data; + u32 offset; + int blocks; + offset = context->length & 63; + context->length += length; + available = 64 - offset; + data = input; + if (available > length) { + if (length) memcpy(context->buffer8 + offset, data, length); + } else { + memcpy(context->buffer8 + offset, data, available); + ProcessBlock(context); + length -= available; + data += available; + blocks = length >> 6; + while (blocks > 0) { + memcpy(context->buffer8, data, 64); + data += 64; + ProcessBlock(context); + --blocks; + } + length &= 63; + if (length) memcpy(context->buffer8, data, length); + } +} + +#define SWAP32(x) (((((x) << 8) | ((x) >> 24)) & 0x00ff00ff) | ((((x) << 24) | ((x) >> 8)) & 0xff00ff00)) + +void NETMD5GetDigest(NETMD5Context* context, void* digest) { + static u8 endMarker = 0x80; + u32* output = digest; + u64 bits = context->length << 3; + u32 low = bits; + u32 high = bits >> 32; + u32 offset, available; + NETMD5Update(context, &endMarker, 1); + offset = context->length & 63; + available = 64 - offset; + if (available < 8) { + memset(context->buffer8 + offset, 0, available); + ProcessBlock(context); + offset = 0; + available = 64; + } + if (available > 8) memset(context->buffer8 + offset, 0, available - 8); + context->buffer32[14] = SWAP32(low); + context->buffer32[15] = SWAP32(high); + ProcessBlock(context); + __stwbrx(context->a, digest, 0); + __stwbrx(context->b, &output[1], 0); + __stwbrx(context->c, &output[2], 0); + __stwbrx(context->d, &output[3], 0); + memset(context, 0, sizeof(*context)); +} + +#define ROTATE(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) +#define STEP(a, b, c, d, f, word, n) ((a) += (f), (a) = (b) + ROTATE(__lwbrx(0, (int)(word)) + (*constant + (a)), n)) + +static void ProcessBlock(NETMD5Context* context) { + static u32 constants[64] = {0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501, 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821, 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, 0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8, 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A, 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70, 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05, 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665, 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1, 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391}; + static u32 indices[48] = {0x00000001, 0x00000006, 0x0000000B, 0x00000000, 0x00000005, 0x0000000A, 0x0000000F, 0x00000004, 0x00000009, 0x0000000E, 0x00000003, 0x00000008, 0x0000000D, 0x00000002, 0x00000007, 0x0000000C, 0x00000005, 0x00000008, 0x0000000B, 0x0000000E, 0x00000001, 0x00000004, 0x00000007, 0x0000000A, 0x0000000D, 0x00000000, 0x00000003, 0x00000006, 0x00000009, 0x0000000C, 0x0000000F, 0x00000002, 0x00000000, 0x00000007, 0x0000000E, 0x00000005, 0x0000000C, 0x00000003, 0x0000000A, 0x00000001, 0x00000008, 0x0000000F, 0x00000006, 0x0000000D, 0x00000004, 0x0000000B, 0x00000002, 0x00000009}; + u32 a = context->a, b = context->b, c = context->c, d = context->d; + u32* block = context->buffer32; + u32* word = block; + u32* constant = constants; + u32* index = indices; + int round; + for (round = 0; round < 4; ++round) { + STEP(a,b,c,d,(b & c) | (~b & d),word,7); ++word; ++constant; + STEP(d,a,b,c,(a & b) | (~a & c),word,12); ++word; ++constant; + STEP(c,d,a,b,(d & a) | (~d & b),word,17); ++word; ++constant; + STEP(b,c,d,a,(c & d) | (~c & a),word,22); ++word; ++constant; + } + for (round = 0; round < 4; ++round) { + STEP(a,b,c,d,(b & d) | (c & ~d),block + *index,5); ++index; ++constant; + STEP(d,a,b,c,(a & c) | (b & ~c),block + *index,9); ++index; ++constant; + STEP(c,d,a,b,(d & b) | (a & ~b),block + *index,14); ++index; ++constant; + STEP(b,c,d,a,(c & a) | (d & ~a),block + *index,20); ++index; ++constant; + } + for (round = 0; round < 4; ++round) { + STEP(a,b,c,d,d ^ b ^ c,block + *index,4); ++index; ++constant; + STEP(d,a,b,c,c ^ a ^ b,block + *index,11); ++index; ++constant; + STEP(c,d,a,b,b ^ d ^ a,block + *index,16); ++index; ++constant; + STEP(b,c,d,a,a ^ c ^ d,block + *index,23); ++index; ++constant; + } + for (round = 0; round < 4; ++round) { + STEP(a,b,c,d,c ^ (b | ~d),block + *index,6); ++index; ++constant; + STEP(d,a,b,c,b ^ (a | ~c),block + *index,10); ++index; ++constant; + STEP(c,d,a,b,a ^ (d | ~b),block + *index,15); ++index; ++constant; + STEP(b,c,d,a,d ^ (c | ~a),block + *index,21); ++index; ++constant; + } + context->a += a; + context->b += b; + context->c += c; + context->d += d; +} diff --git a/libs/RevoEX/src/net/neterrorcode.c b/libs/RevoEX/src/net/neterrorcode.c new file mode 100644 index 00000000..eabbff1f --- /dev/null +++ b/libs/RevoEX/src/net/neterrorcode.c @@ -0,0 +1,74 @@ +#include +#include + +int NCDiGetEnabledConfigList(u32* wireless, u32* wired, u32* other); +int GetStartupErrorCode(int error, int connection); + +static int FirstConfig(u32 configs) { + int index = 0; + u32 mask = 1; + for (; index < 32; ++index) { + if (configs & mask) return index; + mask <<= 1; + } + return -1; +} + +#pragma dont_inline on +int NETiGetConnectionTypeFromConfigList(u32 wireless, u32 wired, u32 other); +#pragma dont_inline reset +int NETiGetConnectionTypeFromConfigList(u32 wireless, u32 wired, u32 other) { + int connection = 99; + if (wireless != 0) { + if (wired == 0 && other == 0) connection = FirstConfig(wireless) + 20; + } else if (wired != 0) { + if (other == 0) connection = FirstConfig(wired) + 30; + } else if (other != 0) { + connection = FirstConfig(other) + 40; + } + return connection; +} + +#pragma dont_inline on +int NETGetStartupErrorCode(int error) { + u32 other, wired, wireless; + int connection = 99; + if (NCDiGetEnabledConfigList(&wireless, &wired, &other) >= 0) + connection = NETiGetConnectionTypeFromConfigList(wireless, wired, other); + if (connection < 0) { + error = (int)0x80000000; + connection = 99; + } + return GetStartupErrorCode(error, connection) - connection; +} + +#pragma dont_inline reset +int NETGetStartupErrorCodeEx(int error, int connection) { + return GetStartupErrorCode(error, connection) - connection; +} + +int GetStartupErrorCode(int error, int connection) { + if (error >= 0) return 0; + switch (error) { + case -45: return -50200; + case -28: return -50300; + case -62: return -50400; + case -111: return -52700; + case -121: + if (connection >= 20 && connection < 30) return -51400; + return -51000; + case -39: + case -48: + case -76: + case -112: + if (connection >= 20 && connection < 30) return -51400; + return -51300; + case -100: + case -101: + case -102: return -52000; + case (int)0x80000000: return -50100; + default: + OSReport("Unknown SOStartup Error: %d\n", error); + return -50100; + } +} diff --git a/libs/RevoEX/src/net/sha1.c b/libs/RevoEX/src/net/sha1.c new file mode 100644 index 00000000..785793c1 --- /dev/null +++ b/libs/RevoEX/src/net/sha1.c @@ -0,0 +1,110 @@ +#include +#include + +typedef struct SHA1State { + u32 state[5]; + u8 buffer[64]; + u32 buffered; + u32 blocksLow; + u32 blocksHigh; +} SHA1State; + +typedef struct DigestInterface { + u32 digestSize; + u32 blockSize; + u32 contextSize; + u32 flags; + void (*init)(NETSHA1Context*); + void (*update)(NETSHA1Context*, const void*, u32); + void (*getDigest)(NETSHA1Context*, void*); +} DigestInterface; + +void NETSHA1iProcessBlock(NETSHA1Context* context); + +void NETSHA1Init(NETSHA1Context* context) { + SHA1State* work = (SHA1State*)context; + work->blocksLow = 0; + work->blocksHigh = 0; + work->buffered = 0; + work->state[0] = 0x67452301; + work->state[1] = 0xefcdab89; + work->state[2] = 0x98badcfe; + work->state[3] = 0x10325476; + work->state[4] = 0xc3d2e1f0; +} + +void NETSHA1Update(NETSHA1Context* context, const void* input, u32 length) { + SHA1State* work = (SHA1State*)context; + u32 available; + u32 remaining = length; + const u8* data = input; + while (remaining != 0) { + available = 64 - work->buffered; + if (available > remaining) available = remaining; + memcpy(work->buffer + work->buffered, data, available); + work->buffered += available; + data += available; + remaining -= available; + if (work->buffered >= 64) { + NETSHA1iProcessBlock(context); + work->buffered = 0; + if (++work->blocksLow == 0) ++work->blocksHigh; + } + } +} + +void NETSHA1GetDigest(NETSHA1Context* context, void* digest) { + static const u8 endMarker = 0x80; + static const u8 zeroBytes[8] = {0}; + SHA1State* work = (SHA1State*)context; + u32 bitLength[2]; + u32 length; + u32 available; + u32 endSpace; + bitLength[1] = (work->blocksLow << 9) + (work->buffered << 3); + bitLength[0] = (work->blocksHigh << 9) + (work->blocksLow >> 23); + NETSHA1Update(context, &endMarker, 1); + endSpace = 64 - work->buffered; + if (endSpace < 8) NETSHA1Update(context, zeroBytes, endSpace); + length = 56 - work->buffered; + while (length != 0) { + available = 64 - work->buffered; + if (available > length) available = length; + memset(work->buffer + work->buffered, 0, available); + work->buffered += available; + length -= available; + if (work->buffered >= 64) { + NETSHA1iProcessBlock(context); + work->buffered = 0; + if (++work->blocksLow == 0) ++work->blocksHigh; + } + } + NETSHA1Update(context, bitLength, 8); + memcpy(digest, context, 20); +} + +const DigestInterface* NETGetSHA1Interface(void) { + static const DigestInterface interface = {20, 64, 96, 0, NETSHA1Init, NETSHA1Update, NETSHA1GetDigest}; + return &interface; +} + +#define ROTATE(x,n) (((x) << (n)) | ((x) >> (32 - (n)))) +#define EXPAND() if (round >= 16) words[round & 15] = ROTATE((words[(round-3)&15] ^ words[(round-8)&15]) ^ (words[(round-16)&15] ^ words[(round-14)&15]), 1) +#define ROUND(f,k) { u32 next = (f) + (k); EXPAND(); next = words[round & 15] + (ROTATE(a,5) + (next + e)); e=d; d=c; c=ROTATE(b,30); b=a; a=next; } + +void NETSHA1iProcessBlock(NETSHA1Context* context) { + SHA1State* work = (SHA1State*)context; + u32 words[16]; + int round=0; + u32 a=work->state[0], b=work->state[1], c=work->state[2], d=work->state[3], e=work->state[4]; + { int word; for (word=0; word<16; ++word) words[word] = ((u32*)work->buffer)[word]; } + for (; round < 20; ++round) ROUND((b & c) | (~b & d), 0x5a827999); + for (; round < 40; ++round) ROUND(b ^ c ^ d, 0x6ed9eba1); + for (; round < 60; ++round) ROUND((c & d) | (b & (c | d)), 0x8f1bbcdc); + for (; round < 80; ++round) ROUND(b ^ c ^ d, 0xca62c1d6); + work->state[0] += a; + work->state[1] += b; + work->state[2] += c; + work->state[3] += d; + work->state[4] += e; +} diff --git a/libs/RevoEX/src/nhttp/NHTTP_recvbuf.c b/libs/RevoEX/src/nhttp/NHTTP_recvbuf.c new file mode 100644 index 00000000..4870468b --- /dev/null +++ b/libs/RevoEX/src/nhttp/NHTTP_recvbuf.c @@ -0,0 +1,136 @@ +#include + +void* NHTTPi_memcpy(void*, const void*, u32); +s32 NHTTPi_SocRecv(void*, NHTTPRequestInfo*, s32, void*, s32, s32); + +static void FindHeaderBlock(const NHTTPResponseInfo* response, s32 position, NHTTPi_HDRBUFLIST** block, s32* offset) { + if(position<1024) { *offset=position; *block=NULL; } + else { + s32 blocks=(position-1024)>>9; + *block=response->hdrBufBlock_p; + while(blocks--) *block=(*block)->next_p; + *offset=(position-1024)&511; + } +} + +static s8 ReadHeaderChar(const NHTTPResponseInfo* response, NHTTPi_HDRBUFLIST** block, s32* offset) { + if(!*block) { + if(*offset<1024) return (s8)response->hdrBufFirst[(*offset)++]; + *block=response->hdrBufBlock_p; + *offset=0; + } else if(*offset==512) { *offset=0; *block=(*block)->next_p; } + return (*block)->block[(*offset)++]; +} + +static int LowerCase(int character) { + if((character>='A') & (character<='Z')) character+=32; + return character; +} + +s32 NHTTPi_findNextLineHdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 limit, s32* colon, s32* newlineLength) { + NHTTPi_HDRBUFLIST* block; + s32 offset; + s32 next=-1; + BOOL carriage=FALSE; + if(colon) *colon=-1; + if(position>=limit) return -1; + FindHeaderBlock(response,position,&block,&offset); + for(; position=limit) return -1; + FindHeaderBlock(response,position,&block,&offset); + for(; position=limit) return -1; + FindHeaderBlock(response,position,&block,&offset); + character=ReadHeaderChar(response,&block,&offset); + while(LowerCase(character)==LowerCase(*token)) { + if(*token==0 || *token==' ' || *token==delimiter || position==limit-1) return 0; + character=ReadHeaderChar(response,&block,&offset); + ++position; + ++token; + } + return -1; +} + +s32 NHTTPi_loadFromHdrRecvBuf(NHTTPResponseInfo* response, char* destination, s32 position, s32 length) { + + s32 amount; + NHTTPi_HDRBUFLIST* block; + if(position+length>response->headerLen) return FALSE; + if(length) { + if(position<1024) { + amount=length; + if(length>1024-position) amount=1024-position; + NHTTPi_memcpy(destination,response->hdrBufFirst+position,amount); + position+=amount; length-=amount; destination+=amount; + } + if(length) { + s32 blocks; + position-=1024; + block=response->hdrBufBlock_p; + blocks=position>>9; + position&=511; + while(blocks--) block=block->next_p; + while(length) { + amount=length; + if(length>512-position) amount=512-position; + NHTTPi_memcpy(destination,block->block+position,amount); + position=(position+amount)&511; + block=block->next_p; + length-=amount; destination+=amount; + } + } + } + return TRUE; +} + +BOOL NHTTPi_isRecvBufFull(NHTTPResponseInfo* response, u32 length) { return length>=response->recvBufLen; } + +s32 NHTTPi_RecvBuf(void* mutex, NHTTPRequestInfo* request, s32 socket, u32 offset, s32 flags) { + NHTTPResponseInfo* response=request->response; + return NHTTPi_SocRecv(mutex,request,socket,response->recvBuf_p+offset,response->recvBufLen-offset,flags); +} + +s32 NHTTPi_RecvBufN(void* mutex, NHTTPRequestInfo* request, s32 socket, u32 offset, s32 length, s32 flags) { + NHTTPResponseInfo* response=request->response; + s32 available; + if(response->recvBufLen<=offset) return -1003; + available=response->recvBufLen-offset; + if(length>available) length=available; + return NHTTPi_SocRecv(mutex,request,socket,response->recvBuf_p+offset,length,flags); +} diff --git a/libs/RevoEX/src/nhttp/NHTTP_socket_RVL.c b/libs/RevoEX/src/nhttp/NHTTP_socket_RVL.c new file mode 100644 index 00000000..249ce2c1 --- /dev/null +++ b/libs/RevoEX/src/nhttp/NHTTP_socket_RVL.c @@ -0,0 +1,196 @@ +#include +#include +#include + +struct NHTTPBgnEndInfo { + NCDIpConfig ipConfig; + NHTTPAlloc alloc; + NHTTPFree free; + BOOL started; + s32 socket; + s32 sslError; + NHTTPErr error; + u32 stop; + void* threadStack; + void (*sslInit)(SSLId, void*); +}; + +void NHTTPi_lockReqList(void*); +void NHTTPi_unlockReqList(void*); +void NHTTPi_SetSSLError(NHTTPBgnEndInfo*, s32); +NHTTPConnectionInfo* NHTTPi_Request2Connection(void*, NHTTPRequestInfo*); +void* NHTTPi_memcpy(void*, const void*, u32); +void* NHTTPi_memclr(void*, u32); +s32 NHTTPi_SocSSLConnect(NHTTPBgnEndInfo*, void*, NHTTPRequestInfo*, s32); + +s32 NHTTPi_SocOpen(NHTTPRequestInfo* request) { + s32 socket=__SOCreateSocket(2,1,0); + s32 bufferSize=0; + if(request) bufferSize=request->recvBufferSize; + if(socket>=0 && bufferSize!=0) SOSetSockOpt(socket,0xffff,0x1002,&bufferSize,4); + return socket; +} + +s32 NHTTPi_SocClose(void* mutex, NHTTPRequestInfo* request, s32 socket) { + NHTTPi_lockReqList(mutex); + if(request->sslId>0) { SSLShutdown(request->sslId); request->sslId=-1; } + NHTTPi_unlockReqList(mutex); + return SOClose(socket); +} + +s32 NHTTPi_SocConnect(NHTTPBgnEndInfo* info, void* mutex, NHTTPRequestInfo* request, s32 socket, u32 address, u32 port) { + SOSockAddrIn destination; + destination.len=8; destination.family=2; + destination.port=SOHtoNs(port); + destination.addr.addr=address; + if(SOConnect(socket,&destination)<0) { + s32 error=-1001; + if(request->cancel) error=-1002; + return error; + } + if(request->secure && !request->proxyEnabled) return NHTTPi_SocSSLConnect(info,mutex,request,socket); + return 0; +} + +s32 NHTTPi_SocSSLConnect(NHTTPBgnEndInfo* info, void* mutex, NHTTPRequestInfo* request, s32 socket) { + BOOL complete=FALSE; + request->sslId=SSLNew(request->verifyOption,request->host); + if(info->sslInit && request->_unkD4) info->sslInit(request->sslId,request->_unkD4); + if(request->clientCertDefault==1) { + if(SSLSetBuiltinClientCert(request->sslId,request->builtinClientCert)!=0) return -1005; + } else if(request->clientCertData && request->privateKeyData) { + if(SSLSetClientCert(request->sslId,request->clientCertData,request->clientCertSize,request->privateKeyData,request->privateKeySize)!=0) return -1005; + } + if(request->rootCAData) { + if(SSLSetRootCA(request->sslId,request->rootCAData,request->rootCASize)!=0) return -1004; + } else { + if(SSLSetBuiltinRootCA(request->sslId,request->builtinRootCA)!=0) return -1004; + } + if(SSLConnect(request->sslId,socket)<-1) return -1001; + while(!complete) { + NHTTPConnectionInfo* connection=NHTTPi_Request2Connection(mutex,request); + s32 result=SSLDoHandshake(request->sslId); + NHTTPi_SetSSLError(info,result); + if(connection) connection->sslError=result; + switch(result) { + case -7: + case -3: + case -2: break; + case 0: complete=TRUE; break; + default: return -1001; + } + } + return 0; +} + +s32 NHTTPi_SocRecv_sub(NHTTPConnectionInfo* connection, s32 socket, void* data, s32 length, s32 flags) { + u8* buffer=connection->recvBuf; + s32 received=0; + if(length>0) { + if(connection->recvBufDataLen==0) { + s32 result=SORecv(socket,buffer,32768,flags); + if(result>0) { + connection->recvBufDataLen=result; + connection->recvBufOffset=0; + } else return result; + } + if(connection->recvBufDataLen!=0) { + if((u32)length>connection->recvBufDataLen) length=connection->recvBufDataLen; + NHTTPi_memcpy(data,buffer+connection->recvBufOffset,length); + connection->recvBufDataLen-=length; + if(connection->recvBufDataLen==0) { + NHTTPi_memclr(buffer,32768); + connection->recvBufOffset=0; + } else connection->recvBufOffset+=length; + received=length; + } + } + return received; +} + +s32 NHTTPi_SocRecv(void* mutex, NHTTPRequestInfo* request, s32 socket, void* data, s32 length, s32 flags) { + s32 result; + if(request->sslId>0) result=SSLRead(request->sslId,data,length); + else { + NHTTPConnectionInfo* connection=NHTTPi_Request2Connection(mutex,request); + if(connection) result=NHTTPi_SocRecv_sub(connection,socket,data,length,flags); + else return -1001; + } + if(result<0) { + if(request->cancel) return -1002; + if(request->sslId>0) { if(result==-7 || result==-6) return 0; } + else if(result==-56) return 0; + return -1001; + } + return result; +} + +s32 NHTTPi_SocSend_sub(s32 socket, const char* data, u32 length, s32 flags) { + char buffer[32] ATTRIBUTE_ALIGN(32); + u32 head=((u32)data&31) ? 32-((u32)data&31) : 0; + s32 sent=0; + s32 result; + NHTTPi_memclr(buffer,32); + if(head) { + if(head>length) head=length; + NHTTPi_memcpy(buffer,data,head); + result=SOSend(socket,buffer,head,flags); + if(result<=0) return result; + sent=result; + if((u32)result0) { + head=length&~31; + if(head) { + result=SOSend(socket,data,head,flags); + if(result>0) { + sent+=result; + if((u32)result0) return sent; return result; } + } + } + if((s32)length>0) { + head=length&31; + if(head) { + NHTTPi_memclr(buffer,32); + NHTTPi_memcpy(buffer,data,head); + result=SOSend(socket,buffer,head,flags); + if(result>0) sent+=result; + else { if(sent>0) return sent; return result; } + } + } + return sent; +} + +s32 NHTTPi_SocSend(NHTTPRequestInfo* request, s32 socket, const char* data, s32 length, s32 flags) { + s32 result; + SSLId ssl=request->sslId; + if(ssl>0) result=SSLWrite(ssl,data,length); + else result=NHTTPi_SocSend_sub(socket,data,length,flags); + if(result<0) { + if(request->cancel) return -1002; + if(request->sslId>0) { if(result==-7 || result==-6) return 0; } + else if(result==-56) return 0; + return -1001; + } + return result; +} + +void NHTTPi_SocCancel(void* mutex, NHTTPRequestInfo* request, s32 socket) { + NHTTPi_lockReqList(mutex); + if(socket>=0) SOShutdown(socket,2); + NHTTPi_unlockReqList(mutex); +} + +u32 NHTTPi_resolveHostname(NHTTPBgnEndInfo* info, const char* hostname) { + u32 address=0; + SOAddrInfo* result; + if(SOGetAddrInfo(hostname,NULL,NULL,&result)==0) { + SOSockAddrIn* socketAddress=result->addr; + NHTTPi_memcpy(&address,&socketAddress->addr,4); + SOFreeAddrInfo(result); + } else address=0; + return address; +} diff --git a/libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL.c b/libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL.c new file mode 100644 index 00000000..b4310f4b --- /dev/null +++ b/libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL.c @@ -0,0 +1,166 @@ +#include +#include + +void* NHTTPi_memcpy(void* destination, const void* source, u32 size) { return memcpy(destination,source,size); } +s32 NHTTPi_strlen(const char* string) { return strlen(string); } +s32 NHTTPi_strcmp(const char* left, const char* right) { return strcmp(left,right); } +void* NHTTPi_memclr(void* destination, u32 size) { return memset(destination,0,size); } + +static int LowerCase(int character) { + if((character>='A') & (character<='Z')) character+=32; + return character; +} + +s32 NHTTPi_strnicmp(const char* left, const char* right, s32 length) { + while(length>0) { + int a=*left++, b=*right++; + if(a==0 || b==0) { if(a==0 && b==0) { length=0; break; } } + b=LowerCase(b); + a=LowerCase(a); + if(a!=b) break; + --length; + } + return length; +} + +static BOOL UrlPlain(int character) { + return (character>='0' && character<='9') || (character>='A' && character<='Z') || (character>='a' && character<='z') || character==' '; +} + +s32 NHTTPi_getUrlEncodedSize(const char* string) { + int character=*string++; + s32 size=0; + while(character) { + if((character>='0' && character<='9') || (character>='A' && character<='Z') || (character>='a' && character<='z') || character==' ') ++size; + else size+=3; + character=*string++; + } + return size; +} + +s32 NHTTPi_getUrlEncodedSize2(const char* string, s32 length) { + int character=*string++; + s32 size=0; + for(; length>0; --length) { + if((character>='0' && character<='9') || (character>='A' && character<='Z') || (character>='a' && character<='z') || character==' ') ++size; + else size+=3; + character=*string++; + } + return size; +} + +s32 NHTTPi_encodeUrlChar(char* destination, s8 character) { + if(character==' ') { destination[0]='+'; return 1; } + if((character>='0' && character<='9') || (character>='A' && character<='Z') || (character>='a' && character<='z')) { + destination[0]=character; return 1; + } else { + int high=(character>>4)&15; + int low=character&15; + destination[0]='%'; + destination[1]=high<10 ? high+'0' : high+'A'-10; + destination[2]=low<10 ? low+'0' : low+'A'-10; + return 3; + } +} + +s32 NHTTPi_strToHex(const char* string, s32 length) { + s32 value=0; + BOOL started=FALSE; + if(length>8) return -1; + if((length==8) & (*string>='7')) return -1; + for(; length>0; --length,++string) { + s8 character=LowerCase(*string); + if(character>='0' && character<='9') { value=(value<<4)+character-'0'; started=TRUE; } + else if(character>='a' && character<='f') { value=(value<<4)+character-'a'+10; started=TRUE; } + else { + if(started && (character==' ' || character==0)) break; + if(!started && character==' ') continue; + return -1; + } + } + return value; +} + +s32 NHTTPi_strToInt(const char* string, s32 length) { + s32 value; + BOOL started; + if(length>10) return -1; + value=0; started=FALSE; + for(; length>0; --length,++string) { + s8 character=*string; + s32 previous; + if(started && (character==' ' || character==0)) break; + if(!started && character==' ') continue; + if(character<'0' || character>'9') return -1; + previous=value; + value=value*10+character-'0'; + started=TRUE; + if(previous>value) return -1; + } + return value; +} + +s32 NHTTPi_intToStr(char* destination, u32 value) { + u32 scales[9]={1000000000,100000000,10000000,1000000,100000,10000,1000,100,10}; + char* output=destination; + s32 length=0; + BOOL started=FALSE; + int digit; + for(digit=0; digit<9; ++digit) { + if(value>=scales[digit]) { + u32 quotient=value/scales[digit]; + started=TRUE; + ++length; + *output++=quotient+'0'; + value-=quotient*scales[digit]; + } else if(started) { *output++='0'; ++length; } + } + destination[length]=value+'0'; + return length+1; +} + +s32 NHTTPi_compareToken(const char* left, const char* right) { + for (;;) { + int rightCharacter=LowerCase(*right); + int leftCharacter=LowerCase(*left); + if(leftCharacter!=rightCharacter) break; + if(*left==0 || *left==' ') return 0; + ++left; ++right; + } + return -1; +} + +s32 NHTTPi_strtonum(const char* string, u32 length) { + int digits=0; + s32 value=0; + while(length--) { + int character=*string++; + if(character==' ') continue; + if((character>='0') & (character<='9')) { + value=value*10+character-'0'; + ++digits; + if(digits>9) return -1; + } + } + if(digits==0) return -1; + return value; +} + +s32 NHTTPi_Base64Encode(char* destination, const char* source) { + static char alphabet[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + const char* table=alphabet; + char* output=destination; + u32 length=strlen(source); + s32 consumed=0; + for(; consumed<(s32)length; consumed+=3) { + output[0]=table[source[0]>>2]; + output[1]=table[((source[0]&3)<<4)+(source[1]>>4)]; + output[2]=table[((source[1]&15)<<2)+(source[2]>>6)]; + output[3]=table[source[2]&63]; + source+=3; output+=4; + } + if(consumed==length+1) output[-1]='='; + else if(consumed==length+2) { output[-2]='='; output[-1]='='; } + *output=0; + return strlen(destination); +} diff --git a/libs/RevoEX/src/nhttp/d_nhttp_private.c b/libs/RevoEX/src/nhttp/d_nhttp_private.c new file mode 100644 index 00000000..2e423186 --- /dev/null +++ b/libs/RevoEX/src/nhttp/d_nhttp_private.c @@ -0,0 +1,151 @@ +#include + +void* NHTTPi_GetSystemInfoP(void); +NHTTPBgnEndInfo* NHTTPi_GetBgnEndInfoP(void*); +void* NHTTPi_GetMutexInfoP(void*); +void* NHTTPi_GetThreadInfoP(void*); +void* NHTTPi_alloc(u32, int); +void NHTTPi_free(void*); +void* NHTTPi_memclr(void*, u32); +void NHTTPi_SetError(NHTTPBgnEndInfo*, NHTTPErr); +NHTTPRequestInfo* NHTTP_CreateRequest(NHTTPBgnEndInfo*, const char*, s32, void*, u32, void*, NHTTPResponseCallback, NHTTPResponseCleanup); +NHTTPConnectionInfo* NHTTPi_GetConnection(void*, NHTTPConnectionInfo*); +NHTTPRequestInfo* NHTTPi_GetRequest(void*, NHTTPRequestInfo*); +NHTTPResponseInfo* NHTTPi_Connection2Response(void*, NHTTPConnectionInfo*); +void NHTTPi_CommitConnectionList(void*, NHTTPConnectionInfo*); +s32 NHTTPi_OmitConnectionList(void*, NHTTPConnectionInfo*); +void NHTTPi_SetVirtualContentLength(NHTTPConnectionInfo*, u32); +void NHTTPi_CheckCurrentThread(void*, BOOL); +BOOL NHTTP_CancelRequestAsync(void*, s32); +void NHTTP_DestroyRequest(void*, NHTTPRequestInfo*); +void NHTTP_DestroyResponse(void*, NHTTPResponseInfo*); +s32 NHTTP_SendRequestAsync(void*, NHTTPRequestInfo*); +void NHTTPi_WaitForCompletion(NHTTPConnectionInfo*); + +NHTTPConnectionInfo* NHTTPCreateConnection(const char* url, s32 method, void* buffer, u32 size, NHTTPConnectionCallback callback, void* userParam) { + + NHTTPConnectionInfo* connection; + void* mutex; + NHTTPBgnEndInfo* info; + void* system; + system=NHTTPi_GetSystemInfoP(); + info=NHTTPi_GetBgnEndInfoP(system); + mutex=NHTTPi_GetMutexInfoP(system); + connection=NHTTPi_alloc(sizeof(*connection),32); + if(!connection) { NHTTPi_SetError(info,NHTTP_ERROR_ALLOC); return NULL; } + NHTTPi_memclr(connection,sizeof(*connection)); + connection->request=NHTTP_CreateRequest(info,url,method,buffer,size,userParam,NULL,NULL); + if(!connection->request) { NHTTPi_free(connection); return NULL; } + connection->response=connection->request->response; + connection->started=FALSE; + connection->callback=callback; + connection->_unk24=0; connection->_unk28=0; + connection->requestId=-1; + NHTTPi_CommitConnectionList(mutex,connection); + connection->state=15; + connection->sslError=0; + connection->_unkC=1; + NHTTPi_SetVirtualContentLength(connection,0); + connection->requestCallback=NULL; + connection->recvBufOffset=0; connection->recvBufDataLen=0; + NHTTPi_memclr(connection->recvBuf,sizeof(connection->recvBuf)); + return connection; +} + +static s32 ConnectionStarted(NHTTPConnectionInfo* handle) { + void* system=NHTTPi_GetSystemInfoP(); + void* mutex=NHTTPi_GetMutexInfoP(system); + NHTTPConnectionInfo* connection=NHTTPi_GetConnection(mutex,handle); + return connection ? connection->started : -1; +} + +static s32 ConnectionState(NHTTPConnectionInfo* handle) { + void* system=NHTTPi_GetSystemInfoP(); + void* mutex=NHTTPi_GetMutexInfoP(system); + NHTTPConnectionInfo* connection=NHTTPi_GetConnection(mutex,handle); + return connection ? connection->state : -1; +} + +static void WaitConnection(NHTTPConnectionInfo* handle) { + void* system=NHTTPi_GetSystemInfoP(); + void* thread=NHTTPi_GetThreadInfoP(system); + void* mutex=NHTTPi_GetMutexInfoP(system); + NHTTPConnectionInfo* connection=NHTTPi_GetConnection(mutex,handle); + if(connection) { + s32 started=ConnectionStarted(handle); + NHTTPi_CheckCurrentThread(thread,TRUE); + if(started!=-1 && started!=0 && ConnectionState(handle)==15) NHTTPi_WaitForCompletion(connection); + } +} + +s32 NHTTPDeleteConnection(NHTTPConnectionInfo* handle) { + void* system=NHTTPi_GetSystemInfoP(); + void* mutex=NHTTPi_GetMutexInfoP(system); + void* thread=NHTTPi_GetThreadInfoP(system); + NHTTPConnectionInfo* connection=NHTTPi_GetConnection(mutex,handle); + if(!connection) return -1; + NHTTPi_CheckCurrentThread(thread,TRUE); + if(connection->requestId>=0) { + NHTTP_CancelRequestAsync(system,connection->requestId); + connection->requestId=-1; + } + if(connection->request && connection->request->state==0) NHTTP_DestroyRequest(system,connection->request); + if(connection->response) { + if(!connection->request) NHTTP_DestroyResponse(mutex,connection->response); + else { WaitConnection(connection); NHTTP_DestroyResponse(mutex,connection->response); } + } + NHTTPi_OmitConnectionList(mutex,connection); + NHTTPi_free(connection); + return 0; +} + +s32 NHTTPStartConnection(NHTTPConnectionInfo* handle) { + void* system=NHTTPi_GetSystemInfoP(); + void* mutex=NHTTPi_GetMutexInfoP(system); + NHTTPConnectionInfo* connection=NHTTPi_GetConnection(mutex,handle); + if(!connection) return -1; + if(!connection->request) return -1; + connection->requestId=NHTTP_SendRequestAsync(system,connection->request); + if(connection->requestId>=0) connection->started=TRUE; + return 0; +} + +s32 NHTTPGetBodyBuffer(NHTTPConnectionInfo* handle, void** buffer, u32* size) { + void* system=NHTTPi_GetSystemInfoP(); + void* mutex=NHTTPi_GetMutexInfoP(system); + NHTTPConnectionInfo* connection=NHTTPi_GetConnection(mutex,handle); + if(connection) { + NHTTPResponseInfo* response=NHTTPi_Connection2Response(mutex,connection); + if(response) { *buffer=response->recvBuf_p; *size=response->recvBufLen; return response->bodyLen; } + return -1; + } + return -1; +} + +void* NHTTPGetUserParam(NHTTPConnectionInfo* handle) { + void* system=NHTTPi_GetSystemInfoP(); + void* mutex=NHTTPi_GetMutexInfoP(system); + NHTTPConnectionInfo* connection=NHTTPi_GetConnection(mutex,handle); + if(connection) { + NHTTPResponseInfo* response=NHTTPi_Connection2Response(mutex,connection); + if(response) return response->param_p; + return NULL; + } + return NULL; +} + +s32 NHTTPGetConnectionError(NHTTPConnectionInfo* handle) { + void* system=NHTTPi_GetSystemInfoP(); + void* mutex=NHTTPi_GetMutexInfoP(system); + NHTTPConnectionInfo* connection=NHTTPi_GetConnection(mutex,handle); + return connection ? connection->state : -1; +} + +s32 NHTTPSetSocketBufferSize(NHTTPRequestInfo* handle, u32 size) { + void* system=NHTTPi_GetSystemInfoP(); + void* mutex=NHTTPi_GetMutexInfoP(system); + NHTTPRequestInfo* request=NHTTPi_GetRequest(mutex,handle); + if(!request) return -1; + request->recvBufferSize=size; + return 0; +} diff --git a/libs/RevoEX/src/so/SOBasic.c b/libs/RevoEX/src/so/SOBasic.c new file mode 100644 index 00000000..73ca0106 --- /dev/null +++ b/libs/RevoEX/src/so/SOBasic.c @@ -0,0 +1,388 @@ +#include +#include +#include +#include +#include +#include + +int SOiPrepare(const char*, s32*); +int SOiConclude(const char*, int); +int SOiPrepareTempRm(const char*, s32*, int*); +int SOiConcludeTempRm(const char*, int, int); +int SOiIsBufferAddrCheck(void); +void* SOiAlloc(u32, s32); +void SOiFree(u32, void*, s32); + +static int soSocketRegistered; +const char* __SOCKETVersion="<< RVL_SDK - SOCKET \trelease build: Dec 12 2008 03:06:17 (0x4199_60831) >>"; + +typedef struct SocketRequest { int socket; int type; int protocol; } SocketRequest; +typedef struct AddressRequest { int socket; int hasAddress; SOSockAddr address; } AddressRequest; +typedef struct NameRequest { + union { int socket; u8 socketBlock[32]; }; + SOSockAddr address; +} NameRequest; +typedef struct PollRequest { + union { s64 timeout; u8 timeoutBlock[32]; }; + SOPollFD fds[1]; +} PollRequest; +typedef struct InetRequest { + union { struct { int family; u8 address[16]; } reply; u8 replyBlock[32]; }; + char text[1]; +} InetRequest; +typedef struct RecvRequest { + IOSIoVector vectors[4]; + union { struct { int socket; int flags; } command; u8 commandBlock[32]; }; + SOSockAddr address; +} RecvRequest; +typedef struct SendRequest { + IOSIoVector vectors[4]; + struct { int socket; int flags; int hasAddress; SOSockAddr address; } command; +} SendRequest; + +static int RecvFrom(const char*, int, void*, int, int, SOSockAddr*); +static int SendTo(const char*, int, const void*, int, int, const SOSockAddr*); + +int SOSocket(int family, int type, int protocol) { + s32 rm; + SocketRequest* request; + int result; + if(!soSocketRegistered) { OSRegisterVersion(__SOCKETVersion); soSocketRegistered=1; } + if((result=SOiPrepare(NULL,&rm))==0) { + if(family==23) result=-5; + else { + request=SOiAlloc(12,32); + if(!request) result=-49; + else { + request->socket=family; request->type=type; request->protocol=protocol; + result=IOS_Ioctl(rm,15,request,12,NULL,0); + SOiFree(12,request,32); + } + } + result=SOiConclude(NULL,result); + } + return result; +} + +int SOClose(int socket) { + s32 rm; + int result; + SocketRequest* request; + if((result=SOiPrepare(NULL,&rm))==0) { + request=SOiAlloc(12,32); + if(!request) result=-49; + else { + request->socket=socket; + result=IOS_Ioctl(rm,3,request,4,NULL,0); + SOiFree(12,request,32); + } + result=SOiConclude(NULL,result); + } + return result; +} + +int SOBind(int socket, void* address) { + SOSockAddr* addr=address; + s32 rm; + int result; + AddressRequest* request; + if((result=SOiPrepare(NULL,&rm))==0) { + if(!addr || addr->len>8 || addr->len<8) result=-28; + else { + request=SOiAlloc(12,64); + if(!request) result=-49; + else { + request->socket=socket; request->hasAddress=1; + memcpy(&request->address,addr,addr->len); + result=IOS_Ioctl(rm,2,request,36,NULL,0); + SOiFree(12,request,64); + } + } + result=SOiConclude(NULL,result); + } + return result; +} + +int SOConnect(int socket, void* address) { + SOSockAddr* addr=address; + s32 rm; + int result; + AddressRequest* request; + if((result=SOiPrepare(NULL,&rm))==0) { + if(!addr || addr->len>8 || addr->len<8) result=-28; + else { + request=SOiAlloc(12,64); + if(!request) result=-49; + else { + request->socket=socket; request->hasAddress=1; + memcpy(&request->address,addr,addr->len); + result=IOS_Ioctl(rm,4,request,36,NULL,0); + SOiFree(12,request,64); + } + } + result=SOiConclude(NULL,result); + } + return result; +} + +int SOGetSockName(int socket, void* address) { + + SOSockAddr* reply; + NameRequest* request; + int size; + int result; + s32 rm; + SOSockAddr* addr; + addr=address; + if((result=SOiPrepare(NULL,&rm))==0) { + if(!addr || addr->len>8 || addr->len<8) result=-28; + else { + size=(addr->len+63)&~31; + request=SOiAlloc(12,size); + if(!request) result=-49; + else { + request->socket=socket; + reply=&request->address; + memcpy(reply,addr,addr->len); + result=IOS_Ioctl(rm,7,request,4,reply,addr->len); + if(result>=0) memcpy(addr,reply,reply->len); + SOiFree(12,request,size); + } + } + result=SOiConclude(NULL,result); + } + return result; +} + +int SORecvFrom(int socket, void* data, int length, int flags, void* address) { return RecvFrom(NULL,socket,data,length,flags,address); } +int SORecv(int socket, void* data, int length, int flags) { return RecvFrom(NULL,socket,data,length,flags,NULL); } +int SORead(int socket, void* data, int length) { return RecvFrom(NULL,socket,data,length,0,NULL); } +int SOSendTo(int socket, const void* data, int length, int flags, const void* address) { return SendTo(NULL,socket,data,length,flags,address); } +int SOSend(int socket, const void* data, int length, int flags) { return SendTo(NULL,socket,data,length,flags,NULL); } + +int SOFcntl(int socket, int command, ...) { + va_list args; + s32 rm; + int result,value; + SocketRequest* request; + va_start(args,command); + value=va_arg(args,int); + va_end(args); + if((result=SOiPrepare(NULL,&rm))==0) { + request=SOiAlloc(12,32); + if(!request) result=-49; + else { + request->socket=socket; request->type=command; request->protocol=value; + result=IOS_Ioctl(rm,5,request,12,NULL,0); + SOiFree(12,request,32); + } + result=SOiConclude(NULL,result); + } + return result; +} + +int SOShutdown(int socket, int how) { + s32 rm; + int result; + SocketRequest* request; + if((result=SOiPrepare(NULL,&rm))==0) { + request=SOiAlloc(12,32); + if(!request) result=-49; + else { + request->socket=socket; request->type=how; + result=IOS_Ioctl(rm,14,request,8,NULL,0); + SOiFree(12,request,32); + } + result=SOiConclude(NULL,result); + } + return result; +} + +int SOPoll(SOPollFD* fds, unsigned int count, s64 timeout) { + s32 rm; + s32 result,bytes,size; + PollRequest* request; + SOPollFD* reply; + if((result=SOiPrepare(NULL,&rm))==0) { + if(!fds) result=-28; + else { + bytes=count*12; size=(bytes+63)&~31; + request=SOiAlloc(12,size); + if(!request) result=-49; + else { + reply=request->fds; + if(timeout<=-1) memcpy(&request->timeout,&timeout,8); + else request->timeout=timeout/((__OSBusClock/4)/1000); + memcpy(reply,fds,bytes); + result=IOS_Ioctl(rm,11,request,8,reply,bytes); + if(result>=0) memcpy(fds,reply,bytes); + SOiFree(12,request,size); + } + } + result=SOiConclude(NULL,result); + } + return result; +} + +int SOInetAtoN(const char* text, SOInAddr* address) { + s32 rm; + int temporary,size,result; + InetRequest* request; + char* input; + if((result=SOiPrepareTempRm(NULL,&rm,&temporary))==0) { + if(!text) result=-28; + else { + size=(strlen(text)+64)&~31; + request=SOiAlloc(12,size); + if(!request) result=-49; + else { + input=request->text; + if(text) strcpy(input,text); + result=IOS_Ioctl(rm,21,input,strlen(text),request,4); + if(result>=0 && address) memcpy(address,request,4); + SOiFree(12,request,size); + } + } + result=SOiConcludeTempRm(NULL,result,temporary); + } + return result; +} + +char* SOInetNtoA(SOInAddr address) { + static char ascii[40]; + const u8* bytes=(const u8*)&address; + sprintf(ascii,"%d.%d.%d.%d",bytes[0],bytes[1],bytes[2],bytes[3]); + return ascii; +} + +int SOInetPtoN(int family, const char* text, void* address) { + s32 rm; + int temporary,result,size,bytes; + InetRequest* request; + if((result=SOiPrepareTempRm(NULL,&rm,&temporary))==0) { + bytes=0; + if(family==2) bytes=4; + if(!bytes) result=-5; + else if(!text) result=-28; + else { + size=(strlen(text)+64)&~31; + request=SOiAlloc(12,size); + if(!request) result=-49; + else { + strcpy(request->text,text); + request->reply.family=family; + memset(request->reply.address,0,bytes); + result=IOS_Ioctl(rm,22,(void*)text,strlen(text)+1,request,20); + if(result>=0 && address) memcpy(address,request->reply.address,bytes); + SOiFree(12,request,size); + } + } + result=SOiConcludeTempRm(NULL,result,temporary); + } + return result; +} + +u32 SONtoHl(u32 value) { return value; } +u16 SONtoHs(u16 value) { return value; } +u32 SOHtoNl(u32 value) { return value; } +u16 SOHtoNs(u16 value) { return value; } + +static inline int DirectBuffer(const void* data, int length) { + BOOL direct=FALSE; + BOOL aligned=FALSE; + if(((u32)data&31)==0 && length%32==0) aligned=TRUE; + if(aligned) { + BOOL accessible=TRUE; + if(SOiIsBufferAddrCheck()) { + BOOL inMemory=FALSE; + if(((u32)data&0x1fffffff)>=0x10000000 && ((u32)data&0x1fffffff)<0x18000000) inMemory=TRUE; + if(!inMemory) accessible=FALSE; + } + if(accessible) direct=TRUE; + } + return direct; +} + +static int RecvFrom(const char* name, int socket, void* data, int length, int flags, SOSockAddr* address) { + s32 rm; + int result,size; + BOOL direct; + RecvRequest* request; + void* buffer; + SOSockAddr* reply; + if(length>32768) length=32768; + if((result=SOiPrepare(name,&rm))==0) { + if(address && (address->len>8 || address->len<8)) result=-28; + else if(length<0 || (length>0 && !data)) result=-28; + else { + direct=TRUE; + if(length && !DirectBuffer(data,length)) direct=FALSE; + size=((address ? address->len : 0)+95)&~31; + request=SOiAlloc(12,size); + if(!direct) buffer=SOiAlloc(13,(length+31)&~31); + else buffer=data; + if(!request || !buffer) result=-49; + else { + request->command.socket=socket; request->command.flags=flags; + reply=&request->address; + request->vectors[0].base=(u8*)&request->command; request->vectors[0].length=8; + request->vectors[1].base=buffer; request->vectors[1].length=length; + if(!address) { + request->vectors[2].base=NULL; request->vectors[2].length=0; + result=IOS_Ioctlv(rm,12,1,2,request->vectors); + } else { + memcpy(reply,address,address->len); + request->vectors[2].base=(u8*)reply; request->vectors[2].length=address->len; + result=IOS_Ioctlv(rm,12,1,2,request->vectors); + if(result>=0) { + u32 bytes=address->len; + if(bytes>reply->len) bytes=reply->len; + memcpy(address,reply,bytes); + } + } + if(result>=0 && !direct) memcpy(data,buffer,length); + } + if(!direct) SOiFree(13,buffer,(length+31)&~31); + SOiFree(12,request,size); + } + result=SOiConclude(name,result); + } + return result; +} + +static int SendTo(const char* name, int socket, const void* data, int length, int flags, const SOSockAddr* address) { + + void* buffer; + SendRequest* request; + BOOL direct; + int result; + s32 rm; + if((result=SOiPrepare(name,&rm))==0) { + if(address && (address->len>8 || address->len<8)) result=-28; + else if(length<0 || (length>0 && !data)) result=-28; + else { + direct=TRUE; + if(length && !DirectBuffer(data,length)) direct=FALSE; + request=SOiAlloc(12,96); + if(!direct) buffer=SOiAlloc(14,(length+31)&~31); + else buffer=(void*)data; + if(!request || !buffer) result=-49; + else { + request->command.socket=socket; request->command.flags=flags; + if(!address) request->command.hasAddress=0; + else { + request->command.hasAddress=1; + memcpy(&request->command.address,address,address->len); + } + if(!direct) memcpy(buffer,data,length); + request->vectors[0].base=buffer; request->vectors[0].length=length; + request->vectors[1].base=(u8*)&request->command; request->vectors[1].length=40; + result=IOS_Ioctlv(rm,13,2,0,request->vectors); + } + if(!direct) SOiFree(14,buffer,(length+31)&~31); + SOiFree(12,request,96); + } + result=SOiConclude(name,result); + } + return result; +} diff --git a/libs/RevoEX/src/so/SOInformation.c b/libs/RevoEX/src/so/SOInformation.c new file mode 100644 index 00000000..8b92ab4c --- /dev/null +++ b/libs/RevoEX/src/so/SOInformation.c @@ -0,0 +1,144 @@ +#include +#include +#include +#include + +int SOiPrepare(const char*, s32*); +int SOiConclude(const char*, int); +int SOiIsInitialized(void); +void* SOiAlloc(u32, s32); +void SOiFree(u32, void*, s32); + +typedef struct HostReply { + SOHostEnt host; + char nameStorage[816]; + u8* addresses[72]; +} HostReply; + +typedef struct SOSysWork { + SOAlloc alloc; + SOFree free; + int rmState; + int rm; + HostReply* host; + int allocations; +} SOSysWork; + +SOSysWork* SOiGetSysWork(void); + +typedef struct AddrInfoRequest { + IOSIoVector vectors[4]; + u8 storage[1]; +} AddrInfoRequest; + +typedef struct AddrInfoReply { + SOAddrInfo entries[35]; + u8 addresses[980]; +} AddrInfoReply; + +s32 SOGetHostID(void) { + s32 rm; + int result; + s32 address=0; + if((result=SOiPrepare(NULL,&rm))==0) { + address=IOS_Ioctl(rm,16,NULL,0,NULL,0); + SOiConclude(NULL,result); + } + return address; +} + +SOHostEnt* SOGetHostByName(const char* name) { + s32 rm; + char* request; + HostReply* reply; + int result,size,length; + SOHostEnt* host=NULL; + if((result=SOiPrepare(NULL,&rm))==0) { + if(!name) result=-28; + else { + length=strlen(name); + size=(length+32)&~31; + request=SOiAlloc(12,size); + reply=SOiGetSysWork()->host; + if(!request) result=-49; + else { + strcpy(request,name); + result=IOS_Ioctl(rm,17,request,length+1,reply,0x460); + if(result>=0) { + int displacement=(int)reply->nameStorage-(int)reply->host.name; + u8** address=reply->addresses; + while(*address) { *address+=displacement; ++address; } + reply->host.aliases=(char**)((u8*)reply->host.aliases+displacement); + host=&reply->host; + reply->host.name+=displacement; + reply->host.addrList=(u8**)((u8*)reply->host.addrList+displacement); + } + SOiFree(12,request,size); + } + } + SOiConclude(NULL,result); + } + return host; +} + +static int NameSize(const char* name) { return name ? strlen(name)+1 : 0; } + +int SOGetAddrInfo(const char* nodeName, const char* servName, const SOAddrInfo* hints, SOAddrInfo** resultInfo) { + s32 rm; + int result,size; + AddrInfoRequest* request; + AddrInfoReply* reply; + char* node; + char* service; + SOAddrInfo* requestHints; + if((result=SOiPrepare(NULL,&rm))==0) { + size=(((NameSize(nodeName)+31)&~31)+((servName ? strlen(nodeName)+32 : 31)&~31)+95)&~31; + request=SOiAlloc(12,size); + if(!request) result=-49; + else { + reply=SOiAlloc(10,0x840); + if(!reply) { SOiFree(12,request,size); result=-49; } + else { + node=(char*)request->storage; + service=node+((NameSize(nodeName)+31)&~31); + requestHints=(SOAddrInfo*)(service+((servName ? strlen(nodeName)+32 : 31)&~31)); + if(nodeName) strcpy(node,nodeName); + request->vectors[0].base=nodeName ? (u8*)node : NULL; + request->vectors[0].length=nodeName ? strlen(nodeName) : 0; + if(servName) strcpy(service,servName); + request->vectors[1].base=servName ? (u8*)service : NULL; + request->vectors[1].length=servName ? strlen(servName) : 0; + if(hints) memcpy(requestHints,hints,32); + else memset(requestHints,0,32); + if(requestHints->family==0) requestHints->family=2; + if(requestHints->family==23) { + *resultInfo=NULL; result=-68; SOiFree(10,reply,0x840); + } else { + request->vectors[2].base=(u8*)requestHints; request->vectors[2].length=32; + request->vectors[3].base=(u8*)reply; request->vectors[3].length=0x834; + result=IOS_Ioctlv(rm,24,3,1,request->vectors); + if(result>=0) { + SOAddrInfo* entry=reply->entries; + u8* address=reply->addresses; + *resultInfo=entry; + while(entry) { + entry->addr=address; + if(entry->next) entry->next=entry+1; + entry=entry->next; + address+=28; + } + } else { *resultInfo=NULL; SOiFree(10,reply,0x840); } + } + SOiFree(12,request,size); + } + } + result=SOiConclude(NULL,result); + } + return result; +} + +void SOFreeAddrInfo(SOAddrInfo* head) { + BOOL enabled=OSDisableInterrupts(); + if(SOiIsInitialized()==1 && head) SOiFree(10,head,0x840); + OSRestoreInterrupts(enabled); +} diff --git a/libs/RevoEX/src/so/SOOption.c b/libs/RevoEX/src/so/SOOption.c new file mode 100644 index 00000000..3ed35bc5 --- /dev/null +++ b/libs/RevoEX/src/so/SOOption.c @@ -0,0 +1,167 @@ +#include +#include +#include + +int SOiPrepare(const char*, s32*); +int SOiConclude(const char*, int); +int SOiPrepareTempRm(const char*, s32*, int*); +int SOiConcludeTempRm(const char*, int, int); +void* SOiAlloc(u32, s32); +void SOiFree(u32, void*, s32); + +typedef struct SocketOption { + int socket; + int level; + int option; + int length; + u8 value[20]; +} SocketOption; + +typedef struct InterfaceCommand { int level; int option; } InterfaceCommand; + +typedef struct InterfaceOption { + IOSIoVector vectors[4]; + union { + InterfaceCommand command; + u8 commandBlock[32]; + }; + union { + int length; + u8 lengthBlock[32]; + }; + u8 value[1]; +} InterfaceOption; + +typedef struct InterfaceSetting { + IOSIoVector vectors[4]; + union { + InterfaceCommand command; + u8 commandBlock[32]; + }; + u8 value[1]; +} InterfaceSetting; + +int SOGetSockOpt(int socket, int level, int option, void* value, int* length) { + s32 rm; + int result; + SocketOption* request; + if ((result=SOiPrepare(NULL,&rm))==0) { + request=SOiAlloc(12,32); + if (!request) result=-49; + else { + request->socket=socket; request->level=level; request->option=option; + result=IOS_Ioctl(rm,8,NULL,0,request,24); + if(result>=0 && length) { + if(*length>=request->length) { + if(value) memcpy(value,request->value,request->length); + *length=request->length; + } else { *length=request->length; result=-28; } + } + SOiFree(12,request,32); + } + result=SOiConclude(NULL,result); + } + return result; +} + +int SOSetSockOpt(int socket, int level, int option, const void* value, int length) { + s32 rm; + int result; + SocketOption* request; + if ((result=SOiPrepare(NULL,&rm))==0) { + if(length<0 || length>20) result=-28; + else { + request=SOiAlloc(12,64); + if(!request) result=-49; + else { + request->socket=socket; request->level=level; request->option=option; request->length=length; + if(value) memcpy(request->value,value,length); + else memset(request->value,0,length); + result=IOS_Ioctl(rm,9,request,36,NULL,0); + SOiFree(12,request,64); + } + } + result=SOiConclude(NULL,result); + } + return result; +} + +static int OptionLength(int* length) { + int invalid=0; + if(length==NULL || *length<0) invalid=1; + if(invalid) return 0; + return *length; +} + +int SOGetInterfaceOpt(void* interface, int level, int option, void* value, int* length) { + s32 rm; + int temporary; + InterfaceOption* request; + int result; + int size; + InterfaceCommand* command; + int* returnedLength; + u8* reply; + if ((result=SOiPrepareTempRm(NULL,&rm,&temporary))==0) { + if(option==0x1001 || option==0x1002) result=-28; + else { + size=(OptionLength(length)+127)&~31; + request=SOiAlloc(12,size); + if(!request) result=-49; + else { + command=&request->command; + command->level=level; command->option=option; + returnedLength=&request->length; + reply=request->value; + *returnedLength=OptionLength(length); + request->vectors[0].base=(u8*)command; + request->vectors[0].length=8; + request->vectors[1].base=reply; + request->vectors[1].length=OptionLength(length); + request->vectors[2].base=(u8*)returnedLength; + request->vectors[2].length=4; + result=IOS_Ioctlv(rm,28,1,2,request->vectors); + if(result>=0 && length) { + if(*length>=*returnedLength) { + if(value) memcpy(value,reply,*returnedLength); + *length=*returnedLength; + } else { *length=*returnedLength; result=-28; } + } + SOiFree(12,request,size); + } + } + result=SOiConcludeTempRm(NULL,result,temporary); + } + return result; +} + +int SOSetInterfaceOpt(void* interface, int level, int option, const void* value, int length) { + s32 rm; + int temporary; + InterfaceSetting* request; + int result; + int size; + InterfaceCommand* command; + u8* reply; + if ((result=SOiPrepareTempRm(NULL,&rm,&temporary))==0) { + if(option==0x1001 || option==0x1002 || length<0) result=-28; + else { + size=(length+95)&~31; + request=SOiAlloc(12,size); + if(!request) result=-49; + else { + command=&request->command; + command->level=level; command->option=option; + reply=request->value; + if(value) memcpy(reply,value,length); + else memset(reply,0,length); + request->vectors[0].base=(u8*)command; request->vectors[0].length=8; + request->vectors[1].base=reply; request->vectors[1].length=length; + result=IOS_Ioctlv(rm,29,2,0,request->vectors); + SOiFree(12,request,size); + } + } + result=SOiConcludeTempRm(NULL,result,temporary); + } + return result; +} diff --git a/tools/decomp-assist/revoex-batch.attempts.md b/tools/decomp-assist/revoex-batch.attempts.md new file mode 100644 index 00000000..a894a2e4 --- /dev/null +++ b/tools/decomp-assist/revoex-batch.attempts.md @@ -0,0 +1,106 @@ +# RevoEX socket and HTTP attempts + +so/SOBasic/SOGetSockName: literal implementation and focused variants: instructions 63/63, aligned differences 17 +so/SOBasic/SOGetSockName: separate local declarations and initialization: instructions 63/63, aligned differences 17 +so/SOBasic/SOGetSockName: reverse local declarations, preserve initialization order: instructions 63/63, aligned differences 20 +so/SOBasic/SOGetSockName: retained candidate: instructions 63/63, aligned differences 17 +so/SOBasic/SOPoll: literal implementation and focused variants: instructions 87/87, aligned differences 7 +so/SOBasic/SOPoll: separate local declarations and initialization: instructions 87/87, aligned differences 7 +so/SOBasic/SOPoll: reverse local declarations, preserve initialization order: instructions 87/87, aligned differences 21 +so/SOBasic/SOPoll: retained candidate: instructions 87/87, aligned differences 7 +so/SOBasic/SOInetPtoN: literal implementation and focused variants: instructions 79/80, aligned differences 66 +so/SOBasic/SOInetPtoN: separate local declarations and initialization: compiler rejected types +so/SOBasic/SOInetPtoN: reverse local declarations, preserve initialization order: instructions 79/80, aligned differences 69 +so/SOBasic/SOInetPtoN: retained candidate: instructions 79/80, aligned differences 66 +so/SOBasic/RecvFrom: literal implementation and focused variants: instructions 174/174, aligned differences 70 +so/SOBasic/RecvFrom: separate local declarations and initialization: instructions 174/174, aligned differences 70 +so/SOBasic/RecvFrom: reverse local declarations, preserve initialization order: instructions 174/174, aligned differences 85 +so/SOBasic/RecvFrom: retained candidate: instructions 174/174, aligned differences 70 +so/SOBasic/SendTo: literal implementation and focused variants: instructions 139/139, aligned differences 66 +so/SOBasic/SendTo: separate local declarations and initialization: instructions 139/139, aligned differences 66 +so/SOBasic/SendTo: reverse local declarations, preserve initialization order: instructions 139/139, aligned differences 68 +so/SOBasic/SendTo: retained candidate: instructions 139/139, aligned differences 66 +so/SOOption/SOGetInterfaceOpt: literal implementation and focused variants: instructions 119/119, aligned differences 16 +so/SOOption/SOGetInterfaceOpt: separate local declarations and initialization: compiler rejected types +so/SOOption/SOGetInterfaceOpt: reverse local declarations, preserve initialization order: instructions 119/119, aligned differences 45 +so/SOOption/SOGetInterfaceOpt: retained candidate: instructions 119/119, aligned differences 16 +so/SOOption/SOSetInterfaceOpt: literal implementation and focused variants: instructions 74/74, aligned differences 14 +so/SOOption/SOSetInterfaceOpt: separate local declarations and initialization: compiler rejected types +so/SOOption/SOSetInterfaceOpt: reverse local declarations, preserve initialization order: instructions 74/74, aligned differences 22 +so/SOOption/SOSetInterfaceOpt: retained candidate: instructions 74/74, aligned differences 14 +so/SOInformation/SOGetHostByName: literal implementation and focused variants: instructions 80/80, aligned differences 23 +so/SOInformation/SOGetHostByName: separate local declarations and initialization: instructions 80/80, aligned differences 23 +so/SOInformation/SOGetHostByName: reverse local declarations, preserve initialization order: instructions 80/80, aligned differences 28 +so/SOInformation/SOGetHostByName: retained candidate: instructions 80/80, aligned differences 23 +so/SOInformation/SOGetAddrInfo: literal implementation and focused variants: instructions 183/185, aligned differences 166 +so/SOInformation/SOGetAddrInfo: separate local declarations and initialization: instructions 183/185, aligned differences 166 +so/SOInformation/SOGetAddrInfo: reverse local declarations, preserve initialization order: instructions 183/185, aligned differences 166 +so/SOInformation/SOGetAddrInfo: retained candidate: instructions 183/185, aligned differences 166 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strnicmp: literal implementation and focused variants: instructions 51/51, aligned differences 2 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strnicmp: separate local declarations and initialization: instructions 51/51, aligned differences 2 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strnicmp: reverse local declarations, preserve initialization order: instructions 51/51, aligned differences 2 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strnicmp: retained candidate: instructions 51/51, aligned differences 2 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strToHex: literal implementation and focused variants: instructions 72/73, aligned differences 71 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strToHex: separate local declarations and initialization: instructions 72/73, aligned differences 71 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strToHex: reverse local declarations, preserve initialization order: instructions 72/73, aligned differences 71 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strToHex: retained candidate: instructions 72/73, aligned differences 71 +nhttp/NHTTP_stdlib_RVL/NHTTPi_intToStr: literal implementation and focused variants: instructions 95/95, aligned differences 61 +nhttp/NHTTP_stdlib_RVL/NHTTPi_intToStr: separate local declarations and initialization: instructions 95/95, aligned differences 61 +nhttp/NHTTP_stdlib_RVL/NHTTPi_intToStr: reverse local declarations, preserve initialization order: instructions 95/95, aligned differences 65 +nhttp/NHTTP_stdlib_RVL/NHTTPi_intToStr: retained candidate: instructions 95/95, aligned differences 61 +nhttp/NHTTP_stdlib_RVL/NHTTPi_compareToken: literal implementation and focused variants: instructions 44/45, aligned differences 42 +nhttp/NHTTP_stdlib_RVL/NHTTPi_compareToken: separate local declarations and initialization: instructions 44/45, aligned differences 42 +nhttp/NHTTP_stdlib_RVL/NHTTPi_compareToken: reverse local declarations, preserve initialization order: instructions 44/45, aligned differences 42 +nhttp/NHTTP_stdlib_RVL/NHTTPi_compareToken: retained candidate: instructions 44/45, aligned differences 42 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strtonum: literal implementation and focused variants: instructions 36/36, aligned differences 23 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strtonum: separate local declarations and initialization: instructions 36/36, aligned differences 23 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strtonum: reverse local declarations, preserve initialization order: instructions 36/36, aligned differences 25 +nhttp/NHTTP_stdlib_RVL/NHTTPi_strtonum: retained candidate: instructions 36/36, aligned differences 23 +nhttp/NHTTP_stdlib_RVL/NHTTPi_Base64Encode: literal implementation and focused variants: instructions 119/119, aligned differences 58 +nhttp/NHTTP_stdlib_RVL/NHTTPi_Base64Encode: separate local declarations and initialization: instructions 119/119, aligned differences 58 +nhttp/NHTTP_stdlib_RVL/NHTTPi_Base64Encode: reverse local declarations, preserve initialization order: instructions 119/119, aligned differences 73 +nhttp/NHTTP_stdlib_RVL/NHTTPi_Base64Encode: retained candidate: instructions 119/119, aligned differences 58 +nhttp/NHTTP_socket_RVL/NHTTPi_SocRecv_sub: literal implementation and focused variants: instructions 67/67, aligned differences 4 +nhttp/NHTTP_socket_RVL/NHTTPi_SocRecv_sub: separate local declarations and initialization: instructions 67/67, aligned differences 4 +nhttp/NHTTP_socket_RVL/NHTTPi_SocRecv_sub: reverse local declarations, preserve initialization order: instructions 67/67, aligned differences 11 +nhttp/NHTTP_socket_RVL/NHTTPi_SocRecv_sub: retained candidate: instructions 67/67, aligned differences 4 +nhttp/NHTTP_socket_RVL/NHTTPi_SocRecv_sub: literal implementation and focused variants: instructions 67/67, aligned differences 4 +nhttp/NHTTP_socket_RVL/NHTTPi_SocRecv_sub: separate local declarations and initialization: instructions 67/67, aligned differences 4 +nhttp/NHTTP_socket_RVL/NHTTPi_SocRecv_sub: reverse local declarations, preserve initialization order: instructions 67/67, aligned differences 11 +nhttp/NHTTP_socket_RVL/NHTTPi_SocRecv_sub: retained candidate: instructions 67/67, aligned differences 4 +nhttp/NHTTP_socket_RVL/NHTTPi_SocSend_sub: literal implementation and focused variants: instructions 101/102, aligned differences 67 +nhttp/NHTTP_socket_RVL/NHTTPi_SocSend_sub: separate local declarations and initialization: instructions 101/102, aligned differences 67 +nhttp/NHTTP_socket_RVL/NHTTPi_SocSend_sub: reverse local declarations, preserve initialization order: instructions 101/102, aligned differences 75 +nhttp/NHTTP_socket_RVL/NHTTPi_SocSend_sub: retained candidate: instructions 101/102, aligned differences 67 +nhttp/NHTTP_socket_RVL/NHTTPi_SocSend: literal implementation and focused variants: instructions 43/43, aligned differences 3 +nhttp/NHTTP_socket_RVL/NHTTPi_SocSend: separate local declarations and initialization: instructions 43/43, aligned differences 3 +nhttp/NHTTP_socket_RVL/NHTTPi_SocSend: reverse local declarations, preserve initialization order: instructions 43/43, aligned differences 3 +nhttp/NHTTP_socket_RVL/NHTTPi_SocSend: retained candidate: instructions 43/43, aligned differences 3 +nhttp/NHTTP_recvbuf/NHTTPi_findNextLineHdrRecvBuf: literal implementation and focused variants: instructions 125/126, aligned differences 106 +nhttp/NHTTP_recvbuf/NHTTPi_findNextLineHdrRecvBuf: separate local declarations and initialization: instructions 125/126, aligned differences 106 +nhttp/NHTTP_recvbuf/NHTTPi_findNextLineHdrRecvBuf: reverse local declarations, preserve initialization order: instructions 125/126, aligned differences 113 +nhttp/NHTTP_recvbuf/NHTTPi_findNextLineHdrRecvBuf: retained candidate: instructions 125/126, aligned differences 106 +nhttp/NHTTP_recvbuf/NHTTPi_skipSpaceHdrRecvBuf: literal implementation and focused variants: instructions 64/62, aligned differences 57 +nhttp/NHTTP_recvbuf/NHTTPi_skipSpaceHdrRecvBuf: separate local declarations and initialization: compiler rejected types +nhttp/NHTTP_recvbuf/NHTTPi_skipSpaceHdrRecvBuf: reverse local declarations, preserve initialization order: instructions 64/62, aligned differences 57 +nhttp/NHTTP_recvbuf/NHTTPi_skipSpaceHdrRecvBuf: retained candidate: instructions 64/62, aligned differences 57 +nhttp/NHTTP_recvbuf/NHTTPi_compareTokenN_HdrRecvBuf: literal implementation and focused variants: instructions 127/124, aligned differences 118 +nhttp/NHTTP_recvbuf/NHTTPi_compareTokenN_HdrRecvBuf: separate local declarations and initialization: compiler rejected types +nhttp/NHTTP_recvbuf/NHTTPi_compareTokenN_HdrRecvBuf: reverse local declarations, preserve initialization order: instructions 127/124, aligned differences 124 +nhttp/NHTTP_recvbuf/NHTTPi_compareTokenN_HdrRecvBuf: retained candidate: instructions 127/124, aligned differences 118 +nhttp/NHTTP_recvbuf/NHTTPi_loadFromHdrRecvBuf: literal implementation and focused variants: instructions 81/81, aligned differences 58 +nhttp/NHTTP_recvbuf/NHTTPi_loadFromHdrRecvBuf: separate local declarations and initialization: instructions 81/81, aligned differences 58 +nhttp/NHTTP_recvbuf/NHTTPi_loadFromHdrRecvBuf: reverse local declarations, preserve initialization order: instructions 81/81, aligned differences 57 +nhttp/NHTTP_recvbuf/NHTTPi_loadFromHdrRecvBuf: retained candidate: instructions 81/81, aligned differences 57 +nhttp/NHTTP_recvbuf/NHTTPi_RecvBufN: literal implementation and focused variants: instructions 14/15, aligned differences 11 +nhttp/NHTTP_recvbuf/NHTTPi_RecvBufN: separate local declarations and initialization: instructions 14/15, aligned differences 11 +nhttp/NHTTP_recvbuf/NHTTPi_RecvBufN: reverse local declarations, preserve initialization order: instructions 14/15, aligned differences 11 +nhttp/NHTTP_recvbuf/NHTTPi_RecvBufN: retained candidate: instructions 14/15, aligned differences 11 +nhttp/d_nhttp_private/NHTTPCreateConnection: literal implementation and focused variants: instructions 82/82, aligned differences 22 +nhttp/d_nhttp_private/NHTTPCreateConnection: separate local declarations and initialization: instructions 82/82, aligned differences 22 +nhttp/d_nhttp_private/NHTTPCreateConnection: reverse local declarations, preserve initialization order: instructions 82/82, aligned differences 2 +nhttp/d_nhttp_private/NHTTPCreateConnection: retained candidate: instructions 82/82, aligned differences 2 +nhttp/d_nhttp_private/NHTTPDeleteConnection: literal implementation and focused variants: instructions 103/103, aligned differences 11 +nhttp/d_nhttp_private/NHTTPDeleteConnection: separate local declarations and initialization: instructions 103/103, aligned differences 11 +nhttp/d_nhttp_private/NHTTPDeleteConnection: reverse local declarations, preserve initialization order: instructions 103/103, aligned differences 36 +nhttp/d_nhttp_private/NHTTPDeleteConnection: retained candidate: instructions 103/103, aligned differences 11 diff --git a/tools/decomp-assist/revoex-net.attempts.md b/tools/decomp-assist/revoex-net.attempts.md new file mode 100644 index 00000000..f80bb870 --- /dev/null +++ b/tools/decomp-assist/revoex-net.attempts.md @@ -0,0 +1,34 @@ +# RevoEX net attempts + +md5/NETMD5GetDigest: current expression and loop forms: src 0x128 base 0x128 insns 74/74; diffs 6: [38, 40, 41, 42, 44, 45] +md5/ProcessBlock: current expression and loop forms: src 0x498 base 0x4c8 insns 294/306; --- replace mine 2:4 base 2:4 +md5/NETMD5GetDigest: integer locals and alternate loop declarations: src 0x128 base 0x128 insns 74/74; diffs 6: [38, 40, 41, 42, 44, 45] +md5/ProcessBlock: integer locals and alternate loop declarations: src 0x498 base 0x4c8 insns 294/306; --- replace mine 2:4 base 2:4 +md5/NETMD5GetDigest: expression grouping and assignment order: src 0x128 base 0x128 insns 74/74; diffs 6: [38, 40, 41, 42, 44, 45] +md5/ProcessBlock: expression grouping and assignment order: src 0x498 base 0x4c8 insns 294/306; --- replace mine 2:4 base 2:4 +md5/NETMD5GetDigest: retained readable candidate: src 0x128 base 0x128 insns 74/74; diffs 6: [38, 40, 41, 42, 44, 45] +md5/ProcessBlock: retained readable candidate: src 0x498 base 0x4c8 insns 294/306; --- replace mine 2:4 base 2:4 +hmac/NETHMACInit: current expression and loop forms: src 0x23c base 0x23c insns 143/143; diffs 79: [8, 12, 14, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34] +hmac/NETHMACGetDigest: current expression and loop forms: src 0x198 base 0x1a4 insns 102/105; --- delete mine 4:5 base 4:4 +hmac/NETHMACInit: integer locals and alternate loop declarations: src 0x23c base 0x23c insns 143/143; diffs 79: [8, 12, 14, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34] +hmac/NETHMACGetDigest: integer locals and alternate loop declarations: src 0x198 base 0x1a4 insns 102/105; --- delete mine 4:5 base 4:4 +hmac/NETHMACInit: expression grouping and assignment order: src 0x23c base 0x23c insns 143/143; diffs 79: [8, 12, 14, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34] +hmac/NETHMACGetDigest: expression grouping and assignment order: src 0x198 base 0x1a4 insns 102/105; --- delete mine 4:5 base 4:4 +hmac/NETHMACInit: retained readable candidate: src 0x23c base 0x23c insns 143/143; diffs 79: [8, 12, 14, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34] +hmac/NETHMACGetDigest: retained readable candidate: src 0x198 base 0x1a4 insns 102/105; --- delete mine 4:5 base 4:4 +aes/AESiEncryptBlock: current expression and loop forms: src 0x278 base 0x278 insns 158/158; diffs 137: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 23, 24, 25, 26] +aes/AESiDecryptBlock: current expression and loop forms: src 0x3c4 base 0x3ec insns 241/251; --- insert mine 6:6 base 6:7 +aes/NETAESCreateEx: current expression and loop forms: src 0x19c base 0x1b0 insns 103/108; --- replace mine 19:21 base 19:21 +aes/AESiEncryptBlock: integer locals and alternate loop declarations: src 0x27c base 0x278 insns 159/158; --- replace mine 0:1 base 0:1 +aes/AESiDecryptBlock: integer locals and alternate loop declarations: src 0x3c8 base 0x3ec insns 242/251; --- insert mine 6:6 base 6:7 +aes/NETAESCreateEx: integer locals and alternate loop declarations: src 0x19c base 0x1b0 insns 103/108; --- replace mine 19:21 base 19:21 +aes/AESiEncryptBlock: expression grouping and assignment order: src 0x278 base 0x278 insns 158/158; diffs 139: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 23, 24, 25, 26] +aes/AESiDecryptBlock: expression grouping and assignment order: src 0x3c4 base 0x3ec insns 241/251; --- insert mine 6:6 base 6:7 +aes/NETAESCreateEx: expression grouping and assignment order: src 0x19c base 0x1b0 insns 103/108; --- replace mine 19:21 base 19:21 +aes/AESiEncryptBlock: retained readable candidate: src 0x278 base 0x278 insns 158/158; diffs 137: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 23, 24, 25, 26] +aes/AESiDecryptBlock: retained readable candidate: src 0x3c4 base 0x3ec insns 241/251; --- insert mine 6:6 base 6:7 +aes/NETAESCreateEx: retained readable candidate: src 0x19c base 0x1b0 insns 103/108; --- replace mine 19:21 base 19:21 + +md5 NETMD5Update: deferred available calculation and declared available before data; 60/60 instructions, diffs 0. +sha1: reordered remaining-length locals and replaced memcpy with a 16-word copy loop; all exact. SHA1 round XOR order b ^ c ^ d gives diffs 0. +neterrorcode: initialized index before mask and disabled inlining inside startup caller; all exact.