mirror of
https://github.com/AssetRipper/AssetRipper.CIL.git
synced 2026-11-13 20:05:28 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e871881517 | ||
|
|
c1eceeda51 | ||
|
|
44996e27ff | ||
|
|
0039dc95b3 | ||
|
|
0953640bf1 | ||
|
|
c1e8657d67 |
No files matched your search
@@ -13,13 +13,13 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="NUnit" Version="4.3.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.6.0">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="NUnit" Version="4.4.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.10.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -94,7 +94,7 @@ public class LoadIndirectTests
|
||||
private static void AssertCorrectLoadIndirect(TypeSignature typeToLoad, CilCode expectedOpCode)
|
||||
{
|
||||
MethodDefinition method = new MethodDefinition("Test", MethodAttributes.Public | MethodAttributes.Static, null);
|
||||
method.CilMethodBody = new(method);
|
||||
method.CilMethodBody = new();
|
||||
CilInstructionCollection instructions = method.CilMethodBody.Instructions;
|
||||
instructions.AddLoadIndirect(typeToLoad);
|
||||
Assert.That(instructions, Has.Count.EqualTo(1));
|
||||
|
||||
@@ -94,7 +94,7 @@ public class StoreIndirectTests
|
||||
private static void AssertCorrectStoreIndirect(TypeSignature typeToStore, CilCode expectedOpCode)
|
||||
{
|
||||
MethodDefinition method = new MethodDefinition("Test", MethodAttributes.Public | MethodAttributes.Static, null);
|
||||
method.CilMethodBody = new(method);
|
||||
method.CilMethodBody = new();
|
||||
CilInstructionCollection instructions = method.CilMethodBody.Instructions;
|
||||
instructions.AddStoreIndirect(typeToStore);
|
||||
Assert.That(instructions, Has.Count.EqualTo(1));
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AsmResolver.DotNet" Version="6.0.0-beta.3" />
|
||||
<PackageReference Include="AsmResolver.DotNet" Version="6.0.0-beta.4" />
|
||||
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.1" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -29,7 +29,7 @@ public static class IHasCustomAttributeExtensions
|
||||
|
||||
internal static ModuleDefinition GetModule(this IHasCustomAttribute _this)
|
||||
{
|
||||
return (_this as IModuleProvider)?.Module ?? throw new ArgumentException("Entity does not have a module", nameof(_this));
|
||||
return (_this as IModuleProvider)?.ContextModule ?? throw new ArgumentException("Entity does not have a module", nameof(_this));
|
||||
}
|
||||
|
||||
public static CustomAttribute AddFlagsAttribute(this IHasCustomAttribute _this)
|
||||
@@ -44,7 +44,7 @@ public static class IHasCustomAttributeExtensions
|
||||
{
|
||||
TypeReference flagsTypeRef = new(module.CorLibTypeFactory.CorLibScope, "System", nameof(FlagsAttribute));
|
||||
MemberReference constructor = new(flagsTypeRef, ".ctor", MethodSignature.CreateInstance(module.CorLibTypeFactory.Void));
|
||||
return _this.AddCustomAttribute(constructor);
|
||||
return _this.AddCustomAttribute(module.DefaultImporter.ImportMethod(constructor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public static class IHasCustomAttributeExtensions
|
||||
|
||||
MemberReference constructor = new(compilerGeneratedTypeRef, ".ctor", MethodSignature.CreateInstance(module.CorLibTypeFactory.Void));
|
||||
|
||||
return _this.AddCustomAttribute(constructor);
|
||||
return _this.AddCustomAttribute(module.DefaultImporter.ImportMethod(constructor));
|
||||
}
|
||||
|
||||
static AssemblyReference GetOrAddReferenceToSystemRuntimeCompilerServices(ModuleDefinition module)
|
||||
|
||||
@@ -11,7 +11,7 @@ public sealed class SwitchRemover : ICilManipulator
|
||||
{
|
||||
public void Execute(CilManipulationContext context)
|
||||
{
|
||||
ModuleDefinition? module = context.Instructions.Owner.Owner.Module;
|
||||
ModuleDefinition? module = context.Instructions.Owner.Owner?.DeclaringModule;
|
||||
if (module is null)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using AsmResolver.DotNet;
|
||||
using AsmResolver.DotNet.Code.Cil;
|
||||
using AsmResolver.DotNet.Collections;
|
||||
using AsmResolver.DotNet.Signatures;
|
||||
using AsmResolver.PE.DotNet.Cil;
|
||||
using AsmResolver.PE.DotNet.Metadata.Tables;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
@@ -23,6 +25,25 @@ public static class MethodDefinitionExtensions
|
||||
MethodStubber.FillMethodBodyWithStub(methodDefinition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the method body with: <code>throw null;</code>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the method is not managed or should not have a body, this method does nothing.
|
||||
/// </remarks>
|
||||
/// <param name="methodDefinition">The method to modify.</param>
|
||||
public static void ReplaceMethodBodyWithThrowNull(this MethodDefinition methodDefinition)
|
||||
{
|
||||
if (!methodDefinition.IsManagedMethodWithBody())
|
||||
{
|
||||
return;
|
||||
}
|
||||
methodDefinition.CilMethodBody = new();
|
||||
CilInstructionCollection methodInstructions = methodDefinition.CilMethodBody.Instructions;
|
||||
methodInstructions.Add(CilOpCodes.Ldnull);
|
||||
methodInstructions.Add(CilOpCodes.Throw);
|
||||
}
|
||||
|
||||
public static bool IsInstance(this MethodDefinition methodDefinition)
|
||||
{
|
||||
return !methodDefinition.IsStatic;
|
||||
|
||||
@@ -16,7 +16,7 @@ internal static class MethodStubber
|
||||
return;
|
||||
}
|
||||
|
||||
methodDefinition.CilMethodBody = new(methodDefinition);
|
||||
methodDefinition.CilMethodBody = new();
|
||||
CilInstructionCollection methodInstructions = methodDefinition.CilMethodBody.Instructions;
|
||||
|
||||
if (methodDefinition.IsAutoPropertyGetMethod(out FieldDefinition? backingField))
|
||||
@@ -131,13 +131,13 @@ internal static class MethodStubber
|
||||
return null;
|
||||
}
|
||||
MethodDefinition? baseConstructor = GetFirstCompatibleConstructor(methodDefinition.DeclaringType, baseTypeResolved);
|
||||
if (baseConstructor is null || methodDefinition.DeclaringType.Module is null)
|
||||
if (baseConstructor is null || methodDefinition.DeclaringType.DeclaringModule is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return methodDefinition.DeclaringType.Module.DefaultImporter.ImportMethod(baseConstructor);
|
||||
return methodDefinition.DeclaringType.DeclaringModule.DefaultImporter.ImportMethod(baseConstructor);
|
||||
}
|
||||
}
|
||||
else if (baseType is TypeSpecification baseTypeSpec)
|
||||
@@ -153,11 +153,11 @@ internal static class MethodStubber
|
||||
return null;
|
||||
}
|
||||
MethodDefinition? baseConstructor = GetFirstCompatibleConstructor(methodDefinition.DeclaringType, baseTypeResolved);
|
||||
if (baseConstructor is null || methodDefinition.DeclaringType.Module is null)
|
||||
if (baseConstructor is null || methodDefinition.DeclaringType.DeclaringModule is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
IMethodDefOrRef baseConstructorImported = methodDefinition.DeclaringType.Module.DefaultImporter.ImportMethod(baseConstructor);
|
||||
IMethodDefOrRef baseConstructorImported = methodDefinition.DeclaringType.DeclaringModule.DefaultImporter.ImportMethod(baseConstructor);
|
||||
return new MemberReference(baseType, baseConstructorImported.Name, baseConstructorImported.Signature);
|
||||
}
|
||||
|
||||
@@ -165,14 +165,7 @@ internal static class MethodStubber
|
||||
|
||||
static MethodDefinition? GetFirstCompatibleConstructor(TypeDefinition declaringType, TypeDefinition baseType)
|
||||
{
|
||||
if (declaringType.Module == baseType.Module)
|
||||
{
|
||||
return baseType.Methods.FirstOrDefault(m => m.IsInstanceConstructor() && !m.IsPrivate);
|
||||
}
|
||||
else
|
||||
{
|
||||
return baseType.Methods.FirstOrDefault(m => m.IsInstanceConstructor() && (m.IsFamily || m.IsPublic));
|
||||
}
|
||||
return baseType.Methods.FirstOrDefault(m => m.IsInstanceConstructor() && m.IsAccessibleFromType(declaringType));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +183,7 @@ internal static class MethodStubber
|
||||
}
|
||||
|
||||
TypeSignature[] typeArguments = Enumerable.Range(0, field.DeclaringType.GenericParameters.Count)
|
||||
.Select(i => new GenericParameterSignature(field.Module, GenericParameterType.Type, i))
|
||||
.Select(i => new GenericParameterSignature(field.DeclaringModule, GenericParameterType.Type, i))
|
||||
.ToArray();
|
||||
|
||||
return new MemberReference(field.DeclaringType.MakeGenericInstanceType(typeArguments).ToTypeDefOrRef(), field.Name, field.Signature);
|
||||
|
||||
@@ -25,7 +25,7 @@ public static class ModuleDefinitionExtensions
|
||||
?? throw new ArgumentOutOfRangeException(nameof(underlyingType), underlyingType, null);
|
||||
|
||||
TypeReference baseType = new(module.CorLibTypeFactory.CorLibScope, "System", "Enum");
|
||||
TypeDefinition type = new(@namespace, name, visibility.ToTypeAttributes() | TypeAttributes.Sealed, baseType);
|
||||
TypeDefinition type = new(@namespace, name, visibility.ToTypeAttributes() | TypeAttributes.Sealed, module.DefaultImporter.ImportType(baseType));
|
||||
module.TopLevelTypes.Add(type);
|
||||
AddEnumValue(type, underlyingTypeSignature);
|
||||
return type;
|
||||
|
||||
@@ -44,7 +44,7 @@ public static class TypeDefinitionExtensions
|
||||
public static MethodDefinition AddConstructor(this TypeDefinition type, Visibility visibility = Visibility.Public)
|
||||
{
|
||||
MethodAttributes methodAttributes = visibility.ToMethodAttributes() | MethodAttributes.SpecialName | MethodAttributes.RuntimeSpecialName;
|
||||
return type.AddMethod(".ctor", methodAttributes, type.Module!.CorLibTypeFactory.Void);
|
||||
return type.AddMethod(".ctor", methodAttributes, type.DeclaringModule!.CorLibTypeFactory.Void);
|
||||
}
|
||||
|
||||
public static FieldDefinition AddEnumField(this TypeDefinition type, string name, long value)
|
||||
@@ -75,7 +75,7 @@ public static class TypeDefinitionExtensions
|
||||
: MethodSignature.CreateInstance(returnType);
|
||||
MethodDefinition result = new MethodDefinition(methodName, methodAttributes, methodSignature);
|
||||
|
||||
result.CilMethodBody = new CilMethodBody(result);
|
||||
result.CilMethodBody = new CilMethodBody();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
|
||||
|
||||
<Version>1.1.6</Version>
|
||||
<Version>1.2.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<Copyright>Copyright (c) 2025 ds5678</Copyright>
|
||||
<Authors>ds5678</Authors>
|
||||
|
||||
Reference in new issue
Block a user