Enable explicit API mode

This already caught some cases of public members that should have been
private and one case where the inferred type was too specific.

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent ed2a3f6dc6
commit 232ba32bbd
  1. 4
      all/src/main/java/dev/openrs2/Command.kt
  2. 2
      asm/src/main/java/dev/openrs2/asm/AsmJacksonModule.kt
  3. 2
      asm/src/main/java/dev/openrs2/asm/AsmModule.kt
  4. 6
      asm/src/main/java/dev/openrs2/asm/ClassForNameUtils.kt
  5. 4
      asm/src/main/java/dev/openrs2/asm/ClassNameExtensions.kt
  6. 20
      asm/src/main/java/dev/openrs2/asm/ClassNodeRemapper.kt
  7. 6
      asm/src/main/java/dev/openrs2/asm/ClassVersionUtils.kt
  8. 6
      asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt
  9. 10
      asm/src/main/java/dev/openrs2/asm/InsnMatcher.kt
  10. 20
      asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt
  11. 12
      asm/src/main/java/dev/openrs2/asm/MemberDesc.kt
  12. 16
      asm/src/main/java/dev/openrs2/asm/MemberRef.kt
  13. 2
      asm/src/main/java/dev/openrs2/asm/MemberRefDeserializer.kt
  14. 2
      asm/src/main/java/dev/openrs2/asm/MemberRefKeyDeserializer.kt
  15. 8
      asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt
  16. 2
      asm/src/main/java/dev/openrs2/asm/NopClassVisitor.kt
  17. 4
      asm/src/main/java/dev/openrs2/asm/StackMetadata.kt
  18. 12
      asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt
  19. 30
      asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt
  20. 18
      asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt
  21. 10
      asm/src/main/java/dev/openrs2/asm/classpath/ExtendedRemapper.kt
  22. 2
      asm/src/main/java/dev/openrs2/asm/classpath/JsrInliner.kt
  23. 20
      asm/src/main/java/dev/openrs2/asm/classpath/Library.kt
  24. 4
      asm/src/main/java/dev/openrs2/asm/classpath/LibraryRemapper.kt
  25. 8
      asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt
  26. 2
      asm/src/main/java/dev/openrs2/asm/classpath/StackFrameClassWriter.kt
  27. 2
      asm/src/main/java/dev/openrs2/asm/filter/AnyClassFilter.kt
  28. 2
      asm/src/main/java/dev/openrs2/asm/filter/AnyMemberFilter.kt
  29. 4
      asm/src/main/java/dev/openrs2/asm/filter/ClassFilter.kt
  30. 6
      asm/src/main/java/dev/openrs2/asm/filter/Glob.kt
  31. 2
      asm/src/main/java/dev/openrs2/asm/filter/GlobClassFilter.kt
  32. 2
      asm/src/main/java/dev/openrs2/asm/filter/GlobMemberFilter.kt
  33. 6
      asm/src/main/java/dev/openrs2/asm/filter/MemberFilter.kt
  34. 2
      asm/src/main/java/dev/openrs2/asm/filter/UnionClassFilter.kt
  35. 2
      asm/src/main/java/dev/openrs2/asm/filter/UnionMemberFilter.kt
  36. 2
      asm/src/main/java/dev/openrs2/asm/io/AbstractJarLibraryWriter.kt
  37. 2
      asm/src/main/java/dev/openrs2/asm/io/JarLibraryReader.kt
  38. 2
      asm/src/main/java/dev/openrs2/asm/io/JarLibraryWriter.kt
  39. 4
      asm/src/main/java/dev/openrs2/asm/io/LibraryReader.kt
  40. 4
      asm/src/main/java/dev/openrs2/asm/io/LibraryWriter.kt
  41. 2
      asm/src/main/java/dev/openrs2/asm/io/ManifestJarLibraryWriter.kt
  42. 2
      asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryReader.kt
  43. 2
      asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryWriter.kt
  44. 2
      asm/src/main/java/dev/openrs2/asm/io/PackClassLibraryReader.kt
  45. 2
      asm/src/main/java/dev/openrs2/asm/io/PackClassLibraryWriter.kt
  46. 2
      asm/src/main/java/dev/openrs2/asm/io/SignedJarLibraryWriter.kt
  47. 4
      asm/src/main/java/dev/openrs2/asm/transform/Transformer.kt
  48. 2
      buffer/src/main/java/dev/openrs2/buffer/ReferenceCountedExtensions.kt
  49. 6
      build.gradle.kts
  50. 4
      bundler/src/main/java/dev/openrs2/bundler/BundleCommand.kt
  51. 4
      bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
  52. 2
      bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt
  53. 2
      bundler/src/main/java/dev/openrs2/bundler/BundlerQualifier.kt
  54. 28
      bundler/src/main/java/dev/openrs2/bundler/Resource.kt
  55. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/BufferSizeTransformer.kt
  56. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.kt
  57. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/DomainTransformer.kt
  58. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/HostCheckTransformer.kt
  59. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/LoadLibraryTransformer.kt
  60. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/MacResizeTransformer.kt
  61. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/MemoryAllocationTransformer.kt
  62. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/NameTransformer.kt
  63. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/PlatformDetectionTransformer.kt
  64. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/PublicKeyTransformer.kt
  65. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/ResourceTransformer.kt
  66. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/RightClickTransformer.kt
  67. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/TypoTransformer.kt
  68. 8
      cache/src/main/java/dev/openrs2/cache/BufferedFileChannel.kt
  69. 8
      cache/src/main/java/dev/openrs2/cache/DiskStore.kt
  70. 8
      cache/src/main/java/dev/openrs2/cache/FlatFileStore.kt
  71. 8
      cache/src/main/java/dev/openrs2/cache/Js5Compression.kt
  72. 10
      cache/src/main/java/dev/openrs2/cache/Js5CompressionType.kt
  73. 26
      cache/src/main/java/dev/openrs2/cache/Store.kt
  74. 2
      cache/src/main/java/dev/openrs2/cache/StoreCorruptException.kt
  75. 2
      cache/src/main/java/dev/openrs2/cache/StoreFullException.kt
  76. 4
      compress-cli/src/main/java/dev/openrs2/compress/cli/CompressCommand.kt
  77. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bunzip2Command.kt
  78. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bzip2Command.kt
  79. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/DeflateCommand.kt
  80. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/InflateCommand.kt
  81. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GunzipCommand.kt
  82. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GzipCommand.kt
  83. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/LzmaCommand.kt
  84. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/UnlzmaCommand.kt
  85. 6
      compress/src/main/java/dev/openrs2/compress/bzip2/Bzip2.kt
  86. 9
      compress/src/main/java/dev/openrs2/compress/gzip/Gzip.kt
  87. 2
      compress/src/main/java/dev/openrs2/compress/gzip/GzipLevelOutputStream.kt
  88. 12
      compress/src/main/java/dev/openrs2/compress/lzma/Lzma.kt
  89. 2
      conf/src/main/java/dev/openrs2/conf/Config.kt
  90. 2
      conf/src/main/java/dev/openrs2/conf/ConfigModule.kt
  91. 2
      conf/src/main/java/dev/openrs2/conf/ConfigProvider.kt
  92. 4
      crc32/src/main/java/dev/openrs2/crc32/Crc32Command.kt
  93. 2
      crypto/src/main/java/dev/openrs2/crypto/CryptoModule.kt
  94. 8
      crypto/src/main/java/dev/openrs2/crypto/IsaacRandom.kt
  95. 8
      crypto/src/main/java/dev/openrs2/crypto/Pkcs12KeyStore.kt
  96. 28
      crypto/src/main/java/dev/openrs2/crypto/Rsa.kt
  97. 2
      crypto/src/main/java/dev/openrs2/crypto/RsaKeyProvider.kt
  98. 2
      crypto/src/main/java/dev/openrs2/crypto/ThreadLocalSecureRandom.kt
  99. 12
      crypto/src/main/java/dev/openrs2/crypto/Whirlpool.kt
  100. 20
      crypto/src/main/java/dev/openrs2/crypto/Xtea.kt
  101. Some files were not shown because too many files have changed in this diff Show More

