Skip to content

Instantly share code, notes, and snippets.

@Sascha-T
Last active July 26, 2023 12:08
Show Gist options
  • Save Sascha-T/b5db44d5c1864d1f681b3ca11ed8837d to your computer and use it in GitHub Desktop.
Save Sascha-T/b5db44d5c1864d1f681b3ca11ed8837d to your computer and use it in GitHub Desktop.
Everbook Decryptor
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
public class Main {
static String get(byte[] bytes) {
StringBuilder out = new StringBuilder();
for (byte b : bytes) out.append(String.format("%02X", b));
return out.toString();
}
public static void main(String[] args) throws Throwable {
if (args.length < 1) {
System.out.println("java -cp . Main [everbook file name]");
return;
}
File book = new File(args[0]);
String uuid = Arrays.stream(book.getName().split("-")).skip(1).collect(Collectors.joining("-")).substring(0, 36);
UUID uid = UUID.fromString(uuid);
System.out.println("Your UUID: " + uid);
ByteBuffer buffer = ByteBuffer.allocate(16);
buffer.putLong(uid.getMostSignificantBits());
buffer.putLong(uid.getLeastSignificantBits());
System.out.println("Your key: " + get(buffer.array()));
DataInputStream ins = new DataInputStream(new FileInputStream(book));
byte[] iv = new byte[16];
ins.read(iv);
byte[] rest = ins.readAllBytes();
System.out.println("Your IV: " + get(iv));
SecretKeySpec spec = new SecretKeySpec(buffer.array(), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, spec, new IvParameterSpec(iv));
byte[] output = cipher.doFinal(rest);
if (args.length != 2) {
output = new GZIPInputStream(new ByteArrayInputStream(output)).readAllBytes(); // for comfort
if (!(output[0] == 0x0A && output[1] == 0x00 && output[2] == 0x00))
System.err.println("Decryption may have failed, no unnamed root compound tag.");
}
FileOutputStream stream = new FileOutputStream("decrypted.dat");
stream.write(output);
stream.flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment