From 15109b2b684fae0e6db9ada29161e88bac56740f Mon Sep 17 00:00:00 2001 From: Sculas Date: Sat, 22 Apr 2023 22:15:59 +0200 Subject: [PATCH] feat: implement hidden api restriction flags --- src/raw/hiddenapi.rs | 33 +++++++++++++++++++++++++++++++++ src/raw/mod.rs | 1 + 2 files changed, 34 insertions(+) create mode 100644 src/raw/hiddenapi.rs diff --git a/src/raw/hiddenapi.rs b/src/raw/hiddenapi.rs new file mode 100644 index 0000000..a127d34 --- /dev/null +++ b/src/raw/hiddenapi.rs @@ -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 { + 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(()) + } +} diff --git a/src/raw/mod.rs b/src/raw/mod.rs index d5a8484..2fd0f11 100644 --- a/src/raw/mod.rs +++ b/src/raw/mod.rs @@ -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.