mrfearless / UASM-SDK

UASM SDK
11 stars 8 forks source link

error: unresolved external symbol; some libraries may be wrong? #1

Open blue-devil opened 2 years ago

blue-devil commented 2 years ago

Hello @mrfearless , how'r you doin'?

I have setup RadASM with UASM. I had issues if i use libraries in this repo.

Platform: OS : Windows 10 x64 IDE : RasASM v2.2.2.3

Assembler : UASM v2.55 Assembler PATH : C:\UASM Library Path : C:\UASM\Lib\x64

Sample MessageBox Code I have created a new project under RadASM UASM64 -> WIN64 -> Without template and pasted the code


;--- Win64 "hello world" GUI application.
;--- assemble: 

    option casemap:none

    includelib kernel32.lib
    includelib user32.lib

externdef MessageBoxA : near
externdef ExitProcess : near

    .data

text    db 'Hello world!', 0
caption db 'Hello x86-64', 0

    .code

OPTION PROC:NONE
main proc
    sub rsp, 28h        ; space for 4 arguments + 16byte aligned stack
    xor r9d, r9d        ; 4. argument: r9d = uType = 0
    lea r8, [caption]   ; 3. argument: r8  = caption
    lea rdx, [text]     ; 2. argument: edx = window text
    xor rcx, rcx        ; 1. argument: rcx = hWnd = NULL
    call MessageBoxA
    xor ecx, ecx        ; ecx = exit code
    call ExitProcess
main endp

    end

RADASM OUTPUT Then I hit the build button

\UASM\Bin\UASM64.exe /c -win64 -Zp8 /win64 /D_WIN64 /Cp /nologo /W2 /I"\UASM\Include" "GUI-MessageBox.asm"
GUI-MessageBox.Asm: 36 lines, 2 passes, 1 ms, 0 warnings, 0 errors
\UASM\Bin\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /MACHINE:X64 /LIBPATH:"\UASM\Lib\x64" /OUT:"GUI-MessageBox.exe" "GUI-MessageBox.obj" "GUI-MessageBox.res"
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation.  All rights reserved.

\UASM\Lib\x64\kernel32.lib : warning LNK4003: invalid library format; library ignored
\UASM\Lib\x64\user32.lib : warning LNK4003: invalid library format; library ignored
GUI-MessageBox.obj : error LNK2019: unresolved external symbol MessageBoxA referenced in function main
GUI-MessageBox.obj : error LNK2019: unresolved external symbol ExitProcess referenced in function main
LINK : error LNK2001: unresolved external symbol WinMainCRTStartup
GUI-MessageBox.exe : fatal error LNK1120: 3 unresolved externals

Make error(s) occured.
Total compile time 187 ms

So I changed the library path to one of my windows sdk's and build again(i also added /ENTRY:main)

\UASM\Bin\UASM64.exe /c -win64 -Zp8 /win64 /D_WIN64 /Cp /nologo /W2 /I"\UASM\include" "GUI-MessageBox.asm"
GUI-MessageBox.Asm: 36 lines, 2 passes, 1 ms, 0 warnings, 0 errors
\UASM\Bin\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /MACHINE:X64 /ENTRY:main /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64" /OUT:"GUI-MessageBox.exe" "GUI-MessageBox.obj" "GUI-MessageBox.res"
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Make finished.
Total compile time 187 ms

So what is the problem. I have checked several lib files in this repo -like kernel32 and user32- and they are slightly problematic. For example we can open a lib file with 7zip. Because they are a kind of archive files. you cannot open kernel32.lib and user32.lib in your this repo. But also there are some libraries are working like msvcrt.lib

We can also use detect-it-easy for cheking! If we open a normal working library with die, we get this output:

Binary
Archive: Coff library[AMD64]

But if it is a problematic library, die says:

Binary

Finally -maybe temporary- workaround is using library files under windows sdk!

mrfearless commented 2 years ago

Thanks for checking it out. Yes, I think some of the older libraries might possibly be corrupt (might have been when i originally uploaded them to github and github added or stripping carriage returns and line feeds possibly) Think the libraries originally came from PellesC, but I may have replaced/updated my own local ones from the Windows SDK over time. I updated the UASM-SDK repo to include a note about the libraries for other users.

If you find ones that are working and want to send a pull request to the UASM-SDK repo then free to do so. I should probably update the UASM in the repo as well - but as its an unofficial SDK I kinda left it in case anyone wasn't happy with me gathering the various binaries, includes and libraries together and uploading then into one 'SDK' onto github. I could then say "sorry, it wasnt being actively maintained" and take it down then. But who knows, it been a few years now, so maybe people are just happy to turn a blind eye :D

