Binarysharp.MemoryManagement.Threading.ThreadCore.GetThreadSelectorEntry C# (CSharp) Méthode

GetThreadSelectorEntry() public static méthode

Retrieves a descriptor table entry for the specified selector and thread.
public static GetThreadSelectorEntry ( SafeMemoryHandle threadHandle, uint selector ) : LdtEntry
threadHandle Binarysharp.MemoryManagement.Native.SafeMemoryHandle A handle to the thread containing the specified selector.
selector uint The global or local selector value to look up in the thread's descriptor tables.
Résultat Binarysharp.MemoryManagement.Native.LdtEntry
        public static LdtEntry GetThreadSelectorEntry(SafeMemoryHandle threadHandle, uint selector)
        {
            // Check if the handle is valid
            HandleManipulator.ValidateAsArgument(threadHandle, "threadHandle");

            // Get the selector entry
            LdtEntry entry;
            if (NativeMethods.GetThreadSelectorEntry(threadHandle, selector, out entry))
                return entry;

            // Else couldn't get the selector entry, throws an exception
            throw new Win32Exception(string.Format("Couldn't get the selector entry for this selector: {0}.", selector));
        }

Usage Example

Exemple #1
0
        /// <summary>
        ///     Gets the linear address of a specified segment.
        /// </summary>
        /// <param name="segment">The segment to get.</param>
        /// <returns>A <see cref="IntPtr" /> pointer corresponding to the linear address of the segment.</returns>
        public IntPtr GetRealSegmentAddress(SegmentRegisters segment)
        {
            // Get a selector entry for the segment
            LdtEntry entry;

            switch (segment)
            {
            case SegmentRegisters.Cs:
                entry = ThreadCore.GetThreadSelectorEntry(Handle, Context.SegCs);
                break;

            case SegmentRegisters.Ds:
                entry = ThreadCore.GetThreadSelectorEntry(Handle, Context.SegDs);
                break;

            case SegmentRegisters.Es:
                entry = ThreadCore.GetThreadSelectorEntry(Handle, Context.SegEs);
                break;

            case SegmentRegisters.Fs:
                entry = ThreadCore.GetThreadSelectorEntry(Handle, Context.SegFs);
                break;

            case SegmentRegisters.Gs:
                entry = ThreadCore.GetThreadSelectorEntry(Handle, Context.SegGs);
                break;

            case SegmentRegisters.Ss:
                entry = ThreadCore.GetThreadSelectorEntry(Handle, Context.SegSs);
                break;

            default:
                throw new InvalidEnumArgumentException("segment");
            }

            // Compute the linear address
            return(new IntPtr(entry.BaseLow | (entry.BaseMid << 16) | (entry.BaseHi << 24)));
        }