Add ent command for analysing the randomness of keys

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent e4776f7c3c
commit ae88bca924
  1. 32
      archive/src/main/kotlin/org/openrs2/archive/key/EntCommand.kt
  2. 1
      archive/src/main/kotlin/org/openrs2/archive/key/KeyCommand.kt
  3. 38
      archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt

@ -0,0 +1,32 @@
package org.openrs2.archive.key
import com.github.ajalt.clikt.core.CliktCommand
import com.google.inject.Guice
import kotlinx.coroutines.runBlocking
import org.openrs2.archive.ArchiveModule
import org.openrs2.inject.CloseableInjector
import java.io.BufferedOutputStream
import java.io.DataOutputStream
public class EntCommand : CliktCommand(name = "ent") {
override fun run(): Unit = runBlocking {
CloseableInjector(Guice.createInjector(ArchiveModule)).use { injector ->
val exporter = injector.getInstance(KeyExporter::class.java)
val keys = exporter.exportValid()
val process = ProcessBuilder("ent")
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
DataOutputStream(BufferedOutputStream(process.outputStream)).use { out ->
for (key in keys) {
out.writeInt(key.k0)
out.writeInt(key.k1)
out.writeInt(key.k2)
out.writeInt(key.k3)
}
}
}
}
}

@ -8,6 +8,7 @@ public class KeyCommand : NoOpCliktCommand(name = "key") {
subcommands( subcommands(
BruteForceCommand(), BruteForceCommand(),
DownloadCommand(), DownloadCommand(),
EntCommand(),
ImportCommand() ImportCommand()
) )
} }

@ -0,0 +1,38 @@
package org.openrs2.archive.key
import org.openrs2.crypto.XteaKey
import org.openrs2.db.Database
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
public class KeyExporter @Inject constructor(
private val database: Database
) {
public suspend fun exportValid(): List<XteaKey> {
return database.execute { connection ->
connection.prepareStatement(
"""
SELECT (k.key).k0, (k.key).k1, (k.key).k2, (k.key).k3
FROM keys k
JOIN containers c ON c.key_id = k.id
ORDER BY k.id ASC
""".trimIndent()
).use { stmt ->
stmt.executeQuery().use { rows ->
val keys = mutableListOf<XteaKey>()
while (rows.next()) {
val k0 = rows.getInt(1)
val k1 = rows.getInt(2)
val k2 = rows.getInt(3)
val k3 = rows.getInt(4)
keys += XteaKey(k0, k1, k2, k3)
}
keys
}
}
}
}
}
Loading…
Cancel
Save