Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to decompile java bytecode files with javap

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to decompile java bytecode files by javap". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Overview:

Javap is a Java class file decomposer, which can decompile or view the bytecode generated by the java compiler to analyze the execution logic inside the code.

Syntax:

Compile the java file into a class file: javac Test.java (Test.java is the name of the java file) to generate the corresponding .class file Test.class

Perform javap operation: javap command line class file name (without .class suffix)

For example: javap-c Test

Command Lin

-help outputs help information for javap.

-l output line and local variable scale.

-b ensures backward compatibility with JDK 1.1 javap.

-public displays only public classes and members.

-protected displays only protected and public classes and members.

-package displays only the package, protected, and public classes and members. This is the default setting.

-private displays all classes and members.

-J [flag] passes the flag directly to the runtime system.

-s outputs the internal type signature.

-c outputs the unparsed code of the methods in the class, that is, the instructions that make up the Java bytecode.

-verbose output stack size, number of locals and args of each method, and compiled version of the class file

-classpath [path] specifies the path that javap uses to find the class. If this option is set, it overrides the default value or CLASSPATH environment variable. Directories are separated by colons.

-bootclasspath [path] specifies the path used to load the bootstrap class. By default, bootstrap classes are classes that implement the core Java platform and are located in jrelibt.jar and jrelibi18n.jar.

-extdirs [dirs] overrides the location of the search for installation method extensions. The default location for the extension is jrelibext.

Example:

A Demo.java file (stored on the desktop)

Class Demo {public static void main (String [] args) {Integer aInteger = 56; int aInt=0; int aInt2 = 123; String s = "helloworld"; String aString = new String ("IamString");}}

Disassembly result

Compiled from "Demo.java" class Demo {Demo (); Code: 0: aload_0 1: invokespecial # 1 / / Method java/lang/Object. "": () V 4: return public static void main (java.lang.String []); Code: 0: bipush 56 2: invokestatic # 2 / / Method java/lang/Integer.valueOf: (I) Ljava/lang/Integer 5: astore_1 6: iconst_0 7: istore_2 8: bipush 123 10: istore_3 11: ldc # 3 / / String helloworld 13: astore 4 15: new # 4 / / class java/lang/String 18: dup 19: ldc # 5 / / String IamString 21: invokespecial # 6 / / Method java/lang/String. "(Ljava/lang/String ) V 24: astore 5 26: return}

Integer stack instructions for JVM bytecodes (iconst, bipush, sipush, ldc)

Common decompilation tools:

1. Jd-gui: it's best to use it, but sometimes the result of decompilation will be omitted.

2. DJ Java Decompiler: it is less easy to use than jd-gui, but the decompiled result is more accurate.

3. Jclasslib bytecode viewer: a tool for converting bytecode into JVM instructions.

This is the end of the content of "how to decompile java bytecode files with javap". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report