ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
April 2010
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
22 participants
435 discussions
Start a n
N
ew thread
[tkreuzer] 47027: [WIN32CSR] - Rewrite harderror handling. The old code was a monster function, leaking memory, using ansi rather than unicode strings and not getting this right. It was also vulnerable to attacks, making csrss crash, when corrupt parameters were sent.
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Mon Apr 26 03:23:21 2010 New Revision: 47027 URL:
http://svn.reactos.org/svn/reactos?rev=47027&view=rev
Log: [WIN32CSR] - Rewrite harderror handling. The old code was a monster function, leaking memory, using ansi rather than unicode strings and not getting this right. It was also vulnerable to attacks, making csrss crash, when corrupt parameters were sent. Added: trunk/reactos/subsystems/win32/csrss/win32csr/harderror.c (with props) Modified: trunk/reactos/subsystems/win32/csrss/win32csr/dllmain.c trunk/reactos/subsystems/win32/csrss/win32csr/w32csr.h trunk/reactos/subsystems/win32/csrss/win32csr/win32csr.rbuild Modified: trunk/reactos/subsystems/win32/csrss/win32csr/dllmain.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/win…
============================================================================== --- trunk/reactos/subsystems/win32/csrss/win32csr/dllmain.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrss/win32csr/dllmain.c [iso-8859-1] Mon Apr 26 03:23:21 2010 @@ -180,402 +180,6 @@ return TRUE; } -static BOOL WINAPI -Win32CsrHardError(IN PCSRSS_PROCESS_DATA ProcessData, - IN PHARDERROR_MSG HardErrorMessage) -{ - UINT responce = MB_OK; - NTSTATUS Status; - HANDLE hProcess; - OBJECT_ATTRIBUTES ObjectAttributes; - ULONG nParam = 0; - PRTL_MESSAGE_RESOURCE_ENTRY MessageResource; - ULONG_PTR ParameterList[MAXIMUM_HARDERROR_PARAMETERS]; - LPSTR CaptionText, MessageBody; - LPWSTR szxCaptionText, szxMessageBody; - DWORD SizeOfAllUnicodeStrings = 0; - PROCESS_BASIC_INFORMATION ClientBasicInfo; - UNICODE_STRING ClientFileNameU; - UNICODE_STRING TempStringU; - UNICODE_STRING ParameterStringU; - ANSI_STRING ParamStringA; - ULONG UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask; - int MessageBoxResponse; - - HardErrorMessage->Response = ResponseNotHandled; - - DPRINT("NumberOfParameters = %d\n", HardErrorMessage->NumberOfParameters); - DPRINT("Status = %lx\n", HardErrorMessage->Status); - - // open client process - InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL); - Status = NtOpenProcess(&hProcess, PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, &ObjectAttributes, &HardErrorMessage->h.ClientId); - if( !NT_SUCCESS(Status) ) { - DPRINT1("NtOpenProcess failed with code: %lx\n", Status); - return FALSE; - } - - // let's get a name of the client process to display it in the caption of a message box - - ClientFileNameU.MaximumLength = 0; - ClientFileNameU.Length = 0; - ClientFileNameU.Buffer = NULL; - Status = NtQueryInformationProcess(hProcess, - ProcessBasicInformation, - &ClientBasicInfo, - sizeof(ClientBasicInfo), - NULL); - if( NT_SUCCESS(Status) ) { - PLIST_ENTRY ModuleListHead; - PLIST_ENTRY Entry; - PLDR_DATA_TABLE_ENTRY Module; - PPEB_LDR_DATA Ldr; - PPEB Peb = ClientBasicInfo.PebBaseAddress; - - if( Peb ) - { - Status = NtReadVirtualMemory(hProcess, &Peb->Ldr, &Ldr, sizeof(Ldr), NULL); - if( NT_SUCCESS(Status) ) { - ModuleListHead = &Ldr->InLoadOrderModuleList; - Status = NtReadVirtualMemory( - hProcess, - &ModuleListHead->Flink, - &Entry, - sizeof(Entry), - NULL - ); - - if( NT_SUCCESS(Status) ) - { - if (Entry != ModuleListHead) - { - LDR_DATA_TABLE_ENTRY ModuleData; - Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); - - Status = NtReadVirtualMemory(hProcess, Module, &ModuleData, sizeof(ModuleData), NULL); - if( NT_SUCCESS(Status) ) { - PVOID ClientDllBase; - - Status = NtReadVirtualMemory( - hProcess, - &Peb->ImageBaseAddress, - &ClientDllBase, - sizeof(ClientDllBase), - NULL - ); - if( NT_SUCCESS(Status) && (ClientDllBase == ModuleData.DllBase) ) { - - ClientFileNameU.MaximumLength = ModuleData.BaseDllName.MaximumLength; - ClientFileNameU.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, ClientFileNameU.MaximumLength); - Status = NtReadVirtualMemory( - hProcess, - ModuleData.BaseDllName.Buffer, - ClientFileNameU.Buffer, - ClientFileNameU.MaximumLength, - NULL - ); - if( NT_SUCCESS(Status) ) { - ClientFileNameU.Length = wcslen(ClientFileNameU.Buffer)*sizeof(wchar_t); - } - else { - RtlFreeHeap (RtlGetProcessHeap(), 0, ClientFileNameU.Buffer); - ClientFileNameU.Buffer = NULL; - } - - DPRINT("ClientFileNameU=\'%wZ\'\n", &ClientFileNameU); - } - } - } - } - } - } - } - - // read all unicode strings from client space - for(nParam = 0; nParam < HardErrorMessage->NumberOfParameters; nParam++, UnicodeStringParameterMask >>= 1) - { - if( UnicodeStringParameterMask & 0x01 ) { - Status = NtReadVirtualMemory(hProcess, - (PVOID)HardErrorMessage->Parameters[nParam], - (PVOID)&TempStringU, - sizeof(TempStringU), - NULL); - - if( NT_SUCCESS(Status) ) { - ParameterStringU.Buffer = (PWSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, TempStringU.MaximumLength); - if( !ParameterStringU.Buffer ) { - DPRINT1("Cannot allocate memory %d\n", TempStringU.MaximumLength); - NtClose(hProcess); - if( ClientFileNameU.Buffer ) { - RtlFreeHeap (RtlGetProcessHeap(), 0, ClientFileNameU.Buffer); - } - return FALSE; - } - - Status = NtReadVirtualMemory(hProcess, - (PVOID)TempStringU.Buffer, - (PVOID)ParameterStringU.Buffer, - TempStringU.MaximumLength, - NULL); - if( !NT_SUCCESS(Status) ) { - DPRINT1("NtReadVirtualMemory failed with code: %lx\n", Status); - RtlFreeHeap (RtlGetProcessHeap(), 0, ParameterStringU.Buffer); - if( ClientFileNameU.Buffer ) { - RtlFreeHeap (RtlGetProcessHeap(), 0, ClientFileNameU.Buffer); - } - NtClose(hProcess); - return FALSE; - } - ParameterStringU.Length = TempStringU.Length; - ParameterStringU.MaximumLength = TempStringU.MaximumLength; - DPRINT("ParameterStringU=\'%wZ\'\n", &ParameterStringU); - RtlUnicodeStringToAnsiString(&ParamStringA, &ParameterStringU, TRUE); - ParameterList[nParam] = (ULONG_PTR)ParamStringA.Buffer; - SizeOfAllUnicodeStrings += ParamStringA.MaximumLength; - } - } - else { - // it's not a unicode string - ParameterList[nParam] = HardErrorMessage->Parameters[nParam]; - } - } - - NtClose(hProcess); - - // get text string of the error code - Status = RtlFindMessage( - (PVOID)GetModuleHandle(TEXT("ntdll")), - (ULONG_PTR)RT_MESSAGETABLE, - LANG_NEUTRAL, - HardErrorMessage->Status, - &MessageResource ); - if( !NT_SUCCESS(Status) ) { - // WE HAVE TO DISPLAY HERE: "Unknown hard error" - if( ClientFileNameU.Buffer ) { - szxCaptionText = (LPWSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, ClientFileNameU.MaximumLength+64); - wsprintfW(szxCaptionText, L"%s - %hs", ClientFileNameU.Buffer, "Application Error"); - } else { - szxCaptionText = (LPWSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, 64); - wsprintfW(szxCaptionText, L"System - Application Error"); - } - MessageBody = (LPSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, 38); - wsprintfA(MessageBody, "Unknown hard error"); - } - else { - LPSTR NtStatusString; - UNICODE_STRING MessageU; - ANSI_STRING MessageA; - USHORT CaptionSize = 0; - - if( !MessageResource->Flags ) { - /* we've got an ansi string */ - DPRINT("MessageResource->Text=%s\n", (PSTR)MessageResource->Text); - RtlInitAnsiString(&MessageA, MessageResource->Text); - } - else { - /* we've got a unicode string */ - DPRINT("MessageResource->Text=%S\n", (PWSTR)MessageResource->Text); - RtlInitUnicodeString(&MessageU, (PWSTR)MessageResource->Text); - RtlUnicodeStringToAnsiString(&MessageA, &MessageU, TRUE); - } - - // check whether a caption exists - if( *MessageA.Buffer == '{' ) { - // get size of the caption - for( CaptionSize = 0; (CaptionSize < MessageA.Length) && ('}' != MessageA.Buffer[CaptionSize]); CaptionSize++); - - CaptionText = (LPSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, CaptionSize); - RtlCopyMemory(CaptionText, MessageA.Buffer+1, CaptionSize-1); - CaptionSize += 2; // "}\r\n" - 3 - - szxCaptionText = (LPWSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(wchar_t)*CaptionSize+ClientFileNameU.MaximumLength+128); - if( ClientFileNameU.Buffer ) { - wsprintfW(szxCaptionText, L"%s - %hs", ClientFileNameU.Buffer, CaptionText); - } else { - wsprintfW(szxCaptionText, L"System - %hs", CaptionText); - } - RtlFreeHeap (RtlGetProcessHeap(), 0, CaptionText); - } - else { - if( ClientFileNameU.Buffer ) { - szxCaptionText = (LPWSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, ClientFileNameU.MaximumLength); - wsprintfW(szxCaptionText, L"%s", ClientFileNameU.Buffer); - } else { - szxCaptionText = (LPWSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, 14); // 14 - "System\0\0" - wsprintfW(szxCaptionText, L"System"); - } - } - DPRINT("ParameterList[0]=0x%lx\n", ParameterList[0]); - if( STATUS_UNHANDLED_EXCEPTION == HardErrorMessage->Status ) - { - PRTL_MESSAGE_RESOURCE_ENTRY MsgResException; - MessageBody = NULL; - Status = RtlFindMessage( - (PVOID)GetModuleHandle(TEXT("ntdll")), - (ULONG_PTR)RT_MESSAGETABLE, - LANG_NEUTRAL, - ParameterList[0], - &MsgResException); - - if( NT_SUCCESS(Status) ) - { - UNICODE_STRING ExcMessageU; - ANSI_STRING ExcMessageA; - if( !MsgResException->Flags ) { - /* we've got an ansi string */ - DPRINT("MsgResException->Text=%s\n", (PSTR)MsgResException->Text); - RtlInitAnsiString(&ExcMessageA, MsgResException->Text); - } - else { - /* we've got a unicode string */ - DPRINT("MsgResException->Text=%S\n", (PWSTR)MsgResException->Text); - RtlInitUnicodeString(&ExcMessageU, (PWSTR)MsgResException->Text); - RtlUnicodeStringToAnsiString(&ExcMessageA, &ExcMessageU, TRUE); - } - - MessageBody = (LPSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, MsgResException->Length+SizeOfAllUnicodeStrings+1024); // 1024 is a magic number I think it should be enough - if( STATUS_ACCESS_VIOLATION == ParameterList[0] ) { - LPSTR pOperationType; - if( ParameterList[2] ) pOperationType = "written"; - else pOperationType = "read"; - wsprintfA(MessageBody, ExcMessageA.Buffer, ParameterList[1], ParameterList[3], pOperationType); - } - else if( STATUS_IN_PAGE_ERROR == ParameterList[0] ) { - wsprintfA(MessageBody, ExcMessageA.Buffer, ParameterList[1], ParameterList[3], ParameterList[2]); - } - } - if( !MessageBody ) { - NtStatusString = (LPSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, MessageResource->Length-CaptionSize); - RtlCopyMemory(NtStatusString, MessageA.Buffer+CaptionSize, (MessageResource->Length-CaptionSize)-1); - - MessageBody = (LPSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, MessageResource->Length+SizeOfAllUnicodeStrings+1024); // 1024 is a magic number I think it should be enough - - wsprintfA(MessageBody, NtStatusString, - L"Unknown software exception", - ParameterList[0], - ParameterList[1]); - - RtlFreeHeap (RtlGetProcessHeap(), 0, NtStatusString); - } - } - else - { - NtStatusString = (LPSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, MessageResource->Length-CaptionSize); - RtlCopyMemory(NtStatusString, MessageA.Buffer+CaptionSize, (MessageResource->Length-CaptionSize)-1); - - MessageBody = (LPSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, MessageResource->Length+SizeOfAllUnicodeStrings+1024); // 1024 is a magic number I think it should be enough - - wsprintfA(MessageBody, NtStatusString, - ParameterList[0], - ParameterList[1], - ParameterList[2], - ParameterList[3]); - - RtlFreeHeap (RtlGetProcessHeap(), 0, NtStatusString); - } - if( MessageResource->Flags ) { - /* we've got a unicode string */ - RtlFreeAnsiString(&MessageA); - } - } - if( ClientFileNameU.Buffer ) { - RtlFreeHeap (RtlGetProcessHeap(), 0, ClientFileNameU.Buffer); - } - - szxMessageBody = (LPWSTR)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(wchar_t)*(strlen(MessageBody)+1)); - wsprintfW(szxMessageBody, L"%hs", MessageBody); - RtlFreeHeap (RtlGetProcessHeap(), 0, MessageBody); - - switch ( HardErrorMessage->ValidResponseOptions ) - { - case OptionAbortRetryIgnore: - responce = MB_ABORTRETRYIGNORE; - break; - - case OptionOk: - responce = MB_OK; - break; - - case OptionOkCancel: - responce = MB_OKCANCEL; - break; - - case OptionRetryCancel: - responce = MB_RETRYCANCEL; - break; - - case OptionYesNo: - responce = MB_YESNO; - break; - - case OptionYesNoCancel: - responce = MB_YESNOCANCEL; - break; - - case OptionShutdownSystem: - // XZ?? - break; - - default: - DPRINT1("Wrong option: ValidResponseOptions = %d\n", HardErrorMessage->ValidResponseOptions); - ASSERT(FALSE); - break; - } - - // FIXME: We should not use MessageBox !!!! - DPRINT1("%S\n", szxMessageBody); - MessageBoxResponse = MessageBoxW(0, szxMessageBody, szxCaptionText, responce|MB_ICONERROR|MB_SYSTEMMODAL|MB_SETFOREGROUND); - - RtlFreeHeap (RtlGetProcessHeap(), 0, szxMessageBody); - RtlFreeHeap (RtlGetProcessHeap(), 0, szxCaptionText); - - switch( MessageBoxResponse ) - { - case IDOK: - HardErrorMessage->Response = ResponseOk; - break; - - case IDCANCEL: - HardErrorMessage->Response = ResponseCancel; - break; - - case IDYES: - HardErrorMessage->Response = ResponseYes; - break; - - case IDNO: - HardErrorMessage->Response = ResponseNo; - break; - - case IDABORT: - HardErrorMessage->Response = ResponseAbort; - break; - - case IDIGNORE: - HardErrorMessage->Response = ResponseIgnore; - break; - - case IDRETRY: - HardErrorMessage->Response = ResponseRetry; - break; - - case 10://IDTRYAGAIN: - HardErrorMessage->Response = ResponseTryAgain; - break; - - case 11://IDCONTINUE: - HardErrorMessage->Response = ResponseContinue; - break; - - default: - ASSERT(FALSE); - break; - } - - return TRUE; -} - - BOOL WINAPI Win32CsrInitialization(PCSRSS_API_DEFINITION *ApiDefinitions, PCSRSS_OBJECT_DEFINITION *ObjectDefinitions, Added: trunk/reactos/subsystems/win32/csrss/win32csr/harderror.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/win…
============================================================================== --- trunk/reactos/subsystems/win32/csrss/win32csr/harderror.c (added) +++ trunk/reactos/subsystems/win32/csrss/win32csr/harderror.c [iso-8859-1] Mon Apr 26 03:23:21 2010 @@ -1,0 +1,552 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: subsys/csrss/win32csr/dllmain.c + * PURPOSE: Initialization + * PROGRAMMERS: Dmitry Philippov (shedon(a)mail.ru) + * Timo Kreuzer (timo.kreuzer(a)reactos.org) + */ + +/* INCLUDES ******************************************************************/ + +#define NDEBUG +#include "w32csr.h" +#include <debug.h> +#include <strsafe.h> + +#define IDTRYAGAIN 10 +#define IDCONTINUE 11 + +/* FUNCTIONS *****************************************************************/ + +static +NTSTATUS +CsrpGetClientFileName( + OUT PUNICODE_STRING ClientFileNameU, + HANDLE hProcess) +{ + PLIST_ENTRY ModuleListHead; + PLIST_ENTRY Entry; + PLDR_DATA_TABLE_ENTRY Module; + PPEB_LDR_DATA Ldr; + PROCESS_BASIC_INFORMATION ClientBasicInfo; + LDR_DATA_TABLE_ENTRY ModuleData; + PVOID ClientDllBase; + NTSTATUS Status; + PPEB Peb; + + /* Initialize string */ + ClientFileNameU->MaximumLength = 0; + ClientFileNameU->Length = 0; + ClientFileNameU->Buffer = NULL; + + /* Query process information */ + Status = NtQueryInformationProcess(hProcess, + ProcessBasicInformation, + &ClientBasicInfo, + sizeof(ClientBasicInfo), + NULL); + if (!NT_SUCCESS(Status)) return Status; + + Peb = ClientBasicInfo.PebBaseAddress; + if (!Peb) return STATUS_UNSUCCESSFUL; + + Status = NtReadVirtualMemory(hProcess, &Peb->Ldr, &Ldr, sizeof(Ldr), NULL); + if (!NT_SUCCESS(Status)) return Status; + + ModuleListHead = &Ldr->InLoadOrderModuleList; + Status = NtReadVirtualMemory(hProcess, + &ModuleListHead->Flink, + &Entry, + sizeof(Entry), + NULL); + if (!NT_SUCCESS(Status)) return Status; + + if (Entry == ModuleListHead) return STATUS_UNSUCCESSFUL; + + Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); + + Status = NtReadVirtualMemory(hProcess, + Module, + &ModuleData, + sizeof(ModuleData), + NULL); + if (!NT_SUCCESS(Status)) return Status; + + Status = NtReadVirtualMemory(hProcess, + &Peb->ImageBaseAddress, + &ClientDllBase, + sizeof(ClientDllBase), + NULL); + if (!NT_SUCCESS(Status)) return Status; + + if (ClientDllBase != ModuleData.DllBase) return STATUS_UNSUCCESSFUL; + + ClientFileNameU->MaximumLength = ModuleData.BaseDllName.MaximumLength; + ClientFileNameU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + ClientFileNameU->MaximumLength); + + Status = NtReadVirtualMemory(hProcess, + ModuleData.BaseDllName.Buffer, + ClientFileNameU->Buffer, + ClientFileNameU->MaximumLength, + NULL); + if (!NT_SUCCESS(Status)) + { + RtlFreeHeap(RtlGetProcessHeap(), 0, ClientFileNameU->Buffer); + ClientFileNameU->Buffer = NULL; + ClientFileNameU->MaximumLength = 0; + return Status; + } + + ClientFileNameU->Length = wcslen(ClientFileNameU->Buffer)*sizeof(wchar_t); + DPRINT("ClientFileNameU=\'%wZ\'\n", &ClientFileNameU); + + return STATUS_SUCCESS; +} + + +static +NTSTATUS +CsrpCaptureStringParameters( + OUT PULONG_PTR Parameters, + OUT PULONG SizeOfAllUnicodeStrings, + IN PHARDERROR_MSG HardErrorMessage, + HANDLE hProcess) +{ + ULONG nParam, UnicodeStringParameterMask, Size = 0; + NTSTATUS Status; + UNICODE_STRING TempStringU; + PWSTR ParamString; + + UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask; + + /* Read all strings from client space */ + for (nParam = 0; + nParam < HardErrorMessage->NumberOfParameters; + nParam++, UnicodeStringParameterMask >>= 1) + { + Parameters[nParam] = 0; + + /* Check if the current parameter is a unicode string */ + if (UnicodeStringParameterMask & 0x01) + { + /* Read the UNICODE_STRING from the process memory */ + Status = NtReadVirtualMemory(hProcess, + (PVOID)HardErrorMessage->Parameters[nParam], + &TempStringU, + sizeof(TempStringU), + NULL); + + if (!NT_SUCCESS(Status)) return Status; + + /* Allocate a buffer for the string */ + ParamString = RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + TempStringU.Length + sizeof(WCHAR)); + + if (!ParamString) + { + DPRINT1("Cannot allocate memory %d\n", TempStringU.Length); + return STATUS_NO_MEMORY; + } + + /* Read the string buffer from the process memory */ + Status = NtReadVirtualMemory(hProcess, + TempStringU.Buffer, + ParamString, + TempStringU.Length, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtReadVirtualMemory failed with code: %lx\n", Status); + RtlFreeHeap(RtlGetProcessHeap(), 0, ParamString); + return Status; + } + + /* Zero terminate the string */ + ParamString[TempStringU.Length / sizeof(WCHAR)] = 0; + DPRINT("ParamString=\'%S\'\n", ParamString); + + Parameters[nParam] = (ULONG_PTR)ParamString; + Size += TempStringU.Length; + } + else + { + /* It's not a unicode string */ + Parameters[nParam] = HardErrorMessage->Parameters[nParam]; + } + } + + *SizeOfAllUnicodeStrings = Size; + return STATUS_SUCCESS; +} + +static +VOID +CsrpFreeStringParameters( + IN OUT PULONG_PTR Parameters, + IN PHARDERROR_MSG HardErrorMessage) +{ + ULONG nParam, UnicodeStringParameterMask; + + UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask; + + /* Loop all parameters */ + for (nParam = 0; + nParam < HardErrorMessage->NumberOfParameters; + nParam++, UnicodeStringParameterMask >>= 1) + { + /* Check if the current parameter is a string */ + if (UnicodeStringParameterMask & 0x01) + { + /* Free the string buffer */ + RtlFreeHeap(RtlGetProcessHeap(), 0, (PVOID)Parameters[nParam]); + } + } +} + + +static +NTSTATUS +CsrpFormatMessages( + OUT PUNICODE_STRING TextStringU, + OUT PUNICODE_STRING CaptionStringU, + IN PULONG_PTR Parameters, + IN ULONG SizeOfStrings, + IN PHARDERROR_MSG Message, + IN HANDLE hProcess) +{ + NTSTATUS Status; + UNICODE_STRING FileNameU, TempStringU, FormatU; + ANSI_STRING FormatA; + PRTL_MESSAGE_RESOURCE_ENTRY MessageResource; + PWSTR FormatString; + ULONG Size; + + /* Get the file name of the client process */ + CsrpGetClientFileName(&FileNameU, hProcess); + + /* Check if we have a file name */ + if (!FileNameU.Buffer) + { + /* No, use system */ + RtlInitUnicodeString(&FileNameU, L"System"); + } + + /* Get text string of the error code */ + Status = RtlFindMessage(GetModuleHandleW(L"ntdll"), + (ULONG_PTR)RT_MESSAGETABLE, + LANG_NEUTRAL, + Message->Status, + &MessageResource); + + if (NT_SUCCESS(Status)) + { + if (MessageResource->Flags) + { + RtlInitUnicodeString(&FormatU, (PWSTR)MessageResource->Text); + FormatA.Buffer = NULL; + } + else + { + RtlInitAnsiString(&FormatA, MessageResource->Text); + RtlAnsiStringToUnicodeString(&FormatU, &FormatA, TRUE); + } + } + else + { + /* Fall back to hardcoded value */ + RtlInitUnicodeString(&FormatU, L"Unknown Hard Error"); + FormatA.Buffer = NULL; + } + + FormatString = FormatU.Buffer; + + /* Check whether a caption exists */ + if (FormatString[0] == L'{') + { + /* Set caption start */ + TempStringU.Buffer = ++FormatString; + + /* Get size of the caption */ + for (Size = 0; *FormatString != 0 && *FormatString != L'}'; Size++) + FormatString++; + + /* Skip '}', '\r', '\n' */ + FormatString += 3; + + TempStringU.Length = Size * sizeof(WCHAR); + TempStringU.MaximumLength = TempStringU.Length; + } + else + { + /* FIXME: Set string based on severity */ + RtlInitUnicodeString(&TempStringU, L"Application Error"); + } + + /* Calculate buffer length for the caption */ + CaptionStringU->MaximumLength = FileNameU.Length + TempStringU.Length + + 4 * sizeof(WCHAR); + + /* Allocate a buffer for the caption */ + CaptionStringU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + CaptionStringU->MaximumLength); + + /* Append the file name, seperator and the caption text */ + CaptionStringU->Length = 0; + RtlAppendUnicodeStringToString(CaptionStringU, &FileNameU); + RtlAppendUnicodeToString(CaptionStringU, L" - "); + RtlAppendUnicodeStringToString(CaptionStringU, &TempStringU); + + /* Zero terminate the buffer */ + CaptionStringU->Buffer[CaptionStringU->Length] = 0; + + /* Free the file name buffer */ + RtlFreeUnicodeString(&FileNameU); + + /* Check if this is an exception message */ + if (Message->Status == STATUS_UNHANDLED_EXCEPTION) + { + /* Handle special cases */ + if (Parameters[0] == STATUS_ACCESS_VIOLATION) + { + Parameters[0] = Parameters[1]; + Parameters[1] = Parameters[3]; + if (Parameters[2]) Parameters[2] = (ULONG_PTR)L"written"; + else Parameters[2] = (ULONG_PTR)L"read"; + MessageResource = NULL; + } + else if (Parameters[0] == STATUS_IN_PAGE_ERROR) + { + Parameters[0] = Parameters[1]; + Parameters[1] = Parameters[3]; + MessageResource = NULL; + } + else + { + /* Fall back to hardcoded value */ + Parameters[2] = Parameters[1]; + Parameters[1] = Parameters[0]; + Parameters[0] = (ULONG_PTR)L"unknown software exception"; + } + + if (!MessageResource) + { + /* Get text string of the exception code */ + Status = RtlFindMessage(GetModuleHandleW(L"ntdll"), + (ULONG_PTR)RT_MESSAGETABLE, + LANG_NEUTRAL, + Parameters[0], + &MessageResource); + + if (NT_SUCCESS(Status)) + { + if (FormatA.Buffer) RtlFreeUnicodeString(&FormatU); + + if (MessageResource->Flags) + { + RtlInitUnicodeString(&FormatU, (PWSTR)MessageResource->Text); + FormatA.Buffer = NULL; + } + else + { + RtlInitAnsiString(&FormatA, MessageResource->Text); + RtlAnsiStringToUnicodeString(&FormatU, &FormatA, TRUE); + } + } + else + { + /* Fall back to hardcoded value */ + Parameters[2] = Parameters[1]; + Parameters[1] = Parameters[0]; + Parameters[0] = (ULONG_PTR)L"unknown software exception"; + } + } + } + + /* Calculate length of text buffer */ + TextStringU->MaximumLength = wcslen(FormatString) * sizeof(WCHAR) + + SizeOfStrings + 42 * sizeof(WCHAR); + + /* Allocate a buffer for the text */ + TextStringU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + TextStringU->MaximumLength); + + /* Wrap in SEH to protect from invalid string parameters */ + _SEH2_TRY + { + /* Print the string into the buffer */ + StringCbPrintfW(TextStringU->Buffer, + TextStringU->MaximumLength, + FormatString, + Parameters[0], + Parameters[1], + Parameters[2], + Parameters[3], + Parameters[4]); + Status = STATUS_SUCCESS; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + /* Set error and free buffers */ + Status = _SEH2_GetExceptionCode(); + RtlFreeHeap(RtlGetProcessHeap(), 0, TextStringU->Buffer); + RtlFreeHeap(RtlGetProcessHeap(), 0, CaptionStringU->Buffer); + } + _SEH2_END + + if (NT_SUCCESS(Status)) + { + TextStringU->Length = wcslen(TextStringU->Buffer) * sizeof(WCHAR); + } + + if (FormatA.Buffer) RtlFreeUnicodeString(&FormatU); + + return Status; +} + +static +ULONG +CsrpMessageBox( + PWSTR Text, + PWSTR Caption, + ULONG ValidResponseOptions, + ULONG Severity) +{ + ULONG Type, MessageBoxResponse; + + /* Set the message box type */ + switch (ValidResponseOptions) + { + case OptionAbortRetryIgnore: + Type = MB_ABORTRETRYIGNORE; + break; + case OptionOk: + Type = MB_OK; + break; + case OptionOkCancel: + Type = MB_OKCANCEL; + break; + case OptionRetryCancel: + Type = MB_RETRYCANCEL; + break; + case OptionYesNo: + Type = MB_YESNO; + break; + case OptionYesNoCancel: + Type = MB_YESNOCANCEL; + break; + case OptionShutdownSystem: + Type = MB_RETRYCANCEL; // FIXME??? + break; + /* Anything else is invalid */ + default: + return ResponseNotHandled; + } + + /* Set severity */ + if (Severity == STATUS_SEVERITY_INFORMATIONAL) Type |= MB_ICONINFORMATION; + else if (Severity == STATUS_SEVERITY_WARNING) Type |= MB_ICONWARNING; + else if (Severity == STATUS_SEVERITY_ERROR) Type |= MB_ICONERROR; + + Type |= MB_SYSTEMMODAL | MB_SETFOREGROUND; + + DPRINT("Text = '%S', Caption = '%S', Severity = %d, Type = 0x%lx\n", + Text, Caption, Severity, Type); + + /* Display a message box */ + MessageBoxResponse = MessageBoxW(0, Text, Caption, Type); + + /* Return response value */ + switch (MessageBoxResponse) + { + case IDOK: return ResponseOk; + case IDCANCEL: return ResponseCancel; + case IDYES: return ResponseYes; + case IDNO: return ResponseNo; + case IDABORT: return ResponseAbort; + case IDIGNORE: return ResponseIgnore; + case IDRETRY: return ResponseRetry; + case IDTRYAGAIN: return ResponseTryAgain; + case IDCONTINUE: return ResponseContinue; + } + + return ResponseNotHandled; +} + +BOOL +WINAPI +Win32CsrHardError( + IN PCSRSS_PROCESS_DATA ProcessData, + IN PHARDERROR_MSG Message) +{ + ULONG_PTR Parameters[MAXIMUM_HARDERROR_PARAMETERS]; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING TextU, CaptionU; + NTSTATUS Status; + HANDLE hProcess; + ULONG Size; + + /* Default to not handled */ + Message->Response = ResponseNotHandled; + + /* Make sure we don't have too many parameters */ + if (Message->NumberOfParameters > MAXIMUM_HARDERROR_PARAMETERS) + Message->NumberOfParameters = MAXIMUM_HARDERROR_PARAMETERS; + + /* Initialize object attributes */ + InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL); + + /* Open client process */ + Status = NtOpenProcess(&hProcess, + PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, + &ObjectAttributes, + &Message->h.ClientId); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtOpenProcess failed with code: %lx\n", Status); + return FALSE; + } + + /* Capture all string parameters from the process memory */ + Status = CsrpCaptureStringParameters(Parameters, &Size, Message, hProcess); + if (!NT_SUCCESS(Status)) + { + NtClose(hProcess); + return FALSE; + } + + /* Format the caption and message box text */ + Status = CsrpFormatMessages(&TextU, + &CaptionU, + Parameters, + Size, + Message, + hProcess); + + /* Cleanup */ + CsrpFreeStringParameters(Parameters, Message); + NtClose(hProcess); + + if (!NT_SUCCESS(Status)) + { + return FALSE; + } + + /* Display the message box */ + Message->Response = CsrpMessageBox(TextU.Buffer, + CaptionU.Buffer, + Message->ValidResponseOptions, + (ULONG)Message->Status >> 30); + + RtlFreeUnicodeString(&TextU); + RtlFreeUnicodeString(&CaptionU); + + return TRUE; +} + Propchange: trunk/reactos/subsystems/win32/csrss/win32csr/harderror.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/reactos/subsystems/win32/csrss/win32csr/w32csr.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/win…
============================================================================== --- trunk/reactos/subsystems/win32/csrss/win32csr/w32csr.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrss/win32csr/w32csr.h [iso-8859-1] Mon Apr 26 03:23:21 2010 @@ -35,4 +35,11 @@ /* shared header with console.dll */ #include "console.h" + +BOOL +WINAPI +Win32CsrHardError( + IN PCSRSS_PROCESS_DATA ProcessData, + IN PHARDERROR_MSG Message); + /* EOF */ Modified: trunk/reactos/subsystems/win32/csrss/win32csr/win32csr.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/win…
============================================================================== --- trunk/reactos/subsystems/win32/csrss/win32csr/win32csr.rbuild [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrss/win32csr/win32csr.rbuild [iso-8859-1] Mon Apr 26 03:23:21 2010 @@ -14,6 +14,7 @@ <library>advapi32</library> <library>win32ksys</library> <library>psapi</library> + <library>pseh</library> <pch>w32csr.h</pch> <file>alias.c</file> <file>conio.c</file> @@ -21,6 +22,7 @@ <file>dllmain.c</file> <file>exitros.c</file> <file>guiconsole.c</file> + <file>harderror.c</file> <file>tuiconsole.c</file> <file>appswitch.c</file> <file>win32csr.rc</file>
14 years, 8 months
1
0
0
0
[tkreuzer] 47026: [STRSAFE] Add strsafe.h from amd64 branch.
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Mon Apr 26 02:41:09 2010 New Revision: 47026 URL:
http://svn.reactos.org/svn/reactos?rev=47026&view=rev
Log: [STRSAFE] Add strsafe.h from amd64 branch. Added: trunk/reactos/include/psdk/strsafe.h (with props) Added: trunk/reactos/include/psdk/strsafe.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/strsafe.h?rev…
============================================================================== --- trunk/reactos/include/psdk/strsafe.h (added) +++ trunk/reactos/include/psdk/strsafe.h [iso-8859-1] Mon Apr 26 02:41:09 2010 @@ -1,0 +1,626 @@ +#ifndef __STRSAFE_H_ +#define __STRSAFE_H_ + +#include <stdlib.h> +#include <stdarg.h> + +#if defined(STRSAFE_NO_CCH_FUNCTIONS) && defined(STRSAFE_NO_CB_FUNCTIONS) +#error Both STRSAFE_NO_CCH_FUNCTIONS and STRSAFE_NO_CB_FUNCTIONS are defined +#endif + +#ifndef SUCCEEDED +#define SUCCEEDED(Status) ((HRESULT)(Status) >= 0) +#endif +#define STRSAFE_MAX_CCH 2147483647 +#define STRSAFE_E_INVALID_PARAMETER ((HRESULT)0x80070057L) +#define STRSAFE_E_INSUFFICIENT_BUFFER ((HRESULT)0x8007007AL) +#define STRSAFE_E_END_OF_FILE ((HRESULT)0x80070026L) + +#define STRSAFE_FILL_BEHIND_NULL 0x00000200 +#define STRSAFE_IGNORE_NULLS 0x00000200 +#define STRSAFE_FILL_ON_FAILURE 0x00000400 +#define STRSAFE_NULL_ON_FAILURE 0x00000800 +#define STRSAFE_NO_TRUNCATION 0x00001000 + +#ifndef S_OK +#define S_OK ((HRESULT)0x00000000L) +#endif + +#define STRSAFE_MIN(a,b) (((a) < (b))?(a):(b)) + +#ifndef _HRESULT_DEFINED +#define _HRESULT_DEFINED +typedef long HRESULT; +#endif + +typedef char * STRSAFE_LPSTR; +typedef const char * STRSAFE_LPCSTR; +typedef wchar_t * STRSAFE_LPWSTR; +typedef const wchar_t * STRSAFE_LPCWSTR; +typedef unsigned long STRSAFE_DWORD; + +#define STRSAFE_PASS2 + +/* Implement Cb functions for ansi and unicode */ +#ifndef STRSAFE_NO_CB_FUNCTIONS +#define STRSAFE_CB +#define STRSAFE_UNICODE 0 +# include <strsafe.h> +#undef STRSAFE_UNICODE +#define STRSAFE_UNICODE 1 +# include <strsafe.h> +#undef STRSAFE_UNICODE +#undef STRSAFE_CB +#endif // !STRSAFE_NO_CB_FUNCTIONS + +/* Implement Cch functions for ansi and unicode */ +#ifndef STRSAFE_NO_CCH_FUNCTIONS +#define STRSAFE_UNICODE 0 +# include <strsafe.h> +#undef STRSAFE_UNICODE +#define STRSAFE_UNICODE 1 +# include <strsafe.h> +#undef STRSAFE_UNICODE +#endif // !STRSAFE_NO_CCH_FUNCTIONS + +#undef STRSAFE_PASS2 + +/* Now define the functions depending on UNICODE */ +#if defined(UNICODE) +# define STRSAFE_UNICODE 1 +#else +# define STRSAFE_UNICODE 0 +#endif +#include <strsafe.h> +#undef STRSAFE_UNICODE + +#endif // !__STRSAFE_H_ + +/*****************************************************************************/ + +#if defined(STRSAFE_UNICODE) +#if (STRSAFE_UNICODE == 1) + +#define STRSAFE_LPTSTR STRSAFE_LPWSTR +#define STRSAFE_LPCTSTR STRSAFE_LPCWSTR +#define STRSAFE_TCHAR wchar_t + +#define StringCbCat StringCbCatW +#define StringCbCatEx StringCbCatExW +#define StringCbCatN StringCbCatNW +#define StringCbCatNEx StringCbCatNExW +#define StringCbCatWorker StringCxxCatWorkerW +#define StringCbCopy StringCbCopyW +#define StringCbCopyEx StringCbCopyExW +#define StringCbCopyN StringCbCopyNW +#define StringCbCopyNEx StringCbCopyNExW +#define StringCbGets StringCbGetsW +#define StringCbGetsEx StringCbGetsExW +#define StringCbLength StringCbLengthW +#define StringCbPrintf StringCbPrintfW +#define StringCbPrintfEx StringCbPrintfExW +#define StringCbVPrintf StringCbVPrintfW +#define StringCbVPrintfEx StringCbVPrintfExW +#define StringCchCat StringCchCatW +#define StringCchCatEx StringCchCatExW +#define StringCchCatN StringCchCatNW +#define StringCchCatNEx StringCchCatNExW +#define StringCchCatWorker StringCchCatWorkerW +#define StringCchCopy StringCchCopyW +#define StringCchCopyEx StringCchCopyExW +#define StringCchCopyN StringCchCopyNW +#define StringCchCopyNEx StringCchCopyNExW +#define StringCchGets StringCchGetsW +#define StringCchGetsEx StringCchGetsExW +#define StringCchLength StringCchLengthW +#define StringCchPrintf StringCchPrintfW +#define StringCchPrintfEx StringCchPrintfExW +#define StringCchVPrintf StringCchVPrintfW +#define StringCchVPrintfEx StringCchVPrintfExW +#define _vsnprintfAW _vsnwprintf + +#else // (STRSAFE_UNICODE != 1) + +#define STRSAFE_LPTSTR STRSAFE_LPSTR +#define STRSAFE_LPCTSTR STRSAFE_LPCSTR +#define STRSAFE_TCHAR char + +#define StringCbCat StringCbCatA +#define StringCbCatEx StringCbCatExA +#define StringCbCatN StringCbCatNA +#define StringCbCatNEx StringCbCatNExA +#define StringCbCatWorker StringCxxCatWorkerA +#define StringCbCopy StringCbCopyA +#define StringCbCopyEx StringCbCopyExA +#define StringCbCopyN StringCbCopyNA +#define StringCbCopyNEx StringCbCopyNExA +#define StringCbGets StringCbGetsA +#define StringCbGetsEx StringCbGetsExA +#define StringCbLength StringCbLengthA +#define StringCbPrintf StringCbPrintfA +#define StringCbPrintfEx StringCbPrintfExA +#define StringCbVPrintf StringCbVPrintfA +#define StringCbVPrintfEx StringCbVPrintfExA +#define StringCchCat StringCchCatA +#define StringCchCatEx StringCchCatExA +#define StringCchCatN StringCchCatNA +#define StringCchCatNEx StringCchCatNExA +#define StringCchCatWorker StringCchCatWorkerA +#define StringCchCopy StringCchCopyA +#define StringCchCopyEx StringCchCopyExA +#define StringCchCopyN StringCchCopyNA +#define StringCchCopyNEx StringCchCopyNExA +#define StringCchGets StringCchGetsA +#define StringCchGetsEx StringCchGetsExA +#define StringCchLength StringCchLengthA +#define StringCchPrintf StringCchPrintfA +#define StringCchPrintfEx StringCchPrintfExA +#define StringCchVPrintf StringCchVPrintfA +#define StringCchVPrintfEx StringCchVPrintfExA +#define _vsnprintfAW _vsnprintf + +#endif // (STRSAFE_UNICODE != 1) +#endif // defined(STRSAFE_UNICODE) + +/*****************************************************************************/ + +#if defined (STRSAFE_PASS2) + +#if defined(STRSAFE_CB) + +#define STRSAFE_CXXtoCB(x) (x) +#define STRSAFE_CBtoCXX(x) (x) +#define STRSAFE_CXXtoCCH(x) (x)/sizeof(STRSAFE_TCHAR) +#define STRSAFE_CCHtoCXX(x) (x)*sizeof(STRSAFE_TCHAR) +#define StringCxxCat StringCbCat +#define StringCxxCatEx StringCbCatEx +#define StringCxxCatN StringCbCatN +#define StringCxxCatNEx StringCbCatNEx +#define StringCxxCatWorker StringCbCatWorker +#define StringCxxCopy StringCbCopy +#define StringCxxCopyEx StringCbCopyEx +#define StringCxxCopyN StringCbCopyN +#define StringCxxCopyNEx StringCbCopyNEx +#define StringCxxGets StringCbGets +#define StringCxxGetsEx StringCbGetsEx +#define StringCxxLength StringCbLength +#define StringCxxPrintf StringCbPrintf +#define StringCxxPrintfEx StringCbPrintfEx +#define StringCxxVPrintf StringCbVPrintf +#define StringCxxVPrintfEx StringCbVPrintfEx + +#else // !STRSAFE_CB + +#define STRSAFE_CXXtoCB(x) (x)*sizeof(STRSAFE_TCHAR) +#define STRSAFE_CBtoCXX(x) (x)/sizeof(STRSAFE_TCHAR) +#define STRSAFE_CXXtoCCH(x) (x) +#define STRSAFE_CCHtoCXX(x) (x) +#define StringCxxCat StringCchCat +#define StringCxxCatEx StringCchCatEx +#define StringCxxCatN StringCchCatN +#define StringCxxCatNEx StringCchCatNEx +#define StringCxxCatWorker StringCchCatWorker +#define StringCxxCopy StringCchCopy +#define StringCxxCopyEx StringCchCopyEx +#define StringCxxCopyN StringCchCopyN +#define StringCxxCopyNEx StringCchCopyNEx +#define StringCxxGets StringCchGets +#define StringCxxGetsEx StringCchGetsEx +#define StringCxxLength StringCchLength +#define StringCxxPrintf StringCchPrintf +#define StringCxxPrintfEx StringCchPrintfEx +#define StringCxxVPrintf StringCchVPrintf +#define StringCxxVPrintfEx StringCchVPrintfEx + +#endif // !STRSAFE_CB + +#ifdef STRSAFE_LIB + +/* Normal function prototypes only */ +#define STRSAFEAPI HRESULT __stdcall + +STRSAFEAPI StringCxxCat(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszSrc); +STRSAFEAPI StringCxxCatEx(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszSrc, STRSAFE_LPTSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags); +STRSAFEAPI StringCxxCatN(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszSrc, size_t cbMaxAppend); +STRSAFEAPI StringCxxCatNEx(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszSrc, size_t cbMaxAppend, STRSAFE_LPTSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags); +STRSAFEAPI StringCxxCopy(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszSrc); +STRSAFEAPI StringCxxCopyEx(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszSrc, STRSAFE_LPTSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags); +STRSAFEAPI StringCxxCopyN(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszSrc, size_t cbSrc); +STRSAFEAPI StringCxxCopyNEx(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszSrc, size_t cbSrc, STRSAFE_LPTSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags); +STRSAFEAPI StringCxxGets(STRSAFE_LPTSTR pszDest, size_t cxDest); +STRSAFEAPI StringCxxGetsEx(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPTSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags); +STRSAFEAPI StringCxxLength(STRSAFE_LPCTSTR psz, size_t cxMax, size_t *pcb); +STRSAFEAPI StringCxxPrintf(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszFormat, ...); +STRSAFEAPI StringCxxPrintfEx(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPTSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCTSTR pszFormat, ...); +STRSAFEAPI StringCxxVPrintf(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPCTSTR pszFormat, va_list args); +STRSAFEAPI StringCxxVPrintfEx(STRSAFE_LPTSTR pszDest, size_t cxDest, STRSAFE_LPTSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags, LPCTSTR pszFormat, va_list args); + +#else // !STRSAFE_LIB + +/* Create inlined versions */ +#define STRSAFEAPI HRESULT static __inline__ + +#define STRSAFE_MAX_CXX STRSAFE_CCHtoCXX(STRSAFE_MAX_CCH) + +STRSAFEAPI +StringCxxCatWorker( + STRSAFE_LPTSTR pszDest, + size_t cxDest, + STRSAFE_LPCTSTR pszSrc, + size_t cxMaxAppend, + STRSAFE_LPTSTR *ppszDestEnd, + size_t *pcbRemaining, + STRSAFE_DWORD dwFlags, + int UseN) +{ + HRESULT result; + STRSAFE_LPTSTR psz = pszDest; + size_t cch = STRSAFE_CXXtoCCH(cxDest); + + if (!pszDest || !pszSrc || cxDest > STRSAFE_MAX_CXX || cxDest == 0) + { + return STRSAFE_E_INVALID_PARAMETER; + } + + for (--psz; *(++psz) != 0 && --cch > 0;); + if (cch == 0) + { + return STRSAFE_E_INSUFFICIENT_BUFFER; + } + + if (UseN) + { + cch = STRSAFE_MIN(cxDest, STRSAFE_CXXtoCCH(cxMaxAppend)); + } + + for (--pszSrc, --psz; (*(++psz) = *(++pszSrc)) != 0 && --cch > 0;); + if (cch == 0) + { + result = STRSAFE_E_INSUFFICIENT_BUFFER; + } + else + result = S_OK; + + if (ppszDestEnd) + { + *ppszDestEnd = psz; + } + + if (pcbRemaining) + { + *pcbRemaining = STRSAFE_CCHtoCXX(cch); + } + + if (dwFlags & STRSAFE_FILL_BEHIND_NULL) + { + for (--psz, ++cch; --cch; *(++psz) = dwFlags & 0xff); + } + + if (!SUCCEEDED(result)) + { + if (dwFlags & STRSAFE_FILL_ON_FAILURE) + { + cch = STRSAFE_CXXtoCCH(cxDest); + for (--pszDest, ++cch; --cch; *(++pszDest) = dwFlags & 0xff); + } + + if (dwFlags & STRSAFE_NULL_ON_FAILURE) + { + *pszDest = 0; + } + } + + return result; +} + +STRSAFEAPI +StringCxxCatEx( + STRSAFE_LPTSTR pszDest, + size_t cxDest, + STRSAFE_LPCTSTR pszSrc, + STRSAFE_LPTSTR *ppszDestEnd, + size_t *pcbRemaining, + STRSAFE_DWORD dwFlags) +{ + return StringCxxCatWorker(pszDest, cxDest, pszSrc, 0, ppszDestEnd, pcbRemaining, dwFlags, 0); +} + +STRSAFEAPI +StringCxxCat( + STRSAFE_LPTSTR pszDest, + size_t cxDest, + STRSAFE_LPCTSTR pszSrc) +{ + return StringCxxCatWorker(pszDest, cxDest, pszSrc, 0, NULL, NULL, 0, 0); +} + +STRSAFEAPI +StringCxxCatN( + STRSAFE_LPTSTR pszDest, + size_t cxDest, + STRSAFE_LPCTSTR pszSrc, + size_t cbMaxAppend) +{ + return StringCxxCatWorker(pszDest, cxDest, pszSrc, cbMaxAppend, NULL, NULL, 0, 1); +} + +STRSAFEAPI +StringCxxCatNEx( + STRSAFE_LPTSTR pszDest, + size_t cxDest, + STRSAFE_LPCTSTR pszSrc, + size_t cbMaxAppend, + STRSAFE_LPTSTR *ppszDestEnd, + size_t *pcbRemaining, + STRSAFE_DWORD dwFlags) +{ + return StringCxxCatWorker(pszDest, cxDest, pszSrc, cbMaxAppend, ppszDestEnd, pcbRemaining, dwFlags, 1); +} + +STRSAFEAPI +StringCxxCopy( + STRSAFE_LPTSTR pszDest, + size_t cbDest, + STRSAFE_LPCTSTR pszSrc) +{ + return 0; // FIXME +} + +STRSAFEAPI +StringCxxCopyEx( + STRSAFE_LPTSTR pszDest, + size_t cbDest, + STRSAFE_LPCTSTR pszSrc, + STRSAFE_LPTSTR *ppszDestEnd, + size_t *pcbRemaining, + STRSAFE_DWORD dwFlags) +{ + return 0; // FIXME +} + +STRSAFEAPI +StringCxxCopyN( + STRSAFE_LPTSTR pszDest, + size_t cbDest, + STRSAFE_LPCTSTR pszSrc, + size_t cbSrc) +{ + return 0; // FIXME +} + +STRSAFEAPI +StringCxxCopyNEx( + STRSAFE_LPTSTR pszDest, + size_t cbDest, + STRSAFE_LPCTSTR pszSrc, + size_t cbSrc, + STRSAFE_LPTSTR *ppszDestEnd, + size_t *pcbRemaining, + STRSAFE_DWORD dwFlags) +{ + return 0; // FIXME +} + +STRSAFEAPI +StringCxxGets( + STRSAFE_LPTSTR pszDest, + size_t cbDest) +{ + return 0; // FIXME +} + +STRSAFEAPI +StringCxxGetsEx( + STRSAFE_LPTSTR pszDest, + size_t cbDest, + STRSAFE_LPTSTR *ppszDestEnd, + size_t *pcbRemaining, + STRSAFE_DWORD dwFlags) +{ + return 0; // FIXME +} + +STRSAFEAPI +StringCxxLength( + STRSAFE_LPCTSTR psz, + size_t cxMax, + size_t *pcx) +{ + size_t cch = STRSAFE_CXXtoCCH(cxMax); + + /* Default return on error */ + if (pcx) + *pcx = 0; + + if (!psz || cxMax > STRSAFE_MAX_CXX || cxMax == 0) + { + return STRSAFE_E_INVALID_PARAMETER; + } + + for (--psz; *(++psz) != 0 && --cch > 0;); + + if (cch == 0) + { + return STRSAFE_E_INVALID_PARAMETER; + } + + if (pcx) + *pcx = cxMax - STRSAFE_CCHtoCXX(cch); + + return S_OK; +} + +STRSAFEAPI +StringCxxVPrintfEx( + STRSAFE_LPTSTR pszDest, + size_t cxDest, + STRSAFE_LPTSTR *ppszDestEnd, + size_t *pcxRemaining, + STRSAFE_DWORD dwFlags, + STRSAFE_LPCTSTR pszFormat, + va_list args) +{ + size_t cchDest = STRSAFE_CXXtoCCH(cxDest); + size_t cchMax = cchDest - 1; + int iResult; + HRESULT hr; + + if (dwFlags & STRSAFE_IGNORE_NULLS) + { + if (!pszDest) pszDest = (STRSAFE_LPTSTR)L""; + if (!pszFormat) pszFormat = (STRSAFE_LPTSTR)L""; + } + + if (!pszDest || !pszFormat || cxDest > STRSAFE_MAX_CXX || cxDest == 0) + { + return STRSAFE_E_INVALID_PARAMETER; + } + +#if (STRSAFE_USE_SECURE_CRT == 1) + iResult = _vsnprintf_sAW(pszDest, cchDest, cchMax, pszFormat, args); +#else + iResult = _vsnprintfAW(pszDest, cchMax, pszFormat, args); +#endif + + hr = (iResult == -1) ? STRSAFE_E_INSUFFICIENT_BUFFER : S_OK; + + if ((size_t)iResult >= cchMax) + { + pszDest[cchMax] = 0; + iResult = cchMax; + } + + if (ppszDestEnd) *ppszDestEnd = pszDest + iResult; + + if (pcxRemaining) *pcxRemaining = STRSAFE_CCHtoCXX(cchMax - iResult); + + if (SUCCEEDED(hr)) + { + if ((dwFlags & STRSAFE_FILL_BEHIND_NULL) && (iResult + 1 < cchMax)) + { + memset(pszDest + iResult + 1, + dwFlags & 0xff, + (cchMax - iResult - 1) * sizeof(STRSAFE_TCHAR)); + } + } + else + { + if (dwFlags & STRSAFE_FILL_ON_FAILURE) + { + memset(pszDest, dwFlags & 0xff, cchMax * sizeof(STRSAFE_TCHAR)); + } + else if (dwFlags & STRSAFE_NULL_ON_FAILURE) + { + *pszDest = 0; + } + } + + return hr; +} + +STRSAFEAPI +StringCxxVPrintf( + STRSAFE_LPTSTR pszDest, + size_t cxDest, + STRSAFE_LPCTSTR pszFormat, + va_list args) +{ + return StringCxxVPrintfEx(pszDest, cxDest, NULL, NULL, 0, pszFormat, args); +} + +STRSAFEAPI +StringCxxPrintf( + STRSAFE_LPTSTR pszDest, + size_t cxDest, + STRSAFE_LPCTSTR pszFormat, ...) +{ + HRESULT result; + va_list args; + va_start(args, pszFormat); + result = StringCxxVPrintf(pszDest, cxDest, pszFormat, args); + va_end(args); + return result; +} + +STRSAFEAPI +StringCxxPrintfEx( + STRSAFE_LPTSTR pszDest, + size_t cxDest, + STRSAFE_LPTSTR *ppszDestEnd, + size_t *pcbRemaining, + STRSAFE_DWORD dwFlags, + STRSAFE_LPCTSTR pszFormat, ...) +{ + HRESULT result; + va_list args; + va_start(args, pszFormat); + result = StringCxxVPrintfEx(pszDest, cxDest, ppszDestEnd, pcbRemaining, dwFlags, pszFormat, args); + va_end(args); + return result; +} + +#endif // !STRSAFE_LIB + +/* Functions are implemented or defined, clear #defines for next pass */ +#undef StringCxxCat +#undef StringCxxCatEx +#undef StringCxxCatN +#undef StringCxxCatNEx +#undef StringCxxCatWorker +#undef StringCxxCopy +#undef StringCxxCopyEx +#undef StringCxxCopyN +#undef StringCxxCopyNEx +#undef StringCxxGets +#undef StringCxxGetsEx +#undef StringCxxLength +#undef StringCxxPrintf +#undef StringCxxPrintfEx +#undef StringCxxVPrintf +#undef StringCxxVPrintfEx + +#undef StringCbCat +#undef StringCbCatEx +#undef StringCbCatN +#undef StringCbCatNEx +#undef StringCbCatWorker +#undef StringCbCopy +#undef StringCbCopyEx +#undef StringCbCopyN +#undef StringCbCopyNEx +#undef StringCbGets +#undef StringCbGetsEx +#undef StringCbLength +#undef StringCbPrintf +#undef StringCbPrintfEx +#undef StringCbVPrintf +#undef StringCbVPrintfEx +#undef StringCchCat +#undef StringCchCatEx +#undef StringCchCatN +#undef StringCchCatNEx +#undef StringCchCatWorker +#undef StringCchCopy +#undef StringCchCopyEx +#undef StringCchCopyN +#undef StringCchCopyNEx +#undef StringCchGets +#undef StringCchGetsEx +#undef StringCchLength +#undef StringCchPrintf +#undef StringCchPrintfEx +#undef StringCchVPrintf +#undef StringCchVPrintfEx +#undef _vsnprintfAW + +#undef STRSAFE_LPTSTR +#undef STRSAFE_LPCTSTR +#undef STRSAFE_TCHAR + +#undef STRSAFE_CXXtoCB +#undef STRSAFE_CBtoCXX +#undef STRSAFE_CXXtoCCH +#undef STRSAFE_CCHtoCXX + +#endif // defined (STRSAFE_PASS2) + Propchange: trunk/reactos/include/psdk/strsafe.h ------------------------------------------------------------------------------ svn:eol-style = native
14 years, 8 months
1
0
0
0
[tkreuzer] 47025: [STRSAFE] Fix calculation between cch and cb, it was inverted.
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Mon Apr 26 01:15:37 2010 New Revision: 47025 URL:
http://svn.reactos.org/svn/reactos?rev=47025&view=rev
Log: [STRSAFE] Fix calculation between cch and cb, it was inverted. Modified: branches/ros-amd64-bringup/reactos/include/psdk/strsafe.h Modified: branches/ros-amd64-bringup/reactos/include/psdk/strsafe.h URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/inclu…
============================================================================== --- branches/ros-amd64-bringup/reactos/include/psdk/strsafe.h [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/include/psdk/strsafe.h [iso-8859-1] Mon Apr 26 01:15:37 2010 @@ -170,8 +170,8 @@ #define STRSAFE_CXXtoCB(x) (x) #define STRSAFE_CBtoCXX(x) (x) -#define STRSAFE_CXXtoCCH(x) (x)*sizeof(STRSAFE_TCHAR) -#define STRSAFE_CCHtoCXX(x) (x)/sizeof(STRSAFE_TCHAR) +#define STRSAFE_CXXtoCCH(x) (x)/sizeof(STRSAFE_TCHAR) +#define STRSAFE_CCHtoCXX(x) (x)*sizeof(STRSAFE_TCHAR) #define StringCxxCat StringCbCat #define StringCxxCatEx StringCbCatEx #define StringCxxCatN StringCbCatN @@ -191,8 +191,8 @@ #else // !STRSAFE_CB -#define STRSAFE_CXXtoCB(x) (x)/sizeof(STRSAFE_TCHAR) -#define STRSAFE_CBtoCXX(x) (x)*sizeof(STRSAFE_TCHAR) +#define STRSAFE_CXXtoCB(x) (x)*sizeof(STRSAFE_TCHAR) +#define STRSAFE_CBtoCXX(x) (x)/sizeof(STRSAFE_TCHAR) #define STRSAFE_CXXtoCCH(x) (x) #define STRSAFE_CCHtoCXX(x) (x) #define StringCxxCat StringCchCat @@ -477,7 +477,7 @@ } #if (STRSAFE_USE_SECURE_CRT == 1) - iResult = _vsntprintf_sAW(pszDest, cchDest, cchMax, pszFormat, args); + iResult = _vsnprintf_sAW(pszDest, cchDest, cchMax, pszFormat, args); #else iResult = _vsnprintfAW(pszDest, cchMax, pszFormat, args); #endif
14 years, 8 months
1
0
0
0
[cgutman] 47024: [OSKITTCP] - Add a sanity check - Dedicated to Caemyr
by cgutman@svn.reactos.org
Author: cgutman Date: Sun Apr 25 23:00:04 2010 New Revision: 47024 URL:
http://svn.reactos.org/svn/reactos?rev=47024&view=rev
Log: [OSKITTCP] - Add a sanity check - Dedicated to Caemyr Modified: trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c Modified: trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/oskit…
============================================================================== --- trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c [iso-8859-1] Sun Apr 25 23:00:04 2010 @@ -41,5 +41,10 @@ } void oskit_bufio_map(void *srcbuf, void**dstbuf, int off, int len) { +#if DBG + if (off != 0) + panic("oskit_bufio_map: offset is non-zero"); +#endif + *dstbuf = srcbuf; }
14 years, 8 months
1
0
0
0
[cgutman] 47023: [AFD] - Add some sanity checks
by cgutman@svn.reactos.org
Author: cgutman Date: Sun Apr 25 22:51:07 2010 New Revision: 47023 URL:
http://svn.reactos.org/svn/reactos?rev=47023&view=rev
Log: [AFD] - Add some sanity checks Modified: trunk/reactos/drivers/network/afd/afd/lock.c Modified: trunk/reactos/drivers/network/afd/afd/lock.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/afd/afd/lo…
============================================================================== --- trunk/reactos/drivers/network/afd/afd/lock.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/afd/afd/lock.c [iso-8859-1] Sun Apr 25 22:51:07 2010 @@ -16,6 +16,10 @@ /* Lock a method_neither request so it'll be available from DISPATCH_LEVEL */ PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) { BOOLEAN LockFailed = FALSE; + + ASSERT(IrpSp->Parameters.DeviceIoControl.Type3InputBuffer); + ASSERT(IrpSp->Parameters.DeviceIoControl.InputBufferLength); + ASSERT(!Irp->MdlAddress); Irp->MdlAddress = IoAllocateMdl( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer,
14 years, 8 months
1
0
0
0
[ekohl] 47022: [MKHIVE] Fix a buggy format string (%s --> %S). Add _wcsicmp to rtl.c.
by ekohl@svn.reactos.org
Author: ekohl Date: Sun Apr 25 22:49:29 2010 New Revision: 47022 URL:
http://svn.reactos.org/svn/reactos?rev=47022&view=rev
Log: [MKHIVE] Fix a buggy format string (%s --> %S). Add _wcsicmp to rtl.c. Modified: trunk/reactos/tools/mkhive/reginf.c trunk/reactos/tools/mkhive/rtl.c Modified: trunk/reactos/tools/mkhive/reginf.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/reginf.c?rev=…
============================================================================== --- trunk/reactos/tools/mkhive/reginf.c [iso-8859-1] (original) +++ trunk/reactos/tools/mkhive/reginf.c [iso-8859-1] Sun Apr 25 22:49:29 2010 @@ -354,7 +354,7 @@ if (Data == NULL) return FALSE; - DPRINT("setting binary data %s len %d\n", ValueName, Size); + DPRINT("setting binary data %S len %d\n", ValueName, Size); InfHostGetBinaryField (Context, 5, Data, Size, NULL); } Modified: trunk/reactos/tools/mkhive/rtl.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/rtl.c?rev=470…
============================================================================== --- trunk/reactos/tools/mkhive/rtl.c [iso-8859-1] (original) +++ trunk/reactos/tools/mkhive/rtl.c [iso-8859-1] Sun Apr 25 22:49:29 2010 @@ -207,3 +207,32 @@ } return Mask ? 1 : 0; } + +#undef tolower +WCHAR towlower(WCHAR ch) +{ + if (ch < L'A') + { + return ch; + } + else if (ch <= L'Z') + { + return ch + (L'a' - L'A'); + } + + return ch; +} + +int _wcsicmp(PCWSTR cs, PCWSTR ct) +{ + while (towlower(*cs) == towlower(*ct)) + { + if (*cs == 0) + return 0; + + cs++; + ct++; + } + + return towlower(*cs) - towlower(*ct); +}
14 years, 8 months
1
0
0
0
[gschneider] 47021: [MKHIVE] wcsicmp -> _wcsicmp, should fix buildbot build
by gschneider@svn.reactos.org
Author: gschneider Date: Sun Apr 25 22:26:37 2010 New Revision: 47021 URL:
http://svn.reactos.org/svn/reactos?rev=47021&view=rev
Log: [MKHIVE] wcsicmp -> _wcsicmp, should fix buildbot build Modified: trunk/reactos/tools/mkhive/reginf.c Modified: trunk/reactos/tools/mkhive/reginf.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/reginf.c?rev=…
============================================================================== --- trunk/reactos/tools/mkhive/reginf.c [iso-8859-1] (original) +++ trunk/reactos/tools/mkhive/reginf.c [iso-8859-1] Sun Apr 25 22:26:37 2010 @@ -53,32 +53,32 @@ static BOOL GetRootKey (PWCHAR Name) { - if (!wcsicmp (Name, L"HKCR")) + if (!_wcsicmp (Name, L"HKCR")) { wcscpy (Name, L"\\Registry\\Machine\\SOFTWARE\\Classes\\"); return TRUE; } - if (!wcsicmp (Name, L"HKCU")) + if (!_wcsicmp (Name, L"HKCU")) { wcscpy (Name, L"\\Registry\\User\\.DEFAULT\\"); return TRUE; } - if (!wcsicmp (Name, L"HKLM")) + if (!_wcsicmp (Name, L"HKLM")) { wcscpy (Name, L"\\Registry\\Machine\\"); return TRUE; } - if (!wcsicmp (Name, L"HKU")) + if (!_wcsicmp (Name, L"HKU")) { wcscpy (Name, L"\\Registry\\User\\"); return TRUE; } #if 0 - if (!wcsicmp (Name, L"HKR")) + if (!_wcsicmp (Name, L"HKR")) return FALSE; #endif @@ -138,7 +138,7 @@ len = wcslen (Strings) + 1; for (p = Buffer; *p != 0; p += wcslen (p) + 1) - if (!wcsicmp (p, Strings)) + if (!_wcsicmp (p, Strings)) break; if (*p == 0) /* not found, need to append it */
14 years, 8 months
1
0
0
0
[cgutman] 47020: [WS2_32] - Add support for reading the hosts file - Fix an off-by-one error which prevented reading the last value in the services file - Fixes bug 4410 and bug 4880
by cgutman@svn.reactos.org
Author: cgutman Date: Sun Apr 25 22:01:59 2010 New Revision: 47020 URL:
http://svn.reactos.org/svn/reactos?rev=47020&view=rev
Log: [WS2_32] - Add support for reading the hosts file - Fix an off-by-one error which prevented reading the last value in the services file - Fixes bug 4410 and bug 4880 Modified: trunk/reactos/dll/win32/ws2_32/misc/ns.c Modified: trunk/reactos/dll/win32/ws2_32/misc/ns.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/misc/ns.c…
============================================================================== --- trunk/reactos/dll/win32/ws2_32/misc/ns.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/ws2_32/misc/ns.c [iso-8859-1] Sun Apr 25 22:01:59 2010 @@ -640,7 +640,199 @@ HFREE(s); } - +/* This function is far from perfect but it works enough */ +static +LPHOSTENT +FindEntryInHosts(IN CONST CHAR FAR* name) +{ + BOOL Found = FALSE; + HANDLE HostsFile; + CHAR HostsDBData[BUFSIZ] = { 0 }; + PCHAR SystemDirectory = HostsDBData; + PCHAR HostsLocation = "\\drivers\\etc\\hosts"; + PCHAR AddressStr, DnsName = NULL, AddrTerm, NameSt, NextLine, ThisLine, Comment; + UINT SystemDirSize = sizeof(HostsDBData) - 1, ValidData = 0; + DWORD ReadSize; + ULONG Address; + PWINSOCK_THREAD_BLOCK p = NtCurrentTeb()->WinSockData; + + /* We assume that the parameters are valid */ + + if (!GetSystemDirectoryA(SystemDirectory, SystemDirSize)) + { + WSASetLastError(WSANO_RECOVERY); + WS_DbgPrint(MIN_TRACE, ("Could not get windows system directory.\n")); + return NULL; /* Can't get system directory */ + } + + strncat(SystemDirectory, + HostsLocation, + SystemDirSize ); + + HostsFile = CreateFileA(SystemDirectory, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, + NULL); + if (HostsFile == INVALID_HANDLE_VALUE) + { + WSASetLastError(WSANO_RECOVERY); + return NULL; + } + + while(!Found && + ReadFile(HostsFile, + HostsDBData + ValidData, + sizeof(HostsDBData) - ValidData, + &ReadSize, + NULL)) + { + ValidData += ReadSize; + ReadSize = 0; + NextLine = ThisLine = HostsDBData; + + /* Find the beginning of the next line */ + while(NextLine < HostsDBData + ValidData && + *NextLine != '\r' && *NextLine != '\n' ) + { + NextLine++; + } + + /* Zero and skip, so we can treat what we have as a string */ + if( NextLine > HostsDBData + ValidData ) + break; + + *NextLine = 0; NextLine++; + + Comment = strchr( ThisLine, '#' ); + if( Comment ) *Comment = 0; /* Terminate at comment start */ + + AddressStr = ThisLine; + /* Find the first space separating the IP address from the DNS name */ + AddrTerm = strchr(ThisLine, ' '); + if (AddrTerm) + { + /* Terminate the address string */ + *AddrTerm = 0; + + /* Find the last space before the DNS name */ + NameSt = strrchr(ThisLine, ' '); + + /* If there is only one space (the one we removed above), then just use the address terminator */ + if (!NameSt) + NameSt = AddrTerm; + + /* Move from the space to the first character of the DNS name */ + NameSt++; + + DnsName = NameSt; + + if (!strcmp(name, DnsName)) + { + Found = TRUE; + break; + } + } + + /* Get rid of everything we read so far */ + while( NextLine <= HostsDBData + ValidData && + isspace (*NextLine)) + { + NextLine++; + } + + if (HostsDBData + ValidData - NextLine <= 0) + break; + + WS_DbgPrint(MAX_TRACE,("About to move %d chars\n", + HostsDBData + ValidData - NextLine)); + + memmove(HostsDBData, + NextLine, + HostsDBData + ValidData - NextLine ); + ValidData -= NextLine - HostsDBData; + WS_DbgPrint(MAX_TRACE,("Valid bytes: %d\n", ValidData)); + } + + CloseHandle(HostsFile); + + if (!Found) + { + WS_DbgPrint(MAX_TRACE,("Not found\n")); + WSASetLastError(WSANO_DATA); + return NULL; + } + + if( !p->Hostent ) + { + p->Hostent = HeapAlloc(GlobalHeap, 0, sizeof(*p->Hostent)); + if( !p->Hostent ) + { + WSASetLastError( WSATRY_AGAIN ); + return NULL; + } + } + + p->Hostent->h_name = HeapAlloc(GlobalHeap, 0, strlen(DnsName)); + if( !p->Hostent->h_name ) + { + WSASetLastError( WSATRY_AGAIN ); + return NULL; + } + + RtlCopyMemory(p->Hostent->h_name, + DnsName, + strlen(DnsName)); + + p->Hostent->h_aliases = HeapAlloc(GlobalHeap, 0, sizeof(char *)); + if( !p->Hostent->h_aliases ) + { + WSASetLastError( WSATRY_AGAIN ); + return NULL; + } + + p->Hostent->h_aliases[0] = 0; + + if (strstr(AddressStr, ":")) + { + DbgPrint("AF_INET6 NOT SUPPORTED!\n"); + WSASetLastError(WSAEINVAL); + return NULL; + } + else + p->Hostent->h_addrtype = AF_INET; + + p->Hostent->h_addr_list = HeapAlloc(GlobalHeap, 0, sizeof(char *)); + if( !p->Hostent->h_addr_list ) + { + WSASetLastError( WSATRY_AGAIN ); + return NULL; + } + + Address = inet_addr(AddressStr); + if (Address == INADDR_NONE) + { + WSASetLastError(WSAEINVAL); + return NULL; + } + + p->Hostent->h_addr_list[0] = HeapAlloc(GlobalHeap, 0, sizeof(Address)); + if( !p->Hostent->h_addr_list[0] ) + { + WSASetLastError( WSATRY_AGAIN ); + return NULL; + } + + RtlCopyMemory(p->Hostent->h_addr_list[0], + &Address, + sizeof(Address)); + + p->Hostent->h_length = sizeof(Address); + + return p->Hostent; +} LPHOSTENT EXPORT @@ -661,6 +853,7 @@ /* include/WinDNS.h -- look up DNS_RECORD on MSDN */ PDNS_RECORD dp = 0; PWINSOCK_THREAD_BLOCK p; + LPHOSTENT Hostent; addr = GH_INVALID; @@ -726,6 +919,12 @@ case GH_RFC1123_DNS: /* DNS_TYPE_A: include/WinDNS.h */ /* DnsQuery -- lib/dnsapi/dnsapi/query.c */ + + /* Look for the DNS name in the hosts file */ + Hostent = FindEntryInHosts(name); + if (Hostent) + return Hostent; + dns_status = DnsQuery_A(name, DNS_TYPE_A, DNS_QUERY_STANDARD, @@ -993,7 +1192,7 @@ } /* Zero and skip, so we can treat what we have as a string */ - if( NextLine >= ServiceDBData + ValidData ) + if( NextLine > ServiceDBData + ValidData ) break; *NextLine = 0; NextLine++; @@ -1174,7 +1373,7 @@ *NextLine != '\r' && *NextLine != '\n' ) NextLine++; /* Zero and skip, so we can treat what we have as a string */ - if( NextLine >= ServiceDBData + ValidData ) + if( NextLine > ServiceDBData + ValidData ) break; *NextLine = 0; NextLine++;
14 years, 8 months
1
0
0
0
[ekohl] 47019: [MKHIVE] - Use newinflib instead of inflib. - Add RegDeleteKeyW stub. - Convert registry generation code from ANSI APIs to UNICODE APIs. ATTENTION: This commit might break the build bot because it was not tested on a Linux system.
by ekohl@svn.reactos.org
Author: ekohl Date: Sun Apr 25 21:54:57 2010 New Revision: 47019 URL:
http://svn.reactos.org/svn/reactos?rev=47019&view=rev
Log: [MKHIVE] - Use newinflib instead of inflib. - Add RegDeleteKeyW stub. - Convert registry generation code from ANSI APIs to UNICODE APIs. ATTENTION: This commit might break the build bot because it was not tested on a Linux system. Modified: trunk/reactos/tools/mkhive/mkhive.rbuild trunk/reactos/tools/mkhive/reginf.c trunk/reactos/tools/mkhive/registry.c Modified: trunk/reactos/tools/mkhive/mkhive.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/mkhive.rbuild…
============================================================================== --- trunk/reactos/tools/mkhive/mkhive.rbuild [iso-8859-1] (original) +++ trunk/reactos/tools/mkhive/mkhive.rbuild [iso-8859-1] Sun Apr 25 21:54:57 2010 @@ -1,13 +1,13 @@ <?xml version="1.0"?> <!DOCTYPE module SYSTEM "../../tools/rbuild/project.dtd"> <module name="mkhive" type="buildtool"> - <include base="inflibhost">.</include> + <include base="newinflibhost">.</include> <include base="cmlibhost">.</include> <include base="zlibhost">.</include> <include base="rtl">.</include> <define name="MKHIVE_HOST" /> <compilerflag compilerset="gcc">-fshort-wchar</compilerflag> - <library>inflibhost</library> + <library>newinflibhost</library> <library>cmlibhost</library> <library>host_wcsfuncs</library> <file>binhive.c</file> Modified: trunk/reactos/tools/mkhive/reginf.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/reginf.c?rev=…
============================================================================== --- trunk/reactos/tools/mkhive/reginf.c [iso-8859-1] (original) +++ trunk/reactos/tools/mkhive/reginf.c [iso-8859-1] Sun Apr 25 21:54:57 2010 @@ -51,34 +51,34 @@ /* FUNCTIONS ****************************************************************/ static BOOL -GetRootKey (PCHAR Name) +GetRootKey (PWCHAR Name) { - if (!strcasecmp (Name, "HKCR")) - { - strcpy (Name, "\\Registry\\Machine\\SOFTWARE\\Classes\\"); - return TRUE; - } - - if (!strcasecmp (Name, "HKCU")) - { - strcpy (Name, "\\Registry\\User\\.DEFAULT\\"); - return TRUE; - } - - if (!strcasecmp (Name, "HKLM")) - { - strcpy (Name, "\\Registry\\Machine\\"); - return TRUE; - } - - if (!strcasecmp (Name, "HKU")) - { - strcpy (Name, "\\Registry\\User\\"); + if (!wcsicmp (Name, L"HKCR")) + { + wcscpy (Name, L"\\Registry\\Machine\\SOFTWARE\\Classes\\"); + return TRUE; + } + + if (!wcsicmp (Name, L"HKCU")) + { + wcscpy (Name, L"\\Registry\\User\\.DEFAULT\\"); + return TRUE; + } + + if (!wcsicmp (Name, L"HKLM")) + { + wcscpy (Name, L"\\Registry\\Machine\\"); + return TRUE; + } + + if (!wcsicmp (Name, L"HKU")) + { + wcscpy (Name, L"\\Registry\\User\\"); return TRUE; } #if 0 - if (!strcasecmp (Name, "HKR")) + if (!wcsicmp (Name, L"HKR")) return FALSE; #endif @@ -94,19 +94,19 @@ static VOID AppendMultiSzValue ( IN HKEY KeyHandle, - IN PCHAR ValueName, - IN PCHAR Strings, + IN PWCHAR ValueName, + IN PWCHAR Strings, IN SIZE_T StringSize) { SIZE_T Size; ULONG Type; size_t Total; - PCHAR Buffer; - PCHAR p; + PWCHAR Buffer; + PWCHAR p; size_t len; LONG Error; - Error = RegQueryValueExA ( + Error = RegQueryValueExW ( KeyHandle, ValueName, NULL, @@ -117,11 +117,11 @@ (Type != REG_MULTI_SZ)) return; - Buffer = malloc (Size + StringSize); + Buffer = malloc (Size + (StringSize * sizeof(WCHAR))); if (Buffer == NULL) return; - Error = RegQueryValueExA ( + Error = RegQueryValueExW ( KeyHandle, ValueName, NULL, @@ -135,25 +135,25 @@ Total = Size; while (*Strings != 0) { - len = strlen (Strings) + 1; - - for (p = Buffer; *p != 0; p += strlen (p) + 1) - if (!strcasecmp (p, Strings)) + len = wcslen (Strings) + 1; + + for (p = Buffer; *p != 0; p += wcslen (p) + 1) + if (!wcsicmp (p, Strings)) break; if (*p == 0) /* not found, need to append it */ { - memcpy (p, Strings, len); + memcpy (p, Strings, len * sizeof(WCHAR)); p[len] = 0; - Total += len; + Total += len * sizeof(WCHAR); } Strings += len; } if (Total != Size) { - DPRINT ("setting value %s to %s\n", ValueName, Buffer); - RegSetValueExA ( + DPRINT ("setting value %S to %S\n", ValueName, Buffer); + RegSetValueExW ( KeyHandle, ValueName, 0, @@ -175,11 +175,11 @@ static BOOL do_reg_operation( IN HKEY KeyHandle, - IN PCHAR ValueName, + IN PWCHAR ValueName, IN PINFCONTEXT Context, IN ULONG Flags) { - CHAR EmptyStr = (CHAR)0; + WCHAR EmptyStr = (WCHAR)0; ULONG Type; ULONG Size; LONG Error; @@ -188,11 +188,11 @@ { if (ValueName) { - RegDeleteValueA (KeyHandle, ValueName); - } - else - { - RegDeleteKeyA (KeyHandle, NULL); + RegDeleteValueW (KeyHandle, ValueName); + } + else + { + RegDeleteKeyW (KeyHandle, NULL); } return TRUE; @@ -203,7 +203,7 @@ if (Flags & (FLG_ADDREG_NOCLOBBER | FLG_ADDREG_OVERWRITEONLY)) { - Error = RegQueryValueExA ( + Error = RegQueryValueExW ( KeyHandle, ValueName, NULL, @@ -253,7 +253,7 @@ if (!(Flags & FLG_ADDREG_BINVALUETYPE) || (Type == REG_DWORD && InfHostGetFieldCount (Context) == 5)) { - PCHAR Str = NULL; + WCHAR *Str = NULL; if (Type == REG_MULTI_SZ) { @@ -262,7 +262,7 @@ if (Size) { - Str = malloc (Size); + Str = malloc (Size * sizeof(WCHAR)); if (Str == NULL) return FALSE; @@ -292,7 +292,7 @@ if (Size) { - Str = malloc (Size); + Str = malloc (Size * sizeof(WCHAR)); if (Str == NULL) return FALSE; @@ -302,11 +302,11 @@ if (Type == REG_DWORD) { - ULONG dw = Str ? strtoul (Str, NULL, 0) : 0; - - DPRINT("setting dword %s to %x\n", ValueName, dw); - - RegSetValueExA ( + ULONG dw = Str ? wcstoul (Str, NULL, 0) : 0; + + DPRINT("setting dword %S to %x\n", ValueName, dw); + + RegSetValueExW ( KeyHandle, ValueName, 0, @@ -316,27 +316,27 @@ } else { - DPRINT("setting value %s to %s\n", ValueName, Str); + DPRINT("setting value %S to %S\n", ValueName, Str); if (Str) { - RegSetValueExA ( + RegSetValueExW ( KeyHandle, ValueName, 0, Type, (PVOID)Str, - (ULONG)Size); + (ULONG)Size * sizeof(WCHAR)); } else { - RegSetValueExA ( + RegSetValueExW ( KeyHandle, ValueName, 0, Type, (PVOID)&EmptyStr, - (ULONG)sizeof(CHAR)); + (ULONG)sizeof(WCHAR)); } } free (Str); @@ -358,7 +358,7 @@ InfHostGetBinaryField (Context, 5, Data, Size, NULL); } - RegSetValueExA ( + RegSetValueExW ( KeyHandle, ValueName, 0, @@ -378,10 +378,10 @@ * Called once for each AddReg and DelReg entry in a given section. */ static BOOL -registry_callback (HINF hInf, PCHAR Section, BOOL Delete) +registry_callback (HINF hInf, PWCHAR Section, BOOL Delete) { - CHAR Buffer[MAX_INF_STRING_LENGTH]; - PCHAR ValuePtr; + WCHAR Buffer[MAX_INF_STRING_LENGTH]; + PWCHAR ValuePtr; ULONG Flags; size_t Length; @@ -403,11 +403,11 @@ continue; /* get key */ - Length = strlen (Buffer); + Length = wcslen (Buffer); if (InfHostGetStringField (Context, 2, Buffer + Length, MAX_INF_STRING_LENGTH - (ULONG)Length, NULL) != 0) *Buffer = 0; - DPRINT("KeyName: <%s>\n", Buffer); + DPRINT("KeyName: <%S>\n", Buffer); if (Delete) { @@ -424,17 +424,17 @@ if (Delete || (Flags & FLG_ADDREG_OVERWRITEONLY)) { - if (RegOpenKeyA (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS) - { - DPRINT("RegOpenKey(%s) failed\n", Buffer); + if (RegOpenKeyW (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS) + { + DPRINT("RegOpenKey(%S) failed\n", Buffer); continue; /* ignore if it doesn't exist */ } } else { - if (RegCreateKeyA (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS) - { - DPRINT("RegCreateKey(%s) failed\n", Buffer); + if (RegCreateKeyW (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS) + { + DPRINT("RegCreateKey(%S) failed\n", Buffer); continue; } } @@ -469,18 +469,18 @@ ULONG ErrorLine; /* Load inf file from install media. */ - if (InfHostOpenFile(&hInf, FileName, &ErrorLine) != 0) + if (InfHostOpenFile(&hInf, FileName, 0, &ErrorLine) != 0) { DPRINT1 ("InfHostOpenFile(%s) failed\n", FileName); return FALSE; } - if (!registry_callback (hInf, "DelReg", TRUE)) + if (!registry_callback (hInf, L"DelReg", TRUE)) { DPRINT1 ("registry_callback() for DelReg failed\n"); } - if (!registry_callback (hInf, "AddReg", FALSE)) + if (!registry_callback (hInf, L"AddReg", FALSE)) { DPRINT1 ("registry_callback() for AddReg failed\n"); } Modified: trunk/reactos/tools/mkhive/registry.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/registry.c?re…
============================================================================== --- trunk/reactos/tools/mkhive/registry.c [iso-8859-1] (original) +++ trunk/reactos/tools/mkhive/registry.c [iso-8859-1] Sun Apr 25 21:54:57 2010 @@ -25,9 +25,9 @@ /* * TODO: - * - Implement RegDeleteKey() + * - Implement RegDeleteKeyW() * - Implement RegEnumValue() - * - Implement RegQueryValueExA() + * - Implement RegQueryValueExW() */ #include <stdlib.h> @@ -246,15 +246,34 @@ } LONG WINAPI -RegDeleteKeyA(HKEY Key, - LPCSTR Name) -{ - if (Name != NULL && strchr(Name, '\\') != NULL) - return(ERROR_INVALID_PARAMETER); - - DPRINT1("FIXME!\n"); - - return(ERROR_SUCCESS); +RegDeleteKeyW(IN HKEY hKey, + IN LPCWSTR lpSubKey) +{ + if (lpSubKey != NULL && wcschr(lpSubKey, L'\\') != NULL) + return(ERROR_INVALID_PARAMETER); + + DPRINT1("RegDeleteKeyW: FIXME!\n"); + + return(ERROR_SUCCESS); +} + +LONG WINAPI +RegDeleteKeyA(IN HKEY hKey, + IN LPCSTR lpSubKey) +{ + PWSTR lpSubKeyW; + LONG rc; + + if (lpSubKey != NULL && strchr(lpSubKey, '\\') != NULL) + return(ERROR_INVALID_PARAMETER); + + lpSubKeyW = MultiByteToWideChar(lpSubKey); + if (!lpSubKeyW) + return ERROR_OUTOFMEMORY; + + rc = RegDeleteKeyW(hKey, lpSubKeyW); + free(lpSubKeyW); + return rc; } LONG WINAPI
14 years, 8 months
1
0
0
0
[ekohl] 47018: [NEWINFLIB] - Use LANGID instead of LCID. - Move LANGID and language macros into the host typedefs header. - Remove dead code.
by ekohl@svn.reactos.org
Author: ekohl Date: Sun Apr 25 21:20:59 2010 New Revision: 47018 URL:
http://svn.reactos.org/svn/reactos?rev=47018&view=rev
Log: [NEWINFLIB] - Use LANGID instead of LCID. - Move LANGID and language macros into the host typedefs header. - Remove dead code. Modified: trunk/reactos/include/host/typedefs.h trunk/reactos/lib/newinflib/builddep.h trunk/reactos/lib/newinflib/infget.c trunk/reactos/lib/newinflib/infhost.h trunk/reactos/lib/newinflib/infhostgen.c trunk/reactos/lib/newinflib/infpriv.h trunk/reactos/lib/newinflib/infros.h trunk/reactos/lib/newinflib/infrosgen.c Modified: trunk/reactos/include/host/typedefs.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/host/typedefs.h?re…
============================================================================== --- trunk/reactos/include/host/typedefs.h [iso-8859-1] (original) +++ trunk/reactos/include/host/typedefs.h [iso-8859-1] Sun Apr 25 21:20:59 2010 @@ -65,6 +65,7 @@ typedef INT NTSTATUS, POOL_TYPE; typedef LONG HRESULT; typedef ULONG_PTR SIZE_T, *PSIZE_T; +typedef WORD LANGID; #define MAXUSHORT USHRT_MAX @@ -232,6 +233,11 @@ #define RtlCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length) #define RtlMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length) +#define MAKELANGID(p,s) ((((WORD)(s))<<10)|(WORD)(p)) +#define PRIMARYLANGID(l) ((WORD)(l)&0x3ff) +#define SUBLANGID(l) ((WORD)(l)>>10) +#define SUBLANG_NEUTRAL 0x00 + /* Prevent inclusion of some other headers */ #define __INTERNAL_DEBUG #define RTL_H Modified: trunk/reactos/lib/newinflib/builddep.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/builddep.h?r…
============================================================================== --- trunk/reactos/lib/newinflib/builddep.h [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/builddep.h [iso-8859-1] Sun Apr 25 21:20:59 2010 @@ -30,7 +30,6 @@ typedef char TCHAR, *PTCHAR, *PTSTR; typedef const TCHAR *PCTSTR; -typedef WORD LCID; #define _T(x) x #define _tcsicmp strcasecmp @@ -59,11 +58,6 @@ #define IS_TEXT_UNICODE_REVERSE_MASK 240 #define IS_TEXT_UNICODE_NOT_UNICODE_MASK 3840 #define IS_TEXT_UNICODE_NOT_ASCII_MASK 61440 - -#define SUBLANG_NEUTRAL 0 -#define PRIMARYLANGID(lgid) ((WORD)(lgid) & 0x3ff) -#define MAKELANGID(p, s) ((((WORD)(s)) << 10) | (WORD)(p)) - #else /* ! defined(INFLIB_HOST) */ Modified: trunk/reactos/lib/newinflib/infget.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infget.c?rev…
============================================================================== --- trunk/reactos/lib/newinflib/infget.c [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infget.c [iso-8859-1] Sun Apr 25 21:20:59 2010 @@ -46,11 +46,11 @@ DPRINT("Value name: %S\n", ValueName); - if (Inf->LocaleId != 0) + if (Inf->LanguageId != 0) { swprintf(StringLangId, L"Strings.%04hx", - Inf->LocaleId); + Inf->LanguageId); Status = InfpFindFirstLine(Inf, StringLangId, @@ -60,7 +60,7 @@ { swprintf(StringLangId, L"Strings.%04hx", - MAKELANGID(PRIMARYLANGID(Inf->LocaleId), SUBLANG_NEUTRAL)); + MAKELANGID(PRIMARYLANGID(Inf->LanguageId), SUBLANG_NEUTRAL)); Status = InfpFindFirstLine(Inf, StringLangId, Modified: trunk/reactos/lib/newinflib/infhost.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infhost.h?re…
============================================================================== --- trunk/reactos/lib/newinflib/infhost.h [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infhost.h [iso-8859-1] Sun Apr 25 21:20:59 2010 @@ -23,11 +23,11 @@ extern int InfHostOpenBufferedFile(PHINF InfHandle, void *Buffer, ULONG BufferSize, - LCID LocaleId, + LANGID LanguageId, ULONG *ErrorLine); extern int InfHostOpenFile(PHINF InfHandle, const CHAR *FileName, - LCID LocaleId, + LANGID LanguageId, ULONG *ErrorLine); extern int InfHostWriteFile(HINF InfHandle, const CHAR *FileName, Modified: trunk/reactos/lib/newinflib/infhostgen.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infhostgen.c…
============================================================================== --- trunk/reactos/lib/newinflib/infhostgen.c [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infhostgen.c [iso-8859-1] Sun Apr 25 21:20:59 2010 @@ -20,7 +20,7 @@ InfHostOpenBufferedFile(PHINF InfHandle, void *Buffer, ULONG BufferSize, - LCID LocaleId, + LANGID LanguageId, ULONG *ErrorLine) { INFSTATUS Status; @@ -59,8 +59,9 @@ ZEROMEMORY(Cache, sizeof(INFCACHE)); - Cache->LocaleId = LocaleId; - + Cache->LanguageId = LanguageId; + + /* Parse the inf buffer */ if (!RtlIsTextUnicode(FileBuffer, (INT)FileBufferSize, NULL)) { // static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf }; @@ -77,9 +78,6 @@ new_buff = MALLOC(FileBufferSize * sizeof(WCHAR)); if (new_buff != NULL) { -// DWORD len = MultiByteToWideChar( codepage, 0, (char *)FileBuffer + offset, -// FileBufferSize - offset, new_buff, FileBufferSize); - ULONG len; Status = RtlMultiByteToUnicodeN(new_buff, FileBufferSize * sizeof(WCHAR), @@ -111,11 +109,6 @@ ErrorLine); } - /* Parse the inf buffer */ -// Status = InfpParseBuffer (Cache, -// FileBuffer, -// FileBuffer + BufferSize, -// ErrorLine); if (!INF_SUCCESS(Status)) { FREE(Cache); @@ -134,7 +127,7 @@ int InfHostOpenFile(PHINF InfHandle, const CHAR *FileName, - LCID LocaleId, + LANGID LanguageId, ULONG *ErrorLine) { FILE *File; @@ -219,7 +212,7 @@ ZEROMEMORY(Cache, sizeof(INFCACHE)); - Cache->LocaleId = LocaleId; + Cache->LanguageId = LanguageId; /* Parse the inf buffer */ if (!RtlIsTextUnicode(FileBuffer, (INT)FileBufferLength, NULL)) @@ -238,9 +231,6 @@ new_buff = MALLOC(FileBufferLength * sizeof(WCHAR)); if (new_buff != NULL) { -// DWORD len = MultiByteToWideChar( codepage, 0, (char *)FileBuffer + offset, -// FileLength - offset, new_buff, FileLength); - ULONG len; Status = RtlMultiByteToUnicodeN(new_buff, FileBufferLength * sizeof(WCHAR), @@ -273,10 +263,6 @@ ErrorLine); } -// Status = InfpParseBuffer (Cache, -// FileBuffer, -// FileBuffer + FileLength, -// ErrorLine); if (!INF_SUCCESS(Status)) { FREE(Cache); Modified: trunk/reactos/lib/newinflib/infpriv.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infpriv.h?re…
============================================================================== --- trunk/reactos/lib/newinflib/infpriv.h [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infpriv.h [iso-8859-1] Sun Apr 25 21:20:59 2010 @@ -55,7 +55,7 @@ typedef struct _INFCACHE { - LCID LocaleId; + LANGID LanguageId; PINFCACHESECTION FirstSection; PINFCACHESECTION LastSection; Modified: trunk/reactos/lib/newinflib/infros.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infros.h?rev…
============================================================================== --- trunk/reactos/lib/newinflib/infros.h [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infros.h [iso-8859-1] Sun Apr 25 21:20:59 2010 @@ -18,11 +18,11 @@ extern NTSTATUS InfOpenBufferedFile(PHINF InfHandle, PVOID Buffer, ULONG BufferSize, - LCID LocaleId, + LANGID LanguageId, PULONG ErrorLine); extern NTSTATUS InfOpenFile(PHINF InfHandle, PUNICODE_STRING FileName, - LCID LocaleId, + LANGID LanguageId, PULONG ErrorLine); extern NTSTATUS InfWriteFile(HINF InfHandle, PUNICODE_STRING FileName, Modified: trunk/reactos/lib/newinflib/infrosgen.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/newinflib/infrosgen.c?…
============================================================================== --- trunk/reactos/lib/newinflib/infrosgen.c [iso-8859-1] (original) +++ trunk/reactos/lib/newinflib/infrosgen.c [iso-8859-1] Sun Apr 25 21:20:59 2010 @@ -51,7 +51,7 @@ InfOpenBufferedFile(PHINF InfHandle, PVOID Buffer, ULONG BufferSize, - LCID LocaleId, + LANGID LanguageId, PULONG ErrorLine) { INFSTATUS Status; @@ -92,8 +92,9 @@ ZEROMEMORY(Cache, sizeof(INFCACHE)); - Cache->LocaleId = LocaleId; - + Cache->LanguageId = LanguageId; + + /* Parse the inf buffer */ if (!RtlIsTextUnicode(FileBuffer, FileBufferSize, NULL)) { // static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf }; @@ -110,9 +111,6 @@ new_buff = MALLOC(FileBufferSize * sizeof(WCHAR)); if (new_buff != NULL) { -// DWORD len = MultiByteToWideChar( codepage, 0, (char *)FileBuffer + offset, -// FileBufferSize - offset, new_buff, FileBufferSize); - ULONG len; Status = RtlMultiByteToUnicodeN(new_buff, FileBufferSize * sizeof(WCHAR), @@ -162,7 +160,7 @@ NTSTATUS InfOpenFile(PHINF InfHandle, PUNICODE_STRING FileName, - LCID LocaleId, + LANGID LanguageId, PULONG ErrorLine) { OBJECT_ATTRIBUTES ObjectAttributes; @@ -267,7 +265,7 @@ ZEROMEMORY(Cache, sizeof(INFCACHE)); - Cache->LocaleId = LocaleId; + Cache->LanguageId = LanguageId; /* Parse the inf buffer */ if (!RtlIsTextUnicode(FileBuffer, FileBufferLength, NULL)) @@ -286,9 +284,6 @@ new_buff = MALLOC(FileBufferLength * sizeof(WCHAR)); if (new_buff != NULL) { -// DWORD len = MultiByteToWideChar( codepage, 0, (char *)FileBuffer + offset, -// FileLength - offset, new_buff, FileLength); - ULONG len; Status = RtlMultiByteToUnicodeN(new_buff, FileBufferLength * sizeof(WCHAR),
14 years, 8 months
1
0
0
0
← Newer
1
2
3
4
5
6
7
8
...
44
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Results per page:
10
25
50
100
200