-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHDRTool.c
More file actions
80 lines (71 loc) · 2.78 KB
/
HDRTool.c
File metadata and controls
80 lines (71 loc) · 2.78 KB
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
/** @file
* Create a header or remove a header of a
* kernel for android boot v1.
*
* Copyright (c) 2021-2025 The DuoWoa authors. All rights reserved.
* MIT License
*
*/
#include "utils.h"
int main(
int argc,
char *argv[]
) {
// Print hello world message
printf("Project Aloha Kernel Image HDR Patcher v1.2.0.0\n");
printf("Copyright (c) 2021-2025 The DuoWoA authors\n\n");
// Check parameters and print help message
if (argc != 3) {
printf("Usage: <Input Kernel> <Output Kernel>\n");
return -EINVAL;
}
// Check if file exist
// Init Input file content
FileContent kernelInput = {.filePath = argv[1]};
if (!get_file_size(&kernelInput)) {
printf("Error: Input kernel file not found or invalid.\n");
return -EINVAL;
}
kernelInput.fileBuffer = malloc(kernelInput.fileSize + 0x14);
read_file_content(&kernelInput);
// add a 0x14 offset of the buffer
memmove(kernelInput.fileBuffer + 0x14, kernelInput.fileBuffer, kernelInput.fileSize);
// Init Output file content
FileContent kernelOutput = {.filePath = argv[2]};
kernelOutput.fileSize = kernelInput.fileSize;
kernelOutput.fileBuffer = kernelInput.fileBuffer + 0x14;
// OK now check if kernel has a header
// if it is, then remove it
// if it is not, then create a header
// Header format:
// 0x00-0x0F: "UNCOMPRESSED_IMG" (16 bytes)
// 0x10-0x17: Kernel size (8 bytes, little-endian)
if (strncmp((char *) kernelInput.fileBuffer, "UNCOMPRESSED_IMG", 0x10) == 0) {
// Kernel has a header, remove it
printf("Kernel has UNCOMPRESSED_IMG header, removing...\n");
kernelOutput.fileBuffer += 0x14; // Move past the header
kernelOutput.fileSize -= 0x14; // Reduce size by header size
} else {
// Kernel does not have a header, create one
printf("Kernel does not have UNCOMPRESSED_IMG header, creating...\n");
// Reallocate buffer to add header
kernelOutput.fileBuffer -= 0x14;
// Set header value
memcpy(kernelOutput.fileBuffer, "UNCOMPRESSED_IMG", 0x10);
kernelOutput.fileBuffer[0x10] = kernelOutput.fileSize >> 0 & 0xFF;
kernelOutput.fileBuffer[0x11] = kernelOutput.fileSize >> 8 & 0xFF;
kernelOutput.fileBuffer[0x12] = kernelOutput.fileSize >> 16 & 0xFF;
kernelOutput.fileBuffer[0x13] = kernelOutput.fileSize >> 24 & 0xFF;
kernelOutput.fileSize += 0x14;
}
// Save the output kernel
if (write_file_content(&kernelOutput)) {
printf("Error: Failed to write output kernel file.\n");
free(kernelInput.fileBuffer);
return -EINVAL;
}
// Free allocated memory
free(kernelInput.fileBuffer);
// Print success message
printf("Kernel image processed successfully.\n");
}