?? sol_system.inc
字號:
;-------------------------------------------------
; flat assembler interface for Win32
; Copyright (c) 1999-2006, Tomasz Grysztar.
; All rights reserved.
;-------------------------------------------------
;------------------------------------------------
; FASM port to Solar_OS
; copyright (c) 2007 by Bogdan Valentin Ontanu
; All rights reserved.
;------------------------------------------------
;----------------------------------------------
; Macro for using STDCALL SOLAR_OS API
;----------------------------------------------
include '../../include/macro/proc32.inc'
include 'solar_os.inc'
;-----------------------------------
; variables used in GUI
;-----------------------------------
wnd_main_handle dd 0
btn_compile_handle dd 0
btn_std_handle dd 0
btn_binary_handle dd 0
btn_pe_handle dd 0
edit_cmd_handle dd 0
btn1_handle dd 0
btn2_handle dd 0
btn3_handle dd 0
btn_dbg_fasm_handle dd 0
btn_compile_caption db "Compile",0
btn_std_caption db "View Stdout",0
btn_binary_caption db "Binary",0
btn_pe_caption db "Map PE",0
edit_cmd_label db "Command line:",0
btn1_caption db "1",0
btn2_caption db "2",0
btn3_caption db "3",0
btn_dbg_fasm_caption db "Debug FASM",0
sol_cmd_line1 db "fasm sample.asm sample.exe ",0
sol_cmd_line2 db "fasm sample_pe.asm sample.exe ",0
sol_cmd_line3 db "fasm sample_pe2.asm sample.exe ",0
fasm_cmd_line rb 512
;-------------------------------------
; memory buffers
;-------------------------------------
fasm_mem_handle dd 0
fasm_mem_size dd 0
fasm_mem_ptr dd 0
fasm_stdout_mem_ptr dd 0
fasm_stdout_mem_handle dd 0
fasm_stdout_size dd 0
; special value inorder to avoid CLOSE
fasm_write_fhandle dd 055AA1234h
fasm_write_fpos dd 0
fasm_write_mem_handle dd 0
fasm_write_mem_ptr dd 0
fasm_write_mem_size dd 4
;-------------------------------------
; GUI Creation
;-------------------------------------
Create_Main_Window:
;------------------------------
; Create the Main app window
;------------------------------
invoke API_Window_Create, 0,100,128,460,156, FLAG_WND_MINI + FLAG_WND_NO_RESIZE, WND_TYPE_TOP
mov [wnd_main_handle],eax
; set main window caption
invoke API_Window_Set_Caption, [wnd_main_handle], _logo
; set wnd_main callback
invoke API_Window_Set_Callback, [wnd_main_handle], OS_CALL_AFTER, App_Fasm_Main_Callback
;--------------------------------
; Create a button for "Compile"
;--------------------------------
invoke API_Window_Create, [wnd_main_handle], 8,32,96,22, FLAG_WND_NO_MOVE + FLAG_WND_NO_RESIZE, WND_TYPE_BUTTON
mov [btn_compile_handle],eax
; set button caption
invoke API_Window_Set_Caption, [btn_compile_handle], btn_compile_caption
; set compile button callback
invoke API_Window_Set_Callback, [btn_compile_handle], OS_CALL_AFTER, App_Fasm_Btn_Compile_Callback
;-----------------------------------------------------------
; Create a button for "View STDOUT" messages of compilation
;-----------------------------------------------------------
invoke API_Window_Create, [wnd_main_handle], 128,32,96,22, FLAG_WND_NO_MOVE + FLAG_WND_NO_RESIZE, WND_TYPE_BUTTON
mov [btn_std_handle],eax
; set button caption
invoke API_Window_Set_Caption, [btn_std_handle], btn_std_caption
; set binary button callback
invoke API_Window_Set_Callback, [btn_std_handle], OS_CALL_AFTER, App_Fasm_Btn_Std_Callback
;-------------------------------------------------------
; Create a button for "Binary" result of compilation
;-------------------------------------------------------
invoke API_Window_Create, [wnd_main_handle], 228,32,96,22, FLAG_WND_NO_MOVE + FLAG_WND_NO_RESIZE, WND_TYPE_BUTTON
mov [btn_binary_handle],eax
; set button caption
invoke API_Window_Set_Caption, [btn_binary_handle], btn_binary_caption
; set binary button callback
invoke API_Window_Set_Callback, [btn_binary_handle], OS_CALL_AFTER, App_Fasm_Btn_Binary_Callback
;-------------------------------------------------------
; Create a button for "PE" result of compilation
;-------------------------------------------------------
invoke API_Window_Create, [wnd_main_handle], 328,32,96,22, FLAG_WND_NO_MOVE + FLAG_WND_NO_RESIZE, WND_TYPE_BUTTON
mov [btn_pe_handle],eax
; set button caption
invoke API_Window_Set_Caption, [btn_pe_handle], btn_pe_caption
; set binary button callback
invoke API_Window_Set_Callback, [btn_pe_handle], OS_CALL_AFTER, App_Fasm_Btn_Pe_Callback
;--------------------------------
; Create a EDIT for command line
;--------------------------------
invoke API_Window_Create, [wnd_main_handle],8,90,445,22, FLAG_WND_NO_MOVE + FLAG_WND_NO_RESIZE, WND_TYPE_EDIT
mov [edit_cmd_handle],eax
;-------------------
; set edit caption
;-------------------
invoke API_Window_Set_Caption, [edit_cmd_handle], sol_cmd_line1
;-------------------------------------------------------
; Create 3 buttons for test cmd lines
;-------------------------------------------------------
invoke API_Window_Create, [wnd_main_handle], 130,64,21,22, FLAG_WND_NO_MOVE + FLAG_WND_NO_RESIZE, WND_TYPE_BUTTON
mov [btn1_handle],eax
invoke API_Window_Set_Caption, [btn1_handle], btn1_caption
invoke API_Window_Set_Callback, [btn1_handle], OS_CALL_AFTER, App_Fasm_Btn1_Callback
invoke API_Window_Create, [wnd_main_handle], 154,64,21,22, FLAG_WND_NO_MOVE + FLAG_WND_NO_RESIZE, WND_TYPE_BUTTON
mov [btn2_handle],eax
invoke API_Window_Set_Caption, [btn2_handle], btn2_caption
invoke API_Window_Set_Callback, [btn2_handle], OS_CALL_AFTER, App_Fasm_Btn2_Callback
invoke API_Window_Create, [wnd_main_handle], 178,64,21,22, FLAG_WND_NO_MOVE + FLAG_WND_NO_RESIZE, WND_TYPE_BUTTON
mov [btn3_handle],eax
invoke API_Window_Set_Caption, [btn3_handle], btn3_caption
invoke API_Window_Set_Callback, [btn3_handle], OS_CALL_AFTER, App_Fasm_Btn3_Callback
;---------------------------------------
; Create a button for "Debug FASM"
;---------------------------------------
invoke API_Window_Create, [wnd_main_handle], 8,128,96,22, FLAG_WND_NO_MOVE + FLAG_WND_NO_RESIZE, WND_TYPE_BUTTON
mov [btn_dbg_fasm_handle],eax
invoke API_Window_Set_Caption, [btn_dbg_fasm_handle], btn_dbg_fasm_caption
invoke API_Window_Set_Callback, [btn_dbg_fasm_handle], OS_CALL_AFTER, App_Fasm_Btn_Dbg_Fasm_Callback
;-------------------------------------
; allocate memory for OUTPUT file
;-------------------------------------
invoke API_Memory_Allocate, 128
mov [fasm_write_mem_handle],eax
mov [fasm_write_mem_ptr],esi
;-------------------------------------
; allocate memory for STDOUT write
;-------------------------------------
invoke API_Memory_Allocate, 128
mov [fasm_stdout_mem_handle],eax
mov [fasm_stdout_mem_ptr],esi
mov [fasm_stdout_size],0
; return handle of main window
mov eax,[wnd_main_handle]
ret
clear_write_buffer:
push ecx
push edi
mov edi, [fasm_write_mem_ptr]
mov ecx, 128 ; buffer size in 4k blocks
shl ecx, 12 ; * 4096
xor eax,eax
rep stosb
pop edi
pop ecx
ret
;-----------------------------------------------
; Callbacks for main window and each control
;-----------------------------------------------
proc App_Fasm_Main_Callback wnd_handle,wnd_action,wnd_param1,wnd_param2
mov eax,[wnd_action]
cmp eax,ACT_PAINT_CHILD
jz .is_paint
cmp eax,ACT_CLOSE_CHILD
jz .is_close
.done:
xor eax,eax
ret
.is_paint:
;-------------------------
; WND_MAIN::ON PAINT
; - show label
;-------------------------
invoke API_Text_Draw,[wnd_handle],8,68,edit_cmd_label, 0ff7f3fh
jmp .done
.is_close:
;-------------------------
; WND_MAIN::ON CLOSE
; - release memory
;-------------------------
invoke API_Memory_Release,[fasm_write_mem_handle],128
invoke API_Memory_Release,[fasm_stdout_mem_handle],128
jmp .done
endp
proc App_Fasm_Btn_Compile_Callback wnd_handle,wnd_action,wnd_param1,wnd_param2
mov eax,[wnd_action]
cmp eax,ACT_LEFT_UP_CHILD
jz .is_mouse_click
.done:
xor eax,eax
ret
.is_mouse_click:
;-------------------------
; BTN_COMPILE::ON CLICK
;-------------------------
Call clear_write_buffer
; reset output write positions
mov [fasm_write_fpos],0
mov [fasm_stdout_size],0
;------------------------------
; FASM touches my EBP ;)
;------------------------------
pushad
call start_fasm
popad
jmp .done
endp
proc App_Fasm_Btn_Dbg_Fasm_Callback wnd_handle,wnd_action,wnd_param1,wnd_param2
; button used for debugging FASM compilation stage on SOL
; same as above just an extra INT 3 added
mov eax,[wnd_action]
cmp eax,ACT_LEFT_UP_CHILD
jz .is_mouse_click
.done:
xor eax,eax
ret
.is_mouse_click:
;-------------------------
; BTN_COMPILE::ON CLICK
;-------------------------
Call clear_write_buffer
; allow debuger to enter here
int3
; in order to know the location during debug
mov eax,[fasm_write_mem_ptr]
; reset output write positions
mov [fasm_write_fpos],0
mov [fasm_stdout_size],0
;------------------------------
; FASM touches my EBP ;)
;------------------------------
pushad
call start_fasm
popad
jmp .done
endp
proc App_Fasm_Btn_Std_Callback wnd_handle,wnd_action,wnd_param1,wnd_param2
mov eax,[wnd_action]
cmp eax,ACT_LEFT_UP_CHILD
jz .is_mouse_click
.done:
xor eax,eax
ret
.is_mouse_click:
;-------------------------
; ::ON CLICK
;-------------------------
; allow debuger to enter here
;int3
pushad
invoke App_View_Text_Init,OS_ARG_ADDR_SIZE_INFO,[fasm_stdout_mem_ptr],[fasm_stdout_size],0
popad
jmp .done
endp
proc App_Fasm_Btn_Binary_Callback wnd_handle,wnd_action,wnd_param1,wnd_param2
mov eax,[wnd_action]
cmp eax,ACT_LEFT_UP_CHILD
jz .is_mouse_click
.done:
xor eax,eax
ret
.is_mouse_click:
;-------------------------
; ::ON CLICK
;-------------------------
; allow debuger to enter here
;int3
pushad
invoke App_View_Memory_Init,OS_ARG_ADDR_SIZE_INFO,[fasm_write_mem_ptr],4096,0
popad
jmp .done
endp
proc App_Fasm_Btn_Pe_Callback wnd_handle,wnd_action,wnd_param1,wnd_param2
mov eax,[wnd_action]
cmp eax,ACT_LEFT_UP_CHILD
jz .is_mouse_click
.done:
xor eax,eax
ret
.is_mouse_click:
;-------------------------
; ::ON CLICK
;-------------------------
; allow debuger to enter here
;int3
pushad
invoke App_View_Pe_Init,OS_ARG_ADDR_SIZE_INFO,[fasm_write_mem_ptr],4096,0
popad
jmp .done
endp
proc App_Fasm_Btn1_Callback wnd_handle,wnd_action,wnd_param1,wnd_param2
mov eax,[wnd_action]
cmp eax,ACT_LEFT_UP_CHILD
jz .is_mouse_click
.done:
xor eax,eax
ret
.is_mouse_click:
invoke API_Window_Set_Caption, [edit_cmd_handle], sol_cmd_line1
jmp .done
endp
proc App_Fasm_Btn2_Callback wnd_handle,wnd_action,wnd_param1,wnd_param2
mov eax,[wnd_action]
cmp eax,ACT_LEFT_UP_CHILD
jz .is_mouse_click
.done:
xor eax,eax
ret
.is_mouse_click:
invoke API_Window_Set_Caption, [edit_cmd_handle], sol_cmd_line2
jmp .done
endp
proc App_Fasm_Btn3_Callback wnd_handle,wnd_action,wnd_param1,wnd_param2
mov eax,[wnd_action]
cmp eax,ACT_LEFT_UP_CHILD
jz .is_mouse_click
.done:
xor eax,eax
ret
.is_mouse_click:
invoke API_Window_Set_Caption, [edit_cmd_handle], sol_cmd_line3
jmp .done
endp
;----------------------------------------------------
;
; FASM interfaces to SOL follow
;
;----------------------------------------------------
get_cmd_line:
; copy string from edit caption to command line buffer
invoke API_Window_Get_Caption,[edit_cmd_handle],fasm_cmd_line
; return address of command line buffer
mov eax,fasm_cmd_line
ret
write_stdout:
;--------------------------------------------
; Write bytes to STDOUT
; - stdout is simulated in a memory buffer
;--------------------------------------------
;-------------------------------------
; INPUT:
; esi = source ptr
; ecx = number of bytes to write
; ebx = handle ... is ignored
;-------------------------------------
push ecx
push esi
push edi
mov edi, [fasm_stdout_mem_ptr]
add edi, [fasm_stdout_size]
add [fasm_stdout_size],ecx
rep movsb
pop edi
pop esi
pop ecx
ret
init_memory:
mov eax,esp
and eax,not 0FFFh
add eax,1000h-10000h
mov [stack_limit],eax
;---------------------------------
; give the beast 4 Mega bytes
; - hardcoded ;)
;---------------------------------
mov eax,4*1024*1024
allocate_memory:
mov edx,eax
shr edx,2
mov ecx,eax
sub ecx,edx
mov [memory_end],ecx
mov [additional_memory_end],edx
push esi
;-------------------------------------------------
; SOL wants the number of 4K blocks not bytes
;-------------------------------------------------
shr eax,12 ; div 4096
inc eax
mov [fasm_mem_size],eax
invoke API_Memory_Allocate, eax
;----------------------------------------
; on return
;----------------------------------------
; esi = memory block pointer
; eax, memory block handle
;----------------------------------------
mov [fasm_mem_handle],eax
mov [fasm_mem_ptr],esi
mov eax,esi
pop esi
mov [memory_start],eax
add eax,[memory_end]
mov [memory_end],eax
mov [additional_memory],eax
add [additional_memory_end],eax
ret
not_enough_memory:
mov eax,[additional_memory_end]
shl eax,1
cmp eax,4000h
jb out_of_memory
jmp allocate_memory
exit_program:
;---------------------------------------------
; release the memory used for compilation
;---------------------------------------------
invoke API_Memory_Release, [fasm_mem_handle], [fasm_mem_size]
;--------------------------
; and return to SOL
;--------------------------
xor eax,eax
ret
get_environment_variable:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -