public PeRunner(PeRunnerOptions opt) { _nextStart = opt.StartAddress; Initialize(_nextStart); using (this.EnterExit()) { // load any predefined exports _psx = new Psx(this); _exports.Add("libpsxscl.so", BizExvoker.GetExvoker(_psx, CallingConventionAdapters.Waterbox)); _emu = new Emu(this); _exports.Add("libemuhost.so", BizExvoker.GetExvoker(_emu, CallingConventionAdapters.Waterbox)); _syscalls = new Syscalls(this); _exports.Add("__syscalls", BizExvoker.GetExvoker(_syscalls, CallingConventionAdapters.Waterbox)); // load and connect all modules, starting with the executable var todoModules = new Queue <string>(); todoModules.Enqueue(opt.Filename); while (todoModules.Count > 0) { var moduleName = todoModules.Dequeue(); if (!_exports.ContainsKey(moduleName)) { var path = Path.Combine(opt.Path, moduleName); var gzpath = path + ".gz"; byte[] data; if (File.Exists(gzpath)) { using (var fs = new FileStream(gzpath, FileMode.Open, FileAccess.Read)) { data = Util.DecompressGzipFile(fs); } } else { data = File.ReadAllBytes(path); } var module = new PeWrapper(moduleName, data, _nextStart); ComputeNextStart(module.Size); AddMemoryBlock(module.Memory, moduleName); _savestateComponents.Add(module); _disposeList.Add(module); _exports.Add(moduleName, module); _modules.Add(module); foreach (var name in module.ImportsByModule.Keys) { todoModules.Enqueue(name); } } } _libcpatch = new LibcPatch(this); _exports["libc.so"] = new PatchImportResolver(_exports["libc.so"], BizExvoker.GetExvoker(_libcpatch, CallingConventionAdapters.Waterbox)); ConnectAllImports(); // load all heaps _heap = CreateHeapHelper(opt.SbrkHeapSizeKB, "brk-heap", true); _sealedheap = CreateHeapHelper(opt.SealedHeapSizeKB, "sealed-heap", true); _invisibleheap = CreateHeapHelper(opt.InvisibleHeapSizeKB, "invisible-heap", false); _plainheap = CreateHeapHelper(opt.PlainHeapSizeKB, "plain-heap", true); if (opt.MmapHeapSizeKB != 0) { _mmapheap = new MapHeap(_nextStart, opt.MmapHeapSizeKB * 1024, "mmap-heap"); _mmapheap.Memory.Activate(); ComputeNextStart(opt.MmapHeapSizeKB * 1024); AddMemoryBlock(_mmapheap.Memory, "mmap-heap"); _savestateComponents.Add(_mmapheap); _disposeList.Add(_mmapheap); } _syscalls.Init(); Console.WriteLine("About to enter unmanaged code"); if (!OSTailoredCode.IsUnixHost && !System.Diagnostics.Debugger.IsAttached && Win32Imports.IsDebuggerPresent()) { // this means that GDB or another unconventional debugger is attached. // if that's the case, and it's observing this core, it probably wants a break System.Diagnostics.Debugger.Break(); } // run unmanaged init code var libcEnter = _exports["libc.so"].GetProcAddrOrThrow("__libc_entry_routine"); var psxInit = _exports["libpsxscl.so"].GetProcAddrOrThrow("__psx_init"); var del = (LibcEntryRoutineD)CallingConventionAdapters.Waterbox.GetDelegateForFunctionPointer(libcEnter, typeof(LibcEntryRoutineD)); // the current mmglue code doesn't use the main pointer at all, and this just returns del(IntPtr.Zero, psxInit, 0); foreach (var m in _modules) { m.RunGlobalCtors(); } /*try * { * _modules[0].RunExeEntry(); * //throw new InvalidOperationException("main() returned!"); * } * catch //(EndOfMainException) * { * } * _modules[0].RunGlobalCtors(); * foreach (var m in _modules.Skip(1)) * { * if (!m.RunDllEntry()) * throw new InvalidOperationException("DllMain() returned false"); * m.RunGlobalCtors(); * }*/ } }
private async void btnControlsConfigure_Click(object sender, RoutedEventArgs e) { // get button name Button button = (Button)sender; string name = button.Name; // remove beginning and end name = name.Replace("btn", "").Replace("Configure", ""); // get the relevant combox ComboBox cb = (ComboBox)this.FindName("cmb" + name); // get the virtual port number string selectedString = cb.SelectionBoxItem.ToString(); int portNum = Convert.ToInt32(selectedString.Replace("Virtual Port ", "")); DeviceDefinition dev = new DeviceDefinition(); switch (name) { case "PsxGamePad": dev = Psx.DigitalGamePad(portNum); break; case "PsxDualAnalogGamepad": dev = Psx.DualAnalog(portNum); break; case "PsxDualShockGamepad": dev = Psx.DualShock(portNum); break; case "PsxNegconGamepad": dev = Psx.NeGcon(portNum); break; case "PsxDancepad": dev = Psx.DancePad(portNum); break; case "PsxGunCon": dev = Psx.GunCon(portNum); break; case "PsxJustifier": dev = Psx.Justifier(portNum); break; case "PsxMouse": dev = Psx.Mouse(portNum); break; default: return; } mw.ControllerDefinition = dev; // launch controller configuration window Grid RootGrid = (Grid)mw.FindName("RootGrid"); await mw.ShowChildWindowAsync(new ConfigureController() { IsModal = true, AllowMove = false, Title = "Controller Configuration", CloseOnOverlay = false, CloseByEscape = false, ShowCloseButton = false }, RootGrid); }