コード例 #1
0
        private void btnL2ToL1_Click(object sender, EventArgs e)
        {
            byte[] l2data = new byte[23];

            if (textL2Data.Text.Length != 23 * 2 && textL2Data.Text.Length != 23 * 3 - 1)
            {
                MessageBox.Show(this, "Supply 23 bytes L2 data ...");
                textL1burst0.Text = "";
                textL1burst1.Text = "";
                textL1burst2.Text = "";
                textL1burst3.Text = "";
                return;
            }

            ByteUtil.BytesFromString(textL2Data.Text, ref l2data);

            bool[][] l1bursts = new bool[4][];
            for (int i = 0; i < l1bursts.Length; i++)
            {
                l1bursts[i] = new bool[114];
            }

            SDCCHBurst sdcch = new SDCCHBurst();

            sdcch.L2DataAdd(l2data);
            sdcch.L2ToL1Convert();
            sdcch.L1BurstIGet(ref l1bursts);

            textL1burst0.Text = ByteUtil.BitsToString(l1bursts[0]);
            textL1burst1.Text = ByteUtil.BitsToString(l1bursts[1]);
            textL1burst2.Text = ByteUtil.BitsToString(l1bursts[2]);
            textL1burst3.Text = ByteUtil.BitsToString(l1bursts[3]);
        }
コード例 #2
0
        private void btnBoolGadConvert_Click(object sender, EventArgs e)
        {
            bool inputError   = false;
            bool dirBoolToGad = radioBoolToGad.Checked;

            if (dirBoolToGad)
            {
                if (textBool0.Text.Length != 114 || textBool1.Text.Length != 114 ||
                    textBool2.Text.Length != 114 || textBool3.Text.Length != 114)
                {
                    inputError = true;
                }
                MessageBox.Show("not supported yet!");
                return;
            }
            else
            {
                byte[] byteBuf = new byte[19];

                GSMParameters param = new GSMParameters();
                SDCCHBurst    sdcch = new SDCCHBurst();

                ByteUtil.BytesFromString(textGad0.Text, ref byteBuf);
                sdcch.ParseData(param, ByteUtil.BitsFromBytes(byteBuf), 0);

                ByteUtil.BytesFromString(textGad1.Text, ref byteBuf);
                sdcch.ParseData(param, ByteUtil.BitsFromBytes(byteBuf), 1);

                ByteUtil.BytesFromString(textGad2.Text, ref byteBuf);
                sdcch.ParseData(param, ByteUtil.BitsFromBytes(byteBuf), 2);

                ByteUtil.BytesFromString(textGad3.Text, ref byteBuf);
                sdcch.ParseData(param, ByteUtil.BitsFromBytes(byteBuf), 3);

                bool[][] boolBuf = new bool[4][];
                for (int i = 0; i < boolBuf.Length; i++)
                {
                    boolBuf[i] = new bool[114];
                }

                sdcch.L1BurstEGet(ref boolBuf);

                if (boolBuf == null)
                {
                    MessageBox.Show("error reading bits");
                    return;
                }

                textBool0.Text = ByteUtil.BitsToString(boolBuf[0]);
                textBool1.Text = ByteUtil.BitsToString(boolBuf[1]);
                textBool2.Text = ByteUtil.BitsToString(boolBuf[2]);
                textBool3.Text = ByteUtil.BitsToString(boolBuf[3]);
            }
        }
