-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(classification): add semantic pattern matching for GUID, email, base64, format strings, and user agents #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
574f562
6b6ffb2
771852a
9b7789d
8cb6ee8
e1aa897
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # This is an example .goreleaser.yml file with some sensible defaults. | ||
| # Make sure to check the documentation at https://goreleaser.com | ||
|
|
||
| # The lines below are called `modelines`. See `:help modeline` | ||
| # Feel free to remove those if you don't want/need to use them. | ||
| # yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
| # vim: set ts=2 sw=2 tw=0 fo=cnqoj | ||
|
|
||
| version: 2 | ||
|
|
||
| before: | ||
| hooks: | ||
| # Ensure cargo-zigbuild is available for cross-compilation | ||
| # Note: rustup toolchain is pinned via rust-toolchain.toml | ||
| - cargo install --locked cargo-zigbuild | ||
| - cargo fetch --locked | ||
|
|
||
| builds: | ||
| # macOS targets - use regular cargo (zigbuild has issues with macOS linker flags) | ||
| - builder: rust | ||
| id: darwin | ||
| command: build | ||
| flags: | ||
| - --release | ||
| targets: | ||
| - x86_64-apple-darwin | ||
| - aarch64-apple-darwin | ||
|
|
||
| # Linux/Windows targets - use cargo-zigbuild for cross-compilation | ||
| - builder: rust | ||
| id: cross | ||
| command: zigbuild | ||
| flags: | ||
| - --release | ||
| targets: | ||
| - x86_64-unknown-linux-gnu | ||
| - aarch64-unknown-linux-gnu | ||
| - x86_64-pc-windows-gnu | ||
|
|
||
| archives: | ||
| - formats: [tar.gz] | ||
| # this name template makes the OS and Arch compatible with the results of `uname`. | ||
| name_template: >- | ||
| {{ .ProjectName }}_ | ||
| {{- title .Os }}_ | ||
| {{- if eq .Arch "amd64" }}x86_64 | ||
| {{- else if eq .Arch "386" }}i386 | ||
| {{- else }}{{ .Arch }}{{ end }} | ||
| # use zip for windows archives | ||
| format_overrides: | ||
| - goos: windows | ||
| formats: [zip] | ||
|
|
||
| changelog: | ||
| sort: asc | ||
| filters: | ||
| exclude: | ||
| - "^docs:" | ||
| - "^test:" | ||
|
|
||
| release: | ||
| footer: >- | ||
|
|
||
| --- | ||
|
|
||
| Released by [GoReleaser](https://github.com/goreleaser/goreleaser). |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,136 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use criterion::{Criterion, criterion_group, criterion_main}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::hint::black_box; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use stringy::classification::SemanticClassifier; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use stringy::types::{BinaryFormat, Encoding, SectionType, StringContext, StringSource}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn make_context() -> StringContext { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StringContext::new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SectionType::StringData, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BinaryFormat::Elf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Encoding::Ascii, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StringSource::SectionData, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .with_section_name(".rodata".to_string()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn bench_classifier_construction(c: &mut Criterion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c.bench_function("classification_classifier_construction", |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = SemanticClassifier::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn bench_guid_classification(c: &mut Criterion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let classifier = SemanticClassifier::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let context = make_context(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let guid = "{12345678-1234-1234-1234-123456789abc}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c.bench_function("classification_guid", |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = classifier.classify(black_box(guid), &context); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn bench_email_classification(c: &mut Criterion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let classifier = SemanticClassifier::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let context = make_context(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let email = "user.name+tag@example.co.uk"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c.bench_function("classification_email", |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = classifier.classify(black_box(email), &context); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn bench_base64_classification(c: &mut Criterion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let classifier = SemanticClassifier::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let context = make_context(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let base64 = "U29tZSBsb25nZXIgYmFzZTY0IHN0cmluZw=="; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c.bench_function("classification_base64", |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = classifier.classify(black_box(base64), &context); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn bench_format_string_classification(c: &mut Criterion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let classifier = SemanticClassifier::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let context = make_context(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let format_string = "Error: %s at line %d"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c.bench_function("classification_format_string", |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = classifier.classify(black_box(format_string), &context); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn bench_user_agent_classification(c: &mut Criterion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let classifier = SemanticClassifier::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let context = make_context(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c.bench_function("classification_user_agent", |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = classifier.classify(black_box(user_agent), &context); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn bench_batch_classification(c: &mut Criterion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let classifier = SemanticClassifier::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let context = make_context(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut samples = Vec::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for index in 0..1000 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| samples.push(format!("{{12345678-1234-1234-1234-{:012x}}}", index)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| samples.push(format!("user{}@example.com", index)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| samples.push(format!("Error %s at line {}", index)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c.bench_function("classification_batch", |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for sample in &samples { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = classifier.classify(black_box(sample.as_str()), &context); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+84
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Batch sample misses a format-string match. "Error %s at line {}" uses {} which does not match the documented format-string patterns that rely on % specifiers or {digits}. This reduces the intended mix of categories in the batch set. Proposed fix- samples.push(format!("Error %s at line {}", index));
+ samples.push(format!("Error %s at line %d {}", index));📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn bench_worst_case(c: &mut Criterion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let classifier = SemanticClassifier::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let context = make_context(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let worst_case = "x9qz1p0t8v7w6r5y4u3i2o1p-"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c.bench_function("classification_worst_case", |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = classifier.classify(black_box(worst_case), &context); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn bench_context_creation(c: &mut Criterion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c.bench_function("classification_context_creation", |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let _ = make_context(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| criterion_group!( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| classification_benches, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bench_classifier_construction, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bench_guid_classification, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bench_email_classification, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bench_base64_classification, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bench_format_string_classification, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bench_user_agent_classification, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bench_batch_classification, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bench_worst_case, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bench_context_creation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| criterion_main!(classification_benches); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix MD036 by using a heading instead of bold text.
Markdownlint reports emphasis used as a heading. Convert the bold label to a heading or list item.
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents