• Welcome to Valhalla Legends Archive.
 

Bot basics (Java)

Started by mirza911, December 20, 2009, 06:26 PM

Previous topic - Next topic

mirza911

I am very new to bot making but i am pretty comfortable with java and i want to try to write a simple bot in java just to get the feel for it. I have been using bnetdocs, wireshark, and d2 smells to see the communication between battle.net and my computer. but the basics of a bot are still very hard for me to grasp.

-I need some advice on how to take the data from the bnet and read it.
-I need advice on how to send the proper packet back.
-With a packet there is so much to look at. I don't know which part is the most important to me and what i need to modify and send back.

This is the code i found online and added a couple things to it. I just want to try to send the first packet successfully.

import java.net.InetAddress;

import jpcap.*;
import jpcap.packet.EthernetPacket;
import jpcap.packet.IPPacket;
import jpcap.packet.Packet;
import jpcap.packet.TCPPacket;

class SendTCP
{
    public static void main(String[] args) throws java.io.IOException
    {
        NetworkInterface[] devices = JpcapCaptor.getDeviceList();
        if (args.length < 1)
        {
            System.out
                    .println("Usage: java SentTCP <device index (e.g., 0, 1..)>");
            for (int i = 0; i < devices.length; i++)
                System.out.println(i + ":" + devices.name + "("
                        + devices.description + ")");
            // System.exit(0);
        }
        int index = Integer.parseInt(args[0]);
        JpcapSender sender = JpcapSender.openDevice(devices[index]);

        TCPPacket p = new TCPPacket(50371, 6112, 1, 1, false, true, true,
                false, false, false, false, false, 16896, 00);
        p.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0,
                1010101, 128, IPPacket.IPPROTO_TCP, InetAddress.getLocalHost(),
                InetAddress.getByName("useast.battle.net"));
        byte[] by = new byte[]
        { (byte) Integer.parseInt("01", 16) };
        p.data = by;

        EthernetPacket ether = new EthernetPacket();
        ether.frametype = EthernetPacket.ETHERTYPE_IP;
        ether.src_mac = new byte[]
        { (byte) 0, (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
        ether.dst_mac = new byte[]
        { (byte) 0, (byte) 6, (byte) 7, (byte) 8, (byte) 9, (byte) 10 };
        p.datalink = ether;

        for (int i = 0; i < 1; i++)
            sender.sendPacket(p);
        sender.close();
        System.out.println("done");
        return;
    }
}

I would be happy with just a logon bot.
Any help will be appreciated.

Hdx

Why are you using jpcap?
Just use standard java sockets.
http://java.sun.com/j2se/1.4.2/docs/api/java/net/Socket.html
http://java.sun.com/docs/books/tutorial/networking/sockets/
Bnet docs describes the protocol, and what to send.
If you're looking for code handouts, JavaOp is open source, but you can just use it, you don't need to make your own.

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

mirza911

i tried getting javaop but all the links on the javaop homepage dont work. with mozilla or IE.

i thought jpcap would be more useful though why should i just use java sockets?

Also the whole bot thing. Will diablo know how to act based on the packets i send or do i need to send packets and still click on things and type things etc etc.?

Hdx

Are you trying to 'hack' Diablo II?
AE, attach it to it while you're in game?
jpcap is for (i assume) capturing packets that other processes are sending/receiving. I think it's the java equivalent of PCap.
What EXACTLY are you wanting to do?

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

mirza911


Hdx


Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

mirza911

well the main goal would be something like a gambling bot or mf bot but right now i want to start small to get the feel for it. something like a log in bot.

Hdx

Well, it's rather difficult, pretty much impossible for you to write a bot that would do mf runs or anything.
But look at those two links i sent you
and learn the basics of sockets before you try anything else.

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

mirza911

do you mean just for me because i am so inexperienced? or for anyone?
Why exactly is it so impossible?

Hdx

#9
Few reasons, bust mainly because you're way to inexperienced.
To do a gambling or MF bot, you need to not only understand network programming, you also need to know how to read map files from D2. As well as different types of compression formats (namely huffman, for d2 in-game) Not to mention that quite a bit of things in D2 are not publicly documented, you can thank Ringo and a few others for what is known. (Quite a bit, but i think its outdated)

Do you know anything about network connections, or binary protocols?
Also, Java won't be able to actually hook into Diablo II, so you can't even be lazy, and make the game do most the work for you.

Start by making a basic text based server that echos things back and forth.
Then turn it into a basic binary protocol
Then you can start work on a bnet bot using BNLS because it does 90% of the hard stuff for you
Then work on doing things locally
Then work on in-game protocols.
THEN! once you get something in game and talking, you can work on doing specific things like ganbeling and stuff. BUT! Not many people will help you for that specific thing, because it's pretty much cheating, and ya, not a good thing here.

By the way, wtf is this?
{ (byte) Integer.parseInt("01", 16) };, Why not do (byte)1

I mean I *could* hand you the code that would connect you to Bnet and make it easy on you, But why? If you actually give a shit, you'll work and understand whats going on. Its NOT hard if you know the basics. B.net's protocol is really really simple. But if I were to ask you to show me the hex for the DWORD 0x010203 in network byte order, what would you show me?

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

mirza911

would the hex not just be 01 02 03 ? since that would be big-endian. And i am not sure that would just be my guess from what i've read up on it from the newcomers sticky.

I really appreciate you posting though and explaining what you have to me.

Hdx

Yes, network byte order is big-endian, but, it would actually be: 00 01 02 03 As DWORDs are 32-bit integers (when referring to almost any system)
Let me know when you've made a echo server/client.
And I'll help you with understanding binary protocols.

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

mirza911

right that makes sense.  but in little endian would that be 03 02 01 00 or 00 03 02 01?

Hdx

03 02 01 00
Most everything Battle.net related (and once again almost everything else) is little endian
With the exception of IP/Port information in the protocol.

But ya, get crackin on learnin to use sockets.
If you try hard should take you like.. a day. :P

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

mirza911

alright i got an echo server working. and its sending back whatever i send it. so thats why i assume its working...  :) . how can i "learn" to use them?