1

How can one access all references to the stack (also outside of its frame) a function has via the Java Plugin API?

Example: This instructions write values outside of the stack frame of the function:

enter image description here

Do I need to traverse the CFG of the function? (If yes, how do I do this?)

1

I asked the question on github and got the following reply:

Assuming stack analysis has been performed and the function has been marked with stack references as shown above, you can iterate over the references "from" the body of the function (i.e., AddressSetView). The references returned would need to be filtered as other type of references would also be returned. Although there are a variety of ways to obtain references here is one example:

Function f;
Program p;
ReferenceManager refMgr = p.getReferenceManager();
    for (Address fromAddr : refMgr.getReferenceSourceIterator(f.getBody(), true)) {
        for (Reference ref : refMgr.getReferencesFrom(fromAddr)) {
            if (ref.isStackReference()) {
                StackReference stackRef = (StackReference) ref;
            }
        }
}

The important part is that your analysis must take place AFTER the stack analysis happened, which is quite late. You can control when your analysis runs in the constructor by passing the point where you want to run into the parent constructor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.