Skip to content

Commit

Permalink
Do not export FernFlower library, instead provide the used functionality
Browse files Browse the repository at this point in the history
to read qualified class name from class data as function
  • Loading branch information
jpstotz committed Apr 29, 2023
1 parent 484e8d4 commit c7b5174
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
import java.util.List;

import org.apache.commons.lang3.time.StopWatch;
import org.jetbrains.java.decompiler.struct.StructClass;
import org.jetbrains.java.decompiler.struct.lazy.LazyLoader;
import org.sf.feeling.decompiler.JavaDecompilerPlugin;
import org.sf.feeling.decompiler.editor.IDecompiler;
import org.sf.feeling.decompiler.jd.JDCoreDecompilerPlugin;
import org.sf.feeling.decompiler.util.ClassUtil;
import org.sf.feeling.decompiler.util.FileUtil;
import org.sf.feeling.decompiler.util.UIUtil;

Expand Down Expand Up @@ -59,10 +58,8 @@ public void decompile(String root, String classPackage, String className) {
try {
if (classPackage.length() == 0) {
File classFile = new File(root, className);
StructClass structClass = new StructClass(Files.readAllBytes(classFile.toPath()), true,
new LazyLoader(null));
structClass.releaseResources();
classPackage = structClass.qualifiedName.replace("/" //$NON-NLS-1$
String qualifiedName = ClassUtil.getClassQualifiedName(Files.readAllBytes(classFile.toPath()));
classPackage = qualifiedName.replace("/" //$NON-NLS-1$
+ className.replaceAll("(?i)\\.class", ""), ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

Expand Down
4 changes: 2 additions & 2 deletions org.sf.feeling.decompiler/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="lib/fernflower-352.jar"/>
<classpathentry kind="lib" path="lib/fernflower-352.jar"/>
<classpathentry exported="true" kind="lib" path="lib/json.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jsoup.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.drgarbage.asm_5.0.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.drgarbage.asm.util_5.0.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.drgarbage.bytecodevisualizer.plugin_4.4.1.201408050542.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.drgarbage.core.plugin_4.4.1.201408050542.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-9.1.jar"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
5 changes: 0 additions & 5 deletions org.sf.feeling.decompiler/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ Bundle-Activator: org.sf.feeling.decompiler.JavaDecompilerPlugin
Bundle-SymbolicName: org.sf.feeling.decompiler;singleton:=true
Eclipse-ExtensibleAPI: true
Export-Package: com.eclipsesource.json,
org.jetbrains.java.decompiler.main,
org.jetbrains.java.decompiler.main.collectors,
org.jetbrains.java.decompiler.main.extern,
org.jetbrains.java.decompiler.struct,
org.jetbrains.java.decompiler.struct.lazy,
org.jsoup,
org.jsoup.helper,
org.jsoup.nodes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.io.InputStream;
import java.util.Collection;

import org.jetbrains.java.decompiler.struct.StructClass;
import org.jetbrains.java.decompiler.struct.lazy.LazyLoader;
import org.sf.feeling.decompiler.JavaDecompilerPlugin;
import org.sf.feeling.decompiler.editor.IDecompiler;
import org.sf.feeling.decompiler.editor.IDecompilerDescriptor;
Expand Down Expand Up @@ -85,8 +87,8 @@ public static int getLevel(InputStream is) {
return -1;
}

public static boolean isClassFile(byte[] bytes) {
try (DataInputStream data = new DataInputStream(new ByteArrayInputStream(bytes))) {
public static boolean isClassFile(byte[] classData) {
try (DataInputStream data = new DataInputStream(new ByteArrayInputStream(classData))) {
if (0xCAFEBABE != data.readInt()) {
return false;
}
Expand All @@ -99,6 +101,15 @@ public static boolean isClassFile(byte[] bytes) {
return false;
}

/**
* Uses FernFlower library to read the class and extract it's qualified name
*/
public static String getClassQualifiedName(byte[] classData) throws IOException {
StructClass structClass = new StructClass(classData, true, new LazyLoader(null));
structClass.releaseResources();
return structClass.qualifiedName;
}

public static IDecompiler getDefaultDecompiler(int level, boolean debug) {
Collection<IDecompilerDescriptor> descriptors = JavaDecompilerPlugin.getDefault().getDecompilerDescriptorMap()
.values();
Expand Down

0 comments on commit c7b5174

Please sign in to comment.