Skip to content

Commit 940dcb3

Browse files
committed
thcrap: Add more plugin functions
1 parent 4e4da13 commit 940dcb3

File tree

1 file changed

+55
-23
lines changed

1 file changed

+55
-23
lines changed

thcrap/src/plugin.cpp

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include <time.h>
1515
#include <process.h>
1616

17+
#undef strlen
18+
#undef wcslen
19+
#undef strcmp
20+
1721
#if TH_X86
1822
extern "C" {
1923
// None of these signatures are accurate,
@@ -73,11 +77,21 @@ extern uint64_t __cdecl _aullshr(uint64_t, uint8_t);
7377

7478
using math_1arg_ptr = double(__cdecl*)(double);
7579
using math_2arg_ptr = double(__cdecl*)(double, double);
80+
using math_2arg_ptr_alt = double(__cdecl*)(double, int);
7681
using math_3arg_ptr = double(__cdecl*)(double, double, double);
7782
using math_remquo_ptr = double(__cdecl*)(double, double, int*);
7883
using memchr_ptr = const void*(__cdecl*)(const void*, int, size_t);
84+
using wmemchr_ptr = const wchar_t*(__cdecl*)(const wchar_t*, wchar_t, size_t);
7985
using strchr_ptr = const char*(__cdecl*)(const char*, int);
8086
using strstr_ptr = const char*(__cdecl*)(const char*, const char*);
87+
using strpbrk_ptr = const char*(__cdecl*)(const char*, const char*);
88+
using wcschr_ptr = const wchar_t*(__cdecl*)(const wchar_t*, wchar_t);
89+
using wcsstr_ptr = const wchar_t*(__cdecl*)(const wchar_t*, const wchar_t*);
90+
using wcspbrk_ptr = const wchar_t*(__cdecl*)(const wchar_t*, const wchar_t*);
91+
using swprintf_ptr = int(__cdecl*)(wchar_t*, const wchar_t*, ...);
92+
using vswprintf_ptr = int(__cdecl*)(wchar_t*, const wchar_t*, va_list);
93+
using snwprintf_ptr = int(__cdecl*)(wchar_t*, size_t, const wchar_t*, ...);
94+
using vsnwprintf_ptr = int(__cdecl*)(wchar_t*, size_t, const wchar_t*, va_list);
8195

8296
// Pointer casting is used to select the C style overload
8397
static std::unordered_map<std::string_view, uintptr_t> funcs = {
@@ -96,39 +110,55 @@ static std::unordered_map<std::string_view, uintptr_t> funcs = {
96110
// Memory functions
97111
{ "th_memcpy", (uintptr_t)&memcpy },
98112
{ "th_memmove", (uintptr_t)&memmove },
99-
{ "th_memcmp", (uintptr_t)&memcmp },
113+
{ "th_memcmp", (uintptr_t)&memcmp }, { "th_wmemcmp", (uintptr_t)&wmemcmp },
100114
{ "th_memset", (uintptr_t)&memset },
101115
{ "th_memccpy", (uintptr_t)&memccpy },
102-
{ "th_memchr", (uintptr_t)static_cast<memchr_ptr>(&memchr) },
103-
{ "th_strdup", (uintptr_t)&strdup },
116+
{ "th_memchr", (uintptr_t)static_cast<memchr_ptr>(&memchr) }, { "th_wmemchr", (uintptr_t)static_cast<wmemchr_ptr>(&wmemchr) },
117+
{ "th_strdup", (uintptr_t)&strdup }, { "th_wcsdup", (uintptr_t)&_wcsdup },
104118
{ "th_strndup", (uintptr_t)&strndup },
105119
{ "th_strdup_size", (uintptr_t)&strdup_size },
106120

107121
// String functions
108-
{ "th_strcmp", (uintptr_t)&strcmp },
109-
{ "th_strncmp", (uintptr_t)&strncmp },
110-
{ "th_stricmp", (uintptr_t)&stricmp },
111-
{ "th_strnicmp", (uintptr_t)&strnicmp },
112-
{ "th_strcpy", (uintptr_t)&strcpy },
113-
{ "th_strncpy", (uintptr_t)&strncpy },
114-
{ "th_strcat", (uintptr_t)&strcat },
115-
{ "th_strncat", (uintptr_t)&strncat },
116-
{ "th_strlen", (uintptr_t)&strlen },
117-
{ "th_strnlen_s", (uintptr_t)&strnlen_s },
118-
{ "th_strchr", (uintptr_t)static_cast<strchr_ptr>(&strchr) },
119-
{ "th_strrchr", (uintptr_t)static_cast<strchr_ptr>(&strrchr) },
120-
{ "th_strstr", (uintptr_t)static_cast<strstr_ptr>(&strstr) },
121-
{ "th_strrev", (uintptr_t)&_strrev },
122+
{ "th_strcmp", (uintptr_t)&strcmp }, { "th_wcscmp", (uintptr_t)&wcscmp },
123+
{ "th_strncmp", (uintptr_t)&strncmp }, { "th_wcsncmp", (uintptr_t)&wcsncmp },
124+
{ "th_stricmp", (uintptr_t)&stricmp }, { "th_wcsicmp", (uintptr_t)&wcsicmp },
125+
{ "th_strnicmp", (uintptr_t)&strnicmp }, { "th_wcsnicmp", (uintptr_t)&_wcsnicmp },
126+
{ "th_strcpy", (uintptr_t)&strcpy }, { "th_wcscpy", (uintptr_t)&wcscpy },
127+
{ "th_strncpy", (uintptr_t)&strncpy }, { "th_wcsncpy", (uintptr_t)&wcsncpy },
128+
{ "th_strcat", (uintptr_t)&strcat }, { "th_wcscat", (uintptr_t)&wcscat },
129+
{ "th_strncat", (uintptr_t)&strncat }, { "th_wcsncat", (uintptr_t)&wcsncat },
130+
{ "th_strlen", (uintptr_t)&strlen }, { "th_wcslen", (uintptr_t)&wcslen },
131+
{ "th_strnlen_s", (uintptr_t)&strnlen_s }, { "th_wcsnlen_s", (uintptr_t)&wcsnlen_s },
132+
{ "th_strchr", (uintptr_t)static_cast<strchr_ptr>(&strchr) }, { "th_wcschr", (uintptr_t)static_cast<wcschr_ptr>(&wcschr) },
133+
{ "th_strrchr", (uintptr_t)static_cast<strchr_ptr>(&strrchr) }, { "th_wcsrchr", (uintptr_t)static_cast<wcschr_ptr>(&wcsrchr) },
134+
{ "th_strstr", (uintptr_t)static_cast<strstr_ptr>(&strstr) }, { "th_wcsstr", (uintptr_t)static_cast<wcsstr_ptr>(&wcsstr) },
135+
{ "th_strspn", (uintptr_t)&strspn }, { "th_wcsspn", (uintptr_t)&wcsspn },
136+
{ "th_strcspn", (uintptr_t)&strcspn }, { "th_wcscspn", (uintptr_t)&wcscspn },
137+
{ "th_strpbrk", (uintptr_t)static_cast<strpbrk_ptr>(&strpbrk) }, { "th_wcspbrk", (uintptr_t)static_cast<wcspbrk_ptr>(&wcspbrk) },
138+
{ "th_strrev", (uintptr_t)&_strrev }, { "th_wcsrev", (uintptr_t)&_wcsrev },
139+
{ "th_strtol", (uintptr_t)&strtol }, { "th_wcstol", (uintptr_t)&wcstol },
140+
{ "th_strtoul", (uintptr_t)&strtoul }, { "th_wcstoul", (uintptr_t)&wcstoul },
141+
{ "th_strtoll", (uintptr_t)&strtoll }, { "th_wcstoll", (uintptr_t)&wcstoll },
142+
{ "th_strtoull", (uintptr_t)&strtoull }, { "th_wcstoull", (uintptr_t)&wcstoull },
143+
{ "th_strtof", (uintptr_t)&strtof }, { "th_wcstof", (uintptr_t)&wcstof },
144+
{ "th_strtod", (uintptr_t)&strtod }, { "th_wcstod", (uintptr_t)&wcstod },
122145

123146
// Formatting functions
124-
{ "th_sprintf", (uintptr_t)&sprintf },
125-
{ "th_vsprintf", (uintptr_t)&vsprintf },
126-
{ "th_snprintf", (uintptr_t)&snprintf },
127-
{ "th_vsnprintf", (uintptr_t)&vsnprintf },
128-
{ "th_sscanf", (uintptr_t)&sscanf },
129-
{ "th_vsscanf", (uintptr_t)&vsscanf },
147+
{ "th_sprintf", (uintptr_t)&sprintf }, //{ "th_swprintf", (uintptr_t)&_swprintf },
148+
{ "th_vsprintf", (uintptr_t)&vsprintf }, //{ "th_vswprintf", (uintptr_t)&_vswprintf },
149+
{ "th_snprintf", (uintptr_t)&snprintf }, //{ "th_snwprintf", (uintptr_t)static_cast<snwprintf_ptr>(&swprintf) },
150+
{ "th_vsnprintf", (uintptr_t)&vsnprintf }, //{ "th_vsnwprintf", (uintptr_t)static_cast<vsnwprintf_ptr>(&vswprintf) },
151+
{ "th_sscanf", (uintptr_t)&sscanf }, { "th_swscanf", (uintptr_t)&swscanf },
152+
{ "th_vsscanf", (uintptr_t)&vsscanf }, { "th_vswscanf", (uintptr_t)&vswscanf },
130153
{ "th_strftime", (uintptr_t)&strftime },
131154

155+
// Console IO functions
156+
{ "th_printf", (uintptr_t)&printf }, { "th_wprintf", (uintptr_t)&wprintf },
157+
{ "th_vprintf", (uintptr_t)&vprintf }, { "th_vwprintf", (uintptr_t)&vwprintf },
158+
{ "th_puts", (uintptr_t)&puts },
159+
{ "th_getchar", (uintptr_t)&getchar }, { "th_getwchar", (uintptr_t)&getwchar },
160+
{ "th_putchar", (uintptr_t)&putchar }, { "th_putwchar", (uintptr_t)&putwchar },
161+
132162
// Math functions
133163
{ "th_fabsf", (uintptr_t)&fabsf }, { "th_fabs", (uintptr_t)static_cast<math_1arg_ptr>(&fabs) },
134164
{ "th_fmodf", (uintptr_t)&fmodf }, { "th_fmod", (uintptr_t)static_cast<math_2arg_ptr>(&fmod) },
@@ -139,6 +169,7 @@ static std::unordered_map<std::string_view, uintptr_t> funcs = {
139169
{ "th_fminf", (uintptr_t)&fminf }, { "th_fmin", (uintptr_t)static_cast<math_2arg_ptr>(&fmin) },
140170
{ "th_fdimf", (uintptr_t)&fdimf }, { "th_fdim", (uintptr_t)static_cast<math_2arg_ptr>(&fdim) },
141171
{ "th_expf", (uintptr_t)&expf }, { "th_exp", (uintptr_t)static_cast<math_1arg_ptr>(&exp) },
172+
{ "th_exp2f", (uintptr_t)&exp2f }, { "th_exp2", (uintptr_t)static_cast<math_1arg_ptr>(&exp2) },
142173
{ "th_logf", (uintptr_t)&logf }, { "th_log", (uintptr_t)static_cast<math_1arg_ptr>(&log) },
143174
{ "th_log10f", (uintptr_t)&log10f }, { "th_log10", (uintptr_t)static_cast<math_1arg_ptr>(&log10) },
144175
{ "th_log2f", (uintptr_t)&log2f }, { "th_log2", (uintptr_t)static_cast<math_1arg_ptr>(&log2) },
@@ -157,6 +188,7 @@ static std::unordered_map<std::string_view, uintptr_t> funcs = {
157188
{ "th_truncf", (uintptr_t)&truncf }, { "th_trunc", (uintptr_t)static_cast<math_1arg_ptr>(&trunc) },
158189
{ "th_roundf", (uintptr_t)&roundf }, { "th_round", (uintptr_t)static_cast<math_1arg_ptr>(&round) },
159190
{ "th_nearbyintf", (uintptr_t)&nearbyintf }, { "th_nearbyint", (uintptr_t)static_cast<math_1arg_ptr>(&nearbyint) },
191+
{ "th_ldexpf", (uintptr_t)&ldexpf }, { "th_ldexp", (uintptr_t)static_cast<math_2arg_ptr_alt>(&ldexp) },
160192

161193
#if TH_X86
162194
// Various compiler intrinsics

0 commit comments

Comments
 (0)