博客 / 詳情

返回

二進制分析實戰--環境搭建

安裝依賴環境

brew install riscv-gnu-toolchain

riscv64-unknown-elf-gcc --version

makefile

all:
    riscv64-unknown-elf-gcc -g  hello.c -o hello.out
#預處理
e:
    riscv64-unknown-elf-gcc  -E -P hello.c -o hello.e
#編譯
s:
    riscv64-unknown-elf-gcc -S hello.c
#彙編
c:
    riscv64-unknown-elf-gcc -c hello.c
run:all
    ./hello.o

clean:
    rm -f hello.out hello.o hello.S hello.e

c代碼

#include <stdio.h>

#define FORMAT_STRING "%s"
#define MESSAGE "hello world\n"

int main() {
    printf(FORMAT_STRING, MESSAGE);
    return 0;
}

file hello.o

hello.o: ELF 64-bit LSB relocatable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), not stripped

file hello.out

hello.out: ELF 64-bit LSB executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped

剝離二進制文件:

riscv64-unknown-elf-strip --strip-all hello.out

剝離之後

hello.out: ELF 64-bit LSB executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), statically linked, stripped

解釋:
relocatable:
not stripped:
statically linked:

user avatar
0 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.