using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
namespace Detection.Structs
{
public class VbfSetting
{
public string description { get; set; }
public string sw_part_number { get; set; }
public string sw_version { get; set; }
public string sw_part_type { get; set; }
public string data_format_identifier { get; set; }
public string ecu_address { get; set; }
public string verification_block_root_hash { get; set; }
public string verification_block_start { get; set; }
public string verification_block_length { get; set; }
public byte[] sw_signature_dev { get; set; }
public string file_checksum { get; set; }
public byte[] callAddress { get; set; }
public byte[] eraseAddr { get; set; }
public int Index { get; set; }
public List<DataSegment> SegmentList { get; set; }
public static VbfSetting ReadVbfFile(string vbfFileName)
{
try
{
VbfSetting myVbfSetting = new VbfSetting();
//read all data from vbf file
FileStream fs = new FileStream(vbfFileName, FileMode.Open);
byte[] allDataArray = new byte[fs.Length];
int resInt = fs.Read(allDataArray, 0, (int)(fs.Length));
//BinaryReader br = new BinaryReader(fs);
fs.Close();
//find srart index of data
string tempHeaderStr = Encoding.ASCII.GetString(allDataArray.Skip(0).Take(8192).ToArray());
int sCount = 0;
int leftIndex = 0;
int rightIndex = 0;
int dataStartIndex = 0;
for (int i = 0; i < 32; i++)
{
leftIndex = tempHeaderStr.IndexOf("{");
rightIndex = tempHeaderStr.IndexOf("}");
if (leftIndex >= 0 || rightIndex >= 0)
{
if (leftIndex < rightIndex)
{
sCount++;