Hi ppl, I've declared two labels in my little code, I read some values from the first and write some values to the second, but when I write to the second I got an exception "memory cant be written", the two labels arent declared in .data section so what Im doing wrong ?



mov dword ptr , eax

Address label dword
addr1 dd 0
addr2 dd 7654321h
dd 0
Posted on 2003-06-05 08:08:26 by stwu
.code section is defined as readable+exutable but not writable. Thus the error "Memory cannot be written". Either change your section attribute or store the above in the .data. Anyway .data section is declared as writable+readable, thus you can read and write from/to it
Posted on 2003-06-05 08:12:45 by roticv
I did a lame code to change the section attribute in the pe header but it doesnt work.

add esi,
movzx edi, word ptr
lea edi,
mov eax,dword ptr
add eax,20000000h
Posted on 2003-06-05 15:13:18 by stwu
Listen to Roticv
Posted on 2003-06-05 15:36:09 by iblis
If you are using MASM32, you can try OPTION NOREADONLY:

Syntax: OPTION READONLY

OPTION NOREADONLY

Description:

The READONLY option sets the READONLY attribute for subsequent code
segments. Enables checking for instructions that explicitly modify
segments or groups containing code. Useful for detecting self-
modifying code. NOREADONLY is the default.

This option replaces the command-line /P option from previous
versions of the assembler. Segments can be also be made read-

only with the READONLY parameter of the SEGMENT directive.
-o-
Posted on 2003-06-05 15:59:38 by MazeGen
Originally posted by stwu
I did a lame code to change the section attribute in the pe header but it doesnt work.

add esi,
movzx edi, word ptr
lea edi,
mov eax,dword ptr
add eax,20000000h

I mean changing the section attribute via linker option if I remember correctly.

Anyway to make the the section writable you should be doing "or eax, IMAGE_SCN_MEM_WRITE" and "IMAGE_SCN_MEM_WRITE" is defined in windows.inc as "IMAGE_SCN_MEM_WRITE equ 80000000h"

If I remember correctly a code section that is writeable+excutable+readable should be E000002h.
Posted on 2003-06-06 01:51:33 by roticv