MCPcopy Create free account
hub / github.com/bloomberg/pystack / getStringFromAddress

Method getStringFromAddress

src/pystack/_pystack/process.cpp:519–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517}
518
519std::string
520AbstractProcessManager::getStringFromAddress(remote_addr_t addr) const
521{
522 Python2::_PyStringObject string;
523 std::vector<char> buffer;
524 ssize_t len;
525 remote_addr_t data_addr;
526
527 if (d_major == 2) {
528 LOG(DEBUG) << std::hex << std::showbase << "Handling string object of version 2 from address "
529 << addr;
530 copyObjectFromProcess(addr, &string);
531
532 len = string.ob_base.ob_size;
533 buffer.resize(len);
534 data_addr = (remote_addr_t)((char*)addr + offsetof(Python2::_PyStringObject, ob_sval));
535 LOG(DEBUG) << std::hex << std::showbase << "Copying ASCII data for string object from address "
536 << data_addr;
537 copyMemoryFromProcess(data_addr, len, buffer.data());
538 } else {
539 LOG(DEBUG) << std::hex << std::showbase << "Handling unicode object of version 3 from address "
540 << addr;
541 Structure<py_unicode_v> unicode(shared_from_this(), addr);
542
543 AnyPyUnicodeState state = unicode.getField(&py_unicode_v::o_state);
544 if (versionIsAtLeast(3, 14) and isFreeThreaded()) {
545 if (state.python3_14t.kind != 1 || state.python3_14t.compact != 1) {
546 throw InvalidRemoteObject();
547 }
548 } else {
549 if (state.python3.kind != 1 || state.python3.compact != 1) {
550 throw InvalidRemoteObject();
551 }
552 }
553
554 len = unicode.getField(&py_unicode_v::o_length);
555 buffer.resize(len);
556 data_addr = unicode.getFieldRemoteAddress(&py_unicode_v::o_ascii);
557 LOG(DEBUG) << std::hex << std::showbase << "Copying ASCII data for unicode object from address "
558 << data_addr;
559 copyMemoryFromProcess(data_addr, len, buffer.data());
560 }
561 return std::string(buffer.begin(), buffer.end());
562}
563
564// ----------------------------------------------------------------------------
565std::string

Callers 2

toConcreteObjectMethod · 0.80
CodeObjectMethod · 0.80

Calls 3

LOGClass · 0.85
InvalidRemoteObjectClass · 0.85
getFieldRemoteAddressMethod · 0.80

Tested by

no test coverage detected