Java agent throws UnsupportedClassVersionError when Instrumentation#retransformClasses is called.
I need to dump who invokes a
setCancelled(boolean cancelled)
method in a running jar (Spigot 1.8). I decided to do this via dumping the caller using StackWalker
by using a javaagent to add a method call which dumps the caller, the item
field which is of type org.bukkit.inventory.ItemStack
, & the cancelled
argument. The only issue currently, is that when i call retransformClasses
the whole thing comes burning down.
Target class: org.bukkit.event.player.PlayerInteractEvent
The agent is compiled under Java 17.0.12
the JVM is 17.0.12
The spigot jar is java 8 (i think)
Ran via the -javaagent
command line option53 Replies
ā
This post has been reserved for your question.
Hey @cire! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Transformer:
Only ran on target class obviously
Can you show the stack trace?
Stacktrace:
Are you ure you are running it with java 17?
How exactly are you running the application?
yep
javaw -javaagent:path/to/java/agent spigot-1.8.8.jar [server options here]
ASM version 9.6
btw
Does
javaw -version
show you any output?nvm, im actually running
java -javaagent:path/to/agent -Xmx1G -Xms1G -jar spigot-1.8.8.jar
java --version is
openjdk 17.0.12Can you set the bytecode version with
ClassWriter
?i don't think so
but im new to asm
Where are you adding the instructions to the
classWriter
?Adding to the
classNode
which affects the classwriteroh i forgot
cn.accept(cw)
brb i'll test
if that fixesWhen compiling Java applications to
.class
files, javac
adds an integer representing the version it has been compiled for to the class file.
Each Java version has a class file (major) version associated with it. A list with Java versions and the matching class file major version numbers can be found in this Stack Overflow question.
In order to use a class, the JVM must be of a newer or equal version to the one specified in the class file.try
cn.version = 52
before the cn.accept(cw)
got it
should i bother with minor version?
no
i dont think jdk cares
k
though maybe you need some bit magic
oh yeah its like 16 msb is minor and 16 lsb is major right
I think it might be ok just using 52 might be the less significant part
š¤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
Okay, i downgraded to JVM 1.8
to access sun.reflect
If you are using Java 8 to run it, your agent needs to be compiled with that as well
Why do you need that?
yup i changed my gradle
#getCallerClass
my vm that needs the debugging runs jvm8 so StackWalker doesn't exist
?
If the target uses Java 8 then you'd need to compile your agent with java 8 anyways, yes
i need to figure out whats calling the
setCancelled
method
yup agent is now built with jvm8Can't you just set a breakpoint?
3rd party jar on a vm
not really
What about just getting/printing the stack trace?
im waiting for the vm to shutdown the server and reboot with new agent
You can still do that
i heavily dislike bytecode, getCallerClass is the easiest with bytecode
huh
You can attach a debugger and set breakpoints even for code that isn't yours
as long as you can control the JVM in question
ill take a look at that
thanks
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
buh
š
What does it have to do with that?
i have to write the dumping in bytecode
It's pretty much
new Exception("THIS IS INSERTED FOR DEBUGGING").printStackTrace()
ohhhhhh
shit
and you can do the same in bytecode
wait
i'm stupid
š
or you could use
Thread.getStackTrace()
to get the current stack trace as a StackTraceElement[]
i dont even need to printStackTrace
i can just throw the exception and check console
omg im stupid
or that but that has a significant side effect
but as I said, there's also the option of attaching a debugger and setting a breakpoint
i'm only running this for debugging to figure out which plugin is cancelling the event
i think i'll just throw an exception if
cancelled
param is true
and check logsNote that the code calling the method could catch the exception
š¤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.