From 1c53d3b858c2917961f1d6eef004d1cc6bf08332 Mon Sep 17 00:00:00 2001 From: pmikova Date: Wed, 28 Nov 2018 14:51:45 +0100 Subject: [PATCH 1/5] Initial import (#1636019) --- .gitignore | 1 + java-runtime-decompiler | 86 ++++++++++++++++++++++++++++++++++++ java-runtime-decompiler.1 | 26 +++++++++++ java-runtime-decompiler.spec | 84 +++++++++++++++++++++++++++++++++++ jrd.desktop | 8 ++++ sources | 1 + 6 files changed, 206 insertions(+) create mode 100644 .gitignore create mode 100644 java-runtime-decompiler create mode 100644 java-runtime-decompiler.1 create mode 100644 java-runtime-decompiler.spec create mode 100644 jrd.desktop create mode 100644 sources diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e75df4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/java-runtime-decompiler-2.0.tar.gz diff --git a/java-runtime-decompiler b/java-runtime-decompiler new file mode 100644 index 0000000..f7da489 --- /dev/null +++ b/java-runtime-decompiler @@ -0,0 +1,86 @@ +#!/usr/bin/bash + +# java runtime decompiler launch script + +# JPackage Project +# Source functions library + +. /usr/share/java-utils/java-functions + +# identify directory tree +JRD=`basename $0` +CONF_HOME=$XDG_CONFIG_HOME + + +if [ "$CONF_HOME" = "" ] ; then + CONF_HOME=$HOME/.config/$JRD + +else + CONF_HOME=$CONF_HOME/$JRD + +fi + +LOG_DIR=$CONF_HOME/logs + +CONF_DIR=$CONF_HOME/conf + +# create directory tree +PLUGIN_HOME=$CONF_HOME/plugins + +mkdir -p $LOG_DIR + +mkdir -p $CONF_DIR + +mkdir -p $PLUGIN_HOME + +: ${MAIN_CLASS:=org.jrd.backend.data.Main} + +# set java and jvm arguments +export _prefer_jre=false +_set_java_home +set_jvm + +# all dependencies must be on classpath +set_classpath java-runtime-decompiler rsyntaxtextarea byteman google-gson +CLASSPATH=$CLASSPATH:${JAVA_HOME}/lib/tools.jar + +# set path to agent automatically +AGENT="/usr/share/java/java-runtime-decompiler/decompiler-agent.jar" +CONFIG_FILE=$CONF_DIR/config.cfg +AGENT_PREFIX="AGENT_PATH===" +AGENT_STRING=$AGENT_PREFIX$AGENT + +# copy json wrappers information to home so the users can edit +CP_FILES="$(ls /etc/$JRD/plugins/*.json)" +for cpfile in $CP_FILES; do + FILE_NAME="$(basename -- $cpfile)" + if [ ! -e "$PLUGIN_HOME/$FILE_NAME" ] + then + cp $cpfile $PLUGIN_HOME + else + echo "Configuration files were not copied for $FILE_NAME - the existing configuration would be overwritten." + fi +done + +# create config file and add agent default path +touch $CONFIG_FILE + +if [ -e $AGENT ] +then + if grep -Fxq $AGENT_STRING $CONFIG_FILE + then + echo "Default agent path is already set in $CONFIG_FILE. Skipping agent path setting." + elif grep -rq $AGENT_PREFIX $CONFIG_FILE + then + RESULT_OF_GREP="$(grep -rq $AGENT_PREFIX $CONFIG_FILE)" + echo "Agent path is already set in $CONFIG_FILE as ${RESULT_OF_GREP}. Skipping agent path setting." + else + echo $AGENT_STRING >> $CONFIG_FILE + + fi +else + echo "Agent was not found and agent path was not set correctly. This has to be done manually in the decompiler GUI, or set AGENT_PATH===path_to_agent_jar in the configuration file: $CONFIG_FILE" +fi + +run "$@" + diff --git a/java-runtime-decompiler.1 b/java-runtime-decompiler.1 new file mode 100644 index 0000000..5aa7e3c --- /dev/null +++ b/java-runtime-decompiler.1 @@ -0,0 +1,26 @@ +.TH java-runtime-decompiler 1 "05 September 2018" "version 2.0" +.SH NAME +java-runtime-decompiler \- launch java-runtime decompiler GUI +.SH SYNOPSIS +java-runtime-decompiler +.SH DESCRIPTION +It is used for extraction of bytecode from running JVM and decompilation of the bytecode with an external decompiler. Paths to the decompiler need to be specified in .json configuration file located in /etc/java-runtime-decompiler +.SH OPTIONS +.IP -verbose +Print out all exceptions and debugging strings in stdout. +.IP -help +Print out help and exits. +.IP -listjvms +List available local JVMs. +.IP -listplugins +List currently configured plugins with their status. +.IP "-listclasses pid-xor-url" +List loaded classes from JVM with given PID/URL. +.IP "-bytes pid class-name" +Print on stdout binary form of given class loaded in JVM with given PID/URL. +.IP "-base64bytes pid-xor-url class-name" +Print on stdout binary form encoded in base64 of given class loaded in JVM with given PID/URL. +.IP "-decompile pid-xor-url class-name config-file" +Print on stdout decompiled class, needs PID/URL of JVM, class name and name/file with decompiler configuration, can use javap disassembler. To pass arguments to the disassembler, add them to javap without spaces (e.g. javap-v). +.SH AUTHOR +Petra Alice Mikova (petra.alice.mikova@gmail.com) diff --git a/java-runtime-decompiler.spec b/java-runtime-decompiler.spec new file mode 100644 index 0000000..b96cacd --- /dev/null +++ b/java-runtime-decompiler.spec @@ -0,0 +1,84 @@ +Summary: Application for extraction and decompilation of JVM byte code +Name: java-runtime-decompiler +Version: 2.0 +Release: 2%{?dist} +License: GPLv3 +URL: https://github.com/pmikova/java-runtime-decompiler +Source0: https://github.com/pmikova/%{name}/archive/%{name}-%{version}.tar.gz +Source1: java-runtime-decompiler +Source2: java-runtime-decompiler.1 +Source3: jrd.desktop +BuildArch: noarch +BuildRequires: maven-local +BuildRequires: byteman +BuildRequires: rsyntaxtextarea +# depends on devel, not runtime (needs tools.jar) +BuildRequires: java-devel = 1:1.8.0 +BuildRequires: google-gson +BuildRequires: desktop-file-utils +Requires: java-devel = 1:1.8.0 + +%description +This application can access JVM memory at runtime, +extract byte code from the JVM and decompile it. +%package javadoc +Summary: Javadoc for %{name} +Requires: %{name} = %{version}-%{release} + +%description javadoc +This package contains the API documentation for %{name}. + +%prep +%setup -q -n %{name}-%{name}-%{version} + +%build +pushd runtime-decompiler +%pom_remove_dep com.sun:tools +%pom_add_dep com.sun:tools +%pom_remove_plugin :maven-jar-plugin +popd +%mvn_build + +%install +%mvn_install +install -d -m 755 $RPM_BUILD_ROOT%{_mandir}/man1/ +install -m 644 %{SOURCE2} $RPM_BUILD_ROOT%{_mandir}/man1/ + +install -d -m 755 $RPM_BUILD_ROOT%{_bindir} +install -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/ +install -d -m 755 $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/ +cp -r %{_builddir}/%{name}-%{name}-%{version}/runtime-decompiler/src/plugins/ $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/ + +install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/applications +desktop-file-install --vendor="fedora" \ +--dir=${RPM_BUILD_ROOT}%{_datadir}/applications %{SOURCE3} + +%files -f .mfiles +%attr(755, root, -) %{_bindir}/java-runtime-decompiler +%{_mandir}/man1/java-runtime-decompiler.1* + +# wrappers for decompilers +%dir %{_sysconfdir}/%{name} +%dir %{_sysconfdir}/%{name}/plugins +%config %{_sysconfdir}/%{name}/plugins/FernflowerDecompilerWrapper.java +%config(noreplace) %{_sysconfdir}/%{name}/plugins/FernflowerDecompilerWrapper.json +%config %{_sysconfdir}/%{name}/plugins/ProcyonDecompilerWrapper.java +%config(noreplace) %{_sysconfdir}/%{name}/plugins/ProcyonDecompilerWrapper.json +%license LICENSE + +%dir %{_datadir}/applications +%{_datadir}/applications/fedora-jrd.desktop + +%files javadoc -f .mfiles-javadoc +%license LICENSE + +%changelog +* Wed Nov 28 2018 Petra Mikova - 2.0-2 +- fixed changelog + +* Mon Nov 19 2018 Petra Mikova - 2.0-1 +- fixed issues listed in review (rhbz#1636019) +- added installation of desktop file + +* Wed Jun 06 2018 Petra Mikova - 1.1-1 +- initial commit diff --git a/jrd.desktop b/jrd.desktop new file mode 100644 index 0000000..eb2d468 --- /dev/null +++ b/jrd.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Application +Categories=Development;Profiling;Java; +Version=1.0 +Name=Java Runtime Decompiler +Exec=java-runtime-decompiler +Terminal=false diff --git a/sources b/sources new file mode 100644 index 0000000..bbb57cd --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (java-runtime-decompiler-2.0.tar.gz) = dc7c1e9c785539ef464d18d039403b677476e34ba54cc3717552c59a2e405b550c86b40607cc77efafdfdd0b3ce1f6813a7532915bbfabffc0e46023bb85ed95 From 2852c8b3d073f05c0b11568dfc4d0953b60c4bdb Mon Sep 17 00:00:00 2001 From: Jiri Vanek Date: Thu, 10 Jan 2019 17:42:57 +0100 Subject: [PATCH 2/5] added depndence of fernflower decompiler, added and applied Patch1, systemFernflower.patch to enable system fernflower --- java-runtime-decompiler.spec | 9 ++++++++- systemFernflower.patch | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 systemFernflower.patch diff --git a/java-runtime-decompiler.spec b/java-runtime-decompiler.spec index b96cacd..2a8d3c0 100644 --- a/java-runtime-decompiler.spec +++ b/java-runtime-decompiler.spec @@ -1,13 +1,14 @@ Summary: Application for extraction and decompilation of JVM byte code Name: java-runtime-decompiler Version: 2.0 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv3 URL: https://github.com/pmikova/java-runtime-decompiler Source0: https://github.com/pmikova/%{name}/archive/%{name}-%{version}.tar.gz Source1: java-runtime-decompiler Source2: java-runtime-decompiler.1 Source3: jrd.desktop +Patch1: systemFernflower.patch BuildArch: noarch BuildRequires: maven-local BuildRequires: byteman @@ -17,6 +18,7 @@ BuildRequires: java-devel = 1:1.8.0 BuildRequires: google-gson BuildRequires: desktop-file-utils Requires: java-devel = 1:1.8.0 +Recommends: fernflower %description This application can access JVM memory at runtime, @@ -30,6 +32,7 @@ This package contains the API documentation for %{name}. %prep %setup -q -n %{name}-%{name}-%{version} +%patch1 %build pushd runtime-decompiler @@ -73,6 +76,10 @@ desktop-file-install --vendor="fedora" \ %license LICENSE %changelog +* Thu Jan 10 2019 Jiri Vanek - 2.0-3 +- added depndence of fernflower decompiler +- added and applied Patch1, systemFernflower.patch to enable system fernflower + * Wed Nov 28 2018 Petra Mikova - 2.0-2 - fixed changelog diff --git a/systemFernflower.patch b/systemFernflower.patch new file mode 100644 index 0000000..ab707cd --- /dev/null +++ b/systemFernflower.patch @@ -0,0 +1,13 @@ +--- runtime-decompiler/src/plugins/FernflowerDecompilerWrapper.json ++++ runtime-decompiler/src/plugins/FernflowerDecompilerWrapper.json +@@ -2,7 +2,7 @@ + "Name": "Fernflower", + "WrapperURL": "file:///etc/java-runtime-decompiler/plugins/FernflowerDecompilerWrapper.java", + "DependencyURL": [ +- "file://${HOME}/IdeaProjects/fernflower/build/libs/fernflower.jar" ++ "file:///usr/share/java/fernflower.jar" + ], + "DecompilerDownloadURL": "https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler/engine" +-} +\ No newline at end of file ++} From daa3f3d1726d4396e0b1bc8b34f8ff5021b8c58f Mon Sep 17 00:00:00 2001 From: Jiri Date: Wed, 16 Jan 2019 12:28:51 +0100 Subject: [PATCH 3/5] Added binding for future procyon --- java-runtime-decompiler.spec | 9 ++++++++- systemProcyon.patch | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 systemProcyon.patch diff --git a/java-runtime-decompiler.spec b/java-runtime-decompiler.spec index 2a8d3c0..68e4c6a 100644 --- a/java-runtime-decompiler.spec +++ b/java-runtime-decompiler.spec @@ -1,7 +1,7 @@ Summary: Application for extraction and decompilation of JVM byte code Name: java-runtime-decompiler Version: 2.0 -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv3 URL: https://github.com/pmikova/java-runtime-decompiler Source0: https://github.com/pmikova/%{name}/archive/%{name}-%{version}.tar.gz @@ -9,6 +9,7 @@ Source1: java-runtime-decompiler Source2: java-runtime-decompiler.1 Source3: jrd.desktop Patch1: systemFernflower.patch +Patch2: systemProcyon.patch BuildArch: noarch BuildRequires: maven-local BuildRequires: byteman @@ -19,6 +20,7 @@ BuildRequires: google-gson BuildRequires: desktop-file-utils Requires: java-devel = 1:1.8.0 Recommends: fernflower +Recommends: procyon-decompiler %description This application can access JVM memory at runtime, @@ -33,6 +35,7 @@ This package contains the API documentation for %{name}. %prep %setup -q -n %{name}-%{name}-%{version} %patch1 +%patch2 %build pushd runtime-decompiler @@ -76,6 +79,10 @@ desktop-file-install --vendor="fedora" \ %license LICENSE %changelog +* Thu Jan 17 2019 Jiri Vanek - 2.0-4 +- added depndence of procyon decompiler (currenlty under review +- added and applied Patch2, systemProcyon.patch to enable system procyon out of thebox + * Thu Jan 10 2019 Jiri Vanek - 2.0-3 - added depndence of fernflower decompiler - added and applied Patch1, systemFernflower.patch to enable system fernflower diff --git a/systemProcyon.patch b/systemProcyon.patch new file mode 100644 index 0000000..91e2c7b --- /dev/null +++ b/systemProcyon.patch @@ -0,0 +1,15 @@ +--- runtime-decompiler/src/plugins/ProcyonDecompilerWrapper.json 2018-11-12 15:25:47.000000000 +0100 ++++ runtime-decompiler/src/plugins/ProcyonDecompilerWrapper.json 2019-01-16 12:13:37.317778036 +0100 +@@ -2,7 +2,9 @@ + "Name": "Procyon", + "WrapperURL": "file:///etc/java-runtime-decompiler/plugins/ProcyonDecompilerWrapper.java", + "DependencyURL": [ +- "file:///usr/share/java/procyon-decompiler.jar" ++ "/usr/share/java/procyon/procyon-core.jar", ++ "/usr/share/java/procyon/procyon-compilertools.jar", ++ "/usr/share/java/procyon/procyon-decompiler.jar" + ], + "DecompilerDownloadURL": "https://bitbucket.org/mstrobel/procyon/downloads/" +-} +\ No newline at end of file ++} From f36bb9c63754457d4853ef38f41787398e924d26 Mon Sep 17 00:00:00 2001 From: Jiri Date: Wed, 16 Jan 2019 12:33:40 +0100 Subject: [PATCH 4/5] - added and applied Patch3, includeLambdas.patch to at least list lamdas untill fixed in upstream --- includeLambdas.patch | 15 +++++++++++++++ java-runtime-decompiler.spec | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 includeLambdas.patch diff --git a/includeLambdas.patch b/includeLambdas.patch new file mode 100644 index 0000000..ca5c21c --- /dev/null +++ b/includeLambdas.patch @@ -0,0 +1,15 @@ +--- runtime-decompiler/src/main/java/org/jrd/backend/core/DecompilerRequestReceiver.java ++++ runtime-decompiler/src/main/java/org/jrd/backend/core/DecompilerRequestReceiver.java.nw +@@ -214,9 +214,9 @@ + list.removeAll(Arrays.asList("", null)); + List list1 = new ArrayList<>(); + for (String s : list) { +- if (!(s.contains("Lambda") | s.startsWith("["))){ ++// if (!(s.contains("Lambda") | s.startsWith("["))){ + list1.add(s); +- } ++// } + } + java.util.Collections.sort(list1); + return list1.toArray(new String[]{}); + diff --git a/java-runtime-decompiler.spec b/java-runtime-decompiler.spec index 68e4c6a..634d4ca 100644 --- a/java-runtime-decompiler.spec +++ b/java-runtime-decompiler.spec @@ -10,6 +10,7 @@ Source2: java-runtime-decompiler.1 Source3: jrd.desktop Patch1: systemFernflower.patch Patch2: systemProcyon.patch +Patch3: includeLambdas.patch BuildArch: noarch BuildRequires: maven-local BuildRequires: byteman @@ -36,6 +37,7 @@ This package contains the API documentation for %{name}. %setup -q -n %{name}-%{name}-%{version} %patch1 %patch2 +%patch3 %build pushd runtime-decompiler @@ -82,6 +84,7 @@ desktop-file-install --vendor="fedora" \ * Thu Jan 17 2019 Jiri Vanek - 2.0-4 - added depndence of procyon decompiler (currenlty under review - added and applied Patch2, systemProcyon.patch to enable system procyon out of thebox +- added and applied Patch3, includeLambdas.patch to at least list lamdas untill fixed in upstream * Thu Jan 10 2019 Jiri Vanek - 2.0-3 - added depndence of fernflower decompiler From 6fc774f9b73df6a54a0657665d17362cb30aeb04 Mon Sep 17 00:00:00 2001 From: Jiri Vanek Date: Wed, 16 Jan 2019 18:08:15 +0100 Subject: [PATCH 5/5] Improved the lmbda patch to sort [ classes to bottom --- includeLambdas.patch | 53 ++++++++++++++++++++++++++++++++---- java-runtime-decompiler.spec | 5 +++- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/includeLambdas.patch b/includeLambdas.patch index ca5c21c..2fc9fee 100644 --- a/includeLambdas.patch +++ b/includeLambdas.patch @@ -1,15 +1,58 @@ +commit fd66fd3a37cc899b11d97a13e0e23319d86f39c3 +Author: Jiri Vanek +Date: Wed Jan 16 18:03:43 2019 +0100 + + Showing Lambdas again, but sorting them to the end. + +diff --git a/runtime-decompiler/src/main/java/org/jrd/backend/core/DecompilerRequestReceiver.java b/runtime-decompiler/src/main/java/org/jrd/backend/core/DecompilerRequestReceiver.java +index b7fddea..603c26d 100644 --- runtime-decompiler/src/main/java/org/jrd/backend/core/DecompilerRequestReceiver.java -+++ runtime-decompiler/src/main/java/org/jrd/backend/core/DecompilerRequestReceiver.java.nw -@@ -214,9 +214,9 @@ ++++ runtime-decompiler/src/main/java/org/jrd/backend/core/DecompilerRequestReceiver.java +@@ -8,6 +8,7 @@ import org.jrd.backend.data.VmManager; + + import java.util.ArrayList; + import java.util.Arrays; ++import java.util.Comparator; + import java.util.List; + + /** +@@ -146,6 +147,29 @@ public class DecompilerRequestReceiver { + return ERROR_RESPONSE; + } + String[] arrayOfClasses = parseClasses(classes); ++ if (arrayOfClasses != null){ ++ Arrays.sort(arrayOfClasses, new Comparator() { ++ @Override ++ public int compare(String o1, String o2) { ++ if (o1 == null && o2 == null) { ++ return 0; ++ } ++ if (o1 == null && o2 != null) { ++ return 1; ++ } ++ if (o1 != null && o2 == null) { ++ return -1; ++ } ++ if (o1.startsWith("[") && !o2.startsWith("[")) { ++ return 1; ++ } ++ if (!o1.startsWith("[") && o2.startsWith("[")) { ++ return -1; ++ } ++ return o1.compareTo(o2); ++ } ++ }); ++ } + VmDecompilerStatus status = new VmDecompilerStatus(); + status.setHostname(hostname); + status.setListenPort(actualListenPort); +@@ -214,9 +238,7 @@ public class DecompilerRequestReceiver { list.removeAll(Arrays.asList("", null)); List list1 = new ArrayList<>(); for (String s : list) { - if (!(s.contains("Lambda") | s.startsWith("["))){ -+// if (!(s.contains("Lambda") | s.startsWith("["))){ list1.add(s); - } -+// } } java.util.Collections.sort(list1); return list1.toArray(new String[]{}); - diff --git a/java-runtime-decompiler.spec b/java-runtime-decompiler.spec index 634d4ca..ea6ed59 100644 --- a/java-runtime-decompiler.spec +++ b/java-runtime-decompiler.spec @@ -1,7 +1,7 @@ Summary: Application for extraction and decompilation of JVM byte code Name: java-runtime-decompiler Version: 2.0 -Release: 4%{?dist} +Release: 5%{?dist} License: GPLv3 URL: https://github.com/pmikova/java-runtime-decompiler Source0: https://github.com/pmikova/%{name}/archive/%{name}-%{version}.tar.gz @@ -81,6 +81,9 @@ desktop-file-install --vendor="fedora" \ %license LICENSE %changelog +* Thu Jan 17 2019 Jiri Vanek - 2.0-5 +- improved Patch3, includeLambdas.patch to sort the lamdas t the bottom + * Thu Jan 17 2019 Jiri Vanek - 2.0-4 - added depndence of procyon decompiler (currenlty under review - added and applied Patch2, systemProcyon.patch to enable system procyon out of thebox