Exemplo n.º 1
0
 def add_call_comment(self, from_addr, to_addr):
     to_func = self.bv.get_function_at(to_addr)
     _, name = demangle.demangle_gnu3(self.bv.arch, to_func.name)
     old_comment = self.caller.get_comment_at(from_addr)
     self.caller.set_comment_at(
         from_addr,
         demangle.get_qualified_name(name) + "\n" + old_comment)
Exemplo n.º 2
0
    def try_unmangle(self, value):
        if value[:2] != b'_Z':
            return (None, value)

        decoded_name = value.decode('ascii')
        demangled_type, demangled_name = demangle_gnu3(Architecture[self.ARCH],
                                                       decoded_name)
        decoded_name = get_qualified_name(demangled_name)
        return (demangled_type, decoded_name)
Exemplo n.º 3
0
    def test_demangle_gnu3(self):
        tests = (
            "__ZN15BinaryNinjaCore12BinaryReader5Read8Ev",
            "__ZN5QListIP18QAbstractAnimationE18detach_helper_growEii",
            "__ZN13QStatePrivate22emitPropertiesAssignedEv",
            "__ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI14QItemSelectionLb1EE9ConstructEPvPKv",
            "__ZN18QSharedDataPointerI16QFileInfoPrivateE4dataEv",
            "__ZN26QAbstractNativeEventFilterD2Ev",
            "__ZN5QListIP14QAbstractStateE3endEv",
            "__ZNK15BinaryNinjaCore19ArchitectureWrapper22GetOpcodeDisplayLengthEv",
            "__ZN15BinaryNinjaCore17ScriptingInstance19SetCurrentSelectionEyy",
            "__ZL32qt_meta_stringdata_QHistoryState",
            "__ZN12_GLOBAL__N_114TypeDestructor14DestructorImplI11QStringListLb1EE8DestructEiPv",
            "__ZN13QGb18030Codec5_nameEv", "__ZN5QListIP7QObjectE6detachEv",
            "__ZN19QBasicAtomicPointerI9QFreeListI13QMutexPrivateN12_GLOBAL__N_117FreeListConstantsEEE17testAndSetReleaseEPS4_S6_",
            "__ZN12QJsonPrivate6Parser12reserveSpaceEi",
            "__ZN20QStateMachinePrivate12endMacrostepEb",
            "__ZN14QScopedPointerI20QTemporaryDirPrivate21QScopedPointerDeleterIS0_EED2Ev",
            "__ZN14QVariantIsNullIN12_GLOBAL__N_115CoreTypesFilterEE8delegateI10QMatrix4x4EEbPKT_",
            "__ZN26QAbstractProxyModelPrivateC2Ev",
            "__ZNSt3__110__function6__funcIZ26BNWorkerInteractiveEnqueueE4$_16NS_9allocatorIS2_EEFvvEEclEv"
        )

        results = (
            "int32_t BinaryNinjaCore::BinaryReader::Read8()",
            "int32_t QList<QAbstractAnimation*>::detach_helper_grow(int32_t, int32_t)",
            "int32_t QStatePrivate::emitPropertiesAssigned()",
            "int32_t QtMetaTypePrivate::QMetaTypeFunctionHelper<QItemSelection, true>::Construct(void*, void const*)",
            "int32_t QSharedDataPointer<QFileInfoPrivate>::data()",
            "void QAbstractNativeEventFilter::~QAbstractNativeEventFilter()",
            "int32_t QList<QAbstractState*>::end()",
            "int32_t BinaryNinjaCore::ArchitectureWrapper::GetOpcodeDisplayLength() const",
            "int32_t BinaryNinjaCore::ScriptingInstance::SetCurrentSelection(uint64_t, uint64_t)",
            "qt_meta_stringdata_QHistoryState",
            "int32_t (anonymous namespace)::TypeDestructor::DestructorImpl<QStringList, true>::Destruct(int32_t, void*)",
            "int32_t QGb18030Codec::_name()",
            "int32_t QList<QObject*>::detach()",
            "int32_t QBasicAtomicPointer<QFreeList<QMutexPrivate, (anonymous namespace)::FreeListConstants> >::testAndSetRelease(QFreeList<QMutexPrivate, (anonymous namespace)::FreeListConstants>*, QFreeList<QMutexPrivate, (anonymous namespace)::FreeListConstants>*)",
            "int32_t QJsonPrivate::Parser::reserveSpace(int32_t)",
            "int32_t QStateMachinePrivate::endMacrostep(bool)",
            "void QScopedPointer<QTemporaryDirPrivate, QScopedPointerDeleter<QTemporaryDirPrivate> >::~QScopedPointer()",
            "bool QVariantIsNull<(anonymous namespace)::CoreTypesFilter>::delegate<QMatrix4x4>(QMatrix4x4 const*)",
            "void QAbstractProxyModelPrivate::QAbstractProxyModelPrivate()",
            "int32_t std::__1::__function::__func<BNWorkerInteractiveEnqueue::$_16, std::__1::allocator<BNWorkerInteractiveEnqueue::$_16>, void ()>::operator()()"
        )

        for i, test in enumerate(tests):
            t, n = demangle_gnu3(Architecture['x86'], test)
            assert self.get_type_string(t, n) == results[i]
Exemplo n.º 4
0
def demangle_name(bv, name, max_size=64):
    res = name
    if bv.platform.name.startswith("linux-") or bv.platform.name.startswith(
            "mac-"):
        _, demangled = demangle.demangle_gnu3(bv.arch, name)
        if not isinstance(demangled, list):
            res = demangled
        else:
            res = demangle.simplify_name_to_string(
                demangle.get_qualified_name(demangled))
    elif bv.platform.name.startswith("windows-"):
        _, demangled = demangle.demangle_ms(bv.arch, name)
        if not isinstance(demangled, list):
            res = demangled
        else:
            res = demangle.simplify_name_to_string(
                demangle.get_qualified_name(demangled))

    if len(res) > max_size:
        res = res[:max_size // 2 - 3] + "..." + res[-max_size // 2:]
    return res