// Path: src/main/java/org/cf/resequencer/Console.java
// public class Console {
//     private static final boolean StackTrace = false;
//     public static int VerboseLevel;
//     public static String LogFile = "console.log";
// 
//     public static void msgln() {
//         System.out.println();
//     }
// 
//     public static void msgln(final String msg) {
//         System.out.println(msg);
//     }
// 
//     public static void msg(final String msg) {
//         System.out.print(msg);
//     }
// 
//     public static void debug(final String msg) {
//         if (VerboseLevel > 0) {
//             System.out.println(msg);
//         }
//     }
// 
//     public static void debug(final String msg, final int verboseLevel) {
//         if (verboseLevel <= VerboseLevel) {
//             debug(msg);
//         }
//     }
// 
//     public static void warn(final String msg) {
//         System.err.println("Warning: " + msg);
//         if (StackTrace) {
//             Thread.dumpStack();
//         }
//     }
// 
//     public static void error(final String msg) {
//         System.err.println("Error: " + msg);
//         if (StackTrace) {
//             Thread.dumpStack();
//         }
//     }
// 
//     public static void die(final Exception ex) {
//         die(ex, -1);
//     }
// 
//     public static void die(final Exception ex, final int exitStatus) {
//         if (StackTrace) {
//             ex.printStackTrace();
//         }
//         System.err.println("" + ex);
//         System.exit(exitStatus);
//     }
// 
//     public static void die(final String msg) {
//         die(msg, -1);
//     }
// 
//     public static void die(final String msg, int exitStatus) {
//         System.err.println("Fatal error: " + msg);
//         if (StackTrace) {
//             Thread.dumpStack();
//         }
//         System.exit(exitStatus);
//     }
// 
//     // run command and return {result, exit status}
//     public static String[] execute(String[] cmd) {
//         debug("Executing: " + Arrays.asList(cmd).toString());
// 
//         StringBuffer output = new StringBuffer();
//         Integer status = null;
// 
//         InputStream in = null;
//         try {
//             Process child = Runtime.getRuntime().exec(cmd);
// 
//             BufferedReader stdInput = new BufferedReader(new InputStreamReader(child.getInputStream()));
// 
//             String s;
//             while ((s = stdInput.readLine()) != null) {
//                 output.append(s).append('\n');
//             }
// 
//             status = child.waitFor();
// 
//             debug("Exit status: " + status, 2);
//         } catch (Exception ex) {
//             error("Run command failed.\n" + ex);
//         } finally {
//             IOUtils.closeQuietly(in);
//         }
// 
//         return new String[] { output.toString(), String.valueOf(status) };
//     }
// 
//     public static boolean deleteBestEffort(File path, String whatIsIt) {
//         return deleteBestEffort(path, whatIsIt, 3, false);
//     }
// 
//     public static boolean deleteBestEffort(File path, String whatIsIt, int maxTries) {
//         return deleteBestEffort(path, whatIsIt, maxTries, false);
//     }
// 
//     public static boolean deleteBestEffort(File path, String whatIsIt, int maxTries, boolean quiet) {
//         System.gc();
// 
//         int tries = 0;
//         while (!FileUtils.deleteQuietly(path) && (tries < maxTries)) {
//             System.gc();
//             tries++;
// 
//             if (!quiet) {
//                 warn("Unable to delete " + whatIsIt + ": " + path + ". Trying again ...");
//             }
// 
//             try {
//                 Thread.sleep(3000);
//             } catch (InterruptedException ex) {
//             }
//         }
// 
//         return !path.exists();
//     }
// }


import java.io.File;
import java.io.IOException;
import java.security.DigestException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Random;
import java.util.zip.Adler32;
import org.apache.commons.io.FileUtils;
import org.cf.resequencer.Console;
package org.cf.resequencer.sequence;



/**
 * 
 * @author Caleb Fenton
 */
public class DexFile {

    private static final int OFF_LINK_SIZE = 44;
    private static final int OFF_LINK_OFF = 48;
    private static final int INT_SIZE = 4;

    private static final byte[] InvalidRef = new byte[] { 0x4e, 0x01, 0x01, 0x01, 0x00, 0x00 // aput-bool p0, p0, p0;
                                                                                             // nop
    };

    private byte[] DexBytes;
    protected File DexFile;

    DexFile(File dexFile) throws IOException {
        DexFile = dexFile;
        DexBytes = FileUtils.readFileToByteArray(dexFile);
    }

