본문 바로가기
Security/Reversing

[어셈블리어 분석 실습] example 1

by 단월໒꒱ 2022. 5. 8.

example1.asm의 코드는 아래와 같다.

 

 

# example1.asm
.file	"example1.c"
.section	.rodata
.LC0:
	.string	"Hello world"
	.text
	.globl	main
	.type	main, @function
main:
	.LFB0:
	.cfi_startproc
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$.LC0, %edi
	movl	$0, %eax
	call	printf
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4"
	.section	.note.GNU-stack,"",@progbits

 

 

먼저 main 함수 부분을 살펴보았다. (main: 이후에 나오는 부분을 보면 된다.)

 

 

main:
	.LFB0:
	.cfi_startproc
	pushq	%rbp  #rbp를 스택에 push
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp   #rbp를 rsp로 옮겨줌, rbp = rsp
	.cfi_def_cfa_register 6
	movl	$.LC0, %edi   #LC0을 edi에 저장, 여기서 LC0은 "Hello world"
	movl	$0, %eax   #0을 eax에 저장
	call	printf   #printf 함수 호출
	movl	$0, %eax   #0을 eax에 저장
	popq	%rbp   # rbp 꺼냄
	.cfi_def_cfa 7, 8
	ret   #return address 주소로 리턴
	.cfi_endproc

 

 

위의 과정을 바탕으로 C언어로 나타내면 아래와 같다.

 

 

#include <stdio.h>

int main() {
    printf("Hello world");
    
    return 0;
}

 

 

 

댓글