Java Code Examples for pxb.android.axml.AxmlVisitor#TYPE_STRING
The following examples show how to use
pxb.android.axml.AxmlVisitor#TYPE_STRING .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessManifest.java From JAADAS with GNU General Public License v3.0 | 6 votes |
private void checkAndAddComponent(Set<String> entryPoints, AXmlNode node) { AXmlAttribute<?> attrEnabled = node.getAttribute("enabled"); if (attrEnabled == null || !attrEnabled.getValue().equals(Boolean.FALSE)) { AXmlAttribute<?> attr = node.getAttribute("name"); if (attr != null) entryPoints.add(expandClassName((String) attr.getValue())); else { // This component does not have a name, so this might be obfuscated // malware. We apply a heuristic. for (Entry<String, AXmlAttribute<?>> a : node.getAttributes().entrySet()) if (a.getValue().getName().isEmpty() && a.getValue().getType() == AxmlVisitor.TYPE_STRING) { String name = (String) a.getValue().getValue(); if (isValidComponentName(name)) entryPoints.add(expandClassName(name)); } } } }
Example 2
Source File: ProcessManifest.java From JAADAS with GNU General Public License v3.0 | 6 votes |
/** * Gets the permissions this application requests * @return The permissions requested by this application * @return */ public Set<String> getPermissions() { List<AXmlNode> usesPerms = this.manifest.getChildrenWithTag("uses-permission"); Set<String> permissions = new HashSet<String>(); for (AXmlNode perm : usesPerms) { AXmlAttribute<?> attr = perm.getAttribute("name"); if (attr != null) permissions.add((String) attr.getValue()); else { // The required "name" attribute is missing, so we collect all empty // attributes as a best-effort solution for broken malware apps for (AXmlAttribute<?> a : perm.getAttributes().values()) if (a.getType() == AxmlVisitor.TYPE_STRING && a.getName().isEmpty()) permissions.add((String) a.getValue()); } } return permissions; }
Example 3
Source File: ProcessManifest.java From DroidRA with GNU Lesser General Public License v2.1 | 6 votes |
private void checkAndAddComponent(Set<String> entryPoints, AXmlNode node) { AXmlAttribute<?> attrEnabled = node.getAttribute("enabled"); if (attrEnabled == null || !attrEnabled.getValue().equals(Boolean.FALSE)) { AXmlAttribute<?> attr = node.getAttribute("name"); if (attr != null) entryPoints.add(expandClassName((String) attr.getValue())); else { // This component does not have a name, so this might be obfuscated // malware. We apply a heuristic. for (Entry<String, AXmlAttribute<?>> a : node.getAttributes().entrySet()) if (a.getValue().getName().isEmpty() && a.getValue().getType() == AxmlVisitor.TYPE_STRING) { String name = (String) a.getValue().getValue(); if (isValidComponentName(name)) entryPoints.add(expandClassName(name)); } } } }
Example 4
Source File: ProcessManifest.java From DroidRA with GNU Lesser General Public License v2.1 | 6 votes |
/** * Gets the permissions this application requests * @return The permissions requested by this application * @return */ public Set<String> getPermissions() { List<AXmlNode> usesPerms = this.manifest.getChildrenWithTag("uses-permission"); Set<String> permissions = new HashSet<String>(); for (AXmlNode perm : usesPerms) { AXmlAttribute<?> attr = perm.getAttribute("name"); if (attr != null) permissions.add((String) attr.getValue()); else { // The required "name" attribute is missing, so we collect all empty // attributes as a best-effort solution for broken malware apps for (AXmlAttribute<?> a : perm.getAttributes().values()) if (a.getType() == AxmlVisitor.TYPE_STRING && a.getName().isEmpty()) permissions.add((String) a.getValue()); } } return permissions; }
Example 5
Source File: LayoutFileParser.java From LibScout with Apache License 2.0 | 5 votes |
@Override public void attr(String ns, String name, int resourceId, int type, Object obj) { String tname = name.trim(); if (tname.equals("id") && type == AxmlVisitor.TYPE_REFERENCE) this.id = (Integer) obj; else if ((tname.equals("name") || tname.equals("class") && type == AxmlVisitor.TYPE_STRING && obj instanceof String)) { String className = ((String) obj).trim(); if (className.startsWith(".")) { logger.debug("Fragment attr parser:: \"" + tname + "\" contains leading dot: " + className); className = className.substring(1); // TODO: sometimes the parser adds a leading "." } // weird we had sth. like "5apperfection.bluebox.ui.fragments.DeviceLinksFragment" although the file included the string "apperfection.bluebox.ui.fragments.DeviceLinksFragment" while (!className.substring(0, 1).matches("[a-zA-Z]")) { logger.debug("Fragment attr parser:: \"" + tname + "\" starts with a non-letter character!: " + className + " fixing.."); className = className.substring(1); } try { fragmentClazz = WalaUtils.lookupClass(cha, className); } catch (ClassNotFoundException e) { logger.warn("Could not lookup IClass for Fragment " + className); } } super.attr(ns, name, resourceId, type, obj); }
Example 6
Source File: LayoutFileParser.java From LibScout with Apache License 2.0 | 5 votes |
@Override public void attr(String ns, String name, int resourceId, int type, Object obj) { // Check that we're actually working on an android attribute if (!isAndroidNamespace(ns)) return; String tname = name.trim(); if (tname.equals("id") && type == AxmlVisitor.TYPE_REFERENCE) this.id = (Integer) obj; else if (tname.equals("password") && type == AxmlVisitor.TYPE_INT_BOOLEAN) isSensitive = ((Integer) obj) != 0; // -1 for true, 0 for false else if (!isSensitive && tname.equals("inputType") && type == AxmlVisitor.TYPE_INT_HEX) { int tp = (Integer) obj; isSensitive = ((tp & TYPE_NUMBER_VARIATION_PASSWORD) == TYPE_NUMBER_VARIATION_PASSWORD) || ((tp & TYPE_TEXT_VARIATION_PASSWORD) == TYPE_TEXT_VARIATION_PASSWORD) || ((tp & TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) || ((tp & TYPE_TEXT_VARIATION_WEB_PASSWORD) == TYPE_TEXT_VARIATION_WEB_PASSWORD); } else if (isActionListener(tname) && type == AxmlVisitor.TYPE_STRING && obj instanceof String) { String strData = ((String) obj).trim(); addCallbackMethod(layoutFile, strData); } else { if (type == AxmlVisitor.TYPE_STRING) logger.trace(Utils.INDENT + "Found unrecognized XML attribute: " + tname); } super.attr(ns, name, resourceId, type, obj); }
Example 7
Source File: LayoutFileParser.java From JAADAS with GNU General Public License v3.0 | 4 votes |
/** * Parses the layout file with the given root node * @param layoutFile The full path and file name of the file being parsed * @param rootNode The root node from where to start parsing */ private void parseLayoutNode(String layoutFile, AXmlNode rootNode) { if (rootNode.getTag() == null || rootNode.getTag().isEmpty()) { System.err.println("Encountered a null or empty node name " + "in file " + layoutFile + ", skipping node..."); return; } String tname = rootNode.getTag().trim(); if (tname.equals("dummy")) { // dummy root node, ignore it } // Check for inclusions else if (tname.equals("include")) { parseIncludeAttributes(layoutFile, rootNode); } // The "merge" tag merges the next hierarchy level into the current // one for flattening hierarchies. else if (tname.equals("merge")) { // do not consider any attributes of this elements, just // continue with the children } else if (tname.equals("fragment")) { final AXmlAttribute<?> attr = rootNode.getAttribute("name"); if (attr == null) System.err.println("Fragment without class name detected"); else { if (attr.getType() != AxmlVisitor.TYPE_STRING) System.err.println("Invalid targer resource "+attr.getValue()+"for fragment class value"); getLayoutClass(attr.getValue().toString()); } } else { final SootClass childClass = getLayoutClass(tname); if (childClass != null && (isLayoutClass(childClass) || isViewClass(childClass))) parseLayoutAttributes(layoutFile, childClass, rootNode); } // Parse the child nodes for (AXmlNode childNode : rootNode.getChildren()) parseLayoutNode(layoutFile, childNode); }
Example 8
Source File: LayoutFileParser.java From JAADAS with GNU General Public License v3.0 | 4 votes |
/** * Parses the layout attributes in the given AXml node * @param layoutFile The full path and file name of the file being parsed * @param layoutClass The class for the attributes are parsed * @param rootNode The AXml node containing the attributes */ private void parseLayoutAttributes(String layoutFile, SootClass layoutClass, AXmlNode rootNode) { boolean isSensitive = false; int id = -1; for (Entry<String, AXmlAttribute<?>> entry : rootNode.getAttributes().entrySet()) { String attrName = entry.getKey().trim(); AXmlAttribute<?> attr = entry.getValue(); // On obfuscated Android malware, the attribute name may be empty if (attrName.isEmpty()) continue; // Check that we're actually working on an android attribute if (!isAndroidNamespace(attr.getNamespace())) continue; // Read out the field data if (attrName.equals("id") && (attr.getType() == AxmlVisitor.TYPE_REFERENCE || attr.getType() == AxmlVisitor.TYPE_INT_HEX)) id = (Integer) attr.getValue(); else if (attrName.equals("password")) { if (attr.getType() == AxmlVisitor.TYPE_INT_HEX) isSensitive = ((Integer) attr.getValue()) != 0; // -1 for true, 0 for false else if (attr.getType() == AxmlVisitor.TYPE_INT_BOOLEAN) isSensitive = (Boolean) attr.getValue(); else throw new RuntimeException("Unknown representation of boolean data type"); } else if (!isSensitive && attrName.equals("inputType") && attr.getType() == AxmlVisitor.TYPE_INT_HEX) { int tp = (Integer) attr.getValue(); isSensitive = ((tp & TYPE_NUMBER_VARIATION_PASSWORD) == TYPE_NUMBER_VARIATION_PASSWORD) || ((tp & TYPE_TEXT_VARIATION_PASSWORD) == TYPE_TEXT_VARIATION_PASSWORD) || ((tp & TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) || ((tp & TYPE_TEXT_VARIATION_WEB_PASSWORD) == TYPE_TEXT_VARIATION_WEB_PASSWORD); } else if (isActionListener(attrName) && attr.getType() == AxmlVisitor.TYPE_STRING && attr.getValue() instanceof String) { String strData = ((String) attr.getValue()).trim(); addCallbackMethod(layoutFile, strData); } else if (attr.getType() == AxmlVisitor.TYPE_STRING && attrName.equals("text")) { // To avoid unrecognized attribute for "text" field } else if (DEBUG && attr.getType() == AxmlVisitor.TYPE_STRING) { System.out.println("Found unrecognized XML attribute: " + attrName); } } // Register the new user control addToMapSet(this.userControls, layoutFile, new LayoutControl(id, layoutClass, isSensitive)); }