    /*
     * Do whatever we can to the dex file to prevent decompilers from working.
     */
    public void dexLock() {
        /*
         * byte[] header = new byte[0x70]; System.arraycopy(DexBytes, 0, header, 0, 0x70);
         * System.out.println(StringUtils.toHexString(header)); for ( int i = 0; i < header.length; i++ ) {
         * System.out.print(header[i] + " "); }
         * 
         * for ( int i = 0; i < 0x70; i++ ) { System.out.print(DexBytes[i] +" "); } System.exit(0);
         */

        Random rng = new Random();
        byte[] val = new byte[4];

        // 40-43 = endian tag (ignore for now)

        System.arraycopy(DexBytes, OFF_LINK_SIZE, val, 0, INT_SIZE);
// Path: src/main/java/org/cf/resequencer/Console.java
// public class Console {
//     private static final boolean StackTrace = false;
//     public static int VerboseLevel;
//     public static String LogFile = "console.log";
// 
//     public static void msgln() {
//         System.out.println();
//     }
// 
//     public static void msgln(final String msg) {
//         System.out.println(msg);
//     }
// 
//     public static void msg(final String msg) {
//         System.out.print(msg);
//     }
// 
//     public static void debug(final String msg) {
//         if (VerboseLevel > 0) {
//             System.out.println(msg);
//         }
//     }
// 
//     public static void debug(final String msg, final int verboseLevel) {
//         if (verboseLevel <= VerboseLevel) {
//             debug(msg);
//         }
//     }
// 
//     public static void warn(final String msg) {
//         System.err.println("Warning: " + msg);
//         if (StackTrace) {
//             Thread.dumpStack();
//         }
//     }
// 
//     public static void error(final String msg) {
//         System.err.println("Error: " + msg);
//         if (StackTrace) {
//             Thread.dumpStack();
//         }
//     }
// 
//     public static void die(final Exception ex) {
//         die(ex, -1);
//     }
// 
//     public static void die(final Exception ex, final int exitStatus) {
//         if (StackTrace) {
//             ex.printStackTrace();
//         }
//         System.err.println("" + ex);
//         System.exit(exitStatus);
//     }
// 
//     public static void die(final String msg) {
//         die(msg, -1);
//     }
// 
//     public static void die(final String msg, int exitStatus) {
//         System.err.println("Fatal error: " + msg);
//         if (StackTrace) {
//             Thread.dumpStack();
//         }
//         System.exit(exitStatus);
//     }
// 
//     // run command and return {result, exit status}
//     public static String[] execute(String[] cmd) {
//         debug("Executing: " + Arrays.asList(cmd).toString());
// 
//         StringBuffer output = new StringBuffer();
//         Integer status = null;
// 
//         InputStream in = null;
//         try {
//             Process child = Runtime.getRuntime().exec(cmd);
// 
//             BufferedReader stdInput = new BufferedReader(new InputStreamReader(child.getInputStream()));
// 
//             String s;
//             while ((s = stdInput.readLine()) != null) {
//                 output.append(s).append('\n');
//             }
// 
//             status = child.waitFor();
// 
//             debug("Exit status: " + status, 2);
//         } catch (Exception ex) {
//             error("Run command failed.\n" + ex);
//         } finally {
//             IOUtils.closeQuietly(in);
//         }
// 
//         return new String[] { output.toString(), String.valueOf(status) };
//     }
// 
//     public static boolean deleteBestEffort(File path, String whatIsIt) {
//         return deleteBestEffort(path, whatIsIt, 3, false);
//     }
// 
//     public static boolean deleteBestEffort(File path, String whatIsIt, int maxTries) {
//         return deleteBestEffort(path, whatIsIt, maxTries, false);
//     }
// 
//     public static boolean deleteBestEffort(File path, String whatIsIt, int maxTries, boolean quiet) {
//         System.gc();
// 
//         int tries = 0;
//         while (!FileUtils.deleteQuietly(path) && (tries < maxTries)) {
//             System.gc();
//             tries++;
// 
//             if (!quiet) {
//                 warn("Unable to delete " + whatIsIt + ": " + path + ". Trying again ...");
//             }
// 
//             try {
//                 Thread.sleep(3000);
//             } catch (InterruptedException ex) {
//             }
//         }
// 
//         return !path.exists();
//     }
// }


// Path: src/main/java/org/cf/resequencer/sequence/DexFile.java
import java.io.File;
import java.io.IOException;
import java.security.DigestException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Random;
import java.util.zip.Adler32;
import org.apache.commons.io.FileUtils;
import org.cf.resequencer.Console;

package org.cf.resequencer.sequence;



/**
 * 
 * @author Caleb Fenton
 */
public class DexFile {

    private static final int OFF_LINK_SIZE = 44;
    private static final int OFF_LINK_OFF = 48;
    private static final int INT_SIZE = 4;

    private static final byte[] InvalidRef = new byte[] { 0x4e, 0x01, 0x01, 0x01, 0x00, 0x00 // aput-bool p0, p0, p0;
                                                                                             // nop
    };

    private byte[] DexBytes;
    protected File DexFile;

    DexFile(File dexFile) throws IOException {
        DexFile = dexFile;
        DexBytes = FileUtils.readFileToByteArray(dexFile);
    }

    /*
     * Do whatever we can to the dex file to prevent decompilers from working.
     */
    public void dexLock() {
        /*
         * byte[] header = new byte[0x70]; System.arraycopy(DexBytes, 0, header, 0, 0x70);
         * System.out.println(StringUtils.toHexString(header)); for ( int i = 0; i < header.length; i++ ) {
         * System.out.print(header[i] + " "); }
         * 
         * for ( int i = 0; i < 0x70; i++ ) { System.out.print(DexBytes[i] +" "); } System.exit(0);
         */

        Random rng = new Random();
        byte[] val = new byte[4];

        // 40-43 = endian tag (ignore for now)

        System.arraycopy(DexBytes, OFF_LINK_SIZE, val, 0, INT_SIZE);
        Console.debug("DexLock - link size: " + StringUtils.toHexString(val));