public void Setup() { this.mr = new MockRepository(); this.sc = new ServiceContainer(); loader = mr.Stub<ILoader>(); arch = mr.StrictMock<IProcessorArchitecture>(); this.listener = mr.Stub<DecompilerEventListener>(); Address dummy; arch.Stub(a => a.TryParseAddress(null, out dummy)).IgnoreArguments().WhenCalled(m => { Address addr; var sAddr = (string)m.Arguments[0]; var iColon = sAddr.IndexOf(':'); if (iColon > 0) { addr = Address.SegPtr( Convert.ToUInt16(sAddr.Remove(iColon)), Convert.ToUInt16(sAddr.Substring(iColon+1))); m.ReturnValue = true; } else { m.ReturnValue = Address32.TryParse32((string)m.Arguments[0], out addr); } m.Arguments[1] = addr; }).Return(false); this.cfgSvc = mr.Stub<IConfigurationService>(); this.sc.AddService<IConfigurationService>(cfgSvc); }
public DataFlowAnalysis(Program program, IImportResolver importResolver, DecompilerEventListener eventListener) { this.program = program; this.importResolver = importResolver; this.eventListener = eventListener; this.flow = new ProgramDataFlow(program); }
public void Setup() { this.mr = new MockRepository(); this.sc = new ServiceContainer(); this.listener = mr.Stub<DecompilerEventListener>(); this.sc.AddService<DecompilerEventListener>(listener); }
public void Setup() { mr = new MockRepository(); sc = new ServiceContainer(); listener = mr.Stub<DecompilerEventListener>(); sc.AddService<DecompilerEventListener>(listener); sc.AddService<DecompilerHost>(new FakeDecompilerHost()); }
public ImportResolver(Project project, Program program, DecompilerEventListener eventListener) { if (project == null) throw new ArgumentNullException("project"); this.project = project; this.program = program; this.eventListener = eventListener; }
/// <summary> /// For each procedure, either use a user-supplied signature, /// or the predefined one. /// </summary> public void BuildSignatures(DecompilerEventListener listener) { foreach (var de in program.Procedures) { if (listener.IsCanceled()) break; BuildSignature(de.Key, de.Value); } }
public void Setup() { this.mr = new MockRepository(); this.mockFactory = new MockFactory(mr); this.sc = new ServiceContainer(); this.cfgSvc = mr.Stub<IConfigurationService>(); this.listener = mr.Stub<DecompilerEventListener>(); this.sc.AddService<IConfigurationService>(cfgSvc); }
public ShingledScanner(Program program, IRewriterHost host, DecompilerEventListener eventListener) { this.program = program; this.host = host; this.eventListener = eventListener; this.bad = program.Platform.MakeAddressFromLinear(~0ul); this.possibleCallDestinationTallies = new Dictionary<Address,int>(); this.possiblePointerTargetTallies = new Dictionary<Address, int>(); this.instructions = new SortedList<Address, MachineInstruction>(); }
public TypedExpressionRewriter(Program program, DecompilerEventListener eventListener) { this.program = program; this.globals = program.Globals; this.eventListener = eventListener; this.compTypes = new DataTypeComparer(); this.tcr = new TypedConstantRewriter(program, eventListener); this.m = new ExpressionEmitter(); this.unifier = new Unifier(); }
public DecompilerDriver(ILoader ldr, IServiceProvider services) { if (ldr == null) throw new ArgumentNullException("ldr"); if (services == null) throw new ArgumentNullException("services"); this.loader = ldr; this.host = services.RequireService<DecompilerHost>(); this.services = services; this.eventListener = services.GetService<DecompilerEventListener>(); }
public static void Rewrite(Program program, DecompilerEventListener listener) { var crw = new CallRewriter(program); foreach (Procedure proc in program.Procedures.Values) { if (listener.IsCanceled()) break; crw.RewriteCalls(proc); crw.RewriteReturns(proc); } }
public IndirectCallRewriter( Program program, SsaState ssa, DecompilerEventListener eventListener) { this.program = program; this.proc = ssa.Procedure; this.ssa = ssa; this.asc = new IndirectCallTypeAscender(program); this.expander = new IndirectCallExpander(ssa); this.ssaIdTransformer = new SsaIdentifierTransformer(ssa); this.eventListener = eventListener; }
public void Setup() { exit = new ExternalProcedure("exit", new FunctionType( null, null, new Identifier("retCode", PrimitiveType.Int32, new StackArgumentStorage(0, PrimitiveType.Int32)))); exit.Characteristics = new ProcedureCharacteristics(); exit.Characteristics.Terminates = true; progMock = new ProgramBuilder(); flow = new ProgramDataFlow(); eventListener = new FakeDecompilerEventListener(); }
public TrashedRegisterFinder2( IProcessorArchitecture arch, ProgramDataFlow flow, Procedure proc, SsaIdentifierCollection ssa, DecompilerEventListener listener) { this.arch = arch; this.progFlow = flow; this.proc = proc; this.ssa = ssa; this.decompilerEventListener = listener; this.flow = new ProcedureFlow2(); }
public void Setup() { this.mr = new MockRepository(); this.sc = new ServiceContainer(); this.eventListener = mr.Stub<DecompilerEventListener>(); this.sc.AddService(typeof(DecompilerEventListener), this.eventListener); var arch = mr.Stub<IProcessorArchitecture>(); var platform = mr.Stub<IPlatform>(); arch.Stub(a => a.WordWidth).Return(PrimitiveType.Word32); platform.Stub(p => p.Architecture).Return(arch); platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.Long)).Return(4); platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.Double)).Return(8); platform.Stub(p => p.PointerType).Return(PrimitiveType.Pointer32); this.program = new Program { Platform = platform }; }
public TypeCollector( TypeFactory factory, TypeStore store, Program program, DecompilerEventListener eventListener) { this.factory = factory; this.store = store; this.program = program; if (eventListener == null) throw new ArgumentNullException("eventListener"); this.eventListener = eventListener; this.asc = new ExpressionTypeAscender(program, store, factory); this.desc = new ExpressionTypeDescender(program, store, factory); }
public void Setup() { mr = new MockRepository(); fakeArch = new FakeArchitecture(); importResolver = mr.StrictMock<IImportResolver>(); callSigs = new Dictionary<Address, FunctionType>(); this.eventListener = new FakeDecompilerEventListener(); arch = fakeArch; var r1 = arch.GetRegister(1); reg1 = new Identifier(r1.Name, PrimitiveType.Word32, r1); this.sc = new ServiceContainer(); sc.AddService<DecompilerHost>(new FakeDecompilerHost()); sc.AddService<DecompilerEventListener>(eventListener); sc.AddService<IFileSystemService>(new FileSystemServiceImpl()); }
public virtual void Setup() { mr = new MockRepository(); eventListener = mr.Stub <DecompilerEventListener>(); }
public CallRewriter(IPlatform platform, ProgramDataFlow mpprocflow, DecompilerEventListener listener) { this.platform = platform; this.mpprocflow = mpprocflow; this.listener = listener; }
public TypeTransformer(TypeFactory factory, TypeStore store, Program program, DecompilerEventListener eventListener) { this.factory = factory; this.store = store; this.program = program; this.eventListener = eventListener; this.unifier = new Unifier(factory, trace); this.visitedTypes = new Dictionary <DataType, DataType>(); }
public AddressContext(Program program, Address addr, DecompilerEventListener decompilerEventListener) { this.program = program; this.addr = addr; this.decompilerEventListener = decompilerEventListener; }
public ImportResolver(Project project, Program program, DecompilerEventListener eventListener) { this.project = project ?? throw new ArgumentNullException("project"); this.program = program; this.eventListener = eventListener; }
public bool ReplaceAll(DecompilerEventListener eventListener) { changed = false; classesVisited = new HashSet <EquivalenceClass>(); this.eventListener = eventListener; // Replace the DataType of all the equivalence classes foreach (TypeVariable tv in store.TypeVariables) { if (eventListener.IsCanceled()) { return(false); } EquivalenceClass eq = tv.Class; if (!classesVisited.Contains(eq)) { classesVisited.Add(eq); var dt = Replace(eq.DataType); eq.DataType = dt; } } // Replace the DataType of all the TypeVariables foreach (TypeVariable tv in store.TypeVariables) { if (eventListener.IsCanceled()) { return(false); } tv.DataType = Replace(tv.DataType); } foreach (EquivalenceClass eq in classesVisited) { if (eventListener.IsCanceled()) { return(false); } if (eq != program.Globals.TypeVariable.Class && (eq.DataType is PrimitiveType || eq.DataType is VoidType || eq.DataType is EquivalenceClass || eq.DataType is CodeType)) { eq.DataType = null; changed = true; continue; } Pointer ptr = eq.DataType as Pointer; if (ptr != null) { eq.DataType = ptr.Pointee; changed = true; continue; } MemberPointer mp = eq.DataType as MemberPointer; if (mp != null) { eq.DataType = mp.Pointee; changed = true; } ArrayType array = eq.DataType as ArrayType; if (array != null) { eq.DataType = array.ElementType; changed = true; } } return(changed); }
public Arm64Relocator(IServiceProvider services, Program program) : base(program) { this.eventListener = services.RequireService <DecompilerEventListener>(); }
public HeuristicScanner(Program program, IRewriterHost host, DecompilerEventListener eventListener) { this.program = program; this.host = host; this.eventListener = eventListener; }
public DataFlowAnalysis(Program prog, DecompilerEventListener eventListener) { this.program = prog; this.eventListener = eventListener; this.flow = new ProgramDataFlow(prog); }
public override Dictionary <string, IDictionary <Address, IAddressable> > GetObjectPlacements(string fileExtension, DecompilerEventListener listener) { this.defaultFile = Path.ChangeExtension(program.Name, fileExtension); this.defaultDataFile = Path.ChangeExtension(program.Name, "globals" + fileExtension); // Find the segment for each procedure var result = new Dictionary <string, IDictionary <Address, IAddressable> >(); foreach (var proc in program.Procedures.Values) { PlaceObject(proc, defaultFile, result); } // Place all global objects. var wl = new WorkList <(StructureField, Address)>( MakeGlobalWorkItems() .Concat(MakeSegmentWorkitems())); var objectTracer = new GlobalObjectTracer(program, wl, listener); while (wl.GetWorkItem(out var item)) { var(field, addr) = item; var globalVar = new GlobalVariable(addr, field.DataType, program.NamingPolicy.GlobalName(field)); PlaceObject(globalVar, defaultDataFile, result); objectTracer.TraceObject(field.DataType, addr); } return(result); }
public DecompiledFileService(IFileSystemService fsSvc, DecompilerEventListener listener) { this.fsSvc = fsSvc; this.listener = listener; }
/// <summary> /// Returns a placement mapping for rendering high-level items. /// </summary> /// <param name="fileExtension"></param> /// <returns></returns> public abstract Dictionary <string, IDictionary <Address, IAddressable> > GetObjectPlacements( string fileExtension, DecompilerEventListener listener);
public ScannerBase(Program program, DecompilerEventListener eventListener) { this.Program = program; this.eventListener = eventListener; this.noDecompiledProcs = new Dictionary <Address, Procedure_v1>(); }
public WebBuilder(Program program, SsaState ssa, Dictionary <Identifier, LinearInductionVariable> ivs, DecompilerEventListener listener) { this.program = program; this.ssa = ssa; this.ssaIds = ssa.Identifiers; this.ivs = ivs; this.listener = listener; this.doms = ssa.Procedure.CreateBlockDominatorGraph(); this.webs = new List <Web>(); this.webOf = new Dictionary <Identifier, Web>(); }
private IScanner CreateScanner(Program program, DecompilerEventListener eventListener) { return new Scanner( program, LoadCallSignatures(program, program.UserCalls.Values), new ImportResolver(project), eventListener); }
public SparseValuePropagation(SsaState ssa, Program program, IDynamicLinker resolver, DecompilerEventListener listener) { this.ssa = ssa; this.listener = listener; this.cmp = new ExpressionValueComparer(); this.ctx = new SparseEvaluationContext(ssa.Procedure.Architecture); this.eval = new Evaluation.ExpressionSimplifier(program.SegmentMap, ctx, listener); }
public GlobalCallRewriter(Program program, ProgramDataFlow mpprocflow, DecompilerEventListener eventListener) : base(program) { this.mpprocflow = mpprocflow; }
public TerminationAnalysis(ProgramDataFlow flow, DecompilerEventListener eventListener) { this.flow = flow; this.eventListener = eventListener; }
public ProjectLoader(IServiceProvider services, ILoader loader, DecompilerEventListener listener) : this(services, loader, new Project(), listener) { }
public virtual void Setup() { mr = new MockRepository(); eventListener = mr.Stub<DecompilerEventListener>(); }
public static ImageSegment?LoadSegment(MemorySegment_v1 segment, IPlatform platform, DecompilerEventListener listener) { if (segment.Name is null) { listener.Warn("Memory map segments must have names."); return(null); } if (!platform.TryParseAddress(segment.Address, out var addr)) { listener.Warn( "Unable to parse address '{0}' in memory map segment {1}.", segment.Address !, segment.Name !); return(null); } if (!uint.TryParse(segment.Size, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var size)) { listener.Warn( "Unable to parse hexadecimal size '{0}' in memory map segment {1}.", segment.Size !, segment.Name !); return(null); } var mem = new ByteMemoryArea(addr, new byte[size]); return(new ImageSegment(segment.Name, mem, ConvertAccess(segment.Attributes))); }
public TableExtent?DiscoverTableExtent(Address addrSwitch, RtlTransfer xfer, DecompilerEventListener listener) { if (!Start(rtlBlock, host.BlockInstructionCount(rtlBlock) - 1, xfer.Target)) { // No registers were found, so we can't trace back. return(null); } while (Step()) { ; } var jumpExpr = this.JumpTableFormat; var interval = this.JumpTableIndexInterval; var index = this.JumpTableIndexToUse; var ctx = new Dictionary <Expression, ValueSet>(new ExpressionValueComparer()); if (index == null) { // Weren't able to find the index register, // try finding it by blind pattern matching. index = this.FindIndexWithPatternMatch(this.JumpTableFormat); if (index == null) { // This is likely an indirect call like a C++ // vtable dispatch. Since these are common, we don't // spam the user with warnings. return(null); } // We have a jump table, and we've guessed the index expression. // At this point we've given up on knowing the exact size // of the table, but we do know that it must be at least // more than one entry. The safest assumption is that it // has two entries. listener.Warn( listener.CreateAddressNavigator(host.Program, addrSwitch), "Unable to determine size of call or jump table; there may be more than 2 entries."); ctx.Add(index, new IntervalValueSet(index.DataType, StridedInterval.Create(1, 0, 1))); } else if (interval.IsEmpty) { return(null); } else if (interval.High == Int64.MaxValue) { // We have no reasonable upper bound. We make the arbitrary // assumption that the jump table has 2 items; it wouldn't // make sense to be indexing otherwise. listener.Warn( listener.CreateAddressNavigator(host.Program, addrSwitch), "Unable to determine the upper bound of an indirect call or jump; there may be more than 2 entries."); var vs = new IntervalValueSet( this.JumpTableIndex !.DataType, StridedInterval.Create(1, interval.Low, interval.Low + 1)); ctx.Add(this.JumpTableIndexToUse !, vs); } else { ctx.Add(this.JumpTableIndex !, new IntervalValueSet(this.JumpTableIndex !.DataType, interval)); } var vse = new ValueSetEvaluator(host.Architecture, host.SegmentMap, ctx, this.processorState); var(values, accesses) = vse.Evaluate(jumpExpr !); var vector = values.Values .TakeWhile(c => !(c is InvalidConstant)) .Take(2000) // Arbitrary limit .Select(ForceToAddress) .TakeWhile(a => !(a is null)) .ToList() !; if (vector.Count == 0) { return(null); } return(new TableExtent { Targets = vector !, Accesses = accesses, Index = index, });
public MipsRelocator(IServiceProvider services, Program program) : base(program) { dcSvc = services.RequireService <DecompilerEventListener>(); }
public bool ReplaceAll(DecompilerEventListener eventListener) { changed = false; classesVisited = new HashSet<EquivalenceClass>(); // Replace the DataType of all the equivalence classes foreach (TypeVariable tv in store.TypeVariables) { if (eventListener.IsCanceled()) return false; EquivalenceClass eq = tv.Class; if (!classesVisited.Contains(eq)) { classesVisited.Add(eq); var dt = Replace(eq.DataType); eq.DataType = dt; } } // Replace the DataType of all the TypeVariables foreach (TypeVariable tv in store.TypeVariables) { if (eventListener.IsCanceled()) return false; tv.DataType = Replace(tv.DataType); } foreach (EquivalenceClass eq in classesVisited) { if (eventListener.IsCanceled()) return false; if (eq != program.Globals.TypeVariable.Class && (eq.DataType is PrimitiveType || eq.DataType is VoidType || eq.DataType is EquivalenceClass || eq.DataType is CodeType)) { eq.DataType = null; changed = true; continue; } Pointer ptr = eq.DataType as Pointer; if (ptr != null) { eq.DataType = ptr.Pointee; changed = true; continue; } MemberPointer mp = eq.DataType as MemberPointer; if (mp != null) { eq.DataType = mp.Pointee; changed = true; } ArrayType array = eq.DataType as ArrayType; if (array != null) { eq.DataType = array.ElementType; changed = true; } } return changed; }
public TypeAnalyzer(DecompilerEventListener eventListener) { this.eventListener = eventListener; }
public Scanner( Program program, IImportResolver importResolver, IServiceProvider services) { this.program = program; this.segmentMap = program.SegmentMap; this.importResolver = importResolver; this.Services = services; this.eventListener = services.RequireService<DecompilerEventListener>(); this.cancelSvc = services.GetService<CancellationTokenSource>(); if (segmentMap == null) throw new InvalidOperationException("Program must have an segment map."); if (program.ImageMap == null) { program.ImageMap = segmentMap.CreateImageMap(); } this.imageMap = program.ImageMap; this.queue = new PriorityQueue<WorkItem>(); this.blocks = new SortedList<Address, BlockRange>(); this.blockStarts = new Dictionary<Block, Address>(); this.pseudoProcs = program.PseudoProcedures; this.importReferences = program.ImportReferences; this.visitedProcs = new HashSet<Procedure>(); this.noDecompiledProcs = new Dictionary<Address, Procedure_v1>(); }
public TypeTransformer(TypeFactory factory, TypeStore store, Program program, DecompilerEventListener eventListener) { this.factory = factory; this.store = store; this.program = program; this.eventListener = eventListener; this.unifier = new Unifier(factory); this.comparer = new DataTypeComparer(); this.visitedTypes = new HashSet <DataType>(); }
public MipsRelocator(IServiceProvider services, Program program) : base(program) { dcSvc = services.RequireService<DecompilerEventListener>(); }
public ScannerInLinq(IServiceProvider services, Program program, IRewriterHost host, DecompilerEventListener eventListener) { this.services = services; this.program = program; this.host = host; this.eventListener = eventListener; }
public NroLoader(IServiceProvider services, ImageLocation imageLocation, byte[] imgRaw) : base(services, imageLocation, imgRaw) { decompilerEventListener = services.RequireService <DecompilerEventListener>(); rdr = new LeImageReader(RawImage, 0); }
public AddressContext(Program prog, Address addr, DecompilerEventListener decompilerEventListener) { this.program = prog; this.addr = addr; this.decompilerEventListener = decompilerEventListener; }
public PtrPrimitiveReplacer(TypeFactory factory, TypeStore store, Program program, DecompilerEventListener eventListener) { this.factory = factory; this.store = store; this.program = program; this.eventListener = eventListener; this.visitedTypes = new HashSet <DataType>(); this.classesVisited = new HashSet <EquivalenceClass>(); }
public Scanner( Program program, IDictionary<Address, ProcedureSignature> callSigs, IImportResolver importResolver, DecompilerEventListener eventListener) { this.program = program; this.image = program.Image; this.imageMap = program.ImageMap; this.importResolver = importResolver; this.callSigs = callSigs; this.eventListener = eventListener; if (imageMap == null) throw new InvalidOperationException("Program must have an image map."); this.queue = new PriorityQueue<WorkItem>(); this.blocks = new Map<Address, BlockRange>(); this.blockStarts = new Dictionary<Block, Address>(); this.pseudoProcs = program.PseudoProcedures; this.vectors = program.Vectors; this.importReferences = program.ImportReferences; this.visitedProcs = new HashSet<Procedure>(); }
public AdjacentBranchCollector(Procedure proc, DecompilerEventListener listener) { this.proc = proc; this.listener = listener; this.cmp = new ExpressionValueComparer(); }
public NroLoader(IServiceProvider services, string filename, byte[] imgRaw) : base(services, filename, imgRaw) { decompilerEventListener = services.RequireService <DecompilerEventListener>(); rdr = new LeImageReader(RawImage, 0); }
public ShingledScanner(Program program, IRewriterHost host, IStorageBinder storageBinder, ScanResults sr, DecompilerEventListener eventListener) { this.program = program; this.host = host; this.storageBinder = storageBinder; this.sr = sr; this.eventListener = eventListener; this.sr.TransferTargets = new HashSet <Address>(); this.sr.DirectlyCalledAddresses = new Dictionary <Address, int>(); this.sr.Instructions = new SortedList <Address, RtlInstructionCluster>(); this.sr.FlatInstructions = new SortedList <Address, ScanResults.instr>(); this.sr.FlatEdges = new List <ScanResults.link>(); this.G = new DiGraph <Address>(); this.Bad = program.Platform.MakeAddressFromLinear(~0ul); G.AddNode(Bad); }
public static void Rewrite( Program program, ProgramDataFlow summaries, DecompilerEventListener eventListener) { GlobalCallRewriter crw = new GlobalCallRewriter(program, summaries, eventListener); foreach (Procedure proc in program.Procedures.Values) { if (eventListener.IsCanceled()) return; ProcedureFlow flow = crw.mpprocflow[proc]; flow.Dump(program.Architecture); crw.AdjustLiveOut(flow); crw.EnsureSignature(proc, flow); crw.AddUseInstructionsForOutArguments(proc); } foreach (Procedure proc in program.Procedures.Values) { if (eventListener.IsCanceled()) return; crw.RewriteCalls(proc); crw.RewriteReturns(proc); } }
public ShingledScanner(Program program, IRewriterHost host, IStorageBinder storageBinder, ScanResults sr, DecompilerEventListener eventListener) { this.program = program; this.host = host; this.storageBinder = storageBinder; this.sr = sr; this.eventListener = eventListener; this.Bad = program.Platform.MakeAddressFromLinear(~0ul, false); }
public StructureAnalysis(DecompilerEventListener listener, Program program, Procedure proc) { this.eventListener = listener; this.program = program; this.proc = proc; }