Skip to content

Commit

Permalink
feat: impl hex extension
Browse files Browse the repository at this point in the history
  • Loading branch information
pk5ls20 committed Mar 4, 2025
1 parent c37231c commit a22cf9c
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 58 deletions.
1 change: 1 addition & 0 deletions mania/src/core/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub(crate) mod prelude {
PacketBuilder, PacketError, PacketReader, PacketType,
};
pub use crate::dda;
pub use crate::utility::extensions::HexString;
pub use bytes::Bytes;
pub use inventory;
pub use mania_macros::{DummyEvent, ServerEvent, command, oidb_command};
Expand Down
2 changes: 1 addition & 1 deletion mania/src/core/event/message/file_group_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl ClientEvent for FileGroupDownloadEvent {
let url = format!(
"https://{}/ftn_handler/{}/?fname=",
download.download_dns,
hex::encode(download.download_url)
download.download_url.hex()
);
Ok(ClientResult::single(Box::new(dda!(Self { file_url: url }))))
}
Expand Down
4 changes: 2 additions & 2 deletions mania/src/core/event/message/image_c2c_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl ClientEvent for ImageC2CUploadEvent {
upload_info: vec![UploadInfo {
file_info: Some(FileInfo {
file_size: self.req.size,
file_hash: hex::encode(self.req.md5.clone()),
file_sha1: hex::encode(self.req.sha1.clone()),
file_hash: self.req.md5.hex(),
file_sha1: self.req.md5.hex(),
file_name: self.req.name.to_owned(),
r#type: Some(FileType {
r#type: 1,
Expand Down
4 changes: 2 additions & 2 deletions mania/src/core/event/message/image_group_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl ClientEvent for ImageGroupUploadEvent {
upload_info: vec![UploadInfo {
file_info: Some(FileInfo {
file_size: self.req.size,
file_hash: hex::encode(self.req.md5.clone()),
file_sha1: hex::encode(self.req.sha1.clone()),
file_hash: self.req.md5.hex(),
file_sha1: self.req.sha1.hex(),
file_name: self.req.name.to_owned(),
r#type: Some(FileType {
r#type: 1,
Expand Down
4 changes: 2 additions & 2 deletions mania/src/core/event/message/record_c2c_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl ClientEvent for RecordC2CUploadEvent {
upload_info: vec![UploadInfo {
file_info: Some(FileInfo {
file_size: self.req.size,
file_hash: hex::encode(self.req.md5.clone()),
file_sha1: hex::encode(self.req.sha1.clone()),
file_hash: self.req.md5.hex(),
file_sha1: self.req.sha1.hex(),
file_name: self.req.name.to_owned(),
r#type: Some(FileType {
r#type: 3,
Expand Down
4 changes: 2 additions & 2 deletions mania/src/core/event/message/record_group_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ impl ClientEvent for RecordGroupUploadEvent {
upload_info: vec![UploadInfo {
file_info: Some(FileInfo {
file_size: self.req.size,
file_hash: hex::encode(self.req.md5.clone()),
file_sha1: hex::encode(self.req.sha1.clone()),
file_hash: self.req.md5.hex(),
file_sha1: self.req.sha1.hex(),
file_name: self.req.name.to_owned(),
r#type: Some(FileType {
r#type: 3,
Expand Down
8 changes: 4 additions & 4 deletions mania/src/core/event/message/video_c2c_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ impl ClientEvent for VideoC2CUploadEvent {
UploadInfo {
file_info: Some(FileInfo {
file_size: self.req.video_size,
file_hash: hex::encode(self.req.video_md5.clone()),
file_sha1: hex::encode(self.req.video_sha1.clone()),
file_hash: self.req.video_md5.hex(),
file_sha1: self.req.video_sha1.hex(),
file_name: self.req.video_name.to_owned(),
r#type: Some(FileType {
r#type: 2,
Expand All @@ -82,8 +82,8 @@ impl ClientEvent for VideoC2CUploadEvent {
UploadInfo {
file_info: Some(FileInfo {
file_size: self.req.thumb_size,
file_hash: hex::encode(self.req.thumb_md5.clone()),
file_sha1: hex::encode(self.req.thumb_sha1.clone()),
file_hash: self.req.thumb_md5.hex(),
file_sha1: self.req.thumb_sha1.hex(),
file_name: self.req.thumb_name.to_owned(),
r#type: Some(FileType {
r#type: 1,
Expand Down
8 changes: 4 additions & 4 deletions mania/src/core/event/message/video_group_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ impl ClientEvent for VideoGroupUploadEvent {
UploadInfo {
file_info: Some(FileInfo {
file_size: self.req.video_size,
file_hash: hex::encode(self.req.video_md5.clone()),
file_sha1: hex::encode(self.req.video_sha1.clone()),
file_hash: self.req.video_md5.hex(),
file_sha1: self.req.video_sha1.hex(),
file_name: self.req.video_name.to_owned(),
r#type: Some(FileType {
r#type: 2,
Expand All @@ -81,8 +81,8 @@ impl ClientEvent for VideoGroupUploadEvent {
UploadInfo {
file_info: Some(FileInfo {
file_size: self.req.thumb_size,
file_hash: hex::encode(self.req.thumb_md5.clone()),
file_sha1: hex::encode(self.req.thumb_sha1.clone()),
file_hash: self.req.thumb_md5.hex(),
file_sha1: self.req.thumb_sha1.hex(),
file_name: self.req.thumb_name.to_owned(),
r#type: Some(FileType {
r#type: 1,
Expand Down
2 changes: 1 addition & 1 deletion mania/src/core/event/system/info_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl ClientEvent for InfoSyncEvent {
}),
normal_config: Some(NormalConfig::default()),
register_info: Some(RegisterInfo {
guid: hex::encode(ctx.device.uuid),
guid: ctx.device.uuid.hex(),
kick_pc: 0,
current_version: ctx.app_info.current_version.parse().unwrap(),
is_first_register_proxy_online: 1,
Expand Down
7 changes: 4 additions & 3 deletions mania/src/core/highway/hw_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::core::protos::service::highway::{
DataHighwayHead, LoginSigHead, ReqDataHighwayHead, RespDataHighwayHead, SegHead,
};
use crate::dda;
use crate::utility::extensions::HexString;
use bytes::{Bytes, BytesMut};
use futures::SinkExt;
use futures::StreamExt;
Expand Down Expand Up @@ -33,13 +34,13 @@ pub struct HighwaySession {
impl Debug for HighwaySession {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("HighwaySession")
.field("ticket", &hex::encode(self.ticket.clone()))
.field("ticket", &self.ticket.hex())
.field("uin", &self.uin)
.field("cmd", &self.cmd)
.field("command", &self.command)
.field("file_md5", &hex::encode(self.file_md5.clone()))
.field("file_md5", &self.file_md5.hex())
.field("file_size", &self.file_size)
.field("ext", &hex::encode(self.ext.clone()))
.field("ext", &self.ext.hex())
.finish()
}
}
Expand Down
5 changes: 3 additions & 2 deletions mania/src/core/highway/hw_frame_codec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::core::highway::HighwayError;
use crate::utility::extensions::HexString;
use bytes::{Buf, BufMut, Bytes, BytesMut};
use std::fmt::Debug;
use tokio_util::codec::{Decoder, Encoder};
Expand All @@ -11,8 +12,8 @@ pub struct HighwayFrame {
impl Debug for HighwayFrame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("HighwayFrame")
.field("head", &hex::encode(self.head.clone()))
.field("body", &hex::encode(self.body.clone()))
.field("head", &self.head.hex())
.field("body", &self.body.hex())
.finish()
}
}
Expand Down
45 changes: 23 additions & 22 deletions mania/src/core/operation/highway_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::core::protos::service::highway::{
use crate::message::entity::image::ImageEntity;
use crate::message::entity::record::RecordEntity;
use crate::message::entity::video::VideoEntity;
use crate::utility::extensions::HexString;
use crate::utility::image_resolver::{ImageFormat, resolve_image_metadata};
use crate::utility::stream_helper::{mut_stream_ctx, stream_pipeline};
use crate::{ManiaError, ManiaResult, dda};
Expand Down Expand Up @@ -114,7 +115,7 @@ impl BusinessHandle {
size: image.size,
name: image.file_path.clone().unwrap_or_else(|| format!(
"{}.{}",
hex::encode(&sha1),
&sha1.hex(),
iv.0
)),
md5,
Expand Down Expand Up @@ -149,8 +150,8 @@ impl BusinessHandle {
.info
.as_ref()
.ok_or(ManiaError::GenericError(Cow::from("No info in response")))?;
let sha1 = hex::decode(&info.file_sha1).map_err(HighwayError::HexError)?;
let md5 = hex::decode(&info.file_hash).map_err(HighwayError::HexError)?;
let sha1 = info.file_sha1.unhex().map_err(HighwayError::HexError)?;
let md5 = info.file_hash.unhex().map_err(HighwayError::HexError)?;
let extend = Ntv2RichMediaHighwayExt {
file_uuid: index_node.file_uuid.to_owned(),
u_key: res.res.u_key.to_owned().unwrap(),
Expand Down Expand Up @@ -202,7 +203,7 @@ impl BusinessHandle {
size: image.size,
name: image.file_path.clone().unwrap_or_else(|| format!(
"{}.{}",
hex::encode(&sha1),
&sha1.hex(),
iv.0
)),
md5,
Expand Down Expand Up @@ -237,8 +238,8 @@ impl BusinessHandle {
.info
.as_ref()
.ok_or(ManiaError::GenericError(Cow::from("No info in response")))?;
let sha1 = hex::decode(&info.file_sha1).map_err(HighwayError::HexError)?;
let md5 = hex::decode(&info.file_hash).map_err(HighwayError::HexError)?;
let sha1 = info.file_sha1.unhex().map_err(HighwayError::HexError)?;
let md5 = info.file_hash.unhex().map_err(HighwayError::HexError)?;
let extend = Ntv2RichMediaHighwayExt {
file_uuid: index_node.file_uuid.to_owned(),
u_key: res.res.u_key.to_owned().unwrap(),
Expand Down Expand Up @@ -333,14 +334,14 @@ impl BusinessHandle {
video_name: video
.video_path
.clone()
.unwrap_or_else(|| { format!("{}.mp4", hex::encode(&file_sha1)) }),
.unwrap_or_else(|| { format!("{}.mp4", &file_sha1.hex()) }),
video_md5: file_md5,
video_sha1: file_sha1,
thumb_size: video.video_thumb_size as u32,
thumb_name: video
.video_thumb_path
.clone()
.unwrap_or_else(|| { format!("{}.jpg", hex::encode(&thumb_sha1)) }),
.unwrap_or_else(|| { format!("{}.jpg", &thumb_sha1.hex()) }),
thumb_md5,
thumb_sha1,
thumb_width: video.video_thumb_width as u32,
Expand Down Expand Up @@ -371,7 +372,7 @@ impl BusinessHandle {
.info
.as_ref()
.ok_or(ManiaError::GenericError(Cow::from("No info in response")))?;
let md5 = hex::decode(&info.file_hash).map_err(HighwayError::HexError)?;
let md5 = info.file_hash.unhex().map_err(HighwayError::HexError)?;
let extend = Ntv2RichMediaHighwayExt {
file_uuid: index_node.file_uuid.to_owned(),
u_key: res.res.u_key.to_owned().unwrap(),
Expand Down Expand Up @@ -423,8 +424,8 @@ impl BusinessHandle {
.info
.as_ref()
.ok_or(ManiaError::GenericError(Cow::from("No info in response")))?;
let md5 = hex::decode(&info.file_hash).map_err(HighwayError::HexError)?;
let sha1 = hex::decode(&info.file_sha1).map_err(HighwayError::HexError)?;
let sha1 = info.file_sha1.unhex().map_err(HighwayError::HexError)?;
let md5 = info.file_hash.unhex().map_err(HighwayError::HexError)?;
let size = video.video_thumb_size as u32;
let extend = Ntv2RichMediaHighwayExt {
file_uuid: index.file_uuid.to_owned(),
Expand Down Expand Up @@ -477,14 +478,14 @@ impl BusinessHandle {
video_name: video
.video_path
.clone()
.unwrap_or_else(|| { format!("{}.mp4", hex::encode(&file_sha1)) }),
.unwrap_or_else(|| { format!("{}.mp4", &file_sha1.hex()) }),
video_md5: file_md5,
video_sha1: file_sha1,
thumb_size: video.video_thumb_size as u32,
thumb_name: video
.video_thumb_path
.clone()
.unwrap_or_else(|| { format!("{}.jpg", hex::encode(&thumb_sha1)) }),
.unwrap_or_else(|| { format!("{}.jpg", &thumb_sha1.hex()) }),
thumb_md5,
thumb_sha1,
thumb_width: video.video_thumb_width as u32,
Expand Down Expand Up @@ -515,7 +516,7 @@ impl BusinessHandle {
.info
.as_ref()
.ok_or(ManiaError::GenericError(Cow::from("No info in response")))?;
let md5 = hex::decode(&info.file_hash).map_err(HighwayError::HexError)?;
let md5 = info.file_hash.unhex().map_err(HighwayError::HexError)?;
let extend = Ntv2RichMediaHighwayExt {
file_uuid: index_node.file_uuid.to_owned(),
u_key: res.res.u_key.to_owned().unwrap(),
Expand Down Expand Up @@ -567,8 +568,8 @@ impl BusinessHandle {
.info
.as_ref()
.ok_or(ManiaError::GenericError(Cow::from("No info in response")))?;
let md5 = hex::decode(&info.file_hash).map_err(HighwayError::HexError)?;
let sha1 = hex::decode(&info.file_sha1).map_err(HighwayError::HexError)?;
let sha1 = info.file_sha1.unhex().map_err(HighwayError::HexError)?;
let md5 = info.file_hash.unhex().map_err(HighwayError::HexError)?;
let size = video.video_thumb_size as u32;
let extend = Ntv2RichMediaHighwayExt {
file_uuid: index.file_uuid.to_owned(),
Expand Down Expand Up @@ -708,7 +709,7 @@ impl BusinessHandle {
name: record
.file_path
.clone()
.unwrap_or_else(|| format!("{}.amr", hex::encode(&md5))),
.unwrap_or_else(|| format!("{}.amr", &md5.hex())),
md5,
sha1,
},
Expand All @@ -735,8 +736,8 @@ impl BusinessHandle {
.info
.as_ref()
.ok_or(ManiaError::GenericError(Cow::from("No info in response")))?;
let sha1 = hex::decode(&info.file_sha1).map_err(HighwayError::HexError)?;
let md5 = hex::decode(&info.file_hash).map_err(HighwayError::HexError)?;
let sha1 = info.file_sha1.unhex().map_err(HighwayError::HexError)?;
let md5 = info.file_hash.unhex().map_err(HighwayError::HexError)?;
let extend = Ntv2RichMediaHighwayExt {
file_uuid: index_node.file_uuid.to_owned(),
u_key: res.res.u_key.to_owned().unwrap(),
Expand Down Expand Up @@ -796,7 +797,7 @@ impl BusinessHandle {
name: record
.file_path
.clone()
.unwrap_or_else(|| format!("{}.mp3", hex::encode(&sha1))),
.unwrap_or_else(|| format!("{}.mp3", &sha1.hex())),
md5,
sha1,
}
Expand All @@ -823,8 +824,8 @@ impl BusinessHandle {
.info
.as_ref()
.ok_or(ManiaError::GenericError(Cow::from("No info in response")))?;
let sha1 = hex::decode(&info.file_sha1).map_err(HighwayError::HexError)?;
let md5 = hex::decode(&info.file_hash).map_err(HighwayError::HexError)?;
let sha1 = info.file_sha1.unhex().map_err(HighwayError::HexError)?;
let md5 = info.file_hash.unhex().map_err(HighwayError::HexError)?;
let extend = Ntv2RichMediaHighwayExt {
file_uuid: index_node.file_uuid.to_owned(),
u_key: res.res.u_key.to_owned().unwrap(),
Expand Down
3 changes: 2 additions & 1 deletion mania/src/core/operation/wt_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::core::http;
use crate::core::session::QrSign;
use crate::event::system::SystemEvent;
use crate::event::system::bot_online::BotOnlineEvent;
use crate::utility::extensions::HexString;
use crate::{KeyStore, ManiaError, ManiaResult};
use bytes::Bytes;
use std::borrow::Cow;
Expand Down Expand Up @@ -193,7 +194,7 @@ impl BusinessHandle {
tracing::info!("Online success");
tracing::debug!(
"d2key: {:?}",
hex::encode(**self.context.key_store.session.d2_key.load())
(**self.context.key_store.session.d2_key.load()).hex()
);
self.event_dispatcher
.system
Expand Down
5 changes: 3 additions & 2 deletions mania/src/core/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::core::crypto::tea;
use crate::core::protos::service::oidb::{OidbLafter, OidbSvcTrpcTcpBase};
use crate::core::protos::system::{NtDeviceSign, NtPacketUid, Sign};
use crate::dda;
use crate::utility::extensions::HexString;

#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -125,7 +126,7 @@ impl Debug for SsoPacket {
.field("packet_type", &self.packet_type)
.field("command", &self.command)
.field("sequence", &self.sequence)
.field("payload", &hex::encode(&self.payload.0))
.field("payload", &self.payload.0.hex())
.finish()
}
}
Expand Down Expand Up @@ -208,7 +209,7 @@ impl SsoPacket {
.section(|p| p.bytes(&ctx.key_store.session.tgt.load())) // tgt
.section(|p| p.string(&self.command)) // command
.section(|p| p) // unknown
.section(|p| p.string(&hex::encode(ctx.device.uuid))) // uuid
.section(|p| p.string(&ctx.device.uuid.hex())) // uuid
.section(|p| p) // unknown
.section_16(|p| p.string(ctx.app_info.current_version)) // version
.section(|signature| {
Expand Down
5 changes: 2 additions & 3 deletions mania/src/core/sign.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::core::context::Protocol;
use crate::utility::extensions::HexString;
use bytes::Bytes;
use phf::{Set, phf_set};
use serde::{Deserialize, Deserializer};
Expand Down Expand Up @@ -60,9 +61,7 @@ where
D: Deserializer<'de>,
{
let str = String::deserialize(deserializer)?;
Ok(Bytes::from(
hex::decode(str).map_err(serde::de::Error::custom)?,
))
Ok(Bytes::from(str.unhex().map_err(serde::de::Error::custom)?))
}

pub trait SignProvider: Send + Sync {
Expand Down
3 changes: 2 additions & 1 deletion mania/src/core/sign/linux.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::core::http;
use crate::core::sign::{SignProvider, SignResult};
use crate::utility::extensions::HexString;
use bytes::Bytes;
use reqwest::header::HeaderMap;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -36,7 +37,7 @@ impl SignProvider for LinuxSignProvider {
let request_body = SignServerReq {
cmd: cmd.to_string(),
seq,
src: hex::encode(body),
src: body.hex(),
};
let payload = match serde_json::to_vec(&request_body) {
Ok(payload) => payload,
Expand Down
Loading

0 comments on commit a22cf9c

Please sign in to comment.