• Welcome to Valhalla Legends Archive.
 
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Metallicist

#2
Java Programming / Re: Sending a packet in java..
September 30, 2008, 10:59 AM
No problem now.. bot chillin' on b.net :)

Dunno what was happening there.. that code was tossed.
#3
Java Programming / Re: Sending a packet in java..
September 19, 2008, 05:48 PM
not trying to do anything nice and clean yet.. was just trying to see if i could get bnet to respond. B.net responds just fine.. just confused about the double data in packet.. here's the full code


//--------------------------------------------------------------
import java.net.*;
import java.io.*;

public class Connection
{
Socket client;
DataInputStream disStream;
DataOutputStream dosStream;

public Connection(String address, int port)
{
try
{
client = new Socket(address, port);
client.setKeepAlive(true);
}
catch(Exception e)
{
System.out.println("Trying to open socket... " + e);
}

try
{
disStream = new DataInputStream(client.getInputStream());
}
catch(Exception e)
{
System.out.println("Trying to get input stream... " + e);
}

try
{
dosStream = new DataOutputStream(client.getOutputStream());
}
catch(Exception e)
{
System.out.println("Trying to get output stream... " + e);
}
}

public DataInputStream getInputStream()
{
return disStream;
}

public void sendPacket(int ID)
{
try
{
dosStream.flush();
}
catch(Exception e)
{
closeConnection();
System.out.println("flush... " + e);
}
switch(ID)
{
case 00:
try
{
dosStream.writeByte(0x01);
}
catch( Exception e)
{
closeConnection();
System.out.println("Trying to send 0x01... " + e);
}
case 50:
try
{
ByteFromIntArray intToByte=new ByteFromIntArray(false);
int[] intAr = {0xFF,0x50,0x3a,0x00,0x00,0x00,0x00,0x00,0x36,0x38,
0x58,0x49,0x50,0x58,0x45,0x53,0xd1,0x00,0x00,0x00,0x53,0x55,0x6e,
0x65,0xc0,0xa8,0x01,0x03,0xf0,0x00,0x00,0x00,0x09,0x04,0x00,0x00,
0x09,0x04,0x00,0x00,0x55,0x53,0x41,0x00,0x55,0x6e,0x69,0x74,0x65,
0x64,0x20,0x53,0x74,0x61,0x74,0x65,0x73,0x00};
byte[] SID_AUTH_INFO = intToByte.getByteArray(intAr);
dosStream.write(SID_AUTH_INFO);
}
catch (Exception e)
{
closeConnection();
System.out.println("Trying to send 0x50... " + e);
}

}


}


public void closeConnection()
{
try
{
dosStream.close();
disStream.close();
client.close();
}
catch(Exception e)
{
System.out.println("Trying to close connection..." + e);
}
}

}
//--------------------------------------------------------------
import java.io.*;

public class BNC
{
public static void main(String[] args)
{

Connection cn = new Connection("asia.battle.net",6112);
DataInputStream inStream;
cn.sendPacket(0);
cn.sendPacket(50);

inStream = cn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
int inChar=0;
try
{
inChar = br.read();
}
catch(Exception e)
{
cn.closeConnection();
System.out.println("Trying to read initial char from input stream... " + e);
}
System.out.print(inChar+" ");
while(inChar != -1)
{
try
{
inChar = br.read();
}
catch(Exception e)
{
cn.closeConnection();
System.out.println("Trying to read char from input stream... " + e);
}
System.out.print(inChar+ " ");
}
}
        cn.closeConnection();
}
#4
Java Programming / Re: Sending a packet in java..
September 19, 2008, 04:22 PM
Can someone move this to java programming forum.. sorry  :-\
#5
Java Programming / Sending a packet in java..
September 19, 2008, 03:42 PM
Just started trying to make a b.net bot and am testing sending the SID_AUTH_INFO packet. I used ethereal to check what gets sent
and the data gets sent twice in same packet.. any one know why?
      (From ethereal)
XXXXXXXXXXXXXXXX ff 50 3a 00 00 00 00 00 36 38  .<.Y...P:.....68
58 49 50 58 45 53 d1 00 00 00 53 55 6e 65 c0 a8   XIPXES....SUne..
01 03 f0 00 00 00 09 04 00 00 09 04 00 00 55 53    ..............US
41 00 55 6e 69 74 65 64 20 53 74 61 74 65 73 00   A.United States.
ff 50 3a 00 00 00 00 00 36 38 58 49 50 58 45 53    .P:.....68XIPXES
d1 00 00 00 53 55 6e 65 c0 a8 01 03 f0 00 00 00    ....SUne........
09 04 00 00 09 04 00 00 55 53 41 00 55 6e 69 74   ........USA.Unit
65 64 20 53 74 61 74 65 73 00                            ed States.

Heres the relevant code ...

     (Sends the SID_AUTH_INFO packet {copied from ethereal})
...........................
ByteFromIntArray intToByte=new ByteFromIntArray(false);
int[] intAr = {0xFF,0x50,0x3a,0x00,0x00,0x00,0x00,0x00,0x36,0x38,
0x58,0x49,0x50,0x58,0x45,0x53,0xd1,0x00,0x00,0x00,0x53,0x55,0x6e,
0x65,0xc0,0xa8,0x01,0x03,0xf0,0x00,0x00,0x00,0x09,0x04,0x00,0x00,
0x09,0x04,0x00,0x00,0x55,0x53,0x41,0x00,0x55,0x6e,0x69,0x74,0x65,
0x64,0x20,0x53,0x74,0x61,0x74,0x65,0x73,0x00};
byte[] SID_AUTH_INFO = intToByte.getByteArray(intAr);
dosStream.write(SID_AUTH_INFO); (dosStream = DataOutputStream
....................
      (Taken from http://bnubot.googlecode.com/svn/trunk/BNUBot/src/org/jbls/util/ByteFromIntArray.java)
public byte[] getByteArray(int[] array) {
byte[] newArray = new byte[array.length];

int pos = 0;
for (int element : array) {
if (littleEndian) {
newArray[pos++] = (byte) ((element >> 0) & 0xFF);
newArray[pos++] = (byte) ((element >> 8) & 0xFF);
newArray[pos++] = (byte) ((element >> 16) & 0xFF);
newArray[pos++] = (byte) ((element >> 24) & 0xFF);
} else {
//newArray[pos++] = (byte) ((element >> 24) & 0xFF);
//newArray[pos++] = (byte) ((element >> 16) & 0xFF);
//newArray[pos++] = (byte) ((element >> 8) & 0xFF);
newArray[pos++] = (byte) ((element >> 0) & 0xFF);
}
}

return newArray;
}