<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shekhar Chandra</title>
    <description>The latest articles on DEV Community by Shekhar Chandra (@ranuzz).</description>
    <link>https://dev.to/ranuzz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F658660%2F8a881cba-ac2d-4db5-99f0-981c3fc20cb3.jpg</url>
      <title>DEV Community: Shekhar Chandra</title>
      <link>https://dev.to/ranuzz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ranuzz"/>
    <language>en</language>
    <item>
      <title>Common Mistakes to Avoid When Starting a SideProject</title>
      <dc:creator>Shekhar Chandra</dc:creator>
      <pubDate>Fri, 27 May 2022 07:36:52 +0000</pubDate>
      <link>https://dev.to/ranuzz/common-mistakes-to-avoid-when-starting-a-sideproject-237j</link>
      <guid>https://dev.to/ranuzz/common-mistakes-to-avoid-when-starting-a-sideproject-237j</guid>
      <description>&lt;p&gt;Time estimation in software engineering seems to be the most difficult task.&lt;/p&gt;

&lt;p&gt;Time estimation becomes a bit easier for well-managed projects where most of the design decisions have been made and there is enough internal tooling and resources. But it is still not perfect. Things become more difficult for teams with limited resources and external pressure on deadlines. More often than not, the projects get delivered, some more polished than others.&lt;/p&gt;

&lt;p&gt;When it comes to time estimation, solo developers working on their side projects face a real challenge. It becomes worse if there is no external motivation or revenue potential for the project. Building something for fun or learning might end up in an unfinished project that never sees a launch day.&lt;br&gt;
Although launching a side project is not necessary, it does help in closure and moving on to the next big thing. If you do want to finish your next side project and cannot find the time or motivation, try avoiding these pitfalls.&lt;/p&gt;

&lt;h3&gt;
  
  
  Too Many Features
&lt;/h3&gt;

&lt;p&gt;Side projects should be straightforward by design. If it has dozens of trivial and non-trivial features, it is on its way to becoming a startup. Think about the reason you are building your project. If it is for fun, then pick the top three to five features to include in the first version and move ahead.&lt;/p&gt;

&lt;h3&gt;
  
  
  No Delegation
&lt;/h3&gt;

&lt;p&gt;Think of yourself as a resource even when you are working alone. Ask yourself how much you can deliver while working a few hours a week and assign achievable tasks to yourself. Don't forget to look for tools and services outside of your site that you can use to handle some of the work.&lt;/p&gt;

&lt;h3&gt;
  
  
  No Deadline
&lt;/h3&gt;

&lt;p&gt;Set a soft and hard deadline for yourself once you have a clear idea of what you are trying to build. Give yourself enough buffer to catch up.&lt;/p&gt;

&lt;h3&gt;
  
  
  Unnecessary Marketing
&lt;/h3&gt;

&lt;p&gt;Don’t fall into the trap of doing irrelevant market research and user surveys before coding. As a developer, your strength lies in development. Creating a production-ready product would be easier to market than a landing page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Busy Work
&lt;/h3&gt;

&lt;p&gt;Too much planning will ruin the flow and give you a false sense of accomplishment. Don’t create an extensive task list and roadmap before you start coding. Once you have your first few features finalized and an estimation of how much time it will take, start working on your project. You can always revise the estimate and drop or add another feature along the way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Burden of Launch Day
&lt;/h3&gt;

&lt;p&gt;Don’t worry too much about the launch. You don’t have to showcase your launch and post links everywhere. Keep it simple and ensure that your project ends up on an accessible platform. You can share the links to your project later.&lt;/p&gt;

&lt;p&gt;In conclusion, if you are a developer working on a side project for fun or learning purposes, Then it's better to jump ahead and target finishing the project and avoid these pitfalls.&lt;/p&gt;

</description>
      <category>sideprojects</category>
      <category>productivity</category>
    </item>
    <item>
      <title>HowTo Examine &amp; Modify Executables</title>
      <dc:creator>Shekhar Chandra</dc:creator>
      <pubDate>Mon, 26 Jul 2021 21:20:32 +0000</pubDate>
      <link>https://dev.to/ranuzz/howto-examine-modify-executables-48jp</link>
      <guid>https://dev.to/ranuzz/howto-examine-modify-executables-48jp</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I have been working with C all my professional and student life. There have been times when I had to look a little deeper to understand what is going on with my buggy program. There are many tools and techniques to examine an executable and this post is about that and a little bit of reverse engineering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Code
