绿色版Aspose生成方法
项目中加入我们的java工具包javassist
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.27.0-GA</version>
</dependency>
收集信息,分析源码
License.class中无论是setLicense(String licenseName)还是setLicense(InputStream stream)最终都用到了zzZK5这个类。
public void setLicense(String licenseName) throws Exception {
if (licenseName == null) {
throw new NullPointerException(this.zzYIG.zzZw(new byte[]{108, 105, 99, 101, 110, 115, 101, 78, 97, 109, 101}));
} else {
(new zzZK5()).zzV(licenseName, zzZZS.zzlP());
}
}
public void setLicense(InputStream stream) throws Exception {
if (stream == null) {
throw new NullPointerException(this.zzYIG.zzZw(new byte[]{115, 116, 114, 101, 97, 109}));
} else {
(new zzZK5()).zzV(stream);
}
}
而zzZK5这个类有两个方法暴露出来:zzZej和zzZei方法(估计是验证License方法),我们推测可以修改这两个方法,让他们都return 1
static int zzZej()
static int zzZei()
开始行动,获得修改后的class
//指明目标jar包
ClassPool.getDefault().insertClassPath("D:\\work\\apache-maven-3.0.4\\repository\\com\\aspose\\aspose-words\\19.12\\aspose-words-19.12-jdk17.jar");
//找到验证License的类
CtClass zzZJJClass = ClassPool.getDefault().getCtClass("com.aspose.words.zzZK5");
//两个目标方法
CtMethod zzZej = zzZJJClass.getDeclaredMethod("zzZej");
CtMethod zzZei = zzZJJClass.getDeclaredMethod("zzZei");
//修改方法
zzZej.setBody("{return 1;}");
zzZei.setBody("{return 1;}");
//这一步就是将破译完的class放在桌面上
zzZJJClass.writeFile("C:\\Users\\shower\\Desktop\\");
修改Aspose的jar包
然后需要替换jar包中对应的这个class,为防止文件指纹校验,删除META-INF中的 *.RSA 和 *.SF 文件
maven包含本地jar包的方法
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>19.12</version>
<classifier>jdk17</classifier>
<scope>system</scope>
<systemPath>${project.basedir}/lib/aspose-words-19.12-jdk17.jar</systemPath>
</dependency>
......
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 包含本地jar -->
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
云上面使用绿色版jar包
将去掉后缀的jar包放在lib目录下,创建build.sh,在云部署脚本里执行该shell脚本
#! /bin/bash
pwd
mv ./lib/aspose-words-19.12-jdk17 ./lib/aspose-words-19.12-jdk17.jar