コード例 #1
0
ファイル: RtlBitmap.c プロジェクト: hoangduit/reactos
void
Test_RtlInitializeBitMap(void)
{
    RTL_BITMAP BitMapHeader;
    ULONG Buffer[2];
    BOOLEAN Exception = FALSE;

    _SEH2_TRY
    {
        RtlInitializeBitMap(NULL, NULL, 0);
    }
    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
    {
        Exception = TRUE;
    }
    _SEH2_END;
    ok_int(Exception, 1);

    memset(Buffer, 0xcc, sizeof(Buffer));
    RtlInitializeBitMap(&BitMapHeader, Buffer, 0);
    ok_int(BitMapHeader.SizeOfBitMap, 0);
    ok_ptr(BitMapHeader.Buffer, Buffer);
    ok_hex(Buffer[0], 0xcccccccc);

    RtlInitializeBitMap(&BitMapHeader, Buffer, 8);
    ok_int(BitMapHeader.SizeOfBitMap, 8);
    ok_hex(Buffer[0], 0xcccccccc);
}
コード例 #2
0
ファイル: RtlBitmap.c プロジェクト: hoangduit/reactos
void
Test_RtlAreBitsSet(void)
{
    RTL_BITMAP BitMapHeader;
    ULONG *Buffer;

    Buffer = AllocateGuarded(2 * sizeof(*Buffer));
    RtlInitializeBitMap(&BitMapHeader, Buffer, 19);
    Buffer[0] = 0xff00ff00;
    Buffer[1] = 0x3F303F30;

    ok_hex(RtlAreBitsSet(&BitMapHeader, 0, 8), FALSE);
    ok_hex(RtlAreBitsSet(&BitMapHeader, 8, 8), TRUE);
    ok_hex(RtlAreBitsSet(&BitMapHeader, 7, 8), FALSE);
    ok_hex(RtlAreBitsSet(&BitMapHeader, 8, 9), FALSE);
    ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 1), FALSE);

    RtlInitializeBitMap(&BitMapHeader, Buffer, 31);
    ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 1), TRUE);
    ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 7), TRUE);
    ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 8), FALSE);

    RtlInitializeBitMap(&BitMapHeader, Buffer, 64);
    ok_hex(RtlAreBitsSet(&BitMapHeader, 60, 4), FALSE);
    FreeGuarded(Buffer);
}
コード例 #3
0
ファイル: RtlReAllocateHeap.c プロジェクト: GYGit/reactos
static
BOOLEAN
ReAllocBuffer(
    PUCHAR *Buffer,
    SIZE_T Size,
    SIZE_T *OldSizePtr,
    PCSTR Action)
{
    PUCHAR NewBuffer;
    SIZE_T OldSize = *OldSizePtr;

    RtlFillMemory(*Buffer, OldSize, 0x7a);
    NewBuffer = RtlReAllocateHeap(RtlGetProcessHeap(),
                                  HEAP_ZERO_MEMORY,
                                  *Buffer,
                                  Size);
    if (!NewBuffer)
    {
        skip("RtlReAllocateHeap failed for size %lu (%s)\n", Size, Action);
        return FALSE;
    }
    *Buffer = NewBuffer;
    ok_hex(RtlSizeHeap(RtlGetProcessHeap(), 0, NewBuffer), Size);
    if (OldSize < Size)
    {
        ok(CheckBuffer(NewBuffer, OldSize, 0x7a), "CheckBuffer failed at size 0x%lx -> 0x%lx\n", OldSize, Size);
        ok(CheckBuffer(NewBuffer + OldSize, Size - OldSize, 0), "HEAP_ZERO_MEMORY not respected for 0x%lx -> 0x%lx\n", OldSize, Size);
    }
    else
    {
        ok(CheckBuffer(NewBuffer, Size, 0x7a), "CheckBuffer failed at size 0x%lx -> 0x%lx\n", OldSize, Size);
    }
    *OldSizePtr = Size;
    return TRUE;
}
コード例 #4
0
ファイル: RtlBitmap.c プロジェクト: hoangduit/reactos
void
Test_RtlSetAllBits(void)
{
    RTL_BITMAP BitMapHeader;
    ULONG *Buffer;
    ULONG BufferSize = 2 * sizeof(*Buffer);

    Buffer = AllocateGuarded(BufferSize);
    RtlInitializeBitMap(&BitMapHeader, Buffer, 19);
    memset(Buffer, 0xcc, BufferSize);
    RtlSetAllBits(&BitMapHeader);
    ok_hex(Buffer[0], 0xffffffff);
    ok_hex(Buffer[1], 0xcccccccc);

    RtlInitializeBitMap(&BitMapHeader, Buffer, 0);
    memset(Buffer, 0xcc, BufferSize);
    RtlSetAllBits(&BitMapHeader);
    ok_hex(Buffer[0], 0xcccccccc);
    ok_hex(Buffer[1], 0xcccccccc);

    RtlInitializeBitMap(&BitMapHeader, Buffer, 64);
    memset(Buffer, 0xcc, BufferSize);
    RtlSetAllBits(&BitMapHeader);
    ok_hex(Buffer[0], 0xffffffff);
    ok_hex(Buffer[1], 0xffffffff);
    FreeGuarded(Buffer);
}
コード例 #5
0
ファイル: LdrEnumResources.c プロジェクト: Moteesh/reactos
static
void
Test_Data(PTEST_IMAGE TestImage)
{
    LDR_RESOURCE_INFO ResourceInfo;
    LDR_ENUM_RESOURCE_INFO EnumRes[8];
    ULONG ResourceCount;
    NTSTATUS Status;

    InitializeTestImage(TestImage);

    memset(EnumRes, 0xcc, sizeof(EnumRes));

    ResourceInfo.Type = 1;
    ResourceInfo.Name = 1;
    ResourceInfo.Language = 0x408;
    ResourceCount = 8;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, EnumRes);
    ok_hex(Status, STATUS_SUCCESS);
    ok_dec(ResourceCount, 8);

    ok_ptr((PVOID)EnumRes[0].Data, TestImage->Resources.StringBuffer);
    ok_dec(EnumRes[0].Size, 2);

    ok_enumres(&EnumRes[0], 1, L"TEST", 0x409, TestImage->Resources.StringBuffer, 2)
    ok_enumres(&EnumRes[1], 1, L"TEST", 0x407, TestImage->Resources.StringBuffer + 2, 4)
    ok_enumres(&EnumRes[2], 1, 7, 0x408, TestImage->Resources.StringBuffer + 4, 6)
    ok_enumres(&EnumRes[3], 1, 7, 0x406, TestImage->Resources.StringBuffer + 6, 8)
    ok_enumres(&EnumRes[4], 2, L"LOL", 0x405, TestImage->Resources.StringBuffer + 8, 10)
    ok_enumres(&EnumRes[5], 2, L"LOL", 0x403, TestImage->Resources.StringBuffer + 10, 12)
    ok_enumres(&EnumRes[6], 2, L"xD", 0x402, TestImage->Resources.StringBuffer + 12, 14)
    ok_enumres(&EnumRes[7], 2, L"xD", 0x404, TestImage->Resources.StringBuffer + 14, 16)

    Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, EnumRes);
    ok_hex(Status, STATUS_SUCCESS);
    ok_dec(ResourceCount, 4);

}
コード例 #6
0
ファイル: WSAIoctl.c プロジェクト: Moteesh/reactos
void Test_WSAIoctl_GetInterfaceList()
{
    WSADATA wdata;
    INT iResult;
    SOCKET sck;
    ULONG buflen, BytesReturned, BCastAddr;
    ULONG infoCount, i1, j1, iiFlagsExpected;
    BYTE* buf = NULL;
    LPINTERFACE_INFO ifInfo;
    PMIB_IPADDRTABLE pTable = NULL;
    PMIB_IPADDRROW pRow;

    /* Get PMIB_IPADDRTABE - these results we should get from wshtcpip.dll too. */ 
    /* pTable is allocated by Test_WSAIoctl_InitTest! */
    if (!Test_WSAIoctl_InitTest(&pTable))
        goto cleanup;

    /* Start up Winsock */
    iResult = WSAStartup(MAKEWORD(2, 2), &wdata);
    ok(iResult == 0, "WSAStartup failed. iResult = %d\n", iResult);

    /* Create the socket */
    sck = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0, 0, 0);
    ok(sck != INVALID_SOCKET, "WSASocket failed. sck = %d\n", (INT)sck);
    if (sck == INVALID_SOCKET)
    {
        skip("Failed to create socket!\n");
        goto cleanup;
    }

    /* Do the Ioctl (buffer to small) */
    buflen = sizeof(INTERFACE_INFO)-1;
    buf = (BYTE*)HeapAlloc(GetProcessHeap(), 0, buflen);
    if (buf == NULL)
    {
        skip("Failed to allocate memory!\n");
        goto cleanup;
    }
    BytesReturned = 0;
    iResult = WSAIoctl(sck, SIO_GET_INTERFACE_LIST, 0, 0,
                       buf, buflen, &BytesReturned, 0, 0);
    ok(iResult == -1, "WSAIoctl/SIO_GET_INTERFACE_LIST did not fail! iResult = %d.\n", iResult);
    ok_hex(WSAGetLastError(), WSAEFAULT);
    ok(BytesReturned == 0, "WSAIoctl/SIO_GET_INTERFACE_LIST: BytesReturned should be 0, not %ld.\n", BytesReturned);
    HeapFree(GetProcessHeap(), 0, buf);
    buf = NULL;

    /* Do the Ioctl 
       In most cases no loop is done. 
       Only if WSAIoctl fails with WSAEFAULT (buffer to small) we need to retry with a 
       larger buffer */
    i1 = 0;
    while (TRUE) 
    {
        if (buf != NULL)
        {
            HeapFree(GetProcessHeap(), 0, buf);
            buf = NULL;
        }

        buflen = sizeof(INTERFACE_INFO) * (i1+1) * 32;
        buf = (BYTE*)HeapAlloc(GetProcessHeap(), 0, buflen);
        if (buf == NULL)
        {
            skip("Failed to allocate memory!\n");
            goto cleanup;
        }
        BytesReturned = 0;
        iResult = WSAIoctl(sck, SIO_GET_INTERFACE_LIST, 0, 0,
                           buf, buflen, &BytesReturned, 0, 0);
        /* we have what we want ... leave loop */
        if (iResult == NO_ERROR)
            break;
        /* only retry if buffer was to small */
        /* to avoid infinite loop we maximum retry count is 4 */
        if ((i1 >= 4) || (WSAGetLastError() != WSAEFAULT))
        {
            ok_hex(iResult, NO_ERROR);
            skip("WSAIoctl / SIO_GET_INTERFACE_LIST\n");
            goto cleanup;
        }
        /* buffer to small -> retry */
        i1++;
    }

    ok_dec(BytesReturned % sizeof(INTERFACE_INFO), 0);

    /* Calculate how many INTERFACE_INFO we got */
    infoCount = BytesReturned / sizeof(INTERFACE_INFO);
    ok(infoCount == pTable->dwNumEntries, 
       "Wrong count of entries! Got %ld, expected %ld.\n", pTable->dwNumEntries, infoCount);    

    if (winetest_debug >= 2)
    {
        trace("WSAIoctl\n");
        trace("  BytesReturned %ld - InfoCount %ld\n ", BytesReturned, infoCount);
        ifInfo = (LPINTERFACE_INFO)buf;
        for (i1 = 0; i1 < infoCount; i1++)
        {
            trace("entry-index %ld\n", i1);
            trace("  iiFlags %ld\n", ifInfo->iiFlags);
            traceaddr("ifInfo^.iiAddress", ifInfo->iiAddress);
            traceaddr("ifInfo^.iiBroadcastAddress", ifInfo->iiBroadcastAddress);
            traceaddr("ifInfo^.iiNetmask", ifInfo->iiNetmask);
            ifInfo++;
        }
    }

    /* compare entries */
    ifInfo = (LPINTERFACE_INFO)buf;
    for (i1 = 0; i1 < infoCount; i1++)
    {
        if (winetest_debug >= 2)
            trace("Entry %ld\n", i1);
        for (j1 = 0; j1 < pTable->dwNumEntries; j1++)
        {
            if (ifInfo[i1].iiAddress.AddressIn.sin_addr.s_addr == pTable->table[j1].dwAddr)
            {
                pRow = &pTable->table[j1];
                break;
            }
        }
        if (j1 == pTable->dwNumEntries)
        {
            skip("Skipping interface\n");
            continue;
        }

        /* iiFlags
         * Don't know if this value is fix for SIO_GET_INTERFACE_LIST! */ 
        iiFlagsExpected = IFF_BROADCAST | IFF_MULTICAST;
        if ((pRow->wType & MIB_IPADDR_DISCONNECTED) == 0)
            iiFlagsExpected |= IFF_UP;
        if (pRow->dwAddr == ntohl(INADDR_LOOPBACK))
        {
            iiFlagsExpected |= IFF_LOOPBACK;
            /* on Windows 7 loopback has broadcast flag cleared */
            //iiFlagsExpected &= ~IFF_BROADCAST;
        }
        
        ok_hex(ifInfo[i1].iiFlags, iiFlagsExpected);
        ok_hex(ifInfo[i1].iiAddress.AddressIn.sin_addr.s_addr, pRow->dwAddr);
        // dwBCastAddr is not the "real" Broadcast-Address. 
        BCastAddr = (pRow->dwBCastAddr == 1 && (iiFlagsExpected & IFF_BROADCAST) != 0) ? 0xFFFFFFFF : 0x0;
        ok_hex(ifInfo[i1].iiBroadcastAddress.AddressIn.sin_addr.s_addr, BCastAddr);
        ok_hex(ifInfo[i1].iiNetmask.AddressIn.sin_addr.s_addr, pRow->dwMask);
    }

cleanup:
    if (sck != 0)
        closesocket(sck);
    if (pTable != NULL)
       free(pTable);
    if (buf != NULL)
       HeapFree(GetProcessHeap(), 0, buf);
    WSACleanup();
}
コード例 #7
0
ファイル: LdrEnumResources.c プロジェクト: Moteesh/reactos
static
void
Test_Parameters(PTEST_IMAGE TestImage)
{
    LDR_RESOURCE_INFO ResourceInfo;
    LDR_ENUM_RESOURCE_INFO Resources[8];
    ULONG ResourceCount;
    NTSTATUS Status;

    InitializeTestImage(TestImage);

    ResourceInfo.Type = 6;
    ResourceInfo.Name = 1;
    ResourceInfo.Language = 0x409;

    ResourceCount = 8;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 3, &ResourceCount, Resources);
    ok_hex(Status, STATUS_SUCCESS);
    ok_dec(ResourceCount, 0);

    ResourceInfo.Type = 1;
    ResourceInfo.Name = 7;
    ResourceInfo.Language = 0x406;
    ResourceCount = 8;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, Resources);
    ok_hex(Status,  STATUS_SUCCESS);
    ok_dec(ResourceCount, 8);

    ResourceCount = 8;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, Resources);
    ok_hex(Status, STATUS_SUCCESS);
    ok_dec(ResourceCount, 4);

    ResourceCount = 8;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 2, &ResourceCount, Resources);
    ok_hex(Status, STATUS_SUCCESS);
    ok_dec(ResourceCount, 2);

    ResourceCount = 8;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 3, &ResourceCount, Resources);
    ok_hex(Status, STATUS_SUCCESS);
    ok_dec(ResourceCount, 1);

    ResourceCount = 8;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 99, &ResourceCount, Resources);
    ok_hex(Status, STATUS_SUCCESS);
    ok_dec(ResourceCount, 1);

    ResourceCount = 0;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, Resources);
    ok_hex(Status,  STATUS_INFO_LENGTH_MISMATCH);
    ok_dec(ResourceCount, 8);

    ResourceCount = 7;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, Resources);
    ok_hex(Status,  STATUS_INFO_LENGTH_MISMATCH);
    ok_dec(ResourceCount, 8);

    ResourceCount = 8;
    Status = LdrEnumResources(NULL, &ResourceInfo, 1, &ResourceCount, Resources);
    ok_hex(Status, STATUS_RESOURCE_DATA_NOT_FOUND);
    ok_dec(ResourceCount, 0);

    ResourceCount = 8;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, NULL);
    ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
    ok_dec(ResourceCount, 4);

    ResourceCount = 8;
    _SEH2_TRY
    {
        Status = LdrEnumResources(NULL, NULL, 0, NULL, NULL);
    }
    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
    {
        Status = 0xDeadC0de;
    }
    _SEH2_END
    ok_hex(Status, 0xDeadC0de);

    ResourceCount = 42;
    _SEH2_TRY
    {
        Status = LdrEnumResources(TestImage, &ResourceInfo, 1, NULL, Resources);
    }
    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
    {
        Status = 0xDeadC0de;
    }
    _SEH2_END
    ok_hex(Status, 0xDeadC0de);
    ok_dec(ResourceCount, 42);

    ResourceCount = 8;
    Status = LdrEnumResources(TestImage + 2, &ResourceInfo, 1, &ResourceCount, NULL);
    ok_hex(Status,  STATUS_RESOURCE_DATA_NOT_FOUND);
    ok_dec(ResourceCount, 0);

    TestImage->Resources.TypeEntries[0].DataIsDirectory = 0;
    Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, NULL);
    ok_hex(Status,  STATUS_INVALID_IMAGE_FORMAT);
    ok_dec(ResourceCount, 0);

}
コード例 #8
0
ファイル: RtlBitmap.c プロジェクト: hoangduit/reactos
void
Test_RtlFindSetBitsAndClear(void)
{
    RTL_BITMAP BitMapHeader;
    ULONG *Buffer;

    Buffer = AllocateGuarded(2 * sizeof(*Buffer));
    Buffer[0] = 0xF9F078B2;
    Buffer[1] = 0x3F303F30;

    RtlInitializeBitMap(&BitMapHeader, Buffer, 0);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 0, 0), 0);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 0, 3), 0);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 0), -1);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 1), -1);
    ok_hex(Buffer[0], 0xF9F078B2);

    Buffer[0] = 0xF9F078B2;
    RtlInitializeBitMap(&BitMapHeader, Buffer, 8);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 0), 1);
    ok_hex(Buffer[0], 0xf9f078b0);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 1), 4);
    ok_hex(Buffer[0], 0xf9f078a0);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 2), 5);
    ok_hex(Buffer[0], 0xf9f07880);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 2, 0), -1);
    ok_hex(Buffer[0], 0xf9f07880);

    Buffer[0] = 0xF9F078B2;
    RtlInitializeBitMap(&BitMapHeader, Buffer, 32);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 4, 0), 11);
    ok_hex(Buffer[0], 0xf9f000b2);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 5, 0), 20);
    ok_hex(Buffer[0], 0xf80000b2);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 4, 11), 27);
    ok_hex(Buffer[0], 0x800000b2);

    Buffer[0] = 0xF9F078B2;
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 4, 12), 20);
    ok_hex(Buffer[0], 0xf90078b2);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 2, 11), 11);
    ok_hex(Buffer[0], 0xf90060b2);
    ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 2, 12), 13);
    ok_hex(Buffer[0], 0xf90000b2);
    FreeGuarded(Buffer);
}
コード例 #9
0
ファイル: RtlBitmap.c プロジェクト: hoangduit/reactos
void
Test_RtlFindClearBitsAndSet(void)
{
    RTL_BITMAP BitMapHeader;
    ULONG *Buffer;

    Buffer = AllocateGuarded(2 * sizeof(*Buffer));
    Buffer[0] = 0x060F874D;
    Buffer[1] = 0x3F303F30;

    RtlInitializeBitMap(&BitMapHeader, Buffer, 0);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 0, 0), 0);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 0, 3), 0);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 0), -1);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 1), -1);
    ok_hex(Buffer[0], 0x060F874D);

    Buffer[0] = 0x060F874D;
    RtlInitializeBitMap(&BitMapHeader, Buffer, 8);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 0), 1);
    ok_hex(Buffer[0], 0x60f874f);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 1), 4);
    ok_hex(Buffer[0], 0x60f875f);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 2), 5);
    ok_hex(Buffer[0], 0x60f877f);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 2, 0), -1);
    ok_hex(Buffer[0], 0x60f877f);

    Buffer[0] = 0x060F874D;
    RtlInitializeBitMap(&BitMapHeader, Buffer, 32);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 4, 0), 11);
    ok_hex(Buffer[0], 0x60fff4d);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 5, 0), 20);
    ok_hex(Buffer[0], 0x7ffff4d);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 4, 11), 27);
    ok_hex(Buffer[0], 0x7fffff4d);

    Buffer[0] = 0x060F874D;
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 4, 12), 20);
    ok_hex(Buffer[0], 0x6ff874d);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 2, 11), 11);
    ok_hex(Buffer[0], 0x6ff9f4d);
    ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 2, 12), 13);
    ok_hex(Buffer[0], 0x6ffff4d);
    FreeGuarded(Buffer);
}
コード例 #10
0
ファイル: RtlBitmap.c プロジェクト: hoangduit/reactos
void
Test_RtlSetBits(void)
{
    RTL_BITMAP BitMapHeader;
    ULONG *Buffer;
    ULONG BufferSize = 2 * sizeof(*Buffer);

    Buffer = AllocateGuarded(BufferSize);
    RtlInitializeBitMap(&BitMapHeader, Buffer, 19);

    memset(Buffer, 0x00, BufferSize);
    RtlSetBits(&BitMapHeader, 0, 0);
    ok_hex(Buffer[0], 0x00000000);
    ok_hex(Buffer[1], 0x00000000);

    memset(Buffer, 0x00, BufferSize);
    RtlSetBits(&BitMapHeader, 0, 1);
    ok_hex(Buffer[0], 0x00000001);
    ok_hex(Buffer[1], 0x00000000);

    memset(Buffer, 0x00, BufferSize);
    RtlSetBits(&BitMapHeader, 21, 1);
    ok_hex(Buffer[0], 0x00200000);
    ok_hex(Buffer[1], 0x00000000);

    memset(Buffer, 0x00, BufferSize);
    RtlSetBits(&BitMapHeader, 7, 9);
    ok_hex(Buffer[0], 0x0000ff80);
    ok_hex(Buffer[1], 0x00000000);

    memset(Buffer, 0x00, BufferSize);
    RtlSetBits(&BitMapHeader, 13, 22);
    ok_hex(Buffer[0], 0xffffe000);
    ok_hex(Buffer[1], 0x00000007);

    memset(Buffer, 0x00, BufferSize);
    RtlSetBits(&BitMapHeader, 63, 1);
    ok_hex(Buffer[0], 0x00000000);
    ok_hex(Buffer[1], 0x80000000);

    memset(Buffer, 0xcc, BufferSize);
    RtlSetBits(&BitMapHeader, 3, 6);
    RtlSetBits(&BitMapHeader, 11, 5);
    RtlSetBits(&BitMapHeader, 21, 7);
    RtlSetBits(&BitMapHeader, 37, 4);
    ok_hex(Buffer[0], 0xcfecfdfc);
    ok_hex(Buffer[1], 0xcccccdec);
    FreeGuarded(Buffer);
}
コード例 #11
0
ファイル: RtlBitmap.c プロジェクト: hoangduit/reactos
void
Test_RtlClearBits(void)
{
    RTL_BITMAP BitMapHeader;
    ULONG *Buffer;
    ULONG BufferSize = 2 * sizeof(*Buffer);

    Buffer = AllocateGuarded(BufferSize);
    RtlInitializeBitMap(&BitMapHeader, Buffer, 19);

    memset(Buffer, 0xff, BufferSize);
    RtlClearBits(&BitMapHeader, 0, 0);
    ok_hex(Buffer[0], 0xffffffff);
    ok_hex(Buffer[1], 0xffffffff);

    memset(Buffer, 0xff, BufferSize);
    RtlClearBits(&BitMapHeader, 0, 1);
    ok_hex(Buffer[0], 0xfffffffe);
    ok_hex(Buffer[1], 0xffffffff);

    memset(Buffer, 0xff, BufferSize);
    RtlClearBits(&BitMapHeader, 21, 1);
    ok_hex(Buffer[0], 0xffdfffff);
    ok_hex(Buffer[1], 0xffffffff);

    memset(Buffer, 0xff, BufferSize);
    RtlClearBits(&BitMapHeader, 7, 9);
    ok_hex(Buffer[0], 0xffff007f);
    ok_hex(Buffer[1], 0xffffffff);

    memset(Buffer, 0xff, BufferSize);
    RtlClearBits(&BitMapHeader, 13, 22);
    ok_hex(Buffer[0], 0x00001fff);
    ok_hex(Buffer[1], 0xfffffff8);

    memset(Buffer, 0xff, BufferSize);
    RtlClearBits(&BitMapHeader, 63, 1);
    ok_hex(Buffer[0], 0xffffffff);
    ok_hex(Buffer[1], 0x7fffffff);

    memset(Buffer, 0xcc, BufferSize);
    RtlClearBits(&BitMapHeader, 3, 6);
    RtlClearBits(&BitMapHeader, 11, 5);
    RtlClearBits(&BitMapHeader, 21, 7);
    RtlClearBits(&BitMapHeader, 37, 4);
    ok_hex(Buffer[0], 0xc00c0404);
    ok_hex(Buffer[1], 0xcccccc0c);
    FreeGuarded(Buffer);
}
コード例 #12
0
void
Test_ImageSection(void)
{
    UNICODE_STRING FileName;
    NTSTATUS Status;
    OBJECT_ATTRIBUTES FileObjectAttributes;
    IO_STATUS_BLOCK IoStatusBlock;
    HANDLE FileHandle, DataSectionHandle, ImageSectionHandle;
    PVOID DataBase, ImageBase;
    SIZE_T ViewSize;

    if (!RtlDosPathNameToNtPathName_U(L"testdata\\test.dll",
                                      &FileName,
                                      NULL,
                                      NULL))
    {
        ok(0, "RtlDosPathNameToNtPathName_U failed\n");
        return;
    }

    InitializeObjectAttributes(&FileObjectAttributes,
                               &FileName,
                               0,
                               NULL,
                               NULL);

    Status = NtOpenFile(&FileHandle,
                        GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
                        &FileObjectAttributes,
                        &IoStatusBlock,
                        FILE_SHARE_READ,
                        FILE_SYNCHRONOUS_IO_NONALERT);
    ok(Status == STATUS_SUCCESS, "NtOpenFile failed, Status 0x%lx\n", Status);

    /* Create a data section with write access */
    Status = NtCreateSection(&DataSectionHandle,
                             SECTION_ALL_ACCESS, // DesiredAccess
                             NULL, // ObjectAttributes
                             NULL, // MaximumSize
                             PAGE_READWRITE, // SectionPageProtection
                             SEC_COMMIT, // AllocationAttributes
                             FileHandle);
    ok(Status == STATUS_SUCCESS, "NtCreateSection failed, Status 0x%lx\n", Status);

    /* Map the data section */
    DataBase = NULL;
    ViewSize = 0;
    Status = NtMapViewOfSection(DataSectionHandle,
                                NtCurrentProcess(),
                                &DataBase,
                                0,
                                0,
                                NULL,
                                &ViewSize,
                                ViewShare,
                                0,
                                PAGE_READWRITE);
    ok(Status == STATUS_SUCCESS, "NtMapViewOfSection failed, Status 0x%lx\n", Status);

    /* Check the original data */
    ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n");

    /* Modify the PE header (but do not flush!) */
    *(ULONG*)DataBase = 0xdeadbabe;
    ok(*(ULONG*)DataBase == 0xdeadbabe, "Header not ok\n");

    /* Modify data in the .data section (but do not flush!) */
    ok(*(ULONG*)((PUCHAR)DataBase + 0x800) == 0x12345678,
       "Data in .data section invalid: 0x%lx!\n", *(ULONG*)((PUCHAR)DataBase + 0x800));
    *(ULONG*)((PUCHAR)DataBase + 0x800) = 0x87654321;

    /* Now try to create an image section (should fail) */
    Status = NtCreateSection(&ImageSectionHandle,
                             SECTION_ALL_ACCESS, // DesiredAccess
                             NULL, // ObjectAttributes
                             NULL, // MaximumSize
                             PAGE_READWRITE, // SectionPageProtection
                             SEC_IMAGE, // AllocationAttributes
                             FileHandle);
    ok(Status == STATUS_INVALID_IMAGE_NOT_MZ, "NtCreateSection failed, Status 0x%lx\n", Status);

    /* Restore the original header */
    *(ULONG*)DataBase = 0x00905a4d;

    /* Modify data in the .data section (but do not flush!) */
    ok_hex(*(ULONG*)((PUCHAR)DataBase + 0x800), 0x87654321);
    *(ULONG*)((PUCHAR)DataBase + 0x800) = 0xdeadbabe;

    /* Try to create an image section again */
    Status = NtCreateSection(&ImageSectionHandle,
                             SECTION_ALL_ACCESS, // DesiredAccess
                             NULL, // ObjectAttributes
                             NULL, // MaximumSize
                             PAGE_READWRITE, // SectionPageProtection
                             SEC_IMAGE, // AllocationAttributes
                             FileHandle);
    ok(Status == STATUS_SUCCESS, "NtCreateSection failed, Status 0x%lx\n", Status);

    /* Map the image section */
    ImageBase = NULL;
    ViewSize = 0;
    Status = NtMapViewOfSection(ImageSectionHandle,
                                NtCurrentProcess(),
                                &ImageBase,
                                0,
                                0,
                                NULL,
                                &ViewSize,
                                ViewShare,
                                0,
                                PAGE_READONLY);
#ifdef _M_IX86
    ok(Status == STATUS_SUCCESS, "NtMapViewOfSection failed, Status 0x%lx\n", Status);
#else
    ok(Status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH, "NtMapViewOfSection failed, Status 0x%lx\n", Status);
#endif

    /* Check the header */
    ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n");
    ok(*(ULONG*)ImageBase == 0x00905a4d, "Header not ok\n");

    /* Check the data section. Either of these can be present! */
    ok((*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x87654321) ||
       (*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x12345678),
       "Wrong value in data section: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));

    /* Now modify the data again */
    *(ULONG*)DataBase = 0xdeadbabe;
    *(ULONG*)((PUCHAR)DataBase + 0x800) = 0xf00dada;

    /* Check the data */
    ok(*(ULONG*)DataBase == 0xdeadbabe, "Header not ok\n");
    ok(*(ULONG*)ImageBase == 0x00905a4d, "Data should not be synced!\n");
    ok((*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x87654321) ||
       (*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x12345678),
       "Wrong value in data section: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));

    /* Flush the view */
    ViewSize = 0x1000;
    Status = NtFlushVirtualMemory(NtCurrentProcess(),
                                  &DataBase,
                                  &ViewSize,
                                  &IoStatusBlock);
    ok(Status == STATUS_SUCCESS, "NtFlushVirtualMemory failed, Status 0x%lx\n", Status);

    /* Check the data again */
    ok(*(ULONG*)ImageBase == 0x00905a4d, "Data should not be synced!\n");
    ok((*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x87654321) ||
       (*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0x12345678),
       "Wrong value in data section: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));

    /* Restore the original header */
    *(ULONG*)DataBase = 0x00905a4d;
    ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n");

    /* Close the image mapping */
    NtUnmapViewOfSection(NtCurrentProcess(), ImageBase);
    NtClose(ImageSectionHandle);

    /* Create an image section again */
    Status = NtCreateSection(&ImageSectionHandle,
                             SECTION_ALL_ACCESS, // DesiredAccess
                             NULL, // ObjectAttributes
                             NULL, // MaximumSize
                             PAGE_READWRITE, // SectionPageProtection
                             SEC_IMAGE, // AllocationAttributes
                             FileHandle);
    ok(Status == STATUS_SUCCESS, "NtCreateSection failed, Status 0x%lx\n", Status);

    /* Map the image section again */
    ImageBase = NULL;
    ViewSize = 0;
    Status = NtMapViewOfSection(ImageSectionHandle,
                                NtCurrentProcess(),
                                &ImageBase,
                                0,
                                0,
                                NULL,
                                &ViewSize,
                                ViewShare,
                                0,
                                PAGE_READONLY);
#ifdef _M_IX86
    ok(Status == STATUS_SUCCESS, "NtMapViewOfSection failed, Status 0x%lx\n", Status);
#else
    ok(Status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH, "NtMapViewOfSection failed, Status 0x%lx\n", Status);
#endif

    /* Check the .data section again */
    ok(*(ULONG*)((PUCHAR)ImageBase + 0x80000) == 0xf00dada,
       "Data should be synced: 0x%lx!\n", *(ULONG*)((PUCHAR)ImageBase + 0x80000));

    /* Restore the original data */
    *(ULONG*)((PUCHAR)DataBase + 0x800) = 0x12345678;

    /* Close the data mapping */
    NtUnmapViewOfSection(NtCurrentProcess(), DataBase);

    NtClose(DataSectionHandle);

    /* Try to allocate memory inside the image mapping */
    DataBase = (PUCHAR)ImageBase + 0x20000;
    ViewSize = 0x1000;
    Status = NtAllocateVirtualMemory(NtCurrentProcess(), &DataBase, 0, &ViewSize, MEM_RESERVE, PAGE_NOACCESS);
    ok(Status ==  STATUS_CONFLICTING_ADDRESSES, "Wrong Status: 0x%lx\n", Status);

    /* Cleanup */
    NtClose(FileHandle);
    NtClose(ImageSectionHandle);
    NtUnmapViewOfSection(NtCurrentProcess(), ImageBase);
}