flat assembler
Message board for the users of flat assembler.
Index
> Windows > Implementing a FORTH system |
Author |
|
chriscurl 20 May 2020, 21:10
Here is my little program to tell me if CS == DS ...
Code: ; Test to see if CS and DS are equal include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here section '.text' code readable writeable executable start: mov eax, cs mov edx, ds cmp eax, edx je yyy invoke MessageBox,HWND_DESKTOP,"No, CS != DS","Comparison",MB_OK jmp zzz yyy: invoke MessageBox,HWND_DESKTOP,"Yes, CS == DS","Comparison",MB_OK zzz: invoke ExitProcess,0 .end start |
|||
20 May 2020, 21:10 |
|
DimonSoft 20 May 2020, 22:32
One shouldn’t really bother what values are in segment registers while writing Windows applications (well, until it comes to using some more advanced stuff like SEH, and even then only the value meaning is of some importance). And segments are of little to no importance in implementing read-only/read-write/execute access to memory ranges.
|
|||
20 May 2020, 22:32 |
|
chriscurl 20 May 2020, 23:17
So this looks like it will work! And yeah, I guess it doesn't matter if CS != DS.
Code: ; Test to see if I can "generate" code include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here section '.text' code readable writeable executable xxsub1: dd 0 db 0 invoke MessageBox,HWND_DESKTOP,"First subroutine", "Su1b",MB_OK ret xxsub2: dd xxsub1 db 0 invoke MessageBox,HWND_DESKTOP,"Second subroutine", "Sub2",MB_OK ret xxsub3: dd xxsub2 db 0 invoke MessageBox,HWND_DESKTOP,"Third subroutine", "Sub3",MB_OK ret start: ; change the first instruction in sub2 to ret mov ecx, xxsub3 mov ecx, [ecx] add ecx, 5 mov al, 0xC3 mov [ecx], al ; This should call sub1 mov ecx, xxsub3 mov ecx, [ecx] mov ecx, [ecx] add ecx, 5 call ecx ; this should call sub2, which should just return now mov ecx, xxsub3 mov ecx, [ecx] add ecx, 5 call ecx ; "generate" code ... copy sub3 to sub4 mov esi, xxsub3 add esi, 5 mov edi, xxsub4 add edi, 5 mov ecx, 250 cld rep movsb ; call the newly "generated" code, sub4 mov ecx, xxsub4 add ecx, 5 call ecx ; compare CS and DS mov eax, cs mov edx, ds cmp eax, edx je yyy invoke MessageBox,HWND_DESKTOP,"No, CS != DS","Comparison",MB_OK jmp zz yyy: invoke MessageBox,HWND_DESKTOP,"Yes, CS == DS","Comparison",MB_OK zz: invoke ExitProcess,0 xxsub4: dd xxsub3 db 0 db 0 dup 256 .end start |
|||
20 May 2020, 23:17 |
|
revolution 21 May 2020, 00:02
Just a note that if you plan to publish this code for others to run, then some AVs get upset with writeable code sections and self modifying code. It's the kind of trick that malware does to try and avoid detection.
|
|||
21 May 2020, 00:02 |
|
chriscurl 21 May 2020, 00:28
Fair enough ... this is just a hobby project though, but it will be in GitHub for anyone who wants to fork and play with.
|
|||
21 May 2020, 00:28 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.