memory address search

I'm wondering whether it's possible to somehow search for a specific object instance by checking every possible (used, if that's checkable) memory address. The object wouldn't be accessible otherwise but this way (or it's stored in some unknown instance or class). Would some Unsafe magic work for that?
16 Replies
JavaBot
JavaBot3mo ago
This post has been reserved for your question.
Hey @ShadowOfHeaven! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
ShadowOfHeaven
ShadowOfHeaven3mo ago
What if I'm sure that this object isn't garbage-collected For example because it's handling incoming connections Wouldn't that prevent it from being garbage-collected as it's method's bytecode is used? Or if you just once started a new thread And it always does something but the reference to it is lost Wouldn't it still be stored as an object in memory somewhere?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
dan1st
dan1st3mo ago
I'd say that running threads are GC roots and therefore not GCed
ShadowOfHeaven
ShadowOfHeaven3mo ago
So I COULD perform a search by like Unsafe#getObject(long address) and check every address to get for example a thread? That makes me wonder If I were to replace that memory address with another object Could I somehow update the thread-cached values And therefore completly override any object I want? Even if it's not stored anywhere as a variable
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
ShadowOfHeaven
ShadowOfHeaven3mo ago
It does wonders for fast modifying of basically anything I just don't know about this
dan1st
dan1st3mo ago
what? you cannot rely on objects being stored at a specific address, objects may be moved at any time It is a JDK internal class giving you somewhat low level access to more or less raw memory. The memory access methods are deprecated for removal in favor of the Foreign Function and Memory API and VarHandles
ShadowOfHeaven
ShadowOfHeaven3mo ago
So it isn't likely that I can find any object by searching through all addresses? It's deprecated since java 23 But I honestly don't see the reason behind that
dan1st
dan1st3mo ago
ig it would probably work
ShadowOfHeaven
ShadowOfHeaven3mo ago
Unsafe can offer better performance to VarHandles
dan1st
dan1st3mo ago
depends how you are using it
ShadowOfHeaven
ShadowOfHeaven3mo ago
And even if that's not the main concern or the difference isn't significant VarHandles' main features were added in java 9 So they pretty much are saying "more work if you wanna support all java versions"
dan1st
dan1st3mo ago
Well Unsafe stuff is probably gonna get removed at some point
Want results from more Discord servers?
Add your server