Thread: using ASM

Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    open|Fire's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    fs:[0]
    Posts
    62
    Reputation
    18
    Thanks
    36
    Code:
    #include <windows.h>
    #include "detours.h"
    #pragma comment(lib, "detours.lib")
    
    // use a naked function so that there is no prolog or epilog and you can right pure asm
    DWORD back = 0x5BF94FD4;
    __declspec (naked) void Hack()
    {
                __asm
                  {
                    inc [esi]
                    pop edi
                    mov eax,esi
                    jmp back
                  }
    } 
    
    void thread()
    {
        DetourFunction((BYTE*)(0x5BF94FCF), (BYTE*)Hack);  //This is to basically detour the function that makes your smg count go down.
    }
    
    BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved )
    {
    	if( dwReason == DLL_PROCESS_ATTACH )
    	{
    		CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)thread, NULL, NULL, NULL);
    	}
    	return TRUE;
    }
    try that.

  2. The Following User Says Thank You to open|Fire For This Useful Post:

    Hell_Demon (05-10-2011)

  3. #17
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    Kibbles didn't I already tell you that you had to return? I told u to try it without return because I wanted u to see why we return to the game function. Well, at least we learned something new today, lol.

  4. #18
    kibbles18's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Location
    US
    Posts
    860
    Reputation
    5
    Thanks
    127
    still not working. btw its a dynamic address. the real address of the instruction of mov [esi],edi is
    Code:
    	DWORD server_dll = (DWORD)(GetModuleHandle("server.dll"));
    	DWORD address = server_dll + 0x2AF1F;
    and what does pop edi do? why would i want to use that?
    Last edited by kibbles18; 05-10-2011 at 04:29 PM.

  5. #19
    kibbles18's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Location
    US
    Posts
    860
    Reputation
    5
    Thanks
    127
    heres my updated code, still not working. added some comments to help u understand
    Code:
    #include <windows.h>
    #include "detours.h"
    #pragma comment(lib, "detours.lib")
    
    DWORD address;
    DWORD back;
    
    // use a naked function so that there is no prolog or epilog and you can right pure asm
    
    __declspec (naked) void main()
    {
    	__asm
    	{
    		nop
    		mov eax,edi //im replacing the bytes lost because of the detour
    		pop edi
    		jmp back //return to the address after the detour jump
    	}
    }
    
    void thread()
    {
    	DWORD server_dll = (DWORD)(GetModuleHandle("server.dll"));
    	address = server_dll + 0x2AF1F;
    	back = address + 5; //5 because the detour takes up 5 bytes
        DetourFunction((BYTE*)address, (BYTE*)main);  //This is to basically detour the function that makes your smg count go down.
    }
    
    BOOL WINAPI DllMain( HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved )
    {
    	if( dwReason == DLL_PROCESS_ATTACH )
    	{
    		CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)thread, NULL, NULL, NULL);
    	}
    	return TRUE;
    }

  6. #20
    open|Fire's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    fs:[0]
    Posts
    62
    Reputation
    18
    Thanks
    36
    Quote Originally Posted by kibbles18 View Post
    heres my updated code, still not working. added some comments to help u understand
    Code:
    #include <windows.h>
    #include "detours.h"
    #pragma comment(lib, "detours.lib")
    DWORD back;
    
    // use a naked function so that there is no prolog or epilog and you can right pure asm
    
    __declspec (naked) void main()
    {
    	__asm
    	{
    		mov eax,edi //im replacing the bytes lost because of the detour
    		pop edi      
    		jmp back //return to the address after the detour jump
    	}
    }
    
    
    BOOL WINAPI DllMain( HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved )
    {
    	if( dwReason == DLL_PROCESS_ATTACH )
    	{
    		DWORD server_dll = (DWORD)(GetModuleHandle("server.dll"));
    	        server_dll += 0x2AF1F;
    	        back = server_dll + 5; //5 because the detour takes up 5 bytes
                    DetourFunction((BYTE*)server_dll, (BYTE*)main);  //This is to basically
    	}
    	return TRUE;
    }
    if you want nop these bytes mov [esi],edi just do this.
    Code:
    DWORD server_dll = (DWORD)(GetModuleHandle("server.dll"));
    server_dll += 0x2AF1F;
    memcpy((void*)server_dll, "\x90\x90");

  7. #21
    kibbles18's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Location
    US
    Posts
    860
    Reputation
    5
    Thanks
    127
    @Void
    @Hell_Demon

    well i got it working!
    here are the steps i took if anyone needs this:
    i found the address of the instruction i wanted to edit
    i detoured it with detours
    i found that the jump takes up 5 bytes of memory, and since the address i put the jump (detour) in was only 2 bytes, i placed the other 3 bytes that were absorbed by the jump(detour) in my detoured function.
    i then knew that i would need to go return to the place in memory i left off at after the jump(detour), and i knew the jump was 5 bytes, so i added 5 to the address that i found the instruction i wanted to detour at and added the jmp to that after i was done with the detour.
    have fun and learn from my mistakes!
    Last edited by kibbles18; 05-11-2011 at 04:14 PM.

  8. The Following User Says Thank You to kibbles18 For This Useful Post:

    Lyoto Machida (05-14-2011)

Page 2 of 2 FirstFirst 12