forked from SamboyCoding/Cpp2IL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call analysis improvements (SamboyCoding#165)
- Loading branch information
1 parent
bdc1b84
commit 11b1aae
Showing
136 changed files
with
28,271 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Linq; | ||
using Cpp2IL.Core.Model.Contexts; | ||
using Cpp2IL.Core.Utils; | ||
|
||
namespace Cpp2IL.Core.Tests; | ||
|
||
public class AccessibilityUtilsTests | ||
{ | ||
[Test] | ||
public void AccessibilityTests() | ||
{ | ||
var appContext = GameLoader.LoadSimpleGame(); | ||
var mscorlib = appContext.AssembliesByName["mscorlib"]; | ||
var coreModule = appContext.AssembliesByName["UnityEngine.CoreModule"]; | ||
|
||
var console = GetTypeByFullName(mscorlib, "System.Console");//public | ||
var consoleWindowsConsole = GetTypeByFullName(mscorlib, "System.Console.WindowsConsole");//private nested | ||
var dateTimeFormat = GetTypeByFullName(mscorlib, "System.DateTimeFormat");//internal | ||
var gameObject = GetTypeByFullName(coreModule, "UnityEngine.GameObject");//public | ||
Assert.Multiple(() => | ||
{ | ||
AssertAccessibleTo(console, consoleWindowsConsole); | ||
AssertAccessibleTo(consoleWindowsConsole, console); | ||
AssertAccessibleTo(console, gameObject); | ||
AssertNotAccessibleTo(consoleWindowsConsole, gameObject); | ||
AssertNotAccessibleTo(gameObject, console); | ||
AssertAccessibleTo(consoleWindowsConsole, consoleWindowsConsole); | ||
AssertAccessibleTo(dateTimeFormat, consoleWindowsConsole); | ||
AssertNotAccessibleTo(consoleWindowsConsole, dateTimeFormat); | ||
AssertNotAccessibleTo(dateTimeFormat, gameObject); | ||
}); | ||
} | ||
|
||
private static void AssertAccessibleTo(TypeAnalysisContext type1, TypeAnalysisContext type2) | ||
{ | ||
Assert.That(type1.IsAccessibleTo(type2), () => $"{type1.FullName} is not accessible to {type2.FullName}, but should be."); | ||
} | ||
|
||
private static void AssertNotAccessibleTo(TypeAnalysisContext type1, TypeAnalysisContext type2) | ||
{ | ||
Assert.That(!type1.IsAccessibleTo(type2), () => $"{type1.FullName} is accessible to {type2.FullName}, but shouldn't be."); | ||
} | ||
|
||
private static TypeAnalysisContext GetTypeByFullName(AssemblyAnalysisContext assembly, string fullName) | ||
{ | ||
return assembly.Types.FirstOrDefault(t => t.FullName == fullName) ?? throw new($"Could not find {fullName} in {assembly.CleanAssemblyName}."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Cpp2IL.Core\Cpp2IL.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.5.0" /> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using NUnit.Framework; | ||
|
||
namespace Cpp2IL.Core.Tests; | ||
public class Cpp2IlApiTests | ||
{ | ||
[Test] | ||
public void UnityVersionIsCorrectlyDeterminedFromGlobalGameManagers() | ||
{ | ||
var version = Cpp2IlApi.DetermineUnityVersion(null, Paths.SimpleGame.DataDirectory); | ||
Assert.That(version.IsEqual(2019, 4, 34)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using AssetRipper.VersionUtilities; | ||
using Cpp2IL.Core.Api; | ||
using Cpp2IL.Core.CorePlugin; | ||
using Cpp2IL.Core.Model.Contexts; | ||
using LibCpp2IL; | ||
|
||
namespace Cpp2IL.Core.Tests; | ||
|
||
public static class GameLoader | ||
{ | ||
static GameLoader() | ||
{ | ||
InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_32); | ||
InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_64); | ||
InstructionSetRegistry.RegisterInstructionSet<WasmInstructionSet>(DefaultInstructionSets.WASM); | ||
InstructionSetRegistry.RegisterInstructionSet<ArmV7InstructionSet>(DefaultInstructionSets.ARM_V7); | ||
var useNewArm64 = true; | ||
if (useNewArm64) | ||
{ | ||
InstructionSetRegistry.RegisterInstructionSet<NewArmV8InstructionSet>(DefaultInstructionSets.ARM_V8); | ||
} | ||
else | ||
{ | ||
InstructionSetRegistry.RegisterInstructionSet<Arm64InstructionSet>(DefaultInstructionSets.ARM_V8); | ||
} | ||
|
||
LibCpp2IlBinaryRegistry.RegisterBuiltInBinarySupport(); | ||
} | ||
|
||
public static ApplicationAnalysisContext LoadSimpleGame() | ||
{ | ||
Cpp2IlApi.InitializeLibCpp2Il(Paths.SimpleGame.GameAssembly, Paths.SimpleGame.Metadata, new UnityVersion(2019, 4, 34, UnityVersionType.Final, 1)); | ||
return Cpp2IlApi.CurrentAppContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Cpp2IL.Core.Tests; | ||
public static class Paths | ||
{ | ||
public const string TestProjectDirectory = "../../../"; | ||
public const string RepositoryRootDirectory = "../" + TestProjectDirectory; | ||
public const string TestFilesDirectory = RepositoryRootDirectory + "TestFiles/"; | ||
|
||
public static class SimpleGame | ||
{ | ||
public const string RootDirectory = TestFilesDirectory + "Simple_2019_4_34/"; | ||
public const string DataDirectory = RootDirectory + "Simple_2019_4_34_Data/"; | ||
public const string ExecutableFile = RootDirectory + "Simple_2019_4_34.exe"; | ||
public const string GameAssembly = RootDirectory + "GameAssembly.dll"; | ||
public const string Metadata = DataDirectory + "il2cpp_data/Metadata/global-metadata.dat"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using NUnit.Framework; |
Oops, something went wrong.