相关疑难解决方法(0)

132
推荐指数
4
解决办法
10万
查看次数

在C中_start()有什么用?

我从同事那里了解到,无需编写函数即可编写和执行C程序main().它可以在下面完成

withoutMain.c

/* Compile this with gcc -nostartfiles */

#include <stdlib.h>

void _start() {
  int ret = my_main();
  exit(ret); 
}

int my_main() {
  puts("This is a program without a main() function!");
  return 0; 
}
Run Code Online (Sandbox Code Playgroud)

将其编译为: my_main.c

运行方式为: main()

我的问题是,何时需要做这种事情?一些现实世界的场景?

c

115
推荐指数
3
解决办法
2万
查看次数

如果我要在程序集中编写程序,那么这个HelloWorld汇编代码的哪些部分是必不可少的?

我有这个简短的你好世界计划:

#include <stdio.h>

static const char* msg = "Hello world";

int main(){
    printf("%s\n", msg);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我用gcc将它编译成以下汇编代码:

    .file   "hello_world.c"
    .section    .rodata
.LC0:
    .string "Hello world"
    .data
    .align 4
    .type   msg, @object
    .size   msg, 4
msg:
    .long   .LC0
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    andl    $-16, %esp
    subl    $16, %esp
    movl    msg, %eax
    movl    %eax, (%esp)
    call    puts
    movl    $0, %eax
    leave
    .cfi_restore 5
    .cfi_def_cfa …
Run Code Online (Sandbox Code Playgroud)

c linux x86 assembly

10
推荐指数
1
解决办法
1149
查看次数

Linux 中的“int 80h”是什么?

我想了解我们为什么使用int 80h以及在汇编代码中调用它后会发生什么。像这儿:

int 80h
mov eax,1
int 80h
Run Code Online (Sandbox Code Playgroud)

它怎么知道我要调用系统退出,而不只是在eax中保存十进制数?

linux x86 assembly system-calls linux-kernel

6
推荐指数
1
解决办法
1万
查看次数

$ NAS如何在NASM中工作?

message db "Enter a digit ", 0xA,0xD
Length equ $- message
Run Code Online (Sandbox Code Playgroud)

它用于获取字符串的长度吗?
它在内部如何运作?

x86 assembly nasm

4
推荐指数
1
解决办法
1833
查看次数

使用自己的 python 调试器获取系统调用时出现问题

我试图在 32 位测试 Linux 系统(Lubuntu)上用 python3 编写一个简单的调试器,它应该能够捕获任意程序的所有系统调用(在本例中为:/bin/ls)。为此,我使用 ptrace 系统调用来单步执行该过程。每一步之后,我都会读取寄存器以找到指令指针eip,以从下一条指令读取 2 个字节。如果这 2 个字节是0xcd0x80,则表示int 80是系统调用。我知道还有用于此目的的 PTRACE_SYSCALL,但我想在不使用它的情况下执行此操作。

下面我向您展示代码,它似乎有效, 有一些奇怪的行为:

为了弄清楚这是否有效,我使用strace将其输出与我自己的系统调用进行比较。看来我的程序只显示系统调用的第一部分,第二部分就丢失了。为了向您展示我在下面发布了我的程序和 strace 的输出。有人知道这里可能出什么问题吗?

import os               # os interaction
from struct import pack # dealing with bytes (ptrace)
import ctypes           # support c data structures

""" ========================================================== """

# 32 bit reg process structrue
class UserRegsStruct(ctypes.Structure):
    _fields_ = [
        ("ebx", ctypes.c_ulong),
        ("ecx", ctypes.c_ulong),
        ("edx", ctypes.c_ulong),
        ("esi", ctypes.c_ulong),
        ("edi", ctypes.c_ulong),
        ("ebp", ctypes.c_ulong), …
Run Code Online (Sandbox Code Playgroud)

python linux x86 ptrace system-calls

2
推荐指数
1
解决办法
442
查看次数

你好,有 Linux 系统调用的汇编语言世界?

  1. 我知道这int 0x80会在 linux 中造成中断。但是,我不明白这段代码是如何工作的。它会返回一些东西吗?

  2. 代表什么$ - msg

global _start

section .data
    msg db "Hello, world!", 0x0a
    len equ $ - msg

section .text
_start:
    mov eax, 4
    mov ebx, 1
    mov ecx, msg
    mov edx, len
    int 0x80 ;What is this?
    mov eax, 1
    mov ebx, 0
    int 0x80 ;and what is this?
Run Code Online (Sandbox Code Playgroud)

linux x86 assembly nasm system-calls

0
推荐指数
1
解决办法
1179
查看次数

标签 统计

assembly ×5

linux ×5

x86 ×5

system-calls ×3

c ×2

nasm ×2

abi ×1

linux-kernel ×1

ptrace ×1

python ×1

unix ×1

x86-64 ×1