首页

Jar包混淆器源码下载(JNI算法加密)

标签:混淆器,jni,jar包混淆,加密,安全,防复制,java,本地加密,c++,批处理,打包部署bat,启动运行脚本,classpath,运行环境配置     发布时间:2016-06-21   
  • 云盘下载:
  • [提取码:0000]
       ( 需积分:2  )

一、项目简介

该项目源码基本c++封装本地加密算法API,通过java代码实现指令深度路径遍历加密逻辑并调用JNI本地调用接口加密coar,通过window批处理指令startup.bat运行启动,界面如下图所示,浏览GitHub查看源码https://github.com/xwooduser/EncryptJar

Jar包混淆器源码下载(JNI算法加密)

如上图所示,提示请输入混淆命令 - 输入jar所在路径,如输入“C:/NJ/WSPACE/coar/jar”

二、源码快照

1.JAVA源码

import java.io.File;@b@import java.io.FileInputStream;@b@import java.io.FileOutputStream;@b@@b@import org.apache.commons.logging.Log;@b@import org.apache.commons.logging.LogFactory;@b@@b@/**@b@ * @author junni@b@ * @b@ */@b@public class rname {@b@    private static Log log = LogFactory.getLog(rname.class);@b@    String classpath;@b@    String _classpath;@b@    private final static String encodeFileSuffix=".jar";@b@@b@    {@b@        _classpath = rname.class.getClassLoader().getResource(".")@b@                .toString();@b@        _classpath = _classpath.replaceAll("file:", "");@b@        _classpath = _classpath.substring(1, _classpath.length());@b@        System.out.println("当前默认classpath为:"+_classpath);@b@@b@    }@b@    @b@    static{@b@        System.loadLibrary("MSVCRTD");@b@        System.loadLibrary("MFC42D");@b@        System.loadLibrary("coar");@b@    }@b@    @b@    @b@    public native String rJarName(String iname);@b@@b@    public native String rrJarName(String iname);@b@    @b@@b@    rname() {@b@        classpath = rname.class.getClassLoader().getResource(".")@b@                .toString();@b@        classpath = classpath.replaceAll("file:", "");@b@        classpath = classpath.substring(1, classpath.length());@b@    }@b@@b@    rname(String classpath) {@b@        if (classpath.equals("") || classpath == null) {@b@            classpath = rname.class.getClassLoader().getResource(".")@b@                    .toString();@b@            classpath = classpath.replaceAll("file:", "");@b@            classpath = classpath.substring(1, classpath.length());@b@@b@        }@b@    }@b@@b@    /**@b@    * 入口程序@b@    */@b@    void inputLine(String str){@b@    @b@    if(str!=null)@b@        str=str.trim();@b@        @b@    if("".equals(str.trim())||str==null)@b@            str=_classpath;@b@    try{    @b@        if((str.indexOf(encodeFileSuffix) != -1||str.indexOf(encodeFileSuffix.toUpperCase()) != -1)){@b@            @b@             @b@            if(str.lastIndexOf("/")==-1&&str.lastIndexOf("")==-1){@b@             @b@                str=findAbsolutePath(str,null);    @b@            }else if(str.lastIndexOf("/")!=-1&&str.lastIndexOf(":")==-1){                @b@                str=_classpath+str;@b@            }else if(str.lastIndexOf("")!=-1&&str.lastIndexOf(":")==-1){                @b@                str=_classpath+str;            @b@                str=str.replaceAll("","/");            @b@            }else;@b@             @b@            int w=str.lastIndexOf("/")+str.lastIndexOf("")+1;                 @b@            renameFile(str.substring(0,w+1),str.substring(w+1,str.length()));                  @b@       }else if(str.indexOf(":") == -1) {@b@           @b@            if(str.lastIndexOf("/")!=-1){                @b@                str=_classpath+str+"/";@b@            }else if(str.lastIndexOf("")!=-1){                @b@                str=_classpath+str+"";            @b@                str=str.replaceAll("","/");            @b@            }else@b@                str=_classpath+str+"/";@b@@b@             @b@             renameFolder(str);        @b@       }else{@b@         @b@          renameFolder(str);@b@       }@b@          @b@      }catch(Exception e){@b@        log.error(str+"操作失败!");         @b@      }@b@    }@b@@b@@b@    /**处理单个jar文件*/@b@    public void renameFile(String _path,String fileName) throws Exception{@b@         File f=new File(_path+fileName);@b@        // String oFileName=rJarName(fileName)+String.valueOf(Math.random()).substring(2,8)+".jar";@b@          String oFileName=rJarName(fileName)+encodeFileSuffix;@b@         System.gc();@b@         File mm=new File(_path+oFileName);     @b@        if(f.renameTo(mm))           @b@          log.info(_path+fileName+"文件修改为:"+oFileName);        @b@        else  @b@          log.error(_path+fileName+"文件修改失败!");        @b@    @b@    }@b@@b@@b@@b@    /**处理文件目录*/@b@    public void renameFolder(String _path) throws Exception{            @b@@b@         if(_path.lastIndexOf("")!=-1)@b@             if(_path.lastIndexOf("")<_path.length()-1)@b@                _path+="";@b@         else if(_path.lastIndexOf("/")!=-1)@b@             if(_path.lastIndexOf("/")<_path.length()-1)@b@                _path+="/";     @b@        @b@        File ff=new File(_path);@b@        if(!ff.exists()){@b@            log.error("指定的目录不存在!");@b@            return;@b@        }@b@        if(!ff.isDirectory()){@b@            log.error("指定的不是目录");@b@            return;@b@        }            @b@        String[] flist=ff.list();         @b@        for(String f:flist){@b@            File f2=new File(_path+f);            @b@            if(!f2.isDirectory()&&(f.indexOf(encodeFileSuffix)!=-1||f.indexOf(encodeFileSuffix.toUpperCase())!=-1)){@b@                log.info("正在混淆文件:"+_path+f);                 @b@                renameFile(_path,f);@b@            }else if(f2.isDirectory()){                 @b@                System.out.println("处理下一级目录:"+f);@b@               if(_path.lastIndexOf("")!=-1)@b@                renameFolder(_path+f+"");@b@              else if(_path.lastIndexOf("/")!=-1)@b@               renameFolder(_path+f+"/");@b@              else@b@                renameFolder(_path+f);                 @b@              continue;                @b@            }else@b@                continue;         @b@                @b@        }@b@    @b@    }@b@@b@@b@    /**@b@     * 重编译指定目录下class类文件@b@     */@b@    void compileAll(String inputComment) {                 @b@        if(inputComment.equals("")||inputComment==null){@b@            inputComment=_classpath;             @b@        }@b@        if (inputComment.indexOf(encodeFileSuffix) != -1||inputComment.indexOf(encodeFileSuffix.toUpperCase()) != -1) {@b@            //System.out.println(inputComment+"##");@b@            compileClass(inputComment);            @b@        }else{            @b@            File fl=new File(inputComment);@b@            if(!fl.exists()){@b@                log.error("指定的目录不存在!");@b@                return;@b@            }@b@            if(!fl.isDirectory()){@b@                log.error("指定的不是目录");@b@                return;@b@            }@b@            String[] flist=fl.list();@b@            for(String f:flist){@b@                File f2=new File(inputComment+f);@b@                if(!f2.isDirectory()){@b@                    log.info("编译加密class文件:"+f);@b@                    compileClass(inputComment+f);@b@                    System.out.println(inputComment+f+"文件重编译成功");@b@                }else{@b@                    log.info("编译下一级目录...");@b@                    compileAll(inputComment+f);@b@                    System.out.println("正在编译同级目录"+inputComment+f+"。。。");@b@                }@b@            }@b@        }@b@    }@b@    @b@    /**@b@     * 编译单个class文件@b@     */@b@    void compileClass(String fPath){        @b@        try {@b@            String _fpath="";@b@            //System.out.println("#####################"+fPath);@b@            if((fPath.indexOf("/")!=-1||fPath.indexOf("")!=-1)&&(fPath.indexOf(encodeFileSuffix)!=-1||fPath.indexOf(encodeFileSuffix.toUpperCase())!=-1)){@b@                _fpath=fPath;@b@                //int w=fPath.lastIndexOf("/")+fPath.lastIndexOf("")+1;    @b@                //System.out.println(fPath.substring(w+1,fPath.length()));@b@                // _fpath=findAbsolutePath(fPath.substring(w+1,fPath.length()),fPath.substring(0,w+1));         @b@            //     System.out.println("#####################223344:"+_fpath);@b@            }else{                 @b@                _fpath=findAbsolutePath(fPath,null);@b@            //    System.out.println("#####################223355:"+_fpath);@b@            }@b@            @b@            if(_fpath==null||_fpath.equals("")){@b@                System.out.println("没找到所要编译的文件");@b@                return ;@b@            }@b@@b@            @b@            FileInputStream fi1 = new FileInputStream(new File(_fpath@b@                    ));@b@            byte data[] = new byte[fi1.available()];@b@            fi1.read(data);@b@            fi1.close();@b@            System.out.println("传入字节大小"+data.length);@b@            @b@            byte[] _data=data;@b@@b@            System.out.println("##传出字符串为:"+new String(_data));@b@    @b@            FileOutputStream fo = new FileOutputStream(new File(_fpath));@b@            fo.write(_data);@b@            fo.close();@b@            @b@        } catch (Exception e) {@b@            log.error("编译class文件时出错:"+e.getMessage());@b@            e.printStackTrace();@b@            @b@        }@b@    }@b@    @b@    /**@b@     * 返回需要查找文件的全路径@b@     * @param fName@b@     * @return @b@     */@b@    String findAbsolutePath(String fName,String filePath) throws Exception{@b@        //System.out.println(fName+"$");@b@        //System.out.println(filePath+"$#");@b@        String _rpath="";@b@        if(filePath==null||filePath.equals(""))@b@            filePath=_classpath;@b@        else{             @b@            if(filePath.lastIndexOf("/")!=filePath.length()-1){@b@                filePath+="/";                @b@            }else if(filePath.lastIndexOf("/")==filePath.length()-1)@b@                ;@b@             else @b@                 filePath+="";                      @b@            System.out.println(filePath+fName);@b@            File f2=new File(filePath+fName);@b@            if(f2.exists()){                @b@                return filePath+fName;        @b@            }@b@                    @b@        }@b@        File ff=new File(filePath);@b@        if(!ff.exists()){@b@            log.error("指定的目录不存在!");@b@            return null;@b@        }@b@        if(!ff.isDirectory()){@b@            log.error("指定的不是目录");@b@            return null;@b@        }    @b@        String[] flist=ff.list();         @b@        for(String f:flist){@b@            File f2=new File(filePath+f);            @b@            if(!f2.isDirectory()&&fName.equalsIgnoreCase(f)){@b@                log.info("查找的文件全路径:"+filePath+f);@b@                System.out.println("查找的文件全路径:"+filePath+f);@b@                return filePath+f;@b@            }else if(f2.isDirectory()){@b@                log.info("查找下一级目录...");@b@                System.out.println("查找下一级目录:"+filePath+f);@b@                _rpath=findAbsolutePath(fName,filePath+f);@b@                if("".equals(_rpath))@b@                    continue;@b@                else@b@                    break; @b@            }else@b@                continue;         @b@                @b@        }@b@        @b@        return _rpath;@b@        @b@    }@b@    @b@    public static void main(String[] args) throws Exception@b@    {@b@        rname rcc=new rname();@b@        System.out.println("请输入密码>");@b@        int a;@b@        StringBuffer str=new StringBuffer("");@b@        while((a=System.in.read())!= -1){             @b@            str.append((char)a);@b@            if((char)a=='@b@'){@b@                System.out.println("@b@");@b@                if(("bmlqdW4yMDEyAAAAAAAA").equals(rcc.rJarName(str.toString().trim()))){@b@                //bmlqdW4NCm5panVuMjAx@b@                //bmlqdW4yMDEyAAAAAAAA@b@                    System.out.println("身份正确!@b@");@b@                    str=new StringBuffer("");@b@                    @b@                    System.gc();@b@                    break;@b@                }else{@b@                    System.out.println("身份错误!");@b@                    str=new StringBuffer("");@b@                    System.gc();                    @b@                }@b@                    @b@            }@b@        }@b@     @b@        System.out.println("服务器已启动...");@b@        System.out.print("请输入混淆命令:");@b@@b@        int c;@b@        int i=0;@b@        @b@        try { @b@            str=new StringBuffer("");@b@            while((c=System.in.read())!= -1){@b@                    str.append((char)c);@b@                    //System.out.print((char*)c);@b@    //              System.out.print((char)c); @b@                  if((char)c=='@b@'){@b@                      System.out.println("混淆准备中...");                  @b@                      rcc.inputLine(str.toString().trim());@b@                      i=0;@b@                     // break;@b@                  }                  @b@            }            @b@        }catch(Exception e) {@b@              System.out.println("混淆出错:"+e.getMessage());@b@              e.printStackTrace();@b@        }@b@        System.out.println("");@b@        @b@        System.gc();@b@    }@b@@b@}

2.批处理脚本文件

::::::::::::::::compile.bat@b@@b@@echo off@b@cd .@b@set APP_HOME=%cd%@b@set CLASSPATH=%APP_HOME%\commons-logging-1.0.4.jar;%APP_HOME%\jre\jre\lib\rt.jar@b@javac  -encoding utf-8  rname.java@b@javah -classpath . -jni rname @b@javac  -encoding utf-8  rrname.java@b@javah -classpath . -jni rrname @b@echo rname.java、rrname.java编译成功!@b@@pause@b@@b@::::::::::::::::copy.bat@b@@b@@echo on@b@cd .@b@set APP_HOME=%cd%@b@echo y| xcopy /y %APP_HOME%\jar  %APP_HOME%\xxx  /s /a  /e /h /p /f  @b@@pause@b@@b@::::::::::::::::build_jar.bat@b@@b@@echo on@b@set app_home=D:\project\zhsq\WebRoot@b@cd %app_home%\WEB-INF\classes@b@jar cvf  commons-po.jar com/*@b@@b@::::::::::::::::del_jar.bat@b@@b@@echo on@b@cd .@b@cd D:\project\zhsq\WebRoot\WEB-INF\lib @b@del /f commons-po.jar@b@@b@@b@::::::::::::::::deploy_jar.bat@b@@b@@echo on@b@set source_=D:\study\java\jni\coar\test\WEB-INF\classes\junit@b@@b@set target_=D:\study\java\jni\coar\test\WEB-INF\lib@b@@b@echo y| xcopy /y %source_%  %target_% /s /a  /e /h /p /f   @b@@b@@pause@b@@b@@echo on@b@set app_home=D:\project\zhsq\WebRoot@b@cd %app_home%\WEB-INF\classes@b@rd /s/q com@b@@pause@b@@b@@b@::::::::::::::::run.bat@b@@b@@echo off@b@title JAR包混淆器2@b@cd .@b@set APP_HOME=%cd%@b@::del /f coar.dll @b@::cd ../../../@b@::cd c++/coar/Debug@b@::copy coar.dll  %APP_HOME%@b@cd  %APP_HOME% @b@::set CLASSPATH=.;%APP_HOME%\commons-logging-1.0.4.jar;;%APP_HOME%\jre\jre\lib\rt.jar@b@::if %JAVA_HOME%="" goto SETJAVA@b@::SETJAVA@b@SET JAVA_HOME=%APP_HOME%\jre@b@::echo %JAVA_HOME%@b@set path=.;%JAVA_HOME%\bin;%path%@b@javac.exe -encoding utf-8 -classpath "%APP_HOME%"  -Djava.ext.dirs="%JAVA_HOME%\lib\ext";"%APP_HOME%"  rname.java   @b@echo rname.java编译成功!@b@java.exe  -classpath "%APP_HOME%"  -Djava.ext.dirs="%JAVA_HOME%\lib\ext";"%APP_HOME%"  -Xms128m -Xmx300m   rname@b@@pause@b@@b@@b@::::::::::::::::run.bat@b@@b@@echo off@b@title JAR包混淆器@b@cd .@b@set APP_HOME=%cd%@b@::del /f coar.dll @b@::cd ../../../@b@::cd c++/coar/Debug@b@::copy coar.dll  %APP_HOME%@b@cd  %APP_HOME% @b@set CLASSPATH=.;%APP_HOME%\commons-logging-1.0.4.jar;;%APP_HOME%\jre\jre\lib\rt.jar@b@::if %JAVA_HOME%="" goto SETJAVA@b@::SETJAVA@b@SET JAVA_HOME=%APP_HOME%\jre@b@::echo %JAVA_HOME%@b@set path=.;%JAVA_HOME%\bin;%path%@b@javac.exe -encoding utf-8  rname.java   @b@echo rname.java编译成功!@b@java.exe  -Xms128m -Xmx800m   rname@b@@pause@b@@b@@b@::::::::::::::::myStat.bat@b@set JAVA_HOME=D:\NIJUN\soft\jdk1.6.0_20@b@@b@set  CLASSPATH=D:\NIJUN\soft\apache-ftpserver-1.0.6\common\lib\*@b@@b@ftpd.bat res/conf/ftpd-typical.xml

��

<<热门下载>>