Exemplo n.º 1
0
        /// <summary>
        /// Gets the size (in bytes) of the data type passed to the function and returns the value.  All data types, including primitive,
        /// type definitions, enumeations and structures can be evaluated, so it will be neccessary to pass in the HeaderData data set
        /// to use to check for the appropriate extracted data types, such as type definitions and structures that were defined in the header.
        /// </summary>
        /// <param name="HeaderAccess"></param>
        /// <param name="strDataTypeName"></param>
        /// <returns></returns>
        public static int SizeOfDataType(DataAccess HeaderAccess, string strDataTypeName)
        {
            try
            {
                int iDataSizeBytes = 0;

                if (DataAccess.PrimDataTypes.IsPrimitiveDataType(strDataTypeName))
                {
                    iDataSizeBytes = DataAccess.PrimDataTypes[strDataTypeName];
                }
                else if (HeaderAccess.TypeDefExists(strDataTypeName))
                {
                    CHeaderDataSet.tblTypeDefsRow rowTypeDef = HeaderAccess.GetTypeDef(strDataTypeName);
                    iDataSizeBytes = rowTypeDef.DataSize;
                }
                else if (HeaderAccess.StructExists(strDataTypeName))
                {
                    CHeaderDataSet.tblStructuresRow rowStruct = HeaderAccess.GetStruct(strDataTypeName);
                    iDataSizeBytes = rowStruct.DataSize;
                }//end if

                return(iDataSizeBytes);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in SizeOfDataType function of ExtractorUtils class.");
                return(0);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves a set of FieldData rows in the Fields data table in the Header Data Set object linked to the DataAccess class that are contained
        /// in the structure/union specified in the function's StructName parameter.  Each field in a structure/union will be keyed by the name of the
        /// structure/union concatenated with the index of the field.
        /// </summary>
        /// <param name="strStructName"></param>
        /// <returns></returns>
        public CHeaderDataSet.tblFieldsRow[] GetStructFields(string strStructName)
        {
            try
            {
                CHeaderDataSet.tblStructuresRow rowStruct = GetStruct(strStructName);

                if (rowStruct == null)
                {
                    return(null);
                }

                CHeaderDataSet.tblFieldsRow[] rowFields = new CHeaderDataSet.tblFieldsRow[rowStruct.FieldCount];

                for (int iFieldIndex = 0; iFieldIndex < rowFields.Length; iFieldIndex++)
                {
                    rowFields[iFieldIndex] = FieldsTable.FindByFieldKey(rowStruct.StructName + "_" + iFieldIndex.ToString());
                }//next iFieldIndex

                return(rowFields);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in GetStructFields function of DataAccess class.");
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads all controls in the form that display information specific to the selected structure in the Structures
        /// listbox.
        /// </summary>
        private void LoadStructInfo()
        {
            try
            {
                CHeaderDataSet.tblStructuresRow rowStruct = m_HeaderAccess.GetStruct(lbStructs.Items[lbStructs.SelectedIndex].ToString());
                lblStructName.Text       = rowStruct.StructName;
                lblStructSize.Text       = rowStruct.DataSize.ToString();
                lblStructFieldCount.Text = rowStruct.FieldCount.ToString();
                lblStructElements.Text   = rowStruct.Elements.ToString();

                if (rowStruct.StructUnion == 1)
                {
                    lblStructNameHdr.Text = "Structure Name";
                    lblStructSizeHdr.Text = "Structure Size (Bytes)";
                }
                else
                {
                    lblStructNameHdr.Text = "Union Name";
                    lblStructSizeHdr.Text = "Union Size (Bytes)";
                }//end if
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in LoadStructInfo function of frmCHeaderExtract form.");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieves the row in the Structures data table in the Header Data Set object linked to the DataAccess class with the name specified
        /// in the function's StructName parameter.
        /// </summary>
        /// <param name="strStructName"></param>
        /// <returns></returns>
        public CHeaderDataSet.tblStructuresRow GetStruct(string strStructName)
        {
            try
            {
                CHeaderDataSet.tblStructuresRow rowStruct = StructuresTable.FindByStructName(strStructName);

                return(rowStruct);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in GetStruct function of DataAccess class.");
                return(null);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Generates JSON formatted data structures a set of structures and their associated fields and exports the data to a JSON file
        /// specified in the FileName parameter.  This export file will contain the relevant information for each structure and be in a format
        /// that will allow for it to be loaded into a web page (such as the StructInfo.html page of the CHeaderParser program) or any
        /// other program that can consume and process JSON formatted data.
        /// The Structure/Union JSON export file will be in the following JSON format:
        /// "structs": [ { "structname",  "structdata": { "datasize", "fieldcount", "elements",
        ///                                                                 "fields": [ { "offset", "fieldtypename", "fieldname",
        ///                                                                                "fieldindex", "datasize", "elements" } ] } }]
        /// </summary>
        /// <param name="aryStructNames">An array of strings, containing the names of each struct to export.</param>
        /// <param name="strFileName">The full name and path of the struture/union export data file.  It will either be a JSON file or JS file
        /// containing all the JSON data assigned to a global variable.</param>
        /// <param name="exportType">Indicates whether the export file will be generated so that it can be loaded into a page hosted
        /// either locally or on a web server.   If an export data file is to be generated that is to be used in a locally hosted web file, then
        /// a javascript file will be generated that will load the entire exported JSON data structure into a global variable.  When the a web
        /// file hosted on a server is used, the data will be exported to a standard JSON formatted data file that can be consumed by the
        /// server hosted  web application.</param>
        public bool ExportStructs(string[] aryStructNames, string strFileName, WebExportTypeEnum exportType)
        {
            try
            {
                CHeaderDataSet.tblStructuresRow[] aryStructs = new CHeaderDataSet.tblStructuresRow[aryStructNames.Length];

                for (int i = 0; i < aryStructNames.Length; i++)
                {
                    aryStructs[i] = m_HeaderAccess.GetStruct(aryStructNames[i]);
                }

                return(ExportStructs(aryStructs, strFileName, exportType));
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in ExportStructs Overload 2 function of DataExport class.");
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Queries the data type associated with the field with the specified key passed to the function.  The linked data type record will be returned
        /// by the function.   Depending on what type of data type is associated with the field, will determine whether a structure data row, typedef data row
        /// or primitive data object is returned by the function.  Primtive data types will not be stored in the Header Data Set and will have its data returned
        /// from the Global Primitive data object.
        /// </summary>
        /// <param name="strFieldKey"></param>
        /// <returns></returns>
        public object QueryFieldTypeDataByKey(string strFieldKey)
        {
            try
            {
                CHeaderDataSet.tblFieldsRow rowField = FieldsTable.FindByFieldKey(strFieldKey);

                if (rowField == null)
                {
                    return(null);
                }

                switch ((FieldTypeEnum)rowField.FieldType)
                {
                case FieldTypeEnum.Primitive:
                case FieldTypeEnum.Enum:
                case FieldTypeEnum.Pointer:
                    object[] aryPrimTypeData = new object[] { rowField.FieldTypeName, DataAccess.PrimDataTypes[rowField.FieldTypeName] };

                    return(aryPrimTypeData);

                case FieldTypeEnum.TypeDef:
                    CHeaderDataSet.tblTypeDefsRow rowTypeDef = TypeDefsTable.FindByTypeDefName(rowField.FieldTypeName);

                    return(rowTypeDef);

                case FieldTypeEnum.Structure:
                    CHeaderDataSet.tblStructuresRow rowStruct = StructuresTable.FindByStructName(rowField.FieldTypeName);

                    return(rowStruct);
                }
                ;

                return(null);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in QueryFieldTypeDataByKey function of DataAccess class.");

                return(null);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds a row to the Structures data table in the Header Data Set object linked to the DataAccess class using the data contained in the
        /// StructData object passed to the function.  The StructData object will contain all the required information needed to create a structure record
        /// in the Structures table.
        /// </summary>
        /// <param name="sdStruct"></param>
        /// <returns></returns>
        public bool AddStructRow(StructData sdStruct)
        {
            try
            {
                CHeaderDataSet.tblStructuresRow rowStruct = StructuresTable.NewtblStructuresRow();

                rowStruct.StructName  = sdStruct.StructName;
                rowStruct.StructUnion = (byte)sdStruct.StructUnion;
                rowStruct.FieldCount  = sdStruct.Fields.Count;
                rowStruct.Elements    = sdStruct.Elements;
                rowStruct.DataSize    = sdStruct.DataSize;

                StructuresTable.AddtblStructuresRow(rowStruct);

                return(true);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in AddStructRow function of DataAccess class.");
                return(false);
            }
        }
Exemplo n.º 8
0
        private void lbStructs_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (m_CancelEvents.ListBoxIndexChanged)
                {
                    return;
                }

                if (lbStructs.SelectedIndex != -1)
                {
                    //Loads all the information of the fields contained in the selected structure into the fields grid control.
                    CHeaderDataSet.tblFieldsViewDataTable tblFieldsView = dsHeaderDataView.tblFieldsView;
                    tblFieldsView.Rows.Clear();

                    CHeaderDataSet.tblFieldsRow[] aryStructFields =
                        m_HeaderAccess.GetStructFields(lbStructs.Items[lbStructs.SelectedIndex].ToString());

                    foreach (CHeaderDataSet.tblFieldsRow rowField in aryStructFields)
                    {
                        CHeaderDataSet.tblFieldsViewRow rowFieldView = tblFieldsView.NewtblFieldsViewRow();

                        for (int i = 0; i < tblFieldsView.Columns.Count; i++)
                        {
                            if (m_HeaderAccess.FieldsTable.Columns.Contains(tblFieldsView.Columns[i].ColumnName))
                            {
                                rowFieldView[i] = rowField[tblFieldsView.Columns[i].ColumnName];
                            }
                            else if (tblFieldsView.Columns[i].ColumnName == "DataType")
                            {
                                switch ((FieldTypeEnum)rowField.FieldType)
                                {
                                case FieldTypeEnum.Enum:
                                    rowFieldView[i] = "enum";
                                    break;

                                case FieldTypeEnum.TypeDef:
                                    rowFieldView[i] = "typedef";
                                    break;

                                case FieldTypeEnum.Structure:
                                    CHeaderDataSet.tblStructuresRow rowStruct = m_HeaderAccess.GetStruct(rowFieldView.FieldTypeName);

                                    if (rowStruct != null)
                                    {
                                        if (m_HeaderAccess.GetStruct((rowFieldView.FieldTypeName)).StructUnion == 1)
                                        {
                                            rowFieldView[i] = "struct";
                                        }
                                        else
                                        {
                                            rowFieldView[i] = "union";
                                        }
                                    }
                                    else
                                    {
                                        rowFieldView[i] = "struct/union";
                                    }

                                    break;

                                case FieldTypeEnum.Primitive:
                                    rowFieldView[i] = "primitive";
                                    break;

                                case FieldTypeEnum.Pointer:
                                    rowFieldView[i] = "pointer";
                                    break;
                                }
                                ; //end switch
                            }//end if
                        }//next i

                        tblFieldsView.AddtblFieldsViewRow(rowFieldView);
                    }//next rowField

                    //Loads all controls in the form that display information specific to the selected structure in the Structures
                    //listbox.
                    LoadStructInfo();
                }//end if
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in lbStructs_SelectedIndexChanged function of frmCHeaderExtract form.");
            }
        }