Skip to content

Commit 56e0f8d

Browse files
committed
added linux compilation support for native plugins
1 parent 6a5d80b commit 56e0f8d

File tree

2 files changed

+102
-14
lines changed

2 files changed

+102
-14
lines changed

Native/Makefile

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
WORKDIR = `pwd`
2+
3+
CC = gcc
4+
CXX = g++
5+
AR = ar
6+
LD = g++
7+
WINDRES = windres
8+
9+
INC = -I../../ReClass.NET/NativeCore/
10+
CFLAGS = -Wall -fpermissive -fPIC -std=c++14
11+
RESINC =
12+
LIBDIR =
13+
LIB =
14+
LDFLAGS = -shared
15+
16+
INC_DEBUG = $(INC)
17+
CFLAGS_DEBUG = $(CFLAGS) -g
18+
RESINC_DEBUG = $(RESINC)
19+
RCFLAGS_DEBUG = $(RCFLAGS)
20+
LIBDIR_DEBUG = $(LIBDIR)
21+
LIB_DEBUG = $(LIB)
22+
LDFLAGS_DEBUG = $(LDFLAGS)
23+
OBJDIR_DEBUG = obj/debug
24+
DEP_DEBUG =
25+
OUT_DEBUG = build/debug/native_plugin.so
26+
27+
INC_RELEASE = $(INC)
28+
CFLAGS_RELEASE = $(CFLAGS) -O2
29+
RESINC_RELEASE = $(RESINC)
30+
RCFLAGS_RELEASE = $(RCFLAGS)
31+
LIBDIR_RELEASE = $(LIBDIR)
32+
LIB_RELEASE = $(LIB)
33+
LDFLAGS_RELEASE = $(LDFLAGS) -s
34+
OBJDIR_RELEASE = obj/release
35+
DEP_RELEASE =
36+
OUT_RELEASE = build/release/native_plugin.so
37+
38+
OBJ_DEBUG = $(OBJDIR_DEBUG)/dllmain.o
39+
40+
OBJ_RELEASE = $(OBJDIR_RELEASE)/dllmain.o
41+
42+
all: debug release
43+
44+
clean: clean_debug clean_release
45+
46+
before_debug:
47+
test -d build/debug || mkdir -p build/debug
48+
test -d $(OBJDIR_DEBUG) || mkdir -p $(OBJDIR_DEBUG)
49+
50+
after_debug:
51+
52+
debug: before_debug out_debug after_debug
53+
54+
out_debug: before_debug $(OBJ_DEBUG) $(DEP_DEBUG)
55+
$(CXX) $(LIBDIR_DEBUG) -o $(OUT_DEBUG) $(OBJ_DEBUG) $(LDFLAGS_DEBUG) $(LIB_DEBUG)
56+
57+
$(OBJDIR_DEBUG)/dllmain.o: dllmain.cpp
58+
$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c dllmain.cpp -o $(OBJDIR_DEBUG)/dllmain.o
59+
60+
clean_debug:
61+
rm -f $(OBJ_DEBUG) $(OUT_DEBUG)
62+
rm -rf build/debug
63+
rm -rf $(OBJDIR_DEBUG)
64+
65+
before_release:
66+
test -d build/release || mkdir -p build/release
67+
test -d $(OBJDIR_RELEASE) || mkdir -p $(OBJDIR_RELEASE)
68+
69+
after_release:
70+
71+
release: before_release out_release after_release
72+
73+
out_release: before_release $(OBJ_RELEASE) $(DEP_RELEASE)
74+
$(LD) $(LIBDIR_RELEASE) -o $(OUT_RELEASE) $(OBJ_RELEASE) $(LDFLAGS_RELEASE) $(LIB_RELEASE)
75+
76+
$(OBJDIR_RELEASE)/dllmain.o: dllmain.cpp
77+
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c dllmain.cpp -o $(OBJDIR_RELEASE)/dllmain.o
78+
79+
clean_release:
80+
rm -f $(OBJ_RELEASE) $(OUT_RELEASE)
81+
rm -rf build/release
82+
rm -rf $(OBJDIR_RELEASE)
83+
84+
.PHONY: before_debug after_debug clean_debug before_release after_release clean_release

