Skip to content

Instantly share code, notes, and snippets.

@Saket-Upadhyay
Created June 7, 2021 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saket-Upadhyay/12ffd0a8321beba8542079b340b363d0 to your computer and use it in GitHub Desktop.
Save Saket-Upadhyay/12ffd0a8321beba8542079b340b363d0 to your computer and use it in GitHub Desktop.
Code to teach symbolic execution in Linux.
// MIT License
//
// Copyright (c) 2021 Saket Upadhyay
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <iostream>
#include <string>
std::string get_selfpath(const char *namearg)
{
return namearg;
}
int main(int argc, char const *argv[])
{
if (get_selfpath(argv[0]) == "add")
{
std::cout << "ADD MODE" << std::endl;
if (argc >= 3)
{
int sum = 0;
for (size_t i = 1; i < argc; i++)
{
sum = sum + atoi(argv[i]);
}
std::cout << "The result of addition is = " << sum << std::endl;
return 0;
}
else
{
std::cout << "Not enough input." << std::endl;
}
return 0;
}
else if (get_selfpath(argv[0]) == "sub")
{
std::cout << "SUB MODE" << std::endl;
if (argc >= 3)
{
int sum = atoi(argv[1]);
for (size_t i = 2; i < argc; i++)
{
sum = sum - atoi(argv[i]);
}
std::cout << "The result of subtraction is = " << sum << std::endl;
return 0;
}
else
{
std::cout << "Not enough input." << std::endl;
}
}
else if (get_selfpath(argv[0]) == "mul")
{
std::cout << "MUL MODE" << std::endl;
if (argc >= 3)
{
int sum = 1;
for (size_t i = 1; i < argc; i++)
{
sum = sum * atoi(argv[i]);
}
std::cout << "The result of multiplication is = " << sum << std::endl;
return 0;
}
else
{
std::cout << "Not enough input." << std::endl;
}
}
else
{
return -1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment