示例#1
0
EXTC NTSTATUS NTAPI iOSDeviceAuthorizeDsids(iOSDevice &Device, PCSTR SCInfoPath, PULONG64 Dsids, ULONG Count, PULONG64* Authed, PULONG AuthedCount)
{
    NTSTATUS status;
    GrowableArray<ULONG64> dsidToAuth, dsidAuthed;

    for (; Count; --Count)
        dsidToAuth.Add(*Dsids++);

    status = Device.AuthorizeDsids(helper, SCInfoPath, dsidToAuth, dsidAuthed);
    if (status != STATUS_SUCCESS)
        return status;

    if (Authed != nullptr && dsidAuthed.GetSize() != 0)
    {
        ULONG_PTR size = dsidAuthed.GetSize() * sizeof(*Dsids);

        *Authed = (PULONG64)AllocateMemoryP(size);
        if (*Authed == nullptr)
            return STATUS_NO_MEMORY;

        CopyMemory(*Authed, dsidAuthed.GetData(), size);
        *AuthedCount = (ULONG)dsidAuthed.GetSize();
    }

    return status;
}
示例#2
0
NTSTATUS InitializeRedirectEntry()
{
    NTSTATUS                Status;
    UNICODE_STRING          ExePath;
    PLDR_MODULE             Module;
    PWSTR                   Buffer;
    ULONG_PTR               Length;
    PFILE_REDIRECT_ENTRY    Entry, RedirectEntry;

    static FILE_REDIRECT_ENTRY RedirectSubDirectory[] =
    {
        REDIRECT_PATH(L"data\\", L"patch\\"),
        REDIRECT_PATH(L"data\\", L"patch2\\"),
    };

    Module = FindLdrModuleByHandle(NULL);
    Status = NtFileDisk::QueryFullNtPath(Module->FullDllName.Buffer, &ExePath);
    FAIL_RETURN(Status);

    RedirectEntry = (PFILE_REDIRECT_ENTRY)AllocateMemoryP((countof(RedirectSubDirectory) + 1) * sizeof(*RedirectEntry), HEAP_ZERO_MEMORY);
    if (RedirectEntry == NULL)
    {
        RtlFreeUnicodeString(&ExePath);
        return STATUS_NO_MEMORY;
    }

    GlobalRedirectEntry = RedirectEntry;

    ExePath.Length -= Module->BaseDllName.Length;
    Length = 0;
    FOR_EACH(Entry, RedirectSubDirectory, countof(RedirectSubDirectory))
    {
        Length = ML_MAX(Entry->Original.Length, ML_MAX(Entry->Redirected.Length, Length));
    }
示例#3
0
PWSTR TitleMByteToWChar(PCSTR AnsiString)
{
    if (AnsiString[0] == -1)
    {
        PWSTR ResourceId = (PWSTR)AllocateMemoryP(6);
        if (ResourceId == NULL)
            return NULL;

        ResourceId[0] = 0xFFFF;
        ResourceId[1] = *(PUSHORT)&AnsiString[1];
        ResourceId[2] = 0;

        return ResourceId;
    }

    return MByteToWChar(AnsiString);
}
示例#4
0
PSTR TitleWCharToMByte(PCWSTR Unicode)
{
    if (Unicode[0] == 0xFFFF)
    {
        PSTR ResourceId = (PSTR)AllocateMemoryP(4);
        if (ResourceId == NULL)
            return NULL;

        ResourceId[0] = -1;
        *(PUSHORT)&ResourceId[1] = Unicode[1];
        ResourceId[3] = 0;

        return ResourceId;
    }

    return WCharToMByte(Unicode);
}
示例#5
0
PWSTR MByteToWChar(PCSTR AnsiString, ULONG_PTR Length)
{
    PWSTR Unicode;

    if (Length == -1)
        Length = StrLengthA(AnsiString);

    ++Length;

    Unicode = (PWSTR)AllocateMemoryP(Length * sizeof(WCHAR));
    if (Unicode == NULL)
        return NULL;

    RtlMultiByteToUnicodeN(Unicode, Length * sizeof(WCHAR), NULL, AnsiString, Length);

    return Unicode;
}
示例#6
0
PSTR WCharToMByte(PCWSTR Unicode, ULONG_PTR Length)
{
    PSTR AnsiString;

    if (Length == -1)
        Length = StrLengthW(Unicode);

    ++Length;
    Length *= sizeof(WCHAR);

    AnsiString = (PSTR)AllocateMemoryP(Length);
    if (AnsiString == NULL)
        return NULL;

    RtlUnicodeToMultiByteN(AnsiString, Length, NULL, Unicode, Length);

    return AnsiString;
}
示例#7
0
NTSTATUS iOSDeviceGetStringValue(iOSDevice &Device, String (iOSDevice::*func)(), PSTR *Output)
{
    const auto &productType = (&Device->*func)().Encode(CP_UTF8);

    *Output = (PSTR)AllocateMemoryP(productType.GetSize());
    if (*Output != nullptr)
        CopyMemory(*Output, productType.GetData(), productType.GetSize());

#if 1

    iOSService house_arrest(Device);
    house_arrest.Start("com.apple.mobile.house_arrest");

    iOSAFC afc;

    afc.CreateConnection(house_arrest);

#endif

    return *Output == nullptr ? STATUS_NO_MEMORY : STATUS_SUCCESS;
}
NTSTATUS ReadFileInSystemDirectory(NtFileMemory &File, PUNICODE_STRING Path)
{
    PWSTR       Buffer;
    ULONG_PTR   Length;
    NTSTATUS    Status;

    Length = sizeof(ROOTDIR_SYSTEM32) + Path->Length + sizeof(WCHAR);
    Buffer = (PWSTR)AllocateMemoryP(Length);
    if (Buffer == nullptr)
        return STATUS_NO_MEMORY;

    Length = CONST_STRLEN(ROOTDIR_SYSTEM32);
    CopyMemory(Buffer, ROOTDIR_SYSTEM32, Length * sizeof(WCHAR));
    CopyMemory(Buffer + Length, Path->Buffer, Path->Length);
    Buffer[Length + Path->Length / sizeof(WCHAR)] = 0;

    Status = File.Open(Buffer, NFD_NOT_RESOLVE_PATH);

    FreeMemoryP(Buffer);

    return Status;
}
NTSTATUS LeGlobalData::InitRegistryRedirection(PREGISTRY_REDIRECTION_ENTRY64 Entry64, ULONG_PTR Count, PVOID BaseAddress)
{
    NTSTATUS    Status;
    PLEPEB      LePeb;
    PREGISTRY_REDIRECTION_ENTRY Entry;

    if (Count == 0)
        return STATUS_NO_MORE_ENTRIES;

    LePeb = this->GetLePeb();

#pragma push_macro("USTR64ToUSTR")
#undef USTR64ToUSTR
#define USTR64ToUSTR(ustr64) UNICODE_STRING({ ustr64.Length, ustr64.MaximumLength, PtrAdd(ustr64.Buffer, BaseAddress) });

    REGISTRY_REDIRECTION_ENTRY LocalEntry;

    FOR_EACH(Entry64, Entry64, Count)
    {
        ULONG_PTR       LastIndex;
        HANDLE          OriginalKey, RedirectedKey;
        UNICODE_STRING  KeyFullPath;

        OriginalKey     = nullptr;
        RedirectedKey   = nullptr;

        Status = Reg::OpenKey(&OriginalKey, (HANDLE)Entry64->Original.Root, KEY_QUERY_VALUE, PtrAdd(Entry64->Original.SubKey.Buffer, BaseAddress));
        FAIL_CONTINUE(Status);

        if (Entry64->Redirected.Root != NULL)
        {
            Status = Reg::OpenKey(&RedirectedKey, (HANDLE)Entry64->Redirected.Root, KEY_QUERY_VALUE, PtrAdd(Entry64->Redirected.SubKey.Buffer, BaseAddress));
            if (NT_FAILED(Status))
            {
                Reg::CloseKeyHandle(OriginalKey);
                continue;
            }
        }

        this->RegistryRedirectionEntry.Add(LocalEntry);
        LastIndex = this->RegistryRedirectionEntry.GetSize() - 1;
        Entry = &this->RegistryRedirectionEntry[LastIndex];

        Status = QueryRegKeyFullPath(OriginalKey, &KeyFullPath);
        Reg::CloseKeyHandle(OriginalKey);
        if (NT_FAILED(Status))
        {
            Reg::CloseKeyHandle(RedirectedKey);
            this->RegistryRedirectionEntry.Remove(LastIndex);
            continue;
        }

        Entry->Original.FullPath = KeyFullPath;
        RtlFreeUnicodeString(&KeyFullPath);

        if (RedirectedKey != nullptr)
        {
            Status = QueryRegKeyFullPath(RedirectedKey, &KeyFullPath);
            Reg::CloseKeyHandle(RedirectedKey);
            if (NT_FAILED(Status))
            {
                this->RegistryRedirectionEntry.Remove(LastIndex);
                continue;
            }

            Entry->Redirected.FullPath = KeyFullPath;
            RtlFreeUnicodeString(&KeyFullPath);
        }

        Entry->Original.Root        = (HKEY)Entry64->Original.Root;
        Entry->Original.SubKey      = USTR64ToUSTR(Entry64->Original.SubKey);
        Entry->Original.ValueName   = USTR64ToUSTR(Entry64->Original.ValueName);
        Entry->Original.DataType    = Entry64->Original.DataType;
        Entry->Original.Data        = nullptr;
        Entry->Original.DataSize    = 0;

        Entry->Redirected.Root      = (HKEY)Entry64->Redirected.Root;
        Entry->Redirected.SubKey    = USTR64ToUSTR(Entry64->Redirected.SubKey);
        Entry->Redirected.ValueName = USTR64ToUSTR(Entry64->Redirected.ValueName);
        Entry->Redirected.DataType  = Entry64->Redirected.DataType;
        Entry->Redirected.Data      = nullptr;
        Entry->Redirected.DataSize  = 0;

        if (Entry64->Redirected.Data != nullptr && Entry64->Redirected.DataSize != 0)
        {
            Entry->Redirected.DataSize = (ULONG_PTR)Entry64->Redirected.DataSize;
            Entry->Redirected.Data = AllocateMemoryP(Entry->Redirected.DataSize);
            if (Entry->Redirected.Data == nullptr)
            {
                this->RegistryRedirectionEntry.Remove(LastIndex);
                continue;
            }

            CopyMemory(Entry->Redirected.Data, PtrAdd(Entry64->Redirected.Data, BaseAddress), Entry->Redirected.DataSize);
        }
    }