@@ -3,8 +3,8 @@ use std::borrow::Cow;
33use std:: io:: { BufRead , Cursor , Seek } ;
44
55use idb_rs:: id1:: ID1Section ;
6- use idb_rs:: id2:: { ID2Section , ID2SectionVariants } ;
7- use idb_rs:: { IDAKind , IDAUsize , IDBFormat } ;
6+ use idb_rs:: id2:: ID2Section ;
7+ use idb_rs:: { IDAKind , IDAUsize , IDAVariants , IDBFormat , IDBString } ;
88use types:: * ;
99mod addr_info;
1010use addr_info:: * ;
@@ -14,7 +14,7 @@ use binaryninja::debuginfo::{
1414 CustomDebugInfoParser , DebugFunctionInfo , DebugInfo , DebugInfoParser ,
1515} ;
1616
17- use idb_rs:: id0:: { ID0Section , ID0SectionVariants } ;
17+ use idb_rs:: id0:: ID0Section ;
1818use idb_rs:: til:: section:: TILSection ;
1919use idb_rs:: til:: TypeVariant as TILTypeVariant ;
2020
@@ -135,8 +135,11 @@ fn parse_idb_info(
135135 let mut file = std:: io:: BufReader :: new ( file) ;
136136 let idb_kind = idb_rs:: identify_idb_file ( & mut file) ?;
137137 match idb_kind {
138- idb_rs:: IDBFormats :: Separated ( sep) => {
139- parse_idb_info_format ( debug_info, bv, debug_file, sep, file, progress)
138+ idb_rs:: IDBFormats :: Separated ( IDAVariants :: IDA32 ( sep32) ) => {
139+ parse_idb_info_format ( debug_info, bv, debug_file, sep32, file, progress)
140+ }
141+ idb_rs:: IDBFormats :: Separated ( IDAVariants :: IDA64 ( sep64) ) => {
142+ parse_idb_info_format ( debug_info, bv, debug_file, sep64, file, progress)
140143 }
141144 idb_rs:: IDBFormats :: InlineUncompressed ( inline) => {
142145 parse_idb_info_format ( debug_info, bv, debug_file, inline, file, progress)
@@ -156,11 +159,11 @@ fn parse_idb_info(
156159 }
157160}
158161
159- fn parse_idb_info_format (
162+ fn parse_idb_info_format < K : IDAKind > (
160163 debug_info : & mut DebugInfo ,
161164 bv : & BinaryView ,
162165 debug_file : & BinaryView ,
163- format : impl IDBFormat ,
166+ format : impl IDBFormat < K > ,
164167 mut idb_data : impl BufRead + Seek ,
165168 progress : Box < dyn Fn ( usize , usize ) -> Result < ( ) , ( ) > > ,
166169) -> Result < ( ) > {
@@ -185,21 +188,7 @@ fn parse_idb_info_format(
185188 . map ( |id2_idx| format. read_id2 ( & mut idb_data, id2_idx) )
186189 . transpose ( ) ?;
187190
188- match ( id0, id2) {
189- ( ID0SectionVariants :: IDA32 ( id0) , Some ( ID2SectionVariants :: IDA32 ( id2) ) ) => {
190- parse_id0_section_info ( debug_info, bv, debug_file, & id0, & id1, Some ( & id2) ) ?
191- }
192- ( ID0SectionVariants :: IDA32 ( id0) , None ) => {
193- parse_id0_section_info ( debug_info, bv, debug_file, & id0, & id1, None ) ?
194- }
195- ( ID0SectionVariants :: IDA64 ( id0) , Some ( ID2SectionVariants :: IDA64 ( id2) ) ) => {
196- parse_id0_section_info ( debug_info, bv, debug_file, & id0, & id1, Some ( & id2) ) ?
197- }
198- ( ID0SectionVariants :: IDA64 ( id0) , None ) => {
199- parse_id0_section_info ( debug_info, bv, debug_file, & id0, & id1, None ) ?
200- }
201- _ => unreachable ! ( ) ,
202- }
191+ parse_id0_section_info ( debug_info, bv, debug_file, & id0, & id1, id2. as_ref ( ) ) ?;
203192
204193 Ok ( ( ) )
205194}
@@ -291,19 +280,18 @@ fn parse_id0_section_info<K: IDAKind>(
291280 bv : & BinaryView ,
292281 debug_file : & BinaryView ,
293282 id0 : & ID0Section < K > ,
294- id1 : & ID1Section ,
283+ id1 : & ID1Section < K > ,
295284 id2 : Option < & ID2Section < K > > ,
296285) -> Result < ( ) > {
297286 let ida_info_idx = id0. root_node ( ) ?;
298287 let ida_info = id0. ida_info ( ida_info_idx) ?;
299288 let idb_baseaddr = ida_info. addresses . loading_base . into_u64 ( ) ;
300289 let bv_baseaddr = bv. start ( ) ;
301- let netdelta = ida_info. netdelta ( ) ;
302290 // just addr this value to the address to translate from ida to bn
303291 // NOTE this delta could wrap here and while using translating
304292 let addr_delta = bv_baseaddr. wrapping_sub ( idb_baseaddr) ;
305293
306- for ( idb_addr, info) in get_info ( id0, id1, id2, netdelta ) ? {
294+ for ( idb_addr, info) in get_info ( id0, id1, id2, & ida_info ) ? {
307295 let addr = addr_delta. wrapping_add ( idb_addr. into_raw ( ) . into_u64 ( ) ) ;
308296 // just in case we change this struct in the future, this line will for us to review this code
309297 // TODO merge this data with folder locations
@@ -314,30 +302,35 @@ fn parse_id0_section_info<K: IDAKind>(
314302 } = info;
315303 // TODO set comments to address here
316304 for function in & bv. functions_containing ( addr) {
317- function. set_comment_at ( addr, & String :: from_utf8_lossy ( & comments. join ( & b"\n " [ ..] ) ) ) ;
305+ let comments: Vec < String > = comments
306+ . iter ( )
307+ . map ( idb_rs:: IDBString :: as_utf8_lossy)
308+ . map ( Cow :: into_owned)
309+ . collect ( ) ;
310+ function. set_comment_at ( addr, & comments. join ( "\n " ) ) ;
318311 }
319312
320- let bnty = ty
321- . as_ref ( )
322- . and_then ( |ty| match translate_ephemeral_type ( debug_file, ty) {
323- TranslateTypeResult :: Translated ( result) => Some ( result) ,
324- TranslateTypeResult :: PartiallyTranslated ( result, None ) => {
325- warn ! ( "Unable to fully translate the type at {addr:#x}" ) ;
326- Some ( result)
327- }
328- TranslateTypeResult :: NotYet => {
329- error ! ( "Unable to translate the type at {addr:#x}" ) ;
330- None
331- }
332- TranslateTypeResult :: PartiallyTranslated ( _, Some ( bn_type_error) )
333- | TranslateTypeResult :: Error ( bn_type_error) => {
334- error ! ( "Unable to translate the type at {addr:#x}: {bn_type_error}" , ) ;
335- None
336- }
337- } ) ;
313+ let bnty =
314+ ty. as_ref ( ) . and_then (
315+ |ty| match translate_ephemeral_type ( debug_file, & ida_info, ty) {
316+ TranslateTypeResult :: Translated ( result) => Some ( result) ,
317+ TranslateTypeResult :: PartiallyTranslated ( result, None ) => {
318+ warn ! ( "Unable to fully translate the type at {addr:#x}" ) ;
319+ Some ( result)
320+ }
321+ TranslateTypeResult :: NotYet => {
322+ error ! ( "Unable to translate the type at {addr:#x}" ) ;
323+ None
324+ }
325+ TranslateTypeResult :: PartiallyTranslated ( _, Some ( bn_type_error) )
326+ | TranslateTypeResult :: Error ( bn_type_error) => {
327+ error ! ( "Unable to translate the type at {addr:#x}: {bn_type_error}" , ) ;
328+ None
329+ }
330+ } ,
331+ ) ;
338332
339- let label: Option < Cow < ' _ , str > > =
340- label. as_ref ( ) . map ( Cow :: as_ref) . map ( String :: from_utf8_lossy) ;
333+ let label: Option < Cow < ' _ , str > > = label. as_ref ( ) . map ( IDBString :: as_utf8_lossy) ;
341334 match ( label, & ty, bnty) {
342335 ( label, Some ( ty) , bnty) if matches ! ( & ty. type_variant, TILTypeVariant :: Function ( _) ) => {
343336 if bnty. is_none ( ) {
0 commit comments