揭示系统 API 的奥秘
Linux 系统架构
- 应用程序运行之后得到用户进程
模式切换的本质(系统调用的本质)
- 系统模式切换依赖于 CPU 提供的工作方式
一般来说,大部分 CPU 至少具有两种工作方式
- 高特权级 (Ring 0) : 可以访问任意的数据,包括外围设备,比如网卡、硬盘等(内核模式)
- 低特权级 (Ring 3) : 只能受限的访问内存,并且不允许访问外围设备,可被打断(用户模式)
- 系统模式切换通过执行特殊的 CPU 指令发起 (
int 0x80
,触发中断) - 应用程序(进程)无法直接切换 CPU 的工作方式
- 系统调用是应用程序(进程)请求模式切换的唯一方式
系统调用的真面目
char *s = "D.T.Software\n;"
int l = 13;
asm volatile (
"movl $s, %%eax\n" // 指定编号为 4 的系统调用(sys_write)
"movl $1, %%ebx\n" // 指定 sys_write 的输出目标, 1 为标准输出
"movl %0, %%ecx\n" // 指定输出字符串地址
"movl %1, %%edx\n" // 指定输出字符串长度
"int $0x80 \n" // 执行系统调用
: // 忽略输出参数
: "r"(s), "r"(l)
: "eax", "ebx", "ecx", "edx"); // 保留寄存去,不用于关联变量
void print(const char *s, int l)
{
asm volatile (
"movl $s, %%eax\n" // sys_write
"movl $1, %%ebx\n"
"movl %0, %%ecx\n"
"movl %1, %%edx\n"
"int $0x80 \n" // 80H Service
:
: "r"(s), "r"(l) // parameter
: "eax", "ebx", "ecx", "edx"); // 保留寄存去,不用于关联变量
}
系统调用和系统 API 实现示例
#define SysCall(type, cmd, param1, param2) asm volatile (
"movl $"#type", %%eax\n" \
"movl $"#cmd", %%ebx\n" \
"movl %0, %%ecx\n" \
"movl %1, %%edx\n" \
"int $0x80 \n" \
: \
: "r"(param1), "r"(param2) \
: "eax", "ebx", "ecx", "edx" \
)
void RegApp(const char *name, void(*tmain)(), byte pri)
{
if (name && tmain) {
AppInof info = {0};
info.name = name;
info.tmain = tmain;
info.priority = pri;
SysCall(0, 2, &info, 0);
}
}
编程实验:系统调用的本质
直接使用系统调用 program.c
第 1 处不同,没有引用头文件
第 2 处不同,没有 main 函数
第 3 处不同,函数里面嵌入了汇编代码
void print(const char *s, int l);
void exit(int code);
void program()
{
print("Hello World!\n", 13);
exit(0);
}
void print(const char *s, int l)
{
asm volatile (
"movl $4, %%eax\n"
"movl $1, %%ebx\n"
"movl %0, %%ecx\n"
"movl %1, %%edx\n"
"int $0x80 \n"
:
: "r"(s), "r"(l)
: "eax", "ebx", "ecx", "edx"
);
}
void exit(int code)
{
asm volatile (
"movl $1, %%eax\n"
"movl %0, %%ebx\n"
"int $0x80 \n"
:
: "r"(code)
: "eax", "ebx"
);
}
编译:
gcc -m32 -e program -fno-builtin -nostartfiles program.c -o program.out
-m32 : 指定使用 32 位编译方式
-e program : 指定 program 函数为入口
-fno-builtin -nostartfiles : 不需要 _start 函数
运行:
Hello World!
借助第三方库 main.c
#include
int main()
{
printf("Hello World!\n");
return 0;
}
编译:
gcc main.c -o main.out
运行:
Hello World!
值得思考的问题
- 如何判断一个应用程序(进程)触发了系统调用?
相同功能的代码实现
python
print('Hello World!')
perl
print "Hello World!\n"
C++
#include "iostream"
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
C#
namespace Test {
class Program {
static void Main(string[] args)
{
Console.Write("Hello World\n");
}
}
}
strace - 系统调用探测器
- strace 用户监控进程与内核的交付(监控系统调用)
- starce 用于追踪进程内部状态(定位运行时问题)
- starce 按序输出进程运行过程系统调用名称,参数和返回值
strace 程序性能分析
tiansong@tiansong:~/Desktop$ strace -tt -T -o program.log ./program.out
Hello World!
program.log
20:49:43.455558 execve("./program.out", ["./program.out"], 0x7ffd4866f4f0 /* 41 vars */) = 0 <0.000543>
20:49:43.456490 brk(NULL) = 0x57eb4000 <0.000090>
20:49:43.456758 arch_prctl(0x3001 /* ARCH_??? */, 0xffe88698) = -1 EINVAL (Invalid argument) <0.000087>
20:49:43.457239 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) <0.000242>
20:49:43.457786 mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xf7f95000 <0.000226>
20:49:43.458639 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) <0.000726>
20:49:43.459965 set_thread_area({entry_number=-1, base_addr=0xf7f959c0, limit=0x0fffff, seg_32bit=1, contents=0, read_exec_only=0, limit_in_pages=1, seg_not_present=0, useable=1}) = 0 (entry_number=12) <0.000489>
20:49:43.460899 mprotect(0x565c7000, 4096, PROT_READ) = 0 <0.000247>
20:49:43.461308 write(1, "Hello World!\n", 13) = 13 <0.000162>
20:49:43.461744 exit(0) = ?
20:49:43.462040 +++ exited with 0 +++
man execve
man brk
查看依赖
tiansong@tiansong:~/Desktop$ ldd program.out
statically linked
tiansong@tiansong:~/Desktop$ strace -c ./program.out
strace: [ Process PID=3691 runs in 32 bit mode. ]
Hello World!
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
0.00 0.000000 0 1 execve
------ ----------- ----------- --------- --------- ----------------
100.00 0.000000 1 total
System call usage summary for 32 bit mode:
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
0.00 0.000000 0 1 write
0.00 0.000000 0 2 2 access
0.00 0.000000 0 1 brk
0.00 0.000000 0 1 mprotect
0.00 0.000000 0 1 mmap2
0.00 0.000000 0 1 set_thread_area
0.00 0.000000 0 1 1 arch_prctl
------ ----------- ----------- --------- --------- ----------------
100.00 0.000008 8 3 total
tiansong@tiansong:~/Desktop$ strace -tt -T ./a.out
20:49:16.540739 execve("./a.out", ["./a.out"], 0x7ffdf1b95370 /* 41 vars */) = 0 <0.000394>
20:49:16.541439 brk(NULL) = 0x55a4e7477000 <0.000090>
20:49:16.541730 arch_prctl(0x3001 /* ARCH_??? */, 0x7ffe0f8e6a60) = -1 EINVAL (Invalid argument) <0.000088>
20:49:16.542141 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) <0.000150>
20:49:16.542615 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 <0.000146>
20:49:16.542949 fstat(3, {st_mode=S_IFREG|0644, st_size=73887, ...}) = 0 <0.000117>
20:49:16.543361 mmap(NULL, 73887, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6df5276000 <0.000187>
20:49:16.543696 close(3) = 0 <0.000108>
20:49:16.544083 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 <0.000534>
20:49:16.544859 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300A\2\0\0\0\0\0"..., 832) = 832 <0.000131>
20:49:16.545221 pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784 <0.000169>
20:49:16.545577 pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32 <0.000133>
20:49:16.546027 pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68 <0.000106>
20:49:16.546356 fstat(3, {st_mode=S_IFREG|0755, st_size=2029592, ...}) = 0 <0.000182>
20:49:16.546723 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6df5274000 <0.000096>
20:49:16.547047 pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784 <0.000091>
20:49:16.547426 pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32 <0.000375>
20:49:16.548194 pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68 <0.000175>
20:49:16.548696 mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6df5082000 <0.000283>
20:49:16.549183 mmap(0x7f6df50a4000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f6df50a4000 <0.000117>
20:49:16.549507 mmap(0x7f6df521c000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7f6df521c000 <0.000177>
20:49:16.549875 mmap(0x7f6df526a000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f6df526a000 <0.000301>
20:49:16.550483 mmap(0x7f6df5270000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6df5270000 <0.000295>
20:49:16.551340 close(3) = 0 <0.000251>
20:49:16.551837 arch_prctl(ARCH_SET_FS, 0x7f6df5275540) = 0 <0.000148>
20:49:16.552355 mprotect(0x7f6df526a000, 16384, PROT_READ) = 0 <0.000143>
20:49:16.552720 mprotect(0x55a4e6f29000, 4096, PROT_READ) = 0 <0.000197>
20:49:16.553099 mprotect(0x7f6df52b6000, 4096, PROT_READ) = 0 <0.000423>
20:49:16.553795 munmap(0x7f6df5276000, 73887) = 0 <0.000281>
20:49:16.554455 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0 <0.000791>
20:49:16.555759 brk(NULL) = 0x55a4e7477000 <0.000404>
20:49:16.556416 brk(0x55a4e7498000) = 0x55a4e7498000 <0.000268>
20:49:16.557149 write(1, "Hello World!\n", 13Hello World!
) = 13 <0.000127>
20:49:16.557496 exit_group(0) = ?
20:49:16.557904 +++ exited with 0 +++
查看依赖
tiansong@tiansong:~/Desktop$ ldd a.out
linux-vdso.so.1 (0x00007ffc13f0f000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f95f22f0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f95f24fc000)
tiansong@tiansong:~/Desktop$ strace -c ./a.out
Hello World!
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
0.00 0.000000 0 1 read
0.00 0.000000 0 1 write
0.00 0.000000 0 2 close
0.00 0.000000 0 3 fstat
0.00 0.000000 0 7 mmap
0.00 0.000000 0 3 mprotect
0.00 0.000000 0 1 munmap
0.00 0.000000 0 3 brk
0.00 0.000000 0 6 pread64
0.00 0.000000 0 1 1 access
0.00 0.000000 0 1 execve
0.00 0.000000 0 2 1 arch_prctl
0.00 0.000000 0 2 openat
------ ----------- ----------- --------- --------- ----------------
100.00 0.000012 33 2 total
strace - 用法详解
• -c -- count time, calls, and errors for each syscall and report summary
• -f -- follow forks
• -ff -- with output into separate files
• -F -- attempt to follow vforks
• -i -- print instruction pointer at time of syscall
• -q -- suppress messages about attaching, detaching, etc.
• -r -- print relative timestamp
• -t -- absolute timestamp,
• -tt -- with usecs
• -T -- print time spent in each syscall,
• -v -- verbose mode: print unabbreviated argv, stat, termio[s], etc. args
• -x -- print non-ascii strings in hex,
• -xx -- print all strings in hex
• -o file -- send trace output to FILE instead of stderr
• -O overhead -- set overhead for tracing syscalls to OVERHEAD usecs
• -p pid -- trace process with process id PID, may be repeated
• -D -- run tracer process as a detached grandchild, not as parent
• -s strsize -- limit length of print strings to STRSIZE chars (default 32)
• -S sortby -- sort syscall counts by: time, calls, name, nothing (default time)
-e expr : 指定一个表达式,用来控制如何跟踪
-e trace=set 跟踪指定的系统调用 如: -e trace=open,close,rean,write 表示只跟踪这四个系统调用 -e trace=file 跟踪有关文件操作的系统调用 -e trace=process 跟踪有关进程控制的系统调用 -e trace=network 跟踪与网络有关的所有系统调用 -e strace=signal 跟踪所有与系统信号有关的系统调用 -e trace=ipc 跟踪所有与进程通讯有关的系统调用 -e raw=set 将指定的系统调用的参数以十六进制显示 -e signal=set 指定跟踪的系统信号 如: signal=!SIGIO(或者signal=!IO),表示不跟踪 SIGIO 信号 -e read=set 输出从指定文件中读出的数据 如: -e read=3,5 -e write=set 输出写入到指定文件中的数据
编程实验:strace 程序逆向分析
在只有可执行程序fcopy.out
的前提下,探究其实现
通过read
、write
的交替,大概可判断为文件的复制
tiansong@tiansong:~/Desktop$ strace ./fcopy.out new_a.out a.out
execve("./fcopy.out", ["./fcopy.out", "new_a.out", "a.out"], 0x7fff7dbfd8f0 /* 41 vars */) = 0
brk(NULL) = 0x55b198e42000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffc282006b0) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=73887, ...}) = 0
mmap(NULL, 73887, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc31c5f6000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300A\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2029592, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc31c5f4000
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc31c402000
mmap(0x7fc31c424000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7fc31c424000
mmap(0x7fc31c59c000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7fc31c59c000
mmap(0x7fc31c5ea000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7fc31c5ea000
mmap(0x7fc31c5f0000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc31c5f0000
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7fc31c5f5540) = 0
mprotect(0x7fc31c5ea000, 16384, PROT_READ) = 0
mprotect(0x55b198828000, 4096, PROT_READ) = 0
mprotect(0x7fc31c636000, 4096, PROT_READ) = 0
munmap(0x7fc31c5f6000, 73887) = 0
openat(AT_FDCWD, "new_a.out", O_WRONLY|O_CREAT, 0600) = 3
openat(AT_FDCWD, "a.out", O_RDONLY) = 4
read(4, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\20\0\0\0\0\0\0"..., 512) = 512
write(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\20\0\0\0\0\0\0"..., 512) = 512
read(4, "\4\0\0\0\4\0\0\0X\3\0\0\0\0\0\0X\3\0\0\0\0\0\0X\3\0\0\0\0\0\0"..., 512) = 512
write(3, "\4\0\0\0\4\0\0\0X\3\0\0\0\0\0\0X\3\0\0\0\0\0\0X\3\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\37\0\0\0\22\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\37\0\0\0\22\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\363\17\36\372H\203\354\10H\213\5\331/\0\0H\205\300t\2\377\320H\203\304\10\303\0\0\0\0\0"..., 512) = 512
write(3, "\363\17\36\372H\203\354\10H\213\5\331/\0\0H\205\300t\2\377\320H\203\304\10\303\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\1\0\2\0Hello World!\0\0\0\0\1\33\3;@\0\0\0\7\0\0\0"..., 512) = 512
write(3, "\1\0\2\0Hello World!\0\0\0\0\1\33\3;@\0\0\0\7\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\270=\0\0\0\0\0\0\33\0\0\0\0\0\0\0\10\0\0\0\0\0\0\0\32\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\270=\0\0\0\0\0\0\33\0\0\0\0\0\0\0\10\0\0\0\0\0\0\0\32\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\10@\0\0\0\0\0\0GCC: (Ubuntu 9.4"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\10@\0\0\0\0\0\0GCC: (Ubuntu 9.4"..., 512) = 512
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\3\0\23\0\24 \0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\3\0\23\0\24 \0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\255\0\0\0\0\0\25\0\300=\0\0\0\0\0\0\0\0\0\0\0\0\0\0\276\0\0\0\1\0\27\0"..., 512) = 512
write(3, "\255\0\0\0\0\0\25\0\300=\0\0\0\0\0\0\0\0\0\0\0\0\0\0\276\0\0\0\1\0\27\0"..., 512) = 512
read(4, "I\21\0\0\0\0\0\0\33\0\0\0\0\0\0\0\300\1\0\0\21\2\31\0\20@\0\0\0\0\0\0"..., 512) = 512
write(3, "I\21\0\0\0\0\0\0\33\0\0\0\0\0\0\0\300\1\0\0\21\2\31\0\20@\0\0\0\0\0\0"..., 512) = 512
read(4, "u_init\0__bss_start\0main\0__TMC_EN"..., 512) = 512
write(3, "u_init\0__bss_start\0main\0__TMC_EN"..., 512) = 512
read(4, "\2\0\0\0\0\0\0\08\3\0\0\0\0\0\08\3\0\0\0\0\0\0 \0\0\0\0\0\0\0"..., 512) = 512
write(3, "\2\0\0\0\0\0\0\08\3\0\0\0\0\0\08\3\0\0\0\0\0\0 \0\0\0\0\0\0\0"..., 512) = 512
read(4, "\2\0\0\0\0\0\0\0 \5\0\0\0\0\0\0 \5\0\0\0\0\0\0\300\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\2\0\0\0\0\0\0\0 \5\0\0\0\0\0\0 \5\0\0\0\0\0\0\300\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\2\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0 \0\0\0\0\0\0\21\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\2\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0 \0\0\0\0\0\0\21\0\0\0\0\0\0\0"..., 512) = 512
read(4, "\3\0\0\0\0\0\0\0\20@\0\0\0\0\0\0\0200\0\0\0\0\0\0\10\0\0\0\0\0\0\0"..., 512) = 312
write(3, "\3\0\0\0\0\0\0\0\20@\0\0\0\0\0\0\0200\0\0\0\0\0\0\10\0\0\0\0\0\0\0"..., 312) = 312
read(4, "", 512) = 0
close(3) = 0
close(4) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
brk(NULL) = 0x55b198e42000
brk(0x55b198e63000) = 0x55b198e63000
write(1, "copy completed\n", 15copy completed
) = 15
exit_group(0) = ?
+++ exited with 0 +++
fcopy.c
#include
#include
#include
#include
#include
#include
#include
int file_copy(const char* dst, const char* src)
{
int dfd = open(dst, O_WRONLY|O_CREAT, 0600);
int sfd = open(src, O_RDONLY);
int ret = 0;
if( dfd == -1 )
{
ret = -1;
}
else if( sfd == -1 )
{
ret = -2;
}
else if( (dfd != -1) && (sfd != -1) )
{
char buf[512] = {0};
int len = 0;
while( (len = read(sfd, buf, sizeof(buf))) > 0 )
{
write(dfd, buf, len);
}
close(dfd);
close(sfd);
}
return ret;
}
int main(char argc, char* argv[])
{
if( argc > 2 )
{
if( file_copy(argv[1], argv[2]) == 0)
{
printf("copy completed\n");
}
else
{
printf("copy failed\n");
}
}
else
{
printf("parameter error\n");
}
return 0;
}
编程实验:应用程序错误定位
tiansong@tiansong:~/Desktop$ ./fcopy.out /new_folder/new_a.out
a.out
copy failed // 应用程序报错
tiansong@tiansong:~/Desktop$ strace ./fcopy.out /new_folder/new_a.out a.out
execve("./fcopy.out", ["./fcopy.out", "/new_folder/new_a.out", "a.out"], 0x7ffef202d8c0 /* 41 vars */) = 0
brk(NULL) = 0x55da5b131000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffff7aaec10) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) // 错误定位
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=73887, ...}) = 0
mmap(NULL, 73887, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f0b8eac7000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300A\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2029592, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0b8eac5000
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f0b8e8d3000
mmap(0x7f0b8e8f5000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f0b8e8f5000
mmap(0x7f0b8ea6d000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7f0b8ea6d000
mmap(0x7f0b8eabb000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f0b8eabb000
mmap(0x7f0b8eac1000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f0b8eac1000
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7f0b8eac6540) = 0
mprotect(0x7f0b8eabb000, 16384, PROT_READ) = 0
mprotect(0x55da5abe0000, 4096, PROT_READ) = 0
mprotect(0x7f0b8eb07000, 4096, PROT_READ) = 0
munmap(0x7f0b8eac7000, 73887) = 0
openat(AT_FDCWD, "/new_folder/new_a.out", O_WRONLY|O_CREAT, 0600) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "a.out", O_RDONLY) = 3
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
brk(NULL) = 0x55da5b131000
brk(0x55da5b152000) = 0x55da5b152000
write(1, "copy failed\n", 12copy failed
) = 12
exit_group(0) = ?
+++ exited with 0 +++
编程实验:strace 程序数据分析
查看程序执行过程中所涉及的数据
tiansong@tiansong:~/Desktop$ strace -xx -s 512 ./fcopy.out /n
ew_a.out a.out
execve("\x2e\x2f\x66\x63\x6f\x70\x79\x2e\x6f\x75\x74", ["\x2e\x2f\x66\x63\x6f\x70\x79\x2e\x6f\x75\x74", "\x2f\x6e\x65\x77\x5f\x61\x2e\x6f\x75\x74", "\x61\x2e\x6f\x75\x74"], 0x7fff63fd54e8 /* 41 vars */) = 0
brk(NULL) = 0x5649cb7b0000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffdd8ed6540) = -1 EINVAL (Invalid argument)
access("\x2f\x65\x74\x63\x2f\x6c\x64\x2e\x73\x6f\x2e\x70\x72\x65\x6c\x6f\x61\x64", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "\x2f\x65\x74\x63\x2f\x6c\x64\x2e\x73\x6f\x2e\x63\x61\x63\x68\x65", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=73887, ...}) = 0
mmap(NULL, 73887, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fbd28ca5000
close(3) = 0
openat(AT_FDCWD, "\x2f\x6c\x69\x62\x2f\x78\x38\x36\x5f\x36\x34\x2d\x6c\x69\x6e\x75\x78\x2d\x67\x6e\x75\x2f\x6c\x69\x62\x63\x2e\x73\x6f\x2e\x36", O_RDONLY|O_CLOEXEC) = 3
read(3, "\x7f\x45\x4c\x46\x02\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x3e\x00\x01\x00\x00\x00\xc0\x41\x02\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x18\xe7\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x38\x00\x0e\x00\x40\x00\x44\x00\x43\x00\x06\x00\x00\x00\x04\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x10\x03\x00\x00\x00\x00\x00\x00\x10\x03\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\xa0\xe6\x1b\x00\x00\x00\x00\x00\xa0\xe6\x1b\x00\x00\x00\x00\x00\xa0\xe6\x1b\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe8\x14\x02\x00\x00\x00\x00\x00\xe8\x14\x02\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x00\x20\x02\x00\x00\x00\x00\x00\x00\x20\x02\x00\x00\x00\x00\x00\x00\x20\x02\x00\x00\x00\x00\x00\x24\x76\x17\x00\x00\x00\x00\x00\x24\x76\x17\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x00\xa0\x19\x00\x00\x00\x00\x00\x00\xa0\x19\x00\x00\x00\x00\x00\x00\xa0\x19\x00\x00\x00\x00\x00\xc4\xd2\x04\x00\x00\x00\x00\x00\xc4\xd2\x04\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x06\x00\x00\x00\x88\x77\x1e\x00\x00\x00\x00\x00\x88\x87\x1e\x00\x00\x00\x00\x00\x88\x87\x1e\x00\x00\x00\x00\x00\x18\x50\x00\x00\x00\x00\x00\x00\xd8\x8e\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x06\x00\x00\x00\x80\xab\x1e\x00\x00\x00\x00\x00\x80\xbb\x1e\x00\x00\x00\x00\x00\x80\xbb\x1e\x00\x00\x00\x00\x00\xe0\x01\x00\x00\x00\x00\x00\x00\xe0\x01\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x50\x03\x00\x00\x00\x00\x00\x00\x50\x03\x00\x00\x00\x00\x00\x00\x50\x03\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00"..., 832) = 832
pread64(3, "\x06\x00\x00\x00\x04\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x10\x03\x00\x00\x00\x00\x00\x00\x10\x03\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\xa0\xe6\x1b\x00\x00\x00\x00\x00\xa0\xe6\x1b\x00\x00\x00\x00\x00\xa0\xe6\x1b\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe8\x14\x02\x00\x00\x00\x00\x00\xe8\x14\x02\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x00\x20\x02\x00\x00\x00\x00\x00\x00\x20\x02\x00\x00\x00\x00\x00\x00\x20\x02\x00\x00\x00\x00\x00\x24\x76\x17\x00\x00\x00\x00\x00\x24\x76\x17\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x00\xa0\x19\x00\x00\x00\x00\x00\x00\xa0\x19\x00\x00\x00\x00\x00\x00\xa0\x19\x00\x00\x00\x00\x00\xc4\xd2\x04\x00\x00\x00\x00\x00\xc4\xd2\x04\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x06\x00\x00\x00\x88\x77\x1e\x00\x00\x00\x00\x00\x88\x87\x1e\x00\x00\x00\x00\x00\x88\x87\x1e\x00\x00\x00\x00\x00\x18\x50\x00\x00\x00\x00\x00\x00\xd8\x8e\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x06\x00\x00\x00\x80\xab\x1e\x00\x00\x00\x00\x00\x80\xbb\x1e\x00\x00\x00\x00\x00\x80\xbb\x1e\x00\x00\x00\x00\x00\xe0\x01\x00\x00\x00\x00\x00\x00\xe0\x01\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x50\x03\x00\x00\x00\x00\x00\x00\x50\x03\x00\x00\x00\x00\x00\x00\x50\x03\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x70\x03\x00\x00\x00\x00\x00\x00\x70\x03\x00\x00\x00\x00\x00\x00\x70\x03\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x04\x00\x00\x00"..., 784, 64) = 784
pread64(3, "\x04\x00\x00\x00\x10\x00\x00\x00\x05\x00\x00\x00\x47\x4e\x55\x00\x02\x00\x00\xc0\x04\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00", 32, 848) = 32
pread64(3, "\x04\x00\x00\x00\x14\x00\x00\x00\x03\x00\x00\x00\x47\x4e\x55\x00\x18\x78\xe6\xb4\x75\x72\x0c\x7c\x51\x96\x9e\x69\xab\x2d\x27\x6f\xae\x6d\x1d\xee\x04\x00\x00\x00\x10\x00\x00\x00\x01\x00\x00\x00\x47\x4e\x55\x00\x00\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2029592, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fbd28ca3000
pread64(3, "\x06\x00\x00\x00\x04\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x10\x03\x00\x00\x00\x00\x00\x00\x10\x03\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\xa0\xe6\x1b\x00\x00\x00\x00\x00\xa0\xe6\x1b\x00\x00\x00\x00\x00\xa0\xe6\x1b\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe8\x14\x02\x00\x00\x00\x00\x00\xe8\x14\x02\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x00\x20\x02\x00\x00\x00\x00\x00\x00\x20\x02\x00\x00\x00\x00\x00\x00\x20\x02\x00\x00\x00\x00\x00\x24\x76\x17\x00\x00\x00\x00\x00\x24\x76\x17\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x00\xa0\x19\x00\x00\x00\x00\x00\x00\xa0\x19\x00\x00\x00\x00\x00\x00\xa0\x19\x00\x00\x00\x00\x00\xc4\xd2\x04\x00\x00\x00\x00\x00\xc4\xd2\x04\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x06\x00\x00\x00\x88\x77\x1e\x00\x00\x00\x00\x00\x88\x87\x1e\x00\x00\x00\x00\x00\x88\x87\x1e\x00\x00\x00\x00\x00\x18\x50\x00\x00\x00\x00\x00\x00\xd8\x8e\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x06\x00\x00\x00\x80\xab\x1e\x00\x00\x00\x00\x00\x80\xbb\x1e\x00\x00\x00\x00\x00\x80\xbb\x1e\x00\x00\x00\x00\x00\xe0\x01\x00\x00\x00\x00\x00\x00\xe0\x01\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x50\x03\x00\x00\x00\x00\x00\x00\x50\x03\x00\x00\x00\x00\x00\x00\x50\x03\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x70\x03\x00\x00\x00\x00\x00\x00\x70\x03\x00\x00\x00\x00\x00\x00\x70\x03\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x04\x00\x00\x00"..., 784, 64) = 784
pread64(3, "\x04\x00\x00\x00\x10\x00\x00\x00\x05\x00\x00\x00\x47\x4e\x55\x00\x02\x00\x00\xc0\x04\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00", 32, 848) = 32
pread64(3, "\x04\x00\x00\x00\x14\x00\x00\x00\x03\x00\x00\x00\x47\x4e\x55\x00\x18\x78\xe6\xb4\x75\x72\x0c\x7c\x51\x96\x9e\x69\xab\x2d\x27\x6f\xae\x6d\x1d\xee\x04\x00\x00\x00\x10\x00\x00\x00\x01\x00\x00\x00\x47\x4e\x55\x00\x00\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 68, 880) = 68
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fbd28ab1000
mmap(0x7fbd28ad3000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7fbd28ad3000
mmap(0x7fbd28c4b000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7fbd28c4b000
mmap(0x7fbd28c99000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7fbd28c99000
mmap(0x7fbd28c9f000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fbd28c9f000
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7fbd28ca4540) = 0
mprotect(0x7fbd28c99000, 16384, PROT_READ) = 0
mprotect(0x5649c9a24000, 4096, PROT_READ) = 0
mprotect(0x7fbd28ce5000, 4096, PROT_READ) = 0
munmap(0x7fbd28ca5000, 73887) = 0
openat(AT_FDCWD, "\x2f\x6e\x65\x77\x5f\x61\x2e\x6f\x75\x74", O_WRONLY|O_CREAT, 0600) = -1 EACCES (Permission denied)
openat(AT_FDCWD, "\x61\x2e\x6f\x75\x74", O_RDONLY) = 3
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
brk(NULL) = 0x5649cb7b0000
brk(0x5649cb7d1000) = 0x5649cb7d1000
write(1, "\x63\x6f\x70\x79\x20\x66\x61\x69\x6c\x65\x64\x0a", 12copy failed
) = 12
exit_group(0) = ?
+++ exited with 0 +++
tiansong@tiansong:~/Desktop$ strace -e read=3 ./fcopy.out /new_a.out a.out
execve("./fcopy.out", ["./fcopy.out", "/new_a.out", "a.out"], 0x7fff6dde78e0 /* 41 vars */) = 0
brk(NULL) = 0x55eda4dca000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd1320ade0) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=73887, ...}) = 0
mmap(NULL, 73887, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1ede05a000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300A\2\0\0\0\0\0"..., 832) = 832
| 00000 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00 .ELF............ |
| 00010 03 00 3e 00 01 00 00 00 c0 41 02 00 00 00 00 00 ..>......A...... |
| 00020 40 00 00 00 00 00 00 00 18 e7 1e 00 00 00 00 00 @............... |
| 00030 00 00 00 00 40 00 38 00 0e 00 40 00 44 00 43 00 [email protected][email protected]. |
| 00040 06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00 ........@....... |
| 00050 40 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 @.......@....... |
| 00060 10 03 00 00 00 00 00 00 10 03 00 00 00 00 00 00 ................ |
| 00070 08 00 00 00 00 00 00 00 03 00 00 00 04 00 00 00 ................ |
| 00080 a0 e6 1b 00 00 00 00 00 a0 e6 1b 00 00 00 00 00 ................ |
| 00090 a0 e6 1b 00 00 00 00 00 1c 00 00 00 00 00 00 00 ................ |
| 000a0 1c 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 ................ |
| 000b0 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 000d0 e8 14 02 00 00 00 00 00 e8 14 02 00 00 00 00 00 ................ |
| 000e0 00 10 00 00 00 00 00 00 01 00 00 00 05 00 00 00 ................ |
| 000f0 00 20 02 00 00 00 00 00 00 20 02 00 00 00 00 00 . ....... ...... |
| 00100 00 20 02 00 00 00 00 00 24 76 17 00 00 00 00 00 . ......$v...... |
| 00110 24 76 17 00 00 00 00 00 00 10 00 00 00 00 00 00 $v.............. |
| 00120 01 00 00 00 04 00 00 00 00 a0 19 00 00 00 00 00 ................ |
| 00130 00 a0 19 00 00 00 00 00 00 a0 19 00 00 00 00 00 ................ |
| 00140 c4 d2 04 00 00 00 00 00 c4 d2 04 00 00 00 00 00 ................ |
| 00150 00 10 00 00 00 00 00 00 01 00 00 00 06 00 00 00 ................ |
| 00160 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00170 88 87 1e 00 00 00 00 00 18 50 00 00 00 00 00 00 .........P...... |
| 00180 d8 8e 00 00 00 00 00 00 00 10 00 00 00 00 00 00 ................ |
| 00190 02 00 00 00 06 00 00 00 80 ab 1e 00 00 00 00 00 ................ |
| 001a0 80 bb 1e 00 00 00 00 00 80 bb 1e 00 00 00 00 00 ................ |
| 001b0 e0 01 00 00 00 00 00 00 e0 01 00 00 00 00 00 00 ................ |
| 001c0 08 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00 ................ |
| 001d0 50 03 00 00 00 00 00 00 50 03 00 00 00 00 00 00 P.......P....... |
| 001e0 50 03 00 00 00 00 00 00 20 00 00 00 00 00 00 00 P....... ....... |
| 001f0 20 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ............... |
| 00200 04 00 00 00 04 00 00 00 70 03 00 00 00 00 00 00 ........p....... |
| 00210 70 03 00 00 00 00 00 00 70 03 00 00 00 00 00 00 p.......p....... |
| 00220 44 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 D.......D....... |
| 00230 04 00 00 00 00 00 00 00 07 00 00 00 04 00 00 00 ................ |
| 00240 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00250 88 87 1e 00 00 00 00 00 10 00 00 00 00 00 00 00 ................ |
| 00260 90 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ................ |
| 00270 53 e5 74 64 04 00 00 00 50 03 00 00 00 00 00 00 S.td....P....... |
| 00280 50 03 00 00 00 00 00 00 50 03 00 00 00 00 00 00 P.......P....... |
| 00290 20 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 ....... ....... |
| 002a0 08 00 00 00 00 00 00 00 50 e5 74 64 04 00 00 00 ........P.td.... |
| 002b0 bc e6 1b 00 00 00 00 00 bc e6 1b 00 00 00 00 00 ................ |
| 002c0 bc e6 1b 00 00 00 00 00 d4 5e 00 00 00 00 00 00 .........^...... |
| 002d0 d4 5e 00 00 00 00 00 00 04 00 00 00 00 00 00 00 .^.............. |
| 002e0 51 e5 74 64 06 00 00 00 00 00 00 00 00 00 00 00 Q.td............ |
| 002f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 00300 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 00310 10 00 00 00 00 00 00 00 52 e5 74 64 04 00 00 00 ........R.td.... |
| 00320 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00330 88 87 1e 00 00 00 00 00 78 38 00 00 00 00 00 00 ........x8...... |
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
| 00000 06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00 ........@....... |
| 00010 40 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 @.......@....... |
| 00020 10 03 00 00 00 00 00 00 10 03 00 00 00 00 00 00 ................ |
| 00030 08 00 00 00 00 00 00 00 03 00 00 00 04 00 00 00 ................ |
| 00040 a0 e6 1b 00 00 00 00 00 a0 e6 1b 00 00 00 00 00 ................ |
| 00050 a0 e6 1b 00 00 00 00 00 1c 00 00 00 00 00 00 00 ................ |
| 00060 1c 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 ................ |
| 00070 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 00080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 00090 e8 14 02 00 00 00 00 00 e8 14 02 00 00 00 00 00 ................ |
| 000a0 00 10 00 00 00 00 00 00 01 00 00 00 05 00 00 00 ................ |
| 000b0 00 20 02 00 00 00 00 00 00 20 02 00 00 00 00 00 . ....... ...... |
| 000c0 00 20 02 00 00 00 00 00 24 76 17 00 00 00 00 00 . ......$v...... |
| 000d0 24 76 17 00 00 00 00 00 00 10 00 00 00 00 00 00 $v.............. |
| 000e0 01 00 00 00 04 00 00 00 00 a0 19 00 00 00 00 00 ................ |
| 000f0 00 a0 19 00 00 00 00 00 00 a0 19 00 00 00 00 00 ................ |
| 00100 c4 d2 04 00 00 00 00 00 c4 d2 04 00 00 00 00 00 ................ |
| 00110 00 10 00 00 00 00 00 00 01 00 00 00 06 00 00 00 ................ |
| 00120 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00130 88 87 1e 00 00 00 00 00 18 50 00 00 00 00 00 00 .........P...... |
| 00140 d8 8e 00 00 00 00 00 00 00 10 00 00 00 00 00 00 ................ |
| 00150 02 00 00 00 06 00 00 00 80 ab 1e 00 00 00 00 00 ................ |
| 00160 80 bb 1e 00 00 00 00 00 80 bb 1e 00 00 00 00 00 ................ |
| 00170 e0 01 00 00 00 00 00 00 e0 01 00 00 00 00 00 00 ................ |
| 00180 08 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00 ................ |
| 00190 50 03 00 00 00 00 00 00 50 03 00 00 00 00 00 00 P.......P....... |
| 001a0 50 03 00 00 00 00 00 00 20 00 00 00 00 00 00 00 P....... ....... |
| 001b0 20 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ............... |
| 001c0 04 00 00 00 04 00 00 00 70 03 00 00 00 00 00 00 ........p....... |
| 001d0 70 03 00 00 00 00 00 00 70 03 00 00 00 00 00 00 p.......p....... |
| 001e0 44 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 D.......D....... |
| 001f0 04 00 00 00 00 00 00 00 07 00 00 00 04 00 00 00 ................ |
| 00200 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00210 88 87 1e 00 00 00 00 00 10 00 00 00 00 00 00 00 ................ |
| 00220 90 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ................ |
| 00230 53 e5 74 64 04 00 00 00 50 03 00 00 00 00 00 00 S.td....P....... |
| 00240 50 03 00 00 00 00 00 00 50 03 00 00 00 00 00 00 P.......P....... |
| 00250 20 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 ....... ....... |
| 00260 08 00 00 00 00 00 00 00 50 e5 74 64 04 00 00 00 ........P.td.... |
| 00270 bc e6 1b 00 00 00 00 00 bc e6 1b 00 00 00 00 00 ................ |
| 00280 bc e6 1b 00 00 00 00 00 d4 5e 00 00 00 00 00 00 .........^...... |
| 00290 d4 5e 00 00 00 00 00 00 04 00 00 00 00 00 00 00 .^.............. |
| 002a0 51 e5 74 64 06 00 00 00 00 00 00 00 00 00 00 00 Q.td............ |
| 002b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 002c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 002d0 10 00 00 00 00 00 00 00 52 e5 74 64 04 00 00 00 ........R.td.... |
| 002e0 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 002f0 88 87 1e 00 00 00 00 00 78 38 00 00 00 00 00 00 ........x8...... |
| 00300 78 38 00 00 00 00 00 00 01 00 00 00 00 00 00 00 x8.............. |
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
| 00000 04 00 00 00 10 00 00 00 05 00 00 00 47 4e 55 00 ............GNU. |
| 00010 02 00 00 c0 04 00 00 00 03 00 00 00 00 00 00 00 ................ |
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68
| 00000 04 00 00 00 14 00 00 00 03 00 00 00 47 4e 55 00 ............GNU. |
| 00010 18 78 e6 b4 75 72 0c 7c 51 96 9e 69 ab 2d 27 6f .x..ur.|Q..i.-'o |
| 00020 ae 6d 1d ee 04 00 00 00 10 00 00 00 01 00 00 00 .m.............. |
| 00030 47 4e 55 00 00 00 00 00 03 00 00 00 02 00 00 00 GNU............. |
| 00040 00 00 00 00 .... |
fstat(3, {st_mode=S_IFREG|0755, st_size=2029592, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1ede058000
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
| 00000 06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00 ........@....... |
| 00010 40 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 @.......@....... |
| 00020 10 03 00 00 00 00 00 00 10 03 00 00 00 00 00 00 ................ |
| 00030 08 00 00 00 00 00 00 00 03 00 00 00 04 00 00 00 ................ |
| 00040 a0 e6 1b 00 00 00 00 00 a0 e6 1b 00 00 00 00 00 ................ |
| 00050 a0 e6 1b 00 00 00 00 00 1c 00 00 00 00 00 00 00 ................ |
| 00060 1c 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 ................ |
| 00070 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 00080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 00090 e8 14 02 00 00 00 00 00 e8 14 02 00 00 00 00 00 ................ |
| 000a0 00 10 00 00 00 00 00 00 01 00 00 00 05 00 00 00 ................ |
| 000b0 00 20 02 00 00 00 00 00 00 20 02 00 00 00 00 00 . ....... ...... |
| 000c0 00 20 02 00 00 00 00 00 24 76 17 00 00 00 00 00 . ......$v...... |
| 000d0 24 76 17 00 00 00 00 00 00 10 00 00 00 00 00 00 $v.............. |
| 000e0 01 00 00 00 04 00 00 00 00 a0 19 00 00 00 00 00 ................ |
| 000f0 00 a0 19 00 00 00 00 00 00 a0 19 00 00 00 00 00 ................ |
| 00100 c4 d2 04 00 00 00 00 00 c4 d2 04 00 00 00 00 00 ................ |
| 00110 00 10 00 00 00 00 00 00 01 00 00 00 06 00 00 00 ................ |
| 00120 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00130 88 87 1e 00 00 00 00 00 18 50 00 00 00 00 00 00 .........P...... |
| 00140 d8 8e 00 00 00 00 00 00 00 10 00 00 00 00 00 00 ................ |
| 00150 02 00 00 00 06 00 00 00 80 ab 1e 00 00 00 00 00 ................ |
| 00160 80 bb 1e 00 00 00 00 00 80 bb 1e 00 00 00 00 00 ................ |
| 00170 e0 01 00 00 00 00 00 00 e0 01 00 00 00 00 00 00 ................ |
| 00180 08 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00 ................ |
| 00190 50 03 00 00 00 00 00 00 50 03 00 00 00 00 00 00 P.......P....... |
| 001a0 50 03 00 00 00 00 00 00 20 00 00 00 00 00 00 00 P....... ....... |
| 001b0 20 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ............... |
| 001c0 04 00 00 00 04 00 00 00 70 03 00 00 00 00 00 00 ........p....... |
| 001d0 70 03 00 00 00 00 00 00 70 03 00 00 00 00 00 00 p.......p....... |
| 001e0 44 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 D.......D....... |
| 001f0 04 00 00 00 00 00 00 00 07 00 00 00 04 00 00 00 ................ |
| 00200 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00210 88 87 1e 00 00 00 00 00 10 00 00 00 00 00 00 00 ................ |
| 00220 90 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ................ |
| 00230 53 e5 74 64 04 00 00 00 50 03 00 00 00 00 00 00 S.td....P....... |
| 00240 50 03 00 00 00 00 00 00 50 03 00 00 00 00 00 00 P.......P....... |
| 00250 20 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 ....... ....... |
| 00260 08 00 00 00 00 00 00 00 50 e5 74 64 04 00 00 00 ........P.td.... |
| 00270 bc e6 1b 00 00 00 00 00 bc e6 1b 00 00 00 00 00 ................ |
| 00280 bc e6 1b 00 00 00 00 00 d4 5e 00 00 00 00 00 00 .........^...... |
| 00290 d4 5e 00 00 00 00 00 00 04 00 00 00 00 00 00 00 .^.............. |
| 002a0 51 e5 74 64 06 00 00 00 00 00 00 00 00 00 00 00 Q.td............ |
| 002b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 002c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 002d0 10 00 00 00 00 00 00 00 52 e5 74 64 04 00 00 00 ........R.td.... |
| 002e0 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 002f0 88 87 1e 00 00 00 00 00 78 38 00 00 00 00 00 00 ........x8...... |
| 00300 78 38 00 00 00 00 00 00 01 00 00 00 00 00 00 00 x8.............. |
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
| 00000 04 00 00 00 10 00 00 00 05 00 00 00 47 4e 55 00 ............GNU. |
| 00010 02 00 00 c0 04 00 00 00 03 00 00 00 00 00 00 00 ................ |
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68
| 00000 04 00 00 00 14 00 00 00 03 00 00 00 47 4e 55 00 ............GNU. |
| 00010 18 78 e6 b4 75 72 0c 7c 51 96 9e 69 ab 2d 27 6f .x..ur.|Q..i.-'o |
| 00020 ae 6d 1d ee 04 00 00 00 10 00 00 00 01 00 00 00 .m.............. |
| 00030 47 4e 55 00 00 00 00 00 03 00 00 00 02 00 00 00 GNU............. |
| 00040 00 00 00 00 .... |
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1edde66000
mmap(0x7f1edde88000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f1edde88000
mmap(0x7f1ede000000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7f1ede000000
mmap(0x7f1ede04e000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f1ede04e000
mmap(0x7f1ede054000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1ede054000
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7f1ede059540) = 0
mprotect(0x7f1ede04e000, 16384, PROT_READ) = 0
mprotect(0x55eda4c16000, 4096, PROT_READ) = 0
mprotect(0x7f1ede09a000, 4096, PROT_READ) = 0
munmap(0x7f1ede05a000, 73887) = 0
openat(AT_FDCWD, "/new_a.out", O_WRONLY|O_CREAT, 0600) = -1 EACCES (Permission denied)
openat(AT_FDCWD, "a.out", O_RDONLY) = 3
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
brk(NULL) = 0x55eda4dca000
brk(0x55eda4deb000) = 0x55eda4deb000
write(1, "copy failed\n", 12copy failed
) = 12
exit_group(0) = ?
+++ exited with 0 +++
tiansong@tiansong:~/Desktop$ strace -e read=3 -e trace=file,read,close ./fcopy.out /new_a.out
a.out
execve("./fcopy.out", ["./fcopy.out", "/new_a.out", "a.out"], 0x7fff0de15440 /* 41 vars */) = 0
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300A\2\0\0\0\0\0"..., 832) = 832
| 00000 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00 .ELF............ |
| 00010 03 00 3e 00 01 00 00 00 c0 41 02 00 00 00 00 00 ..>......A...... |
| 00020 40 00 00 00 00 00 00 00 18 e7 1e 00 00 00 00 00 @............... |
| 00030 00 00 00 00 40 00 38 00 0e 00 40 00 44 00 43 00 [email protected][email protected]. |
| 00040 06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00 ........@....... |
| 00050 40 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 @.......@....... |
| 00060 10 03 00 00 00 00 00 00 10 03 00 00 00 00 00 00 ................ |
| 00070 08 00 00 00 00 00 00 00 03 00 00 00 04 00 00 00 ................ |
| 00080 a0 e6 1b 00 00 00 00 00 a0 e6 1b 00 00 00 00 00 ................ |
| 00090 a0 e6 1b 00 00 00 00 00 1c 00 00 00 00 00 00 00 ................ |
| 000a0 1c 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 ................ |
| 000b0 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 000d0 e8 14 02 00 00 00 00 00 e8 14 02 00 00 00 00 00 ................ |
| 000e0 00 10 00 00 00 00 00 00 01 00 00 00 05 00 00 00 ................ |
| 000f0 00 20 02 00 00 00 00 00 00 20 02 00 00 00 00 00 . ....... ...... |
| 00100 00 20 02 00 00 00 00 00 24 76 17 00 00 00 00 00 . ......$v...... |
| 00110 24 76 17 00 00 00 00 00 00 10 00 00 00 00 00 00 $v.............. |
| 00120 01 00 00 00 04 00 00 00 00 a0 19 00 00 00 00 00 ................ |
| 00130 00 a0 19 00 00 00 00 00 00 a0 19 00 00 00 00 00 ................ |
| 00140 c4 d2 04 00 00 00 00 00 c4 d2 04 00 00 00 00 00 ................ |
| 00150 00 10 00 00 00 00 00 00 01 00 00 00 06 00 00 00 ................ |
| 00160 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00170 88 87 1e 00 00 00 00 00 18 50 00 00 00 00 00 00 .........P...... |
| 00180 d8 8e 00 00 00 00 00 00 00 10 00 00 00 00 00 00 ................ |
| 00190 02 00 00 00 06 00 00 00 80 ab 1e 00 00 00 00 00 ................ |
| 001a0 80 bb 1e 00 00 00 00 00 80 bb 1e 00 00 00 00 00 ................ |
| 001b0 e0 01 00 00 00 00 00 00 e0 01 00 00 00 00 00 00 ................ |
| 001c0 08 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00 ................ |
| 001d0 50 03 00 00 00 00 00 00 50 03 00 00 00 00 00 00 P.......P....... |
| 001e0 50 03 00 00 00 00 00 00 20 00 00 00 00 00 00 00 P....... ....... |
| 001f0 20 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ............... |
| 00200 04 00 00 00 04 00 00 00 70 03 00 00 00 00 00 00 ........p....... |
| 00210 70 03 00 00 00 00 00 00 70 03 00 00 00 00 00 00 p.......p....... |
| 00220 44 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 D.......D....... |
| 00230 04 00 00 00 00 00 00 00 07 00 00 00 04 00 00 00 ................ |
| 00240 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00250 88 87 1e 00 00 00 00 00 10 00 00 00 00 00 00 00 ................ |
| 00260 90 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ................ |
| 00270 53 e5 74 64 04 00 00 00 50 03 00 00 00 00 00 00 S.td....P....... |
| 00280 50 03 00 00 00 00 00 00 50 03 00 00 00 00 00 00 P.......P....... |
| 00290 20 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 ....... ....... |
| 002a0 08 00 00 00 00 00 00 00 50 e5 74 64 04 00 00 00 ........P.td.... |
| 002b0 bc e6 1b 00 00 00 00 00 bc e6 1b 00 00 00 00 00 ................ |
| 002c0 bc e6 1b 00 00 00 00 00 d4 5e 00 00 00 00 00 00 .........^...... |
| 002d0 d4 5e 00 00 00 00 00 00 04 00 00 00 00 00 00 00 .^.............. |
| 002e0 51 e5 74 64 06 00 00 00 00 00 00 00 00 00 00 00 Q.td............ |
| 002f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 00300 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ |
| 00310 10 00 00 00 00 00 00 00 52 e5 74 64 04 00 00 00 ........R.td.... |
| 00320 88 77 1e 00 00 00 00 00 88 87 1e 00 00 00 00 00 .w.............. |
| 00330 88 87 1e 00 00 00 00 00 78 38 00 00 00 00 00 00 ........x8...... |
close(3) = 0
openat(AT_FDCWD, "/new_a.out", O_WRONLY|O_CREAT, 0600) = -1 EACCES (Permission denied)
openat(AT_FDCWD, "a.out", O_RDONLY) = 3
copy failed
+++ exited with 0 +++
tiansong@tiansong:~/Desktop$ strace -e trace=write ./fcopy.out ./new_a.out a.out
write(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\20\0\0\0\0\0\0"..., 512) = 512
write(3, "\4\0\0\0\4\0\0\0X\3\0\0\0\0\0\0X\3\0\0\0\0\0\0X\3\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\37\0\0\0\22\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\363\17\36\372H\203\354\10H\213\5\331/\0\0H\205\300t\2\377\320H\203\304\10\303\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\1\0\2\0Hello World!\0\0\0\0\1\33\3;@\0\0\0\7\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\270=\0\0\0\0\0\0\33\0\0\0\0\0\0\0\10\0\0\0\0\0\0\0\32\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\10@\0\0\0\0\0\0GCC: (Ubuntu 9.4"..., 512) = 512
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\3\0\23\0\24 \0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\255\0\0\0\0\0\25\0\300=\0\0\0\0\0\0\0\0\0\0\0\0\0\0\276\0\0\0\1\0\27\0"..., 512) = 512
write(3, "I\21\0\0\0\0\0\0\33\0\0\0\0\0\0\0\300\1\0\0\21\2\31\0\20@\0\0\0\0\0\0"..., 512) = 512
write(3, "u_init\0__bss_start\0main\0__TMC_EN"..., 512) = 512
write(3, "\2\0\0\0\0\0\0\08\3\0\0\0\0\0\08\3\0\0\0\0\0\0 \0\0\0\0\0\0\0"..., 512) = 512
write(3, "\2\0\0\0\0\0\0\0 \5\0\0\0\0\0\0 \5\0\0\0\0\0\0\300\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\2\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0 \0\0\0\0\0\0\21\0\0\0\0\0\0\0"..., 512) = 512
write(3, "\3\0\0\0\0\0\0\0\20@\0\0\0\0\0\0\0200\0\0\0\0\0\0\10\0\0\0\0\0\0\0"..., 312) = 312
write(1, "copy completed\n", 15copy completed
) = 15
+++ exited with 0 +++