Esempio n. 1
0
        public override object Execute(List <string> args)
        {
            if (args.Count > 1)
            {
                return(false);
            }


            Process process;

            if (args.Count == 1)
            {
                if (!int.TryParse(args[0], NumberStyles.HexNumber, null, out int processId) || processId < 0)
                {
                    return(false);
                }

            #if !DEBUG
                try
                {
            #endif
                process = Process.GetProcessById(processId);
            #if !DEBUG
            }
            catch (ArgumentException)
            {
                Console.Error.WriteLine("Unable to find a process with an ID of 0x{0:X}", processId);
                return(true);
            }
            #endif
            }
            else
            {
                var processes = Process.GetProcessesByName("eldorado");

                if (processes.Length == 0)
                {
                    Console.Error.WriteLine("Unable to find any eldorado.exe processes.");
                    return(true);
                }

                process = processes[0];
            }

            using (var processStream = new ProcessMemoryStream(process))
            {
                var address = GetTagAddress(processStream, Tag.Index);
                if (address != 0)
                {
                    var runtimeContext = new RuntimeSerializationContext(Cache, processStream, address, Tag.Offset, Tag.CalculateHeaderSize(), Tag.TotalSize);

                    //pause the process during poking to prevent race conditions
                    Stopwatch stopWatch = new Stopwatch();
                    stopWatch.Start();
                    process.Suspend();
                    Cache.Serializer.Serialize(runtimeContext, Value);
                    process.Resume();
                    stopWatch.Stop();

                    Console.WriteLine($"Poked tag at 0x{address.ToString("X8")} in {stopWatch.ElapsedMilliseconds / 1000.0f} seconds");
                }
                else
                {
                    Console.Error.WriteLine("Tag 0x{0:X} is not loaded in process 0x{1:X}.", Tag.Index, process.Id);
                }
            }

            return(true);
        }
        public override object Execute(List <string> args)
        {
            if (args.Count > 1)
            {
                return(false);
            }

            Process process;

            if (args.Count == 1)
            {
                if (!int.TryParse(args[0], NumberStyles.HexNumber, null, out int processId) || processId < 0)
                {
                    return(false);
                }

            #if !DEBUG
                try
                {
            #endif
                process = Process.GetProcessById(processId);
            #if !DEBUG
            }
            catch (ArgumentException)
            {
                Console.Error.WriteLine("Unable to find a process with an ID of 0x{0:X}", processId);
                return(true);
            }
            #endif
            }
            else
            {
                var processes = Process.GetProcessesByName("eldorado");

                if (processes.Length == 0)
                {
                    Console.Error.WriteLine("Unable to find any eldorado.exe processes.");
                    return(true);
                }

                process = processes[0];
            }

            using (var processStream = new ProcessMemoryStream(process))
            {
                var address = GetTagAddress(processStream, Tag.Index);

                var runtimeContext = new RuntimeSerializationContext(CacheContext, processStream);
                processStream.Position = address + Tag.DefinitionOffset;

                var definition = CacheContext.Deserializer.Deserialize(runtimeContext, TagDefinition.Find(Tag.Group.Tag));
                CacheContext.Serializer.Serialize(runtimeContext, Value);

                if (address != 0)
                {
                    Console.WriteLine("Tag 0x{0:X} is loaded at 0x{1:X8} in process 0x{2:X}.", Tag.Index, address, process.Id);
                }
                else
                {
                    Console.Error.WriteLine("Tag 0x{0:X} is not loaded in process 0x{1:X}.", Tag.Index, process.Id);
                }
            }

            return(true);
        }