&lt;/h2&gt;

&lt;p&gt;As an example I wrote a pretty basic piece of code with some intentional inclusions. There are two global variables &lt;code&gt;msga&lt;/code&gt; and &lt;code&gt;msgb&lt;/code&gt;. Two user defined routines &lt;code&gt;allow&lt;/code&gt; and &lt;code&gt;deny&lt;/code&gt; that get executed inside the &lt;code&gt;main&lt;/code&gt; function. One conditional call to an external program using &lt;code&gt;execvp&lt;/code&gt;. The idea here is to examine the executable this program creates. Find out where the code I wrote lands in the executable and what compiler adds on top of it. Later I'll showcase some basic reverse engineering that can be done by pretending we haven't seen the code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ranuzz/makeall-code/blob/main/examinebin/examinebin.c" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;unistd.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;msga&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;msgb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Deny"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;allow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msga&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;deny&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msgb&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;argc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;deny&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;runExternal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;runExternal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;lsargs&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"ls"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"-l"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
        &lt;span class="n"&gt;execvp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ls"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lsargs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While dealing with executable we'll encounter a lot of hexadecimal values, I prefer using Python to do quick arithmetic whenever the need arises.&lt;br&gt;
Also, some of the output is going to be too big to paste here in the post so I'll link them in the end.&lt;/p&gt;
&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;Let's compile the program and get our &lt;code&gt;a.out&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcc examinebin.c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we see in the code the execution of the program basically runs the &lt;code&gt;deny&lt;/code&gt; and halts. I am creating a goal for myself that I'll identify the instruction inside the executable and change it to make sure that &lt;code&gt;allow&lt;/code&gt; is called and then 'ls&lt;code&gt;is executed with&lt;/code&gt;-a` argument.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: The tools used to do analysis and their output are listed at the bottom of this post for reference.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Call Sequence
&lt;/h2&gt;

&lt;p&gt;If we look at the &lt;code&gt;objdump&lt;/code&gt; output, it is very neatly divided into segment and clearly labeled with symbol names. The code we are interested in is the one we wrote but it's nice to know what everything else is.&lt;/p&gt;

&lt;p&gt;The short version is every C program needs a &lt;code&gt;main&lt;/code&gt; routing which marks the start and end of user written code. C runtime executes &lt;code&gt;main&lt;/code&gt; within its framework and takes care of all static and runtime dependencies. The order of execution can be determined very easily by hooking up the executable with &lt;code&gt;gdb&lt;/code&gt; and adding breakpoint to all symbols defined in &lt;code&gt;.text&lt;/code&gt; section and &lt;code&gt;_init&lt;/code&gt; &amp;amp; &lt;code&gt;_fini&lt;/code&gt;. Let's see what happens.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;breakpoint : _init, _start, deregister_tm_clones, register_tm_clones, __do_global_dtors_aux, frame_dummy, allow, deny, main, __libc_csu_init, __libc_csu_fini, _fini&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the call sequence labelled by me based on what my understanding of the usual meaning of these symbols&lt;/p&gt;

&lt;p&gt;// Initialisation&lt;br&gt;
_init (argc=1, argv=0x7fffffffdfd8, envp=0x7fffffffdfe8)&lt;br&gt;
_start ()&lt;br&gt;
__libc_csu_init ()&lt;br&gt;
_init ()&lt;br&gt;
frame_dummy ()&lt;br&gt;
register_tm_clones ()&lt;/p&gt;

&lt;p&gt;// User Code&lt;br&gt;
main ()&lt;br&gt;
deny () // we want to call allow and execvp here instead&lt;/p&gt;

&lt;p&gt;// Deconstruction and finalisation&lt;br&gt;
__do_global_dtors_aux ()&lt;br&gt;
deregister_tm_clones ()&lt;br&gt;
deregister_tm_clones ()&lt;br&gt;
_fini ()&lt;/p&gt;
&lt;h2&gt;
  
  
  Identification
&lt;/h2&gt;

