Go Back   UnKnoWnCheaTs - Multiplayer Game Hacks and Cheats > Anti-Cheat Software & Programming > C and C++

- Sponsored Advertisement -
http://www.myfpscheats.com/

Welcome to the UnKnoWnCheaTs - Multiplayer Game Hacks and Cheats.
You have to register before you can post and see and access any of the advanced forum features, please click the register link to proceed to the registration form. To start viewing threads or posts, select a forum that you want to visit from the selection below.
C and C++
hacking programming reversing
You are Unregistered, please register to gain Full access.    
Reply
 
Thread Tools

Creating your first C++ dll hack
Old 03-16-2009, 11:38 PM   #1
retired moderator

JoshRose's Avatar

Join Date: Nov 2007
Location: London
Posts: 1,360
Reputation: 10674
Rep Power: 185
JoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server space
Air Shooter Champion
Points: 14,708, Level: 15
Points: 14,708, Level: 15 Points: 14,708, Level: 15 Points: 14,708, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
Talking Creating your first C++ dll hack

This is a follow on to my tutorial of game hacking with Vb.net. All of the code here is mine and not copy/pasted. Credit will be given where due to people who helped me with things that i will now help you with.

Okay so here goes:

First, load up Visual Studio or whatever it is you use and create a new "Win32 Application", set Application type to "DLL" and tick "Empty project".

Now we are ready.

Create a new SOURCE file called "main.cpp" and inside that, type this at the very top:

Code:
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <float.h>
using namespace std;
This will incude all your typical headers.

Now, since this is a DLL, we are going to want to have functions that we can turn on or off so we need to create some new threads.

First and foremost, you must type this just below your includes:

Code:
BOOL WINAPI DllMain (HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
{
    if (dwAttached == DLL_PROCESS_ATTACH) {
        CreateThread(NULL,0,&LoopFunction,NULL,0,NULL);
    }
    return 1;
}
In simple terms, it says, upon the attachment of this DLL to a process, create a new thread called "LoopFunction"

simple right......

Now, the reason we have created this thread is becuase we need to continually loop around so we can detect when a certain key has been pressed. We will come onto this later.

So, you need this code above the code you just typed:

Code:
 DWORD WINAPI LoopFunction( LPVOID lpParam  )
{
//some CPU relief
    Sleep(200);
}


}
return 0;
}
Now, for my example, i will be locking the X-hairs in the game BF2142

Here we go....

Underneath the line

Code:
 DWORD WINAPI LoopFunction( LPVOID lpParam  ) {
copy this:

Code:
    BYTE StandingON[] = {0x8B, 0x02, 0x90};
    BYTE CrouchingON[] = {0x8B, 0x11, 0x90};
    BYTE ProneON[] = {0x8B, 0x08, 0x90};
    BYTE StandingOFF[] = {0x8B, 0x42, 0x4C};
    BYTE CrouchingOFF[] = {0x8B, 0x51, 0x50};
    BYTE ProneOFF[] = {0x8B, 0x48, 0x54};
This is defining a phrase as an array of bytes thus making our writeprocessmemory tasks much easier.

Once you have done that, put this underneath:

Code:
 bool CrosshairOn = false;
Here we are using a boolean to determine or set the status of our hack. The reason we put it here is so that when we first attach our dll it sets the boolean to false, meaning out hack is not active. We will later set it to true so that our hack turns on.....

After that line, leave a few lines and paste:

Code:
HANDLE bf2142 = GetCurrentProcess();
Due to the fatc we are using a DLL we are already inside the process and therefore can get the pid and other things very easily using this line of code.

Once again leave a few more lines and paste this:

Code:
if (GetAsyncKeyState(VK_F1)&0x80000)
{
    if (CrosshairOn ==  true) {
        WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingOFF, 3, 0);
        WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingOFF, 3, 0);
        WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneOFF, 3, 0);
        CrosshairOn = false;

    }
    else if( CrosshairOn ==  false ) {
        WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingON, 3, 0);
        WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingON, 3, 0);
        WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneON, 3, 0);
        CrosshairOn ==  true
    }

}
Here we are using our boolean.
Basically what it is doing is:

