Implemented some more native methods
This commit is contained in:
parent
272a34b7cd
commit
aba29af0a3
5 changed files with 198 additions and 6 deletions
|
@ -62,6 +62,24 @@ impl HeapArea {
|
|||
array_ref
|
||||
}
|
||||
|
||||
pub fn decode_java_string(&mut self, string_ref: ObjectReference, class_store: &ClassStore) -> String {
|
||||
let byte_array_reference = self.object_area.get_object_field(string_ref, "value", self.object_area.get_object_class_index(string_ref), class_store).unwrap().expect_reference();
|
||||
let byte_array_length = self.object_area.get_array_length(byte_array_reference);
|
||||
|
||||
let mut utf16_bytes = Vec::with_capacity(byte_array_length / 2);
|
||||
for index in 0..byte_array_length/2 {
|
||||
let i0 = self.object_area.get_array_element(byte_array_reference, (index * 2) as i32).expect_byte();
|
||||
let i1 = self.object_area.get_array_element(byte_array_reference, (index * 2 + 1) as i32).expect_byte();
|
||||
|
||||
let u0 = u8::from_ne_bytes(i0.to_ne_bytes());
|
||||
let u1 = u8::from_ne_bytes(i1.to_ne_bytes());
|
||||
|
||||
utf16_bytes.push(u16::from_ne_bytes([u0, u1]));
|
||||
}
|
||||
|
||||
String::from_utf16(&utf16_bytes).unwrap()
|
||||
}
|
||||
|
||||
pub fn make_handmade_string(&mut self, s: &String, class_store: &ClassStore) -> ObjectReference {
|
||||
let utf16_bytes = {
|
||||
let utf16 = s.encode_utf16();
|
||||
|
@ -713,6 +731,20 @@ impl FieldValue {
|
|||
}
|
||||
}
|
||||
|
||||
fn expect_reference(&self) -> ObjectReference {
|
||||
match self {
|
||||
Self::Reference(r) => *r,
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
fn expect_byte(&self) -> i8 {
|
||||
match self {
|
||||
Self::Byte(b) => *b,
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
fn default_for(t: &AbstractTypeDescription) -> Self {
|
||||
if t.array_level != 0 {
|
||||
return Self::Reference(ObjectReference::NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue