forked from focus-creative-games/il2cpp_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlobReader.cpp
More file actions
86 lines (80 loc) · 2.67 KB
/
BlobReader.cpp
File metadata and controls
86 lines (80 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "il2cpp-config.h"
#if !IL2CPP_TINY_WITHOUT_DEBUGGER
#include <stdint.h>
#include "BlobReader.h"
#include "utils/MemoryRead.h"
#include "il2cpp-object-internals.h"
#include "il2cpp-vm-support.h"
#include "hybridclr/metadata/RawImage.h"
namespace il2cpp
{
namespace utils
{
int BlobReader::GetConstantValueFromBlob(Il2CppTypeEnum type, const char *blob, void *value, bool compressBlogSize)
{
int retval = 0;
const char *p = blob;
switch (type)
{
case IL2CPP_TYPE_BOOLEAN:
case IL2CPP_TYPE_U1:
case IL2CPP_TYPE_I1:
*(uint8_t*)value = *p;
break;
case IL2CPP_TYPE_CHAR:
*(Il2CppChar*)value = ReadChar(p);
break;
case IL2CPP_TYPE_U2:
case IL2CPP_TYPE_I2:
*(uint16_t*)value = Read16(p);
break;
case IL2CPP_TYPE_U4:
case IL2CPP_TYPE_I4:
*(uint32_t*)value = Read32(p);
break;
case IL2CPP_TYPE_U8:
case IL2CPP_TYPE_I8:
*(uint64_t*)value = Read64(p);
break;
case IL2CPP_TYPE_R4:
*(float*)value = ReadFloat(p);
break;
case IL2CPP_TYPE_R8:
*(double*)value = ReadDouble(p);
break;
case IL2CPP_TYPE_STRING:
{
*(void**)value = NULL;
if (p != NULL)
{
if (compressBlogSize)
{
// origin IL metadata use compress encode length
hybridclr::metadata::BlobReader blob = hybridclr::metadata::RawImage::DecodeBlob((const hybridclr::byte*)p);
*(VmString**)value = IL2CPP_VM_STRING_NEW_UTF16((const Il2CppChar*)blob.GetData(), blob.GetLength()/2);
}
else
{
// int32_t length followed by non-null terminated utf-8 byte stream
uint32_t length = Read32(p);
*(VmString**)value = IL2CPP_VM_STRING_NEW_LEN(p + sizeof(uint32_t), length);
}
}
break;
}
case IL2CPP_TYPE_CLASS:
case IL2CPP_TYPE_OBJECT:
case IL2CPP_TYPE_GENERICINST:
case IL2CPP_TYPE_SZARRAY:
IL2CPP_ASSERT(p == NULL);
*(void**)value = NULL;
break;
default:
retval = -1;
IL2CPP_ASSERT(0);
}
return retval;
}
} /* utils */
} /* il2cpp */
#endif