ReactOS  0.4.14-dev-614-gbfd8a84
testvdd.c File Reference
#include <stdio.h>
#include <windows.h>
#include <vddsvc.h>
#include <debug.h>
Include dependency graph for testvdd.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define VDD_DBG   VddDbgMsg
 
#define NUM_PORTS   4
 
#define PAGE_SIZE   0x1000
 
#define PAGE_ROUND_DOWN(x)   ( ((ULONG_PTR)(x)) & (~(PAGE_SIZE-1)) )
 
#define PAGE_ROUND_UP(x)   ( (((ULONG_PTR)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1)) )
 
#define MEM_SEG_START   0x0000
 
#define MEM_SIZE   PAGE_SIZE
 

Functions

static VOID VddDbgMsg (LPCSTR Format,...)
 
VOID WINAPI PortInB (IN USHORT Port, OUT PUCHAR Data)
 
VOID WINAPI PortOutB (IN USHORT Port, IN UCHAR Data)
 
VOID WINAPI PortInW (IN USHORT Port, OUT PUSHORT Data)
 
VOID WINAPI PortOutW (IN USHORT Port, IN USHORT Data)
 
VOID WINAPI PortInsB (IN USHORT Port, OUT PUCHAR Data, IN USHORT Count)
 
VOID WINAPI PortOutsB (IN USHORT Port, IN PUCHAR Data, IN USHORT Count)
 
VOID WINAPI PortInsW (IN USHORT Port, OUT PUSHORT Data, IN USHORT Count)
 
VOID WINAPI PortOutsW (IN USHORT Port, IN PUSHORT Data, IN USHORT Count)
 
VOID WINAPI MemoryHandler (IN PVOID FaultAddress, IN ULONG RWMode)
 
PVOID FindHookableMemory (IN USHORT StartSegment, IN ULONG StartOffset, OUT PUSHORT HookedSegment, OUT PULONG HookedOffset)
 
VOID WINAPI Create1Handler (USHORT DosPDB)
 
VOID WINAPI Create2Handler (USHORT DosPDB)
 
VOID WINAPI Terminate1Handler (USHORT DosPDB)
 
VOID WINAPI Terminate2Handler (USHORT DosPDB)
 
VOID WINAPI Block1Handler (VOID)
 
VOID WINAPI Block2Handler (VOID)
 
VOID WINAPI Resume1Handler (VOID)
 
VOID WINAPI Resume2Handler (VOID)
 
VOID WINAPI TestVDDRegister (VOID)
 
VOID WINAPI TestVDDUnRegister (VOID)
 
VOID WINAPI TestVDDDispatch (VOID)
 
BOOLEAN RegisterVDD (BOOLEAN Register)
 
BOOL WINAPI DllMain (IN HINSTANCE hInstanceDll, IN DWORD dwReason, IN LPVOID lpReserved)
 

Variables

HANDLE hVdd = NULL
 
VDD_IO_PORTRANGE PortDefs [NUM_PORTS]
 
VDD_IO_HANDLERS PortHandlers [NUM_PORTS]
 
USHORT HookedSegment = 0x0000
 
ULONG HookedOffset = 0x0000
 
PVOID HookedAddress = NULL
 

Macro Definition Documentation

◆ MEM_SEG_START

#define MEM_SEG_START   0x0000

Definition at line 208 of file testvdd.c.

◆ MEM_SIZE

#define MEM_SIZE   PAGE_SIZE

Definition at line 209 of file testvdd.c.

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file testvdd.c.

◆ NUM_PORTS

#define NUM_PORTS   4

Definition at line 95 of file testvdd.c.

◆ PAGE_ROUND_DOWN

#define PAGE_ROUND_DOWN (   x)    ( ((ULONG_PTR)(x)) & (~(PAGE_SIZE-1)) )

Definition at line 199 of file testvdd.c.

◆ PAGE_ROUND_UP

#define PAGE_ROUND_UP (   x)    ( (((ULONG_PTR)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1)) )

Definition at line 204 of file testvdd.c.

◆ PAGE_SIZE

#define PAGE_SIZE   0x1000

Definition at line 195 of file testvdd.c.

◆ VDD_DBG

#define VDD_DBG   VddDbgMsg

Definition at line 81 of file testvdd.c.

Function Documentation

◆ Block1Handler()

VOID WINAPI Block1Handler ( VOID  )

Definition at line 321 of file testvdd.c.

322 {
323  VDD_DBG("Block1Handler");
324 }
#define VDD_DBG
Definition: testvdd.c:81

Referenced by RegisterVDD().

◆ Block2Handler()

VOID WINAPI Block2Handler ( VOID  )

Definition at line 328 of file testvdd.c.

329 {
330  VDD_DBG("Block2Handler");
331 }
#define VDD_DBG
Definition: testvdd.c:81

Referenced by RegisterVDD().

◆ Create1Handler()

VOID WINAPI Create1Handler ( USHORT  DosPDB)

Definition at line 293 of file testvdd.c.

294 {
295  VDD_DBG("Create1Handler(0x%04x)", DosPDB);
296 }
#define VDD_DBG
Definition: testvdd.c:81

Referenced by RegisterVDD().

◆ Create2Handler()

VOID WINAPI Create2Handler ( USHORT  DosPDB)

Definition at line 300 of file testvdd.c.

301 {
302  VDD_DBG("Create2Handler(0x%04x)", DosPDB);
303 }
#define VDD_DBG
Definition: testvdd.c:81

Referenced by RegisterVDD().

◆ DllMain()

BOOL WINAPI DllMain ( IN HINSTANCE  hInstanceDll,
IN DWORD  dwReason,
IN LPVOID  lpReserved 
)

Definition at line 476 of file testvdd.c.

479 {
481 
482  UNREFERENCED_PARAMETER(lpReserved);
483 
484  switch (dwReason)
485  {
486  case DLL_PROCESS_ATTACH:
487  {
488  VDD_DBG("DLL_PROCESS_ATTACH");
489 
490  /* Save our global VDD handle */
491  hVdd = hInstanceDll;
492 
493  /* Register VDD */
495  if (!Success) VDD_DBG("Failed to register the VDD...");
496 
497  break;
498  }
499 
500  case DLL_PROCESS_DETACH:
501  {
502  VDD_DBG("DLL_PROCESS_DETACH");
503 
504  /* Unregister VDD */
506  if (!Success) VDD_DBG("Failed to unregister the VDD...");
507 
508  break;
509  }
510 
511  case DLL_THREAD_ATTACH:
512  case DLL_THREAD_DETACH:
513  default:
514  break;
515  }
516 
517  return TRUE;
518 }
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define DLL_THREAD_ATTACH
Definition: compat.h:121
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define DLL_THREAD_DETACH
Definition: compat.h:122
DWORD dwReason
Definition: misc.cpp:154
unsigned char BOOLEAN
#define DLL_PROCESS_DETACH
Definition: compat.h:119
#define VDD_DBG
Definition: testvdd.c:81
BOOLEAN RegisterVDD(BOOLEAN Register)
Definition: testvdd.c:381
HANDLE hVdd
Definition: testvdd.c:87

◆ FindHookableMemory()

PVOID FindHookableMemory ( IN USHORT  StartSegment,
IN ULONG  StartOffset,
OUT PUSHORT  HookedSegment,
OUT PULONG  HookedOffset 
)

Definition at line 230 of file testvdd.c.

234 {
236  PVOID PhysMemStart = NULL;
237  USHORT Segment = StartSegment;
238  ULONG Offset = PAGE_ROUND_DOWN(StartOffset);
239 
240  *HookedSegment = 0x0000;
241  *HookedOffset = 0x0000;
242 
243  while (Segment <= 0xF000)
244  {
245  // PhysMemStart = GetVDMPointer(GetVDMAddress(Segment, Offset), MEM_SIZE, (getMSW() & MSW_PE));
246  PhysMemStart = VdmMapFlat(Segment, Offset, getMODE());
247 
248  /* Try to hook this memory area... */
250  if (!Success)
251  {
252  /* ... it didn't work. Free PhysMemStart, increase segment/offset and try again. */
253  DPRINT1("%04lX:%08lX hooking failed, continue...\n", Segment, Offset);
254 
255  VdmUnmapFlat(Segment, Offset, PhysMemStart, getMODE());
256  // FreeVDMPointer(GetVDMAddress(Segment, Offset), MEM_SIZE, PhysMemStart, (getMSW() & MSW_PE));
257  PhysMemStart = NULL;
258 
259  Offset += MEM_SIZE;
260  if (Offset + MEM_SIZE > 0xFFFF)
261  {
262  Segment += 0x1000;
263  Offset = 0x0000;
264  }
265  }
266  else
267  {
268  /* ... it worked. We'll free PhysMemStart later on. */
269  DPRINT1("%04lX:%08lX hooking succeeded!\n", Segment, Offset);
270  break;
271  }
272  }
273 
274  if (PhysMemStart)
275  {
276  VDD_DBG("We hooked at %04lX:%08lX (0x%p)", Segment, Offset, PhysMemStart);
278  *HookedOffset = Offset;
279  }
280  else
281  {
282  VDD_DBG("Hooking attempt failed!");
283  }
284 
285  return PhysMemStart;
286 }
#define MEM_SIZE
Definition: testvdd.c:209
ULONG HookedOffset
Definition: testvdd.c:212
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI VdmUnmapFlat(_In_ USHORT Segment, _In_ ULONG Offset, _In_ PVOID Buffer, _In_ VDM_MODE Mode)
_Inout_ PVOID Segment
Definition: exfuncs.h:893
#define getMODE()
Definition: nt_vdd.h:228
USHORT HookedSegment
Definition: testvdd.c:211
PVOID WINAPI VdmMapFlat(_In_ USHORT Segment, _In_ ULONG Offset, _In_ VDM_MODE Mode)
#define VDD_DBG
Definition: testvdd.c:81
BOOL WINAPI VDDInstallMemoryHook(_In_ HANDLE hVdd, _In_ PVOID pStart, _In_ DWORD dwCount, _In_ PVDD_MEMORY_HANDLER MemoryHandler)
#define PAGE_ROUND_DOWN(x)
Definition: testvdd.c:199
unsigned short USHORT
Definition: pedump.c:61
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
VOID WINAPI MemoryHandler(IN PVOID FaultAddress, IN ULONG RWMode)
Definition: testvdd.c:217
HANDLE hVdd
Definition: testvdd.c:87

Referenced by RegisterVDD().

◆ MemoryHandler()

VOID WINAPI MemoryHandler ( IN PVOID  FaultAddress,
IN ULONG  RWMode 
)

Definition at line 217 of file testvdd.c.

219 {
221 
222  VDD_DBG("MemoryHandler(0x%08x, %s)", FaultAddress, (RWMode == 1) ? "Write" : "Read");
223  // VDDTerminateVDM();
224 
226  if (!Success) VDD_DBG("Unable to allocate memory");
227 }
#define MEM_SIZE
Definition: testvdd.c:209
unsigned char BOOLEAN
BOOL WINAPI VDDAllocMem(_In_ HANDLE hVdd, _In_ PVOID Address, _In_ ULONG Size)
PVOID HookedAddress
Definition: testvdd.c:213
#define VDD_DBG
Definition: testvdd.c:81
HANDLE hVdd
Definition: testvdd.c:87

Referenced by FindHookableMemory(), and VDDInstallMemoryHook().

◆ PortInB()

VOID WINAPI PortInB ( IN USHORT  Port,
OUT PUCHAR  Data 
)

Definition at line 107 of file testvdd.c.

109 {
110  *Data = 0;
111  VDD_DBG("0x%08x (BYTE 0x%02x) <-- Port 0x%04x", Data, *Data, Port);
112 }
CPPORT Port[4]
Definition: headless.c:34
#define VDD_DBG
Definition: testvdd.c:81

◆ PortInsB()

