Author Topic: Convert VC++ library to masm?  (Read 22060 times)

Redlabel

  • Guest
Re: Convert VC++ library to masm?
« Reply #15 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.
« Last Edit: May 23, 2013, 03:50:55 AM by Redlabel »

qWord

  • Member
  • *****
  • Posts: 1476
  • The base type of a type is the type itself
    • SmplMath macros
Re: Convert VC++ library to masm?
« Reply #16 on: May 23, 2013, 02:57:45 AM »
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.
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.
Code: [Select]
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

  • Guest
Re: Convert VC++ library to masm?
« Reply #17 on: May 23, 2013, 03:11:30 AM »
thanks for the help :eusa_clap: but i do not understand.
« Last Edit: May 23, 2013, 06:31:48 AM by Redlabel »

qWord

  • Member
  • *****
  • Posts: 1476
  • The base type of a type is the type itself
    • SmplMath macros
Re: Convert VC++ library to masm?
« Reply #18 on: May 23, 2013, 03:35:09 AM »
It could be something like this:
c++:
Code: [Select]
extern "C" void CalculateDigest(byte* hash_value, const byte* data, size_t length) {
    CryptoPP::MD5 hash;
    hash.CalculateDigest( hash_value, data, length);
}
MASM:
Code: [Select]
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

  • Member
  • *****
  • Posts: 2372
Re: Convert VC++ library to masm?
« Reply #19 on: May 23, 2013, 03:49:31 AM »
It's a C++ library. Not easy to extract the method names from the lib.

Redlabel

  • Guest
Re: Convert VC++ library to masm?
« Reply #20 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.
« Last Edit: May 23, 2013, 06:32:10 AM by Redlabel »

ragdog

  • Member
  • ****
  • Posts: 610
Re: Convert VC++ library to masm?
« Reply #21 on: May 23, 2013, 04:03:13 AM »
Can you post the link where I get complete crypto lib with Header files and documentation?

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Convert VC++ library to masm?
« Reply #22 on: May 23, 2013, 04:11:48 AM »
so you write a wrapper function, then import the wrapper ?
or am i missing something ?   :redface:

TouEnMasm

  • Member
  • *****
  • Posts: 1397
    • EditMasm
Re: Convert VC++ library to masm?
« Reply #23 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.
 
Fa is a musical note to play with CL

qWord

  • Member
  • *****
  • Posts: 1476
  • The base type of a type is the type itself
    • SmplMath macros
Re: Convert VC++ library to masm?
« Reply #24 on: May 23, 2013, 04:12:29 AM »
just 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

  • Guest
Re: Convert VC++ library to masm?
« Reply #25 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>
Code: [Select]
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

  • Member
  • ****
  • Posts: 610
Re: Convert VC++ library to masm?
« Reply #26 on: May 23, 2013, 05:06:01 AM »
Quote
ragdog, 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

« Last Edit: May 24, 2013, 03:17:49 AM by ragdog »

Redlabel

  • Guest
Re: Convert VC++ library to masm?
« Reply #27 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:

qWord

  • Member
  • *****
  • Posts: 1476
  • The base type of a type is the type itself
    • SmplMath macros
Re: Convert VC++ library to masm?
« Reply #28 on: May 23, 2013, 05:35:47 AM »
so 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:
Code: [Select]
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

  • Guest
Re: Convert VC++ library to masm?
« Reply #29 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

Quote
must 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