This commit is contained in:
G2-Games 2023-12-17 01:59:10 -06:00
parent cafd518f9d
commit 6c1a66a97d
3 changed files with 74 additions and 6 deletions

View file

@ -17,12 +17,13 @@ encoding_rs = "0.8.33"
magic-crypt = "3.1.12" magic-crypt = "3.1.12"
nofmt = "1.0.0" nofmt = "1.0.0"
once_cell = "1.18.0" once_cell = "1.18.0"
regex = "1.9.5"
unicode-jp = "0.4.0"
unicode-normalization = "0.1.22" unicode-normalization = "0.1.22"
hex = "0.4.3" hex = "0.4.3"
des = "0.8.1" des = "0.8.1"
webusb = "0.5.0" webusb = "0.5.0"
unicode-jp = "0.4.0"
regex = "1.10.2"
[lib] [lib]
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]

View file

@ -12,9 +12,9 @@ const BULK_READ_ENDPOINT: u8 = 0x81;
pub const CHUNKSIZE: u32 = 0x10000; pub const CHUNKSIZE: u32 = 0x10000;
// TODO: I think this sucks, figure out a better way // TODO: I think this sucks, figure out a better way
pub static DEVICE_IDS: Lazy<Vec<DeviceId>> = Lazy::new(|| { pub static DEVICE_IDS: Lazy<Box<[DeviceId]>> = Lazy::new(|| {
nofmt::pls! { nofmt::pls! {Box::new(
Vec::from([ [
DeviceId {vendor_id: 0x04dd, product_id: 0x7202, name: Some(String::from("Sharp IM-MT899H"))}, DeviceId {vendor_id: 0x04dd, product_id: 0x7202, name: Some(String::from("Sharp IM-MT899H"))},
DeviceId {vendor_id: 0x04dd, product_id: 0x9013, name: Some(String::from("Sharp IM-DR400"))}, DeviceId {vendor_id: 0x04dd, product_id: 0x9013, name: Some(String::from("Sharp IM-DR400"))},
DeviceId {vendor_id: 0x04dd, product_id: 0x9014, name: Some(String::from("Sharp IM-DR80"))}, DeviceId {vendor_id: 0x04dd, product_id: 0x9014, name: Some(String::from("Sharp IM-DR80"))},

View file

@ -9,6 +9,7 @@ use std::collections::HashMap;
use std::error::Error; use std::error::Error;
use magic_crypt::{MagicCrypt, SecureBit, MagicCryptTrait, new_magic_crypt}; use magic_crypt::{MagicCrypt, SecureBit, MagicCryptTrait, new_magic_crypt};
use hex; use hex;
use once_cell::sync::Lazy;
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
use webusb; use webusb;
@ -35,6 +36,7 @@ pub enum DiscFormat {
SPStereo = 6, SPStereo = 6,
} }
#[derive(Clone, Hash, Eq, PartialEq)]
enum WireFormat { enum WireFormat {
PCM = 0x00, PCM = 0x00,
L105kbps = 0x90, L105kbps = 0x90,
@ -151,6 +153,13 @@ enum Status {
Interim = 0x0f, Interim = 0x0f,
} }
const FRAME_SIZE: Lazy<HashMap<WireFormat, usize>> = Lazy::new(|| HashMap::from([
(WireFormat::PCM, 2048),
(WireFormat::LP2, 192),
(WireFormat::L105kbps, 152),
(WireFormat::LP4, 96),
]));
impl std::convert::TryFrom<u8> for Status { impl std::convert::TryFrom<u8> for Status {
type Error = Box<dyn Error>; type Error = Box<dyn Error>;
@ -1544,8 +1553,14 @@ pub fn retailmac(
Ok(()) Ok(())
} }
struct EKBOpenSource { const DISC_FOR_WIRE: Lazy<HashMap<WireFormat, DiscFormat>> = Lazy::new(|| HashMap::from([
(WireFormat::PCM, DiscFormat::SPStereo),
(WireFormat::LP2, DiscFormat::LP2),
(WireFormat::L105kbps, DiscFormat::LP2),
(WireFormat::LP4, DiscFormat::LP4),
]));
struct EKBOpenSource {
} }
impl EKBOpenSource { impl EKBOpenSource {
@ -1577,14 +1592,66 @@ impl EKBOpenSource {
*/ */
} }
#[derive(Clone)]
struct MDTrack { struct MDTrack {
title: String, title: String,
format: WireFormat, format: WireFormat,
data: Vec<u8>, data: Vec<u8>,
chunk_size: i32, chunk_size: i32,
full_width_title: Option<String>, full_width_title: Option<String>,
encrypt_packets_iterator: EncryptPacketsIterator
}
#[derive(Clone)]
struct EncryptPacketsIterator {
kek: Vec<u8>,
frame_size: i32,
data: Vec<u8>,
chunk_size: i32
} }
impl MDTrack { impl MDTrack {
pub fn full_width_title(self) -> String {
self.full_width_title.unwrap_or("".to_string())
}
pub fn title(&self) -> String {
self.title.clone()
}
pub fn data_format(&self) -> WireFormat {
self.format.clone()
}
pub fn frame_count(&self) -> usize {
self.total_size() / self.frame_size()
}
pub fn frame_size(&self) -> usize {
*FRAME_SIZE.get(&self.format).unwrap()
}
pub fn chunk_size(self) -> i32 {
self.chunk_size
}
pub fn total_size(&self) -> usize {
let frame_size = self.frame_size();
let mut len = self.data.len();
if len % frame_size != 0 {
len = len + (frame_size - (len % frame_size));
}
len
}
pub fn content_id() -> [u8; 20] {
[0x01, 0x0f, 0x50, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x48,
0xa2, 0x8d, 0x3e, 0x1a, 0x3b, 0x0c, 0x44, 0xaf, 0x2f, 0xa0]
}
pub fn get_kek() -> [u8; 8] {
[0x14, 0xe3, 0x83, 0x4e, 0xe2, 0xd3, 0xcc, 0xa5]
}
} }