public void ElfReadTest() { var file = GetTempFile(); var asm = new IshtarAssembly { Name = "wave_test" }; asm.AddSegment((".code", Encoding.ASCII.GetBytes("IL_CODE"))); IshtarAssembly.WriteTo(asm, file); var result = IshtarAssembly.LoadFromFile(file); var(_, body) = result.Sections[0]; Assert.AreEqual("IL_CODE", Encoding.ASCII.GetString(body)); var f_mem = new MemoryStream(File.ReadAllBytes(file)); f_mem.Seek(f_mem.Capacity - (sizeof(uint) * 2), SeekOrigin.Begin); var bin = new BinaryReader(f_mem); var len = bin.ReadUInt32(); var offset = bin.ReadUInt32(); f_mem.Seek(offset, SeekOrigin.Begin); var bytes = bin.ReadBytes((int)len); Assert.AreEqual("IL_CODE", Encoding.ASCII.GetString(bytes)); File.Delete(file); }
public void ElfReadManual() { var file = @"C:\Users\ls-mi\Desktop\wave.elf"; var asm = new IshtarAssembly { Name = "wave_test" }; asm.AddSegment((".code", Encoding.ASCII.GetBytes("IL_CODE"))); IshtarAssembly.WriteTo(asm, file); var result = IshtarAssembly.LoadFromFile(file); }
public static unsafe int Main(string[] args) { ishtar.Trace.init(); //while (!Debugger.IsAttached) // Thread.Sleep(200); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console.OutputEncoding = Encoding.Unicode; } IshtarCore.INIT(); INIT_VTABLES(); IshtarGC.INIT(); FFI.INIT(); AppVault.CurrentVault = new AppVault("app"); var masterModule = default(IshtarAssembly); var resolver = default(AssemblyResolver); if (AssemblyBundle.IsBundle(out var bundle)) { resolver = AppVault.CurrentVault.GetResolver(); masterModule = bundle.Assemblies.First(); resolver.AddInMemory(bundle); } else { if (args.Length < 1) { return(-1); } var entry = new FileInfo(args.First()); if (!entry.Exists) { return(-2); } AppVault.CurrentVault.WorkDirecotry = entry.Directory; resolver = AppVault.CurrentVault.GetResolver(); masterModule = IshtarAssembly.LoadFromFile(entry); resolver.AddSearchPath(entry.Directory); } var module = resolver.Resolve(masterModule); foreach (var @class in module.class_table.OfType <RuntimeIshtarClass>()) { @class.init_vtable(); VM.ValidateLastError(); } var entry_point = module.GetEntryPoint(); if (entry_point is null) { VM.FastFail(WNE.MISSING_METHOD, $"Entry point in '{module.Name}' module is not defined.", IshtarFrames.EntryPoint); VM.ValidateLastError(); return(-280); } var args_ = stackalloc stackval[1]; var frame = new CallFrame { args = args_, method = entry_point, level = 0 }; {// i don't know why IshtarCore.INIT_ADDITIONAL_MAPPING(); INIT_VTABLES(); } var watcher = Stopwatch.StartNew(); VM.exec_method(frame); if (frame.exception is not null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"unhandled exception '{frame.exception.value->decodeClass().Name}' was thrown. \n" + $"{frame.exception.stack_trace}"); Console.ForegroundColor = ConsoleColor.White; } watcher.Stop(); Console.WriteLine($"Elapsed: {watcher.Elapsed}"); return(0); }