public void TestFreeMemory() { var regionAddress = _memoryModule.AllocateVirtualMemory(sizeof(int)); _memoryModule.FreeVirtualMemory(regionAddress); Assert.Throws <Win32Exception>(() => _memoryModule.ReadVirtualMemory <int>(regionAddress)); }
public override bool canWrite() { byte[] bytes = memoryModule.ReadVirtualMemory(bufferAddress + writeOffset, 4); unsafe { fixed(byte *ptr = bytes) { int *int_ptr = (int *)ptr; return(int_ptr[0] == 1); } } }
public ExternalCommunicationBuffer() : base(MAGIC_NUMBER_BYTE_LENGTH + HEADER_BYTE_LENGTH + DATA_BYTE_LENGTH, MAGIC_NUMBER_BYTE_LENGTH) { this.memoryModule = new MemoryModule("TS3"); //The buffer tends to be after this address, so use this for quicker searching. Not guaranteed. To be replaced with actual pointer mapping later on //List<IntPtr> addresses = memoryModule.PatternScan(new IntPtr(0x20000000), BUFFER_MAGIC_NUMBERS).ToList(); //if (addresses.Count != 1) { // //Error handle??? //} //this.bufferAddress = addresses.ElementAt(0); //Console.WriteLine("Buffer Address: {0:x}", bufferAddress.ToInt32()); //From Cheat Engine investigation int baseAddress = 0x00400000; int baseOffset = 0x00E1D89C; //Using the path from cheat engine, navigate the pointers to our buffer (hopefully) List <int> offsets = new List <int> { 0x18, 0x24, 0x1e0, 0x1c, 0x1c, 0x1c, 0x18, 0x1c, 0x10 }; int address = baseAddress + baseOffset; foreach (int offset in offsets) { address = BitConverter.ToInt32(memoryModule.ReadVirtualMemory(new IntPtr(address), 4), 0) + offset; } Console.WriteLine("Buffer Address: {0:x}", address); bufferAddress = new IntPtr(address); //Make sure that the pointer has actually given us the buffer byte[] toCompare = memoryModule.ReadVirtualMemory(bufferAddress, BUFFER_MAGIC_NUMBERS.Length); bool equal = Enumerable.SequenceEqual(BUFFER_MAGIC_NUMBERS, toCompare); if (!equal) { Console.WriteLine("Big boi error time! The bytes at the found address are not correct!"); System.Environment.Exit(-1); } }
public void TestManualMap() { using (var injector = new Injector(_process.Id, _dllPath, InjectionMethod.ManualMap)) { using (var memoryModule = new MemoryModule(_process.Id)) { var firstTwoBytes = memoryModule.ReadVirtualMemory(injector.InjectDll(), 2); Assert.Equal(firstTwoBytes, new byte[] { 0x4D, 0x5A }); } } }