Skip to content
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

feat: add function to convert from proto to custom module type #63

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions convert/src/from_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use crate::*;
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use crate::types::Audit;

#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use chrono::offset::TimeZone;

use modsurfer_module::{Export, Function, FunctionType, Import, ValType};

pub fn source_language(src: api::SourceLanguage) -> SourceLanguage {
Expand Down Expand Up @@ -90,6 +93,30 @@ pub fn exports(exports: Vec<api::Export>) -> Vec<Export> {
exports.into_iter().map(export).collect()
}

pub fn module(module: &modsurfer_proto_v1::api::Module) -> modsurfer_module::Module {
let modsurfer_module = &mut modsurfer_module::Module {
hash: module.hash.clone(),
imports: imports(module.imports.clone()),
exports: exports(module.exports.clone()),
size: module.size,
location: module.location.clone(),
source_language: source_language(module.source_language.enum_value_or_default()),
metadata: Some(module.metadata.clone()),
strings: module.strings.clone(),
complexity: module.complexity,
graph: module.graph.clone(),
function_hashes: module.function_hashes.clone(),
#[cfg(not(target_arch = "wasm32"))]
inserted_at: chrono::DateTime::from(
chrono::Utc.timestamp_nanos(module.inserted_at.nanos as i64),
),
#[cfg(target_arch = "wasm32")]
inserted_at: module.inserted_at.nanos as u64,
};

return modsurfer_module.clone();
}

#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub fn search(mut req: api::SearchModulesRequest) -> Search {
Search {
Expand Down
2 changes: 1 addition & 1 deletion validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{collections::BTreeMap, fmt::Display, process::ExitCode};
use comfy_table::{modifiers::UTF8_SOLID_INNER_BORDERS, presets::UTF8_FULL, Row, Table};
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use extism::{Context, Plugin};
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]

use modsurfer_convert::from_api;

use anyhow::Result;
Expand Down