mac nasm osx_nasm mac - CSDN
  • Mac OSX nasm安装与更新

    2016-03-22 09:45:36
    对于MAC系统nasm版本比较老,然而很多的第三方C开源库的编译要求的nasm版本会比较高,那我们怎么来安装或者更新Mac里的nasm呢,废话少说开始动手吧 1、打开Finder ——>应用程序 ——> 实用工具——>终端 ...

    我用的MAC系统版本是OS X EI Capitan 10.11.1


    对于MAC系统nasm版本比较老,然而很多的第三方C开源库的编译要求的nasm版本会比较高,那我们怎么来安装或者更新Mac里的nasm呢,废话少说开始动手吧


    1、打开Finder ——>应用程序 ——> 实用工具——>终端


    2、在命令行中输入如下命令(复制粘贴就好)

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null


    3、上述命令执行完毕后,输入如下命令

    brew install nasm

    4、将MAC重新启动,在终端中输入

    nasm -v

    就可以看到最新版本的nasm啦,腻不腻害呀?


    展开全文
  • MAC下使用nasm编译汇编

    2016-03-03 21:03:31
    汇编的基础知识我们知道, 对于计算机的CPU而言, 无论是指令还是数据, 都是以机器码的形式存在于计算机当中。我们的高级语言都需要通过编译器或者解释器转化成机器码才能...NASM简介nasm是一款开源的汇编语言编译器, 其

    汇编的基础知识

    我们知道, 对于计算机的CPU而言, 无论是指令还是数据, 都是以机器码的形式存在于计算机当中。我们的高级语言都需要通过编译器或者解释器转化成机器码才能执行。

    对于不同的CPU而言, 其可以识别的汇编语言并不相同, 这就决定了汇编语言并不具备良好的可移植性。所以我们在编译汇编代码的时候,需要注意汇编的代码是否与当前的机器CPU兼容。

    NASM简介

    nasm是一款开源的汇编语言编译器, 其官网在

    http://www.nasm.us/


    在这个官网上面, 我们可以找到开发文档和历史上的所有版本。

    在mac os上配置nasm

    首先, 我们会发现, 在我们的mac上面早已安装好了nasm,但是我们看版本的话

    nasm -v

    会发现这一个版本太过久远, 特别是不支持64位处理器代码的编译, 这将给我们带来极大的困难。所以, 我们需要将下载的最新版本的nasm来代替原有的老版本的nasm.
    我们执行下面的语句:

    which nasm
    cp nasm <route of nasm>


    将我们下载的nasm复制到指定的地点来覆盖原有的nasm,我们再次检查版本号,就会发现我们的nasm已经被我们更新到最新的版本了。

    在mac上使用nasm

    使用我们最熟悉的命令man来查询nasm支持的CPU框架, 我们得到下面的信息:

    ```
    valid output formats for -f are (`*' denotes default):
      * bin       flat-form binary files (e.g. DOS .COM, .SYS)
        ith       Intel hex
        srec      Motorola S-records
        aout      Linux a.out object files
        aoutb     NetBSD/FreeBSD a.out object files
        coff      COFF (i386) object files (e.g. DJGPP for DOS)
        elf32     ELF32 (i386) object files (e.g. Linux)
        elf64     ELF64 (x86_64) object files (e.g. Linux)
        elfx32    ELFX32 (x86_64) object files (e.g. Linux)
        as86      Linux as86 (bin86 version 0.3) object files
        obj       MS-DOS 16-bit/32-bit OMF object files
        win32     Microsoft Win32 (i386) object files
        win64     Microsoft Win64 (x86-64) object files
        rdf       Relocatable Dynamic Object File Format v2.0
        ieee      IEEE-695 (LADsoft variant) object file format
        macho32   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files
        macho64   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
        dbg       Trace of all info passed to output stage
        elf       ELF (short name for ELF32)
        macho     MACHO (short name for MACHO32)
        win       WIN (short name for WIN32)

    选择合适的框架, 现在的苹果MBP需要使用macho64来编译, 生成可执行文件, 然后就可以执行了。

    展开全文
  • mac os X 下用nasm大杂烩

    2013-05-09 20:35:37
    section .data msg db 'This is a test', 10, 0 ; something stupid here ft db 'addr is %x',10,0 section .text global _main extern _printf extern _exit _main: push rbp
    section .data
        msg db 'This is a test', 10, 0    ; something stupid here
        ft db 'addr is %x',10,0
    
    section .text
        global _main
        extern _printf
        extern _exit
    
    _main:
        push    rbp
        mov     rbp, rsp       
    
        ;xor     al, al
        mov     rdi, ft
        ;lea rdi,[rel ft]
        mov rsi,rdi
        call    _printf
    
    	;xor rax,rax
    	;mov [rax],rax
    
    	xor rdi,rdi
    	call _exit
        ;mov     rsp, rbp
        ;pop     rbp
        ret
        

    mac OS X 10.8.3:

    nasm -f macho x.asm

    gcc -o x x.o


    会出现警告:

    ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _main from a.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie

    由于安全问题,解释如下:

    所谓的PIE是指position independent executable,即地址无关exe,换句话说也就是生成的机器码中不能出现lea rax, some_symbol_name这样的绝对寻址,而只能以:lea rax, [rel some_symbol_name]这种形式出现,目的是为了提高安全性,这样OS可以以随机的地址加载exe。

    采用相对地址定位即可:使用第16行指令代替。

    x64 API接口有用的提示:

    Mac OS X complies to the System V ABI - AMD64 Architecture Processor Supplement. It mandates that the fist 6 integer/pointer arguments are passed in RDIRSIRDXRCXR8 and R9, exactly in that order. The first 8 floating-point or vector arguments go into XMM0XMM1, ..., XMM7. Only after all the available registers are depleted or there are arguments that cannot fit in any of those registers (e.g. a 80-bit long double value) the stack is used. 64-bit pushes are performed using MOV (the QWORDvariant) and not PUSH. Simple return values are passed back in the RAX register. The caller must also provide stack space for the callee to save some of the registers.

    printf is a special function because it takes variable number of arguments. When calling such functions RAX should be set to the number of floating-point arguments, passed in the vector registers. Also note that RIP-relative addressing is preferred for data that lies within 2 GiB of the code.


    关于mac OS X系统调用号有用提示:

    Mac OS X 64 bit Assembly System Calls

    After reading about shellcode in Chapter 5 of Hacking: The Art of Exploitation, I wanted to go back through some of the examples and try them out. The first example was a simple Hello World program in Intel assembly. I followed along in the book and had no problems reproducing results on a 32 bit Linux VM using nasm with elf file format and ld for linking.

    Then I decided I wanted to try something similar but with a little bit of a challenge: write a Mac OS X 64 bit “hello world” program using the new fast ‘syscall’ instruction instead of the software interrupt based (int 0×80) system call, this is where things got interesting.

    First and foremost, the version of Nasm that comes with Mac OS X is a really old version. If you want to assemble macho64 code, you’ll need to download the lastest version.

    nobody@nobody:~$ nasm -v
    NASM version 2.09.03 compiled on Oct 27 2010
    

    I figured I could replace the extended registers with the 64 bit registers and the int 0×80 call with a syscall instruction so my first attempt was something like this

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    section .data
    hello_world     db      "Hello World!", 0x0a
     
    section .text
    global _start
     
    _start:
    mov rax, 4              ; System call write = 4
    mov rbx, 1              ; Write to standard out = 1
    mov rcx, hello_world    ; The address of hello_world string
    mov rdx, 14             ; The size to write
    syscall                 ; Invoke the kernel
    mov rax, 1              ; System call number for exit = 1
    mov rbx, 0              ; Exit success = 0
    syscall                 ; Invoke the kernel

    After assembling and linking, I got this

    nobody@nobody:~$ nasm -f macho64 helloworld.s
    nobody@nobody:~$ ld helloworld.o 
    ld: could not find entry point "start" (perhaps missing crt1.o) for inferred architecture x86_64
    

    Apparently Mac OS X doesn’t use ‘_start’ for linking, instead it just uses ‘start’. After removing the underscore prefix from start, I was able to link but after running, I got this

    nobody@nobody:~$ ./a.out
    Bus error
    

    I was pretty stumped at this point so I headed off to Google to figure out how I was supposed to use the ‘syscall’ instruction. After a bunch of confusion, I stumbled upon the documentation and realized that x86_64 uses entirely different registers for passing arguments. From the documentation:

    The number of the syscall has to be passed in register rax.
    
    rdi - used to pass 1st argument to functions
    rsi - used to pass 2nd argument to functions
    rdx - used to pass 3rd argument to functions
    rcx - used to pass 4th argument to functions
    r8 - used to pass 5th argument to functions
    r9 - used to pass 6th argument to functions
    
    A system-call is done via the syscall instruction. The kernel destroys registers rcx and r11.
    

    So I tweaked the code with this new information

    ...
    mov rax, 4              ; System call write = 4
    mov rdi, 1              ; Write to standard out = 1
    mov rsi, hello_world    ; The address of hello_world string
    mov rdx, 14             ; The size to write
    syscall                 ; Invoke the kernel
    mov rax, 1              ; System call number for exit = 1
    mov rdi, 0              ; Exit success = 0
    syscall                 ; Invoke the kernel
    ...
    

    And with high hopes that I’d see “Hello World!” on the console, I still got the exact same ‘Bus error’ after assembling and linking. Back to Google to see if others had tried a write syscall on Mac OS X. I found a few posts of people having success with the syscall number 0×2000004 so I thought I’d give it a try. Similarly, the exit syscall number was 0×2000001. I tweaked the code and BINGO! I was now able to see “Hello World” output on my console but I was seriously confused at this point; what was this magic number 0×200000 that is being added to the standard syscall numbers?

    I looked in syscall.h to see if this was some sort of padding (for security?) I greped all of /usr/include for 0×2000000 with no hints what-so-ever. I looked into the Mach-o file format to see if it was related to that with no luck.

    After about an hour and a half of looking, I spotted what I was looking for in ‘syscall_sw.h’

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /*
     * Syscall classes for 64-bit system call entry.
     * For 64-bit users, the 32-bit syscall number is partitioned
     * with the high-order bits representing the class and low-order
     * bits being the syscall number within that class.
     * The high-order 32-bits of the 64-bit syscall number are unused.
     * All system classes enter the kernel via the syscall instruction.
     *
     * These are not #ifdef'd for x86-64 because they might be used for
     * 32-bit someday and so the 64-bit comm page in a 32-bit kernel
     * can use them.
     */
    #define SYSCALL_CLASS_SHIFT 24
    #define SYSCALL_CLASS_MASK  (0xFF << SYSCALL_CLASS_SHIFT)
    #define SYSCALL_NUMBER_MASK (~SYSCALL_CLASS_MASK)
     
    #define SYSCALL_CLASS_NONE  0   /* Invalid */
    #define SYSCALL_CLASS_MACH  1   /* Mach */ 
    #define SYSCALL_CLASS_UNIX  2   /* Unix/BSD */
    #define SYSCALL_CLASS_MDEP  3   /* Machine-dependent */
    #define SYSCALL_CLASS_DIAG  4   /* Diagnostics */

    Mac OS X or likely BSD has split up the system call numbers into several different “classes.” The upper order bits of the syscall number represent the class of the system call, in the case of write and exit, it’s SYSCALL_CLASS_UNIX and hence the upper order bits are 2! Thus, every Unix system call will be (0×2000000 + unix syscall #).

    Armed with this information, here’s the final x86_64 Mach-o “Hello World”

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    section .data
    hello_world     db      "Hello World!", 0x0a
     
    section .text
    global start
     
    start:
    mov rax, 0x2000004      ; System call write = 4
    mov rdi, 1              ; Write to standard out = 1
    mov rsi, hello_world    ; The address of hello_world string
    mov rdx, 14             ; The size to write
    syscall                 ; Invoke the kernel
    mov rax, 0x2000001      ; System call number for exit = 1
    mov rdi, 0              ; Exit success = 0
    syscall                 ; Invoke the kernel
    nobody@nobody:~$ nasm -f macho64 helloworld.s
    nobody@nobody:~$ ld helloworld.o 
    nobody@nobody:~$ ./a.out
    Hello World!

    总结如下:

    因为mac OS X 10.8.3是64位系统,如果想要写汇编代码可有2种方式:

    1 32位方式 macho32 ,但是要有32位的C库,你可以按照老的API ABI接口写程序,即

    push xxx,push xxx,call xxx。

    2 64位方式 macho64 ,使用新的64位ABI调用C库,或者你直接用syscall调用。

    最后你可以用mac OS X自带的as汇编器来搞:

    gcc -S -o x.s x.c

    as -o x.o x.s

    gcc -o x x.o


    展开全文
  • Mac升级nasm

    2019-03-05 11:34:53
    Mac上进行开源软件的编译,提示nasm版本过低,不想disable-asm,尝试进行nasm升级。 过程 由于之前都是使用Windows和Linux进行开发,对Mac不太熟悉,在网上查找了一些方法,绝大部分都是如下做法: 1)在终端...

    前言

    在Mac上进行开源软件的编译,提示nasm版本过低,不想disable-asm,尝试进行nasm升级。

    过程

    由于之前都是使用Windows和Linux进行开发,对Mac不太熟悉,在网上查找了一些方法,绝大部分都是如下做法:

    1)在终端命令行中输入如下命令(复制粘贴就好)
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null 
    2)上述命令执行完毕后,输入如下命令
    brew install nasm 
    3)将MAC重新启动,在终端中输入,查看最新版本
    nasm -v
    

    经过以上方法后,nasm -v查看nasm版本并未发生变化。
    查找发现“/usr/local/Cellar”目录下有个nasm文件夹,执行如下命令

     /usr/local/Cellar/nasm/2.14.02/bin/nasm -v
    

    显示是2.14.02 版本的。
    而执行

    /usr/bin/nasm -v
    

    版本还是旧版本。
    推测nasm是升级安装成功了,但是是安装到了“/usr/local/Cellar”目录下,没有替换到/usr/bin,因此想要将/usr/local/Cellar/nasm/2.14.02/bin/nasm拷贝到/usr/bin/nasm,但是在执行拷贝时,报错

    operation not permitted
    

    应该是权限问题,经过网上查找原因是:电脑启用了SIP(System Integrity Protection),增加了rootless机制,导致即使在root权限下依然无法修改文件,在必要时候为了能够修改下面的文件,我们只能关闭该保护机制。具体操作如下:

    1)重启,过程中按住 Command+R,进入保护模式(我用的普通蓝牙键鼠套装,用“Win键”代替“Command键”)
    2)打开terminal终端,输入
    csrutil disable
    3)再次重启,即可对 usr/bin 目录下文件进行修改
    经过以上操作后,nasm拷贝替换成功,执行

    nasm -v
    

    显示已是升级版本。
    再次进行编译没有报nasm过低的错误。

    展开全文
  • 先在 pc 上编译,熟悉一下。...nasm -DUNIX64 -DPREFIX -f macho64 -I./codec/common/x86/ -o codec/common/x86/cpuid.o codec/common/x86/cpuid.asm nasm: fatal: unrecognised output format `macho64' - use -hf...
  • This lib doesn't use dependency management tool. You have to installnasm, an assembly compiler. download and install it from shell: Linux & cie sudo apt-get install nasm ...Mac OSX (withHo...
  • 教你在Mac上写汇编!

    2019-06-14 10:42:39
    mac自带了nasm, 但是, 但是, 但是, 老得一塌糊涂. apple版本 brew install nasm 安装完之后重启. 最新版本 撰写编译运行 之后就是和写c差不多了. 但是, 我们要讲究一些, 写个32, 写个64, 好吧. ...
  • mkdir cp -f ls -l =============================================== brew install nasm  brew uninstall brew list ...============================================ ...nasm boot.asm -o boot.bi
  • 安装masm5 下载masm5 解压 家目录新建masm5目录,解压在该目录下 安装Dosbox 下载Dosbox 运行DOSBox.dmg: 挂载 debug
  • 在安装yaf拓展时,使用到了phpize,在执行 phpize 时会出现以下报错 Cannot find autoconf. Please check your autoconf installation and the $...初次使用 phpize 需要 安装 autoconf 请...
  • vcpkg支持多平台,Windows、Linux以及Mac。自动集成开源第三方C 和 C++ 库,如openssl等。摘自官网:vcpkg未添加到任何环境变量,并且不依赖于Windows注册表或Visual Studio
  • mac下编译ijkplayer

    2017-06-04 15:37:17
    mac或者linux环境下编译ijkplayer相对于window...Homebrew是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件,相当于linux下的apt-get、yum神器;Homebre可以在Mac上安装一些OS X没有的UNIX工具,H
  • 64-bit FFmpeg on Mac OS X Lion or Snow Leopard Posted by Martin in Science (updated September 26, 2011) FFmpeg (http://www.ffmpeg.org) is open source software to record, convert a
  • 操作系统:mac osx 将汇编代码写入磁盘的0柱面,0磁道,1扇区,开机启动后bios会自动加载这512字节到内存0x7c00处,然后跳到这开始执行。 在屏幕上显示字符,可以直接写到显存里,就直接在屏幕上显示出来了,显存...
  • 编译boot loader Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 C:\Users\LostSpeed>d: D:\>cd D:\prj\nasm_prj\...D:\prj\nasm_prj\boot\boot_dispmsg>C:\nasm\n
  • FFmpeg 在macOS上的编译

    2018-03-05 10:48:36
     (注:下载下来的是master分支,一开始我也是在主分支编译,结果输出的程序只有ffmpeg,ffprobe, 而ffplay,ffserver,没有出来,文章后面会提到怎么把这两个编出来。)2.拿到源代码了,想必大家就急着编译吧,是的,...
  • Mac 开发配置手册 手册内容为「如何让一部全新的 MacBook 快速完成开发环境配置」,主要面向 Web 开发者。其中的指导,在 Mavericks 和 Yosemite 上有效,其他版本系统并未尝试。 如果你是一名老手,本手册让你减少...
  • 之前在MAC OS折腾编译iOS版linphone-iphone SDK和APP成功,下一步继续编译Android版的linphone-android。Android版的文档更简单,一个README.TXT就结束,然后各种调查。简单说明一下linphoneLinphone is an open ...
1 2 3 4
收藏数 73
精华内容 29
关键字:

mac nasm osx