Skip to content

Commit 4ed27a2

Browse files
committed
Update to support CREV with CheckRevisionD1.mpq
It doesn't extract the data from the files on its own, but lets you put in the extracted values (which are the same every time unless there is an update) in the settings.ini file. CheckRevision.mpq requires the "Version" field to be filled out. CheckRevisionD1.mpq requires both "Version" and "Cert". Cert should be the hex representation of the EXE's certificate public key, with no spaces.
1 parent b05aba1 commit 4ed27a2

File tree

4 files changed

+65
-39
lines changed

4 files changed

+65
-39
lines changed

Hashing/CheckRevisionV4.java

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,17 @@ public static CheckrevisionResults checkRevision(String value, int prod, byte pl
5757
}
5858
crCacheMisses++;
5959

60-
String version = null;
61-
if (prod == Constants.PRODUCT_DIABLO2 || prod == Constants.PRODUCT_LORDOFDESTRUCTION)
62-
version = "1.14.3.71";
63-
else {
64-
String[] files = getFiles(prod, plat);
65-
if (Version[plat][prod] == 0) Version[plat][prod] = getVersion(files, prod);
66-
version = getVersionString(Version[plat][prod]);
60+
String version = Constants.IX86versions[prod-1];
61+
if (version.length() == 0) {
62+
Out.error("CREV", "Simple check revision unavailable for " + Constants.prods[prod-1] + ": missing version number");
63+
return null;
6764
}
6865

69-
BigInteger vint = new BigInteger(InetAddress.getByName(version).getAddress());
70-
Version[plat][prod] = vint.intValue();
66+
Version[plat][prod] = 0;
7167

72-
Buffer buff = new Buffer(new Buffer(Base64.getDecoder().decode(value)).removeBytes(4));
68+
Buffer seed = new Buffer(new Buffer(Base64.getDecoder().decode(value)).removeBytes(4));
69+
70+
Buffer buff = new Buffer(seed.getBuffer());
7371
buff.addString(":" + version + ":");
7472
buff.addByte((byte)1);
7573

@@ -80,9 +78,31 @@ public static CheckrevisionResults checkRevision(String value, int prod, byte pl
8078
Out.error("CREV", "Hashing failed - SHA1 not supported");
8179
return null;
8280
}
83-
String b64 = Base64.getEncoder().encodeToString(hash);
81+
String ret = Base64.getEncoder().encodeToString(hash);
82+
83+
// Add the certificate hash if needed
84+
if (mpq.endsWith("D1.mpq")) {
85+
Version[plat][prod] = 6;
86+
87+
String certHex = Constants.IX86certs[prod-1];
88+
if (certHex.length() == 0) {
89+
Out.error("CREV", "Simple check revision unavailable for " + Constants.prods[prod-1] + ": missing certificate");
90+
return null;
91+
}
92+
buff = new Buffer(hexToBytes(certHex));
93+
buff.addBytes(seed.getBuffer());
94+
95+
try {
96+
hash = MessageDigest.getInstance("SHA-1").digest(buff.getBuffer());
97+
} catch (NoSuchAlgorithmException e) {
98+
Out.error("CREV", "Hashing failed - SHA1 not supported (step 2)");
99+
return null;
100+
}
101+
102+
ret += ":" + Base64.getEncoder().encodeToString(hash);
103+
}
84104

85-
byte[] checkB = b64.substring(0, 4).getBytes();
105+
byte[] checkB = ret.substring(0, 4).getBytes();
86106

87107
// Flip the byte order
88108
for (int i = 0, j = checkB.length - 1; i < j; i++, j--) {
@@ -91,25 +111,22 @@ public static CheckrevisionResults checkRevision(String value, int prod, byte pl
91111
checkB[j] = temp;
92112
}
93113
int checksum = new BigInteger(checkB).intValue();
94-
if (checksum == 0 || Version[plat][prod] == 0) return null;
114+
if (checksum == 0) return null;
95115

96-
Buffer info = new Buffer(b64.substring(4).getBytes());
116+
Buffer info = new Buffer(ret.substring(4).getBytes());
97117
info.addByte((byte)0); // Null terminator
98118

99-
CheckrevisionResults result = new CheckrevisionResults(0, checksum, info);
119+
CheckrevisionResults result = new CheckrevisionResults(Version[plat][prod], checksum, info);
100120
crCache.put(value + mpq + prod + plat, result);
101121
return result;
102122
}
103123

104-
public static String getVersionString(int version)
105-
{
106-
try {
107-
byte[] b = BigInteger.valueOf(version).toByteArray();
108-
InetAddress val = InetAddress.getByAddress(b);
109-
return val.getHostAddress();
110-
} catch (UnknownHostException e) {
111-
Out.error("CREV", "Unable to parse version string");
112-
return null;
113-
}
124+
public static byte[] hexToBytes(String hex) {
125+
byte[] value = new byte[hex.length() / 2];
126+
for (int i = 0; i < value.length; i++) {
127+
int index = i * 2;
128+
value[i] = (byte)Integer.parseInt(hex.substring(index, index + 2), 16);
129+
}
130+
return value;
114131
}
115132
}

Hashing/HashMain.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static CheckrevisionResults getRevision(int prod, String formula, String
107107
case 1: files = CheckRevisionV1.getFiles(prod, platform); return CheckRevisionV1.checkRevision(formula, prod, platform, dll);
108108
case 2: files = CheckRevisionV1.getFiles(prod, platform); return CheckRevisionV2.checkRevision(formula, prod, platform, dll);
109109
case 3: files = CheckRevisionV3.getFiles(prod, platform); return CheckRevisionV3.checkRevision(formula, prod, platform, dll);
110-
case 4: files = CheckRevisionV1.getFiles(prod, platform); return CheckRevisionV4.checkRevision(formula, prod, platform, dll);
110+
case 4: files = new String[0]; return CheckRevisionV4.checkRevision(formula, prod, platform, dll);
111111
default:files = CheckRevisionV1.getFiles(prod, platform); return CheckRevisionV2.checkRevision(formula, prod, platform, dll);
112112
}
113113
}catch(FileNotFoundException e){
@@ -157,6 +157,7 @@ public static CheckrevisionResults getRevision(int prod, String formula, String
157157
if(dll.matches("lockdown-IX86-[0-1][0-9].mpq") == true) return getRevision(prod, formula, dll, Constants.PLATFORM_INTEL, 3);
158158

159159
if(dll.matches("CheckRevision.mpq") == true) return getRevision(prod, formula, dll, Constants.PLATFORM_INTEL, 4);
160+
if(dll.matches("CheckRevisionD1.mpq") == true) return getRevision(prod, formula, dll, Constants.PLATFORM_INTEL, 4);
160161

161162
Out.info("CHSUM", "Unknown archive: " + dll + ", Filetime: 0x" + Long.toHexString(filetime));
162163
return null;

util/Constants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public final class Constants{
3131
{"IX86/DSHR/", "Diablo_s.exe", "Storm.dll", "Battle.snp", "DSHR.bin"},
3232
{"IX86/SSHR/", "Starcraft_s.exe", "Storm.dll", "Battle.snp", "SSHR.bin"}
3333
};
34-
public static int[] IX86verbytes = {0xD3, 0xD3, 0x4f, 0x0e, 0x0e, 0xa9, 0x1E, 0x1E, 0x2a, 0x2a, 0xa5};
34+
public static int[] IX86verbytes = {0xD3, 0xD3, 0x4f, 0x0e, 0x0e, 0xa9, 0x1E, 0x1E, 0x2a, 0x2a, 0xa5};
35+
public static String[] IX86versions = {"", "", "2.0.2.1", "1.14.3.71", "1.14.3.71", "", "", "", "2001, 5, 18, 1", "", ""};
36+
public static String[] IX86certs = {"", "", "", "", "", "", "", "", "", "", ""};
3537

3638
public static String ArchivePath = "DLLs/";
3739
public static String LogFilePath = "./Logs/";

util/cSettings.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ public static void LoadSettings() {
4949

5050
//Load IX86 Versioning Settings
5151
for(int x = 0; x < Constants.prods.length; x++){
52-
Constants.IX86files[x][0] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "HashPath", Constants.IX86files[x][0]);
53-
Constants.IX86files[x][1] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "Exe", Constants.IX86files[x][1]);
54-
Constants.IX86files[x][2] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "Storm", Constants.IX86files[x][2]);
55-
Constants.IX86files[x][3] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "Network", Constants.IX86files[x][3]);
56-
Constants.IX86files[x][4] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "Screen", Constants.IX86files[x][4]);
57-
Constants.IX86verbytes[x] = Integer.parseInt(Ini.ReadIni(file, Constants.prods[x] + "-IX86", "VerByte", Integer.toHexString(Constants.IX86verbytes[x])), 16);
52+
String header = Constants.prods[x] + "-IX86";
53+
Constants.IX86files[x][0] = Ini.ReadIni(file, header, "HashPath", Constants.IX86files[x][0]);
54+
Constants.IX86files[x][1] = Ini.ReadIni(file, header, "Exe", Constants.IX86files[x][1]);
55+
Constants.IX86files[x][2] = Ini.ReadIni(file, header, "Storm", Constants.IX86files[x][2]);
56+
Constants.IX86files[x][3] = Ini.ReadIni(file, header, "Network", Constants.IX86files[x][3]);
57+
Constants.IX86files[x][4] = Ini.ReadIni(file, header, "Screen", Constants.IX86files[x][4]);
58+
Constants.IX86verbytes[x] = Integer.parseInt(Ini.ReadIni(file, header, "VerByte", Integer.toHexString(Constants.IX86verbytes[x])), 16);
59+
Constants.IX86versions[x] = Ini.ReadIni(file, header, "Version", Constants.IX86versions[x]);
60+
Constants.IX86certs[x] = Ini.ReadIni(file, header, "Cert", Constants.IX86certs[x]);
5861
}
5962
}
6063
public static void SaveSettings(){
@@ -94,13 +97,16 @@ public static void SaveSettings(){
9497

9598
//Save IX86 Versioning Settings
9699
for(int x = 0; x < Constants.prods.length; x++){
97-
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "HashPath", Constants.IX86files[x][0]);
98-
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "Exe", Constants.IX86files[x][1]);
99-
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "Storm", Constants.IX86files[x][2]);
100-
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "Network", Constants.IX86files[x][3]);
101-
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "Screen", Constants.IX86files[x][4]);
102-
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "VerByte",
100+
String header = Constants.prods[x] + "-IX86";
101+
Ini.WriteIni(file, header, "HashPath", Constants.IX86files[x][0]);
102+
Ini.WriteIni(file, header, "Exe", Constants.IX86files[x][1]);
103+
Ini.WriteIni(file, header, "Storm", Constants.IX86files[x][2]);
104+
Ini.WriteIni(file, header, "Network", Constants.IX86files[x][3]);
105+
Ini.WriteIni(file, header, "Screen", Constants.IX86files[x][4]);
106+
Ini.WriteIni(file, header, "VerByte",
103107
PadString.padString(Integer.toHexString(Constants.IX86verbytes[x]), 2, '0'));
108+
Ini.WriteIni(file, header, "Version", Constants.IX86versions[x]);
109+
Ini.WriteIni(file, header, "Cert", Constants.IX86certs[x]);
104110
}
105111

106112
}

0 commit comments

Comments
 (0)