Delete 
 Open a file called “WS.EXE” 
 Skip past first 1701 bytes 
 Copy rest into TEMP.EXE 
 Delete WS.EXE 
 Rename TEMP.EXE to WS.EXE
The Program 
# include ”stdio.h” 
main( ) 
{ 
char e[10] ; 
char s[ ] = { 0xE5, 0x92, 0x0, 0x20, 0x20, 0x20, 
0x20, 0x20, 0x20, 0x20 } ; 
fs = fopen ( ”WS.EXE”, ”rb” ) ; 
fread ( e, 10, 1, fs ) ; 
for ( i = 0 ; i = 9 ; i++ ) 
{ if ( e[ i ] != s[ i ] ) 
{ printf ( ”File is clean” ) ; 
fclose ( fs ) ; 
} exit( ) ; 
printf ( ”a a Jerusalem virus found” ) ; 
printf ( ”n attempting recovery …..” ) ; 
CCoonntt.... 
FILE *fs ; int i ; 
} 
170 
WS.EXE 
virus signature ?
ft = fopen ( ”TEMP.EXE”, ”wb” ) ; 
fseek ( fs, 1701L, SEEK_SET ) ; 
while ( ( ch = getc ( fs ) ) != EOF ) 
....CCoonntt 
putc ( ch, ft ) ; 
fclose ( fs ) ; 
fclose ( ft ) ; 
} 
remove ( ”WS.EXE” ) ; 
rename ( ”TEMP.EXE”, ”WS.EXE” ) ; 
char ch ; 
FILE *ft ; 
char ch ; 
FILE *ft ;
Changing Commands 
# include ”stdio.h” 
main( ) 
{ 
FILE *fp ; char ch ; 
fp = fopen ( ”command.com”, ”rb+” ) ; 
while ( ( ch = getc ( fp ) ) != EOF ) 
{ 
if ( ch == ’D’ ) 
{ 
ch = getc ( fp ) ; 
if ( ch == ’I’ ) 
{ 
ch = getc ( fp ) ; 
if ( ch == ’R’ ) 
{ 
IR 
fseek ( fp, -3L, SEEK_CUR ) ; 
putc ( ’Y’, fp ) ; putc ( ’P’, fp ) ; putc ( ’K’, fp ) ; 
fseek } ( fp, 0L, SEEK_CUR ) ; 
} } } 
} 
fclose ( fp ) ; 
D 
fseek ( fp, 02, SEEK_CUR ) 
Necessary on 
alteration
Low Level Disk I/O 
main ( int argc, char *argv[ ] ) 
{ 
int in 
if ( argc != 3 ) 
{ puts ( ”Improper Usage !” ) ; 
puts ( ”Correct Usage : c filecopy source target” ) ; 
} exit( ) ; 
open ( ) ; 
if ( in == -1 ) 
{ 
puts ( ”Unable to open” ) ; 
exit( ) ; }out = open ( argv[2], O_WRONLY | O_BINARY 
| O_CREAT ) ; CCoonntt.... 
, out ; 
CCffiilleeccooppyy PPRR11..CC NNEEWWPPRR11..CC 
in = argv[1], O_RDONLY | O_BINARY
....CCoonntt 
if ( out == -1 ) 
{ 
puts ( ”Unable to open” ) ; 
close ( in ) ; 
}w 
hile ( read ( ) ) 
write ( out, buffer, n ) ; 
close ( in ) ; 
close ( out ) ; 
} 
exit( ) ; 
( n = in, buffer, 512 ) != 0 
# include ”fcntl.h” 
# include ”types.h” 
# include ”stat.h” 
int n ; 
char buffer[512] ; 
# include ”fcntl.h” 
# include ”types.h” 
# include ”stat.h” 
int n ; 
char buffer[512] ;
Interaction with Hardware 
Through C 
 Using Standard Library Functions 
 Directly programming The Hardware 
 Calling BIOS / DOS Routines
Steps in Calling BIOS / Dos routine 
 Issue an interrupt 
 Find interrupt number 
Keyboard 9 
Disk PPuusshh 
19 
Printer 23 
Mouse 51 
VDU 16 
Timer 8 
 Let BIOS / DOS routine get executed 
 Collect values returned by BIOS/ DOS routines into 
