Results 1 to 7 of 7
  1. #1
    Fleepster99's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    163
    My Mood
    Cool

    Ways of Preventing Injected DLL Crashes

    Hey guys so im currently writing a DLL to inject into AssaultCube and im getting a few crashes, i chose that due to its simplicity and because it is my first dll hack.

    So i use the common code to write to the programs memory, this works in most cases but i have to shoot the gun at least once before injecting the DLL otherwise it will crash, if i minimize it will often crash and also when next map is loading.

    Code:
    			 
                 VirtualProtect((LPVOID)(AddressToWrite), 3, PAGE_EXECUTE_READWRITE, &dwOldProtection);
                            
                 memcpy( (LPVOID)AddressToWrite, &AmmoValue, 3);
    
                 VirtualProtect((LPVOID)(AddressToWrite), 3, dwOldProtection, NULL);
    What im asking is if there is any way i can get around this maybe by doing some sort of check to ensure the address is available and if so dont write to memory.
    Ive also noticed crashes happening when injecting other peoples hacks in processes e.g. mw2 therefore i was wondering if there were any useful ways of preventing this, ive searched quite thoroughly in the forum with no luck :/.

    Thanks for reading

    EDIT:
    Found a fix for this, for anyone with the same problem you can fix this by having a simple if statement where your address is found.
    E.g.
    Code:
    DWORD Ptr = *(DWORD*)(0x00123A1F3); //Base Address
    if(Ptr == 0) return NULL; //<-- fix here
    
    Ptr = *(DWORD*)(Ptr+0xFA);  //Add 1st offset to pointer
    if(Ptr == 0) return NULL;//<-- fix here
    Last edited by Fleepster99; 12-30-2011 at 06:25 AM. Reason: Found a fix

  2. #2
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,679
    My Mood
    Mellow
    Windows has some available pointer functions you can use:

    IsBadWritePtr IsBadWritePtr function
    IsBadReadPtr IsBadReadPtr function

    which you can condense with your own macro:
    Code:
    #define IsBadPtr(ptr,sz) (IsBadReadPtr((LPVOID)(ptr),(sz)) || IsBadWritePtr((LPVOID)(ptr),(sz)))

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  3. #3
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    As Jason said, you should always do a pointer check before writing anything to an address. If you don't want to use api's you can do it manually like this:

    Code:
    if(*(DWORD*)(youraddie) != 0) // assuming it's one level down.
    {
    }

  4. The Following User Says Thank You to 258456 For This Useful Post:

    Fleepster99 (12-31-2011)

  5. #4
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,679
    My Mood
    Mellow
    Quote Originally Posted by 258456 View Post
    As Jason said, you should always do a pointer check before writing anything to an address. If you don't want to use api's you can do it manually like this:

    Code:
    if(*(DWORD*)(youraddie) != 0) // assuming it's one level down.
    {
    }
    Dereferencing the address still performs a read operation, which can lead to an exception if the memory isn't available for reading, also that just checks if the 4 bytes starting at "youraddie" are 0, which isn't really the most robust check, as quite often a pointer can be completely valid and point to a value of 0. In truth you should really just have a conditional wait period at the start of your code while you wait for the modules to load.

    Code:
    while (GetModuleHandleA("requiredmodule") == NULL)
        Sleep(50);
    Last edited by Jason; 12-30-2011 at 11:30 PM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  6. The Following User Says Thank You to Jason For This Useful Post:

    Fleepster99 (12-31-2011)

  7. #5
    Fleepster99's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    163
    My Mood
    Cool
    Ah i see il be trying both those methods, thanks to both.

  8. #6
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    Quote Originally Posted by Jason View Post


    Dereferencing the address still performs a read operation, which can lead to an exception if the memory isn't available for reading, also that just checks if the 4 bytes starting at "youraddie" are 0, which isn't really the most robust check, as quite often a pointer can be completely valid and point to a value of 0. In truth you should really just have a conditional wait period at the start of your code while you wait for the modules to load.

    Code:
    while (GetModuleHandleA("requiredmodule") == NULL)
        Sleep(50);
    Well i inject it after login so all the modules are already loaded. Plus you save the return address of GetModuleHandle to get the base address of that module.

    ---------- Post added at 07:19 PM ---------- Previous post was at 07:14 PM ----------

    Quote Originally Posted by Jason View Post


    Dereferencing the address still performs a read operation, which can lead to an exception if the memory isn't available for reading, also that just checks if the 4 bytes starting at "youraddie" are 0, which isn't really the most robust check, as quite often a pointer can be completely valid and point to a value of 0. In truth you should really just have a conditional wait period at the start of your code while you wait for the modules to load.

    Code:
    while (GetModuleHandleA("requiredmodule") == NULL)
        Sleep(50);
    Even if you do that module check it will fail in some games, because like in crossfire, the playerclass pointer isn't always valid, it's only valid in the game. So if i was just doing a module check and then if the module is valid and I write info to the memory location the game will crash because it isn't valid. But nevertheless you are totally correct, but I guess it all comes down to your situation and what you need to do.

  9. #7
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,679
    My Mood
    Mellow
    Quote Originally Posted by 258456 View Post
    Even if you do that module check it will fail in some games, because like in crossfire, the playerclass pointer isn't always valid, it's only valid in the game. So if i was just doing a module check and then if the module is valid and I write info to the memory location the game will crash because it isn't valid. But nevertheless you are totally correct, but I guess it all comes down to your situation and what you need to do.
    Yeah, I still agree you need to check for the validity of a pointer, just saying that dereferencing it as a DWORD and comparing it to 0 probably isn't the best solution. In games like CF you should really be reversing the location of the gamestate variable anyway. Anyways, this is probs getting into a bit much detail. In the end, wait for the modules to load, use the IsBadRead/WritePtr functions to check the validity of pointers and you should be fine

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

Similar Threads

  1. hacks injected/.dll's put in place and game crashes!!!
    By silencekvala in forum Combat Arms Help
    Replies: 10
    Last Post: 08-11-2010, 01:38 AM
  2. 5 byte code jump crashing when in a injected dll
    By Anddos in forum General Hacking
    Replies: 1
    Last Post: 08-01-2010, 09:16 AM
  3. Inject dll.
    By heroes213 in forum WolfTeam General
    Replies: 6
    Last Post: 04-22-2008, 06:52 AM
  4. Another way to prevent leechers...
    By NetNavi in forum WarRock - International Hacks
    Replies: 30
    Last Post: 09-02-2007, 10:20 PM
  5. TUTORIAL - How to prevent Warrock from crashing!
    By Darky in forum WarRock - International Hacks
    Replies: 25
    Last Post: 07-06-2007, 09:31 PM

Tags for this Thread