Looking for code snippets, library, or toolkit to modify a USB Flash Drive's serial number - usb-drive

I've been writing some tools to interact with a USB Flash Drive (removable drive) for our portable application. We are going to be tying some relevant information directly to the flash drive via the serial number (device serial number, not the volume serial number which is formatting based)
I am able to read the device serial number. What is required to write/modify that device serial number?
I am open to seeing this in any language really (Perl, Ruby, Python, C/C++, .NET anything, etc) but C# is the current code base so what would be first preference.
If a code snippet or script can't be found, some canned application or tool (binary, etc) or similar would be helpful as well.

I think the serial number you are refering to is hardware coded to the flash drive (ie. in its ROM). So there is no way you can (easily) change that serial number. Even if the serial was printed in reprogrammable ROM (I forgot the name EPROM or EEPROM), but then you still need a EPROM writer to do that, not only bunch of codes.

AFAIK, there is one data structure named CIS(Card Information Structure) "embedded" in USB flash drive and stored in flash memory. It is not stored in ROM but in flash, thus it can be modified. But unfortunately the only way to modify it is via specific vendor commands and general users don't know it, unless you can get help from the firmware programmer in charge of this flash controller IC...

In a legitimate way it cannot be done, however if you have the correct MP tool for the built-in USB controller it is possible to modify the serial number and the whole digital structure of the drive.

Related

How windows drivers talk to Hardware?

I am curious about the different ways windows drivers interact with the hardware. For example, some drivers might use a function, others a macro, and others might hard-code the register addresses directly into their code. There are probably other ways as well.
Can someone please let me know about the different ways of interaction.
Also, I would like to know, given a particular driver, How can we find out how is it interacting, if we have all the source files including the .vcxproj and other binaries. ?
Any help is really appreciated.
TIA. :-)
It depends on the type of device. for example, if it is a generic PCI Device then the access to the hardware is done "directly" to the HW, meaning Windows map the PCI MMIO to some virtual address and the driver interacts with it.
Microsoft recommended using HAL Function in order to prevent issues with compiler optimization, e.g. to use READ_REGISTER_UCHAR() macro to read BYTE from a device register.
USB, for example, is a subsystem that has a big stack and there is a USB controller that manages access to the device. so, in this case, you will need to use a function to access the device register.
You can find a lot of Microsoft driver samples in GitHub

How to Use 10-Sector Track Format On A USB Floppy Drive

I'm programming a floppy disk-extractor/manager for an old synthesizer/keyboard instrument (made in 1980's).
My Problem: This software should support USB-Floppy drives. It needs to read and write images to a 10-sector track formats. But USB Floppy-drives only support 9 or 18 sector track. I wasn't able to find a way to control this with my software (it seems like it is hard-coded into the drives firmware).
Has anyone successfully done this before? I would appreciate any hints
If the track format isn't standard PC format then it wouldn't work anyway. You'll need to make a floppy controller of your own in order to read a differently formatted disk.

How to programatically create custom input/output devices?

How do i create a custom media input/output device like a speaker or microphone that i can select from a program like Skype. For example i could make a GreyScale webcam that reads the webcam and makes it greyscale or a custom Beep Speaker that takes anything a program sends to the speaker and adds a beep after 3 seconds etc. An example would be this:
http://www.videohelp.com/tools/UScreenCapture
I just need help on how to create the actual (virtual?) device, not how to make it greyscale etc. I can figure that out later.
Where do i even begin to search for tutorials/readings on this? As per the tags, i prefer qt/c++ related but it doesn't necessarily have to be that. Just a nudge in the right direction to get me started would be fine.
You need to create a device driver. What that entails depends entirely on the platform and the type of device you want to emulate.
Start with the documentation of your operating system and look up references as if you were developing a new hardware device. But you'll just skip any actual hardware interfaces.
Nevertheless this is likely to require kernel programming, so Qt is likely to be inappropriate.

Controlling the USB from Windows

