3 ## Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # Purpose: Create a corrupt (invalid ZIP) version of a Chromium crx.
9 echo "Usage: bad_zip.sh <extension dir> <pem path>"
14 name
=$
(basename "$dir")
19 trap 'rm -f "$pub" "$sig" "$zip"' EXIT
22 (cd "$dir" && zip -qr -9 -X "$cwd/$zip" .
)
23 # truncate the zip to 8K so it's invalid
24 dd if=$zip of
=$zip+ bs
=1024 count
=8 2>/dev
/null
&& mv $zip+ $zip
26 openssl sha1
-sha1 -binary -sign "$key" < "$zip" > "$sig"
28 openssl rsa
-pubout -outform DER
< "$key" > "$pub" 2>/dev
/null
30 # Take "abcdefgh" and return it as "ghefcdab"
31 echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}"
33 crmagic_hex
="4372 3234" # Cr24
34 version_hex
="0200 0000" # 2
35 pub_len_hex
=$
(byte_swap $
(printf '%08x\n' $
(ls -l "$pub" |
awk '{print $5}')))
36 sig_len_hex
=$
(byte_swap $
(printf '%08x\n' $
(ls -l "$sig" |
awk '{print $5}')))
38 echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd
-r -p
39 cat "$pub" "$sig" "$zip"
41 echo "Wrote $crx with invalid ZIP"