Sunday, December 1, 2013

Compiling FASM (flat assembler) using Notepad++ and the NppExec plugin

I enjoy writing assembly for fun and I usually write my source code in Notepad++ due to it's robustness as a text editor.  I like to test my code as I write so I constantly found myself copy-pasting my source code from Notepad++ over to FASMW to compile and run.  I needed a way to compile and run my FASM source code directly from Notepad++ and this is where the plugin, NppExec, became extremely helpful.

These instructions operate under the following assumptions:
  1. Notepad++ is installed to C:\Program Files\Notepad++
  2. The NppExec plugin is installed through Notepad++'s Plugin Manager.
  3. FASM (flat assembler) is installed to C:\Program Files\FASM
  4. You've added the Environment Variable (system variable) "INCLUDE" within Windows which points to C:\Program Files\FASM\INCLUDE (restarting may be required).
In Notepad++, navigate to Plugins -> NppExec -> Execute... and paste the following:

 NPP_SAVE  
 SET FASM = "C:\Program Files\FASM\FASM.EXE"  
 CD "$(CURRENT_DIRECTORY)"  
 cmd.exe /c "$(FASM) "$(FILE_NAME)" "$(NAME_PART).exe""  
 UNSET FASM  

Click "Save..." and under "Script name" type "Compile" and click "OK".

Again, navigate to Plugins -> NppExec -> Execute... and paste the following:

 NPP_SAVE  
 SET FASM = "C:\Program Files\FASM\FASM.EXE"  
 CD "$(CURRENT_DIRECTORY)"  
 cmd.exe /c "$(FASM) "$(FILE_NAME)" "$(NAME_PART).exe" && "$(NAME_PART).exe""  
 UNSET FASM  

Click "Save..." and under "Script name" type "Run" and click "OK".

Navigate to Plugins -> NppExec -> Advanced Options... In the "Menu items" pane, check the box next to "Place to the Macros submenu".  Under the "Associated script" drop-down menu select "Compile" and give it an appropriate "Item name" (e.g., Compile) and click "OK".  Repeat this process again once more but select "Run" from the "Associated script" drop-down menu instead.

Navigate to Settings -> Shortcut Mapper... Click on the "Plugin commands" button and scroll down until you find both "Compile" and "Run".  If you want the same shortcuts used in FASMW next to "Compile" click "Modify" and create the shortcut "CTRL + F9". Do the same for "Run" but instead use the shortcut "F9".

We're finished.  Now when you're working on an *.asm document in Notepad++ and press F9, FASM will compile the source code and if no errors arise, will launch the newly-compiled binary.

Tuesday, November 19, 2013

Drag-and-drop batch image resizing in Windows using ImageMagick and ExifTool

I became frustrated when a friend of mine kept sending me image attachments via e-mail that were in the RAW format and at the high resolutions he originally took his shots with. While my connection could handle the large files, I figured there were probably some listed addresses he sent these same images to where the receiver would get frustrated at how long it would take to download. This friend isn't very tech savvy and I've found that Windows makes it difficult to batch resize images so I came up with a batch file in which he could place wherever (hopefully his Pictures folder) that he could drag any folder into it and it would resize all the images in the folder to his default liking.

These instructions operate under the following assumptions:
  1. ImageMagick is installed to C:\Program Files\ImageMagick
  2. A copy of ExifTool (exiftool.exe) has been placed in your system folder at %SystemRoot%\System32
This version (0.3) is optimal for converting many images, however, this script is extremely memory-intensive. So run this while you're not doing too many other things on your computer.
 @echo off  
   
 rem 0.3  
 setlocal enabledelayedexpansion  
 set ImageDir=%1  
 set ImageFileTypes=bmp, gif, jpeg, jpg, png  
 set ResizedImageDir="%ImageDir:"=% (Resized)"  
 set ResizedImageGeometry=640x480  
 set RemoveImageMetadata=1  
 if not exist %ImageDir%\* (  
      exit  
 )  
 if not exist %ResizedImageDir%\* (  
      md %ResizedImageDir%>nul 2>&1  
 )  
 for %%a in (%ImageFileTypes%) do (  
      set ImageCount=0  
      for /f "tokens=*" %%b in ('dir /a:-d /b "%ImageDir:"=%\*.%%a" 2^>nul') do (set /a ImageCount+=1)  
      if !ImageCount! gtr 0 (  
           echo Resizing %%a images...  
           rem convert "C:\Images\*.xxx[640x480] -set filename:original "%t.%e" "C:\Images (Resized)\%[filename:original]">nul 2>&1  
           convert "%ImageDir:"=%\*.%%a[%ResizedImageGeometry%]" -set filename:original "%%t.%%e" "%ResizedImageDir:"=%\%%[filename:original]">nul 2>&1  
             
           if %RemoveImageMetadata% equ 1 (  
                rem echo Stripping %%a images of all profiles and comments...  
                rem mogrify -strip "C:\Images (Resized)\*.jpg">nul 2>&1  
                rem mogrify -strip "%ResizedImageDir:"=%\*.%%a">nul 2>&1  
   
                echo Deleting all meta information from %%a images...  
                rem exiftool -overwrite_original -all= "C:\Images (Resized)\*.jpg">nul 2>&1  
                exiftool -overwrite_original -all= "%ResizedImageDir:"=%\*.%%a">nul 2>&1  
           )  
      )  
 )  
Save the file as "batchImageResizer.bat"

This version (0.2) is an alternate build that is less memory-intensive.
 @echo off  
   
 rem 0.2  
 setlocal enabledelayedexpansion  
 set ImageDir=%1  
 set ImageFileTypes=bmp, gif, jpeg, jpg, png  
 set ResizedImageDir="%ImageDir:"=% (Resized)"  
 set ResizedImageGeometry=640x480  
 set RemoveImageMetadata=1  
 if not exist %ImageDir%\* (  
      exit  
 )  
 if not exist %ResizedImageDir%\* (  
      md %ResizedImageDir%>nul 2>&1  
 )  
 for %%a in (%ImageFileTypes%) do (  
      set ImageCount=0  
      for /f "tokens=*" %%b in ('dir /a:-d /b "%ImageDir:"=%\*.%%a" 2^>nul') do (  
           set /a ImageCount+=1  
           if not exist "%ResizedImageDir:"=%\%%~nxb" (  
                echo Resizing %%~nxb...  
                rem convert "C:\Images\image.jpg" -resize 640x480 "C:\Images (Resized)\image.jpg">nul 2>&1  
                convert "%ImageDir:"=%\%%~nxb" -resize %ResizedImageGeometry% "%ResizedImageDir:"=%\%%~nxb">nul 2>&1  
           )  
      )  
      if %RemoveImageMetadata% equ 1 (  
           if !ImageCount! gtr 0 (  
                rem echo Stripping %%a images of all profiles and comments...  
                rem mogrify -strip "C:\Images (Resized)\*.jpg">nul 2>&1  
                rem mogrify -strip "%ResizedImageDir:"=%\*.%%a">nul 2>&1  
   
                echo Deleting all meta information from %%a images...  
                rem exiftool -overwrite_original -all= "C:\Images (Resized)\*.jpg">nul 2>&1  
                exiftool -overwrite_original -all= "%ResizedImageDir:"=%\*.%%a">nul 2>&1  
           )  
      )  
 )  
Save the file as "batchImageResizer.bat"

You can modify some of the variables to your own liking.  As-is, if you drop a folder of images into this batch file it will create a new folder in the same directory, resize all the images to 640x480, and scrub the EXIF data from the images.

Enjoy. :)

Sunday, September 15, 2013

Using bookmarklets to open websites in new tabs

Recently, there was a situation where I needed to have a site open in a new tab.  I had to send multiple GET requests to a certain website to show a friend that the received responses were not always the same.  At the time I was using a portable version of the Pale Moon browser (Firefox fork) and didn't want to mess with searching for an add-on that was capable of the task so instead I came up with a simple solution:  Use a bookmarklet and keep visible on the bookmark's bar. That way I could manually tap the bookmark and load multiple tabs of the site I needed. To do that, I just created a bookmark with the location:

javascript:void(window.open("https://[website here]/"));

That's it.

Tuesday, September 10, 2013

Using the RIGHT-TO-LEFT OVERRIDE (RLO) unicode character to bypass content-filtering systems

This technique is nothing new but I keep finding myself trying to remember the character code for it. So I'm posting this as a personal reminder:

javascript:document.write(String.fromCharCode(8238) + 'desrever');

Tuesday, July 16, 2013

Add "Run CCleaner & Shutdown" to the context menu of the Recycle Bin

If you're concerned about your privacy or mistakenly having your laptop's volume maximized while booting your laptop up in a public place then this is a registry tweak for you.

These instructions operate under the following assumptions:
  1. CCleaner is installed to C:\Program Files\CCleaner
  2. A copy of NirCmd (nircmd.exe) has been placed in your system folder at %SystemRoot%\System32
 Windows Registry Editor Version 5.00  
   
 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\shell\Run CCleaner && Shutdown]  
   
 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\shell\Run CCleaner && Shutdown\command]  
 @="cmd.exe /c nircmd.exe setsysvolume 8738 & \"\"\"%%ProgramFiles%%\\CCleaner\\CCleaner.exe\"\"\" /AUTO /SHUTDOWN"  
Save the file as "addCCleanerToRecycleBin.reg"

Double-click on "addCCleanerToRecycleBin.reg" to execute. If everything went as expected, if you right-click on your Recycle Bin you should see a new menu item: "Run CCleaner & Shutdown". Selecting this menu item will execute NirCmd's setsysvolume function which will lower the system's volume to 8738 (of 65535). Afterwards, CCleaner will execute using the current set of saved options* and upon finishing will shutdown the computer.

*To ensure the highest level of security when cleaning files, enable the "Secure file deletion" option within CCleaner.

Displaying thumbnails from Everything search engine using IrfanView

Everything search engine by voidtools is a great piece of software which I would highly recommend to users looking for a replacement to Windows' built-in search feature. Unfortunately in it's current state, Everything search engine does not allow the option of viewing image thumbnails. One way to work around this problem is to generate a list of all image filenames and import them into IrfanView.

These instructions operate under the following assumptions:
  1. Everything search engine along with "es.exe" (Everything's command-line interface) are installed to C:\Program Files\Everything
  2. IrfanView is installed to C:\Program Files\IrfanView
Open up Notepad (notepad.exe) and paste the following:
 @echo off  
 set ImageFileTypes=gif, jpeg, jpg, png, psd  
 for %%a in (%ImageFileTypes%) do (  
      "%ProgramFiles%\Everything\es.exe" -s ""*.%%a"" >> "%Temp%\images.txt"  
 )  
 "%ProgramFiles%\IrfanView\i_view32.exe" /filelist="%Temp%\images.txt" /thumbs  
 del /f /q "%Temp%\images.txt"  
Save the file as "previewImages.bat"

Make sure Everything search engine is running before executing "previewImages.bat"