&lt;p&gt;Now that we know what we don't have to explore we can focus on the task at hand, calling allow and &lt;code&gt;ls&lt;/code&gt; with &lt;code&gt;-a&lt;/code&gt;. To do that we will specify our goal properly, basically we want to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;call allow instead of deny.&lt;/li&gt;
&lt;li&gt;change &lt;code&gt;runExternal&lt;/code&gt; flag value to non-zero.&lt;/li&gt;
&lt;li&gt;change &lt;code&gt;"-l"&lt;/code&gt; to &lt;code&gt;"-a" in &lt;/code&gt;lsargs`&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To do that we have to know where these values are in binary and then change them manually without disturbing everything else.&lt;/p&gt;
&lt;h2&gt;
  
  
  Replace &lt;code&gt;deny&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The hexadecimal code calling &lt;code&gt;deny&lt;/code&gt; from &lt;code&gt;objdump&lt;/code&gt; output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0000000000001189 &amp;lt;allow&amp;gt;:

00000000000011a3 &amp;lt;deny&amp;gt;:

00000000000011bd &amp;lt;main&amp;gt;:
    11e4:    e8 ba ff ff ff           callq  11a3 &amp;lt;deny&amp;gt;
    11e9:    c7 45 dc 00 00 00 00     movl   $0x0,-0x24(%rbp)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from the &lt;a href="https://www.felixcloutier.com/x86/call" rel="noopener noreferrer"&gt;callq&lt;/a&gt; reference we know that opcode &lt;code&gt;e8&lt;/code&gt; takes the operand &lt;code&gt;ba ff ff ff&lt;/code&gt; (0xffffffba) which is basically the offset from next instruction  &lt;code&gt;0x11e9&lt;/code&gt;. So, it should point to (0x11a3)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0xffffffba&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x100000000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# getting the negative value
&lt;/span&gt;&lt;span class="n"&gt;deny_addr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x11e9&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deny_addr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To call &lt;code&gt;allow&lt;/code&gt; instead we will have to change (0xffffffba) to something that gives (0x1189) instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;allow_addr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x1189&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;allow_addr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x11e9&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mh"&gt;0x100000000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# 0xffffffa0 -&amp;gt; a0 ff ff ff
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;So all we need to do is change &lt;code&gt;ba&lt;/code&gt; to &lt;code&gt;a0&lt;/code&gt; in the binary&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Change &lt;code&gt;runExternal&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This is quite simple, all we need to do is locate the &lt;code&gt;mov&lt;/code&gt; instruction that is putting the value in the flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    11e9:    c7 45 dc 00 00 00 00     movl   $0x0,-0x24(%rbp)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and change the value to any non-zero one. &lt;a href="https://www.felixcloutier.com/x86/mov" rel="noopener noreferrer"&gt;ref&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;00 00 00 00 -&amp;gt; 01 00 00 00&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Change &lt;code&gt;"-l"&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;We basically want to change the arguments going into &lt;code&gt;execvp&lt;/code&gt; function call. In the assembly we can see the location where the &lt;code&gt;callq&lt;/code&gt; to execvp has been made and there should be &lt;code&gt;push&lt;/code&gt; or &lt;code&gt;lea&lt;/code&gt; instruction before that to add the argument into the stack. Since these values are hardcoded in binaries all we need to do is get the location of &lt;code&gt;-l&lt;/code&gt; and change it to &lt;code&gt;-a&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    11f6:    48 8d 05 12 0e 00 00     lea    0xe12(%rip),%rax        # 200f &amp;lt;_IO_stdin_used+0xf&amp;gt;
    11fd:    48 89 45 e0              mov    %rax,-0x20(%rbp)
    1201:    48 8d 05 0a 0e 00 00     lea    0xe0a(%rip),%rax        # 2012 &amp;lt;_IO_stdin_used+0x12&amp;gt;
    1208:    48 89 45 e8              mov    %rax,-0x18(%rbp)
    121b:    48 8d 3d ed 0d 00 00     lea    0xded(%rip),%rdi        # 200f &amp;lt;_IO_stdin_used+0xf&amp;gt;
    1222:    e8 69 fe ff ff           callq  1090 &amp;lt;execvp@plt&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.felixcloutier.com/x86/lea" rel="noopener noreferrer"&gt;lea&lt;/a&gt; instruction is basically calculating the effective address which in every case here is an offset to the next instruction pointer. So we have three addresses, which can be calculated or seen in the objdump output as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0xe12&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mh"&gt;0x11fd&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 0x200f
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0xe0a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mh"&gt;0x1208&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 0x2012
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0xded&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mh"&gt;0x1222&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 0x200f
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from the hexdump output we can clearly see that our strings are really there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;00002000: 0100 0200 416c 6c6f 7700 4465 6e79 006c  ....Allow.Deny.l
00002010: 7300 2d6c 0000 0000 011b 033b 5400 0000  s.-l.......;T...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changing the fourth byte from the right &lt;strong&gt;6c -&amp;gt; 61&lt;/strong&gt; will make &lt;code&gt;l-&amp;gt;a&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Changes
&lt;/h2&gt;

&lt;p&gt;Let's summarize and do all the necessary changes to the text output provided by &lt;code&gt;xxd&lt;/code&gt; utility.&lt;/p&gt;

&lt;p&gt;Changes for &lt;code&gt;allow&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;000011e0: 0000 0000 e8(ba) ffff ffc7 45dc 0000 0000 
000011e0: 0000 0000 e8(a0) ffff ffc7 45dc 0000 0000 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changes for &lt;code&gt;runExternal&lt;/code&gt; flag&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;000011e0: 0000 0000 e8ba ffff ffc7 45dc (00)00 0000 
000011e0: 0000 0000 e8ba ffff ffc7 45dc (01)00 0000 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changes for &lt;code&gt;l -&amp;gt; a&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;00002010: 7300 2d(6c) 0000 0000 011b 033b 5400 0000 
00002010: 7300 2d(61) 0000 0000 011b 033b 5400 0000 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create new executable
&lt;/h2&gt;

&lt;p&gt;Using xxd utility&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;xxd &lt;span class="nt"&gt;-r&lt;/span&gt; modified-xxd.txt &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; a2.out
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;change permission&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x a2.out
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run
&lt;/h2&gt;

&lt;p&gt;Well I can tell you that it actually works but it's better to try yourself. The output is:&lt;/p&gt;

&lt;h3&gt;
  
  
  Before
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Deny
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  After
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Allow
&lt;span class="nb"&gt;.&lt;/span&gt;  ..  a.out  a2.out
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tools
&lt;/h2&gt;

&lt;p&gt;Lets review some tools that tell us about the file from the outside.&lt;/p&gt;

&lt;h3&gt;
  
  
  file
&lt;/h3&gt;

&lt;p&gt;utility that gives the file name, file type and other format related information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ranuzz/makeall-code/blob/main/examinebin/file.txt" rel="noopener noreferrer"&gt;output&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  sum
&lt;/h3&gt;

&lt;p&gt;Get the checksum and number of blocks in the file. Once we do some reverese engineering this output will tell us that the new executable is not genuine.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ranuzz/makeall-code/blob/main/examinebin/sum.txt" rel="noopener noreferrer"&gt;output&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ldd
&lt;/h3&gt;

&lt;p&gt;Gives the list of shared objects required by the executable&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ranuzz/makeall-code/blob/main/examinebin/ldd.txt" rel="noopener noreferrer"&gt;output&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are some utilities that give a quick peek about the executable if in depth examination is not something you need.&lt;/p&gt;

&lt;h3&gt;
  
  
  strings
&lt;/h3&gt;

&lt;p&gt;Displays all printable characters and strings in the file. Works on any file in fact not just executable&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ranuzz/makeall-code/blob/main/examinebin/strings.txt" rel="noopener noreferrer"&gt;output&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  nm
&lt;/h3&gt;

&lt;p&gt;Lists all the symbols present in the executable file address map.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ranuzz/makeall-code/blob/main/examinebin/nm.txt" rel="noopener noreferrer"&gt;output&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now comes the in depth analysis of executable, this includes intrepreting the machine code into human readable form and also figuring out a way to edit the file.&lt;/p&gt;

&lt;h3&gt;
  
  
  objdump
&lt;/h3&gt;

&lt;p&gt;using the &lt;code&gt;-d&lt;/code&gt; option you can get the detailed version of each section and segment of your executable along with the interpreted assembly instruction.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ranuzz/makeall-code/blob/main/examinebin/objdump.txt" rel="noopener noreferrer"&gt;output&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  xxd or hexdump
&lt;/h3&gt;

&lt;p&gt;These are plain read-write tools to deal with binary files and not just executables. Reading part creates a text file showing hexadecimal values at each byte and if possible there is a printable version side by side. Any changes to this output text file can be fed back to the tool, which can then create a binary file.&lt;/p&gt;

&lt;p&gt;I am using &lt;code&gt;xxd&lt;/code&gt; for reading and writing the executable here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ranuzz/makeall-code/blob/main/examinebin/xxd.txt" rel="noopener noreferrer"&gt;output&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to send me an &lt;a href="mailto:ranuzz@makeall.dev"&gt;email&lt;/a&gt; for any suggestion or feedback. Follow me on &lt;a href="https://twitter.com/ranuzzzz" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; and &lt;a href="https://github.com/ranuzz" rel="noopener noreferrer"&gt;github&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Visualizing Artificial Ant Problem using pygame</title>
      <dc:creator>Shekhar Chandra</dc:creator>
      <pubDate>Tue, 20 Jul 2021 20:49:15 +0000</pubDate>
      <link>https://dev.to/ranuzz/visualizing-artificial-ant-problem-using-pygame-4fc2</link>
      <guid>https://dev.to/ranuzz/visualizing-artificial-ant-problem-using-pygame-4fc2</guid>
      <description>&lt;h2&gt;
  
  
  DEAP
&lt;/h2&gt;

&lt;p&gt;I recently started learning about genetic algorithms and programming. I came across several easy to start tools, libraries and tutorials.There are many cool visualizations available online to showcase how the algorithm improves the population generation over generation. Seems like a nice way to grasp the concept and build intuition. &lt;/p&gt;

&lt;p&gt;Since I mainly code in Python, I ended up using &lt;a href="https://deap.readthedocs.io/en/master/" rel="noopener noreferrer"&gt;DEAP&lt;/a&gt; for prototyping and learning. Documentations are very clear and with lots of examples to study from. &lt;/p&gt;

&lt;h2&gt;
  
  
  Artificial Ant Problem
&lt;/h2&gt;

&lt;p&gt;One particular example was, &lt;a href="https://deap.readthedocs.io/en/master/examples/gp_ant.html" rel="noopener noreferrer"&gt;Artificial Ant Problem&lt;/a&gt;. The goal is to evolve an individual that can control an ant and eat as many food items from the environment as possible given a limited amount and types of moves.&lt;/p&gt;

&lt;p&gt;The code runs seamlessly and you could see the output in the console that generation over generation the population is actually able to increase the amount of food items eaten. &lt;/p&gt;

&lt;h2&gt;
  
  
  Code Changes
&lt;/h2&gt;

&lt;p&gt;That’s all well and good, but I wanted to visualise the solution to see for myself and get a better understanding. First step was to actually read the best individual attributes &lt;code&gt;hall of fame&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/DEAP/deap/blob/f4b77759897d0322ab5a6551106b28f6f4401a4e/examples/gp/ant.py" rel="noopener noreferrer"&gt;Original Base Code for Reference&lt;/a&gt;&lt;br&gt;
I captured the best individual after running the program and recompiled the attribute for that individual.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;deap&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;gp&lt;/span&gt;
&lt;span class="n"&gt;hof_promitive_tree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PrimitiveTree&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hof&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;routine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hof_promitive_tree&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Modified the &lt;code&gt;AntSimulator&lt;/code&gt; class a little bit to record every move for later use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AntSimulator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;object&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_moves&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="bp"&gt;...&lt;/span&gt;
&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;recorded_moves&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;record_move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;recorded_moves&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next step was to run the routine again on modified &lt;code&gt;AntSimulator&lt;/code&gt; and get the recorder moves for simulation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;routine&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# contains the initial food item and ant location
&lt;/span&gt;&lt;span class="n"&gt;grid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;
&lt;span class="c1"&gt;# recorder moves of best individual
&lt;/span&gt;&lt;span class="n"&gt;moves&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;recorded_moves&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Pygame
&lt;/h2&gt;

&lt;p&gt;Given this much information, initialisation involved placing ant and food items on the pygame screen. The main loop consists of playing each move one by one and removing food items once eaten. Complete modified code can be found &lt;a href="https://gist.github.com/ranuzz/89ee8a84274cb7d0634b94c84f317547" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here is the end result. Shows the individual controlling the first 600 moves of our artificial ant.&lt;/p&gt;

&lt;h2&gt;
  
  
  one generation
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/rlXWhgnjqhk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Ten Generations
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/uz8Kt738kkA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Forty Generations
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/RxEwl5rGGkY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>python</category>
      <category>pygame</category>
      <category>geneticprogramming</category>
    </item>
    <item>
      <title>Hugo Shortcodes to Embed Anything</title>
      <dc:creator>Shekhar Chandra</dc:creator>
      <pubDate>Thu, 15 Jul 2021 18:08:15 +0000</pubDate>
      <link>https://dev.to/ranuzz/hugo-shortcodes-to-embed-anything-p7c</link>
      <guid>https://dev.to/ranuzz/hugo-shortcodes-to-embed-anything-p7c</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Hugo is a static site generator suitable for personal websites and blogs. Being an open source project it lets users to manipulate the presentation layer to great extent. Strong theme support and customization options makes it a perfect platform to host almost any kind of web object.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shortcodes
&lt;/h3&gt;

&lt;p&gt;Hugo &lt;a href="https://gohugo.io/content-management/shortcodes/" rel="noopener noreferrer"&gt;shortcodes&lt;/a&gt; lets developers embed any snippet into a markdown article. It comes with a lot of in built shortcodes to embed widgets from most popular sharing platforms. Shortcodes can embed a complete HTML document as well not just script tags and small snippets. This makes it possible to natively embed a small standalone project.&lt;/p&gt;

&lt;p&gt;Shortcodes are &lt;code&gt;html&lt;/code&gt; files which are, by convention, placed in &lt;code&gt;/layouts/shortcodes&lt;/code&gt; directory. Once placed the shortcode can be included in any page using &lt;code&gt;{{\&amp;lt; filename \&amp;gt;}}&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Passing argument
&lt;/h3&gt;

&lt;p&gt;It is possible to pass arguments while including a shortcode. Just add any number of positional arguments like in a command line and hugo will capture them as string on rendering.&lt;/p&gt;

&lt;p&gt;For example, the first argument can be captured as a zeroth positional argument inside the shortcode file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{- $arg0 := .Get "arg0" | default (.Get 0) -}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and can be accessed anywhere in the html document as such&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="na"&gt;arg0&lt;/span&gt; &lt;span class="err"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding Style
&lt;/h3&gt;

&lt;p&gt;Shortcodes get the style definition from the selected theme of custom css. A shortcode specific CSS can be included in the HTML as usual and place in &lt;code&gt;/static/&lt;/code&gt; folder&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript and Minification
&lt;/h3&gt;

&lt;p&gt;The generated HTML gets minified naturally while compiling for production using &lt;code&gt;--minify&lt;/code&gt; option. To make sure the javascript used in the shortcode is minified as well, place them in the &lt;code&gt;/assets&lt;/code&gt; folder and include using hugo minification pipe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;$customjs&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;resources&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Get&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/custom.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;resources&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Minify&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{{ $customjs.Permalink }}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Hugo Shortcode to Render HTML</title>
      <dc:creator>Shekhar Chandra</dc:creator>
      <pubDate>Wed, 14 Jul 2021 20:27:34 +0000</pubDate>
      <link>https://dev.to/ranuzz/hugo-shortcode-to-render-html-4maf</link>
      <guid>https://dev.to/ranuzz/hugo-shortcode-to-render-html-4maf</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Adding raw HTML in &lt;code&gt;hugo&lt;/code&gt; content doesn't render at all in static page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Add a &lt;code&gt;shortcode&lt;/code&gt; in layout folder to handle HTML in a safe manner.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- renderhtml.html --&amp;gt;&lt;/span&gt;
{{- $content := .Get "content" | default (.Get 0) -}}
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    {{ $content | safeHTML }}
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it can be included in any mardown content file as, Just put the raw HTML in between the ticks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{ &amp;lt; renderhtml `&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;` &amp;gt;}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
