Exetools

Exetools (https://forum.exetools.com/index.php)
-   General Discussion (https://forum.exetools.com/forumdisplay.php?f=2)
-   -   How to fix these three RadASM compile errors? (https://forum.exetools.com/showthread.php?t=14920)

bridgeic 04-02-2013 18:07

How to fix these three RadASM compile errors?
 
1 Attachment(s)
I'm working on an asm file, now seems only 3 errors, I don't understand it, anyone can give help? Many thanks.

K:\testasm\_tolower.asm(18) : error A2008: syntax error : _SYSTEM_INFO
K:\testasm\_tolower.asm(38) : error A2008: syntax error : type
K:\testasm\_tolower.asm(498) : error A2081: missing operand after unary operator

bilbo 04-02-2013 19:32

First Error:
first field of _SYSTEM_INFO struc cannot refer itself. In Windows it is an union
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
but you can replace the line
anonymous_0 _SYSTEM_INFO::$1593C2ABA4C275C0FBEC2498FA3B0937 ?
with
dwOemId dd ?
without problems


Second and third error:
"Type" name is a reserved word: simply replace it with _Type, for example


Best regards,
bilbo

bridgeic 04-02-2013 21:57

Quote:

Originally Posted by bilbo (Post 83775)
First Error:
first field of _SYSTEM_INFO struc cannot refer itself. In Windows it is an union
......

It works, many thanks, bilbo.

After generate the .obj file and do LINK with VC, it reports errors below, any lib file I need add when do LINK?

; Imports from KERNEL32.dll
; HMODULE __stdcall GetModuleHandleA(LPCSTR lpModuleName)
externdef GetModuleHandleA:dword

error LNK2019: Unresolved external symbol _GetModuleHandleA
......
error LNK2019: Unresolved external symbol _LeaveCriticalSection

cnbragon 04-02-2013 22:49

you should link with kernel32.lib

bridgeic 04-02-2013 22:57

Quote:

Originally Posted by cnbragon (Post 83788)
you should link with kernel32.lib

But I have used it already, still get this error.

Below is the options I used:

LINK /nologo /NODEFAULTLIB /OPT:NOREF /out:test.exe test.obj lmgr.lib libsb.lib libcrvs.lib .\activation\lib\libnoact.lib oldnames.lib kernel32.lib user32.lib netapi32.lib advapi32.lib gdi32.lib comdlg32.lib comctl32.lib wsock32.lib libcmt.lib _tolower.obj

Av0id 04-03-2013 12:46

you need to set environment variable or include path for those libs in link parameters /LIBPATH, IIRC

bridgeic 04-03-2013 12:59

Quote:

Originally Posted by Av0id (Post 83806)
you need to set environment variable or include path for those libs in link parameters /LIBPATH, IIRC

Hi Av0id,

I do the VC setting as below, is this enough or still something missing? Thank you for your help on check.

@set MYPATH=C:\Program Files\VC2008
@set PATH=%MYPATH%\bin
@set INCLUDE=%MYPATH%\include;%MYPATH%\PlatformSDK\Include;%MYPATH%\atlmfc\include;%MYPATH%\DirectX_SDK\Include;
@set LIB=%MYPATH%\lib;%MYPATH%\PlatformSDK\Lib;%MYPATH%\atlmfc\lib;%MYPATH%\DirectX_SDK\Lib\x86;

bilbo 04-03-2013 13:20

kernel32.lib does not export GetModuleHandleA, but _imp__GetModuleHandleA
So you need to replace
Code:

externdef GetModuleHandleA:dword
with
Code:

pr1 typedef PROTO :DWORD
externdef _imp__GetModuleHandleA@4:PTR pr1
GetModuleHandleA equ <_imp__GetModuleHandleA@4>

Best regards
bilbo

bridgeic 04-03-2013 14:22

Quote:

Originally Posted by bilbo (Post 83811)
kernel32.lib does not export GetModuleHandleA, but _imp__GetModuleHandleA
So you need to replace
Code:

externdef GetModuleHandleA:dword
with
Code:

pr1 typedef PROTO :DWORD
externdef _imp__GetModuleHandleA@4:PTR pr1
GetModuleHandleA equ <_imp__GetModuleHandleA@4>

Best regards
bilbo

Wow, it works, Thanks a million, bilbo.

bridgeic 04-03-2013 14:29

Quote:

Originally Posted by bilbo (Post 83811)
pr1 typedef PROTO :DWORD
externdef _imp__GetModuleHandleA@4:PTR pr1
GetModuleHandleA equ <_imp__GetModuleHandleA@4>
[/CODE]

May I ask one more question, here "@4" mean ? Sorry, I'm newbie on this.

bridgeic 04-03-2013 15:09

Hi Bilbo,

Seems I can't simply copy/paste and just rename the function name as solution for other Unresolved external symbols.

I modify GetLastError as below, but don't works.
pr2 typedef PROTO ��DWORD
externdef _imp__GetLastError@4:PTR pr2
GetLastError equ <_imp__GetLastError@4>

Is there easy way can work it out for all Unresolved external symbols below?

_GetLastError
_MultiByteToWideChar
_WideCharToMultiByte
_GetCurrentProcess
_VirtualAlloc
_VirtualFree
_SetLastError
_WriteFile
_GetModuleFileNameA
_GetSystemInfo
_VirtualProtect
_GetCPInfo
_GetLocaleInfoA
_VirtualQuery
_InterlockedExchange
_InitializeCriticalSection
_GetStringTypeW
_GetStringTypeA
_LoadLibraryA
_GetProcAddress
_GetStdHandle
_GetCurrentThreadId
_LCMapStringW
_LCMapStringA
_ExitProcess
_TerminateProcess
_HeapReAlloc
_HeapAlloc
_HeapFree

bilbo 04-03-2013 20:03

Quote:

I modify GetLastError as below, but don't works.
@4 means the total number of bytes required by function arguments (google for __stdcall calling convention). Now, GetLastError has no args at all. So, if you open kernel32.lib with an hex editor (I suggest you HxD) and look for GetLastError, you will find _imp__GetLastError@0 and not _imp__GetLasterror@4

Quote:

Is there easy way can work it out for all Unresolved external symbols below?
have a look at this link

Quote:

Sorry, I'm newbie on this
I like the approach you are following. I learned a lot of things using exactly the same approach than yours. By the way, how have you solved the assembly errors from defines such as
ms_exc = CPPEH_RECORD ptr -18h
in _tolower.asm?

Best regards
bilbo

bridgeic 04-03-2013 21:30

Quote:

Originally Posted by bilbo

have a look at this link

Sorry, it seems can't be download now, may I get your help to share if you have it?

Quote:

Originally Posted by bilbo
I like the approach you are following. I learned a lot of things using exactly the same approach than yours.

Thank you, I have put much time on it, near succeed now, many thanks for your patience to help me.

Quote:

Originally Posted by bilbo
how have you solved the assembly errors from defines such as
ms_exc = CPPEH_RECORD ptr -18h
in _tolower.asm?

I just add /Zm option when compile to make it back to masm5.10 .



Many many thanks, bilbo, you help me a lots, very appreciated. :)

ragdog 04-04-2013 00:09

Hi

Radasm set standart the environment variable or include path

You must only add in the source include the Lib

Include kernel32.inc
Includelib kernel32.lib

Or use a macro called "uselib"

uselib kernel,gdi32,.....

bridgeic 04-04-2013 01:41

Quote:

Originally Posted by ragdog (Post 83834)
Hi

Radasm set standart the environment variable or include path

You must only add in the source include the Lib

Include kernel32.inc
Includelib kernel32.lib

Or use a macro called "uselib"

uselib kernel,gdi32,.....

Hi ragdog,

I have done that way, but seems doesn't work, would you give more suggestion whether others need check? Thanks.

bilbo 04-04-2013 02:03

1 Attachment(s)
it's strange that you cannot go to the provided link: it is up...
anyway here is the program, from vortex.masmcode.com

and thanks for the /Zm tip I was unaware of...
bilbo

bridgeic 04-04-2013 03:31

Quote:

bridgeic, you do not have permission to access this page. This could be due to one of several reasons:

Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Sorry, why I can't download? I search the web and get this v22 version, but seems always crash both under winxp and win7, really strange.

bilbo 04-04-2013 20:21

@ Av0id, ragdog
I think our importing problems are related to the calling convention adopted, which is supposedly != stdcall

@ bridgeic
it sounds like you are a very unluck man... I tried the program on all masm32 libs without problems...

Best regards, bilbo

bridgeic 04-04-2013 21:25

Quote:

Originally Posted by bilbo (Post 83854)
@ bridgeic
it sounds like you are a very unluck man... I tried the program on all masm32 libs without problems...

Best regards, bilbo

Hi bilbo,

I don't know why I can't download your attachement in exetools forum.

Not sure whether the file lib2inc I used is same with yours, I download it from

http://www.winasm.net/library-to-include.html

Anyway, based on your guide below, I wrote a perl script to solve it as workround.
@4 means the total number of bytes required by function arguments

Thanks,
bridgeic

bilbo 04-05-2013 01:36

Quote:

I don't know why I can't download your attachement in exetools forum.
it is a matter of forum rules... look for an old post http://forum.exetools.com/showthread.php?t=6206

ragdog 04-05-2013 04:12

.686
.model flat, stdcall ;32 bit memory model
option casemap :none ;case sensitive

include windows.inc
include kernel32.inc
includelib kernel32.lib

bridgeic 04-06-2013 08:46

Quote:

Originally Posted by ragdog (Post 83871)
.686
.model flat, stdcall ;32 bit memory model
option casemap :none ;case sensitive

include windows.inc
include kernel32.inc
includelib kernel32.lib

Hi ragdog,

When I set it as your suggestion, RadASM give error below when compile, would you help check why?

D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(11326) : error A2005: symbol redefinition : Red
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(11327) : error A2005: symbol redefinition : Green
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(11328) : error A2005: symbol redefinition : Blue
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(12224) : error A2005: symbol redefinition : fReserved
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(18572) : error A2005: symbol redefinition : Type1
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(18617) : error A2005: symbol redefinition : Type1
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(18621) : error A2005: symbol redefinition : Type1
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(18624) : fatal error A1010: unmatched block nesting

Thanks,
bridgeic

bridgeic 04-06-2013 09:06

Quote:

Originally Posted by ragdog (Post 83871)
.686
.model flat, stdcall ;32 bit memory model
option casemap :none ;case sensitive

include windows.inc
include kernel32.inc
includelib kernel32.lib

Hi ragdog,

question1: When I set it as your suggestion, RadASM give error below when compile, would you help check why?

D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(11326) : error A2005: symbol redefinition : Red
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(11327) : error A2005: symbol redefinition : Green
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(11328) : error A2005: symbol redefinition : Blue
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(12224) : error A2005: symbol redefinition : fReserved
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(18572) : error A2005: symbol redefinition : Type1
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(18617) : error A2005: symbol redefinition : Type1
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(18621) : error A2005: symbol redefinition : Type1
D:\RadASM_2.2.1.9\Masm32\Include\windows.inc(18624) : fatal error A1010: unmatched block nesting

question 2: after remove "include windows.inc", it can be compiled succesfully, but when do LINK in VC, it still reports errors below, how to solve this issue?
error LNK2019: Unresolved external symbol _GetModuleHandleA

Thanks,
bridgeic

ragdog 04-06-2013 15:20

Send me you Project
I look into

bridgeic 04-07-2013 00:09

Quote:

Originally Posted by ragdog (Post 83916)
Send me you Project
I look into

Hi ragdog,

Would you help me have a look on question 1 first?

I'll try to upload the test case for question 2 tomorrow, it's a little big. In fact, it's FlexLM SDK 11.4, if you have it already, I need only share two files then.

Thanks,
bridgeic

ragdog 04-07-2013 00:59

I cannot answer your questions without see your source ;-)

But i think your have trouble with the includes

bridgeic 04-07-2013 01:29

1 Attachment(s)
Quote:

Originally Posted by ragdog (Post 83934)
I cannot answer your questions without see your source ;-)

