 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
lolAnonymous Expert Cheater
Reputation: 1
Joined: 19 Jul 2015 Posts: 154
|
Posted: Sun Jun 05, 2016 7:25 am Post subject: C# Find Process (Help) |
|
|
Hello I am new to C# so someone can please tell me where to put the process name in this script :-
| Code: | using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
//Helper_news.cs
namespace HelperTools
{
/// <summary>
/// Game memory code tool
/// </summary>
class Helper
{
/// <summary>
/// Process DLL names do not need to leave this blank.
/// </summary>
private static readonly string moduleName = "";
/// <summary>
/// Process game name
/// </summary>
private static readonly string gameName = "Marmalade.App";
private static readonly string logo = "";
//--------------Defined constants---------------------------
private const int MEM_COMMIT = 0x1000;
private const int MEM_RELEASE = 0x8000;
private const int PAGE_EXECUTE_READWRITE = 0x00000040;
private const int PROCESS_ALL_ACCESS = 0x1F0FFF;
#region (For internal use) from API: OpenProcess--CloseHandle--ReadProcessMemory--WriteProcessMemory--VirtualAllocEx--VirtualFreeEx
/// <summary>
/// Open process, returns the process handle
/// </summary>
/// <param name="dwDesiredAccess"></param>
/// <param name="bInheritHandle"></param>
/// <param name="dwProcessId"></param>
/// <returns></returns>
[DllImportAttribute("kernel32.dll", EntryPoint = "OpenProcess")]
private static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
/// <summary>
/// Close process handle
/// </summary>
/// <param name="hObject"></param>
[DllImportAttribute("kernel32.dll", EntryPoint = "CloseHandle")]
private static extern void CloseHandle(IntPtr hObject);
/// <summary>
/// Read process memory
/// </summary>
/// <param name="hProcess"></param>
/// <param name="lpBaseAddress"></param>
/// <param name="lpBuffer"></param>
/// <param name="nSize"></param>
/// <param name="lpNumberOfBytesRead">数据的实际大小</param>
/// <returns></returns>
[DllImportAttribute("kernel32.dll", EntryPoint = "ReadProcessMemory")]
private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress
, IntPtr lpBuffer, int nSize, IntPtr lpNumberOfBytesRead);
/// <summary>
/// WriteProcessMemory
/// </summary>
/// <param name="process"></param>
/// <param name="baseAddress"></param>
/// <param name="buffer"></param>
/// <param name="nSize"></param>
/// <param name="lpNumberOfBytesWritten"></param>
/// <returns></returns>
[DllImportAttribute("kernel32.dll", EntryPoint = "WriteProcessMemory")]
private static extern bool WriteProcessMemory(IntPtr process, IntPtr baseAddress
, byte[] buffer, int nSize, IntPtr lpNumberOfBytesWritten);
/// <summary>
/// VirtualAllocEx(Function returns the first address of the allocated memory.)
/// </summary>
/// <param name="hwnd"></param>
/// <param name="lpAddress"></param>
/// <param name="dwSize">0</param>
/// <param name="flAllocationType">MEM_COMMIT</param>
/// <param name="flProtect"></param>
/// <returns></returns>
[DllImportAttribute("kernel32.dll", EntryPoint = "VirtualAllocEx")]
private static extern IntPtr VirtualAllocEx(IntPtr hwnd, IntPtr lpAddress, int dwSize, int flAllocationType, int flProtect);
/// <summary>
/// VirtualFreeEx
/// </summary>
/// <param name="hwnd"></param>
/// <param name="lpAddress"></param>
/// <param name="dwSize"></param>
/// <param name="flAllocationType"></param>
/// <returns></returns>
[DllImportAttribute("kernel32.dll", EntryPoint = "VirtualFreeEx")]
private static extern int VirtualFreeEx(IntPtr hwnd, IntPtr lpAddress, int dwSize, int flAllocationType);
#endregion
#region Custom auxiliary function: --GetProcessByName--ArrayJoin--GetErrorMessage--
/// <summary>
/// return Process Group of the process name (include PID, process, address MainModule.BaseAddress)
/// </summary>
/// <param name="_processName">processName</param>
/// <returns></returns>
public static Process GetProcessByName(string _processName)
{
Process[] processArray = Process.GetProcessesByName(_processName);
int index = 0;
while (index < processArray.Length)
{
return processArray[index];
}
return null;
}
/// <summary>
/// ((For internal use)Get the DLL information group
/// </summary>
/// <param name="_myPrcess"></param>
/// <param name="_moduleName">dllName</param>
/// <returns></returns>
private static ProcessModule GetProcessModule(Process _myPrcess, string _moduleName)
{
_moduleName = _moduleName.Trim();
foreach (ProcessModule module in _myPrcess.Modules)
{
if (_moduleName == module.ModuleName)
{
return module;
}
}
return null;
}
/// <summary>
/// Merge two arrays of bytes and returns the new byte array in the first array.
/// </summary>
/// <param name="_byteArrayOne">first array</param>
/// <param name="_byteArrayTwo">second array</param>
public static void MergeArray(ref byte[] _byteArrayOne, byte[] _byteArrayTwo)
{
if (_byteArrayTwo.Length != 0)
{
byte[] array = new byte[_byteArrayOne.Length + _byteArrayTwo.Length];
_byteArrayOne.CopyTo(array, 0);
_byteArrayTwo.CopyTo(array, _byteArrayOne.Length);
_byteArrayOne = new byte[0];
_byteArrayOne = array;
}
}
public static void SetCheckBoxColor(CheckBox _myCheckBox,TextBlock _myTextBlock,int _errorCode)
{
if (_myCheckBox.IsChecked.Value == true)
{
_myCheckBox.Foreground = Brushes.Red;
_myCheckBox.FontStyle = FontStyles.Italic;
// _myTextBlock.Text = GetErrorMessage(_errorCode);
_myTextBlock.Text = GetErrorMessage(_errorCode) + "< " + _myCheckBox.Content + " > start!";
_myTextBlock.Foreground = Brushes.Black;
}
else
{
_myCheckBox.Foreground = Brushes.Black;
_myCheckBox.FontStyle = FontStyles.Normal;
// _myTextBlock.Text = GetErrorMessage(_errorCode);
_myTextBlock.Text = GetErrorMessage(_errorCode) + "< " + _myCheckBox.Content + " > stop!";
_myTextBlock.Foreground = Brushes.Red;
}
}
/// <summary>
/// (For internal use)Replace the byte array. Replacement array returned successfully, failed return an empty array.
/// </summary>
/// <param name="_sourceByteArray">source data</param>
/// <param name="_oldValue">replace data</param>
/// <param name="_newValue">Be replaced with data</param>
/// <returns></returns>
private static byte[] ReplaceByte(byte[] _sourceByteArray, byte[] _oldValue, byte[] _newValue)
{
if (_oldValue.Length != _newValue.Length)
{
return new byte[0];
}
if (_sourceByteArray.Length <= _newValue.Length)
{
return new byte[0];
}
string outText = BitConverter.ToString(_sourceByteArray).Replace("-", "");
string oldValue = BitConverter.ToString(_oldValue).Replace("-", "");
string newValue = BitConverter.ToString(_newValue).Replace("-", "");
outText = outText.Replace(oldValue, newValue);
string str;
byte[] aNum = new byte[_sourceByteArray.Length];
try
{
for (int i = 0; i < _sourceByteArray.Length; i++)
{
str = outText.Substring(i * 2, 2);
//byte num = Convert.ToByte(str, 16);
aNum[i] = Convert.ToByte(str, 16);
}
}
catch (Exception)
{
return new byte[0];
}
return aNum;
}
/// <summary> GetErrorMessage
/// GetErrorMessage
/// </summary>
/// <param name="_errorCode">error code</param>
/// <returns></returns>
public static string GetErrorMessage(int _errorCode)
{
string errorMessage;
switch (_errorCode)
{
case 0:
errorMessage = "< Unknown error >";
break;
case -1:
errorMessage = "< Didn't find the game process >";
break;
case -2:
errorMessage = "< Failed to open the game >";
break;
case -3:
errorMessage = "< Application memory failure >";
break;
case -4:
errorMessage = "< Application address space is empty, failed to release >";
break;
case -5:
errorMessage = "< Failed to free application memory space >";
break;
case -6:
errorMessage = "< Object code recovery failed >";
break;
case -7:
errorMessage = "< Application code space write failed >";
break;
case -8:
errorMessage = "< Object code write failed>";
break;
case -9:
errorMessage = "< Read failed! Could not find the target code>";
break;
case -10:
errorMessage = "< Failed to write to the target data>";
break;
case -11:
errorMessage = "< Special wrote: integration code to fail >";
break;
default:
//errorMessage = "";
errorMessage = logo;
break;
}
return errorMessage;
}
#endregion
#region Injects code, rewrite code.
/// <summary>ApplyMyAddress
/// (For internal use)Application memory space in the process, successfully returned for the memory address,failed return error code.
/// </summary>
/// <param name="_myProcess">/param>
/// <returns></returns>
private static IntPtr ApplyMyAddress(Process _myProcess)
{
IntPtr hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, _myProcess.Id);
if (hProcess == IntPtr.Zero)
{
return ((IntPtr)(-2));
}
IntPtr virtualBaseAddress = VirtualAllocEx(hProcess, IntPtr.Zero, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
CloseHandle(hProcess);
if (virtualBaseAddress == IntPtr.Zero) { return ((IntPtr)(-3)); }
return virtualBaseAddress;
}
/// <summary> FreeMyAddress
/// (For internal use)FreeMyAddress ,100 returned successfully,failed return error code.
/// </summary>
/// <param name="_myProcess"></param>
/// <param name="_virtualBaseAddress"></param>
/// <returns></returns>
private static int FreeMyAddress(Process _myProcess, IntPtr _virtualBaseAddress)
{
IntPtr hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, _myProcess.Id); //PROCESS_ALL_ACCESS==0x1F0FFF
if (hProcess == IntPtr.Zero) { return (-2); }
int ok = VirtualFreeEx(hProcess, _virtualBaseAddress, 0, MEM_RELEASE);
// Console.WriteLine("hProcess==" + hProcess);
CloseHandle(hProcess);
if (ok == 0)
{
//Console.WriteLine("free failed");
return (-5);
}
return (100);
}
#region Injects code--<WriteCode>--<RecoveryCode>--------------start-------------------------
/// <summary>
/// (For internal use)Check for the injected code, fails return error code.
/// </summary>
/// <param name="_myProcess"></param>
/// <param name="_gameVlue">Custom data types</param>
/// <param name="_isWrite">true:Check writing code;false:Check the recovery code</param>
/// <returns></returns>
private static int CheckedCode(Process _myProcess, ref GameInjectVariable _gameVlue, bool _isWrite)
{
if (_gameVlue.CZOffset > 0x0)
{
if (false== CZCode(_myProcess, ref _gameVlue))
{
//Integration code to fail
return -11;
}
}
//Read the target space code
byte[] readCode = ReadMemoryByteValue(_gameVlue.jmpOffset, _gameVlue.jmpRecovery.Length, _myProcess);
string tmp;
//Check writing code
if (_isWrite)
{
tmp = BitConverter.ToString(_gameVlue.jmpRecovery);
}
//Check recovery code
else
{
/* Similar calls:
push rax
mov rax,xxxxxxxxxx
call rax
pop rax
*/
byte[] tmpValueOne = _gameVlue.jmpStart;
byte[] tmpValueTwo=new byte[0];
//64-bit Size equal to 8, 32-bit Size equal to 4
if (IntPtr.Size == 8)
{
tmpValueTwo = BitConverter.GetBytes((long)_gameVlue.applyTopAddress);
}
else
{
tmpValueTwo = BitConverter.GetBytes((int)_gameVlue.applyTopAddress);
}
MergeArray(ref tmpValueOne, tmpValueTwo);
MergeArray(ref tmpValueOne, _gameVlue.jmpEnd);
tmp = BitConverter.ToString(tmpValueOne);
}
//Determine whether the code is readCode code
if (BitConverter.ToString(readCode) != tmp)
{
// errorMessage = "< Read failed! Could not find the target code>!!!";
return -9;
}
return 100;
}
/// <summary>
/// (For internal use)Replace the code in the special address
/// </summary>
/// <param name="_myProcess"></param>
/// <param name="_game"></param>
/// <returns></returns>
private static bool CZCode(Process _myProcess,ref GameInjectVariable _game)
{
_game.PID = _myProcess.Id;
byte[] oldByte = new byte[0];
byte[] newByte = new byte[0];
//will write value address
IntPtr newAddress = IntPtr.Add(_myProcess.MainModule.BaseAddress, _game.CZOffset);
if (IntPtr.Size == 4)
{
oldByte = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF };
newByte = BitConverter.GetBytes((int)newAddress);
}
else
{
oldByte = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
newByte = BitConverter.GetBytes((long)newAddress);
}
_game.jmpRecovery = (ReplaceByte(_game.jmpRecovery, oldByte, newByte));
if (_game.jmpRecovery==null)
{
return false;
}
_game.applyCode=(ReplaceByte(_game.applyCode, oldByte, newByte));
if (_game.applyCode ==null)
{
return false;
}
return true;
}
/// <summary>
/// Writing code and application memory space. successfully return the number 100, failed return a negative number.。GetErrorMessage(-1)
/// </summary>
/// <param name="_game">Custom data types</param>
/// <returns></returns>
public static int WriteCode(ref GameInjectVariable _game)
{
Process myProcess = GetProcessByName(gameName);
if (myProcess == null) { return (-1); }
//check the target code
int errorCode = CheckedCode(myProcess, ref _game, true);
if (errorCode <= 0) { return errorCode; }
//Application memory space
_game.applyTopAddress = ApplyMyAddress(myProcess);
if (((long)_game.applyTopAddress) <= 0L) { return ((int)_game.applyTopAddress); }
// Console.WriteLine("topAddress==" + _game.applyTopAddress.ToString("X2"));
//Writes code, in application memory space
bool ok = WriteMemoryByteValue(_game.applyTopAddress, _game.applyCode, myProcess.Id);
if (!ok)
{
//Failed,free memory
FreeMyAddress(myProcess, _game.applyTopAddress);
return (-7);
}
//Combination jump code
byte[] tmpValue=new byte[0];
//64-bit Size equal to 8, 32-bit Size equal to 4
if (IntPtr.Size==8)
{
tmpValue = BitConverter.GetBytes((long)_game.applyTopAddress);
}
else
{
tmpValue = BitConverter.GetBytes((int)_game.applyTopAddress);
}
MergeArray(ref _game.jmpStart, tmpValue);
MergeArray(ref _game.jmpStart, _game.jmpEnd);
//write code
ok = WriteMemoryByteValue(_game.jmpOffset, _game.jmpStart, myProcess);
if (!ok)
{
//Failed,free memory
FreeMyAddress(myProcess, _game.applyTopAddress);
return (-8);
}
// Console.WriteLine("code write oky!");
return 100;
}
/// <summary>
/// Restore code and free memory space. successfully return the number 100, failed return a negative number.。GetErrorMessage(-1)
/// </summary>
/// <param name="_game">Custom data types</param>
/// <returns></returns>
public static int RecoveryCode(ref GameInjectVariable _game)
{
Process myProcess = GetProcessByName(gameName);
if (myProcess == null) { return (-1); }
//check the target code
int tmp = CheckedCode(myProcess,ref _game, false);
if (tmp < 0) { return tmp; }
//Write the recovery code
bool ok = WriteMemoryByteValue(_game.jmpOffset, _game.jmpRecovery, myProcess);
if (!ok) { return (-6); }
//Testing release address is empty
if (_game.applyTopAddress == IntPtr.Zero) { return (-4); }
//Free up space applications
int ok1 = FreeMyAddress(myProcess, _game.applyTopAddress);
if (ok1 < 0) { return (-5); }
return 100;
}
#endregion Injects code--<WriteCode>--<RecoveryCode>--------------end-------------------------
#region Rewriting code----<WriteCode>--<RecoveryCode>--------------start-------------------------
/// <summary>
/// (For internal use)Check for the rewriting code, fails return error code.
/// </summary>
/// <param name="_myProcess"></param>
/// <param name="_gameVlue">Custom data types</param>
/// <param name="_isWrite">true:Check writing code;false:Check the recovery code</param>
/// <returns></returns>
private static int CheckedCode(Process _myProcess, GameRewriteVariable _gameVlue, bool _isWrite)
{
//Read the target space code
byte[] readCode = ReadMemoryByteValue(_gameVlue.offset, _gameVlue.recoveryCode.Length, _myProcess);
string tmp;
//check write code
if (_isWrite)
{
tmp = BitConverter.ToString(_gameVlue.recoveryCode);
}
//Check recovery code
else
{
tmp = BitConverter.ToString(_gameVlue.writeCode);
}
//Determine whether the code is readCode code
if (BitConverter.ToString(readCode) != tmp)
{
// errorMessage = "< Read failed! Could not find the target code>!!!";
return -9;
}
return 100;
}
/// <summary>
/// Rewriting code
/// </summary>
/// <param name="_game">Custom data types</param>
/// <returns></returns>
public static int WriteCode(ref GameRewriteVariable _game)
{
Process myProcess = GetProcessByName(gameName);
if (myProcess == null) { return (-1); }
//Check the target code
int tmp = CheckedCode(myProcess, _game, true);
if (tmp < 0) { return tmp; }
//write code
bool ok = WriteMemoryByteValue(_game.offset, _game.writeCode, myProcess);
if (!ok) { return (-8); }
return 100;
}
/// <summary>
/// RecoveryCode
/// </summary>
/// <param name="_game">Custom data types</param>
/// <returns></returns>
public static int RecoveryCode(ref GameRewriteVariable _game)
{
Process myProcess = GetProcessByName(gameName);
if (myProcess == null) { return (-1); }
int tmp = CheckedCode(myProcess, _game, false);
if (tmp < 0) { return tmp; }
bool ok = WriteMemoryByteValue(_game.offset, _game.recoveryCode, myProcess);
if (!ok) { return (-6); }
return 100;
}
#endregion ------------------end-------------------------
/// <summary>
/// Write data base address;According to the offset. Writing DLL needs to specify the DLL name.
/// </summary>
/// <param name="_offset">In turn all offset collection</param>
/// <param name="_value">Numeric value to be written</param>
/// <param name="isSetAdd">True: increase _value numerical; false: write _value numerical</param>
/// <returns></returns>
public static int WriteCode(int[] _offset, int _value,bool isSetAdd)
{
/*
like : gameName.exe+123456[+10[+A[+B]]]
int[] offset=new int[4];
offset[0] = 0x123456;
offset[1] = 0x10;
offset[2] = 0xA;
offset[3] = 0xB;
if like: gameDllName+123456[+10[+A[+B]]]
You need to set:
moduleName = "gameDllName";
*/
//Get process information group
Process myProcess = GetProcessByName(gameName);
if (myProcess == null) {return -1;}
IntPtr baseAddress;
if (moduleName!="")
{
//In the process of acquiring DLL base address
ProcessModule myModule = GetProcessModule(myProcess, moduleName);
if (myModule == null) { return -1; }
baseAddress =myModule.BaseAddress;
}
else
{
//Get process top address
baseAddress = myProcess.MainModule.BaseAddress;
}
//According to the offset loop reads the address
for (int i = 0; i < _offset.Length - 1; i++)
{
baseAddress = IntPtr.Add(baseAddress, _offset[i]);
baseAddress = ReadMemoryValue(baseAddress, myProcess.Id);
if (baseAddress ==IntPtr.Zero)
{
return -9;
}
}
//Obtains the address of the last data
baseAddress = IntPtr.Add(baseAddress, _offset[_offset.Length-1]);
//isSetAdd==true
if (isSetAdd)
{
//Read the original value
byte[] address = ReadMemoryValue(baseAddress, myProcess.Id, 4);
if (address == new byte[0]) { return -9; }
//Cumulative values
_value += BitConverter.ToInt32(address, 0);
}
//write value
bool ok = WriteMemoryByteValue(baseAddress, BitConverter.GetBytes(_value), myProcess.Id);
if (!ok)
{
return -10;
}
return 100;
}
#endregion
#region (For internal use) reading and writing memory data : ReadMemoryValue、WriteMemoryValue
/// <summary>
/// (For internal use)Read 4 bytes of memory data (according to the memory address). Successfully returned a non-zero value, failed will return zero.
/// </summary>
/// <param name="_baseAddress"></param>
/// <param name="_PID">Process PID</param>
/// <returns></returns>
private static IntPtr ReadMemoryValue(IntPtr _baseAddress, int _PID)
{
try
{
byte[] buffer = new byte[4];
IntPtr byteAddress = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); //Gets the buffer address
IntPtr hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, _PID);//0x1F0FFF
if ((int)hProcess <= 0) { return IntPtr.Zero; }
ReadProcessMemory(hProcess, _baseAddress, byteAddress, 4, IntPtr.Zero);
CloseHandle(hProcess);
return Marshal.ReadIntPtr(byteAddress);
}
catch
{
return IntPtr.Zero;
}
}
/// <summary>
/// (internal use)Returns data read bytes (according to memory addresses, you need to set read lengths). Successfully returned a non-zero-byte array, failed will return zero byte array.
/// </summary>
/// <param name="_baseAddress"></param>
/// <param name="_PID"></param>
/// <param name="_nSize"></param>
/// <returns></returns>
private static byte[] ReadMemoryValue(IntPtr _baseAddress, int _PID, int _nSize)
{
try
{
byte[] buffer = new byte[_nSize];
IntPtr byteAddress = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
IntPtr hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, _PID);
if ((int)hProcess <= 0) { return new byte[0]; }
ReadProcessMemory(hProcess, _baseAddress, byteAddress, _nSize, IntPtr.Zero);
CloseHandle(hProcess);
return buffer;
}
catch
{
return new byte[0];
}
}
/// <summary> ReadMemoryByteValue
/// (internal use)read bytes of data (according to the offset, process DLL data that can be read).Successfully returned a non-zero-byte array, failed will return zero byte array.
/// </summary>
/// <param name="_offset"></param>
/// <param name="_nSize"></param>
/// <param name="_myProcess"></param>
/// <returns></returns>
private static byte[] ReadMemoryByteValue(int _offset, int _nSize, Process _myProcess)
{
try
{
IntPtr baseAddress;
if (moduleName!="")
{
//get base address of the DLL in the process.
ProcessModule myModule = GetProcessModule(_myProcess, moduleName);
if (myModule == null) { return new byte[0]; }
baseAddress =IntPtr.Add( myModule.BaseAddress,_offset);
}
else
{
baseAddress =IntPtr.Add( _myProcess.MainModule.BaseAddress,_offset);
}
byte[] buffer = new byte[_nSize];
IntPtr byteAddress = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
IntPtr hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, _myProcess.Id);
if ((int)hProcess <= 0) { return new byte[0]; }
ReadProcessMemory(hProcess, baseAddress, byteAddress, _nSize, IntPtr.Zero);
CloseHandle(hProcess);
return buffer;
}
catch
{
return (new byte[0]);
}
}
/// <summary>
/// (internal use)Write the memory byte (based on the offset, can be written in the process Dll), success returns true, else return false
/// </summary>
/// <param name="_offset"></param>
/// <param name="_value"></param>
/// <param name="_myProcess"></param>
/// <returns></returns>
private static bool WriteMemoryByteValue(int _offset, byte[] _value, Process _myProcess)
{
if (_myProcess == null) { return false; }
try
{
IntPtr baseAddress;
if (moduleName != "")
{
//get base address of the DLL in the process.
ProcessModule myModule = GetProcessModule(_myProcess, moduleName);
if (myModule == null) { return false; }
baseAddress = IntPtr.Add(myModule.BaseAddress, _offset);
}
else
{
baseAddress = IntPtr.Add(_myProcess.MainModule.BaseAddress, _offset);
}
IntPtr hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, _myProcess.Id);
if ((int)hProcess <= 0) { return false; }
bool ok = WriteProcessMemory(hProcess, baseAddress, _value, _value.Length, IntPtr.Zero);
CloseHandle(hProcess);
return ok;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// (internal use)Write the memory byte(according to the memory address) ,success returns true, else return false
/// </summary>
/// <param name="_baseAddress"></param>
/// <param name="_value"></param>
/// <param name="_PID"></param>
/// <returns></returns>
private static bool WriteMemoryByteValue(IntPtr _baseAddress, byte[] _value, int _PID)
{
try
{
IntPtr hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, _PID); //0x1F0FFF
if ((int)hProcess <= 0) { return false; }
bool ok = WriteProcessMemory(hProcess, _baseAddress, _value, _value.Length, IntPtr.Zero);
CloseHandle(hProcess);
return ok;
}
catch (Exception)
{
return false;
}
}
#endregion
}
/// <summary>
/// Inject code data type
/// </summary>
public struct GameInjectVariable
{
/// <summary>
/// Restructured code offset
/// </summary>
public int CZOffset;
/// <summary>
/// Application of address space, automatic acquisition, internal use
/// </summary>
public IntPtr applyTopAddress;
/// <summary>
/// Apply for a space to write the set of code bytes and ending with Ret
/// </summary>
public byte[] applyCode;
/// <summary>
/// Process PID, automatic acquisition, internal use
/// </summary>
public int PID;
/// <summary>
/// Modify the code Office offset
/// </summary>
public int jmpOffset;
/// <summary>
/// Code byte set (start section)
/// </summary>
public byte[] jmpStart;
/// <summary>
/// Code byte set (end section)
/// </summary>
public byte[] jmpEnd;
/// <summary>
/// Code byte set for recovery
/// </summary>
public byte[] jmpRecovery;
}
/// <summary>
/// Rewrite code data type
/// </summary>
public struct GameRewriteVariable
{
/// <summary>
/// Modify the code Office offset
/// </summary>
public int offset;
/// <summary>
/// write code
/// </summary>
public byte[] writeCode;
/// <summary>
/// recovery Code
/// </summary>
public byte[] recoveryCode;
// public int size;
}
}
|
Thanks In Advance
|
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Jun 05, 2016 8:49 am Post subject: |
|
|
May want to try learning the language if you couldn't find this.
| Code: | | private static readonly string gameName = "Marmalade.App"; |
|
|
| Back to top |
|
 |
lolAnonymous Expert Cheater
Reputation: 1
Joined: 19 Jul 2015 Posts: 154
|
Posted: Sun Jun 05, 2016 9:38 am Post subject: |
|
|
Hmmm... I changed that but it still not working... It is saying u have to attach to the game...
Zanzer can u help me ,I will send u the whole source code and can u tell me what Is wrong...
Can I pm u? Reply please...
|
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Jun 05, 2016 10:04 am Post subject: |
|
|
| Sure... let's see what you've got.
|
|
| Back to top |
|
 |
lolAnonymous Expert Cheater
Reputation: 1
Joined: 19 Jul 2015 Posts: 154
|
Posted: Sun Jun 05, 2016 10:19 am Post subject: |
|
|
| lol we are not going in a battle.. Zanzer relax... I sent u the pm...
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|