blob: 93a07590bfafc69c323a0a14a1a61744b8366ec8 [file] [log] [blame]
Jooyung Han347d9f22021-05-28 00:05:14 +09001// Copyright 2021, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Microdroid Manager
16
Jiyong Park21ce2c52021-08-28 02:32:17 +090017mod instance;
Jooyung Hanf48ceb42021-06-01 18:00:04 +090018mod ioutil;
Jooyung Han7a343f92021-09-08 22:53:11 +090019mod payload;
Jooyung Han347d9f22021-05-28 00:05:14 +090020
Jiyong Parkf7dea252021-09-08 01:42:54 +090021use crate::instance::{ApkData, InstanceDisk, MicrodroidData, RootHash};
Jooyung Handd0a1732021-11-23 15:26:20 +090022use anyhow::{anyhow, bail, ensure, Context, Error, Result};
Jiyong Parka41535b2021-09-10 19:31:48 +090023use apkverify::{get_public_key_der, verify};
Inseob Kim1b95f2e2021-08-19 13:17:40 +090024use binder::unstable_api::{new_spibinder, AIBinder};
25use binder::{FromIBinder, Strong};
Jiyong Park21ce2c52021-08-28 02:32:17 +090026use idsig::V4Signature;
Jiyong Parkbb4a9872021-09-06 15:59:21 +090027use log::{error, info, warn};
Jooyung Han4a9b3bf2021-09-10 17:19:00 +090028use microdroid_metadata::{write_metadata, Metadata};
Jooyung Han634e2d72021-06-10 16:27:38 +090029use microdroid_payload_config::{Task, TaskType, VmPayloadConfig};
Jooyung Han4a9b3bf2021-09-10 17:19:00 +090030use payload::{get_apex_data_from_payload, load_metadata, to_metadata};
Jiyong Parkbb4a9872021-09-06 15:59:21 +090031use rustutils::system_properties;
Joel Galenson482704c2021-07-29 15:53:53 -070032use rustutils::system_properties::PropertyWatcher;
Inseob Kim7f61fe72021-08-20 20:50:47 +090033use std::fs::{self, File, OpenOptions};
Inseob Kimc7d28c72021-10-25 14:28:10 +000034use std::os::unix::io::{FromRawFd, IntoRawFd};
Jooyung Hanf48ceb42021-06-01 18:00:04 +090035use std::path::Path;
Inseob Kim217038e2021-11-25 11:15:06 +090036use std::process::{Child, Command, Stdio};
Jiyong Park8611a6c2021-07-09 18:17:44 +090037use std::str;
Jiyong Parkbb4a9872021-09-06 15:59:21 +090038use std::time::{Duration, SystemTime};
Jiyong Park8611a6c2021-07-09 18:17:44 +090039use vsock::VsockStream;
Jooyung Han634e2d72021-06-10 16:27:38 +090040
Inseob Kimd0587562021-09-01 21:27:32 +090041use android_system_virtualmachineservice::aidl::android::system::virtualmachineservice::IVirtualMachineService::{
Jooyung Han5c6d4172021-12-06 14:17:52 +090042 ERROR_PAYLOAD_CHANGED, ERROR_PAYLOAD_VERIFICATION_FAILED, ERROR_PAYLOAD_INVALID_CONFIG, ERROR_UNKNOWN, VM_BINDER_SERVICE_PORT, VM_STREAM_SERVICE_PORT, IVirtualMachineService,
Inseob Kimd0587562021-09-01 21:27:32 +090043};
Inseob Kim1b95f2e2021-08-19 13:17:40 +090044
Jooyung Han634e2d72021-06-10 16:27:38 +090045const WAIT_TIMEOUT: Duration = Duration::from_secs(10);
Inseob Kim217038e2021-11-25 11:15:06 +090046const APK_DM_VERITY_ARGUMENT: ApkDmverityArgument = {
47 ApkDmverityArgument {
48 apk: "/dev/block/by-name/microdroid-apk",
49 idsig: "/dev/block/by-name/microdroid-apk-idsig",
50 name: "microdroid-apk",
51 }
52};
Jooyung Han19c1d6c2021-08-06 14:08:16 +090053const DM_MOUNTED_APK_PATH: &str = "/dev/block/mapper/microdroid-apk";
Inseob Kim217038e2021-11-25 11:15:06 +090054const APKDMVERITY_BIN: &str = "/system/bin/apkdmverity";
55const ZIPFUSE_BIN: &str = "/system/bin/zipfuse";
Jooyung Han347d9f22021-05-28 00:05:14 +090056
Inseob Kim1b95f2e2021-08-19 13:17:40 +090057/// The CID representing the host VM
58const VMADDR_CID_HOST: u32 = 2;
59
Jiyong Parkbb4a9872021-09-06 15:59:21 +090060const APEX_CONFIG_DONE_PROP: &str = "apex_config.done";
Jiyong Parkfa91d702021-10-18 23:51:39 +090061const LOGD_ENABLED_PROP: &str = "ro.boot.logd.enabled";
Jiyong Parkbb4a9872021-09-06 15:59:21 +090062
Jooyung Handd0a1732021-11-23 15:26:20 +090063#[derive(thiserror::Error, Debug)]
64enum MicrodroidError {
65 #[error("Payload has changed: {0}")]
66 PayloadChanged(String),
67 #[error("Payload verification has failed: {0}")]
68 PayloadVerificationFailed(String),
Jooyung Han5c6d4172021-12-06 14:17:52 +090069 #[error("Payload config is invalid: {0}")]
70 InvalidConfig(String),
Jooyung Handd0a1732021-11-23 15:26:20 +090071}
72
73fn translate_error(err: &Error) -> (i32, String) {
74 if let Some(e) = err.downcast_ref::<MicrodroidError>() {
75 match e {
76 MicrodroidError::PayloadChanged(msg) => (ERROR_PAYLOAD_CHANGED, msg.to_string()),
77 MicrodroidError::PayloadVerificationFailed(msg) => {
78 (ERROR_PAYLOAD_VERIFICATION_FAILED, msg.to_string())
79 }
Jooyung Han5c6d4172021-12-06 14:17:52 +090080 MicrodroidError::InvalidConfig(msg) => (ERROR_PAYLOAD_INVALID_CONFIG, msg.to_string()),
Jooyung Handd0a1732021-11-23 15:26:20 +090081 }
82 } else {
83 (ERROR_UNKNOWN, err.to_string())
84 }
85}
86
Inseob Kim1b95f2e2021-08-19 13:17:40 +090087fn get_vms_rpc_binder() -> Result<Strong<dyn IVirtualMachineService>> {
88 // SAFETY: AIBinder returned by RpcClient has correct reference count, and the ownership can be
89 // safely taken by new_spibinder.
90 let ibinder = unsafe {
91 new_spibinder(binder_rpc_unstable_bindgen::RpcClient(
92 VMADDR_CID_HOST,
Inseob Kimd0587562021-09-01 21:27:32 +090093 VM_BINDER_SERVICE_PORT as u32,
Inseob Kim1b95f2e2021-08-19 13:17:40 +090094 ) as *mut AIBinder)
95 };
96 if let Some(ibinder) = ibinder {
97 <dyn IVirtualMachineService>::try_from(ibinder).context("Cannot connect to RPC service")
98 } else {
99 bail!("Invalid raw AIBinder")
100 }
101}
102
Jooyung Han311b1202021-09-14 22:00:16 +0900103fn main() {
104 if let Err(e) = try_main() {
Jooyung Hanbfe086f2021-10-28 10:15:45 +0900105 error!("Failed with {:?}. Shutting down...", e);
106 if let Err(e) = system_properties::write("sys.powerctl", "shutdown") {
107 error!("failed to shutdown {:?}", e);
108 }
Jooyung Han311b1202021-09-14 22:00:16 +0900109 std::process::exit(1);
110 }
111}
112
113fn try_main() -> Result<()> {
Jiyong Park79b88012021-06-25 13:06:25 +0900114 kernlog::init()?;
Jooyung Han347d9f22021-05-28 00:05:14 +0900115 info!("started.");
116
Jooyung Handd0a1732021-11-23 15:26:20 +0900117 let service = get_vms_rpc_binder().context("cannot connect to VirtualMachineService")?;
Jooyung Han5c6d4172021-12-06 14:17:52 +0900118 match try_run_payload(&service) {
119 Ok(code) => {
120 info!("notifying payload finished");
121 service.notifyPayloadFinished(code)?;
122 if code == 0 {
123 info!("task successfully finished");
124 } else {
125 error!("task exited with exit code: {}", code);
126 }
127 Ok(())
128 }
129 Err(err) => {
130 error!("task terminated: {:?}", err);
131 let (error_code, message) = translate_error(&err);
132 service.notifyError(error_code, &message)?;
133 Err(err)
134 }
Jooyung Handd0a1732021-11-23 15:26:20 +0900135 }
136}
137
Jooyung Han5c6d4172021-12-06 14:17:52 +0900138fn try_run_payload(service: &Strong<dyn IVirtualMachineService>) -> Result<i32> {
Jooyung Han311b1202021-09-14 22:00:16 +0900139 let metadata = load_metadata().context("Failed to load payload metadata")?;
Jooyung Han19c1d6c2021-08-06 14:08:16 +0900140
Jooyung Han311b1202021-09-14 22:00:16 +0900141 let mut instance = InstanceDisk::new().context("Failed to load instance.img")?;
Jooyung Han7a343f92021-09-08 22:53:11 +0900142 let saved_data = instance.read_microdroid_data().context("Failed to read identity data")?;
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900143
144 // Verify the payload before using it.
Jooyung Han7a343f92021-09-08 22:53:11 +0900145 let verified_data =
146 verify_payload(&metadata, saved_data.as_ref()).context("Payload verification failed")?;
147 if let Some(saved_data) = saved_data {
Jooyung Handd0a1732021-11-23 15:26:20 +0900148 ensure!(
149 saved_data == verified_data,
150 MicrodroidError::PayloadChanged(String::from(
151 "Detected an update of the payload which isn't supported yet."
152 ))
153 );
154 info!("Saved data is verified.");
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900155 } else {
Jooyung Han7a343f92021-09-08 22:53:11 +0900156 info!("Saving verified data.");
157 instance.write_microdroid_data(&verified_data).context("Failed to write identity data")?;
Jooyung Han19c1d6c2021-08-06 14:08:16 +0900158 }
159
Jooyung Hana6d11eb2021-09-10 11:48:05 +0900160 // Before reading a file from the APK, start zipfuse
Inseob Kim217038e2021-11-25 11:15:06 +0900161 run_zipfuse(
162 "fscontext=u:object_r:zipfusefs:s0,context=u:object_r:system_file:s0",
163 Path::new("/dev/block/mapper/microdroid-apk"),
164 Path::new("/mnt/apk"),
165 )
166 .context("Failed to run zipfuse")?;
Jiyong Park21ce2c52021-08-28 02:32:17 +0900167
Jooyung Han5c6d4172021-12-06 14:17:52 +0900168 ensure!(
169 !metadata.payload_config_path.is_empty(),
170 MicrodroidError::InvalidConfig("No payload_config_path in metadata".to_string())
171 );
172 let config = load_config(Path::new(&metadata.payload_config_path))?;
Jooyung Han634e2d72021-06-10 16:27:38 +0900173
Jooyung Han5c6d4172021-12-06 14:17:52 +0900174 let fake_secret = "This is a placeholder for a value that is derived from the images that are loaded in the VM.";
175 if let Err(err) = rustutils::system_properties::write("ro.vmsecret.keymint", fake_secret) {
176 warn!("failed to set ro.vmsecret.keymint: {}", err);
Jooyung Han347d9f22021-05-28 00:05:14 +0900177 }
178
Jooyung Han5c6d4172021-12-06 14:17:52 +0900179 // Wait until apex config is done. (e.g. linker configuration for apexes)
180 // TODO(jooyung): wait until sys.boot_completed?
181 wait_for_apex_config_done()?;
182
183 ensure!(
184 config.task.is_some(),
185 MicrodroidError::InvalidConfig("No task in VM config".to_string())
186 );
187 exec_task(&config.task.unwrap(), service)
Jooyung Han347d9f22021-05-28 00:05:14 +0900188}
189
Inseob Kim217038e2021-11-25 11:15:06 +0900190struct ApkDmverityArgument<'a> {
191 apk: &'a str,
192 idsig: &'a str,
193 name: &'a str,
194}
195
196fn run_apkdmverity(args: &[ApkDmverityArgument]) -> Result<Child> {
197 let mut cmd = Command::new(APKDMVERITY_BIN);
198
199 cmd.stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());
200
201 for argument in args {
202 cmd.arg("--apk").arg(argument.apk).arg(argument.idsig).arg(argument.name);
203 }
204
205 cmd.spawn().context("Spawn apkdmverity")
206}
207
208fn run_zipfuse(option: &str, zip_path: &Path, mount_dir: &Path) -> Result<Child> {
209 Command::new(ZIPFUSE_BIN)
210 .arg("-o")
211 .arg(option)
212 .arg(zip_path)
213 .arg(mount_dir)
214 .stdin(Stdio::null())
215 .stdout(Stdio::null())
216 .stderr(Stdio::null())
217 .spawn()
218 .context("Spawn zipfuse")
219}
220
Jooyung Han7a343f92021-09-08 22:53:11 +0900221// Verify payload before executing it. For APK payload, Full verification (which is slow) is done
222// when the root_hash values from the idsig file and the instance disk are different. This function
223// returns the verified root hash (for APK payload) and pubkeys (for APEX payloads) that can be
224// saved to the instance disk.
225fn verify_payload(
226 metadata: &Metadata,
227 saved_data: Option<&MicrodroidData>,
228) -> Result<MicrodroidData> {
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900229 let start_time = SystemTime::now();
230
Jooyung Han7a343f92021-09-08 22:53:11 +0900231 let root_hash = saved_data.map(|d| &d.apk_data.root_hash);
Jiyong Parkf7dea252021-09-08 01:42:54 +0900232 let root_hash_from_idsig = get_apk_root_hash_from_idsig()?;
233 let root_hash_trustful = root_hash == Some(&root_hash_from_idsig);
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900234
Jiyong Parkf7dea252021-09-08 01:42:54 +0900235 // If root_hash can be trusted, pass it to apkdmverity so that it uses the passed root_hash
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900236 // instead of the value read from the idsig file.
Jiyong Parkf7dea252021-09-08 01:42:54 +0900237 if root_hash_trustful {
238 let root_hash = to_hex_string(root_hash.unwrap());
239 system_properties::write("microdroid_manager.apk_root_hash", &root_hash)?;
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900240 }
241
242 // Start apkdmverity and wait for the dm-verify block
Inseob Kim217038e2021-11-25 11:15:06 +0900243 let mut apkdmverity_child = run_apkdmverity(&[APK_DM_VERITY_ARGUMENT])?;
Jooyung Han7a343f92021-09-08 22:53:11 +0900244
Jooyung Hanc8deb472021-09-13 13:48:25 +0900245 // While waiting for apkdmverity to mount APK, gathers public keys and root digests from
246 // APEX payload.
Jooyung Han7a343f92021-09-08 22:53:11 +0900247 let apex_data_from_payload = get_apex_data_from_payload(metadata)?;
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900248 if let Some(saved_data) = saved_data.map(|d| &d.apex_data) {
Jooyung Hanc8deb472021-09-13 13:48:25 +0900249 // We don't support APEX updates. (assuming that update will change root digest)
Jooyung Handd0a1732021-11-23 15:26:20 +0900250 ensure!(
251 saved_data == &apex_data_from_payload,
252 MicrodroidError::PayloadChanged(String::from("APEXes have changed."))
253 );
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900254 let apex_metadata = to_metadata(&apex_data_from_payload);
Jooyung Hanc8deb472021-09-13 13:48:25 +0900255 // Pass metadata(with public keys and root digests) to apexd so that it uses the passed
256 // metadata instead of the default one (/dev/block/by-name/payload-metadata)
Jooyung Han4a9b3bf2021-09-10 17:19:00 +0900257 OpenOptions::new()
258 .create_new(true)
259 .write(true)
260 .open("/apex/vm-payload-metadata")
261 .context("Failed to open /apex/vm-payload-metadata")
262 .and_then(|f| write_metadata(&apex_metadata, f))?;
263 }
264 // Start apexd to activate APEXes
265 system_properties::write("ctl.start", "apexd-vm")?;
Jooyung Han7a343f92021-09-08 22:53:11 +0900266
Inseob Kim217038e2021-11-25 11:15:06 +0900267 // TODO(inseob): add timeout
268 apkdmverity_child.wait()?;
Jooyung Han19c1d6c2021-08-06 14:08:16 +0900269
Jiyong Parkf7dea252021-09-08 01:42:54 +0900270 // Do the full verification if the root_hash is un-trustful. This requires the full scanning of
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900271 // the APK file and therefore can be very slow if the APK is large. Note that this step is
Jiyong Parkf7dea252021-09-08 01:42:54 +0900272 // taken only when the root_hash is un-trustful which can be either when this is the first boot
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900273 // of the VM or APK was updated in the host.
274 // TODO(jooyung): consider multithreading to make this faster
Jiyong Parka41535b2021-09-10 19:31:48 +0900275 let apk_pubkey = if !root_hash_trustful {
Jooyung Handd0a1732021-11-23 15:26:20 +0900276 verify(DM_MOUNTED_APK_PATH).context(MicrodroidError::PayloadVerificationFailed(format!(
277 "failed to verify {}",
278 DM_MOUNTED_APK_PATH
279 )))?
Jiyong Parka41535b2021-09-10 19:31:48 +0900280 } else {
281 get_public_key_der(DM_MOUNTED_APK_PATH)?
282 };
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900283
284 info!("payload verification successful. took {:#?}", start_time.elapsed().unwrap());
285
Jiyong Parkf7dea252021-09-08 01:42:54 +0900286 // At this point, we can ensure that the root_hash from the idsig file is trusted, either by
287 // fully verifying the APK or by comparing it with the saved root_hash.
Jooyung Han7a343f92021-09-08 22:53:11 +0900288 Ok(MicrodroidData {
Jiyong Parka41535b2021-09-10 19:31:48 +0900289 apk_data: ApkData { root_hash: root_hash_from_idsig, pubkey: apk_pubkey },
Jooyung Han7a343f92021-09-08 22:53:11 +0900290 apex_data: apex_data_from_payload,
291 })
Jiyong Parkbb4a9872021-09-06 15:59:21 +0900292}
293
294// Waits until linker config is generated
295fn wait_for_apex_config_done() -> Result<()> {
296 let mut prop = PropertyWatcher::new(APEX_CONFIG_DONE_PROP)?;
297 loop {
298 prop.wait()?;
299 let val = system_properties::read(APEX_CONFIG_DONE_PROP)?;
300 if val == "true" {
301 break;
302 }
303 }
Jooyung Han19c1d6c2021-08-06 14:08:16 +0900304 Ok(())
305}
306
Jiyong Parkf7dea252021-09-08 01:42:54 +0900307fn get_apk_root_hash_from_idsig() -> Result<Box<RootHash>> {
Jiyong Park21ce2c52021-08-28 02:32:17 +0900308 let mut idsig = File::open("/dev/block/by-name/microdroid-apk-idsig")?;
309 let idsig = V4Signature::from(&mut idsig)?;
310 Ok(idsig.hashing_info.raw_root_hash)
311}
312
Jooyung Han634e2d72021-06-10 16:27:38 +0900313fn load_config(path: &Path) -> Result<VmPayloadConfig> {
314 info!("loading config from {:?}...", path);
315 let file = ioutil::wait_for_file(path, WAIT_TIMEOUT)?;
316 Ok(serde_json::from_reader(file)?)
317}
318
Jiyong Park8611a6c2021-07-09 18:17:44 +0900319/// Executes the given task. Stdout of the task is piped into the vsock stream to the
320/// virtualizationservice in the host side.
Jooyung Han5c6d4172021-12-06 14:17:52 +0900321fn exec_task(task: &Task, service: &Strong<dyn IVirtualMachineService>) -> Result<i32> {
Jiyong Park8611a6c2021-07-09 18:17:44 +0900322 info!("executing main task {:?}...", task);
Inseob Kim86ca0162021-10-20 02:21:02 +0000323 let mut command = build_command(task)?;
Inseob Kim7f61fe72021-08-20 20:50:47 +0900324
325 info!("notifying payload started");
Inseob Kimc7d28c72021-10-25 14:28:10 +0000326 service.notifyPayloadStarted()?;
Inseob Kim7f61fe72021-08-20 20:50:47 +0900327
Jiyong Parkfa91d702021-10-18 23:51:39 +0900328 // Start logging if enabled
329 // TODO(b/200914564) set filterspec if debug_level is app_only
330 if system_properties::read(LOGD_ENABLED_PROP)? == "1" {
331 system_properties::write("ctl.start", "seriallogging")?;
332 }
333
Inseob Kim86ca0162021-10-20 02:21:02 +0000334 let exit_status = command.spawn()?.wait()?;
Jooyung Han5c6d4172021-12-06 14:17:52 +0900335 exit_status.code().ok_or_else(|| anyhow!("Failed to get exit_code from the paylaod."))
Jooyung Han347d9f22021-05-28 00:05:14 +0900336}
Jooyung Han634e2d72021-06-10 16:27:38 +0900337
338fn build_command(task: &Task) -> Result<Command> {
Inseob Kim7f61fe72021-08-20 20:50:47 +0900339 const VMADDR_CID_HOST: u32 = 2;
Inseob Kim7f61fe72021-08-20 20:50:47 +0900340
341 let mut command = match task.type_ {
Jooyung Han634e2d72021-06-10 16:27:38 +0900342 TaskType::Executable => {
343 let mut command = Command::new(&task.command);
344 command.args(&task.args);
345 command
346 }
347 TaskType::MicrodroidLauncher => {
348 let mut command = Command::new("/system/bin/microdroid_launcher");
349 command.arg(find_library_path(&task.command)?).args(&task.args);
350 command
351 }
Inseob Kim7f61fe72021-08-20 20:50:47 +0900352 };
353
Inseob Kimd0587562021-09-01 21:27:32 +0900354 match VsockStream::connect_with_cid_port(VMADDR_CID_HOST, VM_STREAM_SERVICE_PORT as u32) {
Inseob Kim7f61fe72021-08-20 20:50:47 +0900355 Ok(stream) => {
356 // SAFETY: the ownership of the underlying file descriptor is transferred from stream
357 // to the file object, and then into the Command object. When the command is finished,
358 // the file descriptor is closed.
359 let file = unsafe { File::from_raw_fd(stream.into_raw_fd()) };
360 command
361 .stdin(Stdio::from(file.try_clone()?))
362 .stdout(Stdio::from(file.try_clone()?))
363 .stderr(Stdio::from(file));
364 }
365 Err(e) => {
366 error!("failed to connect to virtualization service: {}", e);
367 // Don't fail hard here. Even if we failed to connect to the virtualizationservice,
368 // we keep executing the task. This can happen if the owner of the VM doesn't register
369 // callback to accept the stream. Use /dev/null as the stream so that the task can
370 // make progress without waiting for someone to consume the output.
371 command.stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());
372 }
373 }
374
375 Ok(command)
Jooyung Han634e2d72021-06-10 16:27:38 +0900376}
377
378fn find_library_path(name: &str) -> Result<String> {
379 let mut watcher = PropertyWatcher::new("ro.product.cpu.abilist")?;
380 let value = watcher.read(|_name, value| Ok(value.trim().to_string()))?;
381 let abi = value.split(',').next().ok_or_else(|| anyhow!("no abilist"))?;
382 let path = format!("/mnt/apk/lib/{}/{}", abi, name);
383
384 let metadata = fs::metadata(&path)?;
385 if !metadata.is_file() {
386 bail!("{} is not a file", &path);
387 }
388
389 Ok(path)
390}
Jiyong Park21ce2c52021-08-28 02:32:17 +0900391
392fn to_hex_string(buf: &[u8]) -> String {
393 buf.iter().map(|b| format!("{:02X}", b)).collect()
394}