Ejemplo n.º 1
0
void CfgTest()
{
#if	0
	FOLDER *root;
	BUF *b;
	Debug("\nCFG Test Begin\n");

	root = CfgCreateFolder(NULL, TAG_ROOT);
	CfgTest2(root, 5);

	b = CfgFolderToBufText(root);
	//Print("%s\n", b->Buf);
	SeekBuf(b, 0, 0);

	CfgDeleteFolder(root);

	DumpBuf(b, "test1.config");

	root = CfgBufTextToFolder(b);

	FreeBuf(b);

	b = CfgFolderToBufText(root);
//	Print("%s\n", b->Buf);
	DumpBuf(b, "test2.config");
	FreeBuf(b);

	CfgSave(root, "test.txt");

	CfgDeleteFolder(root);

	Debug("\nCFG Test End\n");
#endif
}
Ejemplo n.º 2
0
// Extract the Cabinet file from the EXE file
bool ViExtractCabinetFile(char *exe, char *cab)
{
	BUF *b;
	// Validate arguments
	if (exe == NULL || cab == NULL)
	{
		return false;
	}

	b = ViExtractResource(exe, RT_RCDATA, "CABINET");
	if (b == NULL)
	{
		return false;
	}

	if (DumpBuf(b, cab) == false)
	{
		FreeBuf(b);

		return false;
	}

	FreeBuf(b);

	return true;
}
Ejemplo n.º 3
0
// Copy a file
bool FileCopy(char *src, char *dst)
{
	BUF *b;
	bool ret = false;
	// Validate arguments
	if (src == NULL || dst == NULL)
	{
		return false;
	}

	b = ReadDump(src);
	if (b == NULL)
	{
		return false;
	}

	SeekBuf(b, 0, 0);

	ret = DumpBuf(b, dst);

	FreeBuf(b);

	return ret;
}
Ejemplo n.º 4
0
/**
  Print EFI_IPSEC_SA_ID and EFI_IPSEC_SA_DATA2 content.

  @param[in] SaId          The pointer to the EFI_IPSEC_SA_ID structure.
  @param[in] Data          The pointer to the EFI_IPSEC_SA_DATA2 structure.
  @param[in] EntryIndex    The pointer to the Index in the SAD Database.

  @retval EFI_SUCCESS    Dump SAD information successfully.
**/
EFI_STATUS
DumpSadEntry (
  IN EFI_IPSEC_SA_ID      *SaId,
  IN EFI_IPSEC_SA_DATA2   *Data,
  IN UINTN                *EntryIndex
  )
{
  BOOLEAN    HasPre;
  CHAR16     *AuthAlgoStr;
  CHAR16     *EncAlgoStr;

  AuthAlgoStr      = NULL;
  EncAlgoStr       = NULL;

  //
  // SPI:1234 ESP Destination:xxx.xxx.xxx.xxx
  //  Mode:Transport SeqNum:134 AntiReplayWin:64 life:[0B,1023s,3400S] PathMTU:34
  //  Auth:xxxx/password Encrypt:yyyy/password
  //  xxx.xxx.xxx.xxx/yy -> xxx.xxx.xxx.xx/yy proto:23 port:100~300 -> 300~400
  //

  Print (L"%d.", (*EntryIndex)++);
  Print (L"0x%x %s ", (UINTN) SaId->Spi, MapIntegerToString (SaId->Proto, mMapIpSecProtocol));
  if (Data->Mode == EfiIPsecTunnel) {
    Print (L"TunnelSourceAddress:");
    DumpIpAddress (&Data->TunnelSourceAddress);
    Print (L"\n");
    Print (L"  TunnelDestination:");
    DumpIpAddress (&Data->TunnelDestinationAddress);
    Print (L"\n");
  }

  Print (
    L"  Mode:%s SeqNum:%lx AntiReplayWin:%d ",
    MapIntegerToString (Data->Mode, mMapIpSecMode),
    Data->SNCount,
    (UINTN) Data->AntiReplayWindows
    );

  HasPre = FALSE;
  if (Data->SaLifetime.ByteCount != 0) {
    Print (HasPre ? L"," : L"life:[");
    Print (L"%lxB", Data->SaLifetime.ByteCount);
    HasPre = TRUE;
  }

  if (Data->SaLifetime.SoftLifetime != 0) {
    Print (HasPre ? L"," : L"life:[");
    Print (L"%lxs", Data->SaLifetime.SoftLifetime);
    HasPre = TRUE;
  }

  if (Data->SaLifetime.HardLifetime != 0) {
    Print (HasPre ? L"," : L"life:[");
    Print (L"%lxS", Data->SaLifetime.HardLifetime);
    HasPre = TRUE;
  }

  if (HasPre) {
    Print (L"] ");
  }

  Print (L"PathMTU:%d\n", (UINTN) Data->PathMTU);

  if (SaId->Proto == EfiIPsecAH) {
    Print (
      L"  Auth:%s/%s\n",
      MapIntegerToString (Data->AlgoInfo.AhAlgoInfo.AuthAlgoId, mMapAuthAlgo),
      Data->AlgoInfo.AhAlgoInfo.AuthKey
      );
  } else {
    AuthAlgoStr = MapIntegerToString (Data->AlgoInfo.EspAlgoInfo.AuthAlgoId, mMapAuthAlgo);
    EncAlgoStr  = MapIntegerToString (Data->AlgoInfo.EspAlgoInfo.EncAlgoId, mMapEncAlgo);

    if (Data->ManualSet) {
      //
      // if the SAD is set manually the key is a Ascii string in most of time.
      // Print the Key in Ascii string format.
      //
      Print (L"  Auth:%s/",AuthAlgoStr);
      DumpAsciiString (
        Data->AlgoInfo.EspAlgoInfo.AuthKey,
        Data->AlgoInfo.EspAlgoInfo.AuthKeyLength
        );
      Print (L"\n  Encrypt:%s/",EncAlgoStr);
      DumpAsciiString (
        Data->AlgoInfo.EspAlgoInfo.EncKey,
        Data->AlgoInfo.EspAlgoInfo.EncKeyLength
        );
    } else {
      //
      // if the SAD is created by IKE, the key is a set of hex value in buffer.
      // Print the Key in Hex format.
      //
      Print (L"  Auth:%s/",AuthAlgoStr);
      DumpBuf ((UINT8 *)(Data->AlgoInfo.EspAlgoInfo.AuthKey), Data->AlgoInfo.EspAlgoInfo.AuthKeyLength);

      Print (L"\n  Encrypt:%s/",EncAlgoStr);
      DumpBuf ((UINT8 *)(Data->AlgoInfo.EspAlgoInfo.EncKey), Data->AlgoInfo.EspAlgoInfo.EncKeyLength);
    }
  }
  Print (L"\n");
  if (Data->SpdSelector != NULL) {
    Print (L"  ");
    DumpSpdSelector (Data->SpdSelector);
    Print (L"\n");
  }

  return EFI_SUCCESS;
}
Ejemplo n.º 5
0
int GptWriteHeader(HGPT hGPT)
    {
    int i;
    int iErr;
    char far *lpArray = (char far *)NULL;
    char far *lpc;
    int iEntryArraySize;
    int nSect;
    QWORD qwLBA;
    
#ifdef _DEBUG
    if (iDebug) printf("GptWriteHeader(hBlockDev=%p)\n", hGPT->hBlockDev);
#endif

    // Compute the entire entry array CRC, and update the header.
    iEntryArraySize = (int)(hGPT->pGptHdr->NumberOfPartitionEntries) * sizeof(EFI_PARTITION_ENTRY);
    nSect = (iEntryArraySize + hGPT->iSectorSize - 1) / hGPT->iSectorSize;
    lpArray = (char far *)_fmalloc(nSect * hGPT->iSectorSize);
    if (!lpArray) GptWriteHeaderFail(1);
    
    for (lpc=lpArray, i=0, qwLBA=hGPT->pGptHdr->PartitionEntryLBA; i<nSect; i++, lpc+=hGPT->iSectorSize, qwLBA++)
        {
	iErr = GptBlockRead(hGPT, qwLBA, 1, lpc);
	if (iErr) GptWriteHeaderFail(2);
        }

    hGPT->pGptHdr->PartitionEntryArrayCRC32 = crc32(lpArray, iEntryArraySize);
    
    // Write the backup GPT header
    // Exchange the main and alternate LBA addresses.
    qwLBA = hGPT->pGptHdr->AlternateLBA;
    hGPT->pGptHdr->AlternateLBA = hGPT->pGptHdr->MyLBA;
    hGPT->pGptHdr->MyLBA = qwLBA;
    // Update the header CRC
    SetCrc(&(hGPT->pGptHdr->Header));
    // Write the backup GPT header
    iErr = GptBlockWrite(hGPT, hGPT->pGptHdr->MyLBA, 1, hGPT->pGptHdr);
    if (iErr)
    	{
#ifdef _DEBUG
    	if (iVerbose) printf("Error %d writing the GPT backup header.\n", iErr);
#endif
    	GptWriteHeaderFail(3);
    	}

    // Write the main GPT header
    // Exchange the main and alternate LBA addresses.
    qwLBA = hGPT->pGptHdr->AlternateLBA;
    hGPT->pGptHdr->AlternateLBA = hGPT->pGptHdr->MyLBA;
    hGPT->pGptHdr->MyLBA = qwLBA;
    // Update the header CRC
    SetCrc(&(hGPT->pGptHdr->Header));
#ifdef _DEBUG
    if (iVerbose) DumpBuf(hGPT->pGptHdr, 0, (WORD)hGPT->pGptHdr->Header.HeaderSize);
#endif
    // Write the main GPT header
    iErr = GptBlockWrite(hGPT, hGPT->pGptHdr->MyLBA, 1, hGPT->pGptHdr);
    if (iErr)
    	{
#ifdef _DEBUG
    	if (iVerbose) printf("Error %d writing the GPT header.\n", iErr);
#endif
    	GptWriteHeaderFail(4);
    	}
    	
header_return:
    _ffree(lpArray);
    
    return iErr;
    }
