2020-07-09 21:06:48 +02:00
|
|
|
/** @file
|
|
|
|
Copyright (C) 2019, vit9696. All rights reserved.
|
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Uefi.h>
|
|
|
|
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/OcMiscLib.h>
|
|
|
|
#include <Library/UefiLib.h>
|
|
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
|
|
#include <Protocol/LoadedImage.h>
|
|
|
|
#include <Protocol/ShellParameters.h>
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
GetArguments (
|
|
|
|
OUT UINTN *Argc,
|
|
|
|
OUT CHAR16 ***Argv
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters;
|
|
|
|
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
|
|
|
|
|
|
|
|
Status = gBS->HandleProtocol (
|
|
|
|
gImageHandle,
|
|
|
|
&gEfiShellParametersProtocolGuid,
|
|
|
|
(VOID**) &ShellParameters
|
|
|
|
);
|
2020-07-15 19:29:27 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2020-07-09 21:06:48 +02:00
|
|
|
*Argc = ShellParameters->Argc;
|
|
|
|
*Argv = ShellParameters->Argv;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->HandleProtocol (
|
|
|
|
gImageHandle,
|
|
|
|
&gEfiLoadedImageProtocolGuid,
|
|
|
|
(VOID**) &LoadedImage
|
|
|
|
);
|
2020-07-15 19:29:27 +02:00
|
|
|
if (EFI_ERROR(Status) || LoadedImage->LoadOptions == NULL) {
|
2020-07-09 21:06:48 +02:00
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC CHAR16 *StArgv[2] = {L"Self", NULL};
|
|
|
|
StArgv[1] = LoadedImage->LoadOptions;
|
|
|
|
*Argc = ARRAY_SIZE (StArgv);
|
|
|
|
*Argv = StArgv;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
OcUninstallAllProtocolInstances (
|
|
|
|
EFI_GUID *Protocol
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE *Handles;
|
|
|
|
UINTN Index;
|
|
|
|
UINTN NoHandles;
|
|
|
|
VOID *OriginalProto;
|
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
|
|
|
Protocol,
|
|
|
|
NULL,
|
|
|
|
&NoHandles,
|
|
|
|
&Handles
|
|
|
|
);
|
|
|
|
|
|
|
|
if (Status == EFI_NOT_FOUND) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-07-15 19:29:27 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2020-07-09 21:06:48 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Index = 0; Index < NoHandles; ++Index) {
|
|
|
|
Status = gBS->HandleProtocol (
|
|
|
|
Handles[Index],
|
|
|
|
Protocol,
|
|
|
|
&OriginalProto
|
|
|
|
);
|
|
|
|
|
2020-07-15 19:29:27 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2020-07-09 21:06:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->UninstallProtocolInterface (
|
|
|
|
Handles[Index],
|
|
|
|
Protocol,
|
|
|
|
OriginalProto
|
|
|
|
);
|
|
|
|
|
2020-07-15 19:29:27 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2020-07-09 21:06:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gBS->FreePool (Handles);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
OcHandleProtocolFallback (
|
|
|
|
IN EFI_HANDLE Handle,
|
|
|
|
IN EFI_GUID *Protocol,
|
|
|
|
OUT VOID **Interface
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = gBS->HandleProtocol (
|
|
|
|
Handle,
|
|
|
|
Protocol,
|
|
|
|
Interface
|
|
|
|
);
|
2020-07-15 19:29:27 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2020-07-09 21:06:48 +02:00
|
|
|
Status = gBS->LocateProtocol (
|
|
|
|
Protocol,
|
|
|
|
NULL,
|
|
|
|
Interface
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|