Find the keyword of the. Class file in the jar package (variable name, string)

Source: Internet
Author: User

Sometimes you can view the logs and often find the error logs printed by the bottom layer of the framework. If you are not familiar with the framework when you want to modify this error, you need to follow the process that may generate this error log step by step. It may not be found at half past one. For example, when I recently conducted a stress test on the server set up by smartfoxserver, I found that the maximum number of waiting threads exceeds 20 and the error log will be printed, then, it took a long time to find the error output in the decompilation code that smartfoxserver received the request. Then I was wondering if I could use inputstream to query strings. The test code is as follows:

Import Java. io. bufferedreader; import Java. io. file; import Java. io. filefilter; import Java. io. ioexception; import Java. io. inputstreamreader; import Java. util. enumeration; import Java. util. regEx. pattern; import java.util.zip. zipentry; import java.util.zip. zipexception; import java.util.zip. zipfile; public class find {public static final string Path = "D:/workspace/test/"; // jar package parent directory public static final string KEYWORDS = "AAA"; // keyword public static void main (string [] ARGs) {file = new file (PATH); final pattern P = pattern. compile (". + \\. jar $ "); file [] files = file. listfiles (New filefilter () {@ override public Boolean accept (File pathname) {If (P. matcher (pathname. getpath ()). matches () {return true;} else {return false ;}}); search (files);} Private Static void search (file [] files) {try {for (file F: Files) {If (F. isdirectory () {search (F. listfiles ();} else {zipfile jar = new zipfile (f); enumeration enumration = jar. entries (); While (enumration. hasmoreelements () {zipentry = (zipentry) enumration. nextelement (); inputstreamreader ISR = new inputstreamreader (jar. getinputstream (zipentry); bufferedreader BR = new bufferedreader (ISR); string line = BR. readline (); int line_num = 1; while (Null! = Line) {// system. out. println (line); If (line. contains (keywords) {system. out. println (F. getpath () + "," + zipentry. getname () + "," + "line number =" + line_num);} line = BR. readline (); line_num ++ ;}}} catch (zipexception z_e) {z_e.printstacktrace () ;}catch (ioexception io_e) {io_e.printstacktrace ();}}}

 

The jar package for testing: D: \ workspace \ test. Jar code is as follows:
Test. Java:

public class Test {    public static void main(String[] args){        System.out.print("aaa");    }}

The test results are as follows:

 

D: \ workspace \ test. jar, COM/test. Class, line number = 3

 

The above code is not related to the decompilation, so currently it is only valid for the query string or variable name, and the other method name may not be able to find out the time to study the decompilation Parsing

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.