MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / DecodeBase64

Function DecodeBase64

Bcore/src/main/cpp/dex/base64_test_util.h:30–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28namespace art_lkchan {
29
30static inline uint8_t* DecodeBase64(const char* src, size_t* dst_size) {
31 static const uint8_t kBase64Map[256] = {
32 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
33 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
34 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
35 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
36 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
37 255, 254, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6,
38 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
39 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
40 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
41 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
42 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255,
43 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
44 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
45 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
46 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
47 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
48 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
49 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
50 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
51 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
52 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
53 255, 255, 255, 255
54 };
55
56 CHECK(dst_size != nullptr);
57 std::vector<uint8_t> tmp;
58 uint32_t t = 0, y = 0;
59 int g = 3;
60 for (size_t i = 0; src[i] != '\0'; ++i) {
61 uint8_t c = kBase64Map[src[i] & 0xFF];
62 if (c == 255) continue;
63 // the final = symbols are read and used to trim the remaining bytes
64 if (c == 254) {
65 c = 0;
66 // prevent g < 0 which would potentially allow an overflow later
67 if (--g < 0) {
68 *dst_size = 0;
69 return nullptr;
70 }
71 } else if (g != 3) {
72 // we only allow = to be at the end
73 *dst_size = 0;
74 return nullptr;
75 }
76 t = (t << 6) | c;
77 if (++y == 4) {
78 tmp.push_back((t >> 16) & 255);
79 if (g > 1) {
80 tmp.push_back((t >> 8) & 255);
81 }
82 if (g > 2) {
83 tmp.push_back(t & 255);
84 }
85 y = t = 0;
86 }
87 }

Callers

nothing calls this directly

Calls 5

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected