From 47dccbf2188b44d36e9441fddfa83b0bd0a2c01d Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 12 Jun 2018 20:02:41 -0400 Subject: [PATCH] remove silly macros --- vnr/ccutil/ccmacro.h | 26 -------- vnr/cpputil/cppcstring.h | 3 +- vnr/cpputil/cpplocale.h | 35 ---------- vnr/cpputil/cppmarshal.h | 110 ------------------------------- vnr/cpputil/cppmath.h | 25 ------- vnr/cpputil/cpppath.h | 54 --------------- vnr/cpputil/cppstring.h | 18 ----- vnr/cpputil/cpptype.h | 42 ------------ vnr/cpputil/cppunicode.h | 23 ------- vnr/texthook/host/host.cc | 4 +- vnr/vnrhook/CMakeLists.txt | 8 --- vnr/vnrhook/src/engine/engine.cc | 9 ++- vnr/vnrhook/src/engine/match.cc | 5 +- vnr/vnrhook/src/main.cc | 1 - vnr/vnrhook/src/pipe.cc | 1 - 15 files changed, 9 insertions(+), 355 deletions(-) delete mode 100644 vnr/ccutil/ccmacro.h delete mode 100644 vnr/cpputil/cpplocale.h delete mode 100644 vnr/cpputil/cppmarshal.h delete mode 100644 vnr/cpputil/cppmath.h delete mode 100644 vnr/cpputil/cpppath.h delete mode 100644 vnr/cpputil/cppstring.h delete mode 100644 vnr/cpputil/cpptype.h delete mode 100644 vnr/cpputil/cppunicode.h diff --git a/vnr/ccutil/ccmacro.h b/vnr/ccutil/ccmacro.h deleted file mode 100644 index 21be12f..0000000 --- a/vnr/ccutil/ccmacro.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef CCMACRO_H -#define CCMACRO_H - -// ccmacro.h -// 12/9/2011 jichi - -#include - -#define CONCAT_STR_NUM(_str, _num) (std::wstring(_str) + std::to_wstring(_num)).c_str() -#define CONCAT_STR_STR(_str1, _str2) (std::wstring(_str1) + std::wstring(_str2)).c_str() - -#define CC_UNUSED(_var) (void)(_var) -#define CC_NOP CC_UNUSED(0) - -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) -# define CC_LIKELY(expr) __builtin_expect(!!(expr), true) -# define CC_UNLIKELY(expr) __builtin_expect(!!(expr), false) -#else -# define CC_LIKELY(x) (x) -# define CC_UNLIKELY(x) (x) -#endif - -#define CC_MIN(x, y) ((x) < (y) ? (x) : (y)) -#define CC_MAX(x, y) ((x) < (y) ? (y) : (x)) - -#endif // CCMACRO_H diff --git a/vnr/cpputil/cppcstring.h b/vnr/cpputil/cppcstring.h index 02793a0..38fd4a9 100644 --- a/vnr/cpputil/cppcstring.h +++ b/vnr/cpputil/cppcstring.h @@ -7,7 +7,6 @@ #include // for size_t #include //#include // for std::min -#include "ccutil/ccmacro.h" // strlen @@ -60,7 +59,7 @@ inline const wchar_t *cpp_wcsnchr(const wchar_t *s, wchar_t c, size_t n) { retur #define cpp_basic_strnstr_(s, slen, r, rlen, ncmp) \ { \ while (*s && slen >= rlen) { \ - if (ncmp(s, r, CC_MIN(slen, rlen)) == 0) \ + if (ncmp(s, r, slen < rlen ? slen : rlen) == 0) \ return s; \ s++, slen--; \ } \ diff --git a/vnr/cpputil/cpplocale.h b/vnr/cpputil/cpplocale.h deleted file mode 100644 index bb36c75..0000000 --- a/vnr/cpputil/cpplocale.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef CPPLOCALE_H -#define CPPLOCALE_H - -// cpplocale.h -// 9/26/2014 jichi - -#include - -#ifdef WITHOUT_CXX_CODECVT -// http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/codecvt.html -# define BOOST_UTF8_BEGIN_NAMESPACE -# define BOOST_UTF8_END_NAMESPACE -# define BOOST_UTF8_DECL -# include -# include // WARNING: This implementation should only be included ONCE -# define CPPLOCALE_NEW_FACET_UTF8(charT) (new utf8_codecvt_facet) // charT is ignored and assumed to be wchar_t -//# include -//# define CPPLOCALE_NEW_FACET_UTF8(charT) (new utf8_codecvt_facet) -#else -# include -# define CPPLOCALE_NEW_FACET_UTF8(charT) (new std::codecvt_utf8) -#endif // WITHOUT_CXX_CODECVT - -//#include - -// See: http://stackoverflow.com/questions/20195262/how-to-read-an-utf-8-encoded-file-containing-chinese-characters-and-output-them -// The same as boost::locale::generator().generate("UTF-8"), which require linking -// See: http://en.cppreference.com/w/cpp/locale/codecvt_utf8 -// - 0x10ffff is the default maximum value. -// - std::consume_header will skip the leading encoding byte from the input. -template -inline std::locale cpp_utf8_locale(std::locale init = std::locale()) //::empty()) -{ return std::locale(init, CPPLOCALE_NEW_FACET_UTF8(charT)); } - -#endif // CPPLOCALE_H diff --git a/vnr/cpputil/cppmarshal.h b/vnr/cpputil/cppmarshal.h deleted file mode 100644 index 8b81639..0000000 --- a/vnr/cpputil/cppmarshal.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef CPPMARSHAL_H -#define CPPMARSHAL_H - -// cppmarshal.h -// 10/12/2014 jichi -// -// Functions are by default big-endian, the same as memory layout. -#include "cpputil/cppcstring.h" -#include "cpputil/cpptype.h" -#include - -/* Read */ - -// Read number - -template -inline const byteT *cpp_marshal_getval(const byteT *p, valT *v) -{ *v = *reinterpret_cast(p); return p + sizeof(valT); } - -// Read pointer - -template \ -inline const byteT *cpp_marshal_getptr(const byteT *p, ptrT v) -{ return cpp_marshal_getval(p, reinterpret_cast(v)); } - -// Read string - -template -inline const byteT *cpp_marshal_getstr(const byteT *p, charT *s) -{ - size_t n = cpp_basic_strlen(p); - ::memcpy(s, p, n + 1); // including '\0' - return p + n + 1; -} - -template -inline const byteT *cpp_marshal_getnstr(const byteT *p, charT *s, size_t n) -{ - if (n = cpp_basic_strnlen(p, n)) - ::memcpy(s, p, n); // including '\0' - s[n] = 0; - return p + n + 1; -} - -/* Write */ - -// Write number - -template -inline byteT *cpp_marshal_putval(byteT *p, valT v) -{ *reinterpret_cast(p) = v; return p + sizeof(valT); } - -// Write pointer - -template \ -inline byteT *cpp_marshal_putptr(byteT *p, ptrT v) -{ return cpp_marshal_putval(p, reinterpret_cast(v)); } - -// Write string - -template -inline byteT *cpp_marshal_putstr(byteT *p, charT *s) -{ - size_t n = cpp_basic_strlen(s); - ::memcpy(p, s, n + 1); // including '\0' - return p + n + 1; -} - -template -inline byteT *cpp_marshal_putstr(byteT *p, charT *s, size_t n) -{ - if (n = cpp_basic_strnlen(s, n)) - ::memcpy(p, s, n); // including '\0' - s[n] = 0; - return p + n + 1; -} - -/* Expansion */ - -#define CPP_DECLARE_MARSHAL_GETVAL(type) \ - template \ - inline const byteT *cpp_marshal_get##type(const byteT *p, cpp_##type *v) { return cpp_marshal_getval(p, v); } - -#define CPP_DECLARE_MARSHAL_PUTVAL(type) \ - template \ - inline byteT *cpp_marshal_put##type(byteT *p, cpp_##type v) { return cpp_marshal_putval(p, v); } - -CPP_DECLARE_MARSHAL_PUTVAL(float) -CPP_DECLARE_MARSHAL_PUTVAL(double) -CPP_DECLARE_MARSHAL_GETVAL(float) -CPP_DECLARE_MARSHAL_GETVAL(double) -CPP_DECLARE_MARSHAL_GETVAL(int) -CPP_DECLARE_MARSHAL_GETVAL(int8) -CPP_DECLARE_MARSHAL_GETVAL(int32) -CPP_DECLARE_MARSHAL_GETVAL(int64) -CPP_DECLARE_MARSHAL_GETVAL(uint) -CPP_DECLARE_MARSHAL_GETVAL(uint8) -CPP_DECLARE_MARSHAL_GETVAL(uint32) -CPP_DECLARE_MARSHAL_GETVAL(uint64) - -CPP_DECLARE_MARSHAL_PUTVAL(int) -CPP_DECLARE_MARSHAL_PUTVAL(int8) -CPP_DECLARE_MARSHAL_PUTVAL(int32) -CPP_DECLARE_MARSHAL_PUTVAL(int64) -CPP_DECLARE_MARSHAL_PUTVAL(uint) -CPP_DECLARE_MARSHAL_PUTVAL(uint8) -CPP_DECLARE_MARSHAL_PUTVAL(uint32) -CPP_DECLARE_MARSHAL_PUTVAL(uint64) - -#endif // CPPMARSHAL_H diff --git a/vnr/cpputil/cppmath.h b/vnr/cpputil/cppmath.h deleted file mode 100644 index 2ed2296..0000000 --- a/vnr/cpputil/cppmath.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef CPPMATH_H -#define CPPMATH_H - -// cppmacro.h -// 10/12/2014 jichi -#include - -// The same as qMin -template -inline const T &cpp_min(const T &a, const T &b) { return (a < b) ? a : b; } - -// The same as qMax -template -inline const T &cpp_max(const T &a, const T &b) { return (a < b) ? b : a; } - -// The same as qBound -template -inline const T &cpp_bound(const T &min, const T &val, const T &max) -{ return cpp_max(min, cpp_min(max, val)); } - -// The same as qFuzzyCompare -inline bool cpp_fuzzy_compare(float p1, float p2) -{ return (abs(p1 - p2) <= 0.00001f * cpp_min(abs(p1), abs(p2))); } - -#endif // CPPMATH_H diff --git a/vnr/cpputil/cpppath.h b/vnr/cpputil/cpppath.h deleted file mode 100644 index e812a9d..0000000 --- a/vnr/cpputil/cpppath.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef CPPPATH_H -#define CPPPATH_H - -// cpppath.h -// 5/7/2014 jichi - -#include // for size_t - -enum : char { cpp_pathsep_unix = '/' , cpp_pathsep_win = '\\' }; - -// basename - -template -inline const charT *cpp_basic_basename(const charT *s) -{ - const charT *p = s; - //if (s) // not checked - for (; *s; s++) - if (*s == cpp_pathsep_unix || *s == cpp_pathsep_win) - p = s + 1; - return p; -} - -//if (const char *r = ::strrchr(s, pathsep)) -// return r + 1; // skip the path seperator -//else -// return s; -inline const char *cpp_basename(const char *s) { return cpp_basic_basename(s); } - -//if (const wchar_t *r = ::wcsrchr(s, pathsep)) -// return r + 1; // skip the path seperator -//else -// return s; -inline const wchar_t *cpp_wbasename(const wchar_t *s) { return cpp_basic_basename(s); } - -// dirmame - -/// Return the length so that s[len] == pathsep -template -inline size_t cpp_basic_dirlen(const charT *s) -{ - const charT *p = s, - *t = s; - //if (s) // not checked - for (; *s; s++) - if (*s == cpp_pathsep_unix || *s == cpp_pathsep_win) - p = s + 1; - return p - t; -} - -inline size_t cpp_wdirlen(const char *s) { return cpp_basic_dirlen(s); } -inline size_t cpp_wdirlen(const wchar_t *s) { return cpp_basic_dirlen(s); } - -#endif // CPPPATH_H diff --git a/vnr/cpputil/cppstring.h b/vnr/cpputil/cppstring.h deleted file mode 100644 index 6c0e67b..0000000 --- a/vnr/cpputil/cppstring.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef CPPSTRING_H -#define CPPSTRING_H - -// cppstring.h -// 10/12/2014 jichi - -/#include - -// Initializers - -template -inline std::basic_string cpp_basic_string_of(const std::string &s) -{ return std::basic_string(s.begin(), s.end()); } - -inline std::wstring cpp_wstring_of(const std::string &s) -{ return std::wstring(s.begin(), s.end()); } - -#endif // CPPSTRING_H diff --git a/vnr/cpputil/cpptype.h b/vnr/cpputil/cpptype.h deleted file mode 100644 index cc381ae..0000000 --- a/vnr/cpputil/cpptype.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef CPPTYPE_H -#define CPPTYPE_H - -// cpptype.h -// 10/12/2014 jichi -#include - -// Platform-dependent - -typedef char cpp_char; -typedef unsigned char cpp_uchar; - -typedef short cpp_short; -typedef unsigned short cpp_ushort; - -typedef int cpp_int; -typedef unsigned int cpp_uint; - -typedef long cpp_long; -typedef unsigned long cpp_ulong; - -typedef long long cpp_llong; -typedef unsigned long long cpp_ullong; - -typedef float cpp_float; -typedef double cpp_double; - -// Platform-independent - -typedef int8_t cpp_int8; -typedef uint8_t cpp_uint8; - -typedef cpp_int8 cpp_byte; -typedef cpp_uint8 cpp_ubyte; - -typedef int32_t cpp_int32; -typedef uint32_t cpp_uint32; - -typedef int64_t cpp_int64; -typedef uint64_t cpp_uint64; - -#endif // CPPTYPE_H diff --git a/vnr/cpputil/cppunicode.h b/vnr/cpputil/cppunicode.h deleted file mode 100644 index e874c38..0000000 --- a/vnr/cpputil/cppunicode.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef CPPUNICODE_H -#define CPPUNICODE_H - -#include -typedef std::basic_string, std::allocator > cpp_u16string; -typedef std::basic_string, std::allocator > cpp_u32string; - -// -#if defined(_FSTREAM_) || defined(_LIBCPP_FSTREAM) || defined(_GLIBCXX_FSTREAM) -typedef std::basic_ifstream > cpp_u16ifstream; -typedef std::basic_ifstream > cpp_u32ifstream; - -typedef std::basic_ofstream > cpp_u16ofstream; -typedef std::basic_ofstream > cpp_u32ofstream; - -typedef std::basic_fstream > cpp_u16fstream; -typedef std::basic_fstream > cpp_u32fstream; -#endif // - -inline char16_t cpp_u32low(char32_t c) { return c; } -inline char16_t cpp_u32high(char32_t c) { return c >> 16; } - -#endif // CPPUNICODE_H diff --git a/vnr/texthook/host/host.cc b/vnr/texthook/host/host.cc index 80cae9a..d263b5f 100644 --- a/vnr/texthook/host/host.cc +++ b/vnr/texthook/host/host.cc @@ -16,8 +16,8 @@ #include "vnrhook/include/defs.h" #include "vnrhook/include/types.h" #include "ithsys/ithsys.h" -#include "ccutil/ccmacro.h" #include +#include #include "extensions/Extensions.h" #define DEBUG "vnrhost/host.cc" @@ -145,7 +145,7 @@ IHFSERVICE bool IHFAPI InjectProcessById(DWORD processId, DWORD timeout) success = false; } - CloseHandle(CreateMutexW(nullptr, FALSE, CONCAT_STR_NUM(ITH_HOOKMAN_MUTEX_, processId))); + CloseHandle(CreateMutexW(nullptr, FALSE, (ITH_HOOKMAN_MUTEX_ + std::to_wstring(processId)).c_str())); if (GetLastError() == ERROR_ALREADY_EXISTS) { man->AddConsoleOutput(L"already locked"); diff --git a/vnr/vnrhook/CMakeLists.txt b/vnr/vnrhook/CMakeLists.txt index b21d902..514571c 100644 --- a/vnr/vnrhook/CMakeLists.txt +++ b/vnr/vnrhook/CMakeLists.txt @@ -43,14 +43,6 @@ set(vnrhook_src src/util/growl.h src/util/util.cc src/util/util.h - ${PROJECT_SOURCE_DIR}/ccutil/ccmacro.h - ${PROJECT_SOURCE_DIR}/cpputil/cpplocale.h - ${PROJECT_SOURCE_DIR}/cpputil/cppmarshal.h - ${PROJECT_SOURCE_DIR}/cpputil/cppmath.h - ${PROJECT_SOURCE_DIR}/cpputil/cpppath.h - ${PROJECT_SOURCE_DIR}/cpputil/cppstring.h - ${PROJECT_SOURCE_DIR}/cpputil/cpptype.h - ${PROJECT_SOURCE_DIR}/cpputil/cppunicode.h ${PROJECT_SOURCE_DIR}/disasm/disasm.cc ${PROJECT_SOURCE_DIR}/memdbg/memdbg.h ${PROJECT_SOURCE_DIR}/memdbg/memsearch.cc diff --git a/vnr/vnrhook/src/engine/engine.cc b/vnr/vnrhook/src/engine/engine.cc index c41b2f9..5e5506f 100644 --- a/vnr/vnrhook/src/engine/engine.cc +++ b/vnr/vnrhook/src/engine/engine.cc @@ -20,7 +20,6 @@ #include "ntinspect/ntinspect.h" #include "disasm/disasm.h" #include "cpputil/cppcstring.h" -#include "ccutil/ccmacro.h" #include "mono/monoobject.h" //#include #include @@ -4345,7 +4344,7 @@ rUGP hook: ********************************************************************************************/ void SpecialHookRUGP1(DWORD esp_base, HookParam *hp, BYTE, DWORD *data, DWORD *split, DWORD *len) { - CC_UNUSED(split); + //CC_UNUSED(split); DWORD *stack = (DWORD *)esp_base; DWORD i, val; for (i = 0; i < 4; i++) { @@ -6735,7 +6734,7 @@ bool InsertMalieHook2() // jichi 8/20/2013: Change return type to boolean */ void SpecialHookMalie2(DWORD esp_base, HookParam *, BYTE, DWORD *data, DWORD *split, DWORD *len) { - CC_UNUSED(data); + //CC_UNUSED(data); //*len = GetHookDataLength(*hp, esp_base, (DWORD)data); *len = 2; @@ -6909,7 +6908,7 @@ LPCWSTR _Malie3GetEOL(LPCWSTR p) void SpecialHookMalie3(DWORD esp_base, HookParam *, BYTE, DWORD *data, DWORD *split, DWORD *len) { - CC_UNUSED(split); + //CC_UNUSED(split); DWORD ecx = regof(ecx, esp_base), // *(DWORD *)(esp_base + pusha_ecx_off - 4), edx = regof(edx, esp_base); // *(DWORD *)(esp_base + pusha_edx_off - 4); //*data = ecx + edx*2; // [ecx+edx*2]; @@ -7171,7 +7170,7 @@ bool InsertEMEHook() } static void SpecialRunrunEngine(DWORD esp_base, HookParam *, BYTE, DWORD *data, DWORD *split, DWORD *len) { - CC_UNUSED(split); + //CC_UNUSED(split); DWORD eax = regof(eax, esp_base), // *(DWORD *)(esp_base - 0x8), edx = regof(edx, esp_base); // *(DWORD *)(esp_base - 0x10); DWORD addr = eax + edx; // eax + edx diff --git a/vnr/vnrhook/src/engine/match.cc b/vnr/vnrhook/src/engine/match.cc index 619cf3f..1a8dd12 100644 --- a/vnr/vnrhook/src/engine/match.cc +++ b/vnr/vnrhook/src/engine/match.cc @@ -15,7 +15,6 @@ #include "src/main.h" #include "src/except.h" #include "ithsys/ithsys.h" -#include "ccutil/ccmacro.h" //#define ConsoleOutput(...) (void)0 // jichi 8/18/2013: I don't need ConsoleOutput @@ -886,9 +885,9 @@ bool DetermineEngineType() // HANDLE hijackThread; -void hijackThreadProc(LPVOID lpThreadParameter) +void hijackThreadProc(LPVOID unused) { - CC_UNUSED(lpThreadParameter); + //CC_UNUSED(lpThreadParameter); //static bool done = false; //if (done) diff --git a/vnr/vnrhook/src/main.cc b/vnr/vnrhook/src/main.cc index 71b0c1b..ea688c9 100644 --- a/vnr/vnrhook/src/main.cc +++ b/vnr/vnrhook/src/main.cc @@ -17,7 +17,6 @@ #include "include/const.h" #include "include/defs.h" #include "ithsys/ithsys.h" -#include "ccutil/ccmacro.h" #include "util/util.h" #include // for swprintf //#include "ntinspect/ntinspect.h" diff --git a/vnr/vnrhook/src/pipe.cc b/vnr/vnrhook/src/pipe.cc index 03a97af..a92794f 100644 --- a/vnr/vnrhook/src/pipe.cc +++ b/vnr/vnrhook/src/pipe.cc @@ -14,7 +14,6 @@ #include "include/defs.h" #include "src/util/growl.h" #include "ithsys/ithsys.h" -#include "ccutil/ccmacro.h" #include // for swprintf HANDLE hookPipe;