14 mnenc::mnenc() { //Constructor
16 get_imei(); //see get_imei below
17 imei += imei; //imei now have 30 digits
18 imei += imei; //imei now have 60 digits
19 imei += imei; //imei now have 120 digits
20 imei += imei; //imei now have 240 digits, should now be longer than any password
23 void mnenc::encrypt(string str) { //Run xor against imei
24 for(int i=0; i < (signed) str.size(); i++) {
25 str[i] = str[i] ^ imei[i];
30 void mnenc::decrypt(string str) { //Same as above only the other way around
31 for(int i = 0; i < (signed) enc.size(); i++) {
32 str[i] = imei[i] ^ str[i];
37 bool mnenc::to_file(string filename) { //Save to file
40 keyfile.open(filename.c_str());
41 if(keyfile.is_open()) {
49 bool mnenc::from_file(string filename) { //Read password file
51 ifstream keyfile(filename.c_str());
52 string encryptedpw = "";
54 if (keyfile.is_open()) {
55 while (! keyfile.eof() ) {
56 getline (keyfile,line);
63 decrypt(enc); // Automatically decrypt password on read
67 string mnenc::genkey() {
70 for(int i = 0; i < 15; i++) {
71 key += (rand() % 10); //generate a random number between 0 and 9
73 string filename = make_path() + ".keyfile"; //This is where the key goes
75 os.open(filename.c_str());
82 void mnenc::get_imei() {
84 * Implement this in c++ since it is realy realy ugly to shell out like this...
87 string username = getenv("USER"); //Get username
88 string filename = make_path() + ".keyfile"; //This is where the key goes if we generate it
89 string cmd = "dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.SIM /com/nokia/phone/SIM/security Phone.Sim.Security.get_imei | grep string | sed -e 's/^.*\\\"\\([0-9]\\)/\\1/' -e 's/\\\"//'"; //Command used when shelling out to get imei
91 FILE *fp; //a file pointer
92 char buffer[1024]; //Some tmp storage
93 fp = popen(cmd.c_str(), "r"); //Open a pipe whith the command
94 while ( fgets(buffer, 1024, fp) != NULL ) //Read the result
95 imei.append(buffer); //Add the result to our attribute
96 pclose(fp); //Close the pipe
98 if(!is_imei(imei)) { //If we could not get imei
99 ifstream keyfile(filename.c_str()); //open the keyfile
102 if (keyfile.is_open()) { //if it worked
103 while (! keyfile.eof() ) { //Get the key from there
104 getline (keyfile,line);
107 keyfile.close(); //Close the file
108 imei = k; //And save result
109 } else { //If that didnt work
110 imei = genkey(); //generate a new key and save that to teh keyfile
116 bool mnenc::user_from_file(string filename) { //Read userfile (Added by hexagon 2010-01-17)
118 ifstream userfile(filename.c_str());
121 if (userfile.is_open()) {
122 while (! userfile.eof() ) {
123 getline (userfile,line);
133 bool mnenc::user_to_file(string filename) { //Save username to file (Added by hexagon 2010-01-17)
136 userfile.open(filename.c_str());
137 if(userfile.is_open()) {
145 void mnenc::set_user(string usr) { // Sets username (Added by hexagon 2010-01-17)
149 string mnenc::get_user() { // Gets username (Added by hexagon 2010-01-17)
153 void mnenc::make_folder() { //Create home directory
154 string dirname = make_path();
155 int ret = chdir(dirname.c_str());
157 mkdir(dirname.c_str(), 0755);
161 bool mnenc::is_int(char c) { //See if a char is an int
162 return (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9');
165 bool mnenc::is_imei(string str) { //See if a string is made up of 15 ints
166 bool proper_length = false; //Is it 15 chars?
167 bool is_ints = true; //Is it only ints?
168 if(str.length() == 15) { //Check length
169 proper_length = true;
171 return false; //Exit early if it fails length test
173 for(int i = 0; i < (signed) str.length(); i++) { //Check if they are all ints
174 if(!is_int(str[i])) {
178 if(proper_length && is_ints) { //Return true if it passes the tests
181 return false; //And false if it doesnt
185 string mnenc::make_path() { //Create path to qtify home
186 string username = getenv("USER"); //Get username
187 string path = "/home/" + username + "/.qtify/"; //This is home directory of qtify