From 8a2cdbe47e0facf768deb07252d714a07fbe0916 Mon Sep 17 00:00:00 2001 From: solohsu Date: Mon, 22 Apr 2019 18:54:59 +0800 Subject: [PATCH] Add class ResStringPool --- .../jni/main/native_hook/resource_hook.cpp | 6 ++--- .../jni/main/native_hook/resource_hook.h | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/edxp-core/jni/main/native_hook/resource_hook.cpp b/edxp-core/jni/main/native_hook/resource_hook.cpp index 4f485bac..f627b216 100644 --- a/edxp-core/jni/main/native_hook/resource_hook.cpp +++ b/edxp-core/jni/main/native_hook/resource_hook.cpp @@ -20,7 +20,7 @@ void (*ResXMLParser_restart)(void *); int32_t (*ResXMLParser_getAttributeNameID)(void *, int); -char16_t *(*ResStringPool_stringAt)(void *, int32_t, size_t *); +char16_t *(*ResStringPool_stringAt)(const void *, int32_t, size_t *); bool prepareSymbols() { void *fwHandle = dlopen(kLibFwPath, RTLD_LAZY | RTLD_GLOBAL); @@ -51,7 +51,7 @@ bool prepareSymbols() { LOGE("can't get ResXMLParser_getAttributeNameID: %s", dlerror()); return false; } - ResStringPool_stringAt = reinterpret_cast(dlsym( + ResStringPool_stringAt = reinterpret_cast(dlsym( fwHandle, #if defined(__LP64__) "_ZNK7android13ResStringPool8stringAtEmPm" @@ -122,7 +122,7 @@ void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass, // only replace attribute name IDs for app packages if (attrNameID >= 0 && (size_t)attrNameID < mTree.mNumResIds && dtohl(mResIds[attrNameID]) >= 0x7f000000) { size_t attNameLen; - const char16_t* attrName = ResStringPool_stringAt(mTree.mStrings, attrNameID, &attNameLen); + const char16_t* attrName = ResStringPool_stringAt(&(mTree.mStrings), attrNameID, &attNameLen); jint attrResID = env->CallStaticIntMethod(classXResources, methodXResourcesTranslateAttrId, env->NewString((const jchar*)attrName, attNameLen), origRes); if (env->ExceptionCheck()) diff --git a/edxp-core/jni/main/native_hook/resource_hook.h b/edxp-core/jni/main/native_hook/resource_hook.h index 52e91bbd..ef532a18 100644 --- a/edxp-core/jni/main/native_hook/resource_hook.h +++ b/edxp-core/jni/main/native_hook/resource_hook.h @@ -23,7 +23,7 @@ enum { RES_TABLE_TYPE = 0x0002, RES_XML_TYPE = 0x0003, // Chunk types in RES_XML_TYPE - RES_XML_FIRST_CHUNK_TYPE = 0x0100, + RES_XML_FIRST_CHUNK_TYPE = 0x0100, RES_XML_START_NAMESPACE_TYPE= 0x0100, RES_XML_END_NAMESPACE_TYPE = 0x0101, RES_XML_START_ELEMENT_TYPE = 0x0102, @@ -32,9 +32,9 @@ enum { RES_XML_LAST_CHUNK_TYPE = 0x017f, // This contains a uint32_t array mapping strings in the string // pool back to resource identifiers. It is optional. - RES_XML_RESOURCE_MAP_TYPE = 0x0180, + RES_XML_RESOURCE_MAP_TYPE = 0x0180, // Chunk types in RES_TABLE_TYPE - RES_TABLE_PACKAGE_TYPE = 0x0200, + RES_TABLE_PACKAGE_TYPE = 0x0200, RES_TABLE_TYPE_TYPE = 0x0201, RES_TABLE_TYPE_SPEC_TYPE = 0x0202, RES_TABLE_LIBRARY_TYPE = 0x0203 @@ -78,6 +78,23 @@ public: const void* mCurExt; }; +class ResStringPool +{ +public: + int32_t mError; + void* mOwnedData; + const void* mHeader; + size_t mSize; + mutable pthread_mutex_t mDecodeLock; + const uint32_t* mEntries; + const uint32_t* mEntryStyles; + const void* mStrings; + char16_t mutable** mCache; + uint32_t mStringPoolSize; // number of uint16_t + const uint32_t* mStyles; + uint32_t mStylePoolSize; // number of uint32_t +}; + class ResXMLTree : public ResXMLParser { @@ -90,7 +107,7 @@ public: const void* mHeader; size_t mSize; const uint8_t* mDataEnd; - void* mStrings; + ResStringPool mStrings; const uint32_t* mResIds; size_t mNumResIds; const ResXMLTree_node* mRootNode;