I want to print out all methods that get called during runtime. They should be printed out in the order that they're called in and if they're called multiple times, they should be printed multiple times.
This can be used for reverse engineering - seeing which functions get called when you press a button or do a specific action.
I want to use Java agents and instrumentation for this.
This can be done using Java Agents and an instrumentation library.
Java agent - Separate code that can be made to run before the main part of the code.
Instrumentation - Changing the source code during the load-time of a program.
Code for making it work
(taken from appcrawler and modified slightly):
The agent.jar source code:
SimpleTransformer.java:
SimpleMain.java:
MANIFEST.mf:
Take these files and package them into a jar file. Also make sure to include files from javassist.jar (downloadable from www.javassist.org) and tools.jar (found in Program Files/Java/jdk/lib/). Not sure if the second one is necessary, but the article says it is for some reason.
Now you can use this jar file as a java agent.
And voila. The java agent will instrument all methods and print out every method called during execution.