29
29
import com .google .gson .JsonObject ;
30
30
import com .google .gson .stream .JsonWriter ;
31
31
32
+ import ghidra .program .database .data .DataTypeUtilities ;
32
33
import ghidra .program .database .data .ProgramDataTypeManager ;
33
34
import ghidra .program .model .address .Address ;
34
35
import ghidra .program .model .address .AddressFormatException ;
@@ -96,7 +97,8 @@ public class IsfDataTypeWriter extends AbstractIsfWriter {
96
97
* @param baseWriter the writer to use when writing data types
97
98
* @throws IOException if there is an exception writing the output
98
99
*/
99
- public IsfDataTypeWriter (DataTypeManager dtm , List <DataType > target , Writer baseWriter ) throws IOException {
100
+ public IsfDataTypeWriter (DataTypeManager dtm , List <DataType > target , Writer baseWriter )
101
+ throws IOException {
100
102
super (baseWriter );
101
103
this .baseWriter = baseWriter ;
102
104
this .dtm = dtm ;
@@ -117,11 +119,12 @@ public IsfDataTypeWriter(DataTypeManager dtm, List<DataType> target, Writer base
117
119
STRICT = true ;
118
120
}
119
121
122
+ @ Override
120
123
public JsonObject getRootObject (TaskMonitor monitor ) throws CancelledException , IOException {
121
124
genRoot (monitor );
122
125
return data ;
123
126
}
124
-
127
+
125
128
@ Override
126
129
protected void genRoot (TaskMonitor monitor ) throws CancelledException , IOException {
127
130
genMetadata ();
@@ -160,7 +163,8 @@ private void genMetadata() {
160
163
oskey = metaData .get ("Compiler ID" );
161
164
if (metaData .containsKey ("PDB Loaded" )) {
162
165
os = gson .toJsonTree (new IsfWinOS (metaData ));
163
- } else if (metaData .containsKey ("Executable Format" )) {
166
+ }
167
+ else if (metaData .containsKey ("Executable Format" )) {
164
168
if (metaData .get ("Executable Format" ).contains ("ELF" )) {
165
169
oskey = "linux" ;
166
170
os = gson .toJsonTree (new IsfLinuxOS (gson , metaData ));
@@ -201,15 +205,18 @@ private void genSymbols(TaskMonitor monitor) {
201
205
Symbol symbol = iterator .next ();
202
206
symbolToJson (imageBase , symbolTable , linkages , map , symbol );
203
207
}
204
- } else {
208
+ }
209
+ else {
205
210
for (Address addr : requestedAddresses ) {
206
- Symbol [] symsFromAddr = symbolTable .getSymbols (addr .add (imageBase .getOffset ()));
211
+ Symbol [] symsFromAddr =
212
+ symbolTable .getSymbols (addr .add (imageBase .getOffset ()));
207
213
for (Symbol symbol : symsFromAddr ) {
208
214
symbolToJson (imageBase , symbolTable , linkages , map , symbol );
209
215
}
210
216
}
211
217
}
212
- } else {
218
+ }
219
+ else {
213
220
for (String key : requestedSymbols ) {
214
221
SymbolIterator iter = symbolTable .getSymbols (key );
215
222
while (iter .hasNext ()) {
@@ -263,7 +270,7 @@ private void processMap(Map<String, DataType> map, List<String> keylist, TaskMon
263
270
monitor .setMaximum (keylist .size ());
264
271
for (String key : keylist ) {
265
272
DataType dataType = map .get (key );
266
- if (key . contains ( ".conflict" )) {
273
+ if (DataTypeUtilities . isConflictDataType ( dataType )) {
267
274
continue ;
268
275
}
269
276
obj = getObjectForDataType (dataType , monitor );
@@ -273,28 +280,34 @@ private void processMap(Map<String, DataType> map, List<String> keylist, TaskMon
273
280
if (dataType instanceof FunctionDefinition ) {
274
281
// Would be nice to support this in the future, but Volatility does not
275
282
add (functions , dataType .getPathName (), obj );
276
- } else if (IsfUtilities .isBaseDataType (dataType )) {
283
+ }
284
+ else if (IsfUtilities .isBaseDataType (dataType )) {
277
285
add (baseTypes , dataType .getPathName (), obj );
278
- } else if (dataType instanceof TypeDef ) {
286
+ }
287
+ else if (dataType instanceof TypeDef ) {
279
288
DataType baseDataType = ((TypeDef ) dataType ).getBaseDataType ();
280
289
if (IsfUtilities .isBaseDataType (baseDataType )) {
281
290
add (baseTypes , dataType .getPathName (), obj );
282
- } else if (baseDataType instanceof Enum ) {
291
+ }
292
+ else if (baseDataType instanceof Enum ) {
283
293
add (enums , dataType .getPathName (), obj );
284
- } else {
294
+ }
295
+ else {
285
296
add (userTypes , dataType .getPathName (), obj );
286
297
}
287
- } else if (dataType instanceof Enum ) {
298
+ }
299
+ else if (dataType instanceof Enum ) {
288
300
add (enums , dataType .getPathName (), obj );
289
- } else if (dataType instanceof Composite ) {
301
+ }
302
+ else if (dataType instanceof Composite ) {
290
303
add (userTypes , dataType .getPathName (), obj );
291
304
}
292
305
monitor .increment ();
293
306
}
294
307
}
295
308
296
- private void symbolToJson (Address imageBase , SymbolTable symbolTable , Map < String , Symbol > linkages ,
297
- Map <String , JsonObject > map , Symbol symbol ) {
309
+ private void symbolToJson (Address imageBase , SymbolTable symbolTable ,
310
+ Map <String , Symbol > linkages , Map < String , JsonObject > map , Symbol symbol ) {
298
311
String key = symbol .getName ();
299
312
Address address = symbol .getAddress ();
300
313
JsonObject sym = map .containsKey (key ) ? map .get (key ) : new JsonObject ();
@@ -305,10 +318,12 @@ private void symbolToJson(Address imageBase, SymbolTable symbolTable, Map<String
305
318
sym .addProperty ("linkage_name" , linkage .getName ());
306
319
sym .addProperty ("address" , linkage .getAddress ().getOffset ());
307
320
}
308
- } else {
321
+ }
322
+ else {
309
323
if (address .getAddressSpace ().equals (imageBase .getAddressSpace ())) {
310
324
sym .addProperty ("address" , address .subtract (imageBase ));
311
- } else {
325
+ }
326
+ else {
312
327
sym .addProperty ("address" , address .getOffset ());
313
328
}
314
329
}
@@ -323,6 +338,7 @@ private void symbolToJson(Address imageBase, SymbolTable symbolTable, Map<String
323
338
}
324
339
}
325
340
341
+ @ Override
326
342
public void write (JsonObject obj ) {
327
343
gson .toJson (obj , writer );
328
344
}
@@ -332,7 +348,8 @@ protected void addSingletons() {
332
348
add (baseTypes , "undefined" , getTree (newTypedefPointer (null )));
333
349
}
334
350
335
- protected JsonObject getObjectForDataType (DataType dt , TaskMonitor monitor ) throws IOException , CancelledException {
351
+ protected JsonObject getObjectForDataType (DataType dt , TaskMonitor monitor )
352
+ throws IOException , CancelledException {
336
353
IsfObject isf = getIsfObject (dt , monitor );
337
354
if (isf != null ) {
338
355
JsonObject jobj = (JsonObject ) getTree (isf );
@@ -351,7 +368,8 @@ protected JsonObject getObjectForDataType(DataType dt, TaskMonitor monitor) thro
351
368
* @param monitor the task monitor
352
369
* @throws IOException if there is an exception writing the output
353
370
*/
354
- protected IsfObject getIsfObject (DataType dt , TaskMonitor monitor ) throws IOException , CancelledException {
371
+ protected IsfObject getIsfObject (DataType dt , TaskMonitor monitor )
372
+ throws IOException , CancelledException {
355
373
if (dt == null ) {
356
374
throw new IOException ("Null datatype passed to getIsfObject" );
357
375
}
@@ -377,21 +395,29 @@ protected IsfObject getIsfObject(DataType dt, TaskMonitor monitor) throws IOExce
377
395
if (dt instanceof Dynamic dynamic ) {
378
396
DataType rep = dynamic .getReplacementBaseType ();
379
397
return rep == null ? null : getIsfObject (rep , monitor );
380
- } else if (dt instanceof TypeDef typedef ) {
398
+ }
399
+ else if (dt instanceof TypeDef typedef ) {
381
400
return getObjectTypeDef (typedef , monitor );
382
- } else if (dt instanceof Composite composite ) {
401
+ }
402
+ else if (dt instanceof Composite composite ) {
383
403
return new IsfComposite (composite , this , monitor );
384
- } else if (dt instanceof Enum enumm ) {
404
+ }
405
+ else if (dt instanceof Enum enumm ) {
385
406
return new IsfEnum (enumm );
386
- } else if (dt instanceof BuiltInDataType builtin ) {
407
+ }
408
+ else if (dt instanceof BuiltInDataType builtin ) {
387
409
return new IsfBuiltIn (builtin );
388
- } else if (dt instanceof BitFieldDataType ) {
410
+ }
411
+ else if (dt instanceof BitFieldDataType ) {
389
412
// skip - not hit
390
- } else if (dt instanceof FunctionDefinition ) { /// FAIL
413
+ }
414
+ else if (dt instanceof FunctionDefinition ) { /// FAIL
391
415
// skip - not hit
392
- } else if (dt .equals (DataType .DEFAULT )) {
416
+ }
417
+ else if (dt .equals (DataType .DEFAULT )) {
393
418
// skip - not hit
394
- } else {
419
+ }
420
+ else {
395
421
Msg .warn (this , "Unable to write datatype. Type unrecognized: " + dt .getClass ());
396
422
}
397
423
@@ -417,8 +443,8 @@ public IsfObject resolve(DataType dt) {
417
443
}
418
444
}
419
445
}
420
- Msg .warn (this ,
421
- "WARNING! conflicting data type names: " + dt . getPathName () + " - " + resolvedType .getPathName ());
446
+ Msg .warn (this , "WARNING! conflicting data type names: " + dt . getPathName () + " - " +
447
+ resolvedType .getPathName ());
422
448
return resolved .get (dt );
423
449
}
424
450
@@ -465,8 +491,9 @@ public IsfObject getObjectTypeDeclaration(DataTypeComponent component) {
465
491
return newIsfDynamicComponent (dynamic , type , elementCnt );
466
492
467
493
}
468
- Msg .error (this , dynamic .getClass ().getSimpleName () + " returned bad replacementBaseType: "
469
- + replacementBaseType .getClass ().getSimpleName ());
494
+ Msg .error (this ,
495
+ dynamic .getClass ().getSimpleName () + " returned bad replacementBaseType: " +
496
+ replacementBaseType .getClass ().getSimpleName ());
470
497
}
471
498
}
472
499
return null ;
@@ -500,7 +527,7 @@ public IsfObject getObjectDataType(DataType dataType, int componentOffset) {
500
527
IsfObject baseObject = getObjectDataType (IsfUtilities .getBaseDataType (dataType ));
501
528
return new IsfDataTypeTypeDef (dataType , baseObject );
502
529
}
503
- if (dataType . getPathName (). contains ( ".conflict" )) {
530
+ if (DataTypeUtilities . isConflictDataType ( dataType )) {
504
531
if (!deferredKeys .contains (dataType .getPathName ())) {
505
532
deferredKeys .add (dataType .getPathName ());
506
533
}
@@ -513,7 +540,8 @@ public IsfObject getObjectDataType(DataType dataType, int componentOffset) {
513
540
*
514
541
* @throws CancelledException if the action is cancelled by the user
515
542
*/
516
- protected IsfObject getObjectTypeDef (TypeDef typeDef , TaskMonitor monitor ) throws CancelledException {
543
+ protected IsfObject getObjectTypeDef (TypeDef typeDef , TaskMonitor monitor )
544
+ throws CancelledException {
517
545
DataType dataType = typeDef .getDataType ();
518
546
String typedefName = typeDef .getPathName ();
519
547
@@ -527,7 +555,8 @@ protected IsfObject getObjectTypeDef(TypeDef typeDef, TaskMonitor monitor) throw
527
555
return newTypedefUser (typeDef , isfObject );
528
556
}
529
557
return newTypedefPointer (typeDef );
530
- } catch (Exception e ) {
558
+ }
559
+ catch (Exception e ) {
531
560
Msg .error (this , "TypeDef error: " + e );
532
561
}
533
562
clearResolve (typedefName , baseType );
@@ -544,7 +573,8 @@ public void requestAddress(String key) throws IOException {
544
573
return ;
545
574
}
546
575
requestedAddresses .add (address );
547
- } catch (AddressFormatException e ) {
576
+ }
577
+ catch (AddressFormatException e ) {
548
578
throw new IOException ("Bad address format: " + key );
549
579
}
550
580
}
0 commit comments