Пример #1
0
def getFullNameWithID(rec):
    item = getFirstSubrecord(rec, 'FULL')
    if not item: return (None, '')
    plugin = rec.GetPlugin()
    data = ArraySegment[Byte](item.GetReadonlyData())
    if TypeConverter.IsLikelyString(data):
        return (None, item.GetStrData())
    else:
        id = TypeConverter.h2i(data)
        return (id, plugin.LookupFormStrings(id))
Пример #2
0
    def GetDescriptionSubRecord(self, rec):
        p = self.page

        # table has up to 5 columns
        ss = structure = rec.Structure
        if not structure or not structure.elementTree:
            with p.table(id='record-desc'):
                if ss:
                    with p.thead():
                        with p.tr():
                            p.td(ss.name, class_='headerlabel', width="33%")
                            p.td(ss.desc, colspan='4', class_='header')
                #with p.tfoot(): # write a blank footer to fix the HtmlRenderer Control
                #	with p.tr(class_='hidden'):
                #		p.td('',class_='header',width="33%").td('').td('').td('').td('')
                with p.tr():
                    p.td("String:", width="33%", class_='label')
                    p.td(rec.GetStrData(), class_='value', colspan='4')
                with p.tr():
                    p.td("Hex:", width="33%", class_='label')
                    p.td(rec.GetHexData(), class_='value', colspan='4')
            return

        try:
            plugin = rec.GetPlugin()
            pluginFile = plugin.Name
            elems = [elem for elem in rec.EnumerateElements(True)
                     if elem.Structure != None and not elem.Structure.notininfo]
            if not elems:
                return

            with p.table(id='record-desc'):
                with p.thead():
                    with p.tr():
                        p.td(ss.name, class_='headerlabel')
                        p.td(ss.desc, colspan='4', class_='header')
                #with p.tfoot(): # write a blank footer to fix the HtmlRenderer Control
                #	with p.tr(class_='hidden'):
                #		p.td('',class_='header',width="33%").td('').td('').td('').td('')
                with p.tbody():
                    for elem in elems:
                        sselem = elem.Structure
                        ssname = self.GetElementName(elem)
                        value = self.GetElementValue(elem)
                        strValue = str(value)

                        with p.tr():
                            p.td(ssname, width="33%", class_='label')

                            if sselem.type == ElementValueType.Blob:
                                p.td(TypeConverter.GetHexData(elem.Data), class_='value', colspan='4')
                            elif sselem.type == ElementValueType.Str4:
                                p.td(TypeConverter.GetString(elem.Data), class_='text', colspan='4')
                            elif sselem.type == ElementValueType.BString:
                                p.td(TypeConverter.GetBString(elem.Data), class_='text', colspan='4')
                            elif sselem.type == ElementValueType.IString:
                                p.td(TypeConverter.GetIString(elem.Data), class_='text', colspan='4')
                            elif sselem.type == ElementValueType.FormID:
                                if not value:
                                    p.td(strValue, class_='value', colspan='4')
                                else:
                                    formid = value.ToString("X8")
                                    record = plugin.GetRecordByID(value)
                                    if not record: # lookup plugin name using the id
                                        prefName = plugin.GetRecordMaster(value)
                                        with p.td(class_='formid', colspan='4'):
                                            p.a(formid, href=createLink(pluginFile, sselem.FormIDType, formid, prefName))
                                    else: # lookup actual record to know actual type
                                        pref = record.GetPlugin()
                                        with p.td(class_='formid', width="15%"):
                                            p.a(formid, href=createLink(pluginFile, record.Name, record.FormID.ToString("X8"), pref.Name))

                                        if record.Name != sselem.FormIDType:
                                            p.td(record.DescriptiveName, class_='text', width='20%')
                                        else:
                                            p.td(getEditorID(record), class_='text', width='20%')

                                        id, fullStr = getFullNameWithID(record)
                                        if id == None:
                                            p.td(fullStr, class_='text', colspan=2)
                                        else:
                                            p.td(id, class_='textid', width="15%")
                                            p.td(fullStr, class_='text')

                            elif sselem.type == ElementValueType.LString:
                                if elem.Type == ElementValueType.String:
                                    p.td(value, class_='text', colspan=4)
                                elif TypeConverter.IsLikelyString(elem.Data):
                                    p.td(TypeConverter.GetString(elem.Data), class_='text', colspan=4)
                                else:
                                    id = TypeConverter.h2i(elem.Data)
                                    p.td(id.ToString("X8"), class_='text')
                                    p.td(plugin.LookupFormStrings(id), class_='text', colspan=3)

                            elif sselem.type in (ElementValueType.SByte, ElementValueType.Int
                                                 , ElementValueType.Short, ElementValueType.Byte
                                                 , ElementValueType.UInt, ElementValueType.UShort):

                                if sselem.type in (ElementValueType.Byte, ElementValueType.UInt, ElementValueType.UShort):
                                    intVal = Convert.ToUInt32(value)
                                else:
                                    intVal = Convert.ToInt32(value)

                                hasOptions = sselem.options != None and sselem.options.Length > 0;
                                hasFlags = sselem.flags != None and sselem.flags.Length > 1;

                                if sselem.hexview or hasFlags:
                                    hexstr = value.ToString("X" + str(elem.Data.Count * 2))
                                    if sselem.hexviewwithdec:
                                        p.td(hexstr, class_='text', width="15%")
                                        p.td(strValue, class_='text', width="15%")
                                    else:
                                        p.td(hexstr, class_='text', colspan=3, width="30%")
                                else:
                                    p.td(strValue, class_='text', colspan=3, width="30%")

                                strDesc = ''
                                if hasOptions:
                                    for k in xrange(0, sselem.options.Length, 2):
                                        ok, intValOption = int.TryParse(sselem.options[k + 1])
                                        if ok and intVal == intValOption:
                                            strDesc = sselem.options[k]
                                elif hasFlags:
                                    sb = StringBuilder()
                                    for k in xrange(0, sselem.flags.Length, 1):
                                        if ((intVal & (1 << k)) != 0):
                                            if (sb.Length > 0):
                                                sb.Append("<br/>")
                                            sb.Append(sselem.flags[k])
                                    strDesc = sb.ToString()
                                p.td(strDesc, class_='desc', colspan=3, width='50%')
                                pass

                            else:
                                #p.td(str(sselem.type), class_='text',width='auto' )
                                p.td(strValue, class_='text', colspan=4)
        except Exception as e:
            p.p("Warning: Subrecord doesn't seem to match the expected structure", class_='danger')
            p.p(str(e), class_='danger')