aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <JBottomley@Parallels.com>2012-12-07 20:20:02 +0000
committerJames Bottomley <JBottomley@Parallels.com>2012-12-07 20:20:02 +0000
commit98b4d0bfb9511259b1a88a0ffd122695087f9230 (patch)
treea4e8229d4e1496dbc6f4e7864186223c6f3f5a22
parent76a79df951f2beb49aeec371f144f2cce9c07a1f (diff)
downloadefitools-98b4d0bfb9511259b1a88a0ffd122695087f9230.tar.gz
Fix the file selectors to work properly in a relative directory
-rw-r--r--HashTool.c4
-rw-r--r--PreLoader.c6
-rw-r--r--lib/execute.c89
-rw-r--r--lib/simple_file.c23
4 files changed, 45 insertions, 77 deletions
diff --git a/HashTool.c b/HashTool.c
index ede3a35..ebf028a 100644
--- a/HashTool.c
+++ b/HashTool.c
@@ -17,7 +17,7 @@
#include <guid.h>
#include <execute.h>
-static CHAR16* keytoolbin = L"\\KeyTool.efi";
+static CHAR16* keytoolbin = L"KeyTool.efi";
static int transition_to_setup = 0, reboot_to_uefi_menu = 0;
static EFI_HANDLE im;
@@ -70,7 +70,7 @@ enrol_hash(void)
L"This means it will Subsequently Boot with no prompting",
L"Remember to make sure it is a genuine binary before Enroling its hash",
NULL
- }, L".", NULL, &file_name);
+ }, L"\\", NULL, &file_name);
if (!file_name)
/* user pressed ESC */
diff --git a/PreLoader.c b/PreLoader.c
index e5a1d8e..856676c 100644
--- a/PreLoader.c
+++ b/PreLoader.c
@@ -15,8 +15,8 @@
#include "hashlist.h"
-CHAR16 *loader = L"\\loader.efi";
-CHAR16 *hashtool = L"\\HashTool.efi";
+CHAR16 *loader = L"loader.efi";
+CHAR16 *hashtool = L"HashTool.efi";
EFI_STATUS
efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
@@ -53,7 +53,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
console_alertbox((CHAR16 *[]) {
L"Failed to start loader",
L"",
- L"It is probably in \\boot\\efi\\loader.efi",
+ L"It should be called loader.efi (in the current directory)",
L"Please enrol its hash and try again",
L"",
L"I will now execute HashTool for you to do this",
diff --git a/lib/execute.c b/lib/execute.c
index 99f5fef..27b3d50 100644
--- a/lib/execute.c
+++ b/lib/execute.c
@@ -48,38 +48,27 @@ EFI_STATUS
generate_path(CHAR16* name, EFI_LOADED_IMAGE *li, EFI_DEVICE_PATH **path, CHAR16 **PathName)
{
EFI_DEVICE_PATH *devpath;
- EFI_HANDLE device;
- FILEPATH_DEVICE_PATH *FilePath;
- int len;
- unsigned int pathlen = 0;
+ unsigned int pathlen;
EFI_STATUS efi_status = EFI_SUCCESS;
+ CHAR16 *devpathstr = DevicePathToStr(li->FilePath),
+ *found = NULL;
+ int i;
- device = li->DeviceHandle;
devpath = li->FilePath;
- while (!IsDevicePathEnd(devpath) &&
- !IsDevicePathEnd(NextDevicePathNode(devpath))) {
- FilePath = (FILEPATH_DEVICE_PATH *)devpath;
- len = StrLen(FilePath->PathName);
-
- pathlen += len;
-
- if (len == 1 && FilePath->PathName[0] == '\\') {
- devpath = NextDevicePathNode(devpath);
- continue;
- }
-
- /* If no leading \, need to add one */
- if (FilePath->PathName[0] != '\\')
- pathlen++;
-
- /* If trailing \, need to strip it */
- if (FilePath->PathName[len-1] == '\\')
- pathlen--;
-
- devpath = NextDevicePathNode(devpath);
+ for (i = 0; i < StrLen(devpathstr); i++)
+ if (devpathstr[i] == '\\')
+ found = &devpathstr[i];
+ if (!found) {
+ pathlen = 0;
+ } else {
+ *found = '\0';
+ pathlen = StrLen(devpathstr);
}
+ if (name[0] != '\\')
+ pathlen++;
+
*PathName = AllocatePool((pathlen + 1 + StrLen(name))*sizeof(CHAR16));
if (!*PathName) {
@@ -88,49 +77,18 @@ generate_path(CHAR16* name, EFI_LOADED_IMAGE *li, EFI_DEVICE_PATH **path, CHAR16
goto error;
}
- *PathName[0] = '\0';
- devpath = li->FilePath;
-
- while (!IsDevicePathEnd(devpath) &&
- !IsDevicePathEnd(NextDevicePathNode(devpath))) {
- CHAR16 *tmpbuffer;
- FilePath = (FILEPATH_DEVICE_PATH *)devpath;
- len = StrLen(FilePath->PathName);
-
- if (len == 1 && FilePath->PathName[0] == '\\') {
- devpath = NextDevicePathNode(devpath);
- continue;
- }
-
- tmpbuffer = AllocatePool((len + 1)*sizeof(CHAR16));
-
- if (!tmpbuffer) {
- Print(L"Unable to allocate temporary buffer\n");
- return EFI_OUT_OF_RESOURCES;
- }
-
- StrCpy(tmpbuffer, FilePath->PathName);
-
- /* If no leading \, need to add one */
- if (tmpbuffer[0] != '\\')
- StrCat(*PathName, L"\\");
-
- /* If trailing \, need to strip it */
- if (tmpbuffer[len-1] == '\\')
- tmpbuffer[len-1] = '\0';
-
- StrCat(*PathName, tmpbuffer);
- FreePool(tmpbuffer);
- devpath = NextDevicePathNode(devpath);
- }
+ StrCpy(*PathName, devpathstr);
+ if ((*PathName)[StrLen(*PathName) - 1] == '/')
+ (*PathName)[StrLen(*PathName) - 1] = '\0';
if (name[0] != '\\')
StrCat(*PathName, L"\\");
StrCat(*PathName, name);
-
- *path = FileDevicePath(device, *PathName);
+
+ *path = FileDevicePath(li->DeviceHandle, *PathName);
error:
+ FreePool(devpathstr);
return efi_status;
}
@@ -156,10 +114,13 @@ execute(EFI_HANDLE image, CHAR16 *name)
status = uefi_call_wrapper(BS->LoadImage, 6, FALSE, image,
devpath, NULL, 0, &h);
if (status != EFI_SUCCESS)
- return status;
+ goto out;
status = uefi_call_wrapper(BS->StartImage, 3, h, NULL, NULL);
uefi_call_wrapper(BS->UnloadImage, 1, h);
+ out:
+ FreePool(PathName);
+ FreePool(devpath);
return status;
}
diff --git a/lib/simple_file.c b/lib/simple_file.c
index 9fa927f..53530e6 100644
--- a/lib/simple_file.c
+++ b/lib/simple_file.c
@@ -65,16 +65,15 @@ simple_file_open(EFI_HANDLE image, CHAR16 *name, EFI_FILE **file, UINT64 mode)
if (efi_status != EFI_SUCCESS) {
Print(L"Unable to generate load path for %s\n", name);
- goto error;
+ return efi_status;
}
device = li->DeviceHandle;
- return simple_file_open_by_handle(device, PathName, file, mode);
+ efi_status = simple_file_open_by_handle(device, PathName, file, mode);
- error:
- //if (PathName)
- // FreePool(PathName);
+ FreePool(PathName);
+ FreePool(loadpath);
return efi_status;
}
@@ -449,7 +448,8 @@ simple_file_selector(EFI_HANDLE *im, CHAR16 **title, CHAR16 *name,
} else if (StrCmp(selected, L"../") == 0) {
int i;
- FreePool(dmp);
+ i = StrLen(name) - 1;
+
for (i = StrLen(name); i > 0; --i) {
if (name[i] == '\\')
@@ -457,8 +457,13 @@ simple_file_selector(EFI_HANDLE *im, CHAR16 **title, CHAR16 *name,
}
if (i == 0)
i = 1;
- name[i] = '\0';
- goto redo;
+
+ if (StrCmp(name, L"\\") != 0
+ && StrCmp(&name[i], L"..") != 0) {
+ name[i] = '\0';
+ FreePool(dmp);
+ goto redo;
+ }
}
newname = AllocatePool((StrLen(name) + len + 2)*sizeof(CHAR16));
if (!newname)
@@ -470,9 +475,11 @@ simple_file_selector(EFI_HANDLE *im, CHAR16 **title, CHAR16 *name,
StrCat(newname, selected);
/* remove trailing / */
newname[StrLen(newname) - 1] = '\0';
+
FreePool(dmp);
FreePool(name);
name = newname;
+
goto redo;
}
*result = AllocatePool((StrLen(name) + len + 2)*sizeof(CHAR16));