Exemple #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            StartRuntime();
            ulong   eeClass = Convert.ToUInt64(textBox6.Text, 16);
            ClrType myType  = AdHoc.GetTypeFromEE(m_runtime, eeClass);

            WriteLine("EEClass: {1:x16} Type: {0}", myType == null ? "*Invalid*" : myType.Name, eeClass);
        }
Exemple #2
0
        private void button6_Click(object sender, EventArgs e)
        {
            StartRuntime();
            ulong   mt     = Convert.ToUInt64(textBox5.Text, 16);
            ClrType myType = AdHoc.GetTypeFromMT(m_runtime, mt);

            WriteLine("MT: {1:x16} Type: {0}", myType == null ? "*Invalid*" : myType.Name, mt);
        }
        public void OutputCommand()
        {
            var sut = new AdHoc();

            string cmd = sut.ToString();

            Assert.AreEqual(sut.CommandName, cmd);
        }
        public void PartialMatchDoesNotMatchAny()
        {
            var specification = new AdHoc <User>(u => u.Username == "user");

            SpecificationDoesNotMatch(user1, specification);
            SpecificationDoesNotMatch(user2, specification);
            SpecificationDoesNotMatch(user3, specification);
        }
Exemple #5
0
        public void DumpModules(ulong DomainAddr = 0, bool DebugOnly = false, bool NotMicrosoftOnly = false)
        {
            var domains = AdHoc.GetDomains(m_runtime);

            if (domains == null || domains.Length < 2)
            {
                WriteLine("Unable to get Application Domains. This is not expected.");
                return;
            }
        }
Exemple #6
0
        private void StartRuntime(string Target)
        {
            DataTarget dataTarget = DataTarget.LoadCrashDump(Target);
            ClrInfo    latest     = null;

            foreach (var version in dataTarget.ClrVersions)
            {
                WriteLine("Version: {0}.{1}.{2}.{3} from {4}", version.Version.Major, version.Version.Minor, version.Version.Patch, version.Version.Revision, version.DacInfo.FileName);
                latest = version;
            }
            m_runtime = dataTarget.CreateRuntime(latest.TryDownloadDac());
            ulong strMT, arrMT, freeMT = 0;

            AdHoc.GetCommonMT(m_runtime, out strMT, out arrMT, out freeMT);

            WriteLine("Free MT: {0:x16}, String MT: {1:x16}, Array MT: {2:x16}", freeMT, strMT, arrMT);

            WriteLine("== App Domains ===");
            int i = 0;

            DumpDomains();
            //foreach (var appDomain in AdHoc.GetDomains(m_runtime))
            //{
            //    i++;
            //    if (i == 1)
            //    {
            //        WriteLine("{0:x16} System", appDomain.Address);
            //        WriteLine("  Modules: {0}", appDomain.Modules.Count);
            //        continue;
            //    }
            //    if (i == 2)
            //    {
            //        WriteLine("{0:x16} Shared", appDomain.Address);
            //        WriteLine("  Modules: {0}", appDomain.Modules.Count);
            //        continue;
            //    }



            //    WriteLine("{0:x16} {1}", appDomain.Address, appDomain.Name);
            //    WriteLine("  {0}{1}", appDomain.ApplicationBase, appDomain.ConfigurationFile);
            //    WriteLine("  Modules: {0}", appDomain.Modules.Count);

            //}

            WriteLine("==================");
            WriteLine("Heap(s): {0}  GC Server Mode: {1}", m_runtime.HeapCount, m_runtime.ServerGC);
            m_heap   = m_runtime.GetHeap();
            heapObjs = m_heap.EnumerateObjects().GetEnumerator();
            count    = 0;
        }
        public void OutputCommandWithArgs()
        {
            string arg0 = "all";
            string arg1 = "--module-name";
            string arg2 = "setup";
            var    sut  = new AdHoc();

            sut.AddParameter(arg0);
            sut.AddParameter(arg1, arg2);
            string expectedCmd = $"{sut.CommandName} {arg0} {arg1} {arg2}";

            string cmd = sut.ToString();

            Assert.AreEqual(expectedCmd, cmd);
        }
Exemple #8
0
        private void button3_Click(object sender, EventArgs e)
        {
            StartRuntime();
            if (currObj == 0)
            {
                WriteLine("No object selected");
                return;
            }
            var type = m_heap.GetObjectType(currObj);

            if (type.IsException)
            {
                DumpException(currObj);
                return;
            }
            WriteLine("===================================================");
            WriteLine("000>!wdo {0:x16}", currObj);
            WriteLine("Address: {0:x16}", currObj);
            WriteLine("EE Class: {0:x16}", GetEEClass(ReadPointer(currObj)));
            WriteLine("Method Table: {0:x16}", ReadPointer(currObj));
            WriteLine("Class Name: {0}", type.Name);
            WriteLine("Size: {0}", type.GetSize(currObj));
            WriteLine("Instance Fields: {0}", type.Fields.Count);
            WriteLine("Static Fields: {0}", type.StaticFields.Count);
            WriteLine("Total Fields: {0}", type.Fields.Count + type.StaticFields.Count);
            var seg = m_heap.GetSegmentByAddress(currObj);

            WriteLine("Heap/Generation: {0}/{1}", seg.ProcessorAffinity, m_heap.GetGeneration(currObj));

            WriteLine("Module: {0:x16}", type.Module.ImageBase);
            WriteLine("Assembly: {0:x16}", type.Module.AssemblyId);

            WriteLine("File Name: {0}", type.Module.FileName);


            WriteLine("Domain: {0:x16}", AdHoc.GetDomainFromMT(m_runtime, ReadPointer(currObj)));

            /*
             * foreach(var domainAddr in Hacks.GetDomainFromMT(runtime, ReadPointer(currObj))
             * {
             *  Write("{0:x16} ", domainAddr);
             * }
             * WriteLine("");
             */

            WriteLine("===================================================");
            DumpFields(currObj);
        }
        public void PrepareLoadingScreen(GameCartridge gameCartridge, MachinaRuntime runtime, AssetLibrary assets, WindowInterface machinaWindow, Action <GameCartridge> onFinished)
        {
            var loader = assets.GetStaticAssetLoadTree();

            LoadDefaultStyle(loader, assets, runtime.Painter);
            gameCartridge.PrepareDynamicAssets(loader, runtime);

            var loadingScreen =
                new LoadingScreen(loader);

            var introScene  = SceneLayers.AddNewScene();
            var loaderActor = introScene.AddActor("Loader");
            var adHoc       = new AdHoc(loaderActor);

            adHoc.onPreDraw += (spriteBatch) =>
            {
                if (!loadingScreen.IsDoneUpdateLoading())
                {
                    // Waiting for this to complete before draw loading
                }
                else if (!loadingScreen.IsDoneDrawLoading())
                {
                    loadingScreen.IncrementDrawLoopLoad(assets, spriteBatch);
                }
            };

            adHoc.onDraw += (spriteBatch) =>
            {
                loadingScreen.Draw(spriteBatch, machinaWindow.CurrentWindowSize);
            };

            adHoc.onUpdate += (dt) =>
            {
                if (!loadingScreen.IsDoneUpdateLoading())
                {
                    var increment = 3;
                    for (var i = 0; i < increment; i++)
                    {
                        loadingScreen.Update(dt / increment);
                    }
                }

                if (loadingScreen.IsDoneDrawLoading() && loadingScreen.IsDoneUpdateLoading())
                {
                    onFinished(gameCartridge);
                }
            };
        }
Exemple #10
0
    public void RuntimeMessageContract()
    {
        var adhoc = new AdHoc();

        Extensible.AppendValue <double>(adhoc, 1, 0.0);
        Extensible.AppendValue <int>(adhoc, 2, 1);
        Extensible.AppendValue <string>(adhoc, 3, "2");
        Extensible.AppendValue <bool>(adhoc, 4, true);
        var clone = Serializer.DeepClone(adhoc);

        Assert.AreNotSame(clone, adhoc);
        Assert.AreEqual(0.0, Extensible.GetValue <double>(clone, 1));
        Assert.AreEqual(1, Extensible.GetValue <int>(clone, 2));
        Assert.AreEqual("2", Extensible.GetValue <string>(clone, 3));
        Assert.AreEqual(true, Extensible.GetValue <bool>(clone, 4));
    }
Exemple #11
0
        public ulong GetDomain(ulong Address)
        {
            StartRuntime();
            foreach (var domain in AdHoc.GetDomains(m_runtime))
            {
                foreach (var module in domain.Modules)
                {
                    if (module.ImageBase == Address)
                    {
                        return(domain.Address);
                    }
                }
            }

            return(0);
        }
Exemple #12
0
 /// <summary>
 /// Start this instance.
 /// </summary>
 void Start()
 {
     //Stopwatch stopWatch = new Stopwatch();
     //stopWatch.Start();
     ll = gameObject.GetComponent <LevelLoad>();
     if (!StaticObjects.cahBuilt)
     {
         AdHoc myAdHoc = new AdHoc(sectLen, height, sectNum);
         myAdHoc.placeCorners();
         myAdHoc.placeWalls();
         myAdHoc.placeInteriors();
         StaticObjects.ahCave   = myAdHoc.levelArr;
         StaticObjects.cahBuilt = true;
     }
     ll.setup(caveLen, height, StaticObjects.ahCave, 3, 0);
     //stopWatch.Stop();
     //TimeSpan ts = stopWatch.Elapsed;
     //print ( ts.Seconds + "." + ts.Milliseconds);
 }
Exemple #13
0
        public void DumpDomains()
        {
            var domains = AdHoc.GetDomains(m_runtime);

            if (domains == null || domains.Length < 2)
            {
                WriteLine("Unable to get Application Domains. This is not expected.");
                return;
            }

            if (m_runtime.PointerSize == 8)
            {
                WriteLine("Address          Domain Name                                                 Modules Base Path & Config");
            }
            else
            {
                WriteLine("Address  Domain Name                                                 Modules Base Path & Config");
            }


            for (int i = 0; i < domains.Length; i++)
            {
                if (IsInterrupted())
                {
                    return;
                }

                Write("{0:%p} ", domains[i].Address);
                Write("{0, -60} ", i == 0 ? "System" : i == 1 ? "Shared" : domains[i].Name);
                Write("{0,6:#,#} ", domains[i].Modules.Count);
                if (!String.IsNullOrEmpty(domains[i].ApplicationBase))
                {
                    Write("Base Path: {0} ", domains[i].ApplicationBase);
                }
                if (!String.IsNullOrEmpty(domains[i].ConfigurationFile))
                {
                    Write("Config: {0} ", domains[i].ConfigurationFile);
                }
                WriteLine("");
            }
        }
