HyperDbg Debugger
Loading...
Searching...
No Matches
MetaMacros.h
Go to the documentation of this file.
1
12#pragma once
13
14#define MetaScopedExpr(Pre_, Post_, ScopedExpr_) \
15 do \
16 { \
17 Pre_; \
18 ScopedExpr_; \
19 Post_; \
20 } while (FALSE);
21
22//
23// Linked-List
24//
25
26//
27// borrowed from
28// https://github.com/hvmi/hvmi/blob/master/introcore/include/hlist.h
29// https://github.com/hvmi/hvmi/blob/master/introcore/src/introcore.c
30//
31
32#define LIST_FOR_EACH(_head, _struct_type, _var) _LIST_FOR_EACH(_head, _struct_type, Link, _var)
33#define LIST_FOR_NEXT(_start, _head, _type, _var) _LIST_FOR_NEXT(_start, _head, _type, Link, _var)
34#define LIST_FOR_EACH_LINK(_head, _struct_type, _member, _var) _LIST_FOR_EACH(_head, _struct_type, _member, _var)
35
36//
37// Conversion
38//
39#define HANDLE_TO_UINT32(_var) (UINT32)((UINT64)_var & 0xffffffff)
40#define PVOID_TO_BOOLEAN(_var) (BOOLEAN)((UINT64)_var & 0xff)
41
42//
43// RAW versions, use only if really needed
44//
45#define _NEXT(_var, _member) _var->_member.Flink
46#define _NEXT_ENTRY(_var, _member, _type) CONTAINING_RECORD(_NEXT(_var, _member), _type, _member)
47
48#define PREPROC_CONCAT(a, b) PREPROC_CONCAT_1(a, b)
49#define PREPROC_CONCAT_1(a, b) PREPROC_CONCAT_2(~, a##b)
50#define PREPROC_CONCAT_2(p, res) res
51
52#define UNIQUE_NAME(base) PREPROC_CONCAT(base, __LINE__)
53
54#define _LIST_FOR_EACH(_head, _type, _member, _var) \
55 for (_type * _var = CONTAINING_RECORD(_head.Flink, _type, _member), *UNIQUE_NAME(_n) = _NEXT_ENTRY(_var, _member, _type); \
56 &_var->_member != &_head; \
57 _var = UNIQUE_NAME(_n), UNIQUE_NAME(_n) = _NEXT_ENTRY(_var, _member, _type))
58
59#define _LIST_FOR_NEXT(_start, _head, _type, _member, _var) \
60 for (_type * _var = _NEXT_ENTRY(_start, _member, _type), *UNIQUE_NAME(_n) = _NEXT_ENTRY(_var, _member, _type); \
61 &_var->_member != &_head; \
62 _var = UNIQUE_NAME(_n), UNIQUE_NAME(_n) = _NEXT_ENTRY(_var, _member, _type))