private string GetError(AttachResult result) { switch (result) { case AttachResult.UnknownException: return("Unknown error"); case AttachResult.NoError: return(""); case AttachResult.VisualStudioInstanceNotFound: return("Could not find Visual Studio instance"); case AttachResult.TargetApplicatioNotFound: return("Could not find target application to attach"); case AttachResult.InvalidEngine: return("Invalid debugging engine, change your selection in the target definition"); case AttachResult.NoEngineSelected: return("No debugging engine selected"); default: throw new ArgumentOutOfRangeException(nameof(result), result, null); } }
private void ExitButton_Click(object sender, System.Windows.RoutedEventArgs e) { bool?result = LSMessageBox.YNShow("退出", "确认完成实验?"); if (result == true) { int count = 0; foreach (UploadFile uf in upfiles) { if (uf.Status.Equals(UploadFile.FAIL)) { count++; } } if (count != 0) { LSMessageBox.Show("退出", "检测到您还有" + count + "个实验数据未提交成功,请全部重新上传后再点击完成实验"); return; } List <int> ids = new List <int>(); foreach (Student s in CacheService.Instance.GetStudentList()) { ids.Add(s.RecordId); } AttachResult ar = rf.FinishExperiment(CacheService.Instance.ExperimentId, ids, CacheService.Instance.GetStuToken()); if (ar != null) { if (ar.code == "200") { if (device != null) { device.SignalToStop(); device.WaitForStop(); } if (device2 != null) { device2.SignalToStop(); device2.WaitForStop(); } Application.Current.Shutdown(); } else { LSMessageBox.Show("完成实验异常", ar.message); } } else { LSMessageBox.Show("网络错误", "网络异常"); } } }
private AttachResult PessimisticAttach(AttachType attachType) { AttachResult res = Attach(attachType); DateTime timeout = DateTime.Now.AddSeconds(_waitTimeout); while (res == AttachResult.NotRunning && timeout > DateTime.Now) { res = Attach(attachType); System.Threading.Thread.Sleep(100); } return res; }
private void UploadButton_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { String token = CacheService.Instance.GetStuToken(); FileResult fr = rf.UploadFile(openFileDialog.FileName, token); //获取文件名字 String file_name = openFileDialog.FileName.Split('\\')[openFileDialog.FileName.Split('\\').Length - 1]; if (fr != null) { if (fr.code == "200") { //关联文件与记录 List <Attach> attaches = new List <Attach>(); foreach (Student s in CacheService.Instance.GetStudentList()) { Attach a = new Attach { subjectId = s.RecordId, ownerId = s.Id, type = "EXPERIMENT_RECORD_FILE" }; attaches.Add(a); } AttachResult ar = rf.AttachRecordWithFile(CacheService.Instance.ExperimentId, fr.data.id, attaches, CacheService.Instance.GetStuToken()); if (ar != null) { if (ar.code == "200") { UploadFile up = new UploadFile() { FileName = file_name, FileType = UploadFile.EXPERIMENT, Status = UploadFile.SUCCESS, FilePath = openFileDialog.FileName, Id = fr.data.id, Color = "#FF979797", Operation = UploadFile.OPENDOC }; upfiles.Add(up); fileList.Items.Refresh(); } else { LSMessageBox.Show("关联文件错误", ar.message); UploadFile up = new UploadFile() { FileName = file_name, FileType = UploadFile.EXPERIMENT, Status = UploadFile.FAIL, FilePath = openFileDialog.FileName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; upfiles.Add(up); fileList.Items.Refresh(); } } else { LSMessageBox.Show("网络错误", "网络异常"); UploadFile up = new UploadFile() { FileName = file_name, FileType = UploadFile.EXPERIMENT, Status = UploadFile.FAIL, FilePath = openFileDialog.FileName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; upfiles.Add(up); fileList.Items.Refresh(); } } else { LSMessageBox.Show("上传文件错误", fr.message); UploadFile up = new UploadFile() { FileName = file_name, FileType = UploadFile.EXPERIMENT, Status = UploadFile.FAIL, FilePath = openFileDialog.FileName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; upfiles.Add(up); fileList.Items.Refresh(); } } else { LSMessageBox.Show("网络错误", "网络异常"); UploadFile up = new UploadFile() { FileName = file_name, FileType = UploadFile.EXPERIMENT, Status = UploadFile.FAIL, FilePath = openFileDialog.FileName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; upfiles.Add(up); fileList.Items.Refresh(); } } }
private void OpenLabel_MouseDown(object sender, MouseButtonEventArgs e) { Label label = sender as Label; UploadFile uploadFile = null; foreach (UploadFile uf in this.upfiles) { if (uf.FilePath.Equals(label.Tag.ToString())) { uploadFile = uf; } } if (uploadFile != null) { if (label.Content.Equals(UploadFile.OPENDOC)) { String doc = uploadFile.FilePath.Substring(0, uploadFile.FilePath.Length - uploadFile.FilePath.Split('\\')[uploadFile.FilePath.Split('\\').Length - 1].Length); System.Diagnostics.Process.Start("explorer.exe ", doc); } else if (label.Content.Equals(UploadFile.REUPLOAD)) { String token = CacheService.Instance.GetStuToken(); FileResult fr = rf.UploadFile(uploadFile.FilePath, token); //获取文件名字 String file_name = uploadFile.FilePath.Split('\\')[uploadFile.FilePath.Split('\\').Length - 1]; if (fr != null) { if (fr.code == "200") { //关联文件与记录 List <Attach> attaches = new List <Attach>(); foreach (Student s in CacheService.Instance.GetStudentList()) { Attach a = new Attach { subjectId = s.RecordId, ownerId = s.Id, type = "EXPERIMENT_RECORD_FILE" }; attaches.Add(a); } AttachResult ar = rf.AttachRecordWithFile(CacheService.Instance.ExperimentId, fr.data.id, attaches, CacheService.Instance.GetStuToken()); if (ar != null) { if (ar.code == "200") { uploadFile.Status = UploadFile.SUCCESS; uploadFile.Color = "#FF979797"; uploadFile.Operation = UploadFile.OPENDOC; fileList.Items.Refresh(); } else { LSMessageBox.Show("关联文件错误", ar.message); uploadFile.Status = UploadFile.FAIL; uploadFile.Color = "Red"; uploadFile.Operation = UploadFile.REUPLOAD; fileList.Items.Refresh(); } } else { LSMessageBox.Show("网络错误", "网络异常"); uploadFile.Status = UploadFile.FAIL; uploadFile.Color = "Red"; uploadFile.Operation = UploadFile.REUPLOAD; fileList.Items.Refresh(); } } else { LSMessageBox.Show("上传文件错误", fr.message); uploadFile.Status = UploadFile.FAIL; uploadFile.Color = "Red"; uploadFile.Operation = UploadFile.REUPLOAD; fileList.Items.Refresh(); } } else { LSMessageBox.Show("网络错误", "网络异常"); uploadFile.Status = UploadFile.FAIL; uploadFile.Color = "Red"; uploadFile.Operation = UploadFile.REUPLOAD; fileList.Items.Refresh(); } } } }
private void WatchCreated(object sender, FileSystemEventArgs e) { Thread.Sleep(3000); FileInfo fi = new FileInfo(e.FullPath); FileResult fr = rf.UploadFile(fi.FullName, CacheService.Instance.GetStuToken()); if (fr != null) { if (fr.code == "200") { //关联文件与记录 List <Attach> attaches = new List <Attach>(); foreach (Student s in CacheService.Instance.GetStudentList()) { Attach a = new Attach { subjectId = s.RecordId, ownerId = s.Id, type = type }; attaches.Add(a); } AttachResult ar = rf.AttachRecordWithFile(CacheService.Instance.ExperimentId, fr.data.id, attaches, CacheService.Instance.GetStuToken()); if (ar != null) { if (ar.code == "200") { UploadFile up = new UploadFile() { FileName = fi.Name, FileType = fileType, Status = UploadFile.SUCCESS, FilePath = fi.FullName, Id = fr.data.id, Color = "#FF979797", Operation = UploadFile.OPENDOC }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } else { UploadFile up = new UploadFile() { FileName = fi.Name, FileType = fileType, Status = UploadFile.FAIL, FilePath = fi.FullName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } } else { UploadFile up = new UploadFile() { FileName = fi.Name, FileType = fileType, Status = UploadFile.FAIL, FilePath = fi.FullName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } } else { UploadFile up = new UploadFile() { FileName = fi.Name, FileType = fileType, Status = UploadFile.FAIL, FilePath = fi.FullName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } } else { UploadFile up = new UploadFile() { FileName = fi.Name, FileType = fileType, Status = UploadFile.FAIL, FilePath = fi.FullName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } }
public static Result CreateResultObject(string command) { Result result = null; switch (command) { case "attach": result = new AttachResult(); break; case "detach": result = new DetachResult(); break; case "getthreads": result = new ThreadsResult(); break; case "appdomains": result = new AppDomainsResult(); break; case "assemblies": result = new AssembliesResult(); break; case "callstack": result = new CallStackResult(); break; case "setbreakpoint": result = new BreakPointResult(); break; case "exception": result = new ExceptionResult(); break; case "go": result = new GoResult(); break; case "assemblyloadevent": result = new AssemblyLoadResult(); break; case "removebreakpoint": result = new RemoveBreakPointResult(); break; case "arguments": result = new ArgumentsResult(); break; case "members": result = new MembersResult(); break; case "value": result = new MemberValueResult(); break; } return result; }
public static async Task <AttachResult> AttachDebugger(int pid) { if (IsConnected) { return(AttachResult.SUCCESS); } AttachResult result = AttachResult.SUCCESS; DebuggerThread = Task.Run(() => { abort = false; bool success = DebugActiveProcess((uint)pid); if (!success) { result = AttachResult.FAILED; abort = false; debuggerAttaching.Release(); return; } DEBUG_EVENT e = default; if (!WaitForDebugEvent(ref e, 5000) || e.dwDebugEventCode != DebugEventType.CREATE_PROCESS_DEBUG_EVENT) { result = AttachResult.FAILED; DebugActiveProcessStop((uint)pid); abort = false; debuggerAttaching.Release(); return; } IntPtr hProcess = e.CreateProcessInfo.hProcess; IntPtr hThread = e.CreateProcessInfo.hThread; byte[] verify = new byte[verificationData.Length]; ReadProcessMemory(hProcess, verificationAddress, verify, verify.Length, out _); if (!verificationData.SequenceEqual(verify)) { result = AttachResult.BAD_VER; debuggerAttaching.Release(); return; } // Success! Let's go debuggerAttaching.Release(); SetBreakpoint(hProcess); ContinueDebugEvent(e.dwProcessId, e.dwThreadId, ContinueStatus.DBG_CONTINUE); while (!abort) { // Check for abort every 200ms if (!WaitForDebugEvent(ref e, 200)) { continue; } if (e.dwDebugEventCode == DebugEventType.EXCEPTION_DEBUG_EVENT && e.Exception.ExceptionRecord.ExceptionCode == 0x80000003u && e.Exception.ExceptionRecord.ExceptionAddress == breakpoint) { CONTEXT c = default; c.ContextFlags = (uint)CONTEXT_FLAGS.CONTEXT_ALL; GetThreadContext(hThread, ref c); byte[] pad = new byte[4]; ReadProcessMemory(hProcess, new IntPtr(c.Esp - 4), pad, 4, out _); int i = BitConverter.ToInt32(pad, 0); if (i == 0) { if (reporting) { for (uint i1 = last, i2 = c.Eax, n = 0; n < 8; i1 >>= 1, i2 >>= 1, n++) { if ((i1 & 1) != (i2 & 1)) { Recorder.RecordInput((i2 & 1) == 1, new NESInput((NESKeys)n)); } } } last = c.Eax; } c.Eip--; c.EFlags |= 0x100; // Set trap flag (single step) SetThreadContext(hThread, ref c); ResetBreakpoint(hProcess); do { ContinueDebugEvent(e.dwProcessId, e.dwThreadId, ContinueStatus.DBG_CONTINUE); WaitForDebugEvent(ref e, 1000); } while (e.Exception.ExceptionRecord.ExceptionCode != 0x80000004u); if (!abort) { SetBreakpoint(hProcess); } } ContinueDebugEvent(e.dwProcessId, e.dwThreadId, ContinueStatus.DBG_CONTINUE); if (e.dwDebugEventCode == DebugEventType.EXIT_PROCESS_DEBUG_EVENT) // User closed Nestopia { abort = true; } } abort = false; if (e.dwDebugEventCode != DebugEventType.EXIT_PROCESS_DEBUG_EVENT) { ResetBreakpoint(hProcess); DebugActiveProcessStop((uint)pid); debuggerDetaching.Release(); } else { MainForm.Instance?.NestopiaWasDisconnected(); } }); await debuggerAttaching.WaitAsync(); return(result); }
private void videoSourcePlayer_NewFrame(object sender, NewFrameEventArgs eventArgs) { Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone(); if (task.Contains(0)) { String timepath = DateTime.Now.Hour.ToString() + "_" + DateTime.Now.Minute.ToString() + "_" + DateTime.Now.Second.ToString() + "_" + device_id; string img = this.save_path + "\\" + timepath + ".jpg"; bitmap.Save(img); task.Remove(0); FileResult fr = rf.UploadFile(img, CacheService.Instance.GetStuToken()); if (fr != null) { if (fr.code == "200") { //关联文件与记录 List <Attach> attaches = new List <Attach>(); foreach (Student s in CacheService.Instance.GetStudentList()) { Attach a = new Attach { subjectId = s.RecordId, ownerId = s.Id, type = "EXPERIMENT_RECORD_IMAGE" }; attaches.Add(a); } AttachResult ar = rf.AttachRecordWithFile(CacheService.Instance.ExperimentId, fr.data.id, attaches, CacheService.Instance.GetStuToken()); if (ar != null) { if (ar.code == "200") { UploadFile up = new UploadFile() { FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.SUCCESS, FilePath = img, Id = fr.data.id, Color = "#FF979797", Operation = UploadFile.OPENDOC }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } else { UploadFile up = new UploadFile() { FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.FAIL, FilePath = img, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } } else { UploadFile up = new UploadFile() { FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.FAIL, FilePath = img, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } } else { UploadFile up = new UploadFile() { FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.FAIL, FilePath = img, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } } else { UploadFile up = new UploadFile() { FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.FAIL, FilePath = img, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD }; this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up); } } GC.Collect(); }