MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / hex2bin

Function hex2bin

rEFIt_UEFI/Platform/Utils.cpp:62–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60//out value is a number of byte. out = len
61
62UINT32 hex2bin(IN const CHAR8 *hex, OUT UINT8 *bin, UINT32 len) //assume len = number of UINT8 values
63{
64 CHAR8 *p;
65 UINT32 i, outlen = 0;
66 CHAR8 buf[3];
67
68 if (hex == NULL || bin == NULL || len <= 0 || AsciiStrLen(hex) < len * 2) {
69 // DBG("[ERROR] bin2hex input error\n"); //this is not error, this is empty value
70 return FALSE;
71 }
72
73 buf[2] = '\0';
74 p = (CHAR8 *) hex;
75
76 for (i = 0; i < len; i++)
77 {
78 while ((*p == 0x20) || (*p == ',')) {
79 p++; //skip spaces and commas
80 }
81 if (*p == 0) {
82 break;
83 }
84 if (!IsHexDigit(p[0]) || !IsHexDigit(p[1])) {
85 MsgLog("[ERROR] bin2hex '%s' syntax error\n", hex);
86 return 0;
87 }
88 buf[0] = *p++;
89 buf[1] = *p++;
90 bin[i] = hexstrtouint8(buf);
91 outlen++;
92 }
93 //bin[outlen] = 0;
94 return outlen;
95}
96
97XString8 Bytes2HexStr(UINT8 *data, UINTN len)
98{

Callers 5

ApplyInputsFunction · 0.85
GetDataSettingFunction · 0.85
GetUserSettingsFunction · 0.85
SetDevicesFunction · 0.85
nsvg__parseColorHexFunction · 0.85

Calls 3

AsciiStrLenFunction · 0.85
hexstrtouint8Function · 0.85
IsHexDigitFunction · 0.70

Tested by

no test coverage detected