Correct resources types' offsets

This commit is contained in:
solohsu 2019-04-22 22:44:52 +08:00
parent 8a2cdbe47e
commit 6e6327bec8
2 changed files with 98 additions and 87 deletions

View File

@ -97,15 +97,17 @@ jboolean XposedBridge_initXResourcesNative(JNIEnv *env, jclass) {
void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
jlong parserPtr, jobject origRes, jobject repRes) {
ResXMLParser *parser = (ResXMLParser *) parserPtr;
if (parser == nullptr)
return;
const ResXMLTree &mTree = parser->mTree;
uint32_t *mResIds = (uint32_t *) mTree.mResIds;
ResXMLTree_attrExt *tag;
int attrCount;
if (parser == NULL)
return;
do {
switch (ResXMLParser_next(parser)) {
case ResXMLParser::START_TAG:
@ -120,11 +122,16 @@ void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
// find resource IDs for attribute names
int32_t attrNameID = ResXMLParser_getAttributeNameID(parser, idx);
// only replace attribute name IDs for app packages
if (attrNameID >= 0 && (size_t)attrNameID < mTree.mNumResIds && dtohl(mResIds[attrNameID]) >= 0x7f000000) {
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);
jint attrResID = env->CallStaticIntMethod(classXResources, methodXResourcesTranslateAttrId,
env->NewString((const jchar*)attrName, attNameLen), origRes);
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())
goto leave;
@ -139,7 +146,8 @@ void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
if (oldValue < 0x7f000000)
continue;
jint newValue = env->CallStaticIntMethod(classXResources, methodXResourcesTranslateResId,
jint newValue = env->CallStaticIntMethod(classXResources,
methodXResourcesTranslateResId,
oldValue, origRes, repRes);
if (env->ExceptionCheck())
goto leave;

View File

@ -14,9 +14,12 @@ static constexpr const char *kLibFwPath = "/system/lib/libandroidfw.so";
#endif
jboolean XposedBridge_initXResourcesNative(JNIEnv *env, jclass);
void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
jlong parserPtr, jobject origRes, jobject repRes);
typedef int32_t status_t;
enum {
RES_NULL_TYPE = 0x0000,
RES_STRING_POOL_TYPE = 0x0001,
@ -40,8 +43,7 @@ enum {
RES_TABLE_LIBRARY_TYPE = 0x0203
};
struct ResXMLTree_node
{
struct ResXMLTree_node {
void *header;
// Line number in original source file at which this element appeared.
uint32_t lineNumber;
@ -51,8 +53,8 @@ struct ResXMLTree_node
class ResXMLTree;
class ResXMLParser
{
class ResXMLParser {
public:
enum event_code_t {
BAD_DOCUMENT = -1,
@ -68,20 +70,16 @@ public:
TEXT = RES_XML_CDATA_TYPE
};
public:
friend class ResXMLTree;
event_code_t nextNode();
const ResXMLTree &mTree;
event_code_t mEventCode;
const ResXMLTree_node *mCurNode;
const void *mCurExt;
};
class ResStringPool
{
class ResStringPool {
public:
int32_t mError;
status_t mError;
void *mOwnedData;
const void *mHeader;
size_t mSize;
@ -96,13 +94,11 @@ public:
};
class ResXMLTree : public ResXMLParser
{
class ResXMLTree : public ResXMLParser {
public:
friend class ResXMLParser;
int32_t validateNode(const ResXMLTree_node* node) const;
void *mDynamicRefTable;
int32_t mError;
status_t mError;
void *mOwnedData;
const void *mHeader;
size_t mSize;
@ -115,14 +111,22 @@ public:
event_code_t mRootCode;
};
struct ResXMLTree_attrExt
{
struct ResStringPool_ref {
// Index into the string pool table (uint32_t-offset from the indices
// immediately after ResStringPool_header) at which to find the location
// of the string data in the pool.
uint32_t index;
};
struct ResXMLTree_attrExt {
// String of the full namespace of this element.
void* ns;
struct ResStringPool_ref ns;
// String name of this node if it is an ELEMENT; the raw
// character data if this is a CDATA node.
void* name;
struct ResStringPool_ref name;
// Byte offset from the start of this structure where the attributes start.
uint16_t attributeStart;
@ -145,8 +149,8 @@ struct ResXMLTree_attrExt
uint16_t styleIndex;
};
struct Res_value
{
struct Res_value {
// Number of bytes in this structure.
uint16_t size;
// Always set to 0.
@ -253,18 +257,17 @@ struct Res_value
// The data for this item, as interpreted according to dataType.
typedef uint32_t data_type;
data_type data;
void copyFrom_dtoh(const Res_value& src);
};
struct ResXMLTree_attribute
{
struct ResXMLTree_attribute {
// Namespace of this attribute.
void* ns;
struct ResStringPool_ref ns;
// Name of this attribute.
void* name;
struct ResStringPool_ref name;
// The original raw string value of this attribute.
void* rawValue;
struct ResStringPool_ref rawValue;
// Processesd typed value of this attribute.
struct Res_value typedValue;