Repository navigation
Expand file tree
/
Copy pathinjectCX.cpp
More file actions
60 lines (59 loc) · 1.62 KB
/
Copy pathinjectCX.cpp
File metadata and controls
60 lines (59 loc) · 1.62 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
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdio>
int main(int argc, char *argv[]) {
if (argc == 2 || 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];
char* THEMP = new char[(*pHemp).size()+1];
strcpy(THEMP, (*pHemp).c_str());
delete pHemp;
// std::ofstream tfile(THEMP);
std::string tfile;
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();
std::ofstream ofile(argv[1]);
if (ofile.is_open()) {
ofile << tfile;
}
else {
std::cerr << "Error Opening File For Output. \n";
}
ofile.close();
// tfile.close();
// std::rename(THEMP, argv[1]);
delete[] THEMP;
return 0;
}