<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by patata on Medium]]></title>
        <description><![CDATA[Stories by patata on Medium]]></description>
        <link>https://medium.com/@skr611?source=rss-13c66a89697f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*b4CrEkDRtvtPXdBgFn6qtw.png</url>
            <title>Stories by patata on Medium</title>
            <link>https://medium.com/@skr611?source=rss-13c66a89697f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:03:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@skr611/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Basic C Concepts]]></title>
            <link>https://medium.com/@skr611/basic-c-concepts-cb2445afea0e?source=rss-13c66a89697f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb2445afea0e</guid>
            <category><![CDATA[c]]></category>
            <dc:creator><![CDATA[patata]]></dc:creator>
            <pubDate>Mon, 20 May 2024 01:19:12 GMT</pubDate>
            <atom:updated>2024-05-20T01:19:12.963Z</atom:updated>
            <content:encoded><![CDATA[<h3>Basic C / Windows API Concepts</h3><p>This is where my journey to becoming a terrible C malware developer begins. Learning some basic C concepts is super important before diving too deep into the world of malware development. I only cover these concepts in a very simple manner and they will be guided towards use in C malware development.</p><p>Disclamer: I am a noob and some of these things may be inaccurate. Only use information related to malware development for testing purposes / ethically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*zju5e4KO6pUbuct47FZ8CQ.jpeg" /></figure><h4>Structures</h4><p>Structures or “Structs” in C programming are user-defined data types that allow you to group related data into one unit and help organize large amounts of data of varying types about an object. A lot of the Windows API functions require populated structures as input.</p><p>An example of a commonly used structure is CreateFileA — this Windows API function takes a structure as input which it then passes to the underlying Windows API function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1OBqtHFVxuHEFkvhfw8feg.png" /><figcaption>CreateFileW Structure</figcaption></figure><p>As you can see, the structure contains many elements of different variable types. When working with these functions, its always a good idea to look up the microsoft official documentation to learn what needs to be provided to each function. Notice how the elements all have [in] on the far left, this is to note the element is input or provided by the user when the function is called. There are other function structures that have [out] elements which note the element is output by the function after it is called.</p><p>You can also declare your own structures which is done with the following syntax</p><pre>typedef PVOID StructureName {<br>  &lt;elements here&gt;<br>} STRUCTURENAME, *PSTRUCTURENAME</pre><p>typedef allows you to create a structure alias that includes the STRUCTURENAME and *PSTRUCTURENAME names. The prior alias refers to the structurename while the latter alias refers to a pointer to the structure.</p><h4>Passing by value vs reference</h4><p>Passing by value is when you pass arguments to a function where the argument is. When passing by value, the object itself is not modified, rather a local copy of it instead and the original value does not change. So, in the code below the original value of num is 5 and even after passing it to the modifyValue function which mulitplies it by 2, the original value is preserved resulting in num being 5. The use cases for this seem slim especially for someone with little C knowledge.</p><pre>void modifyValue(int x) {<br>    x = x * 2;<br>}<br><br>int main() {<br>    int num = 5;<br>    modifyValue(num);<br>    // num is still 5 because the function worked with a copy of num<br>    return 0;<br>}</pre><p>Passing by reference is when you pass the memor address or pointer of the argument to the function. This allows the function to directly access and modify the original value and is performed with pointers and the address-of operator ‘&amp;’.</p><pre>void modifyReference(int *x) {<br>    *x = *x * 2;<br>}<br><br>int main() {<br>    int num = 5;<br>    modifyReference(&amp;num); // Pass the address of num<br>    // num is now 10 because the function modified the original value<br>    return 0;<br>}</pre><h4>Windows API</h4><p>The Windows API is a collection of functions, structures, and other resources that allow developers to create applications that run on windows systems in a structured way. Some of the most important components of the windows api include:</p><ol><li>Kernel32.dll: Provides low-level operating system services such as memory management, process and thread management, file and device I/O, and error handling.</li><li>User32.dll: Contains functions related to the creation and management of user interface elements, including windows, menus, dialogs, and controls.</li><li>Advapi32.dll: Provides functions for advanced system administration tasks, including registry manipulation, security management, and event logging.</li></ol><h4>Common Windows API Data Types</h4><p>There’s a ton but ill just cover the main ones — and in the most basic way possible.</p><p>First some background:</p><ul><li>The variables below relate to Windows API functions and are closely related to typical C variables</li><li>Unsigned means positive numbers only and signed means it allows negative numbers, and 32 bit (4 byte) vs 64 bit (8 byte) integers differ in size. 64 bit integers can hold HUGE numbers compared to 32bit.</li><li>A pointer is a variable that stores the memory address of another variable.</li></ul><p>Data Types</p><ul><li>DWORD: 32 bit unsigned integer</li><li>size_t: 64 bit unsigned integer; represents the size of an object</li><li>VOID: absence of a data type; useful for functions that have no return value and for generic pointers</li><li>PVOID: 64 bit pointer of any data type; ‘&amp;’ operator can be used to call the memory location of some variable/data</li><li>HANDLE: defined as a PVOID type meaning its a generic/abstract pointer to an object; a handle to an object such as a file is needed to access and manipulate the file object</li><li>LPCSTR (AKA long pointer to constant string): a pointer to a constant string; L stands for long in this case so the only difference is the size of string it represents.</li><li>LPSTR (AKA long pointer to string) a pointer to a string, equivalent to char*; same thing as the above but its not a constant string</li><li>LPCWSTR (AKA long pointer to constant wide string): pointer to a constant wide (16-bit) string, equivalent to const wchar*</li><li>PWSTR (AKA pointer to wide string): pointer to a wide (16-bit) string; same as above but not a constant string</li><li>wchar_t: same as wchar; used to represent wide characters</li><li>ULONG_PTR: represents an unsigned integer based on the system architecture (32bit vs 64bit); in maldev this is often used to manipulate calculation/arithmetic expressions containing pointers (like PVOID). <br> — Before executing any arithmetic operations w/ pointers, the pointer will be type-casted (discussed later) to ULONG_PTR to avoid direct manipulation of pointers which is a no no.</li></ul><h4>Windows API Data Type Pointers</h4><p>Windows API allows you to declare a data type directly or a pointer to the data type — data types that start with “P” are pointers to data types. This will be useful when interacting with Windows APIs that have parameters that are pointers to a data type</p><ul><li>PHANDLE is the same as HANDLE*</li><li>PSIZE_T is the same as SIZE_T*</li></ul><h4>ANSI vs Unicode Functions</h4><p>Most of the windows API functions have ‘A’ and ‘W’ variants which vary in how they handle character encoding.</p><ul><li>ANSI functions that accept strings are denoted with the ‘A’ at the end such as CreateFileA. Strings are represented with the char data type.</li><li>Unicode functions that accept strings are denoted with the ‘W’ at the end such as CreateFileW. Strings are represented with the wchar_t data type.</li></ul><p>The CreateFileA function’s first parameter is LPCSTR which is a pointer to a null-terminated 8-bit string of windows ANSI characters. On the other hand, the CreateFileW function’s first parameter is LPCWSTR which is a 16-bit, null-terminated 16-bit string of unicode characters. When using the Unicode/W functions you’ll have to prepend the string with an ‘L’ which tells the compiler to interpret the string as a sequence of wide characters.</p><h4>Example of using a Windows API</h4><p>A simple example of using the MessageBoxA winapi function can be seen below. If you look at the parameters below, they dont make much sense without referencing the microsoft documentation. Once you learn more about each element (data type, in or out, options etc.) the functions start to make more sense.</p><pre>MessageBoxA(NULL, &quot;You think thats air you&#39;re breathing?&quot;, &quot;Error&quot;, MB_OK | MB_ICONWARNING);</pre><h3>Conculsion</h3><p>If you’ve made it this far, you may know a little more about some basic C concepts than before. Again, this is more for my own learning and some of the information above may be misrepresented / not fully accurate.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb2445afea0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>