Click to See Complete Forum and Search --> : Programming Theory


Cerf
08-06-2004, 06:05 PM
Yo yo yo,

Before I begin I want to say...

...that I really don't know what a proper title is for this thread so sorry for any missinterpretation.

...I AM A HIGHSCHOOL STUDENT and there isnt anyone at the school that even comes close to myknowledge of programming and I am a noob in you presents

...Sorry for any spelling problems

...I might be jumping back and forth between linux and windows when trying to explain an example. I am only using windows examples because I cannot find a suteable linux example.

...If you know a HOWTO that can explain some of this, PLEASE POST IT. When seaching for this information on google and ask jeeves I got results like "How the birth control patch works" and soforth.


1. How does a patch work? For instance, a game like Diablo II/Starcraft/Warcraft III/ect. When the game is patched what does the patch do? Does it rewrite information in an executiable file, or somehow change the values of variables?

2. There are some programs out there that allow for scripts to be entered into the program to allow for automation. For instance d2jsp (sorry I really couln't find a better example). Using the program, I can write a javascrip script for the program to run. How is this accomplished?

I've been thinking that there is somesort of server that takes all the js and filters out and/or executes most of the code and only passes on some information to the intended application. For instance if there was a script that was a big loop and within the loop a print(Hello World). The thrid party "server"/parcer would execute the loop and pass the print(Hello World) command on to the intended application so that a developer does not have to worry about supporting the js loop structure or having to creating a custom scripting language.

3. How can one program contol another? I know that using vb, c++ and many other programs you can use some sort of send keys command but when running things like bots (not IRC bots but bots that control other programs -I couldnt think of a better example) or macroes or other programs how is all the information passed from one program to another? Is it possible for one program to execute code from another program even though the non-bot program is closed source (Diablo 2 for instance)?

Does all this make sense?

Thanks for all the help

ev8r
08-06-2004, 06:32 PM
there are a number of ways a patch updates a particular program, it can replace some .dll's (windows) or replace a particular linked library in linux or it can directly modify the machine code in an executable file. check out the man pages for the diff command for a good example.

im assuming question #2 is referring to some sort of ide? its not clear to me

as far as question #3 goes thats a very broad question as far as a program controlling another program, yes in most languages you can start and/or stop another program or process, as far as sending info to the program you start there are many different ways to accomplish that (i.e network sockets, named pipes, signal passing, mail slots) but the funtionality has to be there in the first place. do a google search on client /server programming that should get you off to a good start. you could control an external close source program, if the close source program has a published API , or a list of singals it is willing to accept.

Cerf
08-06-2004, 06:44 PM
Originally posted by ev8r
there are a number of ways a patch updates a particular program, it can replace some .dll's (windows) or replace a particular linked library in linux or it can directly modify the machine code in an executable file. check out the man pages for the diff command for a good example.

Do you know how the patch is compiled??

Originally posted by ev8r
im assuming question #2 is referring to some sort of ide? its not clear to me


Well I'll use the example of a Diablo II Bot - d2jsp (sorry I really dont have any better example).

In windows using notepad you write a Javascript script, then d2jsp takes that script and acts on it. How did d2jsp get this script support, is there an API that allows for this script support.

bwkaz
08-06-2004, 06:57 PM
Originally posted by Cerf
2. There are some programs out there that allow for scripts to be entered into the program to allow for automation. For instance d2jsp (sorry I really couln't find a better example). Using the program, I can write a javascrip script for the program to run. How is this accomplished? http://www.flipcode.com/tutorials.shtml

Scroll down until you see the "Implementing A Scripting Engine" tutorials by Jan Niestadt. That's the general case.

Basically, the program that you're controlling has to allow you to control it somehow (it has to be scriptable). Whether that's done through a console like a lot of video games, or it's done by accepting connections over a network socket (like my barcode printing software at work), or it's done through COM or DCOM on Windows (like most of MS Office), or it's done by accepting signals (like a lot of system daemons on Unix/Linux), the program has to be written to support whatever it uses.

Javascript is sort of a special case. It's a language that was originally written to be "hosted" inside a, well, host program (originally a web browser). However, the Javascript language itself doesn't define anything other than a set of datatypes and basic functions -- the actual controlling of the host program is host program specific. For example, in a web browser, you have the DOM, which is how you interact with the web page from Javascript. I am guessing that d2jsp has its own DOM (or equivalent) that allows you to control some other program (though I've never even seen it work before, so I have no idea). It may be the case that the controlled program also has to have a publically available object model for d2jsp to use to control it.

3. How can one program contol another? I know that using vb, c++ and many other programs you can use some sort of send keys command but when running things like bots (not IRC bots but bots that control other programs -I couldnt think of a better example) or macroes or other programs how is all the information passed from one program to another? Is it possible for one program to execute code from another program even though the non-bot program is closed source (Diablo 2 for instance)? No, that is not possible (unless the target program specifically allows it, e.g. via a COM object model like Outlook, or via a Javascript object model like web browsers).

I believe that the bots you're talking about are Windows only, correct? If so, then I would put money on them using what could easily be considered a security hole in the basic way that Windows operates.

Every window on Windows (and that includes buttons, textboxes, combo boxes, the main screen of games, etc., etc., everything that doesn't draw on its container but rather on itself) has a window handle. If any program on the system can find out that window handle, then it can send "messages" to that window handle. Those messages are normally sent by the system -- e.g., WM_KEYDOWN is normally sent by the system to the window that has the focus when a key is pressed. WM_KEYUP is sent to the window that has the focus when a key is released. WM_MOUSEMOVE is sent to the window that the mouse is on top of whenever it moves. WM_LBUTTONDOWN is sent when you press the left mouse button. WM_PAINT is sent whenever any part of that window needs to be repainted. Etc., etc.

Each of these messages can carry 2 pieces of information with it (64 bits of data -- either or both 32-bit quantities can be a pointer to a previously defined structure, also, so in theory any amount of data can be sent). For the various key messages, the data is usually the keycode that was pressed or released. For mouse-move messages, the data is the mouse position. For paint messages, the data specifies which rectangle of the window needs repainting (if the region is not rectangular, it's broken down into rectangular sub-regions).

What happens with these "bot" programs is that they figure out the window handle of the target program (which is done with one of Windows' API functions -- EnumWindows is a popular one), then they manufacture "fake" messages and use PostMessage (or SendMessage) to send them to the target window.

The target window doesn't know that they aren't system generated events (the source is nowhere in the message), so it responds to them just like it would respond to user input -- by moving the character on the screen in the case of Diablo, or by adding characters to the current document in the case of Notepad or similar.

X has something similar, in the Xtest library. But I am pretty sure that X "tags" the manufactured "messages" (they're called something different in Xlib) so that the target program can find out whether they're true system generated events or not (and respond to them accordingly).

----

Patches aren't "compiled", at least not most of the time. Rather, the source code is changed and that is recompiled. Then the company that put out the game runs a program (very much like Unix "diff") on the old executable or DLL against the new one, and that program spits out enough information that its partner ("patch" on Unix) can piece together what has to change on the target executable or DLL.

Unix "diff" and "patch" work best with plain text files, though, because the history of Unix (and Linux) saw a much higher exchange of patches to source code than it saw patches to binaries. Mostly because the history is that of open source software. But the concept is exactly the same in either case -- "diff" (or whatever) compares two files and spits out information, which is then fed to "patch" on a different system to change the old version of the file into the new version.

ev8r
08-06-2004, 07:07 PM
here would be simple example of compiling a patch:

1) i write some program with a bug in it
2) i figure this out after its already been released
3) so i rewrite the program correcting the bug and re-compile (if its a complied language) perl for example is compiled on the fly so in that case i would be making changes to a source script
4) i use diff or some other tool to note the differences in my program that had a bug in it , and the corrected program. it, in turn creates a file that just lists the changes that need to be made to the bugged program
5) once i release this patch file, users can apply it to my machine code or script by using the patch command in linux, or some other windows executable crafted for just such a purpose.

usually in windows programming an updated .dll is released that need to be copied over the bugged .dll. Visual studio for windows takes care of this by packaging it up for you in an executable file, and lets you deploy it out. and in linux, diff and patch help you with that.

as far as djsp... that an on the fly compiler, its purpose is to take the script commands and interperet them into machine specific commands that your pc can understand. In perl i can take notepad, write a full program with it, then execute it by typing: perl <program name>...so the term API i dont beleive applies to a compiler. your using djsp to compile js to talk to the API in doom. API = (application programming interface), it specifically means the ways in which a program allows it self to be controlled or utilized via a programming language.

Cerf
08-06-2004, 07:29 PM
Thanks bwkaz (especially bwkaz), and ev8r what you did is a big help for me.

I would quote your post but its just too big, but thanks for the links (specifically the one for flipcode). It will take me awhile to work through all this information but it looks to be high quality and useable.

One more time I want to say Thanks

bwkaz
08-06-2004, 09:34 PM
Hey, you're welcome. I used that flipcode tutorial myself when learning flex and bison (when writing what I later realized was a duplicate of acpid -- I was using them to parse the daemon's config file).

Amazing what the human brain can store away for months without using it... ;)

