Professional Documents
Culture Documents
OS Lab 11 Eng
OS Lab 11 Eng
Методичні вказівки
до курсу “Операційні системи”
для студентів базової вищої освіти
за напрямком “Комп’ютерні науки”
Львів - 2022
Laboratory work #11
.586
.model flat,STDCALL
extrn SHGetSpecialFolderLocation:Proc
extrn MessageBoxA:Proc
extrn ExitProcess:Proc
extrn SHGetPathFromIDList:Proc
.data
INDEX dd 0 ; index of the folder
DIRECTORY_ID dd 0 ; handle of the folder
DIRECTORY_NAME db 512 dup(0) ; Folder path
T db ' Cпеціальна папка:',0
.code
Start: push offset DIRECTORY_ID ; The result of function
push INDEX ; input folder index
push 0 ; not used
call SHGetSpecialFolderLocation
inc INDEX
cmp INDEX,65 ; index to be less than 65
jnc STOP
push offset DIRECTORY_NAME ; Result: folder name and path
push DIRECTORY_ID ; handle of folder (see function before)
call SHGetPathFromIDList
; Output the Special Folder path and name:
call MessageBoxA,0,offset DIRECTORY_NAME,offset T,1
cmp eax,1
jz Start
STOP: call ExitProcess,0
end Start
.586
.model flat,STDCALL
extrn ExitProcess:Proc, MessageBoxA:Proc
extrn EnumWindows:Proc
extrn GetWindowTextA:Proc, SendMessageA:Proc
MB_YESNOCANCEL equ 3h
IDCANCEL equ 2
IDYES equ 6
IDNO equ 7
WM_CLOSE equ 10h
.data
TITLE1 db 'Keep this window open?',0
WND_NAME db 200 dup(0)
;===============================
.code
Start: push 0 ; not used
push offset PROG1 ; CallBack-function address;
call EnumWindows
STOP: call ExitProcess,0
;======================== Procedure of CallBack:
cmp eax,IDNO
jnz STOP_ENUM
; If pressed «NO», the window will close:
call SendMessageA,hwnd, WM_CLOSE,0,0
jmp CONT_ENUM1
STOP_ENUM:
xor eax,eax ; eax = 0 – finish enumeration.
jmp EX_PROG1
CONT_ENUM1: ; eax = 1 – continue enumeration
mov eax,1
EX_PROG1:
Ret ; Return from Callback to EnumWindows.
Endp PROG1
End Start
.586
.model flat,STDCALL
extrn ExitProcess:Proc, RegOpenKeyA: Proc, RegEnumKeyExA:Proc
extrn MessageBoxA:Proc
HKEY_CURRENT_USER equ 80000001h
.data
SizeKeyClassName dd 260 ; maximal size of key name
KeyClassName db 'Software\Microsoft\Internet
Explorer',260 dup(0)
SizeSubKeyName dd 260
SubKeyName db 260 dup(0)
IndexKey dd 0 ; Key index (input value)
KeyHandle dd 0 ; Key handle;
KeyTime dq 0 ; creation or changed packed time
;===========================================
.code
Start: push offset KeyHandle ; The result address
push offset KeyClassName ; KeyName;
push HKEY_CURRENT_USER ; Section of the registry;
call RegOpenKeyA ; System API call;
or eax,eax
jnz STOP ; On error go to Stop.
NEXT_KEY:
; Refresh size of buffer
mov SizeSubKeyName,260
mov SizeKeyClassName,260
push offset KeyTime ; result time
push offset SizeKeyClassName ; result size
push offset KeyClassName ; result name
push 0 ; not used
push offset SizeSubKeyName ; result size
push offset SubKeyName ; result name
push IndexKey ; input index
push KeyHandle ; input handle.
call RegEnumKeyExA ; Get all key information
cmp eax,0 ; якщо eax=0, то успішне виконання,
jnz STOP ; інакше підключів не існує
You need to first find out the time of creation of each key
that is displayed by this program, and then create your own key
in the "Software" section, display the time of its creation (the
same time is the time of change), and then delete the created
key. To get the key generation time, replace the loop
termination command "jz NEXT_KEY" with "jz
GET_KEY_TIME". Place the new label GET_KEY_TIME
after the call ExitProcess,0 on a separate line. Start a new
program fragment with the time format conversion function:
then add the time output snippet from the lab that outputted the
system time without the "GetLocalTime" operation. End the
fragment with a "jmp NEXT_KEY" transition to continue the
key listing loop.
To create your own key, use the following program:
.586
.model flat,stdcall
extrn RegCreateKeyExA:Proc, RegSetValueExA:Proc,
RegCloseKey:Proc, MessageBoxA:Proc, ExitProcess:Proc, lstrlen:Proc
HKEY_CURRENT_USER equ 80000001h
KEY_ALL_ACCESS equ 0f003fh
REG_SZ equ 1 ; тип даних ключа – текстовий рядок
.data
KEY_NAME db "SOFTWARE\Lab_work\Registration",0
NAME1 db "Студент",0
VALUE1 db "Петренко Петро Петрович",0
ERR_TEXT1 db "Помилка створення ключа",0
DISP_TEXT1 db "Створили новий ключ",0
DISP_TEXT2 db "Відкрили існучий ключ",0
Result_KEY dd 0
Disposition dd 0
.code
Start: call RegCreateKeyExA,HKEY_CURRENT_USER,offset
KEY_NAME,0,0,0,KEY_ALL_ACCESS,0,offset Result_KEY,offset
Disposition
cmp eax,0
jz C_OK1
call MessageBoxA,0,offset ERR_TEXT1,0,10h
C_OK1:
.if Disposition==1
call MessageBoxA,0,offset KEY_NAME,offset DISP_TEXT1,40h
.endif
.if Disposition==2
call MessageBoxA,0,offset KEY_NAME,offset DISP_TEXT2,30h
.endif
call lstrlen,offset VALUE1
call RegSetValueExA, Result_KEY, offset NAME1,0,REG_SZ,
offset VALUE1,eax
call RegCloseKey, Result_KEY
call ExitProcess,0
end Start
.586
.model flat, stdcall
Extrn RegDeleteKeyA:Proc, MessageBoxA:Proc, ExitProcess:Proc
HKEY_CURRENT_USER equ 80000001h
.data
TEXT_DELETE_KEY db "Key has been deleted:",0
TEXT_ERR_KEY db "Check the next registry key:",0
KEY_NAME1 db "SOFTWARE\Lab_work\Registration",0
KEY_NAME2 db "SOFTWARE\Lab_work",0
.code
Start: call RegDeleteKeyA, HKEY_CURRENT_USER, offset
KEY_NAME1
call RegDeleteKeyA, HKEY_CURRENT_USER, offset
KEY_NAME2
.if eax==0
call MessageBoxA, 0, offset KEY_NAME1, offset
TEXT_DELETE_KEY, 40h
jmp STOP
.endif
call MessageBoxA, 0, offset KEY_NAME1, offset
TEXT_ERR_KEY, 10h
STOP: call ExitProcess,0
end Start
CONTROL QUESTIONS
1. How do the functions of the list of system objects work?
2. What is a specialized system folder?
3. How does the registry differ from a specialized folder?
4. What specialized folders do you know?
5. What is a folder handle?
6. How to get the name of the specialized folder through the
handle?
7. What does the SystemParametersInfoA function do?
8. What list API functions do you know?
9. How to get the name of the window class?
10. What sections exist in the system registry?