无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
查看: 14848|回复: 51
打印 上一主题 下一主题

imdisk支持sector map扇区映射

    [复制链接]
跳转到指定楼层
#
发表于 2018-1-25 12:06:46 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
http://reboot.pro/topic/20450-mounting-split-image/ 的 7 楼,imdisk 的开发者本人透露:

This is rather easy nowadays with ImDisk.
Simply specify a physical drive object as "image file"
and specify offset and size as -b and -s switches.
Example:

  1. imdisk -a -f \\?\physicaldrive1 -b 200000 -s 300000 -m #:
复制代码


-f \\?\physicaldrive1 - path to physical drive object

-b 200000 = offset in bytes

-s 300000 = size in bytes (length to use after offset)

For first experiments add -o ro for read-only operation, so that ImDisk does not overwrite anything until you know that it works and you have got the right offsets and lengths.

And yes, I use this method now and then to mount secondary partitions on USB thumb drives that are not directly visible in Windows. :)

http://diddy.boot-land.net/firadisk/files/imdisk.htm 有个 imdisk 的教程。

在命令窗口执行 imdisk  /? 命令,可以获得如下的帮助信息:


  1. Control program for the ImDisk Virtual Disk Driver.
  2. For copyrights and credits, type imdisk --version

  3. Syntax:
  4. imdisk -a -t type -m mountpoint [-n] [-o opt1[,opt2 ...]] [-f|-F file]
  5.        [-s size] [-b offset] [-v partition] [-S sectorsize] [-u unit]
  6.        [-x sectors/track] [-y tracks/cylinder] [-p "format-parameters"]
  7. imdisk -d|-D [-u unit | -m mountpoint]
  8. imdisk -l [-u unit | -m mountpoint]
  9. imdisk -e [-s size] [-o opt1[,opt2 ...]] [-u unit | -m mountpoint]

  10. -a      Attach a virtual disk. This will configure and attach a virtual disk
  11.         with the parameters specified and attach it to the system.

  12. -d      Detach a virtual disk from the system and release all resources.
  13.         Use -D to force removal even if the device is in use.

  14. -e      Edit an existing virtual disk.

  15.         Along with the -s parameter extends the size of an existing virtual
  16.         disk. Note that even if the disk can be extended successfully, the
  17.         existing filesystem on it can only be extended to fill the new size
  18.         without re-formatting if you are running Windows 2000 or later and the
  19.         current filesystem is NTFS.

  20.         Along with the -o parameter changes media characteristics for an
  21.         existing virtual disk. Options that can be changed on existing virtual
  22.         disks are those specifying wether or not the media of the virtual disk
  23.         should be writable and/or removable.

  24. -t type
  25.         Select the backingstore for the virtual disk.

  26. vm      Storage for this type of virtual disk is allocated from virtual memory
  27.         in the system process. If a file is specified with -f that file is
  28.         is loaded into the memory allocated for the disk image.

  29. file    A file specified with -f file becomes the backingstore for this
  30.         virtual disk.

  31. proxy   The actual backingstore for this type of virtual disk is controlled by
  32.         an ImDisk storage server accessed by the driver on this machine by
  33.         sending storage I/O request through a named pipe specified with -f.

  34. -f file or -F file
  35.         Filename to use as backingstore for the file type virtual disk, to
  36.         initialize a vm type virtual disk or name of a named pipe for I/O
  37.         client/server communication for proxy type virtual disks. For proxy
  38.         type virtual disks "file" may be a COM port or a remote server
  39.         address if the -o options includes "ip" or "comm".

  40.         Instead of using -f to specify 'DOS-style' paths, such as
  41.         C:\dir\image.bin or \\server\share\image.bin, you can use -F to
  42.         specify 'NT-style' native paths, such as
  43.         \Device\Harddisk0\Partition1\image.bin. This makes it possible to
  44.         specify files on disks or communication devices that currently have no
  45.         drive letters assigned.

  46. -l      List configured devices. If given with -u or -m, display details about
  47.         that particular device.

  48. -n      When printing ImDisk device names, print only the unit number without
  49.         the \Device\ImDisk prefix.

  50. -s size
  51.         Size of the virtual disk. Size is number of bytes unless suffixed with
  52.         a b, k, m, g, t, K, M, G or T which denotes number of 512-byte blocks,
  53.         thousand bytes, million bytes, billion bytes, trillion bytes,
  54.         kilobytes, megabytes, gigabytes and terabytes respectively. The suffix
  55.         can also be % to indicate percentage of free physical memory which
  56.         could be useful when creating vm type virtual disks. It is optional to
  57.         specify a size unless the file to use for a file type virtual disk does
  58.         not already exist or when a vm type virtual disk is created without
  59.         specifying an initialization image file using the -f or -F. If size is
  60.         specified when creating a file type virtual disk, the size of the file
  61.         used as backingstore for the virtual disk is adjusted to the new size
  62.         specified with this size option.

  63.         The size can be a negative value to indicate the size of free physical
  64.         memory minus this size. If you e.g. type -400M the size of the virtual
  65.         disk will be the amount of free physical memory minus 400 MB.

  66. -b offset
  67.         Specifies an offset in an image file where the virtual disk begins. All
  68.         offsets of I/O operations on the virtual disk will be relative to this
  69.         offset. This parameter is particularily useful when mounting a specific
  70.         partition in an image file that contains an image of a complete hard
  71.         disk, not just one partition. This parameter has no effect when
  72.         creating a blank vm type virtual disk. When creating a vm type virtual
  73.         disk with a pre-load image file specified with -f or -F paramters, the
  74.         -b parameter specifies an offset in the image file where the image to
  75.         be loaded into the vm type virtual disk begins.

  76.         Specify auto as offset to automatically select offset for a few known
  77.         non-raw disk image file formats. Currently auto-selection is supported
  78.         for Nero .nrg and Microsoft .sdi image files.

  79. -v partition
  80.         Specifies which partition to mount when mounting a raw hard disk image
  81.         file containing a master boot record and partitions.

  82.         Specify number 1-4 to mount a partition from the primary partition
  83.         table and 5-8 to mount a partition from an extended partition table.

  84. -S sectorsize
  85.         Sectorsize to use for the virtual disk device. Default value is 512
  86.         bytes except for CD-ROM/DVD-ROM style devices where 2048 bytes is used
  87.         by default.

  88. -x sectors/track
  89.         See the description of the -y option below.

  90. -y tracks/cylinder
  91.         The -x and -y options can be used to specify a synthetic geometry.
  92.         This is useful for constructing bootable images for later download to
  93.         physical devices. Default values depends on the device-type specified
  94.         with the -o option. If the 'fd' option is specified the default values
  95.         are based on the virtual disk size, e.g. a 1440K image gets 2
  96.         tracks/cylinder and 18 sectors/track.

  97. -p "format-parameters"
  98.         If -p is specified the 'format' command is invoked to create a
  99.         filesystem when the new virtual disk has been created.
  100.         "format-parameters" must be a parameter string enclosed within
  101.         double-quotes. The string is added to the command line that starts
  102.         'format'. You usually specify something like "/fs:ntfs /q /y", that
  103.         is, create an NTFS filesystem with quick formatting and without user
  104.         interaction.

  105. -o option
  106.         Set or reset options.

  107. ro      Creates a read-only virtual disk. For vm type virtual disks, this
  108.         option can only be used if the -f option is also specified.

  109. rw      Specifies that the virtual disk should be read/writable. This is the
  110.         default setting. It can be used with the -e parameter to set an
  111.         existing read-only virtual disk writable.

  112. rem     Specifies that the device should be created with removable media
  113.         characteristics. This changes the device properties returned by the
  114.         driver to the system. For example, this changes how some filesystems
  115.         cache write operations.

  116. fix     Specifies that the media characteristics of the virtual disk should be
  117.         fixed media, as opposed to removable media specified with the rem
  118.         option. Fixed media is the default setting. The fix option can be used
  119.         with the -e parameter to set an existing removable virtual disk as
  120.         fixed.

  121. saved   Clears the 'image modified' flag from an existing virtual disk. This
  122.         flag is set by the driver when an image is modified and is displayed
  123.         in the -l output for a virtual disk. The 'saved' option is only valid
  124.         with the -e parameter.

  125.         Note that virtual floppy or CD/DVD-ROM drives are always read-only and
  126.         removable devices and that cannot be changed.

  127. cd      Creates a virtual CD-ROM/DVD-ROM. This is the default if the file
  128.         name specified with the -f option ends with either .iso, .nrg or .bin
  129.         extensions.

  130. fd      Creates a virtual floppy disk. This is the default if the size of the
  131.         virtual disk is any of 160K, 180K, 320K, 360K, 640K, 720K, 820K, 1200K,
  132.         1440K, 1680K, 1722K, 2880K, 123264K or 234752K.

  133. hd      Creates a virtual fixed disk partition. This is the default unless
  134.         file extension or size match the criterias for defaulting to the cd or
  135.         fd options.

  136. ip      Can only be used with proxy-type virtual disks. With this option, the
  137.         user-mode service component is initialized to connect to an ImDisk
  138.         storage server using TCP/IP. With this option, the -f switch specifies
  139.         the remote host optionally followed by a colon and a port number to
  140.         connect to.

  141. comm    Can only be used with proxy-type virtual disks. With this option, the
  142.         user-mode service component is initialized to connect to an ImDisk
  143.         storage server through a COM port. With this option, the -f switch
  144.         specifies the COM port to connect to, optionally followed by a colon,
  145.         a space, and then a device settings string with the same syntax as the
  146.         MODE command.

  147. -u unit
  148.         Along with -a, request a specific unit number for the ImDisk device
  149.         instead of automatic allocation. Along with -d or -l specifies the
  150.         unit number of the virtual disk to remove or query.

  151. -m mountpoint
  152.         Specifies a drive letter or mount point for the new virtual disk, the
  153.         virtual disk to query or the virtual disk to remove. When creating a
  154.         new virtual disk you can specify #: as mountpoint in which case the
  155.         first unused drive letter is automatically used.
