-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.h
82 lines (65 loc) · 2.08 KB
/
helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include <vector>
#include <string>
#define MEMORY_DEBUGGING 0
#if MEMORY_DEBUGGING
void* xalloc (size_t cb);
void xfree (void* p);
#define malloc xalloc
#define free xfree
char* _mstrdup (const char* szSrc);
#define _strdup _mstrdup
#endif
char* strndup (const char* str, size_t n);
typedef struct COFF_SYMBOL_TABLE
{
SIZE_T NumberOfSymbols;
#pragma warning(disable:4200)
IMAGE_SYMBOL Symbols[0];
#pragma warning(default:4200)
} COFF_SYMBOL_TABLE, *PCOFF_SYMBOL_TABLE;
//
//
// PCOFF_SYMBOL_TABLE SYMCreate (size_t cSyms);
// PCOFF_SYMBOL_TABLE SYMFromCoffSyms (PIMAGE_SYMBOL SymTbl, size_t cSyms);
// PCOFF_SYMBOL_TABLE SYMFromVector (std::vector<IMAGE_SYMBOL> &syms);
// PCOFF_SYMBOL_TABLE SYMDuplicate (PCOFF_SYMBOL_TABLE SymTbl);
// PIMAGE_SYMBOL SYMGetSymbol (PCOFF_SYMBOL_TABLE pSym, unsigned iSym);
// void SYMDestroy (PCOFF_SYMBOL_TABLE pSym);
// void SYMSetSymbol (PCOFF_SYMBOL_TABLE pSym, unsigned iSym, PIMAGE_SYMBOL Sym);
// size_t SYMGetSymsCount (PCOFF_SYMBOL_TABLE pSym);
// DWORD SYMGetIndex (PCOFF_SYMBOL_TABLE pSym, PIMAGE_SYMBOL Sym);
// size_t SYMStore (PCOFF_SYMBOL_TABLE pSym, void *pBuffer);
// PCOFF_SYMBOL_TABLE SYMConcat (PCOFF_SYMBOL_TABLE pOne, PCOFF_SYMBOL_TABLE pOther);
// PIMAGE_SYMBOL SYMFirstSymbol (PCOFF_SYMBOL_TABLE pSym);
// PIMAGE_SYMBOL SYMLastSymbol (PCOFF_SYMBOL_TABLE pSym);
// void SYMToVector (PCOFF_SYMBOL_TABLE pSym, std::vector<IMAGE_SYMBOL> &syms);
void FreeSymName (PSZ szSymName);
typedef struct MEMBLOCK
{
PVOID pBuf;
SIZE_T cBuf;
} MEMBLOCK, *PMEMBLOCK;
inline MEMBLOCK MemBlock (PVOID p, SIZE_T cb)
{
MEMBLOCK mb = {p, cb};
return mb;
}
MEMBLOCK AllocateMemBlock (SIZE_T cb);
void FreeMemBlock (MEMBLOCK mb);
static void WriteBuff (HANDLE hFile, PVOID pb, SIZE_T cb)
{
DWORD wr = 0;
if (!WriteFile (hFile, pb, cb, &wr, 0))
__debugbreak();
if (wr < cb)
__debugbreak();
}
static void WriteBlock (HANDLE hFile, MEMBLOCK &mb)
{
DWORD wr = 0;
if (!WriteFile (hFile, mb.pBuf, mb.cBuf, &wr, 0))
__debugbreak();
if (wr < mb.cBuf)
__debugbreak();
}