From d25c1b105da1606d3e372974d7546c1f7726a198 Mon Sep 17 00:00:00 2001 From: Plex Date: Mon, 25 Oct 2021 16:47:49 +0200 Subject: handshake serialized --- mcping | Bin 21816 -> 21856 bytes mcping.c | 6 +++--- mctypes.c | 24 ++++++++++++------------ mctypes.h | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/mcping b/mcping index 56aee3d..dad70c2 100755 Binary files a/mcping and b/mcping differ diff --git a/mcping.c b/mcping.c index 20fbb68..ddeff4a 100644 --- a/mcping.c +++ b/mcping.c @@ -73,12 +73,12 @@ int main(int argc, char *argv[]) writeVarInt(1) }; - char u; - char* raw_hs = &u; - size_t hs_size = serializeHandshake(hs, raw_hs); + unsigned char *raw_hs; + size_t hs_size = serializeHandshake(hs, &raw_hs); printf("%lu\n", hs_size); for (int i = 0; i < hs_size; ++i) { printf("%02X ", raw_hs[i]); } + printf("\n"); return 0; } diff --git a/mctypes.c b/mctypes.c index 30319ee..79adc73 100644 --- a/mctypes.c +++ b/mctypes.c @@ -32,33 +32,33 @@ int readVarInt(varint x) return (int) res; } -size_t serializeHandshake(handshake hs, void *buf) +size_t serializeHandshake(handshake hs, void **buf) { size_t size = 0; size_t vi_size; - buf = malloc(size); + *buf = malloc(size); for (vi_size = 1; (hs.protocol_version[vi_size - 1] & 0x80) != 0; vi_size++); - buf = realloc(buf, size+vi_size); - memcpy(buf + size, hs.protocol_version, vi_size); + *buf = realloc(*buf, size+vi_size); + memcpy(*buf + size, hs.protocol_version, vi_size); size += vi_size; for (vi_size = 1; (hs.server_address.length[vi_size - 1] & 0x80) != 0; vi_size++); - buf = realloc(buf, size+vi_size); - memcpy(buf + size, hs.server_address.length, vi_size); + *buf = realloc(*buf, size+vi_size); + memcpy(*buf + size, hs.server_address.length, vi_size); size += vi_size; - buf = realloc(buf, size+readVarInt(hs.server_address.length)); - memcpy(buf + size, hs.server_address.content, readVarInt(hs.server_address.length)); + *buf = realloc(*buf, size+readVarInt(hs.server_address.length)); + memcpy(*buf + size, hs.server_address.content, readVarInt(hs.server_address.length)); size += readVarInt(hs.server_address.length); - buf = realloc(buf, size+sizeof(unsigned short)); - memcpy(buf + size, &hs.server_port, sizeof(unsigned short)); + *buf = realloc(*buf, size+sizeof(unsigned short)); + memcpy(*buf + size, &hs.server_port, sizeof(unsigned short)); size += sizeof(unsigned short); for (vi_size = 1; (hs.next_state[vi_size - 1] & 0x80) != 0; vi_size++); - buf = realloc(buf, size+vi_size); - memcpy(buf + size, hs.next_state, vi_size); + *buf = realloc(*buf, size+vi_size); + memcpy(*buf + size, hs.next_state, vi_size); size += vi_size; return size; diff --git a/mctypes.h b/mctypes.h index 8230b53..89e9b81 100644 --- a/mctypes.h +++ b/mctypes.h @@ -26,5 +26,5 @@ typedef long pong; int readVarInt(varint x); varint writeVarInt(unsigned int x); -size_t serializeHandshake(handshake hs, void *buf); +size_t serializeHandshake(handshake hs, void **buf); size_t serializePacket(packet p, void *buf); -- cgit v1.2.3