Part of this issue has already been discussed on the forum, but at the moment the task is a bit different. You need to get information about whether the process uses ASLR and DEP technologies in C #.
This code, which is a reinterpretation of this code , works correctly:
/* Definitions required for getting policies */ const int Process_Query_Information = 0x0400; const int Process_WM_Read = 0x0010; public enum Process_Mitigation_Policy { ProcessDEPPolicy = 0, ProcessASLRPolicy = 1 } [StructLayout(LayoutKind.Explicit)] public struct union { [FieldOffset(0)] uint EnableBottomUpRandomization; [FieldOffset(0)] uint EnableForceRelocateImages; [FieldOffset(0)] uint EnableHighEntropy; [FieldOffset(0)] uint DisallowStrippedImages; [FieldOffset(0)] uint ReservedFlags; } public struct Process_Mitigation_Type_Policy { uint Flags; bool EnableBottomUpRandomization { get { return (Flags & 1) > 0; } } bool EnableForceRelocateImage { get { return (Flags & 2) > 0; } } bool EnableHighEntropy { get { return (Flags & 4) > 0; } } bool DisallowStrippedImages { get { return (Flags & 8) > 0; } } } By analogy, I tried to get information about DEP. According to MSDN , I defined the structure of this type:
public struct Process_Mitigation_DEP_Policy { uint Flags; bool Enable { get { return (Flags & 1) > 0; } } bool DisableAtlThunkEmulation { get { return (Flags & 2) > 0; } } } Having tried to use the implemented functionality, it turned out that the same functions refuse to work with this structure. One of the problems is that I need to define a union of another kind, again, according to MSDN ( union for DEP ), but then a union override error occurs. How to define another structure and use it in the same code is not clear to me, especially considering that the WINAPI functions described on MSDN represent examples of functions for C ++ and transferring the latter to C # is also quite difficult.
Question: how to get information about the use of DEP and ASLR process?