We developed a web application (based on struts 1.x / Hibernate) for which I built using the ANT build script file. Now my company wants me to mess up .classes files before starting a war and spreading it to a client. When I googled, I came across an example using the YGuard library to complete this task. The link was pretty useful, but I had only partial success, as it confused all java classes, leaving the hibernate mapping (* .hbm.xml) un-obfuscated files that had links to those classes that were already confused.
For example: after obfuscating, the links to MenuGlobalBean.class turn into something like say ABHIN (where the names A, B..are and N are the class name). But my MenuGlobal.hbm.xml still treats this as
<class name="com.mycompany.myproduct.bean.MenuGlobalBean" table="MENU_GLOBAL">
but not
<class name="ABHIN" table="MENU_GLOBAL">
Now my question is how do I mess up my war file so that the obfuscated class references reflect my * .hbm.xml and other configuration / properties files, if any.
Below is my full ANT build script using the YGuard library for obfuscation
<project name="MyProject" default="dist" basedir="."> <property name="proj-home" value="/home/simba/tomcat-7.0.19/webapps/MyProject" /> <property name="src" location="WEB-INF/src"/> <property name="build" location="build"/> <property name="lib" location="WEB-INF/lib"/> <property name="dist" location="dist"/> <target name="init"> <tstamp/> <mkdir dir="${build}"/> </target> <path id="project-classpath"> <fileset dir="${proj-home}/WEB-INF/lib" includes="*.jar" /> </path> <target name="copy-non-java-files"> <copy todir="build" includeemptydirs="false"> <fileset dir="."> <include name="*" /> <include name="css/**/*" /> <include name="help_files/**/*" /> <include name="images/**/*" /> <include name="js/**/*" /> <include name="jsp/**/*" /> <include name="schemas/**/*" /> <include name="Sounds/**/*" /> <include name="VideoImage/**/*" /> <exclude name="WEB-INF/src" /> <exclude name="yguard.jar" /> <exclude name="*.war" /> <exclude name="build.xml" /> </fileset> <fileset dir="."> <include name="WEB-INF/classes/**/*" /> <include name="WEB-INF/classes/*.xml" /> <include name="WEB-INF/lib/**/*" /> <include name="WEB-INF/*.xml" /> <include name="WEB-INF/*.properties"/> <include name="WEB-INF/*.dtd" /> <include name="WEB-INF/*.tld" /> <include name="WEB-INF/*.txt" /> <include name="WEB-INF/*.ico" /> </fileset> </copy> </target> <target name="compile" depends="clean,init,copy-non-java-files" description="compile the source " > <javac srcdir="${src}" destdir="${build}/WEB-INF/classes" classpathref="project-classpath"/> </target> <target name="dist" depends="compile" description="generate the distribution" > <mkdir dir="${dist}/lib"/> <war jarfile="${dist}/lib/MyProject.war" basedir="${build}"/> </target> <target name="clean" description="clean up" > <delete dir="${build}"/> <delete dir="${dist}"/> </target> <tempfile property="unwar.dir" destdir="${java.io.tmpdir}" deleteonexit="no"/> <mkdir dir="${unwar.dir}"/> <unwar src="${dist}/lib/MyProject.war" dest="${unwar.dir}"/> <jar destfile="${unwar.dir}/WEB-INF/lib/MyProject.jar" whenempty="fail"> <zipfileset dir="${unwar.dir}/WEB-INF/classes" excludes="*.xml,*.properties"/> </jar> <delete dir="${unwar.dir}/WEB-INF/classes/*" excludes="*.xml,*.properties"/> <fileset dir="${unwar.dir}/WEB-INF/lib" id="internal.lib.set"> <include name="MyProject.jar"/> </fileset> <tempfile property="obfuscation.dir" destDir="${java.io.tmpdir}" deleteonexit="yes"/> <mkdir dir="${obfuscation.dir}"/> <move todir="${obfuscation.dir}"> <fileset refid="internal.lib.set"/> </move> <jar destfile="${obfuscation.dir}/web.xml.jar" whenempty="fail"> <zipfileset dir="${unwar.dir}/WEB-INF" includes="*.xml"/> </jar> <fileset dir="${obfuscation.dir}" includes="*.jar" id="in-out.set"/> <path id="external.lib.path"> <fileset dir="${unwar.dir}/WEB-INF/lib" includes="*.jar"/> </path> <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="../ref/yguard.jar"/> <yguard> <inoutpairs> <fileset refid="in-out.set"/> </inoutpairs> <externalclasses refid="external.lib.path"/> <rename> <adjust replaceContent="true"> <include name="web.xml"/> <include name="struts-config.xml"/> <include name="*.hbm.xml"/> </adjust> <keep> </keep> </rename> </yguard> <move todir="${unwar.dir}/WEB-INF/lib"> <fileset dir="${obfuscation.dir}" includes="*_obf.jar"/> </move> <unzip dest="${unwar.dir}/WEB-INF/" src="${unwar.dir}/WEB-INF/lib/web.xml_obf.jar"> <patternset includes="*.xml"/> </unzip> <war destfile="MyProject_obf.war" basedir="${unwar.dir}"/> </project>
Manoj source share