new: add package com.code-philosophy.obfuz4hybridclr

before-split
walon 2025-05-21 09:08:13 +08:00
parent 5766d2f2f4
commit da47e1283d
12 changed files with 260 additions and 0 deletions

View File

@ -77,10 +77,12 @@ namespace Obfuz
public void Run()
{
Debug.Log($"Obfuscator Run. begin");
FileUtil.RecreateDir(_obfuscatedAssemblyOutputPath);
RunPipeline(_pipeline1);
_assemblySearchPaths.Insert(0, _obfuscatedAssemblyOutputPath);
RunPipeline(_pipeline2);
Debug.Log($"Obfuscator Run. end");
}
private void RunPipeline(Pipeline pipeline)

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 067341936b8cb2242be3bdc83f3ca3cd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,82 @@
using HybridCLR.Editor;
using Obfuz.Settings;
using Obfuz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using HybridCLR.Editor.Commands;
using HybridCLR.Editor.Installer;
using System.IO;
using HybridCLR.Editor.ABI;
using UnityEngine;
namespace ObfuzExtension4HybridCLR
{
public static class ObfuscateUtil
{
public static bool AreSameDirectory(string path1, string path2)
{
try
{
var dir1 = new DirectoryInfo(path1);
var dir2 = new DirectoryInfo(path2);
// 比较完整路径(考虑符号链接)
return dir1.FullName.TrimEnd('\\') == dir2.FullName.TrimEnd('\\');
}
catch
{
return false;
}
}
public static void CompileAndObfuscateHotUpdateAssemblies(BuildTarget target)
{
string hotUpdateDllPath = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target);
BashUtil.RemoveDir(hotUpdateDllPath);
CompileDllCommand.CompileDll(target);
var assemblySearchPaths = new List<string>
{
SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target),
};
Obfuscate(target, assemblySearchPaths, hotUpdateDllPath);
}
public static void Obfuscate(BuildTarget target, List<string> assemblySearchPaths, string outputPath)
{
var obfuzSettings = ObfuzSettings.Instance;
var assemblySearchDirs = assemblySearchPaths;
ObfuscatorBuilder builder = ObfuscatorBuilder.FromObfuzSettings(obfuzSettings, target, true);
builder.InsertTopPriorityAssemblySearchPaths(assemblySearchDirs);
string obfuscatedAssemblyOutputPath = obfuzSettings.GetObfuscatedAssemblyOutputPath(target);
if (AreSameDirectory(outputPath, obfuscatedAssemblyOutputPath))
{
throw new Exception($"outputPath:{outputPath} can't be same to ObfuscatedAssemblyOutputPath:{obfuscatedAssemblyOutputPath}");
}
foreach (var assemblySearchDir in builder.AssemblySearchPaths)
{
if (AreSameDirectory(assemblySearchDir, obfuscatedAssemblyOutputPath))
{
throw new Exception($"assemblySearchDir:{assemblySearchDir} can't be same to ObfuscatedAssemblyOutputPath:{obfuscatedAssemblyOutputPath}");
}
}
Obfuscator obfuz = builder.Build();
obfuz.Run();
Directory.CreateDirectory(outputPath);
foreach (string srcFile in Directory.GetFiles(obfuscatedAssemblyOutputPath, "*.dll"))
{
string fileName = Path.GetFileName(srcFile);
string destFile = $"{outputPath}/{fileName}";
File.Copy(srcFile, destFile, true);
Debug.Log($"Copy {srcFile} to {destFile}");
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b7f5fe18513bcdd4c8960d908e88402e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
{
"name": "ObfuzExtension4HybridCLR",
"rootNamespace": "",
"references": [
"GUID:2373f786d14518f44b0f475db77ba4de",
"GUID:66e09fc524ec6594b8d6ca1d91aa1a41"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3743e71edcd5bd8499007797ef02cbfb
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,64 @@
using HybridCLR.Editor.Commands;
using HybridCLR.Editor;
using Obfuz.Settings;
using Obfuz;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.Reflection;
using System;
using System.IO;
using HybridCLR.Editor.Link;
using HybridCLR.Editor.Meta;
using UnityEditor.Build;
using HybridCLR.Editor.Installer;
namespace ObfuzExtension4HybridCLR
{
public static class PrebuildCommandExt
{
[MenuItem("HybridCLR/ObfuzExtension/GenerateAll")]
public static void GenerateAll()
{
var installer = new InstallerController();
if (!installer.HasInstalledHybridCLR())
{
throw new BuildFailedException($"You have not initialized HybridCLR, please install it via menu 'HybridCLR/Installer'");
}
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
ObfuscateUtil.CompileAndObfuscateHotUpdateAssemblies(target);
//CompileDllCommand.CompileDll(target, EditorUserBuildSettings.development);
//// obfuscate hot update assemblies
//string hotUpdateAssemblyOutputPath = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target);
//string obfuscatedAssemblyOutputPath = ObfuzSettings.Instance.GetObfuscatedAssemblyOutputPath(target);
//var assemblySearchPaths = new List<string>
//{
// hotUpdateAssemblyOutputPath,
//};
//ObfuscateUtil.Obfuscate(target, assemblySearchPaths, obfuscatedAssemblyOutputPath);
//// override assembly in hot update path with obfuscated assembly
//foreach (string hotUpdateAssName in SettingsUtil.HotUpdateAssemblyNamesIncludePreserved)
//{
// string srcFile = $"{obfuscatedAssemblyOutputPath}/{hotUpdateAssName}.dll";
// string dstFile = $"{hotUpdateAssemblyOutputPath}/{hotUpdateAssName}.dll";
// // not all assemblies are obfuscated
// if (File.Exists(srcFile))
// {
// File.Copy(srcFile, dstFile, true);
// File.SetLastWriteTimeUtc(dstFile, new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
// File.SetCreationTimeUtc(dstFile, new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
// Debug.Log($"[ObfuzExtension] Copy {srcFile} to {dstFile}");
// }
//}
Il2CppDefGeneratorCommand.GenerateIl2CppDef();
LinkGeneratorCommand.GenerateLinkXml(target);
StripAOTDllCommand.GenerateStripedAOTDlls(target);
MethodBridgeGeneratorCommand.GenerateMethodBridgeAndReversePInvokeWrapper(target);
AOTReferenceGeneratorCommand.GenerateAOTGenericReference(target);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: afc965e1afdfc8e47b8a70be7a93cf25
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Code Philosophy(代码哲学)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3036602f815e31341b4445f0e331b58e
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
{
"name": "com.code-philosophy.obfuz4hybridclr",
"version": "1.0.0-alpha",
"displayName": "Obfuz4HybridCLR",
"description": "Obfuz Extension for HybridCLR",
"category": "Editor",
"documentationUrl": "https://www.obfuz.com",
"changelogUrl": "https://github.com/focus-creative-games/obfuz/commits/main/",
"licensesUrl": "https://github.com/focus-creative-games/obfuz/blob/main/LICENSE",
"keywords": [
"obfuscation",
"obfuscator",
"confuser",
"code-philosophy"
],
"author": {
"name": "Code Philosophy",
"email": "obfuz@code-philosophy.com",
"url": "https://code-philosophy.com"
}
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9ac66e213a764b840b2533ee30123717
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: