The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
August 26, 2019, 01:24:38 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  Specialised Projects
| |-+  Compiler Based Assembler
| | |-+  Inline in VB
« previous next »
Pages: [1] 2 Print
Author Topic: Inline in VB  (Read 20256 times)
Bieb
Guest


Email
Inline in VB
« on: January 01, 2005, 05:13:26 PM »

Assuming I'm absolutely hellbent on doing it, and you're not going to be able to dissuade me or sell me an alternative, what's the easiest way to use inline assembly code in Visual Basic?
Logged
Phoenix
Guest


Email
Re: Inline in VB
« Reply #1 on: January 01, 2005, 05:56:26 PM »

Bieb,

inline assembly in VB6 was my first step to asm, and there are several ways to realize it. One of them is to store the asm-PE-file as an array of longs within the code, and then to call this with CallWindowProc-API. But there are a lot of restrictions (NO .data-segment i.e.) that make this way not the best one. I have a good doc that explaines how to do it, but it is in german language. If you are interestet, mail me and i'll send it to you.

For me, i think it is much better and a lot more flexible to code the things you want in a DLL and use it like every other dll in VB.

Regards, Phoenix
Logged
Bieb
Guest


Email
Re: Inline in VB
« Reply #2 on: January 01, 2005, 07:31:11 PM »

Well, I'm just starting to learn German, but I'll take a look at this document, as long as it uses normal VB code.  Thanks.  Now, if I create a Win32 executable and store it in memory as an array, can I just call the first part of the array, or will I have to target specific locations within the file?  Could there be some way to get VB's CALL statement to work with an array of longs?
Logged
Phoenix
Guest


Email
Re: Inline in VB
« Reply #3 on: January 01, 2005, 08:32:44 PM »

Now, if I create a Win32 executable and store it in memory as an array, can I just call the first part of the array, or will I have to target specific locations within the file?  Could there be some way to get VB's CALL statement to work with an array of longs?

Bieb,

here is the link for the tutorial, on page 5 you can get this as word document (I'm sorry, cant find it on my machine because of new installation redface).

http://www.activevb.de/tutorials/tut_asm/asm1.html

Within this tutorial you will find all explanations how to use an array of longs with CallWindowProc-API. You just pass the array as first parameter:

CallWindowProc(asm(0), Var1, Var2, Var3, Var4)

where asm() is the name of the array that holds asm-code. I don't know, but should be possible to call several procedures within the code. But i think it is easier to make different arrays.

You also need a tool to convert PE to hex array, you will find this in the tutorial, too.

However, you should think of creating a dll, this is much easier...

Logged
Bieb
Guest


Email
Re: Inline in VB
« Reply #4 on: January 01, 2005, 08:51:36 PM »

Well, the automated translation of that page wasn't a whole lot of help, but it included a link to an MSDN article that I think will give me what I need. Thanks.
Logged
Bieb
Guest


Email
Re: Inline in VB
« Reply #5 on: January 01, 2005, 09:26:14 PM »

Alright, so suppose I have the following OpCodes

Code:
50
53
8BC3
5B
58
C3

How ekactly do I go about loading them into an array and calling them?
The above code, by the way, does nothing, purposely.  I just want to test out this whole inline thing.
Logged
Robert Collins
Guest


Email
Re: Inline in VB
« Reply #6 on: January 01, 2005, 09:33:28 PM »

I got the impression from Bieb's question that he was asking for a way to include assembly code in-line within a Visual Basic program. Kind of like you can do when you include in-line assembly code within a C program. I have never seen anything that allows this per se. I remember long ago that in Basic (not Visual Basic) we could 'poke' assembly code (not the mnuemonics, but the absolute binary) into some memory location and then call the first byte of that location. Whether you can do that in VB I have no idea.
Logged
Phoenix
Guest


Email
Re: Inline in VB
« Reply #7 on: January 01, 2005, 10:16:24 PM »

Bieb,

using vb inline this should be:

Code:
Option Explicit

' asmExample
'
Function asmExample() As Long
   
    Static asm(1) As Long
   
    If asm(0) = 0 Then
        asm(0) = &H50538BC3:  asm(1) = &H5B58C3
    End If
   
    ' ************************************************************
 
    asmExample = CallWindowProc(asm(0), 0, 0, 0, 0)

End Function


I'm not quite shure about the byte order because never did this by hand. I have attached a vb-module that extracts code from PE-files and copies them to clipboard i. e. Perhaps you find it useful.  ;)



[attachment deleted by admin]
Logged
Phoenix
Guest


Email
Re: Inline in VB
« Reply #8 on: January 01, 2005, 10:21:02 PM »

forgot this:

REAL inline-assembly as in C++ is NOT possible with VB6, as Robert Collins said.
Logged
Robert Collins
Guest


Email
Re: Inline in VB
« Reply #9 on: January 01, 2005, 10:29:37 PM »

OK you guys, now you got me interested in the VB/Assembly stuff. So, what is a 'PE-file'?
Logged
MichaelW
Global Moderator
Member
*****
Gender: Male
Posts: 5161


Re: Inline in VB
« Reply #10 on: January 01, 2005, 11:24:17 PM »

Logged

eschew obfuscation
Phoenix
Guest


Email
Re: Inline in VB
« Reply #11 on: January 01, 2005, 11:56:43 PM »

OK you guys, now you got me interested in the VB/Assembly stuff. So, what is a 'PE-file'?

PE EQU Win32 Portable Executable File Format  wink

http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx

Logged
hutch--
Administrator
Member
*****
Posts: 12013


Mnemonic Driven API Grinder


Re: Inline in VB
« Reply #12 on: January 02, 2005, 12:34:10 AM »

Somewhere along the line in the dim past I remember later versions of VB used CL.EXE or one of its DLLs to generate compiled code and I think it was here that someone found a trick to plug in an object module.
Logged

Regards,



Download site for MASM32
http://www.masm32.com
Maven
Guest


Email
Re: Inline in VB
« Reply #13 on: January 02, 2005, 05:52:03 PM »

Assuming I'm absolutely hellbent on doing it, and you're not going to be able to dissuade me or sell me an alternative, what's the easiest way to use inline assembly code in Visual Basic?

I would avoid using inline asm (It's not even really inline) with visual basic like that. It's a very hacky way of doing things and I think it would be best to just write a dll. But to answer you're question, you just write a small modual in asm and then generate the machine code listing for it. Store that in a variable and call it using the windows API with a pointer to the variable.

You would put it in the variable like so: 50538BC35B58C3

Anyway that is so hacky lol
Logged
Mr. Sade
Guest


Email
Re: Inline in VB
« Reply #14 on: February 19, 2005, 09:48:44 AM »

You can use an add-in for vb6 called TweakVB, I have never use it though.
it says it can:

Statically link Assembler or C modules directly into your compiled Visual Basic executables.
Add Inline-Assembly right into your Visual Basic project for the ultimate in performance.
Generate Assembly listings of your Visual Basic code.
Use custom optimization settings on a per-module basis.
Easily call Function Pointers using just Visual Basic code. No type libraries, no DLL's or any external files.
Export functions from your Visual Basic DLLs, just like a normal DLL, with no external "shadow dlls" or the like.
Build Control Panel applets and more using only native Visual Basic code.
Increase or decrease your program's stack size.
Easily generate Map files to assist in debugging.
Much, much more!
Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!