示例#1
0
        public Engine(Configuration configuration, RuntimeBase runtime)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            this._CachedNames   = new Dictionary <int, string>();
            this._CachedClasses = new Dictionary <IntPtr, UnrealClass>();
            this._CachedFields  = new Dictionary <IntPtr, UnrealField>();
            this._CachedPaths   = new Dictionary <IntPtr, string>();

            this.Configuration = (Configuration)configuration.Clone();
            this.Runtime       = runtime;

            this._NameAddresses   = this.ReadPointerArray(configuration.GlobalNameArrayAddress);
            this._ObjectAddresses = this.ReadPointerArray(configuration.GlobalObjectArrayAddress);

            this._ObjectShims = new Dictionary <IntPtr, UnrealObjectShim>();
            foreach (var objectAddress in this._ObjectAddresses.Where(oa => oa != IntPtr.Zero))
            {
                var objectClassPointer = this.ReadPointer(objectAddress + this.Offsets.CoreObjectClass);
                var objectClass        = this.ReadClass(objectClassPointer);
                var objectName         = this.ReadName(objectAddress + this.Offsets.CoreObjectName);
                var objectPath         = this.ReadPath(objectAddress);
                var objectShim         = new UnrealObjectShim(this, objectAddress, objectClass, objectName, objectPath);
                this._ObjectShims.Add(objectAddress, objectShim);
            }
        }
示例#2
0
        public override ISimulatable NewSimulator(string name, RuntimeBase runtime)
        {
            switch (name)
            {
            case Models.Network.Name:
                return(new PeerToPeerNetworkSimulator(runtime));

            case Models.Scene.Name:
                return(new SceneSimulator(runtime));

            case Models.Channel.AdaptedFriis.Name:
                return(new AdaptedFriisSimulator(runtime));

            case Models.Antenna.Spheric.Name:
                return(new SphericAntennaSimulator(runtime));

            case Models.Antenna.Simple.Name:
                return(new SimpleAntennaSimulator(runtime));

            case Models.Antenna.Flat.Name:
                return(new SimpleAntennaSimulator(runtime));

            case Models.Communication.LrWpan.Name:
                return(new LrwpanSimulator(runtime));

            case Models.Energy.Battery.Name:
                return(new BatteryPackSimulator(runtime));

            default:
                return(null);
            }
        }
示例#3
0
        // -- constructor

        public ImportPipeline(OptionsBase options, FactoryBase factory, RuntimeBase runtime)
        {
            Arguments = new Dictionary <SimulationTypes, ArgumentsBase>();
            Options   = options;
            Factory   = factory;
            Runtime   = runtime;
        }
示例#4
0
文件: heapbase.cs 项目: tomasr/clrmd
 public HeapBase(RuntimeBase runtime)
 {
     _canWalkHeap = runtime.CanWalkHeap;
     if (runtime.DataReader.CanReadAsync)
         MemoryReader = new AsyncMemoryReader(runtime.DataReader, 0x10000);
     else
         MemoryReader = new MemoryReader(runtime.DataReader, 0x10000);
     _pointerSize = runtime.PointerSize;
 }
示例#5
0
        private static StashTableEntry <T>[] ReadStashTable <T>(
            this RuntimeBase runtime, IntPtr pointer, Func <IntPtr, T> callback)
        {
            if (pointer == IntPtr.Zero)
            {
                return(new StashTableEntry <T> [0]);
            }

            StashTableHeader header;

            if (runtime.Is32Bit == false)
            {
                header = runtime.ReadStructure <StashTableHeader>(pointer);
            }
            else
            {
                header = runtime.ReadStructure <x32.StashTableHeader>(pointer).Upgrade();
            }

            if (header.AllocatedCount == 0)
            {
                return(new StashTableEntry <T> [0]);
            }

            StashTableEntry[] entries;
            if (runtime.Is32Bit == false)
            {
                entries = runtime.ReadStructureArray <StashTableEntry>(header.EntriesPointer, header.AllocatedCount);
            }
            else
            {
                var entries32 = runtime.ReadStructureArray <x32.StashTableEntry>(header.EntriesPointer, header.AllocatedCount);
                entries = new StashTableEntry[header.AllocatedCount];
                for (int i = 0; i < header.AllocatedCount; i++)
                {
                    entries[i] = entries32[i].Upgrade();
                }
            }

            var items = new StashTableEntry <T> [header.AllocatedCount];
            int o     = 0;

            for (int i = 0; i < header.AllocatedCount; i++)
            {
                var entry = entries[i];
                if (entry.NamePointer == default && entry.ValuePointer == default)
                {
                    continue;
                }
                var name  = runtime.ReadStringZ(entry.NamePointer, Encoding.ASCII);
                var value = callback(entry.ValuePointer);
                items[o] = new StashTableEntry <T>(name, value);
                o++;
            }
            Array.Resize(ref items, o);
            return(items);
        }
示例#6
0
        internal static int GetTlsSlotForThread(RuntimeBase runtime, ulong teb)
        {
            const int maxTlsSlot              = 64;
            const int tlsSlotOffset           = 0x1480; // Same on x86 and amd64
            const int tlsExpansionSlotsOffset = 0x1780;
            uint      ptrSize = (uint)runtime.PointerSize;

            ulong lowerTlsSlots = teb + tlsSlotOffset;
            uint  clrTlsSlot    = runtime.GetTlsSlot();

            if (clrTlsSlot == uint.MaxValue)
            {
                return(0);
            }

            ulong tlsSlot = 0;

            if (clrTlsSlot < maxTlsSlot)
            {
                tlsSlot = lowerTlsSlots + ptrSize * clrTlsSlot;
            }
            else
            {
                if (!runtime.ReadPointer(teb + tlsExpansionSlotsOffset, out tlsSlot) || tlsSlot == 0)
                {
                    return(0);
                }

                tlsSlot += ptrSize * (clrTlsSlot - maxTlsSlot);
            }

            ulong clrTls = 0;

            if (!runtime.ReadPointer(tlsSlot, out clrTls))
            {
                return(0);
            }

            // Get thread data;

            uint tlsThreadTypeIndex = runtime.GetThreadTypeIndex();

            if (tlsThreadTypeIndex == uint.MaxValue)
            {
                return(0);
            }

            ulong threadType = 0;

            if (!runtime.ReadPointer(clrTls + ptrSize * tlsThreadTypeIndex, out threadType))
            {
                return(0);
            }

            return((int)threadType);
        }
示例#7
0
        public override void Arrange()
        {
            base.Arrange();

            _runtime = new RuntimeController(new D3vS1mValidator());
            _runtime.IterationPassed += (o, e) =>
            {
                var runtimeArgs = e.Arguments as RuntimeArgs;
                _log.Debug(runtimeArgs);
            };
        }
示例#8
0
        // -- constructor

        protected SimulatorBase(RuntimeBase runtime)
        {
            _log = LoggingProvider.CreateLogger <SimulatorBase>();
            Guid = global::System.Guid.NewGuid().ToString();

            if (runtime != null)
            {
                _runtime          = runtime;
                _runtime.Started += OnStarted;
            }
        }
示例#9
0
        public override RuntimeBase SetupRuntime(ArgumentsBase[] args, RuntimeBase runtime)
        {
            base.Simulators.Clear();
            foreach (var arg in args)
            {
                RegisterSimulator(
                    NewSimulator(arg.Name, runtime), arg);
            }

            runtime.BindSimulators(Simulators);
            return(runtime);
        }
示例#10
0
        private static uint HashKeyValueList(RuntimeBase runtime, IntPtr baseAddress, uint hash)
        {
            var entries = runtime.ReadStringStashTable(baseAddress);
            var sb      = new StringBuilder();

            foreach (var entry in entries.OrderBy(e => e.Name.ToLowerInvariant()))
            {
                sb.Append(entry.Name);
                sb.Append(entry.Value);
            }
            return(Adler32.Hash(sb.ToString(), hash));
        }
