Hi Delight,

couldn?t answer you before.

1)
perhaps we can use the BoyerMore search algorithm by hutch
Yes, I tought of that also, but for this I think it's overkill. The Boyer-Moore is great for things like huge databases (internet, ODBC, etc). So we can use the regular FindSentence, from the API.

2)
UsedAPIS db 'MessageBeep', 0, 'MessageBox', 0, 'GetDlgItemInt', 0,'AnotherInvokedApi',0,'OneMore'

and

ApiLengths db 11,10,13,17,7

Looks interesting, but please explain it a little bit more. I don?t finish to get it. If we could use a base pointer to compare it would be REALLY FAST.

3) Since I've been looking at your code in delphi, I think this is a very good exercise: translating to fasm. I saw that the compiler really overbloats the source with all sort of stuff. But then it's a very good starting point. So we could also start making other things in delphi. I'm thinking mostly about a way to automatize the resource generation. It sort of similar to this one.
What do you think? You are the delphi expert here :)

4) and last,
the skeleton has grown, and now it only remains the COMPARE procedure, and output to do.
There is a change, because, as the process runs from the dialogbox, there's no need to open a file, but to process it directly (to open it will use the regular File/open menu).
The compare is a sequential thing, and then the output is written every time it finds a match.
This is the new skeleton:


IDR_DELIGHT_DIALOG =307
IDM_DELIGHT =502
IDD_PATH =306 ;DelightDialog with SetDlgItemText
IDD_COPY =402
IDD_OPEN =403
IDD_EDIT = 306
delight_text db "invoke"
_notfound_delight db 'No invokes found',0
IncludePath db "C:\FASM\INCLUDE\APIA",0
.
.

nochild:
invoke EnableMenuItem,[hmenu],IDM_DELIGHT,MF_BYCOMMAND+MF_GRAYED

.
wmcommand:
cmp ebx,IDM_DELIGHT
je delight
.
.
.
delight:
invoke DialogBoxParam,[hInstance], IDR_DELIGHT_DIALOG, [hwnd], DelightDialog, 0
jmp finish
.
.
.
proc DelightDialog,hwnddlg,msg,wparam,lparam
enter
push ebx esi edi
cmp [msg],WM_INITDIALOG
je .initdialog
cmp [msg],WM_COMMAND
je .command
cmp [msg],WM_CLOSE
je .close
xor eax,eax
jmp .finish
.initdialog:
invoke SetDlgItemText,[hwnddlg],IDD_PATH, IncludePath
jmp .processed
.command:
cmp [wparam],IDD_OPEN
je .open
cmp [wparam],IDD_COPY
jne .processed
.copy:
invoke GetWindowLong, [hwnddlg],GWL_USERDATA
invoke SendMessage,eax,WM_COPY,0,0
jmp .finish
.delight:
invoke GetWindowLong, [hwnddlg],GWL_USERDATA
mov edi,eax
invoke SendMessage,edi,AEM_FINDFIRST,AEFIND_WHOLEWORDS,delight_text
or eax,eax
jz not_found
.delight_found:
;every time it finds an invoke, it gets copied to a buffer and continues
;
;Under construction
;
invoke SendMessage,edi,AEM_FINDNEXT,0,0
or eax,eax
jz not_found
;
;Then when it has all the invokes, it compares with the APIs
;
jmp .finish
.not_found:
invoke MessageBox,[hwnd],_notfound_delight,_title,MB_ICONINFORMATION+MB_OK
jmp .finish
.close:
invoke EndDialog,[hwnddlg],0
.processed:
mov eax,1
.finish:
pop edi esi ebx
return
.
.
.
resource IDR_DELIGHT_DIALOG,LANG_ENGLISH+SUBLANG_DEFAULT,delight_dialog,\
.
menuitem '&Options',0,MFR_POPUP
menuitem '&Appearance...',IDM_APPEARANCE,MFR_END
menuitem '&Delight...',IDM_DELIGHT,MFR_END
.
dialog delight_dialog,5,'Delight',50,50,220,320,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
dialogitem 'STATIC','Fasm includes path:',-1,18,8,128,40,WS_VISIBLE+SS_CENTER
dialogitem 'EDIT','',IDD_PATH,20,20,180,10,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_NUMBER
dialogitem 'EDIT','',IDD_EDIT,20,40,180,250,WS_VISIBLE+WS_BORDER+WS_HSCROLL+WS_VSCROLL
dialogitem 'BUTTON','&Copy',IDD_COPY,30,300,42,14,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
dialogitem 'BUTTON','&Delight',IDD_CANCEL,130,300,42,14,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON

