File tree Expand file tree Collapse file tree 3 files changed +23
-16
lines changed Expand file tree Collapse file tree 3 files changed +23
-16
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ use core::convert::TryInto;
14
14
use core:: mem;
15
15
use core:: u32;
16
16
use libc:: c_void;
17
- use mystd:: ffi:: OsString ;
17
+ use mystd:: ffi:: { OsStr , OsString } ;
18
18
use mystd:: fs:: File ;
19
19
use mystd:: path:: Path ;
20
20
use mystd:: prelude:: v1:: * ;
@@ -322,6 +322,21 @@ fn create_mapping(lib: &Library) -> Option<Mapping> {
322
322
}
323
323
}
324
324
325
+ /// Try to extract the archive path from an "embedded" library path
326
+ /// (e.g. `/path/to/my.apk` from `/path/to/my.apk!/mylib.so`).
327
+ ///
328
+ /// Returns `None` if the path does not contain a `!/` separator.
329
+ #[ cfg( target_os = "android" ) ]
330
+ fn extract_zip_path_android ( path : & OsStr ) -> Option < & OsStr > {
331
+ use mystd:: os:: unix:: ffi:: OsStrExt ;
332
+
333
+ path. as_bytes ( )
334
+ . windows ( 2 )
335
+ . enumerate ( )
336
+ . find ( |( _, chunk) | chunk == b"!/" )
337
+ . map ( |( index, _) | OsStr :: from_bytes ( path. as_bytes ( ) . split_at ( index) . 0 ) )
338
+ }
339
+
325
340
// unsafe because this is required to be externally synchronized
326
341
pub unsafe fn clear_symbol_cache ( ) {
327
342
Cache :: with_global ( |cache| cache. mappings . clear ( ) ) ;
Original file line number Diff line number Diff line change @@ -59,12 +59,7 @@ impl Mapping {
59
59
pub fn new_android ( path : & Path , zip_offset : Option < u64 > ) -> Option < Mapping > {
60
60
fn map_embedded_library ( path : & Path , zip_offset : u64 ) -> Option < Mapping > {
61
61
// get path of ZIP archive (delimited by `!/`)
62
- let raw_path = path. as_os_str ( ) . as_bytes ( ) ;
63
- let zip_path = raw_path
64
- . windows ( 2 )
65
- . enumerate ( )
66
- . find ( |( _, chunk) | chunk == b"!/" )
67
- . map ( |( index, _) | Path :: new ( OsStr :: from_bytes ( raw_path. split_at ( index) . 0 ) ) ) ?;
62
+ let zip_path = Path :: new ( super :: extract_zip_path_android ( path. as_os_str ( ) ) ?) ;
68
63
69
64
let file = fs:: File :: open ( zip_path) . ok ( ) ?;
70
65
let len = file. metadata ( ) . ok ( ) ?. len ( ) ;
Original file line number Diff line number Diff line change @@ -89,15 +89,12 @@ unsafe extern "C" fn callback(
89
89
// only check for ZIP-embedded file if we have data from /proc/self/maps
90
90
maps. as_ref ( ) . and_then ( |maps| {
91
91
// check if file is embedded within a ZIP archive by searching for `!/`
92
- name. as_bytes ( )
93
- . windows ( 2 )
94
- . find ( |& chunk| chunk == b"!/" )
95
- . and_then ( |_| {
96
- // find MapsEntry matching library's base address
97
- maps. iter ( )
98
- . find ( |m| m. ip_matches ( dlpi_addr as usize ) )
99
- . and_then ( |m| Some ( m. offset ( ) ) )
100
- } )
92
+ super :: extract_zip_path_android ( & name) . and_then ( |_| {
93
+ // find MapsEntry matching library's base address and get its file offset
94
+ maps. iter ( )
95
+ . find ( |m| m. ip_matches ( dlpi_addr as usize ) )
96
+ . map ( |m| m. offset ( ) )
97
+ } )
101
98
} )
102
99
} ;
103
100
let headers = if dlpi_phdr. is_null ( ) || dlpi_phnum == 0 {
You can’t perform that action at this time.
0 commit comments