Author Topic: EasyCode with NASM/YASM  (Read 21338 times)

David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #15 on: July 15, 2014, 03:41:17 AM »
Hi David,

I hope that link will help you.

Gunther

Hmmm.....  I'll check it now.  Thank you Gunther!
 :biggrin:

rsala

  • Moderator
  • Member
  • *****
  • Posts: 273
    • Easy Code
Re: EasyCode with NASM/YASM
« Reply #16 on: July 15, 2014, 04:39:04 AM »
Hi David,

I'd really like to help you but I have no idea how Yasm works. I am sorry!

Ramon
EC coder

David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #17 on: July 15, 2014, 04:57:03 AM »
Hi David,
I'd really like to help you but I have no idea how Yasm works. I am sorry!
Ramon


No problem at all Ramon.
I had really appreciated your efforts in help me.
And go on enhancing EasyCode. It's a great software, it saves a lot of time of programmers specially in build MAKE files and macros.
Kindest regards.

rsala

  • Moderator
  • Member
  • *****
  • Posts: 273
    • Easy Code
Re: EasyCode with NASM/YASM
« Reply #18 on: July 15, 2014, 08:25:44 AM »
Thanks once again for your kind words! I really appreciate your support!

Ramon
EC coder

David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #19 on: July 15, 2014, 09:31:22 AM »
Ramon,

Do you know how can start a classic DLL file but using x64 code?
I'll try the MASM classic DLL file calling the INTEL LIB file...
But I'm not sure if the include files can be those EasyCode put automatically to me when I start a new DLL project.
Could you light my way?

Thanks in advance.


Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: EasyCode with NASM/YASM
« Reply #20 on: July 15, 2014, 09:46:47 AM »
Hi David,

what about that: YASM will produce an OBJ file for you. The rest is a linker question. You could use GOLINK, which can produce DLL files:
Quote

GoLink.Exe Version 0.27.0.0 - Copyright Jeremy Gordon 2002/12 - JG@JGnet.co.uk

Use one or more command files eg. GoLink @command.fil and/or the command line.
Specify obj,res,dll,ocx,exe or drv input files and/or these switches:-
/base xxxx   = set image base (use hex)
/console     = make console executable (otherwise Windows GUI)
/debug xxx   = coff = embedded coff, dbg = dbg file in subfolder
/dll         = make a dll (otherwise exe)
/e           = empty output file allowed
/entry xxxx  = set program entry point to xxxx
/export xxxx = allow this label to be called from another module
/files       = give full information about input and output files
/fo xxxx     = file output eg. /fo prog.exe, prog.dll or off (no file)
              if no output file is specified, 1st .obj/.res file name is used
/h or /?     = this help
/mix         = link mixed object files or lib code having decorated symbols
/unused      = list unused/unreferenced data and code labels
/uponly      = file is not designed to run on multi-processor machines
/version xxxx= set image version to major minor value
Make a driver using /driver (PE driver) or /wdm (Windows Driver Model driver)
Control stack allocation and commitment using /stacksize and /stackinit
Control message output with /b, /more, /ne, /ni, /no, /nw (see manual)
To make Microsoft Layer for Unicode loader, see manual

Another possibility is POLINK:
Quote

Pelles Linker, Version 7.00.3
Copyright (c) Pelle Orinius 1998-2012

Syntax:
POLINK [ { option | file | @commandfile } ... ]

