Results 1 to 7 of 7
  1. #1
    Laertesiceking's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    0

    value of GetModuleHandle() always is 0...

    hi everybody!

    I practice using c++ builder & cheat engine to change the money of Plants VS Zombies.

    and I know the address of money. ("popcapgame1.exe"+0002619C, Offest = C)

    First step, i use GetModuleHandle() like this in C++ builder:

    //-------------------------------------------------------------------------------------------

    DWORD baseAddr = (DWORD)GetModuleHandle("popcapgame1.exe");

    //-------------------------------------------------------------------------------------------

    when i use debugger to check the value of the baseAddr, the value is always 0. (i don't know why...)

    i'm sure that process's name is right and process is running.

    and i can't use Findwindow() because the money of data saves in popcapgame1.exe.

    it's not saving in PlantsVSZombies.exe

  2. #2
    Eddington's Avatar
    Join Date
    Apr 2015
    Gender
    male
    Posts
    57
    Reputation
    10
    Thanks
    5
    My Mood
    Fine
    Is your exe path correct?
    edit:
    Wait what the hell GetModuleHandle returns a handle which is totally not an address. It is nonsensical trying to cast it to a DWORD and use it as an address.
    Last edited by Eddington; 07-04-2015 at 07:57 PM.

  3. #3
    殺す必要がある唯一のものは殺されるために準備され人 々である。
    Premium Member
    Hitokiri~'s Avatar
    Join Date
    Oct 2012
    Gender
    female
    Location
    Cancer.
    Posts
    1,201
    Reputation
    24
    Thanks
    937
    My Mood
    Bitchy
    GetModuleHandle only works for exe's if it's in the same process ( Aka only in DLLs injected into a process can it be used to return the base of a process )
    Besides, GMH returns -1 for the local process ( psuedo-handle ) anyways.

    I.E.
    Process Name: calc.exe
    Code: GetModuleHandleA( "calc.exe" ) -> Returns "-1"
    Code: GetModuleHandleA( NULL ) -> Returns "-1"
    Code: GetModuleHandleA( "explorer.exe" ) -> Returns NULL ( No such module in the process calc.exe exists. )

    If you want to read an external process's modules, you'll need to create a snapshot and walk through the module list, locate the desired module and read the base from the PROCESSENTRY32/MODULEENTRY32 structures.

    In your case however, since you're merely dealing with a process named "popcapwhatever.exe" a simple snapshot with
    TH32CS_SNAPPROCESS will work. ( Simply do strcmp with szExeFile stripping out the last "\" delimiter and attach to that process ID. )

    Refs:
    https://msdn.microsof*****m/en-us/librarydows/desktop/ms682489(v=vs.85).aspx
    https://msdn.microsof*****m/en-us/librarydows/desktop/ms684834(v=vs.85).aspx
    https://msdn.microsof*****m/en-us/librarydows/desktop/ms684836(v=vs.85).aspx
    https://msdn.microsof*****m/en-us/librarydows/desktop/ms684218(v=vs.85).aspx
    https://msdn.microsof*****m/en-us/lib...(v=vs.85).aspx

    Try googling next time.

    Code:
    // Find the process and get the PROCESSENTRY32 structure from it
    PROCESSENTRY32 pe; MODULEENTRY32 me;
    
    while( Module32First( moduleSnapshot, &me ){
       if( me.th32ProcessID == pe.th32ProcessID ){ // Module is a child of the parent
          moduleBase = reinterpret_cast< ULONG_PTR >( me.modBaseAddr );
          break;
      }
    
      Module32Next( moduleSnapshot, &me );
    }
    Last edited by Hitokiri~; 07-05-2015 at 01:22 AM.

  4. #4
    Laertesiceking's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    0
    Sorry, i'm newbie in Windows API.

    Actually I found a source code at first.

    refs: =.=" sorry i can't post links yet.

    //------------------------------------------------------------------------------------------------------------------------

    // My first game hack. This is for "Sniper: Ghost Warrior"

    #include "stdafx.h"
    #include <iostream>
    #include <Windows.h>

    using namespace std;

    int main ()
    {
    HWND hWnd = FindWindow(0, L"Sniper: Ghost Warrior"); // Finds the window titled "Sniper: Ghost Warrior".

    if (hWnd == 0) // If it can't find the window, then:
    {
    cout << "Can't find window, dopey noonga!" << endl;
    }
    else
    {
    DWORD pr0c3zz;
    GetWindowThreadProcessId(hWnd, &pr0c3zz); // Locates the process through the window.
    HANDLE trollpr0c3zz = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pr0c3zz); // Gives access to process.
    if (!trollpr0c3zz) // If it can't access the process, then:
    {
    cout << "I can nawtz open pr0c3zz ." << endl;
    }
    else
    {
    int ammoAmount = 10; // Amount of bullets in current round.
    int roundsAmount = 60; // Amount of rounds left.
    int ammoAddr = 0x29500340; // Ammunition memory address.
    int roundsAddr = 0x296E629C; // Rounds memory address.

    cout << "Unlimited ammo - F1" << endl;

    bool AmmoHax = false;

    while(1) // Loops so the memory keeps rewriting itself if it's changed.
    {
    if (GetAsyncKeyState(VK_F1)) // If the "F1" hotkey is pressed then it will write the new data to the memory address.
    AmmoHax = !AmmoHax;

    if (AmmoHax)
    WriteProcessMemory(trollpr0c3zz, (LPVOID)ammoAddr, &ammoAmount, sizeof(ammoAmount), NULL); // Modifies the ammunition's memory value to 10.
    WriteProcessMemory(trollpr0c3zz, (LPVOID)roundsAddr, &roundsAmount, sizeof(roundsAmount), NULL); // Modifies the rounds' memory value to 60.

    } // End of loop.

    }
    CloseHandle(trollpr0c3zz); // Removes access to the process when it is not needed.
    }
    system("pause");
    return 0;
    }

    //--------------------------------------------------------------------------------------------------------------------------

    when this game is running, it generates two processes. (popcapgame1.exe and PlantsVSZombies.exe)

    i can't use Findwindow() like the above example after i analysis the money of memory address by cheat engine.

    the money of data saves in popcapgame1.exe. it's not saving in PlantsVSZombies.exe.

    i google it, and i found GetModuleHandle() could be used maybe.

    refs: sorry i can't post links yet.

    that's why i have the first problem.

    thanks rely.

    but Hitokiri's rely is too diffcult for me. = ||

    could you explain simpler like the first example?

    i think i need to learn more about the windows api.

    thanks rely again.
    Last edited by Laertesiceking; 07-05-2015 at 10:31 AM.

  5. #5
    殺す必要がある唯一のものは殺されるために準備され人 々である。
    Premium Member
    Hitokiri~'s Avatar
    Join Date
    Oct 2012
    Gender
    female
    Location
    Cancer.
    Posts
    1,201
    Reputation
    24
    Thanks
    937
    My Mood
    Bitchy
    Code:
    1. #include <iostream>
    2. #include <Windows.h>
    3. #include <TlHelp32.h>
    4. #include <Shlwapi.h>
    5. using namespace std;
    6. DWORD GetProcessIdByName( LPCSTR procName ){
    7. PROCESSENTRY32 pe;
    8. HANDLE snapShot;
    9. pe.dwSize = sizeof( pe );
    10. snapShot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, NULL );
    11. if( !snapShot ) throw runtime_error( "Unable to create a snapshot for processes." );
    12. if( Process32First( snapShot, &pe ) ){
    13. do{
    14. if( !stricmp( pe.szExeFile, procName ) ){
    15. CloseHandle( snapShot );
    16. return pe.th32ProcessID;
    17. }
    18. } while( Process32Next( snapShot, &pe ) );
    19. }
    20. CloseHandle( snapShot );
    21. return -1;
    22. }
    23. HMODULE GetModuleBaseByName( DWORD PID, LPCSTR modName ){
    24. MODULEENTRY32 me;
    25. HANDLE snapShot;
    26. WCHAR wModName[MAX_PATH];
    27. wcstombs_s(
    28. me.dwSize = sizeof( me );
    29. me.th32ProcessID = PID;
    30. snapShot = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, NULL );
    31. if( !snapShot ) throw runtime_error( "Unable to create a snapshot for process modules." );
    32. if( Module32First( snapShot, &me ) ){
    33. do{
    34. if( !StrCmpW( me.szModule, wModName ) ){
    35. CloseHandle( snapShot );
    36. return HMODULE( me.modBaseAddr );
    37. }
    38. } while( Module32Next( snapShot, &me );
    39. }
    40. CloseHandle( snapShot );
    41. return HMODULE( NULL );
    42. }
    43. HANDLE OpenProcessByName( LPCSTR procName ){
    44. HANDLE hProc = INVALID_HANDLE_VALUE;
    45. DWORD pID = GetProcessIdByName( procName );
    46. if( pID != -1 )
    47. hProc = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID );
    48. return hProc;
    49. }
    50. HANDLE OpenProcessID( DWORD PID ){
    51. return OpenProcess( PROCESS_ALL_ACCESS, FALSE, PID );
    52. }
    53. int main( int argc, char** argv ){
    54. DWORD pid = -1, tick = 0;
    55. HANDLE Proc = INVALID_HANDLE_VALUE;
    56. PVOID BaseModule = NULL, PVOID Money = NULL;
    57. DWORD MoneyInt = 99999, Out = 0;
    58. cout << "Waiting for Plants vs Zombies to start " << endl;
    59. while( ( pid = GetProcessIdByName( "popcapgame1.exe" ), pid == -1 ) )
    60. {
    61. cout << ".";
    62. Sleep(1000);
    63. }
    64. cout << endl << "Located Process with ID of ( " << pid << " )" << endl << "Attaching ..." << endl;
    65. Proc = OpenProcessID( pid );
    66. if( !Proc ) throw runtime_error( "Unable to attach to the process." );
    67. cout << "Attached to process." << endl << "Locating module's base address..." << endl;
    68. BaseModule = PVOID( GetModuleBaseByName( "popcapgame1.exe" );
    69. if( !BaseModule ) throw runtime_error( "Unable to locate the module's base address." );
    70. else cout << "Located module's base address at: " << BaseModule << endl;
    71. Money = PVOID( PCHAR( BaseModule ) + 0x2619C );
    72. cout << "Keeping $$ value constant .";
    73. while( 1 ){
    74. if( GetAsyncKeyState( VK_F1 ) & 1 )
    75. break;
    76. if( tick++ > 10 ){
    77. cout << "."
    78. tick = 0;
    79. }
    80. WriteProcessMemory( Proc, Money, LPCVOID( &MoneyInt ), sizeof( DWORD ), &Out );
    81. Sleep( 100 );
    82. }
    83. cout << "Hotkey pressed. Program terminated." << endl;
    84. CloseHandle( Proc );
    85. getchar();
    86. return 0;
    87. }
    https://pastebin.com/zvdGCZ4R

    You really should pay me for my kind work. Especially since I'm not a kind person.

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

    Cosmo_ (07-06-2015)

  7. #6
    Laertesiceking's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    0
    Thank you so much!
    I'll study hard.

  8. #7
    Mayion's Avatar
    Join Date
    Oct 2012
    Gender
    male
    Location
    Bed
    Posts
    13,504
    Reputation
    4018
    Thanks
    8,372
    My Mood
    Twisted
    I guess OP found his answer.
    I do not use any type of messenger outside of MPGH.
    Inactive but you can reach me through VM/PM.










     

    Donator - 30 August 2013
    Battlefield Minion - 26 October 2013

    Blackshot Minion - 14 January 2014/16 September 2014
    Minecraft Minion - 7 February 2014/16 September 2014
    WarRock Minion - 23 February 2014
    League of Legends Minion - 21 March 2014

    Minion+ - 15 May 2014
    Other Semi-Popular First Person Shooter Minion - 8 August 2014
    CrossFire Minion - 23 October 2014
    Programming Section Minion - 13 November 2014
    Marketplace Minion - 7 December 2014

    Official Middleman - 7 December 2014 - 27 June 2015
    Moderator - 29 December 2014
    Project Blackout Minion - 10 January 2015
    News Force Interviewer - January 2015
    Steam Games Minion - 21 March 2015
    Dragon Nest Minion - 31 March 2015
    Publicist - April 2015 - 21 September 2015
    Global Moderator - 25 August 2015
    Super User - 13 August 2016



Similar Threads

  1. Replies: 0
    Last Post: 03-05-2014, 12:33 PM
  2. [Help Request] Need Value Off Always HS!!
    By Astr3Lune in forum Crossfire Coding Help & Discussion
    Replies: 7
    Last Post: 10-28-2013, 02:58 PM
  3. Replies: 6
    Last Post: 12-08-2008, 12:57 PM
  4. Ammo/Damage Box Values?
    By wooden_amulet in forum WarRock - International Hacks
    Replies: 4
    Last Post: 06-02-2006, 02:55 AM
  5. Cheat Engine Values
    By Bull3t in forum WarRock - International Hacks
    Replies: 0
    Last Post: 05-31-2006, 04:10 AM