示例#11
0
        internal DesktopThread(RuntimeBase clr, IThreadData thread, ulong address, bool finalizer)
        {
            m_runtime   = clr;
            m_address   = address;
            m_finalizer = finalizer;

            Debug.Assert(thread != null);
            if (thread != null)
            {
                m_osThreadId      = thread.OSThreadID;
                m_managedThreadId = thread.ManagedThreadID;
                m_appDomain       = thread.AppDomain;
                m_lockCount       = thread.LockCount;
                m_teb             = thread.Teb;
                m_threadState     = thread.State;
                m_exception       = thread.ExceptionPtr;
                m_preemptive      = thread.Preemptive;
            }
        }
        public Engine(Configuration configuration, RuntimeBase runtime)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            this.Configuration    = (Configuration)configuration.Clone();
            this.Runtime          = runtime;
            this._NameAddresses   = this.ReadPointerArray(configuration.GlobalNameArrayAddress);
            this._ObjectAddresses = this.ReadPointerArray(configuration.GlobalObjectArrayAddress);

            foreach (var objectAddress in this._ObjectAddresses.Where(oa => oa != IntPtr.Zero))
            {
                var objectClassPointer = this.ReadPointer(objectAddress + this.Configuration.ObjectClassOffset);
                var objectClass        = this.ReadClass(objectClassPointer);
                var objectName         = this.ReadName(objectAddress + this.Configuration.ObjectNameOffset);
                var objectPath         = this.ReadPath(objectAddress);
                this._ObjectShims.Add(objectAddress,
                                      new UnrealObjectShim(this, objectAddress, objectClass, objectName, objectPath));
            }
        }
示例#13
0
        private void SetupDemoRepo(RuntimeBase runtime)
        {
            var sceneArgs   = new InvariantSceneArgs();
            var radioArgs   = base.GetRadioArgs();
            var comArgs     = new WirelessCommArgs();
            var netArgs     = new NetworkArgs();
            var antennaArgs = new SimpleAntennaArgs();

            _repo = new SimulatorRepository();
            _repo.AddRange(new ISimulatable[] {
                new SceneSimulator(runtime)
                .With(sceneArgs),
                new AdaptedFriisSimulator(runtime)
                .With(radioArgs)
                .With(comArgs),
                new SimpleAntennaSimulator(runtime)
                .With(antennaArgs),
                new PeerToPeerNetworkSimulator(runtime)
                .With(netArgs),
                new LrwpanSimulator(runtime)
                .With(comArgs)
            });
        }
示例#14
0
文件: heapbase.cs 项目: tomasr/clrmd
 internal HeapSegment(RuntimeBase clr, ISegmentData segment, SubHeap subHeap, bool large, HeapBase heap)
 {
     _clr = clr;
     _large = large;
     _segment = segment;
     _heap = heap;
     _subHeap = subHeap;
 }
示例#15
0
        // -- constructor

        public LrwpanSimulator(RuntimeBase runtime) : base(runtime)
        {
        }
示例#16
0
        // -- constructors

        public SceneSimulator(RuntimeBase runtime) : base(runtime)
        {
        }
示例#17
0
 public abstract ISimulatable NewSimulator(string name, RuntimeBase runtime);
示例#18
0
 public AdaptedFriisSimulator(RuntimeBase runtime) : base(runtime)
 {
     _log = LoggingProvider.CreateLogger <SimulatorBase>();
 }
示例#19
0
 public static StashTableEntry <IntPtr>[] ReadStashTable(this RuntimeBase runtime, IntPtr pointer)
 {
     return(runtime.ReadStashTable(pointer, p => p));
 }
示例#20
0
        // -- constructor

        public SimpleAntennaSimulator(RuntimeBase runtime) : base(runtime)
        {
        }
示例#21
0
        // -- constructor

        public PeerToPeerNetworkSimulator(RuntimeBase runtime) : base(runtime)
        {
        }
示例#22
0
 public HeapBase(RuntimeBase runtime)
 {
     _canWalkHeap = runtime.CanWalkHeap;
     MemoryReader = new MemoryReader(runtime.DataReader, 0x10000);
     _pointerSize = runtime.PointerSize;
 }
