diff options
| author | Glenn Smith <glenn@vector35.com> | 2024-04-11 15:54:34 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2024-04-11 15:54:34 -0400 |
| commit | 3394019790216360933090478665025216727891 (patch) | |
| tree | 9d0835e90f0d1c55da1cadb54234e38715207cb3 | |
| parent | 62036d41a3e7491e274a5ab4826bdac0522dac1b (diff) | |
Rename lineWidth -> paddingCols in GetTypeLines()
This is a more accurate name for what the parameter actually does. Documentation was improved as well.
| -rw-r--r-- | binaryninjaapi.h | 22 | ||||
| -rw-r--r-- | binaryninjacore.h | 12 | ||||
| -rw-r--r-- | python/typeprinter.py | 30 | ||||
| -rw-r--r-- | python/types.py | 6 | ||||
| -rw-r--r-- | suite/api_test.py | 2 | ||||
| -rw-r--r-- | type.cpp | 4 | ||||
| -rw-r--r-- | typeprinter.cpp | 24 |
7 files changed, 50 insertions, 50 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 4b1a2b25..7b66133c 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -8795,7 +8795,7 @@ namespace BinaryNinja { bool AddTypeMemberTokens(BinaryView* data, std::vector<InstructionTextToken>& tokens, int64_t offset, std::vector<std::string>& nameList, size_t size = 0, bool indirect = false); std::vector<TypeDefinitionLine> GetLines(const TypeContainer& types, const std::string& name, - int lineWidth = 80, bool collapsed = false, BNTokenEscapingType escaping = NoTokenEscapingType); + int paddingCols = 80, bool collapsed = false, BNTokenEscapingType escaping = NoTokenEscapingType); static std::string GetSizeSuffix(size_t size); }; @@ -14800,10 +14800,10 @@ namespace BinaryNinja { static bool GetTypeStringAfterNameCallback(void* ctxt, BNType* type, BNPlatform* platform, BNTokenEscapingType escaping, char** result); static bool GetTypeLinesCallback(void* ctxt, BNType* type, BNTypeContainer* types, - BNQualifiedName* name, int lineWidth, bool collapsed, + BNQualifiedName* name, int paddingCols, bool collapsed, BNTokenEscapingType escaping, BNTypeDefinitionLine** result, size_t* resultCount); static bool PrintAllTypesCallback(void* ctxt, BNQualifiedName* names, BNType** types, size_t typeCount, - BNBinaryView* data, int lineWidth, BNTokenEscapingType escaping, char** result); + BNBinaryView* data, int paddingCols, BNTokenEscapingType escaping, char** result); static void FreeTokensCallback(void* ctxt, BNInstructionTextToken* tokens, size_t count); static void FreeStringCallback(void* ctxt, char* string); static void FreeLinesCallback(void* ctxt, BNTypeDefinitionLine* lines, size_t count); @@ -14915,7 +14915,7 @@ namespace BinaryNinja { \param type Type to print \param types Type Container in which the type is defined \param name Name of the type - \param lineWidth Maximum width of lines, in characters + \param paddingCols Maximum number of bytes represented by each padding line \param collapsed Whether to collapse structure/enum blocks \param escaping Style of escaping literals which may not be parsable \return List of type definition lines @@ -14924,7 +14924,7 @@ namespace BinaryNinja { Ref<Type> type, const TypeContainer& types, const QualifiedName& name, - int lineWidth = 80, + int paddingCols = 80, bool collapsed = false, BNTokenEscapingType escaping = NoTokenEscapingType ) = 0; @@ -14933,14 +14933,14 @@ namespace BinaryNinja { Print all types to a single big string, including headers, sections, etc \param types All types to print \param data Binary View in which all the types are defined - \param lineWidth Maximum width of lines, in characters + \param paddingCols Maximum number of bytes represented by each padding line \param escaping Style of escaping literals which may not be parsable \return All the types in a string */ virtual std::string PrintAllTypes( const std::vector<std::pair<QualifiedName, Ref<Type>>>& types, Ref<BinaryView> data, - int lineWidth = 80, + int paddingCols = 80, BNTokenEscapingType escaping = NoTokenEscapingType ); @@ -14949,14 +14949,14 @@ namespace BinaryNinja { Print all types to a single big string, including headers, sections, etc \param types All types to print \param data Binary View in which all the types are defined - \param lineWidth Maximum width of lines, in characters + \param paddingCols Maximum number of bytes represented by each padding line \param escaping Style of escaping literals which may not be parsable \return All the types in a string */ std::string DefaultPrintAllTypes( const std::vector<std::pair<QualifiedName, Ref<Type>>>& types, Ref<BinaryView> data, - int lineWidth = 80, + int paddingCols = 80, BNTokenEscapingType escaping = NoTokenEscapingType ); }; @@ -14986,10 +14986,10 @@ namespace BinaryNinja { virtual std::string GetTypeStringAfterName(Ref<Type> type, Ref<Platform> platform, BNTokenEscapingType escaping) override; virtual std::vector<TypeDefinitionLine> GetTypeLines(Ref<Type> type, - const TypeContainer& types, const QualifiedName& name, int lineWidth, + const TypeContainer& types, const QualifiedName& name, int paddingCols, bool collapsed, BNTokenEscapingType escaping) override; virtual std::string PrintAllTypes(const std::vector<std::pair<QualifiedName, Ref<Type>>>& types, - Ref<BinaryView> data, int lineWidth, BNTokenEscapingType escaping) override; + Ref<BinaryView> data, int paddingCols, BNTokenEscapingType escaping) override; }; // DownloadProvider diff --git a/binaryninjacore.h b/binaryninjacore.h index 72e5c9a4..68828ce8 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2771,10 +2771,10 @@ extern "C" bool (*getTypeStringAfterName)(void* ctxt, BNType* type, BNPlatform* platform, BNTokenEscapingType escaping, char** result); bool (*getTypeLines)(void* ctxt, BNType* type, BNTypeContainer* types, BNQualifiedName* name, - int lineWidth, bool collapsed, + int paddingCols, bool collapsed, BNTokenEscapingType escaping, BNTypeDefinitionLine** result, size_t* resultCount); bool (*printAllTypes)(void* ctxt, BNQualifiedName* names, BNType** types, size_t typeCount, - BNBinaryView* data, int lineWidth, BNTokenEscapingType escaping, char** result); + BNBinaryView* data, int paddingCols, BNTokenEscapingType escaping, char** result); void (*freeTokens)(void* ctxt, BNInstructionTextToken* tokens, size_t count); void (*freeString)(void* ctxt, char* string); void (*freeLines)(void* ctxt, BNTypeDefinitionLine* lines, size_t count); @@ -5758,7 +5758,7 @@ extern "C" BINARYNINJACOREAPI bool BNAddTypeMemberTokens(BNType* type, BNBinaryView* data, BNInstructionTextToken** tokens, size_t* tokenCount, int64_t offset, char*** nameList, size_t* nameCount, size_t size, bool indirect); - BINARYNINJACOREAPI BNTypeDefinitionLine* BNGetTypeLines(BNType* type, BNTypeContainer* types, const char* name, int lineWidth, bool collapsed, BNTokenEscapingType escaping, size_t* count); + BINARYNINJACOREAPI BNTypeDefinitionLine* BNGetTypeLines(BNType* type, BNTypeContainer* types, const char* name, int paddingCols, bool collapsed, BNTokenEscapingType escaping, size_t* count); BINARYNINJACOREAPI void BNFreeTypeDefinitionLineList(BNTypeDefinitionLine* list, size_t count); BINARYNINJACOREAPI BNQualifiedName BNTypeBuilderGetTypeName(BNTypeBuilder* nt); @@ -6042,12 +6042,12 @@ extern "C" BNType* type, BNPlatform* platform, BNTokenEscapingType escaping, char** result); BINARYNINJACOREAPI bool BNGetTypePrinterTypeLines(BNTypePrinter* printer, BNType* type, BNTypeContainer* types, BNQualifiedName* name, - int lineWidth, bool collapsed, BNTokenEscapingType escaping, + int paddingCols, bool collapsed, BNTokenEscapingType escaping, BNTypeDefinitionLine** result, size_t* resultCount); BINARYNINJACOREAPI bool BNTypePrinterPrintAllTypes(BNTypePrinter* printer, BNQualifiedName* names, BNType** types, - size_t typeCount, BNBinaryView* data, int lineWidth, BNTokenEscapingType escaping, char** result); + size_t typeCount, BNBinaryView* data, int paddingCols, BNTokenEscapingType escaping, char** result); BINARYNINJACOREAPI bool BNTypePrinterDefaultPrintAllTypes(BNTypePrinter* printer, BNQualifiedName* names, BNType** types, - size_t typeCount, BNBinaryView* data, int lineWidth, BNTokenEscapingType escaping, char** result); + size_t typeCount, BNBinaryView* data, int paddingCols, BNTokenEscapingType escaping, char** result); BINARYNINJACOREAPI void BNFreeTypeParserResult(BNTypeParserResult* result); BINARYNINJACOREAPI void BNFreeTypeParserErrors(BNTypeParserError* errors, size_t count); diff --git a/python/typeprinter.py b/python/typeprinter.py index dfddfed4..47793ec3 100644 --- a/python/typeprinter.py +++ b/python/typeprinter.py @@ -221,13 +221,13 @@ class TypePrinter(metaclass=_TypePrinterMetaclass): log_error(traceback.format_exc()) return False - def _get_type_lines(self, ctxt, type, container, name, line_width, collapsed, escaping, result, result_count): + def _get_type_lines(self, ctxt, type, container, name, padding_cols, collapsed, escaping, result, result_count): try: result_py = self.get_type_lines( types.Type.create(handle=core.BNNewTypeReference(type)), typecontainer.TypeContainer(handle=container), types.QualifiedName._from_core_struct(name.contents), - line_width, collapsed, escaping) + padding_cols, collapsed, escaping) TypePrinter._cached_lines = (core.BNTypeDefinitionLine * len(result_py))() for (i, line) in enumerate(result_py): @@ -240,7 +240,7 @@ class TypePrinter(metaclass=_TypePrinterMetaclass): log_error(traceback.format_exc()) return False - def _print_all_types(self, ctxt, names, types_, type_count, data, line_width, escaping, result): + def _print_all_types(self, ctxt, names, types_, type_count, data, padding_cols, escaping, result): try: types_py = [] for i in range(type_count): @@ -252,7 +252,7 @@ class TypePrinter(metaclass=_TypePrinterMetaclass): result_py = self.print_all_types( types_py, binaryview.BinaryView(handle=core.BNNewViewReference(data)), - line_width, escaping) + padding_cols, escaping) TypePrinter._cached_string = core.cstr(result_py) result[0] = TypePrinter._cached_string @@ -288,7 +288,7 @@ class TypePrinter(metaclass=_TypePrinterMetaclass): log_error(traceback.format_exc()) return False - def _default_print_all_types(self, types_: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, line_width = 80, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str: + def _default_print_all_types(self, types_: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, padding_cols = 80, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str: cpp_names = (core.BNQualifiedName * len(types_))() cpp_types = (ctypes.POINTER(core.BNType) * len(types_))() @@ -299,7 +299,7 @@ class TypePrinter(metaclass=_TypePrinterMetaclass): i += 1 result = ctypes.c_char_p() - core.BNTypePrinterDefaultPrintAllTypes(self.handle, cpp_names, cpp_types, len(types_), data.handle, line_width, ctypes.c_int(escaping), result) + core.BNTypePrinterDefaultPrintAllTypes(self.handle, cpp_names, cpp_types, len(types_), data.handle, padding_cols, ctypes.c_int(escaping), result) return core.pyNativeStr(result.value) def get_type_tokens(self, type: types.Type, platform: Optional[_platform.Platform] = None, name: types.QualifiedNameType = "", base_confidence: int = core.max_confidence, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> List[_function.InstructionTextToken]: @@ -379,31 +379,31 @@ class TypePrinter(metaclass=_TypePrinterMetaclass): """ raise NotImplementedError() - def get_type_lines(self, type: types.Type, container: 'typecontainer.TypeContainer', name: types.QualifiedNameType, line_width = 80, collapsed = False, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> List[types.TypeDefinitionLine]: + def get_type_lines(self, type: types.Type, container: 'typecontainer.TypeContainer', name: types.QualifiedNameType, padding_cols = 80, collapsed = False, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> List[types.TypeDefinitionLine]: """ Generate a multi-line representation of a type :param type: Type to print :param container: Type Container containing the type and dependencies :param name: Name of the type - :param line_width: Maximum width of lines, in characters + :param padding_cols: Maximum number of bytes represented by each padding line :param collapsed: Whether to collapse structure/enum blocks :param escaping: Style of escaping literals which may not be parsable :return: List of type definition lines """ raise NotImplementedError() - def print_all_types(self, types: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, line_width = 80, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str: + def print_all_types(self, types: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, padding_cols = 80, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str: """ Print all types to a single big string, including headers, sections, etc :param types: All types to print :param data: Binary View in which all the types are defined - :param line_width: Maximum width of lines, in characters + :param padding_cols: Maximum number of bytes represented by each padding line :param escaping: Style of escaping literals which may not be parsable :return: All the types in a string """ - return self._default_print_all_types(types, data, line_width, escaping) + return self._default_print_all_types(types, data, padding_cols, escaping) class CoreTypePrinter(TypePrinter): @@ -491,14 +491,14 @@ class CoreTypePrinter(TypePrinter): def get_type_lines(self, type: types.Type, container: 'typecontainer.TypeContainer', name: types.QualifiedNameType, - line_width = 80, collapsed = False, + padding_cols = 80, collapsed = False, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType ) -> List[types.TypeDefinitionLine]: if not isinstance(name, types.QualifiedName): name = types.QualifiedName(name) count = ctypes.c_ulonglong() core_lines = ctypes.POINTER(core.BNTypeDefinitionLine)() - if not core.BNGetTypePrinterTypeLines(self.handle, type.handle, container.handle, name._to_core_struct(), line_width, collapsed, ctypes.c_int(escaping), core_lines, count): + if not core.BNGetTypePrinterTypeLines(self.handle, type.handle, container.handle, name._to_core_struct(), padding_cols, collapsed, ctypes.c_int(escaping), core_lines, count): raise RuntimeError("BNGetTypePrinterTypeLines returned False") lines = [] for i in range(count.value): @@ -507,7 +507,7 @@ class CoreTypePrinter(TypePrinter): core.BNFreeTypeDefinitionLineList(core_lines, count.value) return lines - def print_all_types(self, types_: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, line_width = 80, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str: + def print_all_types(self, types_: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, padding_cols = 80, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str: cpp_names = (core.BNQualifiedName * len(types_))() cpp_types = (ctypes.POINTER(core.BNType) * len(types_))() @@ -518,5 +518,5 @@ class CoreTypePrinter(TypePrinter): i += 1 result = ctypes.c_char_p() - core.BNTypePrinterPrintAllTypes(self.handle, cpp_names, cpp_types, len(types_), data.handle, line_width, ctypes.c_int(escaping), result) + core.BNTypePrinterPrintAllTypes(self.handle, cpp_names, cpp_types, len(types_), data.handle, padding_cols, ctypes.c_int(escaping), result) return core.pyNativeStr(result.value) diff --git a/python/types.py b/python/types.py index 57c0824c..e08bc796 100644 --- a/python/types.py +++ b/python/types.py @@ -2005,7 +2005,7 @@ class Type: return result def get_lines( - self, bv: Union['binaryview.BinaryView', 'typecontainer.TypeContainer'], name: str, line_width: int = 80, collapsed: bool = False, + self, bv: Union['binaryview.BinaryView', 'typecontainer.TypeContainer'], name: str, padding_cols: int = 80, collapsed: bool = False, escaping: TokenEscapingType = TokenEscapingType.NoTokenEscapingType ) -> List['TypeDefinitionLine']: """ @@ -2015,7 +2015,7 @@ class Type: :param BinaryView bv: BinaryView object owning this Type :param str name: Displayed name of the Type - :param int line_width: Maximum width of lines (in characters) + :param int padding_cols: Maximum number of bytes represented by each padding line :param bool collapsed: If the type should be collapsed, and not show fields/members :param TokenEscapingType escaping: How to escape non-parsable strings in types :return: Returns a list of :py:class:`TypeDefinitionLine` structures @@ -2028,7 +2028,7 @@ class Type: container = bv else: assert False, "Unexpected type container type" - core_lines = core.BNGetTypeLines(self._handle, container.handle, name, line_width, collapsed, escaping, count) + core_lines = core.BNGetTypeLines(self._handle, container.handle, name, padding_cols, collapsed, escaping, count) assert core_lines is not None, "core.BNGetTypeLines returned None" lines = [] for i in range(count.value): diff --git a/suite/api_test.py b/suite/api_test.py index dfba75ae..7054008a 100644 --- a/suite/api_test.py +++ b/suite/api_test.py @@ -1022,7 +1022,7 @@ class TestTypePrinter(unittest.TestCase): return f" bottom text" def get_type_lines(self, type: types.Type, container: typecontainer.TypeContainer, name: types.QualifiedName, - line_width, collapsed, escaping: TokenEscapingType) -> List[types.TypeDefinitionLine]: + padding_cols, collapsed, escaping: TokenEscapingType) -> List[types.TypeDefinitionLine]: return [ TypeDefinitionLine(TypeDefinitionLineType.TypedefLineType, [ InstructionTextToken(InstructionTextTokenType.TextToken, "the type is: ", 0), @@ -1203,11 +1203,11 @@ bool Type::AddTypeMemberTokens(BinaryView* data, vector<InstructionTextToken>& t std::vector<TypeDefinitionLine> Type::GetLines(const TypeContainer& types, const std::string& name, - int lineWidth, bool collapsed, BNTokenEscapingType escaping) + int paddingCols, bool collapsed, BNTokenEscapingType escaping) { size_t count; BNTypeDefinitionLine* list = - BNGetTypeLines(m_object, types.GetObject(), name.c_str(), lineWidth, collapsed, escaping, &count); + BNGetTypeLines(m_object, types.GetObject(), name.c_str(), paddingCols, collapsed, escaping, &count); std::vector<TypeDefinitionLine> results; for (size_t i = 0; i < count; i++) diff --git a/typeprinter.cpp b/typeprinter.cpp index 036c7c18..3b36da9d 100644 --- a/typeprinter.cpp +++ b/typeprinter.cpp @@ -102,13 +102,13 @@ bool TypePrinter::GetTypeStringAfterNameCallback(void* ctxt, BNType* type, bool TypePrinter::GetTypeLinesCallback(void* ctxt, BNType* type, BNTypeContainer* types, - BNQualifiedName* name, int lineWidth, bool collapsed, + BNQualifiedName* name, int paddingCols, bool collapsed, BNTokenEscapingType escaping, BNTypeDefinitionLine** result, size_t* resultCount) { TypePrinter* printer = (TypePrinter*)ctxt; vector<TypeDefinitionLine> lines = printer->GetTypeLines( new Type(BNNewTypeReference(type)), TypeContainer(types), - QualifiedName::FromAPIObject(name), lineWidth, collapsed, escaping); + QualifiedName::FromAPIObject(name), paddingCols, collapsed, escaping); *resultCount = lines.size(); *result = TypeDefinitionLine::CreateTypeDefinitionLineList(lines); @@ -117,7 +117,7 @@ bool TypePrinter::GetTypeLinesCallback(void* ctxt, BNType* type, BNTypeContainer bool TypePrinter::PrintAllTypesCallback(void* ctxt, BNQualifiedName* names, BNType** types, size_t typeCount, - BNBinaryView* data, int lineWidth, BNTokenEscapingType escaping, char** result) + BNBinaryView* data, int paddingCols, BNTokenEscapingType escaping, char** result) { TypePrinter* printer = (TypePrinter*)ctxt; vector<pair<QualifiedName, Ref<Type>>> apiTypes; @@ -126,7 +126,7 @@ bool TypePrinter::PrintAllTypesCallback(void* ctxt, BNQualifiedName* names, BNTy apiTypes.push_back({QualifiedName::FromAPIObject(&names[i]), new Type(types[i])}); } - string resultStr = printer->PrintAllTypes(apiTypes, new BinaryView(data), lineWidth, escaping); + string resultStr = printer->PrintAllTypes(apiTypes, new BinaryView(data), paddingCols, escaping); *result = BNAllocString(resultStr.c_str()); return true; } @@ -265,18 +265,18 @@ std::string TypePrinter::GetTypeStringAfterName( std::string TypePrinter::PrintAllTypes( const std::vector<std::pair<QualifiedName, Ref<Type>>>& types, Ref<BinaryView> data, - int lineWidth, + int paddingCols, BNTokenEscapingType escaping ) { - return DefaultPrintAllTypes(types, data, lineWidth, escaping); + return DefaultPrintAllTypes(types, data, paddingCols, escaping); } std::string TypePrinter::DefaultPrintAllTypes( const std::vector<std::pair<QualifiedName, Ref<Type>>>& types, Ref<BinaryView> data, - int lineWidth, + int paddingCols, BNTokenEscapingType escaping ) { @@ -291,7 +291,7 @@ std::string TypePrinter::DefaultPrintAllTypes( char* resultStr; BNTypePrinterDefaultPrintAllTypes(m_object, apiNames, apiTypes, types.size(), data->GetObject(), - lineWidth, escaping, &resultStr); + paddingCols, escaping, &resultStr); for (size_t i = 0; i < types.size(); i ++) { @@ -433,7 +433,7 @@ std::string CoreTypePrinter::GetTypeStringAfterName(Ref<Type> type, Ref<Platform std::vector<TypeDefinitionLine> CoreTypePrinter::GetTypeLines(Ref<Type> type, - const TypeContainer& types, const QualifiedName& name, int lineWidth, + const TypeContainer& types, const QualifiedName& name, int paddingCols, bool collapsed, BNTokenEscapingType escaping) { BNTypeDefinitionLine* lines; @@ -442,7 +442,7 @@ std::vector<TypeDefinitionLine> CoreTypePrinter::GetTypeLines(Ref<Type> type, BNQualifiedName qname = name.GetAPIObject(); bool success = BNGetTypePrinterTypeLines(GetObject(), type->GetObject(), types.GetObject(), &qname, - lineWidth, collapsed, escaping, &lines, &lineCount); + paddingCols, collapsed, escaping, &lines, &lineCount); QualifiedName::FreeAPIObject(&qname); if (!success) @@ -464,7 +464,7 @@ std::vector<TypeDefinitionLine> CoreTypePrinter::GetTypeLines(Ref<Type> type, std::string CoreTypePrinter::PrintAllTypes( const std::vector<std::pair<QualifiedName, Ref<Type>>>& types, Ref<BinaryView> data, - int lineWidth, + int paddingCols, BNTokenEscapingType escaping ) { @@ -479,7 +479,7 @@ std::string CoreTypePrinter::PrintAllTypes( char* resultStr; BNTypePrinterPrintAllTypes(m_object, apiNames, apiTypes, types.size(), data->GetObject(), - lineWidth, escaping, &resultStr); + paddingCols, escaping, &resultStr); for (size_t i = 0; i < types.size(); i ++) { |
