Advertisement
Guest User

Dead Rising

a guest
Oct 31st, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. "
  2. Security:
  3. -> Custom Checksum(s)
  4.   -> Offset: 16, 36, 56, ..., EOF - 4
  5.   -> Calculation Start: 0, 20, 40, ..., EOF - 20
  6.   -> Calculation Length: 16
  7.  
  8. Additional:
  9. You can calculate the checksum count n with Size / 20.
  10. Each checksum consist of two separate Int16 checksums, that are calculated with the following formulas.
  11.  
  12. 1: x[0] + x[1] + x[2] + x[3] + x[4] + x[5] + ...
  13. 2: x[0] - x[1] + x[2] - x[3] + x[4] - x[5] + ...
  14. "
  15.  
  16. public void FixChecksums(byte[] data, int offset, int size) {
  17.     fixed (byte* x = data) {
  18.         byte* e = x + offset + size;
  19.                
  20.         ushort sumL, sumH;
  21.         for (byte* s = e - size; s < e; s += 4) {
  22.  
  23.             sumL = sumH = 0;
  24.             for (int n = 0; n < 16; ++n, ++s) {
  25.                 sumL += *s;
  26.                 sumH += (ushort) ((n % 2) == 0 ? *s : -*s);
  27.             }
  28.  
  29.             *(ushort*) s = sumL.Swap();
  30.             *(ushort*) (s + 2) = sumH.Swap();
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement