Skip to content

Instantly share code, notes, and snippets.

@bplaat
Last active September 3, 2019 17:05
Show Gist options
  • Select an option

  • Save bplaat/63cadd7f271a9e4463d7c2f78fdec3e9 to your computer and use it in GitHub Desktop.

Select an option

Save bplaat/63cadd7f271a9e4463d7c2f78fdec3e9 to your computer and use it in GitHub Desktop.
A simple win32 editor made with assembly
; Bassies Editor
format PE GUI
entry start
macro invoke proc, [arg] {
reverse pushd arg
common call [proc]
}
section '.text' code readable executable
start:
invoke GetModuleHandleA, 0
mov [wc + 16], eax
invoke LoadCursorA, 0, 32512
mov [wc + 24], eax
invoke CreateSolidBrush, 0x00fe9821
mov [wc + 28], eax
invoke RegisterClassA, wc
invoke CreateWindowExA, 0, class, title, 0x10CF0000, 0x80000000, 0x80000000, 800, 600, 0, 0, wc + 16, 0
msg_loop:
invoke GetMessageA, msg, 0, 0, 0
cmp eax, 0
jle end_loop
invoke TranslateMessage, msg
invoke DispatchMessageA, msg
jmp msg_loop
end_loop:
invoke ExitProcess, [msg + 8]
WindowProc:
push ebp
mov ebp, esp
cmp dword [ebp + 12], 0x0001
je .wmcreate
cmp dword [ebp + 12], 0x0024
je .wmminmax
cmp dword [ebp + 12], 0x0005
je .wmsize
cmp dword [ebp + 12], 0x0111
je .wmcommand
cmp dword [ebp + 12], 0x0002
je .wmdestroy
jmp .default
.wmcreate:
invoke CreateFontA, 20, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, georgia
mov [georgia_font], eax
invoke CreateFontA, 20, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, courier_new
mov [courier_new_font], eax
invoke CreateWindowExA, 0, button, new, 0x50000000, 20, 20, 100, 40, [ebp + 8], 1, 0, 0
invoke SendMessageA, eax, 0x0030, [georgia_font], 1
invoke CreateWindowExA, 0, button, open, 0x50000000, 140, 20, 100, 40, [ebp + 8], 2, 0, 0
invoke SendMessageA, eax, 0x0030, [georgia_font], 1
invoke CreateWindowExA, 0, button, save, 0x50000000, 260, 20, 100, 40, [ebp + 8], 3, 0, 0
invoke SendMessageA, eax, 0x0030, [georgia_font], 1
invoke CreateWindowExA, 0, button, about, 0x50000000, 380, 20, 100, 40, [ebp + 8], 4, 0, 0
invoke SendMessageA, eax, 0x0030, [georgia_font], 1
invoke CreateWindowExA, 0, button, exit, 0x50000000, 500, 20, 100, 40, [ebp + 8], 5, 0, 0
invoke SendMessageA, eax, 0x0030, [georgia_font], 1
invoke CreateWindowExA, 0, static, filename, 0x50000000, 20, 80, 100, 20, [ebp + 8], 0, 0, 0
invoke SendMessageA, eax, 0x0030, [georgia_font], 1
invoke CreateWindowExA, 0, edit, 0, 0x50000000, 140, 80, 620, 20, [ebp + 8], 0, 0, 0
mov [filename_hwnd], eax
invoke SendMessageA, eax, 0x0030, [courier_new_font], 1
invoke CreateWindowExA, 0, edit, 0, 0x503000c4, 20, 120, 740, 380, [ebp + 8], 0, 0, 0
mov [edit_hwnd], eax
invoke SendMessageA, eax, 0x0030, [courier_new_font], 1
invoke CreateWindowExA, 0, static, footer, 0x50000000, 20, 520, 740, 20, [ebp + 8], 0, 0, 0
mov [footer_hwnd], eax
invoke SendMessageA, eax, 0x0030, [georgia_font], 1
jmp .done
.wmminmax:
mov eax, [ebp + 20]
mov dword [eax + 24], 635
mov dword [eax + 28], 550
jmp .done
.wmsize:
invoke GetClientRect, [ebp + 8], rect
mov eax, [rect + 8]
sub eax, 160
invoke SetWindowPos, [filename_hwnd], 0, 140, 80, eax, 20, 0x0200
mov eax, [rect + 8]
sub eax, 40
mov ebx, [rect + 12]
sub ebx, 180
invoke SetWindowPos, [edit_hwnd], 0, 20, 120, eax, ebx, 0x0200
mov eax, [rect + 12]
sub eax, 40
mov ebx, [rect + 8]
sub ebx, 40
invoke SetWindowPos, [footer_hwnd], 0, 20, eax, ebx, 20, 0x0200
jmp .done
.wmcommand:
cmp dword [ebp + 16], 1
je .new_button
cmp dword [ebp + 16], 2
je .open_button
cmp dword [ebp + 16], 3
je .save_button
cmp dword [ebp + 16], 4
je .about_button
cmp dword [ebp + 16], 5
je .exit_button
jmp .done
.new_button:
invoke SendMessageA, [filename_hwnd], 0x000c, 0, [null_buffer]
invoke SendMessageA, [edit_hwnd], 0x000c, 0, [null_buffer]
jmp .done
.open_button:
push filename_buffer
push [filename_hwnd]
call GetWindowText
invoke CreateFileA, [filename_buffer], 0xc0000000, 0, 0, 3, 080h, 0
mov [file_handle], eax
invoke GetFileSize, [file_handle], 0
mov [data_size], eax
invoke GlobalAlloc, 0x0040, [data_size]
mov [edit_buffer], eax
invoke ReadFile, [file_handle], [edit_buffer], [data_size], 0, 0
invoke CloseHandle, [file_handle]
invoke SendMessageA, [edit_hwnd], 0x000c, [data_size], [edit_buffer]
invoke GlobalFree, [filename_buffer]
invoke GlobalFree, [edit_buffer]
jmp .done
.save_button:
push filename_buffer
push [filename_hwnd]
call GetWindowText
push edit_buffer
push [edit_hwnd]
call GetWindowText
dec [data_size]
invoke CreateFileA, [filename_buffer], 0xc0000000, 0, 0, 2, 080h, 0
mov [file_handle], eax
invoke WriteFile, [file_handle], [edit_buffer], [data_size], 0, 0
invoke CloseHandle, [file_handle]
invoke GlobalFree, [filename_buffer]
invoke GlobalFree, [edit_buffer]
jmp .done
.about_button:
invoke MessageBoxA, [ebp + 8], footer, about, 0
jmp .done
.exit_button:
invoke DestroyWindow, [ebp + 8]
jmp .done
.wmdestroy:
invoke PostQuitMessage, 0
mov eax, 0
jmp .done
.default:
invoke DefWindowProcA, [ebp + 8], [ebp + 12], [ebp + 16], [ebp + 20]
.done:
pop ebp
ret 16
GetWindowText:
push ebp
mov ebp, esp
invoke GetWindowTextLengthA, [ebp + 8]
inc eax
mov [data_size], eax
invoke GlobalAlloc, 0x0040, [data_size]
mov edi, [ebp + 12]
mov [edi], eax
invoke SendMessageA, [ebp + 8], 0x000d, [data_size], eax
pop ebp
ret 8
section '.data' import data readable writeable
dd 0, 0, 0, RVA gdi_name, RVA gdi_table
dd 0, 0, 0, RVA kernel_name, RVA kernel_table
dd 0, 0, 0, RVA user_name, RVA user_table
dd 0, 0, 0, 0, 0
gdi_table:
CreateFontA dd RVA _CreateFontA
CreateSolidBrush dd RVA _CreateSolidBrush
dd 0
kernel_table:
CloseHandle dd RVA _CloseHandle
CreateFileA dd RVA _CreateFileA
ExitProcess dd RVA _ExitProcess
GlobalAlloc dd RVA _GlobalAlloc
GetFileSize dd RVA _GetFileSize
GlobalFree dd RVA _GlobalFree
GetModuleHandleA dd RVA _GetModuleHandleA
ReadFile dd RVA _ReadFile
WriteFile dd RVA _WriteFile
dd 0
user_table:
CreateWindowExA dd RVA _CreateWindowExA
DefWindowProcA dd RVA _DefWindowProcA
DestroyWindow dd RVA _DestroyWindow
DispatchMessageA dd RVA _DispatchMessageA
GetClientRect dd RVA _GetClientRect
GetMessageA dd RVA _GetMessageA
GetWindowTextLengthA dd RVA _GetWindowTextLengthA
MessageBoxA dd RVA _MessageBoxA
LoadCursorA dd RVA _LoadCursorA
PostQuitMessage dd RVA _PostQuitMessage
TranslateMessage dd RVA _TranslateMessage
SendMessageA dd RVA _SendMessageA
SetWindowPos dd RVA _SetWindowPos
RegisterClassA dd RVA _RegisterClassA
dd 0
class db 'BASSIES_EDITOR', 0
title db 'Bassies Text Editor For Windows Made In Assembly', 0
georgia db 'Georgia', 0
courier_new db 'Courier New', 0
button db 'BUTTON', 0
new db 'New', 0
open db 'Open', 0
save db 'Save', 0
about db 'About', 0
exit db 'Exit', 0
static db 'STATIC', 0
filename db 'Filename: ', 0
edit db 'EDIT', 0
footer db 'This application is made by Bastiaan van der Plaat!!!', 0
wc dd 0, WindowProc, 0, 0, 0, 0, 0, 0, 0, class
msg dd 0, 0, 0, 0, 0, 0, 0
georgia_font dd 0
courier_new_font dd 0
rect dd 0, 0, 0, 0
filename_hwnd dd 0
edit_hwnd dd 0
footer_hwnd dd 0
file_handle dd 0
data_size dd 0
filename_buffer dd 0
edit_buffer dd 0
null_buffer dd 0
gdi_name db 'GDI32.dll', 0
_CreateFontA db 0, 0, 'CreateFontA', 0
_CreateSolidBrush db 0, 0, 'CreateSolidBrush', 0
kernel_name db 'KERNEL32.DLL', 0
_CloseHandle db 0, 0, 'CloseHandle', 0
_CreateFileA db 0, 0, 'CreateFileA', 0
_ExitProcess db 0, 0, 'ExitProcess', 0
_GlobalAlloc db 0, 0, 'GlobalAlloc', 0
_GetFileSize db 0, 0, 'GetFileSize', 0
_GlobalFree db 0, 0, 'GlobalFree', 0
_GetModuleHandleA db 0, 0, 'GetModuleHandleA', 0
_ReadFile db 0, 0, 'ReadFile', 0
_WriteFile db 0, 0, 'WriteFile', 0
user_name db 'USER32.DLL', 0
_CreateWindowExA db 0, 0, 'CreateWindowExA', 0
_DefWindowProcA db 0, 0, 'DefWindowProcA', 0
_DestroyWindow db 0, 0, 'DestroyWindow', 0
_DispatchMessageA db 0, 0, 'DispatchMessageA', 0
_GetClientRect db 0, 0, 'GetClientRect', 0
_GetMessageA db 0, 0, 'GetMessageA', 0
_GetWindowTextLengthA db 0, 0, 'GetWindowTextLengthA', 0
_MessageBoxA db 0, 0, 'MessageBoxA', 0
_LoadCursorA db 0, 0, 'LoadCursorA', 0
_PostQuitMessage db 0,0, 'PostQuitMessage', 0
_TranslateMessage db 0, 0, 'TranslateMessage', 0
_SendMessageA db 0, 0, 'SendMessageA', 0
_SetWindowPos db 0, 0, 'SetWindowPos', 0
_RegisterClassA db 0, 0, 'RegisterClassA', 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment