192 char* OutputFileName = NULL;
201 printf (
"Usage: EfiLdrImage -o OutImage LoaderImage PeImage1 PeImage2 ... PeImageN\n");
208 if ((strcmp (argv[0],
"-h") == 0) || (strcmp (argv[0],
"--help") == 0)) {
213 if (strcmp (argv[0],
"--version") == 0) {
220 if ((strcmp (argv[0],
"-o") == 0) || (strcmp (argv[0],
"--output") == 0)) {
221 OutputFileName = argv[1];
222 if (OutputFileName == NULL) {
223 Error (NULL, 0, 1003,
"Invalid option value",
"Output file can't be null");
231 if ((strcmp (argv[0],
"-q") == 0) || (strcmp (argv[0],
"--quiet") == 0)) {
237 if ((strlen(argv[0]) >= 2 && argv[0][0] ==
'-' && (argv[0][1] ==
'v' || argv[0][1] ==
'V')) || (strcmp (argv[0],
"--verbose") == 0)) {
239 if (strlen(argv[0]) > 2) {
242 Error (NULL, 0, 1003,
"Invalid option value",
"%s", argv[0]);
252 if ((strcmp (argv[0],
"-d") == 0) || (strcmp (argv[0],
"--debug") == 0)) {
253 DebugLevel = strtoull (argv[1], NULL, 0);
261 InputFileNames[InputFileCount] = argv[0];
267 if (InputFileCount == 0) {
268 Error (NULL, 0, 1001,
"Missing option",
"No input file");
274 if (OutputFileName == NULL) {
275 Error (NULL, 0, 1001,
"Missing option",
"No output file");
279 fpOut = fopen (OutputFileName,
"w+b");
281 Error (NULL, 0, 0001,
"Could not open output file", OutputFileName);
285 memset (&EfiLdrHeader, 0,
sizeof (EfiLdrHeader));
294 fseek (fpOut, EfiLdrHeader.
FileLength, SEEK_SET);
299 for(i=0;i<InputFileCount;i++) {
303 fpIn = fopen (InputFileNames[i],
"rb");
305 Error (NULL, 0, 0001,
"Could not open input file", InputFileNames[i]);
317 InputName = strrchr(InputFileNames[i],
'/');
318 if (InputName == NULL) {
319 InputName = strrchr(InputFileNames[i],
'\\');
320 if (InputName == NULL) {
321 InputName = InputFileNames[i];
328 strncpy ((
char*) EfiLdrImage[i].FileName, InputName,
sizeof (EfiLdrImage[i].FileName) - 1);
336 fseek (fpOut, 0, SEEK_SET);
338 fwrite (&EfiLdrImage ,
sizeof(
EFILDR_IMAGE)*(InputFileCount), 1, fpOut);
341 printf (
"Created %s\n", OutputFileName);
void Error(char *FileName, uint32_t LineNumber, uint32_t ErrorCode, char *OffendingText, char *MsgFmt,...)