Showing posts with label decompile. Show all posts
Showing posts with label decompile. Show all posts

Monday, January 28, 2019

ClassModifier : Utility to easily modify your Java class files

Modify your Java class files easy with an interactive GUI.

Since it is not possible to edit a class file directly, this tool changes the class file to Smali version which is editable. After making the required changes, this tool converts the modified Smali to the modified Class file.
Features:
  • Modify a given Java class file
  • Allows Pen-tester to verify if their java desktop application is safe from Auth bypass
  • Can help you change the logical behavior of a Jar file by modifying a class
  • You can override private methods, change access modifier for variables of a class using ClassModifier.
  • Many other possibilities....

Download ClassModifier:



How to Use:

java -jar ClassModifier.jar

Menu:

File
  1. Open class (CTRL+O)- Takes the input class which need to be modified
  2. Open Project (CTRL+P)– You can reopen the project created using this feature.
  3. Save & Convert (CTRL+S) – Saves & Convert the code to modified Class and Smali file
  4. Export Class (CTRL+E) – Export modified class
  5. Java 2 Smali Helper - Opens a tab where you can write any Java code which on saving will show its equivalent Smali code
  6. Smali 2 Java code - Opens a tab where you can write any Smali code which on saving will show its equivalent Java 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.
Decompiler
  1. Change Decompiler – Allows you to switch between jadx and jd-cli decompilers.

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

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

ClassModifier_lib Folder

  1. It comes along with the software
  2. Contains the helper jars used by program
  3. ClassModifier_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 ClassModifier_lib\userLibrary

How to Use:
  • Open the Java class to be Modified
  • On opening, ClassModifier will open the Smali version of the class file
  • Edit the smali file and make the required changes
  • Save the smali file 
  • Modified java class file will be created which can be anytime exported using the File -> Export Class button.
  • Since Smali editing can be difficult, 2 options are provided - Java 2 Smali Helper and vice-versa.
  • As name suggests, Java 2 Smali Helper lets you see the Smali equivalent code for the input Java code.
  • Similarly, Smali 2 Java Helper lets you see the Java equivalent code for the input Smali code.

Screenshot:




Note: This software is meant for educational purpose only. Don't use it for any illegal activity.

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.

Sunday, February 26, 2017

Java Reflection- Reading unknown class file

Java Reflection allows you to inspect interfaces, fields and methods from a known or an unknown class. It also allows you to call methods from these unknown class which otherwise wont be possible.
This post is for inspecting class , methods, constructors, fields from an unknown class. In the next post, I would be sharing on how you could utilize and execute those retrieved methods.

Reference:
http://stackoverflow.com/questions/37628/what-is-reflection-and-why-is-it-useful
http://www.javatpoint.com/java-reflection
http://tutorials.jenkov.com/java-reflection/index.html
http://www.oracle.com/technetwork/articles/java/javareflection-1536171.html

Language Used:
Java

Git Location:
https://github.com/csanuragjain/extra/tree/master/ReflectionReadAPI

Related:
https://cooltrickshome.blogspot.in/2017/04/java-reflection-accessingmodifying.html

Pre-requisite:

1) We have a class file named Unknown.class.
2) Unknown.class is the compiled class file and contains the byte code
3) You cannot check the methods and fields from this class unless you deobfuscate the java file
4) You cannot directly call the methods from this class in Eclipse unless and until you copy the java source code which you obtained by deobfuscating this class into a new java file in eclipse. (Or you use Reflection, which we will see :) )

Program:

Obtaining the real class name from Unknown.class:
      public static void main(String[] args) {  
           ClassLoader cl;  
           Class c;  
           try {  
           File file = new File(".");  
           URL url = file.toURL();  
        URL[] urls = new URL[]{url};  
        cl = new URLClassLoader(urls);  
        c = cl.loadClass("Unknown");  
        System.out.println(c.isInterface());   
           } catch (ClassNotFoundException e) {  
                System.out.println("Requested class was not found "+e.getMessage());  
           } catch (MalformedURLException e) {  
                System.out.println("Given class file url was not found "+e.getMessage());  
           }  
      }  

Output:

How it works:
1) We place the Unknown.class in the current project directory.
2) We make a File object which points to the directory where Unknown.class is present. Since it is present in current directory we keep path as '.'
3) We make a URL object using the above File object and then pass this object in a URL array.
4) We use URLClassLoader to load the class from the URL we created.
5) We retrieve the class instance using loadClass
6) isInterface method tells if Unknown.class is an interface
7) When we run this class we get an error wrong name: com/cooltrickshome/completed/RunExternalProgram
8) This tells that real name of Unknown.class is RunExternalProgram.class and its part of package com.cooltrickshome.completed.RunExternalProgram
9) After knowing this, we create folders com/cooltrickshome/completed inside the current project directory (why: refer step 2)
10) We rename Unknown.class to RunExternalProgram.class and place it inside com/cooltrickshome/completed folder
11) Finally we change loadClass to cl.loadClass("com.cooltrickshome.completed.RunExternalProgram");
12) Folder structure finally becomes ./com/cooltrickshome/completed/RunExternalProgram.class

