LogEntryFMT ReadLogFormat(Stream br)
        {
            int len = Marshal.SizeOf <log_Format>();

            if (_logFormatPtr == IntPtr.Zero)
            {
                _logFormatPtr    = Marshal.AllocCoTaskMem(len);
                _logFormatBuffer = new byte[len];
            }

            br.Read(_logFormatBuffer, 0, _logFormatBuffer.Length);

            // copy byte array to ptr
            Marshal.Copy(_logFormatBuffer, 0, _logFormatPtr, len);

            log_Format logfmt = Marshal.PtrToStructure <log_Format>(_logFormatPtr);

            string lgname = ASCIIEncoding.ASCII.GetString(logfmt.name).Trim(NullTerminator);


            var result = new LogEntryFMT()
            {
                Length       = logfmt.length,
                Type         = logfmt.type,
                Name         = ASCIIEncoding.ASCII.GetString(logfmt.name).Trim(NullTerminator),
                FormatString = ASCIIEncoding.ASCII.GetString(logfmt.format).Trim(NullTerminator),
                Columns      = ASCIIEncoding.ASCII.GetString(logfmt.labels).Trim(NullTerminator).Split(',')
            };

            if (result.Columns.Length == 1 && string.IsNullOrEmpty(result.Columns[0]))
            {
                result.Columns = new string[0];
            }
            packettypecache[logfmt.type] = result;
            Debug.WriteLine("// FMT {0}, {1}, {2}, {3}", result.Name, result.Length, result.FormatString, string.Join(",", result.Columns));

            if (GenerateParser)
            {
                StringWriter sw = new StringWriter();
                GenerateLogEntryClass(result, sw);
                Debug.WriteLine(sw.ToString());
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Process each log entry
        /// </summary>
        /// <param name="packettype">packet type</param>
        /// <param name="br">input file</param>
        /// <returns>string of converted data</returns>
        string logEntry(byte packettype, Stream br)
        {
            switch (packettype)
            {
            case 0x80:      // FMT

                log_Format logfmt = new log_Format();

                object obj = logfmt;

                int len = Marshal.SizeOf(obj);

                byte[] bytearray = new byte[len];

                br.Read(bytearray, 0, bytearray.Length);

                IntPtr i = Marshal.AllocHGlobal(len);

                // create structure from ptr
                obj = Marshal.PtrToStructure(i, obj.GetType());

                // copy byte array to ptr
                Marshal.Copy(bytearray, 0, i, len);

                obj = Marshal.PtrToStructure(i, obj.GetType());

                Marshal.FreeHGlobal(i);

                logfmt = (log_Format)obj;

                string lgname   = ASCIIEncoding.ASCII.GetString(logfmt.name).Trim(new char[] { '\0' });
                string lgformat = ASCIIEncoding.ASCII.GetString(logfmt.format).Trim(new char[] { '\0' });
                string lglabels = ASCIIEncoding.ASCII.GetString(logfmt.labels).Trim(new char[] { '\0' });

                logformat[lgname] = logfmt;

                string line = String.Format("FMT, {0}, {1}, {2}, {3}, {4}\r\n", logfmt.type, logfmt.length, lgname, lgformat, lglabels);

                return(line);

            default:
                string format = "";
                string name   = "";
                int    size   = 0;

                foreach (log_Format fmt in logformat.Values)
                {
                    if (fmt.type == packettype)
                    {
                        name   = ASCIIEncoding.ASCII.GetString(fmt.name).Trim(new char[] { '\0' });
                        format = ASCIIEncoding.ASCII.GetString(fmt.format).Trim(new char[] { '\0' });
                        size   = fmt.length;
                        break;
                    }
                }

                // didnt find a match, return unknown packet type
                if (size == 0)
                {
                    return("UNKW, " + packettype);
                }

                byte[] data = new byte[size - 3];  // size - 3 = message - messagetype - (header *2)

                br.Read(data, 0, data.Length);

                return(ProcessMessage(data, name, format));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Process each log entry
        /// </summary>
        /// <param name="packettype">packet type</param>
        /// <param name="br">input file</param>
        /// <returns>string of converted data</returns>
        static string logEntry(byte packettype, BinaryReader br)
        {
            switch (packettype)
            {

                case 0x80:  // FMT

                    log_Format logfmt = new log_Format();

                    object obj = logfmt;

                    int len = Marshal.SizeOf(obj);

                    byte[] bytearray = br.ReadBytes(len);

                    IntPtr i = Marshal.AllocHGlobal(len);

                    // create structure from ptr
                    obj = Marshal.PtrToStructure(i, obj.GetType());

                    // copy byte array to ptr
                    Marshal.Copy(bytearray, 0, i, len);

                    obj = Marshal.PtrToStructure(i, obj.GetType());

                    Marshal.FreeHGlobal(i);

                    logfmt = (log_Format)obj;

                    string lgname = ASCIIEncoding.ASCII.GetString(logfmt.name).Trim(new char[] { '\0' });
                    string lgformat = ASCIIEncoding.ASCII.GetString(logfmt.format).Trim(new char[] { '\0' });
                    string lglabels = ASCIIEncoding.ASCII.GetString(logfmt.labels).Trim(new char[] { '\0' });

                    logformat[lgname] = logfmt;

                    string line = String.Format("FMT, {0}, {1}, {2}, {3}, {4}\r\n", logfmt.type, logfmt.length, lgname, lgformat, lglabels);

                    return line;

                default:
                    string format = "";
                    string name = "";
                    int size = 0;

                    foreach (log_Format fmt in logformat.Values)
                    {
                        if (fmt.type == packettype)
                        {
                            name = ASCIIEncoding.ASCII.GetString(fmt.name).Trim(new char[] { '\0' });
                            format = ASCIIEncoding.ASCII.GetString(fmt.format).Trim(new char[] { '\0' });
                            size = fmt.length;
                            break;
                        }
                    }

                    // didnt find a match, return unknown packet type
                    if (size == 0)
                        return "UNKW, " + packettype;

                    return ProcessMessage(br.ReadBytes(size - 3),name,format); // size - 3 = message - messagetype - (header *2)
            }
        }
Beispiel #4
0
        object[] logEntryObjects(byte packettype, Stream br)
        {
            switch (packettype)
            {
            case 0x80:     // FMT

                log_Format logfmt = new log_Format();

                object obj = logfmt;

                int len = Marshal.SizeOf(obj);

                byte[] bytearray = new byte[len];

                br.Read(bytearray, 0, bytearray.Length);

                IntPtr i = Marshal.AllocHGlobal(len);

                // create structure from ptr
                obj = Marshal.PtrToStructure(i, obj.GetType());

                // copy byte array to ptr
                Marshal.Copy(bytearray, 0, i, len);

                obj = Marshal.PtrToStructure(i, obj.GetType());

                Marshal.FreeHGlobal(i);

                logfmt = (log_Format)obj;

                string lgname   = ASCIIEncoding.ASCII.GetString(logfmt.name).Trim(new char[] { '\0' });
                string lgformat = ASCIIEncoding.ASCII.GetString(logfmt.format).Trim(new char[] { '\0' });
                string lglabels = ASCIIEncoding.ASCII.GetString(logfmt.labels).Trim(new char[] { '\0' });

                logformat[lgname] = logfmt;

                return(null);

            default:
                string format = "";
                string name   = "";
                int    size   = 0;

                if (packettypecache.ContainsKey(packettype))
                {
                    var fmt = packettypecache[packettype];
                    name   = fmt.name;
                    format = fmt.format;
                    size   = fmt.length;
                }
                else
                {
                    foreach (log_Format fmt in logformat.Values)
                    {
                        packettypecache[fmt.type] = new log_format_cache()
                        {
                            length = fmt.length,
                            type   = fmt.type,
                            name   = ASCIIEncoding.ASCII.GetString(fmt.name).Trim(new char[] { '\0' }),
                            format = ASCIIEncoding.ASCII.GetString(fmt.format).Trim(new char[] { '\0' }),
                        };

                        if (fmt.type == packettype)
                        {
                            name   = packettypecache[fmt.type].name;
                            format = packettypecache[fmt.type].format;
                            size   = fmt.length;
                            //break;
                        }
                    }
                }

                // didnt find a match, return unknown packet type
                if (size == 0)
                {
                    return(null);
                }

                byte[] data = new byte[size - 3];     // size - 3 = message - messagetype - (header *2)

                br.Read(data, 0, data.Length);

                return(ProcessMessageObjects(data, name, format));
            }
        }
Beispiel #5
0
        void logEntryFMT(byte packettype, Stream br)
        {
            lock (locker)
            {
                switch (packettype)
                {
                case 0x80:     // FMT

                    log_Format logfmt = new log_Format();

                    object obj = logfmt;

                    int len = Marshal.SizeOf(obj);

                    byte[] bytearray = new byte[len];

                    br.Read(bytearray, 0, bytearray.Length);

                    IntPtr i = Marshal.AllocHGlobal(len);

                    // create structure from ptr
                    obj = Marshal.PtrToStructure(i, obj.GetType());

                    // copy byte array to ptr
                    Marshal.Copy(bytearray, 0, i, len);

                    obj = Marshal.PtrToStructure(i, obj.GetType());

                    Marshal.FreeHGlobal(i);

                    logfmt = (log_Format)obj;

                    string lgname = ASCIIEncoding.ASCII.GetString(logfmt.name).Trim(new char[] { '\0' });
                    //string lgformat = ASCIIEncoding.ASCII.GetString(logfmt.format).Trim(new char[] {'\0'});
                    //string lglabels = ASCIIEncoding.ASCII.GetString(logfmt.labels).Trim(new char[] {'\0'});

                    logformat[lgname] = logfmt;

                    return;

                default:
                    //string format = "";
                    //string name = "";
                    int size = 0;

                    if (packettypecache[packettype].length != 0)
                    {
                        var fmt = packettypecache[packettype];
                        //name = fmt.name;
                        //format = fmt.format;
                        size = fmt.length;
                    }
                    else
                    {
                        foreach (log_Format fmt in logformat.Values)
                        {
                            packettypecache[fmt.type] = new log_format_cache()
                            {
                                length = fmt.length,
                                type   = fmt.type,
                                name   = ASCIIEncoding.ASCII.GetString(fmt.name).Trim(new char[] { '\0' }),
                                format = ASCIIEncoding.ASCII.GetString(fmt.format).Trim(new char[] { '\0' }),
                            };

                            if (fmt.type == packettype)
                            {
                                //name = packettypecache[fmt.type].name;
                                //format = packettypecache[fmt.type].format;
                                size = fmt.length;
                                //break;
                            }
                        }
                    }

                    // didnt find a match, return unknown packet type
                    if (size == 0)
                    {
                        return;
                    }

                    byte[] buf = new byte[size - 3];
                    br.Read(buf, 0, buf.Length);
                    break;
                }
            }
        }
Beispiel #6
0
        object[] logEntryObjects(byte packettype, Stream br)
        {
            switch (packettype)
            {
                case 0x80: // FMT

                    log_Format logfmt = new log_Format();

                    object obj = logfmt;

                    int len = Marshal.SizeOf(obj);

                    byte[] bytearray = new byte[len];

                    br.Read(bytearray, 0, bytearray.Length);

                    IntPtr i = Marshal.AllocHGlobal(len);

                    // create structure from ptr
                    obj = Marshal.PtrToStructure(i, obj.GetType());

                    // copy byte array to ptr
                    Marshal.Copy(bytearray, 0, i, len);

                    obj = Marshal.PtrToStructure(i, obj.GetType());

                    Marshal.FreeHGlobal(i);

                    logfmt = (log_Format) obj;

                    string lgname = ASCIIEncoding.ASCII.GetString(logfmt.name).Trim(new char[] {'\0'});
                    string lgformat = ASCIIEncoding.ASCII.GetString(logfmt.format).Trim(new char[] {'\0'});
                    string lglabels = ASCIIEncoding.ASCII.GetString(logfmt.labels).Trim(new char[] {'\0'});

                    logformat[lgname] = logfmt;

                    return null;

                default:
                    string format = "";
                    string name = "";
                    int size = 0;

                    foreach (log_Format fmt in logformat.Values)
                    {
                        if (fmt.type == packettype)
                        {
                            name = ASCIIEncoding.ASCII.GetString(fmt.name).Trim(new char[] {'\0'});
                            format = ASCIIEncoding.ASCII.GetString(fmt.format).Trim(new char[] {'\0'});
                            size = fmt.length;
                            break;
                        }
                    }

                    // didnt find a match, return unknown packet type
                    if (size == 0)
                        return null;

                    byte[] data = new byte[size - 3]; // size - 3 = message - messagetype - (header *2)

                    br.Read(data, 0, data.Length);

                    return ProcessMessageObjects(data, name, format);
            }
        }
        /// <summary>
        /// Process each log entry
        /// </summary>
        /// <param name="packettype">packet type</param>
        /// <param name="br">input file</param>
        /// <returns>string of converted data</returns>
        string logEntry(byte packettype, Stream br)
        {
            lock (locker)
            {
                switch (packettype)
                {
                    case 0x80: // FMT

                        log_Format logfmt = new log_Format();

                        object obj = logfmt;

                        int len = Marshal.SizeOf(obj);

                        byte[] bytearray = new byte[len];

                        br.Read(bytearray, 0, bytearray.Length);

                        IntPtr i = Marshal.AllocHGlobal(len);

                        // create structure from ptr
                        obj = Marshal.PtrToStructure(i, obj.GetType());

                        // copy byte array to ptr
                        Marshal.Copy(bytearray, 0, i, len);

                        obj = Marshal.PtrToStructure(i, obj.GetType());

                        Marshal.FreeHGlobal(i);

                        logfmt = (log_Format) obj;

                        string lgname = ASCIIEncoding.ASCII.GetString(logfmt.name).Trim(new char[] {'\0'});
                        string lgformat = ASCIIEncoding.ASCII.GetString(logfmt.format).Trim(new char[] {'\0'});
                        string lglabels = ASCIIEncoding.ASCII.GetString(logfmt.labels).Trim(new char[] {'\0'});

                        logformat[lgname] = logfmt;

                        string line = String.Format("FMT, {0}, {1}, {2}, {3}, {4}\r\n", logfmt.type, logfmt.length,
                            lgname,
                            lgformat, lglabels);

                        return line;

                    default:
                        string format = "";
                        string name = "";
                        int size = 0;

                        if (packettypecache.ContainsKey(packettype))
                        {
                            var fmt = packettypecache[packettype];
                            name = fmt.name;
                            format = fmt.format;
                            size = fmt.length;
                        }
                        else
                        {
                            foreach (log_Format fmt in logformat.Values)
                            {
                                packettypecache[fmt.type] = new log_format_cache()
                                {
                                    length = fmt.length,
                                    type = fmt.type,
                                    name = ASCIIEncoding.ASCII.GetString(fmt.name).Trim(new char[] {'\0'}),
                                    format = ASCIIEncoding.ASCII.GetString(fmt.format).Trim(new char[] {'\0'}),
                                };

                                if (fmt.type == packettype)
                                {
                                    name = packettypecache[fmt.type].name;
                                    format = packettypecache[fmt.type].format;
                                    size = fmt.length;
                                    //break;
                                }
                            }
                        }

                        // didnt find a match, return unknown packet type
                        if (size == 0)
                            return "UNKW, " + packettype;

                        byte[] data = new byte[size - 3]; // size - 3 = message - messagetype - (header *2)

                        br.Read(data, 0, data.Length);

                        return ProcessMessage(data, name, format);
                }
            }
        }
        void logEntryFMT(byte packettype, Stream br)
        {
            lock (locker)
            {
                switch (packettype)
                {
                    case 0x80: // FMT

                        log_Format logfmt = new log_Format();

                        object obj = logfmt;

                        int len = Marshal.SizeOf(obj);

                        byte[] bytearray = new byte[len];

                        br.Read(bytearray, 0, bytearray.Length);

                        IntPtr i = Marshal.AllocHGlobal(len);

                        // create structure from ptr
                        obj = Marshal.PtrToStructure(i, obj.GetType());

                        // copy byte array to ptr
                        Marshal.Copy(bytearray, 0, i, len);

                        obj = Marshal.PtrToStructure(i, obj.GetType());

                        Marshal.FreeHGlobal(i);

                        logfmt = (log_Format) obj;

                        string lgname = ASCIIEncoding.ASCII.GetString(logfmt.name).Trim(new char[] {'\0'});
                        string lgformat = ASCIIEncoding.ASCII.GetString(logfmt.format).Trim(new char[] {'\0'});
                        string lglabels = ASCIIEncoding.ASCII.GetString(logfmt.labels).Trim(new char[] {'\0'});

                        logformat[lgname] = logfmt;

                        return;

                    default:
                        string format = "";
                        string name = "";
                        int size = 0;

                        if (packettypecache.ContainsKey(packettype))
                        {
                            var fmt = packettypecache[packettype];
                            name = fmt.name;
                            format = fmt.format;
                            size = fmt.length;
                        }
                        else
                        {
                            foreach (log_Format fmt in logformat.Values)
                            {
                                packettypecache[fmt.type] = new log_format_cache()
                                {
                                    length = fmt.length,
                                    type = fmt.type,
                                    name = ASCIIEncoding.ASCII.GetString(fmt.name).Trim(new char[] {'\0'}),
                                    format = ASCIIEncoding.ASCII.GetString(fmt.format).Trim(new char[] {'\0'}),
                                };

                                if (fmt.type == packettype)
                                {
                                    name = packettypecache[fmt.type].name;
                                    format = packettypecache[fmt.type].format;
                                    size = fmt.length;
                                    //break;
                                }
                            }
                        }

                        // didnt find a match, return unknown packet type
                        if (size == 0)
                            return;

                        br.Seek(size - 3, SeekOrigin.Current);
                        break;
                }
            }
        }