Advertisement
Guest User

Untitled

a guest
Sep 28th, 2021
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. //Base logic for decoding 256 u16 blocks (512bytes)
  2. //Key appears to vary within file, can't tie to some logic right now. Might be arbitrary?
  3. //Might not cover whole file correctly
  4.  
  5. private void showTime()
  6. {
  7.     byte[] bCoded;
  8.     bCoded = File.ReadAllBytes(@"D:\S29GL064N90BFI03@BGA48_20210924_142237.BIN");
  9.     ushort[] coded = new ushort[bCoded.Length / 2];
  10.  
  11.     for (int i = 0; i < coded.Length; i++)
  12.     {
  13.         //coded[i] = (ushort)((bCoded[i * 2] << 8) + bCoded[i * 2 + 1]); //as in file load
  14.         coded[i] = (ushort)((bCoded[i * 2 + 1] << 8) + bCoded[i * 2]); //byteswap load
  15.     }
  16.  
  17.     int endAddr = 0x800000 / 2;
  18.     for (int addr = 0; addr < endAddr; addr++)
  19.     {
  20.         ushort key = 0x8a28;
  21.         if (addr >= 0x4000 && addr < 0x8000) key = 0x228a;
  22.  
  23.         if ((addr & 0x01) != 0) key |= 0x0100; //bit 8
  24.         if ((addr & 0x02) != 0) key |= 0x4000; //bit 14
  25.         if ((addr & 0x04) != 0) key |= 0x0400; //bit 11
  26.         if ((addr & 0x08) != 0) key |= 0x0040; //bit 6
  27.         if ((addr & 0x10) != 0) key |= 0x0010; //bit 4
  28.         if ((addr & 0x20) != 0) key |= 0x0001; //bit 0
  29.         if ((addr & 0x40) != 0) key |= 0x1000; //bit 12
  30.         if ((addr & 0x80) != 0) key |= 0x0004; //bit 2
  31.  
  32.         bCoded[addr * 2 + 1] = (byte)(coded[addr] ^ key);
  33.         bCoded[addr * 2] = (byte)((coded[addr] ^ key) >> 8);
  34.     }
  35.  
  36.     File.WriteAllBytes(@"D:\DECODED.BIN", bCoded);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement