Exemple #1
0
 public FpuStackReturnGuesser(SsaState ssa, DecompilerEventListener listener)
 {
     this.ssa              = ssa;
     this.ssam             = new SsaMutator(ssa);
     this.ssaIdTransformer = new SsaIdentifierTransformer(ssa);
     this.listener         = listener;
 }
 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;
     this.ssam             = new SsaMutator(ssa);
 }
Exemple #3
0
        private Statement?stmCur;       //$REFACTOR: try to make this a context paramter.

        public ValuePropagator(
            SegmentMap segmentMap,
            SsaState ssa,
            CallGraph callGraph,
            IDynamicLinker dynamicLinker,
            DecompilerEventListener eventListener)
        {
            this.ssa           = ssa;
            this.callGraph     = callGraph;
            this.arch          = ssa.Procedure.Architecture;
            this.eventListener = eventListener;
            this.ssam          = new SsaMutator(ssa);
            this.evalCtx       = new SsaEvaluationContext(arch, ssa.Identifiers, dynamicLinker);
            this.eval          = new ExpressionSimplifier(segmentMap, evalCtx, eventListener);
        }
Exemple #4
0
        /// <summary>
        /// Rewrites CALL instructions to function applications.
        /// </summary>
        /// <remarks>
        /// Converts an instruction:
        /// <code>
        ///   call procExpr
        /// </code>
        /// to one of:
        /// <code>
        ///	 ax = procExpr(bindings);
        ///  procEexpr(bindings);
        /// </code>
        /// </remarks>
        /// <param name="ssaCaller">SSA state of the procedure in which the CALL instruction exists</param>
        /// <param name="stm">The particular statement of the call instruction</param>
        /// <param name="call">The actuall CALL instruction.</param>
        public bool RewriteCall(SsaState ssaCaller, Statement stm, CallInstruction call)
        {
            if (call.Callee is ProcedureConstant callee)
            {
                var procCallee = callee.Procedure;
                var sigCallee  = procCallee.Signature;
                var fn         = new ProcedureConstant(platform.PointerType, procCallee);
                if (sigCallee == null || !sigCallee.ParametersValid)
                {
                    return(false);
                }
                if (stm.LinearAddress == 0x000000000001e32)
                {
                    stm.ToString(); //$DEBUG
                }
                ApplicationBuilder ab = CreateApplicationBuilder(ssaCaller, stm, call, fn);
                var instr             = ab.CreateInstruction(sigCallee, procCallee.Characteristics);
                var instrOld          = stm.Instruction;
                stm.Instruction = instr;
                var ssam = new SsaMutator(ssaCaller);
                ssam.AdjustSsa(stm, call);
                return(true);
            }
            else
            {
                return(false);

#if NOT_READY_YET       //$TODO
                // We have an indirect call with an unknown signature.
                // Use the guessed `uses` and `defs` to construct a signature.
                // It's likely going to be wrong, but it can be overridden with
                // user-provided metadata.
                var sigCallee = MakeSignature(ssaCaller, call.Uses, call.Definitions);
                var ab        = CreateApplicationBuilder(ssaCaller, stm, call, call.Callee);
                var instr     = ab.CreateInstruction(sigCallee, Core.Serialization.DefaultProcedureCharacteristics.Instance);
                stm.Instruction = instr;
                var ssam = new SsaMutator(ssaCaller);
                ssam.AdjustSsa(stm, call);
                return(true);
#endif
            }
        }
Exemple #5
0
 private void BypassRegisterOffsets(Dictionary <Procedure, int?> savedSps, RegisterStorage register)
 {
     foreach (var ssa in this.ssas.Values)
     {
         var callStms = ssa.Procedure.Statements
                        .Where(stm => stm.Instruction is CallInstruction)
                        .ToList();
         var ssam = new SsaMutator(ssa);
         foreach (var stm in callStms)
         {
             var call = (CallInstruction)stm.Instruction;
             if (!((call.Callee as ProcedureConstant)?.Procedure is Procedure proc))
             {
                 continue;
             }
             if (savedSps.TryGetValue(proc, out var delta) &&
                 delta.HasValue)
             {
                 ssam.AdjustRegisterAfterCall(stm, call, register, delta.Value);
             }
         }
     }
 }
Exemple #6
0
 public FpuStackReturnGuesser(SsaState ssa)
 {
     this.ssa              = ssa;
     this.ssam             = new SsaMutator(ssa);
     this.ssaIdTransformer = new SsaIdentifierTransformer(ssa);
 }