If the bool CrosshairOn = false then it knows that the hack is inactive and thus performs the writememoryprocesses using the correct array of bytes that will lock my X-Hair at all times. If it finds that the bool CrosshairOn = true, then it does the opposite and writes the original bytes back to the correct offsets, thus making my x-hair return to normal.

You can add other hacks by doing this:

Code:
if (GetAsyncKeyState(VK_F2)&0x80000)
{
   

}
your finished code will look something along the lines of:
Code:
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <float.h>
using namespace std;

DWORD WINAPI LoopFunction( LPVOID lpParam )
{

    BYTE StandingON[] = {0x8B, 0x02, 0x90};
    BYTE CrouchingON[] = {0x8B, 0x11, 0x90};
    BYTE ProneON[] = {0x8B, 0x08, 0x90};
    BYTE StandingOFF[] = {0x8B, 0x42, 0x4C};
    BYTE CrouchingOFF[] = {0x8B, 0x51, 0x50};
    BYTE ProneOFF[] = {0x8B, 0x48, 0x54};

    bool Crosshair = false;

    HANDLE bf2142 = GetCurrentProcess();

    while(1) {
        if (GetAsyncKeyState(VK_F1)&0x80000) {
            if (Crosshair == true) {
                WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingOFF, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingOFF, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneOFF, 3, 0);
                Crosshair = false;

            }
            else if( Crosshair == false) {
                WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingON, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingON, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneON, 3, 0);
                Crosshair = true;
            }

        }
    }
//some CPU relief
    Sleep(200);
    return 0;
}

