Convert C++ To C#

Posts 1–8 of 8 · Page 1 of 1
Convert C++ To C#
Can someone convert this, I dont have experience with C++

DWORD SF = (DWORD)GetModuleHnalde("game.exe");
Dword Speed = SF + 0x798F80;

DWORD WINAPI SpeedHack(void*)
{
while (true)
{
(*(PBYTE)(Speed)) = 0;
Sleep(100)
}
}

BOOL APIENTRY DLLMain(HMODULE hm, DWORD rr, DWORD re)
{
if (rr == DLL_PROCESS_ATTACK)
{
CreateThread(0,0, SpeedHack, 0, 0, 0);
}
}
Quote Originally Posted by DaniielSanchez View Post
What is this game?
specialforce.exe
You're going to need a few kernel functions defined... OpenProcess, WriteProcessMemory, and some kind of GetModuleBaseAddress function.
GetModuleBaseAddress <---- Search for this in C# or vb.net.

:::: EXPLANATION OF YOUR CODE ::::
  1. You read module address
  2. You add the offset to pointer
  3. Then you write 0 to that added address.
  4. After all, you pause then loop. (basic functionality)

And its pretty easy (as long as you know a bit of c#)

processhandle is a intptr.
processID as int32

Code:
processID = system.diagnostics.process.getprocessesbyname("skype")(0).Id;
^^^^ I'm not sure about caps. Im just using what i know from memory

OpenProcess(processhandle, false, 0x43A);
processhandle is an empty intptr that you are going to fill in
false is the parameter to not inherit handle into process
0x43A is some random access that has everything to need (WPM/RPM/Allocation/Protection) I use this instead of PROCESS_ALL_ACCESS for detection

Now you will get module address:
SF is a Int32.
SF = GetModuleBaseAddress("processname", "game.exe");
GetModuleBaseAddress is a function that is not declared. Find this on google somewhere. Must be able to search modules in another process

Speed is a Int32.
Speed = SF + 0x798F80;

Now for writing you can simple use
WriteByte(ProcessHandle, Speed, 0);

Write Byte function params : Int32, Int32, Byte

and function consists of:

Byte oBuffer[1] = {wrteByte};

WriteProcessMemory(pHandle, wrteByte, obuffer, 1, null);

MSDN Definitions :

Code:
HANDLE WINAPI OpenProcess(
  _In_ DWORD dwDesiredAccess,
  _In_ BOOL  bInheritHandle,
  _In_ DWORD dwProcessId
);
Code:
BOOL WINAPI WriteProcessMemory(
  _In_  HANDLE  hProcess,
  _In_  LPVOID  lpBaseAddress,
  _In_  LPCVOID lpBuffer,
  _In_  SIZE_T  nSize,
  _Out_ SIZE_T  *lpNumberOfBytesWritten
);

I went ahead and found a working example of how to make your own GetModuleBaseAddress


Code:
Process[] ProcessList = System.Diagnostics.Process.GetProcessByName("skype");
IntPtr 
 
if (ProcessList.Length > 0
{
	Process MYPROCESS = ProcessList[0];
	IntPtr BaseAddress = IntPtr.Zero;
 
	foreach (System.Diagnostics.ProcessModule Module in MYPROCESS.Modules)
	{
		if (Module.ModuleName.ToLower.Contains("game.exe"))
			BaseAddress = Module.BaseAddress;
	}
 
	if (BaseAddress != IntPtr.Zero)
	{
		// No Module
	}
}
Note : Make sure to run your app as x86 though, or else you will only receive a the x64 modules if you are on a x64 machine.
Quote Originally Posted by Nine11 View Post
You're going to need a few kernel functions defined... OpenProcess, WriteProcessMemory, and some kind of GetModuleBaseAddress function.
GetModuleBaseAddress <---- Search for this in C# or vb.net.

:::: EXPLANATION OF YOUR CODE ::::
  1. You read module address
  2. You add the offset to pointer
  3. Then you write 0 to that added address.
  4. After all, you pause then loop. (basic functionality)

And its pretty easy (as long as you know a bit of c#)

processhandle is a intptr.
processID as int32

Code:
processID = system.diagnostics.process.getprocessesbyname("skype")(0).Id;
^^^^ I'm not sure about caps. Im just using what i know from memory

OpenProcess(processhandle, false, 0x43A);
processhandle is an empty intptr that you are going to fill in
false is the parameter to not inherit handle into process
0x43A is some random access that has everything to need (WPM/RPM/Allocation/Protection) I use this instead of PROCESS_ALL_ACCESS for detection

Now you will get module address:
SF is a Int32.
SF = GetModuleBaseAddress("processname", "game.exe");
GetModuleBaseAddress is a function that is not declared. Find this on google somewhere. Must be able to search modules in another process

Speed is a Int32.
Speed = SF + 0x798F80;

Now for writing you can simple use
WriteByte(ProcessHandle, Speed, 0);

Write Byte function params : Int32, Int32, Byte

and function consists of:

Byte oBuffer[1] = {wrteByte};

WriteProcessMemory(pHandle, wrteByte, obuffer, 1, null);

MSDN Definitions :

Code:
HANDLE WINAPI OpenProcess(
  _In_ DWORD dwDesiredAccess,
  _In_ BOOL  bInheritHandle,
  _In_ DWORD dwProcessId
);
Code:
BOOL WINAPI WriteProcessMemory(
  _In_  HANDLE  hProcess,
  _In_  LPVOID  lpBaseAddress,
  _In_  LPCVOID lpBuffer,
  _In_  SIZE_T  nSize,
  _Out_ SIZE_T  *lpNumberOfBytesWritten
);

I went ahead and found a working example of how to make your own GetModuleBaseAddress


Code:
Process[] ProcessList = System.Diagnostics.Process.GetProcessByName("skype");
IntPtr 
 
if (ProcessList.Length > 0
{
	Process MYPROCESS = ProcessList[0];
	IntPtr BaseAddress = IntPtr.Zero;
 
	foreach (System.Diagnostics.ProcessModule Module in MYPROCESS.Modules)
	{
		if (Module.ModuleName.ToLower.Contains("game.exe"))
			BaseAddress = Module.BaseAddress;
	}
 
	if (BaseAddress != IntPtr.Zero)
	{
		// No Module
	}
}
Note : Make sure to run your app as x86 though, or else you will only receive a the x64 modules if you are on a x64 machine.
Oh thanks I get it know.
DllMain.
I guess you can't inject c# DLL to other process
Quote Originally Posted by Zaczero View Post
DllMain.
I guess you can't inject c# DLL to other process
No many sorry, I thought you wanted externally.

What you wanting is still possible, except it requires a special type of injector. It requires a CLR injector. It loads the needed modules into the target process, then loads the c#/vb .net dll and calls the function that looks like dllmain. You can then use marshal library to read/write memory or readprocessmemory local.

This works great :
http://www.mpgh.net/forum/showthread.php?t=450105
Is that possible or maybe I dont get what you mean?
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us