public void Dump(Program program, TextWriter stm) { var map = program.SegmentMap; ImageSegment segment = null; foreach (ImageMapItem i in program.ImageMap.Items.Values) { if (!map.IsValidAddress(i.Address)) { continue; } ImageSegment seg; if (!map.TryFindSegment(i.Address, out seg)) { continue; } if (seg != segment) { segment = seg; stm.WriteLine(";;; Segment {0} ({1})", seg.Name, seg.Address); } // Address addrLast = i.Address + i.Size; ImageMapBlock block = i as ImageMapBlock; if (block != null) { stm.WriteLine(); if (program.Procedures.ContainsKey(block.Address)) { stm.WriteLine(block.Address.GenerateName("fn", "()")); } else { stm.WriteLine(block.Address.GenerateName("l", ":")); } DumpAssembler(program.SegmentMap, block.Address, block.Address + block.Size, stm); continue; } ImageMapVectorTable table = i as ImageMapVectorTable; if (table != null) { stm.WriteLine("Code vector at {0} ({1} bytes)", table.Address, table.Size); foreach (Address addr in table.Addresses) { stm.WriteLine("\t{0}", addr != null ? addr.ToString() : "-- null --"); } DumpData(program.SegmentMap, i.Address, i.Size, stm); } else { var segLast = segment.Address + segment.Size; var size = segLast - i.Address; size = Math.Min(i.Size, size); DumpData(program.SegmentMap, i.Address, size, stm); } } }
private void DumpItem(ImageSegment segment, ImageMapItem i, Formatter formatter) { ImageMapBlock block = i as ImageMapBlock; if (block != null) { formatter.WriteLine(); Procedure proc; if (program.Procedures.TryGetValue(block.Address, out proc)) { formatter.WriteComment(string.Format( ";; {0}: {1}", proc.Name, block.Address)); formatter.WriteLine(); formatter.Write(proc.Name); formatter.Write(" "); formatter.Write("proc"); formatter.WriteLine(); } else { formatter.Write(block.Block.Name); formatter.Write(":"); formatter.WriteLine(); } DumpAssembler(program.SegmentMap, block.Address, block.Address + block.Size, formatter); return; } ImageMapVectorTable table = i as ImageMapVectorTable; if (table != null) { formatter.WriteLine(";; Code vector at {0} ({1} bytes)", table.Address, table.Size); foreach (Address addr in table.Addresses) { formatter.WriteLine("\t{0}", addr != null ? addr.ToString() : "-- null --"); } DumpData(program.SegmentMap, i.Address, i.Size, formatter); } else { var segLast = segment.Address + segment.Size; var size = segLast - i.Address; size = Math.Min(i.Size, size); if (i.DataType == null || i.DataType is UnknownType || i.DataType is CodeType) { DumpData(program.SegmentMap, i.Address, size, formatter); } else { DumpTypedData(program.SegmentMap, i, formatter); } } }
public VectorWorkItem(IScanner scanner, Program program, ImageMapVectorTable table, Procedure proc) : base() { this.scanner = scanner; this.program = program; this.Table = table; this.proc = proc; this.vectorUses = new Dictionary<Address, VectorUse>(); }
public void Dump(Program program, ImageMap map, TextWriter stm) { if (map == null) { DumpAssembler(program.Image, program.Image.BaseAddress, program.Image.BaseAddress + (uint)program.Image.Length, stm); } else { foreach (ImageMapItem i in map.Items.Values) { if (!program.Image.IsValidAddress(i.Address)) { continue; } // Address addrLast = i.Address + i.Size; ImageMapBlock block = i as ImageMapBlock; if (block != null) { stm.WriteLine(); if (program.Procedures.ContainsKey(block.Address)) { stm.WriteLine(block.Address.GenerateName("fn", "()")); } else { stm.WriteLine(block.Address.GenerateName("l", ":")); } DumpAssembler(program.Image, block.Address, block.Address + block.Size, stm); continue; } ImageMapVectorTable table = i as ImageMapVectorTable; if (table != null) { stm.WriteLine("{0} table at {1} ({2} bytes)", table.IsCallTable?"Call":"Jump", table.Address, table.Size); foreach (Address addr in table.Addresses) { stm.WriteLine("\t{0}", addr != null ? addr.ToString() : "-- null --"); } DumpData(program.Image, i.Address, i.Size, stm); } else { DumpData(program.Image, i.Address, i.Size, stm); } } } }
public void Dump(Program program, Formatter formatter) { var map = program.SegmentMap; ImageSegment segment = null; foreach (ImageMapItem i in program.ImageMap.Items.Values) { if (!map.IsValidAddress(i.Address)) { continue; } ImageSegment seg; if (!map.TryFindSegment(i.Address, out seg)) { continue; } if (seg != segment) { segment = seg; formatter.WriteLine(";;; Segment {0} ({1})", seg.Name, seg.Address); } ImageMapBlock block = i as ImageMapBlock; if (block != null) { formatter.WriteLine(); Procedure proc; if (program.Procedures.TryGetValue(block.Address, out proc)) { formatter.WriteComment(string.Format( ";; {0}: {1}", proc.Name, block.Address)); formatter.WriteLine(); formatter.Write(proc.Name); formatter.Write(" "); formatter.Write("proc"); formatter.WriteLine(); } else { formatter.Write(block.Block.Name); formatter.Write(":"); formatter.WriteLine(); } DumpAssembler(program.SegmentMap, block.Address, block.Address + block.Size, formatter); continue; } ImageMapVectorTable table = i as ImageMapVectorTable; if (table != null) { formatter.WriteLine(";; Code vector at {0} ({1} bytes)", table.Address, table.Size); foreach (Address addr in table.Addresses) { formatter.WriteLine("\t{0}", addr != null ? addr.ToString() : "-- null --"); } DumpData(program.SegmentMap, i.Address, i.Size, formatter); } else { var segLast = segment.Address + segment.Size; var size = segLast - i.Address; size = Math.Min(i.Size, size); if (i.DataType == null || i.DataType is UnknownType || i.DataType is CodeType) { DumpData(program.SegmentMap, i.Address, size, formatter); } else { DumpTypedData(program.SegmentMap, i, formatter); } } } }
public UserIndirectJump GetResults() { var vb = new VectorBuilder(dlg.Services, dlg.Program, new DirectedGraphImpl<object>()); var stride = 4; //$TODO: get from dialog var entries = vb.BuildTable(dlg.VectorAddress, stride * (int)dlg.EntryCount.Value, null, stride, null); var table = new ImageMapVectorTable(dlg.VectorAddress, entries.ToArray(), 0); return new UserIndirectJump { Address = dlg.Instruction.Address, Table = table, IndexRegister = dlg.Program.Architecture.GetRegister(dlg.IndexRegister.SelectedIndex.ToString()) }; }
public void EnqueueVectorTable(Address addrFrom, Address addrTable, PrimitiveType elemSize, ushort segBase, bool calltable, Procedure proc, ProcessorState state) { ImageMapVectorTable table; if (vectors.TryGetValue(addrTable, out table)) return; table = new ImageMapVectorTable(addrTable, calltable); var wi = new VectorWorkItem(this, program, table, proc); wi.State = state.Clone(); wi.Stride = elemSize; wi.SegBase = segBase; wi.Table = table; wi.AddrFrom = addrFrom; imageMap.AddItem(addrTable, table); vectors[addrTable] = table; queue.Enqueue(PriorityVector, wi); }
public void SudSaveProject() { Given_Architecture(); Given_TestOS_Platform(); var eax = new RegisterStorage("eax", 0, 0, PrimitiveType.Word32); var ecx = new RegisterStorage("ecx", 1, 0, PrimitiveType.Word32); var jumpTable = new ImageMapVectorTable( Address.SegPtr(0x1000, 0x400), new Address[] { Address.SegPtr(0x1000, 0x500), Address.SegPtr(0x1000, 0x513), Address.SegPtr(0x1000, 0x5BA), }, 0); Project project = new Project { Programs = { new Program { Architecture = arch, Platform = platform, SegmentMap = new SegmentMap(Address.SegPtr(0x1000, 0)), //, new byte[100]), DisassemblyFilename = "foo.asm", IntermediateFilename = "foo.cod", User = new UserData { Procedures = { { Address.SegPtr(0x1000, 0x10), new Procedure_v1 { Name = "foo", Signature = new SerializedSignature { ReturnValue = new Argument_v1 { Kind = new Register_v1("eax") }, Arguments = new Argument_v1[] { new Argument_v1 { Kind = new StackVariable_v1(), Type = new PrimitiveType_v1(Domain.SignedInt, 4) }, new Argument_v1 { Kind = new StackVariable_v1(), Type = new PrimitiveType_v1(Domain.SignedInt, 4) } } } } } }, Globals = { { Address.SegPtr(0x2000, 0), new GlobalDataItem_v2 { Address = Address.SegPtr(0x2000, 0).ToString(), DataType = new StringType_v2 { Termination=StringType_v2.ZeroTermination, CharType = new PrimitiveType_v1 { Domain = Domain.Character, ByteSize = 1 } } } } }, Calls = { { Address.SegPtr(0x1000, 0x0320), new UserCallData { Address = Address.SegPtr(0x1000, 0x0320), NoReturn = true, } } }, RegisterValues = { { Address.Ptr32(0x012310), new List<UserRegisterValue> { new UserRegisterValue { Register = eax, Value=Constant.Word32(0x01231) }, new UserRegisterValue { Register = ecx, Value=Constant.Word32(0x42424711) }, } } }, IndirectJumps = { { Address.SegPtr(0x1000, 0x380), new UserIndirectJump { Address = jumpTable.Address, Table = jumpTable, IndexRegister = new RegisterStorage("R1", 1, 0, PrimitiveType.Word32) } } }, JumpTables = { { jumpTable.Address, jumpTable } } } } } }; mr.ReplayAll(); using (FileUnitTester fut = new FileUnitTester("Core/SudSaveProject.txt")) { FilteringXmlWriter writer = new FilteringXmlWriter(fut.TextWriter); writer.Formatting = System.Xml.Formatting.Indented; XmlSerializer ser = SerializedLibrary.CreateSerializer_v4(typeof(Project_v4)); Project_v4 ud = new ProjectSaver(sc).Save("/var/foo/foo.proj", project); ser.Serialize(writer, ud); fut.AssertFilesEqual(); } }