示例#23
0
文件: threads.cs 项目: mwatts/clrmd
        internal static int GetTlsSlotForThread(RuntimeBase runtime, ulong teb)
        {
            const int maxTlsSlot = 64;
            const int tlsSlotOffset = 0x1480; // Same on x86 and amd64
            const int tlsExpansionSlotsOffset = 0x1780;
            uint ptrSize = (uint)runtime.PointerSize;

            ulong lowerTlsSlots = teb + tlsSlotOffset;
            uint clrTlsSlot = runtime.GetTlsSlot();
            if (clrTlsSlot == uint.MaxValue)
                return 0;

            ulong tlsSlot = 0;
            if (clrTlsSlot < maxTlsSlot)
            {
                tlsSlot = lowerTlsSlots + ptrSize * clrTlsSlot;
            }
            else
            {
                if (!runtime.ReadPointer(teb + tlsExpansionSlotsOffset, out tlsSlot) || tlsSlot == 0)
                    return 0;

                tlsSlot += ptrSize * (clrTlsSlot - maxTlsSlot);
            }

            ulong clrTls = 0;
            if (!runtime.ReadPointer(tlsSlot, out clrTls))
                return 0;

            // Get thread data;

            uint tlsThreadTypeIndex = runtime.GetThreadTypeIndex();
            if (tlsThreadTypeIndex == uint.MaxValue)
                return 0;

            ulong threadType = 0;
            if (!runtime.ReadPointer(clrTls + ptrSize * tlsThreadTypeIndex, out threadType))
                return 0;

            return (int)threadType;
        }
示例#24
0
文件: threads.cs 项目: mwatts/clrmd
        internal DesktopThread(RuntimeBase clr, IThreadData thread, ulong address, bool finalizer)
        {
            _runtime = clr;
            _address = address;
            _finalizer = finalizer;

            Debug.Assert(thread != null);
            if (thread != null)
            {
                _osThreadId = thread.OSThreadID;
                _managedThreadId = thread.ManagedThreadID;
                _appDomain = thread.AppDomain;
                _lockCount = thread.LockCount;
                _teb = thread.Teb;
                _threadState = thread.State;
                _exception = thread.ExceptionPtr;
                _preemptive = thread.Preemptive;
            }
        }
示例#25
0
        private static uint HashTable(RuntimeBase runtime, IntPtr address, uint hash)
        {
            throw new NotImplementedException();

            var columns        = new List <KeyValuePair <ParseColumn, string> >();
            var currentAddress = address;

            while (true)
            {
                var column = runtime.ReadStructure <ParseColumn>(currentAddress);
                currentAddress += 40;

                var name = runtime.ReadStringZ(column.NamePointer, Encoding.ASCII);

                if (column.Type == 0)
                {
                    if (string.IsNullOrEmpty(name) == true)
                    {
                        break;
                    }
                }

                columns.Add(new KeyValuePair <ParseColumn, string>(column, name));
            }

            foreach (var kv in columns)
            {
                var column = kv.Key;

                if (column.Flags.HasAny(Parse.ColumnFlags.REDUNDANTNAME |
                                        Parse.ColumnFlags.UNOWNED) == true)
                {
                    continue;
                }

                var name = kv.Value;

                if (string.IsNullOrEmpty(name) == false)
                {
                    hash = Adler32.Hash(name, hash);
                }

                hash = Adler32.Hash(column.Type, hash);

                var token = Parse.GlobalTokens.GetToken(column.Token);

                switch (token.GetParameter(column.Flags, 0))
                {
                case Parse.ColumnParameter.NumberOfElements:
                case Parse.ColumnParameter.Default:
                case Parse.ColumnParameter.StringLength:
                case Parse.ColumnParameter.Size:
                {
                    hash = Adler32.Hash(column.Parameter0.Int32, hash);
                    break;
                }

                case Parse.ColumnParameter.BitOffset:
                {
                    hash = Adler32.Hash(column.Parameter0.Int32 >> 16, hash);
                    break;
                }

                case Parse.ColumnParameter.DefaultString:
                case Parse.ColumnParameter.CommandString:
                {
                    if (column.Parameter0.Pointer != default)
                    {
                        hash = Adler32.Hash(runtime.ReadStringZ(column.Parameter0.Pointer, Encoding.ASCII), hash);
                    }
                    break;
                }
                }

                var param1 = token.GetParameter(column.Flags, 1);

                if (column.Parameter1.Pointer != default &&
                    (column.Token == 20 || column.Token == 21) &&
                    address != column.Parameter1.Pointer &&
                    column.Flags.HasAny(Parse.ColumnFlags.STRUCT_NORECURSE) == false)
                {
                    hash = HashTable(runtime, column.Parameter1.Pointer, hash);
                }

                if (column.Parameter1.Pointer != default &&
                    param1 == Parse.ColumnParameter.StaticDefineList)
                {
                    hash = HashStaticDefineList(runtime, column.Parameter1.Pointer, hash);
                }

                if (column.Token == 23)
                {
                    var formatString = runtime.ReadStringZ(column.FormatStringPointer, Encoding.ASCII);
                    if (string.IsNullOrEmpty(formatString) == false)
                    {
                        hash = Adler32.Hash(formatString, hash);
                    }
                }
            }

            return(hash);
        }
