Java Code Examples for ghidra.program.model.data.StructureDataType#add()

The following examples show how to use ghidra.program.model.data.StructureDataType#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RuntimeParameterAnnotationsAttribute.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public DataType toDataType() throws DuplicateNameException, IOException {
	String name = _isVisible
			? "RuntimeVisibleParameterAnnotations_attribute" + "|" + numberOfParameters + "|"
			: "RuntimeInvisibleParameterAnnotations_attribute" + "|" + numberOfParameters + "|";

	StructureDataType structure = getBaseStructure(name);
	structure.add(BYTE, "num_parameters", null);
	for (int i = 0; i < numberOfParameters; ++i) {
		structure.add(WORD, "num_annotations_" + i, null);
		AnnotationJava[] annotations = parameterAnnotations.get(i);
		for (int a = 0; a < annotations.length; ++a) {
			structure.add(annotations[a].toDataType(), "annotations_" + i + "_" + a, null);
		}
	}

	return structure;
}
 
Example 2
Source File: GoTypesAnalyzer.java    From gotools with MIT License 6 votes vote down vote up
@Override
public boolean added(Program program, AddressSetView addressSetView, TaskMonitor taskMonitor,
    MessageLog messageLog) throws CancelledException {
  StructureDataType s = new StructureDataType("GoString", 0);
  s.add(new QWordDataType(), "len", null);
  s.add(new Pointer64DataType(new CharDataType()), "str", null);
  program.getDataTypeManager().addDataType(s, DataTypeConflictHandler.KEEP_HANDLER);

  StructureDataType sl = new StructureDataType("GoSlice", 0);
  sl.add(new PointerDataType(), 8, "data", null);
  sl.add(new QWordDataType(), "len", null);
  sl.add(new QWordDataType(), "cap", null);

  program.getDataTypeManager().addDataType(sl, DataTypeConflictHandler.KEEP_HANDLER);
  return false;
}
 
Example 3
Source File: RuntimeVisibleAnnotationsAttribute.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public DataType toDataType() throws DuplicateNameException, IOException {
	StructureDataType structure = getBaseStructure( "RuntimeVisibleAnnotations_attribute" );
	if ( infoBytes.length > 0 ) {
		DataType array = new ArrayDataType( BYTE, infoBytes.length, BYTE.getLength() );
		structure.add( array, "info", null );
	}
	return structure;
}
 
Example 4
Source File: PreviewTableCellDataTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisplayString_StructureFieldLocation() {

	StructureDataType struct = new StructureDataType("TestStruct", 0);
	struct.add(new CharDataType());
	struct.add(new StringDataType(), 4);
	struct.add(new TerminatedStringDataType(), 8);
	struct.add(new UnicodeDataType(), 12);

	Address structAddress = addr("f0001302");
	CreateDataCmd cmd = new CreateDataCmd(structAddress, true, struct);
	assertTrue(applyCmd(program, cmd));

	Address address = addr("f0001307");
	int[] componentPath = new int[] { 2 }; // second field
	Address refAddr = null;
	String rep = "\"\",00";
	int opIndex = 0;
	int charOffset = 0;
	OperandFieldLocation location = new OperandFieldLocation(program, address, componentPath,
		refAddr, rep, opIndex, charOffset);

	PreviewTableCellData data = new PreviewTableCellData(location, formatter);
	String preview = data.getDisplayString();

	// this is the mnemonic and operand inside of the structure at field [2]
	assertEquals("ds \"\" (TestStruct.field_0x5)", preview);
}
 
Example 5
Source File: LocalVariableTableAttribute.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public DataType toDataType() throws DuplicateNameException, IOException {
	StructureDataType structure = getBaseStructure("LocalVariableTable_attribute");
	structure.add(WORD, "local_variable_table_length", null);
	for (int i = 0; i < localVariableTable.length; ++i) {
		structure.add(localVariableTable[i].toDataType(), "local_variable_" + i, null);
	}
	return structure;
}
 
Example 6
Source File: CliTableExportedType.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public StructureDataType getRowDataType() {
	StructureDataType rowDt = new StructureDataType(new CategoryPath(PATH), "ExportedType Row", 0);
	rowDt.add(CliEnumTypeAttributes.dataType, "Flags", "Bitmask of type TypeAttributes");
	rowDt.add(DWORD, "TypeDefId", "4B index into TypeDef table of another module in this Assembly. Hint only. Must match other fields in this row.");
	rowDt.add(metadataStream.getStringIndexDataType(), "TypeName", "index into String heap");
	rowDt.add(metadataStream.getStringIndexDataType(), "TypeNamespace", "index into String heap");
	rowDt.add(CliIndexImplementation.toDataType(metadataStream), "Implementation", "index into File or ExportedType table.");
	return rowDt;
}
 
Example 7
Source File: ObjectiveC1_ProtocolMethod.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public DataType toDataType() throws DuplicateNameException, IOException {
	StructureDataType struct = new StructureDataType(NAME, 0);
	struct.setCategoryPath(ObjectiveC1_Constants.CATEGORY_PATH);
	struct.add(PointerDataType.getPointer(ASCII, _state.pointerSize), "name", null);
	struct.add(PointerDataType.getPointer(ASCII, _state.pointerSize), "types", null);
	return struct;
}
 
Example 8
Source File: CliTableFile.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public StructureDataType getRowDataType() {
	StructureDataType rowDt = new StructureDataType(new CategoryPath(PATH), "File Row", 0);
	rowDt.add(CliEnumFileAttributes.dataType, "Flags", "Bitmask of type FileAttributes");
	rowDt.add(metadataStream.getStringIndexDataType(), "Name", "index into String heap");
	rowDt.add(metadataStream.getBlobIndexDataType(), "Hash", "index into Blob heap");
	return rowDt;
}
 
