Author Topic: [Python] Packetbuffer  (Read 15926 times)

0 Members and 3 Guests are viewing this topic.

Offline igimo1

  • Full Member
  • ***
  • Posts: 420
    • View Profile
[Python] Packetbuffer
« on: May 23, 2006, 08:13:28 pm »
Quote
#packet buffer

__author__ = 'topaz'
__copyright = 'BSD License'

import string
import struct
import main

class pBuffer:

    def __init__(self):
        self.buffer = list()
        #declares self.buffer as a list
   
    def insertData(self, data):
        self.buffer.append(data)

    def insertInteger(self, data):
        if string.isdigit(data) == false:
            return
        else:
            data = struct.pack('I', data)
                #converts data into unsigned int and adds it into the buffer
                #converting integers into dwords/words is unnecessary, so we
                #simply pack it and append it
            self.buffer.append(data)

    def insertIntegerList(self, data):
        if string.isdigit(data) == false:
            return
        else:
            self.buffer.append('%s' %data)
            #adds a list of integers into the buffer

    def insertString(self, data):
        self.buffer.append(data)

    def insertNTString(self, data):
        self.buffer.append('%s.' % data)
        #adds string into buffer with a null terminator

    def makeInteger(self, data):
        data = struct.pack('I', data)

        return data
   
    def strToHex(self, data):
        data = data.encode('hex')

        return data
       
    def makeLong(self, data):
        data = struct.pack('L', data)
        #convert data into a Long and return it

        return data
   
    def hexToStr(self, data):
        data = data.decode('hex')
        #decodes data back into string and returns it

        return data

    def GetDWORD(self, data):
        #transform data into an integer and return it
        data = int(data)

        return data
       
    def GetWORD(self, data):
        data = int(data)

        return data

    def insertBYTE(self, data):
        data = Chr(data)
        #convert data into byte format and return it

        self.buffer.append(data)
   
    def sendPacket(self, packetID):
        main.transport.write(self.buffer)

        clear()

    def clear(self):
        #clears the buffer
        self.buffer[:] = []

Updated code.
« Last Edit: May 24, 2006, 12:08:40 pm by Topaz »

Offline GameSnake

  • News hound
  • Hero Member
  • *****
  • Posts: 2937
    • View Profile
Re: [Python] Packetbuffer
« Reply #1 on: May 24, 2006, 10:54:24 pm »
I'm a Python developer. I tried this code out in the Python IDLE GUI along with a homemade structure code and it works suprisingly well.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [Python] Packetbuffer
« Reply #2 on: May 24, 2006, 11:03:03 pm »
I'm a Python developer. I tried this code out in the Python IDLE GUI along with a homemade structure code and it works suprisingly well.

It's . . . 200 lines, tops?  Unless you lack simple analsys skills, I don't see how it would be that surprising.

What did you mean by "surprising," anyway?  Are you being condescending? :P

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [Python] Packetbuffer
« Reply #3 on: May 24, 2006, 11:18:26 pm »
I'd be interested in seeing a bot written in Python. I've never used the language - does it have a nice API including networking stuff as well, or is it more like Brainfuck where you have nothing at all?
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline GameSnake

  • News hound
  • Hero Member
  • *****
  • Posts: 2937
    • View Profile
Re: [Python] Packetbuffer
« Reply #4 on: May 24, 2006, 11:24:59 pm »
I'd be interested in seeing a bot written in Python. I've never used the language - does it have a nice API including networking stuff as well?
Yes. Although a little outdated, Python is a simple yet powerfull language. If your interested, $t0rm has made a bot using Python before, the only problem is the GUI, you need another program that can interface python with a GUI.
I'm a Python developer. I tried this code out in the Python IDLE GUI along with a homemade structure code and it works suprisingly well.

It's . . . 200 lines, tops?  Unless you lack simple analsys skills, I don't see how it would be that surprising.

What did you mean by "surprising," anyway?  Are you being condescending? :P
Condecsending, you never know with Topaz, I was just confirming to everyone that the code does work ;). It is rare to find Python code in bot development
« Last Edit: May 24, 2006, 11:31:28 pm by GameSnake »

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [Python] Packetbuffer
« Reply #5 on: May 24, 2006, 11:44:30 pm »
Condecsending, you never know with Topaz, I was just confirming to everyone that the code does work ;). It is rare to find Python code in bot development

Your response either convoluted or nonsensical. :P

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [Python] Packetbuffer
« Reply #6 on: May 25, 2006, 12:05:43 am »
This is cool,

anyone ever done a bot in python or something like that? i'd be interested in learning it

