Leaked source code of windows server 2003
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.5 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. dump.c
  5. Abstract:
  6. Dumps a block of memory to file
  7. Author:
  8. Stephane Plante (splante)
  9. Environment:
  10. User Mode
  11. --*/
  12. #include "pch.h"
  13. VOID
  14. dumpMemory(
  15. IN ULONG_PTR Address,
  16. IN ULONG Length,
  17. IN PUCHAR Name
  18. )
  19. {
  20. BOOL b;
  21. HANDLE file;
  22. PUCHAR buffer;
  23. ULONG readLength;
  24. //
  25. // Open the file
  26. //
  27. file = CreateFile(
  28. Name,
  29. GENERIC_READ | GENERIC_WRITE,
  30. 0,
  31. NULL,
  32. OPEN_ALWAYS,
  33. 0,
  34. NULL
  35. );
  36. if (file == INVALID_HANDLE_VALUE) {
  37. dprintf("dm: could not open '%s'\n",Name);
  38. return;
  39. }
  40. //
  41. // Read the bytes from memory
  42. //
  43. buffer = LocalAlloc( LPTR, Length );
  44. if (buffer == NULL) {
  45. dprintf("dm: could not allocate '0x%x' bytes\n", Length );
  46. CloseHandle( file );
  47. return;
  48. }
  49. b = ReadMemory(
  50. Address,
  51. buffer,
  52. Length,
  53. &readLength
  54. );
  55. if (!b) {
  56. dprintf(
  57. "dm: could not read '0x%x' bytes from '0x%p'\n",
  58. Length,
  59. Address
  60. );
  61. LocalFree ( buffer );
  62. CloseHandle( file );
  63. return;
  64. }
  65. //
  66. // Write the contents of memory to the file
  67. //
  68. WriteFile( file, buffer, readLength, &readLength, NULL );
  69. //
  70. // Done
  71. //
  72. CloseHandle( file );
  73. LocalFree( buffer );
  74. }