feat!: compress plugin via zlib

This commit is contained in:
b1n
2024-07-09 15:47:39 +08:00
parent c4fceb6c58
commit 8f7955aa7f
4 changed files with 21 additions and 4 deletions

View File

@@ -1,5 +1,9 @@
# CHANGELOG # CHANGELOG
## v1.1.0
- Compress plugin via zlib.
## v1.0.0 ## v1.0.0
- Implementing a Plug-in System with Extism. - Implementing a Plug-in System with Extism.

3
Cargo.lock generated
View File

@@ -3177,7 +3177,7 @@ dependencies = [
[[package]] [[package]]
name = "pumpbin" name = "pumpbin"
version = "1.0.0" version = "1.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@@ -3185,6 +3185,7 @@ dependencies = [
"capnpc", "capnpc",
"dirs 5.0.1", "dirs 5.0.1",
"extism", "extism",
"flate2",
"iced", "iced",
"memchr", "memchr",
"open", "open",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "pumpbin" name = "pumpbin"
version = "1.0.0" version = "1.1.0"
authors = ["b1n <b1n@b1n.io>"] authors = ["b1n <b1n@b1n.io>"]
edition = "2021" edition = "2021"
description = "PumpBin is an Implant Generation Platform." description = "PumpBin is an Implant Generation Platform."
@@ -28,6 +28,7 @@ capnp = "0.19"
extism = "1.4.1" extism = "1.4.1"
serde = { version = "1.0.203", features = ["derive"] } serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.120" serde_json = "1.0.120"
flate2 = "1.0.30"
[dependencies.iced] [dependencies.iced]
version = "0.13.0-dev" version = "0.13.0-dev"

View File

@@ -9,9 +9,11 @@ use std::{
use anyhow::{anyhow, bail}; use anyhow::{anyhow, bail};
use bincode::{decode_from_slice, encode_to_vec, Decode, Encode}; use bincode::{decode_from_slice, encode_to_vec, Decode, Encode};
use capnp::{ use capnp::{
io::Write,
message::{self, ReaderOptions}, message::{self, ReaderOptions},
serialize_packed, serialize_packed,
}; };
use flate2::Compression;
use crate::{ use crate::{
plugin_capnp, plugin_capnp,
@@ -276,7 +278,12 @@ pub struct Plugin {
impl Plugin { impl Plugin {
pub fn decode_from_slice(data: &[u8]) -> anyhow::Result<Self> { pub fn decode_from_slice(data: &[u8]) -> anyhow::Result<Self> {
let message = serialize_packed::read_message(data, ReaderOptions::new())?; let mut decoder = flate2::write::ZlibDecoder::new(Vec::new());
decoder.write_all(data)?;
let decompressed = decoder.finish()?;
let message =
serialize_packed::read_message(decompressed.as_slice(), ReaderOptions::new())?;
let plugin = message.get_root::<plugin_capnp::plugin::Reader>()?; let plugin = message.get_root::<plugin_capnp::plugin::Reader>()?;
let info = plugin.get_info()?; let info = plugin.get_info()?;
@@ -412,7 +419,11 @@ impl Plugin {
let mut buf = Vec::new(); let mut buf = Vec::new();
serialize_packed::write_message(&mut buf, &message)?; serialize_packed::write_message(&mut buf, &message)?;
anyhow::Ok(buf) let mut encoder = flate2::write::ZlibEncoder::new(Vec::new(), Compression::best());
encoder.write_all(buf.as_slice())?;
let compressed = encoder.finish()?;
anyhow::Ok(compressed)
} }
pub fn replace_binary( pub fn replace_binary(