@@ -976,73 +976,11 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
976
976
break ;
977
977
978
978
case HLIL_CALL:
979
- [&]() {
980
- const auto destExpr = instr.GetDestExpr <HLIL_CALL>();
981
- const auto parameterExprs = instr.GetParameterExprs <HLIL_CALL>();
982
-
983
- GetExprTextInternal (destExpr, tokens, settings, MemberAndFunctionOperatorPrecedence);
984
- tokens.AppendOpenParen ();
985
-
986
- vector<FunctionParameter> namedParams;
987
- Ref<Type> functionType = instr.GetDestExpr <HLIL_CALL>().GetType ();
988
- if (functionType && (functionType->GetClass () == PointerTypeClass)
989
- && (functionType->GetChildType ()->GetClass () == FunctionTypeClass))
990
- namedParams = functionType->GetChildType ()->GetParameters ();
991
-
992
- for (size_t index {}; index < parameterExprs.size (); index ++)
993
- {
994
- const auto & parameterExpr = parameterExprs[index ];
995
- if (index != 0 ) tokens.Append (TextToken, " , " );
996
-
997
- // If the type of the parameter is known to be a pointer to a string, then we directly render it as a
998
- // string, regardless of its length
999
- bool renderedAsString = false ;
1000
- if (index < namedParams.size () && parameterExprs[index ].operation == HLIL_CONST_PTR)
1001
- {
1002
- auto exprType = namedParams[index ].type ;
1003
- if (exprType && (exprType->GetClass () == PointerTypeClass))
1004
- {
1005
- if (auto child = exprType->GetChildType (); child)
1006
- {
1007
- if ((child->IsInteger () && child->IsSigned () && child->GetWidth () == 1 )
1008
- || child->IsWideChar ())
1009
- {
1010
- tokens.AppendPointerTextToken (parameterExprs[index ],
1011
- parameterExprs[index ].GetConstant <HLIL_CONST_PTR>(), settings, AddressOfDataSymbols,
1012
- precedence, true );
1013
- renderedAsString = true ;
1014
- }
1015
- }
1016
- }
1017
- }
1018
-
1019
- if (!renderedAsString)
1020
- GetExprText (parameterExpr, tokens, settings);
1021
- }
1022
- tokens.AppendCloseParen ();
1023
- if (statement)
1024
- tokens.AppendSemicolon ();
1025
- }();
979
+ GetExpr_CALL_OR_TAILCALL (instr, tokens, settings, precedence, statement);
1026
980
break ;
1027
981
1028
982
case HLIL_IMPORT:
1029
- [&]() {
1030
- const auto constant = instr.GetConstant <HLIL_IMPORT>();
1031
- auto symbol = GetHighLevelILFunction ()->GetFunction ()->GetView ()->GetSymbolByAddress (constant);
1032
- const auto symbolType = symbol->GetType ();
1033
-
1034
- if (symbol && (symbolType == ImportedDataSymbol || symbolType == ImportAddressSymbol))
1035
- {
1036
- symbol = Symbol::ImportedFunctionFromImportAddressSymbol (symbol, constant);
1037
- const auto symbolShortName = symbol->GetShortName ();
1038
- tokens.Append (IndirectImportToken, NoTokenContext, symbolShortName, instr.address , constant, instr.size , instr.sourceOperand );
1039
- return ;
1040
- }
1041
-
1042
- tokens.AppendPointerTextToken (instr, constant, settings, DereferenceNonDataSymbols, precedence);
1043
- if (statement)
1044
- tokens.AppendSemicolon ();
1045
- }();
983
+ GetExpr_IMPORT (instr, tokens, settings, precedence, statement);
1046
984
break ;
1047
985
1048
986
case HLIL_ARRAY_INDEX:
@@ -1288,12 +1226,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
1288
1226
break ;
1289
1227
1290
1228
case HLIL_CONST_PTR:
1291
- [&]() {
1292
- tokens.AppendPointerTextToken (
1293
- instr, instr.GetConstant <HLIL_CONST_PTR>(), settings, AddressOfDataSymbols, precedence);
1294
- if (statement)
1295
- tokens.AppendSemicolon ();
1296
- }();
1229
+ GetExpr_CONST_PTR (instr, tokens, settings, precedence, statement);
1297
1230
break ;
1298
1231
1299
1232
case HLIL_VAR:
@@ -1766,17 +1699,8 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
1766
1699
tokens.Append (AnnotationToken, " /* tailcall */" );
1767
1700
tokens.NewLine ();
1768
1701
tokens.Append (KeywordToken, " return " );
1769
- GetExprTextInternal (destExpr, tokens, settings, MemberAndFunctionOperatorPrecedence);
1770
- tokens.AppendOpenParen ();
1771
- for (size_t index {}; index < parameterExprs.size (); index ++)
1772
- {
1773
- const auto & parameterExpr = parameterExprs[index ];
1774
- if (index != 0 ) tokens.Append (TextToken, " , " );
1775
- GetExprTextInternal (parameterExpr, tokens, settings);
1776
- }
1777
- tokens.AppendCloseParen ();
1778
- if (statement)
1779
- tokens.AppendSemicolon ();
1702
+
1703
+ GetExpr_CALL_OR_TAILCALL (instr, tokens, settings, precedence, statement);
1780
1704
}();
1781
1705
break ;
1782
1706
@@ -2800,6 +2724,88 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
2800
2724
}
2801
2725
}
2802
2726
2727
+ void PseudoCFunction::GetExpr_CALL_OR_TAILCALL (const BinaryNinja::HighLevelILInstruction& instr,
2728
+ BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings,
2729
+ BNOperatorPrecedence precedence, bool statement)
2730
+ {
2731
+ const auto destExpr = instr.GetDestExpr ();
2732
+ const auto parameterExprs = instr.GetParameterExprs ();
2733
+
2734
+ vector<FunctionParameter> namedParams;
2735
+ Ref<Type> functionType = destExpr.GetType ();
2736
+ if (functionType && (functionType->GetClass () == PointerTypeClass)
2737
+ && (functionType->GetChildType ()->GetClass () == FunctionTypeClass))
2738
+ namedParams = functionType->GetChildType ()->GetParameters ();
2739
+
2740
+ GetExprTextInternal (destExpr, tokens, settings, MemberAndFunctionOperatorPrecedence);
2741
+ tokens.AppendOpenParen ();
2742
+
2743
+ for (size_t index {}; index < parameterExprs.size (); index ++)
2744
+ {
2745
+ const auto & parameterExpr = parameterExprs[index ];
2746
+ if (index != 0 )
2747
+ tokens.Append (TextToken, " , " );
2748
+
2749
+ // If the type of the parameter is known to be a pointer to a string, then we directly render it as a
2750
+ // string, regardless of its length
2751
+ bool renderedAsString = false ;
2752
+ if (index < namedParams.size () && parameterExprs[index ].operation == HLIL_CONST_PTR)
2753
+ {
2754
+ auto exprType = namedParams[index ].type ;
2755
+ if (exprType && (exprType->GetClass () == PointerTypeClass))
2756
+ {
2757
+ if (auto child = exprType->GetChildType (); child)
2758
+ {
2759
+ if ((child->IsInteger () && child->IsSigned () && child->GetWidth () == 1 ) || child->IsWideChar ())
2760
+ {
2761
+ tokens.AppendPointerTextToken (parameterExprs[index ],
2762
+ parameterExprs[index ].GetConstant <HLIL_CONST_PTR>(), settings, AddressOfDataSymbols,
2763
+ precedence, true );
2764
+ renderedAsString = true ;
2765
+ }
2766
+ }
2767
+ }
2768
+ }
2769
+
2770
+ if (!renderedAsString)
2771
+ GetExprText (parameterExpr, tokens, settings);
2772
+ }
2773
+ tokens.AppendCloseParen ();
2774
+ if (statement)
2775
+ tokens.AppendSemicolon ();
2776
+ }
2777
+
2778
+ void PseudoCFunction::GetExpr_CONST_PTR (const BinaryNinja::HighLevelILInstruction& instr,
2779
+ BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings,
2780
+ BNOperatorPrecedence precedence, bool statement)
2781
+ {
2782
+ auto constant = instr.GetConstant <HLIL_CONST_PTR>();
2783
+ tokens.AppendPointerTextToken (
2784
+ instr, instr.GetConstant <HLIL_CONST_PTR>(), settings, AddressOfDataSymbols, precedence);
2785
+ if (statement)
2786
+ tokens.AppendSemicolon ();
2787
+ }
2788
+
2789
+ void PseudoCFunction::GetExpr_IMPORT (const BinaryNinja::HighLevelILInstruction& instr,
2790
+ BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings,
2791
+ BNOperatorPrecedence precedence, bool statement)
2792
+ {
2793
+ const auto constant = instr.GetConstant <HLIL_IMPORT>();
2794
+ auto symbol = GetHighLevelILFunction ()->GetFunction ()->GetView ()->GetSymbolByAddress (constant);
2795
+ const auto symbolType = symbol->GetType ();
2796
+
2797
+ if (symbol && (symbolType == ImportedDataSymbol || symbolType == ImportAddressSymbol))
2798
+ {
2799
+ symbol = Symbol::ImportedFunctionFromImportAddressSymbol (symbol, constant);
2800
+ const auto symbolShortName = symbol->GetShortName ();
2801
+ tokens.Append (IndirectImportToken, NoTokenContext, symbolShortName, instr.address , constant, instr.size , instr.sourceOperand );
2802
+ return ;
2803
+ }
2804
+
2805
+ tokens.AppendPointerTextToken (instr, constant, settings, DereferenceNonDataSymbols, precedence);
2806
+ if (statement)
2807
+ tokens.AppendSemicolon ();
2808
+ }
2803
2809
2804
2810
string PseudoCFunction::GetAnnotationStartString () const
2805
2811
{
@@ -2819,32 +2825,12 @@ PseudoCFunctionType::PseudoCFunctionType(): LanguageRepresentationFunctionType("
2819
2825
{
2820
2826
}
2821
2827
2828
+ PseudoCFunctionType::PseudoCFunctionType (const string& name) : LanguageRepresentationFunctionType(name) {}
2822
2829
2823
2830
Ref<LanguageRepresentationFunction> PseudoCFunctionType::Create (Architecture* arch, Function* owner,
2824
2831
HighLevelILFunction* highLevelILFunction)
2825
2832
{
2826
2833
return new PseudoCFunction (this , arch, owner, highLevelILFunction);
2827
2834
}
2828
2835
2829
-
2830
- extern " C"
2831
2836
{
2832
- BN_DECLARE_CORE_ABI_VERSION
2833
-
2834
- #ifndef DEMO_EDITION
2835
- BINARYNINJAPLUGIN void CorePluginDependencies ()
2836
- {
2837
- }
2838
- #endif
2839
-
2840
- #ifdef DEMO_EDITION
2841
- bool PseudoCPluginInit ()
2842
- #else
2843
- BINARYNINJAPLUGIN bool CorePluginInit ()
2844
- #endif
2845
- {
2846
- LanguageRepresentationFunctionType* type = new PseudoCFunctionType ();
2847
- LanguageRepresentationFunctionType::Register (type);
2848
- return true ;
2849
- }
2850
- }
0 commit comments