JRebal(原名JavaRebel)破解小记

JavaRebel是一个工具,主要是用于热加载,比如说在Tomcat之类的应用服务器中,更新了class或者某些资源文件,使用了JRebel之后,就不需要重新启动应用服务器。这对于开发的人来说,是特别方便的。当然Java也提供了HotSpot的JVM,但是如果你修改的类中有方法名称变动的话,HotSpot就无能为力了,必须要重要启动应用服务器。
这里有一点先声明一下,本文只是破解仅限于学习和研究使用,勿用于其他用途。
第一步当然是下载JRebel
下载地址:http://www.zeroturnaround.com/jrebel/download/
下载下来的是一个Zip压缩包,打开之后会发现一个jrebel.jar,这就是其最重要的运行包了。其他都是一些文档和插件。
第二步,是进行反编译。
我推荐一个工具:http://java.decompiler.free.fr/,分成Eclipse插件和单独的运行程序两种,我下载的是单独的运行程序,只有一个绿色的exe文件,点击后直接运行。
看了一下,最显眼的自然是UserLicense类了。

 1 package  com.zeroturnaround.licensing;
 2
 3 import  java.io.Serializable;
 4 import  java.util.Map;
 5
 6 public   class  UserLicense
 7    implements  Serializable
 8 {
 9  static final long serialVersionUID = 1L;
10  private byte[] signature;
11  private byte[] license;
12  private Map dataMap;
13
14  public byte[] getSignature()
15  {
16    return this.signature;
17  }

18
19  public void setSignature(byte[] paramArrayOfByte) {
20    this.signature = paramArrayOfByte;
21  }

22
23  public byte[] getLicense() {
24    return this.license;
25  }

26
27  public void setLicense(byte[] paramArrayOfByte) {
28    this.license = paramArrayOfByte;
29  }

30}

31

 

然后就找到了调用getLicense方法的jS类(名字很奇怪,因为是混淆过的原因,jS类反编译后的源码附在最后面了)
这个类中很明确地显示了License的获取方法。
首先是:jreble.lic文件,用winrar打开jrebel.jar就看到这个文件了。
从源码来看,UserLicense是用ObjectInputStream通过ReadObject得到了。
然后,属性license里面其实是一个Map,用ObjectInputStream从ByteArrayInputSteam中通过ReadObject得到。于是写了下面这样的测试代码

 1 package  temp.jrebel;
 2
 3 import  java.io.BufferedInputStream;
 4 import  java.io.BufferedOutputStream;
 5 import  java.io.ByteArrayInputStream;
 6 import  java.io.ByteArrayOutputStream;
 7 import  java.io.File;
 8 import  java.io.FileInputStream;
 9 import  java.io.FileOutputStream;
