This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmain.c
96 lines (77 loc) · 2.29 KB
/
main.c
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
/* PMPatch
Copyright (c) 2012, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include <stdio.h>
#include <stdlib.h>
#include "patch.h"
int main(int argc, char* argv[])
{
FILE* file;
char* inputfile;
char* outputfile;
UINT8* buffer;
size_t filesize;
size_t read;
printf("PMPatch 0.5.14\n");
if(argc < 3)
{
printf("This program patches UEFI BIOS files\nto be compatible with Mac OS X SpeedStep implementation\n\n"
"Usage: PMPatch INFILE OUTFILE\n\n");
return ERR_INVALID_PARAMETER;
}
inputfile = argv[1];
outputfile = argv[2];
// Opening input file
file = fopen(inputfile, "rb");
if (!file)
{
perror("Can't open input file.\n");
return ERR_FILE_OPEN;
}
// Determining file size
fseek(file, 0, SEEK_END);
filesize = ftell(file);
fseek(file, 0, SEEK_SET);
// Allocating memory for buffer
buffer = (UINT8*)malloc(filesize);
if (!buffer)
{
fprintf(stderr, "Can't allocate memory for buffer.\n");
return ERR_OUT_OF_MEMORY;
}
// Reading whole file to buffer
read = fread((void*)buffer, sizeof(char), filesize, file);
if (read != filesize)
{
perror("Can't read input file.\n");
return ERR_FILE_READ;
}
// Closing input file
fclose(file);
// Patching BIOS
if(!patch_bios(buffer, (UINT32)filesize))
return ERR_NOT_PATCHED;
// Creating output file
file = fopen(outputfile, "wb");
if (!file)
{
perror("Can't create output file.\n");
return ERR_FILE_OPEN;
}
// Writing modified BIOS file
if(fwrite(buffer, sizeof(char), filesize, file) != filesize)
{
perror("Can't write output file.\n");
return ERR_FILE_WRITE;
}
// Closing output file
fclose(file);
printf("Output file generated.\n");
return ERR_SUCCESS;
}