BOOL WINAPI DllMain (HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
{
    if (dwAttached == DLL_PROCESS_ATTACH) {
        CreateThread(NULL,0,&LoopFunction,NULL,0,NULL);
    }
    return 1;
}
That covers the very basics of creating your first hack in C++, just post any questions



Credits:
Zoomgod
raiders
ReUnioN

All of the above helped and are still helping me learn.

Last edited by JoshRose; 06-16-2009 at 04:28 PM.
JoshRose is offline

Reply With Quote


Old 03-17-2009, 01:40 AM   #2
Administrator

Alkatraz's Avatar

Join Date: Nov 2004
Location: In your darkest Fears you will find me!
Posts: 5,318
Reputation: 62788
Rep Power: 822
Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!
Points: 55,278, Level: 35
Points: 55,278, Level: 35 Points: 55,278, Level: 35 Points: 55,278, Level: 35
Activity: 41.4%
Activity: 41.4% Activity: 41.4% Activity: 41.4%
Last Achievements
Award-Showcase
Nice tutorial man, love it when guys actually make a tutorial instead of just posting code and saying have fun. Makes it easier on the guys trying to learn..

+rep for this.
__________________


Sexy Siggy By zero_tolerance





Alkatraz is online now

Reply With Quote

Old 03-17-2009, 03:03 AM   #3


Roverturbo's Avatar

Join Date: Feb 2005
Posts: 5,035
Reputation: 92245
Rep Power: 1108
Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (?)
I am GOD? Hmm K. God
Points: 69,888, Level: 38
Points: 69,888, Level: 38 Points: 69,888, Level: 38 Points: 69,888, Level: 38
Activity: 19.5%
Activity: 19.5% Activity: 19.5% Activity: 19.5%
Last Achievements
You might want to also tell people how the execute their first C+P hack because double clicking a Dynamic-Link Library will not make it magically write itself into a processes memory space and execute.

Thanks for posting something to help the newbies.

Quote:
Originally Posted by jjrose54 View Post
just post any questions
WriteProcessMemory(...) when your code is running inside the processes memory your editing? memcpy... pointers...
__________________


I've learned that something constructive comes from every defeat.

Sometimes i say things i shouldn't, and sometimes i say what other people are thinking.

Real programmer's don't document, if it was hard to write, it should be hard to understand.

First learn computer science and all the theory, next develop a programming style, then forget all that and just hack.

Roverturbo is online now

Reply With Quote

Old 03-17-2009, 12:45 PM   #4
Supreme G0d

d1gitalSLR's Avatar

Join Date: Sep 2008
Posts: 379
Reputation: 3457
Rep Power: 83
d1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating communityd1gitalSLR is a legend in the cheating community
Points: 6,148, Level: 8
Points: 6,148, Level: 8 Points: 6,148, Level: 8 Points: 6,148, Level: 8
Activity: 3.5%
Activity: 3.5% Activity: 3.5% Activity: 3.5%
Last Achievements
There is one thing off about this tutorial. Its that you give them the minimap yet you lock the X-Hairs. That may confuse a beginner and then they will come back with "It doesent work I get a error C2065: 'StandingOFF' : undeclared identifier error.

But still its a great tutorial for some beginners that have some background in what they are doing.

A++ Tutorial and +rep!
d1gitalSLR is online now

Reply With Quote

Old 03-17-2009, 03:49 PM   #5
n00bie

nerrAd's Avatar

Join Date: Feb 2009
Posts: 13
Reputation: 10
Rep Power: 37
nerrAd has made posts that are generally average in quality
Very nice tutorial that gets right down to the bare stuff for beginners like me! I wish more tutorials were like this! Unforunately I don't play or have BF2142 so cannot test if I done it correctly!

I am currently reading several C++ books by Ivor Horton (currently half way through Beginning ANSI C++ and have Beginning Visual C++ 2008 set aside for after!) and Secrets of Reserve Engineering by Eldad Eilam. All recommended somewhere on this forum, I think. Only need to find some good D3D9 books now!
I've been surfing these forums for several months and having a read of source code, etc that I don't even have understand!

More tutorials like this but for CSS or BF2 would be very much appreciated and helpful!
nerrAd is offline

Reply With Quote

Old 04-07-2009, 05:06 AM   #6
n00bie

jimix's Avatar

Join Date: Apr 2009
Posts: 7
Reputation: 10
Rep Power: 35
jimix has made posts that are generally average in quality
okey,but how i can save and use this????
jimix is offline

Reply With Quote

Old 04-07-2009, 01:54 PM   #7
retired moderator

JoshRose's Avatar

Threadstarter
Join Date: Nov 2007
Location: London
Posts: 1,360
Reputation: 10674
Rep Power: 185
JoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server space
Air Shooter Champion
Points: 14,708, Level: 15
Points: 14,708, Level: 15 Points: 14,708, Level: 15 Points: 14,708, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
Quote:
Originally Posted by jimix View Post
okey,but how i can save and use this????
What do you mean save and use?

Go download MS VC++, read the tutorial, do everything as read the tutorial. Add or edit any code you want then save all and build
JoshRose is offline

Reply With Quote

Old 04-13-2009, 01:24 PM   #8
n00bie

jancsies's Avatar

Join Date: Apr 2009
Posts: 1
Reputation: 10
Rep Power: 35
jancsies has made posts that are generally average in quality
1. question: Put the main.cpp to the Source files or to the root folder?
2. question: when I made the dll file where to put it or what to do with that?
jancsies is offline

Reply With Quote

Old 04-14-2009, 02:18 AM   #9
retired moderator

JoshRose's Avatar

Threadstarter
Join Date: Nov 2007
Location: London
Posts: 1,360
Reputation: 10674
Rep Power: 185
JoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server space
Air Shooter Champion
Points: 14,708, Level: 15
Points: 14,708, Level: 15 Points: 14,708, Level: 15 Points: 14,708, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
Quote:
Originally Posted by jancsies View Post
1. question: Put the main.cpp to the Source files or to the root folder?
2. question: when I made the dll file where to put it or what to do with that?

Create a new empty dll in MS VC++.

In the Solution explorer you will see a directory tree, right click "Source Files" and press:

Add -> New Item -> C++ File (cpp)

name it "main.cpp" and put the code in there.

Once you have successfully compiled your dll, you need a program just as Winject so that you can 'Inject' your newly created dll into the procees of the game you wish to hack

Regards
Josh
JoshRose is offline

Reply With Quote

Old 04-14-2009, 03:26 AM   #10
UC Supporter

3p1c's Avatar

Join Date: Oct 2008
Posts: 283
Reputation: 1168
Rep Power: 57
3p1c -- This man endangers the world3p1c -- This man endangers the world3p1c -- This man endangers the world3p1c -- This man endangers the world3p1c -- This man endangers the world3p1c -- This man endangers the world3p1c -- This man endangers the world3p1c -- This man endangers the world3p1c -- This man endangers the world
Quote:
Originally Posted by Roverturbo View Post
You might want to also tell people how the execute their first C+P hack because double clicking a Dynamic-Link Library will not make it magically write itself into a processes memory space and execute.

Thanks for posting something to help the newbies.



WriteProcessMemory(...) when your code is running inside the processes memory your editing? memcpy... pointers...
Using WPM is essentially the same as virtual protect and memcpy. Depending on what your doing the overhead is not that big of deal. Maybe I am wrong. What is your resoning for memcpy rather than WPM? I mean we are coding for a windows environment so IDK.
3p1c is offline

Reply With Quote

Old 04-14-2009, 03:28 AM   #11
Retired Admin

learn_more's Avatar

Join Date: Sep 2006
Posts: 5,249
Reputation: 93628
Rep Power: 1106
learn_more has a huge epeen!learn_more has a huge epeen!learn_more has a huge epeen!learn_more has a huge epeen!learn_more has a huge epeen!learn_more has a huge epeen!learn_more has a huge epeen!learn_more has a huge epeen!learn_more has a huge epeen!learn_more has a huge epeen!learn_more has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (2)
sieg heil Nazi
Points: 70,490, Level: 39
Points: 70,490, Level: 39 Points: 70,490, Level: 39 Points: 70,490, Level: 39
Activity: 24.7%
Activity: 24.7% Activity: 24.7% Activity: 24.7%
Last Achievements
Award-Showcase
Quote:
Originally Posted by jaroldoshoot54 View Post
Using WPM is essentially the same as virtual protect and memcpy. Depending on what your doing the overhead is not that big of deal. Maybe I am wrong. What is your resoning for memcpy rather than WPM? I mean we are coding for a windows environment so IDK.
writeprocessmemory is calling ring 0 functions,

memcyp isnt (unless you virtualprotect ofc)
__________________
learn_more is offline

Reply With Quote

Old 05-03-2009, 04:28 PM   #12
n00bie

Breeze's Avatar

Join Date: May 2009
Posts: 4
Reputation: 10
Rep Power: 34
Breeze has made posts that are generally average in quality
Good tut
Breeze is offline

Reply With Quote

Old 05-04-2009, 12:53 AM   #13
UC Supporter

AndrewThomas's Avatar

Join Date: Feb 2009
Location: Canada
Posts: 281
Reputation: 4599
Rep Power: 87
AndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating communityAndrewThomas is a legend in the cheating community
Quote:
Originally Posted by jaroldoshoot54 View Post
Using WPM is essentially the same as virtual protect and memcpy. Depending on what your doing the overhead is not that big of deal. Maybe I am wrong. What is your resoning for memcpy rather than WPM? I mean we are coding for a windows environment so IDK.
A ) Anti-hack systems will hook WriteProcessMemory
B ) It's more proper, quicker, and doesn't make any calls the the kernel
C ) Looks neater, doesn't require a handle to the address space, also only has 3 params opposed to 5.

