diff --git a/apktool-cli/src/main/java/brut/apktool/Main.java b/apktool-cli/src/main/java/brut/apktool/Main.java index 9949e691..15c9cab1 100644 --- a/apktool-cli/src/main/java/brut/apktool/Main.java +++ b/apktool-cli/src/main/java/brut/apktool/Main.java @@ -18,6 +18,7 @@ package brut.apktool; import brut.androlib.*; import brut.androlib.err.CantFindFrameworkResException; +import brut.androlib.err.InFileNotFoundException; import brut.androlib.err.OutDirExistsException; import java.io.File; import java.io.IOException; @@ -122,6 +123,11 @@ public class Main { "Destination directory (" + outDir.getAbsolutePath() + ") " + "already exists. Use -f switch if you want to overwrite it."); System.exit(1); + } catch (InFileNotFoundException ex) { + System.out.println( + "Input file (" + args[i] + ") " + + "was not found or was not readable."); + System.exit(1); } catch (CantFindFrameworkResException ex) { System.out.println( "Can't find framework resources for package of id: " + diff --git a/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java b/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java index 83cb8d91..4c4587c5 100644 --- a/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java +++ b/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java @@ -16,6 +16,7 @@ package brut.androlib; +import brut.androlib.err.InFileNotFoundException; import brut.androlib.err.OutDirExistsException; import brut.androlib.res.AndrolibResources; import brut.androlib.res.data.ResPackage; @@ -64,6 +65,10 @@ public class ApkDecoder { throw new OutDirExistsException(); } + if (! mApkFile.isFile() || ! mApkFile.canRead() ) { + throw new InFileNotFoundException(); + } + try { OS.rmdir(outDir); } catch (BrutException ex) { diff --git a/apktool-lib/src/main/java/brut/androlib/err/InFileNotFoundException.java b/apktool-lib/src/main/java/brut/androlib/err/InFileNotFoundException.java new file mode 100644 index 00000000..af8de523 --- /dev/null +++ b/apktool-lib/src/main/java/brut/androlib/err/InFileNotFoundException.java @@ -0,0 +1,40 @@ +/** + * Copyright 2011 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. + */ + +package brut.androlib.err; + +import brut.androlib.AndrolibException; + +/** + * @author Ryszard Wiśniewski + */ +public class InFileNotFoundException extends AndrolibException { + + public InFileNotFoundException(Throwable cause) { + super(cause); + } + + public InFileNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public InFileNotFoundException(String message) { + super(message); + } + + public InFileNotFoundException() { + } +}