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.

94 lines
1.6 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1999
  3. Module Name:
  4. InvMap
  5. Abstract:
  6. This file provides an application that dumps an inverse bit ordering array
  7. to the supplied file. It is invoked with the command,
  8. invmap <file>
  9. It then writes a binary reverse mapping table to that file, which can be
  10. formatted with hexfmt.
  11. Author:
  12. Doug Barlow (dbarlow) 12/3/1996
  13. Environment:
  14. CRT
  15. Notes:
  16. See DBarlow for hexfmt.
  17. --*/
  18. #include <windows.h>
  19. #include <crtdbg.h>
  20. #include <iostream.h>
  21. #include <fstream.h>
  22. #ifdef _DEBUG
  23. #define ASSERT(x) _ASSERTE(x)
  24. #else
  25. #define ASSERT(x)
  26. #endif
  27. int _cdecl
  28. main(
  29. ULONG argc,
  30. TCHAR *argv[])
  31. {
  32. static BYTE rgbInv[256];
  33. DWORD ix, jx;
  34. BYTE org, inv;
  35. if (2 != argc)
  36. {
  37. cerr << "Usage: " << argv[0] << " <outFile>" << endl;
  38. return 0;
  39. }
  40. ofstream outf(argv[1], ios::out | ios::noreplace | ios::binary);
  41. if (!outf)
  42. {
  43. cerr << "Can't create file " << argv[1] << endl;
  44. return 1;
  45. }
  46. for (ix = 0; 256 > ix; ix += 1)
  47. {
  48. inv = 0;
  49. org = (BYTE)ix;
  50. for (jx = 0; jx < 8; jx += 1)
  51. {
  52. inv <<= 1;
  53. if (0 == (org & 0x01))
  54. inv |= 0x01;
  55. org >>= 1;
  56. }
  57. rgbInv[ix] = inv;
  58. outf << inv;
  59. }
  60. #ifdef _DEBUG
  61. for (ix = 0; 256 > ix; ix += 1)
  62. {
  63. org = (BYTE)ix;
  64. inv = (BYTE)rgbInv[ix];
  65. ASSERT(inv == rgbInv[org]);
  66. ASSERT(org == rgbInv[inv]);
  67. }
  68. #endif
  69. return 0;
  70. }