Android安装Busybox
这个只为开发者用,一般人别用。
最新的busybox已经足够强大,强大到不可想像了添加了很多命令,对开发者来说是极为好用的。
如果你是个拿来主义,把这个下载了,在system分区解压就好了。toolbox中特有的命令还是会保留的,相同的命令会替换。我使用的是armv4指令集的交叉工具链编译的,目的就是尽可能的通用。如果你的Android设备不能用,那么就得自己编译了。(编译好的:http://download.csdn.net/detail/kangear/7564291,将压缩包放到Android手机中,进行第7步解压操作就好了!)
编译一个busybox,前提你装好了交叉工具链,以下就是编译脚本。
#!/bin/sh
#@author : kangear
#@function: build busybox static.
# 1.download source
wget http://www.busybox.net/downloads/busybox-1.22.1.tar.bz2 -O busybox.tar.bz2 || exit 1
# 2.uncompress and cd
tar xvjf busybox.tar.bz2 && cd busybox-1.22.1 || exit 1
# 3.config
make defconfig CROSS_COMPILE=arm-linux- || exit 1
# 4.modify busybox.links
make CROSS_COMPILE=arm-linux- LDFLAGS=--static install || exit 1
rm _install -rf || exit 1
# 4.1 delect linuxrc line
sed -i '/linuxrc/d' busybox.links || exit 1
# 4.2 sbin usr/bin usr/sbin => bin
sed -i 's/usr\/sbin/bin/' busybox.links || exit 1
sed -i 's/usr\/bin/bin/' busybox.links || exit 1
sed -i 's/sbin/bin/' busybox.links || exit 1
# 5. build & install
make CROSS_COMPILE=arm-linux- LDFLAGS=--static install || exit 1
# 6. tar cvzf
# adb push /system/bin & tar xvzf bin.tar.gz
tar cvzf busybox_bin.tar.gz -C _install/ bin || exit 1
# 7. install into Android
# 7.1 将/system分区进行remount成可写的
# 7.2 将busybox_bin.tar.gz放置到Android文件系统中任何位置
# 7.3 tar xvzf busybox_bin.tar.gz -C /system/
包含的命令:
root@android:/ # busybox
BusyBox v1.22.1 (2014-06-27 15:14:59 CST) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2012.
Licensed under GPLv2. See source distribution for detailed
copyright notices.
Usage: busybox [function [arguments]...]
or: busybox --list[-full]
or: busybox --install [-s] [DIR]
or: function [arguments]...
BusyBox is a multi-call binary that combines many common Unix
utilities into a single executable. Most people will create a
link to busybox for each function they wish to use and BusyBox
will act like whatever it was invoked as.
Currently defined functions:
[, [[, acpid, add-shell, addgroup, adduser, adjtimex, arp, arping, ash,
awk, base64, basename, beep, blkid, blockdev, bootchartd, brctl,
bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod,
chown, chpasswd, chpst, chroot, chrt, chvt, cksum, clear, cmp, comm,
conspy, cp, cpio, crond, crontab, cryptpw, cttyhack, cut, date, dc, dd,
deallocvt, delgroup, deluser, depmod, devmem, df, dhcprelay, diff,
dirname, dmesg, dnsd, dnsdomainname, dos2unix, du, dumpkmap,
dumpleases, echo, ed, egrep, eject, env, envdir, envuidgid, ether-wake,
expand, expr, fakeidentd, false, fbset, fbsplash, fdflush, fdformat,
fdisk, fgconsole, fgrep, find, findfs, flock, fold, free, freeramdisk,
fsck, fsck.minix, fstrim, fsync, ftpd, ftpget, ftpput, fuser, getopt,
getty, grep, groups, gunzip, gzip, halt, hd, hdparm, head, hexdump,
hostid, hostname, httpd, hush, hwclock, id, ifconfig, ifdown,
ifenslave, ifplugd, ifup, inetd, init, insmod, install, ionice, iostat,
ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel,
kbd_mode, kill, killall, killall5, klogd, last, less, linux32, linux64,
linuxrc, ln, loadfont, loadkmap, logger, login, logname, logread,
losetup, lpd, lpq, lpr, ls, lsattr, lsmod, lsof, lspci, lsusb, lzcat,
lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mdev, mesg,
microcom, mkdir, mkdosfs, mke2fs, mkfifo, mkfs.ext2, mkfs.minix,
mkfs.vfat, mknod, mkpasswd, mkswap, mktemp, modinfo, modprobe, more,
mount, mountpoint, mpstat, mt, mv, nameif, nanddump, nandwrite,
nbd-client, nc, netstat, nice, nmeter, nohup, nslookup, ntpd, od,
openvt, passwd, patch, pgrep, pidof, ping, ping6, pipe_progress,
pivot_root, pkill, pmap, popmaildir, poweroff, powertop, printenv,
printf, ps, pscan, pstree, pwd, pwdx, raidautorun, rdate, rdev,
readahead, readlink, readprofile, realpath, reboot, reformime,
remove-shell, renice, reset, resize, rev, rm, rmdir, rmmod, route, rpm,
rpm2cpio, rtcwake, run-parts, runlevel, runsv, runsvdir, rx, script,
scriptreplay, sed, sendmail, seq, setarch, setconsole, setfont,
setkeycodes, setlogcons, setserial, setsid, setuidgid, sh, sha1sum,
sha256sum, sha3sum, sha512sum, showkey, slattach, sleep, smemcap,
softlimit, sort, split, start-stop-daemon, stat, strings, stty, su,
sulogin, sum, sv, svlogd, swapoff, swapon, switch_root, sync, sysctl,
syslogd, tac, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp,
tftpd, time, timeout, top, touch, tr, traceroute, traceroute6, true,
tty, ttysize, tunctl, ubiattach, ubidetach, ubimkvol, ubirmvol,
ubirsvol, ubiupdatevol, udhcpc, udhcpd, udpsvd, umount, uname,
unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, users,
usleep, uudecode, uuencode, vconfig, vi, vlock, volname, wall, watch,
watchdog, wc, wget, which, who, whoami, whois, xargs, xz, xzcat, yes,
zcat, zcip
root@android:/ #
另:关于《busybox无法ping域名的解决办法 》可以尝试如下实现busybox 中的ping:
#include
#include
#include
#include
#include
#include
#include
#include
#define oops(msg) { perror(msg); exit(1);}
void fillip(char* buffer, const char* ip);
char* name2ip(const char* name);
/**
* * head len: 12
* * query: ? + 4
* * total: strlen(query.buffer) + 16
* */
typedef struct{
u_short txid;
u_short flag;
u_short question;
u_short answer;
u_short authority;
u_short additional;
char buffer[256];
struct {
u_short type;
u_short cls;
}query;
}dns_req;
/** length of resp: 12 */
typedef struct{
u_short txid;
u_short flag;
u_short question;
u_short answer;
u_short authority;
u_short addtional;
char buffer[1024];
struct{
u_short name;
u_short type;
u_short cls;
u_short live_l;
u_short live_h;
u_short len;
struct in_addr addr;
}resp;
}dns_res;
int main()
{
char* p = name2ip("www.baidu.com");
printf("ip is:%s\n", p);
return 0;
}
char* name2ip(const char *node){
struct sockaddr_in dns;
dns_req req;
dns_res res;
int sockid, len, index;
char* dnsip = "61.139.2.69";
//char* dnsip = "202.114.215.73";
sockid = socket(PF_INET, SOCK_DGRAM, 0);
if(sockid == -1)
oops("socket");
memset((void*)&dns, 0, sizeof(dns));
dns.sin_family = AF_INET;
dns.sin_port = htons(53);
dns.sin_addr.s_addr = inet_addr(dnsip);
memset((void*)&req, 0, sizeof(req));
req.txid = htons(0x4419);
req.flag = htons(0x0100);
req.question = htons(1);
fillip(req.buffer,node);
req.query.type=htons(1);
req.query.cls=htons(1);
memcpy(req.buffer+strlen(req.buffer)+1, (void*)(&req.query), sizeof(req.query));
sendto(sockid, (void*)&req, strlen(req.buffer)+17, 0,
(struct sockaddr*)&dns, sizeof(dns));
recvfrom(sockid, (void*)&res, sizeof(res), 0,
(struct sockaddr*)&dns, &len);
index = strlen(res.buffer)+5;
while(1){
memcpy((void*)&(res.resp), res.buffer+index, 12);
if(ntohs(res.resp.type)==1){
memcpy((void*)&(res.resp.addr), res.buffer+index+12, 4);
break;
}
index += ntohs(res.resp.len) + 12;
}
return inet_ntoa(res.resp.addr);
}
void fillip(char* buffer, const char* ip){
int i,j=0;
for(i = 0; ip[i] != 0; i ++){
if(ip[i] != '.'){
buffer[i+1] = ip[i];
}
else{
buffer[j] = i - j;
j = i + 1;
}
}
buffer[j] = i - j;
}
先获取地区dns或者路由器上的dns或者getprop中的dns,思路先留在这里,以后有时候再完善。
/ # getprop | grep dns
[dhcp.eth0.dns1]: [192.168.100.1]
[dhcp.eth0.dns2]: []
[dhcp.eth0.dns3]: []
[dhcp.eth0.dns4]: []
[dhcp.wlan0.dns1]: [192.168.2.1]
[dhcp.wlan0.dns2]: []
[dhcp.wlan0.dns3]: []
[dhcp.wlan0.dns4]: []
[net.change]: [net.eth0.dns2]
[net.dns1]: [192.168.100.1]
[net.dnschange]: [4]
[net.eth0.dns1]: [49.0.0.0]
[net.eth0.dns2]: []
[net.wlan0.dns1]: [49.0.0.0]
[net.wlan0.dns2]: []