#define kOSSerializeBinarySignature "\323\0\0" /* 0x000000d3 */
enum {
kOSSerializeDictionary = 0x01000000U,
kOSSerializeArray = 0x02000000U,
kOSSerializeSet = 0x03000000U,
kOSSerializeNumber = 0x04000000U,
kOSSerializeSymbol = 0x08000000U,
kOSSerializeString = 0x09000000U,
kOSSerializeData = 0x0a000000U,
kOSSerializeBoolean = 0x0b000000U,
kOSSerializeObject = 0x0c000000U,
kOSSerializeTypeMask = 0x7F000000U,
kOSSerializeDataMask = 0x00FFFFFFU,
kOSSerializeEndCollection = 0x80000000U,
};
031000000024000000000000000000000000
0x000000d3 0x81000000 0x09000004 0x00414141 0x8b000001
<dict>
<string>AAA</string>
<boolean>1</boolean>
</dict>
<dict> <!-- dict, level 0 | END! -->
<string>AAA</string> <!-- string, level 1 -->
<boolean>1</boolean> <!-- bool, level 1 -->
<string>BBB</string> <!-- string, level 1 -->
<boolean>1</boolean> <!-- bool, level 1 -->
<dict> <!-- dict, level 1 -->
<string>CCC</string> <!-- string, level 2 -->
<boolean>1</boolean> <!-- bool, level 2 | END! -->
</dict>
<string>DDD</string> <!-- string, level 1 -->
<boolean>1</boolean> <!-- bool, level 1 | END! -->
</dict>
libkern/c++/OSUnserializeXML.cpp
OSObject* OSUnserializeXML(const char *buffer, size_t bufferSize, OSString **errorString)
{
if (!buffer)
return (0);
if (bufferSize < sizeof(kOSSerializeBinarySignature))
return (0);
if (!strcmp(kOSSerializeBinarySignature, buffer))
return OSUnserializeBinary(buffer, bufferSize, errorString);
// XML must be null terminated
if (buffer[bufferSize - 1]) return 0;
return OSUnserializeXML(buffer, errorString);
}
while (ok)
{
bufferPos += sizeof(*next);
if (!(ok = (bufferPos <= bufferSize))) break;
key = *next++;
len = (key & kOSSerializeDataMask);
wordLen = (len + 3) >> 2;
end = (0 != (kOSSerializeEndCollecton & key));
newCollect = isRef = false;
o = 0; newDict = 0; newArray = 0; newSet = 0;
switch (kOSSerializeTypeMask & key)
{
case kOSSerializeDictionary:
...
case kOSSerializeArray:
...
case kOSSerializeSet:
...
case kOSSerializeObject:
...
case kOSSerializeNumber:
...
case kOSSerializeSymbol:
...
case kOSSerializeString:
...
case kOSSerializeData:
...
case kOSSerializeBoolean:
...
default:
break;
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)