Comments (2)
Here is a sample.
It may not work because I have not tested it.
It doesn't work when the bitness (64-bit or 32-bit) of the injector process is different from that of the target process.
DWORD pid = ...process id of the target process...;
// find the base address of the library in the target process.
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
if (hSnapshot == INVALID_HANDLE_VALUE) {
...error handling...
}
MODULEENTRY32 me;
me.dwSize = sizeof(me);
BOOL ok;
for (ok = Module32FirstW(hSnapshot, &me); ok; ok = Module32NextW(hSnapshot, &me)) {
if (...check `me.szModule` or `me.szExePath`...) {
break;
}
}
if (!ok) {
...error handling...
}
CloseHandle(hSnapshot);
// `me.modBaseAddr` is the base address of the library to be uninjected.
// Call FreeLibarry in the target process.
HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD, FALSE, pid);
if (hProcess == NULL) {
...error handling...
}
HMODULE kernel32 = GetModuleHandleA("kernel32");
LPTHREAD_START_ROUTINE func_addr = (LPTHREAD_START_ROUTINE)GetProcAddress(kernel32, "FreeLibrary");
HANDLE hThread = CreateRemoteThead(hProcess, NULL, 0, func_addr, me.modBaseAddr, 0, NULL);
if (hThread == NULL) {
...error handling...
}
WaitForSingleObject(hThread, INFINITE);
DWORD exit_code;
GetExitCodeThread(hThread, &exit_code);
if (exit_code == 0) {
// FreeLibrary in the target process failed.
...error handling...
}
CloseHandle(hThread);
CloseHandle(hProcess);
from injector.
Sorry for so late replay, After test, it works.
But in one situation, it does not work: the injected dll start new thread and the thread is running. In this situation, seem like did nothing.
from injector.
Related Issues (20)
- add option HOT 2
- Create new process and inject HOT 1
- macos dylib injector HOT 1
- Segfault in ld on ARM HOT 2
- Could not find libc HOT 4
- PTRACE_ATTACH error : Operation not permitted HOT 6
- Trace/breakpoint trap on UserLAnd (Android App) HOT 1
- `INJERR_NO_LIBRARY` and `INJERR_NO_FUNCTION` have same integer representation
- ubuntu 18.04 inject snap process failed HOT 2
- Support for MIPS HOT 9
- Support RISC-V HOT 2
- Support PowerPC HOT 2
- injector_uninject should fail when the libc is musl. HOT 1
- Wine? HOT 4
- expose API to set libc name?
- Compile for Windows on Linux (mingw) HOT 1
- Safe injection on linux HOT 3
- Pass an argument to function HOT 3
- Inconsistency detected by ld.so HOT 2
- -Wimplicit-function-declaration and -Wint-conversion when compiling under MinGW x64 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from injector.