• B правой части каждого сообщения есть стрелки и . Не стесняйтесь оценивать ответы. Чтобы автору вопроса закрыть свой тикет, надо выбрать лучший ответ. Просто нажмите значок в правой части сообщения.

  • Курсы Академии Кодебай, стартующие в мае - июне, от команды The Codeby

    1. Цифровая криминалистика и реагирование на инциденты
    2. ОС Linux (DFIR) Старт: 16 мая
    3. Анализ фишинговых атак Старт: 16 мая Устройства для тестирования на проникновение Старт: 16 мая

    Скидки до 10%

    Полный список ближайших курсов ...

Учебник по NASM x64

Ronin

Member
07.09.2019
5
0
BIT
0
Здравствуйте.
Решил изучить ассемблер. Выбрал NASM.
Кто-нибудь может подсказать учебник по этому ассемблеру для 64-битной архитектуры?
Нашел только для 32-битной, ссылка . К нему прилагается файл ( ), при попытке скомпилировать получаю ошибку, судя по трассировке - проблема именно в несовместимости команд.
Работаю под Linux (Ubuntu 18.04).
 

Ronin

Member
07.09.2019
5
0
BIT
0
%include "stud_io.inc"
global _start
section .text
_start: mov eax, 0
again: PRINT "Hello"
PUTCHAR 10
inc eax
cmp eax, 5
jl again
FINISH
;; File stud_io.inc for Linux O.S.
;; Copyright (c) Andrey Vikt. Stolyarov, 2009.
;; I, the author, hereby grant everyone the right to use this
;; file for any purpose, in any manner, in it's original or
;; modified form, provided that any modified versions are
;; clearly marked as such.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; system dependend part

; generic 3-param syscall
%macro _syscall_3 4
push edx
push ecx
push ebx ; it is senseless to save eax as it holds the return
push %1
push %2
push %3
push %4
pop edx
pop ecx
pop ebx
pop eax
int 0x80
pop ebx
pop ecx
pop edx
%endmacro

; syscall_exit is the only syscall we use that has 1 parameter
%macro _syscall_exit 1
mov ebx, %1 ; exit code
mov eax, 1 ; 1 = sys_exit
int 0x80
%endmacro

;; system dependent part ends here
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; %1: descriptor %2: buffer addr %3: buffer length
; output: eax: read bytes
%macro _syscall_read 3
_syscall_3 3,%1,%2,%3
%endmacro

; %1: descriptor %2: buffer addr %3: buffer length
; output: eax: written bytes
%macro _syscall_write 3
_syscall_3 4,%1,%2,%3
%endmacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%macro PRINT 1
pusha
pushf
jmp %%astr
%%str db %1, 0
%%strln equ $-%%str
%%astr: _syscall_write 1, %%str, %%strln
popf
popa
%endmacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%macro PUTCHAR 1
pusha
pushf
%ifstr %1
mov al, %1
%elifnum %1
mov al, %1
%elifidni %1,al
nop
%elifidni %1,ah
mov al, ah
%elifidni %1,bl
mov al, bl
%elifidni %1,bh
mov al, bh
%elifidni %1,cl
mov al, cl
%elifidni %1,ch
mov al, ch
%elifidni %1,dl
mov al, dl
%elifidni %1,dh
mov al, dh
%else
mov al, %1 ; let's hope it is a memory location such as [var]
%endif
sub esp, 2 ; reserve memory for buffer
mov edi, esp
mov [edi], al
_syscall_write 1, edi, 1
add esp, 2
popf
popa
%endmacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%macro GETCHAR 0
pushf
push edi
sub esp, 2
mov edi, esp
_syscall_read 0, edi, 1
cmp eax, 1
jne %%eof_reached
xor eax,eax
mov al, [edi]
jmp %%gcquit
%%eof_reached:
xor eax, eax
not eax ; eax := -1
%%gcquit:
add esp, 2
pop edi
popf
%endmacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%macro FINISH 0-1 0
_syscall_exit %1
%endmacro

