Compare commits

...

4 Commits

Author SHA1 Message Date
Olixi11 6eb0cbd579 Merge remote-tracking branch 'r/Olixi11-2024-06-03' 2024-06-09 17:40:11 +02:00
Olixi11 35b57421cb Merge zaliczenie 2024-06-09 17:39:29 +02:00
Olixi11 3b999158fe tak 2023-12-03 20:07:32 +01:00
Olixi11 fcfeafb1df pierwsze zatwierdzenie 2023-12-03 20:05:17 +01:00
9 changed files with 519 additions and 0 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# tak
# tak
# tak

256
work/c1/cpp/.gdb_history Normal file
View File

@ -0,0 +1,256 @@
si
b main
c
:q!
exit
target extended-remote localhost:3333
load cpp/prog
si
load
load
load
file cpp/prog
load
si
bmain
b main
c
load
si
sic
b main
c
del b
del
laod
si
load
si
set radix 16
set args 0x1ff80 0x80 0x30
dashboard -layout registers stack memory variables
si
dashboard memory watch 0x1ff80 0x80
source gdb/z.py
dashboard
b main
c
si
load
si
c
source gdb/z.py
si
b func
c
load
si
c
load
si
c
si
source gdb/z.py
si
laod
load
si
c
dash
dash
si
file cpp/prog
load
si
si
c
del
b func
si
c
si
load
si
c
load
si
c main
load
si
c
load
del
b main
si
c
si
load cpp/prog
load
file cpp/prog
load
si
dashboard
source gdb/z.py
dashboard
del
b main
c
b func
c
load
si
file cpp/prog
laod
load
si
c
c
load
si
c
del
b func
c
exit
file cpp/prog
load
load
target extended-remote localhost:3333
load
si
c
load
b main
c
b func
c
load
si
c
si
file cpp/prog
load
si
c
c
file cpp/prog
load
si
c
b swap_ptr(signed char*, signed char*)
c
load
b func(char*)
c
c
load
b func(char*)
del
b func(char*)
load
file cpp/prog
load
si
del
b main
c
b swap_ptr(signed char*, signed char*)
c
target extended-remote localhost:3333
file cpp/prog
load
si
del
b main
c
b swap_ptr(signed char*, signed char*)
c
dashboard -layout registers stack memory variables
dashboard memory watch 0x1ff80 0x80
:asm
si
p/x amessage
p/x &amessage
p/x & pmessage
p/x &pmessage
p/x pmessage
p/x &pmessage
laod
load
si
c
c
p/x pmessage
p/x &pmessage
load
si
c
c
p/x &pmessage
load
load
si
c
c
p/x pmessage
p/x &pmessage
load
si
exit
target extended-remote localhost:3333
file cpp/prog
load
si
load
si
si
load
si
exit
target extended-remote localhost:3333
file cpp/prog
dashboard -layout registers memory variables breakpoints stack
load
si
break main
c
break 58
break 48
break 44
su
si
dashboard -layout registers memory variables stack
si
c
exit
target extended-remote localhost:3333
file counter/counter
file cpp/prog
load
si
exit
target extended-remote localhost:3333
file cpp/prog
load
b main
c
load
si
dashboard -layout registers variables memory stack breakpoints
dashboard -layout registers variables memory stack breakpoints
run
si
si
si
si
si
isi
si
si
si
si
si
si
si
si
exit

16
work/c1/cpp/conf.json Normal file
View File

@ -0,0 +1,16 @@
{
"user": "Olixi11",
"email": "olixi11@gmail.com",
"remotes": [
{
"name": "r",
"protocol": "http",
"domain": "qstack.pl",
"port": "3000",
"token_name": "t",
"token": "5dd2da03bd806bf2811ac8e5a6ebd981c78c0e7a",
"group": "1i-2023",
"project": "strlen-c"
}
]
}

1
work/c1/cpp/cpp Submodule

@ -0,0 +1 @@
Subproject commit c8e1b4b449bee2fd2de30de2e99c3f4010360bcc

17
work/c1/cpp/gdb/z.py Normal file
View File

@ -0,0 +1,17 @@
# set args 0x1FF80 0x80 0x30
# source gdb/z.py
import gdb
import sys
# Parse arguments from the GDB command
args = gdb.string_to_argv(gdb.parameter("args"))
if len(args) != 3:
print("Usage: source gdb/zero_with_params.py <start_address> <num_bytes> <pattern>")
else:
start_address = int(args[0], 16) # Convert start address from hex to int
num_bytes = int(args[1], 16) # Convert number of bytes from hex to int
pattern = int(args[2], 16) # Convert pattern from hex to int
for i in range(num_bytes):
gdb.execute("set *((char*)%x + %x) = %x" % (start_address, i, pattern))

5
work/c1/cpp/gdb/zero.py Normal file
View File

@ -0,0 +1,5 @@
#source gdb/z.py
import gdb
for i in range(0, 128): # 128 bajtów
gdb.execute("set *((char*)(0x1FF80 + %x)) = 0xaa" % i)

111
work/c1/cpp/igit.py Normal file
View File

@ -0,0 +1,111 @@
import argparse
import json
import sys
import subprocess
import os
from datetime import datetime
DEFAULT_CONFIG = {
"user": "Olixi11",
"email": "olixi11@gmail.com",
"remotes": [{
"name": "r", # Zaktualizowano z "default" na "mpabi"
"protocol": "http",
"domain": "qstack.pl",
"port": "3000",
"token_name": "t",
"token": "5dd2da03bd806bf2811ac8e5a6ebd981c78c0e7a",
"group": "1i-2023",
"project": "strlen-c"
}]
}
def load_or_create_config(config_file, args):
config_exists = os.path.exists(config_file) and os.stat(config_file).st_size != 0
if config_exists:
with open(config_file, 'r') as file:
config = json.load(file)
else:
config = DEFAULT_CONFIG.copy()
# Znajdź istniejące zdalne repozytorium o podanej nazwie
remote = next((remote for remote in config['remotes'] if remote['name'] == args.remote), None)
# Jeśli istnieje zdalne repozytorium i podano argumenty związane z konfiguracją zdalnego repozytorium
if remote:
for field in ['protocol', 'domain', 'port', 'token_name', 'token', 'group', 'project']:
# Aktualizuj tylko, jeśli argument został jawnie podany
if getattr(args, field, None) is not None:
remote[field] = getattr(args, field)
# Jeśli zdalne repozytorium nie istnieje, ale podano nazwę, tworzymy nowe zdalne repozytorium
elif args.remote:
new_remote = {'name': args.remote}
for field in ['protocol', 'domain', 'port', 'token_name', 'token', 'group', 'project']:
new_remote[field] = getattr(args, field, DEFAULT_CONFIG['remotes'][0].get(field, ''))
if new_remote[field] == None:
new_remote[field] = DEFAULT_CONFIG['remotes'][0].get(field, '')
config['remotes'].append(new_remote)
# Aktualizuj informacje o użytkowniku i email, tylko jeśli zostały podane
if getattr(args, 'user', None):
config['user'] = args.user
if getattr(args, 'email_domain', None):
config['email'] = f"{args.user}@{args.email_domain}"
# Zapisz zmodyfikowaną konfigurację
with open(config_file, 'w') as file:
json.dump(config, file, indent=4)
return config
def init_git_repo(config):
user_name = config['user']
user_email = config['email']
branch_name = f"{user_name}-{datetime.now().strftime('%Y-%m-%d')}"
if subprocess.run(["git", "rev-parse", "--git-dir"], stderr=subprocess.DEVNULL).returncode != 0:
subprocess.run(["git", "init"])
subprocess.run(["git", "config", "user.name", user_name])
subprocess.run(["git", "config", "user.email", user_email])
subprocess.run(["git", "checkout", "-b", branch_name])
print("Git repository initialized.")
else:
print("Already inside a Git repository. Skipping initialization.")
remotesFromList = str(subprocess.run(["git", "remote", "-v"], capture_output=True).stdout)
remotesFromList = remotesFromList.replace('b\'', "").replace('\'', "").split('\\n')
for rm in remotesFromList:
name = rm.split("\\t")[0]
subprocess.run(["git", "remote", "remove", name], stderr=subprocess.DEVNULL)
for remote in config['remotes']:
remote_url = f"{remote['protocol']}://{remote['token_name']}:{remote['token']}@{remote['domain']}:{remote['port']}/{remote['group']}/{remote['project']}"
# Usunięcie i ponowne dodanie zdalnego repozytorium, jeśli jest zaktualizowane
#subprocess.run(["git", "remote", "remove", remote['name']], stderr=subprocess.DEVNULL)
subprocess.run(["git", "remote", "add", remote['name'], remote_url])
print(f"Remote '{remote['name']}' added or updated.")
def main():
parser = argparse.ArgumentParser(description="Git repository initializer with custom configuration.")
parser.add_argument("--user", help="User name")
parser.add_argument("--email_domain", help="Email domain")
parser.add_argument("--config", help="Path to the JSON config file", default="conf.json")
parser.add_argument("--remote", help="Name of the remote to add or update")
parser.add_argument("--protocol", help="Remote protocol")
parser.add_argument("--domain", help="Remote domain")
parser.add_argument("--port", help="Remote port")
parser.add_argument("--token_name", help="Remote token name")
parser.add_argument("--token", help="Remote token")
parser.add_argument("--group", help="Group name")
parser.add_argument("--project", help="Project name")
args = parser.parse_args()
config = load_or_create_config(args.config, args)
init_git_repo(config)
print("Git repository initialized and configured based on the provided configuration.")
if __name__ == "__main__":
main()

