News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

DLL Export Name

Started by guga, April 11, 2020, 06:36:32 AM

Previous topic - Next topic

guga

Hi guys

Do windows dlls have a list of forbidden chars for the export function name of a dll ? I mean, can i have a dll with a export function like:

"My Function" - (with a space anywhere the function name)
";MyFunction" - (with a colon sign anywhere the function name)
"My,Function" - (with a comma sign anywhere the function name)
"My'Function"  - (with a single quote char anywhere the function name)

So...if it have some forbidden chars to be used as the name of a exported function, what are those chars ?


Note: I´m not talking about the decoretaed name that allows chars like @ ? _ # etc... I would like to know if there are other chars that are strictly forbidden to be used as a export function name
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

Test it... write your own DLL, then insert chars with a hex editor.

I did some tests, and it seems that the OS has means to detect changes. Attached a test project: when you run the exe, it allows to poke one char into MyReal8. GetProcAddress, handle, M?Real8 works fine as long as the ? is y. Even uppercase Y won't work, so it seems that a checksum is involved to prevent poking around.

hutch--

Guga,

I would be inclined to stick to normal alphabetical characters as the conventions for things like export name was settle long ago and before spaces and punctuations were allowed in file names.

aw27

Quote from: guga on April 11, 2020, 06:36:32 AM
"My Function" - (with a space anywhere the function name)
";MyFunction" - (with a colon sign anywhere the function name)
"My,Function" - (with a comma sign anywhere the function name)
"My'Function"  - (with a single quote char anywhere the function name)

None of the above are acceptable.
Acceptable:

[_,a..z,A..Z], [0..9] for characters after first.
Untested/Uncertain:
- Some Unicode code points.
- $
- ASCII after 127 when using specific code pages.



Vortex

No any problem with the leading symbol $ :

.386
.model flat, stdcall
option casemap :none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib
includelib  simpleDLL.lib

$StrLen      PROTO :DWORD

.data

message     db 'Hello world!',0
str1        db 'StrLen = %d',0

.code

start:

    invoke  $StrLen,ADDR message
    invoke  crt_printf,ADDR str1,eax                                               
    invoke  ExitProcess,0

END start

jj2007

Quote from: Vortex on April 11, 2020, 09:23:51 PM
No any problem with the leading symbol $

Not tested, but it probably works also for the question mark. These are legal chars used in macros etc.

Vortex

Quote
Not tested, but it probably works also for the question mark. These are legal chars used in macros etc.

The question mark does not pose any problem, that's OK. I tested it now.

aw27

I think the question mark is a hint for C++ linkage, otherwise is not a legal character.

nidud

#8
deleted

guga

Thanks guys

Indeed the OS seems to not allow some specific chars. Unfortunately, i didn´t find anywhere what those chars are. This was for a update i made in rosAsm on a function that imports the Apis using LoaLibraryEx, LoadLibrary to assemble the app. I would like to make a extra security check in case a user made a mistake typing invalid chars as the name of a api.

I´m quite sure the space ' '  is not allowed, but i was wondering what are the other chars.

Btw....Nidud and AW

You mean Ansi chars, right ? So, valid chars are:
a to z
A to Z
0 to 9
_
?

But....watcom, OpenVMS, Visual Studio, GCC, IAR EWARM allows also "(" and ")" and "$" and "@" and "<" ">" ASCII after 127 when using specific code pages. ?

So, if those others chars and rules are allowed is it safe to use them on any Windows Version ?

Are there any other chars that are valid ?

https://en.wikipedia.org/wiki/Name_mangling
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

nidud

#10
deleted

aw27

#11
We are talking about exported functions from DLLs not about identifiers in general.
For those I believe only the following characters are acceptable:
[_,a..z,A..Z], [0..9] for characters after first
With C++, the ? character exists and  has a special meaning.

However, for internal functions of a program more characters are acceptable, including some Unicode code points and after-127 ASCII characters. The $ is a Microsoft extension.

See:
https://docs.microsoft.com/en-us/cpp/cpp/identifiers-cpp?view=vs-2019

hutch--

There is another alternative and that is to use ordinals instead of names. I rarely ever use it but it does work and it appears to be a Microsoft technique to make tracking the exports more obscure, mainly against hacking.

nidud

#13
deleted

jj2007

Quote from: hutch-- on April 12, 2020, 07:14:38 PM
There is another alternative and that is to use ordinals instead of names. I rarely ever use it but it does work and it appears to be a Microsoft technique to make tracking the exports more obscure, mainly against hacking.

You can even use equates in your sources to de-obscure them

PrintReal10Index=123
.data?
PrintReal10  dd ?
.code
mov PrintReal10, rv(GetProcAddress, MyDll, PrintReal10Index)
push FP10(123.456)
call PrintReal10