fix: instantiate deobfuscator in mapresponse fn

Reason: quickjs context is not Send
This commit is contained in:
ThetaDev 2023-02-08 12:28:30 +01:00
parent d9e07b37e6
commit ee5e82f6bb
17 changed files with 74 additions and 84 deletions

View file

@ -9,7 +9,6 @@ use crate::{error::DeobfError, util};
type Result<T> = core::result::Result<T, DeobfError>;
pub struct Deobfuscator {
data: DeobfData,
ctx: quick_js::Context,
}
@ -42,13 +41,13 @@ impl DeobfData {
}
impl Deobfuscator {
pub fn new(data: DeobfData) -> Result<Self> {
pub fn new(data: &DeobfData) -> Result<Self> {
let ctx =
quick_js::Context::new().or(Err(DeobfError::Other("could not create QuickJS rt")))?;
ctx.eval(&data.sig_fn)?;
ctx.eval(&data.nsig_fn)?;
Ok(Self { data, ctx })
Ok(Self { ctx })
}
pub fn deobfuscate_sig(&self, sig: &str) -> Result<String> {
@ -74,14 +73,6 @@ impl Deobfuscator {
},
)
}
pub fn get_sts(&self) -> String {
self.data.sts.to_owned()
}
pub fn get_data(&self) -> DeobfData {
self.data.to_owned()
}
}
const DEOBF_SIG_FUNC_NAME: &str = "deobf_sig";
@ -322,7 +313,7 @@ c[36](c[8],c[32]),c[20](c[25],c[10]),c[2](c[22],c[8]),c[32](c[20],c[16]),c[32](c
#[fixture]
fn deobf() -> Deobfuscator {
Deobfuscator::new(DeobfData {
Deobfuscator::new(&DeobfData {
js_url: String::default(),
sig_fn: SIG_DEOBF_FUNC.to_owned(),
nsig_fn: NSIG_DEOBF_FUNC.to_owned(),
@ -406,7 +397,7 @@ c[36](c[8],c[32]),c[20](c[25],c[10]),c[2](c[22],c[8]),c[32](c[20],c[16]),c[32](c
fn t_update() {
let client = Client::new();
let deobf_data = tokio_test::block_on(DeobfData::download(client)).unwrap();
let deobf = Deobfuscator::new(deobf_data).unwrap();
let deobf = Deobfuscator::new(&deobf_data).unwrap();
let deobf_sig = deobf.deobfuscate_sig("GOqGOqGOq0QJ8wRAIgaryQHfplJ9xJSKFywyaSMHuuwZYsoMTAvRvfm51qIGECIA5061zWeyfMPX9hEl_U6f9J0tr7GTJMKyPf5XNrJb5fb5i").unwrap();
println!("{deobf_sig}");