Update ustar functions

This commit is contained in:
Alex 2023-05-22 01:48:10 +03:00
parent fedccbfd79
commit 3d93f9d919
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
3 changed files with 28 additions and 6 deletions

View File

@ -76,15 +76,29 @@ namespace VirtualFileSystem
.Seek = USTAR_Seek, .Seek = USTAR_Seek,
}; };
USTAR::USTAR(uintptr_t Address, Virtual *vfs_ctx) bool USTAR::TestArchive(uintptr_t Address)
{ {
trace("Initializing USTAR with address %#llx", Address); if (!Memory::Virtual().Check((void *)Address))
{
error("Address %#lx is not mapped!", Address);
return false;
}
if (memcmp(((FileHeader *)(uintptr_t)Address)->signature, "ustar", 5) != 0) if (memcmp(((FileHeader *)(uintptr_t)Address)->signature, "ustar", 5) != 0)
{ {
error("ustar signature invalid!"); error("ustar signature invalid!");
return; return false;
} }
return true;
}
void USTAR::ReadArchive(uintptr_t Address, Virtual *vfs_ctx)
{
trace("Initializing USTAR with address %#llx", Address);
if (!this->TestArchive(Address))
return; /* Check whether the archive is deflated */
debug("USTAR signature valid! Name:%s Signature:%s Mode:%c Size:%lu", debug("USTAR signature valid! Name:%s Signature:%s Mode:%c Size:%lu",
((FileHeader *)Address)->name, ((FileHeader *)Address)->name,
((FileHeader *)Address)->signature, ((FileHeader *)Address)->signature,
@ -168,5 +182,7 @@ namespace VirtualFileSystem
} }
} }
USTAR::~USTAR() { warn("Destroyed"); } USTAR::USTAR() {}
USTAR::~USTAR() {}
} }

View File

@ -412,7 +412,11 @@ EXTERNC NIF void Main()
debug("Found initrd at %p", bInfo.Modules[i].Address); debug("Found initrd at %p", bInfo.Modules[i].Address);
static char initrd = 0; static char initrd = 0;
if (!initrd++) if (!initrd++)
new VirtualFileSystem::USTAR((uintptr_t)bInfo.Modules[i].Address, vfs); {
uintptr_t initrdAddress = (uintptr_t)bInfo.Modules[i].Address;
VirtualFileSystem::USTAR *ustar = new VirtualFileSystem::USTAR;
ustar->ReadArchive(initrdAddress, vfs);
}
} }
} }

View File

@ -80,7 +80,9 @@ namespace VirtualFileSystem
} }
public: public:
USTAR(uintptr_t Address, Virtual *vfs_ctx); bool TestArchive(uintptr_t Address);
void ReadArchive(uintptr_t Address, Virtual *vfs_ctx);
USTAR();
~USTAR(); ~USTAR();
}; };
} }