mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 12:51:51 +09:00
hash checking for module's jarfile
This commit is contained in:
@@ -25,6 +25,9 @@ version=0.3.0
|
||||
# Due to security reasons, loading an arbitrary JAR is not allowed.
|
||||
jar=
|
||||
|
||||
# Sha256sum of the External JAR, if any
|
||||
jarhash=
|
||||
|
||||
# Modules that must be pre-installed, separate multiple by semicolon (;)
|
||||
# Dependency syntax: "module's identification name (aka folder name) spaces allowed versionnumber"
|
||||
# Version number:
|
||||
|
||||
@@ -6,4 +6,5 @@ entrypoint=net.torvald.terrarum.modulecomputers.EntryPoint
|
||||
releasedate=2021-12-03
|
||||
version=0.3.0
|
||||
jar=ModuleComputers.jar
|
||||
jarhash=b2d50cc10693885f060a5825a4fb2be2993b461bae2e58b4a4900fa169ec898f
|
||||
dependency=basegame 0.3.0
|
||||
|
||||
@@ -11,8 +11,10 @@ import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import org.apache.commons.csv.CSVFormat
|
||||
import org.apache.commons.csv.CSVParser
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
@@ -100,6 +102,8 @@ object ModMgr {
|
||||
errorLogs.add(ModuleErrorInfo(type, moduleName, cause))
|
||||
}
|
||||
|
||||
private val digester = DigestUtils.getSha256Digest()
|
||||
|
||||
/**
|
||||
* Try to create an instance of a "titlescreen" from the current load order set.
|
||||
*/
|
||||
@@ -162,6 +166,7 @@ object ModMgr {
|
||||
val releaseDate = modMetadata.getProperty("releasedate")
|
||||
val version = modMetadata.getProperty("version")
|
||||
val jar = modMetadata.getProperty("jar")
|
||||
val jarHash = modMetadata.getProperty("jarhash").uppercase()
|
||||
val dependency = modMetadata.getProperty("dependency").split(Regex(""";[ ]*""")).filter { it.isNotEmpty() }.toTypedArray()
|
||||
val isDir = FileSystems.getDefault().getPath("$modDir/$moduleName").toFile().isDirectory
|
||||
|
||||
@@ -203,10 +208,20 @@ object ModMgr {
|
||||
if (jar.isNotBlank()) {
|
||||
val urls = arrayOf<URL>()
|
||||
|
||||
val jarFilePath = "${File(modDir).absolutePath}/$moduleName/$jar"
|
||||
val cl = JarFileLoader(urls)
|
||||
cl.addFile("${File(modDir).absolutePath}/$moduleName/$jar")
|
||||
cl.addFile(jarFilePath)
|
||||
moduleClassloader[moduleName] = cl
|
||||
|
||||
// check for hash
|
||||
digester.reset()
|
||||
val hash = digester.digest(File(jarFilePath).readBytes()).joinToString("","","") { it.toInt().and(255).toString(16).uppercase().padStart(2,'0') }
|
||||
|
||||
if (jarHash != hash) {
|
||||
println("Hash expected: $jarHash, got: $hash")
|
||||
throw IllegalStateException("Module Jarfile hash mismatch")
|
||||
}
|
||||
|
||||
// check for module-info.java
|
||||
val moduleInfoPath = cl.getResources("module-info.class").toList().filter { it.toString().contains("$moduleName/$jar!/module-info.class") && it.toString().endsWith("module-info.class")}
|
||||
if (moduleInfoPath.size == 0) {
|
||||
|
||||
@@ -6,10 +6,7 @@ import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.modulebasegame.ui.MODULEINFO_CELL_HEIGHT
|
||||
import net.torvald.terrarum.modulebasegame.ui.MODULEINFO_CELL_WIDTH
|
||||
|
||||
@@ -27,6 +24,7 @@ class UIItemModuleInfoCell(
|
||||
|
||||
private val modProp = ModMgr.moduleInfo[modName] ?: ModMgr.moduleInfoErrored[modName]!!
|
||||
|
||||
private val modErrors = ModMgr.errorLogs.filter { it.moduleName == modName }
|
||||
private val modErrored = (ModMgr.moduleInfo[modName] == null)
|
||||
|
||||
private val modIcon = try {
|
||||
@@ -88,7 +86,10 @@ class UIItemModuleInfoCell(
|
||||
batch.shader = null
|
||||
batch.color = Color.WHITE
|
||||
App.fontGame.draw(batch, "$ccZero${modName.toUpperCase()}$ccNum $modVer", initialX + 86f + 3f, initialY + 2f)
|
||||
App.fontGame.draw(batch, "$ccDesc$modDesc", initialX + 86f + 3f, initialY + 26f)
|
||||
if (modErrored)
|
||||
App.fontGame.draw(batch, "$emphRed${modErrors.first().cause?.message}", initialX + 86f + 3f, initialY + 26f)
|
||||
else
|
||||
App.fontGame.draw(batch, "$ccDesc$modDesc", initialX + 86f + 3f, initialY + 26f)
|
||||
App.fontGame.draw(batch, "$ccZero2$modAuthor$ccNum2 $modDate", initialX + 86f + 3f, initialY + 50f)
|
||||
|
||||
if (modErrored) {
|
||||
|
||||
Reference in New Issue
Block a user