2019-10-06 02:51:34 +00:00
|
|
|
|
// Copyright 2019 faddenSoft. All Rights Reserved.
|
|
|
|
|
// See the LICENSE.txt file for distribution terms (Apache 2.0).
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using PluginCommon;
|
|
|
|
|
|
|
|
|
|
namespace RuntimeData.Test2022 {
|
2019-10-14 01:19:28 +00:00
|
|
|
|
public class Test2022A : MarshalByRefObject, IPlugin, IPlugin_SymbolList,
|
|
|
|
|
IPlugin_InlineJsr, IPlugin_InlineJsl {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
private IApplication mAppRef;
|
|
|
|
|
private byte[] mFileData;
|
|
|
|
|
|
|
|
|
|
private int mInline8StringAddr; // jsr
|
|
|
|
|
private int mInlineRev8StringAddr; // jsr
|
|
|
|
|
private int mInlineNullStringAddr; // jsr
|
|
|
|
|
private int mInlineL1StringAddr; // jsl
|
|
|
|
|
private int mInlineL2StringAddr; // jsl
|
|
|
|
|
private int mInlineDciStringAddr; // jsl
|
|
|
|
|
|
|
|
|
|
public string Identifier {
|
|
|
|
|
get {
|
2019-10-07 21:21:26 +00:00
|
|
|
|
return "Test 2022-extension-scripts A";
|
2019-10-06 02:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 01:19:28 +00:00
|
|
|
|
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans) {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
mAppRef = appRef;
|
|
|
|
|
mFileData = fileData;
|
|
|
|
|
|
2019-10-07 21:21:26 +00:00
|
|
|
|
mAppRef.DebugLog("Test2022-A(id=" + AppDomain.CurrentDomain.Id + "): prepare()");
|
2019-10-14 01:19:28 +00:00
|
|
|
|
}
|
2019-12-01 01:52:33 +00:00
|
|
|
|
|
|
|
|
|
public void Unprepare() {
|
|
|
|
|
mAppRef = null;
|
|
|
|
|
mFileData = null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 01:19:28 +00:00
|
|
|
|
public void UpdateSymbolList(List<PlSymbol> plSyms) {
|
2019-10-07 01:13:39 +00:00
|
|
|
|
foreach (PlSymbol sym in plSyms) {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
switch (sym.Label) {
|
|
|
|
|
case "PrintInline8String":
|
|
|
|
|
mInline8StringAddr = sym.Value;
|
|
|
|
|
break;
|
|
|
|
|
case "PrintInlineRev8String":
|
|
|
|
|
mInlineRev8StringAddr = sym.Value;
|
|
|
|
|
break;
|
|
|
|
|
case "PrintInlineNullString":
|
|
|
|
|
mInlineNullStringAddr = sym.Value;
|
|
|
|
|
break;
|
|
|
|
|
case "PrintInlineL1String":
|
|
|
|
|
mInlineL1StringAddr = sym.Value;
|
|
|
|
|
break;
|
|
|
|
|
case "PrintInlineL2String":
|
|
|
|
|
mInlineL2StringAddr = sym.Value;
|
|
|
|
|
break;
|
|
|
|
|
case "PrintInlineDciString":
|
|
|
|
|
mInlineDciStringAddr = sym.Value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 01:19:28 +00:00
|
|
|
|
public bool IsLabelSignificant(string beforeLabel, string afterLabel) {
|
|
|
|
|
const string PREFIX = "PrintInline"; // all interesting labels start with this
|
|
|
|
|
return (beforeLabel.StartsWith(PREFIX) || afterLabel.StartsWith(PREFIX));
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 20:15:25 +00:00
|
|
|
|
public void CheckJsr(int offset, int operand, out bool noContinue) {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
noContinue = false;
|
2019-10-17 20:15:25 +00:00
|
|
|
|
if (operand == mInline8StringAddr) {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
if (offset + 3 + 8 > mFileData.Length) {
|
|
|
|
|
mAppRef.DebugLog("8string ran off end at +" +
|
|
|
|
|
(offset + 3).ToString("x6"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mAppRef.SetInlineDataFormat(offset + 3, 8,
|
|
|
|
|
DataType.StringGeneric, DataSubType.Ascii, null);
|
2019-10-17 20:15:25 +00:00
|
|
|
|
} else if (operand == mInlineRev8StringAddr) {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
if (offset + 3 + 8 > mFileData.Length) {
|
|
|
|
|
mAppRef.DebugLog("rev8string ran off end at +" +
|
|
|
|
|
(offset + 3).ToString("x6"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mAppRef.SetInlineDataFormat(offset + 3, 8,
|
|
|
|
|
DataType.StringReverse, DataSubType.Ascii, null);
|
2019-10-17 20:15:25 +00:00
|
|
|
|
} else if (operand == mInlineNullStringAddr) {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
// look for the terminating null byte
|
|
|
|
|
int nullOff = offset + 3;
|
|
|
|
|
while (nullOff < mFileData.Length) {
|
|
|
|
|
if (mFileData[nullOff] == 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
nullOff++;
|
|
|
|
|
}
|
|
|
|
|
if (nullOff == mFileData.Length) {
|
|
|
|
|
mAppRef.DebugLog("Unable to find end of null-terminated string at +" +
|
|
|
|
|
(offset+3).ToString("x6"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mAppRef.SetInlineDataFormat(offset + 3, nullOff - (offset + 3) + 1,
|
|
|
|
|
DataType.StringNullTerm, DataSubType.Ascii, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 20:15:25 +00:00
|
|
|
|
public void CheckJsl(int offset, int operand, out bool noContinue) {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
noContinue = false;
|
2019-10-17 20:15:25 +00:00
|
|
|
|
if (operand == mInlineL1StringAddr) {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
// 0 1 2 3 4 5
|
|
|
|
|
// 22 00 10 01 01 66
|
2019-10-14 01:19:28 +00:00
|
|
|
|
if (offset + 4 >= mFileData.Length) {
|
|
|
|
|
return; // length byte is off end
|
|
|
|
|
}
|
2019-10-06 02:51:34 +00:00
|
|
|
|
int len = mFileData[offset + 4]; // 1-byte len in first byte past 4-byte JSL
|
|
|
|
|
if (offset + 5 + len > mFileData.Length) {
|
|
|
|
|
// ran off the end
|
|
|
|
|
mAppRef.DebugLog("L1 string ran off end of file at +" +
|
|
|
|
|
(offset + 4).ToString("x6"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mAppRef.SetInlineDataFormat(offset + 4, len + 1,
|
|
|
|
|
DataType.StringL8, DataSubType.Ascii, null);
|
2019-10-17 20:15:25 +00:00
|
|
|
|
} else if (operand == mInlineL2StringAddr) {
|
2019-10-14 01:19:28 +00:00
|
|
|
|
if (offset + 5 >= mFileData.Length) {
|
|
|
|
|
return; // length word is off end
|
|
|
|
|
}
|
2019-10-06 02:51:34 +00:00
|
|
|
|
int len = Util.GetWord(mFileData, offset + 4, 2, false);
|
|
|
|
|
if (offset + 6 + len > mFileData.Length) {
|
|
|
|
|
// ran off the end
|
|
|
|
|
mAppRef.DebugLog("L2 string ran off end of file at +" +
|
|
|
|
|
(offset+4).ToString("x6"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mAppRef.SetInlineDataFormat(offset + 4, len + 2,
|
|
|
|
|
DataType.StringL16, DataSubType.Ascii, null);
|
2019-10-17 20:15:25 +00:00
|
|
|
|
} else if (operand == mInlineDciStringAddr) {
|
2019-10-06 02:51:34 +00:00
|
|
|
|
// look for the first byte whose high bit doesn't match the first byte's bit
|
|
|
|
|
// 0 1 2 3 4 5
|
|
|
|
|
// 22 00 30 01 66 c1
|
|
|
|
|
if (offset + 3 + 2 >= mFileData.Length) {
|
|
|
|
|
// need at least two bytes
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
byte firstBit = (byte) (mFileData[offset + 4] & 0x80);
|
|
|
|
|
int endOff = offset + 5;
|
|
|
|
|
while (endOff < mFileData.Length) {
|
|
|
|
|
if ((mFileData[endOff] & 0x80) != firstBit) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
endOff++;
|
|
|
|
|
}
|
|
|
|
|
if (endOff == mFileData.Length) {
|
|
|
|
|
mAppRef.DebugLog("Unable to find end of DCI string at +" +
|
|
|
|
|
(offset+4).ToString("x6"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mAppRef.SetInlineDataFormat(offset + 4, endOff - (offset + 4) + 1,
|
|
|
|
|
DataType.StringDci, DataSubType.Ascii, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|