10
10
#include < QDirIterator>
11
11
#include " hobbitspython.h"
12
12
13
-
14
13
KaitaiStruct::KaitaiStruct ()
15
14
{
16
15
QList<ParameterDelegate::ParameterInfo> infos = {
17
- {" katai_struct_yaml " , QJsonValue::String, true },
18
- {" precompiled_py_file " , QJsonValue::String, true }
16
+ {PARAM_KSY , QJsonValue::String, true },
17
+ {PARAM_PY , QJsonValue::String, true }
19
18
};
20
19
21
20
m_delegate = QSharedPointer<ParameterDelegateUi>(
@@ -90,8 +89,10 @@ QSharedPointer<const AnalyzerResult> KaitaiStruct::analyzeBits(
90
89
91
90
progress->setProgressPercent (10 );
92
91
93
- if (parameters.contains (" kaitai_struct_yaml" )
94
- && !parameters.value (" kaitai_struct_yaml" ).toString ().isEmpty ()) {
92
+ QString kscOutput = " " ;
93
+
94
+ if (parameters.contains (PARAM_KSY)
95
+ && !parameters.value (PARAM_KSY).toString ().isEmpty ()) {
95
96
QString kscPath = SettingsManager::getPrivateSetting (KAITAI_PATH_KEY).toString ();
96
97
if (kscPath.isEmpty ()) {
97
98
return AnalyzerResult::error (" A Kaitai Struct Compiler path must be specified" );
@@ -104,7 +105,7 @@ QSharedPointer<const AnalyzerResult> KaitaiStruct::analyzeBits(
104
105
if (!ksy.open (QIODevice::Truncate | QIODevice::WriteOnly)) {
105
106
return AnalyzerResult::error (" Could not open ksy file for writing" );
106
107
}
107
- ksy.write (parameters.value (" katai_struct_yaml " ).toString ().toLocal8Bit ());
108
+ ksy.write (parameters.value (PARAM_KSY ).toString ().toLocal8Bit ());
108
109
ksy.close ();
109
110
110
111
progress->setProgressPercent (20 );
@@ -135,21 +136,23 @@ QSharedPointer<const AnalyzerResult> KaitaiStruct::analyzeBits(
135
136
if (errorFile.open (QIODevice::ReadOnly)) {
136
137
errorOutput = errorFile.readAll ();
137
138
errorFile.close ();
139
+ kscOutput += QString (" stderr:\n %2" ).arg (errorOutput);
138
140
}
139
141
140
142
if (stdoutFile.open (QIODevice::ReadOnly)) {
141
143
stdOutput = stdoutFile.readAll ();
142
144
stdoutFile.close ();
145
+ kscOutput += QString (" stdout:\n %2" ).arg (stdOutput);
143
146
}
144
147
145
148
if (!errorOutput.isEmpty ()) {
146
- return AnalyzerResult::error (QString (" kaitai-struct-compiler error:\n %1\n\n stdout: %2 " ).arg (errorOutput). arg (stdOutput ));
149
+ return AnalyzerResult::error (QString (" kaitai-struct-compiler error:\n %1" ).arg (kscOutput ));
147
150
}
148
151
149
152
}
150
- else if (parameters.contains (" precompiled_py_file " )
151
- && !parameters.value (" precompiled_py_file " ).toString ().isEmpty ()) {
152
- QString precompiledFilePath = parameters.value (" precompiled_py_file " ).toString ();
153
+ else if (parameters.contains (PARAM_PY )
154
+ && !parameters.value (PARAM_PY ).toString ().isEmpty ()) {
155
+ QString precompiledFilePath = parameters.value (PARAM_PY ).toString ();
153
156
QFileInfo info (precompiledFilePath);
154
157
QFile::copy (precompiledFilePath, dir.filePath (info.fileName ()));
155
158
}
@@ -249,6 +252,13 @@ QSharedPointer<const AnalyzerResult> KaitaiStruct::analyzeBits(
249
252
QSharedPointer<BitInfo> bitInfo = BitInfo::copyFromContainer (container);
250
253
bitInfo->addHighlights (highlights);
251
254
255
+ if (!kscOutput.isEmpty ()) {
256
+ bitInfo->setMetadata (KSC_OUT_LABEL, kscOutput);
257
+ }
258
+ if (!output.isEmpty ()) {
259
+ bitInfo->setMetadata (PYTHON_OUT_LABEL, output);
260
+ }
261
+
252
262
return AnalyzerResult::result (bitInfo, parameters);
253
263
}
254
264
0 commit comments