User-space BPF interpreter, disassembler and debugger in MoonBit.
moon test
moon run cmd/main --target js -- disasm examples/minimal.elf
moon run cmd/main --target js -- run examples/minimal.elf
moon run cmd/main --target js -- run examples/minimal.elf --trace0: mov64 r0, 42
1: exit
r0=0x2a (42)bpflab disasm <file> disassemble with jump/call targets
bpflab run <file> [input-hex] [--trace]
execute and print r0
bpflab elf <file> print entry, sections and symbols| 类别 | 指令 |
|---|---|
| ALU64 | add, sub, mul, div, or, and, lsh, rsh, neg, mod, xor, mov, arsh |
| ALU32 | 同上,结果零扩展到 64 位 |
| 跳转 | ja, jeq, jgt, jge, jset, jne, jsgt, jsge, jlt, jle, jslt, jsle |
| 内存 | ldxb/h/w/dw, stxb/h/w/dw, stb/h/w/dw |
| 其他 | lddw, call (helper 与本地子程序), exit |
pub(all) suberror BpfError {
UnknownOpcode(Int)
DivisionByZero
InvalidRegister(Int)
InvalidProgram(Int)
MemoryAccess(UInt64, Int)
WriteToReadOnly(UInt64)
StepBudgetExceeded
UnknownHelper(Int)
CallDepthExceeded
UnsupportedCallMode(Int)
UnsupportedMapFd
UnknownMap(Int)
MapFull(Int)
MapKeyError(Int)
}pub(all) suberror ElfError {
NotElf
UnsupportedClass
UnsupportedEndian
UnsupportedMachine(Int)
Truncated
BadSection
NoText
}pub(all) struct ElfSection {
name : String
typ : Int
flags : Int
offset : Int
size : Int
}