Native/dllmain.cpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
2+
#ifndef __linux__
13
#include <windows.h>
4+
#endif
5+
26
#include <cstdint>
37

48
#include <ReClassNET_Plugin.hpp>
59

610
/// <summary>Enumerate all processes on the system.</summary>
711
/// <param name="callbackProcess">The callback for a process.</param>
8-
void __stdcall EnumerateProcesses(EnumerateProcessCallback callbackProcess)
12+
extern "C" void __stdcall EnumerateProcesses(EnumerateProcessCallback callbackProcess)
913
{
1014
// Enumerate all processes with the current plattform (x86/x64) and call the callback.
1115
}
@@ -14,7 +18,7 @@ void __stdcall EnumerateProcesses(EnumerateProcessCallback callbackProcess)
1418
/// <param name="process">The process handle obtained by OpenRemoteProcess.</param>
1519
/// <param name="callbackSection">The callback for a section.</param>
1620
/// <param name="callbackModule">The callback for a module.</param>
17-
void __stdcall EnumerateRemoteSectionsAndModules(RC_Pointer handle, EnumerateRemoteSectionsCallback callbackSection, EnumerateRemoteModulesCallback callbackModule)
21+
extern "C" void __stdcall EnumerateRemoteSectionsAndModules(RC_Pointer handle, EnumerateRemoteSectionsCallback callbackSection, EnumerateRemoteModulesCallback callbackModule)
1822
{
1923
// Enumerate all sections and modules of the remote process and call the callback for them.
2024
}
@@ -23,7 +27,7 @@ void __stdcall EnumerateRemoteSectionsAndModules(RC_Pointer handle, EnumerateRem
2327
/// <param name="id">The identifier of the process returned by EnumerateProcesses.</param>
2428
/// <param name="desiredAccess">The desired access.</param>
2529
/// <returns>A handle to the remote process or nullptr if an error occured.</returns>
26-
RC_Pointer __stdcall OpenRemoteProcess(RC_Pointer id, ProcessAccess desiredAccess)
30+
extern "C" RC_Pointer __stdcall OpenRemoteProcess(RC_Pointer id, ProcessAccess desiredAccess)
2731
{
2832
// Open the remote process with the desired access rights and return the handle to use with the other functions.
2933

@@ -33,7 +37,7 @@ RC_Pointer __stdcall OpenRemoteProcess(RC_Pointer id, ProcessAccess desiredAcces
3337
/// <summary>Queries if the process is valid.</summary>
3438
/// <param name="handle">The process handle obtained by OpenRemoteProcess.</param>
3539
/// <returns>True if the process is valid, false if not.</returns>
36-
bool __stdcall IsProcessValid(RC_Pointer handle)
40+
extern "C" bool __stdcall IsProcessValid(RC_Pointer handle)
3741
{
3842
// Check if the handle is valid.
3943

@@ -42,7 +46,7 @@ bool __stdcall IsProcessValid(RC_Pointer handle)
4246

4347
/// <summary>Closes the handle to the remote process.</summary>
4448
/// <param name="handle">The process handle obtained by OpenRemoteProcess.</param>
45-
void __stdcall CloseRemoteProcess(RC_Pointer handle)
49+
extern "C" void __stdcall CloseRemoteProcess(RC_Pointer handle)
4650
{
4751
// Close the handle to the remote process.
4852
}
@@ -54,7 +58,7 @@ void __stdcall CloseRemoteProcess(RC_Pointer handle)
5458
/// <param name="offset">The offset into the buffer.</param>
5559
/// <param name="size">The number of bytes to read.</param>
5660
/// <returns>True if it succeeds, false if it fails.</returns>
57-
bool __stdcall ReadRemoteMemory(RC_Pointer handle, RC_Pointer address, RC_Pointer buffer, int offset, int size)
61+
extern "C" bool __stdcall ReadRemoteMemory(RC_Pointer handle, RC_Pointer address, RC_Pointer buffer, int offset, int size)
5862
{
5963
// Read the memory of the remote process into the buffer.
6064

@@ -68,7 +72,7 @@ bool __stdcall ReadRemoteMemory(RC_Pointer handle, RC_Pointer address, RC_Pointe
6872
/// <param name="offset">The offset into the buffer.</param>
6973
/// <param name="size">The number of bytes to write.</param>
7074
/// <returns>True if it succeeds, false if it fails.</returns>
71-
bool __stdcall WriteRemoteMemory(RC_Pointer handle, RC_Pointer address, RC_Pointer buffer, int offset, int size)
75+
extern "C" bool __stdcall WriteRemoteMemory(RC_Pointer handle, RC_Pointer address, RC_Pointer buffer, int offset, int size)
7276
{
7377
// Write the buffer into the memory of the remote process.
7478

@@ -78,15 +82,15 @@ bool __stdcall WriteRemoteMemory(RC_Pointer handle, RC_Pointer address, RC_Point
7882
/// <summary>Control the remote process (Pause, Resume, Terminate).</summary>
7983
/// <param name="handle">The process handle obtained by OpenRemoteProcess.</param>
8084
/// <param name="action">The action to perform.</param>
81-
void __stdcall ControlRemoteProcess(RC_Pointer handle, ControlRemoteProcessAction action)
85+
extern "C" void __stdcall ControlRemoteProcess(RC_Pointer handle, ControlRemoteProcessAction action)
8286
{
8387
// Perform the desired action on the remote process.
8488
}
8589

8690
/// <summary>Attach a debugger to the process.</summary>
8791
/// <param name="id">The identifier of the process returned by EnumerateProcesses.</param>
8892
/// <returns>True if it succeeds, false if it fails.</returns>
89-
bool __stdcall AttachDebuggerToProcess(RC_Pointer id)
93+
extern "C" bool __stdcall AttachDebuggerToProcess(RC_Pointer id)
9094
{
9195
// Attach a debugger to the remote process.
9296

@@ -95,7 +99,7 @@ bool __stdcall AttachDebuggerToProcess(RC_Pointer id)
9599

96100
/// <summary>Detach a debugger from the remote process.</summary>
97101
/// <param name="id">The identifier of the process returned by EnumerateProcesses.</param>
98-
void __stdcall DetachDebuggerFromProcess(RC_Pointer id)
102+
extern "C" void __stdcall DetachDebuggerFromProcess(RC_Pointer id)
99103
{
100104
// Detach the debugger.
101105
}
@@ -104,16 +108,16 @@ void __stdcall DetachDebuggerFromProcess(RC_Pointer id)
104108
/// <param name="evt">[out] The occured debug event.</param>
105109
/// <param name="timeoutInMilliseconds">The timeout in milliseconds.</param>
106110
/// <returns>True if an event occured within the given timeout, false if not.</returns>
107-
bool __stdcall AwaitDebugEvent(DebugEvent* evt, int timeoutInMilliseconds)
111+
extern "C" bool __stdcall AwaitDebugEvent(DebugEvent* evt, int timeoutInMilliseconds)
108112
{
109113
// Wait for a debug event.
110-
114+
111115
return false;
112116
}
113117

114118
/// <summary>Handles the debug event described by evt.</summary>
115119
/// <param name="evt">[in] The (modified) event returned by AwaitDebugEvent.</param>
116-
void __stdcall HandleDebugEvent(DebugEvent* evt)
120+
extern "C" void __stdcall HandleDebugEvent(DebugEvent* evt)
117121
{
118122
// Handle the debug event.
119123
}
@@ -126,7 +130,7 @@ void __stdcall HandleDebugEvent(DebugEvent* evt)
126130
/// <param name="size">The size of the breakpoint.</param>
127131
/// <param name="set">True to set the breakpoint, false to remove it.</param>
128132
/// <returns>True if it succeeds, false if it fails.</returns>
129-
bool __stdcall SetHardwareBreakpoint(RC_Pointer id, RC_Pointer address, HardwareBreakpointRegister reg, HardwareBreakpointTrigger type, HardwareBreakpointSize size, bool set)
133+
extern "C" bool __stdcall SetHardwareBreakpoint(RC_Pointer id, RC_Pointer address, HardwareBreakpointRegister reg, HardwareBreakpointTrigger type, HardwareBreakpointSize size, bool set)
130134
{
131135
// Set a hardware breakpoint with the given parameters.
132136

0 commit comments

Comments
 (0)