PDA

View Full Version : [C++ Help] Error Injecting DLL



KryptiC
11-14-2007, 06:28 AM
I'm having trouble injecting a dll into a running process. I'm following the stickied tutorials. I build both the .dll and .exe and i get no errors, but when i run the exe, it can't inject to gta san andreas. This is my code:

DLL:

functions.cpp


#include "stdafx.h"
#include "functions.h"


// Thanks to Sobeit
DWORD* dwCarPointerBase = (DWORD*)0xB6F3B8; //car base
DWORD proc_id;
HANDLE hProcess;

void OpenMemory()
{
HWND hWnd = FindWindow(0, "GTA: San Andreas");
GetWindowThreadProcessId(hWnd, &proc_id);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
}




void Writelong(long addy, long value)
{
OpenMemory();
WriteProcessMemory(hProcess, (LPVOID*)(DWORD) addy, &value, sizeof(value), NULL);

}


// Player functions

void Health()
{

Writelong(0x96916D, 1);
}

void Money()
{

Writelong(0xB7CE50, 1337);
}

void Money1()
{

Writelong(0xB7CE50, 50000);
}

void Money2()
{

Writelong(0xB7CE50, 100000);
}

void Money3()
{

Writelong(0xB7CE50, 1000000);
}

void Money4()
{

Writelong(0xB7CE50, 999999999);
}



// Cheats

void CarsCanFlyA()
{

Writelong(0x969160, 1);
}


void CarsCanFlyD()
{

Writelong(0x969160, 0);
}

void BoatsCanFlyA()
{

Writelong(0x969153, 1);
}

void BoatsCanFlyD()
{

Writelong(0x969153, 0);
}

void CarsNos()
{

Writelong(0x969165, 1);
}


void MegaJumpA()
{

Writelong(0x96916C, 1);
}

void MegaJumpD()
{

Writelong(0x96916C, 0);
}


void JetPack()
{

Writelong(0x969170, 1);
}

void MaxStamina()
{

Writelong(0x969181, 1);
}

// Other


//Inf. Nos

float* fXSpeed = (float*)((*dwCarPointerBase) + 68); // X Speed
float* fYSpeed = (float*)((*dwCarPointerBase) + 72); // Y Speed
float* fZSpeed = (float*)((*dwCarPointerBase) + 76); // Z Speed

void InfNos()
{

if(*dwCarPointerBase)

if (GetAsyncKeyState(VK_LSHIFT) < 0)
{
*fXSpeed += *fXSpeed;
*fYSpeed += *fYSpeed;
}
}

LH1337DLL.def


LIBRARY LH1337DLL

EXPORTS
Health
Money
Money1
Money2
Money3
Money4
CarsCanFlyA
CarsCanFlyD
BoatsCanFlyA
BoatsCanFlyD
CarsNos
MegaJumpA
MegaJumpD
JetPack
MaxStamina
InfNos

functions.h


#pragma once

void Health();
void Money();
void Money1();
void Money2();
void Money3();
void Money4();
void CarsCanFlyA();
void CarsCanFlyD();
void BoatsCanFlyA();
void BoatsCanFlyD();
void CarsNos();
void MegaJumpA();
void MegaJumpD();
void JetPack();
void MaxStamina();
void InfNos();


And now my EXE (i left out some unimportant stuff)


#include "stdafx.h"
#include "LH1337EXE.h"
#include "LH1337EXEDlg.h"



HINSTANCE hDLL = NULL;



typedef void (*HEALTH)();
HEALTH Health;

typedef void (*MONEY)();
MONEY Money;

typedef void (*MONEY1)();
MONEY1 Money1;

typedef void (*MONEY2)();
MONEY2 Money2;

typedef void (*MONEY3)();
MONEY1 Money3;

typedef void (*MONEY4)();
MONEY1 Money4;

typedef void (*CARSCANFLYA)();
CARSCANFLYA CarsCanFlyA;

typedef void (*CARSCANFLYD)();
CARSCANFLYD CarsCanFlyD;

typedef void (*BOATSCANFLYA)();
BOATSCANFLYA BoatsCanFlyA;

typedef void (*BOATSCANFLYD)();
BOATSCANFLYD BoatsCanFlyD;

typedef void (*CARSNOS)();
CARSNOS CarsNos;

typedef void (*MEGAJUMPA)();
MEGAJUMPA MegaJumpA;

typedef void (*MEGAJUMPD)();
MEGAJUMPD MegaJumpD;

typedef void (*JETPACK)();
JETPACK JetPack;

typedef void (*MAXSTAMINA)();
MAXSTAMINA MaxStamina;

typedef void (*INFNOS)();
INFNOS InfNos;