@ -10,9 +10,9 @@ import dev.openrs2.deob.DeobfuscateCommand
import dev.openrs2.deob.ast.DeobfuscateAstCommand
import dev.openrs2.game.GameCommand
fun main(args: Array<String>) = Command().main(args)
public fun main(args: Array<String>): Unit = Command().main(args)
class Command : NoOpCliktCommand(name = "openrs2") {
public class Command : NoOpCliktCommand(name = "openrs2") {
init {
subcommands(
BundleCommand(),

@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule
import javax.inject.Singleton
@Singleton
class AsmJacksonModule : SimpleModule() {
public class AsmJacksonModule : SimpleModule() {
init {
addDeserializer(MemberRef::class.java, MemberRefDeserializer)
addKeyDeserializer(MemberRef::class.java, MemberRefKeyDeserializer)

@ -5,7 +5,7 @@ import com.google.inject.AbstractModule
import com.google.inject.multibindings.Multibinder
import dev.openrs2.yaml.YamlModule
object AsmModule : AbstractModule() {
public object AsmModule : AbstractModule() {
override fun configure() {
install(YamlModule)

@ -6,7 +6,7 @@ import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
object ClassForNameUtils {
public object ClassForNameUtils {
private val INVOKE_MATCHER = InsnMatcher.compile("LDC INVOKESTATIC")
private fun isClassForName(match: List<AbstractInsnNode>): Boolean {
@ -31,11 +31,11 @@ object ClassForNameUtils {
return (ldc.cst as String).toInternalClassName()
}
fun findClassNames(method: MethodNode): Sequence<String> {
public fun findClassNames(method: MethodNode): Sequence<String> {
return findLdcInsns(method).map(::internalName)
}
fun remap(remapper: Remapper, method: MethodNode) {
public fun remap(remapper: Remapper, method: MethodNode) {
for (ldc in findLdcInsns(method)) {
val name = remapper.mapType(internalName(ldc))
if (name != null) {

@ -1,9 +1,9 @@
package dev.openrs2.asm
fun String.toBinaryClassName(): String {
public fun String.toBinaryClassName(): String {
return replace('/', '.')
}
fun String.toInternalClassName(): String {
public fun String.toInternalClassName(): String {
return replace('.', '/')
}

@ -18,7 +18,7 @@ import org.objectweb.asm.tree.ParameterNode
import org.objectweb.asm.tree.TryCatchBlockNode
import org.objectweb.asm.tree.TypeInsnNode
fun ClassNode.remap(remapper: ExtendedRemapper) {
public fun ClassNode.remap(remapper: ExtendedRemapper) {
val originalName = name
name = remapper.mapType(originalName)
signature = remapper.mapSignature(signature, false)
@ -46,20 +46,20 @@ fun ClassNode.remap(remapper: ExtendedRemapper) {
}
}
fun InnerClassNode.remap(remapper: Remapper) {
public fun InnerClassNode.remap(remapper: Remapper) {
name = remapper.mapType(name)
outerName = remapper.mapType(outerName)
innerName = remapper.mapType(innerName)
}
fun FieldNode.remap(remapper: ExtendedRemapper, owner: String) {
public fun FieldNode.remap(remapper: ExtendedRemapper, owner: String) {
name = remapper.mapFieldName(owner, name, desc)
desc = remapper.mapDesc(desc)
signature = remapper.mapSignature(signature, true)
value = remapper.mapValue(value)
}
fun MethodNode.remap(remapper: ExtendedRemapper, owner: String) {
public fun MethodNode.remap(remapper: ExtendedRemapper, owner: String) {
if (parameters == null) {
parameters = List(Type.getArgumentTypes(desc).size) { ParameterNode(null, 0) }
}
@ -86,15 +86,21 @@ fun MethodNode.remap(remapper: ExtendedRemapper, owner: String) {
}
}
fun ParameterNode.remap(remapper: ExtendedRemapper, owner: String, methodName: String, desc: String, index: Int) {
public fun ParameterNode.remap(
remapper: ExtendedRemapper,
owner: String,
methodName: String,
desc: String,
index: Int
) {
name = remapper.mapArgumentName(owner, methodName, desc, index, name)
}
fun TryCatchBlockNode.remap(remapper: Remapper) {
public fun TryCatchBlockNode.remap(remapper: Remapper) {
type = remapper.mapType(type)
}
fun AbstractInsnNode.remap(remapper: ExtendedRemapper) {
public fun AbstractInsnNode.remap(remapper: ExtendedRemapper) {
when (this) {
is FrameNode -> throw UnsupportedOperationException("SKIP_FRAMES and COMPUTE_FRAMES must be used")
is FieldInsnNode -> {

@ -1,15 +1,15 @@
package dev.openrs2.asm
object ClassVersionUtils {
public object ClassVersionUtils {
private fun swapWords(v: Int): Int {
return (v shl 16) or (v ushr 16)
}
fun gte(v1: Int, v2: Int): Boolean {
public fun gte(v1: Int, v2: Int): Boolean {
return swapWords(v1) >= swapWords(v2)
}
fun max(v1: Int, v2: Int): Int {
public fun max(v1: Int, v2: Int): Int {
return if (gte(v1, v2)) {
v1
} else {

@ -5,7 +5,7 @@ import org.objectweb.asm.tree.InsnList
private val ANY_INSN = { _: AbstractInsnNode -> true }
fun getExpression(
public fun getExpression(
last: AbstractInsnNode,
filter: (AbstractInsnNode) -> Boolean = ANY_INSN
): List<AbstractInsnNode>? {
@ -31,7 +31,7 @@ fun getExpression(
return null
}
fun InsnList.replaceExpression(
public fun InsnList.replaceExpression(
last: AbstractInsnNode,
replacement: AbstractInsnNode,
filter: (AbstractInsnNode) -> Boolean = ANY_INSN
@ -42,7 +42,7 @@ fun InsnList.replaceExpression(
return true
}
fun InsnList.deleteExpression(
public fun InsnList.deleteExpression(
last: AbstractInsnNode,
filter: (AbstractInsnNode) -> Boolean = ANY_INSN
): Boolean {

@ -6,12 +6,12 @@ import org.objectweb.asm.tree.InsnList
import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.util.Printer
class InsnMatcher private constructor(private val regex: Regex) {
fun match(method: MethodNode): Sequence<List<AbstractInsnNode>> {
public class InsnMatcher private constructor(private val regex: Regex) {
public fun match(method: MethodNode): Sequence<List<AbstractInsnNode>> {
return match(method.instructions)
}
fun match(list: InsnList): Sequence<List<AbstractInsnNode>> {
public fun match(list: InsnList): Sequence<List<AbstractInsnNode>> {
val insns = ArrayList<AbstractInsnNode>(list.size())
val builder = StringBuilder(list.size())
@ -27,7 +27,7 @@ class InsnMatcher private constructor(private val regex: Regex) {
}
}
companion object {
public companion object {
private const val PRIVATE_USE_AREA = 0xE000
private val OPCODE_GROUPS = mapOf(
"InsnNode" to intArrayOf(
@ -260,7 +260,7 @@ class InsnMatcher private constructor(private val regex: Regex) {
throw IllegalArgumentException("$opcode is not a valid opcode or opcode group")
}
fun compile(regex: String): InsnMatcher {
public fun compile(regex: String): InsnMatcher {
val pattern = StringBuilder()
val opcode = StringBuilder()

@ -200,7 +200,7 @@ private val THROW_RETURN_OPCODES = listOf(
Opcodes.ATHROW
)
val AbstractInsnNode.nextReal: AbstractInsnNode?
public val AbstractInsnNode.nextReal: AbstractInsnNode?
get() {
var insn = next
while (insn != null && insn.opcode == -1) {
@ -209,7 +209,7 @@ val AbstractInsnNode.nextReal: AbstractInsnNode?
return insn
}
val AbstractInsnNode.previousReal: AbstractInsnNode?
public val AbstractInsnNode.previousReal: AbstractInsnNode?
get() {
var insn = previous
while (insn != null && insn.opcode == -1) {
@ -218,7 +218,7 @@ val AbstractInsnNode.previousReal: AbstractInsnNode?
return insn
}
val AbstractInsnNode.nextVirtual: AbstractInsnNode?
public val AbstractInsnNode.nextVirtual: AbstractInsnNode?
get() {
var insn = next
while (insn != null && insn.opcode != -1) {
@ -227,7 +227,7 @@ val AbstractInsnNode.nextVirtual: AbstractInsnNode?
return insn
}
val AbstractInsnNode.previousVirtual: AbstractInsnNode?
public val AbstractInsnNode.previousVirtual: AbstractInsnNode?
get() {
var insn = previous
while (insn != null && insn.opcode != -1) {
@ -236,7 +236,7 @@ val AbstractInsnNode.previousVirtual: AbstractInsnNode?
return insn
}
val AbstractInsnNode.intConstant: Int?
public val AbstractInsnNode.intConstant: Int?
get() = when (this) {
is IntInsnNode -> {
if (opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH) {
@ -265,7 +265,7 @@ val AbstractInsnNode.intConstant: Int?
}
}
val AbstractInsnNode.isSequential: Boolean
public val AbstractInsnNode.isSequential: Boolean
get() = when (this) {
is LabelNode -> false
is JumpInsnNode -> false
@ -274,14 +274,14 @@ val AbstractInsnNode.isSequential: Boolean
else -> opcode !in THROW_RETURN_OPCODES
}
val AbstractInsnNode.isPure: Boolean
public val AbstractInsnNode.isPure: Boolean
get() = when (opcode) {
in PURE_OPCODES -> true
in IMPURE_OPCODES -> false
else -> throw IllegalArgumentException()
}
fun Int.toAbstractInsnNode(): AbstractInsnNode = when (this) {
public fun Int.toAbstractInsnNode(): AbstractInsnNode = when (this) {
-1 -> InsnNode(Opcodes.ICONST_M1)
0 -> InsnNode(Opcodes.ICONST_0)
1 -> InsnNode(Opcodes.ICONST_1)
@ -294,7 +294,7 @@ fun Int.toAbstractInsnNode(): AbstractInsnNode = when (this) {
else -> LdcInsnNode(this)
}
fun AbstractInsnNode.toPrettyString(): String {
public fun AbstractInsnNode.toPrettyString(): String {
val printer = Textifier()
val visitor = TraceMethodVisitor(printer)
@ -308,7 +308,7 @@ fun AbstractInsnNode.toPrettyString(): String {
}
}
fun TryCatchBlockNode.isBodyEmpty(): Boolean {
public fun TryCatchBlockNode.isBodyEmpty(): Boolean {
var current = start.next
while (true) {

@ -5,12 +5,12 @@ import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
data class MemberDesc(val name: String, val desc: String) {
constructor(field: FieldNode) : this(field.name, field.desc)
constructor(method: MethodNode) : this(method.name, method.desc)
constructor(fieldInsn: FieldInsnNode) : this(fieldInsn.name, fieldInsn.desc)
constructor(methodInsn: MethodInsnNode) : this(methodInsn.name, methodInsn.desc)
constructor(memberRef: MemberRef) : this(memberRef.name, memberRef.desc)
public data class MemberDesc(val name: String, val desc: String) {
public constructor(field: FieldNode) : this(field.name, field.desc)
public constructor(method: MethodNode) : this(method.name, method.desc)
public constructor(fieldInsn: FieldInsnNode) : this(fieldInsn.name, fieldInsn.desc)
public constructor(methodInsn: MethodInsnNode) : this(methodInsn.name, methodInsn.desc)
public constructor(memberRef: MemberRef) : this(memberRef.name, memberRef.desc)
override fun toString(): String {
return "$name $desc"

@ -6,12 +6,12 @@ import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
data class MemberRef(val owner: String, val name: String, val desc: String) : Comparable<MemberRef> {
constructor(clazz: ClassNode, field: FieldNode) : this(clazz.name, field.name, field.desc)
constructor(clazz: ClassNode, method: MethodNode) : this(clazz.name, method.name, method.desc)
constructor(fieldInsn: FieldInsnNode) : this(fieldInsn.owner, fieldInsn.name, fieldInsn.desc)
constructor(methodInsn: MethodInsnNode) : this(methodInsn.owner, methodInsn.name, methodInsn.desc)
constructor(owner: String, desc: MemberDesc) : this(owner, desc.name, desc.desc)
public data class MemberRef(val owner: String, val name: String, val desc: String) : Comparable<MemberRef> {
public constructor(clazz: ClassNode, field: FieldNode) : this(clazz.name, field.name, field.desc)
public constructor(clazz: ClassNode, method: MethodNode) : this(clazz.name, method.name, method.desc)
public constructor(fieldInsn: FieldInsnNode) : this(fieldInsn.owner, fieldInsn.name, fieldInsn.desc)
public constructor(methodInsn: MethodInsnNode) : this(methodInsn.owner, methodInsn.name, methodInsn.desc)
public constructor(owner: String, desc: MemberDesc) : this(owner, desc.name, desc.desc)
override fun compareTo(other: MemberRef): Int {
var result = owner.compareTo(other.owner)
@ -31,10 +31,10 @@ data class MemberRef(val owner: String, val name: String, val desc: String) : Co
return "$owner.$name $desc"
}
companion object {
public companion object {
private val STRING_REGEX = Regex("([^.]+)[.]([^ ]+) (.+)")
fun fromString(str: String): MemberRef {
public fun fromString(str: String): MemberRef {
val result = STRING_REGEX.matchEntire(str)
require(result != null)
return MemberRef(result.groupValues[1], result.groupValues[2], result.groupValues[3])

@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
object MemberRefDeserializer : StdDeserializer<MemberRef>(MemberRef::class.java) {
public object MemberRefDeserializer : StdDeserializer<MemberRef>(MemberRef::class.java) {
override fun deserialize(parser: JsonParser, ctx: DeserializationContext): MemberRef {
return MemberRef.fromString(ctx.readValue(parser, String::class.java))
}

@ -3,7 +3,7 @@ package dev.openrs2.asm
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.KeyDeserializer
object MemberRefKeyDeserializer : KeyDeserializer() {
public object MemberRefKeyDeserializer : KeyDeserializer() {
override fun deserializeKey(key: String, ctx: DeserializationContext): Any {
return MemberRef.fromString(key)
}

@ -33,7 +33,7 @@ private fun remapAll(indexes: List<Int>, argType: Type, localIndex: Int, newLoca
return indexes.mapTo(mutableListOf()) { remap(it, argType, localIndex, newLocalIndex) }
}
fun MethodNode.removeArgument(argIndex: Int) {
public fun MethodNode.removeArgument(argIndex: Int) {
// remove argument from the descriptor
val type = Type.getType(desc)
val argType = type.argumentTypes[argIndex]
@ -129,7 +129,7 @@ fun MethodNode.removeArgument(argIndex: Int) {
}
}
fun MethodNode.removeDeadCode(owner: String) {
public fun MethodNode.removeDeadCode(owner: String) {
var changed: Boolean
do {
changed = false
@ -152,10 +152,10 @@ fun MethodNode.removeDeadCode(owner: String) {
} while (changed)
}
val MethodNode.hasCode
public val MethodNode.hasCode: Boolean
get() = access and (Opcodes.ACC_NATIVE or Opcodes.ACC_ABSTRACT) == 0
fun MethodNode.copy(): MethodNode {
public fun MethodNode.copy(): MethodNode {
val copy = MethodNode(
access,
name,

@ -3,4 +3,4 @@ package dev.openrs2.asm
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.Opcodes
object NopClassVisitor : ClassVisitor(Opcodes.ASM8)
public object NopClassVisitor : ClassVisitor(Opcodes.ASM8)

@ -9,7 +9,7 @@ import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MultiANewArrayInsnNode
data class StackMetadata(val pops: Int, val pushes: Int)
public data class StackMetadata(val pops: Int, val pushes: Int)
private val NONE = StackMetadata(0, 0)
private val POP1 = StackMetadata(1, 0)
@ -181,7 +181,7 @@ private val SIMPLE_OPCODES = mapOf(
Opcodes.IFNONNULL to POP1
)
val AbstractInsnNode.stackMetadata
public val AbstractInsnNode.stackMetadata: StackMetadata
get() = when (this) {
is LdcInsnNode -> if (cst is Double || cst is Long) {
PUSH2

@ -4,7 +4,7 @@ import dev.openrs2.asm.MemberDesc
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
class AsmClassMetadata(
public class AsmClassMetadata(
private val classPath: ClassPath,
private val clazz: ClassNode,
override val dependency: Boolean
@ -12,19 +12,19 @@ class AsmClassMetadata(
override val name: String
get() = clazz.name
override val `interface`
override val `interface`: Boolean
get() = clazz.access and Opcodes.ACC_INTERFACE != 0
override val superClass
override val superClass: ClassMetadata?
get() = clazz.superName?.let { classPath[it] ?: error("Failed to find $it on provided classpath.") }
override val superInterfaces
override val superInterfaces: List<ClassMetadata>
get() = clazz.interfaces.map { classPath[it] ?: error("Failed to find $it on provided classpath.") }
override val fields
override val fields: List<MemberDesc>
get() = clazz.fields.map(::MemberDesc)
override val methods
override val methods: List<MemberDesc>
get() = clazz.methods.map(::MemberDesc)
override fun getFieldAccess(field: MemberDesc): Int? {

@ -2,16 +2,16 @@ package dev.openrs2.asm.classpath
import dev.openrs2.asm.MemberDesc
abstract class ClassMetadata {
abstract val name: String
abstract val dependency: Boolean
abstract val `interface`: Boolean
abstract val superClass: ClassMetadata?
abstract val superInterfaces: List<ClassMetadata>
abstract val fields: List<MemberDesc>
abstract val methods: List<MemberDesc>
val superClassAndInterfaces: List<ClassMetadata>
public abstract class ClassMetadata {
public abstract val name: String
public abstract val dependency: Boolean
public abstract val `interface`: Boolean
public abstract val superClass: ClassMetadata?
public abstract val superInterfaces: List<ClassMetadata>
public abstract val fields: List<MemberDesc>
public abstract val methods: List<MemberDesc>
public val superClassAndInterfaces: List<ClassMetadata>
get() {
val clazz = superClass
return if (clazz != null) {
@ -21,10 +21,10 @@ abstract class ClassMetadata {
}
}
abstract fun getFieldAccess(field: MemberDesc): Int?
abstract fun getMethodAccess(method: MemberDesc): Int?
public abstract fun getFieldAccess(field: MemberDesc): Int?
public abstract fun getMethodAccess(method: MemberDesc): Int?
fun isOverride(method: MemberDesc): Boolean {
public fun isOverride(method: MemberDesc): Boolean {
val superClass = this.superClass
if (superClass != null) {
if (method in superClass.methods) {
@ -49,7 +49,7 @@ abstract class ClassMetadata {
return false
}
fun isAssignableFrom(type: ClassMetadata): Boolean {
public fun isAssignableFrom(type: ClassMetadata): Boolean {
return type == this || isSuperClassOf(type) || isSuperInterfaceOf(type)
}
@ -71,7 +71,7 @@ abstract class ClassMetadata {
return false
}
fun resolveField(member: MemberDesc): ClassMetadata? {
public fun resolveField(member: MemberDesc): ClassMetadata? {
// see https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-5.html#jvms-5.4.3.2
if (fields.contains(member)) {

@ -10,10 +10,10 @@ import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
import java.util.IdentityHashMap
class ClassPath(
public class ClassPath(
private val runtime: ClassLoader,
private val dependencies: List<Library>,
val libraries: List<Library>
public val libraries: List<Library>
) {
private val cache = mutableMapOf<String, ClassMetadata?>()
@ -26,9 +26,9 @@ class ClassPath(
* Transformers to avoid adding extraneous labels until the last possible
* moment, which would confuse some of our analyses if added earlier.
*/
val originalPcs = IdentityHashMap<AbstractInsnNode, Int>()
public val originalPcs: MutableMap<AbstractInsnNode, Int> = IdentityHashMap()
val libraryClasses: Sequence<ClassMetadata>
public val libraryClasses: Sequence<ClassMetadata>
get() = libraries.asSequence().flatten().map { get(it.name)!! }
private inline fun computeIfAbsent(name: String, f: (String) -> ClassMetadata?): ClassMetadata? {
@ -41,7 +41,7 @@ class ClassPath(
return clazz
}
operator fun get(name: String): ClassMetadata? = computeIfAbsent(name) {
public operator fun get(name: String): ClassMetadata? = computeIfAbsent(name) {
for (library in libraries) {
val clazz = library[name]
if (clazz != null) {
@ -65,7 +65,7 @@ class ClassPath(
return@computeIfAbsent ReflectionClassMetadata(this, clazz)
}
fun getClassNode(name: String): ClassNode? {
public fun getClassNode(name: String): ClassNode? {
for (library in libraries) {
val clazz = library[name]
if (clazz != null) {
@ -76,7 +76,7 @@ class ClassPath(
return null
}
fun remap(remapper: ExtendedRemapper) {
public fun remap(remapper: ExtendedRemapper) {
for (library in libraries) {
library.remap(remapper)
}
@ -84,11 +84,11 @@ class ClassPath(
cache.clear()
}
fun createInheritedFieldSets(): DisjointSet<MemberRef> {
public fun createInheritedFieldSets(): DisjointSet<MemberRef> {
return createInheritedMemberSets(ClassMetadata::fields, ClassMetadata::getFieldAccess, fields = true)
}
fun createInheritedMethodSets(): DisjointSet<MemberRef> {
public fun createInheritedMethodSets(): DisjointSet<MemberRef> {
return createInheritedMemberSets(ClassMetadata::methods, ClassMetadata::getMethodAccess, fields = false)
}

@ -3,20 +3,20 @@ package dev.openrs2.asm.classpath
import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.AbstractInsnNode
abstract class ExtendedRemapper : Remapper() {
open fun getFieldInitializer(owner: String, name: String, descriptor: String): List<AbstractInsnNode>? {
public abstract class ExtendedRemapper : Remapper() {
public open fun getFieldInitializer(owner: String, name: String, descriptor: String): List<AbstractInsnNode>? {
return null
}
open fun mapFieldOwner(owner: String, name: String, descriptor: String): String {
public open fun mapFieldOwner(owner: String, name: String, descriptor: String): String {
return mapType(owner)
}
open fun mapMethodOwner(owner: String, name: String, descriptor: String): String {
public open fun mapMethodOwner(owner: String, name: String, descriptor: String): String {
return mapType(owner)
}
open fun mapArgumentName(
public open fun mapArgumentName(
owner: String,
name: String,
descriptor: String,

@ -5,7 +5,7 @@ import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes
import org.objectweb.asm.commons.JSRInlinerAdapter
class JsrInliner(cv: ClassVisitor) : ClassVisitor(Opcodes.ASM8, cv) {
public class JsrInliner(cv: ClassVisitor) : ClassVisitor(Opcodes.ASM8, cv) {
override fun visitMethod(
access: Int,
name: String,

@ -10,10 +10,10 @@ import java.nio.file.Path
import java.util.SortedMap
import java.util.TreeMap
class Library(val name: String) : Iterable<ClassNode> {
public class Library(public val name: String) : Iterable<ClassNode> {
private var classes: SortedMap<String, ClassNode> = TreeMap()
constructor(name: String, library: Library) : this(name) {
public constructor(name: String, library: Library) : this(name) {
for (clazz in library.classes.values) {
val copy = ClassNode()
clazz.accept(copy)
@ -21,19 +21,19 @@ class Library(val name: String) : Iterable<ClassNode> {
}
}
operator fun contains(name: String): Boolean {
public operator fun contains(name: String): Boolean {
return classes.containsKey(name)
}
operator fun get(name: String): ClassNode? {
public operator fun get(name: String): ClassNode? {
return classes[name]
}
fun add(clazz: ClassNode): ClassNode? {
public fun add(clazz: ClassNode): ClassNode? {
return classes.put(clazz.name, clazz)
}
fun remove(name: String): ClassNode? {
public fun remove(name: String): ClassNode? {
return classes.remove(name)
}
@ -41,11 +41,11 @@ class Library(val name: String) : Iterable<ClassNode> {
return classes.values.iterator()
}
fun remap(remapper: ExtendedRemapper) {
public fun remap(remapper: ExtendedRemapper) {
classes = LibraryRemapper(remapper, classes).remap()
}
fun write(path: Path, writer: LibraryWriter, classPath: ClassPath) {
public fun write(path: Path, writer: LibraryWriter, classPath: ClassPath) {
logger.info { "Writing library $path" }
path.useAtomicOutputStream { output ->
@ -53,10 +53,10 @@ class Library(val name: String) : Iterable<ClassNode> {
}
}
companion object {
public companion object {
private val logger = InlineLogger()
fun read(name: String, path: Path, reader: LibraryReader): Library {
public fun read(name: String, path: Path, reader: LibraryReader): Library {
logger.info { "Reading library $path" }
val classes = Files.newInputStream(path).use { input ->

@ -15,7 +15,7 @@ import java.util.SortedMap
import java.util.TreeMap
import kotlin.math.max
class LibraryRemapper(
public class LibraryRemapper(
private val remapper: ExtendedRemapper,
private var classes: SortedMap<String, ClassNode>
) {
@ -34,7 +34,7 @@ class LibraryRemapper(
private val splicedFields = mutableSetOf<MemberRef>()
private val methods = mutableListOf<Method>()
fun remap(): SortedMap<String, ClassNode> {
public fun remap(): SortedMap<String, ClassNode> {
// extract static fields/methods that are being moved between classes
extractFields()
extractMethods()

@ -7,7 +7,7 @@ import org.objectweb.asm.Type
private val Class<*>.asmName: String
get() = name.toInternalClassName()
class ReflectionClassMetadata(private val classPath: ClassPath, private val clazz: Class<*>) : ClassMetadata() {
public class ReflectionClassMetadata(private val classPath: ClassPath, private val clazz: Class<*>) : ClassMetadata() {
override val name: String
get() = clazz.asmName
@ -20,13 +20,13 @@ class ReflectionClassMetadata(private val classPath: ClassPath, private val claz
override val superClass: ClassMetadata?
get() = if (clazz.superclass != null) classPath[clazz.superclass.asmName]!! else null
override val superInterfaces
override val superInterfaces: List<ClassMetadata>
get() = clazz.interfaces.map { classPath[it.asmName]!! }
override val fields
override val fields: List<MemberDesc>
get() = clazz.declaredFields.map { MemberDesc(it.name, Type.getDescriptor(it.type)) }
override val methods
override val methods: List<MemberDesc>
get() = clazz.declaredMethods.map { MemberDesc(it.name, Type.getMethodDescriptor(it)) }
override fun getFieldAccess(field: MemberDesc): Int? {

@ -2,7 +2,7 @@ package dev.openrs2.asm.classpath
import org.objectweb.asm.ClassWriter
class StackFrameClassWriter(private val classPath: ClassPath) : ClassWriter(COMPUTE_FRAMES) {
public class StackFrameClassWriter(private val classPath: ClassPath) : ClassWriter(COMPUTE_FRAMES) {
override fun getCommonSuperClass(type1: String, type2: String): String {
var c = classPath[type1]!!
val d = classPath[type2]!!

@ -1,6 +1,6 @@
package dev.openrs2.asm.filter
object AnyClassFilter : ClassFilter {
public object AnyClassFilter : ClassFilter {
override fun matches(name: String): Boolean {
return true
}

@ -1,6 +1,6 @@
package dev.openrs2.asm.filter
object AnyMemberFilter : MemberFilter {
public object AnyMemberFilter : MemberFilter {
override fun matches(owner: String, name: String, desc: String): Boolean {
return true
}

@ -1,5 +1,5 @@
package dev.openrs2.asm.filter
interface ClassFilter {
fun matches(name: String): Boolean
public interface ClassFilter {
public fun matches(name: String): Boolean
}

@ -1,11 +1,11 @@
package dev.openrs2.asm.filter
object Glob {
fun compile(pattern: String): Regex {
public object Glob {
public fun compile(pattern: String): Regex {
return compile(pattern, className = false)
}
fun compileClass(pattern: String): Regex {
public fun compileClass(pattern: String): Regex {
return compile(pattern, className = true)
}

@ -2,7 +2,7 @@ package dev.openrs2.asm.filter
import com.fasterxml.jackson.annotation.JsonIgnore
class GlobClassFilter(@Suppress("CanBeParameter") private val patterns: List<String>) : ClassFilter {
public class GlobClassFilter(@Suppress("CanBeParameter") private val patterns: List<String>) : ClassFilter {
@JsonIgnore
private val compiledPatterns = patterns.map(Glob::compileClass).toList()

@ -3,7 +3,7 @@ package dev.openrs2.asm.filter
import com.fasterxml.jackson.annotation.JsonIgnore
import dev.openrs2.asm.MemberRef
class GlobMemberFilter(@Suppress("CanBeParameter") private val patterns: List<MemberRef>) : MemberFilter {
public class GlobMemberFilter(@Suppress("CanBeParameter") private val patterns: List<MemberRef>) : MemberFilter {
private data class CompiledPattern(val owner: Regex, val name: Regex, val desc: Regex)
@JsonIgnore

@ -2,10 +2,10 @@ package dev.openrs2.asm.filter
import dev.openrs2.asm.MemberRef
interface MemberFilter {
fun matches(owner: String, name: String, desc: String): Boolean
public interface MemberFilter {
public fun matches(owner: String, name: String, desc: String): Boolean
fun matches(member: MemberRef): Boolean {
public fun matches(member: MemberRef): Boolean {
return matches(member.owner, member.name, member.desc)
}
}

@ -1,6 +1,6 @@
package dev.openrs2.asm.filter
class UnionClassFilter(vararg filters: ClassFilter) : ClassFilter {
public class UnionClassFilter(vararg filters: ClassFilter) : ClassFilter {
private val filters = filters.toList()
override fun matches(name: String): Boolean {

@ -1,6 +1,6 @@
package dev.openrs2.asm.filter
class UnionMemberFilter(vararg filters: MemberFilter) : MemberFilter {
public class UnionMemberFilter(vararg filters: MemberFilter) : MemberFilter {
private val filters = filters.toList()
override fun matches(owner: String, name: String, desc: String): Boolean {

@ -12,7 +12,7 @@ import java.io.OutputStream
import java.util.jar.JarEntry
import java.util.jar.JarOutputStream
abstract class AbstractJarLibraryWriter : LibraryWriter {
public abstract class AbstractJarLibraryWriter : LibraryWriter {
override fun write(output: OutputStream, classPath: ClassPath, classes: Iterable<ClassNode>) {
createJarOutputStream(output).use { jar ->
for (clazz in classes) {

@ -7,7 +7,7 @@ import org.objectweb.asm.tree.ClassNode
import java.io.InputStream
import java.util.jar.JarInputStream
object JarLibraryReader : LibraryReader {
public object JarLibraryReader : LibraryReader {
private const val CLASS_SUFFIX = ".class"
override fun read(input: InputStream): Iterable<ClassNode> {

@ -4,7 +4,7 @@ import dev.openrs2.util.io.DeterministicJarOutputStream
import java.io.OutputStream
import java.util.jar.JarOutputStream
object JarLibraryWriter : AbstractJarLibraryWriter() {
public object JarLibraryWriter : AbstractJarLibraryWriter() {
override fun createJarOutputStream(output: OutputStream): JarOutputStream {
return DeterministicJarOutputStream(output)
}

@ -3,6 +3,6 @@ package dev.openrs2.asm.io
import org.objectweb.asm.tree.ClassNode
import java.io.InputStream
interface LibraryReader {
fun read(input: InputStream): Iterable<ClassNode>
public interface LibraryReader {
public fun read(input: InputStream): Iterable<ClassNode>
}

@ -4,6 +4,6 @@ import dev.openrs2.asm.classpath.ClassPath
import org.objectweb.asm.tree.ClassNode
import java.io.OutputStream
interface LibraryWriter {
fun write(output: OutputStream, classPath: ClassPath, classes: Iterable<ClassNode>)
public interface LibraryWriter {
public fun write(output: OutputStream, classPath: ClassPath, classes: Iterable<ClassNode>)
}

@ -5,7 +5,7 @@ import java.io.OutputStream
import java.util.jar.JarOutputStream
import java.util.jar.Manifest
class ManifestJarLibraryWriter(private val manifest: Manifest) : AbstractJarLibraryWriter() {
public class ManifestJarLibraryWriter(private val manifest: Manifest) : AbstractJarLibraryWriter() {
override fun createJarOutputStream(output: OutputStream): JarOutputStream {
return DeterministicJarOutputStream(output, manifest)
}

@ -8,7 +8,7 @@ import java.io.InputStream
import java.util.jar.JarOutputStream
import java.util.jar.Pack200
object Pack200LibraryReader : LibraryReader {
public object Pack200LibraryReader : LibraryReader {
override fun read(input: InputStream): Iterable<ClassNode> {
ByteArrayOutputStream().use { tempOutput ->
Gzip.createHeaderlessInputStream(input).use { gzipInput ->

@ -9,7 +9,7 @@ import java.io.OutputStream
import java.util.jar.JarInputStream
import java.util.jar.Pack200
object Pack200LibraryWriter : LibraryWriter {
public object Pack200LibraryWriter : LibraryWriter {
override fun write(output: OutputStream, classPath: ClassPath, classes: Iterable<ClassNode>) {
ByteArrayOutputStream().use { tempOutput ->
JarLibraryWriter.write(tempOutput, classPath, classes)

@ -3,7 +3,7 @@ package dev.openrs2.asm.io
import org.objectweb.asm.tree.ClassNode
import java.io.InputStream
object PackClassLibraryReader : LibraryReader {
public object PackClassLibraryReader : LibraryReader {
override fun read(input: InputStream): Iterable<ClassNode> {
// TODO(gpe): implement
return emptyList()

@ -4,7 +4,7 @@ import dev.openrs2.asm.classpath.ClassPath
import org.objectweb.asm.tree.ClassNode
import java.io.OutputStream
object PackClassLibraryWriter : LibraryWriter {
public object PackClassLibraryWriter : LibraryWriter {
override fun write(output: OutputStream, classPath: ClassPath, classes: Iterable<ClassNode>) {
// TODO(gpe): implement
}

@ -14,7 +14,7 @@ import java.nio.file.Files
import java.util.jar.JarInputStream
import java.util.jar.Manifest
class SignedJarLibraryWriter(
public class SignedJarLibraryWriter(
private val manifest: Manifest,
private val keyStore: Pkcs12KeyStore
) : LibraryWriter {

@ -7,8 +7,8 @@ import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodNode
abstract class Transformer {
open fun transform(classPath: ClassPath) {
public abstract class Transformer {
public open fun transform(classPath: ClassPath) {
preTransform(classPath)
var changed: Boolean

@ -2,7 +2,7 @@ package dev.openrs2.buffer
import io.netty.util.ReferenceCounted
inline fun <T : ReferenceCounted, R> T.use(block: (T) -> R): R {
public inline fun <T : ReferenceCounted, R> T.use(block: (T) -> R): R {
try {
return block(this)
} finally {

@ -55,6 +55,12 @@ allprojects {
}
}
plugins.withType<KotlinPluginWrapper> {
kotlin {
explicitApi()
}
}
plugins.withType<KotlinterPlugin> {
configure<KotlinterExtension> {
// see https://github.com/pinterest/ktlint/issues/764

@ -4,9 +4,9 @@ import com.github.ajalt.clikt.core.CliktCommand
import com.google.inject.Guice
import java.nio.file.Paths
fun main(args: Array<String>) = BundleCommand().main(args)
public fun main(args: Array<String>): Unit = BundleCommand().main(args)
class BundleCommand : CliktCommand(name = "bundle") {
public class BundleCommand : CliktCommand(name = "bundle") {
override fun run() {
val injector = Guice.createInjector(BundlerModule)
val bundler = injector.getInstance(Bundler::class.java)

@ -23,7 +23,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class Bundler @Inject constructor(
public class Bundler @Inject constructor(
@BundlerQualifier private val transformers: Set<@JvmSuppressWildcards Transformer>,
private val config: Config
) {
@ -39,7 +39,7 @@ class Bundler @Inject constructor(
mainAttributes[PERMISSIONS] = "all-permissions"
}
fun run(input: Path, output: Path, keyStorePath: Path) {
public fun run(input: Path, output: Path, keyStorePath: Path) {
// read input jars/packs
logger.info { "Reading input jars" }
val unpacker = Library.read("unpackclass", input.resolve("unpackclass.pack"), JarLibraryReader)

@ -18,7 +18,7 @@ import dev.openrs2.bundler.transform.TypoTransformer
import dev.openrs2.conf.ConfigModule
import dev.openrs2.crypto.CryptoModule
object BundlerModule : AbstractModule() {
public object BundlerModule : AbstractModule() {
override fun configure() {
install(ConfigModule)
install(CryptoModule)

@ -5,4 +5,4 @@ import javax.inject.Qualifier
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION)
annotation class BundlerQualifier
public annotation class BundlerQualifier

@ -11,31 +11,31 @@ import java.security.MessageDigest
import java.util.zip.CRC32
import java.util.zip.Deflater
class Resource(
val source: String,
val destination: String,
val crc: Int,
val digest: ByteArray,
val uncompressedSize: Int,
val content: ByteArray
public class Resource(
public val source: String,
public val destination: String,
public val crc: Int,
public val digest: ByteArray,
public val uncompressedSize: Int,
public val content: ByteArray
) {
val sourceWithCrc: String
public val sourceWithCrc: String
get() = source.replace(".", "_$crc.")
val compressedSize: Int
public val compressedSize: Int
get() = content.size
init {
require(digest.size == 20)
}
fun write(dir: Path) {
public fun write(dir: Path) {
val path = dir.resolve(source)
logger.info { "Writing resource $path" }
Files.write(path, content)
}
companion object {
public companion object {
private val logger = InlineLogger()
private fun compress(source: String, destination: String, uncompressed: ByteArray): Resource {
@ -66,7 +66,7 @@ class Resource(
return Resource(source, destination, crc.value.toInt(), digest.digest(), uncompressed.size, content)
}
fun compressLibrary(
public fun compressLibrary(
source: String,
destination: String,
classPath: ClassPath,
@ -85,7 +85,7 @@ class Resource(
return compress(source, destination, uncompressed)
}
fun compressGlNatives() = listOf(
public fun compressGlNatives(): List<List<Resource>> = listOf(
// Windows i386
listOf(
compressNative("jaggl_0_0.lib", "jaggl.dll", "windows-i386/jaggl.dll")
@ -119,7 +119,7 @@ class Resource(
)
)
fun compressMiscNatives() = listOf(
public fun compressMiscNatives(): List<Resource> = listOf(
compressNative("jagmisc_0.lib", "jagmisc.dll", "windows-i386/jagmisc.dll"),
compressNative("jagmisc_1.lib", "jagmisc.dll", "windows-amd64/jagmisc.dll")
)

@ -15,7 +15,7 @@ import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class BufferSizeTransformer : Transformer() {
public class BufferSizeTransformer : Transformer() {
private var buffer: MemberRef? = null
private var buffersResized = 0

@ -12,7 +12,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class CachePathTransformer @Inject constructor(
public class CachePathTransformer @Inject constructor(
private val config: Config
) : Transformer() {
private var paths = 0

@ -12,7 +12,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class DomainTransformer @Inject constructor(
public class DomainTransformer @Inject constructor(
private val config: Config
) : Transformer() {
private var domains = 0

@ -14,7 +14,7 @@ import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class HostCheckTransformer : Transformer() {
public class HostCheckTransformer : Transformer() {
private var hostChecks = 0
override fun preTransform(classPath: ClassPath) {

@ -13,7 +13,7 @@ import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class LoadLibraryTransformer : Transformer() {
public class LoadLibraryTransformer : Transformer() {
private var jnilibs = 0
private var amd64Checks = 0
private var sunOsChecks = 0

@ -15,7 +15,7 @@ import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class MacResizeTransformer : Transformer() {
public class MacResizeTransformer : Transformer() {
private var branchesRemoved = 0
override fun preTransform(classPath: ClassPath) {

@ -15,7 +15,7 @@ import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class MemoryAllocationTransformer : Transformer() {
public class MemoryAllocationTransformer : Transformer() {
private var usedMemoryExprsZeroed = 0
override fun preTransform(classPath: ClassPath) {

@ -12,7 +12,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class NameTransformer @Inject constructor(
public class NameTransformer @Inject constructor(
private val config: Config
) : Transformer() {
private var names = 0

@ -22,7 +22,7 @@ import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class PlatformDetectionTransformer : Transformer() {
public class PlatformDetectionTransformer : Transformer() {
private var glBlocks = 0
private var miscBlocks = 0

@ -12,7 +12,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class PublicKeyTransformer @Inject constructor(private val key: RSAPrivateCrtKeyParameters) : Transformer() {
public class PublicKeyTransformer @Inject constructor(private val key: RSAPrivateCrtKeyParameters) : Transformer() {
private var exponents = 0
private var moduli = 0

@ -17,7 +17,7 @@ import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.TypeInsnNode
class ResourceTransformer(
public class ResourceTransformer(
private val resources: List<Resource>? = null,
private val glResources: List<List<Resource>> = Resource.compressGlNatives(),
private val miscResources: List<Resource> = Resource.compressMiscNatives()

@ -14,7 +14,7 @@ import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class RightClickTransformer : Transformer() {
public class RightClickTransformer : Transformer() {
private var metaDownCalls = 0
override fun preTransform(classPath: ClassPath) {

@ -10,7 +10,7 @@ import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class TypoTransformer : Transformer() {
public class TypoTransformer : Transformer() {
private var errorsFixed = 0
override fun preTransform(classPath: ClassPath) {

@ -9,7 +9,7 @@ import java.nio.channels.FileChannel
import kotlin.math.max
import kotlin.math.min
class BufferedFileChannel(
public class BufferedFileChannel(
private val channel: FileChannel,
readBufferSize: Int,
writeBufferSize: Int,
@ -23,7 +23,7 @@ class BufferedFileChannel(
private val writeBuffer = alloc.buffer(writeBufferSize, writeBufferSize)
private var writePos = -1L
fun read(pos: Long, dest: ByteBuf, len: Int) {
public fun read(pos: Long, dest: ByteBuf, len: Int) {
require(pos >= 0)
require(len <= dest.writableBytes())
@ -165,7 +165,7 @@ class BufferedFileChannel(
}
}
fun write(pos: Long, src: ByteBuf, len: Int) {
public fun write(pos: Long, src: ByteBuf, len: Int) {
require(pos >= 0)
require(len <= src.readableBytes())
@ -277,7 +277,7 @@ class BufferedFileChannel(
}
}
fun size(): Long {
public fun size(): Long {
return size
}

@ -17,7 +17,7 @@ import kotlin.math.min
* A [Store] implementation compatible with the native `main_file_cache.dat2`
* and `main_file_cache.idx*` format used by the client.
*/
class DiskStore private constructor(
public class DiskStore private constructor(
private val root: Path,
private val data: BufferedFileChannel,
private val indexes: Array<BufferedFileChannel?>,
@ -436,7 +436,7 @@ class DiskStore private constructor(
}
}
companion object {
public companion object {
private const val INDEX_ENTRY_SIZE = 6
private const val BLOCK_HEADER_SIZE = 8
@ -460,7 +460,7 @@ class DiskStore private constructor(
return root.resolve("main_file_cache.idx$archive")
}
fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
val data = BufferedFileChannel(
FileChannel.open(dataPath(root), READ, WRITE),
DATA_BUFFER_SIZE,
@ -485,7 +485,7 @@ class DiskStore private constructor(
return DiskStore(root, data, archives, alloc)
}
fun create(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
public fun create(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
Files.createDirectories(root)
val data = BufferedFileChannel(

@ -15,7 +15,7 @@ import java.nio.file.Path
* content-addressable version control systems, such as Git, than the native
* format used by the client.
*/
class FlatFileStore private constructor(
public class FlatFileStore private constructor(
private val root: Path,
private val alloc: ByteBufAllocator
) : Store {
@ -108,12 +108,12 @@ class FlatFileStore private constructor(
// no-op
}
companion object {
public companion object {
private val ARCHIVE_NAME = Regex("[1-9][0-9]*")
private val GROUP_NAME = Regex("[1-9][0-9]*[.]dat")
private const val GROUP_EXTENSION = ".dat"
fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
if (!Files.isDirectory(root)) {
throw FileNotFoundException()
}
@ -121,7 +121,7 @@ class FlatFileStore private constructor(
return FlatFileStore(root, alloc)
}
fun create(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
public fun create(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
Files.createDirectories(root)
return FlatFileStore(root, alloc)
}

@ -8,8 +8,8 @@ import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufInputStream
import io.netty.buffer.ByteBufOutputStream
object Js5Compression {
fun compress(input: ByteBuf, type: Js5CompressionType, key: XteaKey = XteaKey.ZERO): ByteBuf {
public object Js5Compression {
public fun compress(input: ByteBuf, type: Js5CompressionType, key: XteaKey = XteaKey.ZERO): ByteBuf {
input.alloc().buffer().use { output ->
output.writeByte(type.ordinal)
@ -48,7 +48,7 @@ object Js5Compression {
}
}
fun compressBest(input: ByteBuf, enableLzma: Boolean = false, key: XteaKey = XteaKey.ZERO): ByteBuf {
public fun compressBest(input: ByteBuf, enableLzma: Boolean = false, key: XteaKey = XteaKey.ZERO): ByteBuf {
var best = compress(input.slice(), Js5CompressionType.NONE, key)
try {
for (type in Js5CompressionType.values()) {
@ -73,7 +73,7 @@ object Js5Compression {
}
}
fun uncompress(input: ByteBuf, key: XteaKey = XteaKey.ZERO): ByteBuf {
public fun uncompress(input: ByteBuf, key: XteaKey = XteaKey.ZERO): ByteBuf {
val typeId = input.readUnsignedByte().toInt()
val type = Js5CompressionType.fromOrdinal(typeId)
require(type != null) {

@ -8,13 +8,13 @@ import java.io.OutputStream
import java.util.zip.Deflater
import java.util.zip.GZIPInputStream
enum class Js5CompressionType {
public enum class Js5CompressionType {
NONE,
BZIP2,
GZIP,
LZMA;
fun createInputStream(input: InputStream, length: Int): InputStream {
public fun createInputStream(input: InputStream, length: Int): InputStream {
return when (this) {
NONE -> input
BZIP2 -> Bzip2.createHeaderlessInputStream(input)
@ -23,7 +23,7 @@ enum class Js5CompressionType {
}
}
fun createOutputStream(output: OutputStream): OutputStream {
public fun createOutputStream(output: OutputStream): OutputStream {
return when (this) {
NONE -> output
BZIP2 -> Bzip2.createHeaderlessOutputStream(output)
@ -39,8 +39,8 @@ enum class Js5CompressionType {
}
}
companion object {
fun fromOrdinal(ordinal: Int): Js5CompressionType? {
public companion object {
public fun fromOrdinal(ordinal: Int): Js5CompressionType? {
val values = values()
return if (ordinal >= 0 && ordinal < values.size) {
values[ordinal]

@ -10,7 +10,7 @@ import java.io.IOException
* A low-level interface for reading and writing raw groups directly to and
* from a collection of JS5 archives.
*/
interface Store : Flushable, Closeable {
public interface Store : Flushable, Closeable {
/**
* Checks whether an archive exists.
* @param archive the archive ID.
@ -18,7 +18,7 @@ interface Store : Flushable, Closeable {
* @throws IllegalArgumentException if the archive ID is out of bounds.
* @throws IOException if an underlying I/O error occurs.
*/
fun exists(archive: Int): Boolean
public fun exists(archive: Int): Boolean
/**
* Checks whether a group exists.
@ -29,14 +29,14 @@ interface Store : Flushable, Closeable {
* bounds.
* @throws IOException if an underlying I/O error occurs.
*/
fun exists(archive: Int, group: Int): Boolean
public fun exists(archive: Int, group: Int): Boolean
/**
* Lists all archives in the store.
* @return a sorted list of archive IDs.
* @throws IOException if an underlying I/O error occurs.
*/
fun list(): List<Int>
public fun list(): List<Int>
/**
* Lists all groups in an archive.
@ -47,7 +47,7 @@ interface Store : Flushable, Closeable {
* @throws FileNotFoundException if the archive does not exist.
* @throws IOException if an underlying I/O error occurs.
*/
fun list(archive: Int): List<Int>
public fun list(archive: Int): List<Int>
/**
* Creates an archive. Does nothing if the archive already exists.
@ -55,7 +55,7 @@ interface Store : Flushable, Closeable {
* @throws IllegalArgumentException if the archive ID is out of bounds.
* @throws IOException if an underlying I/O error occurs.
*/
fun create(archive: Int)
public fun create(archive: Int)
/**
* Reads a group.
@ -71,7 +71,7 @@ interface Store : Flushable, Closeable {
* @throws StoreCorruptException if the store is corrupt.
* @throws IOException if an underlying I/O error occurs.
*/
fun read(archive: Int, group: Int): ByteBuf
public fun read(archive: Int, group: Int): ByteBuf
/**
* Writes a group. If the archive does not exist, it is created first. If a
@ -87,7 +87,7 @@ interface Store : Flushable, Closeable {
* @throws StoreFullException if the store is full.
* @throws IOException if an underlying I/O error occurs.
*/
fun write(archive: Int, group: Int, buf: ByteBuf)
public fun write(archive: Int, group: Int, buf: ByteBuf)
/**
* Deletes an archive and all groups contained inside it. Does nothing if
@ -96,7 +96,7 @@ interface Store : Flushable, Closeable {
* @throws IllegalArgumentException if the archive ID is out of bounds.
* @throws IOException if an underlying I/O error occurs.
*/
fun remove(archive: Int)
public fun remove(archive: Int)
/**
* Deletes a group. Does nothing if the archive or group does not exist.
@ -106,17 +106,17 @@ interface Store : Flushable, Closeable {
* bounds.
* @throws IOException if an underlying I/O error occurs.
*/
fun remove(archive: Int, group: Int)
public fun remove(archive: Int, group: Int)
companion object {
public companion object {
/**
* The maximum archive ID.
*/
const val MAX_ARCHIVE = 255
public const val MAX_ARCHIVE: Int = 255
/**
* The maximum length of a group's contents in bytes.
*/
const val MAX_GROUP_SIZE = (1 shl 24) - 1
public const val MAX_GROUP_SIZE: Int = (1 shl 24) - 1
}
}

@ -2,4 +2,4 @@ package dev.openrs2.cache
import java.io.IOException
class StoreCorruptException(message: String) : IOException(message)
public class StoreCorruptException(message: String) : IOException(message)

@ -2,4 +2,4 @@ package dev.openrs2.cache
import java.io.IOException
class StoreFullException : IOException()
public class StoreFullException : IOException()

@ -11,9 +11,9 @@ import dev.openrs2.compress.cli.gzip.GzipCommand
import dev.openrs2.compress.cli.lzma.LzmaCommand
import dev.openrs2.compress.cli.lzma.UnlzmaCommand
fun main(args: Array<String>) = CompressCommand().main(args)
public fun main(args: Array<String>): Unit = CompressCommand().main(args)
class CompressCommand : NoOpCliktCommand(name = "compress") {
public class CompressCommand : NoOpCliktCommand(name = "compress") {
init {
subcommands(
Bzip2Command(),

@ -8,7 +8,7 @@ import com.github.ajalt.clikt.parameters.types.inputStream
import com.github.ajalt.clikt.parameters.types.outputStream
import dev.openrs2.compress.bzip2.Bzip2
class Bunzip2Command : CliktCommand(name = "bunzip2") {
public class Bunzip2Command : CliktCommand(name = "bunzip2") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()

@ -8,7 +8,7 @@ import com.github.ajalt.clikt.parameters.types.inputStream
import com.github.ajalt.clikt.parameters.types.outputStream
import dev.openrs2.compress.bzip2.Bzip2
class Bzip2Command : CliktCommand(name = "bzip2") {
public class Bzip2Command : CliktCommand(name = "bzip2") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()

@ -12,7 +12,7 @@ import com.github.ajalt.clikt.parameters.types.outputStream
import java.util.zip.Deflater
import java.util.zip.DeflaterOutputStream
class DeflateCommand : CliktCommand(name = "deflate") {
public class DeflateCommand : CliktCommand(name = "deflate") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()
private val level by option().int().default(Deflater.BEST_COMPRESSION).validate {

@ -9,7 +9,7 @@ import com.github.ajalt.clikt.parameters.types.outputStream
import java.util.zip.Inflater
import java.util.zip.InflaterInputStream
class InflateCommand : CliktCommand(name = "inflate") {
public class InflateCommand : CliktCommand(name = "inflate") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()

@ -8,7 +8,7 @@ import com.github.ajalt.clikt.parameters.types.inputStream
import com.github.ajalt.clikt.parameters.types.outputStream
import dev.openrs2.compress.gzip.Gzip
class GunzipCommand : CliktCommand(name = "gunzip") {
public class GunzipCommand : CliktCommand(name = "gunzip") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()

@ -12,7 +12,7 @@ import com.github.ajalt.clikt.parameters.types.outputStream
import dev.openrs2.compress.gzip.Gzip
import java.util.zip.Deflater
class GzipCommand : CliktCommand(name = "gzip") {
public class GzipCommand : CliktCommand(name = "gzip") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()
private val level by option().int().default(Deflater.BEST_COMPRESSION).validate {

@ -12,7 +12,7 @@ import com.github.ajalt.clikt.parameters.types.outputStream
import dev.openrs2.compress.lzma.Lzma
import org.tukaani.xz.LZMA2Options
class LzmaCommand : CliktCommand(name = "lzma") {
public class LzmaCommand : CliktCommand(name = "lzma") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()
private val level by option().int().default(LZMA2Options.PRESET_DEFAULT).validate {

@ -10,7 +10,7 @@ import com.github.ajalt.clikt.parameters.types.long
import com.github.ajalt.clikt.parameters.types.outputStream
import dev.openrs2.compress.lzma.Lzma
class UnlzmaCommand : CliktCommand(name = "unlzma") {
public class UnlzmaCommand : CliktCommand(name = "unlzma") {
private val input by option().inputStream().defaultStdin()
private val length by option().long().required()
private val output by option().outputStream().defaultStdout()

@ -8,15 +8,15 @@ import java.io.InputStream
import java.io.OutputStream
import java.io.SequenceInputStream
object Bzip2 {
public object Bzip2 {
private const val BLOCK_SIZE = 1
private val HEADER = byteArrayOf('B'.toByte(), 'Z'.toByte(), 'h'.toByte(), ('0' + BLOCK_SIZE).toByte())
fun createHeaderlessInputStream(input: InputStream): InputStream {
public fun createHeaderlessInputStream(input: InputStream): InputStream {
return BZip2CompressorInputStream(SequenceInputStream(ByteArrayInputStream(HEADER), input))
}
fun createHeaderlessOutputStream(output: OutputStream): OutputStream {
public fun createHeaderlessOutputStream(output: OutputStream): OutputStream {
return BZip2CompressorOutputStream(SkipOutputStream(output, HEADER.size.toLong()), BLOCK_SIZE)
}
}

@ -8,14 +8,17 @@ import java.io.SequenceInputStream
import java.util.zip.Deflater
import java.util.zip.GZIPInputStream
object Gzip {
public object Gzip {
private val HEADER = byteArrayOf(0x1F, 0x8B.toByte())
fun createHeaderlessInputStream(input: InputStream): InputStream {
public fun createHeaderlessInputStream(input: InputStream): InputStream {
return GZIPInputStream(SequenceInputStream(ByteArrayInputStream(HEADER), input))
}
fun createHeaderlessOutputStream(output: OutputStream, level: Int = Deflater.BEST_COMPRESSION): OutputStream {
public fun createHeaderlessOutputStream(
output: OutputStream,
level: Int = Deflater.BEST_COMPRESSION
): OutputStream {
return GzipLevelOutputStream(SkipOutputStream(output, HEADER.size.toLong()), level)
}
}

@ -3,7 +3,7 @@ package dev.openrs2.compress.gzip
import java.io.OutputStream
import java.util.zip.GZIPOutputStream
class GzipLevelOutputStream(output: OutputStream, level: Int) : GZIPOutputStream(output) {
public class GzipLevelOutputStream(output: OutputStream, level: Int) : GZIPOutputStream(output) {
init {
def.setLevel(level)
}

@ -8,12 +8,12 @@ import org.tukaani.xz.LZMAOutputStream
import java.io.InputStream
import java.io.OutputStream
object Lzma {
val BEST_SPEED = LZMA2Options(LZMA2Options.PRESET_MIN)
val DEFAULT_COMPRESSION = LZMA2Options(LZMA2Options.PRESET_DEFAULT)
val BEST_COMPRESSION = LZMA2Options(LZMA2Options.PRESET_MAX)
public object Lzma {
public val BEST_SPEED: LZMA2Options = LZMA2Options(LZMA2Options.PRESET_MIN)
public val DEFAULT_COMPRESSION: LZMA2Options = LZMA2Options(LZMA2Options.PRESET_DEFAULT)
public val BEST_COMPRESSION: LZMA2Options = LZMA2Options(LZMA2Options.PRESET_MAX)
fun createHeaderlessInputStream(input: InputStream, length: Long): InputStream {
public fun createHeaderlessInputStream(input: InputStream, length: Long): InputStream {
val headerInput = LittleEndianDataInputStream(input)
val properties = headerInput.readByte()
@ -22,7 +22,7 @@ object Lzma {
return LZMAInputStream(input, length, properties, dictionarySize)
}
fun createHeaderlessOutputStream(output: OutputStream, options: LZMA2Options): OutputStream {
public fun createHeaderlessOutputStream(output: OutputStream, options: LZMA2Options): OutputStream {
val headerOutput = LittleEndianDataOutputStream(output)
headerOutput.writeByte((options.pb * 5 + options.lp) * 9 + options.lc)
headerOutput.writeInt(options.dictSize)

@ -1,6 +1,6 @@
package dev.openrs2.conf
data class Config(
public data class Config(
val game: String,
val operator: String,
val domain: String

@ -4,7 +4,7 @@ import com.google.inject.AbstractModule
import com.google.inject.Scopes
import dev.openrs2.yaml.YamlModule
object ConfigModule : AbstractModule() {
public object ConfigModule : AbstractModule() {
override fun configure() {
install(YamlModule)

@ -6,7 +6,7 @@ import java.nio.file.Paths
import javax.inject.Inject
import javax.inject.Provider
class ConfigProvider @Inject constructor(private val mapper: ObjectMapper) : Provider<Config> {
public class ConfigProvider @Inject constructor(private val mapper: ObjectMapper) : Provider<Config> {
override fun get(): Config {
if (Files.notExists(CONFIG_PATH)) {
Files.copy(EXAMPLE_CONFIG_PATH, CONFIG_PATH)

@ -6,9 +6,9 @@ import com.github.ajalt.clikt.parameters.types.defaultStdin
import com.github.ajalt.clikt.parameters.types.inputStream
import java.util.zip.CRC32
fun main(args: Array<String>) = Crc32Command().main(args)
public fun main(args: Array<String>): Unit = Crc32Command().main(args)
class Crc32Command : CliktCommand(name = "crc32") {
public class Crc32Command : CliktCommand(name = "crc32") {
private val input by option().inputStream().defaultStdin()
override fun run() {

@ -4,7 +4,7 @@ import com.google.inject.AbstractModule
import com.google.inject.Scopes
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters
object CryptoModule : AbstractModule() {
public object CryptoModule : AbstractModule() {
override fun configure() {
bind(RSAPrivateCrtKeyParameters::class.java)
.toProvider(RsaKeyProvider::class.java)

@ -1,6 +1,6 @@
package dev.openrs2.crypto
class IsaacRandom {
public class IsaacRandom {
private var count = 0
private val rsl: IntArray
private val mem = IntArray(SIZE)
@ -8,12 +8,12 @@ class IsaacRandom {
private var b = 0
private var c = 0
constructor() {
public constructor() {
rsl = IntArray(SIZE)
init(false)
}
constructor(seed: IntArray) {
public constructor(seed: IntArray) {
require(seed.size <= SIZE)
rsl = seed.copyOf(SIZE)
@ -257,7 +257,7 @@ class IsaacRandom {
this.a = a
}
fun nextInt(): Int {
public fun nextInt(): Int {
if (count-- == 0) {
isaac()
count = SIZE - 1

@ -23,20 +23,20 @@ import java.time.ZoneOffset
import java.util.Date
import java.util.jar.JarFile
class Pkcs12KeyStore private constructor(privateKeyEntry: KeyStore.PrivateKeyEntry, signerName: String) {
public class Pkcs12KeyStore private constructor(privateKeyEntry: KeyStore.PrivateKeyEntry, signerName: String) {
private val signer = JarSigner.Builder(privateKeyEntry)
.signatureAlgorithm("SHA256withRSA")
.digestAlgorithm("SHA-256")
.signerName(signerName)
.build()
fun signJar(input: Path, output: OutputStream) {
public fun signJar(input: Path, output: OutputStream) {
JarFile(input.toFile()).use { file ->
signer.sign(file, output)
}
}
companion object {
public companion object {
private const val ALIAS = "openrs2"
private const val PASSWORD = ALIAS
@ -51,7 +51,7 @@ class Pkcs12KeyStore private constructor(privateKeyEntry: KeyStore.PrivateKeyEnt
private val SHA256_WITH_RSA = AlgorithmIdentifier(PKCSObjectIdentifiers.sha256WithRSAEncryption)
private val SHA256 = AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256)
fun open(path: Path, signerName: String): Pkcs12KeyStore {
public fun open(path: Path, signerName: String): Pkcs12KeyStore {
val keyStore = KeyStore.getInstance("PKCS12")
if (Files.exists(path)) {
Files.newInputStream(path).use { input ->

@ -28,7 +28,7 @@ import java.nio.file.Path
import java.security.spec.KeySpec
import java.security.spec.RSAPrivateCrtKeySpec
val RSAPrivateCrtKeyParameters.publicKey
public val RSAPrivateCrtKeyParameters.publicKey: RSAKeyParameters
get() = RSAKeyParameters(false, modulus, publicExponent)
private fun ByteBuf.toBigInteger(): BigInteger {
@ -40,19 +40,19 @@ private fun BigInteger.toByteBuf(): ByteBuf {
return Unpooled.wrappedBuffer(toByteArray())
}
fun ByteBuf.rsaEncrypt(key: RSAKeyParameters): ByteBuf {
public fun ByteBuf.rsaEncrypt(key: RSAKeyParameters): ByteBuf {
return Rsa.encrypt(toBigInteger(), key).toByteBuf()
}
fun ByteBuf.rsaDecrypt(key: RSAKeyParameters): ByteBuf {
public fun ByteBuf.rsaDecrypt(key: RSAKeyParameters): ByteBuf {
return Rsa.decrypt(toBigInteger(), key).toByteBuf()
}
fun RSAPrivateCrtKeyParameters.toKeySpec(): KeySpec {
public fun RSAPrivateCrtKeyParameters.toKeySpec(): KeySpec {
return RSAPrivateCrtKeySpec(modulus, publicExponent, exponent, p, q, dp, dq, qInv)
}
object Rsa {
public object Rsa {
private const val PUBLIC_KEY = "PUBLIC KEY"
private const val PRIVATE_KEY = "PRIVATE KEY"
@ -66,14 +66,14 @@ object Rsa {
* The maximum output length of RSA encryption is the key size plus one, so
* the maximum key size supported by the client is 126 bytes - or 1008 bits.
*/
const val CLIENT_KEY_LENGTH = 1008
public const val CLIENT_KEY_LENGTH: Int = 1008
const val JAR_KEY_LENGTH = 2048
public const val JAR_KEY_LENGTH: Int = 2048
// 1 in 2^80
private const val CERTAINTY = 80
fun generateKeyPair(length: Int): Pair<RSAKeyParameters, RSAPrivateCrtKeyParameters> {
public fun generateKeyPair(length: Int): Pair<RSAKeyParameters, RSAPrivateCrtKeyParameters> {
val generator = RSAKeyPairGenerator()
generator.init(RSAKeyGenerationParameters(F4, secureRandom, length, CERTAINTY))
@ -81,7 +81,7 @@ object Rsa {
return Pair(keyPair.public as RSAKeyParameters, keyPair.private as RSAPrivateCrtKeyParameters)
}
fun encrypt(plaintext: BigInteger, key: RSAKeyParameters): BigInteger {
public fun encrypt(plaintext: BigInteger, key: RSAKeyParameters): BigInteger {
require(!key.isPrivate)
return plaintext.modPow(key.exponent, key.modulus)
}
@ -100,7 +100,7 @@ object Rsa {
}
}
fun decrypt(ciphertext: BigInteger, key: RSAKeyParameters): BigInteger {
public fun decrypt(ciphertext: BigInteger, key: RSAKeyParameters): BigInteger {
require(key.isPrivate)
if (key is RSAPrivateCrtKeyParameters) {
@ -137,7 +137,7 @@ object Rsa {
}
}
fun readPublicKey(path: Path): RSAKeyParameters {
public fun readPublicKey(path: Path): RSAKeyParameters {
val der = readSinglePemObject(path, PUBLIC_KEY)
val spki = SubjectPublicKeyInfo.getInstance(der)
@ -147,12 +147,12 @@ object Rsa {
return RSAKeyParameters(false, key.modulus, key.publicExponent)
}
fun writePublicKey(path: Path, key: RSAKeyParameters) {
public fun writePublicKey(path: Path, key: RSAKeyParameters) {
val spki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(key)
return writeSinglePemObject(path, PUBLIC_KEY, spki.encoded)
}
fun readPrivateKey(path: Path): RSAPrivateCrtKeyParameters {
public fun readPrivateKey(path: Path): RSAPrivateCrtKeyParameters {
val der = readSinglePemObject(path, PRIVATE_KEY)
val pki = PrivateKeyInfo.getInstance(der)
@ -171,7 +171,7 @@ object Rsa {
)
}
fun writePrivateKey(path: Path, key: RSAKeyParameters) {
public fun writePrivateKey(path: Path, key: RSAKeyParameters) {
val pki = PrivateKeyInfoFactory.createPrivateKeyInfo(key)
return writeSinglePemObject(path, PRIVATE_KEY, pki.encoded)
}

@ -5,7 +5,7 @@ import java.nio.file.Files
import java.nio.file.Paths
import javax.inject.Provider
class RsaKeyProvider : Provider<RSAPrivateCrtKeyParameters> {
public class RsaKeyProvider : Provider<RSAPrivateCrtKeyParameters> {
override fun get(): RSAPrivateCrtKeyParameters {
return if (Files.exists(PATH)) {
Rsa.readPrivateKey(PATH)

@ -4,5 +4,5 @@ import java.security.SecureRandom
private val threadLocal = ThreadLocal.withInitial { SecureRandom() }
val secureRandom: SecureRandom
public val secureRandom: SecureRandom
get() = threadLocal.get()

@ -1,6 +1,6 @@
package dev.openrs2.crypto
class Whirlpool {
public class Whirlpool {
private val bitLength = ByteArray(32)
private val buffer = ByteArray(64)
private var bufferBits = 0
@ -67,7 +67,7 @@ class Whirlpool {
}
}
fun NESSIEinit() {
public fun NESSIEinit() {
bitLength.fill(0)
bufferBits = 0
bufferPos = 0
@ -75,7 +75,7 @@ class Whirlpool {
hash.fill(0)
}
fun NESSIEadd(source: ByteArray, bits: Long) {
public fun NESSIEadd(source: ByteArray, bits: Long) {
var sourceBits = bits
var sourcePos = 0
val sourceGap = (8 - (sourceBits.toInt() and 7)) and 7
@ -138,7 +138,7 @@ class Whirlpool {
}
}
fun NESSIEfinalize(digest: ByteArray) {
public fun NESSIEfinalize(digest: ByteArray) {
buffer[bufferPos] = (buffer[bufferPos].toInt() or (0x80 ushr (bufferBits and 7))).toByte()
bufferPos++
@ -173,7 +173,7 @@ class Whirlpool {
}
}
companion object {
public companion object {
private const val DIGESTBITS = 512
private const val DIGESTBYTES = DIGESTBITS ushr 3
private const val R = 10
@ -248,7 +248,7 @@ class Whirlpool {
}
}
fun whirlpool(data: ByteArray, off: Int = 0, len: Int = data.size): ByteArray {
public fun whirlpool(data: ByteArray, off: Int = 0, len: Int = data.size): ByteArray {
val source: ByteArray
if (off <= 0) {
source = data

@ -7,20 +7,20 @@ private const val ROUNDS = 32
private const val BLOCK_SIZE = 8
private const val BLOCK_SIZE_MASK = BLOCK_SIZE - 1
class XteaKey(
public class XteaKey(
private val k0: Int,
private val k1: Int,
private val k2: Int,
private val k3: Int
) {
val isZero: Boolean
public val isZero: Boolean
get() = k0 == 0 && k1 == 0 && k2 == 0 && k3 == 0
fun toIntArray(): IntArray {
public fun toIntArray(): IntArray {
return intArrayOf(k0, k1, k2, k3)
}
fun toHex(): String {
public fun toHex(): String {
return Integer.toUnsignedString(k0, 16).padStart(8, '0') +
Integer.toUnsignedString(k1, 16).padStart(8, '0') +
Integer.toUnsignedString(k2, 16).padStart(8, '0') +
@ -31,16 +31,16 @@ class XteaKey(
return toHex()
}
companion object {
val ZERO = XteaKey(0, 0, 0, 0)
public companion object {
public val ZERO: XteaKey = XteaKey(0, 0, 0, 0)
fun fromIntArray(a: IntArray): XteaKey {
public fun fromIntArray(a: IntArray): XteaKey {
require(a.size == 4)
return XteaKey(a[0], a[1], a[2], a[3])
}
fun fromHex(s: String): XteaKey {
public fun fromHex(s: String): XteaKey {
require(s.length == 32)
val k0 = Integer.parseUnsignedInt(s, 0, 8, 16)
@ -53,7 +53,7 @@ class XteaKey(
}
}
fun ByteBuf.xteaEncrypt(index: Int, length: Int, key: XteaKey) {
public fun ByteBuf.xteaEncrypt(index: Int, length: Int, key: XteaKey) {
val k = key.toIntArray()
val end = index + (length and BLOCK_SIZE_MASK.inv())
@ -73,7 +73,7 @@ fun ByteBuf.xteaEncrypt(index: Int, length: Int, key: XteaKey) {
}
}
fun ByteBuf.xteaDecrypt(index: Int, length: Int, key: XteaKey) {
public fun ByteBuf.xteaDecrypt(index: Int, length: Int, key: XteaKey) {
val k = key.toIntArray()
val end = index + (length and BLOCK_SIZE_MASK.inv())

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save