Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JNetReflector writes some files using execution stub with different behaviors on each execution #542

Closed
masesdevelopers opened this issue Sep 25, 2024 · 3 comments · Fixed by #544, #546, #547 or #550
Assignees
Labels
bug Something isn't working JNetReflector JNetReflector related issue

Comments

@masesdevelopers
Copy link
Contributor

masesdevelopers commented Sep 25, 2024

Outside from the topic of this issue, the generation of the methods is not stable. Run by run, JNetReflector writes some files using execution stub with different behaviors:
image
image

Originally posted by @masesdevelopers in masesgroup/netdroid#75 (comment)

@masesdevelopers masesdevelopers self-assigned this Sep 25, 2024
@masesdevelopers masesdevelopers added bug Something isn't working JNetReflector JNetReflector related issue labels Sep 25, 2024
@masesdevelopers
Copy link
Contributor Author

Look at masesgroup/netdroid#96: it is a simple run done on an unchanged configuration

@masesdevelopers
Copy link
Contributor Author

JNetReflector uses

public static IDictionary<Class, IReadOnlyDictionary<string, string>> ExtractJavaInfo(IEnumerable<Class> classes, string classPath, string javapFullPath = null)
to extract information from each class if PreferMethodWithSignature is true:

  1. JNetReflector prefills a dictionary with the output of the javap tool executed on all classes to be reflected
  2. If the configuration reports PreferMethodWithSignature to true the IExecuteWithSignature is preferred if the dictionary at step 1 contains a signature associated to the method.

Everything is systematic expect the availability of the result in the dictionary. The possible problem identified comes from some timeout within

public static IDictionary<Class, IReadOnlyDictionary<string, string>> ExtractJavaInfo(IEnumerable<Class> classes, string classPath, string javapFullPath = null)

The reason of the timeout introduced comes from some conditions identified the first time this behavior was introduced.

The output of javap for android.companion.AssociatedDevice is the following:

D:\tools\android\cmdline-tools\latest\bin>javap -s -cp ..\..\..\platforms\android-35\android.jar android.companion.AssociatedDevice
Compiled from "AssociatedDevice.java"
public final class android.companion.AssociatedDevice implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator<android.companion.AssociatedDevice> CREATOR;
    descriptor: Landroid/os/Parcelable$Creator;
  android.companion.AssociatedDevice();
    descriptor: ()V

  public android.bluetooth.BluetoothDevice getBluetoothDevice();
    descriptor: ()Landroid/bluetooth/BluetoothDevice;

  public android.bluetooth.le.ScanResult getBleDevice();
    descriptor: ()Landroid/bluetooth/le/ScanResult;

  public android.net.wifi.ScanResult getWifiDevice();
    descriptor: ()Landroid/net/wifi/ScanResult;

  public void writeToParcel(android.os.Parcel, int);
    descriptor: (Landroid/os/Parcel;I)V

  public int describeContents();
    descriptor: ()I

  public java.lang.String toString();
    descriptor: ()Ljava/lang/String;

  public boolean equals(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Z

  public int hashCode();
    descriptor: ()I

  static {};
    descriptor: ()V
}

D:\tools\android\cmdline-tools\latest\bin>

since it ends with }, a possible update is to wait that it appears in

while ((line = process.StandardOutput.ReadLine()) != null)

prebuilding the lines reported from the process.StandardOutput.
The function
public static IDictionary<Class, IReadOnlyDictionary<string, string>> ExtractJavaInfo(IEnumerable<Class> classes, string classPath, string javapFullPath = null)
never kills the process, so waiting more time on the stream can help.

masesdevelopers added a commit that referenced this issue Sep 26, 2024
* #542 (comment): implemented javap output prefill with timeout

* Added new algorithm
@masesdevelopers
Copy link
Contributor Author

#544 (comment): After a first test with head of JNet repository the issue is still there, see masesgroup/netdroid#100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment