moved encode|image|splaytee into rtl

svn path=/trunk/; revision=9781
This commit is contained in:
Gunnar Dalsnes 2004-06-20 23:27:21 +00:00
parent d26418fb30
commit 75a50813aa
4 changed files with 302 additions and 1 deletions

80
reactos/lib/rtl/encode.c Normal file
View file

@ -0,0 +1,80 @@
/* $Id: encode.c,v 1.1 2004/06/20 23:27:21 gdalsnes Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Security descriptor functions
* FILE: lib/rtl/encode.c
* PROGRAMMER: KJK::Hyperion <noog@libero.it>
* REVISION HISTORY:
* 02/04/2003: created (code contributed by crazylord
* <crazyl0rd@minithins.net>)
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <ntdll/ntdll.h>
/* FUNCTIONS ***************************************************************/
VOID STDCALL
RtlRunDecodeUnicodeString (IN UCHAR Hash,
IN OUT PUNICODE_STRING String)
{
PUCHAR ptr;
USHORT i;
ptr = (PUCHAR)String->Buffer;
if (String->Length > 1)
{
for (i = String->Length; i > 1; i--)
{
ptr[i - 1] ^= ptr[i - 2] ^ Hash;
}
}
if (String->Length >= 1)
{
ptr[0] ^= Hash | (UCHAR)0x43;
}
}
VOID STDCALL
RtlRunEncodeUnicodeString (IN OUT PUCHAR Hash,
IN OUT PUNICODE_STRING String)
{
LARGE_INTEGER CurrentTime;
PUCHAR ptr;
USHORT i;
NTSTATUS Status;
ptr = (PUCHAR) String->Buffer;
if (*Hash == 0)
{
Status = NtQuerySystemTime (&CurrentTime);
if (NT_SUCCESS(Status))
{
for (i = 1; i < sizeof(LARGE_INTEGER) && (*Hash == 0); i++)
*Hash |= *(PUCHAR)(((PUCHAR)&CurrentTime) + i);
}
if (*Hash == 0)
*Hash = 1;
}
if (String->Length >= 1)
{
ptr[0] ^= (*Hash) | (UCHAR)0x43;
if (String->Length > 1)
{
for (i = 1; i < String->Length; i++)
{
ptr[i] ^= ptr[i - 1] ^ (*Hash);
}
}
}
}
/* EOF */

148
reactos/lib/rtl/image.c Normal file
View file

@ -0,0 +1,148 @@
/* $Id: image.c,v 1.1 2004/06/20 23:27:21 gdalsnes Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: lib/ntdll/rtl/image.c
* PURPOSE: Image handling functions
* PROGRAMMER: Eric Kohl
* UPDATE HISTORY:
* 17/03/2000 Created
*/
#include <ddk/ntddk.h>
#include <ntdll/rtl.h>
#define NDEBUG
#include <ntdll/ntdll.h>
/* FUNCTIONS ****************************************************************/
/*
* @implemented
*/
PIMAGE_NT_HEADERS STDCALL
RtlImageNtHeader (IN PVOID BaseAddress)
{
PIMAGE_NT_HEADERS NtHeader;
PIMAGE_DOS_HEADER DosHeader = (PIMAGE_DOS_HEADER)BaseAddress;
if (DosHeader && DosHeader->e_magic != IMAGE_DOS_SIGNATURE)
{
DPRINT1("DosHeader->e_magic %x\n", DosHeader->e_magic);
DPRINT1("NtHeader %x\n", (BaseAddress + DosHeader->e_lfanew));
}
if (DosHeader && DosHeader->e_magic == IMAGE_DOS_SIGNATURE)
{
NtHeader = (PIMAGE_NT_HEADERS)(BaseAddress + DosHeader->e_lfanew);
if (NtHeader->Signature == IMAGE_NT_SIGNATURE)
return NtHeader;
}
return NULL;
}
/*
* @implemented
*/
PVOID
STDCALL
RtlImageDirectoryEntryToData (
PVOID BaseAddress,
BOOLEAN bFlag,
ULONG Directory,
PULONG Size
)
{
PIMAGE_NT_HEADERS NtHeader;
ULONG Va;
NtHeader = RtlImageNtHeader (BaseAddress);
if (NtHeader == NULL)
return NULL;
if (Directory >= NtHeader->OptionalHeader.NumberOfRvaAndSizes)
return NULL;
Va = NtHeader->OptionalHeader.DataDirectory[Directory].VirtualAddress;
if (Va == 0)
return NULL;
if (Size)
*Size = NtHeader->OptionalHeader.DataDirectory[Directory].Size;
if (bFlag)
return (PVOID)(BaseAddress + Va);
/* image mapped as ordinary file, we must find raw pointer */
return (PVOID)RtlImageRvaToVa (NtHeader, BaseAddress, Va, NULL);
}
/*
* @implemented
*/
PIMAGE_SECTION_HEADER
STDCALL
RtlImageRvaToSection (
PIMAGE_NT_HEADERS NtHeader,
PVOID BaseAddress,
ULONG Rva
)
{
PIMAGE_SECTION_HEADER Section;
ULONG Va;
ULONG Count;
Count = NtHeader->FileHeader.NumberOfSections;
Section = (PIMAGE_SECTION_HEADER)((ULONG)&NtHeader->OptionalHeader +
NtHeader->FileHeader.SizeOfOptionalHeader);
while (Count)
{
Va = Section->VirtualAddress;
if ((Va <= Rva) &&
(Rva < Va + Section->SizeOfRawData))
return Section;
Section++;
}
return NULL;
}
/*
* @implemented
*/
ULONG
STDCALL
RtlImageRvaToVa (
PIMAGE_NT_HEADERS NtHeader,
PVOID BaseAddress,
ULONG Rva,
PIMAGE_SECTION_HEADER *SectionHeader
)
{
PIMAGE_SECTION_HEADER Section = NULL;
if (SectionHeader)
Section = *SectionHeader;
if (Section == NULL ||
Rva < Section->VirtualAddress ||
Rva >= Section->VirtualAddress + Section->SizeOfRawData)
{
Section = RtlImageRvaToSection (NtHeader, BaseAddress, Rva);
if (Section == NULL)
return 0;
if (SectionHeader)
*SectionHeader = Section;
}
return (ULONG)(BaseAddress +
Rva +
Section->PointerToRawData -
Section->VirtualAddress);
}
/* EOF */

View file

@ -30,7 +30,10 @@ TARGET_OBJECTS = \
time.o \
timezone.o \
unicode.o \
version.o
version.o \
encode.o \
image.o \
splaytree.o
# atom
# registry

View file

@ -0,0 +1,70 @@
/*
* ReactOS kernel
* Copyright (C) 2003 ReactOS Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: splaytree.c,v 1.1 2004/06/20 23:27:21 gdalsnes Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* PURPOSE: Splay-Tree implementation
* FILE: lib/rtl/splaytree.c
*/
#include <ddk/ntddk.h>
/* FUNCTIONS *****************************************************************/
PRTL_SPLAY_LINKS STDCALL
RtlSubtreePredecessor (IN PRTL_SPLAY_LINKS Links)
{
PRTL_SPLAY_LINKS Child;
Child = Links->RightChild;
if (Child == NULL)
return NULL;
if (Child->LeftChild == NULL)
return Child;
/* Get left-most child */
while (Child->LeftChild != NULL)
Child = Child->LeftChild;
return Child;
}
PRTL_SPLAY_LINKS STDCALL
RtlSubtreeSuccessor (IN PRTL_SPLAY_LINKS Links)
{
PRTL_SPLAY_LINKS Child;
Child = Links->LeftChild;
if (Child == NULL)
return NULL;
if (Child->RightChild == NULL)
return Child;
/* Get right-most child */
while (Child->RightChild != NULL)
Child = Child->RightChild;
return Child;
}
/* EOF */