示例#1
0
/**
  Get section entry heximal UINT64 value.

  @param[in]  Context         INI Config file context.
  @param[in]  SectionName     Section name.
  @param[in]  EntryName       Section entry name.
  @param[out] Data            Point to the got heximal UINT64 value.

  @retval EFI_SUCCESS    Section entry heximal UINT64 value is got.
  @retval EFI_NOT_FOUND  Section is not found.
**/
EFI_STATUS
EFIAPI
GetHexUint64FromDataFile (
  IN      VOID                          *Context,
  IN      CHAR8                         *SectionName,
  IN      CHAR8                         *EntryName,
  OUT     UINT64                        *Data
  )
{
  CHAR8                                 *Value;
  EFI_STATUS                            Status;

  if (Context == NULL || SectionName == NULL || EntryName == NULL || Data == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  Status = GetStringFromDataFile(
             Context,
             SectionName,
             EntryName,
             &Value
             );
  if (EFI_ERROR(Status)) {
    return EFI_NOT_FOUND;
  }
  ASSERT (Value != NULL);
  if (!IsValidHexString(Value, AsciiStrLen(Value))) {
    return EFI_NOT_FOUND;
  }
  *Data = AsciiStrHexToUint64(Value);
  return EFI_SUCCESS;
}
示例#2
0
vlong
_plstr2vlong(char* vbuf, unsigned int bsz) {
	UINT64 rval;
	unsigned int wsize;
	char* wptr;
	int negative;
	char wbuffer[40];

	if (vbuf == NULL || bsz < 1) { return 0; }
	wsize = sizeof(wbuffer) - 1;
	if (bsz < wsize) { wsize = bsz; }
	_plmemcpy(wbuffer, vbuf, wsize);
	wbuffer[wsize] = '\0';
	wptr = ScanMem8(wbuffer, wsize, '-');
	if (wptr != NULL) {
		negative = 1;
		wptr++;
	} else {
		negative = 0;
		wptr = wbuffer;
	}
	wsize -= (unsigned int)(wptr - wbuffer);
	if (ScanMem8(wptr, wsize, 'x') != NULL || ScanMem8(wptr, wsize, 'X') != NULL ) {
		rval = AsciiStrHexToUint64(wptr);
	} else {
		rval = AsciiStrDecimalToUint64(wptr);
	}
	if (negative) {
		return (vlong) (0 - (vlong) rval);
	} else {
		return (vlong) rval;
	}
}
示例#3
0
/**
  Converts a string to GUID value.
  Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

  @param[in]  Str              The registry format GUID string that contains the GUID value.
  @param[out] Guid             A pointer to the converted GUID value.

  @retval EFI_SUCCESS     The GUID string was successfully converted to the GUID value.
  @retval EFI_UNSUPPORTED The input string is not in registry format.
  @return others          Some error occurred when converting part of GUID value.

**/
EFI_STATUS
AsciiStrToGuid (
  IN  CHAR8    *Str,
  OUT EFI_GUID *Guid
  )
{
  //
  // Get the first UINT32 data
  //
  Guid->Data1 = (UINT32) AsciiStrHexToUint64  (Str);
  while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {
    Str ++;
  }

  if (IS_HYPHEN (*Str)) {
    Str++;
  } else {
    return EFI_UNSUPPORTED;
  }

  //
  // Get the second UINT16 data
  //
  Guid->Data2 = (UINT16) AsciiStrHexToUint64  (Str);
  while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {
    Str ++;
  }

  if (IS_HYPHEN (*Str)) {
    Str++;
  } else {
    return EFI_UNSUPPORTED;
  }

  //
  // Get the third UINT16 data
  //
  Guid->Data3 = (UINT16) AsciiStrHexToUint64  (Str);
  while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {
    Str ++;
  }

  if (IS_HYPHEN (*Str)) {
    Str++;
  } else {
    return EFI_UNSUPPORTED;
  }

  //
  // Get the following 8 bytes data
  //
  AsciiStrToBuf (&Guid->Data4[0], 2, Str);
  //
  // Skip 2 byte hex chars
  //
  Str += 2 * 2;

  if (IS_HYPHEN (*Str)) {
    Str++;
  } else {
    return EFI_UNSUPPORTED;
  }
  AsciiStrToBuf (&Guid->Data4[2], 6, Str);

  return EFI_SUCCESS;
}
示例#4
0
//
// Returns parsed hex integer key.
// Plist - kext pist
// Key - key to find
// WholePlist - _PrelinkInfoDictionary, used to find referenced values
//
// Searches for Key in Plist and it's value:
// a) <integer ID="26" size="64">0x2b000</integer>
//    returns 0x2b000
// b) <integer IDREF="26"/>
//    searches for <integer ID="26"... from WholePlist
//    and returns value from that referenced field
//
// Whole function is here since we should avoid ParseXML() and it's
// memory allocations during ExitBootServices(). And it seems that
// ParseXML() does not support IDREF.
// This func is hard to read and debug and probably not reliable,
// but it seems it works.
//
UINT64
GetPlistHexValue (
    CHAR8 *Plist,
    CHAR8 *Key,
    CHAR8 *WholePlist
)
{
    CHAR8     *Value;
    CHAR8     *IntTag;
    UINT64    NumValue;
    CHAR8     *IDStart;
    CHAR8     *IDEnd;
    UINTN     IDLen;
    CHAR8     Buffer[48];

    NumValue = 0;

    // search for Key
    Value = AsciiStrStr (Plist, Key);
    if (Value == NULL) {
        return 0;
    }
    // search for <integer
    IntTag = AsciiStrStr (Value, "<integer");
    if (IntTag == NULL) {
        return 0;
    }
    // find <integer end
    Value = AsciiStrStr (IntTag, ">");
    if (Value == NULL) {
        return 0;
    }
    // normal case: value is here
    if (Value[-1] != '/') {
        NumValue = AsciiStrHexToUint64 (Value + 1);
        return NumValue;
    }
    // it might be a reference: IDREF="173"/>
    Value = AsciiStrStr (IntTag, "<integer IDREF=\"");
    if (Value != IntTag) {
        return 0;
    }
    // compose <integer ID="xxx" in the Buffer
    IDStart = AsciiStrStr (IntTag, "\"") + 1;
    IDEnd = AsciiStrStr (IDStart, "\"");
    IDLen = IDEnd - IDStart;
    if (IDLen > 8) {
        return 0;
    }
    AsciiStrCpy (Buffer, "<integer ID=\"");
    AsciiStrnCat (Buffer, IDStart, IDLen);
    AsciiStrCat (Buffer, "\"");
    // and search whole plist for ID
    IntTag = AsciiStrStr (WholePlist, Buffer);
    if (IntTag == NULL) {
        return 0;
    }
    // got it. find closing >
    Value = AsciiStrStr (IntTag, ">");
    if (Value == NULL) {
        return 0;
    }
    if (Value[-1] == '/') {
        return 0;
    }
    // we should have value now
    NumValue = AsciiStrHexToUint64 (Value + 1);

    return NumValue;
}