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

Function MangleForJni

Bcore/src/main/cpp/dex/descriptors_names.cc:99–126  ·  view source on GitHub ↗

See http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp615 for the full rules.

Source from the content-addressed store, hash-verified

97
98// See http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp615 for the full rules.
99std::string MangleForJni(const std::string& s) {
100 std::string result;
101 size_t char_count = CountModifiedUtf8Chars(s.c_str());
102 const char* cp = &s[0];
103 for (size_t i = 0; i < char_count; ++i) {
104 uint32_t ch = GetUtf16FromUtf8(&cp);
105 if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
106 result.push_back(ch);
107 } else if (ch == '.' || ch == '/') {
108 result += "_";
109 } else if (ch == '_') {
110 result += "_1";
111 } else if (ch == ';') {
112 result += "_2";
113 } else if (ch == '[') {
114 result += "_3";
115 } else {
116 const uint16_t leading = GetLeadingUtf16Char(ch);
117 const uint32_t trailing = GetTrailingUtf16Char(ch);
118
119 StringAppendF(&result, "_0%04x", leading);
120 if (trailing != 0) {
121 StringAppendF(&result, "_0%04x", trailing);
122 }
123 }
124 }
125 return result;
126}
127
128std::string DotToDescriptor(const char* class_name) {
129 std::string descriptor(class_name);

Callers 1

GetJniShortNameFunction · 0.85

Calls 6

CountModifiedUtf8CharsFunction · 0.85
GetUtf16FromUtf8Function · 0.85
GetLeadingUtf16CharFunction · 0.85
GetTrailingUtf16CharFunction · 0.85
StringAppendFFunction · 0.85
c_strMethod · 0.80

Tested by

no test coverage detected