Skip to content

Commit

Permalink
PINCE_USER_FILES is now created when PINCE is invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
korcankaraokcu committed Apr 9, 2017
1 parent 669fea3 commit bd1f3c4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
2 changes: 0 additions & 2 deletions PINCE.py
Original file line number Diff line number Diff line change
Expand Up @@ -2979,14 +2979,12 @@ def show_trace_info(self, trace_data=""):

def save_file(self):
trace_file_path = type_defs.USER_PATHS.TRACE_INSTRUCTIONS_PATH
SysUtils.is_path_valid(trace_file_path, "create")
file_path = QFileDialog.getSaveFileName(self, "Save trace file", trace_file_path)[0]
if file_path:
SysUtils.save_trace_instructions_file(GDB_Engine.currentpid, self.breakpoint, file_path)

def load_file(self):
trace_file_path = type_defs.USER_PATHS.TRACE_INSTRUCTIONS_PATH
SysUtils.is_path_valid(trace_file_path, "create")
file_path = QFileDialog.getOpenFileName(self, "Open trace file", trace_file_path)[0]
if file_path:
self.treeWidget_InstructionInfo.clear()
Expand Down
37 changes: 16 additions & 21 deletions libPINCE/SysUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import sys
import binascii
import pickle
import pexpect
from . import type_defs
from re import match, search, IGNORECASE, split, sub

Expand Down Expand Up @@ -630,26 +629,8 @@ def execute_shell_command_as_user(command):
Args:
command (str): Command that'll be invoked from the shell
"""
output = pexpect.run("who").decode("utf-8")
user_name = output.split()[0]
pexpect.run('sudo -u ' + user_name + ' ' + command)


def init_gdbinit_file():
"""
Initializes the required .gdbinit file in $HOME
Very useful if you need to automatically execute a .gdbinit file and don't have the required .gdbinit file in $HOME
"""
file_path = get_home_directory() + "/.gdbinit"
if not is_path_valid(file_path):
gdbinit_file = open(file_path, "w+")
else:
gdbinit_file = open(file_path, "r+")
auto_load_string = "set auto-load safe-path /"
if gdbinit_file.read().find(auto_load_string) == -1:
gdbinit_file.seek(0, 2)
gdbinit_file.write("\n" + auto_load_string)
gdbinit_file.close()
user_name = os.getlogin()
os.system('sudo -u ' + user_name + ' ' + command)


def get_comments_of_variables(source_file_path, single_comment="#", multi_start='"""', multi_end='"""'):
Expand Down Expand Up @@ -723,3 +704,17 @@ def get_comments_of_variables(source_file_path, single_comment="#", multi_start=
break
comment_dict[variable] = "\n".join(docstring_list)
return comment_dict


def init_user_files():
is_path_valid(type_defs.USER_PATHS.ROOT_PATH, "create")
is_path_valid(type_defs.USER_PATHS.TRACE_INSTRUCTIONS_PATH, "create")
try:
open(type_defs.USER_PATHS.GDBINIT_PATH).close()
except FileNotFoundError:
open(type_defs.USER_PATHS.GDBINIT_PATH, "w").close()
user_name = os.getlogin()
os.system("sudo chown -R " + user_name + ":" + user_name + " " + type_defs.USER_PATHS.ROOT_PATH)


init_user_files()
4 changes: 4 additions & 0 deletions libPINCE/gdb_python_scripts/ScriptUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
# Use this function instead of the .gdbinit file
# If you have to load a .gdbinit file, just load it in this function with command "source"
def gdbinit():
try:
gdb.execute("source " + type_defs.USER_PATHS.GDBINIT_PATH)
except:
pass
gdb.execute("set disassembly-flavor intel")
gdb.execute("set case-sensitive auto")

Expand Down
4 changes: 3 additions & 1 deletion libPINCE/type_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class PATHS:

class USER_PATHS:
HOME_PATH = os.path.expanduser("~")
TRACE_INSTRUCTIONS_PATH = HOME_PATH + "/PINCE_USER_FILES/TraceInstructions/"
ROOT_PATH = HOME_PATH + "/PINCE_USER_FILES/"
GDBINIT_PATH = ROOT_PATH + "gdbinit"
TRACE_INSTRUCTIONS_PATH = ROOT_PATH + "TraceInstructions/"


class INFERIOR_STATUS:
Expand Down

0 comments on commit bd1f3c4

Please sign in to comment.