GDB option for 'python - c' - gdb

in this document (https://www.exploit-db.com/docs/28553.pdf), what is "r python -c" doing? Thanks.

r is running your program.
Arguments to run are program arguments to pass to your executable.
In this case arguments passed are calculated by running a python expression print "A"*264.
So this runs you program giving it a string consisting of 264 A characters as an argument.

Related

Creating a bar from repeated characters in python [duplicate]

Let's say I have a C program, and I run it from bash:
$ ./a.out 123 *
The program would output all the command line arguments,
but it will show these instead:
Argument 1: 123
Argument 2: a.out
What can I do in my program to fix this?
The shell is replacing the asterisk with the name of each file in the directory.
To pass a literal asterisk, you should be able to escape it:
$ ./a.out 123 \*
Another option is to use set -f to turn off expansion. Compare:
echo *
v.s.
set -f
echo *
You can turn it back on with set +f:
set -f
echo *
set +f
echo *
You can quote it in the shell
./a.out 123 '*'
There is nothing you can do in your program, because the * expansion is done by the shell (in contrast to Windows, where it's done by the program).
Another alternative is to start your script with #!/bin/bash -f as the first line, which will allow you to accept literal strings as arguments (including the asterisk), and thus that will allow you to run ./a.out 123 * with the desired input, but note that bash -f disables expansions completely, and that can have adverse effects in your script depending on what you do.
This doesn't have anything to do with your program.
The * is a wildcard in Bash, it means "all files in the current directory". If you want to pass an asterisk as an argument to your program, you do it the same way you do it with every other program: you escape it with a backslash or quote it.

How to enter command line arguments in python notepad++?

I am practicing beginner's Python in Notepad++ and I am stuck when trying to give command line arguments during runtime. When I run the code, I get ValueError: need more than 1 value to unpack, and I can't give input arguments. I tried using Python plugins PyNPP, NppExec and even tried running it through Notepad++'s inbuilt console but I'm still unable to give input. There is no syntactical error in the code:
from sys import argv
script, first, second, third = argv
print "the script is called : ", script
print "your first variable is : ", first
print "your second variable is :", second
print "your third variable is: ", third
Please explain how I can give arguments during runtime. I have searched in Google for possible solutions.
argv is a list of arguments to the python script. It should not be defined inside a script. An example:
python script.py first second third
In this case
sys.argv[0] is script.py
sys.argv[1] is first
sys.argv[2] is second
sys.argv[3] is third

Pass \ in command line arguments of C++

I am working on a C++ program where one of the command line arguments needs to be a passed a regex. For example: abc.exe --option ab\[0\]
When I access the option value from inside the program, it becomes ab\\[0\\] which becomes a different regex.
Inside the program when I try to replace \\[ with \[ using boost::replace_all, the result is [ which also is not the intended output for me.
So, any suggestions on how to pass and retain \[ this while passing it through command line arguments
You can quote the parameter:
abc.exe --option "ab\[0\]"
Or use the shell escape sequence:
abc.exe --option ab\\[0\\]
Did you try these?
It was a problem with how visual studio displays the symbol. When I looked on the ASCII code of the symbol, it was alright. Thanks #ScottK for helping me to debug this through your comments

How to pass a very very long list of arguments to a program?

I'm coding and running programs to which I need to pass a long list of data files for analysis, sometimes a few hundred thousands. The problem is that the argument list can be so long that the system (Unix) refuses to run it, outputting:
bash: ./yourProgram: Argument list too long
Is there a environment variable I can change to bypass this obstacle?
The only solution I can think of is writing my program list in a separate file (using ls ... >) and then reading each file line by line. Would you know of anything simpler?
ps: my programs are written in C++ if it matters
Better to have an environment variable defined with values as space delimited list of items, for example, define as
export MYLIST=a b ab cd ef
Within your program, use getenv("MYLIST") to get the value as char *, and tokenize to get individual values
I would just pass it as stdin..
echo "file1 file2 file3" | ./program
How to pass a very very long list of arguments to a program?
place the arguments in a file
redirect the file to the standard input of the application, on startup
bash$ echo "arg1 arg2 arg3 ... argn" >> inputs.txt
bash$ ./yourProgram < inputs.txt
This has the advantage of storing your arguments (so that for a subsequent execution, you only need to run the second line).

Why does FINDSTR behave differently in powershell and cmd?

The following command pipes the output of echo to findstr and tries to match a regular expression with it. I use it to check if the echoed line only consists of (one or more) digits:
echo 123 | findstr /r /c:"^[0-9][0-9]*$"
The expected output of findstr is 123, which means that the expression could be matched with this string. The output is correct when I execute the command with powershell.exe.
Executing the command in cmd.exe however does not give a match. It only outputs an empty line and sets %ERRORLEVEL% to 1, which means that no match was found.
What causes the different behavior? Is there a way to make this command run correctly on cmd as well?
My OS is Windows 7 Professional, 64 Bit.
In Powershell the command echoes the string 123 to the pipeline and that matches your regular expression.
In cmd, your command echos 123<space> to the pipeline. The trailing space isn't allowed for in your regular expression so you don't get a match.
Try:
echo 123| findstr /r /c:"^[0-9][0-9]*$"
and it will work just fine. Or just switch entirely to Powershell and stop having to worry about the vagaries of cmd.exe.
Edit:
Yes, cmd and powershell handle parameters very differently.
With cmd all programs are passed a simple text command line. The processing that cmd performs is pretty minimal: it will terminate the command at | or &, removes i/o redirection and will substitute in any variables. Also of course it identifies the command and executes it. Any argument processing is done by the command itself, so a command can choose whether spaces separate arguments or what " characters mean. Mostly commands have a fairly common interpretation of these things but they can just do their own thing with the string they were given. echo does it's own thing.
Powershell on the other hand has a complex syntax for arguments. All of the argument parsing is done by Powershell. The parsed arguments are then passed to Powershell functions or cmdlets as a sequence of .Net objects: that means you aren't limited to just passing simple strings around. If the command turns out not to be a powershell command and runs externally it will attempt to convert the objects into a string and puts quotes round any arguments that have a space. Sometimes the conversion can be a bit confusing, but it does mean that something like this:
echo (1+1)
will echo 2 in Powershell where cmd would just echo the input string.
It is worth always remembering that with Powershell you are working with objects, so for example:
PS C:\> echo Today is (get-date)
Today
is
17 April 2014 20:03:15
PS C:\> echo "Today is $(get-date)"
Today is 04/17/2014 20:03:20
In the first case echo gets 3 objects, two strings and a date. It outputs each object on a separate line (and a blank line when the type changes). In the second case it gets a single object which is a string (and unlike the cmd echo it never sees the quote marks).