aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-09-25 20:42:10 +0200
committermetamuffin <metamuffin@disroot.org>2022-09-25 20:42:10 +0200
commit0a18eae178a23e7f7bfd88c37502e5e8c1fdf64a (patch)
treefb5b1aa5f9a8d023b2edbc9e89b5d2e4844a42eb
parente3edf18503b3975ccec3b33c0cb9e7f0888bd031 (diff)
downloadmetamuffin-blog-0a18eae178a23e7f7bfd88c37502e5e8c1fdf64a.tar
metamuffin-blog-0a18eae178a23e7f7bfd88c37502e5e8c1fdf64a.tar.bz2
metamuffin-blog-0a18eae178a23e7f7bfd88c37502e5e8c1fdf64a.tar.zst
(the commit before proper parsers will replace everything™™)
-rw-r--r--code/Cargo.lock204
-rw-r--r--code/Cargo.toml1
-rw-r--r--code/src/main.rs2
-rw-r--r--code/src/markdown/parser.rs3
-rw-r--r--code/src/markdown/render.rs25
-rw-r--r--code/src/syntax_highlight/grammar.rs53
-rw-r--r--code/src/syntax_highlight/theme.rs2
-rw-r--r--content/articles/2022-09-25-ductf-file-magic.md16
-rw-r--r--content/style.css2
9 files changed, 270 insertions, 38 deletions
diff --git a/code/Cargo.lock b/code/Cargo.lock
index a41b2d4..28ef179 100644
--- a/code/Cargo.lock
+++ b/code/Cargo.lock
@@ -25,7 +25,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -47,11 +47,24 @@ dependencies = [
"anyhow",
"clap",
"iso8601",
+ "katex",
"laby",
"synoptic",
]
[[package]]
+name = "cc"
+version = "1.0.73"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
name = "clap"
version = "3.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -91,6 +104,93 @@ dependencies = [
]
[[package]]
+name = "copy_dir"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e4281031634644843bd2f5aa9c48cf98fc48d6b083bd90bb11becf10deaf8b0"
+dependencies = [
+ "walkdir",
+]
+
+[[package]]
+name = "darling"
+version = "0.14.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4529658bdda7fd6769b8614be250cdcfc3aeb0ee72fe66f9e41e5e5eb73eac02"
+dependencies = [
+ "darling_core",
+ "darling_macro",
+]
+
+[[package]]
+name = "darling_core"
+version = "0.14.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "649c91bc01e8b1eac09fb91e8dbc7d517684ca6be8ebc75bb9cafc894f9fdb6f"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "strsim",
+ "syn",
+]
+
+[[package]]
+name = "darling_macro"
+version = "0.14.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ddfc69c5bfcbd2fc09a0f38451d2daf0e372e367986a83906d1b0dbc88134fb5"
+dependencies = [
+ "darling_core",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "derive_builder"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d07adf7be193b71cc36b193d0f5fe60b918a3a9db4dad0449f57bcfd519704a3"
+dependencies = [
+ "derive_builder_macro",
+]
+
+[[package]]
+name = "derive_builder_core"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4"
+dependencies = [
+ "darling",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "derive_builder_macro"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68"
+dependencies = [
+ "derive_builder_core",
+ "syn",
+]
+
+[[package]]
+name = "either"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
+
+[[package]]
+name = "fnv"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
+
+[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -112,6 +212,12 @@ dependencies = [
]
[[package]]
+name = "ident_case"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
+
+[[package]]
name = "indexmap"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -131,12 +237,44 @@ dependencies = [
]
[[package]]
+name = "itertools"
+version = "0.10.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
+dependencies = [
+ "either",
+]
+
+[[package]]
name = "itoap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9028f49264629065d057f340a86acb84867925865f73bbf8d47b4d149a7e88b8"
[[package]]
+name = "katex"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2143ecac5f6d760dc1928c83ff1b3f46ecd1c9c57e85d17a3111340a59a48c42"
+dependencies = [
+ "cfg-if",
+ "derive_builder",
+ "itertools",
+ "quick-js",
+ "thiserror",
+]
+
+[[package]]
+name = "kernel32-sys"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
+dependencies = [
+ "winapi 0.2.8",
+ "winapi-build",
+]
+
+[[package]]
name = "laby"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -176,6 +314,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
[[package]]
+name = "libquickjs-sys"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f0b24e9bd171b75ae0295bd428fb8fe58410fb23156e5f34a4657a70c3cee96"
+dependencies = [
+ "cc",
+ "copy_dir",
+]
+
+[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -243,6 +391,16 @@ dependencies = [
]
[[package]]
+name = "quick-js"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19cb4cefcb00f4ab9b332664d06005a74f582ac16aa959c6ad5912957bd83e5f"
+dependencies = [
+ "libquickjs-sys",
+ "once_cell",
+]
+
+[[package]]
name = "quote"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -326,6 +484,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]]
+name = "thiserror"
+version = "1.0.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0a99cb8c4b9a8ef0e7907cd3b617cc8dc04d571c4e73c8ae403d80ac160bb122"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a891860d3c8d66fec8e73ddb3765f90082374dbaaa833407b904a94f1a7eb43"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "unicode-ident"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -344,6 +522,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
+name = "walkdir"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c66c0b9792f0a765345452775f3adbd28dde9d33f30d13e5dcc5ae17cf6f3780"
+dependencies = [
+ "kernel32-sys",
+ "winapi 0.2.8",
+]
+
+[[package]]
+name = "winapi"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
+
+[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -354,6 +548,12 @@ dependencies = [
]
[[package]]
+name = "winapi-build"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
+
+[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -365,7 +565,7 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
diff --git a/code/Cargo.toml b/code/Cargo.toml
index c2081a5..2155502 100644
--- a/code/Cargo.toml
+++ b/code/Cargo.toml
@@ -9,3 +9,4 @@ clap = { version = "3.2.17", features = ["derive"] } # bloated argument parser
anyhow = "1.0.62" # error stuff
iso8601 = "0.5.0" # date parsing
synoptic = "1.2.0" # syntax highlighting
+katex = "0.4.4"
diff --git a/code/src/main.rs b/code/src/main.rs
index 21732d7..83869f0 100644
--- a/code/src/main.rs
+++ b/code/src/main.rs
@@ -1,3 +1,5 @@
+#![feature(const_fmt_arguments_new)]
+
pub mod atom;
pub mod html;
pub mod markdown;
diff --git a/code/src/markdown/parser.rs b/code/src/markdown/parser.rs
index cb025a6..94eab49 100644
--- a/code/src/markdown/parser.rs
+++ b/code/src/markdown/parser.rs
@@ -102,10 +102,9 @@ fn try_list(mut s: &str) -> Option<(Block, &str)> {
}
s = &s[1..];
let mut lf = s.find("\n").unwrap();
- while s[lf + 1..].starts_with(" -") {
+ while s[lf + 1..].starts_with(" ") {
lf += 2 + s[lf + 2..].find("\n").unwrap();
}
- eprintln!("{:?}", &s[..lf]);
let mut k = s[..lf]
.split("\n")
.map(|l| if l.starts_with(" ") { &l[2..] } else { &l })
diff --git a/code/src/markdown/render.rs b/code/src/markdown/render.rs
index 39f204f..f6b7686 100644
--- a/code/src/markdown/render.rs
+++ b/code/src/markdown/render.rs
@@ -15,7 +15,10 @@ pub fn span_to_html(ss: Vec<Span>) -> String {
Span::Image(_, _) => todo!(),
Span::Emphasis(c) => format!("<i>{}</i>", span_to_html(c)),
Span::Strong(c) => format!("<b>{}</b>", span_to_html(c)),
- Span::Latex(_) => format!("TODO: Inline Latex"),
+ Span::Latex(s) => fix_katex(
+ &katex::render_with_opts(&s, &katex::OptsBuilder::default().build().unwrap())
+ .unwrap(),
+ ),
}
.as_str()
}
@@ -55,7 +58,16 @@ pub fn blocks_to_html(blocks: Vec<Block>) -> String {
}
Block::Raw(r) => r,
Block::Hr => format!("<hr/>"),
- Block::LatexBlock(_) => format!("TODO: Latex block"),
+ Block::LatexBlock(s) => fix_katex(
+ &katex::render_with_opts(
+ &s,
+ &katex::OptsBuilder::default()
+ .display_mode(true)
+ .build()
+ .unwrap(),
+ )
+ .unwrap(),
+ ),
}
.as_str();
}
@@ -69,3 +81,12 @@ pub fn escape(text: &str) -> String {
.replace("'", "&#8217;")
.replace("\"", "&quot;")
}
+
+// TODO this is *really* bad fix
+fn fix_katex<'a>(s: &str) -> String {
+ let e = s.find("<span class=\"katex-html\"").unwrap();
+ s[0..e].replace(
+ "<mspace linebreak=\"newline\"></mspace>",
+ "</mrow></semantics></math><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow>",
+ )
+}
diff --git a/code/src/syntax_highlight/grammar.rs b/code/src/syntax_highlight/grammar.rs
index 0878b33..0cecac9 100644
--- a/code/src/syntax_highlight/grammar.rs
+++ b/code/src/syntax_highlight/grammar.rs
@@ -1,3 +1,8 @@
+const CONST: &str = "[\\. \\(,=^]([A-Z][A-Z0-9_]*)[\\. ,\\)=$]";
+const TYPE: &str = "[\\. \\(,=^]([A-Z][a-zA-Z0-9_]*)[\\. ,\\)\\(=$]";
+const IDENT: &str = "[\\. \\(,=^]([a-z][a-zA-Z0-9_]*)[\\. ,\\)=$]";
+const FUNC: &str = "[\\. \\(,=^]([a-z][A-Z0-9_]*)\\(";
+
pub fn grammar_for(syntax: &str) -> &'static [(&'static str, &'static [&'static str])] {
match syntax {
"rs" | "rust" => &[
@@ -11,41 +16,43 @@ pub fn grammar_for(syntax: &str) -> &'static [(&'static str, &'static [&'static
(
"type",
&[
- "[A-Z][a-z0-9]*",
- "bool",
- "usize",
- "u8",
- "u16",
- "u32",
- "u64",
- "u128",
- "i8",
- "i16",
- "i32",
- "i64",
- "i128",
- "isize",
- "f32",
- "f64",
+ TYPE, "bool", "usize", "u8", "u16", "u32", "u64", "u128", "i8", "i16", "i32",
+ "i64", "i128", "isize", "f32", "f64",
],
),
+ ("constant", &[CONST]),
("comment", &["(?m)(//.*)$", "(?ms)/\\*.*?\\*/"]),
- ("macro", &["([a-z_][A-Za-z0-9_]*!)\\s*"]),
- ("identifier", &["([a-z_][A-Za-z0-9_]*)\\s*\\("]),
- ("literal", &["\".*?\"", "\\d", "true", "false"]),
+ ("macro", &["[\\. ,=^]([a-z_][A-Za-z0-9_]*!)[\\. ,=$]"]),
+ ("identifier", &[IDENT]),
+ ("function", &[FUNC]),
+ (
+ "literal",
+ &["\".*?\"", "(0x|0o|0b)[0-9a-f]+", "\\d+", "true", "false"],
+ ),
],
"py" | "python" => &[
("type", &["bytes", "bool", "int", "str", "float"]),
(
"keyword",
&[
- "from", "for", "def", "if", "else", "elif", "while", "with", "in", "as",
- "import",
+ "from", "for", "def", "if", "else", "elif", "while", "with", "in", "assert",
+ "global", "nonlocal", "as", "import",
],
),
("comment", &["(?m)(#.*)$"]),
- ("identifier", &["([a-z_][A-Za-z0-9_]*)\\s*\\("]),
- ("literal", &["b?\".*?\"", "\\d", "true", "false"]),
+ ("constant", &[CONST]),
+ ("identifier", &[IDENT]),
+ (
+ "literal",
+ &[
+ "b?f?\".*?\"",
+ "b?f?'.*?'",
+ "(0x|0o|0b)[0-9a-f]+",
+ "\\d+",
+ "true",
+ "false",
+ ],
+ ),
],
"tree" => &[("keyword", &["[├─└│]+"])],
// makefile doesnt really match the token-kinds, i'll just use something that looks goo
diff --git a/code/src/syntax_highlight/theme.rs b/code/src/syntax_highlight/theme.rs
index 288662a..2dfd10d 100644
--- a/code/src/syntax_highlight/theme.rs
+++ b/code/src/syntax_highlight/theme.rs
@@ -6,7 +6,7 @@ pub fn theme(kind: &str) -> &'static str {
"function" => "#26ffbc",
"types" => "#26ff34",
"identifier" => "#ccff26",
- "" => "#ff7c26",
+ "constant" => "#ff7c26",
"comment" => "#6e6e6e",
_ => "#ff00ff",
}
diff --git a/content/articles/2022-09-25-ductf-file-magic.md b/content/articles/2022-09-25-ductf-file-magic.md
index 42d6429..267a707 100644
--- a/content/articles/2022-09-25-ductf-file-magic.md
+++ b/content/articles/2022-09-25-ductf-file-magic.md
@@ -50,7 +50,7 @@ So for a anything to make it past these check and be executed it must:
1. be a valid 13x37 JPEG image with the pixel at 7,7 set to #070707
2. be a valid ELF binary that reads `./flag.txt` after decrypting with AES CBC,
- fixed key and the provided IV
+ fixed key and the provided IV
3. The IV must contain `DUCTF`
## 1. AES CBC
@@ -99,7 +99,7 @@ $$ c = AES(m \oplus IV) \\
AES^{-1}(c) = m \oplus IV \\
-AES^{-1}(c) \oplus m = IV \\ $$
+AES^{-1}(c) \oplus m = IV $$
All blocks after the first are now "uncontrollable" as ciphertext because IV and
plaintext are set.
@@ -109,12 +109,12 @@ plaintext are set.
JPEG consists of a list of _segments_. Each starts with a marker byte (`ff`)
followed by a identifier and the length of the segment (if non-zero).
-| Identifier | Name |
-| ---------- | ---------------------------------------------- |
-| `d8` | Start of Image |
-| `fe` | Comment |
-| `d9` | End of Image |
-| ... | _a bunch more that we dont need to know about_ |
+| Identifier | Name |
+| ---------- | ----------------------------------------------- |
+| `d8` | Start of Image |
+| `fe` | Comment |
+| `d9` | End of Image |
+| ... | _a bunch more that you dont need to know about_ |
The comment segment is perfect for embedding our ELF binary into JPEG. We can
first generate a JPEG image, then insert a _comment_ somewhere containing any
diff --git a/content/style.css b/content/style.css
index 2a7f010..15ea9b8 100644
--- a/content/style.css
+++ b/content/style.css
@@ -31,6 +31,8 @@ p,li { color: white; margin-left: 3em }
a { color: #82a8ff; font-style: italic; text-decoration: underline }
hr { border: 1px solid grey }
+math {color:white}
+
pre,code {
color: #eeeeee;
font-family: monospace;