复制代码
推荐
 楼主| 发表于 2018-1-25 15:37:21 | 只看该作者
红毛樱木 发表于 2018-1-25 13:11
这个一直都支持。。。您才知道啊,用了几年了。

哦,我跟不上形势了。能分享使用经验、心得体会吗?能给出优缺点的评价吗?

我想制作一个 U 盘,含两个分区:开头是 FAT32 分区,紧接着是 NTFS 分区。

NTFS 分区需要从分区表中去除掉,只留下 FAT32 分区,这样的单一分区结构,才能满足某些变态 BIOS 的要求(其实我认为那是垄断者用 BIOS 来封杀多分区启动盘,不然的话,U 盘到处能启动 Windows,尤其是低版本的 Windows,这可能不符合垄断者的利益)。

这个 NTFS 分区的数据还在,只是分区表上找不到它了。

请问,这种情况,进入 Win7 (或 Win10 PE)以后,怎么用 imdisk 来挂上这个 NTFS 分区?最好给出详细步骤。

点评

我一直用PECMD操作的。IMDISK命令行应该差不多。 好像还有个更简单的方式。MOUN-udm -udmid:pt1,具体格式忘记了。  详情 回复 发表于 2018-1-25 15:59

评分

参与人数 1无忧币 +5 收起 理由
ge + 5 不排除是微软捣的鬼!

查看全部评分

回复

使用道具 举报

50#
 楼主| 发表于 2018-2-25 15:34:22 | 只看该作者
sp_star 发表于 2018-2-25 14:47
64位应该是签名的原因。
由于编译环境,可能不支持xp,我在win10 x86下试过。你可以试试在xp下自己再编 ...

在 Windows 下我没有编译环境,就不试了。
回复

使用道具 举报

49#
发表于 2018-2-25 14:47:04 | 只看该作者
不点 发表于 2018-2-25 13:39
Win7x64 下运行失败。出错信息:InitializeWinIo failed!
是必须签名的原因吗?
我没有 32 位 Win7  ...

64位应该是签名的原因。
由于编译环境,可能不支持xp,我在win10 x86下试过。你可以试试在xp下自己再编译一下。

点评

在 Windows 下我没有编译环境,就不试了。  详情 回复 发表于 2018-2-25 15:34
回复

使用道具 举报

48#
 楼主| 发表于 2018-2-25 13:39:35 | 只看该作者
本帖最后由 不点 于 2018-2-25 14:28 编辑
sp_star 发表于 2018-2-25 11:03
一个小工具,在windows下读GRUB4DOS map的磁盘信息。


Win7x64 下运行失败。出错信息:InitializeWinIo failed!
是必须签名的原因吗?
我没有 32 位 Win7 环境,现在无法测试。但稍后可以试试 XP。

【更新】
XP 下报错:对话框 “g4d.exe 不是有效的 Win32 应用程序。”

有个“确定”按钮。

点击 “确定” 按钮后,DOS 框里显示 “拒绝访问。”

回到命令提示符。


  1. D:\G4D>dir
  2. 驱动器 D 中的卷没有标签。
  3. 卷的序列号是 0000-4823

  4. D:\G4D 的目录

  5. 2018/02/25  13:31    <DIR>          .
  6. 2018/02/25  13:31    <DIR>          ..
  7. 2018/02/25  10:10           161,280 g4d.exe
  8. 2010/05/15  23:56            45,568 WinIo32.dll
  9. 2010/05/08  23:16             6,656 WinIo32.sys
  10. 2010/05/15  23:56            44,544 WinIo64.dll
  11. 2010/05/08  23:46            10,920 WinIo64.sys
  12.                5 个文件        268,968 字节
  13.                2 个目录 263,994,019,840 可用字节

  14. D:\G4D>g4d
  15. InitializeWinIo failed!

  16. D:\G4D>
复制代码

点评

64位应该是签名的原因。 由于编译环境,可能不支持xp,我在win10 x86下试过。你可以试试在xp下自己再编译一下。  详情 回复 发表于 2018-2-25 14:47
回复

使用道具 举报

47#
 楼主| 发表于 2018-2-25 13:20:09 | 只看该作者
sp_star 发表于 2018-2-25 12:04
还是使用的Winio驱动,64位时有签名问题。既然有兴趣,自己改改就可以了。

我的 Windows 编译环境建立不起来,没有缘分,已经放弃。目前我的兴趣已经彻底转到 Linux 下了。在 Linux 下可做的事多着呢,根本忙不过来,恐怕以后再也没有机会回到 Windows 下编程了。

