aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/image/pe.h40
-rw-r--r--server/src/main.cpp14
-rw-r--r--server/src/server/packet.h5
-rw-r--r--server/src/util/util.cpp4
4 files changed, 58 insertions, 5 deletions
diff --git a/server/src/image/pe.h b/server/src/image/pe.h
index 2199411..0256a8b 100644
--- a/server/src/image/pe.h
+++ b/server/src/image/pe.h
@@ -120,6 +120,44 @@ class image {
}
}
+ void copy(std::vector<char> &out) {
+ const auto nt = m_image->get_nt_headers();
+ const auto n = nt->file_header.num_sections;
+
+ out.resize(nt->optional_header.size_image);
+
+ for (auto &sec : m_sections) {
+ std::memcpy(&out[sec.va], &m_buffer[sec.rva], sec.size);
+ }
+ }
+
+ void relocate(std::vector<char> &image, uintptr_t base) {
+ const uint32_t delta =
+ base - m_image->get_nt_headers()->optional_header.image_base;
+ if (delta > 0) {
+ for (auto &[base_rva, entry] : m_relocs) {
+ if (entry.type == win::rel_based_high_low) {
+ *reinterpret_cast<uint32_t *>(image.data() + base_rva +
+ entry.offset) += delta;
+ }
+ }
+ }
+ }
+
+ void fix_imports(std::vector<char> &image, const std::string_view imports) {
+ if (!nlohmann::json::accept(imports.data())) {
+ io::logger->error("imports arent valid json!!");
+ return;
+ }
+
+ auto j = nlohmann::json::parse(imports.data());
+ for (auto &[mod, funcs] : m_imports) {
+ for (auto &func : funcs) {
+ *reinterpret_cast<uint32_t *>(image.data() + func.rva) = j[func.name];
+ }
+ }
+ }
+
const auto operator->() { return m_image; }
operator bool() const { return m_image != nullptr; }
@@ -138,4 +176,6 @@ class image {
}
};
+
+
}; // namespace pe \ No newline at end of file
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 6350179..df3f6e8 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -169,6 +169,20 @@ int main(int argc, char* argv[]) {
}
}
+ if (id == tcp::packet_id::game_select) {
+ // select image
+ // set message to be pe header
+ // stream imports
+ // wait for client to send back a packet with allocation base and fixed imports
+ }
+
+ if (id == tcp::packet_id::image) {
+ // message contains allocation base
+ // fixed imports are streamed back/save them in a folder to see if anything went wrong
+ // stream back the fixed image
+ // set client status or just drop them
+ }
+
client.write(tcp::packet_t(message, tcp::packet_type::write, session));
});
diff --git a/server/src/server/packet.h b/server/src/server/packet.h
index 77bca7b..626d340 100644
--- a/server/src/server/packet.h
+++ b/server/src/server/packet.h
@@ -18,10 +18,7 @@ enum packet_id {
process_list,
ban,
game_select,
- image_req,
- image_resp,
- import_req,
- import_resp
+ image
};
struct packet_t {
diff --git a/server/src/util/util.cpp b/server/src/util/util.cpp
index 799663f..1cb6367 100644
--- a/server/src/util/util.cpp
+++ b/server/src/util/util.cpp
@@ -4,4 +4,6 @@
void util::to_lowercase(std::string &str) {
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
-} \ No newline at end of file
+}
+
+