There are several other reasons, but I'm not writing a book on it :S


Not to get off-topic, great tut, only thing I disagree with is your use of WriteProcessMemory. Also, instead of including the whole std namepace in the cpp file, you really should only use it in functions that make constant use of it, like a logging function.

Last edited by AndrewThomas; 05-04-2009 at 12:56 AM.
AndrewThomas is offline

Reply With Quote

Old 06-16-2009, 04:07 PM   #14
n00bie

x3res's Avatar

Join Date: Jun 2009
Posts: 3
Reputation: -11
Rep Power: 0
x3res is becoming a waste of our time
i got error like this:

1>------ Build started: Project: proper, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\documents and settings\arek\moje dokumenty\visual studio 2005\projects\proper\proper\main.cpp(1) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>Build log was saved at "file://c:\Documents and Settings\arek\Moje dokumenty\Visual Studio 2005\Projects\proper\proper\Debug\BuildLog.htm"
1>proper - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


and my script looks like this:

#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <float.h>
using namespace std;
DWORD WINAPI LoopFunction( LPVOID lpParam ) {


//some CPU relief
Sleep(200);

}
}
return 0;
}
BOOL WINAPI DllMain (HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved) {
if (dwAttached == DLL_PROCESS_ATTACH) {
CreateThread(NULL,0,&LoopFunction,NULL,0,NULL);

}
return 1;
}
DWORD WINAPI LoopFunction( LPVOID lpParam ) {

BYTE MiniMapInfantryON[] = {0x17};
BYTE MiniMapVehicleON[] = {0x90, 0x90};
BYTE MiniMapInfantryOFF[] = {0x18};
BYTE MiniMapVehicleOFF[] = {0x75, 0x09};
bool CrosshairOn = false;



HANDLE bf2142 = GetCurrentProcess();
if (GetAsyncKeyState(VK_F1)&0x80000)
{
if (CrosshairOn)
{
WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingOFF, 3, 0);
WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingOFF, 3, 0);
WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneOFF, 3, 0);


}
else
{
WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingON, 3, 0);
WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingON, 3, 0);
WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneON, 3, 0);
}

