mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FIX] Фиксы InjectClassAcceptor
This commit is contained in:
parent
b4a75b9076
commit
667fb21e9b
3 changed files with 11 additions and 3 deletions
|
@ -49,14 +49,15 @@ private static void visit(ClassNode cn, Map<String, Object> object) {
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
List<MethodNode> constructors = cn.methods.stream().filter(e -> "<init>".equals(e.name)).collect(Collectors.toList());
|
List<MethodNode> constructors = cn.methods.stream().filter(e -> "<init>".equals(e.name)).collect(Collectors.toList());
|
||||||
MethodNode init = constructors.stream().filter(e -> e.invisibleAnnotations.stream().filter(f -> INJ_C_DESC.equals(f.desc)).findFirst()
|
MethodNode init = constructors.stream().filter(e -> e != null && e.invisibleAnnotations != null && e.invisibleAnnotations.stream().anyMatch(f -> INJ_C_DESC.equals(f.desc))).findFirst()
|
||||||
.isPresent()).findFirst().orElseGet(() -> constructors.stream().filter(e -> e.desc.equals("()V")).findFirst().orElse(null));
|
.orElseGet(() -> constructors.stream().filter(e -> e.desc.equals("()V")).findFirst().orElse(null));
|
||||||
cn.fields.stream().filter(e -> e.invisibleAnnotations != null)
|
cn.fields.stream().filter(e -> e.invisibleAnnotations != null)
|
||||||
.filter(e -> !e.invisibleAnnotations.isEmpty() && e.invisibleAnnotations.stream().anyMatch(f -> f.desc.equals(INJ_DESC))).forEach(e -> {
|
.filter(e -> !e.invisibleAnnotations.isEmpty() && e.invisibleAnnotations.stream().anyMatch(f -> f.desc.equals(INJ_DESC))).forEach(e -> {
|
||||||
// Notice that fields that will be used with this algo should not have default
|
// Notice that fields that will be used with this algo should not have default
|
||||||
// value by = ...;
|
// value by = ...;
|
||||||
AnnotationNode n = e.invisibleAnnotations.stream().filter(f -> INJ_DESC.equals(f.desc)).findFirst()
|
AnnotationNode n = e.invisibleAnnotations.stream().filter(f -> INJ_DESC.equals(f.desc)).findFirst()
|
||||||
.get();
|
.get();
|
||||||
|
e.invisibleAnnotations.removeIf(f -> INJ_DESC.equals(f.desc));
|
||||||
AtomicReference<String> valueName = new AtomicReference<>(null);
|
AtomicReference<String> valueName = new AtomicReference<>(null);
|
||||||
n.accept(new AnnotationVisitor(Opcodes.ASM7) {
|
n.accept(new AnnotationVisitor(Opcodes.ASM7) {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.asm.ClassMetadataReader;
|
import pro.gravit.launchserver.asm.ClassMetadataReader;
|
||||||
import pro.gravit.launchserver.asm.ConfigGenerator;
|
import pro.gravit.launchserver.asm.ConfigGenerator;
|
||||||
|
import pro.gravit.launchserver.asm.InjectClassAcceptor;
|
||||||
import pro.gravit.launchserver.binary.BuildContext;
|
import pro.gravit.launchserver.binary.BuildContext;
|
||||||
import pro.gravit.launchserver.binary.LauncherConfigurator;
|
import pro.gravit.launchserver.binary.LauncherConfigurator;
|
||||||
import pro.gravit.utils.HookException;
|
import pro.gravit.utils.HookException;
|
||||||
|
@ -123,9 +124,13 @@ public void transform(ClassNode cn, String classname, BuildContext context) {
|
||||||
public IOHookSet<BuildContext> preBuildHook = new IOHookSet<>();
|
public IOHookSet<BuildContext> preBuildHook = new IOHookSet<>();
|
||||||
public IOHookSet<BuildContext> postBuildHook = new IOHookSet<>();
|
public IOHookSet<BuildContext> postBuildHook = new IOHookSet<>();
|
||||||
|
|
||||||
|
public Map<String, Object> properties = new HashMap<>();
|
||||||
|
|
||||||
public MainBuildTask(LaunchServer srv) {
|
public MainBuildTask(LaunchServer srv) {
|
||||||
server = srv;
|
server = srv;
|
||||||
reader = new ClassMetadataReader();
|
reader = new ClassMetadataReader();
|
||||||
|
InjectClassAcceptor injectClassAcceptor = new InjectClassAcceptor(properties);
|
||||||
|
transformers.add(injectClassAcceptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import org.objectweb.asm.tree.FieldNode;
|
import org.objectweb.asm.tree.FieldNode;
|
||||||
import pro.gravit.launcher.LauncherInject;
|
import pro.gravit.launcher.LauncherInject;
|
||||||
|
import pro.gravit.launcher.LauncherInjectionConstructor;
|
||||||
import pro.gravit.launchserver.asm.InjectClassAcceptor;
|
import pro.gravit.launchserver.asm.InjectClassAcceptor;
|
||||||
import pro.gravit.utils.PublicURLClassLoader;
|
import pro.gravit.utils.PublicURLClassLoader;
|
||||||
import pro.gravit.utils.helper.JarHelper;
|
import pro.gravit.utils.helper.JarHelper;
|
||||||
|
@ -48,7 +49,8 @@ void testASM() throws Exception
|
||||||
node.name = "ASMTestClass";
|
node.name = "ASMTestClass";
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("testprop", 1234);
|
map.put("testprop", 1234);
|
||||||
InjectClassAcceptor.visit(node, map);
|
InjectClassAcceptor injectClassAcceptor = new InjectClassAcceptor(map);
|
||||||
|
injectClassAcceptor.transform(node, "ASMTestClass", null);
|
||||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
node.accept(writer);
|
node.accept(writer);
|
||||||
byte[] bytes = writer.toByteArray();
|
byte[] bytes = writer.toByteArray();
|
||||||
|
|
Loading…
Reference in a new issue