Skip to content

Commit 9866243

Browse files
authored
Merge pull request #42 from emilycares/dynamic_constant
Add DynamicConstant
2 parents 075abc3 + df6b50d commit 9866243

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/constant_info/parser.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ fn const_method_type(input: &[u8]) -> ConstantInfoResult<'_> {
119119
))
120120
}
121121

122+
fn const_dynamic(input: &[u8]) -> ConstantInfoResult<'_> {
123+
let (input, bootstrap_method_attr_index) = be_u16(input)?;
124+
let (input, name_and_type_index) = be_u16(input)?;
125+
Ok((
126+
input,
127+
ConstantInfo::Dynamic(DynamicConstant {
128+
bootstrap_method_attr_index,
129+
name_and_type_index,
130+
}),
131+
))
132+
}
133+
122134
fn const_invoke_dynamic(input: &[u8]) -> ConstantInfoResult<'_> {
123135
let (input, bootstrap_method_attr_index) = be_u16(input)?;
124136
let (input, name_and_type_index) = be_u16(input)?;
@@ -159,6 +171,7 @@ fn const_block_parser(input: &[u8], const_type: u8) -> ConstantInfoResult<'_> {
159171
12 => const_name_and_type(input),
160172
15 => const_method_handle(input),
161173
16 => const_method_type(input),
174+
17 => const_dynamic(input),
162175
18 => const_invoke_dynamic(input),
163176
19 => const_module(input),
164177
20 => const_package(input),

src/constant_info/types.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub enum ConstantInfo {
1616
NameAndType(NameAndTypeConstant),
1717
MethodHandle(MethodHandleConstant),
1818
MethodType(MethodTypeConstant),
19+
Dynamic(DynamicConstant),
1920
InvokeDynamic(InvokeDynamicConstant),
2021
Module(ModuleConstant),
2122
Package(PackageConstant),
@@ -106,6 +107,13 @@ pub struct MethodTypeConstant {
106107
pub descriptor_index: u16,
107108
}
108109

110+
#[derive(Clone, Debug)]
111+
#[binrw]
112+
pub struct DynamicConstant {
113+
pub bootstrap_method_attr_index: u16,
114+
pub name_and_type_index: u16,
115+
}
116+
109117
#[derive(Clone, Debug)]
110118
#[binrw]
111119
pub struct InvokeDynamicConstant {

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn class_parser(input: &[u8]) -> IResult<&[u8], ClassFile> {
3434
let (input, minor_version) = be_u16(input)?;
3535
let (input, major_version) = be_u16(input)?;
3636
let (input, const_pool_size) = be_u16(input)?;
37-
let (input, const_pool) = constant_parser(input, (const_pool_size - 1) as usize)?;
37+
let (input, const_pool) = constant_parser(input, (const_pool_size.saturating_sub(1)) as usize)?;
3838
let (input, access_flags) = be_u16(input)?;
3939
let (input, this_class) = be_u16(input)?;
4040
let (input, super_class) = be_u16(input)?;

0 commit comments

Comments
 (0)