I am generating Java code from Haxe code and I want to strip down the generated java files.
This basically means, that I want to delete specific functions from them. It is the same function from all java files.
And I want to do that everytime after I compile the Haxe files. So I need automation. I looking into sed, but I am not even sure it can be done with it. I would to find the end of the function somehow.
Or does anyone know another tool suited for this?
Get hold of one of the bytecode manipulation package, such as ASM. Read the docs and sample programs. Write a program that automates the code modification you're interested in.
Related
I am trying to develop a tool that basically analyses an Android app APK and counts the number of calls to a specific API method (e.g., android.app.AlarmManager.set())
1. What approach do you recommend?
So far I have used APKTool and now I have.smali files.
However, for the same java source, I can have multiple files:
ExportAsyncTask$1.smali
ExportAsyncTask$2.smali
ExportAsyncTask$3.smali
ExportAsyncTask$4.smali
2. What do these multiple files mean?
3. The resulting .smali files also include external libraries that I would like to leave out the analysis. How can I do that?
1. What approach do you recommend?
Yes, Apktool can be used for your task. Each java class in the APK will be represented by a .smali file in directories tree representing the packages. Smali - is the Android Virtual Machine language. The language is much simpler than Java and hence easier for analysis. In your case you should search for invoke opcodes and Landroid/app/AlarmManager;->set strings. If you are working in Linux, you can for example grep and count them. In Windows you have text editors like Notepad++ that allow text search in multiple files.
2. What do these multiple files mean?
In Java there are internal classes and implicit internal classes. The former will appear in OutherClass$InnerClass.smali and the later, having no name of its own, get numbers, like OuterClass$1.smali. You sometimes even get more deep levels like a$b$c$1.smali.
3. The resulting .smali files also include external libraries that I would like to leave out the analysis. How can I do that?
You have no precise way to do that. But generally speaking, when you look at the packages/directory tree of many samples you usually grasp the pattern. E.g. usually application code is in com.* package and android.*, org.* and uk.* include libraries. After such inspection you simply exclude those directories from your search.
I'm trying to figure out how to use Soot in an existing project (a metacircular interpreter). Specifically, I want to use Soot to convert java bytecode into a convenient 3-address code (either Jimple or Shimple) that I can interpret. I may want to do more things later, but for now I just want the conversion.
What's the best way to perform this translation? Soot seems like a ginormous project which as tons of functionality, but I really only need a single method
compileClass: Byte[] -> ShimpleClass
Preferably as pure as possible (i.e. no setup/teardown required, everything packaged within that method). I've spent hours going over the javadoc/papers/presentations, but most of them seem focused on usage as a command line tool or an eclipse plugin. Could anyone give me some pointers as to where to start?
This is probably easiest answered on the Soot mailing list.
Soot is set up to load .class files from the file system but it should not be that hard to instruct it to load something from a ByteArrayInputStream as well. I guess that should help you in your case.
I'm thinking about trying to convert a Scons (Python) script to another build system but was wondering if there was a Python-analysis library available in order to 'interrogate' the Scons/Python script?
What I'm [possibly] after is something along the lines of Java's reflection mechanism, in fact, if this is possible via say Jython/Java, coding in Java, that would be best for me as a Java dev (I have no real background in Python).
What I need to be able to do is extract the variable assigment values etc. for certain named class types and methods within the script, so that I can transfer them to my new output format.
Any ideas?
Thanks
Rich
If your current scons files are very regular and consistent it may be easier to do something "dumb" with standard text-editing tools. If you want to get smarter, you should notice that scons is itself a Python program, and it loads your build files which are also Python. So you could make your own "special" version of scons which implements the functions your build scripts use (to add programs, libraries, whatever). Then you could run your build scripts in your "fake" scons program and have your functions dump their arguments in a format suitable for your new build system.
In other words, don't think of the problem in terms of analyzing the Python grammar completely--realize that you can actually run your build scripts as Python code and hijack their behavior.
Easier said than done, I'm sure.
I doubt it's the best tool for migrating scons, but python's inspect module offers some reflection facilities. For the rest, you can simply poke inside live classes and objects: Python has some data hiding but does not enforce access restrictions.
I'm trying to write a large scale project in Java/Scala(a JVM language) that extends a preexisting program, but the problem is that the API is written in Lua.
I have found a list of websites that claim to be able to access Java from Lua and Lua from Java:
http://www.keplerproject.org/luajava/
http://code.google.com/p/jnlua/
https://www.github.com/dafrito/jna-lua
The program in which my project is extending, works by loading a certain script within a file. Instead, I want to run everything from a JVM project.
In other works: I need to be able to call functions within a Lua file that is loaded via a reflection-like system from a java project.
Has anyone done something like this before? Is it possible? Would you recommend a certain library for Java <-> Lua connection? Would you recommend an alternative?
Thank you for your time!
You might try LuaJ or Kahlua. I have used both, and they work. LuaJava works as well as jnlua. I know projects using both though I don't myself.
So you have 4 to pick from. There isn't a "best" one, each one has some pluses and minuses. It really depends on what you want to do.
I'm making an application where people can upload a java code and do stuff with it.
The application i'm making is in Python. I was wondering whether it was possible to call the 'javac' command from within python, in order to compile the uploaded java file
I'm also using JPype
http://docs.python.org/library/subprocess.html
But are you sure that allowing people to submit arbitrary code is a good idea? There are security aspects of that to consider...
Entirely possible: just use the system command and invoke the java compiler. You'll probably need to set class paths and things of that nature, but it should work fine.
EDIT: see http://docs.python.org/library/os.html#os.system and http://docs.python.org/library/subprocess.html#module-subprocess for detail on invoking sub processes. You'll probably want to capture the output to return to the user in the event of a compile error.