I present you a small collection of miscellaneous WinAPI source codes . Feel free to PM me If you have any suggestions or spotted a bug in the code.
Contents
- Dll injection
- Get disk size
- Drive letter changer
- Associate file extension with a program
- NtQuerySystemInformation
DLL injection example
Shows how to inject a DLL into process. Project includes a simple DLL and a HelloWorld application for testing.
Download (CodeBlocks project)
Get disk size
This simple application shows how to use DeviceIOControl() and IOCTL_DISK_GET_LENGTH_INFO to get disk or partition size.
If you don't need a fully working app, you can use this function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
//
// GetDisk or or partition size
// dsk can be \\\\.\\PhysicalDrive0 or \\\\.\\C:
//
uint64_t GetDiskLengthIoctl(const char *dsk)
{
HANDLE hDisk=CreateFile(dsk,GENERIC_READ,FILE_SHARE_VALID_FLAGS,0,OPEN_EXISTING,0,0);
if(hDisk==INVALID_HANDLE_VALUE)
{
cerr<<"Could not open the disk. GetLastError() returned "<<GetLastError()<<endl;
return 0;
}
GET_LENGTH_INFORMATION gli;
DWORD ret;
DeviceIoControl(hDisk,IOCTL_DISK_GET_LENGTH_INFO,0,0,&gli,sizeof(gli),&ret,0);
CloseHandle(hDisk);
return gli.Length.QuadPart;
}
|
Download (CodeBlocks project)
Drive letter changer
A simple program that shows how to use SetVolumeMountPoint to change drive letters
Download (CodeBlocks project)
Associate file extension with a program
Download (CodeBlocks project)
NtQuerySystemInformation examples
.zip file includes three separate projects that show how to use NtQuerySystemInformation() function to..
- get list of all running processes
- display some information about physical memory (page size, number of physical pages) and number of processors
- display number of disks, serial ports, CdRoms
Download (CodeBlocks projects)
Attachments:
[CodeInject.zip]
[drive_letter_changer.zip]
[ext_assoc.zip]
[get_disk_size.zip]
[nt_query_system_information.zip]