mirror of
https://github.com/xec412/NocturneLdr
synced 2026-07-27 17:18:43 +00:00
1516 lines
47 KiB
C++
1516 lines
47 KiB
C++
#pragma once
|
|
#ifndef STRUCTS_H
|
|
#define STRUCTS_H
|
|
|
|
#include <Windows.h>
|
|
|
|
/*===================================
|
|
# Status Codes
|
|
=====================================*/
|
|
#define STATUS_SUCCESS 0x00000000
|
|
#define STATUS_UNSUCCESSFULL 0xC0000001
|
|
#define STATUS_INFO_LENGTH_MISMATCH 0xC0000004
|
|
#define STATUS_NOT_FOUND 0xC0000225
|
|
|
|
/*===================================
|
|
# NT Macros
|
|
=====================================*/
|
|
#define NtCurrentProcess() ((HANDLE)-1)
|
|
#define NtCurrentThread() ((HANDLE)-2)
|
|
#define NtCurrentTeb() ((TEB*)__readgsqword(0x30))
|
|
#define NT_SUCCESS(STATUS) (((NTSTATUS)(STATUS)) >= STATUS_SUCCESS)
|
|
#define CURRENT_PROCESS ((HANDLE)0xFFFFFFFFFFFFFFFF)
|
|
|
|
/*===================================
|
|
# Alignment Macros
|
|
=====================================*/
|
|
#define ALIGN_UP(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
|
|
#define ALIGN_UP_POW2(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
|
|
|
|
/*===================================
|
|
# Bit Macros
|
|
=====================================*/
|
|
#define BitVal(data, y) ((data >> y) & 1)
|
|
#define BitChainInfo(data) BitVal(data, 2)
|
|
#define BitUHandler(data) BitVal(data, 1)
|
|
#define BitEHandler(data) BitVal(data, 0)
|
|
|
|
/*===================================
|
|
# Unwind Macros
|
|
=====================================*/
|
|
#define MAX_FRAMES 154
|
|
#define HIDWORD(l) ((DWORD)(((DWORDLONG)(l) >> 32) & 0xFFFFFFFF))
|
|
#define Version(data) (BitVal(data, 4) * 2 + BitVal(data, 3))
|
|
|
|
#define GetUnwindCodeEntry(info, index) \
|
|
((info)->UnwindCode[index])
|
|
|
|
#define GetLanguageSpecificDataPtr(info) \
|
|
((PVOID)&GetUnwindCodeEntry((info), ((info)->CountOfCodes + 1) & ~1))
|
|
|
|
#define GetExceptionHandlerPtr(info) \
|
|
((PULONG)GetLanguageSpecificDataPtr(info) - 1)
|
|
|
|
#define GetExceptionHandler(base, info) \
|
|
((PVOID)((ULONG64)(base) + *GetExceptionHandlerPtr(info)))
|
|
|
|
#define GetChainedFunctionEntry(base, info) \
|
|
((PRUNTIME_FUNCTION)GetExceptionHandlerPtr(info))
|
|
|
|
#define GetExceptionDataPtr(info) \
|
|
GetLanguageSpecificDataPtr(info)
|
|
|
|
/*===================================
|
|
# Flags
|
|
=====================================*/
|
|
#define UNWIND_DATA_TAMPER 0x000f0000
|
|
#define UNWIND_DATA_HIJACK 0x0000f000
|
|
#define RT_FUNCTION_HIJACK 0x00000f00
|
|
#define RT_FUNCTION_INJECT 0x000000f0
|
|
#define RTFI_JIT_SYSINFORMER 0x0000000f
|
|
#define RTFI_JIT_WINDBG 0x0f000000
|
|
#define RTFI_JIT_NORMAL_VA 0x00f00000
|
|
|
|
/*===================================
|
|
# Call Instruction Patterns
|
|
=====================================*/
|
|
#define CALL_NEAR 0xE8
|
|
#define CALL_NEAR_QPTR 0xFF15
|
|
#define CALL_FAR_QPTR 0x0015FF48
|
|
|
|
/*===================================
|
|
# Sleep Obfuscation
|
|
=====================================*/
|
|
typedef struct _USTRING {
|
|
DWORD Length;
|
|
DWORD MaximumLength;
|
|
PBYTE Buffer;
|
|
} USTRING, * PUSTRING;
|
|
|
|
typedef struct _SLEEP_CONTEXT {
|
|
PVOID pModule; // Sacrificial DLL base
|
|
PVOID pTextBase; // Loader .text base
|
|
SIZE_T szTextSize; // Loader .text size
|
|
HANDLE hPayloadThread; // Payload thread handle
|
|
HANDLE hHeap; // Process heap
|
|
BYTE Key[16]; // RC4 key
|
|
DWORD dwKeySize; // Key size
|
|
DWORD dwSleepMs; // Sleep interval
|
|
} SLEEP_CONTEXT, * PSLEEP_CONTEXT;
|
|
|
|
/*===================================
|
|
# Unwind Flags
|
|
=====================================*/
|
|
#ifndef UNW_FLAG_EHANDLER
|
|
#define UNW_FLAG_EHANDLER 0x01
|
|
#define UNW_FLAG_UHANDLER 0x02
|
|
#define UNW_FLAG_CHAININFO 0x04
|
|
#endif
|
|
|
|
/*===================================
|
|
# Function Pointer Typedefs
|
|
=====================================*/
|
|
typedef VOID(NTAPI* fnLdrProtectMrdata)(_In_ BOOL Protect);
|
|
typedef VOID(NTAPI* fnRtlAcquireSRWLockExclusive)(_Inout_ PRTL_SRWLOCK SRWLock);
|
|
typedef VOID(NTAPI* fnRtlReleaseSRWLockExclusive)(_Inout_ PRTL_SRWLOCK SRWLock);
|
|
typedef NTSTATUS(NTAPI* fnSystemFunction032)(_Inout_ PUSTRING Data, _In_ PUSTRING Key);
|
|
|
|
/*===================================
|
|
# Typedefs
|
|
=====================================*/
|
|
typedef unsigned char UBYTE;
|
|
typedef unsigned char* PUBYTE;
|
|
|
|
/*===================================
|
|
# Unwind Structures
|
|
=====================================*/
|
|
typedef union _UNWIND_CODE {
|
|
struct {
|
|
UBYTE CodeOffset;
|
|
UBYTE UnwindOp : 4;
|
|
UBYTE OpInfo : 4;
|
|
};
|
|
USHORT FrameOffset;
|
|
} UNWIND_CODE, *PUNWIND_CODE;
|
|
|
|
typedef struct _UNWIND_INFO {
|
|
UBYTE Version : 3;
|
|
UBYTE Flags : 5;
|
|
UBYTE SizeOfProlog;
|
|
UBYTE CountOfCodes;
|
|
UBYTE FrameRegister : 4;
|
|
UBYTE FrameOffset : 4;
|
|
UNWIND_CODE UnwindCode[1];
|
|
} UNWIND_INFO, *PUNWIND_INFO;
|
|
|
|
typedef struct _UNWIND_BACKUP {
|
|
PUNWIND_INFO pOriginalLocation;
|
|
DWORD dwSize;
|
|
UBYTE Data[1];
|
|
} UNWIND_BACKUP, *PUNWIND_BACKUP;
|
|
|
|
typedef struct _RUNTIME_FUNCTION_BACKUP {
|
|
PRUNTIME_FUNCTION pOriginalLocation;
|
|
RUNTIME_FUNCTION Data;
|
|
} RUNTIME_FUNCTION_BACKUP, *PRUNTIME_FUNCTION_BACKUP;
|
|
|
|
typedef struct _UNWIND_BUILD_PARAMS {
|
|
DWORD dwStackSize;
|
|
UBYTE numInstructions;
|
|
UBYTE flags;
|
|
BOOL useFpreg;
|
|
UBYTE fpReg;
|
|
UBYTE fpOffset;
|
|
} UNWIND_BUILD_PARAMS, *PUNWIND_BUILD_PARAMS;
|
|
|
|
/*===================================
|
|
# Unwind Op Codes
|
|
=====================================*/
|
|
typedef enum _UNWIND_OP_CODES {
|
|
// x86_64. https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64.
|
|
UWOP_PUSH_NONVOL = 0,
|
|
UWOP_ALLOC_LARGE, // 1
|
|
UWOP_ALLOC_SMALL, // 2
|
|
UWOP_SET_FPREG, // 3
|
|
UWOP_SAVE_NONVOL, // 4
|
|
UWOP_SAVE_NONVOL_BIG, // 5
|
|
UWOP_EPILOG, // 6
|
|
UWOP_SPARE_CODE, // 7
|
|
UWOP_SAVE_XMM128, // 8
|
|
UWOP_SAVE_XMM128BIG, // 9
|
|
UWOP_PUSH_MACH_FRAME, // 10
|
|
} UNWIND_CODE_OPS;
|
|
|
|
/* ---------------------------------------------------------------
|
|
* Change record types
|
|
* --------------------------------------------------------------- */
|
|
typedef enum _BYOUD_CHANGE_TYPE {
|
|
BCT_NONE = 0,
|
|
BCT_CACHE_ZERO,
|
|
BCT_PDATA_PROTECT,
|
|
BCT_PDATA_NOACCESS,
|
|
BCT_INVERTED_TABLE_SHRINK,
|
|
BCT_DYNAMIC_TABLE_ADD,
|
|
BCT_DYNAMIC_TABLE_TYPE,
|
|
BCT_RUNTIME_FUNCTION,
|
|
BCT_UNWIND_INFO,
|
|
BCT_SHELLCODE_APPENDED,
|
|
BCT_SHELLCODE_VIRTUALALLOC,
|
|
} BYOUD_CHANGE_TYPE;
|
|
|
|
/* ---------------------------------------------------------------
|
|
* Per-change payload
|
|
* --------------------------------------------------------------- */
|
|
typedef struct _BYOUD_CHANGE {
|
|
BYOUD_CHANGE_TYPE Type;
|
|
|
|
union {
|
|
struct { ULONG64 Address; DWORD OldValue; } Cache;
|
|
struct { PVOID pModule; PVOID Base; SIZE_T Size; DWORD OldProtect; } Pdata;
|
|
struct { PVOID pModule; ULONG OldImageSize; } InvertedTable;
|
|
struct { PRUNTIME_FUNCTION pFunctionTable; } DynamicAdd;
|
|
struct { PVOID pEntry; DWORD OldType; } DynamicType;
|
|
struct {
|
|
PVOID pModule; PRUNTIME_FUNCTION pOriginalLocation;
|
|
RUNTIME_FUNCTION OldValue;
|
|
} RuntimeFunction;
|
|
struct { PVOID pLocation; PVOID pBackup; DWORD Size; } UnwindInfo;
|
|
struct { PVOID pModule; PVOID pAddress; DWORD Size; } ShellcodeAppended;
|
|
struct { PVOID pAddress; SIZE_T Size; } ShellcodeVA;
|
|
} u;
|
|
} BYOUD_CHANGE, * PBYOUD_CHANGE;
|
|
|
|
/* ---------------------------------------------------------------
|
|
* Change log
|
|
* --------------------------------------------------------------- */
|
|
#define BYOUD_MAX_CHANGES 32
|
|
|
|
typedef struct _BYOUD_CONTEXT {
|
|
BYOUD_CHANGE Changes[BYOUD_MAX_CHANGES];
|
|
DWORD Count;
|
|
DWORD Technique;
|
|
PVOID pTargetModule;
|
|
PVOID pShellcodeAddress;
|
|
DWORD ShellcodeSize;
|
|
} BYOUD_CONTEXT, * PBYOUD_CONTEXT;
|
|
|
|
|
|
/*===================================
|
|
# Register Numbers
|
|
=====================================*/
|
|
typedef enum _REGISTERS {
|
|
RAX = 0, RCX, RDX, RBX,
|
|
RSP, RBP, RSI, RDI,
|
|
R8, R9, R10, R11,
|
|
R12, R13, R14, R15
|
|
} REGISTERS;
|
|
|
|
/*===================================
|
|
# Min Context
|
|
=====================================*/
|
|
typedef struct _MIN_CTX {
|
|
DWORD64 Rax;
|
|
DWORD64 Rcx;
|
|
DWORD64 Rdx;
|
|
DWORD64 Rbx;
|
|
DWORD64 Rsp;
|
|
DWORD64 Rbp;
|
|
DWORD64 Rsi;
|
|
DWORD64 Rdi;
|
|
DWORD64 R8;
|
|
DWORD64 R9;
|
|
DWORD64 R10;
|
|
DWORD64 R11;
|
|
DWORD64 R12;
|
|
DWORD64 R13;
|
|
DWORD64 R14;
|
|
DWORD64 R15;
|
|
DWORD64 Rip;
|
|
DWORD64 Reserved;
|
|
DWORD64 StackSize;
|
|
} MIN_CTX, *PMIN_CTX;
|
|
|
|
/*===================================
|
|
# Section Info
|
|
=====================================*/
|
|
typedef struct _SECTION_INFO {
|
|
PVOID VirtualAddress;
|
|
SIZE_T VirtualSize;
|
|
} SECTION_INFO, *PSECTION_INFO;
|
|
|
|
/*===================================
|
|
# Dynamic Function Table
|
|
=====================================*/
|
|
typedef struct _RTL_BALANCED_NODE {
|
|
union {
|
|
struct _RTL_BALANCED_NODE* Children[2];
|
|
struct {
|
|
struct _RTL_BALANCED_NODE* Left;
|
|
struct _RTL_BALANCED_NODE* Right;
|
|
};
|
|
};
|
|
union {
|
|
UCHAR Red : 1;
|
|
UCHAR Balance : 2;
|
|
ULONG64 ParentValue;
|
|
};
|
|
} RTL_BALANCED_NODE, *PRTL_BALANCED_NODE;
|
|
|
|
typedef struct _DYNAMIC_FUNCTION_TABLE {
|
|
LIST_ENTRY Links;
|
|
PRUNTIME_FUNCTION FunctionTable;
|
|
LARGE_INTEGER TimeStamp;
|
|
ULONG64 MinimumAddress;
|
|
ULONG64 MaximumAddress;
|
|
ULONG64 BaseAddress;
|
|
PVOID Callback;
|
|
PVOID Context;
|
|
PWSTR OutOfProcessCallbackDll;
|
|
DWORD Type;
|
|
DWORD EntryCount;
|
|
} DYNAMIC_FUNCTION_TABLE, *PDYNAMIC_FUNCTION_TABLE;
|
|
|
|
/*===================================
|
|
# Inverted Function Table
|
|
=====================================*/
|
|
typedef struct _INVERTED_FUNCTION_TABLE_ENTRY {
|
|
PVOID ExceptionDirectory;
|
|
PVOID ImageBase;
|
|
ULONG ImageSize;
|
|
ULONG ExceptionDirectorySize;
|
|
} INVERTED_FUNCTION_TABLE_ENTRY, *PINVERTED_FUNCTION_TABLE_ENTRY;
|
|
|
|
typedef struct _INVERTED_FUNCTION_TABLE {
|
|
ULONG Count;
|
|
ULONG MaxCount;
|
|
ULONG Epoch;
|
|
UCHAR Overflow;
|
|
INVERTED_FUNCTION_TABLE_ENTRY Entries[0x100];
|
|
} INVERTED_FUNCTION_TABLE, *PINVERTED_FUNCTION_TABLE;
|
|
|
|
/*===================================
|
|
# Callgate Params
|
|
=====================================*/
|
|
typedef struct _SHADOWGATE_PARAMS {
|
|
UINT64 pFunction;
|
|
UINT64 dwMinimumFrameSize;
|
|
UINT64 argc;
|
|
UINT64 argv[1];
|
|
} SHADOWGATE_PARAMS, *PSHADOWGATE_PARAMS;
|
|
|
|
typedef struct _SHADOWGATE_COPY_INFO {
|
|
PVOID pSourceAddress;
|
|
DWORD dwSize;
|
|
PVOID pCopiedAddress;
|
|
} SHADOWGATE_COPY_INFO, *PSHADOWGATE_COPY_INFO;
|
|
|
|
typedef ULONG_PTR(*ShadowGateFn)(PSHADOWGATE_PARAMS);
|
|
|
|
typedef struct _LSA_UNICODE_STRING {
|
|
USHORT Length;
|
|
USHORT MaximumLength;
|
|
PWSTR Buffer;
|
|
} LSA_UNICODE_STRING, * PLSA_UNICODE_STRING, UNICODE_STRING, * PUNICODE_STRING, * PUNICODE_STR;
|
|
|
|
typedef struct _STRING {
|
|
USHORT Length;
|
|
USHORT MaximumLength;
|
|
PCHAR Buffer;
|
|
} STRING, *PSTRING;
|
|
|
|
#define PROCESSOR_FEATURE_MAX 64
|
|
#define USER_SHARED_DATA ( ( PKUSER_SHARED_DATA ) 0x7FFE0000 )
|
|
#define DELAY_TICKS 10000
|
|
|
|
typedef enum _EVENT_TYPE {
|
|
NotificationEvent,
|
|
SynchronizationEvent
|
|
} EVENT_TYPE;
|
|
|
|
typedef struct _KSYSTEM_TIME
|
|
{
|
|
ULONG LowPart;
|
|
LONG High1Time;
|
|
LONG High2Time;
|
|
} KSYSTEM_TIME, * PKSYSTEM_TIME;
|
|
|
|
typedef enum _NT_PRODUCT_TYPE
|
|
{
|
|
NtProductWinNt = 1,
|
|
NtProductLanManNt = 2,
|
|
NtProductServer = 3
|
|
} NT_PRODUCT_TYPE;
|
|
|
|
typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE
|
|
{
|
|
StandardDesign,
|
|
NEC98x86,
|
|
EndAlternatives
|
|
} ALTERNATIVE_ARCHITECTURE_TYPE;
|
|
|
|
typedef struct _RTL_HEAP_WALK_ENTRY
|
|
{
|
|
PVOID DataAddress;
|
|
SIZE_T DataSize;
|
|
UCHAR OverheadBytes;
|
|
UCHAR SegmentIndex;
|
|
USHORT Flags;
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
SIZE_T Settable;
|
|
USHORT TagIndex;
|
|
USHORT AllocatorBackTraceIndex;
|
|
ULONG Reserved[2];
|
|
} Block;
|
|
struct
|
|
{
|
|
ULONG CommittedSize;
|
|
ULONG UnCommittedSize;
|
|
PVOID FirstEntry;
|
|
PVOID LastEntry;
|
|
} Segment;
|
|
};
|
|
} RTL_HEAP_WALK_ENTRY, * PRTL_HEAP_WALK_ENTRY;
|
|
|
|
typedef struct _KUSER_SHARED_DATA {
|
|
ULONG TickCountLowDeprecated;
|
|
ULONG TickCountMultiplier;
|
|
KSYSTEM_TIME InterruptTime;
|
|
KSYSTEM_TIME SystemTime;
|
|
KSYSTEM_TIME TimeZoneBias;
|
|
USHORT ImageNumberLow;
|
|
USHORT ImageNumberHigh;
|
|
WCHAR NtSystemRoot[260];
|
|
ULONG MaxStackTraceDepth;
|
|
ULONG CryptoExponent;
|
|
ULONG TimeZoneId;
|
|
ULONG LargePageMinimum;
|
|
ULONG AitSamplingValue;
|
|
ULONG AppCompatFlag;
|
|
ULONGLONG RNGSeedVersion;
|
|
ULONG GlobalValidationRunlevel;
|
|
LONG TimeZoneBiasStamp;
|
|
ULONG NtBuildNumber;
|
|
NT_PRODUCT_TYPE NtProductType;
|
|
BOOLEAN ProductTypeIsValid;
|
|
BOOLEAN Reserved0[1];
|
|
USHORT NativeProcessorArchitecture;
|
|
ULONG NtMajorVersion;
|
|
ULONG NtMinorVersion;
|
|
BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
|
|
ULONG Reserved1;
|
|
ULONG Reserved3;
|
|
ULONG TimeSlip;
|
|
ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
|
|
ULONG BootId;
|
|
LARGE_INTEGER SystemExpirationDate;
|
|
ULONG SuiteMask;
|
|
BOOLEAN KdDebuggerEnabled;
|
|
union {
|
|
UCHAR MitigationPolicies;
|
|
struct {
|
|
UCHAR NXSupportPolicy : 2;
|
|
UCHAR SEHValidationPolicy : 2;
|
|
UCHAR CurDirDevicesSkippedForDlls : 2;
|
|
UCHAR Reserved : 2;
|
|
};
|
|
};
|
|
USHORT CyclesPerYield;
|
|
ULONG ActiveConsoleId;
|
|
ULONG DismountCount;
|
|
ULONG ComPlusPackage;
|
|
ULONG LastSystemRITEventTickCount;
|
|
ULONG NumberOfPhysicalPages;
|
|
BOOLEAN SafeBootMode;
|
|
union {
|
|
UCHAR VirtualizationFlags;
|
|
struct {
|
|
UCHAR ArchStartedInEl2 : 1;
|
|
UCHAR QcSlIsSupported : 1;
|
|
};
|
|
};
|
|
UCHAR Reserved12[2];
|
|
union {
|
|
ULONG SharedDataFlags;
|
|
struct {
|
|
ULONG DbgErrorPortPresent : 1;
|
|
ULONG DbgElevationEnabled : 1;
|
|
ULONG DbgVirtEnabled : 1;
|
|
ULONG DbgInstallerDetectEnabled : 1;
|
|
ULONG DbgLkgEnabled : 1;
|
|
ULONG DbgDynProcessorEnabled : 1;
|
|
ULONG DbgConsoleBrokerEnabled : 1;
|
|
ULONG DbgSecureBootEnabled : 1;
|
|
ULONG DbgMultiSessionSku : 1;
|
|
ULONG DbgMultiUsersInSessionSku : 1;
|
|
ULONG DbgStateSeparationEnabled : 1;
|
|
ULONG SpareBits : 21;
|
|
} DUMMYSTRUCTNAME2;
|
|
} DUMMYUNIONNAME2;
|
|
ULONG DataFlagsPad[1];
|
|
ULONGLONG TestRetInstruction;
|
|
LONGLONG QpcFrequency;
|
|
ULONG SystemCall;
|
|
ULONG Reserved2;
|
|
ULONGLONG SystemCallPad[2];
|
|
union {
|
|
KSYSTEM_TIME TickCount;
|
|
ULONG64 TickCountQuad;
|
|
struct {
|
|
ULONG ReservedTickCountOverlay[3];
|
|
ULONG TickCountPad[1];
|
|
} DUMMYSTRUCTNAME;
|
|
} DUMMYUNIONNAME3;
|
|
ULONG Cookie;
|
|
ULONG CookiePad[1];
|
|
LONGLONG ConsoleSessionForegroundProcessId;
|
|
ULONGLONG TimeUpdateLock;
|
|
ULONGLONG BaselineSystemTimeQpc;
|
|
ULONGLONG BaselineInterruptTimeQpc;
|
|
ULONGLONG QpcSystemTimeIncrement;
|
|
ULONGLONG QpcInterruptTimeIncrement;
|
|
UCHAR QpcSystemTimeIncrementShift;
|
|
UCHAR QpcInterruptTimeIncrementShift;
|
|
USHORT UnparkedProcessorCount;
|
|
ULONG EnclaveFeatureMask[4];
|
|
ULONG TelemetryCoverageRound;
|
|
USHORT UserModeGlobalLogger[16];
|
|
ULONG ImageFileExecutionOptions;
|
|
ULONG LangGenerationCount;
|
|
ULONGLONG Reserved4;
|
|
ULONGLONG InterruptTimeBias;
|
|
ULONGLONG QpcBias;
|
|
ULONG ActiveProcessorCount;
|
|
UCHAR ActiveGroupCount;
|
|
UCHAR Reserved9;
|
|
union {
|
|
USHORT QpcData;
|
|
struct {
|
|
UCHAR QpcBypassEnabled;
|
|
UCHAR QpcShift;
|
|
};
|
|
};
|
|
LARGE_INTEGER TimeZoneBiasEffectiveStart;
|
|
LARGE_INTEGER TimeZoneBiasEffectiveEnd;
|
|
XSTATE_CONFIGURATION XState;
|
|
KSYSTEM_TIME FeatureConfigurationChangeStamp;
|
|
ULONG Spare;
|
|
ULONG64 UserPointerAuthMask;
|
|
} KUSER_SHARED_DATA, * PKUSER_SHARED_DATA;
|
|
|
|
|
|
#define InitializeObjectAttributes( p, n, a, r, s ) { \
|
|
(p)->Length = sizeof( OBJECT_ATTRIBUTES ); \
|
|
(p)->RootDirectory = r; \
|
|
(p)->Attributes = a; \
|
|
(p)->ObjectName = n; \
|
|
(p)->SecurityDescriptor = s; \
|
|
(p)->SecurityQualityOfService = NULL; \
|
|
}
|
|
|
|
#define OBJ_INHERIT 0x00000002L
|
|
#define OBJ_PERMANENT 0x00000010L
|
|
#define OBJ_EXCLUSIVE 0x00000020L
|
|
#define OBJ_CASE_INSENSITIVE 0x00000040L
|
|
#define OBJ_OPENIF 0x00000080L
|
|
#define OBJ_OPENLINK 0x00000100L
|
|
#define OBJ_KERNEL_HANDLE 0x00000200L
|
|
#define OBJ_FORCE_ACCESS_CHECK 0x00000400L
|
|
#define OBJ_IGNORE_IMPERSONATED_DEVICEMAP 0x00000800L
|
|
#define OBJ_DONT_REPARSE 0x00001000L
|
|
#define OBJ_VALID_ATTRIBUTES 0x00001FF2L
|
|
|
|
typedef struct _BASE_RELOCATION_ENTRY {
|
|
WORD Offset : 12;
|
|
WORD Type : 4;
|
|
} BASE_RELOCATION_ENTRY, * PBASE_RELOCATION_ENTRY;
|
|
|
|
|
|
typedef enum _SECTION_INHERIT {
|
|
ViewShare = 1,
|
|
ViewUnmap = 2
|
|
} SECTION_INHERIT, * PSECTION_INHERIT;
|
|
|
|
|
|
#define RTL_MAX_DRIVE_LETTERS 32
|
|
|
|
|
|
|
|
typedef struct _RTL_DRIVE_LETTER_CURDIR
|
|
{
|
|
USHORT Flags;
|
|
USHORT Length;
|
|
ULONG TimeStamp;
|
|
UNICODE_STRING DosPath;
|
|
|
|
} RTL_DRIVE_LETTER_CURDIR, * PRTL_DRIVE_LETTER_CURDIR;
|
|
|
|
typedef struct _CURDIR
|
|
{
|
|
UNICODE_STRING DosPath;
|
|
HANDLE Handle;
|
|
|
|
} CURDIR, * PCURDIR;
|
|
|
|
|
|
typedef struct _RTL_USER_PROCESS_PARAMETERS
|
|
{
|
|
ULONG MaximumLength;
|
|
ULONG Length;
|
|
|
|
ULONG Flags;
|
|
ULONG DebugFlags;
|
|
|
|
HANDLE ConsoleHandle;
|
|
ULONG ConsoleFlags;
|
|
HANDLE StandardInput;
|
|
HANDLE StandardOutput;
|
|
HANDLE StandardError;
|
|
|
|
CURDIR CurrentDirectory;
|
|
UNICODE_STRING DllPath;
|
|
UNICODE_STRING ImagePathName;
|
|
UNICODE_STRING CommandLine;
|
|
PWCHAR Environment;
|
|
|
|
ULONG StartingX;
|
|
ULONG StartingY;
|
|
ULONG CountX;
|
|
ULONG CountY;
|
|
ULONG CountCharsX;
|
|
ULONG CountCharsY;
|
|
ULONG FillAttribute;
|
|
|
|
ULONG WindowFlags;
|
|
ULONG ShowWindowFlags;
|
|
UNICODE_STRING WindowTitle;
|
|
UNICODE_STRING DesktopInfo;
|
|
UNICODE_STRING ShellInfo;
|
|
UNICODE_STRING RuntimeData;
|
|
RTL_DRIVE_LETTER_CURDIR CurrentDirectories[RTL_MAX_DRIVE_LETTERS];
|
|
|
|
ULONG_PTR EnvironmentSize;
|
|
ULONG_PTR EnvironmentVersion;
|
|
PVOID PackageDependencyData;
|
|
ULONG ProcessGroupId;
|
|
ULONG LoaderThreads;
|
|
|
|
} RTL_USER_PROCESS_PARAMETERS, * PRTL_USER_PROCESS_PARAMETERS;
|
|
|
|
typedef struct _LDR_MODULE {
|
|
LIST_ENTRY InLoadOrderModuleList;
|
|
LIST_ENTRY InMemoryOrderModuleList;
|
|
LIST_ENTRY InInitializationOrderModuleList;
|
|
PVOID BaseAddress;
|
|
PVOID EntryPoint;
|
|
ULONG SizeOfImage;
|
|
UNICODE_STRING FullDllName;
|
|
UNICODE_STRING BaseDllName;
|
|
ULONG Flags;
|
|
SHORT LoadCount;
|
|
SHORT TlsIndex;
|
|
LIST_ENTRY HashTableEntry;
|
|
ULONG TimeDateStamp;
|
|
} LDR_MODULE, * PLDR_MODULE;
|
|
|
|
typedef struct _PEB_LDR_DATA {
|
|
ULONG Length;
|
|
ULONG Initialized;
|
|
PVOID SsHandle;
|
|
LIST_ENTRY InLoadOrderModuleList;
|
|
LIST_ENTRY InMemoryOrderModuleList;
|
|
LIST_ENTRY InInitializationOrderModuleList;
|
|
} PEB_LDR_DATA, * PPEB_LDR_DATA;
|
|
|
|
typedef struct _PEB {
|
|
BOOLEAN InheritedAddressSpace;
|
|
BOOLEAN ReadImageFileExecOptions;
|
|
BOOLEAN BeingDebugged;
|
|
BOOLEAN Spare;
|
|
HANDLE Mutant;
|
|
PVOID ImageBase;
|
|
PPEB_LDR_DATA LoaderData;
|
|
PVOID ProcessParameters;
|
|
PVOID SubSystemData;
|
|
PVOID ProcessHeap;
|
|
PVOID FastPebLock;
|
|
PVOID FastPebLockRoutine;
|
|
PVOID FastPebUnlockRoutine;
|
|
ULONG EnvironmentUpdateCount;
|
|
PVOID* KernelCallbackTable;
|
|
PVOID EventLogSection;
|
|
PVOID EventLog;
|
|
PVOID FreeList;
|
|
ULONG TlsExpansionCounter;
|
|
PVOID TlsBitmap;
|
|
ULONG TlsBitmapBits[0x2];
|
|
PVOID ReadOnlySharedMemoryBase;
|
|
PVOID ReadOnlySharedMemoryHeap;
|
|
PVOID* ReadOnlyStaticServerData;
|
|
PVOID AnsiCodePageData;
|
|
PVOID OemCodePageData;
|
|
PVOID UnicodeCaseTableData;
|
|
ULONG NumberOfProcessors;
|
|
ULONG NtGlobalFlag;
|
|
BYTE Spare2[0x4];
|
|
LARGE_INTEGER CriticalSectionTimeout;
|
|
ULONG HeapSegmentReserve;
|
|
ULONG HeapSegmentCommit;
|
|
ULONG HeapDeCommitTotalFreeThreshold;
|
|
ULONG HeapDeCommitFreeBlockThreshold;
|
|
ULONG NumberOfHeaps;
|
|
ULONG MaximumNumberOfHeaps;
|
|
PVOID** ProcessHeaps;
|
|
PVOID GdiSharedHandleTable;
|
|
PVOID ProcessStarterHelper;
|
|
PVOID GdiDCAttributeList;
|
|
PVOID LoaderLock;
|
|
ULONG OSMajorVersion;
|
|
ULONG OSMinorVersion;
|
|
ULONG OSBuildNumber;
|
|
ULONG OSPlatformId;
|
|
ULONG ImageSubSystem;
|
|
ULONG ImageSubSystemMajorVersion;
|
|
ULONG ImageSubSystemMinorVersion;
|
|
ULONG GdiHandleBuffer[0x22];
|
|
ULONG PostProcessInitRoutine;
|
|
ULONG TlsExpansionBitmap;
|
|
BYTE TlsExpansionBitmapBits[0x80];
|
|
ULONG SessionId;
|
|
} PEB, * PPEB;
|
|
|
|
typedef struct __CLIENT_ID {
|
|
HANDLE UniqueProcess;
|
|
HANDLE UniqueThread;
|
|
} CLIENT_ID, * PCLIENT_ID;
|
|
|
|
typedef struct _TEB_ACTIVE_FRAME_CONTEXT {
|
|
ULONG Flags;
|
|
PCHAR FrameName;
|
|
} TEB_ACTIVE_FRAME_CONTEXT, * PTEB_ACTIVE_FRAME_CONTEXT;
|
|
|
|
typedef struct _TEB_ACTIVE_FRAME {
|
|
ULONG Flags;
|
|
struct _TEB_ACTIVE_FRAME* Previous;
|
|
PTEB_ACTIVE_FRAME_CONTEXT Context;
|
|
} TEB_ACTIVE_FRAME, * PTEB_ACTIVE_FRAME;
|
|
|
|
typedef struct _GDI_TEB_BATCH {
|
|
ULONG Offset;
|
|
ULONG HDC;
|
|
ULONG Buffer[310];
|
|
} GDI_TEB_BATCH, * PGDI_TEB_BATCH;
|
|
|
|
typedef PVOID PACTIVATION_CONTEXT;
|
|
|
|
typedef struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME {
|
|
struct __RTL_ACTIVATION_CONTEXT_STACK_FRAME* Previous;
|
|
PACTIVATION_CONTEXT ActivationContext;
|
|
ULONG Flags;
|
|
} RTL_ACTIVATION_CONTEXT_STACK_FRAME, * PRTL_ACTIVATION_CONTEXT_STACK_FRAME;
|
|
|
|
typedef struct _ACTIVATION_CONTEXT_STACK {
|
|
PRTL_ACTIVATION_CONTEXT_STACK_FRAME ActiveFrame;
|
|
LIST_ENTRY FrameListCache;
|
|
ULONG Flags;
|
|
ULONG NextCookieSequenceNumber;
|
|
ULONG StackId;
|
|
} ACTIVATION_CONTEXT_STACK, * PACTIVATION_CONTEXT_STACK;
|
|
|
|
typedef struct _TEB {
|
|
NT_TIB NtTib;
|
|
PVOID EnvironmentPointer;
|
|
CLIENT_ID ClientId;
|
|
PVOID ActiveRpcHandle;
|
|
PVOID ThreadLocalStoragePointer;
|
|
PPEB ProcessEnvironmentBlock;
|
|
ULONG LastErrorValue;
|
|
ULONG CountOfOwnedCriticalSections;
|
|
PVOID CsrClientThread;
|
|
PVOID Win32ThreadInfo;
|
|
ULONG User32Reserved[26];
|
|
ULONG UserReserved[5];
|
|
PVOID WOW32Reserved;
|
|
LCID CurrentLocale;
|
|
ULONG FpSoftwareStatusRegister;
|
|
PVOID SystemReserved1[54];
|
|
LONG ExceptionCode;
|
|
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
|
|
PACTIVATION_CONTEXT_STACK* ActivationContextStackPointer;
|
|
UCHAR SpareBytes1[0x30 - 3 * sizeof(PVOID)];
|
|
ULONG TxFsContext;
|
|
#elif (NTDDI_VERSION >= NTDDI_WS03)
|
|
PACTIVATION_CONTEXT_STACK ActivationContextStackPointer;
|
|
UCHAR SpareBytes1[0x34 - 3 * sizeof(PVOID)];
|
|
#else
|
|
ACTIVATION_CONTEXT_STACK ActivationContextStack;
|
|
UCHAR SpareBytes1[24];
|
|
#endif
|
|
GDI_TEB_BATCH GdiTebBatch;
|
|
CLIENT_ID RealClientId;
|
|
PVOID GdiCachedProcessHandle;
|
|
ULONG GdiClientPID;
|
|
ULONG GdiClientTID;
|
|
PVOID GdiThreadLocalInfo;
|
|
PSIZE_T Win32ClientInfo[62];
|
|
PVOID glDispatchTable[233];
|
|
PSIZE_T glReserved1[29];
|
|
PVOID glReserved2;
|
|
PVOID glSectionInfo;
|
|
PVOID glSection;
|
|
PVOID glTable;
|
|
PVOID glCurrentRC;
|
|
PVOID glContext;
|
|
NTSTATUS LastStatusValue;
|
|
UNICODE_STRING StaticUnicodeString;
|
|
WCHAR StaticUnicodeBuffer[261];
|
|
PVOID DeallocationStack;
|
|
PVOID TlsSlots[64];
|
|
LIST_ENTRY TlsLinks;
|
|
PVOID Vdm;
|
|
PVOID ReservedForNtRpc;
|
|
PVOID DbgSsReserved[2];
|
|
#if (NTDDI_VERSION >= NTDDI_WS03)
|
|
ULONG HardErrorMode;
|
|
#else
|
|
ULONG HardErrorsAreDisabled;
|
|
#endif
|
|
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
|
|
PVOID Instrumentation[13 - sizeof(GUID) / sizeof(PVOID)];
|
|
GUID ActivityId;
|
|
PVOID SubProcessTag;
|
|
PVOID EtwLocalData;
|
|
PVOID EtwTraceData;
|
|
#elif (NTDDI_VERSION >= NTDDI_WS03)
|
|
PVOID Instrumentation[14];
|
|
PVOID SubProcessTag;
|
|
PVOID EtwLocalData;
|
|
#else
|
|
PVOID Instrumentation[16];
|
|
#endif
|
|
PVOID WinSockData;
|
|
ULONG GdiBatchCount;
|
|
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
|
|
BOOLEAN SpareBool0;
|
|
BOOLEAN SpareBool1;
|
|
BOOLEAN SpareBool2;
|
|
#else
|
|
BOOLEAN InDbgPrint;
|
|
BOOLEAN FreeStackOnTermination;
|
|
BOOLEAN HasFiberData;
|
|
#endif
|
|
UCHAR IdealProcessor;
|
|
#if (NTDDI_VERSION >= NTDDI_WS03)
|
|
ULONG GuaranteedStackBytes;
|
|
#else
|
|
ULONG Spare3;
|
|
#endif
|
|
PVOID ReservedForPerf;
|
|
PVOID ReservedForOle;
|
|
ULONG WaitingOnLoaderLock;
|
|
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
|
|
PVOID SavedPriorityState;
|
|
ULONG_PTR SoftPatchPtr1;
|
|
ULONG_PTR ThreadPoolData;
|
|
#elif (NTDDI_VERSION >= NTDDI_WS03)
|
|
ULONG_PTR SparePointer1;
|
|
ULONG_PTR SoftPatchPtr1;
|
|
ULONG_PTR SoftPatchPtr2;
|
|
#else
|
|
Wx86ThreadState Wx86Thread;
|
|
#endif
|
|
PVOID* TlsExpansionSlots;
|
|
#if defined(_WIN64) && !defined(EXPLICIT_32BIT)
|
|
PVOID DeallocationBStore;
|
|
PVOID BStoreLimit;
|
|
#endif
|
|
ULONG ImpersonationLocale;
|
|
ULONG IsImpersonating;
|
|
PVOID NlsCache;
|
|
PVOID pShimData;
|
|
ULONG HeapVirtualAffinity;
|
|
HANDLE CurrentTransactionHandle;
|
|
PTEB_ACTIVE_FRAME ActiveFrame;
|
|
#if (NTDDI_VERSION >= NTDDI_WS03)
|
|
PVOID FlsData;
|
|
#endif
|
|
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
|
|
PVOID PreferredLangauges;
|
|
PVOID UserPrefLanguages;
|
|
PVOID MergedPrefLanguages;
|
|
ULONG MuiImpersonation;
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
USHORT SpareCrossTebFlags : 16;
|
|
};
|
|
USHORT CrossTebFlags;
|
|
};
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
USHORT DbgSafeThunkCall : 1;
|
|
USHORT DbgInDebugPrint : 1;
|
|
USHORT DbgHasFiberData : 1;
|
|
USHORT DbgSkipThreadAttach : 1;
|
|
USHORT DbgWerInShipAssertCode : 1;
|
|
USHORT DbgIssuedInitialBp : 1;
|
|
USHORT DbgClonedThread : 1;
|
|
USHORT SpareSameTebBits : 9;
|
|
};
|
|
USHORT SameTebFlags;
|
|
};
|
|
PVOID TxnScopeEntercallback;
|
|
PVOID TxnScopeExitCAllback;
|
|
PVOID TxnScopeContext;
|
|
ULONG LockCount;
|
|
ULONG ProcessRundown;
|
|
ULONG64 LastSwitchTime;
|
|
ULONG64 TotalSwitchOutTime;
|
|
LARGE_INTEGER WaitReasonBitMap;
|
|
#else
|
|
BOOLEAN SafeThunkCall;
|
|
BOOLEAN BooleanSpare[3];
|
|
#endif
|
|
} TEB, * PTEB;
|
|
|
|
typedef struct _LDR_DATA_TABLE_ENTRY {
|
|
LIST_ENTRY InLoadOrderLinks;
|
|
LIST_ENTRY InMemoryOrderLinks;
|
|
LIST_ENTRY InInitializationOrderLinks;
|
|
PVOID DllBase;
|
|
PVOID EntryPoint;
|
|
ULONG SizeOfImage;
|
|
UNICODE_STRING FullDllName;
|
|
UNICODE_STRING BaseDllName;
|
|
ULONG Flags;
|
|
WORD LoadCount;
|
|
WORD TlsIndex;
|
|
union {
|
|
LIST_ENTRY HashLinks;
|
|
struct {
|
|
PVOID SectionPointer;
|
|
ULONG CheckSum;
|
|
};
|
|
};
|
|
union {
|
|
ULONG TimeDateStamp;
|
|
PVOID LoadedImports;
|
|
};
|
|
PACTIVATION_CONTEXT EntryPointActivationContext;
|
|
PVOID PatchInformation;
|
|
LIST_ENTRY ForwarderLinks;
|
|
LIST_ENTRY ServiceTagLinks;
|
|
LIST_ENTRY StaticLinks;
|
|
} LDR_DATA_TABLE_ENTRY, * PLDR_DATA_TABLE_ENTRY;
|
|
|
|
|
|
typedef struct _INITIAL_TEB {
|
|
PVOID StackBase;
|
|
PVOID StackLimit;
|
|
PVOID StackCommit;
|
|
PVOID StackCommitMax;
|
|
PVOID StackReserved;
|
|
} INITIAL_TEB, * PINITIAL_TEB;
|
|
|
|
typedef struct _OBJECT_ATTRIBUTES {
|
|
ULONG Length;
|
|
HANDLE RootDirectory;
|
|
PUNICODE_STRING ObjectName;
|
|
ULONG Attributes;
|
|
PVOID SecurityDescriptor;
|
|
PVOID SecurityQualityOfService;
|
|
} OBJECT_ATTRIBUTES, * POBJECT_ATTRIBUTES;
|
|
|
|
|
|
|
|
|
|
typedef enum _PS_CREATE_STATE
|
|
{
|
|
PsCreateInitialState,
|
|
PsCreateFailOnFileOpen,
|
|
PsCreateFailOnSectionCreate,
|
|
PsCreateFailExeFormat,
|
|
PsCreateFailMachineMismatch,
|
|
PsCreateFailExeName,
|
|
PsCreateSuccess,
|
|
PsCreateMaximumStates
|
|
|
|
} PS_CREATE_STATE;
|
|
|
|
typedef struct _PS_CREATE_INFO
|
|
{
|
|
SIZE_T Size;
|
|
PS_CREATE_STATE State;
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
union
|
|
{
|
|
ULONG InitFlags;
|
|
struct
|
|
{
|
|
UCHAR WriteOutputOnExit : 1;
|
|
UCHAR DetectManifest : 1;
|
|
UCHAR IFEOSkipDebugger : 1;
|
|
UCHAR IFEODoNotPropagateKeyState : 1;
|
|
UCHAR SpareBits1 : 4;
|
|
UCHAR SpareBits2 : 8;
|
|
USHORT ProhibitedImageCharacteristics : 16;
|
|
} s1;
|
|
} u1;
|
|
ACCESS_MASK AdditionalFileAccess;
|
|
} InitState;
|
|
|
|
struct
|
|
{
|
|
HANDLE FileHandle;
|
|
} FailSection;
|
|
|
|
struct
|
|
{
|
|
USHORT DllCharacteristics;
|
|
} ExeFormat;
|
|
|
|
struct
|
|
{
|
|
HANDLE IFEOKey;
|
|
} ExeName;
|
|
|
|
struct
|
|
{
|
|
union
|
|
{
|
|
ULONG OutputFlags;
|
|
struct
|
|
{
|
|
UCHAR ProtectedProcess : 1;
|
|
UCHAR AddressSpaceOverride : 1;
|
|
UCHAR DevOverrideEnabled : 1;
|
|
UCHAR ManifestDetected : 1;
|
|
UCHAR ProtectedProcessLight : 1;
|
|
UCHAR SpareBits1 : 3;
|
|
UCHAR SpareBits2 : 8;
|
|
USHORT SpareBits3 : 16;
|
|
} s2;
|
|
} u2;
|
|
HANDLE FileHandle;
|
|
HANDLE SectionHandle;
|
|
ULONGLONG UserProcessParametersNative;
|
|
ULONG UserProcessParametersWow64;
|
|
ULONG CurrentParameterFlags;
|
|
ULONGLONG PebAddressNative;
|
|
ULONG PebAddressWow64;
|
|
ULONGLONG ManifestAddress;
|
|
ULONG ManifestSize;
|
|
} SuccessState;
|
|
};
|
|
|
|
} PS_CREATE_INFO, * PPS_CREATE_INFO;
|
|
|
|
|
|
|
|
typedef struct _PS_ATTRIBUTE
|
|
{
|
|
ULONG_PTR Attribute;
|
|
SIZE_T Size;
|
|
union
|
|
{
|
|
ULONG_PTR Value;
|
|
PVOID ValuePtr;
|
|
};
|
|
PSIZE_T ReturnLength;
|
|
|
|
} PS_ATTRIBUTE, * PPS_ATTRIBUTE;
|
|
|
|
|
|
|
|
typedef struct _PS_ATTRIBUTE_LIST
|
|
{
|
|
SIZE_T TotalLength;
|
|
PS_ATTRIBUTE Attributes[3];
|
|
|
|
} PS_ATTRIBUTE_LIST, * PPS_ATTRIBUTE_LIST;
|
|
|
|
|
|
typedef NTSTATUS(NTAPI* PUSER_THREAD_START_ROUTINE)(
|
|
_In_ PVOID ThreadParameter
|
|
);
|
|
|
|
typedef VOID(NTAPI* PPS_APC_ROUTINE) (
|
|
_In_opt_ PVOID ApcArgument1,
|
|
_In_opt_ PVOID ApcArgument2,
|
|
_In_opt_ PVOID ApcArgument3
|
|
);
|
|
|
|
#define PS_ATTRIBUTE_NUMBER_MASK 0x0000ffff
|
|
#define PS_ATTRIBUTE_THREAD 0x00010000 // Attribute may be used with thread creation
|
|
#define PS_ATTRIBUTE_INPUT 0x00020000 // Attribute is input only
|
|
#define PS_ATTRIBUTE_ADDITIVE 0x00040000 // Attribute may be "accumulated", e.g. bitmasks, counters, etc.
|
|
|
|
typedef enum _PS_ATTRIBUTE_NUM
|
|
{
|
|
PsAttributeParentProcess, // in HANDLE
|
|
PsAttributeDebugPort, // in HANDLE
|
|
PsAttributeToken, // in HANDLE
|
|
PsAttributeClientId, // out PCLIENT_ID
|
|
PsAttributeTebAddress, // out PTEB
|
|
PsAttributeImageName, // in PWSTR
|
|
PsAttributeImageInfo, // out PSECTION_IMAGE_INFORMATION
|
|
PsAttributeMemoryReserve, // in PPS_MEMORY_RESERVE
|
|
PsAttributePriorityClass, // in UCHAR
|
|
PsAttributeErrorMode, // in ULONG
|
|
PsAttributeStdHandleInfo, // in PPS_STD_HANDLE_INFO
|
|
PsAttributeHandleList, // in PHANDLE
|
|
PsAttributeGroupAffinity, // in PGROUP_AFFINITY
|
|
PsAttributePreferredNode, // in PUSHORT
|
|
PsAttributeIdealProcessor, // in PPROCESSOR_NUMBER
|
|
PsAttributeUmsThread, // see MSDN UpdateProceThreadAttributeList (CreateProcessW) - in PUMS_CREATE_THREAD_ATTRIBUTES
|
|
PsAttributeMitigationOptions, // in UCHAR
|
|
PsAttributeProtectionLevel, // in ULONG
|
|
PsAttributeSecureProcess, // since THRESHOLD (Virtual Secure Mode, Device Guard)
|
|
PsAttributeJobList,
|
|
PsAttributeChildProcessPolicy, // since THRESHOLD2
|
|
PsAttributeAllApplicationPackagesPolicy, // since REDSTONE
|
|
PsAttributeWin32kFilter,
|
|
PsAttributeSafeOpenPromptOriginClaim,
|
|
PsAttributeBnoIsolation,
|
|
PsAttributeDesktopAppPolicy,
|
|
PsAttributeMax
|
|
} PS_ATTRIBUTE_NUM;
|
|
|
|
|
|
#define PsAttributeValue(Number, Thread, Input, Additive) \
|
|
(((Number) & PS_ATTRIBUTE_NUMBER_MASK) | \
|
|
((Thread) ? PS_ATTRIBUTE_THREAD : 0) | \
|
|
((Input) ? PS_ATTRIBUTE_INPUT : 0) | \
|
|
((Additive) ? PS_ATTRIBUTE_ADDITIVE : 0))
|
|
|
|
#define PS_ATTRIBUTE_PARENT_PROCESS \
|
|
PsAttributeValue(PsAttributeParentProcess, FALSE, TRUE, TRUE)
|
|
#define PS_ATTRIBUTE_DEBUG_PORT \
|
|
PsAttributeValue(PsAttributeDebugPort, FALSE, TRUE, TRUE)
|
|
#define PS_ATTRIBUTE_TOKEN \
|
|
PsAttributeValue(PsAttributeToken, FALSE, TRUE, TRUE)
|
|
#define PS_ATTRIBUTE_CLIENT_ID \
|
|
PsAttributeValue(PsAttributeClientId, TRUE, FALSE, FALSE)
|
|
#define PS_ATTRIBUTE_TEB_ADDRESS \
|
|
PsAttributeValue(PsAttributeTebAddress, TRUE, FALSE, FALSE)
|
|
#define PS_ATTRIBUTE_IMAGE_NAME \
|
|
PsAttributeValue(PsAttributeImageName, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_IMAGE_INFO \
|
|
PsAttributeValue(PsAttributeImageInfo, FALSE, FALSE, FALSE)
|
|
#define PS_ATTRIBUTE_MEMORY_RESERVE \
|
|
PsAttributeValue(PsAttributeMemoryReserve, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_PRIORITY_CLASS \
|
|
PsAttributeValue(PsAttributePriorityClass, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_ERROR_MODE \
|
|
PsAttributeValue(PsAttributeErrorMode, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_STD_HANDLE_INFO \
|
|
PsAttributeValue(PsAttributeStdHandleInfo, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_HANDLE_LIST \
|
|
PsAttributeValue(PsAttributeHandleList, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_GROUP_AFFINITY \
|
|
PsAttributeValue(PsAttributeGroupAffinity, TRUE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_PREFERRED_NODE \
|
|
PsAttributeValue(PsAttributePreferredNode, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_IDEAL_PROCESSOR \
|
|
PsAttributeValue(PsAttributeIdealProcessor, TRUE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_MITIGATION_OPTIONS \
|
|
PsAttributeValue(PsAttributeMitigationOptions, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_PROTECTION_LEVEL \
|
|
PsAttributeValue(PsAttributeProtectionLevel, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_UMS_THREAD \
|
|
PsAttributeValue(PsAttributeUmsThread, TRUE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_SECURE_PROCESS \
|
|
PsAttributeValue(PsAttributeSecureProcess, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_JOB_LIST \
|
|
PsAttributeValue(PsAttributeJobList, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_CHILD_PROCESS_POLICY \
|
|
PsAttributeValue(PsAttributeChildProcessPolicy, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_ALL_APPLICATION_PACKAGES_POLICY \
|
|
PsAttributeValue(PsAttributeAllApplicationPackagesPolicy, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_WIN32K_FILTER \
|
|
PsAttributeValue(PsAttributeWin32kFilter, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_SAFE_OPEN_PROMPT_ORIGIN_CLAIM \
|
|
PsAttributeValue(PsAttributeSafeOpenPromptOriginClaim, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_BNO_ISOLATION \
|
|
PsAttributeValue(PsAttributeBnoIsolation, FALSE, TRUE, FALSE)
|
|
#define PS_ATTRIBUTE_DESKTOP_APP_POLICY \
|
|
PsAttributeValue(PsAttributeDesktopAppPolicy, FALSE, TRUE, FALSE)
|
|
|
|
|
|
|
|
|
|
#define RTL_USER_PROC_PARAMS_NORMALIZED 0x00000001
|
|
#define RTL_USER_PROC_PROFILE_USER 0x00000002
|
|
#define RTL_USER_PROC_PROFILE_KERNEL 0x00000004
|
|
#define RTL_USER_PROC_PROFILE_SERVER 0x00000008
|
|
#define RTL_USER_PROC_RESERVE_1MB 0x00000020
|
|
#define RTL_USER_PROC_RESERVE_16MB 0x00000040
|
|
#define RTL_USER_PROC_CASE_SENSITIVE 0x00000080
|
|
#define RTL_USER_PROC_DISABLE_HEAP_DECOMMIT 0x00000100
|
|
#define RTL_USER_PROC_DLL_REDIRECTION_LOCAL 0x00001000
|
|
#define RTL_USER_PROC_APP_MANIFEST_PRESENT 0x00002000
|
|
#define RTL_USER_PROC_IMAGE_KEY_MISSING 0x00004000
|
|
#define RTL_USER_PROC_OPTIN_PROCESS 0x00020000
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum _SYSTEM_INFORMATION_CLASS
|
|
{
|
|
SystemBasicInformation = 0,
|
|
SystemProcessorInformation = 1,
|
|
SystemPerformanceInformation = 2,
|
|
SystemTimeOfDayInformation = 3,
|
|
SystemPathInformation = 4,
|
|
SystemProcessInformation = 5,
|
|
SystemCallCountInformation = 6,
|
|
SystemDeviceInformation = 7,
|
|
SystemProcessorPerformanceInformation = 8,
|
|
SystemFlagsInformation = 9,
|
|
SystemCallTimeInformation = 10,
|
|
SystemModuleInformation = 11,
|
|
SystemLocksInformation = 12,
|
|
SystemStackTraceInformation = 13,
|
|
SystemPagedPoolInformation = 14,
|
|
SystemNonPagedPoolInformation = 15,
|
|
SystemHandleInformation = 16,
|
|
SystemObjectInformation = 17,
|
|
SystemPageFileInformation = 18,
|
|
SystemVdmInstemulInformation = 19,
|
|
SystemVdmBopInformation = 20,
|
|
SystemFileCacheInformation = 21,
|
|
SystemPoolTagInformation = 22,
|
|
SystemInterruptInformation = 23,
|
|
SystemDpcBehaviorInformation = 24,
|
|
SystemFullMemoryInformation = 25,
|
|
SystemLoadGdiDriverInformation = 26,
|
|
SystemUnloadGdiDriverInformation = 27,
|
|
SystemTimeAdjustmentInformation = 28,
|
|
SystemSummaryMemoryInformation = 29,
|
|
SystemMirrorMemoryInformation = 30,
|
|
SystemPerformanceTraceInformation = 31,
|
|
SystemObsolete0 = 32,
|
|
SystemExceptionInformation = 33,
|
|
SystemCrashDumpStateInformation = 34,
|
|
SystemKernelDebuggerInformation = 35,
|
|
SystemContextSwitchInformation = 36,
|
|
SystemRegistryQuotaInformation = 37,
|
|
SystemExtendServiceTableInformation = 38,
|
|
SystemPrioritySeperation = 39,
|
|
SystemVerifierAddDriverInformation = 40,
|
|
SystemVerifierRemoveDriverInformation = 41,
|
|
SystemProcessorIdleInformation = 42,
|
|
SystemLegacyDriverInformation = 43,
|
|
SystemCurrentTimeZoneInformation = 44,
|
|
SystemLookasideInformation = 45,
|
|
SystemTimeSlipNotification = 46,
|
|
SystemSessionCreate = 47,
|
|
SystemSessionDetach = 48,
|
|
SystemSessionInformation = 49,
|
|
SystemRangeStartInformation = 50,
|
|
SystemVerifierInformation = 51,
|
|
SystemVerifierThunkExtend = 52,
|
|
SystemSessionProcessInformation = 53,
|
|
SystemLoadGdiDriverInSystemSpace = 54,
|
|
SystemNumaProcessorMap = 55,
|
|
SystemPrefetcherInformation = 56,
|
|
SystemExtendedProcessInformation = 57,
|
|
SystemRecommendedSharedDataAlignment = 58,
|
|
SystemComPlusPackage = 59,
|
|
SystemNumaAvailableMemory = 60,
|
|
SystemProcessorPowerInformation = 61,
|
|
SystemEmulationBasicInformation = 62,
|
|
SystemEmulationProcessorInformation = 63,
|
|
SystemExtendedHandleInformation = 64,
|
|
SystemLostDelayedWriteInformation = 65,
|
|
SystemBigPoolInformation = 66,
|
|
SystemSessionPoolTagInformation = 67,
|
|
SystemSessionMappedViewInformation = 68,
|
|
SystemHotpatchInformation = 69,
|
|
SystemObjectSecurityMode = 70,
|
|
SystemWatchdogTimerHandler = 71,
|
|
SystemWatchdogTimerInformation = 72,
|
|
SystemLogicalProcessorInformation = 73,
|
|
SystemWow64SharedInformation = 74,
|
|
SystemRegisterFirmwareTableInformationHandler = 75,
|
|
SystemFirmwareTableInformation = 76,
|
|
SystemModuleInformationEx = 77,
|
|
SystemVerifierTriageInformation = 78,
|
|
SystemSuperfetchInformation = 79,
|
|
SystemMemoryListInformation = 80,
|
|
SystemFileCacheInformationEx = 81,
|
|
MaxSystemInfoClass = 82
|
|
|
|
} SYSTEM_INFORMATION_CLASS;
|
|
|
|
|
|
#define PS_REQUEST_BREAKAWAY 1
|
|
#define PS_NO_DEBUG_INHERIT 2
|
|
#define PS_INHERIT_HANDLES 4
|
|
#define PS_LARGE_PAGES 8
|
|
#define PS_ALL_FLAGS (PS_REQUEST_BREAKAWAY | PS_NO_DEBUG_INHERIT | PS_INHERIT_HANDLES | PS_LARGE_PAGES)
|
|
|
|
typedef struct _IO_STATUS_BLOCK
|
|
{
|
|
union
|
|
{
|
|
NTSTATUS Status;
|
|
PVOID Pointer;
|
|
};
|
|
|
|
ULONG_PTR Information;
|
|
|
|
} IO_STATUS_BLOCK, * PIO_STATUS_BLOCK;
|
|
|
|
#ifndef PIO_APC_ROUTINE_DEFINED
|
|
typedef
|
|
VOID
|
|
(NTAPI* PIO_APC_ROUTINE) (
|
|
IN PVOID ApcContext,
|
|
IN PIO_STATUS_BLOCK IoStatusBlock,
|
|
IN ULONG Reserved
|
|
);
|
|
#define PIO_APC_ROUTINE_DEFINED
|
|
#endif // PIO_APC_ROUTINE_DEFINED
|
|
|
|
|
|
typedef struct _FILE_DISPOSITION_INFORMATION {
|
|
BOOLEAN DeleteFile;
|
|
} FILE_DISPOSITION_INFORMATION, * PFILE_DISPOSITION_INFORMATION;
|
|
|
|
#ifndef FILE_SUPERSEDE
|
|
#define FILE_SUPERSEDE 0x00000000
|
|
#define FILE_OPEN 0x00000001
|
|
#define FILE_CREATE 0x00000002
|
|
#define FILE_OPEN_IF 0x00000003
|
|
#define FILE_OVERWRITE 0x00000004
|
|
#define FILE_OVERWRITE_IF 0x00000005
|
|
#define FILE_MAXIMUM_DISPOSITION 0x00000005
|
|
#endif
|
|
|
|
// Define the create/open option flags
|
|
#ifndef FILE_DIRECTORY_FILE
|
|
#define FILE_DIRECTORY_FILE 0x00000001
|
|
#define FILE_WRITE_THROUGH 0x00000002
|
|
#define FILE_SEQUENTIAL_ONLY 0x00000004
|
|
#define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
|
|
#define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
|
|
#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
|
|
#define FILE_NON_DIRECTORY_FILE 0x00000040
|
|
#define FILE_CREATE_TREE_CONNECTION 0x00000080
|
|
#define FILE_COMPLETE_IF_OPLOCKED 0x00000100
|
|
#define FILE_NO_EA_KNOWLEDGE 0x00000200
|
|
#define FILE_OPEN_FOR_RECOVERY 0x00000400
|
|
#define FILE_RANDOM_ACCESS 0x00000800
|
|
#define FILE_DELETE_ON_CLOSE 0x00001000
|
|
#define FILE_OPEN_BY_FILE_ID 0x00002000
|
|
#define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
|
|
#define FILE_NO_COMPRESSION 0x00008000
|
|
#define FILE_RESERVE_OPFILTER 0x00100000
|
|
#define FILE_OPEN_REPARSE_POINT 0x00200000
|
|
#define FILE_OPEN_NO_RECALL 0x00400000
|
|
#define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
|
|
#endif // FILE_DIRECTORY_FILE
|
|
|
|
typedef LONG KPRIORITY;
|
|
|
|
typedef struct _PROCESS_BASIC_INFORMATION
|
|
{
|
|
NTSTATUS ExitStatus;
|
|
PPEB PebBaseAddress;
|
|
ULONG_PTR AffinityMask;
|
|
KPRIORITY BasePriority;
|
|
ULONG_PTR UniqueProcessId;
|
|
ULONG_PTR InheritedFromUniqueProcessId;
|
|
|
|
} PROCESS_BASIC_INFORMATION, * PPROCESS_BASIC_INFORMATION;
|
|
|
|
|
|
typedef enum _FILE_INFORMATION_CLASS
|
|
{
|
|
FileDirectoryInformation = 1,
|
|
FileFullDirectoryInformation, // 2
|
|
FileBothDirectoryInformation, // 3
|
|
FileBasicInformation, // 4 wdm
|
|
FileStandardInformation, // 5 wdm
|
|
FileInternalInformation, // 6
|
|
FileEaInformation, // 7
|
|
FileAccessInformation, // 8
|
|
FileNameInformation, // 9
|
|
FileRenameInformation, // 10
|
|
FileLinkInformation, // 11
|
|
FileNamesInformation, // 12
|
|
FileDispositionInformation, // 13
|
|
FilePositionInformation, // 14 wdm
|
|
FileFullEaInformation, // 15
|
|
FileModeInformation, // 16
|
|
FileAlignmentInformation, // 17
|
|
FileAllInformation, // 18
|
|
FileAllocationInformation, // 19
|
|
FileEndOfFileInformation, // 20 wdm
|
|
FileAlternateNameInformation, // 21
|
|
FileStreamInformation, // 22
|
|
FilePipeInformation, // 23
|
|
FilePipeLocalInformation, // 24
|
|
FilePipeRemoteInformation, // 25
|
|
FileMailslotQueryInformation, // 26
|
|
FileMailslotSetInformation, // 27
|
|
FileCompressionInformation, // 28
|
|
FileObjectIdInformation, // 29
|
|
FileCompletionInformation, // 30
|
|
FileMoveClusterInformation, // 31
|
|
FileQuotaInformation, // 32
|
|
FileReparsePointInformation, // 33
|
|
FileNetworkOpenInformation, // 34
|
|
FileAttributeTagInformation, // 35
|
|
FileTrackingInformation, // 36
|
|
FileIdBothDirectoryInformation, // 37
|
|
FileIdFullDirectoryInformation, // 38
|
|
FileValidDataLengthInformation, // 39
|
|
FileShortNameInformation, // 40
|
|
FileIoCompletionNotificationInformation, // 41
|
|
FileIoStatusBlockRangeInformation, // 42
|
|
FileIoPriorityHintInformation, // 43
|
|
FileSfioReserveInformation, // 44
|
|
FileSfioVolumeInformation, // 45
|
|
FileHardLinkInformation, // 46
|
|
FileProcessIdsUsingFileInformation, // 47
|
|
FileMaximumInformation // 48
|
|
} FILE_INFORMATION_CLASS, * PFILE_INFORMATION_CLASS;
|
|
|
|
typedef enum _PROCESSINFOCLASS {
|
|
ProcessBasicInformation,
|
|
ProcessQuotaLimits,
|
|
ProcessIoCounters,
|
|
ProcessVmCounters,
|
|
ProcessTimes,
|
|
ProcessBasePriority,
|
|
ProcessRaisePriority,
|
|
ProcessDebugPort,
|
|
ProcessExceptionPort,
|
|
ProcessAccessToken,
|
|
ProcessLdtInformation,
|
|
ProcessLdtSize,
|
|
ProcessDefaultHardErrorMode,
|
|
ProcessIoPortHandlers, // Note: this is kernel mode only
|
|
ProcessPooledUsageAndLimits,
|
|
ProcessWorkingSetWatch,
|
|
ProcessUserModeIOPL,
|
|
ProcessEnableAlignmentFaultFixup,
|
|
ProcessPriorityClass,
|
|
ProcessWx86Information,
|
|
ProcessHandleCount,
|
|
ProcessAffinityMask,
|
|
ProcessPriorityBoost,
|
|
ProcessDeviceMap,
|
|
ProcessSessionInformation,
|
|
ProcessForegroundInformation,
|
|
ProcessWow64Information,
|
|
ProcessImageFileName,
|
|
ProcessLUIDDeviceMapsEnabled,
|
|
ProcessBreakOnTermination,
|
|
ProcessDebugObjectHandle,
|
|
ProcessDebugFlags,
|
|
ProcessHandleTracing,
|
|
MaxProcessInfoClass // MaxProcessInfoClass should always be the last enum
|
|
} PROCESSINFOCLASS;
|
|
|
|
typedef struct _SYSTEM_THREAD_INFORMATION {
|
|
LARGE_INTEGER KernelTime;
|
|
LARGE_INTEGER UserTime;
|
|
LARGE_INTEGER CreateTime;
|
|
ULONG WaitTime;
|
|
PVOID StartAddress;
|
|
CLIENT_ID ClientId;
|
|
KPRIORITY Priority;
|
|
LONG BasePriority;
|
|
ULONG ContextSwitches;
|
|
ULONG ThreadState;
|
|
ULONG WaitReason;
|
|
} SYSTEM_THREAD_INFORMATION, * PSYSTEM_THREAD_INFORMATION;
|
|
|
|
typedef struct _SYSTEM_PROCESS_INFORMATION {
|
|
ULONG NextEntryOffset;
|
|
ULONG NumberOfThreads;
|
|
LARGE_INTEGER WorkingSetPrivateSize;
|
|
ULONG HardFaultCount;
|
|
BYTE Reserved1[36];
|
|
UNICODE_STRING ImageName;
|
|
KPRIORITY BasePriority;
|
|
HANDLE UniqueProcessId;
|
|
PVOID InheritedFromUniqueProcessId;
|
|
ULONG HandleCount;
|
|
ULONG SessionId;
|
|
ULONG_PTR UniqueProcessKey;
|
|
SIZE_T PeakVirtualSize;
|
|
SIZE_T VirtualSize;
|
|
ULONG PageFaultCount;
|
|
SIZE_T PeakWorkingSetSize;
|
|
SIZE_T WorkingSetSize;
|
|
SIZE_T QuotaPeakPagedPoolUsage;
|
|
SIZE_T QuotaPagedPoolUsage;
|
|
SIZE_T QuotaPeakNonPagedPoolUsage;
|
|
SIZE_T QuotaNonPagedPoolUsage;
|
|
SIZE_T PagefileUsage;
|
|
SIZE_T PeakPagefileUsage;
|
|
SIZE_T PrivatePageCount;
|
|
LARGE_INTEGER ReadOperationCount;
|
|
LARGE_INTEGER WriteOperationCount;
|
|
LARGE_INTEGER OtherOperationCount;
|
|
LARGE_INTEGER ReadTransferCount;
|
|
LARGE_INTEGER WriteTransferCount;
|
|
LARGE_INTEGER OtherTransferCount;
|
|
SYSTEM_THREAD_INFORMATION Threads[1];
|
|
} SYSTEM_PROCESS_INFORMATION, * PSYSTEM_PROCESS_INFORMATION;
|
|
|
|
|
|
#endif // !STRUCTS_H
|