Skip to content

Commit 522d630

Browse files
Summer Studentsam-f0
authored andcommitted
Add support for Go binaries
1 parent f56944f commit 522d630

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4860
-336
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ Settings are stored in a file `.llef` located in your home directory formatted a
7474
| rebase_offset | Int | Set the rebase offset (default 0x100000) |
7575
| show_all_registers | Boolean | Enable/disable extended register output |
7676
| enable_darwin_heap_scan | Boolean | Enable/disable more accurate heap scanning for Darwin-based platforms. Uses the Darwin malloc introspection API, executing code in the address space of the target application using LLDB's evaluation engine. |
77+
| max_trace_length | Int | Set the maximum length of the call stack backtrace to display |
78+
| stack_view_size | Int | Set the number of entries in the stack read to display |
79+
| max_disassembly_length | Int | Set the maximum number of instructions to disassemble and display around the current PC |
80+
| go_support_level | String | Control Golang-specific analysis. `disable` / `auto` (default) / `force`. Go support in Windows binaries requires `force`. |
81+
| go_confidence_threshold | String | Set the confidence threshold (`low` / `medium` / `high`) for Go objects to be shown in the context view. |
7782

7883
#### llefcolorsettings
7984
Allows setting LLEF GUI colors:
@@ -179,6 +184,36 @@ aabacadaea
179184
[+] Found in $8 at index 0 (little endian)
180185
```
181186

187+
#### (Go) Unpack Type
188+
189+
```
190+
(lldb) go unpack-type 0xc000130000 []main.Country
191+
[{Name:'Japan' Capital:'Tokyo' Continent:'Asia'} {Name:'Germany' Capital:'Berlin' Continent:'Europe'}]
192+
(lldb) go unpack-type 0xc000130000 []main.Country --depth 1
193+
[0xc000142000.. 0xc000142030..]
194+
(lldb) go unpack-type 0xc000142000 main.Country
195+
{Name:'Japan' Capital:'Tokyo' Continent:'Asia'}
196+
(lldb) go unpack-type 0xc000142000 [6]uintptr
197+
[0xc000114140 0x5 0xc000114145 0x5 0xc00011414c 0x4]
198+
```
199+
200+
#### (Go) Find Function
201+
```
202+
(lldb) go find-func main.main
203+
0x55c6894c0280 - main.main (file address = 0x4c0280)
204+
(lldb) go find-func 0x55c689454a3a
205+
0x55c689454a20 - runtime.(*moduledata).textAddr (file address = 0x454a20)
206+
```
207+
208+
#### (Go) Get Type
209+
```
210+
(lldb) go get-type json.mapEncoder --depth 3
211+
json.mapEncoder = struct { elemEnc func(*json.encodeState, struct { typ_ *abi.Type; ptr unsafe.Pointer; flag uintptr }, struct { quoted bool; escapeHTML bool }) }
212+
Size in bytes: 0x8
213+
(lldb) go get-type json.encodeState --depth 1
214+
json.encodeState = struct { Buffer bytes.Buffer; ptrLevel uint; ptrSeen map[interface {}]struct {} }
215+
Size in bytes: 0x38
216+
```
182217

183218
### Breakpoint hook
184219
This is automatic and prints all the currently implemented information at a break point.

arch/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Arch module __init__.py"""
22

3-
from typing import Type
4-
53
from lldb import SBTarget
64

75
from arch.aarch64 import Aarch64
@@ -12,7 +10,12 @@
1210
from arch.x86_64 import X86_64
1311
from common.constants import MSG_TYPE
1412
from common.output_util import print_message
15-
from common.util import extract_arch_from_triple
13+
14+
15+
def extract_arch_from_triple(triple: str) -> str:
16+
"""Extracts the architecture from triple string."""
17+
return triple.split("-")[0]
18+
1619

1720
# macOS devices running arm chips identify as arm64.
1821
# aarch64 and arm64 backends have been merged, so alias arm64 to aarch64.
@@ -29,13 +32,13 @@
2932
}
3033

3134

32-
def get_arch(target: SBTarget) -> Type[BaseArch]:
35+
def get_arch(target: SBTarget) -> type[BaseArch]:
3336
"""Get the architecture of a given target"""
3437
arch = extract_arch_from_triple(target.triple)
3538
return get_arch_from_str(arch)
3639

3740

38-
def get_arch_from_str(arch: str) -> Type[BaseArch]:
41+
def get_arch_from_str(arch: str) -> type[BaseArch]:
3942
"""Get the architecture class from string"""
4043
if arch in supported_arch:
4144
return supported_arch[arch]

arch/aarch64.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Aarch64(BaseArch):
1010

1111
bits = 64
1212

13+
max_instr_size = 4
14+
1315
gpr_registers = [
1416
"x0",
1517
"x1",

arch/arm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Arm(BaseArch):
1010

1111
bits = 32
1212

13+
max_instr_size = 4
14+
1315
gpr_registers = [
1416
"r0",
1517
"r1",

arch/base_arch.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
from abc import ABC, abstractmethod
44
from dataclasses import dataclass
5-
from typing import Dict, List
65

76

87
@dataclass
98
class FlagRegister:
109
"""FlagRegister dataclass to store register name / bitmask associations"""
1110

1211
name: str
13-
bit_masks: Dict[str, int]
12+
bit_masks: dict[str, int]
1413

1514

1615
class BaseArch(ABC):
@@ -23,7 +22,12 @@ def bits(self) -> int:
2322

2423
@property
2524
@abstractmethod
26-
def gpr_registers(self) -> List[str]:
25+
def max_instr_size(self) -> int:
26+
"""Max instruction size (bytes) property"""
27+
28+
@property
29+
@abstractmethod
30+
def gpr_registers(self) -> list[str]:
2731
"""GPR register property"""
2832

2933
@property
@@ -33,5 +37,5 @@ def gpr_key(self) -> str:
3337

3438
@property
3539
@abstractmethod
36-
def flag_registers(self) -> List[FlagRegister]:
40+
def flag_registers(self) -> list[FlagRegister]:
3741
"""List of flag registers with associated bit masks"""

arch/i386.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class I386(BaseArch):
1010

1111
bits = 32
1212

13+
max_instr_size = 15
14+
1315
gpr_registers = [
1416
"eax",
1517
"ebx",

arch/ppc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class PPC(BaseArch):
1010

1111
bits = 32
1212

13+
max_instr_size = 4
14+
1315
gpr_registers = [
1416
"r0",
1517
"r1",

arch/x86_64.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class X86_64(BaseArch):
1010

1111
bits = 64
1212

13+
max_instr_size = 15
14+
1315
gpr_registers = [
1416
"rax",
1517
"rbx",

commands/base_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Base command definition."""
22

33
from abc import ABC, abstractmethod
4-
from typing import Any, Type
4+
from typing import Any, Union
55

66
from lldb import SBCommandReturnObject, SBDebugger, SBExecutionContext
77

@@ -19,7 +19,7 @@ def __init__(self) -> None:
1919

2020
@property
2121
@abstractmethod
22-
def container(self) -> Type[BaseContainer] | None:
22+
def container(self) -> Union[type[BaseContainer], None]:
2323
"""Container property."""
2424

2525
@property

commands/base_settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import argparse
44
import shlex
55
from abc import ABC, abstractmethod
6-
from typing import Any, Dict
6+
from typing import Any, Union
77

88
from lldb import SBCommandReturnObject, SBDebugger, SBExecutionContext
99

@@ -17,9 +17,9 @@ class BaseSettingsCommand(BaseCommand, ABC):
1717

1818
program: str = ""
1919
container = None
20-
settings: BaseLLEFSettings | None = None
20+
settings: Union[BaseLLEFSettings, None] = None
2121

22-
def __init__(self, debugger: SBDebugger, __: Dict[Any, Any]) -> None:
22+
def __init__(self, debugger: SBDebugger, __: dict[Any, Any]) -> None:
2323
super().__init__()
2424
self.parser = self.get_command_parser()
2525

@@ -56,7 +56,7 @@ def __call__(
5656
raise AttributeError("Class not properly initialised: self.settings is None")
5757

5858
if args.action == "list":
59-
self.settings.list()
59+
self.settings.list_settings()
6060
elif args.action == "save":
6161
self.settings.save()
6262
elif args.action == "reload":

0 commit comments

Comments
 (0)