Metadata-Version: 2.4
Name: unstrip
Version: 2.2.0
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Rust
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Disassemblers
Classifier: Typing :: Typed
License-File: LICENSE-MIT
License-File: LICENSE-APACHE
License-File: unstrip-stdlib/NOTICE
Summary: Recover symbols, types, and method signatures from stripped Go binaries.
Keywords: reverse-engineering,go,golang,binary-analysis,malware-analysis
Home-Page: https://github.com/riven-labs/unstrip
Author-email: Riven Labs <mohamed@riven-labs.com>
License-Expression: MIT OR Apache-2.0
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Changelog, https://github.com/riven-labs/unstrip/blob/main/CHANGELOG.md
Project-URL: Homepage, https://github.com/riven-labs/unstrip
Project-URL: Repository, https://github.com/riven-labs/unstrip

# unstrip

Python bindings for [unstrip](https://github.com/riven-labs/unstrip), which recovers function names, method signatures, types, interface dispatch tables and build metadata from stripped Go binaries.
ELF, Mach-O and PE; amd64, arm64 and 386, and the code of 32-bit arm, mips, ppc64 and riscv64 builds; Go 1.2 through 1.27 (types and itabs from Go 1.7).
The bindings call the same Rust code as the `unstrip` command, so they report what the CLI reports.

```
pip install unstrip
```

Wheels are built for CPython 3.9 and newer (one abi3 wheel per platform) on Linux x86_64 and aarch64 (manylinux), macOS arm64 and Windows x86_64.
Other platforms build from the source distribution, which needs a Rust toolchain (1.85 or newer).

## Use

`unstrip.open(path)` reads a binary, `unstrip.parse(data)` reads one from bytes.
The binary's methods return plain objects: frozen, compared by value, with a `repr` that lists their fields.

```python
import unstrip

binary = unstrip.open("beacon")
print(binary)

info = binary.info()
print(info.go_version, info.goos, info.goarch, info.garble.verdict)

for f in binary.functions():
    if f.name in ("main.(*Beacon).seal", "fmt.Sprintf"):
        print(f"{f.entry:#x}  {f.name}{f.signature}  ({f.signature_source})")
```

```
<unstrip.Binary ELF amd64 go1.24.13>
go1.24.13 linux amd64 clean
0x4d7520  fmt.Sprintf(format string, a ...any) string  (stdlib)
0x633800  main.(*Beacon).seal(_0 []uint8) ([]uint8, error)  (reflection)
```

A method's signature comes from its func type in the binary, which records no parameter names (`_0`, `_1`).
A standard library function's comes from a per-release table built from the Go API snapshots Ghidra ships, with names; `signature_release` says which release.
Other free functions have none: the binary does not record their signatures.

PC lookup lists every frame at a PC, inlined ones first, the physical function last:

```python
run = next(f for f in binary.functions() if f.name == "main.(*Beacon).Run")
for frame in binary.pc_location(run.entry + 0x40).frames:
    print(frame.function, frame.line, "inlined" if frame.inlined else "physical")
```

```
os.Hostname 9 inlined
main.(*Beacon).Run 81 physical
```

Types carry their names as Go source writes them, struct fields with offsets and tags, and method tables; itabs give each (interface, concrete type) pair and the code its methods dispatch to:

```python
beacon = next(t for t in binary.types() if t.name == "main.Beacon")
for field in beacon.fields:
    print(f"+{field.offset:#04x}  {field.name} {field.type}  {field.tag}".rstrip())

for itab in binary.itabs():
    if itab.interface == "main.Transport":
        print(itab.concrete, [m.name for m in itab.methods])
```

```
+0x00  ID string  json:"id"
+0x10  Interval time.Duration  json:"interval"
+0x18  transports []main.Transport
+0x30  aead cipher.AEAD
+0x40  mu sync.Mutex
+0x48  sent int
*main.httpTransport ['Name', 'Send']
main.dnsTransport ['Name', 'Send']
```

`strings()` returns the string literals the code is proven to use, each with the instructions that use it (amd64, arm64, 386, 32-bit arm, mips, ppc64 and riscv64):

```python
for literal in binary.strings():
    if literal.text == "http://127.0.0.1:9/c":
        print(literal)
```

```
Literal(addr=0x71b0d9, length=20, text='http://127.0.0.1:9/c', origin='literal', uses=[LiteralUse(pc=0x633b7b, function='main.main', function_entry=0x633a80, site='store')], headers=[])
```

`origin(name)` says where a function's code comes from, by the build info, as `--own` decides it: `own` (package main and the main module), `dependency`, `stdlib`, `generated` or `undecided` (a package the build info does not place, such as a garbled path). `[f for f in binary.functions() if binary.origin(f.name) == "own"]` is the program's own code.

`garble()` gives the garble verdict and the signals behind it, `reflect_names()` the table of hashed names to the original ones that garble keeps for reflection, and `unstrip.diff(old, new)` pairs the functions of two builds, two garble seeds of one program included:

```python
old = unstrip.open("beacon-seed1")
new = unstrip.open("beacon-seed2")
print(old.garble().verdict, len(old.reflect_names()))

report = unstrip.diff(old, new)
print(report.old_total, report.identical, report.renamed, report.ambiguous_old)
print(next(p for p in report.pairings if p.kind == "renamed" and p.method == "code"))
```

```
garbled 981
5944 1518 3720 669
Pairing(kind='renamed', method='code', confidence='high', old_addr=0x46bca0, new_addr=0x46bca0, old_name='sync/atomic.J1ajpGx', new_name='sync/atomic.VrtRZg8q', old_reflect_name=None, new_reflect_name=None)
```

`buildinfo()` returns the module information `go version -m` prints, with `settings` as a dict in the order the build wrote them.

A file that does not read as a Go binary raises `unstrip.UnstripError` with the reason; a file that cannot be read raises the `OSError` the system gave:

```python
try:
    unstrip.parse(b"MZ" + bytes(62))
except unstrip.UnstripError as err:
    print(err)
```

```
Go metadata does not decode: goblin: Malformed entity: PE header is malformed (signature 0x5a4d)
```

Every method reads its part of the binary on each call, so keep a result you need twice.
The reads that walk the whole binary release the GIL, so threads can read several binaries at once.
The package ships type hints (`py.typed`); the stub lists every class and field.

## License

MIT or Apache-2.0, at your option.
The standard library signature table is Apache-2.0 only, derived from the Go API snapshots in [Ghidra](https://github.com/NationalSecurityAgency/ghidra); its NOTICE ships in the wheel.

