public WriteDeclaration ( DataType dt, string name ) : void | ||
dt | DataType | |
name | string | |
Результат | void |
private void WriteGlobalVariable(StructureField field) { var name = program.NamingPolicy.GlobalName(field); var addr = Address.Ptr32((uint)field.Offset); //$BUG: this is completely wrong; field.Offsets should be as wide as the platform permits. try { tw.WriteDeclaration(field.DataType, name); if (program.SegmentMap.IsValidAddress(addr)) { formatter.Write(" = "); this.rdr = program.CreateImageReader(program.Architecture, addr); field.DataType.Accept(this); } } catch (Exception ex) { var dc = services.RequireService <DecompilerEventListener>(); dc.Error( dc.CreateAddressNavigator(program, addr), ex, "Failed to write global variable {0}.", name); } formatter.Terminate(";"); }
public void WriteGlobalVariable(Address address, DataType dataType, string name, Formatter formatter) { this.formatter = formatter; this.codeFormatter = new CodeFormatter(formatter); this.tw = new TypeReferenceFormatter(formatter); this.globals = new StructureType(); this.queue = new Queue <StructureField>(globals.Fields); try { tw.WriteDeclaration(dataType, name); if (program.SegmentMap.IsValidAddress(address)) { formatter.Write(" = "); this.rdr = program.CreateImageReader(program.Architecture, address); dataType.Accept(this); } } catch (Exception ex) { var dc = services.RequireService <DecompilerEventListener>(); dc.Error( dc.CreateAddressNavigator(program, address), ex, "Failed to write global variable {0}.", name); } formatter.Terminate(";"); }
public Formatter VisitUnion(UnionType ut) { string n = name; writer.WriteKeyword("union"); writer.Write(" "); writer.Write(ut.Name); OpenBrace(); int i = 0; foreach (UnionAlternative alt in ut.Alternatives.Values) { BeginLine(); name = alt.MakeName(i); var trf = new TypeReferenceFormatter(writer, true); trf.WriteDeclaration(alt.DataType, name); EndLine(";"); ++i; } CloseBrace(); name = n; WriteName(true); return(writer); }
public void WriteGlobals(Formatter formatter) { this.codeFormatter = new CodeFormatter(formatter); var tw = new TypeReferenceFormatter(formatter, true); this.globals = (StructureType)((EquivalenceClass)((Pointer)program.Globals.TypeVariable.DataType).Pointee).DataType; foreach (var field in globals.Fields) { var name = string.Format("g_{0:X}", field.Name); var addr = Address.Ptr32((uint)field.Offset); //$BUG: this is completely wrong; offsets should be as wide as the platform permits. try { tw.WriteDeclaration(field.DataType, name); if (program.Image.IsValidAddress(addr)) { formatter.Write(" = "); this.rdr = program.CreateImageReader(addr); field.DataType.Accept(this); } } catch (Exception ex) { var dc = services.RequireService <DecompilerEventListener>(); dc.Error( dc.CreateAddressNavigator(program, addr), ex, string.Format("Failed to write global variable {0}.", name)); } formatter.Terminate(";"); } }
public void Tyreffmt_ptr_TypeReference() { var sw = new StringWriter(); var trf = new TypeReferenceFormatter(new TextFormatter(sw)); trf.WriteDeclaration( new Pointer( new TypeReference("LONG", PrimitiveType.Int32), 4), "l0"); Assert.AreEqual("LONG * l0", sw.ToString()); }
public void Tyreffmt_ptr_function() { var sw = new StringWriter(); var trf = new TypeReferenceFormatter(new TextFormatter(sw)); trf.WriteDeclaration( new Pointer( FunctionType.Action(new [] { Arg("arg0", 0) }), 4), "pfn"); Assert.AreEqual("void (* pfn)(word32 arg0)", sw.ToString()); }
public void WriteFormalArgument(Identifier arg, bool writeStorage, TypeReferenceFormatter t) { if (writeStorage) { WriteFormalArgumentType(arg, writeStorage); writer.Write(" "); writer.Write(arg.Name); } else { if (arg.Storage is OutArgumentStorage) { t.WriteDeclaration(new ReferenceTo(arg.DataType), arg.Name); } else { t.WriteDeclaration(arg.DataType, arg.Name); } } }
public Formatter VisitStructure(StructureType str) { string n = name; if (mode == Mode.Writing) { object v; if (visited.TryGetValue(str, out v) && (v == Defined)) { writer.WriteKeyword("struct"); writer.Write(" "); writer.Write(str.Name); } else { visited[str] = Declared; ScanFields(str); writer.WriteKeyword("struct"); writer.Write(" "); writer.WriteHyperlink(str.Name, str); OpenBrace(str.Size > 0 ? string.Format("size: {0} {0:X}", str.Size) : null); if (str.Fields != null) { foreach (StructureField f in str.Fields) { BeginLine(); var trf = new TypeReferenceFormatter(writer); trf.WriteDeclaration(f.DataType, f.Name); EndLine(";", string.Format("{0:X}", f.Offset)); } } CloseBrace(); visited[str] = Defined; } name = n; WriteName(true); } else { if (!visited.ContainsKey(str)) { visited[str] = Declared; writer.Write("struct "); writer.WriteHyperlink(str.Name, str); writer.Write(";"); writer.WriteLine(); } } return(writer); }
public void VisitDeclaration(Declaration decl) { InnerFormatter.Indent(); Debug.Assert(decl.Identifier.DataType != null, "The DataType property can't ever be null"); var tf = new TypeReferenceFormatter(InnerFormatter); tf.WriteDeclaration(decl.Identifier.DataType ?? new UnknownType(), decl.Identifier.Name); if (decl.Expression != null) { InnerFormatter.Write(" = "); decl.Expression.Accept(this); } InnerFormatter.Terminate(); }
public void VisitDeclaration(Declaration decl) { writer.Indent(); Debug.Assert(decl.Identifier.DataType != null, "The DataType property can't ever be null"); #if OLD TypeFormatter tf = new TypeFormatter(writer, true); tf.Write(decl.Identifier.DataType, decl.Identifier.Name); #else TypeReferenceFormatter tf = new TypeReferenceFormatter(writer); tf.WriteDeclaration(decl.Identifier.DataType, decl.Identifier.Name); #endif if (decl.Expression != null) { writer.Write(" = "); decl.Expression.Accept(this); } writer.Terminate(); }
public void VisitDeclaration(AbsynDeclaration decl) { writer.Indent(); if (decl.Identifier.DataType != null) { TypeReferenceFormatter tf = new TypeReferenceFormatter(writer); tf.WriteDeclaration(decl.Identifier.DataType, decl.Identifier.Name); } else { writer.Write("?unknown?"); writer.Write(" "); decl.Identifier.Accept(this); } if (decl.Expression != null) { writer.Write(" = "); decl.Expression.Accept(this); } writer.Terminate(";"); }
private void WriteClassMembers(ClassType ct, ClassProtection protection, string sectionName) { var methods = ct.Methods.Where(m => m.Protection == protection) .OrderBy(m => m.Offset).ThenBy(m => m.Name) .ToList(); var fields = ct.Fields.Where(f => f.Protection == protection) .OrderBy(m => m.Offset) .ToList(); if (methods.Count == 0 && fields.Count == 0) { return; } writer.Indentation -= writer.TabSize; BeginLine(); writer.WriteKeyword(sectionName); writer.WriteLine(":"); writer.Indentation += writer.TabSize; foreach (var m in methods) { //$TODO: finish this. BeginLine(); writer.Write(m.Name); writer.Write("()"); EndLine(";"); } if (methods.Count > 0 && fields.Count > 0) { // separate methods from fields. writer.WriteLine(); } foreach (var f in fields) { BeginLine(); var trf = new TypeReferenceFormatter(writer); trf.WriteDeclaration(f.DataType, f.Name); EndLine(";", string.Format("{0:X}", f.Offset)); } }
public void VisitDeclaration(AbsynDeclaration decl) { writer.Indent(); if (decl.Identifier.DataType != null) { TypeReferenceFormatter tf = new TypeReferenceFormatter(writer); tf.WriteDeclaration(decl.Identifier.DataType, decl.Identifier.Name); } else { writer.Write("?unknown?"); writer.Write(" "); decl.Identifier.Accept(this); } if (decl.Expression != null) { writer.Write(" = "); decl.Expression.Accept(this); } writer.Terminate(";"); }
public void VisitDeclaration(Declaration decl) { writer.Indent(); Debug.Assert(decl.Identifier.DataType != null, "The DataType property can't ever be null"); #if OLD TypeFormatter tf = new TypeFormatter(writer, true); tf.Write(decl.Identifier.DataType, decl.Identifier.Name); #else TypeReferenceFormatter tf = new TypeReferenceFormatter(writer); tf.WriteDeclaration(decl.Identifier.DataType, decl.Identifier.Name); #endif if (decl.Expression != null) { writer.Write(" = "); decl.Expression.Accept(this); } writer.Terminate(); }
public void Write(TextWriter writer) { TextFormatter f = new TextFormatter(writer); foreach (var de in Signatures.OrderBy(d => d.Key, StringComparer.InvariantCulture)) { string name = de.Key; de.Value.Emit(de.Key, FunctionType.EmitFlags.ArgumentKind, f); writer.WriteLine(); } var tf = new TypeReferenceFormatter(f); foreach (var de in Globals.OrderBy(d => d.Key, StringComparer.InvariantCulture)) { tf.WriteDeclaration(de.Value, de.Key); } }