aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/report/decompile_test.go
blob: 7e05561af702a6411cb46a2eeb3332db683b1512 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2021 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package report

import (
	"reflect"
	"testing"
)

func TestParseObjdumpOutput(t *testing.T) {
	rawResponse := `
/tmp/binary:     file format binary


Disassembly of section .data:

00000000 <.data>:
   0:   55                      push   %ebp
   1:   53                      push   %ebx
   2:   31 c0                   xor    %eax,%eax
   4:   e8 f5 bf f7 ff          call   0xfff7bffe
   9:   ff                      (bad)
`
	opcodes := objdumpParseOutput([]byte(rawResponse))
	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)",
		},
	}
	if !reflect.DeepEqual(opcodes, expected) {
		t.Errorf("expected: %#v, got: %#v", expected, opcodes)
	}
}