1.linux运行sh脚本时出现“/bin/sh^M: bad interpreter”告警信息
原因:windows下的文件是dos格式,即每一行结尾以\r\n来标识,而linux下的文件是unix格式,行尾则以\n来标识
查看文件格式有三种方法:
cat -A <filename>,如果输出结果中行末尾是^M$,则是dos格式,如果行末尾只是$,则是unix格式。
vim <filename>,编辑文件,执行“:set ff”,若执行结果为fileformat=dos则为dos格式,若执行结果为fileformat=unix则为unix格式。
od -t x1 <filename>,以16进制查看文件,若输出结果中存在“0d 0a”则为dos格式,如果只有“0a”则为unix格式。其中“0d”即为回车符“\r”,“0a”即为换行符“\n”。
修改文件格式有三种方式:
sed -i "s/\r//" <filename>或sed -i "s/^M//" <filename>,直接将回车符替换为空字符串。
vim <filename>,编辑文件,执行“: set ff=unix”,将文件设置为unix格式,然后执行“:wq”,保存退出。
dos2unix <filename>或busybox dos2unix <filename>,如果提示command not found,可以使用前两种方法
2.linux下使用make命令编译代码时出现如下告警,
make: warning: Clock skew detected. Your build may be incomplete
原因:检测到时钟偏差了,主要是两个设备系统之间的时间上存在差距
解决方案:
find ./ -type f |xargs touch
将所有文件都重新touch一遍,更新到本地系统的时间,再make就没问题了
3.makefile编译报错:
错误信息:undefined reference to symbol 'pthread_rwlock_rdlock'
解决方法:加上-lpthread
错误信息:undefined reference to 'dlopen'
解决方法:加上-ldl
4.linux下运行编译生成的文件时,出现告警
error while loading shared libraries: libXXXXXXX.so.1: cannot open shared object file: No such file or directory
原因:linux下运行时指定动态库
执行指令:export LD_LIBRARY_PATH=<path>
5.端口号被占用
使用lsof -i:端口号 查看该端口号是否被占用
使用ps -ef | grep PID 查看哪个进程在使用该端口号
kill该进程即可
6.openssl s_server 在shell脚本中与client进程同时启动时,会自动关闭socket
需要加上-www参数
7.MPA的汇编编译需要nasm编译器
安装步骤:
1. ./configure
2. make
3. make install
8.wireshare抓包解密:
在使用openssl建链抓包时,加入命令:-keylogfile,可以将建链的密钥保存下来,如:-keylogfile=/xxxxxx/xxxx/key.log
然后在wireshare-首选项-protocols-Tls中,在(Pre)-Master-Secret log filename一栏将密钥文件填入即可
9.gdb出现动态库链接不上的情况
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr1/w30016506/source_demo/HiTLS_Demo/HiTLS_Binary/adaptor_deps:/usr1/w30016506/source_demo/HiTLS_Demo/platform/Huawei_Secure_C/lib
10.openssl编译
#!/bin/bash
# 若指令回传不等于0,则立即退出shell
set -e
rm -rf ./output
#./config --prefix=/root/wxz/openssl/output/bin --openssldir=/root/wxz/openssl/output/ssl --debug -g -d no-shared sctp no-tests # 指定目录编译
./config --debug -g -d no-shared sctp no-tests # 默认目录编译
make clean
make -j16
make install
# cp -r ./data_files ./output/bin/
11.linux挂代理
export http_proxy="http://w30016506:li13229930518.@proxy.huawei.com:8080/"
export https_proxy="http://w30016506:li13229930518.@proxy.huawei.com:8080/"
代理取消
export http_proxy=
export https_proxy=
12.查看头文件是由哪个rpm提供的
ysd search xx.h -r xx.repo
13.批量修改文件权限
chmod -R 777 [FolderName]
14.在c++代码中使用c代码
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
15.查询.so的符号
objdump -tT libName.so | grep symbel symbolName
nm -D libName.so | grep symbel symbolName
16.dlsym找不到符号
dlsym用于动态查找simpo工具生成的桩文件中的符号,查找失败可能有如下原因,请逐一排查:
1、桩文件未编译进去;
2、桩文件编译进去了,但编译时未用 -rdynamic 选项,导致符号未加到动态符号表中
3、桩文件编译在so文件中,通过dlopen方式打开该so,但dlopen的模式标志中未加入RTLD_GLOBAL标志
17.linux添加环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr1/w30016506/source_nctl_ap/NCTL/deps/lib/x86_64-linux-gnu/securec:/usr1/w30016506/source_nctl_ap/NCTL/output/x86_64/lib
18.如何对系统的函数(如malloc等)进行打桩
可以使用gcc的编译选项 --wrap
19.Linux磁盘空间满,但实际占用却没有那么大
(1)用df 检查发现/根目录可用空间为0
[root@/]#df -h
(2)用du检查发现各目录占用的空间都很少,有约3G的空间莫名其妙地丢了.
[root@/]# du -m –max-depth=1 | sort -gr
(3)用lsof检查后才发现原因是,有文件被删除,而进程还活着,因而造成还占用空间的现象
[root@/]# lsof | grep delete
根据lsof列出的进程号,kill这些进程后,空间就释放出来了
20.对python进行打断点调试
import pdb
然后在需要断点的地方进行加上语句 pdb.set_trace()
如果是需要联合C语言进行调试,可以使用gdb attach xxxx(进程号)来调试
21.当杀死一个进程时,操作系统会负责回收该进程所占用的内存,以确保系统资源的有效利用
22.如何获取malloc申请的内存大小
使用malloc_usable_size函数,传入mallc返回的指针,返回一个size_t
- malloc_usable_size函数只能用于malloc分配的内存块,对于其他分配器(如new、calloc等)分配的内存块,不能使用该函数
- malloc_usable_size函数返回的大小包括了内存块头部和尾部的额外空间,因此它的返回值可能会大于你实际分配的大小
23.linux上使用scp或者ssh命令时,出现报错:Add correct host key in /root/.ssh/known_hosts to get rid of this message,可以使用以下命令解决
ssh-keygen -R 110.0.0.30 -f /root/.ssh/known_hosts