Showing posts with label jar. Show all posts
Showing posts with label jar. Show all posts

Thursday, March 30, 2017

APKRepatcher - Now Decompile & Recompile APK with easy GUI

APKRepatcher helps you to modify an existing apk using a simple user friendly GUI. It lets you edit java/smali code from an APK and rewrite the changes back to the modified signed APK. Additionally, it provides you option to convert Dex, Jar, Class, Smali, Class from one format to another. APKRepatcher makes use of dex2jar, jadx, rsyantaxtextarea, zip4j, apktool

Features:
  1. Decompiles/Recompiles the APK.
  2. Provides an editor to change the decompiled java code.
  3. Compiles the code using javac and saves the updated class.
  4. Allows you to view smali version of your modified java code.
  5. Allows you to edit smali from the original apk or from your modified java code
  6. Smali changes once saved would be reflected back in updated apk after building project.
  7. Build features re-creates new apk with all code changes and lastly it would resign the apk.
  8. Basic features like find/replace/increase or decrease font are also provided.
  9. It also allows you to convert from Dex to Jar/Class/Smali/Java, Jar to Dex/Java, Class to Dex/Smali, Smali to Class/Java/Dex. Also allows to extract and sign any apk.
  10. Allows you to change the amount of memory utilized by APKRepatcher.
  11. Patch Module
  12. APKRepatcher is created using Java with no os dependency (as far as i think) so you can run it with various OS
  13. 100% Free
How to run:
 java -jar APKRepatcher.jar  

File
  1. Open apk (CTRL+O)- Takes the input apk which need to be modified and extracts it inside <APKRepatcher_Software_Dir>/Projects/<APK_NAME_FOLDER>/
  2. Open Project (CTRL+P)– You can reopen the project created from open apk anytime using this feature. Just point it to <APK_NAME_FOLDER> inside Projects directory.
  3. Compile & Save (CTRL+S) – Saves & Compile the java code which is currently shown on the GUI editor.
  4. Build APK (CTRL+B) – Recreates a newly signed apk with the changed code.
Edit
  1. Increase Code FontSize (CTRL+I) – Allows you to increase font size of shown code.
  2. Decrease Code FontSize (CTRL+D) – Allows you to decrease the font size of shown code.
  3. Remove all tabs – Removes all currently shown tabs.
Extra
  1. Extract APK-APKTool – User can provide any apk for extraction using this option
  2. Convert Dex to Jar – User can convert any of dex file to jar format using this option
  3. Convert Dex to Class – User can convert any of dex file to class file using this option
  4. Convert Jar/Class to Dex – User can convert any of jar/class file to dex format using this option
  5. Convert Class to Smali – User can convert any of class file to smali format using this option
  6. Convert Smali to Class – User can convert any of smali file to class format using this option
  7. Convert Smali to Java – User can convert any of smali file to java format using this option
  8. Convert Dex to Smali – User can convert any of dex file to smali format using this option
  9. Convert Smali to Dex – User can convert any of smali file to dex format using this option
  10. Convert Dex/Jar to Java – User can convert any of dex/jar file to java format using this option
  11. Sign your apk – User can resign any apk using this option

Advanced
  1. Edit Smali using current code – Rewrite the smali version of the currently visible java code. This features requires the java code to be compilable in order to convert to smali.
  2. Edit Smali using original APK – This features opens the smali version of the java class from the original apk. Since it is extracted from original apk so no need of current java code to be compilable
  3. Save and apply smali changes – After you have edited smali code, you need to save it so that it gets reflected in modified apk.

Settings
  1. Change Memory Allocation – User is allowed to change the amount of memory reserved by APKRepatcher. Default is 1500mb or 1.5 GB

Help
  1. Update Software – Helps you to update the current software if any update is available
  2. How to use APKRepatcher – Contains the documentation of APKRepatcher.

Toolbar
  1. Allows you to find in current code/replace/replaceAll/find all class


Extra Software Content:

APKRepatcher_lib Folder
  1. It comes along with the software
  2. Contains the helper jars used by program
  3. APKRepatcher_lib\userLibrary is automatically added in classpath while compiling code. If you wish to compile your code using external jars then place those external jars inside APKRepatcher_lib\userLibrary

Settings.txt File
  1. Contains the memory utilized by APKRepatcher.

Software Screenshot:


Things to Remember:
  1. The default memory allocated to APKRepatcher is 1500mb which can be changed simply using Settings -> Change Memory Allocation
  2. You can add external library while compiling your code by simply placing them under APKRepatcher_lib\userLibrary folder
  3. You can also use APKRepatcher for converting dex/jar/class/smali/java from one format to another.
  4. Patch a module - Assume a class is non compilable because of certain modules used, but you wish to change one of methods which does not have any issue. In this case you can remove the non compilable methods, keeping only your changed method. Now select edit smali for current code under Advanced. You will obtain the smali version for your java module. Now choose Advanced -> edit smali using original apk. Replace your modified module in the original apk smali and then click on Advanced -> save and apply changes. When you build the project, it would patch the module. So you are saved from the errors :)
  5. You can always increase or decrease the font size of the code using hotkeys or from Edit section
  6. Don't forget to build the apk after you made your changes. It will create the new apk.
  7. All projects are stored in the Projects directory which comes along with the software.
Tutorial:
  1. Open APKRepatcher using java -jar APKRepatcher.jar
  2. Click on File -> Open APK
  3. Choose the apk you wish to change
  4. Open the package from the left pane and double click on the java file you want to edit.
  5. Once java file opens in editor, just make the required changes.
  6. After you made the changes, click on File -> Compile & Save
  7. If compilation fails, you will see the errors in the console view.
  8. Fix them and compile again
  9. Once compilation succeeds, you click on File -> Build APK
  10. If build succeeds, you would see the new apk created.
  11. If you are unable to compile your class, and want to make changes directly to smali then you can click on Advanced -> edit smali using original apk (which will open the current code smali from the original apk) and make the edits and then click on Advanced -> save and apply. After that you can click on File -> Build APK
  12. Assume a class is non compilable because of certain modules used, but you wish to change one of methods which does not have any issue. In this case you can remove the non compilable methods, keeping only your changed method. Now select edit smali for current code under Advanced. You will obtain the smali version for your java module. Now choose Advanced -> edit smali using original apk. Replace your modified module in the original apk smali and then click on Advanced -> save and apply changes. When you build the project, it would patch the module. So you are saved from the errors
Note: This software is meant for educational purpose only. Don't use it for any illegal activity.

Wednesday, November 9, 2016

Advance JAR compresser/decompresser using Java

Every Java installation comes with 2 exe which is pack200.exe and unpack200.exe located at C:\Program Files\Java\jdk<version>\jre\bin
These exe can be used to highly compress jar files that can be directly deployed, saving bandwidth and reducing download time.

Compress Jar:
pack200 myarchive.pack.gz myarchive.jar

In this example, myarchive.pack.gz is produced using the default pack200 settings.

Decompress Jar:
unpack200 myarchive.pack.gz myarchive.jar

In this example, the myarchive.jar is produced from myarchive.pack.gz using the default unpack200 settings.

Code Location:
https://github.com/csanuragjain/extra/tree/master/Jar%20Compresser

Program:
I created a program which can automatically compress and decompress the file input by user.

runProgram Method:
Already explained at https://cooltrickshome.blogspot.in/2016/11/runmonitor-external-program-using-java.html

Main method:
      public static void main(String[] args) throws IOException, InterruptedException {  
           // TODO Auto-generated method stub  
           Scanner s=new Scanner(System.in);  
           System.out.println("Press 1 to compress file and 2 to decompress");  
           int choice=s.nextInt();  
           if(choice==1)  
           {  
                Scanner s2=new Scanner(System.in);  
                System.out.println("Enter file to compress");  
                String file=s2.nextLine();  
                long origlength= new File(file).length();  
                runProgram(new String[]{"pack200","output.pack.gz",file});  
                long newlength= new File("output.pack.gz").length();  
                System.out.println("File compressed and named output.pack.gz, which saved "+((origlength-newlength)/1000)+" KB");  
                s2.close();  
           }  
           else  
           {  
                Scanner s2=new Scanner(System.in);  
                System.out.println("Enter file to decompress");  
                String file=s2.nextLine();  
                runProgram(new String[]{"unpack200",file,"output.jar"});  
                System.out.println("File uncompressed and named output.jar");  
                s2.close();  
           }  
           s.close();  
      }  

How it works:
1) Program asks if user wants to compress or decompress jar
2) If user opt to compress file then program ask for file to compress. It retrieves the original file length and then compress it. After compression it takes length of compressed file and subtract from original length. Lastly it print the success message with the size saving.
3) If user opts to decompress file then it ask file to decompress and run the unpack command over it to get the uncompressed version.

Sample Input:

Press 1 to compress file and 2 to decompress
2
Enter file to decompress
output.pack.gz
Process completed successfully

File uncompressed and named output.jar

Press 1 to compress file and 2 to decompress
1
Enter file to compress
my.jar
Process completed successfully
File compressed and named output.pack.gz, which saved 7000 KB

Full Program:
 package com.cooltrickshome;  
 import java.io.BufferedReader;  
 import java.io.File;  
 import java.io.IOException;  
 import java.io.InputStream;  
 import java.io.InputStreamReader;  
 import java.util.Scanner;  
 public class JARCompresser {  
      public static void runProgram(String[] program) throws InterruptedException, IOException  
      {  
           Process proc = Runtime.getRuntime().exec (program);  
           InputStream progOutput = proc.getInputStream ();  
           InputStreamReader inputReader=new InputStreamReader(progOutput);  
           BufferedReader reader = new BufferedReader(inputReader);            
           String line;  
           while ((line = reader.readLine()) != null)  
             {  
                     System.out.println(line);  
             }  
           if (0 == proc.waitFor ()) {  
             System.out.println("Process completed successfully");  
           }  
           else  
           {  
                System.out.println("Their was some issue while running the program");  
           }  
      }  
      public static void main(String[] args) throws IOException, InterruptedException {  
           // TODO Auto-generated method stub  
           Scanner s=new Scanner(System.in);  
           System.out.println("Press 1 to compress file and 2 to decompress");  
           int choice=s.nextInt();  
           if(choice==1)  
           {  
                Scanner s2=new Scanner(System.in);  
                System.out.println("Enter file to compress");  
                String file=s2.nextLine();  
                long origlength= new File(file).length();  
                runProgram(new String[]{"pack200","output.pack.gz",file});  
                long newlength= new File("output.pack.gz").length();  
                System.out.println("File compressed and named output.pack.gz, which saved "+((origlength-newlength)/1000)+" KB");  
                s2.close();  
           }  
           else  
           {  
                Scanner s2=new Scanner(System.in);  
                System.out.println("Enter file to decompress");  
                String file=s2.nextLine();  
                runProgram(new String[]{"unpack200",file,"output.jar"});  
                System.out.println("File uncompressed and named output.jar");  
                s2.close();  
           }  
           s.close();  
      }  
 }  

Hope this helps :)