CrosshairOn = !CrosshairOn;

}



anyone know what is wrong?
x3res is offline

Reply With Quote

Old 06-16-2009, 04:18 PM   #15
retired moderator

JoshRose's Avatar

Threadstarter
Join Date: Nov 2007
Location: London
Posts: 1,360
Reputation: 10674
Rep Power: 185
JoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server space
Air Shooter Champion
Points: 14,708, Level: 15
Points: 14,708, Level: 15 Points: 14,708, Level: 15 Points: 14,708, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
Quote:
Originally Posted by x3res View Post
anyone know what is wrong?
You don't know what you are doing

1) You have the loop function in their twice, and they are both wrong anyway
2) When you get it to compile you don't have a dllmain so it won't work
3) Although i made a mistake in the tutorial and named something wrong, you have obvs just C&P all of it (badly may i add) and not realised the rather obvious mistake

But, everyone must start somewhere, try this:

Code:
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <float.h>
using namespace std;

DWORD WINAPI LoopFunction( LPVOID lpParam )
{

    BYTE StandingON[] = {0x8B, 0x02, 0x90};
    BYTE CrouchingON[] = {0x8B, 0x11, 0x90};
    BYTE ProneON[] = {0x8B, 0x08, 0x90};
    BYTE StandingOFF[] = {0x8B, 0x42, 0x4C};
    BYTE CrouchingOFF[] = {0x8B, 0x51, 0x50};
    BYTE ProneOFF[] = {0x8B, 0x48, 0x54};

    bool Crosshair = false;

    HANDLE bf2142 = GetCurrentProcess();

    while(1) {
        if (GetAsyncKeyState(VK_F1)&0x80000) {
            if (Crosshair == true) {
                WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingOFF, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingOFF, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneOFF, 3, 0);
                Crosshair = false;

            }
            else if( Crosshair == false) {
                WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingON, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingON, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneON, 3, 0);
                Crosshair = true;
            }

        }
    }
//some CPU relief
    Sleep(200);
    return 0;
}
There is no DLLMain in that code i just gave you, but the tutorial shows you what to do.
__________________
Regards and happy
Josh

__________________
JoshRose is offline

Reply With Quote

Old 06-16-2009, 04:29 PM   #16
« Forum Admin »

Winslow's Avatar

Join Date: Nov 2004
Posts: 3,163
Reputation: 85707
Rep Power: 1009
Winslow has a huge epeen!Winslow has a huge epeen!Winslow has a huge epeen!Winslow has a huge epeen!Winslow has a huge epeen!Winslow has a huge epeen!Winslow has a huge epeen!Winslow has a huge epeen!Winslow has a huge epeen!Winslow has a huge epeen!Winslow has a huge epeen!
Recognitions:
Awarded to members who have donated 10 times or more. Gratuity (1)
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (10)
Points: 66,910, Level: 38
Points: 66,910, Level: 38 Points: 66,910, Level: 38 Points: 66,910, Level: 38
Activity: 24.1%
Activity: 24.1% Activity: 24.1% Activity: 24.1%
Last Achievements
Award-Showcase
Quote:
Originally Posted by x3res View Post
i got error like this:

1>------ Build started: Project: proper, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\documents and settings\arek\moje dokumenty\visual studio 2005\projects\proper\proper\main.cpp(1) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>Build log was saved at "file://c:\Documents and Settings\arek\Moje dokumenty\Visual Studio 2005\Projects\proper\proper\Debug\BuildLog.htm"
1>proper - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Do you have Microsoft SDK installed? http://www.microsoft.com/downloads/d...displaylang=en

Are your directories set up correctly? Tools >> Options >> Projects and Solutions >> VC++ Directories ...


That should get rid of the specific error you're getting.
Also read what Jose said to fix the other errors you're going to get
Winslow is online now

Reply With Quote

Old 06-16-2009, 04:41 PM   #17
retired moderator

JoshRose's Avatar

Threadstarter
Join Date: Nov 2007
Location: London
Posts: 1,360
Reputation: 10674
Rep Power: 185
JoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server space
Air Shooter Champion
Points: 14,708, Level: 15
Points: 14,708, Level: 15 Points: 14,708, Level: 15 Points: 14,708, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
Quote:
Originally Posted by Winslow View Post
Also read what Jose said to fix the other errors you're going to get
Hmm, i quite like that name, José, very cool
__________________
Regards and happy
Josh

__________________
JoshRose is offline

Reply With Quote

Old 07-20-2009, 11:33 AM   #18
n00bie

explorerkelo's Avatar

Join Date: May 2009
Posts: 24
Reputation: 10
Rep Power: 34
explorerkelo has made posts that are generally average in quality
Quote:
Originally Posted by JoshRose View Post
This is a follow on to my tutorial of game hacking with Vb.net. All of the code here is mine and not copy/pasted. Credit will be given where due to people who helped me with things that i will now help you with.

Okay so here goes:

First, load up Visual Studio or whatever it is you use and create a new "Win32 Application", set Application type to "DLL" and tick "Empty project".

Now we are ready.

Create a new SOURCE file called "main.cpp" and inside that, type this at the very top:

Code:
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <float.h>
using namespace std;
This will incude all your typical headers.

Now, since this is a DLL, we are going to want to have functions that we can turn on or off so we need to create some new threads.

First and foremost, you must type this just below your includes:

Code:
BOOL WINAPI DllMain (HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
{
    if (dwAttached == DLL_PROCESS_ATTACH) {
        CreateThread(NULL,0,&LoopFunction,NULL,0,NULL);
    }
    return 1;
}
In simple terms, it says, upon the attachment of this DLL to a process, create a new thread called "LoopFunction"

simple right......

Now, the reason we have created this thread is becuase we need to continually loop around so we can detect when a certain key has been pressed. We will come onto this later.

So, you need this code above the code you just typed:

Code:
 DWORD WINAPI LoopFunction( LPVOID lpParam  )
{
//some CPU relief
    Sleep(200);
}


}
return 0;
}
Now, for my example, i will be locking the X-hairs in the game BF2142

Here we go....

Underneath the line

Code:
 DWORD WINAPI LoopFunction( LPVOID lpParam  ) {
copy this:

Code:
    BYTE StandingON[] = {0x8B, 0x02, 0x90};
    BYTE CrouchingON[] = {0x8B, 0x11, 0x90};
    BYTE ProneON[] = {0x8B, 0x08, 0x90};
    BYTE StandingOFF[] = {0x8B, 0x42, 0x4C};
    BYTE CrouchingOFF[] = {0x8B, 0x51, 0x50};
    BYTE ProneOFF[] = {0x8B, 0x48, 0x54};
This is defining a phrase as an array of bytes thus making our writeprocessmemory tasks much easier.

Once you have done that, put this underneath:

Code:
 bool CrosshairOn = false;
Here we are using a boolean to determine or set the status of our hack. The reason we put it here is so that when we first attach our dll it sets the boolean to false, meaning out hack is not active. We will later set it to true so that our hack turns on.....

After that line, leave a few lines and paste:

Code:
HANDLE bf2142 = GetCurrentProcess();
Due to the fatc we are using a DLL we are already inside the process and therefore can get the pid and other things very easily using this line of code.

Once again leave a few more lines and paste this:

Code:
if (GetAsyncKeyState(VK_F1)&0x80000)
{
    if (CrosshairOn ==  true) {
        WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingOFF, 3, 0);
        WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingOFF, 3, 0);
        WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneOFF, 3, 0);
        CrosshairOn = false;

    }
    else if( CrosshairOn ==  false ) {
        WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingON, 3, 0);
        WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingON, 3, 0);
        WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneON, 3, 0);
        CrosshairOn ==  true
    }

}
Here we are using our boolean.
Basically what it is doing is:

