mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-10 09:40:53 +01:00
make TagData::setDataValue accept NULL value for data.
This commit is contained in:
parent
352c75c711
commit
babba4de6e
@ -141,6 +141,8 @@
|
||||
9A670D1D24E535AB00B5D780 /* XBuffer_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A670D1B24E535AB00B5D780 /* XBuffer_tests.cpp */; };
|
||||
9A670D1E24E535AB00B5D780 /* XBuffer_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A670D1B24E535AB00B5D780 /* XBuffer_tests.cpp */; };
|
||||
9A670D1F24E535AB00B5D780 /* XBuffer_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A670D1B24E535AB00B5D780 /* XBuffer_tests.cpp */; };
|
||||
9A7D518424FC32F700FA1CC3 /* XBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A7D518124FC32F700FA1CC3 /* XBuffer.cpp */; };
|
||||
9A7D518524FC32F700FA1CC3 /* XRBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A7D518324FC32F700FA1CC3 /* XRBuffer.cpp */; };
|
||||
9A9223312402FD1000483CBA /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9223302402FD1000483CBA /* main.cpp */; };
|
||||
9A9AEB8D243F73CE00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; };
|
||||
9A9AEB8E243F752C00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; };
|
||||
@ -267,6 +269,10 @@
|
||||
9A670D1B24E535AB00B5D780 /* XBuffer_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XBuffer_tests.cpp; sourceTree = "<group>"; };
|
||||
9A6BA73C2449977300BDA52C /* XStringAbstract.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringAbstract.h; sourceTree = "<group>"; };
|
||||
9A7AEDE82459696C003AAD04 /* XToolsCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XToolsCommon.h; sourceTree = "<group>"; };
|
||||
9A7D518024FC32F700FA1CC3 /* XBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XBuffer.h; sourceTree = "<group>"; };
|
||||
9A7D518124FC32F700FA1CC3 /* XBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XBuffer.cpp; sourceTree = "<group>"; };
|
||||
9A7D518224FC32F700FA1CC3 /* XRBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XRBuffer.h; sourceTree = "<group>"; };
|
||||
9A7D518324FC32F700FA1CC3 /* XRBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XRBuffer.cpp; sourceTree = "<group>"; };
|
||||
9A92232D2402FD1000483CBA /* cpp_tests UTF16 signed char */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp_tests UTF16 signed char"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
9A9223302402FD1000483CBA /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
|
||||
9A92234D2402FD9500483CBA /* Platform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = "<group>"; };
|
||||
@ -331,6 +337,10 @@
|
||||
9A0B08432402FE9300E2B470 /* cpp_foundation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A7D518124FC32F700FA1CC3 /* XBuffer.cpp */,
|
||||
9A7D518024FC32F700FA1CC3 /* XBuffer.h */,
|
||||
9A7D518324FC32F700FA1CC3 /* XRBuffer.cpp */,
|
||||
9A7D518224FC32F700FA1CC3 /* XRBuffer.h */,
|
||||
9A7AEDE82459696C003AAD04 /* XToolsCommon.h */,
|
||||
9A4FFA7C2451C8330050B38B /* XString.cpp */,
|
||||
9A57C266241A799B0029A39F /* XString.h */,
|
||||
@ -777,6 +787,7 @@
|
||||
9A36E50024F3B537007A1107 /* TagDict.cpp in Sources */,
|
||||
9A36E50C24F3B537007A1107 /* TagData.cpp in Sources */,
|
||||
9A0B085A2402FF8400E2B470 /* XObjArray_tests.cpp in Sources */,
|
||||
9A7D518424FC32F700FA1CC3 /* XBuffer.cpp in Sources */,
|
||||
9A36E52C24F3C846007A1107 /* plist_tests.cpp in Sources */,
|
||||
9A28CD1F241BB61B00F3D247 /* abort.cpp in Sources */,
|
||||
9A36E53C24F3EDED007A1107 /* base64.cpp in Sources */,
|
||||
@ -800,6 +811,7 @@
|
||||
9A0B08582402FF7F00E2B470 /* XStringArray_test.cpp in Sources */,
|
||||
9A36E4F824F3B537007A1107 /* xml.cpp in Sources */,
|
||||
9A9AEB8D243F73CE00FBD7D8 /* unicode_conversions.cpp in Sources */,
|
||||
9A7D518524FC32F700FA1CC3 /* XRBuffer.cpp in Sources */,
|
||||
9A4185C02439F73A00BEAFB8 /* XStringArray.cpp in Sources */,
|
||||
9A36E51024F3B537007A1107 /* TagArray.cpp in Sources */,
|
||||
9A36E4F024F3B537007A1107 /* TagString8.cpp in Sources */,
|
||||
|
@ -928,8 +928,8 @@ FillinKextPatches (IN OUT KERNEL_AND_KEXT_PATCHES *Patches,
|
||||
p = GetDataSetting (DictPointer, "ATIConnectorsPatch", &i);
|
||||
Patches->KPATIConnectorsPatch.stealValueFrom(p, i);
|
||||
|
||||
if (Patches->KPATIConnectorsData == NULL
|
||||
|| Patches->KPATIConnectorsPatch == NULL
|
||||
if (Patches->KPATIConnectorsData.isEmpty()
|
||||
|| Patches->KPATIConnectorsPatch.isEmpty()
|
||||
|| Patches->KPATIConnectorsData.size() == 0
|
||||
|| Patches->KPATIConnectorsData.size() != i) {
|
||||
// invalid params - no patching
|
||||
|
@ -2383,7 +2383,7 @@ LOADER_ENTRY::KernelUserPatch()
|
||||
UINT8 * curs = &KernelData[procAddr];
|
||||
UINTN j = 0;
|
||||
while (j < KERNEL_MAX_SIZE) {
|
||||
if (!KernelAndKextPatches.KernelPatches[i].StartPattern || //old behavior
|
||||
if (KernelAndKextPatches.KernelPatches[i].StartPattern.isEmpty() || //old behavior
|
||||
CompareMemMask((const UINT8*)curs,
|
||||
KernelAndKextPatches.KernelPatches[i].StartPattern.data(),
|
||||
KernelAndKextPatches.KernelPatches[i].StartPattern.size(),
|
||||
@ -2406,9 +2406,7 @@ LOADER_ENTRY::KernelUserPatch()
|
||||
j += SearchLen - 1;
|
||||
}
|
||||
DBG( "==> %s : %lld replaces done\n", Num ? "Success" : "Error", Num);
|
||||
if (once ||
|
||||
!KernelAndKextPatches.KernelPatches[i].StartPattern ||
|
||||
!KernelAndKextPatches.KernelPatches[i].StartPattern.size()) {
|
||||
if ( once || KernelAndKextPatches.KernelPatches[i].StartPattern.isEmpty() ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2444,7 +2442,7 @@ LOADER_ENTRY::BooterPatch(IN UINT8 *BooterData, IN UINT64 BooterSize)
|
||||
UINT8 * curs = BooterData;
|
||||
UINTN j = 0;
|
||||
while (j < BooterSize) {
|
||||
if (!KernelAndKextPatches.BootPatches[i].StartPattern || //old behavior
|
||||
if (KernelAndKextPatches.BootPatches[i].StartPattern.isEmpty() || //old behavior
|
||||
CompareMemMask((const UINT8*)curs,
|
||||
(const UINT8*)KernelAndKextPatches.BootPatches[i].StartPattern.data(),
|
||||
KernelAndKextPatches.BootPatches[i].StartPattern.size(),
|
||||
@ -2468,8 +2466,7 @@ LOADER_ENTRY::BooterPatch(IN UINT8 *BooterData, IN UINT64 BooterSize)
|
||||
}
|
||||
|
||||
DBG( "==> %s : %lld replaces done\n", Num ? "Success" : "Error", Num);
|
||||
if (!KernelAndKextPatches.BootPatches[i].StartPattern ||
|
||||
!KernelAndKextPatches.BootPatches[i].StartPattern.size()) {
|
||||
if ( KernelAndKextPatches.BootPatches[i].StartPattern.isEmpty() ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2614,7 +2611,7 @@ LOADER_ENTRY::KernelAndKextsPatcherStart()
|
||||
KernelAndKextPatches.KPAppleRTC ||
|
||||
KernelAndKextPatches.EightApple ||
|
||||
KernelAndKextPatches.KPDELLSMBIOS ||
|
||||
KernelAndKextPatches.KPATIConnectorsPatch != NULL ||
|
||||
KernelAndKextPatches.KPATIConnectorsPatch.notEmpty() ||
|
||||
KernelAndKextPatches.KextPatches.size() > 0
|
||||
);
|
||||
|
||||
|
@ -1153,7 +1153,7 @@ VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPli
|
||||
UINT8 * curs = &Driver[procAddr];
|
||||
UINTN j = 0;
|
||||
while (j < DriverSize) {
|
||||
if (!kextpatch.StartPattern || //old behavior
|
||||
if (kextpatch.StartPattern.isEmpty() || //old behavior
|
||||
CompareMemMask((const UINT8*)curs,
|
||||
kextpatch.StartPattern.data(),
|
||||
kextpatch.StartPattern.size(),
|
||||
@ -1174,9 +1174,7 @@ VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPli
|
||||
j += SearchLen - 1;
|
||||
}
|
||||
}
|
||||
if (once ||
|
||||
!kextpatch.StartPattern ||
|
||||
!kextpatch.StartPattern.size()) {
|
||||
if ( once || kextpatch.StartPattern.isEmpty() ) {
|
||||
break;
|
||||
}
|
||||
j++; curs++;
|
||||
|
@ -69,19 +69,14 @@ TagData* TagData::getEmptyTag()
|
||||
|
||||
void TagData::FreeTag()
|
||||
{
|
||||
if ( _data ) FreePool(_data);
|
||||
_data = NULL;
|
||||
_dataLen = 0;
|
||||
dataBuffer.setEmpty();
|
||||
tagsFree.AddReference(this, true);
|
||||
}
|
||||
|
||||
bool TagData::operator == (const TagStruct& other) const
|
||||
{
|
||||
if ( !other.isData() ) return false;
|
||||
if ( _dataLen != other.getData()->_dataLen ) return false;
|
||||
if ( _dataLen > 0 ) { // if dataLen > 0, data cannot be NULL. Enforce by ctor and set setDataValue
|
||||
if ( memcmp((void*)_data, (void*)other.getData()->_data, _dataLen) != 0 ) return false;
|
||||
}
|
||||
if ( dataBuffer != other.getData()->dataBuffer ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -89,9 +84,9 @@ void TagData::sprintf(unsigned int ident, XString8* s) const
|
||||
{
|
||||
for (size_t i = 0 ; i < (size_t)ident ; i++) *s += " ";
|
||||
*s += "<data>\n"_XS8;
|
||||
if ( _dataLen > 0 ) {
|
||||
if ( dataBuffer.size() > 0 ) {
|
||||
size_t outputLen;
|
||||
char* output = base64_encode(_data, _dataLen, &outputLen);
|
||||
char* output = base64_encode(dataBuffer.data(), dataBuffer.size(), &outputLen);
|
||||
for (size_t i = 0 ; i < (size_t)ident ; i++) *s += " ";
|
||||
(*s).strncat(output, outputLen);
|
||||
free(output);
|
||||
|
@ -9,19 +9,19 @@
|
||||
#define __TagData_h__
|
||||
|
||||
#include "plist.h"
|
||||
#include "../../cpp_foundation/XBuffer.h"
|
||||
|
||||
class TagData : public TagStruct
|
||||
{
|
||||
static XObjArray<TagData> tagsFree;
|
||||
UINT8 *_data;
|
||||
UINTN _dataLen;
|
||||
XBuffer<UINT8> dataBuffer;
|
||||
|
||||
public:
|
||||
|
||||
TagData() : _data(NULL), _dataLen(0) {}
|
||||
TagData() : dataBuffer() {}
|
||||
TagData(const TagData& other) = delete; // Can be defined if needed
|
||||
const TagData& operator = (const TagData&); // Can be defined if needed
|
||||
virtual ~TagData() { delete _data; }
|
||||
virtual ~TagData() { }
|
||||
|
||||
virtual bool operator == (const TagStruct& other) const;
|
||||
|
||||
@ -41,23 +41,23 @@ public:
|
||||
const UINT8* dataValue() const
|
||||
{
|
||||
// if ( !isData() ) panic("TagData::dataValue() : !isData() ");
|
||||
return _data;
|
||||
return dataBuffer.data();
|
||||
}
|
||||
UINT8* dataValue()
|
||||
{
|
||||
// if ( !isData() ) panic("TagData::dataValue() : !isData() ");
|
||||
return _data;
|
||||
return dataBuffer.data();
|
||||
}
|
||||
UINTN dataLenValue() const
|
||||
{
|
||||
// if ( !isData() ) panic("TagData::dataLenValue() : !isData() ");
|
||||
return _dataLen;
|
||||
return dataBuffer.size();
|
||||
}
|
||||
void setDataValue(UINT8* data, UINTN dataLen)
|
||||
{
|
||||
if ( data == NULL ) panic("TagData::setDataValue() : _data == NULL ");
|
||||
_data = data;
|
||||
_dataLen = dataLen;
|
||||
if ( data == NULL && dataLen != 0 ) panic("TagData::setDataValue() : data == NULL && dataLen != 0 ");
|
||||
if ( data != NULL && dataLen == 0 ) panic("TagData::setDataValue() : data != NULL && dataLen == 0 ");
|
||||
dataBuffer.stealValueFrom(data, dataLen);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -674,9 +674,7 @@ EFI_STATUS ParseTagData(CHAR8* buffer, TagStruct* * tag, UINT32* lenPtr)
|
||||
// dmazar: base64 decode data
|
||||
UINTN len = 0;
|
||||
UINT8* data = (UINT8 *)Base64DecodeClover(buffer, &len);
|
||||
if (data != nullptr && len != 0) {
|
||||
tmpTag->setDataValue(data, len);
|
||||
}
|
||||
tmpTag->setDataValue(data, len);
|
||||
*tag = tmpTag;
|
||||
*lenPtr = length;
|
||||
|
||||
|
@ -23,7 +23,7 @@ class XBuffer : public XBuffer_Super
|
||||
T*_WData; // same as RData (see XRBuffer)
|
||||
size_t m_allocatedSize;
|
||||
|
||||
void Initialize(T* p, size_t count, size_t index);
|
||||
void Initialize(const T* p, size_t count, size_t index);
|
||||
public:
|
||||
XBuffer() : _WData(NULL), m_allocatedSize(0) { Initialize(NULL, 0, 0); } // ": _WData(NULL), m_allocatedSize(0)" to avoid effc++ warning
|
||||
|
||||
@ -50,7 +50,8 @@ class XBuffer : public XBuffer_Super
|
||||
void CheckSize(size_t nNewSize, size_t nGrowBy = XBufferGrowByDefault);
|
||||
|
||||
void* vdata() const { return XBuffer_Super::data(); }
|
||||
T* data() const { return _WData; }
|
||||
const T* data() const { return _WData; }
|
||||
T* data() { return _WData; }
|
||||
|
||||
template<typename IntegralType, enable_if(is_integral(IntegralType))>
|
||||
const T* data(IntegralType i) const { return XBuffer_Super::data(i); }
|
||||
@ -82,6 +83,14 @@ class XBuffer : public XBuffer_Super
|
||||
|
||||
void setEmpty() { setSize(0); };
|
||||
|
||||
bool operator == (const XBuffer<T>& other) const {
|
||||
if ( size() != other.size() ) return false;
|
||||
if ( size() == 0 ) return true;
|
||||
if ( memcmp(_WData, other._WData, size()) != 0 ) return false;
|
||||
return true;
|
||||
}
|
||||
bool operator != (const XBuffer<T>& other) const { return !(*this == other); }
|
||||
|
||||
/* [] */
|
||||
template<typename IntegralType, enable_if(is_integral(IntegralType))>
|
||||
T& operator [](IntegralType i)
|
||||
@ -90,6 +99,13 @@ class XBuffer : public XBuffer_Super
|
||||
if ( (unsigned_type(IntegralType))i >= size() ) panic("XBuffer::[] : i > _Len. System halted\n");
|
||||
return _WData[(unsigned_type(IntegralType))i];
|
||||
}
|
||||
template<typename IntegralType, enable_if(is_integral(IntegralType))>
|
||||
const T& operator [](IntegralType i) const
|
||||
{
|
||||
if (i < 0) panic("XBuffer::[] : i < 0. System halted\n");
|
||||
if ( (unsigned_type(IntegralType))i >= size() ) panic("XBuffer::[] : i > _Len. System halted\n");
|
||||
return _WData[(unsigned_type(IntegralType))i];
|
||||
}
|
||||
|
||||
// unsigned char& operator [](int i) { return UCData()[i]; } // underflow ? overflow ?
|
||||
// unsigned char& operator [](size_t i) { return UCData()[i]; }
|
||||
@ -153,7 +169,7 @@ class XBuffer : public XBuffer_Super
|
||||
|
||||
//*************************************************************************************************
|
||||
template <typename T>
|
||||
void XBuffer<T>::Initialize(T* p, size_t count, size_t index)
|
||||
void XBuffer<T>::Initialize(const T* p, size_t count, size_t index)
|
||||
{
|
||||
if ( p!=NULL && count>0 )
|
||||
{
|
||||
|
@ -52,6 +52,14 @@ class XRBuffer
|
||||
|
||||
size_t size() const { return m_size; }
|
||||
size_t index() const { return _Index; }
|
||||
|
||||
bool operator == (const XRBuffer<T>& other) const {
|
||||
if ( m_size != other.m_size ) return false;
|
||||
if ( m_size == 0 ) return true;
|
||||
if ( memcmp(_RData, other._RData, m_size) != 0 ) return false;
|
||||
return true;
|
||||
}
|
||||
bool operator != (const XRBuffer<T>& other) const { return !(*this == other); }
|
||||
|
||||
template<typename IntegralType, enable_if(is_integral(IntegralType))>
|
||||
void setIndex(IntegralType Idx)
|
||||
@ -66,7 +74,8 @@ class XRBuffer
|
||||
bool notEmpty() const { return m_size > 0 ; }
|
||||
|
||||
// Cast //
|
||||
operator const char *() const { return CData(); }
|
||||
// Automatic cast are a bit dangerous...
|
||||
// operator const char *() const { return CData(); }
|
||||
|
||||
// [] //
|
||||
template<typename IntegralType, enable_if(is_integral(IntegralType))>
|
||||
@ -78,7 +87,18 @@ class XRBuffer
|
||||
if ( (unsigned_type(IntegralType))i >= m_size ) {
|
||||
panic("XRBuffer::operator [] : index > len. System halted\n");
|
||||
}
|
||||
return UCData()[i];
|
||||
return _RData[i];
|
||||
} // underflow ? overflow ?
|
||||
template<typename IntegralType, enable_if(is_integral(IntegralType))>
|
||||
const T& operator [](IntegralType i) const
|
||||
{
|
||||
if (i < 0) {
|
||||
panic("XRBuffer::operator [] : i < 0. System halted\n");
|
||||
}
|
||||
if ( (unsigned_type(IntegralType))i >= m_size ) {
|
||||
panic("XRBuffer::operator [] : index > len. System halted\n");
|
||||
}
|
||||
return _RData[i];
|
||||
} // underflow ? overflow ?
|
||||
|
||||
bool Get(void *buf, size_t count);
|
||||
|
@ -16,5 +16,12 @@ int XBuffer_tests()
|
||||
xb_uint8.cat(p2);
|
||||
xb_uint8.cat(uintptr_t(0));
|
||||
|
||||
XBuffer<UINT8> xb_uint8_2;
|
||||
xb_uint8_2.cat(uintptr_t(1));
|
||||
xb_uint8_2.cat(uintptr_t(2));
|
||||
xb_uint8_2.cat(uintptr_t(0));
|
||||
|
||||
if ( xb_uint8_2 != xb_uint8 ) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1840,8 +1840,8 @@ RefitMain (IN EFI_HANDLE ImageHandle,
|
||||
if ( !EFI_ERROR(Status) ) DBG("Clover : Image base = 0x%llX\n", (uintptr_t)LoadedImage->ImageBase); // do not change, it's used by grep to feed the debugger
|
||||
|
||||
#ifdef JIEF_DEBUG
|
||||
// gBS->Stall(1500000); // to give time to gdb to connect
|
||||
gBS->Stall(0500000); // to give time to gdb to connect
|
||||
gBS->Stall(1500000); // to give time to gdb to connect
|
||||
// gBS->Stall(0500000); // to give time to gdb to connect
|
||||
// PauseForKey(L"press\n");
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user