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.

122 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. machine.cpp
  5. Abstract:
  6. This file implements the CreateMachApiThunk() function. This
  7. function is responsible for emitting the individual API thunks
  8. for the i386 architecture.
  9. Author:
  10. Wesley Witt (wesw) 28-June-1995
  11. Environment:
  12. User Mode
  13. --*/
  14. #include "apidllp.h"
  15. #pragma hdrstop
  16. PUCHAR
  17. CreateMachApiThunk(
  18. PULONG IatAddress,
  19. PUCHAR Text,
  20. PDLL_INFO DllInfo,
  21. PAPI_INFO ApiInfo
  22. )
  23. /*++
  24. Routine Description:
  25. Emits the machine specific code for the API thunks.
  26. Arguments:
  27. IatAddress - Pointer to the IAT fir this API
  28. Text - Pointer to a buffer to place the generated code
  29. DllInfo - Pointer to the DLL_INFO structure
  30. ApiInfo - Pointer to the API_INFO structure
  31. Return Value:
  32. Pointer to the next byte to place more generated code.
  33. --*/
  34. {
  35. if (ApiInfo->ThunkAddress) {
  36. *IatAddress = ApiInfo->ThunkAddress;
  37. return Text;
  38. }
  39. *IatAddress = (ULONG)Text;
  40. ApiInfo->ThunkAddress = *IatAddress;
  41. PUCHAR Code = (PUCHAR)Text;
  42. Code[0] = 0x68;
  43. Code += 1;
  44. *(LPDWORD)Code = (ULONG)ApiInfo;
  45. Code += sizeof(DWORD);
  46. Code[0] = 0x68;
  47. Code += 1;
  48. *(LPDWORD)Code = (ULONG)DllInfo;
  49. Code += sizeof(DWORD);
  50. Code[0] = 0x68;
  51. Code += 1;
  52. if (_stricmp(DllInfo->Name,KERNEL32)==0) {
  53. if (strcmp((LPSTR)(ApiInfo->Name+(LPSTR)MemPtr),LOADLIBRARYA)==0) {
  54. *(LPDWORD)Code = APITYPE_LOADLIBRARYA;
  55. } else
  56. if (strcmp((LPSTR)(ApiInfo->Name+(LPSTR)MemPtr),LOADLIBRARYW)==0) {
  57. *(LPDWORD)Code = APITYPE_LOADLIBRARYW;
  58. } else
  59. if (strcmp((LPSTR)(ApiInfo->Name+(LPSTR)MemPtr),FREELIBRARY)==0) {
  60. *(LPDWORD)Code = APITYPE_FREELIBRARY;
  61. } else
  62. if (strcmp((LPSTR)(ApiInfo->Name+(LPSTR)MemPtr),GETPROCADDRESS)==0) {
  63. *(LPDWORD)Code = APITYPE_GETPROCADDRESS;
  64. } else {
  65. *(LPDWORD)Code = APITYPE_NORMAL;
  66. }
  67. } else if (_stricmp(DllInfo->Name,USER32)==0) {
  68. if (strcmp((LPSTR)(ApiInfo->Name+(LPSTR)MemPtr),REGISTERCLASSA)==0) {
  69. *(LPDWORD)Code = APITYPE_REGISTERCLASSA;
  70. } else
  71. if (strcmp((LPSTR)(ApiInfo->Name+(LPSTR)MemPtr),REGISTERCLASSW)==0) {
  72. *(LPDWORD)Code = APITYPE_REGISTERCLASSW;
  73. } else
  74. if (strcmp((LPSTR)(ApiInfo->Name+(LPSTR)MemPtr),SETWINDOWLONGA)==0) {
  75. *(LPDWORD)Code = APITYPE_SETWINDOWLONG;
  76. } else
  77. if (strcmp((LPSTR)(ApiInfo->Name+(LPSTR)MemPtr),SETWINDOWLONGW)==0) {
  78. *(LPDWORD)Code = APITYPE_SETWINDOWLONG;
  79. } else {
  80. *(LPDWORD)Code = APITYPE_NORMAL;
  81. }
  82. } else if (_stricmp(DllInfo->Name,WNDPROCDLL)==0) {
  83. *(LPDWORD)Code = APITYPE_WNDPROC;
  84. } else {
  85. *(LPDWORD)Code = APITYPE_NORMAL;
  86. }
  87. Code += sizeof(DWORD);
  88. Code[0] = 0xe9;
  89. Code += 1;
  90. *(LPDWORD)Code = (ULONG)((ULONG)ApiMonThunk-(((ULONG)Code-(ULONG)Text)+(ULONG)Text+4));
  91. Code += sizeof(DWORD);
  92. return Code;
  93. }