The MASM Forum

Projects => MASM32 => Topic started by: Redlabel on May 22, 2013, 06:13:31 AM

Title: Convert VC++ library to masm?
Post by: Redlabel on May 22, 2013, 06:13:31 AM
Hee folks

got a simple and short question

is it possible to use a ms vc++ 2010 .library file in winasm masm?
i got only the *.lib file generated by vc++ 2010.

just using the "uselib" macro won't work because of some missing *.obj files error or something, dont know because i dont have object files, just a *.lib.
Title: Re: Convert VC++ library to masm?
Post by: jj2007 on May 22, 2013, 07:06:15 AM
The uselib macro requires two files:

include \masm32\include\*.inc
includelib \masm32\lib\*.lib

Do you have an inc file, too? Is it located in the right folder?

The best solution to get help would be to zip the library and include files together with a hello world example. You are not giving much information...
Title: Re: Convert VC++ library to masm?
Post by: dedndave on May 22, 2013, 08:04:42 AM
i would imagine you are missing a proper masm-syntax include file
masm does not understand C .h includes

which LIB are you trying to use ?
there may already be a masm INC file made for it, someplace
Title: Re: Convert VC++ library to masm?
Post by: hutch-- on May 22, 2013, 01:57:19 PM
It depends on what the libraries are, if they are C++ libraries you will have problems with the name mangling where if they are plain C libraries, they can be used if you create a set of prototypes for it in MASM format. What you will normally find is if you use the C runtime libraries you pick up most of their overhead as well and there will be little if any gain by building the app in MASM. Alternately you can routinely use separate C object modules if you prototype them correctly and use the right calling convention for them.
Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 22, 2013, 04:09:59 PM
thanks for the reply's guys.

i dont have a inc file. also i think it is a plain c++ library.

im trying to include the latest Crypto++ library.
Title: Re: Convert VC++ library to masm?
Post by: TouEnMasm on May 22, 2013, 07:21:16 PM

use this to have the include file:
http://masm32.com/board/index.php?topic=576.0 (http://masm32.com/board/index.php?topic=576.0)
Just take care that a c++ library use a defaut prototype  PROTO C.
You can have need to change "PROTO" to "PROTO C".
You can also find decorated functions names,use it on the translated header if it is the case.

Title: Re: Convert VC++ library to masm?
Post by: ragdog on May 22, 2013, 08:39:01 PM
It very work to convert the header *.h to include
I use tools for it h2incx or a translator from ToutEnMasm

and the rest of the converted Include make it per hand


need you more help post this crypto lib
or tell us what you need for a crypto many cryptos give allready masm includes
Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 12:26:26 AM
i do not understand.

i do not need inc files, i just want to use this library into masm

i uploaded the library here

http://rghost.net/46180829
Title: Re: Convert VC++ library to masm?
Post by: dedndave on May 23, 2013, 12:58:05 AM
true - you don't NEED inc files
but, it is the easiest way to prototype the functions in the lib
one of the guys may make an inc file for you
if not, i may do it, later
Erol (Vortex) has several nice tools for doing this automatically

http://vortex.masmcode.com/ (http://vortex.masmcode.com/)

Andreas (Japheth) also has a tool called h2incX

http://www.japheth.de/h2incX.html (http://www.japheth.de/h2incX.html)

it was designed for C, not C++, but it's worth a shot
Title: Re: Convert VC++ library to masm?
Post by: dedndave on May 23, 2013, 01:10:11 AM
by the way,
it would simplify creation of the inc file if you knew you were only using a few functions from the lib
you only need to prototype and typedef the symbols you are going to use

also, there are crypto routines written in masm
you may find that they are faster - and easier to use in a masm program   :biggrin:
Title: Re: Convert VC++ library to masm?
Post by: dedndave on May 23, 2013, 01:16:47 AM
here is a quicky inc file
i used Erol's lib2def and def2inc
it only defines the prototypes for functions
not sure how well it will work, but you can give it a try


in your asm source
        INCLUDE    cryptlib.inc
        INCLUDELIB cryptlib.lib
Title: Re: Convert VC++ library to masm?
Post by: TouEnMasm on May 23, 2013, 01:59:11 AM

There is something wrong,
dumpbin find 2925 functions exported by the dll
Title: Re: Convert VC++ library to masm?
Post by: dedndave on May 23, 2013, 02:11:58 AM
probably a problem with dumpbin   :biggrin:
i doubt it is set up to handle C++

and, i doubt the crypto library has that many functions - lol
you can find cryptlib.h online - it wouldn't be that hard to create an inc file by hand - it's pretty small
Title: Re: Convert VC++ library to masm?
Post by: qWord on May 23, 2013, 02:24:18 AM
Quote from: dedndave on May 23, 2013, 02:11:58 AMand, i doubt the crypto library has that many functions
yes, instead it has several thousand methods: http://www.cryptopp.com/docs/ref/annotated.html
Title: Re: Convert VC++ library to masm?
Post by: TouEnMasm on May 23, 2013, 02:46:59 AM
Quote
probably a problem with dumpbin   
i doubt it is set up to handle C++
Of course it is the dumpbin of the c++,not the masm32 one.
Perhaps a use of the wincrypt (.h .sdk) will be more simple.
Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 02:49:02 AM
gracias dendedave and others!

i used the uselib to include the inc file dendedave made and included the library itself, now while compiling it will give serveral errrors, listed below.

and indeed i just need a few functions of it, maybe only 6-8.
Title: Re: Convert VC++ library to masm?
Post by: qWord on May 23, 2013, 02:57:45 AM
Quote from: Redlabel on May 23, 2013, 02:49:02 AMi used the uselib to include the inc file dendedave made and included the library itself, now while compiling it will give serveral errrors, listed below.
forget that include file- its simply wrong.

What you need to do, is to write functions (extern "C") in the c++ source, which interacts with the needed objects. For calling these function, you need to define the prototypes in MASM:
e.g. foo PROC C param1:ptr CHAR,param2:SDWORD  ; extern "C" int foo(char* param1, int param2)
Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 03:11:30 AM
thanks for the help :eusa_clap: but i do not understand.
Title: Re: Convert VC++ library to masm?
Post by: qWord on May 23, 2013, 03:35:09 AM
It could be something like this:
c++:
extern "C" void CalculateDigest(byte* hash_value, const byte* data, size_t length) {
    CryptoPP::MD5 hash;
    hash.CalculateDigest( hash_value, data, length);
}

MASM:
MD5 struct
    bytes BYTE 16 dup (?)
MD5 ends
CalculateDigest proto C hash_value: ptr MD5,data:ptr BYTE, _length:DWORD

...
.data?
    md5 MD5 <>
.data
    foo BYTE "123456789"
.code
...
invoke CalculateDigest,ADDR md5,ADDR foo,SIZEOF foo
Title: Re: Convert VC++ library to masm?
Post by: Vortex on May 23, 2013, 03:49:31 AM
It's a C++ library. Not easy to extract the method names from the lib.
Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 03:50:35 AM
gracias qword!

just 1 problem i got an error while i include the library: LINK : fatal error LNK1196: invalid or corrupt import object: unknown version.
when i remove the includelib cryptlib.lib then the error is gone, but ofcourse the functions of this lib too.
Title: Re: Convert VC++ library to masm?
Post by: ragdog on May 23, 2013, 04:03:13 AM
Can you post the link where I get complete crypto lib with Header files and documentation?
Title: Re: Convert VC++ library to masm?
Post by: dedndave on May 23, 2013, 04:11:48 AM
so you write a wrapper function, then import the wrapper ?
or am i missing something ?   :redface:
Title: Re: Convert VC++ library to masm?
Post by: TouEnMasm on May 23, 2013, 04:12:12 AM
You can also use a dynamic link.
Here a test to see which functions are usable with getprocadress.
Put it on the same directory.
Open a dos windows use the > to have a full list of functions usable.
Title: Re: Convert VC++ library to masm?
Post by: qWord on May 23, 2013, 04:12:29 AM
Quote from: Redlabel on May 23, 2013, 03:50:35 AMjust 1 problem i got an error while i include the library: LINK : fatal error LNK1196: invalid or corrupt import object: unknown version.
You maybe try to replace ( with backup ;-) ) ML.exe and LINK.exe in MASM32's bin folder with the one from your Visual studio installation. If I'm not wrong, you also need to copy: msobj100.dll, mspdb100.dll, mspdbcore.dll, mspdbsrv.exe. (search in the Visual Studio installation directories for this files).
Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 04:46:58 AM
ragdog, there is no dll or lib extension in the offical download, anyway i posted the generated lib by vc++ a few post earlier and here is the offical download to crypto++ library with headers>http://www.cryptopp.com/#download

ToutEnMasm, thank you. it found 2272 good ones and 660 bad ones.

qword, after replacing the vs++ files you metioned it still says the same error.

maybe this is too hard and i should use vc++ then instead of masm  :eusa_boohoo:
Title: Re: Convert VC++ library to masm?
Post by: ragdog on May 23, 2013, 05:06:01 AM
Quoteragdog, there is no dll or lib extension in the offical download, anyway i posted the generated lib by vc++ a few post earlier

Yes i know

i use this setting to make a lib from a C source

copy mirdef.h32 mirdef.h
cl /c /O2 /W3 mrcore.c
cl /c /O2 /W3 mrflsh4.c
..
..
.

lib /OUT:miracl.lib mrflsh4.obj mrcore.obj ...  .

Or you include the obj file to your project

Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 05:18:27 AM
omg nice work dude  :greenclp:

no i do not include any obj.

i do not have the time and patient do did what you did
so i guess i should stick with vc++.

