]> git.proxmox.com Git - mirror_edk2.git/blobdiff - 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
diff --git a/EdkCompatibilityPkg/Sample/Tools/Source/Strip/strip.c b/EdkCompatibilityPkg/Sample/Tools/Source/Strip/strip.c
new file mode 100644 (file)
index 0000000..72d7693
--- /dev/null
@@ -0,0 +1,104 @@
+/*++\r
+\r
+Copyright 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  Strip.c\r
+\r
+Abstract:\r
+\r
+  Quick Exe2Bin equivalent.\r
+\r
+--*/\r
+\r
+#include <stdio.h>\r
+#include <memory.h>\r
+#include <string.h>\r
+#include <malloc.h>\r
+\r
+int\r
+main (\r
+  int  argc,\r
+  char *argv[]\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts executable files to binary files.\r
+\r
+Arguments:\r
+\r
+  argc   - Number of command line arguments\r
+  argv[] - Array of pointers to the command line arguments\r
+\r
+Returns:\r
+\r
+  Zero     - Function completed successfully.\r
+  Non-zero - Function exited with errors. \r
+\r
+--*/\r
+{\r
+  FILE  *InFile;\r
+  FILE  *OutFile;\r
+  int   Index;\r
+  int   FileSize;\r
+  char  *Buffer;\r
+  char  *Ptrx;\r
+\r
+  if (argc < 3) {\r
+    printf ("Need more args, such as file name to convert and output name\n");\r
+    return -1;\r
+  }\r
+\r
+  InFile  = fopen (argv[1], "rb");\r
+  OutFile = fopen (argv[2], "wb");\r
+\r
+  if (!InFile) {\r
+    printf ("no file, exit\n");\r
+    return -1;\r
+  }\r
+\r
+  if (OutFile == NULL) {\r
+    printf ("Unable to open output file.\n");\r
+    return -1;\r
+  }\r
+\r
+  fseek (InFile, 0, SEEK_END);\r
+  FileSize = ftell (InFile);\r
+\r
+  if (FileSize < 0x200) {\r
+    printf ("%d is not a legal size, exit\n", FileSize);\r
+    return -1;\r
+  }\r
+\r
+  fseek (InFile, 0, SEEK_SET);\r
+\r
+  Buffer = malloc (FileSize);\r
+  if (Buffer == NULL) {\r
+    printf ("Error: Out of resources.\n");\r
+    return -1;\r
+  }\r
+\r
+  fread (Buffer, 1, FileSize, InFile);\r
+\r
+  Ptrx  = Buffer + 0x200;\r
+\r
+  Index = FileSize - 0x200;\r
+\r
+  fwrite (Ptrx, Index, 1, OutFile);\r
+\r
+  fclose (InFile);\r
+  fclose (OutFile);\r
+  free (Buffer);\r
+\r
+  return 0;\r
+}\r