@@ -2,7 +2,7 @@ use prettytable::{row, Table};
22
33use crate :: constants:: * ;
44use crate :: header:: { MachHeader , MachHeader32 , MachHeader64 } ;
5- use crate :: load_commands:: { DylibCommand , EncryptionInfoCommand , LcStr , LoadCommand , RoutinesCommand , Section , SegmentCommand , SegmentCommand32 , SegmentCommand64 } ;
5+ use crate :: load_commands:: { DylibCommand , EncryptionInfoCommand , LcStr , LoadCommand , RoutinesCommand , Section , Section32 , Section64 , SegmentCommand , SegmentCommand32 , SegmentCommand64 } ;
66
77pub fn print_header ( header : & MachHeader ) {
88 let mut table = Table :: new ( ) ;
@@ -165,6 +165,7 @@ pub fn print_load_commands(load_commands: &(Vec<LoadCommand>, Vec<Vec<Section>>,
165165 print_segment_command64 ( command, & mut table) ;
166166 }
167167 }
168+ print_sections_for_segment ( & load_commands. 1 [ index] , & mut table) ;
168169 }
169170 LoadCommand :: DylibCommand ( command) => unsafe {
170171 print_dylib_command ( command, & load_commands. 2 [ index] , & mut table) ;
@@ -443,6 +444,45 @@ fn print_segment_flags(flags_combined: u32, table: &mut Table) {
443444 }
444445}
445446
447+ fn print_sections_for_segment ( sections : & Vec < Section > , table : & mut Table ) {
448+ for ( index, section) in sections. iter ( ) . enumerate ( ) {
449+ table. add_row ( row ! [ Fgbc ->format!( "Section #{}" , index) , c->"-" , c->"-" ] ) ;
450+ match section {
451+ Section :: SEC32 ( section32) => print_section32 ( section32, table) ,
452+ Section :: SEC64 ( section64) => print_section64 ( section64, table) ,
453+ }
454+ }
455+ }
456+
457+ fn print_section32 ( section : & Section32 , table : & mut Table ) {
458+ print_segname_bytes_array ( & section. sectname , table) ;
459+ print_segname_bytes_array ( & section. segname , table) ;
460+ table. add_row ( row ! [ Fcc ->"addr" , Fyc ->format!( "0x{:x}" , section. addr) , c->"-" ] ) ;
461+ table. add_row ( row ! [ Fcc ->"size" , Fyc ->format!( "0x{:x}" , section. size) , c->"-" ] ) ;
462+ table. add_row ( row ! [ Fcc ->"offset" , Fyc ->format!( "0x{:x}" , section. offset) , c->"-" ] ) ;
463+ table. add_row ( row ! [ Fcc ->"align" , Fyc ->format!( "0x{:x}" , section. align) , c->"-" ] ) ;
464+ table. add_row ( row ! [ Fcc ->"reloff" , Fyc ->format!( "0x{:x}" , section. reloff) , c->"-" ] ) ;
465+ table. add_row ( row ! [ Fcc ->"nreloc" , Fyc ->format!( "0x{:x}" , section. nreloc) , c->"-" ] ) ;
466+ table. add_row ( row ! [ Fcc ->"flags" , Fyc ->format!( "0x{:x}" , section. flags) , c->"-" ] ) ;
467+ table. add_row ( row ! [ Fcc ->"reserved1" , Fyc ->format!( "0x{:x}" , section. reserved1) , c->"-" ] ) ;
468+ table. add_row ( row ! [ Fcc ->"reserved2" , Fyc ->format!( "0x{:x}" , section. reserved2) , c->"-" ] ) ;
469+ }
470+
471+ fn print_section64 ( section : & Section64 , table : & mut Table ) {
472+ print_segname_bytes_array ( & section. sectname , table) ;
473+ print_segname_bytes_array ( & section. segname , table) ;
474+ table. add_row ( row ! [ Fcc ->"addr" , Fyc ->format!( "0x{:x}" , section. addr) , c->"-" ] ) ;
475+ table. add_row ( row ! [ Fcc ->"size" , Fyc ->format!( "0x{:x}" , section. size) , c->"-" ] ) ;
476+ table. add_row ( row ! [ Fcc ->"offset" , Fyc ->format!( "0x{:x}" , section. offset) , c->"-" ] ) ;
477+ table. add_row ( row ! [ Fcc ->"align" , Fyc ->format!( "0x{:x}" , section. align) , c->"-" ] ) ;
478+ table. add_row ( row ! [ Fcc ->"reloff" , Fyc ->format!( "0x{:x}" , section. reloff) , c->"-" ] ) ;
479+ table. add_row ( row ! [ Fcc ->"nreloc" , Fyc ->format!( "0x{:x}" , section. nreloc) , c->"-" ] ) ;
480+ table. add_row ( row ! [ Fcc ->"flags" , Fyc ->format!( "0x{:x}" , section. flags) , c->"-" ] ) ;
481+ table. add_row ( row ! [ Fcc ->"reserved1" , Fyc ->format!( "0x{:x}" , section. reserved1) , c->"-" ] ) ;
482+ table. add_row ( row ! [ Fcc ->"reserved2" , Fyc ->format!( "0x{:x}" , section. reserved2) , c->"-" ] ) ;
483+ table. add_row ( row ! [ Fcc ->"reserved3" , Fyc ->format!( "0x{:x}" , section. reserved3) , c->"-" ] ) ;
484+ }
485+
446486unsafe fn print_dylib_command ( command : & DylibCommand , lc_str : & LcStr , mut table : & mut Table ) {
447487 print_lc_cmd_and_cmdsize ( command. cmd , command. cmdsize , & mut table) ;
448488 table. add_row ( row ! [ Frbc ->"struct dylib = {" , c->"-" , c->"-" ] ) ;
0 commit comments