diff --git a/Editor/BuildProcess/ObfuzProcess2021.cs b/Editor/BuildProcess/ObfuzProcess.cs similarity index 97% rename from Editor/BuildProcess/ObfuzProcess2021.cs rename to Editor/BuildProcess/ObfuzProcess.cs index 8fe96c7..5e31a2a 100644 --- a/Editor/BuildProcess/ObfuzProcess2021.cs +++ b/Editor/BuildProcess/ObfuzProcess.cs @@ -16,7 +16,7 @@ namespace Obfuz { #if UNITY_2019_1_OR_NEWER - internal class ObfuzProcess2021 : IPreprocessBuildWithReport, IPostprocessBuildWithReport + internal class ObfuzProcess : IPreprocessBuildWithReport, IPostprocessBuildWithReport { private static bool s_obfuscated = false; diff --git a/Editor/FileUtil.cs b/Editor/FileUtil.cs index 03bc86d..97843b5 100644 --- a/Editor/FileUtil.cs +++ b/Editor/FileUtil.cs @@ -15,7 +15,7 @@ namespace Obfuz { if (log) { - UnityEngine.Debug.Log($"[BashUtil] RemoveDir dir:{dir}"); + UnityEngine.Debug.Log($"removeDir dir:{dir}"); } int maxTryCount = 5; @@ -41,7 +41,7 @@ namespace Obfuz } catch (Exception e) { - UnityEngine.Debug.LogError($"[BashUtil] RemoveDir:{dir} with exception:{e}. try count:{i}"); + UnityEngine.Debug.LogError($"removeDir:{dir} with exception:{e}. try count:{i}"); Thread.Sleep(100); } } @@ -79,7 +79,7 @@ namespace Obfuz { if (log) { - UnityEngine.Debug.Log($"[BashUtil] CopyDir {src} => {dst}"); + UnityEngine.Debug.Log($"copyDir {src} => {dst}"); } RemoveDir(dst); Directory.CreateDirectory(dst); diff --git a/Editor/Virtualization/CompileContext.cs b/Editor/Virtualization/CompileContext.cs new file mode 100644 index 0000000..ba2f858 --- /dev/null +++ b/Editor/Virtualization/CompileContext.cs @@ -0,0 +1,7 @@ +namespace Obfuz.Virtualization +{ + public class CompileContext + { + + } +} diff --git a/Editor/Virtualization/ConstBytesDataNode.cs b/Editor/Virtualization/ConstBytesDataNode.cs new file mode 100644 index 0000000..d3c3de0 --- /dev/null +++ b/Editor/Virtualization/ConstBytesDataNode.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Obfuz.Virtualization +{ + public class ConstBytesDataNode : DataNodeAny + { + + public override void Compile(CompileContext ctx) + { + + + // create ldstr + // RuntimeHelpers.InitializeArray(array, fieldHandle); + } + } +} diff --git a/Editor/Virtualization/ConstExpression.cs b/Editor/Virtualization/ConstExpression.cs new file mode 100644 index 0000000..b0d13a3 --- /dev/null +++ b/Editor/Virtualization/ConstExpression.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace Obfuz.Virtualization +{ + public class ConstExpression : DataNodeAny + { + public IFunction function; + public readonly List Inputs = new List(); + + public override void Compile(CompileContext ctx) + { + + } + } +} diff --git a/Editor/Virtualization/ConstFieldDataNode.cs b/Editor/Virtualization/ConstFieldDataNode.cs new file mode 100644 index 0000000..0a5f849 --- /dev/null +++ b/Editor/Virtualization/ConstFieldDataNode.cs @@ -0,0 +1,50 @@ +using System; + +namespace Obfuz.Virtualization +{ + public class ConstFieldDataNode : DataNodeAny + { + + public override void Compile(CompileContext ctx) + { + + switch (Type) + { + case DataNodeType.Byte: + { + // create ldloc.i4 + break; + } + case DataNodeType.Int32: + { + // create ldloc.i4 + break; + } + case DataNodeType.Int64: + { + // create ldloc.i8 + break; + } + case DataNodeType.Float32: + { + // create ldloc.r4 + break; + } + case DataNodeType.Float64: + { + // create ldloc.r8 + break; + } + case DataNodeType.Null: + { + // create ldnull + break; + } + default: + { + throw new NotImplementedException($"Type:{Type} not implemented"); + } + } + } + } +} diff --git a/Editor/Virtualization/ConstFromBytesNode.cs b/Editor/Virtualization/ConstFromBytesNode.cs new file mode 100644 index 0000000..6fd0132 --- /dev/null +++ b/Editor/Virtualization/ConstFromBytesNode.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Obfuz.Virtualization +{ + public class ConstFromBytesNode : DataNodeAny + { + + public override void Compile(CompileContext ctx) + { + + } + } +} diff --git a/Editor/Virtualization/ConstPrimitiveDataNode.cs b/Editor/Virtualization/ConstPrimitiveDataNode.cs new file mode 100644 index 0000000..696b317 --- /dev/null +++ b/Editor/Virtualization/ConstPrimitiveDataNode.cs @@ -0,0 +1,50 @@ +using System; + +namespace Obfuz.Virtualization +{ + public class ConstPrimitiveDataNode : DataNodeAny + { + + public override void Compile(CompileContext ctx) + { + + switch (Type) + { + case DataNodeType.Byte: + { + // create ldloc.i4 + break; + } + case DataNodeType.Int32: + { + // create ldloc.i4 + break; + } + case DataNodeType.Int64: + { + // create ldloc.i8 + break; + } + case DataNodeType.Float32: + { + // create ldloc.r4 + break; + } + case DataNodeType.Float64: + { + // create ldloc.r8 + break; + } + case DataNodeType.Null: + { + // create ldnull + break; + } + default: + { + throw new NotImplementedException($"Type:{Type} not implemented"); + } + } + } + } +} diff --git a/Editor/Virtualization/ConstStringDataNode.cs b/Editor/Virtualization/ConstStringDataNode.cs new file mode 100644 index 0000000..33624cf --- /dev/null +++ b/Editor/Virtualization/ConstStringDataNode.cs @@ -0,0 +1,15 @@ +using System; + +namespace Obfuz.Virtualization +{ + public class ConstStringDataNode : DataNodeBase + { + + public override void Compile(CompileContext ctx) + { + + + // create ldstr + } + } +} diff --git a/Editor/Virtualization/CreateExpressionOptions.cs b/Editor/Virtualization/CreateExpressionOptions.cs new file mode 100644 index 0000000..0294bfe --- /dev/null +++ b/Editor/Virtualization/CreateExpressionOptions.cs @@ -0,0 +1,7 @@ +namespace Obfuz.Virtualization +{ + public class CreateExpressionOptions + { + public IRandom random; + } +} diff --git a/Editor/Virtualization/DataNodeBase.cs b/Editor/Virtualization/DataNodeBase.cs new file mode 100644 index 0000000..d2f581e --- /dev/null +++ b/Editor/Virtualization/DataNodeBase.cs @@ -0,0 +1,36 @@ +namespace Obfuz.Virtualization +{ + public abstract class DataNodeBase : IDataNode + { + public DataNodeType Type { get; protected set; } + + public IDataNode Expr { get; protected set; } + + public abstract object Value { get; protected set; } + + public abstract void Compile(CompileContext ctx); + } + + + public abstract class DataNodeBase : DataNodeBase + { + public T Value2 { get; protected set; } + + public override object Value + { + get => Value2; + protected set => Value2 = (T)value; + } + } + + + public abstract class DataNodeAny : DataNodeBase + { + private object _value; + public override object Value + { + get => _value; + protected set => _value = value; + } + } +} diff --git a/Editor/Virtualization/DataNodeType.cs b/Editor/Virtualization/DataNodeType.cs new file mode 100644 index 0000000..71bb9e3 --- /dev/null +++ b/Editor/Virtualization/DataNodeType.cs @@ -0,0 +1,14 @@ +namespace Obfuz.Virtualization +{ + public enum DataNodeType + { + Byte, + Int32, + Int64, + Float32, + Float64, + String, + Bytes, + Null, + } +} diff --git a/Editor/Virtualization/IDataNode.cs b/Editor/Virtualization/IDataNode.cs new file mode 100644 index 0000000..aa1024a --- /dev/null +++ b/Editor/Virtualization/IDataNode.cs @@ -0,0 +1,20 @@ +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using UnityEditor; + +namespace Obfuz.Virtualization +{ + + public interface IDataNode + { + DataNodeType Type { get; } + + object Value { get; } + + IDataNode Expr { get; } + + void Compile(CompileContext ctx); + } +} diff --git a/Editor/Virtualization/IFunction.cs b/Editor/Virtualization/IFunction.cs new file mode 100644 index 0000000..04c835e --- /dev/null +++ b/Editor/Virtualization/IFunction.cs @@ -0,0 +1,7 @@ +namespace Obfuz.Virtualization +{ + public interface IFunction + { + ConstExpression CreateCallable(IDataNode result, CreateExpressionOptions options); + } +} diff --git a/Editor/Virtualization/IRandom.cs b/Editor/Virtualization/IRandom.cs new file mode 100644 index 0000000..daeb7e5 --- /dev/null +++ b/Editor/Virtualization/IRandom.cs @@ -0,0 +1,7 @@ +namespace Obfuz.Virtualization +{ + public interface IRandom + { + + } +}