Linear 0.5.0
dotnet add package Linear --version 0.5.0
NuGet\Install-Package Linear -Version 0.5.0
<PackageReference Include="Linear" Version="0.5.0" />
<PackageVersion Include="Linear" Version="0.5.0" />
<PackageReference Include="Linear" />
paket add Linear --version 0.5.0
#r "nuget: Linear, 0.5.0"
#:package Linear@0.5.0
#addin nuget:?package=Linear&version=0.5.0
#tool nuget:?package=Linear&version=0.5.0
Linear
Linear file structure ingest library
This library uses structure specification files to read structured data from files.
The command-line program lyn provides a simple means for using a structure file to lay out an input file and dump its outputs.
Installation: dotnet tool install -g lyn
Usage: lyn export <structureFile> <inputFile> <outputDir>
LinearParser.g4
For structure file examples, see the sample folder.
Also check the parser grammar file which has comments for significant elements.
ANTLR4 generates the structure file parser.
Writing structure files
Example
// Structure files follow a simple format.
// For lyn command-line programs, a 'main' struct is needed.
main {
// '`' means deserialize. Type is taken from type marker intb.
intb numEntries `0x4;
// Plain array of 'file' objects starting at 0x10, numEntries elements.
file[numEntries] entries 0x10;
}
// Structure named 'file' with raw size 0x8 (used in plain arrays)
file 0x8 {
// Can use explicit deserializer name to get
// data with 'intb' deserializer at offset 0.
var offsetChunk intb`0;
intb length `0x4;
// Variable depending on offsetChunk.
int offset (offsetChunk * 0x800);
// Call registered function 'log' with another call to 'format' (uses string.Format).
// $i is a replacement for the array index.
$call log(format("Entry {0} offset {1} length {2}", $i, offset, length));
// Export content using the 'data' (direct) exporter.
// Format name (again using string.Format).
// $a is a replacement for the absolute position of the structure in the stream.
$output data [offset - $a, length] format("{0:D6}.dat", $i);
}
Ranges
Some deserializers like string and string16 need a range instead of an offset.
These ranges are expressed as [<sourceOffset>..<endOffsetExclusive>] and [<sourceOffset>, <length>]
Standard deserializers
| Type | Description |
|---|---|
| buf | Byte buffer |
| byte | 8-bit unsigned integer |
| ushort | 16-bit unsigned integer (LE) |
| uint | 32-bit unsigned integer (LE) |
| ulong | 64-bit unsigned integer (LE |
| sbyte | 8-bit signed integer |
| short | 16-bit signed integer (LE) |
| int | 32-bit signed integer (LE) |
| long | 64-bit signed integer (LE) |
| byteb | 8-bit unsigned integer (BE) |
| ushortb | 16-bit unsigned integer (BE) |
| uintb | 32-bit unsigned integer (BE) |
| ulongb | 64-bit unsigned integer (BE) |
| sbyteb | 8-bit signed integer (BE) |
| shortb | 16-bit signed integer (BE) |
| intb | 32-bit signed integer (BE) |
| longb | 64-bit signed integer (BE) |
| float | 32-bit floating point |
| double | 64-bit floating point |
| string | UTF-8 string |
| cstring | Null-terminated UTF-8 string |
| string16 | UTF-16 string |
| cstring16 | Null-terminated UTF-16 string |
Standard methods
| Method | Description |
|---|---|
| void log(string message) | Prints message |
| string format(string format, params object[] formatArgs) | Gets formatted output |
| buf and(buf source, lambda l) (1) | Applies AND |
| buf and(buf source, byte key) (1) | Applies AND |
| buf or(buf source, lambda l) (1) | Applies OR |
| buf or(buf source, byte key) (1) | Applies OR |
| buf xor(buf source, lambda l) (1) | Applies XOR |
| buf xor(buf source, byte key) (1) | Applies XOR |
(1) Available replacements: $$i index, $$v value
Standard replacements
$length- Length of array element (only available in plain arrays or extended pointer arrays)
$a- Absolute offset of structure in stream
$i- Index of array element (only available in array context)
$p/$parent- Parent structure (for referencing parent members with '.')
$u/$unique- Unique integer (sequential, for generating output IDs)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Antlr4.Runtime.Standard (>= 4.13.1)
- Fp (>= 0.29.0)
-
net8.0
- Antlr4.Runtime.Standard (>= 4.13.1)
- Fp (>= 0.29.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.