Re: Correlation issue - conversion from hex to string (1013 Views)
Reply
Occasional Visitor
PerfTester_LR
Posts: 2
Registered: ‎03-01-2012
Message 1 of 11 (1,860 Views)

Correlation issue - conversion from hex to string

Hi ,

We are using LR 11 to script on Oracle Utilities application .

 

During record we observed that for login step server responds with a security token which needs to be used in further steps .

 

However, format of that token needs to be changed when sending it back to the server

 

We are able to correlate that value but we are unable to change the format .

 

Recording :

 

Server sends a value                      tjIAKJprJ\x2FxoK2GJL\x2BZMhgUm9Wat4j16dw\x2B7o4d9Lak\x3D

 

It is used in further requests as      tjIAKJprJ/xoK2GJL+ZMhgUm9Wat4j16dw+7o4d9Lak=

 

following hex codes seem to have been changed :

 

\x2F   -->    /

\x3D   -->   =

\x2B    -->  +

 

Does any one know thw function to change to this format ??

we have used web_convert_param and it did not help .

 

Thanks in adavance

 

 

 

HP Expert
Shane_Evans
Posts: 153
Registered: ‎04-08-2010
Message 2 of 11 (1,844 Views)

Re: Correlation issue - conversion from hex to string

Have you tried capturing the entire value and sending back as-is?

Product Manager - HP LoadRunner
www.hp.com/go/loadrunner
Occasional Visitor
PerfTester_LR
Posts: 2
Registered: ‎03-01-2012
Message 3 of 11 (1,840 Views)

Re: Correlation issue - conversion from hex to string

 I have already tried capturing the whole value and sent back as is but saw the issue

Regular Visitor
Alex_Ou
Posts: 3
Registered: ‎08-11-2011
Message 4 of 11 (1,824 Views)

Re: Correlation issue - conversion from hex to string

The web_convert_param does not support the convertion of hex data, please use the function convert_hexparam I wrote below to do the convertion.

 

void convert_hexparam(const char* paramName)
{
	char* src=0;
	char* psrc=0;
	char* dst = 0;
	char* pdst = 0;

	size_t srclen = 0;

	char c;
	char buf[5];

	char enclosedParamName[256];

	sprintf(enclosedParamName, "{%s}", paramName);
	src=lr_eval_string(enclosedParamName);

	srclen = strlen(src);

	dst = (char*)malloc(srclen);
	memset(dst, 0, srclen);

	for(psrc=src, pdst = dst; *psrc != '\0'; pdst++)
	{
		if(*psrc== '\\' && *(psrc + 1) == 'x')
		{
			memset(buf, 0, 5);
			buf[0] = '0';
			buf[1] = 'x';
			buf[2] = *(psrc + 2);
			buf[3] = *(psrc + 3);
			c = (char)strtol(buf, 0, 0 );

			*pdst  = c;
			psrc += 4;
		}
		else
		{
			*pdst = *psrc;
			++psrc;
		}	
	}
	*(pdst+1) = '\0';

	lr_save_string(dst, paramName);

	free(dst);
}

Action()
{
	lr_save_string("tjIAKJprJ\\x2FxoK2GJL\\x2BZMhgUm9Wat4j16dw\\x2B7o4d9Lak\\x3D", "hex_data");

	lr_output_message(lr_eval_string("{hex_data}"));

	convert_hexparam("hex_data");

	lr_output_message(lr_eval_string("{hex_data}"));

	return 0;
}

 

Alex Ou
LoadRunner R&D
Advisor
sandeep singh_1
Posts: 15
Registered: ‎08-06-2009
Message 5 of 11 (1,820 Views)

Re: Correlation issue - conversion from hex to string

Excellent Alex..

Occasional Visitor
LR11users
Posts: 3
Registered: ‎01-16-2014
Message 6 of 11 (1,079 Views)

Re: Correlation issue - conversion from hex to string

Alex,

 

Great information.  However I am getting errors using the code you provided when the info to convert does not have special characters.  Sometimes the server response provides hex with special characters, sometimes it does not.  Using the code you provided, it works when the server sends special characters and works sometimes when the server provides a string without special characters, but sometimes the results after the hex convert will add stuff to the end of the string. 

 