コード例 #3
0
ファイル: KrakenNet.cs プロジェクト: g3gg0/rx-fft
    public override byte[] RequestResult(bool[] key1, uint count1, bool[] key2, uint count2)
    {
        int tries = 0;

        /* using a goto label to restart instead of recurse */
restart:
        tries++;
        if (tries >= 10)
        {
            Log.AddMessage("KrakenNet", "RequestResult(): Tried to request crack " + tries + " times now... Abort!");
            return(null);
        }

        /* do we have data for this request already in cache? */
        string request = "crack " + ByteUtil.BitsToString(key1) + " " + count1 + " " + ByteUtil.BitsToString(key2) + " " + count2;

        byte[] result = new byte[8];

        if (CheckScanResult(request, ref result))
        {
            return(result);
        }

        /* wait until we have a connection */
        if (!InKrakenNet)
        {
            if (Jid != "")
            {
                Log.AddMessage("KrakenNet", "RequestResult(): Not connected. Waiting until reconnected.");

                while (!InKrakenNet)
                {
                    Thread.Sleep(100);
                }
            }
            else
            {
                Log.AddMessage("KrakenNet", "RequestResult(): Not Configured. Quitting.");
                return(null);
            }
        }

        /* no key cached, try to find a node that cracks the key */
        NodeStatus node = GetBestNode();

        if (node == null)
        {
            Log.AddMessage("KrakenNet", "RequestResult(): Waiting for (usable) Kraken hosts to appear... " + KrakenNodes.Count + " found, but none in a usable state.");
            while (node == null)
            {
                node = GetBestNode();
                Thread.Sleep(100);

                /* restart if there are network problems */
                if (!InKrakenNet)
                {
                    goto restart;
                }
            }
        }

        /* that should not be entered */
        if (node == null)
        {
            Log.AddMessage("KrakenNet", "RequestResult(): No usable node found");
            return(null);
        }

        Log.AddMessage("KrakenNet", "RequestResult(): Will choose " + node.Name + " for cracking.");

        /* make sure we enter this only once and lock from changes done in "Disconnect" */
        lock (this)
        {
            KrakenNetConnection conn = null;

            lock (Connections)
            {
                /* already connected? */
                if (!Connections.ContainsKey(node.Name))
                {
                    conn = new KrakenNetConnection(Client, node.Name);
                    Connections.Add(node.Name, conn);
                }
            }

            /* newly added? */
            if (conn != null)
            {
                /* failed to communicate with node? */
                if (!conn.Available)
                {
                    /* mark as unusable, remove and recurse */
                    node.Unusable = true;
                    conn.CloseConnection();
                    Connections.Remove(node.Name);

                    /* repeat until working node found or no more nodes */
                    goto restart;
                }
            }

            /* is this connection already closed */
            if (Connections[node.Name].State != KrakenNetConnection.eConnState.Ready)
            {
                node.Unusable = true;
                Connections.Remove(node.Name);

                /* repeat until working node found or no more nodes */
                goto restart;
            }

            /* increase internal sotred node load to decrease node priority */
            node.Load += node.Increment;
        }

        try
        {
            result = Connections[node.Name].RequestResult(key1, count1, key2, count2);
            AddScanResult(request, result);

            return(result);
        }
        catch (ThreadAbortException e)
        {
            Connections[node.Name].CancelRequest();
            throw e;
        }
        catch (Exception e)
        {
            Log.AddMessage("KrakenNet", "RequestResult(): Caught '" + e.GetType().ToString() + "'. Retry.");
            goto restart;
        }
    }
コード例 #4
0
ファイル: KrakenNetConnection.cs プロジェクト: g3gg0/rx-fft
        public byte[] RequestResult(bool[] key1, uint count1, bool[] key2, uint count2)
        {
            string request = "crack " + ByteUtil.BitsToString(key1) + " " + count1 + " " + ByteUtil.BitsToString(key2) + " " + count2;

            object        signal = new object();
            StringBuilder result = new StringBuilder();

            KrakenJobStatus = KrakenJobStatus.Submitted;
            QueueCommand(request, signal, result, int.MaxValue);

            lock (signal)
            {
                if (Monitor.Wait(signal))
                {
                    string ret = result.ToString();

                    int    code = -1;
                    int    id   = -1;
                    string msg  = "";

                    ParseResponseString(ret, out code, out id, out msg);

                    switch (code)
                    {
                    case 200:
                        CurrentRequestId = -1;
                        KrakenJobStatus  = KrakenJobStatus.Found;

                        /* split into literals */
                        string[] fields = ret.Split(' ');
                        if (fields.Length < 3)
                        {
                            return(null);
                        }

                        /* the 3rd literal is the found key */
                        string keystring = fields[2];
                        byte[] key       = new byte[8];

                        for (int pos = 0; pos < 8; pos++)
                        {
                            string byteStr = keystring.Substring(pos * 2, 2);

                            if (!byte.TryParse(byteStr, System.Globalization.NumberStyles.HexNumber, null, out key[pos]))
                            {
                                key = null;
                                break;
                            }
                        }

                        ParseSearchDuration(ret);

                        return(key);

                    case 404:
                        /* key not found */
                        CurrentRequestId = -1;
                        KrakenJobStatus  = KrakenJobStatus.NotFound;
                        ParseSearchDuration(ret);
                        return(null);

                    case 405:
                        /* job was cancelled */
                        CurrentRequestId = -1;
                        KrakenJobStatus  = KrakenJobStatus.Cancelled;
                        return(null);

                    default:
                        Log.AddMessage(Remote, "Last message unhandled");
                        break;
                    }
                }
            }

            return(null);
        }
コード例 #5
0
        public virtual byte[] RequestResult(bool[] key1, uint count1, bool[] key2, uint count2)
        {
            if (!Connected)
            {
                Reconnect();
            }

            lock (this)
            {
                string request = "crack " + ByteUtil.BitsToString(key1) + " " + count1 + " " + ByteUtil.BitsToString(key2) + " " + count2;
                byte[] result  = new byte[8];

                RequestId = -1;

                Log.AddMessage("Kraken: > '" + request.Substring(0, 35) + "...'");

                /* do we have data for this request already in cache? */
                if (CheckScanResult(request, ref result))
                {
                    return(result);
                }

                try
                {
                    /* try a few times to get the key cracked */
                    for (int tries = 0; tries < 3; tries++)
                    {
                        DataStream.Flush();
                        Write(request);
                        KrakenJobStatus = KrakenJobStatus.Submitted;

                        result = GetResult();

                        if (result != null)
                        {
                            /* found valid key, add result and jump out of loop */
                            AddScanResult(request, result);
                            break;
                        }
                        else if (KrakenJobStatus == KrakenJobStatus.NotFound)
                        {
                            /* found no valid key, add result and jump out of loop */
                            AddScanResult(request, result);
                            break;
                        }
                        else
                        {
                            /* there went something wrong */

                            KrakenJobStatus = KrakenJobStatus.Unknown;

                            Log.AddMessage("KrakenClient", "Failed to crack. Reconnecting");
                            Reconnect();

                            /* cancel old job with the new connection */
                            if (RequestId != -1)
                            {
                                Log.AddMessage("KrakenClient", "   + cancel job " + RequestId);
                                Write("cancel " + RequestId);
                                RequestId = -1;
                            }
                        }
                    }
                }
                catch (ThreadAbortException ex)
                {
                    /* try to cancel job with new connection */
                    if (RequestId != -1)
                    {
                        Log.AddMessage("KrakenClient", "Aborting. Reconnecting to cancel job" + RequestId);
                        Reconnect();
                        Write("cancel " + RequestId);
                        Disconnect();
                        Log.AddMessage("KrakenClient", "Aborting finished");
                        RequestId = -1;
                    }
                }

                RequestId = -1;
                return(result);
            }
        }
コード例 #6
0
        private void btnEncryptToL1_Click(object sender, EventArgs e)
        {
            bool error = false;

            if (textL2Data.Text.Length != 23 * 2 && textL2Data.Text.Length != 23 * 3 - 1)
            {
                MessageBox.Show(this, "Supply 23 bytes L2 data ...");
                error = true;
            }

            if (textKc.Text.Length != 8 * 2)
            {
                MessageBox.Show(this, "Supply 8 bytes Kc ...");
                error = true;
            }

            if (textFN.Text.Length == 0)
            {
                MessageBox.Show(this, "Supply frame number ...");
                error = true;
            }

            if (error)
            {
                textL1crypt0.Text = "";
                textL1crypt1.Text = "";
                textL1crypt2.Text = "";
                textL1crypt3.Text = "";
                return;
            }

            byte[] l2data = new byte[23];

            ByteUtil.BytesFromString(textL2Data.Text, ref l2data);

            bool[][] l1bursts = new bool[4][];
            for (int i = 0; i < l1bursts.Length; i++)
            {
                l1bursts[i] = new bool[114];
            }

            SDCCHBurst sdcch = new SDCCHBurst();

            sdcch.L2DataAdd(l2data);
            sdcch.L2ToL1Convert();
            sdcch.L1BurstIGet(ref l1bursts);

            /* crypt it */
            byte[] kc = new byte[8];
            ByteUtil.BytesFromString(textKc.Text, ref kc);

            GSMParameters param = new GSMParameters();

            param.FN = uint.Parse(textFN.Text);

            CryptA5 A5Algo = new CryptA5(kc);

            if (radioSameFN.Checked)
            {
                A5Algo.CryptDownlink(l1bursts[0], param.Count);
                A5Algo.CryptDownlink(l1bursts[1], param.Count);
                A5Algo.CryptDownlink(l1bursts[2], param.Count);
                A5Algo.CryptDownlink(l1bursts[3], param.Count);
            }
            else
            {
                A5Algo.CryptDownlink(l1bursts[0], param.Count);
                param.FN++;
                A5Algo.CryptDownlink(l1bursts[1], param.Count);
                param.FN++;
                A5Algo.CryptDownlink(l1bursts[2], param.Count);
                param.FN++;
                A5Algo.CryptDownlink(l1bursts[3], param.Count);
            }

            textL1crypt0.Text = ByteUtil.BitsToString(l1bursts[0]);
            textL1crypt1.Text = ByteUtil.BitsToString(l1bursts[1]);
            textL1crypt2.Text = ByteUtil.BitsToString(l1bursts[2]);
            textL1crypt3.Text = ByteUtil.BitsToString(l1bursts[3]);
        }