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.

110 lines
3.5 KiB

  1. 'Fhash is a file containing the line we
  2. 'want to replace form ?_hash.txt. NHash is
  3. 'the hash to replace it.
  4. DIM FSO,HashTextFileName,HashTextFile,HashTextFileLine,MyVar,FirstArg
  5. DIM HashTextFileOutName,HashTextFileOut,HashTextFileOutLine
  6. DIM NHash,FHashFileName,NHashFileName,FHashFile,NHashFile,FHashText,NHashText,Ptr,SystemCommand
  7. Set FSO=CreateObject("Scripting.FileSystemObject")
  8. 'Check for help
  9. FirstArg=Wscript.Arguments(0)
  10. If FirstArg="/?" then
  11. Usage
  12. End if
  13. If FirstArg="-?" then
  14. Usage
  15. End if
  16. If FirstArg="?" then
  17. Usage
  18. End if
  19. FHashFileName=FirstArg
  20. NHashFileName=Wscript.Arguments(1)
  21. HashTextFileName=Wscript.Arguments(2)
  22. If not FSO.FileExists (FHashFileName) then
  23. Wscript.Stdout.Writeline("Cannot find" & FHashFileName)
  24. WScript.Quit(1)
  25. End If
  26. If not FSO.FileExists (NHashFileName) then
  27. Wscript.Stdout.Writeline("Cannot find" & NHashFileName)
  28. WScript.Quit(1)
  29. End If
  30. If not FSO.FileExists (HashTextFileName) then
  31. Wscript.Stdout.Writeline("Cannot find" & HashTextFileName)
  32. WScript.Quit(1)
  33. End If
  34. Set FHashFile=FSO.GetFile(FHashFileName)
  35. Set NHashFile=FSO.GetFile(NHashFileName)
  36. Set FHashText=FHashFile.OpenAsTextStream()
  37. Set NHashText=NHashFile.OpenAsTextStream()
  38. 'Get the filename
  39. While not FHashText.AtEndOfStream '& not done
  40. FHashLine=FHashText.Readline
  41. ' now we have the line from FHash.tmp
  42. ' we need to parse out the path\filename and the hash
  43. Ptr = Instr(FHashLine,"=")
  44. FilePath = Left(FHashLine,Ptr)
  45. ' if Ptr > 0 then
  46. ' done=true
  47. ' FilePath = Left(FHashLine,Ptr)
  48. ' end if
  49. Wend
  50. 'Now get the new hash
  51. While not NHashText.AtEndOfStream
  52. NHashLine=NHashText.Readline
  53. NHash=NHashLine
  54. Wend
  55. Set HashTextFile=FSO.GetFile(HashTextFileName)
  56. Set HashTextFileText=HashTextFile.OpenAsTextStream()
  57. Ptr=InStr(HashTextFileName,".")
  58. HashTextFileOutName=Left(HashTextFileName,Ptr)
  59. HashTextFileOutName=HashTextFileOutName&"tmp"
  60. if FSO.FileExists (HashTextFileOutName) then
  61. FSO.DeleteFile(HashTextFileOutName)
  62. End If
  63. Set HashTextFileOutText=FSO.CreateTextFile(HashTextFileOutName)
  64. While not HashTextFileText.AtEndOfStream
  65. HashTextFileLine=HashTextFileText.Readline
  66. ' now we need to check if the line begins with our name
  67. ' if it doesn't, just append to the tmp file
  68. ' if it does, replace the line with the new one.
  69. Ptr=InStr(HashTextFileLine,"=")
  70. if Left(HashTextFileLine,Ptr)=FilePath then
  71. ' do our replacement here
  72. HashTextFileOutText.Writeline FilePath & NHash
  73. else
  74. ' do our append here
  75. HashTextFileOutText.Writeline HashTextFileLine
  76. End If
  77. Wend
  78. ' now rename the tmp file to the txt file.
  79. ' system call is easiest here.
  80. Set ShellObj = CreateObject("WScript.Shell")
  81. myVar="mv " & HashTextFileOutName & " " & HashTextFileName
  82. Call ShellObj.Run(myVar)
  83. Sub Usage()
  84. Wscript.stdout.writeline("")
  85. Wscript.stdout.writeline("Hashrep.vbs: Replaces the hash of file you are updating in ?_hash.txt")
  86. Wscript.stdout.writeline(" with the file's new hash, to be used for future backprops.")
  87. Wscript.stdout.writeline("")
  88. Wscript.stdout.writeline("Syntax:")
  89. Wscript.stdout.writeline("")
  90. Wscript.stdout.writeline(" Hashrep.vbs %TMP%\Fhash.tmp %TMP%\Nhash.tmp %BINARIES%\dump\cathash\?_Hash.txt")
  91. Wscript.stdout.writeline("")
  92. Wscript.stdout.writeline(" Fhash.tmp: Conatins the file path and its old hash")
  93. Wscript.stdout.writeline(" Nhash.tmp: Conatins the file's new hash")
  94. Wscript.stdout.writeline(" ?_Hash.txt: Conatins all of ?.cat's hash's and there associated file names.")
  95. Wscript.stdout.writeline("")
  96. Wscript.stdout.writeline("This script is called by %BLDTOOLS%\updtcat.cmd")
  97. Wscript.Quit(0)
  98. End Sub