test.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. "Wolf_Update_131_full.exe::https://archive.org/download/Wolf_Update_131_full_exe/Wolf_Update_131_full.exe"
  22. )
  23. SHA256_SUMS=( \
  24. "35baa2058bf41f872b418e1545d3a8bb92f13f7db211d734e522863b95651604" \
  25. "8ffa2117e8e49162b83adec298ac5c8e40c4dd5994950c0525f49b99374e5f71" \
  26. "9f236e9785980c127d46870a828ba4dac756308767ebd498b85bd7edff3305a8" \
  27. "55b48c810ee65e8b4da88d18ae248ab8e2ade2f9356ae44631bce74780217599" \
  28. "505a096000f8b53fe8d2a3c5dae33b226d69b556db13cc5f26a0b72fbd54be72" \
  29. "2963e480b02e5e29b2577d897ce99355d863d7db580b5d670e070baa2be3a0e5" \
  30. "bb92239488dc40459d68ecd8dffba7eda4824c41bd911e1483c85efe60eab035" \
  31. "fb5f6431535e8184826ebdf19fc51bfff34c4c6272da4ec8bd3c551fb989af54" \
  32. "7a5127c236f7d96534b59d085c654633fb081f28c89afc024eab606ca5eadaef" \
  33. "67033508330e78f8f9687c9b2fe697122dc50b447d9e1a3074627f6935315e3c"
  34. )
  35. dl_installer() {
  36. FILEPATH="$1"
  37. URL="$2"
  38. wget --quiet -O "${FILEPATH}" "${URL}"
  39. if [[ "$?" -ne "0" ]]; then
  40. echo "Failed"
  41. exit 1
  42. fi
  43. }
  44. verify_installer() {
  45. SHASUM="$1"
  46. FILEPATH="$2"
  47. sha256sum --quiet -c - <<< "${SHASUM} ${FILEPATH}"
  48. if [[ "$?" -ne "0" ]]; then
  49. echo "Mismatch"
  50. exit 1
  51. fi
  52. }
  53. clear_extract_dir() {
  54. rm -rf "${EXTRACT_PATH}" && mkdir "${EXTRACT_PATH}"
  55. }
  56. test_corrupted_patch() {
  57. PATCH_FILE="${SELF_PATH}/patches/$1"
  58. # Workaround to extract WiseScript.bin to the TMP path.
  59. ../rewise -lp --tmp-path "${TMP_PATH}" "${DL_PATH}/hluplink.exe" 1>/dev/null
  60. # Backup the extracted WiseScript.bin
  61. mv "${TMP_PATH}/WiseScript.bin" "${TMP_PATH}/WiseScript.bin.bak"
  62. # Corrupt a filesize to 0xFFFFFFFF
  63. bspatch "${TMP_PATH}/WiseScript.bin.bak" "${TMP_PATH}/WiseScript.bin" "${PATCH_FILE}"
  64. # See how REWise reponds
  65. ../rewise --no-extract --verify --silent --tmp-path "${TMP_PATH}" "${DL_PATH}/hluplink.exe"
  66. if [[ "$?" -eq "0" ]]; then
  67. # REWise did not fail, but it should have!
  68. echo "Failed"
  69. rm "${TMP_PATH}/WiseScript.bin"
  70. rm "${TMP_PATH}/WiseScript.bin.bak"
  71. exit 1
  72. fi
  73. rm "${TMP_PATH}/WiseScript.bin"
  74. rm "${TMP_PATH}/WiseScript.bin.bak"
  75. echo "OK"
  76. }
  77. # Create cache dirs
  78. if [[ ! -d "${DL_PATH}" ]]; then
  79. mkdir -p "${DL_PATH}"
  80. fi
  81. if [[ ! -d "${EXTRACT_PATH}" ]]; then
  82. mkdir "${EXTRACT_PATH}"
  83. fi
  84. if [[ ! -d "${TMP_PATH}" ]]; then
  85. mkdir "${TMP_PATH}"
  86. fi
  87. # cd into SELF_PATH so rewise can be found by ../rewise
  88. cd "${SELF_PATH}"
  89. # Make sure rewise is present.
  90. if [[ ! -f "../rewise" ]]; then
  91. echo "REWise (${SELF_PATH}/../rewise) not found."
  92. exit 1
  93. fi
  94. for i in ${!FILES[@]}; do
  95. FILE="${FILES[i]}"
  96. FILENAME="${FILE%%::*}"
  97. FILEURL="${FILE#*::}"
  98. FILEPATH="${DL_PATH}/${FILENAME}"
  99. echo "TEST ${FILENAME}"
  100. echo "-------------------------------------------------------------"
  101. # Make sure the installer file is present, else download it.
  102. if [[ ! -f "${FILEPATH}" ]]; then
  103. echo -n "DOWNLOAD file : "
  104. dl_installer "${FILEPATH}" "${FILEURL}"
  105. echo "OK"
  106. fi
  107. # Verify installer file its sha256.
  108. echo -n "CHECK file integrity : "
  109. verify_installer "${SHA256_SUMS[i]}" "${FILEPATH}"
  110. echo "OK"
  111. # Test --verify
  112. # This assumes REWise will exit accordingly.
  113. echo -n "CHECK rewise verify : "
  114. ../rewise --verify --silent "${FILEPATH}"
  115. if [[ "$?" -ne "0" ]]; then
  116. echo "Failed"
  117. exit 2
  118. fi
  119. echo "OK"
  120. # Test --extract
  121. echo -n "CHECK rewise extract : "
  122. ../rewise --extract "${EXTRACT_PATH}" --silent "${FILEPATH}"
  123. if [[ "$?" -ne "0" ]]; then
  124. echo "Failed"
  125. clear_extract_dir
  126. exit 2
  127. fi
  128. # Match sha256 sums of extracted files.
  129. (
  130. cd "${EXTRACT_PATH}"
  131. sha256sum --quiet -c "${SELF_PATH}/sums/${FILENAME}.extracted.sha256"
  132. if [[ "$?" -ne "0" ]]; then
  133. echo "Mismatch"
  134. clear_extract_dir
  135. exit 1
  136. fi
  137. )
  138. echo "OK"
  139. clear_extract_dir
  140. echo "-------------------------------------------------------------"
  141. echo ""
  142. done
  143. # Corrupt the WiseScript.bin from hluplink.exe and see how REWise responds,
  144. # REWise should fail each time which will result in a OK.
  145. #
  146. # corrupt_filesize_1.patch
  147. # Will patch a filesize in the WiseScript.bin to 0xFFFFFFFF
  148. #
  149. # corrupt_filesize_2.patch
  150. # Will patch a filesize in the WiseScript.bin to 0x00000000
  151. #
  152. # corrupt_crc32.patch
  153. # Will patch a CRC32 to an invalid one.
  154. echo "Going to corrupt WiseScript.bin from hluplink.exe"
  155. echo "-------------------------------------------------------------"
  156. # Skip this test because REWise doesn't check if the inflated size is
  157. # smaller then the advertised size anymore, it only checks if the
  158. # inflated size is larger then the advertised/expected size.
  159. #echo -n "Corrupt filesize 1 : "
  160. #test_corrupted_patch "corrupt_filesize_1.patch"
  161. echo -n "Corrupt filesize : "
  162. test_corrupted_patch "corrupt_filesize_2.patch"
  163. echo -n "Corrupt CRC32 : "
  164. test_corrupted_patch "corrupt_crc32.patch"
  165. echo ""
  166. function test_filtered_extract() {
  167. FILENAME="${1}"
  168. OPT_KEY="${2}"
  169. OPT_VAL="${3}"
  170. SHA_EXTRA="${4}"
  171. OPT_KEY2="${5}"
  172. OPT_VAL2="${6}"
  173. cd "${SELF_PATH}"
  174. echo -n "'${SHA_EXTRA}' for ${FILENAME}: "
  175. ../rewise -x "${EXTRACT_PATH}" "${OPT_KEY}" "${OPT_VAL}" ${OPT_KEY2} ${OPT_VAL2} --silent "${DL_PATH}/${FILENAME}"
  176. if [[ "$?" -ne "0" ]]; then
  177. echo "Failed"
  178. clear_extract_dir
  179. exit 2
  180. fi
  181. cd "${EXTRACT_PATH}"
  182. sha256sum --quiet -c "${SELF_PATH}/sums/${FILENAME}.extracted.${SHA_EXTRA}.sha256"
  183. if [[ "$?" -ne "0" ]]; then
  184. echo "Mismatch"
  185. clear_extract_dir
  186. exit 1
  187. fi
  188. clear_extract_dir
  189. echo "Success!"
  190. }
  191. # Extract specific language test
  192. echo "Test extracting by language"
  193. echo "-------------------------------------------------------------"
  194. test_filtered_extract "Wolf_Update_131_full.exe" "-g" 0 "en"
  195. test_filtered_extract "Wolf_Update_131_full.exe" "-g" 2 "de"
  196. echo ""
  197. # Extract specific language test
  198. echo "Test extracting by components and language"
  199. echo "-------------------------------------------------------------"
  200. test_filtered_extract "Wolf_Update_131_full.exe" "-g" 2 "de-A" "-c" "A"
  201. test_filtered_extract "Wolf_Update_131_full.exe" "-g" 2 "de-B" "-c" "B"
  202. echo ""
  203. echo "All seems OK! :-D"
  204. exit 0