Author Topic: MasmBasic  (Read 168877 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8002
  • Assembler is fun ;-)
    • MasmBasic
HexDump$
« Reply #420 on: September 18, 2017, 11:18:07 PM »
Install the MasmBasic update 18 September 2017 to get this new feature inspired by the How to read Windows MFT thread:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Inkey "Dump of GetModuleHandle(0):", CrLf$, HexDump$(rv(GetModuleHandle, 0), 90h)
EndOfCode


Options are documented in MbGuide.rtf, as usual.

The other major change is that RichMasm got new menus (more), thanks to LiaoMi :icon14:

Tested on WinXP, Win7-64 (also with Aero, see screenshot below) and Win10, looks OK so far, but let me know if it can be improved :icon_mrgreen:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8002
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #421 on: October 27, 2017, 01:13:11 AM »
Changes in version 26 October:
- online help is updated, e.g. for deb & friends (remember that in RichMasm, hovering over a keyword allows to access help with a right-click)
- see Graphics demo; handling of maps is strongly improved
- HexDump$() got a "dd" option:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Let esi=FileRead$("\Masm32\examples\exampl04\car\car.jpg")    ; Masm32 SDK
  PrintLine HexDump$(esi, 80)   ; show 80 bytes of jpg header
  Inkey HexDump$(esi, 80, dd)   ; same but for use with code
EndOfCode


Output:
Code: [Select]
006337D0  FF D8 FF E0 00 10 4A 46 49 46 00 01 00 01 00 64 ÿØÿà..JFIF.....d
006337E0  00 64 00 00 FF FE 00 1F 4C 45 41 44 20 54 65 63 .d..ÿþ..LEAD Tec
006337F0  68 6E 6F 6C 6F 67 69 65 73 20 49 6E 63 2E 20 56 hnologies Inc. V
00633800  31 2E 30 31 00 FF DB 00 84 00 08 05 06 07 06 05 1.01.ÿÛ.„.......
00633810  08 07 06 07 09 08 08 09 0C 14 0D 0C 0B 0B 0C 19 ................

db  0FFh, 0D8h, 0FFh, 0E0h, 000h, 010h, 04Ah, 046h, 049h, 046h, 000h, 001h, 000h, 001h, 000h, 064h
db  000h, 064h, 000h, 000h, 0FFh, 0FEh, 000h, 01Fh, 04Ch, 045h, 041h, 044h, 020h, 054h, 065h, 063h
db  068h, 06Eh, 06Fh, 06Ch, 06Fh, 067h, 069h, 065h, 073h, 020h, 049h, 06Eh, 063h, 02Eh, 020h, 056h
db  031h, 02Eh, 030h, 031h, 000h, 0FFh, 0DBh, 000h, 084h, 000h, 008h, 005h, 006h, 007h, 006h, 005h
db  008h, 007h, 006h, 007h, 009h, 008h, 008h, 009h, 00Ch, 014h, 00Dh, 00Ch, 00Bh, 00Bh, 00Ch, 019h

- the new MasmBasic version is again compatible with UAsm
- a bug in RichMasm was fixed (if a very big document was loaded, and user opened a small one in the same instance, it crashed)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8002
  • Assembler is fun ;-)
    • MasmBasic
Bugfix
« Reply #422 on: October 30, 2017, 01:15:56 AM »
a) Version 29 October has now the "unique" feature for generation random numbers (->Unique random numbers):
Code: [Select]
Rand(-99, 100, SomeIntegerArray(ecx), unique) ; min, max, destination, unique flag
Full example:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  tests=100
  Dim SomeInteger() As DWORD
  PrintLine Str$("Possible range: %i ... ", -tests/2), Str$(tests/2)
  Let edi="unique numbers: "
  Rand()                                        ; set a seed value
  For_ ecx=0 To tests-1
       Rand(-tests/2, tests/2+1, SomeInteger(ecx), unique)     ; min, max, destination, flag
       Let esi=Str$(" %i ", SomeInteger(ecx))
        .if Instr_(edi, esi)
                inc  ebx                ; oops, we got that one already
        .else
                Let edi=edi+esi         ; remember the last number
        .endif
  Next
  if tests le 100
        PrintLine edi                   ; show the unique numbers
  endif
  Inkey Str$("-- %i errors, hit any key --", ebx)
EndOfCode


Output:
Code: [Select]
Possible range: -50 ... 50
unique numbers:  -13  31  43  11  16  1  -14  -36  -6  21  34  -45  17  -2  -35  39  23  40  7  -1  -5  32  -25  -30  -28  -19  15  -26  0
-29  41  -10  27  -15  22  -33  44  35  -9  29  -12  -16  -24  13  -3  -38  26  -20  -21  20  4  18  -46  36  -23  47  37  49  -34  19  14
10  -37  9  -40  -49  -4  -32  -48  -27  -11  33  2  28  -17  -31  -39  -8  8  -41  -22  24  -50  38  25  -42  6  12  42  -47  48  -44  46
45  3  -7  -18  -43  50  30
-- 0 errors, hit any key --

If you find a duplicate, I owe you a beer, but you must come here to get it :bgrin:

Note that for high numbers of unique random numbers, e.g. tests=30000, it may take a few seconds.


b) another little feature: SetWin$ can now set the text of child controls. Example:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Launch "Notepad.exe SetChildWin.rc", SW_RESTORE, 100  ; give Notepad a few milliseconds to set the caption properly
  .if WinByTitle("SetChildWin.rc - ")
        xchg eax, ecx                   ; set the handle to ecx (MasmBasic won't touch ecx)
        SetWin$ ecx, 15=Replace$(Cat$(Win$(ecx, 15)), "Win$", "Win$#####", 0)   ; replace with an easy-to-spot string
  .endif
EndOfCode


Full project attached, tested with Win7-64 and WinXP. When you hit F6 in RichMasm, the fake rc file for Notepad gets generated from the text between the red Rsrc tags.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8002
  • Assembler is fun ;-)
    • MasmBasic
MasmBasic hits the 400 commands mark
« Reply #423 on: November 08, 2017, 03:00:29 PM »
Version 8 November 2017 is ready to be installed. Changes:

- updated help file, with now 400+ macros documented (also online - use Ctrl F to find commands; but remember the best help option is to use RichMasm, hover over a keyword like Open, then right-click on the word and copy the line that fits your case)

- fDate$() and fTime$() can now take a third parameter to force any language:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Print "Right now, ", fDate$(0, "dddd dd MMMM yyyy "), fTime$(0, "HH:mm:ss"), Str$(", we are in ISO week %i\n", IsoWeek())
  Print fDate$(0, "dddd dd MMMM yyyy ", russian), fTime$(0, "HH:mm"), Str$(", мы находимся в ИСО неделе %i", IsoWeek())
  wMsgBox 0, wCat$(wfDate$(0, "dddd dd MMMM yyyy ", hindi)+wfTime$(0)), "This is Unicode:", MB_OK
EndOfCode

Output:
Right now, Wednesday 08 November 2017 04:55:26, we are in ISO week 45
среда 08 ноября 2017 04:55, мы находимся в ИСО неделе 45


- SetInt can now move the content of ST(0) to xmm0:
  fldpi
  Print Str$("PI=\t%Jf\n", ST(0))
  fmul FP4(100.0)
  SetInt ecx
  Print Str$("100*PI=\t %i\n", ecx)
  fldpi
  fmul FP8(10.0e16)
  SetInt xmm0
  Print Str$("100*PI=\t %i\n", xmm0)


Code: [Select]
Output:
PI=     3.141592653589793238
100*PI=  314
10e16*PI=314159265358979324

- finally, the ternary operator If? can now also take the Zero? and Carry? flags as input (testbed attached):

  xor ecx, ecx
  Print Str$("zero flag set: %i\txor ecx, ecx\n", If?(zero?, 111, 222))         ; prints first number, 111
  or ecx, -1
  Print Str$("zero flag set: %i\tor ecx, -1\n", If?(zero?, 111, 222))   ; prints second number, 222
  stc
  Print Str$("carry set: %i\tstc\n", If?(Carry?, 111, 222))     ; carry is set, prints 111
  clc
  Print Str$("carry set: %i\tclc\n", If?(Carry?, 111, 222))     ; carry clear, prints 222

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8002
  • Assembler is fun ;-)
    • MasmBasic
Exe to .DATA
« Reply #424 on: November 25, 2017, 01:46:45 AM »
HexDump$() got new options:

Let My$=HexDump$("SomeFile.exe", file, dq)  ; translate the file to a string ready for pasting

