据我了解,这些是.section指令:
awxMSGT
Run Code Online (Sandbox Code Playgroud)
如果使用 COFF 格式,“旧”指令具有“只读”。
如何将 ELF 格式的 .section 设置为只读?根本没有说明符吗?
我终于回到了我的 colorforth 项目,几年前当 binutils 的更新破坏了我的所有资源时,我放弃了这个项目。这是正在发生的事情的一个例子:
jcomeau@aspire:~$ cat /tmp/test.as
.intel_syntax
.arch i386
.code32
mov eax,[foo + eax*4]
lea ecx,[ecx*4+0x9e0]
mov edx,DWORD PTR [edi*4-0x4]
jmp DWORD PTR [ecx*4+0x12cc]
lea edx,[ecx+edx*1]
Run Code Online (Sandbox Code Playgroud)
第一个非指令行来自手册中的示例:https : //sourceware.org/binutils/docs/as/i386_002dMemory.html#i386_002dMemory,其余来自 objdump 反汇编--disassembler-options=intel。每一个都无法组装:
jcomeau@aspire:~$ as /tmp/test.as
/tmp/test.as: Assembler messages:
/tmp/test.as:4: Error: too many memory references for `mov'
/tmp/test.as:5: Error: too many memory references for `lea'
/tmp/test.as:6: Error: too many memory references for `mov'
/tmp/test.as:8: Error: too many memory references for `lea'
/tmp/test.as:7: Error: invalid operands (*UND* …Run Code Online (Sandbox Code Playgroud) 我有一个简单的C程序示例: -
#include <stdio.h>
int main()
{
printf("hello world!");
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我使用以下命令编译它并生成程序集: -
riscv32-unknown-elf-gcc -S hello.c -o hello.asm
Run Code Online (Sandbox Code Playgroud)
其中生成以下程序集: -
.file "hello.c"
.option nopic
.section .rodata
.align 2
.LC0:
.string "hello world!"
.text
.align 2
.globl main
.type main, @function
main:
addi sp,sp,-16
sw ra,12(sp)
sw s0,8(sp)
addi s0,sp,16
lui a5,%hi(.LC0)
addi a0,a5,%lo(.LC0)
call printf
li a5,1
mv a0,a5
lw ra,12(sp)
lw s0,8(sp)
addi sp,sp,16
jr ra
.size main, .-main
.ident "GCC: (GNU) 7.2.0"
Run Code Online (Sandbox Code Playgroud)
有一个预期的call printf行,但因为在这个程序集文件中没有printf的实现,我本来希望看到它请求外部实现这样的东西......
.global …Run Code Online (Sandbox Code Playgroud) 我正在尝试为不允许 0x00 字节的 CTF 挑战编写 shellcode(它将被解释为终止符)。由于挑战的限制,我必须做这样的事情:
[shellcode bulk]
[(0x514 - sizeof(shellcode bulk)) filler bytes]
[fixed constant data to overwrite global symbols]
[shellcode data]
Run Code Online (Sandbox Code Playgroud)
它看起来像这样
.intel_syntax noprefix
.code32
shellcode:
jmp sc_data
shellcode_main:
#open
xor eax, eax
pop ebx //file string
xor ecx, ecx //flags
xor edx, edx //mode
mov al, 5 //sys_OPEN
int 0x80
... // more shellcode
.org 514, 0x41 // filler bytes
.long 0xffffffff // bss constant overwrite
sc_data:
call shellcode_main
.asciz "/path/to/fs/file"
Run Code Online (Sandbox Code Playgroud)
如果sc_data在shellcode. 在这种情况下,汇编器 …
我正在使用汇编学习 x86 实模式下的中断处理。我正在遵循从这里获取的以下示例:
.include "common.h"
BEGIN
CLEAR
/* Set address of the handler for interrupt 0. */
movw $handler, 0x00
/* Set code segment of the handler for interrupt 0. */
mov %cs, 0x02
int $0
PUTC $'b
hlt
handler:
PUTC $'a
iret
Run Code Online (Sandbox Code Playgroud)
但是当我编译并运行上面的代码时,
$ as --32 -o main.o main.S -g
$ ld -T linker.ld -o main.img --oformat binary -m elf_i386 -nostdlib main.o
$ qemu-system-i386 -hda main.img
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
qemu-system-i386: Trying to execute code outside RAM or ROM at …Run Code Online (Sandbox Code Playgroud) 从我发现的所有文档中,没有提到像offset[var+offset2]Intel x86 语法那样的语法,但是 GCC 有以下标志
gcc -S hello.c -o - -masm=intel
对于这个程序
#include<stdio.h>
int main(){
char c = 'h';
putchar(c);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
产生
.file "hello.c"
.intel_syntax noprefix
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp
.cfi_def_cfa_register 6
sub rsp, 16
mov BYTE PTR -1[rbp], 104
movsx eax, BYTE PTR -1[rbp]
mov edi, eax
call putchar@PLT
mov eax, 0
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size …Run Code Online (Sandbox Code Playgroud) 我的意思是我在 NASM 中这样写的东西:
mov dword [0xA0BF17C], ' : )'
Run Code Online (Sandbox Code Playgroud)
我在 GNU 汇编程序中尝试过这样的事情:
movd " : )", 0xB8000
movd $" : )", 0xB8000
movd ' : )', 0xB8000
movd " : )", $0xB8000
Run Code Online (Sandbox Code Playgroud)
但是......他们都导致了这个错误:
Error: unbalanced parenthesis in operand 1.
Run Code Online (Sandbox Code Playgroud) 当 GAS 支持多种架构而 NASM 只支持 x86 架构时,为什么我要在 GNU 汇编器 (GAS) 上使用 NASM?我知道存在句法差异,但这并没有让我太困扰。
在以下编译器输出中:
a:
.long 4
b:
.byte 99
x:
.zero 4
c:
.byte 12
f:
.zero 4
Run Code Online (Sandbox Code Playgroud)
该.zero指令是什么意思?它似乎是唯一未在gas directives. 只是从上面看,long是四个字节,.byte是一个字节,我猜是四个字节的.zero零(或指令后面的任何数字)。那是对的吗?
如果是这样,为什么不这样做.long 0。这是否将其放在不同的部分或其他内容中?
我目前正在编写一些 x86 汇编代码,并使用as和将其与 glibc 链接ld。
.section .data
str1:
.asciz "\n"
str3:
.asciz "Hello"
str4:
.asciz "Goodbye"
str5:
.asciz "Guten Tag!"
str6:
.asciz "Guten Morgen!"
.section .bss
.section .text
.globl _start
_start:
call main
movl %eax, %ebx
movl $1, %eax
int $0x80
# void writeLine(char*);
.type writeLine, @function
writeLine:
pushl %ebp
movl %esp, %ebp
movl $str1, %ecx
pushl %ecx
movl 8(%ebp), %ecx
pushl %ecx
call strcat
movl %eax, %ecx
pushl %ecx
call puts
popl %ebx
.leaver1:
movl …Run Code Online (Sandbox Code Playgroud) assembly ×10
gnu-assembler ×10
x86 ×6
gcc ×2
intel-syntax ×2
att ×1
elf ×1
gnu ×1
interrupt ×1
libc ×1
machine-code ×1
nasm ×1
riscv ×1
shellcode ×1
x86-16 ×1