Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFString Data Renderer #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions DataRenderers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,42 @@ void RelativePointerDataRenderer::Register()
{
DataRendererContainer::RegisterTypeSpecificDataRenderer(new RelativePointerDataRenderer());
}

/* ---- CFString ------------------------------------------------------------ */

bool CFStringDataRenderer::IsValidForData(BinaryView* bv, uint64_t address,
Type* type, DataRendererContext& context)
{
return isType(context, CustomTypes::CFString);
}

std::vector<DisassemblyTextLine> CFStringDataRenderer::GetLinesForData(
BinaryView* bv, uint64_t address, Type*,
const std::vector<InstructionTextToken>& prefix, size_t,
std::vector<std::pair<Type*, size_t>>&)
{
BinaryReader reader(bv);
reader.Seek(address + 0x10);

auto dataPointer = reader.Read64();
auto size = reader.Read64();

// Data pointer can be tagged, need to decode it before jumping to it.
dataPointer = ObjectiveNinja::ABI::decodePointer(dataPointer, bv->GetStart());
reader.Seek(dataPointer);
auto string = reader.ReadString(size);

DisassemblyTextLine line;
line.addr = address;
line.tokens = prefix;
line.tokens.emplace_back(StringToken, "@\"" + string + "\"", dataPointer);
line.tokens.emplace_back(TextToken, ", ");
line.tokens.emplace_back(IntegerToken, std::to_string(size), dataPointer);
Comment on lines +183 to +190

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have StringDataRenderer in the core which should give you line wrapping, etc. for free. It might make more sense to call the string data renderer on the underlying (null-terminated) string, then insert additional tokens as necessary.

(Yes, I know this code is largely pirated from one of my old branches where I didn't do this...)


return { line };
}

void CFStringDataRenderer::Register()
{
DataRendererContainer::RegisterTypeSpecificDataRenderer(new CFStringDataRenderer());
}
18 changes: 18 additions & 0 deletions DataRenderers.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,21 @@ class RelativePointerDataRenderer : public BinaryNinja::DataRenderer {

static void Register();
};

/**
* Data renderer for CFString data variables.
*/
class CFStringDataRenderer : public BinaryNinja::DataRenderer {
CFStringDataRenderer() = default;

public:
bool IsValidForData(BinaryViewPtr, uint64_t address, TypePtr,
DataRendererContext&) override;

std::vector<BinaryNinja::DisassemblyTextLine> GetLinesForData(
BinaryViewPtr, uint64_t address, TypePtr,
const std::vector<BinaryNinja::InstructionTextToken>& prefix,
size_t width, std::vector<std::pair<TypePtr, size_t>>& context) override;

static void Register();
};
1 change: 1 addition & 0 deletions Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ BINARYNINJAPLUGIN bool CorePluginInit()
TaggedPointerDataRenderer::Register();
FastPointerDataRenderer::Register();
RelativePointerDataRenderer::Register();
CFStringDataRenderer::Register();

Workflow::registerActivities();
Commands::registerCommands();
Expand Down