initial commit of the files

This commit is contained in:
2024-04-21 16:34:29 +02:00
commit e96483ca48
20 changed files with 576 additions and 0 deletions

79
css/styles.css Normal file
View File

@@ -0,0 +1,79 @@
#spike {
float: left;
border-style:solid;
border-color:rgba(18,24,217,0.6);
width: 8.1%;
height: auto;
max-width: 100%;
object-fit: cover;
}
/* unvisited link */
a:link {
color: #686bff;
}
/* visited link */
a:visited {
color: #686bff;
}
/* mouse over link */
a:hover {
color: #5660f1;
}
/* selected link */
a:active {
color: #686bff;
}
.header {
width: auto;
height: auto;
overflow:auto;
background-color: rgba(18,24,217,0.6);
top: 0;
left:0px;
right:0px;
}
.menu {
font-weight: bold;
float: left;
margin-top: 5.2%;
margin-left: 0.5%;
}
body {
background: url(../images/bg.gif) repeat 0 0;
color: white;
}
p {
font-size: large;
margin-left: 3px;
margin-bottom: -5px;
}
a {
overflow: hidden;
}
#foot {
top: 10%;
position: relative;
display: block;
margin: 0 auto;
}
.article {
font-weight: bold;
font-size: large;
}
.center_image {
display: block;
margin-left: auto;
margin-right: auto;
}

BIN
images/bg.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
images/footer/gnu_linux.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

BIN
images/footer/tor.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
images/spike.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

53
index.html Normal file
View File

@@ -0,0 +1,53 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>~Blog of a French coder~</title>
<link rel="stylesheet" type="text/css" href="css/styles.css"/>
</head>
<body>
<div class="header">
<a href="/">
<a href="./index.html"><img alt="Spike" src="images/spike.jpg" id="spike"></a>
</a>
<div class="menu">
<a href="pages/blog.html">the blog</a>
<a href="//github.com/ALittlePatate">github</a>
<a href="pgp/key.txt">pgp key</a>
</div>
</div>
<p>Hey you, thanks for passing by, let me introduce myself. I'm a French C/C++/Python/ASM coder who is interested in reverse engineering, Eurobeat music and 90's looking websites.</p>
<p>I don't know how you found this website but be free to check <a href="pages/blog.html">my blog</a> where i post random stuff.</p>
<br>
<p>I run Arch Linux, i3 and Emacs: <a href="//github.com/ALittlePatate/dotfiles"> my dotfiles.</a></p>
<br>
<p>Interests:<p>
<ul>
<li>Low-level programming</li>
<li>Windows exploitation</li>
<li>Malware engineering</li>
<li>Reverse engineering</li>
<li>Cheat coding</li>
</ul>
<p>Some projects of mine:<p>
<ul>
<li><a href="//github.com/ALittlePatate/patate-crypter">patate crypter</a> - Malware obfuscator, bypasses most AVs</li>
<li><a href="//github.com/ALittlePatate/pasm">pasm</a> - x86 assembly-like interpreted scripting language meant for C2 agents</li>
<li><a href="//github.com/ALittlePatate/taxidriver">TaxiDriver</a> - R/W kernel module for Linux (5.x - 6.x)</li>
</ul>
<footer id="foot">
<script type="text/javascript">
document.write('<img id="foot" src="https://counter.websiteout.net/compte.php?S=patate.dev&C=2&D=8&N=0&M=0" alt="" border="0"/>');
</script>
<a href="//gnu.org"><img alt="GNU/Linux" src="images/footer/gnu_linux.png" /></a>
<img alt="" src="images/footer/internet-privacy.gif" />
<a href="//torproject.org"><img alt="Tor" src="images/footer/tor.gif" /></a>
</footer>
</body>
</html>

38
pages/blog.html Normal file
View File