Ejemplo n.º 6
0
void SwapMachMessage( sComData *message, eSwapDirection direction )
{
    short i;
    sObject* object;
    bool isTwoWay = false;
    
    if (message == nil) return;
    
#ifdef DUMP_BUFFER
    UInt32 bufSize = 0;
    if ( gDumpFile == NULL )
	{
		FILE *tempFile = fopen( "/Library/Logs/DirectoryService/MachMsgDump", "w" );
		if ( OSAtomicCompareAndSwapPtrBarrier(NULL, tempFile, (void **) &gDumpFile) == false )
		{
			// close the file.
			fclose( tempFile );
		}
	}
        
    if (direction == kDSSwapNetworkToHostOrder)
        fprintf(gDumpFile, "\n\n\nBuffer in Network order (preSwap)\n");
    else
        fprintf(gDumpFile, "\n\n\nBuffer in Host order (preSwap)\n");
	
    for (i=0; i< 10; i++)
    {
        object = &message->obj[i];
        UInt32 objType = DSGetLong(&object->type, direction);
        UInt32 offset = DSGetLong(&object->offset, direction);
        UInt32 length = DSGetLong(&object->length, direction);
        char* type = "unknown";
        if (objType >= kResult && objType <= kAttrValueList)
            type = objectTypes[objType - kResult];
        if (objType != 0)
        {
            if (length > 0)
                    fprintf(gDumpFile, "Object %d, type %s, offset %ld, size %ld\n", i, type, DSGetLong(&object->offset, direction), DSGetLong(&object->length, direction));
            else
                    fprintf(gDumpFile, "Object %d, type %s, value %ld\n", i, type, DSGetLong(&object->count, direction));
        }
        if (length > 0)
        {
            UInt32 size = offset + length - sizeof(sComData) + 4;
            if (size > bufSize) bufSize = size;
        }
    }
    DumpBuf(message->data, bufSize);
#endif
    
    DSSwapLong(&message->fDataSize, direction);
    DSSwapLong(&message->fDataLength, direction);
    DSSwapLong(&message->fMsgID, direction);
    
	UInt32 aNodeRef = 0;

	//handle CustomCall endian issues - need to determine which plugin is being used
	bool bCustomCall = false;
	UInt32 aCustomRequestNum = 0;
	bool bIsAPICallResponse = false;
	const char* aPluginName = nil;
    // if this is the auth case or custom call case, we need to do some checks
    for (i=0; i< 10; i++)
    {
        object = &message->obj[i];
        UInt32 objType = DSGetLong( &object->type, direction );
		char* method;
		
		switch ( objType )
		{
			case kAuthMethod:
				// check for two-way random special case before we start swapping stuff
				method = (char *)message + DSGetLong( &object->offset, direction );
				if ( strcmp(method, kDSStdAuth2WayRandom) == 0 )
					isTwoWay = true;
				break;
			case kCustomRequestCode:
				//check for Custom Call special casing
				bCustomCall = true;
				aCustomRequestNum = DSGetLong( &object->count, direction );
				break;
			case ktNodeRef:
				//need to determine the nodename for discrimination of duplicate custom call codes - server
				aNodeRef = (UInt32)DSGetLong( &object->count, direction );
				break;
			case kResult:
				bIsAPICallResponse = true;
				break;
		}
    } // for (i=0; i< 10; i++)
	
	if ( bCustomCall && aCustomRequestNum != 0 && aNodeRef != 0 )
	{
		aPluginName = dsGetPluginNamePriv( aNodeRef, getpid() );
	}

    // swap objects
    for (i=0; i< 10; i++)
    {
        object = &message->obj[i];

        if (object->type == 0)
            continue;
            
        UInt32 objType = DSGetAndSwapLong(&object->type, direction);
        DSSwapLong(&object->count, direction);
        UInt32 objOffset = DSGetAndSwapLong(&object->offset, direction);
        DSSwapLong(&object->used, direction);
        UInt32 objLength = DSGetAndSwapLong(&object->length, direction);
            
        DSSwapObjectData(objType, (char *)message + objOffset, objLength, (!isTwoWay), bCustomCall, aCustomRequestNum, (const char*)aPluginName, bIsAPICallResponse, direction);
    }
    
#ifdef DUMP_BUFFER
    if (direction == kDSSwapNetworkToHostOrder)
        fprintf(gDumpFile, "\n\nBuffer in Host order (post Swap)\n");
    else
        fprintf(gDumpFile, "\n\nBuffer in Network order (post Swap)\n");
    DumpBuf(message->data, bufSize);
    fflush(stdout);
#endif
}