Apply clang-format code style to all source files

This commit is contained in:
icex2
2019-10-20 00:50:40 +02:00
parent c600e1a423
commit c3bc8782f4
401 changed files with 13844 additions and 11361 deletions
+23 -21
View File
@@ -1,8 +1,8 @@
#include <windows.h>
#include <ntdef.h>
#include <devioctl.h>
#include <ntddser.h>
#include <ntdef.h>
#include <stdbool.h>
#include <stdint.h>
@@ -38,7 +38,7 @@ void com4_init(void)
ac_io_emu_init(&com4_ac_io_emu, L"COM4");
ac_io_emu_hdxs_init(&com4_hdxs, &com4_ac_io_emu);
for (i = 0 ; i < lengthof(com4_icca) ; i++) {
for (i = 0; i < lengthof(com4_icca); i++) {
ac_io_emu_icca_init(&com4_icca[i], &com4_ac_io_emu, i);
}
}
@@ -48,7 +48,8 @@ void com4_fini(void)
ac_io_emu_fini(&com4_ac_io_emu);
}
HRESULT com4_dispatch_irp(struct irp *irp)
HRESULT
com4_dispatch_irp(struct irp *irp)
{
const struct ac_io_message *msg;
HRESULT hr;
@@ -69,36 +70,37 @@ HRESULT com4_dispatch_irp(struct irp *irp)
msg = ac_io_emu_request_peek(&com4_ac_io_emu);
switch (msg->addr) {
case 0:
ac_io_emu_cmd_assign_addrs(&com4_ac_io_emu, msg, 3);
case 0:
ac_io_emu_cmd_assign_addrs(&com4_ac_io_emu, msg, 3);
break;
break;
case 1:
ac_io_emu_icca_dispatch_request(&com4_icca[0], msg);
case 1:
ac_io_emu_icca_dispatch_request(&com4_icca[0], msg);
break;
break;
case 2:
ac_io_emu_icca_dispatch_request(&com4_icca[1], msg);
case 2:
ac_io_emu_icca_dispatch_request(&com4_icca[1], msg);
break;
break;
case 3:
ac_io_emu_hdxs_dispatch_request(&com4_hdxs, msg);
case 3:
ac_io_emu_hdxs_dispatch_request(&com4_hdxs, msg);
break;
break;
case AC_IO_BROADCAST:
log_warning("Broadcast(?) message on p3io ACIO bus?");
case AC_IO_BROADCAST:
log_warning("Broadcast(?) message on p3io ACIO bus?");
break;
break;
default:
log_warning("p3io ACIO message on unhandled bus address: %d",
default:
log_warning(
"p3io ACIO message on unhandled bus address: %d",
msg->addr);
break;
break;
}
ac_io_emu_request_pop(&com4_ac_io_emu);
+37 -28
View File
@@ -12,44 +12,56 @@
#include "util/defs.h"
#include "util/log.h"
static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, DWORD dwVersion,
REFIID riidltf, LPVOID * ppvOut, LPVOID punkOuter);
static HRESULT STDCALL my_DirectInput8Create(
HINSTANCE hinst,
DWORD dwVersion,
REFIID riidltf,
LPVOID *ppvOut,
LPVOID punkOuter);
static HRESULT (STDCALL *real_DirectInput8Create)( HINSTANCE hinst, DWORD dwVersion,
REFIID riidltf, LPVOID * ppvOut, LPVOID punkOuter);
static HRESULT(STDCALL *real_DirectInput8Create)(
HINSTANCE hinst,
DWORD dwVersion,
REFIID riidltf,
LPVOID *ppvOut,
LPVOID punkOuter);
static const struct hook_symbol dinput_syms[] = {
{
.name = "DirectInput8Create",
.patch = my_DirectInput8Create,
.link = (void **) &real_DirectInput8Create,
.name = "DirectInput8Create",
.patch = my_DirectInput8Create,
.link = (void **) &real_DirectInput8Create,
},
};
static HRESULT STDCALL my_CreateDevice(
IDirectInput8W *self,
REFGUID rguid,
LPDIRECTINPUTDEVICE8W * lplpDirectInputDevice,
LPUNKNOWN pUnkOuter
) {
IDirectInput8W *self,
REFGUID rguid,
LPDIRECTINPUTDEVICE8W *lplpDirectInputDevice,
LPUNKNOWN pUnkOuter)
{
log_misc("IDirectInput8::CreateDevice hook hit");
return DIERR_NOINTERFACE;
}
static HRESULT STDCALL my_EnumDevices(
IDirectInput8W *self,
DWORD dwDevType,
LPDIENUMDEVICESCALLBACKW lpCallback,
LPVOID pvRef,
DWORD dwFlags
) {
IDirectInput8W *self,
DWORD dwDevType,
LPDIENUMDEVICESCALLBACKW lpCallback,
LPVOID pvRef,
DWORD dwFlags)
{
log_misc("IDirectInput8::EnumDevices hook hit");
return DI_OK;
}
static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, DWORD dwVersion,
REFIID riidltf, LPVOID * ppvOut, LPVOID punkOuter)
static HRESULT STDCALL my_DirectInput8Create(
HINSTANCE hinst,
DWORD dwVersion,
REFIID riidltf,
LPVOID *ppvOut,
LPVOID punkOuter)
{
IDirectInput8W *api;
IDirectInput8WVtbl *api_vtbl;
@@ -58,8 +70,9 @@ static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, DWORD dwVersion,
log_info("DirectInput8Create hook hit");
res = real_DirectInput8Create(hinst, dwVersion, riidltf, (LPVOID *)&api, punkOuter);
if(res != DI_OK) {
res = real_DirectInput8Create(
hinst, dwVersion, riidltf, (LPVOID *) &api, punkOuter);
if (res != DI_OK) {
return res;
}
api_proxy = com_proxy_wrap(api, sizeof(*api->lpVtbl));
@@ -68,18 +81,14 @@ static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, DWORD dwVersion,
api_vtbl->EnumDevices = my_EnumDevices;
api_vtbl->CreateDevice = my_CreateDevice;
*(IDirectInput8W**)ppvOut = (IDirectInput8W *)api_proxy;
*(IDirectInput8W **) ppvOut = (IDirectInput8W *) api_proxy;
return res;
}
void dinput_init(HMODULE target)
{
hook_table_apply(
target,
"dinput8.dll",
dinput_syms,
lengthof(dinput_syms));
hook_table_apply(target, "dinput8.dll", dinput_syms, lengthof(dinput_syms));
log_info("Inserted dinput hooks into %p", target);
}
+4 -13
View File
@@ -51,7 +51,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
args_recover(&argc, &argv);
for (i = 1 ; i < argc ; i++) {
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-') {
continue;
}
@@ -84,10 +84,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
log_info("Initializing DDR IO backend");
ddr_io_set_loggers(
log_body_misc,
log_body_info,
log_body_warning,
log_body_fatal);
log_body_misc, log_body_info, log_body_warning, log_body_fatal);
ok = ddr_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
@@ -98,10 +95,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
log_info("Initializing card reader backend");
eam_io_set_loggers(
log_body_misc,
log_body_info,
log_body_warning,
log_body_fatal);
log_body_misc, log_body_info, log_body_warning, log_body_fatal);
ok = eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
@@ -142,10 +136,7 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
}
log_to_external(
log_body_misc,
log_body_info,
log_body_warning,
log_body_fatal);
log_body_misc, log_body_info, log_body_warning, log_body_fatal);
app_hook_init(my_dll_entry_init, my_dll_entry_main);
+32 -25
View File
@@ -1,8 +1,8 @@
#include <windows.h>
#include <ntdef.h>
#include <devioctl.h>
#include <ntddser.h>
#include <ntdef.h>
#include <stdbool.h>
#include <stdint.h>
@@ -43,7 +43,8 @@ void extio_fini(void)
extio_fd = NULL;
}
HRESULT extio_dispatch_irp(struct irp *irp)
HRESULT
extio_dispatch_irp(struct irp *irp)
{
log_assert(irp != NULL);
@@ -52,12 +53,18 @@ HRESULT extio_dispatch_irp(struct irp *irp)
}
switch (irp->op) {
case IRP_OP_OPEN: return extio_open(irp);
case IRP_OP_CLOSE: return extio_close(irp);
case IRP_OP_READ: return extio_read(irp);
case IRP_OP_WRITE: return extio_write(irp);
case IRP_OP_IOCTL: return extio_ioctl(irp);
default: return E_NOTIMPL;
case IRP_OP_OPEN:
return extio_open(irp);
case IRP_OP_CLOSE:
return extio_close(irp);
case IRP_OP_READ:
return extio_read(irp);
case IRP_OP_WRITE:
return extio_write(irp);
case IRP_OP_IOCTL:
return extio_ioctl(irp);
default:
return E_NOTIMPL;
}
}
@@ -126,31 +133,31 @@ static HRESULT extio_ioctl(struct irp *irp)
log_assert(irp != NULL);
switch (irp->ioctl) {
case IOCTL_SERIAL_GET_COMMSTATUS:
if (irp->read.bytes == NULL) {
log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL");
case IOCTL_SERIAL_GET_COMMSTATUS:
if (irp->read.bytes == NULL) {
log_warning(
"IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL");
return E_INVALIDARG;
}
return E_INVALIDARG;
}
if (irp->read.nbytes < sizeof(*status)) {
log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small");
if (irp->read.nbytes < sizeof(*status)) {
log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small");
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
}
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
}
status = (SERIAL_STATUS *) irp->read.bytes;
status->Errors = 0;
status->AmountInInQueue = extio_pending ? 1 : 0;
status = (SERIAL_STATUS *) irp->read.bytes;
status->Errors = 0;
status->AmountInInQueue = extio_pending ? 1 : 0;
irp->read.pos = sizeof(*status);
irp->read.pos = sizeof(*status);
break;
break;
default:
break;
default:
break;
}
return S_OK;
}
+20 -20
View File
@@ -1,5 +1,5 @@
#include <windows.h>
#include <d3d9.h>
#include <windows.h>
#include <stdbool.h>
@@ -10,32 +10,36 @@
#include "util/log.h"
static HRESULT STDCALL my_CreateDevice(
IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd,
DWORD flags, D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev);
IDirect3D9 *self,
UINT adapter,
D3DDEVTYPE type,
HWND hwnd,
DWORD flags,
D3DPRESENT_PARAMETERS *pp,
IDirect3DDevice9 **pdev);
static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver);
static IDirect3D9 * (STDCALL *real_Direct3DCreate9)(
UINT sdk_ver);
static IDirect3D9 *(STDCALL *real_Direct3DCreate9)(UINT sdk_ver);
static bool gfx_windowed;
static const struct hook_symbol gfx_d3d9_hook_syms[] = {
{
.name = "Direct3DCreate9",
.patch = my_Direct3DCreate9,
.link = (void **) &real_Direct3DCreate9,
.name = "Direct3DCreate9",
.patch = my_Direct3DCreate9,
.link = (void **) &real_Direct3DCreate9,
},
};
static HRESULT STDCALL my_CreateDevice(
IDirect3D9 *self,
UINT adapter,
D3DDEVTYPE type,
HWND hwnd,
DWORD flags,
D3DPRESENT_PARAMETERS *pp,
IDirect3DDevice9 **pdev)
IDirect3D9 *self,
UINT adapter,
D3DDEVTYPE type,
HWND hwnd,
DWORD flags,
D3DPRESENT_PARAMETERS *pp,
IDirect3DDevice9 **pdev)
{
IDirect3D9 *real;
@@ -69,10 +73,7 @@ static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver)
void gfx_insert_hooks(HMODULE target)
{
hook_table_apply(
target,
"d3d9.dll",
gfx_d3d9_hook_syms,
lengthof(gfx_d3d9_hook_syms));
target, "d3d9.dll", gfx_d3d9_hook_syms, lengthof(gfx_d3d9_hook_syms));
log_info("Inserted graphics hooks");
}
@@ -86,4 +87,3 @@ void gfx_set_windowed(void)
{
gfx_windowed = true;
}
+1 -1
View File
@@ -1,4 +1,4 @@
#include <windows.h>
#include <initguid.h>
#include <windows.h>
#include "ddrhook/monitor.h"
+9 -9
View File
@@ -1,6 +1,6 @@
#include "ddrhook/master.h"
#include "ddrhook/dinput.h"
#include "ddrhook/gfx.h"
#include "ddrhook/master.h"
#include "ddrhook/misc.h"
#include "ddrhook/monitor.h"
@@ -11,15 +11,15 @@
#include "util/defs.h"
#include "util/log.h"
static HMODULE (STDCALL *real_LoadLibraryA)(const char *name);
static HMODULE(STDCALL *real_LoadLibraryA)(const char *name);
static HMODULE STDCALL my_LoadLibraryA(const char *name);
static const struct hook_symbol master_kernel32_syms[] = {
{
.name = "LoadLibraryA",
.patch = my_LoadLibraryA,
.link = (void **) &real_LoadLibraryA,
.name = "LoadLibraryA",
.patch = my_LoadLibraryA,
.link = (void **) &real_LoadLibraryA,
},
};
@@ -60,10 +60,10 @@ void master_insert_hooks(HMODULE target)
/* Insert dynamic loader hooks so that we can hook late-loaded modules */
hook_table_apply(
target,
"kernel32.dll",
master_kernel32_syms,
lengthof(master_kernel32_syms));
target,
"kernel32.dll",
master_kernel32_syms,
lengthof(master_kernel32_syms));
log_info("Inserted dynamic loader hooks into %p", target);
}
+140 -75
View File
@@ -11,95 +11,125 @@
#include "util/log.h"
#include "util/str.h"
static LONG (STDCALL *real_ChangeDisplaySettingsExA)(
char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param);
static LRESULT (STDCALL *real_SendMessageW)(
HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
static HWND (STDCALL *real_CreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName,
LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth,
int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam);
static LONG (STDCALL *real_SetWindowLongW)(HWND hWnd, int nIndex, LONG dwNewLong);
static BOOL (STDCALL *real_SetWindowPos)(HWND hWnd, HWND hWndInsertAfter,
int X, int Y, int cx, int cy, UINT uFlags);
static LONG(STDCALL *real_ChangeDisplaySettingsExA)(
char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param);
static LRESULT(STDCALL *real_SendMessageW)(
HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
static HWND(STDCALL *real_CreateWindowExW)(
DWORD dwExStyle,
LPCWSTR lpClassName,
LPCWSTR lpWindowName,
DWORD dwStyle,
int X,
int Y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam);
static LONG(STDCALL *real_SetWindowLongW)(
HWND hWnd, int nIndex, LONG dwNewLong);
static BOOL(STDCALL *real_SetWindowPos)(
HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
static LONG STDCALL my_ChangeDisplaySettingsExA(
char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param);
char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param);
static SHORT STDCALL my_GetKeyState(int vk);
static LRESULT STDCALL my_SendMessageW(
HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
static LRESULT STDCALL
my_SendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
static HWND STDCALL my_CreateWindowExA(
DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle,
int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam);
static HWND STDCALL my_CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName,
LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth,
int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam);
DWORD dwExStyle,
LPCSTR lpClassName,
LPCSTR lpWindowName,
DWORD dwStyle,
int X,
int Y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam);
static HWND STDCALL my_CreateWindowExW(
DWORD dwExStyle,
LPCWSTR lpClassName,
LPCWSTR lpWindowName,
DWORD dwStyle,
int X,
int Y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam);
static LONG STDCALL my_SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong);
static BOOL STDCALL my_SetWindowPos(HWND hWnd, HWND hWndInsertAfter,
int X, int Y, int cx, int cy, UINT uFlags);
static BOOL STDCALL my_SetWindowPos(
HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
static const struct hook_symbol misc_user32_syms[] = {
{
.name = "ChangeDisplaySettingsExA",
.patch = my_ChangeDisplaySettingsExA,
.link = (void **) &real_ChangeDisplaySettingsExA,
.name = "ChangeDisplaySettingsExA",
.patch = my_ChangeDisplaySettingsExA,
.link = (void **) &real_ChangeDisplaySettingsExA,
},
{
.name = "SendMessageW",
.patch = my_SendMessageW,
.link = (void **) &real_SendMessageW,
.name = "SendMessageW",
.patch = my_SendMessageW,
.link = (void **) &real_SendMessageW,
},
{
.name = "GetKeyState",
.patch = my_GetKeyState,
.name = "GetKeyState",
.patch = my_GetKeyState,
},
{
.name = "CreateWindowExA",
.patch = my_CreateWindowExA,
.name = "CreateWindowExA",
.patch = my_CreateWindowExA,
},
{
.name = "CreateWindowExW",
.patch = my_CreateWindowExW,
.link = (void **) &real_CreateWindowExW,
.name = "CreateWindowExW",
.patch = my_CreateWindowExW,
.link = (void **) &real_CreateWindowExW,
},
{
.name = "SetWindowLongW",
.patch = my_SetWindowLongW,
.link = (void **) &real_SetWindowLongW,
.name = "SetWindowLongW",
.patch = my_SetWindowLongW,
.link = (void **) &real_SetWindowLongW,
},
{
.name = "SetWindowPos",
.patch = my_SetWindowPos,
.link = (void **) &real_SetWindowPos,
.name = "SetWindowPos",
.patch = my_SetWindowPos,
.link = (void **) &real_SetWindowPos,
},
};
static LONG STDCALL my_SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong) {
if(nIndex == GWL_STYLE)
static LONG STDCALL my_SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong)
{
if (nIndex == GWL_STYLE)
dwNewLong |= WS_OVERLAPPEDWINDOW;
return real_SetWindowLongW(hWnd, nIndex, dwNewLong);
}
static BOOL STDCALL my_SetWindowPos(HWND hWnd, HWND hWndInsertAfter,
int X, int Y, int cx, int cy, UINT uFlags) {
static BOOL STDCALL my_SetWindowPos(
HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
{
return true;
}
static LONG STDCALL my_ChangeDisplaySettingsExA(
char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param)
char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param)
{
if (gfx_get_windowed()) {
return DISP_CHANGE_SUCCESSFUL;
} else {
return real_ChangeDisplaySettingsExA(dev_name, dev_mode, hwnd, flags,
param);
return real_ChangeDisplaySettingsExA(
dev_name, dev_mode, hwnd, flags, param);
}
}
static void calc_win_size_with_framed(HWND hwnd, DWORD x, DWORD y, DWORD width,
DWORD height, LPWINDOWPOS wp)
static void calc_win_size_with_framed(
HWND hwnd, DWORD x, DWORD y, DWORD width, DWORD height, LPWINDOWPOS wp)
{
/* taken from dxwnd */
RECT rect;
@@ -138,10 +168,19 @@ static void calc_win_size_with_framed(HWND hwnd, DWORD x, DWORD y, DWORD width,
wp->cy = rect.bottom - rect.top;
}
static HWND STDCALL my_CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName,
LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth,
int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam)
static HWND STDCALL my_CreateWindowExW(
DWORD dwExStyle,
LPCWSTR lpClassName,
LPCWSTR lpWindowName,
DWORD dwStyle,
int X,
int Y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam)
{
if (gfx_get_windowed()) {
/* use a different style */
@@ -150,12 +189,22 @@ static HWND STDCALL my_CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName,
ShowCursor(TRUE);
}
if(!lpWindowName)
if (!lpWindowName)
lpWindowName = L"Dance Dance Revolution";
HWND hwnd = real_CreateWindowExW(dwExStyle, lpClassName, lpWindowName,
dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance,
lpParam);
HWND hwnd = real_CreateWindowExW(
dwExStyle,
lpClassName,
lpWindowName,
dwStyle,
X,
Y,
nWidth,
nHeight,
hWndParent,
hMenu,
hInstance,
lpParam);
if (hwnd == INVALID_HANDLE_VALUE) {
return hwnd;
@@ -178,23 +227,43 @@ static HWND STDCALL my_CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName,
}
static HWND STDCALL my_CreateWindowExA(
DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle,
int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam)
DWORD dwExStyle,
LPCSTR lpClassName,
LPCSTR lpWindowName,
DWORD dwStyle,
int X,
int Y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam)
{
LPWSTR longWindowName = NULL;
LPWSTR longClassName = NULL;
if(lpWindowName)
if (lpWindowName)
longWindowName = str_widen(lpWindowName);
if(lpClassName)
if (lpClassName)
longClassName = str_widen(lpClassName);
HWND ret = my_CreateWindowExW(dwExStyle, longClassName, longWindowName,
dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
HWND ret = my_CreateWindowExW(
dwExStyle,
longClassName,
longWindowName,
dwStyle,
X,
Y,
nWidth,
nHeight,
hWndParent,
hMenu,
hInstance,
lpParam);
if(longWindowName)
if (longWindowName)
free(longWindowName);
if(longClassName)
if (longClassName)
free(longClassName);
return ret;
@@ -206,8 +275,8 @@ static SHORT STDCALL my_GetKeyState(int vk)
return 0;
}
static LRESULT STDCALL my_SendMessageW(
HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
static LRESULT STDCALL
my_SendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
if (hwnd == HWND_BROADCAST) {
/* OK COOL STORY BRO */
@@ -222,11 +291,7 @@ static LRESULT STDCALL my_SendMessageW(
void misc_insert_hooks(HMODULE target)
{
hook_table_apply(
target,
"user32.dll",
misc_user32_syms,
lengthof(misc_user32_syms));
target, "user32.dll", misc_user32_syms, lengthof(misc_user32_syms));
log_info("Inserted miscellaneous hooks into %p", target);
}
+57 -75
View File
@@ -1,5 +1,5 @@
#include <windows.h>
#include <setupapi.h>
#include <windows.h>
#include <stdbool.h>
#include <wchar.h>
@@ -14,69 +14,62 @@
/* Link pointers */
static HDEVINFO (WINAPI *next_SetupDiGetClassDevsW)(
const GUID *class_guid,
const wchar_t *enumerator,
HWND hwnd,
DWORD flags);
static HDEVINFO(WINAPI *next_SetupDiGetClassDevsW)(
const GUID *class_guid, const wchar_t *enumerator, HWND hwnd, DWORD flags);
static BOOL (WINAPI *next_SetupDiEnumDeviceInfo)(
HDEVINFO dev_info,
DWORD index,
SP_DEVINFO_DATA *info_data);
static BOOL(WINAPI *next_SetupDiEnumDeviceInfo)(
HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data);
static BOOL (WINAPI *next_SetupDiGetDeviceRegistryPropertyA)(
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
DWORD prop,
DWORD *reg_type,
BYTE *bytes,
DWORD nbytes,
DWORD *need_nbytes);
static BOOL(WINAPI *next_SetupDiGetDeviceRegistryPropertyA)(
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
DWORD prop,
DWORD *reg_type,
BYTE *bytes,
DWORD nbytes,
DWORD *need_nbytes);
static BOOL (WINAPI *next_SetupDiDestroyDeviceInfoList)(HDEVINFO dev_info);
static BOOL(WINAPI *next_SetupDiDestroyDeviceInfoList)(HDEVINFO dev_info);
/* API hooks */
static HDEVINFO WINAPI my_SetupDiGetClassDevsW(
const GUID *class_guid,
const wchar_t *enumerator,
HWND hwnd,
DWORD flags);
const GUID *class_guid, const wchar_t *enumerator, HWND hwnd, DWORD flags);
static BOOL WINAPI my_SetupDiEnumDeviceInfo(
HDEVINFO dev_info,
DWORD index,
SP_DEVINFO_DATA *info_data);
HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data);
static BOOL WINAPI my_SetupDiGetDeviceRegistryPropertyA(
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
DWORD prop,
DWORD *reg_type,
BYTE *bytes,
DWORD nbytes,
DWORD *need_nbytes);
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
DWORD prop,
DWORD *reg_type,
BYTE *bytes,
DWORD nbytes,
DWORD *need_nbytes);
static BOOL WINAPI my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info);
static const struct hook_symbol monitor_setupapi_syms[] = {
{
.name = "SetupDiGetClassDevsW",
.patch = my_SetupDiGetClassDevsW,
.link = (void **) &next_SetupDiGetClassDevsW,
}, {
.name = "SetupDiEnumDeviceInfo",
.patch = my_SetupDiEnumDeviceInfo,
.link = (void **) &next_SetupDiEnumDeviceInfo,
}, {
.name = "SetupDiGetDeviceRegistryPropertyA",
.patch = my_SetupDiGetDeviceRegistryPropertyA,
.link = (void **) &next_SetupDiGetDeviceRegistryPropertyA,
}, {
.name = "SetupDiDestroyDeviceInfoList",
.patch = my_SetupDiDestroyDeviceInfoList,
.link = (void **) &next_SetupDiDestroyDeviceInfoList,
.name = "SetupDiGetClassDevsW",
.patch = my_SetupDiGetClassDevsW,
.link = (void **) &next_SetupDiGetClassDevsW,
},
{
.name = "SetupDiEnumDeviceInfo",
.patch = my_SetupDiEnumDeviceInfo,
.link = (void **) &next_SetupDiEnumDeviceInfo,
},
{
.name = "SetupDiGetDeviceRegistryPropertyA",
.patch = my_SetupDiGetDeviceRegistryPropertyA,
.link = (void **) &next_SetupDiGetDeviceRegistryPropertyA,
},
{
.name = "SetupDiDestroyDeviceInfoList",
.patch = my_SetupDiDestroyDeviceInfoList,
.link = (void **) &next_SetupDiDestroyDeviceInfoList,
},
};
@@ -84,17 +77,14 @@ extern bool standard_def;
static HDEVINFO monitor_hdevinfo;
static HDEVINFO WINAPI my_SetupDiGetClassDevsW(
const GUID *class_guid,
const wchar_t *enumerator,
HWND hwnd,
DWORD flags)
const GUID *class_guid, const wchar_t *enumerator, HWND hwnd, DWORD flags)
{
HDEVINFO result;
result = next_SetupDiGetClassDevsW(class_guid, enumerator, hwnd, flags);
if ( result != INVALID_HANDLE_VALUE &&
IsEqualGUID(class_guid, &monitor_guid)) {
if (result != INVALID_HANDLE_VALUE &&
IsEqualGUID(class_guid, &monitor_guid)) {
monitor_hdevinfo = result;
}
@@ -102,9 +92,7 @@ static HDEVINFO WINAPI my_SetupDiGetClassDevsW(
}
static BOOL WINAPI my_SetupDiEnumDeviceInfo(
HDEVINFO dev_info,
DWORD index,
SP_DEVINFO_DATA *info_data)
HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data)
{
if (dev_info != monitor_hdevinfo) {
return next_SetupDiEnumDeviceInfo(dev_info, index, info_data);
@@ -128,26 +116,20 @@ static BOOL WINAPI my_SetupDiEnumDeviceInfo(
}
static BOOL WINAPI my_SetupDiGetDeviceRegistryPropertyA(
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
DWORD prop,
DWORD *reg_type,
BYTE *bytes,
DWORD nbytes,
DWORD *nbytes_out)
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
DWORD prop,
DWORD *reg_type,
BYTE *bytes,
DWORD nbytes,
DWORD *nbytes_out)
{
const char *txt;
size_t txt_nbytes;
if (dev_info != monitor_hdevinfo) {
return next_SetupDiGetDeviceRegistryPropertyA(
dev_info,
info_data,
prop,
reg_type,
bytes,
nbytes,
nbytes_out);
dev_info, info_data, prop, reg_type, bytes, nbytes, nbytes_out);
}
/* The only implemented property */
@@ -199,10 +181,10 @@ static BOOL WINAPI my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info)
void monitor_setupapi_insert_hooks(HMODULE target)
{
hook_table_apply(
target,
"setupapi.dll",
monitor_setupapi_syms,
lengthof(monitor_setupapi_syms));
target,
"setupapi.dll",
monitor_setupapi_syms,
lengthof(monitor_setupapi_syms));
log_info("Inserted monitor setupapi hooks into %p", target);
}
+12 -5
View File
@@ -4,11 +4,18 @@
#include <windows.h>
DEFINE_GUID(
monitor_guid,
0x4D36E96E,
0xE325,
0x11CE,
0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18);
monitor_guid,
0x4D36E96E,
0xE325,
0x11CE,
0xBF,
0xC1,
0x08,
0x00,
0x2B,
0xE1,
0x03,
0x18);
void monitor_setupapi_insert_hooks(HMODULE target);
+3 -3
View File
@@ -21,9 +21,9 @@ static HRESULT p3io_ddr_get_cab_type(void *ctx, enum p3io_cab_type *type);
static HRESULT p3io_ddr_get_video_freq(void *ctx, enum p3io_video_freq *freq);
static const struct p3io_ops p3io_ddr_ops = {
.read_jamma = p3io_ddr_read_jamma,
.set_outputs = p3io_ddr_set_outputs,
.get_cab_type = p3io_ddr_get_cab_type,
.read_jamma = p3io_ddr_read_jamma,
.set_outputs = p3io_ddr_set_outputs,
.get_cab_type = p3io_ddr_get_cab_type,
.get_video_freq = p3io_ddr_get_video_freq,
};
+49 -45
View File
@@ -2,9 +2,9 @@
#include <windows.h>
#include <ntdef.h>
#include <devioctl.h>
#include <ntddser.h>
#include <ntdef.h>
#include <stdbool.h>
#include <stdint.h>
@@ -36,7 +36,8 @@ void spike_fini(void)
ac_io_emu_fini(&spike_ac_io_emu);
}
HRESULT spike_dispatch_irp(struct irp *irp)
HRESULT
spike_dispatch_irp(struct irp *irp)
{
const struct ac_io_message *msg;
HRESULT hr;
@@ -57,60 +58,61 @@ HRESULT spike_dispatch_irp(struct irp *irp)
msg = ac_io_emu_request_peek(&spike_ac_io_emu);
switch (msg->addr) {
case 0:
ac_io_emu_cmd_assign_addrs(&spike_ac_io_emu, msg, 7);
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
switch (ac_io_u16(msg->cmd.code)) {
case AC_IO_CMD_GET_VERSION:
spike_handle_get_version(msg);
case 0:
ac_io_emu_cmd_assign_addrs(&spike_ac_io_emu, msg, 7);
break;
case AC_IO_CMD_START_UP:
spike_handle_status(msg);
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
switch (ac_io_u16(msg->cmd.code)) {
case AC_IO_CMD_GET_VERSION:
spike_handle_get_version(msg);
break;
case AC_IO_CMD_START_UP:
spike_handle_status(msg);
break;
case AC_IO_CMD_KEEPALIVE:
spike_send_empty(msg);
break;
case 0x100:
case 0x110:
case 0x112:
case 0x128:
spike_handle_status(msg);
break;
default:
log_warning(
"Spike ACIO unhandled cmd: %04X",
ac_io_u16(msg->cmd.code));
}
break;
case AC_IO_CMD_KEEPALIVE:
spike_send_empty(msg);
break;
case 0x100:
case 0x110:
case 0x112:
case 0x128:
spike_handle_status(msg);
case AC_IO_BROADCAST:
spike_handle_broadcast(msg);
break;
default:
log_warning("Spike ACIO unhandled cmd: %04X",
ac_io_u16(msg->cmd.code));
}
break;
case AC_IO_BROADCAST:
spike_handle_broadcast(msg);
break;
default:
log_warning(
log_warning(
"Spike ACIO message on unhandled bus address: %d",
msg->addr);
break;
break;
}
ac_io_emu_request_pop(&spike_ac_io_emu);
@@ -138,8 +140,10 @@ static void spike_handle_get_version(const struct ac_io_message *req)
resp.cmd.version.major = 0x01;
resp.cmd.version.minor = 0x01;
resp.cmd.version.revision = 0x00;
memcpy(resp.cmd.version.product_code, "DDRS",
sizeof(resp.cmd.version.product_code));
memcpy(
resp.cmd.version.product_code,
"DDRS",
sizeof(resp.cmd.version.product_code));
strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date));
strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time));
+41 -35
View File
@@ -2,9 +2,9 @@
#include <windows.h>
#include <ntdef.h>
#include <devioctl.h>
#include <ntddser.h>
#include <ntdef.h>
#include <stdbool.h>
#include <string.h>
@@ -12,8 +12,8 @@
#include "hook/iohook.h"
#include "util/log.h"
#include "util/iobuf.h"
#include "util/log.h"
#include "util/str.h"
#define USBMEM_BUF_SIZE 128
@@ -44,7 +44,8 @@ void usbmem_fini(void)
usbmem_fd = NULL;
}
HRESULT usbmem_dispatch_irp(struct irp *irp)
HRESULT
usbmem_dispatch_irp(struct irp *irp)
{
log_assert(irp != NULL);
@@ -53,12 +54,18 @@ HRESULT usbmem_dispatch_irp(struct irp *irp)
}
switch (irp->op) {
case IRP_OP_OPEN: return usbmem_open(irp);
case IRP_OP_CLOSE: return usbmem_close(irp);
case IRP_OP_READ: return usbmem_read(irp);
case IRP_OP_WRITE: return usbmem_write(irp);
case IRP_OP_IOCTL: return usbmem_ioctl(irp);
default: return E_NOTIMPL;
case IRP_OP_OPEN:
return usbmem_open(irp);
case IRP_OP_CLOSE:
return usbmem_close(irp);
case IRP_OP_READ:
return usbmem_read(irp);
case IRP_OP_WRITE:
return usbmem_write(irp);
case IRP_OP_IOCTL:
return usbmem_ioctl(irp);
default:
return E_NOTIMPL;
}
}
@@ -101,18 +108,17 @@ static HRESULT usbmem_write(struct irp *irp)
if (strlen(request) > 0) {
if (str_eq(request, "sver")) {
str_cpy(usbmem_response,
sizeof(usbmem_response),
"done GQHDXJAA DJHACKRS");
str_cpy(
usbmem_response,
sizeof(usbmem_response),
"done GQHDXJAA DJHACKRS");
} else if (
str_eq(request, "on_a") ||
str_eq(request, "on_b") ||
str_eq(request, "offa") ||
str_eq(request, "offb") ) {
str_eq(request, "on_a") || str_eq(request, "on_b") ||
str_eq(request, "offa") || str_eq(request, "offb")) {
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
} else if (
strncmp(request, "lma ", 4) == 0 ||
strncmp(request, "lmb ", 4) == 0) {
strncmp(request, "lma ", 4) == 0 ||
strncmp(request, "lmb ", 4) == 0) {
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
} else {
str_cpy(usbmem_response, sizeof(usbmem_response), "not connected");
@@ -160,31 +166,31 @@ static HRESULT usbmem_ioctl(struct irp *irp)
log_assert(irp != NULL);
switch (irp->ioctl) {
case IOCTL_SERIAL_GET_COMMSTATUS:
if (irp->read.bytes == NULL) {
log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL");
case IOCTL_SERIAL_GET_COMMSTATUS:
if (irp->read.bytes == NULL) {
log_warning(
"IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL");
return E_INVALIDARG;
}
return E_INVALIDARG;
}
if (irp->read.nbytes < sizeof(*status)) {
log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small");
if (irp->read.nbytes < sizeof(*status)) {
log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small");
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
}
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
}
status = (SERIAL_STATUS *) irp->read.bytes;
status->Errors = 0;
status->AmountInInQueue = usbmem_pending ? 1 : 0;
status = (SERIAL_STATUS *) irp->read.bytes;
status->Errors = 0;
status->AmountInInQueue = usbmem_pending ? 1 : 0;
irp->read.pos = sizeof(*status);
irp->read.pos = sizeof(*status);
break;
break;
default:
break;
default:
break;
}
return S_OK;
}