Any advice?

HP Expert
JerryYin
Posts: 95
Registered: ‎08-16-2011
Message 7 of 11 (1,053 Views)

Re: Correlation issue - conversion from hex to string

Please post the "hex with special characters" you mentioned from the server respond, and the desired the result after conversion. So I can know how to change the code to meet your requirement.

 

Occasional Visitor
LR11users
Posts: 3
Registered: ‎01-16-2014
Message 8 of 11 (1,034 Views)

Re: Correlation issue - conversion from hex to string

Thanks for looking into this Jerry,

 

Examples:  server sent a token = '2PSbh1uAGDXhe2swHq6VpHeILKbzdURR02teczil6B4\\x3D' ;\n

 

I captured the token using web_reg_save_param and got the result 2PSbh...6B4 , so far so good.  Ran the parameter captured in the web_re_save_param through the convert_hexparam("param");    and in this example the result was 2PSbh1uAGDXhe2swHq6VpHeILKbzdURR02teczil6B4m     it added an m at the end of the string.

 

Another example:  server sent a token EcBDxkhep7vuEayT1hnWElvSzM5fnrHogIl6lWkxQBE and when ran it through convert_hexparam  the result was EcBDxkhep7vuEayT1hnWElvSzM5fnrHogIl6lWkxQBE\x04      added the \x04 at the end of string

 

Another example:  server sent a token LgTXm7m7AdSLIyT6c0GUFQYLDqWGs513sTSTYlmT5W5YY and when ran it through convert_hexparam the result was LgTXm7m7AdSLIyT6c0GUFQYLDqWGs513sTSTYlmT5W5YY\x02

 

Examples that did not results in error when the token did not contain special characters..  token was 1Q8ZQ96haMP1FZYvxSuOhOYEp91BKSCkyN08VFiMZmE  and when ran through convert_hexparam routine it had same results as token so the script re-played successfully.

 

Another example of a good result.. token was Md3Kcp6R529Xhj58ym5XvcyQ13XaDZYepvca5jHd4yY and the result out of convert_hexparam was the same so script re-played successfully.

 

I have not seen an re-play error when the token from the server has special characters.

 

 

HP Expert
JerryYin
Posts: 95
Registered: ‎08-16-2011
Message 9 of 11 (1,025 Views)

Re: Correlation issue - conversion from hex to string

There's a small bug in the function convert_hexparam. I put the function below, and please be noticed that the fix in red.

 

void convert_hexparam(const char* paramName)
{
    char* src=0;
    char* psrc=0;
    char* dst = 0;
    char* pdst = 0;

    size_t srclen = 0;

    char c;
    char buf[5];

    char enclosedParamName[256];

    sprintf(enclosedParamName, "{%s}", paramName);
    src=lr_eval_string(enclosedParamName);

    srclen = strlen(src);

    dst = (char*)malloc(srclen);
    memset(dst, 0, srclen);

    for(psrc=src, pdst = dst; *psrc != '\0'; pdst++)
    {
        if(*psrc== '\\' && *(psrc + 1) == 'x')
        {
            memset(buf, 0, 5);
            buf[0] = '0';
            buf[1] = 'x';
            buf[2] = *(psrc + 2);
            buf[3] = *(psrc + 3);
            c = (char)strtol(buf, 0, 0 );

            *pdst  = c;
            psrc += 4;
        }
        else
        {
            *pdst = *psrc;
            ++psrc;
        }    
    }
    *(pdst) = '\0';

    lr_save_string(dst, paramName);

    free(dst);
}

Occasional Visitor
LR11users
Posts: 3
Registered: ‎01-16-2014
Message 10 of 11 (1,013 Views)

Re: Correlation issue - conversion from hex to string

Thank You so much Jerry !

 

That did the trick!

Occasional Visitor
Ravindra_Kumar
Posts: 1
Registered: ‎06-24-2014
Message 11 of 11 (580 Views)

Re: Correlation issue - conversion from hex to string

I have used this function but getting c interprter error memory violation recived every now and then

it seem problem while releasing the memory allocated using malloc function.

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.