-
Notifications
You must be signed in to change notification settings - Fork 14
/
CrackSleeve.java
157 lines (136 loc) · 5.59 KB
/
CrackSleeve.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import common.*;
import dns.SleeveSecurity;
import java.io.*;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class CrackSleeve {
private static byte[] OriginKey = {-13,-114,-77,-47,-93,53,-78,82,-75,-117,-62,-84,-34,-127,-75,66};
private static byte[] CustomizeKey = {-13,-114,-77,-47,-93,53,-78,82,-75,-117,-62,-84,-34,-127,-75,66};
private String DecDir = "Resource/Decode/sleeve";
private String EncDir = "Resource/Encode/sleeve";
public static void main(String[] args) throws IOException {
if (args.length == 0 || args[0].equals("-h") || args[0].equals("--help")) {
System.out.println("UseAge: CrackSleeve OPTION [key]");
System.out.println("Options:");
System.out.println("\tdecode\t\tDecode sleeve files");
System.out.println("\tencode\t\tEncode sleeve files");
System.out.println("\tkey\t\tCustomize key string for encode sleeve files");
System.exit(0);
}
String option = args[0];
if (option.toLowerCase().equals("encode"))
{
}
CrackSleeve Cracker = new CrackSleeve();
// 使用正版key初始化SleeveSecurity中的key
if (option.equals("decode")){
CrackSleevedResource.Setup(OriginKey);
Cracker.DecodeFile();
}else if (option.equals("encode")){
CrackSleevedResource.Setup(CustomizeKey);
Cracker.EncodeFile();
}
}
private void DecodeFile() throws IOException {
// 文件保存目录
File saveDir = new File(this.DecDir);
if (!saveDir.isDirectory())
saveDir.mkdirs();
// 获取jar文件中sleeve文件夹下的文件列表
try {
String path = this.getClass().getClassLoader().getResource("sleeve").getPath();
String jarPath = path.substring(5,path.indexOf("!/"));
Enumeration<JarEntry> jarEnum = new JarFile(new File(jarPath)).entries();
while (jarEnum.hasMoreElements())
{
JarEntry Element = jarEnum.nextElement();
String FileName = Element.getName();
if (FileName.indexOf("sleeve")>=0 && !FileName.equals("sleeve/")) {
System.out.print("[+] Decoding "+FileName+"......");
byte[] decBytes = CrackSleevedResource.DecodeResource(FileName);
if (decBytes.length > 0) {
System.out.println("Done.");
CommonUtils.writeToFile(new File(saveDir,"../"+FileName),decBytes);
}
else
System.out.println("Fail.");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void EncodeFile(){
// 文件保存目录
File saveDir = new File(this.EncDir);
if (!saveDir.isDirectory())
saveDir.mkdirs();
// 获取解密文件列表
File decDir = new File(this.DecDir);
File[] decFiles = decDir.listFiles();
if (decFiles.length == 0) {
System.out.println("[-] There's no file to encode, please decode first.");
System.exit(0);
}
for (File file : decFiles){
String filename = decDir.getPath()+"/"+file.getName();
System.out.print("[+] Encoding " + file.getName() + "......");
byte[] encBytes = CrackSleevedResource.EncodeResource(filename);
if (encBytes.length > 0) {
System.out.println("Done.");
CommonUtils.writeToFile(new File(saveDir,file.getName()),encBytes);
}
else
System.out.println("Fail.");
}
}
}
class CrackSleevedResource{
private static CrackSleevedResource singleton;
private SleeveSecurity data = new SleeveSecurity();
public static void Setup(byte[] paramArrayOfbyte) {
singleton = new CrackSleevedResource(paramArrayOfbyte);
}
public static byte[] DecodeResource(String paramString) {
return singleton._DecodeResource(paramString);
}
public static byte[] EncodeResource(String paramString) {
return singleton._EncodeResource(paramString);
}
private CrackSleevedResource(byte[] paramArrayOfbyte) {
this.data.registerKey(paramArrayOfbyte);
}
private byte[] _DecodeResource(String paramString) {
byte[] arrayOfByte1 = CommonUtils.readResource(paramString);
if (arrayOfByte1.length > 0) {
long l = System.currentTimeMillis();
return this.data.decrypt(arrayOfByte1);
}
byte[] arrayOfByte2 = CommonUtils.readResource(paramString);
if (arrayOfByte2.length == 0) {
CommonUtils.print_error("Could not find sleeved resource: " + paramString + " [ERROR]");
} else {
CommonUtils.print_stat("Used internal resource: " + paramString);
}
return arrayOfByte2;
}
private byte[] _EncodeResource(String paramString){
try {
File fileResource = new File(paramString);
InputStream fileStream = new FileInputStream(fileResource);
if (fileStream != null)
{
byte[] fileBytes = CommonUtils.readAll(fileStream);
if (fileBytes.length > 0)
{
byte[] fileEncBytes = this.data.encrypt(fileBytes);
return fileEncBytes;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
}