flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > hello world using fasm (arm) for android

Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 12877
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 09 May 2014, 06:47
if there are a guide on, how to do hello world using fasm (arm) for android, maybe kinda cool,
Post 09 May 2014, 06:47
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 31 May 2014, 07:46
sleepsleep wrote:
if there are a guide on, how to do hello world using fasm (arm) for android, maybe kinda cool,


Compile with FASMARM (1.71.13)

Code:
        format ELF executable
        entry start

        segment readable executable

start:
        mov     r0, 1
        mov     r1, hello
        mov     r2, len
        mov     r7, 4 ; sys_write
        svc     0
    
        mov     r0, 1
        mov     r7, 1 ; sys_exit
        svc     0

hello:
        db      'Hello world android',10
len  =  $-hello 
    


Using adb.exe
Code:
adb push hello_world /sbin/hello_world
adb shell chmod 777 /sbin/hello_world
adb shell /sbin/hello_world
    


Above code can also be included in an app and executed at run time.

NOTE: I have a rooted phone so I'm able to throw stuff in that directory.
Post 31 May 2014, 07:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 31 May 2014, 08:07
To make the code a bit more flexible you can do this:
Code:
;...
adr r1,hello
;...    
Post 31 May 2014, 08:07
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 31 May 2014, 08:24
Oh. Lol, after banging my head I thought you'd moved it here.

And yup,

mov r1, hello
ldr r1, [hello]
adr r1, hello
Post 31 May 2014, 08:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 31 May 2014, 08:26
ldr won't do it for you unless you put a pointer there.
Post 31 May 2014, 08:26
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 31 May 2014, 11:38
Note that the reason I suggest using adr instead of mov is because by default fasmarm will use all available instructions from all architecture versions. So the mov will use the v7/T2 wide encoding to create "movw r1,0x8074". Whereas using adr will encode "add r1,r15,0x14" which is relocatable.

BTW: It is also advisable to use the processor and coprocessor directives to tell fasmarm which instructions are available. Without these you may get unavailable encodings for your particular CPU.
Post 31 May 2014, 11:38
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12877
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 31 May 2014, 17:21
ok, this is cool, and i wanna say thank you first to typedef.
Post 31 May 2014, 17:21
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1392
Location: Piraeus, Greece
Picnic 01 Feb 2015, 11:54
Hi all,

I have tested typedef's example using fasmarm and adb.exe as suggested above (day 1 in arm).
Then i try a string copy, but the code outputs nothing.

Code:
 format ELF executable
 entry start 

 segment readable executable 

start:
 mov    r1, src
 mov    r0, dest

strcopy: 
 ldrb   r2, [r1], 1
 strb   r2, [r0], 1
 tst    r2, r2
 bne    strcopy

 mov     r0, 1
 mov     r1, dest
 mov     r2, 5
 mov     r7, 4   ; write syscall
 svc     0

 mov    r0, 0  ; exit
 mov    r7, 1
 svc    0

 src    db "12345",0
 dest   db "00000",0 
    
Post 01 Feb 2015, 11:54
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1392
Location: Piraeus, Greece
Picnic 01 Feb 2015, 19:22
I would really appreciate a hint.
Post 01 Feb 2015, 19:22
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 02 Feb 2015, 00:45
Which system are you using? Perhaps "svc 0", or the parameters you are passing, or the file format, is the problem because the copy code appears to be fine. Also the the note above about using "adr" instead of "mov" to get your code relocatable. And use the "processor" directive to avoid any silliness with incompatible CPUs.
Post 02 Feb 2015, 00:45
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1392
Location: Piraeus, Greece
Picnic 02 Feb 2015, 20:09
Hi revolution,

I have windows xp connected with my android phone (CPU:ARM Cortex A7, GPU:ARM Mali-400 MP1) via usb cable. typedef's code along with few other tiny scripts i wrote are working, but the code above outputs "Segmentation fault" at my phone's terminal window. How to workaround this?
Post 02 Feb 2015, 20:09
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 03 Feb 2015, 01:07
Did you try with ADR? Did you use the proper PROCESSOR setting?
Post 03 Feb 2015, 01:07
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1392
Location: Piraeus, Greece
Picnic 03 Feb 2015, 07:19
I used adr but the error remains. What can be the correct settings in my case, can you show me a processor setting example ?
I noticed that whenever i use strb i am getting a "Segmentation fault".

p.s. I appreciate the assistance.
Post 03 Feb 2015, 07:19
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 03 Feb 2015, 07:24
Perhaps the Android system enforces the read only attribute you used?
Code:
segment readable executable    
Post 03 Feb 2015, 07:24
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1392
Location: Piraeus, Greece
Picnic 03 Feb 2015, 17:04
Golden reply, thank you. Smile

I struggled enough and lost my temper for a while.
Post 03 Feb 2015, 17:04
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.