The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Magnum on October 26, 2009, 09:06:26 PM

Title: Where did imagehlp.lib go to?
Post by: Magnum on October 26, 2009, 09:06:26 PM
I need imagehlp.lib in order to use MapFileAndCheckSum.

It's not in the library directory and I can't find it anywhere.

I thought maybe it was in the old Masm32 V. 8.0, but I can't find it either.

Does anyone have a copy of it that they could upload?

Thanks.
Title: Re: Where did imagehlp.lib go to?
Post by: jj2007 on October 26, 2009, 09:49:01 PM
The Genesys package has it afaik.
Title: Re: Where did imagehlp.lib go to?
Post by: rags on October 26, 2009, 10:06:15 PM
You could also use POLIB from PellesC to make the import lib from the DLL.
Title: Re: Where did imagehlp.lib go to?
Post by: hutch-- on October 26, 2009, 11:33:44 PM
Magnum,

You would need to check to see if later versions of Windows still have that functionality available. Image manipulation was available for Win9x versions but from memory it changed with Win2000 and later NT based OS versions. Somewhere along the line I think some of it was transferred to system DLLs like kernel32 and similar.
Title: Re: Where did imagehlp.lib go to?
Post by: MichaelW on October 27, 2009, 01:04:11 AM
IMAGEHLP.DLL and dbghelp.dll seem to be related, but I'm not sure what the relationship is.

On my Windows 2000 SP4 system, the system32 directory includes IMAGEHLP.DLL and dbghelp.dll, both in version 5.0.2195.6613.

On my Windows XP HE SP1 system, the system32 directory includes imagehlp.dll and dbghelp.dll, both in version 5.1.2600.1106.

My MASM32 version 9 installation includes imagehlp.inc and dbghelp.inc, and the import libraries imagehlp.lib and dbghelp.lib. Since the dates of the import libraries match those of the other import libraries, I assume that they were part of the distribution.

My MASM32 version 10 installation includes imagehlp.inc, but not dbghelp.inc or either of the import libraries.

My Windows Server 2003 PSDK (dated February 2003) includes both of the import libraries, and they should be useable.
Title: Re: Where did imagehlp.lib go to?
Post by: Magnum on October 27, 2009, 04:42:01 AM
I found the library, but I can't get it to work right.

I keep getting error_invalid_handle.

This would make a decent checksum if I can get it to work.

Andy


.DATA

szFileName db "C:\masm32\SOURCE\intel.txt",0
dwCheckSum  dd  0
Store_Value dd  0

.data? 

dwHeaderSum dw  ?

.CODE

start:

invoke MapFileAndCheckSum, addr szFileName, addr dwHeaderSum, addr dwCheckSum
Title: Re: Where did imagehlp.lib go to?
Post by: Magnum on October 27, 2009, 04:45:47 AM
Quote from: MichaelW on October 27, 2009, 01:04:11 AM

My Windows Server 2003 PSDK (dated February 2003) includes both of the import libraries, and they should be useable.


The 2003 SDK is where I found imagehlp.lib.

Since masm32 has the imagehlp.inc, it seem logical that imagehlp.lib would also be present since
MapFileAndCheckSum won't work without both of them.

Andy
Title: Re: Where did imagehlp.lib go to?
Post by: MichaelW on October 27, 2009, 05:56:55 AM
The attachment contains three examples that call the MapFileAndCheckSum function. The first one uses the MASM32 version 9 import library and calls the function with invoke. The second one uses LoadLibrary and GetProcAddress and calls the function with the call instruction after pushing the arguments. The third one uses LoadLibrary and GetProcAddress, along with the SPROTO macro so the function can be called with invoke.

I also tested the import library from the PSDK, with a modified version of the first example, and it worked fine.

AFAICT without a .DEF file POLIB creates an import library without the @N decoration on the names. I expect the resulting import library will work with POLINK, but I could not find any way to make it work with the Microsoft linker.
Title: Re: Where did imagehlp.lib go to?
Post by: Vortex on October 27, 2009, 07:22:32 PM
With some macro tricks, it's possible to call functions from import libraries with non-decorated symbols :

Building the import library :

\masm32\bin\lib /OUT:imagehlp.lib /DEF:imagehlp.def /MACHINE:IX86


.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     invoke.inc

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


EXTERN      MapFileAndCheckSumA:PROC


.data
format1     db 'Headersum = %X',13,10
            db 'Checksum   = %X',0

capt        db 'imagehlp demo',0
TestEXE     db 'SimpleWnd.exe',0

.data?

HeaderSum   dd ?
CheckSum    dd ?
buffer      db 128 dup(?)

.code

start:

   _invoke  MapFileAndCheckSumA,ADDR TestEXE,\
            ADDR HeaderSum,ADDR CheckSum

    invoke  wsprintf,ADDR buffer,ADDR format1,\
            HeaderSum,CheckSum

    invoke  MessageBox,0,ADDR buffer,ADDR capt,MB_OK               

    invoke  ExitProcess,0

END start


Building the project :


\masm32\bin\ml /c /coff imagehlpDemo.asm
\masm32\bin\link /SUBSYSTEM:WINDOWS imagehlpDemo.obj

Title: Looks OK
Post by: Magnum on October 27, 2009, 07:39:23 PM
Thanks for all the help that everyone gave me.

I wanted a non-console program and this is what I came up with.

Is there a way that I can make Orig_ChkSum to where I don't have to "manually"
change the order?

Thanks



.DATA

szFileName     db   "C:\masm32\SOURCE\INTERRUPTS.asm",0
szAppName      db   "Box",0
headerSum      dd   0
checkSum       dd   0
szFileChanged  db   "The file has changed.",0
szFile_OK      db   "File has not been altered.",0

Orig_ChkSum    dd   576623h ; value of UNaltered file - Stores in REVERSE order !!
                   
.data?

dwHeaderSum    dw  ?
hWnd           dd  ?
dwCheckSum     dd  ?

.CODE

start:

invoke MapFileAndCheckSumA, ADDR szFileName, ; Do a checksum of our file
                            ADDR headerSum,
                            ADDR checkSum

mov eax, checkSum    ; move value to EAX

.if eax == Orig_ChkSum ; Check if file has been altered
invoke  MessageBox, NULL, addr szFile_OK, addr szAppName,MB_OK

  .else
 
  invoke MessageBox,NULL,addr szFileChanged,addr szAppName,MB_OK
 
.endif

invoke ExitProcess,0

end start


Title: Re: Where did imagehlp.lib go to?
Post by: Vortex on October 29, 2009, 06:20:37 PM
Here is another version of the example project where the import library imahlp.lib is built with Polib.exe