public void RunCode(int i, int output) { var module = WebAssembly.Compile(Wasm); var caller = module.Instantiate(); Assert.That(caller.Run("main", i), Is.EqualTo(output)); }
public void RunCode() { var module = WebAssembly.Compile(Wasm); var hello42 = module.Instantiate(); Assert.That(hello42.Run("main"), Is.EqualTo(42)); }
public void RunCode() { var module = WebAssembly.Compile(Wasm); var adder = module.Instantiate(); Assert.That(adder.Run("main", 123, 321), Is.EqualTo(444)); }
public void GetExports() { var module = WebAssembly.Compile(Wasm); var exports = module.Exports(); var export = exports.First(); Assert.That(export, Is.EqualTo(new ModuleExportDescriptor(ExternalKind.Function, "main"))); }
public void RunCode() { var module = WebAssembly.Compile(Wasm); var value = 0; var import = new WebAssemblyImports(); import.Add("console", "log", arg => value = arg[0]); var caller = module.Instantiate(import); caller.Run("main"); Assert.That(value, Is.EqualTo(13)); }
public void RunCode() { var module = WebAssembly.Compile(Wasm); var memory = new WebAssemblyMemory(1); var import = new WebAssemblyImports(); import.Add("console", "log", ConsoleLog); import.Add("js", "mem", memory); var caller = module.Instantiate(import); caller.Run("main"); Assert.That(_output, Is.EqualTo("Hello World!")); }
private byte[] GetFile(string filePath) { if (this.theme == null || !this.theme.Exists) { string resourceName = "Gablarski.WebServer.Html." + filePath; Stream resourceStream; if (!ResourceNames.Contains(resourceName) || (resourceStream = WebAssembly.GetManifestResourceStream(resourceName)) == null) { return(null); } byte[] resourceBuffer = new byte[resourceStream.Length]; resourceStream.Read(resourceBuffer, 0, resourceBuffer.Length); return(resourceBuffer); } else { try { FileInfo file = new FileInfo(Path.Combine(theme.FullName, filePath)); if (!file.Exists) { return(null); } var fs = file.OpenRead(); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); return(buffer); } catch { return(null); } } }
public void GetCustomName() { var module = WebAssembly.Compile(Wasm); Assert.That(module.CustomSections("name"), Is.Not.Empty); }
private bool Init(string il2CppPath, string metadataPath, out Metadata metadata, out Il2Cpp il2Cpp) { WriteOutput("Read config...", Color.Black); if (File.Exists(realPath + "config.json")) { _config = JsonConvert.DeserializeObject <Config>(File.ReadAllText(Application.StartupPath + Path.DirectorySeparatorChar + "config.json")); } else { _config = new Config(); WriteOutput("config.json file does not exist. Using defaults", Color.Yellow); } WriteOutput("Initializing metadata..."); var metadataBytes = File.ReadAllBytes(metadataPath); metadata = new Metadata(new MemoryStream(metadataBytes)); WriteOutput($"Metadata Version: {metadata.Version}"); WriteOutput("Initializing il2cpp file..."); var il2CppBytes = File.ReadAllBytes(il2CppPath); var il2CppMagic = BitConverter.ToUInt32(il2CppBytes, 0); var il2CppMemory = new MemoryStream(il2CppBytes); switch (il2CppMagic) { default: WriteOutput("ERROR: il2cpp file not supported."); throw new NotSupportedException("ERROR: il2cpp file not supported."); case 0x6D736100: var web = new WebAssembly(il2CppMemory); il2Cpp = web.CreateMemory(); break; case 0x304F534E: var nso = new NSO(il2CppMemory); il2Cpp = nso.UnCompress(); break; case 0x905A4D: //PE il2Cpp = new PE(il2CppMemory); break; case 0x464c457f: //ELF if (il2CppBytes[4] == 2) //ELF64 { var addressValue = ""; il2Cpp = InputBox.Show("Input il2cpp dump address or leave empty to force continue:", "", ref addressValue) != DialogResult.OK ? string.IsNullOrWhiteSpace(addressValue) ? new Elf64(il2CppMemory) : new Elf64(il2CppMemory, addressValue) : new Elf64(il2CppMemory); } else { var addressValue = ""; il2Cpp = InputBox.Show("Input il2cpp dump address or leave empty to force continue:", "", ref addressValue) != DialogResult.OK ? string.IsNullOrWhiteSpace(addressValue) ? new Elf(il2CppMemory) : new Elf(il2CppMemory, addressValue) : new Elf(il2CppMemory); } break; case 0xCAFEBABE: //FAT Mach-O case 0xBEBAFECA: var machofat = new MachoFat(new MemoryStream(il2CppBytes)); WriteOutput("Select Platform: "); for (var i = 0; i < machofat.fats.Length; i++) { var fat = machofat.fats[i]; WriteOutput(fat.magic == 0xFEEDFACF ? $"{i + 1}.64bit " : $"{i + 1}.32bit "); } WriteOutput(""); var key = Console.ReadKey(true); var index = int.Parse(key.KeyChar.ToString()) - 1; var magic = machofat.fats[index % 2].magic; il2CppBytes = machofat.GetMacho(index % 2); il2CppMemory = new MemoryStream(il2CppBytes); if (magic == 0xFEEDFACF) { goto case 0xFEEDFACF; } else { goto case 0xFEEDFACE; } case 0xFEEDFACF: // 64bit Mach-O il2Cpp = new Macho64(il2CppMemory); break; case 0xFEEDFACE: // 32bit Mach-O il2Cpp = new Macho(il2CppMemory); break; } var version = _config.ForceIl2CppVersion ? _config.ForceVersion : metadata.Version; il2Cpp.SetProperties(version, metadata.maxMetadataUsages); WriteOutput($"Il2Cpp Version: {il2Cpp.Version}"); if (il2Cpp.Version >= 27 && il2Cpp is ElfBase elf && elf.IsDumped) { var metadataValue = ""; if (InputBox.Show("Input global-metadata.dat dump address:", "", ref metadataValue) != DialogResult.OK) { return(false); } metadata.Address = Convert.ToUInt64(metadataValue, 16); WriteOutput($"global-metadata.dat dump address: {metadataValue}"); } WriteOutput("Searching..."); try { var flag = il2Cpp.PlusSearch(metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length, metadata.imageDefs.Length); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !flag && il2Cpp is PE) { WriteOutput("Use custom PE loader"); il2Cpp = PELoader.Load(il2CppPath); il2Cpp.SetProperties(version, metadata.maxMetadataUsages); flag = il2Cpp.PlusSearch(metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length, metadata.imageDefs.Length); } if (!flag) { flag = il2Cpp.Search(); } if (!flag) { flag = il2Cpp.SymbolSearch(); } if (!flag) { WriteOutput("ERROR: Can't use auto mode to process file, try manual mode."); WriteOutput("Input CodeRegistration: "); var codeValue = ""; if (InputBox.Show(@"Input CodeRegistration: ", "", ref codeValue) != DialogResult.OK) { return(false); } var codeRegistration = Convert.ToUInt64(codeValue, 16); WriteOutput($"CodeRegistration: {codeValue}"); var metadataValue = ""; if (InputBox.Show("Input MetadataRegistration: ", "", ref metadataValue) != DialogResult.OK) { return(false); } var metadataRegistration = Convert.ToUInt64(metadataValue, 16); WriteOutput($"MetadataRegistration: {metadataValue}"); il2Cpp.Init(codeRegistration, metadataRegistration); return(true); } } catch (Exception e) { WriteOutput(e.Message); WriteOutput("ERROR: An error occurred while processing."); return(false); } return(true); }
/// <summary> /// Load a template into a <see cref="T:System.IO.TextReader"/> and return it. /// </summary> /// <param name="path">Relative path (and filename) to template.</param> /// <returns> /// a <see cref="T:System.IO.TextReader"/> if file was found; otherwise null. /// </returns> public TextReader LoadTemplate(string path) { var rs = WebAssembly.GetManifestResourceStream(ResourcePrefix + path); return(rs != null ? new StreamReader(rs) : null); }
public ResourceTemplateLoader() { ResourceNames = new HashSet <string> (WebAssembly.GetManifestResourceNames()); }
public void CreateComponents() { Application = new TApplication(null); Application.Initialize(); Application.Run(); var el = WebAssembly.GetElementById("helloWorld"); var lForm = new TForm(null); lForm.Width = 800; // el it's a div element in html file, we are using as container for our form lForm.Show(el); var lFontsPanel = new TPanel(lForm); lFontsPanel.Height = 150; lFontsPanel.Width = 800; lFontsPanel.Parent = lForm; var lFontsCombo = new TComboBox(lForm); lFontsCombo.Left = 30; lFontsCombo.Top = 50; lFontsCombo.Width = 130; // Add combo inside TPanel lFontsCombo.Parent = lFontsPanel; lFontsCombo.Items.Add("Arial"); lFontsCombo.Items.Add("Verdana"); lFontsCombo.Items.Add("Helvetica"); lFontsCombo.Items.Add("Times"); var lFontSize = new TComboBox(lForm); lFontSize.Left = 200; lFontSize.Top = 50; lFontSize.Width = 80; lFontSize.Parent = lFontsPanel; for (var i = 8; i <= 72; i += 4) { lFontSize.Items.Add(i.ToString()); } var lLabel = new TLabel(lForm); lLabel.Left = 320; lLabel.Top = 50; lLabel.Caption = "Choose font name and size!"; lLabel.Parent = lFontsPanel; // Assign combo events lFontsCombo.OnSelect = (a) => { lLabel.Font.Name = lFontsCombo.Text; }; lFontSize.OnSelect = (a) => { lLabel.Font.Size = StrToInt(lFontSize.Text); }; var lSecondPanel = new TPanel(lForm); lSecondPanel.Top = 220; lSecondPanel.Height = 150; lSecondPanel.Width = 800; lSecondPanel.Parent = lForm; var lCheckBox = new TCheckBox(lForm); lCheckBox.Top = 20; lCheckBox.Left = 30; lCheckBox.Caption = "CheckBox control"; lCheckBox.Parent = lSecondPanel; var lRadioButton = new TRadioButton(lForm); lRadioButton.Top = 80; lRadioButton.Left = 30; lRadioButton.Caption = "RadioButton control"; lRadioButton.Parent = lSecondPanel; var lChangeButton = new TButton(lForm); lChangeButton.Left = 220; lChangeButton.Top = 20; lChangeButton.Caption = "Change progress bar mode"; lChangeButton.Parent = lSecondPanel; lChangeButton.OnClick = @ChangeButtonClick; var lIncButton = new TButton(lForm); lIncButton.Left = 220; lIncButton.Top = 80; lIncButton.Caption = "Increase progress bar value"; lIncButton.Parent = lSecondPanel; lIncButton.OnClick = (a) => { fProgress.Position = fProgress.Position + 5; if (fProgress.Position >= fProgress.Max) { fProgress.Position = 0; } }; fProgress = new TProgressBar(lForm); fProgress.Top = 55; fProgress.Left = 420; fProgress.Max = 100; fProgress.Parent = lSecondPanel; }
static FileResourceModule() { ResourceNames = new HashSet <string> (WebAssembly.GetManifestResourceNames()); }
public void IsValid() { Assert.That(WebAssembly.Validate(MinimalValid), Is.True); }