hf]dZddlZddlmZmZmZmZmZ ddlZn #e $rdZYnwxYwddl m Z ddl m Z ddlmZGddZdS) zl maxminddb.decoder ~~~~~~~~~~~~~~~~~ This package contains code for decoding the MaxMind DB data section. N)castDictListTupleUnionInvalidDatabaseError) FileBuffer)RecordcreZdZdZ d deedefdededd fd Z d ed ede e e effd Z d ed ede eeffdZd ed ede eeffdZd ed ede eeffdZd ed ede eeffdZd ed ede eeffdZd ed ede eee feffdZd ed ede e effdZd ed ede eeffdZd ed ede eeffdZeeeeeeeeeee eed Zd ede e effdZd ede eeffdZedededd fdZded edede eeffdZd S)!Decoderz.Decoder for the data section of the MaxMind DBrFdatabase_bufferz mmap.mmap pointer_base pointer_testreturnNc0||_||_||_dS)aCreated a Decoder for a MaxMind DB Arguments: database_buffer -- an mmap'd MaxMind DB file. pointer_base -- the base number to use when decoding a pointer pointer_test -- used for internal unit testing of pointer code N) _pointer_test_buffer _pointer_base)selfrrrs q/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/maxminddb/decoder.py__init__zDecoder.__init__s!*& )sizeoffsetcg}t|D]/}||\}}||0||fSN)rangedecodeappend)rrrarray_values r _decode_arrayzDecoder._decode_array,sPt  A"kk&11OUF LL    f}rc|dk|fS)Nr)rrrs r_decode_booleanzDecoder._decode_boolean3sqy&  rc.||z}|j|||fSr)rrrr new_offsets r _decode_byteszDecoder._decode_bytes6s"d] |F:-. ::rc||d||z}|j||}tjd|\}||fS)Ns!d _verify_sizerstructunpackrrrr* packed_bytesr#s r_decode_doublezDecoder._decode_double:P $"""d] |F:$56 = 55j  rc||d||z}|j||}tjd|\}||fS)Ns!fr.r2s r _decode_floatzDecoder._decode_floatAr5rc|dkrd|fS||z}|j||}|dkr|dd}tjd|\}||fS)Nrr7s!i)rrjustr0r1r2s r _decode_int32zDecoder._decode_int32Hsk 199f9 d] |F:$56 199'--a99L= 55j  rci}t|D]J}||\}}||\}}||tt|<K||fSr)rrrstr)rrr containerr"keyr#s r _decode_mapzDecoder._decode_mapSsf') t . .A KK//MS&"kk&11OUF(-Id3nn % %&  rcf|dz dz}|j|||z}||z}|dkr:t|dzg|z}tjd|d|jz}n|dkr@dt|dzgz|z}tjd|dd z|jz}nf|dkr=t|dzg|z}tjd|dd z|jz}n#tjd|d|jz}|jr||fS||\}}||fS) N!Hrr:!Iii)rbytesr0r1rrr) rrr pointer_sizebufr*pointerr#r"s r_decode_pointerzDecoder._decode_pointer[s[ Q l6F\$99:l* 1   %%+CmE3//2T5GGGG Q  E4#:,///#5CmE3//2T9DPPGGmE3//2T5GGG   'J& &[[)) j  rcd||z}|j||}t|d|fS)Nbig)rint from_bytes)rrrr* uint_bytess r _decode_uintzDecoder._decode_uintrs5d] \&"34 ~~j%00*<> JJr) rDrGrCr7rEr- c|dz}|j|}|dz }|s||\}} |j|}n&#t$r}t d|d|d}~wwxYw||||\}}||||S)zDecode a section of the data section starting at offset Arguments: offset -- the location of the data structure to decode rDrVzUnexpected type number (z ) encounteredN)r_read_extended _type_decoderKeyErrorr _size_from_ctrl_byte)rrr* ctrl_bytetype_numdecoderexrs rrzDecoder.decodes aZ L( > E%)%8%8%D%D "Xz (2GG   &B8BBB   "66y*hWWzwtT:...s A A$ AA$cf|j|}|dz}|dkrtd|d||dzfS)NrEz^Something went horribly wrong in the decoder. An extended type resolved to a type number < 8 ()rD)rr )rr next_bytercs rr^zDecoder._read_extendeds^L( q= a<<&L@HLLL !##rexpectedactualc0||krtddS)NzXThe MaxMind DB file's data section contains bad data (unknown data type or corrupt data)r)rirjs rr/zDecoder._verify_sizes, v  &6   rrbrccP|dz}|dks|dkr||fS|dkrd|j|z}||dzfS|dkr6|dz}|j||}dtjd|dz}||fS|d z}|j||}tjd d |zdd z}||fS) NrDrGirFrrCrHr:i)rr0r1)rrbrrcrr* size_bytess rrazDecoder._size_from_ctrl_bytes4 q==D2II<  2:: V,,D!# # 2::!JfZ&78Juj99!<rArMrSrUr_rr^ staticmethodr/rar&rrr r so88 " **z;=>** *  ****"#suT&\3=N7O!C!!tSy9I!!!!;#;s;uUCZ7H;;;;!3!!eSj8I!!!!!#!s!uUCZ7H!!!! !# !s !uS#X ! ! ! !!!S!U4V ;Lc;Q5R!!!!!C!!vs{9K!!!!.==c=eCHo==== KKSKU38_KKKK             M /S/U63;%7////.$S$U38_$$$$sCD\  &) 58 sCx      rr )rtr0typingrrrrrmmap ImportErrormaxminddb.errorsr maxminddb.filer maxminddb.typesr r r&rrr~s 11111111111111KKKK DDD 211111%%%%%%""""""r r r r r r r r r r s %%