生成指定大小填充指定内容(如0xFF)的bash命令行/修改指定位置的内容
dd if=/dev/zero bs=1 count=$((0x3800)) | sed 's/\x00/\xFF/g' > 1.bin
dd if=/dev/zero bs=1 count=$((0x3800)) | tr '\000' '\377' > 2.bin
0x3800 是文件大小, xFF / 377 是指定填充的字节。
上面两种方法都可以,二选一, 我喜欢前面的。
dd if=out.bin of=dest.bin seek=0 conv=notrunc
out.bin 文件叠加到 dest.bin
echo -e '\x50\x52' | dd of=dest.bin bs=1 seek=$((0x3780)) count=2 conv=notrunc
修改0x3780位置2字节为 0x50, 0x52
离线
能满足需求就好
主要是 winhex/ultaredit 我都没有找到这个功能, 不知道是本来就没有,还是眼拙。
离线
楼主这shell玩得真是6666
离线
主要是 winhex/ultaredit 我都没有找到这个功能, 不知道是本来就没有,还是眼拙。
WinHex可以先新建一个指定大小的空白文件,再用Edit->Fill Block填充十六进制数字。
离线
WinHex可以先新建一个指定大小的空白文件,再用Edit->Fill Block填充十六进制数字。
感谢大佬指教, 有空我试一试。
再来一个, 查看linux可执行程序依赖哪些so文件:
objdump -x output/target/usr/sbin/dnsmasq |grep NEEDED
NEEDED libc.so.0
离线
buildroot 重新生成 output/target 文件系统:
rm output/target -rf
find output/build/ |grep \\.stamp_target_installed$ | xargs rm -rf
make
buildroot 重新编译:
find output/build/ |grep \\.stamp_ | xargs rm -rf
make
离线
Linux下Mount TF卡Image文件: https://whycan.cn/t_4401.html
fdisk -l whatever.img
Device Boot Start End Blocks Id System
whatever.img1 8192 122879 57344 c W95 FAT32 (LBA)
whatever.img2 122880 5785599 2831360 83 Linux
计算偏移:
1st partition 512 * 8192 = 4194304
2nd partition 512 * 122880 = 62914560
挂载:
mount -v -o offset=4194304 -t vfat whatever.img /mnt/img/one
mount -v -o offset=62914560 -t ext4 whatever.img /mnt/img/two
离线
linux下监控网卡流量的shell脚本: https://blog.51cto.com/erikxue/1588802
#!/bin/sh
usage() {
echo "Useage : $0"
echo "eg. sh $0 eth0 2"
exit 1
}
if [ $# -lt 2 ]
then
usage
fi
eth=$1
timer=$2
in_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
out_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')
while true
do
sleep ${timer}
in=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
out=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')
dif_in=$(((in-in_old)/timer))
dif_in=$((dif_in/1024))
dif_out=$(((out-out_old)/timer))
dif_out=$((dif_out/1024))
ct=$(date +"%F %H:%M:%S")
echo "${ct} -- IN: ${dif_in} KByte/s OUT: ${dif_out} KByte/s"
in_old=${in}
out_old=${out}
done
exit 0
测试运行:
# ./network_speed.sh wlan0 2
1970-01-01 00:31:23 -- IN: 0 KByte/s OUT: 0 KByte/s
1970-01-01 00:31:25 -- IN: 6 KByte/s OUT: 5 KByte/s
1970-01-01 00:31:27 -- IN: 2 KByte/s OUT: 0 KByte/s
1970-01-01 00:31:30 -- IN: 3 KByte/s OUT: 1 KByte/s
1970-01-01 00:31:32 -- IN: 19 KByte/s OUT: 20 KByte/s
1970-01-01 00:31:34 -- IN: 14 KByte/s OUT: 10 KByte/s
离线
C代码监控网络状态 (network interface create/delete/up/down events)
netlink_test.c:
#include <asm/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <net/if.h>
#include <netinet/in.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#define MYPROTO NETLINK_ROUTE
#define MYMGRP RTMGRP_IPV4_ROUTE
int open_netlink()
{
int sock = socket(AF_NETLINK,SOCK_RAW,MYPROTO);
struct sockaddr_nl addr;
memset((void *)&addr, 0, sizeof(addr));
if (sock<0)
return sock;
addr.nl_family = AF_NETLINK;
addr.nl_pid = getpid();
addr.nl_groups = RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR;
// addr.nl_groups = RTMGRP_LINK;
if (bind(sock,(struct sockaddr *)&addr,sizeof(addr))<0)
return -1;
return sock;
}
int read_event(int sockint, int (*msg_handler)(struct sockaddr_nl *,
struct nlmsghdr *))
{
int status;
int ret = 0;
char buf[4096];
struct iovec iov = { buf, sizeof buf };
struct sockaddr_nl snl;
struct msghdr msg = { (void*)&snl, sizeof snl, &iov, 1, NULL, 0, 0};
struct nlmsghdr *h;
status = recvmsg(sockint, &msg, 0);
if(status < 0)
{
/* Socket non-blocking so bail out once we have read everything */
if (errno == EWOULDBLOCK || errno == EAGAIN)
return ret;
/* Anything else is an error */
printf("read_netlink: Error recvmsg: %d\n", status);
perror("read_netlink: Error: ");
return status;
}
if(status == 0)
{
printf("read_netlink: EOF\n");
}
/* We need to handle more than one message per 'recvmsg' */
for(h = (struct nlmsghdr *) buf; NLMSG_OK (h, (unsigned int)status);
h = NLMSG_NEXT (h, status))
{
/* Finish reading */
if (h->nlmsg_type == NLMSG_DONE)
return ret;
/* Message is some kind of error */
if (h->nlmsg_type == NLMSG_ERROR)
{
printf("read_netlink: Message is an error - decode TBD\n");
return -1; // Error
}
/* Call message handler */
if(msg_handler)
{
ret = (*msg_handler)(&snl, h);
if(ret < 0)
{
printf("read_netlink: Message hander error %d\n", ret);
return ret;
}
}
else
{
printf("read_netlink: Error NULL message handler\n");
return -1;
}
}
return ret;
}
static int netlink_link_state(struct sockaddr_nl *nl, struct nlmsghdr *msg)
{
int len;
struct ifinfomsg *ifi;
nl = nl;
ifi = NLMSG_DATA(msg);
printf("netlink_link_state: Link %s\n",
(ifi->ifi_flags & IFF_RUNNING)?"Up":"Down");
// printf("netlink_link_state: family: %d\n", ifi->ifi_family);
// if(ifi->ifi_family == AF_INET)
// {
// printf("Link index: %d Flags: (0x%x) ",
// ifi->ifi_index, ifi->ifi_flags);
// if(ifi->ifi_flags & IFF_UP)
// printf("IFF_UP ");
// if(ifi->ifi_flags & IFF_BROADCAST)
// printf("IFF_BROADCAST ");
// if(ifi->ifi_flags & IFF_DEBUG)
// printf("IFF_DEBUG ");
// if(ifi->ifi_flags & IFF_LOOPBACK)
// printf("IFF_LOOPBACK ");
// if(ifi->ifi_flags & IFF_POINTOPOINT)
// printf("IFF_POINTOPOINT ");
// if(ifi->ifi_flags & IFF_NOTRAILERS)
// printf("IFF_NOTRAILERS ");
// if(ifi->ifi_flags & IFF_RUNNING)
// printf("IFF_RUNNING ");
// if(ifi->ifi_flags & IFF_NOARP)
// printf("IFF_NOARP ");
// if(ifi->ifi_flags & IFF_PROMISC)
// printf("IFF_PROMISC ");
// if(ifi->ifi_flags & IFF_ALLMULTI)
// printf("IFF_ALLMULTI ");
// if(ifi->ifi_flags & IFF_MASTER)
// printf("IFF_MASTER ");
// if(ifi->ifi_flags & IFF_SLAVE)
// printf("IFF_SLAVE ");
// if(ifi->ifi_flags & IFF_MULTICAST)
// printf("IFF_MULTICAST ");
// if(ifi->ifi_flags & IFF_PORTSEL)
// printf("IFF_PORTSEL ");
// if(ifi->ifi_flags & IFF_AUTOMEDIA)
// printf("IFF_AUTOMEDIA ");
// printf("\n");
// }
return 0;
}
static int msg_handler(struct sockaddr_nl *nl, struct nlmsghdr *msg)
{
switch (msg->nlmsg_type)
{
case RTM_NEWADDR:
printf("msg_handler: RTM_NEWADDR\n");
break;
case RTM_DELADDR:
printf("msg_handler: RTM_DELADDR\n");
break;
case RTM_NEWROUTE:
printf("msg_handler: RTM_NEWROUTE\n");
break;
case RTM_DELROUTE:
printf("msg_handler: RTM_DELROUTE\n");
break;
case RTM_NEWLINK:
printf("msg_handler: RTM_NEWLINK\n");
netlink_link_state(nl, msg);
break;
case RTM_DELLINK:
printf("msg_handler: RTM_DELLINK\n");
break;
default:
printf("msg_handler: Unknown netlink nlmsg_type %d\n",
msg->nlmsg_type);
break;
}
return 0;
}
int main(int argc, char *argv[])
{
int nls = open_netlink();
printf("Started watching:\n");
if (nls<0) {
printf("Open Error!");
}
while (1)
read_event(nls, msg_handler);
return 0;
}
https://www.mail-archive.com/davinci-linux-open-source@linux.davincidsp.com/msg05405/netlink_test.c
离线