Example 9
Source File: CliTableMethodSpec.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public StructureDataType getRowDataType() {
	StructureDataType rowDt = new StructureDataType(new CategoryPath(PATH), "MethodSpec Row", 0);
	rowDt.add(CliIndexMethodDefOrRef.toDataType(metadataStream), "Method", "MethodDefOrRef coded index");
	rowDt.add(metadataStream.getBlobIndexDataType(), "Instantiation", "index into Blob heap, signature of this instantiation");
	return rowDt;
}
 
Example 10
Source File: CliTableManifestResource.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public StructureDataType getRowDataType() {
	StructureDataType rowDt = new StructureDataType(new CategoryPath(PATH), "ManifestResource Row", 0);
	rowDt.add(DWORD, "Offset", null);
	rowDt.add(CliEnumManifestResourceAttributes.dataType, "Flags", "Bitmask of type ManifestResourceAttributes");
	rowDt.add(metadataStream.getStringIndexDataType(), "Name", "index into String heap");
	rowDt.add(CliIndexImplementation.toDataType(metadataStream), "Implementation", "Implementation coded index");
	return rowDt;
}
 
Example 11
Source File: LineNumber.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public DataType toDataType() throws DuplicateNameException, IOException {
	StructureDataType structure = new StructureDataType("line_number", 0);
	structure.add(WORD, "start_pc", null);
	structure.add(WORD, "line_number", null);
	return structure;
}
 
Example 12
Source File: CliTableTypeDef.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public StructureDataType getRowDataType() {
	StructureDataType rowDt = new StructureDataType(new CategoryPath(PATH), "TypeDef Row", 0);
	rowDt.add(CliEnumTypeAttributes.dataType, "Flags", "see CorTypeAttr");
	rowDt.add(metadataStream.getStringIndexDataType(), "TypeName", "index into String heap");
	rowDt.add(metadataStream.getStringIndexDataType(), "TypeNamespace", "index into String heap");
	rowDt.add(CliIndexTypeDefOrRef.toDataType(metadataStream), "Extends", "index: coded TypeDefOrRef");
	rowDt.add(metadataStream.getTableIndexDataType(CliTypeTable.Field), "FieldList", "index into Field table");
	rowDt.add(metadataStream.getTableIndexDataType(CliTypeTable.MethodDef), "MethodList", "index into MethodDef table");
	return rowDt;
}
 
Example 13
Source File: AnnotationJava.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public DataType toDataType() throws DuplicateNameException, IOException {
	String name = "annotation" + "|" + numberOfElementValuePairs + "|";
	StructureDataType structure = new StructureDataType(name, 0);
	structure.add(WORD, "type_index", null);
	structure.add(WORD, "num_element_value_pairs", null);
	for (int i = 0; i < elementValuePairs.length; ++i) {
		structure.add(elementValuePairs[i].toDataType(), "element_value_pair_" + i, null);
	}
	return structure;
}
 
Example 14
Source File: AnnotationElementValuePair.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public DataType toDataType() throws DuplicateNameException, IOException {
	StructureDataType structure = new StructureDataType("element_value_pair", 0);
	structure.add(WORD, "element_name_index", null);
	structure.add(value.toDataType(), "element_value_pair", null);
	return structure;
}
 
Example 15
Source File: CliTableClassLayout.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public StructureDataType getRowDataType() {
	StructureDataType rowDt = new StructureDataType(new CategoryPath(PATH), "ClassLayout Row", 0);
	rowDt.add( WORD, "PackingSize", null);
	rowDt.add(DWORD, "ClassSize", null);
	rowDt.add(metadataStream.getTableIndexDataType(CliTypeTable.TypeDef), "Parent", null);
	return rowDt;
}
 
Example 16
Source File: CliTableField.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public StructureDataType getRowDataType() {
	StructureDataType rowDt = new StructureDataType(new CategoryPath(PATH), "Field Row", 0);
	rowDt.add(CliEnumFieldAttributes.dataType, "Flags", "see CorFieldAttr");
	rowDt.add(metadataStream.getStringIndexDataType(), "Name", "index into String heap");
	rowDt.add(metadataStream.getBlobIndexDataType(), "Signature", "index into Blob heap");
	return rowDt;
}
 
Example 17
Source File: LocalVariableTypeTableAttribute.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public DataType toDataType() throws DuplicateNameException, IOException {
	StructureDataType structure = getBaseStructure( "LocalVariableTypeTable_attribute" );
	if ( infoBytes.length > 0 ) {
		DataType array = new ArrayDataType( BYTE, infoBytes.length, BYTE.getLength() );
		structure.add( array, "info", null );
	}
	return structure;
}
 
Example 18
Source File: CliTableDeclSecurity.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public StructureDataType getRowDataType() {
	StructureDataType rowDt = new StructureDataType(new CategoryPath(PATH), "DeclSecurity Row", 0);
	rowDt.add( WORD, "Action", "Points to a System.Security.SecurityAction as described in ISO23271 IV");
	rowDt.add(CliIndexHasDeclSecurity.toDataType(metadataStream), "Parent", null);
	rowDt.add(metadataStream.getBlobIndexDataType(), "PermissionSet", null);
	return rowDt;
}
 
Example 19
Source File: SignatureAttribute.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public DataType toDataType() throws DuplicateNameException, IOException {
	StructureDataType structure = getBaseStructure("Signature_attribute");
	structure.add(WORD, "signature_index", null);
	return structure;
}
 
Example 20
Source File: ModuleMainClassAttribute.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public DataType toDataType() throws DuplicateNameException, IOException {
	StructureDataType structure = getBaseStructure("ModuleMainClass_attribute");
	structure.add(WORD, "main_class_index", null);
	return structure;
}