-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path5-extract-fw.sh
executable file
·61 lines (43 loc) · 2.73 KB
/
5-extract-fw.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
57
58
59
60
61
#!/bin/bash -xe
. 0-vars
# remove OpenRG header (640 bytes), decrypt the file, remove uImage header (64 bytes)
#dd if=dl/bt_prod_sec.enc.rms-${fw_version} bs=640 skip=1 | \
# openssl enc -d -aes-256-cbc -K ${key} -iv 00000000000000000000000000000000 -nopad | \
# cat > build/openrg-kernel+initramfs+mainfs+modfs.orig.lzma.u-boot
dd if=dl/bt_prod_sec.enc.rms-${fw_version} bs=640 skip=1 | \
openssl enc -d -aes-256-cbc -K ${key} -iv 00000000000000000000000000000000 -nopad | \
dd bs=64 skip=1 \
> build/openrg-kernel+initramfs+mainfs+modfs.orig.lzma.tmp
# trim last 8 bytes
dd if=build/openrg-kernel+initramfs+mainfs+modfs.orig.lzma.tmp \
bs=$(($(stat -c %s build/openrg-kernel+initramfs+mainfs+modfs.orig.lzma.tmp)-8)) \
> build/openrg-kernel+initramfs+mainfs+modfs.orig.lzma
rm build/openrg-kernel+initramfs+mainfs+modfs.orig.lzma.tmp
# unlzma
lzma_alone d build/openrg-kernel+initramfs+mainfs+modfs.orig.lzma \
build/openrg-kernel+initramfs+mainfs+modfs.orig
rm build/openrg-kernel+initramfs+mainfs+modfs.orig.lzma
# $ binwalk build/openrg-kernel+initramfs+mainfs+modfs.orig
#
# DECIMAL HEXADECIMAL DESCRIPTION
# --------------------------------------------------------------------------------
# ...
# 4845568 0x49F000 gzip compressed data, maximum compression, from Unix, last modified: 2017-04-11 12:24:39
# 4861952 0x4A3000 CramFS filesystem, little endian, size: 9568256 version 2 sorted_dirs CRC 0x7664E22F, edition 0, 880 blocks, 583 files
# 14430208 0xDC3000 CramFS filesystem, little endian, size: 1376256 version 2 sorted_dirs CRC 0x57413A5E, edition 0, 89 blocks, 43 files
# kernel, minus embedded initramfs, mainfs and modfs images
dd if=build/openrg-kernel+initramfs+mainfs+modfs.orig bs=${pos1} count=1 of=build/openrg-kernel.orig
# initramfs - contains mostly symlinks to files in /mnt/cramfs
dd if=build/openrg-kernel+initramfs+mainfs+modfs.orig bs=${pos1} skip=1 of=build/openrg-initramfs.orig.tmp
dd if=build/openrg-initramfs.orig.tmp bs=$((pos2-pos1)) count=1 of=build/openrg-initramfs.orig
rm build/openrg-initramfs.orig.tmp
# cramfs_mainfs - mounted at /mnt/cramfs at runtime
dd if=build/openrg-kernel+initramfs+mainfs+modfs.orig bs=${pos2} skip=1 of=build/openrg-mainfs.orig.tmp
dd bs=$((pos3-pos2)) count=1 if=build/openrg-mainfs.orig.tmp of=build/openrg-mainfs.orig
rm build/openrg-mainfs.orig.tmp
# cramfs_modfs - contains most of the kernel modules, mounted at /mnt/modfs at boot time, unmounted after the modules are loaded
dd if=build/openrg-kernel+initramfs+mainfs+modfs.orig bs=${pos3} skip=1 of=build/openrg-modfs.orig
# extract mainfs
[[ -d build/mainfs.orig ]] && rm -rf build/mainfs.orig
build/lzma-uncramfs/lzma-uncramfs build/mainfs.orig build/openrg-mainfs.orig
echo "Success!"