Skip to content

Commit

Permalink
Merge pull request #286 from daanbreur/feat-itcon-parser
Browse files Browse the repository at this point in the history
Create HITCON CTF parser
  • Loading branch information
JJ-8 authored Jul 14, 2024
2 parents c2e0638 + bd64f92 commit 08eed9b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
47 changes: 47 additions & 0 deletions front/src/ctfnote/parsers/hitcon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ParsedTask, Parser } from '.';
import { parseJsonStrict } from '../utils';

const HitconParser: Parser = {
name: 'HITCONCTF parser',
hint: 'paste hitcon /dashboard/challenge_data',
parse(s): ParsedTask[] {
const tasks: ParsedTask[] = [];
const data =
parseJsonStrict<
[{ name: string; category: string; description: string }]
>(s);
if (data == null) {
return [];
}

for (const challenge of data) {
if (!challenge.description || !challenge.name) {
continue;
}

tasks.push({
title: challenge.name,
tags: challenge.category.split(','),
description: challenge.description,
});
}

return tasks;
},
isValid(s) {
const data =
parseJsonStrict<
[{ name: string; category: string; description: string }]
>(s);
if (data == null || data.length < 1) {
return false;
}
return (
data[0].name != null &&
data[0].category != null &&
data[0].description != null
);
},
};

export default HitconParser;
2 changes: 2 additions & 0 deletions front/src/ctfnote/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HTBParser from './htb';
import PicoParser from './pico';
import justCTFParser from './justctf';
import AngstromParser from './angstrom';
import HitconParser from './hitcon';

export type ParsedTask = {
title: string;
Expand All @@ -28,4 +29,5 @@ export default [
PicoParser,
justCTFParser,
AngstromParser,
HitconParser,
];

0 comments on commit 08eed9b

Please sign in to comment.