Skip to content

Commit

Permalink
Merge pull request #70 from BaseMC/develop
Browse files Browse the repository at this point in the history
v0.1.6
  • Loading branch information
litetex authored Jul 8, 2021
2 parents 9c3ccdb + 54d53dd commit 8f95efa
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 49 deletions.
8 changes: 6 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ updates:
directory: "/"
schedule:
interval: daily
time: "03:42"
open-pull-requests-limit: 10
ignore:
- dependency-name: "*"
# GitHub actions are using git tags (v1 = v1.2 = v1.2.3) which should be compatible until a major change is performed
update-types:
- "version-update:semver-minor"
- "version-update:semver-patch"
- package-ecosystem: maven
directory: "/"
schedule:
interval: daily
time: "03:42"
open-pull-requests-limit: 10
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<slf4j.version>1.7.30</slf4j.version>
<slf4j.version>1.7.31</slf4j.version>
<log4j.version>2.14.1</log4j.version>

<asm.version>9.1</asm.version>
<asm.version>9.2</asm.version>

<junit.version>5.7.1</junit.version>
<junit.version>5.7.2</junit.version>

<main.class>javgent.App</main.class>

Expand Down Expand Up @@ -84,7 +84,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand All @@ -96,7 +96,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
<version>2.12.4</version>
</dependency>

<!-- Tests -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/javgent/ASMAC.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private ASMAC() {
//No Impl pls
}

public static final int ASM_VERSION = Opcodes.ASM5;
public static final int ASM_VERSION = Opcodes.ASM9;

public static final String JAVA_PACKAGE_SEPARATOR = ".";
public static final String CLASS_PACKAGE_SEPARATOR = "/";
Expand Down
45 changes: 32 additions & 13 deletions src/main/java/javgent/executor/bytecode/clazz/BCClassVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import javgent.ASMAC;
import javgent.executor.bytecode.ClassControllerRegistry;
import javgent.executor.bytecode.clazz.sub.field.BCFieldVisitor;
import javgent.executor.bytecode.clazz.sub.field.ModifierForField;
import javgent.executor.bytecode.clazz.sub.method.BCMethodVisitor;
import javgent.executor.bytecode.clazz.sub.method.ModifierForMethod;
import javgent.executor.bytecode.clazz.sub.field.ModifierForField;
import javgent.executor.bytecode.clazz.sub.field.BCFieldVisitor;
import javgent.executor.bytecode.clazz.sub.method.visitor.MethodSignatureWriter;
import javgent.executor.bytecode.clazz.util.RemoteMethodResolver;
import javgent.executor.bytecode.clazz.writers.ClassDescriptorWriter;
import org.objectweb.asm.*;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.ModuleVisitor;
import org.objectweb.asm.RecordComponentVisitor;
import org.objectweb.asm.TypePath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -143,16 +150,14 @@ public void visitOuterClass(String owner, String name, String descriptor) {

var result = optResult.get();

String newOwner = result.Owner;

var optName = result.Name;
if (optName.isPresent())
name = optName.get();

if (descriptor != null)
descriptor = MethodSignatureWriter.convert(controller, descriptor);

super.visitOuterClass(newOwner, name, descriptor);
super.visitOuterClass(result.Owner, name, descriptor);
}

