/// <summary> /// Get handle into the current process /// </summary> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The handle to the object</returns> public NtResult <NtObject> GetObject(bool throw_on_error) { NtToken.EnableDebugPrivilege(); using (var result = NtGeneric.DuplicateFrom(ProcessId, new IntPtr(Handle), 0, DuplicateObjectOptions.SameAccess | DuplicateObjectOptions.SameAttributes, throw_on_error)) { if (!result.IsSuccess) { return(result.Cast <NtObject>()); } NtGeneric generic = result.Result; // Ensure that we get the actual type from the handle. NtType = generic.NtType; return(generic.ToTypedObject(throw_on_error).Cast <NtObject>()); } }
/// <summary> /// Get handle into the current process /// </summary> /// <returns>The handle to the object</returns> public NtObject GetObject() { NtToken.EnableDebugPrivilege(); try { using (NtGeneric generic = NtGeneric.DuplicateFrom(ProcessId, new IntPtr(Handle))) { // Ensure that we get the actual type from the handle. NtType = generic.NtType; return(generic.ToTypedObject()); } } catch { } return(null); }