Skip to content
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
57 changes: 47 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sunlight"
version = "0.1.5"
version = "0.2.0"
edition = "2024"
license = "MIT"
repository = "https://github.com/puffyCid/sunlight"
Expand All @@ -10,6 +10,6 @@ keywords = ["forensics"]
[dependencies]
nom = "8.0.0"
serde = { version = "1.0.228", features = ["derive"] }
log = "0.4.29"
tracing = "0.1.44"
serde_json = "1.0.149"
base64 = "0.22.1"
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
clippy::dbg_macro,
clippy::debug_assert_with_mut_call,
clippy::doc_markdown,
clippy::empty_enum,
clippy::empty_enums,
clippy::enum_glob_use,
clippy::exit,
clippy::expl_impl_clone_on_copy,
Expand Down
7 changes: 5 additions & 2 deletions src/light.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{error::SunlightError, tags::parser::parse_tag};
use log::error;
use serde::Serialize;
use serde_json::Value;
use std::collections::HashMap;
use tracing::{Level, event};

#[derive(Debug, Serialize)]
pub struct ProtoTag {
Expand Down Expand Up @@ -76,7 +76,10 @@ pub fn extract_protobuf(data: &[u8]) -> Result<HashMap<usize, ProtoTag>, Sunligh
let proto_map = match proto_result {
Ok((_, results)) => results,
Err(err) => {
error!("[sunlight] could not parse provided protobuf bytes: {err:?}");
event!(
Level::ERROR,
"[sunlight] could not parse provided protobuf bytes: {err:?}"
);
return Err(SunlightError::Parser);
}
};
Expand Down
11 changes: 7 additions & 4 deletions src/tags/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::{
},
utils::encoding::base64_encode_standard,
};
use log::warn;
use serde_json::Value;
use std::collections::HashMap;
use tracing::{Level, event};

/// Extract the Protobuf values from the provided data
pub(crate) fn parse_tag(data: &[u8]) -> nom::IResult<&[u8], HashMap<usize, ProtoTag>> {
Expand All @@ -24,20 +24,23 @@ pub(crate) fn parse_tag(data: &[u8]) -> nom::IResult<&[u8], HashMap<usize, Proto
WireType::Fixed64 => parse_fixed64(input)?,
WireType::Len => parse_length_tag(input)?,
WireType::StartGroup => {
warn!(
event!(
Level::WARN,
"[sunlight] got start group wiretype. This is deprecated, ending parsing now. Returning base64 as final result"
);
([].as_slice(), Value::String(base64_encode_standard(input)))
}
WireType::EndGroup => {
warn!(
event!(
Level::WARN,
"[sunlight] got end group wiretype. This is deprecated, ending parsing now. Returning base64 as final result"
);
([].as_slice(), Value::String(base64_encode_standard(input)))
}
WireType::Fixed32 => parse_fixed32(input)?,
WireType::Unknown => {
warn!(
event!(
Level::WARN,
"[sunlight] got unknown wire type. Protobuf data may be corrupted or this is not protobuf data, ending parsing now. Returning base64 as final result"
);
([].as_slice(), Value::String(base64_encode_standard(input)))
Expand Down
7 changes: 5 additions & 2 deletions src/utils/strings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::utils::encoding::base64_encode_standard;
use log::warn;
use tracing::{Level, event};

/// Get a UTF8 string from provided bytes data. Invalid UTF8 is base64 encoded. Use `extract_uf8_string_lossy` if replacing bytes is acceptable
pub(crate) fn extract_utf8_string(data: &[u8]) -> String {
let utf8_result = String::from_utf8(data.to_vec());
match utf8_result {
Ok(result) => result.trim_end_matches('\0').to_string(),
Err(err) => {
warn!("Failed to get UTF8 string for Protobuf: {err:?}");
event!(
Level::WARN,
"Failed to get UTF8 string for Protobuf: {err:?}"
);
let max_size = 2097152;
let issue = if data.len() < max_size {
base64_encode_standard(data)
Expand Down
Loading