bytecode

Is it possible to have the System ClassLoader load .class files specified at run time?

三世轮回 提交于 2019-11-30 15:25:14
I am writing a static analysis tool for an assignment, it analyses Java bytecode using the ASM library. One of the parts of ASM that we use requires (or at least, appears to require) that the class be loaded from the ClassLoader. We were hoping the tool would be able to analyse .class files without requiring them on the classpath. We already load the .classes from a specified directory at run time and read them in using an InputStream. This is acceptable for ASM in most cases. There are some classes, such as SimpleVerifier , which attempt to load the classes though. Is it possible, under this

What CLR/.NET bytecode tools exist? [closed]

余生颓废 提交于 2019-11-30 15:12:30
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm well aware of Java tools for manipulating, generating, decompiling JVM bytecode (ASM, cglib, jad, etc). What similar tools exist for the CLR bytecode? Do people do bytecode manipulation for the CLR? 回答1: Bytecode is a binary format. .NET assemblies work pretty different in terms of how they store the

Given a python .pyc file, is there a tool that let me view the bytecode?

谁说我不能喝 提交于 2019-11-30 12:17:30
问题 A Python module is automatically compiled into a .pyc file by CPython interpreter. The .pyc file, which contains the bytecode, is in binary format (marshaled code?). Is there a GUI (or command line) tool that let me view the bytecode? 回答1: There's a visual python disassembler called PyChrisanthemum. To do it the command-line way you can use module dis (python 2.7.3, python 3.2.3), as OP already found out. 回答2: Every *.pyc file is a binary file containing next things: a four-byte magic number

How to generate a module object from a code object in Python

女生的网名这么多〃 提交于 2019-11-30 12:11:02
问题 Given that I have the code object for a module, how do I get the corresponding module object? It looks like moduleNames = {}; exec code in moduleNames does something very close to what I want. It returns the globals declared in the module into a dictionary. But if I want the actual module object, how do I get it? EDIT: It looks like you can roll your own module object. The module type isn't conveniently documented, but you can do something like this: import sys module = sys.__class__ del sys

Identify loops in java byte code

孤街浪徒 提交于 2019-11-30 10:40:08
问题 I am trying to instrument java byte code. I want to recognize the entry and exit of a java loop , but I have found the identification of loops to be quite challenging. I have spent a good few hours looking at ASM and open source de-compilers (whom I thought must solve this problem all the time), however, I came up short. The tool I am augmenting / extending, is using ASM, so ideally I would like to know how to instrument the entry and exit of the different loop constructs in java via ASM .

Is list join really faster than string concatenation in python?

微笑、不失礼 提交于 2019-11-30 09:18:50
问题 I find that string concatenation seems to have less python bytecode than list join. This is an example. test.py: a = ''.join(['a', 'b', 'c']) b = 'a' + 'b' + 'c' Then I execute python -m dis test.py . I got the following python bytecode (python 2.7): 1 0 LOAD_CONST 0 ('') 3 LOAD_ATTR 0 (join) 6 LOAD_CONST 1 ('a') 9 LOAD_CONST 2 ('b') 12 LOAD_CONST 3 ('c') 15 BUILD_LIST 3 18 CALL_FUNCTION 1 21 STORE_NAME 1 (a) 3 24 LOAD_CONST 6 ('abc') 27 STORE_NAME 2 (b) 30 LOAD_CONST 4 (None) 33 RETURN_VALUE

Load Java-Byte-Code at Runtime

放肆的年华 提交于 2019-11-30 09:18:06
I got some java-byte-code (so compiled java-source) which is generated in my program. Now I want to load this byte-code into the currently running Java-VM and run a specific function. I'm not sure how to accomplish this, I digged a little bit into the Java Classloaders but found no straight way. I found a solution which takes a class-file on the harddisk, but the bytecode I got is in a Byte-Array and I dont want to write it down to the disk but use it directly instead. Thanks! Nikolaus Gradwohl you need to write a custom class loader that overloads the findClass method public Class findClass

Python: LOAD_FAST vs. LOAD_DEREF with inplace addition

南楼画角 提交于 2019-11-30 09:15:38
Last Friday I went to a job interview and had to answer the following question: why does this code raise an exception ( UnboundLocalError: local variable 'var' referenced before assignment on the line containing var += 1 )? def outer(): var = 1 def inner(): var += 1 return var return inner I couldn't give a proper answer; this fact really upset me, and when I came home I tried really hard to find a proper answer. Well, I have found the answer, but now there's something else that confuses me. I have to say in advance that my question is more about the decisions made when designing the language,

Generating a 'Hello, World!' class with the Java ASM library

余生颓废 提交于 2019-11-30 09:15:10
I have started messing around with the ASM API for a compiler project I am working on. However, I am finding that the documentation is less than clear for a newcomer in many places and I thought having a good solid example of generating a class that simply prints "Hello, World!" would be a great example to have on here. Currently, I can generate a class with a main() (using the ClassWriter, ClassVisitor and MethodVisitor classes) but I can't seem to work out how to generate main's body. Could anyone give me an example of generating a class file in ASM that: contains a main() creates a local

Programmatically inspect .class files

前提是你 提交于 2019-11-30 08:43:17
I'm working on a project where we're doing a lot of remote object transfer between a Java service and clients written in other various languages. Given our current constraints I've decided to see what it would take to generate code based on an existing Java class. Basically I need to take a .class file (or a collection of them) parse the bytecode to determine all of the data members and perhaps getters/setters and then write something that can output code in a different language to create a class with the same structure. I'm not looking for standard decompilers such as JAD. I need to be able