internal int GetCurrentThreadInternal() { uint id; SystemObjects.GetCurrentThreadId(out id); return((int)id); }
int IDebugEventCallbacksWide.CreateThread(ulong Handle, ulong DataOffset, ulong StartOffset) { uint id, tid, pindex, pid; SystemObjects.GetCurrentProcessId(out pindex); SystemObjects.GetCurrentThreadId(out id); SystemObjects.GetCurrentProcessSystemId(out pid); SystemObjects.GetCurrentThreadSystemId(out tid); Debug.Assert(tid > 0 && pid > 0); var process = _processes.First(p => p.PID == pid); var thread = new TargetThread(process) { Index = id, TID = tid, StartAddress = StartOffset, Teb = DataOffset, Handle = Handle, ProcessIndex = pindex }; process.AddThread(thread); OnThreadCreated(new ThreadCreatedEventArgs(thread, process)); return((int)DEBUG_STATUS.NO_CHANGE); }
//private DebugTarget GetTarget(int i) { // if (SystemObjects.SetCurrentProcessId((uint)i) < 0) // return null; // DEBUG_CLASS debugClass; // DEBUG_CLASS_QUALIFIER qualifier; // Control.GetDebuggeeType(out debugClass, out qualifier); // switch (debugClass) { // case DEBUG_CLASS.IMAGE_FILE: // break; // } // return null; //} //public Task SetCurrentTarget(DebugTarget target) { // return RunAsync(() => { // var id = _targets.IndexOf(target); // if (id < 0) // return; // uint currentId; // SystemObjects.GetCurrentProcessId(out currentId); // if (currentId != id) { // SystemObjects.SetCurrentProcessId((uint)id); // Control.OutputPromptWide(DEBUG_OUTCTL.THIS_CLIENT, null); // } // }); //} public Task <int> SetCurrentThreadIndex(int index) { return(RunAsync(() => { uint id; SystemObjects.GetCurrentThreadId(out id).ThrowIfFailed(); SystemObjects.SetCurrentThreadId((uint)index).ThrowIfFailed(); return (int)id; })); }
ulong GetThreadTeb(uint index) { uint id; ulong teb; SystemObjects.GetCurrentThreadId(out id).ThrowIfFailed(); SystemObjects.SetCurrentThreadId(index).ThrowIfFailed(); SystemObjects.GetCurrentThreadTeb(out teb); return(teb); }
int IDebugEventCallbacksWide.CreateProcess(ulong ImageFileHandle, ulong Handle, ulong BaseOffset, uint ModuleSize, string ModuleName, string ImageName, uint CheckSum, uint TimeDateStamp, ulong InitialThreadHandle, ulong ThreadDataOffset, ulong StartOffset) { Debug.WriteLine("IDebugEventCallbacksWide.CreateProcess"); uint id; SystemObjects.GetCurrentProcessId(out id); ulong peb; SystemObjects.GetCurrentProcessPeb(out peb); uint pid; SystemObjects.GetCurrentProcessSystemId(out pid); var process = new TargetProcess { PID = pid, hProcess = Handle, hFile = ImageFileHandle, BaseOffset = BaseOffset, ModuleSize = ModuleSize, ImageName = ImageName, TimeStamp = DateTime.FromFileTime(TimeDateStamp), ModuleName = ModuleName, Index = (int)id, Peb = peb }; _processes.Add(process); OnProcessCreated(process); uint tindex, tid; SystemObjects.GetCurrentThreadId(out tindex); SystemObjects.GetCurrentThreadSystemId(out tid); var thread = new TargetThread(process) { Index = tindex, TID = tid, StartAddress = StartOffset, Teb = ThreadDataOffset, Handle = InitialThreadHandle, ProcessIndex = id }; process.AddThread(thread); OnThreadCreated(new ThreadCreatedEventArgs(thread, process)); return((int)DEBUG_STATUS.NO_CHANGE); }
int IDebugEventCallbacksWide.ExitThread(uint ExitCode) { uint id, pindex, tid, pid; SystemObjects.GetCurrentThreadId(out id); SystemObjects.GetCurrentProcessId(out pindex); SystemObjects.GetCurrentProcessSystemId(out pid); SystemObjects.GetCurrentThreadSystemId(out tid); var process = _processes.First(p => p.PID == pid); var thread = process.Threads.First(t => t.TID == tid); thread.ExitCode = ExitCode; process.RemoveThread(thread); OnThreadExited(new ThreadExitedEventArgs(thread, process)); return((int)DEBUG_STATUS.NO_CHANGE); }