// File: tdv[P]boss/boss/src/regtool/main.cpp
// Function: main
int main(int argc, char const **argv)
{
  try
  {
    if (argc < 2)
    {
      ShowHelp();
      return -1;
    }
    
    if (argc == 2 && !std::strcmp(argv[1], "-help"))
    {
      ShowHelp();
      return 0;
    }
    
    if (argc != 4)
    {
      std::cout << "Bad params." << std::endl;
      return -1;
    }
    
    std::string RegistryFilePath = argv[2];

    auto Reg = Boss::Base<Boss::ServiceRegistry>::Create();
    Boss::RefObjQIPtr<Boss::IServiceRegistryCtrl> Ctrl(Reg);    
    if (!Ctrl.Get())
      throw std::runtime_error("Failed to get RegCtrl.");
    Boss::RefObjQIPtr<Boss::ISerializable> Serializable(Ctrl);
    if (!Serializable.Get())
      throw std::runtime_error("Failed to get ISerializable interface from Registry object.");
    
    if (!std::strcmp(argv[1], "-reg"))
    {
      std::string ModulePath = argv[3];
      
      try
      {
        Load(Serializable, RegistryFilePath);
      }
      catch (std::exception const &)
      {
      }

      auto Info = Boss::Base<Boss::LocalServiceInfo>::Create();
      {
        auto Module = Boss::ModuleHolder(std::move(Boss::DllHolder(ModulePath)));
        
        Info->SetModulePath(ModulePath);
        Info->SetServiceId(Module.GetServiceId());
        
        for (auto const &i : Module.GetClassIds())
          Info->AddCoClassId(i);
        
        if (Ctrl->AddService(Info.Get()) != Boss::Status::Ok)
        {
          std::cout << "Failed to reg service." << std::endl;
          return -1;
        }
        
        Save(Serializable, RegistryFilePath);
      }
      return 0;
    }
    if (!std::strcmp(argv[1], "-unreg"))
    {
      std::string ServiceName = argv[3];
      
      Load(Serializable, RegistryFilePath);
      
      if (Ctrl->DelService(Boss::Crc32(ServiceName.c_str(), ServiceName.length())) != Boss::Status::Ok)
      {
        std::cout << "Failed to reg service." << std::endl;
        return -1;
      }
      
      Save(Serializable, RegistryFilePath);

      return 0;
    }
    
    std::cout << "Bad params." << std::endl;
    return -1;
    
  }
  catch (std::exception const &e)
  {
    std::cout << e.what() << std::endl;
  }
  return 0;
}

