Correct resources types' offsets
This commit is contained in:
parent
8a2cdbe47e
commit
6e6327bec8
|
|
@ -97,15 +97,17 @@ jboolean XposedBridge_initXResourcesNative(JNIEnv *env, jclass) {
|
||||||
|
|
||||||
void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
|
void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
|
||||||
jlong parserPtr, jobject origRes, jobject repRes) {
|
jlong parserPtr, jobject origRes, jobject repRes) {
|
||||||
|
|
||||||
ResXMLParser *parser = (ResXMLParser *) parserPtr;
|
ResXMLParser *parser = (ResXMLParser *) parserPtr;
|
||||||
|
|
||||||
|
if (parser == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
const ResXMLTree &mTree = parser->mTree;
|
const ResXMLTree &mTree = parser->mTree;
|
||||||
uint32_t *mResIds = (uint32_t *) mTree.mResIds;
|
uint32_t *mResIds = (uint32_t *) mTree.mResIds;
|
||||||
ResXMLTree_attrExt *tag;
|
ResXMLTree_attrExt *tag;
|
||||||
int attrCount;
|
int attrCount;
|
||||||
|
|
||||||
if (parser == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
switch (ResXMLParser_next(parser)) {
|
switch (ResXMLParser_next(parser)) {
|
||||||
case ResXMLParser::START_TAG:
|
case ResXMLParser::START_TAG:
|
||||||
|
|
@ -120,11 +122,16 @@ void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
|
||||||
// find resource IDs for attribute names
|
// find resource IDs for attribute names
|
||||||
int32_t attrNameID = ResXMLParser_getAttributeNameID(parser, idx);
|
int32_t attrNameID = ResXMLParser_getAttributeNameID(parser, idx);
|
||||||
// only replace attribute name IDs for app packages
|
// 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;
|
size_t attNameLen;
|
||||||
const char16_t* attrName = ResStringPool_stringAt(&(mTree.mStrings), attrNameID, &attNameLen);
|
const char16_t *attrName = ResStringPool_stringAt(&(mTree.mStrings),
|
||||||
jint attrResID = env->CallStaticIntMethod(classXResources, methodXResourcesTranslateAttrId,
|
attrNameID, &attNameLen);
|
||||||
env->NewString((const jchar*)attrName, attNameLen), origRes);
|
jint attrResID = env->CallStaticIntMethod(classXResources,
|
||||||
|
methodXResourcesTranslateAttrId,
|
||||||
|
env->NewString(
|
||||||
|
(const jchar *) attrName,
|
||||||
|
attNameLen), origRes);
|
||||||
if (env->ExceptionCheck())
|
if (env->ExceptionCheck())
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
|
|
@ -139,7 +146,8 @@ void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
|
||||||
if (oldValue < 0x7f000000)
|
if (oldValue < 0x7f000000)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
jint newValue = env->CallStaticIntMethod(classXResources, methodXResourcesTranslateResId,
|
jint newValue = env->CallStaticIntMethod(classXResources,
|
||||||
|
methodXResourcesTranslateResId,
|
||||||
oldValue, origRes, repRes);
|
oldValue, origRes, repRes);
|
||||||
if (env->ExceptionCheck())
|
if (env->ExceptionCheck())
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,12 @@ static constexpr const char *kLibFwPath = "/system/lib/libandroidfw.so";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
jboolean XposedBridge_initXResourcesNative(JNIEnv *env, jclass);
|
jboolean XposedBridge_initXResourcesNative(JNIEnv *env, jclass);
|
||||||
|
|
||||||
void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
|
void XResources_rewriteXmlReferencesNative(JNIEnv *env, jclass,
|
||||||
jlong parserPtr, jobject origRes, jobject repRes);
|
jlong parserPtr, jobject origRes, jobject repRes);
|
||||||
|
|
||||||
|
typedef int32_t status_t;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
RES_NULL_TYPE = 0x0000,
|
RES_NULL_TYPE = 0x0000,
|
||||||
RES_STRING_POOL_TYPE = 0x0001,
|
RES_STRING_POOL_TYPE = 0x0001,
|
||||||
|
|
@ -40,8 +43,7 @@ enum {
|
||||||
RES_TABLE_LIBRARY_TYPE = 0x0203
|
RES_TABLE_LIBRARY_TYPE = 0x0203
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ResXMLTree_node
|
struct ResXMLTree_node {
|
||||||
{
|
|
||||||
void *header;
|
void *header;
|
||||||
// Line number in original source file at which this element appeared.
|
// Line number in original source file at which this element appeared.
|
||||||
uint32_t lineNumber;
|
uint32_t lineNumber;
|
||||||
|
|
@ -51,8 +53,8 @@ struct ResXMLTree_node
|
||||||
|
|
||||||
class ResXMLTree;
|
class ResXMLTree;
|
||||||
|
|
||||||
class ResXMLParser
|
class ResXMLParser {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
enum event_code_t {
|
enum event_code_t {
|
||||||
BAD_DOCUMENT = -1,
|
BAD_DOCUMENT = -1,
|
||||||
|
|
@ -68,20 +70,16 @@ public:
|
||||||
TEXT = RES_XML_CDATA_TYPE
|
TEXT = RES_XML_CDATA_TYPE
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
|
||||||
friend class ResXMLTree;
|
|
||||||
|
|
||||||
event_code_t nextNode();
|
|
||||||
const ResXMLTree &mTree;
|
const ResXMLTree &mTree;
|
||||||
event_code_t mEventCode;
|
event_code_t mEventCode;
|
||||||
const ResXMLTree_node *mCurNode;
|
const ResXMLTree_node *mCurNode;
|
||||||
const void *mCurExt;
|
const void *mCurExt;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResStringPool
|
class ResStringPool {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
int32_t mError;
|
status_t mError;
|
||||||
void *mOwnedData;
|
void *mOwnedData;
|
||||||
const void *mHeader;
|
const void *mHeader;
|
||||||
size_t mSize;
|
size_t mSize;
|
||||||
|
|
@ -96,13 +94,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ResXMLTree : public ResXMLParser
|
class ResXMLTree : public ResXMLParser {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
friend class ResXMLParser;
|
|
||||||
int32_t validateNode(const ResXMLTree_node* node) const;
|
|
||||||
void *mDynamicRefTable;
|
void *mDynamicRefTable;
|
||||||
int32_t mError;
|
status_t mError;
|
||||||
void *mOwnedData;
|
void *mOwnedData;
|
||||||
const void *mHeader;
|
const void *mHeader;
|
||||||
size_t mSize;
|
size_t mSize;
|
||||||
|
|
@ -115,14 +111,22 @@ public:
|
||||||
event_code_t mRootCode;
|
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.
|
// 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
|
// String name of this node if it is an ELEMENT; the raw
|
||||||
// character data if this is a CDATA node.
|
// 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.
|
// Byte offset from the start of this structure where the attributes start.
|
||||||
uint16_t attributeStart;
|
uint16_t attributeStart;
|
||||||
|
|
@ -145,8 +149,8 @@ struct ResXMLTree_attrExt
|
||||||
uint16_t styleIndex;
|
uint16_t styleIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Res_value
|
struct Res_value {
|
||||||
{
|
|
||||||
// Number of bytes in this structure.
|
// Number of bytes in this structure.
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
// Always set to 0.
|
// Always set to 0.
|
||||||
|
|
@ -253,18 +257,17 @@ struct Res_value
|
||||||
// The data for this item, as interpreted according to dataType.
|
// The data for this item, as interpreted according to dataType.
|
||||||
typedef uint32_t data_type;
|
typedef uint32_t data_type;
|
||||||
data_type data;
|
data_type data;
|
||||||
void copyFrom_dtoh(const Res_value& src);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ResXMLTree_attribute
|
struct ResXMLTree_attribute {
|
||||||
{
|
|
||||||
// Namespace of this attribute.
|
// Namespace of this attribute.
|
||||||
void* ns;
|
struct ResStringPool_ref ns;
|
||||||
|
|
||||||
// Name of this attribute.
|
// Name of this attribute.
|
||||||
void* name;
|
struct ResStringPool_ref name;
|
||||||
|
|
||||||
// The original raw string value of this attribute.
|
// The original raw string value of this attribute.
|
||||||
void* rawValue;
|
struct ResStringPool_ref rawValue;
|
||||||
|
|
||||||
// Processesd typed value of this attribute.
|
// Processesd typed value of this attribute.
|
||||||
struct Res_value typedValue;
|
struct Res_value typedValue;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue