isl_mparse.c
来自「Next BIOS Source code : Extensible Firmw」· C语言 代码 · 共 1,329 行 · 第 1/3 页
C
1,329 行
/*-----------------------------------------------------------------------
* File: m_parse.c
*
Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
*---------------------------------------------------------------------
*/
/*
* INTEL CONFIDENTIAL
* This file, software, or program is supplied under the terms of a
* license agreement or nondisclosure agreement with Intel Corporation
* and may not be copied or disclosed except in accordance with the
* terms of that agreement. This file, software, or program contains
* copyrighted material and/or trade secret information of Intel
* Corporation, and must be treated as such. Intel reserves all rights
* in this material, except as the license agreement or nondisclosure
* agreement specifically indicate.
*/
/*
* WARNING: EXPORT RESTRICTED.
* This software is subject to the U.S. Export Administration Regulations
* and other U.S. law, and may not be exported or re-exported to certain
* countries (currently Afghanistan (Taliban-controlled areas), Cuba, Iran,
* Iraq, Libya, North Korea, Serbia (except Kosovo), Sudan and Syria) or to
* persons or entities prohibited from receiving U.S. exports (including Denied
* Parties, Specially Designated Nationals, and entities on the Bureau of
* Export Administration Entity List or involved with missile technology or
* nuclear, chemical or biological weapons).
*/
//#include <stdio.h>
#include "isl_internal.h"
#include "islutil.h"
#include "isl_parse.h"
extern ISL_CONFIG_METHODS ArchiveConfigMethods;
static ISL_ALG_INFO_PTR
AllocAlgList(
ISL_MEMORY_CONTEXT_PTR MemoryPtr,
unsigned long count); /* length of list */
static unsigned long
CountItemsInList(
const unsigned char *ptr,
unsigned int len);
static ISL_STATUS
InitAlgList(
ISL_ALG_INFO_PTR list,
ISL_CONST_DATA Value,
ISL_ARCHIVE_CONTEXT_PTR pArchive);
ISL_STATUS
ParseToNewline(
ISL_CONST_DATA Input, /* buffer to be parsed */
ISL_CONST_DATA_PTR UpdatedInput);
ISL_STATUS
ParseToEndOfSection(
ISL_CONST_DATA Input, /* buffer to be parsed */
ISL_CONST_DATA_PTR UpdatedInput, /* pointer to remaining buffer */
ISL_CONST_DATA_PTR SectionImage); /* SectionImage */
static ISL_STATUS
AddManifestSection(
ISL_ARCHIVE_CONTEXT_PTR pArchive,
ISL_MANIFEST_SECTION_PTR pManSect);
static ISL_STATUS
InitializeManifestSection(
ISL_ARCHIVE_CONTEXT_PTR pArchive,
ISL_MANIFEST_SECTION_PTR pManSect);
static ISL_STATUS
GetManifestSection(
ISL_CONST_DATA_PTR ptr,
ISL_MANIFEST_SECTION *data);
static ISL_ALG_INFO_PTR
MatchDigest(
ISL_CONST_DATA Name,
ISL_ALG_INFO_PTR AlgList);
static ISL_STATUS AddAttribute(
ISL_CONST_DATA Name,
ISL_CONST_DATA Value,
ISL_SECTION_PTR SectionPtr,
ISL_MEMORY_CONTEXT_PTR MemoryPtr);
/*-----------------------------------------------------------------------------
* Name: ParseVersion
*
* Description:
* Parses a version string into a major/minor version structure
*
* Parameters:
* HeaderInfoPtr (output)
* Version (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
ISL_STATUS
ParseVersion(
ISL_HEADER_SECTION_PTR HeaderInfoPtr,
CSSM_DATA Version)
{
const uint8 *ptr = NULL;
uint32 MinorLength = 0;
uint32 MajorLength = 0;
uint32 i = 0;
if (Version.Length > 7)
return ISL_FAIL;
ptr = isl_memchr(Version.Data,'.',Version.Length);
if (!ptr)
return ISL_FAIL;
MajorLength = (uint32)(ptr - Version.Data);
MinorLength = Version.Length - (MajorLength + 1);
if ( (MajorLength > 3 ) ||
(MinorLength > 3 ) )
return ISL_FAIL;
ptr = Version.Data;
HeaderInfoPtr->MajorVersion = 0;
for (i = 0; i < MajorLength; i++)
{
if (!ISL_ISDIGIT(*(ptr+i)) )
return ISL_FAIL;
HeaderInfoPtr->MajorVersion *= 10;
HeaderInfoPtr->MajorVersion = (uint16) (HeaderInfoPtr->MajorVersion + *(ptr+i) - '0');
}
ptr = Version.Data + (MajorLength + 1);
HeaderInfoPtr->MinorVersion = 0;
for (i = 0; i < MinorLength; i++)
{
if (!ISL_ISDIGIT(*(ptr+i)) )
return ISL_FAIL;
HeaderInfoPtr->MinorVersion *= 10;
HeaderInfoPtr->MinorVersion = (uint16) (HeaderInfoPtr->MinorVersion + *(ptr+i) - '0');
}
return ISL_OK;
}
/*-----------------------------------------------------------------------------
* Name: InitializeSectionAlgList
*
* Description:
*
* Parameters:
* ArchivePtr (output)
* SectionPtr (output)
* Value (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
static ISL_ALG_INFO_PTR
InitializeSectionAlgList(
ISL_ARCHIVE_CONTEXT_PTR ArchivePtr,
ISL_SECTION_PTR SectionPtr,
ISL_CONST_DATA Value)
{
ISL_ALG_INFO_PTR list = NULL;
unsigned long count = 0;
count = CountItemsInList(Value.Data,Value.Length);
list = AllocAlgList(ArchivePtr->Memory, count);
if (!list)
return NULL;
if (InitAlgList(list, Value, ArchivePtr) != ISL_OK)
return NULL;
SectionPtr->Algorithm = list;
SectionPtr->AlgCount = count;
return list;
}
/*-----------------------------------------------------------------------------
* Name: IsHashAlgorithm
*
* Description:
*
* Parameters:
* Name (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
static uint32
IsHashAlgorithm(
ISL_CONST_DATA Name)
{
ISL_CONST_DATA STR;
STR.Data = (const uint8 *)"Digest-Algorithms";
STR.Length = sizeof("Digest-Algorithms")-1;
return IS_EQUAL(Name,STR);
}
/*-----------------------------------------------------------------------------
* Name: IsName
*
* Description:
*
* Parameters:
* Name (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
static uint32
IsName(
ISL_CONST_DATA Name)
{
ISL_CONST_DATA STR;
STR.Data = (const uint8 *)"Name";
STR.Length = sizeof("Name")-1;
return IS_EQUAL(Name,STR);
}
/*-----------------------------------------------------------------------------
* Name: IsSectionName
*
* Description:
*
* Parameters:
* Name (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
static uint32
IsSectionName(
ISL_CONST_DATA Name)
{
ISL_CONST_DATA STR;
STR.Data = (const uint8 *)"SectionName";
STR.Length = sizeof("SectionName")-1;
return IS_EQUAL(Name,STR);
}
/*-----------------------------------------------------------------------------
* Name: IsHash
*
* Description:
*
* Parameters:
* Name (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
static uint32
IsHash(
ISL_CONST_DATA Name)
{
ISL_CONST_DATA STR;
STR.Data = (const uint8 *)"-Digest";
STR.Length = sizeof("-Digest")-1;
return IS_EQUAL(Name,STR);
}
/*-----------------------------------------------------------------------------
* Name: AddAttribute
*
* Description:
*
* Parameters:
* Name (input)
* Value (input)
* SectionPtr (output)
* MemoryPtr (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
static ISL_STATUS
AddAttribute(
ISL_CONST_DATA Name,
ISL_CONST_DATA Value,
ISL_SECTION_PTR SectionPtr,
ISL_MEMORY_CONTEXT_PTR MemoryPtr)
{
ISL_NAME_VALUE_PTR AttributePtr = NULL;
ISL_LIST_PTR AttributeListPtr = NULL;
// ISL_ARCHIVE_CONTEXT_PTR pArchive = NULL;
{
ISL_LIST_PTR pCurr;
AttributeListPtr = (ISL_LIST_PTR) isl_AllocateMemory(
MemoryPtr,
sizeof(ISL_LIST));
if (AttributeListPtr == NULL) {
goto FAIL;
}
AttributePtr = (ISL_NAME_VALUE_PTR) isl_AllocateMemory(
MemoryPtr,
sizeof(ISL_NAME_VALUE));
if (AttributePtr == NULL) {
goto FAIL;
}
AttributeListPtr->Node = AttributePtr;
AttributeListPtr->Next = NULL;
AttributePtr->Name = Name;
AttributePtr->Value = Value;
SectionPtr->AttributeCount++;
pCurr = SectionPtr->Attribute;
if (pCurr == NULL)
{
SectionPtr->Attribute = AttributeListPtr;
return ISL_OK;
}
while (pCurr->Next != NULL) {
pCurr = pCurr->Next;
}
pCurr->Next = AttributeListPtr;
return ISL_OK;
}
FAIL:
{
return ISL_FAIL;
}
}
/*-----------------------------------------------------------------------------
* Name: InitializeSection
*
* Description:
* This function will initialize an ISL_SECTION.
*
* Parameters:
* SectionPtr (output)
* SectionInfoPtr (input)
* ArchivePtr (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
static ISL_STATUS
InitializeSection(
ISL_SECTION_PTR SectionPtr,
ISL_SECTION_INFO_PTR SectionInfoPtr,
ISL_ARCHIVE_CONTEXT_PTR ArchivePtr)
{
ISL_MEMORY_CONTEXT_PTR MemoryPtr;
ISL_CONST_DATA Name;
ISL_CONST_DATA Value;
ISL_ALG_INFO_PTR DigestPtr = NULL;
ISL_ALG_INFO_PTR HashInfoPtr;
uint32 i;
if (SectionInfoPtr->Attributes.NumberOfAttributes == 0 ||
ArchivePtr == NULL)
return ISL_FAIL;
MemoryPtr = ArchivePtr->Memory;
/* first attribute is a name */
Name.Length = SectionInfoPtr->Attributes.Attributes[0].Info.Label.Name.Length;
Name.Data = SectionInfoPtr->Attributes.Attributes[0].Info.Label.Name.Data;
if (IsName(Name)) {
SectionPtr->Name.Data = SectionInfoPtr->Attributes.Attributes[0].Value.Data;
SectionPtr->Name.Length = SectionInfoPtr->Attributes.Attributes[0].Value.Length;
} else {
return ISL_FAIL;
}
SectionPtr->Image = SectionInfoPtr->Image;
/* search for digest tokens */
for(i=0; i < SectionInfoPtr->Attributes.NumberOfAttributes; i++)
{
Name.Length = SectionInfoPtr->Attributes.Attributes[i].Info.Label.Name.Length;
Name.Data = SectionInfoPtr->Attributes.Attributes[i].Info.Label.Name.Data;
if (IsHashAlgorithm(Name))
{
Value.Length = SectionInfoPtr->Attributes.Attributes[i].Value.Length;
Value.Data = SectionInfoPtr->Attributes.Attributes[i].Value.Data;
DigestPtr = InitializeSectionAlgList(ArchivePtr, SectionPtr, Value);
break;
}
}
for(i=0; i < SectionInfoPtr->Attributes.NumberOfAttributes; i++)
{
ISL_ATTRIBUTE_INFO_PTR AttributePtr;
AttributePtr = SectionInfoPtr->Attributes.Attributes + i;
if (AttributePtr->Info.AttributeNameFormat != CSSM_DB_ATTRIBUTE_NAME_AS_BLOB)
{
return ISL_FAIL;
}
Name.Length = AttributePtr->Info.Label.Name.Length;
Name.Data = AttributePtr->Info.Label.Name.Data;
Value.Length = AttributePtr->Value.Length;
Value.Data = AttributePtr->Value.Data;
if (AddAttribute(Name, Value, SectionPtr, MemoryPtr) != ISL_OK)
return ISL_FAIL;
if (IsSectionName(Name))
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?