Options:
/ALIGN:#
/ALLOWBIND[:NO]
/ALLOWISOLATION[:NO]
/ALTERNATENAME:symbol=symbol
/BASE:address
/DEBUG[:NO]
/DEBUGTYPE:{CV|COFF|BOTH}
/DEF:filename
/DEFAULTLIB:filename
/DELAY:{NOBIND|UNLOAD}
/DELAYLOAD:filename
/DLL
/DRIVER[:{UPONLY|WDM}]
/ENTRY:symbol
/EXPORT:symbol[=[module.]symbol][,@ordinal[,NONAME]][,DATA]
/FIXED[:NO]
/FORCE:MULTIPLE
/HEAP:reserve[,commit]
/IMPLIB:filename
/INCLUDE:symbol
/LARGEADDRESSAWARE[:NO]
/LIBPATH:path
/MACHINE:{AMD64|ARM|X64|X86}
/MANIFEST[:NO]
/MANIFESTDEPENDENCY:dependency
/MANIFESTFILE:filename
/MANIFESTUAC[:{NO|execution level}]
/MAP[:filename]
/MAPINFO:{EXPORTS|FIXUPS|LINES|PATHS}
/MERGE:from=to
/NODEFAULTLIB
/NOENTRY
/NXCOMPAT[:NO]
/OPT:{REF|NOREF|WIN98|NOWIN98}
/OSVERSION:#[.##]
/OUT:filename
/RELEASE
/SAFESEH[:NO]
/SECTION:name,[E][R][W][D][K][P]
/STACK:reserve[,commit]
/STUB:filename
/SUBSYSTEM:{CONSOLE|NATIVE|WINDOWS|WINDOWSCE}[,#[.##]]
/SWAPRUN:{CD|NET}
/TSAWARE[:NO]
/VERBOSE
/VERSION:#[.##]
/WS:AGGRESSIVE


HTH,
Gunther
Get your facts first, and then you can distort them.

David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #21 on: July 15, 2014, 10:17:27 AM »
Hi David,

what about that: YASM will produce an OBJ file for you. The rest is a linker question. You could use GOLINK, which can produce DLL files:
HTH,
Gunther

Thank you so much Gunther, but my problem is related to the source file (I'm sending it again).
The file is created 100% but when I try to call it from a x64 Visual Basic application the system hangs.  :icon_redface:
I'm going to be crazy!

The MAIN problem is the fact of the INTEL source code is NOT prepared to be a DLL but a LIB file, and I don't want to get a C++ file ONLY to access it! I'm trying to make it as a DLL and call it directly from Visual Basic.

I had modified the INTEL code adding a DLLEntry procedure as mentioned in NASM manual. Remember: the source code was made to be a LIB of a C/C++ CONSOLE APP.

I compile it successfully using:
vsyasm -f x64 -D WINABI sha512_sse4.asm

I link it successfully using MS LINK and that commandline:
link /entry:DllMain /MACHINE:X64 /NODEFAULTLIB /def:hash.def /DLL /export:sha512_sse4 /subsystem:windows sha512_sse4.obj /out:"hash.dll"

I get the DLL file withou any error from VSYASM and LINK.EXE!  But when I try to call it from Visual Basic the system hangs. I tried two ways to call it, both UNSUCCESSFULLY:

1) To create a STRUCTURE inside VB and call the function via DECLARE (exactly what I done to call CPUID successfully) as shown below:
   
Public Structure GetSHA
        Dim OriginalMsg As String
        Dim SHA_Returned As String
        Dim MsgLen As IntPtr
End Structure

Declare Sub sha512_sse4 Lib "hash.dll" (ByRef sMensagem As String, ByRef ssha As String, ByVal stamanhomensagem As IntPtr)

Public MyRetorno As GetSHA
sha512_sse4(MyRetorno)


2) To create the variables without a structure and point them directly in the function:

Declare Sub sha512_sse4 Lib "hash.dll" (ByRef Message As String, ByRef ReturnedSHA As String, ByVal MsgSize As IntPtr)

 Dim Msg As String = "system test"
 Dim NewMsg As String = Msg.PadRight(64)
 Dim NewMsgLen As UInteger = newMsg.Length

 Dim returned As String = ""
 sha512_sse4(newMsg, returned, NewMsgLen)



WOW!!!  Why INTEL had choosen THIS way to do the things?!?!?  It seems a bad joke with MS programmers....

And I really had appreciated THE WHOLE TEAM efforts to help me. I apologize for any inconvenience but here in Brazil is really too hard to find ANYONE with some ASM knowledge to ask my questions.

