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