-
Notifications
You must be signed in to change notification settings - Fork 18k
x/mobile: reverse binding: undefined #33705
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
Comments
The Go project uses its bug tracker only for tacking bugs and for Proposal Process. This proposal was published more than 2 years ago:
Then, the same person answer this:
Why do you assign unskilled programmers to do the job? They should be more explicit. |
Hello @mvasi90, thank you for filing this bug! Before proceeding, I'd highly recommend reading through Go's code of conduct https://golang.org/conduct and also I'd recommend, "always assume good intent and be kind", "no is considered temporary, yes is forever". I'll assume good intent and that this is perhaps a miscommunication while expressing your frustrations. With that having been said, let's try to get to the filed issue: I believe you filed a bug about reverse bindings being undefined and that the message about MIN_VALUE was unrelated?
Could you please elaborate your question here? I suspect you are directly using that value as a constant and if its constant expression looks like an integer that fits into 256 bits, the compiler will default its type to an integer. Perhaps return or use it as a float32 and you'll be good to go. I am not an x/mobile expert but I shall kindly page @eliasnaur if he has time to reply to your issue. |
First: I apologize for not being word perfect in english. Second: If it seems that I use destructive criticism or I have a strange behavior, it must be due to the lack of tolerance for nonsense.
Now I understand. I thought it was a serious project.
Okay, I apologize for my severity.
Yes, of course. Thank you. I'm working every day (7 days a week), 11-17 hours per day. I'm designing and implementing all (from scratch): my own protocols, advanced security tests, I'm creating SeLinux policies (domain transition, multi category security, etc) on ArchLinux (which is not fully compatible with existing policies, nor does it have official support), I'm using my own Cluster (with Corosync messaging layer and Pacemaker resource manager) better than Docker swarm, etc etc. I prefer Go before C / C ++ because it speeds up the work and already ensures typical programmer concerns (pointers, etc.) and I can focus more on my work.
No. Float.MIN_VALUE are working, but Build.BOARD does not.
I want to be kind, I will not answer that. Thanks for your time. At this step it is not necessary to write this, but I will: package b
import "Java/android/os/Build"
func Test() {
_ = Build.BOARD
} package android.os;
public class Build {
...
public static final String BOARD = null;
...
} Note: BOARD field is final, once "instantiated" (initialized), its value cannot be modified. Even if Java (Dalvik) sends it to Go, it doesn't work. Works: package b
import "Java/java/lang/Float"
func Test3() {
_ = Float.MIN_VALUE
} package java.lang;
public class Float {
...
public static final float MIN_VALUE = 1.4E-45F;
...
} What is the difference?
Indeed, if it cannot be instantiated, there is no object. And Go cannot receive "object reference", such as b os.Build. But you should be able to access the constant fields just like Float.MIN_VALUE. |
The comment above refers to fields that are not constant (final static). PackageInfo.installLocation is not constant and therefore not supported. You correctly point out that Build.BOARD is final static and therefore should be supported. It's been a while since I worked with gomobile, but my guess is that another restriction is that the field must also be a primitive type to be supported. You and I know that String is immutable and could be treated as a primitive constant, but go mobile doesn't know that (yet). If you're still interested, I encourage you to take a stab at adding support of constant String fields to gomobile. |
Okay. If I had known that the constants depend on the type, I would have started the project with C++. It's not too late, but I lost valuable time. Well, no problem.
I don't like to leave the projects unfinished, And I am very busy, I am doing the work of an entire company (system administrators, security, database, multiplatform client and server programming, etc etc) I think I don't be able to contribute for now. But of course, I appreciate your work. And if you can, please leave documented when something does not work. |
I'm having trouble figuring out what the feature request in this issue is: I see some questions in the original post, some discussion of previous proposals, and a comment from @eliasnaur suggesting a specific contribution, but I'm having trouble seeing the scope of that contribution or the component to which it would be applied, and moreover I'm hesitant to tag this issue If there is a concrete feature request or bug fix to be resolved here, please open a new issue and directly describe the specific changes that are needed. Thanks. |
Hello @mvasi90 , Acutally I want to explore reverse binding.. Can you please let me know which is the best place to start.. I couldn't find any concrete sample or documentation at: Any help will be appreciated..:) Edit: I want to define one java class and want to call a function of that class from go layer. |
@jay11ca39 This is not a good place to ask that because they don't want to mix things up. At any moment the cleaning lady appears and throws a fight at you. I strongly recommend that you take time to learn C or Rust for this purpose. You can make your own wrappers manually. x/mobile is interesting but it is not "mature" or stable.
Now, if you still want to do it in Golang, you can investigate here: You can't access some Java fields from Go. I recommend you to invoke setters and getters from Go. If an existent class (Java source) does not have setters and getters you can make a wrapper class in Java an use it from Go. Also you can pass data between Java and Go with interface callback. For reverse binding the best example is the asset package. Here is an example in which I also incorporate the use of callbacks: Golang: package mylib
import (
"io/ioutil"
"golang.org/x/mobile/asset"
)
// Send back information to Java from Golang (async)
type Callback interface {
R(data []byte) // Response: byte slice (array in Java)
E(error byte) // Error: single byte (better than string or byte slice)
}
// call from Java Mylib.test(); (before this, you should set the context, read below: java side)
func Test(cb Callback) {
// go func(){}() is optional, used to run the process in the background with goroutine (asynchronous operations)
go func(cb Callback) {
f, err := asset.Open("secret-encrypted.raw")
if err != nil {
// call java (callback)
cb.E(0x01) // or 1 instead 0x01
// I do not recommend sending compromising information to Java.
// To make reverse engineering more difficult you can send single byte value as flag.
// Example: 0x01, 0x02, etc (for every error). And process errors with a switch in Java side.
// cb.E("Unable to open file") // don't do this
// cb.E([]byte("Unable to open file")) // or this
return
}
defer f.Close()
b, err := ioutil.ReadAll(f)
if err != nil {
cb.E(0x02) // this is another error. You can process it from Java or better treat them all equally sending every time 0x01 or random number
return
}
// call decrypt function
// send back to Java decrypted data
cb.R(decrypted_byte_slice)
}(cb)
} Java example (with Fragment): import mylib.Mylib;
import mylib.Callback;
import go.Seq;
public class MyFragment extends Fragment {
private Context c;
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
c = context;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Seq.setContext(c);
Mylib.test(new Callback() {
@Override
public void r(byte[] data) {
// process response
}
@Override
public void e(byte error) {
switch(error) {
case 0x01:
// process error 0x01
break;
// ...
}
}
});
}
} Note: If you don't want to call Go from a Java Fragment, but from Activity, you can put all Go code inside: @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
// ...
// here Go call
} With the previous example you can do more than simple call Java from Go. As you can see, you can do background operations. Performing operations on tasks other than the main one adds a little more difficulty when reverse engineering is used. You can set a little random sleep (for example from 1 to 5 seconds) before sending the response to Java. (Android = Java).
More low level example: (you can make your own C wrappers) More info:
Example: f, err := os.Open(fmt.Sprintf("/proc/%d/fd", os.Getpid()))
if err == nil {
fs, err := f.Readdir(-1)
if err == nil {
for _, file := range fs {
// readlink, like linux command
l, err := os.Readlink(fmt.Sprintf("/proc/%d/fd/%s", os.Getpid(), file.Name()))
if err == nil {
if strings.HasPrefix(l, "/data/app/") && strings.Contains(l, "<your-package-name>") && strings.HasSuffix(l, ".apk") {
res, err := apkverifier.Verify(l, nil)
if err == nil {
for _, cert := range res.SignerCerts {
for _, crt := range cert {
// replace this by your function that creates the master key based on the raw signature.
// Important:
// don't break the loop
// don't check if the signature is Okay
// a hacker can keep your signature and add another. Use all signatures to make your master key used to decrypt data (master key must created first on your desktop pc with bash script or go binary, and use it to encrypt important files from your desktop and put on your Android Project)
fmt.Printf("Signature: %v\n", crt.Raw)
// masterKeyCalculator(crt.Raw)
}
}
}
break
}
}
}
}
} I hope these examples help you. |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Get the fields of the Build class.
https://play.golang.org/p/PkV4bxUJf8z
The java.lang.Float.MIN_VALUE works. Why? The field type must be Integer? String does not work?
What did you expect to see?
Board String
What did you see instead?
The text was updated successfully, but these errors were encountered: