exec-probe.dhover×110all
#!/usr/bin/env dub
/+ dub.sdl:
    name "android-research-exec-probe"
    platforms "linux"
    dflags "-betterC"
    targetPath "build"
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
+/
// ci: run-always
/**
Libc-only E1–E4 payload: report the real app context, argv and executable;
optionally try execve or dlopen. See ../index.md#current-target-experiments.
No ADB calls, policy changes, namespace changes or persistent child processes.
Compile with -version=ExecProbeStatic to omit dynamic-loader calls for E4.
*/
module 
(module) exec_probe

Libc-only E1–E4 payload: report the real app context, argv and executable; optionally try execve or dlopen. See ../index.md#current-target-experiments. No ADB calls, policy changes, namespace changes or persistent child processes. Compile with -version=ExecProbeStatic to omit dynamic-loader calls for E4.

exec_probe
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.errno

D header file for C99.

pubs.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html, errno.h

Source

core/stdc/errno.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Alex Rønne Petersen@standardsISO/IEC 9899:1999 (E)
errno
:
(alias) exec_probe.errno = int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
errno
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.stdio

D header file for C99 <stdio.h>

pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h

Source

core/stdc/stdio.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Alex Rønne Petersen@standardsISO/IEC 9899:1999 (E)
stdio
:
(alias) exec_probe.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
,
(alias) exec_probe.fflush = int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trusted
fflush
,
(alias) exec_probe.fopen = shared(core.stdc.stdio._IO_FILE)* core.stdc.stdio.fopen(scope const(char*) filename, scope const(char*) mode) nothrow @nogc
fopen
,
(alias) exec_probe.fclose = int core.stdc.stdio.fclose(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc
fclose
,
(alias) exec_probe.fgets = char* core.stdc.stdio.fgets(char* s, int n, shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc
fgets
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.string

D header file for C99.

pubs.opengroup.org/onlinepubs/009695399/basedefs/string.h.html, string.h

Source

core/stdc/string.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly@standardsISO/IEC 9899:1999 (E)
string
:
(alias) exec_probe.strcmp = int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.unistd

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly@standardsThe Open Group Base Specifications Issue 8, IEEE Std 1003.1, 2024 Edition
unistd
:
(alias) exec_probe.getuid = uint core.sys.posix.unistd.getuid() nothrow @nogc @trusted
getuid
,
(alias) exec_probe.getgid = uint core.sys.posix.unistd.getgid() nothrow @nogc @trusted
getgid
,
(alias) exec_probe.readlink = long core.sys.posix.unistd.readlink(scope const(char*), char*, ulong) nothrow @nogc
readlink
,
(alias) exec_probe.execve = int core.sys.posix.unistd.execve(scope const(char*), scope const(char**), scope const(char**)) nothrow @nogc
execve
;
version (
ExecProbeStatic
ExecProbeStatic
) {} else
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.dlfcn

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly, Alex Rønne Petersen@standardsThe Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
dlfcn
:
(alias) exec_probe.dlopen = void* core.sys.posix.dlfcn.dlopen(scope const(char*), int) nothrow @nogc
dlopen
,
(alias) exec_probe.dlclose = int core.sys.posix.dlfcn.dlclose(void*) nothrow @nogc
dlclose
,
(alias) exec_probe.dlerror = char* core.sys.posix.dlfcn.dlerror() nothrow @nogc
dlerror
,
(alias constant) exec_probe.RTLD_NOW = int core.sys.posix.dlfcn.RTLD_NOW = 2
RTLD_NOW
,
(alias constant) exec_probe.RTLD_LOCAL = int core.sys.posix.dlfcn.RTLD_LOCAL = 0
RTLD_LOCAL
;
extern(C) extern __gshared char**
(__gshared global) char** exec_probe.environ
environ
;
extern(C) int
int exec_probe.main(int argc, char** argv) nothrow @nogc @system
main
(int
(parameter) int argc
argc
, char**
(parameter) char** argv
argv
) @system nothrow @nogc
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("uid=%u gid=%u\n",
uint core.sys.posix.unistd.getuid() nothrow @nogc @trusted
getuid
(),
uint core.sys.posix.unistd.getgid() nothrow @nogc @trusted
getgid
());
char[4096]
(local variable) char[4096] buffer
buffer
;
auto
(local variable) shared(core.stdc.stdio._IO_FILE)* context
context
=
shared(core.stdc.stdio._IO_FILE)* core.stdc.stdio.fopen(scope const(char*) filename, scope const(char*) mode) nothrow @nogc
fopen
("/proc/self/attr/current", "r");
if (
(local variable) shared(core.stdc.stdio._IO_FILE)* context
context
is null)
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("context: errno=%d\n",
int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
errno
);
else { if (
char* core.stdc.stdio.fgets(char* s, int n, shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc
fgets
(
(local variable) char[4096] buffer
buffer
.
(constant) char* char[4096].ptr = &buffer
ptr
, cast(int)
(local variable) char[4096] buffer
buffer
.
(constant) ulong char[4096].length = 4096LU
length
,
(local variable) shared(core.stdc.stdio._IO_FILE)* context
context
) !is null)
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("context=%s\n",
(local variable) char[4096] buffer
buffer
.
(constant) char* char[4096].ptr = &buffer
ptr
);
int core.stdc.stdio.fclose(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc
fclose
(
(local variable) shared(core.stdc.stdio._IO_FILE)* context
context
);
} const
(local variable) const(long) size
size
=
long core.sys.posix.unistd.readlink(scope const(char*), char*, ulong) nothrow @nogc
readlink
("/proc/self/exe",
(local variable) char[4096] buffer
buffer
.
(constant) char* char[4096].ptr = &buffer
ptr
,
(local variable) char[4096] buffer
buffer
.
(constant) ulong char[4096].length = 4096LU
length
- 1);
if (
(local variable) const(long) size
size
< 0)
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("readlink: errno=%d\n",
int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
errno
);
else {
(local variable) char[4096] buffer
buffer
[
(local variable) const(long) size
size
] = 0;
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("exe=%s\n",
(local variable) char[4096] buffer
buffer
.
(constant) char* char[4096].ptr = &buffer
ptr
);
} foreach (
(local variable) int i
i
; 0 ..
(parameter) int argc
argc
)
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("argv[%d]=%s\n",
(local variable) int i
i
,
(parameter) char** argv
argv
[
(local variable) int i
i
]);
if (
(parameter) int argc
argc
== 3 &&
int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
(
(parameter) char** argv
argv
[1], "--exec") == 0)
{ const(char)*[2]
(local variable) const(char)*[2] childArgs
childArgs
= [
(parameter) char** argv
argv
[2], null];
int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trusted
fflush
(null);
int core.sys.posix.unistd.execve(scope const(char*), scope const(char**), scope const(char**)) nothrow @nogc
execve
(
(parameter) char** argv
argv
[2],
(local variable) const(char)*[2] childArgs
childArgs
.
(constant) const(char)** const(char)*[2].ptr = &childArgs
ptr
, cast(const(char)**)
(__gshared global) char** exec_probe.environ
environ
);
const
(local variable) const(int) error
error
=
int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
errno
;
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("execve(%s): errno=%d\n",
(parameter) char** argv
argv
[2],
(local variable) const(int) error
error
);
return 1; } version (
ExecProbeStatic
ExecProbeStatic
) {} else
{ if (
(parameter) int argc
argc
== 3 &&
int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
(
(parameter) char** argv
argv
[1], "--dlopen") == 0)
{ auto
(local variable) void* handle
handle
=
void* core.sys.posix.dlfcn.dlopen(scope const(char*), int) nothrow @nogc
dlopen
(
(parameter) char** argv
argv
[2],
(constant) int core.sys.posix.dlfcn.RTLD_NOW = 2
RTLD_NOW
|
(constant) int core.sys.posix.dlfcn.RTLD_LOCAL = 0
RTLD_LOCAL
);
if (
(local variable) void* handle
handle
is null)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("dlopen: %s\n",
char* core.sys.posix.dlfcn.dlerror() nothrow @nogc
dlerror
());
return 1; }
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("dlopen: success\n");
return
int core.sys.posix.dlfcn.dlclose(void*) nothrow @nogc
dlclose
(
(local variable) void* handle
handle
) == 0 ? 0 : 1;
} } return 0; }