Jump to content

Patch function

- - - - -

  • Please log in to reply
2 replies to this topic

#1
butcher1993

butcher1993

    Newbie

  • Members
  • Pip
  • 2 posts
Yeah im pretty new to C++. I want to apply a patcher function, but I don't know how. I have the code from a friend, SEGnosis, but he just gave it to me. I have been coding C++ for 5 days, I know just the basics. I can compile it, but I cant get it to edit the value or bytes or anything.


Im having problem with this part. Say the address is 0078201E and the bytes are 90 90 90, what would I put in that to make Hack1 patch that address to a NOP. Could you mabye fill it in, so I can see how to do it? I learn best that way. Thank you for reading this post!!

BYTE byPatch2[2] = { 0x90,0x90 };//Declare What bytes to patch
BYTE byPatch3[3] = { 0x90,0x90,0x90 };
BYTE byPatch4[4] = { 0x90,0x90,0x90,0x90 };
BYTE byPatch6[6] = { 0x90,0x90,0x90,0x90,0x90,0x90 };
BYTE HackByte1[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 };
BYTE HackByte2[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 };
BYTE HackByte3[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 };


void fMainHacks()//Made Function For Calling Hacks
{
if(iHack1 == 1){Patch(0x01193FA8,&byPatch6,6);}//Patch Function called and The address 0x00000000 is put into
else{Patch(0x01193FA8,&HackByte1,6);}//the parameters along with Which Bytes and how Many

if(iHack2 == 1){Patch(0x00000000,&byPatch6,6);}
else{Patch(0x00000000,&HackByte2,6);}

if(iHack3 == 1){Patch(0x00000000,&byPatch6,6);}
else{Patch(0x00000000,&HackByte3,6);}
}





#include <windows.h>

#include <iostream>//Includes Input Output Stream


using namespace std;//To Avoid STD::


void Patch(int,LPVOID,DWORD);//Prodotype Of Patch Func


char iHack1    = 0;//Declare hack options 1/0        

char iHack2    = 0;            

char iHack3    = 0;


char iOptionToggle    = 0;//Declare Option 

char iMenuSelect    = 0;



BYTE byPatch2[2]        = { 0x90,0x90 };//Declare What bytes to patch

BYTE byPatch3[3]        = { 0x90,0x90,0x90 };

BYTE byPatch4[4]        = { 0x90,0x90,0x90,0x90 };

BYTE byPatch6[6]        = { 0x90,0x90,0x90,0x90,0x90,0x90 };

BYTE HackByte1[6]        = { 0x00,0x00,0x00,0x00,0x00,0x00 };

BYTE HackByte2[6]        = { 0x00,0x00,0x00,0x00,0x00,0x00 };

BYTE HackByte3[6]        = { 0x00,0x00,0x00,0x00,0x00,0x00 };



void fMainHacks()//Made Function For Calling Hacks

{            

    if(iHack1 == 1){Patch(0x01193FA8,&byPatch6,6);}//Patch Function called and The address 0x00000000 is put into 

               else{Patch(0x01193FA8,&HackByte1,6);}//the parameters along with Which Bytes and how Many


    if(iHack2 == 1){Patch(0x00000000,&byPatch6,6);}

               else{Patch(0x00000000,&HackByte2,6);}


    if(iHack3 == 1){Patch(0x00000000,&byPatch6,6);}

               else{Patch(0x00000000,&HackByte3,6);}

}



void fOptionStatus()//Function for Calling Input of Arrow Keys

    {

    if(GetAsyncKeyState(VK_RIGHT)&1){iOptionToggle++;}

    if(GetAsyncKeyState(VK_LEFT)&1){iOptionToggle--;}

    if(iOptionToggle < 0){iOptionToggle++;}//Limits Amount to 1/0

    if(iOptionToggle > 1){iOptionToggle--;}

    }


void fMenuControls()

    {

    if(GetAsyncKeyState(VK_DOWN)&1){iMenuSelect++;}

    if(GetAsyncKeyState(VK_UP)&1){iMenuSelect--;}

    if(iMenuSelect > 2){iMenuSelect--;}

    if(iMenuSelect < 0){iMenuSelect++;}

    }



int fIfSelected(int iInputint)//Made Func That Takes in Option From Hack 

{

    if(iMenuSelect == 0){ iOptionToggle = iHack1;    fOptionStatus(); iInputint = iHack1    = iOptionToggle;}//Puts Value of Option into iOptionToggle

    if(iMenuSelect == 1){ iOptionToggle = iHack2;    fOptionStatus(); iInputint = iHack2    = iOptionToggle;}//Then calls the Func For Arrow Keys

    if(iMenuSelect == 2){ iOptionToggle = iHack3;    fOptionStatus(); iInputint = iHack3    = iOptionToggle;}//Then Puts the Changed value into all

    return iInputint;//returns The value 

}



void fMenu()//Menu Func

