Advertisement
Gamebuster

Untitled

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