Exemple #14
0
        protected override void OnGameLoad()
        {
            MachinaGame.Fullscreen = true;

            var bgScene  = SceneLayers.AddNewScene();
            var bgScene2 = SceneLayers.AddNewScene();
            var bgScene3 = SceneLayers.AddNewScene();


            var gameScene = SceneLayers.AddNewScene();
            var uiScene   = SceneLayers.AddNewScene();
            // SceneLayers.BackgroundColor = Color.Black;

            var bgActor = bgScene.AddActor("Background");

            new BackgroundRenderer(bgActor, gameScene.camera, 0.6f);

            var bgActor2 = bgScene2.AddActor("Background");

            new BackgroundRenderer(bgActor2, gameScene.camera, 1f);

            void StartGame()
            {
                var harness = gameScene.AddActor("Harness", new Vector2(gameScene.camera.ViewportCenter.X, -256));

                var levelIndex = 0;

                var levelTransition = new LevelTransition(harness, levelIndex);
                var player          = new Player(harness);

                new BubbleSpawner(harness, new MinMax <int>(3, 7));
                new Harness(harness);

                var eye         = harness.transform.AddActorAsChild("Eye");
                var eyeRenderer = new EyeRenderer(eye, player, levelTransition);

                var targetReticalActor = gameScene.AddActor("Redical");

                targetReticalActor.transform.Depth -= 20;
                new TargetRedical(targetReticalActor, player);

                {
                    var groupActor = uiScene.AddActor("UI Parent Group");
                    new BoundingRect(groupActor, uiScene.camera.ViewportWidth, uiScene.camera.ViewportHeight);
                    var grp = new LayoutGroup(groupActor, Orientation.Vertical);

                    grp.PixelSpacer(32, (int)(uiScene.camera.ViewportHeight * 9f / 12f));

                    grp.AddBothStretchedElement("TextGroupParent", act =>
                    {
                        var textGroup = new LayoutGroup(act, Orientation.Horizontal);
                        textGroup.HorizontallyStretchedSpacer();
                        textGroup.AddVerticallyStretchedElement("Text", 900, act =>
                        {
                            new BoundedTextRenderer(act, "", MachinaGame.Assets.GetSpriteFont("Roboto"), Color.White, HorizontalAlignment.Left, VerticalAlignment.Top, Overflow.Ignore).EnableDropShadow(Color.Black);
                            new TextCrawlRenderer(act, levelTransition);
                        });
                        textGroup.HorizontallyStretchedSpacer();
                    });

                    grp.PixelSpacer(32, 32);
                }
            }

            var world = gameScene.AddActor("World");

            new WorldStuff(world);

            var menu = gameScene.AddActor("Main Menu");

            new BoundingRect(menu, gameScene.camera.ViewportWidth, gameScene.camera.ViewportHeight);
            var menuLayout = new LayoutGroup(menu, Orientation.Horizontal);

            menuLayout.PixelSpacer(400);
            menuLayout.AddBothStretchedElement("Menu Inner", innerGroupActor =>
            {
                var innerGroup = new LayoutGroup(innerGroupActor, Orientation.Vertical);

                innerGroup.PixelSpacer(250);
                var titleActGroup = innerGroup.AddHorizontallyStretchedElement("Title", 100, titleAct =>
                {
                    new BoundedTextRenderer(titleAct, "Oculus Leviathan", MachinaGame.Assets.GetSpriteFont("Roboto-Big"));
                });

                innerGroup.AddHorizontallyStretchedElement("Subtitle", 64, subtitleAct =>
                {
                    // This was written hours before the deadline, it's spaghetti

                    new BoundedTextRenderer(subtitleAct, "By NotExplosive\n\nThis game is played entirely with the mouse\nPress F4 to toggle fullscreen\n\nMade for Ludum Dare 48 in 72 hours\nHOLD Left Mouse Button to begin", MachinaGame.Assets.GetSpriteFont("Roboto"));

                    float mouseHeldTimer = 0;
                    var mouseHeld        = false;
                    var totalTimer       = 0f;
                    var thresholdMet     = false;

                    var hoc = new AdHoc(subtitleAct);

                    hoc.onMouseButton += (MouseButton button, Vector2 pos, ButtonState state) =>
                    {
                        mouseHeld = button == MouseButton.Left && state == ButtonState.Pressed;
                    };

                    hoc.onUpdate += (float dt) =>
                    {
                        if (!thresholdMet)
                        {
                            if (mouseHeld)
                            {
                                mouseHeldTimer += dt;
                            }
                            else
                            {
                                if (mouseHeldTimer > 0)
                                {
                                    mouseHeldTimer -= dt;
                                }
                            }


                            gameScene.camera.Position = new Vector2(0, MathF.Sin(totalTimer) * 32);

                            if (mouseHeldTimer > 1f)
                            {
                                subtitleAct.RemoveComponent <BoundedTextRenderer>();
                                titleActGroup.actor.Destroy();
                                thresholdMet = true;
                            }
                        }
                        else
                        {
                            // if thresholdMet:
                            mouseHeldTimer -= dt;

                            if (mouseHeldTimer < 0)
                            {
                                menu.Destroy();
                                StartGame();
                            }
                        }

                        if (mouseHeldTimer > 0)
                        {
                            gameScene.camera.Zoom = 1 + EaseFuncs.CubicEaseOut(mouseHeldTimer) / 3;
                        }

                        totalTimer += dt;
                    };
                });
            });
            menuLayout.PixelSpacer(100);

            CommandLineArgs.RegisterFlagArg("edit", () =>
            {
                var curveBrush = gameScene.AddActor("CurveBrush", gameScene.camera.ViewportCenter);
                new CurveEditor(curveBrush);
            });

            if (DebugLevel >= DebugLevel.Passive)
            {
                var debug = gameScene.AddActor("Debug");
                new PanAndZoomCamera(debug, Keys.LeftControl);
            }
        }
        public ParkingSpace GiveParkingSpace(int id)
        {
            Bus bus = Read(id);

            if (bus == null)
            {
                return(null);
            }
            AdHoc adhoc = adHocContainer.Read(id);

            //int adhocType = (int).Type;
            List <ParkingSpace> parkingSpaces = new ParkingSpaceContainer().ReadAll();

            //----------------------------------------------Heeft reparatie?-------------------------------------------------//
            if (bus.PeriodicMaintenance <= DateTime.UtcNow.AddYears(-1) || bus.SmallMaintenance <= DateTime.UtcNow.AddDays(-90))
            {//ja
                return(IsTherePlaceOnParking(parkingSpaces, ParkingTypeEnum.Maintenance, ParkingTypeEnum.NotAvailable));
                //return parkingSpaces.Where(x => x.Type == ParkingTypeEnum.Maintenance && x.Occupied == false).First();
            }
            else
            {//nee
                if (adhoc != null)
                {
                    int adhocTeam = (int)adhoc.Team;
                    //------------------------------------------Heeft Adhoc?-----------------------------------------------------//
                    if (adhocTeam == 1)
                    {//ja schoonmaak
                        return(IsTherePlaceOnParking(parkingSpaces, ParkingTypeEnum.FastCharging, ParkingTypeEnum.Normal));
                    }
                    else if (adhocTeam == 2)
                    {//ja maintenance
                        return(IsTherePlaceOnParking(parkingSpaces, ParkingTypeEnum.Maintenance, ParkingTypeEnum.NotAvailable));
                    }
                    else
                    {//ja anders
                        return(IsTherePlaceOnParking(parkingSpaces, ParkingTypeEnum.Normal, ParkingTypeEnum.FastCharging));
                    }
                }
                else
                {//nee
                    //--------------------------------------Laatste rit?-----------------------------------------------------//
                    if (before5oClock.Hour >= DateTime.Now.Hour || DateTime.Now.Hour >= after11oClock.Hour)
                    {//ja
                        //----------------------------------GEPLANDE SCHOONMAAK?
                        if (bus.SmallCleaning >= DateTime.Now.AddDays(-7) || bus.PeriodicCleaning >= DateTime.Now.AddDays(-21))
                        {//ja
                            return(parkingSpaces.Where(x => x.Type == ParkingTypeEnum.Charging && x.Occupied == false).First());
                        }
                        else
                        {//nee
                            //------------------------------BATTERIJ LAAG?
                            if (bus.BatteryLevel <= 80)
                            {//ja
                                return(IsTherePlaceOnParking(parkingSpaces, ParkingTypeEnum.Charging, ParkingTypeEnum.Normal));
                            }
                            else
                            {//nee
                                return(IsTherePlaceOnParking(parkingSpaces, ParkingTypeEnum.Normal, ParkingTypeEnum.Charging));
                            }
                        }
                    }
                    else
                    {//nee
                        //----------------------------------Batterij Laag?---------------------------------------------------//
                        if (bus.BatteryLevel <= 80)
                        {//ja
                            return(IsTherePlaceOnParking(parkingSpaces, ParkingTypeEnum.FastCharging, ParkingTypeEnum.Normal));
                        }
                        else
                        {//nee
                            return(IsTherePlaceOnParking(parkingSpaces, ParkingTypeEnum.Normal, ParkingTypeEnum.FastCharging));
                        }
                    }
                }
            }
        }
Exemple #16
0
        public void DumpThreads()
        {
            if (m_runtime.PointerSize == 8)
            {
                WriteLine("   Id OSId Address          Domain           Allocation Start:End              COM  GC Type  Locks Type / Status             Last Exception");
            }
            else
            {
                WriteLine("   Id OSId Address  Domain   Alloc Start:End   COM  GC Type  Locks Type / Status             Last Exception");
            }

            foreach (var thread in m_runtime.Threads)
            {
                StringBuilder sb = new StringBuilder();
                ulong         AllocStart;
                ulong         AllocEnd;
                AdHoc.GetThreadAllocationLimits(m_runtime, thread.Address, out AllocStart, out AllocEnd);
                Write("{0,5}", thread.ManagedThreadId);
                if (thread.OSThreadId != 0)
                {
                    Write(" {0:x4}", thread.OSThreadId);
                }
                else
                {
                    Write(" ----");
                }
                Write(" {0:%p} {1:%p} {2:%p}:{3:%p}", thread.Address, thread.AppDomain,
                      AllocStart, AllocEnd);
                Write(" {0}", thread.IsSTA ? "STA " : thread.IsMTA ? "MTA " : "NONE");
                Write(" {0,-11}", thread.GcMode.ToString());
                Write(" {0,2}", thread.LockCount > 9 ? "9+" : thread.LockCount.ToString());

                AddIfTrue(ref sb, thread.IsAbortRequested, "Aborting");
                AddIfTrue(ref sb, thread.IsBackground, "Background");
                AddIfTrue(ref sb, thread.IsDebuggerHelper, "Debugger");
                AddIfTrue(ref sb, thread.IsFinalizer, "Finalizer");
                AddIfTrue(ref sb, thread.IsGC, "GC");
                AddIfTrue(ref sb, thread.IsShutdownHelper, "Shutting down Runtime");
                AddIfTrue(ref sb, thread.IsSuspendingEE, "EESuspend");
                AddIfTrue(ref sb, thread.IsThreadpoolCompletionPort, "IOCPort");
                AddIfTrue(ref sb, thread.IsThreadpoolGate, "Gate");
                AddIfTrue(ref sb, thread.IsThreadpoolTimer, "Timer");
                AddIfTrue(ref sb, thread.IsThreadpoolWait, "Wait");
                AddIfTrue(ref sb, thread.IsThreadpoolWorker, "Worker");
                AddIfTrue(ref sb, thread.IsUnstarted, "NotStarted");
                AddIfTrue(ref sb, thread.IsUserSuspended, "Thread.Suspend()");
                AddIfTrue(ref sb, thread.IsDebugSuspended, "DbgSuspended");
                AddIfTrue(ref sb, !thread.IsAlive, "Terminated");
                AddIfTrue(ref sb, thread.IsGCSuspendPending, "PendingGC");
                Write(" {0,-25}", sb.ToString());
                if (thread.CurrentException != null)
                {
                    Write(" {0}", thread.CurrentException.Type.Name);
                }


                if (thread.IsAbortRequested)
                {
                    sb.Append("Aborting");
                }
                if (thread.IsBackground)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("|");
                    }
                    sb.Append("Background");
                }
                WriteLine("");
            }
        }
Exemple #17
0
        public void DumpClass(ulong MethodTable)
        {
            ClrType type = AdHoc.GetTypeFromMT(m_runtime, MethodTable);

            if (type == null)
            {
                WriteLine("No type with Method Table {0:%p}", MethodTable);
                WriteLine("");
                return;
            }
            string fileName = type.Module == null || !type.Module.IsFile ? "(dynamic)" : type.Module.FileName;

            WriteLine("// Method Table: {0}", MethodTable);
            WriteLine("// Module Address: {0:%p}", type.Module == null ? 0 : type.Module.ImageBase);
            WriteLine("// Debugging Mode: {0}", type.Module == null ? "(NA in Dynamic Module)" : type.Module.DebuggingMode.ToString());
            WriteLine("// Filename: {0}", fileName);
            WriteLine("namespace {0} {1}", type.Name.Substring(0, type.Name.LastIndexOf(".")), "{");

            WriteLine("");
            Write(" ");
            Write("{0}", type.IsInternal ? "internal " : type.IsProtected ? "protected " : type.IsPrivate ? "private " : type.IsPublic ? "public " : "undefinedvisibility ");
            Write("{0}", type.IsSealed ? "sealed " : "");
            Write("{0}", type.IsAbstract ? "abstract " : "");
            Write("{0}", type.IsInterface ? "interface " : "");
            Write("{0}", type.IsValueClass ? "struct " : "");
            Write("{0}", !type.IsValueClass && !type.IsInterface ? "class " : "");
            Write("{0}", type.Name.Split('.')[type.Name.Split('.').Length - 1]);
            if ((type.BaseType != null && type.BaseType.Name != "System.Object") || type.Interfaces.Count > 0)
            {
                Write(": ");
                if (type.BaseType != null && type.BaseType.Name != "System.Object")
                {
                    Write("<link cmd=\"!wclass {0:%p}\">{1}</link>", HeapStatItem.GetMTOfType(type.BaseType), type.BaseType.Name);
                    if (type.Interfaces.Count > 0)
                    {
                        Write(", ");
                    }
                }
                for (int i = 0; i < type.Interfaces.Count; i++)
                {
                    Write("{0}", type.Interfaces[i].Name);
                    if (i < type.Interfaces.Count - 1)
                    {
                        Write(", ");
                    }
                }
            }
            WriteLine("");
            WriteLine("{0}", " {");
            WriteLine("\t//");
            WriteLine("\t// Fields");
            WriteLine("\t//");
            WriteLine("");
            foreach (var field in type.Fields)
            {
                Write("\t");
                PrintFieldVisibility(field);
            }
            WriteLine("");
            WriteLine("\t//");
            WriteLine("\t// Static Fields");
            WriteLine("\t//");
            WriteLine("");
            foreach (var field in type.StaticFields)
            {
                Write("\t");
                PrintFieldVisibility(field, true);
            }

            foreach (var field in type.ThreadStaticFields)
            {
                Write("\t");
                PrintFieldVisibility(field, true);
            }

            var properties =
                from m in type.Methods
                where m.Name.StartsWith("get_") ||
                m.Name.StartsWith("set_")
                orderby m.Name.Substring(4).Split('(')[0], -(int)m.Name[0]
            select m;

            WriteLine("");
            WriteLine("\t//");
            WriteLine("\t// Properties");
            WriteLine("\t//");
            WriteLine("");

            List <string> propstr   = new List <string>();
            int           propCount = 0;

            foreach (ClrMethod met in properties)
            {
                string prop    = met.Name.Substring(4);
                bool   isFirst = propstr.IndexOf(prop) == -1;
                if (isFirst)
                {
                    if (propCount > 0)
                    {
                        WriteLine("\t{0}", "}"); // close previous
                    }
                    Write("\t");
                    if (met.Name.StartsWith("set_"))
                    {
                        Write("{0} ", met.GetFullSignature().Split('(')[1].Split(')')[0]);
                    }
                    else
                    {
                        Write("/* property * / ");
                    }
                    WriteLine("{0}", prop.Split('(')[0]);
                    WriteLine("\t{0}", "{");

                    propstr.Add(prop);
                }
                WriteLine("");
                WriteLine("\t\t// JIT MODE: {0} - THIS IS ONLY VALID FOR .NET 4.5 AND BEYOND", met.CompilationType);
                if (met.NativeCode != ulong.MaxValue)
                {
                    WriteLine("\t\t// Click for breakpoint: <cmd link=\"bp {0:%p}\">{0:%p}</link>", met.NativeCode);
                }
                else
                {
                    WriteLine("\t\t// Not JITTED");
                }
                Write("\t\t{0}", met.IsInternal ? "internal " : met.IsProtected ? "protected " : met.IsPrivate ? "private " : met.IsPublic ? "public " : "");

                WriteLine("{0} {1}", met.Name.Substring(0, 3), " { } ");
                propCount++;
            }
            if (propCount > 0)
            {
                WriteLine("\t{0}", "}"); // close previous
            }
            WriteLine("");
            WriteLine("\t//");
            WriteLine("\t// Methods");
            WriteLine("\t//");
            WriteLine("");

            foreach (var method in type.Methods)
            {
                if (!(method.Name.StartsWith("get_") || method.Name.StartsWith("set_")))
                {
                    WriteLine("");
                    WriteLine("\t// JIT MODE: {0} - THIS IS ONLY VALID FOR .NET 4.5 AND BEYOND", method.CompilationType);
                    if (method.NativeCode != ulong.MaxValue)
                    {
                        WriteLine("\t// Click for breakpoint: <cmd link=\"bp {0:%p}\">{0:%p}</link>", method.NativeCode);
                    }
                    else
                    {
                        WriteLine("\t// Not JITTED");
                    }
                    Write("\t");

                    Write("{0}", method.IsInternal ? "internal " : method.IsProtected ? "protected " : method.IsPrivate ? "private " : method.IsPublic ? "public " : "");
                    Write("{0}", method.IsVirtual ? "virtual " : "");
                    Write("{0}", method.IsStatic ? "static " : "");
                    //Write("{0} ", method.Type == null ? "object" : method.Type.Name);
                    WriteLine("{0}({1};", method.Name, method.GetFullSignature().Split('(')[method.GetFullSignature().Split('(').Length - 1]);
                }
            }

            WriteLine("{0}", " }");
            WriteLine("{0}", "}");
        }
