bcel

How to verify Java Bytecode before injecting into the JVM?

孤人 提交于 2021-02-19 07:27:47
问题 I'm trying to verify "on the fly" generated bytecode! I already had several attempts, one attempt was to compile my classes in runtime with the eclipse compiler another was to compile from memory as mentioned here: Compile From Memory First results looked okay but I'm still not a 100% sure if the verification process is truly valid according to the JAVA 6 guidelines and security measurements as well to normal OOP Models. Any better way on how to verify bytecode? 回答1: If you load the generated

破旧立新,精准测试之道

与世无争的帅哥 提交于 2020-11-25 13:43:38
前言 第一次听到精准测试是在几年前了,那一瞬间就对这个流派充满了好奇和探索的欲望,最近几年逐渐得到了各领域各行业中测试人员的广泛关注,那么问题来了: 什么是精准测试; 精准测试的意义和价值在哪里; 精准测试整体方案如何落地; 传统测试的痛点 测试效率低下 常规的测试类型包括功能测试、回归测试、自动化测试、接口测试等,非常依赖于测试人员的测试经验,基于人工主观分析的黑盒测试,借助常规的用例设计方法来确保产品质量。 根据收益递减规律,虽然大量的人力投入,不断的执行测试,但是漏测率还是居高不下。中间的无效测试和重复测试也浪费了大量的测试成本。 测试范围无法评估 多分支代码合并到主分支,修改哪个文件哪个行,测试不可控; 代码更新影响哪些功能无感知; 大部分的测试还是基于对业务的理解,与真实业务数据还有差距,准确性难以保证,盲测,风险大; 测试过程中的质量标准无法衡量 怎么样判定测试完成,怎么样判定测的怎么样?质量控制贯穿于整个质量保障流程。 用例执行完成; 探索性测试完成; 开发人员缺陷修复完成; 回归测试完成; 自动化执行通过; 上述步骤完成意味着我们的产品质量是合格的吗? 上线之后的非一致性成本逐渐增高,测试过程没有数据量化的评定,无法衡量,只能依赖线上缺陷率,线下缺陷数,千行缺陷率等比较飘的指标来评定,测试管理难度大。 敏捷模式和分布式微服务架构下的挑战 迭代周期短

Parse Jar file and find relationships between classes?

微笑、不失礼 提交于 2020-01-11 11:34:09
问题 How to detect whether the class from the jar file is extending other class or if there are method calls to other class objects or other class objects are created ? and then system out which class extend which class and which class called methods from which class . Im using Classparser to parser the jar . here is part of my code : String jarfile = "C:\\Users\\OOOO\\Desktop\\Sample.Jar"; jar = new JarFile(jarfile); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements())

how to create java file programmatically

梦想的初衷 提交于 2020-01-06 08:05:40
问题 I am creating a util-class which writes .java Files that act as coverter - generator. This util-class will generate AConverter.java' (refer below sample) I want know how to write the util-class. I googled, and found the recommendation to use apache bcel. But I couldn't find an example to write the .java File from a String and have it working in my program. The expectation is... class ADTO { private String empId; private String empName; private String dept; //setters and getters } class ABO {

Dynamically editing/creating classes in Java Android

喜欢而已 提交于 2020-01-04 06:19:21
问题 I am looking for a way to dynamically define classes and instantiate them in Android, at runtime. From my understanding, this is already done in Android, I just need some help figuring it out. I can a similiar result in Javascript and PHP. I know it can be done in Java using something like ASM, BCEL or CGlib. However, I do not know enough about any of these to understand if they will work on Android. Or, of they will work, what are the implications? If, hypothetically, all three will work in

Java find out what imports a .class has [duplicate]

二次信任 提交于 2019-12-25 05:14:25
问题 This question already has answers here : How to get all imports defined in a class using java reflection? (3 answers) Closed 2 years ago . Is there a way to find out what imports a class has? In this question: Jon Skeet says that you can't do this using reflection, but If you want to find all the types used within the compiled code, that's a slightly different matter. You may want to look at BCEL as a way of analyzing bytecode. This is what I want to know how to do. 回答1: Here is an old

Static initializers in bcel

若如初见. 提交于 2019-12-24 05:56:24
问题 In BCEL, I would like to initialize static fields in the static initializer of a class. I haven't found a way to do so however... any hints? I need something like: // Field descriptor #8 [I private static int[] a; static {}; 0 bipush 10 2 multianewarray int[] [9] 6 putstatic Output.a : int[] [11] 9 return I however only seem to be able to generate (with MethodGen ) things like: public static void {}(); 0 bipush 10 2 multianewarray int[] [9] 6 putstatic Output.a : int[] [11] 9 return Which is

Adding a field to Java class

只愿长相守 提交于 2019-12-23 19:19:07
问题 Looked at using CGLib, ASM, BCEL (aspect) and Javassist to add a field to a class during runtime.... Just to get my head straight it looks like these bytecode manipulators don't update the actual class rather allow the user to only dump the modification (like with CGLib and the writeFile method). Was hoping I would find a solution that (a) loaded the class (rather than doing an InputStream with BCEL) and (b) updated the class. Maybe this is normal? Do people usually create a proxy and pass

JVM性能优化--字节码技术

杀马特。学长 韩版系。学妹 提交于 2019-12-18 09:11:32
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一、字节码技术应用场景 AOP技术、Lombok去除重复代码插件、动态修改class文件等 二、字节技术优势 Java字节码增强指的是在Java字节码生成之后,对其进行修改,增强其功能,这种方式相当于对应用程序的二进制文件进行修改。Java字节码增强主要是为了减少冗余代码,提高性能等。 实现字节码增强的主要步骤为: 1、修改字节码 在内存中获取到原来的字节码,然后通过一些工具(如 ASM,Javaasist)来修改它的byte[]数组,得到一个新的byte数组。 2、使修改后的字节码生效 有两种方法: 1) 自定义ClassLoader来加载修改后的字节码; 2)替换掉原来的字节码:在JVM加载用户的Class时,拦截,返回修改后的字节码;或者在运行时,使用Instrumentation.redefineClasses方法来替换掉原来的字节码 三、常见的字节码操作类库 1、BCEL Byte Code Engineering Library(BCEL),这是Apache Software Foundation的Jakarta项目的一部分。BCEL是Java classworking 广泛使用的一种框架,它可以让您深入jvm汇编语言进行类库操作的细节。BCEL与javassist有不同的处理字节码方法

Ant loadproperties failed (bcel error?)

Deadly 提交于 2019-12-12 10:39:42
问题 I'm working on a simple build script that should get some constants from a java class file and use them as the version numbers in my file names. I use Eclipse and its own Ant, but put bcel-5.2.jar in my libs folder and into the classpath for the Ant call. <target name="generate_version" depends="compile"> <loadproperties srcfile="${dir.dest}/MyVersion.class"> <classpath> <fileset dir="${dir.libs}"> <include name="**/bcel*.jar"/> </fileset> </classpath> <filterchain> <classconstants/> <