fix(kotlin-metadata): upgrade to kotlin 2.2 metadata library (PR #2655)
* fix Metadata Bytes String reading and upgrade to kotlin 2.2 metadata library which is now finalized and has therefore renamed from kotlinx.metadata to kotlin.metadata * add test with sample java class --------- Co-authored-by: Skylot <118523+skylot@users.noreply.github.com>
This commit is contained in:
@@ -39,7 +39,7 @@ public class DecompilePassWrapper extends AbstractVisitor implements IPassWrappe
|
||||
try {
|
||||
return decompilePass.visit(cls);
|
||||
} catch (Throwable e) {
|
||||
LOG.error("Error in decompile pass: {}, class: {}", this, cls, e);
|
||||
cls.addError("Error in decompile pass: " + this, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class DecompilePassWrapper extends AbstractVisitor implements IPassWrappe
|
||||
try {
|
||||
decompilePass.visit(mth);
|
||||
} catch (Throwable e) {
|
||||
LOG.error("Error in decompile pass: {}, method: {}", this, mth, e);
|
||||
mth.addError("Error in decompile pass: " + this, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
@@ -744,4 +745,11 @@ public abstract class IntegrationTest extends TestUtils {
|
||||
assertThat(javaVariable).isNotNull();
|
||||
return javaVariable;
|
||||
}
|
||||
|
||||
public File getResourceFile(String filePath) {
|
||||
URL resource = getClass().getClassLoader().getResource(filePath);
|
||||
assertThat(resource).as("Resource not found: %s", filePath).isNotNull();
|
||||
String resPath = resource.getFile();
|
||||
return new File(resPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,11 @@ plugins {
|
||||
dependencies {
|
||||
api(project(":jadx-core"))
|
||||
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.9.0")
|
||||
implementation("org.jetbrains.kotlin:kotlin-metadata-jvm:2.2.20")
|
||||
|
||||
testImplementation(project.project(":jadx-core").sourceSets.getByName("test").output)
|
||||
testImplementation("org.apache.commons:commons-lang3:3.19.0")
|
||||
|
||||
testRuntimeOnly(project(":jadx-plugins:jadx-smali-input"))
|
||||
testRuntimeOnly(project(":jadx-plugins:jadx-java-input"))
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package jadx.plugins.kotlin.metadata.utils
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode
|
||||
import kotlinx.metadata.KmClass
|
||||
import kotlinx.metadata.isData
|
||||
import kotlinx.metadata.jvm.KotlinClassMetadata
|
||||
import kotlin.metadata.KmClass
|
||||
import kotlin.metadata.isData
|
||||
import kotlin.metadata.jvm.KotlinClassMetadata
|
||||
|
||||
// don't expose kotlinx.metadata.* types ?
|
||||
class KmClassWrapper private constructor(
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
package jadx.plugins.kotlin.metadata.utils
|
||||
|
||||
import kotlinx.metadata.KmFunction
|
||||
import kotlinx.metadata.KmProperty
|
||||
import kotlinx.metadata.jvm.fieldSignature
|
||||
import kotlinx.metadata.jvm.signature
|
||||
import kotlin.metadata.KmFunction
|
||||
import kotlin.metadata.KmProperty
|
||||
import kotlin.metadata.jvm.fieldSignature
|
||||
import kotlin.metadata.jvm.signature
|
||||
|
||||
inline val KmFunction.shortId: String? get() = signature?.toString()
|
||||
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ import jadx.api.plugins.input.data.annotations.EncodedValue
|
||||
import jadx.api.plugins.input.data.annotations.IAnnotation
|
||||
import jadx.core.dex.nodes.ClassNode
|
||||
import jadx.plugins.kotlin.metadata.model.KotlinMetadataConsts
|
||||
import kotlinx.metadata.jvm.KotlinClassMetadata
|
||||
import kotlinx.metadata.jvm.Metadata
|
||||
import kotlin.metadata.jvm.KotlinClassMetadata
|
||||
import kotlin.metadata.jvm.Metadata
|
||||
|
||||
fun ClassNode.getMetadata(): Metadata? {
|
||||
val annotation: IAnnotation? = getAnnotation(KotlinMetadataConsts.KOTLIN_METADATA_ANNOTATION)
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import jadx.plugins.kotlin.metadata.model.ClassAliasRename
|
||||
import jadx.plugins.kotlin.metadata.model.CompanionRename
|
||||
import jadx.plugins.kotlin.metadata.model.FieldRename
|
||||
import jadx.plugins.kotlin.metadata.model.MethodArgRename
|
||||
import kotlinx.metadata.KmClass
|
||||
import kotlin.metadata.KmClass
|
||||
|
||||
object KotlinMetadataUtils {
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package jadx.plugins.kotlin.metadata.tests
|
||||
|
||||
import jadx.tests.api.IntegrationTest
|
||||
import jadx.tests.api.utils.assertj.JadxAssertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class TestJavaParser : IntegrationTest() {
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
val sampleCls = getResourceFile("samples/MainKt.class")
|
||||
assertThat(getClassNodeFromFiles(listOf(sampleCls), "MainKt"))
|
||||
.code()
|
||||
.doesNotContain("Exception occurred when reading Kotlin metadata")
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user