BOOL CLH1337EXEDlg::OnInitDialog()
{
CDialog::OnInitDialog();


hDLL = AfxLoadLibrary("LH1337DLL");

if( hDLL == NULL )
{
MessageBox("Could not load LH1337DLL.dll");
}
else
{
Money = (MONEY)GetProcAddress(hDLL, "MONEY");
Health = (HEALTH)GetProcAddress(hDLL, "HEALTH");
Money1 = (MONEY1)GetProcAddress(hDLL, "MONEY1");
Money2 = (MONEY2)GetProcAddress(hDLL, "MONEY2");
Money3 = (MONEY3)GetProcAddress(hDLL, "MONEY3");
Money4 = (MONEY4)GetProcAddress(hDLL, "MONEY4");
CarsCanFlyA = (CARSCANFLYA)GetProcAddress(hDLL, "CARSCANFLYA");
CarsCanFlyD = (CARSCANFLYD)GetProcAddress(hDLL, "CARSCANFLYD");
BoatsCanFlyA = (BOATSCANFLYA)GetProcAddress(hDLL, "BOATSCANFLYA");
BoatsCanFlyD = (BOATSCANFLYD)GetProcAddress(hDLL, "BOATSCANFLYD");
CarsNos = (CARSNOS)GetProcAddress(hDLL, "CARSNOS");
MegaJumpA = (MEGAJUMPA)GetProcAddress(hDLL, "MEGAJUMPA");
MegaJumpD = (MEGAJUMPD)GetProcAddress(hDLL, "MEGAJUMPD");
JetPack = (JETPACK)GetProcAddress(hDLL, "JETPACK");
MaxStamina = (MAXSTAMINA)GetProcAddress(hDLL, "MAXSTAMINA");
InfNos = (INFNOS)GetProcAddress(hDLL, "INFNOS");
}

void CLH1337EXEDlg::OnButton1()
{
Money();
}

void CLH1337EXEDlg::OnButton3()
{
Money1();
}

void CLH1337EXEDlg::OnButton4()
{
Money2();
}

void CLH1337EXEDlg::OnButton5()
{
Money3();
}

void CLH1337EXEDlg::OnButton6()
{
Money4();
}

void CLH1337EXEDlg::OnButton7()
{
Health();
}


void CLH1337EXEDlg::OnButton8()
{
CarsCanFlyA();
}

void CLH1337EXEDlg::OnButton9()
{
CarsCanFlyD();
}

void CLH1337EXEDlg::OnButton10()
{
BoatsCanFlyA();
}

void CLH1337EXEDlg::OnButton11()
{
BoatsCanFlyD();
}

void CLH1337EXEDlg::OnButton12()
{
CarsNos();
}

void CLH1337EXEDlg::OnButton14()
{
MegaJumpA();
}

void CLH1337EXEDlg::OnButton15()
{
MegaJumpD();
}

void CLH1337EXEDlg::OnButton16()
{
JetPack();
}

void CLH1337EXEDlg::OnButton17()
{
MaxStamina();
}

void CLH1337EXEDlg::OnButton18()
{
InfNos();
}

So, once again, I have no problem compiling the project, it just doesn't inject the dll to gta san andreas (Could not load LH1337DLL.dll). Help would be greatly appreciated. I have the process name corect, I've checked 10 times:p Also, I'm a C++ beginner, I only started a few days ago. BTW, this site rocks! It has the best hack-making tutorials ever! Great work, I'm looking forward to more great tutorials!!!

Dxt-Cobra
11-14-2007, 10:06 AM
Did you place the dll with your .exe,they have to be in the same folder,for it to load the dll.


Then if the functions dont work do this to all.



void Health()
{
OpenMemory();
long value=1;
WriteProcessMemory(hProcess, (LPVOID*)(DWORD) 0x96916D, &value, sizeof(value), NULL);

}

KryptiC
11-14-2007, 04:01 PM
Yes, I placed them both in same folders. I have tried placing them both in the game directory to see if it would make a difference, but that didn't work. I changed the functions as you said, but I'm not going to be able to test them until I get it working :( I attached both the exe and .dll source in an attachment if you want to look at it. Thanks for your help! :)

edit: hmmm its not uploading :S here: http://rapidshare.com/files/69754801/LH1337DLL.rar.html

LegendaryHacker
11-15-2007, 01:57 PM
maybe you changed the name of the dll !

the name of the dll must be LH1337DLL.dll

KryptiC
11-16-2007, 12:56 AM
OK, I fixed the problem by using another way of detecting the process. Now i have another problem.

1. Lets say this is the pointer: 0xB6D170 and the two offsets i want to add do it are 0x40 and 0x44. Would I just add the two offsets to make 0x84? Or not?

2. And when I have done this, how would I add a value to it? I don't want to set a value, I want to add a value to the current value.

Thanks guys! I reeaaallllyyy appreciate you helping me! :)