diff --git a/src/brut/androlib/Androlib.java b/src/brut/androlib/Androlib.java index f4400a3e..82f90eed 100644 --- a/src/brut/androlib/Androlib.java +++ b/src/brut/androlib/Androlib.java @@ -17,6 +17,7 @@ package brut.androlib; +import brut.androlib.java.AndrolibJava; import brut.androlib.res.AndrolibResources; import brut.androlib.res.data.ResTable; import brut.androlib.res.util.ExtFile; @@ -65,6 +66,12 @@ public class Androlib { } } + public void decodeSourcesJava(ExtFile apkFile, File outDir) + throws AndrolibException { + LOGGER.info("Decoding Java sources..."); + new AndrolibJava().decode(apkFile, outDir); + } + public void decodeResourcesRaw(ExtFile apkFile, File outDir) throws AndrolibException { try { @@ -120,7 +127,9 @@ public class Androlib { public void buildSources(File appDir, boolean forceBuildAll) throws AndrolibException { if (! buildSourcesRaw(appDir, forceBuildAll) - && ! buildSourcesSmali(appDir, forceBuildAll)) { + && ! buildSourcesSmali(appDir, forceBuildAll) + && ! buildSourcesJava(appDir, forceBuildAll) + ) { LOGGER.warning("Could not find sources"); } } @@ -162,6 +171,24 @@ public class Androlib { return true; } + public boolean buildSourcesJava(File appDir, boolean forceBuildAll) + throws AndrolibException { + File javaDir = new File(appDir, "src"); + if (! javaDir.exists()) { + return false; + } + File dex = new File(appDir, APK_DIRNAME + "/classes.dex"); + if (! forceBuildAll) { + LOGGER.info("Checking whether sources has changed..."); + } + if (forceBuildAll || isModified(javaDir, dex)) { + LOGGER.info("Building java sources..."); + dex.delete(); + new AndrolibJava().build(javaDir, dex); + } + return true; + } + public void buildResources(ExtFile appDir, boolean forceBuildAll, boolean framework) throws AndrolibException { if (! buildResourcesRaw(appDir, forceBuildAll) diff --git a/src/brut/androlib/ApkDecoder.java b/src/brut/androlib/ApkDecoder.java index e2b64bfb..c521d1e6 100644 --- a/src/brut/androlib/ApkDecoder.java +++ b/src/brut/androlib/ApkDecoder.java @@ -68,6 +68,9 @@ public class ApkDecoder { case DECODE_SOURCES_SMALI: mAndrolib.decodeSourcesSmali(mApkFile, outDir); break; + case DECODE_SOURCES_JAVA: + mAndrolib.decodeSourcesJava(mApkFile, outDir); + break; } switch (mDecodeResources) { case DECODE_RESOURCES_NONE: @@ -81,7 +84,8 @@ public class ApkDecoder { } public void setDecodeSources(short mode) throws AndrolibException { - if (mode != DECODE_SOURCES_NONE && mode != DECODE_SOURCES_SMALI) { + if (mode != DECODE_SOURCES_NONE && mode != DECODE_SOURCES_SMALI + && mode != DECODE_SOURCES_JAVA) { throw new AndrolibException("Invalid decode sources mode: " + mode); } mDecodeSources = mode; @@ -104,6 +108,7 @@ public class ApkDecoder { public final static short DECODE_SOURCES_NONE = 0x0000; public final static short DECODE_SOURCES_SMALI = 0x0001; + public final static short DECODE_SOURCES_JAVA = 0x0002; public final static short DECODE_RESOURCES_NONE = 0x0100; public final static short DECODE_RESOURCES_FULL = 0x0101; diff --git a/src/brut/androlib/java/AndrolibJava.java b/src/brut/androlib/java/AndrolibJava.java new file mode 100644 index 00000000..16dbfd0d --- /dev/null +++ b/src/brut/androlib/java/AndrolibJava.java @@ -0,0 +1,34 @@ +/* + * Copyright 2010 Ryszard Wiśniewski . + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * under the License. + */ +package brut.androlib.java; + +import brut.androlib.res.util.ExtFile; +import java.io.File; + +/** + * @author Ryszard Wiśniewski + */ +public class AndrolibJava { + + public void decode(ExtFile apkFile, File outDir) { + throw new UnsupportedOperationException("Not yet implemented"); + } + + public void build(File javaDir, File dex) { + throw new UnsupportedOperationException("Not yet implemented"); + } +}