From c3841a8493511aef0d3b4b0a240412f81f76f859 Mon Sep 17 00:00:00 2001 From: Cody <6558800+Bl3nd@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:58:53 -0600 Subject: [PATCH 1/4] Do not parse if the decompiler used prints out disassembly/bytecode. --- .../gui/util/BytecodeViewPanelUpdater.java | 40 +++++++++++-------- .../classcontainer/ClassFileContainer.java | 26 +++++++++--- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java index df13c76f8..52465cab2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java @@ -118,9 +118,9 @@ public void processDisplay() if (!BytecodeViewer.viewer.workPane.classFiles.containsKey(workingDecompilerName)) { - container.parse(); + boolean parsed = container.parse(); BytecodeViewer.viewer.workPane.classFiles.put(workingDecompilerName, container); - container.hasBeenParsed = true; + container.hasBeenParsed = parsed; } //set the swing components on the swing thread @@ -449,24 +449,27 @@ else if (isPanelEditable && decompiler == Decompiler.KRAKATAU_DISASSEMBLER) @Override public void mouseMoved(MouseEvent e) { - if (e.isControlDown()) + if (classFileContainer.hasBeenParsed) { - RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource(); - Token token = textArea.viewToToken(e.getPoint()); - if (token != null) + if (e.isControlDown()) { - String lexeme = token.getLexeme(); - if (classFileContainer.fieldMembers.containsKey(lexeme) || classFileContainer.methodMembers.containsKey(lexeme) || classFileContainer.methodLocalMembers.containsKey(lexeme) || classFileContainer.methodParameterMembers.containsKey(lexeme) || classFileContainer.classReferences.containsKey(lexeme)) + RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource(); + Token token = textArea.viewToToken(e.getPoint()); + if (token != null) { - textArea.setCursor(new Cursor(Cursor.HAND_CURSOR)); + String lexeme = token.getLexeme(); + if (classFileContainer.fieldMembers.containsKey(lexeme) || classFileContainer.methodMembers.containsKey(lexeme) || classFileContainer.methodLocalMembers.containsKey(lexeme) || classFileContainer.methodParameterMembers.containsKey(lexeme) || classFileContainer.classReferences.containsKey(lexeme)) + { + textArea.setCursor(new Cursor(Cursor.HAND_CURSOR)); + } } } - } - else - { - if (bytecodeViewPanel.textArea.getCursor().getType() != Cursor.TEXT_CURSOR) + else { - bytecodeViewPanel.textArea.setCursor(new Cursor(Cursor.TEXT_CURSOR)); + if (bytecodeViewPanel.textArea.getCursor().getType() != Cursor.TEXT_CURSOR) + { + bytecodeViewPanel.textArea.setCursor(new Cursor(Cursor.TEXT_CURSOR)); + } } } } @@ -477,10 +480,13 @@ public void mouseMoved(MouseEvent e) @Override public void mouseClicked(MouseEvent e) { - if (e.isControlDown()) + if (classFileContainer.hasBeenParsed) { - RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource(); - textArea.getActionMap().get("goToAction").actionPerformed(new ActionEvent(textArea, ActionEvent.ACTION_PERFORMED, "goToAction")); + if (e.isControlDown()) + { + RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource(); + textArea.getActionMap().get("goToAction").actionPerformed(new ActionEvent(textArea, ActionEvent.ACTION_PERFORMED, "goToAction")); + } } } }); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java index 3e8c4bbbf..2d0429fec 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java @@ -9,6 +9,7 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; import the.bytecode.club.bytecodeviewer.resources.classcontainer.locations.*; import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.MyVoidVisitor; @@ -51,14 +52,18 @@ public ClassFileContainer(String className, String content, ResourceContainer re /** * Parse the class content with JavaParser. */ - public void parse() + public boolean parse() { try { - TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false), new JarTypeSolver(path)); - StaticJavaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver)); - CompilationUnit compilationUnit = StaticJavaParser.parse(this.content); - compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null); + if (shouldParse()) + { + TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false), new JarTypeSolver(path)); + StaticJavaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver)); + CompilationUnit compilationUnit = StaticJavaParser.parse(this.content); + compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null); + return true; + } } catch (IOException e) { @@ -69,6 +74,17 @@ public void parse() System.err.println("Parsing error: " + className); e.printStackTrace(); } + + return false; + } + + public boolean shouldParse() + { + return !getDecompiler().equals(Decompiler.BYTECODE_DISASSEMBLER.getDecompilerName()) + && !getDecompiler().equals(Decompiler.KRAKATAU_DISASSEMBLER.getDecompilerName()) + && !getDecompiler().equals(Decompiler.JAVAP_DISASSEMBLER.getDecompilerName()) + && !getDecompiler().equals(Decompiler.SMALI_DISASSEMBLER.getDecompilerName()) + && !getDecompiler().equals(Decompiler.ASM_TEXTIFY_DISASSEMBLER.getDecompilerName()); } public String getName() From d76644ee05e2d59ad4ed5af0d877fea8925bb82d Mon Sep 17 00:00:00 2001 From: Cody <6558800+Bl3nd@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:53:28 -0600 Subject: [PATCH 2/4] Remove adding class reference when it's a "this." expression. --- .../resources/classcontainer/parser/MyVoidVisitor.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java index 4ac3f3e95..9b4ee95f2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java @@ -175,8 +175,6 @@ else if (scope instanceof ThisExpr) ResolvedType resolvedType = n.getSymbolResolver().calculateType(thisExpr); String qualifiedName = resolvedType.asReferenceType().getQualifiedName(); String className = qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1); - String packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')); - this.classFileContainer.putClassReference(className, new ClassReferenceLocation(getOwner(), packageName.replace('.', '/'), fieldName, "reference", line, columnStart, columnEnd + 1)); this.classFileContainer.putField(fieldName, new ClassFieldLocation(className, "reference", line, columnStart, columnEnd + 1)); } } From 9ce2b22f2a518b8067bb91d8aee3b437387e58f6 Mon Sep 17 00:00:00 2001 From: Cody <6558800+Bl3nd@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:34:38 -0600 Subject: [PATCH 3/4] Remove anonymous class body ConstructorDeclaration from being parsed. --- .../classcontainer/parser/MyVoidVisitor.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java index 9b4ee95f2..b5b25283a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java @@ -2,6 +2,7 @@ import com.github.javaparser.Range; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.stmt.*; @@ -205,6 +206,16 @@ public void visit(ConstructorDeclaration n, Object arg) this.classFileContainer.putParameter(parameterName, new ClassParameterLocation(getOwner(), n.getDeclarationAsString(false, false), "declaration", line, columnStart, columnEnd + 1)); }); + if (n.getParentNode().get() instanceof ObjectCreationExpr) + { + ObjectCreationExpr objectCreationExpr = (ObjectCreationExpr) n.getParentNode().get(); + NodeList> bodyDeclarations = objectCreationExpr.getAnonymousClassBody().get(); + if (bodyDeclarations.getFirst().get().equals(n)) + { + return; + } + } + ResolvedConstructorDeclaration resolve = n.resolve(); String signature = resolve.getQualifiedSignature(); String parameters = ""; From d642610d72214ed62e8ee8315ffdd43e66e5aca3 Mon Sep 17 00:00:00 2001 From: Cody <6558800+Bl3nd@users.noreply.github.com> Date: Sat, 28 Sep 2024 00:12:42 -0600 Subject: [PATCH 4/4] Clean-up --- .../bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java | 8 ++------ .../resources/classcontainer/ClassFileContainer.java | 2 -- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java index 52465cab2..4e1a40fcb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java @@ -510,7 +510,6 @@ private void markOccurrences(RSyntaxTextArea textArea, ClassFileContainer classF if (token == null) { highlighterEx.clearMarkOccurrencesHighlights(); - errorStripe.refreshMarkers(); return; } } @@ -519,7 +518,6 @@ private void markOccurrences(RSyntaxTextArea textArea, ClassFileContainer classF if (token == null) { highlighterEx.clearMarkOccurrencesHighlights(); - errorStripe.refreshMarkers(); return; } @@ -620,7 +618,7 @@ private void markMethod(RSyntaxTextArea textArea, ClassFileContainer classFileCo * @param finalToken the token * @param highlighterEx the highlighter */ - private static void markMethodParameter(RSyntaxTextArea textArea, ClassFileContainer classFileContainer, int line, int column, Token finalToken, RSyntaxTextAreaHighlighterEx highlighterEx) + private void markMethodParameter(RSyntaxTextArea textArea, ClassFileContainer classFileContainer, int line, int column, Token finalToken, RSyntaxTextAreaHighlighterEx highlighterEx) { classFileContainer.methodParameterMembers.values().forEach(parameters -> parameters.forEach(parameter -> { @@ -637,7 +635,6 @@ private static void markMethodParameter(RSyntaxTextArea textArea, ClassFileConta { int startOffset = root.getElement(location.line - 1).getStartOffset() + (location.columnStart - 1); int endOffset = root.getElement(location.line - 1).getStartOffset() + (location.columnEnd - 1); - highlighterEx.addMarkedOccurrenceHighlight(startOffset, endOffset, new SmartHighlightPainter()); } } @@ -660,7 +657,7 @@ private static void markMethodParameter(RSyntaxTextArea textArea, ClassFileConta * @param finalToken the token * @param highlighterEx the highlighter */ - private static void markMethodLocalVariable(RSyntaxTextArea textArea, ClassFileContainer classFileContainer, int line, int column, Token finalToken, RSyntaxTextAreaHighlighterEx highlighterEx) + private void markMethodLocalVariable(RSyntaxTextArea textArea, ClassFileContainer classFileContainer, int line, int column, Token finalToken, RSyntaxTextAreaHighlighterEx highlighterEx) { classFileContainer.methodLocalMembers.values().forEach(localVariables -> localVariables.forEach(localVariable -> { @@ -677,7 +674,6 @@ private static void markMethodLocalVariable(RSyntaxTextArea textArea, ClassFileC { int startOffset = root.getElement(location.line - 1).getStartOffset() + (location.columnStart - 1); int endOffset = root.getElement(location.line - 1).getStartOffset() + (location.columnEnd - 1); - highlighterEx.addMarkedOccurrenceHighlight(startOffset, endOffset, new SmartHighlightPainter()); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java index 2d0429fec..50e71bb6f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java @@ -1,10 +1,8 @@ package the.bytecode.club.bytecodeviewer.resources.classcontainer; -import com.github.javaparser.ParseProblemException; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.resolution.TypeSolver; -import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver;