]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Sample/Tools/Source/Strip/strip.c
1) Sync EdkCompatibilityPkg with EDK 1.04. The changes includes:
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / Strip / strip.c
CommitLineData
95d675b5 1/*++\r
2\r
3Copyright 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 Strip.c\r
15\r
16Abstract:\r
17\r
18 Quick Exe2Bin equivalent.\r
19\r
20--*/\r
21\r
22#include <stdio.h>\r
23#include <memory.h>\r
24#include <string.h>\r
25#include <malloc.h>\r
26\r
27int\r
28main (\r
29 int argc,\r
30 char *argv[]\r
31 )\r
32/*++\r
33\r
34Routine Description:\r
35\r
36 Converts executable files to binary files.\r
37\r
38Arguments:\r
39\r
40 argc - Number of command line arguments\r
41 argv[] - Array of pointers to the command line arguments\r
42\r
43Returns:\r
44\r
45 Zero - Function completed successfully.\r
46 Non-zero - Function exited with errors. \r
47\r
48--*/\r
49{\r
50 FILE *InFile;\r
51 FILE *OutFile;\r
52 int Index;\r
53 int FileSize;\r
54 char *Buffer;\r
55 char *Ptrx;\r
56\r
57 if (argc < 3) {\r
58 printf ("Need more args, such as file name to convert and output name\n");\r
59 return -1;\r
60 }\r
61\r
62 InFile = fopen (argv[1], "rb");\r
63 OutFile = fopen (argv[2], "wb");\r
64\r
65 if (!InFile) {\r
66 printf ("no file, exit\n");\r
67 return -1;\r
68 }\r
69\r
70 if (OutFile == NULL) {\r
71 printf ("Unable to open output file.\n");\r
72 return -1;\r
73 }\r
74\r
75 fseek (InFile, 0, SEEK_END);\r
76 FileSize = ftell (InFile);\r
77\r
78 if (FileSize < 0x200) {\r
79 printf ("%d is not a legal size, exit\n", FileSize);\r
80 return -1;\r
81 }\r
82\r
83 fseek (InFile, 0, SEEK_SET);\r
84\r
85 Buffer = malloc (FileSize);\r
86 if (Buffer == NULL) {\r
87 printf ("Error: Out of resources.\n");\r
88 return -1;\r
89 }\r
90\r
91 fread (Buffer, 1, FileSize, InFile);\r
92\r
93 Ptrx = Buffer + 0x200;\r
94\r
95 Index = FileSize - 0x200;\r
96\r
97 fwrite (Ptrx, Index, 1, OutFile);\r
98\r
99 fclose (InFile);\r
100 fclose (OutFile);\r
101 free (Buffer);\r
102\r
103 return 0;\r
104}\r