ryyst
ryyst

Reputation: 9801

GDB - modifying a C string

I got some assembler code that creates a formatted string using sprintf():

...
0x00304272: call   0x557b2 <dyld_stub___sprintf_chk>
...

I'm trying to find out how the exactly the string is formatted, so I found the format argument "%s%s", which is stored in the $ecx register. Now, I don't know where one string ends and the next one begins, so I'd like to alter the format argument to be "%s@%s".

I have tried to use set $ecx = "%s@%s" (which seems to work, according to print (char *) $ecx), but for some reason, sprintf() uses the old format string instead of the new one.

Did I miss anything? How do I modify the format string?

Upvotes: 1

Views: 482

Answers (1)

Employed Russian
Employed Russian

Reputation: 213636

I have tried to use set $ecx = "%s@%s"

If you are in 32-bit mode (I assume you are, since you've used ecx and not rcx), by the time you are stopped on the call ...sprintf, the parameter to sprintf has already been pused onto the stack.

If the parameter came from %ecx, you need to re-assign new value to %ecx before that value is pushed onto the stack.

Upvotes: 1

Related Questions