forked from silverf0x/RpcView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInternalComplexTypesMisc.cpp
973 lines (764 loc) · 21.3 KB
/
InternalComplexTypesMisc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
#include "InternalComplexTypesMisc.h"
#include "internalRpcDecompiler.h"
#include "internalRpcUtils.h"
#include <string>
BOOL __fastcall processBindContext(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Inout_ ParamDesc& ParamDesc,
_Inout_ std::list<TypeToDefine>& listProcTypes,
_Inout_ std::ostringstream& oss)
{
UNREFERENCED_PARAMETER(listProcTypes);
UNREFERENCED_PARAMETER(pType);
UNREFERENCED_PARAMETER(pContext);
oss << "[context_handle] void*";
displayPtrLevel(ParamDesc.getuPtrLevel(), oss);
oss <<" "<<ParamDesc.getStrTypeName();
return TRUE;
}
BOOL __fastcall process_FC_BLKHOLE(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Inout_ ParamDesc& ParamDesc,
_Inout_ std::list<TypeToDefine>& listProcTypes,
_Inout_ std::ostringstream& oss)
{
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
BOOL bResult = TRUE;
short wOffsetRange = 0;
DWORD dwRangeBegin = 0;
DWORD dwRangeEnd = 0;
RVA_T pNewType = NULL;
BYTE bRead = 0;
pType += sizeof(BYTE) + sizeof(BYTE); // skip FC_TYPE and first BYTE
//read offset to complex type
RPC_GET_PROCESS_DATA(pType,&wOffsetRange,sizeof(wOffsetRange));
if(!bResult)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] process_FC_BLKHOLE : unable to read process data\n");
return FALSE;
}
pNewType = pType + wOffsetRange;
pType += sizeof(wOffsetRange);
// read FC_TYPE at given offset
RPC_GET_PROCESS_DATA(pNewType,&bRead,sizeof(bRead));
if(bResult == FALSE)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] process_FC_BLKHOLE : unable to read process data\n");
return FALSE;
}
// if type is a FC_BIND_CONTEXT range doesn't make sense
// todo : check why this happen
if((FC_TYPE) bRead != FC_BIND_CONTEXT)
{
//read range begin
RPC_GET_PROCESS_DATA(pType,&dwRangeBegin,sizeof(dwRangeBegin));
if(bResult == FALSE)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] process_FC_BLKHOLE : unable to read process data\n");
return FALSE;
}
pType += sizeof(dwRangeBegin);
//read range end
RPC_GET_PROCESS_DATA(pType,&dwRangeEnd,sizeof(dwRangeEnd));
if(bResult == FALSE)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] process_FC_BLKHOLE : unable to read process data\n");
return FALSE;
}
oss<<"[range("<<dwRangeBegin<<","<<(UINT)dwRangeEnd<<")] ";
}
ParamDesc.setRva(pNewType);
bResult = rpcDumpType(
pContext,
ParamDesc,
listProcTypes,
oss);
return bResult;
}
BOOL __fastcall getFC_BLKHOLEMemorySize(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Out_ size_t* pszMemorySize,
_In_ BOOL bHasRangeOnConformance)
{
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
BOOL bResult = TRUE;
short offsetRange = 0;
RVA_T pNewType = NULL;
pType += sizeof(BYTE) + sizeof(BYTE); // skip FC_TYPE and first BYTE
//read offset to complex type
RPC_GET_PROCESS_DATA(pType,&offsetRange,sizeof(offsetRange));
if(!bResult)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] getFC_BLKHOLEMemorySize : unable to read process data\n");
return FALSE;
}
pNewType = pType + offsetRange;
bResult = getTypeMemorySize(pContext, pNewType, pszMemorySize, bHasRangeOnConformance);
return bResult;
}
BOOL __fastcall processRange(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Inout_ ParamDesc& ParamDesc,
_Inout_ std::list<TypeToDefine>& listProcTypes,
_Inout_ std::ostringstream& oss)
{
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
BOOL bResult = TRUE;
std::ostringstream ossTmp;
Range_t range;
UNREFERENCED_PARAMETER(listProcTypes);
RPC_GET_PROCESS_DATA(pType, &range, sizeof(range));
if(!bResult)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] processRange : unable to read process data\n");
return FALSE;
}
processSimpleType(
pContext,
(FC_TYPE)(range.flags_type & 0xF), //type is on lower byte
ParamDesc,
ossTmp);
if(ParamDesc.getuPtrLevel() != 0)
{
oss << "/*";
}
oss << "[range(" << std::dec << range.lowValue << "," << range.highValue<< ")] ";
if(ParamDesc.getuPtrLevel() != 0)
{
oss << "*/";
}
oss<<ossTmp.str();
return TRUE;
}
BOOL __fastcall getRangeMemorySize(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Out_ size_t* pszMemorySize)
{
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
BOOL bResult = TRUE;
Range_t range;
RPC_GET_PROCESS_DATA(pType, &range, sizeof(range));
if(!bResult)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] getRangeMemorySize : unable to read process data\n");
return FALSE;
}
(*pszMemorySize) = getSimpleTypeMemorySize((FC_TYPE) (range.flags_type & 0xF));
return TRUE;
}
BOOL __fastcall ProcessArrayRange(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Inout_ ParamDesc& ParamDesc,
_Inout_ std::ostringstream& temp)
{
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
BOOL bResult = TRUE;
Range_t range;
UNREFERENCED_PARAMETER(ParamDesc);
RPC_GET_PROCESS_DATA(pType, &range, sizeof(range));
if(!bResult)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] ProcessArrayRange : unable to read process data\n");
return FALSE;
}
temp << "/*[range(" << std::dec << range.lowValue << "," << range.highValue<< ")]*/ ";
return bResult;
}
UINT getElementByOffset(std::vector <UINT> v, UINT offset)
{
for(UINT i=0; i<v.size(); i++)
{
if(v[i] == offset)
{
return i;
}
}
return (UINT)-1;
}
BOOL __fastcall processUserMarshal(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Inout_ ParamDesc& ParamDesc,
_Inout_ std::list<TypeToDefine>& listProcTypes,
_Inout_ std::ostringstream& oss)
{
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
BOOL bResult = TRUE;
UserMarshal_t userMarshal;
RVA_T pUserMarshalTarget = NULL;
std::string strParamNameTmp;
RPC_GET_PROCESS_DATA(pType, &userMarshal, sizeof(userMarshal));
if(FALSE == bResult)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] processUserMarshal : unable to read process data\n");
return FALSE;
}
oss << "/* WARNING : user_marshall should be defined in ACF file */ [user_marshall(";
// compute user marshal target offset
pUserMarshalTarget = pType + FIELD_OFFSET(UserMarshal_t, offset_to_the_transmitted_type) + userMarshal.offset_to_the_transmitted_type;
ParamDesc.setRva(pUserMarshalTarget);
strParamNameTmp = ParamDesc.getStrTypeName();
ParamDesc.setParamName("");
if (rpcDumpType(pContext, ParamDesc, listProcTypes, oss) == FALSE)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] processUserMarshal : unable to dump type\n");
return FALSE;
}
oss << ")] " << strParamNameTmp;
// set user_marshal size ??
return TRUE;
}
BOOL __fastcall getUserMarshallMemorySize(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Out_ size_t* pszMemorySize)
{
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
BOOL bResult = TRUE;
UserMarshal_t userMarshal;
RPC_GET_PROCESS_DATA(pType, &userMarshal, sizeof(userMarshal));
if(FALSE == bResult)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] processUserMarshal : unable to read process data\n");
return FALSE;
}
*pszMemorySize = userMarshal.user_type_memory_size;
return TRUE;
}
BOOL __fastcall processPipe(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Inout_ ParamDesc& ParamDesc,
_Inout_ std::list<TypeToDefine>& listProcTypes,
_Inout_ std::ostringstream& oss)
{
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
BOOL bResult = TRUE;
Pipe_t pipe;
RVA_T pPipeTarget = NULL;
std::string strParamNameTmp;
RPC_GET_PROCESS_DATA(pType, &pipe, sizeof(pipe));
if(FALSE == bResult)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] processPipe : unable to read process data\n");
return FALSE;
}
// compute pipe target offset
pPipeTarget = pType + FIELD_OFFSET(Pipe_t, offsetToType ) + pipe.offsetToType;
ParamDesc.setRva(pPipeTarget);
oss << "pipe ";
if (rpcDumpType(pContext, ParamDesc, listProcTypes, oss) == FALSE)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] processPipe : unable to read process data\n");
return FALSE;
}
// set pipe size ??
return TRUE;
}
BOOL __fastcall getPipeMemorySize(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Out_ size_t* pszMemorySize,
_In_ BOOL bHasRangeOnConformance)
{
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
BOOL bResult = TRUE;
Pipe_t pipe;
RVA_T pPipeTarget = NULL;
RPC_GET_PROCESS_DATA(pType, &pipe, sizeof(pipe));
if(FALSE == bResult)
{
RPC_DEBUG_FN((UCHAR*)"[ERROR] getPipeMemorySize : unable to read process data\n");
return FALSE;
}
// compute pipe target offset
pPipeTarget = pType + FIELD_OFFSET(Pipe_t, offsetToType ) + pipe.offsetToType;
bResult = getTypeMemorySize(pContext, pPipeTarget, pszMemorySize, bHasRangeOnConformance);
return bResult;
}
BOOL __fastcall processCorrelationDescriptor(
_In_ VOID* pContext,
_In_ ConformanceDescr_T confDesc,
_Inout_ std::ostringstream& oss,
_Inout_ ParamDesc& paramDesc)
{
BOOL bResult = FALSE;
oss<<"[";
// display conformance type
switch(confDesc.confType)
{
case size_is:
oss<<"size_is(";
break;
case switch_is:
oss<<"switch_is(";
break;
case length_is:
oss<<"length_is(";
break;
case byte_count:
oss<<"byte_count(";
break;
default:
oss<<"unknow_corr_type(";
}
// Check on which pointer level conformance should be applied
{
UINT uPtrLevel = paramDesc.getuPtrLevel();
if(uPtrLevel > 1)
{
while(--uPtrLevel > 1)
{
oss << ",";
}
}
}
bResult = processCorrelationDescriptorNaked(pContext, confDesc, oss, paramDesc);
oss<<")]";
return bResult;
}
BOOL __fastcall processCorrelationDescriptorNaked(
_In_ VOID* pContext,
_In_ ConformanceDescr_T confDesc,
_Inout_ std::ostringstream& oss,
_Inout_ ParamDesc& paramDesc)
{
BOOL bResult;
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
std::string strCorrelationItem; // string describing X in size_is(X)
// special cases : OperationType == FC_EXPR || OperationType === FC_CALLBACK
if(confDesc.corrDesc.correlation_operator == FC_EXPR )
{
USHORT offset = 0;
// read offset
RPC_GET_PROCESS_DATA(
((RVA_T)pRpcDecompilerCtxt->pRpcDecompilerInfo->pExprOffset + confDesc.corrDesc.offset*sizeof(USHORT)),
&offset,
sizeof(USHORT));
if(bResult == FALSE)
{
oss << "/* ERROR unable to read ExprOffset table */";
return FALSE;
}
oss << "/* FC_EXPR */";
bResult = processFcExpr(
pContext,
pRpcDecompilerCtxt->pRpcDecompilerInfo->pExprFormatString + offset,
paramDesc,
confDesc,
oss);
return bResult;
}
if(confDesc.corrDesc.correlation_operator == FC_CALLBACK )
{
oss << "/*FC_CALLBACK not implemented */";
return TRUE;
}
// FIRST STEP : according to correlation type correlation item
// case of a FC_CONSTANT_CONFORMANCE
if(confDesc.corrDesc.correlation_type & FC_CONSTANT_CONFORMANCE)
{
INT32 iSize = ((confDesc.corrDesc.correlation_operator << 16) | confDesc.corrDesc.offset) & 0xFFFFFF;
oss<<std::dec<<iSize;
return TRUE;
}
// case of a FC_TOP_LEVEL_CONFORMANCE
// only used in function definition ?
if(confDesc.corrDesc.correlation_type & FC_TOP_LEVEL_CONFORMANCE)
{
UINT uArgNbr = 0;
std::stringstream ss;
#ifdef DBG_DECOMP
oss <<"/*FC_TOP_LEVEL_CONFORMANCE*/";
#endif
uArgNbr = confDesc.corrDesc.offset / (VIRTUAL_STACK_OFFSET_GRANULARITY);
ss<<"arg_"<<std::dec<<uArgNbr;
strCorrelationItem = ss.str();
}
else if(confDesc.corrDesc.correlation_type & FC_POINTER_CONFORMANCE) // case of FC_POINTER_CONFORMANCE
{
std::stringstream ss;
UINT uCorrDescMember;
#ifdef DBG_DECOMP
oss<<"/*FC_POINTER_CONFORMANCE(" << std::dec << confDesc.corrDesc.offset << ") */" ;
#endif
// check if vectMemberOffset is correctly filled
if(paramDesc.getVectMembersOffset().size() == 0)
{
oss << " /* ERROR : FC_POINTER_CONFORMANCE but an empty vectMemberOffset has been provided (offset = " <<confDesc.corrDesc.offset<< ") */";
return FALSE;
}
// get corr desc member number according to its offset
uCorrDescMember = getElementByOffset(paramDesc.getVectMembersOffset(), confDesc.corrDesc.offset);
if(uCorrDescMember == -1)
{
oss << "/* ERROR invalid corrDescMember */";
return FALSE;
}
ss << "StructMember"<<std::dec<<uCorrDescMember;
strCorrelationItem = ss.str();
}
else if(confDesc.corrDesc.correlation_type & FC_TOP_LEVEL_MULTID_CONFORMANCE) // case of FC_TOP_LEVEL_MULTID_CONFORMANCE
{
// currently not implemented
oss<<"/*FC_TOP_LEVEL_MULTID_CONFORMANCE not implemented */)]";
return FALSE;
}
else
{
// last remaining case is FC_NORMAL_CONFORMANCE
// Onlys used in structure definition ?
UINT uCorrDescMemberOffset;
UINT uCorrDescMember;
std::stringstream ss;
#ifdef DBG_DECOMP
oss<<"/*FC_NORMAL_CONFORMANCE ("<< std::dec << confDesc.corrDesc.offset<<")*/ ";
#endif
// check if vectMemberOffset is correctly filled
if(paramDesc.getVectMembersOffset().size() == 0)
{
oss << " /* ERROR : FC_NORMAL_CONFORMANCE but an empty vectMemberOffset has been provided */";
return FALSE;
}
// compute correlation member offset
if(paramDesc.getVectMembersOffset().size() <= paramDesc.getuStructMemberNum())
{
oss << "/* ERROR invalid structMemberNum */";
return FALSE;
}
// get member number according to its offset
uCorrDescMemberOffset = paramDesc.getVectMembersOffset()[paramDesc.getuStructMemberNum()] + confDesc.corrDesc.offset;
uCorrDescMember = getElementByOffset(paramDesc.getVectMembersOffset(), uCorrDescMemberOffset);
if(uCorrDescMember == -1)
{
oss << "/* ERROR invalid corrDescMember || corr desc offset = */" << std::dec << confDesc.corrDesc.offset;
return TRUE;
//return FALSE
}
ss << "StructMember"<<std::dec<<uCorrDescMember;
strCorrelationItem = ss.str();
}
// SECOND STEP : display correlation item according to correlation operator
switch(confDesc.corrDesc.correlation_operator)
{
case FC_DEREFERENCE:
// the correlation item describing the size of the current item
// can derive from an out parameter. In that case, we can only set it
// has a max range and not the exact size since it's not known before the call.
// Ex :
// HRESULT Proc0 (
// [in] int arg1,
// [out] int *arg2,
// [out][size_is( , *arg2)] int **arg2
// );
if (paramDesc.isOut())
{
oss << ", *" << strCorrelationItem;
}
else
{
oss << "*" << strCorrelationItem;
}
break;
case FC_ADD_1:
oss << strCorrelationItem << "+1";
break;
case FC_SUB_1:
oss << strCorrelationItem << "-1";
break;
case FC_DIV_2:
oss << strCorrelationItem << "/2";
break;
case FC_MULT_2:
oss << strCorrelationItem << "*2";
break;
case FC_EXPR:
oss << "/* FC_EXPR not implemented */";
break;
case FC_CALLBACK:
oss << "/* FC_CALLBACK not implemented */";
default:
oss << strCorrelationItem;
}
return TRUE;
}
UINT __fastcall processFcExpr(
_In_ VOID* pContext,
_Out_ RVA_T pExpr,
_In_ ParamDesc& paramDesc,
_In_ ConformanceDescr_T confDesc,
_Inout_ std::ostringstream& oss)
{
EXPR_OPERATOR operation;
EXPR_CONST32 constante32;
//EXPR_CONST64 constante64; Not used as of yet. Maybe with NDR64?
EXPR_VAR var;
UINT32 varNb;
BOOL bResult;
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
UINT sizeToAdvance = 0;
UINT sizeOfExpr = 0;
RPC_GET_PROCESS_DATA(
pExpr,
&operation,
sizeof(EXPR_OPERATOR)
);
switch(operation.ExprType)
{
case FC_EXPR_OPER:
if(operation.Operator >= OP_UNARY_PLUS && operation.Operator <= OP_UNARY_AND) // Unary operator
{
oss << getOperatorType(operation);
pExpr += sizeof(EXPR_OPERATOR);
sizeToAdvance += sizeof(EXPR_OPERATOR);
sizeOfExpr = processFcExpr(pContext, pExpr, paramDesc, confDesc, oss);
sizeToAdvance += sizeOfExpr;
}else if(operation.Operator >= OP_PLUS && operation.Operator <= OP_LOGICAL_OR) // binary operator
{
std::string tmpOper = getOperatorType(operation);
oss << "(";
pExpr += sizeof(EXPR_OPERATOR);
sizeToAdvance += sizeof(EXPR_OPERATOR);
sizeOfExpr = processFcExpr(pContext, pExpr, paramDesc, confDesc, oss);
pExpr += sizeOfExpr;
sizeToAdvance += sizeOfExpr;
oss <<" "<< tmpOper.c_str()<<" ";
sizeOfExpr = processFcExpr(pContext, pExpr, paramDesc, confDesc, oss);
sizeToAdvance += sizeOfExpr;
oss << ")";
}else{ // Ternary operator => (expr ? expr1 : expr2)
std::ostringstream tmpIfYes;
std::ostringstream tmpIfNo;
pExpr += sizeof(EXPR_OPERATOR);
sizeToAdvance += sizeof(EXPR_OPERATOR);
sizeOfExpr = processFcExpr(pContext, pExpr, paramDesc, confDesc, tmpIfYes);
sizeToAdvance += sizeOfExpr;
pExpr += sizeOfExpr;
sizeOfExpr = processFcExpr(pContext, pExpr, paramDesc,confDesc, tmpIfNo);
sizeToAdvance += sizeOfExpr;
pExpr += sizeOfExpr;
oss << "(";
sizeOfExpr = processFcExpr(pContext, pExpr, paramDesc, confDesc, oss);
sizeToAdvance += sizeOfExpr;
oss << "?";
oss << tmpIfYes.str();
oss << ":";
oss << tmpIfNo.str();
oss << ")";
}
break;
case FC_EXPR_VAR:
RPC_GET_PROCESS_DATA(pExpr, &var, sizeof(EXPR_VAR));
if(confDesc.corrDesc.correlation_type & FC_TOP_LEVEL_CONFORMANCE)
{
varNb = var.Offset / VIRTUAL_STACK_OFFSET_GRANULARITY;
oss << "arg_" << std::dec << varNb;
}else{
INT uCorrDescMemberOffset;
INT uCorrDescMember;
std::stringstream ss;
// get member number according to its offset
if(paramDesc.getArrayIsAttributedPointer())
{
uCorrDescMemberOffset = var.Offset;
}else{
uCorrDescMemberOffset = paramDesc.getVectMembersOffset()[paramDesc.getuStructMemberNum()] + var.Offset;
}
uCorrDescMember = getElementByOffset(paramDesc.getVectMembersOffset(), uCorrDescMemberOffset);
if(uCorrDescMember == -1)
{
oss << "/* [ERROR] invalid corrDescMember || var offset = " << std::dec << var.Offset << "*/";
return FALSE;
}
oss << "StructMember"<<std::dec<<uCorrDescMember;
}
sizeToAdvance += sizeof(EXPR_VAR);
break;
case FC_EXPR_CONST32:
RPC_GET_PROCESS_DATA(pExpr, &constante32, sizeof(EXPR_CONST32));
oss << std::dec << constante32.ConstValue;
sizeToAdvance += sizeof(EXPR_CONST32);
break;
case FC_EXPR_CONST64:
// TODO
break;
default:
oss << "/*[ERROR] unknown expression type */";
break;
}
return sizeToAdvance;
}
std::string __fastcall getOperatorType(
_In_ EXPR_OPERATOR oper)
{
std::string result;
switch(oper.Operator)
{
case OP_UNARY_PLUS:
result = "+";
break;
case OP_UNARY_MINUS:
result = "-";
break;
case OP_UNARY_NOT:
result = "!";
break;
case OP_UNARY_COMPLEMENT:
result = "~";
break;
case OP_UNARY_CAST:
switch(oper.CastType)
{
case FC_SMALL:
result = "(byte)" ;
break;
case FC_USMALL:
result = "(char)";
break;
case FC_USHORT:
result = "(unsigned short)";
break;
case FC_LONG:
result = "(long)";
break;
case FC_ULONG:
result = "(unsigned long)";
break;
default:
result = "/* unknown cast type */";
break;
}
break;
case OP_UNARY_INDIRECTION:
result = "*";
break;
case OP_UNARY_AND:
result = "&";
break;
case OP_PLUS:
result = "+";
break;
case OP_MINUS:
result = "-";
break;
case OP_STAR:
result = "*";
break;
case OP_SLASH:
result = "/";
break;
case OP_MOD:
result = "%";
break;
case OP_LEFT_SHIFT:
result = "<<";
break;
case OP_RIGHT_SHIFT:
result = ">>";
break;
case OP_LESS:
result = "<";
break;
case OP_LESS_EQUAL:
result = "<=";
break;
case OP_GREATER_EQUAL:
result = ">=";
break;
case OP_GREATER:
result = ">";
break;
case OP_EQUAL:
result = "==";
break;
case OP_NOT_EQUAL:
result = "!=";
break;
case OP_AND:
result = "&";
break;
case OP_OR:
result = "|";
break;
case OP_XOR:
result = "^";
break;
case OP_LOGICAL_AND:
result = "&&";
break;
case OP_LOGICAL_OR:
result = "||";
break;
case OP_EXPRESSION:
break;
default:
result = "/*[ERROR] unknown operation */" ;
break;
}
return result;
}
BOOL __fastcall processTransmitRepresentAs(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Inout_ ParamDesc& ParamDesc,
_Inout_ std::list<TypeToDefine>& listAdditionalTypes,
_Inout_ std::ostringstream& oss)
{
BOOL bResult;
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
TransmitRepresentAs_t transmit;
RPC_GET_PROCESS_DATA(pType, &transmit, sizeof(TransmitRepresentAs_t));
RVA_T pTransmittedType = pType + sizeof(TransmitRepresentAs_t) + transmit.transmitted_type_offset - sizeof(transmit.transmitted_type_offset);
oss << "/* data transmitted as */";
ParamDesc.setRva(pTransmittedType);
if( rpcDumpType(pContext, ParamDesc, listAdditionalTypes, oss) == FALSE)
{
RPC_DEBUG_FN("[ERROR] processTransmitRepresentAs : dump type failed \n");
return FALSE;
}
return TRUE;
}
BOOL __fastcall getTransmitAsRepresentAsMemorySize(
_In_ VOID* pContext,
_In_ RVA_T pType,
_Out_ size_t* pszMemorySize)
{
BOOL bResult;
RpcDecompilerCtxt_T * pRpcDecompilerCtxt = (RpcDecompilerCtxt_T *) pContext;
TransmitRepresentAs_t transmit;
RPC_GET_PROCESS_DATA(pType, &transmit, sizeof(TransmitRepresentAs_t));
if(bResult == FALSE)
{
RPC_DEBUG_FN("[ERROR] getTransmitAsRepresentAsMemorySize : unable to get process data\n");
return FALSE;
}
// TODO : check if this is this size and not target size that is used for conformance
*pszMemorySize = transmit.presented_type_memory_size;
return TRUE;
}
UINT getCorrelationDescriptorSize(
_In_ BOOL bRobustFlagWasSet,
_In_ BOOL bHasRangeOnConformance)
{
UINT uSize = 0;
UNREFERENCED_PARAMETER(bRobustFlagWasSet);
if(robustFlagWasSet)
{
uSize = sizeof(CorrelationDescriptorRobust_t);
}
else
{
uSize = sizeof(CorrelationDescriptorNonRobust_t);
}
if(bHasRangeOnConformance)
{
uSize += sizeof(Range_t);
}
return uSize;
}