【发布时间】:2013-12-01 21:22:13
【问题描述】:
有没有办法在linux终端显示类似notify-send命令的消息,用NASM编码?
我在 Ubuntu 中使用这个命令:
notify-send "Test"
是否可以使用 NASM 显示类似的内容?
【问题讨论】:
标签: linux ubuntu terminal nasm
有没有办法在linux终端显示类似notify-send命令的消息,用NASM编码?
我在 Ubuntu 中使用这个命令:
notify-send "Test"
是否可以使用 NASM 显示类似的内容?
【问题讨论】:
标签: linux ubuntu terminal nasm
您想将文本发送到桌面并在弹出窗口中显示?好吧,我对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 位系统应该是类似的。
【讨论】:
很好的例子。不知道可以做到。只是我遇到的一个小问题。没有-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
【讨论】: