private void WriteCode(Formatter tsf) { var fmt = new AbsynCodeFormatter(tsf); fmt.InnerFormatter.UseTabs = false; fmt.Write(proc); }
private void CreateNestedTextModel() { this.nestedTextModel = new NestedTextModel(); var mixedCodeDataModel = combinedCodeView.MixedCodeDataView.Model as MixedCodeDataModel; if (mixedCodeDataModel == null) { return; } var dataItemNodes = mixedCodeDataModel.GetDataItemNodes(); this.nodeByAddress = new SortedList <Address, MixedCodeDataModel.DataItemNode>(); foreach (var dataItemNode in dataItemNodes) { var curAddr = dataItemNode.StartAddress; bool nodeCreated = false; ImageMapItem item; Procedure proc = dataItemNode.Proc; if (ShowItem(dataItemNode)) { if (proc != null) { var model = new ProcedureCodeModel(proc); //$TODO: make spacing between globals / procedures user adjustable model.NumEmptyLinesAfter = 2; nestedTextModel.Nodes.Add(model); nodeCreated = true; } else if (program.ImageMap.TryFindItem(curAddr, out item) && item.DataType != null && !(item.DataType is UnknownType)) { var dt = item.DataType; var name = item.Name ?? "<unnamed>"; var tsf = new TextSpanFormatter(); var fmt = new AbsynCodeFormatter(tsf); fmt.InnerFormatter.UseTabs = false; var gdw = new GlobalDataWriter(program, services); gdw.WriteGlobalVariable(curAddr, dt, name, tsf); //$TODO: make spacing between globals / procedures user adjustable tsf.WriteLine(""); nestedTextModel.Nodes.Add(tsf.GetModel()); nodeCreated = true; } } if (nodeCreated) { dataItemNode.ModelNode = nestedTextModel.Nodes.Last(); this.nodeByAddress[curAddr] = dataItemNode; } } combinedCodeView.CodeView.Model = nestedTextModel; }
public void Acf_NegativeSigned_SmallInt() { var c = Constant.Word32(-4); var sw = new StringWriter(); var acf = new AbsynCodeFormatter(new TextFormatter(sw)); c.Accept(acf); Assert.AreEqual("~0x03", sw.ToString()); }
public void Acf_HexEntropy() { var c = Constant.Int32(0x7FF); var sw = new StringWriter(); var acf = new AbsynCodeFormatter(new TextFormatter(sw)); c.Accept(acf); Assert.AreEqual("0x07FF", sw.ToString()); }
public void Acf_SmallInteger() { var c = Constant.Int32(10); var sw = new StringWriter(); var acf = new AbsynCodeFormatter(new TextFormatter(sw)); c.Accept(acf); Assert.AreEqual("0x0A", sw.ToString()); }
public void Acf_NegativeSigned() { var c = Constant.Int32(-256); var sw = new StringWriter(); var acf = new AbsynCodeFormatter(new TextFormatter(sw)); c.Accept(acf); Assert.AreEqual("-0x0100", sw.ToString()); }
public void Acf_EvenPower() { var c = Constant.UInt32(unchecked((uint)-256)); var sw = new StringWriter(); var acf = new AbsynCodeFormatter(new TextFormatter(sw)); c.Accept(acf); Assert.AreEqual("~0xFF", sw.ToString()); }
public void Acf_Reg00001() { var c = Constant.Word32(0x00001000); var sw = new StringWriter(); var acf = new AbsynCodeFormatter(new TextFormatter(sw)); c.Accept(acf); Assert.AreEqual("0x1000", sw.ToString()); }
public void Acf_EvenPower() { var c = Constant.UInt32(unchecked ((uint)-256)); var sw = new StringWriter(); var acf = new AbsynCodeFormatter(new TextFormatter(sw)); c.Accept(acf); Assert.AreEqual("~0xFF", sw.ToString()); }
private void SetTextView(Procedure proc) { var tsf = new TextSpanFormatter(); var fmt = new AbsynCodeFormatter(tsf); fmt.InnerFormatter.UseTabs = false; fmt.Write(proc); this.TextView.Model = tsf.GetModel(); }
public virtual void Write(StringWriter sb) { var f = new AbsynCodeFormatter(new TextFormatter(sb)); foreach (var stm in Statements) { stm.Accept(f); } }
public void Acf_DecEntropy() { var c = Constant.Int32(1000); var sw = new StringWriter(); var acf = new AbsynCodeFormatter(new TextFormatter(sw)); c.Accept(acf); Assert.AreEqual("1000", sw.ToString()); }
private TextViewModel GenerateTextModel(Block b) { var tsf = new TextSpanFormatter(); var fmt = new AbsynCodeFormatter(tsf); var procf = new ProcedureFormatter(b.Procedure, fmt); fmt.InnerFormatter.UseTabs = false; procf.WriteBlock(b, fmt); return(tsf.GetModel()); }
private void GenCode(Procedure proc, StringWriter sb) { sb.WriteLine("{0}()", proc.Name); sb.WriteLine("{"); var cf = new AbsynCodeFormatter(new TextFormatter(sb)); cf.WriteStatementList(proc.Body); sb.WriteLine("}"); }
private void GenCode(Procedure proc, StringWriter sw) { sw.WriteLine("{0}()", proc.Name); sw.WriteLine("{"); var cf = new AbsynCodeFormatter(new TextFormatter(sw) { UseTabs = false }); cf.WriteStatementList(proc.Body); sw.WriteLine("}"); }
public static string RenderProcedureHll(Program program, string sProcAddress) { if (!program.Architecture.TryParseAddress(sProcAddress, out var addr)) { return(""); } if (!program.Procedures.TryGetValue(addr, out var proc)) { return(""); } var sb = new StringBuilder(); var writer = new ProcedureRenderer(sb); var ar = new AbsynCodeFormatter(writer); ar.Write(proc); return(sb.ToString()); }
private TextViewModel GenerateSimulatedHllCode() { var code = new List <AbsynStatement>(); var ase = new Structure.AbsynStatementEmitter(code); var a_id = new Identifier("a", PrimitiveType.Int32, null); var sum_id = new Identifier("sum", PrimitiveType.Int32, null); ase.EmitAssign(a_id, Constant.Int32(10)); ase.EmitAssign(sum_id, Constant.Int32(0)); var tsf = new TextSpanFormatter(); var fmt = new AbsynCodeFormatter(tsf); fmt.InnerFormatter.UseTabs = false; foreach (var stm in code) { stm.Accept(fmt); } return(tsf.GetModel()); }
public static string RenderProcedureIR(Program program, string sProcAddress) { if (!program.Architecture.TryParseAddress(sProcAddress, out var addr)) { return(""); } if (!program.Procedures.TryGetValue(addr, out var proc)) { return(""); } var sb = new StringBuilder(); var writer = new ProcedureRenderer(sb); var ar = new AbsynCodeFormatter(writer); new ProcedureFormatter(proc, new BlockDecorator { ShowEdges = false }, ar).WriteProcedureBlocks(); return(sb.ToString()); }
public void WriteDecompiledProcedures(Program program, TextWriter w) { WriteHeaderComment(Path.GetFileName(program.OutputFilename), program, w); w.WriteLine("#include \"{0}\"", Path.GetFileName(program.TypesFilename)); w.WriteLine(); var fmt = new AbsynCodeFormatter(new TextFormatter(w)); foreach (Procedure proc in program.Procedures.Values) { try { fmt.Write(proc); w.WriteLine(); } catch (Exception ex) { w.WriteLine(); w.WriteLine("// Exception {0} when writing procedure.", ex.Message); } } }
public void WriteDecompiledObjects(Program program, string filename, IEnumerable <IAddressable> objects, TextWriter w) { WriteHeaderComment(filename, program, w); //$REFACTOR: common code -- hardwired ".h" var headerfile = Path.ChangeExtension(Path.GetFileName(program.Filename), ".h"); w.WriteLine("#include \"{0}\"", headerfile); w.WriteLine(); var fmt = new AbsynCodeFormatter(new TextFormatter(w)); var gdw = new GlobalDataWriter(program, fmt.InnerFormatter, false, true, this.services); IAddressable?prev = null; foreach (var o in objects) { if (o is Procedure proc) { try { if (prev is GlobalVariable) { w.WriteLine(); } WriteProcedureHeader(program, proc, w); fmt.Write(proc); w.WriteLine(); } catch (Exception ex) { w.WriteLine(); w.WriteLine("// Exception {0} when writing procedure.", ex.Message); } } else if (o is GlobalVariable global) { gdw.WriteGlobalVariable(global.Address, global.DataType, global.Name); } } }
public void WriteDecompiledProcedures(Program program, string filename, IEnumerable <Procedure> procs, TextWriter w) { var headerfile = Path.ChangeExtension(filename, ".h"); WriteHeaderComment(filename, program, w); w.WriteLine("#include \"{0}\"", headerfile); w.WriteLine(); var fmt = new AbsynCodeFormatter(new TextFormatter(w)); foreach (var proc in procs) { w.WriteLine("// {0}: {1}", proc.EntryAddress, proc); try { fmt.Write(proc); w.WriteLine(); } catch (Exception ex) { w.WriteLine(); w.WriteLine("// Exception {0} when writing procedure.", ex.Message); } } }
private TextViewModel GenerateTextModel(Block b) { var tsf = new TextSpanFormatter(); var fmt = new AbsynCodeFormatter(tsf); var procf = new ProcedureFormatter(b.Procedure, fmt); fmt.InnerFormatter.UseTabs = false; procf.WriteBlock(b, fmt); return tsf.GetModel(); }
private TextViewModel GenerateSimulatedHllCode() { var code = new List<AbsynStatement>(); var ase = new Structure.AbsynStatementEmitter(code); var m = new ExpressionEmitter(); var a_id = new Identifier("a", PrimitiveType.Int32, null); var sum_id = new Identifier("sum", PrimitiveType.Int32, null); ase.EmitAssign(a_id, Constant.Int32(10)); ase.EmitAssign(sum_id, Constant.Int32(0)); var tsf = new TextSpanFormatter(); var fmt = new AbsynCodeFormatter(tsf); fmt.InnerFormatter.UseTabs = false; foreach (var stm in code) { stm.Accept(fmt); } return tsf.GetModel(); }
public virtual void Write(StringWriter sb) { var f = new AbsynCodeFormatter(new TextFormatter(sb)); foreach (var stm in Statements) stm.Accept(f); }
private void CreateNestedTextModel() { this.nestedTextModel = new NestedTextModel(); var mixedCodeDataModel = combinedCodeView.MixedCodeDataView.Model as MixedCodeDataModel; if (mixedCodeDataModel == null) return; var dataItemNodes = mixedCodeDataModel.GetDataItemNodes(); this.nodeByAddress = new SortedList<Address, MixedCodeDataModel.DataItemNode>(); foreach (var dataItemNode in dataItemNodes) { var curAddr = dataItemNode.StartAddress; bool nodeCreated = false; ImageMapItem item; Procedure proc = dataItemNode.Proc; if (ShowItem(dataItemNode)) { if (proc != null) { var tsf = new TextSpanFormatter(); var fmt = new AbsynCodeFormatter(tsf); fmt.InnerFormatter.UseTabs = false; fmt.Write(proc); //$TODO: make spacing between globals / procedures user adjustable tsf.WriteLine(""); tsf.WriteLine(""); nestedTextModel.Nodes.Add(tsf.GetModel()); nodeCreated = true; } else if (program.ImageMap.TryFindItem(curAddr, out item) && item.DataType != null && !(item.DataType is UnknownType)) { var dt = item.DataType; var name = item.Name ?? "<unnamed>"; var tsf = new TextSpanFormatter(); var fmt = new AbsynCodeFormatter(tsf); fmt.InnerFormatter.UseTabs = false; var gdw = new GlobalDataWriter(program, services); gdw.WriteGlobalVariable(curAddr, dt, name, tsf); //$TODO: make spacing between globals / procedures user adjustable tsf.WriteLine(""); nestedTextModel.Nodes.Add(tsf.GetModel()); nodeCreated = true; } } if (nodeCreated) { dataItemNode.ModelNode = nestedTextModel.Nodes.Last(); this.nodeByAddress[curAddr] = dataItemNode; } } combinedCodeView.CodeView.Model = nestedTextModel; }
/// <summary> /// Displace the procedure <paramref name="proc"/> in the code window. /// </summary> /// <param name="proc"></param> public void DisplayProcedure(Procedure proc) { if (codeView == null || proc == null) return; this.proc = proc; var tsf = new TextSpanFormatter(); var fmt = new AbsynCodeFormatter(tsf); fmt.InnerFormatter.UseTabs = false; fmt.Write(proc); this.TextView.Model = tsf.GetModel(); }