Ejemplo n.º 1
0
Archivo: luac.c Proyecto: jcubic/ToME
char *luaU_dumpchunk_buffer(const Proto* Main, size_t *len)
{
	char *buf;

	/* First calculate the total size*/
	__lua_dumper_size = 0;
	DumpByte = DumpByte_calc_size;
	DumpSig = DumpSig_calc_size;
	DumpBlock = DumpBlock_calc_size;
	DumpVector = DumpVector_calc_size;

	DumpHeader(NULL);
	DumpFunction(Main, NULL);

	/* Allocate the buffer */
	*len = __lua_dumper_size;
	C_MAKE(buf, __lua_dumper_size, char);

	/* Now dump it for real */
	__lua_dumper_size = 0;
	DumpByte = DumpByte_buffer;
	DumpSig = DumpSig_buffer;
	DumpBlock = DumpBlock_buffer;
	DumpVector = DumpVector_buffer;

	DumpHeader(buf);
	DumpFunction(Main, buf);
	return buf;
}
Ejemplo n.º 2
0
void Convert(std::string pe_file_name, std::string xky_file_name)
{
	//Creamos el fichero PE
	PEFile pe_file(pe_file_name);
	
	//Testear que exista una seccion ".module"
	if(!pe_file.GetSectionHeaderByName(MODULE_SECTION_NAME))
		throw std::string(".module section doesn't exists");

	//Creamos el fichero linkado
	XFile xky_file(CalculateXkyFileSize(&pe_file, XKY_SECTION_ALIGNMENT, XKY_HEADER_ALIGNMENT));

	//Volcamos la cabecera
	DumpHeader(&xky_file, &pe_file, XKY_HEADER_ALIGNMENT);

	//Volcamos por este orden:
	//	.import
	//	.data
	//	.code
	//	.export
	DumpSection(&xky_file, &pe_file, IMPORT_SECTION_NAME, XKY_SECTION_ALIGNMENT);
	DumpSection(&xky_file, &pe_file, DATA_SECTION_NAME,   XKY_SECTION_ALIGNMENT);
	DumpSection(&xky_file, &pe_file, CODE_SECTION_NAME,   XKY_SECTION_ALIGNMENT);
	DumpSection(&xky_file, &pe_file, EXPORT_SECTION_NAME, XKY_SECTION_ALIGNMENT);

	//Volcamos las relocs
//	xky_module_header->relocs_section.offset = xky_file_write_pointer;
//	xky_module_header->relocs_section.size = xky_file_size - xky_file_write_pointer;
	DumpRelocs(&xky_file, &pe_file, XKY_SECTION_ALIGNMENT);

	//Volcamos a disco
	if(!xky_file.FlushToDisk(xky_file_name))
		throw std::string("Cant open dump disk file: ") + xky_file_name;
}
Ejemplo n.º 3
0
int     main() {
//==============

    char        cmd[128+1];

    ProcArgs( getcmd( cmd ) );
    if( Initialize() != 0 ) {
        return( 1 );
    }
    printf( "Building Lists...\n" );
    BuildLists();
    printf( "Finding Phrases...\n" );
    FindPhrases();
    printf( "Sorting...\n" );
    SortByRef();
    printf( "ReNumbering...\n" );
    ReNumber();
    printf( "Dumping Header...\n" );
    DumpHeader();
    printf( "Dumping Msgs...\n" );
    DumpMsg();
    printf( "Dumping GroupTable...\n" );
    DumpGroupTable();
    printf( "Dumping ErrWords...\n" );
    DumpErrWord();
    Finalize();
    return( 0 );
}
Ejemplo n.º 4
0
/*
** dump function as precompiled chunk
*/
void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data)
{
 DumpState D;
 D.L=L;
 D.write=w;
 D.data=data;
 DumpHeader(&D);
 DumpFunction(Main,NULL,&D);
}
Ejemplo n.º 5
0
void CInstQuoteDay::Dump(const char *sFileName)
{
	FILE *fh;
	int i;
	st_quoteitem *pLast;
	char m_str[1024];
	char *p;
    long lRec;
	long lBackWritePos;
	
	fh = fopen(sFileName,"w");
	if (fh == nullptr)
	{
		printf("Can not open:%s\n",sFileName);
		return;
	}
	
	pLast = nullptr;
	DumpHeader(fh,&lBackWritePos);
    lRec = 0;
	for(i=0;i<m_iQuoteArrayCount;i++)
	{
		if (m_pQuoteArray[i].m_pQuote == nullptr)
		{
			sprintf(m_str,">,%u,%u,",m_pQuoteArray[i].m_dwQuoteTime,m_pQuoteArray[i].m_dwMilliSec);
			p = m_str+strlen(m_str);
			if (i == 0)
			{
				if (m_bprefilled)
				{
					m_preitem.DumpToStr(p);
				}
			}
			else
			{
				if (pLast != nullptr)
				{
					pLast->DumpToStr(p);
				}
			}

		}
		else
		{
			sprintf(m_str," ,%u,%u,",m_pQuoteArray[i].m_dwQuoteTime,m_pQuoteArray[i].m_dwMilliSec);
			p = m_str+strlen(m_str);
			m_pQuoteArray[i].m_pQuote->DumpToStr(p);
			pLast = m_pQuoteArray[i].m_pQuote;
            lRec++;
		}
		fprintf(fh,"%s\n",m_str);
	}
    fseek(fh,lBackWritePos,SEEK_SET);
    fprintf(fh,"%10ld,%10ld",(long)m_iQuoteArrayCount,lRec);
	fclose(fh);
}
Ejemplo n.º 6
0
/*
 * dump ktap function as precompiled chunk
 */
int ktapc_dump(const ktap_proto *f, ktap_writer w, void *data, int strip)
{
	DumpState D;

	D.writer = w;
	D.data = data;
	D.strip = strip;
	D.status = 0;
	DumpHeader(&D);
	DumpFunction(f, &D);
	return D.status;
}
Ejemplo n.º 7
0
/*
** dump Lua function as precompiled chunk
*/
int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
{
    DumpState D;
    D.L=L;
    D.writer=w;
    D.data=data;
    D.strip=strip;
    D.status=0;
    DumpHeader(&D);
    DumpFunction(f,NULL,&D);
    return D.status;
}
Ejemplo n.º 8
0
/*
** dump Lua function as precompiled chunk with specified target
*/
int luaU_dump_crosscompile (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip, DumpTargetInfo target)
{
 DumpState D;
 D.L=L;
 D.writer=w;
 D.data=data;
 D.strip=strip;
 D.status=0;
 D.target=target;
 DumpHeader(&D);
 DumpFunction(f,NULL,&D);
 return D.status;
}
Ejemplo n.º 9
0
/*
** dump Lua function as precompiled chunk
*/
int luaU_dump (LuaThread* L, const LuaProto* f, lua_Writer w, void* data, int strip)
{
 THREAD_CHECK(L);
 DumpState D;
 D.L=L;
 D.writer=w;
 D.data=data;
 D.strip=strip;
 D.status=0;
 DumpHeader(&D);
 DumpFunction(f,&D);
 return D.status;
}
Ejemplo n.º 10
0
void DumpROMImage( PIMAGE_ROM_HEADERS pROMHeader )
{
    DumpHeader(&pROMHeader->FileHeader);
    printf("\n");

    DumpROMOptionalHeader(&pROMHeader->OptionalHeader);
    printf("\n");

    DumpSectionTable( IMAGE_FIRST_ROM_SECTION(pROMHeader), 
                        pROMHeader->FileHeader.NumberOfSections, TRUE);
    printf("\n");

	// Dump COFF symbols out here.  Get offsets from the header
}
Ejemplo n.º 11
0
//o--------------------------------------------------------------------------o
//|	Function		-	bool Save( ofstream &outStream )
//|	Date			-	28th July, 2000
//|	Programmer		-	Abaddon
//|	Modified		-
//o--------------------------------------------------------------------------o
//|	Purpose			-	Saves a multi out to disk
//|						outStream is the file to write to
//o--------------------------------------------------------------------------o
bool CMultiObj::Save( std::ofstream &outStream )
{
	bool rvalue = false;
	if( !isFree() )
	{
		rvalue = true;
		MapData_st& mMap = Map->GetMapData( worldNumber );
		if( GetCont() != NULL || ( GetX() > 0 && GetX() < mMap.xBlock && GetY() < mMap.yBlock ) )
		{
			DumpHeader( outStream );
			DumpBody( outStream );
			DumpFooter( outStream );
		}
	}
	return rvalue;
}
Ejemplo n.º 12
0
/*
** dump Lua function as precompiled chunk
*/
int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip, char endian)
{
 DumpState D;
 D.L=L;
 D.writer=w;
 D.data=data;
 D.strip=strip;
 D.status=0;
 D.swap=doendian(endian);
 D.endian=endian;
 luaZ_initbuffer(L, &D.b);
 DumpHeader(&D);
 DumpFunction(f,NULL,&D);
 luaZ_freebuffer(L, &D.b);
 return D.status;
}
Ejemplo n.º 13
0
Archivo: luac.c Proyecto: jcubic/ToME
void luaU_dumpchunk_file(const Proto* Main, PHYSFS_file* D)
{
	cptr err;

	DumpByte = DumpByte_file;
	DumpSig = DumpSig_file;
	DumpBlock = DumpBlock_file;
	DumpVector = DumpVector_file;

	DumpHeader(D);
	DumpFunction(Main,D);

	if ((err = PHYSFS_getLastError()) != NULL)
	{
		quit(format("luac: write error: %s", err));
	}
}
Ejemplo n.º 14
0
/*
** dump Lua function as precompiled chunk
*/
int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
{
 LuaDumpConfig config;
 DumpState D;
 D.L=L;
 D.writer=w;
 D.data=data;
 D.strip=strip;
 D.status=0;

 // Dump functions are expecting this config 
 config.endianness = (luaU_getHostOrder() == WWS_LUA_LITTLE_ENDIAN) ? 1 : 0;
 config.sizeof_int = sizeof(int);
 config.sizeof_size_t = sizeof(size_t);
 config.sizeof_lua_Number = sizeof(lua_Number);
 D.config = &config;

 DumpHeader(&D);
 DumpFunction(f,NULL,&D);
 return D.status;
}
Ejemplo n.º 15
0
void luaU_dumpchunk(const Proto* Main, FILE* D)
{
 DumpHeader(D);
 DumpFunction(Main,D);
}
Ejemplo n.º 16
0
bool DumpExeFileNE( MPanelItem *pRoot, PIMAGE_DOS_HEADER dosHeader, PIMAGE_OS2_HEADER pOS2Header )
{
	PBYTE pImageBase = (PBYTE)dosHeader;

	pRoot->Root()->AddFlags(_T("16BIT"));


	//MPanelItem* pDos = pRoot->AddFile(_T("DOS_Header"), sizeof(*dosHeader));
	//pDos->SetData((const BYTE*)dosHeader, sizeof(*dosHeader));
	DumpHeader(pRoot, dosHeader);

	
	//MPanelItem* pChild = pRoot->AddFolder(_T("OS2 Header"));
	MPanelItem* pChild = pRoot->AddFile(_T("OS2_Header.txt"));
	pChild->AddText(_T("<OS2 Header>\n"));

	MPanelItem* pOS2 = pRoot->AddFile(_T("OS2_Header"), sizeof(*pOS2Header));
	pOS2->SetData((const BYTE*)pOS2Header, sizeof(*pOS2Header));


	if (pOS2Header->ne_magic != IMAGE_OS2_SIGNATURE) {
		pChild->AddText(_T("  IMAGE_OS2_SIGNATURE_LE signature not supported\n"));
		return true;
	}

	pChild->AddText(_T("  Signature:                          IMAGE_OS2_SIGNATURE\n"));  

	pChild->printf(_T("  Version number:                     %u\n"), (UINT)pOS2Header->ne_ver);
	pChild->printf(_T("  Revision number:                    %u\n"), (UINT)pOS2Header->ne_rev);
	pChild->printf(_T("  Offset of Entry Table:              %u\n"), (UINT)pOS2Header->ne_enttab);
	pChild->printf(_T("  Number of bytes in Entry Table:     %u\n"), (UINT)pOS2Header->ne_cbenttab);
	pChild->printf(_T("  Checksum of whole file:             0x%08X\n"), (UINT)pOS2Header->ne_crc);
	pChild->printf(_T("  Flag word:                          0x%04X\n"), (UINT)pOS2Header->ne_flags);
	pChild->printf(_T("  Automatic data segment number:      %u\n"), (UINT)pOS2Header->ne_autodata);
	pChild->printf(_T("  Initial heap allocation:            %u\n"), (UINT)pOS2Header->ne_heap);
	pChild->printf(_T("  Initial stack allocation:           %u\n"), (UINT)pOS2Header->ne_stack);
	pChild->printf(_T("  Initial CS:IP setting:              0x%08X\n"), (UINT)pOS2Header->ne_csip);
	pChild->printf(_T("  Initial SS:SP setting:              0x%08X\n"), (UINT)pOS2Header->ne_sssp);
	pChild->printf(_T("  Count of file segments:             %u\n"), (UINT)pOS2Header->ne_cseg);
	pChild->printf(_T("  Entries in Module Reference Table:  %u\n"), (UINT)pOS2Header->ne_cmod);
	pChild->printf(_T("  Size of non-resident name table:    %u\n"), (UINT)pOS2Header->ne_cbnrestab);
	pChild->printf(_T("  Offset of Segment Table:            %u\n"), (UINT)pOS2Header->ne_segtab);
	pChild->printf(_T("  Offset of Resource Table:           %u\n"), (UINT)pOS2Header->ne_rsrctab);
	pChild->printf(_T("  Offset of resident name table:      %u\n"), (UINT)pOS2Header->ne_restab);
	pChild->printf(_T("  Offset of Module Reference Table:   %u\n"), (UINT)pOS2Header->ne_modtab);
	pChild->printf(_T("  Offset of Imported Names Table:     %u\n"), (UINT)pOS2Header->ne_imptab);
	pChild->printf(_T("  Offset of Non-resident Names Table: %u\n"), (UINT)pOS2Header->ne_nrestab);
	pChild->printf(_T("  Count of movable entries:           %u\n"), (UINT)pOS2Header->ne_cmovent);
	pChild->printf(_T("  Segment alignment shift count:      %u\n"), (UINT)pOS2Header->ne_align);
	pChild->printf(_T("  Count of resource segments:         %u\n"), (UINT)pOS2Header->ne_cres);
	pChild->printf(_T("  Target Operating system:            %u\n"), (UINT)pOS2Header->ne_exetyp);
	pChild->printf(_T("  Other .EXE flags:                   0x%02X\n"), (UINT)pOS2Header->ne_flagsothers);
	pChild->printf(_T("  offset to return thunks:            %u\n"), (UINT)pOS2Header->ne_pretthunks);
	pChild->printf(_T("  offset to segment ref. bytes:       %u\n"), (UINT)pOS2Header->ne_psegrefbytes);
	pChild->printf(_T("  Minimum code swap area size:        %u\n"), (UINT)pOS2Header->ne_swaparea);
	pChild->printf(_T("  Expected Windows version number:    %u.%u\n"), (UINT)HIBYTE(pOS2Header->ne_expver), (UINT)LOBYTE(pOS2Header->ne_expver));

	pChild->AddText(_T("\n"));

	if (pOS2Header->ne_rsrctab) {
		LPBYTE pResourceTable = (((LPBYTE)pOS2Header)+pOS2Header->ne_rsrctab);
		DumpNEResourceTable(pRoot, dosHeader, pResourceTable);
		//MPanelItem* pChild = pRoot->AddFolder(_T("Resource Table"));
		//pChild->AddText(_T("<Resource Table>\n"));
	}

	return true;
}
Ejemplo n.º 17
0
Archivo: main.c Proyecto: bochf/testing
/* ========================================================================= */
int main(int argc, char *argv[])
{
  struct options *o;

  /* Set our globals to NULL */
  gcf = NULL;
  grf = NULL;

#ifndef BIN_NAME
  CompileFailNoBinaryNameDefined();
#endif

  /* We want a 64 bit value for size_t - insure it is so */
  assert(8 == sizeof(size_t));

  /* Read options from the command line into a manageable struct */
  if ( NULL == (o = ParseOptions(argc, argv)) )
    return(1);

  /* Does user want usage info? */
  if ( o->bHelp )
  {
    usage();
    return(0);
  }

  /* Does user want about info? */
  if ( o->bAbout )
  {
    about();
    return(0);
  }

  if ( o->bAppend )
  {
    if ( o->iRolling )
    {
      if ( IsCircularFile(o->filename) )
      {
	fprintf(stderr, "WARNING: Unable to convert circular file to rolling - staying circular.\n");
	return(ClogAppendSession(o));
      }

      return(RlogAppendSession(o));
    }

    /* No type is specified - assume circular */
    if ( IsCircularFile(o->filename) )
    {
      return(ClogAppendSession(o));
    }
    else
    {
      if(NULL != (LoadMetaDataFile(o->filename)) )
	return(RlogAppendSession(o));

      return(ClogSession(o));
    }
  }

  if ( o->bDumpHeader )
    return(DumpHeader(o));

  if ( o->bDumpMetadata )
  {
    struct rfile *rf;

    if ( NULL == (rf = LoadMetaDataFile(o->filename)) )
      return(1);

    return(PrintMetaData(rf));
  }

  if ( o->bDump )
  {
    if ( IsCircularFile(o->filename) )
      return(DumpCircularFile(o));
    else
      return(DumpRotatingFile(o));
  }

  if ( o->iRolling )
    return(RlogSession(o));

  return(ClogSession(o));
}
Ejemplo n.º 18
0
/**
*
* This function reads the data at the provided FLASH address and expects
* the partition header structure to be present. If the header is not
* present (blank FLASH) or does not match expected values, MOVE_IMAGE_FAIL
* is returned.
*
* There are four cases in partition handling:
*
* 1. If attribute indicates this is a bitstream partition, FPGA is programmed,
*	and if this is the last partition, FSBL hangs with WDT kicking
* 2. If Image word Length != data word length, the partition is encrypted
*	partition. The partition is decrypted into DDR
* 3. Other cases, partition is moved from flash to DDR through copying or DMA
* 4. If partition data word length is 0, the partition is to be skipped. Note
*	that partition header cannot be encrypted for this to work
*
* Except case 1, the reboot status register is updated to reflect the next
* partition.
*
* @param	ImageAddress is the start of the image
* @param	PartitionNum is the index of the partition to process
*
* @return
*		- MOVE_IMAGE_FAIL (0xFFFFFFFF) if image load failed
*		- Address to begin executing at if successful
*
* @note
*
****************************************************************************/
u32 PartitionMove(u32 ImageAddress, int PartitionNum)
{
	u32 SourceAddr;
	u32 LoadAddr;
	u32 ExecAddr;
	u32 ImageLength;
	u32 DataLength;
	u32 SectionCount;
	u32 PartitionStart;
	u32 PartitionLength;
	u32 NextPartitionAddr;
	int NextPartition;
	u32 Status;
	u32 Attribute;

	 /* Flag to determine if image is encrypted or not */
	u32 IsEncrypted = 0;
	struct HeaderArray *Hap;
	struct PartHeader Header;
	/* Execution Address */
	ExecAddr = MOVE_IMAGE_FAIL;

	/* Default is not to skip partition execution */
	SkipPartition = 0;

	fsbl_printf(DEBUG_INFO,"image move with partition number %d\r\n",
			PartitionNum);

	PartitionStart = GoToPartition(ImageAddress, PartitionNum);

	GetHeader(PartitionStart, &Header);

	fsbl_printf(DEBUG_INFO,"Header dump:\n\r");
	DumpHeader(&Header);

	Hap = (struct HeaderArray *)&Header;
	Status = ValidateHeader(&Header);

	if(Status != XST_SUCCESS) {
		return Status;
	}

	ImageLength = Header.ImageWordLen;
	DataLength = Header.DataWordLen;
	PartitionLength = Header.PartitionWordLen;
	LoadAddr = Header.LoadAddr;
	ExecAddr = Header.ExecAddr;
	SourceAddr = Header.PartitionStart;
	Attribute = Header.PartitionAttr;
	SectionCount = Header.SectionCount;

	/* The offset in header is word offset */
	SourceAddr = SourceAddr << WORD_LENGTH_SHIFT;

	/* Consider image offset */
	SourceAddr += ImageAddress;

	fsbl_printf(DEBUG_INFO,"Partition Start %08x, "
						"Partition Length %08x\r\n",
						PartitionStart, PartitionLength);

	fsbl_printf(DEBUG_INFO,"Source addr %08x, Load addr %08x, "
						"Exec addr %08x\r\n",
						SourceAddr, LoadAddr, ExecAddr);

	/*
	 * If encrypted partition header, will get wrong next partition
	 * address. Next run will fail and invoke FSBL fallback.
	 * WARNING: Cannot handle skipping over encrypted partition header
	 */
	if (DataLength == 0) {
		fsbl_printf(DEBUG_INFO,"PartitionImageMove: skip partition. "
			"If encrypted partition, will fail\r\n");

		SkipPartition = 1;
		goto update_status_reg;
	}

	if (Attribute == ATTRIBUTE_PL_IMAGE_MASK) {

		/* FSBL user hook call before bitstream download. */
		Status = FsblHookBeforeBitstreamDload();

		if (Status != XST_SUCCESS) {
			/* Error Handling here */
			fsbl_printf(DEBUG_GENERAL,"FSBL_BEFORE_BSTREAM_HOOK_FAILED\r\n");
			OutputStatus(FSBL_BEFORE_BSTREAM_HOOK_FAIL);
			FsblFallback();
		}

		/* Check if encrypted or non encrypted */
		/* If the ImageLength not equal to DataLength, encrypted */
		if (ImageLength != DataLength) {
			IsEncrypted = 1;
			fsbl_printf(DEBUG_INFO,"Encrypted partition \r \n");
		}

		fsbl_printf(DEBUG_INFO,"Source addr %x, load addr %x, "
				"exec addr %x\r\n", SourceAddr, LoadAddr, ExecAddr);

		fsbl_printf(DEBUG_GENERAL,"Bitstream Download Start \r\n");

		if (IsEncrypted) {
			/* Bitstream NAND/SD encrypted */
			if (((FlashReadBaseAddress & 0xFF000000) == XPS_NAND_BASEADDR) ||
				(FlashReadBaseAddress == XPS_SDIO0_BASEADDR)) {
				fsbl_printf(DEBUG_INFO,"Bitstream NAND/SD encrypted \r\n");
				Status = WritePcapXferData(
						(u32 *)(SourceAddr),
						(u32 *)XDCFG_DMA_INVALID_ADDRESS,
						(ImageLength), 0, XDCFG_SECURE_PCAP_WRITE);
			} else {
			/* Bitstream QSPI/NOR Encrypted */
				fsbl_printf(DEBUG_INFO,"Bit stream QSPI/NOR encrypted \r\n");
				Status = WritePcapXferData(
		 					(u32 *)(FlashReadBaseAddress + SourceAddr),
							(u32 *)XDCFG_DMA_INVALID_ADDRESS,
							(ImageLength), 0, XDCFG_SECURE_PCAP_WRITE);
			}

		} else {
				/* Bitstream NAND/SD Unencrypted */
				if (((FlashReadBaseAddress & 0xFF000000) == XPS_NAND_BASEADDR) ||
						(FlashReadBaseAddress == XPS_SDIO0_BASEADDR)) {
					fsbl_printf(DEBUG_INFO,"Bit stream NAND/SD Unencrypted \r\n");
					Status = WritePcapXferData(
							(u32 *)(SourceAddr),
							(u32 *)XDCFG_DMA_INVALID_ADDRESS,
							(ImageLength), 0, XDCFG_NON_SECURE_PCAP_WRITE);
				} else {
					/* Bitstream QSPI/NOR - unencrypted */
					fsbl_printf(DEBUG_INFO,"Bitstream QSPI/NOR Unencrypted \r\n");
					Status = WritePcapXferData(
						(u32 *)(FlashReadBaseAddress + SourceAddr),
						(u32 *)XDCFG_DMA_INVALID_ADDRESS,
						(ImageLength), 0, XDCFG_NON_SECURE_PCAP_WRITE);
				}
		}

		if (Status != XST_SUCCESS) {
			fsbl_printf(DEBUG_GENERAL,"BITSTREAM_DOWNLOAD_FAIL");
			OutputStatus(BITSTREAM_DOWNLOAD_FAIL);
			return MOVE_IMAGE_FAIL;
		} else {
			fsbl_printf(DEBUG_GENERAL,"Bitstream download successful!\r\n");
		}

		/* FSBL user hook call after bitstream download. */
		Status = FsblHookAfterBitstreamDload();

		if (Status != XST_SUCCESS) {
			fsbl_printf(DEBUG_GENERAL,"FSBL_AFTER_BSTREAM_HOOK_FAIL");
			/* Error Handling here */
			OutputStatus(FSBL_AFTER_BSTREAM_HOOK_FAIL);
			FsblFallback();
		}
		/* We will skip soft reset and start loading the next partition */
		SkipPartition = 1;

		/* Go to the next partition */
		goto update_status_reg;

	} /* End of bitstream */
	/* Process all the partitions of application */

	while(SectionCount-- > 0) {

	/* If image length not equal to data length, encrypted */
	if (ImageLength != DataLength) {
		IsEncrypted = 1;
		fsbl_printf(DEBUG_INFO,"Application encrypted\n\r");
		/* NAND and SD do not support encrypted partitions */
		 if (((FlashReadBaseAddress & 0xFF000000) == XPS_NAND_BASEADDR) ||
			 (FlashReadBaseAddress == XPS_SDIO0_BASEADDR)) {

			 fsbl_printf(DEBUG_INFO,"Images on NAND or SD	encrypted\r\n");
			 Status = WritePcapXferData(
						(u32 *)SourceAddr,
						(u32 *)LoadAddr, ImageLength,
						 DataLength, XDCFG_SECURE_PCAP_WRITE);

		} else {
			 Status = WritePcapXferData(
					 	 (u32 *)(FlashReadBaseAddress + SourceAddr),
					 	 (u32 *)LoadAddr, ImageLength,
					 	 DataLength, XDCFG_SECURE_PCAP_WRITE);

		}
		 
		if (Status != XST_SUCCESS) {
			fsbl_printf(DEBUG_GENERAL,"DECRYPTION_FAIL \r\n");
			OutputStatus(DECRYPTION_FAIL);
			return MOVE_IMAGE_FAIL;
		 }
		 
		fsbl_printf(DEBUG_INFO,"Transfer is completed \r\n");
		if (SectionCount != 0) {
			fsbl_printf(DEBUG_INFO,"load_next_partition\n\r");
			goto load_next_partition;
		}

		goto update_status_reg;
	}	else {/*End of if ImageLength != DataLength */

		fsbl_printf(DEBUG_INFO,"Start transfer data into DDR\n\r");

		/* Copy the flash contents to DDR */

		MoveImage(SourceAddr, LoadAddr, (DataLength << WORD_LENGTH_SHIFT));

	}

load_next_partition:

	//JM detect cpu1 boot vector as last partiton and finish up
    if (LoadAddr == 0xFFFFFFF0) {
		goto update_status_reg;
	}

	PartitionNum += 1;

	/* Read the next partition */
	fsbl_printf(DEBUG_INFO,"Get next partition header\n\r");

	NextPartitionAddr = GoToPartition(ImageAddress, PartitionNum);
	GetHeader(NextPartitionAddr, &Header);

	fsbl_printf(DEBUG_INFO,"Next partition header dump\r\n");
	DumpHeader(&Header);

	Status = ValidateHeader(&Header);
	if(Status != XST_SUCCESS) {
		fsbl_printf(DEBUG_INFO,"Validation of Header failed\r\n");
		return Status;
	}

	/* Don't re-initialize ExecAddr & SectionCount */
	ImageLength = Header.ImageWordLen;
	DataLength = Header.DataWordLen;
	PartitionLength = Header.PartitionWordLen;
	LoadAddr = Header.LoadAddr;
	SourceAddr = Header.PartitionStart;
	//JM reinit SectionCount if this is a new sub-partition
	if (SectionCount == 0) {
		SectionCount = Header.SectionCount;
}

	/* The offset in header is word offset */
	SourceAddr = SourceAddr << WORD_LENGTH_SHIFT;

	/* Consider image offset */
	SourceAddr += ImageAddress;

	fsbl_printf(DEBUG_INFO,"Partition Start %08x, Partition Length %08x\r\n",
						PartitionStart, PartitionLength);

	fsbl_printf(DEBUG_INFO,"Source addr %08x, Load addr %08x, Exec addr %08x\r\n",
						SourceAddr, LoadAddr, ExecAddr);

	} /* End of while Section count > 0 */


update_status_reg:

	NextPartition = PartitionNum + 1;

	fsbl_printf(DEBUG_INFO,"Get next partition header\n\r");

	NextPartitionAddr = GoToPartition(ImageAddress, PartitionNum + 1);
	GetHeader(NextPartitionAddr, &Header);
	Hap = (struct HeaderArray *)&Header;

	fsbl_printf(DEBUG_INFO,"Next Header dump:\n\r");
	DumpHeader(&Header);

	/* If it is the last partition, then we will keep on running this one */
	if (IsLastPartition(Hap)) {
		fsbl_printf(DEBUG_INFO,"There are no more partitions to load\r\n");
		NextPartition = PartitionNum;
		/*
		 * Fix for CR #663277
		 * Review : Since we donot support OCM remap,
		 * any elf whose execution address is 0x0
		 * We will do a JTAG exit 
		 */
 
		if (ExecAddr == 0) {
			fsbl_printf(DEBUG_INFO,"No Execution Address JTAG handoff \r\n");
			/* Stop the Watchdog before JTAG handoff */
#ifdef	XPAR_XWDTPS_0_BASEADDR
			XWdtPs_Stop(&Watchdog);
#endif
			ClearFSBLIn();
			FsblHandoffJtagExit();
		}

	} else if(IsEmptyHeader(Hap)) {
		fsbl_printf(DEBUG_GENERAL,"Empty partition header \r\n");
		OutputStatus(EMPTY_PARTITION_HEADER);
		return MOVE_IMAGE_FAIL;
	}


	Status = FsblSetNextPartition(NextPartition);
	if (Status != XST_SUCCESS) {
		fsbl_printf(DEBUG_INFO,"Next partition number %d is not valid\n",
							NextPartition);
		OutputStatus(TOO_MANY_PARTITIONS);
		return MOVE_IMAGE_FAIL;
	 }

	fsbl_printf(DEBUG_INFO,"end of partition move, reboot status reg %x, "
		 "Next partition %d\r\n", MoverIn32(REBOOT_STATUS_REG), NextPartition);

	/* Returning Execution Address */
	return ExecAddr;
} /* End of Partition Move */
Ejemplo n.º 19
0
MODULE_HEADERS *
ExecPE(char *lpszName)
{
	static void *BaseAddress;

	IMAGE_DOS_HEADER DosHeader;
 	PIMAGE_SECTION_HEADER pSectionHeaders;
	PIMAGE_NT_HEADERS pNTHeader;
	static int nNTHeader;
	int i,len;
	int index = nNTHeader;
	char *bp;
	int ret;
	HFILE hFile;

	bp = lpszName;
	while(*bp) {
		*bp = tolower(*bp);
		bp++;
	}
	for(i=0;i<nNTHeader;i++) {
		if(strcmp(NTModules[i].modulename,lpszName) == 0) {
			return &NTModules[i];
		}
	}

    	hFile = _lopen(lpszName,READ);
	if(hFile == -1) {
		char lpszFileName[256];

		strcpy(lpszFileName,dirname);	
		strcat(lpszFileName,"/");	
		strcat(lpszFileName,lpszName);	

		hFile = _lopen(lpszFileName,READ);

		if(hFile == -1) {
			logstr(LF_ERROR,"cannot open file %s\n",lpszFileName);
			return 0;
		}		
	}

	/* read the dos image header first */
        ret = _lread(hFile,&DosHeader,sizeof(IMAGE_DOS_HEADER));

	if(DosHeader.e_magic == IMAGE_DOS_SIGNATURE)	{

		/* now read in the nt header */
    		_llseek(hFile,DosHeader.e_lfanew,0);

		pNTHeader = &NTHeader[nNTHeader];

		ret = _lread(hFile,pNTHeader, sizeof(IMAGE_NT_HEADERS));

		/* yes, it is a win32 header */
		if (pNTHeader->Signature != IMAGE_NT_SIGNATURE) {
			_lclose(hFile);
			return 0;
		}
		

		bp = strrchr(lpszName,'/');
		if(bp)
			bp++;
		else 
			bp = lpszName;

		BaseAddress = VirtualAlloc(
			(void *) pNTHeader->OptionalHeader.ImageBase,
			pNTHeader->OptionalHeader.SizeOfImage,
			MEM_COMMIT,
			PAGE_EXECUTE_READWRITE);

		logstr(lf_console,"Load File: %s %p\n",lpszName,BaseAddress);

		NTModules[nNTHeader].modulename = bp; 		
		NTModules[nNTHeader].pNTHeader = pNTHeader; 		
		NTModules[nNTHeader].BaseAddress = BaseAddress; 		
		nNTHeader++;

		if (nNTHeader == 1 && usebuiltins) {
			NTModules[nNTHeader++].modulename = "user32.dll";
			NTModules[nNTHeader++].modulename = "gdi32.dll";
			NTModules[nNTHeader++].modulename = "kernel32.dll";
			NTModules[nNTHeader++].modulename = "shell32.dll";
			NTModules[nNTHeader++].modulename = "comctl32.dll";
			NTModules[nNTHeader++].modulename = "comdlg32.dll";
			NTModules[nNTHeader++].modulename = "rpcrt4.dll";
			NTModules[nNTHeader++].modulename = "advapi32.dll";
		}

		/* show the NT header */
	 	//if (index == 0)
		   DumpHeader(&pNTHeader->FileHeader);

		/* show the Optional header */
	 	//if (index == 0)
		   DumpOptionalHeader((PIMAGE_OPTIONAL_HEADER) 
			&pNTHeader->OptionalHeader);

		pSectionHeaders = (PIMAGE_SECTION_HEADER)((void *)BaseAddress + sizeof(IMAGE_NT_HEADERS));

		/* now read the section headers */
		ret = _lread( hFile, pSectionHeaders, sizeof(IMAGE_SECTION_HEADER)*
			pNTHeader->FileHeader.NumberOfSections);

		for(i=0; i < pNTHeader->FileHeader.NumberOfSections; i++) {
			void *LoadAddress;

			LoadAddress = 
				RVA(BaseAddress,pSectionHeaders->VirtualAddress);
			//if (index == 0) 
			{
			   DumpSectionTable( LoadAddress,pSectionHeaders,i);
			}

			/* load only non-BSS segments */
			if(!(pSectionHeaders->Characteristics &
				IMAGE_SCN_CNT_UNINITIALIZED_DATA)) 
		        {
			    _llseek(hFile,pSectionHeaders->PointerToRawData,SEEK_SET);
			    len = _lread(hFile,(char*) LoadAddress, 
				pSectionHeaders->SizeOfRawData);

			    if( len != pSectionHeaders->SizeOfRawData)
			    {
				logstr(LF_ERROR,"Failed to load section %x %x\n", i,len);
				exit(0);
			    }
			    pSectionHeaders++;
			}
			
			/* not needed, memory is zero */
			if(strcmp(pSectionHeaders[i].Name, ".bss") == 0)
			    memset((void *)LoadAddress, 0,
				   pSectionHeaders[i].Misc.VirtualSize ?
				   pSectionHeaders[i].Misc.VirtualSize :
				   pSectionHeaders[i].SizeOfRawData);
		}

		_lclose(hFile);

		// we are dependent on other modules, go get and load those
		//if (index == 0)
		   LoadImportsSection(BaseAddress, pNTHeader,lpszName);

		if (index == 0) 
		{
			logstr(lf_header,"   %32s   PE Header  BaseAddress\n",
				"FileName");
			for(i=0;i<nNTHeader;i++) {
			   logstr(lf_header,"%.4d: %32s %p %p\n",
				i,
				NTModules[i].modulename,
				NTModules[i].pNTHeader,
				NTModules[i].BaseAddress);
			}	
        		
		}

		if (index == 0)
		   LoadExportsTable(&NTModules[0],pNTHeader,lpszName);

		if (index == 0)
		   ExecEntryPoint(
			NTModules[0].BaseAddress, 
			NTModules[0].pNTHeader, 
			lpszName);

		return &NTModules[index]; 		
	}
	return 0;
}
Ejemplo n.º 20
0
void DumpChunk(TProtoFunc* Main, FILE* D) {
 DumpHeader(Main,D);
 DumpFunction(Main,D);
}
Ejemplo n.º 21
0
void dump_lx(std::fstream &file, int hdrOfs, LEHeader &leh)
{
    DumpHeader(leh);
    std::cout << "Object table: " << leh.object_count << std::endl;
    file.seekg(hdrOfs + leh.object_table_offset);
    unsigned buf[6];
    int initPages = 0;
    for (int i=0; i < leh.object_count; i++)
    {
        file.read((char *)buf, sizeof(buf));
        std::cout << "  " << "Object " << i + 1 << ":" << std::endl;
        std::cout << "    " << "Flags:   " << std::hex << std::setw(8) << std::setfill('0') << buf[2] << std::endl;
        std::cout << "    " << "Base:    " << std::hex << std::setw(8) << std::setfill('0') << buf[1] << std::endl;
        std::cout << "    " << "Size:    " << std::hex << std::setw(8) << std::setfill('0') << buf[0] << std::endl;
        std::cout << "    " << "InitSize:" << std::hex << std::setw(8) << std::setfill('0') << buf[4] << std::endl;
        std::cout << "    " << "PageOffs:" << std::hex << std::setw(8) << std::setfill('0') << buf[3] << std::endl;
        initPages += buf[4];
        
    }
    std::cout << "Object page table: " << leh.object_count;
    LXObjectPage::PageData p;
    file.seekg(hdrOfs + leh.object_page_table_offset);
    for (int i=0; i < leh.object_count; i++)
    {
        if (i %8 == 0)
            std::cout << std::endl;
        file.read((char *)&p, sizeof(p));
        std::cout << "    " << i + 1 << ": " << std::hex << std::setw(2) << std::setfill('0') << (int)p.flags << "  " ;
        std::cout << std::hex << std::setw(8) << std::setfill('0') << (int)p.data_offset << " ";
        std::cout << std::hex << std::setw(4) << std::setfill('0') << (int)p.data_size << std::endl;
    }
    std::cout << std::endl << std::endl;
    std::cout << "Fixups: " << std::endl;
    file.seekg(hdrOfs +leh.fixup_page_table_offset);
    unsigned *pt = new unsigned[initPages + 1];
    file.read((char *)pt, (initPages + 1) * sizeof(unsigned));
    file.seekg(hdrOfs + leh.fixup_record_table_offset);
    for (int i=1; i <= initPages; i++)
    {
        int offs = pt[i-1];
        std::cout << "  Page: " << i << ":" << pt[i-1] << ":" << pt[i] << std::endl;
        while (pt[i] > offs)
        {
            // only handling the types of fixups genned by dlle
            unsigned char bf[9];
            file.read((char *)bf, 7);
            offs += 7;
            if (bf[1] & LX_FF_TARGET32)
            {
                offs += 2;
                file.read((char *)bf+7, 2);
            }
            else
            {
                bf[7] = bf[8] = 0;
            }
            std::cout << "    " << std::hex << std::setw(2) << std::setfill('0') << (int)bf[0] << " ";
            std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)bf[1] << " ";
            std::cout << std::hex << std::setw(4) << std::setfill('0') << (int)((unsigned short *)(bf + 2))[0] << " ";
            std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)bf[4] << " ";
            std::cout << std::hex << std::setw(8) << std::setfill('0') << (int)((unsigned *)(bf+ 5))[0] << " " << std::endl;
        }
    }
    
    delete pt;
}