diff --git a/src/Bindings/Memory.cpp b/src/Bindings/Memory.cpp index 2172b70..fe5471f 100644 --- a/src/Bindings/Memory.cpp +++ b/src/Bindings/Memory.cpp @@ -90,14 +90,18 @@ namespace Dotx64Dbg::Native return (int)bytesWritten; } - static uint32_t GetProtection(duint addr) + static uint32_t GetProtection(System::UIntPtr addr, bool useCache) { - return 0; + auto va = static_cast(addr.ToUInt64()); + + return Script::Memory::GetProtect(va, false, useCache); } - static uint32_t SetProtection(duint addr, uint32_t prot) + static bool SetProtection(System::UIntPtr addr, uint32_t prot, int size) { - return 0; + auto va = static_cast(addr.ToUInt64()); + + return Script::Memory::SetProtect(va, prot, (duint)size); } static System::UIntPtr GetBase(System::UIntPtr addr) diff --git a/src/Dotx64Managed/API/Memory.cs b/src/Dotx64Managed/API/Memory.cs index a45fc34..0957072 100644 --- a/src/Dotx64Managed/API/Memory.cs +++ b/src/Dotx64Managed/API/Memory.cs @@ -7,6 +7,7 @@ public static partial class Memory [Flags] public enum Protection { + Invalid = 0, NoAccess = 0x01, ReadOnly = 0x02, ReadWrite = 0x04, @@ -90,5 +91,43 @@ public static nuint GetBase(ulong address) { return GetBase((nuint)address); } + + /// + /// Gets the protection of the memory, if the cache is used this is the last queried page info. + /// It is normally safe to use the cache for performance, when the cache is used the internal + /// API will not use a syscall to determine the protection. + /// + /// Address of the page to query + /// If this is true it will use the last queried page information + /// In case of failure the result is Protection.Invalid otherwise actual protection + public static Protection GetProtection(nuint address, bool useCache) + { + return (Protection)Native.Memory.GetProtection(address, useCache); + } + public static Protection GetProtection(ulong address, bool useCache) + { + return GetProtection((nuint)address, useCache); + } + + /// + /// Sets a new protection on the specified address, the address will be aligned to page + /// boundaries and sets the entire page which is by 4 KiB. This may split up + /// an existing range from the memory map. + /// Internally the size will be always aligned to a minimum of a single page, if the size + /// spans more than two pages then both pages will be modified. + /// This will also update the cached protection info + /// + /// Address of the page + /// New protection + /// The size of the range + /// True on success + public static bool SetProtection(nuint address, Protection protect, int size) + { + return Native.Memory.SetProtection(address, (UInt32)protect, size); + } + public static bool SetProtection(ulong address, Protection protect, int size) + { + return SetProtection((nuint)address, protect, size); + } }; } diff --git a/src/include/pluginsdk/TitanEngine/TitanEngine.h b/src/include/pluginsdk/TitanEngine/TitanEngine.h index 5b1a1f5..b7bcf76 100644 --- a/src/include/pluginsdk/TitanEngine/TitanEngine.h +++ b/src/include/pluginsdk/TitanEngine/TitanEngine.h @@ -57,6 +57,7 @@ #define UE_ENGINE_CALL_PLUGIN_DEBUG_CALLBACK 8 #define UE_ENGINE_SET_DEBUG_PRIVILEGE 9 #define UE_ENGINE_SAFE_ATTACH 10 +#define UE_ENGINE_MEMBP_ALT 11 #define UE_OPTION_REMOVEALL 1 #define UE_OPTION_DISABLEALL 2 diff --git a/src/include/pluginsdk/_scriptapi_memory.h b/src/include/pluginsdk/_scriptapi_memory.h index f52e0e4..828690e 100644 --- a/src/include/pluginsdk/_scriptapi_memory.h +++ b/src/include/pluginsdk/_scriptapi_memory.h @@ -13,6 +13,7 @@ namespace Script SCRIPT_EXPORT duint RemoteAlloc(duint addr, duint size); SCRIPT_EXPORT bool RemoteFree(duint addr); SCRIPT_EXPORT unsigned int GetProtect(duint addr, bool reserved = false, bool cache = true); + SCRIPT_EXPORT bool SetProtect(duint addr, unsigned int protect, duint size); SCRIPT_EXPORT duint GetBase(duint addr, bool reserved = false, bool cache = true); SCRIPT_EXPORT duint GetSize(duint addr, bool reserved = false, bool cache = true); diff --git a/src/include/pluginsdk/bridgemain.h b/src/include/pluginsdk/bridgemain.h index 5be72e7..ce069ea 100644 --- a/src/include/pluginsdk/bridgemain.h +++ b/src/include/pluginsdk/bridgemain.h @@ -1197,6 +1197,7 @@ typedef enum GUI_INVALIDATE_SYMBOL_SOURCE, // param1=duint base, param2=unused GUI_GET_CURRENT_GRAPH, // param1=BridgeCFGraphList*, param2=unused GUI_SHOW_REF, // param1=unused, param2=unused + GUI_SELECT_IN_SYMBOLS_TAB, // param1=duint addr, param2=unused } GUIMSG; //GUI Typedefs @@ -1378,6 +1379,7 @@ BRIDGE_IMPEXP void GuiInvalidateSymbolSource(duint base); BRIDGE_IMPEXP void GuiExecuteOnGuiThreadEx(GUICALLBACKEX cbGuiThread, void* userdata); BRIDGE_IMPEXP void GuiGetCurrentGraph(BridgeCFGraphList* graphList); BRIDGE_IMPEXP void GuiShowReferences(); +BRIDGE_IMPEXP void GuiSelectInSymbolsTab(duint addr); #ifdef __cplusplus } diff --git a/src/include/pluginsdk/x32bridge.lib b/src/include/pluginsdk/x32bridge.lib index 789b16b..7422c41 100644 Binary files a/src/include/pluginsdk/x32bridge.lib and b/src/include/pluginsdk/x32bridge.lib differ diff --git a/src/include/pluginsdk/x32dbg.lib b/src/include/pluginsdk/x32dbg.lib index 78a01c7..68b589b 100644 Binary files a/src/include/pluginsdk/x32dbg.lib and b/src/include/pluginsdk/x32dbg.lib differ diff --git a/src/include/pluginsdk/x64bridge.lib b/src/include/pluginsdk/x64bridge.lib index abce042..5703dd3 100644 Binary files a/src/include/pluginsdk/x64bridge.lib and b/src/include/pluginsdk/x64bridge.lib differ diff --git a/src/include/pluginsdk/x64dbg.lib b/src/include/pluginsdk/x64dbg.lib index cf19a55..0c3b6c9 100644 Binary files a/src/include/pluginsdk/x64dbg.lib and b/src/include/pluginsdk/x64dbg.lib differ