github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/report/decompile_test.go (about)

     1  // Copyright 2021 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  package report
     5  
     6  import (
     7  	"reflect"
     8  	"testing"
     9  )
    10  
    11  func TestParseObjdumpOutput(t *testing.T) {
    12  	rawResponse := `
    13  /tmp/binary:     file format binary
    14  
    15  
    16  Disassembly of section .data:
    17  
    18  00000000 <.data>:
    19     0:   55                      push   %ebp
    20     1:   53                      push   %ebx
    21     2:   31 c0                   xor    %eax,%eax
    22     4:   e8 f5 bf f7 ff          call   0xfff7bffe
    23     9:   ff                      (bad)
    24  `
    25  	opcodes := objdumpParseOutput([]byte(rawResponse))
    26  	expected := []DecompiledOpcode{
    27  		{
    28  			Offset:          0,
    29  			Instruction:     "push   %ebp",
    30  			FullDescription: "   0:   55                      push   %ebp",
    31  		},
    32  		{
    33  			Offset:          1,
    34  			Instruction:     "push   %ebx",
    35  			FullDescription: "   1:   53                      push   %ebx",
    36  		},
    37  		{
    38  			Offset:          2,
    39  			Instruction:     "xor    %eax,%eax",
    40  			FullDescription: "   2:   31 c0                   xor    %eax,%eax",
    41  		},
    42  		{
    43  			Offset:          4,
    44  			Instruction:     "call   0xfff7bffe",
    45  			FullDescription: "   4:   e8 f5 bf f7 ff          call   0xfff7bffe",
    46  		},
    47  		{
    48  			Offset:          9,
    49  			Instruction:     "(bad)",
    50  			IsBad:           true,
    51  			FullDescription: "   9:   ff                      (bad)",
    52  		},
    53  	}
    54  	if !reflect.DeepEqual(opcodes, expected) {
    55  		t.Errorf("expected: %#v, got: %#v", expected, opcodes)
    56  	}
    57  }