News:

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

Code segment permissions

Started by demius2q, March 25, 2006, 11:22:39 AM

Previous topic - Next topic

demius2q

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




hutch--

Look up the linker options to make the .code section writable.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

demius2q

Many thanks for the attention.
will Try to find ::)

sluggy

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.


demius2q

sorry. i am new in the forums. will follow your advise

demius2q

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