News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Convert VC++ library to masm?

Started by Redlabel, May 22, 2013, 06:13:31 AM

Previous topic - Next topic

Redlabel

#15
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.

qWord

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)
MREAL macros - when you need floating point arithmetic while assembling!

Redlabel

#17
thanks for the help :eusa_clap: but i do not understand.

qWord

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
MREAL macros - when you need floating point arithmetic while assembling!

Vortex

It's a C++ library. Not easy to extract the method names from the lib.

Redlabel

#20
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.

ragdog

Can you post the link where I get complete crypto lib with Header files and documentation?

dedndave

so you write a wrapper function, then import the wrapper ?
or am i missing something ?   :redface:

TouEnMasm

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.
Fa is a musical note to play with CL

qWord

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).
MREAL macros - when you need floating point arithmetic while assembling!

Redlabel

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:

ragdog

#26
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


Redlabel

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:

qWord

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

MREAL macros - when you need floating point arithmetic while assembling!

Redlabel

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