本文介绍了如何找到文件的物理地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 - 64 位 操作系统上使用 GoAsm 汇编器,我会问你几个(不是那么愚蠢的)问题.>

第一个问题:

如何找到文件的物理地址?假设文件Text.txt"位于我的 C: 分区的根目录.有没有办法获得这个文件所在的确切内存地址?

第二个问题:

是否可以调用一个例程,就像我调用 C 函数一样?

(即:考虑一个 C 函数WriteToScreen",是否有可能具有相同的功能,但在汇编格式中,这意味着无需使用高级调用来完成这项工作?

第三个问题:

网络上是否有一些 GoAsm 的包含文件,其中包含诸如 (移动、复制、编辑、擦除) 命令之类的有用例程?我首先想到了 ms-dos 中断,但我无法在不使程序崩溃的情况下让它们工作.我猜它只是与 Windows 操作系统不兼容,即使命令提示符的行为类似于 ms-dos... ?

第四个问题:

我从不同的消息来源和我自己听说 NASM 在 Win7 x64 上运行得非常糟糕,这是真的,还是我做错了?

解决方案

1从逻辑的角度来看,硬盘驱动器可以被视为一系列块"(更常见的名称是扇区).可以忽略这些块在磁盘上的物理组织方式,但是驱动程序当然必须知道如何以某种方式获取数据,尽管您发送到现代高清驱动程序的高级"命令,据您所知,这些命令没有很强的相关性到数据的物理位置(您可以说读取块 123",但没有外部证据表明该块所在的位置).

但是,通过这种方式,您可以用数字命名"一个块,并说例如块 0 是 MBR.每个块包含几个字节(512、1024...).并非所有使用的块都包含文件的实际数据,实际上存在任何类型的元信息,这取决于文件系统,但甚至与高清的结构"(我的意思是分区)有关.

位于硬盘上的文件不会自动加载到内存中,因此它没有内存地址.一旦你阅读了它,它的一部分(如果不是全部)当然会被复制到你提供的内存中,这不是文件的固有属性.(文件系统检索属于文件的块,并按照我们习惯的方式显示"它们,作为单个单元",文件)

总结:文件没有内存地址.物理地址可以是保存数据(和元数据,例如 inode) 的文件,或者只是第一个块(但如果数据块是 N,则 N+1 不能属于同一个文件 - 这些块不必是一个相邻的).要了解它们,您必须分析您使用的文件系统的结构.我不知道是否有 API 可以轻松检索它们,但在最坏的情况下,您可以分析文件系统的源代码...祝您好运!

2C 函数被翻译成汇编.如果您遵守 C 调用约定,则可以直接在汇编中编写C 函数".尝试阅读this这个适用于 x86.

3你可以从 asm 调用 windows API.忘记 MS-DOS,MS-DOS 已经死了,MS-DOS 不是 Windows,cmd 是一种模拟"……确实不,不是模拟而是类似于 MS-DOS 用户的命令行界面被用来.但这并不完全相同,即没有您可以使用的 MS-DOS 系统中断.Iczelion 的汇编教程,虽然很旧,但可能是一个有趣的资源.(如果链接过期,请尝试使用 wayback machine)

4我没有Win7,也没有在windows上安装nasm,所以我什么也说不出来.

I'm using the GoAsm assembler on a Windows 7 - 64 bit OS and I'll be asking you a few (not so dumb) questions.

First question :

How can I find the physical address of a file ?Let's suppose file "Text.txt" is at the root of my C: partition.Is there a way to get the exact memory address where this file is ?

Second question :

Is it possible to call a routine which will just do like if I invoked a C function ?

(i.e. : Consider a C function "WriteToScreen", is it possible to have the same function, but in assembler format, that means without having the need to use high-level invokes to do that work ?

Third question :

Are there somewhere on the net some include files for GoAsm containing useful routines like (move, copy, edit, erase) commands ? I've first thought of ms-dos interrupts but I can't manage to get them to work without crashing the program. I guess it just not compatible with Windows OS even though the command prompt acts like ms-dos... ?

Fourth question :

I've heard from different sources and myself that NASM works pretty bad on Win7 x64, is it just true, or am I doing it the wrong way ?

解决方案

1An hard drive, from a logical point of view, can be seen as a sequence of "blocks" (the more common name is sectors). How these blocks are organized physically on the disks can be disregarded, but the driver must know someway how to get data of course, though you send to modern hd driver "high level" commands that, as far as you know, are not strongly related to where data physically are (you can say "read the block 123", but there's no extern evidence of where that block lives).

However this way you can "name" a block with a number, and say e.g. that block 0 is the MBR. Each block contains several bytes (512, 1024...). Not all used blocks contain actual data of a file, in fact there are metainformations of any sort, depending on the filesystem but even related to the "structure" of the hd (I mean, partitions).

A file located on an hd is not automatically loaded into memory, so it has no memory address. Once you read it, piece of it if not all are of course copied into the memory you give, which is not an intrinsic property of the file. (Filesystems retrieve the blocks belonging to the file and "show" them as we are used to see them, as a single "unit", the file)

Summarizing: files have no memory address. The physical address could be the set of blocks holding data (and metadata, like inodes ) of the file, or just the first block (but if a block of data is N, N+1 could not belong to the same file - the blocks need no to be one next to the other). To know them, you have to analyse the structure of the filesystem you use. I don't know if there's an API to retrieve them easily, but in the worst case you can analyse the source code of the filesystem... good luck!

2C functions are translated into assembly. If you respect the C calling convention, you can write a "C function" directly in assembly. Try reading this and this for x86.

3You can call windows API from asm. Forget MS-DOS, MS-DOS is dead, MS-DOS is not Windows, the cmd is a sort of "emulation"... indeed no, not an emulation but just a command line interface that resemble the one MS-DOS users was used to. But it is not exaclty the same, i.e. there are no MS-DOS system interrupt you can use. Iczelion's assembly tutorials, though old, could be an interesting resource. (If links expire, try with the wayback machine)

4I do not own Win7 and never installed nasm on windows, so I can't say anything about.

这篇关于如何找到文件的物理地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 10:39