use of com.google.security.zynamics.binnavi.disassembly.types.TypeMember in project binnavi by google.
the class TypeSubstitutionDialog method createOrUpdateSubstitution.
private void createOrUpdateSubstitution(final TypeSelectionPath path) throws CouldntSaveDataException {
final int offset = path.determineTotalMemberOffset();
final BaseType baseType = path.getRootType();
final int position = selectedNode.getOperandPosition();
final IAddress address = selectedNode.getInstructionAddress();
final TypeSubstitution substitution = selectedNode.getTypeSubstitution();
final List<TypeMember> memberPath = path.getMembers();
if (substitution == null) {
typeManager.createTypeSubstitution(selectedNode, baseType, memberPath, position, offset, address);
} else {
typeManager.updateTypeSubstitution(selectedNode, substitution, baseType, path.getMembers(), offset);
}
}
use of com.google.security.zynamics.binnavi.disassembly.types.TypeMember in project binnavi by google.
the class AppendMemberAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
final MemberDialog dlg = MemberDialog.createBuildNewMemberDialog(owner, typeManager);
GuiHelper.centerChildToParent(owner, dlg, true);
dlg.setVisible(true);
if (!dlg.wasCanceled()) {
final String name = dlg.getMemberName();
final BaseType baseType = dlg.getBaseType();
try {
final TypeMember member = typeManager.appendMember(selectedType, baseType, name);
if (member == null) {
CMessageBox.showInformation(owner, "Unable to append member since that would create a recursive type definition.");
}
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.types.TypeMember in project binnavi by google.
the class TypeDependenceGraph method initializeMembers.
/**
* Initializes a set of members in the type dependence graph. This function is supposed to be used
* on database load only. The reason for this class is reduction of database load time. This is
* due to the normal mechanism of adding a member where the type system ensures consistency. On
* load time we assume that the data from the database is sane and will bail out otherwise.
*
* @param members The {@link ImmutableCollection collection} of {@link TypeMember type members} to
* add to the dependence graph.
*/
private void initializeMembers(final ImmutableCollection<TypeMember> members) {
Preconditions.checkNotNull(members, "Error: members argument can not be null.");
for (TypeMember typeMember : members) {
final Node memberTypeNode = containedRelationMap.get(typeMember.getBaseType());
final Node parentNode = containedRelationMap.get(typeMember.getParentType());
containedRelation.createEdge(memberTypeNode, parentNode);
}
if (!Cycles.findCycle(containedRelation, true).isEmpty()) {
throw new IllegalStateException("Error: Dependence graph has cycles after initialization.");
}
}
use of com.google.security.zynamics.binnavi.disassembly.types.TypeMember in project binnavi by google.
the class BaseTypeTableCellRenderer method renderStruct.
private static void renderStruct(final TypeInstance instance, final StyledDocument document, final boolean renderData) {
final Style structNameStyle = createDeclarationStyle(document);
final Style structMemberStyle = document.addStyle("STRUCTMEMBERSTYLE", structNameStyle);
StyleConstants.setForeground(structMemberStyle, Color.GRAY);
final Style structContentStyle = document.addStyle("STRUCTCONTENTSTYLE", structNameStyle);
StyleConstants.setForeground(structContentStyle, Color.BLUE);
StyleConstants.setAlignment(structNameStyle, StyleConstants.ALIGN_RIGHT);
final BaseType baseType = instance.getBaseType();
int maxMemberLength = 0;
for (final TypeMember member : baseType) {
if (member.getBaseType().getName().length() > maxMemberLength) {
maxMemberLength = member.getBaseType().getName().length();
}
}
int maxNameLength = 0;
for (final TypeMember member : baseType) {
if (member.getName().length() > maxNameLength) {
maxNameLength = member.getName().length();
}
}
/* Renders type information for structures - construct a string such as:
*
* struct STRUCT_NAME { BASE_TYPE_NAME
*/
try {
document.remove(0, document.getLength());
appendString(document, "struct " + baseType.getName() + " {\n", structNameStyle);
long memberOffset = 0;
for (final TypeMember member : baseType) {
appendString(document, " " + member.getBaseType().getName(), structNameStyle);
final String separator = Strings.repeat(" ", maxMemberLength - member.getBaseType().getName().length() + 1);
appendString(document, separator + member.getName(), structMemberStyle);
appendString(document, ";", structMemberStyle);
if (renderData) {
final String dataSeperator = Strings.repeat(".", maxNameLength - member.getName().length() + 1);
appendString(document, dataSeperator, structNameStyle);
appendString(document, renderInstanceData(member.getBaseType(), instance.getAddress().getOffset() + memberOffset, instance.getSection()), createDataStyle(document));
memberOffset += member.getBaseType().getByteSize();
}
appendString(document, "\n", structMemberStyle);
}
appendString(document, "};", structNameStyle);
} catch (final BadLocationException exception) {
CUtilityFunctions.logException(exception);
}
}
use of com.google.security.zynamics.binnavi.disassembly.types.TypeMember in project binnavi by google.
the class ViewReferencesTableModel method addCompoundTypeSubstitutionToTree.
/**
* Adds a {@link TypeSubstitution type substitution} for the given {@link INaviInstruction
* instruction} to the tree. The types passed to this function need to be compund types.
*
* @param operandNode The {@link INaviOperandTreeNode operand node} which holds the
* {@link TypeSubstitution type substitution}.
* @param instruction The {@link INaviInstruction instruction} which holds the
* {@link INaviOperandTreeNode operand node}.
* @param typeSubstitution A {@link TypeSubstitution type substitution} which is a compound type.
* Must be of a compound {@link BaseTypeCategory base type category}.
*/
private void addCompoundTypeSubstitutionToTree(final INaviOperandTreeNode operandNode, final INaviInstruction instruction, final TypeSubstitution typeSubstitution) {
final long completeOffset = operandNode.hasAddendSibling() ? (operandNode.determineAddendValue() * 8 + typeSubstitution.getOffset()) : typeSubstitution.getOffset();
final WalkResult walkResult = BaseTypeHelpers.findMember(typeSubstitution.getBaseType(), completeOffset);
if (!walkResult.isValid()) {
return;
}
addBaseType(typeSubstitution.getBaseType());
DefaultMutableTreeNode currentNode = baseTypeToTreeNode.get(typeSubstitution.getBaseType());
for (TypeMember typeMember : walkResult.getPath()) {
TypeMemberTreeNode nextNode = checkTypeMemberNodeExists(typeMember, currentNode);
if (nextNode == null) {
nextNode = new TypeMemberTreeNode(typeMember);
typeMemberToTreeNode.put(typeMember, nextNode);
insertNodeInto(nextNode, currentNode, currentNode.getChildCount());
}
currentNode = nextNode;
}
insertNodeInto(multiIndex.putTypeSubstitution(typeSubstitution, instruction), currentNode, currentNode.getChildCount());
}
Aggregations