BIN
work/c1/cpp/tex/main.pdf Normal file

Binary file not shown.

110
work/c1/cpp/tex/main.tex Normal file
View File

@ -0,0 +1,110 @@
\documentclass{article}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[polish]{babel}
\usepackage{listings}
\usepackage{color}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\begin{document}
\title{GDB and DASHBOARD}
\author{}
\date{}
\maketitle
\section{Dashboard memory watch}
Dashboard GDB pozwala na dynamiczne obserwowanie określonych obszarów pamięci. Używając funkcji \texttt{dashboard memory watch}, można ustawić obserwację na konkretne adresy pamięci.
\begin{lstlisting}[language=bash]
dashboard memory watch 0x1ff80 128
\end{lstlisting}
\noindent
Powyższa komenda skonfiguruje dashboard do obserwacji 128 bajtów pamięci, począwszy od adresu \texttt{0x1ff80}.
\section{Obserwacja pamięci przy użyciu watch w GDB}
Aby obserwować pamięć na niskim poziomie w GDB, można użyć komendy \texttt{watch} w połączeniu z rzutowaniem i rozmiarem obserwowanego obszaru. Przykładowo, aby obserwować 128 bajty pamięci zaczynając od adresu \texttt{0x1ff80}, użyjemy następującej komendy:
\begin{lstlisting}[language=bash]
watch *(char*)0x1ff80 @ 128
\end{lstlisting}
Ta komenda spowoduje przerwanie wykonania programu, gdy wartości w obserwowanym obszarze pamięci ulegną zmianie. Użycie rzutowania na typ \texttt{(char*)} pozwala na interpretację adresu jako wskaźnika na bajty, a operator \texttt{@} określa ilość obserwowanych bajtów.
\section{Clear Memory}
\subsection{Basic Usage}
To clear 128 bytes of memory starting from 0x1FF80, use the following script:
\begin{lstlisting}[language=bash]
#./gdb/zero.py
import gdb
for i in range(0, 128): # 128 bajtów
gdb.execute("set *((char*)0x1FF80 + %d) = 0" % i)
\end{lstlisting}
Run this script from GDB dashboard by:
\begin{lstlisting}[language=bash]
source gdb/zero.py
\end{lstlisting}
\subsection{Option 2: With Parameters}
To dynamically set the starting address, number of bytes, and pattern from the command line, modify the script as follows:
\begin{lstlisting}[language=bash]
#./gdb/zero_with_params.py
import gdb
import sys
# Parse arguments from the GDB command
args = gdb.string_to_argv(gdb.parameter("args"))
if len(args) != 3:
print("Usage: source gdb/zero_with_params.py <start_address> <num_bytes> <pattern>")
else:
start_address = int(args[0], 16) # Convert start address from hex to int
num_bytes = int(args[1], 16) # Convert number of bytes from hex to int
pattern = int(args[2], 16) # Convert pattern from hex to int
for i in range(num_bytes):
gdb.execute("set *((char*)%d + %d) = %d" % (start_address, i, pattern))
\end{lstlisting}
To run this script with parameters, set GDB's `args` parameter before sourcing the script:
\begin{lstlisting}[language=bash]
set args 0x1FF80 0x80 0x30
source gdb/zero_with_params.py
\end{lstlisting}
This allows specifying the starting address, number of bytes to clear, and the pattern to use directly from the GDB command line.
\end{document}