-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7439: Introduced IConstantPoolExtension for Constant Pools #333
Conversation
👋 Welcome back jpbempel! A progress list of the required criteria for merging this PR into |
Webrevs
|
Add extension methods when constants are read, referenced, resolved and constant pools fully resolved to be able for example: * track constant pool usage inside events * replace or translate symbols, method names, etc... like de-obfuscations of stack traces
1ef4e5b
to
d2d44de
Compare
* | ||
* @return an instance implementing IConstantPoolExtension | ||
*/ | ||
default IConstantPoolExtension createConstantPoolExtension() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we might as well make the other methods default too?
default String getValueInterpretation(String eventTypeId, String fieldId) {
return null;
}
default IEventSinkFactory getEventSinkFactory(IEventSinkFactory subFactory) {
return subFactory;
}
Hi, I wanted to test this PR but are still unsure with Eclipse setup/usage. I managed to check out the PR in my fork (what a GitHub Desktop magic :-) ). The project builds and I can run JMC. Can you help me with this basic setup question? And sorry for beeing OT here. I can later delete this message again. |
Rather than starting with the unit test, I added the MyConstantPoolExtension from to test to the FlightRecordingLoader.loadStream() (only for testing of course). I added breakpoints to all methods of the MyConstantPoolExtension class and loaded a recording (recorded from our company developed app). All methods were executed a lot times as expected. I expected to see my own class or packages names sooner or later, but I only saw JDK internal names. So I probably didn't got the idea. Can you help? I pushed the change to my fork FYI. |
I would avoid cherry picking changes to other forks when reviewing. Your commit in your fork shows one changed file with 80 additions and 1 deletion. This PR has 8 changed files. It is much easier to simply clone JPs fork, and switch to the branch with his changes. |
I haven't CPed anything. Look at my commit history - it contains the changes from jpbempel - even if I did it differently than you propsed. |
FYI, I am reworking the PR to match better with my needs and the dependencies |
- getId - eventsLoaded - getItemCollection to expose data gathered and exposed in IParserStats all ConstantPool extensions
Back to the tests - this time with the JPs clone and branch "pool-extension". I realized that in my Eclipse setup the ConstantPoolExtensionTest class doesn't get compiled unless I do a
Regarding the PR, I have the same test result as last time. I just can't seenany of my own classes in the Parsewr Extension callbacks when I replaced the test JFR file with my own. As I said, I probably didn't got the idea. I would suggest that you provide a test JFR file with a custom class like fr.jpbempel.HelloWorld and demonstrate in the test how to get it. |
hello @docwarems when using the callback: Object constantRead(long constantIndex, Object constant, String eventTypeId) {
return constant;
} you should look at constant argument that should be what you would like to de-obfuscate and return a translated value instead of the original one: Object constantRead(long constantIndex, Object constant, String eventTypeId) {
return deobfuscate(constant);
} |
|
||
import org.openjdk.jmc.common.collection.FastAccessNumberMap; | ||
import org.openjdk.jmc.common.item.IAttribute; | ||
import org.openjdk.jmc.common.item.IItem; | ||
import org.openjdk.jmc.common.unit.ContentType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, right?
@@ -39,6 +39,7 @@ | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Maps, not Sets - not needed.
Yeah, that's more or less what I expected. Maybe I'm unable to find my constant of interest in the mass of other classes. Could you provide a breakpoint condition for the breakpoint condition shown below which would stop at a class "fr.jpbempel.HelloWorld"? |
Hey, @docwarems I have created a custom event: package com.bempel.events;
import jdk.jfr.Event;
import jdk.jfr.Label;
import jdk.jfr.Name;
@Name("com.bempel.events.MyEvent")
@Label("MyEvent")
public class MyEvent extends Event {
@Label("message")
public String message;
} I have used like this: MyEvent myEvent = new MyEvent();
myEvent.message = "showVetList " + uuid;
myEvent.commit(); I have recording with this event in it: You can look at constant pools : in debugging ConstantPoolExtensionTest: But it's a little bit complex because: That's why it may have more sense to look for the symbol constant instead of directly the class constant. |
Hello @jpbempel, the breakpoint condition was the breakthrough - I just wasn't able to catch the desired constant before. Even with the simplest HelloWork console program I ended up with a JFR file where I wasn't able to step through all constants in a reasonable time and find my desired constant. Next I should be able to take my deobfuscator remapping code and build a true extension. I'll come back then. Regarding the PR review, I wonder if you want to wait for my further work, or if you prefer to merge. |
It would be nice to have your feedback on this, because I came back a lot on the design to implement my needs. So depending on yours, we may revisit some parts... |
One last nit for this PR - can you please check the files for unnecessary imports? I'll add an issue for ensuring that this is done automatically. |
@jpbempel I will not find enough time to continue before my holidays starting in mid December. It's better than one hour this day, one hour another day. |
@jpbempel This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 24 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Hi @jpbempel - you can now integrate this PR. :) |
/integrate |
Going to push as commit d4449ce.
Your commit was automatically rebased without conflicts. |
The PR is merged, but I've resumed my tests and are in the middle of adapting my de-obfuscation code to the new extension mechanism. |
@jpbempel as assumed doing the deobfuscation using the IConstantPoolExtension is much more complicated than as I did it previously because it modifies internal state. I'm facing follow-up exceptions and have been trying for a while to sort them out. But I am clueless now. Do you have any more hint? Otherwise I would push my current code to my fork and post the link here. If you can help I will continue, otherwise I'll have to stay with my existing solution doing the deobfuscation on formatting level, which is just fine for our purpose. |
@jpbempel in this branch https://github.com/docwarems/jmc/tree/PR-333-Deobfuscate you'll find a demonstration of my current problem. The README describes how to run the demo. I will/can not further investigate unless you come with a hint what I'm doing wrong. |
is your stacktrace for the error similar to:
? in your example to fix the issue:
|
@jpbempel A happy new to year to you and everyone of the JMC team :-) Yes, that's very obvious, once I replaced the package too, the error was gone and I could see the replacement effect inside JMC. Thanks a lot! |
Back to my real deobfuscation mapping, I found that of course I DID handle the package remapping there, but using real Proguard obfuscation mapping the situation is more complex (or real) than the demo I provided. When I debugged one of these StringIndexOutOfBoundsExceptions, I have this situation in StructTypes.convertNames() name=de.docware.apps.etk.base.db.cache.EtkDbsCacheElems, getPackageName()=de.docware.apps.etk.base.db.AbstractRevisionChangeSet And these are the relevant entries from the Proguard mapping file. de.docware.apps.etk.base.db.cache.EtkDbsCacheElems -> de.docware.apps.etk.base.d.a.e: So "de.docware.apps.etk.base.d.a" refers both to a class and a package name. When in constantRead() the String constant ist de-obfuscated to a clear name I wonder if it's possible to tell whether the constant refers to a class or a package name. At least I don't see a difference in the debugger. The first map which gets a hit returns the deobfuscated string, which in my code is the class map. That's why getPackageName() delivers the class name rather than the package. Is there a possibility in constantRead() to tell what kind of object (class, package, ...) the constant refers to? |
Add extension methods when constants are read, referenced, resolved, constant pools fully resolved and parsing finished to be able for example:
de-obfuscations of stack traces
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jmc pull/333/head:pull/333
$ git checkout pull/333
Update a local copy of the PR:
$ git checkout pull/333
$ git pull https://git.openjdk.java.net/jmc pull/333/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 333
View PR using the GUI difftool:
$ git pr show -t 333
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jmc/pull/333.diff