0

I'm facing an issue, and I'm not sure what is the best way to handle it. While debugging a program (x64, windows), the program copies certain string using

errno_t strncpy_s(char *restrict dest, rsize_t destsz,
              const char *restrict src, rsize_t count);

After the call to strncpy_s I would like to change dest to point to my own string. What is the best method to do so? Things I considered so far:

  • Patching bytes in the program (before execution) - I could possibly patch empty space in the program to contain my string, and then patch a mov instruction after the copy.
  • Breaking the program after the copy, then using a method to allocate a string or patch a string into the memory, then dynamically editing the register to point to the new allocated space.

I tend to think that the 2nd option will be easier to perform, but I'm not sure what is the best tool to achieve it. I've looked at write_dbg_memory using IDAPython to write the memory, and it seems quite promising. Is there another way to do so? Preferably using IDA or WinDBG? Is there something that also mallocs space instead of having to look for a relevant space?

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.