HEX
Server: Apache/2.4.6 () OpenSSL/1.0.2k-fips PHP/8.3.8
System: Linux gateway.rmc-logistics.net 4.1.12-124.48.6.el7uek.x86_64 #2 SMP Tue Mar 16 14:57:50 PDT 2021 x86_64
User: apache (48)
PHP: 8.3.8
Disabled: NONE
Upload Files
File: //usr/share/qemu-kvm/dump-guest-memory.pyo
�
\5�bc@sRddlZddlZejd�ZdZdZdZdZdZ	dZ
dZdZdZ
dZdZd	Zd
ZdZdZd
ZdZdZd�Zd�Zd�Zdefd��YZd�Zdejfd��YZd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&dej'fd ��YZ(e(�dS(!i����Nt	uintptr_tilp���i��iiiiiiii�i>cCs tjdtjd|��dS(Ns<Hs=Hi(tstructtunpacktpack(tval((s(/usr/share/qemu-kvm/dump-guest-memory.pytle16_to_cpu6scCs tjdtjd|��dS(Ns<Is=Ii(RRR(R((s(/usr/share/qemu-kvm/dump-guest-memory.pytle32_to_cpu9scCs tjdtjd|��dS(Ns<Qs=Qi(RRR(R((s(/usr/share/qemu-kvm/dump-guest-memory.pytle64_to_cpu<stELFcBs;eZdZd�Zd�Zd�Zd�Zd�ZRS(sRepresentation of a ELF file.cCsd|_g|_g|_d|_d|_t|_|dkr{t|_t|_t	|j|j�|_t
|j_n�|dkr�t|_t	|j|j�|_t
|j_nD|dkr�t|_t	|j|j�|_t
|j_n|dkr8t|_t|_t	|j|j�|_t|j_n�|dkrtt|_t	|j|j�|_t|j_n�|dkr�t|_t	|j|j�|_t|j_nK|dkr�t|_t	|j|j�|_t|j_ntjd	��|jtdd�dS(
Nis
aarch64-les
aarch64-betX86_64t386ts390sppc64-lesppc64-besvNo valid arch type specified.
Currently supported types:
aarch64-be, aarch64-le, X86_64, 386, s390, ppc64-be, ppc64-le(tNonetehdrtnotestsegmentst
notes_sizet
endiannesst
ELFCLASS64telfclasstELFDATA2LSBt
get_arch_ehdrtEM_AARCHt	e_machinetELFDATA2MSBt	EM_X86_64t
ELFCLASS32tEM_386tEM_S390tEM_PPC64tgdbtGdbErrortadd_segmenttPT_NOTE(tselftarch((s(/usr/share/qemu-kvm/dump-guest-memory.pyt__init__BsL															cCs�t|jt|�t|��}t|�d|_t|�|_|j�|_||_tj	|j
|j�t|��|jj|�|j
djtj|�7_|j
djtj|�7_dS(sAdds a note to the ELF.iiN(t
get_arch_noteRtlentn_namesztn_descsztencodetn_nametn_typetctypestmemmovetn_descRtappendRtp_filesztsizeoftp_memsz(R"R*R.R+tnote((s(/usr/share/qemu-kvm/dump-guest-memory.pytadd_notews!	"cCs�t|jdd�}tjtj|�|tj|��|jdkrRdGHdSt|j|jd|j�}tjtj|�|tj|��|jj	|�|j
djtj|�7_|j
djtj|�7_dS(s'Adds a vmcoreinfo note to the ELF dump.iiis warning: invalid vmcoreinfo sizeNi(
R%RR,R-tpointerR1R(R'RR/RR0R2(R"t
vmcoreinfotheaderR3((s(/usr/share/qemu-kvm/dump-guest-memory.pytadd_vmcoreinfo_note�s	%cCs_t|j|j�}||_||_||_||_|jj|�|j	j
d7_
dS(sAdds a segment to the elf.iN(t
get_arch_phdrRRtp_typetp_paddrR0R2RR/R
te_phnum(R"R:R;tp_sizetphdr((s(/usr/share/qemu-kvm/dump-guest-memory.pyR �s				cCs�|j|j�tj|j�t|j�tj|jd�}x4|jD])}||_|j|�||j7}qMWx|jD]}|j|�q�WdS(s�Writes all ELF structures to the the passed file.

        Structure:
        Ehdr
        Segment 0:PT_NOTE
        Segment 1:PT_LOAD
        Segment N:PT_LOAD
        Note    0..N
        Dump contents
        iN(	twriteR
R,R1R&Rtp_offsetR0R(R"telf_filetoffR>R3((s(/usr/share/qemu-kvm/dump-guest-memory.pytto_file�s$	
(t__name__t
__module__t__doc__R$R4R8R RC(((s(/usr/share/qemu-kvm/dump-guest-memory.pyR?s	5			csQ|tkrtj}n	tj}�d�d|f��fd��Y}|�S(s3Returns a Note class with the specified endianness.itNotecs`eZdZdejfdejfdejfdej�fdej�ddfgZRS(s-Represents an ELF note, includes the content.R'R(R+R*R.ii(RDRERFR,tc_uint32tc_chart_fields_((tlen_desctlen_name(s(/usr/share/qemu-kvm/dump-guest-memory.pyRG�s(RR,tLittleEndianStructuretBigEndianStructure(RRLRKt
superclassRG((RKRLs(/usr/share/qemu-kvm/dump-guest-memory.pyR%�s	
tIdentcBs�eZdZdejfdejfdejfdejfdejfdejfdejfdejfd	ejfd
ejdfg
Zd�ZRS(
s5Represents the ELF ident array in the ehdr structure.tei_mag0tei_mag1tei_mag2tei_mag3tei_classtei_datat
ei_versiontei_osabit
ei_abiversiontei_padicCsUd|_td�|_td�|_td�|_||_||_t|_dS(NitEtLtF(	RQtordRRRSRTRURVt
EV_CURRENTRW(R"RR((s(/usr/share/qemu-kvm/dump-guest-memory.pyR$�s			(RDRERFR,tc_ubyteRJR$(((s(/usr/share/qemu-kvm/dump-guest-memory.pyRP�scs��tkrtj�n	tj�d�f���fd��Y}d�f���fd��Y}�tkrx|�S|�SdS(s5Returns a EHDR64 class with the specified endianness.tEHDR64cs�eZdZdefdejfdejfdejfdejfdejfdejfdejfd	ejfd
ejfdejfdejfd
ejfdejfgZ���fd�Z	RS(s(Represents the 64 bit ELF header struct.te_identte_typeRt	e_versionte_entryte_phoffte_shoffte_flagste_ehsizete_phentsizeR<te_shentsizete_shnumt
e_shstrndxcs�t�|�j�t���|_t|_t|_tj	|�|_
tj	|�|_tj	t����|_
d|_dS(Ni(tsuperR$RPRbtET_CORERcR_RdR,R1RiRfR9RjR<(R"(RRRO(s(/usr/share/qemu-kvm/dump-guest-memory.pyR$s		(
RDRERFRPR,tc_uint16RHtc_uint64RJR$((RRRO(s(/usr/share/qemu-kvm/dump-guest-memory.pyRa�s 	tEHDR32cs�eZdZdefdejfdejfdejfdejfdejfdejfdejfd	ejfd
ejfdejfdejfd
ejfdejfgZ���fd�ZRS(s(Represents the 32 bit ELF header struct.RbRcRRdReRfRgRhRiRjR<RkRlRmcs�t�|�j�t���|_t|_t|_tj	|�|_
tj	|�|_tj	t����|_
d|_dS(Ni(RnR$RPRbRoRcR_RdR,R1RiRfR9RjR<(R"(RRRO(s(/usr/share/qemu-kvm/dump-guest-memory.pyR$$s		(	RDRERFRPR,RpRHRJR$((RRRO(s(/usr/share/qemu-kvm/dump-guest-memory.pyRrs 	N(RR,RMRNR(RRRaRr((RRROs(/usr/share/qemu-kvm/dump-guest-memory.pyR�s	""cCsk|tkrtj}n	tj}d|fd��Y}d|fd��Y}|tkr`|�S|�SdS(s@Returns a 32 or 64 bit PHDR class with the specified endianness.tPHDR64c	BsteZdZdejfdejfdejfdejfdejfdejfdejfdejfgZRS(	s0Represents the 64 bit ELF program header struct.R:tp_flagsR@tp_vaddrR;R0R2tp_align(RDRERFR,RHRqRJ(((s(/usr/share/qemu-kvm/dump-guest-memory.pyRs=stPHDR32c	BsteZdZdejfdejfdejfdejfdejfdejfdejfdejfgZRS(	s0Represents the 32 bit ELF program header struct.R:R@RuR;R0R2RtRv(RDRERFR,RHRJ(((s(/usr/share/qemu-kvm/dump-guest-memory.pyRwIsN(RR,RMRNR(RRRORsRw((s(/usr/share/qemu-kvm/dump-guest-memory.pyR95s	
cCs|dS(s(Returns low 64bit part of Int128 struct.tlo((R((s(/usr/share/qemu-kvm/dump-guest-memory.pytint128_get64\sccs@|d}x/|dkr;|j�}||d}|Vq
WdS(sGenerator for qtails.t	tqh_firstittqe_nextN(tdereference(theadt	field_strtvar_ptvar((s(/usr/share/qemu-kvm/dump-guest-memory.pytqtailq_foreachbs

cCs\tjd�}x3t|d�D]"}||d|dkr|SqWtjd|��dS(s?Returns the RAMBlock struct to which the given address belongs.sram_list.blockstnexttoffsettlengthsBad ram offset %xN(Rtparse_and_evalR�R(tram_addrt
ram_blockstblock((s(/usr/share/qemu-kvm/dump-guest-memory.pytqemu_get_ram_blockks
cCs t|�}|d||dS(s4Returns qemu vaddr for given guest physical address.thostR�(R�(R�R�((s(/usr/share/qemu-kvm/dump-guest-memory.pytqemu_get_ram_ptrwscCs>|ddkr,t|dj��|dSt|dt@�S(Ntaliasitalias_offsetR�(tmemory_region_get_ram_ptrR|R�tTARGET_PAGE_MASK(t
memory_region((s(/usr/share/qemu-kvm/dump-guest-memory.pyR�~s	c
	Cs�g}dGHdGHdGHtjd�}|j�}xjtt|d��D]R}|d|j�}|dj�}|ds�qGnt|d	d
�}t|d	d�}||}t|�|d}	d}
t|�d
kr+|d}
|
d|
d}|
d|ks|
d||	kr+d}
q+n|
dkrb|j	i|d6|d6|	d6�d}n||
d<d}d|||	j
t�|t|�fGHqGW|S(s�Returns a list of ram blocks.

    Each block entry contains:
    'target_start': guest block phys start address
    'target_end':   guest block phys end address
    'host_addr':    qemu vaddr of the block's start
    sguest RAM blocks:s@target_start     target_end       host_addr        message counts@---------------- ---------------- ---------------- ------- -----s address_space_memory.current_maptnrtrangestmrtramtaddrtsizetstarttoffset_in_regionii����t
target_endttarget_startt	host_addrtaddedtjoineds%016x %016x %016x %-7s %5uN(RR�R|trangetintRyR�RR&R/tcastt	UINTPTR_T(
tguest_phys_blockst
current_map_ptcurrent_maptcurt
flat_rangeR�tsection_sizeR�R�R�tpredecessortpredecessor_sizetmessage((s(/usr/share/qemu-kvm/dump-guest-memory.pytget_guest_phys_blocks�sF	

	
	
tDumpGuestMemorycBsDeZdZd�Zd�Zd�Zd�Zd�Zd�ZRS(s�Extract guest vmcore from qemu process coredump.

The two required arguments are FILE and ARCH:
FILE identifies the target file to write the guest vmcore to.
ARCH specifies the architecture for which the core will be generated.

This GDB command reimplements the dump-guest-memory QMP command in
python, using the representation of guest memory as captured in the qemu
coredump. The qemu process that has been dumped must have had the
command line option "-machine dump-guest-core=on" which is the default.

For simplicity, the "paging", "begin" and "end" parameters of the QMP
command are not supported -- no attempt is made to get the guest's
internal paging structures (ie. paging=false is hard-wired), and guest
memory is always fully dumped.

Currently aarch64-be, aarch64-le, X86_64, 386, s390, ppc64-be,
ppc64-le guests are supported.

The CORE/NT_PRSTATUS and QEMU notes (that is, the VCPUs' statuses) are
not written to the vmcore. Preparing these would require context that is
only present in the KVM host kernel module when the guest is alive. A
fake ELF note is written instead, only to keep the ELF parser of "crash"
happy.

Dependent on how busted the qemu process was at the time of the
coredump, this command might produce unpredictable results. If qemu
deliberately called abort(), or it was dumped in response to a signal at
a halfway fortunate point, then its coredump should be in reasonable
shape and this command should mostly work.cCs8tt|�jdtjtj�d|_d|_dS(Nsdump-guest-memory(	RnR�R$RtCOMMAND_DATAtCOMPLETE_FILENAMERtelfR�(R"((s(/usr/share/qemu-kvm/dump-guest-memory.pyR$�s

	cCs}|jjddd�t|j�d}x=|jD]2}|d|d}|jjt|d|�q3W|jj|�dS(s0Prepares and writes ELF structures to core file.tNONEtEMPTYiiR�R�N(R�R4R&R�R tPT_LOADRC(R"tvmcoretphdr_numR�t
block_size((s(/usr/share/qemu-kvm/dump-guest-memory.pyt	dump_init�scCs�tj�d}x�|jD]�}|d}|d|d}d|jt�|fGHxR|dkr�tt|�}|j||�}|j|�||7}||8}qWWqWdS(sWrites guest core to file.iR�R�R�s'dumping range at %016x for length %016xN(	Rt	inferiorsR�R�R�tmintTARGET_PAGE_SIZEtread_memoryR?(R"R�t	qemu_coreR�R�tleftt
chunk_sizetchunk((s(/usr/share/qemu-kvm/dump-guest-memory.pytdump_iterate
s


cCsrtj�d}x[|jD]P}|d|kr|||dkr|d||d}|j||�SqWdS(NiR�R�R�(RR�R�R�R(R"R�R�R�R�thaddr((s(/usr/share/qemu-kvm/dump-guest-memory.pytphys_memory_readscCs�d}tjd|�s.tjd|�r2dStjd|�}tjd|�}tjd|�}t|�}t|�}t|�}|tkr�dS|j||�}|r�|jjt	|��ndS(Ns$vmcoreinfo_realize::vmcoreinfo_states%ss(%s)->has_vmcoreinfos(%s)->vmcoreinfo.guest_formats(%s)->vmcoreinfo.paddrs(%s)->vmcoreinfo.size(
RR�RRRtVMCOREINFO_FORMAT_ELFR�R�R8tbytes(R"tvmcitfmtR�R�R6((s(/usr/share/qemu-kvm/dump-guest-memory.pytadd_vmcoreinfo$scCs�|j�tj|�}t|�dkr=tjd��ntd�|_t�|_|j	�t
|dd��!}|j|�|j|�WdQXdS(s$Handles command invocation from gdb.isusage: dump-guest-memory FILER	itwbN(
tdont_repeatRtstring_to_argvR&RRR�R�R�R�topenR�R�(R"targstfrom_ttytargvR�((s(/usr/share/qemu-kvm/dump-guest-memory.pytinvoke9s


(	RDRERFR$R�R�R�R�R�(((s(/usr/share/qemu-kvm/dump-guest-memory.pyR��s						()R,RRtlookup_typeR�R�R�tPN_XNUMR_RRRRRoR�R!RtEM_PPCRRRRR�RRRtobjectRR%t	StructureRPRR9RyR�R�R�R�R�tCommandR�(((s(/usr/share/qemu-kvm/dump-guest-memory.pyt<module>sH			�		H	'							I}