分享

无废话aspose

 三十的狼 2018-08-04

下载原版aspose-words-18.6-jdk16.jar

使用执行JByteMod-1.8.0.jar反编译其源码查看其注册文件的加载类

  1. package com.aspose.words;
  2. import asposewobfuscated.*;
  3. import java.io.*;
  4. public class License
  5. {
  6. @Deprecated
  7. public boolean getIsLicensed() {
  8. return zzZLX.zzZJT() == 1;
  9. }
  10. public boolean isLicensed() {
  11. return zzZLX.zzZJT() == 1;
  12. }
  13. public void setLicense(final String licenseName) throws Exception {
  14. if (licenseName == null) {
  15. throw new NullPointerException("licenseName");
  16. }
  17. new zzZLX().zzY(licenseName, zz2W.zzA3());
  18. }
  19. public void setLicense(final InputStream stream) throws Exception {
  20. if (stream == null) {
  21. throw new NullPointerException("stream");
  22. }
  23. new zzZLX().zzX(stream);
  24. }
  25. }

可见主要的处理类为zzZLX,反编译后找到关键代码如下

  1. private static void zzZ(final Node node, final Node node2) throws Exception {
  2. byte[] bytes;
  3. if (node != null) {
  4. final StringBuilder sb;
  5. zzZ(sb = new StringBuilder(), node);
  6. bytes = sb.toString().getBytes("UTF-16LE");
  7. }
  8. else {
  9. bytes = new byte[0];
  10. }
  11. byte[] decode;
  12. if (node2 != null) {
  13. decode = zz35.decode(node2.getFirstChild().getNodeValue());
  14. }
  15. else {
  16. decode = new byte[0];
  17. }
  18. final Signature instance = Signature.getInstance("SHA1withRSA");
  19. instance.initVerify(KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(new BigInteger(1, zzZg(zz35.decode("0nRuwNEddXwLfXB7pw66G71MS93gW8mNzJ7vuh3Sf4VAEOBfpxtHLCotymv1PoeukxYe31K441Ivq0Pkvx1yZZG4O1KCv3Omdbs7uqzUB4xXHlOub4VsTODzDJ5MWHqlRCB1HHcGjlyT2sVGiovLt0Grvqw5+QXBuinoBY0suX0="))), new BigInteger(1, zzZg(zz35.decode("AQAB"))))));
  20. instance.update(bytes);
  21. if (!instance.verify(decode)) {
  22. throw new IllegalStateException("The signature is invalid.");
  23. }
  24. }

可见这是使用rsa加密验证许可证的合法性,只需要屏蔽验证过程许可证即有效,使用javassist进行代码修改:

  1. public static void changeMethod() throws Exception {
  2. ClassPool.getDefault().insertClassPath(
  3. "D:/aspose-words-18.6-jdk16.jar");
  4. CtClass c2 = ClassPool.getDefault()
  5. .getCtClass("com.aspose.words.zzZLX");
  6. CtMethod[] ms = c2.getDeclaredMethods();
  7. for (CtMethod c : ms) {
  8. System.out.println(c.getName());
  9. CtClass[] ps = c.getParameterTypes();
  10. for (CtClass cx : ps) {
  11. System.out.println("\t" + cx.getName());
  12. }
  13. if (c.getName().equals("zzZ") && ps.length == 2
  14. && ps[0].getName().equals("org.w3c.dom.Node")
  15. && ps[1].getName().equals("org.w3c.dom.Node")) {
  16. System.out.println("find it!");
  17. c.insertBefore("{return;}");
  18. }
  19. }
  20. c2.writeFile();
  21. }

以上可生成zzZLX.class文件,放入jar文件中替换,为防止文件指纹校验,删除jar文件中的META-INF文件夹

下面生成一个许可文件com.aspose.words.lic_2999.xml:

  1. <License>
  2. <Data>
  3. <Products>
  4. <Product>Aspose.Words for Java</Product>
  5. </Products>
  6. <EditionType>Enterprise</EditionType>
  7. <SubscriptionExpiry>29991231</SubscriptionExpiry>
  8. <LicenseExpiry>29991231</LicenseExpiry>
  9. <SerialNumber>---</SerialNumber>
  10. </Data>
  11. <Signature>---</Signature>
  12. </License>

为方便使用,我将此文件放入了jar文件根目录下

以下为使用代码,Enjoy it:)

  1. package test_fileconvert;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.InputStream;
  5. import com.aspose.words.Document;
  6. import com.aspose.words.License;
  7. import com.aspose.words.SaveFormat;
  8. public class Doc2Pdf {
  9. public static void main(String[] args) throws Exception {
  10. doc2pdf("e:/pjtemp/f_new.docx", "e:/pjtemp/f_new.pdf");
  11. }
  12. public static boolean getLicense() throws Exception {
  13. boolean result = false;
  14. try {
  15. InputStream is = com.aspose.words.Document.class
  16. .getResourceAsStream("/com.aspose.words.lic_2999.xml");
  17. License aposeLic = new License();
  18. aposeLic.setLicense(is);
  19. result = true;
  20. is.close();
  21. } catch (Exception e) {
  22. e.printStackTrace();
  23. throw e;
  24. }
  25. return result;
  26. }
  27. public static void doc2pdf(String inPath, String outPath) throws Exception {
  28. if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档有水印
  29. throw new Exception("com.aspose.words lic ERROR!");
  30. }
  31. System.out.println(inPath + " -> " + outPath);
  32. try {
  33. long old = System.currentTimeMillis();
  34. File file = new File(outPath);
  35. FileOutputStream os = new FileOutputStream(file);
  36. Document doc = new Document(inPath); // word文档
  37. // 支持RTF HTML,OpenDocument, PDF,EPUB, XPS转换
  38. doc.save(os, SaveFormat.PDF);
  39. long now = System.currentTimeMillis();
  40. System.out.println("convert OK! " + ((now - old) / 1000.0) + "秒");
  41. } catch (Exception e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多