Added VTABLE validation

This commit is contained in:
krystalgamer 2024-06-11 17:57:35 +02:00
parent d83056227b
commit b7d19c6dc2
6 changed files with 68 additions and 33 deletions

View File

@ -879,6 +879,12 @@ void validate_CBaddy(void){
VALIDATE(CBaddy, field_318, 0x318);
VALIDATE(CBaddy, field_31C, 0x31C);
VALIDATE(CBaddy, dumbAssPad, 0x320);
VALIDATE_VTABLE(CBaddy, AI, 2);
VALIDATE_VTABLE(CBaddy, Hit, 3);
VALIDATE_VTABLE(CBaddy, PlayerIsVisible, 5);
VALIDATE_VTABLE(CBaddy, TugImpulse, 7);
VALIDATE_VTABLE(CBaddy, GetClosest, 13);
}

View File

@ -3,38 +3,7 @@
#ifndef EXPORT_H
#define EXPORT_H
#ifdef _MSC_VER
#if _MSC_VER < 1300
#define _OLD_WINDOWS
#else
#define _NEW_WINDOWS
#endif
#endif
#ifdef _WIN32
#define EXPORT __declspec( dllexport )
#define FASTCALL __fastcall
#else
#define EXPORT
#define FASTCALL __attribute__((fastcall))
#endif
#include <cstdio>
#ifndef _WIN32
#define __int16 short
#define __int8 char
#endif
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef char i8;
typedef short i16;
typedef int i32;
#include "my_types.h"
static int *Animations = (int*)0x006B245C;

1
ob.cpp
View File

@ -711,6 +711,7 @@ void validate_CBody(void){
VALIDATE(CBody, field_EC, 0xEC);
VALIDATE(CBody, cbodyend, 0xF0);
VALIDATE_VTABLE(CBody, Die, 1);
}
void validate_CSuper(void){

2
thug.h
View File

@ -33,10 +33,10 @@ public:
EXPORT void StrikeUpConversation(void);
EXPORT i32 DistanceToPlayer(i32);
EXPORT u32 CheckStateFlags(SStateFlags*, int);
EXPORT i32 GetClosest(i32, i32);
EXPORT virtual void SetThugType(int);
EXPORT virtual i32 GetClosest(i32, i32);
u8 padTop[0x330-0x324];

View File

@ -1,4 +1,5 @@
#include "validate.h"
#include <cstdarg>
int FAIL_VALIDATION = 0;
@ -32,3 +33,43 @@ void validate_size(int cur, int expected, const char *name){
fflush(stdout);
}
u32* get_thunk_address(void* first,...)
{
va_list args;
va_start(args, first);
u32* res = va_arg(args, u32*);
va_end(args);
return res;
}
void validate_vtable_index(
u32 expected_index,
const u32* known_address,
const char *cls,
const char *name)
{
#ifdef _OLD_WINDOWS
u32 bytes = *known_address;
if (bytes != 0x60FF018B)
{
FAIL_VALIDATION = 1;
printf("[!] Invalid bytes - %08X - at address - %08X - for %s->%s\n", bytes, known_address, cls, name);
}
else
{
u32 cur_index = reinterpret_cast<const u8*>(known_address)[4];
cur_index /= 4;
if (cur_index != expected_index)
{
FAIL_VALIDATION = 1;
printf("[!] Invalid index for %s->%s, expected %u but got %u - %08X\n", cls, name, expected_index, cur_index, known_address);
}
}
fflush(stdout);
#endif
}

View File

@ -1,7 +1,11 @@
#pragma once
#ifndef VALIDATE_H
#define VALIDATE_H
#include <stddef.h>
#include <cstdio>
#include "my_types.h"
void validate_class(int cur, int expected, const char *cls, const char *member);
#define VALIDATE(cls, member, expected) validate_class(offsetof(cls, member), expected, #cls, #member);
@ -9,3 +13,17 @@ void validate_class(int cur, int expected, const char *cls, const char *member);
void validate_size(int cur, int expected, const char *name);
#define VALIDATE_SIZE(cls, size) validate_size(sizeof(cls), size, #cls);
u32* get_thunk_address(void*, ...);
void validate_vtable_index(
u32 expected_index,
const u32* known_address,
const char *cls,
const char *name);
#define VALIDATE_VTABLE(cls, member, expected) {\
validate_vtable_index(expected, get_thunk_address(0, &cls::member), #cls, #member);\
}
#endif