![]() |
[ASM] How to get command line arguments - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Assembly (https://sinister.ly/Forum-Assembly) +--- Thread: [ASM] How to get command line arguments (/Thread-ASM-How-to-get-command-line-arguments) |
[ASM] How to get command line arguments - Deque - 11-08-2012 I already provided an example how to use c functions in assembly and stated differences between 32 bit and 64 bit systems: http://www.hackcommunity.com/Thread-ASM-Calling-C-functions-on-64bit-architecture It is pretty much the same with command line arguments. main is just a function like every function else. You treat it the same way. The declaration is the following: Code: int main(int argc, char** argv) For those who don't know C: int argc - contains the number of command line arguments char** argv - contains addresses to the command line argument strings You can imagine it like that: Code: argv | address1 | address2 | address 3 | On a 32 bit system you can jump to the next command line argument address by adding 4 bytes (=32 bit) to the previous address (i.e. jumping from address1 to address2). A 64 bit system needs 8 byte to jump to the next address that argv contains. I will show how to get and print command line arguments on the screen. The following is an example I found on http://www.cs.lmu.edu/~ray/notes/nasmexamples/ It is written for 32 bit Windows. Here you get the arguments argv and argc from the stack. Code: ; ---------------------------------------------------------------------------- To use the same in 32 bit Linux you just have to remove the underscores: Code: ; create executable this way: In a 64 bit system the arguments are not in the stack but in the general purpose registers. So the code above would not work. The order of the registers is the following: %rdi, %rsi, %rdx, %rcx, %r8 and %r9 That means argc is in %rdi and argv in %rsi. Here is my 64 bit version of the same program (linux). It uses the 64 bit registers and adds 8 byte to jump to the next address of the next command line argument. Code: ; create executable this way: An example output: Quote:[deque@desolate echo]$ ./echo bla la ka2 Here is a makefile for the 64 bit version, so you only need to type "make" to create an executable file: Code: echo: echo.o Deque RE: [ASM] How to get command line arguments - bluedog.tar.gz - 11-08-2012 No responds yet? Anyway very nice thread. I never done ASM and I am fairly a 'noobie' in C. I might try this out sometime. Thanks RE: [ASM] How to get command line arguments - H4R0015K - 11-08-2012 very useful For me! thanks for sharing! RE: [ASM] How to get command line arguments - shortcircuit - 01-08-2013 Nice tutorial, although ASM is harder to use for tasks that could be implemented easily in C/C++, so for everyday usage I never find myself needing command-line arguments. RE: [ASM] How to get command line arguments - hacxx - 01-25-2025 ASM? ChatGPT is becoming very good in replacing programmers with AI. I got an idea a few months ago to convert TSRH ASM Keygens from ASM to JS and ChatGPT was able to convert half of the code, it wasn't enough to get a full keygen. Something for the future. |