本文整理汇总了Java中org.objectweb.asm.ClassReader.accept方法的典型用法代码示例。如果您正苦于以下问题:Java ClassReader.accept方法的具体用法?Java ClassReader.accept怎么用?Java ClassReader.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.ClassReader
的用法示例。
在下文中一共展示了ClassReader.accept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readClassAsEntry
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private static Map<String, Set<String>> readClassAsEntry(InputStream input) {
HashMap<String, Set<String>> map = new HashMap<>();
try {
ClassReader reader = new ClassReader(input);
String className = reader.getClassName().replace('/', '.');
reader.accept(new ClassVisitor(Opcodes.ASM6) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
String methodName = className + '.' + name;
map.computeIfAbsent(methodName, __ -> new HashSet<>()).add(methodName + desc);
return null;
}
}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG);
} catch(IOException e) {
throw new UncheckedIOException(e);
}
return map;
}
示例2: checkAnnotationContent
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private void checkAnnotationContent(Path inputPath, Path outputPath)
throws IOException, ExecutionException {
ClassReader classReader = new ClassReader(new FileInputStream(inputPath.toFile()));
ReadSourceDebugExtensionAttribute sourceDebugExtensionReader =
new ReadSourceDebugExtensionAttribute(Opcodes.ASM5, null);
classReader.accept(sourceDebugExtensionReader, 0);
DexInspector dexInspector =
new DexInspector(outputPath.resolve("classes.dex"), getGeneratedProguardMap());
ClassSubject classSubject = dexInspector.clazz("HelloKt");
AnnotationSubject annotationSubject =
classSubject.annotation("dalvik.annotation.SourceDebugExtension");
Assert.assertTrue(annotationSubject.isPresent());
DexAnnotationElement[] annotationElement = annotationSubject.getAnnotation().elements;
Assert.assertNotNull(annotationElement);
Assert.assertTrue(annotationElement.length == 1);
Assert.assertEquals("value", annotationElement[0].name.toString());
Assert.assertTrue(annotationElement[0].value instanceof DexValueString);
Assert.assertEquals(
sourceDebugExtensionReader.debugSourceExtension,
((DexValueString) annotationElement[0].value).value.toSourceString());
}
示例3: readJar
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
public static Map<String, ClassNode> readJar(JarFile file, boolean skipDebug) throws IOException {
Map<String, ClassNode> classes = new HashMap<>();
Enumeration<JarEntry> entries = file.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String name = entry.getName();
if (name.endsWith(".class")) {
try (InputStream inputStream = file.getInputStream(entry)) {
ClassReader reader = new ClassReader(inputStream);
ClassNode node = new ClassNode();
reader.accept(node, (skipDebug ? ClassReader.SKIP_DEBUG : 0) | ClassReader.SKIP_FRAMES);
classes.put(node.name, node);
}
}
}
return classes;
}
示例4: analyzeClassesForLocalDeadCode
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void analyzeClassesForLocalDeadCode(String dir, Set<String> classesToVisit)
throws IOException, XMLStreamException {
for (final String className : classesToVisit) {
if (isInterrupted()) {
break;
}
// les classes *SoapBindingStub générées par Apache Axis
// contiennent beaucoup des variables locales non utilisées,
// mais il est inutile de le signaler puisque c'est généré par Axis
if (!className.endsWith("SoapBindingStub")) {
final ClassNode classNode = new ClassNode();
final ClassReader classReader = createClassReader(dir, className);
classReader.accept(classNode, ClassReader.EXPAND_FRAMES);
for (final MethodNode methodNode : (List<MethodNode>) classNode.methods) {
analyzeMethodForLocalDeadCode(dir, className, classNode, methodNode);
analyzeMethodForSelfAssignments(className, methodNode);
if (Factory.createStringToStringAnalyzer(methodNode).analyze()) {
report.reportStringToString(className, methodNode);
suspectCount++;
}
}
}
}
}
示例5: generateTests
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private void generateTests() throws IOException {
ClassReader cr = new ClassReader(new FileInputStream(classNamePath.toFile()));
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cr.accept(
new ClassVisitor(Opcodes.ASM5, cw) {
@Override
public void visitEnd() {
generateMethodTest1(cw);
generateMethodTest2(cw);
generateMethodTest3(cw);
generateMethodTest4(cw);
generateMethodTest5(cw);
generateMethodTest6(cw);
generateMethodTest7(cw);
generateMethodTest8(cw);
generateMethodTest9(cw);
generateMethodTest10(cw);
generateMethodTest11(cw);
generateMethodTest12(cw);
generateMethodTest13(cw);
generateMethodMain(cw);
super.visitEnd();
}
}, 0);
new FileOutputStream(classNamePath.toFile()).write(cw.toByteArray());
}
示例6: process
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private static void process(File jarFile, File outputFile, String message) throws Throwable {
ZipFile zipFile = new ZipFile(jarFile);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
try {
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
try (InputStream in = zipFile.getInputStream(entry)) {
ClassReader cr = new ClassReader(in);
ClassNode classNode = new ClassNode();
cr.accept(classNode, 0);
messageInjector(classNode, message);
ClassWriter cw = new ClassWriter(0);
classNode.accept(cw);
ZipEntry newEntry = new ZipEntry(entry.getName());
newEntry.setTime(System.currentTimeMillis());
out.putNextEntry(newEntry);
writeToFile(out, new ByteArrayInputStream(cw.toByteArray()));
}
} else {
entry.setTime(System.currentTimeMillis());
out.putNextEntry(entry);
writeToFile(out, zipFile.getInputStream(entry));
}
}
} finally {
zipFile.close();
out.close();
if (!messagegotinjected) {
// throw new IllegalStateException("Could not find Bukkit onEnable or onLoad method.");
throw new IllegalStateException("Could not find Bukkit onEnable method.");
}
}
}
示例7: extractApiClassFrom
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
/**
* Extracts an API class from a given original class.
*
* @param originalClassReader the reader containing the original class
* @return bytecode of the API class extracted from the original class
*/
public byte[] extractApiClassFrom(ClassReader originalClassReader) {
ClassWriter apiClassWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
originalClassReader.accept(
new ApiMemberSelector(new MethodStubbingApiMemberAdapter(apiClassWriter), apiIncludesPackagePrivateMembers),
ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return apiClassWriter.toByteArray();
}
示例8: transform
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private static byte[] transform(byte[] serverClass, boolean isObfuscated, transformType type)
{
System.out.println("MALMO: Attempting to transform MinecraftServer");
try
{
ClassNode cnode = new ClassNode();
ClassReader creader = new ClassReader(serverClass);
creader.accept(cnode, 0);
switch (type)
{
case SERVER:
overclockServer(cnode, isObfuscated);
break;
case RENDERER:
overclockRenderer(cnode, isObfuscated);
break;
}
ClassWriter cwriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cnode.accept(cwriter);
return cwriter.toByteArray();
}
catch (Exception e)
{
System.out.println("MALMO FAILED to transform MinecraftServer - overclocking not available!");
}
return serverClass;
}
示例9: load
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
@Override
public Map<String, ClassNode> load() throws IOException {
Map<String, ClassNode> clses = new HashMap<String, ClassNode>();
for (String name : classes.keySet()) {
ClassNode node = new ClassNode();
ClassReader reader = new ClassReader(classes.get(name));
reader.accept(node, ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
clses.put(node.name.replace(".class", ""), node);
}
return clses;
}
示例10: getFieldType
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private String getFieldType(String owner, String name)
{
if (fieldDescriptions.containsKey(owner))
{
return fieldDescriptions.get(owner).get(name);
}
synchronized (fieldDescriptions)
{
try
{
byte[] classBytes = ClassPatchManager.INSTANCE.getPatchedResource(owner, map(owner).replace('/', '.'), classLoader);
if (classBytes == null)
{
return null;
}
ClassReader cr = new ClassReader(classBytes);
ClassNode classNode = new ClassNode();
cr.accept(classNode, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
Map<String,String> resMap = Maps.newHashMap();
for (FieldNode fieldNode : classNode.fields) {
resMap.put(fieldNode.name, fieldNode.desc);
}
fieldDescriptions.put(owner, resMap);
return resMap.get(name);
}
catch (IOException e)
{
FMLRelaunchLog.log(Level.ERROR,e, "A critical exception occurred reading a class file %s", owner);
}
return null;
}
}
示例11: readClass
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
static ClassNode readClass(Path path) {
try {
ClassReader reader = new ClassReader(Files.readAllBytes(path));
ClassNode cn = new ClassNode();
reader.accept(cn, ClassReader.EXPAND_FRAMES);
return cn;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例12: apply
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
@Override
public byte[] apply(byte[] origin) {
ClassReader reader = new ClassReader(origin);
PredicateClassVisitor precondition = new PredicateClassVisitor();
reader.accept(precondition, SKIP_DEBUG | SKIP_FRAMES);
if (!precondition.isAttemptToVisitR()) {
return origin;
}
// don't pass reader to the writer.
// or it will copy 'CONSTANT POOL' that contains no used entries to lead proguard running failed!
ClassWriter writer = new ClassWriter(0);
ClassVisitor visitor = new ShrinkRClassVisitor(writer, rSymbols);
reader.accept(visitor, 0);
return writer.toByteArray();
}
示例13: transform
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if(!name.equals(authClassNameObf) && !name.equals(authClassNameDeobf)) return bytes;
ClassNode clazz = new ClassNode();
ClassReader reader = new ClassReader(bytes);
reader.accept(clazz, 0);
boolean patched = false;
for(MethodNode method : clazz.methods) {
String mn = method.name;
if(!mn.equals(acceptMethodNameSrg)) {
if(!mn.equals(acceptMethodNameObf) && !mn.equals(acceptMethodNameDeobf)) continue;
if(!method.desc.equals(acceptMethodDesc)) continue;
}
for(int i = 0; i < method.instructions.size(); i++) {
AbstractInsnNode node = method.instructions.get(i);
if(node instanceof LabelNode) {
patchMethod(clazz, method, (LabelNode)node);
patched = true;
break;
}
}
}
if(!patched) return bytes;
ClassWriter writer = new ClassWriter(0);
clazz.accept(writer);
return writer.toByteArray();
}
示例14: verify
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
/**
* Checks a given class.
*
* @param cr
* a <code>ClassReader</code> that contains bytecode for the
* analysis.
* @param loader
* a <code>ClassLoader</code> which will be used to load
* referenced classes. This is useful if you are verifiying
* multiple interdependent classes.
* @param dump
* true if bytecode should be printed out not only when errors
* are found.
* @param pw
* write where results going to be printed
*/
public static void verify(final ClassReader cr, final ClassLoader loader,
final boolean dump, final PrintWriter pw) {
ClassNode cn = new ClassNode();
cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
Type syperType = cn.superName == null ? null : Type
.getObjectType(cn.superName);
List<MethodNode> methods = cn.methods;
List<Type> interfaces = new ArrayList<Type>();
for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
interfaces.add(Type.getObjectType(i.next()));
}
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = methods.get(i);
SimpleVerifier verifier = new SimpleVerifier(
Type.getObjectType(cn.name), syperType, interfaces,
(cn.access & Opcodes.ACC_INTERFACE) != 0);
Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
if (loader != null) {
verifier.setClassLoader(loader);
}
try {
a.analyze(cn.name, method);
if (!dump) {
continue;
}
} catch (Exception e) {
e.printStackTrace(pw);
}
printAnalyzerResult(method, a, pw);
}
pw.flush();
}
示例15: analyzeClasses
import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private void analyzeClasses(String dir, Set<String> classesToVisit) throws IOException {
final ClassVisitor classVisitor = Factory
.createCallersClassVisitor(result.createCallersMethodVisitor());
for (final String className : classesToVisit) {
if (isInterrupted()) {
break;
}
final ClassReader classReader = createClassReader(dir, className);
classReader.accept(classVisitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
}
}