#include "func.h" #include "glob.h" #include "Buffer.h" int find_password_in_buffer(Buffer& decrypted_buffer, const char* label) { Index* index = (Index*)decrypted_buffer.buffer; Pass* pass = (Pass*)(decrypted_buffer.buffer + sizeof(Index)); for (size_t i = 0; i < index->count; i++) { if (glob(label, (const char*) decrypted_buffer.buffer + pass[i].label + index->offset) == Glob_Result::MATCHED) return i; } return -1; } void delete_password_from_buffer(Buffer& in, Buffer& out, int index_of_pass) { Index* in_index = (Index*)in.buffer; Pass* in_pass = (Pass*)(in.buffer + sizeof(Index)); int size = sizeof(Index) + sizeof(Pass) * (in_index->count - 1); out.resize(size); out.taken = size; Index* out_index = (Index*)out.buffer; out_index->count = in_index->count - 1; out_index->offset = size; int count = 0; for (size_t i = 0; i < in_index->count; i++) { if (i == index_of_pass) continue; uint8_t* label = in.buffer + in_pass[i].label + in_index->offset; uint8_t* password = in.buffer + in_pass[i].password + in_index->offset; size_t label_start = out.add_end(label, strlen((char*)label) + 1); size_t password_start = out.add_end(password, strlen((char*)password) + 1); Pass* out_pass = (Pass*)(out.buffer + sizeof(Index)); out_pass[count].label = label_start - size; out_pass[count].password = password_start - size; count++; } } void add_password_to_buffer(Buffer& in, const char* label, const char* password) { int label_start = in.add_end((uint8_t*)label, strlen(label) + 1); int password_start = in.add_end((uint8_t*)password, strlen(password) + 1); Index* index = (Index*)in.buffer; label_start = label_start - index->offset; password_start = password_start - index->offset; Pass pass = { label_start, password_start }; index->count++; index->offset += sizeof(Pass); in.add_middle((uint8_t*)&pass, sizeof(Pass), index->offset - sizeof(Pass)); } const char* get_password_from_buffer(Buffer& decrypted_buffer, int label) { Index* index = (Index*)decrypted_buffer.buffer; Pass* pass = (Pass*)(decrypted_buffer.buffer + sizeof(Index)); return (const char*)decrypted_buffer.buffer + pass[label].password + index->offset; } void generate_password(std::string& password, int len) { srand(time(NULL)); char characters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_-+={[}]|:;<,>.?"; for (int i = 0; i < len; i++) { password[i] += characters[rand() % (sizeof(characters) - 1)]; } } bool save_buffer_to_file(Buffer& buffer) { std::ofstream file("passwords.bin", std::ios::binary | std::ios::out); if (!file.is_open()) { printf_s("Error saving file\n"); return false; } file.write((char*)buffer.buffer, buffer.taken); file.close(); return true; } bool load_buffer_from_file(Buffer& buffer) { std::ifstream file("passwords.bin", std::ios::binary | std::ios::in); if (!file.is_open()) return false; file.seekg(0, std::ios::end); size_t file_size = file.tellg(); buffer.resize(file_size); file.seekg(0, std::ios::beg); file.read((char*)buffer.buffer, buffer.size); if (file) buffer.taken = file_size; else buffer.taken = file.gcount(); file.close(); return true; } void print_usage() { printf_s(" Usage:\n\n"); printf_s(" password_manager.exe [flags]\n\n"); printf_s(" Flags:\n\n"); printf_s(" -h \t print this message\n"); printf_s("