【问题标题】:NASM Notify-send?NASM 通知发送?
【发布时间】:2013-12-01 21:22:13
【问题描述】:

有没有办法在linux终端显示类似notify-send命令的消息,用NASM编码?

我在 Ubuntu 中使用这个命令:

notify-send "Test"

是否可以使用 NASM 显示类似的内容?

【问题讨论】:

    标签: linux ubuntu terminal nasm


    【解决方案1】:

    您想将文本发送到桌面并在弹出窗口中显示?好吧,我对notify-send 东西一无所知,所以我进行了搜索,发现您可以使用通知库编写一些东西。总而言之,我花了 10 分钟的时间阅读了一些文档、示例代码并编写了这个......

    bits 64 
    extern notify_init, notify_notification_new, notify_notification_show, notify_uninit
    
    extern exit
    
    section .data
    name            db  "Sample Notification", 0
    title           db  "Just a test", 0
    
    global main
    section .text
    main:
        mov     rdi, name
        call    notify_init 
    
        mov     rdx, 0
        mov     rsi, title
        mov     rdi, name
        call    notify_notification_new
    
        mov     rsi, 0
        mov     rdi, rax
        call    notify_notification_show
    
        call    notify_uninit
    
        call    exit
    

    制作文件:

    APP = notify
    $(APP): $(APP).o
        gcc -o $(APP) $(APP).o -lnotify
    
    $(APP).o: $(APP).asm
        nasm -f elf64 $(APP).asm
    

    您需要使用apt-get 或您的包管理器安装libnotify-dev

    对于 32 位系统应该是类似的。

    Gnome Notify Docs

    【讨论】:

    • 奇怪,我在网上找不到任何东西,我只在 stackoverflow 上找到了我自己的问题。但是,谢谢,我会看看!另外,由于我对 linux 还很陌生,在我编译之后,通知还会显示在没有安装 libnotify-dev 的系统上吗?
    • 很好的例子。不知道可以做到。只是我遇到的一个小问题。如果没有 -fPIE,该程序将无法编译,甚至我无法编译它。一个解决方案是(原始代码稍作修改:用_start和makefile替换main:BIN=notify NASM=/usr/bin/nasm NASMOPTS=-felf64 -Fdwarf LDOPS=-melf_x86_64 -g --dynamic-linker /lib64 /ld-linux-x86-64.so.2 LIBS=-lc -lnotify .PHONY: all clean all: $(BIN) clean: rm -rf $(BIN) %: %.asm $(NASM) $(NASMOPTS ) -o $@.o $
    【解决方案2】:

    很好的例子。不知道可以做到。只是我遇到的一个小问题。没有-fPIE我无法编译它,即使使用它我也无法编译它(也许C专家帮助我)。

    解决方案是(对原始代码稍作修改: 用 global _start 替换 global main 和 标签 main: 和 _start: 然后使用下一个makefile:

    BIN=notify
    NASM=/usr/bin/nasm
    NASMOPTS=-felf64 -Fdwarf
    LDOPS=-melf_x86_64 -g --dynamic-linker /lib64/ld-linux-x86-64.so.2
    LIBS=-lc -lnotify
    
    .PHONY: all clean
    
    all: $(BIN)
    
    clean:
    rm -rf $(BIN)
    
    %: %.asm
        $(NASM) $(NASMOPTS) -o $@.o $<
        $(LD) $(LDOPS) -o $@ $@.o $(LIBS)
        rm -f $@.o
    

    【讨论】:

      猜你喜欢
      • 2011-12-10
      • 1970-01-01
      • 2018-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-18
      • 2018-11-27
      • 1970-01-01
      相关资源
      最近更新 更多