所以这就是程序应该做的事情:通过键入限制来限制应用程序在 Mac 上打开。它应该允许通过使用与以前相同的名称再次键入restrict 来访问应用程序。
程序正在做什么:限制应用程序工作正常。但是当我再次输入限制时,它会出现以下输出:
CandyBar
\277_\377CandyBar
\277_\377Restricting application
chmod: /Applications/CandyBar
\277_\377.app: No such file or directory
chown: /Applications/CandyBar
\277_\377.app: No such file or directory
chmod: /Applications/CandyBar
\277_\377.app: No such file or directory
如您所见,它将字符添加到\277_\377
字符串的末尾。这是我的源代码:
for (int i = 0; strlen(argument) + 14 >= i; i++) {
argument[i] = '\0';
}
cout << argument;
getArguments();
argument[strlen(argument) - 1] = '\0';
cout << argument;
string application(argument);
cout << application;
if (!restrictedApplication[application]) {
restrictedApplication[application] = false;
}
if (restrictedApplication[application] == false) {
cout << "Restricting application\n";
restrictedApplication[application] = true;
string fullCommand =
"chmod -x '/Applications/" + application + ".app';" +
"chown root '/Applications/" + application + ".app';" +
"chmod 000 '/Applications/" + application + ".app'";
char fullCommandChar[256];
for (int i = 0; fullCommand[i] != '\0'; i++) {
fullCommandChar[i] = fullCommand[i];
}
system(fullCommandChar);
}
else {
cout << "Restoring application\n";
restrictedApplication[application] = false;
string fullCommand =
"chmod +x '/Applications/" + application + ".app';" +
"chown jamespickering '/Applications/" + application + ".app';" +
"chmod 777 '/Applications/" + application + ".app'";
char fullCommandChar[256];
for (int i = 0; fullCommand[i] != '\0'; i++) {
fullCommandChar[i] = fullCommand[i];
}
system(fullCommandChar);
}