Re: [DynInst_API:] Wrong memory write size?


Date: Mon, 18 Jul 2016 14:51:51 -0500
From: John Detter <jdetter@xxxxxxxx>
Subject: Re: [DynInst_API:] Wrong memory write size?
Fredi,

It looks like this could be a case where the documentation isn't clear about what is returned. The function getMemoryWriteOperands() returns the addresses that are written to by the instruction, not the operands themselves. We are discussing this to see if it's a code issue or a documentation issue.

Based on the name of the function, it would be intuitive to get back the actual operand and not the address, so I can see why this was confusing for you.

We have a digest of the issue on Github if you would like to follow it: https://github.com/dyninst/dyninst/issues/125

I should have more updates for you soon.

-- John

On 7/14/2016 5:21 PM, Frederik Peukert wrote:

John,

 

Thank you for looking into my issue.

My GCC version is 4.8.4.

Since I am new to Dyninst, It might be only an understanding issue.

 

Thanks.

 

--Fredi

 

 

Von: John Detter [mailto:jdetter@xxxxxxxx]
Gesendet: Donnerstag, 14. Juli 2016 20:17
An: Frederik Peukert <fredi5555@xxxxxx>
Cc: dyninst-api@xxxxxxxxxxx
Betreff: Re: [DynInst_API:] Wrong memory write size?

 

Fredi,

 

Could you provide me with your GCC version? I'm looking into your issue now.

Sorry for the long wait,

 

-- John

 

On 7/10/2016 5:10 AM, Frederik Peukert wrote:

Hi all,

 

I use getMemoryWriteOperands() to get the _expression_ of Operands that write to memory and size() to get the actual size of the write. However, it always returns 4 byte, even if I write a single byte (char) like in the following program.

 

int main(void) {

   char x = 'A';

   return 0;

}

 

Even gdb disassembles it to a byte sized write: “mov BYTE PTR [ebp-0x1], 0x41”.

I know that EBP is a 4 byte register, but a 4 byte write would just overwrite the variable next to “x” (at least if layout is not 4 byte aligned). Tell me if I am wrong.

I am using a 32-Bit Linux mint (vmware) and Dyninst 9.2.0.

 

Relevant code:

 

int main(int argc, const char** argv) {

                BPatch bpatch;

                BPatch_addressSpace *app = bpatch.openBinary(“MUTATEE”, true);  

                BPatch_image *appImage = app->getImage();

 

                BPatch_Vector<BPatch_function *> functions;

                appImage->findFunction("main", functions);

 

                BPatch_function* f = functions[0];

                BPatch_flowGraph* fg = f->getCFG();

 

                std::set<BPatch_basicBlock *> blocks;

                fg->getAllBasicBlocks(blocks);

 

                for(auto bb_iter = blocks.begin(); bb_iter != blocks.end(); ++bb_iter){

                                std::vector<Instruction::Ptr> insns;

                                (*bb_iter)->getInstructions(insns);

                                for(auto ins_iter = insns.begin(); ins_iter != insns.end(); ++ins_iter){

                                                cout << (*ins_iter)->format() << endl;

                                                if((*ins_iter)->writesMemory()){

                                                                std::set<_expression_::Ptr> memAccessors;

                                                                (*ins_iter)->getMemoryWriteOperands(memAccessors);

                                                                if (memAccessors.size())

                                                                {

                                                                                for(auto it = memAccessors.begin(); it != memAccessors.end(); ++it)

                                                                                {

                                                                                                std::cout << "\tmem write (size: " << (*it)->size() << ")" << endl;;

                                                                                }

                                                                }

                                                }

                                }

                }

BPatch_binaryEdit *appBin = dynamic_cast<BPatch_binaryEdit *>(app);

                appBin->writeFile(“MUTATEE_PATCHED”);

 

                return 0;

}

 

Thanks!

 

--Fredi



_______________________________________________
Dyninst-api mailing list
Dyninst-api@xxxxxxxxxxx
https://lists.cs.wisc.edu/mailman/listinfo/dyninst-api

 


[← Prev in Thread] Current Thread [Next in Thread→]