forked from SteamWar/SteamWar
Fix Agent and WideningTransformer and ClassPatcher
This commit is contained in:
@@ -19,10 +19,12 @@
|
||||
|
||||
package de.steamwar;
|
||||
|
||||
import org.objectweb.asm.*;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -33,6 +35,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class ClassPatcher {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger("ClassPatcher");
|
||||
|
||||
private final List<AccessWidenerEntry> entries;
|
||||
|
||||
/** Pre-computed set of targeted internal names for fast filtering. */
|
||||
@@ -46,18 +50,22 @@ public class ClassPatcher {
|
||||
}
|
||||
|
||||
/**
|
||||
* Patches {@code classBytes} if {@code internalName} is targeted.
|
||||
* Patches {@code classBytes} if {@code className} is targeted.
|
||||
*
|
||||
* @return patched bytes, or {@code null} if no changes were needed
|
||||
*/
|
||||
public byte[] patch(String internalName, byte[] classBytes) {
|
||||
if (!targets.contains(internalName)) return null;
|
||||
public byte[] patch(String className, byte[] classBytes) {
|
||||
if (!targets.contains(className)) return null;
|
||||
|
||||
ClassReader cr = new ClassReader(classBytes);
|
||||
// COMPUTE_FRAMES would require the full classpath; we only touch flags so 0 is fine
|
||||
ClassWriter cw = new ClassWriter(cr, 0);
|
||||
cr.accept(new ClassTransformer(cw, internalName, entries), 0);
|
||||
return cw.toByteArray();
|
||||
try {
|
||||
ClassReader cr = new ClassReader(classBytes);
|
||||
ClassWriter cw = new ClassWriter(cr, 0);
|
||||
cr.accept(new ClassTransformer(cw, className, entries), ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
|
||||
return cw.toByteArray();
|
||||
} catch (Exception e) {
|
||||
LOG.warning("[AccessWidener] Failed to transform " + className + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user