Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Harmony Injector Help

Featured Replies

Posted

I was trying Harmony it looks very promising as it is very useful for me. My problem is i can't inject the created dll into my assembly to do some test using MegaDumper. I got (Failed to get Base of kernel32)

What i did is just intercept the calculate function inside another form application.

Is there any simple application for injecting dll ?

 

DLL Code to inject

using Harmony;
using System;
using System.Reflection;
using Harmony_test;
using System.Windows.Forms;

namespace ClassLibrary1
{
    public class Class1
    {
        static void Main(string[] args)
        {
            var harmony = HarmonyInstance.Create("com.test.test");
            harmony.PatchAll(Assembly.GetExecutingAssembly());
            
        }
    }

    [HarmonyPatch(typeof(Form1))]
    [HarmonyPatch("calculate")]
    [HarmonyPatch(new Type[] { typeof(int), typeof(int) })]
    class Patch
    {
        static void Prefix(int num1, int num2)
        {
            MessageBox.Show("MOD is loaded"); 
        }
    }
}

 

Test App

        private void button1_Click(object sender, EventArgs e)
        {
            calculate(int.Parse(textBox1.Text),int.Parse(textBox2.Text));
        }

        private void calculate (int num1, int num2)
        {
            textBox3.Text = (num1 + num2).ToString();
        }

 

For Harmony You need to load Target executable to the current domain in other words you need to create application loader.

The Step:

1. Create new WinForms (loader)

- Add reference to 0Harmony.dll and Target.exe

- Add button, name it btnOpenApp with click handler

private void btnOpenApp_Click(object sender, EventArgs e)
{
    AssemblyName assemblyName = AssemblyName.GetAssemblyName(@"c:\path\to\Target.exe");
    var assembly = Assembly.Load(assemblyName);
    var methodBase = assembly.ManifestModule.ResolveMethod(assembly.EntryPoint.MetadataToken);

    // do the patch
    Harmony.Patch();
    
    // Open the Target
    new Thread(() =>
    {
        // assume method entry point is static and doesn't have parameter
        methodBase.Invoke(null, null);
    }).Start();
}

2. Create class Harmony.cs

using Harmony;
using System;
using System.Reflection;
using System.Windows.Forms;

namespace YourWinformsNameSpace
{
    internal static class Harmony
    {
        public static void Patch()
        {
            HarmonyInstance h = HarmonyInstance.Create("test.patch.by.ewwink");
            h.PatchAll(Assembly.GetExecutingAssembly());
        }

        [HarmonyPatch(typeof(Target.FormClass), "calculate")]
        [HarmonyPatch(new Type[] { typeof(int), typeof(int) })]
        public class Patchcalculate
        {
            static void Prefix(int num1, ref int num2)
            {
                MessageBox.Show(string.Format("Second param {0} will be patched to 7", num2));
                num2 = 7;
            }
        }
    }
}

The above will patch second parameter for calculate method to 7.

make sure target Framework and CPU is match.

  • Author

Thank you, i will try it and report back 

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.