Attached source & exe of an application that translates any file into an include file. Limit is around 640kB for the *.inc file. The format is as follows (as an example, I translated \Masm32\MasmBasic\RichMasm.exe):
Code: [Select]
.DATA
hdBytes=68608
RichMasmStart LABEL BYTE
.radix 16
dq 06172627261665A4D, 00000455068637375, 05A1809200001014C, 00000000000000000, 03202010B010F00E0, 000197A0000018400, 00000FE6800000000, 00000000C00001000
...
dq 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000
.radix 10
.code
; FileWrite "RichMasm.tmp", offset RichMasmStart, hdBytes


include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  .if Exist(CL$())
        Let edi=HexDump$(Exist$, file, dq)
        Let esi=Extract$(CL$(), "\", ".", xsRinstrL)+".inc"
        Let ecx=Str$("%i bytes translated to ", LastFileSize)+esi+CrLf$+CrLf$+Left$(edi, 200)+\
          CrLf$+"..."+CrLf$+Right$(edi, 200)+CrLf$+CrLf$+"Create inc (NO=copy to clipboard)?"
        If_ Exist(esi) Then Let ecx="Attention, "+esi+" exists!!!!"+CrLf$+ecx
        MsgBox 0, ecx, "File to *.inc:", MB_YESNOCANCEL or MB_ICONQUESTION
        .if eax==IDYES
                FileWrite esi, edi
        .elseif eax==IDNO
                SetClip$ edi
        .endif
  .else
        If_ Rinstr(CL$(0), "\") Then inc eax
        MsgBox 0, Cat$("Drag a file over "+eax), "File to *.inc:", MB_OK
  .endif
EndOfCode

OPT_Arg1        \Masm32\MasmBasic\RichMasm.exe  ; just for fun, translate the editor to .DATA ;-)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8002
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #425 on: December 19, 2017, 10:56:51 AM »
MasmBasic updated, please reinstall version 19 December 2017. Minor changes, inter alia:

- Cpu$():
include \masm32\MasmBasic\MasmBasic.inc
  Init
  MsgBox 0, Cat$("My CPU: "+Cpu$()), "Hi:", MB_OK
EndOfCode


NanoTimer() has been improved, see the new timings thread.

- Delay until (-> full example):

        Delay 1000                      ; standard version: wait a second
       PrintLine fTime$(0, "HH:mm:ss.fff"), Tb$, "started"
        Delay until fTime$(s:1, "HH:mm:ss.123")         ; use time$(current plus one second)
       PrintLine fTime$(0, "HH:mm:ss.fff "), Tb$, NanoTimer$(), " restarted"
Rem    - uses Sleep but preserves ecx
        - the until variant uses a time string to wait until a precise moment; use e.g. fTime$(1, "HH:mm") to
          suspend running until the current minute is finished; fTime$(s:10, ...) would mean 10 seconds


- the "controls" snippet in the templates has been improved (-> File/New Masm source/console/window/controls)

Let me know if there are any problems (there might be some with Windows XP - I test thoroughly for Win7 and Win10 but for XP I only have a VM).

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8002
  • Assembler is fun ;-)
    • MasmBasic
ClearFileCache and new GuiControls
« Reply #426 on: December 26, 2017, 03:36:15 AM »
MasmBasic 25 December 2017 features ClearFileCache for timings and benchmarks involving disk I/O, uMirror$(), plus a number of new controls. Here are 75 lines of code showing 18 controls in action (screenshot below, source & exe attached; drag a text file over the exe):

