aspose for java系列二:pdf跳过license

Administrator
发布于 2021-08-11 / 490 阅读
0
0

aspose for java系列二:pdf跳过license

准备工作

请看aspose for java系列一:words跳过license

  • aspose官网下载aspose.pdf-21.7.jar(2021/8/11获取的最新版本)

分析jar包license验证代码

大致过程同aspose for java系列一:words跳过license,为了不赘述,本文会略过大部分过程,不了解的请戳前面的超链接。

image.png
补充:如果不知道是类在哪里,可以引入该jar在main方法里new一下,根据IDE import类所在包的提示去找。比如License这个文件里面的l21if这个类一开始我也找了很久,因为代码混淆了很多命名看的很混乱,new一下根据IDE提示还有License类的头部import的包对应一下很快就找到了。

找到上图提到的关键——类l9y的li方法,看下方法最终做了什么。

image.png

通过javassist修改上图的几个值,注意有些类要全限定名,不然执行会报错。

ClassPool.getDefault().insertClassPath("C:/Users/gavin/Desktop/aspose.pdf-21.7.jar");
CtClass c2 = ClassPool.getDefault().getCtClass("com.aspose.pdf.l9y");
CtMethod[] declaredMethods = c2.getDeclaredMethods();
for (CtMethod method : declaredMethods)
{
   CtClass[] parameterTypes = method.getParameterTypes();
   if ("lI".equals(method.getName()) && parameterTypes.length == 1
                    && parameterTypes[0].getName().equals("java.io.InputStream")) {
   method.setBody("{this.ly = new java.util.Date(Long.MAX_VALUE);this.l0if = com.aspose.pdf.l9n.lf;com.aspose.pdf.internal.imaging.internal.p14.Helper.help1();lI(this);}");
   c2.writeFile();
   }
}

run后class文件生成:
image.png

解压jar,替换生成的class、删除META-INF下的RSA、SF后缀的指纹文件。

image.png

重新生成jar,引入到项目并编写测试代码

String license2 = "<License>\n"
                + "  <Data>\n"
                + "    <Products>\n"
                + "      <Product>Aspose.Total for Java</Product>\n"
                + "      <Product>Aspose.Words for Java</Product>\n"
                + "    </Products>\n"
                + "    <EditionType>Enterprise</EditionType>\n"
                + "    <SubscriptionExpiry>20991231</SubscriptionExpiry>\n"
                + "    <LicenseExpiry>20991231</LicenseExpiry>\n"
                + "    <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>\n"
                + "  </Data>\n"
                + "  <Signature>111</Signature>\n"
                + "</License>";
        InputStream is2 = new ByteArrayInputStream(
                license2.getBytes("UTF-8"));
        com.aspose.pdf.License asposeLic2 = new com.aspose.pdf.License();
        asposeLic2.setLicense(is2);
        com.aspose.pdf.Document doc1 = new com.aspose.pdf.Document(pdfPath);
        for (int i = 1; i <= doc1.getPages().size(); i++) {
            String imagePath = "C:/Users/gavin/Desktop/a测试/test/" +  i + ".png";
            File file = new File(imagePath); // 新建一个文件
            FileOutputStream os = new FileOutputStream(file);
            com.aspose.pdf.devices.Resolution reso = new com.aspose.pdf.devices.Resolution(
                    200);
            com.aspose.pdf.devices.JpegDevice jpegDevice = new com.aspose.pdf.devices.JpegDevice(
                    reso, 100);
            jpegDevice.process(doc1.getPages().get_Item(i), os);
        }

原文链接:https://blog.csdn.net/qq_42834405/category_8755308.html


评论