flat assembler
Message board for the users of flat assembler.

Index > Windows > How do i can link form fasm with mingw?

Author
Thread Post new topic Reply to topic
MinhHung



Joined: 10 Sep 2010
Posts: 51
Location: Viet Nam
MinhHung
Hello!!!

I have one source in fasm and one in C(mingw)

when i link it

[Error] C:\Users\admin\Documents\C-Free\Projects\newinject32\mingw5\main.o:main.cSad.text+0x2fa): undefined reference to `InjectDll'
[Error] C:\Users\admin\Desktop\object.OBJ:(.flat+0xf): undefined reference to `OpenProcess'
[Error] C:\Users\admin\Desktop\object.OBJ:(.flat+0x36): undefined reference to `VirtualAllocEx'
[Error] C:\Users\admin\Desktop\object.OBJ:(.flat+0x52): undefined reference to `WriteProcessMemory'
[Error] C:\Users\admin\Desktop\object.OBJ:(.flat+0x57): undefined reference to `LoadLibraryW'
[Error] C:\Users\admin\Desktop\object.OBJ:(.flat+0x61): undefined reference to `Sleep'
[Error] C:\Users\admin\Desktop\object.OBJ:(.flat+0x80): undefined reference to `VirtualAllocEx'
[Error] C:\Users\admin\Desktop\object.OBJ:(.flat+0x9b): undefined reference to `WriteProcessMemory'
[Error] C:\Users\admin\Desktop\object.OBJ:(.flat+0xb7): undefined reference to `CreateRemoteThread'
[Error] collect2: ld returned 1 exit status

_________________
sorry for my english
Post 24 May 2012, 09:39
View user's profile Send private message Yahoo Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17667
Location: In your JS exploiting you and your system
revolution
It looks as though you need to link with the Windows API libraries also. kernel32.lib etc.
Post 24 May 2012, 09:46
View user's profile Send private message Visit poster's website Reply with quote
MinhHung



Joined: 10 Sep 2010
Posts: 51
Location: Viet Nam
MinhHung
ld C:\Users\admin\Documents\C-Free\Projects\newinject32\mingw5\main.o C:\Users\admin\Documents\C-Free\Projects\newinject32\mingw5\newinject32.o C:\Users\admin\Documents\C-Free\Projects\newinject32\mingw5\object.OBJ -o C:\Users\admin\Documents\C-Free\Projects\newinject32\mingw5\newinject32.exe "C:\Program Files (x86)\C-Free 5\mingw\lib\libuser32.a"...etc ect...
and in object.obj contain InjectDll
--sorry, i cannot post code here
Post 24 May 2012, 10:02
View user's profile Send private message Yahoo Messenger Reply with quote
MinhHung



Joined: 10 Sep 2010
Posts: 51
Location: Viet Nam
MinhHung
in object.asm

extrn 'LoadLibraryW' as LoadLibraryW:dword
extrn 'WriteProcessMemory' as WriteProcessMemory:dword
extrn 'CreateRemoteThread' as CreateRemoteThread:dword
extrn 'Sleep' as Sleep:dword
extrn 'VirtualAllocEx' as VirtualAllocEx:dword
extrn 'OpenProcess' as OpenProcess:dword
public InjectDll as 'InjectDll'
Post 24 May 2012, 10:02
View user's profile Send private message Yahoo Messenger Reply with quote
MinhHung



Joined: 10 Sep 2010
Posts: 51
Location: Viet Nam
MinhHung
sources of object.asm like this:
Code:
format MS COFF

include 'win32a.inc'
extrn 'LoadLibraryW' as LoadLibraryW:dword
extrn 'WriteProcessMemory' as WriteProcessMemory:dword
extrn 'CreateRemoteThread' as CreateRemoteThread:dword
extrn 'Sleep' as Sleep:dword
extrn 'VirtualAllocEx' as VirtualAllocEx:dword
extrn 'OpenProcess' as OpenProcess:dword
public  InjectDll as 'InjectDll'

PROCESS_CREATE_THREAD = 2h
PROCESS_VM_OPERATION  = 8h
PROCESS_VM_READ       = 10h
PROCESS_VM_WRITE      = 20h
PROCESS_QUERY_INFORMATION       =       400h

MEM_COMMIT      =       0x1000
MEM_RESERVE     =       0x2000

PAGE_READWRITE  =       0x4
PAGE_EXECUTE    =       0x10


proc InjectDll Pid,DllName
  invoke OpenProcess,PROCESS_CREATE_THREAD+PROCESS_VM_OPERATION+PROCESS_VM_READ+PROCESS_VM_WRITE+PROCESS_QUERY_INFORMATION,0,[Pid]
  test eax,eax
  je InjectDll_exit
        invoke VirtualAllocEx,0,0,0,0,0
        invoke WriteProcessMemory,0,0,0, 0, NULL
        invoke CreateRemoteThread,0,0,0,0,0,0,0
  InjectDll_exit:
  ret
endp    

in C

Code:
extern void InjectDll(DWORD,WCHAR*);    


i'm really sorry, i cant post my code here, this is law of my group
Post 24 May 2012, 10:21
View user's profile Send private message Yahoo Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17667
Location: In your JS exploiting you and your system
revolution
It could be the underscore thing: extrn '_Sleep' as Sleep:dword

Or perhaps: extrn '_Sleep@4' as Sleep:dword

Or some other name mangling.
Post 24 May 2012, 12:02
View user's profile Send private message Visit poster's website Reply with quote
SFeLi



Joined: 03 Nov 2004
Posts: 140
SFeLi
Code:
extrn '_LoadLibraryW@4' as LoadLibraryW:dword
extrn '_WriteProcessMemory@20' as WriteProcessMemory:dword
extrn '_CreateRemoteThread@28' as CreateRemoteThread:dword
extrn '_Sleep@4' as Sleep:dword
extrn '_VirtualAllocEx@20' as VirtualAllocEx:dword
extrn '_OpenProcess@12' as OpenProcess:dword
public  InjectDll as '_InjectDll@8'

; Link with
ld asm.obj whatever.else.o -lkernel32
    
Post 24 May 2012, 16:57
View user's profile Send private message Reply with quote
MinhHung



Joined: 10 Sep 2010
Posts: 51
Location: Viet Nam
MinhHung
Thanks... Smile
Post 25 May 2012, 09:38
View user's profile Send private message Yahoo Messenger 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 cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.