Find all statically linked libraries required before your process can start
There’s some code in this post What external code does your EXE depend on? that determines all the statically linked libraries and function calls of a particular EXE. VFP9.EXE links to about 18 modules. However, there are about 83 modules loaded when VFP is up and running. Much of this is due to these 18 modules depending on other modules.
To get all statically linked libraries from all modules, the code needs to recur: for each module, find its dependent modules.
Below is code that finds a tree of 78 statically linked modules and the almost 10,000 functions that need to be loaded for the first line of VFP9.exe code to execute.
The code uses LoadLibrary and GetModuleFileName to get the module full path name because the module may not be on the path.
DECLARE integer GetModuleFileName IN WIN32API integer hModule, string @ lpfilename, integer nSize
DECLARE integer LoadLibrary IN WIN32API string FileName
DECLARE integer FreeLibrary IN WIN32API integer hModule
CREATE CURSOR imports (Parent c(40), Module c(40),address c(10),FuncName c(40))
CREATE CURSOR modules (module c(40),Level i)
INDEX on UPPER(module) TAG module
GetImports(_vfp.FullName, 1)
*GetImports("kernel32.dll",1)
PROCEDURE GetImports(Parent as String,nLevel as Integer)
LOCAL i,mybat,nLines,aa[1],Module,cLine,Address,FuncName
hm = LoadLibrary(parent)
IF hm=0
?"Can't load "+parent
ELSE
cStr=SPACE(260)
nLen=GetModuleFileName(hm,@cStr,LEN(cStr))
Parent=LEFT(cStr,nLen)
FreeLibrary(hm)
INSERT INTO modules VALUES (UPPER(JUSTFNAME(Parent)), nLevel)
cVars=LOCFILE("c:\Program Files\Microsoft Visual Studio 8\Vc\bin\vcvars32.bat") && VS2005
* cVars=LOCFILE("c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\vcvars32.bat") && VS2003
TEXT TO mybat TEXTMERGE NOSHOW
call "<<cVars>>"
dumpbin /imports "<<Parent>>" > c:\t.txt
ENDTEXT
STRTOFILE(mybat,"t.bat")
!cmd /c t.bat
nLines=ALINES(aa,FILETOSTR("c:\t.txt"))
FOR i = 1 TO nLines
cLine=aa
IF cLine=" Summary"
EXIT
ENDIF
IF cLine = "DUMPBIN : fatal error " OR cLine=" Bound to"
?cLine
EXIT
ENDIF
IF !EMPTY(cLine) AND LEFT(cLine,4)=" "
* ?cLine
IF SUBSTR(cLine,5)!=' '
m.Module=ALLTRIM(cline)
?m.Module
IF !SEEK(UPPER(m.Module),"modules")
GetImports(m.Module,nLevel+1) &&Recur!
ENDIF
ELSE
IF LEFT(cline,8) = SPACE(8)
m.Address = GETWORDNUM(cline,1)
m.FuncName = GETWORDNUM(cline,2)
IF m.FuncName != "Import" AND "0" != m.address
INSERT INTO imports FROM MEMVAR
ENDIF
ENDIF
ENDIF
ENDIF
ENDFOR
ENDIF
RETURN
Comments
Anonymous
January 30, 2006
The comment has been removedAnonymous
January 30, 2006
it's even changing the comments.
That should be Cline = square brackets around the variable i<sigh>Anonymous
February 05, 2006
Did You try giving a space between sq bracket open and close i mean [ i ]Anonymous
February 05, 2006
So, I don't see a bulb like [i] <- in my previous comment so you could use the same stuff..Anonymous
February 06, 2006
It appears the light bulb thing was fixed in the blog hosting software. Here's a test:
This should be an 'i' in square brackets: [i]Anonymous
February 26, 2007
Let’s log all the calls that Excel makes to open or create a file. Start Visual Studio (any version),Anonymous
May 06, 2007
Nice http://myurl.com.tw/h7ht <a href="http://myurl.com.tw/h7ht">laptop pc</a> [url=http://myurl.com.tw/h7ht]personal computer[/url]Anonymous
July 27, 2007
When you start a program on your Windows XP computer, a process is created and several DLLs (DynamicAnonymous
July 27, 2007
When you start a program on your Windows XP computer, a process is created and several DLLs (DynamicAnonymous
August 06, 2007
You can use CreateToolhelp32Snapshot and its family of functions to enumerate the running processes onAnonymous
June 13, 2009
PingBack from http://homelightingconcept.info/story.php?id=800