mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
GP-5367: Filter by max_primitives on homogeneous aggregate types in cspec
This commit is contained in:
parent
db1b6860c9
commit
3067d3e61f
7 changed files with 67 additions and 20 deletions
|
@ -1254,7 +1254,8 @@ AttributeId ATTRIB_WORDSIZE = AttributeId("wordsize",26);
|
|||
AttributeId ATTRIB_STORAGE = AttributeId("storage",149);
|
||||
AttributeId ATTRIB_STACKSPILL = AttributeId("stackspill",150);
|
||||
|
||||
AttributeId ATTRIB_UNKNOWN = AttributeId("XMLunknown",152); // Number serves as next open index
|
||||
AttributeId ATTRIB_UNKNOWN = AttributeId("XMLunknown",154); // Number serves as next open index
|
||||
|
||||
|
||||
ElementId ELEM_DATA = ElementId("data",1);
|
||||
ElementId ELEM_INPUT = ElementId("input",2);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
namespace ghidra {
|
||||
|
||||
AttributeId ATTRIB_SIZES = AttributeId("sizes",151);
|
||||
AttributeId ATTRIB_MAX_PRIMITIVES = AttributeId("maxprimitives", 153);
|
||||
|
||||
ElementId ELEM_DATATYPE = ElementId("datatype",273);
|
||||
ElementId ELEM_CONSUME = ElementId("consume",274);
|
||||
|
@ -224,9 +225,9 @@ bool PrimitiveExtractor::extract(Datatype *dt,int4 max,int4 offset)
|
|||
if (!extract(compDt,max,curOff))
|
||||
return false;
|
||||
expectedOff = curOff + compDt->getAlignSize();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// \param dt is data-type extract from
|
||||
/// \param unionIllegal is \b true if unions encountered during extraction are considered illegal
|
||||
|
@ -385,11 +386,11 @@ HomogeneousAggregate::HomogeneousAggregate(type_metatype meta)
|
|||
|
||||
{
|
||||
metaType = meta;
|
||||
maxPrimitives = 2;
|
||||
maxPrimitives = 4;
|
||||
}
|
||||
|
||||
HomogeneousAggregate::HomogeneousAggregate(type_metatype meta,int4 maxPrim,int4 min,int4 max)
|
||||
: SizeRestrictedFilter(min,max)
|
||||
HomogeneousAggregate::HomogeneousAggregate(type_metatype meta,int4 maxPrim,int4 minSize,int4 maxSize)
|
||||
: SizeRestrictedFilter(minSize, maxSize)
|
||||
{
|
||||
metaType = meta;
|
||||
maxPrimitives = maxPrim;
|
||||
|
@ -408,7 +409,7 @@ bool HomogeneousAggregate::filter(Datatype *dt) const
|
|||
type_metatype meta = dt->getMetatype();
|
||||
if (meta != TYPE_ARRAY && meta != TYPE_STRUCT)
|
||||
return false;
|
||||
PrimitiveExtractor primitives(dt,true,0,4);
|
||||
PrimitiveExtractor primitives(dt,true,0,maxPrimitives);
|
||||
if (!primitives.isValid() || primitives.size() == 0 || primitives.containsUnknown()
|
||||
|| !primitives.isAligned() || primitives.containsHoles())
|
||||
return false;
|
||||
|
@ -422,6 +423,21 @@ bool HomogeneousAggregate::filter(Datatype *dt) const
|
|||
return true;
|
||||
}
|
||||
|
||||
void HomogeneousAggregate::decode(Decoder &decoder)
|
||||
{
|
||||
SizeRestrictedFilter::decode(decoder);
|
||||
decoder.rewindAttributes();
|
||||
for(;;) {
|
||||
uint4 attribId = decoder.getNextAttributeId();
|
||||
if (attribId == 0) break;
|
||||
if (attribId == ATTRIB_MAX_PRIMITIVES) {
|
||||
uint4 xmlMaxPrim = decoder.readUnsignedInteger();
|
||||
if (xmlMaxPrim > 0) maxPrimitives = xmlMaxPrim;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// If the next element is a qualifier filter, decode it from the stream and return it.
|
||||
/// Otherwise return null
|
||||
/// \param decoder is the given stream decoder
|
||||
|
|
|
@ -29,6 +29,7 @@ class ParamEntry;
|
|||
class ParamActive;
|
||||
|
||||
extern AttributeId ATTRIB_SIZES; ///< Marshaling attribute "sizes"
|
||||
extern AttributeId ATTRIB_MAX_PRIMITIVES; ///< Marshaling attribute "maxprimitives"
|
||||
|
||||
extern ElementId ELEM_DATATYPE; ///< Marshaling element \<datatype>
|
||||
extern ElementId ELEM_CONSUME; ///< Marshaling element \<consume>
|
||||
|
@ -151,10 +152,11 @@ class HomogeneousAggregate : public SizeRestrictedFilter {
|
|||
int4 maxPrimitives; ///< Maximum number of primitives in the aggregate
|
||||
public:
|
||||
HomogeneousAggregate(type_metatype meta); ///< Constructor for use with decode()
|
||||
HomogeneousAggregate(type_metatype meta,int4 maxPrim,int4 min,int4 max); ///< Constructor
|
||||
HomogeneousAggregate(type_metatype meta,int4 maxPrim,int4 minSize,int4 maxSize); ///< Constructor
|
||||
HomogeneousAggregate(const HomogeneousAggregate &op2); ///< Copy constructor
|
||||
virtual DatatypeFilter *clone(void) const { return new HomogeneousAggregate(*this); }
|
||||
virtual bool filter(Datatype *dt) const;
|
||||
virtual void decode(Decoder &decoder);
|
||||
};
|
||||
|
||||
/// \brief A filter on some aspect of a specific function prototype
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue