fix: update nbot hashing

This commit is contained in:
Chayapak Supasakul 2025-04-05 19:06:39 +07:00
parent 1193bd0bb4
commit 92867a6217
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA

View file

@ -11,7 +11,6 @@ import net.minecraft.client.network.ClientPlayerEntity;
import org.apache.commons.codec.binary.Hex;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -159,18 +158,23 @@ public class BotValidationUtilities {
try {
String[] arguments = command.split(" ");
MessageDigest md = MessageDigest.getInstance("SHA-256");
final MessageDigest md = MessageDigest.getInstance("SHA-256");
String time = String.valueOf(System.currentTimeMillis() / 5_000);
String input = arguments[0].replaceAll("&[0-9a-fklmnor]", "") + ";" + client.player.getUuidAsString() + ";" + time + ";" + key;
final long time = Math.floorDiv(System.currentTimeMillis(), 250);
md.update(input.getBytes(StandardCharsets.UTF_8));
// yep it is very raw code indeed.
final String input = "ThisCodeIsRaw;" + client.player.getUuidAsString() + ";" + time + ";" + key;
byte[] hash = md.digest();
final byte[] digest = md.digest(input.getBytes(StandardCharsets.UTF_8));
final byte[] positiveDigest = new byte[digest.length + 1];
ByteBuffer buffer = ByteBuffer.wrap(hash, 0, 4);
long bigInt = (buffer.getInt() & 0xFFFFFFFFL);;
String stringHash = Long.toString(bigInt, 36);
System.arraycopy(digest, 0, positiveDigest, 1, digest.length);
final BigInteger bi = new BigInteger(positiveDigest);
final String b36 = bi.toString(36);
final String stringHash = b36.length() > 16 ? b36.substring(0, 16) : b36;
final String[] restArguments = Arrays.copyOfRange(arguments, 1, arguments.length);