Advertisement
Gamebuster

Untitled

Jan 20th, 2022 (edited)
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.83 KB | None | 0 0
  1. package com.gamebuster19901.excite.crc;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.nio.ByteBuffer;
  6.  
  7. import org.apache.commons.io.IOUtils;
  8.  
  9. public class CRCTester {
  10.     private final byte[] data;
  11.    
  12.     public CRCTester(InputStream inputStream) throws IOException {
  13.         this(IOUtils.toByteArray(inputStream));
  14.     }
  15.    
  16.     public CRCTester(byte[] data) {
  17.         this.data = data;
  18.     }
  19.    
  20.     public int test(final int seed) {
  21.        
  22.         ByteBuffer param1 = ByteBuffer.wrap(data);
  23.         int length = data.length;
  24.        
  25.         byte pos1;
  26.         byte pos2;
  27.         byte pos3;
  28.         byte pos4;
  29.         byte pos5;
  30.         byte pos6;
  31.        
  32.         byte bVar7;
  33.         boolean bVar8;
  34.         int leftoverBytes;
  35.         int bytesEvaluated;
  36.         @Unsigned int uVar11;
  37.         @Unsigned int cyclesRemaining;
  38.        
  39.         uVar11 = seed;
  40.        
  41.         int dataPointer = 0;
  42.        
  43.         if(3 < length) {
  44.             pos1 = param1.get(0);
  45.             length = length - 4;
  46.             pos2 = param1.get(1);
  47.             bVar7 = pos1;
  48.             pos3 = param1.get(2);
  49.            
  50.             param1.getInt();
  51.             dataPointer = dataPointer + 4;
  52.            
  53.             uVar11 = ~(bVar7 << 0x18 | pos1 << 0x10 | pos2 << 8 | pos3);
  54.         }
  55.    
  56.         bytesEvaluated = 0;
  57.         if(0 < length) {
  58.             if (8 < length) {
  59.                 bVar8 = false;
  60.                 if (-1 < length && length < 0x7fffffff) {
  61.                     bVar8 = true;
  62.                 }
  63.                 cyclesRemaining = length - 1 >>> 3;
  64.                 if(bVar8
  65.                         && 0 < length - 8) { //this is almost certainty a for loop. Also cyclesRemaining = (maxLength - 1) / 8
  66.                     do {
  67.                         bytesEvaluated = bytesEvaluated + 8;
  68.                         uVar11 = (uVar11 << 8 | param1.getInt(0)) ^ (seed + (uVar11 >>> 0x16 & 0x3fc));
  69.                         pos1 = param1.get(dataPointer + 1);
  70.                         pos2 = param1.get(dataPointer + 2);
  71.                         pos3 = param1.get(dataPointer + 3);
  72.                         uVar11 = (uVar11 << 8 | param1.getInt(1)) ^ (seed + (uVar11 >>> 0x16 & 0x3fc));
  73.                         pos4 = param1.get(dataPointer + 4);
  74.                         pos5 = param1.get(dataPointer + 5);
  75.                         pos6 = param1.get(dataPointer + 6);
  76.                        
  77.                         param1.getLong();
  78.                         dataPointer = dataPointer + 8;
  79.                        
  80.                         uVar11 = (uVar11 << 8 | pos1) ^ (seed + (uVar11 >>> 0x16 & 0x3fc));
  81.                         uVar11 = (uVar11 << 8 | pos2) ^ (seed + (uVar11 >>> 0x16 & 0x3fc));
  82.                         uVar11 = (uVar11 << 8 | pos3) ^ (seed + (uVar11 >>> 0x16 & 0x3fc));
  83.                         uVar11 = (uVar11 << 8 | pos4) ^ (seed + (uVar11 >>> 0x16 & 0x3fc));
  84.                         uVar11 = (uVar11 << 8 | pos5) ^ (seed + (uVar11 >>> 0x16 & 0x3fc));
  85.                         uVar11 = (uVar11 << 8 | pos6) ^ (seed + (uVar11 >>> 0x16 & 0x3fc));
  86.                         cyclesRemaining = cyclesRemaining - 1;
  87.                     }
  88.                     while (cyclesRemaining != 0);
  89.                 }
  90.             }
  91.             leftoverBytes = length - bytesEvaluated;
  92.             if(bytesEvaluated < length) {
  93.                 do {
  94.                     bVar7 = param1.get(dataPointer);
  95.                     dataPointer = dataPointer++;
  96.                    
  97.                     uVar11 = (uVar11 << 8 | bVar7) ^ (seed + (uVar11 >>> 0x16 & 0x3fc));
  98.                     leftoverBytes = leftoverBytes - 1;
  99.                 }
  100.                 while (leftoverBytes != 0);
  101.             }
  102.         }
  103.         return ~uVar11;
  104.     }
  105.    
  106.    
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement