Guest User

Flippingbook downloader

a guest
Dec 13th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.23 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.IO;
  4. using System.IO.Compression;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. using System.Xml;
  9.  
  10. namespace ConsoleApplication87
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             string baseUrl = args.Last();
  17.  
  18.             Console.Write(">");
  19.  
  20.             var wc = new WebClient();
  21.  
  22.             byte[] propSwf = wc.DownloadData(baseUrl + "assets/flash/properties.swf");
  23.             Console.Write("*");
  24.  
  25.             propSwf[0] = 0x50;
  26.             propSwf[1] = 0x4B;
  27.             propSwf[2] = 0x03;
  28.             propSwf[3] = 0x04;
  29.  
  30.             var pms = new MemoryStream();
  31.             new ZipArchive(new MemoryStream(propSwf)).Entries[0].Open().CopyTo(pms);
  32.             var propXml = Encoding.UTF8.GetString(pms.ToArray().Skip(3).ToArray());
  33.  
  34.             XmlDocument doc = new XmlDocument();
  35.             doc.LoadXml(propXml);
  36.  
  37.             int pageCount = doc.SelectNodes("/Properties/bookProperties/pages/elements/page").Count;
  38.  
  39.             byte[] fbSwf = wc.DownloadData(baseUrl + "flash/flippingbook.swf");
  40.             Console.Write("*");
  41.  
  42.             var fms = new MemoryStream(fbSwf);
  43.             fms.Seek(10, SeekOrigin.Begin);
  44.             var z = new DeflateStream(fms, CompressionMode.Decompress);
  45.             var ufms = new MemoryStream();
  46.             z.CopyTo(ufms);
  47.             var ufm = ufms.ToArray();
  48.  
  49.             bool encrypted = true;
  50.             if (ufm[0x7EDBC] == 0x66)
  51.                 ufms.Seek(0x7ED9B, SeekOrigin.Begin);
  52.             else if (ufm[0x7ED9B] == 0x66)
  53.                 encrypted = false;
  54.             else if (ufm[0x81458] == 0x54)
  55.                 ufms.Seek(0x81411, SeekOrigin.Begin);
  56.             else
  57.             {
  58.                 Console.WriteLine("Fail");
  59.                 return;
  60.             }
  61.  
  62.             int so = 0;
  63.             int sx = 0;
  64.  
  65.             if (encrypted)
  66.             {
  67.                 byte[] keyRaw = new byte[32];
  68.                 ufms.Read(keyRaw, 0, 32);
  69.                 string key = Encoding.ASCII.GetString(keyRaw);
  70.  
  71.                 so = 8 + int.Parse(key.Substring(0, 2), NumberStyles.HexNumber) % 8;
  72.                 sx = int.Parse(key.Substring(4, 2), NumberStyles.HexNumber);
  73.             }
  74.  
  75.             Directory.CreateDirectory("pages");
  76.  
  77.             for (int i = 1; i <= pageCount; i++)
  78.             {
  79.                 var fileName = "page" + i.ToString("0000") + "_l.jpg";
  80.                 var filePath = "pages\\" + fileName;
  81.                 if (File.Exists(filePath))
  82.                 {
  83.                     Console.Write("-");
  84.                     continue;
  85.                 }
  86.  
  87.                 byte[] v = wc.DownloadData(baseUrl + "assets/flash/pages/" + fileName);
  88.  
  89.                 if (encrypted)
  90.                 {
  91.                     int a = so;
  92.                     int x = sx + 1;
  93.                     while (a < v.Length)
  94.                     {
  95.                         v[a] = (byte)(v[a] ^ x++);
  96.                         a = a + ((a ^ sx) & 3) + 1;
  97.                     }
  98.                 }
  99.  
  100.                 File.WriteAllBytes(filePath, v);
  101.                 Console.Write(".");
  102.             }
  103.             Console.WriteLine("Done");
  104.         }
  105.     }
  106. }
Add Comment
Please, Sign In to add comment