public Wrap(RemoteHooking.IContext context, RuntimeParams parms) { DebugLogger.WriteLine("Wrap created"); }
public void Run(RemoteHooking.IContext context, RuntimeParams parms) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", false); try { RuntimeProfile profile; using (var fs = new FileStream(parms.ProfileFile, FileMode.Open)) { profile = Iros._7th.Util.DeserializeBinary <RuntimeProfile>(fs); } File.Delete(parms.ProfileFile); if (!String.IsNullOrWhiteSpace(profile.LogFile)) { try { try { File.Delete(profile.LogFile); } catch { } // ensure old log is deleted since new run DebugLogger.Init(profile.LogFile); DebugLogger.IsDetailedLogging = profile.Options.HasFlag(RuntimeOptions.DetailedLog); DebugLogger.WriteLine("Logging debug output to " + profile.LogFile); } catch (Exception ex) { DebugLogger.WriteLine("Failed to log debug output: " + ex.ToString()); } } DebugLogger.WriteLine($"Wrap run... Host: {context.HostPID} PID: {RemoteHooking.GetCurrentProcessId()} TID: {RemoteHooking.GetCurrentThreadId()} Path: {profile.ModPath} Capture: {String.Join(", ", profile.MonitorPaths)}"); //_overrides = new Overrides(basepath); _profile = profile; for (int i = _profile.MonitorPaths.Count - 1; i >= 0; i--) { if (!_profile.MonitorPaths[i].EndsWith(System.IO.Path.DirectorySeparatorChar.ToString())) { _profile.MonitorPaths[i] += System.IO.Path.DirectorySeparatorChar; } if (String.IsNullOrWhiteSpace(_profile.MonitorPaths[i])) { _profile.MonitorPaths.RemoveAt(i); } } foreach (var item in profile.Mods) { DebugLogger.WriteLine($" Mod: {item.BaseFolder} has {item.Conditionals.Count} conditionals"); DebugLogger.WriteLine(" Additional paths: " + String.Join(", ", item.ExtraFolders)); item.Startup(); } _hCreateFileW = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "CreateFileW"), new DCreateFile(HCreateFileW), this); _hCreateFileW.ThreadACL.SetExclusiveACL(new[] { 0 }); //_hCreateFileA = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "CreateFileA"), new DCreateFileA(HCreateFileA), this); //_hCreateFileA.ThreadACL.SetExclusiveACL(new[] { 0 }); //int init = Init7W(); //_hReadFile = LocalHook.CreateUnmanaged(LocalHook.GetProcAddress("kernel32.dll", "ReadFile"), LocalHook.GetProcAddress("7thWrapperNLib.dll", "ReadFile7W"), IntPtr.Zero); _hReadFile = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "ReadFile"), new DReadFile(HReadFile), this); _hReadFile.ThreadACL.SetExclusiveACL(new[] { 0 }); _hWriteFile = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "WriteFile"), new DWriteFile(HWriteFile), this); _hWriteFile.ThreadACL.SetExclusiveACL(new[] { 0 }); _hFindFirstFile = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "FindFirstFileW"), new DFindFirstFileW(HFindFirstFile), this); _hFindFirstFile.ThreadACL.SetExclusiveACL(new[] { 0 }); //_hFindFirstFileA = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "FindFirstFileA"), new DFindFirstFileA(HFindFirstFileA), this); //_hFindFirstFile.ThreadACL.SetExclusiveACL(new[] { 0 }); _hSetFilePointer = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "SetFilePointer"), new DSetFilePointer(HSetFilePointer), this); _hSetFilePointer.ThreadACL.SetExclusiveACL(new[] { 0 }); _hSetFilePointerEx = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "SetFilePointerEx"), new DSetFilePointerEx(HSetFilePointerEx), this); _hSetFilePointerEx.ThreadACL.SetExclusiveACL(new[] { 0 }); _hCloseHandle = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "CloseHandle"), new DCloseHandle(HCloseHandle), this); _hCloseHandle.ThreadACL.SetExclusiveACL(new[] { 0 }); _hGetFileType = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "GetFileType"), new DGetFileType(HGetFileType), this); _hGetFileType.ThreadACL.SetExclusiveACL(new[] { 0 }); _hGetFileInformationByHandle = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "GetFileInformationByHandle"), new DGetFileInformationByHandle(HGetFileInformationByHandle), this); _hGetFileInformationByHandle.ThreadACL.SetExclusiveACL(new[] { 0 }); //_hReadFileEx = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "ReadFileEx"), new DReadFileEx(HReadFileEx), this); //_hReadFileEx.ThreadACL.SetExclusiveACL(new[] { 0 }); _hDuplicateHandle = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "DuplicateHandle"), new DDuplicateHandle(HDuplicateHandle), this); _hDuplicateHandle.ThreadACL.SetExclusiveACL(new[] { 0 }); _hCreateProcessW = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "CreateProcessW"), new DCreateProcessW(HCreateProcessW), this); _hCreateProcessW.ThreadACL.SetExclusiveACL(new[] { 0 }); _hGetFileSize = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "GetFileSize"), new DGetFileSize(HGetFileSize), this); _hGetFileSize.ThreadACL.SetExclusiveACL(new[] { 0 }); _hGetFileSizeEx = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "GetFileSizeEx"), new DGetFileSizeEx(HGetFileSizeEx), this); _hGetFileSizeEx.ThreadACL.SetExclusiveACL(new[] { 0 }); if (profile.MonitorVars != null) { new System.Threading.Thread(MonitorThread) { IsBackground = true } } .Start(profile); //System.Threading.Thread.Sleep(10000); RemoteHooking.WakeUpProcess(); System.Threading.Thread.Sleep(1000); foreach (string LL in profile.Mods.SelectMany(m => m.GetLoadLibraries())) { DebugLogger.WriteLine($"Loading library DLL {LL}"); LoadLibrary(LL); } foreach (var mod in profile.Mods) { foreach (string LA in mod.GetLoadAssemblies()) { DebugLogger.WriteLine($"Loading assembly DLL {LA}"); var asm = System.Reflection.Assembly.LoadFrom(LA); try { string path = mod.BaseFolder; asm.GetType("_7thHeaven.Main") .GetMethod("Init", new[] { typeof(RuntimeMod) }) .Invoke(null, new object[] { mod }); } catch { } } } foreach (var mod in profile.Mods) { foreach (string file in mod.GetPathOverrideNames("hext")) { foreach (var of in mod.GetOverrides("hext\\" + file)) { System.IO.Stream s; if (of.Archive == null) { s = new System.IO.FileStream(of.File, FileMode.Open, FileAccess.Read); } else { s = of.Archive.GetData(of.File); } DebugLogger.WriteLine($"Applying hext patch {file} from mod {mod.BaseFolder}"); try { HexPatch.Apply(s); } catch (Exception ex) { DebugLogger.WriteLine("Error applying patch: " + ex.Message); } } } } } catch (Exception e) {
public Wrap(RemoteHooking.IContext context, RuntimeParams parms) { System.Diagnostics.Debug.WriteLine("Wrap created"); }