Can python 'read disk sectors' like/via linux:dd ?

N

news

Hi,
in order to justify learning another language I'd first need to be convinced
that python could easily do the following:-

ReadSectors2Bufr(hdx, StartSectr, SectrCnt, Bufr); <-- like linux: dd
PrintDecOf4Bytes(Offset, Bufr); <-- and also 1 and 2 byte values
OverWriteBufr(Offset, Bufr, Byte);
WriteBufr2Sectors ..... <-- like linux: dd

I guess one would normally use bash, but I'd rather invest effort
in python if it can do this.

Thanks for any info.

== Chris Glur.
 
P

Pascal Bourguignon

Hi,
in order to justify learning another language I'd first need to be convinced
that python could easily do the following:-

ReadSectors2Bufr(hdx, StartSectr, SectrCnt, Bufr); <-- like linux: dd
PrintDecOf4Bytes(Offset, Bufr); <-- and also 1 and 2 byte values
OverWriteBufr(Offset, Bufr, Byte);
WriteBufr2Sectors ..... <-- like linux: dd

I guess one would normally use bash, but I'd rather invest effort
in python if it can do this.

Thanks for any info.

In unix, disks are files like any other file. So if your programming
language allows you to read and write files, it allows you to read and
write disks.

Just write the equivalent of:

int fd=open("/dev/hda",O_RDWR,0);
if(0<==fd){
check_errors(lseek(fd,SECT_SIZE*sect_num,SEEK_SET));
check_errors(read(fd,buffer,SECT_SIZE));
modify(buffer);
check_errors(lseek(fd,SECT_SIZE*sect_num,SEEK_SET));
check_errors(write(fd,buffer,SECT_SIZE));
close(fd); }

and be sure to have the access rights on /dev/hda (and to know what
you're doing!).
 
T

Tauno Voipio

Pascal said:
In unix, disks are files like any other file. So if your programming
language allows you to read and write files, it allows you to read and
write disks.

Just write the equivalent of:

int fd=open("/dev/hda",O_RDWR,0);
if(0<==fd){
check_errors(lseek(fd,SECT_SIZE*sect_num,SEEK_SET));
check_errors(read(fd,buffer,SECT_SIZE));
modify(buffer);
check_errors(lseek(fd,SECT_SIZE*sect_num,SEEK_SET));
check_errors(write(fd,buffer,SECT_SIZE));
close(fd); }

and be sure to have the access rights on /dev/hda (and to know what
you're doing!).

This means in practice that your program has to run
with root rights to handle complete disks or partitions.

Are you attempting to create a boot block virus?
 
P

Pascal Bourguignon

Tauno Voipio said:
This means in practice that your program has to run
with root rights to handle complete disks or partitions.

Not necessarily. We can see things like: chown oracle /dev/hdc
Are you attempting to create a boot block virus?

I suppose that's what he is, in python...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top