If the bool CrosshairOn = false then it knows that the hack is inactive and thus performs the writememoryprocesses using the correct array of bytes that will lock my X-Hair at all times. If it finds that the bool CrosshairOn = true, then it does the opposite and writes the original bytes back to the correct offsets, thus making my x-hair return to normal.

You can add other hacks by doing this:

Code:
if (GetAsyncKeyState(VK_F2)&0x80000)
{
   

}
your finished code will look something along the lines of:
Code:
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <float.h>
using namespace std;

DWORD WINAPI LoopFunction( LPVOID lpParam )
{

    BYTE StandingON[] = {0x8B, 0x02, 0x90};
    BYTE CrouchingON[] = {0x8B, 0x11, 0x90};
    BYTE ProneON[] = {0x8B, 0x08, 0x90};
    BYTE StandingOFF[] = {0x8B, 0x42, 0x4C};
    BYTE CrouchingOFF[] = {0x8B, 0x51, 0x50};
    BYTE ProneOFF[] = {0x8B, 0x48, 0x54};

    bool Crosshair = false;

    HANDLE bf2142 = GetCurrentProcess();

    while(1) {
        if (GetAsyncKeyState(VK_F1)&0x80000) {
            if (Crosshair == true) {
                WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingOFF, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingOFF, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneOFF, 3, 0);
                Crosshair = false;

            }
            else if( Crosshair == false) {
                WriteProcessMemory(bf2142, (void*)(0x05E2C88), &StandingON, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C93), &CrouchingON, 3, 0);
                WriteProcessMemory(bf2142, (void*)(0x05E2C9E), &ProneON, 3, 0);
                Crosshair = true;
            }

        }
    }
//some CPU relief
    Sleep(200);
    return 0;
}

BOOL WINAPI DllMain (HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
{
    if (dwAttached == DLL_PROCESS_ATTACH) {
        CreateThread(NULL,0,&LoopFunction,NULL,0,NULL);
    }
    return 1;
}
That covers the very basics of creating your first hack in C++, just post any questions



Credits:
Zoomgod
raiders
ReUnioN

All of the above helped and are still helping me learn.

nice, How do I Create a new SOURCE file called "main.cpp" ?
explorerkelo is offline

Reply With Quote

Old 07-20-2009, 01:49 PM   #19
Hacker Supreme

CRYSIS2000's Avatar

Join Date: Mar 2008
Location: GR
Posts: 240
Reputation: 465
Rep Power: 56
CRYSIS2000 is a preacher of ownage - listen and learnCRYSIS2000 is a preacher of ownage - listen and learnCRYSIS2000 is a preacher of ownage - listen and learnCRYSIS2000 is a preacher of ownage - listen and learnCRYSIS2000 is a preacher of ownage - listen and learn
Shoot 2: Cruise Control Champion
Quote:
Originally Posted by explorerkelo View Post
nice, How do I Create a new SOURCE file called "main.cpp" ?
Solved on xfire.
__________________
Official UnKnoWnCheaTs Xfire Clan Page



Quote:
Originally Posted by zoomgod View Post
Damn, PB working weekends now, that didn't last long.
CRYSIS2000 is offline

Reply With Quote

Old 09-05-2009, 02:04 PM   #20
n00bie

FreakBoy's Avatar

Join Date: Sep 2009
Posts: 19
Reputation: 3
Rep Power: 0
FreakBoy has a near-average in quality posting ability
Question

Question,

Does the "main.cpp" go into the "Header Files" (Folder) or just sit out all alone by it self?

Also will and injector basically work to inject this .dll?

Any help would be appreciated.




UPDATE:

I think I found my answer, lol I just had to re-read all these posts 3 more times.

Thanks

Last edited by FreakBoy; 09-05-2009 at 02:08 PM.
FreakBoy is offline

Reply With Quote
Reply  

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit



Tags
creating, dll, hack
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT +1. The time now is 10:14 AM.