dump.java revision 8f8b67f65ec3390e92cce7d710e5b1eaabd4e248
14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/* 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * [The "BSD licence"] 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (c) 2010 Ben Gruver (JesusFreke) 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * All rights reserved. 54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * 64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * modification, are permitted provided that the following conditions 81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * are met: 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 1303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * documentation and/or other materials provided with the distribution. 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 3. The name of the author may not be used to endorse or promote products 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * derived from this software without specific prior written permission. 1603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29package org.jf.baksmali; 30 31import org.jf.dexlib2.dexbacked.DexBackedDexFile; 32import org.jf.dexlib2.dexbacked.raw.RawDexFile; 33import org.jf.dexlib2.dexbacked.raw.util.DexAnnotator; 34import org.jf.util.ConsoleUtil; 35 36import java.io.BufferedWriter; 37import java.io.FileWriter; 38import java.io.IOException; 39import java.io.Writer; 40 41public class dump { 42 public static void dump(DexBackedDexFile dexFile, String dumpFileName) 43 throws IOException { 44 45 if (dumpFileName != null) { 46 Writer writer = null; 47 48 try { 49 writer = new BufferedWriter(new FileWriter(dumpFileName)); 50 51 int consoleWidth = ConsoleUtil.getConsoleWidth(); 52 if (consoleWidth <= 0) { 53 consoleWidth = 120; 54 } 55 56 RawDexFile rawDexFile = new RawDexFile(dexFile); 57 DexAnnotator annotator = new DexAnnotator(rawDexFile, consoleWidth); 58 annotator.writeAnnotations(writer); 59 } catch (IOException ex) { 60 System.err.println("There was an error while dumping the dex file to " + dumpFileName); 61 ex.printStackTrace(System.err); 62 } finally { 63 if (writer != null) { 64 try { 65 writer.close(); 66 } catch (IOException ex) { 67 System.err.println("There was an error while closing the dump file " + dumpFileName); 68 ex.printStackTrace(System.err); 69 } 70 } 71 } 72 } 73 } 74} 75