|
发表于 2022-9-6 14:34:20
|
显示全部楼层
本帖最后由 人造人 于 2022-9-6 15:02 编辑
那你反汇编看一下么,单步调试程序么
一条指令一条指令的执行,看head这个数据结构在内存中的布局,看各个寄存器的值,看看换了位置后,在哪个寄存器的值变了
有很好的工具却不懂得使用怎么能行?
在汇编语言面前,数据结构什么也没有隐藏,也无法隐藏
你一条指令一条指令的执行程序,寄存器中的值你都可以看到,怎么就无法理解这个程序?
调试程序去,一条指令一条指令的执行
手里有很好的工具要懂得去使用,手里有汇编语言这么强大的工具不会用就等于没有
- main.o: file format elf64-x86-64
- Disassembly of section .text:
- 0000000000000000 <delete_duplicates>:
- size_t val;
- struct list_tag_t *next;
- } list_t;
- list_t *delete_duplicates(list_t *head) {
- 0: 55 pushq %rbp
- 1: 48 89 e5 movq %rsp,%rbp
- 4: 48 89 7d e8 movq %rdi,-0x18(%rbp)
- if(!head) return head;
- 8: 48 83 7d e8 00 cmpq $0x0,-0x18(%rbp)
- d: 75 06 jne 15 <delete_duplicates+0x15>
- f: 48 8b 45 e8 movq -0x18(%rbp),%rax
- 13: eb 60 jmp 75 <delete_duplicates+0x75>
- list_t *fast = head;
- 15: 48 8b 45 e8 movq -0x18(%rbp),%rax
- 19: 48 89 45 f0 movq %rax,-0x10(%rbp)
- list_t *slow = head;
- 1d: 48 8b 45 e8 movq -0x18(%rbp),%rax
- 21: 48 89 45 f8 movq %rax,-0x8(%rbp)
- while(fast) {
- 25: eb 37 jmp 5e <delete_duplicates+0x5e>
- if(slow->val != fast->val) {
- 27: 48 8b 45 f8 movq -0x8(%rbp),%rax
- 2b: 48 8b 10 movq (%rax),%rdx
- 2e: 48 8b 45 f0 movq -0x10(%rbp),%rax
- 32: 48 8b 00 movq (%rax),%rax
- 35: 48 39 c2 cmpq %rax,%rdx
- 38: 74 18 je 52 <delete_duplicates+0x52>
- slow->next = fast;
- 3a: 48 8b 45 f8 movq -0x8(%rbp),%rax
- 3e: 48 8b 55 f0 movq -0x10(%rbp),%rdx
- 42: 48 89 50 08 movq %rdx,0x8(%rax)
- slow = slow->next;
- 46: 48 8b 45 f8 movq -0x8(%rbp),%rax
- 4a: 48 8b 40 08 movq 0x8(%rax),%rax
- 4e: 48 89 45 f8 movq %rax,-0x8(%rbp)
- }
- fast = fast->next;
- 52: 48 8b 45 f0 movq -0x10(%rbp),%rax
- 56: 48 8b 40 08 movq 0x8(%rax),%rax
- 5a: 48 89 45 f0 movq %rax,-0x10(%rbp)
- while(fast) {
- 5e: 48 83 7d f0 00 cmpq $0x0,-0x10(%rbp)
- 63: 75 c2 jne 27 <delete_duplicates+0x27>
- }
- slow->next = NULL;
- 65: 48 8b 45 f8 movq -0x8(%rbp),%rax
- 69: 48 c7 40 08 00 00 00 movq $0x0,0x8(%rax)
- 70: 00
- return head;
- 71: 48 8b 45 e8 movq -0x18(%rbp),%rax
- }
- 75: 5d popq %rbp
- 76: c3 retq
复制代码
这不反汇编代码放在这了,你哪里看不懂?
|
|