- 浏览: 436855 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (158)
- J2SE (15)
- c/c++ (17)
- linux & ubuntu (20)
- js (18)
- algorithm (21)
- android (1)
- software (3)
- svn (1)
- db (6)
- other (19)
- css (5)
- go (1)
- html 5 (3)
- computer science (1)
- php (3)
- 创业 (8)
- EJB & jboss (1)
- TDD (1)
- jsp & servlet (2)
- http, tcp & ip (2)
- hibernate (1)
- json (1)
- 乐 (2)
- ps (2)
- netbeans (1)
- extjs (2)
- eclipse (4)
- 项目管理 (1)
- varnish (2)
- study abroad (1)
- python (1)
- erlang (1)
- math (1)
- shell (1)
- assembly (4)
- lucene (1)
- web (1)
- http (1)
- tcp & ip (1)
最新评论
-
yiguxianyun:
...
css li 不换行 -
stdayong:
...
netbeans 中使用 maven -
程序猿_星:
为啥会中文乱码啊
servlet 以 gzip 格式返回数据 -
huanhuan519:
感谢分享~
gdb 调试工具 -
heyl1234:
写过些js,对css还不熟。谢谢~
css li 不换行
assembly - file
- 博客分类:
- assembly
assembly operate file,
------
unix/linux file
linux use the same file concept of unix, any file could be accessed as a sequential stream of bytes,
step to use file:
* open file
open file by file path, and will get a number called file descriptor, which will be used to refer to the file later,
* read/write file
then read/write file with file descriptor,
* close file
when done, close file, and the file descriptor will be released,
------
file relative syscalls
include:
* open file
request:
%eax: syscall number, 5,
%ebx: address of file name,
%ecx: open mode
%edx: permission
response:
%eax: file descriptor which >=0, or error number which <0,
* close file
request:
%eax: syscall number, 6,
%ebx: file descriptor,
* read file
request:
%eax: syscall number, 3,
%ebx: file descriptor,
%ecx: address of buffer
%edx: size(byte) to read
response:
%eax: size(byte) that actural read which >=0 (0 means end of file), or error code which <0,
* write file
request:
%eax: syscall number, 3,
%ebx: file descriptor,
%ecx: address of buffer
%edx: size(byte) to write
response:
%eax: size(byte) that actural write which >=0, or error code which <0,
------
file open mode
* 0
read only
* 03101
write only, create file if not exist, clear file first if exist,
* ..
------
permission
same as linux permission, in octal,
e.g.
0644
0666
------
standard & special files
standard file:
linux has at least 3 standard file opened when started, and their file descriptor is already available, need not to open/close them,
include:
* STDIN
standard input, represent keyboard usually, read only,
file descriptor = 0,
use enter to input a line, ctrl+c to stop program, the last line without enter will be ignored,
* STDOUT
standard output, represent screen display usually, write only,
file descriptor = 1,
* STDERR
standard error, represent screen display usually, write only, error msg usually go to this file,
file descriptor = 2,
special file:
linux treat everything as file, include special file which are actural not file,
include: input/output system, network connection, serial port, pipe that processes communicate with each other, .. ,
some of special file are open/close by different methods than regular file, but they can be read/write the same as regular file,
------
end of file
read, return readed byte count into %eax, 0 means end of file,
------
code
file_copy.s
# file copy # # command line param: # first param: # input file path # second param: # output file path # .section .data # constants # stack position .equ ST_ARGC, 0 # param count .equ ST_ARGV_0, 4 # program file name .equ ST_ARGV_1, 8 # input file name .equ ST_ARGV_2, 12 # output file name .equ ST_SIZE_RESERVE, 8 # reserve size .equ ST_FD_IN, -4 # file descriptor - input file .equ ST_FD_OUT, -8 # file descriptor - output file # syscall number .equ SYS_OPEN, 5 .equ SYS_CLOSE, 6 .equ SYS_READ, 3 .equ SYS_WRITE, 4 .equ SYS_EXIT, 1 # file open mode .equ MODE_RDONLY, 0 .equ MODE_WRONLY_TRUNC, 03101 # syscall interrupt .equ LINUX_SYSCALL, 0x80 # end of file .equ END_OF_FILE, 0 # return value of read .section .bss .equ BUF_SIZE, 1024 # BUF_DATAfer size in byte .lcomm BUF_DATA, BUF_SIZE # a buffer .section .text .globl _start _start: movl %esp, %ebp # backup %esp subl $ST_SIZE_RESERVE, %esp # reserve stack jmp file_open file_open: open_input: movl $SYS_OPEN, %eax movl ST_ARGV_1(%ebp), %ebx movl $MODE_RDONLY, %ecx movl $0644, %edx int $LINUX_SYSCALL movl %eax, ST_FD_IN(%ebp) open_output: movl $SYS_OPEN, %eax movl ST_ARGV_2(%ebp), %ebx movl $MODE_WRONLY_TRUNC, %ecx movl $0644, %edx int $LINUX_SYSCALL movl %eax, ST_FD_OUT(%ebp) jmp file_read # read/write until end of file file_read: movl $SYS_READ, %eax movl ST_FD_IN(%ebp), %ebx movl $BUF_DATA, %ecx movl $BUF_SIZE, %edx int $LINUX_SYSCALL cmpl $END_OF_FILE, %eax jle file_close jmp file_write file_write: movl %eax, %edx movl $SYS_WRITE, %eax movl ST_FD_OUT(%ebp), %ebx int $LINUX_SYSCALL jmp file_read file_close: close_input: movl $SYS_CLOSE, %eax movl ST_FD_IN(%ebp), %ebx int $LINUX_SYSCALL close_output: movl $SYS_CLOSE, %eax movl ST_FD_OUT(%ebp), %ebx int $LINUX_SYSCALL movl %ebp, %esp # restore %esp jmp exit exit: movl $SYS_EXIT, %eax int $LINUX_SYSCALL
file_toupper.s
# file to upper case # # command line param: # first param: # input file path # second param: # output file path # .section .data # constants # stack position .equ ST_ARGC, 0 # param count .equ ST_ARGV_0, 4 # program file name .equ ST_ARGV_1, 8 # input file name .equ ST_ARGV_2, 12 # output file name .equ ST_SIZE_RESERVE, 8 # reserve size .equ ST_FD_IN, -4 # file descriptor - input file .equ ST_FD_OUT, -8 # file descriptor - output file # syscall number .equ SYS_OPEN, 5 .equ SYS_CLOSE, 6 .equ SYS_READ, 3 .equ SYS_WRITE, 4 .equ SYS_EXIT, 1 # file open mode .equ MODE_RDONLY, 0 .equ MODE_WRONLY_TRUNC, 03101 # syscall interrupt .equ LINUX_SYSCALL, 0x80 # end of file .equ END_OF_FILE, 0 # return value of read .section .bss .equ BUF_SIZE, 1024 # BUF_DATAfer size in byte .lcomm BUF_DATA, BUF_SIZE # a buffer .section .text .globl _start _start: movl %esp, %ebp # backup %esp subl $ST_SIZE_RESERVE, %esp # reserve stack jmp file_open file_open: open_input: movl $SYS_OPEN, %eax movl ST_ARGV_1(%ebp), %ebx movl $MODE_RDONLY, %ecx movl $0644, %edx int $LINUX_SYSCALL movl %eax, ST_FD_IN(%ebp) open_output: movl $SYS_OPEN, %eax movl ST_ARGV_2(%ebp), %ebx movl $MODE_WRONLY_TRUNC, %ecx movl $0644, %edx int $LINUX_SYSCALL movl %eax, ST_FD_OUT(%ebp) jmp file_read # read/write until end of file file_read: movl $SYS_READ, %eax movl ST_FD_IN(%ebp), %ebx movl $BUF_DATA, %ecx movl $BUF_SIZE, %edx int $LINUX_SYSCALL cmpl $END_OF_FILE, %eax jle file_close pushl $BUF_DATA # param 1 pushl %eax # backup %eax, as well as param 0 call toupper popl %eax # restore %eax addl $4, %esp # restore %esp jmp file_write file_write: movl %eax, %edx movl $SYS_WRITE, %eax movl ST_FD_OUT(%ebp), %ebx movl $BUF_DATA, %ecx int $LINUX_SYSCALL jmp file_read file_close: close_input: movl $SYS_CLOSE, %eax movl ST_FD_IN(%ebp), %ebx int $LINUX_SYSCALL close_output: movl $SYS_CLOSE, %eax movl ST_FD_OUT(%ebp), %ebx int $LINUX_SYSCALL movl %ebp, %esp # restore %esp jmp exit exit: movl $SYS_EXIT, %eax int $LINUX_SYSCALL # a function that convert a buffer in memory from lower case to upper case # param: # first param: # buffer size, in byte, # second param: # start address of buffer # storage: # %eax: # start address of buffer # %ebx: # buffer size # %cl: # store each char in buffer # %edi: # current buffer offset .type toupper, @function toupper: .equ LOWER_A, 'a' .equ LOWER_Z, 'z' .equ LOWER_TO_UPPER, 'a'-'A' toupper_begin: pushl %ebp # backup %ebp movl %esp, %ebp movl 8(%ebp), %ebx # param 0 - actual buf size movl 12(%ebp), %eax # param 1 - buf location movl $0, %edi # init %edi for loop jmp toupper_loop toupper_loop: cmpl %edi, %ebx jle toupper_end movb (%eax, %edi, 1), %cl # read 1 byte cmpb $LOWER_A, %cl jl toupper_loop_end cmpb $LOWER_Z, %cl jg toupper_loop_end subb $LOWER_TO_UPPER, %cl # lower to upper movb %cl, (%eax, %edi, 1) # change buf toupper_loop_end: incl %edi jmp toupper_loop toupper_end: movl %ebp, %esp popl %ebp ret
file_stdin.s
# file - stdin, save input of stdin to a file, # # params: # first param: output file path # keys: # enter -> to input a line, # ctrl+c -> to stop program, # .section .data .equ SYS_EXIT, 1 .equ SYS_READ, 3 .equ SYS_WRITE, 4 .equ SYS_OPEN, 5 .equ SYS_CLOSE, 6 .equ MODE_REONLY, 0 .equ MODE_WTONLY_TRUNC, 03101 .equ FD_STDIN, 0 .equ LINUX_SYSCALL, 0x80 .equ EOF, 0 .equ ST_ARGC, 4 # param count .equ ST_ARGV_0, 8 # program file path .equ ST_ARGV_1, 12 # output file path .equ ST_RESERVE_SIZE, 8 .equ ST_FD_OUTPUT, -4 .equ ST_LAST_READ_SIZE, -8 .section .bss .equ BUF_SIZE, 100 .lcomm BUF_DATA, BUF_SIZE+1 .section .text .globl _start _start: pushl %ebp movl %esp, %ebp subl $ST_RESERVE_SIZE, %esp jmp file_open file_open: movl $SYS_OPEN, %eax movl ST_ARGV_1(%ebp), %ebx movl $MODE_WTONLY_TRUNC, %ecx movl $0644, %edx int $LINUX_SYSCALL movl %eax, ST_FD_OUTPUT(%ebp) read: movl $SYS_READ, %eax movl $FD_STDIN, %ebx movl $BUF_DATA, %ecx movl $BUF_SIZE, %edx int $LINUX_SYSCALL movl %eax, ST_LAST_READ_SIZE(%ebp) write: movl $SYS_WRITE, %eax movl ST_FD_OUTPUT(%ebp), %ebx movl $BUF_DATA, %ecx movl ST_LAST_READ_SIZE(%ebp), %edx int $LINUX_SYSCALL jmp read file_close: movl $SYS_CLOSE, %eax int $LINUX_SYSCALL end: movl %ebp, %esp popl %ebp movl $SYS_EXIT, %eax int $LINUX_SYSCALL
file_stdout.s
# file - stdout, read file and print to stdout, similar to cat command # # params: # first param: input file path # .section .data .equ SYS_EXIT, 1 .equ SYS_READ, 3 .equ SYS_WRITE, 4 .equ SYS_OPEN, 5 .equ SYS_CLOSE, 6 .equ MODE_REONLY, 0 .equ MODE_WTONLY_TRUNC, 03101 .equ FD_STDIN, 0 .equ FD_STDOUT, 1 .equ LINUX_SYSCALL, 0x80 .equ EOF, 0 .equ ST_ARGC, 4 # param count .equ ST_ARGV_0, 8 # program file path .equ ST_ARGV_1, 12 # input file path .equ ST_RESERVE_SIZE, 8 .equ ST_FD_INPUT, -4 .equ ST_LAST_READ_SIZE, -8 .section .bss .equ BUF_SIZE, 100 .lcomm BUF_DATA, BUF_SIZE .section .text .globl _start _start: pushl %ebp movl %esp, %ebp subl $ST_RESERVE_SIZE, %esp jmp file_open file_open: movl $SYS_OPEN, %eax movl ST_ARGV_1(%ebp), %ebx movl $MODE_REONLY, %ecx movl $0644, %edx int $LINUX_SYSCALL movl %eax, ST_FD_INPUT(%ebp) read: movl $SYS_READ, %eax movl ST_FD_INPUT(%ebp), %ebx movl $BUF_DATA, %ecx movl $BUF_SIZE, %edx int $LINUX_SYSCALL movl %eax, ST_LAST_READ_SIZE(%ebp) write: cmpl $0, %eax jle file_close movl $SYS_WRITE, %eax movl $FD_STDOUT, %ebx movl $BUF_DATA, %ecx movl ST_LAST_READ_SIZE(%ebp), %edx int $LINUX_SYSCALL jmp read file_close: movl $SYS_CLOSE, %eax int $LINUX_SYSCALL end: movl %ebp, %esp popl %ebp movl $SYS_EXIT, %eax int $LINUX_SYSCALL
------
相关推荐
Spring Boot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip
装配状态从FASTA和FASTQ文件获取程序集统计信息。内容安装如果在安装程序集统计信息时遇到问题,请与本地系统管理员联系。...用法从文件列表中获取统计信息: assembly-stats file.fasta another_file.fastq从
SAE J2286-2015 Vendor Component Program Data File Interface for OEM Assembly Operations - 完整英文版(22页).pdf
<descriptor>src/main/resources/config/assembly/assembly.xml <phase>package <goal>single 2、添加assembly.xml文件 <assembly xmlns=...
source insight的arm 汇编语言支持文件,支持标号常量变量指令伪指令着色高亮显示,比在官网上的文件强,需要的下。缺陷是宏定义的定义体及标号不能识别。
Some Final Comments on the MOV Instructions <br>4.9 Laboratory Exercises 4.9.1 The UCR Standard Library for 80x86 Assembly Language Programmers 4.9.2 Editing Your Source Files 4.9.3 The ...
***请支持开源*** 汇编大师Richard Blum的经典AT&T汇编教程英文原版(没有中文版) 下面是书中的介绍 Introduction ... This chapter shows how to use the Linux file-handling system calls to read,...
/your/path/to/spark/bin/spark-submit --properties-file cassandra-example.conf --class org.koeninger.HelloWorldExample target/scala-2.10/cassandra-example-assembly-0.1-SNAPSHOT.jar 要将 jar 添加到 ...
渗透加载器 从pbf文件中提取数据并将其存储在文件夹中(即将推出:到SimplexSpatial服务器中)。... -i, --in <value> input folder or file -o, --out <value> output folder -t, --type <value> export type
ld -s -o file file.o ./file 视窗 对于 Windows,您可以使用alink 、 golink或ld : nasm -f win32 "tutorial-assembly\shellcode_kernel_win.s" alink -entry _start -subsys con -oPE "tutorial-assembly\...
3. Detected lock file Job-1.lck. Please confirm that no other applications are a
source insight官方给arm的clf不太好用,加了些关键词,加了些custome parsing
Dracor-Saga-Buildfile:Dracor Saga-Buildfile
Simplify the deployment of your application by packaging it in one file (Dependency Embedding with compression and encryption, and Dependency Merging). Remove all non-useful code and metadata ...
It can quickly disassemble binary file to a readable assembly listing. USAGE mdisasm [-a address] [-o offset] [-s size] [-p] input-file OPTIONS -a address Set disassemble address to specified. ...
Simple-FASM-window-with-HIGHLY-EXCEPTED-DROP-FILE-FUNCTION 你可以用这个窗口做任何你想做的事。 所有你想要的。 此外,由于某种原因,拖放选项不起作用。 现在弄好了,以后再补。 用 FASM 1.71.31 制作。 时间...
In-line assembly not allowed -----------------不允许使用行间汇编 Incompatible storage class -----------------存储类别不相容 Incompatible type conversion --------------------不相容的类型转换 ...
|-- PCBA_Doc_280040-003/ # Folder containing documents for board assembly |-- BOM-280040-003.xlsx # Bill of Materials in Excel format |-- PCBA_Doc_280040-003.PDF # PCBA Manufacturing Documentation in...
The File-Handling Sequence 453 Opening and Closing Files 454 Access types 455 UNIX permissions 456 Open file code 458 Open error return codes 459 Closing files 460 Writing to Files 460 A simple write ...
——————————————————————————– Could not load file or assembly ‘AjaxPro.2’ or one of its dependencies. 拒绝访问。 Description: An unhandled exception ...