Monday, March 23, 2020

ASM: Convert DWORD to string in Assembly using MSVCRT _ultoa

This post shows how to convert unsigned int (DWORD) to string using MSVCRT function _ultoa.

.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\msvcrt.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\msvcrt.lib
.data
buffer DB 11 DUP(0)
value DWORD 4294967295
.code
start:
invoke crt__ultoa,value,ADDR buffer,10
invoke StdOut, addr buffer
invoke ExitProcess, 0
end start
view raw int2string3.asm hosted with ❤ by GitHub


Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff int2string3.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE int2string3.obj
Keywords: Assembly, Win32

Remote Registry missing in Vista

 

After installing/uninstalling software in Windows Vista Business machine "Remote Registry" got missing in the services list. Poking around the registry, noticed that under "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RemoteRegistry", Start key was gone.

See picture below for the location:

image

Creating the "Start" key of type REG_DWORD and value 3 (Manual) or 2 (Automatic), then a rebooted fixed the problem.

~ts

Wednesday, March 18, 2020

USB Mouse not detected properly in Vista

After using Windows Vista for over a month my USB mice stopped working :(.... Fortunately this is easy to fix via trial and error on what driver best works for Vista. To fix this do the ff:
Step 1. Go to Device Manager (devmgmt.msc).
Step 2. Do Update Driver Software.
Step 3. Browse my computer for driver software.
Step 4. Select "Let me pick from from a list of device drivers on my computer."
Step 5. If it was shown as unknown device, select "Mice and other pointing device" else select "HID-compliant device."
Step 6. Click on "Have Disk..."
Step 7. Drill to C:\Windows\System32\DriverStore\FileRepository. Select a folder with a name that start with msmouse*. Start with the folder that has the latest time stamp. If this driver does not work select the next newer folder until your mouse driver is installed properly.
See below for related figures.
Figures:
capture
Figure 1.
capture2
Figure 2.
~ts

Monday, March 16, 2020

Installing VirtualBox Guest additions in Debian Buster

VirtualBox Guest Additions allow a good number of  host to guest integrations that makes using the VM easier to use, for example copy/pasting text from host to guest and vice versa is very convenient. Another useful feature is resizing the window of the guest VM.

To enable/install VirtualBox Guest Additions, do:
$: sudo apt install dkms

From VirtualBox Guest main UI, select Devices | Install Guest Additions..., then:
$: cd /media/cdrom
$: sudo sh ./VBoxLinuxAdditions.run
$: sudo reboot

Note:


Keywords: Debian Buster, Debian 10.3

Sunday, March 15, 2020

Adding existing user to a group in Ubuntu

Example below adds user timus to the group www-authors

$: sudo usermod -a -G www-authors timus

To add user timus to sudoers group, do:

$: sudo usermod -a -G sudo timus

Note:

  • That for the sudo to take effect you have to logout and log back in.
  • In Debian Buster (10.3), need to reboot for it to take effect


Tested on:
- Lubuntu (13.04)
- Ubuntu (12.04 - 13.04)
- Debian Buster (10.3)

References:
http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/
http://askubuntu.com/questions/7477/how-can-i-add-a-new-user-as-sudoer-using-the-command-line


Saturday, March 14, 2020

Install Lazarus on MX Linux

Lazarus IDE is one of the Free Pascal IDEs available. Lazarus/FPC combination is an open source replacement for Delphi.

Just would like to note that Delphi as of March 2020 is more than just a rapid application development platform for developing desktop applications, it can also be used to write Android and web application.

Anyway, to instal Lazarus on MX Linux (or Debian Buster derivates), do:
$: sudo apt install fpc fpc-source gdb lazarus
Keywords: Lazarus, Free Pascal, Delphi, Linux

Fatal: Cannot find FastHTMLParser used by Clipbrd of package LCLBase

I have tried to install Lazarus 2.0.0 (FPC 3.0.4) on MX Linux 19.1 but got the following error message when compiling the default project created by Lazarus.

Fatal: Cannot find FastHTMLParser used by Clipbrd of package LCLBase.

One way to fix this is to install the fpc package, like:
$: sudo apt install fpc

Keywords: Free Pascal, Lazarus

Disable Windows Vista UAC using MSCONFIG

Run msconfig.exe from command line.

image

Then select "Disable UAC", see above for the location. Then hit on "Launch" button. Reboot computer.

~ts

ASM: Convert int to string in Assembly part 2

This post shows how to convert int (DWORD) to string using modified version of dwtoa(dwtoa2) from MASM library. Older post can be found here.

.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
dwtoa2 proto :DWORD, :DWORD
.data
msg1 DB "Max DWORD : ", 0
msg2 DB 13,10,"Zero : ",0 ;13=CR, 10=LF
buffer1 DB 10 DUP(0)
buffer2 DB 10 DUP(0)
max_dword DWORD 4294967295
.code
start:
invoke dwtoa2, max_dword, addr buffer1
invoke StdOut, addr msg1
invoke StdOut, addr buffer1
invoke dwtoa2, 0, addr buffer2
invoke StdOut, addr msg2
invoke StdOut, addr buffer2
invoke ExitProcess, 0
dwtoa2 proc dwValue:DWORD, lpBuffer:DWORD
; -------------------------------------------------------------
; convert DWORD to ascii string
; dwValue is value to be converted
; lpBuffer is the address of the receiving buffer
; EXAMPLE:
; invoke dwtoa2,edx,ADDR buffer
;
; Uses: eax, ecx, edx.
; -------------------------------------------------------------
push ebx
push esi
push edi
mov eax, dwValue
mov edi, [lpBuffer]
test eax,eax
jnz notzero
zero:
mov word ptr [edi],30h
jmp dtaexit
notzero:
;https://en.wikipedia.org/wiki/Division_algorithm
mov ecx, 3435973837
mov esi, edi
.while (eax > 0)
mov ebx,eax
mul ecx
shr edx, 3
mov eax,edx
lea edx,[edx*4+edx]
add edx,edx
sub ebx,edx
add bl,'0'
mov [edi],bl
add edi, 1
.endw
mov byte ptr [edi], 0 ; terminate the string
; We now have all the digits, but in reverse order.
.while (esi < edi)
sub edi, 1
mov al, [esi]
mov ah, [edi]
mov [edi], al
mov [esi], ah
add esi, 1
.endw
dtaexit:
pop edi
pop esi
pop ebx
ret
dwtoa2 endp
end start
view raw int2string2.asm hosted with ❤ by GitHub


Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff int2string2.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE int2string2.obj

SHDocVw.ShellWindows stopped working on Vista

I have the following code to enumerate running instance of IE 7(not sure if this works with IE6).


Sub TestGetRunningIE()
    Dim sws As SHDocVw.ShellWindows
    Dim ie As SHDocVw.InternetExplorer
    
    Set sws = New SHDocVw.ShellWindows
    For Each ie In sws
        Debug.Print ie.Name
    Next
End Sub

For the above code to work, need to make a reference to shdocvw.dll, see below for the location:
image
When I moved this code in Vista SP1 Business it stopped working. Who would think that this is related to UAC :)... anyway just disable UAC and this code should work again. Note that on one of my machines it is working with UAC on :(....

See this post to disable UAC. This is only one of the methods to disable User Account Control.
~ts

ASM: Convert int to string in Assembly

This post shows how to convert int (DWORD) to string using MASM library dwtoa. There seems to be a bug in dwtoa as it can only handle 2147483647 instead of 4294967295 which is the maximum size of DWORD (32-bit). The code for dwtoa checks for a negative number which is not needed for DWORD. Note that DWORD is defined as 32-bit unsigned.

.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
buffer DB 11 DUP(0)
;value DWORD 4294967295
value DWORD 2147483647
.code
start:
invoke dwtoa, value, addr buffer
invoke StdOut, addr buffer
invoke ExitProcess, 0
end start
view raw int2string.asm hosted with ❤ by GitHub


Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff int2string.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE int2string.obj

Tuesday, March 10, 2020

ASM: Basic Windows application in Assembly

This post shows how to create Windows application using Assembly.

.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
WinMain proto :DWORD, :DWORD, :DWORD, :DWORD
.data
ClassName db "WinClass", 0
AppName db "Simple Window", 0
.data?
hInstance HINSTANCE ?
.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain, hInstance, NULL, NULL, 0
invoke ExitProcess, eax
WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
local wc:WNDCLASSEX
local msg:MSG
local hwnd:HWND
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground, COLOR_WINDOW+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx, 0, addr ClassName, addr AppName, WS_OVERLAPPEDWINDOW or WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL
mov hwnd, eax
.while TRUE
invoke GetMessage, addr msg, NULL, 0, 0
.break .if (!eax)
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
.endw
mov eax, msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg == WM_DESTROY
invoke PostQuitMessage,0
.else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.endif
xor eax, eax
ret
WndProc endp
end start


Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff basicwindows.asm

To link:
\masm32\bin\Link /SUBSYSTEM:WINDOWS basicwindows.obj

Reference(s):
This is shamelessly using contents from Windows Assembly Programming Tutorial  by JEFF HUANG (huang6@uiuc.edu)

Monday, March 09, 2020

ASM: Basic usage of assembly instructions

This program shows usage of basic assembly instructions add, cmp, dec, jnz, jz, mov, mul, pop, push, xor

.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
BadText db "Error: Sum is incorrect value", 0
GoodText db "Excellent! Sum is 6", 0
Sum sdword 0
.code
start:
; eax
mov ecx, 6 ; set the counter to 6 ?
xor eax, eax ; set eax to 0 0
_label: add eax, ecx ; add the numbers ?
dec ecx ; from 0 to 6 ?
jnz _label ; 21
mov edx, 7 ; 21
mul edx ; multiply by 7 147
push eax ; pushes eax into the stack
pop Sum ; pops eax and places it in Sum
cmp Sum, 147 ; compares Sum to 147
jz _good ; if they are equal, go to _good
_bad: invoke StdOut, addr BadText
jmp _quit
_good: invoke StdOut, addr GoodText
_quit: invoke ExitProcess, 0
end start


Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff basicinstructions.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE basicinstructions.obj

Reference(s):
This is shamelessly using contents from Windows Assembly Programming Tutorial  by JEFF HUANG (huang6@uiuc.edu)

Friday, March 06, 2020

ASM: Hello world using MessageBox in Windows assembly

MessageBox Hello World in Windows assembly using MASM

.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
.data
HelloWorld db "Hello World!", 0
.code
start:
invoke MessageBox, NULL, addr HelloWorld, addr HelloWorld, MB_OK
invoke ExitProcess, 0
end start
view raw hellow.asm hosted with ❤ by GitHub

Pre-requisite:

To assemble:
\masm32\bin\ml /c /Zd /coff hellow.asm

To link:
\masm32\bin\Link /SUBSYSTEM:WINDOWS hellow.obj

Reference(s):
This is shamelessly using contents from Windows Assembly Programming Tutorial  by JEFF HUANG (huang6@uiuc.edu)
x86 Disassembly - link

Thursday, March 05, 2020

ASM: Hello world in Windows assembly

Hello world in Windows assembly using MASM

.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
HelloWorld db "Hello World!", 0
.code
start:
invoke StdOut, addr HelloWorld
invoke ExitProcess, 0
end start
view raw hello.asm hosted with ❤ by GitHub


Pre-requisite:



To assemble:
\masm32\bin\ml /c /Zd /coff hello.asm

To link:
\masm32\bin\Link /SUBSYSTEM:CONSOLE hello.obj

Reference(s):
This is shamelessly using contents from Windows Assembly Programming Tutorial  by JEFF HUANG (huang6@uiuc.edu)
x86 Disassembly - link

Wednesday, March 04, 2020

CPP: Basic usage of std::cin for getting input from stdin

CPP: Basic usage of std::cin for getting input from stdin

Basic usage of getting data from standard input (keyboard normally) using std::cin.
#include<iostream>
#include<string>
int main()
{
std::string name;
std::cout << "Please enter your name : ";
std::cin >> name;
std::cout << "Hello " << name << std::endl;
return 0;
}
view raw getinput.cpp hosted with ❤ by GitHub


To build:
$: clang++ getinput.cpp

Run it:
$: ./a.out

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04 I am planning to run qemu-system-ppc to play around QEMU ...