Skip to content

Commit

Permalink
Merge branch 'dev4' of https://github.com/Col-E/Recaf into plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jun 15, 2024
2 parents 98b54f8 + b5dab0e commit fc51909
Show file tree
Hide file tree
Showing 190 changed files with 7,164 additions and 2,189 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*.xml text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
*.toml text eol=lf
*.lang text eol=lf

# These files are binary and should be left untouched
*.png binary
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ Open the project in an IDE or generate the build with gradle.

**Without IDE**:
1. Run `gradlew build`
- Output will be located at: `recaf-ui/build/recaf-ui-{VERSION}-all.jar`
- Output will be located at: `recaf-ui/build/libs/recaf-ui-{VERSION}-all.jar`
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ subprojects {

// Append options for unchecked/deprecation
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation' << '-g' << '-parameters'
options.encoding = 'UTF-8'
options.incremental = true
}
Expand Down
10 changes: 6 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ dex-translator = "1.1.1"
directories = "26"
docking = "1.2.3"
downgrader = "1.1.1"
extra-collections = "1.2.3"
extra-collections = "1.3.0"
extra-observables = "1.3.0"
gson = "2.10.1"
ikonli = "12.3.1"
instrument-server = "1.4.0"
instrument-server = "1.4.1"
jackson = "2.16.1"
jakarta-annotation = "3.0.0-M1"
jasm = "913f24ec92"
jasm = "3db094eade"
jlinker = "1.0.7"
jphantom = "1.4.4"
junit = "5.10.2"
Expand All @@ -26,6 +26,7 @@ llzip = "2.5.0"
logback-classic = { strictly = "1.4.11" } # newer releases break in jar releases
mapping-io = "0.5.1"
mockito = "5.11.0"
natural-order = "1.1"
openrewrite = "8.19.0"
picocli = "4.7.5"
procyon = "0.6.0"
Expand All @@ -44,7 +45,6 @@ peterabeles-gversion = "1.10.2"
jgrapht = "1.5.2"

[libraries]

asm-core = { module = "org.ow2.asm:asm", version.ref = "asm" }
asm-analysis = { module = "org.ow2.asm:asm-analysis", version.ref = "asm" }
asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm" }
Expand Down Expand Up @@ -106,6 +106,8 @@ mapping-io = { module = "net.fabricmc:mapping-io", version.ref = "mapping-io" }

mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }

natural-order = { module = "net.grey-panther:natural-comparator", version.ref = "natural-order" }

openrewrite = { module = "org.openrewrite:rewrite-java-17", version.ref = "openrewrite" }

