// File: minirop[P]JDecomqiler/src/ClassFile.cpp
// Function: ClassFile::ClassFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
ClassFile::ClassFile(std::string filename)
{
	std::ifstream file(filename, std::ios::in | std::ios::binary);
	if(!file.is_open())
		return;
	
	stream.setStream(&file);
	
	std::uint32_t magic;
	stream >> magic;
	if(magic != 0xcafebabe)
	{
		cout << "magic number is " << std::hex << magic << endl;
		return;
	}
	
	std::uint16_t major, minor;
	stream >> minor >> major;
	cout << "JAVA " << major << "." << minor << endl;
	
	std::uint16_t constant_pool_count;
	stream >> constant_pool_count;
	cout << constant_pool_count << " constants" << endl;
	
	constant_pool.push_back(CPinfo()); // index 0 is invalid
	for(std::size_t i = 1;i < constant_pool_count;i++)
	{
		if(parseConstant()) // return true if double or bigint
		{
			constant_pool.push_back(CPinfo()); // double and bigint use 2 indexes
			i++;
		}
	}
	
	std::uint16_t access_flags, this_class, super_class;
	stream >> access_flags >> this_class >> super_class;
	
	if(access_flags & ACC_PUBLIC)
		output.isPublic = true;
	if(access_flags & ACC_FINAL)
		output.isFinal = true;
	if(access_flags & ACC_SUPER)
		cout << "is super, ignored." << endl;
	if(access_flags & ACC_INTERFACE)
		output.isInterface = true;
	if(access_flags & ACC_ABSTRACT)
		output.isAbstract = true;
	if(access_flags & ACC_ANNOTATION)
		output.isAnnotation = true;
	if(access_flags & ACC_ENUM)
		output.isEnum = true;
	if(access_flags & (~0x0631))
		cout << "ERROR: unrecognized flag(s)" << endl;
	
	output.name = getName(constant_pool[this_class].ClassInfo.name_index);
	output.extends = checkClassName(getName(constant_pool[super_class].ClassInfo.name_index));
	
	std::uint16_t interfaces_count;
	stream >> interfaces_count;
	cout << interfaces_count << " interfaces" << endl;
	for(std::uint16_t i = 0;i < interfaces_count;i++)
	{
		output.interfaces.push_back(parseInterface());
	}
	
	std::uint16_t fields_count;
	stream >> fields_count;
	cout << fields_count << " fields" << endl;
	for(std::uint16_t i = 0;i < fields_count;i++)
	{
		output.fields.push_back(parseField());
	}
	
	std::uint16_t methods_count;
	stream >> methods_count;
	cout << methods_count << " methods" << endl;
	for(std::uint16_t i = 0;i < methods_count;i++)
	{
		output.methods.push_back(parseMethod());
	}
	
	std::uint16_t attributes_count;
	stream >> attributes_count;
	cout << attributes_count << " attributes" << endl;
	for(std::uint16_t i = 0;i < attributes_count;i++)
	{
		parseAttribute();
	}
	
	file.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x590, %rsp            # imm = 0x590
movq %rsi, -0x498(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x480(%rbp)
movq %rdi, %rax
movq %rax, -0x490(%rbp)
callq 0x5630
movq -0x480(%rbp), %rdi
addq $0x90, %rdi
movq %rdi, -0x488(%rbp)
callq 0x56c0
movq -0x480(%rbp), %rdi
addq $0xa8, %rdi
callq 0x38e0
jmp 0x3cd3
movl $0x8, %edi
movl $0x4, %esi
callq 0x56e0
movl %eax, -0x49c(%rbp)
jmp 0x3cea
movl -0x49c(%rbp), %edx
movq -0x498(%rbp), %rsi
leaq -0x228(%rbp), %rdi
callq 0x3470
jmp 0x3d05
leaq -0x228(%rbp), %rdi
callq 0x3460
movb %al, -0x49d(%rbp)
jmp 0x3d19
movb -0x49d(%rbp), %al
testb $0x1, %al
jne 0x3d56
jmp 0x3d25
movl $0x1, -0x22c(%rbp)
jmp 0x461e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x463f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x4633
movq -0x490(%rbp), %rdi
addq $0xa8, %rdi
movq %rdi, -0x4a8(%rbp)
leaq -0x228(%rbp), %rsi
callq 0x38f0
movq -0x4a8(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x3ba0
jmp 0x3d8c
cmpl $0xcafebabe, -0x230(%rbp) # imm = 0xCAFEBABE
je 0x3e0f
movq 0x34231(%rip), %rdi     # 0x37fd0
leaq 0x262be(%rip), %rsi     # 0x2a064
callq 0x32a0
movq %rax, -0x4b0(%rbp)
jmp 0x3db4
movq -0x4b0(%rbp), %rdi
leaq 0x193e(%rip), %rsi      # 0x5700
callq 0x30f0
movq %rax, -0x4b8(%rbp)
jmp 0x3dd0
movq -0x4b8(%rbp), %rdi
movl -0x230(%rbp), %esi
callq 0x33b0
movq %rax, -0x4c0(%rbp)
jmp 0x3deb
movq -0x4c0(%rbp), %rdi
movq 0x341c7(%rip), %rsi     # 0x37fc0
callq 0x32d0
jmp 0x3e00
movl $0x1, -0x22c(%rbp)
jmp 0x461e
movq -0x490(%rbp), %rdi
addq $0xa8, %rdi
leaq -0x234(%rbp), %rsi
callq 0x3b40
movq %rax, -0x4c8(%rbp)
jmp 0x3e32
movq -0x4c8(%rbp), %rdi
leaq -0x232(%rbp), %rsi
callq 0x3b40
jmp 0x3e47
movq 0x34182(%rip), %rdi     # 0x37fd0
leaq 0x26220(%rip), %rsi     # 0x2a075
callq 0x32a0
movq %rax, -0x4d0(%rbp)
jmp 0x3e63
movq -0x4d0(%rbp), %rdi
movzwl -0x232(%rbp), %esi
callq 0x34a0
movq %rax, -0x4d8(%rbp)
jmp 0x3e7f
movq -0x4d8(%rbp), %rdi
leaq 0x2620a(%rip), %rsi     # 0x2a097
callq 0x32a0
movq %rax, -0x4e0(%rbp)
jmp 0x3e9b
movq -0x4e0(%rbp), %rdi
movzwl -0x234(%rbp), %esi
callq 0x34a0
movq %rax, -0x4e8(%rbp)
jmp 0x3eb7
movq -0x4e8(%rbp), %rdi
movq 0x340fb(%rip), %rsi     # 0x37fc0
callq 0x32d0
jmp 0x3ecc
movq -0x490(%rbp), %rdi
addq $0xa8, %rdi
leaq -0x236(%rbp), %rsi
callq 0x3b40
jmp 0x3ee8
movzwl -0x236(%rbp), %esi
movq 0x340da(%rip), %rdi     # 0x37fd0
callq 0x34a0
movq %rax, -0x4f0(%rbp)
jmp 0x3f04
movq -0x4f0(%rbp), %rdi
leaq 0x26169(%rip), %rsi     # 0x2a07b
callq 0x32a0
movq %rax, -0x4f8(%rbp)
jmp 0x3f20
movq -0x4f8(%rbp), %rdi
movq 0x34092(%rip), %rsi     # 0x37fc0
callq 0x32d0
jmp 0x3f35
xorps %xmm0, %xmm0
movaps %xmm0, -0x250(%rbp)
movq $0x0, -0x240(%rbp)
leaq 0x34377(%rip), %rdi     # 0x382c8
leaq -0x250(%rbp), %rsi
callq 0x5730
jmp 0x3f5f
movq $0x1, -0x258(%rbp)
movq -0x258(%rbp), %rax
movzwl -0x236(%rbp), %ecx
cmpq %rcx, %rax
jae 0x3ff2
movq -0x490(%rbp), %rdi
callq 0x4660
movb %al, -0x4f9(%rbp)
jmp 0x3f91
movb -0x4f9(%rbp), %al
testb $0x1, %al
jne 0x3f9d
jmp 0x3fd9
xorps %xmm0, %xmm0
movaps %xmm0, -0x270(%rbp)
movq $0x0, -0x260(%rbp)
leaq 0x3430f(%rip), %rdi     # 0x382c8
leaq -0x270(%rbp), %rsi
callq 0x5730
jmp 0x3fc7
movq -0x258(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x258(%rbp)
jmp 0x3fdb
movq -0x258(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x258(%rbp)
jmp 0x3f6a
movq -0x490(%rbp), %rdi
addq $0xa8, %rdi
leaq -0x272(%rbp), %rsi
callq 0x3b40
movq %rax, -0x508(%rbp)
jmp 0x4015
movq -0x508(%rbp), %rdi
leaq -0x274(%rbp), %rsi
callq 0x3b40
movq %rax, -0x510(%rbp)
jmp 0x4031
movq -0x510(%rbp), %rdi
leaq -0x276(%rbp), %rsi
callq 0x3b40
jmp 0x4046
movzwl -0x272(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4063
movq -0x490(%rbp), %rax
movb $0x1, 0x8b(%rax)
movzwl -0x272(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4080
movq -0x490(%rbp), %rax
movb $0x1, 0x88(%rax)
movzwl -0x272(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x40c2
movq 0x33f3a(%rip), %rdi     # 0x37fd0
leaq 0x25fe9(%rip), %rsi     # 0x2a086
callq 0x32a0
movq %rax, -0x518(%rbp)
jmp 0x40ab
movq -0x518(%rbp), %rdi
movq 0x33f07(%rip), %rsi     # 0x37fc0
callq 0x32d0
jmp 0x40c0
jmp 0x40c2
movzwl -0x272(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x40e1
movq -0x490(%rbp), %rax
movb $0x1, 0x8a(%rax)
movzwl -0x272(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x4100
movq -0x490(%rbp), %rax
movb $0x1, 0x89(%rax)
movzwl -0x272(%rbp), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x411f
movq -0x490(%rbp), %rax
movb $0x1, 0x8c(%rax)
movzwl -0x272(%rbp), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x413e
movq -0x490(%rbp), %rax
movb $0x1, 0x8d(%rax)
movzwl -0x272(%rbp), %eax
andl $0xfffff9ce, %eax       # imm = 0xFFFFF9CE
cmpl $0x0, %eax
je 0x4182
movq 0x33e7a(%rip), %rdi     # 0x37fd0
leaq 0x25f3c(%rip), %rsi     # 0x2a099
callq 0x32a0
movq %rax, -0x520(%rbp)
jmp 0x416b
movq -0x520(%rbp), %rdi
movq 0x33e47(%rip), %rsi     # 0x37fc0
callq 0x32d0
jmp 0x4180
jmp 0x4182
movzwl -0x274(%rbp), %eax
movl %eax, %esi
leaq 0x34136(%rip), %rdi     # 0x382c8
callq 0x5760
movzwl 0x8(%rax), %esi
leaq -0x298(%rbp), %rdi
callq 0x28ed0
jmp 0x41a9
movq -0x490(%rbp), %rdi
leaq -0x298(%rbp), %rsi
movq %rsi, -0x528(%rbp)
callq 0x3350
movq -0x528(%rbp), %rdi
callq 0x31d0
movzwl -0x276(%rbp), %eax
movl %eax, %esi
leaq 0x340e9(%rip), %rdi     # 0x382c8
callq 0x5760
movzwl 0x8(%rax), %esi
leaq -0x2d8(%rbp), %rdi
callq 0x28ed0
jmp 0x41f6
leaq -0x2b8(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x29000
jmp 0x420b
movq -0x490(%rbp), %rdi
addq $0x20, %rdi
leaq -0x2b8(%rbp), %rsi
movq %rsi, -0x530(%rbp)
callq 0x3350
movq -0x530(%rbp), %rdi
callq 0x31d0
leaq -0x2d8(%rbp), %rdi
callq 0x31d0
movq -0x490(%rbp), %rdi
addq $0xa8, %rdi
leaq -0x2da(%rbp), %rsi
callq 0x3b40
jmp 0x425d
movzwl -0x2da(%rbp), %esi
movq 0x33d65(%rip), %rdi     # 0x37fd0
callq 0x34a0
movq %rax, -0x538(%rbp)
jmp 0x4279
movq -0x538(%rbp), %rdi
leaq 0x25e2e(%rip), %rsi     # 0x2a0b5
callq 0x32a0
movq %rax, -0x540(%rbp)
jmp 0x4295
movq -0x540(%rbp), %rdi
movq 0x33d1d(%rip), %rsi     # 0x37fc0
callq 0x32d0
jmp 0x42aa
movw $0x0, -0x2dc(%rbp)
movzwl -0x2dc(%rbp), %eax
movzwl -0x2da(%rbp), %ecx
cmpl %ecx, %eax
jge 0x435b
movq -0x490(%rbp), %rsi
movq %rsi, %rax
addq $0x40, %rax
movq %rax, -0x548(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x49a0
jmp 0x42ec
movq -0x548(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x5780
jmp 0x4301
leaq -0x300(%rbp), %rdi
callq 0x31d0
movw -0x2dc(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x2dc(%rbp)
jmp 0x42b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x31d0
jmp 0x4633
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x31d0
jmp 0x4633
movq -0x490(%rbp), %rdi
addq $0xa8, %rdi
leaq -0x302(%rbp), %rsi
callq 0x3b40
jmp 0x4377
movzwl -0x302(%rbp), %esi
movq 0x33c4b(%rip), %rdi     # 0x37fd0
callq 0x34a0
movq %rax, -0x550(%rbp)
jmp 0x4393
movq -0x550(%rbp), %rdi
leaq 0x25d20(%rip), %rsi     # 0x2a0c1
callq 0x32a0
movq %rax, -0x558(%rbp)
jmp 0x43af
movq -0x558(%rbp), %rdi
movq 0x33c03(%rip), %rsi     # 0x37fc0
callq 0x32d0
jmp 0x43c4
movw $0x0, -0x304(%rbp)
movzwl -0x304(%rbp), %eax
movzwl -0x302(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4454
movq -0x490(%rbp), %rsi
movq %rsi, %rax
addq $0x70, %rax
movq %rax, -0x560(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x4ad0
jmp 0x4402
movq -0x560(%rbp), %rdi
leaq -0x368(%rbp), %rsi
callq 0x57b0
jmp 0x4417
leaq -0x368(%rbp), %rdi
callq 0x57e0
movw -0x304(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x304(%rbp)
jmp 0x43cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x57e0
jmp 0x4633
movq -0x490(%rbp), %rdi
addq $0xa8, %rdi
leaq -0x36a(%rbp), %rsi
callq 0x3b40
jmp 0x4470
movzwl -0x36a(%rbp), %esi
movq 0x33b52(%rip), %rdi     # 0x37fd0
callq 0x34a0
movq %rax, -0x568(%rbp)
jmp 0x448c
movq -0x568(%rbp), %rdi
leaq 0x25c2f(%rip), %rsi     # 0x2a0c9
callq 0x32a0
movq %rax, -0x570(%rbp)
jmp 0x44a8
movq -0x570(%rbp), %rdi
movq 0x33b0a(%rip), %rsi     # 0x37fc0
callq 0x32d0
jmp 0x44bd
movw $0x0, -0x36c(%rbp)
movzwl -0x36c(%rbp), %eax
movzwl -0x36a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x454d
movq -0x490(%rbp), %rsi
movq %rsi, %rax
addq $0x58, %rax
movq %rax, -0x578(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x4ed0
jmp 0x44fb
movq -0x578(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0x5820
jmp 0x4510
leaq -0x430(%rbp), %rdi
callq 0x5850
movw -0x36c(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x36c(%rbp)
jmp 0x44c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x5850
jmp 0x4633
movq -0x490(%rbp), %rdi
addq $0xa8, %rdi
leaq -0x432(%rbp), %rsi
callq 0x3b40
jmp 0x4569
movzwl -0x432(%rbp), %esi
movq 0x33a59(%rip), %rdi     # 0x37fd0
callq 0x34a0
movq %rax, -0x580(%rbp)
jmp 0x4585
movq -0x580(%rbp), %rdi
leaq 0x25b3f(%rip), %rsi     # 0x2a0d2
callq 0x32a0
movq %rax, -0x588(%rbp)
jmp 0x45a1
movq -0x588(%rbp), %rdi
movq 0x33a11(%rip), %rsi     # 0x37fc0
callq 0x32d0
jmp 0x45b6
movw $0x0, -0x434(%rbp)
movzwl -0x434(%rbp), %eax
movzwl -0x432(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4606
movq -0x490(%rbp), %rsi
leaq -0x478(%rbp), %rdi
callq 0x52a0
jmp 0x45e6
leaq -0x478(%rbp), %rdi
callq 0x58c0
movw -0x434(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x434(%rbp)
jmp 0x45bf
leaq -0x228(%rbp), %rdi
callq 0x3090
jmp 0x4614
movl $0x0, -0x22c(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x30c0
addq $0x590, %rsp            # imm = 0x590
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x30c0
movq -0x488(%rbp), %rdi
callq 0x58e0
movq -0x480(%rbp), %rdi
callq 0x5940
movq -0x18(%rbp), %rdi
callq 0x34e0