-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmap_mod.py
106 lines (81 loc) · 2.63 KB
/
bitmap_mod.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Remove / Replace Bitmaps ChromeOS
# Chromebook ELM / OAK / HANA / ELM
# Howto:
# flashrom -p host -r firmware.rom
# cbfstool firmware.rom extract -n vbgfx.bin -f vbgfx.bin -m arm64
# (extract vbgfx.bin from firmware file)
# this file in same directory
# python3 ./bitmap_mod.py
# cbfstool firmware.rom remove -n vbgfx.bin
# cbfstool firmware.rom add -n vbgfx.bin -f vbgfx.bin -c lzma -t raw
# flashrom -p host -w firmware.rom
# V0.25
# Should work on locale_xx.bin and font.bin as well (not yet tested)
import struct
# Python program to modify the
# content of binary file
# Function to update the
# content of binary file
def update_chromeos_bitmaps(binfile):
# string variable to store
# each word after reading
# from the file
string = b""
word = "BM"
# Flag variable to check
# if the record is found or
# not
Flag = 0
pos = 0
part = 0
string = ""
counter = 0
# Open the file in r + b mode which means
# opening a binary file for reading and
# writing
file = open(binfile, 'rb+')
while 1:
# Reading the content of the
# file character by character
value = file.read(1)
if not value:
break
byte_value = struct.unpack('B', value)[0]
#print(f"Byte: {byte_value}")
data = byte_value
# Looping till the end of
# file is reached
# checking the word read with
# the word entered by user
#print(string)
if string == word:
# Moving the file pointer
# at the end of the previously
# read recor
print("Found..")
file.seek(pos+52)
# Updating the content of the file
for x in range(128*4):
file.write(b"\0")
Flag = 1
pos = file.tell()
counter = counter+1
string = ""
continue
else:
# storing the position of
# current file pointer i.e. at
# the end of previously read record
pos = file.tell()
string += chr(data)
string = string[-2:]
continue
file.close()
if Flag:
print("Record successfully updated")
print(f"Found: {counter}")
else:
print("Record not found")
update_chromeos_bitmaps("vbgfx.bin")
update_chromeos_bitmaps("font.bin")
update_chromeos_bitmaps("locale_en.bin")