Let's try to figure out how to do one for ourselves...
Always a good exercise
root@kindle:/>
readelf -h /mnt/us/usr/bin/perl
Quote:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x9748
Start of program headers: 52 (bytes into file)
Start of section headers: 1666100 (bytes into file)
Flags: 0x4000002, has entry point, Version4 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 30
Section header string table index: 27
|
root@kindle:/> perl -V
Spoiler:
Quote:
Summary of my perl5 (revision undef undef) configuration:
Platform:
osname=linux, osvers=unknown, archname=arm-unknown-linux-gnueabi
uname='unknown'
config_args='undef'
hint=undef, useposix=true, d_sigaction=undef
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='/home/you/BLDS/buildroot/host/usr/bin/arm-none-linux-gnueabi-gcc', ccflags =' -pipe -O0 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64',
optimize=' -pipe -O0 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64',
cppflags='undef'
ccversion='undef', gccversion='undef', gccosandvers='undef'
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=undef, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='undef', lseeksize=4
alignbytes=4, prototype=undef
Linker and Libraries:
ld='undef', ldflags ='undef'
libpth=undef
libs=undef
perllibs=undef
libc=undef, so=undef, useshrplib=false, libperl=undef
gnulibc_version='undef'
Dynamic Linking:
dlsrc=undef, dlext=undef, d_dlsymun=undef, ccdlflags='undef'
cccdlflags='undef', lddlflags='undef'
Characteristics of this binary (from libperl):
Compile-time options: PERL_DONT_CREATE_GVSV PERL_USES_PL_PIDSTATUS
PERL_USE_SAFE_PUTENV USE_LARGE_FILES USE_PERLIO
USE_PERL_ATOF
Built under linux
Compiled at Aug 21 2012 00:16:18
@INC:
/mnt/us/usr/lib/perl5/5.12.4/arm-unknown-linux-gnueabi
/mnt/us/usr/lib/perl5/5.12.4
/usr/lib
/lib
/mnt/us/usr/lib
/mnt/us/lib
/mnt/us/usr/lib/perl5/5.12.4/arm-unknown-linux-gnueabi
/usr/lib/perl5/5.12.4
/usr/lib/perl5/5.12.4/arm-unknown-linux-gnueabi
/usr/lib/perl5/5.12.4
.
|
so given that information and the reference from kernel org:
Code:
To actually register a new binary type, you have to set up a string looking like
:name:type:offset:magic:mask:interpreter:flags (where you can choose the ':' upon
your needs) and echo it to [/mnt/us]/proc/sys/fs/binfmt_misc/register.
Here is what the fields mean:
- 'name' is an identifier string. A new /proc file will be created with this
name below /proc/sys/fs/binfmt_misc
- 'type' is the type of recognition. Give 'M' for magic and 'E' for extension.
- 'offset' is the offset of the magic/mask in the file, counted in bytes. This
defaults to 0 if you omit it (i.e. you write ':name:type::magic...')
- 'magic' is the byte sequence binfmt_misc is matching for. The magic string
may contain hex-encoded characters like \x0a or \xA4. In a shell environment
you will have to write \\x0a to prevent the shell from eating your \.
If you chose filename extension matching, this is the extension to be
recognised (without the '.', the \x0a specials are not allowed). Extension
matching is case sensitive!
- 'mask' is an (optional, defaults to all 0xff) mask. You can mask out some
bits from matching by supplying a string like magic and as long as magic.
The mask is anded with the byte sequence of the file.
- 'interpreter' is the program that should be invoked with the binary as first
argument (specify the full path)
- 'flags' is an optional field that controls several aspects of the invocation
of the interpreter.
so we want to:
Code:
echo ':perl:M::\x7fELF\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00::/mnt/us/usr/bin/perl:' > /mnt/us/proc/sys/fs/binfmt_misc/register
Code:
(or echo ':perl:E::pl::/mnt/us/usr/bin/perl:'>blah)
root@kindle:script>
nano -w hello.pl
#!/mnt/us/usr/bin/perl
print "Hello world!\n";
save it.
root@kindle:script>
./hello.pl
Hello world!
Seems to be a worker?
great.
Next step... getting this to help us load our 300 odd applications from Buildroot without having to write a script for each.
TBC