Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 11th, 2005, 1:37 AM   #1
liquidsilver
Newbie
 
liquidsilver's Avatar
 
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0 liquidsilver is on a distinguished road
Post Self Modifying Code

I've just recently started with SMC (Self Modifying Code) and I'm having some problems:

.model tiny
.stack
.data
  key db 01h
.code
org 0100h

mov cx,3
StrLoop:
  dec cx
  mov di,(offset fix)
  add di,cx
  mov al,[di]
  xor al,key
  mov [di],al
  jcxz OutLoop
  jmp StrLoop
OutLoop:

fix db 0B9h, 036h, 003h ;mov ax,0237h
  ret
end main

This is my SMC.COM source. This works, but when I convert it to a EXE then it goes haywire. The correct data seems to not get targeted. I use MASM, please help.
__________________
Small is beautiful
liquidsilver is offline   Reply With Quote
Old Mar 11th, 2005, 10:38 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I hardly know any ASM, but IIRC, you may have to change .model tiny to .model small or something.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 11th, 2005, 2:13 PM   #3
liquidsilver
Newbie
 
liquidsilver's Avatar
 
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0 liquidsilver is on a distinguished road
Maybe you misunderstood me. This is the code that works, when I change it from tiny to small model then it doesn't work.
__________________
Small is beautiful
liquidsilver is offline   Reply With Quote
Old Mar 11th, 2005, 3:26 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I see. In that case, I can't help you - distinct lack of knowledge here.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 12th, 2005, 12:44 PM   #5
liquidsilver
Newbie
 
liquidsilver's Avatar
 
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0 liquidsilver is on a distinguished road
Thanx anyway for trying. Anyone else?
__________________
Small is beautiful

Last edited by liquidsilver; Mar 12th, 2005 at 1:10 PM.
liquidsilver is offline   Reply With Quote
Old Mar 15th, 2005, 10:53 AM   #6
Madman
Newbie
 
Join Date: Mar 2005
Posts: 4
Rep Power: 0 Madman is on a distinguished road
Ok, I havent played with asm in a while but here's some key concepts to
remember. DOS or windows for that matter always loads a .com file so that the code segment and data segment is the same causing .com files never to
use more than 64kb without using special tricks

Things a bit different in a .exe file and ds and cs isn't nessecary the same
anymore. I myself havent really tried self modifying code but I can clearly see
how your prog works.

What probably happening is that your [di] not pointing to the right place
in memory from the start and then the wrong bytes get modified somewhere
else in memory.

Just make sure your exe starts like this :

dosseg

BUFSIZE EQU 1024

.stack
.data
 key db 01h
.code
main proc                
 mov ax,@data         ; load ds,es 
 mov ds,ax
 mov es,ax

 mov cx,3
 StrLoop:
  dec cx
  mov di,(offset fix)
  add di,cx
  mov al,[di]
  xor al,key
  mov [di],al
  jcxz OutLoop
  jmp StrLoop
OutLoop:
fix db 0B9h, 036h, 003h ;mov ax,0237h 

  mov ax,4C00h  ; exit to dos
  int 21h
 main endp

; if it still doesn't work then rather try define key here
; key db 01h
; and then set your ds = cs instead making it behave more like a .com file :
; mov ax,cs
; mov ds,ax 

end main

Hope this helps.

Anyway if someone else want to correct me on something here, please
do ( I'm still a bit rusty after not touching asm for 7 years )

Actually did some fun stuff back then like playing around with vga registers
and doing 3d stuff in asm ( definitely needs that putpixel routine as
fast as possible )

Last edited by Madman; Mar 15th, 2005 at 11:14 AM.
Madman is offline   Reply With Quote
Old Mar 16th, 2005, 1:54 PM   #7
liquidsilver
Newbie
 
liquidsilver's Avatar
 
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0 liquidsilver is on a distinguished road
Thanx, I'll try when I'm free.
__________________
Small is beautiful
liquidsilver is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC