2

I was following the response to this question to change the string of an elf executable. No matter how many times I try, I just can't modify the string. I notice that probably the issue lies in the permissions of rodata section.

[0x00001060]> iS
[Sections]

nth paddr        size vaddr       vsize perm name
―――――――――――――――――――――――――――――――――――――――――――――――――
...
16  0x00001060  0x185 0x00001060  0x185 -r-x .text
17  0x000011e8    0xd 0x000011e8    0xd -r-x .fini
18  0x00002000   0x12 0x00002000   0x12 -r-- .rodata
...

Is there a way to write in this section? or is there another way to modify strings?

update

this is the program

#include <stdio.h>
int main()
{
   printf("Hello, World!\n");
   return 0;
}

I want to change "Hello World!\n", this is how I am changing the string in radare2

$ r2 -w modified_helloworld
[0x00001060]> iz
[Strings]
nth paddr      vaddr      len size section type  string
―――――――――――――――――――――――――――――――――――――――――――――――――――――――
0   0x00002004 0x00002004 13  14   .rodata ascii Hello, World!

[0x00001060]> w Good, Bye!!!! @0x00002004
[0x00001060]> iz
[Strings]
nth paddr      vaddr      len size section type  string
―――――――――――――――――――――――――――――――――――――――――――――――――――――――
0   0x00002004 0x00002004 13  14   .rodata ascii Hello, World!

[0x00001060]>

As can be seen, I'm using the w command but when I check the string again, there are no changes. Thanks in advance.

2
  • 1
    Those permission are enforced during runtime by the system that is running your code no one can stop you from writing with an external program post your code and your errors that arise out of your experiments
    – blabb
    Jan 27, 2021 at 4:47
  • How are you changing the string?
    – Igor Skochinsky
    Jan 28, 2021 at 16:58

1 Answer 1

3

All is good. r2 doesn't refresh this .rodata by default after your change but if you go to the address 0x2004, you would see your change.

r2 -w modified_helloworld
w Good, Bye!!!! @0x00002004
s 0x2004
[0x00002004]> px
- offset -   0 1  2 3  4 5  6 7  8 9  A B  C D  E F  0123456789ABCDEF
0x00002004  476f 6f64 2c20 4279 6521 2121 2100 0000  Good, Bye!!!!...

If you want to see your change with iz just reload binary info with ib.

r2 -w modified_helloworld
w Good, Bye!!!! @0x00002004
[0x00001060]> iz
[Strings]
nth paddr      vaddr      len size section type  string
―――――――――――――――――――――――――――――――――――――――――――――――――――――――
0   0x00002004 0x00002004 13  14   .rodata ascii Hello, world!

[0x00001060]> ib
[0x00001060]> iz
[Strings]
nth paddr      vaddr      len size section type  string
―――――――――――――――――――――――――――――――――――――――――――――――――――――――
0   0x00002004 0x00002004 13  14   .rodata ascii Good, Bye!!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.