Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Run `pwninit` in a directory with the relevant files and it will detect which on

If you don't like the default template, you can use your own. Just specify `--template-path <path>`. Check [template.py](src/template.py) for the template format. The names of the `exe`, `libc`, and `ld` bindings can be customized with `--template-bin-name`, `--template-libc-name`, and `--template-ld-name`.

The name of the solve script can be configured with `--template-name <name>`. For example: `--template-name exploit.py` will generate a solve script with the name `exploit.py`.

##### Persisting custom `solve.py`

You can make `pwninit` load your custom template automatically by adding an alias to your `~/.bashrc`.
Expand Down
5 changes: 5 additions & 0 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ pub struct Opts {
#[structopt(default_value = "libc")]
pub template_libc_name: String,

/// Name of pwntools solve script
#[structopt(long)]
#[structopt(default_value = "solve.py")]
pub template_name: String,

/// Name of linker variable for pwntools solve script
#[structopt(long)]
#[structopt(default_value = "ld")]
Expand Down
11 changes: 7 additions & 4 deletions src/solvepy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ fn make_stub(opts: &Opts) -> Result<String> {
.context(FmtSnafu)
}

/// Write script produced with `make_stub()` to `solve.py` in the
/// specified directory, unless a `solve.py` already exists
/// Write script produced with `make_stub()` to `opts.template_name` in the
/// specified directory, unless a `opts.template_name` already exists
pub fn write_stub(opts: &Opts) -> Result<()> {
let stub = make_stub(opts)?;
let path = Path::new("solve.py");
let path = Path::new(&opts.template_name);
if !path.exists() {
println!("{}", "writing solve.py stub".cyan().bold());
println!(
"{}",
format!("writing {} stub", opts.template_name).cyan().bold()
);
fs::write(path, stub).context(WriteSnafu)?;
set_exec(path).context(SetExecSnafu)?;
}
Expand Down