VOID WINAPI PortInsB ( IN USHORT  Port,
OUT PUCHAR  Data,
IN USHORT  Count 
)

Definition at line 142 of file testvdd.c.

145 {
146  VDD_DBG("0x%08x (BYTESTR[%u]) <-- Port 0x%04x", Data, Count, Port);
147  while (Count--) *Data++ = 0;
148 }
CPPORT Port[4]
Definition: headless.c:34
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define VDD_DBG
Definition: testvdd.c:81

◆ PortInsW()

VOID WINAPI PortInsW ( IN USHORT  Port,
OUT PUSHORT  Data,
IN USHORT  Count 
)

Definition at line 161 of file testvdd.c.

164 {
165  VDD_DBG("0x%08x (WORDSTR[%u]) <-- Port 0x%04x", Data, Count, Port);
166  while (Count--) *Data++ = 0;
167 }
CPPORT Port[4]
Definition: headless.c:34
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define VDD_DBG
Definition: testvdd.c:81

◆ PortInW()

VOID WINAPI PortInW ( IN USHORT  Port,
OUT PUSHORT  Data 
)

Definition at line 124 of file testvdd.c.

126 {
127  *Data = 0;
128  VDD_DBG("0x%08x (WORD 0x%04x) <-- Port 0x%04x", Data, *Data, Port);
129 }
CPPORT Port[4]
Definition: headless.c:34
#define VDD_DBG
Definition: testvdd.c:81

◆ PortOutB()

VOID WINAPI PortOutB ( IN USHORT  Port,
IN UCHAR  Data 
)

Definition at line 116 of file testvdd.c.

118 {
119  VDD_DBG("(BYTE 0x%02x) --> Port 0x%04x", Data, Port);
120 }
CPPORT Port[4]
Definition: headless.c:34
#define VDD_DBG
Definition: testvdd.c:81

◆ PortOutsB()

VOID WINAPI PortOutsB ( IN USHORT  Port,
IN PUCHAR  Data,
IN USHORT  Count 
)

Definition at line 152 of file testvdd.c.

155 {
156  VDD_DBG("0x%08x (BYTESTR[%u]) --> Port 0x%04x", Data, Count, Port);
157 }
CPPORT Port[4]
Definition: headless.c:34
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define VDD_DBG
Definition: testvdd.c:81

◆ PortOutsW()

VOID WINAPI PortOutsW ( IN USHORT  Port,
IN PUSHORT  Data,
IN USHORT  Count 
)

Definition at line 171 of file testvdd.c.

174 {
175  VDD_DBG("0x%08x (WORDSTR[%u]) --> Port 0x%04x", Data, Count, Port);
176 }
CPPORT Port[4]
Definition: headless.c:34
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define VDD_DBG
Definition: testvdd.c:81

◆ PortOutW()

VOID WINAPI PortOutW ( IN USHORT  Port,
IN USHORT  Data 
)

Definition at line 133 of file testvdd.c.

135 {
136  VDD_DBG("(WORD 0x%04x) --> Port 0x%04x", Data, Port);
137 }
CPPORT Port[4]
Definition: headless.c:34
#define VDD_DBG
Definition: testvdd.c:81

◆ RegisterVDD()

BOOLEAN RegisterVDD ( BOOLEAN  Register)

Definition at line 381 of file testvdd.c.

382 {
384 
385  if (Register)
386  {
387  /* Hook some IO ports */
388  VDD_DBG("VDDInstallIOHook");
390  if (!Success)
391  {
392  VDD_DBG("Unable to hook IO ports, terminate...");
393  VDDTerminateVDM();
394  }
395 
396  /* Add a memory handler */
397  VDD_DBG("FindHookableMemory");
400  if (HookedAddress == NULL)
401  {
402  VDD_DBG("Unable to install memory handler, terminate...");
403  VDDTerminateVDM();
404  }
405 
406  /* Add some user hooks -- Test order of initialization and calling */
407  VDD_DBG("VDDInstallUserHook (1)");
413  if (!Success)
414  {
415  VDD_DBG("Unable to install user hooks (1)...");
416  }
417 
418  VDD_DBG("VDDInstallUserHook (2)");
424  if (!Success)
425  {
426  VDD_DBG("Unable to install user hooks (2)...");
427  }
428 
429  /* We have finished! */
430  VDD_DBG("Initialization finished!");
431  }
432  else
433  {
434  /* Remove the user hooks */
435  VDD_DBG("VDDDeInstallUserHook (1)");
437  if (!Success) VDD_DBG("Unable to uninstall user hooks (1)");
438 
439  // TODO: See which hooks are still existing there...
440 
441  VDD_DBG("VDDDeInstallUserHook (2)");
443  if (!Success) VDD_DBG("Unable to uninstall user hooks (2)");
444 
445  VDD_DBG("VDDDeInstallUserHook (3)");
447  if (!Success) VDD_DBG("EXPECTED ERROR: Unable to uninstall user hooks (3)");
448  else VDD_DBG("UNEXPECTED ERROR: Uninstalling user hooks (3) succeeded?!");
449 
450  /* Uninstall the memory handler */
452  if (!Success) VDD_DBG("Unable to free memory");
453 
454  VDD_DBG("VDDDeInstallMemoryHook");
456  if (!Success) VDD_DBG("Memory handler uninstall failed");
457 
458  VDD_DBG("VdmUnmapFlat");
460  // FreeVDMPointer(GetVDMAddress(HookedSegment, HookedOffset), MEM_SIZE, HookedAddress, (getMSW() & MSW_PE));
461  if (!Success) VDD_DBG("VdmUnmapFlat failed!");
462 
463  /* Deregister the hooked IO ports */
464  VDD_DBG("VDDDeInstallIOHook");
466 
467  VDD_DBG("Cleanup finished!");
468  Success = TRUE;
469  }
470 
471  return Success;
472 }
PVOID FindHookableMemory(IN USHORT StartSegment, IN ULONG StartOffset, OUT PUSHORT HookedSegment, OUT PULONG HookedOffset)
Definition: testvdd.c:230
#define MEM_SIZE
Definition: testvdd.c:209
#define TRUE
Definition: types.h:120
#define NUM_PORTS
Definition: testvdd.c:95
VOID WINAPI Resume1Handler(VOID)
Definition: testvdd.c:335
VOID WINAPI Create2Handler(USHORT DosPDB)
Definition: testvdd.c:300
VOID WINAPI Resume2Handler(VOID)
Definition: testvdd.c:342
ULONG HookedOffset
Definition: testvdd.c:212
BOOL WINAPI VDDDeInstallMemoryHook(_In_ HANDLE hVdd, _In_ PVOID pStart, _In_ DWORD dwCount)
VOID WINAPI Create1Handler(USHORT DosPDB)
Definition: testvdd.c:293
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define MEM_SEG_START
Definition: testvdd.c:208
VDD_IO_PORTRANGE PortDefs[NUM_PORTS]
Definition: testvdd.c:97
VOID WINAPI Block2Handler(VOID)
Definition: testvdd.c:328
BOOL WINAPI VdmUnmapFlat(_In_ USHORT Segment, _In_ ULONG Offset, _In_ PVOID Buffer, _In_ VDM_MODE Mode)
VOID WINAPI Terminate1Handler(USHORT DosPDB)
Definition: testvdd.c:307
PVOID HookedAddress
Definition: testvdd.c:213
#define getMODE()
Definition: nt_vdd.h:228
VOID WINAPI VDDTerminateVDM(VOID)
Definition: emulator.c:677
USHORT HookedSegment
Definition: testvdd.c:211
VOID WINAPI Block1Handler(VOID)
Definition: testvdd.c:321
BOOL WINAPI VDDInstallIOHook(_In_ HANDLE hVdd, _In_ WORD cPortRange, _In_ PVDD_IO_PORTRANGE pPortRange, _In_ PVDD_IO_HANDLERS IoHandlers)
#define VDD_DBG
Definition: testvdd.c:81
BOOL WINAPI VDDInstallUserHook(_In_ HANDLE hVdd, _In_ PFNVDD_UCREATE Ucr_Handler, _In_ PFNVDD_UTERMINATE Uterm_Handler, _In_ PFNVDD_UBLOCK Ublock_Handler, _In_ PFNVDD_URESUME Uresume_Handler)
BOOL WINAPI VDDDeInstallUserHook(_In_ HANDLE hVdd)
BOOL WINAPI VDDFreeMem(_In_ HANDLE hVdd, _In_ PVOID Address, _In_ ULONG Size)
VDD_IO_HANDLERS PortHandlers[NUM_PORTS]
Definition: testvdd.c:179
VOID WINAPI VDDDeInstallIOHook(_In_ HANDLE hVdd, _In_ WORD cPortRange, _In_ PVDD_IO_PORTRANGE pPortRange)
VOID WINAPI Terminate2Handler(USHORT DosPDB)
Definition: testvdd.c:314
HANDLE hVdd
Definition: testvdd.c:87

Referenced by DllMain().

◆ Resume1Handler()

VOID WINAPI Resume1Handler ( VOID  )

Definition at line 335 of file testvdd.c.

336 {
337  VDD_DBG("Resume1Handler");
338 }
#define VDD_DBG
Definition: testvdd.c:81

Referenced by RegisterVDD().

◆ Resume2Handler()

VOID WINAPI Resume2Handler ( VOID  )

Definition at line 342 of file testvdd.c.

343 {
344  VDD_DBG("Resume2Handler");
345 }
#define VDD_DBG
Definition: testvdd.c:81

Referenced by RegisterVDD().

◆ Terminate1Handler()

VOID WINAPI Terminate1Handler ( USHORT  DosPDB)

Definition at line 307 of file testvdd.c.

308 {
309  VDD_DBG("Terminate1Handler(0x%04x)", DosPDB);
310 }
#define VDD_DBG
Definition: testvdd.c:81

Referenced by RegisterVDD().

◆ Terminate2Handler()

VOID WINAPI Terminate2Handler ( USHORT  DosPDB)

Definition at line 314 of file testvdd.c.

315 {
316  VDD_DBG("Terminate2Handler(0x%04x)", DosPDB);
317 }
#define VDD_DBG
Definition: testvdd.c:81

Referenced by RegisterVDD().

◆ TestVDDDispatch()

VOID WINAPI TestVDDDispatch ( VOID  )

Definition at line 372 of file testvdd.c.

373 {
374  VDD_DBG("TestVDDDispatch");
375 
376  /* Clear the Carry Flag: success */
377  setCF(0);
378 }
VOID WINAPI setCF(ULONG)
Definition: registers.c:573
#define VDD_DBG
Definition: testvdd.c:81

◆ TestVDDRegister()

VOID WINAPI TestVDDRegister ( VOID  )

Definition at line 352 of file testvdd.c.

353 {
354  VDD_DBG("TestVDDRegister");
355 
356  /* Clear the Carry Flag: success */
357  setCF(0);
358 }
VOID WINAPI setCF(ULONG)
Definition: registers.c:573
#define VDD_DBG
Definition: testvdd.c:81

◆ TestVDDUnRegister()

VOID WINAPI TestVDDUnRegister ( VOID  )

Definition at line 362 of file testvdd.c.

363 {
364  VDD_DBG("TestVDDUnRegister");
365 
366  /* Clear the Carry Flag: success */
367  setCF(0);
368 }
VOID WINAPI setCF(ULONG)
Definition: registers.c:573
#define VDD_DBG
Definition: testvdd.c:81

◆ VddDbgMsg()

static VOID VddDbgMsg ( LPCSTR  Format,
  ... 
)
static

Definition at line 35 of file testvdd.c.

