Skip to content
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

Add token attributes to dummy dll #334

Merged
merged 2 commits into from
Jul 31, 2020
Merged

Add token attributes to dummy dll #334

merged 2 commits into from
Jul 31, 2020

Conversation

knah
Copy link
Contributor

@knah knah commented Jul 29, 2020

Motivation: this would make it easier to work with il2cpp API at runtime, as tokens provide a nice and performant way to uniquely identify classes/methods without ambiguity of names and difficulties of overload resolution.
Mainly this would allow to generate better-performing assemblies using future versions of my assembly unhollower that could make use of token information

@Perfare
Copy link
Owner

Perfare commented Jul 29, 2020

I have an idea. It may not be necessary to set attribute, but just set the MetadataToken of Definition to be consistent with il2cpp.
typeDefinition.MetadataToken = new MetadataToken(typeDef.token);
By the way, even if the MetadataToken is not modified, the MetadataToken of the dummy dll after the output can always be consistent with that of il2cpp. It seems that the data of il2cpp is also stored in the order of tokens.

@knah
Copy link
Contributor Author

knah commented Jul 29, 2020

I've checked generated tokens on current version, and they are unfortunately different from original ones. I'll look into your suggestion, if cecil allows that - it would be great. I'll comment on this PR with results

@knah
Copy link
Contributor Author

knah commented Jul 29, 2020

I've tried that, and unfortunately setting MetadataToken values doesn't do anything - tokens are replaced with sequential values in ModuleWriter class in cecil when the assembly is written.

On the other hand, I can look a bit more into why tokens don't match - looks like nested types can cause misalignments

@Perfare
Copy link
Owner

Perfare commented Jul 29, 2020

Thanks for your feedback, maybe I should modify the logic of the nested types part to match it.

@Perfare
Copy link
Owner

Perfare commented Jul 30, 2020

I did some research, cecil uses depth-first traversal when writing modules, but breadth-first traversal can output values consistent with il2cpp.
So I think unless we modify the cecil code, we can only add token attributes to get the correct token.

@Perfare Perfare merged commit a9e3b12 into Perfare:master Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants