コード例 #1
0
ファイル: Elfheader.cpp プロジェクト: 0xZERO3/PCSX2-rr-lua
	void loadProgramHeaders()
	{
		if ( proghead == NULL )
			return;

		for( int i = 0 ; i < header.e_phnum ; i++ )
		{
			ELF_LOG( "Elf32 Program Header\n" );	
			ELF_LOG( "type:      " );
			
			switch ( proghead[ i ].p_type ) {
				default:
					ELF_LOG( "unknown %x", (int)proghead[ i ].p_type );
				break;

				case 0x1:
				{
					ELF_LOG("load");
					const uint elfsize = data.GetLength();

					if (proghead[ i ].p_offset < elfsize) {
						int size;

						if ((proghead[ i ].p_filesz + proghead[ i ].p_offset) > elfsize)
							size = elfsize - proghead[ i ].p_offset;
						else
							size = proghead[ i ].p_filesz;

						if( proghead[ i ].p_vaddr != proghead[ i ].p_paddr )
							Console::Notice( "ElfProgram different load addrs: paddr=0x%8.8x, vaddr=0x%8.8x", params
								proghead[ i ].p_paddr, proghead[ i ].p_vaddr);

						// used to be paddr
						memcpy(
							&PS2MEM_BASE[proghead[ i ].p_vaddr & 0x1ffffff],
							data.GetPtr(proghead[ i ].p_offset), size
						);

						ELF_LOG("\t*LOADED*");
					}
				}
				break;
			}
			
			ELF_LOG("\n");
			ELF_LOG("offset:    %08x\n",(int)proghead[i].p_offset);
			ELF_LOG("vaddr:     %08x\n",(int)proghead[i].p_vaddr);
			ELF_LOG("paddr:     %08x\n",proghead[i].p_paddr);
			ELF_LOG("file size: %08x\n",proghead[i].p_filesz);
			ELF_LOG("mem size:  %08x\n",proghead[i].p_memsz);
			ELF_LOG("flags:     %08x\n",proghead[i].p_flags);
			ELF_LOG("palign:    %08x\n",proghead[i].p_align);
			ELF_LOG("\n");
			
		}
	}
コード例 #2
0
ファイル: Elfheader.cpp プロジェクト: 0xZERO3/PCSX2-rr-lua
	void loadSectionHeaders() 
	{
		if( secthead == NULL || header.e_shoff > (u32)data.GetLength() )
			return;

		const u8* sections_names = data.GetPtr( secthead[ (header.e_shstrndx == 0xffff ? 0 : header.e_shstrndx) ].sh_offset );
			
		int i_st = -1;
		int i_dt = -1;

		for( int i = 0 ; i < header.e_shnum ; i++ )
		{
			ELF_LOG( "Elf32 Section Header [%x] %s", i, &sections_names[ secthead[ i ].sh_name ] );

			if ( secthead[i].sh_flags & 0x2 )
				args_ptr = min( args_ptr, secthead[ i ].sh_addr & 0x1ffffff );
			
#ifdef PCSX2_DEVBULD
			ELF_LOG("\n");
			ELF_LOG("type:      ");
			
			switch ( secthead[ i ].sh_type )
			{
				default:
					ELF_LOG("unknown %08x",secthead[i].sh_type);
					break;

				case 0x0:
					ELF_LOG("null");
					break;

				case 0x1:
					ELF_LOG("progbits");
					break;

				case 0x2:
					ELF_LOG("symtab");
					break;

				case 0x3:
					ELF_LOG("strtab");
					break;

				case 0x4:
					ELF_LOG("rela");
					break;

				case 0x8:
					ELF_LOG("no bits");
					break;

				case 0x9:
					ELF_LOG("rel");
					break;
			}
			
			ELF_LOG("\n");
			ELF_LOG("flags:     %08x\n", secthead[i].sh_flags);
			ELF_LOG("addr:      %08x\n", secthead[i].sh_addr);
			ELF_LOG("offset:    %08x\n", secthead[i].sh_offset);
			ELF_LOG("size:      %08x\n", secthead[i].sh_size);
			ELF_LOG("link:      %08x\n", secthead[i].sh_link);
			ELF_LOG("info:      %08x\n", secthead[i].sh_info);
			ELF_LOG("addralign: %08x\n", secthead[i].sh_addralign);
			ELF_LOG("entsize:   %08x\n", secthead[i].sh_entsize);
			// dump symbol table
		
			if( secthead[ i ].sh_type == 0x02 ) 
			{
				i_st = i; 
				i_dt = secthead[i].sh_link; 
			}
#endif
		}

		if( ( i_st >= 0 ) && ( i_dt >= 0 ) )
		{
			const char * SymNames;
			Elf32_Sym * eS;

			SymNames = (char*)data.GetPtr( secthead[ i_dt ].sh_offset );
			eS = (Elf32_Sym*)data.GetPtr( secthead[ i_st ].sh_offset );
			Console::WriteLn("found %d symbols", params secthead[ i_st ].sh_size / sizeof( Elf32_Sym ));

			for( uint i = 1; i < ( secthead[ i_st ].sh_size / sizeof( Elf32_Sym ) ); i++ ) {
				if ( ( eS[ i ].st_value != 0 ) && ( ELF32_ST_TYPE( eS[ i ].st_info ) == 2 ) ) {
					R5900::disR5900AddSym( eS[i].st_value, &SymNames[ eS[ i ].st_name ] );
				}
			}
		}
	}