Skip to content

Commit

Permalink
#64 #68 #67 use vault, add detect not inited
Browse files Browse the repository at this point in the history
  • Loading branch information
0xF6 committed Jul 3, 2021
1 parent 25d285b commit bb2de80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<AssemblyName>ishtar</AssemblyName>
<DefineConstants>DEBUG;STATIC_VALIDATE_IL;DEBUG_VTABLE</DefineConstants>
<DefineConstants>DEBUG;STATIC_VALIDATE_IL;DEBUG_VTABLE;VALIDATE_RUNTIME_TOKEN</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TrimMode>link</TrimMode>
Expand Down
22 changes: 18 additions & 4 deletions backend/mana.backend.ishtar.light/runtime/ModuleReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ namespace ishtar
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using mana.exceptions;
using mana.extensions;
using mana.ishtar.emit;
using mana.ishtar.emit.extensions;
using mana.reflection;
using mana.runtime;
internal class RuntimeIshtarModule : ManaModule

public class RuntimeIshtarModule : ManaModule
{
public AppVault Vault { get; }
public ushort ID { get; internal set; }


public static RuntimeIshtarModule Read(byte[] arr, List<ManaModule> deps, Func<string, Version, ManaModule> resolver)
public static RuntimeIshtarModule Read(AppVault vault, byte[] arr, List<ManaModule> deps, Func<string, Version, ManaModule> resolver)
{
var module = new RuntimeIshtarModule();
var module = new RuntimeIshtarModule(vault);
using var mem = new MemoryStream(arr);
using var reader = new BinaryReader(mem);
module.Deps.AddRange(deps);
Expand Down Expand Up @@ -130,9 +134,19 @@ public static RuntimeIshtarModule Read(byte[] arr, List<ManaModule> deps, Func<s
module.aspects.AddRange(Aspect.Deconstruct(module.const_table.storage));

DistributionAspects(module);
ValidateRuntimeTokens(module);

return module;
}
[Conditional("VALIDATE_RUNTIME_TOKEN")]
public static void ValidateRuntimeTokens(RuntimeIshtarModule module)
{
foreach (var @class in module.class_table.OfType<RuntimeIshtarClass>())
{
VM.Assert(@class.runtime_token != RuntimeToken.Default, WNE.TYPE_LOAD,
$"Detected non-inited runtime token. type: '{@class.FullName.NameWithNS}'");
}
}

// shit, todo: refactoring
public static void DistributionAspects(RuntimeIshtarModule ishtarModule)
Expand Down

0 comments on commit bb2de80

Please sign in to comment.