使用注入的dll调用Csharp Application的函数

时间:2017-11-16 16:25:08

标签: c# c++ function dll

我想调用ConsoleAppTwo.Program :: PrintMessage应用程序... 我创建了一个csharp测试软件,其功能是给我打电话:

using System;

namespace ConsoleAppTwo
{
    class Program
    {
        static void PrintMessage(string str)
        {
            Console.WriteLine(str);
        }

        static void Main(string[] args)
        {
            while (true)
            {
                if(Console.ReadKey().Key == ConsoleKey.NumPad0)
                {
                    PrintMessage("[Whatever string]");
                }
            }
        }
    }
}

我使用IDA pro找到了这些功能:
IDA PRO

在我使用作弊引擎并添加'地址'“ConsoleAppTwo.Program :: PrintMessage”并获取地址指针后我创建了dll:

#include <string>
#include <Windows.h>
#include "main.h">

using namespace std;

typedef void(__cdecl *_FuncA)(string str);

DWORD WINAPI MainThread(LPVOID param) {
    _FuncA func = (_FuncA)(0x3504F0);

    while (!GetAsyncKeyState(VK_HOME))
    {
        if (GetAsyncKeyState(VK_INSERT) & 1)
        {
            func("What is your name");
        }

        Sleep(10);
    }

    FreeLibraryAndExitThread((HMODULE) param, 0);
    return 0;
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
        DisableThreadLibraryCalls(hModule);
        CreateThread(0, 0, MainThread, GetModuleHandle(NULL), 0, 0);
    default:
        break;
    }

    return true;
}

在我用软件注入dll并且代码不能工作之后...,我得到输出错误:“EXCEPTION_ACCESS_VIOLATION”

0 个答案:

没有答案