2011-09-26 3 views
4

우리는 웹 응용 프로그램을 개발 (스트럿 기반 1.x에서/최대 절전 모드) 내가 ANT 빌드 스크립트를 사용하여 전쟁 파일을 내장하는. 이제 우리 회사는 클라이언트에게 배포하는 & 전쟁을 생성하기 전에 .classes 파일 을 난독 화하기를 원합니다. 내가봤을 때,이 작업을 수행하기 위해 an example using YGuard 라이브러리에 걸쳐 라이브러리를 찾았습니다. 링크는 꽤 유용했지만 모든 Java 클래스를 난독 화했기 때문에 부분적으로 성공했습니다. 이미 모호한이 클래스에 대한 참조를 가진 hibernate 매핑 (* .hbm.xml) 파일을 그대로두고 난독 화되었습니다.Ant & YGuard를 사용하여 내 웹 응용 프로그램 project.war을 난독 화하는 방법?

예 : 난독 처리 후에 MenuGlobalBean.class에 대한 참조는 A.B.H.I.N (여기서 A, B ...는 패키지 이름 & N은 클래스 이름 임)과 같이 바뀔 것입니다. 하지만 내 MenuGlobal.hbm.xml 여전히

<class name="com.mycompany.myproduct.bean.MenuGlobalBean" table="MENU_GLOBAL"> 

보다는 이제 내 질문에 내가 그런 방법으로 내 war 파일을 얼마나 당황 않습니다되어

<class name="A.B.H.I.N" table="MENU_GLOBAL"> 

으로이를 의미 모호한 클래스 그 참조는 내 * .hbm.xml & 다른 구성/등록 정보 파일에 반영됩니다. 일시적으로 항아리에 최대 절전 모드 .XML 파일을 넣어 - 아래

<!-- Build MyProject.war section --> 
<project name="MyProject" default="dist" basedir="."> 
    <property name="proj-home" value="/home/simba/tomcat-7.0.19/webapps/MyProject" /> 
    <!-- set global properties for this build --> 
    <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"> 
    <!-- Create the time stamp --> 
    <tstamp/> 
    <!-- Create the build directory structure used by compile --> 
    <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 " > 
    <!-- Compile the java code from ${src} into ${build} --> 
    <javac srcdir="${src}" destdir="${build}/WEB-INF/classes" classpathref="project-classpath"/> 
    </target> 

    <target name="dist" depends="compile" 
     description="generate the distribution" > 
    <!-- Create the distribution directory --> 
    <mkdir dir="${dist}/lib"/> 

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> 
    <war jarfile="${dist}/lib/MyProject.war" basedir="${build}"/> 
    </target> 

    <target name="clean" 
     description="clean up" > 
    <!-- Delete the ${build} and ${dist} directory trees --> 
    <delete dir="${build}"/> 
    <delete dir="${dist}"/> 
    </target> 




<!-- Using Yguard to obfuscate my .war file --> 
<!-- prepare a temporary directory in which the war file is expanded and obfuscated --> 
<tempfile property="unwar.dir" destdir="${java.io.tmpdir}" deleteonexit="no"/> 
<mkdir dir="${unwar.dir}"/> 
<unwar src="${dist}/lib/MyProject.war" dest="${unwar.dir}"/> 


<!-- create a jar of webapp classes (required by yguard) for obfuscation --> 
<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"/> 

<!-- create a fileset of internal libraries to be obfuscated --> 
<fileset dir="${unwar.dir}/WEB-INF/lib" id="internal.lib.set"> 
    <include name="MyProject.jar"/> 
</fileset> 

<!-- move the internal libraries to a temporary directory and make a fileset out of them --> 
<tempfile property="obfuscation.dir" destDir="${java.io.tmpdir}" deleteonexit="yes"/> 
<mkdir dir="${obfuscation.dir}"/> 
<move todir="${obfuscation.dir}"> 
    <fileset refid="internal.lib.set"/> 
</move> 

<!-- create a jar of web.xml (required by yguard) for obfuscation --> 
<jar destfile="${obfuscation.dir}/web.xml.jar" whenempty="fail"> 
    <zipfileset dir="${unwar.dir}/WEB-INF" includes="*.xml"/> 
</jar> 

<!--<delete file="${unwar.dir}/WEB-INF/web.xml"/> --> 

<!-- make a fileset of all jars to be obfuscated --> 
<fileset dir="${obfuscation.dir}" includes="*.jar" id="in-out.set"/> 

<!-- make a fileset of the remaining libraries, these are not obfuscated --> 
<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> 
     <!-- these filesets are inputs to be obfuscated --> 
     <fileset refid="in-out.set"/> 
    </inoutpairs> 
    <externalclasses refid="external.lib.path"/> <!-- external libs, not obfuscated --> 
    <rename> 
     <adjust replaceContent="true"> 
      <include name="web.xml"/> <!-- modified to reference the obfuscated Servlet --> 
      <include name="struts-config.xml"/> 
      <include name="*.hbm.xml"/> 
     </adjust> 
     <keep> 
      <!-- classes, packages, methods, and fields which should not obfuscated are specified here --> 
     </keep> 
    </rename> 
</yguard> 
<!-- move our newly obfuscated classes back into the lib area --> 
<move todir="${unwar.dir}/WEB-INF/lib"> 
    <fileset dir="${obfuscation.dir}" includes="*_obf.jar"/> 
</move> 

<!-- unjar the adjusted web.xml --> 
<unzip dest="${unwar.dir}/WEB-INF/" src="${unwar.dir}/WEB-INF/lib/web.xml_obf.jar"> 
    <patternset includes="*.xml"/> 
</unzip> 
<!-- <delete> 
    <fileset dir="${unwar.dir}/WEB-INF/lib" includes="web.xml*.jar"/> 
</delete> --> 

<!-- rebuild the war file --> 
<war destfile="MyProject_obf.war" basedir="${unwar.dir}"/> 

</project> 

답변

1

사용을 난처을 위해 내가 web.xml에 참조를 암호화하는 데 사용 같은 트릭을 YGuard 라이브러리를 사용하여 내 전체 ANT 빌드 스크립트입니다 . ("난독에 대한 yguard에 필요한 web.xml에()의 항아리를 만들 수"에 의해 주석 절을 참조하십시오.)

관련 문제