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.

134 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. bmf2mof.c
  5. Abstract:
  6. TODO: Enable localization
  7. Tool to convert a binary mof resource back to a text mof file
  8. Usage:
  9. bmf2mof <image name> <resource name>
  10. Author:
  11. 16-Jan-1997 AlanWar
  12. Revision History:
  13. --*/
  14. #include <windows.h>
  15. #include <shellapi.h>
  16. #include <stdio.h>
  17. #include <fcntl.h>
  18. #include <ctype.h>
  19. #include <bmfmisc.h>
  20. #include <wbemcli.h>
  21. void Usage()
  22. {
  23. printf("bmf2mof <image name> <resource name> <mof file>\n");
  24. printf(" Convert binary mof resource to a text mof\n\n");
  25. printf("****** WARNING: if <image name> is a system dll (like advapi32.dll) ******\n");
  26. printf("****** then the system dll will be used and not the file on disk *****\n\n");
  27. }
  28. ULONG LoadMofResource(
  29. PTCHAR Filename,
  30. PTCHAR ResourceName,
  31. PUCHAR *Data
  32. )
  33. {
  34. HMODULE Module;
  35. HRSRC Resource;
  36. HGLOBAL Global;
  37. ULONG Status;
  38. Module = LoadLibraryEx(Filename,
  39. NULL,
  40. LOAD_LIBRARY_AS_DATAFILE);
  41. if (Module != NULL)
  42. {
  43. Resource = FindResource(Module,
  44. ResourceName,
  45. TEXT("MOFDATA"));
  46. if (Resource != NULL)
  47. {
  48. Global = LoadResource(Module,
  49. Resource);
  50. if (Global != NULL)
  51. {
  52. *Data = LockResource(Global);
  53. if (*Data != NULL)
  54. {
  55. Status = ERROR_SUCCESS;
  56. } else {
  57. FreeLibrary(Module);
  58. Status = GetLastError();
  59. }
  60. } else {
  61. FreeLibrary(Module);
  62. Status = GetLastError();
  63. }
  64. } else {
  65. FreeLibrary(Module);
  66. Status = GetLastError();
  67. }
  68. } else {
  69. Status = GetLastError();
  70. }
  71. return(Status);
  72. }
  73. int _cdecl main(int argc, char *argv[])
  74. {
  75. ULONG Status;
  76. PUCHAR Data;
  77. BOOLEAN b;
  78. SetErrorMode(SEM_NOALIGNMENTFAULTEXCEPT); // BUGBUG: Remove when MOF format maintains alignment correctly
  79. if (argc != 4)
  80. {
  81. Usage();
  82. return(0);
  83. }
  84. printf("BMF2MOF - convert a binary mof resource back into a text mof\n\n");
  85. printf(" Converting resource %s in file %s into text mof %s\n\n",
  86. argv[2], argv[1], argv[3]);
  87. printf("****** WARNING: if %s is a system dll (like advapi32.dll) ******\n",
  88. argv[1]);
  89. printf("****** then the system dll will be used and not the file on disk *****\n\n");
  90. Status = LoadMofResource(argv[1], argv[2], &Data);
  91. if (Status == ERROR_SUCCESS)
  92. {
  93. b = ConvertBmfToMof(Data,
  94. argv[3],
  95. TEXT(""));
  96. if (! b)
  97. {
  98. printf("Could not convert resource %s in file %s to text mof\n",
  99. argv[2], argv[1]);
  100. } else {
  101. printf("%s created successfully\n", argv[3]);
  102. }
  103. } else {
  104. printf("Could not load resource %s from file %s\n",
  105. argv[2], argv[1]);
  106. }
  107. return(Status);
  108. }