10 import  java.io.IOException;
11 import  java.io.ObjectInputStream;
12 import  java.io.ObjectOutputStream;
13 import  java.util.Calendar;
14 import  java.util.GregorianCalendar;
15 import  java.util.Iterator;
16 import  java.util.Map;
17 import  junit.framework.Assert;
18 import  org.junit.Test;
19 import  com.zeroturnaround.licensing.UserLicense;
20
21 public   class  ParseLicense  {
22    @Test
23    public void parseLicenseFile() {
24        Object localObject1 = null;
25        try {
26            System.out.println("start to get lic file.");
27            File localFile2 = new File("d:\\temp\\jrebel.lic");
28            Assert.assertNotNull(localFile2);
29           
30            System.out.println("start to get objectInputStream.");
31            localObject1 = new ObjectInputStream(new BufferedInputStream(
32                    new FileInputStream(localFile2)));
33            Assert.assertNotNull(localObject1);
34           
35            System.out.println("start to get userLicense.");
36            UserLicense localUserLicense1 = (UserLicense)((ObjectInputStream)localObject1).readObject();
37            Assert.assertNotNull(localUserLicense1);
38           
39            System.out.println("start to get ObjectInputStream2.");
40            ObjectInputStream localObjectInputStream = new ObjectInputStream(new ByteArrayInputStream(localUserLicense1.getLicense()));
41            Assert.assertNotNull(localObjectInputStream);
42           
43            System.out.println("start to get localMap.");
44            Map localMap = (Map)localObjectInputStream.readObject();
45            Assert.assertNotNull(localMap);
46           
47            System.out.println("start tot output value.");
48            for ( Iterator<?> iter = localMap.keySet().iterator(); iter.hasNext(); ) {
49                String key = (String)iter.next();
50                System.out.println("key: " + key + ", value: " + localMap.get(key));
51            }

52
53        }
 catch (Exception e) {
54            e.printStackTrace();
55            Assert.fail("faile to parse license. ");
56        }
 finally {
57            if (localObject1 != null{
58                try {
59                    ((ObjectInputStream) localObject1).close();
60                }
 catch (IOException localIOException12) {
61                }

62            }

63        }

64
65    }

66}

67
68


Concole中果然如我所愿地,把Map里的值都打印出来了。到了这一步,剩下的就简单了,把Map里面的validateUntil属性的日期换一下,重新生成一个License文件就行了。
把上面的代码修改一下,很容易地就生成了新的License文件。
原来License里面的试用期只有一个月,比如,我是2009-10-15下载的,那么这个jrebel.lic文件里的validateUntil日期就是11月14日,现在我把他改成了明年元旦。

 

  1 package  temp.jrebel;
  2
  3 import  java.io.BufferedInputStream;
  4 import  java.io.BufferedOutputStream;
  5 import  java.io.ByteArrayInputStream;
  6 import  java.io.ByteArrayOutputStream;
  7 import  java.io.File;
  8 import  java.io.FileInputStream;
  9 import  java.io.FileOutputStream;
 10 import  java.io.IOException;
 11 import  java.io.ObjectInputStream;
 12 import  java.io.ObjectOutputStream;
 13 import  java.util.Calendar;
 14 import  java.util.GregorianCalendar;
 15 import  java.util.Iterator;
 16 import  java.util.Map;
 17 import  junit.framework.Assert;
 18 import  org.junit.Test;
 19 import  com.zeroturnaround.licensing.UserLicense;
 20
 21 public   class  ParseLicense  {
 22    @Test
 23    public void parseLicenseFile() {
 24        Object localObject1 = null;
 25        try {
 26            System.out.println("start to get lic file.");
 27            File localFile2 = new File("d:\\temp\\jrebel.lic");
 28            Assert.assertNotNull(localFile2);
 29           
 30            System.out.println("start to get objectInputStream.");
 31            localObject1 = new ObjectInputStream(new BufferedInputStream(
 32                    new FileInputStream(localFile2)));
 33            Assert.assertNotNull(localObject1);
 34           
 35            System.out.println("start to get userLicense.");
 36            UserLicense localUserLicense1 = (UserLicense)((ObjectInputStream)localObject1).readObject();
 37            Assert.assertNotNull(localUserLicense1);
 38           
 39            System.out.println("start to get ObjectInputStream2.");
 40            ObjectInputStream localObjectInputStream = new ObjectInputStream(new ByteArrayInputStream(localUserLicense1.getLicense()));
 41            Assert.assertNotNull(localObjectInputStream);
 42           
 43            System.out.println("start to get localMap.");
 44            Map localMap = (Map)localObjectInputStream.readObject();
 45            Assert.assertNotNull(localMap);
 46           
 47            System.out.println("start tot output value.");
 48            for ( Iterator<?> iter = localMap.keySet().iterator(); iter.hasNext(); ) {
 49                String key = (String)iter.next();
 50                System.out.println("key: " + key + ", value: " + localMap.get(key));
 51            }

 52
 53           
 54            System.out.println("start to change date.");
 55            Calendar cal = new GregorianCalendar(20100101);
 56            localMap.put("validUntil", cal.getTime());
 57
 58            System.out.println("start to set a new date to license.");
 59            ByteArrayOutputStream out1 = new ByteArrayOutputStream();
 60            ObjectOutputStream out2 = new ObjectOutputStream(out1);
 61            out2.writeObject(localMap);
 62            out1.toByteArray();
 63            localUserLicense1.setLicense(out1.toByteArray());
 64            out1.close();
 65            out2.close();
 66
 67           
 68            System.out.println("start to get ObjectInputStream2.");
 69            localObjectInputStream = new ObjectInputStream(new ByteArrayInputStream(localUserLicense1.getLicense()));
 70            Assert.assertNotNull(localObjectInputStream);
 71           
 72            System.out.println("start to get localMap.");
 73            localMap = (Map)localObjectInputStream.readObject();
 74            Assert.assertNotNull(localMap);
 75           
 76            for ( Iterator<?> iter = localMap.keySet().iterator(); iter.hasNext(); ) {
 77                String key = (String)iter.next();
 78                System.out.println("key: " + key + ", value: " + localMap.get(key));
 79            }

 80
 81           
 82            String newLicenseFile = "d:\\temp\\new.lic";
 83            ObjectOutputStream out3 = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(newLicenseFile)));
 84            out3.writeObject(localUserLicense1);
 85            out3.close();
 86
 87        }
 catch (Exception e) {
 88            e.printStackTrace();
 89            Assert.fail("faile to parse license. ");
 90        }
 finally {
 91            if (localObject1 != null{
 92                try {
 93                    ((ObjectInputStream) localObject1).close();
 94                }
 catch (IOException localIOException12) {
 95                }

 96            }

 97        }

 98
 99    }

100}