Последовательность команд:
$ nasm -f elf64 hello.asm
$ ld hello.o -o hello
На второй команде получаю ошибку

hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:55: ... from macro `PRINT' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:13: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:14: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:15: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:20: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:21: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:22: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:23: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:25: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:26: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:27: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:62: ... from macro `PRINT' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:66: ... from macro `PUTCHAR' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:13: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:14: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:15: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:18: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:20: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:21: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:22: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:23: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:25: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:26: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:27: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:97: ... from macro `PUTCHAR' defined here
 

InetTester

Green Team
21.10.2018
308
43
BIT
5
У меня линкует, но кидает warning
Код:
ld: warning: cannot find entry symbol _start; not setting start address

пробовал на:
Код:
Linux pc 4.19.0-kali4-amd64 #1 SMP Debian 4.19.28-2kali1 (2019-03-18) x86_64 GNU/Linux
 

Ronin

Member
07.09.2019
5
0
BIT
0
Сделал все с начала.
Трассировка та же, после первой команды (очевидно ошибся в прошлом посте, простите чайника).
ld, естессно, не проходит, т.к. нет файла hello.o.

Ассемблер ведь железозависимый? Имеет смысл попробовать на другой машине?

И повторю вопрос - какие есть хорошие учебники по Nasm?
 

InetTester

Green Team
21.10.2018
308
43
BIT
5
Сделал все с начала.
Трассировка та же, после первой команды (очевидно ошибся в прошлом посте, простите чайника).
ld, естессно, не проходит, т.к. нет файла hello.o.

Ассемблер ведь железозависимый? Имеет смысл попробовать на другой машине?

И повторю вопрос - какие есть хорошие учебники по Nasm?

Да железозависимый,
кстати чувство что у меня тоже бинарник в результате 'мертвый' получается, так как судя по ошибке он не может найти точку входа, а это должна быть либо main либо _start,
которые в твоем примере я вообще не вижу, ну или можешь попробовать использовать другой линкер. компилируешь на linux системе?
 

Ronin

Member
07.09.2019
5
0
BIT
0
Да.
Linux RoninPC 5.0.0-36-generic #39~18.04.1-Ubuntu SMP Tue Nov 12 11:09:50 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux.

Проц (по lshw):
Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
разрядность: 64 bits


Линкер - это в данном случае ld? Ошибку выдает команда nasm -f elf64 hello.asm, т.е. до линкера вроде не доходит.
 

InetTester

Green Team
21.10.2018
308
43
BIT
5
да,
я не знаю может какие то зависимости нужно установить(не поверишь но я nasm учил очень давно) попробуй на виртуалку поставь Ubuntu/Deb.. и попробуй там, у меня он на линковке кидает варнинг, но бинарник я получаю все таки...
 

Ronin

Member
07.09.2019
5
0
BIT
0
InetTester, сперва попробую на другой реальной машине.
А точка входа в примере - случайно не четвертая строка (_start: mov eax, 0)?

The Codeby, за ссылку спасибо.
 

SearcherSlava

Red Team
10.06.2017
943
1 260
BIT
159
Приношу извинения, что ответ не совсем по теме: Ассемблер - Assembler

The Codeby, за ссылку спасибо.

Здравы будьте!

Обращаюсь к человеку, искавшему книгу на страницах своей. Возможно, это она:
Паркинсон, Сирил Н. - Законы Паркинсона: Сборник (изд. 1989 г.)
Законы Паркинсона. (Сборник) / Паркинсон – М.: Книга по Требованию,2012. – 224 с

ASM.jpg
 

JustYarka

New member
21.06.2020
2
0
BIT
0
InetTester, сперва попробую на другой реальной машине.
А точка входа в примере - случайно не четвертая строка (_start: mov eax, 0)?

The Codeby, за ссылку спасибо.
Решили проблему?) У меня та же самая возникла, если есть решение, хотелось бы узнать, в чем всё-таки дело)
 

Lunix

New member
18.11.2020
1
0
BIT
0
1605701739421.png

%include "stud_io.inc"
global _start
section .text
_start: mov eax, 0
again: PRINT "Hello"
PUTCHAR 10
inc eax
cmp eax, 5
jl again
FINISH
;; File stud_io.inc for Linux O.S.
;; Copyright (c) Andrey Vikt. Stolyarov, 2009.
;; I, the author, hereby grant everyone the right to use this
;; file for any purpose, in any manner, in it's original or
;; modified form, provided that any modified versions are
;; clearly marked as such.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; system dependend part

; generic 3-param syscall
%macro _syscall_3 4
push edx
push ecx
push ebx ; it is senseless to save eax as it holds the return
push %1
push %2
push %3
push %4
pop edx
pop ecx
pop ebx
pop eax
int 0x80
pop ebx
pop ecx
pop edx
%endmacro

; syscall_exit is the only syscall we use that has 1 parameter
%macro _syscall_exit 1
mov ebx, %1 ; exit code
mov eax, 1 ; 1 = sys_exit
int 0x80
%endmacro

;; system dependent part ends here
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; %1: descriptor %2: buffer addr %3: buffer length
; output: eax: read bytes
%macro _syscall_read 3
_syscall_3 3,%1,%2,%3
%endmacro

; %1: descriptor %2: buffer addr %3: buffer length
; output: eax: written bytes
%macro _syscall_write 3
_syscall_3 4,%1,%2,%3
%endmacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%macro PRINT 1
pusha
pushf
jmp %%astr
%%str db %1, 0
%%strln equ $-%%str
%%astr: _syscall_write 1, %%str, %%strln
popf
popa
%endmacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%macro PUTCHAR 1
pusha
pushf
%ifstr %1
mov al, %1
%elifnum %1
mov al, %1
%elifidni %1,al
nop
%elifidni %1,ah
mov al, ah
%elifidni %1,bl
mov al, bl
%elifidni %1,bh
mov al, bh
%elifidni %1,cl
mov al, cl
%elifidni %1,ch
mov al, ch
%elifidni %1,dl
mov al, dl
%elifidni %1,dh
mov al, dh
%else
mov al, %1 ; let's hope it is a memory location such as [var]
%endif
sub esp, 2 ; reserve memory for buffer
mov edi, esp
mov [edi], al
_syscall_write 1, edi, 1
add esp, 2
popf
popa
%endmacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%macro GETCHAR 0
pushf
push edi
sub esp, 2
mov edi, esp
_syscall_read 0, edi, 1
cmp eax, 1
jne %%eof_reached
xor eax,eax
mov al, [edi]
jmp %%gcquit
%%eof_reached:
xor eax, eax
not eax ; eax := -1
%%gcquit:
add esp, 2
pop edi
popf
%endmacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%macro FINISH 0-1 0
_syscall_exit %1
%endmacro

Последовательность команд:
$ nasm -f elf64 hello.asm
$ ld hello.o -o hello
На второй команде получаю ошибку

hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:55: ... from macro `PRINT' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:13: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:14: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:15: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:20: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:21: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:22: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:23: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:25: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:26: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:60: ... from macro `PRINT' defined here
stud_io.inc:50: ... from macro `_syscall_write' defined here
stud_io.inc:27: ... from macro `_syscall_3' defined here
hello.asm:5: error: instruction not supported in 64-bit mode
stud_io.inc:62: ... from macro `PRINT' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:66: ... from macro `PUTCHAR' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:13: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:14: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:15: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:18: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:20: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:21: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:22: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:23: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:25: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:26: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:94: ... from macro `PUTCHAR' defined here
stud_io.inc:49: ... from macro `_syscall_write' defined here
stud_io.inc:27: ... from macro `_syscall_3' defined here
hello.asm:6: error: instruction not supported in 64-bit mode
stud_io.inc:97: ... from macro `PUTCHAR' defined here



Решили проблему?) У меня та же самая возникла, если есть решение, хотелось бы узнать, в чем всё-таки дело)
 
Мы в соцсетях:

Обучение наступательной кибербезопасности в игровой форме. Начать игру!