View Single Post
  #1  
Old 04-25-2014, 13:23
kheung kheung is offline
Friend
 
Join Date: Feb 2002
Location: China
Posts: 17
Rept. Given: 1
Rept. Rcvd 2 Times in 1 Post
Thanks Given: 0
Thanks Rcvd at 3 Times in 1 Post
kheung Reputation: 2
Keymaker for JxB v1.5 demo version (Windows)

Demo version download
Code:
import java.io.*;
import java.lang.Runtime;
import java.util.Scanner;
import java.nio.ByteBuffer;
import java.security.*;
import java.math.*;

class MakeKey
{
  private static String getSN()
  {
    String s = null;
    Runtime runtime = Runtime.getRuntime();
    Process process;
    try {
      String as[] = {"wmic", "bios", "get", "serialnumber"};
      process = runtime.exec(as);
    } catch(IOException _ex) {
      return null;
    }

    Scanner scanner = new Scanner(process.getInputStream());
    while(scanner.hasNext()) {
      if("SerialNumber".equals(scanner.next())) {
        s = scanner.next().trim();
        break;
      }
    }

    scanner.close();

    return s;
  }

  private static int sum(int i)
  {
    int j = 0;
    for(; i > 0; i >>= 4)
      j += i & 0xf;

    return j % 10;
  }

  private static byte[] reverseBytes(byte ab[])
  {
    byte [] aout = new byte[ab.length];
    for(int i=0; i < ab.length; ++i)
      aout[i] = ab[ab.length -i - 1];
    return aout;
  }

  private static String getKey(long machineId, long unixTime)
  {
    int i = (int)(machineId & -1);
    int j = (int)(machineId >> Integer.SIZE & -1);
    int i1 = i + 0xf5ef08cb + 0x11223344 & -1;
    int j1 = (j - 0xbb87db7) + 0x55667788 & Integer.MAX_VALUE;

    ByteBuffer bb = ByteBuffer.allocateDirect(8);
    bb.putInt(j1);
    bb.putInt(i1);
    bb.rewind();
    long l = bb.getLong();
    int d = (int)unixTime ^ 0x56739acd;

    return String.format("%dZ%d%d", l, d, sum(d));
  }

  public static void main(String [ ] args)
  {
    long machineId = 0;
    String sn = getSN();

    try {
      MessageDigest md = MessageDigest.getInstance("MD5");
      byte[] ba = reverseBytes(md.digest(sn.getBytes()));
      ByteBuffer bb = ByteBuffer.allocateDirect(ba.length);

      bb.put(ba);
      bb.rewind();
      machineId = bb.getLong(Long.SIZE / Byte.SIZE);
    } catch (Exception e) {
      System.out.println("Error: " + e);
    }
    System.out.println("Machine Serial: " + sn);
    long unixTime = System.currentTimeMillis() / 1000L + 86400 * 365 * 3 - 86400 * 13;
    System.out.println("Demo Key: " + getKey(machineId, unixTime));
  }
}
Reply With Quote
The Following 2 Users Gave Reputation+1 to kheung For This Useful Post:
papi (05-02-2014)