I know this probably is not the easiest thing to do, but I am trying to connect Microcontroller and PC using USB. I dont want to use internal USART of Microcontroller or USB to RS232 converted, its project indended to help me understand various principles.
So, getting the communication done from the Microcontroller side is piece of cake - I mean, when I know he protocol, its relativelly easy to implement it on Micro, becouse I am in direct control of evrything, even precise timing.
But this is not the case of PC. I am not very familiar with concept of Windows handling the devices connected. In one of my previous question I ask about how Windows works with devices thru drivers. I understood that for internal use of Windows, drivers must have some default set of functions available to OS. I mean, when OS wants to access HDD, it calls HDD driver (which is probably internal in OS), with specific "questions" so that means that HDD driver has to be written to cooperate with Windows, to have write function in the proper place to be called by the OS. Something similiar is for GPU, Even DirectX, I mean DirectX must call specific functions from drivers, so drivers must be written to work with DX. I know, many functions from WinAPI works on their own, but even "simple" window must be in the end written into framebuffer, using MMIO to adress specified by drivers. Am I right?
So, I expected that Windows have internal functions, parts of WinAPI designed to work with certain comonly used things. To call manufacturer-designed drivers. But this seems to not be entirely true becouse Windows has no way to communicate thru Paralel port. I mean, there is no function in the WinAPI to work with serial port, but there are funcions to work with HDD,GPU and so.
But now there comes the part I am getting very lost at. So, I think Windows must have some built-in functions to communicate thru USB, becouse for example it handles USB flash memory. So, is there any WinAPI function designed to let user to operate USB thru that function, or when I want to use USB myself, do I have to call desired USB-driver function myself? Becouse all you need to send to USB controller is device adress and the infromation right? I mean, I donĀ“t have to write any new drivers, am I right? Just to call WinAPI function if there is such, or directly call original USB driver. Does any of this make some sense?
To make your life easier, and avoid writing your own driver, try using the HID (Human Interface Device) API on top of USB. Although it says "Human Interface", it doesn't actually have to be for devices that a human controls. The advantage is that modern OSes already come with a HID driver and you can use sample code such as what you can find here to get started. Many microcontroller manufacturers provide suitable code for the embedded of the protocol.
Because OSes already understand HID, if you build a device using the HID interface you'll find that not only can you read from it from any OS, you may also find that many applications can already talk to your device if its communication is restricted to a small enough subset of HID. (For example, I built an input device for a music app, but amazingly I found I could literally plug it straight into a 3D animation app we use at work, running on a different OS, and have it work right away without writing a single additional line of code!)
This answer might aim you in the right direction.
The first answer here might also be helpful.
The answers to this have some actual code and links to yet other resources.
USB includes a set of stock functionality, much like supporting USB flash drives (USB Mass Storage class). The two most interesting for microcontroller interfacing are HID and CDC. CDC is easiest to use as it directly emulates an old fashioned serial port.
If you configure the microcontroller to act as a CDC device, Windows will enumerate it as a serial port, and all the old serial APIs will work on it.

USB Hierarchy Driver

Is it possible to create a driver (windows/mac) for a custom usb hub such that it appears as one device in My Computer / Finder and the attached usb card readers each show up as a sub-folder within that device? Any pointers to the right direction to look at would be appreciated.
It is possible, but unholy amounts of difficult. You really don't want to do this. Really. You'll basically be reimplementing USBHub.sys from scratch, as well as breaking the standard paradigm of drives in Windows (i.e. drives appear in My Computer).
You have two routes to doing this:
1) Build your own custom USB hub device, which presents itself as a single drive, and creates its own internal folders based on the devices attached.
2) Write some seriously ninja driver code combining multiple USB card-reader devices into a single drive. This would be extremely platform dependent (Windows v. Mac), and would require what would be at least 6 months of work, give or take.
I honestly would go with the first if it's a big must. Would take a custom piece of hardware though...

Resources