Skip to content

Commit

Permalink
Update to support CREV with CheckRevisionD1.mpq
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Davnit committed Jul 7, 2019
1 parent b05aba1 commit 4ed27a2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 39 deletions.
67 changes: 42 additions & 25 deletions Hashing/CheckRevisionV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,17 @@ public static CheckrevisionResults checkRevision(String value, int prod, byte pl
}
crCacheMisses++;

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

BigInteger vint = new BigInteger(InetAddress.getByName(version).getAddress());
Version[plat][prod] = vint.intValue();
Version[plat][prod] = 0;

Buffer buff = new Buffer(new Buffer(Base64.getDecoder().decode(value)).removeBytes(4));
Buffer seed = new Buffer(new Buffer(Base64.getDecoder().decode(value)).removeBytes(4));

Buffer buff = new Buffer(seed.getBuffer());
buff.addString(":" + version + ":");
buff.addByte((byte)1);

Expand All @@ -80,9 +78,31 @@ public static CheckrevisionResults checkRevision(String value, int prod, byte pl
Out.error("CREV", "Hashing failed - SHA1 not supported");
return null;
}
String b64 = Base64.getEncoder().encodeToString(hash);
String ret = Base64.getEncoder().encodeToString(hash);

// Add the certificate hash if needed
if (mpq.endsWith("D1.mpq")) {
Version[plat][prod] = 6;

String certHex = Constants.IX86certs[prod-1];
if (certHex.length() == 0) {
Out.error("CREV", "Simple check revision unavailable for " + Constants.prods[prod-1] + ": missing certificate");
return null;
}
buff = new Buffer(hexToBytes(certHex));
buff.addBytes(seed.getBuffer());

try {
hash = MessageDigest.getInstance("SHA-1").digest(buff.getBuffer());
} catch (NoSuchAlgorithmException e) {
Out.error("CREV", "Hashing failed - SHA1 not supported (step 2)");
return null;
}

ret += ":" + Base64.getEncoder().encodeToString(hash);
}

byte[] checkB = b64.substring(0, 4).getBytes();
byte[] checkB = ret.substring(0, 4).getBytes();

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

Buffer info = new Buffer(b64.substring(4).getBytes());
Buffer info = new Buffer(ret.substring(4).getBytes());
info.addByte((byte)0); // Null terminator

CheckrevisionResults result = new CheckrevisionResults(0, checksum, info);
CheckrevisionResults result = new CheckrevisionResults(Version[plat][prod], checksum, info);
crCache.put(value + mpq + prod + plat, result);
return result;
}

public static String getVersionString(int version)
{
try {
byte[] b = BigInteger.valueOf(version).toByteArray();
InetAddress val = InetAddress.getByAddress(b);
return val.getHostAddress();
} catch (UnknownHostException e) {
Out.error("CREV", "Unable to parse version string");
return null;
}
public static byte[] hexToBytes(String hex) {
byte[] value = new byte[hex.length() / 2];
for (int i = 0; i < value.length; i++) {
int index = i * 2;
value[i] = (byte)Integer.parseInt(hex.substring(index, index + 2), 16);
}
return value;
}
}
3 changes: 2 additions & 1 deletion Hashing/HashMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static CheckrevisionResults getRevision(int prod, String formula, String
case 1: files = CheckRevisionV1.getFiles(prod, platform); return CheckRevisionV1.checkRevision(formula, prod, platform, dll);
case 2: files = CheckRevisionV1.getFiles(prod, platform); return CheckRevisionV2.checkRevision(formula, prod, platform, dll);
case 3: files = CheckRevisionV3.getFiles(prod, platform); return CheckRevisionV3.checkRevision(formula, prod, platform, dll);
case 4: files = CheckRevisionV1.getFiles(prod, platform); return CheckRevisionV4.checkRevision(formula, prod, platform, dll);
case 4: files = new String[0]; return CheckRevisionV4.checkRevision(formula, prod, platform, dll);
default:files = CheckRevisionV1.getFiles(prod, platform); return CheckRevisionV2.checkRevision(formula, prod, platform, dll);
}
}catch(FileNotFoundException e){
Expand Down Expand Up @@ -157,6 +157,7 @@ public static CheckrevisionResults getRevision(int prod, String formula, String
if(dll.matches("lockdown-IX86-[0-1][0-9].mpq") == true) return getRevision(prod, formula, dll, Constants.PLATFORM_INTEL, 3);

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

Out.info("CHSUM", "Unknown archive: " + dll + ", Filetime: 0x" + Long.toHexString(filetime));
return null;
Expand Down
4 changes: 3 additions & 1 deletion util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public final class Constants{
{"IX86/DSHR/", "Diablo_s.exe", "Storm.dll", "Battle.snp", "DSHR.bin"},
{"IX86/SSHR/", "Starcraft_s.exe", "Storm.dll", "Battle.snp", "SSHR.bin"}
};
public static int[] IX86verbytes = {0xD3, 0xD3, 0x4f, 0x0e, 0x0e, 0xa9, 0x1E, 0x1E, 0x2a, 0x2a, 0xa5};
public static int[] IX86verbytes = {0xD3, 0xD3, 0x4f, 0x0e, 0x0e, 0xa9, 0x1E, 0x1E, 0x2a, 0x2a, 0xa5};
public static String[] IX86versions = {"", "", "2.0.2.1", "1.14.3.71", "1.14.3.71", "", "", "", "2001, 5, 18, 1", "", ""};
public static String[] IX86certs = {"", "", "", "", "", "", "", "", "", "", ""};

public static String ArchivePath = "DLLs/";
public static String LogFilePath = "./Logs/";
Expand Down
30 changes: 18 additions & 12 deletions util/cSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ public static void LoadSettings() {

//Load IX86 Versioning Settings
for(int x = 0; x < Constants.prods.length; x++){
Constants.IX86files[x][0] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "HashPath", Constants.IX86files[x][0]);
Constants.IX86files[x][1] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "Exe", Constants.IX86files[x][1]);
Constants.IX86files[x][2] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "Storm", Constants.IX86files[x][2]);
Constants.IX86files[x][3] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "Network", Constants.IX86files[x][3]);
Constants.IX86files[x][4] = Ini.ReadIni(file, Constants.prods[x] + "-IX86", "Screen", Constants.IX86files[x][4]);
Constants.IX86verbytes[x] = Integer.parseInt(Ini.ReadIni(file, Constants.prods[x] + "-IX86", "VerByte", Integer.toHexString(Constants.IX86verbytes[x])), 16);
String header = Constants.prods[x] + "-IX86";
Constants.IX86files[x][0] = Ini.ReadIni(file, header, "HashPath", Constants.IX86files[x][0]);
Constants.IX86files[x][1] = Ini.ReadIni(file, header, "Exe", Constants.IX86files[x][1]);
Constants.IX86files[x][2] = Ini.ReadIni(file, header, "Storm", Constants.IX86files[x][2]);
Constants.IX86files[x][3] = Ini.ReadIni(file, header, "Network", Constants.IX86files[x][3]);
Constants.IX86files[x][4] = Ini.ReadIni(file, header, "Screen", Constants.IX86files[x][4]);
Constants.IX86verbytes[x] = Integer.parseInt(Ini.ReadIni(file, header, "VerByte", Integer.toHexString(Constants.IX86verbytes[x])), 16);
Constants.IX86versions[x] = Ini.ReadIni(file, header, "Version", Constants.IX86versions[x]);
Constants.IX86certs[x] = Ini.ReadIni(file, header, "Cert", Constants.IX86certs[x]);
}
}
public static void SaveSettings(){
Expand Down Expand Up @@ -94,13 +97,16 @@ public static void SaveSettings(){

//Save IX86 Versioning Settings
for(int x = 0; x < Constants.prods.length; x++){
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "HashPath", Constants.IX86files[x][0]);
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "Exe", Constants.IX86files[x][1]);
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "Storm", Constants.IX86files[x][2]);
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "Network", Constants.IX86files[x][3]);
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "Screen", Constants.IX86files[x][4]);
Ini.WriteIni(file, Constants.prods[x] + "-IX86", "VerByte",
String header = Constants.prods[x] + "-IX86";
Ini.WriteIni(file, header, "HashPath", Constants.IX86files[x][0]);
Ini.WriteIni(file, header, "Exe", Constants.IX86files[x][1]);
Ini.WriteIni(file, header, "Storm", Constants.IX86files[x][2]);
Ini.WriteIni(file, header, "Network", Constants.IX86files[x][3]);
Ini.WriteIni(file, header, "Screen", Constants.IX86files[x][4]);
Ini.WriteIni(file, header, "VerByte",
PadString.padString(Integer.toHexString(Constants.IX86verbytes[x]), 2, '0'));
Ini.WriteIni(file, header, "Version", Constants.IX86versions[x]);
Ini.WriteIni(file, header, "Cert", Constants.IX86certs[x]);
}

}
Expand Down

0 comments on commit 4ed27a2

Please sign in to comment.