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.

160 lines
4.1 KiB

  1. // kernel32.cpp : Defines the initialization routines for the DLL.
  2. //
  3. #include "stdafx.h"
  4. #include <afxdllx.h>
  5. #include "..\..\common\rwdll.h"
  6. #include "..\..\common\rw32hlpr.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char BASED_CODE THIS_FILE[] = __FILE__;
  10. #endif
  11. static AFX_EXTENSION_MODULE kernel32DLL = { NULL, NULL };
  12. UINT ParseRCData( LPCSTR lpszResId, LPVOID lpImageBuf, DWORD dwISize, LPVOID lpBuffer, DWORD dwSize );
  13. UINT UpdateRCData( LPVOID lpNewBuf, LONG dwNewSize, LPVOID lpOldI, LONG dwOldImageSize, LPVOID lpNewI, DWORD* pdwNewImageSize );
  14. extern char szCaption[MAXSTR];
  15. /////////////////////////////////////////////////////////////////////////////
  16. // This file implements the RCDATA handling for the file kernel32.dll
  17. extern "C"
  18. DllExport
  19. UINT
  20. APIENTRY
  21. RWParseImageEx(
  22. LPCSTR lpszType,
  23. LPCSTR lpszResId,
  24. LPVOID lpImageBuf,
  25. DWORD dwImageSize,
  26. LPVOID lpBuffer,
  27. DWORD dwSize,
  28. LPCSTR lpDllName
  29. )
  30. {
  31. UINT uiError = ERROR_NO_ERROR;
  32. BYTE * lpBuf = (BYTE *)lpBuffer;
  33. DWORD dwBufSize = dwSize;
  34. // The Type we can parse are only the standard ones
  35. // This function should fill the lpBuffer with an array of ResItem structure
  36. switch ((UINT)LOWORD(lpszType)) {
  37. case 10:
  38. uiError = ParseRCData( lpszResId, lpImageBuf, dwImageSize, lpBuffer, dwSize );
  39. break;
  40. default:
  41. break;
  42. }
  43. return uiError;
  44. }
  45. extern "C"
  46. DllExport
  47. UINT
  48. APIENTRY
  49. RWUpdateImageEx(
  50. LPCSTR lpszType,
  51. LPVOID lpNewBuf,
  52. DWORD dwNewSize,
  53. LPVOID lpOldImage,
  54. DWORD dwOldImageSize,
  55. LPVOID lpNewImage,
  56. DWORD* pdwNewImageSize,
  57. LPCSTR lpRCFilename
  58. )
  59. {
  60. UINT uiError = ERROR_NO_ERROR;
  61. // The Type we can parse are only the standard ones
  62. switch ((UINT)LOWORD(lpszType)) {
  63. case 10:
  64. uiError = UpdateRCData( lpNewBuf, dwNewSize,
  65. lpOldImage, dwOldImageSize,
  66. lpNewImage, pdwNewImageSize );
  67. break;
  68. default:
  69. *pdwNewImageSize = 0L;
  70. uiError = ERROR_RW_NOTREADY;
  71. break;
  72. }
  73. return uiError;
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Real implementation of the parsers
  77. UINT
  78. ParseRCData( LPCSTR lpszResId, LPVOID lpImageBuf, DWORD dwISize, LPVOID lpBuffer, DWORD dwSize )
  79. {
  80. //
  81. // The data in the RCDATA is just a string null terminated
  82. //
  83. LPRESITEM lpResItem = (LPRESITEM)lpBuffer;
  84. //
  85. // Get the string from the image
  86. //
  87. GetStringW( (BYTE**)&lpImageBuf, &szCaption[0], (LONG*)&dwISize, MAXSTR );
  88. LONG dwOverAllSize = sizeof(RESITEM)+strlen(szCaption);
  89. if( (LONG)dwSize>dwOverAllSize )
  90. {
  91. //
  92. // Clear the resitem buffer
  93. //
  94. memset(lpResItem, '\0', dwSize);
  95. lpResItem->dwSize = dwOverAllSize;
  96. lpResItem->dwItemID = 1;
  97. lpResItem->dwResID = LOWORD(lpszResId);
  98. lpResItem->dwTypeID = 11;
  99. lpResItem->lpszCaption = strcpy((((char*)lpResItem)+sizeof(RESITEM)), &szCaption[0]);
  100. }
  101. return (UINT)(dwOverAllSize);
  102. }
  103. UINT
  104. UpdateRCData( LPVOID lpNewBuf, LONG dwNewSize,
  105. LPVOID lpOldI, LONG dwOldImageSize,
  106. LPVOID lpNewI, DWORD* pdwNewImageSize )
  107. {
  108. UINT uiError = ERROR_NO_ERROR;
  109. LPRESITEM lpResItem = (LPRESITEM)lpNewBuf;
  110. if(*pdwNewImageSize>strlen(lpResItem->lpszCaption))
  111. {
  112. // Write the text
  113. *pdwNewImageSize = PutStringW( (BYTE **)&lpNewI, lpResItem->lpszCaption, (LONG*)pdwNewImageSize );
  114. }
  115. return uiError;
  116. }
  117. extern "C" int APIENTRY
  118. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  119. {
  120. if (dwReason == DLL_PROCESS_ATTACH)
  121. {
  122. TRACE0("RCKERNEL32.DLL Initializing!\n");
  123. InitGlobals();
  124. AfxInitExtensionModule(kernel32DLL, hInstance);
  125. new CDynLinkLibrary(kernel32DLL);
  126. }
  127. else if (dwReason == DLL_PROCESS_DETACH)
  128. {
  129. TRACE0("RCKERNEL32.DLL Terminating!\n");
  130. }
  131. return 1;
  132. }