test.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/bin/bash
  2. # - Test rewise --verify on installers.
  3. # - Test rewise --extract on installers and check sha256 sums of extracted
  4. # files.
  5. # - Test lying/corrupt WiseScript.bin
  6. SELF_PATH="$(dirname $(realpath "$0"))"
  7. CACHE_PATH="${SELF_PATH}/cache"
  8. DL_PATH="${CACHE_PATH}/dl"
  9. EXTRACT_PATH="${CACHE_PATH}/extract"
  10. TMP_PATH="${CACHE_PATH}/tmp"
  11. FILES=( \
  12. "hl1110.exe::http://archive.org/download/half-life-patches/English/Update 1.1.1.0 English/hl1110.exe" \
  13. "steaminstall_halflife.exe::http://archive.org/download/steaminstall_halflife/steaminstall_halflife.exe" \
  14. "hluplink.exe::http://archive.org/download/Half-lifeUplink/hluplink.exe" \
  15. "opfordemofull.exe::https://archive.org/download/opfor-demo/opfordemofull.exe" \
  16. "hl_sdk_v23.exe::https://downloads.ammahls.com/HLSDK/hl_sdk_v23.exe" \
  17. "csv15full.exe::https://archive.org/download/counter-strike-betas-windows/csv15full.exe" \
  18. "wolf_spdemo.exe::http://www.wolfenstein-files.de/rtcw/demos/wolf_spdemo.exe" \
  19. "Wolf_MPDemo.exe::http://www.wolfenstein-files.de/rtcw/demos/Wolf_MPDemo.exe" \
  20. "WolfET.exe::http://www.wolfenstein-files.de/et/demos/WolfET.exe"
  21. )
  22. SHA256_SUMS=( \
  23. "35baa2058bf41f872b418e1545d3a8bb92f13f7db211d734e522863b95651604" \
  24. "8ffa2117e8e49162b83adec298ac5c8e40c4dd5994950c0525f49b99374e5f71" \
  25. "9f236e9785980c127d46870a828ba4dac756308767ebd498b85bd7edff3305a8" \
  26. "55b48c810ee65e8b4da88d18ae248ab8e2ade2f9356ae44631bce74780217599" \
  27. "505a096000f8b53fe8d2a3c5dae33b226d69b556db13cc5f26a0b72fbd54be72" \
  28. "2963e480b02e5e29b2577d897ce99355d863d7db580b5d670e070baa2be3a0e5" \
  29. "bb92239488dc40459d68ecd8dffba7eda4824c41bd911e1483c85efe60eab035" \
  30. "fb5f6431535e8184826ebdf19fc51bfff34c4c6272da4ec8bd3c551fb989af54" \
  31. "7a5127c236f7d96534b59d085c654633fb081f28c89afc024eab606ca5eadaef"
  32. )
  33. dl_installer() {
  34. FILEPATH="$1"
  35. URL="$2"
  36. wget --quiet -O "${FILEPATH}" "${URL}"
  37. if [[ "$?" -ne "0" ]]; then
  38. echo "Failed"
  39. exit 1
  40. fi
  41. }
  42. verify_installer() {
  43. SHASUM="$1"
  44. FILEPATH="$2"
  45. sha256sum --quiet -c - <<< "${SHASUM} ${FILEPATH}"
  46. if [[ "$?" -ne "0" ]]; then
  47. echo "Mismatch"
  48. exit 1
  49. fi
  50. }
  51. clear_extract_dir() {
  52. rm -rf "${EXTRACT_PATH}" && mkdir "${EXTRACT_PATH}"
  53. }
  54. test_corrupted_patch() {
  55. PATCH_FILE="${SELF_PATH}/patches/$1"
  56. # Workaround to extract WiseScript.bin to the TMP path.
  57. ../rewise -lp --tmp-path "${TMP_PATH}" "${DL_PATH}/hluplink.exe" 1>/dev/null
  58. # Backup the extracted WiseScript.bin
  59. mv "${TMP_PATH}/WiseScript.bin" "${TMP_PATH}/WiseScript.bin.bak"
  60. # Corrupt a filesize to 0xFFFFFFFF
  61. bspatch "${TMP_PATH}/WiseScript.bin.bak" "${TMP_PATH}/WiseScript.bin" "${PATCH_FILE}"
  62. # See how REWise reponds
  63. ../rewise --no-extract --verify --silent --tmp-path "${TMP_PATH}" "${DL_PATH}/hluplink.exe"
  64. if [[ "$?" -eq "0" ]]; then
  65. # REWise did not fail, but it should have!
  66. echo "Failed"
  67. rm "${TMP_PATH}/WiseScript.bin"
  68. rm "${TMP_PATH}/WiseScript.bin.bak"
  69. exit 1
  70. fi
  71. rm "${TMP_PATH}/WiseScript.bin"
  72. rm "${TMP_PATH}/WiseScript.bin.bak"
  73. echo "OK"
  74. }
  75. # Create cache dirs
  76. if [[ ! -d "${DL_PATH}" ]]; then
  77. mkdir -p "${DL_PATH}"
  78. fi
  79. if [[ ! -d "${EXTRACT_PATH}" ]]; then
  80. mkdir "${EXTRACT_PATH}"
  81. fi
  82. if [[ ! -d "${TMP_PATH}" ]]; then
  83. mkdir "${TMP_PATH}"
  84. fi
  85. # cd into SELF_PATH so rewise can be found by ../rewise
  86. cd "${SELF_PATH}"
  87. # Make sure rewise is present.
  88. if [[ ! -f "../rewise" ]]; then
  89. echo "REWise (${SELF_PATH}/../rewise) not found."
  90. exit 1
  91. fi
  92. for i in ${!FILES[@]}; do
  93. FILE="${FILES[i]}"
  94. FILENAME="${FILE%%::*}"
  95. FILEURL="${FILE#*::}"
  96. FILEPATH="${DL_PATH}/${FILENAME}"
  97. echo "TEST ${FILENAME}"
  98. echo "-------------------------------------------------------------"
  99. # Make sure the installer file is present, else download it.
  100. if [[ ! -f "${FILEPATH}" ]]; then
  101. echo -n "DOWNLOAD file : "
  102. dl_installer "${FILEPATH}" "${FILEURL}"
  103. echo "OK"
  104. fi
  105. # Verify installer file its sha256.
  106. echo -n "CHECK file integrity : "
  107. verify_installer "${SHA256_SUMS[i]}" "${FILEPATH}"
  108. echo "OK"
  109. # Test --verify
  110. # This assumes REWise will exit accordingly.
  111. echo -n "CHECK rewise verify : "
  112. ../rewise --verify --silent "${FILEPATH}"
  113. if [[ "$?" -ne "0" ]]; then
  114. echo "Failed"
  115. exit 2
  116. fi
  117. echo "OK"
  118. # Test --extract
  119. echo -n "CHECK rewise extract : "
  120. ../rewise --extract "${EXTRACT_PATH}" --silent "${FILEPATH}"
  121. if [[ "$?" -ne "0" ]]; then
  122. echo "Failed"
  123. clear_extract_dir
  124. exit 2
  125. fi
  126. # Match sha256 sums of extracted files.
  127. (
  128. cd "${EXTRACT_PATH}"
  129. sha256sum --quiet -c "${SELF_PATH}/sums/${FILENAME}.extracted.sha256"
  130. if [[ "$?" -ne "0" ]]; then
  131. echo "Mismatch"
  132. clear_extract_dir
  133. exit 1
  134. fi
  135. )
  136. echo "OK"
  137. clear_extract_dir
  138. echo "-------------------------------------------------------------"
  139. echo ""
  140. done
  141. # Corrupt the WiseScript.bin from hluplink.exe and see how REWise responds,
  142. # REWise should fail each time which will result in a OK.
  143. #
  144. # corrupt_filesize_1.patch
  145. # Will patch a filesize in the WiseScript.bin to 0xFFFFFFFF
  146. #
  147. # corrupt_filesize_2.patch
  148. # Will patch a filesize in the WiseScript.bin to 0x00000000
  149. #
  150. # corrupt_crc32.patch
  151. # Will patch a CRC32 to an invalid one.
  152. echo "Going to corrupt WiseScript.bin from hluplink.exe"
  153. echo "-------------------------------------------------------------"
  154. # Skip this test because REWise doesn't check if the inflated size is
  155. # smaller then the advertised size anymore, it only checks if the
  156. # inflated size is larger then the advertised/expected size.
  157. #echo -n "Corrupt filesize 1 : "
  158. #test_corrupted_patch "corrupt_filesize_1.patch"
  159. echo -n "Corrupt filesize : "
  160. test_corrupted_patch "corrupt_filesize_2.patch"
  161. echo -n "Corrupt CRC32 : "
  162. test_corrupted_patch "corrupt_crc32.patch"
  163. echo ""
  164. echo "All seems OK! :-D"
  165. exit 0