Setting String Parameters

From OC Systems Wiki!
Revision as of 00:22, 9 March 2021 by Swn (talk | contribs) (Swn moved page String modifying to Setting String Parameters without leaving a redirect)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Modifying string parameters from applications can be confusing because different languages have different string formats. Here are some examples for modifying different kinds of strings.

C Example

For a C program like this:

/* C function with string parameter */
void p1(const char *str)
{
  printf("str = %s\n", str);
}

This probe:

probe thread
{
   probe "p1"
   {
      on_entry
      {
         // modify string directly 
         $str = "string value";
      }
   }
}

Will modify the string parameter "str" before it is used in the function.

C++ Example

For a C++ program like this:

void p1(std::string str)
{
  std::cout << "str = " << str << std::endl;
}

This probe:

#include "cppstring.h"

probe thread
{
   probe "p1"
   {
      on_entry
      {
         // modify string using macro
         AP_SET_CPP_STR($str, "new value");
      }
   }
}

Compiled with this command:

apc -x my program.exe myprobe.apc cppstring.ual
 

Will modify the C++ string parameter "str" before the method is executed.

See [FAQ] section 17.65 for directions on building cppstring.ual.

Ada Example

See Setting Ada String Parameters for Ada examples.