Created
June 14, 2026 11:39
-
-
Save erfg12/b9b5d2712cd788b8e265c52261252750 to your computer and use it in GitHub Desktop.
OpenJK (Jedi Academy) huffman decode then re-encode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // HUFFMAN TEST, NOTE YOU HAVE TO START PACKETS AT 0xff, 0xff, 0xff, 0xff | |
| // This is a captured "connect" packet in Wireshark | |
| unsigned char og_packet[] = { | |
| 0xff, 0xff, 0xff, 0xff, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x20, 0x01, 0x42, 0x44, 0x74, | |
| 0x70, 0x88, 0x0d, 0x0c, 0xc7, 0x25, 0xcc, 0xc4, 0x1e, 0x9c, 0x8e, 0xad, 0x86, 0x5d, 0xb0, 0x74, | |
| 0xa3, 0x4f, 0x9c, 0x81, 0xc9, 0x63, 0xdd, 0xc3, 0xb8, 0xb1, 0x70, 0xaa, 0xc1, 0xb4, 0x14, 0xf3, | |
| 0xa8, 0x80, 0x56, 0x60, 0xfa, 0x30, 0x10, 0xac, 0x17, 0x4e, 0x80, 0x03, 0xe2, 0x0f, 0xf3, 0x6b, | |
| 0x1f, 0x1c, 0x3f, 0x06, 0x8d, 0x27, 0x2c, 0xb4, 0xc0, 0x96, 0xfc, 0x3d, 0x5a, 0xaf, 0x78, 0xa8, | |
| 0x28, 0xf5, 0x2f, 0xc1, 0x2e, 0xae, 0xea, 0x27, 0x9c, 0xb1, 0x81, 0x15, 0x63, 0xd4, 0x0f, 0xae, | |
| 0xd0, 0x52, 0xd5, 0x1f, 0x6d, 0xad, 0xb2, 0xbd, 0x7e, 0x7e, 0x9d, 0x9b, 0x93, 0x8b, 0x90, 0xf0, | |
| 0x3b, 0xe4, 0xef, 0x7f, 0x7c, 0xb7, 0xa5, 0x92, 0xa3, 0xf2, 0xe9, 0xd3, 0x4f, 0xd5, 0xeb, 0x24, | |
| 0x03, 0xfa, 0xfc, 0x3a, 0x8c, 0x99, 0x74, 0x4b, 0xd3, 0x02, 0xca, 0xa8, 0x8f, 0xfe, 0x15, 0x0a, | |
| 0xeb, 0x46, 0x21, 0xf9, 0x15, 0x85, 0x18, 0xb2, 0xaa, 0x35, 0x1e, 0x5e, 0x3d, 0x1e, 0x7f, 0x6f, | |
| 0x1f, 0xad, 0xc1, 0x1f, 0xf7, 0xff, 0x63, 0xc5, 0xb5, 0x2d, 0xa7, 0x58, 0x49, 0x77, 0x17, 0x25, | |
| 0xe7, 0x3b, 0x5e, 0xe8, 0x9a, 0xb8, 0xd7, 0x9a, 0x1c, 0xc7, 0x80, 0x4e, 0x7d, 0x2a, 0xe2, 0xdc, | |
| 0x8f, 0x87, 0x28, 0x12, 0xd1, 0xc9, 0x05, 0xcd, 0x4e, 0x12, 0xe8, 0x90, 0x30, 0x9e, 0x94, 0x40, | |
| 0xe8, 0xf3, 0x4a, 0xdc, 0x30, 0x3a, 0xcd, 0xe2, 0x83, 0xca, 0x6a, 0xbb, 0xde, 0x3d, 0x66, 0xa7, | |
| 0x67, 0xed, 0x40, 0x9f, 0xe0, 0x90, 0x02, 0xcd, 0xe4, 0x1f, 0x6a, 0x30, 0x5b, 0x7d, 0xa6, 0xea, | |
| 0x64, 0x73, 0x06, 0x6e, 0x67, 0x24, 0xac, 0xdd, 0x59, 0x00 | |
| }; | |
| // make a new msg_t for huffman decode | |
| msg_t msg2; | |
| byte userinfo[MAX_MSGLEN]; | |
| char* s2; | |
| Com_Memcpy(userinfo, og_packet, sizeof(og_packet)); | |
| MSG_Init(&msg2, userinfo, sizeof(userinfo)); | |
| msg2.cursize = sizeof(og_packet); | |
| MSG_BeginReadingOOB(&msg2); // NOTE: This resets everything | |
| MSG_ReadLong(&msg2); // skip the -1 marker // NOTE: This reads the bits to get the length | |
| Huff_Decompress(&msg2, 12); | |
| s2 = MSG_ReadStringLine(&msg2); | |
| Com_Printf("DEBUG: TEST PACKET %s\n", s2); // NOTE: s2 is now in a readable string | |
| // TAKE OUR DECODED MSG AND RE-ENCODE IT | |
| char data[MAX_INFO_STRING + 10]; | |
| Com_sprintf(data, sizeof(data), "%s", s2); | |
| byte* format = (byte *)data; | |
| byte string[MAX_MSGLEN]; | |
| int i; | |
| // set the header | |
| string[0] = 0xff; | |
| string[1] = 0xff; | |
| string[2] = 0xff; | |
| string[3] = 0xff; | |
| for (i = 0; i < strlen(data); i++) { | |
| string[i + 4] = format[i]; | |
| } | |
| msg_t mbuf; | |
| //MSG_Init(&mbuf, string, sizeof(string)); | |
| mbuf.data = string; | |
| mbuf.cursize = strlen(data) + 4; | |
| Huff_Compress(&mbuf, 12); | |
| PrintHex(mbuf.data, mbuf.cursize, "POST-COMPRESSION BUFFER"); | |
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment