Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"permissions": {
"allow": [
"Bash(dir:*)",
"Bash(findstr:*)"
"Bash(findstr:*)",
"Bash(export PATH=\"/c/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64:$PATH\")",
"Bash(cargo test:*)",
"Bash(cargo check:*)"
]
}
}
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["tests", "bb-types", "util/bb-clang", "util/bb-shared", "util/bb-sdk", "util/bb-cli", "util/bb-tui", "bb-consts", "bb-consts-tui", "bb-types-tui", "bb-funcs"]
members = ["tests", "bb-types", "util/bb-arch", "util/bb-clang", "util/bb-shared", "util/bb-sdk", "util/bb-cli", "util/bb-tui", "bb-consts", "bb-consts-tui", "bb-types-tui", "bb-funcs"]
resolver = "3"

[workspace.package]
Expand All @@ -14,6 +14,7 @@ keywords = ["windows", "cli", "tui", "parser"]
categories = ["command-line-utilities", "development-tools", "parsing-tools"]

[workspace.dependencies]
bb-arch = { path = "util/bb-arch" }
bb-clang = { path = "util/bb-clang" }
bb-shared = { path = "util/bb-shared" }
bb-sdk = { path = "util/bb-sdk" }
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,24 @@ bb-consts --name "_MINIDUMP_TYPE::*"
bb-types --arch arm64 --struct _CONTEXT
```

**Inspect a function's ABI breakdown:**

```bash
bb-funcs --name CreateFileW
```

**List exported functions from a header:**

```bash
bb-funcs --name "Create*" --filter fileapi.h --exported
```

**Export as JSON for your own tooling:**

```bash
bb-types --arch arm64 --struct _CONTEXT --json
bb-consts --name "PROCESS_*" --json
bb-funcs --name "Nt*" --phnt --json
```

JSON mode in `bb-types` performs full nested type expansion, producing all matched types alongside their deduplicated `referenced_types` — regardless of the `--depth` flag.
Expand Down Expand Up @@ -176,6 +189,7 @@ error: no structs matching '_PBE'
| --- | --- |
| [`bb-types`](bb-types/) | Inspect struct and class layouts |
| [`bb-consts`](bb-consts/) | Inspect constants, enums, and `#define` macros |
| [`bb-funcs`](bb-funcs/) | Inspect function declarations with ABI parameter locations |

</td>
<td width="50%" valign="top">
Expand All @@ -200,7 +214,8 @@ error: no structs matching '_PBE'

| Crate | What it does |
| --- | --- |
| [`bb-clang`](util/bb-clang/) | libclang abstractions for types and constants |
| [`bb-arch`](util/bb-arch/) | Architecture definitions, register sets, and ABI location types |
| [`bb-clang`](util/bb-clang/) | libclang abstractions for types, constants, and functions |
| [`bb-sdk`](util/bb-sdk/) | Windows SDK / PHNT header management |
| [`bb-cli`](util/bb-cli/) | Shared CLI argument definitions |
| [`bb-tui`](util/bb-tui/) | Shared TUI framework on [`ratatui`](https://ratatui.rs/) |
Expand All @@ -213,13 +228,7 @@ error: no structs matching '_PBE'

### Future support

Support for functions is currently in development, to be implemented with [sparse](https://github.com/cristeigabriela/sparse).


<p align="center">
<img src="https://raw.githubusercontent.com/cristeigabriela/sparse/master/media/diagram.png#gh-light-mode-only" alt="A diagram illustrating the process described below." width="75%">
<img src="https://raw.githubusercontent.com/cristeigabriela/sparse/master/media/diagram-dark-mode.png#gh-dark-mode-only" alt="A diagram illustrating the process described below." width="75%">
</p>
Function support is implemented. Future integration with [sparse](https://github.com/cristeigabriela/sparse) is planned for deeper analysis.

---

Expand Down Expand Up @@ -261,7 +270,7 @@ bb-consts --phnt --name "STATUS_*"

## Architecture support

Both tools support cross-compilation via `--arch` — inspect struct layouts for any target from any host:
All tools support cross-compilation via `--arch` — inspect layouts and ABIs for any target from any host:

| Flag | Target | Notes |
| --- | --- | --- |
Expand Down
2 changes: 1 addition & 1 deletion bb-consts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This also works for `--enum` patterns.

---

### Shared with `bb-types`
### Shared with `bb-types` and `bb-funcs`

<details>
<summary>Expand shared arguments</summary>
Expand Down
1 change: 1 addition & 0 deletions bb-consts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pub fn iter_constants<'a>(tu: &'a TranslationUnit<'a>) -> impl Iterator<Item = E

/// Build a name -> value lookup table from all known constants (used for
/// display-time composition rendering).
#[must_use]
pub fn build_lookup_table(enums: &[Enum], vars: &[Constant]) -> ConstLookup {
let mut known = HashMap::new();
for e in enums {
Expand Down
105 changes: 105 additions & 0 deletions bb-funcs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# bb-funcs

> CLI application for querying and exporting `Function` entities from **Windows SDK** / **PHNT** headers.

`bb-funcs` is a CLI application dedicated to querying, and exporting, information extracted from `Function` entities with `bb-clang`, from the respective SDK (**Windows SDK**/**PHNT**) of your choice.

Each function is parsed with full ABI awareness: the target architecture is detected from the translation unit, and every parameter is assigned its calling-convention location (register, stack offset, or indirect pointer).

---

## Arguments

### Specific to `bb-funcs`

| Flag | Description |
| --- | --- |
| `--name` / `-n` | Function name pattern (supports `*` wildcard) |
| `--filter` / `-H` | Filter your searches to a specific header |
| `--case-sensitive` / `-c` | Case-sensitive matching |
| `--exported` | Show only exported (dllimport) functions |
| `--params` / `-p` | Filter by parameter count (`3`, `0`, `3..7`, `3..`, `..5`) |
| `--param-type` | Parameter type pattern with `...` for gaps and `_` for any single type (see below) |
| `--return` / `-r` | Filter by return type (supports `*` wildcard, e.g., `BOOL`, `void`, `*STATUS*`) |
| `--has-body` | Show only functions with a body (definition, not just declaration) |
| `--sort` | Sort results (`params`, `name`) |
| `--detail` / `-d` | Force detailed ABI breakdown for all results (auto when single result) |
| `--json` | Output as JSON |

When a query matches exactly one function, the detailed ABI breakdown is shown automatically. Use `-d` to force detail mode for multiple results.

Filters are combined with AND logic — `--params 1 --return BOOL` shows functions with exactly 1 parameter that return BOOL.

#### `--param-type` syntax

Comma-separated positional slots. Use `...` for "any number of params" and `_` for "any single type":

| Pattern | Meaning |
| --- | --- |
| `HANDLE,_,DWORD` | Param 0 = HANDLE, 1 = any, 2 = DWORD (exactly 3 params) |
| `HANDLE,...` | HANDLE at position 0, any number of params after |
| `...,HANDLE,...` | HANDLE at any position |
| `HANDLE,...,DWORD` | HANDLE at 0, then DWORD at some later position (exactly) |
| `...,HANDLE,...,DWORD,...` | HANDLE then DWORD somewhere, any surrounding params |
| `HANDLE,DWORD,...,BOOL` | HANDLE,DWORD at 0-1, then BOOL as last param |

Type slots also support `*` glob wildcards (e.g., `*HANDLE*` matches `LPHANDLE`).

---

### Fuzzy suggestions

When an exact (non-wildcard) name doesn't match anything, `bb-funcs` suggests close matches:

```bash
bb-funcs --name CloseHandl
error: no functions matching 'CloseHandl'

did you mean?

CloseHandle
```

---

### Examples

```bash
# Functions with exactly 7 parameters in fileapi.h
bb-funcs --filter fileapi.h --params 7

# Functions that take a HANDLE parameter, sorted by param count
bb-funcs --param-type HANDLE --filter handleapi.h --sort params

# Functions returning BOOL with 5+ parameters
bb-funcs --return BOOL --params 5..

# Functions with 0 parameters (no-arg functions)
bb-funcs --filter errhandlingapi.h --params 0

# All exported functions in a header, sorted by name
bb-funcs --filter processthreadsapi.h --exported --sort name
```

---

### Shared with `bb-types` and `bb-consts`

<details>
<summary>Expand shared arguments</summary>

<br>

These arguments are managed by [`bb-cli`](./util/bb-cli/) and are shared across all CLI apps.

| Flag | Default | Description |
| --- | --- | --- |
| `--winsdk [VERSION]` | *(default SDK)* | Use Windows SDK headers. Optionally specify a version present in your environment |
| `--phnt [VERSION]` | -- | Use PHNT headers instead. Optionally specify a Windows version target |
| `--mode` / `-m` | `user` | `user` or `kernel` (defines `_KERNEL_MODE` for kernel) |
| `--arch` / `-a` | host | `x86` / `amd64` / `arm` / `arm64` -- supports cross-compilation |
| `--diagnostics` | off | Show Clang diagnostics. Useful for troubleshooting |

**PHNT version targets:** `win2k` `win-xp` `ws03` `vista` `win7` `win8` `win-blue` `threshold` `threshold2` `redstone` `redstone2` `redstone3` `redstone4` `redstone5` `19H1` `19H2` `20H1` `20H2` `21H1` `Win10-21H2` `Win10-22H2` `win11` `Win11-22H2`

</details>
Loading
Loading