From 875f916a1c094d31ef9e21ef06321d51748c6f60 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 02:28:20 +0100 Subject: [PATCH 01/10] Add gitattributes for cmkr --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1a139ac --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +# cmkr +/**/CMakeLists.txt linguist-generated +/**/cmkr.cmake linguist-vendored From 26bd9bb1c245b2d4d468d517900db1023a2e41ab Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 01:44:51 +0100 Subject: [PATCH 02/10] Fix plugin generation --- src/Dotx64Managed/Menus.Main.cs | 6 ++--- src/Dotx64Managed/Plugins.cs | 10 ++++----- src/Dotx64Managed/Resources.cs | 23 ++++++++++++-------- src/Dotx64Managed/Utils.cs | 3 ++- src/Resources/Template/plugin.cs | 35 ++++++++++++++++++++++++++++++ src/Resources/Template/plugin.json | 7 ++++++ 6 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 src/Resources/Template/plugin.cs create mode 100644 src/Resources/Template/plugin.json diff --git a/src/Dotx64Managed/Menus.Main.cs b/src/Dotx64Managed/Menus.Main.cs index 61dd152..b32bf93 100644 --- a/src/Dotx64Managed/Menus.Main.cs +++ b/src/Dotx64Managed/Menus.Main.cs @@ -65,10 +65,10 @@ internal static void CreateNewPlugin() internal static void InitializeMainMenu() { // Plugin icon - Native.UI.Menu.SetIcon(MainMenu, Resources.GetData("Dotx64DbgIcon")); + Native.UI.Menu.SetIcon(MainMenu, Resources.GetData("Dotx64DbgIcon.png")); - AddMenu("Main/Run Script", Resources.GetData("RunIcon"), RunScript); - AddMenu("Main/Create Plugin", Resources.GetData("NewScriptIcon"), CreateNewPlugin); + AddMenu("Main/Run Script", Resources.GetData("RunIcon.png"), RunScript); + AddMenu("Main/Create Plugin", Resources.GetData("NewScriptIcon.png"), CreateNewPlugin); AddSeperator("Main"); } diff --git a/src/Dotx64Managed/Plugins.cs b/src/Dotx64Managed/Plugins.cs index 26c431f..89a286c 100644 --- a/src/Dotx64Managed/Plugins.cs +++ b/src/Dotx64Managed/Plugins.cs @@ -435,18 +435,18 @@ public string CreatePluginTemplate(string pluginName) return null; } - // TODO: Fixme. - /* - if (!Utils.WriteReplacedContents(Dotx64Dbg.Properties.Resources.plugin_json, replacements, pluginJsonPath)) + + if (!Utils.WriteReplacedContents(Resources.GetString("Template/plugin.json"), replacements, pluginJsonPath)) { // ERROR. + return null; } - if (!Utils.WriteReplacedContents(Dotx64Dbg.Properties.Resources.plugin_cs, replacements, pluginCsPath)) + if (!Utils.WriteReplacedContents(Resources.GetString("Template/plugin.cs"), replacements, pluginCsPath)) { // ERROR. + return null; } - */ return pluginPath; } diff --git a/src/Dotx64Managed/Resources.cs b/src/Dotx64Managed/Resources.cs index 814c60b..a00c566 100644 --- a/src/Dotx64Managed/Resources.cs +++ b/src/Dotx64Managed/Resources.cs @@ -8,7 +8,6 @@ namespace Dotx64Dbg class Resources { private static Dictionary _resources = new Dictionary(); - private static string[] _resourceExtensions = new string[] { ".png", ".bmp", ".gif", ".jpg", ".jpeg", ".ico" }; static Resources() { @@ -25,14 +24,9 @@ static Resources() var files = Directory.EnumerateFiles(resourcesPath, "*.*", SearchOption.AllDirectories); foreach (var file in files) { - var ext = Path.GetExtension(file); - if (_resourceExtensions.Contains(ext)) - { - // Load the contents and map filename to contents - var contents = File.ReadAllBytes(file); - var name = Path.GetFileNameWithoutExtension(file); - _resources[name] = contents; - } + var name = file.Substring(resourcesPath.Length + 1); + name = name.Replace('\\', '/'); + _resources[name] = File.ReadAllBytes(file); } Utils.DebugPrintLine($"Loaded {_resources.Count} resources"); @@ -40,11 +34,22 @@ static Resources() public static byte[] GetData(string name) { + name = name.Replace('\\', '/'); if (_resources.TryGetValue(name, out var data)) return data; Utils.DebugPrintLine($"Resource not found: {name}"); return null; } + + public static string GetString(string name) + { + name = name.Replace('\\', '/'); + var data = GetData(name); + if (data == null) + return null; + + return System.Text.Encoding.UTF8.GetString(data); + } } } diff --git a/src/Dotx64Managed/Utils.cs b/src/Dotx64Managed/Utils.cs index 59eae4a..f8cafa9 100644 --- a/src/Dotx64Managed/Utils.cs +++ b/src/Dotx64Managed/Utils.cs @@ -125,7 +125,8 @@ internal static bool WriteReplacedContents(string inputText, Dictionary + /// Called as soon the plugin is first loaded, consequent hot-loads will not call this again. + /// + public MyPlugin() + { + Console.WriteLine("Hello World"); + } + + /// + /// This is called after construction. This is also only called once. + /// + public void Startup() + { + } + + /// + /// Classes that have IHotload can implement this to get a notification for whenever + /// the plugin was hot-loaded due to changes. This is not called for the startup. + /// + public void OnHotload() + { + } + + /// + /// This is called right before the plugin is about to be shutdown. + /// + public void Shutdown() + { + } +} diff --git a/src/Resources/Template/plugin.json b/src/Resources/Template/plugin.json new file mode 100644 index 0000000..8d100cb --- /dev/null +++ b/src/Resources/Template/plugin.json @@ -0,0 +1,7 @@ +{ + "Name": "%PLUGIN_NAME%", + "Description": "", + "Version": "0.0.0", + "Author": "", + "Website": "" +} From 17bc9a2371bc642dffd9b99ae64401924ffae803 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 01:46:10 +0100 Subject: [PATCH 03/10] Fix Visual Studio project generation --- src/Dotx64Managed/Plugins.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Dotx64Managed/Plugins.cs b/src/Dotx64Managed/Plugins.cs index 89a286c..d9dd5cc 100644 --- a/src/Dotx64Managed/Plugins.cs +++ b/src/Dotx64Managed/Plugins.cs @@ -170,10 +170,10 @@ static uint FNV1a(string str) public static void GenerateProject(Plugin plugin) { - var binaryPathX86 = Path.Combine(Utils.GetRootPath(), "x86", "plugins"); - var binaryPathX64 = Path.Combine(Utils.GetRootPath(), "x64", "plugins"); + var binaryPathX86 = Path.Combine(Utils.GetRootPath(), "x86", "plugins", "Dotx64Dbg"); + var binaryPathX64 = Path.Combine(Utils.GetRootPath(), "x64", "plugins", "Dotx64Dbg"); var assemblies = new string[] { - "Dotx64Dbg.Bindings.dll", "Dotx64Dbg.Managed.dll" + "Dotx64DbgBindings.dll", "Dotx64DbgManaged.dll" }; if (plugin.Info == null) From 93d27861120b29719cf8bd757259fc2870741de7 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 01:46:28 +0100 Subject: [PATCH 04/10] Improve error messages for invalid plugins --- src/Dotx64Managed/Plugins.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Dotx64Managed/Plugins.cs b/src/Dotx64Managed/Plugins.cs index d9dd5cc..fb1ad8f 100644 --- a/src/Dotx64Managed/Plugins.cs +++ b/src/Dotx64Managed/Plugins.cs @@ -68,6 +68,8 @@ public string SolutionFilePath return System.IO.Path.Combine(Path, Info.Name + ".sln"); } } + + public string Name => Info?.Name; } internal partial class Plugins @@ -290,8 +292,13 @@ void RegisterPlugin(string path) { var jsonFile = Path.Combine(path, "plugin.json"); var pluginInfo = GetPluginInfo(jsonFile); - var pathName = Path.GetFileName(path); + if(pluginInfo == null) + { + Console.WriteLine($"Unable to load plugin info: {jsonFile}"); + return; + } + var pathName = Path.GetFileName(path); var plugin = new Plugin() { Info = pluginInfo, @@ -337,11 +344,11 @@ void LoadPlugin(Plugin plugin) var pluginInfo = GetPluginInfo(plugin.ConfigPath); if (pluginInfo == null) { - Utils.DebugPrintLine("Unable to load plugin info."); + Utils.DebugPrintLine($"[{plugin.Name}] Unable to load plugin info."); return; } - Utils.DebugPrintLine("Plugin meta loaded, activating plugin."); + Utils.DebugPrintLine($"[{plugin.Name}] Plugin meta loaded, activating plugin."); plugin.Info = pluginInfo; if (!File.Exists(plugin.ProjectFilePath)) @@ -371,7 +378,7 @@ void RebuildOrUnloadPlugin(Plugin plugin, bool unloadWithoutSources = true) { if (plugin.Instance != null && plugin.SourceFiles.Count == 0) { - Utils.DebugPrintLine($"[PluginWatch] Plugin {plugin.Info.Name} has no sources, unloading."); + Utils.DebugPrintLine($"[PluginWatch] Plugin {plugin.Name} has no sources, unloading."); UnloadPlugin(plugin); return; } From 36859bcf5d6ea269ec9881dbe65f5b869e95131e Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 02:03:54 +0100 Subject: [PATCH 05/10] Add a log prefix for all system messages --- src/Dotx64Managed/AssemblyLoader.cs | 4 ++-- src/Dotx64Managed/Compiler.cs | 2 +- src/Dotx64Managed/Manager.cs | 4 ++-- src/Dotx64Managed/Plugins.Builder.cs | 6 +++--- src/Dotx64Managed/Plugins.Hotload.cs | 6 +++--- src/Dotx64Managed/Plugins.cs | 8 ++++---- src/Dotx64Managed/ScriptLoader.cs | 18 +++++++----------- src/Dotx64Managed/Settings.cs | 2 +- src/Dotx64Managed/Utils.cs | 7 +++---- 9 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/Dotx64Managed/AssemblyLoader.cs b/src/Dotx64Managed/AssemblyLoader.cs index 1f11199..0cdcc8d 100644 --- a/src/Dotx64Managed/AssemblyLoader.cs +++ b/src/Dotx64Managed/AssemblyLoader.cs @@ -24,7 +24,7 @@ private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs a { var assemblyName = new System.Reflection.AssemblyName(args.Name); - Utils.DebugPrintLine("[DEBUG] LoaderContext.AssemblyResolve({0})", assemblyName.Name); + Utils.DebugPrintLine("LoaderContext.AssemblyResolve({0})", assemblyName.Name); var extenalDll = externalAssemblies.FirstOrDefault(file => System.IO.Path.GetFileNameWithoutExtension(file) .Equals(assemblyName.Name, StringComparison.InvariantCultureIgnoreCase)); @@ -43,7 +43,7 @@ private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs a protected override Assembly Load(AssemblyName assemblyName) { - Utils.DebugPrintLine("[DEBUG] LoaderContext.Load({0})", assemblyName.Name); + Utils.DebugPrintLine("LoaderContext.Load({0})", assemblyName.Name); // See if the assembly is already loaded including the version. var loadedAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(assembly => diff --git a/src/Dotx64Managed/Compiler.cs b/src/Dotx64Managed/Compiler.cs index 3f62f92..ef5a129 100644 --- a/src/Dotx64Managed/Compiler.cs +++ b/src/Dotx64Managed/Compiler.cs @@ -180,7 +180,7 @@ private Result CompileInternal(List parsed, bool forScripting = fals if (!result.Success) { - Console.WriteLine("Build failed"); + Console.WriteLine("[DotX64Dbg] Build failed"); foreach (var info in result.Diagnostics) { diff --git a/src/Dotx64Managed/Manager.cs b/src/Dotx64Managed/Manager.cs index d29c3e0..323cad7 100644 --- a/src/Dotx64Managed/Manager.cs +++ b/src/Dotx64Managed/Manager.cs @@ -37,7 +37,7 @@ public static bool Init(int pluginHandle) if (!Settings.Load(Path.Combine(Utils.GetRootPath(), "dotx64dbg.json"))) { - Console.WriteLine("Failed to load settings, using default configuration"); + Console.WriteLine("[DotX64Dbg] Failed to load settings, using default configuration"); } if (Settings.EnableTests) @@ -45,7 +45,7 @@ public static bool Init(int pluginHandle) RunTests(); } - Console.WriteLine("Dotx64Dbg.Managed initialized"); + Console.WriteLine("[DotX64Dbg] Manager initialized"); } } catch (Exception ex) diff --git a/src/Dotx64Managed/Plugins.Builder.cs b/src/Dotx64Managed/Plugins.Builder.cs index bb9eefd..96682df 100644 --- a/src/Dotx64Managed/Plugins.Builder.cs +++ b/src/Dotx64Managed/Plugins.Builder.cs @@ -97,7 +97,7 @@ bool RebuildPlugin(Plugin plugin, System.Threading.CancellationToken token) { var stopwatch = new Stopwatch(); - Console.WriteLine("Rebuilding plugin '{0}'...", plugin.Info.Name); + Console.WriteLine("[DotX64Dbg] Rebuilding plugin '{0}'...", plugin.Info.Name); stopwatch.Start(); var compiler = new Compiler(plugin.Info.Name, plugin.BuildOutputPath) @@ -108,11 +108,11 @@ bool RebuildPlugin(Plugin plugin, System.Threading.CancellationToken token) if (!res.Success) { - Console.WriteLine("Build failed"); + Console.WriteLine("[DotX64Dbg] Build failed"); return false; } - Console.WriteLine("Compiled plugin '{0}' in {1} ms", plugin.Info.Name, stopwatch.ElapsedMilliseconds); + Console.WriteLine("[DotX64Dbg] Compiled plugin '{0}' in {1} ms", plugin.Info.Name, stopwatch.ElapsedMilliseconds); // Successfully built. plugin.RequiresRebuild = false; diff --git a/src/Dotx64Managed/Plugins.Hotload.cs b/src/Dotx64Managed/Plugins.Hotload.cs index ddd182c..ea8467a 100644 --- a/src/Dotx64Managed/Plugins.Hotload.cs +++ b/src/Dotx64Managed/Plugins.Hotload.cs @@ -47,7 +47,7 @@ void UnloadPluginInstance(Plugin plugin, CancellationToken token, bool isReloadi Expressions.RemoveAllFor(plugin); Menus.RemoveAllFor(plugin); - Console.WriteLine($"Unloaded plugin: {pluginName}"); + Console.WriteLine($"[DotX64Dbg] Unloaded plugin: {pluginName}"); } void RegisterPluginCommand(Plugin plugin, MethodInfo fn, Command cmd, object obj) @@ -227,7 +227,7 @@ bool ReloadPlugin(Plugin plugin, string newAssemblyPath, CancellationToken token var hotReload = Settings.EnableHotloading && plugin.Instance != null; - Console.WriteLine($"{(hotReload ? "Reloading" : "Loading")} '{plugin.Info.Name}'"); + Console.WriteLine($"[DotX64Dbg] {(hotReload ? "Reloading" : "Loading")} '{plugin.Info.Name}'"); try { @@ -350,7 +350,7 @@ bool ReloadPlugin(Plugin plugin, string newAssemblyPath, CancellationToken token return false; } - Console.WriteLine($"{(hotReload ? "Reloaded" : "Loaded")} '{plugin.Info.Name}'"); + Console.WriteLine($"[DotX64Dbg] {(hotReload ? "Reloaded" : "Loaded")} '{plugin.Info.Name}'"); return true; } diff --git a/src/Dotx64Managed/Plugins.cs b/src/Dotx64Managed/Plugins.cs index fb1ad8f..ce94353 100644 --- a/src/Dotx64Managed/Plugins.cs +++ b/src/Dotx64Managed/Plugins.cs @@ -93,11 +93,11 @@ private void SetupDirectories() } catch (Exception) { - Console.WriteLine("Unable to create directory for plugins: {0}", PluginsPath); + Console.WriteLine("[DotX64Dbg] Unable to create directory for plugins: {0}", PluginsPath); } } - Console.WriteLine("DotX64Dbg Plugins Path: {0}", PluginsPath); + Console.WriteLine("[DotX64Dbg] Plugins Path: {0}", PluginsPath); AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DotX64Dbg"); #if _X64_ @@ -182,7 +182,7 @@ public static void GenerateProject(Plugin plugin) return; var projectFilePath = plugin.ProjectFilePath; - Console.WriteLine($"Generating project for {plugin.Info.Name}"); + Console.WriteLine($"[DotX64Dbg] Generating project for {plugin.Info.Name}"); var projGen = new ProjectGenerator(); projGen.ReferencePathX86 = binaryPathX86; @@ -294,7 +294,7 @@ void RegisterPlugin(string path) var pluginInfo = GetPluginInfo(jsonFile); if(pluginInfo == null) { - Console.WriteLine($"Unable to load plugin info: {jsonFile}"); + Console.WriteLine($"[DotX64Dbg] Unable to load plugin info: {jsonFile}"); return; } diff --git a/src/Dotx64Managed/ScriptLoader.cs b/src/Dotx64Managed/ScriptLoader.cs index 293a377..efc9cdb 100644 --- a/src/Dotx64Managed/ScriptLoader.cs +++ b/src/Dotx64Managed/ScriptLoader.cs @@ -16,7 +16,7 @@ private static bool RunScriptCommand(string[] args) { if (args.Length != 2) { - Console.WriteLine("ERROR: Missing argument "); + Console.WriteLine("[DotX64Dbg] ERROR: Missing argument "); return false; } @@ -67,22 +67,18 @@ public static bool ExecuteScriptAssembly(Compiler.Result data) var scriptClass = GetScriptClass(newAssembly); if (scriptClass != null) { -#if DEBUG - Console.WriteLine("[DEBUG] Entry class: {0}", scriptClass.Name); -#endif + Utils.DebugPrintLine($"Entry class: {scriptClass.Name}"); } // Auto-generated method from Roslyn. var entry = scriptClass.GetMethod("
", BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic); if (entry == null) { - Console.WriteLine("No entrypoint defined"); + Console.WriteLine("[DotX64Dbg] No entrypoint defined"); return false; } -#if DEBUG - Console.WriteLine($"[DEBUG] Entrypoint {entry}"); -#endif + Utils.DebugPrintLine($"Entrypoint: {entry}"); ActiveScript = Task.Run(delegate () { @@ -109,7 +105,7 @@ public static bool ExecuteScriptFile(string file) var stopwatch = new Stopwatch(); - Console.WriteLine("Building script '{0}'...", file); + Console.WriteLine("[DotX64Dbg] Building script '{0}'...", file); stopwatch.Start(); var compiler = new Compiler(scriptName); @@ -119,11 +115,11 @@ public static bool ExecuteScriptFile(string file) if (!res.Success) { - Console.WriteLine("Build failed"); + Console.WriteLine("[DotX64Dbg] Build failed"); } else { - Console.WriteLine("Compiled script '{0}' in {1} ms", file, stopwatch.ElapsedMilliseconds); + Console.WriteLine("[DotX64Dbg] Compiled script '{0}' in {1} ms", file, stopwatch.ElapsedMilliseconds); ExecuteScriptAssembly(res); } diff --git a/src/Dotx64Managed/Settings.cs b/src/Dotx64Managed/Settings.cs index 560eeee..3493090 100644 --- a/src/Dotx64Managed/Settings.cs +++ b/src/Dotx64Managed/Settings.cs @@ -60,7 +60,7 @@ public static bool Load(string file) } catch (Exception ex) { - Console.WriteLine($"Exception while loading settings, using defaults.\n{ex}"); + Console.WriteLine($"[DotX64Dbg] Exception while loading settings, using defaults.\n{ex}"); LoadDefaults(); return false; } diff --git a/src/Dotx64Managed/Utils.cs b/src/Dotx64Managed/Utils.cs index f8cafa9..5868f6c 100644 --- a/src/Dotx64Managed/Utils.cs +++ b/src/Dotx64Managed/Utils.cs @@ -76,7 +76,7 @@ internal static string GetExceptionMessage(Exception ex) internal static void PrintException(Exception ex) { ex = ex.InnerException ?? ex; - Console.WriteLine($"Exception: {GetExceptionMessage(ex)}"); + Console.WriteLine($"[DotX64Dbg] Exception: {GetExceptionMessage(ex)}"); } internal static string ReadFileContents(string path, int retryAttempts = 5, int retryTime = 100) @@ -104,14 +104,13 @@ internal static string ReadFileContents(string path, int retryAttempts = 5, int [Conditional("DEBUG")] internal static void DebugPrintLine(string fmt, params object[] args) { - string strOut = string.Format(fmt, args); - Console.WriteLine($"[DEBUG] {strOut}"); + DebugPrintLine(string.Format(fmt, args)); } [Conditional("DEBUG")] internal static void DebugPrintLine(string line) { - Console.WriteLine($"[DEBUG] {line}"); + Console.WriteLine($"[DotX64Dbg][DEBUG] {line}"); } /// From dee5de153ac357f259c45a0791a2259478cf9608 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 02:04:11 +0100 Subject: [PATCH 06/10] Delete the cache on mismatch to be safe --- src/Dotx64Managed/Plugins.Builder.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Dotx64Managed/Plugins.Builder.cs b/src/Dotx64Managed/Plugins.Builder.cs index 96682df..48a6e20 100644 --- a/src/Dotx64Managed/Plugins.Builder.cs +++ b/src/Dotx64Managed/Plugins.Builder.cs @@ -156,7 +156,10 @@ void RebuildPlugins(System.Threading.CancellationToken token) return; } else - Utils.DebugPrintLine($"Skipking cache..."); + { + Utils.DebugPrintLine($"[{plugin.Name}] Deleting cache..."); + File.Delete(cacheFile); + } } if (RebuildPlugin(plugin, token)) { From 71915b75bbabae141b5dd7d7bfb94f71ae0eec1f Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 02:20:07 +0100 Subject: [PATCH 07/10] Simplify pluginit a bit --- src/Dotx64Dbg/Loader.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Dotx64Dbg/Loader.cpp b/src/Dotx64Dbg/Loader.cpp index d83d564..cd0c7e8 100644 --- a/src/Dotx64Dbg/Loader.cpp +++ b/src/Dotx64Dbg/Loader.cpp @@ -374,9 +374,7 @@ PLUG_EXPORT bool pluginit(PLUG_INITSTRUCT* initStruct) SCRIPTTYPEINFO sti = {}; sti.execute = CBEXECUTESCRIPT; - // Lets hope this never collides with any other plugin :shrug: - sti.id = 'D' + 'o' + 't' + 'x' + '6' + '4' + 'D' + 'b' + 'g'; - strcpy_s(sti.name, "Dotx64Dbg"); + strcpy_s(sti.name, "DotX64Dbg"); GuiRegisterScriptLanguage(&sti); From 1b104bbef10a87552e81b10fdce23fdb065f8c41 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 02:20:25 +0100 Subject: [PATCH 08/10] Bump cmkr to the latest version --- CMakeLists.txt | 166 ++++++------------------- cmake.toml | 28 +++-- cmkr.cmake | 253 ++++++++++++++++++++++++++++++++++++++ thirdparty/CMakeLists.txt | 11 +- 4 files changed, 316 insertions(+), 142 deletions(-) create mode 100644 cmkr.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 27133ae..98fb8ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,12 +7,11 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build") endif() -# Regenerate CMakeLists.txt automatically in the root project set(CMKR_ROOT_PROJECT OFF) if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(CMKR_ROOT_PROJECT ON) - # Bootstrap cmkr + # Bootstrap cmkr and automatically regenerate CMakeLists.txt include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT) if(CMKR_INCLUDE_RESULT) cmkr() @@ -20,10 +19,8 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) # Enable folder support set_property(GLOBAL PROPERTY USE_FOLDERS ON) -endif() -# Create a configure-time dependency on cmake.toml to improve IDE support -if(CMKR_ROOT_PROJECT) + # Create a configure-time dependency on cmake.toml to improve IDE support configure_file(cmake.toml cmake.toml COPYONLY) endif() @@ -33,18 +30,18 @@ project(Dotx64Dbg CXX ) - # Only have Release and Debug, there are configuration errors with managed otherwise. - SET(CMAKE_CONFIGURATION_TYPES "Debug;Release") - SET(CMAKE_VS_NUGET_PACKAGE_RESTORE ON) +include(CSharpUtilities) + +# Only have Release and Debug, there are configuration errors with managed otherwise. +SET(CMAKE_CONFIGURATION_TYPES "Debug;Release") +SET(CMAKE_VS_NUGET_PACKAGE_RESTORE ON) - include(CSharpUtilities) - - # Workaround for CLR projects, there is a pending fix for this: - # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7807 which corrects the exception option in use of CLR - string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT}") - string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_CXX_FLAGS_DEBUG_INIT}") - string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") +# Workaround for CLR projects, there is a pending fix for this: +# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7807 which corrects the exception option in use of CLR +string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT}") +string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_CXX_FLAGS_DEBUG_INIT}") +string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(BUILD_OUTPUT_DIR ${CMAKE_SOURCE_DIR}/bin/x64) @@ -52,7 +49,7 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) set(BUILD_OUTPUT_DIR ${CMAKE_SOURCE_DIR}/bin/x32) endif() -# thirdparty +# Subdirectory: thirdparty set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER}) if(CMAKE_FOLDER) set(CMAKE_FOLDER "${CMAKE_FOLDER}/thirdparty") @@ -62,17 +59,9 @@ endif() add_subdirectory(thirdparty) set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER}) -# Target Dotx64DbgCommon -set(CMKR_TARGET Dotx64DbgCommon) -set(Dotx64DbgCommon_SOURCES "") - -set(CMKR_SOURCES ${Dotx64DbgCommon_SOURCES}) +# Target: Dotx64DbgCommon add_library(Dotx64DbgCommon INTERFACE) -if(Dotx64DbgCommon_SOURCES) - target_sources(Dotx64DbgCommon INTERFACE ${Dotx64DbgCommon_SOURCES}) -endif() - add_library(dotx64dbg::common ALIAS Dotx64DbgCommon) target_compile_features(Dotx64DbgCommon INTERFACE cxx_std_17 @@ -86,14 +75,8 @@ target_link_options(Dotx64DbgCommon INTERFACE "/DEBUG" ) -unset(CMKR_TARGET) -unset(CMKR_SOURCES) - -# Target Dotx64DbgBindings -set(CMKR_TARGET Dotx64DbgBindings) -set(Dotx64DbgBindings_SOURCES "") - -list(APPEND Dotx64DbgBindings_SOURCES +# Target: Dotx64DbgBindings +set(Dotx64DbgBindings_SOURCES "src/Bindings/Breakpoints.cpp" "src/Bindings/Commands.cpp" "src/Bindings/Debugger.cpp" @@ -125,19 +108,12 @@ list(APPEND Dotx64DbgBindings_SOURCES "src/Bindings/Marshal.hpp" "src/Bindings/Mnemonic.hpp" "src/Bindings/Register.hpp" -) - -list(APPEND Dotx64DbgBindings_SOURCES cmake.toml ) -set(CMKR_SOURCES ${Dotx64DbgBindings_SOURCES}) add_library(Dotx64DbgBindings SHARED) -if(Dotx64DbgBindings_SOURCES) - target_sources(Dotx64DbgBindings PRIVATE ${Dotx64DbgBindings_SOURCES}) -endif() - +target_sources(Dotx64DbgBindings PRIVATE ${Dotx64DbgBindings_SOURCES}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${Dotx64DbgBindings_SOURCES}) add_library(dotx64dbg::bindings ALIAS Dotx64DbgBindings) @@ -179,6 +155,7 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 4) # x32 ) endif() +set(CMKR_TARGET Dotx64DbgBindings) if(CMAKE_SIZEOF_VOID_P EQUAL 8) target_link_options(Dotx64DbgBindings PRIVATE "/DELAYLOAD:x64dbg.dll") target_link_options(Dotx64DbgBindings PRIVATE "/DELAYLOAD:x64bridge.dll") @@ -188,14 +165,8 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() target_link_options(Dotx64DbgBindings PRIVATE "/DELAYLOAD:titanengine.dll") -unset(CMKR_TARGET) -unset(CMKR_SOURCES) - -# Target Dotx64DbgManaged -set(CMKR_TARGET Dotx64DbgManaged) -set(Dotx64DbgManaged_SOURCES "") - -list(APPEND Dotx64DbgManaged_SOURCES +# Target: Dotx64DbgManaged +set(Dotx64DbgManaged_SOURCES "src/Dotx64Managed/API/Analysis/RegisterMask.cs" "src/Dotx64Managed/API/Assembler.cs" "src/Dotx64Managed/API/Assembler.Instructions.cs" @@ -253,19 +224,12 @@ list(APPEND Dotx64DbgManaged_SOURCES "src/Dotx64Managed/Settings.cs" "src/Dotx64Managed/Tests.cs" "src/Dotx64Managed/Utils.cs" -) - -list(APPEND Dotx64DbgManaged_SOURCES cmake.toml ) -set(CMKR_SOURCES ${Dotx64DbgManaged_SOURCES}) add_library(Dotx64DbgManaged SHARED) -if(Dotx64DbgManaged_SOURCES) - target_sources(Dotx64DbgManaged PRIVATE ${Dotx64DbgManaged_SOURCES}) -endif() - +target_sources(Dotx64DbgManaged PRIVATE ${Dotx64DbgManaged_SOURCES}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${Dotx64DbgManaged_SOURCES}) add_library(dotx64dbg::managed ALIAS Dotx64DbgManaged) @@ -336,14 +300,8 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8) # x64 ) endif() -unset(CMKR_TARGET) -unset(CMKR_SOURCES) - -# Target Dotx64DbgTests -set(CMKR_TARGET Dotx64DbgTests) -set(Dotx64DbgTests_SOURCES "") - -list(APPEND Dotx64DbgTests_SOURCES +# Target: Dotx64DbgTests +set(Dotx64DbgTests_SOURCES "src/Dotx64DbgTests/Testing.cs" "src/Dotx64DbgTests/Runner.cs" "src/Dotx64DbgTests/Tests/Tests.Assembler.cs" @@ -352,24 +310,12 @@ list(APPEND Dotx64DbgTests_SOURCES "src/Dotx64DbgTests/Tests/Tests.Operands.cs" "src/Dotx64DbgTests/Tests/Tests.RegisterMaskGp.cs" "src/Dotx64DbgTests/Tests/Tests.Registers.cs" -) - -list(APPEND Dotx64DbgTests_SOURCES cmake.toml ) -set(CMKR_SOURCES ${Dotx64DbgTests_SOURCES}) add_executable(Dotx64DbgTests) -if(Dotx64DbgTests_SOURCES) - target_sources(Dotx64DbgTests PRIVATE ${Dotx64DbgTests_SOURCES}) -endif() - -get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT) -if(NOT CMKR_VS_STARTUP_PROJECT) - set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Dotx64DbgTests) -endif() - +target_sources(Dotx64DbgTests PRIVATE ${Dotx64DbgTests_SOURCES}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${Dotx64DbgTests_SOURCES}) if(CMAKE_SIZEOF_VOID_P EQUAL 4) # x32 @@ -436,29 +382,21 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8) # x64 ) endif() -unset(CMKR_TARGET) -unset(CMKR_SOURCES) - -# Target Dotx64Dbg -set(CMKR_TARGET Dotx64Dbg) -set(Dotx64Dbg_SOURCES "") +get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT) +if(NOT CMKR_VS_STARTUP_PROJECT) + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Dotx64DbgTests) +endif() -list(APPEND Dotx64Dbg_SOURCES +# Target: Dotx64Dbg +set(Dotx64Dbg_SOURCES "src/Dotx64Dbg/Loader.cpp" "src/Dotx64Dbg/Plugin.cpp" -) - -list(APPEND Dotx64Dbg_SOURCES cmake.toml ) -set(CMKR_SOURCES ${Dotx64Dbg_SOURCES}) add_library(Dotx64Dbg SHARED) -if(Dotx64Dbg_SOURCES) - target_sources(Dotx64Dbg PRIVATE ${Dotx64Dbg_SOURCES}) -endif() - +target_sources(Dotx64Dbg PRIVATE ${Dotx64Dbg_SOURCES}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${Dotx64Dbg_SOURCES}) add_library(dotx64dbg::dotx64dbg ALIAS Dotx64Dbg) @@ -499,28 +437,15 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 4) # x32 ) endif() -unset(CMKR_TARGET) -unset(CMKR_SOURCES) - -# Target Dotx64DbgLoader -set(CMKR_TARGET Dotx64DbgLoader) -set(Dotx64DbgLoader_SOURCES "") - -list(APPEND Dotx64DbgLoader_SOURCES +# Target: Dotx64DbgLoader +set(Dotx64DbgLoader_SOURCES "src/Dotx64DbgLoader/Loader.cpp" -) - -list(APPEND Dotx64DbgLoader_SOURCES cmake.toml ) -set(CMKR_SOURCES ${Dotx64DbgLoader_SOURCES}) add_library(Dotx64DbgLoader SHARED) -if(Dotx64DbgLoader_SOURCES) - target_sources(Dotx64DbgLoader PRIVATE ${Dotx64DbgLoader_SOURCES}) -endif() - +target_sources(Dotx64DbgLoader PRIVATE ${Dotx64DbgLoader_SOURCES}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${Dotx64DbgLoader_SOURCES}) if(CMAKE_SIZEOF_VOID_P EQUAL 4) # x32 @@ -569,30 +494,19 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 4) # x32 ) endif() -unset(CMKR_TARGET) -unset(CMKR_SOURCES) - -# Target Dotx64DbgResources -set(CMKR_TARGET Dotx64DbgResources) -set(Dotx64DbgResources_SOURCES "") - -list(APPEND Dotx64DbgResources_SOURCES +# Target: Dotx64DbgResources +set(Dotx64DbgResources_SOURCES cmake.toml ) -set(CMKR_SOURCES ${Dotx64DbgResources_SOURCES}) add_custom_target(Dotx64DbgResources SOURCES) -if(Dotx64DbgResources_SOURCES) - target_sources(Dotx64DbgResources PRIVATE ${Dotx64DbgResources_SOURCES}) -endif() +target_sources(Dotx64DbgResources PRIVATE ${Dotx64DbgResources_SOURCES}) +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${Dotx64DbgResources_SOURCES}) +set(CMKR_TARGET Dotx64DbgResources) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/Resources ${BUILD_OUTPUT_DIR}/Resources ) - -unset(CMKR_TARGET) -unset(CMKR_SOURCES) - diff --git a/cmake.toml b/cmake.toml index 0830a3c..0527a2d 100644 --- a/cmake.toml +++ b/cmake.toml @@ -3,18 +3,16 @@ name = "Dotx64Dbg" languages = ["CSharp", "CXX"] cmake-after = ''' - # Only have Release and Debug, there are configuration errors with managed otherwise. - SET(CMAKE_CONFIGURATION_TYPES "Debug;Release") - SET(CMAKE_VS_NUGET_PACKAGE_RESTORE ON) +# Only have Release and Debug, there are configuration errors with managed otherwise. +SET(CMAKE_CONFIGURATION_TYPES "Debug;Release") +SET(CMAKE_VS_NUGET_PACKAGE_RESTORE ON) - include(CSharpUtilities) - - # Workaround for CLR projects, there is a pending fix for this: - # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7807 which corrects the exception option in use of CLR - string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT}") - string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_CXX_FLAGS_DEBUG_INIT}") - string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") +# Workaround for CLR projects, there is a pending fix for this: +# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7807 which corrects the exception option in use of CLR +string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT}") +string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_CXX_FLAGS_DEBUG_INIT}") +string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(BUILD_OUTPUT_DIR ${CMAKE_SOURCE_DIR}/bin/x64) @@ -183,7 +181,13 @@ VS_GLOBAL_ProduceReferenceAssembly = "false" VS_GLOBAL_ProduceReferenceAssemblyInOutDir = "false" VS_GLOBAL_CopyLocalLockFileAssemblies = "true" VS_GLOBAL_SatelliteResourceLanguages = "neutral" -VS_PACKAGE_REFERENCES = "Microsoft.CodeAnalysis.Compilers_3.10.0;NuGet.Configuration_5.11.0;NuGet.Frameworks_5.11.0;NuGet.Protocol_5.11.0;NuGet.Versioning_5.11.0" +VS_PACKAGE_REFERENCES = [ + "Microsoft.CodeAnalysis.Compilers_3.10.0", + "NuGet.Configuration_5.11.0", + "NuGet.Frameworks_5.11.0", + "NuGet.Protocol_5.11.0", + "NuGet.Versioning_5.11.0" +] VS_DOTNET_REFERENCES_COPY_LOCAL = "false" x64.RUNTIME_OUTPUT_DIRECTORY_RELEASE = "${BUILD_OUTPUT_DIR}" x64.RUNTIME_OUTPUT_DIRECTORY_DEBUG = "${BUILD_OUTPUT_DIR}" diff --git a/cmkr.cmake b/cmkr.cmake new file mode 100644 index 0000000..cdeea6e --- /dev/null +++ b/cmkr.cmake @@ -0,0 +1,253 @@ +include_guard() + +# Change these defaults to point to your infrastructure if desired +set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE) +set(CMKR_TAG "v0.2.26" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) +set(CMKR_COMMIT_HASH "" CACHE STRING "cmkr git commit hash (optional)" FORCE) + +# To bootstrap/generate a cmkr project: cmake -P cmkr.cmake +if(CMAKE_SCRIPT_MODE_FILE) + set(CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}/build") + set(CMAKE_CURRENT_BINARY_DIR "${CMAKE_BINARY_DIR}") + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}") +endif() + +# Set these from the command line to customize for development/debugging purposes +set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable") +set(CMKR_SKIP_GENERATION OFF CACHE BOOL "skip automatic cmkr generation") +set(CMKR_BUILD_TYPE "Debug" CACHE STRING "cmkr build configuration") +mark_as_advanced(CMKR_REPO CMKR_TAG CMKR_COMMIT_HASH CMKR_EXECUTABLE CMKR_SKIP_GENERATION CMKR_BUILD_TYPE) + +# Disable cmkr if generation is disabled +if(DEFINED ENV{CI} OR CMKR_SKIP_GENERATION OR CMKR_BUILD_SKIP_GENERATION) + message(STATUS "[cmkr] Skipping automatic cmkr generation") + unset(CMKR_BUILD_SKIP_GENERATION CACHE) + macro(cmkr) + endmacro() + return() +endif() + +# Disable cmkr if no cmake.toml file is found +if(NOT CMAKE_SCRIPT_MODE_FILE AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake.toml") + message(AUTHOR_WARNING "[cmkr] Not found: ${CMAKE_CURRENT_SOURCE_DIR}/cmake.toml") + macro(cmkr) + endmacro() + return() +endif() + +# Convert a Windows native path to CMake path +if(CMKR_EXECUTABLE MATCHES "\\\\") + string(REPLACE "\\" "/" CMKR_EXECUTABLE_CMAKE "${CMKR_EXECUTABLE}") + set(CMKR_EXECUTABLE "${CMKR_EXECUTABLE_CMAKE}" CACHE FILEPATH "" FORCE) + unset(CMKR_EXECUTABLE_CMAKE) +endif() + +# Helper macro to execute a process (COMMAND_ERROR_IS_FATAL ANY is 3.19 and higher) +function(cmkr_exec) + execute_process(COMMAND ${ARGV} RESULT_VARIABLE CMKR_EXEC_RESULT) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "cmkr_exec(${ARGV}) failed (exit code ${CMKR_EXEC_RESULT})") + endif() +endfunction() + +# Windows-specific hack (CMAKE_EXECUTABLE_PREFIX is not set at the moment) +if(WIN32) + set(CMKR_EXECUTABLE_NAME "cmkr.exe") +else() + set(CMKR_EXECUTABLE_NAME "cmkr") +endif() + +# Use cached cmkr if found +if(DEFINED ENV{CMKR_CACHE}) + set(CMKR_DIRECTORY_PREFIX "$ENV{CMKR_CACHE}") + string(REPLACE "\\" "/" CMKR_DIRECTORY_PREFIX "${CMKR_DIRECTORY_PREFIX}") + if(NOT CMKR_DIRECTORY_PREFIX MATCHES "\\/$") + set(CMKR_DIRECTORY_PREFIX "${CMKR_DIRECTORY_PREFIX}/") + endif() + # Build in release mode for the cache + set(CMKR_BUILD_TYPE "Release") +else() + set(CMKR_DIRECTORY_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/_cmkr_") +endif() +set(CMKR_DIRECTORY "${CMKR_DIRECTORY_PREFIX}${CMKR_TAG}") +set(CMKR_CACHED_EXECUTABLE "${CMKR_DIRECTORY}/bin/${CMKR_EXECUTABLE_NAME}") + +# Helper function to check if a string starts with a prefix +# Cannot use MATCHES, see: https://github.com/build-cpp/cmkr/issues/61 +function(cmkr_startswith str prefix result) + string(LENGTH "${prefix}" prefix_length) + string(LENGTH "${str}" str_length) + if(prefix_length LESS_EQUAL str_length) + string(SUBSTRING "${str}" 0 ${prefix_length} str_prefix) + if(prefix STREQUAL str_prefix) + set("${result}" ON PARENT_SCOPE) + return() + endif() + endif() + set("${result}" OFF PARENT_SCOPE) +endfunction() + +# Handle upgrading logic +if(CMKR_EXECUTABLE AND NOT CMKR_CACHED_EXECUTABLE STREQUAL CMKR_EXECUTABLE) + cmkr_startswith("${CMKR_EXECUTABLE}" "${CMAKE_CURRENT_BINARY_DIR}/_cmkr" CMKR_STARTSWITH_BUILD) + cmkr_startswith("${CMKR_EXECUTABLE}" "${CMKR_DIRECTORY_PREFIX}" CMKR_STARTSWITH_CACHE) + if(CMKR_STARTSWITH_BUILD) + if(DEFINED ENV{CMKR_CACHE}) + message(AUTHOR_WARNING "[cmkr] Switching to cached cmkr: '${CMKR_CACHED_EXECUTABLE}'") + if(EXISTS "${CMKR_CACHED_EXECUTABLE}") + set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE) + else() + unset(CMKR_EXECUTABLE CACHE) + endif() + else() + message(AUTHOR_WARNING "[cmkr] Upgrading '${CMKR_EXECUTABLE}' to '${CMKR_CACHED_EXECUTABLE}'") + unset(CMKR_EXECUTABLE CACHE) + endif() + elseif(DEFINED ENV{CMKR_CACHE} AND CMKR_STARTSWITH_CACHE) + message(AUTHOR_WARNING "[cmkr] Upgrading cached '${CMKR_EXECUTABLE}' to '${CMKR_CACHED_EXECUTABLE}'") + unset(CMKR_EXECUTABLE CACHE) + endif() +endif() + +if(CMKR_EXECUTABLE AND EXISTS "${CMKR_EXECUTABLE}") + message(VERBOSE "[cmkr] Found cmkr: '${CMKR_EXECUTABLE}'") +elseif(CMKR_EXECUTABLE AND NOT CMKR_EXECUTABLE STREQUAL CMKR_CACHED_EXECUTABLE) + message(FATAL_ERROR "[cmkr] '${CMKR_EXECUTABLE}' not found") +elseif(NOT CMKR_EXECUTABLE AND EXISTS "${CMKR_CACHED_EXECUTABLE}") + set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE) + message(STATUS "[cmkr] Found cached cmkr: '${CMKR_EXECUTABLE}'") +else() + set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE) + message(VERBOSE "[cmkr] Bootstrapping '${CMKR_EXECUTABLE}'") + + message(STATUS "[cmkr] Fetching cmkr...") + if(EXISTS "${CMKR_DIRECTORY}") + cmkr_exec("${CMAKE_COMMAND}" -E rm -rf "${CMKR_DIRECTORY}") + endif() + find_package(Git QUIET REQUIRED) + cmkr_exec("${GIT_EXECUTABLE}" + clone + --config advice.detachedHead=false + --branch ${CMKR_TAG} + --depth 1 + ${CMKR_REPO} + "${CMKR_DIRECTORY}" + ) + if(CMKR_COMMIT_HASH) + execute_process( + COMMAND "${GIT_EXECUTABLE}" checkout -q "${CMKR_COMMIT_HASH}" + RESULT_VARIABLE CMKR_EXEC_RESULT + WORKING_DIRECTORY "${CMKR_DIRECTORY}" + ) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "Tag '${CMKR_TAG}' hash is not '${CMKR_COMMIT_HASH}'") + endif() + endif() + message(STATUS "[cmkr] Building cmkr (using system compiler)...") + cmkr_exec("${CMAKE_COMMAND}" + --no-warn-unused-cli + "${CMKR_DIRECTORY}" + "-B${CMKR_DIRECTORY}/build" + "-DCMAKE_BUILD_TYPE=${CMKR_BUILD_TYPE}" + "-DCMAKE_UNITY_BUILD=ON" + "-DCMAKE_INSTALL_PREFIX=${CMKR_DIRECTORY}" + "-DCMKR_GENERATE_DOCUMENTATION=OFF" + ) + cmkr_exec("${CMAKE_COMMAND}" + --build "${CMKR_DIRECTORY}/build" + --config "${CMKR_BUILD_TYPE}" + --parallel + ) + cmkr_exec("${CMAKE_COMMAND}" + --install "${CMKR_DIRECTORY}/build" + --config "${CMKR_BUILD_TYPE}" + --prefix "${CMKR_DIRECTORY}" + --component cmkr + ) + if(NOT EXISTS ${CMKR_EXECUTABLE}) + message(FATAL_ERROR "[cmkr] Failed to bootstrap '${CMKR_EXECUTABLE}'") + endif() + cmkr_exec("${CMKR_EXECUTABLE}" version) + message(STATUS "[cmkr] Bootstrapped ${CMKR_EXECUTABLE}") +endif() +execute_process(COMMAND "${CMKR_EXECUTABLE}" version + RESULT_VARIABLE CMKR_EXEC_RESULT +) +if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "[cmkr] Failed to get version, try clearing the cache and rebuilding") +endif() + +# Use cmkr.cmake as a script +if(CMAKE_SCRIPT_MODE_FILE) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake.toml") + execute_process(COMMAND "${CMKR_EXECUTABLE}" init + RESULT_VARIABLE CMKR_EXEC_RESULT + ) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "[cmkr] Failed to bootstrap cmkr project. Please report an issue: https://github.com/build-cpp/cmkr/issues/new") + else() + message(STATUS "[cmkr] Modify cmake.toml and then configure using: cmake -B build") + endif() + else() + execute_process(COMMAND "${CMKR_EXECUTABLE}" gen + RESULT_VARIABLE CMKR_EXEC_RESULT + ) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "[cmkr] Failed to generate project.") + else() + message(STATUS "[cmkr] Configure using: cmake -B build") + endif() + endif() +endif() + +# This is the macro that contains black magic +macro(cmkr) + # When this macro is called from the generated file, fake some internal CMake variables + get_source_file_property(CMKR_CURRENT_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}" CMKR_CURRENT_LIST_FILE) + if(CMKR_CURRENT_LIST_FILE) + set(CMAKE_CURRENT_LIST_FILE "${CMKR_CURRENT_LIST_FILE}") + get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) + endif() + + # File-based include guard (include_guard is not documented to work) + get_source_file_property(CMKR_INCLUDE_GUARD "${CMAKE_CURRENT_LIST_FILE}" CMKR_INCLUDE_GUARD) + if(NOT CMKR_INCLUDE_GUARD) + set_source_files_properties("${CMAKE_CURRENT_LIST_FILE}" PROPERTIES CMKR_INCLUDE_GUARD TRUE) + + file(SHA256 "${CMAKE_CURRENT_LIST_FILE}" CMKR_LIST_FILE_SHA256_PRE) + + # Generate CMakeLists.txt + cmkr_exec("${CMKR_EXECUTABLE}" gen + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + ) + + file(SHA256 "${CMAKE_CURRENT_LIST_FILE}" CMKR_LIST_FILE_SHA256_POST) + + # Delete the temporary file if it was left for some reason + set(CMKR_TEMP_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CMakerLists.txt") + if(EXISTS "${CMKR_TEMP_FILE}") + file(REMOVE "${CMKR_TEMP_FILE}") + endif() + + if(NOT CMKR_LIST_FILE_SHA256_PRE STREQUAL CMKR_LIST_FILE_SHA256_POST) + # Copy the now-generated CMakeLists.txt to CMakerLists.txt + # This is done because you cannot include() a file you are currently in + configure_file(CMakeLists.txt "${CMKR_TEMP_FILE}" COPYONLY) + + # Add the macro required for the hack at the start of the cmkr macro + set_source_files_properties("${CMKR_TEMP_FILE}" PROPERTIES + CMKR_CURRENT_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}" + ) + + # 'Execute' the newly-generated CMakeLists.txt + include("${CMKR_TEMP_FILE}") + + # Delete the generated file + file(REMOVE "${CMKR_TEMP_FILE}") + + # Do not execute the rest of the original CMakeLists.txt + return() + endif() + # Resume executing the unmodified CMakeLists.txt + endif() +endmacro() diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 6f04866..9e0b092 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -16,8 +16,12 @@ option(ZYDIS_BUILD_DOXYGEN "" OFF) include(FetchContent) +# Fix warnings about DOWNLOAD_EXTRACT_TIMESTAMP +if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif() message(STATUS "Fetching Zydis (53dd088062c734e7882b3a77ff287bdf3356d977)...") -FetchContent_Declare(Zydis +FetchContent_Declare(Zydis SYSTEM GIT_REPOSITORY "https://github.com/zyantific/zydis" GIT_TAG @@ -26,7 +30,7 @@ FetchContent_Declare(Zydis FetchContent_MakeAvailable(Zydis) message(STATUS "Fetching asmjit (0c03ed2f7497441ac0de232bda2e6b8cc041b2dc)...") -FetchContent_Declare(asmjit +FetchContent_Declare(asmjit SYSTEM GIT_REPOSITORY "https://github.com/asmjit/asmjit" GIT_TAG @@ -35,11 +39,10 @@ FetchContent_Declare(asmjit FetchContent_MakeAvailable(asmjit) message(STATUS "Fetching x64dbg_pluginsdk (11536beb42ec7cb9c0c8112af02d78fe083256d3)...") -FetchContent_Declare(x64dbg_pluginsdk +FetchContent_Declare(x64dbg_pluginsdk SYSTEM GIT_REPOSITORY "https://github.com/ZehMatt/x64dbg-pluginsdk" GIT_TAG 11536beb42ec7cb9c0c8112af02d78fe083256d3 ) FetchContent_MakeAvailable(x64dbg_pluginsdk) - From 2b0a46edbba5c7d0abdc6ac27c252985b3d35b81 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 02:22:15 +0100 Subject: [PATCH 09/10] Bump NuGet to 5.11.5 https://github.com/advisories/GHSA-6qmf-mmc7-6c2p --- CMakeLists.txt | 2 +- cmake.toml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98fb8ff..22b1dbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -273,7 +273,7 @@ set_target_properties(Dotx64DbgManaged PROPERTIES VS_GLOBAL_SatelliteResourceLanguages neutral VS_PACKAGE_REFERENCES - "Microsoft.CodeAnalysis.Compilers_3.10.0;NuGet.Configuration_5.11.0;NuGet.Frameworks_5.11.0;NuGet.Protocol_5.11.0;NuGet.Versioning_5.11.0" + "Microsoft.CodeAnalysis.Compilers_3.10.0;NuGet.Configuration_5.11.5;NuGet.Frameworks_5.11.5;NuGet.Protocol_5.11.5;NuGet.Versioning_5.11.5" VS_DOTNET_REFERENCES_COPY_LOCAL false ) diff --git a/cmake.toml b/cmake.toml index 0527a2d..aea5dc2 100644 --- a/cmake.toml +++ b/cmake.toml @@ -183,10 +183,10 @@ VS_GLOBAL_CopyLocalLockFileAssemblies = "true" VS_GLOBAL_SatelliteResourceLanguages = "neutral" VS_PACKAGE_REFERENCES = [ "Microsoft.CodeAnalysis.Compilers_3.10.0", - "NuGet.Configuration_5.11.0", - "NuGet.Frameworks_5.11.0", - "NuGet.Protocol_5.11.0", - "NuGet.Versioning_5.11.0" + "NuGet.Configuration_5.11.5", + "NuGet.Frameworks_5.11.5", + "NuGet.Protocol_5.11.5", + "NuGet.Versioning_5.11.5" ] VS_DOTNET_REFERENCES_COPY_LOCAL = "false" x64.RUNTIME_OUTPUT_DIRECTORY_RELEASE = "${BUILD_OUTPUT_DIR}" From b3c173eea0d58a68882462f65d78673ac85c9cac Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 16 Mar 2024 02:25:18 +0100 Subject: [PATCH 10/10] Bump GitHub Actions versions --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e589cf5..5e56ba9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.3 + uses: microsoft/setup-msbuild@v2 - name: Build run: | cmake . -B build -DCMAKE_BUILD_TYPE=Release -A ${{ matrix.platform.build }} @@ -35,7 +35,7 @@ jobs: Dotx64DbgTests.exe popd - name: Upload artifacts (CI) - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: dotx64Dbg-${{ runner.os }}-${{ matrix.platform.arch }} path: bin/ @@ -46,7 +46,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Fetch artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: path: artifacts - name: Display structure of downloaded files @@ -72,22 +72,22 @@ jobs: find ./package -type f -name '*.exp' -delete find ./package -type f -name '*.ilk' -delete - name: Upload package (CI) - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: dotx64dbg path: package if-no-files-found: error - name: Compress package - uses: papeloto/action-zip@v1 + uses: papeloto/action-zip@1379ea20d4c5705669ba81fd626dd01b1c738f26 # v1.2 if: ${{ startsWith(github.ref, 'refs/tags/') }} with: files: package/ dest: ${{ github.event.repository.name }}-${{ github.ref_name }}.zip - name: Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@d99959edae48b5ffffd7b00da66dcdb0a33a52ee # v2.0.2 if: ${{ startsWith(github.ref, 'refs/tags/') }} with: prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') || contains(github.ref, '-pre') }} files: ${{ github.event.repository.name }}-${{ github.ref_name }}.zip env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}