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>It turned out, that in order to call <code>system</code> the stack has to be 16-byte aligned.</p>
30200
2022-03-30T07:02:32.233
<br> in oder to solve a CTF-Challenge I have to construct a small ROP-chain. The scope of the ROP chain is to print the content of the `flag` file. I already constructed the ROP-chain, but it seems that when I call the system function with the parameter `cat flag`, the result isn't printed to the console. <p>My ROP-chain: <code>payload = b'A'*80 + pop_rdi + addr_cat_flag + systemPlt</code></p> <p>As far as I know it should work this way, since it is a 64-Bit machine. But the strangest thing is that when insted of calling <code>system</code> I call for example <code>puts</code> then the content at address addr_cat_flag, which in this case is <code>cat flag</code>, is printed to the console. This means that the parameter is hand over corectly.<br> The address of systemPlt should also be correct.</p> <p>Does anybody know were the problem could be?</p>
ROP: System function not printing results to stdout
|binary-analysis|gdb|system-call|rop|pwntools|
<p>A simple problem I see in your code is</p> <pre><code>state.regs.rax = 0x100000 </code></pre> <p>if you need to set constraint on a function argument - you 'll need to follow the calling convention. On my machine - Ubuntu Linux - the calling convention says first arg to be present in <code>rdi</code></p> <p>so by merely changing it to</p> <pre><code>state.regs.rdi = 0x100000 </code></pre> <p>I see this as output</p> <pre><code>&lt;SimState @ &lt;BV64 mem_7ffffffffff0000_6980_64{UNINITIALIZED}&gt;&gt; : 0x4006ed b'A\x00\...' &lt;SimState @ &lt;BV64 mem_7ffffffffff0000_6981_64{UNINITIALIZED}&gt;&gt; : 0x4006ed b'B\x00\...' &lt;SimState @ &lt;BV64 mem_7ffffffffff0000_6982_64{UNINITIALIZED}&gt;&gt; : 0x4006ed b'\x80\x80...' </code></pre> <p>Which matches correctly with what the code does.</p>
30224
2022-04-05T01:58:47.813
<p>I have a binary compiled for x86_64 that looks like this:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; void options(char *input) { if (strcmp(input, &quot;A&quot;) == 0) { printf(&quot;You picked 'A'\n&quot;); } else if (strcmp(input, &quot;B&quot;) == 0) { printf(&quot;You picked 'B'\n&quot;); } else { printf(&quot;You picked something That wasn't 'A' or 'B'\n&quot;); } return; } int main(int argc, char **argv) { options(&quot;Z&quot;); return 0; } </code></pre> <p>It has been compiled with the following command:</p> <pre><code>gcc main.c -static -o demo </code></pre> <p>I would now like to use angr to find inputs for as much code coverage as possible. The desired outputs are <code>A</code>, <code>B</code>, and something similar to <code>Anything</code>.</p> <p>This article (<a href="https://breaking-bits.gitbook.io/breaking-bits/vulnerability-discovery/reverse-engineering/modern-approaches-toward-embedded-research" rel="nofollow noreferrer">https://breaking-bits.gitbook.io/breaking-bits/vulnerability-discovery/reverse-engineering/modern-approaches-toward-embedded-research</a>) shows that its possible to do something like this. I've had success with this technique from time to time, but often I'm left with no inputs generated. The following example is based off of the example given in the link. It is the script I am using to attempt to generate inputs:</p> <pre><code>#! /usr/bin/env python3 import angr import angr.sim_options as so import claripy import sys sys.setrecursionlimit(15000) symbol = &quot;options&quot; # Create a project with history tracking p = angr.Project('/home/user/Documents/demo') extras = {so.REVERSE_MEMORY_NAME_MAP, so.TRACK_ACTION_HISTORY} # User input will be 200 symbolic bytes user_arg = claripy.BVS(&quot;user_arg&quot;, 200*8) # State starts at function address start_addr = p.loader.find_symbol(symbol).rebased_addr state = p.factory.blank_state(addr=start_addr, add_options=extras) # Store symbolic user_input buffer state.memory.store(0x100000, user_arg) state.regs.rax = 0x100000 # Run to exhaustion simgr = p.factory.simgr(state) # Exploration technique to prevent infinite loops simgr.use_technique(angr.exploration_techniques.LoopSeer(bound=50)) simgr.explore() i = 0; # Print each path and the inputs required for path in simgr.unconstrained: print(&quot;{} : {}&quot;.format(path,hex([x for x in path.history.bbl_addrs][-1]))) u_input = path.solver.eval(user_arg, cast_to=bytes) print(u_input) with open('corpus/output'+str(i)+'.bin', 'wb') as file: file.write(u_input) i = i + 1 </code></pre> <p>The main differences from the article are that this script is to be used for an x86_64 binary (register changed), and discovered inputs are saved to files.</p> <p>When I run the script, I get a handful of errors and warnings:</p> <pre><code>WARNING | 2022-04-04 20:23:59,667 | claripy.vsa.strided_interval | Tried to cast_low an interval to an interval shorter than its stride. ERROR | 2022-04-04 20:23:59,703 | angr.analyses.cfg.indirect_jump_resolvers.jumptable.JumpTableProcessor | Unsupported Binop Iop_InterleaveHI64x2. ... WARNING | 2022-04-04 20:24:03,531 | claripy.vsa.strided_interval | Tried to cast_low an interval to an interval shorter than its stride. ... ERROR | 2022-04-04 20:24:05,909 | angr.analyses.cfg.cfg_fast | Decoding error occurred at address 0x428b82 of function 0x426e20. ... WARNING | 2022-04-04 20:24:26,416 | angr.analyses.loopfinder | Bad loop: more than one entry point (&lt;BlockNode at 0x46a2d0 (size 19)&gt;, &lt;BlockNode at 0x46a2f4 (size 15)&gt;) </code></pre> <p>I can provide the full output, but it is rather long and will exceed the post length limit.</p> <p>When the script finished, it provides no unconstrained outputs. This is the approach I thought I should have taken based on the article I read. This could be the wrong approach entirely, but I'll boil it down to one question. What can one do to generate a list of inputs that provide maximum coverage using angr?</p>
How can valid inputs be generated using the simulation manager in angr?
|angr|
<p>E9 is jump relative</p> <p>it jumps to an address relative to the next instruction address</p> <p>E9 is a five byte sequence 1 byte for opcode and 4 byte for calculating the relative location</p> <p>assume you are at address 0x1000 the next instruction will start at 0x1005</p> <p>the jump location is calculated by adding 0x1005 with the constant in the current instruction</p> <p>in your case the constant is DC622600 or 0x002662dc adding 5 makes it 0x002662E1</p> <p>this is the address it will jump to which in your case happens to be 0x00690000</p> <p>so current instruction address must be 0x690000-0x2662e1</p> <p>which is '0x429d1f'</p> <pre><code>&gt;&gt;&gt; ip = 0x429d1f &gt;&gt;&gt; len = 5 &gt;&gt;&gt; nextaddress=ip+len &gt;&gt;&gt; jmpconst = 0x2662dc &gt;&gt;&gt; jmploc = nextaddress+jmpconst &gt;&gt;&gt; print(&quot;%x %x %x %x %x\n&quot; % (ip,len,nextaddress,jmpconst,jmploc)) 429d1f 5 429d24 2662dc 690000 </code></pre>
30225
2022-04-05T05:38:17.130
<p>I'm very new to all this, so sorry if I mess up and/or am unclear. I'm working on reverse engineering assault cube, where a lot of people start, and I'm struggling to understand how this one AOB injection works. In order to make this more universal, I'll try to omit specific things about assault cube. This is all in x86 32-bit, and I'm on Windows 64-bit.</p> <p>My goal is to replace 5 bytes at the address of <code>ac_client.exe</code> (base address) + 29D1F (&lt;-00429D1F) to a jmp instruction to a function that I dynamically allocated in C++. cheat engine shows that in their AOB injection version, the bytes at that address become E9 DC622600, and they label it as jmp 00690000. Following that, at the code at address 00690000, there's another jmp instruction later to return control. these instructions bytes are E9 189DD9FF and its labeled jmp ac_client.exe+29D24 (&lt;- 00429D22, the address of the instruction after the one it replaced). In short, I'll need to be able to inject the compiled bytes of a jump instruction to a specific memory address into memory during runtime.</p> <p>So, in trying to replicate that, I have not been able to draw a link between the bytes and the addresses they represent (DC622600 : 00690000, 189DD9FF : 00429D1F). I have tried big endian, small endian, octals, hex ofc, absolute vs relative, and I can't find anything. I've also tried reassembling and dissembling all of these values / instructions with <a href="https://defuse.ca/online-x86-assembler.htm#disassembly" rel="nofollow noreferrer">https://defuse.ca/online-x86-assembler.htm#disassembly</a> and cannot find a link. If any of you may know what I'm doing wrong, I would hugely appreciate any help, and if you need any more info, I'm on it! Thanks a ton!</p>
Relationship between compiled bytes of jmp instruction and target memory address
|disassembly|x86|c++|reassembly|cheat-engine|
<p>Based on your screenshots (as already mentioned in comments) - references to <code>mono</code> and <code>xamarin</code> help us understand that the apk is probably built with .NET. In this method the code is probably written as C# and then compiled to DLLs depending on what classes you use in the code.</p> <p>See : <a href="https://github.com/xamarin/xamarin-android" rel="nofollow noreferrer">https://github.com/xamarin/xamarin-android</a> for more details on this.</p> <p>A simple unzip will confirm that too.</p> <pre><code>$ unzip ../Sun.apk -d . ... assemblies/xxx.dll ... </code></pre> <p>Now most of the static analysis can be based on decompiling .NET dlls which can be done using something like <a href="https://github.com/icsharpcode/ILSpy" rel="nofollow noreferrer">ILSpy</a>.</p> <p>Looking at the type of dlls</p> <pre><code>$ file assemblies/xxx.dll assemblies/xxx.dll : data </code></pre> <p>The dlls are actually compressed with lz4 based on this <a href="https://github.com/xamarin/xamarin-android/pull/4686" rel="nofollow noreferrer">PR</a> and then can be uncompressed using a <a href="https://github.com/x41sec/tools/blob/master/Mobile/Xamarin/Xamarin_XALZ_decompress.py" rel="nofollow noreferrer">script</a></p> <pre><code>$ find . -type f -name &quot;*.dll&quot; -exec mv {} {}.lz4 \; $ find . -type f -name &quot;*.lz4&quot; -exec python Xamarin_XALZ_decompress.py {} {}.dll \; </code></pre> <p>Now ILSpy can load and decompile these DLLs. Based on the ciphertext you provide it looks like a block cipher such as AES. Look around for that in the decompiled code in <code>Sundirect.dll</code> We find this snippet in <code>Sundirect.Services</code></p> <pre><code>using System; using System.Security.Cryptography; using System.Text; public static string Encrypt(string inputText, string encryptionKey) { UTF8Encoding uTF8Encoding = new UTF8Encoding(); RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Mode = CipherMode.CBC; rijndaelManaged.Padding = PaddingMode.PKCS7; rijndaelManaged.KeySize = 128; rijndaelManaged.BlockSize = 128; byte[] bytes = Encoding.UTF8.GetBytes(encryptionKey); byte[] array = new byte[16]; int num = bytes.Length; if (num &gt; array.Length) { num = array.Length; } Array.Copy(bytes, array, num); rijndaelManaged.Key = array; rijndaelManaged.IV = array; string result = Convert.ToBase64String(rijndaelManaged.CreateEncryptor().TransformFinalBlock(uTF8Encoding.GetBytes(inputText), 0, uTF8Encoding.GetBytes(inputText).Length)); rijndaelManaged.Dispose(); return result; } </code></pre> <p>Right Click -&gt; Analyze to see what code uses this function and we see that is is used to encrypt post data</p> <pre><code>... Sundirect.Services.LoginAPIServices.LoginAync(string, string) : Task&lt;LoginDetailsOutputDto&gt; Sundirect.Services.LoginAPIServices.GetUserPasswordAsync(string) : Task&lt;UserPasswordDto&gt; ... </code></pre> <p>Click and browse to that location and you see that the key to encrypt is hardcoded</p> <pre><code>... string value2 = BaseServices.Encrypt(input, &quot;419201ddtuz3082249879134d06093b95991g6f70d&quot;); ... </code></pre> <p>This can help us write a simple decryptor like this</p> <pre><code>using System.Diagnostics; using System.Security.Cryptography; using System.Text; public class Test { public static string Encrypt(string inputText, string encryptionKey) { UTF8Encoding uTF8Encoding = new UTF8Encoding(); Aes? rijndaelManaged = Aes.Create(&quot;AesManaged&quot;); rijndaelManaged.Mode = CipherMode.CBC; rijndaelManaged.Padding = PaddingMode.PKCS7; rijndaelManaged.KeySize = 128; rijndaelManaged.BlockSize = 128; byte[] bytes = Encoding.UTF8.GetBytes(encryptionKey); byte[] array = new byte[16]; int num = bytes.Length; if (num &gt; array.Length) { num = array.Length; } Array.Copy (bytes, array, num); rijndaelManaged.Key = array; rijndaelManaged.IV = array; string result = Convert .ToBase64String(rijndaelManaged .CreateEncryptor() .TransformFinalBlock(uTF8Encoding.GetBytes(inputText), 0, uTF8Encoding.GetBytes(inputText).Length)); rijndaelManaged.Dispose(); return result; } public static string Decrypt(string inputText, string encryptionKey) { UTF8Encoding uTF8Encoding = new UTF8Encoding(); Aes? rijndaelManaged = Aes.Create(&quot;AesManaged&quot;); rijndaelManaged.Mode = CipherMode.CBC; rijndaelManaged.Padding = PaddingMode.PKCS7; rijndaelManaged.KeySize = 128; rijndaelManaged.BlockSize = 128; byte[] bytes = Encoding.UTF8.GetBytes(encryptionKey); byte[] array = new byte[16]; int num = bytes.Length; if (num &gt; array.Length) { num = array.Length; } Array.Copy (bytes, array, num); rijndaelManaged.Key = array; rijndaelManaged.IV = array; byte[] b64 = Convert.FromBase64String(inputText); string result = System.Text.Encoding.UTF8.GetString(rijndaelManaged .CreateDecryptor() .TransformFinalBlock(b64, 0, b64.Length)); rijndaelManaged.Dispose(); return result; } public static void Main() { string key = &quot;419201ddtuz3082249879134d06093b95991g6f70d&quot;; string e = Decrypt(Encrypt(&quot;input&quot;, key), key); Debug.Assert(e==&quot;input&quot;); Console.WriteLine(Decrypt(&quot;vpEz/Vm8Yi9v5/fzNE+MDoMIQGZ0vNvjPuX8UNAi26c=&quot;, key)); } } </code></pre> <p>which on running decrypts</p> <pre><code>&quot;vpEz/Vm8Yi9v5/fzNE+MDoMIQGZ0vNvjPuX8UNAi26c=&quot; </code></pre> <p>to</p> <pre><code>CR-13261150|03|2022-04-04 22:40 </code></pre>
30230
2022-04-05T19:55:06.317
<p>When I submit a Customer Reference ID in an Android Application it POSTs an encrypted string to an API endpoint.</p> <p>For example, if I enter the following CR ID :</p> <p>&quot;SR-54585482&quot;</p> <p>it POSTs the following Encrypted Data:</p> <pre><code>splainText : &quot;vpEz/Vm8Yi9v5/fzNE+MDoMIQGZ0vNvjPuX8UNAi26c=&quot; Count : 31 </code></pre> <p>How do I find the encryption algorithm in the source code of the APK?</p> <p>In which file can I find about this encryption?</p> <p>Dex2Jar File here : <a href="https://www.mediafire.com/file/hs0qyirhuk4ygo8/test-dex2jar.jar/file" rel="nofollow noreferrer">https://www.mediafire.com/file/hs0qyirhuk4ygo8/test-dex2jar.jar/file</a></p> <p>APK from here : <a href="https://play.google.com/store/apps/details?id=com.sundirect.sundth" rel="nofollow noreferrer">https://play.google.com/store/apps/details?id=com.sundirect.sundth</a></p>
Where can I find the encryption algorithm in source code?
|encryption|android|java|
<p>TLDR: In radare2, while debugging, you use <code>dr &lt;register&gt;=&lt;val&gt;</code></p> <p>Use the -d flag to begin Radare2 in debugging mode</p> <pre><code>r2 -d /usr/bin </code></pre> <p>You'll have a prompt in front of you, type v and then p a few times to get to the debugging view.</p> <p>Press colon to enter commands. You'll most likely want to analyze the binary. To do this, press colon and then <code>aaa</code> or <code>aa</code>. Note, that <code>aaa</code> does could take more time, but does performs a more in-depth analysis.</p> <p>Once in debugging mode, use db [address] to set a breakpoint. For example, to set a breakpoint at main</p> <pre><code>db main </code></pre> <p>And you can get to main, enter <code>s main</code>. This jumps to main (s is for seek).</p> <p>Then, if you want to change the register <code>rdi</code></p> <pre><code>dr rdi=0x20 </code></pre> <p>For more register options, see: <a href="https://r2wiki.readthedocs.io/en/latest/options/d/dr/" rel="nofollow noreferrer">https://r2wiki.readthedocs.io/en/latest/options/d/dr/</a></p>
30232
2022-04-06T03:14:59.173
<p>I would really like to change the registers during radare2's debugging sessiong. In GDB,</p> <pre><code>set $reg 0x2020 </code></pre> <p>was very useful.</p>
Radare2's equivalent of GDB's Radare2's equivalent of GDB's set $reg 0x2020
|radare2|
<p>If I've understood correctly, you are trying to figure out how the functions in this dll are called from the main executable.</p> <p>If that's the case you can use API Monitor by Rohitab, a free tool to &quot;spy&quot; access to dll functions. This tool is very powerful, and it allows you to retrieve the thread id, the name of the DLL that made the call, the API itself with its parameters and return value.</p>
30247
2022-04-09T15:34:16.000
<p>I'm currently analyzing a complex software which compiles a kind of code. By monitoring and correlating it with ProcMon I could figure out it loads a DLL as a module.</p> <p>Now I'm trying to find out how exactly it is compiling the code by using a specific DLL (and which of its function together with its output) so I would like to ask which is the best way to do this.</p> <p>I have IDA Pro and know it has the capability to debug it together with an exe. The problem is the software consists of multiple subprocesses (or exes) so I don't know which one is using it exactly or how to handle such cases.</p> <p>Is there any way you can recommend or reference I could start with? I was considering using processhacker together with &quot;ThreadCreate&quot; Operations but don't know if ProcessHacker is the right tool for this as it doesn't record anything and has only a real-time view.</p> <p>Thanks</p>
Best way to monitor the access to a DLL of a software?
|ida|dll|processhacker|
<p>In <strong>x64dbg</strong>, you can use the shortcut <kbd>Ctrl</kbd>+<kbd>G</kbd> to quickly move to a VA.</p> <p>A VA is a Virtual Address and an RVA is a Relative Virtual Address (the relative address with respect to the imagebase).</p>
30250
2022-04-10T21:37:18.467
<p>I have an absolute address that I want to scroll the Disassembly to in order to see which instructions are at that address. I understand that I can scroll by hand, or I can edit RIP. But the former may be slow and the latter is intrusive, I don't want to edit the state of the process. Is there a command for this?</p> <p>I've found <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>G</kbd>, but this is &quot;Go to offset&quot;, it doesn't accept absolute addresses.</p>
How to navigate Disassembly view to specific absolute address location?
|x64dbg|
<p>There is an undocumented API for this: <code>find_item_coords(item)</code></p> <p>Thus you can do something like this in IDAPython:</p> <pre class="lang-py prettyprint-override"><code>cfunc = ida_hexrays.decompile(ea) item = cfunc.body.find_closest_addr(ea) coord = cfunc.find_item_coords(item) </code></pre> <p>The <code>coord</code> returned is a <code>(x, y)</code> tuple denoting column and row number for the item in the pseudo code.</p> <p>Hope this can help you.</p>
30252
2022-04-11T22:35:18.443
<p>For, e.g. disassembler or IDA view:</p> <p><a href="https://i.stack.imgur.com/EzIas.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EzIas.png" alt="enter image description here" /></a></p> <p>Decompiler or Hex View:</p> <p><a href="https://i.stack.imgur.com/6EoY3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6EoY3.png" alt="enter image description here" /></a></p> <p>I can get the decompilation of whole function using something like:</p> <pre><code>decompiled = ida_hexrays.decompile(ea) </code></pre> <p>But, in this way I get the complete decompilation, but not the part which is only highlighted.</p> <p>For. e.g. I want something like - let's say for the instruction:</p> <pre><code>.text:00000000004011BB call rdx </code></pre> <p>The corresponding decompilation would only be:</p> <pre><code>v4 = ((__int64 (__fastcall *)(_QWORD))a2)(v7) + v3; </code></pre> <p>Any help is appreciated.</p>
idapython: how to get decompiler output corresponding to the indirect call
|ida|idapython|
<p>Its a problem with the binary - maybe intended. The <code>sum</code> variable is next to the char that is passed to <code>atoi</code> via a reference</p> <pre><code>int atoi(const char *nptr); </code></pre> <p><code>atoi</code> expects a null terminated string while here in this case it gets pointer to a char that has an integer next to it - which might not have <code>\0</code> in your case and it would lead to problems.</p> <p>for 5555555555 the argument to atoi in order would be - shown as qword here for clarity</p> <pre><code>0x0000000000000035 - &quot;5\x00&quot; 0x0000000000000535 - &quot;5\x05\x00&quot; 0x0000000000000a35 - &quot;5\n\x00&quot; 0x0000000000000f35 - &quot;5\x0f\x00&quot; 0x0000000000001435 - &quot;5\x14\x00&quot; 0x0000000000001935 - &quot;5\x19\x00&quot; 0x0000000000001e35 - &quot;5\x1e\x00&quot; 0x0000000000002335 - &quot;5#\x00&quot; 0x0000000000002835 - &quot;5(\x00&quot; 0x0000000000002d35 - &quot;5-\x00&quot; </code></pre> <p>Now these cases are handled well by <code>atoi</code> but in case of 9191919191</p> <pre><code>0x0000000000000039 - &quot;9\x00\x00&quot; 0x0000000000000931 - &quot;1\t\x00&quot; 0x0000000000000a39 - &quot;9\n\x00&quot; 0x0000000000001331 - &quot;1\x13\x00&quot; 0x0000000000001439 - &quot;9\x14\x00&quot; 0x0000000000001d31 - &quot;1\x1d\x00&quot; 0x0000000000001e39 - &quot;9\x1e\x00&quot; 0x0000000000002731 - &quot;1&quot;\x00&quot; 0x0000000000002839 - &quot;9(\x00&quot; 0x0000000000003131 - &quot;11\x00&quot; </code></pre> <p>As you can see the last arg here is &quot;11&quot; which would mean 11 is added to <code>sum</code> hereby taking it to 60 instead of 50.</p> <p>This can be verified</p> <pre><code>$ gdb -q ./license_checker_3 Reading symbols from ./license_checker_3...(no debugging symbols found)...done. (gdb) b * main+0xa0 Breakpoint 1 at 0x1219 (gdb) r 9191919191 Starting program: /mnt/c/Users/sverma/Desktop/tmp/license_checker_3 9191919191 Breakpoint 1, 0x0000555555555219 in main () (gdb) x/xi $rip =&gt; 0x555555555219 &lt;main+160&gt;: cmpl $0x32,-0x10(%rbp) (gdb) x/dw $rbp-0x10 0x7fffffffe0b0: 60 </code></pre>
30261
2022-04-14T06:25:36.163
<p>I am playing with <a href="https://crackmes.one/crackme/62327b0433c5d46c8bcc0335" rel="nofollow noreferrer">this</a> crackme. The executable takes a numerical input (e.g., 123) and adds all the numbers. The total must be 50. However, I noticed that not all inputs adding up to 50 are validated. For example: 5555555555 is validated, but 9191919191 is not.</p> <p>Lines of interest: 20-28.</p> <p>I am probably missing something, but I cannot figure out what it may be. Any ideas?</p> <p><a href="https://i.stack.imgur.com/2bHY4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2bHY4.png" alt="Assembly and Seudo-C in Ghidra" /></a></p>
Crackmes challenge not validating all answers
|assembly|c|ghidra|crackme|
<p><kbd>Edit</kbd> -&gt; <kbd>Patch Program</kbd> -&gt; <kbd>Assembly</kbd> is not the best choice because it does not work for all processors and all instructions. I agree with <code>sudhackar</code>, but you can also use <kbd>Edit</kbd> -&gt; <kbd>Patch Program</kbd> -&gt; <kbd>Change byte...</kbd> to change the relative address (in your case it will 4th byte).</p>
30267
2022-04-16T04:34:03.587
<p>I have a disassembly line showing:</p> <pre><code>lea rcx, Format </code></pre> <p>In which <code>Format</code> is a memory address named by IDA. The address is at 0x1400132E0 and points to a C-String &quot;hello, my dear\n&quot;.</p> <p>What I want to do is to patch the address of <code>Format</code> to 0x1400132E1 so that the string would become &quot;ello, my dear\n&quot;. However, <strong>Edit-&gt;Patch Program-&gt;Assembly</strong> does not allow operand such as [0x1400132E1]. What can I do?</p>
IDA Free: How to patch a memory address
|ida|
<p>Just because a particular string is presented in your process memory during the execution of your program, it doesn't mean that it was prepared in advance (on disk) before you launch a program.</p> <p>There are many other possibilities, how your program may load a &quot;non-existing&quot; string, for example:</p> <ul> <li>The string is combined (e.g. concatenated) from others,</li> <li>the string is entered by user,</li> <li>the string is created from its encrypted form,</li> <li>the string is from dynamically loaded DLL,</li> <li>the string is loaded from resources,</li> <li>the string is read from an external file,</li> <li>the string is loaded from an environmental variable,</li> <li>... and so on.</li> </ul> <p>Searching for a particular string is one of the simplest method in reverse engineering, but in the same time one of the <em>least reliable method</em>.</p>
30279
2022-04-17T21:06:19.453
<p>Please note that I am new to x64dbg.</p> <p>As you can be seen in the picture below, the error message has the string</p> <pre><code>[ebp+8]:L&quot;The information you have entered is invalid!\n...&quot; </code></pre> <p><a href="https://i.stack.imgur.com/My60T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/My60T.png" alt="address with string" /></a></p> <p>However, when I do Search For &gt; All Modules &gt; String References, it does not pop up:</p> <p><a href="https://i.stack.imgur.com/0HSIy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0HSIy.png" alt="no results found" /></a></p> <p>I am wondering why this searching only works for some strings, not all strings.</p>
Searching for strings only partially works in x64Dbg
|x64dbg|
<p>The &quot;intended purpose&quot; of a processor register is generally irrelevant to a compiler, unless something fundamental about the instruction set or architecture makes use of that aspect of the register. For example, on x86, the <code>esp</code> register is implicitly used by instructions such as <code>push</code>, <code>pop</code>, <code>call</code>, and <code>ret</code>. As a result, the <code>esp</code> register cannot be repurposed as a general-purpose register. Similarly, some other instructions use fixed registers: there is a <code>shl eax, cl</code> instruction, but no <code>shl eax, bl</code> instruction; <code>rep movsb</code> moves <code>ecx</code> bytes from <code>esi</code> to <code>edi</code>; and there are other examples like this. <code>ebp</code> is technically only tied to its role as the frame pointer through instructions like <code>enter</code> and <code>leave</code>, so it can be used as a general purpose register, although it is often still used as a frame pointer to make debugging easier.</p> <p>Outside of examples like this, where the compiler has no choice but to obey the intended purposes of registers in order interoperate with the architecture and broader platform, the compiler has no reason to care what somebody wrote in a manual 40 years ago recommending that <code>eax</code> be used as an accumulator and <code>ecx</code> be used as a counting register. Not only does the compiler have no sound way of determining in general which category a variable in the source code belongs to, no benefit would be obtained by putting variables into their &quot;proper&quot; register. In fact, having those unnecessary extra constraints would only serve to burden the compiler's job of producing performant code by making register allocation more difficult. Almost any register can be used for almost any purpose, and the compiler will exploit this in order to produce better code, which is a good thing.</p>
30283
2022-04-18T07:42:36.430
<p>It seem to be well known that x86 registers names have a purpose and indicate on how the register should be use (see <a href="https://www.tutorialspoint.com/assembly_programming/assembly_registers.htm" rel="nofollow noreferrer">this website for example</a>).</p> <p>According to this, <code>ecx</code> should be the register holding my <code>i</code> variable on the code bellow :</p> <pre><code>int main() { register int i = 0; for(i = 0 ; i &lt;= 10 ; i++){} return 0; } </code></pre> <p>Objdump disassemble:</p> <pre><code> 0000000000001138 &lt;main&gt;: 1138: f3 0f 1e fa endbr64 113c: 55 push rbp 113d: 48 89 e5 mov rbp,rsp 1140: 53 push rbx 1141: bb 00 00 00 00 mov ebx,0x0 1146: f3 0f 1e fa endbr64 114a: bb 00 00 00 00 mov ebx,0x0 114f: eb 03 jmp 1154 &lt;main+0x1c&gt; 1151: 83 c3 01 add ebx,0x1 1154: 83 fb 0a cmp ebx,0xa 1157: 7e f8 jle 1151 &lt;main+0x19&gt; 1159: b8 00 00 00 00 mov eax,0x0 115e: 5b pop rbx 115f: 5d pop rbp 1160: c3 ret </code></pre> <p>We clearly see that <code>ebx</code> is holding <code>i</code>, not <code>ecx</code>. Is there an historical reason to this? Did compiler used theoretical purpose or registers back then or was it just for humans?</p>
Why aren't compilers using registers for their intended purpose?
|compilers|register|history|
<p>This feels more like a protobuf format - Use an <a href="https://protobuf-decoder.netlify.app/" rel="nofollow noreferrer">online decoder</a> to play around.</p> <pre><code>$ echo 121b0a088153000000360057200028952152040800100052040804100018bcdfcf92062002 | xxd -r -p | protoc --decode_raw 2 { 1: &quot;\201S\000\000\0006\000W&quot; 4: 0 5: 4245 10 { 1: 0 2: 0 } 10 { 1: 4 2: 0 } } 3: 1649668028 4: 2 </code></pre> <p>Field 3 is 1649668028 which fits neatly with the times you mentioned. Here it is formatted in UTC</p> <pre><code>$ echo 121b0a088153000000360057200028952152040800100052040804100018bcdfcf92062002 | xxd -r -p | protoc --decode_raw | grep &quot;^3:&quot; | awk '{print strftime(&quot;%c&quot;, $2, 1)}' Mon Apr 11 09:07:08 2022 $ echo 12140a08814b4d00395805442000282252040800100018bd8bdc92062002 | xxd -r -p | protoc --decode_raw | grep &quot;^3:&quot; | awk '{print strftime(&quot;%c&quot;, $2, 1)}' Wed Apr 13 17:17:49 2022 </code></pre> <p>I need more details such as other columns - maybe phone number? to be sure.</p>
30290
2022-04-19T10:54:05.017
<p>I am trying to figure out and document the structure of WhatsApp's database (iOS version). Most data is easily readable, but the table <code>ZWAMESSAGEINFO</code> has a <code>BLOB</code>-column <code>ZRECEIPTINFO</code>. I am guessing this would contain information about when a message has been received/read, but can't decode the binary format. Attatched are two examples. I would suspect the time to be saved in Mac absolute time, but can't find anything that looks like a date in the data.</p> <p><code>ZRECEIPTINFO</code> of a message that has been read on 11th April 2022, 12:17 CEST (GMT+2) and was delivered on 11th April 2022, 11:07 CEST (GMT+2):</p> <pre><code>121b0a088153000000360057200028952152040800100052040804100018bcdfcf92062002 </code></pre> <p><code>ZRECEIPTINFO</code> of a message that has been read on 13th April 2022, 19:18 CEST (GMT+2) and was delivered 13th April 2022, 19:17 CEST (GMT+2):</p> <pre><code>12140a08814b4d00395805442000282252040800100018bd8bdc92062002 </code></pre> <p>Any insight or idea would be appreciated.</p>
Figuring out WhatsApp's receipt info storage format
|file-format|
<p>To unload a type library you can use <code>del_til</code> function from <code>typeinf.hpp</code>.</p> <p>Usage with IDAPython:</p> <pre><code>import ida_typeinf ida_typeinf.add_til(&quot;ntapi64_win7&quot;, ida_typeinf.ADDTIL_DEFAULT) # load a til file ida_typeinf.del_til(&quot;ntapi64_win7&quot;) # unload a til file </code></pre>
30299
2022-04-21T15:03:16.503
<p>TL;DR: I want to do this programmatically using either IDC or IDAPython and failed to find an option that works for me (also scoured <code>idc.idc</code>).</p> <p><a href="https://i.stack.imgur.com/Cl4E3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cl4E3.png" alt="Unloading type library from the GUI" /></a></p> <hr /> <p>In order to explicitly load a type library I can use <code>add_default_til()</code> (formerly <code>LoadTil()</code>). However, there doesn't appear to be any counterpart to this function to unload a previously loaded type library. And that's what I am looking for.</p> <p>My issue is that although <code>%ProgramFiles%\IDA Pro 7.7\sig\pc\autoload.cfg</code> does <em>not</em> list the <code>ntddk64_win7</code> and <code>ntapi64_win7</code> type libraries, they seem to get loaded implicitly <em>somehow</em>. Chances are (but I haven't found documentation to corroborate this; the only connection seems to be <code>autoload.cfg</code>) that this has to do with the following log lines:</p> <pre><code>Using FLIRT signature: Windows Driver Kit 7/10 64bit Using FLIRT signature: Windows Driver Kit 7/10 64bit Propagating type information... Function argument information has been propagated The initial autoanalysis has been finished. </code></pre> <p>Now, I'd like to unload those two and instead load <code>ntddk64_win10</code> and <code>ntapi64_win10</code> respectively (possibly re-running auto-analysis).</p> <p>Alas, I haven't found a way to script this.</p> <p>Bonus question: <a href="https://reverseengineering.stackexchange.com/q/30854/245">is there something that ties the FLIRT signatures to type libraries (<code>.til</code>) <em>aside</em> from <code>autoload.cfg</code></a>?</p>
How to unload a type library (.til) programmatically (preferably using IDC, but IDAPython is fine, too)?
|ida|idapython|idc|
<p>It is to note that the division in the binary is unsigned while according to <a href="https://z3prover.github.io/api/html/classz3py_1_1_bit_vec_ref.html#a972c1bf635b9697a3d92d066e0ebe10c" rel="nofollow noreferrer">doc</a></p> <blockquote> <p>Use the function URem() for unsigned remainder, and SRem() for signed remainder.</p> </blockquote> <p><code>%</code> operator by default is an alias for <code>SRem</code> or signed modulo. You need to use <code>URem</code>. I have fixed your logic as well in this code</p> <pre><code>from z3 import * v7 = [123,456,789,987,654,321] v6 = [92,29,380,2,497,296] arrl = 14 argv1 = [BitVec(f'a{i}', 32) for i in range(arrl)] solver = Solver() v18 = BitVecVal(0x7fffffff, 32) for i in range(arrl): solver.add(argv1[i] &lt; 128) solver.add(argv1[i] &gt; 32) v18 += i*argv1[i] for i in range(6): solver.add(URem(v18, v7[i]) == v6[i]) print(solver.check()) print(&quot;&quot;.join(map(chr,[solver.model()[argv1[i]].as_long() for i in range(arrl)]))) </code></pre> <p>Please note that this won't solve the problem, It has additional checks.</p>
30303
2022-04-22T11:16:46.947
<p>When I try to solve this crackme chall (<a href="https://crackmes.one/crackme/61ffb07c33c5d46c8bcbfc1d" rel="nofollow noreferrer">https://crackmes.one/crackme/61ffb07c33c5d46c8bcbfc1d</a>) , there is a condition that I can't bypass and my z3 script can't predict the input string that will bypass the condition</p> <p><a href="https://i.stack.imgur.com/52wqB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/52wqB.jpg" alt="enter image description here" /></a></p> <p>and this is my z3 script</p> <pre><code>from z3 import * v7 = [123,456,789,987,654,321] v6 = [92,29,380,2,497,296] s = [BitVec(f'a{i}', 8) for i in range(5)] solver = Solver() v20 = 0x7FFFFFFF for i in range(5): solver.add(s[i]&gt;32,s[i]&lt;127) v20 += i * s[i] solver.add(v20 % v7[i] == v6[i]) solver.check() </code></pre>
Z3 is unable to predict the operand
|ida|crackme|
<p>Based on the following sample:</p> <p><strong>be7df9b222558c6b2afce6db5b20645bf394901f3d5ba27945d5497a367c8034</strong></p> <p>The unpacked Quakbot payload is this:</p> <p><strong>c85839f837d0312d9fb5440b16fa4fe3769df6d8f986dfaa0b5a28fb9ec80e19</strong></p> <p>I have identified the call to the function which resolves the API names that you're asking about at address <code>0x10031E22</code>. To catch all the API names, just set a conditional breakpoint there (SHIFT-F2). In the Log Text field of the breakpoint configuration, put <code>{a:eax}</code>. Then in the Break Condition field, put <code>0</code>. With the breakpoint set, click the Run button or hit F9. You then go look at the log tab, and the API names should all be listed there. This is much faster than trying to do a trace, and you end up with the same dataset. It looks like there are more locations where API names are resolved, so you may need to rinse and repeat this process a couple times for each location where the API names are resolved. You can set multiple breakpoints for all the locations. Here is the list of API names that I collected from this sample at the address above:</p> <pre><code>Breakpoint at 10031E22 set! &lt;kernel32.LoadLibraryA&gt; &lt;kernel32.LoadLibraryW&gt; &lt;kernel32.FreeLibrary&gt; &lt;kernel32.GetProcAddress&gt; &lt;kernel32.GetModuleHandleA&gt; &lt;kernel32.CreateToolhelp32Snapshot&gt; &lt;kernel32.Module32First&gt; &lt;kernel32.Module32Next&gt; &lt;kernel32.WriteProcessMemory&gt; &lt;kernel32.OpenProcess&gt; &lt;kernel32.VirtualFreeEx&gt; &lt;kernel32.WaitForSingleObject&gt; &lt;kernel32.CloseHandle&gt; &lt;kernel32.LocalFree&gt; &lt;kernel32.CreateProcessW&gt; &lt;kernel32.ReadProcessMemory&gt; &lt;kernel32.Process32First&gt; &lt;kernel32.Process32Next&gt; &lt;kernel32.Process32FirstW&gt; &lt;kernel32.Process32NextW&gt; &lt;kernel32.CreateProcessAsUserW&gt; &lt;kernel32.VirtualAllocEx&gt; &lt;kernel32.VirtualAlloc&gt; &lt;kernel32.VirtualFree&gt; &lt;kernel32.OpenThread&gt; &lt;kernel32.Wow64DisableWow64FsRedirection&gt; &lt;kernel32.Wow64EnableWow64FsRedirection&gt; &lt;kernel32.GetVolumeInformationW&gt; &lt;kernel32.IsWow64Process&gt; &lt;kernel32.CreateThread&gt; &lt;kernel32.CreateFileW&gt; &lt;kernel32.CreateFileA&gt; &lt;kernel32.FindClose&gt; &lt;kernel32.GetFileAttributesW&gt; &lt;kernel32.SetFilePointer&gt; &lt;kernel32.WriteFile&gt; &lt;kernel32.ReadFile&gt; &lt;kernel32.CreateMutexA&gt; &lt;kernel32.ReleaseMutex&gt; &lt;kernel32.FindResourceA&gt; &lt;kernel32.FindResourceW&gt; &lt;kernel32.SizeofResource&gt; &lt;kernel32.LoadResource&gt; &lt;kernel32.GetTickCount64&gt; &lt;kernel32.ExpandEnvironmentStringsW&gt; &lt;kernel32.GetThreadContext&gt; &lt;kernel32.SetLastError&gt; &lt;kernel32.GetComputerNameW&gt; &lt;kernel32.Sleep&gt; &lt;kernel32.SleepEx&gt; &lt;kernel32.OpenEventA&gt; &lt;kernel32.SetEvent&gt; &lt;kernel32.CreateEventA&gt; &lt;kernel32.TerminateThread&gt; &lt;kernel32.QueryFullProcessImageNameW&gt; &lt;kernel32.CreateNamedPipeA&gt; &lt;kernel32.ConnectNamedPipe&gt; &lt;kernel32.GetLocalTime&gt; &lt;kernel32.ExitProcess&gt; &lt;kernel32.GetEnvironmentVariableW&gt; &lt;kernel32.GetExitCodeThread&gt; &lt;kernel32.GetFileSize&gt; &lt;kernel32.VirtualProtect&gt; &lt;kernel32.VirtualProtectEx&gt; &lt;kernel32.InterlockedCompareExchange&gt; &lt;kernel32.CreateRemoteThread&gt; &lt;kernel32.SetEnvironmentVariableW&gt; &lt;kernel32.ResumeThread&gt; &lt;kernel32.TerminateProcess&gt; &lt;ntdll.RtlAddVectoredExceptionHandler&gt; &lt;kernel32.DeleteFileW&gt; &lt;kernel32.CopyFileW&gt; &lt;kernel32.AllocConsole&gt; &lt;kernel32.SetConsoleCtrlHandler&gt; &lt;kernel32.GetModuleFileNameW&gt; &lt;kernel32.GetCurrentProcess&gt; &lt;kernel32.CreatePipe&gt; </code></pre> <p><a href="https://i.stack.imgur.com/Inf3T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Inf3T.png" alt="Breakpoint" /></a></p> <p>Cheers!</p>
30307
2022-04-22T19:07:16.183
<p>The question seems pretty simple, but I can't achieve this simple thing in a reasonable time. I have a malware proceeding to deobfuscate a large amount of APIs in memory. Only the pointer to the functions is stored, not the name. I just wanted to quickly get a list of the API names using the trace feature when x64dbg sees the info from the register. ({a:register} gives me the symbol related to this pointer)</p> <p>The problem is that the TraceInto is really too slow since it has to test every non-user instruction. I have just tried to TraceInto and launches the command &quot;StepOut&quot; when the base address isn't linked to user code. <strong>But this command stops the tracing</strong>. RunToParty, RunToUserCode stop the tracing as well. I could set some commands to restart the tracing, but I haven't found any options in the documentation to <strong>append</strong> logs to the log file. The provided log file is cleared each time the tracing starts.</p> <p>Do you have some tricks to perform such common tasks, that is to say, TraceInto only in the usercode ?</p>
x64dbg : TraceInto only in user code
|malware|debuggers|x64dbg|
<p><code>sub_1169</code> is actually an LCG based random number generator. <code>sub_1155</code> sets the seed value for this LCG. So <code>sub_1155</code> is similar to <code>srand</code> and <code>sub_1169</code> is <code>rand</code></p> <p>Because of this the xor key is not the same for every byte.</p> <pre><code>srand(seed); for ( k = 0; k &lt;= 196; ++k ) { v9 = rand(); v8[k] ^= v9; } </code></pre> <p>Now</p> <pre><code>v14 = (int (__fastcall *)(char *, int))v8; </code></pre> <p>This means we are assigning byte data pointed by <code>v8</code> as function or code - specifically a function that takes a string and an int as a param and returns an int. Something like</p> <pre><code>bool verify_flag(char *flag, int len); </code></pre> <p>So <code>v8</code> is some sort of shellcode which is decoded in the xor fashion as above. Later that function is called to verify <code>argv[1]</code></p> <pre><code>if ( v12(argv[1], v5) ) puts(&quot;Good password!&quot;); else puts(&quot;Invalid password!&quot;); </code></pre> <p>The first step of getting the shellcode decoded correctly is to figure out the input that calculates some sort of &quot;checksum&quot; which when used as seed to <code>srand</code> will decode to perfect x86_64 code. This is the &quot;checksum&quot; logic.</p> <pre><code>seed = 0x7FFFFFFF; for ( i = 0; ; ++i ) { v3 = i; if ( v3 &gt;= strlen(argv[1]) ) break; seed += i * argv[1][i]; } </code></pre> <p>Additionally the binary sets up some <code>mod</code> based constraints that will help you figure out the correct checksum using z3.</p> <pre><code>from z3 import * # https://reverseengineering.stackexchange.com/questions/30303/z3-is-unable-to-predict-the-operand v7 = [123, 456, 789, 987, 654, 321] v6 = [92, 29, 380, 2, 497, 296] arrl = 14 argv1 = [BitVec(f'a{i}', 32) for i in range(arrl)] solver = Solver() v18 = BitVecVal(0x7fffffff, 32) for i in range(arrl): solver.add(argv1[i] &lt; 128) solver.add(argv1[i] &gt; 32) v18 += i*argv1[i] for i in range(6): solver.add(URem(v18, v7[i]) == v6[i]) print(solver.check()) print(&quot;&quot;.join(map(chr, [solver.model()[argv1[i]].as_long() for i in range(arrl)]))) </code></pre> <p>Once you know an input that will produce the correct seed for <code>srand</code> such that <code>rand</code> generates the correct order of values for <code>v8</code> shellcode to be decoded correctly.</p> <p>You can then run and dump this decoded shellcode or xor it statically with correct <code>rand</code> values.</p> <p>This shellcode similarly can be analysed with IDA and modelled with z3. Its a simple xor of 2 buffers and then compare with a static buffer. Unrelated to the answer, I have solved it with angr <a href="https://gist.github.com/sudhackar/ad9c15851f274b3248ef1645abee9ae8#file-sol-py" rel="nofollow noreferrer">here</a></p>
30308
2022-04-22T20:49:09.597
<p>As part of solving the <a href="https://crackmes.one/crackme/61ffb07c33c5d46c8bcbfc1d" rel="nofollow noreferrer">Hidden password</a> challenge, I found an condition calls a virtual function</p> <p><a href="https://i.stack.imgur.com/zbQ9g.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zbQ9g.jpg" alt="enter image description here" /></a></p> <p>the <code>v14</code> points to <code>v8</code> variable :</p> <p><a href="https://i.stack.imgur.com/flxah.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/flxah.jpg" alt="enter image description here" /></a></p> <p>and the functions in the program does not make sense for me, there is no two-args functions in binary program, does this bytes mean something such as signatures/evaluable code/etc..</p> <pre><code> v8[0] = 0x28BF16683619A05BLL; v8[1] = 0x4DD3CE3A2552E799LL; v8[2] = 0xA5ED9BE182304449LL; v8[3] = 0x6E27E1473B191037LL; v8[4] = 0x6DA9EC4E7AC0DAECLL; v8[5] = 0x8929723C31C59039LL; v8[6] = 0xEA92AC15DE3C3F69LL; v8[7] = 0x828DD2F713F6E8BELL; v8[8] = 0xBB4D607B1C553C6FLL; v8[9] = 0x7DC2D2F3EC43EF5BLL; v8[10] = 0x4DAF64150084DC96LL; v8[11] = 0xE1F1361E21C67AB9LL; v8[12] = 0xA4B498C90BE95F82LL; v8[13] = 0xB439B94451F266B5LL; v8[14] = 0x2380C814A4F0145BLL; v8[15] = 0x808581A5B7FB9D7ELL; v8[16] = 0x589B2B23881C5633LL; v8[17] = 0xBBAA188D8CDE35D8LL; v8[18] = 0xF6F8FD3AEB6DD0D2LL; v8[19] = 0x2FEAA6B6AE8530B8LL; v8[20] = 0xB30EDC56B009E85FLL; v8[21] = 0xFBD9E747FFC36C8FLL; v8[22] = 0x18194F7045E8F66LL; v8[23] = 0xC27B4D434FE8BEEALL; </code></pre> <pre><code>code = [ 0x28,0xBF,0x16,0x68,0x36,0x19,0xA0,0x5B, 0x4D,0xD3,0xCE,0x3A,0x25,0x52,0xE7,0x99, 0xA5,0xED,0x9B,0xE1,0x82,0x30,0x44,0x49, 0x6E,0x27,0xE1,0x47,0x3B,0x19,0x10,0x37, 0x6D,0xA9,0xEC,0x4E,0x7A,0xC0,0xDA,0xEC, 0x89,0x29,0x72,0x3C,0x31,0xC5,0x90,0x39, 0xEA,0x92,0xAC,0x15,0xDE,0x3C,0x3F,0x69, 0x82,0x8D,0xD2,0xF7,0x13,0xF6,0xE8,0xBE, 0xBB,0x4D,0x60,0x7B,0x1C,0x55,0x3C,0x6F, 0x7D,0xC2,0xD2,0xF3,0xEC,0x43,0xEF,0x5B, 0x4D,0xAF,0x64,0x15,0x00,0x84,0xDC,0x96, 0xE1,0xF1,0x36,0x1E,0x21,0xC6,0x7A,0xB9, 0xA4,0xB4,0x98,0xC9,0x0B,0xE9,0x5F,0x82, 0xB4,0x39,0xB9,0x44,0x51,0xF2,0x66,0xB5, 0x23,0x80,0xC8,0x14,0xA4,0xF0,0x14,0x5B, 0x80,0x85,0x81,0xA5,0xB7,0xFB,0x9D,0x7E, 0x58,0x9B,0x2B,0x23,0x88,0x1C,0x56,0x33, 0xBB,0xAA,0x18,0x8D,0x8C,0xDE,0x35,0xD8, 0xF6,0xF8,0xFD,0x3A,0xEB,0x6D,0xD0,0xD2, 0x2F,0xEA,0xA6,0xB6,0xAE,0x85,0x30,0xB8, 0xB3,0x0E,0xDC,0x56,0xB0,0x09,0xE8,0x5F, 0xFB,0xD9,0xE7,0x47,0xFF,0xC3,0x6C,0x8F, 0x18,0x19,0x4F,0x70,0x45,0xE8,0xF6,0x6, 0xC2,0x7B,0x4D,0x43,0x4F,0xE8,0xBE,0xEA, 0xcb,0x87,0xce,0xb3 ] </code></pre> <p>and the XOR part <code>*((_BYTE *)v8 + (int)k) ^= v11;</code> XOR with the key generated by other function</p> <pre><code>unsigned __int64 sub_1169() { // qword_4040 -&gt; 0x1 qword_4040 = 1103515245 * qword_4040 + 12345; return ((unsigned __int64)qword_4040 &gt;&gt; 16) &amp; 0x7FFF; } </code></pre> <p>outputs <code>0x41c6</code> and Xor'ing that key It won't give anything understandable and even useful</p> <pre><code>code = [ 0x28,0xBF,0x16,0x68,0x36,0x19,0xA0,0x5B, 0x4D,0xD3,0xCE,0x3A,0x25,0x52,0xE7,0x99, 0xA5,0xED,0x9B,0xE1,0x82,0x30,0x44,0x49, 0x6E,0x27,0xE1,0x47,0x3B,0x19,0x10,0x37, 0x6D,0xA9,0xEC,0x4E,0x7A,0xC0,0xDA,0xEC, 0x89,0x29,0x72,0x3C,0x31,0xC5,0x90,0x39, 0xEA,0x92,0xAC,0x15,0xDE,0x3C,0x3F,0x69, 0x82,0x8D,0xD2,0xF7,0x13,0xF6,0xE8,0xBE, 0xBB,0x4D,0x60,0x7B,0x1C,0x55,0x3C,0x6F, 0x7D,0xC2,0xD2,0xF3,0xEC,0x43,0xEF,0x5B, 0x4D,0xAF,0x64,0x15,0x00,0x84,0xDC,0x96, 0xE1,0xF1,0x36,0x1E,0x21,0xC6,0x7A,0xB9, 0xA4,0xB4,0x98,0xC9,0x0B,0xE9,0x5F,0x82, 0xB4,0x39,0xB9,0x44,0x51,0xF2,0x66,0xB5, 0x23,0x80,0xC8,0x14,0xA4,0xF0,0x14,0x5B, 0x80,0x85,0x81,0xA5,0xB7,0xFB,0x9D,0x7E, 0x58,0x9B,0x2B,0x23,0x88,0x1C,0x56,0x33, 0xBB,0xAA,0x18,0x8D,0x8C,0xDE,0x35,0xD8, 0xF6,0xF8,0xFD,0x3A,0xEB,0x6D,0xD0,0xD2, 0x2F,0xEA,0xA6,0xB6,0xAE,0x85,0x30,0xB8, 0xB3,0x0E,0xDC,0x56,0xB0,0x09,0xE8,0x5F, 0xFB,0xD9,0xE7,0x47,0xFF,0xC3,0x6C,0x8F, 0x18,0x19,0x4F,0x70,0x45,0xE8,0xF6,0x6, 0xC2,0x7B,0x4D,0x43,0x4F,0xE8,0xBE,0xEA, 0xcb,0x87,0xce,0xb3 ] key = [0x41,0xc6]*98 code = &quot;&quot; for i in range(196): code+=chr(code[i]^key[i]) </code></pre> <p>what is this line of code really does in this context :</p> <pre><code>if ( ((unsigned int (__fastcall *)(char *, size_t))v14)(a2[1], v5) ) </code></pre>
Decompilers points to non-existing virtual function
|ida|pointer|vtables|virtual-functions|
<pre><code>1006c: 48 8b 45 f0 mov rax,QWORD PTR [rbp-0x10] </code></pre> <p>copies the value in <code>rbp-0x10</code>(local variable) to <code>rax</code>(register).</p> <pre><code>10070: 48 89 45 f8 mov QWORD PTR [rbp-0x8],rax </code></pre> <p>copies <code>rax</code> to another local variable <code>rbp-0x8</code>. Its just creating a copy of a local variable which was a copy of the first argument to <code>mysteryFunc</code>.</p> <p>The C-code could look something like this</p> <pre><code>int doSomething(char * s){ char * start = s, * end = s; </code></pre> <p><a href="https://gcc.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:%271%27,fontScale:14,fontUsePx:%270%27,j:1,lang:c%2B%2B,selection:(endColumn:33,endLineNumber:5,positionColumn:5,positionLineNumber:5,selectionStartColumn:33,selectionStartLineNumber:5,startColumn:5,startLineNumber:5),source:%27%23include%3Cassert.h%3E%0A%23include%3Cstdio.h%3E%0A%0Aint+doSomething(char+*+s)%7B%0A++++char+*+start+%3D+s,+*+end+%3D+s%3B%0A++++int+c+%3D+0%3B%0A++++while(*end)+%7B%0A++++++++c+%5E%3D+*end%3B%0A++++++++end%2B%2B%3B%0A++++%7D%0A++++return+end-start+%2B+c%3B%0A%7D%27),l:%275%27,n:%270%27,o:%27C%2B%2B+source+%231%27,t:%270%27)),k:50,l:%274%27,n:%270%27,o:%27%27,s:0,t:%270%27),(g:!((h:compiler,i:(compiler:g112,filters:(b:%270%27,binary:%271%27,commentOnly:%270%27,demangle:%270%27,directives:%270%27,execute:%271%27,intel:%270%27,libraryCode:%270%27,trim:%271%27),flagsViewOpen:%271%27,fontScale:14,fontUsePx:%270%27,j:1,lang:c%2B%2B,libs:!(),options:%27%27,selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1,tree:%271%27),l:%275%27,n:%270%27,o:%27x86-64+gcc+11.2+(C%2B%2B,+Editor+%231,+Compiler+%231)%27,t:%270%27)),k:50,l:%274%27,n:%270%27,o:%27%27,s:0,t:%270%27)),l:%272%27,n:%270%27,o:%27%27,t:%270%27)),version:4" rel="nofollow noreferrer">sample</a> here</p>
30319
2022-04-24T23:50:17.347
<p>I am trying to recreate a segment of assembly back into the C code. Below is the progress I've made so far, but I'm getting stumped on a specific section.</p> <pre><code>00000000000010049 &lt;mysteryFunc&gt;: 10049: f3 0f 1e fa endbr64 1004d: 55 push rbp 1004e: 48 89 e5 mov rbp,rsp 10051: 48 89 7d d8 mov QWORD PTR [rbp-0x28],rdi ; This is the function call with a unsigned char ptr as input s 10055: 66 c7 45 e8 00 00 mov WORD PTR [rbp-0x18],0x0 ; Declaring h -- unsigned short h = 0; 1005b: c7 45 ec 00 00 00 00 mov DWORD PTR [rbp-0x14],0x0 ; Declaring length -- unsigned long length = 0; 10062: 48 8b 45 d8 mov rax,QWORD PTR [rbp-0x28] ; Declaring a temp char pointer -- unsigned char *temp = s; 10066: 48 89 45 f0 mov QWORD PTR [rbp-0x10],rax 1006a: eb 5f jmp 100cb &lt;mysteryFunc+0x82&gt; ; This seems to be a goto call to the end of a do-while loop 1006c: 48 8b 45 f0 mov rax,QWORD PTR [rbp-0x10] 10070: 48 89 45 f8 mov QWORD PTR [rbp-0x8],rax 10074: 8b 45 ec mov eax,DWORD PTR [rbp-0x14] ; if(!(length &amp; 1)) { 10077: 83 e0 01 and eax,0x1 1007a: 85 c0 test eax,eax 1007c: 75 22 jne 100a0 &lt;mysteryFunc+0x57&gt; </code></pre> <p>I don't know what instructions in C would cause this kind of repositioning.</p> <pre><code>1006c: 48 8b 45 f0 mov rax,QWORD PTR [rbp-0x10] ; What's happening here? 10070: 48 89 45 f8 mov QWORD PTR [rbp-0x8],rax </code></pre> <p>The function does some processing of a string and checks for null within a do-while loop. I get the feeling it's shifting to a next character, but a lot of the ways I can think to do something like that in C don't produce an assembly instruction like that.</p> <p>The function does some things in less than conventional ways, like a goto call to the end of a do-while loop to check if the input string is null, instead of just using a regular while loop.</p>
C instruction causing an address shift
|assembly|x86|c|
<p>I don't know if it's true or not, but I patched the <code>B BlKernelSp0SystemErrorHandler</code> and <code>B BlKernelExceptionHandler</code> with <code>ERET</code> (aka exception return), and the EFI file jumps back and stop at the place of a <code>BRK</code> instruction (as a result of branching because a compare went wrong), which seems true for me since my KVM module didn't correctly implement that stubs yet.</p> <p>Hope this helps for somebody.</p>
30327
2022-04-26T06:02:30.663
<p>I'm debugging the Windows ARM64 version's EFI (<code>bootaa64.efi</code>).</p> <p>Using QEMU and GDB I was able to find that <code>bootaa64.efi</code> was stuck in one of the two functions <code>BlKernelSp0SystemErrorHandler</code> and <code>BlKernelExceptionHandler</code>. The image below is two functions when I load <code>bootaa64.efi</code> to IDA.</p> <p><a href="https://i.stack.imgur.com/QQNQO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QQNQO.png" alt="ida" /></a></p> <p>I'm not really good at ARM64 assembly but I recognized these functions are just forever loops.</p> <p>The code stuck in that loop means <em>somehow</em> the function is called. But IDA just show two xref, one is the function call itself (loop) and the other is <code>.pdata</code> xref:</p> <p>I want to know what called these functions. Thanks!</p> <p><a href="https://i.stack.imgur.com/HDwSB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HDwSB.png" alt=".pdata" /></a></p>
IDA show xrefs in .pdata and nothing else
|ida|windows|arm|arm64|uefi|
<p>Hmm, not sure which WDK you were using, but at least the <code>Windows Kits\10\Include\10.0.22000.0\km\ntifs.h</code> and <code>Windows Kits\10\Include\10.0.22000.0\km\ntddk.h</code> of the newest (non-preview/beta) WDK list:</p> <pre><code>#define DO_VERIFY_VOLUME 0x00000002 #define DO_BUFFERED_IO 0x00000004 #define DO_EXCLUSIVE 0x00000008 #define DO_DIRECT_IO 0x00000010 #define DO_MAP_IO_BUFFER 0x00000020 #define DO_DEVICE_HAS_NAME 0x00000040 // * #define DO_DEVICE_INITIALIZING 0x00000080 #define DO_SYSTEM_BOOT_PARTITION 0x00000100 // * #define DO_LONG_TERM_REQUESTS 0x00000200 // * #define DO_NEVER_LAST_DEVICE 0x00000400 // * #define DO_SHUTDOWN_REGISTERED 0x00000800 #define DO_BUS_ENUMERATED_DEVICE 0x00001000 #define DO_POWER_PAGABLE 0x00002000 #define DO_POWER_INRUSH 0x00004000 #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000 // * #define DO_SUPPORTS_PERSISTENT_ACLS 0x00020000 // * &lt;- only in ntifs.h #define DO_SUPPORTS_TRANSACTIONS 0x00040000 // * #define DO_FORCE_NEITHER_IO 0x00080000 // * #define DO_VOLUME_DEVICE_OBJECT 0x00100000 // * #define DO_SYSTEM_SYSTEM_PARTITION 0x00200000 // * #define DO_SYSTEM_CRITICAL_PARTITION 0x00400000 // * #define DO_DISALLOW_EXECUTE 0x00800000 // * #define DO_DEVICE_TO_BE_RESET 0x04000000 #define DO_DEVICE_IRP_REQUIRES_EXTENSION 0x08000000 // * #define DO_DAX_VOLUME 0x10000000 #define DO_BOOT_CRITICAL 0x20000000 </code></pre> <p>Those marked with <code>*</code> are not on the list you gave. But I think this list is comprehensive enough to decode <em>almost</em> (except for 0x01) all items you were looking for:</p> <ul> <li>0x40001 == <code>DO_SUPPORTS_TRANSACTIONS | 0x01</code></li> <li>0x600100 == <code>DO_SYSTEM_BOOT_PARTITION | DO_SYSTEM_SYSTEM_PARTITION | DO_SYSTEM_CRITICAL_PARTITION</code></li> </ul> <p>I was, however, at first also unable to find what the 0x01 flag means. However, <strong>if</strong> ReactOS is to be trusted (<a href="https://github.com/reactos/reactos/blob/master/media/doc/notes#L43" rel="nofollow noreferrer">and often it can be trusted in those matters</a>, but not always) <a href="https://github.com/reactos/reactos/blob/999345a4feaae1e74533c96fa2cdfa1bce50ec5f/sdk/include/xdk/iotypes.h#L245" rel="nofollow noreferrer">this could be</a>:</p> <pre><code>#define DO_UNLOAD_PENDING 0x00000001 </code></pre>
30331
2022-04-26T23:19:59.740
<p>In Windows 10 looking at <strong>ntoskrnl!IopParseDevice</strong> I'm trying to work out the name / purpose of the flags in this check, which seem to be testing for values in a <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_device_object?msclkid=2d5d8b95c5b411ec885d6080ba6e9290" rel="nofollow noreferrer">DEVICE_OBJECT</a> Characteristics property and the flags property. In particular checking for device object characteristics <strong>40001h</strong> and flags <strong>600100h</strong></p> <p>What what I can tell the 0x40000 device characteristic and flags adding up to 0x600000h aren't defined in the Windows Driver kit.</p> <p>The section of code is:</p> <pre><code> PAGE:00000001404197CC ; 825: Characteristics = DEVICE_OBJECT-&gt;Characteristics; PAGE:00000001404197CC PAGE:00000001404197CC loc_1404197CC: ; CODE XREF: IopParseDevice+CFD↑j PAGE:00000001404197CC ; IopParseDevice+D17↑j ... PAGE:00000001404197CC 8B 4E 34 mov ecx, [rsi+34h] PAGE:00000001404197CF ; 826: if ( (Characteristics &amp; 0x40001) == 0 || (DEVICE_OBJECT-&gt;Flags &amp; 0x600100) != 0 ) PAGE:00000001404197CF F7 C1 01 00 04 00 test ecx, 40001h PAGE:00000001404197D5 74 64 jz short loc_14041983B PAGE:00000001404197D7 F7 46 30 00 01 60 00 test dword ptr [rsi+30h], 600100h PAGE:00000001404197DE 75 5B jnz short loc_14041983B PAGE:00000001404197E0 ; 832: v114 = (struct _SECURITY_SUBJECT_CONTEXT *)a3; PAGE:00000001404197E0 48 8B 7C 24 58 mov rdi, [rsp+208h+AccessState] PAGE:00000001404197E5 ; 833: if ( (Characteristics &amp; 0x100) == 0 ) PAGE:00000001404197E5 0F BA E1 08 bt ecx, 8 PAGE:00000001404197E9 72 55 jb short loc_140419840 PAGE:00000001404197EB ; 835: v215[0] = 0; PAGE:00000001404197EB C6 44 24 60 00 mov [rsp+208h+var_1A8], 0 PAGE:00000001404197F0 ; 836: SeIsAppContainerOrIdentifyLevelContext(a3 + 32, v215); PAGE:00000001404197F0 48 8D 4F 20 lea rcx, [rdi+20h] PAGE:00000001404197F4 48 8D 54 24 60 lea rdx, [rsp+208h+var_1A8] PAGE:00000001404197F9 E8 62 C8 07 00 call SeIsAppContainerOrIdentifyLevelContext </code></pre> <p>When stepping through via a Kernel debugger, on calling nt!NtQueryFullAttributesFile with object attributes pointing to path &quot;??\C:&quot; the value being checked with test ecx instruction is set to 0x00060000. The value for test dword ptr [rsi+30h] (flags) differs depending on what drive I select. For ??\C:\ this is set to <strong>0x1150</strong> and for ??\E:\ it is set to <strong>0x3050.</strong></p> <p>In wdm.h from Windows DDK can see the following definitions:</p> <pre><code>// // Define the various device characteristics flags // #define FILE_REMOVABLE_MEDIA 0x00000001 #define FILE_READ_ONLY_DEVICE 0x00000002 #define FILE_FLOPPY_DISKETTE 0x00000004 #define FILE_WRITE_ONCE_MEDIA 0x00000008 #define FILE_REMOTE_DEVICE 0x00000010 #define FILE_DEVICE_IS_MOUNTED 0x00000020 #define FILE_VIRTUAL_VOLUME 0x00000040 #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080 #define FILE_DEVICE_SECURE_OPEN 0x00000100 #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800 #define FILE_CHARACTERISTIC_TS_DEVICE 0x00001000 #define FILE_CHARACTERISTIC_WEBDAV_DEVICE 0x00002000 #define FILE_CHARACTERISTIC_CSV 0x00010000 #define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL 0x00020000 #define FILE_PORTABLE_DEVICE 0x00040000 #define FILE_REMOTE_DEVICE_VSMB 0x00080000 #define FILE_DEVICE_REQUIRE_SECURITY_CHECK 0x00100000 // Define Device Object (DO) flags // // DO_DAX_VOLUME - If set, this is a DAX volume i.e. the volume supports mapping a file directly // on the persistent memory device. The cached and memory mapped IO to user files wouldn't // generate paging IO. // #define DO_VERIFY_VOLUME 0x00000002 #define DO_BUFFERED_IO 0x00000004 #define DO_EXCLUSIVE 0x00000008 #define DO_DIRECT_IO 0x00000010 #define DO_MAP_IO_BUFFER 0x00000020 #define DO_DEVICE_INITIALIZING 0x00000080 #define DO_SHUTDOWN_REGISTERED 0x00000800 #define DO_BUS_ENUMERATED_DEVICE 0x00001000 #define DO_POWER_PAGABLE 0x00002000 #define DO_POWER_INRUSH 0x00004000 #define DO_DEVICE_TO_BE_RESET 0x04000000 #define DO_DAX_VOLUME 0x10000000 </code></pre>
What are these Device Object Characteristics / Flags in Windows 10 ntoskrnl!IopParseDevice
|disassembly|windows|kernel|
<p>Don't use regular expressions. Generally speaking, never use regular expressions to solve problems in IDA. All of the text you'd be operating upon is available as data via the API, which provides a normalized form and can resolve ambiguities. Anyway, your rough plan of attack here is as follows:</p> <ol> <li>Although it's not strictly necessary, I'm going to strongly recommend <a href="https://github.com/patois/HRDevHelper" rel="nofollow noreferrer">installing HRDevHelper and using it often</a>. Any time you wonder &quot;how is X represented in the Hex-Rays ctree data structures?&quot;, the fastest way to find out is to invoke HRDevHelper via its keyboard shortcut (default <kbd>ctrl</kbd>+<kbd>.</kbd>), see the answer visually, and then go to <code>hexrays.hpp</code> in the SDK for more specifics. (Note, you may want to change the default colors in the configuration file for HRDevHelper).</li> <li>After having done so, locate an indirect call in the decompilation, and use HRDevHelper to view its representation. Here's what we see for the following decompilation <code>(*(void (__fastcall **)(struct BINDING_HANDLE *, __int64))(*(_QWORD *)v5 + 8i64))(v5, 1i64);</code>:</li> </ol> <p><a href="https://i.stack.imgur.com/EY1l2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EY1l2.png" alt="HRDevHelper output" /></a></p> <ol start="3"> <li><p>Looking at the figure, we see that calls are represented by <code>cot_call</code> expressions, whose <code>.x</code> member describes the destination of the call. For indirect calls (like the one in the figure), we can see that the node for <code>.x</code> (off to the left) has the text <code>ptr.8</code> at the top. This indicates that <code>.x</code> is another expression of type <code>cot_ptr</code>. We can also see that the left <code>ptr.8</code> node has the function type printed inside of it. In fact, the type is stored in a <code>tinfo_t</code> object held within the <code>.x.type</code> member, and HRDevHelper is simply printing it for us.</p> </li> <li><p>To summarize: find <code>cot_call</code> expressions whose <code>.x</code> member does not have type <code>cot_obj</code> (as this is how direct calls are represented). Look at the <code>.x.type</code> member to determine the type of the indirect call. You're going to want to take a look at the <code>func_type_data_t</code> data type and the <code>tinfo_t::get_func_details</code> member function from <code>typeinf.hpp</code>. The former is derived from a vector of <code>funcarg_t</code> objects, which contain <code>tinfo_t</code> objects for each argument. The <code>rettype</code> field also describes the function's return type.</p> </li> <li><p>Now that we know how Hex-Rays represents indirect calls, the easiest (but not the only) way to get ahold of them is to use a <code>ctree_visitor_t</code>. There are several examples in <code>%IDADIR%\python\examples\hexrays</code> (grep it for <code>ctree_visitor_t</code>); the simplest one is <code>vds7.py</code>. Give it a try; add a <code>visit_expr(self,expr)</code> method to its <code>cblock_visitor_t</code> class, try to implement the logic described in the previous bulletpoint, run the plugin, and see what happens.</p> </li> </ol>
30338
2022-04-28T02:07:28.103
<p>I am using idapython to get function return type and arguments @ an indirect call instruction.</p> <p>I was able to sync ida disassembler with hexrays decompiler as asked <a href="https://reverseengineering.stackexchange.com/questions/30252/idapython-how-to-get-decompiler-output-corresponding-to-the-indirect-call/30258#30258">here</a> and I can now get decompiled output for specific instruction. For e.g.</p> <p>for instruction:</p> <pre><code>call rdx </code></pre> <p>I can get:</p> <pre><code>v4 = ((__int64 (__fastcall *)(_QWORD))fn2)(b) + v3; </code></pre> <p>My final goal is to get function return type for e.g. in above case it could be the type of variable <code>v4</code> and argument types, for e.g. type of variable <code>b</code>. So, say the function can possibly be:</p> <pre><code>return type: int arg1 type: int .... </code></pre> <p>I want to get these for indirect callsites.</p> <p>I checked the hexrays api but I believe there isn't any function which can give me return type and argument types/ count at a certain callsite.</p> <p>One way to achieve this may be to extract arguments using regex for e.g. in above case <code>b</code> and then hunt their type by searching through <code>lvars</code> method from decompiled object. But, it seems like a lot of work (and maybe error prone) for seemingly easier problem using some internal ida functions.</p> <p>Could you please give many any directions on how to solve this? really appreciated.</p>
how to get indirect callsite function return type and arguments
|ida|idapython|hexrays|
<p>This is a standard method for the C and C++ compilers to build static strings directly on the stack. This method will be used by the compiler when compiling this code:</p> <pre><code>#include &lt;cstdio&gt; int main() { char str1[] = &quot;hello world from some string that is constructed directly on the stack&quot;; printf(&quot;%s\n&quot;, str1); return 0; } </code></pre> <p>Result in Ghidra:</p> <pre><code>undefined8 main(void) { long in_FS_OFFSET; long local_58; undefined8 uStack80; undefined8 uStack72; undefined8 uStack64; undefined8 uStack56; undefined8 uStack48; undefined8 uStack40; undefined8 uStack32; undefined4 uStack24; undefined2 uStack20; undefined uStack18; long lStack16; lStack16 = *(long *)(in_FS_OFFSET + 0x28); local_58 = 0x6f77206f6c6c6568; uStack80 = 0x6d6f726620646c72; uStack72 = 0x747320656d6f7320; uStack64 = 0x61687420676e6972; uStack56 = 0x6e6f632073692074; uStack48 = 0x6465746375727473; uStack40 = 0x6c74636572696420; uStack32 = 0x656874206e6f2079; uStack24 = 0x61747320; uStack20 = 0x6b63; uStack18 = 0; puts((char *)&amp;local_58); if (lStack16 != *(long *)(in_FS_OFFSET + 0x28)) { // WARNING: Subroutine does not return __stack_chk_fail(); } return 0; } </code></pre> <p>The only way I could find to make the output a little less noisy is to change the type of the variable that holds the beginning of each string to <code>char[N]</code> where N is the size of the string. In I've retyped the <code>local_58</code> variable to <code>char[71]</code> and I got this:</p> <pre><code>undefined8 main(void) { long lVar1; long in_FS_OFFSET; char local_58 [71]; lVar1 = *(long *)(in_FS_OFFSET + 0x28); local_58._0_8_ = 0x6f77206f6c6c6568; local_58._8_8_ = 0x6d6f726620646c72; local_58._16_8_ = 0x747320656d6f7320; local_58._24_8_ = 0x61687420676e6972; local_58._32_8_ = 0x6e6f632073692074; local_58._40_8_ = 0x6465746375727473; local_58._48_8_ = 0x6c74636572696420; local_58._56_8_ = 0x656874206e6f2079; local_58._64_4_ = 0x61747320; local_58._68_2_ = 0x6b63; local_58[70] = '\0'; puts(local_58); if (lVar1 != *(long *)(in_FS_OFFSET + 0x28)) { // WARNING: Subroutine does not return __stack_chk_fail(); } return 0; } </code></pre> <p>It's still noisy, but at least now it uses just 1 variable for a string, and it's easier to rename the variables.</p>
30340
2022-04-28T06:01:16.663
<p>I have never seen something like this before but I assume this is some kind of way C++ allocates dynamic strings. In my decompilation listing in Ghidra I see something like:</p> <pre><code> local_14 = DAT_00404004 ^ (uint)&amp;stack0xfffffff0; local_70 = 0x2120302e; local_90 = 0x636c6557; uStack140 = 0x20656d6f; uStack136 = 0x45206f74; uStack132 = 0x7972636e; local_6c = 0xa20; local_80 = 0x6f697470; uStack124 = 0x694b206e; uStack120 = 0x76206172; uStack116 = 0x322e342e; local_6a = 0; local_28 = 0x203a656d; plea_str = 0x61656c50; uStack60 = 0x69206573; uStack56 = 0x7475706e; uStack52 = 0x756f7920; local_30 = 0x616e726573752072; local_24 = 0; local_60 = 0x656c500a; uStack92 = 0x20657361; uStack88 = 0x75706e69; uStack84 = 0x6f792074; local_48 = 0x3a64726f; local_50 = 0x7773736170207275; local_20 = 0x656d6f636c65570a; local_44 = 0x20; local_18 = 0x20; local_d0 = 0xa2e6e; local_f0 = 0x6f72570a; uStack236 = 0x7020676e; uStack232 = 0x77737361; uStack228 = 0x2e64726f; local_e0 = 0x656c5020; uStack220 = 0x20657361; uStack216 = 0x20797274; uStack212 = 0x69616761; your_str = 0x72756f59; uStack156 = 0x65737520; uStack152 = 0x6d616e72; uStack148 = 0x203a65; local_c0 = 0x72756f59; uStack188 = 0x73617020; uStack184 = 0x726f7773; uStack180 = 0x203a64; local_b0 = 0x766e490a; uStack172 = 0x64696c61; uStack168 = 0x6d616e20; uStack164 = 0xa2165; </code></pre> <p>I am not totally sure what <code>local_14</code> is doing either. But each of these locals is a string as you can tell from the bytes. Hovering over them gives the string (in reverse). I'd like to find a way to combine these in a way that makes them make more sense but despite my best efforts I cannot type them correct to get ghidra to recognize what they are and their relationship. What is the best way to handle these strings to clean up my decompilation?</p>
Strange DWORD/QWORD C++ Strings in decompilation
|c++|ghidra|strings|
<p>If you select all instructions referring to the structure and press <kbd>T</kbd>, you'll get a <a href="https://hex-rays.com/blog/igor-tip-of-the-week-04-more-selection/" rel="nofollow noreferrer">different dialog</a> where you can select the base register and the struct to apply to offsets from it.</p>
30341
2022-04-28T10:27:34.190
<p>In IDA, I have the following disassembly code (from an old 16-bit DOS application) :</p> <pre><code>les bx, _Foo mov word ptr es:[bx+84h], 0FFFFh mov word ptr es:[bx+8Ch], 0FFFFh mov word ptr es:[bx+8Ah], 0FFFFh ... _Foo dd 0 </code></pre> <p><code>_Foo</code> is defined as double word (4 bytes) but it's actually a pointer to a structure. That structure is already defined in IDA. I would like IDA to know about it in order to replace all offsets by the actual field names :</p> <pre><code>les bx, _Foo mov word ptr es:[bx+myStruct.FieldX], 0FFFFh mov word ptr es:[bx+myStruct.FieldY], 0FFFFh mov word ptr es:[bx+myStruct.FieldZ], 0FFFFh </code></pre> <p>This is something that can be done by selecting some code, pressing <kbd>T</kbd>, and then selecting appropriate structure, as explained <a href="https://reverseengineering.stackexchange.com/questions/9485/how-to-apply-ida-structure-to-a-pointer-of-a-structure#13491">here</a>. However (AFAIK) this as to be done manually for each piece of code. I would like IDA to do that replacement automatically because it is aware of <code>_Foo</code> type.</p> <p>After some search, I found how to set <code>_Foo</code> as pointer to struct: click on the variable, hit <kbd>U</kbd> (to undefine any type), then <kbd>Y</kbd> and enter <code>myStruct* _Foo;</code> in the dialog.</p> <p><code>_Foo</code> will now looks like this :</p> <pre><code>; myStruct *Foo _Foo dd 0 </code></pre> <p>It seems the only thing it does is to set variable back to <code>dd</code> and put type as comment. Field offsets are still not shown properly. It this a limitation of IDA ? (I use 7.5 version)</p>
How to set a variable as "pointer to struct" in IDA in order to automatically replace offsets by field names?
|ida|disassembly|struct|dos|pointer|
<p>That function, <code>lvar_t::set_lvar_type</code>, is accompanied by the following comment:</p> <pre><code> /// Note: this function does not modify the idb, only the lvar instance /// in the memory. For permanent changes see modify_user_lvars() </code></pre> <p>Instead of calling <code>set_lvar_type</code>, you're going to want something like this instead:</p> <pre><code>def ChangeVariableType(func_ea, lvar, tif): lsi = ida_hexrays.lvar_saved_info_t() lsi.ll = lvar lsi.type = ida_typeinf.tinfo_t(tif) if not ida_hexrays.modify_user_lvar_info(func_ea, ida_hexrays.MLI_TYPE, lsi): print(&quot;[E] Could not modify lvar type for %s&quot; % lvar.name) return False return True </code></pre>
30348
2022-04-30T03:57:52.560
<p>I am using IDA Pro 7.6 on win32 x86 binaries.</p> <p>I'm trying to use the ida_hexrays interface to decompile subroutines. I want all of the local variables and arguments of the subroutine to have integral types, no pointer types. I made this function to do all the processing for me</p> <pre><code>import ida_hexrays import ida_typeinf as ida_type import ida_lines def decompile_function( function_location ): decompile_handle = ida_hexrays.decompile( function_location, flags = ida_hexrays.DECOMP_NO_CACHE ) for local_variable in decompile_handle.lvars: type_info = local_variable.type() try: if ida_type.is_type_ptr( type_info.get_decltype() ): pointed_object = type_info.get_pointed_object() if ida_type.is_type_integral( pointed_object.get_decltype() ): local_variable.set_lvar_type( type_info.get_pointed_object() ) except: pass decompile_handle.refresh_func_ctext() pseudo_code = decompile_handle.get_pseudocode() decompile_result = &quot;&quot; for code_line in pseudo_code: decompile_result = decompile_result + ida_lines.tag_remove( code_line.line ) + &quot;\n&quot;; return decompile_result </code></pre> <p>When I decompile, I can see in the variable list that all of the variables are integral types</p> <pre><code>unsigned __int8 v7; // al int v10; // eax unsigned int v11; // esi const char v12; // cl _DWORD v13; // eax v13 = (_DWORD *)v11; </code></pre> <p>However, as you may notice above, <code>v13 = (_DWORD *)v11</code> v13 is improperly being set as a pointer. As it turns out, none of the code except the variable declarations gets changed. This happens for every subroutine that I try to decompile with this.</p> <p>But when I right-click and use reset pointer value, the code changes and it would look like <code>v13 = v11;</code>. What is the issue with my code, or is IDAPython/IDAHexrays to blame? How do I make it actually reset the pointer value and not just in the declaration list?</p>
idapython: how to reset pointer type for variables
|ida|idapython|hexrays|
<p>This is called <a href="https://frida.re/news/#child-gating" rel="nofollow noreferrer">child-gating</a> and frida has a very good <a href="https://github.com/frida/frida-python/blob/main/examples/child_gating.py" rel="nofollow noreferrer">example</a></p> <p>Here is a demo with a simple application. A simple C program with a <code>fork</code> and we try to hook <code>puts</code> for both child and parent.</p> <pre><code>(test3) [frida-example] cat test.c #include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;unistd.h&gt; int main() { puts(&quot;before&quot;); pid_t pid = fork(); if (pid) { puts(&quot;parent&quot;); } else { puts(&quot;child&quot;); } } (test3) [frida-example] make test cc test.c -o test </code></pre> <p>With the <a href="https://github.com/frida/frida-python/blob/main/examples/child_gating.py" rel="nofollow noreferrer">example</a> - adding changes</p> <pre><code> def _start(self): argv = [&quot;./test&quot;] print(&quot;✔ spawn(argv={})&quot;.format(argv)) pid = self._device.spawn(argv, env={}, stdio='pipe') self._instrument(pid) </code></pre> <p>and</p> <pre><code> def _instrument(self, pid): print(&quot;✔ attach(pid={})&quot;.format(pid)) session = self._device.attach(pid) session.on(&quot;detached&quot;, lambda reason: self._reactor.schedule(lambda: self._on_detached(pid, session, reason))) print(&quot;✔ enable_child_gating()&quot;) session.enable_child_gating() print(&quot;✔ create_script()&quot;) script = session.create_script(&quot;&quot;&quot;\ Interceptor.attach(Module.getExportByName(null, 'puts'), { onEnter: function (args) { send({ type: 'puts', path: Memory.readUtf8String(args[0]) }); } }); &quot;&quot;&quot;) </code></pre> <p>then by running</p> <pre><code>(test3) [frida-example] python hook.py ✔ spawn(argv=['./test']) ✔ attach(pid=1968) ... ✔ resume(pid=1968) ⚡ message: pid=1968, payload={'type': 'puts', 'path': 'before'} ⚡ message: pid=1968, payload={'type': 'puts', 'path': 'parent'} ... ⚡ child_added: Child(pid=1977, parent_pid=1968, origin=fork) ✔ attach(pid=1977) ... ✔ resume(pid=1977) ⚡ child_removed: Child(pid=1977, parent_pid=1968, origin=fork) ⚡ message: pid=1977, payload={'type': 'puts', 'path': 'child'} ... ⚡ detached: pid=1977, reason='process-terminated' </code></pre> <p>We hooked both the instances of child and parent</p>
30349
2022-04-30T12:14:01.617
<p>There was such a situation. I run the frida hook on the process like this:</p> <pre><code>frida -f '..\hack2\hackme.exe' -l .\start.js </code></pre> <p>In the script itself I do this</p> <pre><code>var moduleData = Process.getModuleByName(&quot;hackme.exe&quot;); </code></pre> <p>then comes the code which, as a result of which, I launch a function that launches another process - <code>level2.exe</code>.</p> <p>It would be convenient if you could hook this process directly from this script. calling <code>Process.findModuleByName(&quot;level2.exe&quot;);</code> is always null. The only way I see now is to write a Python script that will monitor the launch of the second process and run the hook in different threads. Perhaps there is a simpler solution without resorting to such extreme measures?</p>
Frida hook multiple processes
|windows|python|frida|
<p>If the library is indeed loaded using LoadLibrary, it must exist on disk. You can, for example, check the list of modules using Process Explorer or similar and look for it on disk, or catch the load event in the debugger - the file should be available at that point even if it’s deleted afterwards.</p>
30354
2022-05-01T13:34:02.327
<p>Idk if this is asked before sorry</p> <p>So I tried something with Process Hacker and Windbg but it couldn't help me The dll is injected using <code> CreateRemoteThread</code>, <code>LoadLibrary</code> i tried looking through files but im a newbie so i didn't got so much experience. What way would you guys prefer to export a dll of process memory?</p>
Exporting dll out of a process memory
|dll|memory-dump|
<p>I took a look at a few of them out of curiosity. My primary observation was that, if instead of <em>shifting</em> to the right by 3, you <em>rotate</em> to the right by 3 -- i.e. don't throw the bottom 3 bits at the bottom away, but rather, move them back to the top 3 bits -- then you <em>almost</em> get the result in the file -- except a few bits were different. I set out to try to figure out what the difference was, and it quickly became obvious that the value in the file was always XORed by <code>0x7000000</code> when compared to the output of the mangling procedure developed until that point. So it seemed like the last step was to XOR by that constant. I wrote a little Python program to test this:</p> <pre><code>import sys def ror32(x,n): n &amp;= 31 low = (x &gt;&gt; n) high = (x &lt;&lt; (32-n)) &amp; 0xFFFFFFFF return high|low def swaplow3(x): x0 = x &amp; 0xFF x1 = (x&gt;&gt;8) &amp; 0xFF x2 = (x&gt;&gt;16) &amp; 0xFF x3 = (x&gt;&gt;24) &amp; 0xFF return (x3&lt;&lt;24) | (x0&lt;&lt;16) | (x1&lt;&lt;8) | x2 def MangleFloat(f): f = ror32(f,3) f = swaplow3(f) f = f ^ 0x7000000 return f print(&quot;%#x&quot; % (MangleFloat(int(sys.argv[1],16)))) </code></pre> <p>Then I took the float values from the names of some of the files from your Google Drive link above, tested them, and compared it to the value in the file. It correctly predicted everything I tested (though I only tested a random sampling of them).</p> <p>You were close; if you'd gone with rotate right instead of shift right, you might've then noticed that the difference was always a fixed bit pattern, which would have lead you to the fixed XOR constant.</p>
30363
2022-05-04T22:23:11.167
<p>I'm reverse engineering a proprietary file format that contains a set of points to construct a curve (FL Studio's .fnv format). What i have trouble with in particular is how the Y-coordinates are saved in the file. The Y-coordinate of a point is represented between 0 and 1, inclusively, although i doubt it's a fixed-point encoding. HxD didn't recognize it and the float values were seemingly garbage. Here's what I've found currently:</p> <p>Let's say the point we have has the coordinate of <code>0.0124069480225444</code>. If we look into it's .fnv file we would observe in that place these bits:</p> <p><code>01100000 11010000 01101000 10001001</code></p> <p>What I've tried doing was to take the binary representation of that float using <a href="https://www.h-schmidt.net/FloatConverter/IEEE754.html" rel="nofollow noreferrer">this handy tool</a> and seeing what was similar:</p> <p><code>00111100 01001011 01000110 10000011</code></p> <p>Then, bitshift three to the right</p> <p><code>00000111 10001001 01101000 11010000</code></p> <p>And reverse the order of the last three bytes:</p> <p><code>00000111 110100000 1101000 10001001</code></p> <p>The last tree bytes <em>do</em> match up with the original value found on all of the files that I've tested, but the first byte always seems to be <code>00000111</code>, which hasn't showed up in any of the files I've seen. It must be something related to the exponent part of IEEE-754 but I'm unsure.</p> <p>So my question is - am i missing something obvious? I'm a bit new to the world of reverse engineering so i'd appreciate your help</p> <p><a href="https://drive.google.com/drive/folders/1B0Q3105zMu6DR1UZasPNFnsMDyVVa66Y?usp=sharing" rel="nofollow noreferrer">File examples</a> - see 4 bytes at 0x17-0x1B</p>
Floating point number mangled in a proprietary file
|file-format|float|
<p>You can use <a href="https://help.x64dbg.com/en/latest/commands/analysis/symload.html" rel="nofollow noreferrer">symload/loadsym</a> command.</p> <p>In the x64dbg console type:</p> <blockquote> <p>symload pdbconsoleapplication1,symbols\pdbconsoleapplication1.pdb,[0/1]</p> </blockquote> <p>With the last argument, you can control if the validation of symbols shall be skipped or not (1 - skips).</p>
30371
2022-05-06T17:50:41.797
<p>I want to see symbols in the disassembly wherever possible, and I have a PDB file for the .exe I'm debugging, but I can't find a way to load the PDB file from disk. Is it even possible?</p>
How to load a PDB file into x64dbg?
|windows|x64dbg|symbols|debugging-symbols|pdb|
<p>The default hotkey for this is 'R', which is mapped to &quot;Add/Edit References&quot;. You can also reach this menu by right-clicking in the Listing view on one of these instructions and selecting <code>References-&gt;Add/Edit...</code>. This will open the References Editor, from which you can add a new reference using the green plus icon for &quot;Add Forward Reference&quot;. You will have to manually specify the address this way, unfortunately. The type of reference will depend on whether this is data, a function address, or something else, and will affect what the decompiler does with this new reference information, if anything.</p> <p>In many cases the decompiler automatically takes care of calculating the final value for you, though it probably won't create an explicit reference. I've seen this happen for other architectures, but have not specifically tried with Tricore.</p>
30378
2022-05-09T08:16:53.677
<p>I encountered the following 2 instructions while reversing Tricore assembly:</p> <p><a href="https://i.stack.imgur.com/KYcG3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KYcG3.png" alt="2 instructions reference" /></a></p> <p>These 2 instructions load the final address: 0x804A9474. Where a global symbol resides.<br /> Is there a way to hint Ghidra the global symbol is located calculated address? (For example like Ctrl+R in IDA)</p>
How to reference an address set by 2 instructions in Ghidra
|decompilation|ghidra|address|offset|
<p>Google returned to me this document with information about function 0x8 subfunction 0x15:</p> <p><a href="https://www.modbus.org/docs/PI_MBUS_300.pdf" rel="nofollow noreferrer">https://www.modbus.org/docs/PI_MBUS_300.pdf</a></p> <blockquote> <p>21 (15 Hex) Get/Clear Modbus Plus Statistics Returns a series of 54 16-bit words (108 bytes) in the data field of the response (this function differs from the usual two-byte length of the data field). The data contains the statistics for the Modbus Plus peer processor in the slave device.</p> </blockquote> <p>Be aware that this document describes MBPlus, not MBTCP/IP, but i hope information still will be useful for you.</p>
30386
2022-05-11T08:28:08.693
<p>A client application sends a Modbus 0x08 diagnostics query to Schneider modicun PLC over TCP/IP. The software describes itself as designed for Modicon Micro/Compact/Quantum/Momentum/584/984.</p> <p>Payload receieved:</p> <pre><code>0000 00 00 00 00 00 06 00 08 00 15 00 03 ............ </code></pre> <p>I interpret this request as:</p> <pre><code>Transaction Identifier: 0 Protocol Identifier: 0 Length: 6 Unit Identifier: 0 Function Code: 8 Subfunction: 0x15 (21) Data: 0003 </code></pre> <p>Received:</p> <pre><code>0000 00 00 00 00 00 53 00 08 00 15 00 03 4c 00 00 54 .....S......L..T 0010 10 01 df 01 c0 d5 00 00 00 03 00 00 00 00 00 00 ................ 0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0050 00 00 00 00 00 06 c6 15 0a ......... Transaction Identifier: 0 Protocol Identifier: 0 Length: 0x53 (83) Unit Identifier: 0 Function Code: 8 Subfunction: 0x15 (21) Data: 000c2960bbff005056e53596080045000081acb100008006b6810a15c606c0a8468001f6ca7018bd77d328e389bf5018faf000e600000000000000530008001500034c0000541001df01c0d500000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c6150a </code></pre> <p>I'm trying to create an emulator that can respond to this 0x8 function code so I can do basic tests of the software without hardware. While I have found documents describing diagnostics with &quot;subfunction&quot; &lt; 21 I can't find any documentation/specification for this subfunction 21.</p> <p>Any idea what information is being requested here and what type of data is being sent in the response?</p>
Interpreting Response for Modbus/TCP function code 0x08 Diagnostics
|networking|
<p>It was <code>Options -&gt; Setup data types...</code> and then choosing <code>octa word</code>: <a href="https://i.stack.imgur.com/Ec3Yh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ec3Yh.png" alt="enter image description here" /></a></p>
30390
2022-05-11T17:58:21.003
<p>How to define an xmmword variable in IDA? <a href="https://i.stack.imgur.com/bzmpH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bzmpH.png" alt="enter image description here" /></a></p> <p>IDA identified one variable as xmmword but I can't find a menu to define other variables around it as xmmwords: <a href="https://i.stack.imgur.com/ZjCoI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZjCoI.png" alt="enter image description here" /></a></p> <p>I also tried to set the type after pressing <code>Y</code> key, and set it as <code>xmmword</code>, and also tried to set the strtuct type after pressing <code>Alt+Q</code> keys, but there is no <code>xmmword</code> in neither of those 2.</p>
How to define an xmmword variable in IDA?
|ida|
<p>I don't know if you are using window or linux but the general solution i can think of is this.</p> <p>Every new allocate buffer must call through function such as VirtualAlloc or NtAllocateVirtualMemory (low level) or malloc for linux.</p> <p>Hook the allocate function (for window it is VirtualAlloc, malloc for linux) and get the following info:</p> <ul> <li>The length of the newly allocated buffer in the argument.</li> <li>The address of the allocate memory from the return of that function.</li> <li>The return address of the VirtualAlloc.</li> </ul> <p>And store to a struct and avl tree (you can check the first 10 min of this video for how the structure look like: <a href="https://www.youtube.com/watch?v=icJ8HV22cbc&amp;ab_channel=BlackHat" rel="nofollow noreferrer">https://www.youtube.com/watch?v=icJ8HV22cbc&amp;ab_channel=BlackHat</a>) or you can just log it.</p> <p>So now you can find the f_init by searching through the log manually.</p> <p>If you want to automate the process then you must build a balance tree like the video i provided above and search in it.</p> <p>For you second question it is very hard and i don't think x64dbg can do it, because it require backward slicing. You should ask a new question for that but the answer may not deal with x64dbg.</p>
30403
2022-05-14T15:42:30.267
<p>I'm interested in a general approach to the following problem:<br /> The function <strong>F_Init</strong> allocates a byte buffer called <strong>Buffer</strong> with a size called <strong>BufSize</strong>. The <strong>Buffer</strong> is allocated with each frame/iteration resulting in different values for <strong>Buffer</strong> and <strong>BufSize</strong>.</p> <p>There are approximately 50 different functions that pass both values as parameters in an arbitrary order, eg. assuming this is a <a href="https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170" rel="nofollow noreferrer">x64 calling convention</a> (left to right -&gt; rcx, rdx, r8, r9), while <strong>Buffer</strong> is stored in r8 register, sometimes other functions pass it in rdx register.</p> <p>Let's say I stopped the execution of the program inside 35th function that processes the <strong>Buffer</strong> how can I quickly figure out where is <strong>F_Init</strong> function? So far I've been manually tracing back the values by looking at the <strong>mov</strong> instructions, eg. currently <strong>Buffer</strong> pointer value is in rdx, but there was a <strong>mov rdx, r9</strong>, so the buffer was previously in r9 register and so on. Doing it manually although a great fun, it takes a lot of time so I'd like to know how to automate this process.</p> <p>Second question, if the allocation and manipulation happens in a one giant function, how to quickly locate the call from which those values originate? The question also applies to other data types like integers, eg. some function calculated the number of files in a directory and returning 5. At some point in a different place in the code I see the value 5 in register r8 and I would like to know where is the first function that created the value 5?</p> <p>How to do it in x64dbg?</p>
How to find the first function that sets the value currently stored in a given register?
|x64dbg|dynamic-analysis|
<p>You need to understand the consequences of patching an instruction. What gets changed by the instruction - both data and control flow. Based on the comments I think you are trying to patch this part</p> <pre><code>.text:0000000000000B4C push rbp .text:0000000000000B4D mov rbp, rsp .text:0000000000000B50 mov edi, 4 .text:0000000000000B55 call sub_1673 </code></pre> <p>to</p> <pre><code>.text:0000000000000B4C push rbp .text:0000000000000B4D mov rbp, rsp .text:0000000000000B50 mov edi, 0 .text:0000000000000B55 call sub_1673 </code></pre> <p>Based on this you can see what will change when <code>sub_1673</code> gets executed.</p> <pre><code>... .text:000000000000167C mov [rbp+nmemb], rdi .text:0000000000001680 cmp [rbp+nmemb], 0 .text:0000000000001685 jnz short loc_1691 .text:0000000000001687 mov eax, 0 .text:000000000000168C jmp loc_1736 ... .text:0000000000001736 add rsp, 28h .text:000000000000173A pop rbx .text:000000000000173B pop rbp .text:000000000000173C retn </code></pre> <p>Based on the calling convention 0 will be copied to <code>rdi</code>. It is then compared to 0 and then a jump is taken if its non zero. If its zero the function returns with a return value of zero. Something like</p> <pre><code>int sub_1673(size_t a1) { if(!a1) return 0; .... } </code></pre> <p>If the value was non-zero some memory is allocated and the pointer is saved to some global variable. In your case - after the patch the variable stays 0 and the application crashes while read NULL(0) address.</p>
30416
2022-05-17T11:28:38.117
<p>I'm learning reversing and for that I use Ghidra. There is program I'm trying to modify so I can recompile it and make it work. I have a code that ghidra decompile like this: <code>data=function(4)</code> Going inside the function I think to make it work I need to pass a zero. In the assembly I can read:</p> <pre><code>PUSH RBP MOV RBP,RSP MOV EDI,0x4 CALL function MOV qword ptr [data],RAX </code></pre> <p>What I understand from that (and I'm propably wrong) is that the <code>MOV EDI,0x4</code> is the 4 given in the function so I tried to rewrite it in Ghidra with <code>0x0</code> and it replace the:</p> <pre><code>bf 04 00 00 00 with bf 00 00 00 00 </code></pre> <p>I thought it would be enough and I exported as an ELF but when I start the program I get a segmentation fault so I guess I'm doing something wrong with the memory.</p> <pre><code> (gdb) x/10xi $rip =&gt; 0x555555401888: mov (%rax),%rax 0x55555540188b: test %rax,%rax 0x55555540188e: jne 0x55555540189a 0x555555401890: mov $0x0,%eax 0x555555401895: jmp 0x55555540199d 0x55555540189a: movq $0x0,-0x50(%rbp) 0x5555554018a2: mov -0x60(%rbp),%rax 0x5555554018a6: mov %rax,%rdi 0x5555554018a9: call 0x5555554008f0 &lt;strlen@plt&gt; 0x5555554018ae: mov %rax,-0x48(%rbp) </code></pre> <p>I would like some help to understand what I'm doing wrong.</p> <p>thanks</p>
Help with Ghidra and rewriting assembly
|assembly|ghidra|
<p>Let's break it down. The first and most obvious difference is Intel syntax (<code>dumpbin</code>) vs. AT&amp;T syntax (<code>objdump</code>) for the output you give. That's be the part of your question:</p> <blockquote> <p>Also why is the instruction written differently (e.g. on the first line, dumpbin writes <code>r8d,6C65746Eh</code>, while objdump writes <code>$0x6c65746e,%r8d</code>). Why is this, and what do the different representations mean?</p> </blockquote> <p>However, <code>objdump</code> lets you choose between the two and just defaults to AT&amp;T (aka <code>att</code>). Excerpt from the <code>man</code> page:</p> <pre><code>&quot;intel&quot; &quot;att&quot; Select between intel syntax mode and AT&amp;T syntax mode. </code></pre> <p>So you could simply use: <code>objdump -D -M intel ...</code> (also <code>-Mintel</code>) to get way closer to the output from <code>dumpbin</code>.</p> <p>However, a comparison of the syntax variants can be found <a href="https://en.wikipedia.org/wiki/X86_assembly_language#Syntax" rel="nofollow noreferrer">on Wikipedia</a>. <a href="http://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html" rel="nofollow noreferrer">This dated overview</a> may also help. The most important difference is that Intel syntax places the target first and the source last, whereas with AT&amp;T it's the opposite.</p> <p>Let's take the instruction you gave:</p> <ul> <li>Intel: <code>xor r8d,6C65746Eh</code> <ul> <li><code>xor</code> instruction</li> <li>(first) target operand is <code>r8d</code> (lower 32-bit of the <code>r8</code> register)</li> <li>(second) source operand is a literal <code>6C65746Eh</code> (the hexadecimal is denoted via the trailing <code>h</code> here)</li> </ul> </li> <li>AT&amp;T: <code>xor $0x6c65746e,%r8d</code> <ul> <li><code>xor</code> instruction</li> <li>(first) source operand is a literal <code>$0x6c65746e</code> (the hexadecimal is denoted via the leading <code>0x</code> here, IIRC <code>$</code> is for literals/addresses)</li> <li>(second) target operand is <code>%r8d</code> (lower 32-bit of the <code>r8</code> register)</li> </ul> </li> </ul> <p>NB: This is largely a matter of taste. Binutils (the set of tools around <code>objdump</code>) and others like GDB default to AT&amp;T syntax, but you can tell them to use the Intel syntax. Most of the disassembly I work with is Intel syntax, but it's good to be aware of the two syntax variants and know how they compare.</p> <blockquote> <p>However, I want to know what the numbers on the left column mean (e.g. 14000e712)?</p> </blockquote> <p>Those are the addresses. You probably know that executables typically take a different form when mapped into memory than on disk and that address implies two things:</p> <ol> <li>it pretends that the image is mapped at base address 0x140000000</li> <li>0x14000e712 is simply an address with offset 0xe712 <em>into</em> the mapped image</li> </ol> <p>Edit 1: Oh and perhaps one word about this <code>mov dword ptr [rsp],eax</code> versus <code>mov %eax,(%rsp)</code> business. I find the Intel syntax more readable, since it doesn't make be think where the syntax can give the clue. &quot;Write DWORD to address pointed to by <code>rsp</code>, fair enough&quot;. However, I suppose the reasoning behind the more concise AT&amp;T syntax is that the knowledge about the operation's size (DWORD) can be deduced from the operand (<code>eax</code>) and so it simply leaves out the more or less cosmetic hint of <code>dword ptr</code>.</p>
30421
2022-05-19T22:40:20.670
<p>I usually write my code on Windows, and there are two different types of development environments, each providing their own tools to view the assembly code of an object file(<code>*.obj</code>) or executable (<code>*.exe</code>).</p> <p>If I am working with Visual Studio build system from command line, the <code>dumpbin /disasm file.obj</code> command can generate disassemble a binary file. A snippet of a disassembly from an executable, produced by <code>dumpbin</code> :</p> <pre><code> 000000014000E712: 41 81 F0 6E 74 65 xor r8d,6C65746Eh 6C 000000014000E719: 41 81 F1 47 65 6E xor r9d,756E6547h 75 000000014000E720: 44 8B D2 mov r10d,edx 000000014000E723: 8B F0 mov esi,eax 000000014000E725: 33 C9 xor ecx,ecx 000000014000E727: 41 8D 43 01 lea eax,[r11+1] 000000014000E72B: 45 0B C8 or r9d,r8d 000000014000E72E: 0F A2 cpuid 000000014000E730: 41 81 F2 69 6E 65 xor r10d,49656E69h 49 000000014000E737: 89 04 24 mov dword ptr [rsp],eax </code></pre> <p>However, if I am working with the GNU toolkit (I mean mingw64, which works with native windows binaries), then running <code>objdump -D file.obj</code> gives a disassembly like this:</p> <pre><code> 14000e712: 41 81 f0 6e 74 65 6c xor $0x6c65746e,%r8d 14000e719: 41 81 f1 47 65 6e 75 xor $0x756e6547,%r9d 14000e720: 44 8b d2 mov %edx,%r10d 14000e723: 8b f0 mov %eax,%esi 14000e725: 33 c9 xor %ecx,%ecx 14000e727: 41 8d 43 01 lea 0x1(%r11),%eax 14000e72b: 45 0b c8 or %r8d,%r9d 14000e72e: 0f a2 cpuid 14000e730: 41 81 f2 69 6e 65 49 xor $0x49656e69,%r10d 14000e737: 89 04 24 mov %eax,(%rsp) </code></pre> <p>Now, it is immediately clear that both are providing the same information. However, I want to know what the numbers on the left column mean (e.g. <code>14000e712</code>)? Also why is the instruction written differently (e.g. on the first line, <code>dumpbin</code> writes <code>r8d,6C65746Eh</code>, while <code>objdump</code> writes <code>$0x6c65746e,%r8d</code>). Why is this, and what do the different representations mean? Additionally dumpbin seems to write extra information such as <code>dword ptr</code> that <code>objdump</code> doesn't write.</p>
Understanding disassembly information from Visual Studio's dumpbin and GNU's objdump
|disassembly|windows|assembly|objdump|
<p>Seek or goto an address in cutter could be done by pressing <kbd>G</kbd>. It'll take the focus to the top where you see an address bar like such</p> <p><strong><a href="https://i.stack.imgur.com/hCGgZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hCGgZ.png" alt="strong text" /></a></strong></p> <p>Just paste the address or function name and press <kbd>Enter</kbd></p>
30426
2022-05-20T19:02:44.677
<p>I'm new to reverse engineering and I'm trying to get into using a disassembler - I've been using reclass for a while now. I was looking at IDA Pro and that was 7k euros so that was not an option. I've been trying to use cutter and I'm wondering is it possible to search the address like IDA Pro, goto address.</p> <p>I'm also wondering what is the best alternative than IDA Pro?</p>
How can I use cutter like ida, trying to search by address
|ida|radare2|address|
<p>As it turns out, the code above works correctly and the issue was somewhere else entirely.</p> <p>While looking at my DLL in ghidra, I noticed that there were some strings defined that appeared nowhere in my code. As it turns out, some old object files from earlier experiments were accidentally linked into the DLL. One of the experiments was a reimplementation of LogInfo which caused the compiler/linker to produce an incorrect result.</p>
30427
2022-05-20T20:24:02.303
<p>The program I'm messing with has builtin logging. Using a proxy DLL, I managed to activate it by calling the right functions from the real DLL. However, I got stuck at using the actual logging functions, as the program crashes with Error 0xC0000142 whenever I get close to using them.</p> <p>Here's what I'm doing in my proxy DLL:</p> <pre><code>typedef void (*FDLAddr_t)(void); FDLAddr_t ForceDebugLog; typedef void (*LIAddr_t)(char const *, ...); LIAddr_t LogInfo; void setupFuncs() { HMODULE trueDll= GetModuleHandleA(&quot;.\\trueDll.dll&quot;); ForceDebugLog = (FDLAddr_t)GetProcAddress(trueDll, &quot;?ForceDebugLog@@YAXXZ&quot;); // LogInfo = (LIAddr_t)GetProcAddress(trueDll, &quot;?LogInfo@@YAXPBDZZ&quot;); } </code></pre> <p>Now, I can just do <code>ForceDebugLog();</code> and logging gets enabled. However, as soon as I uncomment the <code>LogInfo</code> line, the program crashes on startup with Windows showing the error 0xc0000142.</p> <p>Further experimentation shows that <code>GetProcAddress</code> returns the address of <code>LogInfo</code> in the DLL. Also, the line appears to be fine if <code>LogInfo</code> was a <code>FARPROC</code>, as that works without a problem. As soon as I add the cast to <code>LIAddr_t</code>, the error comes back.</p> <p>How can I work around this issue? Or do I need to take a different approach? All binaries involved are 32 bit.</p>
Calling a function with a variable number of args from a proxy DLL
|windows|dll|functions|
<p>If you have the same binary then this should be straightforward. The approaches you came up with are all typical and useful for trying to correlate code from <em>similar</em> binaries and are then handled by dedicated tools/plugins (like BinDiff, Diaphora, or Ghidra's Version tracking)</p> <p>If the binary has a fixed location in the address space, then both IDA and Ghidra should load them at this address and the address of the assembly code you are interested in should just be the same in IDA and Ghidra. If the binary is position independent then IDA and Ghidra might load them at different addresses by default, but this can be set to the same address during the initial import. Then the addresses for each instruction or data should be the same in IDA and Ghidra.</p>
30432
2022-05-23T17:16:22.370
<p>How can I map between code in IDA Pro and the same code in Ghidra? I.e., I am looking at a particular piece of assembly in one, and want to find the same assembly in the other.</p> <p>Based on asking others and thinking about it myself, I have come up with the following:</p> <ul> <li>Symbols - if they exist</li> <li>Library references could serve as hints, if they can be identified</li> <li>String references (i.e., both pieces of code refer to the same constant string)</li> <li>Trying to find the same opcode sequence - is there any easy way to do this, where I could do something like cut the assembly from IDA and tell Ghidra to find the same sequence of instructions?</li> </ul> <p>What else is there? Are there any automated tools for this? If there are no symbols, what is the &quot;best&quot; way?</p> <p>I am assuming that it is useful to be able to use both tools on the same target. Perhaps I am wrong.</p>
What techniques are there for mapping code in IDA Pro to the same code in Ghidra, or vice versa?
|ida|ghidra|
<p>This is somewhat of a symbolic simplification. If you execute code from start of the procedure, then just before ret these are the relevant changes to the state of the program - ignoring registers</p> <pre><code>float_st0 = @64[array + (y + x * 0x78) * 0x8] float_stack_ptr = float_stack_ptr + 0x1 </code></pre> <p>where <code>st0</code> has been loaded with a 64bit value from a location.</p> <pre><code>array + (y + x * 0x78) * 0x8 </code></pre> <p>In a 1D array the way you access any index is</p> <pre><code>array + index * sizeof(member) </code></pre> <p>The size of the array member is 8 <code>sizeof(double)</code> here so the index is</p> <pre><code>y + x * 0x78 </code></pre> <p>2D arrays are laid out linearly in memory. Accessing second dimension requires the size of first dimension to be known -</p> <p><a href="https://i.stack.imgur.com/35lGz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/35lGz.png" alt="enter image description here" /></a></p> <p>In the above example to access <code>array[1][2]</code> we need to access it like</p> <pre><code>array + sizeof(int) * (2 + 1 * 3) </code></pre> <p>In the op <code>x</code> is getting multiplied by 0x78 - so the size of the <code>y</code> dimension is 0x78 members.</p> <p>Additionally I could replicate the problem code to an extent <a href="https://godbolt.org/z/8n74safKd" rel="nofollow noreferrer">here</a></p> <p>With this code and x86 MSVC v19.0, optimization flag /Ox</p> <pre><code>double load(double array[][0x78], int x, int y) { return array[x][y]; } </code></pre> <p>we get</p> <pre><code>_array$ = 8 ; size = 4 _x$ = 12 ; size = 4 _y$ = 16 ; size = 4 _load PROC mov ecx, DWORD PTR _x$[esp-4] mov eax, DWORD PTR _y$[esp-4] shl ecx, 4 sub ecx, DWORD PTR _x$[esp-4] lea ecx, DWORD PTR [eax+ecx*8] mov eax, DWORD PTR _array$[esp-4] fld QWORD PTR [eax+ecx*8] ret 0 _load ENDP </code></pre> <p>PS : I ran this through a miasm based simplification - code <a href="https://gist.github.com/sudhackar/6590295409de25599cb409b3af6ebf9b" rel="nofollow noreferrer">here</a></p>
30439
2022-05-25T03:17:31.803
<p><a href="https://challenges.re/64/" rel="nofollow noreferrer">Challenge #64</a></p> <p>What does this code do?</p> <p>An array of <code>array[x][y]</code> form is accessed here. Try to determine the dimensions of the array, at least partially, by finding y.</p> <pre><code>_array$ = 8 _x$ = 12 _y$ = 16 _f PROC mov eax, DWORD PTR _x$[esp-4] mov edx, DWORD PTR _y$[esp-4] mov ecx, eax shl ecx, 4 sub ecx, eax lea eax, DWORD PTR [edx+ecx*8] mov ecx, DWORD PTR _array$[esp-4] fld QWORD PTR [ecx+eax*8] ret 0 _f ENDP </code></pre> <p>At first I think there is a mistake in the question. Because I only see three variables here, one for array address, the one x and one y, so I assume it's actually a 2d array of double, not a 3d as in <em>&quot;An array of <code>array[x][y]</code>&quot;</em>.</p> <p>Then I was stuck because eventually the program loads <code>array[8y+192x]</code>, and x and y can be anything.</p> <p>So I figured this must be a 3d array of double, with the third dimension given. I still couldn't figure it out so I tried to write my own program and use Godbolt to give me assembly. After a few trials I got something pretty close to the original program:</p> <p><a href="https://godbolt.org/z/bT7bq8exa" rel="nofollow noreferrer">Something close</a></p> <p>However I'm still having difficulty to match my program with the original question. I think I'm pretty close but how do I proceed from here? I have a hunch that y is also 24 in the original question, but not 100% sure.</p>
What does the code do?
|disassembly|x86|
<p>There are some problems with the way you write constraints in claripy. Here's a simple correction</p> <pre><code>import claripy s = claripy.Solver() const1 = claripy.BVS('const1', 64) const2 = claripy.BVS('const2', 64) rand = claripy.BVS('rand', 64) v4 = claripy.BVS('v4', 64) for i in range(64): v4 = claripy.If(rand &amp; 1 != 0, (const1 + v4) % const2, v4) rand = rand &gt;&gt; 1 const1 = 2 * const1 % const2 s.add(v4 == 12345) print(&quot;check&quot;) print(s.check_satisfiability()) </code></pre> <p>You don't need to check the <code>If</code> for every statement. In the original code it was used only to change v4. For <code>BVV</code></p> <blockquote> <p>Creates a bit-vector value (i.e., a concrete value).</p> </blockquote> <p>For <code>BVS</code></p> <blockquote> <p>Creates a bit-vector symbol (i.e., a variable).</p> </blockquote> <p>The C code shows right shift, not <code>RotateRight</code> so just use the <code>&gt;&gt;</code> operator since its been implemented with <code>__rshift__</code> in claripy.</p> <p>Another thing to work on is to search for the constants used in <code>const1</code> and <code>const2</code> - you might get a standard function.</p>
30461
2022-06-01T07:13:16.410
<p>I'm trying to bruteforce an address as part of a CTF challenge using Angr's Claripy. The function is the following:</p> <pre><code>unsigned __int64 __fastcall sub_555555555310( unsigned __int64 rand_addr, unsigned __int64 const1, unsigned __int64 const2) { unsigned __int64 v4; v4 = 0LL; while ( rand_addr ) { if ( (rand_addr &amp; 1) != 0 ) v4 = (const1 + v4) % const2; rand_addr &gt;&gt;= 1; const1 = 2 * const1 % const2; } return v4; } </code></pre> <p>where rand_addr is the address I'm trying to reverse. To be precise, I only need the lower half of the address (32 lower bits). I have v4, const1 and const2 values. This is what I've done so far with Claripy:</p> <pre><code>def do_op(rand, const1, const2): v4 = claripy.BVV(0, 64) b = claripy.BVV(0, 2) #while(claripy.UGE(rand, 1)): for i in range(64): b = claripy.If(rand &amp; 1 != 0, claripy.BVV(1,1), claripy.BVV(0,1)) v4 = claripy.If(b == 1, (const1 + v4) % const2, v4) rand = claripy.If(b == 0, claripy.RotateRight(rand, 1), rand) const1 = claripy.If(b == 0, 2 * const1 % const2, const1) s.add(v4[31:0] == claripy.BVV(&lt;some_value&gt;, 32)) </code></pre> <p>Angr claims that this solver is unsat and I was wondering what am I doing wrong.</p> <p>Thank you!</p>
Using Angr's Claripy to bruteforce a number
|angr|
<blockquote> <p>Can I give this .aab file to any developer to update my App?</p> </blockquote> <p>No you can't. The Android App Bundle usually contains compiled DEX code (and optional compiled .so libraries) very similar to the final APK file(s) that are provided to the end users.</p> <p>People with reverse engineer background may be able to make minor modifications by decompiling the dex code to SMALI code, but SMALI code is a bit like assembler code, difficult to read, not structured difficult to write. Making more than minor modifications this way is unrealistic. You also have to consider that developer with reverse engineering background are more expensive and every modification will take more development time as usual (expect 2-20 times more).</p> <p>Alternatively a developer could try to decompile the app using Jadx to Java code and recover certain parts of the app implementation, but Jadx may not able decompile every method and class, also some methods may be decompiled in an incorrect way.</p> <p>This means large parts of the app have to be reimplemented.</p> <p>Next time make sure you get access the full source code and use a developer who practices standard procedures like regular backups (or at least uses a private online-space for mirroring the code, e.g. a private Github repo or something similar).</p>
30481
2022-06-07T03:41:40.220
<p>My developer has not provided me the source code backup for my listed app in Google Play (his PC was stolen and all codes are gone with it). I logged on to my Play Store developer's account and found the .aab file and downloaded it.</p> <p>Can I give this file to any developer to update my app, or do I need the source code backup to update the app?</p>
Modify, unpack, and rebuild an Android App Bundles (.aab) file
|android|apk|development|
<p>You are apparently using a software capture, <code>usbmon</code> rather than a hardware capture such as <a href="http://openvizsla.org/" rel="nofollow noreferrer">OpenVizla</a>, so the CRC is not going to be visible to you. See the <a href="https://www.youtube.com/watch?v=cUljKImph4s" rel="nofollow noreferrer">USB Analysis 101</a> video by Tomasz Moń for more details.</p>
30487
2022-06-08T06:35:52.347
<p>I'm looking at how MITM works on USB devices. <a href="https://www.beyondlogic.org/usbnutshell/usb4.shtml" rel="nofollow noreferrer">This website</a> states that:</p> <blockquote> <p>Bulk transfers provide error correction in the form of a CRC16 field on the data payload and error detection/re-transmission mechanisms ensuring data is transmitted and received without error.</p> </blockquote> <p>Presumably, if I wanted to modify some data (MITM) on a bulk transfer, I'd need to fix up the CRC16 as well.</p> <p>Wireshark can be used to dump USB packets. Below is a captured USB &quot;bulk in&quot; packet.<a href="https://i.stack.imgur.com/7IaO3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7IaO3.png" alt="enter image description here" /></a></p> <p>The packet data is provided here:</p> <pre><code>&quot;\x40\x52\x59\x18\x53\x9d\xff\xff\x43\x03\x81\x06\x01\x00\x2d\x00&quot; \ &quot;\xe7\x2f\xa0\x62\x00\x00\x00\x00\x20\x2e\x0c\x00\x00\x00\x00\x00&quot; \ &quot;\xb7\x00\x00\x00\xb7\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00&quot; \ &quot;\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00&quot; \ &quot;\x7f\x00\x04\x84\x00\x00\x0f\x80\x06\x00\x60\x00\x00\x30\x00\x00&quot; \ &quot;\x00\x00\x00\x00\x86\x21\xf2\x0e\x20\x1c\x00\x00\x37\xb8\x00\x01&quot; \ &quot;\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00&quot; \ &quot;\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\xff\xff\xff\xff&quot; \ &quot;\xff\xff\x64\x52\x99\x4f\x8a\xf0\xff\xff\xff\xff\xff\xff\x60\x00&quot; \ &quot;\x00\x07\x47\x72\x69\x66\x66\x65\x79\x01\x04\x02\x04\x0b\x16\x32&quot; \ &quot;\x08\x0c\x12\x18\x24\x30\x48\x60\x6c\x2d\x1a\x0c\x11\x18\xff\x00&quot; \ &quot;\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00&quot; \ &quot;\x00\x00\x00\x00\x00\x03\x01\x03\xdd\x09\x00\x10\x18\x02\x00\x00&quot; \ &quot;\x04\x00\x00\xdd\x1e\x00\x90\x4c\x33\x0c\x11\x18\xff\x00\x00\x00&quot; \ &quot;\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00&quot; \ &quot;\x00\x00\x00\x73\x99\xcc\x0b&quot; </code></pre> <p>The Wireshark dissector doesn't point out a checksum. This leads me to believe the checksum is at the end of the &quot;Leftover Capture Data&quot;. I can't seem to regenerate the last two bytes as a matching CRC16.</p> <p>Am I wrong in trying to generate the checksum from <code>leftover_data[:-2]</code>?</p> <p>Is the checksum present in the capture?</p> <p>Is the checksum in another packet?</p> <p>Do Wireshark USB captures even record the checksum?</p>
Where is the CRC16 checksum in a USB BULK IN transfer?
|usb|wireshark|
<p>First I want to say thanks to people at 4pda forum. See their thread <a href="https://4pda.to/forum/index.php?showtopic=1041371&amp;st=0" rel="nofollow noreferrer">here</a>.</p> <blockquote> <p>Can you figure out informations about the MRE VXP format</p> </blockquote> <p>Well I haven't found yet, need further research</p> <blockquote> <p>how to get it signed</p> </blockquote> <p>Short answer:</p> <p>Step 1: Get your <b>SIM 1</b>'s <strong>IMSI</strong> number (<strong>NOT</strong> IMEI, they are <strong>DIFFERENT!</strong>)</p> <p>You can do this in multiple ways, but the easiest way is to plug the SIM 1 in to an Android phone and read. I personally <a href="https://stackoverflow.com/questions/14813875/how-to-get-imsi-number-in-android-using-command-line">use ADB to read IMSI</a> (worked on Android 6+ without root):</p> <pre><code>adb shell service call iphonesubinfo 7 </code></pre> <p>Step 2: Go to <a href="https://vxpatch.luxferre.top/" rel="nofollow noreferrer">https://vxpatch.luxferre.top/</a> and input the IMSI number you got in step 1. Then select your VXP file, click 'Patch' and you should be able to download a patched version.</p> <p>or</p> <p>You can enter the IMSI number in the project setting, but <strong>REMEMBER TO ADD 9 BEFORE THE IMSI NUMBER</strong></p> <p><a href="https://i.stack.imgur.com/1QFTC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1QFTC.png" alt="imsi" /></a></p> <p>Step 3: Move the patched version into a SD card and plug it in your phone Step 4: Find the vxp file and click open, your app should run now!</p> <p>Long answer: Some apps doesn't require specify the IMSI, they just work on any devices. That's because they use another way of signing, using RSA key.</p> <p>If you are interested, read <a href="https://4pda.to/forum/index.php?showtopic=1041371&amp;st=20#:%7E:text=%D0%A2%D0%B0%D0%BC%20%D0%BF%D1%80%D0%BE%D0%B2%D0%B5%D1%80%D0%BA%D0%B0%20%D1%86%D0%B8%D1%84%D1%80%D0%BE%D0%B2%D0%BE%D0%B9%20%D0%BF%D0%BE%D0%B4%D0%BF%D0%B8%D1%81%D0%B8%20%D0%BD%D0%B0%20RSA%20%D0%BA%D0%BB%D1%8E%D1%87%D0%B0%D1%85%20(%D1%83%20%D0%BC%D0%B5%D0%B4%D0%B8%D0%B0%D1%82%D0%B5%D0%BA%20%D0%B7%D0%B0%D0%BA%D1%80%D1%8B%D1%82%D1%8B%D0%B9%20%D0%BA%D0%BB%D1%8E%D1%87%2C%20%D0%B0%20%D0%B2%20%D0%BF%D0%B0%D0%BC%D1%8F%D1%82%D0%B8%20%D1%82%D0%B5%D0%BB%D0%B5%D1%84%D0%BE%D0%BD%D0%B0%20%D0%BE%D1%82%D0%BA%D1%80%D1%8B%D1%82%D1%8B%D0%B9)%0A%D0%9F%D0%BE%D0%B4%D1%80%D0%BE%D0%B1%D0%BD%D0%B5%D0%B5%20%D1%82%D1%83%D1%82%20%D0%9A%D0%B0%D1%82%D0%B0%D0%BB%D0%BE%D0%B3%20%D0%B8%D0%B3%D1%80%20%D0%B8%20%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%20%D0%B4%D0%BB%D1%8F%20%D0%BA%D0%B8%D1%82%D0%B0%D0%B9%D1%81%D0%BA%D0%B8%D1%85%20%D1%82%D0%B5%D0%BB%D0%B5%D1%84%D0%BE%D0%BD%D0%BE%D0%B2%20(%D0%9F%D0%BE%D1%81%D1%82%20Ximik_Boda%20%23111714051)%0A%D0%B8%20%D1%82%D1%83%D1%82%20%D0%9A%D0%B0%D1%82%D0%B0%D0%BB%D0%BE%D0%B3%20%D0%B8%D0%B3%D1%80%20%D0%B8%20%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%20%D0%B4%D0%BB%D1%8F%20%D0%BA%D0%B8%D1%82%D0%B0%D0%B9%D1%81%D0%BA%D0%B8%D1%85%20%D1%82%D0%B5%D0%BB%D0%B5%D1%84%D0%BE%D0%BD%D0%BE%D0%B2%20(%D0%9F%D0%BE%D1%81%D1%82%20Ximik_Boda%20%23107895102)" rel="nofollow noreferrer">here</a>. The text is in Russian, so use Google Translate if you want to.</p> <p>I have tested with ADS 1.2 compiler (I cracked myself, if you want it then tell me) and GCC (Smaller size + work very well) and Nokia 225, will continue to test further!</p> <p>The apps in S30+ platform are written in C (and optionally C++), so you can port many apps to S30+</p> <p>Again, a great thanks to people at 4pda forum!</p> <p>An image of the app running after signing:</p> <p><a href="https://i.stack.imgur.com/N2VRx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N2VRx.png" alt="image of the app" /></a></p>
30490
2022-06-08T17:09:05.380
<h1>Background</h1> <p><a href="https://web.archive.org/web/20150922183623/http://mre.mediatek.com/" rel="nofollow noreferrer">Mediatek's MRE</a> (MAUI Runtime Environment) <a href="https://en.wikipedia.org/wiki/Series_30%2B#:%7E:text=Many%20S30%2B%20devices%20only%20support%20MAUI%20Runtime%20Environment%20(MRE)%2C%5B1%5D%5B2%5D%20developed%20by%20MediaTek%2C%5B3%5D%5B4%5D%20but%20some%20later%20devices%20have%20included%20support%20for%20J2ME%20applications." rel="nofollow noreferrer">is the default runtime</a> on <a href="https://en.wikipedia.org/wiki/Series_30%2B" rel="nofollow noreferrer">Nokia S30+ platform</a>, replacing the J2ME platform on older Nokia. From <a href="https://web.archive.org/web/20151104094204/http://mre.mediatek.com/en/start/what" rel="nofollow noreferrer">MRE's page</a>:</p> <blockquote> <p>MRE (MAUI Runtime Environment) is a phone application development platform similar to JVM and Brew. On the MRE platform, you can realize solutions for smart featuer phones on feature phones. Meanwhile, MediaTek also provides devlopers and end suppliers with highly efficient development tools (MRE SDK) and compilation environment for applications, allowing developers to develop applications more quickly and effectively.</p> </blockquote> <p>MRE's executable file has the extension <code>vxp</code> (I don't know that it stands for).</p> <p>The problem is, MRE SDK isn't supported anymore (people have claim <a href="https://news.ycombinator.com/item?id=14288221#:%7E:text=across%20multiple%20devices.-,As%20for%20the%20Series%2030%2B%2C%20the%20MRE%20was%20a%20market%20failure%2C%20never%20reaching%20a%20fraction%20of%20J2ME%2C%20Mediatek%20doesn%27t%20even%20support%20the%20SDK%20anymore.,-bitmapbrother%20on%20May" rel="nofollow noreferrer">here</a> that it's a market failure on S30+ platform), and the website, including the SDK, documentation, forum, disscussion and other things were totally deleted from the Internet (Wayback Machine archived some of the pages but not all).</p> <p>I myself got a Nokia 220 and a Nokia 225, both are S30+ platform and run MRE VXP (I tried with J2ME jar file and it cannot run, says <code>can't open this file type</code>)</p> <p>Luckily, using <a href="https://github.com/UstadMobile/ustadmobile-mre/issues/2#issuecomment-561627649" rel="nofollow noreferrer">this man's copy</a> of MRE SDK 3.0, and using <a href="https://developer.arm.com/downloads/-/rvds-and-ads" rel="nofollow noreferrer">ARM RVDS</a>, I was able to compile a simple 'Hello World' application for MRE (you can download it <a href="https://transfer.sh/rFF5Rx/Default.vxp" rel="nofollow noreferrer">here</a>).</p> <h1>Problems</h1> <p>I copy the <code>vxp</code> file to my SD card, plug it in the phone, then open the vxp file. The application refused to run, says <code>can't open this app at the moment</code>. I tried other resolution in the SDK, other SDK version (they have SDK 1.0, 2.0 and 3.0), using different compiler (GCC), and it still doesn't run.</p> <p>Check my vxp file with <code>file</code>, it outputs <code>Default.vxp: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /usr/lib/ld.so.1, not stripped</code>, but I don't know how to make it statically linked, even passing <code>-static</code> option to GCC doesn't work. (Maybe the problem is here)</p> <h1>Other <code>vxp</code> apps</h1> <p>I found there are some <code>vxp</code> store online (most are <code>*.xtgem.com</code>, I don't know why), for example <a href="http://shifat100.xtgem.com" rel="nofollow noreferrer">http://shifat100.xtgem.com</a>. I tried downloading some vxp files, put it onto my SD card and run it. Some apps work, while some don't. Some apps work for Nokia 220 but not work on Nokia 225, for example the <a href="http://www.shifat100.xtgem.com/avengers.vxp" rel="nofollow noreferrer">Advengers VXP</a> works on Nokia 220 but not on Nokia 225 (Nokia 225 has bigger screen, so I think app resolution is the problem)</p> <p>Anyway, MRE SDK has an <code>Auto adaptable</code> option for screen resolution.</p> <p><a href="https://i.stack.imgur.com/L3Ir8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L3Ir8.png" alt="mre" /></a></p> <p><a href="http://blacklove.wapamp.com/files/OperaMini4.4.V32206.vxp" rel="nofollow noreferrer">The Opera Mini VXP</a> works on both of my phones.</p> <p>I noticed that most of the VXP for Nokia are made by Gameloft - a game company.</p> <h1>File format</h1> <p>I tried opening the <a href="http://shifat100.xtgem.com/files/Asphalt%206%20Full%20Version.vxp" rel="nofollow noreferrer">Asphalt VXP</a> and that Opera Mini VXP on HxD editor and to my surprise, they are in different formats: <a href="https://i.stack.imgur.com/G4WWk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G4WWk.png" alt="vxp" /></a></p> <p>On the left is the Opera Mini VXP, which is in ELF format, on the right is the Asphalt VXP (developed by Gameloft) in unknown format, but the <code>x</code> at the beginning tells me it might be compressed by zlib.</p> <p>Tried with <code>file</code>: <code>Asphalt 6 Full Version.vxp: zlib compressed data</code> Tried with <code>7z l</code>: <code>ERROR: Asphalt 6 Full Version.vxp : Can not open the file as archive</code></p> <p>Using <code>strings</code> shows <a href="https://gist.githubusercontent.com/raspiduino/3d7ec65a47272f023048a36d05aac4fd/raw/a126f4d204530b54fd2f106ee4e5c15237f5b2a0/asphalt.txt" rel="nofollow noreferrer">some interesting result</a></p> <p>Using <code>binwalk</code>:</p> <pre><code>python -m binwalk -B &quot;Asphalt 6 Full Version.vxp&quot; DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 0 0x0 Zlib compressed data, best compression 123284 0x1E194 Zlib compressed data, best compression 278441 0x43FA9 GIF image data, version &quot;89a&quot;, 45 x 45 281257 0x44AA9 GIF image data, version &quot;89a&quot;, 45 x 45 </code></pre> <p>After extracting the files, I got 2 icon files, which seems correct for that game</p> <p><a href="https://i.stack.imgur.com/b55HG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b55HG.png" alt="icon files" /></a></p> <p>and 2 files extracted from 2 <code>Zlib compressed data</code>, using <code>file</code> on 2 files output the file type <code>data</code>. Using <code>python -m binwalk -B -A</code> for the first file at offset 0 shows many ARM instructions (which seems to be reasonable since the phone was based on Mediatek ARM chip).</p> <p>I tried loaded it into IDA, but since I don't know the start address, it's really hard to get where the entry point is.</p> <p>Using <code>strings</code> also shows <a href="https://gist.githubusercontent.com/raspiduino/3d7ec65a47272f023048a36d05aac4fd/raw/ed4a2fea70d644a2220cfd9eec733f77bc7c9749/0.txt" rel="nofollow noreferrer">interesting things</a>. Things start with <code>vm_</code> like</p> <pre><code>vm_app_log vm_cell_open vm_cell_close vm_cell_get_cur_cell_info vm_cell_get_nbr_cell_info vm_cell_get_nbr_num </code></pre> <p>are some standart MRE API calls while things like</p> <pre><code>Unknown signal Invalid Operation Divide By Zero Overflow Underflow Inexact Result : Heap memory corrupted Abnormal termination Arithmetic exception: Illegal instruction Interrupt received Illegal address Termination request Stack overflow Redirect: can't open: Out of heap memory User-defined signal 1 User-defined signal 2 Pure virtual fn called C++ library exception </code></pre> <p>seems to be runtime error messages.</p> <p>Using <code>strings</code> on the file at <a href="https://gist.github.com/raspiduino/3d7ec65a47272f023048a36d05aac4fd/raw/c233fd7ad01ec8bf93146f047b08a4ea918389b2/1E194.txt" rel="nofollow noreferrer">1E194</a> suggests that this might be a resource file, but note that strings in that file are also existed in the original VXP file without extracting (is binwalk wrong?)</p> <p>Back to Opera Mini VXP, this is an ELF file, shows by <code>file</code>: <code>OperaMini4.4.V32206.vxp: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped</code>.</p> <p>Try loading it into IDA, it seems unreasonable since the main function goes nowhere. I also not sure what is <code>supervisor call</code></p> <p><a href="https://i.stack.imgur.com/GXbQF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GXbQF.png" alt="ida" /></a></p> <p>If I patch any path of the file, for example change a character in a resource string (but still remains the same size as the original), it will output <code>can't open this app at the moment</code>.</p> <p>I have read <a href="https://answers.microsoft.com/en-us/mobiledevices/forum/all/nokia-s30-development-signing-support-in-mre/25c9ad93-644d-4543-9c0d-f539aad27c59" rel="nofollow noreferrer">here</a> that the applications which runs on Nokia S30+ will need to be signed. If that's true, that will explain why patching doesn't work.</p> <p>Can you figure out informations about the MRE VXP format, how to get it signed, and how to run self developed MRE app on Nokia phones? Thanks!</p> <h1>Notes</h1> <p>I am also trying reversing the phone's firmware to find out how <code>vxp</code> file loaded and executed. After doing some Google Search I found some example firmware source code for the MAUI platform (you can think of it like an OS), like <a href="https://github.com/hyperion70/HSPA_MOLY.WR8.W1449.MD.WG.MP.V16" rel="nofollow noreferrer">this</a> repo, but I cannot find out how it load vxp files.</p> <p>If anyone is also interested in reversing this firmware, tell me and I will open a new post :)</p>
What's the format of Mediatek MRE VXP file and how to create a workable VXP binary?
|arm|elf|
<p>I don't know if this should be an answer or not. I finally managed to use <code>lldb</code> remote debugging but again faced more challenges but eventually prevailed.</p> <p>What I did was instead of using <code>lldb</code> platform command I used <code>lldb gdbserver</code> command which function correctly but had a caveat of accepting local connections only and rejecting connections from external addresses. So I had to use iptables' nat table to finally make it work.</p> <pre><code>iptables -I INPUT -t nat -p tcp -d 192.168.43.1 --dport 2000 -j SNAT --to-source 192.168.43.1:50000 ./data/local/tmp/lldb-server g 192.168.43.1:2000 </code></pre> <p>Then on <code>lldb</code> client I did</p> <pre><code>gdb-remote 192.168.43.1:2000 </code></pre>
30493
2022-06-09T03:41:35.787
<p>I currently don't have a pc. I have two rooted devices <code>Arm64</code> host device with Debian rootfs and the device to be debugged which contains the lldb-server binary <code>armv7</code>. I am trying to remote debug my android device using LLDB. I pulled the <code>lldb-server</code> binary from android ndk24 and put it in <code>/data/local/tmp</code>. Installed Debian sid on <code>another term</code> and <code>apt</code> installed <code>lldb</code>.</p> <p>I connected client device via wifi-hotspot (one with <code>lldb-server</code>) using the host with the linux rootfs.</p> <p>The commands I ran on server device</p> <pre><code>./data/local/tmp/lldb-server platform --listen &quot;*:2000&quot;  --server </code></pre> <p>Checked using <code>netstat</code> and the lldb-server had bound to all addresses(<code>0.0.0.0:2000</code>)</p> <p>On host(client <code>lldb</code>) device in <code>debian sid</code> terminal I ran:</p> <pre><code>apt install lldb lldb platform select remote-android platform connect connect://192.168.201.132:2000 </code></pre> <p>Then I got <code>error failed connect port</code>.</p> <p>However, using <code>GDB</code> and <code>gdbserver</code> everything worked perfectly. I have tried installing <code>lldb</code> on <code>debian buster</code> but same result and even ran the <code>lldb-server</code> binary on the host(device with <code>debian sid</code>) but same result. Right now I'm stuck here. How do I solve this?</p> <p>Help will be greatly appreciated. Thank you.</p> <p><strong>Edit</strong> Here is output of <code>telnet</code></p> <pre><code>root@localhost:~# telnet 192.168.43.1 2000 Trying 192.168.43.1... Connected to 192.168.43.1. Escape character is '^]'. Connection closed by foreign host. root@localhost:~# telnet 192.168.43.1 5555 Trying 192.168.43.1... Connected to 192.168.43.1. Escape character is '^]'. Killed root@localhost:~# </code></pre> <p>And heres same network output from lldb.</p> <pre><code>lldb) platform select remote-android Platform: remote-android Connected: no (lldb) platform connect connect;//192.168.43.1:2000 error: Invalid URL: connect;//192.168.43.1:2000 (lldb) platform connect connect://192.168.43.1:2000 error: Failed to connect port (lldb) </code></pre> <p>And now I dont really know the problem. Should i try installing on a different rootfs? Let me do that.</p> <p><strong>Edit 2</strong></p> <p>Installed ubuntu focal and still got same results on lldb 10.0.0.</p>
LLDB debugging on android?
|debugging|android|arm|lldb|
<p>Turns out this processor doesn't support hardware watchpoints or the debuggers dont have support for hardware watchpoints for my processor. After trying to set a watchpoint with <code>lldb</code> lldb reported that there are <code>0</code> available hardware watchpoints. So there is no way around this one.</p>
30498
2022-06-10T11:35:14.403
<p>After failing to find a solution to <a href="https://reverseengineering.stackexchange.com/questions/30493/lldb-debugging-on-android">this</a> I have started using Gdb and have encountered another error.</p> <p><code>Gdb</code>fails to set hardware watchpoint when I'm remote debugging a rooted <code>arm7-a</code> target. It supports hardware watchpoints and breakpoints according to the Technical references manual.</p> <blockquote> <p><strong>Breakpoints and watchpoints</strong></p> <p>The processor supports six breakpoints, four watchpoints, and a standard Debug Communications Channel (DCC). Four of the breakpoints match only to virtual address and the other two match against either virtual address or context ID, or Virtual Machine Identifier (VMID). All the watchpoints can be linked to two breakpoints to enable a memory request to be trapped in a given process context.</p> </blockquote> <p>If i set a hardware watchpoint on <code>gdb</code> then it says failed to set hardware watchpoint. But if i change the parameter using:</p> <pre><code>set can-use-hw-watchpoints 0 </code></pre> <p>I can set the software watchpoint successfully but it is very slow and laggy. I really dont understand why its failing. Could it be because the watchpoint is not correctly aligned?</p> <p>The processor is an arm cortex-a7 and i can link the technical references manual if needed. Help would be greatly appreciated.</p>
Gdb hardware watchpoint error on android
|debugging|android|arm|gdb|breakpoint|
<ol> <li><code>rsi</code> is being copied into <code>arg_0</code></li> <li><code>lea rsi, [qword_1F39B60]</code> means <code>rsi</code> would contain a pointer to <code>qword_1F39B60</code></li> <li>Yes it is allowed, it's a mem-&gt;reg operation.</li> <li>I believe that <code>ds</code> and <code>ss</code> are usually set to zero when using 64bit mode, but <code>cs</code> is set to the start of the text segment, so is the only segment register that can be used to generate a valid address. (There are some conflicting views on this, and I may be wrong)</li> <li>Usually <code>rbp</code> will be set to <code>rsp</code> before space is allocated on the stack:</li> </ol> <pre><code>push rbp ; save the current frame pointer mov rbp, rsp ; create a new frame sub rsp, rax ; allocate space on the stack </code></pre> <p>However, it looks like this program is optimised (omit frame pointers) and is using <code>rsp</code> for all references, so <code>rbp</code> may be used for anything in this case but not its usual job.</p>
30505
2022-06-11T15:08:26.783
<p>I am having problems distinguishing whether the address is loaded or the content from the address. Please help me clarify.</p> <pre><code>1. mov [rsp+78h+arg_0], rsi 2. mov rsi, cs:qword_1F39B60 3. mov [rsp+78h+arg_38], rsi </code></pre> <ol> <li>If line 2 is loading <code>1F39B60</code> in <code>rsi</code> or the contents of <code>1F39B60</code> in <code>rsi</code>?</li> <li>Would <code>lea rsi, [qword_1F39B60]</code> be the same?</li> <li>If non bracket using <code>mov</code> action on a memory even allowed or this is just a visual IDA thing?</li> <li>Can you explain to me why it shows <code>cs:</code> even though <code>qword_1F39B60</code> is in the <code>.data segment</code>? Shouldn't it be <code>ds:</code>?</li> </ol> <p>Last but not the least this isn't directly connected to my main question but is <code>rsp+78h</code> a fancy way of saying <code>rbp</code> by the disassembler?</p>
What is the outcome of mov on non bracket memory locations?
|assembly|x86-64|intel|
<p>As we know there are limitations to using watchpoints: there are a finite amount of watchpoints permitted per architecture (typically 4) and the “watched” size of memory usually caps out at 8 bytes. Therefore, it is important to delete them after they are no longer needed.</p> <p>You can delete a watchpoint in <code>lldb</code> using the <code>watchpoint delete</code> command and passing the watchpoint ID as an argument.</p> <p>Example:</p> <pre><code>(lldb) watchpoint delete 1 1 watchpoints deleted. </code></pre> <p>Or we can use,</p> <pre><code>(lldb) w delete 1 1 watchpoints deleted. </code></pre> <p>To delete all watchpoints - simply omit the last argument.</p>
30508
2022-06-12T12:34:47.810
<p>After trying to use watch command, LLDB said the device had 0 available hardware watchpoints. In GDB you can use</p> <pre><code>set can-use-hw-watchpoints 0 </code></pre> <p>How do you disable hardware watchpoints in LLDB?</p>
How to use software watchpoints in LLDB?
|debugging|debuggers|breakpoint|lldb|
<p>The overall structure of the file appears to be that of a <a href="https://en.wikipedia.org/wiki/Resource_Interchange_File_Format" rel="nofollow noreferrer">RIFF</a> file. This format consists of a number of separate 'chunks' of data each preceded by a header containing a 4 byte chunk type and a 4 byte (little-endian) length.</p> <p>Your file begins -</p> <pre><code> Offset Type Length Data ======== ====== ======== ======== 0000000: 'ampf' 00000004 'aaaa' 000000C: 'meta' 00000004 00000007 // probably the version of the AMXD file 0000028: 'ptch' 000126C0 ... .... </code></pre> <p>Looking at a couple of <code>.amxd</code> files online (with meta = 1) these only contain the <code>ampf</code> <code>meta</code> and <code>ptch</code> chunks and the <code>ptch</code> chunk in each case is total in json format.</p> <p>This is not the case with your file (with <code>meta</code> = 7). Interestingly, the data in the <code>ptch</code> chunk seems have it's own header (with values in big-endian format) before the json data.</p> <pre><code>00000030: `ax@c` 00000010 00000000 000125E8 </code></pre> <p>With only a single example it's hard to infer much from this other than the last value here is a length.</p> <hr /> <p><strong>Edit:</strong> Looking at <code>Infinity.amxd</code> in the github repository you linked to sheds more light on the files with <code>meta</code> = 7.</p> <p>The top-level structure it that of a RIFF file (with little-endian values)</p> <pre><code>00000000: 'ampf' 00000004 6D6D6D6D 0000000C: 'meta' 00000004 00000007 00000018: 'ptch' 0000D13A .... // (This chunk contains the whole rest of the file) </code></pre> <p>Digging further, it appears that the <code>ptch</code> chunk itself contains nested chunks of data in a slightly different format (with big-endian values) -</p> <pre><code>00000020: 'mx@c' 00000010 000000000000CFFA 00000030: ... blob of data ... 0000D01A: 'dlst' 00000140 0000D012: 'dire' 00000068 0000D02A: 'type' 0000000C 'JSON' 0000D036: 'fnam' 00000018 'Infinity.amxd' 0000D04E: 'sz32' 0000000C 0000CC39 0000D05A: 'of32' 0000000C 00000010 0000D066: 'vers' 0000000C 00000000 0000D072: 'flag' 0000000C 00000011 0000D07E: 'mdat' 0000000C D9F0E203 0000D08A: 'dire' 00000068 0000D092: 'type' 0000000C 'PNG ' 0000D09E: 'fnam' 00000018 'infinityyy.png' 0000D0B6: 'sz32' 0000000C 000002B6 0000D0C2: 'of32' 0000000C 0000CC49 0000D0CE: 'vers' 0000000C 00000000 0000D0DA: 'flag' 0000000C 00000000 0000D0E6: 'mdat' 0000000C D6E92F11 0000D0F2: 'dire' 00000068 0000D0FA: 'type' 0000000C 'PNG ' 0000D106: 'fnam' 00000018 'infinity13.png' 0000D11E: 'sz32' 0000000C 000000FB 0000D13A: 'of32' 0000000C 0000CEFF 0000D136: 'vers' 0000000C 00000000 0000D142: 'flag' 0000000C 00000000 0000D14E: 'mdat' 0000000C D6F90E73 </code></pre> <p>This begins with a blob of data and is followed by a directory listing <code>dlst</code>. Each directory entry 'dire' references a file whose data can be found in the blob chunk using offset <code>of32</code> (relative to the start of the <code>ptch</code> chunk data i.e. <code>00000020</code>) and size <code>sz32</code>.</p> <p>In summary the data in the <code>Infinity.amxd</code> file consists of a <code>json</code> file and 2x <code>png</code> files all of which should now be easy to extract.</p>
30519
2022-06-15T15:03:57.697
<p>Currently, I am trying to understand <code>.amxd</code> file formats. I firstly tried to open it in VIM to see what this contains. Turns out there is a JSON file and others files also in the file (I can see PNG somewhere after the JSON).</p> <p>So I guess it is compressed, but I can't find anywhere what this is compressed with.</p> <p>Here is the header I got using <code>od -tx1 file.amxd | head</code></p> <pre><code>0000000 61 6d 70 66 04 00 00 00 6d 6d 6d 6d 6d 65 74 61 0000020 04 00 00 00 07 00 00 00 70 74 63 68 c0 26 01 00 0000040 6d 78 40 63 00 00 00 10 00 00 00 00 00 01 25 e8 0000060 7b 0a 09 22 70 61 74 63 68 65 72 22 20 3a 20 09 0000100 7b 0a 09 09 22 66 69 6c 65 76 65 72 73 69 6f 6e 0000120 22 20 3a 20 31 2c 0a 09 09 22 61 70 70 76 65 72 0000140 73 69 6f 6e 22 20 3a 20 09 09 7b 0a 09 09 09 22 0000160 6d 61 6a 6f 72 22 20 3a 20 38 2c 0a 09 09 09 22 0000200 6d 69 6e 6f 72 22 20 3a 20 30 2c 0a 09 09 09 22 0000220 72 65 76 69 73 69 6f 6e 22 20 3a 20 30 2c 0a 09 </code></pre> <p>I can find the same header in the other files.</p> <p>When using <code>file</code> I get that it contains <code>data</code>, so I guess this doesn't really help me...</p> <p>If someone can maybe help me on how to uncompress this, I would be very happy ! Thanks you !</p>
What kind of compressing/encoding is this?
|file-format|decompress|
<p>For unpacking and repacking Xamarin <code>assemblies.blob</code> + <code>assemblies.manifest</code> files you can use the Python based tool <a href="https://github.com/jakev/pyxamstore/" rel="nofollow noreferrer">Xamarin AssemblyStore Explorer (pyxamstore)</a>.</p> <h3>Unpacking</h3> <p>Make sure your current directory contains the files <code>assemblies.blob</code> and <code>assemblies.manifest</code>.</p> <pre><code>pyxamstore unpack </code></pre> <p>This will create the directory <code>out</code> which will contain the decoded dll files.</p> <h3>Repacking</h3> <p>Enter the directory where you have execute <code>pyxamstore unpack</code> and execute</p> <pre><code>pyxamstore pack </code></pre> <p>This will generate the two files <code>assemblies.blob.new</code> and <code>assemblies.manifest.new</code>. Just rename the two files to it's original names without <code>.new</code> and replace them in the APK file.</p> <p>Finally don't forget to <code>zipalign</code> and resign (<code>apksigner</code>) your APK file.</p>
30535
2022-06-20T17:02:07.890
<p>I have an APK that has assemblies in a single blob file. I could extract them successfully using decompress-assemblies.</p> <p>Is there anyway I can compress them again into assemblies.blob file or at least modify the APK to allow loading the the extracted DLL like older Xamarin APKs?</p> <p>I seem to have found that the application checks for application_config.have_assembly_store value, if it's true, it only continues if there's an assembly blob. Any idea how to change this value inside the APK?</p>
Compress Xamarin assemblies after decompression
|android|dll|decompress|c#|
<p>The problem is that the instruction pointer will always follow the program flow, unless you can alter it. They key time to alter it is on the return from a function, when the saved instruction pointer is popped off the stack into <code>eip</code>. If you can overwrite the saved instruction pointer you can redirect program execution.</p> <p>Finding a <code>jmp esp</code> at a semi-predictable place in memory allows you to redirect execution to the top of the stack reliably.</p> <p>So the process would be something like:</p> <ul> <li>Overwrite saved instruction pointer (ebp+4) on the stack with the address of <code>jmp esp</code> in the .dll.</li> <li>When the function returns, execution continues at the <code>jmp esp</code> instruction.</li> <li>The <code>jmp esp</code> then redirects execution to the top of the stack where your payload is waiting.</li> </ul>
30549
2022-06-23T21:23:49.033
<p>I was reading <a href="https://vulp3cula.gitbook.io/hackers-grimoire/exploitation/buffer-overflow" rel="nofollow noreferrer">this</a> article by Hackers Grimoire on Windows buffer overflow attacks.</p> <p>The article made sense, except for the part where the author searched for a DLL (.dll) file which contained a <code>JMP ESP</code> instruction. I understood the other requirements, such as ensuring the DLL was not protected with DEP, ASLR etc...</p> <p>Why was it necessary to find a DLL file with <code>JMP ESP</code> and note its memory address?</p>
Why is JMP ESP required in buffer overflow?
|disassembly|windows|assembly|buffer-overflow|esp|
<p>Projects has been disabled in debugger mode because not all metadata is rebased when aslr is involved which may result on confusing analysis/comments information. If you disable aslr, or your target is always loading in the same place you can do a couple of things:</p> <ul> <li><code>Ps saving@e:cfg.debug=false</code></li> </ul> <p>or just save the comments into a file:</p> <ul> <li><code>CC* &gt; comments.r2</code></li> </ul> <p>you can reload the script with the <code>. comments.r2</code> or starting the session with <code>r2 -i comments.r2 ...</code> to get the comment lines loaded into the session.</p> <p>Same goes for all the analysis information. if you append <code>*</code> to any command you get the output in r2 commands script.</p>
30562
2022-06-27T12:28:04.330
<p>I'd like to know how I can save/restore comments or possibly other metadata during a debugging session.</p> <p>I know how to save this data when running radare without the <code>-d</code> flag but I often need to debug the binary and would like a way to save <em>at least</em> the comments I made during this.</p> <p>I know about the <code>Ps</code> <code>Po</code> commands but this is what radare2 tells me</p> <pre><code>[0x7ff33eba18a0]&gt; Ps xxx radare2 does not support projects on debugged bins. Cannot save project. </code></pre> <p>I am using version:</p> <pre><code>&gt; r2 -v radare2 5.6.8 0 @ linux-x86-64 git. commit: 5.6.8 build: 2022-06-22__12:33:33 </code></pre> <p>Any help or other way of achieving this is also welcome.</p>
Radare2 - Saving information/metadata from a debugging session
|debugging|radare2|
<p>First get the <code>DataType</code> that you want, for example <code>struct foo</code>:</p> <p><code>DataType dt = getDataTypes(&quot;foo&quot;)[0];</code></p> <p>Or if it's just a pointer you'll have to get the pointer of that type.</p> <p>You said you already have the address, you'll need to make sure it's an <code>Address</code> if not already:</p> <p><code>Address addr = toAddr(0x12345678);</code></p> <p>Then create the data:</p> <p><code>Data data = createData(addr, dt);</code></p> <p>It may already have something there if that fails, you can clear out that memory (there is another API for this if you need more control, this is the simple case):</p> <p><code>clearListing(addr, addr.add(dt.getLength() - 1);</code></p>
30567
2022-06-28T12:10:49.637
<p>I have created a script in Java and I have a structure type as a string name which I want to set at given global variable which I have the Address of.</p> <p>However I can't seem to find a way to do this - like I can get the symbol or something but this doesn't allow me to change the type.</p> <p>Any ideas?</p>
[Ghidra]How to set global variable type?
|ghidra|java|
<p>Reading through the issues in the Capstone repo, there seems to have been some problems/regressions with decoding AVX-512 instructions for the last couple of years:</p> <p><a href="https://github.com/capstone-engine/capstone/issues?q=is%3Aissue+avx" rel="nofollow noreferrer">https://github.com/capstone-engine/capstone/issues?q=is%3Aissue+avx</a></p> <p>You could try building capstone from <code>next</code> and see if that works:</p> <p><a href="https://github.com/capstone-engine/capstone/tree/next" rel="nofollow noreferrer">https://github.com/capstone-engine/capstone/tree/next</a></p>
30586
2022-07-02T18:43:21.390
<p>I am trying to disassemble a binary using Capstone. I noticed that there are some instructions that cannot be disassembled, e.g. the <code>vshufi32x4</code> instruction:</p> <pre><code>from capstone import * from capstone.x86 import * md = Cs(CS_ARCH_X86, CS_MODE_64) md.detail = True #instruction_bytes = b'b\x11\r(\xfe\xf6' # The above instruction_bytes work as expected, the below print shows # 0x6: vpaddd ymm14 , ymm14, ymm30 62110d28fef6 instruction_bytes = b'b\xf3}(C\xe4\x03' # Capstone has problem with the above instruction_bytes. # IDA Pro shows the instruction vshufi32x4 ymm4, ymm0, ymm4, 3 print(instruction_bytes.hex()) # '62f37d2843e403' for c_i in md.disasm(instruction_bytes, len(instruction_bytes)): print(hex(c_i.address) + &quot;:&quot;, c_i.mnemonic, c_i.op_str, &quot;\t\t\t\t&quot;, c_i.bytes.hex()) </code></pre> <p>Other examples which cannot be disassembled by Capstone are <code>vpunpcklqdq</code> and <code>vprold</code></p> <p>What is so special about these instructions? How can I make Capstone disassemble them?</p>
Capstone not disassembling vpunpcklqdq, vprold, and vshufi32x4
|ida|disassembly|disassemblers|x86-64|capstone|
<p>I just tested this on a sample binary using single quotes around the sym name:</p> <p><code>0000d2a0 l F __TEXT,__text -[MasterViewController managedObjectContext]</code></p> <pre><code>$ llvm-objdump-9.0 -m -d --dis-symname '-[MasterViewController managedObjectContext]' MachO-iOS-armv7s-Helloworld MachO-iOS-armv7s-Helloworld: (__TEXT,__text) section -[MasterViewController managedObjectContext]: d2a0: 82 b0 sub sp, #8 d2a2: 43 f6 2a 12 movw r2, #14634 d2a6: c0 f2 00 02 movt r2, #0 d2aa: 7a 44 add r2, pc d2ac: 01 90 str r0, [sp, #4] d2ae: 00 91 str r1, [sp] d2b0: 01 98 ldr r0, [sp, #4] d2b2: 11 68 ldr r1, [r2] d2b4: 08 44 add r0, r1 d2b6: 00 68 ldr r0, [r0] d2b8: 02 b0 add sp, #8 d2ba: 70 47 bx lr </code></pre> <p>Maybe single quotes are the missing piece.</p>
30592
2022-07-04T10:29:26.140
<p>I have a mach-o binary and using <code>llvm-objdump</code> version 9 I can disassemble it. I would like to disassemble only a single function though.</p> <p>If I display the symbol table with <code>--syms</code> I can see the function I would like to disassemble:</p> <pre><code>0000000100005a54 l F __TEXT,__text -[ViewController isValidPin:] </code></pre> <p>however I cannot work out the proper command to do this.</p> <p>I have tried the following options which all just result in the usage being displayed and no indication what the issue is with the command:</p> <ul> <li><code>llvm-objdump-9 --dis-symname &quot;-[ViewController isValidPin:]&quot;</code></li> <li><code>llvm-objdump-9 --macho --dis-symname &quot;-[ViewController isValidPin:]&quot;</code></li> <li><code>llvm-objdump-9 --macho --dis-symname &quot;isValidPin&quot;</code></li> <li><code>llvm-objdump-9 --macho --dis-symname &quot;- isValidPin&quot;</code></li> <li><code>llvm-objdump-9 --macho --dis-symname &quot;- isValidPin:&quot;</code></li> <li><code>llvm-objdump-9 --macho --dis-symname &quot;-isValidPin:&quot;</code></li> </ul> <p>If I use <code>--disassemble-functions</code> with all of the above variations on the command name it just shows all the disassembly and not just <code>isValidPin</code>, including if I add the <code>--demangle</code> flag.</p> <p>If I try and do it using --start address, i.e.:</p> <pre><code>llvm-objdump-9 --macho --start-address=100005a54 </code></pre> <p>or <code>0x100005a54</code> I get the following error:</p> <pre><code>llvm-objdump-9: for the --start-address option: '100005a54' value invalid for ulong argument! </code></pre> <p>If I convert that to decimal instead it just shows the usage again. If I add a stop address as well it shows the usage regardless of whether that is in hex or dec.</p> <p>I came across <a href="https://stackoverflow.com/questions/58450076/how-can-i-make-objdump-disassemble-from-a-specified-start-address-on-macos-catal">this</a> similar question however it is trying to do this on macOS and also the answer there is just suggesting what I have tried.</p> <p>The only other mention I can find of <code>llvm-objdump</code> on here is me answering another question.</p> <p>Googling just seems to lead me to different versions of the man page or discussion on commits to the source.</p>
Disassemble specific mach-o function
|disassembly|objdump|mach-o|llvm|
<p>You can use the <code>dd</code> command or the <code>:dd</code> one if using r2frida to change any filedescriptor at runtime.</p>
30593
2022-07-04T12:04:30.150
<p>I'd like to know how to change stdin multiple times for the given binary for debugging purposes. I know I can launch the application with</p> <pre><code>r2 -r profile.r2 -d binary </code></pre> <p>Where, inside the profile.r2 file I have</p> <pre><code>program=binary stdin=./path/to/some/file </code></pre> <p>But I'd like to know how, if at all possible, to switch stdin so that I can supply multiple different inputs during a <strong>single debugging session</strong></p> <p>Will I have to use <code>r2pipe</code> and its interface or is there a simpler way of achieving this in radare2? If not possible in radare2, how would I go about doing this with <code>gdb</code>?</p> <p>Thanks for any help on this.</p>
Radare2 - changing stdin during binary debugging
|debugging|radare2|
<p>OST has a couple of courses that should give you all the background information you need:</p> <p><a href="https://opensecuritytraining.info/IntroBIOS.html" rel="nofollow noreferrer">https://opensecuritytraining.info/IntroBIOS.html</a></p> <p>Now that Xeno has relaunched OST as OST2 there is also this one, but I'm not sure how much overlap/rebranding is in it:</p> <p><a href="https://p.ost2.fyi/courses/course-v1:OpenSecurityTraining2+Arch4001_x86-64_RVF+2021_v1/about" rel="nofollow noreferrer">https://p.ost2.fyi/courses/course-v1:OpenSecurityTraining2+Arch4001_x86-64_RVF+2021_v1/about</a></p> <p>N.B. I haven't taken either of these courses myself, but I've been through several others on OST and they were excellent, these are on my todo list</p>
30609
2022-07-09T03:06:44.523
<p>I have a 845 g7 with a bios 1.06, which has a load of CVEs which allow SMM and DXE exploits:</p> <p><a href="https://support.hp.com/ca-en/drivers/selfservice/hp-elitebook-845-g7-notebook-pc/37506818" rel="nofollow noreferrer">https://support.hp.com/ca-en/drivers/selfservice/hp-elitebook-845-g7-notebook-pc/37506818</a> (under the UEFI bios versions &gt; 1.06).</p> <p>However, I have no real idea how to exploit these. I'm a programmer (C++), however mostly just corporate applications and data management. It would be great if someone could forward me to how to initiate SWSMI for example and how to actually push arbitrary code execution in the SMM, etc.</p> <p>I think I understand on a very high level what needs to be done:</p> <p>I think I'd have to start with a kernel level driver which writes to an io port to initiate an SMI, particularly SWSMI (0xb2) to initiate SMM? Which would also read from &quot;shell code&quot; which is written to registers that are inside the SWRAM.</p> <p>However, I'm trying to figure out even where to start. At the moment I'm looking into writing to ioports as a starter, which need to be kernel level drivers, such as here for example: <a href="https://github.com/tandasat/SmmExploit" rel="nofollow noreferrer">https://github.com/tandasat/SmmExploit</a>.</p> <p>There is the BRLY stuff which shows something that could be useful to someone who could understand it:</p> <p><a href="https://www.binarly.io/advisories/BRLY-2021-003/index.html" rel="nofollow noreferrer">https://www.binarly.io/advisories/BRLY-2021-003/index.html</a></p> <p>Ideas on some fun stuff like changing the motherboard serial number, etc.? The exploits give all the way down to -2 ring access.</p> <p>Thanks</p>
Help starting with UEFI/SMM exploits
|disassembly|memory|buffer-overflow|uefi|
<pre><code> my_rename &lt;- function(df, varname) { varname &lt;- ensym(varname) df %&gt;% rename(!!varname := cyl) %&gt;% group_by(!!varname) %&gt;% summarize(mean_mpg = mean(mpg)) } my_rename(mtcars, cylinder) # A tibble: 3 x 2 cylinder mean_mpg &lt;dbl&gt; &lt;dbl&gt; 1 4 26.7 2 6 19.7 3 8 15.1 </code></pre>
30622
2022-07-12T12:13:52.723
<p>I am trying to write an IDAPython script that renames some local variables (in the disassembly window) according to some logic, unfortunately I am unable/failing to use the API to do so...</p> <p>In my searches I found that set_member_name should be used since the stack frame is treated like a structure from IDA's POV, but again the documentation is not clear about how I can name a variable in a certain stack frame (or any structure for that matter)...</p> <p>I will appreciate any help.</p>
Renaming a local stack variable with IDAPython
|ida|idapython|stack-variables|idc|
<p>Code written in either language can be reversed, I think the bigger issue here is that the key checking is all performed locally. If someone can RE the algorithm, then they can create a keygen for anyone to use.</p> <p>I'd suggest that you create a web service to validate the keys, and don't expose the algorithm to reversing.</p> <p>The software could still have the key check disabled, and be distributed with a crack or pre-cracked. It's all about raising the bar high enough that no-one wants to bother spending the time breaking it.</p> <p>So definitely use obfuscation, packing, encryption, anything to make reversing more time consuming.</p>
30623
2022-07-12T18:53:57.250
<p>I actually have two choices : <strong>C</strong> or <strong>Python</strong> to create my application. On my application users will need a key (on start) to access it, the key will be verified with an algorythm on the user's computer. I'm searching for the best language to make the reverse more difficult. I know it's impossible to make an application 100% protected againt this. When looking for Python protection I saw this <a href="https://reverseengineering.stackexchange.com/questions/22648/best-way-to-protect-source-code-of-exe-program-running-on-python">question</a>, and so I'm wondering if <strong>C</strong> is better than <strong>Python</strong> for this kind of app.</p>
Python or C for a Qt application and security against reverse engineering
|decompilation|c|python|obfuscation|qt|
<p>I'm not aware of any way to do what you're asking (INAE), however you could try this to obtain readable source using objdump:</p> <pre><code>objdump -l --source-comment &lt;file&gt;.o | grep -e '^\/' -e '^#' </code></pre> <p>This will include the filename and line number for each line of source while excluding the assembly.</p>
30631
2022-07-13T17:57:27.113
<p>Right now, I'm using a combination of <code>gcc -g</code> and the <code>objdump -S</code> modes to generate assembly code with debug source code interleaved. However, I'm having trouble correlating some of the functions that were in the executable to their original source because the final executable contains source code from many different files. Is there a way to get a debug pure source representation (with no assembly) of all of the functions in an executable, using the gcc toolchain? That is, I'm looking for the source that was used for all of the functions in my executable, arranged in the order that the functions appear in the executable, so that I can compare that source to the <code>objdump -S</code> output (which I'm also comparing to Ghidra and Binary Ninja output).</p> <p>Thanks for your time in responding!</p>
Output from gcc containing all included source code?
|linux|objdump|gcc|debug|
<p>There's little in that function that could serve as a signature. The function itself consists of a single if-else statement with a direct and indirect call. The direct call could possibly be inlined in different compilations, as could the function itself (unless it's only ever called via function pointer).</p> <p>The most distinguishing characteristic of this function is that it checks a global <code>QWORD</code> against <code>NULL</code>, and invokes its virtual function at <code>+0x18</code> (passing through arguments #0-#2 as arguments #1-3 to the indirect call). That's a reasonable pattern, but also not so easy to find using IDA's standard search interfaces (though perhaps easier to find with a Hex-Rays plugin), and moreover, is likely to have false positives if the program uses a similar pattern to implement other functionality.</p> <p>I'd say the best things to look at would be:</p> <ol> <li><code>sub_7FF7067A0450</code>. Does it have any better characteristics, such as: is it called within a few functions of a named export; does it have any unique strings, API calls, code sequences, etc., or do any of its nearby called/calling functions have any of those things?</li> <li>Callers of <code>sub_7FF7067A01F0</code> (same questions as above).</li> <li>Look for other references to <code>qword_7FF709F91498</code>. Presumably this pointer starts as <code>NULL</code>, and at least one location writes a non-<code>NULL</code> value to it. Is there anything unique about the location(s) that write to it? If so, you can find the write to <code>qword_7FF709F91498</code>, and then use cross-references to find the function in your question. I'd start with the writes before moving on to other locations that read from <code>qword_7FF709F91498</code>, though either could work.</li> <li>Since this is a global variable, maybe it's statically initialized by the runtime system prior to <code>main</code>? That could give you an easy way to find the constructor of this object, at which point, cross-references could help.</li> </ol>
30638
2022-07-14T20:41:46.740
<p>I have a function with the pseudocode of</p> <pre><code>__int64 __fastcall sub_7FF7067A01F0(__int64 a1, __int64 a2, unsigned int a3) { if ( qword_7FF709F91498 ) return (*(__int64 (__fastcall **)(ID2D1Geometry *, __int64, __int64, _QWORD))(*(_QWORD *)qword_7FF709F91498 + 24i64))( qword_7FF709F91498, a1, a2, a3); else return sub_7FF7067A0450(a1); } </code></pre> <p>Considering there don't appear to be any strings I could easily search for , would there been any other possible way to speed up the process of finding this in IDA without going through lots of functions (for example , anything IDA could search for or anything that could be quickly identified?</p> <p>Any assistance would be greatly appreciated. Thank you.</p>
How to speed up finding a function from pseudocode in IDA?
|ida|c++|functions|
<p>This seems like a bug, there is an open issue in the Capstone repo that seems to fit: <a href="https://github.com/capstone-engine/capstone/issues/1640" rel="nofollow noreferrer">https://github.com/capstone-engine/capstone/issues/1640</a></p>
30644
2022-07-15T19:14:09.253
<p>Given the opcode <code>80 3d 1d b0 09 00 00</code>.</p> <p>The corresponding capstone instruction is</p> <pre><code>&lt;CsInsn 0x66a4 [803d1db0090000]: cmp byte ptr [rip + 0x9b01d], 0&gt; </code></pre> <p>and has the following properties (<code>c_i</code> being the name of the instruction object)</p> <pre><code>c_i.disp: 0x9b01d c_i.disp_offset: 0x2 c_i.disp_size 0x4 </code></pre> <p>A different instruction</p> <p><code>&lt;CsInsn 0xd3de [66c705714309000000]: mov word ptr [rip + 0x94371], 0&gt;</code> has:</p> <pre><code>c_i.disp: 0x94371 c_i.disp_offset: 0x3 c_i.disp_size: 0x2 </code></pre> <p>The first two properties make sense to me. But why is the <code>disp_size</code> <code>0x2</code> and not <code>0x4</code>?</p>
Displacement size (disp_size) of x86 instructions
|disassembly|assembly|x86|x86-64|capstone|
<p>The cookie itself is the same size as a register, 64 bits or 32 bits.</p> <p>The global cookie is copied into a register then xor'ed with RBP/EBP and stored on the stack.</p> <p>When unwinding the frame the &quot;stack cookie&quot; is xor'ed against RBP/EBP again before being validated against the global cookie to ensure it hasn't been modified.</p> <p>Ref: <a href="https://docs.microsoft.com/en-us/archive/msdn-magazine/2017/december/c-visual-c-support-for-stack-based-buffer-protection" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/archive/msdn-magazine/2017/december/c-visual-c-support-for-stack-based-buffer-protection</a></p>
30653
2022-07-18T09:11:01.043
<p>I know that pointer to the security cookie in Load Configuration Directory is 4 bytes long for 32-bit exe and 8 bytes long for 64-bit one (<a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#load-configuration-layout" rel="nofollow noreferrer">source</a>), but what is the size of the security cookie itself?</p> <p><strong>Edit:</strong> the accepted answer links to a long article, here's the quote from it:</p> <blockquote> <p>When /GS is specified, the compiler automatically links the object file built from <strong>gs_cookie.c</strong> source file. This file <strong>defines __security_cookie as a 64-bit or 32-bit global variable of the type uintptr_t on x64 and x86, respectively.</strong></p> </blockquote> <p>And since I can't find any official source for gs_cookie.c online here's the important part, which also shows the default values:</p> <pre><code>#ifdef _WIN64 #define DEFAULT_SECURITY_COOKIE ((UINT_PTR)0x00002B992DDFA232) #else /* _WIN64 */ #define DEFAULT_SECURITY_COOKIE ((UINT_PTR)0xBB40E64E) #endif /* _WIN64 */ UINT_PTR __security_cookie = DEFAULT_SECURITY_COOKIE; </code></pre> <p>And just for completeness the documentation for <a href="https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tsts/f959534d-51f2-4103-8fb5-812620efe49b" rel="nofollow noreferrer"><code>UINT_PTR</code></a> shows it's just <code>int</code> for 32-bit and <code>__int64</code> for 64-bit (both unsigned).</p>
What is the size of a security cookie in PE file?
|pe|
<p>There is the <code>$GHIDRA_ROOT/Extensions/IDAPro/Python/7xx/loaders/xml_loader.py</code> script for IDA that loads the XML file into IDA. To create that XML file you need to use the <code>ghidra.app.util.exporter.XmlExporter</code> class.</p>
30655
2022-07-19T08:29:40.723
<p>I see many questions about how to import IDA DB into Ghidra but I interesting in the backside. I want to export Ghidra DB and import it into Ida PRO. How I can do that?</p>
How to import Ghidra DB into IDA?
|ida|ghidra|
<p>It's the 2nd operand (i.e. <code>w8</code> in your example) that is shifted before the relevant calculation is done.</p> <p>You can see the explanation in the same document you linked to in the section <a href="https://developer.arm.com/documentation/dui0473/m/arm-and-thumb-instructions/syntax-of-operand2-as-a-register-with-optional-shift" rel="noreferrer">Syntax of Operand2 as a register with optional shift</a>. This is pulled out separately in the documentation as this <code>Operand2</code> feature applies to multiple different instructions, not just <code>EOR</code>.</p>
30660
2022-07-19T18:27:51.680
<p>I'm reverse engineering an ARM64 binary and I came across the following instruction</p> <pre><code>48 05 48 4A eor w8, w10, w8, lsr #1 </code></pre> <p>I looked up the definition of ARM64's <code>eor</code> instruction here: <a href="https://developer.arm.com/documentation/dui0473/m/arm-and-thumb-instructions/eor" rel="nofollow noreferrer">https://developer.arm.com/documentation/dui0473/m/arm-and-thumb-instructions/eor</a></p> <p>Unfortunately, the information in that documentation doesn't directly address the optional <code>lsr #1</code> part of the instruction.</p> <p>I understand this instruction would generally perform a Bitwise Exclusive OR between registers w10 and w8, storing the result in register w8. What I'm unsure about is the Logical Shift Right portion. Does this shift occur on the result of the EOR, or does it first shift one of the registers and then perform the EOR?</p> <p>Also, if anyone can recommend a good tool for testing this I would be appreciative.</p> <p>Thank you.</p>
How Does ARM64 EOR with Shift Work?
|arm64|aarch64|
<p>Generally speaking Reverse Engineering is the reverse of engineering, so instead of making a plan and building a product, you start with a product and try to reconstruct the plan that was used for it (or something as close to as you can get).</p> <p>So it's kind of a puzzle and your prior knowledge can make it easier or harder for you. I mean you can technically analyze a computer, knowing nothing about computers just having a bunch of tools and then go for it. Idk you might first disassemble the housing, then you might identify components, simply the big stuff that wires go in and out from. Then you might label and identify wires and track which components are heavily interconnected or literally &quot;central&quot; to the system. Or which components are actively connected to a power cable and which receive their voltage passively. You might plug-in and out some of those components to find out which ones are crucial, which are auxiliary and which are optional. Then you might track which wires run a current or which voltage is applied to which components and how that changes over time and with interaction and so on.</p> <p>That way you probably learn rather intimate but also rather slow how things work within a computer. Though obviously it helps tremendously if you don't start from 0. If you already know what you're dealing with and can identify components and their functionality then that frees you up to analyze the stuff that you don't know. It also helps you to not break stuff irrepairably and it can make the black box a whole lot more transparent. In the sense that if you're aware of the moving parts, a whole new set of inputs and outputs of the system and thereby a whole different angle of attack might reveal itself to you.</p> <p>So whether it's particularly useful to your problem depends on the problem, but in general any prior knowledge about a system that you can acquire is probably suitable to make it easier for you.</p>
30668
2022-07-20T09:06:38.637
<p>I am completely noob in reverse engineering, and I've just started to learn it.<br/> Now I have this question in my mind, that does a reverse engineer use any computer architecture knowledge for doing his/her work? I mean in any field (software/hardware RE).</p>
Do I have to learn computer architecture for underestanding or doing reverse engineering?
|windows|assembly|x86|arm|mips|
<p>as embarrassing as this is turns out the installed version of the app on the emulator is slightly older than the one i decompiled with jadx-gui installing the same version fixed this</p>
30694
2022-07-24T17:23:21.043
<p>im trying to hook the C6494a method has 2 parameters the ge6 object and a activity object whenever i try to hook this method with a hook overload that contains both ge6 and the activity object frida throws a error saying the overload is incorrect (view image2)</p> <p><img src="https://user-images.githubusercontent.com/17355461/180567349-e3f8e1dc-5be9-4a48-b761-8a1b28dc6861.png" alt="image1" /></p> <p>this is the hook im using to hook the constructor</p> <pre><code>Java.use(&quot;com.ge6$a&quot;).$init.overload('com.ge6', 'android.app.Activity').implementation = function(a, b){ } </code></pre> <p>and this is the error frida throws when using the above hook</p> <pre><code>Error: ge6$a(): specified argument types do not match any of: .overload('android.app.Activity') at X (frida/node_modules/frida-java-bridge/lib/class-factory.js:569) at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:899) at &lt;anonymous&gt; (/frida/repl-2.js:76) at &lt;anonymous&gt; (frida/node_modules/frida-java-bridge/lib/vm.js:12) at _performPendingVmOps (frida/node_modules/frida-java-bridge/index.js:250) at &lt;anonymous&gt; (frida/node_modules/frida-java-bridge/index.js:242) at apply (native) at ne (frida/node_modules/frida-java-bridge/lib/class-factory.js:620) at &lt;anonymous&gt; (frida/node_modules/frida-java-bridge/lib/class-factory.js:598) </code></pre> <p>and even if i set the overload without the ge6 object</p> <pre><code>Java.use(&quot;com.ge6$a&quot;).$init.overload('android.app.Activity').implementation = function(a){ } </code></pre> <p>frida throws this error instead</p> <pre><code>Error: Cast from 'com.ge6' to 'android.app.Activity' isn't possible at cast (frida/node_modules/frida-java-bridge/lib/class-factory.js:131) at fromJni (/_java.js) at ne (frida/node_modules/frida-java-bridge/lib/class-factory.js:617) at &lt;anonymous&gt; (frida/node_modules/frida-java-bridge/lib/class-factory.js:598) </code></pre> <p>also trying to create a new object of this subclass throws this issue instead</p> <pre><code>Process crashed: Trace/BPT trap *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** Build fingerprint: 'google/sdk_gphone_x86_arm/generic_x86_arm:11/RSR1.201013.001/6903271:userdebug/dev-keys' Revision: '0' ABI: 'x86' Timestamp: 2022-07-24 18:37:32+0100 pid: 15013, tid: 15013, name: nalds.mobileapp &gt;&gt;&gt; com.mcdonalds.mobileapp &lt;&lt;&lt; uid: 10153 signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- Abort message: 'JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xffaadb28 from void com.ge6.a(android.app.Activity, com.ge6$b)' eax 00000000 ebx 00003aa5 ecx 00003aa5 edx 00000006 edi f005e81e esi ffaad310 ebp f237ab90 esp ffaad2b8 eip f237ab99 backtrace: #00 pc 00000b99 [vdso] (__kernel_vsyscall+9) #01 pc 0005ad68 /apex/com.android.runtime/lib/bionic/libc.so!libc.so (offset 0x59000) (syscall+40) (BuildId: 6e3a0180fa6637b68c0d181c343e6806) #02 pc 00076511 /apex/com.android.runtime/lib/bionic/libc.so!libc.so (offset 0x75000) (abort+209) (BuildId: 6e3a0180fa6637b68c0d181c343e6806) #03 pc 0000040e &lt;anonymous:e3a29000&gt; *** </code></pre>
frida returning wrong overload of android method
|android|java|frida|
<p>You don't need to care about the decrypting routine because a single packed binary can contain many decrypting routines and to analyse every single one of them is time consuming. So you need to utilise the fact that a packed program is packed not from source code but from a compiled binary which mean one way or the other, the decryption routine has to decrypt to some original binary and jump to it to execute.</p> <p>There are two step in an unpacking process. The first is to find the Original Entry Point (OEP) of the program and the second is try to recover lost data (iat, steal entrypoint).</p> <p>To find the OEP you can relies on these informations:</p> <ul> <li>To jump to the OEP the program need to do a long jump (about 0x100 bytes difference) or a section jump after a decryption routine.</li> <li>Because every program need to have a startup routine so if you can find when the startup routine get execute then you can find a candidate for OEP.</li> </ul> <p>After you have found the OEP, you will need to recover obfuscated part of the packed binary (like IAT, stolen OEP, ...). Here is a hint for the IAT, you can trace where the obfuscated function which call the api and then build your own IAT and replace those call with the IAT call. And after that you can dump the binary and run it normally.</p> <p>This is just a tip of the iceberg, each protector has it own unique way to pack and unpack, each version of the protector also has a new way too. So this is just a general tutorial but with each packed binary you have to adapt to the technique it use because there is no universal way to unpack a binary and it is mathematically proven to be true (check appendix of this paper: <a href="https://www.acsac.org/2006/papers/122.pdf" rel="nofollow noreferrer">https://www.acsac.org/2006/papers/122.pdf</a>).</p>
30703
2022-07-25T20:38:47.050
<p>I am working on getting better with concepts of unpacking manually to get more clarity on understanding packing routines and decryption logic, so I am trying a few tutorials on PESpin! Previously I worked with UPX &amp; ASPack, any tutorials apart from <img src="https://www.reversing.be/article.php?story=20050726211417143" alt="this" />, will be appreciated, not looking for shortcuts like <strong>set a breakpoint, then jmp, then dump kind of stuffs</strong> . Thank you for reading this.</p>
Trying to learn more about unpacking
|x64dbg|unpacking|
<p>To your first question, you'd have to look at the code. There may be encryption, but some of the UDP packets have very small payloads, and using encryption would slow down packet processing which is the opposite of the key purpose for using UDP.. which is speed.</p> <p>For your second question, the LAN game is using UDP, and TLS needs TCP. If you think about the use case.. TLS/SSL is to verify that at least one end of the connection is who it says it is. If you're on the LAN, you don't know who is who (no DNS) and you don't care.. TLS makes no sense in this case.</p> <p>I think you're correct that the TLS connections are being used during user authN to the game servers. However, given that the session keys negotiated between 192.168.0.104 &lt;--&gt; game server are used to secure <em>only</em> communication between those 2 hosts, they would not be used between 192.168.0.104 &lt;--&gt; 192.168.0.100 on the LAN as they provide no value. They do not identify either host, and they slow down game performance.</p> <p>This is a little wordy but I hope it helps.</p>
30714
2022-07-31T12:03:35.760
<ul> <li><p>I have a <a href="https://www.mediafire.com/file/fkbsc7a9t1ymotk/grfs_rpcs3_lan_windows_packet_capture_3.pcapng/file" rel="nofollow noreferrer">PCAP file</a> (mediafire link to the file) which basically represents packet captures between 2 machines running the same game connected to each other via LAN inside RPCS3 using RPCN.</p> </li> <li><p>One of them has the inet address 192.168.0.104 and the other one is 192.168.0.100.</p> </li> <li><p>Many UDP packets are being transmitted between both which I believe is the game data.</p> </li> <li><p>If you filter the packets by &quot;tls&quot; there are 2 TLS handshakes of which I have been able to decrypt the first one using session keys.</p> </li> <li><p>It has data related to RPCS3 connection.</p> </li> <li><p>My question is that <strong>are the UDP packets encrypted with the keys generated in the 2nd handshake or are they using some custom encryption</strong> that the game itself manages in its code?</p> </li> <li><p>The second SSL handshake mostly(90% sure) represents the act of logging into the RPCN network inside RPCS3.</p> </li> <li><p>How come there are no SSL handshakes between the 2 LAN machines?</p> </li> </ul>
Identifying the source of encryption used by UDP packets in a PCAP file
|encryption|protocol|networking|wireshark|packet|
<p>The 50683 INTERR means address is invalid. There is a check applied by verifier (<strong>\IDAFolder\plugins\hexrays_sdk\verifier\cverify.cpp</strong>) in <strong>cfunc_t::verify_insn</strong> function:</p> <pre><code>case cit_if: if ( maturity &lt; CMAT_TRANS1 || maturity &gt;= CMAT_CASTED ) { ea_t jea = i-&gt;cif-&gt;expr.calc_jmp_cnd_ea(); if ( jea != BADADDR &amp;&amp; i-&gt;ea != jea ) // ctree: mismatch in if-statement and its expression addresses CFAIL_QASSERT(50683, i); } </code></pre> <p>There are also many other INTERRs for decompilation in case anyone is looking. So, the correct code in my case had to have something like this:</p> <pre><code>new_item = idaapi.cexpr_t(item.cif.expr.x) new_item.ea = item.cif.expr.ea # or just new_item.ea = idaapi.BADADDR it works too item.cif.expr.swap(new_item) </code></pre>
30730
2022-08-03T07:08:04.860
<p>I am trying to modify cfunc AST from</p> <pre><code>If (a1 &amp;&amp; some_func_ptr) { some_func_ptr(); } </code></pre> <p>To</p> <pre><code>if (a1) { some_func_ptr(); } </code></pre> <p>But I constantly get INTERR 50683 error. I tried</p> <pre><code>new_item = idaapi.cexpr_t(item.cif.expr.x) item.cif.expr.swap(new_item) </code></pre> <p>Also many other attempts to modify other parts of AST fail in the same way. I suspect that it has something to do with thisown flag, but various changes did nothing.</p>
Decompilation output modification in IDA Pro
|ida|decompilation|hexrays|
<p>If you use a hex editor and set <code>e_phentsize</code> (offset 0x2a) to 0x20 it works fine, I believe 0x20 is standard for 32bit.</p> <pre><code>$ readelf -l libTheArmKing.so Elf file type is DYN (Shared object file) Entry point 0x0 There are 8 program headers, starting at offset 52 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000034 0x00000034 0x00000034 0x00100 0x00100 R 0x4 INTERP 0x000134 0x00000134 0x00000134 0x00013 0x00013 R 0x1 [Requesting program interpreter: /system/bin/linker] LOAD 0x000000 0x00000000 0x00000000 0x61a6c 0x61a6c R E 0x1000 LOAD 0x062688 0x00063688 0x00063688 0x4b904 0xb950c RW 0x1000 DYNAMIC 0x062d24 0x00063d24 0x00063d24 0x00108 0x00108 RW 0x4 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0 EXIDX 0x05d6dc 0x0005d6dc 0x0005d6dc 0x00f80 0x00f80 R 0x4 GNU_RELRO 0x062688 0x00063688 0x00063688 0x00978 0x00978 RW 0x8 Section to Segment mapping: Segment Sections... 00 01 .interp 02 .interp .dynsym .dynstr .hash .rel.dyn .rel.plt .plt .text .turn .main .maria .ARM.extab .ARM.exidx .rodata 03 .data.rel.ro.local .fini_array .init_array .data.rel.ro .dynamic .got .data .ced .bss 04 .dynamic 05 06 .ARM.exidx 07 .data.rel.ro.local .fini_array .init_array .data.rel.ro .dynamic .got </code></pre> <p>Detailed info:</p> <p>You can calculate the correct sizes by running <code>man 5 elf</code> and looking at the <code>Elf32_Phdr</code> or <code>Elf64_Phdr</code> structure definitions and adding up their element sizes, giving you 0x20 for <code>Elf32_Phdr</code> and 0x38 for <code>Elf64_Phdr</code>.</p> <pre><code> typedef struct { uint32_t p_type; Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; uint32_t p_filesz; uint32_t p_memsz; uint32_t p_flags; uint32_t p_align; } Elf32_Phdr; typedef struct { uint32_t p_type; uint32_t p_flags; Elf64_Off p_offset; Elf64_Addr p_vaddr; Elf64_Addr p_paddr; uint64_t p_filesz; uint64_t p_memsz; uint64_t p_align; } Elf64_Phdr; </code></pre>
30732
2022-08-04T04:41:24.663
<p>I have extracted the <code>.so</code> binary <code>libTheArmKing.so</code> (located in <code>lib</code> directory in <code>apk</code> file) from <a href="https://platinmods.com/threads/world-war-heroes-ww2-fps-ver-1-33-2-mod-menu-apk-unlimited-ammo-ohk-god-mode-radar-anti-kick-more-15-features.120570/" rel="nofollow noreferrer">a hack of World War Heroes game</a> (an Android game) from Plantimod Forum.</p> <p><code>file</code> output:</p> <pre><code>libTheArmKing.so: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), corrupted program header size, stripped </code></pre> <p><code>readelf</code> output:</p> <pre><code>ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: ARM Version: 0x1 Entry point address: 0x0 Start of program headers: 52 (bytes into file) Start of section headers: 712948 (bytes into file) Flags: 0x5000000, Version5 EABI Size of this header: 52 (bytes) Size of program headers: 17 (bytes) Number of program headers: 8 Size of section headers: 40 (bytes) Number of section headers: 28 Section header string table index: 27 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 00000134 000134 000013 00 A 0 0 1 [ 2] .dynsym DYNSYM 00000148 000148 006210 10 A 3 1 4 [ 3] .dynstr STRTAB 00006358 006358 007038 00 A 0 0 1 [ 4] .hash HASH 0000d390 00d390 0028a8 04 A 2 0 4 [ 5] .rel.dyn REL 0000fc38 00fc38 000c50 08 A 2 0 4 [ 6] .rel.plt REL 00010888 010888 0002a8 08 AI 2 7 4 [ 7] .plt PROGBITS 00010b30 010b30 000410 00 AX 0 0 4 [ 8] .text PROGBITS 00010f40 010f40 048398 00 AX 0 0 4 [ 9] .turn PROGBITS 000592d8 0592d8 000044 00 AX 0 0 4 [10] .main PROGBITS 0005931c 05931c 001ba8 00 AX 0 0 4 [11] .maria PROGBITS 0005aec4 05aec4 000010 00 AX 0 0 4 [12] .ARM.extab PROGBITS 0005aed4 05aed4 002808 00 A 0 0 4 [13] .ARM.exidx ARM_EXIDX 0005d6dc 05d6dc 000f80 08 AL 8 0 4 [14] .rodata PROGBITS 0005e660 05e660 00340c 00 A 0 0 16 [15] .data.rel.ro[...] PROGBITS 00063688 062688 000048 00 WA 0 0 4 [16] .fini_array FINI_ARRAY 000636d0 0626d0 000008 00 WA 0 0 4 [17] .init_array INIT_ARRAY 000636d8 0626d8 000010 00 WA 0 0 4 [18] .data.rel.ro PROGBITS 000636e8 0626e8 00063c 00 WA 0 0 8 [19] .dynamic DYNAMIC 00063d24 062d24 000108 08 WA 3 0 4 [20] .got PROGBITS 00063e30 062e30 0001d0 00 WA 0 0 4 [21] .data PROGBITS 00064000 063000 04af6c 00 WA 0 0 8 [22] .ced PROGBITS 000aef6c 0adf6c 000020 00 WA 0 0 4 [23] .bss NOBITS 000aef90 0adf8c 06dc04 00 WA 0 0 8 [24] .comment PROGBITS 00000000 0adf8c 000023 01 MS 0 0 1 [25] .note.gnu.go[...] NOTE 00000000 0adfb0 00001c 00 0 0 4 [26] .ARM.attributes ARM_ATTRIBUTES 00000000 0adfcc 00002f 00 0 0 1 [27] .shstrtab STRTAB 00000000 0adffb 0000f8 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), y (purecode), p (processor specific) There are no section groups in this file. readelf: Error: The e_phentsize field in the ELF header is less than the size of an ELF program header </code></pre> <p>When I load this <code>.so</code> into IDA, IDA cannot detect it as <code>ELF</code>, and only show <code>Binary File</code>. Also, it cannot detect the entry point automatically.</p> <p>I think the mod author made this corruption <em>on purpose</em> to make it harder to reverse engineering his mod.</p> <p><a href="https://transfer.sh/P1Gxoa/libTheArmKing.so" rel="nofollow noreferrer">Here</a> is the binary.</p> <p>So my question is: How to fix the header of this <code>.so</code> to make it loadable to IDA?</p> <p>Thank you!</p> <p><strong>EDIT 1</strong>: Ghidra is able to load and detect this as ELF, but skipped some sections due to incorrect address.</p>
Reverse engineering ELF: The e_phentsize field in the ELF header is less than the size of an ELF program header
|ida|android|arm|elf|apk|
<p>Yes, the protocol was reverse engineered. The results can be found at <a href="https://gist.github.com/mhasdf/489c6d35c830dda512143d0374bb17ce" rel="nofollow noreferrer">https://gist.github.com/mhasdf/489c6d35c830dda512143d0374bb17ce</a></p>
30740
2022-08-07T15:30:36.280
<p>I want to remote-control my Mackie Thump GO loudspeaker without using the official app, so that I can build an app that can control music and the speaker at the same time (and maybe even do some automation). Has anyone reverse engineered the bluetooth protocol of a Mackie Thump GO loudspeaker?</p>
Has anyone reverse engineered the bluetooth protocol of a Mackie Thump GO loudspeaker?
|bluetooth|
<pre><code>0: kd&gt; .reload /f tcpip.sys 0: kd&gt; lm m tcp* start end module name fffff803`575f0000 fffff803`578dc000 tcpip (pdb symbols) f:\symbols\tcpip.pdb\F733C426A17672D6B1CD7EFD711F586C1\tcpip.pdb </code></pre> <p>it is a public function is the pdbg loaded in ida ?</p> <pre><code>0: kd&gt; x /v tcpip!IppInitializePathSet pub func fffff803`57748790 0 tcpip!IppInitializePathSet (IppInitializePathSet) </code></pre> <p>you can find the function by using the relative address from module base</p> <pre><code>0: kd&gt; ? tcpip!IppInitializePathSet-tcpip Evaluate expression: 1410960 = 00000000`00158790 </code></pre> <p>the function as is doesnt appear to be complicated this is not from 2019 but winx</p> <pre><code>0: kd&gt; uf tcpip!IppInitializePathSet tcpip!IppInitializePathSet: fffff803`57748790 48895c2410 mov qword ptr [rsp+10h],rbx fffff803`57748795 4889742418 mov qword ptr [rsp+18h],rsi fffff803`5774879a 57 push rdi fffff803`5774879b 4883ec20 sub rsp,20h fffff803`5774879f 448b05c2ba0a00 mov r8d,dword ptr [tcpip!IppDefaultMemoryLimitOfBuffers (fffff803`577f4268)] fffff803`577487a6 488d8190010000 lea rax,[rcx+190h] fffff803`577487ad 4889442430 mov qword ptr [rsp+30h],rax fffff803`577487b2 8bfa mov edi,edx fffff803`577487b4 48b8abaaaaaaaaaaaaaa mov rax,0AAAAAAAAAAAAAAABh fffff803`577487be 488bf1 mov rsi,rcx fffff803`577487c1 49f7e0 mul rax,r8 fffff803`577487c4 48c1ea07 shr rdx,7 fffff803`577487c8 85d2 test edx,edx fffff803`577487ca 7405 je tcpip!IppInitializePathSet+0x41 (fffff803`577487d1) tcpip!IppInitializePathSet+0x3c: fffff803`577487cc 3bfa cmp edi,edx fffff803`577487ce 0f47fa cmova edi,edx tcpip!IppInitializePathSet+0x41: fffff803`577487d1 8a05a9e50a00 mov al,byte ptr [tcpip!TcpipIsServerSKU (fffff803`577f6d80)] fffff803`577487d7 41b8c0010000 mov r8d,1C0h fffff803`577487dd f6d8 neg al fffff803`577487df 1bdb sbb ebx,ebx fffff803`577487e1 33d2 xor edx,edx fffff803`577487e3 81e3801f0000 and ebx,1F80h fffff803`577487e9 e8d295f4ff call tcpip!memset (fffff803`57691dc0) fffff803`577487ee 4533c9 xor r9d,r9d fffff803`577487f1 89be4c010000 mov dword ptr [rsi+14Ch],edi fffff803`577487f7 4533c0 xor r8d,r8d fffff803`577487fa 8d9380000000 lea edx,[rbx+80h] fffff803`57748800 488d4c2430 lea rcx,[rsp+30h] fffff803`57748805 4c8b1524760c00 mov r10,qword ptr [tcpip!_imp_RtlCreateHashTableEx (fffff803`5780fe30)] fffff803`5774880c e89f0425f9 call nt!RtlCreateHashTableEx (fffff803`50998cb0) fffff803`57748811 84c0 test al,al fffff803`57748813 7533 jne tcpip!IppInitializePathSet+0xb8 (fffff803`57748848) tcpip!IppInitializePathSet+0x85: fffff803`57748815 833d88640a0001 cmp dword ptr [tcpip!MICROSOFT_TCPIP_PROVIDER_Context+0x24 (fffff803`577eeca4)],1 fffff803`5774881c 7523 jne tcpip!IppInitializePathSet+0xb1 (fffff803`57748841) tcpip!IppInitializePathSet+0x8e: fffff803`5774881e f6057ee40a0008 test byte ptr [tcpip!Microsoft_Windows_TCPIPEnableBits+0x3 (fffff803`577f6ca3)],8 fffff803`57748825 741a je tcpip!IppInitializePathSet+0xb1 (fffff803`57748841) tcpip!IppInitializePathSet+0x97: fffff803`57748827 4c8d0d22e50700 lea r9,[tcpip!`string' (fffff803`577c6d50)] fffff803`5774882e 488d15331e0700 lea rdx,[tcpip!TCPIP_MEMORY_FAILURES (fffff803`577ba668)] fffff803`57748835 488d0d44640a00 lea rcx,[tcpip!MICROSOFT_TCPIP_PROVIDER_Context (fffff803`577eec80)] fffff803`5774883c e8e323faff call tcpip!McTemplateK0z_EtwWriteTransfer (fffff803`576eac24) tcpip!IppInitializePathSet+0xb1: fffff803`57748841 b89a0000c0 mov eax,0C000009Ah fffff803`57748846 eb0a jmp tcpip!IppInitializePathSet+0xc2 (fffff803`57748852) tcpip!IppInitializePathSet+0xb8: fffff803`57748848 488bce mov rcx,rsi fffff803`5774884b e88491faff call tcpip!RtlInitializeScalableMrswLock (fffff803`576f19d4) fffff803`57748850 33c0 xor eax,eax tcpip!IppInitializePathSet+0xc2: fffff803`57748852 488b5c2438 mov rbx,qword ptr [rsp+38h] fffff803`57748857 488b742440 mov rsi,qword ptr [rsp+40h] fffff803`5774885c 4883c420 add rsp,20h fffff803`57748860 5f pop rdi fffff803`57748861 c3 ret 0: kd&gt; </code></pre> <p>pseudocode from ghidra 1015</p> <pre><code>undefined8 IppInitializePathSet(void *param_1,uint param_2) { char cVar1; NTSTATUS uVar2; uint uVar3; bool bVar4; longlong local_res8; local_res8 = (longlong)param_1 + 400; uVar3 = IppDefaultMemoryLimitOfBuffers / 0xc0; if ((uVar3 != 0) &amp;&amp; (uVar3 &lt; param_2)) { param_2 = uVar3; } bVar4 = TcpipIsServerSKU != '\0'; memset(param_1,0,0x1c0); *(uint *)((longlong)param_1 + 0x14c) = param_2; _uVar2 = 0; cVar1 = RtlCreateHashTableEx(&amp;local_res8,(-(uint)bVar4 &amp; 0x1f80) + 0x80,0,0); if (cVar1 == '\0') { if ((DAT_1c01feca4 == 1) &amp;&amp; ((DAT_1c0206ca3 &amp; 8) != 0)) { McTemplateK0z_EtwWriteTransfer (&amp;MICROSOFT_TCPIP_PROVIDER_Context,&amp;TCPIP_MEMORY_FAILURES,_uVar2, L&quot;path hash table (IPNG)&quot;); } _uVar2 = 0xc000009a; } else { RtlInitializeScalableMrswLock(param_1); _uVar2 = 0; } return _uVar2; } </code></pre>
30761
2022-08-11T22:24:17.690
<p>I'm debugging windows server 2019 in windbg and I want to find function IppInitializePathSet. However, I can't find the function in IDA but I can find the symbol named tcpip!IppInitializePathSet. How to find the target function?</p>
Symbol name tcpip!IppInitializePathSet found in windbg but unable to find function IppInitializePathSet in tcpip.sys
|windows|windbg|
<p>It looks like the <code>g_37HashSeed</code> variable is initialized in the function <code>IppInitSharedHashContext</code>, in the file <code>tcpip.sys</code>:</p> <pre><code>IppInitSharedHashContext proc near sub rsp, 28h or edx, 0FFFFFFFFh mov ecx, 1 call RandomNumber mov cs:g_37HashSeed, eax mov al, 1 add rsp, 28h retn IppInitSharedHashContext endp </code></pre> <p>The <code>RandomNumber</code> function seems to be a simple LCG (<a href="https://en.wikipedia.org/wiki/Linear_congruential_generator" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Linear_congruential_generator</a>) with the parameters <code>a=1664525, c=1013904223</code>.</p> <p>You can find this by yourself by right clicking on <code>g_37HashSeed</code> in IDA and select <code>List cross references to...</code>.</p>
30784
2022-08-15T22:27:18.213
<p>I'm checking <code>tcpip.sys</code> file in IDA and found that in the <code>.data</code> part there is an int called <code>g_37HashSeed</code>. This seed is an input for a hash function that I look into. Can someone tell me which program or function is responsible for initializing this seed?</p> <pre><code>.data:00000001C020512C g_37HashSeed dd ? ; DATA XREF: IppSendError+33E↑r .data:00000001C020512C ; IppFindPath+31↑r ... .data:00000001C0205130 IppNSWorkerQueue dq ? ; DATA XREF: IppResolveNeighbor+31C↑o .data:00000001C0205130 ; IppNeighborSolicitationWorker+2E↑o ... .data:00000001C0205138 qword_1C0205138 dq ? ; DATA XREF: IppResolveNeighbor+315↑r .data:00000001C0205138 ; IppResolveNeighbor+339↑w ... .data:00000001C0205140 ; KSPIN_LOCK IppNSWorkItemLock .data:00000001C0205140 IppNSWorkItemLock dq ? ; DATA XREF: IppNeighborSetTimeout+253↑o </code></pre>
Which function or file is responsible for initialization of g_37HashSeed
|windows|hash-functions|
<pre><code>func_ea = 0x123450 # sub_123450 tif = ida_typeinf.tinfo_t() funcdata = ida_typeinf.func_type_data_t() assert ida_nalt.get_tinfo(tif, func_ea) assert tif.get_func_details(funcdata) for pos, argument in enumerate(funcdata): print(f'argument {pos + 1}: {argument.type}{argument.name}') </code></pre> <p>This should give you:</p> <pre><code>argument 1: aType* this argument 2: void* a2 </code></pre>
30786
2022-08-16T17:53:09.990
<p>I'm currently trying to make a hotkey to rename example functions <code>sub_123450(aType* this, void* a2)</code> to <code>aType::123450(aType* this, void* a2)</code>. I have code to rename etc. but how can I get the name of the type of the arguments to the function?</p>
IDAPython Get Function Parameter Type Name
|ida|idapython|
<p>Using &quot;Parse C Source&quot; seems to <strong>only</strong> work if all other structs referenced by the parsed structs are also defined in such header files in correct order.</p> <p>If you want to parse a struct that depends on types that have been added from another source (like plugins/scripts, PDB, or manually added), you could use a script.</p> <p>This script allows you to do that: <a href="https://github.com/Katharsas/ghidra-struct-importer" rel="nofollow noreferrer">https://github.com/Katharsas/ghidra-struct-importer</a></p> <p>(Disclaimer: I am the author of that repo)</p>
30791
2022-08-18T14:21:03.127
<p>Either by pasting from a text file or typing it out into a dialog box, which is still much faster than using Ghidra's Structure editor.</p>
Can I import a C struct into Ghidra?
|ghidra|
<p>Programs in the same project can share data types through the data type manager of each program. This can be done using drag-n-drop from one data type manager to the other or through copy (<kbd>Ctrl</kbd>+<kbd>C</kbd>) with focus on the type and paste (<kbd>Ctrl</kbd>+<kbd>V</kbd> ) with focus on the directory or top level archive where the data type should be copied to.</p>
30792
2022-08-18T14:24:00.177
<p>I'm using Ghidra to work out the structure of some binary files. No code.</p> <p>I can use the Structure Editor to define a struct, such as the header of the file format.</p> <p>But I can only find a way to create the struct in the context of one of the files and then it will not be visible to the other.</p> <p>Is there a way to make it visible to both?</p>
In Ghidra can I have two binaries loaded into tabs and create a new struct that I can use in both?
|ghidra|
<p>Manfred has 20+ years of experience and many skills, so don't expect to get there overnight. As a starting point:</p> <ol> <li>Read Beej's guides: <a href="https://beej.us/guide/bgnet/" rel="nofollow noreferrer">https://beej.us/guide/bgnet/</a></li> <li>Write a client and server, use a standard protocol like HTTP.</li> <li>Practice intercepting/modifying traffic between your client and server. Try OWASP ZAP, BurpSuite or similar.</li> <li>Write a dll</li> <li>Read up on dll injection</li> <li>Inject your dll into your client program</li> <li>Use your dll to intercept/modify client/server traffic</li> <li>Modify your server to have a fake inventory/stats/store system.</li> <li>Attempt to use integer overflows to modify the results of inventory/stats/store actions.</li> <li>Add encryption to your client/server communication</li> <li>Does your dll still intercept/modify traffic? If not, fix it</li> </ol> <p>This should give you plenty of learning without having to jump straight into the deep end with a real game. I find that attempting something without the prerequisite knowledge can result in you being sidetracked reading/learning and/or giving up.</p>
30813
2022-08-23T20:54:38.833
<p>I've looked at as many resources on Manfred and Manfred's work</p> <p>I've watched the DEFCON 25 Live talk about what he hacked.</p> <p><a href="https://youtu.be/ZAUf_ygqsDo" rel="nofollow noreferrer">Here</a></p> <p>I've also looked, listened and read the dark net diaries Part One -</p> <p><a href="https://youtu.be/3dkRG3WlAR8" rel="nofollow noreferrer">YouTube</a></p> <p><a href="https://darknetdiaries.com/episode/7/" rel="nofollow noreferrer">Dark net diaries part one</a></p> <p>Part Two -</p> <p><a href="https://youtu.be/s2tce_kQ_QE" rel="nofollow noreferrer">YouTube</a></p> <p><a href="https://darknetdiaries.com/episode/8/" rel="nofollow noreferrer">Dark net diaries part two</a></p> <p>From what my understanding is to bypass the HWID bans he ran the game and did a full memory dump, he also captured the packets sent off the game and started reverse engineering the game and started reversing the routines within a game. I've tried for a few month now to figure out how he managed to do things like this but their is no clear method on how Todo so. I figured the best place to ask would be here.</p> <p><strong>Questions</strong></p> <pre><code>- How did Manfred do it? - What can I do to get started in this field of game hacking? - What was the method Manfred had used? - Is their any resources on this? Any help is appreciated. TL;DR - How did Manfred hack so many online games </code></pre> <p>Thank you.</p>
Reversing Games like Manfred dis
|assembly|game-hacking|binary-editing|api-hacking|
<p>By default IDA does not load PE resources as they rarely contain code or other content required for disassembly. You can enable [x] Load resources in the initial <em>Load new file</em> dialog but all it does is load the <code>.rsrc</code> section’s content; it won’t parse the resource data and mark up the strings but at least you’ll have the UTF-16 text somewhere. An alternative option could be to use <a href="https://pypi.org/project/pefile/" rel="nofollow noreferrer">pefile</a> to <a href="https://github.com/erocarrera/pefile/blob/wiki/ReadingResourceStrings.md" rel="nofollow noreferrer">parse the strings from the file</a></p>
30818
2022-08-24T22:10:59.960
<p>I'm going through through Challenge 3 (Task 4) of Basic Malware RE: <a href="https://tryhackme.com/room/basicmalwarere" rel="nofollow noreferrer">https://tryhackme.com/room/basicmalwarere</a></p> <p>And in Ghidra after I do analysis, I can view the .rsrc area and it shows me all the strings laid out nicely with their uID's right next to them.</p> <p>In IDA, the closest thing I've gotten is going to the Strings menu -&gt; right click -&gt; Setup and checking <code>C-Style</code>, <code>Unicode C-Style (16 bits)</code>, <code>C-Style (32 bits)</code>. After that, I start to see some of the strings show up in the strings menu (whereas before I didn't see any strings from the resource side), but they don't look anywhere near as nice to search through, and I can't seem to find any references to the <code>uID</code> property as seen in Ghidra. (and referenced in the MSDN docs here: <a href="https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadstringa?redirectedfrom=MSDN" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadstringa?redirectedfrom=MSDN</a>)</p> <p>I've read online at various places, like here: <a href="https://medium.com/@obikag/tryhackme-basic-malware-re-room-writeup-8183730100b2" rel="nofollow noreferrer">https://medium.com/@obikag/tryhackme-basic-malware-re-room-writeup-8183730100b2</a> that you'd usually use something like Resource Hacker to load <code>user32.dll</code> and view the memory that way, however I'm on MacOS and can't run Resource Hacker.</p> <p>I am wondering if there's any way to view these resource String ID's in IDA like I can in Ghidra. (See screenshots) <a href="https://i.stack.imgur.com/2edZ6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2edZ6.jpg" alt="enter image description here" /></a> <a href="https://i.stack.imgur.com/1KuuY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1KuuY.jpg" alt="enter image description here" /></a></p>
View user32.dll LoadStringA string ID's in IDA on MacOS like you can with Ghidra
|ida|ghidra|strings|
<p>you are checking the contents of callstack which would be meaningless in an x64 application</p> <p>in x64 calling convention windows passes first four arguments in registers</p> <p>use dt command to view the structures</p> <p>dt foo!blah @rcx</p>
30820
2022-08-25T21:23:06.390
<p>The struct looks like this.</p> <pre><code>typedef struct _RTL_DYNAMIC_HASH_TABLE_ENUMERATOR { struct _RTL_DYNAMIC_HASH_TABLE_ENTRY HashEntry; struct _LIST_ENTRY* CurEntry; struct _LIST_ENTRY* ChainHead; ULONG BucketIndex;// start from 0 to tablesize - 1 }; typedef struct _RTL_DYNAMIC_HASH_TABLE_ENTRY { struct _LIST_ENTRY Linkage; ULONG64 Signature; }; </code></pre> <p>The function I'm interested in is nt!RtlInitEnumerationHashTable</p> <pre><code>BOOLEAN __stdcall RtlInitEnumerationHashTable(PRTL_DYNAMIC_HASH_TABLE HashTable, PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator) </code></pre> <p>I set a bp at the function and got this</p> <pre><code>kv # Child-SP RetAddr : Args to Child : Call Site 00 ffff888e`d3bbf1c8 fffff80a`d2e72de4 : ffff8a83`e35e0d30 00000000`00000000 ffffb08f`74f38d70 00000000`00000000 : nt!RtlEnumerateEntryHashTable 01 ffff888e`d3bbf1d0 fffff80a`d261b740 : 00000000`00000000 fffff80a`d2fc9828 fffff80a`d2fc7930 ffff8a83`e9218000 : tcpip!Ipv4EnumerateAllPaths+0x2c4 02 ffff888e`d3bbf3b0 fffff80a`d3ab290e : ffff8a83`e9218000 ffff8a83`00000070 0000000c`840ff690 ffff8a83`e2802340 : NETIO!NsiEnumerateObjectsAllParametersEx+0x240 </code></pre> <pre><code>db 0xffff8a83e35e0d30 ffff8a83`e35e0d30 00 00 00 00 00 00 00 00-00 20 00 00 00 00 00 00 ......... ...... ffff8a83`e35e0d40 ff 1f 00 00 66 00 00 00-4b 00 00 00 01 00 00 00 ....f...K....... ffff8a83`e35e0d50 60 99 6d e3 83 8a ff ff-00 00 00 00 00 00 00 00 `.m............. ffff8a83`e35e0d60 00 00 00 00 00 00 00 00-03 00 00 00 00 00 00 00 ................ </code></pre> <pre><code>1: kd&gt; kP # Child-SP RetAddr Call Site 00 ffff888e`d3bbf1c8 fffff80a`d2e72de4 nt!RtlEnumerateEntryHashTable 01 ffff888e`d3bbf1d0 fffff80a`d261b740 tcpip!Ipv4EnumerateAllPaths+0x2c4 02 ffff888e`d3bbf3b0 fffff80a`d3ab290e NETIO!NsiEnumerateObjectsAllParametersEx+0x240 </code></pre> <p>I want to display the struct of the function argument Enumerator. I also want to look into the struct to get the Signature in the HashEntry. Any tips?Thanks</p>
which command in windbg to use to display the struct in function argument
|windbg|functions|
<p>Deleting bytes would move around anything after the edit, breaking pointers which would break the whole binary, so Ghidra doesn't even allow you to do it.</p>
30828
2022-08-26T15:00:52.103
<p>I was playing around with some golang code I wrote, and I modified the Go BuildID. However, I had to pad whatever I wanted the buildID to be with characters so that it was the length of the original string.</p> <p>I found that both <code>hexedit</code> and Ghirda's Byte Viewer (which allows modifying bytes) do not allow you to delete bytes (unless I cannot figure out how) from a file. I am wondering whats the reasoning, is there some sort of checksum they don't want you to overwrite? What about files where a checksum is not a concern?</p> <p>Which tool can I use to modify hex bytes, including deleting them from the file?</p>
Hexedit / Ghidra Byte Viewer wont allow deletion of bytes
|ghidra|hex|
<p>In your example, the Exec method is actually implemented in IWshShell3 as can be seen in the typelib:</p> <pre><code>[Guid(&quot;41904400-be18-11d3-a28b-00104bd35090&quot;)] interface IWshShell3 { /* Methods */ int Run(string Command, [Optional] Object&amp; WindowStyle, [Optional] Object&amp; WaitOnReturn); int Popup(string Text, [Optional] Object&amp; SecondsToWait, [Optional] Object&amp; Title, [Optional] Object&amp; Type); object CreateShortcut(string PathLink); string ExpandEnvironmentStrings(string Src); object RegRead(string Name); void RegWrite(string Name, Object&amp; Value, [Optional] Object&amp; Type); void RegDelete(string Name); bool LogEvent(Object&amp; Type, string Message, [Optional] string Target); bool AppActivate(Object&amp; App, [Optional] Object&amp; Wait); void SendKeys(string Keys, [Optional] Object&amp; Wait); WshExec Exec(string Command); /* Properties */ IWshCollection SpecialFolders { get; } IWshEnvironment Environment([Optional] Object&amp; Type) { get; } string CurrentDirectory { get; set; } } </code></pre> <p>With the following quick test code I was able to get an offset for the methods:</p> <pre><code>procedure Main; const Filename: String = 'C:\Windows\SysWOW64\wshom.ocx'; MethodName: PChar = 'Exec'; CLSID_WshShell3: TGuid = '{41904400-BE18-11D3-A28B-00104BD35090}'; var tlib: ITypeLib; hr: HRESULT; i: Integer; tinfo: ITypeInfo; typeattrib: PTypeAttr; j: Integer; FuncDesc: PFuncDesc; Name: WideString; OffSet: DWORD; begin CoInitialize(nil); OleCheck(LoadTypeLibEx(PChar(Filename), REGKIND_NONE, tlib)); for i := 0 to tlib.GetTypeInfoCount-1 do begin hr := tlib.GetTypeInfo(i, tinfo); if Succeeded(hr) then begin hr := tinfo.GetTypeAttr(typeattrib); if Succeeded(hr) then begin if IsEqualGuid(CLSID_WshShell3, typeattrib.guid) then begin WriteLn('Found IWshShell3'); for j := 0 to typeattrib.cFuncs-1 do begin hr := tinfo.GetFuncDesc(j, FuncDesc); if Succeeded(hr) then begin hr := tinfo.GetDocumentation(FuncDesc.memid, @Name, nil, nil, nil); if Succeeded(hr) then begin OffSet := j * SizeOf(Pointer); WriteLn(Format('Found Method %s at Offset: %d', [Name, Offset])); end; tinfo.ReleaseFuncDesc(FuncDesc); end; end; end; tinfo.ReleaseTypeAttr(typeattrib); end; end; end; end; </code></pre> <p>Output:</p> <pre><code>Found IWshShell3 Found Method QueryInterface at Offset: 0 Found Method AddRef at Offset: 4 Found Method Release at Offset: 8 Found Method GetTypeInfoCount at Offset: 12 Found Method GetTypeInfo at Offset: 16 Found Method GetIDsOfNames at Offset: 20 Found Method Invoke at Offset: 24 Found Method SpecialFolders at Offset: 28 Found Method Environment at Offset: 32 Found Method Run at Offset: 36 Found Method Popup at Offset: 40 Found Method CreateShortcut at Offset: 44 Found Method ExpandEnvironmentStrings at Offset: 48 Found Method RegRead at Offset: 52 Found Method RegWrite at Offset: 56 Found Method RegDelete at Offset: 60 Found Method LogEvent at Offset: 64 Found Method AppActivate at Offset: 68 Found Method SendKeys at Offset: 72 Found Method Exec at Offset: 76 Found Method CurrentDirectory at Offset: 80 Found Method CurrentDirectory at Offset: 84 </code></pre> <p>Probably need to do more checking but hopefully this gives you a start and of course, a typelib is needed. The Offset is the offset from the Interface pointer.</p>
30835
2022-08-29T02:24:08.703
<p>What is a way to lookup a COM method offset with an image, just based on the module name and method name.</p> <p>For example want to find &quot;Exec&quot; method in &quot;WScript.Shell&quot; In this scenario we know the method is in wshom.ocx. In this case it is relatively easy to find with the public symbols.</p> <p>We can find the vtable :</p> <pre><code>.text:7B471070 ; const CWshShell::`vftable'{for `IWshShell3'} .text:7B471070 ??_7CWshShell@@6BIWshShell3@@@ dd offset ?QueryInterface@CWshExec@@UAGJABU_GUID@@PAPAX@Z .text:7B471070 ; DATA XREF: CWshShell::Create(IUnknown *)+74↓o .text:7B471070 ; CWshShell::`scalar deleting destructor'(uint)+B↓o .text:7B471070 ; CWshExec::QueryInterface(_GUID const &amp;,void * *) .text:7B471074 dd offset ?AddRef@CWebPreviewDispatch@@EAGKXZ ; CWebPreviewDispatch::AddRef(void) .text:7B471078 dd offset ?Release@?$CAggregatedUnknown@$02@@UAGKXZ ; CAggregatedUnknown&lt;3&gt;::Release(void) .text:7B47107C dd offset ?GetTypeInfoCount@CWshExec@@UAGJPAI@Z ; CWshExec::GetTypeInfoCount(uint *) .text:7B471080 dd offset ?GetTypeInfo@CWshShell@@UAGJIKPAPAUITypeInfo@@@Z ; CWshShell::GetTypeInfo(uint,ulong,ITypeInfo * *) .text:7B471084 dd offset ?GetIDsOfNames@CWshShell@@UAGJABU_GUID@@PAPAGIKPAJ@Z ; CWshShell::GetIDsOfNames(_GUID const &amp;,ushort * *,uint,ulong,long *) .text:7B471088 dd offset ?Invoke@CWshShell@@UAGJJABU_GUID@@KGPAUtagDISPPARAMS@@PAUtagVARIANT@@PAUtagEXCEPINFO@@PAI@Z ; CWshShell::Invoke(long,_GUID const &amp;,ulong,ushort,tagDISPPARAMS *,tagVARIANT *,tagEXCEPINFO *,uint *) .text:7B47108C dd offset ?get_SpecialFolders@CWshShell@@UAGJPAPAUIWshCollection@@@Z ; CWshShell::get_SpecialFolders(IWshCollection * *) .text:7B471090 dd offset ?get_Environment@CWshShell@@UAGJPAUtagVARIANT@@PAPAUIWshEnvironment@@@Z ; CWshShell::get_Environment(tagVARIANT *,IWshEnvironment * *) .text:7B471094 dd offset ?Run@CWshShell@@UAGJPAGPAUtagVARIANT@@1PAH@Z ; CWshShell::Run(ushort *,tagVARIANT *,tagVARIANT *,int *) .text:7B471098 dd offset ?Popup@CWshShell@@UAGJPAGPAUtagVARIANT@@11PAH@Z ; CWshShell::Popup(ushort *,tagVARIANT *,tagVARIANT *,tagVARIANT *,int *) .text:7B47109C dd offset ?CreateShortcut@CWshShell@@UAGJPAGPAPAUIDispatch@@@Z ; CWshShell::CreateShortcut(ushort *,IDispatch * *) .text:7B4710A0 dd offset ?ExpandEnvironmentStringsA@CWshShell@@UAGJPAGPAPAG@Z ; CWshShell::ExpandEnvironmentStringsA(ushort *,ushort * *) .text:7B4710A4 dd offset ?RegRead@CWshShell@@UAGJPAGPAUtagVARIANT@@@Z ; CWshShell::RegRead(ushort *,tagVARIANT *) .text:7B4710A8 dd offset ?RegWrite@CWshShell@@UAGJPAGPAUtagVARIANT@@1@Z ; CWshShell::RegWrite(ushort *,tagVARIANT *,tagVARIANT *) .text:7B4710AC dd offset ?RegDelete@CWshShell@@UAGJPAG@Z ; CWshShell::RegDelete(ushort *) .text:7B4710B0 dd offset ?LogEvent@CWshShell@@UAGJPAUtagVARIANT@@PAG1PAF@Z ; CWshShell::LogEvent(tagVARIANT *,ushort *,ushort *,short *) .text:7B4710B4 dd offset ?AppActivate@CWshShell@@UAGJPAUtagVARIANT@@0PAF@Z ; CWshShell::AppActivate(tagVARIANT *,tagVARIANT *,short *) .text:7B4710B8 dd offset ?SendKeys@CWshShell@@UAGJPAGPAUtagVARIANT@@@Z ; CWshShell::SendKeys(ushort *,tagVARIANT *) .text:7B4710BC dd offset ?Exec@CWshShell@@UAGJPAGPAPAUIWshExec@@@Z ; CWshShell::Exec(ushort *,IWshExec * *) .text:7B4710C0 dd offset ?get_CurrentDirectory@CWshShell@@UAGJPAPAG@Z ; CWshShell::get_CurrentDirectory(ushort * *) .text:7B4710C4 dd offset ?put_CurrentDirectory@CWshShell@@UAGJPAG@Z ; CWshShell::put_CurrentDirectory(ushort *) </code></pre> <p>In this case offset at 7B4710BC points to the method I'm looking into. However I'm trying to more generally resolve this when there are no symbols available.</p> <p>Analyzing the following with WinDbg:</p> <pre><code>&quot;C:\WINDOWS\syswow64\WindowsPowerShell\v1.0\powershell.exe&quot; -Command &quot;$obj = New-Object -ComObject WScript.Shell;$obj.Exec('notepad')&quot; </code></pre> <p>Found that <strong>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll</strong> has a method <code>System.Management.Automation.ComInterop.ComTypeDesc.TryGetFunc(System.String, System.Management.Automation.ComInterop.ComMethodDesc ByRef)</code></p> <p>Which is taking &quot;Exec&quot; as the first parameter, and seems to internally use a hash table to find the method, but couldn't see how the hash table is initially populated.</p> <p>Eventually the function is called via Oleaut32!DispCallFunc which seems to have a function definition like:</p> <pre><code>HRESULT __stdcall DispCallFunc( void *pvInstance, ULONG_PTR oVft, CALLCONV cc, VARTYPE vtReturn, UINT cActuals, VARTYPE *prgvt, VARIANTARG **prgpvarg, VARIANT *pvargResult) </code></pre> <p>In this case pvInstance is pointing to the vfTable in the COM object, and oVft is the offset for the specific target method.</p> <p>Essentially I am trying to work out how do I calculate the vftable offset for &quot;WScript.Shell&quot; (with the module name already known)(, and oVft offset for method i.e. &quot;Exec&quot;, even without symbols for a COM method.</p>
Programmatically Find COM Object Method Offset in Image from Method Name
|windows|com|
<p>turns out i decompiled the wrong library the emulator i was running is 32bit where as the library i decompiled in ghidra is 64bit decompiling the 32bit lib i get the correct offsests same as expected ones</p>
30839
2022-08-31T00:48:48.897
<p>I am reverse engineering a android app shared library (.so file) and I am trying to use frida to hook a non exported native function I am using this hook</p> <pre><code>const ghidraImageBase = 0x00100000; const moduleName = &quot;libclient.so&quot;; const moduleBaseAddress = Module.findBaseAddress(moduleName); const ghidraFunction = 0x0168a7c8; const functionRealAddress = moduleBaseAddress.add(ghidraFunction - ghidraImageBase); Interceptor.attach(functionRealAddress, { onEnter: function(args) { console.log(&quot;function called&quot;); }, onLeave: function(ignored) {} }); </code></pre> <p>However function called is never logged even though the function is getting called I am pretty sure something is wrong with the addresses so I tried hooking into a exported function using the address I got from ghidra</p> <p><a href="https://i.stack.imgur.com/BlAiq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BlAiq.png" alt="![pic" /></a></p> <p>which is <code>0x014ccd08</code> and ghidra image base is equal to <code>0x00100000</code> meaning the offset of the function should be <code>0x014ccd08</code> - <code>0x00100000</code> = <code>0x013ccd08</code> however when I run</p> <pre><code>console.log(&quot;moduleBaseAddress:&quot; + Module.findBaseAddress(&quot;libclient.so&quot;)) Module.enumerateExports(&quot;libclient.so&quot;, { onMatch: function(e) { if (e.type == 'function') { if (e.name == &quot;Java_exported_function etc...&quot;) { console.log(&quot;Function found&quot;); console.log(JSON.stringify(e)) } } }, onComplete: function() {} }); </code></pre> <p>the above code execution result is</p> <pre><code>moduleBaseAddress:0xb6900000 Function recognized by name {&quot;type&quot;:&quot;function&quot;,&quot;name&quot;:&quot;Java_exported_function...&quot;,&quot;address&quot;:&quot;0xb755b9e1&quot;} </code></pre> <p>the .so library is loaded at <code>0xb6900000</code> and the function address is at <code>0xb755b9e1</code> meaning the function offset is <code>0xb755b9e1</code> - <code>0xb6900000</code> = <code>0x00c5b9e1</code> entirely different from the <code>0x013ccd08</code> I found earlier.</p> <ol> <li>Can this issue be from the ghidra settings?</li> <li>How can I get the correct offset from ghidra?</li> </ol>
ghidra returning wrong function address
|android|ghidra|memory|frida|
<p>The closest thing Ghidra has (to my knowledge) to what you want is the &quot;Processor Manual&quot; feature. You can download the <a href="https://docs.oracle.com/javase/specs/jvms/se8/jvms8.pdf" rel="nofollow noreferrer">JVM spec for version 8</a> and place it in <code>\ghidra_XX.X.X_PUBLIC\Ghidra\Processors\JVM\data\manuals</code>. The JVM.idx file describes where in the processor manual to look for the specific instruction you're asking about. If you right-clicked on a <code>bipush</code> instruction and clicked &quot;Processor manual&quot; it would then pull up your jvms8.pdf file and flip to page 396 where it talks about the <code>bipush</code> instruction.</p> <p>I'm not sure if you can add it to the end of the line. The per-instruction view in Ghidra can be customized when you click on the button at the top of the Listing window (it should say &quot;Edit the Listing fields&quot;) - that will allow you, for instance, to rearrange the order the address/instruction/bytes appear. By editing the listing, you for instance can turn on the Pcode viewer that lets you see the intermediate language.</p> <p>If you were going to turn on instruction descriptions, that is the place you would do it. However, I don't see an option to do it.</p>
30847
2022-09-01T22:39:21.930
<p>I am currently working on java byte code in GHIDRA and I was just wondering if there was a way to show the instruction descriptions like there is in IDA and x64dbg.</p> <p>For e.g</p> <p>bipush - Push byte</p>
Is there a way to show/enable mnemonic description in Ghidra?
|ghidra|
<p>For IDA Pro there are decompiler plugins available that can generate a code similar to C (if everything goes well). But IDA Pro + decompiler for the architecture you need is pretty expensive (1975 USD + 2765 USD).</p> <p>A cheaper way to get decompiled code would be <a href="https://ghidra-sre.org" rel="nofollow noreferrer">Ghidra</a>, it includes a decompiler.</p> <p>In both cases the generated code can be good or bad or even wrong. That depends on the code to be decompiled.</p> <p>If you already have IDA Pro you can can also try to integrate Ghidra decompiler into IDA using the open source IDA plugin <a href="https://github.com/Cisco-Talos/GhIDA" rel="nofollow noreferrer">GhIDA</a>.</p>
30856
2022-09-06T12:53:15.220
<p>I've used the IDA 8.0 Demo to retrieve (from a .DLL) the assembly code, such as:</p> <pre><code>; code pxor xmm0, xmm0 ucomiss xmm0, xmm1 ja short loc_67F31600 movss xmm2, cs:dword_6854E3C0 comiss xmm1, xmm2 jbe short loc_67F31630 movups xmm1, xmm2 jmp short loc_67F3160B ; subroutines loc_67F31600: movups xmm1, xmm0 movss xmm0, cs:dword_6854E3C0 loc_67F31630: movups xmm3, xmm1 movups xmm0, xmm1 movss xmm4, cs:dword_6854E43C addss xmm3, xmm1 subss xmm0, xmm2 mulss xmm1, xmm4 movups xmm5, xmm3 addss xmm2, xmm3 mulss xmm0, xmm4 subss xmm5, xmm4 divss xmm1, xmm2 divss xmm0, xmm5 jmp short loc_67F3160B loc_67F3160B: movss dword ptr [rcx+102F0h], xmm0 movss dword ptr [rcx+102ECh], xmm1 movss dword ptr [rcx+160h], xmm0 movss dword ptr [rcx+1D4h], xmm1 retn </code></pre> <p>Is there a way (with the same tool) to retrieve a more readable source code from it? Should I need IDA Pro? Can you show me the steps to do it? (so I can evaluate a purchase).</p> <p>Or which kind of other tools can you suggests to do the same? I mean: at least get C++ standard operations, with the real values placed on arrays and stuff (if possible, of course).</p>
Can I get a valid source code from this assembly?
|ida|disassembly|decompilation|c++|tools|
<p>Rebase does not help you in this case, because rebasing is meant to shift virtual addresses in flat mode or physical addresses of real-mode programs, but it does not apply to selectors of segmented protected mode programs. It is very likely that all segments of your programs get selectors spaced 8 apart, so if you got worked out that 28df is cseg01, the relation that 28e7 is cseg02 is expected. Likely the 2917 is the selector for the data segment. If you get a register dump along with the back trace, possibly you find DS=2917 to help you find the selector values of the code segments.</p>
30877
2022-09-14T03:06:03.520
<p>We have an EXE that IDA pro lists the following segments:</p> <pre><code>Name Start End R W X D L Align Base Type Class AD es ss ds fs gs cseg01 00000000 0000EA50 ? ? ? . L para 0000 public CODE 16 FFFFFFFF FFFFFFFF 5BD5 FFFFFFFF FFFFFFFF cseg02 00000000 0000E020 ? ? ? . L para 0EA5 public CODE 16 FFFFFFFF FFFFFFFF 5BD5 FFFFFFFF FFFFFFFF cseg03 00000000 0000AE20 ? ? ? . L para 1CA7 public CODE 16 FFFFFFFF FFFFFFFF 5BD5 FFFFFFFF FFFFFFFF cseg04 00000000 0000EFD0 ? ? ? . L para 2789 public CODE 16 FFFFFFFF FFFFFFFF 5BD5 FFFFFFFF FFFFFFFF cseg05 00000000 0000EFB0 ? ? ? . L para 3686 public CODE 16 FFFFFFFF FFFFFFFF 5BD5 FFFFFFFF FFFFFFFF cseg06 00000000 0000EFF0 ? ? ? . L para 4581 public CODE 16 FFFFFFFF FFFFFFFF 5BD5 FFFFFFFF FFFFFFFF cseg07 00000000 00007550 ? ? ? . L para 5480 public CODE 16 FFFFFFFF FFFFFFFF 5BD5 FFFFFFFF FFFFFFFF dseg08 00000000 0000A4D0 ? ? ? . L para 5BD5 public DATA 16 FFFFFFFF FFFFFFFF 5BD5 FFFFFFFF FFFFFFFF COMMDLG 00000000 00000004 ? ? ? . L para 6622 public 16 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF PZOHDLL 00000000 00000011 ? ? ? . L para 6623 public 16 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF KERNEL 00000000 00000023 ? ? ? . L para 6625 public 16 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF GDI 00000000 0000003D ? ? ? . L para 6628 public 16 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF USER 00000000 0000006D ? ? ? . L para 662C public 16 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF WIN87EM 00000000 00000001 ? ? ? . L para 6633 public 16 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF CSD_LOGO 00000000 00000001 ? ? ? . L para 6634 public 16 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF X1WIN 00000000 00000003 ? ? ? . L para 6635 public 16 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF </code></pre> <p>If I have stack traces/etc, return addresses, or data addresses in format : how can I match up the segment address to the segment name in IDA Pro.</p> <p>For example when this module loaded LoadModule returned HINSTANCE of 0x28A7. . I have two addresses I wanted to find in IDA:</p> <ol> <li>28df:69ca</li> <li>28e7:246c</li> </ol> <p>Now in this case I search IDA for the address i.e. 69ca and manually find the matching segment based on knowledge of what I expect to be executing at that point.</p> <p>However wonder what approach can be used to easily translate the segment address without needing to search i.e. 0x28df = cseg01 and 0x28e7 = cseg02.</p> <p>There is an option to rebase based on address of first segment, but that doesn't seem to change anything (or I'm not using it correctly) <a href="https://i.stack.imgur.com/61ZZX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/61ZZX.png" alt="enter image description here" /></a></p>
Finding Correct Segment From An Address For Windows 3.1 EXE in IDA Pro
|ida|windows|ne|
<p>Forgot to answer my own question after the hint by Rup.</p> <p>So essentially I found decryption function in .text section of program launcher with IDA.</p> <pre><code>{ unsigned int v2; // eax if (imageSize &gt;= 2) { image[imageSize - 1] += 3 - 3 * imageSize; v2 = imageSize - 2; if (imageSize != 2) { do { image[v2] += -3 * v2 - image[v2 + 1]; --v2; } while (v2); } *image -= image[1]; } } </code></pre>
30879
2022-09-14T07:26:21.417
<p>Hello to everyone in RE section!</p> <p>I have a binary file with questionable extension(meaning idk if its exe/dll). Multiple variations of this file can be acquired throught connection to remote CDN via program launcher and then saved to disk.</p> <p>At first glance (for my limited knowledge view atleast), it appears to be that they are encrypted is some way.</p> <p>The program itself unpacks atleast 2 files with .sys and .dll extensions from said file. As I said before multiple variations of this file are nearly identical in supposed PE signature region.</p> <p>First 112 bytes nearly identical, and supposed extension signature always the same (first 3-4 bytes).</p> <p>First file:</p> <p><img src="https://i.stack.imgur.com/dOEEZ.png" alt="FirstFile" /></p> <p>Second file:</p> <p><img src="https://i.stack.imgur.com/zroY3.png" alt="SecondFile" /></p> <p>Also it appears to me that sequence of chars <code>cfilorux</code> repeats itself multiple times. Am I correct to assume that its XOR encryption?</p>
Reversing encrypted file with unknown extension
|binary-analysis|encryption|
<p>This was down to my misunderstanding. I was wanting to either nop out an instruction or modify a register value. I had been trying to print the instruction to verify I was at the correct address but not considered that frida would obviously have to insert code to redirect execution flow, thank you @Robert.</p> <p>At the point of attaching the register value can still be read or modified and will be handled correctly.</p> <p>Alternatively, launching the app and loading a script but not attaching with interceptor let's me print the correct instruction at the offset via the script, e.g. just doing:</p> <pre><code>var baseAddress = Process.enumerateModules()[0].base; var instructionOffset = 0x100004ce8-0x100000000; var targetAddress = baseAddress.add(instructionOffset); console.log(Instruction.parse(targetAddress).toString()); </code></pre>
30880
2022-09-14T10:54:52.893
<p>I have an iOS device on 14.2 and am using frida 15.2.2 on Ubuntu 18.04.</p> <p>If I launch an app via frida, in the repl I can get the base address of the module, add an offset to that address, and print the instruction at that new address. Doing it like this I get the instruction I expect. The commands I entered were:</p> <pre><code>var baseAddress = Process.enumerateModules()[0].base; var instructionOffset = 0x100004ce8-0x100000000; var targetAddress = baseAddress.add(instructionOffset); Instruction.parse(targetAddress).toString(); </code></pre> <p>and the instruction I expect, based on ghidra, is <code>cbz param_1,LAB_100004d08</code> which I get.</p> <p>However, if I try and do the same by loading a script when I launch the app:</p> <pre><code>var baseAddress = Process.enumerateModules()[0].base; var instructionOffset = 0x100004ce8-0x100000000; var targetAddress = baseAddress.add(instructionOffset); Interceptor.attach(targetAddress, { onEnter: function(args) { console.log(&quot;[+] Current instruction: &quot; + (Instruction.parse(targetAddress).toString())); }, }); </code></pre> <p>it prints a different instruction. I'm not sure if there is something I've misunderstood or it is expected to work differently doing this from a script? Or if I need to take in to account the script being loaded in to memory?</p>
Frida script returning different instruction at address compared to entering commands in repl
|disassembly|ios|frida|
<p>Do you mean JNI / native libraries?</p> <p>Android app cannot view into native libraries, but you can use frida-trace to get in between the call and return.</p> <pre><code>readelf -a -W library.so | grep nativeFunctionNameHere </code></pre> <p>Note the nativeFunctionName with some other words prepended to it</p> <pre><code>frida-trace -i &quot;_JNIStuffblabla_nativeFunctionNameHere&quot; -F </code></pre> <p>You will see when it's being called, and you can edit the .js file in the console output to customize/log the function calls However, to find out what the function does, you will need to use disassemblers/debuggers and try to figure it out.</p> <p>If you only need to inspect OpenSSL library, just intercept like <code>-i &quot;openssl_*&quot;</code> or something, see which function is it that you want, and then log the arguments and/or return value.</p> <p>If you meant <code>android.</code> libraries, you can again intercept them with frida. It's a really good tool for reverse engineering, especially for Android applications. But why would you need to debug them? They're already publicly available, you should probably focus on the return value, no?</p>
30883
2022-09-14T21:47:09.883
<p>I'm debugging an obfuscated android application. I use Android Studio's debugger. I attach it remotely to my physical device via adb. I can set a breakpoint in the app smali code, but when I try to step into a function in an external library, the code browser stays at the caller's place (I expected it to show me the called function's disassebly smali output), but stack trace and the variables output follows the called function as expected. Why is that? Can't java debugger inform Android Studio about the instructions to which the code jumped even though they are in an external library?</p> <p>Also, I know the app calls some functions <code>com.android.conscrypt</code>. Can I set a breakpoint in an external library like this one? If Android Studio can't do that, what other tools can?</p>
How to set a breakpoint in android's openssl library in running android application?
|android|java|dalvik|
<p>In Visual Studio (not Visual Studio Code), go to menu Debug -&gt; &quot;Attach to Process&quot;, pick up the process from the list. Now you can press &quot;pause&quot; / &quot;Break All&quot; in Visual Studio to suspend all process threads and start debugging them.</p> <p>This works regardless of if the process is written in C++ or .NET.</p> <p>Visual Studio will show the stack trace and even source code if available. (In .NET even if source code is not available if you have installed a plugin for Visual Studio like Redgate Reflector Pro or <a href="https://github.com/icsharpcode/ILSpy" rel="nofollow noreferrer">https://github.com/icsharpcode/ILSpy</a>).</p> <p>For debugging a service process, you have to wait until the execution enters your program, you cannot attach a debugger during the SCM execution. The simplest way to do this is to add an blind loop to your code and once attached, exit the loop with the debugger (by changing the value of the sentinel variable) like</p> <pre><code> int i = 0; while (i == 0) { i++; i--; } </code></pre> <p>For dealing with issues like &quot;cannot see this variable value because it has been optimized away&quot; you can disable CLR optimizations, I have used this switch (AllowOptimize), see stackoverflow.com/a/279593/1001395 (in a .ini file of the same name like the assembly you are debugging, ie System.Data.dll.ini) &lt;= this works in .NET classic.</p> <pre><code>[.NET Framework Debugging Control] GenerateTrackingInfo=1 AllowOptimize=0 </code></pre>
30885
2022-09-15T21:02:27.873
<p>This is quite easy to do with a low-level debugger, like x64dbg (for instance). Say, if I have a running native process I can attach to it, set a breakpoint, and then step through native code with it.</p> <p>Is there a similar debugger but for .NET, that would allow me to do what I listed above?</p>
How to attach and step through a running .NET process?
|debugging|.net|
<p>unless you have a private pdb for storport you wouldn't be able to locate the names and even if you have the private pdb it is mostly a guessing game</p> <p>i will show a demo using windbg adapt it to the tools of your choice</p> <p>1)locating function of interest</p> <pre><code>0: kd&gt; x /v /t /f storport!RaGetUnitStorageDeviceProperty prv func fffff801`36f12664 268 &lt;CLR type&gt; storport!RaGetUnitStorageDeviceProperty (void) </code></pre> <p>since the argument list is void either this functions takes no arguments or the details are missing and is not easily locatable without putting in effort</p> <p>since this is an x64 the first four arguments are passed via rcx,rdx,r8,r9 in windows lets check if any of them are used inside the function.</p> <p>if they are going to be accessed they would be saved or used very early in the function dissassemble first 15 lines of the functions</p> <pre><code>0: kd&gt; u storport!RaGetUnitStorageDeviceProperty l15 storport!RaGetUnitStorageDeviceProperty: fffff801`36f12664 4055 push rbp fffff801`36f12666 53 push rbx fffff801`36f12667 56 push rsi fffff801`36f12668 57 push rdi fffff801`36f12669 4154 push r12 fffff801`36f1266b 4156 push r14 fffff801`36f1266d 4157 push r15 fffff801`36f1266f 488dac2440ffffff lea rbp,[rsp-0C0h] fffff801`36f12677 4881ecc0010000 sub rsp,1C0h fffff801`36f1267e 488b056b6cffff mov rax,qword ptr [storport!_security_cookie (fffff801`36f092f0)] fffff801`36f12685 4833c4 xor rax,rsp fffff801`36f12688 488985b0000000 mov qword ptr [rbp+0B0h],rax fffff801`36f1268f 488b7968 mov rdi,qword ptr [rcx+68h] fffff801`36f12693 4d8bf0 mov r14,r8 &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; fffff801`36f12696 4c8bfa mov r15,rdx &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; fffff801`36f12699 488bd9 mov rbx,rcx &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; fffff801`36f1269c 41bc8c010000 mov r12d,18Ch fffff801`36f126a2 488d4c2420 lea rcx,[rsp+20h] fffff801`36f126a7 458bc4 mov r8d,r12d fffff801`36f126aa 33d2 xor edx,edx fffff801`36f126ac e88fd2faff call storport!memset (fffff801`36ebf940) </code></pre> <p>as you can notice three arguments are saved the first argument rcx is saved to rbx the second argument rdx is saved to r15 the third argument r8 is saved to r14</p> <p>disassemble the full function and grep for r9 just in case</p> <pre><code>0: kd&gt; .shell -ci &quot;uf storport!RaGetUnitStorageDeviceProperty&quot; findstr &quot;r9&quot; .shell: Process exited </code></pre> <p>no sign of r9 so this function possibly takes 3 arguments</p> <p>lets concentrate on rbx which holds the first argument</p> <pre><code>0: kd&gt; .shell -ci &quot;uf storport!RaGetUnitStorageDeviceProperty&quot; findstr &quot;rbx&quot; fffff801`36f12666 53 push rbx fffff801`36f12699 488bd9 mov rbx,rcx fffff801`36f126f3 8b83d00c0000 mov eax,dword ptr [rbx+0CD0h] &lt;&lt;&lt;&lt;&lt;&lt;&lt; fffff801`36f126fd 488b8398000000 mov rax,qword ptr [rbx+98h] fffff801`36f1270d 488b9390000000 mov rdx,qword ptr [rbx+90h] fffff801`36f1274c 6644396372 cmp word ptr [rbx+72h],r12w fffff801`36f12773 0fb74370 movzx eax,word ptr [rbx+70h] fffff801`36f12777 488b5378 mov rdx,qword ptr [rbx+78h] fffff801`36f127c4 5b pop rbx fffff801`36f12819 6644396372 cmp word ptr [rbx+72h],r12w fffff801`36f1282e 488b4318 mov rax,qword ptr [rbx+18h] fffff801`36f12879 6644396372 cmp word ptr [rbx+72h],r12w fffff801`36f12880 0fb77b70 movzx edi,word ptr [rbx+70h] fffff801`36f12898 488b5378 mov rdx,qword ptr [rbx+78h] .shell: Process exited </code></pre> <p>this clearly shows rbx is used and is possibly a structure and is possibly a very large structure as a member at offset 0xcd0 is accessed so the possible sizeof structure is greater than 0xcd0</p> <p>from this stage on you either need to identify each member manually and name them or use google or tools like ida / ghidra to aid you or debug the function and infer the members of the structure</p> <p>since you already googled and is having a possible candidate lets trial and eliminate or confirm its correctness</p> <p>confirm if size is greater than the accessed offset</p> <pre><code>0: kd&gt; ?? sizeof(storport!_RAID_UNIT_EXTENSION) unsigned int64 0xd40 </code></pre> <p>yes it is greater</p> <p>check if offset 0xcd0 is correct offset for a member inside this structure</p> <pre><code>0: kd&gt; .shell -ci &quot;dt -v storport!_RAID_UNIT_EXTENSION &quot; findstr &quot;cd0&quot; +0xcd0 BusType : Enum _STORAGE_BUS_TYPE, 22 total enums .shell: Process exited </code></pre> <p>sure it matches lets check the enum</p> <pre><code>0: kd&gt; dt -v storport!_STORAGE_BUS_TYPE Enum _STORAGE_BUS_TYPE, 22 total enums BusTypeUnknown = 0n0 BusTypeScsi = 0n1 BusTypeAtapi = 0n2 BusTypeAta = 0n3 BusType1394 = 0n4 BusTypeSsa = 0n5 BusTypeFibre = 0n6 BusTypeUsb = 0n7 BusTypeRAID = 0n8 BusTypeiScsi = 0n9 BusTypeSas = 0n10 BusTypeSata = 0n11 BusTypeSd = 0n12 BusTypeMmc = 0n13 BusTypeVirtual = 0n14 BusTypeFileBackedVirtual = 0n15 BusTypeSpaces = 0n16 BusTypeNvme = 0n17 BusTypeSCM = 0n18 BusTypeUfs = 0n19 BusTypeMax = 0n20 BusTypeMaxReserved = 0n127 </code></pre> <p>ok test eax,eax means it is possibly checking BusTypeUnknown</p> <p>lets check other offsets</p> <p>+0x018 Adapter : Ptr64 to struct _RAID_ADAPTER_EXTENSION, 178 elements, 0x1740 bytes</p> <p>all other member access 0x70,72,0x90,0x98 etc fall inside</p> <pre><code> +0x068 Identity : struct _STOR_SCSI_IDENTITY, 7 elements, 0x38 bytes +0x0a0 VendorId : [9] UChar </code></pre> <p>lets check that structure</p> <pre><code>0: kd&gt; dt -v storport!_STOR_SCSI_IDENTITY struct _STOR_SCSI_IDENTITY, 7 elements, 0x38 bytes +0x000 InquiryData : Ptr64 to struct _INQUIRYDATA, 44 elements, 0x68 bytes +0x008 SerialNumber : struct _STRING, 3 elements, 0x10 bytes +0x018 Supports1667 : UChar +0x019 ZonedDevice : UChar +0x020 DeviceId : Ptr64 to struct _VPD_IDENTIFICATION_PAGE, 6 elements, 0x4 bytes +0x028 AtaDeviceId : Ptr64 to struct _STOR_ATA_DEVICE_ID, 2 elements, 0x32 bytes +0x030 RichDeviceDescription : Ptr64 to struct _STOR_RICH_DEVICE_DESCRIPTION, 5 elements, 0x6c bytes </code></pre> <p><a href="https://www.unknowncheats.me/forum/2858059-post136.html" rel="nofollow noreferrer">so your google foo has landed a possibly correct reference to the implementation</a></p> <p>opened the storport.sys in ghidra / configured symbol path / searched for the function and de-compiled it selected the PARAMETER 1 and assigned _RAID_UNIT_EXTENSION to it and voila you get a neat output</p> <pre><code>void RaGetUnitStorageDeviceProperty(_RAID_UNIT_EXTENSION *param_1,void *param_2,uint *param_3) { xxxxxxxxxxxxxxxxxxxxxx local_1bc = param_1-&gt;BusType; p_Var5 = (param_1-&gt;Identity).RichDeviceDescription; if (p_Var5 == (_STOR_RICH_DEVICE_DESCRIPTION *)0x0) { p_Var6 = (param_1-&gt;Identity).AtaDeviceId; if ((p_Var6 == (_STOR_ATA_DEVICE_ID *)0x0) || ((((param_1-&gt;Adapter-&gt;Miniport).HwInitializationData)-&gt;FeatureSupport &amp; 0x40) == 0)) { local_1b0 = *(undefined8 *)p_Var4-&gt;VendorId; uVar3 = *(undefined4 *)p_Var4-&gt;ProductRevisionLevel; uStack424 = uStack424 &amp; 0xff | *(int *)p_Var4-&gt;ProductId &lt;&lt; 8; uStack420._1_3_ = (undefined3)*(undefined4 *)(p_Var4-&gt;ProductId + 4); uStack420 = CONCAT31(uStack420._1_3_,(char)((uint)*(int *)p_Var4-&gt;ProductId &gt;&gt; 0x18)); uStack416._1_3_ = (undefined3)*(undefined4 *)(p_Var4-&gt;ProductId + 8); uStack416 = CONCAT31(uStack416._1_3_, (char)((uint)*(undefined4 *)(p_Var4-&gt;ProductId + 4) &gt;&gt; 0x18)); uStack412._1_3_ = (undefined3)*(undefined4 *)(p_Var4-&gt;ProductId + 0xc); uStack412 = CONCAT31(uStack412._1_3_, (char)((uint)*(undefined4 *)(p_Var4-&gt;ProductId + 8) &gt;&gt; 0x18)); xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </code></pre> <p>opening the file in idafree8 inserted the standard structure _RAxxxxx assigned the parameter to pointer to standard structure and decompiled</p> <p>idas output</p> <pre><code> HIDWORD(v26[3]) = a1-&gt;BusType; RichDeviceDescription = a1-&gt;Identity.RichDeviceDescription; if ( RichDeviceDescription ) { if ( RichDeviceDescription-&gt;VendorId[0] ) { v15 = *(_OWORD *)RichDeviceDescription-&gt;VendorId; HIDWORD(v26[1]) = 40; *(_OWORD *)&amp;v26[5] = v15; } v16 = *(_OWORD *)RichDeviceDescription-&gt;ModelNumber; v26[2] = 0x7A00000039i64; v17 = *(_OWORD *)&amp;RichDeviceDescription-&gt;ModelNumber[16]; *(_OWORD *)((char *)&amp;v26[7] + 1) = v16; v18 = *(_OWORD *)&amp;RichDeviceDescription-&gt;ModelNumber[32]; *(_OWORD *)((char *)&amp;v26[9] + 1) = v17; v19 = *(_OWORD *)&amp;RichDeviceDescription-&gt;ModelNumber[48]; *(_OWORD *)((char *)&amp;v26[11] + 1) = v18; v20 = *(_OWORD *)RichDeviceDescription-&gt;FirmwareRevision; *(_OWORD *)((char *)&amp;v26[13] + 1) = v19; *(_OWORD *)((char *)&amp;v26[15] + 2) = v20; if ( a1-&gt;Identity.SerialNumber.MaximumLength ) JUMPOUT(0x1C00761D0i64); goto LABEL_12; } AtaDeviceId = a1-&gt;Identity.AtaDeviceId; if ( AtaDeviceId &amp;&amp; (a1-&gt;Adapter-&gt;Miniport.HwInitializationData-&gt;FeatureSupport &amp; 0x40) != 0 ) { v21 = *(_OWORD *)AtaDeviceId-&gt;ModelNumber; v22 = *(_QWORD *)AtaDeviceId-&gt;FirmwareRevision; v23 = *(_OWORD *)&amp;AtaDeviceId-&gt;ModelNumber[16]; v26[2] = 0x5100000028i64; *(_OWORD *)&amp;v26[5] = v21; *(_QWORD *)((char *)&amp;v26[10] + 1) = v22; v26[9] = *(_QWORD *)&amp;AtaDeviceId-&gt;ModelNumber[32]; *(_OWORD *)&amp;v26[7] = v23; if ( a1-&gt;Identity.SerialNumber.MaximumLength ) { Length = a1-&gt;Identity.SerialNumber.Length; LODWORD(v26[3]) = 90; memmove((char *)&amp;v26[11] + 2, a1-&gt;Identity.SerialNumber.Buffer); v25 = 21; if ( (unsigned __int64)(Length + 1) &lt; 0x15 ) v25 = Length + 1; RaidRemoveTrailingBlanks((char *)&amp;v26[11] + 2, v25); goto LABEL_8; } </code></pre>
30897
2022-09-19T18:55:35.983
<p>I am trying to find out which struct <code>storport!RaGetUnitStorageDeviceProperty</code> uses by myself. I know I can use google and find out the correct answer is <code>_RAID_UNIT_EXTENSION</code>. However i want to do it myself on my own manually and learn the logic behind it.</p> <p>Things so far I tried include setting a breakpoint on the function and then using the <code>dt</code> command which shows the function name as result. I also used IDA to see if I can get any trace of struct but I could not find any trace of <code>_RAID_UNIT_EXTENSION</code> with IDA even though I used storport.pdb as well. How can I find it myself manually? I can clearly see <code>_RAID_UNIT_EXTENSION</code>using <code>dt storport!*</code> in the output but there is not any trace of such a name in IDA. I would really appreciate it if someone could help me.</p>
Find out which struct RaGetUnitStorageDeviceProperty use by reverse engineering
|windows|debugging|windbg|kernel-mode|driver|
<p>I know nothing about OllyFlow plugin, but here some info on WinGraph32.exe.</p> <p>There was GPL-ed source code on hex-rays.com. You can download it using Internet Archive Wayback Machine. Something like this:</p> <p><a href="https://web.archive.org/web/20080901113014/http://www.hex-rays.com/idapro/idadown.htm" rel="nofollow noreferrer">https://web.archive.org/web/20080901113014/http://www.hex-rays.com/idapro/idadown.htm</a></p> <p>Or you can download IDA Pro 5.0 Freeware which contains compiled wingraph32.exe:</p> <p><a href="https://web.archive.org/web/20110804083226/http://www.hex-rays.com/idapro/idadown.htm" rel="nofollow noreferrer">https://web.archive.org/web/20110804083226/http://www.hex-rays.com/idapro/idadown.htm</a></p>
30899
2022-09-20T05:25:49.917
<p>I am trying to use the <a href="http://www.openrce.org/downloads/details/178/OllyFlow" rel="nofollow noreferrer">OllyFlow plugin</a> for OllyDbg 1.10. It requires WinGraph32.exe, which was apparently distributed with IDA at some point, because the <a href="https://nostarch.com/gamehacking" rel="nofollow noreferrer">book Game Hacking</a> says:</p> <blockquote> <p>Wingraph32 is not provided with OllyFlow, but it is available with the free version of IDA</p> </blockquote> <p>It appears the current free version of IDA no longer has WinGraph32.exe included - so, how can I get the OllyFlow plugin to work?</p>
WinGraph32 for the OllyFlow plugin
|ida|ollydbg|
<p>You can do that through the &quot;local types&quot; window (<code>View -&gt; Open subviews -&gt; Local types</code>). Right-click on the structure and select <code>Map to another type</code>.</p>
30925
2022-09-26T15:06:18.293
<p>When decompiling an exe file, I have defined two structs <code>struct A</code> and <code>struct B</code> that are of the same structure. They appeared under different contexts, thus I assumed that they were different structs. However, as the contexts merge, I realize that these are in fact the same struct.</p> <p>Now I would like to get rid of <code>struct B</code> and replace all its occurance with <code>struct A</code>. Is it possible to do that without manually changing everything?</p> <p>I know that I can define <code>struct B</code> as containing just one <code>struct A</code> as its member, but this feels less optimal and creates unnecessary syntax in decompiled code.</p>
Identify two structs in IDA
|ida|struct|
<p>uf foo!blah unassemble full function</p>
30931
2022-09-29T12:59:44.877
<p>I am trying to disassemble the function <code>ExAcquireFastMutex</code> using WinDbg but it gives me only 8 rows:</p> <pre><code>3: kd&gt; u nt!ExAcquireFastMutex nt!ExAcquireFastMutex: fffff805`456e3820 4053 push rbx fffff805`456e3822 56 push rsi fffff805`456e3823 57 push rdi fffff805`456e3824 4883ec30 sub rsp,30h fffff805`456e3828 33f6 xor esi,esi fffff805`456e382a 488bf9 mov rdi,rcx fffff805`456e382d 89742458 mov dword ptr [rsp+58h],esi fffff805`456e3831 65488b1c2588010000 mov rbx,qword ptr gs:[188h] </code></pre> <p>How can I get more rows, until the return instruction ?</p>
How to disassemble an entire function in Windbg?
|disassembly|windows|windbg|winapi|
<p>You don't throw things at IDA and hope for the best and, as an analyst, you don't relay on automatic tools this much. That's clearly a sign you need to start doing the heavy lifting.</p> <p>A packer is simply a binary, so you proceed as you would do with any other binary. There is no general procedure, I'll tell you what I usually do but I may have forgotten something and the list cannot possibly be exhaustive.</p> <p>The general rule is: you debug it until you understand it, no matter how much time and focus will it take (5 min, 1 hour, 3 days, a month, doesn't matter).<br /> You do this often enough and the time will shorten further and further until it's acceptable, you never get your hands dirty (i.e. use automated tools) and you'll never learn how to do this.</p> <p>Anyway, I'd do this assuming the packer is a PE:</p> <ol> <li>Inspect the PE with a PE viewer. I use CFF Explorer. This will tell you if the PE is 32 or 64-bit, if it's a .NET assembly and what resources it has. Very simple packers have plain or XOR/RC4 encrypted payloads in their resources. The resources will also tell you if you are dealing with a Delphi binary, a particular runtime, an installer, UPX and so on. With experience, you can even tell malware and packer families aparts just by inspecting their PE.</li> <li>If it's a .NET use dnspy to inspect and debug it.</li> <li>If it's a Delphi use IDR to inspect and debug it.</li> <li>If it's a VB6 use VB decompiler.</li> <li>If it's AutoIT or similar scripted automation, use the relevant decompiler.</li> <li>If it's an installer (NSIS, MSI, SFX, ...) use 7z 9.38 to extract it and then go back to point 1 (you may find out the packer it's an installer later, it's OK, you are required to know how the main installer looks like when disassembled with IDA, Ghidra or similar).</li> <li>If it's not either use IDA.</li> <li>If necessary debug the packer (I use x64dbg).</li> </ol> <h4>.NET assembly</h4> <p>These can be easy to unpack or can be hard (if they patch metadata or use delegate shadowing).<br /> In either case, check any module constructor and variable initializer. Often the malicious code is hidden inside a legal application, you have to find it starting from the entry-point. This is tedious but not hard, it's easy to spot malicious code (you are required to be a programmer to be a malware analyst, so you surely know what good code looks like).<br /> Often the packers use Control-Flow Obfuscation, this makes the code hard to read but not too hard to debug.<br /> What these packers usually do is decode an assembly (a DLL) from the resource and load it with <code>Assembly.Load</code> then use reflections (<code>GetTypes</code>, <code>GetMethods</code>, <code>Invoke</code>) to invoke a method. Use the <em>module</em> view of dnspy to put breakpoints in dynamically loaded assembly.<br /> By debugging and inspecting the local variable you can easily find the configuration and the payload. You'll know when you are in the final unpacking routine because there will be a lot of checks on the configuration (cfr. MaaS).<br /> Keep in mind that there can be one, two, five, or even ten additional assemblies before the final unpacking. If the packer uses &quot;delegate shadowing&quot; (i.e. call its method and runtime methods through delegates) you can inspect the target of the delegate in the <em>local</em> window to see if you are going to step into a runtime function.</p> <p>De4dot was once useful for deobfuscating .NET assembly, not it's pretty useless but for dynamically executing string deobfuscation and renaming.</p> <p>dnlib is a very useful library to manipulate IL code, you are required to know how to use it to write deobfuscator or simplify the analysis.</p> <h4>IDR</h4> <p>This is a standard Delphi executable, as a malware analyst you are required to be confident with the Delphi runtime (particularly string and array manipulation, Unit initialization and GUI events).<br /> You may need to download additional &quot;Knowledge Bases&quot; to have IDR recognize the Delphi runtime.<br /> Your first task is finding the malicious code. This can be in a unit initialization routine, in a timer in a form or in any form load/create event.<br /> Use IDR to inspect the possible entry-point and look for anything suspicious, use the rename function copiously.<br /> Look for the usual tricks (PEB accesses, <code>LoadLibrary</code> and so on). Generally speaking, the packer will allocate memory to decode the payload and then map and execute it.<br /> There is no way to give a general procedure. Note that you want the payload just decoded but not yet mapped (the payload is usually a PE) otherwise you have to patch it once dumped.</p> <h4>IDA</h4> <p>First identify the runtime used, for example, Go, Rust, C, C++ or so on. You are required to know how to tell the main programming languages apart (including Delphi, sometimes it can be wrongly detected).<br /> If the languages have metadata (e.g. Go, Rust) then use the necessary IDA script to annotate the DB from these metadata (e.g. Go has AlphaGolang). If the scripts don't exist, write them. As a malware analyst, you are required to be confident in the vast majority of programming languages and platforms, including idapy.<br /> See also if FLIRT or Lumina can help you (particularly for C/C++).</p> <p>Once you have made IDA detect as much library code as possible, you need to find and inspect the entry-point.<br /> Get a gist of the possible obfuscation used and if used learn the patterns, what they actually mean and how to mentally translate them.<br /> Learn the shape of the decoy code to ignore (this can be done with several years of experience in programming, decoy code makes no sense so it really stands out as you have never seen it while debugging the legal programs you worked on) and look for the suspicious one (again: PEB access, allocation of memory, loading of modules).<br /> The packer will generally decode the payload in allocated memory and then map and execute it.<br /> The memory can be allocated with a variety of functions (<code>NtAllocateVirtualMemory</code>, <code>GlobalAlloc</code>, <code>LocalAlloc</code>, <code>VirtualAlloc</code>, on a writable section, ...).<br /> See if the decoding code is simple (short actually) enough to be worth emulating in a script or if it's easier to debug it. You can expect an intermediate shellcode, this can be called with anything (indirect <code>jmp</code> and <code>call</code>, <code>push/ret</code> pairs, callbacks in APIs, ...).<br /> Again, you want the payload decoded but not mapped.</p> <h4>VB6</h4> <p>If the packer is really written in VB6, just read the decompiled code. Again it should be easy to spot the decoding routine thanks to the boatload of metadata.<br /> Often the VB6 binary is just a decoy, you have to find the call to the shellcode. This is usually a simple <code>call</code> to a fixed address that is not listed as a VB6 routine. Put a breakpoint there and debug.</p> <hr /> <p>You are also required to <a href="https://anti-reversing.com/Downloads/Anti-Reversing/The_Ultimate_Anti-Reversing_Reference.pdf" rel="noreferrer">know the anti-debug tricks</a> and how to work around them (you can simply put breakpoint on APIs).</p>
30934
2022-09-29T20:41:26.960
<p>I got an assignment to analize an exe file with 97% entropy. It's obviously packed but I got no results from Protection Id or PEid about which packer it used...</p> <p>How can I unpack it if it's possible? Or should I just throw it to ida and hope for the best? Everything I've found on the internet was either too complicated for me or used known packers. Sorry if this is an easy topic to understand, I'm new to this stuff. Every answer is appreciated!</p>
How do I reverse an exe packed with an unknown packer?
|ida|c++|static-analysis|unpacking|packers|
<p>Ah! So despite the function being advertised otherwise it is still async and I have to call</p> <blockquote> <p>ida_dbg.wait_for_next_event(ida_dbg.WFNE_SUSP, -1)</p> </blockquote> <p>Is this the correct solution?</p>
30956
2022-10-05T16:56:08.933
<p>So I am trying to run an app and collect information at certain points. No biggie, right? Wrong. Check this simple example:</p> <pre><code>import ida_dbg ida_dbg.step_over() #or runto() eax = ida_dbg.get_reg_val(&quot;eax&quot;) print(&quot;eax: &quot;, eax) </code></pre> <p>throws an exception</p> <blockquote> <p>Exception: Failed to retrieve register value</p> </blockquote> <p>But Individually it works. So if I do ONLY a &quot;ida_dbg.step_over()&quot;, that works. And if do ONLY a 'get_reg_val(&quot;eax&quot;)' that works too. Only in combination it fails.</p> <p>Now, you might think this is because step_over only posts a request, but the documentation explicitly says otherwise and provides a request_step_over() for that purpose.</p> <p>Please, can someone enlighten me and show me how I can step over my program and collect register values after each step?</p>
ida pro: scripting debugger with python fails on step_over/run_to
|ida|debugging|idapython|
<p>With the help of &quot;locals&quot; and &quot;globals&quot; in python programming, this can be solved</p>
30986
2022-10-13T06:16:45.693
<p>I have a set of equations in string format as given below. Need to assign some value to the left-hand side variable (In the below example: rsp, esp). Then have to calculate and store the results on the right-hand side variable (i.e., rax, esp, rsp).</p> <p>Example:</p> <p><code>rax = rsp</code></p> <p><code>esp = esp - 0x4</code></p> <p><code>rsp = rsp - 0x30</code></p> <p>Though I have used the <code>eval</code> function in python, it is throwing me an error message as it won't support <code>=</code>. Could someone please help me to find the answer?</p>
How to change the Equations in string format to normal equations in Python?
|python|
<p>This is an AT42QT2120 QTouch sensor IC from Atmel.</p>
30987
2022-10-13T19:51:01.397
<p>Does anybody know which IC this is? I cannot find anything for &quot;2746 QA7A&quot; or any combination of it. Neither do I recognise the manufacturer. The IC is actually very small, so I cannot take a better photo of it.</p> <p>What I already found out: The IC is connected to six touch keys, the upper five pins and the first pin on the lower left are connected to the touch pads. Then there are 3 data lines connected to an ST32. May be I2C.</p> <p>Thanks for any hint!</p> <p><a href="https://i.stack.imgur.com/qcGl8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qcGl8.jpg" alt="unknown IC" /></a></p>
Need help identifying this IC
|hardware|
<p>Have you tried <a href="https://github.com/FabricMC/Matcher" rel="nofollow noreferrer">https://github.com/FabricMC/Matcher</a>?<br /> It doesn't always create the best matches automatically but it helps a lot by suggesting classes/methods/fields that are similar to each other across the different versions.</p>
31020
2022-10-20T16:48:36.427
<p>I am currently trying to de-obfuscate a Java program (i.e. find each class name and namespace, each method name and each method parameter name). To do so, I started by using Enigma (the fork from FabricMC).</p> <p>But I have access to old sources that are <strong>not</strong> obfuscated and I was wondering if I could automatically de-obfuscate the part of my Java program that did not change since then.</p> <p>Basically, I have:</p> <ul> <li>Version 3 that is non-obfuscated.</li> <li>Version 6 that is obfuscated.</li> <li>Version 7 that is obfuscated.</li> <li>Version 9 that is obfuscated.</li> </ul> <p>and I want to de-obfuscate automatically as much symbols as possible in Version 9.</p> <p>Are you aware of any tool that can do this? Currently, I am navigating the unobfuscated files of Version 3 by hand and mapping Version 9 on Enigma by hand too, which is quite a long and tedious process.</p> <p>Note: all the subjects I found during my research were about de-obfuscating without access to any prior, non-obfuscated, sources. I would like to extract the maximum I can from the non-obfuscated sources I obtained.</p>
Automatic deobfuscation of Java class/method/parameter names with access to old non obfuscated sources
|java|deobfuscation|
<p>Turns out this is indeed pure deflate bitstream. <code>zlib-flate</code> is for zlib stream.</p> <pre><code>% ./decomp.py ae126b7a3fe86811f981f53cf7cf59cfc1e5bc7c.raw | colrm 82 b'EDF V1: ContentType=syngo.MR.ExamDataFoundation.Data.EdfAddInConfigContent;\r\n </code></pre> <p>With simply:</p> <pre><code>% cat decomp.py #!/bin/env python3 import zlib import sys with open(sys.argv[1], 'rb') as input_file: compressed_data = input_file.read() unzipped = zlib.decompress(compressed_data, -zlib.MAX_WBITS) print(unzipped) </code></pre> <p>Ref:</p> <ul> <li><a href="https://stackoverflow.com/a/22310760/136285">https://stackoverflow.com/a/22310760/136285</a></li> </ul>
31022
2022-10-21T12:36:12.203
<p>I must be missing something obvious here. I cannot make sense of the following deflate stream.</p> <p>Steps:</p> <pre><code>% wget https://github.com/lrq3000/mri_protocol/raw/master/SiemensVidaProtocol/Coma%20Science%20Group.exar1 % sqlite3 Coma\ Science\ Group.exar1 &quot;SELECT writefile('ae126b7a3fe86811f981f53cf7cf59cfc1e5bc7c.raw', Data) FROM Content WHERE hash = 'ae126b7a3fe86811f981f53cf7cf59cfc1e5bc7c'&quot; % file ae126b7a3fe86811f981f53cf7cf59cfc1e5bc7c.raw ae126b7a3fe86811f981f53cf7cf59cfc1e5bc7c.raw: data </code></pre> <p>However upon closer look:</p> <pre><code>% binwalk -X ae126b7a3fe86811f981f53cf7cf59cfc1e5bc7c.raw | head DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 0 0x0 Raw deflate compression stream </code></pre> <p>Looking at the entropy (<code>binwalk -EJ</code>), this really looks like a typical deflate algorithm:</p> <p><a href="https://i.stack.imgur.com/MqaR5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MqaR5.png" alt="enter image description here" /></a></p> <p>But it seems the signature is broken:</p> <pre><code>% zlib-flate -uncompress &lt; ae126b7a3fe86811f981f53cf7cf59cfc1e5bc7c.raw flate: inflate: data: incorrect header check </code></pre> <p>Anyone recognize the compression here ?</p>
What kind of deflate compression is this?
|decompress|
<p>As commented by Robert, the answer for me in this case was that the signature was being checked by the app itself, and the app was causing the crash as a result of detecting modification to the app. If you want to solve this problem, get ready for a long project. If the developers of the app care even a little about the security of their app, they can make it incredibly difficult to modify the app. I would recommend looking up reverse engineering tools such as Ghidra and Frida that might be able to help you.</p>
31048
2022-10-29T03:28:53.553
<p>Decompiling and recompiling an apk causes it to crash. My goal is simply to insert a method into smali code that prints a stacktrace, but even decompiling and recompiling with no changes causes the modified apk to crash. Apktool says everything goes fine, but when the recompiled apk is installed it crashes instantly.</p> <p><a href="https://pastebin.com/zBJWdWYg" rel="nofollow noreferrer">the decompiled and recompiled apk's log</a></p> <p><a href="https://pastebin.com/Ay0m8ns4" rel="nofollow noreferrer">log of the unmodified version installed from Play Store</a></p> <p>It seems as if Apktool doesn't properly recompile.</p>
Decompiling and Recompiling APK leads to crash using Apktool
|decompilation|android|apk|
<p>It looks like something went wrong with binwalk's extraction. I checked the file on the running device with hexdump and it's just a normal ELF executable. I used binwalk to extract the JFFS2 image and it has handled other symlniks just fine. Perhaps it's errors in the extracted image data, or a bug in binwalk.</p> <p>Thanks to @secondperson.</p>
31054
2022-10-30T19:35:04.727
<p>I'm reverse engineering an old TP-Link TD-W9970v3 router for fun and wanted to examine one of the executables called <code>webWarn</code>. Ghidra was unable to recognise the format, which surprised me. I then tried to use the <code>file</code> command on it, and it too did not recognise it, simply reporting it as data. I then opened up the file in a hex editor and was surprised to see that the first bytes in the executable are a string containing a relative path to the location of the <code>busybox</code> executable on the system.</p> <p>Comparing the hex of this executable with a normal ELF executable from the system shows that their headers seem to be the same size. It caught my attention that the presence of the string &quot;/lib/ld-uClibc.so.0&quot; in both files starts at the same offset.</p> <p><a href="https://i.stack.imgur.com/nIsM6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nIsM6.png" alt="Comparison" /></a></p> <p>There are many strings in the binary that seem to refer to C libraries and functions, so it does look like a regular compiled executable.</p> <p>I uploaded it to Decompiler Explorer (<a href="https://dogbolt.org/?id=6d669677-b444-4005-91b8-fa14aac8fc74" rel="noreferrer">see result</a>) and only BinaryNinja was able to recognise the file apparently, although trying to upload it to BinaryNinja's own cloud service didn't work</p> <p>What binary format is this?</p>
Why do the first bytes of this executable contain a path to busybox?
|binary-format|