Skip to content

Commit

Permalink
Use IDEA's ArrayUtil for byte check
Browse files Browse the repository at this point in the history
  • Loading branch information
sschr15 committed Aug 31, 2024
1 parent e99cf6c commit 4e59840
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 4e59840

Please sign in to comment.