无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
12
返回列表 发新帖
楼主: 不点

imdisk支持sector map扇区映射

    [复制链接]
 楼主| 发表于 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/

回复

使用道具 举报

 楼主| 发表于 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
复制代码
回复

使用道具 举报

 楼主| 发表于 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 下查看物理内存,德语操作界面

回复

使用道具 举报

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

点评

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

使用道具 举报

 楼主| 发表于 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
回复

使用道具 举报

发表于 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
回复

使用道具 举报

 楼主| 发表于 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
回复

使用道具 举报

发表于 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
回复

使用道具 举报

 楼主| 发表于 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 毛病不严重,其毛病容易解决。
回复

使用道具 举报

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

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


回复

使用道具 举报

发表于 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
回复

使用道具 举报

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

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

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

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

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


回复

使用道具 举报

 楼主| 发表于 2018-2-12 22:56:54 | 显示全部楼层
本帖最后由 不点 于 2018-2-12 22:58 编辑

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

MmMapIoSpace(0, 0, 0);

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

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

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

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

回复

使用道具 举报

发表于 2018-2-12 23:44:17 | 显示全部楼层

谢谢分享好东西!
回复

使用道具 举报

发表于 2018-2-13 00:04:17 | 显示全部楼层
chenall 发表于 2018-2-12 20:46
我也是用windows 7的安装了vs 2017可以正常使用呀,编译驱动还需要安装winddk.我之前有测试编译imdisk,编 ...


编译imdisk.png


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






回复

使用道具 举报

发表于 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 给这种努力点赞!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 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
回复

使用道具 举报

发表于 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 源码是良好开端,须赞!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 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. }
复制代码
回复

使用道具 举报

 楼主| 发表于 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
回复

使用道具 举报

发表于 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
回复

使用道具 举报

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

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

使用道具 举报

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

本版积分规则

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

闽公网安备 35020302032614号

GMT+8, 2024-3-28 17:04

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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