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/cs/attachment payload #416

Merged
merged 28 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5bbde0a
Rename plist function
ReagentX Dec 22, 2024
fdf8f61
Move `MAX_LENGTH` constant to app
ReagentX Dec 24, 2024
6b43aeb
Update doc comments
ReagentX Dec 24, 2024
1d38f42
Add `ATTRIBUTION_INFO`
ReagentX Dec 24, 2024
abe2d7a
Add `GetBlob` trait
ReagentX Dec 24, 2024
d73d71e
Add sticker name selector
ReagentX Dec 24, 2024
1a65be5
Add new tests for variant construction
ReagentX Dec 24, 2024
5b7abcc
Use new `parse_balloon_bundle_id` function, use `GetBlob` trait
ReagentX Dec 24, 2024
995486a
Update import
ReagentX Dec 24, 2024
ac6ab6b
Add bundle ID parsing tests
ReagentX Dec 24, 2024
8ad4dde
add `plist_as_dictionary()`
ReagentX Dec 24, 2024
2ccd19c
add `bundle_id` module
ReagentX Dec 24, 2024
aef0fc2
Remove `clone()` call
ReagentX Dec 24, 2024
007e8c4
Create and use `StickerSource`
ReagentX Dec 25, 2024
26a9038
Fix #412 and #413
ReagentX Dec 25, 2024
4ce846e
Add test database
ReagentX Dec 25, 2024
34103b9
Update docs
ReagentX Dec 25, 2024
5bba8a9
Use test db for all test case constructors
ReagentX Dec 25, 2024
9f65caf
Try and run tests
ReagentX Dec 25, 2024
f02d5b5
Set time zones for time tests
ReagentX Dec 25, 2024
a24c429
Use test db; fix null sum
ReagentX Dec 25, 2024
a6de262
Disable tests in pipeline
ReagentX Dec 25, 2024
f6198b1
try to set timezone
ReagentX Dec 25, 2024
852f2cd
actually run tests
ReagentX Dec 25, 2024
27f0455
Disable tests due to tz bug
ReagentX Dec 25, 2024
b3af283
Update sticker comments
ReagentX Dec 27, 2024
2ce082f
Use separate css selector for `genmoji_prompt`s
ReagentX Dec 27, 2024
dfe2a0d
Refactor `StickerSource` into `sticker` module
ReagentX Dec 27, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
jobs:
Test:
runs-on: ubuntu-latest
env:
TZ: PST

steps:
- uses: actions/checkout@v2
Expand Down
26 changes: 13 additions & 13 deletions imessage-database/src/message_types/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl AppMessage<'_> {
mod tests {
use crate::{
message_types::{app::AppMessage, variants::BalloonProvider},
util::plist::parse_plist,
util::plist::parse_ns_keyed_archiver,
};
use plist::Value;
use std::fs::File;
Expand All @@ -102,7 +102,7 @@ mod tests {
.join("test_data/app_message/Sent265.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();
let expected = AppMessage {
Expand All @@ -129,7 +129,7 @@ mod tests {
.join("test_data/app_message/ApplePayRecurring.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();
let expected = AppMessage {
Expand All @@ -156,7 +156,7 @@ mod tests {
.join("test_data/app_message/OpenTableInvited.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();
let expected = AppMessage {
Expand All @@ -183,7 +183,7 @@ mod tests {
.join("test_data/app_message/Slideshow.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();
let expected = AppMessage {
Expand All @@ -210,7 +210,7 @@ mod tests {
.join("test_data/app_message/Game.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();
let expected = AppMessage {
Expand All @@ -237,7 +237,7 @@ mod tests {
.join("test_data/app_message/Business.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();
let expected = AppMessage {
Expand All @@ -264,7 +264,7 @@ mod tests {
.join("test_data/app_message/Business.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();
let mut expected = HashMap::new();
Expand All @@ -282,7 +282,7 @@ mod tests {
.join("test_data/app_message/CheckinTimer.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();

Expand Down Expand Up @@ -310,7 +310,7 @@ mod tests {
.join("test_data/app_message/CheckinLate.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();

Expand Down Expand Up @@ -338,7 +338,7 @@ mod tests {
.join("test_data/app_message/CheckinLocation.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();

Expand Down Expand Up @@ -366,7 +366,7 @@ mod tests {
.join("test_data/app_message/CheckinTimer.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();
let mut expected = HashMap::new();
Expand All @@ -385,7 +385,7 @@ mod tests {
.join("test_data/app_message/FindMy.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppMessage::from_map(&parsed).unwrap();
let expected = AppMessage {
Expand Down
4 changes: 2 additions & 2 deletions imessage-database/src/message_types/app_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<'a> AppStoreMessage<'a> {
mod tests {
use crate::{
message_types::{app_store::AppStoreMessage, variants::BalloonProvider},
util::plist::parse_plist,
util::plist::parse_ns_keyed_archiver,
};
use plist::Value;
use std::env::current_dir;
Expand All @@ -92,7 +92,7 @@ mod tests {
.join("test_data/app_store/AppStoreLink.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = AppStoreMessage::from_map(&parsed).unwrap();
let expected = AppStoreMessage {
Expand Down
4 changes: 2 additions & 2 deletions imessage-database/src/message_types/collaboration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'a> CollaborationMessage<'a> {
mod tests {
use crate::{
message_types::{collaboration::CollaborationMessage, variants::BalloonProvider},
util::plist::parse_plist,
util::plist::parse_ns_keyed_archiver,
};
use plist::Value;
use std::env::current_dir;
Expand All @@ -118,7 +118,7 @@ mod tests {
.join("test_data/collaboration_message/Freeform.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let actual = CollaborationMessage::from_map(&parsed).unwrap();
let expected = CollaborationMessage {
Expand Down
4 changes: 2 additions & 2 deletions imessage-database/src/message_types/music.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a> MusicMessage<'a> {
mod tests {
use crate::{
message_types::{music::MusicMessage, variants::BalloonProvider},
util::plist::parse_plist,
util::plist::parse_ns_keyed_archiver,
};
use plist::Value;
use std::env::current_dir;
Expand All @@ -91,7 +91,7 @@ mod tests {
.join("test_data/music_message/AppleMusic.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = MusicMessage::from_map(&parsed).unwrap();
let expected = MusicMessage {
Expand Down
6 changes: 3 additions & 3 deletions imessage-database/src/message_types/placemark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ mod tests {
placemark::{Placemark, PlacemarkMessage},
variants::BalloonProvider,
},
util::plist::parse_plist,
util::plist::parse_ns_keyed_archiver,
};
use plist::Value;
use std::env::current_dir;
Expand All @@ -151,7 +151,7 @@ mod tests {
.join("test_data/shared_placemark/SharedPlacemark.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = PlacemarkMessage::from_map(&parsed).unwrap();
let expected = PlacemarkMessage {
Expand Down Expand Up @@ -183,7 +183,7 @@ mod tests {
.join("test_data/shared_placemark/SharedPlacemark.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let (placemark_data, _) = PlacemarkMessage::get_body_and_url(&parsed).unwrap();

Expand Down
39 changes: 39 additions & 0 deletions imessage-database/src/message_types/sticker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,52 @@ These are [sticker messages](https://support.apple.com/guide/iphone/send-sticker

use std::fmt::Display;

use crate::util::bundle_id::parse_balloon_bundle_id;

/// Bytes for `stickerEffect:type="`
const STICKER_EFFECT_PREFIX: [u8; 20] = [
115, 116, 105, 99, 107, 101, 114, 69, 102, 102, 101, 99, 116, 58, 116, 121, 112, 101, 61, 34,
];
/// Bytes for `"/>`
const STICKER_EFFECT_SUFFIX: [u8; 3] = [34, 47, 62];

/// Represents the source that created a sticker attachment
#[derive(Debug, PartialEq, Eq)]
pub enum StickerSource {
/// A [Genmoji](https://support.apple.com/guide/iphone/create-genmoji-with-apple-intelligence-iph4e76f5667/ios)
Genmoji,
/// A [Memoji](https://support.apple.com/en-us/111115)
Memoji,
/// User-created stickers
UserGenerated,
/// Application provided stickers
App(String),
}

impl StickerSource {
/// Given an application's bundle ID, determine the source
///
/// # Example
///
/// ```rust
/// use imessage_database::message_types::sticker::StickerSource;;
///
/// println!("{:?}", StickerSource::from_bundle_id("com.apple.messages.genmoji")); // StickerSource::Genmoji
/// ```
pub fn from_bundle_id(bundle_id: &str) -> Option<Self> {
match parse_balloon_bundle_id(Some(bundle_id)) {
Some("com.apple.messages.genmoji") => Some(StickerSource::Genmoji),
Some("com.apple.Animoji.StickersApp.MessagesExtension")
| Some("com.apple.Jellyfish.Animoji") => Some(StickerSource::Memoji),
Some("com.apple.Stickers.UserGenerated.MessagesExtension") => {
Some(StickerSource::UserGenerated)
}
Some(other) => Some(StickerSource::App(other.to_string())),
None => None,
}
}
}

/// Represents different types of [sticker effects](https://www.macrumors.com/how-to/add-effects-to-stickers-in-messages/) that can be applied to sticker iMessage balloons.
#[derive(Debug, PartialEq, Eq)]
pub enum StickerEffect {
Expand Down
22 changes: 11 additions & 11 deletions imessage-database/src/message_types/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a> URLMessage<'a> {
mod url_tests {
use crate::{
message_types::{url::URLMessage, variants::BalloonProvider},
util::plist::parse_plist,
util::plist::parse_ns_keyed_archiver,
};
use plist::Value;
use std::env::current_dir;
Expand All @@ -150,7 +150,7 @@ mod url_tests {
.join("test_data/url_message/URL.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = URLMessage::from_map(&parsed).unwrap();
let expected = URLMessage {
Expand All @@ -176,7 +176,7 @@ mod url_tests {
.join("test_data/url_message/MetadataURL.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = URLMessage::from_map(&parsed).unwrap();
let expected = URLMessage {
Expand Down Expand Up @@ -206,7 +206,7 @@ mod url_tests {
.join("test_data/url_message/Twitter.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = URLMessage::from_map(&parsed).unwrap();
let expected = URLMessage {
Expand Down Expand Up @@ -239,7 +239,7 @@ mod url_tests {
.join("test_data/url_message/Reminder.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = URLMessage::from_map(&parsed).unwrap();
let expected = URLMessage {
Expand Down Expand Up @@ -312,7 +312,7 @@ mod url_tests {
mod url_override_tests {
use crate::{
message_types::{url::URLMessage, variants::URLOverride},
util::plist::parse_plist,
util::plist::parse_ns_keyed_archiver,
};
use plist::Value;
use std::env::current_dir;
Expand All @@ -326,7 +326,7 @@ mod url_override_tests {
.join("test_data/url_message/URL.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = URLMessage::get_url_message_override(&parsed).unwrap();
assert!(matches!(balloon, URLOverride::Normal(_)));
Expand All @@ -340,7 +340,7 @@ mod url_override_tests {
.join("test_data/music_message/AppleMusic.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = URLMessage::get_url_message_override(&parsed).unwrap();
assert!(matches!(balloon, URLOverride::AppleMusic(_)));
Expand All @@ -354,7 +354,7 @@ mod url_override_tests {
.join("test_data/app_store/AppStoreLink.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = URLMessage::get_url_message_override(&parsed).unwrap();
assert!(matches!(balloon, URLOverride::AppStore(_)));
Expand All @@ -368,7 +368,7 @@ mod url_override_tests {
.join("test_data/collaboration_message/Freeform.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = URLMessage::get_url_message_override(&parsed).unwrap();
assert!(matches!(balloon, URLOverride::Collaboration(_)));
Expand All @@ -382,7 +382,7 @@ mod url_override_tests {
.join("test_data/shared_placemark/SharedPlacemark.plist");
let plist_data = File::open(plist_path).unwrap();
let plist = Value::from_reader(plist_data).unwrap();
let parsed = parse_plist(&plist).unwrap();
let parsed = parse_ns_keyed_archiver(&plist).unwrap();

let balloon = URLMessage::get_url_message_override(&parsed).unwrap();
println!("{balloon:?}");
Expand Down
Loading
Loading