All pastes #837249 Raw Edit

Stuff

public text v1 · immutable
#837249 ·published 2007-12-29 13:49 UTC
rendered paste body
 .include "linux.s"
 .include "record-def.s"
 
 .section .bss
  .lcomm age_buffer, 4
 
 .equ ST_DESCRIPTOR, -4
 
 .section .text
 .globl _start
_start:
 movl %esp, %ebp
 subl $8, %esp
 
 movl $SYS_OPEN, %eax
 movl $ST_ARGV_1(%ebp), %ebx
 movl $2, %ecx
 movl $0666, %edx
 int $LINUX_SYSCALL
 
 movl %eax, ST_DESCRIPTOR(%ebp)
 
 movl $0, %edi
loop_begin:
 movl $RECORD_SIZE, %esi
 imull %edi, %esi
 addl $RECORD_AGE, %esi
 
 movl $0, %edx
 movl %esi, %ecx
 movl ST_DESCRIPTOR(%ebp), %ebx
 movl $19, %eax
 int $0x80
 
 #should be at the first byte of the age, read 4 bytes
 
 movl $3, %eax
 movl ST_DESCRIPTOR(%ebp), %ebx
 movl $age_buffer, %ecx
 movl $4, %edx
 int $0x80
 
 cmpl $0, %eax
 jle loop_end
 #didn't know what lseek returned if it hit EOF
 incl age_buffer 
 
 movl $19, %eax
 movl ST_DESCRIPTOR(%ebp), %ebx
 movl $-4, %ecx
 movl $1, %edx
 int $0x80
 
 #should be back by 4 bytes
 
 movl $4, %eax
 movl ST_DESCRIPTOR(%ebp), %ebx
 movl $age_buffer, %ecx
 movl $4, %edx
 int $0x80
 
 incl %edi
 jmp loop_begin
loop_end:
 movl $SYS_CLOSE, %eax
 movl $ST_DESCRIPTOR(%ebp), %ebx
 int $0x80
 movl $1, %eax
 movl $0, %ebx
 int $0x80