update rust edition of androscalpel

This commit is contained in:
Jean-Marie Mineau 2025-04-18 11:12:11 +02:00
parent d4ccc73362
commit 218d6bf6fc
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
20 changed files with 223 additions and 167 deletions

View file

@ -390,7 +390,9 @@ mod test {
fn serialize_u64() {
assert_eq!(
0x123456789ABCDEF0u64.serialize_to_vec().unwrap(),
vec![0xF0u8, 0xDEu8, 0xBCu8, 0x9Au8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]
vec![
0xF0u8, 0xDEu8, 0xBCu8, 0x9Au8, 0x78u8, 0x56u8, 0x34u8, 0x12u8
]
);
}

View file

@ -357,26 +357,34 @@ mod test {
/// Test for bug found in <https://github.com/TkTech/mutf8/tree/master>:
#[test]
fn test_tktech_bad_mutf8() {
assert!(TryInto::<String>::try_into(StringDataItem {
utf16_size: Uleb128(0),
data: vec![0x00]
})
.is_err());
assert!(TryInto::<String>::try_into(StringDataItem {
utf16_size: Uleb128(0),
data: vec![0xC2]
})
.is_err());
assert!(TryInto::<String>::try_into(StringDataItem {
utf16_size: Uleb128(0),
data: vec![0xED]
})
.is_err());
assert!(TryInto::<String>::try_into(StringDataItem {
utf16_size: Uleb128(0),
data: vec![0xE2]
})
.is_err());
assert!(
TryInto::<String>::try_into(StringDataItem {
utf16_size: Uleb128(0),
data: vec![0x00]
})
.is_err()
);
assert!(
TryInto::<String>::try_into(StringDataItem {
utf16_size: Uleb128(0),
data: vec![0xC2]
})
.is_err()
);
assert!(
TryInto::<String>::try_into(StringDataItem {
utf16_size: Uleb128(0),
data: vec![0xED]
})
.is_err()
);
assert!(
TryInto::<String>::try_into(StringDataItem {
utf16_size: Uleb128(0),
data: vec![0xE2]
})
.is_err()
);
}
/// Test from <https://github.com/TkTech/mutf8/tree/master>, test 2 bytes

View file

@ -2,7 +2,7 @@
use crate as androscalpel_serializer;
use crate::{
Error, ReadSeek, Result, Serializable, SerializableUntil, Sleb128, Uleb128, Uleb128p1, NO_INDEX,
Error, NO_INDEX, ReadSeek, Result, Serializable, SerializableUntil, Sleb128, Uleb128, Uleb128p1,
};
use std::io::Write;

View file

@ -270,7 +270,7 @@ impl<'a> DexFileReader<'a> {
MapItemType::HeaderItem if item.offset != 0 || item.size != 1 => {
return Err(Error::InconsistantStruct(format!(
"Inconsistant Header Mapping info found in map_list: {item:x?}"
)))
)));
}
MapItemType::StringIdItem
if item.offset != self.header.string_ids_off
@ -280,7 +280,7 @@ impl<'a> DexFileReader<'a> {
"Inconsistant MapList Mapping info found in map_list: {item:x?}, \
header.string_ids_off: 0x{:x}, header.string_ids_size: {}",
self.header.string_ids_off, self.header.string_ids_size
)))
)));
}
MapItemType::TypeIdItem
if item.offset != self.header.type_ids_off
@ -290,7 +290,7 @@ impl<'a> DexFileReader<'a> {
"Inconsistant MapList Mapping info found in map_list: {item:x?}, \
header.type_ids_off: 0x{:x}, header.type_ids_size: {}",
self.header.type_ids_off, self.header.type_ids_size
)))
)));
}
MapItemType::ProtoIdItem
if item.offset != self.header.proto_ids_off
@ -300,7 +300,7 @@ impl<'a> DexFileReader<'a> {
"Inconsistant MapList Mapping info found in map_list: {item:x?}, \
header.proto_ids_off: 0x{:x}, header.proto_ids_size: {}",
self.header.proto_ids_off, self.header.proto_ids_size
)))
)));
}
MapItemType::FieldIdItem
if item.offset != self.header.field_ids_off
@ -310,7 +310,7 @@ impl<'a> DexFileReader<'a> {
"Inconsistant MapList Mapping info found in map_list: {item:x?}, \
header.field_ids_off: 0x{:x}, header.field_ids_size: {}",
self.header.field_ids_off, self.header.field_ids_size
)))
)));
}
MapItemType::MethodIdItem
if item.offset != self.header.method_ids_off
@ -320,7 +320,7 @@ impl<'a> DexFileReader<'a> {
"Inconsistant MapList Mapping info found in map_list: {item:x?}, \
header.method_ids_off: 0x{:x}, header.method_ids_size: {}",
self.header.method_ids_off, self.header.method_ids_size
)))
)));
}
MapItemType::ClassDefItem
if item.offset != self.header.class_defs_off
@ -330,14 +330,14 @@ impl<'a> DexFileReader<'a> {
"Inconsistant MapList Mapping info found in map_list: {item:x?}, \
header.class_defs_off: 0x{:x}, header.class_defs_size: {}",
self.header.class_defs_off, self.header.class_defs_size
)))
)));
}
MapItemType::MapList if item.offset != self.header.map_off || item.size != 1 => {
return Err(Error::InconsistantStruct(format!(
"Inconsistant MapList Mapping info found in map_list: {item:x?}, \
header.map_list_off: 0x{:x}",
self.header.map_off
)))
)));
}
/*
MapItemType::CallSiteIdItem => todo!(),

View file

@ -977,7 +977,9 @@ mod test {
}
.serialize_to_vec()
.unwrap(),
vec![0x03, 0xb4, 0x01, 0x80, 0x02, 0xc7, 0x08, 0x8e, 0x02, 0xd9, 0x09, 0x87, 0x02,]
vec![
0x03, 0xb4, 0x01, 0x80, 0x02, 0xc7, 0x08, 0x8e, 0x02, 0xd9, 0x09, 0x87, 0x02,
]
);
assert_eq!(
EncodedCatchHandler {
@ -999,7 +1001,9 @@ mod test {
}
.serialize_to_vec()
.unwrap(),
vec![0x03, 0xe9, 0x46, 0x56, 0xc7, 0x08, 0x8e, 0x02, 0xd9, 0x09, 0x87, 0x02,]
vec![
0x03, 0xe9, 0x46, 0x56, 0xc7, 0x08, 0x8e, 0x02, 0xd9, 0x09, 0x87, 0x02,
]
);
assert_eq!(
EncodedCatchHandler {