Berkeley Packet Filter (BPF) assembler.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 979B

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