Now, I think AEFIND_FINDNEXT in SendMessage returns a pointer to the text found. Can you check it in the SDK?
If that's so, then we copy the whole invoke line to a buffer, and then do the rest.
We'll have it :)
Posted on 2002-10-02 09:21:51 by slop
Hi Delight,
since asmedit.dll is already there, we can use the find features of it instead of the regular API.
But for the Bayer-More, we could try to use it also, to see how to implement it in fasm.


delight_text DB 'invoke'
.delight:
mov esi,delight_text
mov edi,search_text
mov ecx,6
cld
repe movsb ;Do you think this could be optimised?
invoke SendMessage,[MDI_client_hwnd],WM_MDIGETACTIVE,0,0
or eax,eax
jz finish
invoke GetWindowLong,eax,GWL_USERDATA
mov ebx,eax
invoke SendMessage,ebx,AEM_FINDFIRST,AEFIND_WHOLEWORDS, search_text
invoke SendMessage,ebx,AEM_GETWORDATCARET,100h,string_buffer
;I'm not too sure about these
;But depending in what they return the string after 'invoke' is copied to a buffer, then all invokes
are copied, then the final compare with the APIs

invoke SendMessage,ebx,AEM_FINDNEXT,0,0
;Here loops until EOF
jmp .finish



I wonder how this would be made with the Bayer-More? Do you have ideas?
If we use the Bayer-More, then we use it again to compare with the list of APIS.
And another good point: if we implement it nicely, then we can use it for other search extensive things.
Posted on 2002-10-03 12:56:44 by slop
delight_text DB 'invoke'

.delight:

invoke SendMessage,[MDI_client_hwnd],WM_MDIGETACTIVE,0,0
or eax,eax
jz finish
invoke GetWindowLong,eax,GWL_USERDATA
mov ebx,eax
invoke SendMessage,ebx,AEM_FINDFIRST,AEFIND_WHOLEWORDS, delight_text
invoke SendMessage,ebx,AEM_GETWORDATCARET,100h,string_buffer
;Now the line following 'invoke' is in string_buffer
invoke ExtractTokens string_buffer, token_buffer
;
;A modified version of Delight's tokenizer
;

proc ExtractTokens ,_buffer,TokenBuffer
LastTokenWasInvoke rw 1
enter
push ebx esi edi
mov esi, _buffer
mov edi, TokenBuffer

.tokenize:
lodsb
cmp al,09h ;TAB
jz .tokenize
cmp al,' ' ;Space
jz .tokenize
.APIfound:
stosb
lodsb
cmp al,',' ;colon
jne .APIfound
;Now it's all in the buffer
;And anything can be done
;Either comparing if it's already done (if it appears in the final list)
;Or checking to what .dll belongs
;Even the parameters could be checked here to see if they are all there
;And I think the Boyer-More would be great for this
;What do you think?


pop edi esi ebx
return
Posted on 2002-10-07 12:54:20 by slop
Hi,

Here's where we are Delight and myself,

If anybody wants to give it a look and see what's going on.

AS4.ASM contains the main routine outside the DialogProc
AS1.ASM the stuff is inside DialogProc

We are using buliaNaza's BM algo.
Sorry about the sloppiness.

IncludePathANSI db "C:\FASM\INCLUDE\ANSI",0

IncludePathUNICODE db "C:\FASM\INCLUDE\UNICODE",0
Unicode db 0 ;Unicode flag

The above are the required directories and the flag to tue UNICODE or ANSI APIs

The format for the new .API files is a slight modification of pelaillo's.
AN example follows:
kernel,'KERNEL32.DLL',\


AddAtom,'AddAtomA',\
AddConsoleAlias,'AddConsoleAliasA',\
AllocConsole,'AllocConsole',\
AreFileApisANSI,'AreFileApisANSI',\
AssignProcessToJobObject,'AssignProcessToJobObject',\
BackupRead,'BackupRead',\
BackupSeek,'BackupSeek',\
BackupWrite,'BackupWrite',\
BaseAttachCompleteThunk,'BaseAttachCompleteThunk',\
Beep,'Beep',\
BeginUpdateResource,'BeginUpdateResourceA',\
BuildCommDCB,'BuildCommDCBA',\
BuildCommDCBAndTimeouts,'BuildCommDCBAndTimeoutsA',\
CallNamedPipe....
...
EOF
Posted on 2002-10-15 12:48:24 by slop