d25c4bf0 |
1 | /*++\r |
2 | \r |
3 | Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved\r |
4 | This software and associated documentation (if any) is furnished\r |
5 | under a license and may only be used or copied in accordance\r |
6 | with the terms of the license. Except as permitted by such\r |
7 | license, no part of this software or documentation may be\r |
8 | reproduced, stored in a retrieval system, or transmitted in any\r |
9 | form or by any means without the express written consent of\r |
10 | Intel Corporation.\r |
11 | \r |
12 | \r |
13 | Module Name:\r |
14 | \r |
15 | Strip.c\r |
16 | \r |
17 | Abstract:\r |
18 | \r |
19 | Quick Exe2Bin equivalent.\r |
20 | \r |
21 | --*/\r |
22 | \r |
23 | #include <stdio.h>\r |
24 | #include <memory.h>\r |
25 | #include <string.h>\r |
26 | #include <malloc.h>\r |
27 | \r |
28 | int\r |
29 | main (\r |
30 | int argc,\r |
31 | char *argv[]\r |
32 | )\r |
33 | /*++\r |
34 | \r |
35 | Routine Description:\r |
36 | \r |
37 | Converts executable files to binary files.\r |
38 | \r |
39 | Arguments:\r |
40 | \r |
41 | argc - Number of command line arguments\r |
42 | argv[] - Array of pointers to the command line arguments\r |
43 | \r |
44 | Returns:\r |
45 | \r |
46 | Zero - Function completed successfully.\r |
47 | Non-zero - Function exited with errors. \r |
48 | \r |
49 | --*/\r |
50 | {\r |
51 | FILE *InFile;\r |
52 | FILE *OutFile;\r |
53 | int Index;\r |
54 | int FileSize;\r |
55 | char *Buffer;\r |
56 | char *Ptrx;\r |
57 | \r |
58 | if (argc < 3) {\r |
59 | printf ("Need more args, such as file name to convert and output name\n");\r |
60 | return -1;\r |
61 | }\r |
62 | \r |
63 | InFile = fopen (argv[1], "rb");\r |
64 | OutFile = fopen (argv[2], "wb");\r |
65 | \r |
66 | if (!InFile) {\r |
67 | printf ("no file, exit\n");\r |
68 | return -1;\r |
69 | }\r |
70 | \r |
71 | if (OutFile == NULL) {\r |
72 | printf ("Unable to open output file.\n");\r |
73 | return -1;\r |
74 | }\r |
75 | \r |
76 | fseek (InFile, 0, SEEK_END);\r |
77 | FileSize = ftell (InFile);\r |
78 | \r |
79 | if (FileSize < 0x200) {\r |
80 | printf ("%d is not a legal size, exit\n", FileSize);\r |
81 | return -1;\r |
82 | }\r |
83 | \r |
84 | fseek (InFile, 0, SEEK_SET);\r |
85 | \r |
86 | Buffer = malloc (FileSize);\r |
87 | if (Buffer == NULL) {\r |
88 | printf ("Error: Out of resources.\n");\r |
89 | return -1;\r |
90 | }\r |
91 | \r |
92 | fread (Buffer, 1, FileSize, InFile);\r |
93 | \r |
94 | Ptrx = Buffer + 0x200;\r |
95 | \r |
96 | Index = FileSize - 0x200;\r |
97 | \r |
98 | fwrite (Ptrx, Index, 1, OutFile);\r |
99 | \r |
100 | fclose (InFile);\r |
101 | fclose (OutFile);\r |
102 | free (Buffer);\r |
103 | \r |
104 | return 0;\r |
105 | }\r |