Author Topic: Miscellaneous snippets  (Read 4476 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8504
  • Assembler is fun ;-)
    • MasmBasic
Create a temp web page to save a link
« Reply #45 on: May 14, 2018, 06:37:05 AM »
Sometimes I need to save a webpage but don't want to open it. So I copy the URL and run this proggie (source+exe attached):

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Let esi=Clip$()               ; get URL from clipboard, e.g. http://masm32.com/board/index.php?action=unread
  .if Instr_(esi, "://")
        FileWrite "SaveLinkAsTemp.html", Cat$(Chr$("<html><head><title>Temporary link</title></head>", 13, 10, "<body>", 60, "a href=", 34)+esi+Chr$(34, 62, "Right-click here and choose 'Save Link as...' to download ")+esi+Chr$(60, "/a", 62, "</body></html>"))
        ShEx "SaveLinkAsTemp.html"      ; launch the browser
  .else
        MsgBox 0, esi, "No URL found:", MB_OK
  .endif
EndOfCode



jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8504
  • Assembler is fun ;-)
    • MasmBasic
Check a file for http:// and friends
« Reply #46 on: May 18, 2018, 11:59:07 AM »
Attached a little file DownloadMasm32.exe that does something entirely harmless:
Code: [Select]
include \masm32\MasmBasic\MasmBasic.inc
  Init
  Let esi="0.75=draob?php.xedni/draob/moc.23msam//:ptth"
  PrintLine esi
  Let edi=FileRead$(Mirror$(esi))
  Inkey NoTag$(edi)
EndOfCode

In addition, the attachment contains a project that finds http:// and https:// in files, even if they are mirrored; just drag a file over SpyWareScanMB.exe 8)

Warning: While SpyWareScanMB.exe finds interesting http:// and https:// matches in exes and dlls, it is not a replacement for an AntiVirus. Malware writers use more sophisticated tricks to hide their URLs.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8504
  • Assembler is fun ;-)
    • MasmBasic
Print formatted text
« Reply #47 on: June 25, 2018, 03:55:17 AM »
This snippet
- reads a text file into a RichEdit control (its name is supplied by the commandline)
- formats the first line in bold
- on request via the menu, prints the text.

To test it, extract all files to a temporary folder and drag the text file over the exe (the *.asc file is the source as RTF).

If needed, the whole process can be automated, i.e. eliminate the Event Menu step and just run the exe with the commandline argument, then exit automatically. See PrintRtf for printer dialog handling options.


GuiMenu equ @File, &Open, &Print, E&xit
GuiParas equ "Print formatted text demo", x100, y100, w400, h200; , cblack, b00FFFFD0h
include \masm32\MasmBasic\Res\MbGui.asm

  MakeFont hMyFont, Height:20, "Lucida Handwriting"
  GuiControl MyEdit, "RichEdit", font hMyFont
  SetGlobals f$, charfmt:CHARFORMAT2
  Let f$=FileRead$(CL$())               ; read the text file passed in the commandline
  SetWin$ hMyEdit=f$
  .if Instr_(f$, CrLf$)
       dec edx                         ; index of CrLf-1
       invoke SendMessage, hMyEdit, EM_SETSEL, 0, edx
       m2m charfmt.cbSize, CHARFORMAT2
       m2m charfmt.dwMask, CFM_BOLD            ; CharFtMask
       m2m charfmt.dwEffects, CFE_BOLD         ; Character effects
       invoke SendMessage, hMyEdit, EM_SETCHARFORMAT, SCF_SELECTION, ADDR charfmt
       invoke SendMessage, hMyEdit, EM_SETSEL, 0, 0
  .endif

Event Menu
  .if MenuID==1
        void PrintRtf(hMyEdit, 1)     ; 0=use default printer, 1=ask for printer dialog
  .endif
GuiEnd

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8504
  • Assembler is fun ;-)
    • MasmBasic
Launcher
« Reply #48 on: June 27, 2018, 02:54:41 PM »
Code: [Select]
include \masm32\include\masm32rt.inc

.data
txFile db "extracted.exe", 0
bytesWritten dd ?

.code
start:
  invoke FindResource, 0, 99, RT_RCDATA
  .if eax
xchg eax, ebx ; hRes
push rv(SizeofResource, 0, ebx)
push rv(LoadResource, 0, ebx) ; returns pointer to content in eax
invoke CreateFile, addr txFile, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0
xchg eax, esi
pop eax ; pointer to content
pop ecx ; size in bytes
invoke WriteFile, esi, eax, ecx, addr bytesWritten, 0
invoke CloseHandle, esi
invoke WinExec, addr txFile, SW_SHOW
  .endif
  exit
end start

HSE

  • Member
  • ****
  • Posts: 707
  • <AMD>< 7-32>
Re: Miscellaneous snippets
« Reply #49 on: June 27, 2018, 11:36:18 PM »
 :t

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8504
  • Assembler is fun ;-)
    • MasmBasic
Check if a file is older than a specified date
« Reply #50 on: July 07, 2018, 08:20:15 PM »
Just encountered a case where I had to check if a file was older than dd.month.year, and needed a snippet to perform this check:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  .if Exist(CL$())
        sub esp, 2*FILETIME             ; create two structures on the stack
        movlps QWORD ptr [esp], TimeSF("02.07.2018 11:16:50")   ; European format!
        lea ecx, [esp+QWORD]
        movlps QWORD ptr [ecx], GfLastWrite(-1)         ; the lower QWORD returns the FILETIME
        invoke CompareFileTime, ecx, esp
        add esp, 2*FILETIME             ; correct the stack
        .if signed eax<0
                wMsgBox 0, wCL$(), "File is older. Process?", MB_YESNOCANCEL
                .if eax==IDYES
                                ; ... do stuff ...
               .endif
        .else
                wMsgBox 0, wCL$(), "File is younger:", MB_OK
        .endif
  .else
        wMsgBox 0, wCL$(), "No such file:", MB_OK
  .endif
EndOfCode

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8504
  • Assembler is fun ;-)
    • MasmBasic
Create a hundred folders
« Reply #51 on: July 11, 2018, 09:26:40 PM »
Create a hundred folders, write a testfile to each of them:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  For_ ecx=0 To 99
        Let esi=Str$("New Folder%i", ecx)
        MakeDir esi
        .Break .if !Zero?
        Print "+"
        Let esi=esi+"\test.txt"
        PrintLine Str$(ecx), Tb$, esi
        FileWrite esi, Str$("Test %i", ecx)
  Next
EndOfCode


jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8504
  • Assembler is fun ;-)
    • MasmBasic
Numbers only
« Reply #52 on: July 14, 2018, 05:10:28 AM »
An edit control that allows to enter only valid decimal numbers. Bug feedback welcome :biggrin: