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.

114 lines
2.9 KiB

  1. #ifndef _PATCH_PESTUFF_H_
  2. #define _PATCH_PESTUFF_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef IMAGE_DOS_HEADER UNALIGNED* UP_IMAGE_DOS_HEADER;
  7. typedef IMAGE_NT_HEADERS32 UNALIGNED* UP_IMAGE_NT_HEADERS32;
  8. typedef IMAGE_SECTION_HEADER UNALIGNED* UP_IMAGE_SECTION_HEADER;
  9. typedef IMAGE_EXPORT_DIRECTORY UNALIGNED* UP_IMAGE_EXPORT_DIRECTORY;
  10. typedef IMAGE_IMPORT_DESCRIPTOR UNALIGNED* UP_IMAGE_IMPORT_DESCRIPTOR;
  11. typedef IMAGE_IMPORT_BY_NAME UNALIGNED* UP_IMAGE_IMPORT_BY_NAME;
  12. typedef IMAGE_THUNK_DATA32 UNALIGNED* UP_IMAGE_THUNK_DATA32;
  13. typedef IMAGE_RESOURCE_DIRECTORY UNALIGNED* UP_IMAGE_RESOURCE_DIRECTORY;
  14. typedef IMAGE_RESOURCE_DIRECTORY_ENTRY UNALIGNED* UP_IMAGE_RESOURCE_DIRECTORY_ENTRY;
  15. typedef IMAGE_RESOURCE_DATA_ENTRY UNALIGNED* UP_IMAGE_RESOURCE_DATA_ENTRY;
  16. typedef IMAGE_RESOURCE_DIR_STRING_U UNALIGNED* UP_IMAGE_RESOURCE_DIR_STRING_U;
  17. typedef IMAGE_LOAD_CONFIG_DIRECTORY32 UNALIGNED* UP_IMAGE_LOAD_CONFIG_DIRECTORY32;
  18. typedef IMAGE_BASE_RELOCATION UNALIGNED* UP_IMAGE_BASE_RELOCATION;
  19. UP_IMAGE_NT_HEADERS32
  20. __fastcall
  21. GetNtHeader(
  22. IN PVOID MappedFile,
  23. IN ULONG MappedFileSize
  24. );
  25. BOOL
  26. NormalizeCoffImage(
  27. IN OUT UP_IMAGE_NT_HEADERS32 NtHeader,
  28. IN OUT PUCHAR MappedFile,
  29. IN ULONG FileSize,
  30. IN ULONG OptionFlags,
  31. IN PVOID OptionData,
  32. IN ULONG NewFileCoffBase,
  33. IN ULONG NewFileCoffTime
  34. );
  35. BOOL
  36. TransformCoffImage(
  37. IN ULONG TransformOptions,
  38. IN OUT UP_IMAGE_NT_HEADERS32 NtHeader,
  39. IN OUT PUCHAR OldFileMapped,
  40. IN ULONG OldFileSize,
  41. IN ULONG NewFileResTime,
  42. IN OUT PRIFT_TABLE RiftTable,
  43. IN OUT PUCHAR HintMap,
  44. ...
  45. );
  46. BOOL
  47. GenerateRiftTable(
  48. IN HANDLE OldFileHandle,
  49. IN PUCHAR OldFileMapped,
  50. IN ULONG OldFileSize,
  51. IN ULONG OldFileOriginalChecksum,
  52. IN ULONG OldFileOriginalTimeDate,
  53. IN HANDLE NewFileHandle,
  54. IN PUCHAR NewFileMapped,
  55. IN ULONG NewFileSize,
  56. IN ULONG OptionFlags,
  57. IN PVOID OptionData,
  58. IN ULONG OldFileIndex,
  59. IN PVOID RiftTable
  60. );
  61. VOID
  62. InitImagehlpCritSect(
  63. VOID
  64. );
  65. VOID
  66. UnloadImagehlp(
  67. VOID
  68. );
  69. #define X86_OPCODE_NOP 0x90
  70. #define X86_OPCODE_LOCK 0xF0
  71. BOOL
  72. SmashLockPrefixesInMappedImage(
  73. IN PUCHAR MappedFile,
  74. IN ULONG FileSize,
  75. IN UP_IMAGE_NT_HEADERS32 NtHeader,
  76. IN UCHAR NewOpCode // X86_OPCODE_NOP or X86_OPCODE_LOCK
  77. );
  78. USHORT
  79. ChkSum(
  80. IN USHORT Initial,
  81. IN PUSHORT Buffer,
  82. IN ULONG Bytes
  83. );
  84. PVOID
  85. __fastcall
  86. ImageDirectoryMappedAddress(
  87. IN UP_IMAGE_NT_HEADERS32 NtHeader,
  88. IN ULONG DirectoryIndex,
  89. OUT PULONG DirectorySize,
  90. IN PUCHAR MappedBase,
  91. IN ULONG MappedSize
  92. );
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif // _PATCH_PESTUFF_H_