|
| 1 | +#include <iostream> |
| 2 | +#include <fstream> |
| 3 | +#include <unistd.h> |
| 4 | + |
| 5 | +#include<netdb.h> |
| 6 | +#include<arpa/inet.h> |
| 7 | + |
| 8 | +int main(int argc, char **argv) |
| 9 | +{ |
| 10 | + std::string fileName = "/sdcard/Android/data/com.innersloth.spacemafia/files/regionInfo.dat"; |
| 11 | + std::string serverAddress = "localhost"; |
| 12 | + uint16_t port = 22023; |
| 13 | + std::ofstream file; |
| 14 | + int option = -1; |
| 15 | + uint32_t zero32 = 0; |
| 16 | + uint32_t serverLen = 1; |
| 17 | + uint8_t strLen; |
| 18 | + |
| 19 | + hostent *he = nullptr; |
| 20 | + std::string ipAddress; |
| 21 | + |
| 22 | + do |
| 23 | + { |
| 24 | + option = getopt(argc, argv, "s:p:o:"); |
| 25 | + |
| 26 | + switch(option) |
| 27 | + { |
| 28 | + case 's': |
| 29 | + serverAddress = optarg; |
| 30 | + break; |
| 31 | + case 'p': |
| 32 | + port = std::stoi(optarg); |
| 33 | + break; |
| 34 | + case 'o': |
| 35 | + fileName = optarg; |
| 36 | + break; |
| 37 | + } |
| 38 | + } |
| 39 | + while(option != -1); |
| 40 | + |
| 41 | + // Resolving hostname |
| 42 | + he = gethostbyname(serverAddress.c_str()); |
| 43 | + |
| 44 | + if(!he || he->h_addr_list == nullptr) |
| 45 | + { |
| 46 | + std::cerr << "Error resolving the net address " << serverAddress << '\n'; |
| 47 | + return -1; |
| 48 | + } |
| 49 | + |
| 50 | + ipAddress = inet_ntoa(**(in_addr **)he->h_addr_list); |
| 51 | + |
| 52 | + file = std::ofstream(fileName, std::ios::binary); |
| 53 | + if(!file) |
| 54 | + { |
| 55 | + std::cerr << "I/O error\n"; |
| 56 | + return -1; |
| 57 | + } |
| 58 | + |
| 59 | + // Region info |
| 60 | + file.write((char*)&zero32, sizeof(uint32_t)); |
| 61 | + file.write("\x08Impostor", 9); |
| 62 | + |
| 63 | + // Region address |
| 64 | + strLen = serverAddress.size(); |
| 65 | + file.write((char*)&strLen, sizeof(uint8_t)); |
| 66 | + file << serverAddress; |
| 67 | + |
| 68 | + // N of servers (always 1) |
| 69 | + file.write( (char*)&serverLen, sizeof(uint32_t)); |
| 70 | + |
| 71 | + // First and only server name |
| 72 | + file << "\x11Impostor-Master-1"; |
| 73 | + |
| 74 | + // First and only server address (numeric form not as string) |
| 75 | + file.write((char*)&(*(in_addr **)he->h_addr_list)->s_addr, sizeof(uint32_t)); |
| 76 | + file.write((char*)&port, sizeof(uint16_t)); |
| 77 | + |
| 78 | + file.write((char*)&zero32, sizeof(uint32_t)); |
| 79 | + |
| 80 | + file.close(); |
| 81 | + |
| 82 | + return 0; |
| 83 | +} |
0 commit comments