1 13 package org.jahia.tools; 14 15 import java.io.ByteArrayInputStream ; 16 import java.io.DataInputStream ; 17 import java.io.EOFException ; 18 import java.io.File ; 19 import java.io.FileInputStream ; 20 import java.io.IOException ; 21 import java.util.zip.CRC32 ; 22 23 27 public class ReadLicense 28 { 29 private static final String LICENSE_FILENAME = "jahia.license"; 30 31 32 public static void main (String args[]) 34 { 35 System.out.println ("\nLicense key reader, version 1.0"); 36 System.out.println ("(c) Jahia Ltd 2002\n\n"); 37 38 try { 39 File file = new File (LICENSE_FILENAME); 40 41 FileInputStream fstream = new FileInputStream (file); 42 DataInputStream stream = new DataInputStream (fstream); 43 44 int streamSize = (new Long (file.length() - 10)).intValue(); 47 byte[] bytes = new byte[streamSize]; 48 int index = 0; 49 50 short crcOffset = stream.readShort (); 51 for (int i=0; i<crcOffset; i++) { 53 bytes[index] = stream.readByte(); 54 index++; 55 } 56 57 long storedChecksum = stream.readLong (); 58 System.out.println (" stored checksum = "+Long.toHexString (storedChecksum)); 59 60 try { 62 while (index < bytes.length) { 63 bytes[index] = stream.readByte(); 64 index++; 65 } 66 } 67 catch (EOFException ex) { 68 } 69 70 fstream.close(); 72 stream = null; 73 fstream = null; 74 file = null; 75 76 78 CRC32 crc = new CRC32 (); 80 crc.update (bytes); 81 82 long streamChecksum = crc.getValue (); 83 85 ByteArrayInputStream byteStream = new ByteArrayInputStream (bytes); 87 stream = new DataInputStream (byteStream); 88 int offset = 0; 89 90 91 92 94 try { 95 offset = stream.readInt (); 97 stream.skipBytes(offset); 98 int licenseType = stream.readInt(); 99 System.out.println (" - license type = "+licenseType); 100 } catch ( Throwable t ){ 101 System.out.println (" - error reading license type"); 102 return; 103 } 104 105 try { 106 offset = stream.readInt (); 108 stream.skipBytes(offset); 109 int pageLimit = stream.readInt(); 110 System.out.println (" - page limit = "+pageLimit); 111 } catch ( Throwable t ){ 112 System.out.println (" - error reading page limit"); 113 return; 114 } 115 116 try{ 117 offset = stream.readInt (); 119 stream.skipBytes(offset); 120 int templateLimit = stream.readInt(); 121 System.out.println (" - template limit = "+templateLimit); 122 } catch ( Throwable t ){ 123 System.out.println (" - error reading page template limit"); 124 return; 125 } 126 127 try { 128 offset = stream.readInt (); 130 stream.skipBytes(offset); 131 int userLimit = stream.readInt(); 132 System.out.println (" - user limit = "+userLimit); 133 } catch ( Throwable t ){ 134 System.out.println (" - error reading user limit"); 135 return; 136 } 137 138 try { 139 offset = stream.readInt (); 141 stream.skipBytes(offset); 142 int siteLimit = stream.readInt(); 143 System.out.println (" - site limit = "+siteLimit); 144 } catch ( Throwable t ){ 145 System.out.println (" - error reading site limit"); 146 return; 147 } 148 149 try { 150 offset = stream.readInt (); 152 stream.skipBytes(offset); 153 int nbBytes = stream.readInt(); 154 byte[] stringAsBytes = new byte[nbBytes]; 155 stream.read(stringAsBytes); 156 String licenseID = new String (stringAsBytes,"UTF-16"); 157 System.out.println (" - license id = "+licenseID); 158 } catch ( Throwable t ){ 159 System.out.println (" - error reading license type"); 160 return; 161 } 162 163 try { 164 offset = stream.readInt (); 166 stream.skipBytes(offset); 167 int buildNumber = stream.readInt(); 168 System.out.println (" - build number = "+buildNumber); 169 } catch ( Throwable t ){ 170 System.out.println (" - error reading build number"); 171 return; 172 } 173 174 try { 175 offset = stream.readInt (); 177 stream.skipBytes(offset); 178 double releaseNumber = stream.readDouble(); 179 System.out.println (" - release number = "+releaseNumber); 180 } catch ( Throwable t ){ 181 System.out.println (" - error reading release number"); 182 return; 183 } 184 185 System.out.println ("\nLicense file successfully readed."); 186 187 } 188 catch (IOException ex) { 189 return; 191 } 192 193 } 194 195 196 private static void DisplayBytes (byte[] bytes) 198 { 199 201 for (int i=0; i<bytes.length; i++) { 202 } 204 205 } 207 208 209 } 210 | Popular Tags |