Exemple #18
0
        private void DumpFields(ulong Address, ClrType type = null)
        {
            StartRuntime();
            ClrType obj;

            if (type == null)
            {
                obj = m_heap.GetObjectType(Address);
            }
            else
            {
                obj = type;
            }

            if (cache == null)
            {
                cache = new HeapCache(m_runtime, ShowProgress);
            }
            MDType      tp = new MDType(obj);
            MD_TypeData data;

            tp.GetHeader(Address, out data);
            int count = 0;

            tp.GetAllFieldsDataRawCount(out count);
            int temp = 0;

            MD_FieldData[] fields = new MD_FieldData[count];

            tp.GetAllFieldsDataRaw(data.isValueType ? 1 : 0, count, fields, out temp);

            for (int i = 0; i < count; i++)
            {
                string typeName;
                string Name;
                tp.GetRawFieldTypeAndName(i, out typeName, out Name);
                MD_TypeData fd;
                ClrType     ftp     = AdHoc.GetTypeFromMT(m_runtime, fields[i].MethodTable);
                MDType      ft      = new MDType(ftp);
                ulong       pointer = 0;

                tp.GetRawFieldAddress(Address, data.isValueType ? 1 : 0, i, out pointer);
                if (fields[i].isValueType)
                {
                    ft.GetHeader(pointer, out fd);
                }
                else
                {
                    ft.GetHeader(ReadPointer(pointer), out fd);
                }
                Write("{0:x16} {1:x4} {5:x16} {6} +{2:x4} {3,30} {4,30} {7} ", fd.module,
                      fd.token, fields[i].offset, TrimRight(typeName, 30), Name,
                      data.MethodTable, fields[i].isThreadStatic ? " thread " : fields[i].isStatic ? " Static " : "        ",
                      fields[i].isEnum  ?
                      AdHoc.GetEnumName(ftp,
                                        ReadPointer(pointer) & (fd.size == 4 ?
                                                                0x0000FFFF : ulong.MaxValue))
                    : "" /*cache.GetFieldValue(Address, Name, obj)*/);
                ulong effAddress = pointer;
                if (fd.isValueType)
                {
                    if (fields[i].isEnum)
                    {
                        WriteLine("");
                        continue;
                    }

                    try
                    {
                        WriteLine("{0}", ftp.GetValue(pointer));
                    }
                    catch
                    {
                        WriteLine("{0}", ReadPointer(pointer) & (fd.size == 4 ? 0xFFFFFFFF :
                                                                 fd.size == 8 ? 0x00000000FFFFFFFF : ulong.MaxValue));
                    }
                    continue;
                }
                else
                {
                    if (pointer != 0)
                    {
                        effAddress = ReadPointer(pointer);
                    }

                    Write("({0:x16}) ", effAddress);
                    if (effAddress == 0)
                    {
                        WriteLine("");
                        continue;
                    }
                    if (fd.isString)
                    {
                        string str;

                        tp.GetString(effAddress, out str);
                        Write("{0}", str);
                    }
                    WriteLine("");
                }
            }

            /*
             * var fields =
             *  from f in obj.Fields
             *  orderby f.Offset
             *  select f;
             *
             * foreach (var field in fields)
             * {
             *  WriteLine("{0:x16} {1:x4} +{2:x4} {3,30} {4,30}", field.Type.Module.AssemblyId,
             *      field.Type.MetadataToken, field.Offset, TrimRight(field.Type.Name, 30), field.Name);
             *
             *
             * }
             * if (obj.StaticFields.Count > 0)
             * {
             *  var statFields =
             *      from s in obj.StaticFields
             *      orderby s.Offset
             *      select s;
             *  WriteLine("Static Fields:");
             *  foreach (var field in statFields)
             *  {
             *      WriteLine("{0:x16} {1:x4} +{2:x4} {3,30} {4,30}", field.Type.Module.AssemblyId,
             *          field.Type.MetadataToken, field.Offset, TrimRight(field.Type.Name, 30), field.Name);
             *  }
             * }
             * if (obj.ThreadStaticFields.Count > 0)
             * {
             *  var threadFields =
             *      from t in obj.ThreadStaticFields
             *      orderby t.Offset
             *      select t;
             *  WriteLine("Thread Static Fields:");
             *  foreach (var field in threadFields)
             *  {
             *      WriteLine("{0:x16} {1:x4} +{2:x4} {3,30} {4,30}", field.Type.Module.AssemblyId,
             *          field.Type.MetadataToken, field.Offset, TrimRight(field.Type.Name, 30), field.Name);
             *  }
             *
             * }
             */
        }
Exemple #19
0
 private ulong GetEEClass(ulong MethodTable)
 {
     StartRuntime();
     return(AdHoc.GetEEFromMT(m_runtime, MethodTable));
 }