GuiParas equ "Controls", x660, y50, w500, h320, m4, b RgbCol(160, 255, 255)    ; position, margins, background
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste    ; define a menu (functions not implemented)
include \masm32\MasmBasic\Res\MbGui.asm
  SetGlobals ticks=rv(GetTickCount), f$="some text to find", r$="Доброе утро!!!!"     ; set global variables; note that they use ebx under the hood
  SetGlobals                                                    ; initialise them
  GuiControl ListBox, "listbox", x700, w300, h1000-80, WS_EX_CLIENTEDGE, +WS_BORDER or LBS_NOINTEGRALHEIGHT     ; start at 70% width, use 30% width, full height; + means defstyle or ...
  GuiControl MyDt, "syslink", "Date+Time (MSDN):", x700, w300, y1000-72, h0+18
  GuiControl MyTime, "time", x700, w300, y1000-53, h0+25
  GuiControl MyDate, "date", x700, w300, y1000-26, h0+25
  GuiGroup "Controls can be grouped:", w0+246, h0+75, bgcol RgbCol(255, 255, 200)
    GuiControl StatFind, "static", "Find:",        h0+22, w0+55              ; general syntax:
    GuiControl StatRepl, "static", "Replace:", h0+22, w0+55, y 0+24            ; guicontrol ID, "class", args "text", x, y, w, h, style
    GuiControl EditFind, "edit", f$, x 0+62, w0+100, h0+22, WS_EX_CLIENTEDGE   ; args have a variable part plus an optional fixed one, example:
    GuiControl EditRepl, "edit", r$, x 0+62, w0+100, h0+22, WS_EX_CLIENTEDGE, y 0+28   ; x1000-90 means "at right border, i.e. 100.0%, minus 90 pixels"
    GuiControl Cis, "button", BS_AUTOCHECKBOX, h0+22, x0+170, w0+60, "Case"    ; args may appear in no particular order, e.g. "Case" at the end
    GuiControl Fw, "button", text "Full word", h0+22, x0+170, w0+64, y0+28, BS_AUTOCHECKBOX
  GuiGroup end
  GuiControl BigEdit, "richedit", y0+120, h1000-120, w700      ; y at fixed 120px, h at full height minus 100px; width 70.0%
  If_ Exist(CL$()) Then <SetWin$ hBigEdit=FileRead$(Exist$)>    ; OPT_Arg1      \Masm32\MasmBasic\Res\MbSnippets.asc
  GuiControl Ok, "button", "Reset", x0+257, w0+80, h0+24, BS_DEFPUSHBUTTON
  GuiControl Progress, "progressbar", y0+88, h0+29, w700        ; , style PBS_SMOOTH    ; no effect if manifest is active
  GuiControl Status, "statusbar", "MasmBasic is pure assembly!!!!"
  GuiControl TimeMs, "static", x0+260, y0+32, h0+17, w0+75
  GuiControl InstallMB, "syslink", x0+260, y0+50, h0+17, w0+80, "MasmBasic"     ; RichMasm: copy a URL, select a word, press Ctrl K
  GuiControl Track, "trackbar", x0+257, y0+68, h0+17, w0+75, style TBS_AUTOTICKS or TBS_ENABLESELRANGE
  StringToArray cfm$("These\nare\nsome\nentries\nin\na\nlittle\nlistbox"), lbox$()      ; create an array (use Recall to load a textfile)
  SetListbox lbox$()                   ; fill the listbox
Event Timer
  sub rv(GetTickCount), ticks
  invoke SendMessage, hProgress, PBM_SETPOS, eax, 0
  SetWin$ hTimeMs=fTime$(0, "HH:mm:ss.fff")     ; shows milliseconds (check CPU usage in Task Manager!)
Event Message
  .if uMsg_==WM_HSCROLL                 ; horizontal trackbar sends this message
        mov eax, lParam_
        .if eax==hTrack
                mov ticks, rv(GetTickCount)             ; try to sync with progressbar ;-)
                shl rv(SendMessage, lParam_, TBM_GETPOS, 0, 0), 9
                sub ticks, eax
        .endif
  .elseif uMsg==WM_CLOSE
        if 0                                    ; put 0 for testing (Escape quits), 1 for the release version
               MsgBox 0, "Save settings?", "Hi", MB_YESNOCANCEL
                sub eax, IDCANCEL
                je @RetEax                      ; return 0, i.e. do NOT close
                .if eax==IDYES-IDCANCEL
                                MsgBox 0, "Add your 'save settings' etc here", "Hi", MB_OK
                .endif
        endif
  .endif
Event Key
  .if VKey==VK_A
        MsgBox 0, "You pressed 'A'", "Hi", MB_OK                ; negative VK_ codes indicate the key was hit in an edit control
  .endif
Event Command
  Switch_ MenuID                                        ; menu entries start with 0, controls return their IDs here
  Case_ 0, Ok
        SetWin$ hStatus="You clicked the Open menu or the Reset button"
        mov ticks, rv(GetTickCount)
  Case_ 1: call MySave                          ; your own functions may appear after EndOfEvents
  Case_ 2: invoke SendMessage, hWnd, WM_CLOSE, 0, 0     ; the Exit menu entry
  Case_ 3 .. 9 : <MsgBox 0, Str$("You clicked MenuID #%i", MenuID), "Menu clicked:", MB_OK>
  Case_ EditFind, EditRepl, Cis, Fw
        wSetWin$ hStatus=wStr$("You clicked inside the group on item %i with text '", MenuID)+wWin$(rv(GetDlgItem, hWnd, MenuID))+"'"      ; Unicode is possible
  Endsw_
  .if NotifyCode==DTN_DATETIMECHANGE && (wParam==MyDate || wParam==MyTime)
        SetWin$ hStatus=Cat$(Win$(hMyDate)+", "+Win$(hMyTime))  ; 11.12.2013, 12:34:56
  .endif
  If_ NotifyCode==NM_CLICK && (word ptr wParam==InstallMB || word ptr wParam==MyDt) Then <wShEx Link$()>  ; open a web page
  If_ NotifyCode==LBN_SELCHANGE && word ptr wParam==ListBox Then SetWin$ hStatus=LbSel$         ; LbSel$ returns the text of the current listbox entry
EndOfEvents
MySave proc    ; your procs go below EndOfEvents
  SetWin$ hStatus="You clicked the Save menu"
  ret
MySave endp
GuiEnd


P.S.: You may try other types of controls, see Current UI Automation Control Types for an overview. Let me know what you tried and if it worked; if not, I may be able to implement the missing bits. Btw there is no "control" that allows to pick colours. Instead, use the MasmBasic RgbCol macro with ?, for example: invoke someapi, RgbCol(?). Just for fun, here an "add-on" for the source above:
Code: [Select]
SetWin$ hStatus="You clicked the Open menu or the Reset button"
mov ticks, rv(GetTickCount)
invoke DeleteObject, hcGroupBx   ; internal handles for the groupbox (not documented)
mov hcGroupBx[4], RgbCol(?)
mov hcGroupBx, rv(CreateSolidBrush, eax)
invoke InvalidateRect, hcGroupBx[8], 0, 1
« Last Edit: December 26, 2017, 11:43:51 AM by jj2007 »

jack

  • Regular Member
  • *
  • Posts: 18
Re: MasmBasic
« Reply #427 on: January 01, 2018, 12:06:04 AM »
hi jj2007
I installed the masm32 sdk without problems but trying to install MasmBasic trows Wndows Defender into panic, I forgot the trojans name that it purportedly found, any advise?

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8002
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #428 on: January 01, 2018, 03:06:00 AM »
Just tested the current package on Jotti, details here, but "0/18 scanners reported malware". Quite unusual, actually :icon_mrgreen:

Similar for VirusTotal (results) - the Baidu AV reported "WisdomEyes", whatever that is, but 60 others say it's clean.

The Forum is on a safe server, and the MasmBasic package gets built with an automated procedure. There is no chance of a trojan creeping in. But many AV produce false positives - we even have a dedicated sub-forum AV Software sh*t list  :bgrin:

Assembler produces by its nature suspicious code: The virus scanners expect C/C++ initialisation routines, CRT, SEH, etc; if they don't find them, they shout foul. Sometimes they shout foul because they see a pushad ... popad sequence, which is very unusual in C code, so it's "suspicious". Everything that is non-standard looks dangerous to them. Well, we are all proud here to produce non-standard software, so evidently there is a certain tension between assembler programmers and the AV brigade. And to be honest, there is also a community of assembler programmers who do produce malware, but we usually smell them from a distance if they appear here and ask for advice. The forum rules are very strict, and for valid reasons.

If you cannot ignore or override the message, try if there is an option to exclude certain folders, e.g. \Masm32\, from the scan. In the last five ten years or so, we had one case of a virus introduced here in this forum by a young member (who apparently had an infected machine without knowing it), and it was spotted by experienced members, not by their antivirus software...

jack

  • Regular Member
  • *
  • Posts: 18
Re: MasmBasic
« Reply #429 on: January 01, 2018, 03:17:48 AM »
ok thanks, I suspected it was a false positive.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8002
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #430 on: January 01, 2018, 03:28:02 AM »
Just remembered the Test your AV software thread, which I launched two years ago because I couldn't explain why Windows Defender never tried to defend me from really suspicious software ;)

LiaoMi

  • Member
  • **
  • Posts: 206
Re: MasmBasic
« Reply #431 on: January 01, 2018, 03:34:08 AM »
hi jj2007
I installed the masm32 sdk without problems but trying to install MasmBasic trows Wndows Defender into panic, I forgot the trojans name that it purportedly found, any advise?

Hi jack,

 :biggrin: Windows Defender is a commercial project that removes only unusual or licensed products of competitors, on my windows 10 I completely removed it  :t