Jump to content
Sign in to follow this  

Rookie Help with translation from C and Java functions

Recommended Posts


Hi everybody!

Would anyone by so kind to help me in translation of these functions:

function GeneratePartMD5hash(pngFile,mystart,howmuch){
  var istream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
  istream.init(pngFile, 0x01, 0444, 0);
  var ch = Components.classes["@mozilla.org/security/hash;1"].createInstance(Components.interfaces.nsICryptoHash);
  ch.updateFromStream(istream, howmuch);
  var hash = ch.finish(false);
  function toHexString(charCode){
    return ("0" + charCode.toString(16)).slice(-2);
  var s = [toHexString(hash.charCodeAt(i)) for (i in hash)].join("");
  return s;

Above function that is represented in java language:

public void run() { String hash_string = "";
          File plik = new File(this.val$dir + File.separator + NCode.access$0(this.this$0));
          try {
            FileInputStream fis = new FileInputStream(plik);
            BufferedInputStream bis = new BufferedInputStream(fis);

            byte[] bufor = new byte[1024];
            try {
              for (int i = 0; i < this.this$0.begin.length; ++i) {
                int ile = this.this$0.end[i] - this.this$0.begin[i];
                DigestInputStream md5is = new DigestInputStream(
                  bis, MessageDigest.getInstance("MD5"));
                while (ile > bufor.length) {
                  ile -= bufor.length;
                md5is.read(bufor, 0, ile);
                hash_string = hash_string + 
                if (i + 1 < this.this$0.begin.length)
                  bis.skip(this.this$0.end[i] - this.this$0.begin[(i + 1)]);

Thanks a lot !

I've been trying different methods (used fileread binary function) and nothing :)

I suppose DLLCall will need to be used but i have no clue how and where to start from.

Will appriciate any kind of help from u guys! Thanks

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this