Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Spilled on October 09, 2005, 11:30 PM

Title: [Java] 0x50 Complications
Post by: Spilled on October 09, 2005, 11:30 PM
Hi, in my first attempt to make a bot in java, i have ran into a problem. When i recieve 0x50, extracting the data from it has been harder then i thought and am seeking your help.

In VB i did this like so:

             Hashing.ServerToken = Val("&H" & Connection.StrToHex(StrReverse(Mid(strData, 9, 4))))
             Hashing.Hash = Mid(strData, 38, Len(strData) - 2)
             Hashing.MpqName = CStr(Mid(Mid(strData, InStr(1, strData, "IX86ver"), Len(strData)), 1, 12))


Is there an easier way then writing a reverse function and a strtohex function? What about the Val and the CStr? Any tips would be appreciated because I am kinda lost in this problem.

Spilled[DW]
Title: Re: [Java] 0x50 Complications
Post by: Joe[x86] on October 10, 2005, 12:33 AM
Uh, you're probably going to want to use a debuffer.

http://www.javaop.com/javaop2/src/javaop2_pub/src/util/BNetPacket.java
http://www.javaop.com/javaop2/src/javaop2_pub/src/util/Buffer.java

LoginType = packet.RemoveDWORD();
ServerToken = packet.RemoveDWORD();
UDPValue = packet.RemoveDWORD();
MPQFiletime = packet.RemoveQWORD();
MPQName = packet.RemoveNTString();
ValueString = packet.RemoveNTString();
Title: Re: [Java] 0x50 Complications
Post by: UserLoser. on October 10, 2005, 01:42 AM
Quote

Val("&H" & Connection.StrToHex(StrReverse(Mid(strData, 9, 4))))


wtf.  Do us all and your computer a favor by using memcpy/CopyMemory
Title: Re: [Java] 0x50 Complications
Post by: Joe[x86] on October 10, 2005, 07:15 AM
Oh god, didn't even notice that was a DWORD. =p
Title: Re: [Java] 0x50 Complications
Post by: Dynobird on October 10, 2005, 01:08 PM
Well, you could make a class for receiving 0x50, and have methods that return the bytes/words/dwords that you want to get from it because those methods will know the offset and length ints for your byte array.

Or you could have a generic packet debuffer class in which you give it a Packet or a byte array and call methods that take a given offset. You wouldn't need a length because you could have separate methods for getWord, getDword etc. and they will know the lengths.

~~

String to hex is simply...
String strToHex = new String();
byte strbytes[] = strToHex.getBytes();
the method returns a byte array

Conversion in Java isn't that hard, you should look at the api's
http://java.sun.com/j2se/1.5.0/docs/api/ search for String and you'll see the getBytes() method there.

Perhaps you should read a book on Java or OOP b/c its very different than VB.
Title: Re: [Java] 0x50 Complications
Post by: Spilled on October 10, 2005, 04:39 PM
Yea, i am currently reading a book on Java because we are taking it at my college. But anyways off that subject How would i load the checkrevision.dll library? would i use System.loadLibrary("CheckRevision.dll") ? And if this is how, how come i cant use the functions inside it? I try to but its not letting me.


static
{
System.loadLibrary("CheckRevision.dll");
}


Also is this how i would load the hashes? Thanks in advance!
Title: Re: [Java] 0x50 Complications
Post by: Dynobird on October 10, 2005, 05:40 PM
I don't know that much about the C family, but as I see it you're trying use the functions of .dll's in the Java file? Well, I don't know much about that. The weird thing about the System.loadLibrary() call is that it doesn't return anything. So I guess that it does the functions of the .dll itself... but you said you wanted to use the functions of the dll yourself inside your java class?

Here's another idea, you can make an .exe that does it for you, perhaps a VB .exe if you wish, b/c its easy to run exe's through Java. You use sun's Runtime class to do it.

Example:

Runtime cmd = Runtime.getRuntime();        // I don't think you can instantiate Runtime any other way, it's probably protected
cmd.exec("start DoCheckRevision.exe");


