HyperDbg Debugger
Loading...
Searching...
No Matches
platform-lib-calls.h
Go to the documentation of this file.
1
12#pragma once
13
14#if defined(__linux__)
16#endif // defined(__linux__)
17
18#include <stdarg.h>
19#include <stddef.h>
20
21//
22// VSNPRINTF
23//
24INT
25PlatformVsnprintf(char * Buffer, SIZE_T BufferSize, const char * Format, va_list ArgList);
26
27//
28// STRDUP
29//
30char *
31PlatformStrDup(const char * Str);
32
33//
34// SET MEMORY TO ZERO
35//
36VOID
37PlatformZeroMemory(PVOID Buffer, SIZE_T Size);
38
39//
40// SPRINTF
41//
42INT
43PlatformSprintf(char * Buffer, SIZE_T BufferSize, const char * Format, ...);
44
45//
46// HIGH-RESOLUTION PERFORMANCE COUNTER
47//
49PlatformQueryPerformanceFrequency(LARGE_INTEGER * Frequency);
50
52PlatformQueryPerformanceCounter(LARGE_INTEGER * Count);
53
54//
55// EVENT / SYNCHRONIZATION OBJECTS
56//
57HANDLE
58PlatformCreateEvent(BOOLEAN ManualReset, BOOLEAN InitialState);
59
61PlatformSetEvent(HANDLE EventHandle);
62
64PlatformResetEvent(HANDLE EventHandle);
65
67PlatformWaitForSingleObject(HANDLE Handle, DWORD TimeoutMilliseconds);
68
70PlatformCloseHandle(HANDLE Handle);
71
72//
73// LAST OS ERROR
74//
75// TODO (linux, correctness): the wrappers below only unify the success/failure
76// *boolean* convention. The actual error semantics still differ across platforms
77// and must be reconciled later:
78// - PlatformGetLastError returns raw Linux errno (EACCES=13, ...) which does NOT
79// match the Win32 ERROR_* code space (ERROR_ACCESS_DENIED=5, ...). Code that
80// merely logs/checks-nonzero is fine; code that compares against ERROR_* needs
81// an errno -> ERROR_* mapping here.
82// - Failure sentinels are not uniform across the Win32 calls we wrap: file opens
83// fail with INVALID_HANDLE_VALUE (not NULL), most other handle calls fail with
84// NULL. Callers must test the right one.
85// For now: getting the project to compile is step 1; correctness comes next.
86//
89
90//
91// CONSOLE OUTPUT (raw bytes to stdout)
92//
94PlatformWriteConsole(const VOID * Buffer, DWORD NumberOfBytes);
95
96//
97// FILE I/O
98//
99HANDLE
100PlatformOpenFileForWriting(const WCHAR * Path);
101
103PlatformWriteFile(HANDLE FileHandle, const VOID * Buffer, DWORD NumberOfBytes);
104
107
108//
109// READ-ONLY FILE MAPPING
110//
111// PlatformMapFileReadOnly also hands back the still-open file handle in
112// *OutFileHandle, so callers can issue supplementary raw reads via
113// PlatformReadFileAtOffset; release everything with PlatformUnmapFile.
114//
115VOID *
116PlatformMapFileReadOnly(const WCHAR * Path, PSIZE_T OutFileSize, PHANDLE OutFileHandle);
117
119PlatformReadFileAtOffset(HANDLE FileHandle, UINT64 Offset, VOID * Buffer, DWORD NumberOfBytes, LPDWORD BytesRead);
120
121VOID
122PlatformUnmapFile(VOID * BaseAddress, SIZE_T FileSize, HANDLE FileHandle);
123
124//
125// PROCESS / THREAD IDENTITY
126//
127UINT32
129
130UINT32
132
133UINT32
135
136CHAR *
POOL_TYPE SIZE_T NumberOfBytes
Definition Hooks.h:88
PHANDLE FileHandle
Definition SyscallFootprints.h:133
UCHAR BOOLEAN
Definition BasicTypes.h:35
void * PVOID
Definition BasicTypes.h:56
int INT
Definition BasicTypes.h:43
unsigned long DWORD
Definition BasicTypes.h:38
unsigned int UINT32
Definition BasicTypes.h:54
char CHAR
Definition BasicTypes.h:33
BOOLEAN PlatformCloseHandle(HANDLE Handle)
Platform independent wrapper for CloseHandle.
Definition platform-lib-calls.c:334
BOOLEAN PlatformResetEvent(HANDLE EventHandle)
Platform independent wrapper for ResetEvent.
Definition platform-lib-calls.c:295
BOOLEAN PlatformQueryPerformanceCounter(LARGE_INTEGER *Count)
Platform independent wrapper for QueryPerformanceCounter.
Definition platform-lib-calls.c:106
BOOLEAN PlatformWriteFile(HANDLE FileHandle, const VOID *Buffer, DWORD NumberOfBytes)
Platform independent wrapper to write a buffer to an open file.
Definition platform-lib-calls.c:420
BOOLEAN PlatformSetEvent(HANDLE EventHandle)
Platform independent wrapper for SetEvent.
Definition platform-lib-calls.c:279
HANDLE PlatformOpenFileForWriting(const WCHAR *Path)
Platform independent wrapper to create/open a file for writing.
Definition platform-lib-calls.c:392
UINT32 PlatformGetCurrentProcessorNumber(VOID)
Platform independent wrapper for GetCurrentProcessorNumber / sched_getcpu.
Definition platform-lib-calls.c:168
UINT32 PlatformGetCurrentThreadId(VOID)
Platform independent wrapper for GetCurrentThreadId / gettid.
Definition platform-lib-calls.c:151
VOID * PlatformMapFileReadOnly(const WCHAR *Path, PSIZE_T OutFileSize, PHANDLE OutFileHandle)
Platform independent wrapper to map an entire file read-only into memory.
Definition platform-lib-calls.c:463
char * PlatformStrDup(const char *Str)
Platform independent wrapper for _strdup / strdup.
Definition platform-lib-calls.c:51
INT PlatformSprintf(char *Buffer, SIZE_T BufferSize, const char *Format,...)
Platform independent wrapper for sprintf_s / snprintf.
Definition PlatformMem.c:29
BOOLEAN PlatformReadFileAtOffset(HANDLE FileHandle, UINT64 Offset, VOID *Buffer, DWORD NumberOfBytes, LPDWORD BytesRead)
Platform independent wrapper for a positioned (seek + read) file read.
Definition platform-lib-calls.c:549
BOOLEAN PlatformCloseFile(HANDLE FileHandle)
Platform independent wrapper to close a file opened by PlatformOpenFileForWriting.
Definition platform-lib-calls.c:440
VOID PlatformZeroMemory(PVOID Buffer, SIZE_T Size)
Zeros a memory block.
Definition PlatformMem.c:155
BOOLEAN PlatformQueryPerformanceFrequency(LARGE_INTEGER *Frequency)
Platform independent wrapper for QueryPerformanceFrequency.
Definition platform-lib-calls.c:87
DWORD PlatformGetLastError(VOID)
Platform independent wrapper for GetLastError.
Definition platform-lib-calls.c:350
HANDLE PlatformCreateEvent(BOOLEAN ManualReset, BOOLEAN InitialState)
Platform independent wrapper for CreateEvent.
Definition platform-lib-calls.c:257
INT PlatformVsnprintf(char *Buffer, SIZE_T BufferSize, const char *Format, va_list ArgList)
Platform independent wrapper for vsprintf_s / vsnprintf.
Definition platform-lib-calls.c:33
BOOLEAN PlatformWriteConsole(const VOID *Buffer, DWORD NumberOfBytes)
Platform independent wrapper to write raw bytes to the console.
Definition platform-lib-calls.c:374
DWORD PlatformWaitForSingleObject(HANDLE Handle, DWORD TimeoutMilliseconds)
Platform independent wrapper for WaitForSingleObject.
Definition platform-lib-calls.c:313
CHAR * PlatformGetCurrentProcessName(VOID)
Platform independent wrapper to get the current process name.
Definition platform-lib-calls.c:202
UINT32 PlatformGetCurrentProcessId(VOID)
Platform independent wrapper for GetCurrentProcessId / getpid.
Definition platform-lib-calls.c:185
VOID PlatformUnmapFile(VOID *BaseAddress, SIZE_T FileSize, HANDLE FileHandle)
Platform independent wrapper to release a mapping from PlatformMapFileReadOnly.
Definition platform-lib-calls.c:589