News:

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

Creating a DLL with forwarded functions

Started by Vortex, October 02, 2006, 01:15:09 PM

Previous topic - Next topic

Vortex

The simplest solution is to call the functions with their original name :

.386
.model flat, stdcall
option casemap :none

include             \masm32\include\windows.inc
include             \masm32\include\kernel32.inc
includelib         \masm32\lib\kernel32.lib
includelib         console.lib

.data
library             db 'Console.dll',0
message             db 'Hello from function with ordinal number 3',13,10,0

StdOut              PROTO :DWORD

.code

start:

    invoke  StdOut,ADDR message
    invoke  ExitProcess,0

END start


Examining under Ollydbg :

PUSH Demo.0040300C
CALL <JMP.&console.#3>
PUSH 0
CALL <JMP.&kernel32.ExitProcess>
INT3
JMP DWORD PTR DS:[<&kernel32.ExitProcess>;  kernel32.ExitProcess
JMP DWORD PTR DS:[<&console.#3>]         ;  console.#3

[attachment deleted by admin]

Vortex

Creating an import library with Polib is easy, rewrite the functions in decorated form :

LIBRARY console
EXPORTS

"_StrLen@4" @1 NONAME
"_locate@8" @2 NONAME
"_StdOut@4" @3 NONAME
"_ClearScreen@0" @4 NONAME
"_InitLoadTimeDynLink@0" @5


Building the import library :

\pellesc\bin\polib /OUT:console.lib /DEF:console.def /MACHINE:IX86


gwapo

Quote from: japheth on October 06, 2006, 01:25:37 PM

Hi,

> how to export a nameless function (exported by ordinal) in MASM?

the MS linker understands "NONAME" in the .DEF file:

EXPORTS
MyProc   @1 NONAME

IIRC newer versions of POLINK also accept this.



Thanks, that's good to know that there's easier approach :U


Quote from: PBrennick on October 06, 2006, 02:28:37 PM
What would be the purpose of killing the name of an exported function?

My main purpose is because I am writting a DLL from MASM for use by high-level languages, C++/C#, but some exported functions requires some kind of initializations, as it may crash the calling program (i.e., priviledge issues) if not properly initialized. Exporting by ordinal seems a good way to "hide" these critical functions, and I am only accessing these functions by means of "wrapper DLLs" which contains the proper initialization routines for my DLLs.

Of course, there are better approach than "hiding" function names.

Cheers,

-chris

PBrennick

gwapo,
It makes sense to me now and I am very interested in ordinals for something I might do in my project.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

MichaelW

eschew obfuscation