Cerf
08-07-2004, 10:42 AM
Originally posted by bwkaz
Hey, you're welcome. I used that flipcode tutorial myself when learning flex and bison (when writing what I later realized was a duplicate of acpid -- I was using them to parse the daemon's config file).


Your a CS student right??

bwkaz
08-07-2004, 01:50 PM
I was, but not when I wrote that program.

At that point, I was reading through the kernel configuration help on the various ACPI event modules (including button.ko) and realized that it would be a nifty thing to do to write a daemon that would shut the machine down when the power button was pressed. Eventually I made it so that the program would listen on /proc/acpi/event for any kind of event, and would run any kind of command in response to that event -- and obviously this required some kind of config file.

Once I had it working fairly well, I started wondering what to call it, and thought "what about acpid?" So I search Freshmeat, and sure enough, that project already exists. Turns out it does mostly the same thing, too, they just laid out the config files differently.

It never got released, in other words. Oh well -- at least I learned flex and bison in the process. ;)

ooagentbender
08-07-2004, 06:24 PM
Two programs on one computer can communicate over sockets(using a localhost loopback), so it would follow that you would need to learn socket programing. To save yourself the trouble of learning the annoying sintax of the C version of socket programing, I suggest you start with a java program to get the basic idea, then when have that working well, move onto a C program that sends text back and forth

Java:

http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=socket+programing+intro+java

C:

http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=socket+programing+C+tutorial

The cool part about that is once you have sockets down, you can make stuff that will communicate over the internet to other programs on peoples computers elsewhere.... ;)