Something I'm working on, on the PHP side. This is using named captures just like implemented in my C# parser. This parses my new format.

Much like my client, it parses line by line - (read or write) - and dumps all data to a string[] and works with the data appropriately.

I dont see encryption as necessary. If the file changes, the server and client performs a deep integrity check on the SWT file to ensure it is a exact snapshot. These are created in the client, so a original snapshot is stored in database for validation if the file is modified. Why hide? This is an age of open source data.

Nothing says we can't allow that functionally in a later version supporting a private key generated within the client. Its quite easy.

PHP 5.1+

Movie2022.swt

name: Mario Kart 8 Deluxe + Update 2.0.0 + DLC [NSP]
size: 7929800387
hash: 5FEC54A804462266E4EFDFFAEEAD677C
Files("Mario Kart 8 Deluxe [0100152000022000][v0].nsp", 7268474425, "Mario Kart 8 Deluxe [0100152000022800][v720896].nsp", 661204928, "Mario Kart 8 Deluxe [DLC Booster Course Pass][0100152000023001][v0].nsp", 121034)
date: 2022-10-12 10:39:50 AM



<?
/*
*    SWT File Parser Class - Oct 25, 2022 - v1.02
*
*/
interface Parse
{
   public function openFile(string $file): array;
}
class SWTParsing implements Parse
{
   private function parseField(string $field): string
   {
       return trim(substr($field, (strrpos($field, ':') ?: -1) + 1));
   }
   private function parseFileList(string $field): array
   {
       $pattern = stripslashes(preg_match_all('/(?:\w+\(\h*|(?<!\A)\G\h*,\h*)"(?<filename>[^"]+)"\h*,\h*(?<filesize>\d+)/', $field, $m));
       if ($pattern) {
           return array_combine($m['filename'], $m['filesize']);
       }
   }
   public function openFile(string $filename): array
   {
       $metadata = array();
       $fileData = function($data)
       {
           $file = fopen($data, 'r');
           if (!$file)
               return;
           while (($line = fgets($file)) !== false) {
               yield $line;
           }
           fclose($file);
       };
       $i        = 0;
       foreach ($fileData($filename) as $line) {
           $i++;
           if ($i === 1) {
               $metadata['name'] = $this->parseField($line);
           }
           if ($i === 2) {
               $metadata['size'] = $this->parseField($line);
           }
           if ($i === 3) {
               $metadata['hash'] = $this->parseField($line);
           }
           if ($i === 4) {
               $metadata['files'] = $this->parseFileList($line);
           }
           if ($i === 5) {
               $metadata['date'] = $line;
           }
       }
       return $metadata;
   }
}



Array
(
   [name] => Mario Kart 8 Deluxe + Update 2.0.0 + DLC [NSP]
   [size] => 7929800387
   [hash] => 5FEC54A804462266E4EFDFFAEEAD677C
   [files] => Array
       (
           [Mario Kart 8 Deluxe [0100152000022000][v0].nsp] => 7268474425
           [Mario Kart 8 Deluxe [0100152000022800][v720896].nsp] => 661204928
           [Mario Kart 8 Deluxe [DLC Booster Course Pass][0100152000023001][v0].nsp] => 121034
       )
   [date] => date: 2022-10-12 10:39:50 AM
)


Improvements will be updated near daily as it evolves.

Next update
    Individual file hashes in file array

    Improved loop containing switch/break

    Extended metadata

    Source info - Url data fetch - validate root hash

Last edited by STorrents2020 on 2022-10-29 22:50:20