@@ -0,0 +1,38 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>~Blog of a French coder~</title>
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
</head>
<body>
<div class="header">
<a href="/">
<a href="../index.html"><img alt="Spike" src="../images/spike.jpg" id="spike"></a>
</a>
<div class="menu">
<a href="blog.html">the blog</a>
<a href="//github.com/ALittlePatate">github</a>
<a href="../pgp/key.txt">pgp key</a>
</div>
</div>
<p>In this section of the website you can read the random stuff i post from time to time, i will prob not update the style.css for the programming related ones because it's more readable.</p>
<h2>The articles</h2>
<!--Articles-->
<ul>
<li><a href="reversing_vac_winapi_hooks.html" class="article">reversing VAC's WinApi hooks</a></li>
<li><a href="insecure_mode_bypass.html" class="article">-insecure mode bypass in CS:GO</a></li>
</ul>
<footer id="foot">
<script type="text/javascript">
document.write('<img id="foot" src="https://counter.websiteout.net/compte.php?S=patate.dev&C=2&D=8&N=0&M=0" alt="" border="0"/>');
</script>
<a href="//gnu.org"><img alt="GNU/Linux" src="../images/footer/gnu_linux.png" /></a>
<img alt="" src="../images/footer/internet-privacy.gif" />
<a href="//torproject.org"><img alt="Tor" src="../images/footer/tor.gif" /></a>
</footer>
</body>
</html>

View File

