Skip to content
Back to skills

Layout Review

ASecurity

Reviews the engine object fields the layout inference tool proposes for the Layout_x_x.definition.psv files, class by class, from the evidence in Full Trace exports, then writes reviewed lines and applies the ones the user approves. Use when the user asks to infer, review, check, extend or port engine layouts or offsets, to map the fields of an engine class, to bring the layout to a new SQL Server version, to write or run layout probes, or asks what a field at an offset in an engine object ho...

  • 29 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 24, 2026
databasespythonrustgobashsqldatabasesecurity

Works with

  • mcp

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 24, 2026

npx -y skills add danny-sg/internals-viewer --skill layout-review --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Layout Review?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Layout Review
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/danny-sg-layout-review/badge)](https://www.skillsdirectory.com/skills/danny-sg-layout-review)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: layout-review
description: Reviews the engine object fields the layout inference tool proposes for the Layout_x_x.definition.psv files, class by class, from the evidence in Full Trace exports, then writes reviewed lines and applies the ones the user approves. Use when the user asks to infer, review, check, extend or port engine layouts or offsets, to map the fields of an engine class, to bring the layout to a new SQL Server version, to write or run layout probes, or asks what a field at an offset in an engine object holds.
---

# Layout review

Engine object layouts live in `src/Query/InternalsViewer.Query.FullTrace/Definitions/Layout_<version>.definition.psv`.
Finding fields by hand is slow, so they are found in two passes:

1. **Inference.** The tool in `src/Query/InternalsViewer.Query.FullTrace.LayoutInference` reads Full Trace exports and
   works out what every 8-byte slot of every engine object holds. It replays each object's writes, so it sees every
   value a slot held and the function that wrote it. It follows pointers to their objects, interior pointers to the
   interface they land on, and unclassed blocks to their own fields. It reads inheritance from the order constructors
   stamp vtables, and names fields from rules. It is deterministic and never edits the layout files.
2. **Review.** This skill. You judge what the tool proposes, using the evidence it recorded and more evidence where
   that is thin, write the reviewed lines with a reason for each, and apply them once the user approves.

The tool can also record its own exports with probes: queries that put known values in engine objects, such as
`TOP (54321)`. A slot that holds a known value is identified for certain, so probes settle what inference can only
suggest.

## Run the inference tool

Build it first.

```bash
dotnet build src/Query/InternalsViewer.Query.FullTrace.LayoutInference -p:Platform=x64
```

Run it with an output folder and the exports to read:

```bash
src/Query/InternalsViewer.Query.FullTrace.LayoutInference/bin/x64/Debug/net11.0/InternalsViewer.Query.FullTrace.LayoutInference.exe <output folder> C:\Temp\Traces\Compile C:\Temp\Traces\Path\Q1.ivtrace
```

Every run also reads the probe exports in `<output folder>\Traces`. `--capture` records them first:

```bash
InternalsViewer.Query.FullTrace.LayoutInference.exe C:\Temp\Traces\Probes --capture --server "Server=.;Integrated Security=true;TrustServerCertificate=true"
```

Probes only need capturing once. Later runs with the same output folder read the captured exports again, so capture
again only when a probe or setup script changes, or for another SQL Server version. Keep captures somewhere that lasts,
such as `C:\Temp\Traces\Probes`, rather than the scratchpad.

Capturing:

1. Creates a database named `IVLayoutProbe_<yyyyMMdd_HHmmss>` on the server.
2. Runs the scripts in `ProbeScripts/Setup` in name order. They create and fill a small version of the
   InternalsViewerDemo database.
3. Reads the catalog: object, HoBt, partition and allocation unit ids, and the first, root and first IAM pages of every
   allocation unit.
4. Records each probe with Full Trace, loads it and writes `<output folder>\Traces\<Probe>.ivtrace`, replacing an
   earlier capture of that probe. Next to each export it writes `<Probe>.known.psv`, the values that probe should
   find, with the catalog values added.
5. Drops the database, even when a probe fails or the run is cancelled. `--keep` leaves it for a look afterwards.

Recording needs what Full Trace needs in the app: a SQL Server on this machine, WinDbg with TTD (`--windbg <path>` when it
is not found), the TTD licence accepted, and elevation. Run the tool from an elevated prompt, or Windows asks for
elevation once per probe. Recording can restart the SQL Server service. Ask the user before capturing against their
server, and let them run it when it needs elevation.

A `.known.psv` next to any export is read, so known values work with exports recorded by hand too.

Exports must include compilation and execution setup. The saved ones in `C:\Temp\Traces\Compile` and
`C:\Temp\Traces\Path` do, and probes are recorded with Crop To Query off so theirs do. A run takes about 20 seconds
for six exports. Each layout version found in the exports gets three files, named after the layout file the trace's
server version uses:

| File | What it holds |
| --- | --- |
| `<Layout>.report.txt` | Every class and field, layout classes first, for a person to read |
| `<Layout>.candidates.psv` | The tool's proposed lines, unreviewed |
| `<Layout>.evidence.json` | The same evidence, structured, for this review |

## Write a probe

A probe is a `.sql` file in `ProbeScripts`, or in the folder `--probes` names. Directives in comments above the query
say what to look for:

```sql
-- # Probe: Top
-- # Find: Top Count = 54321 in CQScanTop*
SELECT TOP (54321) Id, TextField
FROM   dbo.ClusteredTable;
```

- `-- # Probe: <Name>` names the probe and its export. Names must be unique.
- `-- # Find: <Field Name> = <Value> [in <Class Pattern>]` names any field that holds the value. Several can follow
  one probe. Without `in`, every class is searched.
- A value is a number (`54321` or `0xD431`), a page (`1:312`), text (`'Probe Sentinel Text'`, matched against UTF-16
  strings a field points to) or a catalog value in braces: `{dbo.ClusteredTable HoBt Id}`,
  `{dbo.ClusteredTable.ix_ClusteredTable_TextField Root Page}` or `{Database Id}`. The catalog values are Object Id,
  Index Id, HoBt Id, Partition Id, Allocation Unit Id, First Page, Root Page and First IAM Page. A table name alone
  means its heap or clustered index.
- The query must be one statement. Separate several probes in one file with `GO`. Setup belongs in `ProbeScripts/Setup`.

Choose values that cannot occur by chance. 54321 finds two fields. 100 finds dozens. Numbers are matched as 8 bytes at
8-byte offsets and as 4 bytes at 4-byte offsets, and pages as 6 bytes (page, then file). The upper half of a slot that
holds a heap address is never matched, because a heap address such as 0x228_xxxx_xxxx reads as page 552 there.

## Query the evidence

The evidence file is several megabytes. Never read it whole. Use the helper:

```bash
python .claude/skills/layout-review/scripts/layout_review.py <evidence.json> queue
python .claude/skills/layout-review/scripts/layout_review.py <evidence.json> class CQScanRangeNew
python .claude/skills/layout-review/scripts/layout_review.py <evidence.json> class CQScanRangeNew --all
python .claude/skills/layout-review/scripts/layout_review.py <evidence.json> bases --status New
python .claude/skills/layout-review/scripts/layout_review.py <evidence.json> matches --status New
python .claude/skills/layout-review/scripts/layout_review.py <evidence.json> find "SetupPrefetch"
python .claude/skills/layout-review/scripts/layout_review.py <evidence.json> unreviewed <reviewed.psv>
```

`queue` orders the classes to review. Tier 1 is layout classes with conflicts, proposed types, base problems or known
values the layout lacks, tier 2 is layout classes with new named fields, and tier 3 is classes outside the layout that
hold a known value or that layout classes point at or lead to. `class` lists a class's known values first and hides
confirmed fields unless `--all` is given. `matches` lists every field that held a known value. `find` searches
writers, names and evidence.

## Reading the evidence

Each field has a status against the layout file:

| Status | Meaning |
| --- | --- |
| Confirmed | The layout has the field and the evidence agrees |
| Typed | The layout has an untyped pointer and the tool found what it points at |
| Conflict | The layout and the evidence disagree |
| New | The layout has nothing at that offset |
| Not Seen | The layout has the field but no export wrote it |

The inferred value kinds:

| Kind | What the slot held |
| --- | --- |
| Object | A pointer to an object of a known class. `Into +0x70` means it points inside the object |
| Self | A pointer into its own object. A pointer to its own slot is a list link |
| Owner | A pointer back to the object that led to this one |
| List | A pointer to a block of pointers to objects |
| Text | A pointer to a wide string |
| Virtual Table | A vtable. At +0x00 it is the class's own. Further in, it names an interface of the class |
| Embedded | Another class's own vtable inside this object, so an embedded member object starts there |
| Code | A pointer into the engine's code that is not a vtable |
| Block | A pointer to an allocation with no class. It is followed and named `<Class>+0x<offset>` |
| Address | A value in the trace's heap range that no recorded block covers |
| Number | Anything else |

Other evidence terms:

- `Named From <function>`: the name came from a function that writes the slot, read as a verb and a type, such as
  `CreateBuffer`. `Type Hint` follows when that type is a known class.
- `Set By <class> Constructor`: the first write came from that constructor, so the field belongs to that class.
- `From <class>`: the layout declares the field in that base class.
- `(Object 12, Number 2)`: the slot held several kinds. A small minority usually means stale or reused memory.
- `<Writer Class> Slot n`: the slot is written by another class's methods, so it is probably part of an embedded object
  of that class.
- The construction chain (`constructed as A > B > C`) lists the vtables stamped at +0x00, base first.
- Confidence: High needs three or more instances that agree. Medium is fewer instances or a numbered name. Low means
  the slot's values disagree.

Known values are listed apart from the inferred fields, under Known Values Found in the report and `matches` in the
evidence. Each has its size (8, 4, or 6 for a page) and its status against the layout:

- `Holds 54321 From Probe Top`: the value and the probe or catalog entry it came from.
- `Constant`: the field kept the value. `Then 54320, 54319`: it moved on after holding it, so it is derived from the
  value, such as a count of rows still to return.
- `Also Holds 65432 As Seek Value`: other probes put their own values in the same field, so it holds whatever the
  query supplies. The names are each probe's role for its value, so name the field for what they have in common.
- `Also Matches <Name>`: another known value is the same number, so the field could be either.
- `In <Field> At 0x368`: the value is inside an embedded structure. The candidate line is for that structure, at the
  offset inside it, such as `BTreeRow` +0x100. A numbered name there was numbered in the outer class, so renumber it.
- A catalog name says what the value is, not what the field is for. A `First Page` field that moves on to the next
  pages is the scan's current page.
- A known value is High confidence even with one instance. Medium means a numbered name or an `Also Matches`.

## Review a class

Work down the queue. For each class:

1. **Known values.** These are the strongest evidence. A New one is a field to add. When the probe found its value in
   two fields, the `Constant` one is the value itself and the one that moves on needs its own name: TOP's
   `Top Count` holds 54321 and `Rows Remaining` counts down from it. A Conflict means the layout reads the slot
   as something else, and the layout is usually wrong.
2. **Bases.** A New base the layout lacks is usually right. When the layout names a different base, the observed class
   may be an intermediate the layout skipped. Propose both lines, the class under the observed base and the observed
   base under the layout's. A base whose constructor never stamps a vtable (an abstract class) cannot be seen, so a
   missing layout base is not a conflict on its own. Check class names exactly: the engine's `DatasetSession` is not
   the layout's `DataSetSession`.
3. **Conflicts.** Decide who is wrong. A minority of other classes is stale or reused memory, and the layout is right.
   Small numbers mixed with pointers suggest a union, so keep the layout's kind and say so. When the evidence is
   consistent and the layout is not, the layout is wrong.
4. **Typed.** Accept the type when one class or class family holds the slot. Prefer the base class the code works
   with.
5. **New.** Name the field for its role, not its type, when the evidence says what the role is:
   - Two pointers to the same class need different names. The interface they land on, or the function that writes
     them, usually tells them apart. A numbered name is a placeholder to resolve, never a final name.
   - Use the writers. `CQScanRowsetNew::SetupPrefetch` writing a pointer says what the pointer is for.
   - Put the field on the class that declares it (`Set By <class> Constructor`), so derived classes inherit it.
   - Leave a number unnamed when nothing says what it counts. Never invent a role.
6. **Dig deeper when the evidence is thin.** When the run is open in the app, the internals-viewer MCP tools show a
   block's writes with their writers (`query_memoryhistory`), what an address is (`query_addressmap`) and the values a
   function was called with (`query_calls`). Otherwise the `internals-viewer:ivtrace` skill reads the export. A probe
   that puts a known value in the field settles it. Say what you checked in the reason.

Names follow the user's rules: Title Case, whole words (no Hungarian prefixes, no abbreviations), no plural type
names, and "etc." rather than "...".

## Write the reviewed file

Write `<Layout>.reviewed.psv` next to the tool's output. Give every class a header and every line a reason, and list
rejected candidates too, so the next review does not repeat the work:

```
# Class: CQScanRowsetNew
# Reason: pointer into RowsetNewSS at its IRowsetFetchNextRow interface, written by QueryInterface in the constructor
CQScanRowsetNew|Fetch Next Row Rowset|0xD0|8|*RowsetNewSS||CQScanRowsetNew::CQScanRowsetNew
# Reject: 0x60 Number, packed values with no writer that says what they are
```

End with suggested rules for the tool (see below). Show the user a short summary per class (what is added, typed,
corrected or rejected), then wait for their approval.

## Apply

Only after the user approves, and only the lines they approve.

- Add each line next to its class's other lines in the layout file for the traces' version. `Base` lines go with the
  other `Base` lines near the top.
- Keep every layout file in step. `EngineLayoutTests.Every_Layout_File_Has_The_Same_Fields` requires the same classes
  and field names in each, so add the line to the other version files too, at the same offset unless a trace of that
  version measured it. Tell the user which offsets are assumed.
- Prefer adding over renaming. Code reads some fields by name, such as `structure.Get("Rowset")`, so search
  `src/Query` for a field's name before renaming it, and rename it in the code in the same change.
- Keep the files' CRLF line endings. Use Edit or Python with `newline=""`, never `sed -i`.
- Run the layout and compilation tree tests:

```bash
dotnet test src/Tests/InternalsViewer.Query.FullTrace.Tests -p:Platform=x64 --filter "FullyQualifiedName~EngineLayout|FullyQualifiedName~Compilation"
```

## Feed decisions back as rules

When a decision applies beyond one field, make it a rule in the tool's definition file,
`src/Query/InternalsViewer.Query.FullTrace.LayoutInference/Definitions/LayoutInference_All.definition.psv`, so the next
run gets it right without a review: `Name` and `List` for a type's field name, `Abbreviation`, `Noise Word`, `Verb`,
`Class Prefix` and `Function Prefix` for naming, and `Skip Writer` for copy routines. Rerun the tool to check the rule
does what was meant.

## Limits

- An export only shows the code paths its query ran. Not Seen means unexercised, not wrong.
- Offsets belong to one version. A field measured on one version is only assumed on another.
- RTTI would give exact base offsets, but exports do not carry the module images it lives in.
- A followed block keeps its `<Class>+0x<offset>` name until the review names its structure.
- Known values come from user tables in the probe database. Columnstore delta store rowgroups and internal tables are
  not in the catalog the tool reads.

Files in this skill

  • SKILL.md15.9 KB
  • scripts/layout_review.py8.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in databases →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.