输入格式:
format PE GUI 4.0
entry Start
include 'win32a.inc'
include 'res.inc'
include 'winlib.inc'
SLQite常量声明(相当于C的宏):
SQLITE_OK = 0 ; Successful result
; beginning-of-error-codes
SQLITE_ERROR = 1 ; SQL error or missing database
SQLITE_INTERNAL = 2 ; Internal logic error in SQLite
SQLITE_PERM = 3 ; Access permission denied
SQLITE_ABORT = 4 ; Callback routine requested an abort
SQLITE_BUSY = 5 ; The database file is locked
SQLITE_LOCKED = 6 ; A table in the database is locked
SQLITE_NOMEM = 7 ; A malloc() failed
SQLITE_READONLY = 8 ; Attempt to write a readonly database
SQLITE_INTERRUPT = 9 ; Operation terminated by sqlite3_interrupt()
SQLITE_IOERR = 10 ; Some kind of disk I/O error occurred
SQLITE_CORRUPT = 11 ; The database disk image is malformed
SQLITE_NOTFOUND = 12 ; Unknown opcode in sqlite3_file_control()
SQLITE_FULL = 13 ; Insertion failed because database is full
SQLITE_CANTOPEN = 14 ; Unable to open the database file
SQLITE_PROTOCOL = 15 ; Database lock protocol error
SQLITE_EMPTY = 16 ; Database is empty
SQLITE_SCHEMA = 17 ; The database schema changed
SQLITE_TOOBIG = 18 ; String or BLOB exceeds size limit
SQLITE_CONSTRAINT = 19 ; Abort due to constraint violation
SQLITE_MISMATCH = 20 ; Data type mismatch
SQLITE_MISUSE = 21 ; Library used incorrectly
SQLITE_NOLFS = 22 ; Uses OS features not supported on host
SQLITE_AUTH = 23 ; Authorization denied
SQLITE_FORMAT = 24 ; Auxiliary database format error
SQLITE_RANGE = 25 ; 2nd parameter to sqlite3_bind out of range
SQLITE_NOTADB = 26 ; File opened that is not a database file
SQLITE_ROW = 100 ; sqlite3_step() has another row ready
SQLITE_DONE = 101 ; sqlite3_step() has finished executing
; end-of-error-codes
section '.rdata' data readable
_dbfile db 'sqlite3.dbz', $0
_sql_create_info_table db 'create table if not exists t_local_filesystem_info ('
db 'id integer primary key autoincrement,'
db 'crc integer,'
db 'size integer,'
db 'attribute integer,'
db 'refer_count integer,'
db 'create_date integer,'
db 'modify_date integer,'
db 'access_date integer,'
db 'description text,'
db 'keywords text,'
db 'location text,'
db 'name text,'
db 'type text,'
db 'md5 text,'
db 'key text'
db ')', $0
_sql_create_path_table db 'create table if not exists t_local_filesystem_path ('
db 'id integer primary key autoincrement,'
db 'name text,'
db 'path text,'
db 'root text,'
db 'machine text,'
db 'category text,'
db 'description text,'
db 'isfolder integer,'
db 'issearched integer,'
db 'search_date integer,'
db 'search_count integer,'
db 'key_parent text,'
db 'key text'
db ')', $0
_sql_query_insert_info db 'insert into table t_local_filesystem_info', $0
_sql_query_insert_path db 'insert into table t_local_filesystem_path', $0
_sql_query_select_info db 'select * from t_local_filesystem_info', $0
_sql_query_select_path db 'select * from t_local_filesystem_path', $0
_sql_query_delete_info db 'delete t_local_filesystem_info where id = "%d"', $0
_sql_query_delete_path db 'delete t_local_filesystem_path where id = "%d"', $0
_sql_query_update_info db 'update t_local_filesystem_info set md5="" where id = "%d"', $0
_sql_query_update_path db 'update t_local_filesystem_path set md5="" where id = "%d"', $0
_format db '%d\n', $0
_time_format db '%d:%d:%d.%d', $0
_date_format db '%d-%d-%d %d:%d:%d.%d', $0
_title db 'Task View', $0
_wnd_cls db 'TaskMgr', $0
_rebar_cls db 'ReBarWindow32', $0
_listvw_cls db 'SysListView32', $0
_toolbar_cls db 'ToolbarWindow32', $0
section '.data' data readable writeable
_global dd 0
winobj dd 0
bufferSize dd $1000
section '.data?' readable writeable
_inst dd ?
_sqlite3 dd ?
_sqlite3_query dd ?
listview dd ?
statusbar dd ?
toolbar dd ?
parent dd ?
rebar dd ?
timer dd ?
hheap dd ?
buffer dd ?
fileTime dq ?
_printbuffer CHAR $2ff
_stringbuffer CHAR $2ff
_seh_buffer CHAR $300
tbbmp TBADDBITMAP
sym SYSTEMTIME
lvc LVCOLUMN
lvi LVITEM
rct RECT
msg MSG
section '.text' code readable executable
Start:
invoke GetModuleHandle, NULL
mov [_inst], eax
invoke InitCommonControls
; 注意啊,声明全局变量直接减栈指针就行,这也是最低级的操作了。
; Declaring a local variable defined as FINDDATA struct.
; The ESP register was pointto the first address of the variable.
add esp, not (sizeof.INITCOMMONCONTROLSEX and $fffc + $3)
mov dword [esp + INITCOMMONCONTROLSEX.dwSize], sizeof.INITCOMMONCONTROLSEX
mov dword [esp + INITCOMMONCONTROLSEX.dwICC], ICC_COOL_CLASSES
invoke InitCommonControlsEx, esp
or eax, eax
jz .Quit
push 0
push [_inst]
call winCreate
or eax, eax
jz .Quit
mov [winobj], eax
push _title
push [winobj]
call winSetTitle
push Win1_OnCreate
push WM_CREATE
push [winobj]
call winAddEvent
push Win1_OnCommand
push WM_COMMAND
push [winobj]
call winAddEvent
push Win1_OnSize
push WM_SIZE
push [winobj]
call winAddEvent
push Win1_OnClose
push WM_CLOSE
push [winobj]
call winAddEvent
push SW_SHOWNORMAL
push [winobj]
call winShow
or eax, eax
jz .Quit
; push 100
; push 20
; push [winobj]
; call winMoveTo
@@:
invoke GetMessage, msg, NULL, $0, $0
or eax, eax
jz .Quit
invoke TranslateMessage, msg
invoke DispatchMessage, msg
mov eax, [msg.message]
cmp eax, WM_QUIT
jz .Quit
jmp @B
.Quit:
invoke MessageBox, 0, 0, 0, 0
mov eax, [winobj]
or eax, eax
jz @F
push eax
call winDestroy
@@:
invoke ExitProcess, [msg.wParam]
sqlite3_exec_non_query:
push ebp
mov ebp, esp
; the sqlite3_prepare function is used to converts the query texts into a prepared_statement object.
;invoke sqlite3_prepare, conn, sql, -1, _sqlite3_query, NULL
cmp eax, SQLITE_OK
jz @F
; if an error has occurred, this procedure will returned directly.
ret
@@:
; the sqlite3_step function is used to evaluate a prepared_statement object.
invoke sqlite3_step, [_sqlite3_query]
; protect the returned value. this procedure will return it if the sqlite3_step
; function have error occur.
push eax
; the sqlite3_finalize function is used to destroys a prepared_statement object.
invoke sqlite3_finalize, [_sqlite3_query]
pop ebx
cmp ebx, SQLITE_OK
leave
retn 8
导入数据节:
section '.idata' import data readable writeable
library kernel32, 'kernel32.dll', \
user32, 'user32.dll', \
sqlite3, 'sqlite3.dll', \
comctl32, 'comctl32.dll'
include 'apia\kernel32.inc'
include 'apia\user32.inc'
include 'apia\gdi32.inc'
include 'sqlite3.inc'
include 'apia\comctl32.inc'
还有一个资源节:
section '.res' resource data readable
; resource directory
; macro directory [type, label]
directory RT_MENU, menus, \
RT_GROUP_ICON, igroups, \
RT_VERSION, versions, \
RT_BITMAP, bitmaps, \
RT_DIALOG, dialogs, \
RT_ICON, icons
; resource subdirectories
; macro resource dir, [id, lang, label]
resource menus, IDR_MENU_MAIN, LANG_ENGLISH + SUBLANG_DEFAULT, main_menu