News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Make section writable

Started by theman, February 13, 2005, 02:03:59 PM

Previous topic - Next topic

theman

Hi .
How can i make the code section writable??

Jibz

If you're using MS link, try /SECTION:.text,ERW

chetnik

Or you can simply write program to do that (b/c TASM doesn't suport /SECTION:.text,rwe) and here is the code

586
.model flat, stdcall
locals
jumps
UNICODE=0
include \tasm32\include\w32.inc
include \tasm32\include\pe.inc

null equ NULL

.data
  file    dd ? 
  fd      dd ?
  temp    dd ?
  memptr  dd ?
.code
start:
          call GetCommandLineA
          mov edi, eax
          mov eax, 20h
          mov ecx, 260
          cld
          repnz scasb
          mov file, edi
         
          call CreateFileA, file, GENERIC_READ or GENERIC_WRITE, null,null, OPEN_EXISTING, null, null
          or eax, eax
          js __exit_pewrite
          mov fd, eax
          call CreateFileMappingA, eax, null, PAGE_READWRITE, null, null, null
          test eax, eax
          jz __exit_pewrite
          mov temp, eax
          call MapViewOfFile, eax, FILE_MAP_ALL_ACCESS, null, null, null
          test eax, eax
          jz __exit_pewrite
          mov memptr, eax
         
          mov ebx, eax
          add ebx, dword ptr[ebx +3ch]
          movzx ecx, [ebx.NT_FileHeader.FH_NumberOfSections]
          add ebx, size IMAGE_NT_HEADERS
__change_protection:
          or [ebx.SH_Characteristics], IMAGE_SCN_MEM_WRITE
          add ebx, size IMAGE_SECTION_HEADER
          loop __change_protection
         
          call UnmapViewOfFile, memptr
          call CloseHandle, temp
          call CloseHandle, fd
__exit_pewrite:
          call ExitProcess, null
end start


Best regards :)

Vortex

Hi chetnik,

How to get these two files to assemble your TASM example?

include \tasm32\include\w32.inc
include \tasm32\include\pe.inc

chetnik

oh sorry  :'( I'll attach them, pe.inc is Jacky Qwerty's inc for PE files and w32.inc is default include file that comes with tasm32 5.0



[attachment deleted by admin]

Vortex

Hi chetnik,

Many thanks for the attachment :U

chetnik