module
Docs::A_GETTING_STARTED::DSL_GUIDE
Overview
Declarative DSL & Scoped Pipelines
Crowbar provides an expressive block-based DSL to pinpoint specific regions of data, attach weighted mutators, and calculate post-transform checksums or lengths.
Executive Summary & Key Topics
| Topic | Method / Anchor | Description |
|---|---|---|
| Scopes, Matchers, and Fixup Hooks | .topic_01_scopes_and_fixups |
Scoping byte ranges, regex captures, and repairing headers with fixups. |
Related Guides & Source References
- src/crowbar/dsl/builder.cr
- src/crowbar/selectors/base.cr
Defined in:
docs/a_getting_started/dsl_guide.crClass Method Summary
-
.topic_01_scopes_and_fixups : Nil
Scopes, Matchers, and Fixup Hooks: Scoping byte ranges, regex captures, and repairing headers with fixups.
Class Method Detail
def self.topic_01_scopes_and_fixups : Nil
#
Scopes, Matchers, and Fixup Hooks: Scoping byte ranges, regex captures, and repairing headers with fixups.
Using Crowbar.define, you can isolate portions of an input payload:
| Directive | Syntax | Description | ||
|---|---|---|---|---|
| `seed` | `seed 1234_u64` | Configures the deterministic PRNG | ||
| `pattern` | `pattern :burst` | Sets frequency (:once, :many, :burst) | ||
| `scope` | `scope :header, bytes: 0...16` | Constrains mutation to a byte range | ||
| `match` | `match /"([^"]+)"/, group: 1` | Targets regex match groups | ||
| `fixup` | `fixup do \ | buf\ | ... end` | Post-mutation callback for checksums |
Working Examples
fuzzer = Crowbar.define do
seed 0x1337_u64
pattern :many
# Scope 1: Protect and mutate header
scope :header, bytes: 0...16 do
weight 0.2
mutate :byte_flip, :byte_swap
end
# Scope 2: Mutate payload
scope :payload, bytes: 16.. do
weight 0.8
mutate :boundary_number, :unicode
end
# Fixup: recalculate payload length
fixup do |buffer|
next if buffer.size < 16
len = (buffer.size - 16).to_u32
IO::ByteFormat::BigEndian.encode(len, buffer[0, 4])
end
end