From 9234017707da1768a9e6d7b6b33132606fb52ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Thu, 1 Apr 2010 17:38:30 +0200 Subject: [PATCH] Added support for framework apks. --- src/brut/androlib/Androlib.java | 2 +- src/brut/androlib/res/AndrolibResources.java | 21 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/brut/androlib/Androlib.java b/src/brut/androlib/Androlib.java index 9ff8a6a7..3aee9093 100644 --- a/src/brut/androlib/Androlib.java +++ b/src/brut/androlib/Androlib.java @@ -214,7 +214,7 @@ public class Androlib { apkFile, new File(appDir, "AndroidManifest.xml"), new File(appDir, "res"), ninePatch, null, false, - false + mAndRes.detectWhetherAppIsFramework(appDir) ); new ExtFile(apkFile).getDirectory() diff --git a/src/brut/androlib/res/AndrolibResources.java b/src/brut/androlib/res/AndrolibResources.java index 4e03437e..19eeb5d3 100644 --- a/src/brut/androlib/res/AndrolibResources.java +++ b/src/brut/androlib/res/AndrolibResources.java @@ -29,7 +29,9 @@ import brut.directory.*; import brut.util.*; import java.io.*; import java.util.Arrays; +import java.util.Iterator; import java.util.logging.Logger; +import org.apache.commons.io.IOUtils; import org.xmlpull.v1.XmlSerializer; /** @@ -38,8 +40,10 @@ import org.xmlpull.v1.XmlSerializer; final public class AndrolibResources { public ResTable getResTable(ExtFile apkFile) throws AndrolibException { ResTable resTable = new ResTable(); - decodeArsc(resTable, new ExtFile(getAndroidResourcesFile()), false); decodeArsc(resTable, apkFile, true); + if (! resTable.hasPackage(1)) { + decodeArsc(resTable, new ExtFile(getAndroidResourcesFile()), false); + } return resTable; } @@ -123,6 +127,21 @@ final public class AndrolibResources { } } + public boolean detectWhetherAppIsFramework(File appDir) + throws AndrolibException { + Iterator it; + try { + it = IOUtils.lineIterator( + new FileReader(new File(appDir, "res/values/public.xml"))); + } catch (FileNotFoundException ex) { + throw new AndrolibException( + "Could not detect whether app is framework one", ex); + } + it.next(); + it.next(); + return it.next().contains("0x01"); + } + public void tagSmaliResIDs(ResTable resTable, File smaliDir) throws AndrolibException { new ResSmaliUpdater().tagResIDs(resTable, smaliDir);