Skip to content

Commit

Permalink
Create 16v2(32).asm
Browse files Browse the repository at this point in the history
  • Loading branch information
tconqueror authored Oct 8, 2019
1 parent f22ec4f commit 7cbe5e3
Showing 1 changed file with 234 additions and 0 deletions.
234 changes: 234 additions & 0 deletions chall/16/16v2(32).asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
.386
.model flat, stdcall
option casemap:none

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\masm32.inc
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\msvcrt.lib
includelib C:\masm32\lib\masm32.lib


.data
ClassName db "WinClass", 0
AppName db "Reverse", 0
MenuName db "Menu", 0
EditClassName db "Edit", 0
EditClassName2 db "Edit", 0
TestText db "BlaBlaBla", 0
process_id dword 0
class_name db 512 dup (0)
hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndEdit1 HWND ?
hwndEdit2 HWND ?
buffer db 512 dup(?)
base db "Chrome_WidgetWin_1",0
dwDesiredAccess dword 0
bInheritHandle dword ?
hProcess HANDLE ?
.const

EditID equ 1
EditID2 equ 2
IDM_HELLO equ 0
IDM_GETTEXT equ 1
IDM_SETTEXT equ 2
ID_TIMER equ 1
.code

start:
xor edi, edi

push NULL
call GetModuleHandle

mov hInstance, eax

call GetCommandLine

mov CommandLine, eax

push SW_SHOWDEFAULT
push CommandLine
push NULL
push hInstance
call WinMain

Exit:
ret
;The Main fuction for the app
WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
Local wc:WNDCLASSEX
Local msg:MSG
Local hwnd:HWND

mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, Offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground, COLOR_BTNFACE + 1
mov wc.lpszMenuName, offset MenuName
mov wc.lpszClassName, offset ClassName

push IDI_APPLICATION
push NULL
call LoadIcon

mov wc.hIcon, eax
mov wc.hIconSm, eax

push IDC_ARROW
push NULL
call LoadCursor

mov wc.hCursor, eax

lea ecx, wc
push ecx
call RegisterClassEx

push NULL
push hInst
push NULL
push NULL
push 50
push 200
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
push offset AppName
push offset ClassName
push WS_EX_CLIENTEDGE
call CreateWindowEx

mov hwnd, eax

push SW_SHOWNORMAL
push hwnd
call ShowWindow

push hwnd
call UpdateWindow

.WHILE TRUE

push 0
push 0
push NULL
lea ecx, msg
push ecx
call GetMessage

.BREAK .IF (!eax)

lea ecx, msg
push ecx
call TranslateMessage

lea ecx, msg
push ecx
call DispatchMessage
.ENDW

mov eax, msg.wParam
ret

WinMain endp

enumWindowCallback proc hWNd:HWND, lParam: LPARAM
push offset process_id
push hWNd
call GetWindowThreadProcessId
push 512
push offset class_name
push hWNd
call GetClassNameA
push hWNd
call IsWindowVisible
push esi
push edi
mov esi, offset base
mov edi, offset class_name
mov ecx, 512
l1:
movzx eax, byte ptr [esi]
cmp al, byte ptr [edi]
jnz endT
cmp eax, 0
je ok
inc edi
inc esi
loop l1
ok:
mov dword ptr [dwDesiredAccess], PROCESS_TERMINATE
mov dword ptr [bInheritHandle], FALSE
push process_id
push bInheritHandle
push dwDesiredAccess
call OpenProcess
mov hProcess,eax
or eax,eax
jz endF
push 1
push hProcess
call TerminateProcess
push hProcess
call CloseHandle
jmp endT
endF:
pop edi
pop esi
mov eax,FALSE
ret
endT:
pop edi
pop esi
mov eax,TRUE
ret
enumWindowCallback endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg == WM_DESTROY
push NULL
call PostQuitMessage

.ELSEIF uMsg == WM_CREATE
push NULL
push 5000
push ID_TIMER
push hWnd
call SetTimer
.ELSEIF uMsg == WM_TIMER
push NULL
push offset enumWindowCallback
call EnumWindows
.ELSE
push lParam
push wParam
push uMsg
push hWnd
call DefWindowProc

ret
.ENDIF

xor eax, eax
ret
WndProc endp

end start

0 comments on commit 7cbe5e3

Please sign in to comment.