Ejemplo n.º 1
0
        public void Rcfg_LoadArchitecture_UnknownModel()
        {
            var cfgSvc = new RekoConfigurationService(sc, "reko.config", new RekoConfiguration_v1
            {
                Architectures = new[] {
                    new Architecture_v1
                    {
                        Name   = "fake",
                        Type   = typeof(FakeArchitecture).AssemblyQualifiedName,
                        Models = new[]
                        {
                            new ModelDefinition_v1
                            {
                                Name    = "Fake-2000",
                                Options = new[]
                                {
                                    new ListOption_v1 {
                                        Text = ProcessorOption.WordSize, Value = "32"
                                    }
                                }
                            }
                        }
                    }
                }
            });

            pluginSvc.Setup(p => p.GetType(It.IsAny <string>()))
            .Returns(typeof(FakeArchitecture));

            var arch = cfgSvc.GetArchitecture("fake", "Unknown Model");

            Assert.AreEqual("WarningDiagnostic -  - Model 'Unknown Model' is not defined for architecture 'fake'.", listener.LastDiagnostic);
        }
Ejemplo n.º 2
0
        public void Rcfg_LoadArchitectureModel()
        {
            var cfgSvc = new RekoConfigurationService(sc, "reko.config", new RekoConfiguration_v1
            {
                Architectures = new[] {
                    new Architecture_v1
                    {
                        Name   = "fake",
                        Type   = typeof(FakeArchitecture).AssemblyQualifiedName,
                        Models = new[]
                        {
                            new ModelDefinition_v1
                            {
                                Name    = "Fake-2000",
                                Options = new[]
                                {
                                    new ListOption_v1 {
                                        Text = ProcessorOption.WordSize, Value = "32"
                                    }
                                }
                            }
                        }
                    }
                }
            });

            pluginSvc.Setup(p => p.GetType(It.IsAny <string>()))
            .Returns(typeof(FakeArchitecture));

            var arch    = cfgSvc.GetArchitecture("fake", "Fake-2000");
            var options = arch.SaveUserOptions();

            Assert.AreEqual("Fake-2000", options[ProcessorOption.Model]);
            Assert.AreEqual("32", options[ProcessorOption.WordSize]);
        }
Ejemplo n.º 3
0
        private void DecompileRawImage(DecompilerDriver dec, Dictionary <string, object> pArgs)
        {
            var arch = config.GetArchitecture((string)pArgs["--arch"]);

            if (arch == null)
            {
                throw new ApplicationException(string.Format("Unknown architecture {0}", pArgs["--arch"]));
            }

            object sEnv;

            pArgs.TryGetValue("--env", out sEnv);

            Address addrBase;
            Address addrEntry;

            if (!arch.TryParseAddress((string)pArgs["--base"], out addrBase))
            {
                throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
            }
            if (pArgs.ContainsKey("--entry"))
            {
                if (!arch.TryParseAddress((string)pArgs["--base"], out addrEntry))
                {
                    throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
                }
            }
            else
            {
                addrEntry = addrBase;
            }


            var state = CreateInitialState(arch, pArgs);

            dec.LoadRawImage((string)pArgs["filename"], (string)pArgs["--arch"], (string)sEnv, addrBase);
            dec.Project.Programs[0].EntryPoints.Add(
                addrEntry,
                new ImageSymbol(addrEntry)
            {
                ProcessorState = state
            });
            object oHeur;

            if (pArgs.TryGetValue("heuristics", out oHeur))
            {
                dec.Project.Programs[0].User.Heuristics = ((string[])oHeur).ToSortedSet();
            }
            dec.ScanPrograms();
            dec.AnalyzeDataFlow();
            dec.ReconstructTypes();
            dec.StructureProgram();
            dec.WriteDecompilerProducts();
        }
Ejemplo n.º 4
0
        private (IProcessorArchitecture, InstrRenderer) ProcessArgs(IEnumerable <string> args)
        {
            string?archName  = DefaultArchName;
            var    maxLength = DefaultMaxInstrLength;

            var it = args.GetEnumerator();

            while (it.MoveNext())
            {
                bool   res = true;
                string arg = it.Current;

                switch (arg)
                {
                case "-a":
                case "--arch":
                    res = TryTake(it, out archName);
                    break;

                case "--maxlen":
                    res = TryTake(it, out string?maxLengthStr) && int.TryParse(maxLengthStr, out maxLength);
                    break;

                case "-r":
                case "--random":
                    this.useRandomBytes = true;
                    int seedValue;
                    if (TryTake(it, out string?seedString))
                    {
                        if (int.TryParse(seedString, out seedValue))
                        {
                            this.seed = seedValue;
                        }
                        else
                        {
                            Console.Error.WriteLine("Invalid seed value '{0}'.", seedString);
                        }
                    }
                    break;

                case "-l":
                case "--llvm":
                    res = TryTake(it, out string?llvmArch);
                    if (res)
                    {
                        processInstr = this.CompareWithLlvm;
                    }
                    otherDasm = new LLVMDasm(llvmArch !);
                    break;

                case "-o":
                case "--objdump":
                    res = TryTake(it, out string?objdumpTarget);
                    if (res)
                    {
                        var    parts = objdumpTarget !.Split(',', 2);
                        string arch  = parts[0];

                        // $TODO: machine parameter
                        // string mach = parts[1];
                        // $TODO: convert machine to uint (BfdMachine)

                        otherDasm    = new ObjDump(arch);
                        processInstr = this.CompareWithObjdump;
                    }
                    break;

                case "-c":
                case "--count":
                    if (TryTake(it, out var sCount) && long.TryParse(sCount, out var count))
                    {
                        this.count = count;
                    }
                    else
                    {
                        res = false;
                    }
                    break;

                case "-h":
                case "--help":
                    res = false;
                    break;
                }

                if (!res)
                {
                    Usage();
                    Environment.Exit(1);
                }
            }

            this.maxInstrLength = maxLength;
            return(
                cfgSvc.GetArchitecture(archName),
                InstrRenderer.Create(archName !));
        }