2

Where I work someone had Java project and used Eclipse to export that project into a .war package.

Now I need to search for a string inside all the files that make that .war package. I know that a .war package is just a .zip file, and I have extracted its contents, however, now I have bunch of of .class java files (among images, xmls and other stuff) and I have no idea on how to search strings inside them.

I am a Linux Mint user, so I tried using the "grep -R stringHere ." command without success (I am not an advanced user), this command only searches inside text files.

I also searched and found the crgrep project but it is currently bugged and it does not work.

Does anyone know a linux command that can search inside all the contents of a .war package and check if those contents contain a specific string or code sample?

I really need to find a way to search through the content of the .class files. That is my only priority so far. I don't care about images nor about any other type of text files.

4
  • 1
    The .class files are just text files right?
    – terdon
    Commented Nov 19, 2013 at 16:48
  • 2
    GNU grep should search binary files by default.
    – jordanm
    Commented Nov 19, 2013 at 16:49
  • The .class java files are not text files as far as I know. So, it means that the command "grep -R supermario ." will also search inside the .class java files? Commented Nov 19, 2013 at 16:51
  • @Flame_Phoenix, it will search inside them (if it's GNU grep), but it will not output the lines that contain the strings as there's no such thing as a line in a binary file. You can use the -a option to override that, or you could use grep -rao '[[:print:]]*yourString[[:print:]]*' to output all the printable characters around yourString that are found in the file. (you should prefer -r over -R). Commented Nov 19, 2013 at 17:11

1 Answer 1

1

How about:

find /path/to/extracted/war -name '*.class' -exec strings -f "{}" +
  |grep yourString
1
  • If a mint grep -R doesn't find it, chances are the string is not in there. However adding -e l or -e b options to string might bring up something if the strings are UCS2 or UTF16. Commented Nov 19, 2013 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .