Created
June 5, 2021 17:14
-
-
Save lemon-sh/512223b4c97bf61cf3fdb7c97283b2ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; LemonTimer 1.0 | |
; A simple desktop clock written in x86 ASM | |
; by ./lemon | |
format PE | |
entry start | |
include 'win32ax.inc' | |
section '.data' data readable writeable | |
; variables/reserved memory | |
stdout rd 1 | |
stdin rd 1 | |
ltime rw 8 | |
ccis dd 1,0 | |
; console window | |
cbsr dw 19,5 ; console win unprocessed size | |
isr dw 0,0,1,1 ; initial minimal size | |
wny rd 1 ; console win Y size | |
wnx rd 1 ; console win X size | |
chwnd rd 1 ; console win HWND | |
; menu | |
btntext db '[Exit]',0 | |
; format strings | |
fint db '%d',0 | |
; static strings | |
stime db 13,' Time: ',0 | |
title db 'LemonTimer',0 | |
section '.code' code readable executable | |
start: | |
mov esp, ebp | |
; s - Get the screen buffer | |
invoke GetStdHandle,-11 | |
mov dword [stdout], eax | |
; e - Get the screen buffer | |
; s - Size buffer and window | |
invoke GetConsoleWindow | |
mov dword [chwnd], eax | |
invoke scwi,dword [stdout],1,isr | |
invoke scsbs,dword [stdout],dword [cbsr] | |
mov ax, word [cbsr+2] | |
sub ax, 1 | |
shl eax, 16 | |
mov ax, word [cbsr] | |
sub ax, 1 | |
push eax | |
push 0 | |
mov eax, esp | |
invoke scwi,dword [stdout],1,eax | |
sub esp,8 | |
invoke Sleep,10 | |
invoke gwr,dword [chwnd],esp | |
mov eax, dword [esp+8] | |
sub eax, dword [esp] | |
mov dword [wnx], eax | |
mov eax, dword [esp+12] | |
sub eax, dword [esp+4] | |
mov dword [wny], eax | |
; e - Size buffer and window | |
; s - Center the window | |
mov ebx, esp | |
invoke getsm,48,0,ebx,0 | |
add esp, 8 | |
mov ecx, dword [wnx] | |
shr ecx, 1 | |
pop esi | |
shr esi, 1 | |
sub esi, ecx | |
mov ecx, dword [wny] | |
shr ecx, 1 | |
pop edi | |
shr edi, 1 | |
sub edi, ecx | |
invoke swp,dword [chwnd],-1,esi,edi,0,0,1 | |
invoke setitle,title | |
invoke GetStdHandle,-10 | |
mov dword [stdin],eax | |
invoke scm,eax,144 | |
invoke swl,dword [chwnd],-16,10CA0000h | |
; e - Center the window | |
; s - hide console cursor | |
invoke scci,dword [stdout],ccis | |
; e - hide console cursor | |
; s - render the button | |
invoke sccp,dword [stdout],30006h | |
invoke scta,dword [stdout],11 | |
invoke printf,btntext | |
add esp,4 | |
invoke sccp,dword [stdout],10000h | |
; e - render the button | |
; s - display time | |
mov edi, 65535 ; bitmask | |
timelp: | |
invoke glt,ltime | |
invoke scta,dword [stdout],14 | |
invoke printf,stime | |
add esp,4 | |
invoke scta,dword [stdout],10 | |
movzx esi, word [ltime+8] ; hours | |
invoke printf,fint,esi | |
add esp,8 | |
invoke putchar,58 ; colon | |
add esp,4 | |
movzx esi, word [ltime+10] ; minutes | |
cmp esi, 9 | |
ja here0 | |
invoke putchar,48 | |
add esp,4 | |
here0: | |
invoke printf,fint,esi | |
add esp,8 | |
invoke putchar,58 ; colon | |
add esp,4 | |
movzx esi, word [ltime+12] ; seconds | |
cmp esi, 9 | |
ja here1 | |
invoke putchar,48 | |
add esp,4 | |
here1: | |
invoke printf,fint,esi | |
add esp,4 | |
; ns - console input reading | |
invoke gnoc,dword [stdin],esp | |
pop edi | |
cmp edi, 0 | |
je continuum0 | |
sub esp,24 | |
mov ebx, esp | |
mov edx, esp | |
add edx, 20 | |
restart0: | |
invoke rci,dword [stdin],ebx,1,edx | |
cmp dword [esp], 2 | |
jne continuum1 | |
cmp dword [esp+8], 1 | |
jne continuum1 | |
movzx eax, word [esp+6] ;y | |
cmp eax, 3 | |
jne continuum1 | |
movzx eax, word [esp+4] ;x | |
cmp eax, 6 | |
jl continuum1 | |
cmp eax, 11 | |
jg continuum1 | |
; if button was pressed, execution jumps here: | |
invoke ExitProcess,0 | |
continuum1: | |
sub edi, 1 | |
cmp edi, 0 | |
jne restart0 | |
add esp,24 | |
; ne - console input reading | |
continuum0: | |
invoke Sleep,400 | |
jmp timelp | |
; e - display time | |
section '.idata' import data readable | |
library kernel32,'KERNEL32.DLL',\ | |
libc,'MSVCRT.DLL',\ | |
userlib,'USER32.DLL' | |
import kernel32,\ | |
GetStdHandle,'GetStdHandle',\ | |
ExitProcess,'ExitProcess',\ | |
Sleep,'Sleep',\ | |
GetConsoleWindow,'GetConsoleWindow',\ | |
scta,'SetConsoleTextAttribute',\ | |
glt,'GetLocalTime',\ | |
scci,'SetConsoleCursorInfo',\ | |
scwi,'SetConsoleWindowInfo',\ | |
scsbs,'SetConsoleScreenBufferSize',\ | |
setitle,'SetConsoleTitleA',\ | |
scm,'SetConsoleMode',\ | |
gnoc,'GetNumberOfConsoleInputEvents',\ | |
rci,'ReadConsoleInputA',\ | |
fcib,'FlushConsoleInputBuffer',\ | |
sccp,'SetConsoleCursorPosition' | |
import userlib,\ | |
getsm,'SystemParametersInfoA',\ | |
gwr,'GetWindowRect',\ | |
swp,'SetWindowPos',\ | |
swl,'SetWindowLongA' | |
import libc,\ | |
printf,'printf',\ | |
putchar,'putchar' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment