AsmDotNet64 Is a new version of masm32Ref, works on X64 platform, to deal with .net framwork, for
Masm64 and
Uasm64, We can use it with
MasmBasic, we designed it to work in an easy way.
how to use AsmDotNet64?
Initialisation:
;*************************************************************
include AsmDotNet64.inc; Necessary, (The AsmDotNet64 include file./With:Masm64Ref.Lib)
;*************************************************************
.
import Dot_Net_Assembly,Assembly_Alias
Dot_Net_Assembly : the fully qualified name of the type that we want to work on, ex: System.Windows.Forms.Form
Assembly_Alias (Optional) : The alias that we will need to shorten the assembly name
Example:
;*************************************************************
.import System.Windows.Forms.Form ,Forms
.import System.Windows.Forms.MessageBox ,MsgBox ;*************************************************************
Remarque:
- ".import Dot_Net_Assembly" This macro inserts (include) a file named Dot_Net_Assembly.inc file ex:System.Windows.Forms.Form.inc
if this file is not en the same directory, we must adjust the correct directory by using: " ClrDirectory equ <DIRECTORY> "
ex:
;*************************************************************
ClrDirectory equ <\Masm32\Include\CLR\>
ClrDirectory equ <.\CLR\>
;*************************************************************
- To get an Inc file of .net assembly use
Masm64Ref.exeDeclaration :
- Global variable: must be in .data section
.global New_Variable_Name,Dot_Net_Assembly
- Local variable:
.local New_Variable_Name,Dot_Net_Assembly
New_Variable_Name : Name of the Variable
Dot_Net_Assembly : Name of the type (or Assembly_Alias) that we want to work on.
Example:
;*************************************************************
.DATA
.global Frm01,System.Windows.Forms.Form
.global Msg1,System.Windows.Forms.MessageBox
.global Msg2,MsgBox
.CODE
MyProc PROC
LOCAL L1,L2
.LOCAL Msg__Box,MsgBox
LOCAL L3
;*************************************************************
Create new instance:
If we declare variable Var, to create new instance we must invoke "CreateInstance" method using:
.invoke Var.CreateInstance
With/Without parameter, depending on what the type contains (Constructor)
If this type contains several constructor, The "CreateInstance" would add to it a underscore with a number; CreateInstance,CreateInstance_1,CreateInstance_2,...
Example:
;*************************************************************
.import System.Windows.Forms.Form ,Forms
.DATA
.global Frm,Forms
.CODE
entry_point proc
.invoke Frm.CreateInstance
;*************************************************************
Invoke method:
we can invoke any method of an declared variable using ".invoke" macro:
.invoke Var.Method,Parameters
If this type contains several Method withe defirent parameters type, The name of Method would add to it a underscore with a number; Method,Method_1,Method_2,...
There is a difference between this version and the previous version, we can now use the masm type without having to pass it as a VARIANT
Provided that it is:
System.Boolean :Word
System.DateTime :Qword
System.Double :IEEE 64-bit floating-point number (REAL8)
System.Single :IEEE 32-bit floating-point number (REAL4)
System.UInt64 :Unsigned 64-bit integer
System.Int64 :Signed 64-bit integer
System.UInt32 :Unsigned 32-bit integer
System.Int32 :signed 32-bit integer
System.UInt16 :Unsigned 16-bit integer
System.Int16 :signed 16-bit integer
System.Byte :Unsigned 8-bit integer
System.SByte :signed 8-bit integer
System.Array :pointer to SAFEARRAY
System.Char :pointer to wchar
System.String :pointer to BSTR
System.IntPtr :Signed native integer; equivalent to the machine word size (32 bits on a 32-bit machine, 64 bits on a 64-bit machine)
System.UIntPtr :UnSigned native integer;
System.Runtime.InteropServices.ErrorWrapper :DWORD
System.Runtime.InteropServices.CurrencyWrapper :QWORD
Example:
;*************************************************************
.import System.Windows.Forms.MessageBox,tMessageBox
.import System.Windows.Forms.MessageBoxButtons
.import System.Windows.Forms.MessageBoxIcon
.import System.Windows.Forms.MessageBoxDefaultButton
.import System.Windows.Forms.MessageBoxOptions
.import System.Windows.Forms.DialogResult
.DATA
.global Msg__Box,tMessageBox
.CODE
entry_point proc
.invoke Msg__Box.Show, "Text string",\
"Caption string",\
MessageBoxButtons_YesNoCancel,\
MessageBoxIcon_Exclamation,\
MessageBoxDefaultButton_Button2,\
MessageBoxOptions_RightAlign,\
FALSE,\
addr pRetVal
.if RAX==DialogResult_Yes
.invoke Msg__Box.Show_14, " you are choise Yes",0
.endif
;*************************************************************
Get/Set Property/Field:
we can affecte a value to any property of an declared variable using ".set" macro, or get value of any property using ".get" macro:
.set Var.propertyName,NewValue
.get desitination , Var.propertyName
propertyName : Name of the Property
NewValue : Value ; The same thing as it is in Method Parameters
desitination : Pointer to Variant, or if the return value the same type as it is in Method Parameters the
value return in rax and leave the desitination blank
Example:
;*************************************************************
.DATA
txt dq 0
.CODE
.invoke vForm.CreateInstance
.set vForm.Text,"Masm64Ref Example"
.set vForm.Width,1000
.set vForm.Height,500
.get ,vForm.Text
mov txt,RAX
.invoke vForm.ShowDialog
;*************************************************************
Add/Remove an Event Handler:
we can Add an Event Handler of an declared object using ".AddHandler" macro, or remove it using ".RemoveHandler" macro:
.addhandler Var.EventName,lpFunction,handler
.removehandler Var.EventName,handler
propertyName : Name of the Event
lpFunction : Pointer to CallBack Function
handler : Pointer to Variant, to get handler (Delegate),We can use it to removehandler ;or leave it empty
Example:
;*************************************************************
.import System.Windows.Forms.Form ,tForm
.DATA
.global vForm,tForm
txt dq 0
hand__ VARIANT <>
.CODE
On_Closed PROC _sender:xWORD, _e:xWORD
RET
On_Closed ENDP
entry_point proc
.invoke vForm.CreateInstance
.AddHandler vForm.Closed,addr On_Closed,addr hand__
;.RemoveHandler vForm.Closed,addr hand__
.invoke vForm.ShowDialog
;*************************************************************