fix: change obfuscation relative metadata to public for compatible with mono because mono has more strict access validation, it will raise FieldAccessException if access a private field.

before-split
walon 2025-05-18 16:43:11 +08:00
parent 56374bbac7
commit 274f827493
4 changed files with 6 additions and 4 deletions

View File

@ -109,7 +109,7 @@ namespace Obfuz.Data
_module.EnableTypeDefFindCache = true;
}
var field = new FieldDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}RVA_Value{_holderTypeDef.Fields.Count}", new FieldSig(GetTypeSigOfValue(value)), FieldAttributes.Static | FieldAttributes.Private | FieldAttributes.InitOnly);
var field = new FieldDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}RVA_Value{_holderTypeDef.Fields.Count}", new FieldSig(GetTypeSigOfValue(value)), FieldAttributes.Static | FieldAttributes.Public | FieldAttributes.InitOnly);
field.DeclaringType = _holderTypeDef;
return new ConstFieldInfo
{

View File

@ -106,7 +106,7 @@ namespace Obfuz.Data
var holderField = new FieldDefUser($"$RVA_Data{_rvaFields.Count}", new FieldSig(dataHolderType.ToTypeSig()), FieldAttributes.InitOnly | FieldAttributes.Static | FieldAttributes.HasFieldRVA);
holderField.DeclaringType = _rvaTypeDef;
var runtimeValueField = new FieldDefUser($"$RVA_Value{_rvaFields.Count}", new FieldSig(new SZArraySig(_module.CorLibTypes.Byte)), FieldAttributes.Static);
var runtimeValueField = new FieldDefUser($"$RVA_Value{_rvaFields.Count}", new FieldSig(new SZArraySig(_module.CorLibTypes.Byte)), FieldAttributes.Static | FieldAttributes.Public);
runtimeValueField.DeclaringType = _rvaTypeDef;
return (holderField, runtimeValueField);
}
@ -117,6 +117,7 @@ namespace Obfuz.Data
if (_dataHolderTypeBySizes.TryGetValue(size, out var type))
return type;
var dataHolderType = new TypeDefUser($"$ObfuzRVA$DataHolder{size}", _module.Import(typeof(ValueType)));
dataHolderType.Attributes = TypeAttributes.Public | TypeAttributes.Sealed;
dataHolderType.Layout = TypeAttributes.ExplicitLayout;
dataHolderType.PackingSize = 1;
dataHolderType.ClassSize = (uint)size;

View File

@ -126,7 +126,7 @@ namespace Obfuz.ObfusPasses.CallObfus
}
MethodDef methodDef = new MethodDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}ProxyCall$Dispatch${_proxyTypeDef.Methods.Count}", methodSig,
MethodImplAttributes.IL | MethodImplAttributes.Managed,
MethodAttributes.Static | MethodAttributes.Private);
MethodAttributes.Static | MethodAttributes.Public);
methodDef.DeclaringType = _proxyTypeDef;
return methodDef;
}

View File

@ -9,7 +9,8 @@ namespace Obfuz
public static class EncryptionService<T> where T : IEncryptionScope
{
private static IEncryptor _encryptor;
// for compatibility with Mono because Mono will raise FieldAccessException when try access private field
public static IEncryptor _encryptor;
public static IEncryptor Encryptor
{