-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (59 loc) · 2.45 KB
/
Makefile
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#
# Reverse engineer the thinkpad dosflash utility
#
# Copyright (C) 2016 Hamish Coleman
#
CFLAGS:=-Wall
all: kvm_flat
$(info See README file for additional details)
.PHONY: all
build_dep:
sudo apt-get install libuuid-perl mtools
#
# Radare didnt seem to let me specify the directory to store the project file,
# so this target hacks around that
#
install.radare.projects:
mkdir -p ~/.config/radare2/projects/g2uj23us.dosflash.exe.d
cp -fs $(PWD)/radare/g2uj23us.dosflash.exe ~/.config/radare2/projects
mkdir -p ~/.config/radare2/projects/g2uj23us.dosflash.flat.d
cp -fs $(PWD)/radare/g2uj23us.dosflash.flat ~/.config/radare2/projects
# Download any ISO image that we have a checksum for
# NOTE: makes an assumption about the Lenovo URL not changing
%.iso.orig: %.iso.orig.sha1
wget -O $@ https://download.lenovo.com/pccbbs/mobiles/$(basename $@)
sha1sum -c $<
touch $@
# All the bios update iso images I have checked have had a fat16 filesystem
# embedded in a dos mbr image as the el-torito ISO payload. They also all
# had the same offset to this fat filesystem, so hardcode that offset here.
FAT_OFFSET := 71680
%.dosflash.exe.orig: %.iso.orig
MTOOLS_SKIP_CHECK=1 mcopy -i $^@@$(FAT_OFFSET) ::FLASH/DOSFLASH.EXE $@
%.dosflash.coff.orig: %.dosflash.exe.orig
./dump_exe.pl $< output_extra >$@
%.dosflash.flat.orig: %.dosflash.coff.orig
./dump_coff.pl $< write_flat $@
# TODO - could parse dosflash.config to extract deps
%.dosflash.flat.fake: %.dosflash.flat.orig kvm_flat dosflash.config.fake fake.bios fake.fl2
./kvm_flat $< dosflash.config.fake
# A copy of some low memory, including all the bios ROMS
bios.img:
sudo dd if=/dev/mem of=bios.img bs=65536 skip=12 count=4
MEMMAP_ACPI = $(dir $(shell egrep -l "ACPI Tables" /sys/firmware/memmap/*/type))
MEMMAP_ACPINV = $(dir $(shell egrep -l "ACPI Non-volatile Storage" /sys/firmware/memmap/*/type))
ACPI_START = $(shell cat $(MEMMAP_ACPI)/start)
ACPI_END = $(shell cat $(MEMMAP_ACPI)/end)
ACPI_LEN = $(ACPI_END) - $(ACPI_START) +1
ACPINV_START = $(shell cat $(MEMMAP_ACPINV)/start)
ACPINV_END = $(shell cat $(MEMMAP_ACPINV)/end)
ACPINV_LEN = $(ACPINV_END) - $(ACPINV_START) +1
# A copy of the high-mem ACPI tables
acpi.img: /dev/fmem
sudo bash -c "./dd_hack.pl /dev/fmem acpi.img $$[$(ACPI_START)] $$[$(ACPI_LEN)]"
acpinv.img: /dev/fmem
sudo bash -c "./dd_hack.pl /dev/fmem acpinv.img $$[$(ACPINV_START)] $$[$(ACPINV_LEN)]"
%: %.asm
nasm -f bin -o $@ $<
OBJECTS_kvm_flat := kvm_flat.o
kvm_flat: $(OBJECTS_kvm_flat)