This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecrypt.java
73 lines (65 loc) · 3.29 KB
/
Decrypt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
public class Decrypt {
// public static String DECRYPTION_KEY =
// "b376645a87fa6ba2ae3eb5111eacc3bcaf2ea83b11acf34be7fd676f7546739b1554ccd0c0faa7c87580bfbd2a3cb63be97761cb0ef2d36c9efb2aea41cdae8f";
public static String DECRYPTION_KEY = "67fb93e12304f0fcb04587f104161dfaae56363b8a10088b39b988480cc5082f4c6b899a27adf86511e64a06254eb2a5bd45b1588a4c1e283a64d94b380a0ec0";
public String getOutputFullPath(String src, String dest, String fullSrcPath) {
return dest + fullSrcPath.substring(src.length());
}
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("Usage: java Decrypt <input dir/file> <output dir/file>");
System.exit(-1);
}
// Normalize the inputs.
// (Only Consider the case that the file separater is used correctly.)
String src = new File(args[0]).getAbsolutePath(), dest = new File(args[1]).getAbsolutePath();
new Decrypt().showFiles(src, dest, new File[] { new File(args[0]) });
}
public void showFiles(String src, String dest, File[] files) throws IOException {
for (File file : files) {
final String inputFullPath = file.getAbsolutePath();
if (file.isDirectory()) {
System.out.println("Dir: " + inputFullPath + " -> " + getOutputFullPath(src, dest, inputFullPath));
new File(getOutputFullPath(src, dest, inputFullPath)).mkdirs();
showFiles(src, dest, file.listFiles());
} else if (file.isFile()) {
System.out.println("File: " + inputFullPath + " -> " + getOutputFullPath(src, dest, inputFullPath));
// Save the file.
byte[] bs = decryptFile(file);
Files.write(new File(getOutputFullPath(src, dest, inputFullPath)).toPath(), bs,
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} else {
System.out.println("Unknown file type: " + inputFullPath);
}
}
}
private byte[] decryptFile(File file) throws IOException {
// Init the key.
com.b.a.a.a.c.a.bLatest = DECRYPTION_KEY.getBytes();
// Check file size.
byte[] byArray = Files.readAllBytes(file.toPath());
if (byArray.length >= 1024 && (byArray[0] == 73 && byArray[1] == 71 && byArray[2] == 69 && byArray[3] == 70
|| byArray[0] == 67 && byArray[1] == 68 && byArray[2] == 69 && byArray[3] == 70)) {
// Encrypted. Using the official file reader.
net.zamasoft.reader.book.a.b randomAccessFile = new net.zamasoft.reader.book.a.b(file);
ArrayList<Byte> bytes = new ArrayList<>();
while (!randomAccessFile.isEOF()) {
byte b = (byte) randomAccessFile.read();
bytes.add(b);
}
assert randomAccessFile.length() == bytes.size();
byte[] bs = new byte[bytes.size()];
for (int ii = 0; ii < bs.length; ii++) {
bs[ii] = bytes.get(ii);
}
return bs;
}
// By default, not encrypted.
return byArray;
}
}