Skip to content

Commit

Permalink
feat: implement hidden api restriction flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Sculas committed Apr 22, 2023
1 parent 0d24926 commit 15109b2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/raw/hiddenapi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::raw::uleb128;

bitflags::bitflags! {
/// For more information, click [here][1].
///
/// [1]: https://source.android.com/docs/core/runtime/dex-format#hiddenapi-class-data-item
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RestrictionFlag: u64 {
const Whitelist = 0;
const Greylist = 1;
const Blacklist = 2;
const GreylistMaxO = 3;
const GreylistMaxP = 4;
const GreylistMaxQ = 5;
const GreylistMaxR = 6;
}
}

impl RestrictionFlag {
pub fn try_from_uleb128(src: &[u8], offset: &mut usize) -> Result<Self, scroll::Error> {
let flags = uleb128::read(src, offset)?;
Ok(RestrictionFlag::from_bits_truncate(flags))
}

pub fn try_into_uleb128(
&self,
dst: &mut [u8],
offset: &mut usize,
) -> Result<(), scroll::Error> {
uleb128::write(dst, offset, self.bits())?;
Ok(())
}
}
1 change: 1 addition & 0 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod code_item;
pub mod encoded_value;
pub mod flags;
pub mod header;
pub mod hiddenapi;
pub mod map_list;
pub mod method_handle;
/// Simple, small types that don't need their own module.
Expand Down

0 comments on commit 15109b2

Please sign in to comment.