From 7e00666b9f8d3fcdbda94c6f578d4484ed7bc2c7 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Thu, 24 Sep 2020 17:05:24 +0200 Subject: [PATCH] proc: use argument position for addr only when injecting function calls (#2181) * proc: use argument position for addr only when injecting function calls We can not, in general, use the argument position to determine the address of a formal parameter, it will not work in presence of optimizations or inlining. In those cases formal arguments could be stored in registers. Fixes #2176 * Travis-CI: add ignorechecksum option to chocolatey command Looks like a configuration problem on chocolatey's end. Co-authored-by: a --- pkg/proc/eval.go | 7 ++++++- pkg/proc/fncall.go | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index 83a16b10..6563e275 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -51,6 +51,11 @@ type EvalScope struct { // The goroutine executing the expression evaluation shall signal that the // evaluation is complete by closing the continueRequest channel. callCtx *callContext + + // If trustArgOrder is true function arguments that don't have an address + // will have one assigned by looking at their position in the argument + // list. + trustArgOrder bool } // ConvertEvalScope returns a new EvalScope in the context of the @@ -208,7 +213,7 @@ func (scope *EvalScope) Locals() ([]*Variable, error) { return nil, errors.New("unable to find function context") } - trustArgOrder := scope.BinInfo.Producer() != "" && goversion.ProducerAfterOrEqual(scope.BinInfo.Producer(), 1, 12) + trustArgOrder := scope.trustArgOrder && scope.BinInfo.Producer() != "" && goversion.ProducerAfterOrEqual(scope.BinInfo.Producer(), 1, 12) && scope.Fn != nil && (scope.PC == scope.Fn.Entry) dwarfTree, err := scope.image().getDwarfTree(scope.Fn.offset) if err != nil { diff --git a/pkg/proc/fncall.go b/pkg/proc/fncall.go index 0933f947..da7157c2 100644 --- a/pkg/proc/fncall.go +++ b/pkg/proc/fncall.go @@ -806,6 +806,7 @@ func funcCallStep(callScope *EvalScope, fncall *functionCallState, thread Thread // pretend we are still inside the function we called fakeFunctionEntryScope(retScope, fncall.fn, int64(regs.SP()), regs.SP()-uint64(bi.Arch.PtrSize())) + retScope.trustArgOrder = true fncall.retvars, err = retScope.Locals() if err != nil {