// ClassLibrary1.dll using System; using System.IO; using…
- User
// ClassLibrary1.dll
using System; using System.IO; using System.Runtime.InteropServices; using System.Threading; using RGiesecke.DllExport;
public class InjectedCode { public static void DisplayMessageBox() { // Redirect console output to a file for debugging Console.SetOut(new StreamWriter("log.txt"));
Console.WriteLine("DisplayMessageBox called."); Win32.MessageBox(IntPtr.Zero, "DLL Successfully Injected!", "Injection Status", 0); // MB_OK Console.WriteLine("MessageBox displayed."); } // Entry point for the DLL [DllExport(CallingConvention = CallingConvention.Cdecl)] public static void DllMain(int reason) { if (reason == 1) // DLL_PROCESS_ATTACH { Console.WriteLine("DLLMain called with reason: DLL_PROCESS_ATTACH"); // Run DisplayMessageBox in the main thread var displayThread = new Thread(DisplayMessageBox); displayThread.Start(); displayThread.Join(); // Wait for the thread to finish } else { Console.WriteLine($"DLLMain called with reason: {reason}"); } }}
// Define Win32 class for PInvoke internal static class Win32 { [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type); }
It's not appearing any messagebox upon injection why?
- Assistant
- User
// ClassLibrary1.dll
using System; using System.IO; using System.Runtime.InteropServices; using System.Threading; using RGiesecke.DllExport;
public class InjectedCode { public static void DisplayMessageBox() { // Redirect console output to a file for debugging Console.SetOut(new StreamWriter("log.txt"));
Console.WriteLine("DisplayMessageBox called."); Win32.MessageBox(IntPtr.Zero, "DLL Successfully Injected!", "Injection Status", 0); // MB_OK Console.WriteLine("MessageBox displayed."); } // Entry point for the DLL [DllExport(CallingConvention = CallingConvention.Cdecl)] public static void DllMain(int reason) { if (reason == 1) // DLL_PROCESS_ATTACH { Console.WriteLine("DLLMain called with reason: DLL_PROCESS_ATTACH"); // Run DisplayMessageBox in the main thread var displayThread = new Thread(DisplayMessageBox); displayThread.Start(); displayThread.Join(); // Wait for the thread to finish } else { Console.WriteLine($"DLLMain called with reason: {reason}"); } }}
// Define Win32 class for PInvoke internal static class Win32 { [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type); }
- Assistant
- User
So I inject the .dll with process hacker. Checked process explorer and classlibrary1.dll is there but still didnt appear the messagebox indicating that the code is not being executed upon injection?
The game is called Superfighters Deluxe.exe
Here's the code
// ClassLibrary1.dll
using System; using System.IO; using System.Runtime.InteropServices; using RGiesecke.DllExport;
public class InjectedCode { public static void DisplayMessageBox(string message) { // Redirect console output to a file for debugging Console.SetOut(new StreamWriter("log.txt"));
Console.WriteLine(message); Win32.MessageBox(IntPtr.Zero, message, "Injection Status", 0); // MB_OK Console.WriteLine("MessageBox displayed."); } // Entry point for the DLL [DllExport("DllMain", CallingConvention = CallingConvention.StdCall)] public static bool DllMain(IntPtr hinstDLL, uint fdwReason, IntPtr lpvReserved) { switch (fdwReason) { case 1: // DLL_PROCESS_ATTACH DisplayMessageBox("DLL_PROCESS_ATTACH: The DLL has been injected successfully."); // Your code here break; // Handle other cases if necessary } return true; // Indicate successful execution } - Assistant