Skip to content

Commit 9483aa6

Browse files
Improve dump command: add --stdout, refactors, more tests (#69)
Usability improvements for the case of examining a single object, easier pipe support etc. Also extensive cleanup of the implementation, and more extensive test coverage, to put us in better position to add other improvements in upcoming PRs (hex, array hashing, JSON support etc)
1 parent 7f79d02 commit 9483aa6

6 files changed

Lines changed: 711 additions & 389 deletions

File tree

Documentation/command-dump.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ UnityDataTool dump <path> [options]
1212
|--------|-------------|---------|
1313
| `<path>` | Path to file to dump | *(required)* |
1414
| `-o, --output-path <path>` | Output folder | Current folder |
15+
| `--stdout` | Write the dump to stdout (status and errors go to stderr). Mutually exclusive with `-o`. | `false` |
1516
| `-f, --output-format <format>` | Output format | `text` |
1617
| `-s, --skip-large-arrays` | Skip dumping large arrays | `false` |
1718
| `-i, --objectid <id>` | Only dump object with this ID | All objects |
@@ -55,6 +56,26 @@ Dump the AssetBundle manifest object:
5556
UnityDataTool dump mybundle -t AssetBundle
5657
```
5758

59+
Write the dump to stdout and pipe it through another tool:
60+
```bash
61+
UnityDataTool dump /path/to/file --stdout | grep "ClassID: 114"
62+
```
63+
64+
---
65+
66+
## Writing to stdout
67+
68+
Use `--stdout` to send the dump to standard output instead of writing a `.txt` file. Status messages (the `Processing ...` line, errors, and stack traces) are routed to stderr so the dump on stdout is clean for piping or redirecting.
69+
70+
```bash
71+
UnityDataTool dump /path/to/file --stdout > my-dump.txt
72+
```
73+
74+
Restrictions:
75+
76+
- `--stdout` and `-o` are mutually exclusive.
77+
- For Unity archives that contain more than one SerializedFile, `--stdout` is refused — there is no unambiguous way to deliver multiple files on a single stream. Pass an individual SerializedFile, or omit `--stdout` to get one `.txt` per SerializedFile in the output folder.
78+
5879
---
5980

6081
## Filtering by Type
@@ -124,7 +145,7 @@ UnityDataTool dump /path/to/file.bundle --typetree-data /path/to/typetree.bin
124145

125146
## Output Format
126147

127-
The output is similar to Unity's `binary2text` tool. Each file begins with external references:
148+
The output is similar to Unity's `binary2text` tool. Unfiltered dumps begin with external references (when filtering with `-i` or `-t` this section is omitted — use the [`serialized-file externalrefs`](#) command if you want them separately):
128149

129150
```
130151
External References

Documentation/textdumper.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ file (AssetBundle or SerializedFile) into human-readable yaml-style text file.
55

66
## How to use
77

8-
The library consists of a single class called [TextDumperTool](../TextDumper/TextDumperTool.cs). It has a method named Dump and takes five parameters:
9-
* path (string): path of the data file.
10-
* outputPath (string): path where the output files will be created.
11-
* skipLargeArrays (bool): if true, the content of arrays larger than 1KB won't be dumped.
12-
* objectId (long, optional): if specified and not 0, only the object with this signed 64-bit id will be dumped. If 0 (default), all objects are dumped.
13-
* typeFilter (string, optional): if specified, only objects matching this type are dumped. Accepts a numeric ClassID (e.g. 114) or a type name (e.g. MonoBehaviour, case-insensitive).
8+
The library consists of a single class called [TextDumperTool](../TextDumper/TextDumperTool.cs). Call its `Dump` method, passing a `TextDumperTool.DumpOptions` object that specify the path of the file to dump and various flags and options.
9+
10+
The library is used to implement the [`UnityDataTool dump` command](command-dump.md).
1411

1512
## How to interpret the output files
1613

1714
There will be one output file per SerializedFile. Depending on the type of the input file, there can
1815
be more than one output file (e.g. AssetBundles are archives that can contain several
1916
SerializedFiles).
2017

21-
The first lines of the output file looks like this:
18+
For an unfiltered dump, the first lines of the output file look like this (when `ObjectId` or `TypeFilter` are set the External References section is omitted, and the output starts directly with the matching object entries):
2219

2320
External References
2421
path(1): "Library/unity default resources" GUID: 0000000000000000e000000000000000 Type: 0

0 commit comments

Comments
 (0)