private byte ReadByte(uint offset)
 {
     try
     {
         return(TrashMem.ReadChar(offset));
     }
     catch { CheckForGameCrashed(); return(0); }
 }
Exemplo n.º 2
0
        public static List <WowProcess> GetRunningWows(IOffsetList offsetList)
        {
            List <WowProcess> wows        = new List <WowProcess>();
            List <Process>    processList = new List <Process>(Process.GetProcessesByName("Wow"));

            foreach (Process p in processList)
            {
                TrashMem trashMem = new TrashMem(p);
                uint     pDevice  = trashMem.ReadUnmanaged <uint>(offsetList.StaticEndSceneDevice);
                uint     pEnd     = trashMem.ReadUnmanaged <uint>(pDevice + offsetList.EndSceneOffsetDevice);
                uint     pScene   = trashMem.ReadUnmanaged <uint>(pEnd);
                uint     endscene = trashMem.ReadUnmanaged <uint>(pScene + offsetList.EndSceneOffset);

                bool isAlreadyHooked = false;
                try
                {
                    isAlreadyHooked = trashMem.ReadChar(endscene + 0x2) == 0xE9;
                }
                catch { }

                string name = trashMem.ReadString(offsetList.StaticPlayerName, Encoding.ASCII, 12);
                if (name.Length == 0)
                {
                    name = "";
                }

                string realm = trashMem.ReadString(offsetList.StaticRealmName, Encoding.ASCII, 12);
                if (realm.Length == 0)
                {
                    realm = "";
                }

                wows.Add(new WowProcess(p, name, realm, isAlreadyHooked));
                trashMem.Detach();
            }

            return(wows);
        }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            Console.Title = "TrashMem Benchmark";
            Process[] testProcesses = Process.GetProcessesByName("ShittyMcUlow");

            if (testProcesses.Length > 0)
            {
                TrashMem TrashMem = new TrashMem(testProcesses.ToList().First());

                Console.WriteLine($"TrashMem Benchmark doing {TOTAL_RUNS} runs for every function");
                Console.WriteLine($">> 1 Byte Char");
                PrettyPrintValue("Read<char>", BenchmarkFunction(() => TrashMem.ReadUnmanaged <char>(STATIC_ADDRESS_INT16)));
                PrettyPrintValue("ReadChar", BenchmarkFunction(() => TrashMem.ReadChar(STATIC_ADDRESS_INT16)));
                PrettyPrintValue("ReadCharSafe", BenchmarkFunction(() => TrashMem.ReadCharSafe(STATIC_ADDRESS_INT16)));
                Console.WriteLine($">> 2 Byte Short");
                PrettyPrintValue("Read<short>", BenchmarkFunction(() => TrashMem.ReadUnmanaged <short>(STATIC_ADDRESS_INT16)));
                PrettyPrintValue("ReadInt16", BenchmarkFunction(() => TrashMem.ReadInt16(STATIC_ADDRESS_INT16)));
                PrettyPrintValue("ReadInt16Safe", BenchmarkFunction(() => TrashMem.ReadInt16Safe(STATIC_ADDRESS_INT16)));
                Console.WriteLine($">> 4 Byte Integer");
                PrettyPrintValue("Read<int>", BenchmarkFunction(() => TrashMem.ReadUnmanaged <int>(STATIC_ADDRESS_INT32)));
                PrettyPrintValue("ReadInt32", BenchmarkFunction(() => TrashMem.ReadInt32(STATIC_ADDRESS_INT32)));
                PrettyPrintValue("ReadInt32Safe", BenchmarkFunction(() => TrashMem.ReadInt32Safe(STATIC_ADDRESS_INT32)));
                Console.WriteLine($">> 8 Byte Long");
                PrettyPrintValue("Read<long>", BenchmarkFunction(() => TrashMem.ReadUnmanaged <long>(STATIC_ADDRESS_INT64)));
                PrettyPrintValue("ReadInt64", BenchmarkFunction(() => TrashMem.ReadInt64(STATIC_ADDRESS_INT64)));
                PrettyPrintValue("ReadInt64Safe", BenchmarkFunction(() => TrashMem.ReadInt64Safe(STATIC_ADDRESS_INT64)));
                Console.WriteLine($">> 12 Byte String");
                PrettyPrintValue("ReadString", BenchmarkFunction(() => TrashMem.ReadString(STATIC_ADDRESS_STRING, Encoding.ASCII, 12)));
                Console.WriteLine($">> 16 Byte Struct");
                PrettyPrintValue("ReadStruct<TestStruct>", BenchmarkFunction(() => TrashMem.ReadStruct <TestStruct>(STATIC_ADDRESS_INT16)));
            }
            else
            {
                Console.WriteLine("Error: please make sure a ShittyMcUlow process is running...");
            }

            Console.ReadLine();
        }
Exemplo n.º 4
0
 public void ReadCharTest()
 => Assert.AreEqual(0xF, TrashMem.ReadChar(STATIC_ADDRESS_CHAR));
Exemplo n.º 5
0
        public byte[] InjectAndExecute(string[] asm, bool readReturnBytes, [CallerMemberName] string callingFunction = "")
        {
            AmeisenBotLogger.Instance.Log($"[{ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tInjecting ASM into Hook [asm = {JsonConvert.SerializeObject(asm)}, readReturnBytes = {readReturnBytes}, callingFunction = {callingFunction}]", LogLevel.Verbose);
            List <byte> returnBytes = new List <byte>();

            if (!IsWorldLoaded)
            {
                return(returnBytes.ToArray());
            }

            try
            {
                int timeoutCounter = 0;
                // wait for the code to be executed
                while (IsInjectionUsed)
                {
                    if (timeoutCounter == 500)
                    {
                        return(Array.Empty <byte>());
                    }

                    timeoutCounter++;
                    Thread.Sleep(1);
                }

                IsInjectionUsed = true;
                // preparing to inject the given ASM
                TrashMem.Asm.Clear();
                // add all lines
                foreach (string s in asm)
                {
                    TrashMem.Asm.AddLine(s);
                }

                // now there is code to be executed
                TrashMem.Write(CodeToExecuteAddress.Address, 1);
                // inject it
                TrashMem.Asm.Inject(CodecaveForExecution.Address);

                timeoutCounter = 0;
                // wait for the code to be executed
                while (TrashMem.ReadInt32(CodeToExecuteAddress.Address) > 0)
                {
                    if (timeoutCounter == 500)
                    {
                        return(Array.Empty <byte>());
                    }

                    timeoutCounter++;
                    IsInjectionUsed = false;
                    Thread.Sleep(1);
                }

                // if we want to read the return value do it otherwise we're done
                if (readReturnBytes)
                {
                    byte buffer;
                    try
                    {
                        uint dwAddress = TrashMem.ReadUnmanaged <uint>(ReturnValueAddress.Address);

                        // read all parameter-bytes until we the buffer is 0
                        buffer = TrashMem.ReadChar(dwAddress);
                        while (buffer != 0)
                        {
                            returnBytes.Add(buffer);
                            dwAddress++;
                            buffer = TrashMem.ReadChar(dwAddress);
                        }
                    }
                    catch (Exception e)
                    {
                        AmeisenBotLogger.Instance.Log($"[{ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tCrash at reading the return bytes: \n{e}", LogLevel.Error);
                    }
                }
                IsInjectionUsed = false;
            }
            catch (Exception e)
            {
                AmeisenBotLogger.Instance.Log($"[{ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tCrash at injecting: \n{e}", LogLevel.Error);
                // now there is no more code to be executed
                TrashMem.ReadUnmanaged <uint>(CodeToExecuteAddress.Address, 0);
                IsInjectionUsed = false;
            }

            return(returnBytes.ToArray());
        }