Exemplo n.º 1
0
 void DisplaySegments(ulong address)
 {
     try
     {
         if (Target.OperatingSystem == OSPlatform.Linux)
         {
             Stream stream  = MemoryService.CreateMemoryStream();
             var    elfFile = new ELFFile(new StreamAddressSpace(stream), address, true);
             if (elfFile.IsValid())
             {
                 foreach (ELFProgramHeader programHeader in elfFile.Segments.Select((segment) => segment.Header))
                 {
                     uint   flags       = MemoryService.PointerSize == 8 ? programHeader.Flags : programHeader.Flags32;
                     ulong  loadAddress = programHeader.VirtualAddress;
                     ulong  loadSize    = programHeader.VirtualSize;
                     ulong  fileOffset  = programHeader.FileOffset;
                     string type        = programHeader.Type.ToString();
                     WriteLine($"        Segment: {loadAddress:X16} {loadSize:X16} {fileOffset:X16} {flags:x2} {type}");
                 }
             }
         }
         else if (Target.OperatingSystem == OSPlatform.OSX)
         {
             Stream    stream    = MemoryService.CreateMemoryStream();
             MachOFile machOFile = new(new StreamAddressSpace(stream), address, true);
             if (machOFile.IsValid())
             {
                 WriteLine("    LoadAddress:     {0:X16}", machOFile.LoadAddress);
                 WriteLine("    LoadBias:        {0:X16}", machOFile.PreferredVMBaseAddress);
                 for (int i = 0; i < machOFile.Segments.Length; i++)
                 {
                     MachSegment segment     = machOFile.Segments[i];
                     ulong       loadAddress = segment.LoadCommand.VMAddress;
                     ulong       loadSize    = segment.LoadCommand.VMSize;
                     ulong       fileOffset  = segment.LoadCommand.FileOffset;
                     uint        prot        = segment.LoadCommand.InitProt;
                     string      name        = segment.LoadCommand.SegName.ToString();
                     WriteLine($"        Segment {i}: {loadAddress:X16} {loadSize:X16} {fileOffset:X16} {prot:x2} {name}");
                 }
             }
         }
     }
     catch (Exception ex) when(ex is InvalidVirtualAddressException || ex is BadInputFormatException)
     {
         Trace.TraceError($"Exception displaying module segments: {ex}");
     }
 }
Exemplo n.º 2
0
 void DisplaySegments(IModule module)
 {
     try
     {
         ELFFile elfFile = module.Services.GetService <ELFFile>();
         if (elfFile is not null)
         {
             foreach (ELFProgramHeader programHeader in elfFile.Segments.Select((segment) => segment.Header))
             {
                 uint   flags       = MemoryService.PointerSize == 8 ? programHeader.Flags : programHeader.Flags32;
                 ulong  loadAddress = programHeader.VirtualAddress;
                 ulong  loadSize    = programHeader.VirtualSize;
                 ulong  fileOffset  = programHeader.FileOffset;
                 string type        = programHeader.Type.ToString();
                 WriteLine($"        Segment: {loadAddress:X16} {loadSize:X16} {fileOffset:X16} {flags:x2} {type}");
             }
         }
         else
         {
             MachOFile machOFile = module.Services.GetService <MachOFile>();
             if (machOFile is not null)
             {
                 WriteLine("    LoadAddress:     {0:X16}", machOFile.LoadAddress);
                 WriteLine("    LoadBias:        {0:X16}", machOFile.PreferredVMBaseAddress);
                 for (int i = 0; i < machOFile.Segments.Length; i++)
                 {
                     MachSegment segment     = machOFile.Segments[i];
                     ulong       loadAddress = segment.LoadCommand.VMAddress;
                     ulong       loadSize    = segment.LoadCommand.VMSize;
                     ulong       fileOffset  = segment.LoadCommand.FileOffset;
                     uint        prot        = segment.LoadCommand.InitProt;
                     string      name        = segment.LoadCommand.SegName.ToString();
                     WriteLine($"        Segment {i}: {loadAddress:X16} {loadSize:X16} {fileOffset:X16} {prot:x2} {name}");
                 }
             }
         }
     }
     catch (Exception ex) when(ex is InvalidVirtualAddressException || ex is BadInputFormatException)
     {
         Trace.TraceError($"Exception displaying module segments: {ex}");
     }
 }