Esempio n. 1
0
        // looks exactly like the definition in DIOpenDiagService (#T)
        public ComParameter(BinaryReader reader, long baseAddress, List <ECUInterface> parentEcuInterfaceList, CTFLanguage language)
        {
            BaseAddress = baseAddress;
            reader.BaseStream.Seek(baseAddress, SeekOrigin.Begin);
            ulong bitflags = reader.ReadUInt16();

            ComParamIndex        = CaesarReader.ReadBitflagInt16(ref bitflags, reader);
            ParentInterfaceIndex = CaesarReader.ReadBitflagInt16(ref bitflags, reader);
            SubinterfaceIndex    = CaesarReader.ReadBitflagInt16(ref bitflags, reader, 0);
            Unk5          = CaesarReader.ReadBitflagInt16(ref bitflags, reader);
            Unk_CTF       = CaesarReader.ReadBitflagInt32(ref bitflags, reader); // no -1? ctf strings should have -1
            Phrase        = CaesarReader.ReadBitflagInt16(ref bitflags, reader);
            DumpSize      = CaesarReader.ReadBitflagInt32(ref bitflags, reader);
            Dump          = CaesarReader.ReadBitflagDumpWithReader(ref bitflags, reader, DumpSize, baseAddress);
            ComParamValue = 0;
            if (DumpSize == 4)
            {
                ComParamValue = BitConverter.ToInt32(Dump, 0);
            }


            ECUInterface parentEcuInterface = parentEcuInterfaceList[ParentInterfaceIndex];

            if (ComParamIndex >= parentEcuInterface.ComParameterNames.Count)
            {
                // throw new Exception("Invalid communication parameter : parent interface has no matching key");
                ParamName = "CP_UNKNOWN_MISSING_KEY";
                Console.WriteLine($"Warning: Tried to load a communication parameter without a parent (value: {ComParamValue}), parent: {parentEcuInterface.Qualifier}.");
            }
            else
            {
                ParamName = parentEcuInterface.ComParameterNames[ComParamIndex];
            }
        }
