<?xml version="1.0"?>
<rss version="2.0">
    <channel>
        <title>OpenRCE: Blog</title>
        <link>http://www.openrce.org/rss/feeds/blog</link>
        <description>OpenRCE: The Open Reverse Code Engineering Community</description>
                <item>
            <title>Unpinning Importet dll's</title>
                            <pubDate>Tue, 13 Jan 2009 13:19:35 -0600</pubDate>
                                        <link>https://www.openrce.org/blog/view/1338/Unpinning_Importet_dll's</link>
                                        <author>Soul12 &lt;email-suppressed@example.com&gt;</author>
                                                    <description>HI.&lt;br /&gt;
&lt;br /&gt;
ever wantet to unload a .dll from memory which was importet via the Import Table ? no , well i have , and turns out that windows prevents you from doing this , for security obiviously , as it would be pretty bad to unload a .dll by accident youd later need :) , but none the less i did some research and found out its more then possible if you preform a little magic , so here are the steps described which are required to do this.&lt;br /&gt;
&lt;br /&gt;
1) Unpinning dll's&lt;br /&gt;
&lt;br /&gt;
when windows Loads a .dll into your process space , the .dll is added to the PEB to be more exact in the PEB-&amp;gt;LoaderData this Double linked list contains all the Modules Loaded into our image space , lets take a look what it looks like.&lt;br /&gt;
&lt;br /&gt;
typedef struct _PEB_LDR_DATA&lt;br /&gt;
{&lt;br /&gt;
ULONG Length;&lt;br /&gt;
BOOLEAN Initialized;&lt;br /&gt;
PVOID SsHandle;&lt;br /&gt;
LIST_ENTRY InLoadOrderModuleList;&lt;br /&gt;
LIST_ENTRY InMemoryOrderModuleList;&lt;br /&gt;
LIST_ENTRY InInitializationOrderModuleList;&lt;br /&gt;
}&lt;br /&gt;
PEB_LDR_DATA, *PPEB_LDR_DATA;&lt;br /&gt;
&lt;br /&gt;
now you see it contains multiple things , for this article the only ones we are interestet in are the 3 LIST_ENTRY's , these 3 are pointers to double linked lists , each entry in the double linked lists contains 1&lt;br /&gt;
&lt;br /&gt;
typedef struct _LDR_MODULE {&lt;br /&gt;
LIST_ENTRY InLoadOrderModuleList;&lt;br /&gt;
LIST_ENTRY InMemoryOrderModuleList;&lt;br /&gt;
LIST_ENTRY InInitializationOrderModuleList;&lt;br /&gt;
PVOID BaseAddress; PVOID EntryPoint;&lt;br /&gt;
ULONG SizeOfImage;&lt;br /&gt;
UNICODE_STRING FullDllName;&lt;br /&gt;
UNICODE_STRING BaseDllName;&lt;br /&gt;
ULONG Flags;&lt;br /&gt;
SHORT LoadCount; SHORT TlsIndex;&lt;br /&gt;
LIST_ENTRY HashTableEntry;&lt;br /&gt;
ULONG TimeDateStamp;&lt;br /&gt;
} LDR_MODULE, *PLDR_MODULE&lt;br /&gt;
&lt;br /&gt;
now all this , is various info about our .dll , but lets go back to when Windows Loads a .dll , Everytime you call LoadLibraryA(&amp;quot;mydll.dll&amp;quot;) windows will add a entry ( if it doesent excist already) and increase the LoadCount by 1 , now what happens when it loads a .dll via our ImportTable ?&lt;br /&gt;
&lt;br /&gt;
well more or less the same except it sets LoadCount to -1 , which means the .dll is pinned , and if this is the case windows will refuse to unload the .dll from memory.&lt;br /&gt;
&lt;br /&gt;
So how do we change this ? well take a look at this code:&lt;br /&gt;
&lt;br /&gt;
bool Mem_Manager::UnPinnAlldlls() {&lt;br /&gt;
OutputDebugStringA(&amp;quot;UnPinning All Dll's&amp;quot;);&lt;br /&gt;
DWORD PebAddr = 0;&lt;br /&gt;
__asm&lt;br /&gt;
{&lt;br /&gt;
mov eax,DWORD PTR FS:[0x18]&lt;br /&gt;
mov eax,DWORD PTR DS:[eax+0x30]&lt;br /&gt;
mov PebAddr,eax&lt;br /&gt;
}&lt;br /&gt;
PPEB Peb = (PPEB)PebAddr;&lt;br /&gt;
_LDR_MODULE *peb_ldr_module;&lt;br /&gt;
peb_ldr_module = (_LDR_MODULE*)Peb-&amp;gt;Ldr-&amp;gt;InLoadOrderModuleList.Flink;&lt;br /&gt;
// Go through each modules one by one in their load order. DWORD First = 0; while((DWORD)peb_ldr_module != First)&lt;br /&gt;
{&lt;br /&gt;
if(First == 0)&lt;br /&gt;
{&lt;br /&gt;
First = (DWORD)peb_ldr_module;&lt;br /&gt;
}&lt;br /&gt;
peb_ldr_module-&amp;gt;LoadCount = 1;&lt;br /&gt;
peb_ldr_module = (_LDR_MODULE*)peb_ldr_module-&amp;gt;InLoadOrderModuleList.Flink;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
what happens is:&lt;br /&gt;
1. Gets Addr of PEB via __asm{} block&lt;br /&gt;
2. Access PEB-&amp;gt;PEB_LDR_DATA&lt;br /&gt;
3. Get First Loaded Module via : Peb-&amp;gt;Ldr-&amp;gt;InLoadOrderModuleList.Flink&lt;br /&gt;
4. Log Address of First Entry ( as its a Recursive Double linked list , so we stop once we been all the way round)&lt;br /&gt;
5. Set RefCount of LoadedModule to 1 , so we can unload it with FreeLibrary&lt;br /&gt;
6. Get Next LoadedModule Via: peb_ldr_module-&amp;gt;InLoadOrderModuleList.Flink&lt;br /&gt;
&lt;br /&gt;
so once , these steps have been preformed , you can unload any .dll with a simpel call to FreeLibrary(&amp;quot;dllName.dll&amp;quot;) and it will be free'd from memory&lt;br /&gt;
&lt;br /&gt;
hope somebody finds this usefull , else oh well :)</description>
                    </item>
                <item>
            <title>My Little packer :)</title>
                            <pubDate>Wed, 06 Feb 2008 17:17:06 -0600</pubDate>
                                        <link>https://www.openrce.org/blog/view/1045/My_Little_packer_:)</link>
                                        <author>Soul12 &lt;email-suppressed@example.com&gt;</author>
                                                    <description>ive decided to finaly get Startet on Coding my own Protection for binaries , im starting small ..and so far i made a SectionAdder which moves the PE to my own Section , updates MZ , Changes EP and writes a JMP OEP @ new EP ... gonna add some simpel Xor encryption and a Loader soon :) heres a first picture for fun ... im a little proud for some odd reason :P hehe&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://img340.imageshack.us/my.php?image=pwnz0rco7.jpg&quot;&gt;http://img340.imageshack.us/my.php?image=pwnz0rco7.jpg&lt;/a&gt;</description>
                    </item>
                <item>
            <title>Asm To C++  Array Converter</title>
                            <pubDate>Thu, 10 Jan 2008 15:02:34 -0600</pubDate>
                                        <link>https://www.openrce.org/blog/view/1020/Asm_To_C++__Array_Converter</link>
                                        <author>Soul12 &lt;email-suppressed@example.com&gt;</author>
                                                    <description>this is a small tool ive written to Convert Large Amounts of ASM into a c++ Comptatible Array .. i found myself doing it allot ..when i was writing test data for Decompiled Functions .. its not very hard todo yourself..but mibi some can use this and save himself the trouble .. atm it supports Olly Bytes and IDA Bytes ..theres examples and sources in the package :) i found usefull .. enjoy&lt;br /&gt;
&lt;br /&gt;
http://www.openrce.org/repositories/users/Soul12/ASM%20to%20C%20Array%20Converter.v.0.2%20Final.rar</description>
                    </item>
                <item>
            <title>Immunity Plugin: Asm -&amp;gt; pseudo C</title>
                            <pubDate>Fri, 17 Aug 2007 08:52:29 -0500</pubDate>
                                        <link>https://www.openrce.org/blog/view/860/Immunity_Plugin:_Asm_-&gt;_pseudo_C</link>
                                        <author>Soul12 &lt;email-suppressed@example.com&gt;</author>
                                                    <description>not much novelty in this :) but i made it it supports simpel commands and make some simpel analyses of cmp's and makes the apropriate IF sentence depending the the jmp below it &lt;br /&gt;
it also tries to find the number of args for function calls&lt;br /&gt;
and orther stuff&lt;br /&gt;
anyways here it is:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://rapidshare.com/files/49550424/ImmunityC.rar.html&quot;&gt;http://rapidshare.com/files/49550424/ImmunityC.rar.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
hope somebody finds it usefull :) its my first publishing of anything aswell ;) </description>
                    </item>
                <item>
            <title>Ranting</title>
                            <pubDate>Sun, 29 Apr 2007 15:56:44 -0500</pubDate>
                                        <link>https://www.openrce.org/blog/view/719/Ranting</link>
                                        <author>Soul12 &lt;email-suppressed@example.com&gt;</author>
                                                    <description>Here zipping some wine after a long weekend :) dident get much RE done ..but long boring story .. just figured id start blogging like everybody else ..and say hello to everybody here those who know me and those who dont .. gonna spend a lovely da y tomorow in school learning about the amazing language &amp;quot;php&amp;quot; my teacher spendt 3 hours last time just setting it up ;) wish me luck so i do not die of boredom</description>
                    </item>
            </channel>
</rss>
