Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed Mar 8, 2017
0 parents commit 1d476de
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea
/out
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# java-decompiler-plugin-cfr
基于[CFR](http://www.benf.org/other/cfr/)后端的,用于[IntelliJ IDEA](https://www.jetbrains.com/idea/)的反编译插件。

## 已知的问题
与文本编辑器的Parser系统似乎有些不兼容,右下角会有报错提示,但是可以不用理会。

## 为什么做这个
自带的反编译插件后端有非常多的错误,这个虽然也不完美,但更加强力,可以用来对付原本无法反编译的字节码。
14 changes: 14 additions & 0 deletions java-decompiler-plugin-cfr.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PLUGIN_MODULE" version="4">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="cfr_0_120" level="project" />
</component>
</module>
Binary file added lib/cfr_0_120.jar
Binary file not shown.
21 changes: 21 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<idea-plugin>
<id>com.i5mc.idea.decompiler.cfr</id>
<name>CFR Decompiler</name>
<version>1.0</version>
<vendor email="[email protected]" url="http://www.i5mc.com">i5mc</vendor>

<description>
The plugin decompile .class with CFR.
http://www.benf.org/other/cfr/
</description>

<change-notes>
- 2017-03-08 INIT
</change-notes>

<idea-version since-build="145.0"/>

<extensions defaultExtensionNs="com.intellij">
<psi.classFileDecompiler implementation="com.i5mc.idea.decompiler.MyDecompiler"/>
</extensions>
</idea-plugin>
48 changes: 48 additions & 0 deletions src/com/i5mc/idea/decompiler/Impl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.i5mc.idea.decompiler;

import org.benf.cfr.reader.PluginRunner;

/**
* Created on 17-3-8.
*/
public interface Impl {

String decompile(String path);

static String fuck(String path) {
PluginRunner r = new PluginRunner();
r.addJarPath(path);
return r.getDecompilationFor(path);
}

static String clazz(String path) {
int i = path.lastIndexOf("!/");// filesystem path can contain ! but java can not
if (i == -1) throw new IllegalArgumentException();
PluginRunner r = new PluginRunner();
String head = path.substring(0, i);
r.addJarPath(head);
String tail = path.substring(i + 2, path.length() - 6);
return r.getDecompilationFor(tail);
}

enum Protocol {

FILE(Impl::fuck),
JAR(Impl::clazz);

private final Impl impl;

Protocol(Impl impl) {
this.impl = impl;
}
}

static String decompile(String protocol, String path) {
try {
return Protocol.valueOf(protocol.toUpperCase()).impl.decompile(path);
} catch (Exception ignore) {
}
return "Plz feed back! (" + protocol + "|" + path + ")";
}

}
20 changes: 20 additions & 0 deletions src/com/i5mc/idea/decompiler/MyDecompiler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.i5mc.idea.decompiler

import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiJavaModule
import com.intellij.psi.PsiPackage
import com.intellij.psi.compiled.ClassFileDecompilers
import com.intellij.psi.impl.compiled.ClsFileImpl

class MyDecompiler : ClassFileDecompilers.Light() {

override fun accepts(input: VirtualFile): Boolean = true

override fun getText(input: VirtualFile): CharSequence {
if (PsiPackage.PACKAGE_INFO_CLS_FILE == input.name || PsiJavaModule.MODULE_INFO_CLS_FILE == input.name) {
return ClsFileImpl.decompile(input)
}
return Impl.decompile(input.fileSystem.protocol, input.path)
}

}

0 comments on commit 1d476de

Please sign in to comment.