But i think your have trouble with the includes

Hi ragdog,

For question 1, please get the asm source code as attached, thank you.

bridgeic 04-07-2013 01:32

Hi ragdog,

Another help please, can you run the program lib2inc22.exe that bilbo shared succesfully?

Thanks,
bridgeic

bridgeic 04-07-2013 18:03

Hi ragdog,

Question 1. seems the errors caused by /Zm option

Question 2. Sorry, the test case upload always failed for the slow network speed.

Thanks,
bridgeic

ragdog 04-07-2013 19:38

To convert it to compile it with masm is to many works
What make _tolower convert it uppercase letter to lower?

Example ABCD to abcd?

Or what make this source?


/Zm option
Enables M510 option for maximum compatibility with MASM 5.1.

bridgeic 04-07-2013 22:03

Quote:

Originally Posted by ragdog (Post 83956)
To convert it to compile it with masm is to many works
What make _tolower convert it uppercase letter to lower?

Example ABCD to abcd?

Hi ragdog,

Yes, just convert it uppercase letter to lower. In fact, we can set this whole function as library function instead of including the code of this function in the ASM code. I study it just want to learn more thing.

By your opinion, with right definition of including kernel32.lib, setting below is not must, right?

pr1 typedef PROTO : DWORD
externdef _imp__GetModuleHandleA@4:PTR pr1
GetModuleHandleA equ <_imp__GetModuleHandleA@4>

