Hope it's useful to someone else.
Code: Select all
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef __x86_64__
#define REG "rax"
#else
#define REG "eax"
#endif
#ifdef NASM
#define TMPL \
"\tmov "REG", 0b8000h\n" \
"\tmov ["REG"+0%02xh], 0%04xh\n\n"
#else
#define TMPL \
"\tmov $0xb8000, %%"REG"\n" \
"\tmovw 0x%04x, 0x%02x(%%"REG")\n\n"
#endif
int main(int argc, char **argv) {
char *string = NULL;
unsigned int clr = 0;
unsigned int i = 0;
string = strdup((char*)argv[1]);
sscanf(argv[2],"%x", &clr);
if(argc != 3) {
fputs("Need two arguments.",stderr);
exit(1);
}
printf("INSTR: %s\n", string);
printf("----------[snip]----------\n");
for(i=0;i<strlen(string);i++) {
printf(TMPL,(clr<<0x8|string[i]),(i*2));
}
printf("----------[snip]----------\n");
free(string);
return 0;
}