Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- namespace GetVehicleName
- {
- class Program
- {
- struct OFFSETS
- {
- public const Int32 ClientGameContext = 0x02380B58;
- public const Int32 ClientLevel = 0x10;
- public const Int32 GameWorld = 0xC0;
- public const Int32 EntityCollection = 0x820;
- public const Int32 EntityWorld = 0x820;
- public const Int32 EntityCollectionSegment = 0x0;
- public const Int32 Entity = 0x0;
- public const Int32 ClientVehicleEntity = 0xF8;
- public const Int32 PhysicsEntity = 0x98;
- public const Int32 PhysicsEntityData = 0x20;
- public const Int32 HavokAssets = 0x0;
- public const Int32 m_name = 0x8;
- }
- static IntPtr processHandle;
- [DllImport("kernel32.dll")]
- static extern IntPtr OpenProcess(Int32 dwDesiredAccess, bool bInheritHandle, Int32 dwProcessId);
- [DllImport("kernel32.dll")]
- static extern bool CloseHandle(IntPtr handle);
- [DllImport("kernel32.dll")]
- static extern bool ReadProcessMemory(IntPtr hProcess, Int32 lpBaseAddress, byte[] lpBuffer, Int32 dwSize, out Int32 lpNumberOfBytesRead);
- static bool IsValid(Int32 address)
- {
- return (address >= -0x7FFFFFFF && address < 0x7FFFFFFF);
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Waiting for BF3 process and module (x86)....");
- Process process;
- ProcessModule processModule;
- Int32 pClientGameContext;
- while (true)
- {
- if (GetProcessByName("bf3", out process))
- {
- if (GetModuleByProcess(process, "bf3.exe", out processModule))
- {
- processHandle = OpenProcess(0x0010, false, process.Id);
- pClientGameContext = ReadInt32(OFFSETS.ClientGameContext);
- if (IsValid(pClientGameContext))
- {
- break;
- }
- CloseHandle(processHandle);
- }
- }
- Thread.Sleep(100);
- }
- Thread.Sleep(100);
- Console.WriteLine("BF3 process and module found");
- Console.WriteLine("Ready and GO!");
- while (true)
- {
- Int32 pClientLevel = ReadInt32(pClientGameContext + OFFSETS.ClientLevel);
- if (!IsValid(pClientLevel))
- {
- continue;
- }
- Int32 pGameWorld = ReadInt32(pClientLevel + OFFSETS.GameWorld);
- if (!IsValid(pGameWorld))
- {
- continue;
- }
- Int32 pEntityCollection = ReadInt32(pGameWorld + OFFSETS.EntityCollection);
- if (!IsValid(pEntityCollection))
- {
- continue;
- }
- Int32 pEntityWorld = ReadInt32(pEntityCollection + OFFSETS.EntityWorld);
- if (!IsValid(pEntityWorld))
- {
- continue;
- }
- Int32 size = ReadInt32(pEntityWorld + 0x1C);
- for (int i = 0; i < size; i++)
- {
- Int32 pEntityCollectionSegment = ReadInt32(pEntityWorld + OFFSETS.EntityCollectionSegment);
- if (!IsValid(pEntityCollectionSegment))
- {
- continue;
- }
- Int32 pEntity = ReadInt32(pEntityCollectionSegment + i * sizeof(Int32));
- if (!IsValid(pEntity))
- {
- continue;
- }
- Int32 pClientVehicleEntity = ReadInt32(pEntity + OFFSETS.ClientVehicleEntity);
- if (!IsValid(pClientVehicleEntity))
- {
- continue;
- }
- Int32 pPhysicsEntity = ReadInt32(pClientVehicleEntity + OFFSETS.PhysicsEntity);
- if (!IsValid(pPhysicsEntity))
- {
- continue;
- }
- Int32 pPhysicsEntityData = ReadInt32(pPhysicsEntity + OFFSETS.PhysicsEntityData);
- if (!IsValid(pPhysicsEntityData))
- {
- continue;
- }
- Int32 pHavokAssets = ReadInt32(pPhysicsEntityData + OFFSETS.HavokAssets);
- if (!IsValid(pHavokAssets))
- {
- continue;
- }
- Int32 pName = ReadInt32(pHavokAssets + OFFSETS.m_name);
- if (!IsValid(pName))
- {
- continue;
- }
- Console.WriteLine(ReadString(pName, 255));
- }
- Console.ReadLine();
- }
- }
- static bool GetProcessByName(string processName, out Process process)
- {
- Process[] processList = Process.GetProcessesByName(processName);
- if (processList.Length > 0)
- {
- process = processList[0];
- return true;
- }
- process = null;
- return false;
- }
- static bool GetModuleByProcess(Process process, string moduleName, out ProcessModule processModule)
- {
- foreach (ProcessModule module in process.Modules)
- {
- if (module.ModuleName == moduleName)
- {
- processModule = module;
- return true;
- }
- }
- processModule = null;
- return false;
- }
- static Int32 ReadInt32(Int32 _lpBaseAddress)
- {
- byte[] buffer = new byte[sizeof(Int32)];
- Int32 bytesRead = 0;
- ReadProcessMemory(processHandle, _lpBaseAddress, buffer, buffer.Length, out bytesRead);
- return BitConverter.ToInt32(buffer, 0);
- }
- static string ReadString(Int32 _lpBaseAddress, Int32 _Size)
- {
- byte[] buffer = new byte[_Size];
- Int32 bytesRead = 0;
- ReadProcessMemory(processHandle, _lpBaseAddress, buffer, _Size, out bytesRead);
- for (int i = 0; i < buffer.Length; i++)
- {
- if (buffer[i] == 0)
- {
- byte[] _buffer = new byte[i];
- Buffer.BlockCopy(buffer, 0, _buffer, 0, i);
- return Encoding.ASCII.GetString(_buffer);
- }
- }
- return Encoding.ASCII.GetString(buffer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement