|
4 | 4 | #include <cstdint> // int32_t, int64_t, uint64_t |
5 | 5 | #include <cstdlib> // malloc, free |
6 | 6 | #include <cstring> // memcpy |
| 7 | +#include <string> |
7 | 8 | #include <vector> |
8 | 9 | #include <memory> // std::unique_ptr |
9 | 10 |
|
| 11 | +#include "idevice/idevice.h" // hexdump |
| 12 | +#include "nskeyedarchiver/nskeyedunarchiver.hpp" |
| 13 | + |
10 | 14 | namespace idevice { |
11 | 15 |
|
12 | 16 | class DTXPrimitiveValue { |
@@ -131,6 +135,49 @@ class DTXPrimitiveValue { |
131 | 135 | Type GetType() const { return t_; } |
132 | 136 | void SetType(Type t) { t_ = t; } |
133 | 137 |
|
| 138 | + void Dump(bool dumphex = true) const { |
| 139 | + switch (t_) { |
| 140 | + case kNull: |
| 141 | + printf("[type=kNull, size=0, value=]\n"); |
| 142 | + case kEmptyKey: |
| 143 | + printf("[type=kEmptyKey, size=0, value=]\n"); |
| 144 | + break; |
| 145 | + case kString: { |
| 146 | + size_t str_len = Size(); |
| 147 | + char* str = static_cast<char*>(malloc(str_len + 1)); |
| 148 | + strncpy(str, d_.b, str_len); |
| 149 | + str[str_len] = '\0'; |
| 150 | + printf("[type=kString, size=%zu, value=%s]\n", Size(), str); |
| 151 | + free(str); |
| 152 | + break; |
| 153 | + } |
| 154 | + case kBuffer: { |
| 155 | + if (dumphex) { |
| 156 | + hexdump(d_.b, Size(), 0); |
| 157 | + } |
| 158 | + nskeyedarchiver::KAValue value = nskeyedarchiver::NSKeyedUnarchiver::UnarchiveTopLevelObjectWithData(d_.b, Size()); |
| 159 | + printf("[type=kBuffer, size=%zu, value=%s]\n", Size(), value.ToJson().c_str()); |
| 160 | + break; |
| 161 | + } |
| 162 | + case kSignedInt32: |
| 163 | + printf("[type=kSignedInt32, size=%zu, value=%d]\n", Size(), d_.i32); |
| 164 | + break; |
| 165 | + case kSignedInt64: |
| 166 | + printf("[type=kSignedInt64, size=%zu, value=%lld]\n", Size(), d_.i64); |
| 167 | + break; |
| 168 | + case kFloat32: |
| 169 | + printf("[type=kFloat32, size=%zu, value=%f]\n", Size(), d_.f); |
| 170 | + break; |
| 171 | + case kFloat64: |
| 172 | + printf("[type=kFloat64, size=%zu, value=%f]\n", Size(), d_.d); |
| 173 | + break; |
| 174 | + case kInteger: |
| 175 | + printf("[type=kSignedInt64, size=%zu, value=%llu]\n", Size(), d_.u); |
| 176 | + default: |
| 177 | + break; |
| 178 | + } |
| 179 | + } |
| 180 | + |
134 | 181 | private: |
135 | 182 | union { |
136 | 183 | char* b; // kString or kBuffer |
@@ -175,6 +222,8 @@ class DTXPrimitiveArray { |
175 | 222 |
|
176 | 223 | size_t Size() const { return items_.size(); } |
177 | 224 |
|
| 225 | + void Dump(bool dumphex = true) const; |
| 226 | + |
178 | 227 | private: |
179 | 228 | std::vector<DTXPrimitiveValue> items_; |
180 | 229 | bool as_dict_ = false; |
|
0 commit comments