@@ -0,0 +1,71 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>~Blog of a French coder~</title>
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
</head>
<body>
<div class="header">
<a href="/">
<a href="../index.html"><img alt="Spike" src="../images/spike.jpg" id="spike"></a>
</a>
<div class="menu">
<a href="blog.html">the blog</a>
<a href="//github.com/ALittlePatate">github</a>
<a href="../pgp/key.txt">pgp key</a>
</div>
</div>
<article aria-label="Content" itemscope itemtype="http://schema.org/BlogPosting">
<h1 itemprop="name headline">-insecure mode bypass in CS:GO</h1>
<time class="mono"> Jan 31, 2022</time>
<main itemprop="articleBody" style="position: relative">
<p>Hey, in this short article i will present you how i found an exploit to join VAC secured community servers with the -insecure flag enabled on CS:GO.</p>
<h2 id="A-bit-of-context">
<a href="#A-bit-of-context">A bit of context</a>
</h2>
<p>2 days ago, <a href="https://www.unknowncheats.me/forum/counterstrike-global-offensive/487812-insecure-mode-bypass.html" target="_blank">this exploit was released to unknonwcheats.</a> But as the file wasn't approved and it was only a DLL no matter what, i decided to try to replicate it myself without trying to reverse it. It wasn't that hard but it was a good learning opportunity !</p>
<h2 id="How--insecure-works">
<a href="#How--insecure-works">How -insecure works</a>
</h2>
<p>The <code class="language-plaintext highlighter-rouge">-insecure</code> flag is used to disable VAC and still launch CS:GO, it is useful for debugging the game or to play with cheats without having a chance of VAC getting triggered. The thing is this flag prevents you from joining VAC secured servers such as community servers. This is what message you get if you try to connect to one with this flag enabled :</p>
<p>
<img class="center_image" src="../images/insecure_mode_bypass/vac_insecure_error.png" width="40%" height="40%" alt="" />
</p>
<p>note for translation : You can't connect to the server because you have <code class="language-plaintext highlighter-rouge">-insecure</code> enabled.</p>
<h2 id="How-to-bypass-that">
<a href="#How-to-bypass-that">How to bypass that</a>
</h2>
<p>Thanksfully the source code of 2k18 CS:GO leaked in 2020 and <a href="https://github.com/perilouswithadollarsign/cstrike15_src" target="_blank">is avalaible on Github.</a> After looking for <code class="language-plaintext highlighter-rouge">insecure</code> in the repo we quickly find a function named <code class="language-plaintext highlighter-rouge">Host_IsSecureServerAllowed</code>, which looks like this :</p>
<p>
<img class="center_image" src="../images/insecure_mode_bypass/Host_IsSecureServerAllowed.png" alt="" />
</p>
<p>But remember, this is from 2018 CS:GO, we still need to find it in IDA, same thing in IDA, load <code class="language-plaintext highlighter-rouge">engine.dll</code> and look for the <code class="language-plaintext highlighter-rouge">insecure</code> string, by looking at the xrefs we can find 2022 Host_IsSecureServerAllowed function :</p>
<p>
<img class="center_image" src="../images/insecure_mode_bypass/Host_IsSecureServerAllowed_IDA.png" alt="" />
</p>
<p>We can see that the function is looking for <code class="language-plaintext highlighter-rouge">insecure</code> or <code class="language-plaintext highlighter-rouge">tools</code> or <code class="language-plaintext highlighter-rouge">edit</code> flags and if it find them, it returns false, thus kicking you from the server you are trying to join.</p><p>From here we can use the IDA plugin <a href="https://github.com/ajkhoury/SigMaker-x64" target="_blank">SigMaker</a> to generate a signature for this function. The only thing that is left to do is hook the function, and always return true so the check for the <code class="language-plaintext highlighter-rouge">insecure</code> flag are never performed.</p>
<h2 id="Hooking-Host_IsSecureServerAllowed">
<a href="#Hooking-Host_IsSecureServerAllowed">Hooking Host_IsSecureServerAllowed</a>
</h2>
<p>Hooking this function with <a href="https://github.com/TsudaKageyu/minhook" target="_blank">MinHook</a> is pretty straightforward, here is the pseudo code :</p>
<p>
<img class="center_image" src="../images/insecure_mode_bypass/hooking_Host_IsSecureServerAllowed.png" width="80%" height="auto" alt="" />
</p>
<p>We are basically defining the <code class="language-plaintext highlighter-rouge">Host_IsSecureServerAllowed</code> function, and in it, we just say to always return true. Then we scan for the (insanely long) signature for this function and hook it with MinHook.</p><p>From now, just build the DLL, inject into CS:GO and you'll see, with <code class="language-plaintext highlighter-rouge">-insecure</code> you'll be able to join VAC protected community servers.</p>
<h2 id="Limitations">
<a href="#Limitations">Limitations</a>
</h2>
<p>At the writing of this blogpost, you can only join community servers with this flag enabled, this may change. Also, remember that even if you join a VAC secured server with this bypass, VAC will still be running thus this exploit is pretty useless. It was only a learning opportunity to me and shouldn't be considered as a VAC bypass.</p><p></p></main></article>
<footer id="foot">
<script type="text/javascript">
document.write('<img id="foot" src="https://counter.websiteout.net/compte.php?S=patate.dev&C=2&D=8&N=0&M=0" alt="" border="0"/>');
</script>
<a href="//gnu.org"><img alt="GNU/Linux" src="../images/footer/gnu_linux.png" /></a>
<img alt="" src="../images/footer/internet-privacy.gif" />
<a href="//torproject.org"><img alt="Tor" src="../images/footer/tor.gif" /></a>
</footer>

View File

