Skip to content

Commit

Permalink
windows: Explicitly use unicode APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Jan 6, 2025
1 parent b7a3752 commit 58c852c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 30 deletions.
7 changes: 3 additions & 4 deletions gum/backend-windows/gumprocess-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <intrin.h>
#include <psapi.h>
#include <tchar.h>
#include <tlhelp32.h>

#ifndef _MSC_VER
Expand Down Expand Up @@ -282,7 +281,7 @@ gum_windows_get_thread_details (DWORD thread_id,
if (g_once_init_enter (&initialized))
{
get_thread_description = (GumGetThreadDescriptionFunc) GetProcAddress (
GetModuleHandle (_T ("kernel32.dll")),
GetModuleHandleW (L"kernel32.dll"),
"GetThreadDescription");

desired_access = THREAD_GET_CONTEXT | THREAD_SUSPEND_RESUME;
Expand Down Expand Up @@ -537,7 +536,7 @@ gum_thread_try_get_ranges (GumMemoryRange * ranges,
if (g_once_init_enter (&initialized))
{
get_stack_limits = (GumGetCurrentThreadStackLimitsFunc) GetProcAddress (
GetModuleHandle (_T ("kernel32.dll")),
GetModuleHandleW (L"kernel32.dll"),
"GetCurrentThreadStackLimits");

g_once_init_leave (&initialized, TRUE);
Expand Down Expand Up @@ -891,7 +890,7 @@ gum_windows_cpu_type_from_pid (guint pid,
{
HMODULE kernel32;

kernel32 = GetModuleHandle (_T ("kernel32.dll"));
kernel32 = GetModuleHandleW (L"kernel32.dll");

is_wow64_process = (GumIsWow64ProcessFunc)
GetProcAddress (kernel32, "IsWow64Process");
Expand Down
11 changes: 5 additions & 6 deletions gum/backend-x86/gumstalker-x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
# define VC_EXTRALEAN
# include <windows.h>
# include <psapi.h>
# include <tchar.h>
#endif
#ifdef HAVE_LINUX
# include <sys/syscall.h>
Expand Down Expand Up @@ -974,8 +973,8 @@ gum_stalker_init (GumStalker * self)
guint8 * p;
GArray * impls;

ntmod = GetModuleHandle (_T ("ntdll.dll"));
usermod = GetModuleHandle (_T ("user32.dll"));
ntmod = GetModuleHandleW (L"ntdll.dll");
usermod = GetModuleHandleW (L"user32.dll");
g_assert (ntmod != NULL && usermod != NULL);

success = GetModuleInformation (GetCurrentProcess (), usermod,
Expand Down Expand Up @@ -1014,9 +1013,9 @@ gum_stalker_init (GumStalker * self)
self->wow_transition_impls = impls;
gum_collect_export_by_handle (impls, ntmod, "Wow64Transition");
gum_collect_export_by_handle (impls, usermod, "Wow64Transition");
gum_collect_export (impls, _T ("kernel32.dll"), "Wow64Transition");
gum_collect_export (impls, _T ("kernelbase.dll"), "Wow64Transition");
gum_collect_export (impls, _T ("win32u.dll"), "Wow64Transition");
gum_collect_export (impls, L"kernel32.dll", "Wow64Transition");
gum_collect_export (impls, L"kernelbase.dll", "Wow64Transition");
gum_collect_export (impls, L"win32u.dll", "Wow64Transition");
}
# endif
#endif
Expand Down
12 changes: 3 additions & 9 deletions libs/gum/prof/gumbusycyclesampler-windows.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2023 Ole André Vadla Ravnås <oleavr@nowsecure.com>
* Copyright (C) 2008-2024 Ole André Vadla Ravnås <oleavr@nowsecure.com>
* Copyright (C) 2008 Christian Berentsen <jc.berentsen@gmail.com>
*
* Licence: wxWindows Library Licence, Version 3.1
Expand All @@ -13,7 +13,6 @@
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <windows.h>
#include <tchar.h>

typedef BOOL (WINAPI * QueryThreadCycleTimeFunc) (HANDLE ThreadHandle,
PULONG64 CycleTime);
Expand Down Expand Up @@ -53,13 +52,8 @@ gum_busy_cycle_sampler_iface_init (gpointer g_iface,
static void
gum_busy_cycle_sampler_init (GumBusyCycleSampler * self)
{
HMODULE mod;

mod = GetModuleHandle (_T ("kernel32.dll"));
g_assert (mod != NULL);

self->query_thread_cycle_time =
(QueryThreadCycleTimeFunc) GetProcAddress (mod, "QueryThreadCycleTime");
self->query_thread_cycle_time = (QueryThreadCycleTimeFunc) GetProcAddress (
GetModuleHandleW (L"kernel32.dll"), "QueryThreadCycleTime");
}

GumSampler *
Expand Down
1 change: 0 additions & 1 deletion tests/core/arch-x86/stalker-x86-fixture.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#ifdef HAVE_WINDOWS
# define VC_EXTRALEAN
# include <windows.h>
# include <tchar.h>
#endif
#ifdef HAVE_LINUX
# include <glib-unix.h>
Expand Down
17 changes: 9 additions & 8 deletions tests/core/arch-x86/stalker-x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -2673,7 +2673,7 @@ typedef void (* TestWindowMessageHandler) (TestWindow * window,

struct _TestWindow
{
LPTSTR klass;
ATOM klass;
HWND handle;
GumStalker * stalker;

Expand Down Expand Up @@ -2803,25 +2803,25 @@ static TestWindow *
create_test_window (GumStalker * stalker)
{
TestWindow * window;
WNDCLASS wc = { 0, };
WNDCLASSW wc = { 0, };

window = g_slice_new (TestWindow);

window->stalker = stalker;

wc.lpfnWndProc = test_window_proc;
wc.hInstance = GetModuleHandle (NULL);
wc.lpszClassName = _T ("GumTestWindowClass");
window->klass = (LPTSTR) GSIZE_TO_POINTER (RegisterClass (&wc));
g_assert_nonnull (window->klass);
wc.lpszClassName = L"GumTestWindowClass";
window->klass = RegisterClassW (&wc);
g_assert_cmpuint (window->klass, !=, 0);

#ifdef _MSC_VER
# pragma warning (push)
# pragma warning (disable: 4306)
#endif
window->handle = CreateWindow (window->klass, _T ("GumTestWindow"),
window->handle = CreateWindowW ((LPCWSTR) window->klass, L"GumTestWindow",
WS_CAPTION, 10, 10, 320, 240, HWND_MESSAGE, NULL,
GetModuleHandle (NULL), NULL);
GetModuleHandleW (NULL), NULL);
#ifdef _MSC_VER
# pragma warning (pop)
#endif
Expand All @@ -2836,7 +2836,8 @@ create_test_window (GumStalker * stalker)
static void
destroy_test_window (TestWindow * window)
{
g_assert_true (UnregisterClass (window->klass, GetModuleHandle (NULL)));
g_assert_true (UnregisterClassW ((LPCWSTR) window->klass,
GetModuleHandleW (NULL)));

g_slice_free (TestWindow, window);
}
Expand Down
1 change: 0 additions & 1 deletion tests/gumjs/script-fixture.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
# define WIN32_LEAN_AND_MEAN
# endif
# include <intrin.h>
# include <tchar.h>
# include <windows.h>
# include <winsock2.h>
# include <ws2tcpip.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/gumjs/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -5872,7 +5872,7 @@ TESTCASE (module_export_can_be_found_by_name)
gpointer actual_address;
char actual_address_str[32];

mod = GetModuleHandle (_T ("kernel32.dll"));
mod = GetModuleHandleW (L"kernel32.dll");
g_assert_nonnull (mod);
actual_address = GetProcAddress (mod, "Sleep");
g_assert_nonnull (actual_address);
Expand Down

0 comments on commit 58c852c

Please sign in to comment.