#!/usr/bin/python3 import sys def help(): print('Usage: mkasmmsg.py -b<32/64> ') if len(sys.argv) != 4: help() sys.exit(1) format = sys.argv[2] msg = sys.argv[3] base = 0xb8000 index = { '1': 'word', '2': 'dword', '4': 'qword' } command = 'mov {} [{}], 0x{}' if sys.argv[1] == '-b32': groupsize = 2 elif sys.argv[1] == '-b64': groupsize = 4 else: help() sys.exit(1) def chunk(iterator, n): for i in range(0, len(iterator), n): yield iterator[i:i + n] raw_nums = [] for char in list(msg): raw_nums.append(format + hex(ord(char))[2:]) total = 0 for num, block in enumerate(list(chunk(raw_nums, groupsize))): if len(block) == 3: total += 2 print(command.format('word', hex(base + total), block[0])) total += 4 print(command.format('dword', hex(base + total), ''.join(block[1:]))) continue total += len(block) * groupsize print(command.format(index[str(len(block))], hex(base + total), ''.join(block)))