Skip to content

Instantly share code, notes, and snippets.

@morkt
Created January 21, 2019 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morkt/1ba5fd458ae65f8105d1a41709444dcc to your computer and use it in GitHub Desktop.
Save morkt/1ba5fd458ae65f8105d1a41709444dcc to your computer and use it in GitHub Desktop.
extract text from Complet's MPX scripts
//! \file mpx2txt.cc
//! \brief extract text from Complet's MPX scripts.
//
#include "sysmemmap.h"
#include <fstream>
int wmain (int argc, wchar_t* argv[])
try
{
if (argc < 3)
{
std::puts ("usage: mpx2txt INPUT OUTPUT");
return 0;
}
sys::mapping::readwrite in (argv[1], sys::mapping::writecopy);
sys::mapping::view<uint8_t> view (in);
if (view.size() < 8 || 0 != std::memcmp (view.data(), "Mp1", 3))
{
std::fprintf (stderr, "%S: invalid MPX file.\n", argv[1]);
return 1;
}
int version = view[3] - '0';
if (version < 6 || version > 7)
{
std::fprintf (stderr, "%S: not supported MPX file version.\n", argv[1]);
return 1;
}
size_t offset = *reinterpret_cast<uint16_t*> (&view[4]);
size_t size = *reinterpret_cast<uint16_t*> (&view[6]);
if (offset >= view.size() || size >= view.size() || offset + size > view.size())
{
std::fprintf (stderr, "%S: invalid MPX file.\n", argv[1]);
return 1;
}
auto begin = view.data() + offset;
for (auto end = begin + size; begin != end; ++begin)
{
*begin ^= 0x24;
if (!*begin)
*begin = '\n';
}
std::ofstream out (argv[2], std::ios::out|std::ios::trunc);
if (!out)
{
std::fprintf (stderr, "%S: unable to open file for writing\n", argv[2]);
return 1;
}
char* data = reinterpret_cast<char*> (view.data() + offset);
out.write (data, size);
return 0;
}
catch (std::exception& X)
{
std::fprintf (stderr, "%S: %s\n", argv[1], X.what());
return 1;
}
@emmauss
Copy link

emmauss commented Jan 24, 2019

do you have any idea on what the variables in scripts do? like what these mean %i%f,1;%e,97;%g,black;%e,10;%m,mnt0;%g,title;%w,5; %e,97;%g,black;%m,mnt0;%g,title;%w,5;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment