Answer
stringlengths
38
29k
Id
stringlengths
1
5
CreationDate
stringlengths
23
23
Body
stringlengths
55
28.6k
Title
stringlengths
15
145
Tags
stringlengths
3
68
<p>Here's how you can automate the labelling process:</p> <pre class="lang-py prettyprint-override"><code>import idc, idautils FUNC_LIB = 4 # Here go your selected functions # This labels everything unless you specify the start/end args funcs = idautils.Functions() for ea in funcs: flags = idc.get_func_flags(ea) | FUNC_LIB idc.set_func_flags(ea, flags) </code></pre> <p>To label a library function we set <a href="https://hex-rays.com/products/ida/support/idadoc/337.shtml" rel="nofollow noreferrer"><code>FUNC_LIB</code></a> flag.</p> <p>You will likely need to write a plugin for UI integration to get the selected functions. If they are in a contiguous address space you can just pass its range in <code>idautils.Functions(start_ea, end_ea)</code>.</p>
32073
2023-07-19T05:09:09.683
<p>I have a binary with debug information and I want to mark STL library functions with &quot;Library function&quot; tag as quick as possible, just by highlighting a range of functions and clicking some button instead of marking every function &quot;Library function&quot; by hand. <a href="https://i.stack.imgur.com/AGxd7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AGxd7.png" alt="list of functions" /></a></p> <p><a href="https://i.stack.imgur.com/fxti4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fxti4.png" alt="" /></a></p> <p>Is there is a way to do that quick?</p>
How to quickly mark functions library in IDA Pro?
|ida|idapython|python|script|
<p>You've stumbled into a complicated question. I'll try to answer it in detail, but for starters, the fact that there are two locations shown for a single stack variable does not mean that it is at two different locations. It means that Hex-Rays is using two different ways of referring to the same location on the the stack. Both shown offsets must be interpreted with care, can be highly misleading, and can also be outright wrong. I will explain all of those points below.</p> <p>For the sake of discovering local variables on the stack and performing analyses that determine what memory may be overwritten by a given memory write, Hex-Rays needs a consistent way to refer to offsets on the stack. This is complicated because <code>rsp</code> can change throughout the function, and because not all functions use frame pointers like <code>rbp</code>. Thus, it has to do something else to keep track of stack offsets. So, Hex-Rays computes the lowest stack value at any point within the function, uses that as the &quot;bottom of the stack&quot;, and performs all stack-based analysis relative to that point.</p> <p>When Hex-Rays prints local variables and displays strings off to the right like <code>[rsp+30h]</code>, that refers to Hex-Rays' internal computation of where the bottom of the stack is. Since <code>rsp</code> can change throughout a function, the location <code>rsp+0x30</code> might mean different things at different points in the function. On x64/Windows binaries that conform to the x64 ABI, <code>rsp</code> will have a consistent value after the function prolog and before the epilog, so the numbers should be reasonably safe to use after the prolog and before the epilog (though I've noticed that they are sometimes off by 8). Since the prolog and the epilog change <code>rsp</code>, those numbers won't be meaningful during the prolog or epilog. In particular, on the first line of the function before the prolog has executed, the <code>rsp</code> number is especially meaningless. On x86 binaries, <code>esp</code> changes often throughout a function, and so those numbers will be generally unreliable as a way to locate stack variables on <code>x86</code>.</p> <p>Meanwhile, when Hex-Rays prints a string like <code>[rbp-38h]</code>, the <code>38h</code> refers to offset within IDA's stack frame for the function. I.e., if you were to look at the top of the function, you might see something like:</p> <pre><code>.text:000000006202C6F0 var_40= qword ptr -40h .text:000000006202C6F0 a1 = xmmword ptr -38h ; &lt;--- HERE .text:000000006202C6F0 var_28= qword ptr -28h .text:000000006202C6F0 var_18= byte ptr -18h </code></pre> <p>Although the offsets line up with what's in the stack view, Hex-Rays always prints <code>rbp</code>, whereas x64 functions can use other non-volatile registers as frame pointers. Therefore, you won't always be able to find the value at <code>rbp-Offset</code>, either; you would need to substitute whatever register is being used for the frame pointer (such as <code>r11</code>) in place of <code>rbp</code>. And note that, like <code>rsp</code>, <code>rbp</code> will also change values within the function (e.g. being set in the prolog and restored in the epilog), so even if a function is using <code>rbp</code> as a frame pointer, the <code>rbp-N</code> offsets will only make sense after the prolog and before the epilog.</p> <p>If you'd like more technical details about this, you should take a look at <code>hexrays.hpp</code> in the IDA SDK. Specifically, there is a diagram showing what Hex-Rays thinks about the stack, and how the <code>rsp</code>-relative numbers are related to the <code>rbp</code>-relative numbers. You want to search that <code>.hpp</code> file for <code>tmpstk_size</code>. It's also <a href="https://www.hex-rays.com/products/decompiler/manual/sdk/hexrays_8hpp_source.shtml" rel="nofollow noreferrer">available online</a>. As of the time of writing, it begins on line 4596. I've reproduced it here:</p> <pre><code>/* +-----------+ &lt;- inargtop | prmN | | ... | &lt;- minargref | prm0 | +-----------+ &lt;- inargoff |shadow_args| +-----------+ | retaddr | frsize+frregs +-----------+ &lt;- initial esp | | frregs | | +frsize +-----------+ &lt;- typical ebp | | | | | | | | fpd | | | | | | frsize | &lt;- current ebp | | | | | | | | | | stacksize | | | | | | | | &lt;- minstkref | stkvar base off 0 +---.. | | | current | | | | stack | | | | pointer | | | | range |tmpstk_size| | | (what getspd() returns) | | | | | | | | +-----------+ &lt;- minimal sp | | offset 0 for the decompiler (vd) There is a detail that may add confusion when working with stack variables. The decompiler does not use the same stack offsets as IDA. The picture above should explain the difference: - IDA stkoffs are displayed on the left, decompiler stkoffs - on the right - Decompiler stkoffs are always &gt;= 0 - IDA stkoff==0 corresponds to stkoff==tmpstk_size in the decompiler - See stkoff_vd2ida and stkoff_ida2vd below to convert IDA stkoffs to vd stkoff */ </code></pre> <p>TL;DR the reason Hex-Rays shows you two different representations for where a variable is on the stack is because Hex-Rays itself, and IDA, use two different ways of representing the stack frame. The <code>rbp-N</code> numbers refer to the offsets you see in IDA's stack view, and the <code>rsp+N</code> numbers refer to displacements from what Hex-Rays thinks is the bottom of the stack.</p> <p>Especially considering that <code>rsp</code> and <code>rbp</code> can change throughout a function, the addresses it shows won't be meaningful at every point within the function. Particularly, none of the numbers make sense before the prolog has finished executing, or after the epilog has begun executing. The <code>esp</code> numbers are particularly unreliable on 32-bit <code>x86</code>, and Hex-Rays will show frame-relative offsets using the <code>rbp</code> register even if the function uses a different register like <code>r11</code> for a frame pointer.</p> <p>Simple, right? ;-)</p>
32074
2023-07-19T06:36:02.297
<p>Suppose I have a function, I know that the first 4 arguments come with fixed registers.</p> <pre><code>_BYTE *__fastcall foo(__int64 a1, _QWORD *a2, unsigned int a3, char a4, _QWORD *a5) </code></pre> <p>For the fifth one, if I move my mouse on that argument, it displays a hint</p> <pre><code>_QWORD *a5 // [rsp+120h] [rbp+28h] ISARG BYREF BYREF: address of this variable is taken somewhere in the current function (e.g. for passing to a function call); ISARG: shown for function arguments (in mouse hint popups); </code></pre> <p>According to <a href="https://hex-rays.com/blog/igors-tip-of-the-week-66-decompiler-annotations/" rel="nofollow noreferrer">documentation</a>.The fist part of the comment is the variable location. However, rsp[0xffff940a1f436b48]+120h and rbp[0xffff940a1f436bf9]+28h are 2 different values. Does that mean the argument is stored in 2 locations? If it's stored separately, how do I know how many bytes are stored in those 2 locations?</p> <p>I just tried several times. It works fine now.</p> <pre><code>1. rsp = 0xffff86817543df49 rbp = 0xffff86817543de98 2. rsp = 0xffff868175428b48 rbp = 0xffff868175428bf9 3. rsp = 0xffff868175692e18 rbp = 0xffff868175692ee0 </code></pre>
split function argument from IDA's hints
|ida|functions|
<p>You can't control where the compiler will put a local variable on the stack. It could put it anywhere on the stack, or even eliminate it entirely (for example, hold it in a register). There's a reason that mitigations like these are implemented inside of the compiler itself and not as source-level transformations.</p>
32078
2023-07-19T17:46:12.330
<p>Can i insert a variable in c source code That will be right before the stack canary, and after all local variables. Like I want to try to implement my own stack canary in source code, is it possible?</p> <p>Thanks</p> <p><strong>Update</strong></p> <p>Can you please explain to me what is this code in <a href="https://elixir.bootlin.com/glibc/latest/source/sysdeps/x86_64/stackguard-macros.h#L3" rel="nofollow noreferrer">linux source code</a>?</p> <pre><code>#define STACK_CHK_GUARD \ ({ uintptr_t x; \ asm (&quot;mov %%fs:%c1, %0&quot; : &quot;=r&quot; (x) \ : &quot;i&quot; (offsetof (tcbhead_t, stack_guard))); x; }) </code></pre> <p>If it's in the compiler what exactly is this implantation?</p>
Can I insert a variable right before the stack canary
|stack-protector|
<p>why using switch s ? switch s takes a size parameter and you do not give it ?</p> <p>you are looking for a symbol from ndis on a module named tcpip ?</p> <p>what is the L?0xffffxxxx doing there ?</p> <p>are you sure symbol name takes the form of string with enclosed double quotes ?</p> <p><a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/x--examine-symbols-" rel="nofollow noreferrer">Have you referred the documentation ?</a></p> <p>x examines symbols and it takes a symbol name not a string<br /> x does not use module start len format it either takes a complete symbol name or a wild card with partial symbol name</p> <p>arguments are available only if the pdb has full type information</p> <p>most of the public pdbs availabe in ms symbol store are stripped of type information<br /> so there is no way you can find the function arguments</p> <p>in your case ndis has type information but tcpip does not</p> <p>if there is type information you can use .shell command</p> <p>redirect the output to be parsed with external utility like grep sed awk find findstr etc</p> <pre><code>0: kd&gt; .shell -ci &quot;x ndis!*&quot; grep _NET_BUFFER_LIST fffff805`79a45d64 ndis!ndisPendWorkOnSetBusyAsyncLocked (void __cdecl ndisPendWorkOnSetBusyAsyncLocked(struct _NDIS_SELECTIVE_SUSPEND *,enum _NDIS_SS_BUSY_REASON,void *,unsigned long,struct _NET_BUFFER_LIST * *,struct _LIST_ENTRY *,unsigned char *)) fffff805`79a4bed0 ndis!ndisVerifierNdisFSendNetBufferListsComplete (void __cdecl ndisVerifierNdisFSendNetBufferListsComplete(void *,struct _NET_BUFFER_LIST *,unsigned long)) fffff805`79a46374 ndis!ndisReplaySendNbls (void __cdecl ndisReplaySendNbls(struct _NDIS_MINIPORT_BLOCK *,struct _NET_BUFFER_LIST *,unsigned char)) fffff805`79a5c250 ndis!ndisMCoSendNetBufferListsCompleteToNetBufferLists (void __cdecl ndisMCoSendNetBufferListsCompleteToNetBufferLists(void *,struct _NET_BUFFER_LIST *,unsigned long)) fffff805`79a461f8 ndis!ndisRemoveFromNblQueueByCancelId (struct _NET_BUFFER_LIST * __cdecl ndisRemoveFromNblQueueByCancelId(struct _NBL_QUEUE *,void *)) </code></pre> <p>tcpip does not have type information</p> <pre><code>0: kd&gt; .shell -ci &quot;x tcpip!en*&quot; grep -i no.*type.*inf.* fffff805`79df45e0 tcpip!EndpointSessionState = &lt;no type information&gt; fffff805`79dfbb58 tcpip!endpointPPLookasideList = &lt;no type information&gt; fffff805`79df55f0 tcpip!engineData = &lt;no type information&gt; fffff805`79dfbd88 tcpip!endpointLruLookasideList = &lt;no type information&gt; fffff805`79dfbc80 tcpip!endpointHandleTable = &lt;no type information&gt; fffff805`79df5820 tcpip!endpointCleanupWorkQueue = &lt;no type information&gt; .shell: Process exited </code></pre>
32085
2023-07-22T13:27:39.517
<p>I want to use the x command to search for functions that take _NET_BUFFER_LIST as an argument(maybe they will take more than one argument). Its symbol is ndis!_NET_BUFFER_LIST. The command I use</p> <pre><code>0:000&gt; x /s module!module+0x1000 L?0xffffffff &quot;ndis!_NET_BUFFER_LIST&quot; Couldn't resolve error at 'tcpip!tcpip+0x1000 L?0xffffffff &quot;ndis!_NET_BUFFER_LIST&quot;' 0:000&gt; x /s module!module+0x1000 L?0xffffffff ndis!_NET_BUFFER_LIST Couldn't resolve error at 'tcpip!tcpip+0x1000 L?0xffffffff ndis!_NET_BUFFER_LIST' </code></pre> <p>How should I change my command to achieve my goal?</p> <p>I have tried commands in various forms. Some of them may not qualify the syntax. I thought add 'L?0xffffffff' could make sure dbg only walk through one module. But like blabb said, I should use another method instead and x doesn't support offset.</p>
windbg command to search all functions that take in certain arguments
|windbg|
<p>In x64dbg, You can right-click the beginning of the function or any place in the instructions/disassembly that you want the execution to continue from for that matter, and simply press on &quot;Set New Origin Here&quot; or Ctrl+*.</p>
32103
2023-07-28T14:20:16.427
<p>I'm currently debugging a program using x64dbg, and I'm wondering how to quickly jump to the start or end (prologue/epilogue) of a function while I'm in the middle of it. I couldn't find this information through Googling.</p> <p>Specifically, I'd like to know if x64dbg has any built-in commands or shortcuts to navigate directly to the beginning or end of a function while debugging. If such functionality exists, what are the steps or commands to use it effectively?</p> <p>Additionally, if there are any alternative methods or plugins available that can achieve this, I'd appreciate hearing about them as well.</p> <p>Related</p> <ul> <li><a href="https://reverseengineering.stackexchange.com/questions/17042/how-to-jump-to-the-start-end-of-a-function-in-ida-disassembly">How to jump to the start/end of a function in IDA disassembly?</a></li> </ul>
How can I jump to the start/end of a function in x64dbg?
|debugging|x64dbg|functions|
<p>As suggested in a comment, the final character is indeed a check digit. It appears to be calculated using the <a href="https://en.wikipedia.org/wiki/Luhn_algorithm" rel="nofollow noreferrer">Luhn algorithm</a> with 25 as the base instead of 10.</p> <p>Using the code in photo as an example:</p> <ol> <li>The code without a check digit: <code>7MXWNLH4ZQ3</code>.</li> <li>Convert to decimal: <code>[2, 1, 15, 3, 6, 13, 9, 7, 12, 17, 14]</code>.</li> <li>Start from the right and double every number in an even position.</li> <li>If a number exceeds 24, re-encode it and sum the digits (e.g. 14 × 2 = 28, which becomes <code>MW</code>, which becomes <code>[1, 3]</code>, which becomes 4).</li> <li>Sum all the digits.</li> <li>If <code>(total % 25) &gt; 0</code>, the check digit is <code>25 - (total % 25)</code>, otherwise it's <code>0</code>.</li> <li>In this case, it's 16, or <code>K</code> in the base 25 character set.</li> </ol> <hr /> <p><strong>Update:</strong> I've created a script to do all this, available on GitHub <a href="https://github.com/sapphire-bt/mcdonalds-uk-survey-codes" rel="nofollow noreferrer">here</a>.</p>
32129
2023-08-04T14:38:09.683
<p>Receipts from McDonald's in the UK include a code that allows you to complete an online survey as shown in the attached image (in the green box):</p> <p><a href="https://i.stack.imgur.com/pBh00.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/pBh00.jpg" alt="McDonald's receipt" /></a></p> <p>After gathering and comparing several receipts I have deduced that the codes use a base 25 alphanumeric system consisting of the following characters:</p> <pre><code>C M 7 W D 6 N 4 R H F 9 Z L 3 X K Q G V P B T J Y 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 </code></pre> <p>25 would therefore be <code>MC</code>, 26 <code>MM</code>, 27 <code>M7</code>, etc.</p> <p>The code for this receipt is <code>7MXW-NLH4-ZQ3K</code> and can be broken down as follows:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Code</th> <th>Decimal</th> <th>Meaning</th> </tr> </thead> <tbody> <tr> <td><code>7MX</code></td> <td>1290</td> <td>Store ID.</td> </tr> <tr> <td><code>W</code></td> <td>3</td> <td>Not sure, but the vast majority of receipts always seem to have <code>W</code> here.</td> </tr> <tr> <td><code>NL</code></td> <td>163</td> <td>Order ID: last two digits + 125, so can be reversed by <code>163 % 125</code> which is 38.</td> </tr> <tr> <td><code>H4ZQ3K</code></td> <td>90,823,491</td> <td>Probably the date/time of purchase - more below.</td> </tr> </tbody> </table> </div> <p>I have noticed that the last number (i.e. what I assume is the purchase date/time) increases with time when comparing receipts.</p> <p>For example, another code's last 6 characters are <code>H4F6XN</code> (90,784,756) and the order was placed on 2022-12-27 19:10:05, just over a day before. A quick comparison:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Order 1</th> <th>Order 2</th> <th>Difference</th> </tr> </thead> <tbody> <tr> <td>90,823,491</td> <td>90,784,756</td> <td>38,735</td> </tr> <tr> <td>2022-12-28 20:59:51</td> <td>2022-12-27 19:10:05</td> <td>92,986 (seconds)</td> </tr> </tbody> </table> </div> <p>Dividing the difference of seconds by the difference of the 6 character number:</p> <pre><code>92,986 ÷ 38,735 = 2.4 (approx.) </code></pre> <p>It would therefore seem that the number increases by 1 every 2.4 seconds. The result of 60 ÷ 25 also happens to be 2.4 which means 1/25th of a minute can be represented by a character from the base 25 system.</p> <p>Following the assumption of the number increasing by 1 every 2.4 seconds it seems that the first datetime (or &quot;epoch&quot;) is approximately <code>2016-02-01 00:00:00</code>.</p> <p>Therefore to decipher the final value of <code>H4ZQ3K</code> in the first receipt:</p> <ol> <li>90,823,491 × 2.4 = 217,976,378.4 seconds</li> <li>2016-02-01 00:00:00 + 217,976,378.4 seconds = 2022-12-28 20:59:38.4</li> </ol> <p>...but note how the predicted timestamp is incorrect - off by 12.6 seconds (the other receipt comes out at 2022-12-27 19:10:14.4 - 9.4 seconds ahead).</p> <p>I'm stumped as to what's causing the error - does anyone have any ideas?</p> <p>Some more codes for reference (note how the predicted timestamp is never more or less than 60 seconds):</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Code</th> <th>Last 6 chars (decimal)</th> <th>Purchased</th> <th>Predicted</th> <th>Ahead by (seconds)</th> </tr> </thead> <tbody> <tr> <td><code>7MXW-NLH4-ZQ3K</code></td> <td>90,823,491</td> <td>2022-12-28 20:59:51</td> <td>2022-12-28 20:59:38.4</td> <td>-12.6</td> </tr> <tr> <td><code>M3NW-YRH4-F6XN</code></td> <td>90,784,756</td> <td>2022-12-27 19:10:05</td> <td>2022-12-27 19:10:14.4</td> <td>+9.4</td> </tr> <tr> <td><code>MNKW-M6H4-7FQX</code></td> <td>90,662,940</td> <td>2022-12-24 09:57:46</td> <td>2022-12-24 09:57:36</td> <td>-10</td> </tr> <tr> <td><code>CRGW-ZYHN-KHBP</code></td> <td>90,490,545</td> <td>2022-12-19 15:01:03</td> <td>2022-12-19 15:01:48</td> <td>+45</td> </tr> <tr> <td><code>CQMW-L9HN-KNC7</code></td> <td>90,488,127</td> <td>2022-12-19 13:25:56</td> <td>2022-12-19 13:25:04.8</td> <td>-51.2</td> </tr> <tr> <td><code>M9JW-QCH6-PT3Z</code></td> <td>90,170,362</td> <td>2022-12-10 17:34:42</td> <td>2022-12-10 17:34:28.8</td> <td>-13.2</td> </tr> <tr> <td><code>7NLW-NFH6-7XLV</code></td> <td>89,884,719</td> <td>2022-12-02 19:08:02</td> <td>2022-12-02 19:08:45.6</td> <td>+43.6</td> </tr> <tr> <td><code>MLZW-Y3HD-YTP9</code></td> <td>89,842,386</td> <td>2022-12-01 14:55:38</td> <td>2022-12-01 14:55:26.4</td> <td>-11.6</td> </tr> <tr> <td><code>MBQW-RCHD-YNQ9</code></td> <td>89,832,311</td> <td>2022-12-01 08:12:04</td> <td>2022-12-01 08:12:26.4</td> <td>+22.4</td> </tr> <tr> <td><code>MP4W-6DHM-QNNC</code></td> <td>88,550,775</td> <td>2022-10-26 17:51:16</td> <td>2022-10-26 17:51:00</td> <td>-16</td> </tr> <tr> <td><code>7HGW-RFRG-9JX9</code></td> <td>85,342,886</td> <td>2022-07-29 15:15:30</td> <td>2022-07-29 15:15:26.4</td> <td>-3.6</td> </tr> <tr> <td><code>MJFW-YNRK-P66H</code></td> <td>84,690,759</td> <td>2022-07-11 12:30:01</td> <td>2022-07-11 12:30:21.6</td> <td>+20.6</td> </tr> <tr> <td><code>CRFD-NZRZ-JZGP</code></td> <td>83,179,845</td> <td>2022-05-30 13:13:26</td> <td>2022-05-30 13:13:48</td> <td>+22</td> </tr> </tbody> </table> </div><hr /> <p>Python functions for encoding/decoding:</p> <pre class="lang-py prettyprint-override"><code>CHARS = &quot;CM7WD6N4RHF9ZL3XKQGVPBTJY&quot; BASE = len(CHARS) def encode(num): encoded = &quot;&quot; while num &gt;= BASE: encoded = CHARS[num % BASE] + encoded num //= BASE return CHARS[num] + encoded def decode(encoded): num = 0 for x, c in enumerate(encoded): exp = len(encoded) - x - 1 num += (BASE**exp) * CHARS.find(c) return num </code></pre>
McDonald's receipt codes
|decryption|encryption|
<p>The code that runs before your <code>main</code> function is the C Runtime (CRT) initialization code. There are ways to remove it, such as via the <code>/NODEFAULTLIB</code> and <code>/ENTRY</code> command-line options to the linker, but be careful what you wish for. If any of your code calls functions in the C standard library (such as <code>printf</code>, <code>malloc</code>, etc.), you will not be able to link your code into a final binary unless you provide your own implementations for those functions. Your implementations must be from scratch; you won't be able to rely upon any standard library functions, or implement them using any third-party library that itself relies upon the standard library. This is not a beginner-friendly task, to put it mildly.</p> <p>To find the <code>main</code> function in a binary: first, note that tools such as IDA do this automatically. To do it manually, first familiarize yourself with the CRT functions that execute before <code>main</code>, find where it calls <code>main</code>. Then, for any given binary, you can locate the address of <code>main</code> by examining those CRT functions around the locations where they call <code>main</code>.</p>
32131
2023-08-04T16:11:23.003
<p>I am using x64dbg to explore image files on Windows. After the computer finishes prowling ntdll.dll it jumps to OptionalHeader.AddressOfEntryPoint. But this is not my main()-function.</p> <ol> <li>What is this code in my EXE that is not mine?</li> <li>Can you remove it so there is only my main()-function remaining?</li> <li>Do you know a way to find the main()-function easily?</li> </ol>
Create exe that jumps directly into main()-function from C
|c|pe|x64dbg|
<p>Looks like some form of <a href="https://en.wikipedia.org/wiki/Run-length_encoding" rel="nofollow noreferrer">run length encoding</a> could be custom since it's quite simple to write. You can lookup run length encoding in TGA image files for a code example. But personally I would first check if it's LZ4 since that uses RLE. You will likely need to use the LZ4 api if so. I would write a for loop that attempts to LZ4 inflate at offset 0,1,2,3,... and see if any complete without error and have an expected size.</p>
32134
2023-08-05T20:25:07.283
<p>I'm trying extract .wav files from a datafile, and each file has some metadata at the end of it. It contains a date, '1996-05-16' as shown here:</p> <p><a href="https://i.stack.imgur.com/qQCAX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qQCAX.png" alt="enter image description here" /></a></p> <p>Most of these dates for the files are correct, but some have special chars in them, like here:</p> <p><a href="https://i.stack.imgur.com/puYV9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/puYV9.png" alt="enter image description here" /></a></p> <p>What's going on? I'm using the HxD editor.</p> <p>edit: also seeing these zeros between 'RIFF' which should be a complete word/identifier for WAV files. Is the data corrupted? I get the feeling the .EXE might be doing some decoding on this data? <a href="https://i.stack.imgur.com/gWXVA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gWXVA.png" alt="enter image description here" /></a></p>
I don't understand this hexeditor output
|hex|
<p>In every line the sum of all big-endian words modulo <code>0xFFFF</code> equals to 0.<br /> Example (the last line):</p> <pre><code>0x4547 + 0x4953 + 0x0000 + ... + 0x9341 + 0xc0b4 + 0x3b00 = 0x9FFF6 </code></pre> <p>To verify the checksum:</p> <ul> <li>append zero byte if number of bytes is odd;</li> <li>calculate 32-bit sum of 16-bit words;</li> <li>split the sum into 16 low bits and 16 high bits;</li> <li>calculate the 16-bit sum (or <code>xor</code>) of the two halves;</li> <li>the result must be equal to <code>0xFFFF</code>.</li> </ul>
32157
2023-08-11T15:12:23.453
<p>I have been working on reverse engineering and building a Linux driver for a fingerprint reader and have most of it sorted out, but one thing which continues to elude me is that there seems to be 2 bytes in each payload that are some kind of &quot;check bytes.&quot; I am not sure if one or both are some kind of CRC, a simple sum or XOR of the bytes in some order, maybe some offset or constant XOR being applied to them, or something? But it seems like any kind of logic I work out for 2 or 3 of the examples does not fit for the others.</p> <p>Does anyone have any thoughts on what how these could be generated? More info here if you are super curious to dig in: <a href="https://gitlab.freedesktop.org/libfprint/libfprint/-/issues/569" rel="nofollow noreferrer">https://gitlab.freedesktop.org/libfprint/libfprint/-/issues/569</a></p> <p>The &quot;payloads&quot; seem to have an 8 byte prefix (one when reading from the device's bulk in, and one when sending to the device's bulk out), followed by these 2 &quot;check&quot; bytes (not calling them a &quot;checksum&quot; yet as I am not sure what either of them actually represent), then 3 &quot;0&quot; bytes, and either 1 or 2 bytes of some kind of type/subtype byte to indicate the type of event or message being sent, finally followed by some kind of &quot;actual&quot; payload for the specific event.</p> <p>I am still not sure if the prefix is included in the check algorithm or if it only looks at what comes payload which comes after everything else, or if when there is occasionally some type/subtype suffixes that these are or are not included either.</p> <p>But here are some examples:</p> <p>BULK IN example payloads (as hex bytes) read from the device during a trace:</p> <pre><code>53 49 47 45 00 00 00 01 d5 6d 00 00 00 02 90 00 53 49 47 45 00 00 00 01 d4 6d 00 00 00 02 91 00 53 49 47 45 00 00 00 01 d5 69 00 00 00 02 90 04 53 49 47 45 00 00 00 01 ff 6f 00 00 00 02 65 fe 53 49 47 45 00 00 00 01 ff d0 00 00 00 04 01 0a 64 91 53 49 47 45 00 00 00 01 fe d0 00 00 00 04 02 0a 64 91 53 49 47 45 00 00 00 01 d2 61 00 00 00 04 03 0a 90 00 53 49 47 45 00 00 00 01 cb 61 00 00 00 04 0a 0a 90 00 53 49 47 45 00 00 00 01 3a d8 00 00 00 0d 39 30 35 30 2e 31 2e 31 2e 38 31 90 00 53 49 47 45 00 00 00 01 8d 2c 00 00 00 06 02 04 46 39 90 00 53 49 47 45 00 00 00 01 9f a5 00 00 00 22 01 89 c4 7f 37 a5 e6 f9 81 c2 b5 45 66 ec 3b ff 26 04 39 77 cb 35 44 ae e8 1d 29 93 41 c0 b4 3b 90 00 </code></pre> <p>BULK OUT example payloads (as hex bytes) sent to the device from the Windows driver during a trace:</p> <pre><code>45 47 49 53 00 00 00 01 04 54 00 00 00 07 50 07 00 02 00 00 1d 45 47 49 53 00 00 00 01 1d 1a 00 00 00 07 50 43 00 00 00 00 04 45 47 49 53 00 00 00 01 00 47 00 00 00 07 50 16 01 00 00 00 20 45 47 49 53 00 00 00 01 1d 45 00 00 00 07 50 16 02 02 00 00 02 45 47 49 53 00 00 00 01 21 46 00 00 00 04 50 1a 00 00 45 47 49 53 00 00 00 01 1f 49 00 00 00 04 50 16 02 01 45 47 49 53 00 00 00 01 fc 46 00 00 00 07 50 16 05 00 00 00 20 45 47 49 53 00 00 00 01 55 f1 00 00 00 27 50 16 03 00 00 00 20 01 89 c4 7f 37 a5 e6 f9 81 c2 b5 45 66 ec 3b ff 26 04 39 77 cb 35 44 ae e8 1d 29 93 41 c0 b4 3b </code></pre> <p>Any ideas?</p>
Derive logic for 2 "check bytes" for a USB fingerprint reader
|crc|checksum|
<p>Frida seems to have some bugs regarding Java arrays that are modified or replaced by JavaScript code. My guess is that the conversion (and mapping of modifications) between the Java array instance and JavaScript array instance has some flaws.</p> <p>Therefore the only alternative I see is using pure Java methods to modify the array content, that way you should be able to bypass this bug.</p> <p>One possible way is to use the method <code>Arrays.fill(Object[] array, int fromIndex,int toIndex, Object val)</code><a href="https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#fill-java.lang.Object:A-int-int-java.lang.Object-" rel="nofollow noreferrer"><sup>1</sup></a>:</p> <pre><code>var stringClass = Java.use(&quot;java.lang.String&quot;); var stringInstance = stringClass.$new(&quot;Hello World&quot;); var arraysClass = Java.use(&quot;java.util.Arrays&quot;); arraysClass.fill(var_0, 0, 1, stringInstance); // equivalent to var_0[0] = stringInstance </code></pre> <p>I have not tested this code, but it should perform the array modification you want to do.</p>
32161
2023-08-11T18:55:09.570
<p>Let's assume we have a such code snippet:</p> <pre><code>public class Test { public void testArrayValue() { Object[] objects = new Object[1]; fillObject(objects); Log.d(&quot;test&quot;, (String)objects[0]); } public void fillObject(Object[] objects) { objects[0] = new String(&quot;fillObject str&quot;); } } </code></pre> <p>How to hook the fillObject method to change the value of the first element in array passed to method?</p> <pre><code>Java.perform(function () { var clazz = Java.use(&quot;com.some.package.Test&quot;); clazz.fillObject.overload('[Ljava.lang.Object;').implementation = function(var_0) { // this won't work :( assigning a string value to var_0[0] // does not pass it outside the hooked code // var stringClass = Java.use(&quot;java.lang.String&quot;); var stringInstance = stringClass.$new(&quot;Hello World&quot;); var_0[0] = stringInstance }; }); </code></pre> <p>The output of running hooked code will be &quot;fillObject str&quot;, and not &quot;Hello World&quot;</p>
Frida Android how to change value of array passed to method
|java|frida|
<p>I just followed the guide from blabb. In my IDA, it's Edit-&gt;Segments-&gt;Rebase program. The image base is 0x1C0000000 instead of 1C0001000. The PE has some other headers before the section headers(.text,.data etc) to provide other essential information for the OS to manage files.</p> <p>The command Ali gave me was not working due to <a href="https://hex-rays.com/products/ida/support/ida74_idapython_no_bc695_porting_guide.shtml" rel="nofollow noreferrer">spec</a>. The below command should work but it didn't subtract the real image base and the output was the same as the wrong one.</p> <pre><code>ida_ida.inf_get_min_ea()-idc.get_screen_ea() </code></pre>
32164
2023-08-12T08:39:41.197
<p>In IDA, I see a value called dword_1C0203AB4 which doesn't have a symbol name. I want to view the value in system. My windbg is connected to the system and the driver files in system and IDA is the same. My approach is to calculate the offset and add it to the base memory.</p> <pre><code>start .text:00000001C0001000 _text segment para public 'CODE' use64 .text:00000001C0001000 assume cs:_text .text:00000001C0001000 ;org 1C0001000h .text:00000001C0001000 assume es:nothing, ss:nothing, ds:_data, fs:nothing, gs:nothing .text:00000001C0001000 db 8 dup(0CCh) .text:00000001C0001008 .text:00000001C0001008 ; =============== S U B R O U T I N E ======================================= .text:00000001C0001008 .text:00000001C0001008 .text:00000001C0001008 ; __int64 __fastcall TcpNotifyBacklogChangeSend(PKSPIN_LOCK SpinLock) .text:00000001C0001008 TcpNotifyBacklogChangeSend proc near ; CODE XREF: TcpNotifyTcbDelay+337↓p .text:00000001C0001008 ; DATA XREF: .pdata:ExceptionDir↓o ... ... .data:00000001C0203AB4 dword_1C0203AB4 dd 0FFFFh ; DATA XREF: CTcpQueryTimeStamp+6↑r .data:00000001C0203AB4 ; CTcpQueryTimeStamp+51↑w ... .data:00000001C0203AB8 icmpPingLowWaterMark dd 1F4h ; DATA XREF: IppInspectLocalDatagramsIn+5FED5↑r .data:00000001C0203ABC EQoSpPolicyAppMarkingSetting dd 0FFFFFFFEh .data:00000001C0203ABC ; DATA XREF: EQoSUpdateAppMarkingSetting+A↑r .data:00000001C0203ABC ; EQoSProcessGlobalSettings+35↓r ... .data:00000001C0203AC0 EQoSpPolicyTcpAutoTuningSetting dd 0FFFFFFFFh </code></pre> <p>So the offset should be 202AB4</p> <pre><code>kd&gt; lm m tcpip start end module name fffff803'6b750000 fffff803'6ba6a000 tcpip (pdb symbols) </code></pre> <p>However, the value is not what I want(0xFFFF) and the initial address function in IDA and windbg is not the same</p> <pre><code>kd&gt; u fffff8036b750000 tcpip! WFPDatagramDataShimV4 &lt;PERF&gt; (tcpip+0x0): fffff803`6b750000 4d5a pop r10 </code></pre> <p>What's the correct approach to calculate the address value dword_1C0203AB4?</p>
how to access the initialized data in windbg through offset from IDA
|ida|windbg|
<p>This is not a ghidra answer but done using windbg Assuming You Have Code as below</p> <pre><code>#include &lt;windows.h&gt; #include &lt;stdio.h&gt; #pragma comment(lib, &quot;Advapi32.lib&quot;) void hexdump(byte *inbuf, DWORD count) { DWORD j = 0; while (j &lt; count) { for (DWORD i = j; i &lt; j + 16; i++) { printf(&quot;%02x &quot;, inbuf[i]); } printf(&quot;\n&quot;); j = j + 16; } } int main(void) { HCRYPTPROV hCryptProv = NULL; byte buff[0x200] = {0}; DWORD count = 0x30; BOOL res = CryptAcquireContextA(&amp;hCryptProv, &quot;MyKeyContainer&quot;, NULL, PROV_RSA_FULL, 0); if (res) { res = CryptGenRandom(hCryptProv, count, buff); if (res) { hexdump(buff, count); } } CryptReleaseContext(hCryptProv, 0); } </code></pre> <p>you can employ memory Breakpoint to find who is writing to your buffer and just corelate with your ghidra/ida disassembly.</p> <p>the buffers are Actually Created in Heap and the pointers to them are Written in bcryptprimitives!g_AesStatesTable</p> <pre><code>0:000&gt; lsa . 21: DWORD count = 0x30; 22: BOOL res = CryptAcquireContextA(&amp;hCryptProv, &quot;MyKeyContainer&quot;, NULL, PROV_RSA_FULL, 0); 23: if (res) 24: { &gt; 25: res = CryptGenRandom(hCryptProv, count, buff); &lt;-------------- 26: if (res) 27: { 28: hexdump(buff, count); 29: } 30: } 0:000&gt; ba w1 buff 0:000&gt; g Breakpoint 0 hit ntdll!memcpy+0x144: 00007ffe`988d4044 0f100411 movups xmm0,xmmword ptr [rcx+rdx] ds:0000027d`a4dbc500=25fc4b9c5d3ddad46e5610a21eff9e1f 0:000&gt; k # Child-SP RetAddr Call Site 00 000000d0`1b6ff648 00007ffe`96815400 ntdll!memcpy+0x144 01 000000d0`1b6ff650 00007ffe`9681513c bcryptprimitives!AesRNGState_generate+0x190 02 000000d0`1b6ff700 00007ffe`9586101d bcryptprimitives!ProcessPrng+0x12c 03 000000d0`1b6ff7b0 00007ffe`94f054f7 CRYPTBASE!SystemFunction036+0xd 04 000000d0`1b6ff7e0 00007ffe`958416b2 rsaenh!CPGenRandom+0x27 05 000000d0`1b6ff810 00007ff6`f72a110f CRYPTSP!CryptGenRandom+0x42 06 000000d0`1b6ff840 00007ff6`f72a14d4 crypt!main+0x7f [crypt.cpp @ 25] &lt;----------- 07 (Inline Function) --------`-------- crypt!invoke_main+0x22 08 000000d0`1b6ffaa0 00007ffe`968a7614 crypt!__scrt_common_main_seh+0x10c 09 000000d0`1b6ffae0 00007ffe`988826f1 KERNEL32!BaseThreadInitThunk+0x14 0a 000000d0`1b6ffb10 00000000`00000000 ntdll!RtlUserThreadStart+0x21 0:000&gt; ub . ntdll!memcpy+0x126: 00007ffe`988d4026 0f2959e0 movaps xmmword ptr [rcx-20h],xmm3 00007ffe`988d402a 0f28c4 movaps xmm0,xmm4 00007ffe`988d402d 75d1 jne ntdll!memcpy+0x100 (00007ffe`988d4000) 00007ffe`988d402f 4d8bc8 mov r9,r8 00007ffe`988d4032 49c1e904 shr r9,4 00007ffe`988d4036 7419 je ntdll!memcpy+0x151 (00007ffe`988d4051) 00007ffe`988d4038 0f1f840000000000 nop dword ptr [rax+rax] 00007ffe`988d4040 0f2941f0 movaps xmmword ptr [rcx-10h],xmm0 &lt;------------- this triggered the write breakpoint 0:000&gt; r rcx rcx=000000d01b6ff890 0:000&gt; ? xmm0 Evaluate expression: 5380964661682152702 = 4aad06d9`a87ea4fe &lt;----------- this is being copied from api buffer to codes buff 0:000&gt; db bcryptprimitives!g_AesStatesTable l2 00007ffe`9687b8e0 60 c0 db a4 7d 02 00 00-00 00 00 00 00 00 00 00 `...}........... 0:000&gt; db poi(bcryptprimitives!g_AesStatesTable) l4 0000027d`a4dbc060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 0000027d`a4dbc070 f0 c3 db a4 7d 02 00 00-90 c2 db a4 7d 02 00 00 ....}.......}... 0:000&gt; db poi(poi(bcryptprimitives!g_AesStatesTable)+10) l120 0000027d`a4dbc3f0 30 01 00 00 00 00 00 00-00 00 00 00 00 00 00 00 0............... 0000027d`a4dbc400 dd 1e e5 f2 c9 ec e9 b5-70 2e 3b c6 da e1 f9 59 ........p.;....Y 0000027d`a4dbc410 f7 7d 2c 07 2d 57 ae e0-c8 5c 31 05 08 9a 10 9f .},.-W...\1..... 0000027d`a4dbc420 bc 83 0c 3b 8f 11 ee 03-b0 8a 9a 7e 0e f5 c5 cd ...;.......~.... 0000027d`a4dbc430 da 4f 77 48 92 54 98 57-12 17 ed 2b af 97 1e 88 .OwH.T.W...+.... &lt;------- 0000027d`a4dbc440 03 00 00 00 00 00 00 00-01 00 00 00 00 00 00 00 ................ 0000027d`a4dbc450 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 0000027d`a4dbc460 80 00 00 00 00 00 00 00-39 00 00 00 00 00 00 00 ........9....... 0000027d`a4dbc470 ff ff ff ff ff ff ff ff-fe ff ff ff 01 00 00 00 ................ 0000027d`a4dbc480 c8 2d 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .-.............. 0000027d`a4dbc490 d0 07 00 02 00 00 00 00-00 00 00 00 00 00 00 00 ................ 0000027d`a4dbc4a0 01 20 b5 34 61 da 46 2a-20 ab 63 2a 90 28 cb 36 . .4a.F* .c*.(.6 0000027d`a4dbc4b0 51 4a dc 28 50 b5 a4 97-78 b8 13 33 e3 3c 5a 24 QJ.(P...x..3.&lt;Z$ 0000027d`a4dbc4c0 e4 6c 8d 70 7a 19 5d 5e-71 15 78 95 4b 9b 61 f2 .l.pz.]^q.x.K.a. 0000027d`a4dbc4d0 0f 8e 0d 32 5b 39 1a 53-6b 2a 0e 47 ae e1 2a 47 ...2[9.Sk*.G..*G 0000027d`a4dbc4e0 37 d4 d7 78 01 de 34 d8-f4 27 fe bf fb 2b 07 7a 7..x..4..'...+.z 0000027d`a4dbc4f0 fe a4 7e a8 d9 06 ad 4a-4a 70 8a c3 57 53 54 e9 ..~....JJp..WST. &lt;------- 0000027d`a4dbc500 1f 9e ff 1e a2 10 56 6e-d4 da 3d 5d 9c 4b fc 25 ......Vn..=].K.% &lt;-------- </code></pre> <p>you need to catch this buffer before it is wiped off after memcpy using SymCryptWipeAsm</p> <pre><code>0:000&gt; db buff 000000d0`1b6ff880 fe a4 7e a8 d9 06 ad 4a-4a 70 8a c3 57 53 54 e9 ..~....JJp..WST. 000000d0`1b6ff890 1f 9e ff 1e a2 10 56 6e-d4 da 3d 5d 9c 4b fc 25 ......Vn..=].K.% 000000d0`1b6ff8a0 da 4f 77 48 92 54 98 57-12 17 ed 2b af 97 1e 88 .OwH.T.W...+.... 000000d0`1b6ff8b0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000d0`1b6ff8c0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000d0`1b6ff8d0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000d0`1b6ff8e0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000d0`1b6ff8f0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ </code></pre> <p>the pertinent disassembly / decompilation in ghidra is as follows</p> <pre><code>in bool AesRNGState_generate(byte *param_1,byte *buff,dword dwLen) if (uVar10 &lt; 0x80) { uVar2 = *(ulonglong *)(param_1 + 0x70); puVar1 = (ulonglong *)(param_1 + 0x70); uVar9 = uVar10; if (uVar2 != 0) { if (uVar2 &lt;= uVar10) { uVar9 = uVar2; } memcpy(local_80,param_1 + (uVar2 - uVar9) + 0xb0,uVar9); SymCryptWipeAsm(param_1 + ((*puVar1 + 0xb0) - uVar9),(dword)uVar9); *puVar1 = *puVar1 - uVar9; local_80 = pbVar8 + uVar9; uVar9 = uVar10 - uVar9; } if (uVar9 != 0) { SymCryptRngAesGenerate(param_1 + 0x10,param_1 + 0xb0,0x80); *puVar1 = 0x80; memcpy(local_80,param_1 + (0x130 - uVar9),uVar9); SymCryptWipeAsm(param_1 + ((*puVar1 + 0xb0) - uVar9),(dword)uVar9); *puVar1 = ~(ulonglong)((uint)((uVar10 - 1 ^ uVar10) &gt;&gt; 1) &amp; 0xf) &amp; *puVar1 - uVar9; } } else { SymCryptRngAesGenerate(param_1 + 0x10,buff,dwLen); } </code></pre>
32166
2023-08-12T10:24:57.820
<p>I am trying to analyze the <a href="https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptgenrandom" rel="nofollow noreferrer">CryptGenRandom</a> algorithm on my Windows 10 laptop.</p> <p>According to Niels Ferguson's <a href="https://aka.ms/win10rng" rel="nofollow noreferrer">Whitepaper</a> called 'The Windows 10 random number generation infrastructure', the CryptGenRandom algorithm uses a buffer for small requests:</p> <blockquote> <p>All PRNGs in the system are SP800-90 <code>AES_CTR_DRBG</code> with 256-bit security strength using the <code>df()</code> function for seeding and re-seeding (see SP 800-90 for details). (…) The Basic PRNGs are not used directly, but rather through a wrapping layer that adds several features.</p> <ul> <li>A small buffer of random bytes to improve performance for small requests.</li> <li>A lock to support multi-threading.</li> <li><code>A</code> seed version.</li> </ul> <p>(…) The buffering is straightforward. There is a small buffer (currently 128 bytes). If a request for random bytes is 128 bytes or larger, it is generated directly from <code>AES_CTR_DRGB</code>. If it is smaller than 128 bytes it is taken from the buffer. The buffer is re-filled from the <code>AES_CTR_DRBG</code> whenever it runs empty. So, if the buffer contains 4 bytes and the request is for 8 bytes, the 4 bytes are taken from the buffer, the buffer is refilled with 128 bytes, and the first 4 bytes of the refilled buffer are used to complete the request, leaving 124 bytes in the buffer.</p> </blockquote> <p>I would like to know if it is possible to locate and access this buffer.</p> <p>To achieve this, I located the <code>Advapi32.dll</code> file in my windows/system32 folder. The <code>CryptGenRandom</code> algorithm is defined in this file. I decompiled this file with Ghidra. However, I am very unexperienced with Ghidra and did not manage to find the buffer. Below you can see the entry function with renamed parameters:</p> <pre class="lang-c prettyprint-override"><code> /* WARNING: Function: _guard_dispatch_icall replaced with injection: guard_dispatch_icall */ /* WARNING: Globals starting with '_' overlap smaller symbols at the same address */ ulonglong entry(undefined8 hProv,int dwLen,longlong pbBuffer) { byte bVar1; int iVar2; undefined4 extraout_var; uint *puVar3; undefined1 *puVar4; uint uVar5; uint *puVar6; uint uVar7; if (dwLen == 1) { FUN_18001d464(hProv,1); } uVar7 = 0; if (dwLen == 1) { uVar5 = 0; puVar4 = &amp;DAT_1800a1008; do { iVar2 = RtlInitializeCriticalSection(*(undefined8 *)(puVar4 + -8)); if (iVar2 &lt; 0) { iVar2 = FUN_180015850(); return CONCAT44(extraout_var,iVar2) &amp; 0xffffffffffffff00; } *puVar4 = 1; uVar5 = uVar5 + 1; puVar4 = puVar4 + 0x10; } while (uVar5 &lt; 4); _DAT_1800a44d4 = 1; } uVar5 = 1 &lt;&lt; ((byte)dwLen &amp; 0x1f); puVar6 = &amp;DAT_1800a43c8; bVar1 = 1; puVar3 = &amp;DAT_18006a738; do { if (((*puVar3 &amp; uVar5) != 0) &amp;&amp; ((dwLen != 0 || (((*puVar6 &amp; 2) != 0 &amp;&amp; ((pbBuffer == 0 || ((int)*puVar3 &lt; 0)))))))) { bVar1 = (**(code **)(puVar3 + -2))(hProv,dwLen,pbBuffer); if (bVar1 == 0) goto LAB_18002d198; (&amp;DAT_1800a43c8)[(int)uVar7] = *puVar6 | uVar5; } uVar7 = uVar7 + 1; puVar3 = puVar3 + 4; puVar6 = puVar6 + 1; } while (uVar7 &lt; 8); if (bVar1 == 0) { LAB_18002d198: if (dwLen != 1) goto LAB_18001577c; } else { LAB_18001577c: if ((dwLen != 0) || (pbBuffer != 0)) goto LAB_180015785; } FUN_180015850(); LAB_180015785: return (ulonglong)bVar1; } </code></pre> <p>Since <code>dwLen</code> is the number of requested bytes, I would expect there to be a statement that checks whether this number is at most the number of available random bytes in the buffer. But I see no such statement. Also, <code>pbBuffer</code> is a different buffer than the one I am looking for.</p> <p>I hope that someone can point me in the right direction!</p>
How can I find the buffer of CryptGenRandom?
|ida|disassembly|windows|binary-analysis|ghidra|
<p>When a ELF binary is loaded each one of its sections is loaded to a Virtual Memory Address which is different than its raw offset on disk.</p> <p>Now, objdump shows the contents of the __got's as if it was mapped to it's virtual memory address in 0x3fc0.</p> <p>However, xxd would show the contents of the same address on raw disk (not mapped).</p> <p>You could check what is the Virtual Memory Address (VMA) of the __got by using &quot;objdump --section-headers test&quot;.</p> <p>Also the --start-address and --end-address switches/flags are only used for disassembling, print relocations, and print symbols according to the documentation (if I understood correctly)</p>
32174
2023-08-14T20:57:33.460
<p>I seriously can't tell if I'm misunderstanding something grossly or if this is a bug in objdump. Newbie alert.</p> <pre><code>$ objdump -s --start-address=0x3fc0 --stop-address=0x3fc1 test test: file format elf64-x86-64 Contents of section .got: 3fc0 00 . $ xxd -s 0x3fc0 -l 1 test 00003fc0: 50 P </code></pre> <p>Looking at the file with kaitai I was able to confirm that objdump is the incorrect one. This doesn't happen merely with this byte: a lot of others in the <code>.got</code> are wrong. However, the <code>.text</code> section is completely correct.</p> <p>It also doesn't happen only with these flags: doing <code>objdump -d -s test | less</code> shows the same bytes wrong in the same place.</p> <p>I'm willing to provide the binary: it is a simple <code>printf</code> for me to play with.</p> <p>Edit: Here is the full contents from the <code>.got</code>, obtained with <code>objdump -d -s test | less</code></p> <pre><code>Contents of section .got: 3fb0 c03d0000 00000000 00000000 00000000 .=.............. 3fc0 00000000 00000000 30100000 00000000 ........0....... 3fd0 40100000 00000000 00000000 00000000 @............... 3fe0 00000000 00000000 00000000 00000000 ................ 3ff0 00000000 00000000 00000000 00000000 ................ </code></pre> <p>And here are the bytes at the same offset, as obtained from xxd:</p> <pre><code>xxd -s 0x3fb0 -l 0x50 test 00003fb0: b03f 0000 0000 0000 b02f 0000 0000 0000 .?......./...... 00003fc0: 5000 0000 0000 0000 0000 0000 0000 0000 P............... 00003fd0: 0800 0000 0000 0000 0800 0000 0000 0000 ................ 00003fe0: 0601 0000 0100 0000 0300 0000 0000 0000 ................ 00003ff0: 0040 0000 0000 0000 0030 0000 0000 0000 .@.......0...... </code></pre> <p>Why are the values different?</p>
ELF - Why does objdump provide a wrong byte value in the .got?
|decompilation|c|elf|x86-64|objdump|
<p>I don't know of any tools that can analyze or disassemble CIL bytecode, but what you can do is to <strong>link</strong> those files and produce normal machine code. E.g. something like:</p> <pre><code>LINK 1.obj /force /debug /dll /out:1.dll /noentry </code></pre>
32181
2023-08-16T14:43:35.117
<p><a href="https://learn.microsoft.com/en-us/archive/msdn-magazine/2002/may/under-the-hood-link-time-code-generation" rel="nofollow noreferrer">This</a> Microsoft article states that:</p> <blockquote> <p>When building with LTCG, the compiler front end doesn't invoke the back end. Instead, it emits an OBJ file with IL in it. It bears repeating: this IL is not the same IL that the .NET runtime uses. While .NET IL is standardized and documented, the IL used with LTCG is undocumented and subject to change from version to version of the compiler.</p> </blockquote> <p>... and concludes:</p> <blockquote> <p>OBJ files produced when using LTCG aren't standard COFF format OBJs. Again, this isn't a problem for most people, but if you examine OBJ files with tools like dumpbin, you're simply out of luck—it won't work.</p> </blockquote> <p>Are there - by now - any tools that let me disassemble the code inside these &quot;IL .obj&quot; files and let me access things like symbols, relocation tables, etc.? Even IDA Pro seems to have problems with these kind of files. It identifies them as &quot;COFF (Microsoft CIL bytecode)&quot; and doesn't show any meaningful disasembly...</p>
Tool to analyze .obj files (not COFF) created with /LTCG
|ida|windows|compiler-optimization|object-code|linker|
<p>The buffer is printed from CurrentMdl-&gt;MappedSystemVa+CurrentMdlOffset upto Size-CurrentOffset</p> <p>When there is an MDLChain the data is printed for all Next-&gt;MappedSystemVa</p> <p>And when posting output from windbg do not edit and insert your own address in the first dump the address starts from 0 but it should start from 308+ec == 3f4</p> <p>I could have answered this earlier if i saw 3f4 i was not sure how 00000000 came there so i had to verify before posting</p> <p>The output from !nbl xxxx -data actually outputs the correct address not some 0x00000000</p> <p>a sample output</p> <pre><code>0: kd&gt; .lastevent Last event: Hit breakpoint 0 0: kd&gt; r ndis!NdisSendNetBufferLists: fffff802`373b2460 44894c2420 mov dword ptr [rsp+20h],r9d ss:0018:fffff802`38077048=00000000 0: kd&gt; !nbl @rdx -data NET_BUFFER ffffcb8dc6f83600 MDL ffffcb8dc65f1180 ffffcb8dc65f11e2 33 33 00 00 00 16 00 0c-29 45 de 6c 86 dd 60 00 33······)E·l··`· ffffcb8dc65f11f2 00 00 00 24 00 01 fe 80-00 00 00 00 00 00 db 08 ···$············ ffffcb8dc65f1202 d6 ac 7c b4 bc 33 ff 02-00 00 00 00 00 00 00 00 ··|··3·········· ffffcb8dc65f1212 00 00 00 00 00 16 ······ MDL ffffcb8dc72e9a40 ffffcb8dc65f10ae 3a 00 05 02 00 00 01 00-8f 00 c9 83 00 00 00 01 :··············· ffffcb8dc65f10be 04 00 00 00 ff 02 00 00-00 00 00 00 00 00 00 01 ················ ffffcb8dc65f10ce ff b4 bc 33 ···3 </code></pre> <p>set up a Pseudo Register for ease of use</p> <pre><code>0: kd&gt; r? $t1 = ((ndis!_NET_BUFFER_LIST *)@rdx)-&gt;FirstNetBuffer </code></pre> <p>address of First Buffer</p> <pre><code>0: kd&gt; ? @@c++(@$t1-&gt;CurrentMdl-&gt;MappedSystemVa) + @@c++(@$t1-&gt;CurrentMdlOffset) Evaluate expression: -57665197764126 = ffffcb8d`c65f11e2 </code></pre> <p>address of Second Buffer</p> <pre><code>0: kd&gt; ? @@c++(@$t1-&gt;MdlChain-&gt;Next-&gt;MappedSystemVa) Evaluate expression: -57665197764434 = ffffcb8d`c65f10ae </code></pre>
32196
2023-08-21T18:35:41.820
<p>I'm trying to figure out how the below windbg extension works</p> <pre><code>!ndiskd.nbl addr -hexcap(or -data) </code></pre> <pre><code>kd&gt; !ndiskd.nbl ffffce8c96bde070 -hexcap # NET_BUFFER_LIST ffffce8c96bde070 # NET_BUFFER ffffce8c96bde1f0 # MDL ffffce8c96bde2c8 00000000 30 39 20 b1 97 42 11 bb 00 00 20 b2 60 12 ff 70 00000010 34 b7 00 00 </code></pre> <p>This looks quite fine because it starts with the header. The address is ffffce8c96bde3f4. But I'm unable to find or compute the value with elements in the structures. So I take a deep look at associated structs.</p> <pre><code>NET_BUFFER_LIST +0x000 Next : NULL +0x008 FirstNetBuffer : Oxffffce8c'96bde1f0 +0x000 Link : _SLIST_HEADER +0x000 NetBufferListHeader : _NET_BUFFER_LIST_HEADER +0x010 Context : Oxffffce8c'96bde2a0 _NET_BUFFER_LIST_CONTEXT +0x018 ParentNetBufferList : NULL +0x020 NdisPoolHandle : ... +0x030 NdisReserved : ... +0x040 ProtocolReserved : ... +0x060 MiniportReserved : ... +0x070 Scratch : ... +0x078 SourceHandle : ... +0x080 NblFlags : ... +0x084 ChildRefCount : ... +0x088 Flags : ... +0x08c Status : ... +0x08c NdisReserved2 : ... +0x090 NetBufferListInfo : ... </code></pre> <p>FirstNetBuffer. The MDL is where system store data</p> <pre><code>NET_BUFFER +0x000 Next : NULL +0x008 CurrentMdl : ffffce8c96bde2c8 +0x010 CurrentMdlOffset : 0xec +0x018 DataLength : 0x14 +0x018 stDataLength : 0x14 //The length, in bytes, of the used data space in the MDL chain +0x020 MdlChain : ffffce8c96bde2c8 +0x028 DataOffset : 0xec +0x000 Link : _SLIST_HEADER +0x000 NetBufferHeader : _NET_BUFFER_HEADER +0x030 ChecksumBias : ... +0x032 Reserved : ... +0x038 NdisPoolHandle : ... +0x040 NdisReserved : ... +0x050 ProtocolReserved : ... +0x080 MiniportReserved : ... +0x0a0 DataPhysicalAddress : ... +0x0a8 SharedMemoryInfo : ... +0x0a8 ScatterGatherList : ... </code></pre> <p>CurrentMdl</p> <pre><code>MDL +0x000 Next : NULL +0x008 Size : 0n56 +0x00a MdlFlags : 0n4 +0x00c AllocationProcessorNumber : ... +0x00e Reserved : ... +0x010 Process : Ptr64 _EPROCESS +0x018 MappedSystemVa : Oxffffce8c'96bde308 +0x020 StartVa : Oxffffce8c'96bde000 +0x028 ByteCount : 0x100 +0x02c ByteOffset : 0x308 </code></pre> <p>OK. Now from MDL I know that system allocates 0x100 bytes for the data. And the first around 0x70 are 0s which is normal. Like I said the data starts with ffffce8c96bde3f4, if I use the Mdloffset(ec) and currentMdl(ffffce8c96bde2c8), I get ffffce8c96bde3b4. The difference is 0x40. But with all the values, I don't know where the 0x40 comes from. What might be the problem?</p>
unable to figure out how a windbg extension work
|windows|windbg|
<p>well if you really need to trace each execution just looking for a value in some register and willing to spend the time you can run a script recursively on each instruction</p> <p>it is very time consuming and is equivalent to setting the trap flag on each instruction</p> <p>here is how you do it using the same example code in an earlier answer</p> <pre><code>int main (void) { unsigned long a = 0; unsigned char b =1; while (a &lt; 0xffffffff) { a=a+b; } return a; } </code></pre> <p>write a script file loopy.wds with contents like this</p> <pre><code>.if (@eax == 0x1001) {} .else {t &quot;$&lt;d:\\loopy.wds&quot;} </code></pre> <p>when reached the main function i save the current time</p> <pre><code>0:000&gt; r $t1 = @$dbgtime 0:000&gt; ? @$t1 Evaluate expression: 133374252215057636 = 01d9d72c`fd763ce4 </code></pre> <p>and start single stepping using</p> <pre><code>0:000&gt; t &quot;$&lt;d:\\loopy.wds&quot; </code></pre> <p>it will keep on tracing every instruction until the register eax holds 0x1001</p> <pre><code>0:000&gt; .if (@eax == 0x1001) {} .else {t &quot;$&lt;d:\\loopy.wds&quot;} 0:000&gt; .if (@eax == 0x1001) {} .else {t &quot;$&lt;d:\\loopy.wds&quot;} 0:000&gt; .if (@eax == 0x1001) {} .else {t &quot;$&lt;d:\\loopy.wds&quot;} 0:000&gt; .if (@eax == 0x1001) {} .else {t &quot;$&lt;d:\\loopy.wds&quot;} 0:000&gt; .if (@eax == 0x1001) {} .else {t &quot;$&lt;d:\\loopy.wds&quot;} 0:000&gt; .if (@eax == 0x1001) {} .else {t &quot;$&lt;d:\\loopy.wds&quot;} 0:000&gt; .if (@eax == 0x1001) {} .else {t &quot;$&lt;d:\\loopy.wds&quot;} </code></pre> <p>it will stop only when eax = 0x1001</p> <pre><code>0:000&gt; .if (@eax == 0x1001) {} .else {t &quot;$&lt;d:\\loopy.wds&quot;} loopy!main+0x27: 00000001`40001027 ebe7 jmp loopy!main+0x10 (00000001`40001010) 0:000&gt; ? @$t1 Evaluate expression: 133374252215057636 = 01d9d72c`fd763ce4 0:000&gt; ? @$dbgtime Evaluate expression: 133374255572685217 = 01d9d72d`c59791a1 0:000&gt; ? @$dbgtime - @$t1 Evaluate expression: 3563614608 = 00000000`d4687190 0:000&gt; r rax rax=0000000000001001 0:000&gt; dv b = 0x01 '' a = 0x1001 0:000&gt; .load kdexts 0:000&gt; 0: kd&gt; !filetime 01d9d72c`fd763ce4 0:000&gt; 8/25/2023 13:50:21.505 (unknown) 0:000&gt; 0: kd&gt; !filetime 01d9d72d`c59791a1 0:000&gt; 8/25/2023 13:55:57.268 (unknown) 0:000&gt; 0: kd&gt; !filetime 00000000`d4687190 0:000&gt; 1/ 1/1601 05:35:56.361 (unknown) &lt;&lt;&lt;&lt; it took about 5 minutes to trace until eax became 0x10001 from 0x0 </code></pre>
32200
2023-08-23T17:31:41.427
<p>I'm using windbg to find the memory of a specific structure in windows. The way is to look at certain values stored in stack and registers in entry function. I notice that register ax holds that value when the program executes one instruction(So I have the address of that instruction). I assume that the value of ax is passed from the address of that structure and my job is to find the address of that instruction. The problem is that the assembly in IDA is very different from the assembly(use u command) in windbg. Thus, I'm unable to target the location from pseudocode in IDA and comparison between assembly in windbg and IDA.</p> <pre><code>assembly 0000 function start(set break point) ... ... some instructions without bp 010f instruction A(where ax already holds the value. set break point) </code></pre> <p>One very straight approach is to stop the machine when ax has the value I want. But there is no straight approach in windbg. Maybe like Thomas <a href="https://stackoverflow.com/questions/73927117/windbg-breakpoint-on-a-register-value">said</a> there are other ways. So I try to use j and t command in windbg.</p> <pre><code>j(@ax=x) 'p';'r;r ax;r rip' </code></pre> <p>With above command with bp, I can set conditional break point in certain address. But this infeasible since there are too many instructions and windbg has bp limits.</p> <p>In <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-a-conditional-breakpoint" rel="nofollow noreferrer">documentation</a> ,t command can execute many instructions and display values of registers. Since ax is not displayed in r command, I can track rax instead. How should I write my command in this form?</p> <pre><code>t [r] [= StartAddress] [Count] [&quot;Command&quot;] </code></pre> <p>The StartAddress should be the entry function. But what about the count? I don't want to view thousands of output but it may not reach to instruction A if count is not big enough. How to solve this problem? Can I just use a big enough value and set bp at instruction A?</p> <p>Update: I managed to print all the instructions that have been executed since the entry function with ta command. But still too many instructions for me. I can only save the output to some files and find the location by string operation with C.</p>
how to stop windbg when register value changes
|windows|windbg|
<p>Turns out that Cutter actually provides RTTI information, but not under the &quot;Symbols&quot; window but under another &quot;Classes&quot; window that is hidden by default.</p> <p>You can open it from <em>Windows &gt; Info &gt; Classes</em>.</p>
32201
2023-08-24T08:09:29.683
<p>I am reversing a 32 bit library used by a Linux game (I am sure someone might recognize the engine used). I was messing around with <a href="https://github.com/rizinorg/cutter" rel="nofollow noreferrer">cutter</a> and when trying to compare it to IDA, which I have used in the past for this library, I noticed that I couldn't search for C++ classes the same way I do with IDA's Ctrl+L.</p> <p>IDA's output:</p> <p><a href="https://i.stack.imgur.com/jpVqm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jpVqm.png" alt="IDA Output" /></a></p> <p>If I search in Cutter's &quot;Symbols&quot; tab:</p> <p><a href="https://i.stack.imgur.com/0feoM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0feoM.png" alt="Cutter symbols" /></a></p> <p>There is also a &quot;VTable&quot; tab, which also looked interesting since it's basically what I am looking for, but although it shows about 1k VTables, none of them have any kind of name:</p> <p><a href="https://i.stack.imgur.com/PeEhm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PeEhm.png" alt="Cutter VTable" /></a></p>
How does IDA know the symbol names for classes and interfaces?
|ida|c++|symbols|vtables|cutter|
<p>In the short term, you'll likely need to understand and debug both x86 and ARM assembly, even if you don't write in them. Here's why:</p> <ul> <li>Analyzing malware demands the skill to read and track its behavior.</li> <li>A significant portion of malware targets Windows and Linux on x86 systems, which underscores the importance of x86 assembly knowledge.</li> <li>Based on data from <a href="https://portal.av-atlas.org/malware" rel="nofollow noreferrer">av-atlas</a> and other sources, the next major targets are Android and MacOS, emphasizing the need for ARM assembly knowledge.</li> <li>The importance of ARM assembly in this area is growing as the number of devices with ARM processors increases, presenting more potential targets for malware.</li> </ul> <p>By learning x86 assembly, you address most of your assembly language related malware analysis requirements, with ARM assembly serving as a beneficial, and at times necessary, addition.</p>
32207
2023-08-24T15:52:56.333
<p>I know we have some architectures for assembly language. But I wanna know this: I need learn x86 assembly ? , or arm assembly ? , or both ? , or others ?..</p> <p>Please help me , what should I learn?</p>
Assembly for malware analysis
|assembly|
<p>This answer is based on <a href="https://codegolf.stackexchange.com/questions/177803/parse-the-bookworm-dictionary-format">this post on codegolf</a></p> <p>It mentions</p> <p>The rules for unpacking the dictionary are simple:</p> <ol> <li><p>Read the number at the start of the line, and copy that many characters from the beginning of the previous word. (If there is no number, copy as many characters as you did last time.)</p> </li> <li><p>Append the following letters to the word.</p> </li> </ol> <p>It also mentions the word list with this output</p> <pre><code>aa aah aahed aahing aahs aal aaliis aals aardvark aardvarks aardwolf aardwolves </code></pre>
32224
2023-08-27T12:05:33.690
<p>I am looking at the &quot;wordlist.txt&quot; file for Bookworm Deluxe (an old game by PopCap), and I have not been able to make sense of it. Most of the lines seem to be pieces of words, often with a single digit prefixing them. These numbers do not constantly represent a same letter combination, as 2rdvark would seem like 2 is &quot;aa&quot;, but 2s is also in the list, and &quot;aas&quot; is not a word. Take note that the game has to have letter rarity information somewhere, but bonus <em>words</em> have their own separate file. <a href="https://gist.github.com/thelabcat/0c47e9b4eec3630da081d19451ede6ae" rel="nofollow noreferrer">Here is the file as a Gist.</a></p>
Bookworm Deluxe wordlist not understood. Any insights?
|game|
<p>You could make use of <a href="https://hex-rays.com/products/ida/tech/flirt/" rel="nofollow noreferrer">FLIRT</a> signatures.</p> <p>There's a <a href="https://github.com/NWMonster/ApplySig" rel="nofollow noreferrer">Python script</a> porting IDA FLIRT for Ghidra. You can use existing signature sets, for instance <a href="https://github.com/Maktm/FLIRTDB" rel="nofollow noreferrer">github.com/Maktm/FLIRTDB</a> (or make and apply your own signatures if needed).</p> <p>If you need a tutorial on Ghidra setup <a href="https://www.youtube.com/watch?v=CgGha_zLqlo" rel="nofollow noreferrer">here</a>'s a decent one.</p>
32226
2023-08-27T22:25:55.767
<p>I am attempting to reverse-engineer an old DOS executable, which seems to have been compiled around 1992 using Microsoft's C compiler at the time.</p> <p>When opening the executable in Ghidra no imports are listed, so I assume that any library functions that were utilised have been statically linked. Certain strings exist such as <code>%s%s</code>, so I can assume that <code>printf</code> has been utilised, for example.</p> <p>However, when looking through the code, nothing stands out as obviously being library code. Is there a way to identify library functions just from looking at the assembly/decompiled output?</p> <p>Thanks, James</p>
Identifying C/C++ Library Functions
|c++|ghidra|c|dos|dos-exe|
<pre><code> 14098c632 48 89 44 24 28 MOV qword ptr [RSP + local_40],RAX=&gt;KiSchedulerApc </code></pre> <p>for a line like above you want the operand Representation?</p> <p>you mean something like this</p> <pre><code>&gt;&gt;&gt; currentLocation OperandFieldLocation@14098c632, refAddr=1402fa5b0, row=0, col=1, charOffset=12, OpRep = RAX=&gt;KiSchedulerApc, subOpIndex = 0, VariableOffset = null &gt;&gt;&gt; currentLocation.getOperandRepresentation() u'RAX=&gt;KiSchedulerApc' </code></pre>
32229
2023-08-28T15:00:36.880
<p>I tried several hours to find a way to get the operand address which is displayed in the ghidra listing, but without success:</p> <p><a href="https://i.stack.imgur.com/LKSuu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LKSuu.png" alt="indirect operand address" /></a></p> <p>I know at least that the OperandType is &quot;Address&quot;.</p> <pre><code>import ghidra.program.model.lang.OperandType; int ot1 = ins1.getOperandType(1); boolean indirect1 = OperandType.isAddress(ot1); // --&gt; result is true </code></pre> <p>The <code>op_rep = ins1.getDefaultOperandRepresentation(1)</code> is of course <code>[a0]-0x38d8</code> but I want the resolved reference / address DAT_d0006b78, or with the next instruction, the address of the symbol in the first operand, the address of ACCI_trqDes.</p> <p>If I use <code>currentProgram.getAddressFactory().getAddress(op_rep)</code> the resulting address is null.</p> <p>I tried it also via <code>PcodeOp[] pc = ins1.getPcode(opIndex);</code> but I was much too stupid to understand it.</p> <p>How can I get this? Thanks a lot!</p>
Ghidra scripting: get indirect operand address
|ghidra|script|
<pre><code>import ida_funcs import ida_auto funcEa = 0x08054FE1 newEndEa = 0x08054FF7 f = ida_funcs.get_func(funcEa) f.end_ea = newEndEa ida_funcs.update_func(f) ida_funcs.reanalyze_function(f) ida_auto.auto_wait() </code></pre> <p>In response to your edit, perhaps some basic safety precautions would help, as in:</p> <pre><code>f = ida_funcs.get_func(funcEa) if f is not None: nChunk = ida_funcs.func_contains(f,newEndEa) if nChunk &gt;= 0: if nChunk &gt; 0: f = ida_funcs.getn_fchunk(nChunk) f.end_ea = newEndEa ida_funcs.update_func(f) ida_funcs.reanalyze_function(f) ida_auto.auto_wait() </code></pre>
32241
2023-08-31T00:10:12.817
<p>I’m trying to set a function chunk end at a certain EA in a function using my Ida python plugin, but I can’t find any API which lets me do just that. set_func_end appear not to work (keeps returning false.). Basically I’m trying to simulate the action of pressing “E” at a certain EA. Appreciate any help, thanks in advance!</p>
IDA python API set function chunk end
|ida|idapython|
<p>I found this IR protocol documented in <a href="https://github.com/crankyoldgit/IRremoteESP8266#readme" rel="nofollow noreferrer">IRremoteESP8266</a> in the source code files <a href="https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.h" rel="nofollow noreferrer">ir_Midea.h</a> and <a href="https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.cpp" rel="nofollow noreferrer">ir_Midea.cpp</a>. The parts of the code I focused on were the <a href="https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.h#L74" rel="nofollow noreferrer">struct definition</a> and the <a href="https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.cpp#L499" rel="nofollow noreferrer">calcChecksum function</a>.</p> <p>In the struct definition, the bytes are ordered with the checksum first, so the bytes in the struct are in the reverse order compared to the bytes in your list. However within each byte, the bits appear to be ordered in the same way as your list. (The struct uses C bit fields. The colon numbers indicate how many bits each value uses. It appears this code expects the compiler to build the bit fields starting from the least significant bit of each byte. And it appears the <code>:0</code> happens to skip over the remaining bits of the byte it appears in.)</p> <p>The checksum method used in the code is the following:</p> <ul> <li>Reverse the bit order of each byte.</li> <li>Flip the bits of each byte.</li> <li>Sum all the bytes including the checksum byte.</li> <li>The sum should be 0, modulo 256 decimal.</li> </ul> <p>When I use this checksum method with your data, every row of your data gives the same sum of decimal 250 (or hex FA or binary 11111010) instead of 0.</p> <p>Instead, if I remove the step that flips all the bits, then the resulting method works with your data:</p> <ul> <li>Reverse the bit order of each byte.</li> <li>Sum all the bytes including the checksum byte.</li> <li>The sum should be 0, modulo 256 decimal.</li> </ul>
32254
2023-09-03T23:10:15.523
<p>For fun I've decided to reverse engineer the Mr Cool IR Remote, and build my own version of it.</p> <p>I've been able to capture the IR sequence for a lot of different button presses. It appears to use a coding scheme similar to the NEC standard, the main difference being it appears to be Msb first. I think it is Msb first because the byte that I think represents the temperature changes logically if I assume Msb first, if I assume Lsb first then it is not as logical. Below is a table of values I've captured along with the associated button press. What I can't make heads or tails of is how the last byte, which I assume is a checksum, is calculated. I've tried various combinations of sums and XOR and haven't gotten it. Any help/tips or tricks for figuring out the algorithm to calculate the last byte would be greatly appreciated. Note, I tried to ask ChatGPT and Bard AI to help and they were laughably bad, so hopefully us normal humans can figure this out!</p> <p><a href="https://i.stack.imgur.com/to12K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/to12K.png" alt="Button Presses and associated values" /></a></p>
Mr Cool Remote Control Checksum Algorithm
|checksum|
<p>xxteakey for decrypt lua: <code>aaa</code></p> <p><code>xxtea_decrypt</code> function jump to <code>cocos2dx_lua_loader+F6</code> <a href="https://i.stack.imgur.com/Mc7zx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mc7zx.png" alt="1" /></a></p> <p>Press F5 (decompile to pseudocode)</p> <p><code>void * xxtea_decrypt(const void * data, size_t len, const void * key, size_t * out_len)</code></p> <p><code>v22</code> is a <code>key</code> load from <code>off_5E4660</code> <a href="https://i.stack.imgur.com/lh2EF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lh2EF.png" alt="2" /></a></p> <p>Goto address <code>5E4660</code> <a href="https://i.stack.imgur.com/ymUDO.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ymUDO.gif" alt="3" /></a></p> <p><code>key</code> is: <code>aaa</code>, full key size 16 from hex: <code>61 61 61 00 00 00 00 00 00 00 00 00 00 00 00 00</code></p>
32262
2023-09-05T12:09:24.923
<p>I was trying to recreate <a href="https://drive.google.com/file/d/12EeyaIOId2QRDhMST_akH-34M-APW4a9/view?usp=sharing" rel="nofollow noreferrer">this game</a> because it was down but I really love it.</p> <p>I tried to decompile the apk and I got the java code and the assets then I looked around the code and found out the main code is not in the java but the lua folder inside the assets but the thing is that it get encrypted by XXTEA (For Example: this is <a href="https://drive.google.com/file/d/1k9RmP0n2sdNLZtPJay8c7uF10q-KQyKD/view?usp=sharing" rel="nofollow noreferrer">main.lua</a>).</p> <p>So I'm trying to use IDA to read the <a href="https://drive.google.com/file/d/15d3zvZLBYuWLUcu6wjwZ1p8LneikHW0J/view?usp=sharing" rel="nofollow noreferrer">lib .so file</a> to find the key but it's a bunch of stuff that doesn't let me get the key easy so I tried to use frida to trace and print out the key when the decrypt get called but sadly because the server was down so the function never get called.</p> <p>Please help me decrypt all the lua file or at least pls help me get the key to decrypt it, I really need it.</p>
Need help decrypt xxtea encrypted Lua file from cocos2D game
|decryption|apk|lua|
<p>the best you can get: <a href="https://github.com/yuv422/skifree_decomp" rel="nofollow noreferrer">https://github.com/yuv422/skifree_decomp</a></p> <blockquote> <p>A source code reconstruction of the 32bit version of Skifree (v1.04) back to C, compilable with Visual Studio 6.</p> </blockquote> <p>so someone already did the very time consuming manual translation from disassembly to C for you</p> <p>you can load the Visual Studio 6 dsw project file (from 1998) in VS2017 or VS2019 - or create a new solution</p>
32265
2023-09-07T06:42:40.587
<p>I am a person interested of old games (MS DOS and 16 bit Windows only) and programming. In 2020, I saw an article about hacking SkiFree somewhere on the internet and soon as I followed the instructions, it was so easy that I made many games with changed graphics and added sound effects (the later 32 bit executable has a hidden ability to do so). Later I tried to go to different lengths after being impressed with my previous stuff mentioned above. Like adding new objects (referred as things in the code). I have explored the original executable using a hex editor and found this:</p> <pre><code>ski2.c </code></pre> <p>I have heard of old Windows applications being leaked by hackers, causing mass controversy and a big problem for Microsoft. They say they extracted the c files and headers from the executable file. Sometimes without a decompiler. I have been working on a SkiFree project for nearly 3 years only for my own enjoyment and I want to know which software do they use to do this. Can anyone help me?</p> <p>Thanks! Picaboo3</p>
How can I extract *.c file hidden in an executable file (SkiFree)
|pe|executable|game-hacking|exe|ne|
<p>It's obviously doable (you already noted the <code>Create C header file</code> functionality), but if you want to customize the output, you'll have to code it yourself.</p> <p>Here's what you'll need:</p> <ul> <li><code>ida_typeinf.first_named_type</code> and <code>ida_typeinf.next_named_type</code> to iterate through all of the type names in a TIL (i.e., the main TIL for an IDB).</li> <li>To retrieve a <code>tinfo_t</code> type object from a type name, create <code>tif = ida_typeinf.tinfo_t()</code>, then do <code>tif.get_named_type(name)</code> with the name returned from the functions above.</li> <li>Once you have the <code>tinfo_t tif</code> object, if <code>tif.is_struct()</code> returns <code>True</code>, you can get the structure details via the function <code>tif.get_udt_details</code> by passing it a new <code>ida_typeinf.udt_type_data_t</code> data structure.</li> <li><code>ida_typeinf.udt_type_data_t</code> is a vector of <code>udt_member_t</code> objects (plus additional information, e.g. size and alignment). Each <code>udt_member_t</code> object describes one field in a <code>struct</code> or <code>union</code>. You can retrieve member names via the <code>.name</code> field, and each field's <code>tinfo_t</code> type via the <code>.type</code> field.</li> </ul> <p>That's all you need. However, if you've never worked with types programmatically before, you're going to find it tricky. It is already evident from the above that <code>tinfo_t</code> is a mutually recursive data structure, i.e., the <code>tinfo_t</code> for a structure contains other data structures (like <code>udt_type_data_t</code>) that themselves contain <code>tinfo_t</code> objects to describe structure field types. Due to the mutual recursion in the data structures, functions involving <code>tinfo_t</code> objects are often mutually recursive.</p>
32271
2023-09-08T06:06:02.693
<p>I want to retrieve IDA Pro .idb database's each type info, such as:</p> <ul> <li><em>size and name of a structure;</em></li> <li><em>each member variable type and name;</em></li> <li><em>each member variable size and offset;</em></li> </ul> <p>And dump it to a .h file in a formatted manner. (&quot;Create C header file...&quot; just dumps without sizes and offsets and does not allow to pre-format it.) How to do this?</p>
Retrieve & dump type information from IDA Pro
|ida|c++|idapython|dumping|script|
<p>@feldspar's <a href="https://reverseengineering.stackexchange.com/a/32338/23491">reply</a> is 100% accurate. It was a change introduced by the Cutter team as of February 2023.</p> <p>I just wanted to add that the important thing here is to understand how the addressing works, regardless of whether it is relative to the bottom of the stack or the <code>rbp</code>. They are equivalent.</p> <p>When you have an address like <code>stack - 0x28</code> it means the variable &quot;lives&quot; in the stack at address -0x28 from the very beginning of the stack. Where does the stack begin? At <code>rbp+0x8</code> (a.k.a the saved return address).If you think about it, it is equivalent to <code>rpb-0x20</code> because the <code>rpb</code> register is 8 bytes long.</p> <p>If we draw the stack something like this:</p> <pre><code>stack+0x8 or rbp+0x10 | ... | Higher Addresses stack or rbp+0x8 |saved @ret| stack-0x8 or rbp |(old) rbp | stack-0x10 or rbp-0x8 | ... | stack-0x18 or rbp-0x10 | ... | stack-0x20 or rbp-0x18 | ... | Lower Addresses and so on.... </code></pre> <p>it may be easier to understand why they are equivalent. Let us take as example the <code>saved return address</code> and the <code>saved rbp</code>:</p> <ul> <li>The saved return address is located from cell <code>stack</code> to <code>stack+0x7</code> (8 bytes) or <code>rbp+0x8</code> to <code>rbp+0xf</code>.</li> <li>Likewise, the saved rbp is located from <code>rbp</code> to <code>rbp+0x7</code> (or <code>stack-0x8</code> to <code>stack-0x1</code>).</li> </ul> <p>Hope this helps clarifying concepts.</p> <p>EDIT 2024.03.27: I've uploaded a video about this topic and Cutter's configuration and customization: <a href="https://www.youtube.com/watch?v=zrXA3AC_658" rel="nofollow noreferrer">https://www.youtube.com/watch?v=zrXA3AC_658</a>.</p>
32317
2023-09-25T05:36:31.707
<p>Look at the first image: <a href="https://i.stack.imgur.com/djnmc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/djnmc.png" alt="enter image description here" /></a></p> <p>Here what I get is <code>var void *buf @ stack - 0x28</code>. But I'm watching a tutorial there his Cutter shows like this: <code>var void *buf @ rbp - 0x20</code>. How can I change cutter to appear like this?</p> <p><a href="https://i.stack.imgur.com/3zREB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3zREB.jpg" alt="enter image description here" /></a></p> <p>I became so confused with it. Had to spent some time to discover the discrepancy.</p>
Cutter shows addresses relative to stack but not rbp. How to change it?
|disassembly|functions|stack|cutter|
<p>Starting <code>A5A5</code> and trailing <code>FFFF</code> should be excluded.<br /> The checksum is just a 16-bit sum of 8-bit bytes.</p> <pre class="lang-none prettyprint-override"><code>A5A5 0018 501A 4D4C 00CC 120D 0008 0003 0002 1201 120D 0245 FFFF FFFF FFFF FFFF ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \----------------bytes to sum up---------------/ sum 0x00 + 0x18 + ... + 0x12 + 0x0D = 0x0245 </code></pre>
32345
2023-10-03T02:04:26.173
<p>I am reverse engineering the communication protocol used by Makita XGT (40V) batteries. I have successfully captured a number of messages and have some hints at their basic structure, but they appear to have a checksum of some description at the end of each message, and I'm not really sure how to go about figuring out the algorithm.</p> <p>The code that calculates them only exists on microcontroller ICs and at this point I do not think the firmware can be dumped, however the algorithm seems like it might be simple (because adding 1 to one of the bytes also adds 1 to the checksum) so I'm hoping someone might be able to spot a pattern and shed some light on how they are calculated.</p> <p>Here are some sample messages. They appear to be 16-bit big endian words, however they are sent as 8-bit bytes so it is possible the checksum works at the 8-bit level, however everything else seems to be 16-bit so I'd probably start there. (The bytes come in over the wire as <code>A5 A5 00 18</code> which I have written below as <code>A5A5 0018</code>.)</p> <p>Every message starts with <code>A5A5</code> so I am not sure whether this is part of the checksum or not - it may be excluded. Messages are padded to the nearest 16-byte (8-word) boundary with <code>FFFF</code> words, and as these come after the checksum word, I presume they are not included in the checksum calculation.</p> <p>Here is the basic structure of the messages, with apologies for my ASCII art:</p> <pre><code>|||| Message header/signature/sync (always A5A5) |||| |||| | Message length (bit flags) |||| | |||| | ||| Message ID (010) |||| | ||| |||| Requesting two parameters (1201 and 120D) |||| | ||| |||| |||| | ||| |||| |||| Checksum to be examined |||| | ||| |||| |||| (ignore FFFF padding) A5A5 0018 5010 4D4C 00CC 120D 0008 0003 0002 1201 120D 023B FFFF FFFF FFFF FFFF | | | | 5 = message from charger to battery | | 9 = reply from battery to charger | | Number of padding bytes (8 bytes = 4 FFFF words) </code></pre> <p>Here is some sample data, one message per line:</p> <pre><code>// Message IDs starting at 01A A5A5 0018 501A 4D4C 00CC 120D 0008 0003 0002 1201 120D 0245 FFFF FFFF FFFF FFFF A5A5 0018 501B 4D4C 00CC 120D 0008 0003 0002 1201 120D 0246 FFFF FFFF FFFF FFFF A5A5 0018 501C 4D4C 00CC 120D 0008 0003 0002 1201 120D 0247 FFFF FFFF FFFF FFFF A5A5 0018 501D 4D4C 00CC 120D 0008 0003 0002 1201 120D 0248 FFFF FFFF FFFF FFFF A5A5 0018 501E 4D4C 00CC 120D 0008 0003 0002 1201 120D 0249 FFFF FFFF FFFF FFFF A5A5 0018 501F 4D4C 00CC 120D 0008 0003 0002 1201 120D 024A FFFF FFFF FFFF FFFF A5A5 0018 5020 4D4C 00CC 120D 0008 0003 0002 1201 120D 024B FFFF FFFF FFFF FFFF A5A5 0018 5021 4D4C 00CC 120D 0008 0003 0002 1201 120D 024C FFFF FFFF FFFF FFFF A5A5 0018 5022 4D4C 00CC 120D 0008 0003 0002 1201 120D 024D FFFF FFFF FFFF FFFF A5A5 0018 5023 4D4C 00CC 120D 0008 0003 0002 1201 120D 024E FFFF FFFF FFFF FFFF A5A5 0018 5024 4D4C 00CC 120D 0008 0003 0002 1201 120D 024F FFFF FFFF FFFF FFFF A5A5 0018 5025 4D4C 00CC 120D 0008 0003 0002 1201 120D 0250 FFFF FFFF FFFF FFFF A5A5 0018 5026 4D4C 00CC 120D 0008 0003 0002 1201 120D 0251 FFFF FFFF FFFF FFFF A5A5 0018 5027 4D4C 00CC 120D 0008 0003 0002 1201 120D 0252 FFFF FFFF FFFF FFFF A5A5 0018 5028 4D4C 00CC 120D 0008 0003 0002 1201 120D 0253 FFFF FFFF FFFF FFFF A5A5 0018 5029 4D4C 00CC 120D 0008 0003 0002 1201 120D 0254 FFFF FFFF FFFF FFFF A5A5 0018 502A 4D4C 00CC 120D 0008 0003 0002 1201 120D 0255 FFFF FFFF FFFF FFFF // Chunk 2: same message IDs as above, but different message length A5A5 001C 501A 4D4C 00CC 120C 0004 2101 0100 0230 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 501B 4D4C 00CC 120C 0004 2101 0100 0231 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 501C 4D4C 00CC 120C 0004 2101 0100 0232 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 501D 4D4C 00CC 120C 0004 2101 0100 0233 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 501E 4D4C 00CC 120C 0004 2101 0100 0234 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 501F 4D4C 00CC 120C 0004 2101 0100 0235 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5020 4D4C 00CC 120C 0004 2101 0100 0236 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5021 4D4C 00CC 120C 0004 2101 0100 0237 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5022 4D4C 00CC 120C 0004 2101 0100 0238 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5023 4D4C 00CC 120C 0004 2101 0100 0239 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5024 4D4C 00CC 120C 0004 2101 0100 023A FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5025 4D4C 00CC 120C 0004 2101 0100 023B FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5026 4D4C 00CC 120C 0004 2101 0100 023C FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5027 4D4C 00CC 120C 0004 2101 0100 023D FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5028 4D4C 00CC 120C 0004 2101 0100 023E FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5029 4D4C 00CC 120C 0004 2101 0100 023F FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 502A 4D4C 00CC 120C 0004 2101 0100 0240 FFFF FFFF FFFF FFFF FFFF FFFF // Checksum carries (2FF -&gt; 300) A5A5 001C 50E6 4D4C 00CC 120C 0004 2101 0100 02FC FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50E7 4D4C 00CC 120C 0004 2101 0100 02FD FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50E8 4D4C 00CC 120C 0004 2101 0100 02FE FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50E9 4D4C 00CC 120C 0004 2101 0100 02FF FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50EA 4D4C 00CC 120C 0004 2101 0100 0300 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50EB 4D4C 00CC 120C 0004 2101 0100 0301 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50EC 4D4C 00CC 120C 0004 2101 0100 0302 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50ED 4D4C 00CC 120C 0004 2101 0100 0303 FFFF FFFF FFFF FFFF FFFF FFFF // Checksum jumps when message ID carries (0FF -&gt; 100) A5A5 001C 50FC 4D4C 00CC 120C 0004 2101 0100 0312 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50FD 4D4C 00CC 120C 0004 2101 0100 0313 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50FE 4D4C 00CC 120C 0004 2101 0100 0314 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 50FF 4D4C 00CC 120C 0004 2101 0100 0315 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5100 4D4C 00CC 120C 0004 2101 0100 0217 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5101 4D4C 00CC 120C 0004 2101 0100 0218 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5102 4D4C 00CC 120C 0004 2101 0100 0219 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5103 4D4C 00CC 120C 0004 2101 0100 021A FFFF FFFF FFFF FFFF FFFF FFFF // As per Chunk 2 above, but message IDs are now +100, checksums are +1 in comparison A5A5 001C 511A 4D4C 00CC 120C 0004 2101 0100 0231 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 511B 4D4C 00CC 120C 0004 2101 0100 0232 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 511C 4D4C 00CC 120C 0004 2101 0100 0233 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 511D 4D4C 00CC 120C 0004 2101 0100 0234 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 511E 4D4C 00CC 120C 0004 2101 0100 0235 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 511F 4D4C 00CC 120C 0004 2101 0100 0236 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5120 4D4C 00CC 120C 0004 2101 0100 0237 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5121 4D4C 00CC 120C 0004 2101 0100 0238 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5122 4D4C 00CC 120C 0004 2101 0100 0239 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5123 4D4C 00CC 120C 0004 2101 0100 023A FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5124 4D4C 00CC 120C 0004 2101 0100 023B FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5125 4D4C 00CC 120C 0004 2101 0100 023C FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5126 4D4C 00CC 120C 0004 2101 0100 023D FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5127 4D4C 00CC 120C 0004 2101 0100 023E FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5128 4D4C 00CC 120C 0004 2101 0100 023F FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 5129 4D4C 00CC 120C 0004 2101 0100 0240 FFFF FFFF FFFF FFFF FFFF FFFF A5A5 001C 512A 4D4C 00CC 120C 0004 2101 0100 0241 FFFF FFFF FFFF FFFF FFFF FFFF // Random assortment of other messages A5A5 0018 5007 4D4C 00CC 1204 0008 2101 0008 2109 0000 0246 FFFF FFFF FFFF FFFF A5A5 0000 9007 4D4C 00CC B204 0000 02B2 A5A5 0016 5008 4D4C 00CC 1205 000A 0003 0003 1201 120D 120F 024D FFFF FFFF FFFF A5A5 0010 9008 4D4C 00CC 3205 0010 0001 0000 1201 0404 120D 0D84 120F 0000 0341 A5A5 001C 5009 4D4C 00CC 120C 0004 2101 0100 021F FFFF FFFF FFFF FFFF FFFF FFFF A5A5 0000 9009 4D4C 00CC B20C 0000 02BC A5A5 0018 500A 4D4C 00CC 120D 0008 0003 0002 1201 120D 0235 FFFF FFFF FFFF FFFF A5A5 0014 900A 4D4C 00CC 320D 000C 0001 0000 1201 0404 120D 0D84 032A FFFF FFFF </code></pre> <p>Most of the checksums seem to be in the <code>0200..0300</code> range, however really long messages can have larger values, such as these ones at powerup that are in the <code>0700</code> range, which suggests to me some kind of sum/addition, given that longer messages have larger checksums:</p> <pre><code>A5A5 0036 5001 4D4C 00CC 1200 002A 2101 0002 2102 2020 4152 3034 4344 2103 0000 2104 0258 2105 0A21 063C 2107 0521 0814 2109 0000 210C E2D0 07D6 FFFF FFFF FFFF A5A5 0036 5002 4D4C 00CC 1200 002A 2101 0002 2102 2020 4152 3034 4344 2103 0000 2104 0258 2105 0A21 063C 2107 0521 0814 2109 0000 210C E2D0 07D7 FFFF FFFF FFFF </code></pre> <p>Any insights to a possible algorithm here would be much appreciated!</p>
Makita XGT battery/charger protocol checksum
|crc|checksum|communication|
<p>A bit underwhelming way to resolve that problem, but after testing it seems that indeed in these 8 first bytes includes both normals AND tangents. Both are saved as signed bytes. Still cannot understand who decided to spend the same amount of memory just for one UV channel compared to normals and tangents....</p>
32360
2023-10-05T03:45:51.830
<p>I'm trying to decode a vertex format that is used by the assets of a 3D application.</p> <p>I've identified the 0x24 stride. Every section starts with the position of the vertex, that is 3 32bit floats + 1 0xFFFFFFFF for as the fourth component/padding whatever that is. Then, then there are another 2 32bit float which 99.999% are the UV coordinates of each vertex.</p> <p>And then there's 12 bytes that I have absolutely no idea what on earth they are. An indicative set of these bytes looks like this:</p> <p><a href="https://i.stack.imgur.com/wxr8O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wxr8O.png" alt="byteselection" /></a></p> <p>So these are definitely not 32bit floats. The thing is that there is not a single time I've worked on any file that a vertex stream does not include normals. So normals should be stored somehow in the stream. However, it is insane to me that they are wasting 8 bytes for UVs and normals are stored in an obscure format.... I've also crosschecked wether the 2 floats were part of a normalized normal vector, but this is also not the case.</p> <p>The mesh is not skinned so they are probably not bytes that could be used for blend indices and thus, there are no weights either. I also tried to interpret them as half floats but they numbers really do not make any sense. So I suspect that something else is going on here, probably some masking of some sort.</p> <p>Any help is very much appreciated.</p> <p>PS: I've also attached a part of the stream.</p> <p><a href="https://temp-file.org/g8LPFepYbRfLHRW/file" rel="nofollow noreferrer">https://temp-file.org/g8LPFepYbRfLHRW/file</a></p>
Trying to decode a vertex format
|graphics|vertex-buffer|
<p><code>SeedEncrypt</code>'s code is <a href="https://developer.arm.com/documentation/dui0068/b/Writing-ARM-and-Thumb-Assembly-Language/Overview-of-the-ARM-architecture/Thumb-instruction-set-overview" rel="nofollow noreferrer">ARM Thumb</a> code, a compressed subset of the ARM istruction set with 2-byte opcodes.</p> <p>To differentiate between normal and Thumb code, the least significant bit of code pointers is used, and a pointer to a Thumb function will have it set. Disassemblers often recognize this, and show a <code>+1</code> after the pointer.</p> <p><a href="https://stackoverflow.com/q/37004954/7547712">__</a></p>
32363
2023-10-05T11:54:18.563
<p>i'm dissassembling an arm shared object and i'm seeing this line:</p> <pre><code>iVar1 = SecurityAccess(param_2,SeedEncrypt + 1,0x1); </code></pre> <p>the SecurityAccess SeedEncrypt is:</p> <pre><code>int SecurityAccess(int param_1,void *param_2,uint param_3) </code></pre> <p>and the SeedEncrypt function signature:</p> <pre><code>uint SeedEncrypt (uint param_1,uint param_2) </code></pre> <p>As you can see it is a pointer to a function (SeedEncrypt being a function), so my question is, what does the SeedEncrypt + 1 means?</p> <p>I saw online that you increment the address by the size of the function's return type, and as the SeedEncrypt address is 000a1fd6 and the signature is uint, how should i interpret it?</p> <p>This the SeedEncrypt function decompiled:</p> <hr /> <pre><code> * FUNCTION * ************************************************************** uint __stdcall SeedEncrypt (uint param_1, uint param_2) assume LRset = 0x0 assume TMode = 0x1 uint r0:4 &lt;RETURN&gt; uint r0:4 param_1 uint r1:4 param_2 SeedEncrypt 000a1fd6 83 08 lsrs r3,param_1,#0x2 000a1fd8 59 40 eors param_2,r3 000a1fda 43 08 lsrs r3,param_1,#0x1 000a1fdc 58 40 eors param_1,r3 000a1fde c3 00 lsls r3,param_1,#0x3 000a1fe0 08 1c adds param_1,param_2,#0x0 000a1fe2 58 40 eors param_1,r3 000a1fe4 70 47 bx lr </code></pre>
What does adding to a function pointer do?
|ghidra|
<p>operator precdence 0xffffffff==somevalue will naturally be false or 0</p> <pre><code>0:000&gt; ? poi(@rbx) Evaluate expression: 8388357042652472396 = 74696e49`7072644c 0:000&gt; ? poi(@rbx) &amp; 0`ffffffff Evaluate expression: 1886544972 = 00000000`7072644c 0:000&gt; ? poi(@rbx) &amp; 0`ffffffff == 7072644c Evaluate expression: 0 = 00000000`00000000 0:000&gt; ? (poi(@rbx) &amp; 0`ffffffff) == 7072644c Evaluate expression: 1 = 00000000`00000001 0:000&gt; </code></pre>
32367
2023-10-06T06:10:11.217
<p>I want to set a conditional breakpoint on function argument at the entry of a function. Here is the value I want which is c0 a8 89 01. I want to break the function when that register holds this specific value</p> <pre><code>2: kd&gt; db @rdx ffffae86`ee4ec024 c0 a8 89 01 c0 a8 89 b4-00 35 e6 d2 00 3a 51 ae .........5...:Q. ffffae86`ee4ec034 d1 c9 81 83 00 01 00 00-00 00 00 00 05 5f 6c 64 ............._ld ffffae86`ee4ec044 61 70 04 5f 74 63 70 03-70 64 63 06 5f 6d 73 64 ap._tcp.pdc._msd ffffae86`ee4ec054 63 73 04 74 65 73 74 05-6c 6f 63 61 6c 00 00 06 cs.test.local... ffffae86`ee4ec064 00 01 87 e4 5c 15 80 e4-22 d2 1e 15 d3 b6 13 67 ....\...&quot;......g ffffae86`ee4ec074 ed b1 02 ec 38 78 8f 7e-26 3e 34 d0 e6 db 55 20 ....8x.~&amp;&gt;4...U ffffae86`ee4ec084 14 fe a2 e2 1e a9 d5 25-6f 47 cd 17 a3 41 08 11 .......%oG...A.. ffffae86`ee4ec094 be b3 c7 20 ed e1 80 26-49 3e f7 90 43 0d 75 db ... ...&amp;I&gt;..C.u. </code></pre> <p>The command I use is</p> <pre><code>bp module!function &quot;.if(poi(@rdx)&amp;0x0`ffffffff==0x0189a8c0){.echo target hash triggered;r rcx} .else{gc} &quot; </code></pre> <p>But I found out that this bp is never triggered so I took a deep look</p> <pre><code>2: kd&gt; ? poi(@rdx)&amp;0x0`ffffffff Evaluate expression: 25798848 = 00000000`0189a8c0 2: kd&gt; ? poi(@rdx)&amp;0x0`ffffffff==0x0189a8c0 Evaluate expression: 0 = 00000000`00000000 </code></pre> <p>why is the condition 0? I know the condition is in MASM but I don't understand why this happened.</p>
windbg conditional breakpoint equal always get 0
|windbg|breakpoint|
<p>This is what I have done in similar cases but adapted to your scenario:</p> <ul> <li>Build the new open source library as a standard SO or DLL that is loadable by your target. If you're unlucky, you might need to use an old compiler...</li> <li>Patch the entry point of your target to load the SO/DLL as soon as it's safe or, alternatively, directly modify the binary to add a new library to it so you don't have to load it yourself.</li> <li>Hook the exported functions of the library statically linked inside your binary and forward them to the newly built library. If you're unlucky, the functions are in-lined and then your life would not be so nice (but most likely the functions aren't in-lined).</li> </ul> <p>By doing this you minimize the number of pure assembler patches you need to write and once it's working, you will almost &quot;magically&quot; have your target working with newest versions of your target library (but you will have to test to verify it's compatible and they didn't break something).</p> <p>Oh, by the way! Naturally, you will need to find first where the library is inside the binary. You can diff with <a href="https://github.com/joxeankoret/diaphora" rel="nofollow noreferrer">Diaphora</a> a version of your open source library against your target and import the symbols you need.</p> <p>Hope it helps.</p>
32369
2023-10-06T13:37:56.533
<p>I'm dealing with a reverse engineering challenge involving a binary application that was statically compiled with a legacy library. While the legacy library is not vulnerable, it lacks certain features that would significantly improve the functionality of the binary. Importantly, I have access to the open-source code of this library.</p> <p>My goal is to enhance the binary by incorporating these missing features from the new version of the library. Specifically, I want to:</p> <ol> <li>Take the binary compiled with the legacy library.</li> <li>Integrate the additional features from the new version of the library into the binary.</li> <li>Rebuild or modify the binary so that it utilizes the enhanced library functionality.</li> </ol> <p>Is this feasible, and if so, what are the general steps or techniques involved in achieving this task? Have you ever heard about something like that?</p> <p>Any advice or insights would be greatly appreciated.</p>
Updating legacy library in an already compiled binary
|c++|c|linux|elf|patching|
<p><em>Note: I also posted this answer at the following ROMHacking.net forum post: <a href="https://www.romhacking.net/forum/index.php?topic=37808.msg449648#msg449648" rel="nofollow noreferrer">Re: Figuring a CRC to edit a PS1 save file</a></em></p> <p>It looks like the &quot;hash&quot; function is just a simple 32-bit sum: In the files you provided, if you treat each group of 4 bytes in the range [0x2200, 0x2850) as a little-endian unsigned integer and sum them all up (modulo 2<sup>32</sup>), the sum will match the 4-byte little-endian unsigned value at 0x285C.</p>
32380
2023-10-08T16:56:27.443
<p>So I've set myself the goal of editing Crash Bash saves for the PS1. I'm using RetroArch + PCSX, so I'm editing memory card .srm files binary contents directly.</p> <p>Uploaded a zip with some save games, in case you want to look at them: <a href="https://drive.google.com/file/d/1xZgQGt4MmSoduK5lWjAT1osa1hBEbsEE/view?usp=drive_link" rel="nofollow noreferrer">https://drive.google.com/file/d/1xZgQGt4MmSoduK5lWjAT1osa1hBEbsEE/view?usp=drive_link</a></p> <p>After editing file contents, the game ignores the save. Through trial and error, I've seen that I can't modify anything inside the range [0x2200, 0x2850), so that must be CRC-checked.</p> <p>Anything before 0x2200 (e.g. file name, icons) is defined in the specs for the memory card file format in here: <a href="https://www.psdevwiki.com/ps3/PS1_Savedata" rel="nofollow noreferrer">https://www.psdevwiki.com/ps3/PS1_Savedata</a></p> <p>The files end up with what looks to be a 32-bit CRC hash. 0x2850: 01 00 00 00 00 00 00 00 00 00 00 00 E3 B6 0C E7</p> <p>Weirdly enough, the hash is at 0x285C, but the hash is not covering the gap between (0x2850, 0x285C), so I can edit those bits and the game recognizes and loads the save just fine. I think it's safe to say that the game data is in the [0x2200, 0x2860) range and that the game is the one (i.e. not the system) running the CRC-check over [0x2200, 0x2850).</p> <p>I've tried copying the hex values of the save into <a href="https://crccalc.com/" rel="nofollow noreferrer">https://crccalc.com/</a> to see if any of the values would match, but no luck.</p> <p>I've also tried using <a href="https://reveng.sourceforge.io/" rel="nofollow noreferrer">https://reveng.sourceforge.io/</a>, <a href="https://crc-reveng.septs.app/" rel="nofollow noreferrer">https://crc-reveng.septs.app/</a> with options: -w 32 -l -s</p> <p>So that:</p> <ul> <li>-w: Assuming that the hash is 32 bit</li> <li>-l: I think that PSX is little-endian, so I assume that this CRC should also be little endian</li> <li>-s: search mode from reveng</li> </ul> <p>Since reveng seems to work better with more samples, I've been doing some additional saves, so I have 6 sample files.</p> <p>But that returns no results. Judging the usages I've seen (<a href="https://hackaday.com/2019/06/27/reverse-engineering-cyclic-redundancy-codes/" rel="nofollow noreferrer">https://hackaday.com/2019/06/27/reverse-engineering-cyclic-redundancy-codes/</a>), I think it should be fine with 6 saves, but all use cases I've seen have always been running over smaller data, so who knows.</p> <p>So I'm running a bit out of ideas here. Let me know if you have any recommendations.</p>
Figuring a CRC to edit a PS1 save file
|crc|game-hacking|checksum|
<p>This is an example of optimizing a <em>tail call</em> - a call to another function which is done as the last statement of the current function. Because the LR (link register) has not been modified, the ret/blr of the destination function will directly return to the caller of the stub.</p>
32383
2023-10-11T19:17:16.237
<p>I'm analyzing some functions I see in Machos binaries and I see that whenever there's <code>bl</code> instruction to an objective-c stub function that resides in the <code>__objc_stubs</code> section and in that function there's eventually a call with <code>br</code> instruction to the <code>_objc_msgSend</code> symbol that resides in the <code>_got</code> section that will eventually get resolved when the <code>libobjc.dylib</code> will get loaded by the <code>dyld</code>, for example:</p> <pre><code>adrp x1, 0x24e000 ldr x1, [x1, #0x670] =&gt; some selector pointer adrp x16, 0x1fc000 ldr x16, [x16, #0xd48] =&gt; _objc_msgSend stub location br x16 </code></pre> <p>Now I wonder why there isnt any <code>ret</code> instruction at the end of these stubs to return to the code flow of the original function that called this stub? Will the <code>ret</code> instruction just be present in the <code>_objc_msgSend</code> from <code>libobjc.dylib</code> and it will eventually call it by itself?</p>
Objective-C stub functions on AARCH64
|arm|mach-o|arm64|
<p>Right-click <code>i</code> and select either:</p> <ul> <li><code>Create new struct type</code> to create a new type deducted from <strong>function-scoped</strong> access to the variable</li> <li><code>Convert to struct *</code> to apply an existing type</li> </ul> <p>You can inspect and manage structure types in <code>Local Types</code> tab (<code>View/Open subviews/Local Types</code>), including the types you already have (found in system APIs and debug symbols).</p>
32389
2023-10-13T02:39:06.470
<p>I'm working on a windows program which is walking PEB Ldr list. the related types are as follows:</p> <pre><code>struct LDR_DATA_TABLE_ENTRY { LIST_ENTRY InLoadOrderLinks; // offset = 0, size = 0x10 LIST_ENTRY InMemoryOrderLinks; // offset = 0x10, size = 0x10 // ... UNICODE_STRING FullDllName; // offset = 0x48, size = 0x10 UNICODE_STRING BaseDllName; // offset = 0x58, size = 0x10 }; </code></pre> <p>the pseudocode IDA generated is like that:</p> <pre><code>i = (LDR_DATA_TABLE_ENTRY *)NtCurrentPeb()-&gt;Ldr-&gt;InMemoryOrderModuleList.Flink; CurDllName = i-&gt;FullDllName.Buffer; // FullDllName should be BaseDllName! CurDllNameLength = i-&gt;FullDllName.Length; </code></pre> <p>The problem is, <code>i-&gt;FullDllName</code> should be <code>i-&gt;BaseDllName</code>, because <code>i</code> is not <code>LDR_DATA_TABLE_ENTRY *</code> but actually <code>LDR_DATA_TABLE_ENTRY * + 0x10</code> (address of <code>LDR_DATA_TABLE_ENTRY.InMemoryOrderLinks</code>).</p> <p>The correct output should be like that:</p> <pre><code>i = NtCurrentPeb()-&gt;Ldr-&gt;InMemoryOrderModuleList.Flink; LDR_DATA_TABLE_ENTRY *Node = CONTAINING_RECORD(i, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); CurDllName = Node-&gt;BaseDllName.Buffer; CurDllNameLength = Node-&gt;BaseDllName.Length; </code></pre> <p>In case <code>i</code> is an offset, Is there any way I can do to change type of <code>i</code> to something correct (like struct members) or just add the variable <code>Node</code> in IDA? The <code>Node</code> pointer I wrote here seems to be optimized out.</p> <p>I tried <code>CONTAINING_RECORD</code> but it seems not applicable here.</p>
How to convert variable to struct member in IDA?
|ida|windows|pe|
<p>You can use the tool mentioned here: <a href="https://github.com/hu60t/hu60wap6/files/6206916/Huawei.configuration.encryption.and.decryption.tools.zip" rel="nofollow noreferrer">https://github.com/hu60t/hu60wap6/files/6206916/Huawei.configuration.encryption.and.decryption.tools.zip</a></p> <p>Reference: <a href="https://gist.github.com/staaldraad/605a5e40abaaa5915bc7" rel="nofollow noreferrer">https://gist.github.com/staaldraad/605a5e40abaaa5915bc7</a></p>
32414
2023-10-22T02:37:05.593
<p>I have a Huawei hg8245h modem and unfortunately, I have forgotten my sip phone password and my ISP does not provide it to me. I have downloaded the modem configuration and this is the section related to the SIP password:</p> <pre><code>&lt;SIP AuthUserName=&quot;XXXX&quot; AuthPassword=&quot;XXXX&quot; URI=&quot;&quot;&gt; &lt;X_HW_Digitmap DMName=&quot;&quot; DigitMap=&quot;&quot; DigitMapStartTimer=&quot;20&quot; DigitMapShortTimer=&quot;5&quot; DigitMapLongTimer=&quot;10&quot;/&gt; &lt;/SIP&gt; </code></pre> <p>I have tried to use this tool to decipher with no success: <a href="https://andreluis034.github.io/huawei-utility-page/#cipher" rel="nofollow noreferrer">https://andreluis034.github.io/huawei-utility-page/#cipher</a></p> <p>Can someone decipher this password for me or give me help to dicpher it?</p>
I need to decipher my Huawei hg8245h modem sip phone password
|decryption|router|
<p>seems like I finally found it:</p> <p>CRC is calculated with polynomial 0x2F, inital 0xFF and final 0xFF. As data are the bytes 1 to 7 used and as an 8th byte the value from table for the current message for the current counter value. Yes, there is one table for each message (Unique identifier array for the CRC calculation of the signal group xyz)...</p>
32421
2023-10-23T07:44:18.633
<p>I have the same situation as in question <a href="https://reverseengineering.stackexchange.com/questions/20484/crc8-reverse-engineering">CRC8 reverse engineering</a>. But changing the final XOR value seems not to solve my problem and reveng does not help as well.</p> <p>I am copying the text from the original question here again:</p> <blockquote> <p>I am creating a CAN Bus on-bench testing solution which replicates the entire vehicle to test a single module. I have a number of messages that require a CRC byte in order to be valid. The messages are in little-endian byte order, and the CRC value is held in byte 0. I have collected valid messages with a changing 4 bit alive-counter along with their CRC byte with the hope someone can help. I have tried CRC reveng, but either do not know hot to use it correctly or it is unable to find the polynomial, as it shows &quot;No models found&quot; when searching.</p> <p>For reference, I found documentation that suggests the polynomial used is the standard SAE J1850 CRC8 polynomial x^8 + x^4 + x^3 + x^2 + 1, with a CRC-ID in decimal of 166 (stated as used for the low byte). I have also tried with the online calculator available here: <a href="http://www.sunshine2k.de/coding/javascript/crc/crc_js.html" rel="nofollow noreferrer">http://www.sunshine2k.de/coding/javascript/crc/crc_js.html</a>, but cannot get the correct result.</p> <p>If anyone could provide some assistance, I would greatly appreciate it. I would like help in clarifying the correct polynomial, along with any other relevant parameters.</p> </blockquote> <p>Here my messages (can provide different, more complex data if required):</p> <pre><code>CRC DATA DE 10 FF FF FF FF FF FF CB 11 FF FF FF FF FF FF A3 12 FF FF FF FF FF FF 48 13 FF FF FF FF FF FF 96 14 FF FF FF FF FF FF 36 15 FF FF FF FF FF FF EB 16 FF FF FF FF FF FF 1C 17 FF FF FF FF FF FF 6A 18 FF FF FF FF FF FF 9D 19 FF FF FF FF FF FF 40 1A FF FF FF FF FF FF E0 1B FF FF FF FF FF FF 3E 1C FF FF FF FF FF FF 43 1D FF FF FF FF FF FF 9E 1E FF FF FF FF FF FF 69 1F FF FF FF FF FF FF </code></pre> <p>CAN trace is from a 9G automatic transmission but most of the messages on this powertrain bus seem to use the same mechanism (counter in the same 4 bits, CRC in the first byte, etc.). Any help with finding out how this CRC byte is calculated is highly appreciated : )</p> <p>Here some more data from another message (id 0x37):</p> <pre><code>CRC DATA FC 20 88 04 21 00 0F 00 88 21 88 05 21 00 0F 00 95 22 88 04 21 00 0F 00 79 23 88 05 21 00 0F 00 66 24 88 04 21 00 0F 00 56 25 88 04 21 00 0F 00 56 26 88 05 21 00 0F 00 8A 27 88 04 21 00 0F 00 17 28 88 05 21 00 0F 00 76 29 88 04 21 00 0F 00 D3 2A 88 05 21 00 0F 00 4C 2B 88 04 21 00 0F 00 EE 2C 88 05 21 00 0F 00 E9 2D 88 04 21 00 0F 00 A2 2E 88 05 21 00 0F 00 1B 2F 88 04 21 00 0F 00 </code></pre> <p>Just found this table in the Damos for the corresponding ECU:</p> <pre><code>Unique identifier array for the CRC calculation of the signal group TCM_EngIntrvntn_Pr2 of the message TCM_EngIntrvntn_AR2 56 5E 66 6E 76 7E 86 8E 96 9E A6 AE B6 BE C6 CE </code></pre> <p>Maybe a different initial of final value is used for every counter value? Will try to generate messages with changing data for the same counter value.</p> <p>Only thing I have in my logs is this one at the moment:</p> <pre><code>CRC Data (counter value '2') 95 22 88 04 21 00 0F 00 C1 22 88 05 21 00 0F 00 </code></pre>
CRC8 CAN message reverse engineering II
|crc|
<p>Cmake Version</p> <pre><code>D:\&gt;cmake --version cmake version 3.28.0-rc3 CMake suite maintained and supported by Kitware (kitware.com/cmake). </code></pre> <p>rust version</p> <pre><code>D:\&gt;cargo -V cargo 1.73.0 (9c4383fb5 2023-08-26) </code></pre> <ol> <li>create a project directory md dir</li> <li>init the project in the directory with cargo init</li> <li>add the Dependency &quot;keystone-engine&quot; to Cargo.toml with cargo add</li> </ol> <hr> <pre><code>D:\&gt;md rustkey D:\&gt;cd rustkey D:\rustkey&gt;cargo init Created binary (application) package D:\rustkey&gt;cargo add keystone-engine Updating crates.io index Adding keystone-engine v0.1.0 to dependencies. Features: + build-from-src + cmake - pkg-config - use-system-lib Updating crates.io index </code></pre> <p>source to compile</p> <pre><code>D:\rustkey&gt;cd src D:\rustkey\src&gt;notepad main.rs D:\rustkey\src&gt;type main.rs use keystone_engine::*; fn main() { let engine = Keystone::new(Arch::X86, Mode::MODE_64).expect(&quot;Could not initialize Keystone engine&quot;); let result = engine.asm(&quot;syscall;ret&quot;.to_string(),0).expect(&quot;Could Not Assemble&quot;); println!(&quot;{}&quot;,result); } D:\rustkey\src&gt;cd .. </code></pre> <p>build the project</p> <pre><code>D:\rustkey&gt;cargo build Compiling cc v1.0.83 Compiling libc v0.2.149 Compiling bitflags v1.3.2 Compiling cmake v0.1.50 Compiling keystone-engine v0.1.0 Compiling rustkey v0.1.0 (D:\rustkey) Finished dev [unoptimized + debuginfo] target(s) in 5m 49s </code></pre> <p>running the project multiple times</p> <pre><code> D:\rustkey&gt;cargo -q run 0f05c3 D:\rustkey&gt;cargo -q run 0f05c3 D:\rustkey&gt;cargo -q run 0f05c3 D:\rustkey&gt;cargo -q run 0f05c3 </code></pre>
32430
2023-10-24T16:54:17.340
<p>I'm working on a project related to Process Injection for learning Rust. I have to inject shellcode at some points and use the Keystone engine for assembling shellcode from source.</p> <p>I detected that the rust bindings were not successful assembling <code>syscall; ret</code> shellcode.</p> <p>I then tried to reproduce by creating a python and rust minimal version and ensuring the syntax in use was the same for both version (also both bindings has the same major and minor versions, which is v0.9)</p> <p><strong>Python version:</strong></p> <pre><code>from keystone import * from capstone import * code = &quot;syscall; ret&quot; ks = Ks(KS_ARCH_X86, KS_MODE_64) ks.syntax = KS_OPT_SYNTAX_INTEL encoding, count = ks.asm(code) cs = Cs(CS_ARCH_X86, CS_MODE_64) disass = cs.disasm(bytes(encoding), 0x1000) print(&quot;Assembly: %s&quot; % code) print(&quot;Binary: %s&quot; % encoding) print(&quot;Disassembly:&quot;) for i in disass: print(&quot;0x%x:\t%s\t%s&quot; % (i.address, i.mnemonic, i.op_str)) </code></pre> <p><strong>Rust version:</strong></p> <pre><code>use keystone::{self, MODE_64}; use capstone::{self, prelude::BuildsCapstone}; fn main() { let code = &quot;syscall; ret&quot;; let ks = keystone::Keystone::new(keystone::Arch::X86, MODE_64).unwrap(); ks.option(keystone::OptionType::SYNTAX, keystone::OPT_SYNTAX_INTEL).unwrap(); let encoding = ks.asm(code.to_string(), 0x1000).unwrap(); let cs = capstone::Capstone::new() .x86() .mode(capstone::arch::x86::ArchMode::Mode64) .build().unwrap(); let insns = cs.disasm_all(&amp;encoding.bytes, 0x1000).unwrap(); println!(&quot;Assembly: {}&quot;, code); println!(&quot;Binary: {:?}&quot;, encoding.bytes); println!(&quot;Disassembly:&quot;); for i in insns.iter() { println!(&quot;{}&quot;, i); } } </code></pre> <p>Here is the result of running the programs: <a href="https://i.stack.imgur.com/9oAxp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9oAxp.png" alt="Testing of both programs" /></a></p> <p>As you can see, the Rust implementation outputs random binary code and I would like to know why.</p> <p>Is it related to a misunderstanding of rust ? or of the rust bindings ? A bug in the rust bindings ?</p> <p>I'm kinda stuck in my comprehension of the problem so if anyone can help me.</p> <p>Regards.</p>
Keystone rust bindings error when assembling "syscall; ret" shellcode
|assembly|
<p>Your toolchain probably does not support VLE (AFAIK it was never mainlined), so you’ll need a fork with VLE support (e.g. from <a href="https://www.nxp.com/design/software/development-software/s32-design-studio-ide/s32-design-studio-for-power-architecture:S32DS-PA?#design-resources" rel="nofollow noreferrer">Freescale/NXP</a>, <a href="https://hightec-rt.com/en/products/development-platform" rel="nofollow noreferrer">Hightec</a> or <a href="https://www.st.com/en/development-tools/spc5-studio.html" rel="nofollow noreferrer">ST</a>) and use the toolchain-specific switch to force VLE disassembly</p>
32440
2023-10-26T12:04:31.207
<p>I am trying to disassemble PowerPC dump with <code>objdump</code>. I have only raw binary dump, not ELF or any other 'container'.</p> <p>Unfortunately, I cannot find any option to force VLE mode (my binary definitely uses it).</p> <p>This one is just a short example:</p> <pre><code>~$ objdump -b binary -EB -m powerpc:vle -M vle -D PowerPC_test.bin PowerPC_test.bin: file format binary Disassembly of section .data: 00000000 &lt;.data&gt;: 0: c5 a9 50 1a .long 0xc5a9501a 4: fb 70 2a a4 .long 0xfb702aa4 </code></pre> <p>According to IDA and Ghidra, it should be</p> <pre><code>seg000:00000000 C5 A9 se_lwz r26, 0x14(r25) seg000:00000002 50 1A FB 70 e_lwz r0, -0x490(r26) seg000:00000006 2A A4 se_cmpi r4, 0xA </code></pre>
PowerPC disassemble with objdump
|objdump|powerpc|
<p>Probably this DAT_4c447798 is a pointer and it should point to the string.</p> <p>Ghidra acts much better, if you specify that some memory areas are constant. In the menu check <code>Window</code> -&gt; <code>Memory map</code> and remove ticks at <code>W</code> column for all areas where your code does not wrote to.</p> <p>And of course, please provide more details in further questions.</p>
32474
2023-11-06T09:09:37.857
<p>I asked exactly the same question <a href="https://stackoverflow.com/questions/77429840/convert-a-memory-location-to-string-in-ghidra">here</a>, but later I figure out this community and found out this helpful to ask it here as well.</p> <p>I would like to have a decompiled pseudo-code in <code>Ghidra</code> like:</p> <pre><code>FUN_4c4363e8(&quot;Hello world&quot;); </code></pre> <p>This is what usually I see in <code>IDA</code> , but in Ghidra, by default I get such a code:</p> <pre><code>FUN_4c4363e8((char*)(DAT_4c447798)); </code></pre> <p>Is there a way to force the decompiler to convert the <code>DAT_4c447798</code> memory address to <code>&quot;Hello world&quot;</code> null-terminated string?</p> <p>Thanks.</p>
convert a memory location to string in Ghidra
|ida|ghidra|
<p>I found the answer <a href="https://www.pnfsoftware.com/jeb/manual/dev/introducing-jeb-extensions/#scripts-vs-plugins" rel="nofollow noreferrer">here</a>.</p> <p>Scripts...</p> <blockquote> <ul> <li>Implement IScript</li> </ul> <ol> <li>Example: modify some code, navigate somewhere, display some info, etc.</li> </ol> </blockquote> <blockquote> <ul> <li>Are called by users to achieve small tasks</li> <li>Must be written in Python (they are run in a Jython VM)</li> </ul> <ol start="2"> <li>Ideal for rapid development and prototyping</li> </ol> </blockquote> <blockquote> <ul> <li>Are executed by JEB on-demand</li> </ul> <ol start="3"> <li>In the GUI client, can be executed via the File menu</li> </ol> </blockquote> <p>Plugins...</p> <blockquote> <ul> <li>Implement a specialized sub-type of IPlugin</li> <li>Can perform a variety of tasks, from input processing, disassembling, decompiling, adding functionality to other plugins, event-triggered actions, etc.</li> <li>May be compiled as jar; some plugin types may be written as scripts (Java or Python)</li> </ul> </blockquote> <p>Hope this reference is useful too all who use this software package.</p>
32475
2023-11-06T11:35:08.813
<p>I've downloaded JEB CE (community edition) and according to the <a href="https://www.pnfsoftware.com/jeb/#features-matrix" rel="nofollow noreferrer">feature matrix</a>, it supports both script and plugin functionality:</p> <p><a href="https://i.stack.imgur.com/Th6bK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Th6bK.png" alt="enter image description here" /></a></p> <p>I would like to know if there is any difference in the 2 and any advantage of using one over the other? In version 5.X+, there is a /coreplugins folder which shows plugins written in both Python and Java:</p> <p><a href="https://i.stack.imgur.com/iCuu7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iCuu7.png" alt="enter image description here" /></a></p> <p>A Java plugin :</p> <pre><code>import com.pnfsoftware.jeb.core.Version; import com.pnfsoftware.jeb.core.units.code.asm.decompiler.ast.opt.AbstractCOptimizer; /** * A sample gendec AST optimizer plugin. * * @author Nicolas Falliere * */ public class COptSampleJava extends AbstractCOptimizer { public COptSampleJava() { super(); } @Override public int perform() { logger.debug(&quot;COptSampleJava: the optimizer is running&quot;); return 0; } } </code></pre> <p>would look identical to the Python version</p> <pre><code>from com.pnfsoftware.jeb.core.units.code.asm.decompiler.ast.opt import AbstractCOptimizer ''' Skeleton for an Java Abstract Syntax Tree (AST) optimizer plugin for gendec, JEB's generic decompiler. This Python plugin is executed during the decompilation pipeline of a method. How to use: - Drop this file in your JEB's coreplugins/scripts/ sub-directory - Make sure to have the setting `.LoadPythonPlugins = true` in your JEB's bin/jeb-engines.cfg file For additional information regarding dexdec AST optimizer plugins, refer to: - the Manual (www.pnfsoftware.com/jeb/manual) - the API documentation: TODO ''' class COptSamplePython(AbstractCOptimizer): # note: Python script optimizers are singleton instances! # the engine will instantiate and provide a single instance for all decompilation threads # therefore, if you are using object attributes, make sure to provide support for concurrency # (this restriction does not apply to Java script optimizers, as well as full-blown jar optimizers; # each decompilation thread has its own unique instance of such optimizer objects) # for this reason (as well as others), moderately complex AST optimizers should be written in Java def __init__(self): self.logger.debug('COptSamplePython: instantiated') def perform(self): self.logger.debug('COptSamplePython: executed') # if a value &gt;0 is returned, the decompiler will assume that AST is being transformed and this AST optimizer will be called again return 0 # no optimization is performed </code></pre> <p>Can both languages be used for both plugin and script?</p>
JEB Community Edition - Difference between Script vs Plugin?
|jeb|
<p>Yes, you are right: <a href="https://en.wikibooks.org/wiki/X86_Assembly/GNU_assembly_syntax#Operation_Suffixes" rel="nofollow noreferrer">Operation suffixes</a> on wikibooks.</p>
32479
2023-11-07T11:25:14.857
<p>I'm trying to understand suffixes used for the AT&amp;T syntax for the x64 assembly used for instruction mnemonics.</p> <p>For regular cases:</p> <pre><code>'b', // 8_bit 'w', // 16_bit 'l', // 32_bit 'q', // 64_bit 't', // 80_bit </code></pre> <p>Examples: Intel vs AT&amp;T:</p> <pre><code>inc word ptr [rbx] incw (%rbx) inc dword ptr [rbx] incl (%rbx) inc qword ptr [rbx] incq (%rbx) </code></pre> <p>But then for floating-point instructions, it's different:</p> <pre><code>L'b', // 8_bit L'w', // 16_bit L's', // 32_bit L'l', // 64_bit L't', // 80_bit </code></pre> <p>If so, then why does the GCC compiler give me this:</p> <pre><code>fiadd word ptr [rcx] fiadds (%rcx) fiadd dword ptr [rcx] fiaddl (%rcx) </code></pre> <p>Can some confirm if I'm right, or correct me?</p>
Mnemonic suffixes for x86-64 assembly for AT&T syntax
|assembly|x86-64|intel|
<p>Fortunately it reappeared once I open ida64 in GUI mode!</p>
32487
2023-11-10T04:53:21.743
<p>I Got IDA Pro license and for some reason ida.reg file from my home/.ida directory got deleted and now I just can't run ida and instead I get following displayed -</p> <p><a href="https://i.stack.imgur.com/ZA5Hj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZA5Hj.png" alt="enter image description here" /></a></p> <p>Is there any way to restore ida? Unfortunately, my support is expired.</p>
My ida.reg file got deleted, is there any way to restore ida?
|ida|idapython|
<p>The return address has been placed below the buffer on the stack. I presume it's the 0x55000008e0 entry in your second screenshot. This means that you won't be able to overwrite the return address via the buffer overflow.</p> <p>See <a href="https://stackoverflow.com/questions/68774522/arm64-buffer-overflow-cannot-overwrite-pc">https://stackoverflow.com/questions/68774522/arm64-buffer-overflow-cannot-overwrite-pc</a> for a more detailed explanation.</p>
32492
2023-11-10T18:20:02.113
<p>I'm trying to exploit a buffer overflow vulnerability in an ARM64 program from <a href="https://ad2001.gitbook.io/a-noobs-guide-to-arm-exploitation/introduction-to-stack-buffer-overflows#redirecting-the-execution" rel="nofollow noreferrer">this blog</a>. When I give as input 100*'A', and I compile the program for ARM 32 bit (without canaries), the program crashes (as the return address is overwritten). But, when I give as input 100*'A', and I compile the program for ARM 64 bit (without canaries), the program does not crash. Why does it happen? Can someone explain?</p> <p>Here are some screenshots of the stack before and after the call for strcpy:</p> <p>32 bit: <a href="https://i.stack.imgur.com/gL6yz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gL6yz.png" alt="enter image description here" /></a> 64 bit: <a href="https://i.stack.imgur.com/EpaXN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EpaXN.png" alt="enter image description here" /></a></p> <p>BTW I'm using QEMU to run the code on an Ubuntu VM 64 bit on an Intel CPU (also tried with Kali Linux 64 bit).</p> <p>Thanks.</p> <p>The code is:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; void vulnerable(char* ip) { char buffer[20]; strcpy(buffer, ip); } void win(){ printf(&quot;You successfully exploited the buffer overflow\n&quot;); system(&quot;/bin/sh&quot;); } int main(int argc, char** argv) { if (argc != 2) { printf(&quot;Argument &lt;input&gt;\n&quot;); exit(1); } vulnerable(argv[1]); exit(0); } </code></pre> <p>Compiled with:</p> <pre><code>aarch64-linux-gnu-gcc -O0 -fno-stack-protector -z execstack -o vuln64 ./vuln.c </code></pre>
ARM64 Stack Layout - Why 100x'A' Doesn't Crash?
|disassembly|c|exploit|buffer-overflow|arm64|
<p>From <a href="https://www.hex-rays.com/products/ida/support/idadoc/1165.shtml" rel="nofollow noreferrer">IDC: Predefined symbols</a> (emphasis mine):</p> <hr /> <p>The following symbols are predefined in the IDC preprocessor:</p> <pre><code> _NT_ IDA is running under MS Windows _LINUX_ IDA is running under Linux _MAC_ IDA is running under Mac OS X _UNIX_ IDA is running under Unix (linux or mac) _EA64_ 64-bit version IDA _QT_ GUI version of IDA (Qt) _GUI GUI version of IDA _TXT_ Text version of IDA _IDA_VERSION_ The current IDA version. For example: &quot;8.3&quot; _IDAVER_ The current, numerical IDA version. For example: &quot;830&quot; means v8.3 </code></pre> <p><strong>These symbols are also defined when parsing C header files.</strong></p> <hr />
32500
2023-11-14T08:39:15.547
<p><a href="https://hex-rays.com/blog/igors-tip-of-the-week-141-parsing-c-files/" rel="nofollow noreferrer">IDA has the ability to parse C header files</a> (by now a secondary option based on Clang also exists). It is useful to get structs and enums into your database via the Local Types view.</p> <p><strong>Question:</strong> <em>Aside</em> from the <code>CC_PARMS</code> setting in <code>ida.cfg</code> mentioned by Igor in the above article, is there a built-in preprocessor define that I can rely upon to accommodate IDA?</p> <p>I am looking for something like <code>__cplusplus</code> but for detecting IDA and perhaps even the IDA major version.</p>
When parsing a C header file in IDA, is there a preprocessor symbol I can use to detect it?
|ida|
<p>This may be related to automotive. I had seen something like this in <a href="https://github.com/ea/bosch_headunit_root/blob/main/README.md" rel="nofollow noreferrer">this</a> repository, strings including /dev/registry/LOCAL_MACHINE/SOFTWARE/BLAUPUNKT are mentioned directly <a href="https://github.com/ea/bosch_headunit_root/blob/main/docs/rtos_interaction.md" rel="nofollow noreferrer">here</a>. Using word &quot;registry&quot; here looks like a coincidence.<br /> <a href="https://i.stack.imgur.com/Tjj1w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tjj1w.png" alt="Explanation on libOSAL, OS abstraction layer" /></a></p>
32505
2023-11-17T15:18:11.913
<p>When trying to determine the filesystem of a firmware image using binwalk, I encountered a strange combination. The binwalk is returning a lot of Unix paths, but some of them contain a typical windows-style registry.</p> <pre><code>3157752 0x302EF8 Unix path: /dev/ffd/DNL 3159348 0x303534 Unix path: /dev/fgs/download 3166204 0x304FFC Unix path: /dev/rp_if/download 3198300 0x30CD5C Unix path: /dev/registry/LOCAL_MACHINE/SOFTWARE/BLAUPUNKT/PROCESS 3201380 0x30D964 Unix path: /dev/registry/LOCAL_MACHINE/SOFTWARE/BLAUPUNKT/PROCESS/%s </code></pre> <p>Did you see anything like this before? What could the filesystem/operating system be?</p>
Unix system with windows-style registry
|windows|linux|binwalk|
<p>Compilers may align function addresses to some boundary as part of the optimization process.</p> <p>When doing this, the gap between functions is filled with padding bytes that might accidentally run as code, should something go wrong with the program's flow.</p> <p>Most common are <code>0xcc</code> for <em>debug</em> build binaries for easier debugging and <code>0x00</code> for <em>release</em> builds where a debugger is not expected to be attached.</p>
32547
2023-12-05T13:05:18.283
<p>First, sorry for my bad english.</p> <p>What I know about 0xCC instruction is a breakpoint instruction.</p> <p>But, when I see x64 binary, each functions are seperate by multiple 0xCC instructions.</p> <p>I think x64 uses 0xCC instructinon as not only breakpoint but also function's serperator.</p> <p>So, what 0xCC instruction means in this case? If this instruction are really means function's seperator, does it always placed between each function at least 1 single 0xCC instruction? (at least call in code section which is going to the function in code section)</p> <p>The reason why I ask this question is, I want to make my code to verifying every binary's call instruction automatically, but some call instruction pointing invalid function. (this invalid functions are made by packer)</p> <p>What I considering is, if every functions are seperate by 0xCC in x64 binary, (call_address - 1) must be 0xCC and this can be one of my verifying condition.</p> <p>I hope for your guide. thank you.</p>
What is 0xCC between each functions?
|x86-64|packers|
<p>I'll post an answer here with the conclusions we came to in the chat, in case anyone finds it useful in the future.</p> <p>There seems to be a limitation of the Instruction Pattern Search tool in that the patterns must contain a fixed amount of bytes. In the screenshot posted in the original post, the second and fourth pattern are looking for <code>movss [addr], xmm</code> instructions (operands encoded in 5 bytes, first operand is <code>00...101</code>), while the instructions that need to be found are <code>movss [reg+offs], xmm</code> (operands encoded in 3 bytes, first operand is <code>01...100</code>). To correct the patterns, one needs to find an appropriate instruction in code or insert the bytes manually into the tool and then unmask the operands (as far as Ghidra allows).</p> <p>Alternatively, one can also use the memory search ('S' hotkey or Search -&gt; Memory) and insert a pattern matching the instruction bytes. For this specific question, the pattern would be:</p> <blockquote> <p>f3 0f 10 ?? ?? ?? ?? ?? f3 0f 11 ?? ?? ?? f3 0f 10 ?? ?? ?? ?? ?? f3 0f 11 ?? ?? ??</p> </blockquote> <p>Ghidra also allows searching in a more dynamic manner via <a href="https://fossies.org/linux/ghidra/Ghidra/Features/Base/src/main/help/help/topics/Search/Regular_Expressions.htm" rel="nofollow noreferrer">regular expressions</a>. This would allow one to craft a regex pattern that matches against four consecutive movss instructions, regardless of their operands, but may make it more difficult to guard against false positives.</p>
32572
2023-12-14T10:15:51.130
<p>I'd like to identify in Ghidra a specific sequence of instructions, which I get from MSVC Debug in Visual Studio compiling my own function:</p> <p><a href="https://i.stack.imgur.com/rMoq1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rMoq1.png" alt="enter image description here" /></a></p> <p>What I'm looking for so is (for the same DLL, decompiled in Ghidra) to intercept the sequence <code>movss/movss/movss/movss/lea/lea/lea</code>, in the hoping to intercept the C++ Clamp function I've defined:</p> <pre><code>template &lt;typename T&gt; T Clamp(const T&amp; min, const T&amp; max, const T&amp; value) { if (value &lt; min) { return min; } else if (value &gt; max) { return max; } return value; } </code></pre> <p>What's the correct way to do this in Ghidra?</p> <p>If I try <em>Instruction Pattern Search</em> feature in Ghidra, inserting the first 4 movss of the sequence (selecting the instructions show in the VS Debugger, after enabling <em>Show Code Bytes</em>; i.e. in order <code>f3 0f 10/f3 0f 11/f3 0f 10/f3 0f 11</code>):</p> <p><a href="https://i.stack.imgur.com/IaKEU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IaKEU.png" alt="enter image description here" /></a></p> <p>it doesn't return any hit.</p> <p>So, is this a mismatch from VS Code disassembly and the Listing elaborated by Ghidra, or am I searching in a wrong way?</p>
How to search a sequence of instructions in Ghidra?
|c++|ghidra|msvc|
<p>The comments in green, XREFs, are all of the references to that function that Ghidra could identify. Start with those to find what you are looking for.</p>
32592
2023-12-21T14:07:48.673
<p>Let says my Program use this <code>FUN_180811be0</code> function, discovered by disassembling the code within Ghidra:</p> <p><a href="https://i.stack.imgur.com/zWeuT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zWeuT.png" alt="enter image description here" /></a></p> <p>Where do I locate the points of the program where this call is being called?</p> <p>If I search for funtions it just show to me it:</p> <p><a href="https://i.stack.imgur.com/dUZWs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dUZWs.png" alt="enter image description here" /></a></p> <p>I need to locate point of code where its being called; for example here, within the function <code>FUN_180606830</code>, I can see the call to <code>thunk_FUN_18051a380</code>:</p> <p><a href="https://i.stack.imgur.com/pm8no.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pm8no.png" alt="enter image description here" /></a></p> <p>How can I find it starting from the target function?</p>
How can I locate where a specific function is being called within the Program using Ghidra?
|ghidra|
<p>You can modify breakpoint conditions from Debugger -&gt; Breakpoints -&gt; Breakpoint List, selecting a breakpoint that you wish to edit, and pressing Ctrl + E. IDA provides some information on modifying breakpoints (incl. conditions):</p> <ul> <li><a href="https://hex-rays.com//products/ida/support/idadoc/1407.shtml" rel="nofollow noreferrer">IDA Help: Edit breakpoints</a></li> <li><a href="https://hex-rays.com//products/ida/support/idadoc/1488.shtml" rel="nofollow noreferrer">IDA Help: Breakpoint conditions</a></li> </ul> <p>In your case, the condition would amount to <code>get_dword(0xD526C122) == 0xFF</code>.</p> <p>As for the counter, this has been asked before in <a href="https://reverseengineering.stackexchange.com/questions/8572/ida-pro-debugger-hit-counter">this question</a>. Unfortunately, it doesn't seem that there's a native way to do this in IDA, but you can do it easily by using some IDC and breakpoint conditions, as the top comment points out. Do note that their answer doesn't work properly due to bad ordering of the brackets, so I'll post a working solution here:</p> <pre><code>extern bpcount; bpcount++; Message(form(&quot;%d. hit\n&quot;, bpcount)); return (bpcount&gt;500); </code></pre>
32629
2024-01-10T15:35:38.380
<p>How to set breakpoint condition that checks certain address value, for example: 0xD526C122 = FF.</p> <p>How can I make a counter that counts how many times breakpoint condition was met without actually breaking the program?</p>
IDA breakpoint condition
|ida|breakpoint|
<p>This obj (or omf) file is an assembled 8086 executable that should contain executable code (no headers).</p> <p>IDA Pro can disassemble it, but the free version won't.</p> <p>Ghidra can handle it.</p> <p>You may have to select the processor type manually and/or set the loading address (0x100).</p>
32637
2024-01-12T13:35:31.277
<p>I'm new to programming and recently studying an ancient DOS assembly program written for 80186 and assembled with MASM. There are some .obj files that I want to open and take a look. I tried obj2asm.exe and IDA 5.0 (freeware version), but both programs could not deliver accurate results. As far as I know those .obj files are just lists of data indexes in format similar to below:</p> <p>IG SEGMENT PUBLIC 'ROM' PUBLIC INDEX1</p> <p>INDEX1 DB 000H,000H ; A<br /> DB 021H,000H ; B<br /> DB 06FH,020H ; C<br /> ...... ......</p> <p>There are no assembly instruction in the .obj files. What should I do in order to accurately diassemble those .obj files? This DOS program is very important to my study and I'm desperate to get the correct files. Could anyone please give me some advice? Your kind assistance is very much appreciated! Thank you in advance!</p>
how to diassemble an .obj file
|assembly|disassemblers|
<p>The whole problem is that all versions of objdump and even llvm-objdump incorrectly disassemble 32-bit instructions of C-SKY processors, I managed to find a working objdump version 2.27 on the website <a href="https://www.xrvm.cn/" rel="nofollow noreferrer">https://www.xrvm.cn/</a> there is also an Eclipse-based IDE</p> <p><a href="https://i.stack.imgur.com/fZfAe.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fZfAe.jpg" alt="enter image description here" /></a></p>
32676
2024-01-29T04:41:50.730
<p>can you tell me why objdump does not correctly disassemble the firmware for the C-SKY (ck803s) processor? what is .long: between the lines, unknown instructions? or am I setting the parameters for objdump incorrectly? here are mine: ./objdump -D -b binary -m csky:cs803 -EL firmware.bin</p> <p><a href="https://i.stack.imgur.com/HKxkC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HKxkC.jpg" alt="enter image description here" /></a></p> <p>from off. sources use CK803S processor</p> <p><a href="https://i.stack.imgur.com/VpNPu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VpNPu.jpg" alt="enter image description here" /></a></p> <p>this is how the bootloader works</p> <p><a href="https://i.stack.imgur.com/7UutO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7UutO.jpg" alt="enter image description here" /></a></p> <p>The firmware is launched from the specified address at offset 0x04, look at the dump merged from the flash drive</p> <p><a href="https://i.stack.imgur.com/dd0ov.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dd0ov.jpg" alt="enter image description here" /></a></p> <p>objdump output</p> <p><a href="https://i.stack.imgur.com/9l5dQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9l5dQ.jpg" alt="enter image description here" /></a></p>
Firmware disassembler for c-sky processor (ck803s)
|firmware-analysis|
<p>As hinted by Ali, this info is stored in the global <code>inf</code> structure. It used to be an actual global variable accessible via the <code>idaapi.cvar</code> wrapper, but now you need to use the various getters/setters in the <a href="https://hex-rays.com//products/ida/support/idapython_docs/ida_ida.html" rel="nofollow noreferrer"><code>ida_ida</code> module</a>.</p> <p>While you can indeed go down that road and use <code>inf_get_cc</code>/<code>inf_set_cc</code> or <code>inf_set_cc_cm</code>, in case you only need to change the pointers to 64-bit, normally it should be enough to call <strong><code>inf_set_64bit(True)</code></strong>.</p>
32678
2024-01-30T02:09:04.820
<p>so, I'm writing a script to automate analysis, and the code I'm working with is 64bit.</p> <p>the <strong>pointer size</strong> field shown here is the wrong one:</p> <p><a href="https://i.stack.imgur.com/WR3wr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WR3wr.png" alt="enter image description here" /></a></p> <p>I want to change it from within python to 64bit. I've searched the Idapython documentation and previously similar questions and could not find an answer</p>
How to change default pointer size in IDA Pro
|ida|idapython|binary|compilers|
<p>You have to:</p> <p>1. Load the DLL into your process. In runtime, Windows' <code>LoadLibrary</code> api, will load the DLL and return a handle, which is the base address for the loaded module.</p> <p>2. Get the address of the function you want to call from the <code>.pdb</code>, either manually or by using the provided pdb querying functions, as documented here:</p> <p><a href="https://learn.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/idiadatasource-loaddatafrompdb?view=vs-2022" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/idiadatasource-loaddatafrompdb?view=vs-2022</a></p> <p>3. Cast the pointer to the the correct prototype and calling convention.</p> <p>There is some pretty good information in this post: <a href="https://copyprogramming.com/howto/pdb-find-calling-function-code-example#calling-a-non-exported-function-in-a-dll" rel="nofollow noreferrer">https://copyprogramming.com/howto/pdb-find-calling-function-code-example#calling-a-non-exported-function-in-a-dll</a></p> <p>Note that while calling a simple function only requires the correct prototype and calling convention, a C++ function may very well depend on objects that in turn may need to be allocated, initialized or constructed in some way for the call to succeed (and not crash the whole process). The constructor(s) for these objects will likely (but not guaranteed to) be in the DLL.</p> <p><code>.pdb</code> files contain more debug information than mere function pointers. There should be more clues inside.</p>
32679
2024-01-30T09:20:56.963
<p>I'm new to reverse engineering and recently met with a problem:</p> <p>I have the dll and pdb of a debug version third party module, but I don't have its source codes. Now I want to write a piece of C++ code to test the stability and efficiency of the interfaces of the module, among which the functions are mainly unexported.</p> <p>So my question is that how can I find the address of an unexported function and correctly call it from C++ with DLL and PDB?</p>
How to call unexported function in a third party DLL while having its PDB?
|c++|dll|functions|pdb|
<p><code>RuntimeException</code> is an Exception class like all the others, the only difference is that developers are not forced to catch <code>RuntimeException</code> and its child classes. And there is no special relation between <code>RuntimeException</code> and &quot;native calls&quot; (JNI calls).</p> <p>Your problems are independent of the <code>RuntimeException</code> instead they are located in your Frida hooking code:</p> <p>When hooking an Java/Android method (or constructor) the Frida hook replaces the original function. So if you just want to log method/constructor calls you always have to manually execute the original method inside the hook.</p> <p>At the moment you don't call the original constructor of <code>RuntimeException</code> and return nothing, which means if Android tries to create an instance of <code>RuntimeException</code> no exception instance is created. This can never happen in compiled Java code and in the end the app crashes.</p> <p>Therefore you have to modify your hooking code to call the original constructor and return the created <code>RuntimeException</code> instance:</p> <pre><code>let RuntimeException = Java.use('java.lang.RuntimeException'); let RTctor1 = RuntimeException.$init.overload(); RTctor1.implementation = function() { console.log(&quot;hits .overload()&quot;); return RTctor1.call(this); } let RTctor2 = RuntimeException.$init.overload('java.lang.String'); RTctor2.implementation = function(arg0) { console.log(&quot;hits .overload('java.lang.String')&quot;); return RTctor2.call(this, arg0); } ... </code></pre>
32682
2024-01-31T12:35:59.180
<p>I tried to find out how <a href="https://developer.android.com/reference/java/lang/RuntimeException" rel="nofollow noreferrer">RuntimeException</a> works internally in <a href="https://cs.android.com/" rel="nofollow noreferrer">cs.android.com</a> so I can understand how to prevent crashes but didn't find anything useful and I have no clue how to analyze components-related JDK in perspective of reverse engineering, I'm curious what's going on behind <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html" rel="nofollow noreferrer">RuntimeException</a> so I can prevent crashes</p> <p>I tried with this Frida script but no luck</p> <pre class="lang-js prettyprint-override"><code>Java.perform(function() { var RuntimeException = Java.use('java.lang.RuntimeException'); RuntimeException.$init.overload().implementation = function(){ console.log(&quot;hits .overload()&quot;) return; } RuntimeException.$init.overload('java.lang.String').implementation = function(arg1){ console.log(&quot;hits .overload('java.lang.String')&quot;) return; } RuntimeException.$init.overload('java.lang.Throwable').implementation = function(arg1){ console.log(&quot;hits .overload('java.lang.Throwable')&quot;) return; } RuntimeException.$init.overload('java.lang.String', 'java.lang.Throwable').implementation = function(arg1,arg2){ console.log(&quot;hits .overload('java.lang.String', 'java.lang.Throwable')&quot;) return; } RuntimeException.$init.overload('java.lang.String', 'java.lang.Throwable', 'boolean', 'boolean').implementation = function(arg1,arg2,arg3,arg4){ console.log(&quot;hits .overload('java.lang.String', 'java.lang.Throwable', 'boolean', 'boolean')&quot;) return; } }) </code></pre>
How to hook RuntimeException to prevent crashes?
|android|java|frida|exception|
<p>This is most likely a &quot;wide character&quot;, <code>wchar_t[]</code> type.</p> <p>These are always 16 bits long and they are used to allow international characters and symbols that are at most 16 bit long, that is, the UTF-16 range.</p> <p>The fixed length allows faster processing than multibyte unicode.</p> <p>ASCII characters that could be encoded as 1 byte in multibyte unicode take up 2 bytes in widechar, which &quot;wastes&quot; an extra byte that is always null.</p>
32708
2024-02-06T23:53:51.377
<p>I've seen this multiple times, through various apps and snooping of hex values. Character strings but every other value is actually a null byte. This particular example is with API Monitor, but I'm almost positive I've seen it through hexdumps of Windows or DOS executables.</p> <p><a href="https://i.stack.imgur.com/aNwb4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aNwb4.png" alt="CreateFileW" /></a> <a href="https://i.stack.imgur.com/C4TPQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C4TPQ.png" alt="Raw data" /></a></p> <p>My first thought might be Unicode or some other sort of wide character standard. But Unicode formats (especially Uni16) are variable width.</p>
Why are these strings padded every other byte?
|disassembly|windows|executable|
<p>You don't need external tools. Mitmproxy since version 9 has <a href="https://mitmproxy.org/posts/wireguard-mode/" rel="nofollow noreferrer">built-in WireGuard support</a> which allows you to use the official <a href="https://play.google.com/store/apps/details?id=com.wireguard.android" rel="nofollow noreferrer">Wireguard VPN app</a> on Android side to forward all traffic to Mitmproxy running on your PC.</p> <p>You just have to start mitmproxy with in Wireguard mode:</p> <pre><code>mitmweb --mode wireguard </code></pre> <p>It will then display the connection info in text and as QR for easy set-up of the WireGurd connection profile.</p> <p>In rare cases where the computer running Mitmproxy doesn't know the correct IP address that should be used for the VPN server you may have to manually correct the WireGuard server IP in the installed VPN profile.</p>
32714
2024-02-08T17:51:08.280
<p>I want to capture packets from Android apps. I need an packets forwarder on phone that creates a VPN to redirect all TCP packets to PC, then capture them with 'mitmproxy'. I want to use mitmproxy because it supports python addons, and it's free/opensource.</p> <p>But I can't find a suitable packet forwarder. Here are what I've tried so far:</p> <ul> <li>Postern: sometimes it causes DNS error, I can't ping sites when it's enabled, unable to modify DNS server in settings, project abandoned.</li> <li>ProxyDroid: fails to resolve dns somehow</li> <li>TunProxy: http only, not support tcp</li> <li>burp, http_toolkit: non-free, not possible to save packets without paying</li> <li>HttpCanary/Reqable/PacketCapture/PCapDroid: doesn't collaborate with other apps like mitmproxy</li> </ul> <p>Any suggestion?</p>
Looking for a packet forwarder on Android that redirects all packets to PC
|android|packet|
<p>(reposting as an answer)</p> <p>IDA uses FLIRT signatures to try and identify known library functions.</p> <p>Functions found in this way would normally be marked as <em>library function</em>s and will be displayed in IDA disassembly with a different color.</p>
32715
2024-02-08T18:03:16.507
<p>I'm currently researching how a certain malware works and patches some stuff in a certain Android's library.</p> <p>Inspecting the library -which is stripped- in IDA I was able to get the symbol for a certain function in it, but I can't get it through any other means (like <code>objdump -T -t</code>, <code>nm</code>, <code>readelf</code>, and executing <code>strings</code> on the binary doesn't throw that string). I'm quite familiar with the ELF format, and so I made a simple ELF parser just to try something else, but obviously it wasn't able to find the symbol either.</p> <p>So now I just want to understand how IDA can get this symbol when it appears isn't contained in the binary. The only thing I can think of is that maybe IDA sees through other symbols the class this method belongs to and also the types of the arguments it receives, and thus can guess the symbol.</p>
Where is IDA getting this symbol?
|ida|c++|elf|symbols|
<p><strong>UPD.:</strong> I found it. It is indeed in Visual Studio Professional installation CD drive. <a href="https://i.stack.imgur.com/XGRJ7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XGRJ7.png" alt="source" /></a></p>
32741
2024-02-17T09:23:00.157
<p>I want to see MSVCRT's implementation details for the old Microsoft Visual Studio C++ 6.0 compiler. On newer Visual Studio versions, it is located in <code>/VC/crt/src/</code> directory, but there is no such directory for MSVC 6.0. Where can I find it?</p>
Where to find the Visual C++ 6.0 CRT Source Code?
|c++|msvc|
<p>After testing several methods, the easiest ended up being TitanHide.</p> <p>With TitanHide, setting only ThreadHideFromDebugger:</p> <p><a href="https://i.stack.imgur.com/VrwIg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VrwIg.png" alt="enter image description here" /></a></p> <p>And enabling my hook for isDebuggerPresent to return false always, I can breakpoint and debug the game normally.</p> <p>For PatchGuard I've used <a href="https://github.com/Mattiwatti/EfiGuard" rel="nofollow noreferrer">EfiGuard</a>.</p>
32750
2024-02-21T04:29:43.390
<p>I'm trying to debug a game and it's closing under few circumstances:</p> <ul> <li>When debugging (solved by hooking IsDebuggerPresent to return false when called by the game)</li> <li>When setting a memory/hardware breakpoint to see what reads/writes</li> </ul> <p>Testing with x64dbg and cheat engine, I'm getting the same results with both tools</p> <p>I can debug some functions and put breakpoints in opcodes to see the program workflow (for example IsDebuggerPresent, I can set a breakpoint there and step in) but I'm not sure if I can do it everywhere</p> <p>The final goal is learning to identify functions by checking what reads/writes on values</p> <p>Here are all breakpoints I've checked without results, the game closes directly:</p> <p><a href="https://i.stack.imgur.com/aIyBM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aIyBM.png" alt="enter image description here" /></a></p> <p>Should I trace who is closing the game to disable it? Or should I debug it differently? If I have to trace, how can I do that if it doesn't hit the breakpoints when closing?</p>
How can I debug if the program closes directly?
|debugging|c++|x64dbg|cheat-engine|
<p>The debugger/CPU doesn't have a feature to break when it notices a particular opcode byte sequence. Ahead of time, you can scan the memory range you're interested in, then set a software breakpoint on all those particular spots. You can use the 'findall' or 'findasm' scripting command to add a breakpoint, or take some other action for each of those addresses. There's also a tracing feature that single-steps through the execution. It'll be slower since you're breaking constantly. You can log and filter on that trace.</p>
32765
2024-02-25T13:34:22.333
<p>Is there any way to break on specific opcode in X64DBG? For example i want to break on start of a function which is</p> <p>55 | push ebp</p> <p>8BEC | mov ebp,esp</p> <p>can i set a breakpoint like opcode == 0x00EC8B55? Also is there any way to break only on certain memory range?</p>
X64DBG Conditional Breakpoint on Specific Opcode?
|assembly|malware|x64dbg|unpacking|
<p><strong>Solved by changing the signature:</strong></p> <pre><code>typedef std::string*(__thiscall* _readFileContents)(DWORD* _resourceManager, std::string* buffer, std::string&amp; fileName, bool safe); </code></pre>
32772
2024-02-28T08:55:53.460
<p>I'm hooking a function that reads and decrypt files and my idea is to read the buffer once it's decrypted:</p> <pre><code>typedef void(__thiscall* _readFileContents)(DWORD* _resourceManager, std::string* buffer, std::string&amp; fileName, bool safe); _readFileContents original_readFileContents; DWORD gateway_readFileContents; void __fastcall readFileContents_hook(DWORD* _resourceManager, void* /*ecx*/, std::string* buffer, std::string&amp; fileName, bool safe) { std::cout &lt;&lt; &quot;[&quot; &lt;&lt; safe &lt;&lt; &quot;] readFileContents_hook: &quot; &lt;&lt; fileName &lt;&lt; std::endl; ((_readFileContents)gateway_readFileContents)(_resourceManager, buffer, fileName, safe); std::string combinedContent; for (size_t i = 0; i &lt; buffer-&gt;size(); ++i) { combinedContent.push_back(buffer-&gt;at(i)); } return ((_readFileContents)gateway_readFileContents)(_resourceManager, buffer, fileName, safe); // same results with return; only } original_readFileContents = (_readFileContents)(moduleBase + 0x12345); gateway_readFileContents = (DWORD)TrampHook32((char*)original_readFileContents, (char*)readFileContents_hook, 6); </code></pre> <p>The problem, is that whenever I touch the <strong>buffer</strong> variable, I get a wonderful crash :)</p> <p>But, I've found an exception! I can get the size() without issues:</p> <pre><code>std::cout &lt;&lt; &quot;Buffer size with size(): &quot; &lt;&lt; buffer-&gt;size() &lt;&lt; std::endl; </code></pre> <p><a href="https://i.stack.imgur.com/9X2jf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9X2jf.png" alt="enter image description here" /></a></p> <p>So, how can I read the data without crashing?</p> <p>PS: This is the original code (it's open source and I'm using it for learning purposes):</p> <pre><code>std::string ResourceManager::readFileContents(const std::string&amp; fileName, bool safe) { std::string fullPath = resolvePath(fileName); if (fullPath.find(&quot;/downloads&quot;) != std::string::npos) { auto dfile = g_http.getFile(fullPath.substr(10)); if (dfile) return std::string(dfile-&gt;response.begin(), dfile-&gt;response.end()); } PHYSFS_File* file = PHYSFS_openRead(fullPath.c_str()); if(!file) stdext::throw_exception(stdext::format(&quot;unable to open file '%s': %s&quot;, fullPath, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()))); int fileSize = PHYSFS_fileLength(file); std::string buffer(fileSize, 0); PHYSFS_readBytes(file, (void*)&amp;buffer[0], fileSize); PHYSFS_close(file); if (safe) { return buffer; } // skip decryption for bot configs if (fullPath.find(&quot;/bot/&quot;) != std::string::npos) { return buffer; } static std::string unencryptedExtensions[] = { &quot;.otml&quot;, &quot;.otmm&quot;, &quot;.dmp&quot;, &quot;.log&quot;, &quot;.txt&quot;, &quot;.dll&quot;, &quot;.exe&quot;, &quot;.zip&quot; }; if (!decryptBuffer(buffer)) { bool ignore = (m_customEncryption == 0); for (auto&amp; it : unencryptedExtensions) { if (fileName.find(it) == fileName.size() - it.size()) { ignore = true; } } if(!ignore) g_logger.fatal(stdext::format(&quot;unable to decrypt file: %s&quot;, fullPath)); } return buffer; } </code></pre>
Hook: can call string::size() but crashing when reading string data... how to read without crash?
|c++|function-hooking|strings|
<p>Signextend is expanding an integer of some size into a larger size and filling the extra bits with the original sign bit. In other words - keeping the larger int positive/negative.</p> <p>Example:</p> <p>An original 8-bit number <code>0x7F</code> (Binary <code>01111111</code>) signextended to 32 bit becomes <code>0x0000007F</code>.</p> <p>An original 8-bit number <code>0x80</code> (Binary <code>10000000</code>) signextended to 32 bit becomes <code>0xFFFFFF80</code></p> <p>It makes sense using this operation in offsets as a relative offset can be negative.</p>
32792
2024-03-07T06:36:55.520
<p>I’m writing a C-SKY (CK803S) processor module for IDA Pro, and a question arose about offsets in transitions, small ones are fine, but long ones lead to nowhere, from the documentation: <a href="https://i.stack.imgur.com/CYqWE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CYqWE.jpg" alt="enter image description here" /></a></p> <p>in code I implemented it like this:<code>insn.Op1.addr = insn.ea + (((code32 &amp; 0x3FFFFFF) &lt;&lt; 1) &amp; 0x3FFFFFF);</code></p> <p><a href="https://i.stack.imgur.com/slbDk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/slbDk.jpg" alt="enter image description here" /></a></p> <p>but I don’t understand what sign_extend does ?</p>
Offset addressing
|ida|disassembly|assembly|debugging|binary-analysis|
<p>Some general steps that might help you in your process are:</p> <ol> <li>Taking the unit apart and looking up the datasheet for each IC from the ports to the CPU.</li> <li>If the above doesn't work, try googling the unit to see if the protocol is documented somewhere or if someone has already reverse engineered it.</li> <li>Attach a debugger to the process or use a scope that has decode options built into it, like the SDS1202X, to capture the serial data.</li> <li>Play around with the baud rates until legitimate data packets are sent.</li> <li>Use a program that virtualizes a COM port and displays the exchanged data to decode the functions.</li> <li>Write a program to automate control.</li> </ol> <p>Moreover, here are some websites you might find useful:</p> <ul> <li>Hackaday: a story about reverse engineering a wirelessly controlled adjustable bed. It involves a lot of technical details on how the process was carried out.</li> <li>Hackster.io: a story about bypassing the razor-and-blades business model of the Cat Genie automated litter box by reverse engineering its soap cartridge.</li> </ul> <p>Additionally, some tools you might find helpful are:</p> <ul> <li>ChipWhisperer: a breakthrough in hobbyist use of power analysis and glitching attacks on embedded hardware. It has IDC and SMA sockets for connecting custom breakouts housing a chip you're probing.</li> <li>HackRF: a tool used for controlling a toy RC car by reverse engineering its wireless control protocol.</li> <li>RTL-SDR: a tool used for reverse engineering wirelessly controlled adjustable beds and garage door openers.</li> </ul>
32803
2024-03-13T02:31:18.690
<p>I Have an ultrasonic machine that has a cartridge with a set amount of uses. When that value gets to 0, the cartridge has to be disposed, and a new one bought. The thing is that with some maintenance before the cartridge runs out of uses, it's possible to prevent it from being damaged, and it's life can be extended (I don't know how true this is, I was just asked to believe).</p> <p>So far, I was able to find that the cartridge uses an STC uC (<a href="https://github.com/grigorig/stcgal/issues/7" rel="nofollow noreferrer">100% impossible to read back</a>), and that it's using UART at 19200bps. That's all I know, and I certainly can read the communication with the machine and the cartridge, so I think all the other things are OK. I was even able to replicate the cartridge with my computer, by re-sending recorded messages using docklight.</p> <p>The thing now is that I can't figure out what is what on the communication. Here is a selected and filtered communication between both devices:</p> <pre><code>CART - FB 05 01 03 86 00 8E BF // 20100 uses left MACH + FB 03 85 95 A8 BF // subtract 1 use CART - FB 05 01 03 85 95 53 BF // 20099 uses left MACH + FB 03 85 94 AF BF // subtract 1 use CART - FB 05 01 03 85 94 54 BF // 20098 uses left MACH + FB 03 85 93 BA BF // subtract 1 use CART - FB 05 01 03 85 93 41 BF // 20097 uses left MACH + FB 03 85 92 BD BF // subtract 1 use CART - FB 05 01 03 85 92 46 BF // 20096 uses left MACH + FB 03 85 91 B4 BF // subtract 1 use CART - FB 05 01 03 85 91 4F BF // 20095 uses left MACH + FB 03 85 90 B3 BF // subtract 1 use CART - FB 05 01 03 85 90 48 BF // 20094 uses left MACH + FB 03 85 8F EE BF // subtract 1 use CART - FB 05 01 03 85 8F 15 BF // 20093 uses left MACH + FB 03 85 8E E9 BF // subtract 1 use CART - FB 05 01 03 85 8E 12 BF // 20092 uses left MACH + FB 03 85 8D E0 BF // subtract 1 use CART - FB 05 01 03 85 8D 1B BF // 20091 uses left MACH + FB 03 85 8C E7 BF // subtract 1 use CART - FB 05 01 03 85 8C 1C BF // 20090 uses left MACH + FB 03 85 8B F2 BF // subtract 1 use CART - FB 05 01 03 85 8B 09 BF // 20089 uses left MACH + FB 03 85 8A F5 BF // subtract 1 use CART - FB 05 01 03 85 8A 0E BF // 20088 uses left MACH + FB 03 85 89 FC BF // subtract 1 use CART - FB 05 01 03 85 89 07 BF // 20087 uses left MACH + FB 03 85 88 FB BF // subtract 1 use CART - FB 05 01 03 85 88 00 BF // 20086 uses left MACH + FB 03 85 87 D6 BF // subtract 1 use CART - FB 05 01 03 85 87 2D BF // 20085 uses left MACH + FB 03 85 86 D1 BF // subtract 1 use CART - FB 05 01 03 85 86 2A BF // 20084 uses left MACH + FB 03 85 85 D8 BF // subtract 1 use CART - FB 05 01 03 85 85 23 BF // 20083 uses left MACH + FB 03 85 84 DF BF // subtract 1 use CART - FB 05 01 03 85 84 24 BF // 20082 uses left MACH + FB 03 85 83 CA BF // subtract 1 use CART - FB 05 01 03 85 83 31 BF // 20081 uses left MACH + FB 03 85 82 CD BF // subtract 1 use CART - FB 05 01 03 85 82 36 BF // 20080 uses left </code></pre> <p>Some things to note:</p> <ul> <li>after the cartridge (CART) sends its byte stream (which I call &quot;Identification&quot; string), it stays on &quot;idle&quot;, sending 00s every 750ms, waiting for the machine to talk to it.</li> <li>the ID string is only sent once, and only when the cartridge gets power, never again until power goes out. for the tests, I always turned the machine on, did one trigger (subtract one use) and turned it off.</li> <li>the machine reads the remaining uses of the cartridge by the ID string. It never verifies if the chip wrote the data to its internal eeprom or wherever it has to be written.</li> <li>there are some prior init messages that have nothing to do with what I want to do</li> <li>after the machine (MACH) sends its &quot;Subtract&quot; command, the cartridge responds with sort of an acknowledge, before the machine sends again the same command, and the cartridge responds again, before going into &quot;idle&quot; mode</li> </ul> <p>So far, I think this is how things go:</p> <p>for everything: <code>FB</code> opens the communication and <code>BF</code> closes it.</p> <p>for the Identificacion string:</p> <ul> <li><code>05 01 03</code> is probably some kind of identification string (I'm still in doubt about the <code>03</code>), the machine is supposed to support different types of cartridges.</li> <li>the next two bytes are probably the uses number, but I cant figure out how to obtain an actual decimal number that is equal to the one I know (I can see it on the machine panel).</li> <li>I believe that the next bit is some kind of checksum, but I don't know which one.</li> </ul> <p>for the Subtract command:</p> <ul> <li><code>03</code>, I don't really know. It can be part of the number of uses, but I'm not sure. I can't get the cartridge to go to 0.</li> <li>the next two bytes are, again, the number of uses left, or part of it.</li> <li>the next byte, again, could be a checksum, but don't know what.</li> </ul> <p>That's where I'm currently sitting. I would like to know if there is some kind of program or website that could help me figure out if the supposedly &quot;checksum&quot; byte, is actually a checksum or not, and also figure out what operation is done to the number to convert it to those two or three bytes before the checksum</p>
Reverse Engineer an ultrasonic cartridge communication with the station to bypass remaining uses
|serial-communication|protocol|checksum|
<p><code>x/d</code> reads the value starting at some address and display it as decimal.</p> <p>If you don't specify a size, <code>x</code> will use the default or the last size used.</p> <p>Your first <code>x/d</code> reads the default size - a word (typically 4-bytes).</p> <p>Then <code>x/s</code> reads a string, that is <em>1</em> string.</p> <p>The last <code>x/d</code> then reads one byte, as <em>1</em> was the last size used.</p> <p>To avoid this, specify a size for the command:</p> <p>For example: <code>x/wd</code> will read a word-sized value as decimal and <code>x/bx</code> will read one byte value as hex.</p> <p>Numeric notation is also accepted:</p> <p><code>x/8bx</code> will read 8 bytes as hex.</p>
32812
2024-03-17T13:13:51.163
<p>I have run the following commands at a breakpoint in gdb and I don't understand how the x/d $rdx commands returns two different values, one before and one after x/s $rdx is executed. To my understanding x is just for reading values?</p> <pre><code>(gdb) x/d $rdx 0x555555559180: -6681 (gdb) x/s $rdx 0x555555559180: &quot;\347\345\377\377\221\345\377\377\261\345\377\377\270\345\377\377\277\345\377\377\306\345\377\377\315\345\377\377\324\345\377\377\002&quot; (gdb) x/d $rdx 0x555555559180: -25 </code></pre> <p>I guess it's more likely I'm misunderstanding something in terms of the x command and how it works so any info on that would be really helpful.</p>
Why does the value stored in a register change after an x/s call? (GDB)
|gdb|
<p>The problem is that Ghidra for whatever reason cannot determine what the actual target of this call is. This might just be a limitation of the C++ support in Ghidra. There are plugins that try to support this better:</p> <ul> <li><a href="https://github.com/astrelsky/Ghidra-Cpp-Class-Analyzer" rel="nofollow noreferrer">https://github.com/astrelsky/Ghidra-Cpp-Class-Analyzer</a></li> <li><a href="https://insights.sei.cmu.edu/blog/using-ooanalyzer-to-reverse-engineer-object-oriented-code-with-ghidra/" rel="nofollow noreferrer">https://insights.sei.cmu.edu/blog/using-ooanalyzer-to-reverse-engineer-object-oriented-code-with-ghidra/</a></li> </ul> <p>but you can also do this manually if you already know the target function via manual reverse engineering:</p> <pre class="lang-py prettyprint-override"><code>ref = program.referenceManager.addMemoryReference( callsite, # FROM, the address of the call instruction func_address, //TO, the address of the function being called RefType.UNCONDITIONAL_CALL, SourceType.USER_DEFINED, 0) program.referenceManager.setPrimary(ref, true) </code></pre>
32837
2024-03-25T19:48:46.193
<p><a href="https://i.stack.imgur.com/ZeAXk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZeAXk.png" alt="enter image description here" /></a></p> <p>On lines 67, 70 and 77 ghidra makes a call to what I assume is a member function, but it does not show me which member function. Why is that?</p> <p>Example from line 70:</p> <p>(**(code **)(*(longlong *)metaStream + 0xd8))(metaStream)</p> <p>Call in assembly:</p> <p>qword ptr [RAX + 0xd8]</p> <p>How can I make ghidra show me which function is being called?</p>
Ghidra not displaying member function call
|ghidra|pe|
<p>This is an industrial type <code>ITT Cannon KPT01E12-10S</code>, like this one:</p> <p><a href="https://www.westfloridacomponents.com/C069APP10/KPT01E12-10S+10+Pos.+Circular+Connector+Receptacle+ITT+Cannon.html" rel="nofollow noreferrer">https://www.westfloridacomponents.com/C069APP10/KPT01E12-10S+10+Pos.+Circular+Connector+Receptacle+ITT+Cannon.html</a></p> <p>This connector is used for CAN bus communication, which can be used for diagnostics, among other applications.</p>
32845
2024-03-28T19:32:04.797
<p>Does anybody know this kind of connector? It is used as a diagnostic connector on diesel engines. Inner diameter 15mm, outer 19mm.</p> <p><a href="https://i.stack.imgur.com/SLTqc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SLTqc.jpg" alt="Female socket" /></a></p>
What's this connector type?
|hardware|
null
32852
2024-03-30T03:43:20.430
<p>I've been attempting to dive into mediaserverd which runs on iOS. Pulling the binary and running <code>otool -L</code> on it reveals, unsurprisingly, that it's linked against <code>/System/Library/Frameworks/CoreMedia.framework/CoreMedia</code>. However, that directory on the phone doesn't have any file called <code>CoreMedia</code>. In fact, all it has are two <code>.plist</code> files and some text file called <code>CodeResources</code>.</p> <p>Where is the actual Mach-O file for the CoreMedia framework?</p>
Location of CoreMedia framework
|ios|
<p>You can use any binary dynamic instrumentation framework (like Intel pin, Frida, etc.)</p> <p><a href="https://github.com/SideChannelMarvels/Tracer/blob/master/TracerPIN/README.md" rel="nofollow noreferrer">https://github.com/SideChannelMarvels/Tracer/blob/master/TracerPIN/README.md</a></p> <p><a href="https://frida.re/docs/frida-trace/" rel="nofollow noreferrer">https://frida.re/docs/frida-trace/</a></p>
32853
2024-03-30T16:50:16.293
<p>I would like to alter the behavior of some executable (in my case, a videogame). One way of doing this is to hook function calls (e.g., a function like <code>Player::ReceiveDamage</code>) and adjust parameters/return values.</p> <p>I know how to inject code and how to hook functions. <strong>The challenge currently is to <em>find</em> the address of the function of interest</strong>. The source code of the target is not available, neither are debug symbols.</p> <p>An approach I successfully used before is the following:</p> <ol> <li>Find all function addresses in the target executable (e.g., with IDA, radare2, Pyew, ...)</li> <li>With the executable running, hook all functions</li> <li>Black-list (and un-hook) functions that are called during moments that are not of interest</li> <li>White-list functions that are called during moments of interest</li> <li>Repeat steps (4,5) until function list is narrowed down sufficiently</li> </ol> <p>Unfortunately, I have misplaced the code I was using for this process. I can re-write it, but I noticed that there is already an <a href="https://www.capstone-engine.org/showcase.html" rel="nofollow noreferrer">enormous offering of tools and libraries</a> that may do exactly what I need.</p> <p>Performance is a challenge: logging all function calls in a videogame introduces significant overhead. I noticed previously that it would take some time for my old tool to black-list enough irrelevant functions for the target to become responsive. This likely makes <a href="https://frida.re/" rel="nofollow noreferrer">Frida</a> not a good choice, as it injects javascript.</p> <p><strong>Does anyone know of a <em>performant</em> tool/library, supporting Windows and x64, that I can use to find functions of interest in a target executable?</strong></p>
Tracing all functions in executable conditionally, to find function of interest
|pe|tools|dynamic-analysis|functions|tracing|