/// <summary> /// Kicks the player from the server with a specified message. /// </summary> /// <param name="message">The kick reason.</param> public void Kick(string message) { if (pkick) { return; } pkick = true; if (UsedNow != null && ((Entity)UsedNow).IsSpawned) { UsedNow.StopUse(this); } if (Network.Alive) { SendMessage(TextChannel.IMPORTANT, "Kicking you: " + message); Network.Alive = false; Network.PrimarySocket.Close(5); } // TODO: Broadcast kick message SysConsole.Output(OutputType.INFO, "Kicking " + this.ToString() + ": " + message); if (IsSpawned && !Removed) { ItemStack it = Items.GetItemForSlot(Items.cItem); it.Info.SwitchFrom(this, it); HookItem.RemoveHook(this); RemoveMe(); } string nl = Name.ToLower(); string fn = "server_player_saves/" + nl[0].ToString() + "/" + nl + ".plr"; SaveToYAML(PlayerConfig); TheServer.Files.WriteText(fn, PlayerConfig.SaveToString()); }
/// <summary> /// Gets the translations for object. /// </summary> /// <param name="filter"></param> /// <param name="descriptionType">Type of the description.</param> /// <returns>DescriptionItem[].</returns> /// <exception cref="System.NotImplementedException"></exception> public DescriptionItem[] GetTranslationsForObject(HookItem filter) { return(TaxonomyPortal .Descriptions .GetDescriptionsForObject(filter.Id, filter.DisplayName) .ToDescriptionItem()); }
/// <summary> /// Gets the enumerations. /// </summary> /// <param name="root">The root.</param> /// <returns>DescriptionItem[].</returns> /// <exception cref="System.NotImplementedException"></exception> public HookItem[] GetEnumerations(HookItem root) { return(TaxonomyPortal .Hooks .GetEnumerationsForType(root.TypeId) .ToEnumerationItem()); }
/// <summary> /// Gets the hook items. /// </summary> /// <param name="root">The root.</param> /// <returns>HookItem[].</returns> /// <exception cref="NotImplementedException"></exception> public HookItem[] GetHookItems(HookItem root) { Hook[] res = TaxonomyPortal .Hooks .GetChildren(root.ToHook()); return(res.ToHookItem()); }
/// <summary> /// Gets the hook items. /// </summary> /// <param name="root">The root.</param> /// <returns>HookItem[].</returns> /// <exception cref="NotImplementedException"></exception> public HookItem[] GetHookItems(HookItem root) { return(ManageTaxoPortal .Agent .GetHookItems(root)); //return ManageTaxoProvider // .Worker // .GetHookItems(root); }
/// <summary> /// Refreshes the descriptions. /// </summary> /// <param name="filter">The filter.</param> private void RefreshDescriptions(HookItem filter) { ManageTaxoPortal .Agent .GetTranslationsForObjectAsync(filter, (x) => { Documents = new ObservableCollection <DescriptionItem>(x); }); }
/// <summary> /// To the hook. /// </summary> /// <param name="item">The item.</param> /// <returns>Hook.</returns> public static Hook ToHook(this HookItem item) { return(new Hook() { Id = item.Id, DisplayName = item.DisplayName, AdditionalInfoUri = item.AdditionalInfoUri, ObjectId = item.ObjectId, ParentId = item.ParentId, TypeId = item.TypeId }); }
/// <summary> /// Gets the enumeration items. /// </summary> /// <param name="root">The root.</param> /// <returns>EnumerationItem[].</returns> public HookItem[] GetHookItems(HookItem root) { var clt = CreateClient(); try { return(clt.GetHookItems(root)); } finally { CloseClient(clt); } }
/// <summary> /// Gets the translations for object. /// </summary> /// <param name="filter">The filter.</param> /// <returns>DescriptionItem[].</returns> /// <exception cref="System.NotImplementedException"></exception> public DescriptionItem[] GetTranslationsForObject(HookItem filter) { var clt = CreateClient(); try { return(clt.GetTranslationsForObject(filter)); } finally { CloseClient(clt); } }
/// <summary> /// Gets the translations for object asynchronous. /// </summary> /// <param name="filter">The filter.</param> /// <param name="act">The act.</param> public void GetTranslationsForObjectAsync(HookItem filter, Action <DescriptionItem[]> act) { DescriptionItem[] result = null; using (var wrk = new BackgroundWorker()) { wrk.DoWork += (s, d) => { result = GetTranslationsForObject(filter); }; wrk.RunWorkerCompleted += (s, e) => { if (act != null) { act(result); } }; wrk.RunWorkerAsync(); }; }
private static void SetThreadHook(HookItem item, bool remove) { var ctx = new ThreadContext(); ctx.ContextFlags = 65559; foreach (IntPtr openThreadHandle in OpenThreadHandles) { SuspendThread(openThreadHandle); GetThreadContext(openThreadHandle, ref ctx); SetDebugRegisters(item.Register, item.Location, ref ctx, remove); item.Hooked = !remove; SetThreadContext(openThreadHandle, ref ctx); ResumeThread(openThreadHandle); } }
/// <summary> /// Gets the enumeration items asynchronous. /// </summary> /// <param name="root">The root.</param> /// <param name="act">The act.</param> public void GetHookItemsAsync(HookItem root, Action <HookItem[]> act) { HookItem[] result = null; using (var wrk = new BackgroundWorker()) { wrk.DoWork += (s, d) => { result = GetHookItems(root); }; wrk.RunWorkerCompleted += (s, e) => { if (act != null) { act(result); } }; wrk.RunWorkerAsync(); }; }
public HardwareBreakpointHook(HookRegister register, uint hookLocation, HandleHookCallback callback) { var i = new HookItem { Callback = callback, Location = hookLocation, Register = register }; _hook = i; Hooks.Add(i); _hookCount++; // So basically, DR hooks work off "waiting for a debug event" basically. // In actuality we're waiting on an exception, but for the sake of wrapping a hook, // we'll do it in a separate thread. This means we need to ensure we close the thread (IsBackground) when the app closes // and ensure we only ever create *one* polling thread. if (_hookCount == 0 || _workerThread == null) { _workerThread = new Thread(() => InstallHardwareHook()); _workerThread.IsBackground = true; _workerThread.Start(); } SetThreadHook(i, false); }
/// <summary> /// Gets the translations for object. /// </summary> /// <param name="filter">The filter.</param> /// <returns>DescriptionItem[].</returns> /// <exception cref="System.NotImplementedException"></exception> public DescriptionItem[] GetTranslationsForObject(HookItem filter) { return(ManageTaxoProvider .Worker .GetTranslationsForObject(filter)); }
/// <summary> /// Gets the enumerations. /// </summary> /// <param name="root">The root.</param> /// <returns>DescriptionItem[].</returns> /// <exception cref="System.NotImplementedException"></exception> public HookItem[] GetHookItems(HookItem root) { return(ManageTaxoProvider .Worker .GetHookItems(root)); }
/// <summary> /// Gets the hook items. /// </summary> /// <param name="root">The root.</param> /// <returns>HookItem[].</returns> /// <exception cref="NotImplementedException"></exception> public HookItem[] GetHookItems(HookItem root) { return ManageTaxoPortal .Agent .GetHookItems(root); //return ManageTaxoProvider // .Worker // .GetHookItems(root); }
public static void InstallHardwareHook() { Process proc = GeneralHelper.GetCurrentProcess; // Open the proc with full privs so we can attach the debugger later. OpenProcess(0x1FFFFFu, false, (uint)proc.Id); // Open all the threads for use with installing/removing the DR hooks OpenAllThreads(proc); /* * // Ideally should never be hit, but we just need to ensure we check it anyway. * if (!_debugActiveAlready && !DebugActiveProcess((uint)proc.Id)) * throw new Exception("Failed to attach debugger!");*/ MessageBox.Show("Attatch now!"); _debugActiveAlready = true; DebugSetProcessKillOnExit(0); try { while (!_removeHook) { // Useless double-checking of hook states. Sanity really... if (Hooks.Any(i => !i.Hooked)) { foreach (HookItem hookItem in Hooks) { if (!hookItem.Hooked) { SetThreadHook(hookItem, false); } } } // And begin waiting for debug events... var ctx = new ThreadContext(); ctx.ContextFlags = 0x10017; DEBUG_EVENT evt; if (!WaitForDebugEvent(out evt, 0xFFFFFFFF)) { continue; } if (evt.Exception.ExceptionRecord.ExceptionCode != 0x80000004) // EXCEPTION_SINGLE_STEP { ContinueDebugEvent((uint)evt.dwProcessId, (uint)evt.dwThreadId, 0x80010001); // EXCEPTION_CONTINUE } else { // Re-open the thread so we can get the context info we need. IntPtr hThread = OpenThread(0x1FFFFFu, false, (uint)evt.dwThreadId); GetThreadContext(hThread, ref ctx); ctx.EFlags |= 0x10040; // CONTEXT_FULL // NOTE: The callback "call" part is in a catch-all exception handler. // This is to prevent people from crashing the application with the DR hook installed. // This won't stop people from breaking the context though! // Feel free to modify this to ensure people see the exception if need be. try { // Call our callback! // Find it by the location we Hooked it to (eip is the current address FYI) HookItem hook = Hooks.FirstOrDefault(h => (uint)h.Location == ctx.Eip); if (hook != null) { hook.Callback(ref ctx); } } catch { } // Set the new thread context (if it was changed) SetThreadContext(hThread, ref ctx); // And we're done with the thread. CloseHandle(hThread); // Move along... ContinueDebugEvent((uint)evt.dwProcessId, (uint)evt.dwThreadId, 0x10002u); } } } finally { // Thread is closing, or something else is making this function "leave" // Make sure we drop all the DR hooks to make sure we don't start spewing exceptions at the client. foreach (HookItem hookItem in Hooks) { if (hookItem.Hooked) { SetThreadHook(hookItem, true); } } } }