P
P
pqgg7nwkd42016-10-30 18:43:13
linux
pqgg7nwkd4, 2016-10-30 18:43:13

How to intercept Java_java_lang_ClassLoader_defineClass0 from libjava.so?

Good afternoon. I am researching Linux and Java for general development for the future.
I read that you can use LD_PRELOADit to intercept dynamically linked functions, you just need to export them in your library and connect it with LD_PRELOAD. And then whoever first declares the function, "that and slippers."
Decided to replace the functions Java_java_lang_ClassLoader_defineClass0, Java_java_lang_ClassLoader_defineClass1, Java_java_lang_ClassLoader_defineClass2from libjava.so. The choice is made in order to further decrypt encrypted resources. I ask you to leave this goal out of the discussion.
Well. Wrote "Hello world" in Java from three classes and one resource. Checking:

#java -cp . Main
Hello world

I am writing a library. Since I'm somewhat fluent in C++, I decided to write in FreePascal:
library run;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

procedure Java_java_lang_ClassLoader_defineClass0; cdecl; export;
begin
  Writeln('LibRun Java_java_lang_ClassLoader_defineClass0');
end;

procedure Java_java_lang_ClassLoader_defineClass1; cdecl; export;
begin
  Writeln('LibRun Java_java_lang_ClassLoader_defineClass1');
end;

procedure Java_java_lang_ClassLoader_defineClass2; cdecl; export;
begin
  Writeln('LibRun Java_java_lang_ClassLoader_defineClass2');
end;

exports
  Java_java_lang_ClassLoader_defineClass0,
  Java_java_lang_ClassLoader_defineClass1,
  Java_java_lang_ClassLoader_defineClass2;

initialization
  Writeln('LibRun loaded');
finalization
  Writeln('LibRun unloaded');
end.

I expect to see one of the messages LibRun Java_java_lang_ClassLoader_defineClass*, and then an error, because my implementations do nothing.
I run:
#LD_PRELOAD=/path/to/lib/librun.so java -cp . Main
LibRun loaded
Hello world
LibRun unloaded

As you can see, the library was connected, but the interception did not happen.
The question is what's wrong?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
P
pqgg7nwkd4, 2016-10-30
@pqgg7nwkd4

Java loads these files via dlopenand dlsym, so it is not intercepted.
It needs to be intercepted dlsym.

R
Rou1997, 2016-10-31
@Rou1997

I read that using LD_PRELOAD you can intercept dynamically linked functions, you just need to export them in your library and connect it using LD_PRELOAD. And then whoever first declares the function, "that and slippers."

If it were that easy, why would you need MSHookFunction (Cydia)?

F
Fragman, 2017-01-03
@Fragman

Because in the css file the path comes from the css file, there is no fonts folder in the css folder ---- specify the full path with the domain or ../

A
A person from Kazakhstan, 2017-01-03
@LenovoId

you do not have these fonts in the fonts folder!
you need what was this
and you only have this:
b27ed2f72c8349a397b8f1073b4a53fe.png

D
Dmitry, 2017-01-04
@ddimonn8080

As a result, I connected it through Google fonts and it all worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question