[Tool]File(1) command for Android (ver 5.11)

Search This thread

samveen

Member
Apr 22, 2012
22
18
samveen.in
After wandering around looking for an android build of the file command, I finally went ahead and compiled it myself.

The attached package contains the file binary (v5.11), the libmagic.so shared library, the associated magic files and the build specific files that I needed (over and above the source) to build it. The paths of the files are relative to '/'.

Refs:
source: file website (www_darwinsys_com/file/)
compiling: Native Vim on Android (gdr_geekhood_net/gdrwpl/vim-android.php)

Note: Add the location of libmagic.so to LD_LIBRARY_PATH to get rid of the "CANNOT LINK EXECUTABLE" error. (I use /data/local/lib)
 

Attachments

  • file-5.11-arm-android_8.tar.gz
    238.2 KB · Views: 2,044
Last edited:

royale1223

Senior Member
Oct 31, 2011
468
684
Calicut
After wandering around looking for an android build of the file command, I finally went ahead and compiled it myself.

The attached package contains the file binary (v5.11), the libmagic.so shared library, the associated magic files and the build specific files that I needed (over and above the source) to build it. The paths of the files are relative to '/'.

Refs:
source: file website (www_darwinsys_com/file/)
compiling: Native Vim on Android (gdr_geekhood_net/gdrwpl/vim-android.php)

Note: Add the location of libmagic.so to LD_LIBRARY_PATH to get rid of the "CANNOT LINK EXECUTABLE" error. (I use /data/local/lib)

I followed your instructions and it works perfectly.

Code:
$ echo $LD_LIBRARY_PATH
/data/local/lib:/data/local/lib:/data/local/lib:/system/lib:/vendor/lib
$ file
Usage: file [-bchikLlNnprsvz0] [--apple] [--mime-encoding] [--mime-type]
            [-e testname] [-F separator] [-f namefile] [-m magicfiles] file ...
       file -C [-m magicfiles]
       file [--help]
$ getprop  | grep device
[ro.cm.device]: [jordan]
[ro.product.device]: [umts_jordan]

I have been looking for this for a while. Man!! This post needs some serious attention. Great work.

Sent from my MB525 usiIng XDA
 

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,763
40,417
Halifax
GT-i9250
Google Nexus 4
@osm0sis Sure. I'll add in a statically linked binary, but it'll take a little time (2-3 days).

Any luck? I think it only needs libmagic statically linked to be portable; the other NDK/Bionic stuff can probably stay dynamic to keep the filesize down. I see file 5.17 source is available now too if you wanted to update your builds to the latest. :)
 

Computoncio

Senior Member
May 29, 2012
1,315
3,569
Três Corações - MG - Brasil
Any luck? I think it only needs libmagic statically linked to be portable; the other NDK/Bionic stuff can probably stay dynamic to keep the filesize down. I see file 5.17 source is available now too if you wanted to update your builds to the latest. :)

If you want only the system file type, the workaround i use is this (eval $(/sbin/blkid /dev/block/mmcblk0p11 | /sbin/awk ' { print $3 } '); /sbin/busybox echo $TYPE)

In a script just add a var like this

TYPE=$(eval $(/sbin/blkid /dev/block/mmcblk0p11 | /sbin/awk ' { print $3 } '); /sbin/busybox echo $TYPE) and you will have the FS type in $TYPE.

Phone: Samsung Galaxy SII - GT-I9100
Kernel: Dorimanx kernel v10.43v99-mv3
1st ROM : SlimSaber 4.4.2 Maliv3 by fusionjack build of 20140320 (Online)
2nd ROM :
MODEM: UHMS1
MODS: Partition Fix, Hue Blue v4.4 by Kroz :good:
 

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,763
40,417
Halifax
GT-i9250
Google Nexus 4
If you want only the system file type, the workaround i use is this (eval $(/sbin/blkid /dev/block/mmcblk0p11 | /sbin/awk ' { print $3 } '); /sbin/busybox echo $TYPE)

In a script just add a var like this

TYPE=$(eval $(/sbin/blkid /dev/block/mmcblk0p11 | /sbin/awk ' { print $3 } '); /sbin/busybox echo $TYPE) and you will have the FS type in $TYPE.

Interesting but nope; I need file to determine a filetype. Compressed archives via a script, to be specific.
 

samveen

Member
Apr 22, 2012
22
18
samveen.in
@osm0sis I got the code compiled (both with a dynamic libmagic.so, and libmagic compiled into file) but I need a little more time to compile the magic data (it requires running file on the target device to compile the magic data into a binary datafile). Once I have that figured out (either by compiling it or by creating a script to allow the users to do it themselves, I'll post it all in one go (need one more day).
 

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,763
40,417
Halifax
GT-i9250
Google Nexus 4
@osm0sis I got the code compiled (both with a dynamic libmagic.so, and libmagic compiled into file) but I need a little more time to compile the magic data (it requires running file on the target device to compile the magic data into a binary datafile). Once I have that figured out (either by compiling it or by creating a script to allow the users to do it themselves, I'll post it all in one go (need one more day).

Awesome! Thanks so much. The magic file isn't terribly important since you can grab one a lot of places and specify it with the -m parameter; keeps the file size down too if you were thinking of including it in the binary somehow! :)
 
Last edited:

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,763
40,417
Halifax
GT-i9250
Google Nexus 4
Alright. I just wanted to thank you again for your work but I managed to make a static native compile (~440kb) of file-5.17 using my N7 and a kbox build environment I set up. It's available in my ARM Android Image Kitchen linked in my sig. Cheers! :)
 

amit.bagaria

Senior Member
May 11, 2011
249
1,056
Mumbai
OnePlus 5T
Alright. I just wanted to thank you again for your work but I managed to make a static native compile (~440kb) of file-5.17 using my N7 and a kbox build environment I set up. It's available in my ARM Android Image Kitchen linked in my sig. Cheers! :)
@osm0sis - Can you please share how did you static compile this? I have setup the Ubuntu 13.10 image on Android using Complete Linux Installer (with all the necessary build tools setup).

I am able to compile this, but it's linking the shared library "libmagic.la".
 
Last edited:

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,763
40,417
Halifax
GT-i9250
Google Nexus 4
@osm0sis - Can you please share how did you static compile this? I have setup the Ubuntu 13.10 image on Android using Complete Linux Installer (with all the necessary build tools setup).

I am able to compile this, but it's linking the shared library "libmagic.la".

Haven't tried it using a full Linux image on Android, just made it native compile in KBox2 on my N7'13 for awhile by editing in the gettext functions it was complaining about, and have since moved on to cross-compiling on my Windows 7 desktop in Cygwin using the NDK. There were still a few tricks to getting it to be a true static compile. It's all linked in my post here:

http://xdaforums.com/showthread.php?p=54510825

My latest compile included in my AIK-mobile package is file 5.20. :good:
 
Last edited:

Restl3ss

Senior Member
Aug 3, 2013
633
1,078
Fort Mcmurray
I don't suppose you could do a quick compile with the -fPIE flag? Trying to use this on 5.0 + and don't want to patch my linker.
Tried to compile it myself (it sort-of worked, file --version is operational) but when I try to actually use it for something my terminal borks out and switches to some weird font after about 20 warnings. (configure also seems to be using the -rpath flag apparently, linker complains about it) hmm



EDIT: I've got it working after some trial and error. If anyone requests I'll post it

EDIT 2: android 6.0's linker seems less forgiving than 5.0/5.1, need to compile without -rpath (so no just using ./configure) will keep posted
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 6
    After wandering around looking for an android build of the file command, I finally went ahead and compiled it myself.

    The attached package contains the file binary (v5.11), the libmagic.so shared library, the associated magic files and the build specific files that I needed (over and above the source) to build it. The paths of the files are relative to '/'.

    Refs:
    source: file website (www_darwinsys_com/file/)
    compiling: Native Vim on Android (gdr_geekhood_net/gdrwpl/vim-android.php)

    Note: Add the location of libmagic.so to LD_LIBRARY_PATH to get rid of the "CANNOT LINK EXECUTABLE" error. (I use /data/local/lib)
    2
    @osm0sis I got the code compiled (both with a dynamic libmagic.so, and libmagic compiled into file) but I need a little more time to compile the magic data (it requires running file on the target device to compile the magic data into a binary datafile). Once I have that figured out (either by compiling it or by creating a script to allow the users to do it themselves, I'll post it all in one go (need one more day).
    2
    @osm0sis - Can you please share how did you static compile this? I have setup the Ubuntu 13.10 image on Android using Complete Linux Installer (with all the necessary build tools setup).

    I am able to compile this, but it's linking the shared library "libmagic.la".

    Haven't tried it using a full Linux image on Android, just made it native compile in KBox2 on my N7'13 for awhile by editing in the gettext functions it was complaining about, and have since moved on to cross-compiling on my Windows 7 desktop in Cygwin using the NDK. There were still a few tricks to getting it to be a true static compile. It's all linked in my post here:

    http://xdaforums.com/showthread.php?p=54510825

    My latest compile included in my AIK-mobile package is file 5.20. :good:
    1
    Compiled a dynamically linked library and associated binary instead of the monolithic binary built earlier.
    1
    @samveen Any chance you could compile it with libmagic statically linked again to make it portable? Thanks for your time. :)

    @osm0sis Sure. I'll add in a statically linked binary, but it'll take a little time (2-3 days).