danleh / wasabi

A dynamic analysis framework for WebAssembly programs.
http://wasabi.software-lab.org
MIT License
366 stars 48 forks source link

Modify state inside of hooks #3

Open Bruisr opened 6 years ago

Bruisr commented 6 years ago

It would be very useful to be able to modify the state of an operation inside of a hook. E.g.

Wasabi.analysis = {
    binary(location, op, first, second, r) {
        // If result for i32.eq operations in function 47 are 0, change it to 1 
        // then continue execution with the new result.
        if (op == 'i32.eq' && location['func'] == 47 && result == 0) {
            result = 1;
            console.log(location, op, "result =", result);
        }
    }
};
danleh commented 6 years ago

Good point, this is definitely useful. Out of interest: What would be your application? (E.g., something along the lines of fault injection by randomly changing instruction results?)

Unfortunately, I think we won't support this in the near future (say, 6 months) because of some technical challenges/open questions:

ctfhacker commented 6 years ago

One application of this would be to force particular paths in a debugging session. If we happen to know some condition needs to be set, but don't quite understand why it needs to be set, having the ability to modify the state would be immensely useful.

danleh commented 6 years ago

If we happen to know some condition needs to be set, but don't quite understand why it needs to be set, having the ability to modify the state would be immensely useful.

I.e., flipping conditions in order to explore previously unreached paths in a program? If so, that sounds more constrained (and thus doable) then modifying any instruction result. In particular, conditions are always i32s, so the problems with i64 handling do not apply.