Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Checksum in Java

 
Post new topic   Reply to topic Printable version
 View previous topic  Flagmover... Post :: Post ConnectionType field in Login packet  View next topic  
Author Message
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sun Mar 23, 2003 2:49 pm    Post subject: Checksum in Java Reply to topic Reply with quote

I'm trying to get the checksums for the map and news.txt in Java. So far I've made a class (validator) to get a checksum from a file. Because Java does not support unsigned variables it returns a long. getInt32() returns an int which is signed so I 0xFFFFFFFFL to make it unsigned each time I want to use it.
As you can probably guess the checksums don't match, any ideas? I used smallmap.lvl that came with the ASSS server.

Code: Show/Hide
...
  public static int getInt32(byte[] msg, int pos) {
    return (int)(
      ((msg[pos+3] & 0xFF) << 24) +
      ((msg[pos+2] & 0xFF) << 16) +
      ((msg[pos+1] & 0xFF) <<  8) +
       (msg[pos  ] & 0xFF)
    );
  }
...
    case 0x29: //Map checksum
      System.out.println("Receieved: Map checksum");
      String mapName = new String(data, 1, 16);

      long mapCRC = validator.getChecksum(mapName.trim());
      if (mapCRC == -1) break; //File not found
      long mCrc   = getInt32(data, 17) & 0xFFFFFFFFL;
      System.out.println("  map " + mapCRC + "/" + mCrc);
      if (mapCRC != mCrc)
      System.out.println("  " + mapName.trim() + " out of sync");
//Receieved: Map checksum
//  map 1087398166/3002814809
//  smallmap.lvl out of sync
...


Code: Show/Hide
import java.io.*;
import java.util.zip.*;

public class validator {
  static final int version = 1;

  public validator() {
    System.out.println("-- validator v" + version + " --");
  }

  public static long getChecksum(byte[] file) {
    CRC32 crc = new CRC32();
    crc.reset();
    crc.update(file);
    return crc.getValue();
  }

  public static long getChecksum(String fileName) {
    byte[] file = {0};
    try {
      RandomAccessFile raf = new RandomAccessFile(fileName, "r");
      raf.readFully(file);
      raf.close();
    } catch(SecurityException e) {
      System.out.println("-- Err: Security settings too high to read local files --");
    } catch(FileNotFoundException e) {
      System.out.println("-- Could not locate " + fileName + " --");
      return -1;
    } catch(EOFException e) {
      System.err.println("-- Err: End of File exception --");
    } catch(IOException e) {
      System.err.println("-- Err: IO exception --");
    }
    //CRC32 crc = new CRC32();
    //crc.reset();
    //crc.update(file);
    //return crc.getValue();
    return getChecksum(file);
  }
}

Feel free to nick my code (if you can get it to work, :?).
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
SOS
Server Help Squatter


Joined: Dec 02 2002
Posts: 329
Offline

PostPosted: Wed Mar 26, 2003 10:06 am    Post subject: Reply to topic Reply with quote

Java doesn't support unsigned?? OMG my opinion of Java dropped below VB. And doing & 0xffffffff sounds weird to me, but I guess Java might be weird like that sa_tongue.gif

Anyway, maybe ask Dock? He made a Java bot, hmm?
_________________
3y3 4m l33t h4x0r
j0! 3y3 4m t4lking to j00!
fux0red 5cr1pt k1dd13.
-"l33t h41ku"
Back to top
View users profile Send private message Add User to Ignore List Send email
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Thu Mar 27, 2003 5:12 pm    Post subject: Reply to topic Reply with quote

maybe..whats even worse is that you can't do pointer arithmetic or get a byte pointer to the beginning of a class (so for each packet you have to set each byte individually!! and it won't tell you how big the UDP packet received is, v. tricky with chunk packets..blah blah blah...).
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 56 page(s) served in previous 5 minutes.

phpBB Created this page in 0.451274 seconds : 27 queries executed (94.5%): GZIP compression disabled