flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > Building and running Android armv7 sample

Author
Thread Post new topic Reply to topic
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
You need any Android device or emulator such as Bluestacks to run the sample (yes, Android x86 devices and emulators can run arm code).

You also need Android SDK because of Android Debug Bridge adb.exe, or you can copy the file to the device manually and run it in Terminal Emulator.

You don't need to root the device/emulator.

sample.asm:
Code:
format ELF executable
entry start

STDOUT      equ 1
SYS_EXIT    equ 1
SYS_WRITE   equ 4

segment readable executable

start:
 mov r0, STDOUT
 add r1, pc, msg-$-8
 mov r2, msg_len
 mov r7, SYS_WRITE
 swi 0

 mov r0, 0
 mov r7, SYS_EXIT
 swi 0

msg DB "hellow from android", 13, 10
msg_len=$-msg
    

Build:

fasmarm.exe sample.asm sample.out

Copy to device (/data/local/tmp/ is usually available on all devices and emulators):

adb.exe push sample.out /data/local/tmp/

Set read and executable rights for all users:

adb.exe shell chmod 555 /data/local/tmp/sample.out

Run it:

adb.exe shell /data/local/tmp/sample.out
Post 04 Jan 2020, 10:49
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9191
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
is that possible to build one just to restart/reboot phone?

sort of utility,
Post 04 Jan 2020, 11:11
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
You can try the reboot syscall (0x58) but I'm note sure if the default Android user has sufficient priviledges.
Post 04 Jan 2020, 12:16
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9191
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
or simulate a power button click?
Post 04 Jan 2020, 14:13
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
ProMiNick wrote:
Some time ago that was still possible to run elfes.
Modern androids fix that so nothing except dalvic could not be run in android environment. Or thou targeted to android versions that soon became out of date?
I'm sure modern Android versions can run ELF executables. I don't have 32-bit modern Android version and it seems that 64-bit Android can't run 32-bit ELF. And I'm not able to assemble an ARM64 sample with GAS or any other assembler. If you can build a Hello world ARM64 ELF in asm please let me know. If I find time, I will try it with ELF64 built from C source.
Post 12 May 2020, 14:24
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
I managed to build it with GAS finally. It runs on my Nokia 8, Android 9, patch level 1 April 2020.
Code:
.global _start 
_start: 
 mov x0, #1          // 1 = StdOut 
 ldr x1, =helloworld // string to print 
 mov x2, #13         // length of our string 
 mov x8, #64         // Linux write system call
 svc 0               // Call Linux to output the string 

 mov x0, #0          // Use 0 return code 
 mov x8, #93         // Service code 93 terminates 
 svc 0               // Call Linux to terminate 

.data 
 helloworld: .ascii "Hello World!\n"    
Code:
%ANDROID_NDK_PATH%\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\aarch64-linux-android\bin\as.exe -o gas_example64.o gas_example64.s
%ANDROID_NDK_PATH%\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\aarch64-linux-android\bin\ld.exe -o gas_example64 gas_example64.o    
Post 12 May 2020, 16:16
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.