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.

132 lines
3.2 KiB

  1. #include "stdafx.h"
  2. #include "filemap.h"
  3. #include "mymfile.h"
  4. #include "myinf.h"
  5. CMyInf::CMyInf()
  6. {
  7. m_SectionStart = NULL;
  8. m_SectionEnd = NULL;
  9. m_Locale[0] = L'\0';
  10. }
  11. CMyInf::~CMyInf()
  12. {
  13. }
  14. BOOL CMyInf::bOpen(LPCSTR FileName, LPCTSTR Locale)
  15. {
  16. if (! CFileMap::bOpen(FileName)) {
  17. return FALSE;
  18. }
  19. if (! FindStringSection()) {
  20. fprintf(stderr,"No string section inside this file !\n");
  21. return FALSE;
  22. }
  23. if (! _GenerateStringName(Locale)) {
  24. fprintf(stderr,"No string section inside this file !\n");
  25. return FALSE;
  26. }
  27. return TRUE;
  28. }
  29. BOOL CMyInf::FindStringSection()
  30. {
  31. BOOL bInSection = FALSE;
  32. for (DWORD i=0; i<m_FileSize; i += sizeof(WCHAR)) {
  33. if (*(WCHAR *) (m_Memory +i) == TEXT('[')) {
  34. if (i+8 >= m_FileSize) {
  35. //
  36. // over boundary, not a candinate
  37. //
  38. return FALSE;
  39. }
  40. WCHAR * TmpBuf = (WCHAR *) (m_Memory +i);
  41. if ( ((TmpBuf[1] == TEXT('s')) || (TmpBuf[1] == TEXT('S'))) &&
  42. ((TmpBuf[2] == TEXT('t')) || (TmpBuf[2] == TEXT('T'))) &&
  43. ((TmpBuf[3] == TEXT('r')) || (TmpBuf[3] == TEXT('R'))) &&
  44. ((TmpBuf[4] == TEXT('i')) || (TmpBuf[4] == TEXT('I'))) &&
  45. ((TmpBuf[5] == TEXT('n')) || (TmpBuf[5] == TEXT('N'))) &&
  46. ((TmpBuf[6] == TEXT('g')) || (TmpBuf[6] == TEXT('G'))) &&
  47. ((TmpBuf[7] == TEXT('s')) || (TmpBuf[7] == TEXT('S'))) &&
  48. (TmpBuf[8] == TEXT(']') ) ) {
  49. bInSection = TRUE;
  50. m_SectionStart = m_Memory+i;
  51. continue;
  52. }
  53. if (bInSection && (*(WCHAR *) (m_Memory +i) == TEXT('['))) {
  54. break;
  55. }
  56. }
  57. }
  58. if (bInSection) {
  59. m_SectionEnd = m_Memory +i;
  60. return TRUE;
  61. } else {
  62. return FALSE;
  63. }
  64. }
  65. BOOL CMyInf::AppendNonStringSectionPart(CMemFile& MemFile)
  66. {
  67. MemFile.Write(m_Memory, (UINT)GetOffset(m_SectionStart));
  68. return TRUE;
  69. }
  70. BOOL CMyInf::AppendStringSectionPart(CMemFile& MemFile)
  71. {
  72. MemFile.Write(m_Locale,lstrlenW(m_Locale)*sizeof(WCHAR));
  73. MemFile.Write(m_SectionStart+lstrlenW(L"[Strings]")*sizeof(WCHAR), (UINT)(m_SectionEnd - m_SectionStart - lstrlenW(L"[Strings]")*sizeof(WCHAR)));
  74. return TRUE;
  75. }
  76. BOOL CMyInf::Duplicate(CMemFile& MemFile)
  77. {
  78. MemFile.Write(m_Memory,m_FileSize);
  79. return TRUE;
  80. }
  81. BOOL CMyInf::_GenerateStringName(LPCSTR Locale)
  82. {
  83. WCHAR szTmpBuf[MAX_PATH];
  84. if (lstrlen(Locale) == 0) {
  85. lstrcpyW(m_Locale,L"[Strings]");
  86. return TRUE;
  87. }
  88. if (lstrlen(Locale)*2+10 > sizeof(m_Locale)) {
  89. return FALSE;
  90. }
  91. //
  92. // this string contains number only, so it's safe to use ACP
  93. //
  94. MultiByteToWideChar(CP_ACP,
  95. 0,
  96. Locale,
  97. -1,
  98. szTmpBuf,
  99. MAX_PATH);
  100. lstrcpyW(m_Locale,L"[Strings");
  101. lstrcatW(m_Locale,L".");
  102. lstrcatW(m_Locale,szTmpBuf);
  103. lstrcatW(m_Locale,L"]");
  104. return TRUE;
  105. }
  106.