36  {
37  #ifndef WIN2K_COMPLIANT
38  CHAR StaticBuffer[256];
39  LPSTR Buffer = StaticBuffer; // Use the static buffer by default.
40  #else
41  CHAR Buffer[2048]; // Large enough. If not, increase it by hand.
42  #endif
43  size_t MsgLen;
45 
47 
48  #ifndef WIN2K_COMPLIANT
49  /*
50  * Retrieve the message length and if it is too long, allocate
51  * an auxiliary buffer; otherwise use the static buffer.
52  */
53  MsgLen = _vscprintf(Format, Parameters) + 1; // NULL-terminated
54  if (MsgLen > ARRAYSIZE(StaticBuffer))
55  {
56  Buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MsgLen * sizeof(WCHAR));
57  if (Buffer == NULL)
58  {
59  /* Allocation failed, use the static buffer and display a suitable error message */
60  Buffer = StaticBuffer;
61  Format = "DisplayMessage()\nOriginal message is too long and allocating an auxiliary buffer failed.";
62  MsgLen = strlen(Format);
63  }
64  }
65  #else
66  MsgLen = ARRAYSIZE(Buffer);
67  #endif
68 
69  /* Display the message */
71  MessageBoxA(NULL, Buffer, "Test VDD", MB_OK);
72 
73  #ifndef WIN2K_COMPLIANT
74  /* Free the buffer if needed */
75  if (Buffer != StaticBuffer) HeapFree(GetProcessHeap(), 0, Buffer);
76  #endif
77 
79  }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char CHAR
Definition: xmlstorage.h:175
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
char * LPSTR
Definition: xmlstorage.h:182
int WINAPI MessageBoxA(_In_opt_ HWND, _In_opt_ LPCSTR, _In_opt_ LPCSTR, _In_ UINT)
#define va_end(ap)
Definition: acmsvcex.h:90
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
_Check_return_ _CRTIMP int __cdecl _vscprintf(_In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define MB_OK
Definition: winuser.h:784
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define _vsnprintf
Definition: xmlstorage.h:202
#define HeapFree(x, y, z)
Definition: compat.h:402

Variable Documentation

◆ HookedAddress

PVOID HookedAddress = NULL

Definition at line 213 of file testvdd.c.

Referenced by MemoryHandler(), and RegisterVDD().

◆ HookedOffset

ULONG HookedOffset = 0x0000

Definition at line 212 of file testvdd.c.

Referenced by FindHookableMemory(), and RegisterVDD().

◆ HookedSegment

USHORT HookedSegment = 0x0000

Definition at line 211 of file testvdd.c.

Referenced by FindHookableMemory(), and RegisterVDD().

◆ hVdd

◆ PortDefs

Initial value:
=
{
{0x3F8, 0x3FF},
{0x2F8, 0x2FF},
{0x3E8, 0x3EF},
{0x2E8, 0x2EF}
}

Definition at line 97 of file testvdd.c.

Referenced by RegisterVDD().

◆ PortHandlers

VDD_IO_HANDLERS PortHandlers[NUM_PORTS]
Initial value:
=
{
}
VOID WINAPI PortOutsW(IN USHORT Port, IN PUSHORT Data, IN USHORT Count)
Definition: testvdd.c:171
VOID WINAPI PortOutB(IN USHORT Port, IN UCHAR Data)
Definition: testvdd.c:116
VOID WINAPI PortInsW(IN USHORT Port, OUT PUSHORT Data, IN USHORT Count)
Definition: testvdd.c:161
smooth NULL
Definition: ftsmooth.c:416
VOID WINAPI PortInB(IN USHORT Port, OUT PUCHAR Data)
Definition: testvdd.c:107
VOID WINAPI PortOutsB(IN USHORT Port, IN PUCHAR Data, IN USHORT Count)
Definition: testvdd.c:152
VOID WINAPI PortInW(IN USHORT Port, OUT PUSHORT Data)
Definition: testvdd.c:124
VOID WINAPI PortInsB(IN USHORT Port, OUT PUCHAR Data, IN USHORT Count)
Definition: testvdd.c:142
VOID WINAPI PortOutW(IN USHORT Port, IN USHORT Data)
Definition: testvdd.c:133

Definition at line 179 of file testvdd.c.

Referenced by RegisterVDD().