I had broken this for NT4 compat earlier, i manually reimplemented ntohll inline in the tlen == 127 check

This commit is contained in:
winsped
2026-07-12 02:58:30 +03:00
parent 962a3b2bff
commit 48f91c0912
+13 -4
View File
@@ -106,7 +106,7 @@ DWORD WINAPI WSThreadProc(LPVOID ssl) {
if (length != 0 && result != 0) { if (length != 0 && result != 0) {
WebSocketOnDataArrival(ssl, buffer, length); WebSocketOnDataArrival(ssl, buffer, length);
// printf("%s\n",buffer); printf("%s\n", buffer);
// LE IMPORTANT: free the buffer after processing... memleak goez // LE IMPORTANT: free the buffer after processing... memleak goez
// brr otherewise // brr otherewise
free(buffer); free(buffer);
@@ -118,6 +118,7 @@ DWORD WINAPI WSThreadProc(LPVOID ssl) {
}; };
int SendWebSocket(SSL *ssl, const char *data, size_t length, int SendWebSocket(SSL *ssl, const char *data, size_t length,
unsigned char flags) { unsigned char flags) {
printf("%s\n", data);
unsigned char frame[14]; unsigned char frame[14];
size_t frame_size = 0; size_t frame_size = 0;
@@ -153,7 +154,8 @@ int SendWebSocket(SSL *ssl, const char *data, size_t length,
mask[i] = (unsigned char)(i & 0xFF); mask[i] = (unsigned char)(i & 0xFF);
} }
RtlCopyMemory(&frame[frame_size], mask, 4); // me when i rtlcopymemory to look cool RtlCopyMemory(&frame[frame_size], mask,
4); // me when i rtlcopymemory to look cool
frame_size += 4; frame_size += 4;
// Send frame header // Send frame header
@@ -200,8 +202,15 @@ int ReadWebSocket(SSL *ssl, char **out_buffer, size_t *out_length) {
SSL_read(ssl, &plHeaders, 1); SSL_read(ssl, &plHeaders, 1);
unsigned char tlen = (plHeaders << 1) >> 1; unsigned char tlen = (plHeaders << 1) >> 1;
if (tlen == 127) { if (tlen == 127) {
SSL_read(ssl, &curPayloadLen, 8); unsigned char lenbytes[8];
curPayloadLen = ntohl(curPayloadLen); SSL_read(ssl, lenbytes,8);
curPayloadLen = 0;
for (int i = 0; i < 4; i++) {
unsigned char temp = lenbytes[i];
lenbytes[i]=lenbytes[7-i];
lenbytes[7-i]=temp;
}
curPayloadLen = *(unsigned long long*)lenbytes;
payloadLen += curPayloadLen; payloadLen += curPayloadLen;
} else if (tlen == 126) { } else if (tlen == 126) {
unsigned short templen; unsigned short templen;