重构Node

backup
walon 2025-04-21 08:58:25 +08:00
parent 33f83d5432
commit 61eab9ed11
13 changed files with 135 additions and 70 deletions

View File

@ -1,62 +0,0 @@
using System;
namespace Obfuz.Virtualization
{
public class ConstDataNode : 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;
}
case DataNodeType.String:
{
// create ldstr
break;
}
case DataNodeType.Bytes:
{
// create ldstr
// RuntimeHelpers.InitializeArray(array, fieldHandle);
break;
}
default:
{
throw new NotImplementedException($"Type:{Type} not implemented");
}
}
}
}
}

View File

@ -4,6 +4,7 @@
{ {
public readonly DataNodeType type; public readonly DataNodeType type;
public readonly object value; public readonly object value;
public ConstValue(DataNodeType type, object value) public ConstValue(DataNodeType type, object value)
{ {
this.type = type; this.type = type;

View File

@ -9,6 +9,6 @@
Float64, Float64,
String, String,
Bytes, Bytes,
Null, //Null,
} }
} }

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Obfuz.Virtualization
{
[NodeOutput(DataNodeType.Bytes)]
public class BytesFromEncryptedBytesNode : DataNodeAny
{
public override void Compile(CompileContext ctx)
{
// only support Int32, int64, bytes.
// string can only create from StringFromBytesNode
// x = memcpy array.GetRange(index, length);
}
}
}

View File

@ -0,0 +1,69 @@
using System;
namespace Obfuz.Virtualization
{
[NodeOutput(DataNodeType.Int32)]
[NodeOutput(DataNodeType.Int64)]
public class ConstDataNode : DataNodeAny
{
public override void Compile(CompileContext ctx)
{
// only Int32 - Null,
// to avoid GC,
// the leaf node that can create string or bytes is ConstFieldDataNode.
// float and double can only come from RawCastAs int32 and int64.
// so we only need to deal int32 and int64
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;
//}
//case DataNodeType.String:
//{
// // create ldstr
// break;
//}
//case DataNodeType.Bytes:
//{
// // create ldstr
// // RuntimeHelpers.InitializeArray(array, fieldHandle);
// break;
//}
default:
{
throw new NotImplementedException($"Type:{Type} not implemented");
}
}
}
}
}

View File

@ -2,6 +2,9 @@
namespace Obfuz.Virtualization namespace Obfuz.Virtualization
{ {
[NodeOutput(DataNodeType.Int32)]
[NodeOutput(DataNodeType.Int64)]
[NodeOutput(DataNodeType.Bytes)]
public class ConstExpression : DataNodeAny public class ConstExpression : DataNodeAny
{ {
public IFunction function; public IFunction function;

View File

@ -7,7 +7,6 @@ namespace Obfuz.Virtualization
public override void Compile(CompileContext ctx) public override void Compile(CompileContext ctx)
{ {
switch (Type) switch (Type)
{ {
//case DataNodeType.Byte: //case DataNodeType.Byte:
@ -35,11 +34,6 @@ namespace Obfuz.Virtualization
// create ldloc.r8 // create ldloc.r8
break; break;
} }
case DataNodeType.Null:
{
// create ldnull
break;
}
case DataNodeType.String: case DataNodeType.String:
{ {
// create ldstr // create ldstr

View File

@ -11,7 +11,9 @@ namespace Obfuz.Virtualization
public override void Compile(CompileContext ctx) public override void Compile(CompileContext ctx)
{ {
// only support Int32, int64, bytes.
// string can only create from StringFromBytesNode
// x = memcpy array.GetRange(index, length);
} }
} }
} }

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Obfuz.Virtualization
{
public class StringFromEncryptedBytesNode : DataNodeAny
{
public override void Compile(CompileContext ctx)
{
// only support Int32, int64, bytes.
// string can only create from StringFromBytesNode
// x = memcpy array.GetRange(index, length);
}
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Obfuz.Virtualization
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
public class NodeOutputAttribute : Attribute
{
public DataNodeType Type { get; }
public NodeOutputAttribute(DataNodeType type)
{
Type = type;
}
}
}