-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject.cpp
More file actions
49 lines (47 loc) · 1.14 KB
/
inject.cpp
File metadata and controls
49 lines (47 loc) · 1.14 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
int main(int argc, char *argv[]) {
if (argc == 1 || argv[1] == "--help") {
std::cout << "INJECT \n\n" << "Usage: inject [File] [Line Number] [Content] \n";
return -3; // Help Command
}
else if (argc < 4) {
std::cout << "Invalid, Not Enough Arguments; Run --help For More Info. \n";
return -2; // Not Enough Args
}
std::ifstream file(argv[1]);
std::string* pHemp = new std::string("temp_");
*pHemp+=argv[1];
const char* THEMP = (*pHemp).c_str();
delete pHemp;
std::ofstream tfile(THEMP);
long num = std::stoi(argv[2]);
std::string line;
long li = 0;
bool numEx = false;
while (std::getline(file, line)) {
if (li == num) {
for (short i=3;i<argc;i++) { tfile << argv[i]; } tfile << " \n"; numEx=1;
}
else {
tfile << line; tfile << " \n";
}
li++;
}
if (!numEx) {
if(li<1) { tfile << " \n"; }
for (short j=3;j<argc;j++) {
tfile << argv[j];
}
tfile << " \n";
}
if (file.good()) {
std::remove(argv[1]);
}
file.close();
tfile.close();
std::rename(THEMP, argv[1]);
return 0;
}