-
Notifications
You must be signed in to change notification settings - Fork 2
/
PassThru.cs
6987 lines (6847 loc) · 461 KB
/
PassThru.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// /////////////////////////////////////////////////////////////////////////////
// ________ .__
// / _____/ ____ ____ ___________|__| ____
// / \ ____/ __ \ / \_/ __ \_ __ \ |/ ___\
// \ \_\ \ ___/| | \ ___/| | \/ \ \___
// \______ /\___ >___| /\___ >__| |__|\___ >
// \/ \/ \/ \/ \/
// ________ .__ __ .__
// \______ \ |__|____ ____ ____ ____ _______/ |_|__| ____
// | | \| \__ \ / ___\ / \ / _ \/ ___/\ __\ |/ ___\
// | ` \ |/ __ \_/ /_/ > | ( <_> )___ \ | | | \ \___
// /_______ /__(____ /\___ /|___| /\____/____ > |__| |__|\___ >
// \/ \//_____/ \/ \/ \/ //Version 1.0.0
//
using J2534;
using System;
using System.IO;
using System.Net;
using System.Data;
using System.Text;
using System.Linq;
using System.Drawing;
using System.IO.Pipes;
using System.IO.Ports;
using System.Threading;
using System.Reflection;
using System.Diagnostics;
using System.Collections;
using System.Windows.Forms;
using System.Globalization;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Reflection.Emit;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
using static System.Net.Mime.MediaTypeNames;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace PassThruJ2534
{
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public partial class PassThru : Form
{
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public PassThru()
{
InitializeComponent();
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void PassThru_Load(object sender, EventArgs e)
{
comboBoxJ2534Devices.Items.Clear();
// ///////////////////////////////////////////////////
//1) Search for all of our J2534 Devices
List<J2534.J2534Device> MyListOfJ2534Devices = J2534DeviceFinder.FindInstalledJ2534DLLs();
//List of devices installed on the PC
for (int i = 0; i < MyListOfJ2534Devices.Count; i++)
{
string J2534ToolsName = MyListOfJ2534Devices[i].Name;
comboBoxJ2534Devices.Items.Add(J2534ToolsName);
Log("Found Installed Device: " + J2534ToolsName.ToString() + "\r\n");
}
if (comboBoxJ2534Devices.Items.Count > 0)
{
comboBoxJ2534Devices.SelectedIndex = 0;
}
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void CmdDetectDevicesClick(object sender, EventArgs e)
{
// ///////////////////////////////////////////////////
//1) Search for all of our J2534 Devices
List<J2534.J2534Device> MyListOfJ2534Devices = J2534DeviceFinder.FindInstalledJ2534DLLs();
//List of devices installed on the PC
for (int i = 0; i < MyListOfJ2534Devices.Count; i++)
{
string J2534ToolsName = MyListOfJ2534Devices[i].Name;
comboBoxJ2534Devices.Items.Add(J2534ToolsName);
Log("Found Installed Device: " + J2534ToolsName.ToString() + "\r\n");
}
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private Thread thread;
private bool stopThread;
bool connectFlag = false;
bool highSpeedCan;
byte ecuId;
byte ecuId2;
byte ecuId3;
byte ecuId4;
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void comboBoxCanBus_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void groupBox3_Enter(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
//TESTER PRESENT SIGNAL START BUTTON
private void button2_Click(object sender, EventArgs e)
{
timerTesterPresent.Enabled = true;
buttonStopTester.Enabled = true;
buttonTester.Enabled = false;
}
private void DSC_Click(object sender, EventArgs e)
{
}
private void groupBox4_Enter(object sender, EventArgs e)
{
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
// ADD MSG BUTTON CODE
private void button6_Click(object sender, EventArgs e)
{
// Check if the textbox is not empty
if (!string.IsNullOrWhiteSpace(textBoxPassThruMsg.Text))
{
// Add the text from the TextBox to the ListBox
listBox1.Items.Add(textBoxPassThruMsg.Text);
// Optionally clear the TextBox after adding
textBoxPassThruMsg.Clear();
}
else
{
MessageBox.Show("Please input a diagnostic message into the textbox to add it to the send list.");
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void textBoxLog_TextChanged(object sender, EventArgs e)
{
}
//bruteforce 0x27 button click
private void button6_Click_1(object sender, EventArgs e)
{
switch (comboBoxSess.SelectedIndex)
{
case 0:
startDiagnosticSession(0x81);
break;
case 1:
startDiagnosticSession(0x85);
break;
case 2:
startDiagnosticSession(0x87);
break;
case 3:
startDiagnosticSession(0xFE);
break;
case 4:
startDiagnosticSession(0xFA);
break;
case 5:
startDiagnosticSession(0x01);
break;
case 6:
startDiagnosticSession(0x02);
break;
case 7:
startDiagnosticSession(0x03);
break;
case 8:
startDiagnosticSession(0x04);
break;
}
bruteforce();
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void buttonConnect(object sender, EventArgs e)
{
if (button1.Text == "Connect")
{
if (comboBoxCanBus.SelectedIndex == 0) { highSpeedCan = true; } else { highSpeedCan = false; }
string hexString1 = textBoxEcuRx.Text;
// Convert the hex string to an integer
int intValue1 = Convert.ToInt32(hexString1, 16);
// Extract the two bytes
ecuId = (byte)((intValue1 >> 8) & 0xFF); // Extract 0x07
ecuId2 = (byte)(intValue1 & 0xFF); // Extract 0xE0
string hexString2 = textBoxEcuTx.Text;
// Convert the hex string to an integer
int intValue2 = Convert.ToInt32(hexString2, 16);
// Extract the two bytes
ecuId4 = (byte)((intValue2 >> 8) & 0xFF); // Extract 0x07
ecuId3 = (byte)(intValue2 & 0xFF); // Extract 0xE0
connectFlag = true;
button1.BackColor = System.Drawing.Color.Crimson; // Change Connect BTN colour to RED
button1.Text = "Disconnect"; //
Log("Initialising Comms...\r\n");
connectSelectedJ2534Device(ecuId, ecuId2, ecuId3, highSpeedCan);
}
else
{
connectFlag = false;
button1.BackColor = System.Drawing.Color.MediumSeaGreen; // Change Connect BTN colour to RED
button1.Text = "Connect"; //
Log("Disconnected.\r\n");
connectSelectedJ2534Device(ecuId, ecuId2, ecuId3, highSpeedCan);
}
}
//THIS DOESNT WORK
public void buttonSendPassThruMsg_Click(object sender, EventArgs e)
{
string message = listBox1.SelectedItem.ToString();
message = message.Replace(" ", "");
byte[] byteMsg = StringToByteArray(message); // Your byte array from the string
byte[] byteEcuId = new byte[] { 0, 0, ecuId, ecuId2 }; // Your ECU ID byte arra
// Create a new byte array with enough space to hold both arrays
byte[] combinedArray = new byte[byteMsg.Length + byteEcuId.Length];
// Copy byteMsg into the new array
Array.Copy(byteMsg, 0, combinedArray, 0, byteMsg.Length);
// Copy byteEcuId into the new array, starting right after the byteMsg
Array.Copy(byteEcuId, 0, combinedArray, byteMsg.Length, byteEcuId.Length);
sendPassThruMsg(combinedArray);
}
private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
//DIAG SESS CONTROL BTN
int sessionType = comboBoxDiagSessControl.SelectedIndex;
switch (sessionType)
{
case 0x00:
startDiagnosticSession(0x81);
break;
case 0x01:
startDiagnosticSession(0x85);
break;
case 0x02:
startDiagnosticSession(0x87);
break;
case 0x03:
startDiagnosticSession(0xFE);
break;
case 0x04:
startDiagnosticSession(0xFA);
break;
case 0x05:
startDiagnosticSession(0x81);
break;
case 0x06:
startDiagnosticSession(0x02);
break;
case 0x07:
startDiagnosticSession(0x03);
break;
case 0x08:
startDiagnosticSession(0x04);
break;
}
}
private void button4_Click(object sender, EventArgs e)
{
//ECU RESET BTN
int resetType = comboBoxEcuReset.SelectedIndex;
switch (resetType)
{
case 0x00:
ecuReset(0x01);
break;
case 0x01:
ecuReset(0x02);
break;
case 0x02:
ecuReset(0x03);
break;
case 0x03:
ecuReset(0x04);
break;
case 0x04:
ecuReset(0x05);
break;
}
}
private void button8_Click(object sender, EventArgs e)
{
//CONTROL DTC BTN
int onOff = comboBoxControlDtc.SelectedIndex;
switch (onOff)
{
case 0x00:
controlDtcSetting(0x01);
break;
case 0x01:
controlDtcSetting(0x02);
break;
}
}
private void tabPage8_Click(object sender, EventArgs e)
{
}
private void tabPage5_Click(object sender, EventArgs e)
{
}
private void button14_Click(object sender, EventArgs e)
{
mode07();
}
private void textBox21_TextChanged(object sender, EventArgs e)
{
}
private void tabPage7_Click(object sender, EventArgs e)
{
}
private void button17_Click(object sender, EventArgs e)
{
mode09();
}
private void button16_Click(object sender, EventArgs e)
{
mode03();
}
private void button15_Click(object sender, EventArgs e)
{
mode04();
}
private void button13_Click(object sender, EventArgs e)
{
mode0A();
}
private void button11_Click(object sender, EventArgs e)
{
mode01();
}
private void button12_Click(object sender, EventArgs e)
{
mode02();
}
private void listBoxObd_SelectedIndexChanged(object sender, EventArgs e)
{
//Service / Mode $01 Live Sensor Data
//Service / Mode $02 Freeze Frame Data
//Service / Mode $03 Stored Fault Codes
//Service / Mode $04 Clear Stored Codes
//Service / Mode $05 Oxygen Sensor Monitor
//Service / Mode $06 Monitoring Results
//Service / Mode $07 Pending Fault Codes
//Service / Mode $08 Test Device Control
//Service / Mode $09 Vehicle Information
//Service / Mode $0A Permanent Fault Codes
switch (listBoxObd.SelectedIndex)
{
case 0x00:
Log("Mode $01 Live Sensor Data\r\n");
mode01();
break;
case 0x01:
Log("Mode $02 Freeze Frame Data\r\n");
mode02();
break;
case 0x02:
Log("Mode $03 Stored Fault Codes\r\n");
mode03();
break;
case 0x03:
Log("Clear Stored Codes\r\n");
mode04();
break;
case 0x04:
Log("Mode $05 Oxygen Sensor Monitor\r\n");
mode05();
break;
case 0x05:
Log("Mode $06 Monitoring Results\r\n");
mode06();
break;
case 0x06:
Log("Mode $07 Pending Fault Codes\r\n");
mode07();
break;
case 0x07:
Log("Mode $08 Test Device Control\r\n");
mode08();
break;
case 0x08:
Log("Mode $09 Vehicle Information\r\n");
mode09();
break;
case 0x09:
Log("Mode $0A Permanent Fault Codes\r\n");
mode0A();
break;
}
}
// //////////////////////////////////
private void bruteforceSecurityAccessToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void readOBDDTCToolStripMenuItem_Click(object sender, EventArgs e)
{
mode03();
}
private void clearOBD2DTCToolStripMenuItem_Click(object sender, EventArgs e)
{
mode04();
}
private void requestVehicleVINToolStripMenuItem_Click(object sender, EventArgs e)
{
mode09();
}
// /////////////////////////////////////////////////////////////////////////////
/// <summary>
/// VIN DECODER CODE BUTTON CLICKS
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//GET VIN NUMBER BTN
private void button10_Click(object sender, EventArgs e)
{
try
{
textBoxInterVin.Text = "";
byte[] mode0902 = new byte[] { 0, 0, 0x7, 0xDF, 0x09, 0x02 };
string vehicleIdentificationNumberMsg = sendPassThruMsg(mode0902);
//string test = "00 00 07 E8 49 02 01 36 46 50 41 41 41 4A 47 53 57 36 4A 38 30 35 30 31";
string interVin = vehicleIdentificationNumberMsg.Replace(" ", "");
string interVin2 = interVin.Substring(14);
string finalVin = HexToASCII(interVin2);
textBoxInterVin.Text += finalVin;
//string finalVin = textBoxInterVin.Text; // FOR TESTING THE VIN NUMEBR DISPLAY I HAVE DISABLED THE REQUEST VIN MESSAGE AND LOGIC
t0.Text = finalVin.Substring(0, 1);
t1.Text = finalVin.Substring(1, 1);
t2.Text = finalVin.Substring(2, 1);
t3.Text = finalVin.Substring(3, 1);
t4.Text = finalVin.Substring(4, 1);
t5.Text = finalVin.Substring(5, 1);
t6.Text = finalVin.Substring(6, 1);
t7.Text = finalVin.Substring(7, 1);
t8.Text = finalVin.Substring(8, 1);
t9.Text = finalVin.Substring(9, 1);
t10.Text = finalVin.Substring(10, 1);
t11.Text = finalVin.Substring(11, 1);
t12.Text = finalVin.Substring(12, 1);
t13.Text = finalVin.Substring(13, 1);
t14.Text = finalVin.Substring(14, 1);
t15.Text = finalVin.Substring(15, 1);
t16.Text = finalVin.Substring(16, 1);
}
catch (Exception ex)
{
Log("VIN Grab ERROR\r\n");
}
}
//VIN DECODE BUTTON
private void button7_Click_1(object sender, EventArgs e)
{
try
{
string vin = textBoxInterVin.Text.ToUpper();
//string vin = txtVIN.Text.ToUpper();
if (vin.Length != 17)
{
MessageBox.Show("VIN must be 17 characters long.");
return;
}
// Decoding each section of the VIN
labelWmi.Text = PassThruJ2534.lib.Decoder.VIN_DECODER.DecodeWMI(vin.Substring(0, 3)); // World Manufacturer Identifier
labelVd.Text = PassThruJ2534.lib.Decoder.VIN_DECODER.DecodeVDS(vin.Substring(3, 6)); // Vehicle Descriptor Section
labelSn.Text = PassThruJ2534.lib.Decoder.VIN_DECODER.DecodeVIS(vin.Substring(9, 8)); // Vehicle Identifier Section
}
catch (Exception ex)
{
Log("VIN Decoding Error\r\n");
}
}
//VIN DECODE CLICK
private void button7_Click_2(object sender, EventArgs e)
{
try
{
string vin = textBoxInterVin.Text.ToUpper();
//string vin = txtVIN.Text.ToUpper();
if (vin.Length != 17)
{
MessageBox.Show("VIN must be 17 characters long.");
return;
}
// Decoding each section of the VIN
labelWmi.Text = PassThruJ2534.lib.Decoder.VIN_DECODER.DecodeWMI(vin.Substring(0, 3)); // World Manufacturer Identifier
labelVd.Text = PassThruJ2534.lib.Decoder.VIN_DECODER.DecodeVDS(vin.Substring(3, 6)); // Vehicle Descriptor Section
labelSn.Text = PassThruJ2534.lib.Decoder.VIN_DECODER.DecodeVIS(vin.Substring(9, 8)); // Vehicle Identifier Section
}
catch (Exception ex)
{
Log("VIN Decoding Error\r\n");
}
}
// /////////////////////////////////////////////////////////////
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox8_TextChanged(object sender, EventArgs e)
{
}
private void label18_Click(object sender, EventArgs e)
{
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void tabPage9_Click(object sender, EventArgs e)
{
}
private void label22_Click(object sender, EventArgs e)
{
}
//WHATS THIS FOR
bool flagNoDataAbort;
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 0x23 Direct Memory Read readMemoryByAddress
private async void button20_Click(object sender, EventArgs e)
{
await Task.Run(DirectMemoryRead);
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 0x23 Direct Memory Read readMemoryByAddress
public async Task DirectMemoryRead()
{
// Show SaveFileDialog on the main UI thread
string fileName = null;
Invoke(new Action(() =>
{
SaveFileDialog saveFileDialog = new SaveFileDialog
{
Filter = "Binary Files (*.bin)|*.bin",
Title = "Generic Diagnostic Tool | Direct Memory Read | Save File",
DefaultExt = "bin",
FileName = "DMR.bin"
};
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
fileName = saveFileDialog.FileName;
}
}));
// If no file selected, return
if (fileName == null)
{
MessageBox.Show("Save operation canceled.", "Canceled", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
// Parse inputs from UI on the main thread
uint startAddress = 0, finishAddress = 0, blockSize = 0;
int millisecTxGap = 0;
Invoke(new Action(() =>
{
startAddress = Convert.ToUInt32(textBoxStartAddress.Text, 16);
finishAddress = Convert.ToUInt32(textBoxFinishAddress.Text, 16);
blockSize = Convert.ToUInt32(textBoxBlockSize.Text, 16);
millisecTxGap = Convert.ToInt32(textBoxMilliseconds.Text);
}));
// Validate inputs
if (startAddress > finishAddress || blockSize == 0)
{
Invoke(new Action(() =>
{
MessageBox.Show("Invalid input: Ensure start address <= finish address and block size > 0.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}));
return;
}
// Perform file operations in a background task
await Task.Run(() =>
{
using (FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
for (uint i = startAddress; i <= finishAddress; i += blockSize)
{
uint currentBlockSize = (i + blockSize > finishAddress + 1) ? finishAddress - i + 1 : blockSize;
// Read memory block and simulate delay
byte[] memory = readMemoryByAddress(i, currentBlockSize);
Task.Delay(millisecTxGap).Wait();
// Write the memory block to the file
fileStream.Write(memory, 0, memory.Length);
}
}
});
// Show success message on the UI thread
Invoke(new Action(() =>
{
MessageBox.Show("Direct Memory Read saved successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}));
}
catch (FormatException)
{
MessageBox.Show("Please enter valid hexadecimal numbers in the text boxes.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (OverflowException)
{
MessageBox.Show("One or more values are too large. Please enter smaller hexadecimal numbers.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private TResult Invoke<TResult>(Func<TResult> function)
{
if (InvokeRequired)
return (TResult)Invoke(function);
return function();
}
private void Invoke(Action action)
{
if (InvokeRequired)
Invoke((Delegate)action);
else
action();
}
//Invoke required for updating listbox 2 from a seperate async task...
private Task UpdateUIAsync(Action uiAction)
{
return Task.Run(() =>
{
if (listBox2.InvokeRequired)
{
listBox2.Invoke(uiAction);
}
else
{
uiAction();
}
});
}
private async void button22_Click(object sender, EventArgs e)
{
await Task.Run(bruteforceDids);
}
/// <summary>
/// BRUTEFORCE DID's with service 0x22 readDataByCommonId
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public async Task bruteforceDids()
{
try
{
for (int did = 0x0000; did <= 0xFFFF; did++)
{
int response = 0;
// Extract upper and lower byte of the DID
byte upperByte = (byte)((did >> 8) & 0xFF); // Upper byte of the DID
byte lowerByte = (byte)(did & 0xFF); // Lower byte of the DID
// Send the PassThru message with the current DID
byte[] array = { 0, 0, ecuId, ecuId2, 0x22, upperByte, lowerByte };
string did1 = sendPassThruMsg(array); did1 = did1.Replace(" ", ""); string didFound = "$" + did1.Substring(10, 4);
response = int.Parse(did1.Substring(8, 2), System.Globalization.NumberStyles.HexNumber);
switch (response)
{
case 0x62:
await UpdateUIAsync(() =>
{
Log($"Data Identifier Located @ {didFound}\r\n");
listBox2.Items.Add(didFound);
});
break;
case 0x7F:
await UpdateUIAsync(() =>
{
Log($"No Data Identifier Located @ {did1}\r\n");
});
break;
default:
await UpdateUIAsync(() =>
{
Log("No Response from ECU\r\n");
});
break;
}
}
}
catch (Exception)
{
Log("An Exception Occured with the DID Bruteforce attempt. \r\n");
return;
}
}
/// <summary>
/// Request a Single DID in hex form using service 0x22
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
// Retreive Single DID
private void button23_Click(object sender, EventArgs e)
{
string did = textBoxDid.Text;
// Convert the first two characters to a byte (0xFF)
byte upperByte = Convert.ToByte(did.Substring(0, 2), 16);
// Convert the last two characters to a byte (0xFF)
byte lowerByte = Convert.ToByte(did.Substring(2, 2), 16);
byte[] array = { 0x00, 0x00, ecuId, ecuId2, 0x22, upperByte, lowerByte };
sendPassThruMsg(array);
}
private void tabPage10_Click(object sender, EventArgs e)
{
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void tabPage3_Click(object sender, EventArgs e)
{
}
// Load the service 0x22 ListBox and disable the default listbox when 0x22 Tab is selected
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (TABCNTRL1.SelectedTab == READDIAG) // Check if the selected tab is Tab 2
{
tabControl2.SelectedTab = DTC;
}
else
{
tabControl2.SelectedTab = PT;
}
if (TABCNTRL1.SelectedTab == READDATABYCOMMONID) // Check if the selected tab is Tab 2
{
listBox1.Visible = false;
textBoxPassThruMsg.Visible = false;
buttonAddMsg.Visible = false;
buttonSendPassThruMsg.Visible = false;
labelPTMsg.Visible = false;
listBox2.Visible = true;
labelDid.Visible = true;
pBarBruteforce.Visible = false;
}
else if (TABCNTRL1.SelectedTab == SECURITY)
{
pBarBruteforce.Visible = true;
}
else
{
pBarBruteforce.Visible = false;
listBox1.Visible = true;
textBoxPassThruMsg.Visible = true;
buttonAddMsg.Visible = true;
buttonSendPassThruMsg.Visible = true;
labelPTMsg.Visible = true;
listBox2.Visible = false;
labelDid.Visible = false;
}
}
private Dictionary<string, string> definitions;
//DID LOOKUP TABLE
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
// Initialize the dictionary with items and definitions
definitions = new Dictionary<string, string>
{
{ "0102", "Air Cleaner Housing DoorFlap Control" },
{ "0103", "Air Fuel Ratio Mass Ratio Of AirFuel At Lambda 1" },
{ "0104", "Percent Alcohol Learning Status" },
{ "0105", "Fuel Learning Enable Conditions" },
{ "0106", "Differential Pressure Feedback DPFE LEGR Differential Pressure Learned Offset Value" },
{ "0107", "Fuel Injector 7 Fault Status" },
{ "0108", "Fuel Injector 8 Fault Status" },
{ "0109", "TurbochargerSupercharger Wastegate A Commanded" },
{ "010A", "Turbocharger Turbine Inlet Valve A Duty Cycle" },
{ "010B", "TurbochargerSupercharger Wastegate B Position Commanded" },
{ "010C", "Turbocharger Turbine Inlet Valve A Position Corrected" },
{ "010D", "Turbocharger Turbine Inlet Valve A Position Sensor Voltage" },
{ "010E", "Turbocharger Turbine Inlet Valve A Position Commanded" },
{ "010F", "Boost Pressure Actuator Bank 1 Duty Cycle" },
{ "0110", "Turbocharger Turbine Inlet Valve A Position Measured" },
{ "0111", "TurbochargerSupercharger Boost Sensor A Fault Status" },
{ "0112", "Crankcase Pressure Sensor Fault Status" },
{ "0113", "Particulate Filter Pressure Sensor A Fault Status" },
{ "0114", "Charge Air Cooler Temperature Sensor Bank 1 Fault Status" },
{ "0115", "Fuel Injector Group B Supply Sense Circuit Voltage Measured Raw" },
{ "0116", "Status Of The ECU Output That Controls The Relay That Controls The Fuel Injector Group B Supply Voltage" },
{ "0117", "Coolant Pump B Control Speed Commanded" },
{ "0118", "Coolant Pump B Control Circuit Duty Cycle Commanded" },
{ "0119", "Coolant Pump B Control Diagnostic Status" },
{ "011A", "Coolant Pump A Control Speed Commanded" },
{ "011B", "Fuel Composition Sensor Frequency Measured Raw" },
{ "011C", "Fuel Composition Sensor Fault Status" },
{ "011D", "Coolant Pump C Control Circuit Duty Cycle Commanded" },
{ "011E", "Coolant Pump C Control Diagnostic Status" },
{ "011F", "Coolant Pump C Control Speed Commanded" },
{ "0120", "StarterGenerator Current Operation Mode" },
{ "0121", "Cylinder 1 Deactivation System Operation State" },
{ "0122", "Cylinder 1 Deactivation Control Commanded" },
{ "0123", "Cylinder 1 Deactivation Desired And Actual States" },
{ "0124", "Cylinder 1 Deactivation Solenoid Duty Cycle Commanded" },
{ "0125", "Cylinder 1 Deactivation System Operation Mode" },
{ "0126", "Cylinder 1 Deactivation System FMEM Status" },
{ "0127", "Cylinder 1 Deactivation Solenoid Output Fault Status" },
{ "0128", "Conditions Preventing Cylinder Deactivation" },
{ "0129", "Engine Oil Level Sensor Fault Status" },
{ "012A", "DFI Specific Long Term Fuel Trim Bank 2" },
{ "012B", "DFI Specific Long Term Fuel Trim Bank 1" },
{ "012C", "PFI Specific Long Term Fuel Trim Bank 2" },
{ "012D", "PFI Specific Long Term Fuel Trim Bank 1" },
{ "012E", "Engine Oil Pressure Sensor A Fault Status" },
{ "012F", "Engine Oil Temperature Sensor A Fault Status" },
{ "0130", "Misfire Transmission Information" },
{ "0131", "Exhaust Flow Control Valve A Position Measured" },
{ "0132", "Exhaust Flow Control Valve B Fault Status" },
{ "0133", "Exhaust Flow Control Valve B Monitor Status" },
{ "0134", "Exhaust Flow Control Valve B Position Measured" },
{ "0135", "Exhaust Flow Control Valve A Monitor Status" },
{ "0136", "Exhaust Flow Control Valve B Position Commanded" },
{ "0137", "Particulate Filter PF System Percentage of the Maximum Soot Loading Bank 2 Inferred Closed Loop" },
{ "0138", "Electric Fan Load Shed Operation Event Data" },
{ "013B", "Water In Fuel WIF History Data" },
{ "013C", "Engine Coolant Temperature Sensor Data 4" },
{ "013D", "Engine coolant Temperature Sensor Data 2" },
{ "0142", "EGR Valve Drop Test Break Away Duty Cycle" },
{ "0143", "EGR Valve Accumulator to Trigger Cleaning Cycle" },
{ "0144", "EGR Valve Drop Test Drop Speed" },
{ "0145", "EGR Valve Accumulator to Trigger BurOff Cycle" },
{ "0146", "Intake Air Pressure Corrected" },
{ "0147", "Intake Air Pressure Measured" },
{ "0148", "Glow Plug 2 Voltage Commanded With Resistance Compensation" },
{ "0149", "Glow Plug 3 Voltage Commanded With Resistance Compensation" },
{ "014A", "Glow Plug 4 Voltage Commanded With Resistance Compensation" },
{ "014B", "Glow Plug 5 Voltage Commanded With Resistance Compensation" },
{ "014C", "Glow Plug 6 Voltage Commanded With Resistance Compensation" },
{ "014D", "Glow Plug 7 Voltage Commanded With Resistance Compensation" },
{ "014E", "Glow Plug 8 Voltage Commanded With Resistance Compensation" },
{ "014F", "Particulate Filter Pressure Sensor A Differential Pressure Raw" },
{ "0150", "Particulate Filter Pressure Sensor B Differential Pressure Raw" },
{ "0151", "Intake Air Temperature Sensor Fault Status" },
{ "0152", "Turbocharger Inlet Pressure Sensor Fault Status" },
{ "0153", "Mass Air Flow Sensor Fault Status" },
{ "0154", "Manifold Absolute Pressure Sensor A Fault Status" },
{ "0155", "Exhaust Pressure Sensor A Fault Status" },
{ "0156", "Glow Plug 1 Voltage Commanded With Resistance Compensation" },
{ "0157", "Engine Mount Control B Duty Cycle Commanded" },
{ "0158", "Engine Mount Control B Circuit Fault Status" },
{ "0159", "Manifold Absolute Pressure Sensor A Fault Status" },
{ "015B", "Status of Diesel Selective Catalytic Reduction SCR System Diagnostic Routine Entry Conditions" },
{ "015C", "Brushless Fuel Pump Monitor FPM Status" },
{ "015D", "NOx Sensor Adaptation Offset Bank 1 Sensor 2" },
{ "015E", "NOx Sensor Adaptation Offset Bank 1 Sensor 1" },
{ "015F", "Reductant Temperature Measurement Value From Sensor" },
{ "0160", "Reductant Level Measurement Value From Sensor" },
{ "0161", "Reductant Concentration Measurement Value From Sensor" },
{ "0162", "Selected Calibration Dataset" },
{ "0163", "Reductant Pump Requested Pump Strokes Remaining" },
{ "0164", "Reductant Backflow Pump Duty Cycte" },
{ "0165", "Quantity Of Reductant Injected On This Drive Cycle" },
{ "0166", "Reductant Line Pressure Modelled" },
{ "0167", "Particulate Filter Pressure Sensor D Gauge Pressure Raw" },
{ "0168", "Particulate Filter Pressure Sensor C Voltage" },
{ "0169", "Particulate Filter Pressure Sensor C Status" },
{ "016A", "Particulate Filter Pressure Sensor C Gauge Pressure Raw" },
{ "016B", "Particulate Filter Pressure Sensor D Voltage" },
{ "016C", "Particulate Filter Pressure Sensor D Status" },
{ "016D", "Exhaust Gas Temperature Bank 1 Sensor 1 Fault Status" },
{ "016E", "Oil Maintenance Minder Change Oil Soon and Change Oil Now Data" },
{ "016F", "Engine Coolant Bypass Valve D Output Status" },
{ "0170", "EGR Position Sensor Learned Offset With Statuses" },
{ "0171", "Turbocharger Wastegate Position Sensor A Learned Offset With Statuses" },
{ "0172", "Turbocharger Wastegate Position Sensor B Learned Offset With Statuses" },
{ "0173", "Clutch Actuator Clutch Slave Cylinder Position Relative To The Learned Offset Where Torque Capacity Changes At Its Max Rate" },
{ "0174", "Clutch Actuator Clutch Slave Cylinder Position Raw With No Learned Offset Applied" },
{ "0175", "Clutch Actuator Clutch Slave Cylinder Position Relative To The Learned Offset Corrected" },
{ "0176", "Clutch Actuator Clutch Slave Cylinder Position Relative To The Learned Offset Raw" },
{ "0177", "Belt Integrated Starter Generator Belt Tensioner Control Fault Status" },
{ "0178", "Total Fuel Consumed By The Vehicle Over Its Life Time" },
{ "0179", "Transmission Range Selector Gear Shift Position Circuit C Frequency Measured Raw" },
{ "017A", "Transmission Range Selector Gear Shift Position Circuit C Duty Cycle Measured Raw" },
{ "017B", "4WDAWD Rear Differential Unit Motor Position At Which The Variable Torque Clutch Begins To Transfer Torque Kiss Position" },
{ "017C", "4WDAWD Power Transfer Unit Actuator Cam Position Corrected" },
{ "017D", "4WDAWD Power Transfer Unit DisconnectConnect Clutch Commanded State" },
{ "017E", "4WDAWD Rear Differential Unit Input Shaft Speed Raw" },
{ "017F", "4WDAWD Power Transfer Unit Actuator Duty Cycle Output Commanded" },
{ "0180", "4WDAWD Power Transfer Unit Actuator Device Status" },
{ "0181", "4WDAWD Power Transfer Unit High Level Strategy Desired State For DisconnectConnect Function Commanded" },
{ "0182", "4WDAWD Rear Differential Unit Actuator A Requested Torque" },
{ "0183", "4WDAWD Rear Differential Unit Motor Position Corrected" },
{ "0184", "4WDAWD Power Transfer Unit Sump Temperature Measured Raw" },
{ "0185", "4WDAWD Rear Differential Unit Actuator A Torque Capacity Inferred" },
{ "0186", "Selective Catalytic Reduction SCR System First Fill Special Function Entry Condition Preventing Activation" },
{ "0187", "Selective Catalytic Reduction SCR System First Fill Special Function Activation" },
{ "0188", "Selective Catalytic Reduction SCR System First Fill Special Function Status" },
{ "0189", "Transmission Fluid Pressure Sensor A Absolute Pressure Measured Raw" },
{ "018A", "Transmission Fluid Pressure Sensor B Absolute Pressure Measured Raw" },
{ "018C", "Low Pressure Fuel Pressure Sensor Fault Status" },
{ "018D", "Low Pressure Fuel Temperature Sensor Fault Status" },
{ "018E", "Number Of Alarm Wakups That Have Occurred Since The Last Keoff" },
{ "018F", "Wakup Manager Status" },
{ "0190", "Auxiliary Transmission Fluid Pump Control Percentage Speed Commanded" },
{ "0191", "Transmission Fluid Pressure Sensor C Absolute Pressure Measured Raw" },
{ "0192", "Engine Disconnect Clutch Solenoid Current Fault Status" },
{ "0193", "Auxiliary Transmission Fluid Pump Monitor Percentage Speed Measured" },
{ "0194", "Engine Disconnect Clutch Operational State Commanded" },