Esempio n. 2
0
        public ECU(BinaryReader reader, CTFLanguage language, CFFHeader header, long baseAddress, CaesarContainer parentContainer)
        {
            ParentContainer = parentContainer;
            BaseAddress     = baseAddress;
            // Read 32+16 bits
            ulong ecuBitFlags = reader.ReadUInt32();
            // after exhausting the 32 bits, load these additional 16 bits
            ulong ecuBitFlagsExtended = reader.ReadUInt16();

            // Console.WriteLine($"ECU bitflags: {ecuBitFlags:X}");

            // advancing forward to ecuBase + 10
            int ecuHdrIdk1 = reader.ReadInt32(); // no idea

            // Console.WriteLine($"Skipping: {ecuHdrIdk1:X8}");

            Qualifier            = CaesarReader.ReadBitflagStringWithReader(ref ecuBitFlags, reader, BaseAddress);
            EcuName_CTF          = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader, -1);
            EcuDescription_CTF   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader, -1);
            EcuXmlVersion        = CaesarReader.ReadBitflagStringWithReader(ref ecuBitFlags, reader, BaseAddress);
            InterfaceBlockCount  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            InterfaceTableOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            SubinterfacesCount   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            SubinterfacesOffset  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            EcuClassName         = CaesarReader.ReadBitflagStringWithReader(ref ecuBitFlags, reader, BaseAddress);
            UnkStr7 = CaesarReader.ReadBitflagStringWithReader(ref ecuBitFlags, reader, BaseAddress);
            UnkStr8 = CaesarReader.ReadBitflagStringWithReader(ref ecuBitFlags, reader, BaseAddress);

            int dataBufferOffsetRelativeToFile = header.StringPoolSize + StubHeader.StubHeaderSize + header.CffHeaderSize + 4;

            // Console.WriteLine($"{nameof(dataBufferOffsetRelativeToFile)} : 0x{dataBufferOffsetRelativeToFile:X}");

            IgnitionRequired   = CaesarReader.ReadBitflagInt16(ref ecuBitFlags, reader);
            Unk2               = CaesarReader.ReadBitflagInt16(ref ecuBitFlags, reader);
            UnkBlockCount      = CaesarReader.ReadBitflagInt16(ref ecuBitFlags, reader);
            UnkBlockOffset     = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            EcuSgmlSource      = CaesarReader.ReadBitflagInt16(ref ecuBitFlags, reader);
            Unk6RelativeOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            EcuVariant_BlockOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader) + dataBufferOffsetRelativeToFile;
            EcuVariant_EntryCount  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            EcuVariant_EntrySize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            EcuVariant_BlockSize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            DiagJob_BlockOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader) + dataBufferOffsetRelativeToFile;
            DiagJob_EntryCount  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            DiagJob_EntrySize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            DiagJob_BlockSize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            Dtc_BlockOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader) + dataBufferOffsetRelativeToFile;
            Dtc_EntryCount  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            Dtc_EntrySize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            Dtc_BlockSize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            Env_BlockOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader) + dataBufferOffsetRelativeToFile;
            Env_EntryCount  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            Env_EntrySize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            // bitflags will be exhausted at this point, load the extended bitflags
            ecuBitFlags = ecuBitFlagsExtended;

            Env_BlockSize = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            VcDomain_BlockOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader) + dataBufferOffsetRelativeToFile;
            VcDomain_EntryCount  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            VcDomain_EntrySize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            VcDomain_BlockSize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            Presentations_BlockOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader) + dataBufferOffsetRelativeToFile;
            Presentations_EntryCount  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            Presentations_EntrySize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            Presentations_BlockSize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            Info_BlockOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader) + dataBufferOffsetRelativeToFile;
            Info_EntryCount  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            Info_EntrySize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            Info_BlockSize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            Unk_BlockOffset = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader) + dataBufferOffsetRelativeToFile;
            Unk_EntryCount  = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            Unk_EntrySize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);
            Unk_BlockSize   = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            Unk39 = CaesarReader.ReadBitflagInt32(ref ecuBitFlags, reader);

            // read ecu's supported interfaces and subtypes

            // try to read interface block from the interface buffer table
            // this address is relative to the definitions block
            long interfaceTableAddress = BaseAddress + InterfaceTableOffset;

            // Console.WriteLine($"Interface table address: {interfaceTableAddress:X}, given offset: {interfaceTableOffset:X}");

            ECUInterfaces = new List <ECUInterface>();
            for (int interfaceBufferIndex = 0; interfaceBufferIndex < InterfaceBlockCount; interfaceBufferIndex++)
            {
                // Console.WriteLine($"Parsing interface {interfaceBufferIndex + 1}/{interfaceBlockCount}");

                // find our interface block offset
                reader.BaseStream.Seek(interfaceTableAddress + (interfaceBufferIndex * 4), SeekOrigin.Begin);
                // seek to the actual block (ambiguity: is this relative to the interface table or the current array?)
                int interfaceBlockOffset = reader.ReadInt32();

                long ecuInterfaceBaseAddress = interfaceTableAddress + interfaceBlockOffset;

                ECUInterface ecuInterface = new ECUInterface(reader, ecuInterfaceBaseAddress);
                ECUInterfaces.Add(ecuInterface);
            }

            // try to read interface subtype block from the interface buffer table
            // this address is relative to the definitions block
            ECUInterfaceSubtypes = new List <ECUInterfaceSubtype>();
            long ctTableAddress = BaseAddress + SubinterfacesOffset;

            // Console.WriteLine($"Interface subtype table address: {ctTableAddress:X}, given offset: {ecuChildTypesOffset:X}");
            for (int ctBufferIndex = 0; ctBufferIndex < SubinterfacesCount; ctBufferIndex++)
            {
                // Console.WriteLine($"Parsing interface subtype {ctBufferIndex + 1}/{ecuNumberOfEcuChildTypes}");
                // find our ct block offset
                reader.BaseStream.Seek(ctTableAddress + (ctBufferIndex * 4), SeekOrigin.Begin);
                // seek to the actual block (ambiguity: is this relative to the ct table or the current array?)
                int  actualBlockOffset = reader.ReadInt32();
                long ctBaseAddress     = ctTableAddress + actualBlockOffset;

                ECUInterfaceSubtype ecuInterfaceSubtype = new ECUInterfaceSubtype(reader, ctBaseAddress, ctBufferIndex);
                ECUInterfaceSubtypes.Add(ecuInterfaceSubtype);
            }

            CreateDiagServices(reader, language);
            CreateEcuVariants(reader, language);
            CreatePresentations(reader, language);
            ECUDescriptionTranslated = language.GetString(EcuDescription_CTF);
        }