示例#1
0
 private void ModernDecypherShortBtn_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(ModernShortOutputTxt.Text))
     {
         ModernShortInputTxt.Text = Modern.DecypherShort(HMessage.ToBytes(ModernShortOutputTxt.Text)).ToString();
     }
 }
示例#2
0
        private void DataFromClient(IAsyncResult iAr)
        {
            try
            {
                if (_clientS == null)
                {
                    return;
                }
                int length = _clientS.EndReceive(iAr);
                if (length < 1)
                {
                    Disconnect(); return;
                }

                byte[] data = ByteUtils.CopyBlock(_clientB, 0, length);
                #region Official Socket Check
                if (!_hasOfficialSocket)
                {
                    bool isModern = Modern.DecypherShort(data, 4) == 4000;
                    if (_hasOfficialSocket = (isModern || Ancient.DecypherShort(data, 3) == 206))
                    {
                        ResetHost();

                        _htcpExt.Stop();
                        _htcpExt = null;

                        Protocol = isModern ? HProtocol.Modern : HProtocol.Ancient;
                        OnConnected(EventArgs.Empty);
                    }
                    else
                    {
                        SendToServer(data);
                        return;
                    }
                }
                #endregion
                #region Decrypt/Split
                if (ClientDecrypt != null)
                {
                    ClientDecrypt.Parse(data);
                }

                if (_toServerS == 3 && Protocol == HProtocol.Modern)
                {
                    int dLength = data.Length >= 6 ? Modern.DecypherInt(data) : 0;
                    RequestEncrypted = (dLength != data.Length - 4);
                }

                byte[][] chunks = RequestEncrypted ? new[] { data } : ByteUtils.Split(ref _clientC, data, HDestination.Server, Protocol);
                #endregion

                foreach (byte[] chunk in chunks)
                {
                    ProcessOutgoing(chunk);
                }

                ReadClientData();
            }
            catch { Disconnect(); }
        }
示例#3
0
        public Rc4(int key)
        {
            key = key < 0 ? 0 : key;
            var nKey = new[] { (byte)key };

            if (key > byte.MaxValue)
            {
                nKey = key > ushort.MaxValue ? Modern.CypherInt(key) : Modern.CypherShort((ushort)key);
            }
            Initialize(nKey);
        }
