双层巴士小站


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签

  • 搜索

ffmpeg常用命令

发表于 2025-05-15 | 分类于 tutorial
  • 播放yuv文件
    1
    ffplay.exe -f rawvideo -pixel_format yuv420p -video_size 800x480 e:\dump.yuv
    
阅读全文 »

android路由笔记

发表于 2025-03-05 | 分类于 tutorial
  • 查看所有表的所有路由项
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ip -6 route show table all
    fe80::/64 dev dummy0 table dummy0 proto kernel metric 256 pref medium
    default dev dummy0 table dummy0 proto static metric 1024 pref medium
    fe80::/64 dev usb0 table 1013 proto kernel metric 256 pref medium
    local ::1 dev lo table local proto kernel metric 0 pref medium
    local fe80::a89b:eeff:fe83:9a5a dev dummy0 table local proto kernel metric 0 pref medium
    local fe80::b838:10ff:fe12:1d8 dev usb0 table local proto kernel metric 0 pref medium
    multicast ff00::/8 dev dummy0 table local proto kernel metric 256 pref medium
    multicast ff00::/8 dev usb0 table local proto kernel metric 256 pref medium
    
  • 查看指定接口的所有路由项
    1
    2
    3
    4
    ip -6 route show table all dev usb0
    fe80::/64 table 1013 proto kernel metric 256 pref medium
    local fe80::b838:10ff:fe12:1d8 table local proto kernel metric 0 pref medium
    multicast ff00::/8 table local proto kernel metric 256 pref medium
    
  • 查看所有策略
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    ip -6 rule                                                         
    0:	from all lookup local 
    10000:	from all fwmark 0xc0000/0xd0000 lookup legacy_system 
    11000:	from all iif lo oif dummy0 uidrange 0-0 lookup dummy0 
    16000:	from all fwmark 0x10063/0x1ffff iif lo lookup local_network 
    17000:	from all iif lo oif dummy0 lookup dummy0 
    18000:	from all fwmark 0x0/0x10000 lookup legacy_system 
    19000:	from all fwmark 0x0/0x10000 lookup legacy_network 
    20000:	from all fwmark 0x0/0x10000 lookup local_network 
    32000:	from all unreachable
    
  • ndc命令
    ``` 创建网络 ndc network create 999

将接口添加到网络 ndc network interface add 999 usb0

做了上面两个动作后, 就可以在策略表里看到关于usb0的策略了 ip -6 rule
0: from all lookup local 10000: from all fwmark 0xc0000/0xd0000 lookup legacy_system 11000: from all iif lo oif dummy0 uidrange 0-0 lookup dummy0 11000: from all iif lo oif usb0 uidrange 0-0 lookup usb0 16000: from all fwmark 0x10063/0x1ffff iif lo lookup local_network 16000: from all fwmark 0x103e7/0x1ffff iif lo lookup usb0 17000: from all iif lo oif dummy0 lookup dummy0 17000: from all iif lo oif usb0 lookup usb0 18000: from all fwmark 0x0/0x10000 lookup legacy_system 19000: from all fwmark 0x0/0x10000 lookup legacy_network 20000: from all fwmark 0x0/0x10000 lookup local_network 23000: from all fwmark 0x3e7/0x1ffff iif lo lookup usb0 32000: from all unreachable

```

阅读全文 »

django笔记

发表于 2025-02-07 | 分类于 tutorial
  • 安装
    pip install django
    pip install django-simpleui
    pip install mysqlclient

  • 创建项目
    django-admin startproject project1

  • 创建app
    cd project1
    django-admin startapp app1
    django-admin startapp app2

  • 创建迁移
    python manage.py makemigrations
    python manage.py migrate

  • 设置超级用户, 启用admin面板
    python manage.py createsuperuser

阅读全文 »

gva自动代码笔记

发表于 2024-11-19 | 分类于 tutorial

使用gva后台新建pkgTest package, 并根据数据库的test表生成代码后, git diff查看自动添加了哪些代码

  • server/api/v1 目录, 添加了pkgTest目录, 增加了下面的文件
    • enter.go, 创建了pkgTest对应的ApiGroup alt text
    • test_.go, 对应的是test表的增删查改操作, 这里是做一些必要处理, 检查request里的参数后, 调用service目录下对应的接口 alt text
  • server/initialize/gorm_biz.go 文件, 增加test表的AutoMigrate操作 alt text

  • server/initialize/router_biz.go 文件, 增加pkgTest对应的路由 alt text

  • server/model 目录, 添加了pkgTest目录, 增加了下面的文件
    • request/test_.go, 这里是TestSearch结构 alt text

    • test_.go, 这里是test表对应的golang结构 alt text

  • server/router 目录, 添加了pkgTest目录, 增加了下面的文件
    • enter.go, 创建了pkgTest对应的RouterGroup alt text

    • test_.go, 这里创建了pkgTest相关路由, 路由到pkgTest增删查改api的实现 alt text

  • server/router/enter.go 文件, 将上面的pkgTest RouterGroup注册进上级路由 alt text

  • server/service 目录, 添加了pkgTest目录, 增加了下面的文件
    • enter.go, 创建了pkgTest对应的ServiceGroup alt text

    • test_.go, 对test表操作, 实现了具体的增删查改操作 alt text

  • server/service/enter.go 文件, 将上面创建的ServiceGroup注册进上级服务组 alt text

  • web/src/api/ 目录, 增加了pkgTest目录, 包含下面文件
    • test.js, 实现对后端的增删查改请求 alt text
  • web/src/view/ 目录, 增加了pkgTest目录, 包含下面文件
    • test.vue, 实现了前端的test表查看页面
    • testForm.vue, 存疑
