// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rdi, %r14
movl %r15d, (%rdx)
testq %rcx, %rcx
je 0x3f702
movl $0x0, (%r12)
cmpq $0x10, %r15
jb 0x3f877
movq %r8, 0x20(%rsp)
leal -0x10(%r15), %ebp
leaq 0x20(%rsp), %rcx
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movq %rbp, %rsi
callq *0x10(%r14)
testl %eax, %eax
je 0x3f923
movdqa 0x10(%rsp), %xmm0
pcmpeqb 0x20b01(%rip), %xmm0    # 0x60240
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x3f877
cmpl $0x7, %ebp
jbe 0x3f942
leal -0x18(%r15), %esi
leaq 0x18(%rsp), %rbx
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq *0x10(%r14)
testl %eax, %eax
je 0x3f961
movq %rbx, %rcx
movq 0x10(%rsp), %rbx
leaq 0x8(%rbx), %rax
cmpq %r15, %rax
ja 0x3f980
subl %ebx, %r15d
leal -0x8(%r15), %ebp
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movq %rbp, %rsi
callq *0x10(%r14)
testl %eax, %eax
je 0x3f99f
cmpq 0x10(%rsp), %rbx
jne 0x3f9be
movl %ebp, (%r13)
testq %r12, %r12
je 0x3f7c2
movl %ebx, (%r12)
cmpq $0x0, 0x20(%rsp)
je 0x3f877
leal -0x18(%rbx), %r12d
leaq 0x8(%rsp), %rbp
xorl %ebx, %ebx
testl %r12d, %r12d
je 0x3f86d
cmpl $0xb, %r12d
jbe 0x3f888
movl %r15d, %esi
movq %r14, %rdi
movq %rbp, %rdx
leaq 0x10(%rsp), %rcx
callq *0x10(%r14)
testl %eax, %eax
je 0x3f8e5
movq 0x8(%rsp), %r13
cmpq $0x3, %r13
jbe 0x3f8c6
leaq 0x8(%r13), %rax
movl %r12d, %ecx
cmpq %rcx, %rax
ja 0x3f8a7
leal 0x8(%r15), %esi
movq %r14, %rdi
movq %rbp, %rdx
leaq 0xc(%rsp), %rcx
callq *0x10(%r14)
testl %eax, %eax
je 0x3f904
movl 0x8(%rsp), %eax
leal 0x8(%r13), %ecx
cmpl $0xf05368c0, %eax       # imm = 0xF05368C0
movl $0x0, %edx
cmovel %edx, %ecx
subl %ecx, %r12d
addl %r15d, %ecx
movl %ecx, %r15d
cmpl $0xf05368c0, %eax       # imm = 0xF05368C0
cmovel %r13d, %ebx
jne 0x3f7d9
testl %ebx, %ebx
movq 0x20(%rsp), %rax
setne (%rax)
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a7c1(%rip), %rdi     # 0x5a050
leaq 0x209cb(%rip), %rsi     # 0x60261
leaq 0x21379(%rip), %rcx     # 0x60c16
movl $0x93, %edx
callq 0x4200
leaq 0x1a7a2(%rip), %rdi     # 0x5a050
leaq 0x209ac(%rip), %rsi     # 0x60261
leaq 0x2135a(%rip), %rcx     # 0x60c16
movl $0x97, %edx
callq 0x4200
leaq 0x1a783(%rip), %rdi     # 0x5a050
leaq 0x2098d(%rip), %rsi     # 0x60261
leaq 0x2133b(%rip), %rcx     # 0x60c16
movl $0x96, %edx
callq 0x4200
leaq 0x1a764(%rip), %rdi     # 0x5a050
leaq 0x2096e(%rip), %rsi     # 0x60261
leaq 0x2131c(%rip), %rcx     # 0x60c16
movl $0x94, %edx
callq 0x4200
leaq 0x1a745(%rip), %rdi     # 0x5a050
leaq 0x2094f(%rip), %rsi     # 0x60261
leaq 0x212fd(%rip), %rcx     # 0x60c16
movl $0x98, %edx
callq 0x4200
leaq 0x1a726(%rip), %rdi     # 0x5a050
leaq 0x20930(%rip), %rsi     # 0x60261
leaq 0x2093e(%rip), %rcx     # 0x60276
movl $0xb3, %edx
callq 0x4200
leaq 0x1a707(%rip), %rdi     # 0x5a050
leaq 0x20911(%rip), %rsi     # 0x60261
leaq 0x2091f(%rip), %rcx     # 0x60276
movl $0xb6, %edx
callq 0x4200
leaq 0x1a6e8(%rip), %rdi     # 0x5a050
leaq 0x208f2(%rip), %rsi     # 0x60261
leaq 0x20900(%rip), %rcx     # 0x60276
movl $0xb8, %edx
callq 0x4200
leaq 0x1a6c9(%rip), %rdi     # 0x5a050
leaq 0x208d3(%rip), %rsi     # 0x60261
leaq 0x208e1(%rip), %rcx     # 0x60276
movl $0xbb, %edx
callq 0x4200
leaq 0x1a6aa(%rip), %rdi     # 0x5a050
leaq 0x208b4(%rip), %rsi     # 0x60261
leaq 0x208c2(%rip), %rcx     # 0x60276
movl $0xbd, %edx
callq 0x4200
leaq 0x1a68b(%rip), %rdi     # 0x5a050
leaq 0x20895(%rip), %rsi     # 0x60261
leaq 0x208a3(%rip), %rcx     # 0x60276
movl $0xbe, %edx
callq 0x4200