CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/byakugan/heapStructs.h
Views: 11766
1
#define ALLOCATESTRUCT 0x0
2
#define REALLOCATESTRUCT 0x1
3
#define FREESTRUCT 0x2
4
#define CREATESTRUCT 0x3
5
#define DESTROYSTRUCT 0x4
6
#define COALESCESTRUCT 0x5
7
8
#define SPACEBETWEEN 0x18
9
10
#define CHUNK(x) (heap->chunks[x])
11
12
#define NEXTADDR(x) (PVOID)(*((ULONG *)(&(CHUNK(i).addr))) + CHUNK(i).size + SPACEBETWEEN)
13
14
#define NULLNODE 0xffffffff
15
16
#define MODEL 1
17
#define LOG 2
18
#define RUNNING 4
19
20
// Space between chunks on vista
21
22
// Dont use a direct access list here because looping should
23
// be faster for our number of heaps (I think!)
24
struct HeapState {
25
BYTE state;
26
ULONG numHeaps;
27
ULONG hPoolListLen;
28
HANDLE hLogFile;
29
struct HPool *heaps;
30
31
};
32
33
struct HPool {
34
PVOID base;
35
ULONG numChunks;
36
ULONG chunkListLen;
37
ULONG flags;
38
ULONG reserve;
39
ULONG commit;
40
BOOLEAN lock;
41
ULONG *map;
42
struct HeapChunk *chunks;
43
ULONG inUseHead;
44
ULONG lastInUse;
45
BOOLEAN inUse;
46
};
47
48
struct LookAsideList {
49
DWORD placeHolder;
50
};
51
52
struct HeapCache {
53
ULONG NumBuckets;
54
unsigned __int8 *pBitmap;
55
ULONG **pBuckets;
56
};
57
58
struct HeapChunk {
59
PVOID addr;
60
PVOID heapHandle;
61
ULONG size;
62
ULONG flags;
63
ULONG nextBucket;
64
ULONG nextInUse;
65
ULONG nextFreeListChunk;
66
BOOLEAN free;
67
BOOLEAN inUse;
68
};
69
70
struct AllocateStruct {
71
BYTE type;
72
PVOID heapHandle;
73
ULONG flags;
74
ULONG size;
75
PVOID ret;
76
PVOID caller;
77
};
78
79
struct ReallocateStruct {
80
BYTE type;
81
PVOID heapHandle;
82
ULONG flags;
83
PVOID memoryPointer;
84
ULONG size;
85
PVOID ret;
86
PVOID caller;
87
};
88
89
struct FreeStruct {
90
BYTE type;
91
PVOID heapHandle;
92
ULONG flags;
93
PVOID memoryPointer;
94
PVOID ret;
95
PVOID caller;
96
};
97
98
struct CreateStruct {
99
BYTE type;
100
ULONG flags;
101
PVOID base;
102
ULONG reserve;
103
ULONG commit;
104
BOOLEAN lock;
105
PVOID RtlHeapParams; // Wont get this info back now - maybe later
106
PVOID ret; // if we think we really need it?
107
108
};
109
110
struct DestroyStruct {
111
BYTE type;
112
PVOID heapHandle;
113
NTSTATUS ret;
114
};
115
116
struct CoalesceStruct {
117
BYTE type;
118
PVOID heapHandle;
119
ULONG arg2;
120
ULONG arg3;
121
ULONG arg4;
122
PVOID ret;
123
};
124
125
void initializeHeapModel(struct HeapState *);
126
void heapAllocate(struct HeapState *heapModel, struct AllocateStruct *aStruct);
127
void logAllocate(struct HeapState *heapModel, struct AllocateStruct *aStruct);
128
129
void heapReallocate(struct HeapState *heapModel, struct ReallocateStruct *aStruct);
130
void logReallocate(struct HeapState *heapModel, struct ReallocateStruct *aStruct);
131
132
void heapFree(struct HeapState *heapModel, struct FreeStruct *fStruct);
133
void logFree(struct HeapState *heapModel, struct FreeStruct *fStruct);
134
135
void heapCreate(struct HeapState *heapModel, struct CreateStruct *cStruct);
136
void heapDestroy(struct HeapState *heapModel, struct DestroyStruct *dStruct);
137
void heapCoalesce(struct HeapState *heapModel, struct CoalesceStruct *cfbStruct);
138
struct HPool *getHeap(struct HeapState *heapModel, PVOID heapHandle);
139
struct HeapChunk *getChunk(struct HPool *heap, PVOID memoryPointer, ULONG inAfter);
140
int FindOffsetForChunk(struct HPool *heap, PVOID memoryPointer); //quickly match a (heap, chunkAddress) into an offset in heap.chunks
141
142
143