Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
1.8 KiB

4 years ago
  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include "psapi.h"
  6. DWORD
  7. WINAPI
  8. GetMappedFileNameW(
  9. HANDLE hProcess,
  10. LPVOID lpv,
  11. LPWSTR lpFilename,
  12. DWORD nSize
  13. )
  14. {
  15. struct {
  16. OBJECT_NAME_INFORMATION ObjectNameInfo;
  17. WCHAR FileName[MAX_PATH];
  18. } s;
  19. DWORD ReturnLength;
  20. NTSTATUS Status;
  21. DWORD cb;
  22. //
  23. // See if we can figure out the name associated with
  24. // this mapped region
  25. //
  26. Status = NtQueryVirtualMemory(hProcess,
  27. lpv,
  28. MemoryMappedFilenameInformation,
  29. &s.ObjectNameInfo,
  30. sizeof(s),
  31. &ReturnLength
  32. );
  33. if ( !NT_SUCCESS(Status) ) {
  34. SetLastError( RtlNtStatusToDosError( Status ) );
  35. return(0);
  36. }
  37. nSize *= sizeof(WCHAR);
  38. cb = s.ObjectNameInfo.Name.MaximumLength;
  39. if ( nSize < cb ) {
  40. cb = nSize;
  41. }
  42. CopyMemory(lpFilename, s.ObjectNameInfo.Name.Buffer, cb);
  43. if (cb == s.ObjectNameInfo.Name.MaximumLength) {
  44. cb -= sizeof(WCHAR);
  45. }
  46. return(cb / sizeof(WCHAR));
  47. }
  48. DWORD
  49. WINAPI
  50. GetMappedFileNameA(
  51. HANDLE hProcess,
  52. LPVOID lpv,
  53. LPSTR lpFilename,
  54. DWORD nSize
  55. )
  56. {
  57. LPWSTR lpwstr;
  58. DWORD cwch;
  59. DWORD cch;
  60. lpwstr = (LPWSTR) LocalAlloc(LMEM_FIXED, nSize * 2);
  61. if (lpwstr == NULL) {
  62. return(0);
  63. }
  64. cch = cwch = GetMappedFileNameW(hProcess, lpv, lpwstr, nSize);
  65. if (cwch < nSize) {
  66. //
  67. // Include NULL terminator
  68. //
  69. cwch++;
  70. }
  71. if (!WideCharToMultiByte(CP_ACP, 0, lpwstr, cwch, lpFilename, nSize, NULL, NULL)) {
  72. cch = 0;
  73. }
  74. LocalFree((HLOCAL) lpwstr);
  75. return(cch);
  76. }