-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_plugin.rs
58 lines (48 loc) · 2.19 KB
/
example_plugin.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use dotenv::dotenv;
use abi_stable::{export_root_module, prefix_type::PrefixTypeTrait, rvec, sabi_extern_fn, sabi_trait::prelude::TU_Opaque, std_types::{RString, RVec}};
use eframework::{analysis_framework::{AnalysisModule, AnalysisModuleBox, AnalysisModule_TO, Dependency, ModuleInfo, Plugin, Plugin_Ref}, rversion::RVersion, rversion_req::RVersionReq};
use diesel::{Connection, RunQueryDsl, pg::PgConnection};
embed_migrations!();//Embed our Diesel migrations into this crate so we can run them upon beginning analysis later.
#[export_root_module]
pub fn get_library() -> Plugin_Ref {
Plugin {
get_analyzer,
}.leak_into_prefix()
}
#[sabi_extern_fn]
pub fn get_analyzer() -> AnalysisModuleBox {
AnalysisModule_TO::from_value(ExampleModule {}, TU_Opaque)
}
pub struct ExampleModule { }
impl AnalysisModule for ExampleModule {
fn get_info(&self) -> eframework::analysis_framework::ModuleInfo {
return ModuleInfo {
name: RString::from("ExamplePluginName"),
version: RVersion::new(0, 1, 0),
dependencies: rvec![
Dependency
{
name: RString::from("PCapParser"), //Base plugin for most if not all plugins.
version_requirement: RVersionReq {
minimum_version: RVersion::new(0, 1, 0),
maximum_version: RVersion::new(1, 0, 0)
}
}
]
}
}
fn analyze(&self, pcap_input_directory: &RString, connection_string: &RString) {
println!("Starting the example plugin!");
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let connection: PgConnection = PgConnection::establish(&connection_string)
.expect(&format!("Error connecting to {}", database_url));
//Run our embedded Diesel migrations
let migration_result = embedded_migrations::run(&connection);
if migration_result.is_err() {
println!("An error occurred while running migrations: {}", migration_result.err().unwrap());
return;
}
//Do some packet analysis...
}
}