Quantcast

Jump to content

» «
Photo

[VC]Injecting DLL in C++ to Read and Write Memory

11 replies to this topic
Zeyad_Ahmed
  • Zeyad_Ahmed

    Player Hater

  • Members
  • Joined: 22 Aug 2016
  • Egypt

#1

Posted 21 August 2017 - 11:54 PM

Ok, Welcome guys, as the topic says, i know C++ and wrote that code as a DLL

#include "stdafx.h"
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, PVOID lpvReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		// DO STUFF HERE 
		
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

so.

What i write to read a memory and write it ? use WriteProcessMemory function or something else , can u show me guys a small example and thanks :D


madleg
  • madleg

  • Members
  • Joined: 01 Jan 2014
  • None

#2

Posted 22 August 2017 - 06:51 AM

just cast memory address to pointer. For protected memory regions you should set virtual protect first.


Zeyad_Ahmed
  • Zeyad_Ahmed

    Player Hater

  • Members
  • Joined: 22 Aug 2016
  • Egypt

#3

Posted 22 August 2017 - 02:54 PM

just cast memory address to pointer. For protected memory regions you should set virtual protect first.

oh thanks very much, can u show small example to cast memory , let memory address is 0xAAFE8C :D


madleg
  • madleg

  • Members
  • Joined: 01 Jan 2014
  • None

#4

Posted 22 August 2017 - 03:17 PM Edited by madleg, 22 August 2017 - 03:31 PM.

setting integer value at given address:

int* ptr = (int*)0xAAFE8C

*ptr = 123

 

or just *(int*)0xAAFE8C = 123

  • Zeyad_Ahmed likes this

Zeyad_Ahmed
  • Zeyad_Ahmed

    Player Hater

  • Members
  • Joined: 22 Aug 2016
  • Egypt

#5

Posted 22 August 2017 - 03:32 PM

setting integer value at given address:

int* ptr = (int*)0xAAFE8C

*ptr = 123

 

or just *(int*)0xAAFE8C = 123

Thanks mate u are Awesome :)


Zeyad_Ahmed
  • Zeyad_Ahmed

    Player Hater

  • Members
  • Joined: 22 Aug 2016
  • Egypt

#6

Posted 22 August 2017 - 11:21 PM

ok well I did that code to make the health 100 forever

BOOL WINAPI VCCOOPDLL(HMODULE hModule, DWORD ul_reason_for_call, PVOID lpvReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		// DO STUFF HERE
		for (;;)
		{
			*(float*)(0x94AD28 + 0x354) = 100;
		}
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

so some people said compile that DLL and rename it into *.asi file and put it in root file of the game, i did that and the health decrease, also used cheat engine and injected the DLL and nothing happend , any help? did i do any thing wrong?

note: 0x94AD28 is CPed Pointer (Return to the player instance too) then we add 0x354 to get health and with value of float.


spaceeinstein
  • spaceeinstein

    Chocolate

  • GTA Mods Staff
  • Joined: 17 Jul 2003
  • Hong-Kong
  • Major Contribution Award [Mods]
    Helpfulness Awards [Mods]

#7

Posted 22 August 2017 - 11:55 PM Edited by spaceeinstein, 23 August 2017 - 12:07 AM.

It's much easier to use plugin-sdk if you are just modifying known values and behaviors. There are lots of examples available there.

Zeyad_Ahmed
  • Zeyad_Ahmed

    Player Hater

  • Members
  • Joined: 22 Aug 2016
  • Egypt

#8

Posted 23 August 2017 - 12:16 PM

It's much easier to use plugin-sdk if you are just modifying known values and behaviors. There are lots of examples available there.

Thanks mate that will help me, but i have to make it DLL to control it from another C++ program, hmm let me explain

well iam making a Online COOP mod for Vice City , so i will make a DLL that will be injected with values like coordinates and health to make sync later

but the problem is in the DLL what i write, i make a DLL that can be injected easily in the game and be controled like the not working example above , or to make a DLL with (WriteProcessMemory) and that can be hard and take alot of time, i hope i explained that, so question is making a DLL in C++ that can be injected and thanks mates :) <3


madleg
  • madleg

  • Members
  • Joined: 01 Jan 2014
  • None

#9

Posted 23 August 2017 - 02:43 PM Edited by madleg, 23 August 2017 - 02:44 PM.

your "hello world" is not working or will not work cause of many reasons:

VCCOOPDLL is just a function, nothing is calling it.

for (; ; ) is infinite loop and it has no break condition in your example

if 0x94ad28 is pointer to CPlayerPed, then you have to read this pointer first *(float*)(*(unsigned int*)0x94ad28 + 0x354) = 100


spaceeinstein
  • spaceeinstein

    Chocolate

  • GTA Mods Staff
  • Joined: 17 Jul 2003
  • Hong-Kong
  • Major Contribution Award [Mods]
    Helpfulness Awards [Mods]

#10

Posted 23 August 2017 - 03:07 PM

plugin-sdk still works if you're writing your code in C++. With plugin-sdk, madleg's line is equivalent to
FindPlayerPed()->m_fHealth = 100.0f;

Zeyad_Ahmed
  • Zeyad_Ahmed

    Player Hater

  • Members
  • Joined: 22 Aug 2016
  • Egypt

#11

Posted 23 August 2017 - 10:07 PM

your "hello world" is not working or will not work cause of many reasons:

VCCOOPDLL is just a function, nothing is calling it.

for (; ; ) is infinite loop and it has no break condition in your example

if 0x94ad28 is pointer to CPlayerPed, then you have to read this pointer first *(float*)(*(unsigned int*)0x94ad28 + 0x354) = 100

yea that what i want is how to call it xD

 

plugin-sdk still works if you're writing your code in C++. With plugin-sdk, madleg's line is equivalent to

FindPlayerPed()->m_fHealth = 100.0f;

Awesome mate, can i make a DLL in that SDK or it only make ASI? to be called later :D

and thanks guy for helping , i didnt even expected that , i thought that my topic will be ignored , thanks :D


DK22Pac
  • DK22Pac

    𝘉eчнo 𝘔oлoдoй...

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]
    Helpfulness Award [Mods]

#12

Posted 03 September 2017 - 05:04 PM

Yes, you can.

When project is created, go to project settings, and change target extension from ".asi" to ".dll" (for both Release and Debug modes).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users