Anyhow thanks for letting me know about it, and for using the Uasm-with-Radasm as well.

Cheers

On Thu, Aug 18, 2022 at 12:43 PM Blue DeviL @.***> wrote:

Hello @mrfearless https://github.com/mrfearless , how'r you doin'?

I have setup RadASM with UASM. I had issues if i use libraries in this repo.

Platform: OS : Windows 10 x64 IDE : RasASM v2.2.2.3

Assembler : UASM v2.55 Assembler PATH : C:\UASM Library Path : C:\UASM\Lib\x64

Sample MessageBox Code I have created a new project under RadASM UASM64 -> WIN64 -> Without template and pasted the code

;--- Win64 "hello world" GUI application.;--- assemble: option casemap:none includelib kernel32.lib includelib user32.lib externdef MessageBoxA : nearexterndef ExitProcess : near .data text db 'Hello world!', 0caption db 'Hello x86-64', 0 .code OPTION PROC:NONEmain proc sub rsp, 28h ; space for 4 arguments + 16byte aligned stack xor r9d, r9d ; 4. argument: r9d = uType = 0 lea r8, [caption] ; 3. argument: r8 = caption lea rdx, [text] ; 2. argument: edx = window text xor rcx, rcx ; 1. argument: rcx = hWnd = NULL call MessageBoxA xor ecx, ecx ; ecx = exit code call ExitProcessmain endp end

RADASM OUTPUT Then I hit the build button

\UASM\Bin\UASM64.exe /c -win64 -Zp8 /win64 /D_WIN64 /Cp /nologo /W2 /I"\UASM\Include" "GUI-MessageBox.asm" GUI-MessageBox.Asm: 36 lines, 2 passes, 1 ms, 0 warnings, 0 errors \UASM\Bin\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /MACHINE:X64 /LIBPATH:"\UASM\Lib\x64" /OUT:"GUI-MessageBox.exe" "GUI-MessageBox.obj" "GUI-MessageBox.res" Microsoft (R) Incremental Linker Version 12.00.31101.0 Copyright (C) Microsoft Corporation. All rights reserved.

\UASM\Lib\x64\kernel32.lib : warning LNK4003: invalid library format; library ignored \UASM\Lib\x64\user32.lib : warning LNK4003: invalid library format; library ignored GUI-MessageBox.obj : error LNK2019: unresolved external symbol MessageBoxA referenced in function main GUI-MessageBox.obj : error LNK2019: unresolved external symbol ExitProcess referenced in function main LINK : error LNK2001: unresolved external symbol WinMainCRTStartup GUI-MessageBox.exe : fatal error LNK1120: 3 unresolved externals

Make error(s) occured. Total compile time 187 ms

So I changed the library path to one of my windows sdk's and build again(i also added /ENTRY:main)

\UASM\Bin\UASM64.exe /c -win64 -Zp8 /win64 /D_WIN64 /Cp /nologo /W2 /I"\UASM\include" "GUI-MessageBox.asm" GUI-MessageBox.Asm: 36 lines, 2 passes, 1 ms, 0 warnings, 0 errors \UASM\Bin\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /MACHINE:X64 /ENTRY:main /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64" /OUT:"GUI-MessageBox.exe" "GUI-MessageBox.obj" "GUI-MessageBox.res" Microsoft (R) Incremental Linker Version 12.00.31101.0 Copyright (C) Microsoft Corporation. All rights reserved.

Make finished. Total compile time 187 ms

So what is the problem. I have checked several lib files in this repo -like kernel32 and user32- and they are slightly problematic. For example we can open a lib file with 7zip. Because they are a kind of archive files. you cannot open kernel32.lib and user32.lib in your this repo. But also there are some libraries are working like msvcrt.lib

We can also use detect-it-easy for cheking! If we open a normal working library with die, we get this output:

Binary Archive: Coff library[AMD64]

But if it is a problematic library, die says:

Binary

Finally -maybe temporary- workaround is using library files under windows sdk!

— Reply to this email directly, view it on GitHub https://github.com/mrfearless/UASM-SDK/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANP2PQNCP2KLYPBQ4GIPXTVZYOV7ANCNFSM5644IEKA . You are receiving this because you were mentioned.Message ID: @.***>

blue-devil commented 2 years ago

OK this is sooo interesting; if i clone the repo, all the libs are working, NO PROBLEM

BUT, if i download latest tag or download repo as ZIP, the libraries are becoming broken! All the LF - LineFeeds become CarriageReturnLineFeed - CRLF; WHY? And there are exceptions(like i told above).

Unfortunately, I don't know how to fix this? You can close it if you want @mrfearless

BTW, -temp solution- cloning the repo, eliminates the problem.