The main question is whether it is safe to change some "string" information inside a file *.class(java compiled classes).
What am I doing:
using regexp I'm trying to find all the mouth IP addresses inside some compiled project
find . -type f | xargs grep -E "[0-9]{3}\.[0-9]{3}\.1\.[0-9]{0,3}"
This command tells me that some binaries match my regular expression. And this indicates that these binaries .jarand .class. When I open these .classfiles with vi, I see a lot of strange characters, as well as something like http://192.168.1.111 "among this binary garbage.
My final task is to replace all IP addresses (using sed -i) with a fully qualified domain name.
It is safe? Or just a working solution to disassemble the whole project and recompile?
Added after replies.
I test it like this:
Create Change.java
public class Change {
public static String CHANGE_ME="SOME_TEST_STRING";
public static void main (String[] argv){
System.out.println(CHANGE_ME);
}
}
Run it and see in the terminal
$ java Change
SOME_TEST_STRING
Compile it and run the replacement:
sed -i 's/SOME_TEST_STRING/AAAAA/g' Change.class
After this restart
$ java Change
Exception in thread "main" java.lang.ClassFormatError: Illegal UTF8 string in constant pool in class file Change
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
source
share