Search code examples
assemblygrepreverse-engineering

Is there any fast way to find assembler source code?


I am trying to find dietlibc source code for basic functions like printf, puts, etc. Currently using grep {command_name} -r -A20 in the folder where they should be, but it seems really exhausting. Is there any faster way?

Another known way is to reverse object files for each function, but i think it will take more time.


Solution

  • I've already found folder with *.S files, but for the most basic functions such as printf() there are only .c files

    Many functions are written in C, and they're written in terms of other C functions and/or assembly language functions. So printf() (in .../libstdio/printf.c), for example, uses vprintf(), which uses __v_printf() (in .../lib/__v_printf.c), which uses strcpy() and strlen() etc., which have ARM implementations in .../arm. Some functions are implemented both in C and assembly, probably because assembly provides a performance boost on some architectures but not others (or possibly because nobody has gotten around to writing assembly versions for some architectures).

    So, if you're looking for printf.S, you're probably not going to find it for any architecture because it's a relatively high level function that calls other functions. That means that you can port dietlibc to a new architecture without having to write assembly versions of every function in the library; you only have to implement a small set of essential routines. Read the PORTING file to get an idea of what has to be done to port to a new architecture, and that'll help you understand what those core routines are. Or, just look in several of the architecture-specific directories and see what they implement.