101
102  
103

 

 

这是我用反编译工具反编译出来的部分源码:

/*     */ package com.zeroturnaround.javarebel;
/*     */ public class jS
/*     */   implements dn


/* 405 */     if (localUserLicense != null) {
/*     */       try {
/* 407 */         if (eO.a(localUserLicense)) {
/* 408 */           jdField_a_of_type_Int = 1;
/*     */         }
/* 410 */         ObjectInputStream localObjectInputStream = new ObjectInputStream(new ByteArrayInputStream(localUserLicense.getLicense()));
/* 411 */         localMap = (Map)localObjectInputStream.readObject();
/* 412 */         localObjectInputStream.close();
/*     */
/* 414 */         if ((!("JavaRebel".equals(localMap.get("Product")))) && (!("JRebel".equals(localMap.get("Product"))))) {
/* 415 */           jdField_a_of_type_Int = 0;
/*     */         }
/* 417 */         iH.log("License information: " + localMap);
/*     */
/* 420 */         boolean bool1 = Boolean.valueOf((String)localMap.get("commercial")).booleanValue();
/* 421 */         if ((jdField_a_of_type_Int == 1) && (bool1)) {
/* 422 */           jdField_a_of_type_Int = 3;
/*     */         }
/*     */
/* 425 */         localObject = (String)localMap.get("limited");
/*     */
/* 427 */         if ((localObject != null) && (jdField_a_of_type_Int == 1)) {
/* 428 */           if (((String)localObject).equals("true")) {
/* 429 */             jdField_a_of_type_Int = 2;
/* 430 */             jn.a("License: evaluation");
/*     */           }
/* 432 */           else if (((String)localObject).equals("scala")) {
/* 433 */             jdField_a_of_type_Int = 2;
/* 434 */             jdField_b_of_type_Int |= 1;
/* 435 */             jn.a("License: scala");
/*     */           }
/* 437 */           else if (((String)localObject).equals("liverebel")) {
/* 438 */             jdField_a_of_type_Int = 2;
/* 439 */             jdField_b_of_type_Int |= 2;
/* 440 */             jn.a("License: liverebel");
/*     */           }
/*     */         }
/* 443 */         if (jdField_a_of_type_Int == 1) {
/* 444 */           localDate2 = (Date)localMap.get("validUntil");
/* 445 */           localDate3 = (Date)localMap.get("validFrom");
/*     */         }
/* 447 */         else if (jdField_a_of_type_Int == 2) {
/* 448 */           localDate2 = (Date)localMap.get("limitedUntil");
/* 449 */           localDate3 = (Date)localMap.get("limitedFrom");
/*     */         }
/*     */
/* 452 */         if (c.contains(localMap.get("uid")))
/* 453 */           jdField_a_of_type_Int = 0;
/*     */       }
/*     */       catch (Exception localException1)
/*     */       {
/* 457 */         iH.log("Exception checking the JRebel License");
/* 458 */         localException1.printStackTrace();
/* 459 */         iH.error(localException1);
/*     */       }
/*     */     }
/*     */
/* 463 */     iH.echo();
/* 464 */     iH.echo("#############################################################");
/* 465 */     iH.echo();
/* 466 */     iH.echo(" JRebel " + str1 + " (" + ((jdField_a_of_type_JavaLangClass == null) ? (jS.jdField_a_of_type_JavaLangClass = a("com.zeroturnaround.javarebel.java4.Install")) : jdField_a_of_type_JavaLangClass).getPackage().getImplementationTitle() + ")");
/* 467 */     iH.echo(" (c) Copyright ZeroTurnaround, Ltd, 2007-2009. All rights reserved.");
/* 468 */     iH.echo();
/*     */
/* 470 */     if (gA.c()) {
/*     */       try {
/* 472 */         NumberFormat localNumberFormat = NumberFormat.getNumberInstance();
/* 473 */         localNumberFormat.setMinimumFractionDigits(0);
/* 474 */         localNumberFormat.setMaximumFractionDigits(1);
/*     */
/* 476 */         String str3 = localNumberFormat.format(cU.a() * 96.0D / 3600.0D);
/* 477 */         localObject = localNumberFormat.format(cU.a() * 195.0D / 3600.0D);
/*     */
/* 479 */         String str4 = localNumberFormat.format(cU.b() * 96.0D / 3600.0D);
/* 480 */         String str5 = localNumberFormat.format(cU.b() * 195.0D / 3600.0D);
/*     */
/* 482 */         String str6 = "" + (cU.c() + 1);
/* 483 */         String str7 = "" + (cU.c() + 1);
/*     */
/* 485 */         iH.echo(" A rough estimate: Over the last " + str6 + " days JRebel ");
/* 486 */         iH.echo(" prevented the need for at least " + cU.a() + " redeploys/restarts.");
/* 487 */         iH.echo(" Using industry standard build and redeploy times, ");
/* 488 */         iH.echo(" JRebel saved you between " + str3 + " and " + ((String)localObject) + " hours.");
/*     */
/* 490 */         if (cU.c() > 60) {
/* 491 */           iH.echo(" Over the last " + str7 + " days JRebel saved you");
/* 492 */           iH.echo(" between " + str4 + " and " + str5 + " hours.");
/*     */         }
/*     */
/* 495 */         iH.echo();
/*     */       }
/*     */       catch (Exception localException2) {
/* 498 */         iH.error(localException2);
/*     */       }
/*     */     }
/*     */
/* 502 */     if (jdField_a_of_type_Int == 3) {
/* 503 */       jdField_a_of_type_Boolean = true;
/*     */
/* 505 */       str2 = (String)localMap.get("Seats");
/*     */
/* 507 */       bool2 = ("1".equals(str2)) && (((localMap.get("Organization") == null) || ("".equals(localMap.get("Organization"))) || (((String)localMap.get("Organization")).equalsIgnoreCase("personal"))));
/*     */
/* 511 */       localObject = new StringBuffer(" This product is licensed to ");
/* 512 */       if ((bool2) && (localMap.get("Name") != null) && (!("".equals(localMap.get("Name"))))) {
/* 513 */         ((StringBuffer)localObject).append(localMap.get("Name"));
/*     */
/* 515 */         if ((localMap.get("Organization") != null) && (!("".equals(localMap.get("Organization"))))) {
/* 516 */           ((StringBuffer)localObject).append(" (");
/* 517 */           ((StringBuffer)localObject).append(localMap.get("Organization"));
/* 518 */           ((StringBuffer)localObject).append(") ");
/*     */         }
/* 520 */         jn.a("License: personal");
/*     */       }
/*     */       else {
/* 523 */         ((StringBuffer)localObject).append(localMap.get("Organization"));
/* 524 */         jn.a("License: corporate");
/*     */       }
/*     */
/* 527 */       iH.echo(((StringBuffer)localObject).toString());
/*     */
/* 529 */       if ("Unlimited".equals(str2)) {
/* 530 */         iH.echo(" for unlimited number of developer seats on site.");
/*     */       }
/* 532 */       else if ((str2 != null) && (!(bool2))) {
/* 533 */         iH.echo(" for up to " + str2 + " developer seats on site. ");
/*     */       }
/* 535 */       else if (bool2) {
/* 536 */         iH.echo(" for personal use only. ");
/*     */       }
/*     */
/* 539 */       if ((localMap.get("Comment") != null) && (!("".equals(localMap.get("Comment"))))) {
/* 540 */         iH.echo(" " + localMap.get("Comment"));
/*     */       }
/*     */
/* 543 */       if (localDate2 != null) {
/* 544 */         a(localDate1, localDate2);
/*     */       }
/*     */
/* 547 */       iH.echo();
/* 548 */       iH.echo("#############################################################");
/* 549 */       iH.echo();
/*     */     }
/* 551 */     else if (jdField_a_of_type_Int == 2) {
/* 552 */       if (((jdField_b_of_type_Int & 0x2) == 0) && ((((localDate2 != null) && (localDate1.after(localDate2))) || ((localDate3 != null) && (localDate1.before(localDate3))))))
/*     */       {
/* 555 */         iH.echo(" YOUR JREBEL LIMITED LICENSE HAS EXPIRED!");
/*     */       }
/*     */       else {
/* 558 */         jdField_a_of_type_Boolean = true;
/*     */       }
/*     */
/* 561 */       if ((jdField_b_of_type_Int & 0x2) == 0) {
/* 562 */         str2 = (String)localMap.get("Seats");
/*     */
/* 564 */         bool2 = "1".equals(str2);
/*     */
/* 566 */         localObject = new StringBuffer(" This product is licensed to ");
/* 567 */         if ((bool2) && (localMap.get("Name") != null) && (!("".equals(localMap.get("Name"))))) {
/* 568 */           ((StringBuffer)localObject).append(localMap.get("Name"));
/*     */
/* 570 */           if ((localMap.get("Organization") != null) && (!("".equals(localMap.get("Organization"))))) {
/* 571 */             ((StringBuffer)localObject).append(" (");
/* 572 */             ((StringBuffer)localObject).append(localMap.get("Organization"));
/* 573 */             ((StringBuffer)localObject).append(") ");
/*     */           }
/*     */         }
/*     */         else {
/* 577 */           ((StringBuffer)localObject).append(localMap.get("Organization"));
/*     */         }
/*     */
/* 580 */         iH.echo(((StringBuffer)localObject).toString());
/*     */
/* 582 */         if (localDate2 != null) {
/* 583 */           iH.echo(" until " + SimpleDateFormat.getDateInstance(1, Locale.ENGLISH).format(localDate2));
/*     */         }
/*     */
/* 586 */         if ("Unlimited".equals(str2)) {
/* 587 */           iH.echo(" for unlimited number of developer seats on site.");
/*     */         }
/* 589 */         else if ((str2 != null) && (!("1".equals(str2)))) {
/* 590 */           iH.echo(" for up to " + str2 + " developer seats on site. ");
/*     */         }
/*     */
/* 593 */         if ((localMap.get("Comment") != null) && (!("".equals(localMap.get("Comment"))))) {
/* 594 */           iH.echo(" With the following restrictions: ");
/* 595 */           iH.echo(" " + ((String)localMap.get("Comment")));
/*     */         }
/*     */
/* 598 */         if (localDate2 != null) {
/* 599 */           a(localDate1, localDate2);
/*     */         }
/*     */       }
/*     */
/* 603 */       if (localMap.get("Organization") != null) {
/* 604 */         str2 = (String)localMap.get("Organization");
/* 605 */         if (str2.indexOf("[Open-Source]") != -1) {
/* 606 */           jn.a("Giveaway: OSS");
/*     */         }
/*     */
/*     */       }
/*     */
/* 613 */       iH.echo();
/* 614 */       iH.echo("#############################################################");
/* 615 */       iH.echo();
/*     */     }
/* 617 */     else if (jdField_a_of_type_Int == 1) {
/* 618 */       if ((localDate2 == null) || (localDate1.after(localDate2))) {
/* 619 */         iH.echo(" YOUR JREBEL EVALUATION LICENSE HAS EXPIRED!");
/*     */       }
/* 621 */       else if ((localDate3 == null) || (localDate1.before(localDate3))) {
/* 622 */         iH.echo(" YOUR JREBEL EVALUATION COULD NOT HAVE STARTED YET!");
/*     */       }
/*     */       else {
/* 625 */         jdField_a_of_type_Boolean = true;
/*     */
/* 627 */         long l1 = localDate2.getTime() - localDate1.getTime();
/* 628 */         long l2 = l1 / 86400000L;
/*     */
/* 630 */         iH.echo(" You are running JRebel evaluation license.");
/* 631 */         iH.echo(" You have " + (l2 + 1L) + " days until the license expires. ");
/* 632 */         iH.echo();
/* 633 */         iH.echo(" You will see this notification until you obtain a ");
/* 634 */         iH.echo(" full license for your installation. ");
/*     */       }
/* 636 */       iH.echo("                                                          ");
/* 637 */       iH.echo(" Visit www.jrebel.com for instructions on obtaining    ");
/* 638 */       iH.echo(" a full license. If you wish to continue your evaluation  ");
/* 639 */       iH.echo(" please e-mail to [email protected].             ");
/* 640 */       iH.echo("                                                          ");
/* 641 */       iH.echo(" If you think you should not see this message contact     ");
/* 642 */       iH.echo(" [email protected] or check that you have your   ");
/* 643 */       iH.echo(" license file in the same directory as the JAR file.      ");
/* 644 */       iH.echo("                                                          ");
/* 645 */       iH.echo("#############################################################");
/* 646 */       iH.echo();
/*     */
/* 649 */       eO.a(localUserLicense);
/*     */     }
/*     */     else {
/* 652 */       iH.echo(" YOU DO NOT HAVE A VALID JREBEL LICENSE!               ");
/* 653 */       iH.echo("                                                          ");
/* 654 */       iH.echo(" Visit www.jrebel.com for instructions on obtaining    ");
/* 655 */       iH.echo(" a full or evaluation license.                            ");
/* 656 */       iH.echo("                                                          ");
/* 657 */       iH.echo(" If you think you should not see this message contact     ");
/* 658 */       iH.echo(" [email protected] or check that you have your   ");
/* 659 */       iH.echo(" license file in the same directory as the JAR file.      ");
/* 660 */       iH.echo("                                                          ");
/* 661 */       iH.echo("#############################################################");
/* 662 */       iH.echo();
/*     */     }
/*     */
/* 665 */     if (!(jdField_a_of_type_Boolean)) {
/* 666 */       System.exit(1);
/*     */     }

 



你可能感兴趣的:(JRebal(原名JavaRebel)破解小记)