Skip to content

Commit 384ce46

Browse files
authored
feature/validation (#35)
In order to test and verify our modification framework, the validation framework has been unified and greatly extended
1 parent 36f50ba commit 384ce46

File tree

311 files changed

+36454
-17090
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

311 files changed

+36454
-17090
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1919
[dependencies]
2020
thiserror = "2.0.12"
2121
uguid = "2.2.1"
22-
widestring = "1.1.0"
22+
widestring = "1.2.0"
2323
strum = { version = "0.27.1", features = ["derive"]}
2424
memmap2 = "0.9.7"
2525
tempfile = "3.13.0"
@@ -29,7 +29,7 @@ goblin = { version = "0.10.0", git= "https://github.com/BinFlip/goblin.git", bra
2929
ouroboros = "0.18.5"
3030
sha1 = "0.10.6"
3131
md-5 = "0.10.6"
32-
bitflags = "2.9.0"
32+
bitflags = "2.9.1"
3333
dashmap = "6.1.0"
3434
crossbeam-skiplist = "0.1.3"
3535
rayon = "1.10.0"

benches/cilassemblyview.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
extern crate dotscope;
33

44
use criterion::{criterion_group, criterion_main, Criterion};
5-
use dotscope::CilAssemblyView;
5+
use dotscope::{CilAssemblyView, ValidationConfig};
66
use std::path::{Path, PathBuf};
77

88
pub fn criterion_benchmark(c: &mut Criterion) {
@@ -16,6 +16,15 @@ pub fn criterion_benchmark(c: &mut Criterion) {
1616
c.bench_function("bench_cilassemblyview", |b| {
1717
b.iter({ || CilAssemblyView::from_file(&path).unwrap() });
1818
});
19+
20+
c.bench_function("bench_cilassemblyview_validation", |b| {
21+
b.iter({
22+
|| {
23+
CilAssemblyView::from_file_with_validation(&path, ValidationConfig::strict())
24+
.unwrap()
25+
}
26+
});
27+
});
1928
}
2029

2130
criterion_group!(benches, criterion_benchmark);

benches/cilobject.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
extern crate dotscope;
33

44
use criterion::{criterion_group, criterion_main, Criterion};
5-
use dotscope::metadata::cilobject::CilObject;
5+
use dotscope::{metadata::cilobject::CilObject, ValidationConfig};
66
use std::path::{Path, PathBuf};
77

88
pub fn criterion_benchmark(c: &mut Criterion) {
@@ -16,6 +16,12 @@ pub fn criterion_benchmark(c: &mut Criterion) {
1616
c.bench_function("bench_cilobject", |b| {
1717
b.iter({ || CilObject::from_file(&path).unwrap() });
1818
});
19+
20+
c.bench_function("bench_cilobject_validation", |b| {
21+
b.iter({
22+
|| CilObject::from_file_with_validation(&path, ValidationConfig::strict()).unwrap()
23+
});
24+
});
1925
}
2026

2127
criterion_group!(benches, criterion_benchmark);

examples/modify.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2323
use dotscope::{
2424
metadata::{
25-
tables::{CodedIndex, TableDataOwned, TableId, TypeDefRaw},
25+
tables::{CodedIndex, CodedIndexType, TableDataOwned, TableId, TypeDefRaw},
2626
token::Token,
2727
},
2828
prelude::*,
@@ -86,9 +86,9 @@ fn main() -> Result<()> {
8686

8787
// Add strings to the string heap
8888
println!("📝 Adding strings to #Strings heap...");
89-
let hello_index = assembly.add_string("Hello from modified assembly!")?;
90-
let debug_index = assembly.add_string("DEBUG_MODIFIED")?;
91-
let version_index = assembly.add_string("v2.0.0-modified")?;
89+
let hello_index = assembly.string_add("Hello from modified assembly!")?;
90+
let debug_index = assembly.string_add("DEBUG_MODIFIED")?;
91+
let version_index = assembly.string_add("v2.0.0-modified")?;
9292
println!(" ✅ Added 'Hello from modified assembly!' at index {hello_index}");
9393
println!(" ✅ Added 'DEBUG_MODIFIED' at index {debug_index}");
9494
println!(" ✅ Added 'v2.0.0-modified' at index {version_index}");
@@ -97,8 +97,8 @@ fn main() -> Result<()> {
9797
println!("📦 Adding blobs to #Blob heap...");
9898
let signature_blob = vec![0x07, 0x01, 0x0E]; // Sample method signature blob
9999
let custom_data_blob = vec![0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE];
100-
let signature_index = assembly.add_blob(&signature_blob)?;
101-
let custom_data_index = assembly.add_blob(&custom_data_blob)?;
100+
let signature_index = assembly.blob_add(&signature_blob)?;
101+
let custom_data_index = assembly.blob_add(&custom_data_blob)?;
102102
println!(" ✅ Added method signature blob at index {signature_index}");
103103
println!(" ✅ Added custom data blob at index {custom_data_index}");
104104

@@ -112,24 +112,24 @@ fn main() -> Result<()> {
112112
0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0x07, 0x18, 0x29, 0x3A, 0x4B, 0x5C, 0x6D, 0x7E, 0x8F,
113113
0x90,
114114
];
115-
let module_guid_index = assembly.add_guid(&module_guid)?;
116-
let type_guid_index = assembly.add_guid(&type_guid)?;
115+
let module_guid_index = assembly.guid_add(&module_guid)?;
116+
let type_guid_index = assembly.guid_add(&type_guid)?;
117117
println!(" ✅ Added module GUID at index {module_guid_index}");
118118
println!(" ✅ Added type GUID at index {type_guid_index}");
119119

120120
// Add user strings to the user string heap
121121
println!("💭 Adding user strings to #US heap...");
122-
let user_message = assembly.add_userstring("This assembly has been modified!")?;
123-
let user_warning = assembly.add_userstring("⚠️ MODIFIED ASSEMBLY")?;
122+
let user_message = assembly.userstring_add("This assembly has been modified!")?;
123+
let user_warning = assembly.userstring_add("⚠️ MODIFIED ASSEMBLY")?;
124124
println!(" ✅ Added user message at index {user_message}");
125125
println!(" ✅ Added user warning at index {user_warning}");
126126

127127
// Demonstrate heap modifications
128128
println!("✏️ Updating existing heap content...");
129129
// Note: In a real scenario, you would know the indices of existing content
130130
// For demonstration, we'll update our newly added strings
131-
assembly.update_string(debug_index, "RELEASE_MODIFIED")?;
132-
assembly.update_blob(custom_data_index, &[0xFF, 0xEE, 0xDD, 0xCC])?;
131+
assembly.string_update(debug_index, "RELEASE_MODIFIED")?;
132+
assembly.blob_update(custom_data_index, &[0xFF, 0xEE, 0xDD, 0xCC])?;
133133
println!(" ✅ Updated debug string to 'RELEASE_MODIFIED'");
134134
println!(" ✅ Updated custom data blob");
135135
println!();
@@ -180,17 +180,13 @@ fn main() -> Result<()> {
180180
flags: 0x00100001, // Class, Public
181181
type_name: debug_index, // Reference to our added string
182182
type_namespace: 0, // No namespace (root)
183-
extends: CodedIndex {
184-
tag: TableId::TypeRef,
185-
row: 1, // Typically System.Object
186-
token: Token::new(0x01000001),
187-
},
183+
extends: CodedIndex::new(TableId::TypeRef, 1, CodedIndexType::TypeDefOrRef),
188184
field_list: 1, // Start of field list
189185
method_list: 1, // Start of method list
190186
};
191187

192188
let new_typedef_rid =
193-
assembly.add_table_row(TableId::TypeDef, TableDataOwned::TypeDef(new_typedef))?;
189+
assembly.table_row_add(TableId::TypeDef, TableDataOwned::TypeDef(new_typedef))?;
194190
println!(" ✅ Added new TypeDef row with RID {new_typedef_rid}");
195191

196192
// Update an existing table row (if any exist)
@@ -204,7 +200,7 @@ fn main() -> Result<()> {
204200
let mut modified_row = first_row.clone();
205201
modified_row.type_name = version_index; // Point to our version string
206202

207-
assembly.update_table_row(
203+
assembly.table_row_update(
208204
TableId::TypeDef,
209205
1,
210206
TableDataOwned::TypeDef(modified_row),
@@ -219,7 +215,7 @@ fn main() -> Result<()> {
219215
println!("🗑️ Demonstrating table row deletion...");
220216
// Note: Be very careful with deletions as they can break assembly integrity
221217
// For safety, we'll only delete the row we just added
222-
assembly.delete_table_row(
218+
assembly.table_row_remove(
223219
TableId::TypeDef,
224220
new_typedef_rid,
225221
ReferenceHandlingStrategy::FailIfReferenced,

0 commit comments

Comments
 (0)