flat assembler
Message board for the users of flat assembler.

Index > Windows > Recognize text from buffer and jump to...

Author
Thread Post new topic Reply to topic
Hunter13



Joined: 05 Jan 2005
Posts: 13
Hunter13
Hello, I need help with one project. I need to recognize action from FileBuffer (in my chase from internet) and jump to function which will done command and send response... But no with compare because File buffer can be dynamic... Just first word... AHH i really need use if else.. for example on server is type "DIR windows/www" === windows/www is as variabile... Please help me include this function to my programm... Its really hard Sad

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
        invoke  MessageBox,0,FileBuffer,szAgent,0

        invoke  InternetOpen,szAgent,0,0,0,0
        test    eax,eax
        jz      error1
        mov     [InternetHandle],eax

        invoke  InternetOpenUrl,eax,szURLanswer,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     loop1
loop1:
        invoke  InternetCloseHandle,[InternetHandle]
        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=done!!!',0
szHeader        db 'Host: http://phptools.site.cz/',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
Post 11 Jan 2005, 17:28
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85
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    
Post 11 Jan 2005, 21:41
View user's profile Send private message Reply with quote
Hunter13



Joined: 05 Jan 2005
Posts: 13
Hunter13
ok i do it just myself as baby Smile 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
Post 12 Jan 2005, 17:40
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85
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"?
Post 12 Jan 2005, 18:37
View user's profile Send private message Reply with quote
Hunter13



Joined: 05 Jan 2005
Posts: 13
Hunter13
after crash Very Happy i have to use just own commands

_________________
beauty is anywhere welcome guest
Post 12 Jan 2005, 18:41
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Hunter13



Joined: 05 Jan 2005
Posts: 13
Hunter13
or if is command DIRECT and DIR i just use after DIR space... No problem...

_________________
beauty is anywhere welcome guest
Post 13 Jan 2005, 06:20
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.