阅读全文 »

mysql安装

发表于 2024-11-15 | 分类于 tutorial

安装mysql

1
2
3
4
apt remove --purge *mysql*  
rm -rf /etc/mysql /var/lib/mysql  
apt remove --purge *mariadb*  
apt install mysql-server  

这时候root用户没有密码, mysql -uroot 进入mysql命令行界面
设置密码

1
2
alter user 'root'@'localhost' identified with mysql_native_password by 'root';
flush privileges;
阅读全文 »

海奇固件解包

发表于 2024-07-12 | 分类于 tutorial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
from struct import *

def to_string(b):
    b = b.rstrip(b'\xff')
    b = b.rstrip(b'\x00')
    return b.decode()
    
with open('flash.bin', 'rb') as f:
    data = f.read()

offset = 0
length = len(data)

try:
    os.mkdir('tmp')
except:
    pass

sf = open('tmp/script.txt', 'w')

while offset < length:
    block_id = unpack('>I', data[offset:offset+4])[0]
    block_len = unpack('>I', data[offset+4:offset+8])[0]
    next_block_offset = unpack('>I', data[offset+8:offset+12])[0]
    block_name = to_string(data[offset+0x10:offset+0x20])
    block_ver = to_string(data[offset+0x20:offset+0x30])
    block_time = to_string(data[offset+0x30:offset+0x40])

    print('[File]')
    print('id=0x%08x' % block_id)
    if next_block_offset == 0:
        print('len=0x%X' % block_len)
    else:
        print('offset=0x%X' % next_block_offset)
        print('file=%s' % block_name)
        
    print('name="%s"' % block_name)
    print('ver="%s"' % block_ver)
    print('time="%s"' % block_time)
    
    sf.write('[File]\n')
    sf.write('id=0x%08x\n' % block_id)
    if next_block_offset == 0:
        sf.write('len=0x%X\n' % block_len)
    else:
        sf.write('offset=0x%X\n' % next_block_offset)
        sf.write('file=%s\n' % block_name)
        
    sf.write('name="%s"\n' % block_name)
    sf.write('ver="%s"\n' % block_ver)
    sf.write('time="%s"\n' % block_time)
    
    if next_block_offset == 0:
        break
    
    with open('tmp/' + block_name, 'wb') as f:
        f.write(data[offset+0x80:offset+next_block_offset-0x80])
    
    offset += next_block_offset
    
sf.write('[OutFile]\nout=modify.abs\n')
阅读全文 »

发送raw tcp包

发表于 2024-06-18 | 分类于 tutorial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
struct iphdr {
	uint8_t ihl :4,
		 version:4;
	uint8_t tos;
	uint16_t tot_len;
	uint16_t id;
	uint16_t frag_off;
	uint8_t ttl;
	uint8_t protocol;
	uint16_t check;
	int32_t saddr;
	int32_t daddr;
};

struct tcphdr {
	uint16_t source;
	uint16_t dest;
	uint32_t seq;
	uint32_t ack_seq;
	uint16_t res1:4,
		doff:4,
		fin:1,
		syn:1,
		rst:1,
		psh:1,
		ack:1,
		urg:1,
		ece:1,
		cwr:1;
	uint16_t window;
	uint16_t check;
	uint16_t urg_ptr;
};

struct pseudo_header
{
    u_int32_t source_address;
    u_int32_t dest_address;
    u_int8_t placeholder;
    u_int8_t protocol;
    u_int16_t tcp_length;
};

static uint16_t checksum(uint8_t* buf, size_t size)
{    
    int res = 0;
    uint16_t* ptr = (uint16_t*)buf;
    
    for (int i = 0; i < size / 2; i++) {
        res += ptr[i];
    }
    
    if (size & 1) {
        res += buf[size - 1];
    }
    
    res = (res >> 16) + (res & 0xFFFF);
    res += (res >> 16);
    
    return ~res; 
}

static int send_rst(std::string ip, uint16_t port)
{
    int fd;
    uint8_t buf[128];
    uint8_t psb[128];
    struct pseudo_header psh;
    struct iphdr* iph = (struct iphdr*)buf;
    struct tcphdr* tcph = (struct tcphdr*)(buf + sizeof(struct iphdr));
    struct sockaddr_in dest;
    int val;

    fd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
    if (fd < 0) {
        printf("socket open failed\n");
        return -1;
    }
    
    val = 1;
    setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &val, sizeof(val));
    
    memset(buf, 0, sizeof(buf));

    iph->ihl = sizeof(struct iphdr) >> 2;
    iph->version = 4;
    iph->tos = 0;
    iph->tot_len = htons(sizeof(struct iphdr) + sizeof(struct tcphdr));
    iph->id = htonl(54321);
    iph->frag_off = 0;
    iph->ttl = 255;
    iph->protocol = IPPROTO_TCP;
    iph->saddr = inet_addr("192.168.1.1");
    iph->daddr = inet_addr(ip.c_str());
    iph->check = 0;
    iph->check = checksum((uint8_t*)iph, sizeof(struct iphdr));

    tcph->source = htons(7000);
    tcph->dest = htons(port);
    tcph->seq = 123456789;
    tcph->ack_seq = 0;
    tcph->doff = sizeof(struct tcphdr) >> 2;
    tcph->rst = 1;
    tcph->window = htons(5840);
    tcph->check = 0;
    tcph->urg_ptr = 0;
    
    psh.source_address = iph->saddr;
    psh.dest_address = iph->daddr;
    psh.placeholder = 0;
    psh.protocol = IPPROTO_TCP;
    psh.tcp_length = htons(sizeof(struct tcphdr));
    
    memcpy(psb, &psh, sizeof(struct pseudo_header));
    memcpy(psb + sizeof(struct pseudo_header), tcph, sizeof(struct tcphdr));
    
    tcph->check = checksum(psb, sizeof(struct pseudo_header) + sizeof(struct tcphdr));
     
    dest.sin_family = AF_INET;
    dest.sin_port = tcph->dest;
    dest.sin_addr.s_addr = iph->daddr;

    if (sendto(fd, buf, sizeof(struct iphdr) + sizeof(struct tcphdr), 0, (struct sockaddr*)&dest, sizeof(dest)) < 0) {
        printf("send failed: %s\n", strerror(errno));
    }

    close(fd);
    return 0;
}
阅读全文 »

ats解密加密流

发表于 2024-04-23 | 分类于 tutorial

pair-setup/pair-verify加密的流如果需要在ats里能解码,可以向ff02::01端口4444发送如下内容的一个包 ats收到后就会自动解码对应连接的数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<dict>
	<key>LocalIPAddress</key>
	<string>本机ipv6地址</string>
	<key>LocalPort</key>
	<integer>本机ipv6端口</integer>
	<key>LocalSendsWithReadKey</key>
	<integer>0</integer>
	<key>ReadKey</key>
	<data>
	pair-verify派生得到的read key
	</data>
	<key>RemoteIPAddress</key>
	<string>对端ipv6地址</string>
	<key>RemotePort</key>
	<integer>对端端口</integer>
	<key>WriteKey</key>
	<data>
	pair-verify派生得到的write key
	</data>
	<key>StreamType</key>
	<string>Ctrl</string>
	<key>SessionType</key>
	<string>CP</string>
</dict>
阅读全文 »

tlv解析

发表于 2024-04-10 | 分类于 tutorial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def parse_buf(data, depth):
    format = Struct(
        "length" / Int16ub,
        "tag" / Int16ub,
        "data" / Bytes(this.length - 4),
    )
    while len(data) > 0:   
        pkt = format.parse(data)
        data = data[pkt.length:]
        parse_pkt(pkt, depth)
    
def parse_pkt(pkt, depth):
    if pkt.length == 4:
        print('%s.AddTag(%d);' % ('\t' * depth, pkt.tag))
    elif pkt.length == 5:
        print('%s.AddInt8(%d, %d);' % ('\t' * depth, pkt.tag, int.from_bytes(pkt.data, 'big')))
    elif pkt.length == 6:
        print('%s.AddInt16BE(%d, %d);' % ('\t' * depth, pkt.tag, int.from_bytes(pkt.data, 'big')))
    elif pkt.length == 8:
        print('%s.AddInt32BE(%d, %d);' % ('\t' * depth, pkt.tag, int.from_bytes(pkt.data, 'big')))
    elif pkt.length == 12:
        print('%s.AddInt64BE(%d, %d);' % ('\t' * depth, pkt.tag, int.from_bytes(pkt.data, 'big')))
    elif pkt.tag in [0,1,2]:
        print('------------------------------')
        parse_buf(pkt.data, depth + 1)
    else:
        print('.AddString(%d, %s);' % (pkt.tag, pkt.data.decode('utf8')))
        
def test4():
    data = bytes([
        0x00, 0x06, 0x00, 0x00, 0x04, 0x57,
        0x00, 0x04, 0x00, 0x01
    ])
    
    parse_buf(data, 0)
    
test4()
阅读全文 »

mdnsd组播发送不出的问题

发表于 2024-04-07 | 分类于 tutorial

mdnsd在网络接口up的时候会往该接口发送组播包,发往ff02::fb多播地址的包会有一段时间发不出去 原因是网络接口的地址正处于ipv6的地址重复检测状态,持续1秒左右 禁用重复地址检测的方法

1
echo 0 > /proc/sys/net/ipv6/conf/<interface>/accept_dad
阅读全文 »
1 2
双层巴士

双层巴士

双层巴士小站

17 日志
1 分类
RSS
© 2025 双层巴士
由 Jekyll 强力驱动
主题 - NexT.Pisces