@@ -42,6 +42,7 @@ public class GoTypesAnalyzer extends AnalyzerBase {
42
42
"Uint" , "Uint8" , "Uint16" , "Uint32" , "Uint64" , "Uintptr" , "Float32" , "Float64" , "Complex64" , "Complex128" ,
43
43
"Array" , "Chan" , "Func" , "Interface" , "Map" , "Ptr" , "Slice" , "String" , "Struct" , "UnsafePointer" };
44
44
private final CategoryPath goPath = new CategoryPath ("/go" );
45
+ private final CategoryPath rtypePath = new CategoryPath ("/go/rtype" );
45
46
46
47
public GoTypesAnalyzer (String name , String description , AnalyzerType type ) {
47
48
super (name , description , type );
@@ -79,9 +80,9 @@ private void createBaseTypes(Program p) {
79
80
}
80
81
81
82
private void createRTypes (Program p ) {
82
- CategoryPath goPath = new CategoryPath ( "/go" );
83
+
83
84
DataTypeManager dtm = p .getDataTypeManager ();
84
- StructureDataType rtype = new StructureDataType (goPath , "Rtype" , 0 );
85
+ StructureDataType rtype = new StructureDataType (rtypePath , "Rtype" , 0 );
85
86
rtype .add (new QWordDataType (), "size" , null );
86
87
rtype .add (new QWordDataType (), "ptrdata" , null );
87
88
rtype .add (new QWordDataType (), "hash" , null );
@@ -96,11 +97,11 @@ private void createRTypes(Program p) {
96
97
97
98
dtm .addDataType (rtype , DataTypeConflictHandler .KEEP_HANDLER );
98
99
99
- StructureDataType bitvector = new StructureDataType (goPath , "bitvector " , 0 );
100
+ StructureDataType bitvector = new StructureDataType (rtypePath , "Bitvector " , 0 );
100
101
bitvector .add (new QWordDataType (), "n" , null );
101
102
bitvector .add (new PointerDataType (), "bytedata" , null );
102
103
103
- StructureDataType moduledata = new StructureDataType (goPath , "moduledata " , 0 );
104
+ StructureDataType moduledata = new StructureDataType (rtypePath , "Moduledata " , 0 );
104
105
moduledata .add (new PointerDataType (), "pcHeader" , null );
105
106
moduledata .add (dtm .getDataType (goPath , "Slice" ), "funcnametab" , null );
106
107
moduledata .add (dtm .getDataType (goPath , "Slice" ), "cutab" , null );
@@ -143,38 +144,38 @@ private void createRTypes(Program p) {
143
144
144
145
dtm .addDataType (moduledata , DataTypeConflictHandler .KEEP_HANDLER );
145
146
146
- StructureDataType arr = new StructureDataType ("RArray " , 0 );
147
+ StructureDataType arr = new StructureDataType (rtypePath , "Array " , 0 );
147
148
arr .add (new PointerDataType (), 8 , "elem" , "array element type" );
148
149
arr .add (new PointerDataType (), 8 , "slice" , null );
149
150
arr .add (new QWordDataType (), "len" , null );
150
151
151
152
dtm .addDataType (arr , DataTypeConflictHandler .KEEP_HANDLER );
152
153
153
- StructureDataType chan = new StructureDataType ("RChan " , 0 );
154
+ StructureDataType chan = new StructureDataType (rtypePath , "Chan " , 0 );
154
155
chan .add (new PointerDataType (), "elem" , "channel element type" );
155
156
chan .add (new QWordDataType (), "dir" , "channel direction" );
156
157
157
158
dtm .addDataType (chan , DataTypeConflictHandler .KEEP_HANDLER );
158
159
159
- StructureDataType func = new StructureDataType ("RFunc " , 0 );
160
+ StructureDataType func = new StructureDataType (rtypePath , "Func " , 0 );
160
161
func .add (new UnsignedShortDataType (), "in" , "function argment number" );
161
162
func .add (new QWordDataType (), "out" , "function return number" );
162
163
163
164
dtm .addDataType (func , DataTypeConflictHandler .KEEP_HANDLER );
164
- // internal type, there is no rtype before this type
165
- StructureDataType imethod = new StructureDataType ("RInterfaceMethod " , 0 );
165
+
166
+ StructureDataType imethod = new StructureDataType (rtypePath , "InterfaceMethod " , 0 );
166
167
imethod .add (new QWordDataType (), "nameOff" , "name of method" );
167
168
imethod .add (new QWordDataType (), "typeOff" , ".(*FuncType) underneath" );
168
169
169
170
dtm .addDataType (imethod , DataTypeConflictHandler .KEEP_HANDLER );
170
171
171
- StructureDataType iface = new StructureDataType ("RInterface " , 0 );
172
+ StructureDataType iface = new StructureDataType (rtypePath , "Interface " , 0 );
172
173
iface .add (new QWordDataType (), "pkgPath" , "import path" );
173
174
iface .add (dtm .getDataType (goPath , "Slice" ), "methods" , "interface data" );
174
175
175
176
dtm .addDataType (iface , DataTypeConflictHandler .KEEP_HANDLER );
176
177
177
- StructureDataType map = new StructureDataType ("RMap " , 0 );
178
+ StructureDataType map = new StructureDataType (rtypePath , "Map " , 0 );
178
179
map .add (new PointerDataType (), "key" , "map key type" );
179
180
map .add (new PointerDataType (), "elem" , "map element type" );
180
181
map .add (new PointerDataType (), "buckets" , "hash function" );
@@ -185,25 +186,25 @@ private void createRTypes(Program p) {
185
186
186
187
dtm .addDataType (map , DataTypeConflictHandler .KEEP_HANDLER );
187
188
188
- StructureDataType ptr = new StructureDataType ("RPtr " , 0 );
189
+ StructureDataType ptr = new StructureDataType (rtypePath , "Ptr " , 0 );
189
190
ptr .add (new PointerDataType (), "elem" , "pointer type" );
190
191
191
192
dtm .addDataType (ptr , DataTypeConflictHandler .KEEP_HANDLER );
192
193
193
- StructureDataType slice = new StructureDataType ("RSlice " , 0 );
194
+ StructureDataType slice = new StructureDataType (rtypePath , "Slice " , 0 );
194
195
slice .add (new PointerDataType (), "data" , "slice data" );
195
196
slice .add (new QWordDataType (), "elem" , "slice element type" );
196
197
197
198
dtm .addDataType (slice , DataTypeConflictHandler .KEEP_HANDLER );
198
199
199
- StructureDataType structfield = new StructureDataType ("GoRStructField " , 0 );
200
+ StructureDataType structfield = new StructureDataType (rtypePath , "StructField " , 0 );
200
201
structfield .add (new PointerDataType (), "name" , "name of field" );
201
202
structfield .add (new PointerDataType (), "typ" , "type of field" );
202
203
structfield .add (new QWordDataType (), "offset" , "offset of field" );
203
204
204
205
dtm .addDataType (structfield , DataTypeConflictHandler .KEEP_HANDLER );
205
206
206
- StructureDataType struct = new StructureDataType ("GoRStruct " , 0 );
207
+ StructureDataType struct = new StructureDataType (rtypePath , "Struct " , 0 );
207
208
struct .add (new PointerDataType (), "name" , "name of struct" );
208
209
struct .add (dtm .getDataType (goPath , "Slice" ), "fields" , "sorted by offset" );
209
210
@@ -236,7 +237,7 @@ private void analyzeModuleData(Program p, TaskMonitor m, MessageLog log) {
236
237
.getAddress (typeBase .getOffset () + offset );
237
238
Map <String , Data > rtype = setRType (p , typeAddress );
238
239
int idx = (int ) rtype .get ("kind" ).getValue ();
239
- typeAddress = typeAddress .add (p .getDataTypeManager ().getDataType (goPath , "RType" ).getLength ());
240
+ typeAddress = typeAddress .add (p .getDataTypeManager ().getDataType (rtypePath , "RType" ).getLength ());
240
241
idx = idx & ((1 << 5 ) - 1 ); // mask kind
241
242
if (idx > 27 ) {
242
243
idx = 0 ;
@@ -344,7 +345,7 @@ private void analyzeModuleData(Program p, TaskMonitor m, MessageLog log) {
344
345
}
345
346
346
347
private Map <String , Data > setRArrayType (Program p , Address a ) throws Exception {
347
- DataType arrayType = p .getDataTypeManager ().getDataType (goPath , "RArray " );
348
+ DataType arrayType = p .getDataTypeManager ().getDataType (rtypePath , "Array " );
348
349
p .getListing ().clearCodeUnits (a , a .add (arrayType .getLength ()), true );
349
350
Map <String , Data > ret = new HashMap <>();
350
351
Data d = p .getListing ().createData (a , arrayType );
@@ -355,7 +356,7 @@ private Map<String, Data> setRArrayType(Program p, Address a) throws Exception {
355
356
}
356
357
357
358
private Map <String , Data > setRChanType (Program p , Address a ) throws Exception {
358
- DataType chanType = p .getDataTypeManager ().getDataType (goPath , "RChan " );
359
+ DataType chanType = p .getDataTypeManager ().getDataType (rtypePath , "Chan " );
359
360
p .getListing ().clearCodeUnits (a , a .add (chanType .getLength ()), true );
360
361
Map <String , Data > ret = new HashMap <>();
361
362
Data d = p .getListing ().createData (a , chanType );
@@ -365,7 +366,7 @@ private Map<String, Data> setRChanType(Program p, Address a) throws Exception {
365
366
}
366
367
367
368
private Map <String , Data > setRFuncType (Program p , Address a ) throws Exception {
368
- DataType funcType = p .getDataTypeManager ().getDataType (goPath , "RFunc " );
369
+ DataType funcType = p .getDataTypeManager ().getDataType (rtypePath , "Func " );
369
370
p .getListing ().clearCodeUnits (a , a .add (funcType .getLength ()), true );
370
371
Map <String , Data > ret = new HashMap <>();
371
372
Data d = p .getListing ().createData (a , funcType );
@@ -375,7 +376,7 @@ private Map<String, Data> setRFuncType(Program p, Address a) throws Exception {
375
376
}
376
377
377
378
private Map <String , Data > setRInterfaceType (Program p , Address a ) throws Exception {
378
- DataType interfaceType = p .getDataTypeManager ().getDataType (goPath , "RInterface " );
379
+ DataType interfaceType = p .getDataTypeManager ().getDataType (rtypePath , "Interface " );
379
380
p .getListing ().clearCodeUnits (a , a .add (interfaceType .getLength ()), true );
380
381
Map <String , Data > ret = new HashMap <>();
381
382
Data d = p .getListing ().createData (a , interfaceType );
@@ -385,7 +386,7 @@ private Map<String, Data> setRInterfaceType(Program p, Address a) throws Excepti
385
386
}
386
387
387
388
private Map <String , Data > setRMapType (Program p , Address a ) throws Exception {
388
- DataType mapType = p .getDataTypeManager ().getDataType (goPath , "RMap " );
389
+ DataType mapType = p .getDataTypeManager ().getDataType (rtypePath , "Map " );
389
390
p .getListing ().clearCodeUnits (a , a .add (mapType .getLength ()), true );
390
391
Map <String , Data > ret = new HashMap <>();
391
392
Data d = p .getListing ().createData (a , mapType );
@@ -401,7 +402,7 @@ private Map<String, Data> setRMapType(Program p, Address a) throws Exception {
401
402
}
402
403
403
404
private Map <String , Data > setRPtrType (Program p , Address a ) throws Exception {
404
- DataType ptrType = p .getDataTypeManager ().getDataType (goPath , "RPtr " );
405
+ DataType ptrType = p .getDataTypeManager ().getDataType (rtypePath , "Ptr " );
405
406
p .getListing ().clearCodeUnits (a , a .add (ptrType .getLength ()), true );
406
407
Map <String , Data > ret = new HashMap <>();
407
408
Data d = p .getListing ().createData (a , ptrType );
@@ -410,7 +411,7 @@ private Map<String, Data> setRPtrType(Program p, Address a) throws Exception {
410
411
}
411
412
412
413
private Map <String , Data > setRSliceType (Program p , Address a ) throws Exception {
413
- DataType sliceType = p .getDataTypeManager ().getDataType (goPath , "RSlice " );
414
+ DataType sliceType = p .getDataTypeManager ().getDataType (rtypePath , "Slice " );
414
415
p .getListing ().clearCodeUnits (a , a .add (sliceType .getLength ()), true );
415
416
Map <String , Data > ret = new HashMap <>();
416
417
Data d = p .getListing ().createData (a , sliceType );
@@ -419,7 +420,7 @@ private Map<String, Data> setRSliceType(Program p, Address a) throws Exception {
419
420
}
420
421
421
422
private Map <String , Data > setRStructType (Program p , Address a ) throws Exception {
422
- DataType structType = p .getDataTypeManager ().getDataType (goPath , "RStruct " );
423
+ DataType structType = p .getDataTypeManager ().getDataType (rtypePath , "Struct " );
423
424
p .getListing ().clearCodeUnits (a , a .add (structType .getLength ()), true );
424
425
Map <String , Data > ret = new HashMap <>();
425
426
Data d = p .getListing ().createData (a , structType );
@@ -429,7 +430,7 @@ private Map<String, Data> setRStructType(Program p, Address a) throws Exception
429
430
}
430
431
431
432
private Map <String , Data > setRType (Program p , Address a ) throws Exception {
432
- DataType rType = p .getDataTypeManager ().getDataType (goPath , "RType " );
433
+ DataType rType = p .getDataTypeManager ().getDataType (rtypePath , "Rtype " );
433
434
p .getListing ().clearCodeUnits (a , a .add (rType .getLength ()), true );
434
435
Map <String , Data > ret = new HashMap <>();
435
436
Data d = p .getListing ().createData (a , rType );
@@ -448,7 +449,7 @@ private Map<String, Data> setRType(Program p, Address a) throws Exception {
448
449
}
449
450
450
451
private Map <String , Data > setModuleData (Program p , Address a ) throws Exception {
451
- DataType moduleData = p .getDataTypeManager ().getDataType (goPath , "RModule " );
452
+ DataType moduleData = p .getDataTypeManager ().getDataType (rtypePath , "Moduledata " );
452
453
p .getListing ().clearCodeUnits (a , a .add (moduleData .getLength ()), true );
453
454
Map <String , Data > ret = new HashMap <>();
454
455
Data d = p .getListing ().createData (a , moduleData );
0 commit comments