Reputation: 3689
On Android, I need to retrieve the bytecode from the executing class at runtime. If you're wondering why, the reason is that I'd like to compute a hash of it in order ton implement some anti-piracy mechanism that would check that the file hasn't been tampered.
Anyway, I'm trying it like this:
InputStream is = this.getClass().getClassLoader()
.getResourceAsStream("org/foo/bar");
Whichever parameter I pass in the getResourceAsStream(), it always return null.
Is there actually a way to get access ti the bytecode at runtime on Android?
Upvotes: 1
Views: 393
Reputation: 178
Not sure if that is possible, you should trust the signature system used for APK's. The only hack that I have seen with these is wrapping that app in another app that contains the malicious code and Google fixed that ( I think ). Classes already have a hash code but I'm sure that will not give the same results to what you want to do.
If someone can change your code they will also disable your checks.
I have seen and tried a reverse engineering app to check the security of Android's byte code with an app of my own and it only worked on rooted systems and the disabled code is so horrendous it's unusable. It's not the same as dissembling a Java app.
Pirating a game does not require it to be modified.
Upvotes: 1