Sanitize Usernames + Allow Extended ASCII In Sanitizer
minecraft-pi-reborn/pipeline/head This commit looks good Details

pull/10/head^2
TheBrokenRail 2 years ago
parent 19f8228058
commit 1582066d0d

@ -124,6 +124,17 @@ static uint32_t Minecraft_gui_property_offset = 0x198; // Gui
static uint32_t CommandServer_minecraft_property_offset = 0x18; // Minecraft *
// Packet
typedef void (*Packet_read_t)(unsigned char *packet, unsigned char *bit_stream);
// LoginPacket
static Packet_read_t LoginPacket_read = (Packet_read_t) 0x6e5f8;
static void *LoginPacket_read_vtable_addr = (void *) 0x108dcc;
static uint32_t LoginPacket_username_property_offset = 0xc; // RakString
// ChatPacket
static uint32_t ChatPacket_message_property_offset = 0xc; // char *
@ -293,6 +304,17 @@ static uint32_t ItemInstance_auxilary_property_offset = 0x8;
typedef int32_t (*FillingContainer_addItem_t)(unsigned char *filling_container, unsigned char *item_instance);
static FillingContainer_addItem_t FillingContainer_addItem = (FillingContainer_addItem_t) 0x92aa0;
// RakNet::RakString
typedef void (*RakNet_RakString_Assign_t)(unsigned char *rak_string, const char *str);
static RakNet_RakString_Assign_t RakNet_RakString_Assign = (RakNet_RakString_Assign_t) 0xe9e34;
static uint32_t RakNet_RakString_sharedString_property_offset = 0x0; // RakNet::RakString::SharedString *
// RakNet::RakString::SharedString
static uint32_t RakNet_RakString_SharedString_c_str_property_offset = 0x10; // char *
// RakNetInstance
typedef void (*RakNetInstance_send_t)(unsigned char *rak_net_instance, unsigned char *packet);
@ -301,7 +323,7 @@ static uint32_t RakNetInstance_send_vtable_offset = 0x38;
typedef uint32_t (*RakNetInstance_isServer_t)(unsigned char *rak_net_instance);
static uint32_t RakNetInstance_isServer_vtable_offset = 0x48;
static uint32_t RakNetInstance_peer_property_offset = 0x4;
static uint32_t RakNetInstance_peer_property_offset = 0x4; // RakNet::RakPeer *
// RakNet::RakPeer

@ -212,8 +212,9 @@ void _patch_address(const char *file, int line, void *start, void *target) {
}
// Sanitize String
#define MINIMUM_MESSAGE_CHARACTER 32
#define MAXIMUM_MESSAGE_CHARACTER 126
#define MINIMUM_SAFE_CHARACTER 32
#define MAXIMUM_SAFE_CHARACTER 126
#define MINIMUM_EXTENDED_SAFE_CHARACTER 128
void sanitize_string(char **str, int max_length, unsigned int allow_newlines) {
// Store Message Length
int length = strlen(*str);
@ -227,7 +228,7 @@ void sanitize_string(char **str, int max_length, unsigned int allow_newlines) {
if (allow_newlines && ((*str)[i] == '\n' || (*str)[i] == '\r')) {
continue;
}
if ((*str)[i] < MINIMUM_MESSAGE_CHARACTER || (*str)[i] > MAXIMUM_MESSAGE_CHARACTER) {
if (((*str)[i] < MINIMUM_SAFE_CHARACTER || (*str)[i] > MAXIMUM_SAFE_CHARACTER) && (*str)[i] < MINIMUM_EXTENDED_SAFE_CHARACTER) {
// Replace Illegal Character
(*str)[i] = '?';
}

@ -1,13 +1,18 @@
#include <string.h>
#include <libreborn/libreborn.h>
#include <libreborn/minecraft.h>
#include "../feature/feature.h"
#include "misc.h"
#include "../init/init.h"
#include <libreborn/minecraft.h>
// Minecraft Pi User Data Root
#define NEW_PATH "/.minecraft-pi/"
// Maximum Username Length
#define MAX_USERNAME_LENGTH 16
// Render Selected Item Text
static void Gui_renderChatMessages_injection(unsigned char *gui, int32_t param_1, uint32_t param_2, uint32_t param_3, unsigned char *font) {
// Call Original Method
@ -40,6 +45,26 @@ static void Inventory_selectSlot_injection(unsigned char *inventory, int32_t slo
reset_selected_item_text_timer = 1;
}
// Sanitize Username
static void LoginPacket_read_injection(unsigned char *packet, unsigned char *bit_stream) {
// Call Original Method
(*LoginPacket_read)(packet, bit_stream);
// Prepare
unsigned char *rak_string = packet + LoginPacket_username_property_offset;
// Get Original Username
unsigned char *shared_string = *(unsigned char **) (rak_string + RakNet_RakString_sharedString_property_offset);
char *c_str = *(char **) (shared_string + RakNet_RakString_SharedString_c_str_property_offset);
// Sanitize
char *new_username = strdup(c_str);
ALLOC_CHECK(new_username);
sanitize_string(&new_username, MAX_USERNAME_LENGTH, 0);
// Set New Username
(*RakNet_RakString_Assign)(rak_string, new_username);
// Free
free(new_username);
}
void init_misc() {
// Store Data In ~/.minecraft-pi Instead Of ~/.minecraft
patch_address((void *) default_path, (void *) NEW_PATH);
@ -55,6 +80,9 @@ void init_misc() {
overwrite_calls((void *) Gui_tick, (void *) Gui_tick_injection);
overwrite_calls((void *) Inventory_selectSlot, (void *) Inventory_selectSlot_injection);
// Sanitize Username
patch_address(LoginPacket_read_vtable_addr, (void *) LoginPacket_read_injection);
// Init C++
init_misc_cpp();
}
Loading…
Cancel
Save