From 4f7e58f5639b9055a489a883eee2d869c96035a2 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Sun, 25 Aug 2024 23:46:59 +0200 Subject: [PATCH] read root obj table --- .../DotNetSiemensPLCToolBoxLibrary.csproj | 1 + .../Enums/TiaFixedRootObjectInstanceIds.cs | 7 +--- .../TIA/Step7ProjectTiaBinaryParsed.cs | 34 +++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/LibNoDaveConnectionLibrary/DotNetSiemensPLCToolBoxLibrary.csproj b/LibNoDaveConnectionLibrary/DotNetSiemensPLCToolBoxLibrary.csproj index b1bc6050..0a3b0cef 100644 --- a/LibNoDaveConnectionLibrary/DotNetSiemensPLCToolBoxLibrary.csproj +++ b/LibNoDaveConnectionLibrary/DotNetSiemensPLCToolBoxLibrary.csproj @@ -3,6 +3,7 @@ Library netstandard2.1;net461 + 9 SHARPZIPLIB diff --git a/LibNoDaveConnectionLibrary/Projectfiles/TIA/Enums/TiaFixedRootObjectInstanceIds.cs b/LibNoDaveConnectionLibrary/Projectfiles/TIA/Enums/TiaFixedRootObjectInstanceIds.cs index 2ba399be..04dcd8ac 100644 --- a/LibNoDaveConnectionLibrary/Projectfiles/TIA/Enums/TiaFixedRootObjectInstanceIds.cs +++ b/LibNoDaveConnectionLibrary/Projectfiles/TIA/Enums/TiaFixedRootObjectInstanceIds.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA.Enums +namespace DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA.Enums { public enum TiaFixedRootObjectInstanceIds : long { diff --git a/LibNoDaveConnectionLibrary/Projectfiles/TIA/Step7ProjectTiaBinaryParsed.cs b/LibNoDaveConnectionLibrary/Projectfiles/TIA/Step7ProjectTiaBinaryParsed.cs index eb91311c..c8af2cb3 100644 --- a/LibNoDaveConnectionLibrary/Projectfiles/TIA/Step7ProjectTiaBinaryParsed.cs +++ b/LibNoDaveConnectionLibrary/Projectfiles/TIA/Step7ProjectTiaBinaryParsed.cs @@ -2,9 +2,11 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Text; using System.Xml; using DotNetSiemensPLCToolBoxLibrary.DataTypes; using DotNetSiemensPLCToolBoxLibrary.General; +using DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA.Enums; using DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA.Structs; namespace DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA @@ -38,6 +40,38 @@ public void BinaryParseTIAFile() { var hd = TiaObjectHeader.Deserialize(rd); TiaObjectsList.Add(hd); + + if (hd.TypeId == 0x70000 + 14) //localization_table + { + var langs = new List(); + using var ms = new MemoryStream(hd.Data); + using var br = new BinaryReader(ms); + var maybe_length_including_itself = br.ReadInt32(); + + var count = br.ReadInt32(); + for (int i = 0; i < count;i++) + { + var lng = br.ReadInt32(); + langs.Add(lng); + var unkown_maybe_flags = br.ReadByte(); + } + } + else if (hd.TypeId == 0x70000 + 9) //Root Object Table + { + var rootObjs = new List(); + using var ms = new MemoryStream(hd.Data); + using var br = new BinaryReader(ms); + var maybe_length_including_itself = br.ReadInt32(); + + var count = br.ReadInt32(); + for (int i = 0; i < count; i++) + { + var id = br.ReadInt32(); + var instId = br.ReadInt64(); + var ln = br.ReadByte(); + var nm = Encoding.UTF8.GetString(br.ReadBytes(ln)); + } + } } } catch (EndOfStreamException) // Zip File Stream has no length