Ayant trouver un petit compilateur assembleur extrêmement puissant (FASM), me voila lancer pour développer un petit logiciel en assembleur Win32. Ce logiciel est simple il permet de tracer les connexions à un ordinateur. Si vous rajouter ce logiciel au lancement de la machine il écrira dans un fichier de log, la date et l’heure du démarrage. Si une demande de fermeture de Windows est demandé on log aussi l’heure. Et le petit plus, et que si la session est locké (touche Windows+L) ceci est aussi tracé.
; Simple text editor - fasm example program
format PE GUI 4.0
entry start
include ‘win32a.inc’
IDM_NEW = 101
IDM_EXIT = 102
IDM_ABOUT = 901
section ‘.data’ data readable writeable
_class TCHAR ‘SESSION32′,0
_edit TCHAR ‘EDIT’,0
_title TCHAR ‘Session’,0
_about_title TCHAR ‘About Session’,0
_about_text TCHAR ‘This is Win32 example program created with flat assembler.’,0
_error TCHAR ‘Startup failed.’,0
_error1 TCHAR ‘Unable to open’,0
_text TCHAR ‘Hello’,0
_sessionStart TCHAR ‘Session start’, 0
_sessionStop TCHAR ‘Session stop’, 0
_sessionLock TCHAR ‘Session lock’, 0
_sessionUnlock TCHAR ‘Session unlock’, 0
_file TCHAR ‘session.txt’,0
_dwWritted dd ?
_handle dd ?
_time SYSTEMTIME 0
_buff TCHAR 255 dup(0)
_strFmtDate TCHAR 0x0D, 0x0A, ‘%0.2d/%0.2d/%0.4d ‘,0
_strFmtTime TCHAR ‘%0.2d:%0.2d:%0.2d ‘,0
wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class
edithwnd dd ?
editfont dd ?
msg MSG
client RECT
section ‘.code’ code readable executable
start:
invoke GetModuleHandle,0
mov [wc.hInstance],eax
invoke LoadIcon,eax,17
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
invoke RegisterClass,wc
test eax,eax
jz error
invoke LoadMenu,[wc.hInstance],37
invoke CreateWindowEx,0,_class,_title,WS_OVERLAPPEDWINDOW,144,128,256,256,NULL,eax,[wc.hInstance],NULL
test eax,eax
jz error
;BOOL ret = WTSRegisterSessionNotification(hwnd, NOTIFY_FOR_THIS_SESSION);
invoke WTSRegisterSessionNotification, eax, 0
test eax,eax
jz error
msg_loop:
invoke GetMessage,msg,NULL,0,0
cmp eax,1
jb end_loop
jne msg_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop
error:
invoke MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK
end_loop:
invoke ExitProcess,[msg.wParam]
proc WriteToFile text
invoke CreateFile, _file, GENERIC_READ+GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
mov [_handle], eax
test eax,INVALID_HANDLE_VALUE
;Va a la fin du fichier
invoke SetFilePointer, [_handle], 0, 0, FILE_END
invoke GetSystemTime, _time
movzx ecx,[_time.wYear]
movzx ebx,[_time.wMonth]
movzx eax,[_time.wDay]
invoke wsprintf, _buff, _strFmtDate, eax, ebx, ecx
invoke lstrlen, _buff
invoke WriteFile, [_handle], _buff, eax, _dwWritted, 0
movzx eax,[_time.wHour]
movzx ebx,[_time.wMinute]
movzx ecx,[_time.wSecond]
invoke wsprintf, _buff, _strFmtTime, eax, ebx, ecx
invoke lstrlen, _buff
invoke WriteFile, [_handle], _buff, eax, _dwWritted, 0
invoke lstrlen, [text]
invoke WriteFile, [_handle], [text], eax, _dwWritted, 0
or eax,eax
jz error1
invoke CloseHandle, [_handle]
ret
error1:
invoke MessageBox,NULL,_error1,NULL,MB_ICONERROR+MB_OK
ret
endp
proc WindowProc hwnd,wmsg,wparam,lparam
push ebx esi edi
cmp [wmsg],WM_CREATE
je .wmcreate
cmp [wmsg],WM_QUERYENDSESSION
je .wmqueryendsession
cmp [wmsg],WM_DESTROY
je .wmdestroy
cmp [wmsg],0x02B1 ;WM_WTSSESSION_CHANGE
je .wmsessionchange
.defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp .finish
.wmcreate:
; Ecrire dans le fichier
stdcall WriteToFile, _sessionStart
jmp .finish
.wmqueryendsession:
; Ecrire dans le fichier
stdcall WriteToFile, _sessionStop
jmp .wmdestroy ; On quit
.wmsessionchange:
mov eax, [wparam]
and eax, 0×7 ;WTS_SESSION_LOCK
jnz .sessionlock
mov eax, [wparam]
and eax, 0×8 ;WTS_SESSION_UNLOCK
jnz .sessionunlock
jmp .finish
.sessionlock:
stdcall WriteToFile, _sessionLock
jmp .finish
.sessionunlock:
stdcall WriteToFile, _sessionUnlock
jmp .finish
.wmdestroy:
invoke WTSUnRegisterSessionNotification, [hwnd]
invoke PostQuitMessage,0
xor eax,eax
.finish:
pop edi esi ebx
ret
endp
section ‘.idata’ import data readable writeable
library kernel,’KERNEL32.DLL’,\
user,’USER32.DLL’,\
gdi,’GDI32.DLL’,\
WtsApi,’WtsApi32.DLL’
import WtsApi,\
WTSRegisterSessionNotification, ‘WTSRegisterSessionNotification’,\
WTSUnRegisterSessionNotification, ‘WTSUnRegisterSessionNotification’
import kernel,\
GetModuleHandle,’GetModuleHandleA’,\
ExitProcess,’ExitProcess’,\
CreateFile,’CreateFileA’,\
CloseHandle,’CloseHandle’,\
WriteFile,’WriteFile’,\
SetFilePointer,’SetFilePointer’,\
GetSystemTime,’GetSystemTime’,\
lstrlen,’lstrlen’
import user,\
RegisterClass,’RegisterClassA’,\
CreateWindowEx,’CreateWindowExA’,\
DefWindowProc,’DefWindowProcA’,\
SetWindowLong,’SetWindowLongA’,\
RedrawWindow,’RedrawWindow’,\
GetMessage,’GetMessageA’,\
TranslateMessage,’TranslateMessage’,\
DispatchMessage,’DispatchMessageA’,\
SendMessage,’SendMessageA’,\
LoadCursor,’LoadCursorA’,\
LoadIcon,’LoadIconA’,\
LoadMenu,’LoadMenuA’,\
GetClientRect,’GetClientRect’,\
MoveWindow,’MoveWindow’,\
SetFocus,’SetFocus’,\
MessageBox,’MessageBoxA’,\
PostQuitMessage,’PostQuitMessage’,\
wsprintf,’wsprintfA’
import gdi,\
CreateFont,’CreateFontA’,\
DeleteObject,’DeleteObject’
section ‘.rsrc’ resource data readable
; resource directory
directory RT_MENU,menus,\
RT_ICON,icons,\
RT_GROUP_ICON,group_icons,\
RT_VERSION,versions
; resource subdirectories
resource menus,\
37,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu
resource icons,\
1,LANG_NEUTRAL,icon_data
resource group_icons,\
17,LANG_NEUTRAL,main_icon
resource versions,\
1,LANG_NEUTRAL,version
menu main_menu
menuitem ‘&File’,0,MFR_POPUP
menuitem ‘&New’,IDM_NEW
menuseparator
menuitem ‘E&xit’,IDM_EXIT,MFR_END
menuitem ‘&Help’,0,MFR_POPUP + MFR_END
menuitem ‘&About…’,IDM_ABOUT,MFR_END
icon main_icon,icon_data,’minipad.ico’
versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLA