You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. std::string demangle(const std::string& mangled) {
  5. std::string result;
  6. std::vector<std::string> parts;
  7. size_t i = 0;
  8. while (i < mangled.size()) {
  9. if (std::isdigit(mangled[i])) {
  10. // Read length of the following name
  11. size_t length = 0;
  12. while (std::isdigit(mangled[i])) {
  13. length = length * 10 + (mangled[i] - '0');
  14. i++;
  15. }
  16. // Get the name part
  17. std::string name = mangled.substr(i, length);
  18. parts.push_back(name);
  19. i += length;
  20. } else {
  21. // Handle other characters (if needed)
  22. // result += mangled[i];
  23. i++;
  24. }
  25. }
  26. // Join parts with '.'
  27. for (const auto& part : parts) {
  28. if (!result.empty()) {
  29. result += ".";
  30. }
  31. result += part;
  32. }
  33. return result;
  34. }
  35. int main() {
  36. std::string mangledName = "_ZNKiflytop13zscanprotocol16ZSCanProtocolCom7callcmdEiiPhii";
  37. std::string demangledName = demangle(mangledName);
  38. std::cout << "Demangled Name: " << demangledName << std::endl;
  39. return 0;
  40. }