X
X
xuvohocan2014-09-21 21:45:28
C++ / C#
xuvohocan, 2014-09-21 21:45:28

Why doesn't it inject a certain function?

#include "stdafx.h"
#include <Windows.h>
#include "MinHook.h"
#include "Xul\nspr.h"
#include <fstream>

#if defined _M_X64
#pragma comment(lib, "libMinHook.x64.lib")
#elif defined _M_IX86
#pragma comment(lib, "libMinHook.x86.lib")
#endif

typedef int (WINAPI *PR_WRITE)(PRFileDesc *fd, void * buf, PRInt32 amount);

PR_WRITE fpPR_WRITE = NULL;

int WINAPI fPR_WRITE(PRFileDesc *fd, void * buf, PRInt32 amount)
{
  std::ofstream output("D:\\Data.txt", std::ios::out || std::ios::app);
  output << buf << "\n";
  return fpPR_WRITE(fd, buf, amount);
}

BOOL APIENTRY DllMain(HMODULE hModule,
  DWORD  ul_reason_for_call,
  LPVOID lpReserved
  )
{
  MessageBox(NULL, L"All Right", L"All Right", MB_OK);
  switch (ul_reason_for_call)
  {
  case DLL_PROCESS_ATTACH:
  {
    if (MH_Initialize() != MH_OK)
    {
      return 1;
    }
    if (MH_CreateHook(&PR_Write, &fPR_WRITE,
      reinterpret_cast<void**>(&fpPR_WRITE)) != MH_OK)
    {
      return 1;
    }
    if (MH_EnableHook(&PR_Write) != MH_OK)
    {
      return 1;
    }
    break;
  }
  case DLL_THREAD_ATTACH:
    break;
  case DLL_THREAD_DETACH:
    break;
  case DLL_PROCESS_DETACH:
  {
    if (MH_DisableHook(&PR_Write) != MH_OK)
    {
      return 1;
    }
    if (MH_Uninitialize() != MH_OK)
    {
      return 1;
    }
    break;
  }
  }
  return TRUE;
}

If instead of PR_Write, for example, MessageBox, then everything is injected, and if not, then it is not even included in DllMain.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
darkvimer, 2015-08-01
@darkvimer

darkvimer.blogspot.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question