News:

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

Forwarding Export Function

Started by Astro, July 23, 2009, 02:27:01 PM

Previous topic - Next topic

Astro

Hi,

I'm attempting to implement a forwarding export function. It semi-works in that the DLL builds without errors, and when I examine the exports with dumpbin I get the expected results, but when I actually try to use it, I get a run-time error pertaining to a memory access violation.

Running the .EXE in OllyDbg I get two errors:

* Memory at address ... is unreadable.
* GetLastError = ERROR_INVALID_WINDOW_HANDLE (00000578)

The stub DLL is empty.

The real DLL uses CreateFile, and returns true/false. I just re-wrote it in assembler and that made no difference.

Has anyone done this before and got it working? What have I missed?

Real DLL (checkdevice2.dll):

.386
.model flat,stdcall
option casemap:none

include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.code
device db "\\\\.\\Device\\Serial0",0
caption db "Test",0
msg1 db "FALSE",0
msg2 db "TRUE",0

DllEntry proc hInstDLL:DWORD, reason:DWORD, reserved1:DWORD
        mov  eax,1h
        ret 0Ch
DllEntry endp

CheckForDevice proc
push 0h
push 0h
push 3h
push 0h
push 1h
push 0h
push offset device
call CreateFile

cmp eax,-1
jz INVALID

push 0h
push offset caption
push offset msg2
push 0h
call MessageBox

mov eax,1h
ret

INVALID:
push 0h
push offset caption
push offset msg1
push 0h
call MessageBox

mov eax,0h
ret
CheckForDevice endp

end DllEntry


LIBRARY CheckDevice
EXPORTS
CheckForDevice



Stub DLL (checkdevice.dll):

.386
.model flat,stdcall

.code

DllEntry proc hInstDLL:DWORD, reason:DWORD, reserved1:DWORD
        mov  eax,1h
        ret 0Ch
DllEntry endp

end DllEntry


LIBRARY CheckDevice
EXPORTS
CheckForDevice=CheckDevice2.CheckForDevice,@1




Output of dumpbin:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

G:\MASM-Proj\TestDevDLL>dumpbin /exports checkdevice.dll

G:\MASM-Proj\TestDevDLL>Microsoft (R) COFF Binary File Dumper Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Dump of file checkdevice.dll

File Type: DLL

  Section contains the following exports for CheckDevice.dll

           0 characteristics
    4A686FE6 time date stamp Thu Jul 23 15:12:54 2009
        0.00 version
           1 ordinal base
           1 number of functions
           1 number of names

    ordinal hint RVA      name

          1    0          CheckForDevice (forwarded to CheckDevice2.CheckForDevice,@1)

  Summary

        1000 .rdata
        1000 .reloc
        1000 .text

G:\MASM-Proj\TestDevDLL>


Best regards,
Astro.

Astro

Hmm.

Running the same app under Vista 64-bit yielded the following JIT error:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)


EDIT: Rebuilt the EXE as "x86" (it was originally "AnyCPU") and this error has gone. Back to the original problem...

Best regards,
Astro.