Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 05:33

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Microsoft Detours 2.1

Discussion on Microsoft Detours 2.1 within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old 03/31/2011, 11:21   #16
 
elite*gold: 20
Join Date: Aug 2007
Posts: 1,749
Received Thanks: 2,198
There's a way to remove the detoured.dll from getting injected into the process. Erm, let me Google it for you, there's a certain include and a function or something you need to remove from the source.

Link:


Quote:
Originally Posted by tanelipe View Post
You could do the injection manually so you wouldn't have to worry about the detoured.dll, however you might want to look into the code that detours use for DetourCreateProcessWithDll so you can have it do exactly same thing but without the use of detoured.dll

Here's a sample code on how to do it manually, oh and by the way, it doesn't work with Windows XP for some reason.

PHP Code:
#include "StdAfx.h"
#include "ConquerInjector.h"


ConquerInjector::ConquerInjector(char *Directory)
{
    
int Size strlen(Directory) + 1;
    
ConquerDirectory = new char[Size];
    
MoveMemory(ConquerDirectoryDirectorySize);

    
Startup = new STARTUPINFOA();
    
Process = new PROCESS_INFORMATION();
}


ConquerInjector::~ConquerInjector(void)
{
    
delete[] ConquerDirectory;
    
delete Startup;
    
delete Process;
}

BOOL ConquerInjector::EnablePrivileges()
{
    
HANDLE hToken;
    if(
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES TOKEN_QUERY, &hToken))
    {
        
TOKEN_PRIVILEGES priv;
        
priv.PrivilegeCount 1;
        
priv.Privileges[0].Attributes SE_PRIVILEGE_ENABLED;

        if(
LookupPrivilegeValue(NULLSE_DEBUG_NAME, &priv.Privileges[0].Luid))
        {
            if(
AdjustTokenPrivileges(hTokenFALSE, &privNULLNULLNULL))
            {
                
CloseHandle(hToken);
                return 
TRUE;
            }
        }

        
CloseHandle(hToken);
    }
    return 
FALSE;
}

BOOL ConquerInjector::Start(char *Application)
{
    
char CommandLine[256];
    
sprintf_s(CommandLine"%s%s blacknull"ConquerDirectoryApplication);
    return 
CreateProcessA(NULLCommandLineNULLNULLFALSENORMAL_PRIORITY_CLASS CREATE_SUSPENDEDNULLConquerDirectoryStartupProcess);
}
BOOL ConquerInjector::Attach(char *Applicationchar *Dll)
{
    if(
Start(Application))
    {
        
EnablePrivileges();
        
HANDLE hProcess OpenProcess(PROCESS_ALL_ACCESSFALSEProcess->dwProcessId);
        if(
hProcess != NULL)
        {
            
char Library[MAX_PATH];
            
ZeroMemory(Library256);
            
GetCurrentDirectoryA(MAX_PATHLibrary);

            
sprintf(Library"%s\\%s"LibraryDll);

            
int Length strlen(Library) + 1;

            
LPVOID RemoteMemory VirtualAllocEx(hProcessNULLLengthMEM_COMMITPAGE_READWRITE);
            if(
RemoteMemory != NULL)
            {
                if(
WriteProcessMemory(hProcessRemoteMemoryLibraryLengthNULL))
                {
                    
FARPROC hLoadLibrary GetProcAddress(GetModuleHandleA("Kernel32"), "LoadLibraryA");

                    
HANDLE hThread CreateRemoteThread(hProcessNULLNULL, (LPTHREAD_START_ROUTINE)hLoadLibraryRemoteMemoryNULLNULL);
                    if(
hThread != NULL)
                    {
                        
WaitForSingleObject(hThread5000);
                        
VirtualFreeEx(hProcessRemoteMemory0MEM_RELEASE);
                        
CloseHandle(hProcess);
                        
ResumeThread(Process->hThread);
                        return 
TRUE;
                    }
                }
                
VirtualFreeEx(hProcessRemoteMemory0MEM_RELEASE);
            }
            
CloseHandle(hProcess);
        }
        
ResumeThread(Process->hThread);
        return 
FALSE;
    }
    else
    {
        
printf("CreateProcessA failed with the following error: %d\n"GetLastError());
        return 
FALSE;
    }
    return 
FALSE;

If you change the code
PHP Code:
                    HANDLE hThread CreateRemoteThread(hProcessNULLNULL, (LPTHREAD_START_ROUTINE)hLoadLibraryRemoteMemoryNULLNULL);
                    if(
hThread != NULL)
                    {
                        
WaitForSingleObject(hThread5000);
                        
VirtualFreeEx(hProcessRemoteMemory0MEM_RELEASE);
                        
CloseHandle(hProcess);
                        
ResumeThread(Process->hThread);
                        return 
TRUE;
                    } 
Into this (resume main thread before executing the LoadLibrary thread):
PHP Code:
                    ResumeThread(Process->hThread);
                    
HANDLE hThread CreateRemoteThread(hProcessNULLNULL, (LPTHREAD_START_ROUTINE)hLoadLibraryRemoteMemoryNULLNULL);
                    if(
hThread != NULL)
                    {
                        
WaitForSingleObject(hThread5000);
                        
VirtualFreeEx(hProcessRemoteMemory0MEM_RELEASE);
                        
CloseHandle(hProcess);
                        return 
TRUE;
                    } 
It works on XP. Not that I recommend it though, it would probably be better to hook the import table and manually force the process to load your DLL
IAmHawtness is offline  
Old 03/31/2011, 12:20   #17
 
elite*gold: 0
Join Date: Jun 2006
Posts: 85
Received Thanks: 8
Yes, I have gotten the issue solved. That's what I meant by do something about it, lol.
fm_sparkart is offline  
Old 03/31/2011, 15:14   #18
 
elite*gold: 20
Join Date: Aug 2007
Posts: 1,749
Received Thanks: 2,198
Quote:
Originally Posted by fm_sparkart View Post
Yes, I have gotten the issue solved. That's what I meant by do something about it, lol.
Right, I thought you just created your own "CreateProcessWithDLL" function, like the example tanelipe posted, my bad .
IAmHawtness is offline  
Old 04/10/2011, 12:09   #19
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,223
Received Thanks: 867
After I finally got it working & help from Sparkie.

I'm trying to do:
Code:
int WINAPI DetouredConnect(SOCKET s, const sockaddr *name, int len)
{
   sockaddr_in my_addr;
    my_addr.sin_addr.S_un.S_addr = inet_addr("5.94.169.205");
    my_addr.sin_port = htons(5816);
    my_addr.sin_family = AF_INET;
    return OriginalConnect(s, (sockaddr*)&my_addr, sizeof(my_addr));
    //return OriginalConnect(s, name, len);
}
But upon login the client dc's.

#edit
Tried
Code:
struct sockaddr_in dds;
char *some_addr;
dds.sin_addr.s_addr = inet_addr("5.94.169.205");
dds.sin_port = htons(5816);
dds.sin_family = AF_INET;
return OriginalConnect(s, (sockaddr*)&dds, sizeof(dds));
Which is almost the same but it still didn't work. Not a server-side issue not working on other servers either.
_DreadNought_ is offline  
Old 04/10/2011, 12:36   #20
 
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,000
This is how I'm doing my connect-function. It's a bit long because I was saving the IP/Port the client is connecting to.

Biggest difference seems to be with this
PHP Code:
sockaddr_in my_addr
VS.
PHP Code:
sockaddr_in *addr = (sockaddr_in*)name
PHP Code:
int WINAPI DetouredConnect(SOCKET s, const sockaddr *nameint namelen)
{
    
sockaddr_in *addr = (sockaddr_in*)name;

    
u_short Port ntohs(addr->sin_port);
    
char szPort[32];

    
sprintf_s(szPort"%d"Port);

    
char CurrentDirectory[MAX_PATH];
    
GetModuleFileNameA(GetModuleHandleA("ConquerLibrary.dll"),CurrentDirectory,MAX_PATH);
    
int slen strlen(CurrentDirectory);
    for (
int i =slen -1;>= 0;i--)
    {
        if (
CurrentDirectory[i] == '\\')
        {
            
CurrentDirectory[i+1] = NULL;
            break;
        }
    }
    
MessageBoxA(NULLszPort""MB_OK);
    if(
Port == 80)
    {
        
strcat_s(CurrentDirectory"StatusChecker.ini");
    }
    else if(
Port == 5816 || Port == 5817)
    {
        
strcat_s(CurrentDirectory"GameServer.ini");
        
Port 5816;
    }
    else
    {
        
strcat_s(CurrentDirectory"AuthServer.ini");
        
Port 9958;
    }
    
WritePrivateProfileStringA("Settings""IP"inet_ntoa(addr->sin_addr), CurrentDirectory);
    
WritePrivateProfileStringA("Settings""Port"szPortCurrentDirectory);

    
addr->sin_addr.s_addr inet_addr("127.0.0.1");
    
addr->sin_port htons(Port);
    return 
OriginalConnect(s, (const sockaddr*)addrnamelen);

tanelipe is offline  
Thanks
1 User
Old 04/10/2011, 12:53   #21
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,223
Received Thanks: 867
#edit
Got it. Thanks.

*sighs in relief*
_DreadNought_ is offline  
Old 02/27/2012, 09:35   #22
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
I know this is kinda an old bump, but better than making a new thread and since it's related to the thread, could anyone possibly upload Detours 2.1? As I can't seems to get Detours 3 working.

Thank you.
I don't have a username is offline  
Old 02/27/2012, 14:43   #23
 
m7mdxlife's Avatar
 
elite*gold: 0
Join Date: Feb 2009
Posts: 920
Received Thanks: 3,514
Quote:
Originally Posted by I don't have a username View Post
I know this is kinda an old bump, but better than making a new thread and since it's related to the thread, could anyone possibly upload Detours 2.1? As I can't seems to get Detours 3 working.

Thank you.
This one >> ?
m7mdxlife is offline  
Thanks
3 Users
Old 02/27/2012, 17:39   #24
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by m7mdxlife View Post
This one >> ?
Thanks a lot it was perfect.
I don't have a username is offline  
Old 02/27/2012, 17:46   #25
 
tkblackbelt's Avatar
 
elite*gold: 0
Join Date: Sep 2010
Posts: 266
Received Thanks: 85
Quote:
Originally Posted by m7mdxlife View Post
This one >> ?
Thanks . This seems like a fun api to play around with.
tkblackbelt is offline  
Old 02/28/2012, 07:37   #26
 
elite*gold: 0
Join Date: Feb 2012
Posts: 1
Received Thanks: 0
Nice, but couldn't you just configure %systemroot%Drivers\etc\Hosts.txt? I assume that conquer uses somesort of DNS to lookup the server address.
SpaceUrkel is offline  
Old 02/28/2012, 07:43   #27
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by SpaceUrkel View Post
Nice, but couldn't you just configure %systemroot%Drivers\etc\Hosts.txt? I assume that conquer uses somesort of DNS to lookup the server address.
Do you even know what this is for?

I don't have a username is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
[Tutorial] Microsoft Detours
07/24/2013 - Coding Tutorials - 74 Replies
Eine kleine .dll wird geschrieben, die mithilfe der Microsoft Detours Library die MessageBoxA Funktion detourt, und den Text ersetzt, sobald sie in einen Prozess injeziert wird. Ich hoffe ich konnte es einigermaßen verständlich erklären (mein Gedankenfluss ist manchmal etwas wirr). Es ist auf Deutsch. Detours Video Tutorial
[Video Tutorial] Microsoft Detours 1.5 New Video
05/09/2012 - Coding Tutorials - 66 Replies
Da schlurmann sein Video ja gelöscht hat und einige User wollten, dass ich ein neues mache, habe ich mich kurzer Hand entschieden, ein eigenes Tutorial zu MS Detours 1.5 hochzuladen. Es ist mein erstes (Video-)Tutorial, also bitte ich um Kritik und Verbesserungsvorschläge, aber bitte bleibt dabei sachlich! Wenn ihr fragen habt, weil etwas zu schnell ging oder ich etwas zu undeutlich erklärt habe, fragt ruhig ;) (detours.h und detours.lib sind im Anhang)



All times are GMT +2. The time now is 05:33.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.