@@ -0,0 +1,68 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>~Blog of a French coder~</title>
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
</head>
<body>
<div class="header">
<a href="/">
<a href="../index.html"><img alt="Spike" src="../images/spike.jpg" id="spike"></a>
</a>
<div class="menu">
<a href="blog.html">the blog</a>
<a href="//github.com/ALittlePatate">github</a>
<a href="../pgp/key.txt">pgp key</a>
</div>
</div>
<article aria-label="Content" itemscope itemtype="http://schema.org/BlogPosting">
<h1 itemprop="name headline">Reversing VAC winapi hooks</h1>
<time class="mono"> Jun 02, 2022</time>
<main itemprop="articleBody" style="position: relative">
<p>Hello there, been a long time ! Today i will talk about the implementation of winapi hooks inside Valve Anti Cheat (aka VAC).</p>
<h2 id="A-bit-of-context">
<a href="#A-bit-of-context">A bit of context</a>
</h2>
<p>Everything i will say is directly from <a href="https://www.unknowncheats.me/forum/counterstrike-global-offensive/501339-possibility-virtualprotect-hooked-valve.html" target="_blank">this topic on UC</a></p>
<h2 id="What-is-hooking-?">
<a href="#What-is-hooking-?">What is hooking ?</a>
</h2>
<p>In the first place we need to properly understand the way hooking works. To hook a function you need to overwrite the first 5 bytes to <code class="language-plaintext highlighter-rouge">jmp 0xYOURADDR</code> where 0xYOURADDR is the memory address for the function that will replace the original (a pointer basically). We can also save the original function pointer to return to the original function after our code, this is called a trampoline (tramp) hook.</p>
<p>
<img class="center_image" src="../images/reversing_vac_winapi_hooks/hooking_explained.png" alt="" />
</p>
<h2 id="What's-up-with-VAC-?">
<a href="#What's-up-with-VAC-?">What's up with VAC ?</a>
</h2>
<p>Some guy reported that VAC may be hooking VirtualProtect to check if you're messing with the game's code. Another one showed that <a href="https://www.unknowncheats.me/forum/3215599-post33.html" target="_blank">it has already been reported on UC in the past</a></p>
<h2 id="Reversing-VAC">
<a href="#Reversing-VAC">Reversing VAC</a>
</h2>
<p>VAC is actually in GameOverlayRenderer.dll, which manages... the Steam overlay you got it. Pretty dumb design if you ask me but VAC always tries to think outside of the box. From now we just open the dll in IDA, search for the string "VirtualProtect" and we find it ! Here it is after some renaming :</p>
<p>
<img class="center_image" src="../images/reversing_vac_winapi_hooks/winapi_hooks.PNG" alt="" />
</p>
<p>We can see that VAC actually hooks a ton of those winapi functions. For the code, it's pretty straight forward :</p><ul><li>We get the address of VirtualProtect in the memory with <code class="language-plaintext highlighter-rouge">GetProcAddress</code><code class="language-plaintext highlighter-rouge"></li></code><li>We hook the function by passing to <code class="language-plaintext highlighter-rouge">HookMethod</code> its pointer, the pointer of the modified function and the tramp pointer that we want to use.</li>Now we can actually start looking inside of the hook for VirtualProtect. Here is the cleaned code :
<br>
<p>
<img class="center_image" src="../images/reversing_vac_winapi_hooks/VirtualProtectHook.PNG" alt="" />
</p>
We see that the function is defined the same as the original one; you need to do this when hooking.This function basically executes VirtualProtect as usual with the trampoline pointer, sets the LastError and returns the result.But you may have noticed an if statement, pretty self explanatory but if the game we're running is a Valve game and we're trying to change the rights of the region to execute/read/write, then it jumps to <code class="language-plaintext highlighter-rouge">do_sketchy_stuff_0</code> which i haven't decompiled yet (lol) but it must have something to do with VAC reporting abuse.
<h2 id="Conclusion">
<a href="#Conclusion">Conclusion</a>
</h2>
To conclude, reversing VAC is a great way of learning as it's not obfuscated/packed and the code is pretty easy to read. Bye.<p></p></main></article>
<footer id="foot">
<script type="text/javascript">
document.write('<img id="foot" src="https://counter.websiteout.net/compte.php?S=patate.dev&C=2&D=8&N=0&M=0" alt="" border="0"/>');
</script>
<a href="//gnu.org"><img alt="GNU/Linux" src="../images/footer/gnu_linux.png" /></a>
<img alt="" src="../images/footer/internet-privacy.gif" />
<a href="//torproject.org"><img alt="Tor" src="../images/footer/tor.gif" /></a>
</footer>

52
pgp/key.txt Normal file
View File

