Class ARSCFileParser
java.lang.Object
soot.jimple.infoflow.android.resources.AbstractResourceParser
soot.jimple.infoflow.android.resources.ARSCFileParser
Parser for reading out the contents of Android's resource.arsc file.
Structure declarations and comments taken from the Android source code and
ported from C to Java.
- Author:
- Steven Arzt
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract base class for all Android resources.static classSpecial Android resource that contains an array of other resourcesstatic classAndroid resource containing an attribute resource identifier.static classAndroid resource containing boolean data.static classAndroid resource containing color data.static classAndroid resource containing complex map data.static enumEnumeration containing all dimension units available in Androidstatic classAndroid resource containing dimension data like "11pt".static classAndroid resource containing a single-precision floating point numberstatic classAndroid resource containing fraction data (e.g. element width relative to some other control).static enumEnumeration containing the types of fractions supported in Androidstatic classAndroid resource containing integer data.static classAndroid resource that does not contain any datastatic classAndroid resource containing a reference to another resource.protected static classRepresentation of a value in a resource, supplying type information.protected static classHeader that appears at the front of every data chunk in a resourcestatic classA configuration in an Android resource file.static classClass containing the data encoded in an Android resource IDstatic classprotected static classstatic classDescribes a particular resource configuration.protected static classThis is the beginning of information about an entry in the resource table.protected static classprotected static classA single name/value mapping that is part of a complex resource entry.protected static classExtended form of a ResTable_Entry for map entries, defining a parent map resource from which to inherit values.protected static classprotected static classA collection of resource entries for a particular resource data type.protected static classA specification of the resources defined by a particular type.static classA resource type in an Android resource file.static classAndroid resource containing string data. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final intLocalization of this resource is can be encouraged or required with an aapt flag if this is setprotected static final intprotected static final intFor integral attributes, this is the maximum value it can hold.protected static final intFor integral attributes, this is the minimum value it can hold.protected static final intprotected static final intprotected static final intprotected static final intThis entry holds the attribute's type code.protected static final intprotected static final intprotected static final intWhere the actual value is.protected static final intThe mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnnprotected static final intThe mantissa magnitude is 16 bits -- i.e, 0xnnnn.nnprotected static final intThe mantissa is an integral number -- i.e., 0xnnnnnn.0protected static final intThe mantissa magnitude is 8 bits -- i.e, 0xnn.nnnnprotected static final intprotected static final intWhere the radix information is, telling where the decimal place appears in the mantissa.protected static final intTYPE_DIMENSION: Value is Device Independent Pixels.protected static final intTYPE_FRACTION: A basic fraction of the overall size.protected static final intTYPE_FRACTION: A fraction of the parent size.protected static final intTYPE_DIMENSION: Value is in inches.protected static final intprotected static final intTYPE_DIMENSION: Value is in millimeters.protected static final intTYPE_DIMENSION: Value is in points.protected static final intTYPE_DIMENSION: Value is raw pixels.protected static final intWhere the unit type information is.protected static final intTYPE_DIMENSION: Value is a Scaled device independent Pixels.static final intIf set, this is a compact entry with data type and value directly encoded in the entry.static final intIf set, this is a complex entry, holding a set of name/value mappings.static final intIf set, the offsets to the entries are encoded in 16-bit,real_offset = offset * 4uAn 16-bit offset of 0xffffu means a NO_ENTRYARSCFileParser.ResTable_Type.flagsstatic final intIf set, this resource has been declared public, so libraries are allowed to reference it.static final intIf set, the entry is sparse, and encodes both the entry ID and offset into each entry, and a binary search is used to find the key.static final intIf set, this is a weak resource and may be overridden by strong resources of the same name/type.protected final org.slf4j.Loggerprotected static final floatprotected static final intprotected static final float[]protected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intstatic booleanIftrueany encountered resource format violation like reserved fields which should be zero but have a value will raise anRuntimeException.protected static final intThe 'data' holds an attribute resource identifier.protected static final intThe 'data' holds a complex number encoding a dimension value, such as "100in".protected static final intBeginning of color integer flavors...protected static final intBeginning of integer flavors...protected static final intThe 'data' holds a single-precision floating point number.protected static final intThe 'data' holds a complex number encoding a fraction of a container.protected static final intThe 'data' is either 0 or 1, for input "false" or "true" respectively.protected static final intThe 'data' is a raw integer value of the form #argb.protected static final intThe 'data' is a raw integer value of the form #aarrggbb.protected static final intThe 'data' is a raw integer value of the form #rgb.protected static final intThe 'data' is a raw integer value of the form #rrggbb.protected static final intThe 'data' is a raw integer value of the form n..n.protected static final intThe 'data' is a raw integer value of the form 0xn..n.protected static final int...end of integer flavors.protected static final int...end of integer flavors.protected static final intContains no dataprotected static final intThe 'data' holds a ResTable_ref, a reference to another resource table entry.protected static final intThe 'data' holds an index into the containing resource table's global value string pool.protected static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(ARSCFileParser otherParser) Adds all resources loaded from anotherARSCFileParserto this data objectprotected static floatcomplexToFloat(int complex) Taken from https://github.com/menethil/ApkTool/blob/master/src/android/util/TypedValue.javafindAllResources(int resourceId) Finds all resources with the given Android resource ID.findResource(int resourceId) Finds the resource with the given Android resource ID.findResourceByName(String type, String resourceName) Gets the resource with the given name and typefindResourcesByType(String type) Finds all resources that have the given typefindResourceType(int resourceId) Gets the resource type with the package and type specified in the given resource IDfindStringResource(String resourceName) Convenience method for loading a string resource with a given namestatic ARSCFileParsergetInstance(File apkFile) Creates a new instance of theARSCFileParserclass and parses the Android resource database in the given APK filegetPackage(int pkgID, String pkgName) protected booleanChecks whether the given complex map entry is one of the well-known attributes.voidParses the resource definition file in the given APKvoidparse(InputStream stream) parseResourceId(int resourceId) Parses an Android resource ID into its componentsprotected voidraiseFormatViolationIssue(String message, int offset) Methods inherited from class soot.jimple.infoflow.android.resources.AbstractResourceParser
handleAndroidResourceFiles
-
Field Details
-
STRICT_MODE
public static boolean STRICT_MODEIftrueany encountered resource format violation like reserved fields which should be zero but have a value will raise anRuntimeException. Iffalseformat violations will only be logged as errors. -
logger
protected final org.slf4j.Logger logger -
RES_STRING_POOL_TYPE
protected static final int RES_STRING_POOL_TYPE- See Also:
-
RES_TABLE_TYPE
protected static final int RES_TABLE_TYPE- See Also:
-
RES_TABLE_PACKAGE_TYPE
protected static final int RES_TABLE_PACKAGE_TYPE- See Also:
-
RES_TABLE_TYPE_SPEC_TYPE
protected static final int RES_TABLE_TYPE_SPEC_TYPE- See Also:
-
RES_TABLE_TYPE_TYPE
protected static final int RES_TABLE_TYPE_TYPE- See Also:
-
SORTED_FLAG
protected static final int SORTED_FLAG- See Also:
-
UTF8_FLAG
protected static final int UTF8_FLAG- See Also:
-
SPEC_PUBLIC
protected static final int SPEC_PUBLIC- See Also:
-
TYPE_NULL
protected static final int TYPE_NULLContains no data- See Also:
-
TYPE_REFERENCE
protected static final int TYPE_REFERENCEThe 'data' holds a ResTable_ref, a reference to another resource table entry.- See Also:
-
TYPE_ATTRIBUTE
protected static final int TYPE_ATTRIBUTEThe 'data' holds an attribute resource identifier.- See Also:
-
TYPE_STRING
protected static final int TYPE_STRINGThe 'data' holds an index into the containing resource table's global value string pool.- See Also:
-
TYPE_FLOAT
protected static final int TYPE_FLOATThe 'data' holds a single-precision floating point number.- See Also:
-
TYPE_DIMENSION
protected static final int TYPE_DIMENSIONThe 'data' holds a complex number encoding a dimension value, such as "100in".- See Also:
-
TYPE_FRACTION
protected static final int TYPE_FRACTIONThe 'data' holds a complex number encoding a fraction of a container.- See Also:
-
TYPE_FIRST_INT
protected static final int TYPE_FIRST_INTBeginning of integer flavors...- See Also:
-
TYPE_INT_DEC
protected static final int TYPE_INT_DECThe 'data' is a raw integer value of the form n..n.- See Also:
-
TYPE_INT_HEX
protected static final int TYPE_INT_HEXThe 'data' is a raw integer value of the form 0xn..n.- See Also:
-
TYPE_INT_BOOLEAN
protected static final int TYPE_INT_BOOLEANThe 'data' is either 0 or 1, for input "false" or "true" respectively.- See Also:
-
TYPE_FIRST_COLOR_INT
protected static final int TYPE_FIRST_COLOR_INTBeginning of color integer flavors...- See Also:
-
TYPE_INT_COLOR_ARGB8
protected static final int TYPE_INT_COLOR_ARGB8The 'data' is a raw integer value of the form #aarrggbb.- See Also:
-
TYPE_INT_COLOR_RGB8
protected static final int TYPE_INT_COLOR_RGB8The 'data' is a raw integer value of the form #rrggbb.- See Also:
-
TYPE_INT_COLOR_ARGB4
protected static final int TYPE_INT_COLOR_ARGB4The 'data' is a raw integer value of the form #argb.- See Also:
-
TYPE_INT_COLOR_RGB4
protected static final int TYPE_INT_COLOR_RGB4The 'data' is a raw integer value of the form #rgb.- See Also:
-
TYPE_LAST_COLOR_INT
protected static final int TYPE_LAST_COLOR_INT...end of integer flavors.- See Also:
-
TYPE_LAST_INT
protected static final int TYPE_LAST_INT...end of integer flavors.- See Also:
-
ATTR_TYPE
protected static final int ATTR_TYPEThis entry holds the attribute's type code.- See Also:
-
ATTR_MIN
protected static final int ATTR_MINFor integral attributes, this is the minimum value it can hold.- See Also:
-
ATTR_MAX
protected static final int ATTR_MAXFor integral attributes, this is the maximum value it can hold.- See Also:
-
ATTR_L10N
protected static final int ATTR_L10NLocalization of this resource is can be encouraged or required with an aapt flag if this is set- See Also:
-
ATTR_OTHER
protected static final int ATTR_OTHER- See Also:
-
ATTR_ZERO
protected static final int ATTR_ZERO- See Also:
-
ATTR_ONE
protected static final int ATTR_ONE- See Also:
-
ATTR_TWO
protected static final int ATTR_TWO- See Also:
-
ATTR_FEW
protected static final int ATTR_FEW- See Also:
-
ATTR_MANY
protected static final int ATTR_MANY- See Also:
-
NO_ENTRY
protected static final int NO_ENTRY- See Also:
-
COMPLEX_UNIT_SHIFT
protected static final int COMPLEX_UNIT_SHIFTWhere the unit type information is. This gives us 16 possible types, as defined below.- See Also:
-
COMPLEX_UNIT_MASK
protected static final int COMPLEX_UNIT_MASK- See Also:
-
COMPLEX_UNIT_PX
protected static final int COMPLEX_UNIT_PXTYPE_DIMENSION: Value is raw pixels.- See Also:
-
COMPLEX_UNIT_DIP
protected static final int COMPLEX_UNIT_DIPTYPE_DIMENSION: Value is Device Independent Pixels.- See Also:
-
COMPLEX_UNIT_SP
protected static final int COMPLEX_UNIT_SPTYPE_DIMENSION: Value is a Scaled device independent Pixels.- See Also:
-
COMPLEX_UNIT_PT
protected static final int COMPLEX_UNIT_PTTYPE_DIMENSION: Value is in points.- See Also:
-
COMPLEX_UNIT_IN
protected static final int COMPLEX_UNIT_INTYPE_DIMENSION: Value is in inches.- See Also:
-
COMPLEX_UNIT_MM
protected static final int COMPLEX_UNIT_MMTYPE_DIMENSION: Value is in millimeters.- See Also:
-
COMPLEX_UNIT_FRACTION
protected static final int COMPLEX_UNIT_FRACTIONTYPE_FRACTION: A basic fraction of the overall size.- See Also:
-
COMPLEX_UNIT_FRACTION_PARENT
protected static final int COMPLEX_UNIT_FRACTION_PARENTTYPE_FRACTION: A fraction of the parent size.- See Also:
-
COMPLEX_RADIX_SHIFT
protected static final int COMPLEX_RADIX_SHIFTWhere the radix information is, telling where the decimal place appears in the mantissa. This give us 4 possible fixed point representations as defined below.- See Also:
-
COMPLEX_RADIX_MASK
protected static final int COMPLEX_RADIX_MASK- See Also:
-
COMPLEX_RADIX_23p0
protected static final int COMPLEX_RADIX_23p0The mantissa is an integral number -- i.e., 0xnnnnnn.0- See Also:
-
COMPLEX_RADIX_16p7
protected static final int COMPLEX_RADIX_16p7The mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn- See Also:
-
COMPLEX_RADIX_8p15
protected static final int COMPLEX_RADIX_8p15The mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn- See Also:
-
COMPLEX_RADIX_0p23
protected static final int COMPLEX_RADIX_0p23The mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn- See Also:
-
COMPLEX_MANTISSA_SHIFT
protected static final int COMPLEX_MANTISSA_SHIFTWhere the actual value is. This gives us 23 bits of precision. The top bit is the sign.- See Also:
-
COMPLEX_MANTISSA_MASK
protected static final int COMPLEX_MANTISSA_MASK- See Also:
-
MANTISSA_MULT
protected static final float MANTISSA_MULT- See Also:
-
RADIX_MULTS
protected static final float[] RADIX_MULTS -
FLAG_COMPLEX
public static final int FLAG_COMPLEXIf set, this is a complex entry, holding a set of name/value mappings. It is followed by an array of ResTable_Map structures.- See Also:
-
FLAG_PUBLIC
public static final int FLAG_PUBLICIf set, this resource has been declared public, so libraries are allowed to reference it.- See Also:
-
FLAG_WEAK
public static final int FLAG_WEAKIf set, this is a weak resource and may be overridden by strong resources of the same name/type. This is only useful during linking with other resource tables.- See Also:
-
FLAG_COMPACT
public static final int FLAG_COMPACTIf set, this is a compact entry with data type and value directly encoded in the entry.- See Also:
-
FLAG_SPARSE
public static final int FLAG_SPARSEIf set, the entry is sparse, and encodes both the entry ID and offset into each entry, and a binary search is used to find the key. Only available on platforms >= O. Mark any types that use this with a v26 qualifier to prevent runtime issues on older platforms.ARSCFileParser.ResTable_Type.flags- See Also:
-
FLAG_OFFSET16
public static final int FLAG_OFFSET16If set, the offsets to the entries are encoded in 16-bit,real_offset = offset * 4uAn 16-bit offset of 0xffffu means a NO_ENTRYARSCFileParser.ResTable_Type.flags- See Also:
-
-
Constructor Details
-
ARSCFileParser
public ARSCFileParser()
-
-
Method Details
-
parse
Parses the resource definition file in the given APK- Parameters:
apkFile- The APK file in which to parse the resource definition file- Throws:
IOException- Thrown if the given APK file cannot be opened
-
parse
- Throws:
IOException
-
isAttribute
Checks whether the given complex map entry is one of the well-known attributes.- Parameters:
map- The map entry to check- Returns:
- True if the given entry is one of the well-known attributes, otherwise false.
-
complexToFloat
protected static float complexToFloat(int complex) Taken from https://github.com/menethil/ApkTool/blob/master/src/android/util/TypedValue.java- Parameters:
complex-- Returns:
-
getGlobalStringPool
-
getPackages
-
getPackage
-
findResource
Finds the resource with the given Android resource ID. This method is configuration-agnostic and simply returns the first match it finds.- Parameters:
resourceId- The Android resource ID for which to the find the resource object- Returns:
- The resource object with the given Android resource ID if it has been found, otherwise null.
-
findAllResources
Finds all resources with the given Android resource ID. This method returns all matching resources, regardless of their respective configuration.- Parameters:
resourceId- The Android resource ID for which to the find the resource object- Returns:
- The resource object with the given Android resource ID if it has been found, otherwise null.
-
findResourceType
Gets the resource type with the package and type specified in the given resource ID- Parameters:
resourceId- The resource ID- Returns:
- The resource type with the given type and package ID, or null if no such type exists
-
parseResourceId
Parses an Android resource ID into its components- Parameters:
resourceId- The numeric resource ID to parse- Returns:
- The data contained in the given Android resource ID
-
findResourceByName
Gets the resource with the given name and type- Parameters:
type- The type of the resource to retrieve, e.g., "string"resourceName- The name of the resource to retrieve- Returns:
- The resource with the given name and type if such a resource exists, null otherwise
-
findStringResource
Convenience method for loading a string resource with a given name- Parameters:
resourceName- The name of the resource to locate- Returns:
- The string contents of the resource with the given name, if such a resource exists and is of type "string", null otherwise
-
findResourcesByType
Finds all resources that have the given type- Parameters:
type- The resource type to look for- Returns:
- All resources of the given type
-
getInstance
Creates a new instance of theARSCFileParserclass and parses the Android resource database in the given APK file- Parameters:
apkFile- The APK file in which to parse the resource database- Returns:
- The new
ARSCFileParserinstance, ornullif the file could not be read - Throws:
IOException
-
addAll
Adds all resources loaded from anotherARSCFileParserto this data object- Parameters:
otherParser- The other parser
-
raiseFormatViolationIssue
-