flat assembler
Message board for the users of flat assembler.

Index > Heap > static link & dynamic link, what are they?

Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 8903
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
maybe guys can chip in some information about static & dynamic link.

what are the advantages & disadvantages, and best advice for application building,

what is that static link Laughing
Post 09 Jul 2012, 03:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Static link means no DLL or SO files. Essentially all just one executable file.
Post 09 Jul 2012, 03:37
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8903
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
does the linker copy the "proc code" into our exe or dll?

if let say we use MessageBox in user32.dll, does it means the "total" code to perform MessageBox is copied into our application?

because i read somewhere on the net, they said even if static link, i still need the dll, (which kinda confuse).
Post 09 Jul 2012, 03:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
The linker can't link to OS files made by another company unless you can get the .obj files from MS. If you are talking about Windows then the design of the OS means you have to link to at least one of the OS DLLs, but for Linux you don't have such a restriction. But either way, one generally doesn't include the OS requirements when talking about static linking.
Post 09 Jul 2012, 03:52
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
Linker does not copy the code.
When you use import table in FASM code - it is static linking.

When you call LoadLibrary/GetProcAddress from your FASM code -- it is dynamic linking.
Post 09 Jul 2012, 17:20
View user's profile Send private message Send e-mail Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8903
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
hi AsmGuru

sorry, i don't understand, but if linker does not copy the code in static link, then what is the difference compare to dynamic link?

i assume,
dynamic link is

my application starting addres
40,000

then i use some dll function through LoadLibrary,
if i use GetProcAddress, then OS load the whole dll, go through the dll exported functions, return to me address that fit my application address range, (assume my app address range is 40,000 to 60,000) then OS gave me 60,001 for functionABC

if i call [60,001], then OS will based on that table then call the functionABC that reside on only OS knows where the dll is loaded.



then how about static link?
the OS still need to load the dll,

assume once assembled, i import functionABC, functionDEF

then another dll, i import function123, function456

is it during assembly time, the assembler decide (make the import table)

functionABC = 60,001 is calling to ABC.DLL 34,000
functionDEF = 60,002 is calling to ABC.DLL 34,001

then

function123 = 60,003 is calling to NUMBER.DLL 34,000
function234 = 60,004 is calling to NUMBER.DLL 34,001

?

is my terminology makes sense? (this is what i understood so far)
Post 09 Jul 2012, 21:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
AsmGuru62 wrote:
Linker does not copy the code.
Yes it does. That is its job.
AsmGuru62 wrote:
When you use import table in FASM code - it is static linking.
No. That is dynamic linking.
AsmGuru62 wrote:
When you call LoadLibrary/GetProcAddress from your FASM code -- it is dynamic linking.
No. That is delayed linking.
Post 09 Jul 2012, 22:35
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8903
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
yo,
i do a little bit coding to see how do i call unexported functions inside a dll, it seems that we could call them quite easily

Code:
format PE GUI 4.0
include 'win32ax.inc'

.code
start:
invoke       LoadLibrary,"DLL1.DLL"
            mov     [libh],eax
          .if eax <> NULL
                       invoke  OutputDebugString,"LoadLibrary - Loaded"
                  invoke  GetProcAddress,[libh],"function1"
                                 mov  [func1],eax
                                    .if eax <> NULL
                                               invoke  OutputDebugString,"GetProcAddress - func1"
                                                                push 40
                                                             call [func1]
                                                                mov  eax,[func1]
                                                            add  eax,72
                                                         mov  [func2],eax
                                                            push 50
                                                             call [func2]
                                        .else
                                               invoke  OutputDebugString,"GetProcAddress - NULL"
                                 .endif
                      invoke  FreeLibrary,[libh]
          .else
                       invoke  OutputDebugString,"LoadLibrary - NULL"
            .endif
invoke        ExitProcess,0

.data
func0             dd 0
func1           dd 0
func2           dd 0
libh            dd 0
    


the dll
Code:
include 'win32ax.inc'
dummy1 = dllexportfunction0
dummy2 = dllexportfunction2

section '.text' code readable executable
; --------------------------------------
proc dllexportfunction1 param1
 cinvoke wsprintf,buff,"dllexportfunction1 param1 = %lu",[param1]
  invoke  OutputDebugString,buff
      ret
endp

proc dllexportfunction2 param1
   cinvoke wsprintf,buff,"dllexportfunction2 param1 = %lu",[param1]
  invoke  OutputDebugString,buff
      ret
endp
    


could we overwrite the dll proc1 address to another code?

well, i got Access Violation if i do the following
Code:
mov  eax,[func1]
xor  ecx,ecx
mov  byte [eax],56h
mov  cl,[eax]
    


but if i set the .code section to writeable in dll, then it works

now how to hack a dll .code section to WRITEABLE Smile yummy!!
Post 10 Jul 2012, 01:44
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
revolution: the whole point of DLLs is to NOT COPY the code.
Maybe linker copies something, but not the code of function themselves -- maybe just the stubs (those JMPs to the real code).

From MSDN:
=============
DLLs provide a way to modularize applications so that their functionality can be updated and reused more easily. DLLs also help reduce memory overhead when several applications use the same functionality at the same time, because although each application receives its own copy of the DLL data, the applications share the DLL code.
=============

Now, I am not sure what to believe...
Post 10 Jul 2012, 03:45
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
AsmGuru62: You are talking about the OS runtime loader. A linker is still required at compile time to link the original DLLs or EXEs (of course fasm has an internal linker).
Post 10 Jul 2012, 04:08
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
of course fasm has an internal linker
fasm does not contain a linker - when you use object output, you need an external one, and when you use the executable output, the resulting file is simply being "scripted" by the source, exactly in order. For instance, that is why with fasm you cannot merge out-of-order sections during assembly - this is something a linker would do. And of course static linking is not possible with fasm alone (maybe with the exception of .RES files).
Post 10 Jul 2012, 08:19
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
I see.
sleepsleep was asking if code for MessageBox is copied into application.
It is not. But I may be confused about the types of linking.
For me static means: FASM build the code and just call to a DLL happens through that built code.
Dynamic (or delayed) is for me that code needs to be written to load the DLL, find the function and call it.
Post 10 Jul 2012, 13:55
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.