From 4e59840391d85b6007c482776257c104c298ce7a Mon Sep 17 00:00:00 2001 From: sschr15 Date: Sat, 31 Aug 2024 15:59:10 -0500 Subject: [PATCH] Use IDEA's ArrayUtil for byte check --- src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt b/src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt index 84bd0ce..f984424 100644 --- a/src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt +++ b/src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt @@ -14,6 +14,7 @@ import com.intellij.openapi.vfs.readBytes import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiClass import com.intellij.psi.search.GlobalSearchScope +import com.intellij.util.ArrayUtil import java.io.File import java.util.concurrent.CompletableFuture import java.util.concurrent.LinkedBlockingQueue @@ -250,8 +251,10 @@ class VineflowerInvoker(classLoader: ClassLoader) { private val getCurrentDecompContext = classLoader.loadClass("org.jetbrains.java.decompiler.main.DecompilerContext") .getMethod("getCurrentContext") + private val cafebabe = listOf(0xCA, 0xFE, 0xBA, 0xBE).map(Int::toByte).toByteArray() + fun getLanguage(bytes: ByteArray): String? { - if (bytes.take(4) != listOf(0xCA, 0xFE, 0xBA, 0xBE).map { it.toByte() }) { + if (ArrayUtil.startsWith(bytes, cafebabe)) { // Non-class file return null }