我把你提供的代码贴出来,方便有兴趣者查看。

  1. // mdisk.cpp : 定义控制台应用程序的入口点。
  2. //

  3. #include "stdafx.h"
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <conio.h>
  7. #include <windows.h>
  8. #include <shellapi.h>
  9. //#include <winable.h>

  10. typedef BOOL(WINAPI *INITIALIZEWINTO)(void);
  11. typedef BOOL(WINAPI *SHUTDOWNWINIO)(void);
  12. typedef BOOL(WINAPI *GETPORTVAL)(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);
  13. typedef BOOL(WINAPI *SETPORTVAL)(WORD wPortAddr, DWORD dwPortVal, BYTE bSize);
  14. typedef PBYTE(_stdcall *MAPPHYSTOLIN)(PBYTE pbPhysAddr, DWORD dwPhysSize, HANDLE *pPhysicalMemoryHandle);  
  15. typedef BOOL(_stdcall *UNMAPPHYSICALMEMORY)(HANDLE PhysicalMemoryHandle, PBYTE pbLinAddr);  
  16. typedef BOOL(WINAPI *GETPHYSLONG)(PBYTE pbPhysAddr, PDWORD pdwPhysVal);  
  17. typedef BOOL(WINAPI *SETPHYSLONG)(PBYTE pbPhysAddr, DWORD dwPhysVal);
  18. //typedef BOOL(WINAPI *INSTALLWINIODRIVER)(PWSTR pszWinIoDriverPath, bool IsDemandLoaded = false);   
  19. //typedef BOOL(WINAPI *REMOVEWINIODRIVER)();  

  20. INITIALIZEWINTO   InitializeWinIo = NULL;
  21. SHUTDOWNWINIO        ShutdownWinIo = NULL;
  22. GETPORTVAL  GetPortVal = NULL;
  23. SETPORTVAL  SetPortVal = NULL;
  24. MAPPHYSTOLIN MapPhysToLin = NULL;   
  25. UNMAPPHYSICALMEMORY UnmapPhysicalMemory = NULL;  
  26. GETPHYSLONG GetPhysLong = NULL;
  27. SETPHYSLONG SetPhysLong = NULL;
  28. //INSTALLWINIODRIVER InstallWinIoDriver = NULL;
  29. //REMOVEWINIODRIVER RemoveWinIoDriver = NULL;

  30. BOOL InitFuncs(void)
  31. {
  32.         HMODULE hMod = LoadLibrary(_T("WinIo32.dll"));
  33.     InitializeWinIo= (INITIALIZEWINTO)GetProcAddress(hMod,"InitializeWinIo");
  34.         ShutdownWinIo= (SHUTDOWNWINIO)GetProcAddress(hMod,"ShutdownWinIo");
  35.     GetPortVal= (GETPORTVAL)GetProcAddress(hMod,"GetPortVal");
  36.         SetPortVal= (SETPORTVAL)GetProcAddress(hMod,"SetPortVal");
  37.         MapPhysToLin=(MAPPHYSTOLIN)GetProcAddress(hMod,"MapPhysToLin");  
  38.         UnmapPhysicalMemory=(UNMAPPHYSICALMEMORY)GetProcAddress(hMod,"UnmapPhysicalMemory");  
  39.         GetPhysLong=(GETPHYSLONG)GetProcAddress(hMod,"GetPhysLong");  
  40.         SetPhysLong=(SETPHYSLONG)GetProcAddress(hMod,"SetPhysLong");  
  41.         //InstallWinIoDriver=(INSTALLWINIODRIVER)GetProcAddress(hMod,"InstallWinIoDriver");        
  42.         //RemoveWinIoDriver=(REMOVEWINIODRIVER)GetProcAddress(hMod,"RemoveWinIoDriver");  

  43.         if(InitializeWinIo==NULL) return FALSE;
  44.         if(ShutdownWinIo==NULL) return FALSE;
  45.         if(GetPortVal==NULL) return FALSE;
  46.         if(SetPortVal==NULL) return FALSE;
  47.         if(MapPhysToLin==NULL) return FALSE;
  48.         if(UnmapPhysicalMemory==NULL) return FALSE;
  49.         if(GetPhysLong==NULL) return FALSE;
  50.         if(SetPhysLong==NULL) return FALSE;
  51.         //if(InstallWinIoDriver==NULL) return FALSE;
  52.         //if(RemoveWinIoDriver==NULL) return FALSE;
  53.         
  54.         return TRUE;
  55. }


  56. BOOL ReadPhysicalMemory(unsigned int phyAddr, DWORD phySize, unsigned char *buf)
  57. {
  58.         unsigned int addr;
  59.         unsigned long data;
  60.         unsigned long *p=(unsigned long *)buf;
  61.         for(unsigned int i=0;i<phySize;i+=4)
  62.         {
  63.                 addr=phyAddr+i;
  64.                 GetPhysLong((PBYTE)addr,&data);
  65.                 *p=data;
  66.                 p++;
  67.         }
  68.         return TRUE;
  69. }

  70. void print_buf(unsigned char *p)
  71. {
  72.         for(int k=0;k<200;k++)
  73.         {
  74.                 printf("%c",*(p+k));
  75.         }
  76.         printf("\n");
  77. }

  78. void find_g4d_drive(unsigned char* buf, int bufLen);


  79. int _tmain(int argc, _TCHAR* argv[])
  80. {

  81.     if(InitFuncs()!=TRUE)
  82.         {
  83.                 printf("Load WinIo.dll failed!\n");
  84.                 return 0;
  85.         }
  86.     if(InitializeWinIo()!=TRUE)
  87.         {
  88.                 printf("InitializeWinIo failed!\n");
  89.                 return 0;
  90.         }
  91.         printf("InitializeWinIo OK!\n");

  92.         printf("\n");
  93.         //printf("DWORD length=%d\n",sizeof(DWORD));
  94. #if 0        
  95.         HANDLE hPhyMem;
  96.         PBYTE pbLinAddr;
  97.         //下面的语句让 0xf0000 地址的 65536 个字节可直接读写
  98.     pbLinAddr = MapPhysToLin((unsigned char *)0xf0000,65536,&hPhyMem);
  99.         printf("pbLinAddr=%x\n",pbLinAddr);

  100.         DWORD ttmp;
  101.         BOOL rtv;
  102.         rtv=GetPhysLong((PBYTE)0xf0000,&ttmp);
  103.         printf("rtv=%d, ttmp=%x\n",rtv, ttmp);
  104.         
  105. #endif        
  106.         // real-mode RAM range 0-640KB
  107.     const int nBytes=0xA0000;
  108.         unsigned char buf[nBytes];
  109.         memset(buf,0,nBytes);
  110.         ReadPhysicalMemory(0,nBytes,buf);
  111.     //print_buf(buf);

  112.     find_g4d_drive(buf,nBytes);

  113.         ShutdownWinIo();
  114.         printf("Done!\n");
  115.         return 0;
  116. }

  117. typedef struct _INTRVECT {
  118.         UINT16 offset;
  119.         UINT16 segment;
  120. } INTRVECT, *PINTRVECT;

  121. typedef struct _GRUB4DOS_DRIVE_MAP_SLOT {
  122.         unsigned char from_drive;
  123.         unsigned char to_drive;                        // 0xFF indicates a memdrive
  124.         unsigned char max_head;
  125.         unsigned char max_sector:6,
  126.                 disable_lba:1,                // bit 6: disable lba
  127.                 read_only:1;                // bit 7: read only
  128.         unsigned short to_cylinder:13,        // max cylinder of the TO drive
  129.                 from_cdrom:1,                // bit 13: FROM drive is CDROM(with big 2048-byte sector)
  130.                 to_cdrom:1,                        // bit 14:  TO  drive is CDROM(with big 2048-byte sector)
  131.                 to_support_lba:1;        // bit 15:  TO  drive support LBA
  132.         unsigned char to_head;                        // max head of the TO drive
  133.         unsigned char to_sector:6,                // max sector of the TO drive
  134.                 fake_write:1,                // bit 6: fake-write or safe-boot
  135.                 in_situ:1;                        // bit 7: in-situ
  136.         UINT64 start_sector;
  137.         UINT64 sector_count;
  138. } GRUB4DOS_DRIVE_MAP_SLOT, *PGRUB4DOS_DRIVE_MAP_SLOT;

  139. void print_drv_map(PGRUB4DOS_DRIVE_MAP_SLOT slot)
  140. {
  141.         int dataLen=sizeof(GRUB4DOS_DRIVE_MAP_SLOT);
  142.         printf("DATA: ");
  143.         for(int k=0;k<dataLen;k++)
  144.         {
  145.                 printf("%.2X ", *((unsigned char *)slot+k) );
  146.         }
  147.         printf("\n");

  148.         UINT64 drvlen=slot->sector_count<<9;
  149.         UINT64 address=slot->start_sector<<9;
  150.         printf("Detected GRUB4DOS disk offset=0x%I64x bytes, len=%I64d KB\n",address, drvlen>>10);
  151.         

  152.     printf("   GRUB4DOS SourceDrive: 0x%02x\n", slot->from_drive);
  153.     printf("   GRUB4DOS DestDrive: 0x%02x\n", slot->to_drive);
  154.     printf("   GRUB4DOS MaxHead: %d\n", slot->max_head);
  155.     printf("   GRUB4DOS MaxSector: %d\n", slot->max_sector);
  156.     printf("   GRUB4DOS DestMaxCylinder: %d\n", slot->to_cylinder);
  157.     printf("   GRUB4DOS DestMaxHead: %d\n", slot->to_head);
  158.     printf("   GRUB4DOS DestMaxSector: %d\n", slot->to_sector);
  159.     printf("   GRUB4DOS SectorStart: 0x%08x\n", slot->start_sector);
  160.     printf("   GRUB4DOS SectorCount: %d\n", slot->sector_count);
  161.     printf("\n");
  162.         printf("   GRUB4DOS disable_lba=%d\n", slot->disable_lba);
  163.         printf("   GRUB4DOS read_only=%d\n", slot->read_only);
  164.         printf("   GRUB4DOS from_cdrom=%d\n", slot->from_cdrom);
  165.         printf("   GRUB4DOS to_cdrom=%d\n", slot->to_cdrom);
  166.         printf("   GRUB4DOS to_support_lba=%d\n", slot->to_support_lba);
  167.         printf("   GRUB4DOS fake_write=%d\n", slot->fake_write);
  168.         printf("   GRUB4DOS in_situ=%d\n", slot->in_situ);

  169. }

  170. void print_vector(INTRVECT * pvec)
  171. {
  172.         printf("offset=0x%.4x  ", pvec->offset);
  173.         printf("segment=0x%.4x", pvec->segment);
  174.         printf("\n");
  175. }

  176. void print_string(unsigned char *buf,UINT32 int13entry)
  177. {
  178.         unsigned char tmp_str[9];
  179.     memset(tmp_str,0,9);
  180.         memcpy(tmp_str,buf+int13entry+3,8);
  181.         printf("%s  ",tmp_str);
  182.     memset(tmp_str,0,9);
  183.         memcpy(tmp_str,buf+int13entry+3+8,8);
  184.         printf("%s\n",tmp_str);
  185. }

  186. int check_string(unsigned char *buf,UINT32 int13entry)
  187. {
  188.         int cmp=-1;
  189.         
  190.         unsigned char tmp_str[9];
  191.     memset(tmp_str,0,9);
  192.         memcpy(tmp_str,buf+int13entry+3,8);
  193.         cmp = strcmp((char *)tmp_str,"$INT13SF");
  194.         if(cmp!=0) return 0;

  195.         memset(tmp_str,0,9);
  196.         memcpy(tmp_str,buf+int13entry+3+8,8);
  197.         cmp = strcmp((char *)tmp_str,"GRUB4DOS");
  198.         if(cmp==0)
  199.         {
  200.                 //printf("Found GRUB4DOS\n");
  201.                 return 1;
  202.         }

  203.         return 0;
  204. }

  205. void find_g4d_drive(unsigned char* buf, int bufLen)
  206. {
  207.         //bufLen=0xA0000;  //640K

  208.         INTRVECT int13vector;
  209.         UINT32 int13entry;
  210.         int found=0;

  211.         /*for(int kk=0;kk<0x40;kk++)
  212.         {
  213.         int13vector = ((PINTRVECT)buf)[kk];        
  214.         int13entry = (((UINT32)int13vector.segment << 4) + int13vector.offset);        
  215.         printf("int13entry=0x%lX [%.4X:%.4X]\n",int13entry,int13vector.segment,int13vector.offset);
  216.         }
  217.         printf("\n");
  218.         return;
  219.         */
  220.         
  221.         int13vector = ((PINTRVECT)buf)[0x13];        
  222.         int13entry = (((UINT32)int13vector.segment << 4) + int13vector.offset);
  223.         while(int13entry<0xA0000-27)
  224.         {
  225.                 //if(int13entry==0) continue;
  226.                 printf("int13entry=0x%lX [%.4X:%.4X]\n",int13entry,int13vector.segment,int13vector.offset);
  227.                 found=check_string(buf,int13entry);
  228.                 if(found==1)
  229.                 {
  230.                         PGRUB4DOS_DRIVE_MAP_SLOT pdrvmap;
  231.                         //drive map slot starts at offset 0x20 of the same segment as int13 entry
  232.                         pdrvmap = (PGRUB4DOS_DRIVE_MAP_SLOT)(buf+(((UINT32)int13vector.segment << 4) + 0x20));                        
  233.                         printf("Found GRUBDOS drive at offset 0x%lX [%.4X:%.4X], data length=%d bytes\n",
  234.                                 (unsigned char *)pdrvmap-buf,int13vector.segment,0x20,
  235.                                 sizeof(GRUB4DOS_DRIVE_MAP_SLOT) );
  236.                         printf("\n");
  237.                     print_drv_map(pdrvmap);
  238.                         printf("\n");
  239.                         
  240.                 }
  241.                 int13vector = *((UNALIGNED INTRVECT *)(buf+int13entry+3+8+8));
  242.                 int13entry = (((UINT32)int13vector.segment << 4) + int13vector.offset);
  243.                 //printf("==>int13entry=0x%lX [%.4X:%.4X]\n",int13entry,int13vector.segment,int13vector.offset);
  244.         
  245.         }
  246. }