示例#26
0
 public abstract RuntimeBase SetupRuntime(ArgumentsBase[] args, RuntimeBase runtime);
示例#27
0
 public BatteryPackSimulator(RuntimeBase runtime) : base(runtime)
 {
     _log = LoggingProvider.CreateLogger <BatteryPackSimulator>();
 }
示例#28
0
文件: heapbase.cs 项目: tomasr/clrmd
        protected void InitSegments(RuntimeBase runtime)
        {
            // Populate segments
            SubHeap[] heaps;
            if (runtime.GetHeaps(out heaps))
            {
                var segments = new List<HeapSegment>();
                foreach (var heap in heaps)
                {
                    if (heap != null)
                    {
                        ISegmentData seg = runtime.GetSegmentData(heap.FirstLargeSegment);
                        while (seg != null)
                        {
                            var segment = new HeapSegment(runtime, seg, heap, true, this);
                            segments.Add(segment);

                            UpdateSegmentData(segment);
                            seg = runtime.GetSegmentData(seg.Next);
                        }

                        seg = runtime.GetSegmentData(heap.FirstSegment);
                        while (seg != null)
                        {
                            var segment = new HeapSegment(runtime, seg, heap, false, this);
                            segments.Add(segment);

                            UpdateSegmentData(segment);
                            seg = runtime.GetSegmentData(seg.Next);
                        }
                    }
                }

                UpdateSegments(segments.ToArray());
            }
            else
            {
                _segments = new ClrSegment[0];
            }
        }
示例#29
0
 public SphericAntennaSimulator(RuntimeBase runtime) : base(runtime)
 {
     _log = LoggingProvider.CreateLogger <SphericAntennaSimulator>();
 }
示例#30
0
 public static StashTableEntry <string>[] ReadStringStashTable(this RuntimeBase runtime, IntPtr pointer)
 {
     return(runtime.ReadStashTable(pointer, p => runtime.ReadStringZ(p, Encoding.ASCII)));
 }
示例#31
0
        private static uint HashStaticDefineList(RuntimeBase runtime, IntPtr baseAddress, uint hash)
        {
            var valueType = 4;

            while (true)
            {
                var type = runtime.ReadValueU32(baseAddress);
                if (type == 0)
                {
                    break;
                }

                switch (type)
                {
                case 1:
                {
                    valueType    = 1;
                    baseAddress += 8;
                    break;
                }

                case 2:
                {
                    valueType    = 2;
                    baseAddress += 8;
                    break;
                }

                case 3:
                {
                    var listAddress = runtime.ReadPointer(baseAddress + 4);
                    baseAddress += 8;

                    if (listAddress != IntPtr.Zero)
                    {
                        hash = HashKeyValueList(runtime, listAddress, hash);
                    }

                    break;
                }

                case 5:
                {
                    var parent = runtime.ReadPointer(baseAddress + 4);
                    return(HashStaticDefineList(runtime, parent, hash));
                }

                default:
                {
                    // TODO(gibbed): FIXME
                    var name = runtime.ReadStringZ(new IntPtr(type), Encoding.ASCII);
                    hash = Adler32.Hash(name, hash);

                    switch (valueType)
                    {
                    case 1:
                    {
                        var value = runtime.ReadValueU32(baseAddress + 4);
                        hash         = Adler32.Hash(value, hash);
                        baseAddress += 8;
                        break;
                    }

                    case 2:
                    {
                        var value = runtime.ReadStringZ(baseAddress + 4, Encoding.ASCII);
                        hash         = Adler32.Hash(value, hash);
                        baseAddress += 8;
                        break;
                    }

                    default:
                    {
                        throw new NotImplementedException();
                    }
                    }

                    break;
                }
                }
            }

            return(hash);
        }