// File: /workspace/github_cpp_makefile_star2_O1/BleuLlama[P]msf-tools/DiskUtils.cpp
// Function: DiskUtils::IsSimilarFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool DiskUtils::IsSimilarFile( std::string _pathA, std::string _pathB )
{
	// just in case we're stupid, make sure the paths aren't
	// exact, if so, short circuit out quick.
	// (quick check for alike files)
	if( _pathA.compare( _pathB ) == 0 ) return true;

	// 1. check filesizes. (quick check for non-differing files)
	long sizeA = DiskUtils::FileSize( _pathA );
	long sizeB = DiskUtils::FileSize( _pathB );

	// file sizes are different.  just bail out.
	if( sizeA != sizeB ) return false;	// both are different-sized

	if( sizeA == 0 || sizeB == 0 ) return false;	// one or the other couldn't be opened.

	// 2. check a few bytes to see if they're the same
	FILE * fpA = fopen( _pathA.c_str(), "rb" );
	FILE * fpB = fopen( _pathB.c_str(), "rb" );

	int differences = 0;

	if( fpA && fpB ) {
		// check at 0x0000 and again at 0x800 for different bytes
		for( int offs = 0 ; offs < 0x900 ; offs += 0x800 )
		{
			// go to 0x0000 or 0x800
			fseek( fpA, offs, SEEK_SET );
			fseek( fpB, offs, SEEK_SET );

			for( int addr=0 ; addr < 0x100  ; addr++ ) 
			{
				int dA = fgetc( fpA );
				int dB = fgetc( fpB );

				if( dA != dB ) differences++;
			}
		}
	}

	if( fpA ) fclose( fpA );
	if( fpB ) fclose( fpB );

	return (differences == 0) ? true : false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x2050
testl %eax, %eax
je 0x2578
leaq 0x38(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x2c9a
movq (%r15), %rdi
leaq 0x48(%rsp), %rsi
callq 0x20e0
testl %eax, %eax
jne 0x2580
movq 0x78(%rsp), %r12
jmp 0x2583
movb $0x1, %bpl
jmp 0x26b6
xorl %r12d, %r12d
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x259a
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2110
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x2c9a
movq (%r15), %rdi
leaq 0x48(%rsp), %rsi
callq 0x20e0
testl %eax, %eax
jne 0x25d2
movq 0x78(%rsp), %r15
jmp 0x25d5
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x25ec
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2110
xorl %ebp, %ebp
cmpq %r15, %r12
jne 0x26b6
testq %r12, %r12
je 0x26b6
testq %r15, %r15
je 0x26b6
movq (%r14), %rdi
leaq 0x2a0c(%rip), %r15      # 0x501f
movq %r15, %rsi
callq 0x2140
movq %rax, %r14
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x2140
movq %rax, %rbx
testq %r14, %r14
sete %al
testq %rbx, %rbx
sete %cl
movb $0x1, %bpl
orb %al, %cl
jne 0x269c
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2120
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2120
movl $0x100, %r13d           # imm = 0x100
movq %r14, %rdi
callq 0x21d0
movl %eax, %ebp
movq %rbx, %rdi
callq 0x21d0
xorl %ecx, %ecx
cmpl %eax, %ebp
setne %cl
addl %ecx, %r12d
decl %r13d
jne 0x2665
leaq 0x800(%r15), %rax
testq %r15, %r15
movq %rax, %r15
je 0x2645
testl %r12d, %r12d
sete %bpl
testq %r14, %r14
je 0x26a9
movq %r14, %rdi
callq 0x2100
testq %rbx, %rbx
je 0x26b6
movq %rbx, %rdi
callq 0x2100
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq