|
|
@@ -141,37 +141,16 @@ public class Reverses {
|
|
|
return classfileBuffer;
|
|
|
}
|
|
|
}
|
|
|
- if (decryptProjectPathPrefixSet.size() > 0) {
|
|
|
+ boolean settingDecryptProjectPath = decryptProjectPathPrefixSet.size() > 0;
|
|
|
+ if (settingDecryptProjectPath) {
|
|
|
if (notPointToDecrypt(projectPath, decryptProjectPathPrefixSet)) {
|
|
|
return classfileBuffer;
|
|
|
}
|
|
|
}
|
|
|
className = className.replace("/", ".").replace("\\", ".");
|
|
|
- // 本项目的印章
|
|
|
- if (!Cache.sealCache.containsKey(projectPath)) {
|
|
|
- try {
|
|
|
- byte[] sealByte = IOUtil.readFileFromWorkbenchRoot(new File(projectPath), Constant.SEAL_FILE);
|
|
|
- if (sealByte == null) {
|
|
|
- Logger.error(Reverses.class, "Obtain project seal fail. "
|
|
|
- + "Maybe you need to try it with decrypt params 'decryptProjectPathPrefix' or 'skipProjectPathPrefix'. "
|
|
|
- + "@see https://gitee.com/JustryDeng/class-winter#%E8%A7%A3%E5%AF%86%E5%8F%82%E6%95%B0 ");
|
|
|
- // 结束程序
|
|
|
- exit(projectPath);
|
|
|
- }
|
|
|
- String sealContent = new String(sealByte, StandardCharsets.UTF_8);
|
|
|
- Logger.debug(Reverses.class, "seal of the project is -> " + sealContent);
|
|
|
- Cache.sealCache.put(projectPath, sealContent);
|
|
|
- } catch (Exception e) {
|
|
|
- Logger.error(Reverses.class, "Obtain project seal fail.");
|
|
|
- Logger.error(Reverses.class, ExceptionUtil.getStackTraceMessage(e));
|
|
|
- exit(projectPath);
|
|
|
- for (int i = 0; i < Constant.TEN; i++) {
|
|
|
- Logger.error(Reverses.class, "!!!!!!!!!!! class-winter Invalidation. !!!!!!!!!!!");
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ // 抽取印章
|
|
|
+ extractSeal(projectPath, settingDecryptProjectPath);
|
|
|
+
|
|
|
/// ============================================ 1.校验启动时是否输入了加密时指定的jvm参数 2.处理non-class文件
|
|
|
final String inputPwd = javaagentCmdArgs.getPassword();
|
|
|
if (firstExec.compareAndSet(false, true)) {
|
|
|
@@ -303,6 +282,51 @@ public class Reverses {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 抽取项目印章
|
|
|
+ *
|
|
|
+ * @param settingDecryptProjectPath 是否指定了项目解密路径前缀
|
|
|
+ */
|
|
|
+ private static void extractSeal(String projectPath, boolean settingDecryptProjectPath) {
|
|
|
+ if (Cache.sealCache.containsKey(projectPath)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ byte[] sealByte = IOUtil.readFileFromWorkbenchRoot(new File(projectPath), Constant.SEAL_FILE);
|
|
|
+ // 如果指定了解密路径,但是没有获取到印章的话,直接报错
|
|
|
+ if (settingDecryptProjectPath) {
|
|
|
+ if (sealByte == null) {
|
|
|
+ Logger.error(Reverses.class, "Obtain project seal fail. "
|
|
|
+ + "Cannot found seal at " + new File(projectPath, Constant.SEAL_FILE).getAbsolutePath());
|
|
|
+ // 结束程序
|
|
|
+ exit(projectPath);
|
|
|
+ }
|
|
|
+ String sealContent = new String(sealByte, StandardCharsets.UTF_8);
|
|
|
+ Logger.debug(Reverses.class, "seal of the project is -> " + sealContent);
|
|
|
+ Cache.sealCache.put(projectPath, sealContent);
|
|
|
+ } else if (Cache.firstSealCache != null) {
|
|
|
+ // 如果在没有指定解密路径的情况下,没有获取到印章的话,那么获取第一个印章作为本projectPath的印章
|
|
|
+ Logger.debug(Reverses.class, "direct-seal of the project obtain fail. use firstSealCache as this project seal. "
|
|
|
+ + "firstSealProjectPath -> '" + Cache.firstSealProjectPath + "'. firstSealCache -> '" + Cache.firstSealCache + "'.");
|
|
|
+ Cache.sealCache.put(projectPath, Cache.firstSealCache);
|
|
|
+ } else {
|
|
|
+ if (sealByte == null) {
|
|
|
+ Logger.error(Reverses.class, "Obtain project seal fail. "
|
|
|
+ + "Cannot found seal at " + new File(projectPath, Constant.SEAL_FILE).getAbsolutePath());
|
|
|
+ // 结束程序
|
|
|
+ exit(projectPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ Logger.error(Reverses.class, "Obtain project seal fail.");
|
|
|
+ Logger.error(Reverses.class, ExceptionUtil.getStackTraceMessage(e));
|
|
|
+ exit(projectPath);
|
|
|
+ for (int i = 0; i < Constant.TEN; i++) {
|
|
|
+ Logger.error(Reverses.class, "!!!!!!!!!!! class-winter Invalidation. !!!!!!!!!!!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 是否不需要试着解密projectPath指向的代码
|
|
|
*/
|