C++ Detours "DetourFunction" issue.

Posts 1–9 of 9 · Page 1 of 1
C++ Detours "DetourFunction" issue.
Using the "detours library" I have a message box when someone logs into a server and selects a character:

Code:
//the function
void NewUser(void)
{
	MessageBox(0, "User Logged On.", "Function Called", MB_OK);
}

NewUserHook = (int (__stdcall*)(void))DetourFunction((PBYTE)0x004BA74D, (PBYTE)NewUser); //the hook line im calling on DLL_PROCESS_ATTACH
NOTE: this is just small snippets

Now on to the problem I get the messagebox when a user logs on but after I close the box and they load the map they are unable to move or do anything so I guess I need a way to return properly and allow the server to continue running normally(if someone else connects it acts fine until of course they load the map and cannot load not sure if that is from threading probably is)
Quote Originally Posted by MerkurAlex View Post
Using the "detours library" I have a message box when someone logs into a server and selects a character:

Code:
//the function
void NewUser(void)
{
	MessageBox(0, "User Logged On.", "Function Called", MB_OK);
}

NewUserHook = (int (__stdcall*)(void))DetourFunction((PBYTE)0x004BA74D, (PBYTE)NewUser); //the hook line im calling on DLL_PROCESS_ATTACH
NOTE: this is just small snippets

Now on to the problem I get the messagebox when a user logs on but after I close the box and they load the map they are unable to move or do anything so I guess I need a way to return properly and allow the server to continue running normally(if someone else connects it acts fine until of course they load the map and cannot load not sure if that is from threading probably is)
I personally can't help you, but I THINK this is problem that DavidM44 was running into, he was trying to hook a function, jmp the function, then execute the rest of the code normally(Which would require calling the function that was jumped. Correct me if i'm wrong) So someone here may be able to help you. Depending on whether or not he figured out the answer.
NewUser is of a different type then NewUserHook
And you'll want to return the original function
Code:
int __stdcall NewUser(void)
{
    MessageBox(0, "User Logged On.", "Function Called", MB_OK);
    return NewUserHook();
}
Quote Originally Posted by Hell_Demon View Post
NewUser is of a different type then NewUserHook
And you'll want to return the original function
Code:
int __stdcall NewUser(void)
{
    MessageBox(0, "User Logged On.", "Function Called", MB_OK);
    return NewUserHook();
}
Hmm I tried this and now the server just gets stuck right after my message box(I have to end the process) as if its in an endless loop.
this looks like a complicated problem and i think you have to ask dave or some one to get this working
Try running it in VS debugger, and find the point where it freezes. Seems like its local.
Quote Originally Posted by why06 View Post
Try running it in VS debugger, and find the point where it freezes. Seems like its local.
Are you suggesting I run my dll(that I normally inject into the game) in VS debugger?

Im probably missing something please explain.
Quote Originally Posted by MerkurAlex View Post
Are you suggesting I run my dll(that I normally inject into the game) in VS debugger?

Im probably missing something please explain.
I was under the impression that this was a game you were making. In that case, idk, it really depends exactly what the code does. Something about what ur .dll does is causing adverse effects in the game. Just make sure you don't have any loose ends. =/

It could be a combination of your .dll and the game causing the loop.
With my current code (see below) the hook(detour) works the first time(just like before) and then the process seems to continue but if I try to close the process it stops responding.

I ran the program with IDA pro injected the dll and then went through the steps to make that hook run when it did IDA said it caused an unknown exception.

Current code(basically the same thing but for a different address point):
Code:
#include <windows.h>
#include "detours.h"
#include <iostream>
#include <fstream>
using namespace std;

int (__stdcall* DemoBugFixPoint)(void);
int __stdcall DemoBugFixPoint(void)
{
	ofstream myfile;
	  myfile.open ("legends.log");
	  myfile << "SetRights(demo bug fix) applied to new logon.\n";
	  myfile.close();

	  return DemoBugFixPointHook();
}

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
	case DLL_PROCESS_ATTACH:
		DemoBugFixPointHook = (int (__stdcall*)(void))DetourFunction((PBYTE)0x004B8ABF, (PBYTE)DemoBugFixPoint);
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		DetourRemove((PBYTE)0x004B8ABF, (PBYTE)DemoBugFixPointHook); //Remove hook
		break;
}
return TRUE;
}
btw the assembly of "0x004B8ABF" is just NOP im not sure if that is an issue if it is can someone explain an easier way to run my function when the program reaches that address point?
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?