ndk.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. Native Development Kit for Native NT
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2009-2010 by Sven Barth
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit NDK;
  12. interface
  13. const
  14. {$ifdef kmode}
  15. ntdll = 'ntoskrnl.exe';
  16. {$else}
  17. ntdll = 'ntdll.dll';
  18. {$endif}
  19. {$calling stdcall}
  20. {$include ntdef.inc}
  21. {$include winnt.inc}
  22. {$include ntstatus.inc}
  23. {$include umtypes.inc}
  24. {$include iotypes.inc}
  25. {$include rtltypes.inc}
  26. {$include ketypes.inc}
  27. {$include obtypes.inc}
  28. {$include pstypes.inc}
  29. {$include peb_teb.inc}
  30. {$include rtlfuncs.inc}
  31. {$include iofuncs.inc}
  32. {$include obfuncs.inc}
  33. function NtClose(Handle: HANDLE): NTSTATUS; stdcall; external ntdll;
  34. function NtDelayExecution(aAlertable: NT_BOOLEAN; aInterval: PLARGE_INTEGER): NTSTATUS; stdcall; external ntdll;
  35. function NtDisplayString(aString: PUNICODE_STRING): NTSTATUS; stdcall; external ntdll;
  36. function LdrGetProcedureAddress(hModule: HANDLE; psName: PUNICODE_STRING; dwOrdinal: LongWord; var pProcedure: PVOID): NTSTATUS; stdcall; external ntdll;
  37. function LdrLoadDll(pwPath : PWord; pdwFlags : LongWord; pusPath : PUNICODE_STRING; var phModule : HANDLE): NTSTATUS; stdcall; external ntdll;
  38. function LdrUnloadDll(hModule: HANDLE): NTSTATUS; stdcall; external ntdll;
  39. implementation
  40. function SharedUserData: PKUSER_SHARED_DATA; register;
  41. begin
  42. { this is a pointer to a page that is mapped into every process by the kernel
  43. }
  44. SharedUserData := PKUSER_SHARED_DATA(USER_SHARED_DATA);
  45. end;
  46. procedure InitializeObjectAttributes(var aObjectAttr: OBJECT_ATTRIBUTES;
  47. aName: PUNICODE_STRING; aAttributes: ULONG; aRootDir: HANDLE;
  48. aSecurity: Pointer {PSECURITY_DESCRIPTOR}); register;
  49. begin
  50. with aObjectAttr do begin
  51. Length := SizeOf(OBJECT_ATTRIBUTES);
  52. RootDirectory := aRootDir;
  53. Attributes := aAttributes;
  54. ObjectName := aName;
  55. SecurityDescriptor := aSecurity;
  56. SecurityQualityOfService := Nil;
  57. end;
  58. end;
  59. function NT_SUCCESS(Status: NTSTATUS): Boolean; register;
  60. begin
  61. NT_SUCCESS := Status >= 0;
  62. end;
  63. function NT_INFORMATION(Status: NTSTATUS): Boolean; register;
  64. begin
  65. NT_INFORMATION := ULONG(Status) shr 30 = 1;
  66. end;
  67. function NT_WARNING(Status: NTSTATUS): Boolean; register;
  68. begin
  69. NT_WARNING := ULONG(Status) shr 30 = 2;
  70. end;
  71. function NT_ERROR(Status: NTSTATUS): Boolean; register;
  72. begin
  73. NT_ERROR := ULONG(Status) shr 30 = 3;
  74. end;
  75. end.