From cf38c1f51f0e4024a9c13b7a0a017b716b458b17 Mon Sep 17 00:00:00 2001 From: bgk- Date: Sun, 26 May 2024 17:10:53 -0700 Subject: [PATCH] Add ByteCode.GetBoughs function --- Topiary/ByteCode.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Topiary/ByteCode.cs b/Topiary/ByteCode.cs index b88ffe1..0206163 100644 --- a/Topiary/ByteCode.cs +++ b/Topiary/ByteCode.cs @@ -33,5 +33,32 @@ public static SortedSet GetExterns(BinaryReader reader) return result; } + + public static string[] GetBoughs(BinaryReader reader) + { + var globalSymbolsCount = reader.ReadUInt64(); + var indexSize = Marshal.SizeOf(); + + for (ulong i = 0; i < globalSymbolsCount; i++) + { + var nameLength = reader.ReadByte(); + reader.ReadBytes(nameLength); // skip name + reader.ReadBytes(indexSize); // skip globals index + reader.ReadByte(); + reader.ReadByte(); // mutable + } + + var boughCount = reader.ReadUInt64(); + var result = new string[boughCount]; + for (ulong i = 0; i < boughCount; i++) + { + var nameLength = reader.ReadByte(); + var name = Encoding.UTF8.GetString(reader.ReadBytes(nameLength)); + reader.ReadBytes(indexSize); // skip index + result[i] = name; + } + + return result; + } } } \ No newline at end of file