Created
March 1, 2022 19:40
-
-
Save Green-Sky/26b4a177cccdd35f83af24b9a71efacc to your computer and use it in GitHub Desktop.
ImHex pattern file for toxcore save files
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
// tox save pattern for unencrypted data | |
#pragma endian little | |
#include <std/cint.pat> | |
#include <std/io.pat> | |
#include <std/sys.pat> | |
#include <std/mem.pat> | |
// crypt_core.h import | |
/* SPDX-License-Identifier: GPL-3.0-or-later | |
* Copyright © 2016-2018 The TokTok team. | |
* Copyright © 2013 Tox project. | |
*/ | |
/** | |
* @brief The number of bytes in a Tox public key used for encryption. | |
*/ | |
#define CRYPTO_PUBLIC_KEY_SIZE 32 | |
/** | |
* @brief The number of bytes in a Tox secret key used for encryption. | |
*/ | |
#define CRYPTO_SECRET_KEY_SIZE 32 | |
/** | |
* @brief The number of bytes in a shared key computed from public and secret keys. | |
*/ | |
#define CRYPTO_SHARED_KEY_SIZE 32 | |
/** | |
* @brief The number of bytes in a symmetric key. | |
*/ | |
//#define CRYPTO_SYMMETRIC_KEY_SIZE CRYPTO_SHARED_KEY_SIZE | |
#define CRYPTO_SYMMETRIC_KEY_SIZE 32 | |
/** | |
* @brief The number of bytes needed for the MAC (message authentication code) in an | |
* encrypted message. | |
*/ | |
#define CRYPTO_MAC_SIZE 16 | |
/** | |
* @brief The number of bytes in a nonce used for encryption/decryption. | |
*/ | |
#define CRYPTO_NONCE_SIZE 24 | |
/** | |
* @brief The number of bytes in a SHA256 hash. | |
*/ | |
#define CRYPTO_SHA256_SIZE 32 | |
/** | |
* @brief The number of bytes in a SHA512 hash. | |
*/ | |
#define CRYPTO_SHA512_SIZE 64 | |
// crypt_core.h import END | |
// state.h import | |
/* SPDX-License-Identifier: GPL-3.0-or-later | |
* Copyright © 2016-2020 The TokTok team. | |
* Copyright © 2014 Tox project. | |
*/ | |
#define STATE_COOKIE_GLOBAL 0x15ed1b1f | |
#define STATE_COOKIE_TYPE 0x01ce | |
enum State_Type : std::uint16_t { | |
STATE_TYPE_NOSPAMKEYS = 1, | |
STATE_TYPE_DHT = 2, | |
STATE_TYPE_FRIENDS = 3, | |
STATE_TYPE_NAME = 4, | |
STATE_TYPE_STATUSMESSAGE = 5, | |
STATE_TYPE_STATUS = 6, | |
STATE_TYPE_TCP_RELAY = 10, | |
STATE_TYPE_PATH_NODE = 11, | |
STATE_TYPE_CONFERENCES = 20, | |
STATE_TYPE_END = 255, | |
}; | |
// state.h import END | |
std::uint32_t cookie[2] @ 0x00; | |
struct State_empty_ { | |
}; | |
struct State_STATE_TYPE_NOSPAMKEYS { | |
std::uint32_t nospam; | |
std::uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; | |
std::uint8_t private_key[CRYPTO_SECRET_KEY_SIZE]; | |
}; | |
struct State_STATE_TYPE_DHT { | |
}; | |
struct State_STATE_TYPE_FRIENDS { | |
}; | |
struct State_STATE_TYPE_NAME { | |
}; | |
struct State_STATE_TYPE_STATUSMESSAGE { | |
}; | |
struct State_STATE_TYPE_STATUS { | |
}; | |
struct State_STATE_TYPE_TCP_RELAY { | |
}; | |
struct State_STATE_TYPE_PATH_NODE { | |
}; | |
//#define GROUP_ID_LENGTH CRYPTO_SYMMETRIC_KEY_SIZE | |
#define GROUP_ID_LENGTH 32 | |
#define SAVED_CONF_SIZE_CONSTANT (1 + GROUP_ID_LENGTH + sizeof(std::uint32_t) + sizeof(std::uint16_t) + sizeof(std::uint16_t) + sizeof(std::uint32_t) + 1) | |
struct GroupPeer { | |
std::uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; | |
std::uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; | |
u16 peer_num; | |
u64 last_active; | |
u8 nick_len; | |
u8 nick[nick_len]; | |
}; | |
u32 g_curr_group_list_size; | |
u32 g_curr_group_list_max; | |
struct Group { | |
u8 type; | |
u8 id[GROUP_ID_LENGTH]; | |
u32 msg_num; | |
u16 lossy_msg_num; | |
u16 peer_num; | |
u32 frozen_num; | |
u8 title_len; | |
u8 title[title_len]; | |
GroupPeer frozen[frozen_num]; | |
//g_curr_group_list_size += sizeof(this); // sizeof(this) == 0 | |
g_curr_group_list_size += sizeof(type); | |
g_curr_group_list_size += sizeof(id); | |
g_curr_group_list_size += sizeof(msg_num); | |
g_curr_group_list_size += sizeof(lossy_msg_num); | |
g_curr_group_list_size += sizeof(peer_num); | |
g_curr_group_list_size += sizeof(frozen_num); | |
g_curr_group_list_size += sizeof(title_len); | |
g_curr_group_list_size += sizeof(title); | |
g_curr_group_list_size += sizeof(frozen); | |
std::print("curr: {}", g_curr_group_list_size); | |
}; | |
struct State_STATE_TYPE_CONFERENCES { | |
g_curr_group_list_size = 0; | |
Group groups[while(g_curr_group_list_size < g_curr_group_list_max)]; | |
}; | |
struct State { | |
std::uint32_t length_sub; | |
State_Type type; | |
std::uint16_t cookie; | |
if (type == State_Type::STATE_TYPE_END) { | |
State_empty_ data; | |
break; | |
} else if (type == State_Type::STATE_TYPE_NOSPAMKEYS) { | |
State_STATE_TYPE_NOSPAMKEYS data; | |
} else if (type == State_Type::STATE_TYPE_DHT) { | |
State_STATE_TYPE_DHT data; | |
} else if (type == State_Type::STATE_TYPE_FRIENDS) { | |
State_STATE_TYPE_FRIENDS data; | |
} else if (type == State_Type::STATE_TYPE_NAME) { | |
State_STATE_TYPE_NAME data; | |
} else if (type == State_Type::STATE_TYPE_STATUSMESSAGE) { | |
State_STATE_TYPE_STATUSMESSAGE data; | |
} else if (type == State_Type::STATE_TYPE_STATUS) { | |
State_STATE_TYPE_STATUS data; | |
} else if (type == State_Type::STATE_TYPE_TCP_RELAY) { | |
State_STATE_TYPE_TCP_RELAY data; | |
} else if (type == State_Type::STATE_TYPE_PATH_NODE) { | |
State_STATE_TYPE_PATH_NODE data; | |
} else if (type == State_Type::STATE_TYPE_CONFERENCES) { | |
g_curr_group_list_max = length_sub; | |
State_STATE_TYPE_CONFERENCES data; | |
} else { | |
State_empty_ data; | |
//std::error("unkown state type"); | |
break; | |
} | |
if (length_sub > sizeof(data)) { | |
padding[length_sub - sizeof(data)]; | |
} | |
}; | |
State states[9] @ 0x08; | |
fn check_cookie() { | |
std::assert(cookie[0] == 0, "cookie part0 has to be 0"); | |
std::assert(cookie[1] == STATE_COOKIE_GLOBAL, "cookie part1 has to be STATE_COOKIE_GLOBAL"); | |
std::print("cookie OK"); | |
}; | |
fn main() { | |
std::print("entering main"); | |
check_cookie(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment