Compare commits

...

2 Commits

Author SHA1 Message Date
mrbesen d8addeac3c
allow clone & socketpair 2021-08-20 17:58:24 +02:00
mrbesen e0f86da8d6
binary font 2021-08-20 17:17:15 +02:00
4 changed files with 51 additions and 1 deletions

View File

@ -4,9 +4,12 @@
using json = nlohmann::json;
#include "replacefont.h"
#include "rulefont.h"
#include "phonefont.h"
#include "vectorfont.h"
#include <bitset> // covnert chars to int
static const std::string fancyrepl[] {"𝓪","𝓫","𝓬","𝓭","𝓮","𝓯","𝓰","𝓱","𝓲","𝓳","𝓴","𝓵","𝓶","𝓷","𝓸","𝓹","𝓺","𝓻","𝓼","𝓽","𝓾","𝓿","𝔀","𝔁","𝔂","𝔃","𝓐","𝓑","𝓒","𝓓","𝓔","𝓕","𝓖","𝓗","𝓘","𝓙","𝓚","𝓛","𝓜","𝓝","𝓞","𝓟","𝓠","𝓡","𝓢","𝓣","𝓤","𝓥","𝓦","𝓧","𝓨","𝓩"};
static const std::string frakturrepl[] {"𝖆","𝖇","𝖈","𝖉","𝖊","𝖋","𝖌","𝖍","𝖎","𝖏","𝖐","𝖑","𝖒","𝖓","𝖔","𝖕","𝖖","𝖗","𝖘","𝖙","𝖚","𝖛","𝖜","𝖝","𝖞","𝖟","𝕬","𝕭","𝕮","𝕯","𝕰","𝕱","𝕲","𝕳","𝕴","𝕵","𝕶","𝕷","𝕸","𝕹","𝕺","𝕻","𝕼","𝕽","𝕾","𝕿","𝖀","𝖁","𝖂","𝖃","𝖄","𝖅"};
static const std::string doublerepl[] {"𝕒","𝕓","𝕔","𝕕","𝕖","𝕗","𝕘","𝕙","𝕚","𝕛","𝕜","𝕝","𝕞","𝕟","𝕠","𝕡","𝕢","𝕣","𝕤","𝕥","𝕦","𝕧","𝕨","𝕩","𝕪","𝕫","𝔸","𝔹","","𝔻","𝔼","𝔽","𝔾","","𝕀","𝕁","𝕂","𝕃","𝕄","","𝕆","","","","𝕊","𝕋","𝕌","𝕍","𝕎","𝕏","𝕐",""};
@ -18,7 +21,7 @@ static const std::string ncirclerepl[] {"🅐", "🅑", "🅒", "🅓", "🅔",
static const std::string nboxrepl[] {"🅰", "🅱", "🅲", "🅳", "🅴", "🅵", "🅶", "🅷", "🅸", "🅹", "🅺", "🅻", "🅼", "🅽", "🅾", "🅿", "🆀", "🆁", "🆂", "🆃", "🆄", "🆅", "🆆", "🆇", "🆈", "🆉", "🅰", "🅱", "🅲", "🅳", "🅴", "🅵", "🅶", "🅷", "🅸", "🅹", "🅺", "🅻", "🅼", "🅽", "🅾", "🅿", "🆀", "🆁", "🆂", "🆃", "🆄", "🆅", "🆆", "🆇", "🆈", "🆉"};
FontBot::FontBot() {
fonts.reserve(12);
fonts.reserve(13);
fonts.push_back(new ReplaceFont("Fancy", fancyrepl));
fonts.push_back(new ReplaceFont("Fraktur", frakturrepl));
fonts.push_back(new ReplaceFont("Double", doublerepl));
@ -30,6 +33,7 @@ FontBot::FontBot() {
fonts.push_back(new ReplaceFont("Boxes", boxrepl));
fonts.push_back(new ReplaceFont("Negative Circles", ncirclerepl));
fonts.push_back(new ReplaceFont("Negative Boxes", nboxrepl));
fonts.push_back(new RuleFont("Binary", [](char c){ return std::bitset<8>((int) c).to_string() + " "; }));
}
FontBot::~FontBot() {

View File

@ -79,6 +79,9 @@ static bool enableSecurity() {
seccomp_rule_add(scmp, SCMP_ACT_ALLOW, SCMP_SYS(restart_syscall), 0);
seccomp_rule_add(scmp, SCMP_ACT_ALLOW, SCMP_SYS(futex), 0);
seccomp_rule_add(scmp, SCMP_ACT_ALLOW, SCMP_SYS(socketpair), 0); // what?
seccomp_rule_add(scmp, SCMP_ACT_ALLOW, SCMP_SYS(clone), 0); // curl wants to spawn threads
//apply seccomp
int err = seccomp_load(scmp);

26
src/rulefont.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "rulefont.h"
#include <exception>
RuleFont::RuleFont(const std::string& name, ruleFunc rule) : name(name), rule(rule) {
if(!rule) {
throw std::exception(); // "invalid Rule"
}
}
void RuleFont::applyFont(const std::string& in, std::string& out) const {
out.reserve(in.size());
for(size_t pos = 0; pos < in.size(); ++pos) {
char c = in[pos];
std::string append = rule(c);
out += append;
}
}
const std::string& RuleFont::getName() const {
return name;
}
bool RuleFont::canApply(const std::string& in) const {
return true;
}

17
src/rulefont.h Normal file
View File

@ -0,0 +1,17 @@
#include "font.h"
#include <functional>
class RuleFont : public Font {
public:
using ruleFunc = std::function<std::string(char)>;
RuleFont(const std::string& name, ruleFunc rule);
virtual void applyFont(const std::string& in, std::string& out) const override;
virtual const std::string& getName() const override;
virtual bool canApply(const std::string& in) const override;
private:
ruleFunc rule;
std::string name;
};