picocli = { module = "info.picocli:picocli", version.ref = "picocli" }
Expand Down
1 change: 1 addition & 0 deletions recaf-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
api(libs.llzip)
api(libs.bundles.logging)
api(libs.mapping.io)
api(libs.natural.order)
api(libs.picocli)
api(libs.procyon)
api(libs.jackson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import static org.slf4j.LoggerFactory.getLogger;

Expand All @@ -23,7 +24,7 @@
*/
public class Logging {
private static final Map<String, DebuggingLogger> loggers = new ConcurrentHashMap<>();
private static final List<LogConsumer<String>> logConsumers = new ArrayList<>();
private static final List<LogConsumer<String>> logConsumers = new CopyOnWriteArrayList<>();
private static Level interceptLevel = Level.INFO;

/**
Expand All @@ -50,15 +51,15 @@ public static DebuggingLogger get(Class<?> cls) {
* @param consumer
* New log message consumer.
*/
public static void addLogConsumer(LogConsumer<String> consumer) {
public static void addLogConsumer(@Nonnull LogConsumer<String> consumer) {
logConsumers.add(consumer);
}

/**
* @param consumer
* Log message consumer to remove.
*/
public static void removeLogConsumer(LogConsumer<String> consumer) {
public static void removeLogConsumer(@Nonnull LogConsumer<String> consumer) {
logConsumers.remove(consumer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/**
* Applied to beans to enable eager initialization, which is to say they and their dependencies get created as soon as
* possible depending on the {@link #value() value of the intended} {@link InitializationStage}.
* <p/>
* Beans are not eagerly initialized while in a test environment.
*
* @author Matt Coley
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import software.coley.recaf.info.builder.AbstractClassInfoBuilder;
import software.coley.recaf.info.member.BasicMember;
import software.coley.recaf.info.member.FieldMember;
import software.coley.recaf.info.member.LocalVariable;
import software.coley.recaf.info.member.MethodMember;
import software.coley.recaf.info.properties.Property;
import software.coley.recaf.info.properties.PropertyContainer;
import software.coley.recaf.util.Types;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Stream;

/**
Expand All @@ -24,6 +23,9 @@
* @see BasicAndroidClassInfo
*/
public abstract class BasicClassInfo implements ClassInfo {
private static final int SIGS_VALID = 1;
private static final int SIGS_INVALID = 0;
private static final int SIGS_UNKNOWN = -1;
private final PropertyContainer properties;
private final String name;
private final String superName;
Expand All @@ -40,6 +42,7 @@ public abstract class BasicClassInfo implements ClassInfo {
private final List<FieldMember> fields;
private final List<MethodMember> methods;
private List<String> breadcrumbs;
private int sigCheck = SIGS_UNKNOWN;

protected BasicClassInfo(AbstractClassInfoBuilder<?> builder) {
this(builder.getName(),
Expand All @@ -60,14 +63,14 @@ protected BasicClassInfo(AbstractClassInfoBuilder<?> builder) {
}

protected BasicClassInfo(@Nonnull String name, String superName, @Nonnull List<String> interfaces, int access,
String signature, String sourceFileName,
@Nonnull List<AnnotationInfo> annotations,
@Nonnull List<TypeAnnotationInfo> typeAnnotations,
String outerClassName, String outerMethodName,
String outerMethodDescriptor,
@Nonnull List<InnerClassInfo> innerClasses,
@Nonnull List<FieldMember> fields, @Nonnull List<MethodMember> methods,
@Nonnull PropertyContainer properties) {
String signature, String sourceFileName,
@Nonnull List<AnnotationInfo> annotations,
@Nonnull List<TypeAnnotationInfo> typeAnnotations,
String outerClassName, String outerMethodName,
String outerMethodDescriptor,
@Nonnull List<InnerClassInfo> innerClasses,
@Nonnull List<FieldMember> fields, @Nonnull List<MethodMember> methods,
@Nonnull PropertyContainer properties) {
this.name = name;
this.superName = superName;
this.interfaces = interfaces;
Expand Down Expand Up @@ -117,6 +120,49 @@ public String getSignature() {
return signature;
}

@Override
public boolean hasValidSignatures() {
// Check cached value.
if (sigCheck != SIGS_UNKNOWN) return sigCheck == SIGS_VALID;

// Check class level signature.
String classSignature = getSignature();
if (classSignature != null && !Types.isValidSignature(classSignature, false)) {
sigCheck = SIGS_INVALID;
return false;
}

// Check field signatures.
for (FieldMember field : getFields()) {
String fieldSignature = field.getSignature();
if (fieldSignature != null && !Types.isValidSignature(field.getSignature(), true)) {
sigCheck = SIGS_INVALID;
return false;
}
}

// Check method signatures.
for (MethodMember method : getMethods()) {
String methodSignature = method.getSignature();
if (methodSignature != null && !Types.isValidSignature(methodSignature, false)) {
sigCheck = SIGS_INVALID;
return false;
}

// And local variables.
for (LocalVariable variable : method.getLocalVariables()) {
String localSignature = variable.getSignature();
if (localSignature != null && !Types.isValidSignature(localSignature, true)) {
sigCheck = SIGS_INVALID;
return false;
}
}
}

sigCheck = SIGS_VALID;
return true;
}

@Override
public String getSourceFileName() {
return sourceFileName;
Expand Down Expand Up @@ -153,16 +199,19 @@ public String getOuterMethodDescriptor() {
@Override
public List<String> getOuterClassBreadcrumbs() {
if (breadcrumbs == null) {
String currentOuter = getOuterClassName();
if (currentOuter == null)
return breadcrumbs = Collections.emptyList();

int maxOuterDepth = 10;
breadcrumbs = new ArrayList<>();
String currentOuter = getOuterClassName();
int counter = 0;
while (currentOuter != null) {
if (++counter > maxOuterDepth) {
breadcrumbs.clear(); // assuming some obfuscator is at work, so breadcrumbs might be invalid.
break;
}
breadcrumbs.add(0, currentOuter);
breadcrumbs.addFirst(currentOuter);
String targetOuter = currentOuter;
currentOuter = innerClasses.stream()
.filter(i -> i.getInnerClassName().equals(targetOuter))
Expand Down Expand Up @@ -236,7 +285,7 @@ public boolean equals(Object o) {
public int hashCode() {
// NOTE: Do NOT consider the properties since contents of the map can point back to this instance
// or our containing resource, causing a cycle.
int result = name.hashCode();
int result = name.hashCode();
result = 31 * result + (superName != null ? superName.hashCode() : 0);
result = 31 * result + interfaces.hashCode();
result = 31 * result + access;
Expand Down
12 changes: 12 additions & 0 deletions recaf-core/src/main/java/software/coley/recaf/info/ClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import software.coley.recaf.info.member.ClassMember;
import software.coley.recaf.info.member.FieldMember;
import software.coley.recaf.info.member.MethodMember;
import software.coley.recaf.util.Types;
import software.coley.recaf.util.visitors.IllegalSignatureRemovingVisitor;

import java.util.List;
import java.util.function.Consumer;
Expand Down Expand Up @@ -78,6 +80,16 @@ default Stream<String> parentTypesStream() {
@Nullable
String getSignature();

/**
* @return {@code true} when the {@link #getSignature() class signature} and all
* {@link #getFields() fields} and {@link #getMethods() methods} have valid {@link ClassMember#getSignature() signatures}.
* {@code false} when any of those values is malformed.
*
* @see IllegalSignatureRemovingVisitor Visitor for removing invalid signatures on JVM classes.
* @see Types#isValidSignature(String, boolean) Method for checking validity of a generic signature.
*/
boolean hasValidSignatures();

/**
* @return Name of outer class that this is declared in, if this is an inner class.
* {@code null} when this class is not an inner class.
Expand Down
Loading

0 comments on commit fc51909

Please sign in to comment.