@@ -0,0 +1,52 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
m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A7LfyJRHjB1tI5XwI2Q3RgS7gCe1UB8vq
NJVbPnFa36xWsDv6GnSssegcNoKlf/ZT1hTQHeNcsNO00wx0Fz7gONB6FrFzCdrF
77SDABEBAAGJAjYEGAEIACACGwwWIQR24NZCdITbsvtkkA8xYCQ2Yf6enQUCZiUL
UwAKCRAxYCQ2Yf6enT2sEACn4kGQRRV2O32eQkv5JXTPRtuzYDIZ8+EV/7R5PHAS
dKfPZJWw4DK8FIias58yx2GSiP5tbRuh31XQJvOLZZ5WpIfZeQygjorZ5jdcobSj
+uaSy+s+hPDFAZlzd2ELXIVt3hvquFOtw825b1FmLDFCGzTiYb4UEGwIOjP1GQSt
EI9Bl96J0V9UkdRzaBxshuEYAWcGU5IlESGouKLnH1dNKaSuT+B8nPv1xp1UZTa5
aO+/tM2+i8DhMMOXWMVEAd4jdg0zM8NnXRp4o/5/8UpKg7Sn7h0ReUJwK2WpXOBv
EpTRzb1gITJsJ5C5fzH7HBceDSvr8FDuYBkVz4Fq5godEHBh40Rpp3RE1UYJcHlj
fQD9sYAk1r3rUny/6JwwOkXMxNWUQz79E9VaJYonadKU3wM9ZS2pYP2Bslm1QA4b
I3Dn+VxZy1GfBwrfcKMWcMaQZDWlVUhRRtHzAT4tUACIbJMEQliQE0plSZ6vCZZ3
KMVXA5m15JLz7CPVK5ul62imW8c4lSxEgaqCvLfQCrURiMbT7M4HfuNsoOKymaRo
Xm4+9+3OqFOvakKajckMPDVT16WWb7dpnE2bIdCULBzrOgl9JyivP9ik3XCXq2gb
iNczgpTBLp9PX3ATh3Fz4kDr1jE1sDFGw179RisnjGO1B7ZtLQ17B/nMh0SLxhyr
MQ==
=YkTw
-----END PGP PUBLIC KEY BLOCK-----

View File

