简单的方法来获取文件大小在x86汇编语言 [英] Simple way to Get filesize in x86 Assembly Language

查看:254
本文介绍了简单的方法来获取文件大小在x86汇编语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经打开的程序集的文件,并有寄存器EAX该文件中的文件句柄。我怎么会去获取文件的大小,所以我可以为它分配足够的缓冲空间?结果

我在这里研究的另一个讨论使用 sys_fstat(28)系统调用来获取文件的统计信息表明,但不能执行它...

 在获得文件大小#我的尝试_test:MOVL文件句柄,EBX%句柄#move(文件描述符)到EBX
        MOVL $ 28%EAX #fstat系统调用
        诠释$#0x80的总是在这里不知道有-14最终为什么


解决方案

我的解决办法 - 只要使用.lcomm创建所有命名变量位置

  MOVL inputfile中,EBX%文件#Move进入处理程序EBX系统调用
MOVL $ 0x6c,%eax中#Stat Sys系统调用到EAX
莱亚尔statlocation,ECX%预留#Move位置stat结构成
INT 0x80的$系统#Execute电话
MOVL 20(%ECX),%eax中排名第20到大小可变的位置,大小现在是EAX

Assuming that I have opened a file in assembly and have the file handle for that file in register eax. How would I go about getting the size of the file so I can allocate enough buffer space for it?

I researched another discussion here that suggested using the sys_fstat(28) system call to get the file stats but couldn't implement it...

#My attempt at getting the file size

_test:  movl    filehandle, %ebx  #move filehandle (file descriptor) into ebx
        movl    $28, %eax         #fstat syscall
        int $0x80             # always end up with -14 in here not sure why

解决方案

My solution -- Just use .lcomm to create locations for all the named variables

movl    inputfile, %ebx         #Move file handler into ebx for system call
movl    $0x6c, %eax          #Stat Sys Call into eax
leal    statlocation, %ecx      #Move reserved location for stat structure into
int     $0x80                    #Execute System Call
movl    20(%ecx), %eax          #20 to location of size variable, size is now in eax

这篇关于简单的方法来获取文件大小在x86汇编语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