@@ -8,7 +8,7 @@ use num_traits::{AsPrimitive, CheckedAdd, PrimInt, ToBytes};
8
8
use crate :: addr_info:: SubtypeId ;
9
9
use crate :: id0:: flag:: nsup:: NSUP_LLABEL ;
10
10
use crate :: ida_reader:: { IdbBufRead , IdbReadKind } ;
11
- use crate :: { til, Address } ;
11
+ use crate :: { til, Address , IDBStr } ;
12
12
use crate :: { IDAVariants , SectionReader , IDA32 , IDA64 } ;
13
13
14
14
use super :: entry_iter:: {
@@ -503,7 +503,7 @@ impl<K: IDAKind> ID0Section<K> {
503
503
// TODO there is also a "P" entry in patches, it seems to only contains
504
504
// the value 0x01 for each equivalent "A" entry
505
505
506
- pub fn segment_name ( & self , idx : SegmentNameIdx < K > ) -> Result < & [ u8 ] > {
506
+ pub fn segment_name ( & self , idx : SegmentNameIdx < K > ) -> Result < IDBStr < ' _ > > {
507
507
let seg_idx = self . segment_strings_idx ( ) ?;
508
508
// TODO I think this is dependent on the version, and not on availability
509
509
if let Some ( seg_idx) = seg_idx {
@@ -523,7 +523,7 @@ impl<K: IDAKind> ID0Section<K> {
523
523
pub ( crate ) fn name_by_index (
524
524
& self ,
525
525
idx : SegmentNameIdx < K > ,
526
- ) -> Result < & [ u8 ] > {
526
+ ) -> Result < IDBStr < ' _ > > {
527
527
// if there is no names, AKA `$ segstrings`, search for the key directly
528
528
let name_idx = self
529
529
. netnode_tag_idx (
@@ -532,6 +532,7 @@ impl<K: IDAKind> ID0Section<K> {
532
532
)
533
533
. ok_or_else ( || anyhow ! ( "Not found name for segment {}" , idx. 0 ) ) ?;
534
534
parse_maybe_cstr ( & self . entries [ name_idx] . value )
535
+ . map ( IDBStr :: new)
535
536
. ok_or_else ( || anyhow ! ( "Invalid segment name {}" , idx. 0 ) )
536
537
}
537
538
@@ -585,8 +586,8 @@ impl<K: IDAKind> ID0Section<K> {
585
586
)
586
587
}
587
588
588
- pub fn input_file ( & self , idx : RootNodeIdx < K > ) -> Option < & [ u8 ] > {
589
- self . netnode_value ( idx. into ( ) )
589
+ pub fn input_file ( & self , idx : RootNodeIdx < K > ) -> Option < IDBStr < ' _ > > {
590
+ self . netnode_value ( idx. into ( ) ) . map ( IDBStr :: new )
590
591
}
591
592
592
593
// TODO identify the data
@@ -1139,17 +1140,20 @@ impl<K: IDAKind> ID0Section<K> {
1139
1140
Ok ( None )
1140
1141
}
1141
1142
1142
- pub ( crate ) fn comment_at ( & self , netnode : NetnodeIdx < K > ) -> Option < & [ u8 ] > {
1143
+ pub ( crate ) fn comment_at (
1144
+ & self ,
1145
+ netnode : NetnodeIdx < K > ,
1146
+ ) -> Option < IDBStr < ' _ > > {
1143
1147
let comment = self . sup_value ( netnode, 0u8 . into ( ) , ARRAY_SUP_TAG ) ?;
1144
- Some ( parse_maybe_cstr ( comment) . unwrap_or ( comment) )
1148
+ Some ( IDBStr :: new ( parse_maybe_cstr ( comment) . unwrap_or ( comment) ) )
1145
1149
}
1146
1150
1147
1151
pub ( crate ) fn comment_repeatable_at (
1148
1152
& self ,
1149
1153
netnode : NetnodeIdx < K > ,
1150
- ) -> Option < & [ u8 ] > {
1154
+ ) -> Option < IDBStr < ' _ > > {
1151
1155
let comment = self . sup_value ( netnode, 1u8 . into ( ) , ARRAY_SUP_TAG ) ?;
1152
- Some ( parse_maybe_cstr ( comment) . unwrap_or ( comment) )
1156
+ Some ( IDBStr :: new ( parse_maybe_cstr ( comment) . unwrap_or ( comment) ) )
1153
1157
}
1154
1158
1155
1159
// TODO: comments have a strange hole in id0
@@ -1162,7 +1166,7 @@ impl<K: IDAKind> ID0Section<K> {
1162
1166
pub ( crate ) fn comment_pre_at (
1163
1167
& self ,
1164
1168
netnode : NetnodeIdx < K > ,
1165
- ) -> impl Iterator < Item = & [ u8 ] > {
1169
+ ) -> impl Iterator < Item = IDBStr < ' _ > > {
1166
1170
crate :: id0:: entry_iter:: EntryTagContinuousSubkeys :: new (
1167
1171
self ,
1168
1172
netnode,
@@ -1172,13 +1176,17 @@ impl<K: IDAKind> ID0Section<K> {
1172
1176
// 1000..2000
1173
1177
// max number of lines, NOTE this check is not done by IDA
1174
1178
. take ( 1000 )
1175
- . map ( |entry| parse_maybe_cstr ( & entry. value ) . unwrap_or ( & entry. value [ ..] ) )
1179
+ . map ( |entry| {
1180
+ IDBStr :: new (
1181
+ parse_maybe_cstr ( & entry. value ) . unwrap_or ( & entry. value [ ..] ) ,
1182
+ )
1183
+ } )
1176
1184
}
1177
1185
1178
1186
pub ( crate ) fn comment_post_at (
1179
1187
& self ,
1180
1188
netnode : NetnodeIdx < K > ,
1181
- ) -> impl Iterator < Item = & [ u8 ] > {
1189
+ ) -> impl Iterator < Item = IDBStr < ' _ > > {
1182
1190
crate :: id0:: entry_iter:: EntryTagContinuousSubkeys :: new (
1183
1191
self ,
1184
1192
netnode,
@@ -1188,7 +1196,11 @@ impl<K: IDAKind> ID0Section<K> {
1188
1196
// 2000..3000
1189
1197
// max number of lines, NOTE this check is not done by IDA
1190
1198
. take ( 1000 )
1191
- . map ( |entry| parse_maybe_cstr ( & entry. value ) . unwrap_or ( & entry. value [ ..] ) )
1199
+ . map ( |entry| {
1200
+ IDBStr :: new (
1201
+ parse_maybe_cstr ( & entry. value ) . unwrap_or ( & entry. value [ ..] ) ,
1202
+ )
1203
+ } )
1192
1204
}
1193
1205
1194
1206
pub fn struct_at ( & self , idx : SubtypeId < K > ) -> Result < & [ u8 ] > {
0 commit comments