@@ -0,0 +1,204 @@
"""
~foldername~template~foldername~
~titre~Test article~titre~
~date~ Jan 25, 2022~date~
~section~Test~section~
~data~data~data~
~link~[https://www.google.com]link to google~link~
~list~Test~list~
~endlist~
~image~serverlist.png~image~
"""
#TODO :
# - add code snippet
import os
from os import listdir
from os.path import isfile, join
import shutil
from tkinter import Tk
from tkinter.filedialog import askopenfilename
def write_file(text) :
with open("out.html", "a") as o :
o.write(text)
def generate_base(title) :
base = """
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>"""+title+"""</title>
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
</head>
<body>
<div class="header">
<a href="/">
<a href="../index.html"><img alt="Spike" src="../images/spike.jpg" id="spike"></a>
</a>
<div class="menu">
<a href="blog.html">the blog</a>
<a href="//github.com/ALittlePatate">github</a>
<a href="../pgp/key.txt">pgp key</a>
</div>
</div>
<article aria-label="Content" itemscope itemtype="http://schema.org/BlogPosting">
<h1 itemprop="name headline">"""+title+"""</h1>
"""
write_file(base)
def generate_date(date) :
base = """
<time class="mono"> """+date+"""</time>
<main itemprop="articleBody" style="position: relative">
"""
write_file(base)
def generate_paragraph(p) :
base = "<p>"+p+"</p>"
write_file(base)
def generate_section(s) :
s_2 = s.replace(" ","-")
base = '''
<h2 id="'''+s_2+'''">
<a href="#'''+s_2+'''">'''+s+'''</a>
</h2>
'''
write_file(base)
def generate_end_file() :
base = '''
<p></p></main></article>
<footer id="foot">
<script type="text/javascript">
document.write('<img id="foot" src="https://counter.websiteout.net/compte.php?S='+encodeURI(window.location.hostname)+'&C=2&D=8&N=0&M=0" alt="" border="0"/>');
</script>
<a href="//gnu.org"><img alt="GNU/Linux" src="../images/footer/gnu_linux.png" /></a>
<img alt="" src="../images/footer/internet-privacy.gif" />
<a href="//torproject.org"><img alt="Tor" src="../images/footer/tor.gif" /></a>
</footer>
</html>'''
write_file(base)
def generate_image(path) :
base = '''
<p>
<img class="center_image" src="'''+path+'''" alt="" />
</p>
'''
write_file(base)
def set_foldername(name) :
os.mkdir("../images/"+name)
onlyfiles = [f for f in listdir(".") if isfile(join(".", f))]
for f in onlyfiles :
if f.endswith(".jpg") or f.endswith(".jpeg") or f.endswith(".png") or f.endswith(".ico") or f.endswith(".gif") :
shutil.move(f, "../images/"+name+"/"+f)
def main() :
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
name = ""
titre = ""
date = ""
was_list = False
with open(filename, "r") as a :
for line in a.readlines() :
if line.startswith("~foldername~") :
final_line = line.replace("~foldername~","").strip()
name = final_line
set_foldername(final_line)
elif line.startswith("~titre~") :
final_line = line.replace("~titre~","").strip()
titre = final_line
generate_base(final_line)
elif line.startswith("~date~") :
final_line = line.replace("~date~","").strip()
date = " " + final_line
generate_date(final_line)
elif line.startswith("~section~") :
final_line = line.replace("~section~","").strip()
generate_section(final_line)
elif line.startswith("~image~") :
final_line = line.replace("~image~","").strip()
final_line = "../images/"+name+"/" + final_line
generate_image(final_line)
else :
if line.startswith("~endlist~"):
was_list = False
write_file("</ul>")
continue
if line.startswith("~list~") :
l = line.split("~list~")
res = ""
if not was_list :
res += "<ul>"
for w in l :
if not w == " " and not w == "" and not w == "\n":
res += "<li>"+w+"</li>"
was_list = True
line = res
if "~data~" in line :
l = line.split("~data~")
res = ""
for w in l :
if not w.startswith(" ") and not w.endswith(" ") and not "<li" in w :
res += '<code class="language-plaintext highlighter-rouge">'+w+'</code>'
else :
res += w
line = res
if "~link~" in line :
l = line.split("~link~")
res = ""
for w in l :
if not w.startswith(" ") and not w.endswith(" ") and not w == "":
link = w.split("]")
if len(link) < 2 :
continue
res += '<a href="'+link[0][1:]+'" target="_blank">'+link[1]+'</a>'
else :
res += w
line = res
if not was_list :
write_file("<p>" + line.strip() + "</p>")
else :
write_file(line.strip())
generate_end_file()
shutil.move("out.html", "../pages/"+name+".html")
base = '''\n\t\t<li><a href="'''+name+'''.html" class="article">'''+titre+'''</a></li>\n'''
with open("../pages/blog.html", "r+") as f :
lines = f.readlines()
for i, line in enumerate(lines):
if "<!--Articles-->" in line :
lines[i+1] = lines[i+1].strip() + base
f.seek(0)
for line in lines:
f.write(line)
if __name__ == "__main__" :
main()

11
python_script/template Normal file
View File

@@ -0,0 +1,11 @@
~foldername~template~foldername~
~titre~Example~titre~
~date~Jan 25, 2022~date~
This is a paragraph
This is another one with ~data~data text~data~ and ~link~[https://www.youtube.com/watch?v=UaH8cAGdjzw]a link.~link~
~section~Title 1~section~
Paragraph of Title 1
~list~list element~list~
~list~~data~data element in list~data~~list~
~endlist~
~image~serverlist.png~image~