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

Function ThinFatFile

rEFIt_UEFI/Platform/kext_inject.cpp:35–85  ·  view source on GitHub ↗

/////////////// before booting ///////////////

Source from the content-addressed store, hash-verified

33// before booting
34////////////////////
35EFI_STATUS EFIAPI ThinFatFile(IN OUT UINT8 **binary, IN OUT UINTN *length, IN cpu_type_t archCpuType)
36{
37 UINT32 nfat, swapped, size = 0;
38 FAT_HEADER *fhp = (FAT_HEADER *)*binary;
39 FAT_ARCH *fap = (FAT_ARCH *)(*binary + sizeof(FAT_HEADER));
40 cpu_type_t fapcputype;
41 UINT32 fapoffset;
42 UINT32 fapsize;
43
44 swapped = 0;
45 if (fhp->magic == FAT_MAGIC) {
46 nfat = fhp->nfat_arch;
47 } else if (fhp->magic == FAT_CIGAM) {
48 nfat = SwapBytes32(fhp->nfat_arch);
49 swapped = 1;
50 //already thin
51 } else if (fhp->magic == THIN_X64){
52 if (archCpuType == CPU_TYPE_X86_64) {
53 return EFI_SUCCESS;
54 }
55 return EFI_NOT_FOUND;
56 } else if (fhp->magic == THIN_IA32){
57 if (archCpuType == CPU_TYPE_I386) {
58 return EFI_SUCCESS;
59 }
60 return EFI_NOT_FOUND;
61 } else {
62 MsgLog("Thinning fails\n");
63 return EFI_NOT_FOUND;
64 }
65
66 for (; nfat > 0; nfat--, fap++) {
67 if (swapped) {
68 fapcputype = SwapBytes32(fap->cputype);
69 fapoffset = SwapBytes32(fap->offset);
70 fapsize = SwapBytes32(fap->size);
71 } else {
72 fapcputype = fap->cputype;
73 fapoffset = fap->offset;
74 fapsize = fap->size;
75 }
76 if (fapcputype == archCpuType) {
77 *binary = (*binary + fapoffset);
78 size = fapsize;
79 break;
80 }
81 }
82 if (length != 0) *length = size;
83
84 return EFI_SUCCESS;
85}
86
87void toLowerStr(CHAR8 *tstr, IN CONST CHAR8 *str) {
88 UINT16 cnt = 0;

Callers 1

LoadKextMethod · 0.85

Calls 1

SwapBytes32Function · 0.50

Tested by

no test coverage detected