Hi all there,
I'm studing the Iczelion tutorial 24: Windows Hooks. In this tut Iczelion shares a DLL's data section among other processes by the help of linker switch.

/SECTION:<section name>,S

My question is how to make it with nasm and/or alink?

NOT:As I see, alink don't have such a linker switch. Maybe sharing a section could be done inside nasm itself without alink. I saw a lot of section declarations like this;


Can I code something like this?

Posted on 2004-07-27 16:08:37 by
If all else fails, create a regular data section (with a name like "shared" or "foo" or "happyho"), and use a PE editor to change the section flags after linking.

Or consider getting a new linker - pelle's polink might do the trick, http://www.smorgasbordet.com/pellesc/index.htm .
Posted on 2004-07-27 16:23:15 by f0dder
Thanks for fast reply. I'll do all you said. Using a PE editor is realy a nice idea. And I imagined another way. I'll not create a shared data segment. Instead I'll put shared segment's variables directly inside code segment with the help of nasm-nagoa+ 's CONST macro. I'm not sure if this method works?

%include 'nagoa+.inc'


CONST,hWnd resd 1
CONST,hHook resd 1

proc DllMain,hInst,reason,reserved
Posted on 2004-07-27 17:12:46 by
I guess that shared mean common in nasm.

You can check http://nasm.sourceforge.net/doc/html/nasmdoc6.html#section-6.2 with nagoa is used the switch -obj check that ;).

A yes, continue reading that section 6.2.x, for other things about the format.

Have a nice day or night.
Posted on 2004-07-27 18:44:10 by rea

Instead I'll put shared segment's variables directly inside code segment with the help of nasm-nagoa+ 's CONST macro.

When you add SHARED flag to a section in a PE file, that section will be *shared* across all instances of the running image.

To explain what that means, let me first describe what happens with a NOT shared data section. Sections are generally shared across multiple instances - once you write to a section, the page you access will get a private copy in the process that does a write. This is called copy-on-write.

Okay, that was a bit cryptic. Imagine you have "C:A.EXE" and run it three times (click on it in explorer, whatever). Initially, all three instances will share the memory for the code and data. When on of the three instances try to write to a byte in memory, the process will get a private version of the 4kb region if writes to.

With shared sections, all instances of the process will write to the same memory.

Okay, this explanation sucked, tell me if you didn't understand and I'll try explaining it better. Anyway for hooks you'll need shared sections....
Posted on 2004-07-27 20:10:06 by f0dder
I found some information in nasm-help. It explains obj file format (OMF) and extensions to the segment (section) directive.

segment code private align=16

"defines the segment code, but also declares it to be a private segment, and requires that the portion of it described in this code module must be aligned on a 16-byte boundary.
The available qualifiers are: "

1) "PRIVATE, PUBLIC, COMMON and STACK specify the combination characteristics of the segment. PRIVATE segments do not get combined with any others by the linker; PUBLIC and STACK segments get concatenated together at link time; and COMMON segments all get overlaid on top of each other rather than stuck end-to-end. "

4) "OVERLAY, like CLASS, is specified with an arbitrary word as an argument, and provides overlay information to an overlay-capable linker."

I quoted some lines from nasm-help. I think COMMON extension which is explained in above will do the shared segment but I'm not sure. And I din't find any other information about how to chance section attributes inside nasm. As you see SHARED keyword don't contained explicitly inside nasm-help. In section 5.6 another interesting directive explained:

"COMMON: Defining Common Data Areas:

The COMMON directive is used to declare common variables. A common variable is much like a global variable declared in the uninitialised data section, so that

common intvar 4 ;I don't know what that 4 means?

is similar in function to

global intvar
section .bss

intvar resd 1

The difference is that if more than one module defines the same common variable, then at link time those variables will be merged, and references to intvar in all modules will point at the same piece of memory. "
Posted on 2004-07-28 00:09:39 by
Finaly, I came to the following results,

i-As f0dder said I create a new section and than after assembling and linking opened the file with PEditor and changed section characteristics to include shared option. After all of that app worked properly.

ii-I added section extension option COMMON to the nasm source code as below,


var1 resd 1

And after assembling and linking app. only worked locally. Hook function doesn't worked among other processes. I think COMMON section extension option doesn't equal to the SHARED

iii-I used common directive with the variables I would like to share among other processes as below,


common var1 4
common var2 4

And after assembling and linking app only locally worked. I think this common directive behaves like global directive and it has no effect to make variables SHARED.


I'd like to thank to f0dder for his detailed explanations and hgb for his referances.:alright:
Posted on 2004-07-28 05:13:56 by
...you really should get another linker so you don't have to do the manual PE editing. Doesn't look like nasm supports 'shared' section neither in OMF or COFF mode, but that's probably because of the object format itself?
Posted on 2004-07-28 08:34:39 by f0dder
Hi highenergy:

I have added a new "-share" option to ALINK.

You can download it from:

This version has other ALINK bugs fixed.

I have tested it with some sources that you wrote:
Posted on 2004-08-18 15:56:49 by n u M I T_o r
numitor, have you sent those changes to the ALINK author? Is he still reachable, even if alink seems more or less dead? And is there a non-yahoo-groups place to get it, I hate all that signup crap :)
Posted on 2004-08-18 19:07:31 by f0dder