Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform improvements #97

Merged
merged 2 commits into from
Apr 12, 2024
Merged

Platform improvements #97

merged 2 commits into from
Apr 12, 2024

Conversation

mrexodia
Copy link
Member

Just added a few APIs I needed while writing a simple plugin to map a file into memory:

using System;
using Dotx64Dbg;

public partial class MyPlugin : IPlugin, IHotload
{
    /// <summary>
    /// Called as soon the plugin is first loaded, consequent hot-loads will not call this again.
    /// </summary>
    public MyPlugin()
    {
        Console.WriteLine("Hello World");
    }

    [UI.Menu(UI.Menu.Root.MemoryMap, "Map file")]
    public void MapFile()
    {
        var file = Platform.OpenFileBrowse("Select a file to map", "All files (*.*)");
        if(string.IsNullOrEmpty(file))
            return;
        
        var data = System.IO.File.ReadAllBytes(file);
        var page = Memory.RemoteAlloc(0, data.Length);
        if(page == 0)
        {
            Platform.MessageBoxError("Failed to allocate memory");
            return;
        }

        if(Memory.Write(page, data) != data.Length)
        {
            Platform.MessageBoxError("Failed to write memory");
            return;
        }

        UI.MemoryMap.Update();
        var ptr = "0x" + page.ToString("X");
        Platform.SetClipboardText(ptr);
        Platform.MessageBoxInfo($"File mapped to: {ptr} (address copied to clipboard)");
        UI.MemoryMap.SetSelection(new UI.Selection(page, page));
    }

    /// <summary>
    /// This is called after construction. This is also only called once.
    /// </summary>
    public void Startup()
    {
    }

    /// <summary>
    /// 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.
    /// </summary>
    public void OnHotload()
    {
    }

    /// <summary>
    /// This is called right before the plugin is about to be shutdown.
    /// </summary>
    public void Shutdown()
    {
    }
} 

We should probably allow flattening the menus btw. I think if a plugin has a single menu entry it can all just be added directly to the context menu instead of the indirections there are now...

@ZehMatt
Copy link
Collaborator

ZehMatt commented Apr 11, 2024

Needs the CI fixed otherwise looking good.

@mrexodia mrexodia merged commit 7670610 into master Apr 12, 2024
5 checks passed
@mrexodia mrexodia deleted the platform-improvements branch April 12, 2024 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants