aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2021-08-19 13:09:46 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2021-08-19 17:15:00 +0200
commitf6c43faab72cc4d24c97287064030de97ab74f4a (patch)
treef258f1686881d9e24c38957e9c6ae275ef284b37
parente2da378b5ceacf2ee1e23913bb1bc4de502f364a (diff)
pkg/report: return more information from opcode decompiler
Let decompiler also parse the exact command name. Perform right trim on the full output line, as it may contain tabs and spaces at the end. Introduce an "-update" flag to facilitate mass updating of opcode decompilation tests after changes to this functionality.
-rw-r--r--pkg/report/decompile.go9
-rw-r--r--pkg/report/decompile_test.go5
-rw-r--r--pkg/report/linux_test.go7
-rw-r--r--pkg/report/testdata/linux/decompile/amd64/0.out2
-rw-r--r--pkg/report/testdata/linux/decompile/amd64/2.out6
5 files changed, 21 insertions, 8 deletions
diff --git a/pkg/report/decompile.go b/pkg/report/decompile.go
index ea352fc29..6f5a6fe41 100644
--- a/pkg/report/decompile.go
+++ b/pkg/report/decompile.go
@@ -10,6 +10,7 @@ import (
"os"
"regexp"
"strconv"
+ "strings"
"time"
"github.com/google/syzkaller/pkg/osutil"
@@ -28,6 +29,7 @@ const objdumpCallTimeout = 10 * time.Second
type DecompiledOpcode struct {
Offset int
IsBad bool
+ Instruction string
FullDescription string
}
@@ -80,11 +82,12 @@ func objdumpParseOutput(rawOutput []byte) []DecompiledOpcode {
if err != nil {
continue
}
- const objdumpBadCommand = "(bad)"
+ const objdumpBadInstruction = "(bad)"
ret = append(ret, DecompiledOpcode{
Offset: int(offset),
- IsBad: result[3] == objdumpBadCommand,
- FullDescription: result[0],
+ IsBad: result[3] == objdumpBadInstruction,
+ Instruction: result[3],
+ FullDescription: strings.TrimRight(result[0], " \t"),
})
}
return ret
diff --git a/pkg/report/decompile_test.go b/pkg/report/decompile_test.go
index 15843de83..c89b88681 100644
--- a/pkg/report/decompile_test.go
+++ b/pkg/report/decompile_test.go
@@ -26,22 +26,27 @@ Disassembly of section .data:
expected := []DecompiledOpcode{
{
Offset: 0,
+ Instruction: "push %ebp",
FullDescription: " 0: 55 push %ebp",
},
{
Offset: 1,
+ Instruction: "push %ebx",
FullDescription: " 1: 53 push %ebx",
},
{
Offset: 2,
+ Instruction: "xor %eax,%eax",
FullDescription: " 2: 31 c0 xor %eax,%eax",
},
{
Offset: 4,
+ Instruction: "call 0xfff7bffe",
FullDescription: " 4: e8 f5 bf f7 ff call 0xfff7bffe",
},
{
Offset: 9,
+ Instruction: "(bad)",
IsBad: true,
FullDescription: " 9: ff (bad)",
},
diff --git a/pkg/report/linux_test.go b/pkg/report/linux_test.go
index ec5eb3c71..bba6326e0 100644
--- a/pkg/report/linux_test.go
+++ b/pkg/report/linux_test.go
@@ -14,6 +14,7 @@ import (
"testing"
"github.com/google/syzkaller/pkg/mgrconfig"
+ "github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/symbolizer"
"github.com/google/syzkaller/sys/targets"
)
@@ -421,12 +422,16 @@ func testDisassembly(t *testing.T, reporter *linux, testFilePrefix string) {
t.Fatalf("failed to read input file: %v", err)
}
+ result := reporter.decompileReportOpcodes(input)
+ if *flagUpdate {
+ osutil.WriteFile(testFilePrefix+".out", result)
+ }
+
output, err := ioutil.ReadFile(testFilePrefix + ".out")
if err != nil {
t.Fatalf("failed to read output file: %v", err)
}
- result := reporter.decompileReportOpcodes(input)
if !bytes.Equal(output, result) {
t.Fatalf("Expected:\n%s\nGot:\n%s\n", output, result)
}
diff --git a/pkg/report/testdata/linux/decompile/amd64/0.out b/pkg/report/testdata/linux/decompile/amd64/0.out
index 1d50e885d..93f0dda98 100644
--- a/pkg/report/testdata/linux/decompile/amd64/0.out
+++ b/pkg/report/testdata/linux/decompile/amd64/0.out
@@ -57,7 +57,7 @@ Code disassembly (best guess), 2 bytes skipped:
19: e8 f4 c7 f6 fd callq 0xfdf6c812
1e: e9 e0 fb ff ff jmpq 0xfffffc03
23: e8 4a a8 b0 fd callq 0xfdb0a872
- 28: 0f 0b ud2 <-- trapping instruction
+ 28: 0f 0b ud2 <-- trapping instruction
2a: e9 97 fb ff ff jmpq 0xfffffbc6
2f: 4c 89 ff mov %r15,%rdi
32: e8 0b c8 f6 fd callq 0xfdf6c842
diff --git a/pkg/report/testdata/linux/decompile/amd64/2.out b/pkg/report/testdata/linux/decompile/amd64/2.out
index 87de89e9e..b5c3e5f63 100644
--- a/pkg/report/testdata/linux/decompile/amd64/2.out
+++ b/pkg/report/testdata/linux/decompile/amd64/2.out
@@ -171,15 +171,15 @@ Code disassembly (best guess):
13: bf 01 00 00 00 mov $0x1,%edi
18: e8 15 2a 09 00 callq 0x92a32
1d: e8 50 84 35 00 callq 0x358472
- 22: fb sti
+ 22: fb sti
23: 65 8b 05 88 91 bc 7e mov %gs:0x7ebc9188(%rip),%eax # 0x7ebc91b2
2a: 85 c0 test %eax,%eax <-- trapping instruction
2c: 74 58 je 0x86
2e: 5b pop %rbx
2f: 5d pop %rbp
- 30: c3 retq
+ 30: c3 retq
31: 65 8b 05 d6 98 bc 7e mov %gs:0x7ebc98d6(%rip),%eax # 0x7ebc990e
38: 85 c0 test %eax,%eax
3a: 75 a2 jne 0xffffffde
- 3c: 0f 0b ud2
+ 3c: 0f 0b ud2
3e: eb 9e jmp 0xffffffde