I’m getting “access violation while writing” error in the below code while putting null byte in the string last character checked via Ollydbg, Can anyone please help in in sorting this out, thanks
[SECTION .text]
global _start
_start:
jmp short stuff
code:
pop esi
xor eax,eax
mov byte [esi + 17],al ; put a null byte byte on [esi + 17]
stuff:
call code
db 'This is my string#'
You’re running a self-modifying code: depending on the platform, it may work or not. In protected mode, it will not work, because the code segment is read-only (it would work perfectly in DOS on a 386)
You must put the strings in the data segment, or instruct the linker to place a “writeable” tag in the .text segment (something like:
/SECTION:.text,EWR).This last method is frowned upon, because (a) it is poor coding practice, (b) it is used by so-called “polymorphic” virus engines, and disapproved by antivirus software, (c) may interfere with virtualized environment operations, finally (d) may not work, apparently at random, with some hardware configurations due to processor prefetch.
Unless you have a really pressing reason to do so, I’d suggest declaring a data segment and place your string there.