Snippets

XOR Hex Change GetSystemDefaultUILanguage() Return Value Via Pin

Created by XOR Hex last modified

/*! @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)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.