-1

I've recently started looking into low level bit manipulation.

http://bits.stephan-brumme.com/

and

http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetNaive

I understand the concept of how to clear/set/toggle/check etc., a bit within an integer or a byte. (Get a specific bit from byte)

I cannot however seem to find how to change the value of a bit at a specific location in my hard drive.

I would be attempting to do this in Ubuntu 14.04 LTS. I am most familiar with Python and C++ but i'll take answers in any language.

Community
  • 1
  • 1
  • Stack Overflow is neither a forum nor a tutorial, code-writing, or homework service. This is a Q&A site where *specific* programming questions (usually, but not always, including some code) get *specific* answers. Please take the [tour] and carefully read through the [help] to learn more about the site, including [what is on-topic](http://stackoverflow.com/help/on-topic) and [what is not](http://stackoverflow.com/help/dont-ask), and how to [ask a good question](http://stackoverflow.com/help/how-to-ask). Please also follow the [question checklist](http://meta.stackoverflow.com/q/260648). – MattDMo Jun 14 '16 at 15:38
  • When you say "change a bit at a specific location (on the) hard drive", do you really mean anywhere in the entire disk? Or might you mean *within a file on the hard drive*? – wallyk Jun 14 '16 at 15:39
  • @wallyk i really mean anywhere. The idea is going right to a specific bit and modifying it without interacting with anything else. – Salvadorjer Jun 14 '16 at 15:42
  • You do realize this could be dangerous to your installed filesystem. I mean randomly changing a bit could cause corruption to a important system file or the structure of your filesystem. – drescherjm Jun 14 '16 at 16:37
  • @drescherjm Yep that's part of the point of what i'm going to try and do. It would be on a secondary hard drive not the main one containing the program or OS. – Salvadorjer Jun 14 '16 at 18:04

1 Answers1

1

It would go like this:

  • Open the drive for read/write, as root. (ex: /dev/sda)
  • Mmap the drive (or you can seek and read/write)
  • find the byte, modify the bits you want, flush and unmmap (or close).

Someone else would probably provide the code version of this.

OneOfOne
  • 95,033
  • 20
  • 184
  • 185