Hope that helps.
Title: Re: [Java] 0x50 Complications
Post by: Spilled on October 11, 2005, 12:18 AM
Any other ideas?
Title: Re: [Java] 0x50 Complications
Post by: Kp on October 11, 2005, 06:52 PM
Why're you loading a DLL?  That's inherently non-portable, which negates the primary benefit of writing this in Java.  Besides which, if that's the Blizzard CheckRevision DLL, it won't work for you anyway.
Title: Re: [Java] 0x50 Complications
Post by: Joe[x86] on October 11, 2005, 06:59 PM
Using a DLL in Java is possible, I think, but rather messy and totally distroys Java's main advantage, its cross-platformness. You can do it if you want, but I suggest recreating checkrevision (http://www.javaop.com/javaop2/src/BNetLogin/src/versioning/CheckRevision.java) in Java.

EDIT -
WAR3 Stuff (http://forum.valhallalegends.com/phpbbs/index.php?topic=8153.0)
Title: Re: [Java] 0x50 Complications
Post by: Spilled on October 12, 2005, 01:26 PM
Quote from: Joe on October 11, 2005, 06:59 PM
Using a DLL in Java is possible, I think, but rather messy and totally distroys Java's main advantage, its cross-platformness. You can do it if you want, but I suggest recreating checkrevision (http://www.javaop.com/javaop2/src/BNetLogin/src/versioning/CheckRevision.java) in Java.

EDIT -
WAR3 Stuff (http://forum.valhallalegends.com/phpbbs/index.php?topic=8153.0)

What variable does this CheckRevision return? The CheckSum or the Version ID?, and how would i get the other stuff that i need? Including the exeinfo and anything else i need? Please no flaming I have never worked with doing CheckRevision in any other language then VB, which is already provided by the dll and im eager to learn how to do it in Java. All help is appreciated!
Title: Re: [Java] 0x50 Complications
Post by: Hdx on October 12, 2005, 04:29 PM
Crev() return the checksum.
I will post info on how to get the exeinfo when i get home. And I'm not sure how to get the EXEVer automatically in java so I'm interested in this to.
~-~(HDX)~-~
Title: Re: [Java] 0x50 Complications
Post by: Spilled on October 12, 2005, 05:02 PM
ahh i c, Thanks again Hdx. Get back as soon as possible. :)
Title: Re: [Java] 0x50 Complications
Post by: Hdx on October 12, 2005, 06:09 PM
/** Compiles BNET Exe Info of a given game set
* @return Exe Info String
* @param files - file list
* */
    private static String getExeInfo(String[] files)
    {
        //return "starcraft.exe 03/28/03 04:21:56 1064960";

        File f = new File(files[0]);
       
        // Set up a calendar to point at the last modified time
        Calendar c = Calendar.getInstance();
        c.setTime(new Date(f.lastModified()));
       
        StringBuffer exeInfo = new StringBuffer();
       
        // Write to the exeInfo buffer
        exeInfo.append(f.getName()).append(" ");
       
        // date
        exeInfo.append(PadString.padNumber(c.get(Calendar.MONTH), 2)).append("/");
        exeInfo.append(PadString.padNumber(c.get(Calendar.DAY_OF_MONTH), 2)).append("/");
        exeInfo.append(PadString.padNumber((c.get(Calendar.YEAR) % 100), 2)).append(" ");
       
        // time
        exeInfo.append(PadString.padNumber(c.get(Calendar.HOUR_OF_DAY), 2)).append(":");
        exeInfo.append(PadString.padNumber(c.get(Calendar.MINUTE), 2)).append(":");
        exeInfo.append(PadString.padNumber(c.get(Calendar.SECOND), 2)).append(" ");
       
        // size
        exeInfo.append(f.length());
       
        return exeInfo.toString();
    }

Code was writtin by iago, It's part of many open source programs so He shouldn't have a problem with you using it. you need his PadString (http://hdx.no-ip.org/files/PadString.java) class. It jsut makes life easier >.<
Also as for the ExeVer I beleave you can set it to null due to Macs not having the proper functions to get it.
~-~(HDX)~-~
Title: Re: [Java] 0x50 Complications
Post by: Spilled on October 12, 2005, 11:18 PM
o, nice nice Thanks HdX and Thanks iago i  hope you dont mind ;)

Hrmm now what about the Bnetauth class and the hash class? Anyone mind helping me with those functions? Thanks in advance!