Browse Source

Updated README

master
maze 11 months ago
parent
commit
0736fa7caa
1 changed files with 60 additions and 1 deletions
  1. +60
    -1
      README.md

+ 60
- 1
README.md View File

@@ -1,3 +1,62 @@
# bpf

Berkeley Packet Filter (BPF) assembler.
Berkeley Packet Filter (BPF) assembler.

## Installation

Easy as running `go get`:

```console
~$ go get maze.io/x/bpf/cmd/bpfasm
```

## Usage

Compiling an assembly file:

`demo.asm` contents:

```nasm
; icmp random packet sampling, 1 in 4
ldh [12]
jne #0x800, drop
ldb [23]
jneq #1, drop
; get a random uint32 number
ld rand
mod #4
jneq #1, drop
ret #-1
drop: ret #0
```

Assembling to (big endian) binary:

```console
~$ bpfasm assemble demo.asm
writing to demo.asm.bin
```

Disassembling:

```console
~$ bpfasm disassemble demo.asm.bin
ld #12
jeq #2048,6
ld #23
jeq #1,4
ld #rand
mod #4
jeq #1,1
ret #4294967295
ret #0
```

## Copyright

The assembler parser and compiler are © 2019 Wijnand Modderman-Lenstra.

The assembler virtual machine and opcode assembler are © 2009, 2016 The
Go Authors.

For more details, see the [LICENSE](LICENSE).

Loading…
Cancel
Save