Panda

Struct Panda 

Source
pub struct Panda { /* private fields */ }
Expand description

Builder for creating PANDA instances. Only for use in libpanda mode.

Implementations§

Source§

impl Panda

Source

pub fn new() -> Self

Create a new PANDA instance.

§Example
Panda::new()
    .generic("x86_64")
    .run();
Examples found in repository?
examples/hooks.rs (line 33)
32fn main() {
33    Panda::new().generic("x86_64").replay("test").run();
34}
More examples
Hide additional examples
examples/osi.rs (line 44)
43fn main() {
44    Panda::new().generic("x86_64").replay("test").run();
45}
examples/guest_ptr.rs (line 47)
46fn main() {
47    Panda::new().arch(panda::Arch::x86_64).configurable().run();
48}
examples/unicorn_taint.rs (line 78)
77fn main() {
78    Panda::new()
79        .arch(panda::Arch::x86_64)
80        .configurable()
81        .run();
82}
examples/syscall_injection.rs (line 33)
32fn main() {
33    Panda::new()
34        .generic("x86_64")
35        //.args(&["-loadvm", "root"])
36        .run();
37}
examples/ppp_callback_export.rs (line 27)
10fn main() {
11    let mut i = 0;
12    let callback = panda::Callback::new();
13    callback.before_block_exec(move |cpu, _| {
14        if i % 2 == 0 {
15            on_every_even_block::trigger(cpu);
16        } else {
17            if on_every_odd_block::trigger(cpu) {
18                callback.disable();
19            }
20        }
21        i += 1;
22    });
23
24    on_every_even_block::add_callback(on_even_test);
25    on_every_odd_block::add_callback(on_odd_test);
26
27    Panda::new().generic("x86_64").replay("test").run();
28}
Source

pub fn arg<S: Into<String>>(&mut self, arg: S) -> &mut Self

Add an argument for PANDA

§Example
Panda::new()
    .arg("-nomonitor")
    .run();
Source

pub fn args<I, S>(&mut self, args: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Add a set of extra arguments for PANDA

§Example
Panda::new()
    .args(&["-panda", "callstack_instr"])
    .run();
Source

pub fn arch(&mut self, arch: Arch) -> &mut Self

Sets the architecture of the guest

§Example
Panda::new()
    .arch(Arch::i386)
    .run();
Examples found in repository?
examples/guest_ptr.rs (line 47)
46fn main() {
47    Panda::new().arch(panda::Arch::x86_64).configurable().run();
48}
More examples
Hide additional examples
examples/unicorn_taint.rs (line 79)
77fn main() {
78    Panda::new()
79        .arch(panda::Arch::x86_64)
80        .configurable()
81        .run();
82}
Source

pub fn configurable(&mut self) -> &mut Self

Set the machine to PANDA’s configurable machine

§Example
Panda::new()
    .configurable()
    .run();
Examples found in repository?
examples/guest_ptr.rs (line 47)
46fn main() {
47    Panda::new().arch(panda::Arch::x86_64).configurable().run();
48}
More examples
Hide additional examples
examples/unicorn_taint.rs (line 80)
77fn main() {
78    Panda::new()
79        .arch(panda::Arch::x86_64)
80        .configurable()
81        .run();
82}
Source

pub fn enable_graphics(&mut self) -> &mut Self

§Example
Panda::new()
    .enable_graphics()
    .run();
Source

pub fn expect_prompt<S: Into<String>>(&mut self, prompt_regex: S) -> &mut Self

Regular expression describing the prompt exposed by the guest on a serial console. Used in order to know when running a command has finished with its output.

Source

pub fn mem<S: Into<String>>(&mut self, mem: S) -> &mut Self

Set the available memory. If restoring from a snapshot or viewing a replay, this must be the same as when the replay/snapshot was taken.

Source

pub fn generic<S: Into<String>>(&mut self, generic: S) -> &mut Self

Use generic PANDA Qcow for run

§Example
Panda::new()
    .generic("x86_64")
    .run();
Examples found in repository?
examples/hooks.rs (line 33)
32fn main() {
33    Panda::new().generic("x86_64").replay("test").run();
34}
More examples
Hide additional examples
examples/osi.rs (line 44)
43fn main() {
44    Panda::new().generic("x86_64").replay("test").run();
45}
examples/syscall_injection.rs (line 34)
32fn main() {
33    Panda::new()
34        .generic("x86_64")
35        //.args(&["-loadvm", "root"])
36        .run();
37}
examples/ppp_callback_export.rs (line 27)
10fn main() {
11    let mut i = 0;
12    let callback = panda::Callback::new();
13    callback.before_block_exec(move |cpu, _| {
14        if i % 2 == 0 {
15            on_every_even_block::trigger(cpu);
16        } else {
17            if on_every_odd_block::trigger(cpu) {
18                callback.disable();
19            }
20        }
21        i += 1;
22    });
23
24    on_every_even_block::add_callback(on_even_test);
25    on_every_odd_block::add_callback(on_odd_test);
26
27    Panda::new().generic("x86_64").replay("test").run();
28}
examples/closures.rs (line 26)
5fn main() {
6    // Callbacks can capture state
7    let mut count = 1;
8    let bb_callback = Callback::new();
9    bb_callback.before_block_exec(move |cpu, _| {
10        println!("Block: {} | PC: {:#x?}", count, panda::regs::get_pc(cpu));
11        count += 1;
12        if count > 5 {
13            // callbacks can disable themselves by capturing a copy
14            // of the `Callback` reference to it
15            bb_callback.disable();
16        }
17    });
18
19    // If you don't need to enable and disable the callback, you can just
20    // use method chaining instead of assigning to a variable
21    PppCallback::new().on_rec_auxv(|_, _, auxv| {
22        // print out the auxillary vector when any process starts
23        dbg!(auxv);
24    });
25
26    Panda::new().generic("x86_64").replay("test").run();
27}
Source

pub fn replay<S: Into<String>>(&mut self, replay: S) -> &mut Self

Run the given replay in the PANDA instance. Equivalent to -replay [name] from the PANDA command line.

§Example
Panda::new()
    .replay("grep_recording")
    .run();
Examples found in repository?
examples/hooks.rs (line 33)
32fn main() {
33    Panda::new().generic("x86_64").replay("test").run();
34}
More examples
Hide additional examples
examples/osi.rs (line 44)
43fn main() {
44    Panda::new().generic("x86_64").replay("test").run();
45}
examples/ppp_callback_export.rs (line 27)
10fn main() {
11    let mut i = 0;
12    let callback = panda::Callback::new();
13    callback.before_block_exec(move |cpu, _| {
14        if i % 2 == 0 {
15            on_every_even_block::trigger(cpu);
16        } else {
17            if on_every_odd_block::trigger(cpu) {
18                callback.disable();
19            }
20        }
21        i += 1;
22    });
23
24    on_every_even_block::add_callback(on_even_test);
25    on_every_odd_block::add_callback(on_odd_test);
26
27    Panda::new().generic("x86_64").replay("test").run();
28}
examples/closures.rs (line 26)
5fn main() {
6    // Callbacks can capture state
7    let mut count = 1;
8    let bb_callback = Callback::new();
9    bb_callback.before_block_exec(move |cpu, _| {
10        println!("Block: {} | PC: {:#x?}", count, panda::regs::get_pc(cpu));
11        count += 1;
12        if count > 5 {
13            // callbacks can disable themselves by capturing a copy
14            // of the `Callback` reference to it
15            bb_callback.disable();
16        }
17    });
18
19    // If you don't need to enable and disable the callback, you can just
20    // use method chaining instead of assigning to a variable
21    PppCallback::new().on_rec_auxv(|_, _, auxv| {
22        // print out the auxillary vector when any process starts
23        dbg!(auxv);
24    });
25
26    Panda::new().generic("x86_64").replay("test").run();
27}
Source

pub fn plugin_args<T: PandaArgs>(&mut self, args: &T) -> &mut Self

Load a plugin with args provided by a PandaArgs struct.

§Example
use panda::prelude::*;

#[derive(PandaArgs)]
#[name = "stringsearch"]
struct StringSearch {
    str: String
}

fn main() {
    Panda::new()
        .generic("x86_64")
        .replay("test")
        .plugin_args(&StringSearch {
            str: "test".into()
        })
        .run();
}
Source

pub fn run(&mut self)

Start the PANDA instance with the given settings. This is a blocking operation.

§Example
Panda::new()
    .generic("x86_64")
    .run();
Examples found in repository?
examples/hooks.rs (line 33)
32fn main() {
33    Panda::new().generic("x86_64").replay("test").run();
34}
More examples
Hide additional examples
examples/osi.rs (line 44)
43fn main() {
44    Panda::new().generic("x86_64").replay("test").run();
45}
examples/guest_ptr.rs (line 47)
46fn main() {
47    Panda::new().arch(panda::Arch::x86_64).configurable().run();
48}
examples/unicorn_taint.rs (line 81)
77fn main() {
78    Panda::new()
79        .arch(panda::Arch::x86_64)
80        .configurable()
81        .run();
82}
examples/syscall_injection.rs (line 36)
32fn main() {
33    Panda::new()
34        .generic("x86_64")
35        //.args(&["-loadvm", "root"])
36        .run();
37}
examples/ppp_callback_export.rs (line 27)
10fn main() {
11    let mut i = 0;
12    let callback = panda::Callback::new();
13    callback.before_block_exec(move |cpu, _| {
14        if i % 2 == 0 {
15            on_every_even_block::trigger(cpu);
16        } else {
17            if on_every_odd_block::trigger(cpu) {
18                callback.disable();
19            }
20        }
21        i += 1;
22    });
23
24    on_every_even_block::add_callback(on_even_test);
25    on_every_odd_block::add_callback(on_odd_test);
26
27    Panda::new().generic("x86_64").replay("test").run();
28}
Source

pub fn run_after_init(func: impl FnOnce() + Send + Sync + 'static)

Queue up a function that should run before libpanda has started but after the libpanda has been initialized. If run under a plugin context (e.g. no libpanda), or libpanda is currently running, then the function will run immediately.

This is useful for functions that may require waiting until things like arguments or OS has been set, such as setting up an OSI callback.

Trait Implementations§

Source§

impl Default for Panda

Source§

fn default() -> Panda

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Panda

§

impl RefUnwindSafe for Panda

§

impl Send for Panda

§

impl Sync for Panda

§

impl Unpin for Panda

§

impl UnwindSafe for Panda

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.