└── src
├── XmlToIdc
├── XmlToIdc.exe
├── obj
│ └── x86
│ │ └── Debug
│ │ └── XmlToIdc.exe
└── Properties
│ └── AssemblyInfo.cs
├── MakeXmlDef
├── MakeXmlDef.exe
├── MakeXmlDef.userprefs
├── MakeXmlDef.sln
└── MakeXmlDef
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── MakeXmlDef.csproj
│ └── MakeXmlDef.cs
├── RR2EcuFlash
├── RR2EcuFlash.exe
├── RR2EcuFlash
│ ├── AssemblyInfo.cs
│ └── Main.cs
└── Make_ECUFlash_def.pl
├── Definitions
├── upload.html
├── update_logger.pl
└── UpdateLoggerFromXmlForEcuId.php
└── IDA
├── ida.idc
├── Convert16bitOperand.idc
├── WalkTheRom.idc
├── Format16bitTABLE.idc
├── MakeTablePointers.idc
├── Format_SH_VectorTable.idc
└── Format16bitROM.idc
/src/XmlToIdc/XmlToIdc.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dschultzca/DefinitionTools/HEAD/src/XmlToIdc/XmlToIdc.exe
--------------------------------------------------------------------------------
/src/MakeXmlDef/MakeXmlDef.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dschultzca/DefinitionTools/HEAD/src/MakeXmlDef/MakeXmlDef.exe
--------------------------------------------------------------------------------
/src/RR2EcuFlash/RR2EcuFlash.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dschultzca/DefinitionTools/HEAD/src/RR2EcuFlash/RR2EcuFlash.exe
--------------------------------------------------------------------------------
/src/XmlToIdc/obj/x86/Debug/XmlToIdc.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dschultzca/DefinitionTools/HEAD/src/XmlToIdc/obj/x86/Debug/XmlToIdc.exe
--------------------------------------------------------------------------------
/src/MakeXmlDef/MakeXmlDef.userprefs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/Definitions/upload.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | RR Logger XML Import Tool
4 |
5 |
6 |
7 |
8 |
9 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/MakeXmlDef/MakeXmlDef.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MakeXmlDef", "MakeXmlDef\MakeXmlDef.csproj", "{31512E83-07B9-4D70-AD6D-9C8387EEF835}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|x86 = Debug|x86
9 | Release|x86 = Release|x86
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {31512E83-07B9-4D70-AD6D-9C8387EEF835}.Debug|x86.ActiveCfg = Debug|x86
13 | {31512E83-07B9-4D70-AD6D-9C8387EEF835}.Debug|x86.Build.0 = Debug|x86
14 | {31512E83-07B9-4D70-AD6D-9C8387EEF835}.Release|x86.ActiveCfg = Release|x86
15 | {31512E83-07B9-4D70-AD6D-9C8387EEF835}.Release|x86.Build.0 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(MonoDevelopProperties) = preSolution
18 | StartupItem = MakeXmlDef\MakeXmlDef.csproj
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/src/MakeXmlDef/MakeXmlDef/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MakeXmlDef")]
9 | [assembly: AssemblyDescription("Create a ECU def from a template and IDA names/address info.")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("dschultz")]
12 | [assembly: AssemblyProduct("MakeXmlDef")]
13 | [assembly: AssemblyCopyright("Copyright © dschultz 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("b7d6d26b-1509-47d9-b0aa-fe46aa94109f")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.3.1.*")]
36 | [assembly: AssemblyFileVersion("0.3.1.0")]
37 |
--------------------------------------------------------------------------------
/src/XmlToIdc/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("XmlToIdc")]
9 | [assembly: AssemblyDescription("Convert RomRaider XML definition data to IDA naming scripts")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("NSFW")]
12 | [assembly: AssemblyProduct("XmlToIdc")]
13 | [assembly: AssemblyCopyright("Copyright © 2015 NSFW@romraider.forum and Dale C. Schultz")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("1f7256d3-481c-4b0a-9393-877c7530a955")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.2.8.*")]
36 | [assembly: AssemblyFileVersion("1.2.8.0")]
37 |
--------------------------------------------------------------------------------
/src/RR2EcuFlash/RR2EcuFlash/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // Information about this assembly is defined by the following attributes.
6 | // Change them to the values specific to your project.
7 |
8 | [assembly: AssemblyTitle("RR2EcuFlash")]
9 | [assembly: AssemblyDescription("Convert a RomRaider Editor definition to an EcuFlash definition")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Dale C. Schultz")]
12 | [assembly: AssemblyProduct("RR2EcuFlash")]
13 | [assembly: AssemblyCopyright("Copyright © 2012 - Dale C. Schultz")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("1f7256d3-481c-4b0a-9393-877c7530a559")]
24 |
25 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
26 | // The form "{Major}.{Minor}.*" will automatically update the build and revision,
27 | // and "{Major}.{Minor}.{Build}.*" will update just the revision.
28 |
29 | [assembly: AssemblyVersion("1.0.0.*")]
30 | [assembly: AssemblyFileVersion("1.0.0.0")]
31 |
32 | // The following attributes are used to specify the signing key for the assembly,
33 | // if desired. See the Mono documentation for more information about signing.
34 |
35 | //[assembly: AssemblyDelaySign(false)]
36 | //[assembly: AssemblyKeyFile("")]
37 |
38 |
--------------------------------------------------------------------------------
/src/MakeXmlDef/MakeXmlDef/MakeXmlDef.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 10.0.0
7 | 2.0
8 | {31512E83-07B9-4D70-AD6D-9C8387EEF835}
9 | Exe
10 | MakeXmlDef
11 | MakeXmlDef
12 |
13 |
14 | true
15 | full
16 | false
17 | bin\Debug
18 | DEBUG;
19 | prompt
20 | 4
21 | x86
22 | true
23 |
24 |
25 | full
26 | true
27 | bin\Release
28 | prompt
29 | 4
30 | x86
31 | true
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/IDA/ida.idc:
--------------------------------------------------------------------------------
1 | //
2 | // This file is automatically executed when IDA is started.
3 | // You can define your own IDC functions and assign hotkeys to them.
4 | //
5 | // You may add your frequently used functions here and they will
6 | // be always available.
7 | //
8 | //
9 | #include
10 |
11 | static main(void) {
12 |
13 | //
14 | // This function is executed when IDA is started.
15 |
16 | AddHotkey("Ctrl-Alt-B", "myMakeByte");
17 | AddHotkey("Ctrl-Alt-W", "myMakeWord");
18 | AddHotkey("Ctrl-Alt-D", "myMakeDword");
19 | AddHotkey("Ctrl-Alt-F", "myMakeFloat");
20 | }
21 |
22 | /*
23 | * Copyright (C) 2012 Dale C. Schultz
24 | * RomRaider member ID: dschultz
25 | *
26 | * You are free to use this script and the finctions:
27 | * myMakeByte
28 | * myMakeWord
29 | * myMakeDword
30 | * myMakeFloat
31 | * for any purpose, but please keep
32 | * notice of where it came from!
33 | *
34 | */
35 | //-----------------------------------------------------------------------
36 | // Format the selected range of addresses or at the cursor position as BYTE
37 | static myMakeByte(void) {
38 | auto addrFrom, addrTo;
39 | if ((SelStart() == BADADDR) || (SelEnd() == BADADDR)) {
40 | addrFrom = here;
41 | addrTo = addrFrom + 1;
42 | }
43 | else {
44 | addrFrom = SelStart();
45 | addrTo = SelEnd();
46 | }
47 | while (addrFrom < addrTo) {
48 | MakeUnknown(addrFrom, 1, DOUNK_SIMPLE);
49 | MakeByte(addrFrom);
50 | addrFrom = addrFrom+1;
51 | }
52 | }
53 |
54 | //-----------------------------------------------------------------------
55 | // Format the selected range of addresses or at the cursor position as WORD
56 | static myMakeWord(void) {
57 | auto addrFrom, addrTo;
58 | if ((SelStart() == BADADDR) || (SelEnd() == BADADDR)) {
59 | addrFrom = here;
60 | addrTo = addrFrom + 1;
61 | }
62 | else {
63 | addrFrom = SelStart();
64 | addrTo = SelEnd();
65 | }
66 | while (addrFrom < addrTo) {
67 | MakeUnknown(addrFrom, 2, DOUNK_SIMPLE);
68 | MakeWord(addrFrom);
69 | addrFrom = addrFrom+2;
70 | }
71 | }
72 | //-----------------------------------------------------------------------
73 | // Format the selected range of addresses or at the cursor position as DOUBLE WORD
74 | static myMakeDword(void) {
75 | auto addrFrom, addrTo;
76 | if ((SelStart() == BADADDR) || (SelEnd() == BADADDR)) {
77 | addrFrom = here;
78 | addrTo = addrFrom + 1;
79 | }
80 | else {
81 | addrFrom = SelStart();
82 | addrTo = SelEnd();
83 | }
84 | while (addrFrom < addrTo) {
85 | MakeUnknown(addrFrom, 4, DOUNK_SIMPLE);
86 | MakeDword(addrFrom);
87 | addrFrom = addrFrom+4;
88 | }
89 | }
90 |
91 | //-----------------------------------------------------------------------
92 | // Format the selected range of addresses or at the cursor position as FLOAT
93 | static myMakeFloat(void) {
94 | auto addrFrom, addrTo;
95 | if ((SelStart() == BADADDR) || (SelEnd() == BADADDR)) {
96 | addrFrom = here;
97 | addrTo = addrFrom + 1;
98 | }
99 | else {
100 | addrFrom = SelStart();
101 | addrTo = SelEnd();
102 | }
103 | while (addrFrom < addrTo) {
104 | MakeUnknown(addrFrom, 4, DOUNK_SIMPLE);
105 | MakeFloat(addrFrom);
106 | addrFrom = addrFrom+4;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/src/IDA/Convert16bitOperand.idc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Dale C. Schultz
3 | * RomRaider member ID: dschultz
4 | *
5 | * You are free to use this script for any purpose, but please keep
6 | * notice of where it came from!
7 | *
8 | * Version: 4
9 | * Date : 2013-12-09
10 | *
11 | * This script attempts to convert immediate and indirect references to
12 | * offsets if the value is greater than 0x00FF.
13 | * This script REQUIRES that Segments are create prior to its use.
14 | * Use the IDA scipt Format16BitROM.idc to achieve this. The
15 | * DATA segment to be referenced must have a base paragraph set to the
16 | * offest value >> 8. i.e.: offset 0x20000, segment base: 0x2000
17 | *
18 | * Offest creation can be started in four ways.
19 | * 1) run the script at the screen cursor position to convert one instruction entry, but beware of item 2)
20 | * 2) place the screen cursor at the beginning of a function to convert the entire function start to end
21 | * 3) select a screen range and convert the selected range
22 | * 4) place the screen cursor at 0x0000 to convert the entire segment, NOT ADVISED
23 | * NOTE: if you need to remove an offset from an instruction, press Alt-F1 and delete the operand info
24 | * in the Operand text field and press OK.
25 | *
26 | * If you wish to make this script available via an IDA hotkey you will need to modify your ida.idc script.
27 | * Add the line: #include
28 | * at the top of the file.
29 | * Then add this line to the main() section of ida.idc
30 | * AddHotkey("F4", "Convert16bitOperand");
31 | *
32 | */
33 |
34 | #include
35 | // uncomment the next line if you are using hotkeys, then comment out the static main() line
36 | //static Convert16bitOperand() {
37 | static main() {
38 | auto proc, currAddr, endAddr, opType, segReg, op1, op2, newOp1, xAddrStr, xAddr, opTypeStr;
39 | proc = get_processor_name();
40 | if (proc != "6816") {
41 | Message(form("%s processor not supported by Convert16bitOperand() function\n", proc));
42 | return;
43 | }
44 | if (SegByName("RAM") == BADADDR) {
45 | Warning("This ROM is not segmented properly for use by the Convert16bitOperand() function");
46 | return;
47 | }
48 | currAddr = here;
49 | if (currAddr == 0x0) {
50 | currAddr = Word(0x2);
51 | endAddr = SegEnd(currAddr);
52 | }
53 | else if (GetFunctionAttr(currAddr, FUNCATTR_START) == currAddr) {
54 | endAddr = GetFunctionAttr(currAddr, FUNCATTR_END);
55 | }
56 | else if ((SelStart() == BADADDR) || (SelEnd() == BADADDR)) {
57 | currAddr = here;
58 | endAddr = currAddr + 1;
59 | }
60 | else {
61 | currAddr = SelStart();
62 | endAddr = SelEnd();
63 | }
64 | // walk the selected range and convert referecnes
65 | while (currAddr < endAddr) {
66 | opType = GetOpType(currAddr, 0);
67 | opTypeStr = "";
68 | if ((opType == o_displ) || (opType == o_imm)) {
69 | op2 = "";
70 | segReg = -1;
71 | op1 = GetOpnd(currAddr, 0);
72 | if (strstr(op1, "X") != BADADDR) {
73 | op2 = "X";
74 | segReg = GetReg(currAddr,"XK");
75 | }
76 | if (strstr(op1, "Y") != BADADDR) {
77 | op2 = "Y";
78 | segReg = GetReg(currAddr,"YK");
79 | }
80 | if (strstr(op1, "Z") != BADADDR) {
81 | op2 = "Z";
82 | segReg = GetReg(currAddr,"ZK");
83 | }
84 | if (strstr(GetMnem(currAddr), "ldx") != BADADDR) {
85 | op2 = "X";
86 | segReg = GetReg(currAddr,"XK");
87 | }
88 | if (strstr(GetMnem(currAddr), "ldy") != BADADDR) {
89 | op2 = "Y";
90 | segReg = GetReg(currAddr,"YK");
91 | }
92 | if (strstr(GetMnem(currAddr), "ldz") != BADADDR) {
93 | op2 = "Z";
94 | segReg = GetReg(currAddr,"ZK");
95 | }
96 | if (op2 != "" && segReg != BADADDR) {
97 | if (opType == o_displ) {
98 | OpAlt(currAddr, 0, "");
99 | OpOff(MK_FP("ROM", currAddr), 0, segReg << 16);
100 | opTypeStr = "register";
101 | }
102 | if (opType == o_imm && (GetOperandValue(currAddr, 0) > 0x00FF)) {
103 | OpAlt(currAddr, 0, "");
104 | OpOffEx(MK_FP("ROM", currAddr), 0, REF_OFF32, -1, segReg << 16, 0);
105 | opTypeStr = "immediate";
106 | }
107 | newOp1 = GetOpnd(currAddr, 0);
108 | xAddrStr = substr(newOp1 , 0, strstr(newOp1, ","));
109 | xAddr = LocByName(xAddrStr);
110 | add_dref(currAddr, xAddr, dr_I);
111 | Message(form("At %s converting %s reference using I%s with base 0x%X, referencing location %s\n", atoa(currAddr), opTypeStr, op2, segReg << 16, xAddrStr));
112 | }
113 | }
114 | currAddr = currAddr + 2;
115 | }
116 | }
117 |
118 |
--------------------------------------------------------------------------------
/src/RR2EcuFlash/Make_ECUFlash_def.pl:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2010+ Dale C. Schultz
3 | # RomRaider member ID: dschultz
4 | #
5 | # You are free to use this script for any purpose, but please keep
6 | # notice of where it came from!
7 | #
8 | # Use this script to convert the RomRaider Editor definition to an ECUFlash definition.
9 | # Then update the ECUFlash ROM ID info.
10 | #
11 | # Caveats: This script expects only one ROM definition in the file
12 | # excluding the tag. Basically take the RR ECU def of interest
13 | # and copy it to an XML format of a typical EcuFlash def, start/ending
14 | # with only the and included elements.
15 | #
16 | unless ($ARGV[0]) {
17 | print "Input file missing...\n";
18 | print "Usage: $0 \n";
19 | exit 1;
20 | }
21 |
22 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
23 | $mDate = sprintf("%04d-%02d-%02d", $year+=1900, $mon+=1, $mday);
24 |
25 | use XML::TreeBuilder;
26 | my $tree = XML::TreeBuilder->new();
27 |
28 | $tree->parse_file($ARGV[0]);
29 | $xmlid = $tree->find_by_tag_name('xmlid')->as_text;
30 | $address = $tree->find_by_tag_name('internalidaddress')->as_text;
31 | $ecuid = $tree->find_by_tag_name('ecuid')->as_text;
32 | $year = $tree->find_by_tag_name('year')->as_text;
33 | $market = $tree->find_by_tag_name('market')->as_text;
34 | $model = $tree->find_by_tag_name('model')->as_text;
35 | $submodel = $tree->find_by_tag_name('submodel')->as_text;
36 | $trans = $tree->find_by_tag_name('transmission')->as_text;
37 | $flash = $tree->find_by_tag_name('flashmethod')->as_text;
38 |
39 | open (OUTPUT, ">${xmlid}.xml") || die "Could not open output file to write. $!\n";
40 |
41 | #
45 | print OUTPUT <
47 |
68 | PREAMBLE
69 | print OUTPUT "\n";
70 | print OUTPUT " \n";
71 | print OUTPUT " ${xmlid}\n";
72 | print OUTPUT " ${address}\n";
73 | print OUTPUT " ${xmlid}\n";
74 | print OUTPUT " ${ecuid}\n";
75 | print OUTPUT " ${year}\n";
76 | print OUTPUT " ${market}\n";
77 | print OUTPUT " Subaru\n";
78 | print OUTPUT " ${model}\n";
79 | print OUTPUT " ${submodel}\n";
80 | print OUTPUT " ${trans}\n";
81 | print OUTPUT " SH7058\n";
82 | print OUTPUT " ${flash}\n";
83 | print OUTPUT " subarudbw\n";
84 | print OUTPUT " \n";
85 | print OUTPUT " 32BITBASE\n";
86 | foreach my $rom ($tree->find_by_tag_name('table')){
87 | $TableName = $rom->attr_get_i('name');
88 | next if ($TableName eq "Checksum Fix");
89 | $TableName = "Fuel Pump Duty" if ($TableName eq "Fuel Pump Duty Cycle");
90 | $TableName =~ s/ $/__/;
91 | $TableName =~ s/ $/_/;
92 | $TableAddress = $rom->attr_get_i('storageaddress');
93 | $TableAddress =~ s/^0x//;
94 | $TableType = $rom->find_by_tag_name('table')->attr_get_i('type');
95 | $TableType =~ s/^X Axis$/X/;
96 | $TableType =~ s/^Y Axis$/Y/;
97 | $TableXsize = $rom->attr_get_i('sizex');
98 | $TableYsize = $rom->attr_get_i('sizey');
99 | if (!$TableType) {
100 | if (!$LastTable) {
101 | }
102 | elsif ($LastTable eq "data") {
103 | print OUTPUT " />\n";
104 | }
105 | else {
106 | print OUTPUT ">\n";
107 | }
108 | print OUTPUT ' \n" . ' \n\n";
131 | close OUTPUT;
132 |
--------------------------------------------------------------------------------
/src/IDA/WalkTheRom.idc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Dale C. Schultz
3 | * RomRaider member ID: dschultz
4 | *
5 | * You are free to use this script for any purpose, but please keep
6 | * notice of where it came from!
7 | *
8 | * Version: 2
9 | */
10 |
11 | #include
12 | static main() {
13 | auto currAddr, currName, fout, textOut, namesArray, xSize, ySize, xSizeAr, ySizeAr, lastAddr;
14 | namesArray = GetArrayId("myNAMES");
15 | DeleteArray(namesArray);
16 | namesArray = CreateArray("myNAMES");
17 | xSizeAr = GetArrayId("myXSIZE");
18 | DeleteArray(xSizeAr);
19 | xSizeAr = CreateArray("myXSIZE");
20 | ySizeAr = GetArrayId("myYSIZE");
21 | DeleteArray(ySizeAr);
22 | ySizeAr = CreateArray("myYSIZE");
23 |
24 | // walk the ROM and list the names and addresses
25 | currAddr = 0x00000000;
26 | lastAddr = SegEnd(currAddr);
27 | while (currAddr < lastAddr) {
28 | currName = Name(currAddr);
29 | if (currName != "") {
30 | if (
31 | strstr(currName, "dword_") == -1 &&
32 | strstr(currName, "off_") == -1 &&
33 | strstr(currName, "byte_") == -1 &&
34 | strstr(currName, "word_") == -1 &&
35 | strstr(currName, "flt_") == -1 &&
36 | strstr(currName, "loc_") == -1 &&
37 | strstr(currName, "unk_") == -1 &&
38 | strstr(currName, "sub_") == -1 &&
39 | strstr(currName, "_Axis") == -1) {
40 | if (strstr(currName, "Table_") == 0) {
41 | // 1 axis table with no data conversion values, undefined data type
42 | // Table Definition is 12 bytes long
43 | if (((Word(currAddr) > 0) && (Word(currAddr) < 256)) &&
44 | (Word(currAddr+2) == 0x0000)) {
45 | currAddr = Get2dTable(currAddr, 11);
46 | }
47 | // 1 axis table with data conversion values and defined data type
48 | // Table Definition is 20 bytes long
49 | if (((Word(currAddr) > 0) && (Word(currAddr) < 256)) &&
50 | ((Word(currAddr+2) == 0x0400) || (Word(currAddr+2) == 0x0800)) &&
51 | !((Word(currAddr+14) == 0x0400) || (Word(currAddr+14) == 0x0800))) {
52 | currAddr = Get2dTable(currAddr, 19);
53 | }
54 | // 1 axis table with no data conversion values and defined data type
55 | // Table Definition is 12 bytes long
56 | if (((Word(currAddr) > 0) && (Word(currAddr) < 256)) &&
57 | ((Word(currAddr+2) == 0x0400) || (Word(currAddr+2) == 0x0800)) &&
58 | ((Word(currAddr+14) == 0x0400) || (Word(currAddr+14) == 0x0800))) {
59 | currAddr = Get2dTable(currAddr, 11);
60 | }
61 | // 2 axis table with no data conversion values, undefined data type
62 | // Table Definition is 20 bytes long
63 | if (((Word(currAddr) > 0) && (Word(currAddr) < 256)) &&
64 | ((Word(currAddr+2) > 0) && (Word(currAddr+2) < 256)) &&
65 | (Dword(currAddr+16) == 0x00000000)) {
66 | currAddr = Get3dTable(currAddr, 19);
67 | }
68 | // 2 axis table with data conversion values and defined data type
69 | // Table Definition is 28 bytes long
70 | if (((Word(currAddr) > 0) && (Word(currAddr) < 256)) &&
71 | ((Word(currAddr+2) > 0) && (Word(currAddr+2) < 256)) &&
72 | ((Dword(currAddr+16) == 0x04000000) || (Dword(currAddr+16) == 0x08000000))) {
73 | currAddr = Get3dTable(currAddr, 27);
74 | }
75 | }
76 | else {
77 | Message(currName + " " + form("%08s",ltoa(currAddr, 16)) + "\n");
78 | SetHashLong(namesArray, currName, currAddr);
79 | }
80 | }
81 | }
82 | currAddr = currAddr + 1;
83 | }
84 | fout = fopen("addresses.txt", "w");
85 | textOut = GetFirstHashKey(namesArray);
86 | while (textOut != GetLastHashKey(namesArray)) {
87 | writestr(fout, textOut + " " + form("%08s",ltoa(GetHashLong(namesArray, textOut), 16)));
88 | xSize = GetHashLong(xSizeAr, textOut);
89 | if (xSize != 0) {
90 | writestr(fout, " " + form("%d",ltoa(xSize, 10)));
91 | }
92 | ySize = GetHashLong(ySizeAr, textOut);
93 | if (ySize != 0) {
94 | writestr(fout, " " + form("%d",ltoa(ySize, 10)));
95 | }
96 | writestr(fout, "\n");
97 | textOut = GetNextHashKey(namesArray, textOut);
98 | }
99 | fclose(fout);
100 | DeleteArray(namesArray);
101 | DeleteArray(xSizeAr);
102 | DeleteArray(ySizeAr);
103 | }
104 |
105 | static Get2dTable(currAddr, defSize) {
106 | auto arrayId, axisAddr, axisName, dataAddr, dataLength, dataName, sizeId;
107 | arrayId = GetArrayId("myNAMES");
108 | sizeId = GetArrayId("myYSIZE");
109 | dataLength = Word(currAddr);
110 | axisAddr = Dword(currAddr+4);
111 | dataAddr = Dword(currAddr+8);
112 | dataName = substr(Name(currAddr),6,-1);
113 | axisName = dataName + "_Y_Axis";
114 | MakeNameEx(axisAddr, axisName, SN_CHECK);
115 | MakeNameEx(dataAddr, dataName, SN_CHECK);
116 | Message(dataName + " " + form("%08s",ltoa(dataAddr, 16)) + " " + form("%d", dataLength,10) + "\n");
117 | SetHashLong(arrayId, dataName, dataAddr);
118 | SetHashLong(sizeId, dataName, dataLength);
119 | Message(axisName + " " + form("%08s",ltoa(axisAddr, 16)) + "\n");
120 | SetHashLong(arrayId, axisName, axisAddr);
121 | currAddr = currAddr + defSize;
122 | return currAddr;
123 | }
124 |
125 | static Get3dTable(currAddr, defSize) {
126 | auto arrayId, axisXAddr, axisXName, axisYAddr, axisYName, dataYLength, dataXLength, dataAddr, dataName, xSizeId, ySizeId;
127 | arrayId = GetArrayId("myNAMES");
128 | xSizeId = GetArrayId("myXSIZE");
129 | ySizeId = GetArrayId("myYSIZE");
130 | dataXLength = Word(currAddr);
131 | dataYLength = Word(currAddr+2);
132 | axisXAddr = Dword(currAddr+4);
133 | axisYAddr = Dword(currAddr+8);
134 | dataAddr = Dword(currAddr+12);
135 | dataName = substr(Name(currAddr),6,-1);
136 | axisXName = dataName + "_X_Axis";
137 | axisYName = dataName + "_Y_Axis";
138 | MakeNameEx(axisXAddr, axisXName, SN_CHECK);
139 | MakeNameEx(axisYAddr, axisYName, SN_CHECK);
140 | MakeNameEx(dataAddr, dataName, SN_CHECK);
141 | Message(dataName + " " + form("%08s",ltoa(dataAddr, 16)) + " " + form("%d", dataXLength,10) + " " + form("%d", dataYLength,10) + "\n");
142 | SetHashLong(arrayId, dataName, dataAddr);
143 | SetHashLong(xSizeId, dataName, dataXLength);
144 | SetHashLong(ySizeId, dataName, dataYLength);
145 | Message(axisXName + " " + form("%08s",ltoa(axisXAddr, 16)) + "\n");
146 | SetHashLong(arrayId, axisXName, axisXAddr);
147 | Message(axisYName + " " + form("%08s",ltoa(axisYAddr, 16)) + "\n");
148 | SetHashLong(arrayId, axisYName, axisYAddr);
149 | currAddr = currAddr + defSize;
150 | return currAddr;
151 | }
152 |
--------------------------------------------------------------------------------
/src/IDA/Format16bitTABLE.idc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Dale C. Schultz
3 | * RomRaider member ID: dschultz
4 | *
5 | * You are free to use this script for any purpose, but please keep
6 | * notice of where it came from!
7 | *
8 | * Version: 1
9 | * Date : 2013-12-14
10 | *
11 | * This script is used to format tables in a 16bit ROM.
12 | *
13 | Layout of a 2D table:
14 | ---------------------
15 | axis values
16 | axis length - 1 (i.e.: 0 based)
17 | type (this is the byte refereneced in subroutines, i.e.: Table_)
18 | data values
19 | When reading the map:
20 | idxY = table map type byte (function assumes yk=2).
21 | regB (byte) or regD (word) = axis (depending on data type).
22 |
23 |
24 | Layout of a 3D table:
25 | ---------------------
26 | y-axis values
27 | y-axis length - 1 (i.e.: 0 based)
28 | x-axis values
29 | x-axis length - 1 (i.e.: 0 based)
30 | type (this is the byte refereneced in subroutines, i.e.: Table_)
31 | data values
32 | When reading the map:
33 | idxY = table map type byte 16-bit offset
34 | regB (byte) or regD (word) = x-axis (depending on data type)
35 | regE = y-axis
36 |
37 |
38 | Layout of a 2D series:
39 | ----------------------
40 | axis step
41 | axis start
42 | number of data items - 1 (i.e.: 0 based)
43 | type (this is the byte refereneced in subroutines, i.e.: Table_)
44 | data values
45 |
46 |
47 | Layout of a 3D series:
48 | ----------------------
49 | y-axis step
50 | y-axis start
51 | x-axis series length - 1 (i.e.: 0 based)
52 | x-axis step
53 | x-axis start
54 | x-axis series length - 1 (i.e.: 0 based)
55 | type (this is the byte refereneced in subroutines, i.e.: Table_)
56 | data values
57 |
58 | Type byte - bit definition:
59 | 7--4-2-0
60 | 00000000
61 | ||||||||- bit 0: 0 = byte, 1 = word (X or single axis data type)
62 | |||||||-
63 | ||||||- bit 2: 0 = byte, 1 = word (Y or dual axis data type)
64 | |||||-
65 | ||||- bit 4: 0 = byte, 1 = word (data values)
66 | |||-
67 | ||-
68 | |- bit7: 0 = Table, 1 = Series
69 |
70 | */
71 |
72 | #include
73 |
74 | static main() {
75 | auto ync, axisInfo, dim, typeByte, fAxisType, sAxisType, dataType, data, storageType, xStart, xStep, yStart, yStep;
76 | ync = AskYN(0, "Format as 3D table?"); // -1:cancel,0-no,1-ok
77 | if (ync == -1) { return 0;}
78 |
79 | axisInfo = GetArrayId("AXIS_INFO");
80 | DeleteArray(axisInfo);
81 | axisInfo = CreateArray("AXIS_INFO");
82 | MakeByte(here);
83 | typeByte = Byte(here);
84 |
85 | // Determine data type of first axis
86 | if (typeByte & 0x01)
87 | {
88 | fAxisType = 2;
89 | }
90 | else
91 | {
92 | fAxisType = 1;
93 | }
94 |
95 | // Determine data type of second axis
96 | if (typeByte & 0x04)
97 | {
98 | sAxisType = 2;
99 | }
100 | else
101 | {
102 | sAxisType = 1;
103 | }
104 |
105 | // Determine data type of data elements
106 | if (typeByte & 0x10)
107 | {
108 | dataType = 2;
109 | }
110 | else
111 | {
112 | dataType = 1;
113 | }
114 |
115 | // Determine if this is a Table or Series
116 | if (typeByte & 0x80)
117 | {
118 | storageType = 1;
119 | }
120 | else
121 | {
122 | storageType = 0;
123 | }
124 |
125 | if (storageType == 0)
126 | {
127 | Message(form("Table at ROM:0x%X", here));
128 | if (GetTrueName(here) == "" ||
129 | GetTrueName(here) == form("byte_%X", here))
130 | {
131 | MakeNameEx(here, form("Table_%X", here), SN_NOWARN);
132 | }
133 | SetArrayLong(axisInfo, 0, 0);
134 | SetArrayLong(axisInfo, 2, 1);
135 | FormatAxis(here, fAxisType, sAxisType, 1);
136 | if (ync == 1 )
137 | {
138 | FormatAxis(here, fAxisType, sAxisType, 2);
139 | }
140 | FormatData(here, dataType);
141 | }
142 | else if (storageType == 1)
143 | {
144 | Message(form("Series at ROM:0x%X", here));
145 | if (GetTrueName(here) == "" ||
146 | GetTrueName(here) == form("byte_%X", here))
147 | {
148 | MakeNameEx(here, form("Series_%X", here), SN_NOWARN);
149 | }
150 | SetArrayLong(axisInfo, 0, 1);
151 | SetArrayLong(axisInfo, 2, 1);
152 | FormatSeries(here, fAxisType, sAxisType, 1);
153 | if (ync == 1 )
154 | {
155 | FormatSeries(here, fAxisType, sAxisType, 2);
156 | }
157 | FormatData(here, dataType);
158 | }
159 | DeleteArray(axisInfo);
160 | }
161 |
162 | static FormatAxis(currAddr, fAxisType, sAxisType, axisCnt)
163 | {
164 | auto axisInfo, label, axisSize, startAddr, endAddr, axisType, type;
165 | axisInfo = GetArrayId("AXIS_INFO");
166 | label = form("Table_%X_axis%d", currAddr, axisCnt);
167 | if (axisCnt == 1)
168 | {
169 | axisSize = Byte(currAddr - 1) + 1;
170 | MakeByte(currAddr - 1);
171 | startAddr = currAddr - 1 - (fAxisType * axisSize);
172 | endAddr = startAddr + (fAxisType * axisSize);
173 | axisType = fAxisType;
174 | SetArrayLong(axisInfo, 1, axisSize);
175 | }
176 | if (axisCnt == 2)
177 | {
178 | axisSize = Byte(currAddr - 1) + 1;
179 | currAddr = currAddr - 1 - (fAxisType * axisSize);
180 | axisSize = Byte(currAddr - 1) + 1;
181 | MakeByte(currAddr - 1);
182 | startAddr = currAddr - 1 - (sAxisType * axisSize);
183 | endAddr = startAddr + (sAxisType * axisSize);
184 | axisType = sAxisType;
185 | SetArrayLong(axisInfo, 2, axisSize);
186 | }
187 |
188 | if (axisType == 1)
189 | {
190 | type = "uint8";
191 | for (currAddr = startAddr; currAddr < endAddr; currAddr = currAddr + axisType)
192 | {
193 | MakeUnknown(currAddr, axisType, DOUNK_SIMPLE);
194 | MakeByte(currAddr);
195 | }
196 | }
197 | if (axisType == 2)
198 | {
199 | type = "uint16";
200 | for (currAddr = startAddr; currAddr < endAddr; currAddr = currAddr + axisType)
201 | {
202 | MakeUnknown(currAddr, axisType, DOUNK_SIMPLE);
203 | MakeWord(currAddr);
204 | }
205 | }
206 | if (GetTrueName(startAddr) == "")
207 | {
208 | MakeNameEx(startAddr, label, SN_NOWARN);
209 | }
210 | Message(form(", axis-%d %s, size: %d at ROM:0x%X", axisCnt, type, axisSize, startAddr));
211 | }
212 |
213 | static FormatSeries(currAddr, fAxisType, sAxisType, axisCnt)
214 | {
215 | auto axisInfo, label, axisSize, startAddr, endAddr, axisType, type;
216 | axisInfo = GetArrayId("AXIS_INFO");
217 | label = form("Series_%X_axis%d_step", currAddr, axisCnt);
218 | if (axisCnt == 1)
219 | {
220 | axisSize = Byte(currAddr - 1) + 1;
221 | MakeByte(currAddr - 1);
222 | startAddr = currAddr - 1 - (fAxisType * 2);
223 | endAddr = startAddr + (fAxisType * 2);
224 | axisType = fAxisType;
225 | SetArrayLong(axisInfo, 1, axisSize);
226 | }
227 | if (axisCnt == 2)
228 | {
229 | axisSize = Byte(currAddr - 1) + 1;
230 | currAddr = currAddr - 1 - (fAxisType * 2);
231 | axisSize = Byte(currAddr - 1) + 1;
232 | MakeByte(currAddr - 1);
233 | startAddr = currAddr - 1 - (sAxisType * 2);
234 | endAddr = startAddr + (sAxisType * 2);
235 | axisType = sAxisType;
236 | SetArrayLong(axisInfo, 2, axisSize);
237 | }
238 |
239 | if (axisType == 1)
240 | {
241 | type = "uint8";
242 | for (currAddr = startAddr; currAddr < endAddr; currAddr = currAddr + axisType)
243 | {
244 | MakeUnknown(currAddr, axisType, DOUNK_SIMPLE);
245 | MakeByte(currAddr);
246 | }
247 | }
248 | if (axisType == 2)
249 | {
250 | type = "uint16";
251 | for (currAddr = startAddr; currAddr < endAddr; currAddr = currAddr + axisType)
252 | {
253 | MakeUnknown(currAddr, axisType, DOUNK_SIMPLE);
254 | MakeWord(currAddr);
255 | }
256 | }
257 | if (GetTrueName(startAddr) == "")
258 | {
259 | MakeNameEx(startAddr, label, SN_NOWARN);
260 | }
261 | Message(form(", axis-%d %s, size: %d at ROM:0x%X", axisCnt, type, axisSize, startAddr));
262 | }
263 |
264 | static FormatData(currAddr, dataType)
265 | {
266 | auto axisInfo, format, label, fAxisSize, sAxisSize, startAddr, endAddr, type;
267 | axisInfo = GetArrayId("AXIS_INFO");
268 | label = "Table";
269 | format = GetArrayElement(AR_LONG, axisInfo, 0);
270 | if (format == 1)
271 | {
272 | label = "Series";
273 | }
274 | label = form("%s_%X_data", label, currAddr);
275 | fAxisSize = GetArrayElement(AR_LONG, axisInfo, 1);
276 | sAxisSize = GetArrayElement(AR_LONG, axisInfo, 2);
277 | startAddr = currAddr + 1;
278 | endAddr = startAddr + (fAxisSize * sAxisSize * dataType);
279 |
280 | if (dataType == 1)
281 | {
282 | type = "uint8";
283 | for (currAddr = startAddr; currAddr < endAddr; currAddr = currAddr + dataType)
284 | {
285 | MakeUnknown(currAddr, dataType, DOUNK_SIMPLE);
286 | MakeByte(currAddr);
287 | }
288 | }
289 | if (dataType == 2)
290 | {
291 | type = "uint16";
292 | for (currAddr = startAddr; currAddr < endAddr; currAddr = currAddr + dataType)
293 | {
294 | MakeUnknown(currAddr, dataType, DOUNK_SIMPLE);
295 | MakeWord(currAddr);
296 | }
297 | }
298 | SetArrayFormat(startAddr, 0, fAxisSize, 0);
299 | if (sAxisSize > 1)
300 | {
301 | MakeArray(startAddr, (fAxisSize * sAxisSize * dataType));
302 | }
303 | if (GetTrueName(startAddr) == "")
304 | {
305 | MakeNameEx(startAddr, label, SN_NOWARN);
306 | }
307 | Message(form(", data %s at ROM:0x%X\n", type, startAddr));
308 | }
--------------------------------------------------------------------------------
/src/Definitions/update_logger.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | #
3 | # Copyright (C) 2014 Dale C. Schultz
4 | # RomRaider member ID: dschultz
5 | #
6 | # You are free to use this source for any purpose, but please keep
7 | # notice of where it came from!
8 | #
9 | #
10 | # Purpose
11 | # Reads from IDC dump file to update MySQL Logger definitions tables.
12 | # Version: 8
13 | # Update: Feb. 06/2014
14 | #------------------------------------------------------------------------------------------
15 |
16 | use File::Basename;
17 | unless ($ARGV[0])
18 | {
19 | print "Input file missing...\n";
20 | print "Usage: logger_update.pl \n";
21 | exit 1;
22 | }
23 | $param_file = $ARGV[0];
24 | if ($ARGV[1] eq "-commit") {$commit = 1};
25 |
26 | # get the list of stat files
27 | open (INPUT, "$param_file") || die "Could not open file $param_file : $!\n";
28 | $param_file = basename($param_file);
29 | $param_file =~ s/\.txt//;
30 | $ecuid = uc($param_file);
31 | use DBI;
32 |
33 | # create a handle and connect to the statistics database
34 | $dbh = DBI->connect (
35 | 'DBI:mysql:database=definitions;host=localhost',
36 | 'xxxx','xxxx',{AutoCommit=>1, RaiseError=>0, PrintError=>0})
37 | or die "$0: Couldn't connect to database";
38 |
39 | &get_db_version;
40 | &get_ecuparam_id;
41 | $add_ecuid = 0;
42 | $add_addr = 0;
43 | $change_addr = 0;
44 | $add_entry = 0;
45 |
46 | print "Current Database Version: $db_id ($db_version)\n";
47 | #check if we have the ECU ID already
48 | $ecuid_serial = get_ecu_id($ecuid);
49 | if ($ecuid_serial)
50 | {
51 | print "ECU ID $ecuid ($ecuid_serial) exists.\n";
52 | $update = "Updated ECU ID: $ecuid extended parameters \n";
53 | }
54 | else
55 | {
56 | print "ECU ID $ecuid is not defined.\n";
57 | if ($commit)
58 | {
59 | $ecuid_serial = new_ecuid_entry($ecuid);
60 | $update = "Added ECU ID: $ecuid to extended parameters\n";
61 | print "+ COMMIT: ECU ID $ecuid ($ecuid_serial) added.\n\n";
62 | }
63 | else
64 | {
65 | print "+ TEST: ECU ID $ecuid will be added.\n\n";
66 | }
67 | $add_ecuid++;
68 | }
69 | $count = 0;
70 | $count1 = 0;
71 | foreach $line ()
72 | {
73 | $bit = '';
74 | $count++;
75 | if ($line =~ /^\#/)
76 | {
77 | $count--;
78 | next;
79 | }
80 | @values = split(/\s+/, $line); # line format expected: Extended Paramter ID RAM Address [ bit]
81 | if ($#values > 2) # line contains two or three values
82 | {
83 | print "WARNING: Line $count invalid number of parameters, line skipped.\n";
84 | $warn++;
85 | next;
86 | }
87 | @extname = split(/_/, $values[0]); # split first argument to extract the ID from the last element
88 | $extid = $extname[$#extname]; # get last element
89 | $extid =~ s/^E//; # clean last element up so we have digits only
90 | if (length($values[1]) > 6)
91 | {
92 | $values[1] =~ s/.*(\w{6,6}$)/\1/; # make the address six bytes long
93 | }
94 | $addr = $values[1];
95 | if ($#values == 2) # line contains three values, get bit
96 | {
97 | $bit = $values[2];
98 | }
99 | # check if we have the Extended Parameter id already
100 | if (!$ecuparam_id{$extid})
101 | {
102 | print "WARNING: Extended parameter $extid is not a known ID.\n";
103 | $warn++;
104 | next;
105 | }
106 |
107 | # default length of data expected for this Extended Parameter id
108 | $deft_len = $ecuparam_len{$ecuparam_id{$extid}};
109 |
110 | # check that the bit value is appropriate for the length
111 | $address_id = '';
112 | if (($deft_len == 1 && $bit >= 0 && $bit <= 7 ) ||
113 | ($deft_len == 2 && $bit >= 0 && $bit <= 15) ||
114 | ($deft_len == 4 && $bit >= 0 && $bit <= 31))
115 | {
116 | $address_id = get_address_id($addr, $deft_len, $bit);
117 | }
118 | else
119 | {
120 | print "WARNING: Incompatible bit value passed for parameter address length, length:$deft_len, bit:$bit\n";
121 | $warn++;
122 | }
123 |
124 | # check if we have the RAM address/length/bit id already
125 | $address_id = get_address_id($addr, $deft_len, $bit);
126 | if ($address_id)
127 | {
128 | print "Address $addr/$deft_len/$bit ($address_id) exists.\n\n";
129 | }
130 | else
131 | {
132 | print "Address $addr/$deft_len/$bit is not defined.\n";
133 | if ($commit)
134 | {
135 | $address_id = new_addr_entry($addr, $deft_len, $bit);
136 | print "+ COMMIT: Address $addr/$deft_len/$bit ($address_id) added.\n\n";
137 | }
138 | else
139 | {
140 | print "+ TEST: Address $addr/$deft_len/$bit will be added.\n\n";
141 | }
142 | $add_addr++;
143 | }
144 | # check to see if the parameter entry exists and if the address_id matches or not.
145 | # If they don't match then UPDATE rather than INSERT the entry
146 | ($param_rel_id, $address_serial) = get_relation_id($ecuid_serial, $ecuparam_id{$extid});
147 | if ($param_rel_id)
148 | {
149 | if ($address_serial == $address_id)
150 | {
151 | print "E${extid} - Parameter combination Address entry matches ($address_serial), no change.\n\n";
152 | }
153 | else
154 | {
155 | if ($commit)
156 | {
157 | update_unique_entry($param_rel_id, $address_id);
158 | print "~ COMMIT: E${extid} - Parameter combination Address entry ($address_serial) ";
159 | print "changed to $address_id.\n\n";
160 | $update = $update."Changed address/length/bit entry for ECU ID $ecuid for extended parameter E${extid}\n";
161 | }
162 | else
163 | {
164 | print "* TEST: E${extid} - Parameter combination Address entry ($address_serial) ";
165 | if ($address_id)
166 | {
167 | print "will change to $address_id.\n\n";
168 | }
169 | else
170 | {
171 | print "will be updated.\n\n";
172 | }
173 | }
174 | $change_addr++;
175 | }
176 | }
177 | else
178 | {
179 | print "E${extid} - Parameter combination is not defined.\n";
180 | if ($commit)
181 | {
182 | $param_rel_id = new_unique_entry($ecuid_serial, $ecuparam_id{$extid}, $address_id);
183 | print "+ COMMIT: E${extid} - unique entry ($param_rel_id) added.\n\n";
184 | }
185 | else
186 | {
187 | print "+ TEST: E${extid} - will be added.\n\n";
188 | }
189 | $add_entry++;
190 | }
191 | $count1++;
192 | }
193 | print "$count1 of $count lines evaluated.\n";
194 | if ($warn)
195 | {
196 | print "$warn WARNING(S)\n";
197 | }
198 | if ($commit)
199 | {
200 | &update_version;
201 | &get_db_version;
202 | print "COMMIT: New Database version is $db_id ($db_version)\n";
203 | print "Changes:\n$update\n";
204 | }
205 | elsif ($warn)
206 | {
207 | print "!--> Correct input file and test again <--!\n";
208 | }
209 | else
210 | {
211 | print "TEST complete, run with commit to add entries to database.\n";
212 | }
213 | print "Summary:\n";
214 | print "\tECU ID added: $add_ecuid\n" if ($add_ecuid);
215 | print "\tAddresses added: $add_addr\n" if ($add_addr);
216 | print "\tParameter Combo Addresses changed: $change_addr\n" if ($change_addr);
217 | print "\tEntries added: $add_entry\n" if ($add_entry);
218 | print "\tNo changes\n" if (!$add_ecuid && !$add_addr && !$change_addr && !$add_entry);
219 |
220 | THE_END:
221 | $dbh->do("FLUSH TABLES");
222 | $dbh->disconnect;
223 | exit;
224 |
225 | # --- SUBROIUTINES ---
226 |
227 | sub get_db_version {
228 | # get database version
229 | my $id, $version;
230 |
231 | my $sql = qq(SELECT id, version FROM version ORDER BY id DESC LIMIT 1);
232 | my $sth = $dbh->prepare($sql);
233 | $sth->execute;
234 | $sth->bind_columns(\$id, \$version);
235 | while ($sth->fetch) {
236 | $db_id=$id;
237 | $db_version=$version;
238 | }
239 | }
240 |
241 | sub get_ecuparam_id {
242 | # create an array for all of the extended parameters
243 | my $serial, $id, $length;
244 |
245 | my $sql = qq(SELECT serial, id, length FROM ecuparam);
246 | my $sth = $dbh->prepare($sql);
247 | $sth->execute;
248 | $sth->bind_columns(\$serial, \$id, \$length);
249 | while ($sth->fetch) {
250 | $ecuparam_id{$id}=$serial;
251 | $ecuparam_len{$serial}=$length;
252 | }
253 | }
254 |
255 | sub get_address_id {
256 | # return the id of the passed address/length/bit
257 | my $serial;
258 | my $address = shift;
259 | my $length = shift;
260 | my $bit = shift;
261 |
262 | if ($bit eq '')
263 | {
264 | $bit = " IS NULL";
265 | }
266 | elsif ($bit >= 0 && $bit <= 31)
267 | {
268 | $bit = "='" . $bit . "'";
269 | }
270 | else
271 | {
272 | report_error("Invalid address bit value passed, value:$bit");
273 | }
274 | my $sql = qq[SELECT serial FROM address where address='$address' and length='$length' and bit$bit];
275 | my $sth = $dbh->prepare($sql);
276 | $sth->execute;
277 | $sth->bind_columns(\$serial);
278 | my $count = 0;
279 | while ($sth->fetch) {
280 | $count++;
281 | }
282 | report_error("More than one address/length/bit combo found in database") if ($count > 1);
283 | return $serial;
284 | }
285 |
286 | sub get_ecu_id {
287 | # get serial number for the ECU ID
288 | my $ecuid = shift;
289 | my $serial;
290 |
291 | my $sql = qq(SELECT serial FROM ecuid where ecuid='$ecuid');
292 | my $sth = $dbh->prepare($sql);
293 | $sth->execute;
294 | $sth->bind_columns(\$serial);
295 | my $count = 0;
296 | while ($sth->fetch) {
297 | $count++;
298 | }
299 | report_error("More than one ECU ID found in database") if ($count > 1);
300 | return $serial;
301 | }
302 |
303 | sub get_relation_id {
304 | # get the serial number for the ECU ID, Extended Parameter, Address combo
305 | my $ecuid_id = shift;
306 | my $param_id = shift;
307 | my $serial, $address_serial;
308 |
309 | my $sql = qq[SELECT serial,addressid from ecuparam_rel
310 | WHERE ecuparamid='$param_id'
311 | AND ecuidid='$ecuid_id'];
312 | my $sth = $dbh->prepare($sql);
313 | $sth->execute;
314 | $sth->bind_columns(\$serial, \$address_serial);
315 | my $count = 0;
316 | while ($sth->fetch) {
317 | $count++;
318 | }
319 | report_error("More than one ECU ID/Parameter/Address combo found in database") if ($count > 1);
320 | return ($serial, $address_serial);
321 | }
322 |
323 | sub update_unique_entry {
324 | # Update Address ID entry for an exisitng parameter
325 | my $serial = shift;
326 | my $addr_id = shift;
327 |
328 | my $sql = qq[UPDATE ecuparam_rel SET addressid = '$addr_id' WHERE serial = '$serial'];
329 | my $sth = $dbh->prepare($sql);
330 | $sth->execute;
331 | }
332 |
333 | sub update_version {
334 | # update version of database
335 | # vserion = YYYYMMDD_hhmmss
336 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
337 | $year += 1900;
338 | $version = sprintf("%04d%02d%02d_%02d%02d%02d", $year, ++$mon, $mday, $hour, $min, $sec);
339 | $update =~ s/\n$//;
340 | my $sql_version_in = qq[INSERT INTO `version` (`version`, `update`) VALUES ('$version', '$update')];
341 | my $sth = $dbh->prepare($sql_version_in);
342 | $sth->execute;
343 | }
344 |
345 | sub new_ecuid_entry {
346 | # create a new entry in the database for the current ECU ID as we have
347 | # not seen it before.
348 |
349 | my $ecuid = shift; # ECU ID pasted to subroutine
350 |
351 | my $sql_ecuid_in = qq[INSERT INTO ecuid (ecuid) VALUES ('$ecuid')];
352 | my $sth = $dbh->prepare($sql_ecuid_in);
353 | $sth->execute;
354 | return $sth->{mysql_insertid};
355 | }
356 |
357 | sub new_addr_entry {
358 | # create a new entry in the database for the current address as we have
359 | # not seen it before.
360 |
361 | my $address = shift; # RAM address pasted to subroutine
362 | my $addr_len = shift; # length of data to retrieve at address pasted to subroutine
363 | my $addr_bit = shift; # bit to isolate at address pasted to subroutine
364 |
365 | if ($addr_bit eq '')
366 | {
367 | $addr_bit = "NULL";
368 | }
369 | elsif ($addr_bit >= 0 && $addr_bit <= 31)
370 | {
371 | $addr_bit = "'$addr_bit'";
372 | }
373 | else
374 | {
375 | report_error("Invalid address bit value passed, value:$addr_bit");
376 | }
377 |
378 | my $sql_addr_in = qq[INSERT INTO address (address,length,bit) VALUES ('$address','$addr_len',$addr_bit)];
379 | my $sth = $dbh->prepare($sql_addr_in);
380 | $sth->execute;
381 | return $sth->{mysql_insertid};
382 | }
383 |
384 | sub new_unique_entry {
385 | # create a new entry in the database for the current Extended Parameter as we have
386 | # not seen it before.
387 |
388 | my $ecuid_id = shift; # ECU ID pasted to subroutine
389 | my $extparamid_id = shift; # Extended parameter pasted to subroutine
390 | my $address_id = shift; # RAM address pasted to subroutine
391 | my $serial = shift;
392 |
393 | # now we can insert the new Extended Parameter relation info into the table
394 | my $sql_ecuparamrel_in = qq[INSERT INTO
395 | ecuparam_rel (ecuparamid, ecuidid, addressid)
396 | VALUES ('$extparamid_id', '$ecuid_id', '$address_id')];
397 | my $sth = $dbh->prepare($sql_ecuparamrel_in);
398 | $sth->execute;
399 | return $sth->{mysql_insertid};
400 | }
401 |
402 | sub report_error {
403 | my $message = shift;
404 | print "ERROR: $message\n";
405 | $dbh->do("FLUSH TABLES");
406 | $dbh->disconnect;
407 | exit;
408 | }
409 |
--------------------------------------------------------------------------------
/src/MakeXmlDef/MakeXmlDef/MakeXmlDef.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Dale C. Schultz
3 | * RomRaider member ID: dschultz
4 | *
5 | * You are free to use this source for any purpose, but please keep
6 | * notice of where it came from!
7 | */
8 | using System;
9 | using System.IO;
10 | using System.Collections;
11 | using System.Collections.Generic;
12 | using System.Linq;
13 | using System.Text;
14 | using System.Xml;
15 | using System.Xml.XPath;
16 | using System.Text.RegularExpressions;
17 |
18 | namespace MakeXmlDef
19 | {
20 | class MakeXmlDef
21 | {
22 | private static Hashtable addrTable = new Hashtable();
23 | private static Hashtable sizexTable = new Hashtable();
24 | private static Hashtable sizeyTable = new Hashtable();
25 | private static HashSet names = new HashSet();
26 |
27 | static void Main(string[] args)
28 | {
29 | if (args.Length == 0)
30 | {
31 | Usage();
32 | return;
33 | }
34 |
35 | // read the address file into a hash table for key lookups on table/axis name
36 | string line;
37 | try
38 | {
39 | StreamReader file = new StreamReader(args[1]);
40 | string pattern = @"\s+";
41 | while ((line = file.ReadLine()) != null)
42 | {
43 | string[] result = Regex.Split(line, pattern);
44 | if (result.Length == 4 && !addrTable.Contains(result[0])) // 3D Table with X & Y size
45 | {
46 | addrTable.Add(result[0], result[1]);
47 | sizexTable.Add(result[0], result[2]);
48 | sizeyTable.Add(result[0], result[3]);
49 | }
50 | if (result.Length == 3 && !addrTable.Contains(result[0])) // 2D Table with Y size
51 | {
52 | addrTable.Add(result[0], result[1]);
53 | sizeyTable.Add(result[0], result[2]);
54 | }
55 | if (result.Length == 2 && !addrTable.Contains(result[0])) // 1D Table no size
56 | {
57 | addrTable.Add(result[0], result[1]);
58 | }
59 | }
60 | file.Close();
61 | }
62 | catch (Exception e)
63 | {
64 | Console.WriteLine("Could not read address file. " + e);
65 | return;
66 | }
67 | if (addrTable.Count == 0)
68 | {
69 | Console.WriteLine("The address file " + args[1] + "contained no valid entries.");
70 | return;
71 | }
72 |
73 | XmlDocument doc = new XmlDocument();
74 | try
75 | {
76 | doc.Load(args[0]);
77 | }
78 | catch (Exception e)
79 | {
80 | Console.WriteLine("Could not read template file. " + e);
81 | return;
82 | }
83 |
84 | string path = "/roms/rom/table";
85 | XmlNodeList nodeList = doc.SelectNodes(path); // all table Nodes of the template file
86 | Console.WriteLine("Table size change summary (changes over base):");
87 |
88 | foreach (XmlNode node in nodeList)
89 | {
90 | if ((node.NodeType == XmlNodeType.Element) && node.Name == "table")
91 | {
92 | XmlAttributeCollection attrList = node.Attributes; // attributes of current table element
93 | string name = attrList["name"].Value; // table name which will be "cleaned" to match IDA names
94 | string rawName = name; // table name from table element
95 | name = ConvertName(name); // convert the name to match IDA names
96 | string storageAddress = "undef";
97 | if (addrTable.Contains(name) && attrList["storageaddress"] != null)
98 | {
99 | storageAddress = addrTable[name].ToString();
100 | attrList["storageaddress"].Value = Convert.ToInt32(storageAddress , 16).ToString("X");
101 | //Console.WriteLine(name + " = " + attrList["storageaddress"].Value);
102 |
103 | string path1 = "/roms/rom/table[@name='" + rawName + "']";
104 | XmlNodeList tableList = doc.SelectNodes(path1); // all table nodes of template file that match this rawName
105 | //Console.WriteLine("Search for: " + path1 + " found: " + tableList.Count);
106 | foreach (XmlNode tableNode in tableList)
107 | {
108 | if ((tableNode.NodeType == XmlNodeType.Element) && tableNode.Name == "table")
109 | {
110 | string status = "Updated";
111 | XmlAttributeCollection tableAttrList = tableNode.Attributes;
112 | if (tableAttrList["storageaddress"] == null && // this is the entry in the 32BITBASE rom section
113 | tableAttrList["sizex"] != null &&
114 | sizexTable.Contains(name)
115 | )
116 | {
117 | // Is the default X size different than the IDA table X size
118 | if (tableAttrList["sizex"].Value != sizexTable[name].ToString()) // yes
119 | {
120 | // Is there an X size attribute in our template
121 | if (attrList["sizex"] == null) // no
122 | {
123 | XmlAttribute newAttr = doc.CreateAttribute("sizex");
124 | newAttr.Value = sizexTable[name].ToString();
125 | node.Attributes.Append(newAttr);
126 | status = "Added ";
127 | }
128 | else // yes
129 | {
130 | attrList["sizex"].Value = sizexTable[name].ToString();
131 | }
132 | Console.WriteLine(
133 | string.Format("{3} X size: {0,2} -> {1,2} Table Name: '{2}'", tableAttrList["sizex"].Value, sizexTable[name].ToString(), tableAttrList["name"].Value, status)
134 | );
135 | }
136 | else // no
137 | {
138 | // Is there an X size attribute in our template
139 | if (attrList["sizex"] != null) // yes
140 | {
141 | // remove the unneeded attribute
142 | status = "Removed";
143 | Console.WriteLine(
144 | string.Format("{2} X size: {1,2} from Table Name: '{0}'", tableAttrList["name"].Value, attrList["sizex"].Value, status)
145 | );
146 | node.Attributes.Remove(attrList["sizex"]);
147 | }
148 | }
149 | }
150 | // Is the default Y size different than the IDA table Y size
151 | if (tableAttrList["storageaddress"] == null &&
152 | tableAttrList["sizey"] != null &&
153 | sizeyTable.Contains(name)
154 | )
155 | {
156 | if (tableAttrList["sizey"].Value != sizeyTable[name].ToString())
157 | {
158 | if (attrList["sizey"] == null)
159 | {
160 | XmlAttribute newAttr = doc.CreateAttribute("sizey");
161 | newAttr.Value = sizeyTable[name].ToString();
162 | node.Attributes.Append(newAttr);
163 | status = "Added ";
164 | }
165 | else
166 | {
167 | attrList["sizey"].Value = sizeyTable[name].ToString();
168 | }
169 | Console.WriteLine(
170 | string.Format("{3} Y size: {0,2} -> {1,2} Table Name: '{2}'", tableAttrList["sizey"].Value, sizeyTable[name].ToString(), tableAttrList["name"].Value, status)
171 | );
172 | }
173 | else
174 | {
175 | // Is there an Y size attribute in our template
176 | if (attrList["sizey"] != null) // yes
177 | {
178 | // remove the unneeded attribute
179 | status = "Removed";
180 | Console.WriteLine(
181 | string.Format("{2} Y size: {1,2} from Table Name: '{0}'", tableAttrList["name"].Value, attrList["sizey"].Value, status)
182 | );
183 | node.Attributes.Remove(attrList["sizey"]);
184 | }
185 | }
186 | }
187 | }
188 | }
189 | if (node.HasChildNodes) // thesee are the axis entries for the current table element
190 | {
191 | XmlNodeList childNodes = node.ChildNodes;
192 | foreach (XmlNode child in childNodes)
193 | {
194 | if ((child.NodeType == XmlNodeType.Element) && child.Name == "table")
195 | {
196 | XmlAttributeCollection cattrList = child.Attributes;
197 | string axis = cattrList["type"].Value;
198 | axis = ConvertName(name + "_" + axis);
199 | if (addrTable.Contains(axis))
200 | {
201 | cattrList["storageaddress"].Value = Convert.ToInt32(addrTable[axis].ToString() , 16).ToString("X");
202 | }
203 | //Console.WriteLine(axis + " = " + cattrList["storageaddress"].Value);
204 | }
205 | }
206 | }
207 | }
208 | }
209 | }
210 | try
211 | {
212 | doc.Save(args[2]);
213 | }
214 | catch (Exception e)
215 | {
216 | Console.WriteLine("Could not write output file. " + e);
217 | return;
218 | }
219 | }
220 |
221 | private static string ConvertName(string original)
222 | {
223 | original = original.Replace(")(", "_");
224 |
225 | StringBuilder builder = new StringBuilder(original.Length);
226 | foreach (char c in original)
227 | {
228 | if (char.IsLetterOrDigit(c))
229 | {
230 | builder.Append(c);
231 | continue;
232 | }
233 |
234 | if (c == '_')
235 | {
236 | builder.Append(c);
237 | continue;
238 | }
239 |
240 | if (char.IsWhiteSpace(c))
241 | {
242 | builder.Append('_');
243 | continue;
244 | }
245 |
246 | if (c == '*')
247 | {
248 | builder.Append("Ext");
249 | continue;
250 | }
251 | }
252 |
253 | // Make sure the name is unique
254 | string name = builder.ToString();
255 | while (names.Contains(name))
256 | {
257 | name = name + "_";
258 | }
259 | names.Add(name);
260 |
261 | return name;
262 | }
263 |
264 | private static void Usage()
265 | {
266 | Console.WriteLine("MakeXmlDef Usage:");
267 | Console.WriteLine("MakeXmlDef.exe ");
268 | Console.WriteLine();
269 | Console.WriteLine("Where is an XML file that will be used as a template to modify.");
270 | Console.WriteLine(" is a text file containing Table names and Addresses from");
271 | Console.WriteLine(" the IDA Names Window.");
272 | Console.WriteLine(" is the file to save the output to.");
273 | }
274 | }
275 | }
276 |
--------------------------------------------------------------------------------
/src/Definitions/UpdateLoggerFromXmlForEcuId.php:
--------------------------------------------------------------------------------
1 | alert('" . $message . "\\nTerminating script.')