Snippets
Created by
XOR Hex
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
/*! @file
* This is the PIN tool example modified to replace the
* GetSystemDefaultUILanguage function to return a value we
* control via a command line parameter.
*/
#include "pin.H"
#include <iostream>
#include <fstream>
#define GETSYSTEMDEFAULTUILANGUAGE "GetSystemDefaultUILanguage"
/* ================================================================== */
// Global variables
/* ================================================================== */
UINT16 newLangCode = 0;
std::ostream * out = &cerr;
/* ===================================================================== */
// Command line switches
/* ===================================================================== */
KNOB<string> KnobOutputFile(KNOB_MODE_WRITEONCE, "pintool",
"o", "", "specify file name for MyPinTool output");
// Add option to allow the hex code for the DefaultUILanguage to be set
KNOB<UINT32> KnobLangugeCode(KNOB_MODE_WRITEONCE, "pintool",
"c", "", "integer value of the language code to set");
/* ===================================================================== */
// Utilities
/* ===================================================================== */
/*!
* Print out help message.
*/
INT32 Usage()
{
cerr << "This tool modifies the return value for GetSystemDefaultUILanguage. " << endl <<
"The language code is set using the -c flag." << endl << endl;
cerr << KNOB_BASE::StringKnobSummary() << endl;
return -1;
}
/* ===================================================================== */
// Analysis routines
/* ===================================================================== */
UINT16 __stdcall SetSystemDefaultUILanguage() {
return (UINT16)newLangCode;
}
/* ===================================================================== */
// Instrumentation routines
/* ===================================================================== */
VOID Image(IMG img, VOID *v)
{
RTN sysDefUILangRtn = RTN_FindByName(img, GETSYSTEMDEFAULTUILANGUAGE);
if (RTN_Valid(sysDefUILangRtn)) {
RTN_Open(sysDefUILangRtn);
if (newLangCode > 0)
RTN_Replace(sysDefUILangRtn, (AFUNPTR)SetSystemDefaultUILanguage);
RTN_Close(sysDefUILangRtn);
}
}
/*!
* The main procedure of the tool.
* This function is called when the application image is loaded but not yet started.
* @param[in] argc total number of elements in the argv array
* @param[in] argv array of command line arguments,
* including pin -t <toolname> -- ...
*/
int main(int argc, char *argv[])
{
// Initialize PIN library. Print help message if -h(elp) is specified
// in the command line or the command line is invalid
PIN_InitSymbols();
if( PIN_Init(argc,argv) )
{
return Usage();
}
string fileName = KnobOutputFile.Value();
if (!fileName.empty()) { out = new std::ofstream(fileName.c_str());}
newLangCode = KnobLangugeCode.Value();
cerr << "===============================================" << endl;
cerr << "This application is instrumented by MyPinTool" << endl;
if (!KnobOutputFile.Value().empty())
{
cerr << "See file " << KnobOutputFile.Value() << " for analysis results" << endl;
}
cerr << "===============================================" << endl;
// Register Image to be called to instrument functions.
IMG_AddInstrumentFunction(Image, 0);
// Start the program, never returns
PIN_StartProgram();
return 0;
}
/* ===================================================================== */
/* eof */
/* ===================================================================== */
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.