Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
__ _ | ||
.-.' `; `-._ __ _ | ||
(_, .-:' `; `-._ | ||
,'o"( (_, ) | ||
(__,-' ,'o"( )> | ||
( (__,-' ) | ||
`-'._.--._( ) | ||
||| |||`-'._.--._.-' | ||
||| ||| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// :D | ||
|
||
#include <stdio.h> | ||
|
||
int main () { | ||
const char str_data[] = | ||
#embed_str "foo/art.txt" | ||
; | ||
puts(str_data); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// :D | ||
|
||
#include <stdio.h> | ||
|
||
int main () { | ||
const unsigned char data[] = | ||
#embed __FILE__ | ||
; | ||
const char str_data[] = | ||
#embed_str __FILE__ | ||
; | ||
puts(str_data); | ||
return !(str_data[0] == '/' | ||
&& str_data[1] == '/' | ||
&& str_data[2] == ' ' | ||
&& data[3] == ':' | ||
&& data[4] == 'D'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <phd/embed.hpp> | ||
|
||
|
||
int main () { | ||
constexpr std::span<const char> data = std::embed("foo/art.txt"); | ||
return data[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// :D | ||
|
||
#include <stdio.h> | ||
|
||
int main () { | ||
const unsigned char data[] = | ||
#embed 5 __FILE__ | ||
; | ||
const char str_data[] = | ||
#embed_str 3 __FILE__ | ||
; | ||
puts(str_data); | ||
return !(str_data[0] == '/' | ||
&& str_data[1] == '/' | ||
&& str_data[2] == ' ' | ||
&& str_data[3] == '\0' | ||
&& data[3] == ':' | ||
&& data[4] == 'D'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// :D | ||
|
||
#include <stdio.h> | ||
|
||
int main () { | ||
const unsigned char data[] = | ||
#embed 5 "/dev/urandom" | ||
; | ||
const char str_data[] = | ||
#embed_str 3 "/dev/urandom" | ||
; | ||
return str_data[0] + data[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <phd/embed.hpp> | ||
|
||
int main () { | ||
constexpr std::span<const char> data = std::embed("art.txt"); | ||
return data[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// >:3 | ||
|
||
#include <cstddef> | ||
#include <utility> | ||
#include <cassert> | ||
|
||
int main () { | ||
const char* data = nullptr; | ||
const char* trunc_data = nullptr; | ||
const size_t data_size = __builtin_embed("foo.txt.txt", 7, &data); | ||
const size_t trunc_data_size = __builtin_embed_n("foo.txt.wdhawdkaw", 7, &trunc_data, 1); | ||
int arr[trunc_data_size]{}; | ||
assert(data_size == 3); | ||
assert(data[0] == 'F'); | ||
assert(data[1] == 'o'); | ||
assert(data[2] == 'o'); | ||
assert(trunc_data_size == 1); | ||
assert(trunc_data[0] == 'F'); | ||
return arr[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Nice. | ||
|
||
#include <cstddef> | ||
#include <cassert> | ||
|
||
int main () { | ||
const char* data = nullptr; | ||
std::size_t data_size = __builtin_embed_n("/dev/urandom", 12, &data, 1); | ||
assert(data_size == 1); | ||
return data[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <phd/embed.hpp> | ||
|
||
int main () { | ||
constexpr std::span<const char> data = std::embed("foo.txt"); | ||
return data[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <phd/embed.hpp> | ||
|
||
#include <cstdint> | ||
|
||
constexpr std::uint64_t val_64_const = 0xcbf29ce484222325; | ||
constexpr std::uint64_t prime_64_const = 0x100000001b3; | ||
|
||
inline constexpr std::uint64_t | ||
hash_64_fnv1a_const(const char* const ptr, std::size_t ptr_size, const std::uint64_t value = val_64_const) noexcept { | ||
return (ptr_size == 1) | ||
? value : | ||
hash_64_fnv1a_const(&ptr[1], ptr_size - 1, (value ^ static_cast<std::uint64_t>(ptr[0])) * prime_64_const); | ||
} | ||
|
||
#include <iostream> | ||
|
||
int main () { | ||
constexpr std::span<const char> art_data = std::embed("art.txt"); | ||
constexpr std::uint64_t expected = 12781078433878002033; | ||
constexpr std::uint64_t actual = hash_64_fnv1a_const(art_data.data(), art_data.size()); | ||
|
||
static_assert(expected == actual, "🚨 SUSPICIOUS ART SUSPICIOUS ART 🚨"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <phd/embed.hpp> | ||
|
||
#include <cstdint> | ||
|
||
inline constexpr std::uint64_t | ||
compute_stuff(const char* const ptr, std::size_t ptr_size, std::uint64_t seed = 0, std::size_t limit = 5) noexcept { | ||
const char* first = ptr; | ||
const char* last = ptr + ptr_size; | ||
for (const char* first = ptr; first != last; ++first) { | ||
const char val = *first; | ||
if (limit > 1 && val > 126) { | ||
std::span<const char> more = std::embed("foo.txt"); | ||
seed = compute_stuff(more.data(), more.size(), seed, limit - 1); | ||
} | ||
seed ^= *first; | ||
} | ||
return seed; | ||
} | ||
|
||
int main () { | ||
constexpr std::span<const char> art_data = std::embed("foo/art.txt"); | ||
constexpr std::uint64_t actual = compute_stuff(art_data.data(), art_data.size()); | ||
static_assert(actual == 103); | ||
|
||
return static_cast<int>(actual); | ||
} |