![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I hardly know any ASM, but IIRC, you may have to change .model tiny to .model small or something.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I see. In that case, I can't help you - distinct lack of knowledge here.
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0
![]() |
Thanx anyway for trying. Anyone else?
![]()
__________________
Small is beautiful Last edited by liquidsilver; Mar 12th, 2005 at 1:10 PM. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0
![]() |
Thanx, I'll try when I'm free.
__________________
Small is beautiful |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|