/* Function to retrieve the EFI_HANDLE from the human-friendly index. */
EFI_HANDLE EFIAPI ConvertHandleIndexToHandle(IN CONST UINTN TheIndex)
/* Function to retrieve the EFI_HANDLE from the human-friendly index. */
EFI_HANDLE EFIAPI ConvertHandleIndexToHandle(IN CONST UINTN TheIndex)
{
  EFI_STATUS   Status;
  EFI_GUID     **ProtocolBuffer;
  UINTN        ProtocolCount;
  HANDLE_LIST  *ListWalker;
  InternalShellInitHandleList ();
  if (TheIndex >= mHandleList.NextIndex) {
    return NULL;
  }
  for (ListWalker = (HANDLE_LIST *)GetFirstNode (&mHandleList.List.Link)
       ; !IsNull (&mHandleList.List.Link, &ListWalker->Link)
       ; ListWalker = (HANDLE_LIST *)GetNextNode (&mHandleList.List.Link, &ListWalker->Link)
       )
  {
    if ((ListWalker->TheIndex == TheIndex) && (ListWalker->TheHandle != NULL)) {
      Status = gBS->ProtocolsPerHandle (ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);
      if (!EFI_ERROR (Status)) {
        FreePool (ProtocolBuffer);
      } else {
        ListWalker->TheHandle = NULL;
      }
      return (ListWalker->TheHandle);
    }
  }
  return NULL;
}