Kai他ICO的writing
Kaitai code writing
我最近开始使用 kaitai-struct 来处理任意二进制格式。我为我的数据创建了 .ksy 文件并将其解析为目标语言 java。现在谁能告诉我如何传递包含数据的输入文件以及如何获取被解析为输出的数据,以便我可以编写代码来根据我的要求操作该数据?有没有关于如何根据得到的数据写代码的教程
提前致谢。
首先,您必须使用 Kaitai Struct 编译器或 WebIDE 从 .ksy 文件生成 Java 类。您可以在 the Kaitai user guide.
中找到有关如何使用编译器的更多信息
如果您使用 WebIDE,只需右键单击您的 .ksy 文件,然后 select Generate parser > Java
菜单项。
生成 Java 代码后,您可以像这样直接从本地文件解析结构:
AnExampleClass output = AnExampleClass.fromFile("an_example.data");
// ... manipulate output ...
或者您可以从字节数组 (byte[]) 解析结构:
AnExampleClass output = new AnExampleClass(new KaitaiStream(byteArray));
// ... manipulate output ...
请注意,不支持并且可能不会支持从不可搜索的流(即 FileInputStream、BufferedInputStream 等)进行解析,因为 KS 中的许多解析功能都依赖于搜索支持。
您可以阅读generic documentation how to use the API here and you can find the Java-specific documentation here。
我最近开始使用 kaitai-struct 来处理任意二进制格式。我为我的数据创建了 .ksy 文件并将其解析为目标语言 java。现在谁能告诉我如何传递包含数据的输入文件以及如何获取被解析为输出的数据,以便我可以编写代码来根据我的要求操作该数据?有没有关于如何根据得到的数据写代码的教程
提前致谢。
首先,您必须使用 Kaitai Struct 编译器或 WebIDE 从 .ksy 文件生成 Java 类。您可以在 the Kaitai user guide.
中找到有关如何使用编译器的更多信息如果您使用 WebIDE,只需右键单击您的 .ksy 文件,然后 select Generate parser > Java
菜单项。
生成 Java 代码后,您可以像这样直接从本地文件解析结构:
AnExampleClass output = AnExampleClass.fromFile("an_example.data");
// ... manipulate output ...
或者您可以从字节数组 (byte[]) 解析结构:
AnExampleClass output = new AnExampleClass(new KaitaiStream(byteArray));
// ... manipulate output ...
请注意,不支持并且可能不会支持从不可搜索的流(即 FileInputStream、BufferedInputStream 等)进行解析,因为 KS 中的许多解析功能都依赖于搜索支持。
您可以阅读generic documentation how to use the API here and you can find the Java-specific documentation here。