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

Function UpdateSmbiosString

rEFIt_UEFI/Platform/smbios.cpp:285–343  ·  view source on GitHub ↗

the procedure insert Buffer into SmbiosTable by copy and update Field the Buffer restricted by zero or by space

Source from the content-addressed store, hash-verified

283// the procedure insert Buffer into SmbiosTable by copy and update Field
284// the Buffer restricted by zero or by space
285EFI_STATUS UpdateSmbiosString(OUT APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN,
286 SMBIOS_TABLE_STRING* Field, const XString8& Buffer)
287{
288 CHAR8* AString;
289 CHAR8* C1; //pointers for copy
290 CHAR8* C2;
291 UINTN Length = SmbiosTableLength(SmbiosTableN);
292 UINTN ALength, BLength;
293 UINT8 IndexStr = 1;
294
295 if ((SmbiosTableN.Raw == NULL) || Buffer.isEmpty() || !Field) {
296 return EFI_NOT_FOUND;
297 }
298 AString = (CHAR8*)(SmbiosTableN.Raw + SmbiosTableN.Hdr->Length); //first string
299 while (IndexStr != *Field) {
300 if (*AString) {
301 IndexStr++;
302 }
303 while (*AString != 0) AString++; //skip string at index
304 AString++; //next string
305 if (*AString == 0) {
306 //this is end of the table
307 if (*Field == 0) {
308 AString[1] = 0; //one more zero
309 }
310 *Field = IndexStr; //index of the next string that is empty
311 if (IndexStr == 1) {
312 AString--; //first string has no leading zero
313 }
314 break;
315 }
316 }
317 // AString is at place to copy
318 ALength = iStrLen(AString, 0);
319 BLength = iStrLen(Buffer.c_str(), MAX_OEM_STRING);
320 // DBG("Table type %d field %d\n", SmbiosTable.Hdr->Type, *Field);
321 // DBG("Old string length=%d new length=%d\n", ALength, BLength);
322 if (BLength > ALength) {
323 //Shift right
324 C1 = (CHAR8*)SmbiosTableN.Raw + Length; //old end
325 C2 = C1 + BLength - ALength; //new end
326 *C2 = 0;
327 while (C1 != AString) *(--C2) = *(--C1);
328
329 } else if (BLength < ALength) {
330 //Shift left
331 C1 = AString + ALength; //old start
332 C2 = AString + BLength; //new start
333 while (C1 != ((CHAR8*)SmbiosTableN.Raw + Length)) {
334 *C2++ = *C1++;
335 }
336 *C2 = 0;
337 *(--C2) = 0; //end of table
338 }
339 CopyMem(AString, Buffer.c_str(), BLength);
340 *(AString + BLength) = 0; // not sure there is 0
341
342 return EFI_SUCCESS;

Callers 9

PatchTableType0Function · 0.85
PatchTableType1Function · 0.85
PatchTableType2Function · 0.85
PatchTableType3Function · 0.85
PatchTableType4Function · 0.85
PatchTableType7Function · 0.85
PatchTableType9Function · 0.85
PatchTableType11Function · 0.85
PatchTableType17Function · 0.85

Calls 5

iStrLenFunction · 0.85
SmbiosTableLengthFunction · 0.70
CopyMemFunction · 0.50
isEmptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected