Browse Source

Updated README

maze 6 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 @@
1 1
 # bpf
2 2
 
3
-Berkeley Packet Filter (BPF) assembler.
3
+Berkeley Packet Filter (BPF) assembler.
4
+
5
+## Installation
6
+
7
+Easy as running `go get`:
8
+
9
+```console
10
+~$ go get maze.io/x/bpf/cmd/bpfasm
11
+```
12
+
13
+## Usage
14
+
15
+Compiling an assembly file:
16
+
17
+`demo.asm` contents:
18
+
19
+```nasm
20
+; icmp random packet sampling, 1 in 4
21
+        ldh 	[12]
22
+        jne 	#0x800, drop
23
+        ldb 	[23]
24
+        jneq 	#1, drop
25
+        ; get a random uint32 number
26
+        ld 		rand
27
+        mod 	#4
28
+        jneq 	#1, drop
29
+        ret 	#-1
30
+drop:	ret 	#0
31
+```
32
+
33
+Assembling to (big endian) binary:
34
+
35
+```console
36
+~$ bpfasm assemble demo.asm
37
+writing to demo.asm.bin
38
+```
39
+
40
+Disassembling:
41
+
42
+```console
43
+~$ bpfasm disassemble demo.asm.bin
44
+ld     #12
45
+jeq    #2048,6
46
+ld     #23
47
+jeq    #1,4
48
+ld     #rand
49
+mod    #4
50
+jeq    #1,1
51
+ret    #4294967295
52
+ret    #0
53
+```
54
+
55
+## Copyright
56
+
57
+The assembler parser and compiler are © 2019 Wijnand Modderman-Lenstra.
58
+
59
+The assembler virtual machine and opcode assembler are © 2009, 2016 The
60
+Go Authors.
61
+
62
+For more details, see the [LICENSE](LICENSE).

Loading…
Cancel
Save