@Override
Expand Down Expand Up @@ -180,31 +185,45 @@ public void visitInnerClass(String name, String outerName, String innerName, int

@Override
public void visitNestMember(String nestMember) {
Log.warn("Visiting not implemented method! nestMember='{}'", nestMember);
super.visitNestMember(nestMember);
if (!controllerPresent()) {
super.visitNestMember(nestMember);
return;
}

super.visitNestMember(controller.findNameByObfNameOrReturn(nestMember));
}

@Override
public void visitNestHost(String nestHost) {
Log.warn("Visiting not implemented method! nestHost='{}'", nestHost);
super.visitNestHost(nestHost);
if (!controllerPresent()) {
super.visitNestHost(nestHost);
return;
}

super.visitNestHost(controller.findNameByObfNameOrReturn(nestHost));
}

@Override
public ModuleVisitor visitModule(String name, int access, String version) {
Log.warn("Visiting not implemented method! name='{}',version='{}'", name, version);
Log.warn("Visiting not implemented 'visitModule'! name='{}',version='{}'", name, version);
return super.visitModule(name, access, version);
}

@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
Log.warn("Visiting not implemented method! typePath='{}',descriptor='{}'", typePath, descriptor);
Log.warn("Visiting not implemented 'visitTypeAnnotation'! typePath='{}',descriptor='{}'", typePath, descriptor);
return super.visitTypeAnnotation(typeRef, typePath, descriptor, visible);
}

@Override
public void visitAttribute(Attribute attribute) {
Log.warn("Visiting not implemented method! attr.type='{}'", attribute.type);
Log.warn("Visiting not implemented 'visitAttribute'! attr.type='{}'", attribute.type);
super.visitAttribute(attribute);
}

@Override
public RecordComponentVisitor visitRecordComponent(String name, String descriptor, String signature) {
Log.warn("Visiting not implemented 'visitRecordComponent'! name='{},descriptor='{}'", name, descriptor);
return super.visitRecordComponent(name, descriptor, signature);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {

@Override
public void visitAttribute(Attribute attribute) {
Log.warn("Visiting not implemented method! type='{}'", attribute.type);
Log.warn("Visiting not implemented 'visitAttribute'! type='{}'", attribute.type);
super.visitAttribute(attribute);
}

@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
Log.warn("Visiting not implemented method! typePath='{}',descriptor='{}'", typePath, descriptor);
Log.warn("Visiting not implemented 'visitTypeAnnotation'! typePath='{}',descriptor='{}'", typePath, descriptor);
return super.visitTypeAnnotation(typeRef, typePath, descriptor, visible);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
import javgent.executor.bytecode.clazz.util.RemoteMethodResolver;
import javgent.executor.bytecode.clazz.writers.ClassDescriptorWriter;
import javgent.executor.bytecode.clazz.writers.ClassSignatureWriter;
import org.objectweb.asm.*;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.TypePath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -69,7 +74,6 @@ public void visitFieldInsn(int opcode, String owner, String name, String descrip
@Override
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {


var optionalMethodMethodResolverResult = RemoteMethodResolver.resolve(getCurrentClassController(), owner, name, descriptor);
if (optionalMethodMethodResolverResult.isPresent()) {
var methodFieldResolverResult = optionalMethodMethodResolverResult.get();
Expand Down Expand Up @@ -190,21 +194,21 @@ public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, Str

@Override
public AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
Log.warn("Visiting not implemented method! descriptor='{}'", descriptor);
Log.warn("Visiting not implemented 'visitInsnAnnotation! descriptor='{}'", descriptor);
return super.visitInsnAnnotation(typeRef, typePath, descriptor, visible);
}

//----

@Override
public void visitAttribute(Attribute attribute) {
Log.warn("Visiting not implemented method! attr.type='{}'", attribute.type);
Log.warn("Visiting not implemented 'visitAttribute'! attr.type='{}'", attribute.type);
super.visitAttribute(attribute);
}

@Override
public void visitParameter(String name, int access) {
Log.warn("Visiting not implemented method! name='{}'", name);
Log.warn("Visiting not implemented 'visitParameter'! name='{}'", name);
super.visitParameter(name, access);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package javgent.executor.execmodules.patchfiles;

import javgent.executor.model.PatchClass;
import javgent.executor.modelconverter.ComPatchConverter;
import javgent.commodel.ComPatchClass;
import javgent.commodel.ComPatchField;
import javgent.commodel.ComPatchMethod;
import javgent.commodel.ComPatchParameter;
import javgent.executor.model.PatchClass;
import javgent.executor.modelconverter.ComPatchConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -35,8 +39,7 @@ public Set<PatchClass> readPatchFiles(String mappingFile) {

try {
List<String> lines = new ArrayList<>();
try(Stream<String> stream = Files.lines(Paths.get(mappingFile)))
{
try (Stream<String> stream = Files.lines(Paths.get(mappingFile))) {
lines = stream.collect(Collectors.toList());
}
for (var line : lines) {
Expand All @@ -48,7 +51,7 @@ public Set<PatchClass> readPatchFiles(String mappingFile) {
if (!line.startsWith(" ")) { //Class
last = getComPatchClassFromLine(line);
comPatchClasses.add(last);
} else if(last == null)
} else if (last == null)
throw new IllegalArgumentException("Didn't find a class for line: " + line);
else //Sub
processPayloadOfLine(line, last);
Expand All @@ -75,8 +78,8 @@ private ComPatchClass getComPatchClassFromLine(String line) {

private void processPayloadOfLine(String line, ComPatchClass last) {
var tmp1 = line.split(CLASS_SPLIT_PATTERN);
if(tmp1.length != 2)
throw new IllegalArgumentException(tmp1.length +" == "+ 2);
if (tmp1.length != 2)
throw new IllegalArgumentException(tmp1.length + " == " + 2);

String obfName = tmp1[1];

Expand All @@ -86,12 +89,12 @@ private void processPayloadOfLine(String line, ComPatchClass last) {
method.ObfName = obfName;

var tmp2 = tmp1[0].split(Pattern.quote(":"));
if(tmp2.length != 3)
throw new IllegalArgumentException(tmp2.length +" == "+ 3);
if (tmp2.length != 3)
throw new IllegalArgumentException(tmp2.length + " == " + 3);

var tmp3 = tmp2[2].split(" ");
if(tmp3.length != 2)
throw new IllegalArgumentException(tmp3.length +" == "+ 2);
if (tmp3.length != 2)
throw new IllegalArgumentException(tmp3.length + " == " + 2);

method.ReturnType = tmp3[0];

Expand All @@ -103,8 +106,8 @@ private void processPayloadOfLine(String line, ComPatchClass last) {
} else //Field or Method with no line numbers (rare)
{
var tmp2 = Arrays.stream(tmp1[0].split(" ")).filter(str -> !str.isEmpty()).toArray(String[]::new);
if(tmp2.length != 2)
throw new IllegalArgumentException(tmp2.length +" == "+ 2);
if (tmp2.length != 2)
throw new IllegalArgumentException(tmp2.length + " == " + 2);

//Method with no line numbers
if (tmp2[1].contains("(") && tmp2[1].contains(")")) {
Expand All @@ -129,8 +132,7 @@ private void processPayloadOfLine(String line, ComPatchClass last) {
}
}

private NameAndParametersComObj getNameAndComPatchParameters(String nameAndPars)
{
private NameAndParametersComObj getNameAndComPatchParameters(String nameAndPars) {
var indexOfParsStart = nameAndPars.indexOf('(');
var name = nameAndPars.substring(0, indexOfParsStart);

Expand All @@ -139,8 +141,7 @@ private NameAndParametersComObj getNameAndComPatchParameters(String nameAndPars)
parStr = parStr.substring(0, parStr.indexOf(')'));

List<ComPatchParameter> pars = new ArrayList<>();
if (!"".equals(parStr))
{
if (!"".equals(parStr)) {
pars = Arrays.stream(parStr.split(","))
.map(parType -> {
var comPar = new ComPatchParameter();
Expand All @@ -150,11 +151,11 @@ private NameAndParametersComObj getNameAndComPatchParameters(String nameAndPars)
.collect(Collectors.toList());
}

return new NameAndParametersComObj(name,pars);
return new NameAndParametersComObj(name, pars);
}


class NameAndParametersComObj {
class NameAndParametersComObj {
private final String name;
private final List<ComPatchParameter> parameters;

Expand Down

0 comments on commit 8f95efa

Please sign in to comment.