Source code of Windows XP (NT5)
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.

131 lines
2.5 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. Status = GetLastError();
  58. }
  59. } else {
  60. Status = GetLastError();
  61. }
  62. } else {
  63. Status = GetLastError();
  64. }
  65. } else {
  66. Status = GetLastError();
  67. }
  68. return(Status);
  69. }
  70. int _cdecl main(int argc, char *argv[])
  71. {
  72. ULONG Status;
  73. PUCHAR Data;
  74. BOOLEAN b;
  75. SetErrorMode(SEM_NOALIGNMENTFAULTEXCEPT); // BUGBUG: Remove when MOF format maintains alignment correctly
  76. if (argc != 4)
  77. {
  78. Usage();
  79. return(0);
  80. }
  81. printf("BMF2MOF - convert a binary mof resource back into a text mof\n\n");
  82. printf(" Converting resource %s in file %s into text mof %s\n\n",
  83. argv[2], argv[1], argv[3]);
  84. printf("****** WARNING: if %s is a system dll (like advapi32.dll) ******\n",
  85. argv[1]);
  86. printf("****** then the system dll will be used and not the file on disk *****\n\n");
  87. Status = LoadMofResource(argv[1], argv[2], &Data);
  88. if (Status == ERROR_SUCCESS)
  89. {
  90. b = ConvertBmfToMof(Data,
  91. argv[3],
  92. TEXT(""));
  93. if (! b)
  94. {
  95. printf("Could not convert resource %s in file %s to text mof\n",
  96. argv[2], argv[1]);
  97. } else {
  98. printf("%s created successfully\n", argv[3]);
  99. }
  100. } else {
  101. printf("Could not load resource %s from file %s\n",
  102. argv[2], argv[1]);
  103. }
  104. return(Status);
  105. }