概要
中古ノート買ってみた。
windows10でfasmをやってみた。
GDI見つけたので、やってみた。
写真
サンプルコード
format PE64 GUI 6.0
entry WinMain
include 'win64a.inc'
IMAGE_BASE equ 0x400000
struct RectF
x rd 1 ;REAL = REAL4
y rd 1
awidth rd 1
height rd 1
ends
struct GdiplusStartupInput
GdiplusVersion rd 1
DebugEventCallback rd 1
SuppressBackgroundThread rd 1
SuppressExternalCodecs rd 1
ends
section '.code' code readable executable writeable
proc WinMain
local msg:MSG
frame
xor r8, r8 ;NULL
mov edx, gdiplusStartupInput
mov ecx, GdiplusToken
invoke GdiplusStartup
xor ebx, ebx
mov ecx, FileName
invoke LoadCursorFromFile
mov esi, IMAGE_BASE
mov edi, ClassName
push rax ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOWTEXT ;hbrBackground=black
push 10003h ;hCursor
push rax ;hIcon
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
push WndSDI
push sizeof.WNDCLASSEX ;cbSize & style
invoke RegisterClassEx,esp ;addr WNDCLASSEX
push rbx
push rsi ;rsi=400000h
shl esi, 9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 290
push 270
push rsi ;rsi=CW_USEDEFAULT
push rsi ;rsi=CW_USEDEFAULT
sub rsp, 20h
xor ecx, ecx
mov r9d, WS_OVERLAPPEDWINDOW or WS_VISIBLE
invoke CreateWindowEx,,edi,edi
lea edi, [msg]
@@:
xor r9, r9
xor r8, r8
xor edx, edx
invoke GetMessage, edi
invoke DispatchMessage, edi
jmp @b
endf
endp
proc WndSDI hwnd,uMsg,wParam,lParam
local Ps:PAINTSTRUCT
local hdc:QWORD
local graphics:QWORD
mov [hwnd], rcx
frame
cmp edx, WM_DESTROY
je wmDESTROY
cmp edx, WM_CREATE
je wmCREATE
cmp edx, WM_PAINT
je wmPAINT
leave
jmp [NtdllDefWindowProc]
wmDESTROY:
invoke DeleteObject, [hCompatibleDC]
invoke DestroyWindow, [hwnd]
invoke GdiplusShutdown, [GdiplusToken]
invoke DeleteObject, [hFont]
xor ecx, ecx
invoke RtlExitUserProcess
wmCREATE:
mov ecx, logfont
invoke CreateFontIndirect
mov [hFont], rax
mov edx, WM_SETFONT
xor r9, r9 ;FALSE
invoke SendMessage,[hwnd],,rax
xor ecx, ecx ;NULL
xor edx, edx ;LANG_NEUTRAL
mov r8d, nativeFormat
invoke GdipCreateStringFormat
mov ecx, 0FF00C832h
mov edx, nativebrush
invoke GdipCreateSolidFill
jmp wmBYE
wmPAINT:
lea edx, [Ps]
invoke BeginPaint
mov [hdc], rax
lea edx, [graphics]
invoke GdipCreateFromHDC, [hdc]
lea edx, [graphics]
invoke GdipCreateFromHWND, [hwnd]
mov edx, logfont
mov r8d, gpFont
invoke GdipCreateFontFromLogfont, [hdc]
mov edx, wPhrase
or r8, -1
invoke GdipDrawString,[graphics],,,[gpFont],RectText,[nativeFormat],[nativebrush]
invoke GdipDeleteFont,[gpFont]
lea edx, [Ps]
invoke EndPaint, [hwnd]
wmBYE:
endf
leave
retn
endp
;section '.data' data readable writeable
ClassName db "GDI+ test",0
FileName db "sample 0",0
gdiplusStartupInput GdiplusStartupInput 1,NULL,FALSE,FALSE
nativeFormat rq 1
hCompatibleDC rq 1
wPhrase du "hello, World!", 0
nativebrush rq 1
gpFont rq 1
hFont rq 1
logfont LOGFONT 36,12,0,0,400,0,0,0,0,0,0,0,DEFAULT_PITCH or FF_SCRIPT,"Times New Roman"
RectText RectF 0.0,0.0,270.0,90.0
GdiplusToken rq 1
section '.idata' import data readable writeable
library ntdll,'ntdll.dll',\
user,'USER32.DLL',\
gdiplus,'gdiplus.dll',\
gdi,'GDI32.DLL'
import gdiplus,\
GdipCreateFontFromLogfont,'GdipCreateFontFromLogfontA',\
GdipCreateStringFormat,'GdipCreateStringFormat',\
GdipCreateSolidFill,'GdipCreateSolidFill',\
GdipCreateFromHWND,'GdipCreateFromHWND',\
GdipCreateFromHDC,'GdipCreateFromHDC',\
GdiplusShutdown,'GdiplusShutdown',\
GdipDeleteFont,'GdipDeleteFont',\
GdipDrawString,'GdipDrawString',\
GdiplusStartup,'GdiplusStartup'
import user,\
LoadCursorFromFile,'LoadCursorFromFileA',\
RegisterClassEx,'RegisterClassExA',\
DispatchMessage,'DispatchMessageA',\
CreateWindowEx,'CreateWindowExA',\
DestroyWindow,'DestroyWindow',\
SendMessage,'SendMessageA',\
GetMessage,'GetMessageA',\
BeginPaint,'BeginPaint',\
EndPaint,'EndPaint'
import gdi,\
CreateFontIndirect,'CreateFontIndirectA',\
DeleteObject,'DeleteObject'
import ntdll,\
NtdllDefWindowProc,'NtdllDefWindowProc_A',\
RtlExitUserProcess,'RtlExitUserProcess'
以上。
