// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/src/patch/Zipper.cpp
// Function: UnZipper_searchApkV2Sign
bool UnZipper_searchApkV2Sign(const hpatch_TStreamInput* stream,hpatch_StreamPos_t centralDirectory_pos,
                              ZipFilePos_t* v2sign_topPos,ZipFilePos_t* out_blockSize,bool* out_isHaveV3Sign){
    *v2sign_topPos=(ZipFilePos_t)centralDirectory_pos; //default not found
    if (out_blockSize) *out_blockSize=0;
    //nodePos_begin=v2sign_topPos-8;
    //sumNodeSize=blockSize-8-APKSigningTagLen;
    
    //tag
    const size_t APKSigningTagLen=16;
    const char* APKSigningTag="APK Sig Block 42";
    if (APKSigningTagLen>centralDirectory_pos) return true; //not found
    ZipFilePos_t APKSigningBlockTagPos=(ZipFilePos_t)centralDirectory_pos-APKSigningTagLen;
    TByte buf[APKSigningTagLen];
    check(stream->read(stream,APKSigningBlockTagPos,buf,buf+APKSigningTagLen));
    if (0!=memcmp(buf,APKSigningTag,APKSigningTagLen)) return true;//not found
    //bottom size
    check(8<=APKSigningBlockTagPos);
    ZipFilePos_t blockSizeBottomPos=APKSigningBlockTagPos-8;
    check(stream->read(stream,blockSizeBottomPos,buf,buf+8));
    hpatch_StreamPos_t blockSize=readUInt64(buf);
    //top
    check(blockSize+8<=centralDirectory_pos);
    ZipFilePos_t blockTopSizePos=(ZipFilePos_t)centralDirectory_pos-(ZipFilePos_t)blockSize-8;
    check(stream->read(stream,blockTopSizePos,buf,buf+8));
    check(blockSize==readUInt64(buf)); //check top size
    
    *v2sign_topPos=blockTopSizePos;
    if (out_blockSize) *out_blockSize=(ZipFilePos_t)blockSize;
    if (out_isHaveV3Sign){
        const hpatch_uint32_t kV3SignID=0xf05368c0;
        ZipFilePos_t IDNodePos;
        ZipFilePos_t IDNodeSize;
        if (!_searchID_in_block(stream,blockTopSizePos+8,(ZipFilePos_t)blockSize-8-APKSigningTagLen,
                                kV3SignID,&IDNodePos,&IDNodeSize)) return false; //error
        *out_isHaveV3Sign=(IDNodeSize>0);
    }
    return true;//found
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r15
movl %r14d, (%rdx)
testq %rcx, %rcx
je 0x36933
andl $0x0, (%r12)
cmpq $0x10, %r14
jb 0x36a97
movq %r8, 0x20(%rsp)
leal -0x10(%r14), %ebp
leaq 0x20(%rsp), %rcx
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq *0x10(%r15)
testl %eax, %eax
je 0x36b43
movdqa 0x10(%rsp), %xmm0
pcmpeqb 0x1e9f0(%rip), %xmm0    # 0x55360
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x36a97
cmpl $0x7, %ebp
jbe 0x36b62
leal -0x18(%r14), %esi
leaq 0x18(%rsp), %rbx
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rcx
callq *0x10(%r15)
testl %eax, %eax
je 0x36b81
movq %rbx, %rcx
movq 0x10(%rsp), %rbx
leaq 0x8(%rbx), %rax
cmpq %r14, %rax
ja 0x36ba0
subl %ebx, %r14d
leal -0x8(%r14), %ebp
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq *0x10(%r15)
testl %eax, %eax
je 0x36bbf
cmpq 0x10(%rsp), %rbx
jne 0x36bde
movl %ebp, (%r13)
testq %r12, %r12
je 0x369f3
movl %ebx, (%r12)
cmpq $0x0, 0x20(%rsp)
je 0x36a97
addl $-0x18, %ebx
leaq 0xc(%rsp), %r13
leaq 0x8(%rsp), %rbp
testl %ebx, %ebx
je 0x36a86
cmpl $0xb, %ebx
jbe 0x36aa8
movl %r14d, %esi
movq %r15, %rdi
movq %rbp, %rdx
leaq 0x10(%rsp), %rcx
callq *0x10(%r15)
testl %eax, %eax
je 0x36ae6
movq 0x8(%rsp), %r12
cmpq $0x3, %r12
jbe 0x36ac7
leaq 0x8(%r12), %rax
movl %ebx, %ecx
cmpq %rcx, %rax
ja 0x36b05
leal 0x8(%r14), %esi
movq %r15, %rdi
movq %rbp, %rdx
movq %r13, %rcx
callq *0x10(%r15)
testl %eax, %eax
je 0x36b24
cmpl $0xf05368c0, 0x8(%rsp)  # imm = 0xF05368C0
je 0x36a8a
movl %r12d, %eax
addl $0x8, %eax
addl %r12d, %r14d
addl $0x8, %r14d
subl %eax, %ebx
jmp 0x36a0c
xorl %eax, %eax
jmp 0x36a90
testl %r12d, %r12d
setne %al
movq 0x20(%rsp), %rcx
movb %al, (%rcx)
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x185a1(%rip), %rdi     # 0x4f050
leaq 0x1e8cb(%rip), %rsi     # 0x55381
leaq 0x1f279(%rip), %rcx     # 0x55d36
movl $0x93, %edx
callq 0x4230
leaq 0x18582(%rip), %rdi     # 0x4f050
leaq 0x1e8ac(%rip), %rsi     # 0x55381
leaq 0x1f25a(%rip), %rcx     # 0x55d36
movl $0x96, %edx
callq 0x4230
leaq 0x18563(%rip), %rdi     # 0x4f050
leaq 0x1e88d(%rip), %rsi     # 0x55381
leaq 0x1f23b(%rip), %rcx     # 0x55d36
movl $0x94, %edx
callq 0x4230
leaq 0x18544(%rip), %rdi     # 0x4f050
leaq 0x1e86e(%rip), %rsi     # 0x55381
leaq 0x1f21c(%rip), %rcx     # 0x55d36
movl $0x97, %edx
callq 0x4230
leaq 0x18525(%rip), %rdi     # 0x4f050
leaq 0x1e84f(%rip), %rsi     # 0x55381
leaq 0x1f1fd(%rip), %rcx     # 0x55d36
movl $0x98, %edx
callq 0x4230
leaq 0x18506(%rip), %rdi     # 0x4f050
leaq 0x1e830(%rip), %rsi     # 0x55381
leaq 0x1e83e(%rip), %rcx     # 0x55396
movl $0xb3, %edx
callq 0x4230
leaq 0x184e7(%rip), %rdi     # 0x4f050
leaq 0x1e811(%rip), %rsi     # 0x55381
leaq 0x1e81f(%rip), %rcx     # 0x55396
movl $0xb6, %edx
callq 0x4230
leaq 0x184c8(%rip), %rdi     # 0x4f050
leaq 0x1e7f2(%rip), %rsi     # 0x55381
leaq 0x1e800(%rip), %rcx     # 0x55396
movl $0xb8, %edx
callq 0x4230
leaq 0x184a9(%rip), %rdi     # 0x4f050
leaq 0x1e7d3(%rip), %rsi     # 0x55381
leaq 0x1e7e1(%rip), %rcx     # 0x55396
movl $0xbb, %edx
callq 0x4230
leaq 0x1848a(%rip), %rdi     # 0x4f050
leaq 0x1e7b4(%rip), %rsi     # 0x55381
leaq 0x1e7c2(%rip), %rcx     # 0x55396
movl $0xbd, %edx
callq 0x4230
leaq 0x1846b(%rip), %rdi     # 0x4f050
leaq 0x1e795(%rip), %rsi     # 0x55381
leaq 0x1e7a3(%rip), %rcx     # 0x55396
movl $0xbe, %edx
callq 0x4230