News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

External function scanner

Started by Vortex, October 13, 2005, 08:32:34 PM

Previous topic - Next topic

Vortex

Originally developed to support Fasm, scan.exe looks for external functions and creates a listing of declarations. Now, the tool has the capacity to create listings for MASM :
.386
.model flat, stdcall
option casemap:none

Include \masm32\include\windows.inc  ; Include with uppercase I to skip windows.inc
include msgbox.imp

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
MsgCaption      db "Iczelion's tutorial no.2",0
MsgBoxText      db "Win32 Assembly is Great!",0

.code
start:
invoke MessageBox, NULL,addr MsgBoxText, addr MsgCaption, MB_OK
invoke ExitProcess,NULL
end start


scan msgbox.asm -m5
msgbox.imp :

ExitProcess PROTO :DWORD
MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
MessageBox equ <MessageBoxA>

scan msgbox.asm -m2
msgbox.imp :

externdef _imp__ExitProcess@4:PTR pr1
ExitProcess equ <_imp__ExitProcess@4>

externdef _imp__MessageBoxA@16:PTR pr4
MessageBox equ <_imp__MessageBoxA@16>


Scan available from :

http://vortex.masmcode.com/files/Scan338.zip

Vortex

Version 3.45

Support for Nasm :

%include '..\nasm32.inc' ;*

%include 'demo.imp'

%define cinvoke invoke ;*

[section .data]
caption : db "Hello",0x0
msg1 : db "Nasm",0x0
msg2 : db 'demo',0x0
format : db "%s %s",0x0

[section .bss]
buffer : resb 10

entry demo

[section .text]
proc    demo

    cinvoke  wsprintf,dword buffer,dword format,dword msg1,dword msg2
    invoke   MessageBox, dword 0, dword buffer, dword caption, dword 0
    invoke   ExitProcess, dword 0
    ret

endproc


scan demo.asm -na

%define __stdcall_defined_ExitProcess _ExitProcess@4
%define __stdcall_defined_MessageBox _MessageBoxA@16
%define __cdecl_defined_wsprintf _wsprintfA


http://vortex.masmcode.com/files/scan345.zip

James Ladd

Vortex,
Thats nice work.
Did you do something like this for scanning DLL's and finding the public routines in them ?

Rgs, James.

Vortex

Hi James,

Thanks for your kind words. The tool searches the export sections of DLLs to match the external functions called with invoke or cinvoke

James Ladd

Vortex,

Your avatar cracks me up.

Would you consider doing an ELF version of your tool to find the exported / publis API's in SO's
(Linux equivilant of DLL's) ?

Also, do you mind if I use the scanner in some of my own work?

Rgs,James.

Vortex

Hi James,

Yes, you can use the scanner in your works. James, I am afraid I can do an ELF version of my tool because I never used Linux.

Please tell me if I can help you concerning the usage of the scanner.

Vortex

Version 3.47
========

- Support for LzAsm ideal mode PROCDESC statement.

http://vortex.masmcode.com/files/Scan347.zip

Vortex

Version 3.48
========

- Fixed bug with the standard Fasm output
- New switch -g2 for GoASM

http://vortex.masmcode.com/files/Scan348.zip

Vortex


BogdanOntanu

Hi Vortex,

Again, thank you for a nice tool and for supporting SolAsm.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Queue

I love this utility but have a couple feature requests:

Would you add a command line switch that toggles failing on missing includes? I'd like for your External Function Scanner to be able to ignore missing includes and just scan what's available.

Would you add a command line option to specify a single DLL file to scan for (and ignore scan.ini)?

Thanks for making this and so many other great tools available to everyone.

Queue

Queue

A possible bug report; if it's not a bug, then please consider it a feature request:

If I invoke a function that can be named either with or without an A (ansi) suffix, for example:
SHGetFolderPath / SHGetFolderPathA
and I DO use the A suffix, your External Function Scanner seems to miss it. In other words, if I use ''SHGetFolderPath'' it properly builds the proto for it, and if I use ''SHGetFolderPathA'' it fails.

Queue

Vortex

Hi Queue,

If the scanner finds an extra ANSI version of the same function, it will omit it. This is a feature by design. You should always use the non-ANSI API functions.

The tool ignores all lines terminating with the symbol pair ;*  The example Masm1 demonstrates this feature :

include \masm32\include\windows.inc ;*

scan will not read the file windows.inc

Normally, the assembler will warn you for missing include files. Depending on your assembler, how do you by-pass missing include files?

About the command-line option to specify a DLL file : would you like to see an option to specify multiple DLL files separated by a symbol? Generally, an application imports functions from two or more DLLs.

Thanks for your interest and support.

Queue

I certainly wouldn't be averse to being able to specify multiple DLLs on the command line, but in the particular case of what I've been using your Scanner for, I only scan 1 DLL at a time. Extendable capability certainly is good though.

I'll elaborate on how I've been using it, and why I made those requests:

I have an ASM parser that reads through an ASM file and looks for missing includes and missing includelibs. It assumes any missing includes/includelibs are missing import libraries and their PROTO definition includes, so it takes their file name (kernel32.inc and kernel32.lib for example), and then writes a Scan.ini file containing only that one DLL file name (kernel32.dll if we continue the example). It then calls your Scanner with the switches -m5 and -cd to produce the include file (I actually call it a second time with -l2 to pick up any functions that are called and not invoked, and then compare the two lists and search the source files for PROTOs for the call'd versions). I then use polib.exe to make the LIB file based off of the include file (this was inspired by your utility inc2lib).

So, I'm using your Scanner to make the missing files, hence why I'd like it to optionally ignore missing files.

- So, if I could specify a DLL from the command line, it would skip having to write a Scan.ini file.
- If it could ignore missing files I wouldn't need to hex edit Scan.exe and change ''include'' to gibberish so that it skips parsing included files, and I'd regain its capability to check included files for function calls.

As for not using the ansi suffix, although ideally everyone would call the functions by the proper name, it just doesn't always happen, and if someone used the A-suffixed function name everywhere in their code, I'd have to go through and resolve that by hand before your Scanner would handle the parse.

Queue

Vortex

Hi Queue,

Would you like to test Scan V3.52 Beta 1 ? This new version will issue a warning message if it detects a missing include file but will continue to process the source file(s). About the the command-line option you proposed, I will try to see what I can do.