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;
1414use core:: mem;
1515use core:: u32;
1616use libc:: c_void;
17- use mystd:: ffi:: OsString ;
17+ use mystd:: ffi:: { OsStr , OsString } ;
1818use mystd:: fs:: File ;
1919use mystd:: path:: Path ;
2020use mystd:: prelude:: v1:: * ;
@@ -322,6 +322,21 @@ fn create_mapping(lib: &Library) -> Option<Mapping> {
322322 }
323323}
324324
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+
325340// unsafe because this is required to be externally synchronized
326341pub unsafe fn clear_symbol_cache ( ) {
327342 Cache :: with_global ( |cache| cache. mappings . clear ( ) ) ;
Original file line number Diff line number Diff line change @@ -59,12 +59,7 @@ impl Mapping {
5959 pub fn new_android ( path : & Path , zip_offset : Option < u64 > ) -> Option < Mapping > {
6060 fn map_embedded_library ( path : & Path , zip_offset : u64 ) -> Option < Mapping > {
6161 // 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 ( ) ) ?) ;
6863
6964 let file = fs:: File :: open ( zip_path) . ok ( ) ?;
7065 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(
8989 // only check for ZIP-embedded file if we have data from /proc/self/maps
9090 maps. as_ref ( ) . and_then ( |maps| {
9191 // 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+ } )
10198 } )
10299 } ;
103100 let headers = if dlpi_phdr. is_null ( ) || dlpi_phnum == 0 {
You can’t perform that action at this time.
0 commit comments