你的位置:首页 > 软件开发 > Java > 基于ProGuard

基于ProGuard

发布时间:2016-07-22 19:00:04
介绍大家可能都会碰到一些代码比较敏感的项目场景,这个时候代码被反编译看到就不好了,这个时候就需要代码混淆插件来对代码进行混淆了。基于Maven的项目一般会去考虑使用proguard-maven-plugin,但是这个插件仅支持打Jar包不支持打War包。于是我用空闲时间在prog ...

介绍

大家可能都会碰到一些代码比较敏感的项目场景,这个时候代码被反编译看到就不好了,这个时候就需要代码混淆插件来对代码进行混淆了。

基于Maven的项目一般会去考虑使用proguard-maven-plugin,但是这个插件仅支持打Jar包不支持打War包。

于是我用空闲时间在proguard-maven-plugin的基础上修改了里面的一部分逻辑,可以在项目构建过的时候把代码混淆,支持打成jar包和war包。 

现在贴出来给大家看看。

项目地址

https://github.com/lovethegirl/code-hidding-plugin

 修改部分

War包压缩解压的工具类

package com.github.wvengen.maven.proguard;  import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Iterator;  import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.ArchiveOutputStream; import org.apache.commons.compress.archivers.ArchiveStreamFactory; import org.apache.commons.compress.archivers.jar.JarArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.io.FileUtils;  /** * 处理WAR文件工具类。可压缩或解压缩WAR文件。 *  * @author Xiong Shuhong(shelltea@gmail.com) */ public class WarUtils {   public static void unzip(String warPath, String unzipPath) {     File warFile = new File(warPath);     try {       BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(         warFile));       ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(         ArchiveStreamFactory.JAR, bufferedInputStream);        JarArchiveEntry entry = null;       while ((entry = (JarArchiveEntry) in.getNextEntry()) != null) {         File file = new File(unzipPath, entry.getName());         if (file.exists()) {           file.delete();         }         if (entry.isDirectory()) {           file.mkdir();         } else {           OutputStream out = FileUtils.openOutputStream(file);           IOUtils.copy(in, out);           out.close();         }       }       in.close();     } catch (FileNotFoundException e) {       System.err.println("未找到war文件");     } catch (ArchiveException e) {       System.err.println("不支持的压缩格式");     } catch (IOException e) {       System.err.println("文件写入发生错误");     }   }    public static void zip(String destFile, String zipDir) {     File outFile = new File(destFile);     try {       outFile.createNewFile();       BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(         new FileOutputStream(outFile));       ArchiveOutputStream out = new ArchiveStreamFactory().createArchiveOutputStream(         ArchiveStreamFactory.JAR, bufferedOutputStream);        if (zipDir.charAt(zipDir.length() - 1) != '/') {         zipDir += '/';       }        Iterator<File> files = FileUtils.iterateFiles(new File(zipDir), null, true);       while (files.hasNext()) {         File file = files.next();         ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(file, file.getPath().replace(           zipDir.replace("/", "\\"), ""));         out.putArchiveEntry(zipArchiveEntry);         IOUtils.copy(new FileInputStream(file), out);         out.closeArchiveEntry();       }       out.finish();       out.close();     } catch (IOException e) {       System.err.println("创建文件失败");     } catch (ArchiveException e) {       System.err.println("不支持的压缩格式");     }   } } 
1.创建紧凑的代码文档是为了更快的网络传输,快速装载和更小的内存占用.混淆因为我们开发的是webwork+spring+hibernate的架构的项目,所有需要很详细的配置。(经过n次失败后总结)

# 保留实现Action接口类中的公有的,友好的,私有的属性 和 公有的,友好的方法。其它的全部压缩,优化,混淆。

原标题:基于ProGuard

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录