1

私はマイクロソフトの迂回路でいくつかの基本的なフッキングを行おうとしていますが、それを機能させることができません。私は基本的にこのスレッドに投稿されたコードを使用しました:

C / C ++でWindows関数をフックするにはどうすればよいですか?

しかし、サイコロはありません。DLLコードの送受信機能を更新して、データをファイルに記録するだけで、メインプログラムを「インターネットチェッカー」プログラムに接続しようとしましたが、ログファイルが作成されないため、dllが表示されます。注入されませんでした。

私はWindows764ビット、Visual Studio 10.0、Detours 3.0を実行しています(私の環境は正しくセットアップされているようで、ビルドなどの問題はありません)。上記のリンクからDLLコードに貼り付けたDLLプロジェクトを作成し、send/recvを次のように更新しました。

FILE * pSendLogFile;
fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
fprintf(pSendLogFile, "%s\n", buf);
fclose(pSendLogFile);

コンパイルされます。次に、別のプロジェクトを作成し、上記のリンクからメインコードに貼り付け、chkrzm.exeプログラム(チェッカー)を検索するように設定し、DLLパスを次のようにハードコーディングしました。

fullPath = "C:\\Users\\PM\\Documents\\Programs\\C Code\\Test\\DLLTester2\\Debug\\DLLTester2.dll";

そしてそれを実行しましたが、サイコロはありません。これを機能させることができない理由はありますか?

4

2 に答える 2

2

参考までに、これは解決しました。どのプロセスが32ビットであるかを確認するには、ctrl-alt-deleteを実行してタスクマネージャーに移動します。32ビットプロセスは、その横に*32が付いてリストされています。また、私のフックが機能しました。これがコードです。CreateRemoteThreadアプローチを放棄し、システム全体のフックを使用しました。私は以下からコードをつなぎ合わせました:

SetWindowsHookExとWH_KEYBOARDを使用して外部プロセスをフックする 方法http://www.codingthewheel.com/archives/how-i-built-a-working-online-poker-bot-4http://www.codingthewheel.com/archives/ how-i-built-a-working-online-poker-bot-7

このプログラムは、32ビットプロセスでテキストを単純に反転します(上記の最後のリンクに示されているように)。例えば。テキストパッドを開き、メニューにカーソルを合わせます。それらのテキストは逆になります。

dll:

#include <windows.h>
#include <detours.h>
#include <stdio.h>
#include <iostream>
using namespace std;


// Initial stuff
#ifdef _MANAGED
#pragma managed(push, off)
#endif

#pragma comment( lib, "Ws2_32.lib" )
#pragma comment( lib, "detours.lib" )

#pragma data_seg("Shared")
HHOOK   g_hHook  = NULL;
#pragma data_seg()


// Globals
HINSTANCE  g_hInstance = NULL;


// ExtTextOut - original
BOOL (WINAPI * Real_ExtTextOut)(HDC hdc, int X, int Y, UINT options, const RECT* lprc, LPCTSTR text, UINT cbCount, const INT* lpSpacingValues) = ExtTextOut;

// ExtTextOut - overridden
BOOL WINAPI Mine_ExtTextOut(HDC hdc, int X, int Y, UINT options, const RECT* lprc, LPCTSTR text, UINT cbCount, const INT* lpSpacingValues)
{
    if (!text)
        return TRUE;

    // Make a copy of the supplied string..safely
    LPWSTR szTemp = (LPWSTR)LocalAlloc(0, (cbCount+1) * 2);
    memcpy(szTemp, text, cbCount*2); // can't use strcpy here
    szTemp[cbCount] = L'\0'; // append terminating null

    // Reverse it..
    wcsrev(szTemp);

    // Pass it on to windows...
    BOOL rv = Real_ExtTextOut(hdc, X, Y, options, lprc, szTemp, cbCount, lpSpacingValues);

    // Cleanup
    LocalFree(szTemp);

    return TRUE;
}


// DLLMain
BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved  )
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
            g_hInstance  = (HINSTANCE) hModule;

            DetourTransactionBegin(); 
            DetourUpdateThread(GetCurrentThread());
            DetourAttach(&(PVOID&)Real_ExtTextOut, Mine_ExtTextOut); // <- magic
            DetourTransactionCommit();
            break;

        case DLL_PROCESS_DETACH:
            DetourTransactionBegin(); 
            DetourUpdateThread(GetCurrentThread());
            DetourDetach(&(PVOID&)Real_ExtTextOut, Mine_ExtTextOut);
            DetourTransactionCommit();
            break;
    }

    return TRUE;
}


// CBT Hook - dll is hooked into all processes (only 32 bit processes on my machine)
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode < 0)
        return CallNextHookEx(g_hHook, nCode, wParam, lParam);

    // Return 0 to allow window creation/destruction/activation to proceed as normal.
    return 0;
}


// Install hook
extern "C" __declspec(dllexport) bool install()
{
    g_hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC) CBTProc, g_hInstance, 0);

    return g_hHook != NULL;
}


// Uninstall hook
extern "C" __declspec(dllexport) void uninstall()
{
    if (g_hHook)
    {
        UnhookWindowsHookEx(g_hHook);
        g_hHook = NULL;
    }
}

メインプログラム:

#include <Windows.h>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
using namespace std;


// Main
int _tmain(int argc, _TCHAR* argv[])
{
    // Load dll
    HINSTANCE hinst = LoadLibrary(_T("C:\\Users\\PM\\Documents\\Programs\\C Code\\Test\\DLLTesterFinal\\Debug\\DLLTesterFinal.dll")); 

    if (hinst)
    {
        // Get functions
        typedef bool (*Install)();
        typedef void (*Uninstall)();
        Install install = (Install) GetProcAddress(hinst, "install");
        Uninstall uninstall = (Uninstall) GetProcAddress(hinst, "uninstall");
        cout << "GetLastError1: " << GetLastError () << endl << endl;

        // Install hook
        bool hookInstalledSuccessfully = install ();
        cout << "GetLastError2: " << GetLastError () << endl;
        cout << "Hook installed successfully? " << hookInstalledSuccessfully << endl << endl;

        // At this point, go to a 32-bit process (eg. textpad, chrome) and hover over menus; their text should get reversed
        cout << "Text should now be reversed in 32-bit processes" << endl;
        system ("Pause");

        // Uninstall hook
        uninstall();
        cout << endl << "GetLastError3: " << GetLastError () << endl;
        cout << "Done" << endl;
        system ("Pause");
    }

    return 0;
}

ただし、JavaアプリケーションでExtTextOutを迂回しようとすると、Javaアプリがクラッシュします。それを調査する必要があります。

于 2011-12-26T08:47:26.320 に答える
1

Windows 7 64ビット、VisualStudio10.0を実行しています

WIN7の管理者ユーザーとしてMSDETOURINJECTを実行する必要があります。動作する迂回コードを検証するには、迂回3.0のサンプルを使用してmaketargettestを使用します。

cmd>$Path/Detours Express 3.0>nmake test

于 2012-05-30T18:00:22.963 に答える