From 358e0ae8c7a2bf8d0483822b0e894f99eda128f7 Mon Sep 17 00:00:00 2001 From: Ada Freya Ahmed <614231+neptuwunium@users.noreply.github.com> Date: Mon, 9 Nov 2026 15:54:16 +0530 Subject: [PATCH 1/3] Tuanjie Pass 1a --- source/windows/windows_impl.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/windows/windows_impl.cpp b/source/windows/windows_impl.cpp index 2d64fd7..c7b1c70 100644 --- a/source/windows/windows_impl.cpp +++ b/source/windows/windows_impl.cpp @@ -17,7 +17,10 @@ namespace for (const auto &module : { L"UnityPlayer.dll", L"Unity.dll", - L"Unity.exe" + L"Unity.exe", + L"TuanjiePlayer.dll", + L"Tuanjie.dll", + L"Tuanjie.exe" }) { const auto hModule = GetModuleHandleW(module); @@ -166,14 +169,14 @@ namespace const auto unityModuleName = std::filesystem::path(unityModuleFilepath.get()).filename().string(); // UnityPlayer.dll is either Runtime or RuntimeDev - if (unityModuleName == "UnityPlayer.dll") + if (unityModuleName == "UnityPlayer.dll" || unityModuleName == "TuanjiePlayer.dll") { return Variant::Runtime; } // Unity.dll is always the editor // (Unity.exe is checked in the executable check) - if (unityModuleName == "Unity.dll") + if (unityModuleName == "Unity.dll" || unityModuleName == "Tuanjie.dll") { return Variant::Editor; } From e191903861188b17d12334b349e6b79b197684eb Mon Sep 17 00:00:00 2001 From: Ada Freya Ahmed <614231+neptuwunium@users.noreply.github.com> Date: Mon, 9 Nov 2026 15:55:44 +0530 Subject: [PATCH 2/3] Tuanjie Pass 1b --- source/common.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/common.hpp b/source/common.hpp index 2f06156..6fc50ab 100644 --- a/source/common.hpp +++ b/source/common.hpp @@ -62,6 +62,7 @@ inline std::optional ExecutableNameToVariant(const std::string_view nam constexpr std::array kExecutableVariants = { std::make_tuple("Unity.exe", Variant::Editor), std::make_tuple("Unity.com", Variant::Editor), + std::make_tuple("Tuanjie.exe", Variant::Editor), }; for (const auto& [executableName, variant] : kExecutableVariants) From 494f1449ad9fbc66c269fd0d34c0c0322f664660 Mon Sep 17 00:00:00 2001 From: Ada Freya Ahmed Date: Mon, 9 Nov 2026 19:26:19 +0530 Subject: [PATCH 3/3] Tuanjie pass 2 --- source/GenerateTypeTreeTransfer.hpp | 43 ++++----- source/Object.hpp | 9 +- source/binary_output.hpp | 4 +- source/dumper.hpp | 17 +++- source/linux/linux_impl.cpp | 133 +++++++++++++++++++++++++++- 5 files changed, 175 insertions(+), 31 deletions(-) diff --git a/source/GenerateTypeTreeTransfer.hpp b/source/GenerateTypeTreeTransfer.hpp index 72074eb..e55afd4 100644 --- a/source/GenerateTypeTreeTransfer.hpp +++ b/source/GenerateTypeTreeTransfer.hpp @@ -27,7 +27,7 @@ class GenerateTypeTreeTransfer : public TransferBase GenerateTypeTreeTransfer(TypeTree &t, TransferInstructionFlags options, void *objectPtr, int32_t objectDataSize) : m_TypeTree(t), m_ActiveFather(nullptr), - m_ObjectPtr(static_cast(objectPtr)), + m_ObjectPtr((char*)(objectPtr)), m_ObjectSize(objectDataSize) { this->m_Flags = options; @@ -45,28 +45,29 @@ class GenerateTypeTreeTransfer : public TransferBase DEFINE_REVISION(class, GenerateTypeTreeTransfer, Revision::V5_0_0) : public TransferBase { - TypeTree &m_TypeTree; - TypeTreeIterator m_ActiveFather; - char *m_ObjectPtr; - int32_t m_ObjectSize; - char *m_ScriptingObjectPtr = nullptr; - int32_t m_ScriptingObjectSize = 0; - int32_t m_Index = 0; - int32_t m_SimulatedByteOffset = 0; - bool m_DidErrorAlignment = false; - bool m_RequireTypelessData = false; + // i'm lazy and they refactored the entire thing :) + // size grew by about 0x30 bytes + uint8_t blob[0xc8]; public: - GenerateTypeTreeTransfer(TypeTree &t, TransferInstructionFlags options, void *objectPtr, int32_t objectDataSize) : - m_TypeTree(t), - m_ActiveFather(nullptr, nullptr, 0), - m_ObjectPtr(static_cast(objectPtr)), - m_ObjectSize(objectDataSize) + GenerateTypeTreeTransfer(TypeTree *t, TransferInstructionFlags options, void *objectPtr, int32_t objectDataSize) { - this->m_Flags = options; + memset(blob, 0, sizeof(blob)); - if (t.GetData()) - { - t.GetData()->SetGenerationFlags(options); - } + *reinterpret_cast((char*)(this) + 0x5c) = 0x4d; + *reinterpret_cast((char*)(this) + 0x64) = -1; + *((char*)(this) + 0x50) = 0x18; + *((char*)(this) + 0x58) = 1; + *reinterpret_cast((char*)(this) + 0x80) = reinterpret_cast(t); + *reinterpret_cast((char*)(this) + 8) = objectPtr; + *reinterpret_cast((char*)(this) + 0xa8) = objectDataSize; + *reinterpret_cast((char*)(this) + 0xb0) = options; + } + + virtual int64_t GetCachePosition() { + return -1; + } + + virtual void Skip(uint64_t n) { + *((char*)(this) + 0xcd) = 0; } }; diff --git a/source/Object.hpp b/source/Object.hpp index cbe9198..f8bb3dd 100644 --- a/source/Object.hpp +++ b/source/Object.hpp @@ -597,16 +597,23 @@ DEFINE_REVISION_VARIANT(class, Object, Revision::V2022_2_0, Variant::RuntimeDev) virtual void VirtualRedirectTransfer(class SafeBinaryRead &) = 0; }; -DEFINE_REVISION_VARIANT(class, Object, Revision::V2022_2_0, Variant::Editor) +DEFINE_REVISION_VARIANT(class, Object, Revision::V2022_3_0, Variant::Editor) { using RTTI = ::RTTI; using GenerateTypeTreeTransfer = ::GenerateTypeTreeTransfer; public: virtual ~Object() = 0; + virtual void SetIsDone(bool) = 0; + virtual bool IsDone() = 0; + virtual void SetCompleted(bool) = 0; + virtual bool IsCompleted() = 0; + virtual void* GetOrCreate_THX_Proxy() = 0; + virtual void Create_THX_Proxy() = 0; virtual void MainThreadCleanup() = 0; virtual void AwakeFromLoad(AwakeFromLoadMode) = 0; virtual void AwakeFromLoadThreaded() = 0; virtual void CheckConsistency() = 0; + virtual void SetObjectReadyForUpdate() = 0; virtual void Reset() = 0; virtual void SmartReset() = 0; virtual bool IsAScriptedObject() = 0; diff --git a/source/binary_output.hpp b/source/binary_output.hpp index 0402b43..e0a37f6 100644 --- a/source/binary_output.hpp +++ b/source/binary_output.hpp @@ -412,7 +412,7 @@ class DumpedTypeTreeWriter #undef IF_HAS_ENUM_FLAG public: - void Add(const RTTI* rtti, const TypeTree& tree, const TransferInstructionFlags& flags, char const* commonStringBuffer) + void Add(const RTTI* rtti, const TypeTree& tree, const TransferInstructionFlags& flags, char const* commonStringBuffer, void* object) { DumpedTypeTree dumpedTree{}; @@ -420,7 +420,7 @@ class DumpedTypeTreeWriter ConvertTransferInstructionFlags(flags, dumpedTree.TransferFlags); - if (!rtti->isAbstract && rtti->factory) + if (!rtti->isAbstract && rtti->factory && object) { const auto stringBuffer = tree.StringsBuffer(); const auto nodes = tree.Nodes(); diff --git a/source/dumper.hpp b/source/dumper.hpp index 47a88c6..1e46727 100644 --- a/source/dumper.hpp +++ b/source/dumper.hpp @@ -106,6 +106,9 @@ class Dumper : public IDumper if ((x.Protection & ExecutableSection::kSectionProtectionRead) == 0) return false; + if (x.Data.size() < sizeof(RuntimeTypeArray)) + return false; + return true; })) { @@ -145,6 +148,7 @@ class Dumper : public IDumper } } + PlatformImpl.DebugLog("Failed to find common string buffer"); return nullptr; } public: @@ -169,14 +173,19 @@ class Dumper : public IDumper TypeTreeShareableData data(label); TypeTree tree(&data, label); + Object * object = nullptr; if (!pRTTI->isAbstract && pRTTI->factory) { - Object *object = pRTTI->factory(label, kCreateObjectDefault); - GenerateTypeTreeTransfer transfer(tree, flags, object, pRTTI->size); - object->VirtualRedirectTransfer(transfer); + object = pRTTI->factory(label, kCreateObjectDefault); + // "THX_Proxy" (what is this) can't be created, so it returns nothing. + // but it also is not abstract, curious! + if (object) { + GenerateTypeTreeTransfer transfer(&tree, flags, object, pRTTI->size); + object->VirtualRedirectTransfer(transfer); + } } - Writer.Add(pRTTI, tree, flags, pTable); + Writer.Add(pRTTI, tree, flags, pTable, object); } PlatformImpl.DebugLog("Dumped types, now writing to file"); diff --git a/source/linux/linux_impl.cpp b/source/linux/linux_impl.cpp index 83441c7..673c0ae 100644 --- a/source/linux/linux_impl.cpp +++ b/source/linux/linux_impl.cpp @@ -1,7 +1,134 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include #include +#include + +#include "common.hpp" +#include "executable.hpp" +#include "dumper.hpp" -int main() +template +class LinuxDumper { - std::cout << "not implemented :(" << "\n"; - return -1; +public: + std::span GetExecutableSections() + { + if (CachedSections.empty()) + { + struct ElfInfo { + std::span Sections; + uintptr_t BaseAddress{}; + }; + ElfInfo libraryInfo{}; + + const auto findResult = dl_iterate_phdr([](dl_phdr_info* info, size_t size, void* context) -> int { + if (info->dlpi_name[0] == 0 || + std::string_view(info->dlpi_name).ends_with("/UnityPlayer.so") || std::string_view(info->dlpi_name).ends_with("/TuanjiePlayer.so")) { + const auto result = static_cast(context); + result->Sections = std::span(info->dlpi_phdr, info->dlpi_phnum); + result->BaseAddress = info->dlpi_addr; + return true; + } + + return false; + }, &libraryInfo); + + if (!findResult) { + DebugLog("Failed to find unity :("); + return {}; + } + + for (const auto& phdr : libraryInfo.Sections) { + const auto base = phdr.p_vaddr + libraryInfo.BaseAddress; + const auto size = phdr.p_memsz; + + auto protection = 0; + if (phdr.p_flags & PF_R) + protection |= ExecutableSection::kSectionProtectionRead; + + if (phdr.p_flags & PF_W) + protection |= ExecutableSection::kSectionProtectionWrite; + + if (phdr.p_flags & PF_X) + protection |= ExecutableSection::kSectionProtectionExecute; + + CachedSections.emplace_back(std::span(reinterpret_cast(base), size), protection); + } + } + + return CachedSections; + } + + static std::ofstream CreateOutputFile(char const *filename) + { + // Create the output file in the current directory. + // NOTE: Should this be made configurable? i.e. through an environment variable? + const auto path = std::filesystem::current_path() / filename; + dprintf(2, "[TypeTreeRipper] writing '%s'", path.c_str()); + return std::ofstream(path, std::ios::out | std::ios::binary); + } + + static void DebugLog(char const *message) + { + dprintf(2, "[TypeTreeRipper] %s\n", message); + } +private: + std::vector CachedSections; +}; + +typedef int (*orig_vfprintf_type)(FILE *stream, const char *format, va_list ap); + +static Revision CachedRevision = Revision::Count; + +int vfprintf(FILE *stream, const char *format, va_list ap) { + orig_vfprintf_type orig_vfprintf = (orig_vfprintf_type)dlsym(RTLD_NEXT, "vfprintf"); + + char tmp_buffer[0x100]; + va_list cap; + va_copy(cap, ap); + vsnprintf(tmp_buffer, sizeof(tmp_buffer), format, cap); + va_end(cap); + tmp_buffer[0xff] = 0; + // "engine version:" -> Runtime: Version + // "Editor version:" -> Editor: version + // is there a better way?? + if (CachedRevision == Revision::Count && strstr(tmp_buffer, "engine version:")) { + const auto str = std::string(tmp_buffer); + if (const auto parsedRevision = VersionStringToRevision(str.substr(str.find(':') + 1)); parsedRevision.has_value()) + { + CachedRevision = parsedRevision.value(); + RunDumper(CachedRevision, Variant::Runtime); + // this is likely too early. + dprintf(2, "[TypeTreeRipper] parsed runtime revision"); + raise(SIGKILL); + } else { + dprintf(2, "[TypeTreeRipper] failed to parse revision"); + } + } else if (CachedRevision == Revision::Count && strstr(tmp_buffer, "Editor version:")) { + const auto str = std::string(tmp_buffer); + if (const auto parsedRevision = VersionStringToRevision(str.substr(str.find(':') + 1)); parsedRevision.has_value()) + { + CachedRevision = parsedRevision.value(); + dprintf(2, "[TypeTreeRipper] parsed editor revision"); + } else { + dprintf(2, "[TypeTreeRipper] failed to parse revision"); + } + } + + // note: this is late, it also re-initializes managers which can crash unity if it happens during mono reset + // luckily this needle is printed after that + if (CachedRevision != Revision::Count && strstr(tmp_buffer, "Finished resetting the current domain")) { + RunDumper(CachedRevision, Variant::Editor); + raise(SIGKILL); + } + + return orig_vfprintf(stream, format, ap); }