c - switch 语句汇编代码到c

标签 c assembly switch-statement reverse-engineering

我很难将 switch 语句从汇编代码逆向工程为 C 程序。

.file 
"switch_prob2-soln.c"
.text
.globl switch_prob
.type switch_prob, @function
switch_prob:
.LFB0:
.cfi_startproc
subq $60, %rsi
cmpq $5, %rsi
ja .L2
jmp *.L7(,%rsi,8)
.section .rodata
.align 8
.align 4
 .L7:
 .quad .L3
 .quad .L2
 .quad .L3
 .quad .L4
 .quad .L5
 .quad .L6
 .text
 .L3:
 leaq 0(,%rdi,8), %rax
 ret
 .L4:
 movq %rdi, %rax
 sarq $3, %rax
 ret
 .L5:
 movq %rdi, %rax
 salq $4, %rax
 subq %rdi, %rax
 movq %rax, %rdi
 .L6:
 imulq %rdi, %rdi
 .L2:
 leaq 75(%rdi), %rax
 ret
 .cfi_endproc
 .LFE0:
 .size switch_prob, .-switch_prob
  .ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
 .section .note.GNU-stack,"",@progbits

这是我的基本 C 程序:

long switch_prob(long x, long n)
{
    long result = x;
    switch(n) {

 }
 return result;
 }

我所要求的只是一些有用的入门建议。我知道我可以使用 -S 或 -O1 进行编译。感谢您抽出时间。

这是我的 C 代码在汇编中显示的内容 enter image description here

这是我的c代码

enter image description here

如果有人可以帮助我,那就太棒了,我正在努力让四边形显示出来 3 2 3 4 5 6

最佳答案

目前尚不清楚您遇到了什么问题。我希望您知道它使用跳转表。

很明显,您有 6 个案例和一个默认案例,并且有一些共享代码。说明非常简单,我相信您不会有任何问题。

至于 switch 表达式本身,它只是一条指令完成的简单转换。

我试图不泄露解决方案,毕竟你征求了建议以开始使用。您需要更多提示吗?

关于c - switch 语句汇编代码到c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33381475/

相关文章:

coding-style - Switch 语句失败...应该允许吗?

c - 二叉树,打印出我在哪一层

c - 在终端中隔离标准输入和标准输出

c - 如何在 c x86 AT&T 内联汇编中访问和更改 char 数组

c - 如何查看为 C 函数生成的汇编代码?

assembly - 基址指针和堆栈指针

c - 为什么 sum1 = 46 而 sum2 = 48

c - ld 在 .o 中找不到符号

c++ - 带 switch 语句的 for 循环

java - 将字符串转换为整数