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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news@absamail.co.za

    #1

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

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

    ReadSectors2Buf r(hdx, StartSectr, SectrCnt, Bufr); <-- like linux: dd
    PrintDecOf4Byte s(Offset, Bufr); <-- and also 1 and 2 byte values
    OverWriteBufr(O ffset, Bufr, Byte);
    WriteBufr2Secto rs ..... <-- 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.

  • Pascal Bourguignon

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

    news@absamail.c o.za writes:
    [color=blue]
    > Hi,
    > in order to justify learning another language I'd first need to be convinced
    > that python could easily do the following:-
    >
    > ReadSectors2Buf r(hdx, StartSectr, SectrCnt, Bufr); <-- like linux: dd
    > PrintDecOf4Byte s(Offset, Bufr); <-- and also 1 and 2 byte values
    > OverWriteBufr(O ffset, Bufr, Byte);
    > WriteBufr2Secto rs ..... <-- 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.[/color]

    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(ls eek(fd,SECT_SIZ E*sect_num,SEEK _SET));
    check_errors(re ad(fd,buffer,SE CT_SIZE));
    modify(buffer);
    check_errors(ls eek(fd,SECT_SIZ E*sect_num,SEEK _SET));
    check_errors(wr ite(fd,buffer,S ECT_SIZE));
    close(fd); }

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

    --
    __Pascal Bourguignon__ http://www.informatimago.com/

    Nobody can fix the economy. Nobody can be trusted with their finger
    on the button. Nobody's perfect. VOTE FOR NOBODY.

    Comment

    • Tauno Voipio

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

      Pascal Bourguignon wrote:
      [color=blue]
      > 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(ls eek(fd,SECT_SIZ E*sect_num,SEEK _SET));
      > check_errors(re ad(fd,buffer,SE CT_SIZE));
      > modify(buffer);
      > check_errors(ls eek(fd,SECT_SIZ E*sect_num,SEEK _SET));
      > check_errors(wr ite(fd,buffer,S ECT_SIZE));
      > close(fd); }
      >
      > and be sure to have the access rights on /dev/hda (and to know what
      > you're doing!).[/color]

      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?

      --

      Tauno Voipio
      tauno voipio (at) iki fi

      Comment

      • Pascal Bourguignon

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

        Tauno Voipio <tauno.voipio@I NVALIDiki.fi> writes:
        [color=blue]
        > Pascal Bourguignon wrote:
        >[color=green]
        >> 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(ls eek(fd,SECT_SIZ E*sect_num,SEEK _SET));
        >> check_errors(re ad(fd,buffer,SE CT_SIZE));
        >> modify(buffer);
        >> check_errors(ls eek(fd,SECT_SIZ E*sect_num,SEEK _SET));
        >> check_errors(wr ite(fd,buffer,S ECT_SIZE)); close(fd); }
        >> and be sure to have the access rights on /dev/hda (and to know what
        >> you're doing!).[/color]
        >
        > This means in practice that your program has to run
        > with root rights to handle complete disks or partitions.[/color]

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

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

        --
        __Pascal Bourguignon__ http://www.informatimago.com/
        The mighty hunter
        Returns with gifts of plump birds,
        Your foot just squashed one.

        Comment

        Working...