Пример #1
0
        public void TestResolveCallOfCall()
        {
            NfConfig.AssemblySearchPaths.Add(@"C:\Projects\31g\trunk\Code\NoFuture.Tests\ExampleDlls\");
            NfConfig.UseReflectionOnlyLoad = false;
            NoFuture.Util.FxPointers.AddResolveAsmEventHandlerToDomain();
            var testAsm =
                System.Reflection.Assembly.Load(
                    System.IO.File.ReadAllBytes(
                        @"C:\Projects\31g\trunk\Code\NoFuture.Tests\ExampleDlls\AdventureWorks2012.dll"));
            System.Reflection.Assembly.Load(
                    System.IO.File.ReadAllBytes(
                        @"C:\Projects\31g\trunk\Code\NoFuture.Tests\ExampleDlls\Iesi.Collections.dll"));
            System.Reflection.Assembly.Load(
                    System.IO.File.ReadAllBytes(
                        @"C:\Projects\31g\trunk\Code\NoFuture.Tests\ExampleDlls\NHibernate.dll"));
            System.Reflection.Assembly.Load(
                    System.IO.File.ReadAllBytes(
                        @"C:\Projects\31g\trunk\Code\NoFuture.Tests\ExampleDlls\NoFuture.Hbm.Sid.dll"));
            System.Reflection.Assembly.Load(
                    System.IO.File.ReadAllBytes(
                        @"C:\Projects\31g\trunk\Code\NoFuture.Tests\ExampleDlls\SomeSecondDll.dll"));
            System.Reflection.Assembly.Load(
                    System.IO.File.ReadAllBytes(
                        @"C:\Projects\31g\trunk\Code\NoFuture.Tests\ExampleDlls\SomethingShared.dll"));
            System.Reflection.Assembly.Load(
                    System.IO.File.ReadAllBytes(
                        @"C:\Projects\31g\trunk\Code\NoFuture.Tests\ExampleDlls\ThirdDll.dll"));
            var tp = new IaaProgram(new[] {"noop"})
            {
                RootAssembly = testAsm,
                AssemblyNameRegexPattern = "(Some|ThirdDll)"
            };
            tp.Init(testAsm);
            tp.AssignAsmIndicies(testAsm);

            var testAsmTypes = testAsm.GetTypes();

            var testTokens = testAsmTypes.Select(x =>  NoFuture.Util.Gia.AssemblyAnalysis.GetMetadataToken(x)).ToArray();

            var dee = testTokens.FirstOrDefault();
            Assert.IsNotNull(dee);

            var tProgram = new IaaProgram(null);
            var tGetTokenIds = new GetTokenIds(tProgram);

            var testDepth = 0;
            foreach (var iToken in testTokens)
            {
                foreach (var tToken in iToken.Items)
                {
                    foreach (var vToken in tToken.Items)
                    {
                        tGetTokenIds.ResolveCallOfCall(vToken, ref testDepth, new Stack<MetadataTokenId>(), null);
                    }
                }

            }
            Assert.IsNotNull(testTokens);

            //got this from ildasm
            var targetTokenType = 0x2000060;

            Assert.IsTrue(testTokens.Any(x => x.Id == targetTokenType));
            var testTokenRslt = testTokens.First(x => x.Id == targetTokenType);
            var tokenPrint = MetadataTokenId.Print(testTokenRslt);
            System.Diagnostics.Debug.WriteLine(tokenPrint);

            var testFlattenedRslt = MetadataTokenId.FlattenToDistinct(testTokenRslt);
            Assert.IsTrue(tokenPrint.Split('\n').Length >= testFlattenedRslt.Length);

            var testTokenNames =
                tProgram.UtilityMethods.ResolveAllTokenNames(testFlattenedRslt);
            Assert.IsNotNull(testTokenNames);
            Assert.AreNotEqual(0, testTokenNames.Count);

            foreach (var tname in testTokenNames)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("{0}.{1} ({2})", tname.RslvAsmIdx,tname.Id.ToString("X4"), tname.Name));
            }
        }
Пример #2
0
        /// <summary>
        /// Main from which the console is launched.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            var ut = String.Empty;
            var p = new IaaProgram(args);
            try
            {
                p.StartConsole();

                if (p.PrintHelp()) return;
                p.PrintToConsole("New console started!");

                p.ParseProgramArgs();

                //print settings
                p.PrintToConsole($"GetAsmIndicesCmdPort listening on port [{p.GetAsmIndicesCmdPort}]");
                p.PrintToConsole($"GetTokenIdsCmdPort listening on port [{p.GetTokenIdsCmdPort}]");
                p.PrintToConsole($"GetTokenNamesCmdPort listening on port [{p.GetTokenNamesCmdPort}]");
                p.PrintToConsole($"GetTokenPageRankCmdPort listening on port [{p.GetTokenPageRankCmdPort}]");
                p.PrintToConsole($"Resolve GAC Assembly names is [{p.AreGacAssembliesResolved}]");
                p.PrintToConsole("type 'exit' to quit", false);

                //open ports
                p.LaunchListeners();

                //park main
                for (; ; ) //ever
                {
                    ut = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(ut))
                        continue;
                    ut = ut.Trim();
                    if (String.Equals(ut, "exit", StringComparison.OrdinalIgnoreCase))
                        break;
                    if (p.PrintHelp(new [] {ut}))
                    {
                        Console.WriteLine(p.RuntimeHelp());
                    }

                    //handle command from the console.
                    p.RtCommands(ut);
                }
            }
            catch (Exception ex)
            {
                p.PrintToConsole(ex);
            }

            if (string.IsNullOrWhiteSpace(ut) || !ut.StartsWith("exit"))
            {
                Console.ReadKey();
            }
        }
Пример #3
0
 public UtilityMethods(IaaProgram myProgram)
 {
     _myProgram = myProgram;
 }