java_asm_server/
lib.rs

1use crate::impls::apk_load::ApkAccessor;
2use enum_dispatch::enum_dispatch;
3use java_asm::smali::SmaliNode;
4use java_asm::{DescriptorRef, StrRef};
5use parking_lot::Mutex;
6use std::sync::Arc;
7
8pub mod server;
9
10pub(crate) mod impls;
11pub mod ui;
12
13// the server contains all information for single opened file.
14#[derive(Clone)]
15pub struct AsmServer {
16    pub loading_state: LoadingState,
17    // when in loading state, the accessor is None.
18    pub accessor: AccessorMut,
19}
20
21pub type ServerMut = Arc<Mutex<Option<AsmServer>>>;
22type AccessorMut = Arc<Mutex<Option<AccessorEnum>>>;
23
24#[derive(Default, Clone, Debug)]
25pub struct LoadingState {
26    pub in_loading: bool,
27    // file loading progress, 0.0 ~ 1.0
28    pub loading_progress: f32,
29    // when loading failed, the error will be set.
30    pub err: Option<String>,
31}
32
33#[enum_dispatch]
34pub enum AccessorEnum {
35    Apk(ApkAccessor),
36}
37
38#[enum_dispatch(AccessorEnum)]
39pub trait Accessor {
40    fn read_classes(&self) -> Vec<StrRef>;
41    fn exist_class(&self, class_key: &str) -> bool;
42    fn read_content(&self, class_key: &str) -> Option<SmaliNode>;
43}
44
45pub struct MethodMeta {
46    pub class_key: StrRef,
47    pub name: StrRef,
48    pub descriptor: DescriptorRef,
49}
50
51pub struct FieldMeta {
52    pub class_key: StrRef,
53    pub name: StrRef,
54}
55