Thank you very much for any help.
Kindest regards Gunther and all the guys involved with my questions.


David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #22 on: July 15, 2014, 10:32:28 AM »
Ops!  The step (1) is really:

Public Structure GetSHA
        Dim OriginalMsg As String
        Dim SHA_Returned As String
        Dim MsgLen As IntPtr
End Structure

Declare Sub sha512_sse4 Lib "hash.dll" (ByRef Struc as GetSHA)


1) To create a STRUCTURE inside VB and call the function via DECLARE (exactly what I done to call CPUID successfully) as shown below:
   
Public Structure GetSHA
        Dim OriginalMsg As String
        Dim SHA_Returned As String
        Dim MsgLen As IntPtr
End Structure

Declare Sub sha512_sse4 Lib "hash.dll" (ByRef sMensagem As String, ByRef ssha As String, ByVal stamanhomensagem As IntPtr)

Public MyRetorno As GetSHA
sha512_sse4(MyRetorno)


Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: EasyCode with NASM/YASM
« Reply #23 on: July 15, 2014, 11:31:19 AM »
David,

okay I'll check the source tomorrow.

Gunther
Get your facts first, and then you can distort them.

David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #24 on: July 15, 2014, 11:34:47 AM »

David,
okay I'll check the source tomorrow.
Gunther

Thanks a lot Gunther!  :t

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: EasyCode with NASM/YASM
« Reply #25 on: July 15, 2014, 11:46:07 AM »
Hi Dave,

would it help to have the YASM source in - let me say - near masm syntax? I've it in Intel syntax and can post it.

Gunther
Get your facts first, and then you can distort them.

David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #26 on: July 15, 2014, 12:48:48 PM »
Hi Dave,

would it help to have the YASM source in - let me say - near masm syntax? I've it in Intel syntax and can post it.

Gunther

Yes, I believe so...
I'm trying now call ASM code from VB utilizing MARSHAL functions (it pass addresses instead values), but I'm getting error all the time.
I believe the main problem is the fact of the ASM source receive parameters in YASM syntax (directly from stack??) and all of them are VOID type, which is a little bit confuse to set in VB.
But in the point I'm now, any help is valuable.   ;)

Again, thanks a lot and excuse me for any inconvenience.

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: EasyCode with NASM/YASM
« Reply #27 on: July 15, 2014, 08:42:52 PM »
Hi Dave,

I've attached a ZIP archive. It's generated by OBJDUMP and contains both, the machine code and the appropriate assembly language instructions in MASM syntax. I hope that helps. The only thing to do is to copy and paste the instructions into a MASM source code with proc and endp statements. NASM and YASM don't have such statements. For both is a procedure just a label. So here is an example. If the yasm syntax looks like:
Code: [Select]
MyProcedure:
        push        rbx
        ...
        ret
you have to write for ml or jWasm:
Code: [Select]
MyProcedure    proc
        push        rbx
        ...
        ret
MyProcedure    endp
The rest is copy and paste, because you've the original YASM source.

I think Intel did it that way, because YASM is available on both platforms (Windows and Linux) producing appropriate output. The Microsoft Assembler runs only under Windows. That might be the reason.

Gunther
Get your facts first, and then you can distort them.

David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #28 on: July 15, 2014, 10:25:20 PM »
Thank you very much Gunther.
I'll try what you recommend still today, as soon as possible.
My job requires my attention right now, but I guess until the middle of day I could try it.

Kindest regards.

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: EasyCode with NASM/YASM
« Reply #29 on: July 16, 2014, 12:00:15 AM »
Hi David,

Thank you very much Gunther.
I'll try what you recommend still today, as soon as possible.
My job requires my attention right now, but I guess until the middle of day I could try it.

you're welcome. If you need some more assistance by converting the code, let me know. I'm at home in both worlds, YASM and MASM.

Gunther
Get your facts first, and then you can distort them.