From c4c08d1494070b385a6ef86f88e7757ec7491a75 Mon Sep 17 00:00:00 2001 From: feyris-tan <4116042+feyris-tan@users.noreply.github.com> Date: Mon, 18 May 2026 21:50:40 +0200 Subject: [PATCH] Implemented Salvaging Strategy 3. --- skyscraper8/Properties/launchSettings.json | 2 +- .../Skyscraper/IO/UnseekableInputStream.cs | 16 ++++- skyscraper8/Skyscraper/Salvager.cs | 60 +++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/skyscraper8/Properties/launchSettings.json b/skyscraper8/Properties/launchSettings.json index b9f7ec3..8571166 100644 --- a/skyscraper8/Properties/launchSettings.json +++ b/skyscraper8/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "skyscraper8": { "commandName": "Project", - "commandLineArgs": "\"C:\\Users\\Sascha Schiemann\\Downloads\\65w_fix.ts\"", + "commandLineArgs": "salvage strat3 \"Z:\\Persönliches\\Satellitescommunity\\Skyscraper Test Fixture\\105.5E_4169.263_H_5237_(2026-04-24 12.36.13)_dump.ts\"", "remoteDebugEnabled": false }, "Container (Dockerfile)": { diff --git a/skyscraper8/Skyscraper/IO/UnseekableInputStream.cs b/skyscraper8/Skyscraper/IO/UnseekableInputStream.cs index a1f399a..74b36f6 100644 --- a/skyscraper8/Skyscraper/IO/UnseekableInputStream.cs +++ b/skyscraper8/Skyscraper/IO/UnseekableInputStream.cs @@ -15,6 +15,7 @@ namespace skyscraper8.Skyscraper.IO private bool _positionSupported; private readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name); private long emulatedPosition; + private bool canNotReadAnymore; public UnseekableInputStream(Stream wrappedStream) { @@ -57,6 +58,9 @@ namespace skyscraper8.Skyscraper.IO emulatedPosition += result; } + if (result == 0 && count > 0) + canNotReadAnymore = true; + return result; } @@ -75,7 +79,17 @@ namespace skyscraper8.Skyscraper.IO throw new NotSupportedException(); } - public override bool CanRead => _wrappedStream.CanRead; + public override bool CanRead + { + get + { + if (canNotReadAnymore) + return false; + + return true; + } + } + public override bool CanSeek => false; public override bool CanWrite => false; diff --git a/skyscraper8/Skyscraper/Salvager.cs b/skyscraper8/Skyscraper/Salvager.cs index 6862ed2..a86e50d 100644 --- a/skyscraper8/Skyscraper/Salvager.cs +++ b/skyscraper8/Skyscraper/Salvager.cs @@ -42,6 +42,11 @@ namespace skyscraper8.Skyscraper if (fi.Exists) { InputStream = fi.OpenRead(); + + string filename = fi.Name; + filename = Path.GetFileNameWithoutExtension(filename); + filename = string.Format("{0}_salvaged_{1}_{2}.ts", filename, args[1], DateTime.Now.Ticks); + SalvagedOutput = File.OpenWrite(filename); } else { @@ -74,6 +79,9 @@ namespace skyscraper8.Skyscraper InputStream = new UnseekableInputStream(InputStream); Run(); + SalvagedOutput?.Flush(); + SalvagedOutput?.Close(); + } private void Run() @@ -110,12 +118,64 @@ namespace skyscraper8.Skyscraper case SalvagingStrategy.PatchSyncByte: RunWithPatchingSyncByte(); break; + case SalvagingStrategy.SeekForSyncByte: + RunWithSeekForSyncByte(); + break; default: logger.ErrorFormat("I'm sorry, but the strategy \"{0}\" is not yet fully implemented.",Strategy); return; } } + private void RunWithSeekForSyncByte() + { + bool synced = false; + while (InputStream.CanRead) + { + Array.Clear(readBuffer); + + if (InputStream.Read(readBuffer, 0, 1) != 1) + return; + + if (readBuffer[0] != 'G') //wrong sync byte + { + if (synced) + { + logger.WarnFormat("Lost sync at byte {0}", InputStream.Position - 1); + synced = false; + } + + continue; + } + + if (InputStream.Read(readBuffer, 1, 3) != 3) + { + return; + } + + int tsc = readBuffer[3] & 0xc0; + int adaptionField = readBuffer[3] & 0x30; + + tsc >>= 6; + adaptionField >>= 4; + + if (tsc == 1) + continue; + + if (adaptionField == 0) + continue; + + if (InputStream.Read(readBuffer, 4, 184) != 184) + { + return; + } + + SalvagedOutput?.Write(readBuffer,0,184); + Context.IngestSinglePacket(readBuffer); + synced = true; + } + } + private void RunWithPatchingSyncByte() { while (readLength == 188)