fix(replace): no error returned when holder not found

This commit is contained in:
b1n
2024-07-15 20:17:39 +08:00
parent 2a134082e5
commit 1b8f8fd8da
5 changed files with 31 additions and 25 deletions

2
Cargo.lock generated
View File

@@ -3177,7 +3177,7 @@ dependencies = [
[[package]]
name = "pumpbin"
version = "1.1.0"
version = "1.1.1"
dependencies = [
"anyhow",
"bincode",

View File

@@ -1,6 +1,6 @@
[package]
name = "pumpbin"
version = "1.1.0"
version = "1.1.1"
authors = ["b1n <b1n@b1n.io>"]
edition = "2021"
description = "PumpBin is an Implant Generation Platform."

View File

@@ -1,4 +1,6 @@
fn build_capnp() {
fn main() {
#[cfg(debug_assertions)]
{
capnpc::CompilerCommand::new()
.src_prefix("capnp")
.file("capnp/plugin.capnp")
@@ -7,10 +9,6 @@ fn build_capnp() {
.expect("schema compiler command");
}
fn main() {
#[cfg(debug_assertions)]
build_capnp();
#[cfg(target_os = "windows")]
{
let mut res = winresource::WindowsResource::new();

View File

@@ -479,14 +479,14 @@ impl Plugin {
self.replace().src_prefix(),
shellcode_src.as_slice(),
self.replace().max_len(),
);
)?;
// replace pass
for pass in pass {
let holder = pass.holder();
let replace_by = pass.replace_by();
utils::replace(bin, holder, replace_by, holder.len());
utils::replace(bin, holder, replace_by, holder.len())?;
}
// replace size_holder
@@ -503,7 +503,7 @@ impl Plugin {
.collect();
size_bytes.extend_from_slice(shellcode_len_bytes.as_slice());
utils::replace(bin, size_holder, size_bytes.as_slice(), size_holder.len());
utils::replace(bin, size_holder, size_bytes.as_slice(), size_holder.len())?;
}
Ok(())

View File

@@ -1,5 +1,6 @@
use std::iter;
use anyhow::anyhow;
use iced::{
advanced::graphics::image::image_rs::ImageFormat,
window::{self, Level, Position},
@@ -62,11 +63,17 @@ pub fn window_settings() -> window::Settings {
}
}
pub fn replace(bin: &mut [u8], holder: &[u8], replace_by: &[u8], max_len: usize) {
pub fn replace(
bin: &mut [u8],
holder: &[u8],
replace_by: &[u8],
max_len: usize,
) -> anyhow::Result<()> {
let mut replace_by = replace_by.to_owned();
let find = memmem::find_iter(bin, holder).next();
if let Some(position) = find {
let position = memmem::find_iter(bin, holder)
.next()
.ok_or(anyhow!("Not found {}", String::from_utf8_lossy(holder)))?;
let mut random: Vec<u8> = iter::repeat(b'0')
.take(max_len - replace_by.len())
.collect();
@@ -74,5 +81,6 @@ pub fn replace(bin: &mut [u8], holder: &[u8], replace_by: &[u8], max_len: usize)
replace_by.extend_from_slice(random.as_slice());
bin[position..(position + max_len)].copy_from_slice(replace_by.as_slice());
}
Ok(())
}