The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: demius2q on March 25, 2006, 11:22:39 AM

Title: Code segment permissions
Post by: demius2q on March 25, 2006, 11:22:39 AM
Hello to everybody!
I am writing on masm32 under xp pro.
Kode should crypt and decrypt itself during runtime
But as suun as itry to modify the code during runtime(code) OS terminates my application.
Maybe code segment should have "write" permission. whow to do this?
Kindly help as i am  :(k!!!
code is belo
---------------------------------------------------------------------
     .386p

      .model flat, stdcall
      option casemap :none   ; case sensitive
       
; ----------------------------------------------------------------------------------------------------------------------
      include \masm32\include\windows.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc

      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
; ----------------------------------------------------------------------------------------------------------------------

.code
     
start:

        pushad                                  ; Push all the registers
        pushfd                                  ; Push the FLAG register
       jmp    d     

      MsgCaption    db "Minimum crypto MASM",0
      MsgBoxText    db "  --- crypted! -- Start decrypt?---  ",0
         MsgCaption_1    db "Minimum decrypto MASM",0
      MsgBoxText_1    db "  --- Assembler decrypted ---  ",0
   

;----------------------------------------------------------------------------------------------------------------------

d: 
;----------------------------------------------------------------------------------------------------------------------
              pushad
   call      Crypt
              popad
;----------------------------------------------------
    push MB_OK
    push offset MsgCaption
    push offset MsgBoxText
    push 0
    call MessageBox
;-----------------------------------------------------
             pushad
             call      Crypt
             popad




CryptStart:   
      
;----------------------------------------------------
    push MB_OK
    push offset MsgCaption_1
    push offset MsgBoxText_1
    push 0
    call MessageBox
;-----------------------------------------------------
CryptEnd:

push 0
    call ExitProcess





;------------------------------------------------------------------------------
;Encrypt/Decrypt Data
;------------------------------------------------------------------------------
Crypt:
   mov      esi, offset CryptStart
   mov      ah, 23h ;key
   mov      ecx, CryptEnd-CryptStart

CryptLoop:
   xor      byte ptr [esi], ah
   inc      esi
   loop      CryptLoop
   ret
   

;-------------------------------------------------------------------------------
end start



Title: Re: Code segment permissions
Post by: hutch-- on March 25, 2006, 12:43:56 PM
Look up the linker options to make the .code section writable.
Title: Re: Code segment permissions
Post by: demius2q on March 25, 2006, 02:11:59 PM
Many thanks for the attention.
will Try to find ::)
Title: Re: Code segment permissions
Post by: sluggy on March 25, 2006, 10:49:11 PM
demius2q,
when you have a question, do not post it into multiple forums - that is commonly called cross-posting or spamming. I have removed your post from the Campus.

Title: Re: Code segment permissions
Post by: demius2q on March 25, 2006, 11:23:24 PM
sorry. i am new in the forums. will follow your advise
Title: Re: Code segment permissions
Post by: demius2q on March 26, 2006, 02:07:44 AM
Finally i found it.
For those who are interested and for the sake of good order It should look like this:
-----------------------
Link /section:.text,rwe
-------------------------------
regret to mention that masm32 help is very limitrd on the subject. :eek