// examples/inert-sample/NativeProbe.java
//
// =========================================================================
// INERT TEACHING SAMPLE — chapter 69. THIS IS NOT MALWARE.
// The Java half of jni/inert_stub.c. Loading the library prints three log
// lines and does nothing else.
// =========================================================================
//
// This class exists to make one comparison possible, and lab 01 step 6 walks
// it:
//
//   * staticallyNamed()      is bound by the runtime doing dlsym() on the
//                            mangled name Java_com_pentest_ch69_inert_
//                            NativeProbe_staticallyNamed. That name is in the
//                            .so's dynamic symbol table, so a purely static
//                            reading recovers the whole mapping.
//
//   * dynamicallyRegistered() is bound by RegisterNatives() inside
//                            JNI_OnLoad. The C function is `static` and
//                            appears in NO symbol table. A static reading
//                            sees a `native` Java method with no
//                            implementation anywhere, and an ELF with an
//                            export list that does not mention it.
//
// Run this against the library and note that the second mapping is missing:
//
//   llvm-nm -D --defined-only libinertstub.so | grep -i java
//   python3 ../../15-Native-Code/scripts/elf-inspect.py libinertstub.so --dynsyms
//
// Then note what recovers it: hooking art::JNI::RegisterNatives, which is
// what ../../52-StaticAnalysis/scripts/blindspot-recorder.js does, or reading
// the JNINativeMethod table out of JNI_OnLoad in a disassembler, which is
// chapter 57's job.
//
// This is the concrete reason chapter 15 says native RE is not optional in
// malware analysis. It is not that native code is harder — it is that a
// specific, common, deliberate construct makes the Java-to-native mapping
// unrecoverable from the file alone.
//
// NOTHING CALLS THESE METHODS. MainActivity does not load the library. The
// library is present in the APK so that the triage tool reports a native
// surface; loading it is the reader's decision, on an emulator.

package com.pentest.ch69.inert;

public final class NativeProbe {

    private NativeProbe() {
        // no instances
    }

    /**
     * Not called anywhere in this sample. If you want to load the library on
     * an emulator, call this from a debugger or add one line to
     * MainActivity yourself — the sample deliberately does not.
     */
    public static void loadIfYouWantTo() {
        System.loadLibrary("inertstub");
    }

    /** Bound by dlsym on the mangled name. Visible in the ELF symbol table. */
    public static native String staticallyNamed();

    /** Bound by RegisterNatives. Invisible in the ELF symbol table. */
    public static native String dynamicallyRegistered();
}
