Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ gh-pages/
.idea/
artifacts/
/Confuser.Protections/runtime
/Confuser.Protections/runtime
*.binlog
2 changes: 1 addition & 1 deletion Confuser.Core/CoreComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected internal override void Initialize(ConfuserContext context) {
context.Registry.RegisterService(_RandomServiceId, typeof(IRandomService), new RandomService(_context.Project.Seed));
context.Registry.RegisterService(_MarkerServiceId, typeof(IMarkerService), new MarkerService(context, marker));
context.Registry.RegisterService(_TraceServiceId, typeof(ITraceService), new TraceService());
context.Registry.RegisterService(_RuntimeServiceId, typeof(IRuntimeService), new RuntimeService());
context.Registry.RegisterService(_RuntimeServiceId, typeof(IRuntimeService), new RuntimeService(context));
context.Registry.RegisterService(_CompressionServiceId, typeof(ICompressionService), new CompressionService(context));
context.Registry.RegisterService(_APIStoreId, typeof(IAPIStore), new APIStore(context));
}
Expand Down
11 changes: 9 additions & 2 deletions Confuser.Core/Services/RuntimeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
using dnlib.DotNet;

namespace Confuser.Core.Services {
internal class RuntimeService : IRuntimeService {
internal class RuntimeService : IRuntimeService {
private readonly ConfuserContext context;
ModuleDef rtModule;

public RuntimeService(ConfuserContext context) {
this.context = context;
}

/// <inheritdoc />
public TypeDef GetRuntimeType(string fullName) {
if (rtModule == null) {
Expand All @@ -16,7 +21,9 @@ public TypeDef GetRuntimeType(string fullName) {
}

private void LoadConfuserRuntimeModule() {
const string runtimeDllName = "Confuser.Runtime.dll";
var entryPoint = this.context.Project[0].Resolve(this.context.Project.BaseDirectory);
var hasMscorlib = entryPoint.GetAssemblyRef("mscorlib") != null;
var runtimeDllName = hasMscorlib ? "runtime\\net472\\Confuser.Runtime.dll" : "runtime\\net8.0\\Confuser.Runtime.dll";

var module = typeof(RuntimeService).Assembly.ManifestModule;
string rtPath = runtimeDllName;
Expand Down
53 changes: 47 additions & 6 deletions Confuser.Protections/Confuser.Protections.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,64 @@

<PropertyGroup Label="Assembly Settings">
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<RuntimeProject>..\Confuser.Runtime\Confuser.Runtime.csproj</RuntimeProject>
</PropertyGroup>

<PropertyGroup Label="Assembly Information">
<Title>ConfuserEx Protections</Title>
<Description>Protections and packers of ConfuserEx</Description>
</PropertyGroup>

<ItemGroup Label="Nuget Dependencies">
<PackageReference Include="System.ValueTuple" Version="4.6.2" />
</ItemGroup>

<ItemGroup Label="Project Dependencies">
<ProjectReference Include="..\Confuser.DynCipher\Confuser.DynCipher.csproj" />
<ProjectReference Include="..\Confuser.Renamer\Confuser.Renamer.csproj" />
<ProjectReference Include="..\Confuser.Runtime\Confuser.Runtime.csproj" Condition="'$(TargetFramework)' == 'net472'" />
<ProjectReference Include="..\Confuser.Runtime\Confuser.Runtime.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<Import Project="..\ConfuserEx.Common.targets" Condition="Exists('..\ConfuserEx.Common.targets')" />

</Project>
<ItemGroup>
<RuntimeProjectFramework Include="$(TargetFrameworks)" />
</ItemGroup>

<Target Name="BuildRuntimeProject" BeforeTargets="Build">

<MSBuild Projects="$(RuntimeProject)" Targets="Build"
Properties="Configuration=$(Configuration);TargetFramework=%(RuntimeProjectFramework.Identity)"
BuildInParallel="true" />

</Target>

<Target Name="CollectRuntimeOutputs" DependsOnTargets="BuildRuntimeProject" AfterTargets="Build">

<!-- Query each TFM output -->
<MSBuild Projects="$(RuntimeProject)" Targets="GetTargetPath" Properties="Configuration=$(Configuration);TargetFramework=%(RuntimeProjectFramework.Identity)" BuildInParallel="true">

<Output TaskParameter="TargetOutputs" ItemName="RuntimeOutputs" />

</MSBuild>
<ItemGroup>
<RuntimeOutputsNetFramework Include="@(RuntimeOutputs)" Condition="'%(TargetFrameworkVersion)' == '4.7.2'" />
<RuntimeOutputsNet Include="@(RuntimeOutputs)" Condition="'%(TargetFrameworkVersion)' == '8.0'" />
</ItemGroup>
<Copy SourceFiles="@(RuntimeOutputsNetFramework)" DestinationFolder="$(OutDir)runtime\net472\" />
<Copy SourceFiles="@(RuntimeOutputsNet)" DestinationFolder="$(OutDir)runtime\net8.0\" />

</Target>

<Target Name="RegisterExtraFiles" DependsOnTargets="CollectRuntimeOutputs" BeforeTargets="GetCopyToOutputDirectoryItems">

<ItemGroup>
<ContentWithTargetPath Include="@(RuntimeOutputsNet)">
<TargetPath>runtime\net8.0\%(Filename)%(Extension)</TargetPath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</ContentWithTargetPath>
<ContentWithTargetPath Include="@(RuntimeOutputsNetFramework)">
<TargetPath>runtime\net472\%(Filename)%(Extension)</TargetPath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</ContentWithTargetPath>
</ItemGroup>

</Target>

</Project>
Loading