Compare commits

...

6 Commits

6 changed files with 102 additions and 89 deletions

View File

@@ -1870,7 +1870,7 @@ config.libs = [
RVLSDKLib("nup", [
Object(NonMatching, "nup/nup.cpp"),
Object(NonMatching, "nup/nup_nhttp.cpp"),
Object(NonMatching, "nup/nup_mem.cpp"),
Object(Matching, "nup/nup_mem.cpp"),
]
),
RVLSDKLib("scutil", [

View File

@@ -192,11 +192,7 @@ static s32 __nupParseServerInfo(NUPContextInfo* context, char* response, char* m
const char* versionStartTag = "<Version>";
afterEnd = __nupFindTag(response, versionEndTag, versionStartTag,
&start, &valueLength);
if (afterEnd == 0) {
result = -5004;
goto done;
}
if (valueLength != strlen("1.0") || strncmp(start, "1.0", valueLength) != 0) {
if (afterEnd == 0 || valueLength != strlen("1.0") || strncmp(start, "1.0", valueLength) != 0) {
result = -5004;
goto done;
}
@@ -339,22 +335,13 @@ static s32 __nupParseServerInfo(NUPContextInfo* context, char* response, char* m
const char* titleIdStartTag = "<TitleId>";
const char* versionEndTag = "</Version>";
const char* versionStartTag = "<Version>";
char* titleStart;
char* versionStart;
size_t titleLength;
size_t versionLength;
char* parsedEnd;
goto first;
for (;;) {
char* titleStart;
char* versionStart;
size_t titleLength;
size_t versionLength;
char* parsedEnd;
cursor = __nupFindTag(cursor, titleIdEndTag, titleIdStartTag,
&titleStart, &titleLength);
if (cursor == 0) {
break;
}
cursor = __nupFindTag(cursor, versionEndTag, versionStartTag,
&versionStart, &versionLength);
if (cursor == 0) {
break;
}
unsigned long long titleId = strtoull(titleStart, &parsedEnd, 16);
if (parsedEnd != titleStart + titleLength) {
result = -5004;
@@ -365,13 +352,24 @@ static s32 __nupParseServerInfo(NUPContextInfo* context, char* response, char* m
result = -5004;
goto done;
}
if ((u16)version != version) {
if (version != (u16)version) {
result = -5004;
goto done;
}
context->titles[context->titleCount].titleId = titleId;
context->titles[context->titleCount].serverVersion = version;
context->titleCount++;
first:
cursor = __nupFindTag(cursor, titleIdEndTag, titleIdStartTag,
&titleStart, &titleLength);
if (cursor == 0) {
break;
}
cursor = __nupFindTag(cursor, versionEndTag, versionStartTag,
&versionStart, &versionLength);
if (cursor == 0) {
break;
}
}
}
@@ -401,9 +399,9 @@ static s32 __nupGetServerInfo(char* serverAddress, char* messageId, unsigned lon
result = -5000;
} else {
snprintf(endpoint, endpointSize, "https://%s/nus/services/NetUpdateSOAP", serverAddress);
requestSize = strlen(messageId);
requestSize += strlen(productArea);
requestSize += strlen(countryCode) + 0x449;
requestSize = strlen(messageId) + strlen(productArea);
requestSize += strlen(countryCode);
requestSize += 0x449;
if (auditData != 0) {
requestSize += strlen(auditData);
}
@@ -515,15 +513,16 @@ static u32 __nupSetAuditState(u8 state) {
#pragma dont_inline reset
static void __nupBase64Encode(u8* output, u8* input, unsigned long length) {
const char* alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
u8* end = input + length;
u32 value = 0;
u32 count = 0;
static char fillByte = '=';
static char pad = '=';
while (input != end) {
count++;
value = value << 8 | *input++;
value <<= 8;
value |= *input++;
if (count < 3) {
continue;
}
@@ -540,7 +539,7 @@ static void __nupBase64Encode(u8* output, u8* input, unsigned long length) {
output[0] = alphabet[value >> 18 & 0x3f];
output[1] = alphabet[value >> 12 & 0x3f];
output[2] = alphabet[value >> 6 & 0x3f];
output[3] = fillByte;
output[3] = pad;
return;
}
if (count != 1) {
@@ -549,8 +548,8 @@ static void __nupBase64Encode(u8* output, u8* input, unsigned long length) {
value <<= 16;
output[0] = alphabet[value >> 18 & 0x3f];
output[1] = alphabet[value >> 12 & 0x3f];
output[2] = fillByte;
output[3] = fillByte;
output[2] = pad;
output[3] = pad;
}
static s32 __nupGetAuditData(NUPContextInfo* context, char** auditData) {
@@ -559,7 +558,7 @@ static s32 __nupGetAuditData(NUPContextInfo* context, char** auditData) {
ESTicketView* ticketViews = 0;
u32 viewCount;
u32 selected = 0;
u32 selectedIndex = 0;
u32 selectedIndex;
void* auditRecord = 0;
void* signatureCertificate = 0;
void* deviceCertificate = 0;
@@ -633,12 +632,13 @@ static s32 __nupGetAuditData(NUPContextInfo* context, char** auditData) {
memcpy(signedData->signature, signature, sizeof(signature));
memcpy(signedData->signatureCertificate, signatureCertificate, 0x180);
memcpy(signedData->deviceCertificate, deviceCertificate, 0x180);
encodedData = nup::__nupMalloc(0x5a1);
unsigned long dataSize = sizeof(NUPSignedAuditData);
encodedData = nup::__nupMalloc((dataSize + 2) / 3 * 4 + 1);
if (encodedData == 0) {
result = -5000;
} else {
__nupBase64Encode((u8*)encodedData, (u8*)signedData, sizeof(NUPSignedAuditData));
((u8*)encodedData)[0x5a0] = 0;
((u8*)encodedData)[(dataSize + 2) / 3 * 4] = 0;
}
}
}
@@ -900,6 +900,8 @@ static inline BOOL __nupHasContent(const NUPTitleInfo* title, ESContentId conten
}
static s32 __nupGetTitleSize(NUPTitleInfo* title) {
ESTmdView* tmdView = (ESTmdView*)title->tmdView;
ESCmdView* content;
s32 contentIndex;
s32 result = 0;
title->progressStep += 2;
@@ -915,11 +917,12 @@ static s32 __nupGetTitleSize(NUPTitleInfo* title) {
title->installedContentSize += 0x8000;
title->installedContentSize += 0x4000;
title->installedContentSize += 0x4000;
for (contentIndex = 0; contentIndex < ((ESTmdView*)title->tmdView)->head.numContents; contentIndex++) {
ESCmdView* content = &((ESTmdView*)title->tmdView)->contents[contentIndex];
if (!__nupHasContent(title, content->cid) ||
for (contentIndex = 0; contentIndex < tmdView->head.numContents; contentIndex++) {
content = &tmdView->contents[contentIndex];
ESContentId cid = content->cid;
if (!__nupHasContent(title, cid) ||
title->titleId == 0x0000000100000001ULL) {
if (content->size >= 0xfffffff0ULL) {
if (content->size > 0xffffffefULL) {
result = -0x1394;
break;
}
@@ -1111,11 +1114,12 @@ static s32 __nupUpdateTitle(NUPContextInfo* context, NUPTitleInfo* title, char*
}
} else {
ISFSStats stats;
result = ISFS_GetStats(&stats);
if (result == 0 && stats.freeBlocks >= (title->installedContentSize >> 14) &&
s32 hasSpace = ISFS_GetStats(&stats);
if (hasSpace == 0 && stats.freeBlocks >= (title->installedContentSize >> 14) &&
title->progressStep <= stats.freeInodes) {
result = 1;
hasSpace = 1;
}
result = hasSpace;
if (result == 0) {
result = -0x1392;
goto done;
@@ -1144,11 +1148,12 @@ static s32 __nupUpdateTitle(NUPContextInfo* context, NUPTitleInfo* title, char*
goto done;
}
result = ES_ImportTitleDone();
if (result != 0) {
goto done;
}
}
if (result == 0) {
__nupCleanupTitleInfo(title);
title->updateRequired = 0;
}
__nupCleanupTitleInfo(title);
title->updateRequired = 0;
done:
return result;
}
@@ -1163,7 +1168,7 @@ extern "C" void* __nupOp(void* argument) {
NUPTitleInfo* systemTitle = 0;
u32 deviceId;
u32 bootVersion;
u16 serverBootVersion = 0;
u32 serverBootVersion = 0;
u16 bootTitleVersion;
u16 systemMenuVersion;
ESTitleId currentTitleId;
@@ -1181,7 +1186,7 @@ extern "C" void* __nupOp(void* argument) {
result = ES_GetBoot2Version(&bootVersion);
if (result == 0) {
serverBootVersion = bootVersion;
if (serverBootVersion != bootVersion) {
if ((u16)serverBootVersion != bootVersion) {
result = -0x1389;
}
}
@@ -1375,7 +1380,13 @@ done:
} else {
OSLockMutex(&context->mutex);
context->progress.result = result;
context->progress.message = __nupStatusMessage[5];
if (result < 0) {
context->progress.message = __nupStatusMessage[5];
} else if (result >= 4) {
context->progress.message = __nupStatusMessage[4];
} else {
context->progress.message = __nupStatusMessage[result];
}
OSUnlockMutex(&context->mutex);
}
return 0;

View File

@@ -41,8 +41,7 @@ int __nupRegisterAllocator(MEMAllocator* allocator) {
} else {
if (((MEMHeapHandle)allocator->heap)->magic != 0x45585048) {
result = -5011;
}
if (((MEMHeapHandle)allocator->heap)->magic == 0x45585048) {
} else {
__mem = allocator;
}
}

View File

@@ -70,7 +70,7 @@ static u8* __nupNhttpBufFull(u8** buffer, unsigned long* length, unsigned long r
}
next = *buffer;
if (next == NULL) {
if (requested != 0 && requested < 0x8000) {} else requested = 0x8000;
if (requested == 0 || requested >= 0x8000) requested = 0x8000;
next = (u8*)nup::__nupMalloc(requested);
if (next == NULL) {
state->error = -5000;
@@ -83,8 +83,8 @@ static u8* __nupNhttpBufFull(u8** buffer, unsigned long* length, unsigned long r
}
done:
if (state->error != 0) {
next = NULL;
*length = 0;
next = NULL;
}
return next;
}
@@ -101,12 +101,13 @@ static void __nupNhttpReqDone(int result, void* response, HttpState* state) {
}
static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* body, unsigned long bodyLength, unsigned long limit, ProgressCallback progress, void* progressContext, FlushCallback flush, void* flushContext) {
unsigned long transferred, expected;
int length;
char* responseHeaders = NULL;
u8* responseBody = NULL;
HttpState state;
int result = 0;
int status;
u8* responseBody = NULL;
char* responseHeaders = NULL;
int length;
unsigned long expected, transferred;
HttpState state;
state.error = 0;
state.limit = limit;
state.received = 0;
@@ -118,8 +119,7 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
state.done = 0;
state.result = 0;
state.lastActivity = 0;
int result = 0;
int requestId = 0;
int requestId;
char* headerCopy = NULL;
void* request = NHTTPCreateRequestEx(url, method, NULL, 0, __nupNhttpReqDone, &state, __nupNhttpBufFull, __nupNhttpBufFree);
if (request == NULL) { result = -7000 - NHTTPGetError(); goto cleanup; }
@@ -130,16 +130,15 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
if (headerCopy == NULL) { result = -5000; goto cleanup; }
memcpy(headerCopy, headers, size);
char* field = headerCopy;
while (*field != 0) {
char* colon = strchr(field, ':');
if (colon == NULL) break;
char* end = strstr(colon, "\r\n");
if (end == NULL) break;
char* colon;
char* end;
while (*field != 0 && (colon = strchr(field, ':')) != NULL && (end = strstr(colon, "\r\n")) != NULL) {
*colon = 0;
*end = 0;
while (*field && isspace(*field)) field++;
do { colon++; } while (*colon && isspace(*colon));
if (NHTTPAddHeaderField(request, field, colon) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
char* value = colon + 1;
while (*value && isspace(*value)) value++;
if (NHTTPAddHeaderField(request, field, value) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
field = end + 2;
}
}
@@ -153,9 +152,8 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
if (method == NHTTP_POST && body != NULL && bodyLength != 0 && NHTTPAddPostDataRaw(request, body, bodyLength) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
requestId = NHTTPSendRequestAsync(request);
if (requestId < 0) {
int error = NHTTPGetError();
result = -7000 - NHTTPGetError();
NHTTPDeleteRequest(request);
result = -7000 - error;
goto cleanup;
}
state.lastActivity = OSGetTime();
@@ -167,8 +165,8 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
if (length < 0) { result = -5007; goto cleanup; }
__nupNhttpBufFull(&responseBody, (unsigned long*)&length, 0, NULL, NULL, &state);
}
result = state.error;
if (result != 0 || state.response == NULL) goto cleanup;
if (state.error != 0) { result = state.error; goto cleanup; }
if (state.response == NULL) goto cleanup;
length = NHTTPGetHeaderAll(state.response, &responseHeaders);
if (length < 0) { result = -5007; goto cleanup; }
char* protocol = strstr(responseHeaders, "HTTP/");
@@ -197,10 +195,10 @@ extern "C" {
static long __nupHttpStringFlush(u8* data, unsigned long length, unsigned long requested, void* context) {
HttpString* text = (HttpString*)context;
unsigned long total;
total = length + text->length;
total = text->length + length;
long result = 0;
if (total > text->capacity) {
if (requested >= total) {} else {
if (requested < total) {
requested = text->growth + total;
text->growth <<= 1;
if (text->growth < text->maximumGrowth) {} else text->growth = text->maximumGrowth;

View File

@@ -13,7 +13,7 @@ int SOiIsBufferAddrCheck(void);
void* SOiAlloc(u32, s32);
void SOiFree(u32, void*, s32);
static int soSocketRegistered;
static int soSocketRegistered[2];
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;
@@ -47,7 +47,7 @@ int SOSocket(int family, int type, int protocol) {
s32 rm;
SocketRequest* request;
int result;
if(!soSocketRegistered) { OSRegisterVersion(__SOCKETVersion); soSocketRegistered=1; }
if(!soSocketRegistered[0]) { OSRegisterVersion(__SOCKETVersion); soSocketRegistered[0]=1; }
if((result=SOiPrepare(NULL,&rm))==0) {
if(family==23) result=-5;
else {
@@ -129,9 +129,9 @@ int SOGetSockName(int socket, void* address) {
int size;
int result;
s32 rm;
SOSockAddr* addr;
SOSockAddr* reply;
NameRequest* request;
SOSockAddr* reply;
SOSockAddr* addr;
addr=address;
if((result=SOiPrepare(NULL,&rm))==0) {
if(!addr || addr->len>8 || addr->len<8) result=-28;
@@ -199,7 +199,7 @@ int SOShutdown(int socket, int how) {
int SOPoll(SOPollFD* fds, unsigned int count, s64 timeout) {
s32 rm;
s32 result,bytes,size;
s32 size,bytes,result;
PollRequest* request;
SOPollFD* reply;
if((result=SOiPrepare(NULL,&rm))==0) {
@@ -256,11 +256,11 @@ char* SOInetNtoA(SOInAddr address) {
int SOInetPtoN(int family, const char* text, void* address) {
s32 rm;
int temporary,result,size,bytes;
int temporary,size,result,bytes;
InetRequest* request;
if((result=SOiPrepareTempRm(NULL,&rm,&temporary))==0) {
bytes=0;
if(family==2) bytes=4;
switch(family) { case 2: bytes=4; break; default: break; }
if(!bytes) result=-5;
else if(!text) result=-28;
else {
@@ -316,7 +316,7 @@ static int RecvFrom(const char* name, int socket, void* data, int length, int fl
else {
direct=TRUE;
if(length && !DirectBuffer(data,length)) direct=FALSE;
size=((address ? address->len : 0)+95)&~31;
size=((address==NULL ? 0 : address->len)+95)&~31;
request=SOiAlloc(12,size);
if(!direct) buffer=SOiAlloc(13,(length+31)&~31);
else buffer=data;

View File

@@ -48,13 +48,13 @@ s32 SOGetHostID(void) {
}
SOHostEnt* SOGetHostByName(const char* name) {
char* request;
HostReply* reply;
int result;
int size;
int length;
SOHostEnt* host;
int result;
s32 rm;
char* request;
host = NULL;
if((result=SOiPrepare(NULL,&rm))==0) {
if(!name) result=-28;
@@ -84,18 +84,21 @@ SOHostEnt* SOGetHostByName(const char* name) {
return host;
}
static int NameSize(const char* name) { return name ? strlen(name)+1 : 0; }
static int NameSize(const char* name) { return name==NULL ? 0 : strlen(name)+1; }
int SOGetAddrInfo(const char* nodeName, const char* servName, const SOAddrInfo* hints, SOAddrInfo** resultInfo) {
s32 rm;
int result,size;
AddrInfoRequest* request;
AddrInfoReply* reply;
int servLen,nodeLen;
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;
if(servName==NULL) servLen=0; else servLen=strlen(nodeName)+1;
nodeLen=NameSize(nodeName);
size=(((nodeLen+31)&~31)+((servLen+31)&~31)+95)&~31;
request=SOiAlloc(12,size);
if(!request) result=-49;
else {
@@ -104,13 +107,15 @@ int SOGetAddrInfo(const char* nodeName, const char* servName, const SOAddrInfo*
else {
node=(char*)request->storage;
service=node+((NameSize(nodeName)+31)&~31);
requestHints=(SOAddrInfo*)(service+((servName ? strlen(nodeName)+32 : 31)&~31));
requestHints=(SOAddrInfo*)(service+(((servName==NULL ? 0 : strlen(nodeName)+1)+31)&~31));
if(nodeName) strcpy(node,nodeName);
request->vectors[0].base=nodeName ? (u8*)node : NULL;
request->vectors[0].length=nodeName ? strlen(nodeName) : 0;
node=nodeName ? node : NULL;
request->vectors[0].base=(u8*)node;
request->vectors[0].length=nodeName==NULL ? 0 : strlen(nodeName);
if(servName) strcpy(service,servName);
request->vectors[1].base=servName ? (u8*)service : NULL;
request->vectors[1].length=servName ? strlen(servName) : 0;
service=servName ? service : NULL;
request->vectors[1].base=(u8*)service;
request->vectors[1].length=servName==NULL ? 0 : strlen(servName);
if(hints) memcpy(requestHints,hints,32);
else memset(requestHints,0,32);
if(requestHints->family==0) requestHints->family=2;