public ModuleDataElemRecord(Table table, byte[] record) : base(table, record) { this.moduleForId = (ushort)this.table.readField(this, FIELD_MODULE_FOR_ID); this.txid = (uint)this.table.readField(this, FIELD_TXID); // Add TXRecord to corresponding ModuleRecord's List<TXRecord> Table moduleTable = this.table.db.tables[Database.TABLE_MODULE]; Table txTable = this.table.db.tables[Database.TABLE_TRANSMIT]; ModuleRecord moduleRec = (ModuleRecord)moduleTable.getRecord(this.moduleForId); TXRecord txRec = (TXRecord)txTable.getRecord(this.txid); moduleRec.dataelements.Add(txRec); }
public string getTX(uint id) { Table t = this.tables[TABLE_TRANSMIT]; Record recordObj = t.getRecord(id); if (recordObj == null) { return(null); } TXRecord txrec = (TXRecord)recordObj; string protocolTxt = this.getProtocolText(txrec.dadRecord.protocolid) + "; "; return(txrec.name + ": " + protocolTxt + "xmit: " + txrec.xmitstring + "; sc: " + txrec.scname); }
public string getDetailedTX(uint id) { Table t = this.tables[TABLE_TRANSMIT]; Record recordObj = t.getRecord(id); if (recordObj == null) { return(null); } TXRecord txrec = (TXRecord)recordObj; string protocolTxt = this.getProtocolText(txrec.dadRecord.protocolid) + "; "; string detailText = ""; detailText += Environment.NewLine + "dadreqlen: " + txrec.dadRecord.requestLength + "; dadresplen: " + txrec.dadRecord.responseLength + ";"; detailText += Environment.NewLine + "dadextroff: " + txrec.dadRecord.extractOffset + "; dadextrsize: " + txrec.dadRecord.extractSize + ";"; detailText += Environment.NewLine + "desid: " + txrec.dataelemsetid + "; desname: " + this.getDESString(txrec.dataelemsetid) + ";"; detailText += Environment.NewLine + "record: " + BitConverter.ToString(txrec.record) + ";"; return(txrec.name + ": " + protocolTxt + "xmit: " + txrec.xmitstring + "; sc: " + txrec.scname + ";" + detailText); }
public void readRecords() { int readOffset = (int)this.offset; // NOTE: loop unrolled purposely switch (this.id) { case Database.TABLE_STATE_DATA_SPECIFIER: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new SDSRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_BINARY_DATA_SPECIFIER: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new BDSRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_NUMERIC_DATA_SPECIFIER: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new NDSRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_CONVERTERS_STATE: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new SCRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_CONVERTERS_NUMERIC: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new NCRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_STATE_ENTRY: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new StateEntryRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_STRINGS: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new StringRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_DATA_ACQUISITION_DESCRIPTION: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new DADRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_DES_INFO: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new DESRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_SERIVCE_CAT_STUFFS: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new ServiceCatRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_TRANSMIT: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new TXRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_MODULE_DATAELEMENT: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new ModuleDataElemRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_MODULE: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new ModuleRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_DRB_MENU: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new MenuRecord(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; case Database.TABLE_UNKNOWN_3: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new RecordUnknownWithString(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize), 2); } break; case Database.TABLE_UNKNOWN_21: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new RecordUnknownWithString(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize), 3); } break; default: for (ushort i = 0; i < this.rowCount; ++i) { records[i] = new Record(this, this.db.dbReader.ReadBytes(ref readOffset, this.rowSize)); } break; } }
public void consoleCommandHandler(string cmd) { try { string tofind = ""; string[] tofindall = null; ushort modid, stid; uint txid; cmd = cmd.Trim(); this.cmdHistory.Add(cmd); cmdIdx = this.cmdHistory.Count - 1; string[] splitted = cmd.Split(new char[] { ' ' }, 2); switch (splitted[0]) { case "readdb": if (splitted.Length > 1 && splitted[1].Trim() != "") { this.fi = new FileInfo(splitted[1].Trim()); } this.checkDB(); break; case "unloaddb": this.db = null; // We're taking out a huge chunk of memory, so let GC clear it out right away. GC.Collect(); break; case "stringid": this.checkDB(); stid = Util.parseUShort(splitted[1]); StringRecord stringRec = (StringRecord)this.db.tables[Database.TABLE_STRINGS].getRecord(stid); if (stringRec != null) { string toWrite = "text: " + stringRec.text; if (stringRec.obdCodeString != "" && stringRec.obdCodeString != " ") { toWrite += "; OBD: " + stringRec.obdCodeString; } this.writeToConsole(toWrite + Environment.NewLine); } else { this.writeToConsole("(null)" + Environment.NewLine); } break; case "stringsearch": this.checkDB(); this.writeBulkToConsoleStart(); string searching = splitted[1].ToLower(); foreach (StringRecord sr in this.db.tables[Database.TABLE_STRINGS].records) { if (sr.text.ToLower().Contains(searching) || sr.obdCodeString.ToLower().Contains(searching)) { string toWrite = "0x" + sr.id.ToString("x4") + ": text: " + sr.text; if (sr.obdCodeString != "" && sr.obdCodeString != " ") { toWrite += "; OBD: " + sr.obdCodeString; } this.writeBulkToConsole(toWrite); } } this.writeBulkToConsoleEnd(); break; case "txid": this.checkDB(); txid = Util.parseUInt(splitted[1]); this.writeToConsole(this.db.getDetailedTX(txid) + Environment.NewLine); break; case "txrunconverter": case "txrunconvertermetric": this.checkDB(); string[] txconvsplit = splitted[1].Split(new char[] { ' ' }, 2); long convdata = 0; txid = Util.parseUInt(txconvsplit[0]); convdata = Util.parseLong(txconvsplit[1]); Table txconvtable = this.db.tables[Database.TABLE_TRANSMIT]; TXRecord txconvrec = (TXRecord)txconvtable.getRecord(txid); string result = txconvrec.converter.processData(convdata, outputMetric: splitted[0].EndsWith("metric")); this.writeToConsole(result + Environment.NewLine); break; case "txsearch": this.checkDB(); tofind = splitted[1].ToLower(); if (tofind.Contains(" && ")) { tofindall = tofind.Split(new string[] { " && " }, StringSplitOptions.RemoveEmptyEntries); } this.writeBulkToConsoleStart(); for (uint u = 0x80000000; u < 0x80009000; ++u) { try { string temp = this.db.getTX(u); if (temp != null) { string templower = temp.ToLower(); if (tofindall != null) { foreach (string s in tofindall) { if (!templower.Contains(s)) { goto SKIPTX; } } this.writeBulkToConsole(temp + "; 0x" + u.ToString("x")); } else if (templower.Contains(tofind)) { this.writeBulkToConsole(temp + "; 0x" + u.ToString("x")); } } } catch { continue; } SKIPTX: continue; } this.writeBulkToConsoleEnd(); break; case "dumpstateconverter": case "dumpconverter": case "convertertostring": this.checkDB(); txid = Util.parseUInt(splitted[1]); Table ctsTable = this.db.tables[Database.TABLE_TRANSMIT]; TXRecord ctsTxRecord = (TXRecord)ctsTable.getRecord(txid); this.writeToConsole(ctsTxRecord.converter.ToString() + Environment.NewLine); break; case "dumptableinfo": this.checkDB(); ushort tableNum = Util.parseUShort(splitted[1]); Table t = this.db.tables[tableNum]; string toPrint = ""; toPrint += "Table: " + tableNum + "; Columns: " + t.colCount + "; Rows: " + t.rowCount + ";" + Environment.NewLine; toPrint += "ColSizes: " + BitConverter.ToString(t.colSizes) + "; RowSize: " + t.rowSize + ";" + Environment.NewLine; this.writeToConsole(toPrint); break; case "stringidfuzz": this.checkDB(); string[] stringfuzzsplit = splitted[1].Split(new char[] { ' ' }, 2); ushort stringfuzzTable = Util.parseUShort(stringfuzzsplit[0]); byte stringfuzzTableCol = (byte)Util.parseUShort(stringfuzzsplit[1]); Table tt = this.db.tables[stringfuzzTable]; int stringfuzzhits = 0; int stringfuzzzeros = 0; foreach (Record stringfuzzrec in tt.records) { ushort stringfuzzfield = (ushort)tt.readField(stringfuzzrec, stringfuzzTableCol); string stringfuzzstring = this.db.getString(stringfuzzfield); if (stringfuzzstring != "(null)") { ++stringfuzzhits; } if (stringfuzzfield == 0) { ++stringfuzzzeros; } } this.writeToConsole("Records: " + tt.records.Length + "; Hits: " + stringfuzzhits + "; Zeros: " + stringfuzzzeros + Environment.NewLine); break; case "genericidfuzz": this.checkDB(); string[] fuzzsplit = splitted[1].Split(new char[] { ' ' }, 4); ushort fuzzerTableId = Util.parseUShort(fuzzsplit[0]); byte fuzzerTableCol = (byte)Util.parseUShort(fuzzsplit[1]); ushort fuzzingTableId = Util.parseUShort(fuzzsplit[2]); byte fuzzingTableCol = (byte)Util.parseUShort(fuzzsplit[3]); Table fuzzerTable = this.db.tables[fuzzerTableId]; Table fuzzingTable = this.db.tables[fuzzingTableId]; int fuzzhits = 0; int fuzzzeros = 0; foreach (Record fuzzingRec in fuzzingTable.records) { uint fuzzingRecID = (uint)fuzzingTable.readField(fuzzingRec, fuzzingTableCol); Record fuzzerRec = fuzzerTable.getRecord(fuzzingRecID, idcol: fuzzerTableCol, sorted: false); if (fuzzerRec != null) { ++fuzzhits; } if (fuzzingRecID == 0) { ++fuzzzeros; } } this.writeToConsole("Records: " + fuzzingTable.records.Length + "; Hits: " + fuzzhits + "; Zeros: " + fuzzzeros + Environment.NewLine); break; case "modid": this.checkDB(); modid = Util.parseUShort(splitted[1]); string modresult = this.db.getModule(modid); if (modresult != null) { this.writeToConsole(modresult + Environment.NewLine); } else { this.writeToConsole("No such module ID." + Environment.NewLine); } this.txtConsoleInput.Focus(); this.txtConsoleInput.AppendText("modid " + splitted[1]); break; case "modlist": case "modsearch": this.checkDB(); if (splitted[0] != "modlist") { tofind = splitted[1].ToLower(); if (tofind.Contains(" && ")) { tofindall = tofind.Split(new string[] { " && " }, StringSplitOptions.RemoveEmptyEntries); } } this.writeBulkToConsoleStart(); for (ushort l = 0x0000; l < 0x2000; ++l) { try { string temp = this.db.getModule(l); if (temp != null) { if (splitted[0] != "modlist") { string templower = temp.ToLower(); if (tofindall != null) { foreach (string s in tofindall) { if (!templower.Contains(s)) { goto SKIPMOD; } } this.writeBulkToConsole(temp + "; 0x" + l.ToString("x")); } else if (templower.Contains(tofind)) { this.writeBulkToConsole(temp + "; 0x" + l.ToString("x")); } } else { this.writeBulkToConsole(temp + "; 0x" + l.ToString("x")); } } } catch { continue; } SKIPMOD: continue; } this.writeBulkToConsoleEnd(); break; case "modtxlist": this.checkDB(); modid = Util.parseUShort(splitted[1]); Record rec = this.db.tables[Database.TABLE_MODULE].getRecord(modid); if (rec != null) { ModuleRecord modrec = (ModuleRecord)rec; this.writeBulkToConsoleStart(); foreach (TXRecord txrec in modrec.dataelements) { string temp = this.db.getTX(txrec.id); this.writeBulkToConsole(temp + "; 0x" + txrec.id.ToString("x")); } this.writeBulkToConsoleEnd(); } else { this.writeToConsole("No such module." + Environment.NewLine); } break; } } catch (Exception e) { this.writeToConsole("Exception: " + e.ToString() + Environment.NewLine); } }