/*BEGIN_LEGAL Intel Open Source License Copyright (c) 2002-2005 Intel Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. END_LEGAL */ /* ===================================================================== */ /*! @file Replace an original function with a custom function defined in the tool. The new function can have either the same or different signature from that of its original function. */ /* ===================================================================== */ #include "pin.H" #include using namespace std; /* ===================================================================== */ static void (*pf_bar)(int, int, int, int); /* ===================================================================== */ VOID Boo( UINT32 num0, UINT32 num1, UINT32 arg0, UINT32 arg1, UINT32 num2, UINT32 num3, UINT32 num4, UINT32 arg2, UINT32 arg3 ) { cout << "Original Arguments = ( " << arg0 << ", " << arg1 << ", " << arg2 << ", " << arg3 << " )" << endl << flush; cout << "New Arguments = ( " << num0 << ", " << num1 << ", " << num2 << ", " << num3 << ", " << num4 << " )" << endl << flush; } /* ===================================================================== */ VOID ImageLoad(IMG img, VOID *v) { cout << IMG_Name(img) << endl; PROTO proto = PROTO_Allocate( PIN_PARG(void), CALLINGSTD_DEFAULT, "Bar", PIN_PARG(int), PIN_PARG(int), PIN_PARG(int), PIN_PARG(int), PIN_PARG_END() ); RTN rtn = RTN_FindByName(img, "Bar"); if (RTN_Valid(rtn)) { cout << "Replacing " << RTN_Name(rtn) << " in " << IMG_Name(img) << endl; pf_bar = (void (*)(int, int, int, int))RTN_ReplaceSignatureProbed( rtn, AFUNPTR(Boo), IARG_PROTOTYPE, proto, IARG_UINT32, 100, IARG_UINT32, 200, IARG_FUNCARG_ENTRYPOINT_VALUE, 0, IARG_FUNCARG_ENTRYPOINT_VALUE, 1, IARG_UINT32, 300, IARG_UINT32, 400, IARG_UINT32, 500, IARG_FUNCARG_ENTRYPOINT_VALUE, 2, IARG_FUNCARG_ENTRYPOINT_VALUE, 3, IARG_END); } PROTO_Free( proto ); } /* ===================================================================== */ int main(INT32 argc, CHAR *argv[]) { PIN_InitSymbols(); PIN_Init(argc, argv); IMG_AddInstrumentFunction(ImageLoad, 0); PIN_StartProgramProbed(); return 0; } /* ===================================================================== */ /* eof */ /* ===================================================================== */