Skip to content
Browse files

Initial Revision .

  • Loading branch information...
1 parent 1f8c28f commit bcf1babdbd9e137213fa501903019b995ab109a0 Karthik Kumar committed
Showing with 9,746 additions and 0 deletions.
  1. +15 −0 AUTHORS
  2. +48 −0 CHANGES
  3. +11 −0 INSTALL
  4. +161 −0 build.xml
  5. +41 −0 src/net/sf/jrevpro/CustomLoggerFactory.java
  6. +102 −0 src/net/sf/jrevpro/JReverseProContext.java
  7. +67 −0 src/net/sf/jrevpro/JavaDecompileVersionContext.java
  8. +53 −0 src/net/sf/jrevpro/VersionChecker.java
  9. +84 −0 src/net/sf/jrevpro/ast/block/Block.java
  10. +39 −0 src/net/sf/jrevpro/ast/block/ConditionalBlock.java
  11. +35 −0 src/net/sf/jrevpro/ast/block/MethodBlock.java
  12. +54 −0 src/net/sf/jrevpro/ast/block/Statement.java
  13. +42 −0 src/net/sf/jrevpro/ast/evaluator/AConstNullEvaluator.java
  14. +67 −0 src/net/sf/jrevpro/ast/evaluator/AbstractInstructionEvaluator.java
  15. +152 −0 src/net/sf/jrevpro/ast/evaluator/ArithmeticEvaluator.java
  16. +78 −0 src/net/sf/jrevpro/ast/evaluator/ArrayIndexLoadEvaluator.java
  17. +55 −0 src/net/sf/jrevpro/ast/evaluator/ArrayIndexStoreEvaluator.java
  18. +101 −0 src/net/sf/jrevpro/ast/evaluator/CastEvaluator.java
  19. +74 −0 src/net/sf/jrevpro/ast/evaluator/CompareEvaluator.java
  20. +96 −0 src/net/sf/jrevpro/ast/evaluator/ConditionBiOperatorEvaluator.java
  21. +80 −0 src/net/sf/jrevpro/ast/evaluator/ConditionNullEvaluator.java
  22. +101 −0 src/net/sf/jrevpro/ast/evaluator/ConditionUniOperatorEvaluator.java
  23. +53 −0 src/net/sf/jrevpro/ast/evaluator/DConstEvaluator.java
  24. +59 −0 src/net/sf/jrevpro/ast/evaluator/DLoadEvaluator.java
  25. +173 −0 src/net/sf/jrevpro/ast/evaluator/DupEvaluator.java
  26. +47 −0 src/net/sf/jrevpro/ast/evaluator/EvaluatorContext.java
  27. +127 −0 src/net/sf/jrevpro/ast/evaluator/EvaluatorStack.java
  28. +59 −0 src/net/sf/jrevpro/ast/evaluator/FConstEvaluator.java
  29. +60 −0 src/net/sf/jrevpro/ast/evaluator/FLoadEvaluator.java
  30. +61 −0 src/net/sf/jrevpro/ast/evaluator/GotoEvaluator.java
  31. +43 −0 src/net/sf/jrevpro/ast/evaluator/IConstEvaluator.java
  32. +78 −0 src/net/sf/jrevpro/ast/evaluator/IINCEvaluator.java
  33. +84 −0 src/net/sf/jrevpro/ast/evaluator/ILoadEvaluator.java
  34. +51 −0 src/net/sf/jrevpro/ast/evaluator/IPushEvaluator.java
  35. +98 −0 src/net/sf/jrevpro/ast/evaluator/IStoreEvaluator.java
  36. +184 −0 src/net/sf/jrevpro/ast/evaluator/InvokeEvaluator.java
  37. +76 −0 src/net/sf/jrevpro/ast/evaluator/JSREvaluator.java
  38. +41 −0 src/net/sf/jrevpro/ast/evaluator/LConstEvaluator.java
  39. +75 −0 src/net/sf/jrevpro/ast/evaluator/LLoadEvaluator.java
  40. +60 −0 src/net/sf/jrevpro/ast/evaluator/LdcEvaluator.java
  41. +112 −0 src/net/sf/jrevpro/ast/evaluator/LogicalOpEvaluator.java
  42. +95 −0 src/net/sf/jrevpro/ast/evaluator/LongFloatDoubleStoreEvaluator.java
  43. +63 −0 src/net/sf/jrevpro/ast/evaluator/MonitorEvaluator.java
  44. +81 −0 src/net/sf/jrevpro/ast/evaluator/NegateEvaluator.java
  45. +142 −0 src/net/sf/jrevpro/ast/evaluator/NewArrayEvaluator.java
  46. +101 −0 src/net/sf/jrevpro/ast/evaluator/NonStaticFieldReferenceEvaluator.java
  47. +40 −0 src/net/sf/jrevpro/ast/evaluator/NullEvaluator.java
  48. +97 −0 src/net/sf/jrevpro/ast/evaluator/PopEvaluator.java
  49. +60 −0 src/net/sf/jrevpro/ast/evaluator/ReferenceLoadEvaluator.java
  50. +68 −0 src/net/sf/jrevpro/ast/evaluator/ReferenceStoreEvaluator.java
  51. +116 −0 src/net/sf/jrevpro/ast/evaluator/ReferenceTypeInfoEvaluator.java
  52. +87 −0 src/net/sf/jrevpro/ast/evaluator/ReturnEvaluator.java
  53. +187 −0 src/net/sf/jrevpro/ast/evaluator/RuntimeFrame.java
  54. +87 −0 src/net/sf/jrevpro/ast/evaluator/StaticFieldReferenceEvaluator.java
  55. +64 −0 src/net/sf/jrevpro/ast/evaluator/SwitchEvaluator.java
  56. +47 −0 src/net/sf/jrevpro/ast/evaluator/UndefinedEvaluator.java
  57. +81 −0 src/net/sf/jrevpro/ast/expression/ArrayInstantiationExpression.java
  58. +46 −0 src/net/sf/jrevpro/ast/expression/ArrayLengthExpression.java
  59. +50 −0 src/net/sf/jrevpro/ast/expression/ArrayMemberReferenceExpression.java
  60. +55 −0 src/net/sf/jrevpro/ast/expression/Assignment.java
  61. +99 −0 src/net/sf/jrevpro/ast/expression/BinaryOpExpression.java
  62. +106 −0 src/net/sf/jrevpro/ast/expression/ConditionExpression.java
  63. +83 −0 src/net/sf/jrevpro/ast/expression/Constant.java
  64. +103 −0 src/net/sf/jrevpro/ast/expression/Expression.java
  65. +143 −0 src/net/sf/jrevpro/ast/expression/ExpressionPrecedenceConstants.java
  66. +75 −0 src/net/sf/jrevpro/ast/expression/FieldAccessExpression.java
  67. +46 −0 src/net/sf/jrevpro/ast/expression/InstanceOfExpression.java
  68. +123 −0 src/net/sf/jrevpro/ast/expression/MethodAccessExpression.java
  69. +52 −0 src/net/sf/jrevpro/ast/expression/ObjectInstantiationExpression.java
  70. +52 −0 src/net/sf/jrevpro/ast/expression/ReturnExpression.java
  71. +46 −0 src/net/sf/jrevpro/ast/expression/ThrowExpression.java
  72. +145 −0 src/net/sf/jrevpro/ast/expression/UnaryOpExpression.java
  73. +99 −0 src/net/sf/jrevpro/ast/expression/Variable.java
  74. +56 −0 src/net/sf/jrevpro/ast/intermediate/AbstractLineOfCode.java
  75. +44 −0 src/net/sf/jrevpro/ast/intermediate/CompleteLine.java
  76. +53 −0 src/net/sf/jrevpro/ast/intermediate/ConditionalLine.java
  77. +18 −0 src/net/sf/jrevpro/ast/intermediate/GotoLine.java
  78. +47 −0 src/net/sf/jrevpro/ast/intermediate/JSRLine.java
  79. +43 −0 src/net/sf/jrevpro/ast/intermediate/LineOfCodeList.java
  80. +47 −0 src/net/sf/jrevpro/ast/intermediate/RetLine.java
  81. +49 −0 src/net/sf/jrevpro/ast/intermediate/SwitchLine.java
  82. +148 −0 src/net/sf/jrevpro/cmd/CommandLineInterface.java
  83. +95 −0 src/net/sf/jrevpro/cmd/CommandMain.java
  84. +100 −0 src/net/sf/jrevpro/decompile/BlockInferrer.java
  85. +52 −0 src/net/sf/jrevpro/decompile/DecompilationContext.java
  86. +75 −0 src/net/sf/jrevpro/decompile/Decompiler.java
  87. +67 −0 src/net/sf/jrevpro/decompile/simulate/BranchComparator.java
  88. +114 −0 src/net/sf/jrevpro/decompile/simulate/BranchConstants.java
  89. +69 −0 src/net/sf/jrevpro/decompile/simulate/BranchEntry.java
  90. +472 −0 src/net/sf/jrevpro/decompile/simulate/BranchTable.java
  91. +180 −0 src/net/sf/jrevpro/decompile/simulate/CaseEntry.java
  92. +336 −0 src/net/sf/jrevpro/decompile/simulate/SwitchTable.java
  93. +218 −0 src/net/sf/jrevpro/gui/ClassEditPanel.java
  94. +55 −0 src/net/sf/jrevpro/gui/ConfirmCloseDialog.java
  95. +99 −0 src/net/sf/jrevpro/gui/CustomFileChooser.java
  96. +131 −0 src/net/sf/jrevpro/gui/CustomListPanel.java
  97. +66 −0 src/net/sf/jrevpro/gui/DlgAbout.java
  98. +42 −0 src/net/sf/jrevpro/gui/DlgClose.java
  99. +213 −0 src/net/sf/jrevpro/gui/DlgConstantPool.java
  100. +99 −0 src/net/sf/jrevpro/gui/DlgError.java
  101. +159 −0 src/net/sf/jrevpro/gui/DlgFont.java
  102. +42 −0 src/net/sf/jrevpro/gui/EditorJavaDocument.java
  103. +503 −0 src/net/sf/jrevpro/gui/GUIMain.java
  104. +84 −0 src/net/sf/jrevpro/gui/GuiConstants.java
  105. +134 −0 src/net/sf/jrevpro/gui/MainMenu.java
Sorry, we could not display the entire diff because it was too big.
View
15 AUTHORS
@@ -0,0 +1,15 @@
+Current Active Developers:
+---------------------------
+
+Karthik Kumar, akkumar@users.sourceforge.net.
+
+Previous Developers:
+--------------------
+Karthikeyan C, bercolax@users.sourceforge.net
+
+Anand Krishnan , anandk@users.sourceforge.net.
+Paul Norp, norpaul@users.sourceforge.net
+
+Jiri Malak , malakj@users.sourceforge.net.
+Norman Richards , orb@jump.net.
+Rina Woo , rongwoo@yahoo.com.
View
48 CHANGES
@@ -0,0 +1,48 @@
+ JReversePro
+ Java Decompiler / Disassembler
+ http://jreversepro.blogspot.com
+
+
+version 1.4.0 ( Oct 19 2002 )
+ bug regarding transient field members fixed.
+ lookup switch handling modified appropriately.
+ invokestatic instruction handling bug fixed.
+ Introduction of method blocks in API thereby moving towards provision of maximum manipulation of decompiled code through code.
+ Fixed a bug related to space in throw new Exception .
+
+version 1.3.3: ( May 07 2002 ).
+
+version 1.3.2: ( Feb 5 2002 ).
+ Fixed a bug to identify an empty-catch statement.
+ Better command-line interface now.
+
+
+version 1.3.1: ( Jan 26 2002 ).
+ Some code enhancements to speed up the decompilation especially avoiding the costly breakup for switch and normal statements.
+ Bug regarding the size of long and double variables in LocalSymbolTable fixed.
+
+ Statements of the type 'Object obj = null' get decompiled correctly.
+
+ Now viewing of constantpool contents is better.
+
+
+version 1.3: ( Jan 2002 ).
+ Now statements containing finally .. and synchronized are decompiled properly.
+ Also ternary expressions now decompile correctly.
+
+ TODO: Live variable analysis probably need to be more rigorous ...,
+ Currently variables are declared but decompiled code uses variables use
+ them out-of-scope.
+ This project has hopefully entered into its pre-alpha stage..
+
+
+version 1.2: ( Jun 2001 ).
+ Fixed more bugs.
+
+version 1.1: ( Mar 2001 ).
+ Bugs fixed in the reverse engineering engine.
+
+
+version 1.0: ( Dec 2000 ).
+ Started working on a Java decompiler.
+ This has just got over the design stage!!
View
11 INSTALL
@@ -0,0 +1,11 @@
+ JReversePro 1.4.0
+ Java Decompiler / Disassembler
+ http://jrevpro.sourceforge.net
+ Oct 19 2002
+
+To Install:
+==========
+ Set the environment variable JREVERSE_HOME to point to this directory,
+to which you have extracted the tarball.
+ Add JREVERSE_HOME/bin to the PATH environment variable.
+
View
161 build.xml
@@ -0,0 +1,161 @@
+<?xml version="1.0"?>
+<project name="JReversePro" default="compile" basedir=".">
+ <!-- ==================================================== -->
+ <!-- JReversePro - Java Decompiling suite -->
+ <!-- Decompiling Engine build file -->
+ <!-- Author - Karthik Kumar -->
+ <!-- ==================================================== -->
+
+ <target name="default" depends="usage, makejar">
+ <echo message="Using option makejar as the default option" />
+ </target>
+
+ <target name="usage">
+ <echo message="compile Compile all source files"/>
+ <echo message="makejar Make Library Jar File"/>
+ <echo message="dist Create Distribution"/>
+ <echo message="docs Create Java Docs"/>
+ <echo message="clean Clean binaries"/>
+ </target>
+
+ <target name="init">
+ <property name="version" value="1.4.0" />
+
+ <property name="build.compiler" value="modern"/>
+ <property name="dirs.base" value="${basedir}"/>
+ <property name="classpath" value="${java.class.path}" />
+ <property name="srcdir" value="${dirs.base}/src"/>
+ <property name="classdir" value="${dirs.base}/classes"/>
+ <property name="libdir" value="${dirs.base}/lib"/>
+ <property name="bindir" value="${dirs.base}/bin"/>
+ <property name="docdir" value="${dirs.base}/docs"/>
+ <property name="distdir" value="${dirs.base}/dist"/>
+ <property name="bindistdir" value="${distdir}/bin" />
+ <property name="srcdistdir" value="${distdir}/src" />
+ <property name="testdir" value="${dirs.base}/test"/>
+ <property name="testtarget" value="${dirs.base}/test/output"/>
+ <property name="apidir" value="api"/>
+ <property name="jarfile" value="jreversepro.jar"/>
+ <property name="doctitle" value="JReversePro ${version} API"/>
+ <property name="windowtitle" value="JReversePro ${version} API"/>
+ <property name="bottom" value="Submit Feedback to akkumar@users.sourceforge.net"/>
+
+ <chmod file="${bindir}/*" perm="ugo+rx-w"/>
+
+ </target>
+
+ <!-- Compiler Target -->
+ <target name="compile" depends="clean,init"
+ description="Compile all the Java source files">
+ <mkdir dir="${classdir}"/>
+ <javac srcdir="${srcdir}" destdir="${classdir}"/>
+ </target>
+
+ <!-- Create the Jar File -->
+ <target name="makejar" depends="init,compile" description="Make the Library Jar file">
+ <jar jarfile="${libdir}/${jarfile}" basedir="${classdir}" manifest="${srcdir}/manifest.txt"/>
+ </target>
+
+ <!-- Create Java Documentation -->
+ <target name="docs" depends="init, makejar" description="Create the Javadocs file">
+ <mkdir dir="${docdir}/${apidir}"/>
+ <javadoc packagenames=" jreversepro, jreversepro.common,jreversepro.parser,jreversepro.reflect, jreversepro.reflect.method, jreversepro.revengine, jreversepro.runtime"
+ sourcepath="${srcdir}" classpath="${classpath}" destdir="${docdir}/${apidir}" use="true" windowtitle="${windowtitle}" doctitle="${doctitle}" bottom="${bottom}"/>
+ </target>
+
+ <!-- dist -->
+ <target name="dist" depends="cleanall, docs">
+ <property name="jrevroot" value="jreversepro-${version}" />
+ <property name="infofiles" value="COPYING CHANGES README INSTALL AUTHORS"/>
+
+ <mkdir dir="${distdir}" />
+
+ <mkdir dir="${bindistdir}" />
+ <mkdir dir="${bindistdir}/${jrevroot}" />
+ <copy todir="${bindistdir}/${jrevroot}">
+ <fileset dir="." includes="${infofiles} bin/** lib/** docs/** "
+ excludes="CVS/** lib/checkstyle-all-2.3.jar" />
+ </copy>
+ <chmod file="${bindistdir}/${jrevroot}/bin/*" perm="ugo+rx-w"/>
+ <tar tarfile="${distdir}/bin.tar">
+ <tarfileset dir="${bindistdir}" mode="755">
+ <include name="${jrevroot}/bin/**" />
+ </tarfileset>
+
+ <tarfileset dir="${bindistdir}">
+ <exclude name="${jrevroot}/bin/**"/>
+ <include name="${jrevroot}/**"/>
+ </tarfileset>
+ </tar>
+ <gzip zipfile="${distdir}/jreversepro-${version}-bin.tgz"
+ src="${distdir}/bin.tar" />
+
+ <mkdir dir="${srcdistdir}" />
+ <mkdir dir="${srcdistdir}/${jrevroot}" />
+ <copy todir="${srcdistdir}/${jrevroot}">
+ <fileset dir="." includes="build.xml ${infofiles} bin/** src/**"
+ excludes="CVS/**" />
+ </copy>
+ <chmod file="${srcdistdir}/${jrevroot}/bin/*" perm="ugo+rx-w"/>
+ <tar tarfile="${distdir}/src.tar">
+ <tarfileset dir="${srcdistdir}" mode="755">
+ <include name="${jrevroot}/bin/**" />
+ </tarfileset>
+
+ <tarfileset dir="${srcdistdir}">
+ <exclude name="${jrevroot}/bin/**"/>
+ <include name="${jrevroot}/**"/>
+ </tarfileset>
+ </tar>
+ <gzip zipfile="${distdir}/jreversepro-${version}-src.tgz"
+ src="${distdir}/src.tar" />
+
+ </target>
+
+ <!-- uploads to sourceforge -->
+ <target name="sourceforge" depends="dist">
+ <exec dir="${distdir}" executable="ncftpput">
+ <arg line="-V upload.sourceforge.net /incoming jreversepro-${version}-src.tgz" />
+ </exec>
+
+ <exec dir="${distdir}" executable="ncftpput">
+ <arg line="-V upload.sourceforge.net /incoming jreversepro-${version}-bin.tgz" />
+ </exec>
+ </target>
+
+
+ <!-- Clean up -->
+ <target name="clean" depends="init" description="Clean up binary Files">
+ <delete dir="${classdir}"/>
+ <delete>
+ <fileset dir="${basedir}" includes="**/*~" defaultexcludes="no" />
+ </delete>
+ </target>
+
+
+ <!-- Clean up -->
+ <target name="cleanall" depends="init, clean" description="Clean up All Files">
+ <delete dir="${docdir}/${apidir}"/>
+ <delete dir="${distdir}"/>
+ </target>
+
+ <!-- targets for testing -->
+ <target name="compiletests" depends="init">
+ <javac srcdir="testclasses" destdir="testclasses"/>
+ </target>
+
+ <target name="runtests" depends="compiletests">
+ <java classpath="lib/jreversepro.jar" classname="jreversepro.tester.TestMain">
+ <arg value="${dirs.base}" />
+ </java>
+ </target>
+
+ <target name="cleantests">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${basedir}" includes="testrun*/*" />
+ <fileset dir="${basedir}" includes="testrun*" />
+ <fileset dir="testclasses" includes="**/*.class" />
+ </delete>
+ </target>
+
+</project>
View
41 src/net/sf/jrevpro/CustomLoggerFactory.java
@@ -0,0 +1,41 @@
+/**
+ * @(#) CustomLoggerFactory.java
+ *
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+package net.sf.jrevpro;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.SimpleFormatter;
+import java.util.logging.StreamHandler;
+
+/**
+ * @author akkumar
+ *
+ */
+public class CustomLoggerFactory {
+
+ public static Logger createLogger() {
+ Logger logger = Logger.getLogger("JReversePro");
+ SimpleFormatter formatter = new SimpleFormatter();
+ StreamHandler handler = new StreamHandler(System.out, formatter);
+ logger.addHandler(handler);
+ logger.setLevel(Level.FINER);
+ return logger;
+ }
+
+}
View
102 src/net/sf/jrevpro/JReverseProContext.java
@@ -0,0 +1,102 @@
+/**
+ * * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+
+ */
+package net.sf.jrevpro;
+
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Date;
+import java.util.logging.Logger;
+
+import net.sf.jrevpro.output.AbstractOutputter;
+import net.sf.jrevpro.output.DecompilerOutputter;
+import net.sf.jrevpro.output.DisassemblerOutputter;
+import net.sf.jrevpro.parser.ClassFileParser;
+import net.sf.jrevpro.parser.ClassFileParserFactory;
+import net.sf.jrevpro.parser.ClassParserException;
+import net.sf.jrevpro.reflect.ClassInfo;
+
+/**
+ *
+ * @author akkumar Karthik Kumar
+ *
+ */
+public class JReverseProContext {
+
+ public enum OutputType {
+ NONE, DISASSEMBLER, DECOMPILER, VIEW_CONSTANTPOOL,
+ }
+
+ /**
+ *
+ * @param pathToClass
+ * Path to the class for which resource needs to be loaded
+ * @return
+ * @throws FileNotFoundException
+ * @throws ClassParserException
+ */
+ public ClassInfo loadResource(String pathToClass)
+ throws FileNotFoundException, IOException, ClassParserException {
+ FileInputStream fis = new FileInputStream(pathToClass);
+ DataInputStream dis = new DataInputStream(fis);
+
+ ClassFileParser cfp = ClassFileParserFactory.getClassFileParser(dis);
+ ClassInfo info = cfp.parseInputStream(dis, pathToClass);
+ fis.close();
+ return info;
+ }
+
+ public String print(OutputType outputType, ClassInfo info) {
+ AbstractOutputter printer = null;
+ switch (outputType) {
+ case DISASSEMBLER:
+ printer = new DisassemblerOutputter();
+ break;
+ case DECOMPILER:
+ printer = new DecompilerOutputter();
+ break;
+ }
+ return printer.output(info);
+ }
+
+ public static void checkJREVersion() {
+ if (!VersionChecker.versionCheck()) {
+ System.exit(1);
+ }
+ System.out.println(GPL_INFO);
+ }
+
+ /**
+ * Version of the software.
+ */
+ public static final String VERSION = "1.5.0";
+
+ /**
+ * GPL Information.
+ */
+ public static String GPL_INFO = "// JReversePro v " + VERSION + " "
+ + (new Date()) + "\n// http://jrevpro.sourceforge.net"
+ + "\n// Copyright (C)2008 Karthik Kumar."
+ + "\n// JReversePro comes with ABSOLUTELY NO WARRANTY;"
+ + "\n// This is free software, and you are welcome to redistribute"
+ + "\n// it under certain conditions;See the File 'COPYING' for "
+ + "more details.\n";
+
+ private Logger logger = CustomLoggerFactory.createLogger();
+}
View
67 src/net/sf/jrevpro/JavaDecompileVersionContext.java
@@ -0,0 +1,67 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro;
+
+/**
+ *
+ * @author karthikeyanc
+ *
+ */
+public final class JavaDecompileVersionContext {
+
+ private JavaDecompileVersionContext(){}
+
+ private static final JavaDecompileVersionContext ctx=new JavaDecompileVersionContext();
+
+ public enum JAVA_VERSION { JAVA_1_4, JAVA_5, JAVA_6 }
+
+
+ public static final void setJavaVersionToDecompile(String version){
+ parseJavaVersionToDecompile(version);
+ }
+
+ public static JAVA_VERSION getJavaVersionToDecompile(){
+ return ctx.getJavaVersion();
+ }
+
+
+
+ private static final void parseJavaVersionToDecompile(String userInput){
+ //TODO impleemntation is to be provided
+ //till then setting it as java 1.4
+
+ ctx.setJavaVersion(JAVA_VERSION.JAVA_1_4);
+ }
+
+
+ private JAVA_VERSION javaVersion=null;
+
+
+ private JAVA_VERSION getJavaVersion() {
+ return javaVersion;
+ }
+
+
+ private void setJavaVersion(JAVA_VERSION javaVersion) {
+ this.javaVersion = javaVersion;
+ }
+
+
+
+
+}
View
53 src/net/sf/jrevpro/VersionChecker.java
@@ -0,0 +1,53 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro;
+
+public class VersionChecker {
+
+ /**
+ * Checks for the version compatibility between the system JRE and the JRE
+ * for which the application is written for.
+ *
+ * @return true , if System JRE is >= {@value #DEFAULT_VERSION}<br>
+ * false , otherwise.
+ */
+ public static boolean versionCheck() {
+ String version = System.getProperty("java.version");
+ for (int i = 0; i <= 5; i += 2) {
+ int versionVal = (int) (version.charAt(i));
+ int workingVal = (int) (DEFAULT_VERSION.charAt(i));
+ if (versionVal > workingVal) {
+ return true;
+ } else if (versionVal < workingVal) {
+ System.err.println("This Software is designed to run under "
+ + DEFAULT_VERSION);
+ System.err.println("Please upgrade your JRE"
+ + " from http://java.sun.com/j2se"
+ + " for your operating system");
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Working Version Could be compromised
+ */
+ static final String DEFAULT_VERSION = "1.5.0";
+
+}
View
84 src/net/sf/jrevpro/ast/block/Block.java
@@ -0,0 +1,84 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.block;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import net.sf.jrevpro.jls.emitter.BlockEmitter;
+import net.sf.jrevpro.jls.emitter.BlockEmitterFactory;
+
+public abstract class Block {
+
+ public void addChildBlock(Block block) {
+ children.add(block);
+ }
+
+ public void addChildBlocks(Collection<Block> _blocks) {
+ if (_blocks != null) {
+ children.addAll(_blocks);
+ }
+ }
+
+ public List<Block> getChildren() {
+ return children;
+ }
+
+ public boolean hasChildren() {
+ return children.size() > 0;
+ }
+
+ public BlockEmitter getEmitter() {
+
+ BlockEmitter emitter = null;
+ try {
+ emitter = BlockEmitterFactory.getBlockEmitter(this.getClass());
+ } catch (Exception e) {
+ // TODO Exception handling
+ e.printStackTrace();
+ }
+ return emitter;
+ }
+
+ public void setParent(Block _parent) {
+ parent = _parent;
+ }
+
+ public Block getParent() {
+ return parent;
+ }
+
+ public int endOfBlock() {
+ int sz = children.size();
+ if (sz == 0) {
+ throw new IllegalStateException("Something gone wrong");
+ }
+ return children.get(sz).endOfBlock();
+ }
+
+ protected Block(Block _parent) {
+ children = new ArrayList<Block>();
+ parent = _parent;
+ }
+
+ protected List<Block> children;
+
+ protected Block parent;
+
+}
View
39 src/net/sf/jrevpro/ast/block/ConditionalBlock.java
@@ -0,0 +1,39 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.block;
+
+import net.sf.jrevpro.ast.expression.ConditionExpression;
+
+public class ConditionalBlock extends Block {
+
+ public enum ConditionalType {
+ CONDITION_IF, CONDITION_ELSE_IF, CONDITION_RETURN
+ };
+
+ public ConditionalBlock(Block _parent, ConditionExpression _expr,
+ ConditionalType _type) {
+ super(_parent);
+ expr = _expr;
+ type = _type;
+ }
+
+ private ConditionExpression expr;
+
+ private ConditionalType type;
+
+}
View
35 src/net/sf/jrevpro/ast/block/MethodBlock.java
@@ -0,0 +1,35 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.block;
+
+public class MethodBlock extends Block {
+
+ public MethodBlock(int lengthOfByteArray) {
+ // There is no parent for this - because it is the main block
+ super(null);
+ this.lengthOfByteArray=lengthOfByteArray;
+ }
+
+ @Override
+ public int endOfBlock() {
+ return lengthOfByteArray;
+ }
+
+ private int lengthOfByteArray;
+
+}
View
54 src/net/sf/jrevpro/ast/block/Statement.java
@@ -0,0 +1,54 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.block;
+
+import net.sf.jrevpro.ast.expression.Expression;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+/**
+ * Represents the abstraction of a statement
+ *
+ * @author akkumar
+ *
+ */
+public class Statement extends Block {
+
+ /**
+ *
+ * @param _expr
+ * Expression contained within a given statement.
+ */
+ public Statement(Block _parent, Instruction _instruction, Expression _expr) {
+ super(_parent);
+ expr = _expr;
+ instruction = _instruction;
+ }
+
+ @Override
+ public int endOfBlock() {
+ return instruction.getNextIndex();
+ }
+
+ public Expression getExpression() {
+ return expr;
+ }
+
+ private Expression expr;
+ private Instruction instruction;
+
+}
View
42 src/net/sf/jrevpro/ast/evaluator/AConstNullEvaluator.java
@@ -0,0 +1,42 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.Constant;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+public class AConstNullEvaluator extends AbstractInstructionEvaluator {
+
+ public AConstNullEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ @Override
+ void evaluate(Instruction ins) {
+ evalStack.push(Constant.NULL);
+
+ }
+
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_ACONST_NULL);
+ }
+
+}
View
67 src/net/sf/jrevpro/ast/evaluator/AbstractInstructionEvaluator.java
@@ -0,0 +1,67 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Logger;
+
+import net.sf.jrevpro.CustomLoggerFactory;
+import net.sf.jrevpro.ast.expression.ConditionExpression;
+import net.sf.jrevpro.ast.intermediate.ConditionalLine;
+import net.sf.jrevpro.ast.intermediate.LineOfCodeList;
+import net.sf.jrevpro.jls.JLSConstants;
+import net.sf.jrevpro.jvm.JVMConstants;
+import net.sf.jrevpro.jvm.Opcodes;
+import net.sf.jrevpro.reflect.ConstantPool;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+import net.sf.jrevpro.reflect.variabletable.VariableTable;
+
+public abstract class AbstractInstructionEvaluator implements JVMConstants,
+ JLSConstants, Opcodes {
+
+ public AbstractInstructionEvaluator(EvaluatorContext context) {
+ pool = context.pool;
+ varTable = context.varTable;
+ evalStack = context.opStack;
+ statements = context.statements;
+
+ }
+
+ abstract List<Integer> getProcessingOpcodes();
+
+ abstract void evaluate(Instruction ins);
+
+ protected List<Integer> numbersAsList(Integer ... numbers) {
+ return Arrays.asList(numbers);
+ }
+
+ protected void addConditional(Instruction ins, ConditionExpression expr) {
+ statements.append(new ConditionalLine(ins, expr));
+ }
+
+ protected ConstantPool pool;
+ protected VariableTable varTable;
+ protected String methodReturnType;
+ protected LineOfCodeList statements;
+ protected EvaluatorStack evalStack;
+
+ protected static final Logger logger = CustomLoggerFactory.createLogger();
+
+}
View
152 src/net/sf/jrevpro/ast/evaluator/ArithmeticEvaluator.java
@@ -0,0 +1,152 @@
+/**
+ * @(#) ArithmeticEvaluator.java
+ *
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.BinaryOpExpression;
+import net.sf.jrevpro.ast.expression.BinaryOpExpression.BinaryOperator;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+/**
+ * @author akkumar
+ *
+ */
+public class ArithmeticEvaluator extends AbstractInstructionEvaluator {
+
+ /**
+ * @param context
+ */
+ public ArithmeticEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#evaluate(net.sf.jrevpro.reflect.instruction.Instruction)
+ */
+ @Override
+ void evaluate(Instruction ins) {
+ switch (ins.opcode) {
+ // +
+ case OPCODE_IADD:
+ BinaryOpExpression.evaluateBinary(evalStack, BinaryOperator.PLUS,
+ JVM_TYPE_INT);
+ break;
+ case OPCODE_LADD:
+ BinaryOpExpression.evaluateBinary(evalStack, BinaryOperator.PLUS,
+ JVM_TYPE_LONG);
+ break;
+ case OPCODE_FADD:
+ BinaryOpExpression.evaluateBinary(evalStack, BinaryOperator.PLUS,
+ JVM_TYPE_FLOAT);
+ break;
+ case OPCODE_DADD:
+ BinaryOpExpression.evaluateBinary(evalStack, BinaryOperator.PLUS,
+ JVM_TYPE_DOUBLE);
+ break;
+ // -
+ case OPCODE_ISUB:
+ BinaryOpExpression.evaluateBinary(evalStack, BinaryOperator.MINUS,
+ JVM_TYPE_INT);
+ break;
+ case OPCODE_LSUB:
+ BinaryOpExpression.evaluateBinary(evalStack, BinaryOperator.MINUS,
+ JVM_TYPE_LONG);
+ break;
+ case OPCODE_FSUB:
+ BinaryOpExpression.evaluateBinary(evalStack, BinaryOperator.MINUS,
+ JVM_TYPE_FLOAT);
+ break;
+ case OPCODE_DSUB:
+ BinaryOpExpression.evaluateBinary(evalStack, BinaryOperator.MINUS,
+ JVM_TYPE_DOUBLE);
+ break;
+ // *
+ case OPCODE_IMUL:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.MULTIPLY, JVM_TYPE_INT);
+ break;
+ case OPCODE_LMUL:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.MULTIPLY, JVM_TYPE_LONG);
+ break;
+ case OPCODE_FMUL:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.MULTIPLY, JVM_TYPE_FLOAT);
+ break;
+ case OPCODE_DMUL:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.MULTIPLY, JVM_TYPE_DOUBLE);
+ break;
+ // /
+ case OPCODE_IDIV:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.DIVIDE, JVM_TYPE_INT);
+ break;
+ case OPCODE_LDIV:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.DIVIDE, JVM_TYPE_LONG);
+ break;
+ case OPCODE_FDIV:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.DIVIDE, JVM_TYPE_FLOAT);
+ break;
+ case OPCODE_DDIV:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.DIVIDE, JVM_TYPE_DOUBLE);
+ break;
+ // %
+ case OPCODE_IREM:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.MODULO, JVM_TYPE_INT);
+ break;
+ case OPCODE_LREM:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.MODULO, JVM_TYPE_LONG);
+ break;
+ case OPCODE_FREM:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.MODULO, JVM_TYPE_FLOAT);
+ break;
+ case OPCODE_DREM:
+ BinaryOpExpression.evaluateBinary(evalStack,
+ BinaryOperator.MODULO, JVM_TYPE_DOUBLE);
+ break;
+
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#getProcessingOpcodes()
+ */
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_IADD, OPCODE_LADD, OPCODE_FADD,
+ OPCODE_DADD, OPCODE_ISUB, OPCODE_LSUB, OPCODE_FSUB,
+ OPCODE_DSUB, OPCODE_IMUL, OPCODE_LMUL, OPCODE_FMUL,
+ OPCODE_DMUL, OPCODE_IDIV, OPCODE_LDIV, OPCODE_FDIV,
+ OPCODE_DDIV, OPCODE_IREM, OPCODE_LREM, OPCODE_FREM, OPCODE_DREM);
+ }
+
+}
View
78 src/net/sf/jrevpro/ast/evaluator/ArrayIndexLoadEvaluator.java
@@ -0,0 +1,78 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.ArrayMemberReferenceExpression;
+import net.sf.jrevpro.ast.expression.Expression;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+public class ArrayIndexLoadEvaluator extends AbstractInstructionEvaluator {
+
+ public ArrayIndexLoadEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ @Override
+ void evaluate(Instruction ins) {
+ Expression subscript = evalStack.pop();
+ Expression arrayObject = evalStack.pop();
+
+ char type = JVM_TYPE_UNDEFINED;
+ switch (ins.opcode) {
+ case OPCODE_IALOAD:
+ type = JVM_TYPE_INT;
+ break;
+ case OPCODE_LALOAD:
+ type = JVM_TYPE_LONG;
+ break;
+ case OPCODE_FALOAD:
+ type = JVM_TYPE_FLOAT;
+ break;
+ case OPCODE_DALOAD:
+ type = JVM_TYPE_DOUBLE;
+ break;
+ case OPCODE_AALOAD:
+ type = JVM_TYPE_REFERENCE;
+ break;
+ case OPCODE_BALOAD:
+ type = JVM_TYPE_BOOLEAN;
+ break;
+ case OPCODE_CALOAD:
+ type = JVM_TYPE_CHAR;
+ break;
+ case OPCODE_SALOAD:
+ type = JVM_TYPE_SHORT;
+ break;
+ }
+ ArrayMemberReferenceExpression expr = new ArrayMemberReferenceExpression(subscript,
+ arrayObject, type);
+
+ evalStack.push(expr);
+
+ }
+
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_IALOAD, OPCODE_LALOAD, OPCODE_FALOAD,
+ OPCODE_DALOAD, OPCODE_AALOAD, OPCODE_BALOAD, OPCODE_CALOAD,
+ OPCODE_SALOAD);
+ }
+
+}
View
55 src/net/sf/jrevpro/ast/evaluator/ArrayIndexStoreEvaluator.java
@@ -0,0 +1,55 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.ArrayMemberReferenceExpression;
+import net.sf.jrevpro.ast.expression.Assignment;
+import net.sf.jrevpro.ast.expression.Expression;
+import net.sf.jrevpro.ast.intermediate.CompleteLine;
+import net.sf.jrevpro.jvm.TypeInferrer;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+public class ArrayIndexStoreEvaluator extends AbstractInstructionEvaluator {
+
+ public ArrayIndexStoreEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ @Override
+ void evaluate(Instruction ins) {
+ Expression value = evalStack.pop();
+ Expression subscript = evalStack.pop();
+ Expression arrayObject = evalStack.pop();
+
+ ArrayMemberReferenceExpression arr = new ArrayMemberReferenceExpression(
+ arrayObject, subscript, TypeInferrer
+ .getArrayMemberType(arrayObject.getType()));
+
+ statements.append(new CompleteLine(ins, new Assignment(arr, value)));
+ }
+
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_IASTORE, OPCODE_LASTORE, OPCODE_FASTORE,
+ OPCODE_DASTORE, OPCODE_AASTORE, OPCODE_BASTORE, OPCODE_CASTORE,
+ OPCODE_SASTORE);
+ }
+
+}
View
101 src/net/sf/jrevpro/ast/evaluator/CastEvaluator.java
@@ -0,0 +1,101 @@
+/**
+ * @(#) CastEvaluator.java
+ *
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.reflect.instruction.Instruction;
+import net.sf.jrevpro.ast.expression.UnaryOpExpression;
+import net.sf.jrevpro.ast.expression.UnaryOpExpression.UnaryOperator;
+/**
+ * @author akkumar
+ *
+ */
+public class CastEvaluator extends AbstractInstructionEvaluator {
+
+ /**
+ * @param context
+ */
+ public CastEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#evaluate(net.sf.jrevpro.reflect.instruction.Instruction)
+ */
+ @Override
+ void evaluate(Instruction ins) {
+ switch (ins.opcode) {
+ case OPCODE_I2L:
+ case OPCODE_F2L:
+ case OPCODE_D2L:
+ UnaryOpExpression.evaluateCasting(evalStack,
+ UnaryOperator.CAST_LONG);
+ break;
+ case OPCODE_I2F:
+ case OPCODE_L2F:
+ case OPCODE_D2F:
+ UnaryOpExpression.evaluateCasting(evalStack,
+ UnaryOperator.CAST_FLOAT);
+ break;
+ case OPCODE_I2D:
+ case OPCODE_L2D:
+ case OPCODE_F2D:
+ UnaryOpExpression.evaluateCasting(evalStack,
+ UnaryOperator.CAST_DOUBLE);
+ break;
+ case OPCODE_L2I:
+ case OPCODE_F2I:
+ case OPCODE_D2I:
+ UnaryOpExpression
+ .evaluateCasting(evalStack, UnaryOperator.CAST_INT);
+ break;
+ case OPCODE_I2B:
+ UnaryOpExpression.evaluateCasting(evalStack,
+ UnaryOperator.CAST_BYTE);
+ break;
+ case OPCODE_I2C:
+ UnaryOpExpression.evaluateCasting(evalStack,
+ UnaryOperator.CAST_CHAR);
+ break;
+ case OPCODE_I2S:
+ UnaryOpExpression.evaluateCasting(evalStack,
+ UnaryOperator.CAST_SHORT);
+ break;
+
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#getProcessingOpcodes()
+ */
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_I2L, OPCODE_F2L, OPCODE_D2L, // long
+ OPCODE_I2F, OPCODE_L2F, OPCODE_D2F, // float
+ OPCODE_I2D, OPCODE_L2D, OPCODE_F2D, // double
+ OPCODE_L2I, OPCODE_F2I, OPCODE_D2I, // int
+ OPCODE_I2B, OPCODE_I2C, OPCODE_I2S // integer to other types
+ );
+ }
+}
View
74 src/net/sf/jrevpro/ast/evaluator/CompareEvaluator.java
@@ -0,0 +1,74 @@
+/**
+ * @(#) CompareEvaluator.java
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+
+ **/
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.ConditionExpression;
+import net.sf.jrevpro.ast.expression.Constant;
+import net.sf.jrevpro.ast.expression.Expression;
+import net.sf.jrevpro.ast.expression.ConditionExpression.RelationalOperator;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+/**
+ * @author akkumar
+ *
+ */
+public class CompareEvaluator extends AbstractInstructionEvaluator {
+
+ /**
+ * @param context
+ */
+ public CompareEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#evaluate
+ * (net.sf.jrevpro.reflect.instruction.Instruction)
+ */
+ @Override
+ void evaluate(Instruction ins) {
+ Expression rhs = evalStack.pop();
+ Expression lhs = evalStack.pop();
+
+ evalStack.conditionExpression = null; // Fix memory leaks
+ evalStack.conditionExpression = new ConditionExpression(lhs, rhs,
+ RelationalOperator.EQ);
+
+ evalStack.push(Constant.VALUE_1);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#
+ * getProcessingOpcodes()
+ */
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_LCMP, OPCODE_FCMPL, OPCODE_FCMPG,
+ OPCODE_DCMPL, OPCODE_DCMPG);
+
+ }
+
+}
View
96 src/net/sf/jrevpro/ast/evaluator/ConditionBiOperatorEvaluator.java
@@ -0,0 +1,96 @@
+/**
+ * @(#) ConditionBiOperatorEvaluator.java
+ *
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.ConditionExpression;
+import net.sf.jrevpro.ast.expression.Expression;
+import net.sf.jrevpro.ast.expression.ConditionExpression.RelationalOperator;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+/**
+ * @author akkumar
+ *
+ */
+public class ConditionBiOperatorEvaluator extends AbstractInstructionEvaluator {
+
+ /**
+ * @param context
+ */
+ public ConditionBiOperatorEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#evaluate
+ * (net.sf.jrevpro.reflect.instruction.Instruction)
+ */
+ @Override
+ void evaluate(Instruction ins) {
+ evalStack.conditionExpression = null;
+
+ Expression rhs = evalStack.pop();
+ Expression lhs = evalStack.pop();
+
+ RelationalOperator op = RelationalOperator.EQ;
+ switch (ins.opcode) {
+ case OPCODE_IF_ICMPEQ:
+ case OPCODE_IF_ACMPEQ:
+ op = RelationalOperator.EQ;
+ break;
+ case OPCODE_IF_ACMPNE:
+ case OPCODE_IF_ICMPNE:
+ op = RelationalOperator.NE;
+ break;
+ case OPCODE_IF_ICMPLT:
+ op = RelationalOperator.LT;
+ break;
+ case OPCODE_IF_ICMPGE:
+ op = RelationalOperator.GE;
+ break;
+ case OPCODE_IF_ICMPGT:
+ op = RelationalOperator.GT;
+ break;
+ case OPCODE_IF_ICMPLE:
+ op = RelationalOperator.LE;
+ break;
+ }
+ evalStack.conditionExpression = new ConditionExpression(lhs, rhs, op);
+
+ addConditional(ins, evalStack.conditionExpression);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#
+ * getProcessingOpcodes()
+ */
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_IF_ICMPEQ, OPCODE_IF_ACMPEQ, // ==
+ OPCODE_IF_ICMPNE, OPCODE_IF_ACMPNE, // !=
+ OPCODE_IF_ICMPLT, OPCODE_IF_ICMPLE, // <=
+ OPCODE_IF_ICMPGE, OPCODE_IF_ICMPGT); // >=
+ }
+}
View
80 src/net/sf/jrevpro/ast/evaluator/ConditionNullEvaluator.java
@@ -0,0 +1,80 @@
+/**
+ * @(#) ConditionNullEvaluator.java
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+
+ **/
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.ConditionExpression;
+import net.sf.jrevpro.ast.expression.Constant;
+import net.sf.jrevpro.ast.expression.Expression;
+import net.sf.jrevpro.ast.expression.ConditionExpression.RelationalOperator;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+/**
+ * @author akkumar
+ *
+ */
+public class ConditionNullEvaluator extends AbstractInstructionEvaluator {
+
+ /**
+ * @param context
+ */
+ public ConditionNullEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#evaluate
+ * (net.sf.jrevpro.reflect.instruction.Instruction)
+ */
+ @Override
+ void evaluate(Instruction ins) {
+ Expression lhs = evalStack.pop();
+
+ RelationalOperator op = RelationalOperator.EQ;
+
+ switch (ins.opcode) {
+ case OPCODE_IFNULL:
+ op = RelationalOperator.EQ;
+ break;
+ case OPCODE_IFNONNULL:
+ op = RelationalOperator.NE;
+ break;
+ }
+
+ evalStack.conditionExpression = null;
+ evalStack.conditionExpression = new ConditionExpression(lhs,
+ Constant.NULL, op);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#
+ * getProcessingOpcodes()
+ */
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_IFNULL, OPCODE_IFNONNULL);
+ }
+
+}
View
101 src/net/sf/jrevpro/ast/evaluator/ConditionUniOperatorEvaluator.java
@@ -0,0 +1,101 @@
+/**
+ * @(#) ConditionUniOperatorEvaluator.java
+ *
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*
+ **/
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.ConditionExpression;
+import net.sf.jrevpro.ast.expression.Constant;
+import net.sf.jrevpro.ast.expression.Expression;
+import net.sf.jrevpro.ast.expression.ConditionExpression.RelationalOperator;
+import net.sf.jrevpro.jls.JLSConstants;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+/**
+ * @author akkumar
+ *
+ */
+public class ConditionUniOperatorEvaluator extends AbstractInstructionEvaluator {
+
+ /**
+ * @param context
+ */
+ public ConditionUniOperatorEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#evaluate
+ * (net.sf.jrevpro.reflect.instruction.Instruction)
+ */
+ @Override
+ void evaluate(Instruction ins) {
+ Expression lhs = evalStack.pop();
+
+ RelationalOperator op = RelationalOperator.EQ;
+
+ switch (ins.opcode) {
+ case OPCODE_IFEQ:
+ op = RelationalOperator.EQ;
+ break;
+ case OPCODE_IFNE:
+ op = RelationalOperator.NE;
+ break;
+ case OPCODE_IFLT:
+ op = RelationalOperator.LT;
+ break;
+ case OPCODE_IFLE:
+ op = RelationalOperator.LE;
+ break;
+ case OPCODE_IFGE:
+ op = RelationalOperator.GE;
+ break;
+ case OPCODE_IFGT:
+ op = RelationalOperator.GT;
+ break;
+
+ }
+ if (evalStack.prevOpcode < OPCODE_LCMP
+ || evalStack.prevOpcode > OPCODE_DCMPG) {
+ // To be compared with 0
+ evalStack.conditionExpression = null;
+ Expression rhs = new Constant(JLSConstants.VALUE_0, lhs.getType());
+
+ evalStack.conditionExpression = new ConditionExpression(lhs, rhs, op);
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#
+ * getProcessingOpcodes()
+ */
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_IFEQ, OPCODE_IFNE, OPCODE_IFLT,
+ OPCODE_IFLE, OPCODE_IFGT, OPCODE_IFGE);
+ }
+
+}
View
53 src/net/sf/jrevpro/ast/evaluator/DConstEvaluator.java
@@ -0,0 +1,53 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.Constant;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+public class DConstEvaluator extends AbstractInstructionEvaluator {
+
+ public DConstEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ @Override
+ void evaluate(Instruction ins) {
+ switch (ins.opcode) {
+ case OPCODE_DCONST_0: {
+ evalStack.push(Constant.DOUBLE_0);
+ break;
+ }
+ case OPCODE_DCONST_1: {
+ evalStack.push(Constant.DOUBLE_1);
+ break;
+ }
+ default:
+ throw new RuntimeException("Opcode " + ins.opcode
+ + " not supported");
+ }
+ }
+
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_DCONST_0, OPCODE_DCONST_1);
+ }
+
+}
View
59 src/net/sf/jrevpro/ast/evaluator/DLoadEvaluator.java
@@ -0,0 +1,59 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.Variable;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+public class DLoadEvaluator extends AbstractInstructionEvaluator {
+
+ public DLoadEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ @Override
+ void evaluate(Instruction ins) {
+ switch (ins.opcode) {
+ case OPCODE_DLOAD:
+ operateLoadInstruction(ins, ins.getArgUnsignedWide());
+ break;
+ case OPCODE_DLOAD_0:
+ case OPCODE_DLOAD_1:
+ case OPCODE_DLOAD_2:
+ case OPCODE_DLOAD_3:
+ operateLoadInstruction(ins, ins.opcode - OPCODE_DLOAD_0);
+ break;
+
+ }
+ }
+
+ private void operateLoadInstruction(Instruction ins,
+ int variableIndexToSymbolTable) {
+ Variable var = new Variable(varTable, JVM_TYPE_DOUBLE,
+ variableIndexToSymbolTable, ins.currentPc);
+ evalStack.push(var);
+ }
+
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_DLOAD, OPCODE_DLOAD_0, OPCODE_DLOAD_1,
+ OPCODE_DLOAD_2, OPCODE_DLOAD_3);
+ }
+}
View
173 src/net/sf/jrevpro/ast/evaluator/DupEvaluator.java
@@ -0,0 +1,173 @@
+/**
+ * @(#) DupEvaluator.java
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ **/
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.Expression;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+/**
+ * @author akkumar
+ *
+ */
+public class DupEvaluator extends AbstractInstructionEvaluator {
+
+ /**
+ * @param context
+ */
+ public DupEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#evaluate
+ * (net.sf.jrevpro.reflect.instruction.Instruction)
+ */
+ @Override
+ void evaluate(Instruction ins) {
+ try {
+ switch (ins.opcode) {
+ case OPCODE_DUP: { // dup
+ evalStack.push(evalStack.peek());
+ break;
+ }
+ case OPCODE_DUP_X1: { // dup_x1
+ Expression op1 = evalStack.pop();
+ Expression op2 = evalStack.pop();
+ evalStack.push(op1);
+ evalStack.push(op2);
+ evalStack.push((Expression) op1.clone());
+ break;
+ }
+ case OPCODE_DUP_X2: { // dup_x2
+ Expression op1 = evalStack.pop();
+ Expression op2 = evalStack.pop();
+ if (op2.isCategory1()) {
+ // Cat.1
+ Expression op3 = evalStack.pop();
+ evalStack.push((Expression) op1.clone());
+ evalStack.push(op3);
+ } else {
+ // Cat.2
+ evalStack.push((Expression) op1.clone());
+ }
+ evalStack.push(op2);
+ evalStack.push(op1);
+ break;
+ }
+ case OPCODE_DUP2: { // dup2
+ Expression op1 = evalStack.pop();
+ if (op1.isCategory1()) {
+ // Cat.1
+ Expression op2 = evalStack.pop();
+ evalStack.push(op2);
+ evalStack.push(op1);
+ evalStack.push((Expression) op2.clone());
+ } else {
+ // Cat.2
+ evalStack.push(op1);
+ }
+ evalStack.push(op1);
+ break;
+ }
+ case OPCODE_DUP2_X1: { // dup2_x1
+ Expression op1 = evalStack.pop();
+ Expression op2 = evalStack.pop();
+ if (op1.isCategory1()) {
+ // Cat.1
+ Expression op3 = evalStack.pop();
+ evalStack.push(op2);
+ evalStack.push(op1);
+ evalStack.push(op3);
+ evalStack.push((Expression) op2.clone());
+ } else {
+ // Cat.2
+ evalStack.push(op1);
+ evalStack.push(op2);
+ }
+ evalStack.push((Expression) op1.clone());
+ break;
+ }
+ case OPCODE_DUP2_X2: { // dup2_x2
+ Expression op1 = evalStack.pop();
+ Expression op2 = evalStack.pop();
+ if (op1.isCategory1()) {
+ // value1-Cat1
+ Expression op3 = evalStack.pop();
+ if (op2.isCategory1()) {
+ // value2-Cat1
+ Expression op4 = evalStack.pop();
+ evalStack.push(op2);
+ evalStack.push(op1);
+ evalStack.push(op4);
+ // Form 1.
+ } else {
+ // value2-Cat2
+ evalStack.push(op2);
+ evalStack.push(op1);
+ // Form. 3
+ }
+ evalStack.push(op3);
+ } else {
+ // value1-Cat2
+ if (op2.isCategory1()) {
+ // value2-Cat1
+ Expression op3 = evalStack.pop();
+ evalStack.push(op1);
+ evalStack.push(op3);
+ // Form. 2
+ } else {
+ // value2-Cat2
+ evalStack.push(op1);
+ // Form 4.
+ }
+ }
+ evalStack.push(op2);
+ evalStack.push(op1);
+ break;
+ }
+ case OPCODE_SWAP: { // swap
+ Expression op1 = evalStack.pop();
+ Expression op2 = evalStack.pop();
+ evalStack.push(op1);
+ evalStack.push(op2);
+ break;
+ }
+ }
+ } catch (CloneNotSupportedException cex) {
+ throw new UnsupportedOperationException("Clone not supported", cex);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.sf.jrevpro.decompile.evaluator.AbstractInstructionEvaluator#
+ * getProcessingOpcodes()
+ */
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_DUP, OPCODE_DUP_X1, OPCODE_DUP_X2,
+ OPCODE_DUP2, OPCODE_DUP2_X1, OPCODE_DUP2_X2, OPCODE_SWAP);
+ }
+}
View
47 src/net/sf/jrevpro/ast/evaluator/EvaluatorContext.java
@@ -0,0 +1,47 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.evaluator;
+
+import net.sf.jrevpro.ast.intermediate.LineOfCodeList;
+import net.sf.jrevpro.reflect.ConstantPool;
+import net.sf.jrevpro.reflect.variabletable.VariableTable;
+
+public class EvaluatorContext {
+
+ public EvaluatorContext(ConstantPool _pool, VariableTable _varTable) {
+
+ pool = _pool;
+ varTable = _varTable;
+ opStack = new EvaluatorStack();
+ statements = new LineOfCodeList();
+ }
+
+ public void setPreviousOpcode(int opcode) {
+ opStack.setPreviousOpcode(opcode);
+ }
+
+ public LineOfCodeList getStatements() {
+ return statements;
+ }
+
+ LineOfCodeList statements;
+ ConstantPool pool;
+ VariableTable varTable;
+ EvaluatorStack opStack;
+
+}
View
127 src/net/sf/jrevpro/ast/evaluator/EvaluatorStack.java
@@ -0,0 +1,127 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+import java.util.Stack;
+import java.util.Vector;
+
+import net.sf.jrevpro.ast.expression.ConditionExpression;
+import net.sf.jrevpro.ast.expression.Expression;
+
+/**
+ * EvaluatorStack Stack is the abstraction of the Java Method evaluator Stack.
+ * The variables are pushed to and popped from, this stack.
+ *
+ * @author Karthik Kumar.
+ */
+public class EvaluatorStack {
+ /**
+ * Empty constructor
+ */
+ public EvaluatorStack() {
+ stack = new Stack<Expression>();
+ constants = new Vector<String>();
+ }
+
+ public Expression push(Expression rhs) {
+ return stack.push(rhs);
+ }
+
+ public Expression pop() {
+ return stack.pop();
+ }
+
+ public Expression peek() {
+ return stack.peek();
+ }
+
+ /**
+ * Adds a new constant.
+ *
+ * @param constant
+ * New Constant to be added to the vector.
+ */
+ public void addConstant(String constant) {
+ constants.add(constant);
+ }
+
+ /**
+ * Deletes all the constants that were stored in the vector already.
+ */
+ public void removeAllConstants() {
+ constants.removeAllElements();
+ }
+
+ /**
+ * @return List of constants that were stored.
+ */
+ public List<String> getConstants() {
+ return constants;
+ }
+
+ /**
+ * Returns the values of the constants serialized such that it corresponds
+ * to java syntax code too.
+ *
+ * @return Constant values.
+ */
+ public String getConstantValues() {
+ StringBuilder result = new StringBuilder("{");
+ for (int i = 0; i < constants.size(); i++) {
+ if (i != 0) {
+ result.append(",");
+ }
+ result.append(constants.get(i));
+ }
+ result.append("}");
+ return result.toString();
+ }
+
+ public void setPreviousOpcode(int _opcode) {
+ prevOpcode = _opcode;
+
+ }
+
+ private Stack<Expression> stack;
+
+ /**
+ * A List of constants. They are primarily used in the following case. Lets
+ * say - we have a code called .
+ *
+ * String [] args = { "run", "args", "args1" };
+ *
+ * In this case all the individual members of the array namely args come
+ * into the constants.
+ */
+ Vector<String> constants;
+
+ /* Currently active statement */
+ // Statement statement;
+ /* Stores the precedence of the operator */
+ int precedence;
+
+ /* Context of a given condition */
+ ConditionExpression conditionExpression;
+
+ /**
+ * Last processed opcode
+ */
+ int prevOpcode;
+
+}
View
59 src/net/sf/jrevpro/ast/evaluator/FConstEvaluator.java
@@ -0,0 +1,59 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.Constant;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+public class FConstEvaluator extends AbstractInstructionEvaluator {
+
+ public FConstEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ @Override
+ void evaluate(Instruction ins) {
+ switch (ins.opcode) {
+ case OPCODE_FCONST_0: { // fconst_0
+ evalStack.push(Constant.FLOAT_0);
+ break;
+ }
+ case OPCODE_FCONST_1: { // fconst_1
+ evalStack.push(Constant.FLOAT_1);
+ break;
+ }
+ case OPCODE_FCONST_2: { // fconst_2
+ evalStack.push(Constant.FLOAT_2);
+ break;
+ }
+ default: {
+ throw new RuntimeException("Opcode " + ins.opcode
+ + "not supported ");
+ }
+ }
+
+ }
+
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_FCONST_0, OPCODE_FCONST_1, OPCODE_FCONST_2);
+ }
+
+}
View
60 src/net/sf/jrevpro/ast/evaluator/FLoadEvaluator.java
@@ -0,0 +1,60 @@
+/**
+ * JReversePro - Java Decompiler / Disassembler.
+ * Copyright (C) 2008 Karthik Kumar.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package net.sf.jrevpro.ast.evaluator;
+
+import java.util.List;
+
+import net.sf.jrevpro.ast.expression.Variable;
+import net.sf.jrevpro.reflect.instruction.Instruction;
+
+public class FLoadEvaluator extends AbstractInstructionEvaluator {
+
+ public FLoadEvaluator(EvaluatorContext context) {
+ super(context);
+ }
+
+ @Override
+ void evaluate(Instruction ins) {
+ switch (ins.opcode) {
+ case OPCODE_FLOAD:
+ operateLoadInstruction(ins, ins.getArgUnsignedWide());
+ break;
+ case OPCODE_FLOAD_0:
+ case OPCODE_FLOAD_1:
+ case OPCODE_FLOAD_2:
+ case OPCODE_FLOAD_3:
+ operateLoadInstruction(ins, ins.opcode - OPCODE_FLOAD_0);
+ break;
+
+ }
+ }
+
+ private void operateLoadInstruction(Instruction ins,
+ int variableIndexToSymbolTable) {
+ Variable var = new Variable(varTable, JVM_TYPE_FLOAT,
+ variableIndexToSymbolTable, ins.currentPc);
+ evalStack.push(var);
+ }
+
+ @Override
+ List<Integer> getProcessingOpcodes() {
+ return numbersAsList(OPCODE_FLOAD, OPCODE_FLOAD_0, OPCODE_FLOAD_1,
+ OPCODE_FLOAD_2, OPCODE_FLOAD_3);
+ }
+
+}
View
61