⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntdef.inc

📁 用汇编语言编写Windows驱动程序的工具
💻 INC
📖 第 1 页 / 共 3 页
字号:
comment ^
Module Name:
    ntdef.inc

Abstract:
    Type definitions for the basic types.

Author:
    Four-F (four-f@mail.ru)

Last updated:    
    30-March-2004
    
IMPORTANT:
	Hand made -> Bugs are very possible :(
	Your bug report is very welcome.

Comments:
    Some fields name have been changed because of collision with masm reserved words.
    All such words are prefixed with underscore ('_') symbol.
^

IFNDEF _NTDEF_
_NTDEF_ equ 1

CALLBACK	typedef		proto STDCALL
WINAPI		typedef		proto STDCALL
NTAPI		typedef		proto STDCALL

BOOL		typedef		DWORD

PBYTE		typedef		PTR BYTE
PWORD		typedef		PTR DORD
PDWORD		typedef		PTR DWORD
PVOID		typedef		PTR
PVOID64		typedef		PTR
PCVOID		typedef		PTR
PSTR		typedef		PTR BYTE
PCSTR		typedef		PTR BYTE
PWSTR		typedef		PTR WORD

PDWORD_PTR	typedef		PTR DWORD

UINT		typedef		DWORD

HFILE		typedef		DWORD

IFNDEF ANYSIZE_ARRAY
	ANYSIZE_ARRAY	equ 1	; winnt
ENDIF

comment ^
 #include <basetsd.h>
^

; Basics

char	typedef BYTE
CHAR	typedef BYTE
long	typedef	SDWORD
LONG	typedef	SDWORD

; UNICODE (Wide Character) types

WCHAR	typedef	WORD	; wc,   16-bit UNICODE character
wchar_t	typedef	WORD	; wc,   16-bit UNICODE character

PWCHAR	typedef	PTR WORD
LPWCH	typedef	PTR WORD
PWCH	typedef	PTR WORD

LPCWCH	typedef	PTR WORD
PCWCH	typedef	PTR WORD

NWPSTR	typedef	PTR WORD

LPWSTR	typedef	PTR WORD
PWSTR	typedef	PTR WORD

LPCWSTR	typedef	PTR WORD
PCWSTR	typedef	PTR WORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; ANSI (Multi-byte Character) types
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PCHAR	typedef	PTR BYTE
LPCH	typedef	PTR BYTE
PCH		typedef	PTR BYTE

LPCCH	typedef	PTR BYTE
PCCH	typedef	PTR BYTE

NPSTR	typedef	PTR BYTE

LPSTR	typedef	PTR BYTE
PSTR	typedef	PTR BYTE

LPCSTR	typedef	PTR BYTE
PCSTR	typedef	PTR BYTE

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Neutral ANSI/UNICODE types and macros
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

IFDEF UNICODE

	TCHAR	typedef	WORD
	PTCHAR	typedef	PTR WORD

	TUCHAR	typedef	WORD
	PTUCHAR	typedef	PTR WORD

	LPTCH	typedef	PTR WORD
	PTCH	typedef	PTR WORD

	PTSTR	typedef	PTR WORD
	LPTSTR	typedef	PTR WORD

	PCTSTR	typedef	PTR WORD
	LPCTSTR	typedef	PTR WORD

	LP		typedef	PTR WORD

ELSE		; UNICODE

	TCHAR	typedef	SBYTE
	PTCHAR	typedef	PTR SBYTE

	TUCHAR	typedef	BYTE
	PTUCHAR	typedef	PTR BYTE

ENDIF		; UNICODE
comment ^
typedef LPSTR LPTCH, PTCH;
typedef LPSTR PTSTR, LPTSTR;
typedef LPCSTR PCTSTR, LPCTSTR;
^
double	typedef	QWORD
DOUBLE	typedef	QWORD

QUAD STRUCT							; QUAD is for those times we want
	DoNotUseThisField	QWORD	?	; an 8 byte aligned 8 byte long structure
QUAD ENDS							; which is NOT really a floating point
									; number.  Use DOUBLE if you want an FP
									; number.

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Pointer to Basics
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PSHORT	typedef	SWORD
PLONG	typedef	PTR SDWORD
PQUAD	typedef	PTR QWORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Unsigned Basics
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

; Tell windef.h that some types are already defined.

; #define BASETYPES

UCHAR	typedef	BYTE
USHORT	typedef	WORD
ULONG	typedef	DWORD
UQUAD	typedef	QWORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Pointer to Unsigned Basics
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PUCHAR	typedef	PTR BYTE
PUSHORT	typedef	PTR WORD
PULONG	typedef	PTR DWORD
PUQUAD	typedef	PTR QWORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Signed characters
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SCHAR	typedef SBYTE
PSCHAR	typedef PTR SBYTE

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Handle to an Object
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

HANDLE	typedef	DWORD
comment ^
#define DECLARE_HANDLE(name) typedef HANDLE name
^
PHANDLE	typedef	PTR DWORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Flag (bit) fields
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

FCHAR	typedef	BYTE
FSHORT	typedef	WORD
FLONG	typedef	DWORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Low order two bits of a handle are ignored by the system and available
; for use by application code as tag bits.  The remaining bits are opaque
; and used to store a serial number and table index.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Cardinal Data Types [0 - 2**N-2)
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CCHAR	typedef	BYTE
CSHORT	typedef	SWORD
CLONG	typedef	SDWORD

PCCHAR	typedef	PTR BYTE
PCSHORT	typedef	PTR SWORD
PCLONG	typedef	PTR SDWORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; NLS basics (Locale and Language Ids)
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

LCID	typedef DWORD
PLCID	typedef PTR DWORD
LANGID	typedef WORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Logical Data Type - These are 32-bit logical values.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

LOGICAL		typedef	DWORD
PLOGICAL	typedef	PTR DWORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; NTSTATUS
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

NTSTATUS	typedef	SDWORD
PNTSTATUS	typedef	PTR SDWORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;  Status values are 32 bit values layed out as follows:
;
;   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
;   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
;  +---+-+-------------------------+-------------------------------+
;  |Sev|C|       Facility          |               Code            |
;  +---+-+-------------------------+-------------------------------+
;
;  where
;
;      Sev - is the severity code
;
;          00 - Success
;          01 - Informational
;          10 - Warning
;          11 - Error
;
;      C - is the Customer code flag
;
;      Facility - is the facility code
;
;      Code - is the facility's status code
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
comment ^
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Generic test for success on any status value (non-negative numbers
; indicate success).
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Generic test for information on any status value.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#define NT_INFORMATION(Status) ((ULONG)(Status) >> 30 == 1)

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Generic test for warning on any status value.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#define NT_WARNING(Status) ((ULONG)(Status) >> 30 == 2)

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Generic test for error on any status value.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#define NT_ERROR(Status) ((ULONG)(Status) >> 30 == 3)
^
APPLICATION_ERROR_MASK       equ 020000000h
ERROR_SEVERITY_SUCCESS       equ 000000000h
ERROR_SEVERITY_INFORMATIONAL equ 040000000h
ERROR_SEVERITY_WARNING       equ 080000000h
ERROR_SEVERITY_ERROR         equ 0C0000000h

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Large (64-bit) integer types and operations
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

TIME UNION
	struct
		union
			LowPart		DWORD ?
			LowTime		DWORD ?
		ends
		union
			HighPart	SDWORD ?
			HighTime	SDWORD ?
		ends
	ends
	struct u
		union
			LowPart    DWORD ?
			LowTime    DWORD ?
		ends
		union
			HighPart   SDWORD ?
			HighTime   SDWORD ?
		ends
	ends
	QuadPart     QWORD ?	; signed
TIME ENDS
PTIME typedef PTR TIME

comment ^
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; _M_IX86 included so that EM CONTEXT structure compiles with
; x86 programs. *** TBD should this be for all architectures?
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; 16 byte aligned type for 128 bit floats
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

typedef struct _FLOAT128 {
    __int64 LowPart;
    __int64 HighPart;
} FLOAT128;

typedef FLOAT128 *PFLOAT128;
^

LONGLONG	typedef QWORD
ULONGLONG	typedef QWORD

PLONGLONG	typedef PTR QWORD
PULONGLONG	typedef PTR QWORD

USN			typedef QWORD

LARGE_INTEGER UNION
	struct
		LowPart		DWORD ?
		HighPart	SDWORD ?
	ends
	struct u
		LowPart		DWORD ?
		HighPart	SDWORD ?
	ends
	QuadPart		QWORD ?	; signed
LARGE_INTEGER ENDS
PLARGE_INTEGER typedef PTR LARGE_INTEGER

ULARGE_INTEGER UNION
	struct
		LowPart		DWORD ?
		HighPart	DWORD ?
	ends
	struct u
		LowPart		DWORD ?
		HighPart	DWORD ?
	ends
	QuadPart		QWORD ?
ULARGE_INTEGER ENDS
PULARGE_INTEGER	typedef	PTR ULARGE_INTEGER

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Locally Unique Identifier
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

LUID STRUCT
	LowPart		DWORD	?
	HighPart	SDWORD	?
LUID ENDS
PLUID typedef PTR LUID

DWORDLONG	typedef QWORD
PDWORDLONG	typedef PTR QWORD

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Physical address.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PHYSICAL_ADDRESS UNION
	struct
		LowPart    DWORD ?
		HighPart   SDWORD ?
	ends
	struct u
		LowPart    DWORD ?
		HighPart   SDWORD ?
	ends
	QuadPart     QWORD ?	; signed
PHYSICAL_ADDRESS ENDS
PPHYSICAL_ADDRESS typedef PTR PHYSICAL_ADDRESS

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Define operations to logically shift an int64 by 0..31 bits and to multiply
; 32-bits by 32-bits to form a 64-bit product.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
comment ^
#if defined(_M_IX86)

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// The x86 C compiler understands inline assembler. Therefore, inline functions
// that employ inline assembler are used for shifts of 0..31.  The multiplies
// rely on the compiler recognizing the cast of the multiplicand to int64 to
// generate the optimal code inline.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

__inline ULONGLONG
NTAPI
Int64ShllMod32 (
    ULONGLONG Value,
    ULONG ShiftCount
    )
{
    __asm    {
        mov     ecx, ShiftCount
        mov     eax, dword ptr [Value]
        mov     edx, dword ptr [Value+4]
        shld    edx, eax, cl
        shl     eax, cl
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -