Rizin
unix-like reverse engineering framework and cli tools
test_winkernel.cpp File Reference
#include <ntddk.h>
#include <capstone/platform.h>
#include <capstone/capstone.h>
#include "../utils.h"
#include "test_basic.c"
#include "test_detail.c"
#include "test_skipdata.c"
#include "test_iter.c"
#include "test_customized_mnem.c"
#include "test_arm.c"
#include "test_arm64.c"
#include "test_mips.c"
#include "test_m68k.c"
#include "test_ppc.c"
#include "test_sparc.c"
#include "test_systemz.c"
#include "test_x86.c"
#include "test_xcore.c"

Go to the source code of this file.

Namespaces

 basic
 
 detail
 
 skipdata
 
 iter
 
 customized_mnem_
 
 arm
 
 arm64
 
 mips
 
 m68k
 
 ppc
 
 sparc
 
 systemz
 
 x86
 
 xcore
 

Functions

static void test ()
 
static void cs_winkernel_vsnprintf_test ()
 
EXTERN_C NTSTATUS DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 
_Use_decl_annotations_ int __cdecl printf (const char *const format,...)
 

Variables

EXTERN_C DRIVER_INITIALIZE DriverEntry
 

Function Documentation

◆ cs_winkernel_vsnprintf_test()

static void cs_winkernel_vsnprintf_test ( )
static

Definition at line 135 of file test_winkernel.cpp.

136 {
137  char buf[10];
138  bool ok = true;
139  ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "") == 0 && strcmp(buf, "") == 0);
140  ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "0") == 1 && strcmp(buf, "0") == 0);
141  ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "012345678") == 9 && strcmp(buf, "012345678") == 0);
142  ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "0123456789") == 10 && strcmp(buf, "012345678") == 0);
143  ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "01234567890") == 11 && strcmp(buf, "012345678") == 0);
144  ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "0123456789001234567890") == 22 && strcmp(buf, "012345678") == 0);
145  if (!ok) {
146  printf("ERROR: cs_winkernel_vsnprintf_test() did not produce expected results!\n");
147  }
148 }
voidpf void * buf
Definition: ioapi.h:138
@ ok
Definition: lz4.c:1706
int cs_snprintf(char *buffer, size_t size, const char *fmt,...)
Definition: utils.c:104
_Use_decl_annotations_ int __cdecl printf(const char *const format,...)

References cs_snprintf(), ok, and printf().

Referenced by DriverEntry().

◆ DriverEntry()

EXTERN_C NTSTATUS DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 151 of file test_winkernel.cpp.

152 {
153  UNREFERENCED_PARAMETER(DriverObject);
154  UNREFERENCED_PARAMETER(RegistryPath);
156  test();
157  return STATUS_CANCELLED;
158 }
static void cs_winkernel_vsnprintf_test()
static void test()
#define STATUS_CANCELLED
Definition: winapi.h:1824

References cs_winkernel_vsnprintf_test(), STATUS_CANCELLED, and test().

◆ printf()

_Use_decl_annotations_ int __cdecl printf ( const char *const  format,
  ... 
)

Definition at line 163 of file test_winkernel.cpp.

164 {
166  va_list args;
167 
168  va_start(args, format);
169  status = vDbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, format, args);
170  va_end(args);
171  return NT_SUCCESS(status);
172 }
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
int args
Definition: mipsasm.c:18
LONG NTSTATUS
Definition: win.h:198
#define NT_SUCCESS(status)
Definition: winapi.h:52

References args, NT_SUCCESS, and status.

Referenced by cs_winkernel_vsnprintf_test(), and test().

◆ test()

static void test ( )
static

Definition at line 94 of file test_winkernel.cpp.

95 {
96  KFLOATING_SAVE float_save;
98 
99  // Any of Capstone APIs cannot be called at IRQL higher than DISPATCH_LEVEL
100  // since our malloc implementation using ExAllocatePoolWithTag() is able to
101  // allocate memory only up to the DISPATCH_LEVEL level.
102  NT_ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
103 
104  // On a 32bit driver, KeSaveFloatingPointState() is required before using any
105  // Capstone function because Capstone can access to the MMX/x87 registers and
106  // 32bit Windows requires drivers to use KeSaveFloatingPointState() before and
107  // KeRestoreFloatingPointState() after accessing them. See "Using Floating
108  // Point or MMX in a WDM Driver" on MSDN for more details.
109  status = KeSaveFloatingPointState(&float_save);
110  if (!NT_SUCCESS(status)) {
111  printf("ERROR: Failed to save floating point state!\n");
112  return;
113  }
114 
115  basic::test();
116  detail::test();
117  skipdata::test();
118  iter::test();
120  arm::test();
121  arm64::test();
122  mips::test();
123  m68k::test();
124  ppc::test();
125  sparc::test();
126  systemz::test();
127  x86::test();
128  xcore::test();
129 
130  // Restores the nonvolatile floating-point context.
131  KeRestoreFloatingPointState(&float_save);
132 }
KeRestoreFloatingPointState
Definition: kernel.h:142
KeSaveFloatingPointState
Definition: kernel.h:145
KeGetCurrentIrql
Definition: kernel.h:106

References KeGetCurrentIrql, KeRestoreFloatingPointState, KeSaveFloatingPointState, NT_SUCCESS, printf(), and status.

Referenced by DriverEntry().

Variable Documentation

◆ DriverEntry

EXTERN_C DRIVER_INITIALIZE DriverEntry

Definition at line 19 of file test_winkernel.cpp.