summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorMike Fulbright <msf@redhat.com>2002-02-13 17:48:15 +0000
committerMike Fulbright <msf@redhat.com>2002-02-13 17:48:15 +0000
commitf59492ecbce4f65732dcb65da0dc072eba2bf8ed (patch)
treec0ec339d06fb352937b4620a75273a94885c21aa /utils
parent9944365527dd9bc90fe641a2c4aae3bb85a82061 (diff)
downloadanaconda-f59492ecbce4f65732dcb65da0dc072eba2bf8ed.tar.gz
anaconda-f59492ecbce4f65732dcb65da0dc072eba2bf8ed.tar.xz
anaconda-f59492ecbce4f65732dcb65da0dc072eba2bf8ed.zip
code to check efi version
Diffstat (limited to 'utils')
-rw-r--r--utils/fpswa/Makefile11
-rw-r--r--utils/fpswa/fpswa_version.c228
-rw-r--r--utils/fpswa/readme10
3 files changed, 249 insertions, 0 deletions
diff --git a/utils/fpswa/Makefile b/utils/fpswa/Makefile
new file mode 100644
index 000000000..ada7fd75b
--- /dev/null
+++ b/utils/fpswa/Makefile
@@ -0,0 +1,11 @@
+INC = /usr/include
+LIB_DIR = /usr/lib
+LIBS = $(LIB_DIR)/libbfd.a $(LIB_DIR)/libiberty.a
+
+all: fpswa_version
+
+fpswa_version:fpswa_version.c $(LIBS)
+ gcc -g -I$(INC) -o fpswa_version fpswa_version.c $(LIBS)
+
+clean:
+ rm -f fpswa_version
diff --git a/utils/fpswa/fpswa_version.c b/utils/fpswa/fpswa_version.c
new file mode 100644
index 000000000..6a41451dd
--- /dev/null
+++ b/utils/fpswa/fpswa_version.c
@@ -0,0 +1,228 @@
+/*
+ FPSWA Version
+ Parse the FPSWA.efi executable to find the version information.
+ The output may be used to compare multiple executables to determine
+ the newest version.
+
+ Copyright 2002 Intel Corporation
+ Copyright 2002 Jenna Hall <jenna.s.hall@intel.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stddef.h>
+#include <bfd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <malloc.h>
+
+#define SEARCH_STRING "FileVersion"
+#define FILENAME_DESCRIPTOR "InternalName"
+#define FILENAME "fpswa.efi"
+#define MAX_VERSION_LENGTH 8
+
+/* Static declarations */
+
+static off_t rsrc_offset = 0; /* rc info offset - found in header */
+static size_t rsrc_size = 0; /* rc info size - found in header */
+static int exit_status = 0;
+static char *default_target = NULL; /* default at runtime */
+
+static void
+parse_section_header (bfd *, asection *, PTR);
+
+static void
+parse_bfd (bfd *);
+
+static void
+parse_file (char *, char *);
+
+static void
+extract_offset (char **);
+
+static void
+parse_unicode(ssize_t, unsigned short *);
+
+static void
+locate_file_version (char **);
+
+
+/* Definitions */
+
+static void
+parse_section_header (bfd *abfd, asection *section, PTR ignored ATTRIBUTE_UNUSED)
+{
+ unsigned int opb = bfd_octets_per_byte(abfd);
+
+ if (!strcmp(bfd_get_section_name(abfd, section), ".rsrc")) {
+ rsrc_offset = section->filepos;
+ rsrc_size = (bfd_section_size(abfd, section) / opb);
+ }
+}
+
+static void
+parse_bfd (bfd *abfd)
+{
+ char **matching;
+
+ if (bfd_check_format_matches (abfd, bfd_object, &matching)) {
+ bfd_map_over_sections (abfd, parse_section_header, (PTR) NULL);
+ return;
+ }
+ else {
+ fprintf(stderr, "Error: not an object file!\n");
+ return;
+ }
+}
+
+static void
+parse_file (char *filename, char *target)
+{
+ bfd *file;
+
+ file = bfd_openr (filename, target);
+ if (file == NULL) {
+ fprintf(stderr, "BFD library error!\n");
+ exit_status = 1;
+ return;
+ }
+
+ parse_bfd (file);
+
+ bfd_close (file);
+}
+
+/*
+ * Parse the executable to find the .rsrc header offset
+ */
+static void
+extract_offset (char **argv)
+{
+ char *target = default_target;
+
+ bfd_init ();
+
+ parse_file (argv[1], target);
+}
+
+/*
+ * Parse the unicode-encoded rc section of the FPSWA file to find the
+ * version string
+ */
+static void
+parse_unicode(ssize_t rc_section_size, unsigned short *buf)
+{
+ unsigned int i= 0;
+ char version_string[MAX_VERSION_LENGTH];
+ char *temp_ptr;
+ unsigned short *buffer_ptr = buf;
+
+ temp_ptr = SEARCH_STRING;
+
+ /* locate the version search string within the Unicode buffer */
+ while (buffer_ptr && (temp_ptr[0] != '\0')) {
+ if (*buffer_ptr == temp_ptr[0]) {
+ temp_ptr++;
+ }
+ else // reset
+ temp_ptr = SEARCH_STRING;
+ buffer_ptr++;
+ }
+
+ /* parse past the Unicode NULL characters */
+ while (*buffer_ptr == 0) {
+ buffer_ptr++;
+ }
+
+ /* capture the version number string */
+ while (*buffer_ptr != '\0') {
+ version_string[i] = *buffer_ptr;
+ buffer_ptr++; i++;
+ }
+ /* NULL terminate the string */
+ version_string[i] = '\0';
+
+ /* output version string to user */
+ printf("%s\n", version_string);
+
+}
+
+/*
+ * Locate the rc info at that offset in the executable,
+ * then parse that section to locate the FileVersion string
+ */
+static void
+locate_file_version (char **argv)
+{
+ int fd;
+ ssize_t bytes_read = 0;
+ unsigned short *buf = malloc(rsrc_size);
+
+ if (buf == NULL) {
+ fprintf(stderr, "Malloc failed! Exiting...\n");
+ free(buf);
+ exit(1);
+ }
+
+ if ((fd = open(argv[1], O_RDONLY)) < 0) {
+ fprintf(stderr, "Open failed: %s\n", sys_errlist[errno]);
+ free(buf);
+ exit(1);
+ }
+
+ /* first search to the beginning of the rc info section */
+ if (lseek(fd, rsrc_offset, SEEK_SET) < 0) {
+ /* seek error; exit */
+ fprintf(stderr, "Seek failed: %s\n", sys_errlist[errno]);
+ close(fd);
+ free(buf);
+ exit(1);
+ }
+
+ /* next load the rc info section into the buffer for parsing */
+ if ((bytes_read = read(fd, buf, rsrc_size)) < 0) {
+ /* read error; exit */
+ fprintf(stderr, "Read failed: %s\n", sys_errlist[errno]);
+ close(fd);
+ free(buf);
+ exit(1);
+ }
+
+ /* now parse the rc info section for the FileVersion string */
+ parse_unicode(bytes_read, buf);
+
+ free(buf);
+ close(fd);
+}
+
+int
+main (int argc, char **argv)
+{
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s FPSWA.efi\n", argv[0]);
+ exit(1);
+ }
+
+ /* parse the executable to find the .rsrc header offset */
+ extract_offset(argv);
+
+ /* locate the rc info at that offset in the executable,
+ then parse that section to locate the FileVersion string */
+ locate_file_version(argv);
+
+ return exit_status;
+}
diff --git a/utils/fpswa/readme b/utils/fpswa/readme
new file mode 100644
index 000000000..628b6220a
--- /dev/null
+++ b/utils/fpswa/readme
@@ -0,0 +1,10 @@
+*******************************
+FPSWA.efi version check utility
+*******************************
+
+Usage: fpswa_version FPSWA.efi
+
+
+This utility will extract the version number from an FPSWA.efi binary file.
+The output may then be compared with the output from other FPSWA.efi binaries
+to determine which is the newest on the system, for OS installation purposes.