Skip to content

Commit

Permalink
lift: track instruction operand index for context
Browse files Browse the repository at this point in the history
  • Loading branch information
mewmew committed Jun 13, 2017
1 parent 4d825a9 commit 4aa7c7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions disasm/x86/arg.go
Expand Up @@ -12,17 +12,23 @@ import (

// Arg returns the i:th argument of the instruction.
func (inst *Inst) Arg(i int) *Arg {
return NewArg(inst.Args[i], inst)
arg := NewArg(inst.Args[i], inst)
arg.OpIndex = i
return arg
}

// Reg returns the register at the i:th argument of the instruction.
func (inst *Inst) Reg(i int) *Reg {
return NewReg(inst.Args[i], inst)
reg := NewReg(inst.Args[i], inst)
reg.OpIndex = i
return reg
}

// Mem returns the memory reference at the i:th argument of the instruction.
func (inst *Inst) Mem(i int) *Mem {
return NewMem(inst.Args[i], inst)
mem := NewMem(inst.Args[i], inst)
mem.OpIndex = i
return mem
}

// --- [ argument ] ------------------------------------------------------------
Expand All @@ -34,6 +40,8 @@ type Arg struct {
// Parent instruction; used to calculate relative offsets and retrieve
// symbolic execution information.
Parent *Inst
// Instruction operand index.
OpIndex int
}

// NewArg returns a new x86 argument with the given parent instruction.
Expand All @@ -52,6 +60,8 @@ type Reg struct {
x86asm.Reg
// Parent instruction; used to retrieve symbolic execution information.
Parent *Inst
// Instruction operand index.
OpIndex int
}

// NewReg returns a new x86 register argument with the given parent instruction.
Expand All @@ -74,6 +84,8 @@ type Mem struct {
x86asm.Mem
// Parent instruction; used to retrieve symbolic execution information.
Parent *Inst
// Instruction operand index.
OpIndex int
}

// NewMem returns a new memory reference argument with the given parent
Expand Down
4 changes: 2 additions & 2 deletions lift/argument.go
Expand Up @@ -238,7 +238,7 @@ func (f *Func) mem(mem *x86.Mem) value.Value {
// Handle disposition.
if mem.Disp != 0 {
if context, ok := f.l.Contexts[mem.Parent.Addr]; ok {
if c, ok := context.Args[1]; ok {
if c, ok := context.Args[mem.OpIndex]; ok {
if o, ok := c["Mem.offset"]; ok {
offset := o.Int64()
addr := rel + bin.Address(mem.Disp-offset)
Expand Down Expand Up @@ -728,7 +728,7 @@ func (f *Func) getFunc(arg *x86.Arg) (value.Named, *types.FuncType, ir.CallConv,
}
}

if c, ok := context.Args[0]; ok {
if c, ok := context.Args[arg.OpIndex]; ok {
// TODO: Remove poor man's type propagation once the type analysis and
// data flow analysis phases have been properly implemented.
if param, ok := c["param"]; ok {
Expand Down

0 comments on commit 4aa7c7e

Please sign in to comment.