Skip to content

Commit da09c96

Browse files
committedJul 17, 2024
patcher: optimize error handle.
1 parent c2af951 commit da09c96

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
 

‎patcher.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ int main(int argc, char *argv[]) {
7474
read_file_content(&shellCode);
7575

7676
// Patch Kernel.
77-
PatchKernel(&originImage, &uefiImage, &shellCode, &outputImage, &stack);
77+
void *buf = PatchKernel(&originImage, &uefiImage, &shellCode, &outputImage, &stack);
7878

7979
// Output buffer to new kernel.
80-
if (outputImage.fileBuffer != NULL) {
80+
if (outputImage.fileBuffer != NULL && buf != NULL) {
8181
write_file_content(&outputImage);
8282
} else {
8383
printf("Error Patching Kernel.\n");
@@ -229,7 +229,8 @@ uint8_t *PatchKernel(pFileContent kernel, pFileContent uefi, pFileContent shellC
229229
} else // Unknown stuff
230230
if (patchedKernel->fileBuffer[7] != 0x14) {
231231
// There is no branch instruction!
232-
printf("Error: Invalid Kernel Image. Branch instruction not found within first two instruction slots.\n");
232+
printf("Error: Invalid Kernel Image. Branch instruction not found within first two instruction slots.\n"
233+
"Please Check the kernel you provided.\n");
233234
return NULL;
234235
}
235236

0 commit comments

Comments
 (0)