Obtaining the method name from this class file:
      public void printMethods(Class c) {  
           // Getting all the methods  
           System.out.println("\nMethods of this class");  
           Method methlist[] = c.getDeclaredMethods();  
           for (int i = 0; i < methlist.length; i++) {  
                Method m = methlist[i];  
                System.out.println(m.toString());  
                System.out.println("Method Name: " + m.getName());  
                System.out.println("Declaring Class: " + m.getDeclaringClass());  
                Class param[] = m.getParameterTypes();  
                for (int j = 0; j < param.length; j++)  
                     System.out.println("Param #" + j + ": " + param[j]);  
                Class exec[] = m.getExceptionTypes();  
                for (int j = 0; j < exec.length; j++)  
                     System.out.println("Exception thrown by method #" + j + ": "  
                               + exec[j]);  
                System.out.println("Method Return type: " + m.getReturnType());  
                System.out  
                          .println("--------------------------------------------------\n");  
           }  
      }  

Output:
 Methods of this class  
 public static void com.cooltrickshome.completed.RunExternalProgram.main(java.lang.String[]) throws java.lang.InterruptedException,java.io.IOException  
 Method Name: main  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: class [Ljava.lang.String;  
 Exception thrown by method #0: class java.lang.InterruptedException  
 Exception thrown by method #1: class java.io.IOException  
 Method Return type: void  
 --------------------------------------------------  
 public int com.cooltrickshome.completed.RunExternalProgram.getCounter(int)  
 Method Name: getCounter  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: int  
 Method Return type: int  
 --------------------------------------------------  
 public void com.cooltrickshome.completed.RunExternalProgram.runProgram(java.lang.String[]) throws java.lang.InterruptedException,java.io.IOException  
 Method Name: runProgram  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: class [Ljava.lang.String;  
 Exception thrown by method #0: class java.lang.InterruptedException  
 Exception thrown by method #1: class java.io.IOException  
 Method Return type: void  
 --------------------------------------------------  
 public void com.cooltrickshome.completed.RunExternalProgram.incrementCounter(int)  
 Method Name: incrementCounter  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: int  
 Method Return type: void  
 --------------------------------------------------  

How it works:
1) getDeclaredMethods is used to retrieve the methods from the class passed in argument
2) We iterate through each method in a for loop
3) toString method of this method will print the full function prototype
4) getName is used to print the method name
5) getDeclaringClass is used to print the declaring class
6) getParameterTypes is used to retrieve the parameters type used by this method
7) getExceptionTypes is used to find the exception which this method throws
8) getReturnType is used to retrieve the return type of this method.

Obtaining the Constructors from the class file:
      public void printConstructor(Class c) {  
           // Getting all the constructor  
           System.out.println("Constructor of this class");  
           Constructor[] constlist = c.getDeclaredConstructors();  
           for (int i = 0; i < constlist.length; i++) {  
                Constructor m = constlist[i];  
                System.out.println(m.toString());  
                System.out.println("Method Name: " + m.getName());  
                System.out.println("Declaring Class: " + m.getDeclaringClass());  
                Class param[] = m.getParameterTypes();  
                for (int j = 0; j < param.length; j++)  
                     System.out.println("Param #" + j + ": " + param[j]);  
                Class exec[] = m.getExceptionTypes();  
                for (int j = 0; j < exec.length; j++)  
                     System.out.println("Exception thrown by method #" + j + ": "  
                               + exec[j]);  
                System.out  
                          .println("--------------------------------------------------\n");  
           }  
      }  

Output:
 Constructor of this class  
 public com.cooltrickshome.completed.RunExternalProgram()  
 Method Name: com.cooltrickshome.completed.RunExternalProgram  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 --------------------------------------------------  
 public com.cooltrickshome.completed.RunExternalProgram(int)  
 Method Name: com.cooltrickshome.completed.RunExternalProgram  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: int  
 --------------------------------------------------  

How it works:
1) getDeclaredConstructors is used to retrieve the constructors from the class passed in argument
2) We iterate through each constructor in a for loop
3) toString method will print the full constructor prototype
4) getName is used to print the constructor name
5) getDeclaringClass is used to print the declaring class
6) getParameterTypes is used to retrieve the parameters type used by this constructor 
7) getExceptionTypes is used to find the exception which this constructor throws

