The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: theman on February 13, 2005, 02:03:59 PM

Title: Make section writable
Post by: theman on February 13, 2005, 02:03:59 PM
Hi .
How can i make the code section writable??
Title: Re: Make section writable
Post by: Jibz on February 13, 2005, 02:31:18 PM
If you're using MS link, try /SECTION:.text,ERW
Title: Re: Make section writable
Post by: chetnik on February 19, 2005, 05:58:59 PM
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 :)
Title: Re: Make section writable
Post by: Vortex on February 22, 2005, 07:54:34 PM
Hi chetnik,

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

include \tasm32\include\w32.inc
include \tasm32\include\pe.inc
Title: Re: Make section writable
Post by: chetnik on February 25, 2005, 03:47:57 AM
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]
Title: Re: Make section writable
Post by: Vortex on February 26, 2005, 03:16:32 PM
Hi chetnik,

Many thanks for the attachment :U
Title: Re: Make section writable
Post by: chetnik on February 26, 2005, 10:28:40 PM
no problem man  :green