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

RNET-1134: Add obfuscation attribute on generated RealmSchema #3594

Merged
merged 4 commits into from
May 21, 2024

Conversation

nirinchev
Copy link
Member

@nirinchev nirinchev commented May 3, 2024

Description

I went through our reflection usages and it appears the unity initializer and RealmSchema are the low-hanging items here. There are a few more places where I'm not sure if we want to apply the obfuscation attribute:

  • MetaRealmObject:
    private static readonly PropertyInfo RealmObjectRealmProperty = typeof(IRealmObjectBase).GetProperty(nameof(IRealmObjectBase.Realm), PrivateBindingFlags)!;
    private static readonly FieldInfo ObjectMetadataSchemaField = typeof(Metadata).GetField(nameof(Metadata.Schema), PrivateBindingFlags)!;
    private static readonly MethodInfo SchemaGetNameProperty = typeof(ObjectSchema).GetProperty(nameof(ObjectSchema.Name), PrivateBindingFlags)!.GetMethod!;
    private static readonly MethodInfo RealmObjectGetBacklinksForHandle_RealmObject = GetExtensionsMI(nameof(RealmObjectExtensions.GetBacklinksForHandle))
    .MakeGenericMethod(typeof(DynamicRealmObject));
    private static readonly MethodInfo RealmObjectGetBacklinksForHandle_EmbeddedObject = GetExtensionsMI(nameof(RealmObjectExtensions.GetBacklinksForHandle))
    .MakeGenericMethod(typeof(DynamicEmbeddedObject));
    private static readonly MethodInfo RealmObjectGetObjectHandleMethod = GetExtensionsMI(nameof(RealmObjectExtensions.GetObjectHandle));
    private static readonly MethodInfo RealmObjectGetMetadataMethod = GetExtensionsMI(nameof(RealmObjectExtensions.GetObjectMetadata));
    private static readonly MethodInfo RealmValueGetMethod = typeof(RealmValue).GetMethod(nameof(RealmValue.As), BindingFlags.Public | BindingFlags.Instance)!;
    private static readonly MethodInfo CreateRealmValueMethod = typeof(RealmValue).GetMethod(nameof(RealmValue.Create), BindingFlags.NonPublic | BindingFlags.Static)!;

    The problem here is that we'd need to annotate a bunch of properties/fields in the Realm assembly and with no actual tests, I can see this easily diverging over time.
  • RealmSchema:
    var moduleInitializers = AppDomain.CurrentDomain.GetAssemblies()
    .Select(assembly => assembly.GetType("RealmModuleInitializer")?.GetMethod("Initialize"))
    .Where(method => method != null);

    This is generated by the weaver, so it's a bit more annoying to add the attribute. Without it, we wouldn't get auto schema discovery on Unity though, so I'm tempted to just bite the bullet and add it.

Fixes #3574

TODO

  • Changelog entry
  • Tests

@cla-bot cla-bot bot added the cla: yes label May 3, 2024
@nirinchev nirinchev requested a review from papafe May 3, 2024 11:59
Copy link

coveralls-official bot commented May 3, 2024

Pull Request Test Coverage Report for Build 9182118520

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 81.27%

Totals Coverage Status
Change from base Build 9182105591: 0.0%
Covered Lines: 6831
Relevant Lines: 8261

💛 - Coveralls

@nirinchev nirinchev merged commit f30ffdf into main May 21, 2024
12 checks passed
@nirinchev nirinchev deleted the ni/obfuscation branch May 21, 2024 22:08
nirinchev added a commit that referenced this pull request May 22, 2024
* main:
  RNET-1134: Add obfuscation attribute on generated RealmSchema (#3594)
  Revert "Hide collections in mixed from public API" (#3606)
  Update to Core 14.7.0 (#3605)
  RNET-1145, RNET-1143: Fix reading schema from native (#3601)

# Conflicts:
#	.github/templates/test-weaver.yml
#	.github/workflows/test-weaver.yml
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Realm Obfuscation (Unity + Local Database)
1 participant