-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg2sdat.py
103 lines (76 loc) · 2.79 KB
/
img2sdat.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@ File Name : img2sdat.py
@ Author : Abdalrohman Alnasier
@ Created Time : 2022/11/10 19:09:36
OEM_ROM_Editor
Copyright (C) 2022 Abdalrohman Alnasier
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import argparse
import os
import tempfile
import time
# Import necessary modules
import common, images, sparse_img
def img2sdat(input_image, prefix, cache_size, out_dir, version):
"""
Convert image to new.dat format.
Args:
input_image (str): Path to the input system image.
prefix (str): Name of the image.
cache_size (int): Cache size.
out_dir (str): Output directory.
version (int): Transfer list version number.
Returns:
None
"""
start_time = time.time()
# Create output directory if it doesn't exist
os.makedirs(out_dir, exist_ok=True)
# Construct output path
path = os.path.join(out_dir, prefix)
# Create SparseImage object
image = sparse_img.SparseImage(input_image, tempfile.mkstemp()[1], "0")
# Set cache size
common.OPTIONS.cache_size = cache_size
# Create EmptyImage object
src = images.EmptyImage()
# Compute block image diff
block_image_diff = common.BiD(image, src, version)
block_image_diff.Compute(path)
end_time = time.time()
execution_time = end_time - start_time
print(f"Execution time: {execution_time} seconds")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
# Define command-line arguments
parser.add_argument("image", help="input system image")
parser.add_argument("-c", "--cachesize", type=int, default=402653184, help="cache size")
parser.add_argument(
"-o",
"--outdir",
default=".",
help="output directory (current directory by default)",
)
parser.add_argument(
"-v",
"--version",
default=4,
type=int,
help="transfer list version number (3,4 default=4)",
)
parser.add_argument("-p", "--prefix", default="system", help="name of image (prefix.new.dat)")
args = parser.parse_args()
# Call main function with command-line arguments
img2sdat(args.image, args.prefix, args.cachesize, args.outdir, args.version)