From 5a555b2f32bd4adeeaed68406fdcf02e9507accd Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Tue, 5 Feb 2019 11:20:35 -0600 Subject: [PATCH 1/5] prevent accidentical input higher than byte size --- OOVPA.h | 24 +++++++++++++++++++----- XbSymbolDatabase.c | 8 ++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/OOVPA.h b/OOVPA.h index a4320897..8afe8c7e 100644 --- a/OOVPA.h +++ b/OOVPA.h @@ -72,8 +72,20 @@ typedef struct _LOVP // Both the Offset and Value are 16-bit to allow for XRefs with a // large offset. Value can be safely cast to 8-bit for OOVPA, but must // remain 16-bit for XRef entries. - unsigned short Offset; - unsigned short Value; + unsigned short offset; + union { + // Generic structure TODO: Remove me after replace array to macro for OOVPA database + unsigned short value; + + struct { + unsigned char unused; + unsigned char value; + } byte; + + struct { + unsigned short index; + } xref; + }; } LOVP; // This XRefZero constant, when set in the OOVPA.XRefCount field, @@ -96,12 +108,14 @@ typedef struct _LOVP // Macro used for storing an XRef {Offset, XREF}-Pair. #define XREF_ENTRY( Offset, XRef) \ - { Offset, XRef } + { Offset, .xref.index = XRef } -// UNUSED Macro for storing a normal (non-XRef) {Offset, Value}-Pair +// Macro for storing a normal (non-XRef) {Offset, Value}-Pair // Offsets can go up to 16 bits, values are always one byte (8 bits) #define OV_ENTRY(Offset, Value) \ - { Offset, Value } + { Offset, .value = Value } +// TODO: Remove above line, then uncomment the line below for easy swap after OOVPA database has been fixed. +// { Offset, { .unused = 0, .value = Value } } // ****************************************************************** diff --git a/XbSymbolDatabase.c b/XbSymbolDatabase.c index fa9c2f1b..bce37c4e 100644 --- a/XbSymbolDatabase.c +++ b/XbSymbolDatabase.c @@ -333,14 +333,14 @@ uint32_t XbSymbolLibrayToFlag(const char* library_name) // the implementation could be changed if the need ever arises. static inline void GetXRefEntry(OOVPA *oovpa, int index, uint32_t* xref_out, uint16_t* offset_out) { - *xref_out = (unsigned int)((LOOVPA*)oovpa)->Lovp[index].Value; - *offset_out = ((LOOVPA*)oovpa)->Lovp[index].Offset; + *xref_out = (unsigned int)((LOOVPA*)oovpa)->Lovp[index].xref.index; + *offset_out = ((LOOVPA*)oovpa)->Lovp[index].offset; } static inline void GetOovpaEntry(OOVPA *oovpa, int index, uint32_t* offset_out, uint8_t* value_out) { - *offset_out = (unsigned int)((LOOVPA*)oovpa)->Lovp[index].Offset; - *value_out = (uint8_t)((LOOVPA*)oovpa)->Lovp[index].Value; + *offset_out = (unsigned int)((LOOVPA*)oovpa)->Lovp[index].offset; + *value_out = (uint8_t)((LOOVPA*)oovpa)->Lovp[index].value; } bool CompareOOVPAToAddress(OOVPA *Oovpa, memptr_t cur, uintptr_t xb_start_virt_addr) From a35d7528a311c4f0bcba76723bcd14681c88ac22 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Wed, 20 Mar 2019 22:03:48 -0500 Subject: [PATCH 2/5] add macro for multiple byte values in one line of code Requested by other developer --- OOVPA.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/OOVPA.h b/OOVPA.h index 8afe8c7e..08796ee3 100644 --- a/OOVPA.h +++ b/OOVPA.h @@ -106,13 +106,14 @@ typedef struct _LOVP // defined for the OOVPA. #define XRefNoSaveIndex 0xFFFF +// TODO: Rename to OV_XREF. // Macro used for storing an XRef {Offset, XREF}-Pair. #define XREF_ENTRY( Offset, XRef) \ { Offset, .xref.index = XRef } // Macro for storing a normal (non-XRef) {Offset, Value}-Pair // Offsets can go up to 16 bits, values are always one byte (8 bits) -#define OV_ENTRY(Offset, Value) \ +#define OV_BYTE(Offset, Value) \ { Offset, .value = Value } // TODO: Remove above line, then uncomment the line below for easy swap after OOVPA database has been fixed. // { Offset, { .unused = 0, .value = Value } } @@ -186,6 +187,27 @@ typedef struct _OOVPATable #define REGISTER_OOVPA_18(Symbol, Version, ...) REGISTER_OOVPA(Symbol, Version), MSVC_EXPAND(REGISTER_OOVPA_17(Symbol, __VA_ARGS__)) #define REGISTER_OOVPA_19(Symbol, Version, ...) REGISTER_OOVPA(Symbol, Version), MSVC_EXPAND(REGISTER_OOVPA_18(Symbol, __VA_ARGS__)) +#define OV_BYTES_0(...) + #define OV_BYTES_1(Offset, Value) OV_BYTE(Offset, Value) + #define OV_BYTES_2(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_1(Offset+1, __VA_ARGS__)) + #define OV_BYTES_3(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_2(Offset+1, __VA_ARGS__)) + #define OV_BYTES_4(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_3(Offset+1, __VA_ARGS__)) + #define OV_BYTES_5(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_4(Offset+1, __VA_ARGS__)) + #define OV_BYTES_6(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_5(Offset+1, __VA_ARGS__)) + #define OV_BYTES_7(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_6(Offset+1, __VA_ARGS__)) + #define OV_BYTES_8(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_7(Offset+1, __VA_ARGS__)) + #define OV_BYTES_9(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_8(Offset+1, __VA_ARGS__)) + #define OV_BYTES_10(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_9(Offset+1, __VA_ARGS__)) + #define OV_BYTES_11(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_10(Offset+1, __VA_ARGS__)) + #define OV_BYTES_12(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_11(Offset+1, __VA_ARGS__)) + #define OV_BYTES_13(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_12(Offset+1, __VA_ARGS__)) + #define OV_BYTES_14(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_13(Offset+1, __VA_ARGS__)) + #define OV_BYTES_15(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_14(Offset+1, __VA_ARGS__)) + #define OV_BYTES_16(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_15(Offset+1, __VA_ARGS__)) + #define OV_BYTES_17(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_16(Offset+1, __VA_ARGS__)) + #define OV_BYTES_18(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_17(Offset+1, __VA_ARGS__)) + #define OV_BYTES_19(Offset, Value, ...) OV_BYTE(Offset, Value), MSVC_EXPAND(OV_BYTES_18(Offset+1, __VA_ARGS__)) + // Accept any number of args >= N, but expand to just the Nth one. In this case, // we have settled on 20 as N. We could pick a different number by adjusting // the count of throwaway args before N. Note that this macro is preceded by @@ -204,6 +226,12 @@ typedef struct _OOVPATable REGISTER_OOVPA_9, REGISTER_OOVPA_8, REGISTER_OOVPA_7, REGISTER_OOVPA_6, REGISTER_OOVPA_5, \ REGISTER_OOVPA_4, REGISTER_OOVPA_3, REGISTER_OOVPA_2, REGISTER_OOVPA_1, REGISTER_OOVPA_0)(Symbol, __VA_ARGS__)) +#define OV_MATCH(Offset, ...) MSVC_EXPAND(_GET_NTH_ARG("ignored", __VA_ARGS__, \ + OV_BYTES_19, OV_BYTES_18, OV_BYTES_17, OV_BYTES_16, OV_BYTES_15, \ + OV_BYTES_14, OV_BYTES_13, OV_BYTES_12, OV_BYTES_11, OV_BYTES_10, \ + OV_BYTES_9, OV_BYTES_8, OV_BYTES_7, OV_BYTES_6, OV_BYTES_5, \ + OV_BYTES_4, OV_BYTES_3, OV_BYTES_2, OV_BYTES_1, OV_BYTES_0)(Offset, __VA_ARGS__)) + #pragma pack() #endif From 77edc1b272c431af512ad140ea748de2081a0342 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Wed, 20 Mar 2019 22:09:24 -0500 Subject: [PATCH 3/5] remove old note no longer apply to current situation --- OOVPA.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/OOVPA.h b/OOVPA.h index 08796ee3..4e12159d 100644 --- a/OOVPA.h +++ b/OOVPA.h @@ -218,8 +218,6 @@ typedef struct _OOVPATable _9, _8, _7, _6, _5, _4, _3, _2, _1, _0, \ N, ...) N -// NOTE: A reminder for all of developers, TYPE argument is meant for research documentation. -// (eventually UNPATCHED will be replace back to PATCH once LLE is fully supportive in the future) #define REGISTER_OOVPAS(Symbol, ...) MSVC_EXPAND(_GET_NTH_ARG("ignored", __VA_ARGS__, \ REGISTER_OOVPA_19, REGISTER_OOVPA_18, REGISTER_OOVPA_17, REGISTER_OOVPA_16, REGISTER_OOVPA_15, \ REGISTER_OOVPA_14, REGISTER_OOVPA_13, REGISTER_OOVPA_12, REGISTER_OOVPA_11, REGISTER_OOVPA_10, \ From 22a162716db03c244736843668e726ea604bfef3 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Wed, 20 Mar 2019 22:10:29 -0500 Subject: [PATCH 4/5] change OOVPA_TABLE_COUNT to XBSDB_ARRAY_SIZE --- OOVPA.h | 4 ++-- OOVPADatabase/D3D8LTCG_OOVPA.inl | 2 +- OOVPADatabase/D3D8_OOVPA.inl | 2 +- OOVPADatabase/DSound_OOVPA.inl | 2 +- OOVPADatabase/XActEng_OOVPA.inl | 2 +- OOVPADatabase/XGraphic_OOVPA.inl | 2 +- OOVPADatabase/XNet_OOVPA.inl | 2 +- OOVPADatabase/XOnline_OOVPA.inl | 2 +- OOVPADatabase/Xapi_OOVPA.inl | 2 +- XbSymbolDatabase.c | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/OOVPA.h b/OOVPA.h index 4e12159d..6b82b950 100644 --- a/OOVPA.h +++ b/OOVPA.h @@ -154,8 +154,8 @@ typedef struct _OOVPATable // http://en.cppreference.com/w/cpp/iterator/size //#include -//#define OOVPA_TABLE_COUNT(x) std::size(x) -#define OOVPA_TABLE_COUNT(x) (sizeof(x)/sizeof(x[0])) +//#define XBSDB_ARRAY_SIZE(x) std::size(x) +#define XBSDB_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #define OOVPA_TABLE_ENTRY_FULL(Oovpa, DebugName, Version) \ { & Oovpa ## _ ## Version.Header, DebugName, Version } diff --git a/OOVPADatabase/D3D8LTCG_OOVPA.inl b/OOVPADatabase/D3D8LTCG_OOVPA.inl index 0a13f9d9..25e1b8f7 100644 --- a/OOVPADatabase/D3D8LTCG_OOVPA.inl +++ b/OOVPADatabase/D3D8LTCG_OOVPA.inl @@ -486,6 +486,6 @@ OOVPATable D3D8LTCG_OOVPAV2[] = { // ****************************************************************** // * D3D8LTCG_OOVPA_COUNT // ****************************************************************** -#define D3D8LTCG_OOVPA_COUNT OOVPA_TABLE_COUNT(D3D8LTCG_OOVPAV2) +#define D3D8LTCG_OOVPA_COUNT XBSDB_ARRAY_SIZE(D3D8LTCG_OOVPAV2) #endif diff --git a/OOVPADatabase/D3D8_OOVPA.inl b/OOVPADatabase/D3D8_OOVPA.inl index b8fb8789..38c69ad0 100644 --- a/OOVPADatabase/D3D8_OOVPA.inl +++ b/OOVPADatabase/D3D8_OOVPA.inl @@ -427,6 +427,6 @@ OOVPATable D3D8_OOVPAV2[] = { // ****************************************************************** // * D3D8_OOVPA_COUNT // ****************************************************************** -#define D3D8_OOVPA_COUNT OOVPA_TABLE_COUNT(D3D8_OOVPAV2) +#define D3D8_OOVPA_COUNT XBSDB_ARRAY_SIZE(D3D8_OOVPAV2) #endif diff --git a/OOVPADatabase/DSound_OOVPA.inl b/OOVPADatabase/DSound_OOVPA.inl index 6f0fd923..be284f6b 100644 --- a/OOVPADatabase/DSound_OOVPA.inl +++ b/OOVPADatabase/DSound_OOVPA.inl @@ -513,6 +513,6 @@ OOVPATable DSound_OOVPAV2[] = { // ****************************************************************** // * DSound_OOVPA_COUNT // ****************************************************************** -#define DSound_OOVPA_COUNT OOVPA_TABLE_COUNT(DSound_OOVPAV2) +#define DSound_OOVPA_COUNT XBSDB_ARRAY_SIZE(DSound_OOVPAV2) #endif diff --git a/OOVPADatabase/XActEng_OOVPA.inl b/OOVPADatabase/XActEng_OOVPA.inl index 1f098e92..3b0b322d 100644 --- a/OOVPADatabase/XActEng_OOVPA.inl +++ b/OOVPADatabase/XActEng_OOVPA.inl @@ -98,6 +98,6 @@ OOVPATable XACTENG_OOVPAV2[] = { // ****************************************************************** // * XACTENG_OOVPA_COUNT // ****************************************************************** -#define XACTENG_OOVPA_COUNT OOVPA_TABLE_COUNT(XACTENG_OOVPAV2) +#define XACTENG_OOVPA_COUNT XBSDB_ARRAY_SIZE(XACTENG_OOVPAV2) #endif diff --git a/OOVPADatabase/XGraphic_OOVPA.inl b/OOVPADatabase/XGraphic_OOVPA.inl index 2a3d0b85..22c54705 100644 --- a/OOVPADatabase/XGraphic_OOVPA.inl +++ b/OOVPADatabase/XGraphic_OOVPA.inl @@ -93,6 +93,6 @@ OOVPATable XGRAPHC_OOVPAV2[] = { // ****************************************************************** // * XGRAPHC_OOVPA_COUNT // ****************************************************************** -#define XGRAPHC_OOVPA_COUNT OOVPA_TABLE_COUNT(XGRAPHC_OOVPAV2) +#define XGRAPHC_OOVPA_COUNT XBSDB_ARRAY_SIZE(XGRAPHC_OOVPAV2) #endif diff --git a/OOVPADatabase/XNet_OOVPA.inl b/OOVPADatabase/XNet_OOVPA.inl index 0672a47f..f06efe0b 100644 --- a/OOVPADatabase/XNet_OOVPA.inl +++ b/OOVPADatabase/XNet_OOVPA.inl @@ -72,6 +72,6 @@ OOVPATable XNET_OOVPAV2[] = { // ****************************************************************** // * XNET_OOVPA_COUNT // ****************************************************************** -#define XNET_OOVPA_COUNT OOVPA_TABLE_COUNT(XNET_OOVPAV2) +#define XNET_OOVPA_COUNT XBSDB_ARRAY_SIZE(XNET_OOVPAV2) #endif diff --git a/OOVPADatabase/XOnline_OOVPA.inl b/OOVPADatabase/XOnline_OOVPA.inl index db07bd4d..882c0bc5 100644 --- a/OOVPADatabase/XOnline_OOVPA.inl +++ b/OOVPADatabase/XOnline_OOVPA.inl @@ -86,6 +86,6 @@ OOVPATable XONLINES_OOVPAV2[] = { // ****************************************************************** // * XONLINES_OOVPA_COUNT // ****************************************************************** -#define XONLINES_OOVPA_COUNT OOVPA_TABLE_COUNT(XONLINES_OOVPAV2) +#define XONLINES_OOVPA_COUNT XBSDB_ARRAY_SIZE(XONLINES_OOVPAV2) #endif diff --git a/OOVPADatabase/Xapi_OOVPA.inl b/OOVPADatabase/Xapi_OOVPA.inl index 9b0d26f4..fd31700a 100644 --- a/OOVPADatabase/Xapi_OOVPA.inl +++ b/OOVPADatabase/Xapi_OOVPA.inl @@ -250,6 +250,6 @@ OOVPATable XAPILIB_OOVPAV2[] = { // ****************************************************************** // * XAPILIB_OOVPA_COUNT // ****************************************************************** -#define XAPILIB_OOVPA_COUNT OOVPA_TABLE_COUNT(XAPILIB_OOVPAV2) +#define XAPILIB_OOVPA_COUNT XBSDB_ARRAY_SIZE(XAPILIB_OOVPAV2) #endif diff --git a/XbSymbolDatabase.c b/XbSymbolDatabase.c index bce37c4e..b44ef852 100644 --- a/XbSymbolDatabase.c +++ b/XbSymbolDatabase.c @@ -148,7 +148,7 @@ SymbolDatabaseList SymbolDBList[] = { // ****************************************************************** // * SymbolDBListCount // ****************************************************************** -const unsigned int SymbolDBListCount = OOVPA_TABLE_COUNT(SymbolDBList); +const unsigned int SymbolDBListCount = XBSDB_ARRAY_SIZE(SymbolDBList); // ****************************************************************** // * XRefDataBase From 9d58008b1e69af9cac965cddd5c03b7c4e12665c Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Mon, 15 Apr 2019 19:06:38 -0500 Subject: [PATCH 5/5] clean up the comment to exclude field type Thanks to PatrickvL for finding it! --- OOVPA.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OOVPA.h b/OOVPA.h index 6b82b950..eeedd5cf 100644 --- a/OOVPA.h +++ b/OOVPA.h @@ -41,21 +41,21 @@ // ****************************************************************** typedef struct _OOVPA { - // This OOVPA field (uint08 Count) indicates the number of + // This OOVPA field, Count, indicates the number of // {Offset, Value}-pairs present in the Lovp array, // available after casting this OOVPA to LOOVPA. // (This Count INCLUDES optional leading {Offset, XREF_*-enum}- // pairs - see comment at XRefCount.) unsigned char Count; - // This OOVPA field (uint08 XRefCount) contains the number of + // This OOVPA field, XRefCount, contains the number of // {Offset, XREF_*-enum}-pairs that come before all other // {Offset, Value}-pairs. // (The {Offset, XREF_*-enum}-pairs are INCLUDED in OOVPA.Count) // (Also, see comments at XRefZero and XRefOne.) unsigned char XRefCount; - // This OOVPA field (uint16 XRefSaveIndex) contains either an + // This OOVPA field, XRefSaveIndex, contains either an // XREF_* enum value, or the XRefNoSaveIndex marker when there's // no XREF_* enum defined for this OOVPA. unsigned short XRefSaveIndex;