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.

985 lines
25 KiB

  1. //
  2. // This program was created to mirror the functions of the spiisupd.js file,
  3. // but as a standalone EXE, due to problems with AV programs and wscript
  4. // initialization during clean installs.
  5. //
  6. #include <stdio.h>
  7. #include <io.h>
  8. #include <malloc.h>
  9. #include <windows.h>
  10. #include <ntverp.h>
  11. #define countof( a ) ( sizeof( (a) ) / sizeof( (a)[ 0 ] ) )
  12. CHAR BadString1[] = "\tdocument.write('<A HREF=\"' + urlresult + '\">' + displayresult + \"</a>\");";
  13. /* fixed again to NewString9
  14. CHAR NewString1[] = "\tdocument.write( '<A HREF=\"' + escape(urlresult) + '\">\' + displayresult + \"</a>\");";
  15. */
  16. CHAR BadString2[] = " Response.Write \"?\" & Left(Request.QueryString, (lngPos - 1))";
  17. CHAR NewString2[] = " Response.Write \"?\" & Server.HTMLEncode(Left(Request.QueryString, (lngPos - 1)))";
  18. CHAR BadString13[] = "<%= Request.ServerVariables(\"HTTP_USER_AGENT\") %>";
  19. CHAR NewString13[] = "<%= Server.HTMLEncode(Request.ServerVariables(\"HTTP_USER_AGENT\")) %>";
  20. // fix query.asp by shipping its new version
  21. // string 4, 5, 6, 7, 8 are from query.asp
  22. /*
  23. CHAR BadString4[] = " No documents matched the query <%=SearchString%>.<br><br>";
  24. CHAR NewString4[] = " No documents matched the query <%=Server.HTMLEncode(SearchString)%>.<br><br>";
  25. CHAR BadString5[] = "*<%=CompSearch%>*";
  26. CHAR NewString5[] = "*<%=Server.HTMLEncode(CompSearch)%>*";
  27. CHAR BadString6[] = " Session(\"SearchStringDisplay\")=SearchString";
  28. CHAR NewString6[] = " Session(\"SearchStringDisplay\")=Server.HTMLEncode(SearchString)";
  29. CHAR BadString7[] = " <INPUT TYPE=\"HIDDEN\" NAME=\"SearchString\" VALUE=\"<%=SearchString%>\">";
  30. CHAR NewString7[] = " <INPUT TYPE=\"HIDDEN\" NAME=\"SearchString\" VALUE=\"<%=Server.HTMLEncode(SearchString)%>\">";
  31. CHAR BadString8[] = "\t<UL><LI>Let us know about this <a href=\"mailto:[email protected]?subject=<%=SearchString%>-search%20term%20not%20matched&body=The%20term%20'<%=SearchString%>'%20produced%20no%20matches.\">(mailto:[email protected])</a> so that we can improve Search in future releases.";
  32. CHAR NewString8[] = "\t<UL><LI>Let us know about this <a href=\"mailto:[email protected]?subject=<%=Server.HTMLEncode(SearchString)%>-search%20term%20not%20matched&body=The%20term%20'<%=Server.HTMLEncode(SearchString)%>'%20produced%20no%20matches.\">(mailto:[email protected])</a> so that we can improve Search in future releases.";
  33. */
  34. //{ WinSE 26475: CSS bug in custom error pages
  35. CHAR BadString9[] = "\tdocument.write( '<A HREF=\"' + escape(urlresult) + '\">' + displayresult + \"</a>\");";
  36. CHAR NewString9[] = "\tInsertElementAnchor(urlresult, displayresult);";
  37. CHAR InsertCodeBefore1[] = "//-->";
  38. CHAR InsertCodeBefore2[] = "</script>";
  39. CHAR InsertCode9[] =
  40. "\r\n"
  41. "function HtmlEncode(text)\r\n"
  42. "{\r\n"
  43. " return text.replace(/&/g, '&amp').replace(/'/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\r\n"
  44. "}\r\n"
  45. "\r\n"
  46. "function TagAttrib(name, value)\r\n"
  47. "{\r\n"
  48. " return ' '+name+'=\"'+HtmlEncode(value)+'\"';\r\n"
  49. "}\r\n"
  50. "\r\n"
  51. "function PrintTag(tagName, needCloseTag, attrib, inner){\r\n"
  52. " document.write( '<' + tagName + attrib + '>' + HtmlEncode(inner) );\r\n"
  53. " if (needCloseTag) document.write( '</' + tagName +'>' );\r\n"
  54. "}\r\n"
  55. "\r\n"
  56. "function URI(href)\r\n"
  57. "{\r\n"
  58. " IEVer = window.navigator.appVersion;\r\n"
  59. " IEVer = IEVer.substr( IEVer.indexOf('MSIE') + 5, 3 );\r\n"
  60. "\r\n"
  61. " return (IEVer.charAt(1)=='.' && IEVer >= '5.5') ?\r\n"
  62. " encodeURI(href) :\r\n"
  63. " escape(href).replace(/%3A/g, ':').replace(/%3B/g, ';');\r\n"
  64. "}\r\n"
  65. "\r\n"
  66. "function InsertElementAnchor(href, text)\r\n"
  67. "{\r\n"
  68. " PrintTag('A', true, TagAttrib('HREF', URI(href)), text);\r\n"
  69. "}\r\n"
  70. "\r\n";
  71. //} WinSE 26475
  72. //{ German fixes
  73. CHAR BadGoto[] = " on error go to 0";
  74. CHAR NewGoto[] = " on error goto 0";
  75. CHAR BadThen[] = " If objASPError.ASPDescription > \"\" Then Response.Write Server.HTMLEncode(objASPError.ASPDescription) & \"<br>\"";
  76. CHAR NewThen[] = " If objASPError.ASPDescription > \"\" Then\r\n\tResponse.Write Server.HTMLEncode(objASPError.ASPDescription) & \"<br>\"";
  77. //}
  78. //{ winse 29084: css fixes for admin/document pages
  79. // these are partial lines
  80. CHAR BadDoc1[] = "= Request(";
  81. CHAR BadDoc2[] = "= Request.Form(";
  82. CHAR BadDoc3[] = "= Request.QueryString(";
  83. CHAR BadDoc4[] = "= Request.Cookies(";
  84. CHAR BadDoc5[] = "=Request(";
  85. CHAR BadDoc6[] = "=Request.Form(";
  86. CHAR BadDoc7[] = "=Request.QueryString(";
  87. CHAR BadDoc8[] = "=Request.Cookies(";
  88. CHAR BadDoc9[] = "= request.QueryString(";
  89. CHAR BadDoc10[] = "& Request.QueryString(";
  90. CHAR BadDoc11[] = "Response.write Request.Querystring";
  91. CHAR FixDocCall1[] = "= NoAngles(Request(";
  92. CHAR FixDocCall2[] = "= NoAngles(Request.Form(";
  93. CHAR FixDocCall3[] = "= NoAngles(Request.QueryString(";
  94. CHAR FixDocCall4[] = "= NoAngles(Request.Cookies(";
  95. #define FixDocCall5 FixDocCall1
  96. #define FixDocCall6 FixDocCall2
  97. #define FixDocCall7 FixDocCall3
  98. #define FixDocCall8 FixDocCall4
  99. #define FixDocCall9 FixDocCall3
  100. CHAR FixDocCall10[] = "& NoAngles(Request.QueryString(";
  101. CHAR FixDocCall11[] = ""; // delete this junk
  102. CHAR FixDocCallEnd[] = ")"; // place it after original ")" after Request call
  103. CHAR FixDocNewFuncName[] = "NoAngles(str)";
  104. CHAR FixDocNewFunc[] = // place it at the end of the file if the above line isn't found in file
  105. "\r\n<%\r\n"
  106. "function NoAngles(str)\r\n"
  107. " NoAngles = replace( replace(str, \"<\", \"\"), \">\", \"\")\r\n"
  108. "end function\r\n"
  109. "%>\r\n";
  110. CHAR * DocFilesToFix[] = {
  111. // file list is different for XP and Win2K, and NTOP
  112. #if (VER_PRODUCTVERSION_W == 0x501)
  113. // list for IIS 5.1 (WinXP)
  114. "system32\\inetsrv\\iisadmpwd\\aexp2.asp",
  115. "system32\\inetsrv\\iisadmpwd\\aexp2b.asp",
  116. "system32\\inetsrv\\iisadmpwd\\aexp4.asp",
  117. #elif (VER_PRODUCTVERSION_W == 0x400)
  118. // list for IIS 4
  119. "Help\\iis\\htm\\asp\\iiatmd1.asp",
  120. "Help\\iis\\htm\\asp\\iiatmd2.asp",
  121. "Help\\iis\\htm\\asp\\iiatmd3.asp",
  122. "Help\\iis\\htm\\asp\\iiselect.asp",
  123. "Help\\iis\\htm\\asp\\script1.asp",
  124. "Help\\iis\\htm\\asp\\script1a.asp",
  125. "Help\\iis\\htm\\tutorial\\script1.asp",
  126. "system32\\inetsrv\\iisadmin\\default.asp",
  127. "system32\\inetsrv\\iisadmin\\iiaction.asp",
  128. "system32\\inetsrv\\iisadmin\\iicache.asp",
  129. "system32\\inetsrv\\iisadmin\\iichkpath.asp",
  130. "system32\\inetsrv\\iisadmin\\iihdn.asp",
  131. "system32\\inetsrv\\iisadmin\\iipop.asp",
  132. "system32\\inetsrv\\iisadmin\\iipophd.asp",
  133. "system32\\inetsrv\\iisadmin\\iirename.asp",
  134. "system32\\inetsrv\\iisadmin\\iirtels.asp",
  135. "system32\\inetsrv\\iisadmin\\iiscript.asp",
  136. "system32\\inetsrv\\iisadmin\\iisess.asp",
  137. "system32\\inetsrv\\iisadmin\\iiset.asp",
  138. "system32\\inetsrv\\iisadmin\\iislider.asp",
  139. "system32\\inetsrv\\iisadmin\\iistat.asp",
  140. "system32\\inetsrv\\iisadmin\\jsbrowser\\jsbrwpop.asp",
  141. #else
  142. // list for Win2K
  143. "Help\\iisHelp\\iis\\htm\\asp\\iiatmd1.asp",
  144. "Help\\iisHelp\\iis\\htm\\asp\\iiatmd2.asp",
  145. "Help\\iisHelp\\iis\\htm\\asp\\iiatmd3.asp",
  146. "Help\\iisHelp\\iis\\htm\\asp\\iiselect.asp",
  147. "Help\\iisHelp\\iis\\htm\\tutorial\\script1.asp",
  148. "system32\\inetsrv\\iisadmin\\default.asp",
  149. "system32\\inetsrv\\iisadmin\\iiaddnew.asp",
  150. "system32\\inetsrv\\iisadmin\\iicache.asp",
  151. "system32\\inetsrv\\iisadmin\\iicache2.asp",
  152. "system32\\inetsrv\\iisadmin\\iichknname.asp",
  153. "system32\\inetsrv\\iisadmin\\iichkpath.asp",
  154. "system32\\inetsrv\\iisadmin\\iichkuser.asp",
  155. "system32\\inetsrv\\iisadmin\\iihdn.asp",
  156. "system32\\inetsrv\\iisadmin\\iipop.asp",
  157. "system32\\inetsrv\\iisadmin\\iipophd.asp",
  158. "system32\\inetsrv\\iisadmin\\iirename.asp",
  159. "system32\\inetsrv\\iisadmin\\iiscript.asp",
  160. "system32\\inetsrv\\iisadmin\\iisess.asp",
  161. "system32\\inetsrv\\iisadmin\\iiset.asp",
  162. "system32\\inetsrv\\iisadmin\\iislider.asp",
  163. "system32\\inetsrv\\iisadmin\\iistat.asp",
  164. "system32\\inetsrv\\iisadmin\\jsbrowser\\jsbrwpop.asp",
  165. #endif
  166. NULL
  167. };
  168. //}
  169. CHAR BadKanaler[] = "<h2><a name=\"H2_37780216\"><a name=\"channels\">Skapa dynamiska analer</a></a></h2>";
  170. CHAR NewKanaler[] = "<h2><a name=\"H2_37780216\"><a name=\"channels\">Skapa dynamiska kanaler</a></a></h2>";
  171. CHAR KanalerPath[ MAX_PATH ] = { '\0' };
  172. void
  173. LogMessage( CHAR *msg, ...)
  174. {
  175. static char buf[200];
  176. va_list args;
  177. va_start(args, msg);
  178. vsprintf(buf, msg, args);
  179. OutputDebugString(buf);
  180. }
  181. class TextFile {
  182. public:
  183. TextFile( void );
  184. BOOL Open( CHAR * pszFileName );
  185. BOOL GetLine( CHAR * pszBuffer, int cchBuffer );
  186. void Close( void );
  187. ~TextFile();
  188. private:
  189. FILE * m_File;
  190. BOOL m_fUnicode;
  191. };
  192. TextFile::TextFile( void )
  193. {
  194. m_File = NULL;
  195. }
  196. TextFile::~TextFile()
  197. {
  198. Close();
  199. }
  200. void
  201. TextFile::Close( void )
  202. {
  203. if ( m_File != NULL ) {
  204. fclose( m_File );
  205. m_File = NULL;
  206. }
  207. }
  208. BOOL
  209. TextFile::Open(
  210. CHAR * pszFileName
  211. )
  212. {
  213. Close();
  214. m_File = fopen( pszFileName, "rb" );
  215. if ( m_File == NULL ) {
  216. return( FALSE );
  217. }
  218. if (( fgetc( m_File ) == 0xFF ) &&
  219. ( fgetc( m_File ) == 0xFE )) {
  220. m_fUnicode = TRUE;
  221. }
  222. else {
  223. fseek( m_File, 0, SEEK_SET );
  224. m_fUnicode = FALSE;
  225. }
  226. return( TRUE );
  227. }
  228. BOOL
  229. TextFile::GetLine( CHAR * pszBuffer, int cchBuffer )
  230. {
  231. int c = EOF;
  232. int fSomethingRead = FALSE;
  233. if (( m_File == NULL ) ||
  234. ( cchBuffer == 0 )) {
  235. return FALSE;
  236. }
  237. while ( cchBuffer > 1 ) {
  238. c = fgetc( m_File );
  239. if ( m_fUnicode && ( c != EOF )) {
  240. c += ( fgetc( m_File ) << 8 );
  241. }
  242. if (( c == EOF ) || ( c == '\n' )) {
  243. break;
  244. }
  245. if ( c == '\r' ) {
  246. continue;
  247. }
  248. *pszBuffer++ = (CHAR) c;
  249. cchBuffer--;
  250. fSomethingRead = TRUE;
  251. }
  252. *pszBuffer = '\0';
  253. if ( c == EOF ) {
  254. return( fSomethingRead );
  255. }
  256. return( TRUE );
  257. }
  258. void
  259. TrimString(
  260. CHAR * StrLine
  261. )
  262. {
  263. CHAR * StrOut = StrLine;
  264. BOOL fQuoted = FALSE;
  265. while ( *StrLine ) {
  266. switch ( *StrLine ) {
  267. case '"':
  268. *StrOut++ = *StrLine++;
  269. fQuoted = !fQuoted;
  270. break;
  271. case ' ':
  272. case '\t':
  273. if ( fQuoted ) {
  274. *StrOut++ = *StrLine++;
  275. }
  276. else {
  277. StrLine++;
  278. }
  279. break;
  280. case ';':
  281. if ( fQuoted ) {
  282. *StrOut++ = *StrLine++;
  283. }
  284. else {
  285. *StrLine = '\0';
  286. }
  287. break;
  288. case '\r':
  289. case '\n':
  290. *StrLine = '\0';
  291. break;
  292. default:
  293. *StrOut++ = *StrLine++;
  294. }
  295. }
  296. *StrOut = '\0';
  297. return;
  298. }
  299. CHAR *
  300. GetErrLocation(
  301. CHAR * WinDir
  302. )
  303. {
  304. CHAR filename[ MAX_PATH ];
  305. strcpy( filename, WinDir );
  306. strcat( filename, "\\inf\\iis.inf" );
  307. CHAR FoundPath[ MAX_PATH ] = { '\0' };
  308. TextFile objFile;
  309. if ( objFile.Open( filename ) ) {
  310. CHAR StrLine[ 3000 ];
  311. BOOL SectionOpened = FALSE;
  312. while ( objFile.GetLine( StrLine, sizeof( StrLine ))) {
  313. TrimString( StrLine );
  314. _strlwr( StrLine );
  315. if ( ! SectionOpened ) {
  316. if ( strcmp( StrLine, "[destinationdirs]" ) == 0 ) {
  317. SectionOpened = TRUE;
  318. }
  319. }
  320. else {
  321. if ( StrLine[ 0 ] == '[' ) {
  322. SectionOpened = FALSE;
  323. break;
  324. }
  325. if ( strncmp( StrLine, "iisdoc_files_common=18,", 23 ) == 0 ) {
  326. strcpy( FoundPath, StrLine + 23 );
  327. }
  328. if ( strncmp( StrLine, "iisdoc_files_asp=18,", 20 ) == 0 ) {
  329. strcpy( KanalerPath, WinDir );
  330. strcat( KanalerPath, "\\help\\" );
  331. strcat( KanalerPath, StrLine + 20 );
  332. }
  333. }
  334. }
  335. objFile.Close();
  336. }
  337. static CHAR szResult[ MAX_PATH ];
  338. strcpy( szResult, WinDir );
  339. strcat( szResult, "\\help\\" );
  340. strcat( szResult, FoundPath );
  341. return( szResult );
  342. }
  343. CHAR **
  344. GetErrArray(
  345. CHAR * WinDir
  346. )
  347. {
  348. CHAR filename[ MAX_PATH ];
  349. strcpy( filename, WinDir );
  350. strcat( filename, "\\inf\\iis.inf" );
  351. static CHAR * ArrayFiles[ 50 ];
  352. int i = 0;
  353. TextFile objFile;
  354. if ( objFile.Open( filename ) ) {
  355. CHAR StrLine[ 3000 ];
  356. BOOL SectionOpened = FALSE;
  357. while ( objFile.GetLine( StrLine, sizeof( StrLine ))) {
  358. TrimString( StrLine );
  359. _strlwr( StrLine );
  360. if ( ! SectionOpened ) {
  361. if ( strcmp( StrLine, "[iis_www_files_custerr]" ) == 0 ) {
  362. SectionOpened = TRUE;
  363. }
  364. }
  365. else {
  366. if ( StrLine[ 0 ] == '[' ) {
  367. SectionOpened = FALSE;
  368. break;
  369. }
  370. CHAR * Comma = strchr( StrLine, ',' );
  371. if ( Comma != NULL ) {
  372. *Comma = '\0';
  373. if ( strcmp( StrLine, "htmla.htm" ) != 0 ) {
  374. ArrayFiles[ i++ ] = _strdup( StrLine );
  375. if ( i >= ( countof( ArrayFiles ) - 1 )) {
  376. break;
  377. }
  378. }
  379. }
  380. }
  381. }
  382. objFile.Close();
  383. }
  384. ArrayFiles[ i ] = NULL;
  385. return ArrayFiles;
  386. }
  387. #define MATCHED( BadText ) \
  388. \
  389. (( LineLength == strlen( BadText )) && \
  390. ( strncmp( LineStart, BadText, strlen( BadText )) == 0 )) \
  391. #define REPLACE( BadText, GoodText ) { \
  392. \
  393. int NetChange = int(strlen( GoodText ) - strlen( BadText )); \
  394. int FileRemaining = int(FileEnd - LineEnd); \
  395. \
  396. memmove( LineEnd + NetChange, \
  397. LineEnd, \
  398. FileRemaining + 1 \
  399. ); \
  400. \
  401. memmove( LineStart, \
  402. GoodText, \
  403. strlen( GoodText ) \
  404. ); \
  405. \
  406. FileSize += NetChange; \
  407. LineEnd += NetChange; \
  408. FileEnd += NetChange; \
  409. }
  410. #define INSERT( NewText ) { \
  411. \
  412. int NetChange = int(strlen( NewText )); \
  413. int FileRemaining = int(FileEnd - LineStart); \
  414. \
  415. memmove( LineStart + NetChange, \
  416. LineStart, \
  417. FileRemaining + 1 \
  418. ); \
  419. \
  420. memmove( LineStart, \
  421. NewText, \
  422. strlen( NewText ) \
  423. ); \
  424. \
  425. FileSize += NetChange; \
  426. LineEnd += NetChange; \
  427. FileEnd += NetChange; \
  428. }
  429. DWORD
  430. ReadTargetFile(
  431. CHAR * Base,
  432. CHAR * Filename,
  433. CHAR * buffer,
  434. DWORD size)
  435. {
  436. DWORD fileSize=0;
  437. DWORD readSize=0;
  438. CHAR filename[ MAX_PATH ];
  439. strcpy( filename, Base );
  440. strcat( filename, "\\" );
  441. strcat( filename, Filename );
  442. LogMessage( "Reading :%s\n", filename );
  443. FILE * objFile = fopen( filename, "rb" );
  444. if ( objFile != NULL ) {
  445. fileSize = _filelength( _fileno( objFile ));
  446. if (( fileSize > 0 ) &&
  447. ( fileSize < size-2000 ) &&
  448. ( fileSize != -1L )) {
  449. buffer[ fileSize ] = 0;
  450. if ( fread( buffer, 1, fileSize, objFile ) == fileSize )
  451. {
  452. readSize = fileSize+1; // one byte for null terminator
  453. }
  454. }
  455. fclose(objFile);
  456. }
  457. return readSize;
  458. }
  459. bool
  460. WriteTargetFile(
  461. CHAR * Base,
  462. CHAR * Filename,
  463. CHAR * content,
  464. DWORD size)
  465. {
  466. if (size == 0) return false;
  467. size--; // exclude null terminator
  468. CHAR filename[ MAX_PATH ];
  469. strcpy( filename, Base );
  470. strcat( filename, "\\" );
  471. strcat( filename, Filename );
  472. LogMessage( "Writing :%s\n", filename );
  473. FILE *objFile = fopen( filename, "wb" );
  474. if ( objFile != NULL ) {
  475. fwrite( content, 1, size, objFile );
  476. fclose( objFile );
  477. return true;
  478. }
  479. else {
  480. LogMessage( "Unable to open %s\n", filename );
  481. return false;
  482. }
  483. }
  484. bool
  485. PatchFile(
  486. CHAR * Base,
  487. CHAR * Filename,
  488. CHAR * BadStrings[],
  489. CHAR * NewStrings[]
  490. )
  491. {
  492. long FileSize;
  493. CHAR FileBuffer[41000]; // max file to patch: 40K
  494. FileSize = ReadTargetFile(Base, Filename, FileBuffer, sizeof(FileBuffer));
  495. if (FileSize==0) return false;
  496. BOOL FoundBad = FALSE;
  497. int Insert9 = 0;
  498. CHAR * LineStart = FileBuffer;
  499. CHAR * FileEnd = FileBuffer + FileSize;
  500. while ( LineStart < FileEnd )
  501. {
  502. while (( LineStart < FileEnd ) &&
  503. (( *LineStart == '\r' ) || ( *LineStart == '\n' ))) {
  504. LineStart++;
  505. }
  506. CHAR * LineEnd = LineStart;
  507. while (( LineEnd < FileEnd ) &&
  508. ( *LineEnd != '\r' ) &&
  509. ( *LineEnd != '\n' )) {
  510. LineEnd++;
  511. }
  512. if ( LineEnd < FileEnd )
  513. {
  514. DWORD LineLength = int(LineEnd - LineStart);
  515. CHAR **Bad = BadStrings;
  516. CHAR **New = NewStrings;
  517. while (*Bad)
  518. {
  519. if ( MATCHED( *Bad ))
  520. {
  521. REPLACE( *Bad, *New );
  522. FoundBad = TRUE;
  523. // replacing bad strings #9 require us to insert function
  524. if (*New == NewString9)
  525. {
  526. Insert9 |= 1;
  527. }
  528. break;
  529. }
  530. Bad++;
  531. New++;
  532. }
  533. if (! *Bad)
  534. {
  535. // insert code at the end of script block, if we have code to insert
  536. if (Insert9==1)
  537. {
  538. if ( MATCHED( InsertCodeBefore1 ) || MATCHED( InsertCodeBefore2 ) )
  539. {
  540. INSERT( InsertCode9 );
  541. // flag as inserted
  542. Insert9=2;
  543. }
  544. }
  545. }
  546. }
  547. LineStart = LineEnd;
  548. }
  549. if ( FoundBad )
  550. {
  551. return WriteTargetFile(Base, Filename, FileBuffer, FileSize);
  552. }
  553. return true;
  554. }
  555. bool
  556. PatchFile2(
  557. CHAR * Base,
  558. CHAR * Filename,
  559. CHAR * BadStrings[],
  560. CHAR * NewStrings[],
  561. CHAR * newStringAtEndCall,
  562. CHAR * newFunctionName,
  563. CHAR * newFunction
  564. )
  565. {
  566. bool foundBad = false;
  567. CHAR content[41000]; // max file size to patch: 40K
  568. DWORD fileSize = ReadTargetFile(Base, Filename, content, sizeof(content));
  569. if (fileSize==0) return false;
  570. bool newFuncExists = (strstr(content, newFunctionName)!=NULL);
  571. CHAR ** pBad = BadStrings;
  572. CHAR ** pFix = NewStrings;
  573. while (*pBad!=NULL)
  574. {
  575. int sizeOld = strlen( *pBad );
  576. int sizeNew = strlen( *pFix );
  577. int sizeDiff = sizeNew - sizeOld;
  578. // scan through the whole content
  579. char *p = content;
  580. while ( (p=strstr(p, *pBad)) != NULL)
  581. {
  582. foundBad = true;
  583. // replace old string with new string
  584. memmove(p+sizeNew, p+sizeOld, fileSize-(p+sizeOld-content));
  585. memmove(p, *pFix, sizeNew);
  586. fileSize += sizeDiff;
  587. p += sizeNew;
  588. // if we have a newStringAtEndCall
  589. // and we are not deleting this string (*pFix is empty string)
  590. if (newStringAtEndCall && *newStringAtEndCall && **pFix)
  591. {
  592. char *pEndCall = strchr(p, ')');
  593. if ( pEndCall )
  594. {
  595. // insert new string at end of function call
  596. ++pEndCall;
  597. int sizeDiff = strlen(newStringAtEndCall);
  598. memmove(pEndCall+sizeDiff, pEndCall, fileSize-(pEndCall-content));
  599. memmove(pEndCall, newStringAtEndCall, sizeDiff);
  600. fileSize += sizeDiff;
  601. p = pEndCall+sizeDiff;
  602. }
  603. }
  604. }
  605. pBad++;
  606. pFix++;
  607. }
  608. if (foundBad)
  609. {
  610. if (! newFuncExists)
  611. {
  612. strcat(content, newFunction);
  613. fileSize += strlen(newFunction);
  614. }
  615. return WriteTargetFile(Base, Filename, content, fileSize);
  616. }
  617. return true;
  618. }
  619. int WINAPI
  620. WinMain(
  621. HINSTANCE hInstance,
  622. HINSTANCE hPrevInstance,
  623. LPSTR lpCmdLine,
  624. int nShowCmd )
  625. {
  626. int i;
  627. CHAR StrWINDIR[ MAX_PATH ];
  628. GetEnvironmentVariable( "WINDIR",
  629. StrWINDIR,
  630. sizeof( StrWINDIR )
  631. );
  632. CHAR *BadStrings[20];
  633. CHAR *NewStrings[20];
  634. // == fixing custom error pages ==
  635. #if !(VER_PRODUCTVERSION_W == 0x400)
  636. BadStrings[0] = BadString1;
  637. NewStrings[0] = NewString9;
  638. BadStrings[1] = BadString2;
  639. NewStrings[1] = NewString2;
  640. BadStrings[2] = BadGoto;
  641. NewStrings[2] = NewGoto;
  642. BadStrings[3] = BadString9;
  643. NewStrings[3] = NewString9;
  644. BadStrings[4] = BadString13;
  645. NewStrings[4] = NewString13;
  646. BadStrings[5] = BadThen;
  647. NewStrings[5] = NewThen;
  648. BadStrings[6] = NULL;
  649. CHAR * BasePath = GetErrLocation( StrWINDIR );
  650. CHAR ** ArrayNames = GetErrArray( StrWINDIR );
  651. LogMessage( "Processing %s\n", BasePath );
  652. for ( i = 0; ArrayNames[ i ] != NULL; i++ ) {
  653. __try {
  654. PatchFile( BasePath, ArrayNames[ i ], BadStrings, NewStrings );
  655. }
  656. __except( EXCEPTION_EXECUTE_HANDLER ) {
  657. }
  658. }
  659. if ( KanalerPath[ 0 ] != '\0' ) {
  660. BadStrings[0] = BadKanaler;
  661. NewStrings[0] = NewKanaler;
  662. BadStrings[1] = BadGoto;
  663. NewStrings[1] = NewGoto;
  664. BadStrings[2] = NULL;
  665. LogMessage( "Processing %s\n", KanalerPath );
  666. __try {
  667. PatchFile( KanalerPath, "iiwacont.htm", BadStrings, NewStrings );
  668. }
  669. __except( EXCEPTION_EXECUTE_HANDLER ) {
  670. }
  671. }
  672. #endif // !(VER_PRODUCTVERSION_W == 0x400)
  673. // fix query.asp by shipping its new version
  674. /*
  675. BadStrings[0] = BadString4;
  676. NewStrings[0] = NewString4;
  677. BadStrings[1] = BadString5;
  678. NewStrings[1] = NewString5;
  679. BadStrings[2] = BadString6;
  680. NewStrings[2] = NewString6;
  681. BadStrings[3] = BadString7;
  682. NewStrings[3] = NewString7;
  683. BadStrings[4] = BadString8;
  684. NewStrings[4] = NewString8;
  685. BadStrings[5] = NULL;
  686. __try {
  687. PatchFile( BasePath, "..\\iis\\misc\\query.asp", BadStrings, NewStrings );
  688. }
  689. __except( EXCEPTION_EXECUTE_HANDLER ) {
  690. }
  691. */
  692. // == fixing asp help docs and admin pages ==
  693. BadStrings[0] = BadDoc1;
  694. NewStrings[0] = FixDocCall1;
  695. BadStrings[1] = BadDoc2;
  696. NewStrings[1] = FixDocCall2;
  697. BadStrings[2] = BadDoc3;
  698. NewStrings[2] = FixDocCall3;
  699. BadStrings[3] = BadDoc4;
  700. NewStrings[3] = FixDocCall4;
  701. BadStrings[4] = BadDoc5;
  702. NewStrings[4] = FixDocCall5;
  703. BadStrings[5] = BadDoc6;
  704. NewStrings[5] = FixDocCall6;
  705. BadStrings[6] = BadDoc7;
  706. NewStrings[6] = FixDocCall7;
  707. BadStrings[7] = BadDoc8;
  708. NewStrings[7] = FixDocCall8;
  709. BadStrings[8] = BadDoc9;
  710. NewStrings[8] = FixDocCall9;
  711. BadStrings[9] = BadDoc10;
  712. NewStrings[9] = FixDocCall10;
  713. BadStrings[10] = BadDoc11;
  714. NewStrings[10] = FixDocCall11;
  715. BadStrings[11] = NULL;
  716. for (CHAR **pDocFiles=DocFilesToFix; *pDocFiles; pDocFiles++)
  717. {
  718. __try {
  719. PatchFile2( StrWINDIR, *pDocFiles, BadStrings, NewStrings, FixDocCallEnd, FixDocNewFuncName, FixDocNewFunc );
  720. }
  721. __except( EXCEPTION_EXECUTE_HANDLER ) {
  722. }
  723. }
  724. LogMessage( "Done" );
  725. return( 0 );
  726. }