下载原版aspose-words-18.6-jdk16.jar 使用执行JByteMod-1.8.0.jar反编译其源码查看其注册文件的加载类 package com.aspose.words; import asposewobfuscated.*; public boolean getIsLicensed() { return zzZLX.zzZJT() == 1; public boolean isLicensed() { return zzZLX.zzZJT() == 1; public void setLicense(final String licenseName) throws Exception { if (licenseName == null) { throw new NullPointerException("licenseName"); new zzZLX().zzY(licenseName, zz2W.zzA3()); public void setLicense(final InputStream stream) throws Exception { throw new NullPointerException("stream");
可见主要的处理类为zzZLX,反编译后找到关键代码如下 private static void zzZ(final Node node, final Node node2) throws Exception { zzZ(sb = new StringBuilder(), node); bytes = sb.toString().getBytes("UTF-16LE"); decode = zz35.decode(node2.getFirstChild().getNodeValue()); final Signature instance = Signature.getInstance("SHA1withRSA"); instance.initVerify(KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(new BigInteger(1, zzZg(zz35.decode("0nRuwNEddXwLfXB7pw66G71MS93gW8mNzJ7vuh3Sf4VAEOBfpxtHLCotymv1PoeukxYe31K441Ivq0Pkvx1yZZG4O1KCv3Omdbs7uqzUB4xXHlOub4VsTODzDJ5MWHqlRCB1HHcGjlyT2sVGiovLt0Grvqw5+QXBuinoBY0suX0="))), new BigInteger(1, zzZg(zz35.decode("AQAB")))))); if (!instance.verify(decode)) { throw new IllegalStateException("The signature is invalid.");
可见这是使用rsa加密验证许可证的合法性,只需要屏蔽验证过程许可证即有效,使用javassist进行代码修改: public static void changeMethod() throws Exception { ClassPool.getDefault().insertClassPath( "D:/aspose-words-18.6-jdk16.jar"); CtClass c2 = ClassPool.getDefault() .getCtClass("com.aspose.words.zzZLX"); CtMethod[] ms = c2.getDeclaredMethods(); System.out.println(c.getName()); CtClass[] ps = c.getParameterTypes(); System.out.println("\t" + cx.getName()); if (c.getName().equals("zzZ") && ps.length == 2 && ps[0].getName().equals("org.w3c.dom.Node") && ps[1].getName().equals("org.w3c.dom.Node")) { System.out.println("find it!"); c.insertBefore("{return;}");
以上可生成zzZLX.class文件,放入jar文件中替换,为防止文件指纹校验,删除jar文件中的META-INF文件夹 下面生成一个许可文件com.aspose.words.lic_2999.xml: <Product>Aspose.Words for Java</Product> <EditionType>Enterprise</EditionType> <SubscriptionExpiry>29991231</SubscriptionExpiry> <LicenseExpiry>29991231</LicenseExpiry> <SerialNumber>---</SerialNumber> <Signature>---</Signature>
为方便使用,我将此文件放入了jar文件根目录下 以下为使用代码,Enjoy it:) package test_fileconvert; import java.io.FileOutputStream; import java.io.InputStream; import com.aspose.words.Document; import com.aspose.words.License; import com.aspose.words.SaveFormat; public static void main(String[] args) throws Exception { doc2pdf("e:/pjtemp/f_new.docx", "e:/pjtemp/f_new.pdf"); public static boolean getLicense() throws Exception { InputStream is = com.aspose.words.Document.class .getResourceAsStream("/com.aspose.words.lic_2999.xml"); License aposeLic = new License(); public static void doc2pdf(String inPath, String outPath) throws Exception { if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档有水印 throw new Exception("com.aspose.words lic ERROR!"); System.out.println(inPath + " -> " + outPath); long old = System.currentTimeMillis(); File file = new File(outPath); FileOutputStream os = new FileOutputStream(file); Document doc = new Document(inPath); // word文档 // 支持RTF HTML,OpenDocument, PDF,EPUB, XPS转换 doc.save(os, SaveFormat.PDF); long now = System.currentTimeMillis(); System.out.println("convert OK! " + ((now - old) / 1000.0) + "秒");
|