Beispiel #1
0
        private static unsafe IntPtr ScanByPattern(this MvProcess process, IntPtr baseAddress, long size, PatternElement[] patternAsArray)
        {
            fixed(PatternElement *pattern = patternAsArray)
            {
                fixed(byte *dump = Read(process.Pointer, baseAddress, (uint)size, out _))
                {
                    var first       = patternAsArray[0].Byte;
                    var patternSize = patternAsArray.Length;

                    for (var i = 0; i < size; i++)
                    {
                        if (first != *(dump + i))
                        {
                            continue;
                        }
                        var hasFound = true;
                        for (var j = 1; j < patternSize; j++)
                        {
                            if ((pattern + j)->Byte != *(dump + i + (pattern + j)->Offset))
                            {
                                hasFound = false;
                                break;
                            }
                        }
                        if (hasFound)
                        {
                            return(baseAddress + i);
                        }
                    }
                }
            }

            return(IntPtr.Zero);
        }
Beispiel #2
0
 public static long GetModuleAddressByName(this MvProcess process, string moduleName)
 {
     return(process.GetModuleByName(moduleName)
            .SomeNotNull()
            .Map(x => (long)x.BaseAddress)
            .ValueOr(() => 0));
 }
Beispiel #3
0
 public static Vector3 ReadVector2(this MvProcess process, long address)
 {
     return(new Vector2
     {
         x = BitConverter.ToSingle(process.ReadByteArray(address, sizeof(float)), 0),
         y = BitConverter.ToSingle(process.ReadByteArray(address + 4, sizeof(float)), 0)
     });
 }
Beispiel #4
0
 public static ProcessModule GetModuleByName(this MvProcess process, string moduleName)
 {
     return(process
            .SomeWhen(x => x.IsDefined)
            .Map(x =>
     {
         return x.Modules.Cast <ProcessModule>().FirstOrDefault(s => s.ModuleName.Equals(moduleName, StringComparison.OrdinalIgnoreCase));
     })
            .ValueOr(() => null));
 }
Beispiel #5
0
        public static IntPtr ScanModuleByPattern(this MvProcess process, string moduleName, string pattern)
        {
            var processModule = process[moduleName];

            if (processModule == null)
            {
                Console.WriteLine($"Module {moduleName} is undefined.");
                return(IntPtr.Zero);
            }
            return(process.ScanByPattern(processModule.BaseAddress, processModule.ModuleMemorySize, pattern));
        }
Beispiel #6
0
        public static byte[] ReadByteArray(this MvProcess process, long address, uint pSize)
        {
            var buffer = new byte[pSize];

            try
            {
                Kernel32.ReadProcessMemory(process.Pointer, (IntPtr)address, buffer, pSize, 0U);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Reading memory error for {\n" + process.ToString() + "\n}");
                Console.WriteLine("Exception's message: " + exception.Message);
            }
            return(buffer);
        }
Beispiel #7
0
        public static Vector3 ReadVector3(this MvProcess process, long address, Vector3StorageType storageType)
        {
            switch (storageType)
            {
            case Vector3StorageType.Xyz:
                return(new Vector3
                {
                    x = BitConverter.ToSingle(process.ReadByteArray(address, sizeof(float)), 0),
                    y = BitConverter.ToSingle(process.ReadByteArray(address + 4, sizeof(float)), 0),
                    z = BitConverter.ToSingle(process.ReadByteArray(address + 8, sizeof(float)), 0)
                });

            default:
                return(new Vector3
                {
                    x = BitConverter.ToSingle(process.ReadByteArray(address, sizeof(float)), 0),
                    y = BitConverter.ToSingle(process.ReadByteArray(address + 8, sizeof(float)), 0),
                    z = BitConverter.ToSingle(process.ReadByteArray(address + 4, sizeof(float)), 0)
                });
            }
        }
Beispiel #8
0
 public static bool ReadBool(this MvProcess process, long address)
 {
     return(BitConverter.ToBoolean(process.ReadByteArray(address, sizeof(Int16)), 0));
 }
Beispiel #9
0
 public static string ReadStringAscii(this MvProcess process, long address, uint size)
 {
     return(Encoding.ASCII.GetString(process.ReadByteArray(address, size)));
 }
Beispiel #10
0
 public static string ReadStringUnicode(this MvProcess process, long address, uint size)
 {
     return(Encoding.Unicode.GetString(process.ReadByteArray(address, size)));
 }
Beispiel #11
0
 public static float ReadFloat(this MvProcess process, long address)
 {
     return(BitConverter.ToSingle(process.ReadByteArray(address, sizeof(float)), 0));
 }
Beispiel #12
0
 public static double ReadDouble(this MvProcess process, long address)
 {
     return(BitConverter.ToDouble(process.ReadByteArray(address, sizeof(double)), 0));
 }
Beispiel #13
0
 public static UInt64 ReadUInt64(this MvProcess process, long address)
 {
     return(BitConverter.ToUInt64(process.ReadByteArray(address, sizeof(Int16)), 0));
 }
Beispiel #14
0
 public static Int32 ReadPointer32(this MvProcess process, long address)
 {
     return(BitConverter.ToInt32(process.ReadByteArray(address, sizeof(Int32)), 0));
 }
Beispiel #15
0
 public static Int16 ReadInt16(this MvProcess process, long address)
 {
     return(BitConverter.ToInt16(process.ReadByteArray(address, sizeof(Int16)), 0));
 }
Beispiel #16
0
 public static IntPtr ScanByPattern(this MvProcess process, IntPtr baseAddress, long size, string pattern)
 {
     return(process.ScanByPattern(baseAddress, size, BuildPattern(pattern)));
 }
Beispiel #17
0
 public static char ReadChar(this MvProcess process, long address)
 {
     return(BitConverter.ToChar(process.ReadByteArray(address, sizeof(Int16)), 0));
 }