复制代码
回复

使用道具 举报

46#
发表于 2018-2-25 12:04:04 | 只看该作者
不点 发表于 2018-2-25 11:42
前面有个闭源的工具可以显示出物理内存。

既然你能读 map 信息,想必你一定也能 cat 出物理内存。你能 ...

还是使用的Winio驱动,64位时有签名问题。既然有兴趣,自己改改就可以了。

g4d.zip

2.74 KB, 下载次数: 11, 下载积分: 无忧币 -2

点评

我的 Windows 编译环境建立不起来,没有缘分,已经放弃。目前我的兴趣已经彻底转到 Linux 下了。在 Linux 下可做的事多着呢,根本忙不过来,恐怕以后再也没有机会回到 Windows 下编程了。 我把你提供的代码贴出来  详情 回复 发表于 2018-2-25 13:20

评分

参与人数 1无忧币 +5 收起 理由
不点 + 5 源码是良好开端,须赞!

查看全部评分

回复

使用道具 举报

45#
 楼主| 发表于 2018-2-25 11:42:43 | 只看该作者
sp_star 发表于 2018-2-25 11:03
一个小工具,在windows下读GRUB4DOS map的磁盘信息。

前面有个闭源的工具可以显示出物理内存。

既然你能读 map 信息,想必你一定也能 cat 出物理内存。你能否写个工具,显示物理内存的内容呢?命令行工具即可,不需要图形界面。最好能 open source。

点评

还是使用的Winio驱动,64位时有签名问题。既然有兴趣,自己改改就可以了。  详情 回复 发表于 2018-2-25 12:04
回复

使用道具 举报

44#
发表于 2018-2-25 11:03:13 | 只看该作者
一个小工具,在windows下读GRUB4DOS map的磁盘信息。

G4D.zip

112.73 KB, 下载次数: 19, 下载积分: 无忧币 -2

点评

Win7x64 下运行失败。出错信息:InitializeWinIo failed! 是必须签名的原因吗? 我没有 32 位 Win7 环境,现在无法测试。但稍后可以试试 XP。  详情 回复 发表于 2018-2-25 13:39
前面有个闭源的工具可以显示出物理内存。 既然你能读 map 信息,想必你一定也能 cat 出物理内存。你能否写个工具,显示物理内存的内容呢?命令行工具即可,不需要图形界面。最好能 open source。  详情 回复 发表于 2018-2-25 11:42

评分

参与人数 1无忧币 +5 收起 理由
不点 + 5 给这种努力点赞!

查看全部评分

回复

使用道具 举报

43#
发表于 2018-2-13 00:04:17 | 只看该作者
chenall 发表于 2018-2-12 20:46
我也是用windows 7的安装了vs 2017可以正常使用呀,编译驱动还需要安装winddk.我之前有测试编译imdisk,编 ...





我以前编译成功过,记得是用WDK 7.1.0,貌似不用改什么东西啊。






回复

使用道具 举报

42#
发表于 2018-2-12 23:44:17 | 只看该作者

谢谢分享好东西!
回复

使用道具 举报

41#
 楼主| 发表于 2018-2-12 22:56:54 | 只看该作者
本帖最后由 不点 于 2018-2-12 22:58 编辑

谁能编译这一句,就算成功:

MmMapIoSpace(0, 0, 0);

firadisk 和 winvblock 都使用了这个 API。如果编译成功,修改一下,就能把物理内存 dump 出来。

只要能 dump 出物理内存,事情就简单了。我们现在就卡在不能访问物理内存上了。

前面的那个闭源软件能够访问物理内存,可惜是闭源的。

在网上搜了许多天,也见不到一个能够在(新近的) Windows 下 dump 物理内存的开源工具。前面介绍的那个开源的工具只能在 xp 上运行。

回复

使用道具 举报

40#
 楼主| 发表于 2018-2-12 22:33:50 | 只看该作者
chenall 发表于 2018-2-12 20:46
我也是用windows 7的安装了vs 2017可以正常使用呀,编译驱动还需要安装winddk.我之前有测试编译imdisk,编 ...

能力有限,精力、时间、身体都不允许。放弃。也不会再去英文论坛给别人解释什么了,我的英文太 poor,费劲。

有难度的事情,我一下子都失去信心了。

顺其自然,谁愿意干啥就干啥。不勉强自己,也不勉强别人。

一切皆缘分,没办法。有缘和没缘。最后还是得老老实实在 Linux 下捣鼓。


回复

使用道具 举报

39#
发表于 2018-2-12 20:46:18 | 只看该作者
本帖最后由 chenall 于 2018-2-12 20:47 编辑

我也是用windows 7的安装了vs 2017可以正常使用呀,编译驱动还需要安装winddk.我之前有测试编译imdisk,编译没有通过,应该还需要做一些设置.

没有编译过驱动,搞不懂如何编译,我看了imdisk的源码介绍,应该是可以直接用nmake编译的,不过还是失败了.有一些报错.


也许你可以把这些需求到reboot回复给作者看看他能不能直接加上.毕竟我们如果自己要编译的话那个签名就是一个大麻烦.

点评

[attachimg]367277[/attachimg] 我以前编译成功过,记得是用WDK 7.1.0,貌似不用改什么东西啊。  详情 回复 发表于 2018-2-13 00:04
能力有限,精力、时间、身体都不允许。放弃。也不会再去英文论坛给别人解释什么了,我的英文太 poor,费劲。 有难度的事情,我一下子都失去信心了。 顺其自然,谁愿意干啥就干啥。不勉强自己,也不勉强别人。  详情 回复 发表于 2018-2-12 22:33
回复

使用道具 举报

38#
 楼主| 发表于 2018-2-12 18:45:44 | 只看该作者
我在 win7 下安装了 Visual Studio 2017,结果不能编译任何程序。它要求操作系统是 Win10。

难度太大,这个帖子的讨论,我就不再来了,抱歉。有兴趣者,你们可以继续。


回复

使用道具 举报

37#
 楼主| 发表于 2018-2-12 17:27:36 | 只看该作者
sp_star 发表于 2018-2-12 17:08
关键是改了驱动就没有签名了啊。
不然,直接修改firadisk 或 winvblock就可以了。当然这2个本来也没签名 ...

确实是个问题。可以提交给原作者进行签名。

再有就是,干脆就增强 firadisk 或 winvblock 也行。

哪个途径容易编译,就采用那个途径。具体编译的人,看情况决定。

我估计,firadisk 的功能最完善。

firadisk 支持高位内存,winvblock 不支持。
firadisk 和 winvblock 支持物理内存,而 imdisk (有可能)不支持。
winvblock 和 imdisk 支持纯扇区序列,而 firadisk 不支持。

总体感觉,firadisk 毛病不严重,其毛病容易解决。
回复

使用道具 举报

36#
发表于 2018-2-12 17:08:52 | 只看该作者
不点 发表于 2018-2-12 17:02
映射物理内存,我觉得不难,imdisk 应该可以做到。

已知 firadisk 和 winvblock 都能访问物理内存。

关键是改了驱动就没有签名了啊。
不然,直接修改firadisk 或 winvblock就可以了。当然这2个本来也没签名。

点评

确实是个问题。可以提交给原作者进行签名。 再有就是,干脆就增强 firadisk 或 winvblock 也行。 哪个途径容易编译,就采用那个途径。具体编译的人,看情况决定。 我估计,firadisk 的功能最完善。 fira  详情 回复 发表于 2018-2-12 17:27
回复

使用道具 举报

35#
 楼主| 发表于 2018-2-12 17:02:51 | 只看该作者
sp_star 发表于 2018-2-12 16:31
grub4dos的信息应该是在低位内存吧? 即使实际磁盘在高位内存,也要靠imdisk去处理。如果知道ramdisk在内 ...

映射物理内存,我觉得不难,imdisk 应该可以做到。

已知 firadisk 和 winvblock 都能访问物理内存。

imdisk 至少能够访问线性地址。

不过,即使 imdisk 不能访问物理地址,也能够给它添加这个功能(从 firadisk 或 winvblock 复制代码即可)。



点评

关键是改了驱动就没有签名了啊。 不然,直接修改firadisk 或 winvblock就可以了。当然这2个本来也没签名。  详情 回复 发表于 2018-2-12 17:08
回复

使用道具 举报

34#
发表于 2018-2-12 16:31:18 | 只看该作者
不点 发表于 2018-2-12 15:32
试验过了,完全能读出物理内存啊。

只需验证 XP 下能否读高位内存即可。Win7x64 已经验证成功。

grub4dos的信息应该是在低位内存吧? 即使实际磁盘在高位内存,也要靠imdisk去处理。如果知道ramdisk在内存中的地址和大小,imdisk能直接映射吗?

点评

