forked from jotaki/Extract-Kernel-Initramfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature.sh
57 lines (50 loc) · 1.22 KB
/
signature.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
####
# Supported signatures
#####
# Signatures
ALL_SIGS='gzip bzip2 lzma none'
GZIP_SIG='\x1F\x8B\x08'
BZIP_SIG='\x31\x41\x59\x26\x53\x59'
LZMA_SIG='\x5D\x00\x..\xFF\xFF\xFF\xFF\xFF\xFF'
CPIO_SIG='070701'
####
# Wrapper to use appropriate decompression tool
# exports SIGNATURE, COMMAND, CSCHEME and SIG_ADJ (signature offset adjustment)
# environment variables. use: use_signature --zap to unset.
####
function use_signature()
{
echo_debug "Function: use_signature()"
SIG_ADJ=1
case $1 in
gzip)
SIGNATURE=$GZIP_SIG
COMMAND='gunzip -9fq'
CSCHEME=gzip
;;
bzip2)
SIGNATURE=$BZIP_SIG
COMMAND='bunzip2 -q'
CSCHEME=bzip2
SIG_ADJ=-3
;;
lzma)
SIGNATURE=$LZMA_SIG
COMMAND='unlzma -q'
CSCHEME=lzma
;;
none)
SIGNATURE=$CPIO_SIG
COMMAND=cat
CSCHEME=none
;;
--zap)
unset SIGNATURE COMMAND CSCHEME SIG_ADJ
return 0
;;
*)
echo_error "Invalid usage of use_signature()"
exit 1
esac
export SIGNATURE COMMAND CSCHEME SIG_ADJ
}