Skip to content

Commit

Permalink
Rename lineWidth -> paddingCols in GetTypeLines()
Browse files Browse the repository at this point in the history
This is a more accurate name for what the parameter actually does. Documentation was improved as well.
  • Loading branch information
CouleeApps committed Apr 11, 2024
1 parent 62036d4 commit 3394019
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
22 changes: 11 additions & 11 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
);

Expand All @@ -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
);
};
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions python/typeprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ def _get_type_string_after_name(self, ctxt, type, platform, escaping, result):
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):
Expand All @@ -240,7 +240,7 @@ def _get_type_lines(self, ctxt, type, container, name, line_width, collapsed, es
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):
Expand All @@ -252,7 +252,7 @@ def _print_all_types(self, ctxt, names, types_, type_count, data, line_width, es
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
Expand Down Expand Up @@ -288,7 +288,7 @@ def _free_lines(self, ctxt, lines, count):
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_))()

Expand All @@ -299,7 +299,7 @@ def _default_print_all_types(self, types_: List[Tuple[types.QualifiedNameType, t
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]:
Expand Down Expand Up @@ -379,31 +379,31 @@ def get_type_string_after_name(self, type: types.Type, platform: Optional[_platf
"""
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):
Expand Down Expand Up @@ -491,14 +491,14 @@ def get_type_string_after_name(self, type: types.Type, platform: Optional[_platf

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):
Expand All @@ -507,7 +507,7 @@ def get_type_lines(self, type: types.Type, container: 'typecontainer.TypeContain
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_))()

Expand All @@ -518,5 +518,5 @@ def print_all_types(self, types_: List[Tuple[types.QualifiedNameType, types.Type
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)
6 changes: 3 additions & 3 deletions python/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ def get_tokens_after_name(
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']:
"""
Expand All @@ -2015,7 +2015,7 @@ def get_lines(
: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
Expand All @@ -2028,7 +2028,7 @@ def get_lines(
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):
Expand Down
2 changes: 1 addition & 1 deletion suite/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ def get_type_string_after_name(self, type: types.Type, platform: Optional[Platfo
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),
Expand Down
4 changes: 2 additions & 2 deletions type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
Loading

0 comments on commit 3394019

Please sign in to comment.