{

    cout << "-------------------------------\n";//Looks Purty

    cout << "         Gen's Base 1.1\n";

    cout << "-------------------------------\n";

    cout << "\n\n  -]Menu Discription \n \n";

    

    iMenuSelect == 0 ? cout << ">" : cout << " ";//Checks If It is selected To Put > or Just a space

    if ( iHack1 == 1 )//If Hack Option is On 1 then Say:

    { 

        cout << "    Hack1        1.0\n" ; 

    }

    else//If Not Then Say:

    { 

        cout << "    Hack1        0.0\n";

    }


    iMenuSelect == 1 ? cout << ">" : cout << " ";

    if ( iHack2 == 1 )

    { 

        cout << "    Hack2        1.0\n"; 

    }

    else 

    {

        cout << "    Hack2        0.0\n";

    }


    iMenuSelect == 2 ? cout << ">" : cout << " ";

    if ( iHack3 == 1 )

    { 

        cout << "    Hack3        1.0\n"; 

    }

    else 

    {

        cout << "    Hack3        0.0\n";

    }



}


void fControl()

    {

    fIfSelected(iHack1);//Throws all Options into If Selected Func

    fIfSelected(iHack2);

    fIfSelected(iHack3);

    }



void fStatus()

{

    int i = iMenuSelect + iOptionToggle;//Puts value of iMenuSelect and OptionToggle into i

    int k = i;//Puts value of i into k

    do{


    fControl();//Calls for arrow Keys Funcs

    fMenuControls();

    i = iMenuSelect + iOptionToggle;//Puts Value int i again


    }while(k == i);//Keeps looping until You change value with arrow keys


    system("cls");//Clears Screen

}






void fIntro()

{

    HWND hWndTarget = FindWindow(NULL,"Step 2");//Gets handle For game Window

    cout << "\n\nGen's Base\n";

    cout << "Made By SEGnosis\n\n";

    if (hWndTarget != 0){cout << "\n\nThank You For Having GameName On";}//Checks if failed

    else{cout << "\n\nPlease Turn On GameName";}

    Sleep(3000);//pauses for 3 seconds

}




void fFuncCalls()//Calls Funcs

{

    fMenu();

    fMainHacks();

}


int main(){

    SetConsoleTitle( "Gen's Base v1.1" );//Sets Window Title

    fIntro();

    system("cls");


    while(1)//Loops Forever

    {

    fFuncCalls();

    fStatus();

    }

    return 0;

}


//_________________________Patch Fuction *Special Thanks to Mr.Novacain

void Patch(int nAddress,LPVOID lpvPatch,DWORD dwSize){

    DWORD dwProcessID;//will hold the process-id

    DWORD dwOldProtect;//will hold the memory access-rights

    HANDLE hProcess;//will hold the process-handle


    HWND hWndTarget = FindWindow(NULL,"Window Name");//find windows Game window

    if(hWndTarget!=0){//if window was found

        GetWindowThreadProcessId(hWndTarget,&dwProcessID);//get the process-id

        hProcess = OpenProcess(PROCESS_ALL_ACCESS,0,dwProcessID);//get the process-handle from the id

        VirtualProtectEx(hProcess,(void*)nAddress,dwSize,PAGE_EXECUTE_READWRITE,&dwOldProtect);//make the memory-space writeable

        WriteProcessMemory(hProcess,(void*)nAddress,lpvPatch,dwSize,0);//write the byte-patch

        VirtualProtectEx(hProcess,(void*)nAddress,dwSize,dwOldProtect,&dwOldProtect);//write back the original access

        CloseHandle(hProcess);//close handle

        return;

    }

    return;

}




#2
kernelcoder

kernelcoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 277 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal
What the code does: Its gets a process handle (first gets the window-handle by FindWindow, then gets the process-id by calling the GetWindowThreadProcessId with supplying window-handle and finally by calling OpenProcess suppyling the process-id) of process. Then, changes the protection on virtual memory of that process by calling VirtualProtectEx and finally write some data onto the memory space at a particular address of the opened process. After that, changes the old protection and finally close the process.

It also maintains three variables (iHack1, iHack2 & iHack3) with state on/off to track what values to write to a specific address. You can change the variables state by first pointing to corresponding variable (by pressing up/down arrow), then by pressing left/right arrow to make it on/off. If any variable is on, it writes 6 bytes each of 0x90 to a specific memory of the opened process; otherwise it writes 6 bytes each 0x00. The only difference about the 3 variables is that iHack1 writes to address 0x01193FA8 and other two variable write to 0x00000000.

So if you want to change data at address 0078201E, first change the address in function fMainHack first if/else construct. Then run the program, change the state of iHack by keeping up arrow key to top and making its value to 1.

#3
butcher1993

butcher1993

    Newbie

  • Members
  • Pip
  • 2 posts
Thanks! Haha this thread is old I know quite a bit more about C++ now. Thanks for replying though!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users