Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| CBM BASIC | | [`commodore_basic.hexpat`](patterns/commodore_basic.hexpat) | Commodore BASIC |
| Atari XEX | | [`xex.hexpat`](patterns/xex.hexpat) | Atari 8-bit binary format |
| Terminfo | `application/x-terminfo` and `application/x-terminfo2` | [`patterns/terminfo.hexpat`](patterns/terminfo.hexpat) | Compiled *(legacy and extended)* term info entry |

| CSNAP | [`csnap.hexpat`](patterns/csnap.hexpat) | ClipboardEdit Clipboard Snapshot format |


### Scripts
Expand Down
74 changes: 74 additions & 0 deletions patterns/csnap.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma endian little
#pragma magic 0x0F1B0A6D @ 0x00
#pragma author FireBlade
#pragma description ClipboardEdit Clipboard Snapshot format


import std.io;
import std.core;
import std.time;
import type.time;
import std.string;

enum ID : u32 {
CF_TEXT = 1,
CF_BITMAP,
CF_METAFILEPICT,
CF_SYLK,
CF_DIF,
CF_TIFF,
CF_OEMTEXT,
CF_DIB,
CF_PALETTE,
CF_PENDATA,
CF_RIFF,
CF_WAVE,
CF_UNICODETEXT,
CF_ENHMETAFILE,
CF_HDROP,
CF_LOCALE,
CF_DIBV5,
CF_OWNERDISPLAY = 0x80,
CF_DSPTEXT,
CF_DSPBITMAP,
CF_DSPMETAFILEPICT,
CF_DSPENHMETAFILE = 0x8E,
};

fn id_to_format(auto v) {
ID id = v;
str result = std::format("{}",id);
u32 resultLength = std::string::length(result)-4;
result = std::string::substr(result,4,resultLength);
if (result == "???")
return std::format("{:#X} {}",v,v);
return result;
};

struct ClipboardEntry
{
u32 format [[format("id_to_format")]];
u32 length;
u8 data[length];
};

fn to_utc(auto v) {
type::time64_t unix_time = std::time::filetime_to_unix(v);
return type::impl::format_time_t(unix_time);
};

struct ClipboardSnapshot
{
u32 magic;
u32 version;
u32 count;

ClipboardEntry entries[count];

type::FILETIME filetimeTakenUtc [[format("to_utc")]];
};

ClipboardSnapshot snapshot @ 0x00;

if (snapshot.magic != 0x0F1B0A6D)
std::error("Invalid Clipboard Snapshot file");
Binary file added tests/patterns/test_data/csnap.hexpat.csnap
Binary file not shown.
Loading