// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0xa0(%rbp)
movq %rsi, -0x98(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
callq 0x2040
cmpl $0x0, %eax
jne 0x2724
movb $0x1, -0x1(%rbp)
jmp 0x28e4
movq -0xa0(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x20a0
leaq -0x40(%rbp), %rdi
callq 0x26a0
movq %rax, -0xb0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x20e0
movq -0xb0(%rbp), %rax
movq -0x98(%rbp), %rsi
movq %rax, -0x20(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x20a0
leaq -0x68(%rbp), %rdi
callq 0x26a0
movq %rax, -0xa8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x20e0
movq -0xa8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x279f
movb $0x0, -0x1(%rbp)
jmp 0x28e4
cmpq $0x0, -0x20(%rbp)
je 0x27ad
cmpq $0x0, -0x48(%rbp)
jne 0x27b6
movb $0x0, -0x1(%rbp)
jmp 0x28e4
movq -0xa0(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
leaq 0x3853(%rip), %rsi      # 0x601f
callq 0x2210
movq -0x98(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0x2090
movq %rax, %rdi
leaq 0x3834(%rip), %rsi      # 0x601f
callq 0x2210
movq %rax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x28b5
cmpq $0x0, -0x78(%rbp)
je 0x28b5
movl $0x0, -0x80(%rbp)
cmpl $0x900, -0x80(%rbp)     # imm = 0x900
jge 0x28b3
movq -0x70(%rbp), %rdi
movslq -0x80(%rbp), %rsi
xorl %edx, %edx
callq 0x21f0
movq -0x78(%rbp), %rdi
movslq -0x80(%rbp), %rsi
xorl %edx, %edx
callq 0x21f0
movl $0x0, -0x84(%rbp)
cmpl $0x100, -0x84(%rbp)     # imm = 0x100
jge 0x28a1
movq -0x70(%rbp), %rdi
callq 0x22c0
movl %eax, -0x88(%rbp)
movq -0x78(%rbp), %rdi
callq 0x22c0
movl %eax, -0x8c(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x8c(%rbp), %eax
je 0x288e
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x2890
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x284d
jmp 0x28a3
movl -0x80(%rbp), %eax
addl $0x800, %eax            # imm = 0x800
movl %eax, -0x80(%rbp)
jmp 0x2818
jmp 0x28b5
cmpq $0x0, -0x70(%rbp)
je 0x28c5
movq -0x70(%rbp), %rdi
callq 0x2190
cmpq $0x0, -0x78(%rbp)
je 0x28d5
movq -0x78(%rbp), %rdi
callq 0x2190
movl -0x7c(%rbp), %ecx
xorl %eax, %eax
subl $0x1, %ecx
sbbl %eax, %eax
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)