Author Topic: Masm32Ref  (Read 28676 times)

mabdelouahab

  • Member
  • ***
  • Posts: 496
Masm32Ref
« on: January 14, 2016, 09:56:41 AM »
Masm32Ref idea adapted from advanced programming languages, you can add a reference to your project and use it directly, such as Visual Studio, on the Project menu choose Add reference, I wanted to make the same thing for Assembly programmers

Masm32Ref is a free Software, is intended for Assembly programmers, to extract the .INC file to direct access to COM objects and .net object, contains everything a programmer, for use directly without adding or modifying,
This work is primary, improvement, development and auditing, but this depends on the participation of everyone, because it's free and for everyone

Masm32Ref contains open source helper files plus tools to extract reference files; it also contains a utility to inject .net code within your program
The tool contains three axes:
   •   Extract COM object
   •   Extract dot net object
   •   Injector


Extract COM object
I will explain how to use by examples, and I propose to this example, https://msdn.microsoft.com/en-us/library/office/ff838565.aspx
If the object name is "Word.Application", we will replace the point "." by "_" will become the name of the object '' Word_Application"
To get an new instance add "New_" to the name of the object with the addition of a variable either defined or not defined
   New_Word_Application   _WordApplication

Then you can call any Method or Property by adding the name of the function to the name of the object
For example:
Method "Open": Word_Documents_Open
Property " Visible " : Word_Application_Visible_Set
to set up an event proc receiver add "_On_" after the name of the object and add Event name
Event "Quit"    : Word_Application_On_Quit
Application:
First, download the tool,and the helper (copy COMHelper.inc to \Masm32\Include)
Second, after execution Choose List Registred COM TypeLibrary

Go to : Microsoft Word ?? Object Library , I have Microsoft Word 15.0 Object Library
Double Click then Choose OutPut Folder, You will get a file Word.INC
Open a new empty project , and write the following code
Quote
   include word.inc
.data
   _WordDocuments   dd   0
   _WordDocument   dd   0
.code
   ON_Application_Quit    PROC __Inst_Obj:DWORD
      invoke MessageBox,0, chr$("ON_Application_Quit"),0,0
       RET   
   ON_Application_Quit    ENDP
Start:
   New_Word_Application         _WordApplication
   Word_Application_Visible_Set   _WordApplication,TRUE
   ;Event   :   Quit
   Word_Application_On_Quit      _WordApplication,offset ON_Application_Quit
   
   Word_Application_Documents_Get    _WordApplication,addr _WordDocuments
   Word_Documents_Open         _WordDocuments,__String("d:\01.doc"),,,,,,,,,,,,,,,,addr _WordDocument
   inkey
   __Release _WordApplication
   exit
end Start

Try it

Second example:   https://msdn.microsoft.com/en-us/library/windows/desktop/aa393960%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
Microsoft WMI Scripting V1.2 Library (WbemScripting.SWbemLocator)
Quote

include WbemScripting.INC
   .data
      _ISWbemServices      dd   0
      _SWbemObjectSet      dd   0
      _ISWbemObject      dd   0
      _ISWbemPropertySet   dd   0
      _ISWbemProperty      dd   0
      _varValue            VARIANT   <>
   .code
Start:

   New_WbemScripting_SWbemLocator _SWbemLocator
   WbemScripting_SWbemLocator_ConnectServer    _SWbemLocator,BSTR$("."),BSTR$("root\cimv2"),0,0,0,0,0,0,addr _ISWbemServices
   WbemScripting_SWbemServices_ExecQuery      _ISWbemServices,BSTR$("Select * From Win32_ComputerSystem"),BSTR$("WQL"),0,0,   addr _SWbemObjectSet
   WbemScripting_SWbemObjectSet_ItemIndex       _SWbemObjectSet,0,addr _ISWbemObject
   WbemScripting_SWbemObject_Properties__Get    _ISWbemObject,addr _ISWbemPropertySet

      ;===========================================   Name
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("Name"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n Computer name   :%s"),_varValue.bstrVal
      ;===========================================   NumberOfProcessors
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("NumberOfProcessors"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n Nb Processors   :%d    "),_varValue.lVal
      ;===========================================   Workgroup
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("Workgroup"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n Workgroup   :%s   "),_varValue.bstrVal
      ;===========================================   BootupState
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("BootupState"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n BootupState   :%s   "),_varValue.bstrVal
      ;===========================================   DNSHostName
      WbemScripting_SWbemPropertySet_Item      _ISWbemPropertySet,BSTR$("DNSHostName"),0,addr _ISWbemProperty
      WbemScripting_SWbemProperty_Value_Get   _ISWbemProperty,addr _varValue
      invoke crt_wprintf,cfm$("\n DNSHostName   :%s    "),_varValue.bstrVal
   
      invoke crt_wprintf,cfm$("\n \n ")
   inkey
   exit
end Start

I am looking for everyone's participation to improve the tool
I will complete with .net later

To get the latest update Visit https://sourceforge.net/projects/masm32ref/files/
« Last Edit: February 25, 2016, 08:09:08 AM by mabdelouahab »

qWord

  • Member
  • *****
  • Posts: 1476
  • The base type of a type is the type itself
    • SmplMath macros
Re: Masm32Ref
« Reply #1 on: January 14, 2016, 11:49:49 AM »
The Word-example directly worked  :t

The file COMHelper.inc does include code/data and also references masm32rt.inc.
I would at least move the code and data into separate asm files, or better supply them via a static library.  The reference to masm32rt.inc should be completely removed IMO.
There is some redundant macro code (__New_float/double/short,....) that could be removed by using macros that define other macros (afaics).

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

guga

  • Member
  • *****
  • Posts: 1357
  • Assembly is a state of art.
    • RosAsm
Re: Masm32Ref
« Reply #2 on: January 14, 2016, 01:41:32 PM »
Not working on XP
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

  • Member
  • *****
  • Posts: 11768
  • Assembler is fun ;-)
    • MasmBasic
Re: Masm32Ref
« Reply #3 on: January 14, 2016, 04:09:41 PM »
Works great on Win7-64 :t

Here is my version :P

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  SendWordCommands      ; prepare a DDE session; Word must be running
  .if eax
      void FileRead$("http://masm32.com/board/index.php?topic=5028.0")
      Let esi=CurDir$()+"Masm32Ref.htm"
      Rename "~FrLocal.tmp", esi
      SendWordCommands Cat$('[FileOpen "'+esi+'"]')
      SendWordCommands '[MsgBox "Cute"]'
  .else
      MsgBox 0, "MS Word doesn't answer", "Sorry", MB_OK
  .endif
  SendWordCommands exit      ; finish DDE session
EndOfCode

guga

  • Member
  • *****
  • Posts: 1357
  • Assembly is a state of art.
    • RosAsm
Re: Masm32Ref
« Reply #4 on: January 14, 2016, 04:22:41 PM »
I managed to make it work after manual patching the file. The PE Section IMAGE_OPTIONAL_HEADER on the members MajorOperatingSystemVersion and MajorSubsystemVersion are marked as 6 that does not work on earlier versions of windows :(

After changing them to 4, the app runned. Btw,...i liked it a lot ! I wonder if you could make it also export RosAsm version of this macros too ;)
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

mabdelouahab

  • Member
  • ***
  • Posts: 496
Re: Masm32Ref
« Reply #5 on: January 14, 2016, 04:24:59 PM »
Hello qWord,guga,jj2007
We will discuss a lot
But let me complete the examples and then I will come back
Extract dot net object
 after execution Choose List Registred .net Assembly
for example just, select System.Windows.Forms
Double Click then Choose OutPut Folder, You will get a file "System.Windows.Forms.INC"
Open a new empty project , and write the following code
Quote

include System.Windows.Forms.inc
.code
   On_Click   PROC _sender:VARIANT, _e:DWORD
      LOCAL vt_e:VARIANT
      mov vt_e.vt,VT_DISPATCH;  VT_UNKNOWN
      m2m vt_e.punkVal,_e
         invoke MessageBox,0,BSTR$("On_Click"),0,0
      RET
   On_Click   ENDP

start:

   invoke __InitCLR
   .if eax
      New_System_Windows_Forms_Form             Form1
         System_Windows_Forms_Form_Text_Set      Form1,__String("My First Form")
         System_Windows_Forms_Button_SetBounds    Form1,__Integer(640),__Integer(480),__Integer(640),__Integer(480)
      
      New_System_Windows_Forms_Button            Button1
         System_Windows_Forms_Button_Text_Set    Button1,__String("My First Button")
         System_Windows_Forms_Button_SetBounds    Button1,__Integer(100),__Integer(100),__Integer(160),__Integer(60)

         System_Windows_Forms_Button_On_Click       Button1,offset On_Click
   
      __New_Null Controls
      System_Windows_Forms_Control_Controls_Get   Form1,Controls
      System_Windows_Forms_Control_ControlCollection_Add Controls, Button1
   
      System_Windows_Forms_Form_ShowDialog       Form1,0
      invoke __ReleaseClr
   .endif
   exit
end start
« Last Edit: January 14, 2016, 10:23:08 PM by mabdelouahab »

mabdelouahab

  • Member
  • ***
  • Posts: 496
Re: Masm32Ref
« Reply #6 on: January 14, 2016, 04:29:56 PM »
Copy DotNetHelper.inc to \Masm32\include
« Last Edit: January 14, 2016, 07:23:55 PM by mabdelouahab »

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: Masm32Ref
« Reply #7 on: January 14, 2016, 06:34:13 PM »

Help possible with the source code of Masm32Ref.exe
Fa is a musical note to play with CL

mabdelouahab

  • Member
  • ***
  • Posts: 496
Re: Masm32Ref
« Reply #8 on: January 14, 2016, 07:17:58 PM »
Injector
Injector is a tool to help you insert the .net code within your program directly
after execut masm32Ref Choose Injector
Copy this Code example:
Code: [Select]
Public Class MyClass1
    Public Function MyFirstFunc(s As String) As System.Windows.Forms.DialogResult
        Return System.Windows.Forms.MessageBox.Show("Masm32 Injector:"+s, "Masm32Ref")
    End Function
    Public Shared Function MySecFunc(s As String) As System.Windows.Forms.DialogResult
        Return System.Windows.Forms.MessageBox.Show("Masm32 Injector:"+s, "Masm32Ref")
    End Function
End Class
click "Add Ref" and select System.Windows.Forms.dll
click "Generat Inc File" ,type the assembly name "MyAssembly",Choose OutPut Folder, You will get a file "MyAssembly.INC"
Open a new empty project , and write the following code
Quote
include MyAssembly.inc

start:

   invoke __InitCLR
   .if eax
      __New_Empty   _msgRet
      ;Static function
      MyClass1_MySecFunc __String("Hello"),_msgRet

      New_MyClass1    _cls1
      MyClass1_MyFirstFunc _cls1,__String("Hello"),_msgRet
      invoke __ReleaseClr
   .endif

   inkey
   exit
end start

TWell

  • Member
  • ****
  • Posts: 748
Re: Masm32Ref
« Reply #9 on: January 14, 2016, 07:38:13 PM »
Statusline is too narrow in Windows 10

mabdelouahab

  • Member
  • ***
  • Posts: 496
Re: Masm32Ref
« Reply #10 on: January 14, 2016, 10:59:12 PM »
The Word-example directly worked  :t

The file COMHelper.inc does include code/data and also references masm32rt.inc.
I would at least move the code and data into separate asm files, or better supply them via a static library.  The reference to masm32rt.inc should be completely removed IMO.
There is some redundant macro code (__New_float/double/short,....) that could be removed by using macros that define other macros (afaics).

regards

Thank you qWord Good observation, I've removed  masm32rt.inc. I've added what I need only

mabdelouahab

  • Member
  • ***
  • Posts: 496
Re: Masm32Ref
« Reply #11 on: January 14, 2016, 11:21:26 PM »
Statusline is too narrow in Windows 10

Thank you TWell   I reset to default font, If you have experience in colors and fonts please suggest us



HSE

  • Member
  • *****
  • Posts: 1815
  • AMD 7-32 / i3 10-64
Re: Masm32Ref
« Reply #12 on: February 23, 2016, 06:50:37 AM »
Apparently it's posible download only one com object by session, second time nothing happen.

mabdelouahab

  • Member
  • ***
  • Posts: 496
Re: Masm32Ref
« Reply #13 on: February 25, 2016, 08:07:01 AM »
Thank you HSE  :t, You can download the latest update,You must download the files: Masm32Ref.lib and Masm32Ref.inc, Also you can download Masm32RefMacro.INC, I took the tip of qWord to make the tool work well with Masm ,jwasm,hjwasm,and rosasm, I've put COMHelper.INC and DotNetHelper.INC inside static lib and dynamic link lib

All that is >>> here <<<

You can enjoy with .net object and COM object

HSE

  • Member
  • *****
  • Posts: 1815
  • AMD 7-32 / i3 10-64
Re: Masm32Ref
« Reply #14 on: February 25, 2016, 10:46:32 AM »
Perfect now :t