1 /* 2 * Copyright 2016, Google Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * * Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following disclaimer 13 * in the documentation and/or other materials provided with the 14 * distribution. 15 * * Neither the name of Google Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 package org.jf.baksmali; 33 34 import com.beust.jcommander.JCommander; 35 import com.beust.jcommander.Parameter; 36 import com.beust.jcommander.Parameters; 37 import com.beust.jcommander.ParametersDelegate; 38 import org.jf.baksmali.AnalysisArguments.CheckPackagePrivateArgument; 39 import org.jf.dexlib2.analysis.CustomInlineMethodResolver; 40 import org.jf.dexlib2.analysis.InlineMethodResolver; 41 import org.jf.dexlib2.dexbacked.DexBackedOdexFile; 42 import org.jf.util.jcommander.ExtendedParameter; 43 import org.jf.util.jcommander.ExtendedParameters; 44 45 import javax.annotation.Nonnull; 46 import java.io.File; 47 import java.io.IOException; 48 import java.util.List; 49 50 @Parameters(commandDescription = "Deodexes an odex/oat file") 51 @ExtendedParameters( 52 commandName = "deodex", 53 commandAliases = { "de", "x" }) 54 public class DeodexCommand extends DisassembleCommand { 55 56 @ParametersDelegate 57 protected CheckPackagePrivateArgument checkPackagePrivateArgument = new CheckPackagePrivateArgument(); 58 59 @Parameter(names = {"--inline-table", "--inline", "--it"}, 60 description = "Specify a file containing a custom inline method table to use. See the " + 61 "\"deodexerant\" tool in the smali github repository to dump the inline method table from a " + 62 "device that uses dalvik.") 63 @ExtendedParameter(argumentNames = "file") 64 private String inlineTable; 65 DeodexCommand(@onnull List<JCommander> commandAncestors)66 public DeodexCommand(@Nonnull List<JCommander> commandAncestors) { 67 super(commandAncestors); 68 } 69 getOptions()70 @Override protected BaksmaliOptions getOptions() { 71 BaksmaliOptions options = super.getOptions(); 72 73 options.deodex = true; 74 75 if (dexFile instanceof DexBackedOdexFile) { 76 if (inlineTable == null) { 77 options.inlineResolver = InlineMethodResolver.createInlineMethodResolver( 78 ((DexBackedOdexFile)dexFile).getOdexVersion()); 79 } else { 80 File inlineTableFile = new File(inlineTable); 81 if (!inlineTableFile.exists()) { 82 System.err.println(String.format("Could not find file: %s", inlineTable)); 83 System.exit(-1); 84 } 85 try { 86 options.inlineResolver = new CustomInlineMethodResolver(options.classPath, inlineTableFile); 87 } catch (IOException ex) { 88 System.err.println(String.format("Error while reading file: %s", inlineTableFile)); 89 ex.printStackTrace(System.err); 90 System.exit(-1); 91 } 92 } 93 } 94 95 return options; 96 } 97 shouldCheckPackagePrivateAccess()98 @Override protected boolean shouldCheckPackagePrivateAccess() { 99 return checkPackagePrivateArgument.checkPackagePrivateAccess; 100 } 101 needsClassPath()102 @Override protected boolean needsClassPath() { 103 return true; 104 } 105 showDeodexWarning()106 @Override protected boolean showDeodexWarning() { 107 return false; 108 } 109 } 110