小编Jam*_*ore的帖子

从C - Bus错误10测试Shellcode

下面,我写了一个打印'Hello,World!'的x64程序集.来自Mac OS X 10.8上的系统调用.它独立执行时汇编并运行完美.

; Assemble and link with:
; nasm -f macho64 -o HelloWorld.o HelloWorld.s
; ld -arch x86_64 -o HelloWorld HelloWorld.o

global start

section .text

start:

    push rbp
    mov rbp, rsp

    jmp short String

    xor rdi, rdi
    mov di, 0x01

StringRet:
    pop rsi

    xor rdx, rdx
    mov dl, 0xE

    mov r8b, 0x02
    shl r8, 24
    or r8, 0x04
    mov rax, r8

    syscall            ; System call for write(4)

    xor edi, edi

    mov r8b, 0x02
    shl r8, 24
    or r8, …
Run Code Online (Sandbox Code Playgroud)

c macos assembly shellcode

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

根据模板参数删除成员

我想设计一个带矢量优化的矢量类.看起来像:

template <typename T, int small_size = 0>
class Vector {
private:
    T data_small_[small_size];
    T* data_;
    T* size_;
    T* capacity_;
public:
    ...
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,大多数情况下,该类将与small_size = 0一起使用.有没有办法删除data_small_ for small_size = 0而不进入模板专门化并重写该类的整个代码?

c++ templates vector

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

x86汇编比较参数

我正在使用Visual Studio并从C++调用程序集.我知道当你将参数传递给汇编时,第一个参数是在ECX中,第二个参数在EDX中.为什么我不能直接比较两个寄存器而不先将ECX复制到EAX?

C++:

#include <iostream>

extern "C" int PassingParameters(int a, int b);

int main()
{
    std::cout << "The function returned: " << PassingParameters(5, 10) << std::endl;

    std::cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

ASM:直接比较两个寄存器时,这会给出错误的值.

.code
PassingParameters proc
    cmp edx, ecx
    jg ReturnEAX

    mov eax, edx

ReturnEAX:
    ret
PassingParameters endp
end
Run Code Online (Sandbox Code Playgroud)

但如果我像这样写它,我得到正确的值,并可以直接比较两个寄存器,为什么这样?

.code
PassingParameters proc
    mov eax, ecx ; copy ecx to eax.
    cmp edx, ecx ; compare ecx and edx directly like above, but this gives the correct value.
    jg ReturnEAX

    mov eax, …
Run Code Online (Sandbox Code Playgroud)

c++ assembly visual-studio

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

从.txt文件中读取并执行Shellcode

从C总线测试Shellcode错误10

上面是我之前的问题,当shell代码在源代码中时,它涉及从ac程序中清除shellcode.它由Carl Norum解决,并且由于记忆保护.我有一个不同的问题但是很相似.我没有将shell代码放在同一个文件中,而是想从.txt文件中读取shell代码并执行它.下面我尝试将一段内存标记为PROT_EXEC,并将.txt文件的内容读入其中并执行.但是它不起作用,我得到了同样的错误,KERN_PROTECTION_FAILURE,我尝试使用mprotect和mmap将一段内存标记为PROT_EXEC.

#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>

int (*ret)();

unsigned char* buf;

int main()
{
    FILE* file;
    file = fopen("text.txt", "rb");

    fseek(file, 0, SEEK_END);
    unsigned int len = ftell(file);
    fseek(file, 0, SEEK_SET);

    buf = valloc(len);
    fread(buf, 1, len, file);

    fclose(file);

    mprotect(buf, len, PROT_EXEC);

   // I also tried mmap, but same error.
   /* void *ptr = mmap(0, 1024, PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);

    if (ptr == MAP_FAILED)
    {
        perror("mmap");
        exit(-1);
    }

    memcpy(ptr, buf, 1024);*/

    ret = …
Run Code Online (Sandbox Code Playgroud)

c macos shellcode

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

标签 统计

assembly ×2

c ×2

c++ ×2

macos ×2

shellcode ×2

templates ×1

vector ×1

visual-studio ×1