// Assembly:
subq $0x228, %rsp            # imm = 0x228
movl $0x0, 0x224(%rsp)
movl %edi, 0x220(%rsp)
movq %rsi, 0x218(%rsp)
cmpl $0x2, 0x220(%rsp)
jge 0x4055b
callq 0x40290
jmp 0x40532
movl $0xffffffff, 0x224(%rsp) # imm = 0xFFFFFFFF
jmp 0x410dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x4104b
cmpl $0x2, 0x220(%rsp)
jne 0x40599
movq 0x218(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xb7e60(%rip), %rsi     # 0xf83d8
callq 0x1c4f0
cmpl $0x0, %eax
jne 0x40599
callq 0x40290
jmp 0x40589
movl $0x0, 0x224(%rsp)
jmp 0x410dd
cmpl $0x4, 0x220(%rsp)
je 0x405e6
leaq 0x109ed6(%rip), %rdi    # 0x14a480
leaq 0xb7e2d(%rip), %rsi     # 0xf83de
callq 0xb46e0
movq %rax, 0xe8(%rsp)
jmp 0x405c0
movq 0xe8(%rsp), %rdi
leaq 0x739f1(%rip), %rsi     # 0xb3fc0
callq 0xb31d0
jmp 0x405d6
movl $0xffffffff, 0x224(%rsp) # imm = 0xFFFFFFFF
jmp 0x410dd
movq 0x218(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0xd8(%rsp)
leaq 0x1e7(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
callq 0x4a200
movq 0xd8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
leaq 0x1e8(%rsp), %rdi
callq 0xc7340
jmp 0x4062e
leaq 0x1e7(%rsp), %rdi
callq 0x4a220
leaq 0x1d8(%rsp), %rdi
callq 0x41580
jmp 0x4064a
leaq 0x1d0(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0x41670
jmp 0x40661
leaq 0x1d0(%rsp), %rdi
callq 0x416c0
movq %rax, 0xd0(%rsp)
jmp 0x40678
movq 0xd0(%rsp), %rax
cmpq $0x0, %rax
jne 0x40767
movl $0x10, %edi
callq 0x47f80
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0xc8(%rsp)
leaq 0xb7d41(%rip), %rsi     # 0xf83ea
callq 0x5b7e0
jmp 0x406b0
movq 0xc8(%rsp), %rdi
leaq 0x1029b1(%rip), %rsi    # 0x143070
leaq 0x1179a(%rip), %rdx     # 0x51e60
callq 0x48fd0
jmp 0x41101
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x1e7(%rsp), %rdi
callq 0x4a220
jmp 0x4104b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x4103e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x41031
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x41024
movq 0xc8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
callq 0x47fe0
jmp 0x41024
leaq 0x1c8(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x416d0
jmp 0x4077e
leaq 0x1c8(%rsp), %rdi
callq 0x242c0
movq %rax, 0xc0(%rsp)
jmp 0x40795
movq 0xc0(%rsp), %rax
cmpq $0x0, %rax
jne 0x4082c
movl $0x10, %edi
callq 0x47f80
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0xb8(%rsp)
leaq 0xb7c3b(%rip), %rsi     # 0xf8401
callq 0x5b7e0
jmp 0x407cd
movq 0xb8(%rsp), %rdi
leaq 0x102894(%rip), %rsi    # 0x143070
leaq 0x1167d(%rip), %rdx     # 0x51e60
callq 0x48fd0
jmp 0x41101
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x41017
movq 0xb8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
callq 0x47fe0
jmp 0x41017
movq 0x218(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xb7bfe(%rip), %rsi     # 0xf843d
callq 0x1c4f0
cmpl $0x0, %eax
jne 0x40d49
movq 0x218(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0xa8(%rsp)
leaq 0x1a7(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x4a200
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
leaq 0x1a8(%rsp), %rdi
callq 0xc7340
jmp 0x40895
leaq 0x1a7(%rsp), %rdi
callq 0x4a220
leaq 0x198(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x41710
jmp 0x408b9
leaq 0x198(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x402e0
jmp 0x408d0
leaq 0x198(%rsp), %rdi
callq 0x41790
jmp 0x40971
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x1a7(%rsp), %rdi
callq 0x4a220
jmp 0x41017
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x4093f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x41790
movl 0x20c(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x40d37
movq 0x210(%rsp), %rdi
callq 0x480e0
movq %rax, 0x190(%rsp)
callq 0x48150
jmp 0x4096f
jmp 0x40971
leaq 0x188(%rsp), %rdi
callq 0x230a0
jmp 0x40980
leaq 0x178(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x417b0
jmp 0x40997
leaq 0x180(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x418d0
jmp 0x409ae
leaq 0x178(%rsp), %rdi
callq 0x41900
leaq 0x188(%rsp), %rdi
callq 0x23190
movq %rax, 0xa0(%rsp)
jmp 0x409d2
movq 0xa0(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x41920
jmp 0x409e9
leaq 0x188(%rsp), %rdi
callq 0x23190
movq %rax, 0x98(%rsp)
jmp 0x40a00
movq 0x98(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x88(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x41990
movl %eax, 0x94(%rsp)
jmp 0x40a2a
movl 0x94(%rsp), %esi
movq 0x88(%rsp), %rdi
callq 0x231a0
jmp 0x40a40
leaq 0x158(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x41ac0
jmp 0x40a57
leaq 0x158(%rsp), %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rdi
callq 0x41e20
movq %rax, 0x150(%rsp)
movq 0x170(%rsp), %rdi
callq 0x41e50
movq %rax, 0x148(%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x41e80
testb $0x1, %al
jne 0x40b31
leaq 0x158(%rsp), %rdi
callq 0x22bc0
jmp 0x40bb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x40d37
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x40d2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x41900
jmp 0x40d2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x40cfc
leaq 0x150(%rsp), %rdi
callq 0x41ec0
movq %rax, 0x140(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x23190
movq %rax, 0x80(%rsp)
jmp 0x40b5d
movq 0x80(%rsp), %rdi
addq $0x8, %rdi
movq 0x140(%rsp), %rax
movl (%rax), %esi
callq 0x41ed0
jmp 0x40b7a
jmp 0x40b7c
leaq 0x150(%rsp), %rdi
callq 0x41fb0
jmp 0x40a91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x22bc0
jmp 0x40cfc
leaq 0x1d0(%rsp), %rdi
callq 0x41fd0
movq %rax, 0x78(%rsp)
jmp 0x40bc8
leaq 0x188(%rsp), %rdi
callq 0x3cac0
movq %rax, 0x70(%rsp)
jmp 0x40bdc
movq 0x70(%rsp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, 0x68(%rsp)
je 0x40bfc
movq 0x70(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x68(%rsp)
movq 0x78(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq (%rdi), %rax
movq 0x28(%rax), %rax
callq *%rax
movl %eax, 0x64(%rsp)
jmp 0x40c15
movl 0x64(%rsp), %eax
cmpl $0x0, %eax
je 0x40c63
leaq 0x10985b(%rip), %rdi    # 0x14a480
leaq 0xb7816(%rip), %rsi     # 0xf8442
callq 0xb46e0
movq %rax, 0x58(%rsp)
jmp 0x40c38
movq 0x58(%rsp), %rdi
leaq 0x7337c(%rip), %rsi     # 0xb3fc0
callq 0xb31d0
jmp 0x40c4b
movl $0xffffffff, 0x224(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x13c(%rsp)
jmp 0x40ca9
leaq 0x130(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x41710
jmp 0x40c7a
leaq 0x130(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x403f0
jmp 0x40c91
leaq 0x130(%rsp), %rdi
callq 0x41790
movl $0x0, 0x13c(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x41fe0
movl 0x13c(%rsp), %eax
testl %eax, %eax
jne 0x40d0b
jmp 0x40cc3
movl $0x0, 0x224(%rsp)
movl $0x1, 0x13c(%rsp)
jmp 0x40d0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x41790
leaq 0x180(%rsp), %rdi
callq 0x41fe0
jmp 0x40d2a
leaq 0x188(%rsp), %rdi
callq 0x23520
leaq 0x1a8(%rsp), %rdi
callq 0xc49c0
jmp 0x40fde
leaq 0x188(%rsp), %rdi
callq 0x23520
leaq 0x1a8(%rsp), %rdi
callq 0xc49c0
jmp 0x41017
movq 0x218(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xb76fd(%rip), %rsi     # 0xf8459
callq 0x1c4f0
cmpl $0x0, %eax
jne 0x40f9b
movq 0x218(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x48(%rsp)
leaq 0x10f(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x4a200
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0x110(%rsp), %rdi
callq 0xc7340
jmp 0x40da6
leaq 0x10f(%rsp), %rdi
callq 0x4a220
leaq 0x100(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x41710
jmp 0x40dca
leaq 0x100(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x402e0
jmp 0x40de1
leaq 0x100(%rsp), %rdi
callq 0x41790
leaq 0x1d0(%rsp), %rdi
callq 0x41fd0
movq %rax, 0x40(%rsp)
jmp 0x40e02
leaq 0x110(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xc6400
movq 0x28(%rsp), %rdi
movq %rax, 0x30(%rsp)
callq 0xc4bf0
movq 0x30(%rsp), %rdi
movl %eax, %esi
callq 0x41ff0
movl %eax, 0x3c(%rsp)
jmp 0x40e35
movl 0x3c(%rsp), %esi
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movl %eax, 0x24(%rsp)
jmp 0x40e4d
movl 0x24(%rsp), %eax
cmpl $0x0, %eax
je 0x40f07
leaq 0x10961f(%rip), %rdi    # 0x14a480
leaq 0xb75da(%rip), %rsi     # 0xf8442
callq 0xb46e0
movq %rax, 0x18(%rsp)
jmp 0x40e74
movq 0x18(%rsp), %rdi
leaq 0x73140(%rip), %rsi     # 0xb3fc0
callq 0xb31d0
jmp 0x40e87
movl $0xffffffff, 0x224(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x13c(%rsp)
jmp 0x40f7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x10f(%rsp), %rdi
callq 0x4a220
jmp 0x41017
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x40f8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x41790
jmp 0x40f8c
leaq 0xf8(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x41710
jmp 0x40f1e
leaq 0xf8(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x403f0
jmp 0x40f35
leaq 0xf8(%rsp), %rdi
callq 0x41790
movl $0x0, 0x224(%rsp)
movl $0x1, 0x13c(%rsp)
jmp 0x40f7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x41790
jmp 0x40f8c
leaq 0x110(%rsp), %rdi
callq 0xc49c0
jmp 0x40fde
leaq 0x110(%rsp), %rdi
callq 0xc49c0
jmp 0x41017
leaq 0x1094de(%rip), %rdi    # 0x14a480
leaq 0xb7435(%rip), %rsi     # 0xf83de
callq 0xb46e0
movq %rax, 0x10(%rsp)
jmp 0x40fb5
movq 0x10(%rsp), %rdi
leaq 0x72fff(%rip), %rsi     # 0xb3fc0
callq 0xb31d0
jmp 0x40fc8
movl $0xffffffff, 0x224(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x13c(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x242e0
leaq 0x1d0(%rsp), %rdi
callq 0x42070
leaq 0x1d8(%rsp), %rdi
callq 0x42090
leaq 0x1e8(%rsp), %rdi
callq 0xc49c0
jmp 0x410dd
leaq 0x1c8(%rsp), %rdi
callq 0x242e0
leaq 0x1d0(%rsp), %rdi
callq 0x42070
leaq 0x1d8(%rsp), %rdi
callq 0x42090
leaq 0x1e8(%rsp), %rdi
callq 0xc49c0
movl 0x20c(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x410ec
movq 0x210(%rsp), %rdi
callq 0x480e0
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, %rsi
leaq 0x1093f1(%rip), %rdi    # 0x14a480
callq 0xb46e0
movq %rax, 0x8(%rsp)
jmp 0x4109b
movq 0x8(%rsp), %rdi
leaq 0x72f19(%rip), %rsi     # 0xb3fc0
callq 0xb31d0
jmp 0x410ae
callq 0x48150
movl $0x0, 0x224(%rsp)
jmp 0x410dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
callq 0x48150
jmp 0x410db
jmp 0x410ec
movl 0x224(%rsp), %eax
addq $0x228, %rsp            # imm = 0x228
retq
movq 0x210(%rsp), %rdi
callq 0xf31f0
movq %rax, %rdi
callq 0x24a50
nopw %cs:(%rax,%rax)