Esempio n. 1
0
        public bool Open(String file)
        {
            try
            {
                BinaryReader    br = new BinaryReader(File.Open(file, FileMode.Open));
                VaultFileHeader header;

                if (br != null)
                {
                    header.magic = br.ReadUInt32();

                    if (header.magic != VAULT_MAGIC)
                    {
                        return(false);
                    }

                    header.version = br.ReadUInt16();
                    if (header.version != VAULT_VERSION)
                    {
                        return(false);
                    }

                    header.entries = br.ReadUInt32();

                    UInt32 temp;
                    Byte   keyLen;
                    UInt16 valueLen;

                    for (int i = 0; i < header.entries; i++)
                    {
                        //timestamp
                        //C++ time_t
                        temp     = br.ReadUInt32();
                        keyLen   = br.ReadByte();
                        valueLen = br.ReadUInt16();

                        char[] key   = br.ReadChars(keyLen);
                        char[] value = br.ReadChars(valueLen);

                        VaultEntry entry = new VaultEntry();
                        entry.key       = new string( key );
                        entry.timestamp = temp;

                        keyValues.Add(entry, new string( value ));
                    }

                    br.Close();
                    return(true);
                }
            }
            catch (Exception e)
            {
                DarkMessageBox.ShowError("Failed to parse vault file\n" + e.Message, "Error");
                return(false);
            }
            return(false);
        }
Esempio n. 2
0
 private void UpdateTimestamp(VaultEntry itemEntry)
 {
     if (itemEntry.timestamp != 0)
     {
         txtTimestamp.Text = $"{itemEntry.timestamp.ToString()} ({VaultFile.ConvertFromUnixTime( itemEntry.timestamp ).ToString( "MMM dd, yyyy" )})";
     }
     else
     {
         txtTimestamp.Text = "Permanent";
     }
 }
Esempio n. 3
0
        private void BtnAddEntry_Click(object sender, EventArgs e)
        {
            VaultEntry vaultEntry = new VaultEntry();
            int        indexNum   = GetNextFreeIndex();

            vaultEntry.key       = $"new_key-{indexNum}";
            vaultEntry.timestamp = 0;

            vaultFile.AddEntry(vaultEntry, "");

            DarkListItem item = new DarkListItem(vaultEntry.key);

            item.Tag = vaultEntry;

            lvEntries.Items.Add(item);
            lvEntries.SelectItem(lvEntries.Items.Count - 1);
        }
Esempio n. 4
0
        private void LvEntries_SelectedIndicesChanged(object sender, EventArgs e)
        {
            if (lvEntries.Items.Count > 0)
            {
                List <int>   item  = lvEntries.SelectedIndices;
                DarkListItem dItem = lvEntries.Items[item[0]];

                selectedListItem = dItem;

                VaultEntry itemEntry = (VaultEntry)dItem.Tag;
                vaultFile.SelectedEntry = itemEntry;

                this.txtKey.Text   = itemEntry.key;
                this.txtValue.Text = vaultFile.GetValue();

                UpdateTimestamp(itemEntry);
            }
        }
Esempio n. 5
0
 public void DeleteEntry(VaultEntry entry)
 {
     keyValues.Remove(entry);
 }
Esempio n. 6
0
 public void AddEntry(VaultEntry entry, String value)
 {
     keyValues.Add(entry, value);
 }