Bitdefender Hypervisor Memory Introspection
codeblocks.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #ifndef _CODEBLOCKS_H_
6 #define _CODEBLOCKS_H_
7 
8 #include "exceptions.h"
9 
10 
14 typedef enum
15 {
19 
20 
24 typedef enum
25 {
39 } CODE_INS;
40 
41 
43 #define CODE_BLOCK_CHUNKS_COUNT 8
44 
45 
51 typedef struct _CODE_BLOCK
52 {
60 
61 
62 #pragma pack(push)
63 #pragma pack(1)
64 
68 typedef struct _CODE_BLOCK_PATTERN
69 {
73 #pragma pack(pop)
74 
75 
76 //
77 // API
78 //
81  _In_reads_(MaxBufferSize) BYTE *Buffer,
82  _In_ DWORD MaxBufferSize,
83  _In_ IG_CS_TYPE CsType,
84  _In_ CB_EXTRACT_LEVEL ExtractLevel,
85  _In_ DWORD PatternSize,
86  _Out_writes_to_(PatternSize, *TotalExtracted) BYTE *Pattern,
87  _Out_ DWORD *TotalExtracted,
88  _Inout_ DWORD *TotalParsed
89  );
90 
93  _In_reads_(MaxBufferSize) BYTE *Buffer,
94  _In_ DWORD MaxBufferSize,
95  _In_ IG_CS_TYPE CsType,
96  _In_ CB_EXTRACT_LEVEL ExtractLevel,
97  _Inout_ DWORD *HashesCount,
98  _Out_writes_(*HashesCount) DWORD *Hashes
99  );
100 
103  _In_ const DWORD *Hashes,
104  _In_ DWORD CodeBlocksCount,
105  _In_ const SIG_CODEBLOCKS *ExceptionSignature
106  );
107 
108 INTSTATUS
110  _In_ PBYTE Buffer,
111  _In_ DWORD StartOffset,
112  _In_ DWORD MaxBufferSize,
113  _In_ IG_CS_TYPE CsType,
114  _In_ CB_EXTRACT_LEVEL ExtractLevel,
115  _In_ DWORD PatternSize,
116  _Out_writes_to_(PatternSize, *TotalExtracted) CODE_BLOCK_PATTERN *Pattern,
117  _Out_ DWORD *TotalExtracted
118  );
119 
120 INTSTATUS
122  _In_ PBYTE Buffer,
123  _In_ QWORD StartAddress,
124  _In_ DWORD MaxBufferSize,
125  _In_ IG_CS_TYPE CsType,
126  _In_ CB_EXTRACT_LEVEL ExtractLevel,
127  _In_ QWORD Rip,
128  _In_ BOOLEAN ReturnRip
129  );
130 
131 #endif // _CODEBLOCKS_H_
_Bool BOOLEAN
Definition: intro_types.h:58
#define _Out_
Definition: intro_sal.h:22
A mov using a segment:offset.
Definition: codeblocks.h:37
uint8_t BYTE
Definition: intro_types.h:47
INTSTATUS IntFragExtractCodePattern(PBYTE Buffer, DWORD StartOffset, DWORD MaxBufferSize, IG_CS_TYPE CsType, CB_EXTRACT_LEVEL ExtractLevel, DWORD PatternSize, CODE_BLOCK_PATTERN *Pattern, DWORD *TotalExtracted)
Extract a pattern of code-blocks from the given code buffer.
Definition: codeblocks.c:990
#define _In_
Definition: intro_sal.h:21
struct _CODE_BLOCK_PATTERN CODE_BLOCK_PATTERN
BYTE PivotInstruction
Definition: codeblocks.h:56
uint16_t WORD
Definition: intro_types.h:48
Non-conditional jump, of any kind.
Definition: codeblocks.h:28
DWORD OffsetStart
The start of the extracted codeblock (not actually relevant)
Definition: codeblocks.h:53
INTSTATUS IntFragExtractCodeBlocks(BYTE *Buffer, DWORD MaxBufferSize, IG_CS_TYPE CsType, CB_EXTRACT_LEVEL ExtractLevel, DWORD *HashesCount, DWORD *Hashes)
Extract a block of code-block hashes from the given code buffer.
Definition: codeblocks.c:746
WORD Size
Code block size, in patterns.
Definition: codeblocks.h:55
#define _In_reads_(expr)
Definition: intro_sal.h:27
#define __pure
Definition: introtypes.h:46
Ret, of any kind.
Definition: codeblocks.h:30
DWORD Offset
The offset of the instruction in the page.
Definition: codeblocks.h:70
#define CODE_BLOCK_CHUNKS_COUNT
Number of chunks (CODE_INS) per codeblock.
Definition: codeblocks.h:43
A mov using immediate value.
Definition: codeblocks.h:36
int INTSTATUS
The status data type.
Definition: introstatus.h:24
__pure INTSTATUS IntFragMatchSignature(const DWORD *Hashes, DWORD CodeBlocksCount, const SIG_CODEBLOCKS *ExceptionSignature)
Match a block of code-block hashes against a list of code-block exception signatures.
Definition: codeblocks.c:912
CB_EXTRACT_LEVEL
Definition: codeblocks.h:14
#define _Out_writes_(expr)
Definition: intro_sal.h:28
Exchange instruction, including xchg, xadd, cmpxchg, cmpxchg8b/16b.
Definition: codeblocks.h:32
Bit manipulation instruction - bt, bts, btr, btc.
Definition: codeblocks.h:33
Push/Pop flags.
Definition: codeblocks.h:38
BYTE Chunks[CODE_BLOCK_CHUNKS_COUNT]
The actual CODE_INS values representing the instruction pattern.
Definition: codeblocks.h:58
INTSTATUS IntFragDumpBlocks(PBYTE Buffer, QWORD StartAddress, DWORD MaxBufferSize, IG_CS_TYPE CsType, CB_EXTRACT_LEVEL ExtractLevel, QWORD Rip, BOOLEAN ReturnRip)
Dumps code-blocks that can then be used to generate an exception signature.
Definition: codeblocks.c:1293
IG_CS_TYPE
The type of the code segment.
Definition: glueiface.h:183
#define _Inout_
Definition: intro_sal.h:20
uint8_t * PBYTE
Definition: intro_types.h:47
Conditional jump, of any kind, including loop.
Definition: codeblocks.h:27
unsigned long long QWORD
Definition: intro_types.h:53
CODE_INS
Definition: codeblocks.h:24
This includes instructions until codeInsBt.
Definition: codeblocks.h:16
Not really used, only to signal an error.
Definition: codeblocks.h:26
BYTE Value
The CODE_INS value describing the instruction type.
Definition: codeblocks.h:71
DWORD Hash
The hash will be computed on Chunks array.
Definition: codeblocks.h:54
This includes instructions until codeInsFlags.
Definition: codeblocks.h:17
uint32_t DWORD
Definition: intro_types.h:49
Some sort of string instruction - lods, stos, scas, movs.
Definition: codeblocks.h:31
Call, of any kind.
Definition: codeblocks.h:29
INTSTATUS IntFragExtractPattern(BYTE *Buffer, DWORD MaxBufferSize, IG_CS_TYPE CsType, CB_EXTRACT_LEVEL ExtractLevel, DWORD PatternSize, BYTE *Pattern, DWORD *TotalExtracted, DWORD *TotalParsed)
Extract a pattern of code-blocks from the given code buffer.
Definition: codeblocks.c:502
struct _CODE_BLOCK CODE_BLOCK
struct _CODE_BLOCK * PCODE_BLOCK
A mov involving only registers.
Definition: codeblocks.h:34
#define _Out_writes_to_(expr, expr2)
Definition: intro_sal.h:29
A mov involving memory (either as the destination or as the source).
Definition: codeblocks.h:35
Describes a codeblocks signature.
Definition: exceptions.h:397
struct _CODE_BLOCK_PATTERN * PCODE_BLOCK_PATTERN