ndk.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. {$IFNDEF FPC_DOTTEDUNITS}
  12. unit NDK;
  13. {$ENDIF FPC_DOTTEDUNITS}
  14. interface
  15. const
  16. {$ifdef kmode}
  17. ntdll = 'ntoskrnl.exe';
  18. {$else}
  19. ntdll = 'ntdll.dll';
  20. {$endif}
  21. {$calling stdcall}
  22. {$include ntdef.inc}
  23. {$include winnt.inc}
  24. {$include ntstatus.inc}
  25. {$include umtypes.inc}
  26. {$include iotypes.inc}
  27. {$include rtltypes.inc}
  28. {$include ketypes.inc}
  29. {$include obtypes.inc}
  30. {$include pstypes.inc}
  31. {$include peb_teb.inc}
  32. {$include rtlfuncs.inc}
  33. {$include iofuncs.inc}
  34. {$include obfuncs.inc}
  35. function NtClose(Handle: HANDLE): NTSTATUS; stdcall; external ntdll;
  36. function NtDelayExecution(aAlertable: NT_BOOLEAN; aInterval: PLARGE_INTEGER): NTSTATUS; stdcall; external ntdll;
  37. function NtDisplayString(aString: PUNICODE_STRING): NTSTATUS; stdcall; external ntdll;
  38. function LdrGetProcedureAddress(hModule: HANDLE; psName: PUNICODE_STRING; dwOrdinal: LongWord; var pProcedure: PVOID): NTSTATUS; stdcall; external ntdll;
  39. function LdrLoadDll(pwPath : PWord; pdwFlags : LongWord; pusPath : PUNICODE_STRING; var phModule : HANDLE): NTSTATUS; stdcall; external ntdll;
  40. function LdrUnloadDll(hModule: HANDLE): NTSTATUS; stdcall; external ntdll;
  41. implementation
  42. function SharedUserData: PKUSER_SHARED_DATA; register;
  43. begin
  44. { this is a pointer to a page that is mapped into every process by the kernel
  45. }
  46. SharedUserData := PKUSER_SHARED_DATA(USER_SHARED_DATA);
  47. end;
  48. procedure InitializeObjectAttributes(var aObjectAttr: OBJECT_ATTRIBUTES;
  49. aName: PUNICODE_STRING; aAttributes: ULONG; aRootDir: HANDLE;
  50. aSecurity: Pointer {PSECURITY_DESCRIPTOR}); register;
  51. begin
  52. with aObjectAttr do begin
  53. Length := SizeOf(OBJECT_ATTRIBUTES);
  54. RootDirectory := aRootDir;
  55. Attributes := aAttributes;
  56. ObjectName := aName;
  57. SecurityDescriptor := aSecurity;
  58. SecurityQualityOfService := Nil;
  59. end;
  60. end;
  61. function NT_SUCCESS(Status: NTSTATUS): Boolean; register;
  62. begin
  63. NT_SUCCESS := Status >= 0;
  64. end;
  65. function NT_INFORMATION(Status: NTSTATUS): Boolean; register;
  66. begin
  67. NT_INFORMATION := ULONG(Status) shr 30 = 1;
  68. end;
  69. function NT_WARNING(Status: NTSTATUS): Boolean; register;
  70. begin
  71. NT_WARNING := ULONG(Status) shr 30 = 2;
  72. end;
  73. function NT_ERROR(Status: NTSTATUS): Boolean; register;
  74. begin
  75. NT_ERROR := ULONG(Status) shr 30 = 3;
  76. end;
  77. end.