映射物理内存,我觉得不难,imdisk 应该可以做到。 已知 firadisk 和 winvblock 都能访问物理内存。 imdisk 至少能够访问线性地址。 不过,即使 imdisk 不能访问物理地址,也能够给它添加这个功能(从 fira  详情 回复 发表于 2018-2-12 17:02
回复

使用道具 举报

33#
 楼主| 发表于 2018-2-12 15:32:34 | 只看该作者
sp_star 发表于 2018-2-12 14:03
这个工具是.net的,没运行起来。可以试试读取0~1M的内存,看看grub4dos的信息能不能找到。
里面还有个phys ...

试验过了,完全能读出物理内存啊。

只需验证 XP 下能否读高位内存即可。Win7x64 已经验证成功。

点评

grub4dos的信息应该是在低位内存吧? 即使实际磁盘在高位内存,也要靠imdisk去处理。如果知道ramdisk在内存中的地址和大小,imdisk能直接映射吗?  详情 回复 发表于 2018-2-12 16:31
回复

使用道具 举报

32#
发表于 2018-2-12 14:03:28 | 只看该作者
这个工具是.net的,没运行起来。可以试试读取0~1M的内存,看看grub4dos的信息能不能找到。
里面还有个physmem.sys驱动,好像签名齐全啊,只是不知道怎么用。

点评

试验过了,完全能读出物理内存啊。 只需验证 XP 下能否读高位内存即可。Win7x64 已经验证成功。  详情 回复 发表于 2018-2-12 15:32
回复

使用道具 举报

31#
 楼主| 发表于 2018-2-12 07:35:33 | 只看该作者
本帖最后由 不点 于 2018-2-12 12:08 编辑

找到了一个闭源的查看物理内存的工具,德语的界面,可能不太方便:

https://kb.hilscher.com/display/CIFXDRV/Physical+Memory+Viewer+for+Windows

在 XP 和 Win7x64 试验了,能够查看物理内存的内容。

Win7x64 下还可以查看超过 4G 的高位内存。

谁能试试,看看在 XP (32 位)之下能否查看高于 4G 的物理内存地址的内容?

(点击上面的网址,下载原网站上的文件,不需要币值)

PhysicalMemoryViewer_V1.0.0.0.zip

1.05 MB, 下载次数: 15, 下载积分: 无忧币 -2

Windows 下查看物理内存,德语操作界面

回复

使用道具 举报

30#
 楼主| 发表于 2018-2-12 06:54:26 | 只看该作者
访问物理内存,找到如下代码,但不知这个代码能否在新版 Windows 下工作:

http://nah6.com/~itsme/cvs-xdadevtools/itsutils/src/sysint-physmem.cpp

  1. //========================================================
  2. //
  3. // Physmem
  4. //
  5. // Mark Russinovich
  6. // Systems Internals
  7. // http://www.sysinternals.com
  8. //
  9. // This program demonstrates how you can open and
  10. // map physical memory. This is essentially the NT
  11. // equivalent of the \dev\kmem device in UNIX.
  12. //
  13. //========================================================
  14. #include <util/wintypes.h>
  15. #include "debug.h"
  16. //#include <stdio.h>
  17. //#include "native.h"

  18. //========================================================
  19. //
  20. // Native.h
  21. //
  22. // Mark Russinovich
  23. // Systems Internals
  24. // http://www.sysinternals.com
  25. //
  26. // This file contains tyepdefs and defines from NTDDK.H.
  27. // They are included here so that we don't have to
  28. // include NTDDK.H and get all the other stuff that
  29. // we don't really need or want.
  30. //
  31. //========================================================

  32. #define PAGE_NOACCESS          0x01     // winnt
  33. #define PAGE_READONLY          0x02     // winnt
  34. #define PAGE_READWRITE         0x04     // winnt
  35. #define PAGE_WRITECOPY         0x08     // winnt
  36. #define PAGE_EXECUTE           0x10     // winnt
  37. #define PAGE_EXECUTE_READ      0x20     // winnt
  38. #define PAGE_EXECUTE_READWRITE 0x40     // winnt
  39. #define PAGE_EXECUTE_WRITECOPY 0x80     // winnt
  40. #define PAGE_GUARD            0x100     // winnt
  41. #define PAGE_NOCACHE          0x200     // winnt

  42. typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS; // windbgkd


  43. typedef LONG NTSTATUS;
  44. #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)

  45. typedef struct _UNICODE_STRING {
  46.     USHORT Length;
  47.     USHORT MaximumLength;
  48. #ifdef MIDL_PASS
  49.     [size_is(MaximumLength / 2), length_is((Length) / 2) ] USHORT * Buffer;
  50. #else // MIDL_PASS
  51.     PWSTR  Buffer;
  52. #endif // MIDL_PASS
  53. } UNICODE_STRING;
  54. typedef UNICODE_STRING *PUNICODE_STRING;

  55. typedef enum _SECTION_INHERIT {
  56.     ViewShare = 1,
  57.     ViewUnmap = 2
  58. } SECTION_INHERIT;

  59. #define OBJ_INHERIT             0x00000002L
  60. #define OBJ_PERMANENT           0x00000010L
  61. #define OBJ_EXCLUSIVE           0x00000020L
  62. #define OBJ_CASE_INSENSITIVE    0x00000040L
  63. #define OBJ_OPENIF              0x00000080L
  64. #define OBJ_OPENLINK            0x00000100L
  65. #define OBJ_VALID_ATTRIBUTES    0x000001F2L


  66. typedef struct _OBJECT_ATTRIBUTES {
  67.     ULONG Length;
  68.     HANDLE RootDirectory;
  69.     PUNICODE_STRING ObjectName;
  70.     ULONG Attributes;
  71.     PVOID SecurityDescriptor;        // Points to type SECURITY_DESCRIPTOR
  72.     PVOID SecurityQualityOfService;  // Points to type SECURITY_QUALITY_OF_SERVICE
  73. } OBJECT_ATTRIBUTES;
  74. typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;


  75. #define InitializeObjectAttributes( p, n, a, r, s ) { \
  76.     (p)->Length = sizeof( OBJECT_ATTRIBUTES );          \
  77.     (p)->RootDirectory = r;                             \
  78.     (p)->Attributes = a;                                \
  79.     (p)->ObjectName = n;                                \
  80.     (p)->SecurityDescriptor = s;                        \
  81.     (p)->SecurityQualityOfService = NULL;               \
  82.     }


  83. //
  84. // Functions in NTDLL that we dynamically locate
  85. //

  86. typedef NTSTATUS (__stdcall *PFN_NtUnmapViewOfSection)(
  87.                 IN HANDLE  ProcessHandle,
  88.                 IN PVOID  BaseAddress
  89.                 );

  90. typedef NTSTATUS (__stdcall *PFN_NtOpenSection)(
  91.                 OUT PHANDLE  SectionHandle,
  92.                 IN ACCESS_MASK  DesiredAccess,
  93.                 IN POBJECT_ATTRIBUTES  ObjectAttributes
  94.                 );

  95. typedef NTSTATUS (__stdcall *PFN_NtMapViewOfSection)(
  96.                 IN HANDLE  SectionHandle,
  97.                 IN HANDLE  ProcessHandle,
  98.                 IN OUT PVOID  *BaseAddress,
  99.                 IN ULONG  ZeroBits,
  100.                 IN ULONG  CommitSize,
  101.                 IN OUT PLARGE_INTEGER  SectionOffset,        /* optional */
  102.                 IN OUT PULONG  ViewSize,
  103.                 IN SECTION_INHERIT  InheritDisposition,
  104.                 IN ULONG  AllocationType,
  105.                 IN ULONG  Protect
  106.                 );

  107. typedef VOID (__stdcall *PFN_RtlInitUnicodeString)(
  108.                 IN OUT PUNICODE_STRING  DestinationString,
  109.                 IN PCWSTR  SourceString
  110.                 );

  111. typedef ULONG (__stdcall *PFN_RtlNtStatusToDosError) (
  112.                 IN NTSTATUS Status
  113.                 );

  114. PFN_NtUnmapViewOfSection NtUnmapViewOfSection;
  115. PFN_NtOpenSection NtOpenSection;
  116. PFN_NtMapViewOfSection NtMapViewOfSection;
  117. PFN_RtlInitUnicodeString RtlInitUnicodeString;
  118. PFN_RtlNtStatusToDosError RtlNtStatusToDosError;

  119. //--------------------------------------------------------
  120. //
  121. // UnmapPhysicalMemory
  122. //
  123. // Maps a view of a section.
  124. //
  125. //--------------------------------------------------------
  126. VOID UnmapPhysicalMemory( DWORD Address )
  127. {
  128.         NTSTATUS                status;

  129.         status = NtUnmapViewOfSection( (HANDLE) -1, (PVOID) Address );
  130.         if( !NT_SUCCESS(status)) {
  131.                 error(status, "Unable to unmap view");
  132.         }
  133. }


  134. //--------------------------------------------------------
  135. //
  136. // MapPhysicalMemory
  137. //
  138. // Maps a view of a section.
  139. //
  140. //--------------------------------------------------------
  141. BOOLEAN MapPhysicalMemory( HANDLE PhysicalMemory,
  142.                                                         PDWORD Address, PDWORD Length,
  143.                                                         PDWORD VirtualAddress )
  144. {
  145.         NTSTATUS                        ntStatus;
  146.         PHYSICAL_ADDRESS        viewBase;

  147.         *VirtualAddress = 0;
  148.         viewBase.QuadPart = (ULONGLONG) (*Address);
  149.         ntStatus = NtMapViewOfSection (PhysicalMemory,
  150.                                (HANDLE) -1,
  151.                                (PVOID*) VirtualAddress,
  152.                                0L,
  153.                                *Length,
  154.                                &viewBase,
  155.                                Length,
  156.                                ViewShare,
  157.                                0,
  158.                                PAGE_READONLY );

  159.         if( !NT_SUCCESS( ntStatus )) {
  160.                 //error( ntStatus, "Could not map view of %X length %X", *Address, *Length );
  161.                 return FALSE;                                       
  162.         }

  163.         *Address = viewBase.LowPart;
  164.         return TRUE;
  165. }


  166. //--------------------------------------------------------
  167. //
  168. // OpensPhysicalMemory
  169. //
  170. // This function opens the physical memory device. It
  171. // uses the native API since
  172. //
  173. //--------------------------------------------------------
  174. HANDLE OpenPhysicalMemory()
  175. {
  176.         NTSTATUS                status;
  177.         HANDLE                        physmem;
  178.         UNICODE_STRING        physmemString;
  179.         OBJECT_ATTRIBUTES attributes;
  180.         WCHAR                        physmemName[] = L"\\device\\physicalmemory";

  181.         RtlInitUnicodeString( &physmemString, physmemName );        

  182.         InitializeObjectAttributes( &attributes, &physmemString,
  183.                                                                 OBJ_CASE_INSENSITIVE, NULL, NULL );                        
  184.         status = NtOpenSection( &physmem, SECTION_MAP_READ, &attributes );

  185.         if( !NT_SUCCESS( status )) {
  186.                 error(status, "Could not open \\device\\physicalmemory");
  187.                 return NULL;
  188.         }

  189.         return physmem;
  190. }



  191. //--------------------------------------------------------
  192. //
  193. // LocateNtdllEntryPoints
  194. //
  195. // Finds the entry points for all the functions we
  196. // need within NTDLL.DLL.
  197. //
  198. //--------------------------------------------------------
  199. BOOLEAN LocateNtdllEntryPoints()
  200. {
  201.         if( !(RtlInitUnicodeString = (PFN_RtlInitUnicodeString) GetProcAddress( GetModuleHandle("ntdll.dll"),
  202.                         "RtlInitUnicodeString" )) ) {

  203.                 return FALSE;
  204.         }
  205.         if( !(NtUnmapViewOfSection = (PFN_NtUnmapViewOfSection) GetProcAddress( GetModuleHandle("ntdll.dll"),
  206.                         "NtUnmapViewOfSection" )) ) {

  207.                 return FALSE;
  208.         }
  209.         if( !(NtOpenSection = (PFN_NtOpenSection) GetProcAddress( GetModuleHandle("ntdll.dll"),
  210.                         "NtOpenSection" )) ) {

  211.                 return FALSE;
  212.         }
  213.         if( !(NtMapViewOfSection = (PFN_NtMapViewOfSection) GetProcAddress( GetModuleHandle("ntdll.dll"),
  214.                         "NtMapViewOfSection" )) ) {

  215.                 return FALSE;
  216.         }
  217.         if( !(RtlNtStatusToDosError = (PFN_RtlNtStatusToDosError) GetProcAddress( GetModuleHandle("ntdll.dll"),
  218.                         "RtlNtStatusToDosError" )) ) {

  219.                 return FALSE;
  220.         }
  221.         return TRUE;
  222. }

  223. #if 0
  224. //--------------------------------------------------------
  225. //
  226. // Main
  227. //
  228. // This program drives the command loop
  229. //
  230. //--------------------------------------------------------
  231. int main( int argc, char *argv[] )
  232. {
  233.         HANDLE                physmem;
  234.         DWORD                vaddress, paddress, length;
  235.         char                input[256];
  236.         DWORD                lines;
  237.         char                ch;
  238.         DWORD                i, j;

  239.         printf("\nPhysmem v1.0: physical memory viewer\n"
  240.                    "By Mark Russinovich\n"
  241.                    "Systems Internals - http://www.sysinternals.com\n\n");

  242.         //
  243.         // Load NTDLL entry points
  244.         //
  245.         if( !LocateNtdllEntryPoints() ) {

  246.                 printf("Unable to locate NTDLL entry points.\n\n");
  247.                 return -1;
  248.         }

  249.         //
  250.         // Open physical memory
  251.         //
  252.         if( !(physmem = OpenPhysicalMemory())) {

  253.                 return -1;
  254.         }

  255.         //
  256.         // Enter the command loop
  257.         //
  258.         printf("Enter values in hexadecimal. Enter 'q' to quit.\n");
  259.         while( 1 ) {

  260.                 printf("\nAddress: " ); fflush( stdout );
  261.                 gets( input );
  262.                 if( input[0] == 'q' || input[0] == 'Q' ) break;
  263.                 sscanf( input, "%x", &paddress );

  264.                 printf("Bytes: "); fflush( stdout );
  265.                 gets( input );
  266.                 if( input[0] == 'q' || input[0] == 'Q' ) break;
  267.                 sscanf( input, "%x", &length );

  268.                 //
  269.                 // Map it
  270.                 //
  271.                 if( !MapPhysicalMemory( physmem, &paddress, &length,
  272.                                                                 &vaddress ))
  273.                         continue;

  274.                 //
  275.                 // Dump it
  276.                 //
  277.                 lines = 0;
  278.                 for( i = 0; i < length; i += BYTESPERLINE ) {

  279.                         printf("%08X: ", paddress + i );

  280.                         for( j = 0; j < BYTESPERLINE; j++ ) {

  281.                                 if( i+j == length ) break;
  282.                                 if( j == BYTESPERLINE/2 ) printf("-" );
  283.                                 printf("%02X ", *(PUCHAR) (vaddress + i +j ));
  284.                         }

  285.                         for( j = 0; j < BYTESPERLINE; j++ ) {

  286.                                 if( i+j == length ) break;
  287.                                 ch = *(PUCHAR) (vaddress + i +j );

  288.                                 if( __iscsym( ch ) ||
  289.                                         isalnum( ch ) ||
  290.                                         ch == ' ') {

  291.                                         printf("%c", ch);

  292.                                 } else {

  293.                                         printf("." );
  294.                                 }
  295.                         }

  296.                         printf("\n");

  297.                         if( lines++ == LINESPERSCREEN ) {

  298.                                 printf("-- more -- ('q' to abort)" ); fflush(stdout);
  299.                                 ch = getchar();
  300.                                 if( ch == 'q' || ch == 'Q' ) {
  301.                                         fflush( stdin );
  302.                                         break;
  303.                                 }
  304.                                 lines = 0;
  305.                         }
  306.                 }

  307.                 //
  308.                 // Unmap the view
  309.                 //
  310.                 UnmapPhysicalMemory( vaddress );
  311.         }

  312.         //
  313.         // Close physical memory section
  314.         //
  315.         CloseHandle( physmem );

  316.         return 0;
  317. }
  318. #endif
复制代码
回复

使用道具 举报

29#
 楼主| 发表于 2018-2-11 22:30:36 | 只看该作者
搜到一篇好文,备忘(使用了未公开的功能,不具有通用性,但确实是一篇好文,从技术上来说):

Calling BIOS from Driver in Windows XP x64

http://x86asm.net/articles/calling-bios-from-driver-in-windows-xp-x64/

回复

使用道具 举报

28#
发表于 2018-2-11 22:09:24 | 只看该作者
不点 发表于 2018-2-11 18:09
又想到一个方面的问题,提出来,供大家讨论、研究。

我们先前的开源虚拟盘驱动大致有三个(仅就我们感兴 ...

瞎猜的......
================================
看firadisk的实现,好像就是在0~64K这一段内存中直接查找grub4dos映射的磁盘,主要就是需要访问物理内存的权限,这要在驱动中完成,驱动又需要签名。
如果imdisk愿意实现,应该很简单,只要找到grub4dos的ramdisk的位置信息就可以映射了。
如果imdisk没有实现,需要一个第三方程序找到grub4dos的ramdisk的位置信息,调用imdisk来映射。这个第三方程序可能要能访问物理内存。
回复

使用道具 举报

27#
发表于 2018-2-11 21:50:16 | 只看该作者
不点 发表于 2018-2-11 18:09
又想到一个方面的问题,提出来,供大家讨论、研究。

我们先前的开源虚拟盘驱动大致有三个(仅就我们感兴 ...

可以考虑把想法和imdisk作者说说,看他是否可以把需要的功能添加上去。
回复

使用道具 举报

26#
 楼主| 发表于 2018-2-11 18:09:37 | 只看该作者
又想到一个方面的问题,提出来,供大家讨论、研究。

我们先前的开源虚拟盘驱动大致有三个(仅就我们感兴趣的而言)。其中 firadisk 和 winvblock 都是为 bios 启动程序在实模式阶段所建立的虚拟盘提供驱动的。

而 imdisk 则不为这样的目的服务。imdisk 能够接受命令行参数,直接提供磁盘虚拟功能。

imdisk 不依赖于 grub4dos 或 memdisk 在内存中建立的虚拟盘数据结构,而直接进行 “一般化” 的操作,具有 “一般性” (或 “通用”)的那种方便(也可以说是一种 “美感”)。

因此我想,也许我们可以换个思路,利用 imdisk 的这种美感,或者向 imdisk 的这种美感 “靠拢”。

好了,就不 “云里雾里”、“海阔天空” 了,直接来 “干货”:

我们有时候需要在没有 grub4dos 的情况下使用虚拟盘功能。比如,可见 FAT + 隐藏 NTFS 的 U 盘,插在电脑上(可能是别人的电脑),而且电脑不是从 U 盘启动的。此时,我们仅仅希望 imdisk 能够自动挂上隐藏了的 NTFS 卷。注意此时没有 grub4dos,内存中也就不可能存在 grub4dos 的虚拟盘数据结构。此时,firadisk 和 winvblock 都无法起作用。

这一情况就暴露出 firadisk 和 winvblock 的弱点了——它们专用于 grub4dos(或 memdisk),不能脱离 grub4dos(或 memdisk)而成为应用更加广泛的一般化的虚拟磁盘工具。


假如一个磁盘虚拟工具(比如 imdisk)能够识别出任意一个卷(例如 U 盘)上的特定文件(比如叫做 drivemap.tab,含义是 “驱动器映射记录”),该文件含有 “虚拟盘和扇区序列相关信息”。imdisk 一旦检测到这一信息,就按照信息的指示,自动挂上相应的虚拟盘。除了让 imdisk 能够识别卷(即某分区)上的控制文件以外,还可以让 imdisk 在内存中寻找虚拟盘的指示信息,一旦找到,就自动挂上相应的虚拟盘。

就是说,imdisk 不仅可以识别内存中的虚拟盘指示信息,也可以识别卷上含有虚拟盘指示信息的特定文件。如此一来,imdisk 的用法就自由了,应用范围也就扩大了。就是说,无论有没有 grub4dos 的存在,imdisk 都可以自动挂上虚拟盘。另一方面,grub4dos 也可以把内存中的虚拟盘信息拷贝到磁盘文件(drivemap.tab)里面,这样,imdisk 就能够从磁盘上发现 grub4dos 所提供的虚拟盘信息了。

总的来说,需要着力改造的是 imdisk,而不是 grub4dos。改造 imdisk 需要做大量工作,而 grub4dos 可能只需少量改造,就是前述 “在内存盘 (99) 中增加一些扇区信息” 罢了 。


点评

瞎猜的...... ================================ 看firadisk的实现,好像就是在0~64K这一段内存中直接查找grub4dos映射的磁盘,主要就是需要访问物理内存的权限,这要在驱动中完成,驱动又需要签名。 如果imdisk  详情 回复 发表于 2018-2-11 22:09
可以考虑把想法和imdisk作者说说,看他是否可以把需要的功能添加上去。  详情 回复 发表于 2018-2-11 21:50
回复

使用道具 举报

25#
 楼主| 发表于 2018-2-11 11:31:33 | 只看该作者
本帖最后由 不点 于 2018-2-11 11:42 编辑

有个问题,不知在 Windows 保护模式下,能否暂时回到实模式,执行 int13 读盘,然后再返回保护模式。

如果可行的话,那就好办了。

Win98 是可以的,估计 NT 以后都不行了。

如果不行的话,还真得从 grub4dos 身上“打主意” 了。用一个内存盘,类似于 firadisk 的 (99) 或 winvblock 的 (55),用来存放各种信息。内存盘可以弄大一点,比如 32K,这样可以存放很多信息。

imdisk 只需读取这个内存盘信息,即可知道该怎么建立虚拟盘了。

赶紧行动!最好由 chenall 和 yaya 设计这个内存盘的格式,尽量兼容 firadisk 和 winvblock(我从未接触过,对它们都不了解)。还有谁能帮忙在 Windows 下编译软件的,请主动出手(由于 imdisk 需要进行相应的调整,因此需要编译)。我目前只能提供思路,尽自己所能吧。

【补充】不可能同时兼容 (99) 和 (55)。只需兼容 firadisk 的 (99) 即可。就是说,我们也采用 (99) 这个盘号,格式尽量与 firadisk 完全兼容,只不过我们的内存盘要大得多,能放下几十个扇区数据。

为什么要兼容 firadisk 而不是兼容 winvblock 呢?因为 winvblock 不需要兼容。winvblock 功能强,能支持纯扇区映射,大家通常都不需要 (55) 里面的信息。而 firadisk 在这方面就做得不太好了,它需要 (99) 里面的信息,否则,它根本就无法成功。

回复

使用道具 举报

24#
 楼主| 发表于 2018-2-11 09:26:16 | 只看该作者
chenall 发表于 2018-2-11 09:19
我觉得把firadisk、winvblock的一些特性整合进imdisk是最理想的,因为imdisk已经实现了所有需要的功能, 整合 ...

chenall 你必须帮忙。你只要有编译环境即可,不需要懂得很多驱动开发知识。主要的代码,在这三个软件当中可能都有了,所需要的仅仅是局部改进而已。

回复

使用道具 举报

23#
发表于 2018-2-11 09:19:43 | 只看该作者
我觉得把firadisk、winvblock的一些特性整合进imdisk是最理想的,因为imdisk已经实现了所有需要的功能, 整合其实主要是作一些映射处理.

不懂驱动开发,帮不上忙.

点评

chenall 你必须帮忙。你只要有编译环境即可,不需要懂得很多驱动开发知识。主要的代码,在这三个软件当中可能都有了,所需要的仅仅是局部改进而已。  详情 回复 发表于 2018-2-11 09:26
回复

使用道具 举报

22#
 楼主| 发表于 2018-2-11 07:55:18 | 只看该作者
本帖最后由 不点 于 2018-2-11 08:29 编辑

找到 WinVblock 的处理方法了(见下面代码)。果然有磁盘签名的处理!【更正】遗憾,不是检查磁盘签名,而只是检查 mbr 尾部的 55 AA 标志。

如果扇区数据所在介质是软盘,则拒绝处理(这是没问题的,因为现在没有软盘了,而 U 盘在 Windows 下会被识别为硬盘)。
如果扇区数据所在介质是硬盘,则先检查硬盘上的磁盘签名,如果匹配(通常都能匹配),则成功;如果不匹配,继续检查扇区序列尾部是否 VHD 格式,如果是的,也成功。(我认为 VHD 格式就不用检查了,但可以增加检查虚拟盘第一扇区的内容,见接下来的详述)
如果扇区数据所在介质是光盘,则检查光盘上的 "CD001" 标识符,如果匹配,则成功。

我觉得可以改进一下,无论数据介质是在硬盘还是光盘上,再增加一个检查,即,检查该盘相应于扇区序列的第一扇区内容是否正好是虚拟盘的第一扇区内容,如果不是,则失败。这要求驱动程序在实模式已经保存好虚拟盘的第一扇区。如果虚拟盘是虚拟光盘,则保存含有 "CD001" 的那个扇区(只保存512字节就行)。如果觉得 512 字节太多,可以考虑只保存扇区的 “校验和”(4字节)。

【补充】好的,既然知道了 winvblock 并未使用磁盘签名技术,我们就可以改进了,即,使用磁盘签名,或者干脆使用整个 mbr 扇区,即可唯一确定数据介质所在的物理盘。在实模式阶段,保存所有物理盘的第一扇区数据,同时也保存所有虚拟盘的第一扇区数据。这样,在保护模式就可以对比确认了。


  1. /**
  2. * Check if a disk might be the matching backing disk for
  3. * a GRUB4DOS sector-mapped disk.
  4. *
  5. * @v file              HANDLE to an open disk.
  6. * @v filedisk          Points to the filedisk to match against.
  7. */
  8. static BOOLEAN STDCALL WvFilediskG4dCheckDiskMatch_(
  9.     IN HANDLE file,
  10.     IN WV_SP_FILEDISK_T filedisk
  11.   ) {
  12.     BOOLEAN ok = FALSE;

  13.     switch (filedisk->disk->Media) {
  14.         case WvlDiskMediaTypeFloppy:
  15.           break;

  16.         case WvlDiskMediaTypeHard:
  17.           ok = WvFilediskG4dCheckDiskMatchMbrSig_(file, filedisk);
  18.           if (ok)
  19.             break;
  20.           ok = WvFilediskG4dCheckDiskMatchVHD_(file, filedisk);
  21.           break;
  22.         case WvlDiskMediaTypeOptical:
  23.           ok = WvFilediskG4dCheckDiskMatchIsoSig_(file, filedisk);
  24.           break;
  25.       }
  26.     return ok;
  27.   }
复制代码


回复

使用道具 举报

21#
发表于 2018-2-10 17:31:51 | 只看该作者
嗯,大师辛苦了。。。很有趣的解决问题办法。。。可以拓展启动思路。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-5-4 02:34

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表