With this way, I have passed the LINK steps, but the results is not right, I'm still checking what's wrong.

I'll try to build up a small test case, hope you can help me to have a check, many thanks.

By the way, may I check with you whether you can run lib2inc22.exe succesfully?

ragdog 04-08-2013 03:26

Why use you not the apis crt__tolower or CharLower

bridgeic 04-08-2013 17:25

Quote:

Originally Posted by ragdog (Post 83971)
Why use you not the apis crt__tolower or CharLower

The code dump from IDA, just want to study the methodology to modify and compile the dumped code to boj, then call by VC.

bridgeic 04-08-2013 17:31

1 Attachment(s)
Hi ragdog,

Would you help check this small test case, Why failed when do LINK?
( I use the include based on your suggestion)

1. compile newtolower.asm to get newtolower.obj
2. run build.cmd to get newtest.exe(not succesful, can't find newtolower function)

Thanks,
bridgeic

bridgeic 04-08-2013 18:08

1 Attachment(s)
Quote:

Originally Posted by bridgeic (Post 83994)
Hi ragdog,

Would you help check this small test case, Why failed when do LINK?
( I use the include based on your suggestion)

1. compile newtolower.asm to get newtolower.obj
2. run build.cmd to get newtest.exe(not succesful, can't find newtolower function)

Thanks,
bridgeic

After change as below based on other friend's help, the newtest.exe generated, but error reported when run, I attached it here. Although still have errors, the metholodgy ragdog mentioned should be ok, thanks ragdog. If anyone would like help debug the generated newtest.exe run error, I will provide original file that IDA disassembled for reference.
newtolower proc near ,argv1: DWORD

bilbo 04-08-2013 20:19

Quote:

Although still have errors, the metholodgy ragdog mentioned should be ok
not exactly...

again a problem of calling conventions...
newtolower() must be CDECL since the stack is adjusted on return by the caller.. Please google for calling conventions...

In first newtolower.asm you will obtain a decorated name _newtolower@0: that's not ok, it is a STDCALL decoration with 0 bytes as arguments

In second newtolower.asm you will obtain a decorated name _newtolower@4:
that's not ok, it is a STDCALL decoration with 4 bytes as arguments (it gots linked because the function declaration is coherent in both files, but the stack will be corrupted).

So the correct ASM must be:
Code:

newtolower proc near c
But also newtest.c is not correct, since newtolower must not declared as WINAPI (stdcall). Remove it (the default is CDECL):
Code:

extern int newtolower(int);
Finally, the program will yet trap because __getptd is calling
Code:

call dword_57E704
which is a call to 0!

Best regards, bilbo

bridgeic 04-09-2013 09:55

Dear bilbo,

Thank you so much for your warm help, seems "call dword_57E704" will be a Gordian knot��do you have any suggestion how to solve this issue?

bridgeic 04-09-2013 22:09

Quote:

Originally Posted by bilbo (Post 83997)
Code:

call dword_57E704
which is a call to 0!

Hi Bilbo,

Trace with ollydbg, seems the value is assigned outside the newtolower function, I'm not sure whether it is this way, still studying.

dword_57E704 dd 7C8097D0h ; kernel32.TlsGetValue

bilbo 04-10-2013 01:52

In fact, the trap in your EXE is no more related to that call...

To debug the trap: run it with your preferred debugger... It will break at
Code:

004699E0  mov        byte ptr [esi],dl
where ESI is 514808

If you look at program memory map (for example through Process Hacker), you will see that memory 514000-51D000 (presumably allocated by LMCRYPT, look at memory content in the debugger) is read-only!
Hence the trap due to Access Violation.

Best regards, bilbo

bridgeic 04-10-2013 12:32

Quote:

Originally Posted by bilbo (Post 84035)
In fact, the trap in your EXE is no more related to that call...

To debug the trap: run it with your preferred debugger... It will break at
Code:

004699E0  mov        byte ptr [esi],dl
where ESI is 514808

If you look at program memory map (for example through Process Hacker), you will see that memory 514000-51D000 (presumably allocated by LMCRYPT, look at memory content in the debugger) is read-only!
Hence the trap due to Access Violation.

Best regards, bilbo

Dear bilbo,

I guess I may understand your means, test with ollydbg, if give parameters as "-i input.txt -o output.txt", then it won't run to 004699E0. Seems it will be bottleneck here. :-)


All times are GMT +8. The time now is 14:43.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX