Skip to content

Commit 47c9509

Browse files
committed
Store the original SHA-256 inside server jars.
1 parent 7538a93 commit 47c9509

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

loader/src/main/java/com/fox2code/foxloader/installer/InstallerGUI.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ public void extractServer() {
366366
"com.fox2code.foxloader.launcher.ServerMain")
367367
.getBytes(StandardCharsets.UTF_8)), zipOutputStream);
368368
zipOutputStream.closeEntry();
369+
// Insert the original FoxLoader jar hash in the server jar file.
370+
zipOutputStream.putNextEntry(new ZipEntry("META-INF/FL-SHA-256"));
371+
zipOutputStream.write(IOUtils.sha256Of(Main.currentInstallerFile));
372+
zipOutputStream.closeEntry();
369373
} else {
370374
zipOutputStream.putNextEntry(zipEntry);
371375
IOUtils.copy(zipInputStream, zipOutputStream);

loader/src/main/java/com/fox2code/foxloader/installer/Main.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package com.fox2code.foxloader.installer;
2525

26+
import com.fox2code.foxloader.launcher.FoxLauncher;
2627
import com.fox2code.foxloader.launcher.LauncherType;
2728
import com.fox2code.foxloader.launcher.ServerMain;
2829
import com.fox2code.foxloader.utils.SourceUtil;
@@ -37,6 +38,10 @@
3738
public class Main {
3839
static final File currentInstallerFile = SourceUtil.getSourceFile(Main.class);
3940
public static void main(String[] args) throws Throwable {
41+
if (FoxLauncher.class.getClassLoader().getResource("META-INF/FL-SHA-256") != null) {
42+
System.out.println("This jar file has been erroneously tampered with!");
43+
return;
44+
}
4045
if (args.length == 0 && GraphicsEnvironment.isHeadless()) {
4146
ServerMain.main(new String[]{"nogui"});
4247
return;

loader/src/main/java/com/fox2code/foxloader/loader/ModLoaderInit.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.fox2code.foxloader.patching.mixin.MixinModLoader;
3737
import com.fox2code.foxloader.updater.FoxLoaderUpdater;
3838
import com.fox2code.foxloader.utils.Platform;
39+
import com.fox2code.foxloader.utils.io.IOUtils;
3940
import com.google.gson.Gson;
4041
import com.google.gson.GsonBuilder;
4142
import net.minecraft.client.Minecraft;
@@ -46,6 +47,8 @@
4647

4748
import java.io.File;
4849
import java.io.IOException;
50+
import java.io.InputStream;
51+
import java.math.BigInteger;
4952
import java.util.*;
5053
import java.util.jar.JarEntry;
5154
import java.util.jar.JarFile;
@@ -65,6 +68,8 @@ public final class ModLoaderInit {
6568
static final File config = new File(FoxLauncher.getGameDir(), "config");
6669
static final ModContainer FOX_LOADER_CONTAINER = new ModContainer(
6770
JavaLoadingPlugin.JAVA_LOADING_PLUGIN, JavaModInfo.FOX_LOADER_MOD_INFO);
71+
// When extracting the server jar, the FoxLoader SHA-256 is altered.
72+
public static final String FOXLOADER_TRUE_SHA_256;
6873
static final LinkedHashMap<String, ModContainer> modContainers = new LinkedHashMap<>();
6974
private static final Collection<ModContainer> modContainnersCollection =
7075
Collections.unmodifiableCollection(modContainers.values());
@@ -75,6 +80,16 @@ public final class ModLoaderInit {
7580
((LoadingPlugin) JavaLoadingPlugin.JAVA_LOADING_PLUGIN).javaModInfo = JavaModInfo.FOX_LOADER_MOD_INFO;
7681
FoxLauncher.getFoxClassLoader().injectMissingFileInfo(JavaModInfo.FOX_LOADER_MOD_INFO);
7782
assertValidModInfo(JavaModInfo.FOX_LOADER_MOD_INFO, true);
83+
String trueSha256 = JavaModInfo.FOX_LOADER_MOD_INFO.sha256;
84+
try (InputStream inputStream = FoxLauncher.class.getClassLoader().getResourceAsStream("META-INF/FL-SHA-256")) {
85+
if (inputStream != null) {
86+
if (FoxLauncher.isClient()) {
87+
throw new RuntimeException("This jar file has been erroneously tampered with.");
88+
}
89+
trueSha256 = new BigInteger(1, IOUtils.readAllBytes(inputStream)).toString(16);
90+
}
91+
} catch (IOException ignored) {}
92+
FOXLOADER_TRUE_SHA_256 = trueSha256;
7893
}
7994

8095
public static @NotNull Logger getModLoaderLogger() {

0 commit comments

Comments
 (0)