В общем, правильно дизассемблировать так:
./te.py --b16 mbr.bin
так
ndisasm mbr.bin
или так:
objdump -m i8086 -M intel-mnemonic -D -b binary mbr.bin
Меду первым и вторым вариантом будет разница, но думаю, не критичная. Так, например
te.py предпочитает
jae, а
ndisasm jnc ну и всё в таком духе. Третий вариант на отличия не рассматривал, но именно опция
-m i8086 даёт вывод команд
16-битного процессора. Просмотрел, сколько байт занимает каждая команда- всё, как в первом и втором случае. Думаю, интерпретация команд такая же. Опция
-M intel-mnemonic от вырвиглазия.
В общем, всё ровно пока не начинается текст
"Invalid Partitin...". Но текст он и в африке текст.
Вот код
te.py, требуется пакет
python3-distorm3
Код: Выделить всё
#!/usr/bin/python3
# Mario Vilas, http://breakingcode.wordpress.com
# Licensed Under GPLv3
# Example code
import distorm3
import sys
import optparse
# Parse the command line arguments
usage = 'Usage: %prog [--b16 | --b32 | --b64] filename [offset]'
parser = optparse.OptionParser(usage=usage)
parser.add_option( '--b16', help='80286 decoding',
action='store_const', dest='dt', const=distorm3.Decode16Bits )
parser.add_option( '--b32', help='IA-32 decoding [default]',
action='store_const', dest='dt', const=distorm3.Decode32Bits )
parser.add_option( '--b64', help='AMD64 decoding',
action='store_const', dest='dt', const=distorm3.Decode64Bits )
parser.set_defaults(dt=distorm3.Decode32Bits)
options, args = parser.parse_args(sys.argv)
if len(args) < 2:
parser.error('missing parameter: filename')
filename = args[1]
offset = 0
length = None
if len(args) == 3:
try:
offset = int(args[2], 10)
except ValueError:
parser.error('invalid offset: %s' % args[2])
if offset < 0:
parser.error('invalid offset: %s' % args[2])
elif len(args) > 3:
parser.error('too many parameters')
# Read the code from the file
try:
code = open(filename, 'rb').read()
except Exception as e:
parser.error('error reading file %s: %s' % (filename, e))
# Print each decoded instruction
# This shows how to use the Deocode - Generator
iterable = distorm3.DecodeGenerator(offset, code, options.dt)
for (offset, size, instruction, hexdump) in iterable:
print("%.8x: %-32s %s" % (offset, hexdump, instruction))
# It could also be used as a returned list:
# l = distorm3.Decode(offset, code, options.dt)
# for (offset, size, instruction, hexdump) in l:
# print("%.8x: %-32s %s" % (offset, hexdump, instruction))
Я просто читаю маны.