Versioned API client architecture
Unfortunately the IPC implementation I made a post about a while back was completely useless as there is no IL2CPP API to get a class' static field data. So now I'm falling back to manual memory interop.
For this, I need to handle many different versions of both Mono and IL2CPP. I need to expose methods such as these;
The implementation of these methods and internal details (like linked lists or hashmaps) frequently changes between the (~8) versions. The crux of the problem is that working with this API requires some initialization, which is also different between all versions.
I need a solution where I infer some basic information (Mono or IL2CPP), then run the code which fetches the initial data (some addresses, tokens) and finally return the correct class for the corresponding version.
I need to be very clear that I'm using .NET Standard 2.0; I don't have access to
static abstract
.
My initial naive idea was this:
7 Replies
cc @canton7 @goose @JohnStoober
And then I need some factory class which can do something like this;
But, all of this might be redesigned completely as well, let me explain how this will normally be used
If you look at the initial example methods I gave, you can see that you might be able to order them by what they belong to instead (MonoImage, MonoClass, MonoClassField, MonoType, ...).
Eventually, I of course wanna have types that the user can have; my own copies of
MonoImage
, MonoClass
, MonoClassField
.
I guess a first question here: Because ReadProcessMemory calls are somewhat expensive, I wanted to make the properties (like MonoClassField.Offset
) lazy, calling the IMonoInteroperator.GetFieldName
method and caching the result. Would you do this? Or would you make the types immutable and get all the info associated with it at request (can become very, very recursive!!!)?
I'm thinking I could technically have a IMonoImageInterop
or something for every type. But that would become very annoying with all the versions, I'm thinking?Maybe I'm missing something, but there doesn't look like there's anything too impossible here?
Because ReadProcessMemory calls are somewhat expensive, I wanted to make the properties (like MonoClassField.Offset) lazy, calling the IMonoInteroperator.GetFieldName method and caching the result. Would you do this? Or would you make the types immutable and get all the info associated with it at request (can become very, very recursive!!!)?Why not do the caching in the
IMonoInteroperator
? Then your MonoClassField.Offset
just calls IMonoInteroperator.GetClassFieldOffset(this....)
. That way if you have multiple MonoClassField
instances for the same field, they all benefit from the cache
(So your MonoClass
etc classes are just very lightweight, version-independent wrappers around an IMonoInteroperator
)well a certain field can only ever be in one specific class
like, two classes can't share a field
just like a class can't be in 2 assemblies (images)
I think you misunderstood
It was just in response to "if you have multiple
MonoClassField
instances for the same field"
Which can't be a thingCan't you request info on the same field twice? Or does the IMonoInteroperator cache those instances?
well sure, but i was really just thinking of something like this