Anyway thanx for all the great help here at this forum!  :greenclp: :t :icon14: :eusa_clap:
Title: Re: Convert VC++ library to masm?
Post by: qWord on May 23, 2013, 05:35:47 AM
Quote from: Redlabel on May 23, 2013, 05:18:27 AMso i guess i should stick with vc++.
I've test it as descripted above and it does work: It is important that you replace \masm32\bin\LINK.exe with the one from ...\VC\bin\. Also you must add the /LIBPATH:"C:\...\VC\Lib" to the linker command line.
For the following code I get a running EXE - see attachment:
include \masm32\include\masm32rt.inc
includelib C:\<...>\crypt\Win32\Output\Release\cryptlib.lib

MD5 struct
    data DWORD 4 dup (?)
MD5 ends
CalculateDigest proto C hash_value: ptr MD5,data:ptr BYTE, _length:DWORD

.data?
    md5 MD5 <>
.data
    foo BYTE "123456789"
.code

.code
main proc C

    invoke CalculateDigest,ADDR md5,ADDR foo,SIZEOF foo
    print "MD5(<123456789>) = 0x"
    print hex$(DWORD ptr md5.data[3*4])
    print hex$(DWORD ptr md5.data[2*4])
    print hex$(DWORD ptr md5.data[1*4])
    print hex$(DWORD ptr md5.data[0*4]),13,10
   
    inkey
    exit
main endp
end main

Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 06:31:20 AM
dammmnn! you guys are rocking!  :greenclp: :greenclp:

nice work qword, now i can compile without any error!

just 1 thing; i dont know what you mean by this

Quotemust add the /LIBPATH:"C:\...\VC\Lib" to the linker command line

i guess i should open winasm studio>project>properties>release>command line? (my exe is a release version, not a debug).

so when i did this and added the directory to hte VC libs (  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib  )
i got this error: error LNK2019: unresolved external symbol _CalculateDigest referenced in function _doHash@0

this is my project

(http://i40.tinypic.com/2duviw.png)
Title: Re: Convert VC++ library to masm?
Post by: qWord on May 23, 2013, 06:42:24 AM
Quote from: Redlabel on May 23, 2013, 06:31:20 AMi guess i should open winasm studio>project>properties>release>command line?
yes, you must add that option. Because the path contains spaces, it should be enclosed in double quotes:
/LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib"

I hope you also had add the function to your library build. For that purpose I have add a new module (named C_interface.cpp) to the library:
#include "pch.h"
#include "md5.h"

extern "C" void CalculateDigest(byte* hash_value, const byte* data, size_t length) {
    CryptoPP::MD5 hash;
    hash.CalculateDigest( hash_value, data, length);
}
Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 06:57:29 AM
....
Title: Re: Convert VC++ library to masm?
Post by: qWord on May 23, 2013, 07:03:27 AM
Redlabel,
The shown c++ file must be add to the project that is used to build the cryptlib (In other word: you must extend the crypto library by the adding the function CalculateDigest()).
Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 07:23:18 AM
...
Title: Re: Convert VC++ library to masm?
Post by: qWord on May 23, 2013, 07:42:35 AM
You just need to add the file to the project (I'm talking about the c++-library!): for Visual Studio this could be: Project->Add Item->new c++ source.

BTW: It seems like that the whole topic is beyond your limits.
Title: Re: Convert VC++ library to masm?
Post by: Redlabel on May 23, 2013, 04:18:51 PM
....
Title: Re: Convert VC++ library to masm?
Post by: hutch-- on June 09, 2013, 05:04:18 PM
Redlabel,

Make a point of NOT deleting post contents, other members have responded and your deletions render their posts unintelligible.
Title: Re: Convert VC++ library to masm?
Post by: jj2007 on June 09, 2013, 07:51:43 PM
Quote from: hutch-- on June 09, 2013, 05:04:18 PM
Make a point of NOT deleting post contents, other members have responded and your deletions render their posts unintelligible.

This habit is indeed extremely anti-social. I wonder whether one can block post edits for members below a certain post count; allowing as usual, one hour to correct typos etc.
Title: Re: Convert VC++ library to masm?
Post by: Dubby on June 09, 2013, 09:16:36 PM
just a question "Why?"..

never fell embarrassed of making mistakes in learning process.. my first source code was full of garbage, if I made mistake I don't delete them just comment them out and put a notice "this is mistakes.." and after the source finished I retype the right source in the new document, side by side with the old and possibly optimize it ... that way I can learn from my mistakes... and try to stay away from it..

Hutch, if I remember correctly in the old forum you have a notice about not deleting post, right? what about making it as a rule or a notice..?
Title: Re: Convert VC++ library to masm?
Post by: Gunther on June 09, 2013, 10:01:33 PM

Quote from: jj2007 on June 09, 2013, 07:51:43 PM
This habit is indeed extremely anti-social. I wonder whether one can block post edits for members below a certain post count; allowing as usual, one hour to correct typos etc.

Yes, indeed and very unfair.

Quote from: Dubby on June 09, 2013, 09:16:36 PM
Hutch, if I remember correctly in the old forum you have a notice about not deleting post, right? what about making it as a rule or a notice..?

That's a good proposal. We should think about it.

Gunther