1. #1

    Registriert seit
    09.11.2011
    Beiträge
    140
    Thanked 153 Times in 59 Posts

    Standard :-Token (Module) parsen/schreiben

    Hi,

    jeder von euch kennt bestimmt das :-Token, auch bezeichnet als Module-Token. Ich habe mich mal mit dem Applet beschäftigt und entstanden ist eine Klasse (inkl. 2 Klassen zum Lesen/Schreiben), die das Token parsen kann.


    Außerdem habe ich noch ein Sample für euch geschrieben, damit ihr nachvollziehen könnt, wie das Ganze funktioniert. Mit der Klasse könnt ihr aber nicht nur das :-Token parsen, sondern selber auch Pakete erzeugen.

    Zuerst braucht man eine Instanz mit dem Protokollstring.

    Diese Instanz ist sehr wichtig, da mit ihr dann alles andere geregelt wird (Pakete erzeugen und lesen).

    Außerdem habe ich beim Reversen die Methodennamen verändert, damit man besser nachvollziehen kann, was genau welche Methode macht. (jedoch nicht bei allen)

    Kommen wir zur Module-Klasse:

    PHP-Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    using System.IO;

    namespace 
    Knuddels_Reverse
    {
        class 
    Module
        
    {
            private 
    Hashtable i;
            private 
    Hashtable g;
            private 
    int id;
            private 
    Hashtable values;
            private 
    String protocolHash;
            private 
    ArrayList names;
            private 
    ArrayList f;
            private 
    int startValue;
            private 
    string protocolString;
            private 
    int protocolIndex;
            private 
    ArrayList n;

            public 
    String Name { get { return (String)names[this.id]; } }
            public 
    Int32 ID { get { return this.id; } }
            public 
    Hashtable Values { get { return values; } }
            public 
    String Hash { get { return protocolHash; } }

            public 
    T GetValue<T>(string key)
            {
                if (
    values == null)
                    return default(
    T);
                
    Object value = values[key];
                if (
    value == null)
                    return default(
    T);

                return (
    T)value;
            }

            public static 
    Module StartUp(string moduleTree)
            {
                
    Module instance = new Module();
                
    instance.ParseTree(moduleTree);
                return 
    instance;
            }

            private 
    object GetValue(object key)
            {
                return 
    this.values[key];
            }

            private 
    Module() { }

            private 
    Module(int id)
            {
                
    this.id = id;
                
    this.values = new Hashtable();
            }

            private 
    Module Create(int id)
            {
                return new 
    Module(id)
                {
                    
    g = this.g,
                    
    protocolHash = this.protocolHash,
                    
    names = this.names,
                    
    f = this.f,
                    
    i = this.i,
                };
            }

            private 
    void Add(ArrayList arrayList, int num, object obj)
            {
                while (
    arrayList.Count <= num)
                {
                    
    arrayList.Add(null);
                }
                
    arrayList[num] = obj;
            }

            public 
    Module Parse(string packet)
            {
                
    PacketReader dataInput = new PacketReader(Encoding.Default.GetBytes(packet.Substring(2)));
                
    Module result;
                try
                {
                    
    short id = (short)dataInput.ReadShort();
                    
    Module xb = this.Create(id);
                    
    this.Read(xb, dataInput, id, xb);
                    
    result = xb;
                }
                catch
                {
                    return 
    null;
                }
                return 
    result;
            }

            private 
    object Read(Module xb, PacketReader dataInput, int id, Module xb2)
            {
                if (
    xb2 == null)
                {
                    
    xb2 = this.Create(id);
                }

                
    ArrayList arrayList = (ArrayList)this.f[id];
                
                for (
    int i = 0; i < arrayList.Count; i++)
                {
                    
    Int32 integer = (Int32)arrayList[i];
                    switch (integer)
                    {
                        case 
    0: // Byte
                            
    return dataInput.Read();
                        case 
    1: // Boolean
                            
    return dataInput.ReadBoolean();
                        case 
    2: // Byte
                            
    return dataInput.Read();
                        case 
    3: // Short
                            
    return dataInput.ReadShort();
                        case 
    4: // Int32
                            
    return dataInput.ReadInt();
                        case 
    5: // Long
                            
    return dataInput.ReadLong();
                        case 
    6: // Float
                            
    return (float)dataInput.ReadInt();
                        case 
    7: // Double
                            
    return BitConverter.Int64BitsToDouble(dataInput.ReadLong());
                        case 
    8: // Char
                            
    return dataInput.ReadChar();
                        case 
    9: // String
                            
    String str = dataInput.ReadUTF();
                            if (
    str == null || str.Length == 0 || str[0] != 0)
                                return 
    str;
                                if (
    str.Length == 1)
                                    return 
    null;
                                return 
    str.Substring(1);
                        case 
    10: // BinaryTree
                                
    throw new Exception("BinaryTree");
                        case 
    11: // Array (Start)
                                
    i++;
                                
    integer = (Int32)arrayList[i];
                                
    string text = (string)this.names[integer];
                                
    ArrayList arrayList2 = new ArrayList();
                                
    xb2.b(text, arrayList2);
                                while ((
    sbyte)dataInput.Read() == 11)
                                {
                                    
    object obj = this.Read(xb, dataInput, integer, null);
                                    
    obj = this.a(xb, integer, obj);
                                    
    arrayList2.Add(obj);
                                }
                                
    i++;
                                break;
                        case 
    12: // Array (End)
                                
    throw new Exception("End of array");
                        case 
    13: // String
                            
    int len = dataInput.Read();
                            if (
    len == 255) return null;
                            if (
    len >= 128) len = len - 128 << 16 | (dataInput.Read()) << 8 | (dataInput.Read());
                            
    StringBuilder builder = new StringBuilder(len + 2);
                            for (
    int _i = 0; _i < len; _i++) 
                                
    builder.Append((char)dataInput.Read());

                            return 
    builder.ToString();
                        default:
                                
    string text2 = (string)this.names[integer];
                                
    object obj2 = this.Read(xb, dataInput, integer, null);
                                
    obj2 = this.a(xb, integer, obj2);
                                
    xb2.b(text2, obj2);
                                break;
                    }
                }
                return 
    xb2;
            }

            public 
    byte[] WriteBytes(Module xb)
            {
                
    byte[] result;
                try
                {
                    
    int num = xb.id;
                    
    PacketWriter writer = new PacketWriter();
                    
    writer.WriteShort((short)num);
                    
    this.Write(xb, num, writer);
                    
    result = Encoding.Default.GetBytes(writer.ToString());
                }
                catch
                {
                    return 
    null;
                }
                return 
    result;
            }

            private 
    void Write(object obj, int id, PacketWriter dataOutput)
            {
                
    ArrayList arrayList = (ArrayList)this.f[id];
                for (
    int i = 0; i < arrayList.Count; i++)
                {
                    
    int num = (Int32)arrayList[i];
                    switch (
    num)
                    {
                        case 
    0:
                            
    dataOutput.Write((int)obj);
                            break;
                        case 
    1:
                            
    dataOutput.WriteBoolean((bool)obj);
                            break;
                        case 
    2:
                            
    dataOutput.Write((byte)obj);
                            break;
                        case 
    3:
                            
    dataOutput.WriteShort((short)obj);
                            break;
                        case 
    4:
                            
    dataOutput.WriteInt((int)obj);
                            break;
                        case 
    5:
                            
    dataOutput.WriteLong((long)obj);
                            break;
                        case 
    6:
                            
    dataOutput.WriteFloat((float)obj);
                            break;
                        case 
    7:
                            
    dataOutput.WriteDouble((double)obj);
                            break;
                        case 
    8:
                            
    dataOutput.WriteChar((int)obj);
                            break;
                        case 
    9:
                            
    string s = (string)obj;
                            if (
    s == null || s.Length == 0 || s[0] != 0)
                            {
                                
    dataOutput.WriteUTF(s);
                                break;
                            }

                            if (
    s.Length == 1)
                            {
                                
    dataOutput.WriteUTF(null);
                                break;
                            }

                            
    dataOutput.WriteUTF(s.Substring(1));
                            break;
                        case 
    10:
                            throw new 
    Exception("Not implemented yet: BinaryType");
                        case 
    11:
                            
    i++;
                            
    num = (Int32)arrayList[i];
                            
                            
    string text = (string)this.names[num];
                            
    ArrayList arrayList2 = (ArrayList)((Module)obj).GetValue(text);
                         
                            if (
    arrayList2 != null)
                            {
                                for (
    int j = 0; j < arrayList2.Count; j++)
                                {
                                    
    dataOutput.Write(11);
                                    
    this.Write(arrayList2[j], num, dataOutput);
                                }
                            }
                            
    dataOutput.Write(12);
                            
    i++;
                            break;
                        case 
    12:
                            throw new 
    Exception("Not expected: ArrayEnd");
                        case 
    13:
                            
    this.WriteString((string)obj, dataOutput);
                            break;
                        default:
                            
    this.Write(((Module)obj).GetValue(this.names[num]), num, dataOutput);
                            break;
                    }
                }
            }

            private 
    void WriteString(string text, PacketWriter dataOutput)
            {
                if (
    text == null)
                {
                    
    dataOutput.Write(255);
                }
                else
                {
                    
    int len = text.Length;
                    if (
    len < 128)
                    {
                        
    dataOutput.Write(len);
                    }
                    else
                    {
                        if (
    len > 8388608)
                        {
                            throw new 
    IOException("String too long: " + len.ToString());
                        }
                        
    dataOutput.Write((int)((uint)len >> 16 | 128u));
                        
    dataOutput.Write((int)((uint)len >> 8 & 255u));
                        
    dataOutput.Write(len & 255);
                    }
                    if (
    len > 0)
                    {
                        
    dataOutput.WriteChars(text);
                    }
                }
            }

            private 
    object a(Module xb, Int32 integer, object obj)
            {
                
    object obj2 = (this.i != null) ? this.i[integer] : null;
                if (
    obj2 == null)
                    return 
    obj;

                if (
    obj == null)
                    
    xb.a(integer, obj);

                return 
    obj;
            }

            private 
    void a(Int32 integer, object obj)
            {
                if (
    this.n == null)
                    
    this.n = new ArrayList();

                
    this.n.Add(integer);
                
    this.n.Add(obj);
            }

            public 
    Module Add(string name, object value)
            {
                return 
    this.b(name, value);
            }

            public 
    Module CreateModule(string name)
            {
                return 
    this.Create((Int32)this.g[name]);
            }

            private 
    Module b(string text, object obj)
            {
                if (
    obj == null)
                    
    this.values.Remove(text);
                else
                    
    this.values.Add(text, obj);

                return 
    this;
            }

            private 
    void Set(string text)
            {
                
    this.protocolString = text;
                
    this.protocolIndex = 0;
            }

            private 
    string GetString(string text)
            {
                
    int index = this.protocolString.IndexOf(text, this.protocolIndex);
                if (
    index < 0)
                {
                    return 
    null;
                }
                
    string result = this.protocolString.Substring(this.protocolIndex, index - this.protocolIndex);
                
    this.protocolIndex = index + text.Length;
                return 
    result;
            }

            private 
    int ConvertToInt(string text)
            {
                try
                {
                    
    string idString = this.GetString(text);
                    return 
    Int32.Parse(idString);
                }
                catch { return (int)
    text[0]; }
            }

            private 
    bool End(string text)
            {
                if (
    protocolString.IndexOf(text, protocolIndex) == protocolIndex)
                {
                    
    this.protocolIndex += text.Length;
                    return 
    true;
                }
                return 
    false;
            }

            private 
    int b(int num)
            {
                
    Int32 obj = 0;
                do
                {
                    
    num++;
                    if (
    num >= this.f.Count)
                    {
                        break;
                    }
                }
                while (
    this.f[num] == null || ((ArrayList)this.f[num]).Count == 0 || !Object.Equals(((ArrayList)this.f[num])[0], obj));
                if (
    num < this.f.Count)
                {
                    return 
    num;
                }
                
    string exception = "Not enough enumeration rules found.";
                throw new 
    Exception(exception);
            }

            public 
    virtual void ParseTree(string str)
            {
                
    string text = ";";
                
    string text2 = ":";
                
    this.Set(str);
                
    this.protocolHash = this.GetString(text);
                
    this.startValue = this.ConvertToInt(text);
                
    int num = this.startValue;
                
    this.names = new ArrayList();
                while (!
    this.End(text))
                {
                    
    this.Add(this.names, num++, this.GetString(text));
                }
                
    this.g = new Hashtable();
                
    int i;
                for (
    i = 0; i < this.names.Count; i++)
                {
                    
    object obj = this.names[i];
                    if (
    obj != null)
                    {
                        
    this.g.Add(this.names[i], i);
                    }
                }
                
    this.f = new ArrayList();
                
    i = this.startValue;
                while (!
    this.End(text2))
                {
                    
    ArrayList arrayList = new ArrayList();
                    
    this.Add(this.f, i, arrayList);
                    while (!
    this.End(text))
                    {
                        
    arrayList.Add(this.ConvertToInt(text));
                    }
                    
    i++;
                }
                
    int num2 = -1;
                while (!
    this.End(text))
                {
                    
    num2 = this.b(num2);
                    
    string text3 = (string)this.names[num2];
                    
    Hashtable hashtable = new Hashtable();
                    if (!
    this.g.ContainsKey(text3))
                        
    this.g.Add(text3, hashtable);
                    
    int num3 = 0;
                    while (!
    this.End(text))
                    {
                        
    object temp = this.GetString(text);
                        
    num3++;
                        
    hashtable.Add(temp, (byte)num3);
                    }
                }
                
    this.Set(null);
            }
        }
    } 
    Dazu brauchen wir noch 2 weitere Klassen, PacketReader und PacketWriter:

    PacketReader:
    PHP-Code:

    using System
    ;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;

    namespace 
    Knuddels_Reverse
    {
        public class 
    PacketReader : MemoryStream
        
    {
            private 
    byte[] buffer;
            private 
    int offset;

            public 
    PacketReader(byte[] buffer) : base(buffer)
            {
                
    this.buffer = buffer;
                
    offset = 0;
            }

            public 
    String ReadUTF()
            {
                
    int utflen = ReadShort();

                
    byte[] bytearr = new byte[utflen];
                
    char[] chararr = new char[utflen];

                
    int c, char2, char3;
                
    int count = 0;
                
    int chararr_count = 0;

                
    ReadFully(bytearr, 0, utflen);

                while (
    count < utflen)
                {
                    
    c = (int)bytearr[count] & 0xff;
                    if (
    c > 127) break;
                    
    count++;
                    
    chararr[chararr_count++] = (char)c;
                }

                while (
    count < utflen)
                {
                    
    c = (int)bytearr[count] & 0xff;
                    switch (
    c >> 4)
                    {
                        case 
    0:
                        case 
    1:
                        case 
    2:
                        case 
    3:
                        case 
    4:
                        case 
    5:
                        case 
    6:
                        case 
    7:
                            
    count++;
                            
    chararr[chararr_count++] = (char)c;
                            break;
                        case 
    12:
                        case 
    13:
                            
    count += 2;
                            if (
    count > utflen)
                                
    Console.WriteLine("[Error] malformed input: partial character at end");
                            
    char2 = (int)bytearr[count - 1];
                            if ((
    char2 & 0xC0) != 0x80)
                                
    Console.WriteLine("[Error]  malformed input around byte " + count);
                            
    chararr[chararr_count++] = (char)(((c & 0x1F) << 6) | (char2 & 0x3F));
                            break;
                        case 
    14:
                            
    count += 3;
                            if (
    count > utflen)
                                
    Console.WriteLine("[Error] malformed input: partial character at end");
                            
    char2 = (int)bytearr[count - 2];
                            
    char3 = (int)bytearr[count - 1];
                            if (((
    char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
                                
    Console.WriteLine("[Error] malformed input around byte " + (count - 1));
                            
    chararr[chararr_count++] = (char)(((c & 0x0F) << 12) |
                                                                ((
    char2 & 0x3F) << 6) |
                                                                    ((
    char3 & 0x3F) << 0));
                            break;
                        default:
                            
    Console.WriteLine("[Error] malformed input around byte " + count);
                            break;
                    }
                }
                return new 
    String(chararr);
            }

            public 
    void ReadFully(byte[] b)
            {
                
    ReadFully(b, 0, b.Length);
            }

            public 
    void ReadFully(byte[] b, int off, int len)
            {
                
    int n = 0;
                while (
    n < len)
                {
                    
    int count = Read(b, off + n, len - n);
                    if (
    count < 0)
                        throw new 
    Exception("EOFException");
                    
    n += count;
                }
            }

            public 
    byte Read()
            {
                return 
    buffer[offset++];
            }

            public 
    Boolean ReadBoolean()
            {
                return 
    Read() != 0;
            }

            public 
    long ReadLong()
            {
                return (((
    long)buffer[offset++] & 0xFF << 56) +
                        ((
    long)(buffer[offset++] & 0xFF) << 48) +
                        ((
    long)(buffer[offset++] & 0xFF) << 40) +
                        ((
    long)(buffer[offset++] & 0xFF) << 32) +
                        ((
    long)(buffer[offset++] & 0xFF) << 24) +
                        ((
    buffer[offset++] & 0xFF) << 16) +
                        ((
    buffer[offset++] & 0xFF) << 8) +
                        ((
    buffer[offset++] & 0xFF) << 0));
            }

            public 
    short ReadShort()
            {
                return (
    short)(((Read() & 0xFF) << 8)
                        + (
    Read() & 0xFF));
            }

            public 
    int ReadInt()
            {
                return ((
    Read() & 0xFF) << 24)
                        + ((
    Read() & 0xFF) << 16)
                        + ((
    Read() & 0xFF) << 8)
                        + (
    Read() & 0xFF);
            }

            public 
    char ReadChar()
            {
                return (
    char)((Read() << 8) + (Read() << 0));
            }

            public 
    String ReadString()
            {
                
    int len = ReadShort();

                
    StringBuilder builder = new StringBuilder(len);
                for (
    int i = 0; i < len; i++)
                    
    builder.Append((char)Read());

                return 
    builder.ToString();
            }
        }
    } 
    PacketWriter:
    PHP-Code:

    using System
    ;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;

    namespace 
    Knuddels_Reverse
    {
        class 
    PacketWriter : MemoryStream
        
    {
            private 
    StringBuilder builder;

            public 
    PacketWriter() { builder = new StringBuilder(); }

            public 
    override String ToString()
            {
                return 
    builder.ToString();
            }

            public 
    void WriteUTF(String paramString)
            {
                if (
    paramString == null)
                    
    paramString = String.Empty;

                
    int strlen = paramString.Length;
                
    int utflen = 0;
                
    int c, count = 0;

                for (
    int i = 0; i < strlen; i++)
                {
                    
    c = paramString[i];
                    if ((
    c >= 0x0001) && (c <= 0x007F))
                    {
                        
    utflen++;
                    }
                    else if (
    c > 0x07FF)
                    {
                        
    utflen += 3;
                    }
                    else
                    {
                        
    utflen += 2;
                    }
                }

                if (
    utflen > 65535)
                    throw new 
    Exception("Encoded string too long: " + utflen + " bytes");
                
    byte[] bytearr = new byte[utflen + 2];
                
    bytearr[count++] = (byte)((utflen >> 8) & 0xFF);
                
    bytearr[count++] = (byte)((utflen >> 0) & 0xFF);

                
    int i1 = 0;
                for (; 
    i1 < strlen; i1++)
                {
                    
    c = paramString[i1];
                    if (!((
    c >= 0x0001) && (c <= 0x007F))) break;
                    
    bytearr[count++] = (byte)c;
                }

                for (; 
    i1 < strlen; i1++)
                {
                    
    c = paramString[i1];
                    if ((
    c >= 0x0001) && (c <= 0x007F))
                    {
                        
    bytearr[count++] = (byte)c;

                    }
                    else if (
    c > 0x07FF)
                    {
                        
    bytearr[count++] = (byte)(0xE0 | ((c >> 12) & 0x0F));
                        
    bytearr[count++] = (byte)(0x80 | ((c >> 6) & 0x3F));
                        
    bytearr[count++] = (byte)(0x80 | ((c >> 0) & 0x3F));
                    }
                    else
                    {
                        
    bytearr[count++] = (byte)(0xC0 | ((c >> 6) & 0x1F));
                        
    bytearr[count++] = (byte)(0x80 | ((c >> 0) & 0x3F));
                    }
                }

                
    Write(bytearr, 0, utflen + 2);
            }

            public 
    void Write(int value)
            {
                
    builder.Append((char)value);
            }

            public 
    void WriteChars(string value)
            {
                
    int len = value.Length;

                for (
    int i = 0; i < len; i++)
                    
    WriteChar((int)value[i]);
            }

            public 
    void WriteShort(int value)
            {
                
    Write(value >> 8);
                
    Write(value);
            }

            public 
    void WriteChar(int value)
            {
                
    Write((char)value);
            }

            public 
    void WriteInt(int value)
            {
                
    Write(value >> 24);
                
    Write(value >> 16);
                
    Write(value >> 8);
                
    Write(value);
            }

            public 
    void WriteLong(long value)
            {
                
    Write((byte)(value >> 56));
                
    Write((byte)(value >> 48));
                
    Write((byte)(value >> 40));
                
    Write((byte)(value >> 32));
                
    Write((byte)(value >> 24));
                
    Write((byte)(value >> 16));
                
    Write((byte)(value >> 8));
                
    Write((byte)value);
            }

            public 
    void WriteFloat(float value)
            {
                
    WriteInt(BitConverter.ToInt32(BitConverter.GetBytes(value), 0));
            }

            public 
    void WriteDouble(double value)
            {
                
    WriteLong(BitConverter.DoubleToInt64Bits(value));
            }

            public 
    void WriteBytes(String value)
            {
                
    int len = value.Length;

                for (
    int i = 0; i < len; i++)
                    
    Write((byte)value[i]);
            }

            public 
    void WriteBoolean(bool value)
            {
                
    Write(value ? 1 : 0);
            }
        }
    } 
    Ist zwar vielleicht nicht überall sauber, but wayne.

    Hier ein Sample, wie man das Ganze überhaupt benutzt:

    PHP-Code:

    using System
    ;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Collections;

    namespace 
    Knuddels_Reverse
    {
        class 
    Program
        
    {
            static 
    string protocolString = "51492634;20;PROTOCOL_HASH;CONFIRM_PROTOCOL_HASH;PROTOCOL_CONFIRMED;PROTOCOL_DATA;CHANGE_PROTOCOL;TEXT;LABEL;CHANNEL_NAME;IMAGE;SOUND;NICK;TITLE;INT_TIME_MILLIS;TIMEOUT_SECONDS;DURATION;INTERVAL;RED;GREEN;BLUE;COLOR;FONTSIZE;INT_ID;INT_HASH;INT_VALUE;SHORT_ID;STRING_ID;VALID;SELECTED;FOCUS;SHORT_TIME_MILLIS;DEFAULT_COLOR;DEFAULT_FONTSIZE;TEXTPANELTEXT;STRING_MAP;CONFIG;STRING_MAP_ENTRY;STRING_KEY;STRING_VALUE;MOUSEX;MOUSEY;EVENT_ID;WINDOW_ID;EVENT;TEXT_COLOR;BACKGROUND_COLOR;TOP_FADE_FROM;MIDDLE_FADE_TO;BOTTOM_SOLID;SPECULAR_SHADING;IS_DIFF;BIN_DATA;ZINDEX;WINDOWX;WINDOWY;WINDOW;FEEDBACK_DOMAIN;FEEDBACK_KEY;SERVER_FEEDBACK;OPENED_FS_ID;FRAMESTRING_CLOSED;FRAMESTRING_NOT_FOUND;FRAMESTRING_INITIALIZE_OPENED;CLASS_NAME;PREFETCH_MODULE;FS_STRING;UPDATE_OPENED_FRAMESTRING;BUTTON;ANALOG_BUTTON;SHOW_BUTTONS;BUTTON_ALIGN;CHAT_FUNCTION;NR_ANALOG_SEGMENTS;SEND_INTERVAL_MILLIS;COOLDOWN_INTERVAL_MILLIS;ICON;SORT_ICON_NICKNAMES_TO_TOP;SHOW_PREFIXICONS;REMOVE_ALL_PREFIXICONS;MODULE_ID;TIMEOUT_SECONDS_TOTAL;TIMEOUT_SECONDS_HURRY_UP;MAX_VOTES;MIN_VOTE_TOKEN_LINES;VOTE_TOKEN;MAX_VISIBLE_LOG_LINES;LOG_LINE;SHOW_BLOOD_BAR;TOKEN_CLICK_TEMPLATE;NR_STATUS_LINES;STATUS_BAR;STATUS_ABOVE_LOG;NO_TEXT_SNIPPING;SHOW_VOTEBOX;VOTE_COUNT;UPDATE_VOTEBOX;SET_VOTEBOX_LOG;SET_VOTEBOX_STATUS;REMOVE_VOTEBOX;FINALIZE_VOTEBOX;UPDATE_VOTEBOX_TIMEOUT;BORDER_COLOR;VOTE_BARS_SETTING;VOTEBOX_BOX_SETTING;VOTEBOX_BUTTON_SETTING;TIMOUT_BAR_SETTING;VOTEBOX_SETTINGS;IMAGE_ID;VOTEBOX_IMAGE_CLICKED_SUCCESS;VOTE_BAR_WIN;VOTE_BAR_FIRST;VOTE_BAR_DRAW_FIRST;VOTE_BAR_REG;VOTE_BAR_LOSE;FOUR_COLOR_BAR;COLOR_TOP_TOP;COLOR_TOP;COLOR_BOT;COLOR_BOT_BOT;TOP_BOX_BACKGROUND_COLOR;TOP_BOX_TEXT_COLOR;MIDDLE_BOX_BACKGROUND_IMAGE;USE_BOLD_VOTE_TOKENS;TIMEOUT_BAR;BAR;SHOW_BARS;BAR_LENGTH_PIXEL;SIMPLE_BAR_UPDATE;BAR_TREND;BUTTON_TREND;ANALOG_TREND;BUTTON_BAR_SETTINGS;HEADER_BOX_TEXT;HEADER_BOX_UPDATE;REMOVE_HEADER_BOX;SEARCH_REQUEST_PARAMETERS;SEARCH_SORT_MODE;RESULT_COUNT_MINIMUM_NEEDED;SEARCH_NEW_REQUEST;AGE_FROM;AGE_TO;GENDER;SEARCH_REASON;SEARCH_TAG;SEARCH_OPTION;SHOW_MEMBERS_NEAR_ME;SHOW_NEW_MEMBERS;SEXUAL_ORIENTATION;OTHERS_FIND_ME_WHEN;UPDATE_FRIENDS;REQUEST_TOP_SEARCH_TAGS;RESULT_COUNT_START_OFFSET;SEARCH_UPDATE_REQUEST;STORE_SEARCH_OPTIONS;LOGIN_NICK;SEARCHER_AGE;SEARCHER_GENDER;SEARCHER_HAS_ZIP_CODE;SEARCHES_FIRST_TIME;OPEN_SEARCH_CHANNEL;RESULT;RESULT_START_INDEX;ESTIMATED_RESULT_COUNT;CLEAR_OLD_RESULTS;SEARCH_RESULT;FRIEND_RESULT;AGE;CURRENT_CHANNEL;IS_AFK;DISTANCE;MATCHING_PERCENT;IS_ONLINE;SEND_HI_OK;MINI_RESULT;SEARCH_RESULTS_CHANGED_ONLINESTATUS;CAME_ONLINE_RESULTS;GONE_OFFLINE_NICKS;FRIEND_RESULT_CHANGED_ONLINESTATUS;SHOW_TOP_SEARCH_TAGS;WHOIS_CONTENT;SHOW_MINIWHOIS;KEY_VALUE;MODULE_INIT;KEY;VALUE;COMMA_SEPARATED_NICK_LIST;INITIAL_TEXT;POST_OLD_MSG_TEXT;CLIENT_PP;IMAGE_PREFETCH;SOUND_PREFETCH;NICKLIST_SORT_TOGETHER;APPSTATS;BINGO_SHEET_ID;BINGO_SHEET_MATRIX_SIZE;BINGO_FIELD_STATES;INDEX;BINGO_PATTERN_ROW_WIDTH;MES_ID;BINGO_GAME_MESSAGE;BINGO_FIELD;BINGO_SHEET_STATE_CONST;BINGO_SHEET;BINGO_PATTERN_REFLECTED;BINGO_PATTERN;BINGO_CALLED_NUMBER;BINGO_FIELD_UPDATE;BINGO_SHEET_UPDATE;BINGO_ROUND;BINGO_HISTORY_UPDATE;BINGO_INIT;BINGO_UPDATE;BINGO_ACTIVE_TEXT;BINGO_ACTIVE_BUTTON_LABEL;BINGO_ACTIVE_BUTTON_COMMAND;BINGO_SET_STATE;FILENAME;PLAY_SOUND;SI_ID;SI_NAME;SI_DESCRIPTION;SI_LEVEL;SI_STOCKCOUNT;SI_COUNTDOWN_TO_REVEAL;SI_COUNTDOWN_TO_OUTOFSTOCK;SI_PRICE_CC;SI_PRICE_KNUDDELS;SI_OWNINGCOUNT;SI_LOCK;SHOP_ITEM;WINDOW_SIZE;SI_DESCRIPTION_LONG;SHOP_ITEM_DETAILS;SHOP_BUTTON;SHOP_MAINTAB;SHOP_BUTTONS;TAB_ID;TAB;SHOP_SUBTABS;TAB_ALIGNMENT;LOGO_IMAGE;SHOP_TITLE;USER_IMAGE;LOCALE;SHOP_USERSTATUS;SHOP_HEADER;UPDATE_SHOP_USERSTATUS;UPDATE_SHOP_ITEM;PERSONAL_HISTORY;NEW_SHOP_ITEMS;RECOMMENDED_SHOP_ITEMS;SHOP_MYSHOP;SHOP_VIEW;SHOP_MYSHOP_ITEM;REFERRAL_INFOTEXT;RESET_SCROLL_POS;SHOP_REFERRALS;SHOP_CLEAR_ITEMCACHE;SHOP_CLOSED;SHOP_REQUEST_ITEM_DETAILS;SHOP_CALL_OTHER;SHOP_REQUEST_ITEMS;INSTANT_WHOIS_CONTENT;SERVE_INSTANT_WHOIS;FORCED_SERVE_INSTANT_WHOIS;PANEL_SETTINGS;CONTENT_AREA_PIXEL_HEIGHT;CONTENT_AREA_PIXEL_WIDTH;IMAGEBOX_ID;SERVE_INSTANT_WHOIS_MISSING_USER;NICKLIST_COLOR;HI_WHOIS;INSTANT_WHOIS_PREFETCH_ITEM;INSTANT_WHOIS_PREFETCH;APPLET_INT_CONFIG_PARAM;APPLET_STRING_CONFIG_PARAM;CONFIGURE_APPLET;APPLET_INT_CONFIG_KEY;APPLET_STRING_CONFIG_KEY;REQUEST_INSTANT_WHOIS;REQUEST_RESPONSE_TIME;VIEW_TIME;INSTANT_WHOIS_STATS;W2_CONTENT;W2_HASHCODES;WAS_REQUESTED;SERVE_W2_NEW_WINDOW;W2_TARGET_WINDOW_ID;SERVE_W2;SERVE_W2_UPDATE;W2_TABS;W2_HEADER;W2_LEFT_COLUMN;W2_SELECTED_CENTER_TAB;W2_CENTER_COLUMN;W2_RIGHT_COLUMN;W2_SELECTED_BG;W2_TAB;SHOW_PARAMETER;W2_PARENTTAB_ID;W2_EDIT_COMMAND;ONLY_CENTER_COLUMN;W2_TARGET_WINDOW_ID_FLAGS;PAGE;CLOSED;FORCE_NO_MISSING;ADMIN_NO_MISSING;SOURCEID;REQUEST_W2;HASH_W2_TABS;HASH_W2_HEADER;HASH_W2_LEFTCOLUMN;HASH_W2_CENTERCOLUMN;HASH_W2_RIGHTCOLUMN;CLOSED_W2;CHANNELS;HI_BOX_ADDLINE;HI_BOX_REMOVE_LINE;HI_BOX_REMOVE_BOX;MESSAGE_OVERVIEW_UPDATE;POST_COUNT_CHANGED;PLZ;USERPLZ;REQUEST_DECODE;DECODE;SERVE_DECODE;PIXEL_URL;DEBUG_NOTIFY_USER;LOAD_TRACKING_PIXEL;SELECTED_ID;ANCHOR_ID;OWNER_NICK;REQUEST_W2EDIT;W2E_ENTRY;SAVE_W2E;ACTIONTYPE;W2E_ACTION;W2E_ACTIONLIST;SUGREQID;SUGTYPE;SUGTOKEN;SUGREQ;SUGRES;W2E_HEADER;MENU_ENTRY;WHOIS2_EDIT;COMPONENT_ID;LAYOUT_ITEM;POSITION;DIMENSION;LAYOUT_ITEM_TYPE;CONTENT;LAYOUT_ITEM_FLAG;LABEL_FONTSIZE;WIDTH;HEIGHT;XPOS;YPOS;SUCCESSFUL;WHOIS2_SAFE_RESULT;GUEST_APPLET_LOADED;STATUS_CODE;GUEST_CREATED;PREFFERED_CHANNEL;LOGIN_GUEST;GUEST_REGISTERED;ELEMENT_CLICKED_SUCCESS;W2GROUP_HEADER;W2GROUP_LEFT_COLUMN;W2GROUP_CENTER_COLUMN;SERVE_W2GROUP;MEMBERTYPE;REQUEST_W2GROUP;FROM_NICK;TO_NICK;SEND_FEEDBACK;WANDERING_KNUDDEL;WANDERING_KNUDDEL_DONE;TAB_NAME;OPEN_ON_LOAD;CLOSE_ON_INSERT;BOX_POSITION;USE_TRANSPARENCY;USE_ANIMATIONS;SB_TABS;SMILEY;SMILEY_SPECIAL;ADVERTISEMENT;SB_TAB;AMOUNT;REPLACEMENT;NAME;FAVORITE;SMILEY_INDEX;FEATURE_CMD;FEATURE_NAME;FEATURE_COOLDOWN;SB_DETAILS;SB_FAVORITE;SB_INVALIDATE;FORCE_PUSH;PUSH_DELAY;START_DV;DV_DATA;DV_SHOW;REQUEST_SB_TABS;REQUEST_SB_TAB;REQUEST_SB_DETAIL;TARGET_REPLACEMENT;REORDER_FAVORITES;STAT;STAT_REPORT;COUNT;HEARTLIGHT;HEARTLIGHT_DONE;NEXT_DATE_MODUL;FUNCTIONS;PARAMS;ACTIVATE_FUNCTIONS;DEACTIVATE_FUNCTIONS;NUM_COCONUTS;GAME_ID;PPS;NEW_COCONUT_GAME;COCONUT_ID;COCONUT_COLLECT;END_COCONUT_GAME;ENABLED;ACTIVE;FOTOMEET;SET_FOREGROUND_IMAGE_BOX;;5;;20;;;9;;23;;13;;13;;13;;13;;13;;13;;13;;4;;4;;4;;4;;2;;2;;2;;36;37;38;;2;;4;;4;;4;;3;;13;;1;;1;;1;;3;;39;;40;;50;51;25;;11;55;12;;53;;56;57;;13;;13;;3;;3;;3;;4;;32;61;43;58;59;60;;39;;39;;39;;39;;39;;65;66;67;;1;;13;;3;;3;;3;;32;61;31;72;73;69;70;71;;3;;13;;27;75;76;53;;13;;78;;78;;11;78;12;;13;;82;33;;13;;78;84;48;;25;28;89;90;;86;91;92;93;;27;11;86;12;11;87;12;;0;;13;;4;;4;;4;;30;11;28;12;;1;;27;11;94;12;95;;27;;13;;4;;4;;4;;4;;25;113;;4;;13;;1;;13;;4;;13;;1;;1;;27;98;31;33;99;100;86;101;102;11;103;12;104;11;105;12;106;107;108;109;110;111;;4;;27;98;103;105;109;;27;98;105;109;;27;98;109;;27;98;;27;98;;27;98;33;;39;;128;129;130;131;132;;63;64;138;139;140;141;;63;120;68;;64;142;;27;98;120;121;122;123;124;;4;;27;98;126;;28;;133;;133;;133;;133;;134;135;136;137;;39;;39;;39;;39;;39;;39;;28;;1;;68;;31;68;145;;27;11;143;12;;3;;145;;68;;68;;68;;27;147;148;149;;13;;98;27;151;;98;27;;158;159;160;11;161;12;11;162;12;11;163;12;164;165;166;11;167;12;;0;;3;;154;155;156;;2;;2;;0;;0;;13;;0;;0;;0;;0;;0;;;;3;;170;156;;154;;30;;2;;160;;1;;1;;27;173;174;175;176;177;154;;30;185;160;186;187;188;189;11;162;12;28;190;191;;4;;4;;1;;11;179;12;180;181;182;;11;179;12;;2;;27;;1;;3;;2;;1;;1;;30;190;;11;192;12;;11;179;12;;11;30;12;;194;195;;11;162;12;;13;;30;198;191;;202;203;;27;98;82;11;200;12;;13;;13;;13;;13;;13;;27;204;205;206;;11;28;12;;11;29;12;;27;11;30;12;;53;;5;;2;;0;;4;;2;;4;;217;25;;3;;0;;212;213;11;219;12;11;214;12;220;;1;;216;11;214;12;222;;13;;215;219;214;;212;11;225;12;11;218;12;;4;;212;224;227;;98;27;221;11;223;12;11;224;12;;98;27;11;226;12;11;223;12;11;218;12;11;228;12;;25;;25;;25;;98;27;212;220;231;232;233;;13;;27;98;235;;4;;13;;13;;2;;4;;33;;33;;6;;6;;2;;13;;237;238;239;240;28;120;241;242;243;244;245;246;247;;3;;52;;120;240;238;249;250;;255;25;40;47;;256;257;;11;252;12;11;253;12;;2;;255;258;25;40;47;11;237;12;;11;256;12;;0;;28;;25;;28;;13;;52;;259;260;254;261;262;263;;263;;11;248;12;;52;;11;237;12;;11;237;12;;264;267;268;269;;264;;264;;52;;1;;264;273;274;;;;237;;255;;11;237;12;;284;52;42;;41;281;;27;30;281;;285;286;287;;3;;3;;13;;41;;39;;27;30;281;289;;30;281;;27;11;291;12;;296;43;;297;57;;11;293;12;11;294;12;;0;;0;;30;27;41;42;;49;;49;;11;299;12;11;300;12;;309;310;311;312;313;314;11;315;12;;46;328;329;330;331;332;;1;;30;302;303;304;;4;;30;306;302;303;304;;30;;11;316;12;;11;52;12;;11;52;12;;45;;11;52;12;;11;52;12;;28;317;;45;318;319;;0;;45;;13;;1;;0;;3;;13;;1;;1;;13;;30;320;312;303;306;321;322;323;324;325;304;326;;4;;4;;4;;4;;4;;30;;11;27;12;;27;30;25;334;;27;30;;27;;48;53;;43;;13;;340;;11;44;12;;44;25;;11;343;12;;13;;1;;345;346;;45;;365;;13;;348;349;350;;45;57;;45;350;11;352;12;;3;;350;354;352;;350;354;11;352;12;;4;;4;;13;;357;358;359;;357;358;11;359;12;;52;;45;28;25;11;366;12;;362;348;349;350;11;363;12;;13;;45;367;368;369;11;370;12;11;371;12;54;26;372;;375;376;;373;374;;0;;13;;0;;40;;3;;3;;3;;3;;1;;45;377;;;3;;380;;13;;382;;;365;126;;52;;52;;52;;45;31;386;387;388;;3;;41;45;390;322;;30;;30;;1;;27;392;393;394;;27;;13;;1;;1;;2;;1;;1;;98;11;397;12;398;399;400;401;402;;28;408;409;410;411;;412;413;414;415;;13;;98;397;11;404;12;11;405;12;406;;2;;13;;13;;1;;3;;13;;13;;5;;98;409;25;;98;409;411;;98;397;;3;;4;;34;35;419;420;45;;11;62;12;11;74;12;;23;11;25;12;;;397;;409;;13;;11;409;12;427;;26;431;;98;11;429;12;;4;;27;393;394;;27;;98;27;25;;13;;13;;11;435;12;11;436;12;;11;435;12;;3;;4;;3;;27;33;439;440;441;;4;;27;11;443;12;;27;;1;;1;;98;446;447;25;;27;25;;:RIGHT;LEFT;;MATCHING;DISTANCE;AGE;SINGLESTATUS;;DOESNT_MATTER;FEMALE;MALE;;TALKING;FRIENDSHIP;FLIRT;MEETING;MARIAGE;EROTIC_TALKING;;ONLY_WITH_FOTO;PREFER_SINGLES;;NORMAL;PREFERRED;NEVER;;NORMAL;PREFERRED;NEVER;;HETERO;HOMO;BI;;THEY_ARE_LONGTERM_MEMBERS;THEY_MATCH_MY_SEARCH_CRITERIA;ONLY_WHILE_I_AM_IN_SEARCH_CHANNEL;NEVER;OFTEN;;ANY_STATE;NOT_SELECTED;SELECTED;DEAD;GLOWING;;ACTIVE;INACTIVE;BINGO;NO_BINGO_POSSIBLE;JACKPOT;GAME_END;;LEFT;RIGHT;;instantWhoisCornerRadius;instantWhoisMillisToRequest;instantWhoisMillisToRequestNickList;instantWhoisMillisToRequestW2;instantWhoisMillisToShow;instantWhoisMillisToHide;instantWhoisMillisToUpdateVisibleRequest;w2WindowWidth;w2WindowHeight;hiBoxWidth;hiBoxBasicHeight;hiBoxLineHeight;hiBoxLineSepHeight;hiBoxDistanceTop;hiBoxDistanceBottom;hiBoxDistanceRight;currentSeason;w2MapWToW2;publicMsgInPP;soundInPP;standAloneSBox;;noKeys;hiBoxBasicContent;hiBoxLineEndText;hiBoxLineSeperatorText;hiBoxBackgroundImageID;w2DefaultTab;imgProxyList;serverId;;FULL;STRETCHED;TILED;;regularTarget;noTarget;newTargetRequested;;TextField;TextPanel;TextArea;Image;Button;CheckBox;ComboBoxSelect;ComboBoxInput;Slider;EMPTY;ComplexGroupInput;ColorBox;ImageBox;TextToolbar;;ShowBulletPoint;TextAlignRight;TextAlignLeft;TextBold;TextItalic;PasswordInput;LabelLocationTop;LabelLocationLeft;LabelLocationRight;LabelLoactionBottom;LabelLocationCenter;LabelBold;LabelItalic;ButtonActionDispose;ButtonActionSubmit;UseImages;AlternativeDisplayMode;ComboBoxFreeInput;ImageHasBorder;DisableHighlightOnInputFocus;Disabled;ScrollingDisabled;SendbackText;NoAdd;;;";
            static 
    string packet = ":\0\0}Bingo Solo Freeÿ\0\0\0mafia/bloodbar.gifâ\0ÿÿÿö·¿æ,AÍnÿÿÿÿ·âx\0æ¹þÿíéÏ\0¾Š\0d\0ÿÿÿ¾Ò·@€,\0\0\0ÏÐü��Ûÿÿÿÿ\0\0\0\0\0\0\0��Û��Û��Ûdd¼¼ûÄzº~R�T";
            static 
    string bingoPacket = ":\0\0åBINGOBingo Solo Free\0\0\0\0\0\0M \n \0 \0 \0 \0& \0, \03 \0E \0I \0U \0c \0d \0 \0 \0" \0/ \04 \0< \0G \0U \0\\ \0 \0 \0 \0# \00 \03 \0C \0K \0T \0_ \0d \0 \0 \0" \00 \07 \0D \0J \0Y \0c \0 \0 \0 \0# \0- \09 \0? \0O \0Y \0\\ \0 \0 \0 \0$ \0* \07 \0E \0O \0T \0b \0 \0 \0 \0 \0* \05 \0D \0K \0W \0_ \0 \0 \0 \0 \0/ \05 \0C \0J \0W \0` \0 \0 \0 \0& \0, \09 \0? \0I \0S \0` \0 \0 \0 \0$ \0- \04 \0< \0G \0S \0b                                                                                                     \0         \0  \0 \0 \0 \0 \0 \0  \0 \0 \0 \0 \0  \0 \0 \0 \0 \0  \0 \0 \0 \0 \0  \0 \0 \0 \0 \0  \0 \0 \0 \0 \0  \0 \0 \0 \0 \0  \0 \0 \0 \0 \0 \0    \0 \0 \0 \0 \0 \0 \0  \0 \0 \0 \0 \0 \0 \0  \0 \0 \0 \0 \0 \0 \0  \0 \0 \0 \0 \0 \0 \0  \0 \0 \0 \0 \0 \0 \0  \0 \0 \0 \0 \0 \0 \0         \0 ";
            
    static void Main(string[] args)
            {
                
    Console.Title = "Knuddels Reverse";

                
    Module main = Module.StartUp(protocolString);

                
    /* Writing */

                // ------------------------------------------------------------------------------------------------ //

                // Example 1
                
    Module playSound = main.CreateModule("PLAY_SOUND");
                
    playSound.Add("CHANNEL_NAME", "Homos");
                
    playSound.Add("MODULE_ID", "Gaylord");
                
    playSound.Add("FILENAME", "Holgi onaniert.mp3");

                
    Module parsedPlaySound = main.Parse(":\0" + Encoding.Default.GetString(main.WriteBytes(playSound)));

                
    Console.WriteLine("Name: {0}", parsedPlaySound.Name);
                
    Console.WriteLine("ID: {0}", parsedPlaySound.ID);
                
    Console.WriteLine("Filename: {0}", parsedPlaySound.GetValue<String>("FILENAME"));

                
    Console.WriteLine("---------------------------------------------\n");

                
    // End of Example 1

                // ------------------------------------------------------------------------------------------------ //

                // Example 2
                
    Module confirm = main.CreateModule("CONFIRM_PROTOCOL_HASH"); // Hier wird das Paket, das zum Server gesendet wird, erzeugt
                
    confirm.Add("PROTOCOL_HASH", long.Parse(main.Hash));

                
    String confirmPacket = Encoding.Default.GetString(main.WriteBytes(confirm));
                
    Console.WriteLine(":\\0" + confirmPacket.Replace("\0", "\\0").Replace("\n", "\\n"));
                
                
    Module PARSED = main.Parse(":\0" + confirmPacket); // als Test lassen wir unser erzeugtes Paket parsen, beim Übergeben (Parsen) MUSS :\0 vorangestellt werden!
                
    Console.WriteLine("Protocolhash: " + PARSED.GetValue<long>("PROTOCOL_HASH"));

                
    Console.WriteLine("---------------------------------------------\n");

                
    // End of Example 2

                // Example 3
                
    Module prefixIcons = main.CreateModule("SHOW_PREFIXICONS");
                
    prefixIcons.Add("CHANNEL_NAME", "/K-Script");

                
    Module iconJames = main.CreateModule("ICON");
                
    iconJames.Add("NICK", "James");
                
    iconJames.Add("IMAGE", new ArrayList() { "sm_00.gif", "gaylord.gif" });

                
    Module iconHolgi = main.CreateModule("ICON");
                
    iconHolgi.Add("NICK", "Holgi");
                
    iconHolgi.Add("IMAGE", new ArrayList() { "homo.jpg" });

                
    prefixIcons.Add("ICON", new ArrayList() { iconJames, iconHolgi });

                
    prefixIcons.Add("SORT_ICON_NICKNAMES_TO_TOP", true);

                
    Module parsedPrefixIcons = main.Parse(":\0" + Encoding.Default.GetString(main.WriteBytes(prefixIcons)));

                
    // Das Paket mal anzeigen
                
    Console.WriteLine("Erzeugt:\n:\\0" + Encoding.Default.GetString(main.WriteBytes(prefixIcons)).Replace("\0", "\\0").Replace("\n", "\\n") + "\n");
                
                
    Console.WriteLine("Name: {0}", parsedPrefixIcons.Name);
                
    Console.WriteLine("ID: {0}", parsedPrefixIcons.ID);
                
    Console.WriteLine("Channel: {0}", parsedPrefixIcons.GetValue<String>("CHANNEL_NAME"));

                
    ArrayList icons = parsedPrefixIcons.GetValue<ArrayList>("ICON");
                for (
    int i = 0; i < icons.Count; i++)
                {
                    
    Module temp = (Module)icons[i];
                    
    Console.WriteLine(temp.GetValue<String>("NICK") + ": " + String.Join(", ", temp.GetValue<ArrayList>("IMAGE").ToArray()));
                }

                
    Console.WriteLine("SORT_ICON_NICKNAMES_TO_TOP: {0}", parsedPrefixIcons.GetValue<bool>("SORT_ICON_NICKNAMES_TO_TOP"));

                
    Console.WriteLine("---------------------------------------------\n");

                
    // End of Example 3

                // ------------------------------------------------------------------------------------------------ //

                /* End of writing */

                // ------------------------------------------------------------------------------------------------ //

                /* Parsing */

                // ------------------------------------------------------------------------------------------------ //

                
    Module parsed = main.Parse(packet);

                
    Console.WriteLine("Name: {0}", parsed.Name);
                
    Console.WriteLine("ID: {0}", parsed.ID);
                
    Console.WriteLine("Channel: {0}", parsed.GetValue<String>("CHANNEL_NAME"));

                
    Module color = parsed.GetValue<Module>("VOTEBOX_BOX_SETTING").GetValue<Module>("TOP_BOX_BACKGROUND_COLOR").GetValue<Module>("COLOR");
                
    Console.WriteLine("RED: {0}", color.GetValue<byte>("RED"));
                
    Console.WriteLine("BLUE: {0}", color.GetValue<byte>("BLUE"));
                
    Console.WriteLine("GREEN: {0}", color.GetValue<byte>("GREEN"));

                
    Console.WriteLine();

                
    Hashtable values = parsed.Values;

                foreach (
    String key in values.Keys)
                    
    Console.WriteLine(key + " -> " + values[key]); // Alles mal anzeigen

                
    Console.WriteLine("---------------------------------------------\n");

                
    // ------------------------------------------------------------------------------------------------ //

                
    Module bingo = main.Parse(bingoPacket);

                
    Console.WriteLine("Name: {0}", bingo.Name);
                
    Console.WriteLine("ID: {0}", bingo.ID);
                
    Console.WriteLine("Channel: {0}", bingo.GetValue<String>("CHANNEL_NAME"));
                
    Console.WriteLine("BingoBlatt-ID: {0}", bingo.GetValue<Module>("BINGO_SHEET").GetValue<long>("BINGO_SHEET_ID"));
                
    Console.WriteLine("Bingo Nums: {0}", String.Join(", ", bingo.GetValue<Module>("BINGO_SHEET").GetValue<ArrayList>("BINGO_FIELD").ToArray()));
                
    // weiter auswerten bla bla bla

                
    Console.ReadLine();
            }
        }
    } 
    Wie die ganzen Pakete genau aufgebaut sind, seht ihr hier:
    KnuddelsData 90ala (thx to KoRn)

    Macht damit was ihr wollt, müsst mich auch nicht erwähnen.

    MfG

  2. The Following User Says Thank You to Brainy For This Useful Post:

    StarWarsFan (10.01.2016)

  3. #2
    Avatar von Mentos
    Registriert seit
    18.11.2011
    Beiträge
    451
    Thanked 498 Times in 240 Posts

    Standard :-Token (Module) parsen/schreiben

    Erinnert mich stark an der KNode, aber es ist natürlich sehr gut, dass du es selbst versucht und geschafft hast.
    Ich werde mich damit auch noch einmal genauer Beschäftigen und die Klassen sind sicher gerade auch in der Emulator Programmierung von Vorteil.
    MfG
    „Es sind nicht unsere Fähigkeiten, die zeigen, wer wir wirklich sind, es sind unsere Entscheidungen.“
    - Albus Dumbledore, Harry Potter 2


    /guestchat registerGuest

  4. #3

    Registriert seit
    09.11.2011
    Beiträge
    140
    Thanked 153 Times in 59 Posts

    Standard :-Token (Module) parsen/schreiben

    Hier habt ihr es auch in Java (nur eine Klasse), ob es auch 100%ig funktioniert, weiß ich nicht, könnt ihr ja im Emulator oder so testen.

    PHP-Code:
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.DataInput;
    import java.io.DataInputStream;
    import java.io.DataOutput;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Hashtable;
    import java.util.List;

    /**
     *
     * @author Brainy
     */
    public class Module {
            private 
    Hashtable i;
            private 
    Hashtable g;
            private 
    int id;
            private 
    Hashtable values;
            private 
    String protocolHash;
            private List 
    names;
            private List 
    f;
            private 
    int startValue;
            private 
    String protocolString;
            private 
    int protocolIndex;
            private List 
    n;

            public 
    String getName() {
                return (String)
    this.names.get(this.id);
            } 
            
            public 
    Integer getID() {
                return 
    this.id;
            }
            
            public 
    Hashtable getValues() {
                return 
    this.values;
            }
            
            public 
    String getHash() {
                return 
    this.protocolHash;
            }
            
            public 
    Object getValue(String key) {
                if (
    values == null) {
                    return 
    null;
                }
                
                return 
    values.get(key);
            }

            public static 
    Module startUp(String moduleTree) throws Exception {
                
    Module instance = new Module();
                
    instance.parseTree(moduleTree);
                return 
    instance;
            }

            private 
    Module() {
                
    // empty
            
    }

            private 
    Module(int id) {
                
    this.id = id;
                
    this.values = new Hashtable();
            }
            
            private 
    Module(int id, Hashtable g, String protocolHash, List names, List f, Hashtable i) {
                
    this.id = id;
                
    this.g = g;
                
    this.protocolHash = protocolHash;
                
    this.names = names;
                
    this.f = f;
                
    this.i = i;
                
                
    this.values = new Hashtable();
            }

            private 
    Module create(int id) {
                return new 
    Module(id, this.g, this.protocolHash, this.names, this.f, this.i);
            }

            private 
    void add(List list, int num, Object obj) {
                while (list.
    size() <= num)  {
                    list.
    add(null);
                }
                list.
    set(num, obj);
            }

            public 
    Module parse(String packet) {
                
    DataInput dataInput = new DataInputStream(new ByteArrayInputStream(packet.substring(packet.indexOf("\0") + 1).getBytes()));
                
    Module result;
                try {
                    
    short id = (short)dataInput.readShort();
                    
    Module xb = this.create(id);
                    
    this.read(xb, dataInput, id, xb);
                    
    result = xb;
                }
                catch (
    Exception e)  {
                    
    e.printStackTrace();
                    return 
    null;
                }
                return 
    result;
            }

            private 
    Object read(Module xb, DataInput dataInput, int id, Module xb2) throws IOException, Exception  {
                if (
    xb2 == null) {
                    
    xb2 = this.create(id);
                }

                List list = (List)
    this.f.get(id);
                
                for (
    int i = 0; i < list.size(); i++) {
                    
    Integer integer = (Integer)list.get(i);
                    switch (integer) {
                        case 
    0: // Byte
                            
    return dataInput.readByte();
                        case 
    1: // Boolean
                            
    return dataInput.readBoolean();
                        case 
    2: // Byte
                            
    return dataInput.readByte();
                        case 
    3: // Short
                            
    return dataInput.readShort();
                        case 
    4: // Integer
                            
    return dataInput.readInt();
                        case 
    5: // Long
                            
    return dataInput.readLong();
                        case 
    6: // Float
                            
    return dataInput.readFloat();
                        case 
    7: // Double
                            
    return dataInput.readDouble();
                        case 
    8: // Char
                            
    return dataInput.readChar();
                        case 
    9: // String
                            
    String str = dataInput.readUTF();
                            if (
    str == null || str.length() == 0 || str.charAt(0) != 0)
                                return 
    str;
                            
                                if (
    str.length() == 1)
                                    return 
    null;
                                return 
    str.substring(1);
                        case 
    10: // BinaryTree
                                
    throw new Exception("BinaryTree");
                        case 
    11: // Array (Start)
                                
    i++;
                                
    integer = (Integer)list.get(i);
                                
    String text = (String)this.names.get(integer);
                                List 
    list2 = new ArrayList();
                                
    xb2.b(text, list2);
                                while (
    dataInput.readByte() == 11) {
                                    
    Object obj = this.read(xb, dataInput, integer, null);
                                    
    obj = this.a(xb, integer, obj);
                                    
    list2.add(obj);
                                }
                                
    i++;
                                break;
                        case 
    12: // Array (End)
                                
    throw new Exception("End of array");
                        case 
    13: // String
                            
    int len = dataInput.readByte();
                            if (
    len == 255) return null;
                            if (
    len >= 128) len = len - 128 << 16 | (dataInput.readByte()) << 8 | (dataInput.readByte());
                            
    StringBuilder builder = new StringBuilder(len + 2);
                            for (
    int _i = 0; _i < len; _i++) 
                                
    builder.append((char)dataInput.readByte());

                            return 
    builder.toString();
                        default:
                                
    String text2 = (String)this.names.get(integer);
                                
    Object obj2 = this.read(xb, dataInput, integer, null);
                                
    obj2 = this.a(xb, integer, obj2);
                                
    xb2.b(text2, obj2);
                                break;
                    }
                }
                return 
    xb2;
            }

            public 
    byte[] writeBytes(Module xb) {
                
    byte[] result;
                try {
                    
    int num = xb.id;
                    
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    
    DataOutput writer = new DataOutputStream(stream);
                    
    writer.writeShort((short)num);
                    
    this.write(xb, num, writer);
                    
    result = stream.toByteArray();
                }
                catch (
    Exception e) {
                    
    e.printStackTrace();
                    return 
    null;
                }
                return 
    result;
            }

            private 
    void write(Object obj, int id, DataOutput dataOutput) throws IOException, Exception {
                List list = (List)
    this.f.get(id);
                for (
    int i = 0; i < list.size(); i++) {
                    
    int num = (Integer)list.get(i);
                    switch (
    num) {
                        case 
    0:
                            
    dataOutput.writeByte(((Byte)obj).byteValue());
                            break;
                        case 
    1:
                            
    dataOutput.writeBoolean(((Boolean)obj).booleanValue());
                            break;
                        case 
    2:
                            
    dataOutput.writeByte(((Byte)obj).byteValue());
                            break;
                        case 
    3:
                            
    dataOutput.writeShort(((Short)obj).shortValue());
                            break;
                        case 
    4:
                            
    dataOutput.writeInt(((Integer)obj).intValue());
                            break;
                        case 
    5:
                            
    dataOutput.writeLong(((Long)obj).longValue());
                            break;
                        case 
    6:
                            
    dataOutput.writeFloat(((Float)obj).floatValue());
                            break;
                        case 
    7:
                            
    dataOutput.writeDouble(((Double)obj).doubleValue());
                            break;
                        case 
    8:
                            
    dataOutput.writeChar(((Integer)obj).intValue());
                            break;
                        case 
    9:
                            
    String s = (String)obj;
                            if (
    s == null || s.length() == 0 || s.charAt(0) != 0) {
                                
    dataOutput.writeUTF(s);
                                break;
                            }

                            if (
    s.length() == 1) {
                                
    dataOutput.writeUTF(null);
                                break;
                            }

                            
    dataOutput.writeUTF(s.substring(1));
                            break;
                        case 
    10:
                            throw new 
    Exception("Not implemented yet: BinaryType");
                        case 
    11:
                            
    i++;
                            
    num = (Integer)list.get(i);
                            
                            
    String text = (String)this.names.get(num);
                            List 
    list2 = (List)((Module)obj).getValue(text);
                         
                            if (
    list2 != null) {
                                for (
    int j = 0; j < list2.size(); j++) {
                                    
    dataOutput.writeByte(11);
                                    
    this.write(list2.get(j), num, dataOutput);
                                }
                            }
                            
    dataOutput.writeByte(12);
                            
    i++;
                            break;
                        case 
    12:
                            throw new 
    Exception("Not expected: ArrayEnd");
                        case 
    13:
                            
    this.writeString((String)obj, dataOutput);
                            break;
                        default:
                            
    this.write(((Module)obj).getValue((String)this.names.get(num)), num, dataOutput);
                            break;
                    }
                }
            }

            private 
    void writeString(String text, DataOutput dataOutput) throws IOException {
                if (
    text == null) {
                    
    dataOutput.writeByte(255);
                }
                else {
                    
    int len = text.length();
                    if (
    len < 128) {
                        
    dataOutput.writeByte(len);
                    }
                    else {
                        if (
    len > 8388608) {
                            throw new 
    IOException("Encoded string too long: " + String.valueOf(len));
                        }
                        
    dataOutput.writeByte((int)(len >> 16 | 128));
                        
    dataOutput.writeByte((int)(len >> 8 & 255));
                        
    dataOutput.writeByte(len & 255);
                    }
                    if (
    len > 0) {
                        for (
    Character c : text.toCharArray()) {
                            
    dataOutput.writeByte((int)c);
                        }
                    }
                }
            }

            private 
    Object a(Module xb, Integer integer, Object obj) {
                
    Object obj2 = (this.i != null) ? this.i.get(integer) : null;
                if (
    obj2 == null)
                    return 
    obj;

                if (
    obj == null)
                    
    xb.a(integer, obj);

                return 
    obj;
            }

            private 
    void a(Integer integer, Object obj) {
                if (
    this.n == null)
                    
    this.n = new ArrayList();

                
    this.n.add(integer);
                
    this.n.add(obj);
            }

            public 
    Module add(String name, Object value) {
                return 
    this.b(name, value);
            }

            public 
    Module createModule(String name) {
                return 
    this.create((Integer)this.g.get(name));
            }

            private 
    Module b(String text, Object obj) {
                if (
    obj == null)
                    
    this.values.remove(text);
                else
                    
    this.values.put(text, obj);

                return 
    this;
            }

            private 
    void set(String text) {
                
    this.protocolString = text;
                
    this.protocolIndex = 0;
            }

            private 
    String getString(String text) {
                
    int index = this.protocolString.indexOf(text, this.protocolIndex);
                if (
    index < 0) {
                    return 
    null;
                }
                
    String result = this.protocolString.substring(this.protocolIndex, index);
                
    this.protocolIndex = index + text.length();
                return 
    result;
            }

            private 
    int convertToInt(String text) {
                
    String idString = this.getString(text);
                return 
    Integer.parseInt(idString);
            }

            private 
    boolean end(String text) {
                if (
    protocolString.indexOf(text, protocolIndex) == protocolIndex) {
                    
    this.protocolIndex += text.length();
                    return 
    true;
                }
                return 
    false;
            }

            private 
    int b(int num) throws Exception {
                
    Integer obj = 0;
                do {
                    
    num++;
                    if (
    num >= this.f.size()) {
                        break;
                    }
                }
                while (
    this.f.get(num) == null || ((List)this.f.get(num)).isEmpty() || ((List)this.f.get(num)).get(0).equals(obj));
                if (
    num < this.f.size()) {
                    return 
    num;
                }
                
    String exception = "Not enough enumeration rules found.";
                throw new 
    Exception(exception);
            }

            private 
    void parseTree(String str) throws Exception {
                
    String text = ";";
                
    String text2 = ":";
                
    this.set(str);
                
    this.protocolHash = this.getString(text);
                
    this.startValue = this.convertToInt(text);
                
    int num = this.startValue;
                
    this.names = new ArrayList();
                while (!
    this.end(text)) {
                    
    this.add(this.names, num++, this.getString(text));
                }
                
    this.g = new Hashtable();
                
    int i;
                for (
    i = 0; i < this.names.size(); i++) {
                    
    Object obj = this.names.get(i);
                    if (
    obj != null) {
                        
    this.g.put(this.names.get(i), i);
                    }
                }
                
    this.f = new ArrayList();
                
    i = this.startValue;
                while (!
    this.end(text2)) {
                    List list = new 
    ArrayList();
                    
    this.add(this.f, i, list);
                    while (!
    this.end(text)) {
                        list.
    add(this.convertToInt(text));
                    }
                    
    i++;
                }
                
    int num2 = -1;
                while (!
    this.end(text)) {
                    
    num2 = this.b(num2);
                    
    String text3 = (String)this.names.get(num2);
                    
    Hashtable hashtable = new Hashtable();
                    if (!
    this.g.containsKey(text3))
                        
    this.g.put(text3, hashtable);
                    
                    
    int num3 = 0;
                    while (!
    this.end(text)) {
                        
    Object temp = this.getString(text);
                        
    num3++;
                        
    hashtable.put(temp, (byte)num3);
                    }
                }
                
    this.set(null);
            }
        } 
    MfG

  5. #4

    Registriert seit
    31.01.2011
    Beiträge
    26
    Thanked 211 Times in 94 Posts

    Standard :-Token (Module) parsen/schreiben

    @Mentos

    Liegt wohl daran dass er es wie ich aus dem Knuddelsk-Archiv hat ;D
    Geändert von Darkfield (12.04.2014 um 08:35 Uhr)


    -------------------------------------------
    Hier kommt der Waynetrain! Er fährt mit deiner Story zum Whateverest !!!
    -------------------------------------------
    BILD ANZEIGEN [Warum wird das Bild nicht angezeigt?]

Ähnliche Themen

  1. VB.Net Json String richtig parsen???
    Von soulreafer im Forum .Net
    Antworten: 1
    Letzter Beitrag: 06.07.2013, 17:15
  2. [PHP] Umlaute parsen
    Von Pwned im Forum PHP
    Antworten: 6
    Letzter Beitrag: 29.12.2012, 11:44
  3. [Input] k - Popup Token
    Von silently im Forum Protokoll
    Antworten: 4
    Letzter Beitrag: 17.04.2011, 15:09
  4. [F] Poker Anmelde Befehl oder Token?
    Von Dbzfreak1337 im Forum Protokoll
    Antworten: 2
    Letzter Beitrag: 02.04.2011, 17:25
  5. [C#] Channellist parsen
    Von Brainy im Forum Sourcecode
    Antworten: 0
    Letzter Beitrag: 31.01.2011, 22:01
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.