| 517 | } |
| 518 | |
| 519 | std::string |
| 520 | AbstractProcessManager::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 | // ---------------------------------------------------------------------------- |
| 565 | std::string |
no test coverage detected