示例#4
0
        private void ModernCypherShortBtn_Click(object sender, EventArgs e)
        {
            ushort value;

            if (ushort.TryParse(ModernShortInputTxt.Text, out value))
            {
                ModernShortOutputTxt.Text = HMessage.ToString(Modern.CypherShort(value));
            }
            else
            {
                MessageBox.Show(NotUInt16, TanjiError, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#5
0
        private void ModernCypherIntegerBtn_Click(object sender, EventArgs e)
        {
            int value;

            if (int.TryParse(ModernIntegerInputTxt.Text, out value))
            {
                ModernIntegerOutputTxt.Text = HMessage.ToString(Modern.CypherInt(value));
            }
            else
            {
                MessageBox.Show(NotInt32, TanjiError, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#6
0
        private void DataFromServer(IAsyncResult iAr)
        {
            try
            {
                if (_serverS == null)
                {
                    return;
                }
                int length = _serverS.EndReceive(iAr);
                if (length < 1)
                {
                    Disconnect(); return;
                }

                byte[] data = ByteUtils.CopyBlock(_serverB, 0, length);
                try
                {
                    #region Decrypt/Split
                    if (ServerDecrypt != null)
                    {
                        ServerDecrypt.Parse(data);
                    }

                    if (_toClientS == 2)
                    {
                        int dLength = Modern.DecypherInt(data);
                        ResponseEncrypted = (dLength > data.Length - 4 || dLength < 6);
                    }

                    byte[][] chunks = ResponseEncrypted ? new[] { data } : ByteUtils.Split(ref _serverC, data, HDestination.Client, HProtocol.Modern);
                    #endregion
                    foreach (byte[] chunk in chunks)
                    {
                        if (Modern.DecypherShort(chunk, 4) == 4000)
                        {
                            Disconnect(); return;
                        }

                        ++_toClientS;
                        if (DataToClient != null)
                        {
                            try { DataToClient(this, new DataToEventArgs(chunk, HDestination.Client, _toClientS)); }
                            catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
                        }
                    }
                }
                catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
                ReadServerData();
            }
            catch (Exception ex) { Disconnect(); Debug.WriteLine(ex.ToString()); }
        }
示例#7
0
        //abstract public int LandLot;
        // etc.

        protected static BuildingStyles Generate(Tech.TechLevel techLevel)
        {
            BuildingStyles retval = null;

            // Example:
            switch (techLevel)
            {
            case Tech.TechLevel.MODERN:
                retval = new Modern();
                break;
            }

            return(retval);
        }
示例#8
0
        private void DataFromServer(IAsyncResult iAr)
        {
            try
            {
                if (_serverS == null)
                {
                    return;
                }
                int length = _serverS.EndReceive(iAr);
                if (length < 1)
                {
                    Disconnect(); return;
                }

                byte[] data = ByteUtils.CopyBlock(_serverB, 0, length);
                #region Official Socket Check
                if (!_hasOfficialSocket)
                {
                    SendToClient(data);
                    _htcpExt.BeginAcceptSocket(SocketAccepted, null);
                    return;
                }
                #endregion
                #region Decrypt/Split
                if (ServerDecrypt != null)
                {
                    ServerDecrypt.Parse(data);
                }

                if (_toClientS == 2 && Protocol == HProtocol.Modern)
                {
                    int dLength = data.Length >= 6 ? Modern.DecypherInt(data) : 0;
                    ResponseEncrypted = (dLength != data.Length - 4);
                }

                byte[][] chunks = ResponseEncrypted ? new[] { data } : ByteUtils.Split(ref _serverC, data, HDestination.Client, Protocol);
                #endregion

                foreach (byte[] chunk in chunks)
                {
                    ProcessIncoming(chunk);
                }

                ReadServerData();
            }
            catch { Disconnect(); }
        }
示例#9
0
        public DencProgram(Architecture architecture, IEnumerable <IStatement> statementlist)
        {
            ArchitectureElement = architecture;

            switch (ArchitectureElement.ArchType.ToLowerInvariant().Trim())
            {
            case "pdp10":
                Architecture = new PDP10(this);
                break;

            case "modern":
                Architecture = new Modern(this);
                break;

            default:
                throw new ApplicationException("Unknown architecture specified");
            }

            foreach (var s in statementlist)
            {
                if (s == null)
                {
                    continue;
                }

                if (s is NameSpace)
                {
                    ProgNameSpace = (NameSpace)s;
                    continue;
                }
                if (s is ClassHeir)
                {
                    var c = (ClassHeir)s;
                    ClassList.Add(c);
                    continue;
                }

                throw new ApplicationException("Unknown Root Statement: " + s.GetType());
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            var bmw = new Modern("BMW", "R1150-RT", 2005);

            var honda = new Vintage("Honda", "Nighthawk 700SC", 1986);

            var grassroots = new IPA("Calfkiller", "Grassroots", 5.7, "unknown");

            var getUpGetDown = new Stout("Wiseacre", "Gotta Get Up To Get Down", 5, true);

            var elijah = new Bourbon("Elijah Craig", "Small Batch", "94", "Kentucky");

            var balcones = new Bourbon("Balcones", "True Blue", "100", "Texas");

            var sarah = new Female("Sarah", "Silverman", "Jesus Is Magic");

            var cross = new Male("David", "Cross", "Mr. Show");


            Console.WriteLine("These are my current favorite motorcycles:");
            Console.WriteLine(bmw.Year + " " + bmw.Make + " " + bmw.Model);
            Console.WriteLine(honda.Year + " " + honda.Make + " " + honda.Model);
            Console.WriteLine("");
            Console.WriteLine("These are some of my favorite beers:");
            Console.WriteLine(grassroots.Brand + " " + grassroots.Name + " is " + grassroots.Abv + "%");
            Console.WriteLine(getUpGetDown.Brand + " " + getUpGetDown.Name + " is a " + getUpGetDown.Abv + "%");
            Console.WriteLine("");
            Console.WriteLine("These are some of my favorite whiskeys:");
            Console.WriteLine(elijah.Brand + " " + elijah.Name + " is " + elijah.Proof + " proof");
            Console.WriteLine(balcones.Brand + " " + balcones.Name + " is " + balcones.Proof + " proof");
            Console.WriteLine("");
            Console.WriteLine("These are some of my favorite comedians:");
            Console.WriteLine(sarah.FirstName + " " + sarah.LastName + " was awesome in '" + sarah.BestWork + "'");
            Console.WriteLine(cross.FirstName + " " + cross.LastName + " was awesome in '" + cross.BestWork + "'");

            Console.ReadKey();
        }
示例#11
0
        private void ReconstructList(bool stringsOnly)
        {
            BeginUpdate();
            for (int i = 0; i < _chunks.Count; i++)
            {
                object chunk = _chunks[i];
                if (!(chunk is string) && stringsOnly)
                {
                    continue;
                }
                string encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, chunk));
                Items[i].SubItems[2].Text = encoded;

                var value = chunk as string;
                if (value != null)
                {
                    string encodedLength = string.Empty;
                    if ((Destination == HDestination.Server && Protocol == HProtocol.Ancient) || Protocol == HProtocol.Modern)
                    {
                        ushort valueLength = (ushort)value.Length;
                        byte[] data        = Protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength);
                        encodedLength = HMessage.ToString(data) + " | ";
                    }

                    Items[i].ToolTipText = string.Format("Type: String\nValue: {0}\n{1}Encoded: {2}", value, string.Format("Length: {0}{1}\n", encodedLength, value.Length), encoded);
                }
                else
                {
                    Items[i].ToolTipText = Items[i].ToolTipText.Replace(Items[i].ToolTipText.GetChild("Encoded: ", '\n'), encoded);
                }
            }
            EndUpdate();
        }
示例#12
0
        public void ReplaceSelected(object value)
        {
            _lastHeader = 0;
            int index = SelectedIndices[0];

            if (value.Equals(_chunks[index]))
            {
                return;
            }

            _chunks[index] = value;
            ListViewItem curItem = Items[index];
            string       type    = value is string? "String" : value is int? "Integer" : "Boolean";
            string       encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, value));

            curItem.SubItems[0].Text = type;
            curItem.SubItems[1].Text = value.ToString();
            curItem.SubItems[2].Text = encoded;
            string encodedLength = string.Empty;

            if (value is string)
            {
                if ((Destination == HDestination.Server && Protocol == HProtocol.Ancient) || Protocol == HProtocol.Modern)
                {
                    ushort valueLength = (ushort)value.ToString().Length;
                    byte[] data        = Protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength);
                    encodedLength = HMessage.ToString(data) + " | ";
                }
            }
            curItem.ToolTipText = string.Format("Type: {0}\nValue: {1}\n{2}Encoded: {3}", type, value, string.Format("Length: {0}{1}\n", encodedLength, value.ToString().Length), encoded);
        }
示例#13
0
        public void AppendChunk(string value)
        {
            _chunks.Add(value);

            string encodedLength = string.Empty;
            string encoded       = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, value));

            if (Destination == HDestination.Server || Protocol == HProtocol.Modern)
            {
                ushort valueLength = (ushort)value.Length;
                byte[] data        = Protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength);
                encodedLength = HMessage.ToString(data) + " | ";
            }
            AddItemChunk("String", value, encoded, string.Format("Length: {0}{1}\n", encodedLength, value.Length));
        }