Obtaining the variables from the class file:
 public void printFields(Class c)  
      {  System.out.println("Variables of this class");
           Field fieldlist[]   
             = c.getDeclaredFields();  
            for (int i   
             = 0; i < fieldlist.length; i++) {  
              Field fld = fieldlist[i];  
              System.out.println("Variable name: " + fld.getName());  
              System.out.println("Declaring class: " +fld.getDeclaringClass());  
              System.out.println("Variable type: " + fld.getType());  
              int mod = fld.getModifiers();  
              System.out.println("Modifiers = " +Modifier.toString(mod));  
              System.out.println("--------------------------------");  
            }  
      }  

Output:
 Variables of this class  
 Variable name: counter  
 Declaring class: class com.cooltrickshome.completed.RunExternalProgram  
 Variable type: int  
 Modifiers = private  
 --------------------------------------------------  

How it works:
1) getDeclaredFields is used to retrieve the variables from the class passed in argument
2) We iterate through each variable in a for loop
3) getName is used to print the variable name
4) getDeclaringClass is used to print the declaring class
5) getParameterTypes is used to retrieve the variable type used by this variable 
7) getModifiers() retrieve the modifier of this variable.

Full Program : (Available from git location)

RunExternalProgram.class:
Placed at <current project directory>/cooltrickshome/completed/RunExternalProgram.class

ReflectionReadApi.java:
 package com.cooltrickshome;  
 import java.io.File;  
 import java.lang.reflect.Constructor;  
 import java.lang.reflect.Field;  
 import java.lang.reflect.Method;  
 import java.lang.reflect.Modifier;  
 import java.net.MalformedURLException;  
 import java.net.URL;  
 import java.net.URLClassLoader;  
 public class ReflectionReadApi {  
      /**  
       * @param args  
       * @throws ClassNotFoundException  
       */  
      public static void main(String[] args) {  
           ClassLoader cl;  
           Class c;  
           try {  
                File file = new File(".");  
                URL url = file.toURL();  
                URL[] urls = new URL[] { url };  
                cl = new URLClassLoader(urls);  
                c = cl.loadClass("com.cooltrickshome.completed.RunExternalProgram");  
                System.out.println("\nName of class is " + c.getName());  
                ReflectionReadApi ra = new ReflectionReadApi();  
                ra.printMethods(c);  
                ra.printConstructor(c);  
                ra.printFields(c);  
           } catch (ClassNotFoundException e) {  
                System.out.println("Requested class was not found "  
                          + e.getMessage());  
           } catch (MalformedURLException e) {  
                System.out.println("Given class file url was not found "  
                          + e.getMessage());  
           }  
      }  
      public void printMethods(Class c) {  
           // Getting all the methods  
           System.out.println("\nMethods of this class");  
           Method methlist[] = c.getDeclaredMethods();  
           for (int i = 0; i < methlist.length; i++) {  
                Method m = methlist[i];  
                System.out.println(m.toString());  
                System.out.println("Method Name: " + m.getName());  
                System.out.println("Declaring Class: " + m.getDeclaringClass());  
                Class param[] = m.getParameterTypes();  
                for (int j = 0; j < param.length; j++)  
                     System.out.println("Param #" + j + ": " + param[j]);  
                Class exec[] = m.getExceptionTypes();  
                for (int j = 0; j < exec.length; j++)  
                     System.out.println("Exception thrown by method #" + j + ": "  
                               + exec[j]);  
                System.out.println("Method Return type: " + m.getReturnType());  
                System.out  
                          .println("--------------------------------------------------\n");  
           }  
      }  
      public void printConstructor(Class c) {  
           // Getting all the constructor  
           System.out.println("Constructor of this class");  
           Constructor[] constlist = c.getDeclaredConstructors();  
           for (int i = 0; i < constlist.length; i++) {  
                Constructor m = constlist[i];  
                System.out.println(m.toString());  
                System.out.println("Method Name: " + m.getName());  
                System.out.println("Declaring Class: " + m.getDeclaringClass());  
                Class param[] = m.getParameterTypes();  
                for (int j = 0; j < param.length; j++)  
                     System.out.println("Param #" + j + ": " + param[j]);  
                Class exec[] = m.getExceptionTypes();  
                for (int j = 0; j < exec.length; j++)  
                     System.out.println("Exception thrown by method #" + j + ": "  
                               + exec[j]);  
                System.out  
                          .println("--------------------------------------------------\n");  
           }  
      }  
      public void printFields(Class c)  
      {  
           System.out.println("Variables of this class");  
           Field fieldlist[]   
             = c.getDeclaredFields();  
            for (int i   
             = 0; i < fieldlist.length; i++) {  
              Field fld = fieldlist[i];  
              System.out.println("Variable name: " + fld.getName());  
              System.out.println("Declaring class: " +fld.getDeclaringClass());  
              System.out.println("Variable type: " + fld.getType());  
              int mod = fld.getModifiers();  
              System.out.println("Modifiers = " +Modifier.toString(mod));  
              System.out.println("--------------------------------------------------\n");  
            }  
      }  
 }  

Output:
 Name of class is com.cooltrickshome.completed.RunExternalProgram  
 Methods of this class  
 public static void com.cooltrickshome.completed.RunExternalProgram.main(java.lang.String[]) throws java.lang.InterruptedException,java.io.IOException  
 Method Name: main  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: class [Ljava.lang.String;  
 Exception thrown by method #0: class java.lang.InterruptedException  
 Exception thrown by method #1: class java.io.IOException  
 Method Return type: void  
 --------------------------------------------------  
 public void com.cooltrickshome.completed.RunExternalProgram.runProgram(java.lang.String[]) throws java.lang.InterruptedException,java.io.IOException  
 Method Name: runProgram  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: class [Ljava.lang.String;  
 Exception thrown by method #0: class java.lang.InterruptedException  
 Exception thrown by method #1: class java.io.IOException  
 Method Return type: void  
 --------------------------------------------------  
 public int com.cooltrickshome.completed.RunExternalProgram.getCounter(int)  
 Method Name: getCounter  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: int  
 Method Return type: int  
 --------------------------------------------------  
 public void com.cooltrickshome.completed.RunExternalProgram.incrementCounter(int)  
 Method Name: incrementCounter  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: int  
 Method Return type: void  
 --------------------------------------------------  
 Constructor of this class  
 public com.cooltrickshome.completed.RunExternalProgram()  
 Method Name: com.cooltrickshome.completed.RunExternalProgram  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 --------------------------------------------------  
 public com.cooltrickshome.completed.RunExternalProgram(int)  
 Method Name: com.cooltrickshome.completed.RunExternalProgram  
 Declaring Class: class com.cooltrickshome.completed.RunExternalProgram  
 Param #0: int  
 --------------------------------------------------  
 Variables of this class  
 Variable name: counter  
 Declaring class: class com.cooltrickshome.completed.RunExternalProgram  
 Variable type: int  
 Modifiers = private  
 --------------------------------------------------  


Hope it helps :)

Tuesday, November 29, 2016

Signing your modified android apk

While installing modified apk,I saw an error stating INSTALL_PARSE_FAILED_NO_CERTIFICATES.
After some research I found the solution for same.

Pre-install:
1) Install Android studio at https://developer.android.com/studio/index.html While Installation, it will ask path for android sdk, configure that path as per your need.
2) In my case it was like C:\Users\anurag\AppData\Local\Android\sdk1.
3) We are mainly interested in adb.exe which is present inside platform-tools, so for me the desired adb.exe path was C:\Users\anjain\AppData\Local\Android\sdk1\platform-tools\adb.exe
4) Add adb.exe in your system environment variables so that you can access adb from command prompt directly.


Problem:
1) Suppose you modified an apk named myapk.apk
2) You try to install the apk using
 adb install myapk.apk  
3) This returns an error Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]
4) This happens because your apk need to be signed again after you modified your apk.

How to sign your jar:

1) Copy the debug.keystore from C:\Users\<YOUR_USERNAME>\.android and place it in the same directory where your modified apk is present.
2) Change extension of your apk file to zip and open it using software like winzip and winrar. (For example your apk was myapk.apk then rename to myapk.zip)
3) Move to META-INF directory inside the myapk.zip.
4) Delete the 2 files with extension SF and RSA. For my case it was CERT.SF & CERT.RSA. For same reason I used CERT in step 7 & 8
5) Close winzip and rename the extension again to apk (For example your apk was myapk.zip then rename to myapk.apk)
6) Open command prompt and point to the directory where your modified apk is present
7) Enter below command: (Password: android)
 keytool -genkey -v -keystore debug.keystore -alias CERT -keyalg RSA -keysize 2048 -validity 20000  
8) Enter below command:
 jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore debug.keystore <Your apk filename with extension> CERT  
9) Verify if jar was signed properly by hitting below command:
 jarsigner -verify <Your apk filename with extension>  
10) If you dont see any error then everything is fine and you can now simply use below command to install in your smartphone
 adb install <Your apk filename with extension>  

Reference:
https://www.kingoapp.com/root-tutorials/how-to-enable-usb-debugging-mode-on-android.htm
https://developer.android.com/studio/index.html
https://dzone.com/articles/android-solution-install-parse-1

Hope it helps :)