Skip to content

How to skip instructions by setting PC? PANDA script not working #1585

@TheSilentDawn

Description

@TheSilentDawn

I'm trying to use PANDA to skip over certain instructions in a program, but I'm running into issues.

Here’s the relevant C code:

int check_value = 1;
check_value++;
check_value++;  // <-- I want to start skipping from here
check_value++;  

myowntestfunc();

check_value++;
check_value++; // <-- and jump directly to here

printf("%d\n", check_value);

The goal is to skip one or more check_value++ operations and function call, and resume execution from a later point.

I tried the following PANDA Python script:

panda.enable_precise_pc()

@panda.cb_insn_translate
def insn_translate(cpu, pc):
    return pc == skipped_addr

@panda.cb_insn_exec
def insn_exec(cpu, pc):
    if pc == skipped_addr:
        panda.arch.set_pc(cpu, target_addr)
        # panda.flush_tb()  # enabling/disabling this has no effect
        print(f"[*] skip {hex(pc)} to {hex(target_addr)}")
        return True  
    return False

However, this does not work as expected — the execution flow does not jump to target_addr. Instead, the instructions are executed normally without being skipped.


My question is:

How can I correctly force a jump in control flow by setting the PC?
Is setting the PC and optionally flushing the translation block (flush_tb) supposed to be enough?
Or is there a more reliable way to skip certain instructions at runtime?


Environment:

  • OS:
  • Ubuntu 22.04 LTS with default python 3.10.12
  • PANDA version:

Thanks in advance!


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions