Giter Club home page Giter Club logo

Comments (11)

romainthomas avatar romainthomas commented on September 3, 2024

I confirm that the root cause of this error is likely dProtect, could you attach the Java code associated with this error?

from dprotect.

577fkj avatar 577fkj commented on September 3, 2024

I confirm that the root cause of this error is likely dProtect, could you attach the Java code associated with this error?

public class Main {
    /**
     * 入口方法
     *
     * @param args 参数
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        //参数配置
        CmdLineOption cmd = new CmdLineOption();
        cmd.addOption("packages", true, "加密的包名(可为空,多个用\",\"分割)");
        cmd.addOption("pwd", true, "加密密码");
        cmd.addOption("code", true, "机器码");
        cmd.addOption("exclude", true, "排除的类名(可为空,多个用\",\"分割)");
        cmd.addOption("file", true, "加密的jar/war路径");
        cmd.addOption("libjars", true, "jar/war lib下的jar(可为空,多个用\",\"分割)");
        cmd.addOption("classpath", true, "依赖jar包目录(可为空,多个用\",\"分割)");
        cmd.addOption("cfgfiles", true, "需要加密的配置文件(可为空,多个用\",\"分割)");
        cmd.addOption("Y", false, "无需确认");
        cmd.addOption("debug", false, "调试模式");
        cmd.addOption("C", false, "生成机器码");
        cmd.parse(args);

        if (cmd.hasOption("C")) {
            makeCode();
            return;
        }

        //全部参数(需要加密的class路径,lib下的jar,包名,排除的class,依赖jar包路径,密码,机器码,需要加密的配置文件)
        String path=null,libjars,packages,excludeClass,classpath,password=null,code,cfgfiles;

        //没有参数手动输入
        if (args == null || args.length == 0) {
            while (StrUtils.isEmpty(path)) {
                Log.print("请输入需要加密的jar/war路径:");
                path = scanner.nextLine();
            }

            Log.print("请输入jar/war包lib下要加密jar文件名(多个用\",\"分割):");
            libjars = scanner.nextLine();

            Log.print("请输入需要加密的包名(可为空,多个用\",\"分割):");
            packages = scanner.nextLine();

            Log.print("请输入需要排除的类名(可为空,多个用\",\"分割):");
            excludeClass = scanner.nextLine();

            Log.print("请输入依赖jar包目录(可为空,多个用\",\"分割):");
            classpath = scanner.nextLine();

            Log.print("请输入要加密的配置文件名(可为空,多个用\",\"分割):");
            cfgfiles = scanner.nextLine();


            Log.print("请输入机器码(可为空):");
            code = scanner.nextLine();

            while (StrUtils.isEmpty(password)) {
                Log.print("请输入加密密码:");
                password = scanner.nextLine();
            }
        }else{//在参数中取
            path = cmd.getOptionValue("file", "");
            libjars = cmd.getOptionValue("libjars", "");
            packages = cmd.getOptionValue("packages", "");
            excludeClass = cmd.getOptionValue("exclude", "");
            classpath = cmd.getOptionValue("classpath", "");
            password = cmd.getOptionValue("pwd", "");
            code = cmd.getOptionValue("code", "");
            cfgfiles = cmd.getOptionValue("cfgfiles", "");
        }

        //test数据
        if ("1".equals(path)) {
            path = "/Users/roseboy/fsdownload/yiyon-package-liuyuan-1.0.0.jar";
            libjars = "yiyon-*.jar,aspectjweaver-1.8.13.jar,a.jar";
            packages = "cn.fkj233.classfuck.*";//包名过滤
            excludeClass = "org.spring.*";//排除的类
            password = "123456";
            classpath = "/Users/roseboy/code-space/apache-tomcat-8.5.32/lib";
            cfgfiles = "*.yml";
        } else if ("2".equals(path)) {
            path = "/Users/roseboy/code-space/pig_project/target/pig_project_maven.war";
            packages = "cn.fkj233";//包名过滤
            excludeClass = "org.spring";//排除的类
            password = "#";
            classpath = "/Users/roseboy/code-space/apache-tomcat-8.5.32/lib";
        } else if ("3".equals(path)) {
            path = "/Users/roseboy/Desktop/iyun.node.dicomserver.jar";
            packages = "com,org";//包名过滤
            password = "1234";
        }

        Log.println();
        Log.println("加密信息如下:");
        Log.println("-------------------------");
        Log.println("1. jar/war路径:      " + path);
        Log.println("2. lib下的jar:       " + libjars);
        Log.println("3. 包名前缀:          " + packages);
        Log.println("4. 排除的类名:        " + excludeClass);
        Log.println("5. 加密配置文件:      " + cfgfiles);
        Log.println("6. ClassPath:       " + classpath);
        Log.println("7. 密码:             " + password);
        Log.println("8. 机器码:           " + code);
        Log.println("-------------------------");
        Log.println();

        String yes;
        if (cmd.hasOption("Y")) {
            yes = "Y";
        } else {
            Log.println("确定执行吗?(Y/n)");
            yes = scanner.nextLine();
            while (!"n".equals(yes) && !"Y".equals(yes)) {
                Log.println("Yes or No ?[Y/n]");
                yes = scanner.nextLine();
            }
        }
        IoUtils.close(scanner);

        if (!"Y".equals(yes)) {
            Log.println("已取消!");
            return;
        }
        Log.println("处理中...");
        List<String> includeJarList = StrUtils.toList(libjars);
        List<String> packageList = StrUtils.toList(packages);
        List<String> excludeClassList = StrUtils.toList(excludeClass);
        List<String> classPathList = StrUtils.toList(classpath);
        List<String> cfgFileList = StrUtils.toList(cfgfiles);
        includeJarList.add("-");

        JarEncryptor encryptor = new JarEncryptor(path, password.trim().toCharArray());
        encryptor.setCode(StrUtils.isEmpty(code) ? null : code.trim().toCharArray());
        encryptor.setPackages(packageList);
        encryptor.setIncludeJars(includeJarList);
        encryptor.setExcludeClass(excludeClassList);
        encryptor.setClassPath(classPathList);
        encryptor.setCfgfiles(cfgFileList);
        try {
            String result = encryptor.doEncryptJar();
            Log.println("加密完成,请牢记密码!");
            Log.println("==>" + result);
        } catch (Exception e) {
            //e.printStackTrace();
            Log.println("ERROR: " + e.getMessage());
        }
    }

    /**
     * 生成机器码
     */
    public static void makeCode() {
        String path = JarUtils.getRootPath(null);
        path = path.substring(0, path.lastIndexOf("/") + 1);

        String code = new String(SysUtils.makeMarchinCode());
        File file = new File(path, "classfuck-code.txt");
        IoUtils.writeTxtFile(file, code);
        Log.println("Server code is: " + code);
        Log.println("==>" + file.getAbsolutePath());
        Log.println();
    }
}

from dprotect.

romainthomas avatar romainthomas commented on September 3, 2024

Thank you, since this code depends on the classes StrUtils, JarEncryptor, could you attach code that I can compile to reproduce the error?

from dprotect.

577fkj avatar 577fkj commented on September 3, 2024

Thank you, since this code depends on the classes StrUtils, JarEncryptor, could you attach code that I can compile to reproduce the error?

helloword.zip
jdk-17.0.1.12-openj9

from dprotect.

577fkj avatar 577fkj commented on September 3, 2024

Thank you, since this code depends on the classes StrUtils, JarEncryptor, could you attach code that I can compile to reproduce the error?

helloword.zip jdk-17.0.1.12-openj9

"C:\Program Files\Semeru\jdk-17.0.1.12-openj9\bin\java.exe" -jar obf-helloword.jar
错误: 无法初始化主类 test.main
原因: java.lang.VerifyError: JVMVRFY021 已抛出对象不可抛出 类=test/main,方法=O0o0(Ljava/lang/String;)Ljava/lang/String;,pc=40
Exception Details:
  Location:
    test/main.O0o0(Ljava/lang/String;)Ljava/lang/String; @40: JBificmpge
  Reason:
    A stackmap frame is expected at branch target 347.

from dprotect.

577fkj avatar 577fkj commented on September 3, 2024

New bug....

"C:\Program Files\Semeru\jdk-17.0.1.12-openj9\bin\java.exe" -jar dprotect.jar -injars helloword-1.0-SNAPSHOT.jar -outjar obf-helloword.jar @proguard.pro
dProtect, version 1.0.0
Unexpected error
java.lang.NullPointerException: Cannot invoke "java.util.List.isEmpty()" because "strings" is null
        at dprotect.obfuscation.strings.StringObfuscator.<init>(StringObfuscator.java:57) ~[dprotect.jar:1.0.0]
        at dprotect.obfuscation.CodeObfuscator.runStringObfuscation(CodeObfuscator.java:171) ~[dprotect.jar:1.0.0]
        at dprotect.obfuscation.CodeObfuscator.obfuscate(CodeObfuscator.java:100) ~[dprotect.jar:1.0.0]
        at dprotect.obfuscation.CodeObfuscator.execute(CodeObfuscator.java:74) ~[dprotect.jar:1.0.0]
        at proguard.pass.PassRunner.run(PassRunner.java:24) ~[dprotect.jar:1.0.0]
        at dprotect.DProtect.obfuscate(DProtect.java:507) ~[dprotect.jar:1.0.0]
        at dprotect.DProtect.execute(DProtect.java:204) ~[dprotect.jar:1.0.0]
        at dprotect.DProtect.main(DProtect.java:664) ~[dprotect.jar:1.0.0]
-keep class test.main {
	public static void main(...);
}
#-obfuscate-arithmetic,high class test.** { *; }
#-obfuscate-constants class test.** { *; }
#-obfuscate-control-flow class test.** { *; }
#-obfuscate-strings class test.** { *; }

-keepattributes *Annotation*
-keepattributes Signature
-keepattributes InnerClasses
-keepattributes InnerClasses,EnclosingMethod

-obfuscationdictionary dic.txt
-classobfuscationdictionary dic.txt
-packageobfuscationdictionary dic.txt

-dontoptimize
-dontpreverify
-dontwarn

from dprotect.

romainthomas avatar romainthomas commented on September 3, 2024

Thank you, the last bug is fixed with f9da3a0

from dprotect.

577fkj avatar 577fkj commented on September 3, 2024

Thank you, the last bug is fixed with f9da3a0

Ok, I got it.

#3 (comment)
This problem seems to be caused by string encryption. It can work normally without string encryption.

from dprotect.

577fkj avatar 577fkj commented on September 3, 2024

image

from dprotect.

romainthomas avatar romainthomas commented on September 3, 2024

Removing -dontpreverify in you configuration fixes the issue.

from dprotect.

nthieu90official avatar nthieu90official commented on September 3, 2024

Thank you, the last bug is fixed with f9da3a0

Hi @romainthomas,
Which version will be included this fix?

from dprotect.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.