Monday, January 18, 2021

Hello World Assembly code for Termux App

There is an article on M1 helloworld assembly language code on tge new Mac M1 hardware. https://smist08.wordpress.com/2021/01/08/apple-m1-assembly-language-hello-world/

The system call table can be referred to this in Mac /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/syscall.h
For the BSD system calls method please refer to https://sigsegv.pl/osx-bsd-syscalls/
whereas #1 is exit system call and #4 is write system call

For the complete ARM64 programming examples for M1 Mac, please refer to this.
https://github.com/below/HelloSilicon

It is important to learn debug skill through assembly language and for mac use lldb to debug, e.g.
(lldb) breakpoint set -f HelloWorld.s -l 14
(lldb) run
(lldb) step
(lldb) register read x16 x0 x1 x2

In order to debug on Mac, the program first must add -g option when compiled/asembled(as) and then must be codesigned and add this codesign command to the makefile
codesign --entitlements entitlements.plist --force -s - $@
entitlements.plist add this key.
<key>com.apple.security.get-task-allow</key>
<true/>


What about Android Termux App?
pkg install clang
wget https://raw.githubusercontent.com/matja/asm-examples/master/aarch64/hello.aarch64.linux.syscall.gas.asm
gcc -nostdlib -static -nostartfiles -Wl,--entry=_start hello.aarch64.linux.syscall.gas.asm -o hello
./hello

What about gbd debug ?
gcc -nostdlib -static -nostartfiles -Wl,--entry=_start hello.aarch64.linux.syscall.gas.asm -g -o hello
pkg install gdb
objdump -d hello
gdb hello
(gdb) break 1 # set breakpoint
(gdb) run # run
(gdb) step # step
(gdb) info reg general # exam register

ARM Architecture Basic
x0-x30 are 64-bit registers
svc 0 is the system call
x8 determines what we do, e.g. #64 write and #93 is exit (for other system call numbers please refer to document)
x8 determines what we do, e.g. #64 write and #93 is exit (for other system call numbers please refer to document)
x8 determines what we do, e.g. #64 is write and #93 is exit (for other system call numbers please refer to this document)
x0-x4 determines how we do it and the required parameters are also documented in the document above.

Saturday, January 16, 2021

How to install youtube-dl and cmus for Android App Termux and play music

# Download youtube-dl (Python Binary executable)
pkg install wget
cd ~
wget https://github.com/ytdl-org/youtube-dl/releases/download/2021.03.25/youtube-dl

chmod +x youtube-dl

Note: This python binary executable can be used cross platform x86, x64, arm or arm64, Linux or Mac.

# move to usr/bin
mv ~/youtube-dl /data/data/com.termux/files/usr/bin/

# Install required packages
pkg install python
pkg install openssl
pkg install ffmpeg

# Update to latest version
youtube-dl -U

# Setup Android local storage
termux-setup-storage

# Download Youtube as m4a format(add --no-continue to overwrite)
cd ~/storage/music
youtube-dl -i -f m4a https://youtu.be/e0npW4WoGmc

# Convert from mp4 to m4a using ffmpeg (-y is to overwrite)
ffmpeg -y -i 'downloaded video.mp4' -vn -c:a copy 'downloaded video convert to audio.m4a'

# Convert from m4a to mp3 using ffmpeg
ffmpeg -i input.m4a -c:v copy -c:a libmp3lame -q:a 4 output.mp3

# scale based on input size e.g. lets say reduce the width/height to half
ffmpeg -i input.avi -vf scale="iw/2:ih/2" output.avi

# Install cmus terminal player
pkg install cmus
cmus
# Press 5 to select music to play