@@ -698,7 +698,7 @@ pub trait ReadStringExt: Read {
698
698
impl < R : Read + ?Sized > ReadStringExt for R { }
699
699
700
700
impl LoadCommand {
701
- pub fn parse < O : ByteOrder > ( buf : & mut Cursor < & [ u8 ] > ) -> Result < ( LoadCommand , usize ) > {
701
+ pub fn parse < O : ByteOrder , T : AsRef < [ u8 ] > > ( buf : & mut Cursor < T > ) -> Result < ( LoadCommand , usize ) > {
702
702
let begin = buf. position ( ) ;
703
703
let cmd = try!( buf. read_u32 :: < O > ( ) ) ;
704
704
let cmdsize = try!( buf. read_u32 :: < O > ( ) ) ;
@@ -717,7 +717,7 @@ impl LoadCommand {
717
717
let mut sections = Vec :: new ( ) ;
718
718
719
719
for _ in 0 ..nsects {
720
- sections. push ( Rc :: new ( try!( Section :: parse_section :: < Cursor < & [ u8 ] > , O > ( buf) ) ) ) ;
720
+ sections. push ( Rc :: new ( try!( Section :: parse_section :: < Cursor < T > , O > ( buf) ) ) ) ;
721
721
}
722
722
723
723
LoadCommand :: Segment {
@@ -745,7 +745,7 @@ impl LoadCommand {
745
745
let mut sections = Vec :: new ( ) ;
746
746
747
747
for _ in 0 ..nsects {
748
- sections. push ( Rc :: new ( try!( Section :: parse_section64 :: < Cursor < & [ u8 ] > , O > ( buf) ) ) ) ;
748
+ sections. push ( Rc :: new ( try!( Section :: parse_section64 :: < Cursor < T > , O > ( buf) ) ) ) ;
749
749
}
750
750
751
751
LoadCommand :: Segment64 {
@@ -760,19 +760,19 @@ impl LoadCommand {
760
760
sections : sections,
761
761
}
762
762
}
763
- LC_IDFVMLIB => LoadCommand :: IdFvmLib ( try!( Self :: read_fvmlib :: < O > ( buf) ) ) ,
764
- LC_LOADFVMLIB => LoadCommand :: LoadFvmLib ( try!( Self :: read_fvmlib :: < O > ( buf) ) ) ,
763
+ LC_IDFVMLIB => LoadCommand :: IdFvmLib ( try!( Self :: read_fvmlib :: < O , T > ( buf) ) ) ,
764
+ LC_LOADFVMLIB => LoadCommand :: LoadFvmLib ( try!( Self :: read_fvmlib :: < O , T > ( buf) ) ) ,
765
765
766
- LC_ID_DYLIB => LoadCommand :: IdDyLib ( try!( Self :: read_dylib :: < O > ( buf) ) ) ,
767
- LC_LOAD_DYLIB => LoadCommand :: LoadDyLib ( try!( Self :: read_dylib :: < O > ( buf) ) ) ,
768
- LC_LOAD_WEAK_DYLIB => LoadCommand :: LoadWeakDyLib ( try!( Self :: read_dylib :: < O > ( buf) ) ) ,
769
- LC_REEXPORT_DYLIB => LoadCommand :: ReexportDyLib ( try!( Self :: read_dylib :: < O > ( buf) ) ) ,
770
- LC_LOAD_UPWARD_DYLIB => LoadCommand :: LoadUpwardDylib ( try!( Self :: read_dylib :: < O > ( buf) ) ) ,
771
- LC_LAZY_LOAD_DYLIB => LoadCommand :: LazyLoadDylib ( try!( Self :: read_dylib :: < O > ( buf) ) ) ,
766
+ LC_ID_DYLIB => LoadCommand :: IdDyLib ( try!( Self :: read_dylib :: < O , T > ( buf) ) ) ,
767
+ LC_LOAD_DYLIB => LoadCommand :: LoadDyLib ( try!( Self :: read_dylib :: < O , T > ( buf) ) ) ,
768
+ LC_LOAD_WEAK_DYLIB => LoadCommand :: LoadWeakDyLib ( try!( Self :: read_dylib :: < O , T > ( buf) ) ) ,
769
+ LC_REEXPORT_DYLIB => LoadCommand :: ReexportDyLib ( try!( Self :: read_dylib :: < O , T > ( buf) ) ) ,
770
+ LC_LOAD_UPWARD_DYLIB => LoadCommand :: LoadUpwardDylib ( try!( Self :: read_dylib :: < O , T > ( buf) ) ) ,
771
+ LC_LAZY_LOAD_DYLIB => LoadCommand :: LazyLoadDylib ( try!( Self :: read_dylib :: < O , T > ( buf) ) ) ,
772
772
773
- LC_ID_DYLINKER => LoadCommand :: IdDyLinker ( try!( Self :: read_dylinker :: < O > ( buf) ) ) ,
774
- LC_LOAD_DYLINKER => LoadCommand :: LoadDyLinker ( try!( Self :: read_dylinker :: < O > ( buf) ) ) ,
775
- LC_DYLD_ENVIRONMENT => LoadCommand :: DyLdEnv ( try!( Self :: read_dylinker :: < O > ( buf) ) ) ,
773
+ LC_ID_DYLINKER => LoadCommand :: IdDyLinker ( try!( Self :: read_dylinker :: < O , T > ( buf) ) ) ,
774
+ LC_LOAD_DYLINKER => LoadCommand :: LoadDyLinker ( try!( Self :: read_dylinker :: < O , T > ( buf) ) ) ,
775
+ LC_DYLD_ENVIRONMENT => LoadCommand :: DyLdEnv ( try!( Self :: read_dylinker :: < O , T > ( buf) ) ) ,
776
776
777
777
LC_SYMTAB => {
778
778
LoadCommand :: SymTab {
@@ -811,21 +811,13 @@ impl LoadCommand {
811
811
812
812
LoadCommand :: Uuid ( try!( Uuid :: from_bytes ( & uuid[ ..] ) ) )
813
813
}
814
- LC_CODE_SIGNATURE => {
815
- LoadCommand :: CodeSignature ( try!( Self :: read_linkedit_data :: < O > ( buf) ) )
816
- }
817
- LC_SEGMENT_SPLIT_INFO => {
818
- LoadCommand :: SegmentSplitInfo ( try!( Self :: read_linkedit_data :: < O > ( buf) ) )
819
- }
820
- LC_FUNCTION_STARTS => {
821
- LoadCommand :: FunctionStarts ( try!( Self :: read_linkedit_data :: < O > ( buf) ) )
822
- }
823
- LC_DATA_IN_CODE => LoadCommand :: DataInCode ( try!( Self :: read_linkedit_data :: < O > ( buf) ) ) ,
824
- LC_DYLIB_CODE_SIGN_DRS => {
825
- LoadCommand :: DylibCodeSignDrs ( try!( Self :: read_linkedit_data :: < O > ( buf) ) )
826
- }
814
+ LC_CODE_SIGNATURE => LoadCommand :: CodeSignature ( try!( Self :: read_linkedit_data :: < O , T > ( buf) ) ) ,
815
+ LC_SEGMENT_SPLIT_INFO => LoadCommand :: SegmentSplitInfo ( try!( Self :: read_linkedit_data :: < O , T > ( buf) ) ) ,
816
+ LC_FUNCTION_STARTS => LoadCommand :: FunctionStarts ( try!( Self :: read_linkedit_data :: < O , T > ( buf) ) ) ,
817
+ LC_DATA_IN_CODE => LoadCommand :: DataInCode ( try!( Self :: read_linkedit_data :: < O , T > ( buf) ) ) ,
818
+ LC_DYLIB_CODE_SIGN_DRS => LoadCommand :: DylibCodeSignDrs ( try!( Self :: read_linkedit_data :: < O , T > ( buf) ) ) ,
827
819
LC_LINKER_OPTIMIZATION_HINT => {
828
- LoadCommand :: LinkerOptimizationHint ( try!( Self :: read_linkedit_data :: < O > ( buf) ) )
820
+ LoadCommand :: LinkerOptimizationHint ( try!( Self :: read_linkedit_data :: < O , T > ( buf) ) )
829
821
}
830
822
831
823
LC_VERSION_MIN_MACOSX |
@@ -858,9 +850,7 @@ impl LoadCommand {
858
850
stacksize : try!( buf. read_u64 :: < O > ( ) ) ,
859
851
}
860
852
}
861
- LC_SOURCE_VERSION => {
862
- LoadCommand :: SourceVersion ( SourceVersionTag ( try!( buf. read_u64 :: < O > ( ) ) ) )
863
- }
853
+ LC_SOURCE_VERSION => LoadCommand :: SourceVersion ( SourceVersionTag ( try!( buf. read_u64 :: < O > ( ) ) ) ) ,
864
854
_ => {
865
855
let mut payload = Vec :: new ( ) ;
866
856
@@ -891,37 +881,37 @@ impl LoadCommand {
891
881
Ok ( ( cmd, cmdsize as usize ) )
892
882
}
893
883
894
- fn read_lc_string < O : ByteOrder > ( buf : & mut Cursor < & [ u8 ] > ) -> Result < String > {
884
+ fn read_lc_string < O : ByteOrder , T : AsRef < [ u8 ] > > ( buf : & mut Cursor < T > ) -> Result < String > {
895
885
let mut s = Vec :: new ( ) ;
896
886
897
887
try!( buf. read_until ( 0 , & mut s) ) ;
898
888
899
889
unsafe { Ok ( String :: from ( try!( CStr :: from_ptr ( s. as_ptr ( ) as * const i8 ) . to_str ( ) ) ) ) }
900
890
}
901
891
902
- fn read_dylinker < O : ByteOrder > ( buf : & mut Cursor < & [ u8 ] > ) -> Result < LcString > {
892
+ fn read_dylinker < O : ByteOrder , T : AsRef < [ u8 ] > > ( buf : & mut Cursor < T > ) -> Result < LcString > {
903
893
let off = try!( buf. read_u32 :: < O > ( ) ) as usize ;
904
894
905
895
buf. consume ( off - 12 ) ;
906
896
907
- Ok ( LcString ( off, try!( Self :: read_lc_string :: < O > ( buf) ) ) )
897
+ Ok ( LcString ( off, try!( Self :: read_lc_string :: < O , T > ( buf) ) ) )
908
898
}
909
899
910
- fn read_fvmlib < O : ByteOrder > ( buf : & mut Cursor < & [ u8 ] > ) -> Result < FvmLib > {
900
+ fn read_fvmlib < O : ByteOrder , T : AsRef < [ u8 ] > > ( buf : & mut Cursor < T > ) -> Result < FvmLib > {
911
901
let off = try!( buf. read_u32 :: < O > ( ) ) as usize ;
912
902
let minor_version = try!( buf. read_u32 :: < O > ( ) ) ;
913
903
let header_addr = try!( buf. read_u32 :: < O > ( ) ) ;
914
904
915
905
buf. consume ( off - 20 ) ;
916
906
917
907
Ok ( FvmLib {
918
- name : LcString ( off, try!( Self :: read_lc_string :: < O > ( buf) ) ) ,
908
+ name : LcString ( off, try!( Self :: read_lc_string :: < O , T > ( buf) ) ) ,
919
909
minor_version : minor_version,
920
910
header_addr : header_addr,
921
911
} )
922
912
}
923
913
924
- fn read_dylib < O : ByteOrder > ( buf : & mut Cursor < & [ u8 ] > ) -> Result < DyLib > {
914
+ fn read_dylib < O : ByteOrder , T : AsRef < [ u8 ] > > ( buf : & mut Cursor < T > ) -> Result < DyLib > {
925
915
let off = try!( buf. read_u32 :: < O > ( ) ) as usize ;
926
916
let timestamp = try!( buf. read_u32 :: < O > ( ) ) ;
927
917
let current_version = try!( buf. read_u32 :: < O > ( ) ) ;
@@ -930,14 +920,14 @@ impl LoadCommand {
930
920
buf. consume ( off - 24 ) ;
931
921
932
922
Ok ( DyLib {
933
- name : LcString ( off, try!( Self :: read_lc_string :: < O > ( buf) ) ) ,
923
+ name : LcString ( off, try!( Self :: read_lc_string :: < O , T > ( buf) ) ) ,
934
924
timestamp : timestamp,
935
925
current_version : VersionTag ( current_version) ,
936
926
compatibility_version : VersionTag ( compatibility_version) ,
937
927
} )
938
928
}
939
929
940
- fn read_linkedit_data < O : ByteOrder > ( buf : & mut Cursor < & [ u8 ] > ) -> Result < LinkEditData > {
930
+ fn read_linkedit_data < O : ByteOrder , T : AsRef < [ u8 ] > > ( buf : & mut Cursor < T > ) -> Result < LinkEditData > {
941
931
Ok ( LinkEditData {
942
932
off : try!( buf. read_u32 :: < O > ( ) ) ,
943
933
size : try!( buf. read_u32 :: < O > ( ) ) ,
@@ -1184,9 +1174,9 @@ pub mod tests {
1184
1174
1185
1175
buf. extend_from_slice( & $buf[ ..] ) ;
1186
1176
1187
- let mut cur = Cursor :: new( buf. as_slice ( ) ) ;
1177
+ let mut cur = Cursor :: new( buf) ;
1188
1178
1189
- LoadCommand :: parse:: <LittleEndian >( & mut cur) . unwrap( )
1179
+ LoadCommand :: parse:: <LittleEndian , Vec < u8 > >( & mut cur) . unwrap( )
1190
1180
} )
1191
1181
}
1192
1182
@@ -1346,8 +1336,7 @@ pub mod tests {
1346
1336
1347
1337
#[ test]
1348
1338
fn test_parse_symtab_command ( ) {
1349
- if let ( LoadCommand :: SymTab { symoff, nsyms, stroff, strsize } , cmdsize) =
1350
- parse_command ! ( LC_SYMTAB_DATA ) {
1339
+ if let ( LoadCommand :: SymTab { symoff, nsyms, stroff, strsize } , cmdsize) = parse_command ! ( LC_SYMTAB_DATA ) {
1351
1340
assert_eq ! ( cmdsize, 24 ) ;
1352
1341
assert_eq ! ( symoff, 0x200d88 ) ;
1353
1342
assert_eq ! ( nsyms, 36797 ) ;
@@ -1405,8 +1394,7 @@ pub mod tests {
1405
1394
1406
1395
#[ test]
1407
1396
fn test_parse_load_dylinker_command ( ) {
1408
- if let ( LoadCommand :: LoadDyLinker ( LcString ( off, ref name) ) , cmdsize) =
1409
- parse_command ! ( LC_LOAD_DYLINKER_DATA ) {
1397
+ if let ( LoadCommand :: LoadDyLinker ( LcString ( off, ref name) ) , cmdsize) = parse_command ! ( LC_LOAD_DYLINKER_DATA ) {
1410
1398
assert_eq ! ( cmdsize, 32 ) ;
1411
1399
assert_eq ! ( off, 12 ) ;
1412
1400
assert_eq ! ( name, "/usr/lib/dyld" ) ;
@@ -1429,7 +1417,7 @@ pub mod tests {
1429
1417
#[ test]
1430
1418
fn test_parse_min_version_command ( ) {
1431
1419
if let ( LoadCommand :: VersionMin { target, version, sdk } , cmdsize) =
1432
- parse_command ! ( LC_VERSION_MIN_MACOSX_DATA ) {
1420
+ parse_command ! ( LC_VERSION_MIN_MACOSX_DATA ) {
1433
1421
assert_eq ! ( cmdsize, 16 ) ;
1434
1422
assert_eq ! ( target, BuildTarget :: MacOsX ) ;
1435
1423
assert_eq ! ( version. to_string( ) , "10.11" ) ;
@@ -1441,8 +1429,7 @@ pub mod tests {
1441
1429
1442
1430
#[ test]
1443
1431
fn test_parse_source_version_command ( ) {
1444
- if let ( LoadCommand :: SourceVersion ( version) , cmdsize) =
1445
- parse_command ! ( LC_SOURCE_VERSION_DATA ) {
1432
+ if let ( LoadCommand :: SourceVersion ( version) , cmdsize) = parse_command ! ( LC_SOURCE_VERSION_DATA ) {
1446
1433
assert_eq ! ( cmdsize, 16 ) ;
1447
1434
assert_eq ! ( version. to_string( ) , "0.0" ) ;
1448
1435
} else {
@@ -1452,8 +1439,7 @@ pub mod tests {
1452
1439
1453
1440
#[ test]
1454
1441
fn test_parse_main_command ( ) {
1455
- if let ( LoadCommand :: EntryPoint { entryoff, stacksize } , cmdsize) =
1456
- parse_command ! ( LC_MAIN_DATA ) {
1442
+ if let ( LoadCommand :: EntryPoint { entryoff, stacksize } , cmdsize) = parse_command ! ( LC_MAIN_DATA ) {
1457
1443
assert_eq ! ( cmdsize, 24 ) ;
1458
1444
assert_eq ! ( entryoff, 0x11400 ) ;
1459
1445
assert_eq ! ( stacksize, 0 ) ;
@@ -1479,16 +1465,15 @@ pub mod tests {
1479
1465
#[ test]
1480
1466
fn test_parse_link_edit_data_command ( ) {
1481
1467
if let ( LoadCommand :: FunctionStarts ( LinkEditData { off, size } ) , cmdsize) =
1482
- parse_command ! ( LC_FUNCTION_STARTS_DATA ) {
1468
+ parse_command ! ( LC_FUNCTION_STARTS_DATA ) {
1483
1469
assert_eq ! ( cmdsize, 16 ) ;
1484
1470
assert_eq ! ( off, 0x1fec50 ) ;
1485
1471
assert_eq ! ( size, 8504 ) ;
1486
1472
} else {
1487
1473
panic ! ( ) ;
1488
1474
}
1489
1475
1490
- if let ( LoadCommand :: DataInCode ( LinkEditData { off, size } ) , cmdsize) =
1491
- parse_command ! ( LC_DATA_IN_CODE_DATA ) {
1476
+ if let ( LoadCommand :: DataInCode ( LinkEditData { off, size } ) , cmdsize) = parse_command ! ( LC_DATA_IN_CODE_DATA ) {
1492
1477
assert_eq ! ( cmdsize, 16 ) ;
1493
1478
assert_eq ! ( off, 0x200d88 ) ;
1494
1479
assert_eq ! ( size, 0 ) ;
0 commit comments