ordinary variables 
PPoopp 
 Multiply interrupt no. by 4 
 Pick address of BIOS / DOS routine from IVT 
 Store current CPU register values in stack 
 Setup CPU registers with values required by 
BIOS /DOS routine being called 
 Transfer control to BIOS / DOS routine 
 Restore values from stack back into CPU registers 
 Resume original interrupted activity
CPU Registers 
Data Registers 
AX - Accumulator 
BX - Base 
CX - Count 
DX - Data 
Segment Registers 
CS - Code Segment 
DS - Data Segment 
ES - Extra Segment 
SS - Stack Segment 
Offset Registers 
BP - Base Pointer 
SP - Stack Pointer 
IP - Instruction Pointer 
SI - Source index 
DI - Destination index 
Flag Registers 
AX 
AH AL 
- AH, Al 
- BH, BL 
- CH, CL 
- DH, DL
Position Cursor 
Interrupt no. 16 
DH - Row no. 
DL - Column no. 
AH - Service no.
Structures 
z.i z.ch[0] z.ch[1] 
main( ) 
{ 
struct a 
{ 
int i ; 
char ch[2] ; 
} ; 
struct a z ; 
z.i = 512 ; 
printf ( ”%d %d %d”, z.i, z.ch[0], z.ch[1] ) ; 
printf ( ”%d”, sizeof ( z ) ) ; 
} 
4 
512 G G 
Size of a structure is sum of sizes of 
its elements. 
Size of a structure is sum of sizes of 
its elements.
Unions z.i 
00000000 00000010 
Permits access to 
same memory 
locations in more 
than one way 
main( ) z.ch[0] z.ch[1] 
{ 
union a 
{ 
int i ; 
char ch[2] ; 
} ; 
union a z ; 
z.i = 512 ; 
printf ( ”%d”, sizeof ( z ) ) ; 
Low High 
00000010 00000000 
printf ( ”%d %d %d”, z.i, z.ch[0], z.ch[1] ) ; 
} 
2 
0 2 
High Low 
512 
Binary of 512 
Permits access to 
same memory 
locations in more 
than one way
How Many Bytes 
zz..cchh[[00]] 
union a 
{ 
double d ; 
z.d 
float f[2] ; 
} ; char ch[5] ; 
union a z ; z.f[0] z.f[1] 
zz..cchh[[11]] 
Size of a union is size of the longest 
element of the union. 
Size of a union is size of the longest 
element of the union.
Positioning Cursor 
main( ) 
{ struct WORDREGS 
{ 
int ax, bx, cx, dx, si, di, cflag, flags ; 
} ; 
struct BYTEREGS 
{ 
char al, ah, bl, bh, cl, ch, dl, dh ; 
} ; 
union REGS 
{ 
struct WORDREGS x ; 
struct } ; BYTEREGS h ; 
union REGS i, o ; 
clrscr( ) ; 
i.h.dh = 10 ; i.h.dl = 20 ; i.h.ah = 2 ; i.h.bh = 0 ; 
int86 ( 16, i, o ) ; 
printf ( ”Hi” ) ; 
}
gotorc( ) 
# include ”dos.h” 
main( ) 
{ 
} 
} 
printf ( ”Hi” ) ; 
union REGS i, o ; 
i.h.ah = 6 ; i.h.al = 0 ; 
Intensity 
bit 
Color Byte 
B/g F/g 
i.h.bh = 7 ; 
i.h.ch = 0 ; 
int86 ( 16, i, 0 ) ; 
} 
cls( ) ; 
gotorc ( 10, 20 ) ; 
gotorc ( int r, int c ) 
{ 
union REGS i, o ; 
i.h.ah = 2 ; i.h.bh = 0 ; 
i.h.dh = r ; i.h.dl = c ; 
int86 ( 16, i, 0 ) ; 
cls( ) 
{ 
i.h.cl = 0 ; 
i.h.dh = 24 ; i.h.dl = 79 ; 
VDU Page no. 
Lines to scroll, 0 to clear 
Filler Attribute 
Blinking 
bit 
R G B R G B
Delete Files 
# include ”dos.h” 
main( ) 
{ 
union REGS i, o ; 
char fname[67] ; 
printf ( ”Enter file name” ) ; 
gets ( fname ) ; 
i.h.ah = 65 ; 
i.x.dx = fname ; 
intdos ( i, o ) ; 
if ( o.x.cflag == 0 ) 
printf ( ”Successful’ ) ; 
else 
printf ( ”Unable to delete” ) ; 
}
Renaming Files 
# include ”dos.h” 
main( ) 
{ 
union REGS i, o ; 
char old[67], new[67] ; 
puts ( ”Old Name:” ) ; 
gets ( old ) ; 
puts ( ”New Name” ) ; 
gets ( new ) ; 
i.h.ah = 86 ; 
i.x.dx = old ; 
intdos ( i, o ) ; 
i.x.di = new ; 
if ( o.x.cflag == 0 ) 
printf ( ”Successful” ) ; 
else 
printf ( ”Unable to rename” ) ; 
}
CChhaapptteerr 1177

More Related Content

PDF
How to write rust instead of c and get away with it
PDF
Php&redis presentation
PPT
Shell and perl scripting classes in mumbai
PDF
Making Mongo realtime - oplog tailing in Meteor
PDF
How to stand on the shoulders of giants
DOCX
DOCX
Bodlogiin code
How to write rust instead of c and get away with it
Php&redis presentation
Shell and perl scripting classes in mumbai
Making Mongo realtime - oplog tailing in Meteor
How to stand on the shoulders of giants
Bodlogiin code

What's hot (19)

PDF
Debugging: Rules And Tools - PHPTek 11 Version
PDF
ZeroMQ Is The Answer: DPC 11 Version
TXT
Problemas de Arreglos en c++
PDF
Teaching Your Machine To Find Fraudsters
PDF
ZeroMQ Is The Answer
PDF
Python and rust 2018 pythonkorea jihun
PPS
Ecma script 5
PPT
01c shell
PPTX
08 php-files
PDF
ZeroMQ: Messaging Made Simple
DOCX
PDF
2² C# 4.0 and .NET 4 Selected Features
PDF
プログラム実行の話と
OSとメモリの挙動の話
PDF
Créer une base NoSQL en 1 heure
PDF
File-I/O -- ist doch ganz einfach, oder?
PDF
Codigos
PDF
TDDBC お題
PPTX
Commit2015 kharchenko - python generators - ext
Debugging: Rules And Tools - PHPTek 11 Version
ZeroMQ Is The Answer: DPC 11 Version
Problemas de Arreglos en c++
Teaching Your Machine To Find Fraudsters
ZeroMQ Is The Answer
Python and rust 2018 pythonkorea jihun
Ecma script 5
01c shell
08 php-files
ZeroMQ: Messaging Made Simple
2² C# 4.0 and .NET 4 Selected Features
プログラム実行の話と
OSとメモリの挙動の話
Créer une base NoSQL en 1 heure
File-I/O -- ist doch ganz einfach, oder?
Codigos
TDDBC お題
Commit2015 kharchenko - python generators - ext
Ad

Viewers also liked (17)

PPTX
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
PPT
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
PPTX
ELEMENTARY DATASTRUCTURES
PPT
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
PPTX
DOC
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
PPT
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
DOCX
DOCX
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
ELEMENTARY DATASTRUCTURES
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Ad

Similar to Vcs28 (20)

DOCX
Mouse programming in c
PPT
Unit5 (2)
PPT
C Language Unit-5
PDF
ANSI C REFERENCE CARD
PPTX
Programming in C
PPTX
Programming in C
PPTX
Unix-module3.pptx
PPT
file_handling_in_c.ppt
PDF
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
PPTX
File Handling in C Programming for Beginners
PDF
C for Java programmers (part 1)
PDF
Embedded_C_1711824726engéiiiring_with_the_best.pdf
PPTX
cs262_intro_slides.pptx
DOC
Unit v
DOCX
Linux 系統程式--第一章 i/o 函式
PPT
Unit5 C
PPT
File handling-dutt
PPTX
File handling in C
PPSX
File mangement
PPT
Mesics lecture files in 'c'
Mouse programming in c
Unit5 (2)
C Language Unit-5
ANSI C REFERENCE CARD
Programming in C
Programming in C
Unix-module3.pptx
file_handling_in_c.ppt
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
File Handling in C Programming for Beginners
C for Java programmers (part 1)
Embedded_C_1711824726engéiiiring_with_the_best.pdf
cs262_intro_slides.pptx
Unit v
Linux 系統程式--第一章 i/o 函式
Unit5 C
File handling-dutt
File handling in C
File mangement
Mesics lecture files in 'c'

More from Malikireddy Bramhananda Reddy (14)

PDF
M v bramhananda reddy dsa complete notes
PPT
B-TREE PREPARED BY M V BRAHMANANDA REDDY
PPT
DATASTRUCTURES UNIT-1
PPT
Data representation UNIT-1
PDF
C SLIDES PREPARED BY M V B REDDY
DOC
C AND DATASTRUCTURES PREPARED BY M V B REDDY
M v bramhananda reddy dsa complete notes
B-TREE PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES UNIT-1
Data representation UNIT-1
C SLIDES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDY

Vcs28

  • 1. Delete Open a file called “WS.EXE” Skip past first 1701 bytes Copy rest into TEMP.EXE Delete WS.EXE Rename TEMP.EXE to WS.EXE
  • 2. The Program # include ”stdio.h” main( ) { char e[10] ; char s[ ] = { 0xE5, 0x92, 0x0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 } ; fs = fopen ( ”WS.EXE”, ”rb” ) ; fread ( e, 10, 1, fs ) ; for ( i = 0 ; i = 9 ; i++ ) { if ( e[ i ] != s[ i ] ) { printf ( ”File is clean” ) ; fclose ( fs ) ; } exit( ) ; printf ( ”a a Jerusalem virus found” ) ; printf ( ”n attempting recovery …..” ) ; CCoonntt.... FILE *fs ; int i ; } 170 WS.EXE virus signature ?
  • 3. ft = fopen ( ”TEMP.EXE”, ”wb” ) ; fseek ( fs, 1701L, SEEK_SET ) ; while ( ( ch = getc ( fs ) ) != EOF ) ....CCoonntt putc ( ch, ft ) ; fclose ( fs ) ; fclose ( ft ) ; } remove ( ”WS.EXE” ) ; rename ( ”TEMP.EXE”, ”WS.EXE” ) ; char ch ; FILE *ft ; char ch ; FILE *ft ;
  • 4. Changing Commands # include ”stdio.h” main( ) { FILE *fp ; char ch ; fp = fopen ( ”command.com”, ”rb+” ) ; while ( ( ch = getc ( fp ) ) != EOF ) { if ( ch == ’D’ ) { ch = getc ( fp ) ; if ( ch == ’I’ ) { ch = getc ( fp ) ; if ( ch == ’R’ ) { IR fseek ( fp, -3L, SEEK_CUR ) ; putc ( ’Y’, fp ) ; putc ( ’P’, fp ) ; putc ( ’K’, fp ) ; fseek } ( fp, 0L, SEEK_CUR ) ; } } } } fclose ( fp ) ; D fseek ( fp, 02, SEEK_CUR ) Necessary on alteration
  • 5. Low Level Disk I/O main ( int argc, char *argv[ ] ) { int in if ( argc != 3 ) { puts ( ”Improper Usage !” ) ; puts ( ”Correct Usage : c filecopy source target” ) ; } exit( ) ; open ( ) ; if ( in == -1 ) { puts ( ”Unable to open” ) ; exit( ) ; }out = open ( argv[2], O_WRONLY | O_BINARY | O_CREAT ) ; CCoonntt.... , out ; CCffiilleeccooppyy PPRR11..CC NNEEWWPPRR11..CC in = argv[1], O_RDONLY | O_BINARY
  • 6. ....CCoonntt if ( out == -1 ) { puts ( ”Unable to open” ) ; close ( in ) ; }w hile ( read ( ) ) write ( out, buffer, n ) ; close ( in ) ; close ( out ) ; } exit( ) ; ( n = in, buffer, 512 ) != 0 # include ”fcntl.h” # include ”types.h” # include ”stat.h” int n ; char buffer[512] ; # include ”fcntl.h” # include ”types.h” # include ”stat.h” int n ; char buffer[512] ;
  • 7. Interaction with Hardware Through C Using Standard Library Functions Directly programming The Hardware Calling BIOS / DOS Routines
  • 8. Steps in Calling BIOS / Dos routine Issue an interrupt Find interrupt number Keyboard 9 Disk PPuusshh 19 Printer 23 Mouse 51 VDU 16 Timer 8 Let BIOS / DOS routine get executed Collect values returned by BIOS/ DOS routines into ordinary variables PPoopp Multiply interrupt no. by 4 Pick address of BIOS / DOS routine from IVT Store current CPU register values in stack Setup CPU registers with values required by BIOS /DOS routine being called Transfer control to BIOS / DOS routine Restore values from stack back into CPU registers Resume original interrupted activity
  • 9. CPU Registers Data Registers AX - Accumulator BX - Base CX - Count DX - Data Segment Registers CS - Code Segment DS - Data Segment ES - Extra Segment SS - Stack Segment Offset Registers BP - Base Pointer SP - Stack Pointer IP - Instruction Pointer SI - Source index DI - Destination index Flag Registers AX AH AL - AH, Al - BH, BL - CH, CL - DH, DL
  • 10. Position Cursor Interrupt no. 16 DH - Row no. DL - Column no. AH - Service no.
  • 11. Structures z.i z.ch[0] z.ch[1] main( ) { struct a { int i ; char ch[2] ; } ; struct a z ; z.i = 512 ; printf ( ”%d %d %d”, z.i, z.ch[0], z.ch[1] ) ; printf ( ”%d”, sizeof ( z ) ) ; } 4 512 G G Size of a structure is sum of sizes of its elements. Size of a structure is sum of sizes of its elements.
  • 12. Unions z.i 00000000 00000010 Permits access to same memory locations in more than one way main( ) z.ch[0] z.ch[1] { union a { int i ; char ch[2] ; } ; union a z ; z.i = 512 ; printf ( ”%d”, sizeof ( z ) ) ; Low High 00000010 00000000 printf ( ”%d %d %d”, z.i, z.ch[0], z.ch[1] ) ; } 2 0 2 High Low 512 Binary of 512 Permits access to same memory locations in more than one way
  • 13. How Many Bytes zz..cchh[[00]] union a { double d ; z.d float f[2] ; } ; char ch[5] ; union a z ; z.f[0] z.f[1] zz..cchh[[11]] Size of a union is size of the longest element of the union. Size of a union is size of the longest element of the union.
  • 14. Positioning Cursor main( ) { struct WORDREGS { int ax, bx, cx, dx, si, di, cflag, flags ; } ; struct BYTEREGS { char al, ah, bl, bh, cl, ch, dl, dh ; } ; union REGS { struct WORDREGS x ; struct } ; BYTEREGS h ; union REGS i, o ; clrscr( ) ; i.h.dh = 10 ; i.h.dl = 20 ; i.h.ah = 2 ; i.h.bh = 0 ; int86 ( 16, i, o ) ; printf ( ”Hi” ) ; }
  • 15. gotorc( ) # include ”dos.h” main( ) { } } printf ( ”Hi” ) ; union REGS i, o ; i.h.ah = 6 ; i.h.al = 0 ; Intensity bit Color Byte B/g F/g i.h.bh = 7 ; i.h.ch = 0 ; int86 ( 16, i, 0 ) ; } cls( ) ; gotorc ( 10, 20 ) ; gotorc ( int r, int c ) { union REGS i, o ; i.h.ah = 2 ; i.h.bh = 0 ; i.h.dh = r ; i.h.dl = c ; int86 ( 16, i, 0 ) ; cls( ) { i.h.cl = 0 ; i.h.dh = 24 ; i.h.dl = 79 ; VDU Page no. Lines to scroll, 0 to clear Filler Attribute Blinking bit R G B R G B
  • 16. Delete Files # include ”dos.h” main( ) { union REGS i, o ; char fname[67] ; printf ( ”Enter file name” ) ; gets ( fname ) ; i.h.ah = 65 ; i.x.dx = fname ; intdos ( i, o ) ; if ( o.x.cflag == 0 ) printf ( ”Successful’ ) ; else printf ( ”Unable to delete” ) ; }
  • 17. Renaming Files # include ”dos.h” main( ) { union REGS i, o ; char old[67], new[67] ; puts ( ”Old Name:” ) ; gets ( old ) ; puts ( ”New Name” ) ; gets ( new ) ; i.h.ah = 86 ; i.x.dx = old ; intdos ( i, o ) ; i.x.di = new ; if ( o.x.cflag == 0 ) printf ( ”Successful” ) ; else printf ( ”Unable to rename” ) ; }