DEV BlackBerry Engineering Screens

Thảo luận trong 'DEV - Khu Vực Dành Cho Lập Trình Viên' bắt đầu bởi Aric Lam, 9/10/12.

  1. Aric Lam Go & Let's go

    Trên tất cả các thiết bị BlackBerry (OS 4.0 hoặc hơn) đều có một màn hình kỹ thuật (Escreen ). để kích hoạt màn hình này chung ta phải thông qua một đoạn mã. đoạn mã này được tạo ra từ PIN, Phiên bản ứng dụng (OS), và thời gian hoạt động thực (Uptime) trên thiết bị đó.

    Các bạn phải kích hoạt màn hình "Help Me!" (Alt+Shift+H /...) và gõ nhập trực tiếp đoạn mã được tạo ra từ code bên dưới. Các bạn sẽ kích hoạt được màn hình Escreen.
    Mã:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
     
    import java.security.InvalidKeyException;
    import java.security.NoSuchAlgorithmException;
    import javax.crypto.Mac;
    import javax.crypto.spec.SecretKeySpec;
     
     
    public class EScreenWizard
    {
            private static final String HMAC_KEY = "Up the time stream without a TARDIS";
         
            private static final String[] DURATION_KEY = {
                    "",
                    "Hello my baby, hello my honey, hello my rag time gal",
                    "He was a boy, and she was a girl, can I make it any more obvious?",
                    "So am I, still waiting, for this world to stop hating?",
                    "I love myself today, not like yesterday. I'm cool, I'm calm, I'm gonna be okay"};
         
            private static final String[] DURATION_LEN = {
                    "1 day",
                    "3 days",
                    "7 days",
                    "15 days",
                    "30 days"};
         
            public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException
            {
                    BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
                    System.out.println("BlackBerry Engineering Screen Unlock Code Generator");
                    System.out.println();
                 
                    // get the data that is used to generate the key
                    System.out.print("App Version: ");
                    String appVer = console.readLine();
                    System.out.print("PIN: ");
                    String pin = console.readLine();
                    System.out.print("Uptime: ");
                    String uptime = console.readLine();
                    System.out.println();
                 
                    // generate the HMAC-SHA1 for all 5 possible codes
                    for (int duration = 0; duration < 5; duration++)
                    {
                            // get an hmac_sha1 key from the raw key bytes
                            SecretKeySpec signingKey = new SecretKeySpec(HMAC_KEY.getBytes(), "HmacSHA1");
                            Mac mac = Mac.getInstance("HmacSHA1");
                            mac.init(signingKey);
         
                            // generate the data
                            StringBuffer buffer = new StringBuffer();
                         
                            buffer.append(pin.toLowerCase());
                            buffer.append(appVer.toLowerCase()); 
                            buffer.append(uptime.toLowerCase());
                         
                            buffer.append(DURATION_KEY[duration]);
                            String data = buffer.toString();
                         
                            // compute the hmac on input data bytes
                            byte[] rawHmac = mac.doFinal(data.getBytes());
         
                            System.out.println("Unlock code [" + DURATION_LEN[duration] + "]: " + makeDigestString(rawHmac).split(" ")[0]);
                    }
            }
         
            private static String makeDigestString(byte[] input)
            {
                    StringBuffer buffer = new StringBuffer();
                    for (int i = 0; i < input.length; i++)
                    {
                            if (i % 4 == 0 && i != 0)
                                    buffer.append(" ");
                            int x = (int)input[i];
                            if (x < 0)
                                    x += 256;
                            if (x < 16)
                                    buffer.append("0");
                            buffer.append(Integer.toString(x, 16));
                    }
                    return buffer.toString();
            }
    }
    Zerostar thích bài này.
  2. khacduy88 Well-Known Member

    Hix.....vậy làm thế nào code trên C# đây, trong C# hem cóa thấy tụi này:
    import java.security.InvalidKeyException;
    import java.security.NoSuchAlgorithmException;
    import javax.crypto.Mac;
    import javax.crypto.spec.SecretKeySpec;


    :(
  3. Aric Lam Go & Let's go

    Đây là khu vực java mà =)):D
  4. Gõ trực tíêp trên bb cả 1 đoạn dài thế kia cơ á
  5. Aric Lam Go & Let's go

    gõ nhiêu đó chết ừ....
  6. tiencm Member

    Đoạn code trên là để tạo mã vào EScreen thui mà, chạy đoạn code đó là ra :D
  7. giahinhphat Member

  8. Sao mình bấm Alt+Shift+H trên 9900 phát nó vào thẳng cái màn hình EScreen luôn là sao nhờ Y_Y