Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 当与MS Detours挂钩并注入Withdll.exe时,应用程序崩溃_C++_Windows_Detours_Api Hook - Fatal编程技术网

C++ 当与MS Detours挂钩并注入Withdll.exe时,应用程序崩溃

C++ 当与MS Detours挂钩并注入Withdll.exe时,应用程序崩溃,c++,windows,detours,api-hook,C++,Windows,Detours,Api Hook,我正在使用MS Detours钩住FindNextFile()。我已经成功地配置了Detours库,并编写了一个名为“Detuors.dll”的dll和一个名为“FNFSend.exe”的应用程序。代码如下: 动态链接库: 请帮助解决此问题。%s对于打印数字无效。改用%d 通过指定%s您告诉fprintf以字符串形式读取地址计数器处的内存。尝试调用fprintf的第一个值是1,这就是为什么在地址0x00000001%s处存在访问冲突的原因,该值对于打印数字无效。改用%d 通过指定%s您告诉fpr

我正在使用MS Detours钩住
FindNextFile()
。我已经成功地配置了Detours库,并编写了一个名为“Detuors.dll”的dll和一个名为“FNFSend.exe”的应用程序。代码如下:

动态链接库:


请帮助解决此问题。

%s
对于打印数字无效。改用
%d


通过指定
%s
您告诉
fprintf
以字符串形式读取地址
计数器处的内存。尝试调用
fprintf
的第一个值是1,这就是为什么在地址
0x00000001
%s
处存在访问冲突的原因,该值对于打印数字无效。改用
%d

通过指定
%s
您告诉
fprintf
以字符串形式读取地址
计数器处的内存。尝试调用
fprintf
的第一个值是1,这就是为什么在地址
0x00000001
处存在访问冲突

#include <cstdio>
#include <stdio.h>
#include <windows.h>
#include "detours.h"
#pragma comment (lib,"detours.lib")

//Prototypes
extern "C" __declspec(dllexport) BOOL (WINAPI *pFNF)(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData) = FindNextFile;
extern "C" __declspec(dllexport) BOOL WINAPI MyFNF(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData);

//Log File
FILE* pFNFLogFile;
int counter = 0;

INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
    switch(Reason)
    {
        case DLL_PROCESS_ATTACH:
            DisableThreadLibraryCalls(hDLL);
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourAttach(&(PVOID&)pFNF, MyFNF);
            if(DetourTransactionCommit() == NO_ERROR)
                OutputDebugString("FNF() detoured successfully");
            else
                OutputDebugString("FNF() not detoured");
            break;
        case DLL_PROCESS_DETACH:
            DetourTransactionBegin();   //Detach
            DetourUpdateThread(GetCurrentThread());
            DetourDetach(&(PVOID&)pFNF, MyFNF);
            DetourTransactionCommit();
            break;
        case DLL_THREAD_ATTACH:
            DisableThreadLibraryCalls(hDLL);
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourAttach(&(PVOID&)pFNF, MyFNF);
            if(DetourTransactionCommit() == NO_ERROR)
                OutputDebugString("FNF() detoured successfully");
            else
                OutputDebugString("FNF() not detoured");
            break;
        case DLL_THREAD_DETACH:
            break;
    }
    return TRUE;
}

//Open file, write contents, close it
extern "C" __declspec(dllexport) int WINAPI MyFNF(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData)
{
    counter ++;
    fopen_s(&pFNFLogFile, "C:\\FNFLog.txt", "a+");
    fprintf(pFNFLogFile, "%s\n", counter);
    fclose(pFNFLogFile);
    return pFNF(hFindFile, lpFindFileData);
}
Unhandled exception at 0x6265984f (msvcr90d.dll) in FNFSend.exe: 0xC0000005:
Access violation reading location 0x00000001.