Yes. Although a little outdated, Python is a simple yet powerfull language. If your interested, $t0rm has made a bot using Python before, the only problem is the GUI, you need another program that can interface python with a GUI.
Quote from: Sidoh link=topic=5956.msg70889#msg70889
[/quote

I'm pretty sure I know the storm he's talking about.  Is this the same one that uses coldfusion a lot and hates PHP?  I work for a guy he used to work for.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [Python] Packetbuffer
« Reply #7 on: May 25, 2006, 11:49:05 pm »
You have some fubared quote tags, Sidoh.

Linkage, GameSnake? I don't plan on using it, of course, but I thought I'd be interesting.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline GameSnake

  • News hound
  • Hero Member
  • *****
  • Posts: 2937
    • View Profile
Re: [Python] Packetbuffer
« Reply #8 on: May 26, 2006, 02:20:50 pm »
You have some fubared quote tags, Sidoh.

Linkage, GameSnake? I don't plan on using it, of course, but I thought I'd be interesting.
python.org

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [Python] Packetbuffer
« Reply #9 on: May 27, 2006, 01:17:01 pm »
I meant his bot. =p
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline GameSnake

  • News hound
  • Hero Member
  • *****
  • Posts: 2937
    • View Profile
Re: [Python] Packetbuffer
« Reply #10 on: May 28, 2006, 12:32:03 am »
I meant his bot. =p
Ask him for it.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [Python] Packetbuffer
« Reply #11 on: May 29, 2006, 02:13:47 am »
I don't know storm.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline igimo1

  • Full Member
  • ***
  • Posts: 420
    • View Profile
Re: [Python] Packetbuffer
« Reply #12 on: July 12, 2007, 11:50:52 pm »
This code sucks, much more elegant if the code is geared towards a purpose, ie parsing incoming data;

Code: [Select]
import struct

def unpack_dword(data):
    return struct.unpack('I', data)[0]

def unpack_word(data):
    return struct.unpack('H', data)[0]

def unpack_byte(data):
    return struct.unpack('<B', data)[0]

class recv_buffer:
    def __init__(self, raw_buffer):
        self.raw_buffer = raw_buffer
        self.position = 0

    def jump(self, bytes):
        self.position += bytes

    def back(self, bytes):
        self.position -= bytes

    def set_position(self, position):
        self.position = position

    def next_string(self):
        pos = self.raw_buffer.find(chr(0), self.position)
        string = self.raw_buffer[self.position:pos]

        self.set_position(pos + 1)
        return string

    def next_byte(self):
        param = self.raw_buffer[self.position:self.position + 1]
        byte = unpack_byte(param)

        self.jump(1)
        return byte

    def next_dword(self):
        param = self.raw_buffer[self.position:self.position + 4]
        dword = unpack_dword(param)

        self.jump(4)
        return dword

    def next_word(self):
        param = self.raw_buffer[self.position:self.position + 2]
        word = unpack_word(param)

        self.jump(2)
        return word

    def next_dword_list(self, size):
        dword_list = []

        for i in xrange(size):
            dword_list.append(self.next_dword())

        return dword_list

    def next_data(self, bytes):
        return self.raw_buffer[self.position: self.position + bytes]

    def dump_data(self):
        self.raw_buffer = ""

Much shorter, too, unlike the code from a good year ago

I'd be interested in seeing a bot written in Python. I've never used the language - does it have a nice API including networking stuff as well, or is it more like Brainfuck where you have nothing at all?

Python is very easy to learn (I've seen users dub it "visual basic 2", or some other clever nick). The stdlib is huge, much like Java's. There is a significant amount of networking modules built-in.

The bot has been available for some time. I ran into some phantom bugs while I was working on it, but it has enough done that it should be easily completed. In fact, some leech even thought it complete enough to use and plaster his name on it without giving credit.
« Last Edit: July 13, 2007, 03:27:18 am by Topaz »

Offline warz

  • Hero Member
  • *****
  • Posts: 1134
    • View Profile
    • chyea.org
Re: [Python] Packetbuffer
« Reply #13 on: July 13, 2007, 02:59:36 am »
Python is not even comparable to Brainfuck - who asks that?

topaz, continue searching for slaughter.. maybe check our irc network again - wait, you can't roflmaomfommaomrfolol
http://www.chyea.org/ - web based markup debugger

Offline igimo1

  • Full Member
  • ***
  • Posts: 420
    • View Profile
Re: [Python] Packetbuffer
« Reply #14 on: July 13, 2007, 03:26:47 am »
Are you sure?

Offline warz

  • Hero Member
  • *****
  • Posts: 1134
    • View Profile
    • chyea.org
Re: [Python] Packetbuffer
« Reply #15 on: July 13, 2007, 03:28:04 pm »
Are you sure?

lorloflromaoroflamololmaomalhaha
http://www.chyea.org/ - web based markup debugger

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: [Python] Packetbuffer
« Reply #16 on: July 13, 2007, 10:55:36 pm »
So..someone leached your code and licensed it under GPLv2? Fucking FSF
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline igimo1

  • Full Member
  • ***
  • Posts: 420
    • View Profile
Re: [Python] Packetbuffer
« Reply #17 on: July 13, 2007, 11:13:01 pm »
So..someone leached your code and licensed it under GPLv2? Fucking FSF

This is correct - the dummy even left a couple lines that indicated the real author in the source. Sigh.

Offline wires

  • Pwnage
  • x86
  • Hero Member
  • *****
  • Posts: 1103
  • cocaine is fun!
    • View Profile
    • Weapon Of Mass Destruction
Re: [Python] Packetbuffer
« Reply #18 on: July 13, 2007, 11:16:25 pm »
So..someone leached your code and licensed it under GPLv2? Fucking FSF

This is correct - the dummy even left a couple lines that indicated the real author in the source. Sigh.
LOL

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: [Python] Packetbuffer
« Reply #19 on: July 14, 2007, 12:51:07 am »
So..someone leached your code and licensed it under GPLv2? Fucking FSF

This is correct - the dummy even left a couple lines that indicated the real author in the source. Sigh.

Fairly certain you can complain to google to have it taken down.
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: [Python] Packetbuffer
« Reply #20 on: September 04, 2007, 12:59:43 pm »
Python is not even comparable to Brainfuck - who asks that?

topaz, continue searching for slaughter.. maybe check our irc network again - wait, you can't roflmaomfommaomrfolol

Code: [Select]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++.-.+.-------.+++++++++++++.------------------
-----------------------------------------------------------.------------.+++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.-
-------------.+++++++++++++++.--------------------------------------------------
-----------------------------------.++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++.+..-------------.
« Last Edit: September 04, 2007, 01:05:27 pm by Camel »

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline Explicit

  • Hero Member
  • *****
  • Posts: 717
  • Hail Bender!
    • View Profile
Re: [Python] Packetbuffer
« Reply #21 on: September 04, 2007, 09:09:45 pm »
Python is not even comparable to Brainfuck - who asks that?

topaz, continue searching for slaughter.. maybe check our irc network again - wait, you can't roflmaomfommaomrfolol

Code: [Select]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++.-.+.-------.+++++++++++++.------------------
-----------------------------------------------------------.------------.+++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.-
-------------.+++++++++++++++.--------------------------------------------------
-----------------------------------.++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++.+..-------------.

It takes forever to even get a "Hello, world!" application compiled and running with BF, that is, if you're actually attempting to write it yourself.  :P
Quote
Like all things in life, pumping is just a primitive, degenerate form of bending.

Quote
Hey, I don't tell you how to tell me what to do, so don't tell me how to do what you tell me to do! ... Bender knows when to use finesse.

[13:41:45]<@Fapiko> Why is TehUser asking for wang pictures?
[13:42:03]<@TehUser> I wasn't asking for wang pictures, I was looking at them.
[13:47:40]<@TehUser> Mine's fairly short.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [Python] Packetbuffer
« Reply #22 on: September 04, 2007, 11:12:31 pm »
I just don't understand why anyone uses anything other than LOLCODE.  I mean, seriously, who doesn't like to giggle at internets memes while they're programming?

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: [Python] Packetbuffer
« Reply #23 on: September 05, 2007, 09:53:59 am »
So..someone leached your code and licensed it under GPLv2? Fucking FSF

This is correct - the dummy even left a couple lines that indicated the real author in the source. Sigh.

Fairly certain you can complain to google to have it taken down.

I'm fairly certain a cease and desist would not be uncalled for. Complaining is easier though.

Then again, can you really take a project at SVN revision 7 seriously anyways?

It takes forever to even get a "Hello, world!" application compiled and running with BF, that is, if you're actually attempting to write it yourself.  :P

Are you serious? Writing a BF interpreter is easy. Writing a BF generator is easy too.

Code: [Select]
char b[MEMORY_SIZE];
char *p = &b;
int main() {
while(true) {
char c = getch();
if(c == EOF)
return 0;
switch(c) {
case '+': *p++; break;
case '-': *p--; break;
case '>': p++; break;
...
}
}
}

Here's the modified code from ABF I used to generate the above BF code. I'd have converted it to C, but that would have required reading that god awful C++ code, so I just left it in.
Code: [Select]
/*
 * Read string from standard input and convert to Brainfuck.
 */

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char** argv)
{
vector<string> stringvec;

for (string tmp; getline(cin, tmp);) {
stringvec.push_back(tmp);
}

int i = 0;
for (vector<string>::const_iterator oit = stringvec.begin();
oit != stringvec.end();
++oit) {
for (string::const_iterator iit = oit->begin();
iit != oit->end();
++iit) {
for (; i < *iit; ++i)
cout << "+";
for (; i > *iit; --i)
cout << "-";
cout << ".";
}
cout << endl;
}
}
« Last Edit: September 05, 2007, 10:05:36 am by Camel »

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [Python] Packetbuffer
« Reply #24 on: September 05, 2007, 10:18:43 am »
I don't see a license on the source files, so there's no way you could force them to give credit. Next time, if you want credit, give it a BSD-style license.

Personally, I release code under an a public domain license, and I tell people who use it that they don't have to give me credit, but it's nice if they do.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: [Python] Packetbuffer
« Reply #25 on: September 05, 2007, 10:25:54 am »
I use GPL v2 because it was the first option in the drop-down when I created the Google Code project.

Honestly, I've never even read it. I do know, however, that it's infectious. That is to say, if you use any GPLv2 code, the modules that include the GPLed code have to be released with the same license.

iago, what's the difference between the license you use and no license at all?

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [Python] Packetbuffer
« Reply #26 on: September 05, 2007, 11:55:06 am »
There is no difference, actually. Mine's just spelling out, clearly, that there is no license.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: [Python] Packetbuffer
« Reply #27 on: September 05, 2007, 01:00:45 pm »
Then why, I must ask, don't you at least insist that you receive credit for your work? I'm completely in support of free OSS (open-source software), but when I say free I mean gratis, not libre. I believe that the majority of the people who use libre OSS and do not turn around and release their own software have an overall negative impact on the software community. There isn't any way to gauge this impact, so it's entirely a matter of opinion, but I can think of several examples that support my case.

The whole philosophy behind OSS is essentially communism -- that's bad for governments, but good for software; by contributing, you are making the software world a better place. By using free OSS, but not returning the favor, one is simply exploiting the system. It's embezzlement, plain and simple.


Discuss.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [Python] Packetbuffer
« Reply #28 on: September 05, 2007, 01:16:57 pm »
Not communism, socialism. Communism was a special form of socialism that sucked it up.

Personally, the code I write is for my own use. I want something, so I write it. I figure that if other people want to benefit from what I write, let 'em. I don't care if they're individuals or corporations or whatever.

There are cases, like the Lockdown code, where I use a stricter license because I know that others will want to use it, and it was a significant amount of work. On Lockdown I used a BSD-style license.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: [Python] Packetbuffer
« Reply #29 on: September 05, 2007, 02:02:36 pm »
I don't see how the distinction between communism and socialism applies to software. Explain?

I remember being asked to help someone debug a problem with their battle.net bot once. They send me a ZIP file with the source code inside of it. When I opened it, I was shocked to find that roughly half of the code inside was identical to the code in my bot - and it wasn't just the large amount of code I'd released to the public domain primarily on the vL forums and in other various places. Modules were not even renamed; often, I add comments with links and credits in my code, and those were all removed. There was no credit given to anyone; in fact, the owner claimed that the bot was a completely original work, from the ground up.

After I called him on it, he admitted that he had started from a barebones bot project, and modified it so that his name replaced the author - let's call him "(2xX)j0ke" to protect his identity. Way back in the day, j0ke and I were working on a project together, but it didn't last long. He kept a lot of the work I'd done, which was fine with me. The problem was that he turned around and handed it off without asking for my permission, or even acknowledging that I'd contributed.

It's infuriating to know that I spent years testing, debugging, and even learning how to do all of the things I'd done for that project, and that someone just passed it off without even a thought of where it came from. The worst part of all was that I'd contributed to what later became the first starcraft win bot.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [Python] Packetbuffer
« Reply #30 on: September 05, 2007, 02:20:24 pm »
I'm not qualified to compare communism and socialism, but I've been assured by reliable sources that using the term "communism" for opensource is incorrect.

As for the rest, I personally wouldn't care. If c0ke, err, j0ke used my code without acknowledging me, it wouldn't matter. I encourage people to give credit, but I don't demand it. The way I see it, I wrote the code for my own purposes, and the fact that he's using it doesn't change that.

I suppose to find the reason, you have to look back to your motivations for writing the code in the first place. If you're like me, you're writing the code for your own personal use and you don't care past there. Some people write code as a way of getting respect, the whole "I can do this better than you!" attitude. I can think of a few people (mostly around vL forums) that fit into that 100%. Then there's the financial motivation, but I don't think that's common in the botdev community.

But out of those three motivations, I think most people are a mixture. I'm almost totally on the "personal use" thing, which is why I don't care if people use my work without credit.

At least, that's the way I see it. :)

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: [Python] Packetbuffer
« Reply #31 on: September 05, 2007, 03:24:50 pm »
It'd be different if I released the code in to the public domain, but it wasn't anything I'd intended to release. One of the driving factors for making my current bot open-source was that it encourages keeping the code clean. If I'd foreseen what happened, I would have paid more attention to details, so at least the people receiving the stolen code would have a chance of comprehending it.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!