Skip to content

Instantly share code, notes, and snippets.

@liweinan
Created October 1, 2019 01:58
Show Gist options
  • Save liweinan/fe2a6dff56e86c781669d54ea5a90692 to your computer and use it in GitHub Desktop.
Save liweinan/fe2a6dff56e86c781669d54ea5a90692 to your computer and use it in GitHub Desktop.
汇编学习笔记

记录汇编学习

@liweinan
Copy link
Author

liweinan commented Oct 1, 2019

::2020-05-07::更新:


使用的容器:

@liweinan
Copy link
Author

liweinan commented Oct 1, 2019

disassemble命令:

启动容器:

$ docker run -it --privileged weli/docker-assembly-gef-pyenv bash

进入容器的root目录:

$ cd /root

查看代码:

$ ls
asm.c    foo.asm

asm.c的内容:

$ cat asm.c
#include <stdio.h>
int main(void)
{
        int foo = 10, bar = 15;
        __asm__ __volatile__("addl  %%ebx,%%eax"
                             :"=a"(foo)
                             :"a"(foo), "b"(bar)
                             );
        printf("foo+bar=%d\n", foo);
        return 0;
}

编译代码:

$ cc -g asm.c

得到a.out

$ ls a.out
a.out

上面过程的截图:

image

使用gdb加载a.out

$ gdb -q a.out

使用gdbdisassemble命令查看main函数编译后的汇编代码:

>  disassemble main

过程截图:

image

可以看到上面的汇编指令中对printf的调用:

image

@liweinan
Copy link
Author

liweinan commented Oct 1, 2019

创建用户:

bash-5.0# adduser reader
Changing password for reader
New password:
Bad password: too short
Retype password:
passwd: password for reader changed by root
bash-5.0# su reader
/root $ whoami
reader
/root $

image

@liweinan
Copy link
Author

liweinan commented Oct 1, 2019

bash-5.0# su reader
/root $ whoami
reader
/root $ pwd
/root
/root $ cd
~ $ pwd
/home/reader
~ $

image

@liweinan
Copy link
Author

liweinan commented Oct 2, 2019

~ $ pwd
/home/reader
~ $ id reader
uid=1000(reader) gid=1000(reader) groups=1000(reader)
~ $ id root
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
~ $

image

@liweinan
Copy link
Author

liweinan commented Oct 2, 2019

9711570009825_ pic_hd

@liweinan
Copy link
Author

liweinan commented Oct 2, 2019

9721570010548_ pic_hd

@liweinan
Copy link
Author

liweinan commented Oct 2, 2019

9741570028859_ pic_hd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment