- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个程序,该程序采用 .class 文件并收集 .class 文件的所有方法以及每个方法的内容。这是我的代码
public class ClassReaderTest1 {
public static void main(String[] args) throws Exception{
InputStream in = new FileInputStream("*.class");
ClassReader reader = new ClassReader(in);
ClassNode classNode = new ClassNode();
reader.accept(classNode,0);
@SuppressWarnings("unchecked")
final List<MethodNode> methods = classNode.methods;
for(MethodNode m: methods){
InsnList inList = m.instructions;
System.out.println(m.name);
for(int i = 0; i< inList.size(); i++){
System.out.println(" " + Integer.toHexString(inList.get(i).getOpcode()));
}
}
}
}
这是我的输出
init>
ffffffff
ffffffff
19
b7
b1
ffffffff
main
ffffffff
ffffffff
b2
12
b6
ffffffff
ffffffff
3
36
ffffffff
ffffffff
b1
ffffffff
最终我不想打印这些值,我只是想能够在我的程序中引用它们(我试图检查我是否获得了正确的值)。我得到了预期的方法,但方法的内容对我来说没有意义。在我看来,这些不是操作码;而是操作码。特别是“ffffffff”不是java操作码。我想做的是打印出我上面所做的所有方法,然后在我现在有操作码的地方打印出java字节码,后跟几个空格,然后是操作码。例如
main
bytecode **
.
.
我加载到该程序中的文件仅包含一个 main 方法、一个 println 语句和一个 int 变量的初始化。
我的问题是我做错了什么,或者我只是没有正确解释我的结果?另外,如何获取字节码?我一直无法找到获得它的方法。当我使用eclipse的java字节码大纲插件时我可以看到它,但我需要能够在我的程序中引用它。
提前致谢
最佳答案
我自己解决了这个问题。我正在发布我的解决方案,以防其他人遇到同样的问题。请注意,在我的实现中,我没有打印出操作码(只需添加一个 println 语句即可完成此操作)。
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.StringWriter;
import java.io.PrintWriter;
import java.util.List;
import org.objectweb.asm.*;
import org.objectweb.asm.tree.*;
import org.objectweb.asm.util.*;
public class ClassReaderTest1 {
public static void main(String[] args) throws Exception{
InputStream in = new FileInputStream("*afile*");
ClassReader reader = new ClassReader(in);
ClassNode classNode = new ClassNode();
reader.accept(classNode,0);
@SuppressWarnings("unchecked")
final List<MethodNode> methods = classNode.methods;
for(MethodNode m: methods){
InsnList inList = m.instructions;
System.out.println(m.name);
for(int i = 0; i< inList.size(); i++){
System.out.print(insnToString(inList.get(i)));
}
}
}
public static String insnToString(AbstractInsnNode insn){
insn.accept(mp);
StringWriter sw = new StringWriter();
printer.print(new PrintWriter(sw));
printer.getText().clear();
return sw.toString();
}
private static Printer printer = new Textifier();
private static TraceMethodVisitor mp = new TraceMethodVisitor(printer);
}
这是生成的输出
<init>
L0
LINENUMBER 1 L0
ALOAD 0
INVOKESPECIAL java/lang/Object.<init> ()V
RETURN
L1
main
L2
LINENUMBER 3 L2
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
LDC "Hello World!!!"
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
L3
LINENUMBER 4 L3
ICONST_0
ISTORE 1
L4
LINENUMBER 5 L4
RETURN
L5
关于java - ASM : outputting java bytecode and opcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19152526/
我有一个递归函数 emit : Map -> exp -> unit哪里il : ILGenerator对函数来说是全局的,并且 exp是一个判别联合,表示带有大小写 InstanceCall of
我正在使用 ASM 框架进行 java 字节码操作。 ASM中出现两次的一些操作码助记符,它们以“H_”为前缀: Opcodes.H_GETFIELD vs. Opcodes.GETF
谁能告诉我以下段错误究竟意味着什么? Unhandled dwarf expression opcode 0x93 它在solaris 10 i386上。 任何建议表示赞赏。 最佳答案 如果您的 GD
在构建芯片 8 仿真器时,我遇到了芯片 8 信息的 2 个主要来源似乎不同的问题,这对整个芯片 8 解释器有影响。 一方面,我们有 wikipedia , 在操作码 FX65 下告诉我们 “用从地址
在intel software developers manual volumen 2A chapter 2.1.2说 Two-byte opcode formats for general-purp
.NET Framework 4.0 向 Reflection API 引入了多项内容,这些内容对我的工作从极其有用到至关重要。其中包括 Assembly、Module、MethodBody 和 Lo
我正在使用 Kony Studio 开发应用程序。我已经使用 Eclipse 完成了登录验证,以编写用于创建 Web 服务以连接到 oracle10g 数据库的代码。但是在前端,当我尝试将前端连接到
当您在堆栈顶部引用 (B) 的实例时,是否有必要发出 OpCode.CastClass(typeof(A)),其中 B 是派生自 A 的类,当准备调用方法时类型 A 的参数? 添加: interfac
如果我有一个 lua 脚本,比如 print("Hello, world!") 我如何获得与之等效的指令或操作码? (用于 luaV_execute) 最佳答案 您几乎不需要对 Lua 的解释器做一个
我们的计算机体系结构教授给了我们一个示例程序,要求输入密码。任务是在比较输入的密码并决定是否正确后更改跳转操作码。我编写了一个程序,可以更改给定二进制文件中特定位置的任何字节。 这是密码程序的代码:
我有一个包含以下代码的汇编程序。 这段代码对于英特尔处理器来说编译得很好。但是,当我使用 PPC(交叉)编译器时,我收到一个错误,提示无法识别操作码。我试图找出是否有 PPC 架构的等效操作码。 .f
这可能是一个非常奇怪的问题,但我一直在小人电脑上做一些工作,这让我有点恼火,不仅没有操作代码 4,而且互联网上也绝对没有关于为什么。 操作码从 0 到 9 但跳过 4。从来没有任何以 4 开头的三位数
我正在阅读Go源代码,就像读过一样,当我阅读fastrand()函数时(对于我的机器,该函数位于asm_amd64.s文件中),我遇到了以下片段: XORL $0x88888eef, D
我设置了一个简单的 Geth (v1.10.2-stable-97d11b01) 专用网络(下面的 genesis.json 配置)。我编译并部署了这个简单的测试合约(solidity版本:0.8.4
我对此很陌生。我试图以清晰的方式理解上述术语之间的区别,但是,我仍然感到困惑。这是我发现的: 在计算机汇编语言中,助记符是操作的缩写。它被输入到每个汇编程序指令的操作码字段中。例如 AND AC,37
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我正在尝试为属性生成动态代理。 生成的代理源 self 们要代理的类型。当代理需要访问其派生类型的(虚拟)属性时,不能使用 OpCodes.Callvirt - 它会导致无限递归。因此我们需要调用Op
有什么办法可以改变OpCodes.Ret跳转到的地址吗? IL 中的方法可以更改 C# 使用的调用堆栈吗? 据我所知,在 C++ 中,您可以访问堆栈上的值并更改返回地址等。在 IL 中,除了“Inva
我已经在我的 linuxbox 上安装了 Zend OpCache。我使用以下命令安装扩展: sudo pecl install zendopcache-7.0.2 现在,无需修改我的 php.ini
许多框架利用 spl_autoload_register() 来动态加载类(即 Controller 和模型)。有几篇关于自动加载和操作码缓存问题的帖子。特别是一篇帖子有@cletus 的回复,其中引
我是一名优秀的程序员,十分优秀!