2017-03-15 8 views
2

미리로드 사용자 정의하면 strchr() - 우분투) (I 그 strchr과 구현

 global strchr 
strchr: 
     cmp  byte[rdi], 0 
     je  end 
     cmp  [rdi], sil 
     je  end 
     add  rdi, 1 
     jmp  strchr 
end: mov  rax, rdi 
     ret 

내가 사용하는 .so로 미리로드 ,

export LD_PRELOAD=abs/path/to/lib.so 

우분투 16.04 충돌 충돌합니다. 때로는 그것이 완료 crahses, 때로는 표시 SIGILL (손상된 데이터?).

opensuse 4를 사용하여 미리로드하면 작동합니다.

왜 그런가? 마이클 페치에

+0

가 어떻게 공유 객체를 구축합니까? 다른 시스템에서 다시 빌드하고 (한 바이너리를 다른 바이너리로 복사하지 않고)합니까? –

+0

@Someprogrammerdude nasm -f elf64 asm.asm을 사용하여 각 시스템에서 빌드 한 다음 gcc -shared asm.o -o lib.so (Makefile) – NanoPish

+1

이 함수는 반환하지 않으므로'strchr'을 따르지 않습니다. 문자가 발견되지 않으면 NULL 포인터. –

답변

1

감사 :

문자가 발견되지 않는 경우는 NULL을 반환하지 않습니다에 대한 strchr과는() 매뉴얼을 준수하지 않습니다.

고정하면 strchr() :

global strchr 
strchr: 
     cmp  [rdi], sil;first check for character (useful if user searches '\0') 
     je  end 
     cmp  byte[rdi], 0;then if it is EoS and the character is not in the string, return NULL 
     je  eos 
     add  rdi, 1 
     jmp  strchr 
eos: mov  rax, 0 
     ret 
end: mov  rax, rdi 
     ret