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>The purpose of <code>sub_3699</code> is to return address of the next instruction after the one that called that procedure. <code>call sub_3699</code> pushes address of the next instruction onto the stack and jumps to the first instruction of <code>sub_3699</code>.</p> <p>That instruction takes the value at the top of the stack (without removing it) and writes it to <code>ebx</code>. Such a mechanism is usually used when <em>position independent code</em> is generated to avoid accessing data using harcoded addresses (though combination of <code>call $+5, pop reg</code> is more popular).</p> <p>So instead of accessing some <code>addr</code> directly, you compute it relatively to the address of the next instruction. So, you first compute <code>addr - address_of_next_instruction = addr - sub_3699() = 0x1DD5C</code> (in your case) and to obtain <code>addr</code> you have to simply add <code>sub_3699()</code> to that number. After this addition, <code>ebx</code> contains <code>addr</code>.</p>
29439
2021-10-21T14:45:43.167
<p>I'm disassembling one SO library for fun and was wondering what's purpose of following procedure:</p> <pre><code>sub_3699 proc near mov ebx, [esp+0] retn sub_3699 endp </code></pre> <p>It's widely used across entire library with very confusing pattern (at least to me) like this:</p> <pre><code>push ebp mov ebp, esp push esi push ebx call sub_3699 ; Here it is called add ebx, 1DD5Ch ; And this magic number is something I'm trying to understand ... ; rest of caller body pop ebx pop esi pop ebp retn </code></pre> <p>Please note magic number <code>1DD5Ch</code> added to <code>EBX</code> after procedure invocation. It seems that this number is unique across all invocations, but I have no idea of its purpose. Even <code>EBX</code> register itself doesn't seem to be read/write within caller code.</p> <p>Any idea?</p> <p>If that matters, here is output of <code>readelf -s ...</code></p> <pre><code>ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: Intel 80386 Version: 0x1 Entry point address: 0x14340 Start of program headers: 52 (bytes into file) Start of section headers: 275660 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 5 Size of section headers: 40 (bytes) Number of section headers: 25 Section header string table index: 24 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .hash HASH 000000d4 0000d4 00221c 04 A 2 0 4 [ 2] .dynsym DYNSYM 000022f0 0022f0 0047e0 10 A 3 1 4 [ 3] .dynstr STRTAB 00006ad0 006ad0 00825f 00 A 0 0 1 [ 4] .gnu.version VERSYM 0000ed30 00ed30 0008fc 02 A 2 0 2 [ 5] .gnu.version_r VERNEED 0000f62c 00f62c 000020 00 A 3 1 4 [ 6] .rel.dyn REL 0000f64c 00f64c 000eb8 08 A 2 0 4 [ 7] .rel.plt REL 00010504 010504 0014b0 08 A 2 9 4 [ 8] .init PROGBITS 000119b4 0119b4 00001c 00 AX 0 0 1 [ 9] .plt PROGBITS 000119d0 0119d0 002970 04 AX 0 0 16 [10] .text PROGBITS 00014340 014340 02b324 00 AX 0 0 4 [11] .fini PROGBITS 0003f664 03f664 000017 00 AX 0 0 1 [12] .rodata PROGBITS 0003f680 03f680 001fa0 00 A 0 0 8 [13] .eh_frame_hdr PROGBITS 00041620 041620 00002c 00 A 0 0 4 [14] .eh_frame PROGBITS 0004164c 04164c 0000f8 00 A 0 0 4 [15] .ctors PROGBITS 00042000 042000 000018 00 WA 0 0 4 [16] .dtors PROGBITS 00042018 042018 000018 00 WA 0 0 4 [17] .jcr PROGBITS 00042030 042030 000004 00 WA 0 0 4 [18] .data.rel.ro PROGBITS 00042038 042038 0006d8 00 WA 0 0 8 [19] .dynamic DYNAMIC 00042710 042710 0000d0 08 WA 3 0 4 [20] .got PROGBITS 000427e0 0427e0 0001b4 04 WA 0 0 4 [21] .got.plt PROGBITS 00042994 042994 000a64 04 WA 0 0 4 [22] .data PROGBITS 000433f8 0433f8 000010 00 WA 0 0 4 [23] .bss NOBITS 00043408 043408 000bb0 00 WA 0 0 8 [24] .shstrtab STRTAB 00000000 043408 0000c3 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), p (processor specific) Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000000 0x00000000 0x00000000 0x41744 0x41744 R E 0x1000 LOAD 0x042000 0x00042000 0x00042000 0x01408 0x01fb8 RW 0x1000 DYNAMIC 0x042710 0x00042710 0x00042710 0x000d0 0x000d0 RW 0x4 GNU_EH_FRAME 0x041620 0x00041620 0x00041620 0x0002c 0x0002c R 0x4 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 Section to Segment mapping: Segment Sections... 00 .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame 01 .ctors .dtors .jcr .data.rel.ro .dynamic .got .got.plt .data .bss 02 .dynamic 03 .eh_frame_hdr 04 </code></pre>
What's purpose of mov ebx, [esp+0]?
|disassembly|x86|
<p>I think you are running into a case of &quot;shifted pointers&quot;. For various reasons the compiler might generate code where a pointer to the middle of a struct is returned. There is a <a href="https://github.com/NationalSecurityAgency/ghidra/pull/2189" rel="nofollow noreferrer">Ghidra PR</a> for this, but this isn't merged yet and still has various issues, IDA discusses this feature <a href="https://hex-rays.com/products/ida/support/idadoc/1695.shtml" rel="nofollow noreferrer">here</a></p>
29453
2021-10-25T10:13:20.793
<p>In this decompiled code, does <code>psVar8[-6]</code> refer to <code>6*sizeof(psVar8) == 12</code> bytes before <code>psVar8</code>?</p> <pre><code>psVar8 = (short *)(&amp;DAT_1412345b4 + named_index * 0x20); do { if (psVar8[-6] == 0) break; // ... } while (lVar10 &lt; 6); </code></pre> <p>It would seem more intuitive to me if the position of <code>psVar8</code> was earlier to avoid the negative index. Is there a way to change this in the decompiled code, or a reason not to?</p> <p>I'm attaching the entire loop in case that is important to the question:</p> <pre><code> do { if (psVar8[-6] == 0) break; if (psVar8[-6] == 4) { named_variable = 0; if (0 &lt; *psVar8) { named_variable = (int)*psVar8; } iVar4 = 0x1d; if (named_variable &lt; 0x1d) { iVar4 = named_variable; } *(undefined2 *)(&amp;DAT_145678900 + (longlong)iVar4 * 2) = 1; } lVar10 += 1; psVar8 = psVar8 + 1; } while (lVar10 &lt; 6); </code></pre>
Does psVar[-6] refer to 6*sizeof(psVar) bytes before psVar? Can you avoid the negative index?
|c|ghidra|pointer|
<p>select SCALAR in decompiler window<br /> right click -&gt;Set Equate (&quot;E&quot; short cut) type or select if available</p> <p>a sample EQUATE as below</p> <pre><code>uVar6 = *(ushort *)param_2 &amp; THIS_IS_MY_BAD; </code></pre>
29454
2021-10-25T11:20:58.063
<p>In a line like this:</p> <pre><code>if ((my_variable &amp; 0x80000000) == 0) { </code></pre> <p>Is there a way to label <code>0x80000000</code> as e.g. <code>FLAG_HAS_PROPERTY_GREEN</code>, or would I have to rely on comments for that?</p>
Is there a way to name a flag for a bit field in Ghidra?
|c|ghidra|
<p>The data you have here is not base64 encoded, as that would only have letters, numbers, <code>+</code>, <code>/</code>, and (as you mentioned) <code>=</code>. The <code>\x</code> escape code in the string indicates bytes that are non-printable or outside the ASCII range.</p> <p>The regular pattern of <code>=</code> or near-<code>=</code> values (<code>;</code>, <code>&lt;</code>, <code>=</code>, <code>&gt;</code>) every four bytes suggests that this is a simple array of 4-byte little-endian fields with values relatively close to each other. Here is what it looks like as a 4-byte (single precision) float array.</p> <pre><code>&gt;&gt;&gt; data = b'&lt;\x12u&lt;\xf4\x808=\x95\xf0U=\x9fse;\xef\xbe\xf2=A\xd1K=...' &gt;&gt;&gt; struct.unpack_from('&lt;{}f'.format(str(len(data)//4)), data) (0.014957960695028305, 0.045044854283332825, 0.05223139002919197, 0.003501154249534011, 0.11852823942899704, 0.049760106950998306, 0.07483314722776413, 0.07962337881326675, 0.0231693834066391, 0.05004388839006424, [...]) </code></pre> <p>Does this look like the range of values you are expecting?</p>
29461
2021-10-26T15:25:10.370
<p>While reverse engineering a database middleware. This is presumably encoding a list of double or float values with Base64 encoding and then compressing it.</p> <p>Via <code>zlib.decompress()</code> I was able to decompress it, but I got a string of presumably multiple base64-strings. I can see that it consists of more than one, because it contains multiple <code>=</code>. But afaik, these do not always mark the end of a b64-encoded string, because one can also end without a <code>=</code>.</p> <p>This is a excerpt of one field:</p> <pre><code>b'&lt;\x12u&lt;\xf4\x808=\x95\xf0U=\x9fse;\xef\xbe\xf2=A\xd1K=\x1fB\x99=\x95\x11\xa3=\xb8\xcd\xbd&lt;\xd2\xfaL=\x1d\x80U=\xd6:\x1e=\xdcp\xcd=1\xd2\xe1=\t\x01\x8e&lt;\x85\xa8\x16&gt;8\xb4\xa7&gt;2\xf4\x11=&gt;\x03\x9b&lt;\xdfA\x9b&gt;%&gt;a&gt;\xcf\x9a\x05&gt;Ie\x1c&gt;\t@Y&lt;\xdfC\xe2=\xf8\'\xb0=zpa=\x8e\xe8\xde&lt;\xc8\xcby=\x88\xfe\xb6=\xb8Uv=\xd5\xe3\xee=q\xef|&lt;B\xe1\x1f=%\xfe\x85=\x90_\x04=p\x9e\xbd=\x89og=\x96\x88\x87&lt;\xa2\x9c\x84=\x969\xaf=\xab\x84^&lt;\xef\x81\xf6&lt;T\x7f\xf4&lt;\x85\xd6\x86&lt;\x80Q\x93&lt;\xb4\xf9\x00&lt;\xfc&amp;s&lt;\xb9q\x1b&lt;\xd3\xd8\xa0&lt;4\xe9\xc3=\x86a\xb4=\xd5s_=\xc8\xb1==\xc24\xca=~\xd3\xe8=^7\xa5=e\xa3-=\x07?4&lt;\xd5HJ==' </code></pre> <p>As an amateur on this field, I am very unsure where to start. From the documentation I know, that it's a b64-encoded list, but I don't know how to use it. Obviously, when decoded, it will consist of a binary format that in some computer language represents a list of floats.</p> <p>Any tips on how to continue working on this problem? Unfortunately I have no access to the software currently, the only thing I have is this data structure.</p> <p>Sorry for my amateur questions, and thanks in advance for any tips!</p>
Unknown binary format of a b64-encoded list of doubles
|decompress|encodings|unknown-data|
<p>Based on the data provided, it appears to be a very simple check with the 5th byte being the sum of the first 3 bytes exclusive-or'd with the 4th byte.</p> <pre><code>// input bytes byte b[4]; // check byte byte c = ( b[0] + b[1] + b[2] ) ^ b[3]; </code></pre> <hr /> <p>To add how I worked it out -</p> <p>Firstly, I observed that change of a single bit in the 4th byte flipped the same bit in the check byte. This is clear exclusive-or behaviour. The results of Xor-ing the 4th bytes with the check bytes did not then depend on the 4th bytes. This proved this was how the 4th bytes were incorporated.</p> <p>At this point I thought it would be difficult as, once you exclude the 4th byte, you've only provided 3 distinct examples of the first 3 bytes.</p> <p>However, in your first example it stood out that <code>FF</code> + <code>CC</code> = <code>CB</code>.</p> <p>I then tried the sum of the first 3 bytes with your 2nd group of examples and, luckily, it worked too. <code>E8</code>+<code>D6</code>+<code>63</code> = <code>21</code></p> <p>A quick check on the remaining examples showed this worked for them too.</p>
29475
2021-10-29T15:30:52.717
<p>I have a remote for a LED panel which sends following 4 bytes data and last byte some sort of CRC/counter byte. I already know that the first 2 bytes are remote-id, the third byte is panel-id and the fourth byte is command-id. The last byte is somehow calculated in correlation with the first 4 bytes and does not change on repetitive button-press.</p> <p>I already tried to use <code>reveng -w 8 -s [some samples]</code> to find the algorithm, but without success.</p> <p>Maybe someone can help to find the correct way to calculate the last byte of these payload-bytes, and maybe even explain how it was discovered:</p> <pre><code>FFCC0000CB FFCC0001CA FFCC0002C9 FFCC0003C8 FFCC0004CF FFCC0005CE FFCC0006CD FFCC0007CC FFCC0008C3 FFCC0009C2 FFCC000AC1 FFCC000BC0 FFCC000CC7 FFCC000DC6 FFCC000EC5 FFCC000FC4 FFCC0010DB FFCC0011DA FFCC0012D9 FFCC0013D8 E8D6630021 E8D6630120 E8D6630223 E8D6630322 E8D6630425 E8D6630524 E8D6630627 E8D6630726 E8D6630829 E8D6630928 E8D6630A2B E8D6630B2A E8D6630C2D E8D6630D2C E8D6630E2F E8D6630F2E E8D6631031 E8D6631130 E8D6631233 E8D6631332 FFCC0300CE FFCC0301CF FFCC0302CC FFCC0303CD FFCC0304CA FFCC0305CB FFCC0306C8 FFCC0307C9 FFCC0308C6 FFCC0309C7 FFCC030AC4 FFCC030BC5 FFCC030CC2 FFCC030DC3 FFCC030EC0 FFCC030FC1 FFCC0310DE FFCC0311DF FFCC0312DC FFCC0313DD </code></pre>
Finding the hash algorithm for these payload-crc pairs
|crc|
<p>Browsing through peda's source, it seems to use a gdb hook-stop, which can be modified back and forth:</p> <pre><code>gdb-peda$ show user hook-stop User command &quot;hook-stop&quot;: peda context session autosave gdb-peda$ define hook-stop Type commands for definition of &quot;hook-stop&quot;. End with a line saying just &quot;end&quot;. &gt;session autosave &gt;end gdb-peda$ n 18 printf(&quot;...&quot;); gdb-peda$ define hook-stop Type commands for definition of &quot;hook-stop&quot;. End with a line saying just &quot;end&quot;. &gt;peda context &gt;session autosave &gt;end gdb-peda$ n [---registers---] EAX: 0x0 EBX: 0x56557000 --&gt; 0x1ef8 </code></pre> <p>Relevant source is at <a href="https://github.com/longld/peda/blob/84d38bda505941ba823db7f6c1bcca1e485a2d43/peda.py#L6120" rel="nofollow noreferrer">https://github.com/longld/peda/blob/84d38bda505941ba823db7f6c1bcca1e485a2d43/peda.py#L6120</a> and <a href="https://github.com/longld/peda/blob/84d38bda505941ba823db7f6c1bcca1e485a2d43/peda.py#L230" rel="nofollow noreferrer">https://github.com/longld/peda/blob/84d38bda505941ba823db7f6c1bcca1e485a2d43/peda.py#L230</a> .</p> <p>I'd imagine there's a way to extend peda, so that the <code>peda</code> object's methods can be called, but I can't figure that out. In the absence of that, we can invoke those commands manually. Note that gdb doesn't seem to allow nested <code>define</code>s, so we can't script the (re)<code>define</code>s themselves.</p>
29485
2021-10-31T21:41:01.410
<p><code>gdb-peda</code> shows a very useful context each time it stops (<code>b</code>, <code>si</code>, etc.), but sometimes I don't want it. Is there any way to quiet it so it won't show the context automatically (unless prompted <code>context</code>)?</p> <p>--</p> <h1>UPDATE</h1> <p>Since there's no out of the box answer, I'll take, for the bounty, a custom or roll-your-own solution (e.g. a script or special command).</p>
PEDA: Don't show context
|debugging|gdb|python|dynamic-analysis|
<p>I'll start with answering a few basic questions, some of which you didn't even ask!</p> <h5>What are segment registers doing in modern code?</h5> <p>It's been a while since we've needed extra registers to address a memory region. 32, and especially 64, bits are more than enough. OS developers took advantage of those unused registers and nowadays most modern OSes use at least some of the registers to hold OS related data. As mentioned in the comments, on amd64 processors segment registers cannot be used for segmentation but OSes have been doing it on 32 bit processors as well.</p> <p>You can read more about it <a href="https://reverseengineering.stackexchange.com/questions/2006/how-are-the-segment-registers-fs-gs-cs-ss-ds-es-used-in-linux">here</a> regarding linux, <a href="https://reverseengineering.stackexchange.com/questions/16336/where-es-gs-fs-are-pointing-to">here</a> and <a href="https://en.wikipedia.org/wiki/Win32_Thread_Information_Block" rel="nofollow noreferrer">here</a> regarding windows, etcetera.</p> <h5>Why can't I restore data from a previous execution of a program</h5> <p>Although you may control some variables of a program's execution (parameters, stack addresses, process loading addresses and heap location) you're still not controlling all variables (locations of specifica allocations, values returned from &quot;external&quot; sources such as the kernel and as we'll see soon, anti-exploitation mitigations might interfere with that sort of thing too).</p> <p>Generally, you should never expect such a thing to work without taking the necessary adjustments. Let alone in something as low-level and nuanced as setjmp/longjmp.</p> <h5>Why isn't the setjmp/longjmp implementation documented?</h5> <p>Firstly, we're in a reverse engineering community, avoiding documentation does not guarantee confidentiality. Secondly, <em>documentation is in the code</em> :)</p> <p>I would imagine documentation is rather difficult for such low-level details that may change frequently and are <em>very architecture specific</em>. Which leads us to your next question -</p> <h4>Why is setump/longjmp architecture-dependent?</h4> <p>Obviously, this goes without saying, but for completeness I thought it'd be better to be explicit here. Here are some reason this has to be done on an per-architecture level:</p> <ol> <li>As these functions touch the some of a CPU's ABI (specifically the <a href="https://en.wikipedia.org/wiki/X86_calling_conventions" rel="nofollow noreferrer">calling convention</a>), the code has to follow a different conventions.</li> <li>Accessing registers by name, for their specific purpose is abstracted in C.</li> <li>C is a <a href="https://en.wikipedia.org/wiki/Procedural_programming" rel="nofollow noreferrer">procedural language</a>, therefore setjmp/longjmp in their core are direct contradiction to the nature of C since it breaks the boundaries of procedures (functions).</li> <li>Additional architecture-specific features (that are implemented differently, <a href="https://sourceware.org/pipermail/libc-alpha/2017-December/089675.html" rel="nofollow noreferrer">shadow stack</a> and <a href="https://sourceware.org/glibc/wiki/PointerEncryption" rel="nofollow noreferrer">pointer guard</a> are such examples) might change how setjmp/longjmp need to handle specific cases.</li> </ol> <p>I'll discuss amd64 from now on.</p> <h4>How is setjump implemented</h4> <p>Now, although this isn't C (and isn't the most readable assembly either), the code for setjmp on amd64 can be found in <a href="https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=sysdeps/x86_64/setjmp.S" rel="nofollow noreferrer">setjmp.S</a>, longjmp is <a href="https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=sysdeps/x86_64/__longjmp.S" rel="nofollow noreferrer">__longjmp.S</a>. It's even quite commented and the code is pretty straight forward!</p> <p>You can clearly see the registers as they're saved onto the structure (For example, <code>movq %r12, (JB_R12*8)(%rdi)</code>). You can see <code>PTR_MANGLE</code> is called if the aformentinoed pointer guard feature is enabled.</p> <p>Because your question mostly revolved around <em>finding</em> the code and not <em>reading</em> the code and since the code is quite straight-forward, I'll leave reading the functions as an exercise for the reader for now. I'll come back and add more details later on, so feel free to ask follow-up questions.</p> <h5>How is the <code>jmp_buf</code> structure defined</h5> <p>Since we're dealing with assembly we don't have structures. Instead, there are several <code>#define</code> preprocessor directives to define the <code>jmp_buf</code> structure. Those are located in a dedicated header: <a href="https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=sysdeps/x86_64/jmpbuf-offsets.h" rel="nofollow noreferrer">jmpbuf-offsets.h</a></p> <h5>Where are those files located? Where can I find different architecture implementations?</h5> <p>These files are located in the <a href="https://sourceware.org/git/?p=glibc.git;a=tree;f=sysdeps" rel="nofollow noreferrer"><code>sysdep</code></a> module, which holds subdirectories for each supported architecture-specific components. <code>aarch64</code> stands for arm 64-bit, <code>x86</code> for 32-bit intel 8086 compatible processors, <code>86_64</code> for 64 bit intel 8086 CPUs, etcetera.</p>
29486
2021-10-31T22:22:18.817
<p>I'm trying to reverse engineer the GNU libc x86 (32 bit) setjmp / longjmp (re a vuln which may allow arbitrary overwrite of the <code>jmp_buf env</code>.</p> <p>There's a <a href="https://offlinemark.com/2016/02/09/lets-understand-setjmp-longjmp/" rel="nofollow noreferrer">great writeup of the musl setjmp</a> but I can find almost nothing online about the GNU. I've tried to navigate the source, but it's a spaghetti ball of macros, probably due to being so sys dependent. The asm is unusual, using things like:</p> <pre><code>CALL dword ptr GS :[0x10 ] </code></pre> <p>which I don't fully understand (I thought segments were for 16 bit 8088 code! What is the <code>GS:</code>?).</p> <p>A priori, I would expect that setjmp would simply save a few registers, but it seems much more complicated. I've found posts claiming GNU intentionally obfuscates it, either to prevent programmers from relying on internals, or for some security purpose, both of which I'm skeptical of.</p> <p>Experimenting with a debugger has shown one thing: the <code>jmp_buf env</code> changes with each invocation, such as that even the same program, with the same params, and the same stack pointers, if you're using a debugger to load the <code>jmp_buf</code> from one invocation into another you get a SIGV. The contents are clearly not a pure function of the program and stack, but somehow change (randomly?) with each invocation.</p> <p>Are any of the crack REs here able to penetrate <code>setjmp</code>?</p>
How to reverse engineer a setjmp/longjmp sequence?
|disassembly|assembly|x86|memory|operating-systems|
<p>I was able to work this one out.</p> <p>The decompiler was not detecting the correct call parameter counts for the <code>&gt;&gt;</code> and <code>&lt;&lt;</code> operators of <code>cin</code> and <code>cout</code>.</p> <p>For example:</p> <pre><code>int __thiscall std__basic_istream_char_std__char_traits_char____operator__(_DWORD, _DWORD, _DWORD) </code></pre> <p>Is the detected signature of the <code>&gt;&gt;</code> operator.</p> <p>However, reviewing the <a href="https://en.cppreference.com/w/cpp/io/basic_istream/operator_gtgt" rel="nofollow noreferrer"> C++ reference</a>, it should be something more like this:</p> <pre><code>int __thiscall std__basic_istream_char_std__char_traits_char____operator__(void *, int *) </code></pre> <p>Where the first parameter is the <code>cin</code> object and the second is a pointer to the integer output. Because these functions use the <code>__thiscall</code> convention if the parameter count is wrong then the decompiler assumes that the function has modified the stack pointer by the incorrect amount and this leads to all sorts of issues.</p>
29518
2021-11-09T07:39:42.387
<p>I'm practicing reverse engineering in IDA and I created an example application in Visual C++ to practice working with classes/structs and the decompiler output seems to be incorrect - I would like to know if it's possible to fix this to get a closer to correct decompiled result or whether this is simply a limitation of the decompiler.</p> <pre><code>#include &lt;iostream&gt; #include &quot;exstruct.cpp&quot; int main() { int x, y; std::cin &gt;&gt; x; std::cin &gt;&gt; y; calculator c(x, y); std::cout &lt;&lt; c.multiply() &lt;&lt; &quot;\r\n&quot;; } </code></pre> <p>I compiled with the Visual C++ compiler with <em>optimizations turned off</em> and after defining the functions and data structures, the hex-rays decompiler spits out this:</p> <pre><code>int __cdecl main(int argc, const char **argv, const char **envp) { char *newline; // ST04_4 int cout; // eax Calculator calculator; // [esp+4h] [ebp-18h] int x; // [esp+10h] [ebp-Ch] int y; // [esp+14h] [ebp-8h] std::basic_istream&lt;char,std::char_traits&lt;char&gt;&gt;::operator&gt;&gt;(std::cin, &amp;x, calculator.x); std::basic_istream&lt;char,std::char_traits&lt;char&gt;&gt;::operator&gt;&gt;(std::cin, &amp;y, calculator.y); Calculator_constructor(&amp;calculator, x, y); calculator.x = (int)new_line_string; newline = (char *)Calculator_multiply(&amp;calculator); cout = std::basic_ostream&lt;char,std::char_traits&lt;char&gt;&gt;::operator&lt;&lt;(std::cout); printf(cout, (int)newline); return 0; } </code></pre> <p>It all looks pretty good up until it assigns the new line string <code>\r\n</code> to <code>calculator.x</code> and then the result of the multiplication to the <code>newline</code> variable, which is wrong for obvious reasons.</p> <p>I've reviewed the assembly and this is simply not what happens. A snippet of the assembly below:</p> <pre><code>.text:00701088 lea ecx, [ebp+calculator] ; this .text:0070108B call Calculator_constructor .text:00701090 push offset new_line_string ; this .text:00701095 lea ecx, [ebp+calculator] ; this .text:00701098 call Calculator_multiply .text:0070109D push eax .text:0070109E mov ecx, ds:?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A ; std::basic_ostream&lt;char,std::char_traits&lt;char&gt;&gt; std::cout .text:007010A4 call ds:??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z ; std::basic_ostream&lt;char,std::char_traits&lt;char&gt;&gt;::operator&lt;&lt;(int) .text:007010AA push eax .text:007010AB call printf </code></pre> <p>It looks to me like the decompiler is getting confused because the pointer to <code>\r\n</code> literal <code>push</code> happens before the <code>multiply</code> call, making it look like an argument where it actually is not.</p> <p>Is there anyway I can fix this?</p> <p>Full assembly is <a href="https://i.stack.imgur.com/mI9dp.png" rel="nofollow noreferrer">here</a>.</p> <p><code>exstruct.cpp</code> as text:</p> <pre><code>class calculator { public: int x; int y; int z; calculator(int x, int y) { this-&gt;x = x; this-&gt;y = y; this-&gt;z = x + y; } int multiply() { return this-&gt;x * this-&gt;y; } }; </code></pre> <p>Constructor &amp; Multiply Source &amp; Decompiled Source:</p> <p><a href="https://i.stack.imgur.com/lJMz5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lJMz5.png" alt="here" /></a>.</p> <p>Notes:</p> <ul> <li>Hex-Rays Decompiler v7.0.0.170914</li> <li>I manually increased the size of the function to <code>1C</code> as it wasn't originally detecting <code>newline</code> as a field</li> <li>I manually defined the location of <code>\r\n</code> in memory as a string</li> </ul>
Hex-rays decompiler incorrect logic
|ida|decompilation|c++|hexrays|
<p><em>Welcome to the Reverse engineering stack exchange Q&amp;A site! Although you only asked about <code>nullsub_</code>, you described <code>___cxa_pure_virtual</code> slightly incorrectly so I'll describe it as well</em></p> <h3>nullsub_X</h3> <p>IDA makes a minimal effort of providing meaningful, yet general, names for functions according to their implementation by adding a prefix or name for certain <em>types</em> of functions.</p> <p>One such case is <code>nullsub</code>, which is a name automatically given (during the analysis phase) to all <em>empty</em> functions. Meaning functions that simply return without doing <strong>anything</strong>.</p> <p>Additionally, since names are unique in IDA, when an in-use name is set to a function IDA will postfix it with an underscore and then an auto-incremented number (starting with 1).</p> <p>If you're wondering why such functions should exist in the first place, <a href="https://reverseengineering.stackexchange.com/questions/2420/what-are-nullsub-functions-in-ida/2422#2422">this</a> post answers that question quite diligently.</p> <h3>___cxa_pure_virtual</h3> <p>This is a function implemented by <a href="https://gcc.gnu.org/onlinedocs/libstdc++/" rel="nofollow noreferrer"><code>libstdc++</code></a> (and a similar function is implemented by other C++ standard libraries) as a place-holder to <strong>pure</strong> virtual functions in virtual function tables.</p> <p>Although pure virtual functions have no implementation the compiler cannot eliminate the risk of pure virtual functions being called at run-time, and so a stub such as <code>___cxa_pure_virtual</code> is used as a place-holder for all pure virtual functions, so that if it ever happens that a pure virtual function would be called at runtime, there an explicit handling (termination of the program with a somewhat meaningful crash, often).</p>
29519
2021-11-09T09:47:09.257
<p>When I looking in a vtable structure in IDA pro, I know that <code>___cxa_pure_virtual</code> means that the function is virtual.</p> <p>But what does <code>nullsub_XXX</code> mean in a vtable structure?</p>
What is "nullsub_XXX" in vtable in IDA
|ida|c++|static-analysis|vtables|
<p><kbd>Shift</kbd>+<kbd>F</kbd> or right-click on the variable and then choose &quot;Force new variable&quot;.</p> <p>IDA documentation: <a href="https://www.hex-rays.com/products/decompiler/manual/cmd_force_lvar.shtml" rel="nofollow noreferrer">https://www.hex-rays.com/products/decompiler/manual/cmd_force_lvar.shtml</a></p>
29525
2021-11-09T22:11:32.497
<p>Sometime the meaning of variable has been changed on the function.</p> <p>For example from Ida pseudo code:</p> <pre><code>a = price .... a= tax.... </code></pre> <p>In the beginning of function <code>a</code> was price and after that <code>a</code> is tax.</p> <p>How can I split a to 2 different variable so I can rename this variable in Ida Pro</p>
Split variable in Ida Pesudo Code
|ida|static-analysis|
<h3>Tracing memory allocations</h3> <p>Tracing is when instead of <em>stopping</em> when a function is called a tool will simply write a log line (usually with some additional data). Tracing is often a lot faster than interrupting the execution and yielding control to a user to handle the break point.</p> <p>This is probably the simplest solution for you. You could trace all allocations either using a debugger with tracing or scripting capabilities or using a specific tracing utility such as <a href="https://www.man7.org/linux/man-pages/man1/ltrace.1.html" rel="nofollow noreferrer"><code>ltrace</code></a>.</p> <p>Once you have tracing set-up and running, you can search for the address of the allocated buffer you're interested in investigating, to find all calls it was involved in.</p> <p>The <a href="https://www.man7.org/linux/man-pages/man1/ltrace.1.html" rel="nofollow noreferrer"><code>ltrace</code> man page</a> is quite helpful but in your case simply <code>grep</code>-ing for the address will do just fine. <code>ltrace</code> has definitions for standard library APIs such as <code>new</code> and <code>malloc</code>.</p> <p>Tracing with <code>gdb</code> will require a bit of gdb-scripting but something like the following should do:</p> <pre><code>(gdb) b malloc Breakpoint 1 at XXXX (gdb) commands 1 Type commands for when breakpoint 1 is hit, one per line. End with a line saying just &quot;end&quot;. &gt;silent # don't stop on breakpoint being hit &gt;backtrace # print current back-trace &gt;p $eax # Pass the input to the call, should be the size allocation! &gt;fin # execute till function's return &gt;p $eax # print return value, should be chunk address! &gt;continue # continue execution of the program &gt;end </code></pre> <h3>Memory access break point on the allocated region</h3> <p>Using a debugger such as <code>gdb</code>, you could place a <em>memory access</em> breakpoint (also called a <a href="https://sourceware.org/gdb/onlinedocs/gdb/Set-Watchpoints.html" rel="nofollow noreferrer">watchpoint</a>) on the allocation's address. Thus by executing <code>awatch &lt;allocation address&gt;</code> you'll have a breakpoint hit every time the allocation is accessed (there's a caveat, though).</p> <p>This won't immediately give you the size of the allocation, but with some reverse engineering and back-tracking the address's origin, you can find the original allocation call that resulted in that buffer. A beneficial side-effect is easily seeing what's the allocation used for.</p> <p>As mentioned previously using memory breakpoints may have a caveat. If your hardware doesn't support the mechanisms required for implementing memory breakpoints efficiently, memory break points may be implemented in software which is pretty slow.</p> <h3>Looking up the size through heap data structures</h3> <p>This may be the most straight-forward way to answer your original question (how to find the size of an allocated heap chunk) theoretically but the most difficult to implement. It may still be of interest to future readers.</p> <p>As the heap is designed to manage allocations in different sizes, all heap implementations maintain metadata about the size of all allocated chunks. That metadata can be read or retrieved and heap-visualization tools will even help with that.</p> <p>Some heap implementations hold the chunk metadata in-bounds, and prefix each allocated chunk with a short header that either directly indicates of it's size, or points to a &quot;bin&quot; of allocations of a given size, or both. <a href="http://web.archive.org/web/20190619034641/http://g.oswego.edu/dl/html/malloc.html" rel="nofollow noreferrer">dlmalloc</a> is an example of such implementation.</p> <p>Some heap allocator implementations include:</p> <p><a href="http://web.archive.org/web/20190619034641/http://g.oswego.edu/dl/html/malloc.html" rel="nofollow noreferrer">dlmalloc</a> - Doug Lea's malloc</p> <p><a href="http://jemalloc.net/" rel="nofollow noreferrer">jemalloc</a> - Jason Evans' malloc</p> <p>HeapAlloc - Visual Studio's allocator</p> <hr /> <p>Side note: heap allocations don't necessarily originate from <code>new</code> calls. There are other possible APIs that request memory from the heap, <code>malloc</code> for example. You should find the lowest API that might interest you.</p>
29532
2021-11-10T22:02:55.197
<p>While I debug with GDB I see the address of a buffer that's located on the heap.</p> <p>How can I know what is the size of this buffer? Or where (in the code) this buffer was originally allocated?</p> <p>When I place a breakpoint on the <code>new</code> function to find out the allocation the process significantly slows down, making debugging difficult.</p>
How can I find out the size of heap allocations?
|debugging|linux|gdb|memory|heap|
<p>Here is the solution:</p> <p>The constructor can be called like this:</p> <pre><code> gladius::GameStruct* thisptr = (gladius::GameStruct*)malloc(sizeof(gladius::GameStruct)); gladius::get().gameConstructor(thisptr); </code></pre> <p>where sizeof(GameStruct) <strong>must match</strong> the size of the original constructor. In my case the Game structure should be re-written to have something like:</p> <pre><code>struct GameStruct : Game{ DWORD_PTR* unknownPtrA = 0; DWORD_PTR* unknownPtrB = 0; DWORD_PTR* unknownPtrC = 0; DWORD_PTR* unknownPtrD = 0; DWORD_PTR* guiObjPtr = 0; DWORD_PTR* unknownPtrE = 0; DWORD_PTR* unknownPtrF = 0; DWORD_PTR* unknownPtrG = 0; DWORD_PTR* unknownPtrH = 0; DWORD_PTR* unknownPtrI = 0; DWORD_PTR* unknownPtrJ = 0; }; </code></pre> <p>to bring the pointers in constructor outside of the Game struct. This way it matches the original constructor in what it does and in size (i.e. 11 members 8 bytes each = 88 bytes of size)</p> <p>Or / and the pointers to the functions should be placed inside the standard C++ functions and be called from there as that way they won't occupy the additional memory space which needs to be allocated.</p>
29541
2021-11-11T20:50:30.367
<p>I wonder how to declare the reference to a constructor to a reversed class, i.e. I have a class say Game and it has a constructor at a certain address.</p> <p>It is declared like this:</p> <p><strong>game.h</strong></p> <pre><code>namespace gladius { struct Game { //virtual int __thiscall main(gladius::Game* thisptr, int param_1, char** param_2, char** param_3); using GameConstructor = Game * (__fastcall*) (Game* thisptr); GameConstructor gameConstructor; .......... } </code></pre> <p><strong>game.cpp</strong></p> <pre><code>namespace gladius { static std::array&lt;Game, 1&gt; functions = { { Game{ (Game::GameConstructor)(AddressHelper::getInstance().GetBaseAddress() + 0x331b0 / (2 * sizeof(DWORD))), </code></pre> <p>Now let's imagine I want an instance of the Game object. How do I get one as something like this</p> <pre><code>Game gameObj = gameConstructor; </code></pre> <p>is not going to work as gameObj and gameConstructor have different type. Without reversing the constructor is there any way to call it (by address) and assign the reversed class instance to it?</p> <p>And</p> <pre><code> namespace gladius { struct Game { using Game = Game * (__fastcall*) (Game* thisptr); Game gameConstructor; </code></pre> <p>doesn't work as a declaration as you can't declare type the same as the type of the class / structure and I don't know how to modify the above to keep it as a reference to the addressed method rather than a fully reversed function.</p> <p>Basically the question is, how to do</p> <pre><code>Game objInst = new Game(); </code></pre> <p>where <code>new Game();</code> points to existing Game constructor (accessible by address offset)?</p>
How to declare a constructor in reversed class?
|c++|dll|function-hooking|dll-injection|api-reversing|
<h3>LIEF</h3> <p>If the binary is a PIE, exporting functions via the LIEF binary instrumentation framework should allow you to call the function you are interested in as if it was a function in a shared object.</p> <ul> <li>Example: <a href="https://lief-project.github.io//doc/latest/tutorials/08_elf_bin2lib.html" rel="nofollow noreferrer">LIEF - Transforming an ELF executable into a library</a></li> </ul> <h3>LD_PRELOAD</h3> <p>If the binary is dynamically linked and contains code for setting up the standard C runtime environment e.g. <code>__libc_start_main</code> calling <code>main()</code>, you can hook these functions with LD_PRELOAD and interpose your own code via shared library injection which calls the target function directly with arguments of your choosing.</p> <ul> <li>Example: <a href="https://breaking-bits.gitbook.io/breaking-bits/vulnerability-discovery/reverse-engineering/modern-approaches-toward-embedded-research" rel="nofollow noreferrer">Modern Vulnerability Research Techniques on Embedded Systems</a></li> <li>Example: <a href="https://gist.github.com/apsun/1e144bf7639b22ff0097171fa0f8c6b1" rel="nofollow noreferrer">Hook main() using LD_PRELOAD </a></li> </ul> <h3>Qiling emulator</h3> <p>Using the Qiling emulator, you can record the state of the program and then replay the target function in GDB. Since the code is being emulated, it is straightforward to manipulate any aspect of the process' state (registers, memory, etc.)</p> <ul> <li>Example: <a href="https://github.com/qilingframework/qiling/blob/master/examples/hello_x8664_linux_part_debug.py" rel="nofollow noreferrer">qiling/examples/hello_x8664_linux_part_debug.py</a></li> </ul> <h3>DBI</h3> <p>Using Frida, Pin, DynamoRIO etc. you can basically make the program do what you want at run time, in this case hook a function, manipulate its arguments and observe the subsequent behavior.</p> <ul> <li>Example: <a href="https://blog.fadyothman.com/getting-started-with-frida-hooking-main-and-playing-with-its-arguments/" rel="nofollow noreferrer">Getting Started with Frida : Hooking a Function and Replacing its Arguments</a></li> <li>Example: <a href="https://software.intel.com/sites/landingpage/pintool/docs/98484/Pin/html/index.html#FunctionArguments" rel="nofollow noreferrer">Pin 3.21 User Guide: Finding the Value of Function Arguments</a></li> </ul> <h3>Trampolining with e9patch</h3> <p>e9patch is a static binary rewriting tool that allows one to change/insert code prior to run time.</p> <ul> <li>Example: <a href="https://github.com/GJDuck/e9patch/blob/master/doc/e9tool-user-guide.md" rel="nofollow noreferrer">e9tool user guide</a></li> <li>Example: <a href="https://github.com/GJDuck/e9afl" rel="nofollow noreferrer">e9afl</a></li> </ul> <p>There are probably even more ways to do this, such as process snapshotting with ptrace and /proc and then manipulating registers and memory with ptrace, emulation with PANDA, emulation with Unicorn, emulation with QEMU, possibly even ELF parasite code or inserting code that calls the target function using LD_PRELOAD together with <code>__attribute__ ((constructor)) injected_function()</code>. You have a lot of options.</p>
29542
2021-11-11T21:17:09.640
<p>I have a binary with a func that I can disassemble. What are simple ways for me to call it with arbitrary args and observe its return val and behavior?</p> <p>Ideally, I'd like to do this:</p> <ul> <li>Within gdb (or gdb-peda)</li> <li>From C (ie linking to the executable as if its a lib)</li> <li>Via Python scripts (I recall reading about a Python script to do this, but can't find it)</li> </ul> <p>I'm operating on Linux, but this question is relevant to other OS as well.</p>
How to call a func in an executable binary?
|disassembly|binary-analysis|dynamic-analysis|libraries|call|
<p>I expect that the compiler emitted two different symbol references in the two LEA instructions, and uses the compare instruction to detect at run time whether the two symbols were resolved to the same address at link time. Many modern compilers/linkers offer &quot;link time code generation&quot; aka &quot;whole program optimization&quot;, where the compiler's optimizer runs at link time. In such a system, there would be no need for a runtime check, but the compiler is (re-)called at link time and can optimize (in this case: eliminate/not generate the dead path) in response to seeing all modules getting linked together.</p>
29546
2021-11-12T18:34:06.020
<p>This is the second time I see this kind of function today :</p> <pre><code>.text:00000000000010B0 sub_10B0 proc near ; CODE XREF: sub_1120:loc_1143↓p .text:00000000000010B0 lea rdi, byte_4418 .text:00000000000010B7 lea rax, byte_4418 .text:00000000000010BE cmp rax, rdi .text:00000000000010C1 jz short locret_10D8 .text:00000000000010C3 mov rax, cs:_ITM_deregisterTMCloneTable_ptr .text:00000000000010CA test rax, rax .text:00000000000010CD jz short locret_10D8 .text:00000000000010CF jmp rax .text:00000000000010CF ; ------------------------------------------------------------------ .text:00000000000010D1 align 8 .text:00000000000010D8 .text:00000000000010D8 locret_10D8: ; CODE XREF: sub_10B0+11↑j .text:00000000000010D8 ; sub_10B0+1D↑j .text:00000000000010D8 retn .text:00000000000010D8 sub_10B0 endp </code></pre> <p>As I understand, both <code>jz</code> are going to jump anyway, so the first <code>jz</code> is always going to jump to the <code>ret</code>.</p> <p>Why isn't this function written more simply, just like a single <code>return &amp;byte_4418</code> ?</p> <pre><code>lea rax, byte_4418 retn </code></pre> <p>I hope my English is good enough to be understood.</p> <p>Thank you,</p> <p>Max</p> <p>PS : I'm sorry, I don't know which compiler is used.</p>
Useless instructions in a compiled getter
|ida|assembly|decompilation|c|
<p>This message shows that you, or a script you run, is trying to create a struct with a name that already exists.</p> <p>Common IDAPython analysis scripts try to define known struct types found in the disassembled code by, for example, known function signatures/symbols.</p> <p>This can be done by calling <code>AddStrucEx</code> function.</p> <p>Scripts don't always check whether the struct is already defined before trying to add it - resulting in this error.</p> <p><code>stat64</code> is a standard Linux structure and variables of that type are most likely used many times in the code.</p>
29563
2021-11-15T01:22:57.117
<p>I am using IDA pro to analyze an old nginx binary. I am getting following warnings which I have never seen before. Does anyone have an idea about these warnings?</p> <pre><code>IDA is analysing the input file... You may start to explore the input file right now. failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'statfs64': name is already used failed to add structure type 'statfs64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'statfs64': name is already used failed to add structure type 'statfs64': name is already used failed to add structure type 'statfs64': name is already used failed to add structure type 'statfs64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used failed to add structure type 'stat64': name is already used </code></pre> <p>I can send you nginx binary if required. And the binary is compiled using a custom version of llvm. I am using IDA Pro 7.5 and an IDAPython script.</p>
IDA Pro: unknown warnings
|ida|idapython|
<p>Yes, it is.</p> <p>For <em>decimal</em> numbers, use the syntax <em>with the period just <strong>before</strong></em> the number, e.g. <code>.10</code>:</p> <p><a href="https://i.stack.imgur.com/t2Xgq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t2Xgq.jpg" alt="enter image description here" /></a></p> <p>Particularly, in your case you will obtain exactly what you wanted (I omitted leading zeroes):</p> <p><a href="https://i.stack.imgur.com/Yr8o5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yr8o5.jpg" alt="enter image description here" /></a></p>
29568
2021-11-16T05:44:10.393
<p>The x64dbg calculator can evaluate hex expressions.</p> <p><a href="https://i.stack.imgur.com/jEl7u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jEl7u.png" alt="enter image description here" /></a></p> <p>Is there a syntax to calculate the sum of a hex value and a decimal value? For the example in the snapshot, is it possible to treat <code>10</code> as a decimal? The expected result is <code>939936F59A</code>. If it can't, what's the most convenient tool to do this kind of calculation?</p>
How to use decimal in x64dbg calculator?
|x64dbg|hexadecimal|
<p>You should ask a lawyer about legal questions -- I am not one, and my understanding of this topic is not more valuable than an actual lawyer's. That said, to my knowledge: generally speaking, for someone to land in legal trouble for reverse engineering, they either need to have:</p> <ol> <li>Committed an offense that the law lays out as being criminal, in which case they might be criminally prosecuted by the government. Related offenses can include piracy of commercially copyrighted materials, or of stealing trade secrets.</li> <li>Have undertaken some action that makes the holder of the copyright feel aggrieved, and compels them to file a lawsuit. In general, these civil actions center around things like license violations, copyright and trademark infringement, and misappropriation of intellectual property.</li> </ol> <p>Both of the above center around unauthorized uses of reverse engineering. Given that you are talking distributing software for free, with explicit authorization of reverse engineering, with source code, and with instructions on how to reverse engineer it, you are effectively waiving your rights to the types of civil proceedings that generally surround reverse engineering. If you were to sue somebody for reverse engineering your software, they would simply point to your own authorization as a defense as to why their actions were legal. On the criminal side, nobody's commercial interests are being harmed -- which is the cornerstone of criminal penalties against reverse engineering -- and so the government has no reason to care about it. Somebody with a stake in the matter has to be upset in order for a reverse engineer to go to jail or get sued.</p> <p>The idea of people creating software for the express purpose of other people reverse engineering it is not new. Capture The Flag and crackme contests have already been doing this for decades. Although it's less common, sometimes commercial software allows reverse engineering by license agreement. For example, here's a bit of text from <a href="https://hex-rays.com/ida_eula.pdf" rel="noreferrer">Hex-Rays' license agreement</a>:</p> <blockquote> <p>This license also allows you to</p> <ul> <li>reverse-engineer the software.</li> </ul> </blockquote> <p>One thing I might note is that, if your code relies upon third-party libraries: you, yourself, do not have legal standing to authorize people to reverse engineer other peoples' code. I.e., if the game engine that you're using has license provisions against reverse engineering, your declaration that it is okay to reverse engineer your own code ultimately does not supplant the engine developers' own license terms surrounding reverse engineering of their code. I imagine it's possible that the engine developer could hold you liable for breaches of their license terms. But, if the engine is open source, then intellectual property interests like that are a moot point, since people can simply read the source code much easier than they could reverse engineer it.</p>
29577
2021-11-18T22:20:08.147
<p>Say I used a game engine and made a game (from scratch on my own). Further, I provide details on how to reverse engineer my game, including methods and details.</p> <p>Two questions.</p> <ol> <li>Is it legal to do that?</li> <li>Can I open my code and provide a use case of reverse engineering in games for educational purposes?</li> </ol>
Is it legal to publish details on how to reverse engineer a non commercial game?
|law|
<p>If windbg has broken on ntdll!NtCreateFile and you issue a p or t it should Single step properly<br /> it will execute the syscall inside ntdll!NtCreateFile in a single Step see below</p> <pre><code>0: kd&gt; g Breakpoint 0 hit ntdll!NtCreateFile: 0033:00007ff9`7fcf0100 4c8bd1 mov r10,rcx 0: kd&gt; p ntdll!NtCreateFile+0x3: 0033:00007ff9`7fcf0103 b855000000 mov eax,55h 0: kd&gt; p ntdll!NtCreateFile+0x8: 0033:00007ff9`7fcf0108 f604250803fe7f01 test byte ptr [SharedUserData+0x308 (00000000`7ffe0308)],1 0: kd&gt; p ntdll!NtCreateFile+0x10: 0033:00007ff9`7fcf0110 7503 jne ntdll!NtCreateFile+0x15 (00007ff9`7fcf0115) 0: kd&gt; p ntdll!NtCreateFile+0x12: 0033:00007ff9`7fcf0112 0f05 syscall 0: kd&gt; k2 # Child-SP RetAddr Call Site 00 0000003f`e10ac5e8 00007ff9`7bd5e5d6 ntdll!NtCreateFile+0x12 01 0000003f`e10ac5f0 00007ff9`7bd5e2c6 KERNELBASE!CreateFileInternal+0x2f6 0: kd&gt; p ntdll!NtCreateFile+0x14: 0033:00007ff9`7fcf0114 c3 ret 0: kd&gt; p KERNELBASE!CreateFileInternal+0x2f6: 0033:00007ff9`7bd5e5d6 0f1f440000 nop dword ptr [rax+rax] </code></pre> <p>from your query it is not clear what you are doing<br /> what is the relevance of lm to .process command ??</p> <p>if you need to single step inside the kernel part you need to have a breakpoint on the actual implementation of ntdll!NtCreateFile in the executive</p> <p>set a process specific breakpoint on both <strong>ntdll!NtCreateFile and nt!NtCreateFile</strong></p> <p>either a p (step over ) or t (step in ) should break on the kernel part</p> <p>also notepad.exe is not a good target for practicing if I recall correctly it uses memory mapped operations instead of opening</p> <p>anyway shown below is a simple demo of breaking on user part and single stepping into kernel part on notepad.exe for file-&gt;open from menu (this will trigger the break on NtCreateFile )</p> <p>look for specific binary (notepad.exe in your case and set process specific breakpoint on user stub in ntdll and executive implementation on kernel.</p> <pre><code>1: kd&gt; $$ look for relevent process 1: kd&gt; !process 0 0 notepad.exe PROCESS ffffc50d96c97080 SessionId: 1 Cid: 10a0 Peb: 3fe1263000 ParentCid: 1008 DirBase: 1e3c0002 ObjectTable: ffff8787c380b700 HandleCount: 568. Image: notepad.exe 1: kd&gt; bp /p ffffc50d96c97080 ntdll!NtCreateFile 1: kd&gt; bp /p ffffc50d96c97080 nt!NtCreateFile 1: kd&gt; bl 0 e Disable Clear 00007ff9`7fcf0100 0001 (0001) ntdll!NtCreateFile Match process data ffffc50d`96c97080 1 e Disable Clear fffff800`4f8914e0 0001 (0001) nt!NtCreateFile Match process data ffffc50d`96c97080 </code></pre> <p>execute and let the target run using g</p> <p>now in side the target use File-&gt;open on the open binary instance (notepad.exe in your case)<br /> the breakpoint on notepad.exe in ntdll should be hit with a call stack thus</p> <p>(be aware you need a proper symbol path and cache of pdbs and you should have issued .reload /f now or prior to calling k for a proper call stack display)</p> <p>Notice the InvokeOpenDialog() in notepad.exe this triggers the break further up on ntdll!NtCreatFile</p> <pre><code>1: kd&gt; g Breakpoint 0 hit ntdll!NtCreateFile: 0033:00007ff9`7fcf0100 4c8bd1 mov r10,rcx 1: kd&gt; k # Child-SP RetAddr Call Site 00 0000003f`e10acaa8 00007ff9`7bd5e5d6 ntdll!NtCreateFile 01 0000003f`e10acab0 00007ff9`7bd5e2c6 KERNELBASE!CreateFileInternal+0x2f6 02 0000003f`e10acc20 00007ff9`7bd5cc21 KERNELBASE!CreateFileW+0x66 03 0000003f`e10acc80 00007ff9`7bd5edc0 KERNELBASE!BasepLoadLibraryAsDataFileInternal+0x291 04 0000003f`e10aceb0 00007ff9`7d912010 KERNELBASE!LoadLibraryExW+0xe0 05 0000003f`e10acf20 00007ff9`7d90fdee SHELL32!GetShellStyleHInstance+0xc8 06 0000003f`e10ad250 00007ff9`7d93d3a4 SHELL32!UpdateStyle+0x1e 07 0000003f`e10ad290 00007ff9`7d93cece SHELL32!DUI_ShellStyleSheet_InitProcess+0x94 08 0000003f`e10ad2d0 00007ff9`7d908ed7 SHELL32!InitializeDirectUI+0x32 09 0000003f`e10ad300 00007ff9`7d981320 SHELL32!CDUIViewFrame::CreateFrameWindow+0x37 0a 0000003f`e10ad360 00007ff9`7d97fc8c SHELL32!CreateViewFrame+0x8c 0b 0000003f`e10ad3d0 00007ff9`7d97fb2c SHELL32!CExplorerBrowser::_SwitchView+0xc0 0c 0000003f`e10ad4a0 00007ff9`7d97f10f SHELL32!CExplorerBrowser::_BrowseToView+0x204 0d 0000003f`e10ad540 00007ff9`7d97ede3 SHELL32!CExplorerBrowser::_BrowseObjectInternal+0xef 0e 0000003f`e10ad5c0 00007ff9`7d97e330 SHELL32!CExplorerBrowser::_OnBrowseObject+0x37 0f 0000003f`e10ad5f0 00007ff9`7cfb5b83 SHELL32!CExplorerBrowser::BrowseObject+0xb0 10 0000003f`e10ad6f0 00007ff9`7cfbd43f COMDLG32!CFileOpenSave::_JumpToInitialLocation+0x1c3 11 0000003f`e10ad780 00007ff9`7cfc9cbe COMDLG32!CFileOpenSave::_InitOpenSaveDialog+0x191f 12 0000003f`e10ae200 00007ff9`7fa8e9cf COMDLG32!CFileOpenSave::s_OpenSaveDlgProc+0x68e 13 0000003f`e10ae4a0 00007ff9`7fa87d62 USER32!UserCallDlgProcCheckWow+0x197 14 0000003f`e10ae580 00007ff9`7fa87c76 USER32!DefDlgProcWorker+0xd2 15 0000003f`e10ae640 00007ff9`7fa8ca66 USER32!DefDlgProcW+0x36 16 0000003f`e10ae680 00007ff9`7fa8c0b8 USER32!UserCallWinProcCheckWow+0x266 17 0000003f`e10ae800 00007ff9`7fa8fa5e USER32!SendMessageWorker+0x218 18 0000003f`e10ae8a0 00007ff9`7faaf61a USER32!InternalCreateDialog+0xa2e 19 0000003f`e10aea80 00007ff9`7faaf4f2 USER32!InternalDialogBox+0x106 1a 0000003f`e10aeae0 00007ff9`7faaf488 USER32!DialogBoxIndirectParamAorW+0x52 1b 0000003f`e10aeb20 00007ff9`7cfd84de USER32!DialogBoxIndirectParamW+0x18 1c 0000003f`e10aeb60 00007ff9`7cfbe568 COMDLG32!&lt;lambda_772b13dd37a5eaf1da6a98973fbee968&gt;::operator()+0x9e 1d 0000003f`e10aeba0 00007ff6`8ced20ac COMDLG32!CFileOpenSave::Show+0xb08 1e 0000003f`e10af000 00007ff6`8ced226b notepad!ShowOpenSaveDialog+0x104 1f 0000003f`e10af060 00007ff6`8ced2941 notepad!InvokeOpenDialog+0x14f 20 0000003f`e10af0c0 00007ff6`8ced4037 notepad!NPCommand+0x425 21 0000003f`e10af440 00007ff9`7fa8ca66 notepad!NPWndProc+0x5e7 22 0000003f`e10af740 00007ff9`7fa8c582 USER32!UserCallWinProcCheckWow+0x266 23 0000003f`e10af8c0 00007ff6`8ced448d USER32!DispatchMessageWorker+0x1b2 24 0000003f`e10af940 00007ff6`8ceeae07 notepad!WinMain+0x255 25 0000003f`e10afa40 00007ff9`7d5b81f4 notepad!__mainCRTStartup+0x19f 26 0000003f`e10afb00 00007ff9`7fcba251 KERNEL32!BaseThreadInitThunk+0x14 27 0000003f`e10afb30 00000000`00000000 ntdll!RtlUserThreadStart+0x21 </code></pre> <p>now you can single step up to syscall with either p or t (I am using pc to step unto next call as i have pasted the instructions above) and on executing the syscall your break on the executive (nt) should be hit.</p> <p>happy tracing :)</p> <pre><code>1: kd&gt; p ntdll!NtCreateFile+0x3: 0033:00007ff9`7fcf0103 b855000000 mov eax,55h 1: kd&gt; pc ntdll!NtCreateFile+0x12: 0033:00007ff9`7fcf0112 0f05 syscall 1: kd&gt; t Breakpoint 1 hit nt!NtCreateFile: fffff800`4f8914e0 4881ec88000000 sub rsp,88h 1: kd&gt; k4 # Child-SP RetAddr Call Site 00 ffff8386`4a667a88 fffff800`4f467785 nt!NtCreateFile 01 ffff8386`4a667a90 00007ff9`7fcf0114 nt!KiSystemServiceCopyEnd+0x25 02 0000003f`e10acaa8 00007ff9`7bd5e5d6 ntdll!NtCreateFile+0x14 03 0000003f`e10acab0 00007ff9`7bd5e2c6 KERNELBASE!CreateFileInternal+0x2f6 1: kd&gt; !obja @r8 Obja +0000000000000000 at 0000003fe10acb78: Name is \??\C:\Windows\resources\themes\Aero\Shell\NormalColor\ShellStyle.dll OBJ_CASE_INSENSITIVE 1: kd&gt; ?? (char *)((nt!_EPROCESS *)@$proc)-&gt;ImageFileName char * 0xffffc50d`96c974d0 &quot;notepad.exe&quot; </code></pre>
29582
2021-11-20T08:53:19.733
<p>I have a VM running windows with notepad open, I did list the modules with <em>lm</em>:</p> <pre><code>start end module name 00007ffc`60fb0000 00007ffc`60fe2000 vertdll (deferred) 00007ffc`60ff0000 00007ffc`611e5000 ntdll # (pdb symbols) C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\sym\ntdll.pdb\96EF4ED537402DAAA51D4A4212EA4B2C1\ntdll.pdb fffff5cc`05c00000 fffff5cc`05ed3000 win32kbase (deferred) fffff5cc`05f70000 fffff5cc`0600a000 win32k (deferred) fffff5cc`064c0000 fffff5cc`06877000 win32kfull (deferred) fffff5cc`06880000 fffff5cc`068c9000 cdd (deferred) fffff801`40600000 fffff801`4088f000 mcupdate_GenuineIntel (deferred) fffff801`40890000 fffff801`40896000 hal (deferred) fffff801`408a0000 fffff801`408ae000 kdcom (deferred) fffff801`408b0000 fffff801`408d7000 tm (deferred) fffff801`408e0000 fffff801`4094a000 CLFS (deferred) fffff801`40950000 fffff801`4096a000 PSHED (deferred) fffff801`40970000 fffff801`4097b000 BOOTVID (deferred) fffff801`40980000 fffff801`409ef000 FLTMGR (deferred) fffff801`409f0000 fffff801`409fe000 cmimcext (deferred) fffff801`40c00000 fffff801`40c7f000 cldflt (deferred) fffff801`40c80000 fffff801`40c9a000 storqosflt (deferred) fffff801`40ca0000 fffff801`40cc8000 bindflt (deferred) fffff801`40cd0000 fffff801`40ce8000 lltdio (deferred) fffff801`40cf0000 fffff801`40d08000 mslldp (deferred) fffff801`40d10000 fffff801`40d2b000 rspndr (deferred) fffff801`40d30000 fffff801`40d4d000 wanarp (deferred) fffff801`40d50000 fffff801`40da6000 msquic (deferred) fffff801`40db0000 fffff801`40f38000 HTTP (deferred) fffff801`40f40000 fffff801`40f65000 bowser (deferred) fffff801`40f70000 fffff801`40f8a000 mpsdrv (deferred) fffff801`40f90000 fffff801`41024000 mrxsmb (deferred) fffff801`41030000 fffff801`41076000 mrxsmb20 (deferred) fffff801`41080000 fffff801`4108a000 vmmemctl (deferred) fffff801`41090000 fffff801`410e3000 srvnet (deferred) fffff801`410f0000 fffff801`41104000 mmcss (deferred) fffff801`41110000 fffff801`411d7000 srv2 (deferred) fffff801`411e0000 fffff801`41207000 Ndu (deferred) fffff801`41210000 fffff801`412e6000 peauth (deferred) fffff801`412f0000 fffff801`41305000 tcpipreg (deferred) fffff801`41310000 fffff801`4132c000 rassstp (deferred) fffff801`41330000 fffff801`4134d000 NDProxy (deferred) fffff801`41350000 fffff801`4137b000 vmhgfs (deferred) fffff801`41380000 fffff801`413a7000 AgileVpn (deferred) fffff801`413b0000 fffff801`413d1000 rasl2tp (deferred) fffff801`413e0000 fffff801`41401000 raspptp (deferred) fffff801`41410000 fffff801`4142c000 raspppoe (deferred) fffff801`41430000 fffff801`41442000 condrv (deferred) fffff801`41450000 fffff801`4145f000 ndistapi (deferred) fffff801`41460000 fffff801`4149b000 ndiswan (deferred) fffff801`414a0000 fffff801`414b2000 WdNisDrv (deferred) fffff801`419a0000 fffff801`41a13000 dxgmms1 (deferred) fffff801`41a20000 fffff801`41a3b000 monitor (deferred) fffff801`41a40000 fffff801`41b21000 dxgmms2 (deferred) fffff801`41b30000 fffff801`41b59000 luafv (deferred) fffff801`41b60000 fffff801`41b96000 wcifs (deferred) fffff801`44a00000 fffff801`45a46000 nt (pdb symbols) C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\sym\ntkrnlmp.pdb\CA8E2F01B822EDE6357898BFBF8629971\ntkrnlmp.pdb fffff801`46000000 fffff801`46114000 clipsp (deferred) fffff801`46120000 fffff801`46149000 ksecdd (deferred) fffff801`46150000 fffff801`461b3000 msrpc (deferred) fffff801`461c0000 fffff801`461d1000 werkernel (deferred) fffff801`461e0000 fffff801`461ec000 ntosext (deferred) fffff801`461f0000 fffff801`462d4000 CI (deferred) fffff801`462e0000 fffff801`4639b000 cng (deferred) fffff801`463a0000 fffff801`46471000 Wdf01000 (deferred) fffff801`46480000 fffff801`46493000 WDFLDR (deferred) fffff801`464a0000 fffff801`464af000 SleepStudyHelper (deferred) fffff801`464b0000 fffff801`464c1000 WppRecorder (deferred) fffff801`464d0000 fffff801`464f6000 acpiex (deferred) fffff801`46500000 fffff801`4654c000 mssecflt (deferred) fffff801`46550000 fffff801`4656a000 SgrmAgent (deferred) fffff801`46570000 fffff801`4663c000 ACPI (deferred) fffff801`46640000 fffff801`4664c000 WMILIB (deferred) fffff801`46650000 fffff801`46660000 WdBoot (deferred) fffff801`46670000 fffff801`466db000 intelpep (deferred) fffff801`466e0000 fffff801`466f7000 WindowsTrustedRT (deferred) fffff801`46700000 fffff801`4670b000 IntelTA (deferred) fffff801`46710000 fffff801`4671b000 WindowsTrustedRTProxy (deferred) fffff801`46720000 fffff801`46734000 pcw (deferred) fffff801`46740000 fffff801`4674b000 msisadrv (deferred) fffff801`46750000 fffff801`467c7000 pci (deferred) fffff801`467d0000 fffff801`467e5000 vdrvroot (deferred) fffff801`467f0000 fffff801`467fb000 intelide (deferred) fffff801`46800000 fffff801`46844000 ucx01000 (deferred) fffff801`46850000 fffff801`4687f000 pdc (deferred) fffff801`46880000 fffff801`4689a000 CEA (deferred) fffff801`468a0000 fffff801`468d1000 partmgr (deferred) fffff801`468e0000 fffff801`4698a000 spaceport (deferred) fffff801`46990000 fffff801`469a3000 PCIIDEX (deferred) fffff801`469b0000 fffff801`469c9000 volmgr (deferred) fffff801`469d0000 fffff801`46a1f000 sdbus (deferred) fffff801`46a20000 fffff801`46a83000 volmgrx (deferred) fffff801`46a90000 fffff801`46aa8000 vsock (deferred) fffff801`46ab0000 fffff801`46acc000 vmci (deferred) fffff801`46ad0000 fffff801`46ae8000 urscx01000 (deferred) fffff801`46af0000 fffff801`46b0e000 mountmgr (deferred) fffff801`46b10000 fffff801`46b2f000 lsi_sas (deferred) fffff801`46b30000 fffff801`46be3000 storport (deferred) fffff801`46bf0000 fffff801`46bfd000 atapi (deferred) fffff801`46c00000 fffff801`46c3c000 ataport (deferred) fffff801`46c40000 fffff801`46c72000 storahci (deferred) fffff801`46c80000 fffff801`46c9c000 EhStorClass (deferred) fffff801`46ca0000 fffff801`46cba000 fileinfo (deferred) fffff801`46cc0000 fffff801`46d00000 Wof (deferred) fffff801`46d10000 fffff801`46d6a000 WdFilter (deferred) fffff801`46d70000 fffff801`47048000 Ntfs (deferred) fffff801`47050000 fffff801`47083000 usbccgp (deferred) fffff801`47090000 fffff801`4709e000 USBD (deferred) fffff801`470a0000 fffff801`470ad000 urschipidea (deferred) fffff801`470b0000 fffff801`470ca000 usbehci (deferred) fffff801`470d0000 fffff801`47149000 USBPORT (deferred) fffff801`47150000 fffff801`471d5000 usbhub (deferred) fffff801`471e0000 fffff801`47283000 UsbHub3 (deferred) fffff801`47290000 fffff801`4729d000 Fs_Rec (deferred) fffff801`472a0000 fffff801`47410000 ndis (deferred) fffff801`47420000 fffff801`474b8000 NETIO (deferred) fffff801`474c0000 fffff801`474f2000 ksecpkg (deferred) fffff801`47500000 fffff801`477eb000 tcpip (deferred) fffff801`477f0000 fffff801`4786f000 fwpkclnt (deferred) fffff801`47870000 fffff801`478a0000 wfplwfs (deferred) fffff801`478b0000 fffff801`47978000 fvevol (deferred) fffff801`47980000 fffff801`4798b000 volume (deferred) fffff801`47990000 fffff801`479fd000 volsnap (deferred) fffff801`47a00000 fffff801`47aa0000 USBXHCI (deferred) fffff801`47ab0000 fffff801`47ad5000 USBSTOR (deferred) fffff801`47ae0000 fffff801`47af8000 uaspstor (deferred) fffff801`47b00000 fffff801`47b1e000 sdstor (deferred) fffff801`47b20000 fffff801`47b70000 rdyboost (deferred) fffff801`47b80000 fffff801`47ba6000 mup (deferred) fffff801`47bb0000 fffff801`47bc2000 iorate (deferred) fffff801`47bd0000 fffff801`47be0000 hwpolicy (deferred) fffff801`47bf0000 fffff801`47c0c000 disk (deferred) fffff801`47c10000 fffff801`47c7d000 CLASSPNP (deferred) fffff801`48200000 fffff801`48215000 filecrypt (deferred) fffff801`48220000 fffff801`4822e000 tbs (deferred) fffff801`48230000 fffff801`4823a000 Null (deferred) fffff801`48240000 fffff801`4824a000 Beep (deferred) fffff801`48250000 fffff801`48260000 vmrawdsk (deferred) fffff801`48270000 fffff801`482cc000 udfs (deferred) fffff801`48300000 fffff801`4831e000 crashdmp (deferred) fffff801`48320000 fffff801`4833f000 dump_lsi_sas (deferred) fffff801`48360000 fffff801`4837d000 dump_dumpfve (deferred) fffff801`483c0000 fffff801`483f0000 cdrom (deferred) fffff801`48800000 fffff801`48810000 TDI (deferred) fffff801`48820000 fffff801`4882e000 ws2ifsl (deferred) fffff801`48830000 fffff801`4888c000 netbt (deferred) fffff801`48890000 fffff801`488a3000 afunix (deferred) fffff801`488b0000 fffff801`48956000 afd (deferred) fffff801`48960000 fffff801`48973000 npcap (deferred) fffff801`48980000 fffff801`4899a000 vwififlt (deferred) fffff801`489a0000 fffff801`489cb000 pacer (deferred) fffff801`489d0000 fffff801`489e4000 ndiscap (deferred) fffff801`489f0000 fffff801`48a04000 netbios (deferred) fffff801`48a10000 fffff801`48ab1000 Vid (deferred) fffff801`48ac0000 fffff801`48ae1000 winhvr (deferred) fffff801`48af0000 fffff801`48b6b000 rdbss (deferred) fffff801`48b70000 fffff801`48c07000 csc (deferred) fffff801`48c10000 fffff801`48c22000 nsiproxy (deferred) fffff801`48c30000 fffff801`48c3e000 npsvctrig (deferred) fffff801`48c40000 fffff801`48c50000 mssmbios (deferred) fffff801`48c60000 fffff801`48c6a000 gpuenergydrv (deferred) fffff801`48c70000 fffff801`48c9c000 dfsc (deferred) fffff801`48cc0000 fffff801`48d2c000 fastfat (deferred) fffff801`48d30000 fffff801`48d47000 bam (deferred) fffff801`48d50000 fffff801`48d9e000 ahcache (deferred) fffff801`48da0000 fffff801`48db2000 CompositeBus (deferred) fffff801`48dc0000 fffff801`48dcd000 kdnic (deferred) fffff801`48dd0000 fffff801`48de5000 umbus (deferred) fffff801`48df0000 fffff801`48e11000 i8042prt (deferred) fffff801`48e20000 fffff801`48e34000 kbdclass (deferred) fffff801`48e40000 fffff801`48e49000 vmmouse (deferred) fffff801`48e50000 fffff801`48e63000 mouclass (deferred) fffff801`48e70000 fffff801`48e8c000 serial (deferred) fffff801`48e90000 fffff801`48e9f000 serenum (deferred) fffff801`48ea0000 fffff801`48eaa000 vm3dmp_loader (deferred) fffff801`48eb0000 fffff801`48efb000 vm3dmp (deferred) fffff801`48f00000 fffff801`48f10000 usbuhci (deferred) fffff801`48f30000 fffff801`48f59000 HDAudBus (deferred) fffff801`48f60000 fffff801`48fc6000 portcls (deferred) fffff801`48fd0000 fffff801`48ff1000 drmk (deferred) fffff801`49000000 fffff801`49076000 ks (deferred) fffff801`49090000 fffff801`4911e000 e1i65x64 (deferred) fffff801`49130000 fffff801`4913b000 vmgencounter (deferred) fffff801`49140000 fffff801`4914f000 CmBatt (deferred) fffff801`49150000 fffff801`49160000 BATTC (deferred) fffff801`49170000 fffff801`491b0000 intelppm (deferred) fffff801`491c0000 fffff801`491cd000 NdisVirtualBus (deferred) fffff801`491d0000 fffff801`491dc000 swenum (deferred) fffff801`491e0000 fffff801`491ee000 rdpbus (deferred) fffff801`491f0000 fffff801`491fe000 USBPcap (deferred) fffff801`49200000 fffff801`4926f000 HdAudio (deferred) fffff801`49270000 fffff801`4927f000 ksthunk (deferred) fffff801`49280000 fffff801`49292000 hidusb (deferred) fffff801`492a0000 fffff801`492df000 HIDCLASS (deferred) fffff801`492e0000 fffff801`492f3000 HIDPARSE (deferred) fffff801`49300000 fffff801`49310000 mouhid (deferred) fffff801`49320000 fffff801`49329000 vmusbmouse (deferred) fffff801`49340000 fffff801`4934e000 dump_diskdump (deferred) fffff801`49350000 fffff801`496fa000 dxgkrnl (deferred) fffff801`49700000 fffff801`49718000 watchdog (deferred) fffff801`49720000 fffff801`49736000 BasicDisplay (deferred) fffff801`49740000 fffff801`49751000 BasicRender (deferred) fffff801`49760000 fffff801`4977c000 Npfs (deferred) fffff801`49780000 fffff801`49791000 Msfs (deferred) fffff801`497a0000 fffff801`497be000 CimFS (deferred) fffff801`497c0000 fffff801`497e2000 tdx (deferred) </code></pre> <p>I then change the context to the process with <code>.process /i ffffd88c774b70c0</code> and set a breakpoint on ntdll!ntcreatefile</p> <p>Problem is, I wanted to step INTO syscall but upon pressing p windbg executes it without stepping into it, what gives? I'm running running a kernel debugger and debugging a VM, so I should be able to do this, what's the problem here?</p>
Why windbg skips syscall on kernel mode?
|windows|debugging|x86|windbg|kernel-mode|
<p>If you want to save the image of the graph as it is displayed in IDA, you can use <a href="https://github.com/tmr232/GraphGrabber" rel="nofollow noreferrer">https://github.com/tmr232/GraphGrabber</a></p> <p>For viewing and printing GDL graphs, you can use <code>qwingraph</code> program shipped with IDA.</p> <p>There is also a “print graph” button on IDA’s graph toolbar but it’s not shown by default.</p> <p>You can also generate graphs in a more common DOT format, see <code>ida.cfg</code> for the settings.</p>
29586
2021-11-21T01:07:58.880
<p>Trying to save a big graph(the default graph view of assembly instructions in IDA after you press space in text view while viewing instructions of a function) as an image.</p> <p>Googled this article: <a href="http://pank4j.github.io/posts/converting-ida-pro-graphs-to-images.html" rel="nofollow noreferrer">Converting IDA Pro graphs to images</a>, it tells to use graph-easy for Linux, and saw this question: <a href="https://reverseengineering.stackexchange.com/questions/3322/saving-ida-graphs-as-image">Saving IDA graphs as image</a>. The only answer suggests to use graph-easy for Linux. I'm on Windows. How to convert the graph to an image on Windows 10?</p> <p>I googled how to convert gdl to image, too, and there's some ArchiCAD software for $3000 or something, and it looks like it's some big program for modeling or whatever. Then there's this online tool which doesn't work: <a href="https://fileproinfo.com/tools/viewer/gdl" rel="nofollow noreferrer">https://fileproinfo.com/tools/viewer/gdl</a> . Says the preview doesn't work. There's also: Stanford Microarray Database GDL Data . Their site is dead.</p> <p>Please help.</p>
How to make a screenshot of a graph view in IDA on Windows?
|ida|
<p>So, it turns out that if you're testing an IAT hook on a driver, the driver must be compiled in the release mode rather than in the debug one.</p> <p>If the driver is compiled in the debug mode, the RVA for the <code>Import Descriptor</code> seems to be wrong. But the issue is resolved with compiling in the release rather than in the debug mode.</p> <p>Thanks to all for the help.</p>
29602
2021-11-23T22:09:29.990
<p>I've wrote a kernel driver recently and it does multiple things, but I wanted to add a IAT hook for a certain driver.</p> <p>I want to hook the IAT of another driver from my driver if that makes sense.</p> <p>So I understand your typical IAT hook is done via DLL injection so you're within the same address space as said module.</p> <p><strong>The main question I'm having is can someone give an example of IAT hooking a kernel driver via a kernel driver?</strong> I can't figure it out.</p> <p>I've been using multiple examples of regular IAT hooking via dll injection but applying it to the Kernel driver instead.</p> <p><strong>Expected outcome:</strong> Driver1.sys (does the IAT hook) parses the import table of Driver2.sys and replaces the function &quot;DbgPrintEx&quot; import with a function located in Driver1.sys aka accomplishing an IAT hook.</p> <p><strong>Here is what I wrote / referenced:</strong></p> <pre><code>NTSTATUS _HOOKS_::HookFn(PVOID ModuleBase, const char* FunctionName, uintptr_t HookFunc, uintptr_t* OrigFunc) { IMAGE_DOS_HEADER DosHeader{ 0 }; memcpy(&amp;DosHeader, ModuleBase, sizeof(IMAGE_DOS_HEADER)); IMAGE_NT_HEADERS NtHeaders{ 0 }; memcpy(&amp;NtHeaders, (PVOID)((uintptr_t)ModuleBase + DosHeader.e_lfanew), sizeof(IMAGE_NT_HEADERS)); IMAGE_IMPORT_DESCRIPTOR ImportDescriptor{ 0 }; IMAGE_DATA_DIRECTORY ImportsDirectory = NtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]; memcpy(&amp;ImportDescriptor, (PVOID)((uintptr_t)ModuleBase + ImportsDirectory.VirtualAddress), sizeof(ImportDescriptor)); LPCSTR LibraryName = NULL; PVOID Library = NULL; IMAGE_IMPORT_BY_NAME FunctionNamee{ 0 }; while (ImportDescriptor.Name != NULL) { memcpy(&amp;LibraryName, &amp;ImportDescriptor.Name + (uintptr_t)ModuleBase, sizeof(LibraryName)); IMAGE_THUNK_DATA OriginalFirstThunk{ 0 }, firstThunk{ 0 }; memcpy(&amp;OriginalFirstThunk, (PVOID)(ImportDescriptor.OriginalFirstThunk + (uintptr_t)ModuleBase), sizeof(IMAGE_THUNK_DATA)); memcpy(&amp;firstThunk, (PVOID)(ImportDescriptor.FirstThunk + (uintptr_t)ModuleBase), sizeof(IMAGE_THUNK_DATA)); while (OriginalFirstThunk.u1.AddressOfData != NULL) { memcpy(&amp;FunctionNamee, (PVOID)(OriginalFirstThunk.u1.AddressOfData + (uintptr_t)ModuleBase), sizeof(IMAGE_IMPORT_BY_NAME)); Log::Debug(&quot;First function name -&gt; %s\n&quot;, FunctionNamee); if (!strcmp(FunctionNamee.Name, FunctionName)) { Log::Debug(&quot;FOUND FUNCTION!!! Address -&gt; %p\n&quot;, firstThunk.u1.Function); } } } return STATUS_SUCCESS; </code></pre> <p>This code BSOD's on: <code>memcpy(&amp;ImportDescriptor, (PVOID)((uintptr_t)ModuleBase + ImportsDirectory.VirtualAddress), sizeof(ImportDescriptor));</code></p> <p>Correct me if I'm wrong but since kernel drivers share the same address space I can just simply use memcpy or RtlCopyMemory to obtain the structs needed for this hook, does anyone have any references or some sort of documentation I can read?</p> <p>Thanks to all in advance!</p> <p>extra info:</p> <ul> <li>Windows 10</li> <li>Using VMWare for testing</li> <li>I'm testing the hook on my own driver</li> </ul> <p>EDIT: Posted the faulting source line that causes BSOD.</p> <p>Upon debugging via WinDbg(x64), the driver obtains all the addresses correctly comparing them to memory view. Except <code>ImportDescriptor</code> gets an RVA of 0x6000, when inspecting <code>ModuleBase + 0x6000</code> for the RVA it shows that this memory region is invalid, so I believe that the 0x6000 RVA is incorrect and I'm not sure why</p> <p><strong>BUG CHECK CODES:</strong></p> <ul> <li>BSOD Error Code: PAGE_FAULT_IN_NONPAGED_AREA</li> <li>BUG Check Code: 50</li> </ul>
IAT Hook via Kernel Driver
|c++|function-hooking|kernel-mode|driver|iat|
<p>Patching in IDA is pretty simple and well documented <a href="https://hex-rays.com/products/ida/support/idadoc/526.shtml" rel="nofollow noreferrer">here</a> and <a href="https://hex-rays.com/blog/igors-tip-of-the-week-37-patching/" rel="nofollow noreferrer">here</a>.</p> <p>First, you need to make the change by selecting a portion of data in the main view and then use the <code>Edit -&gt; Patch program -&gt; Change word</code> submenu item. Note that at that point the change was only made to the IDB you're working on and not to the actual binary you loaded.</p> <p>Before applying the patches made to the original binary, I recommend you review them using the <code>Edit -&gt; Patch program -&gt; Patched bytes</code> option. To apply the changes, you need to use the <code>Edit -&gt; Patch program -&gt; Apply patches to input file...</code>. You should probably create a backup (the option's available in the dialog).</p> <p>Note that this is only possible if the segment you're trying to edit is not a <code>BSS</code> segment. Executables don't <em>contain data</em> for <code>BSS</code> segments because <code>BSS</code> segments are completely initialized to all zeroes by the executable loader.</p> <p>Note that in earlier versions of IDA the <code>Patch program</code> submenu was hidden by default and you had to set the <code>DISPLAY_PATCH_SUBMENU</code> configuration in <code>idagui.cfg</code> to <code>YES</code>.</p>
29603
2021-11-24T05:33:58.370
<p>I have a global variable stored in the data section:</p> <pre><code>data:00007FF7DDBF78E4 00 00 00 00 dword_7FF7DDBF78E4 dd 0 </code></pre> <p>Is there a way to change its value?</p>
Change global variable value in IDA
|ida|patching|
<p>Turned out the executable is a <a href="https://docs.microsoft.com/en-us/dotnet/core/deploying/ready-to-run" rel="nofollow noreferrer">ReadyToRun</a> executable, so it contains both IL and prebuilt x86-64 image. Modifying IL wasn't working because only x86 image was used at runtime. Modifying x86 image worked for me. ILSpy is capable of showing ReadyToRun image alongside C# and IL.</p>
29605
2021-11-24T11:40:54.257
<p><strong>What I am trying to do:</strong></p> <p>I have an .exe written in C#. Ilspy shows the code. Inside it has a class <code>DoWork</code> with static field <code>SomeValue</code>:</p> <pre><code>// Program.DoWork public static int SomeValue =&gt; 15; </code></pre> <p>In code, however, it's not a field but a getter function:</p> <pre><code>// return 15; IL_0000: ldc.i4.s 15 IL_0002: ret </code></pre> <p>and I want to modify this function to return 127 instead. I've found the location of the function inside .exe binary dump:</p> <pre><code>0x123456 1f 0f 2a </code></pre> <p>I've modified .exe in HxD editor so new binary dump has this:</p> <pre><code>0x123456 1f 7f 2a </code></pre> <p>When I open modified .exe with Ilspy it shows:</p> <pre><code>// Program.DoWork public static int SomeValue =&gt; 127; </code></pre> <p>So all seems well, but it doesn't work. The modified .exe still runs as if <code>SomeValue</code> is <code>15</code>.</p> <p><strong>Questions:</strong></p> <ol> <li>Is this a valid approach to modifying .net assembly?</li> <li>If yes, what am I missing?</li> </ol>
Patch .net executable via hex editor
|.net|decompiler|
<p>What you see is possible if the APK files uses the mode <code>extractNativeLibs=&quot;false&quot;</code>. If that attribute is set in the <code>&lt;application</code> tag in <code>AndroidManifest.xml</code> then Android loads the .so files directly from within the APK file without extracting them first.</p> <p>This works because the .so files are stored without compression and aligned to 4KiB page boundary so that they can be directly mapped into memory via mmap (see also zipalign comments on that topic <a href="https://developer.android.com/studio/command-line/zipalign" rel="nofollow noreferrer">https://developer.android.com/studio/command-line/zipalign</a>).</p>
29606
2021-11-24T14:27:22.720
<p>There is an Android application that has a shared library (.so) file in <code>split_config.arm64_v8a.apk</code> that I want to debug .</p> <p>When I look at <code>/proc/PID/maps</code> I don't see that library (I do see the <code>split_config.arm64_v8a.apk</code> file), but I'm sure the library is loaded because I see logs that only that library prints. Additionally, the application calls <code>System.loadLibrary(&quot;libMyLib.so&quot;);</code> to load that library.</p> <p>How can I debug this shared library?</p>
Debug shared library in Android application
|debugging|android|gdb|frida|
<p>IDA’s debugger switches to disassembly when it can’t find a location in the pseudocode which matches the current instruction pointer (IP) value.</p> <p>Due to the way compilers optimize code, a single source code line can be spread over several assembly instructions, in some cases non-contiguous. You may even have instructions belonging to different lines intermixed in different order. All this complicates the task of mapping IP values to source or pseudo code lines. This may cause the behavior you are seeing.</p>
29614
2021-11-25T03:21:48.673
<p>I've noticed that whenever I'm single stepping for loops inside IDA hexrays decompiler it'll jump to the disassenbly view, doesn't matter if I step through with F8 ou F7, what gives and can I prevent it?</p>
Prevent IDA from jumping to disassembly when debugging with decompiler
|ida|
<pre><code>python3 -c &quot;print (56 * 'A' + '\x53\x11\x40\x00\x00\x00\x00\x00')&quot; | ./santa </code></pre>
29620
2021-11-26T19:13:28.177
<p>I'm an absolute newbie when it comes to all this side of reverse engineering. Each time I try and understand it, I get lost almost immediately.</p> <p>I am trying a lab. I open it up in Binary Ninja. I get the following</p> <p><a href="https://i.stack.imgur.com/SkqAf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SkqAf.png" alt="enter image description here" /></a></p> <p>When I open main I get the following</p> <p><a href="https://i.stack.imgur.com/kW4qJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kW4qJ.png" alt="enter image description here" /></a></p> <p>Nothing much seems to happen but there is a function(?) called flag that looks like what I need</p> <p><a href="https://i.stack.imgur.com/maQqE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/maQqE.png" alt="enter image description here" /></a></p> <p>When I copy the address, it comes out as:</p> <pre><code>0x401152 </code></pre> <p>I'm trying to do stuff like this on the command line but getting nowhere fast</p> <pre><code>python3 -c &quot;print (28 * 'A' + '\x52\x11\x40')&quot; | ./santa; </code></pre> <p>I then try to iterate through and no luck although I do get a segmentation fault on the 53rd iteration</p> <pre><code>for i in {0..60}; do python3 -c &quot;print ($i * 'A' + '\x52\x11\x40')&quot; | ./santa; done </code></pre> <p>Any pointers? I'm absolutely lost</p>
How to exploit __isoc99_scanf with a segmentation fault
|binary-analysis|binary|buffer-overflow|
<p>In the <code>.data</code> segment are generally — as it name suggest — simply <em>data</em>.</p> <p>Data are <em>not only ASCII strings</em>, but other data, too. For example, integers and floating-point numbers. They are encoded as sequences of bits, and are preferably displayed — as in your question — in the form of hexadecimal symbols.</p> <p>Knowing nothing about their meaning, we may conclude nothing about values which they represent. Even nothing about the start and end position of individual piece of data.</p> <p>For example, let's take the left half of your 3<sup>rd</sup> row: <code>0A 35 60 BD F1 C9 D6 5D</code>. What is its meaning:</p> <ul> <li>8 bytes?</li> <li>4 words?</li> <li>2 double-words?</li> <li>4 bytes and 1 double-word?</li> <li>etc., etc., ...</li> </ul> <p>Even if we know that they are 2 double-words, what they represent? Integers or floating-point numbers? If integers, signed or unsigned ones? And so on.</p> <p>It means that in the <code>.data</code> segment may be <em>everything</em>. <strong>Nothing is suspicious,</strong> if you have no other information.</p>
29626
2021-11-27T06:50:31.373
<p>I have recently been trying to improve my skills on reverse engineering. So, I opened <code>C:/Windows/System32/DriverStore/FileRepository/xboxgip.inf_amd64_90ed6b3fdc759a5b/devauthe.sys</code> in IDA. While playing around the file, I came across the following bytes under <code>.data</code> segment:</p> <pre><code>00 00 00 00 00 00 00 00 00 00 00 00 32 A2 DF 2D 99 2B 00 00 CD 5D 20 D2 66 D4 FF FF 01 00 D2 8B 0A 35 60 BD F1 C9 D6 5D 6C 59 51 D5 24 FD 02 F5 43 26 29 79 53 3E B0 FB 2B 97 BF 5E FC 20 02 00 54 B4 F2 54 77 D2 99 71 BD 9C 0B 85 C9 D0 29 BE 85 AD 6B CB D7 CA 71 D4 AB 28 DB FA 1A 0E E0 9F 03 00 B0 EB 26 B7 F4 68 74 C7 34 F0 18 10 26 20 01 BB 63 6E F6 20 E2 3B D7 7B D1 1A B4 6D 33 BA 6B 4B 5C D0 0D 95 6B 2F CF 0D 53 C5 AE AC 03 87 23 9B A4 BE 5D 70 E1 26 19 06 56 49 79 E6 7C 1A 71 20 D0 11 C1 D8 7C 61 44 3A 47 B2 9E 8E 44 AB 2E 42 EB 59 B0 3B F1 9C B1 66 4F A3 DA 37 1F 30 5B 7E FF E5 FC 87 00 00 00 00 00 00 C9 57 84 41 69 9B 06 7E C1 14 C5 CA C1 56 B7 8F 71 48 4A FC 08 1D A5 E6 C9 DB F6 53 A6 15 78 5F F4 46 C1 48 76 3B DF 9B 84 5B A3 49 5C 46 B5 D1 66 81 8A 53 E5 EC 02 85 02 2C 4B 24 61 9E 3C 2A A5 28 4D 85 F7 A6 25 45 B4 4D EC FD A0 CD AB 01 8D B3 71 07 DA 93 06 6E D6 37 A1 16 EF 74 E1 A6 BC E0 CE E7 D4 02 C9 C1 40 5B CD 3B 9A 62 84 39 E8 40 3D 13 20 E2 1A B6 3C D3 E6 7A C6 F3 27 B4 6D 66 5B 8D 52 81 06 0F 3C BC F3 1C 05 90 77 67 8B 99 FD 00 04 AD 27 E9 1D B5 68 B2 21 A6 0D A5 81 C0 53 C9 99 B4 ED F1 11 D0 01 91 59 A8 ED 80 BA 82 86 62 CF 3D 94 70 C3 1C 50 9E C6 95 6D 57 17 0F 95 DA 14 38 76 38 09 E7 D5 0C 3E 89 2F 5D DF F4 D6 31 C1 26 02 9C 30 0B EE 28 A7 86 74 A3 46 8F B7 85 FA 8C 0F BB 79 65 A5 AD C9 12 BA CF 43 64 CC 62 A0 30 3F AE 88 06 40 86 EF 27 CA 93 52 53 41 32 </code></pre> <p>Looking at the bytes, it doesn't seem to be ASCII strings, neither does it look to be code, since disassemblers fails on certain bytes. I understand my question might be a bit vague, but can anyone tell me what this is?</p>
.data segment seems to contain code?
|disassembly|assembly|
<p>In the absence of an explicit <code>__spoils</code> declaration on the called function's prototype, Hex-Rays makes decisions about which registers should be spoiled at a call site based on the compiler that has been chosen for the binary, which can be viewed and modified under <code>Options-&gt;Compiler</code>. Your first step should be to ensure that the <code>Compiler</code> dropdown box says &quot;Watcom C++&quot;.</p> <p>The authors of Hex-Rays need to implement support for each compiler's ABI separately. That is to say, if you were to reverse engineer the part of Hex-Rays that chose the standard clobber set to be used throughout call analysis, you'd find that the logic made use of <code>if</code>-statements that were checking the database's compiler settings (as described in the previous paragraph).</p> <p>Unfortunately, as of the last time I reverse engineered that part of Hex-Rays, they had not yet implemented support for Watcom's ABI. It's possible this has changed in the meantime -- again, your first step should be to set the compiler to Watcom and see what happens. I get the impression they <a href="https://hex-rays.com/products/ida/news/7_3/" rel="nofollow noreferrer">might have added it in 7.3, based on the following changelog</a>:</p> <blockquote> <p>BUGFIX: TYPES: corrected the list of spoiled registers for watcom files</p> </blockquote> <p>However, if setting the compiler doesn't work, then there's nothing you can do as a user to fix this without manually annotating each function's <code>__spoils</code> set. If so, this would be a great time to contact Hex-Rays support with your license key, and a copy of the binary if possible, and ask them if they can implement ABI support for Watcom in the decompiler. It may not happen in the next release, but if enough customers have enough requests involving Watcom binaries, it'll happen. After all, it's probably not that much work on their end to implement it, and it's a nice feature to have out-of-the-box.</p>
29628
2021-11-27T17:29:35.630
<p>TL;DR:</p> <p>The __fastcall convention in IDA Pro assumes that all the registers which could be used for transferring parameters are clobbered after a call (tested on x86, clobbered regs are <code>eax</code>, <code>edx</code>, <code>ebx</code>, <code>ecx</code>). I'm wondering how can I change that.</p> <p>Full explanation:</p> <p>I have a chunk of code (used Watcom <a href="https://en.wikipedia.org/wiki/Name_mangling" rel="nofollow noreferrer">name mangling</a>):</p> <pre><code>cseg01:00062A6B mov edx, [ebp+tng1] cseg01:00062A6E mov eax, [ebp+this1] cseg01:00062A71 call W?MyMethod$_Whatever$n_x__pn$SubObject$$ cseg01:00062A76 call W?MySubMethod$_SubObject$n_pn$Thing$$_l cseg01:00062A7B cmp eax, 0Ah </code></pre> <p>The functions are:</p> <pre><code>SubObject *__fastcall Whatever::MyMethod(Whatever *__hidden this); int __fastcall SubObject::MySubMethod(SubObject *__hidden this, Thing *tng); </code></pre> <p>IDA Pro produces:</p> <pre><code>(v3 = Whatever::MyMethod(this1), SubObject::MySubMethod(v3, v4) &lt; 10) </code></pre> <p>So the proper code clearly is:</p> <pre><code>(this1-&gt;MyMethod()-&gt;MySubMethod(tng1) &lt; 10) </code></pre> <p>The problem is — IDA did not use <code>tng1</code> as the 2nd argument of <code>MySubMethod()</code> — instead, it defined a separate variable <code>v4</code> with an unset value.</p> <p>Because we use <code>__fastcall</code> for both functions, first arg is passed through <code>eax</code>, second by <code>edx</code>. The code so happens to set the value of <code>edx</code> before the first call, even though it's really an argument for the second call. IDA seem to assume that <code>MyMethod()</code> overwrote (or with proper nomenclature, <a href="https://en.wikipedia.org/wiki/Clobbering" rel="nofollow noreferrer">clobbered</a>) the value of <code>EDX</code>).</p> <p>I tried __usercall and __userpurge, and it had no impact on the code — IDA still assumes <code>EDX</code> was clobbered by the first call.</p> <p>Is there a way to configure/change that behavior, making IDA know that function calls does not clobber registers?</p> <p>I remember fixing it in the past, so there is a way, just can't remember what it was exactly...</p> <p>Also, it would be nice to configure that on a project level instead of defining a custom calling convention for every function.</p>
IDA Pro - configure register clobbering
|ida|x86|register|calling-conventions|
<p>It's a compiler optimization used to implement <code>switch</code> statements that have many cases leading to one location. Note that the weird output is not Hex-Rays' doing, but rather, a more-or-less direct translation of what's in the assembly language. You didn't show the assembly for your snippet, but here's similar disassembly from a database I have open:</p> <pre><code>.text:0000000061FEA1C8 lea eax, [rdi-33h] .text:0000000061FEA1CB cmp eax, 0Eh .text:0000000061FEA1CE ja short loc_61FEA1F8 .text:0000000061FEA1CE .text:0000000061FEA1D0 mov edx, 6381h .text:0000000061FEA1D5 bt edx, eax ; &lt;- this becomes _bittest .text:0000000061FEA1D8 jnb short loc_61FEA1F8 </code></pre> <p>And here's its Hex-Rays decompilation:</p> <pre><code> if ( (vChildOp - 51) &gt; 0xE ) return /* ... */; v6 = 25473; if ( !_bittest(&amp;v6, vChildOp - 51) ) return /* ... */; </code></pre> <p>Let's take a closer look at your snippet. You said that <code>kBluetoothIntelHardwareVariantJfP = 0x11</code> and <code>kBluetoothIntelHardwareVariantSlrF = 0x19</code>. Now look at the constant, <code>0x39E0000LL</code>. This is <code>11100111100000000000000000b</code> in binary:</p> <pre><code>11 1001 1110 0000 0000 0000 0000 || | | |||- bits 0-16 clear || | | ||-- bit 17 (i.e., 0x11): first bit set || | | |--- bit 0x12 set || | | ---- bit 0x13 set || | ------ bit 0x14 set || --------- bit 0x17 set |----------- bit 0x18 set ------------ bit 0x19: last bit set </code></pre> <p>Notice that the <code>switch</code> statement in your example has 7 cases leading to the same label, and that two of the cases correspond to bits <code>0x19</code> and <code>0x11</code>? It is not a coincidence that the constant in the snippet has 7 bits set, including bits <code>0x11</code> and <code>0x19</code>! The <code>bt</code> instruction, translated as the <code>_bittest</code> intrinsic, is just checking to see whether <code>hardwareVariant</code>, or <code>a2</code> in the decompilation, is one of the values <code>0x11</code>-<code>0x14</code> or <code>0x17-0x19</code>. It performs all 7 comparisons at the same time.</p> <p>The <code>if</code>-statement on the outside is the <code>default</code> check: it ensures that the value of <code>a2</code> is at most <code>0x19</code> -- if it's not, it jumps to the <code>default</code> location, i.e., does nothing.</p>
29629
2021-11-27T17:50:00.250
<p>This is my first question on this forum, so I hope that it would not be offensive or redundant.</p> <p>So recently I am attempting to developing some kernel extensions for Apple's macOS using the IOKit framework. However, in the debugging process, I encountered some confusions while looking at the assembly and pseudocode of my binaries generated by IDA.</p> <p>Currently, the greatest issue is how the normal switch case statement is interrupted by the decompiler — <code>_bittest64</code> commands would be yielded with huge numbers as arguments. I am somewhat sure that it has to do with the “lower-bound” of the cases, but I don't know how exactly should I comprehend it. Here is an example:</p> <p><img src="https://i.stack.imgur.com/LOxqp.png" alt="Actual code" /> <img src="https://i.stack.imgur.com/Qf0zs.png" alt="Hex-Rays decompiler pseudocde" /></p> <p>I can't really see how they relate, particularly the <code>_bittest64</code> part. Just by the way, the enum <code>kBluetoothIntelHardwareVariantJfP = 0x11</code> and <code>kBluetoothIntelHardwareVariantSlrF = 0x19</code>.</p> <p>Happy thanksgiving!</p>
IDA interpretation of switch-case statement
|ida|c++|
<p>The return type is available in the <code>rettype</code> field of the <a href="https://hex-rays.com/products/ida/support/sdkdoc/structfunc__type__data__t.html" rel="nofollow noreferrer"><code>func_type_data_t</code> structure</a>.</p>
29638
2021-11-29T17:30:04.097
<p>I want to get a function's signature information: return type and parameters from x64 binaries. I am able to achieve so, using</p> <pre><code>tif = idaapi.tinfo_t() ida_nalt.get_tinfo(tif, ea) function_type = tif.get_rettype() metadata[function][&quot;ret_type&quot;] = function_type funcdata = ida_typeinf.func_type_data_t() for i,v in enumerate(funcdata): itype = ida_typeinf.print_tinfo('', 0, 0, idc.PRTYPE_1LINE, v.type, '', '') metadata[function][&quot;parameter_list&quot;].append(tuple([i, v.name,itype])) </code></pre> <p>This script works in a lot of cases, but fails in some simple cases, like for example</p> <pre><code>double retDouble() { return 2.4; } </code></pre> <p>In such case, I get an empty <code>tif</code> object, and thus I can't recover the return type — which is double in this case. I believe this happens in cases where there are no function parameters present (like in above case). In such case, How can I recover the return type (or at least recover the type, or is it not possible at all)? I want the type object and not the type as a string, the later can be achievable by parsing IDA disassembly and retrieving function signature by something like regex.</p>
IDAPython: function parameters and return value
|ida|idapython|
<p>Hex-Rays’ version of AST is called “ctree”, so you can search for the term in <code>hexrays.hpp</code> to see what methods are available, as well as in the sample plugins and scripts.</p>
29642
2021-11-30T09:07:32.487
<p>I am implementing deep search with Python Hex Ray API. Can someone say classes and methods for implementing this feature with the IDA Python API?</p>
Functions and methods for working with AST tree
|idapython|hexrays|
<p>I assume that you want to get the PCode of an entire function at once and purely via a script. Getting the PCode for a specific line in the decompiler selected via the GUI is explained in my answer to the question you linked.</p> <p>The easiest way to just dump the entire (decompiled) PCode of a function for human inspection is the <code>Graph AST Control Flow</code> Action hidden in the little menu at the top right of the decompiler window</p> <p><a href="https://i.stack.imgur.com/De1TS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/De1TS.png" alt="enter image description here" /></a></p> <p>This renders a CFG where the basic blocks consist of PCode. It nicely syncs with the GUI, i.e. clicking a node will select the corresponding lines in the decompiler and the listing, and vice versa. This will probably be extremely useful for debugging. If you click any token in the decompiler window you can also easily grab the actual corresponding <code>PCodeAST</code> object with <code>currentLocation.token.pcodeOp</code></p> <p>For getting the actual PCode objects from a plugin/script: The basic idea is that you need the <code>HighFunction</code> object of a function, which has the method <code>HighFunction.getPcodeOps()</code> that returns an iterator over the <code>PcodeOpAST</code> objects. The annoying part is getting the <code>HighFunction</code>. The following code is from the <code>GraphAST.java</code> GhidraScript file:</p> <pre><code>DecompileOptions options = new DecompileOptions(); DecompInterface ifc = new DecompInterface(); ifc.setOptions(options); if (!ifc.openProgram(this.currentProgram)) { throw new DecompileException(&quot;Decompiler&quot;, &quot;Unable to initialize: &quot; + ifc.getLastMessage()); } ifc.setSimplificationStyle(&quot;normalize&quot;); DecompileResults res = ifc.decompileFunction(func, 30, null); high = res.getHighFunction(); </code></pre>
29646
2021-12-01T15:13:03.600
<p>I'm working on an automatic exploit-generation system for low level code, and I want to try it out on real world code.</p> <p>I thought PCode might be a nice place to start, since it abstracts away over many of the details that for example x86 deals with.</p> <p>I've installed Ghidra, and I am able to decompile binaries to C, but I am looking to get the PCode for a specific decompiled function from the binary.</p> <p>There is a <a href="https://reverseengineering.stackexchange.com/questions/21297/can-ghidra-show-me-the-p-code-generated-for-an-instruction/21299">previous question on here</a> that is related to this elsewhere, but the scripts that are linked no longer work with the latest version of Ghidra.</p> <p>Could anyone provide some advice on how to get Ghidra to produce PCode after decompilation?</p> <p>EDIT: For those interested, I've completed a script that dumps every decompiled function: <a href="https://github.com/niconaus/PCode-Dump/blob/main/PCodeDump.java" rel="nofollow noreferrer">https://github.com/niconaus/PCode-Dump/blob/main/PCodeDump.java</a></p>
Dump PCode in Ghidra for a specific decompiled function
|disassembly|ghidra|
<p>basic construct in c,.... languages</p> <pre><code>for (index =start_value; index&lt; end_value; (pre/post) inc/dec(index)) like for (i = 0; i&lt; 10; i++) , ( i=10,i&gt;0;i--) , (i=35; i&gt; 25; --i) ,(i=35; i&lt; 25; ++i) </code></pre> <p>the compiler takes this human readable code and converts it into assembly for the specific platform</p> <p>for x86 this could look like</p> <pre><code>mov end_value to another register like mov edx,10 mov index to a register like mov,ecx,0 body { do anything but preserve ecx,edx } inc/dec regsiter ecx compare ecx with edx, do an if &lt; or &gt; decision and either go back to doing the body or exit </code></pre> <p>a real world example</p> <pre><code>int main (void) { register int a =4; for (register int i =3; i&lt;10; i++){ a = a + i*2; } return a; } </code></pre> <p>compiled and disassembled using vs and windbg</p> <pre><code>:\&gt;ls loopy.cpp :\&gt;cl /Zi /W4 /analyze:autolog- /Od /EHsc /nologo -GS loopy.cpp /link /release /subsystem:windows /entry:main /fixed loopy.cpp :\&gt;ls loopy.cpp loopy.exe loopy.obj loopy.pdb vc140.pdb </code></pre> <p>disassembly of compiled code</p> <pre><code>:\&gt;cdb -c &quot;uf loopy!main;q&quot; loopy.exe | awk &quot;/Reading/,/quit/&quot; 0:000&gt; cdb: Reading initial command 'uf loopy!main;q' loopy!main: 00000000`00401000 55 push rbp 00000000`00401001 8bec mov ebp,esp 00000000`00401003 83ec08 sub esp,8 ===================== memory location instead of register used 00000000`00401006 c745f804000000 mov dword ptr [rbp-8],4 00000000`0040100d c745fc03000000 mov dword ptr [rbp-4],3 ===================== 00000000`00401014 eb09 jmp loopy!main+0x1f (00000000`0040101f) loopy!main+0x16: 00000000`00401016 8b45fc mov eax,dword ptr [rbp-4] increment ================== 00000000`00401019 83c001 add eax,1 00000000`0040101c 8945fc mov dword ptr [rbp-4],eax loopy!main+0x1f: ============ comparison and decision 00000000`0040101f 837dfc0a cmp dword ptr [rbp-4],0Ah 00000000`00401023 7d0e jge loopy!main+0x33 (00000000`00401033) ============== body loopy!main+0x25: 00000000`00401025 8b4dfc mov ecx,dword ptr [rbp-4] 00000000`00401028 8b55f8 mov edx,dword ptr [rbp-8] 00000000`0040102b 8d044a lea eax,[rdx+rcx*2] 00000000`0040102e 8945f8 mov dword ptr [rbp-8],eax 00000000`00401031 ebe3 jmp loopy!main+0x16 (00000000`00401016) =========== body end goes back to re doing again ================ exit loopy!main+0x33: 00000000`00401033 8b45f8 mov eax,dword ptr [rbp-8] 00000000`00401036 8be5 mov esp,ebp 00000000`00401038 5d pop rbp 00000000`00401039 c3 ret quit: </code></pre> <p>in laymans terms this assembly is now further converted to binary (base 2 ,or 0,1) and fed into a network of logic gates which use and , or , not , nand ,xor, xnor circuitry to do the actual work so simply a not gate might return false or true based on the input of index 0b101 versus 0b1000</p> <p>if you need the basic electronics and logic gate circuitry you should look for electronics stack exchange</p> <p><a href="https://circuitverse.org/simulator" rel="nofollow noreferrer">you can also check online logic simulators like this</a></p> <p><a href="https://i.stack.imgur.com/pjUqJ.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pjUqJ.gif" alt="enter image description here" /></a></p>
29653
2021-12-02T10:49:41.797
<h2>Background</h2> <p>Hello! New user. I am working on a personal computer science project that involves research on loop statements such as the <code>for</code> and <code>while</code> loops in <strong>C</strong> - these loops can apply to other programming and scripting languages but, to keep things simple I want to focus primarily on <strong>C</strong>.</p> <hr /> <h2>Issue</h2> <p>I would like to know how developers of programming and scripting languages are able to create <code>for</code> and <code>while</code> loops for those same languages. How can I achieve this for experimentation purposes? Do I have to learn assembly? If so, can anyone provide me with guidance?</p> <p>Apologies if my original question was too vague.</p> <p>Cheers!</p>
Understanding Loop Statements: For & While
|c|
<p>As I Commented if you are adding 0x5c to 0x0F58F478 and getting 0xf58f4d4<br /> it is not what the memory sharp or cheat engine does</p> <p>0x0xf58f4d4 is a pointer an address in the memory space<br /> they dereference the pointer and add 0x5c to the result</p> <p>your other query why adding 0 also falls under the same category adding 0 or 10 or 5c or 100 or 987 and dereferencing them will always provide the underlying value</p> <p>also keep an eye on the square brackets [] means dereference<br /> without square brackets means direct addition<br /> as the first entry in your screen shot shows</p> <pre><code>&amp;a = 0x0F58F478 &amp;a = __addressof(a); *a = 0x3454e04 *a = value of a a + 0x5c = 0xf58f4d4 direct addition [a] + 0x5c = 0x3454e04+0x5c == 0x3454e60 dereferenced addition [a+ 0x5c] = [f58f4d4] = *f58f4d4 = some other value that is got by first adding and then dereferencing </code></pre> <p>since this appears to be c# you should try reading about unsafe / boxing / unboxing etc as it appears you are not aware of pointers,memory ,dereferencing etc</p> <p>here is a boxing example in powershell</p> <pre><code>PS C:\&gt; $a = 123 PS C:\&gt; $b = $a b contains what was in $a viz 123 PS C:\&gt; $a = 456 a gets a new value and a new address PS C:\&gt; $a,$b 456 123 PS C:\&gt; </code></pre> <p>or in c# unsafe construct</p> <pre><code>:\&gt;dir /b unsafe.cs :\&gt;type unsafe.cs using System; class Program { static unsafe void Main() { int var = 32; int* p = &amp;var; Console.WriteLine(&quot;value is 0x{0:x}&quot; , var); Console.WriteLine(&quot;address is 0x{0:x}&quot; , (int)p); Console.WriteLine(&quot;dereferenced is 0x{0:x}&quot; , (*p + 0x5c)); Console.WriteLine(&quot;undereferenced is 0x{0:x}&quot; , ((int)p + 0x5c)); Console.WriteLine(&quot;somegarbage is 0x{0:x}&quot; , *((p + 0x5c))); } } :\&gt;csc unsafe.cs /unsafe Microsoft (R) Visual C# Compiler version 2.10.0.0 (b9fb1610) Copyright (C) Microsoft Corporation. All rights reserved. :\&gt;unsafe.exe value is 0x20 address is 0x4feac4 dereferenced is 0x7c undereferenced is 0x4feb20 somegarbage is 0x0 </code></pre>
29667
2021-12-04T19:10:25.527
<p>I have this memory address <code>0F58F478</code> and this offset <code>5C</code>. I'm using memory sharp and it works perfectly when I'm adding this number.</p> <pre><code>IntPtr address = _mSharp.Read&lt;IntPtr&gt;(0F58F478, false) + 0x5C; // address output: 035F4E60 </code></pre> <p>According to Cheat Engine this would be the result <code>035F4E60</code>. But I've tried using a <a href="https://www.calculator.net/hex-calculator.html" rel="nofollow noreferrer">Hex Calculator</a> and the result is by far kinda different. I'd like to know how MemorySharp or CheatEngine calculates this sum.</p> <p><a href="https://i.stack.imgur.com/qqltd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qqltd.png" alt="enter image description here" /></a></p> <p>Notice that when I add 0 to a pointer this change its value, how this works? Why 0 is adding value there?</p> <p><a href="https://i.stack.imgur.com/nToUq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nToUq.png" alt="enter image description here" /></a></p>
How does Cheat Engine offset calculation work?
|memory|hex|address|offset|cheat-engine|
<p><code>typeinf.hpp</code> is the most complex header file in the IDA SDK. Although it's reasonably well-designed once you understand how to use it, there is likely to be a lot of difficulty in your near future. You probably want to start by ignoring the part of the header that your question asks about, and instead look at the class <code>tinfo_t</code>, which is the primary data structure that IDA uses to represent types. From there, look at its member functions. For example, here are a number of member functions:</p> <ul> <li><code>bool tinfo_t::is_ptr()</code></li> <li><code>bool tinfo_t::is_array()</code></li> <li><code>bool tinfo_t::is_func()</code></li> <li><code>bool tinfo_t::is_complex()</code></li> <li><code>bool tinfo_t::is_struct()</code></li> <li><code>bool tinfo_t::is_union()</code></li> <li><code>bool tinfo_t::is_udt()</code></li> <li><code>bool tinfo_t::is_enum()</code></li> </ul> <p>That should get you started. Good luck! You'll need it!</p>
29669
2021-12-05T02:15:52.693
<p>I checked how to get type information here - <a href="https://www.hex-rays.com/products/ida/support/idapython_docs/ida_typeinf.html" rel="nofollow noreferrer">https://www.hex-rays.com/products/ida/support/idapython_docs/ida_typeinf.html</a></p> <p>Although, I am not sure what these different type prefixes mean. For e.g. <code>BT_{type}</code>, <code>BTMT_{type}</code>, <code>BTF_{type}</code>, etc. I couldn't find any information which distinguishes these types.</p>
idapython: type information with different prefixes
|ida|idapython|
<p>As I Commented the operation here is R0 == R0+R1<br /> the Current Program Status Register or<br /> Application Program Status Register are modified based on the result</p> <p>Assume for example</p> <p>R0 contains 0xffffffff (maximum possible 32 bit unsigned integer)<br /> R1 contains 0x00000001</p> <p>R0+R1 will be</p> <pre><code>&gt;&gt;&gt; print(hex(0xffffffff+0x00000001)) 0x100000000 &gt;&gt;&gt; </code></pre> <p>the result is a 33bit or in other words the result is 0x0 and the 33<sup>rd</sup> bit is lost since result is 0 N or Negative flag is not set <strong>N=0</strong></p> <p>again since result is 0 zero flag is set to 1 <strong>Z=1</strong></p> <p>the upper 33<sup>rd</sup> bit is lost so Carry flag is set <strong>C==1</strong></p> <p>signed or v flag doesn't not have any overflow (-1 + 1 ) == 0 so V flag is not set <strong>V=0</strong></p> <p><a href="https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/condition-codes-1-condition-flags-and-codes" rel="nofollow noreferrer">this all are explained in this document</a></p> <p>there is a source code and demo also attached in the link</p> <p>where adds and the cpsr details are retrieved by this assembly stub you can use unicorn or unicorn based qiling to emulate these instruction</p> <pre><code>doADDS: @ Perform the operation, leaving the result in r0 to return it. adds r0, r0, r1 @ Get the APSR flags and dump them into flags (*r2). mrs r3, CPSR str r3, [r2] @ The recommended (interworking-compatible) return method: bx lr </code></pre> <p>a sample emulation and cpsr flags using Qiling Framework</p> <pre><code>:\&gt;type armshell.py from qiling import * from qiling.const import QL_VERBOSE # 0x0000000000000000: 00 00 E0 E3 mvn r0, #0 # 0x0000000000000004: 01 10 A0 E3 mov r1, #1 # 0x0000000000000008: 01 00 90 E0 adds r0, r0, r1 # 0x000000000000000c: 00 F0 20 E3 nop # 0x0000000000000010: 00 F0 20 E3 nop shellcode = b&quot;\x00\x00\xe0\xe3\x01\x10\xa0\xe3\x01\x00\x90\xe0\x00\xf0\x20\xe3\x00\xf0\x20\xe3&quot; ql = Qiling( code=shellcode, rootfs=r&quot;F:\QILING\examples\rootfs\x8664_windows&quot;, ostype=&quot;linux&quot;, archtype=&quot;arm&quot;, verbose=QL_VERBOSE.DEBUG ) ql.reg.cpsr = 0 ql.reg.r0 = 0 ql.reg.r1 = 0 print(&quot;registers before starting&quot;) print(&quot;r0 = 0x{:x}&quot;.format(ql.reg.r0)) print(&quot;r1 = 0x{:x}&quot;.format(ql.reg.r1)) print(&quot;cpsr = 0x{:x}\n&quot;.format(ql.reg.cpsr)) for i in range(1, 5, 1): ql.run(0, len(shellcode), -1, i) print(&quot;r0 = 0x{:x}&quot;.format(ql.reg.r0)) print(&quot;r1 = 0x{:x}&quot;.format(ql.reg.r1)) print(&quot;cpsr = 0x{:x}\n&quot;.format(ql.reg.cpsr)) </code></pre> <p>executed</p> <pre><code>:\&gt;python armshell.py [+] Profile: Default [+] Set init_kernel_get_tls registers before starting r0 = 0x0 r1 = 0x0 cpsr = 0x0 r0 = 0xffffffff r1 = 0x0 cpsr = 0x0 r0 = 0xffffffff r1 = 0x1 cpsr = 0x0 r0 = 0x0 r1 = 0x1 cpsr = 0x60000000 r0 = 0x0 r1 = 0x1 cpsr = 0x60000000 </code></pre> <p>the cpsr is set with bit 29,30 representing flags Z and C (Zero and Carry)</p> <pre><code>&gt;&gt;&gt; hex(1&lt;&lt;30|1&lt;&lt;29) '0x60000000' &gt;&gt;&gt; </code></pre> <p>feeding with a ladle</p> <pre><code>from qiling import * from qiling.const import QL_VERBOSE # 0x0000000000000000: 00 F0 20 E3 nop # 0x0000000000000004: 01 00 A0 E3 mov r0, #1 # 0x0000000000000008: 06 10 A0 E3 mov r1, #6 # 0x000000000000000c: 00 00 11 E1 tst r1, r0 # 0x0000000000000010: FA 17 00 1A bne #0x6000 # 0x0000000000000014: 00 F0 20 E3 nop shellcode = b&quot;\x00\xf0\x20\xe3\x01\x00\xa0\xe3\x06\x10\xa0\xe3\x00\x00\x11\xe1\xfa\x17\x00\x1a\x00\xf0\x20\xe3&quot; ql = Qiling( code=shellcode, rootfs=r&quot;F:\QILING\examples\rootfs\x8664_windows&quot;, ostype=&quot;linux&quot;, archtype=&quot;arm&quot;, verbose=QL_VERBOSE.DEBUG ) ql.reg.cpsr = 0 ql.reg.r0 = 0 ql.reg.r1 = 0 print(&quot;registers before starting&quot;) print(&quot;r0 = 0x{:x}&quot;.format(ql.reg.r0)) print(&quot;r1 = 0x{:x}&quot;.format(ql.reg.r1)) print(&quot;cpsr = 0x{:x}\n&quot;.format(ql.reg.cpsr)) for i in range(1, 5, 1): ql.run(0, len(shellcode), -1, i) print(&quot;r0 = 0x{:x}&quot;.format(ql.reg.r0)) print(&quot;r1 = 0x{:x}&quot;.format(ql.reg.r1)) print(&quot;cpsr = 0x{:x}\n&quot;.format(ql.reg.cpsr)) </code></pre> <p>emulation of tst instruction.</p> <pre><code>F:\QILING\testqiling&gt;python armtstop.py [+] Profile: Default [+] Set init_kernel_get_tls registers before starting r0 = 0x0 r1 = 0x0 cpsr = 0x0 r0 = 0x0 r1 = 0x0 cpsr = 0x0 r0 = 0x1 r1 = 0x0 cpsr = 0x0 r0 = 0x1 r1 = 0x6 cpsr = 0x0 r0 = 0x1 r1 = 0x6 cpsr = 0x40000000 &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; </code></pre>
29678
2021-12-06T09:40:43.527
<p>This question was asked before here but in the answers I did get what i was looking for.</p> <p>Consider this:</p> <pre><code>ADDS R0 RO R1 </code></pre> <p>As far as I know to update the cpsr flags a subtraction has to be made. So after this instruction, is the result subtracted from RO or R1?</p> <p>Edit: This is what I understand</p> <pre><code>CMP RO R1 </code></pre> <p>In this instruction, <code>R1</code> is subtracted from <code>R0</code> and based on the results the flags are updated. The thing I dont understand is in operations with S suffix the result after the operation like <code>eg ADDS on the top</code> is it subtracted from <code>R0</code> or <code>R1</code> to update the flags or i got it all wrong?</p> <p>Edit 2:</p> <p>For example consider these instructions</p> <pre><code>mov r0, #1 mov r1, #6 tst r1, r0 bne 0x6000 </code></pre> <p>From this example, the result of the tst instruction is 7(111 binary). In the branch instruction how can it branch with the NE condition code if there was no comparison between registers.</p>
ADDS(operations with S suffix) -Arm
|assembly|arm|register|
<p>I know length is sizeof(struct)</p> <pre><code>0:000&gt; ?? sizeof(ntdll!_PEB_LDR_DATA) unsigned int64 0x58 0:000&gt; dt -r nt!_peb Ldr-&gt;Length @$peb ntdll!_PEB +0x018 Ldr : +0x000 Length : 0x58 0:000&gt; </code></pre> <p>edit</p> <p><a href="https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntpsapi_x/peb_ldr_data.htm" rel="nofollow noreferrer">As per Geoff Chappel there is No known Usage of SSHandle</a><br /> so just leave it as PVOID</p>
29687
2021-12-08T12:05:02.603
<p>I've been implementing some Windows internals code and when I have tried to document this structure I have not been able to do so because of those two members. I can't find anything about them.</p> <p>This is the definition of the structure I'm talking about:</p> <pre><code>typedef struct _PEB_LDR_DATA { DWORD dwLength; DWORD dwInitialized; LPVOID lpSsHandle; LIST_ENTRY InLoadOrderModuleList; LIST_ENTRY InMemoryOrderModuleList; LIST_ENTRY InInitializationOrderModuleList; LPVOID lpEntryInProgress; } PEB_LDR_DATA, *PPEB_LDR_DATA; </code></pre> <p>Does anyone know its actual use or content?</p>
Unknown usage of dwLength and SsHandle members in PEB_LDR_DATA
|windows|
<p>I am not sure if there is something inbuilt, but you can write a simple Python script and assign a key binding to that script as below:</p> <pre><code>#TODO evaluates a string expression as Numeral and formats it in multiple radix #@author blabb #@category _NEW_ #@keybinding Shift-SLASH import ghidra exp = askString(&quot;Expression&quot;,&quot;Expression&quot;) print(&quot;Expression is %s&quot; % exp) val = eval(exp) print(ghidra.util.NumericUtilities.formatNumber(val,2)) print(ghidra.util.NumericUtilities.formatNumber(val,8)) print(ghidra.util.NumericUtilities.formatNumber(val,10)) print(ghidra.util.NumericUtilities.formatNumber(val,16)) </code></pre> <p>Executed and screenshotted as below:</p> <p><a href="https://i.stack.imgur.com/sp8nr.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sp8nr.gif" alt="enter image description here" /></a></p>
29690
2021-12-09T09:13:06.200
<p>This is the window that appears when you press <code>Shift</code> + <code>/</code>.</p> <p>Example:</p> <p><img src="https://hex-rays.com/wp-content/uploads/2021/01/calc_simple.png" alt="screenshot" /></p>
Does Ghidra have an equivalent to IDA's "Evaluate Expression" feature?
|ida|ghidra|
<p>Sounds like you want dynamic taint analysis. There is a well-supported, open-source option called <a href="https://github.com/panda-re/panda" rel="nofollow noreferrer">Panda</a>. If you have money to spend, check out the commercial offering <a href="https://www.tetrane.com/" rel="nofollow noreferrer">Reven</a>.</p>
29700
2021-12-10T13:09:13.560
<p>Introduction to problem: I have a binary executable with an unknown network packet protocol. I want to reverse engineer this packet protocol. My current way of doing it is to send some data and step through the instructions in disassembly to try to figure out what the application is doing with this data, and gradually construct the correct protocol. This solution is extremely inefficient. So I want to automate at least a part of this process.</p> <p>Assuming that my network receive function is: <code>int recv(SOCKET s, char * buf, int len, int flags);</code></p> <p>What I want to do is to automate instruction tracking for all instructions reading the chunk of memory pointed by <code>char * buf</code></p> <pre><code>mov eax, [globalRecvBufferPointer] mov dl, [eax] cmp dl, 20h jz somewhere </code></pre> <p>In the example above, I want my automated tool to detect <code>mov dl, [eax]</code> and <code>cmp dl, 20h</code> instructions.<br /> Adding a hardware r/w breakpoint to <code>char * buf</code> lets me detect <code>mov dl, [eax]</code> but not the other.<br /> Another problem I can think of at this stage is when memory pointed by <code>char * buf</code> is copied to stack or other memory locations.</p> <p>Are there ready-made tools for this kind of operation? If not, are there tools where I can implement this idea?</p>
Automated instruction analysis of dynamic memory
|packet|automation|
<p>Two possibilities:</p> <ol> <li>Patch the <code>call</code> instruction to point to a destination of your choosing, such as a &quot;code cave&quot; between the end of the <code>.text</code> section and the subsequent section. Write your function there, or <code>jmp</code> to your DLL / a piece of allocated memory containing your function.</li> <li>Overwrite the IAT entry for <code>glfwCreateWindow</code>, and point it to your new function. Note that this will affect all calls to that function. If you want to affect only individual call sites, you can, for example, check the return address of the caller to ensure that it's the specific call site that you want.</li> </ol>
29707
2021-12-11T15:42:16.797
<p>How to hook to external library function, such as OpenGL for example.</p> <p>I have a function used by the program I am trying to change behaviour of. The function is:</p> <pre><code>lVar17 = glfwCreateWindow(uVar22,uVar25,pplVar29,uVar30,0); </code></pre> <p>Now, I want to change that function without changing the caller function. I.e. the caller function and the call above will remain exactly the same, but the glfwCreateWindow will return something different, i.e. it will be re-written like this:</p> <pre><code>glfwCreateWindow (uVar22,uVar25,pplVar29,uVar30,0) { GLFWwindow* window = glfwCreateWindow(uVar22,uVar25,pplVar29,uVar30,0); HWND hwnd = FindWindow(NULL, WindowName); GLFWwindow* atchdHwd = glfwAttachWin32Window(hwnd, window); return atchdHwd; } </code></pre> <p>Any way of doing this?</p>
How to hook to a system function
|c++|dll|function-hooking|dll-injection|
<p>i just checked idafree 76 and i dont see an idc function to get the pdb file name<br /> but as i commented it is printed in the header you can copy paste it</p> <pre><code>.text:0000000140001000 ; Alignment : default .text:0000000140001000 ; PDB File Name : C:\xx\Desktop\mulcall\mcall.pdb </code></pre> <p>or you can search text for string(&quot;.pdb&quot;) path is normally available in <strong>.rdata</strong> section IMAGE_DEBUG_DIRECTORY</p> <p>using idc function like as below</p> <pre><code>auto cline; cline = find_text(MinEA()+0x1000,1,0,0,&quot;.PDB&quot;); jumpto(cline); Message(&quot;%x\t%s\n&quot; , cline , get_curline()); </code></pre> <p>which should yield</p> <pre><code>14000206c .rdata:000000014000206C text &quot;UTF-8&quot;,'C:\xxx\Desktop\mulcall\mcall.pdb',0 ; PdbFileName </code></pre> <p>be aware this is from debug directory and may not be correct in malwares , stripped , public , etc , manipulated binaries</p> <p>for example a public pdb might return</p> <pre><code>1802420f0 .rdata:00000001802420F0 text &quot;UTF-8&quot;, 'kernelbase.pdb',0 ; PdbFileName </code></pre> <p>in such cases like public pdbs of ms binaries best option is to use dumpbin /pdbpath</p> <pre><code>dumpbin /pdbpath c:\Windows\System32\KernelBase.dll Dump of file c:\Windows\System32\KernelBase.dll File Type: DLL PDB file found at 'f:\symbols\kernelbase.pdb\993F0EEA8C3C260F6D52724A7CA166601\kernelbase.pdb' </code></pre>
29712
2021-12-13T11:30:43.343
<p>IDA Pro can automatically download and load <code>.pdb</code> files from symbol server. And now I want to write an IDAPython plugin to obtain some data from the <code>.pdb</code> file.</p> <p>But I don't know how to get the file path of the already loaded <code>.pdb</code> file.<br /> Can I get it using IDAPython?</p>
Can I get loaded pdb file path from IDAPython?
|ida|idapython|ida-plugin|
<p>The answer is in IDA <strong>Jump to the constructor address</strong>, in my case <code>0x198ef70,</code> then translate to <strong>pseudocode</strong>, and you will find all the attributes with their values related to <strong><code>example</code> class.</strong></p>
29715
2021-12-13T19:39:23.487
<p>I have this class with constructor offsets and attributes:</p> <pre><code>public class example { // Fields public float Attribute_1 = 1.5f; // 0x8 public int Attribute_2 = 102 ; // 0xC // RVA: 0x198EF70 Offset: 0x198EF70 VA: 0x9BF8EF70 public void .ctor() { } } </code></pre> <p>The question is how to access predefined attributes <code>Attribute_1</code> and <code>attribute_2</code> in IDA.</p>
How To Access Predefined Class Attributes From IDA Pro After Loading The Binary Without Debugger Attached To Process
|ida|disassembly|assembly|debugging|binary|
<ul> <li><code>db</code> means “<strong>d</strong>efine <strong>b</strong>yte”, i.e. a reservation of <strong>1</strong> byte of memory,</li> <li><code>dw</code> means “<strong>d</strong>efine <strong>w</strong>ord” (<strong>2</strong> bytes of memory),</li> <li><code>dd</code> means “<strong>d</strong>efine <strong>d</strong>ouble-word” (<strong>4</strong> bytes of memory).</li> </ul> <p>The <code>offset</code> prefix means to fill the reserved byte(s) <em>not with the mentioned data itself (i.e., <em>not with the content</em>),</em> but only with the <em>offset</em> to it (i.e., with the <strong>position</strong> of data in memory, expressed as the number of bytes from the beginning of the segment).</p> <p>The <code>align</code> directive means “If this address is not a multiple of the given number, skip the necessary number of bytes to fulfill this address requirement for the next data”.</p> <hr /> <p>You may see it in your listing:</p> <ul> <li><p><code>db 1</code> is at address <code>0048a388</code>, it occupies only <strong>1</strong> byte (<code>db</code> – <strong>d</strong>efine <strong>b</strong>yte, i.e., <strong>1</strong> byte) and fills it with the given value (<code>1</code>). So the next address is <code>0048a389</code>.</p> </li> <li><p>At this next address (<code>0048a389</code>) is the <code>align 10h</code> directive, so the byte at this address and the subsequent 6 bytes at addresses</p> <ul> <li><code>0048a38a</code>, <code>0048a388b</code>, <code>0048a38c</code>, <code>0048a38d</code>, <code>0048a38e</code>, and <code>0048a38f</code></li> </ul> <p>are <em>skipped,</em> because they <em>don't fulfill</em> the request “a multiple of 10h” (i.e., their last digit in hexadecimal notation is <em>not</em> <code>0</code>).</p> </li> <li><p>At the next address <code>0048a390</code> (which finally fulfills the <code>align 10h</code> requirement) is the directive</p> <ul> <li><code>dd offset WinMain</code>,</li> </ul> <p>which reserves 4 bytes of memory (<code>dd</code> – <strong>d</strong>efine <strong>d</strong>ouble word), and fills them with the <em>offset</em> of the (start of) <code>WinMain</code> function (<code>offset WinMain</code>).</p> </li> </ul>
29733
2021-12-18T18:46:01.303
<p>So, in <code>.data</code> section there is some variable, and after it there is <code>db</code> or <code>dd</code> (<code>offset</code>). What exactly does this mean? And what does “align” means? Is there any Wiki or something like that that tells all this in detail?</p> <pre><code> .data:0048A374 db 0 .data:0048A375 db 0 .data:0048A376 db 0 .data:0048A377 db 0 .data:0048A378 off_48A378 dd offset unk_48A000 ; DATA XREF: start+41↑o .data:0048A37C dd offset unk_48A1CE .data:0048A380 dd offset unk_48A1CE .data:0048A384 dd offset unk_48A33C .data:0048A388 byte_48A388 db 1 ; DATA XREF: __InitVCL+3↑r .data:0048A389 align 10h .data:0048A390 dd offset WinMain .data:0048A394 dd offset __matherr .data:0048A398 dd offset __matherrl .data:0048A39C align 10h .data:0048A3A0 dd offset unk_48F66C .data:0048A3A4 dd offset off_490784 .data:0048A3A8 dd offset off_490788 .data:0048A3AC dd offset __handle_setargv .data:0048A3B0 dd offset __handle_exitargv .data:0048A3B4 dd offset __handle_wsetargv .data:0048A3B8 dd offset __handle_wexitargv .data:0048A3BC dd offset dword_48F0EC .data:0048A3C0 byte_48A3C0 db 0 ; DATA XREF: ___CRTL_VCL_Init_2+2↑r .data:0048A3C0 ; __InitVCL+17↑r .data:0048A3C1 byte_48A3C1 db 0 ; DATA XREF: .text:00401060↑r .data:0048A3C1 ; ___CRTL_VCL_Init_2+B↑r ... .data:0048A3C2 dd offset unk_4906E4 .data:0048A3C6 dd offset unk_4907AC .data:0048A3CA dd offset unk_4904F0 .data:0048A3CE db 0 .data:0048A3CF ; DWORD dwTlsIndex .data:0048A3CF dwTlsIndex dd 0 ; DATA XREF: start:loc_401012↑r .data:0048A3CF ; .text:00401082↑r ... .data:0048A3D3 dword_48A3D3 dd 0 ; DATA XREF: start+1A↑w .data:0048A3D7 dword_48A3D7 dd 0 ; DATA XREF: start+4D↑w .data:0048A3D7 ; .text:__getHInstance↑r ... .data:0048A3DB db 90h ; ђ .data:0048A3DC ; Exported entry 156. ___CPPdebugHook .data:0048A3DC public ___CPPdebugHook .data:0048A3DC ___CPPdebugHook db 0 ; DATA XREF: start+E↑o .data:0048A3DC ; sub_46AF30+20↑o ... .data:0048A3DD db 0 .data:0048A3DE db 0 .data:0048A3DF db 0 </code></pre>
In IDA what does db and dd offset means in data section?
|ida|
<p>This approach won't work. Ghidra analyzes machine code, not ASCII text.</p>
29738
2021-12-19T08:14:44.060
<p>I have some assembly code as a .txt file (i.e. a list of the instructions, stuff like this):</p> <pre><code>00000003 E8D001 call 0x1d6 00000006 A08000 mov al,[0x80] 00000009 0C00 or al,0x0 0000000B 750B jnz 0x18 0000000D 90 nop </code></pre> <p>How would I import this into ghidra? (i.e. copy the code into the code browser window). I originally started with a .COM file, but I couldn't successfully import into Ghidra. My end goal is to compile it up to C.</p>
How to import x86asm into Ghidra?
|assembly|x86|ghidra|dos-com|
<p>In IDA, you can find sequences of bytes via <code>Search-&gt;Sequence of bytes</code>. That said, if your byte pattern is poorly-chosen (for reasons such as that it includes relocatable byte sequences, or it was created for a different version of the software), the result of the search may well be that the pattern cannot be found in the target binary.</p>
29746
2021-12-20T13:26:16.407
<p>I have been trying to reverse engineer a game for a while now. I have a pattern already for the function I want to find:</p> <pre><code>\x89\x54\x24\x10\x4C\x89\x44\x24\x18\x4C \x89\x4C\x24\x20\x48\x83\xEC\x28\x48\x85 \xC9\x75\x08\x8D\x41\x2B\x48\x83\xC4\x28 \xC3\x4C </code></pre> <p>Can I find the function with that pattern using IDA or x64dbg?</p>
Finding function from pattern
|ida|x64dbg|game-hacking|
<p>I'm kinda new to reverse engineering, but I'll tell you what I know.</p> <p>First things:</p> <p>The code is not decompiled, it is just a machine code, but a readable one.</p> <p>If you have an older version of that function, you can scan for it to get the updated version.</p> <p>So to get a function, you need to get the closest thing from it, for example, if you want to get the function that kills your player, you should start to search for a dead state/health/etc. in your player object, get what writes to it, and that should be connected to the kill function somehow, and you go from that function.</p> <p>Now let's say you want to find a GUI or something close, use strings they are the best you can use, by finding a string, for example “Health:”, you could find a reference from it to what draws the GUI.</p> <p>Remember, strings may be obfuscated and/or their references may be obfuscated, too.</p> <p>I recommend you learn more about reverse engineering before posting, there are tons of articles and videos about it.</p> <p>Hopefully, this helps you.</p>
29749
2021-12-20T18:43:11.770
<p>I am attempting to find a function in a specific game. Is there any way that, using the assembly code I get from decompiling the game in either IDA or x64dbg, I can locate a function I am specifically looking for?</p>
How do I find a function and find out what it does using reverse engineering?
|ida|x64dbg|functions|game-hacking|
<p>Assuming you have a binary dump created by say WinDbg <code>.writemem</code></p> <pre><code>0:000&gt; lm m cdb start end module name 00007ff6`af510000 00007ff6`af53e000 cdb (deferred) 0:000&gt; .writemem c:\dumped.bin 00007ff6`af510000 l?(00007ff6`af53e000-00007ff6`af510000) Writing 2e000 bytes............................................................................................ 0:000&gt; </code></pre> <p>C++ does not have the glue to parse PE files. You may need to use the Windows API or roll your own parsing routines.</p> <p>For example the first few bytes of the dump should be <code>IMAGE_DOS_HEADER</code> for it to be a valid PE file.</p> <p>I will dump the section of the aforementioned dump using <a href="https://github.com/erocarrera/pefile" rel="nofollow noreferrer"><code>pefile</code> by Ero</a> a versatile PE parsing Python module.</p> <p>Dumping the first section using the above module from command line</p> <pre><code>C:\&gt;python -c &quot;import pefile;print(pefile.PE(r\&quot;c:\\dumped.bin\&quot;).sections[0]&quot;) [IMAGE_SECTION_HEADER] 0x200 0x0 Name: .text 0x208 0x8 Misc: 0xC1FF 0x208 0x8 Misc_PhysicalAddress: 0xC1FF 0x208 0x8 Misc_VirtualSize: 0xC1FF 0x20C 0xC VirtualAddress: 0x1000 0x210 0x10 SizeOfRawData: 0xC200 0x214 0x14 PointerToRawData: 0x400 0x218 0x18 PointerToRelocations: 0x0 0x21C 0x1C PointerToLinenumbers: 0x0 0x220 0x20 NumberOfRelocations: 0x0 0x222 0x22 NumberOfLinenumbers: 0x0 0x224 0x24 Characteristics: 0x60000020 </code></pre> <p>If you are going to use C basic routines</p> <p>You may need to <code>fopen(....)</code> and <code>fread();</code>, then cast the bytes as DOS header, read <code>e_lfanew</code> as offset to the PE header, then continue to cast, read and parse until you finish.</p> <p>A sample DOS header to PE header offset routine may look like:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;windows.h&gt; #define BUSIZ 0x50 #define MAXREAD 0x40 int main(void) { FILE *infile = NULL; errno_t err = fopen_s(&amp;infile, &quot;c:\\dumped.bin&quot;, &quot;rb&quot;); if (err == 0 &amp;&amp; infile != NULL) { unsigned char buf[BUSIZ] = {0}; size_t siz = 0; siz = fread_s(buf, BUSIZ, 1, MAXREAD, infile); if (siz != 0) { for (int i = 0; i &lt; 16; i++) { printf(&quot;%02x &quot;, buf[i]); } for (int i = 0; i &lt; 16; i++) { printf(&quot;%c &quot;, buf[i]); } printf(&quot;\n&quot;); } PIMAGE_DOS_HEADER dhead = (PIMAGE_DOS_HEADER)&amp;buf; printf(&quot;%x\n&quot;, dhead-&gt;e_magic); printf(&quot;offset to PE Header from start = %x\n&quot;, dhead-&gt;e_lfanew); } else { printf(&quot;file not opened failure \n&quot;); } } </code></pre> <p>compiled and executed</p> <pre><code>:\&gt;cl /Zi /W4 /analyze /Od /EHsc /nologo parse.cpp /link /release parse.cpp :\&gt;parse.exe 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 M Z É 5a4d offset to PE Header from start = f8 </code></pre> <p>edit</p> <p><a href="https://reverseengineering.stackexchange.com/questions/22130/how-to-find-the-starting-address-of-text-section-of-a-dll-inside-a-process-64/22140#22140">a different demo for IMAGE_FIRST_SECTION</a></p> <p>edit src that uses IMAGE_FIRST_SECTION to retrieve all section with 16 initial bytes at each section</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;windows.h&gt; #define BUSIZ 0x500 #define MAXREAD 0x400 FILE *infile = NULL; unsigned char buf[BUSIZ] = {0}; unsigned char tmpbuf[BUFSIZ] = {0}; void hexdump(int bpos, unsigned char *inbuf){ memset(inbuf, 0, BUSIZ); fseek(infile, bpos, SEEK_SET); size_t siz = fread_s(inbuf, BUSIZ, 1, MAXREAD, infile); if (siz != 0) { for (int i = 0; i &lt; 16; i++) { printf(&quot;%02x &quot;, inbuf[i]); } printf(&quot;\n&quot;); } } int main(void){ errno_t err = fopen_s(&amp;infile, &quot;c:\\dumped.bin&quot;, &quot;rb&quot;); if (err == 0 &amp;&amp; infile != NULL){ hexdump(0, buf); PIMAGE_DOS_HEADER dhead = (PIMAGE_DOS_HEADER)&amp;buf; hexdump(dhead-&gt;e_lfanew, buf); PIMAGE_NT_HEADERS64 nthead = (PIMAGE_NT_HEADERS64)&amp;buf; PIMAGE_SECTION_HEADER Section = IMAGE_FIRST_SECTION(nthead); for (WORD i = 0; i &lt; nthead-&gt;FileHeader.NumberOfSections; i++){ printf(&quot;%-8s\t%x\t%x\t%x\n&quot;, Section-&gt;Name, Section-&gt;VirtualAddress, Section-&gt;PointerToRawData, Section-&gt;SizeOfRawData); hexdump(Section-&gt;VirtualAddress, tmpbuf); Section++; } } } </code></pre> <p>compiled and executed</p> <pre><code>&gt;cl /Zi /W4 /analyze /Od /EHsc /nologo parse.cpp /link /release parse.cpp &gt;parse.exe 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 50 45 00 00 64 86 08 00 00 1d 9c 8d 00 00 00 00 .text 1000 400 c200 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc .rdata e000 c600 f800 b0 ff 52 af f6 7f 00 00 50 00 53 af f6 7f 00 00 .data 1e000 1be00 2000 60 e0 51 af f6 7f 00 00 90 e0 51 af f6 7f 00 00 .pdata 27000 1de00 800 10 10 00 00 88 10 00 00 4c ba 01 00 90 10 00 00 .didat 28000 1e600 200 92 ce 51 af f6 7f 00 00 00 00 00 00 00 00 00 00 .mrdata 29000 1e800 2e00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .rsrc 2c000 21600 1000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 .reloc 2d000 22600 a00 00 e0 00 00 28 02 00 00 00 a0 08 a0 10 a0 18 a0 </code></pre> <p>confirmed independently with a hex editor</p> <pre><code>C:\&gt;for %i in (0x0000,0x1000,0xe000,0x1e000,0x27000,0x28000,0x29000,0x2c000,0x2d000) do xxd -s %i -g 1 -l 16 dumped.bin C:\&gt;xxd -s 0x0000 -g 1 -l 16 dumped.bin 00000000: 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 MZ.............. C:\&gt;xxd -s 0x1000 -g 1 -l 16 dumped.bin 00001000: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc ................ C:\&gt;xxd -s 0xe000 -g 1 -l 16 dumped.bin 0000e000: b0 ff 52 af f6 7f 00 00 50 00 53 af f6 7f 00 00 ..R.....P.S..... C:\&gt;xxd -s 0x1e000 -g 1 -l 16 dumped.bin 0001e000: 60 e0 51 af f6 7f 00 00 90 e0 51 af f6 7f 00 00 `.Q.......Q..... C:\&gt;xxd -s 0x27000 -g 1 -l 16 dumped.bin 00027000: 10 10 00 00 88 10 00 00 4c ba 01 00 90 10 00 00 ........L....... C:\&gt;xxd -s 0x28000 -g 1 -l 16 dumped.bin 00028000: 92 ce 51 af f6 7f 00 00 00 00 00 00 00 00 00 00 ..Q............. C:\&gt;xxd -s 0x29000 -g 1 -l 16 dumped.bin 00029000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ C:\&gt;xxd -s 0x2c000 -g 1 -l 16 dumped.bin 0002c000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 ................ C:\&gt;xxd -s 0x2d000 -g 1 -l 16 dumped.bin 0002d000: 00 e0 00 00 28 02 00 00 00 a0 08 a0 10 a0 18 a0 ....(........... </code></pre>
29750
2021-12-20T18:49:48.473
<p>So I am wondering how can I get all sections and their info from a dumped PE file on the disk, using C++.</p> <p>I have the entire PE loaded on a buffer, the NT headers, and hopefully the DOS headers.</p> <p>I need this so I can transform a raw offset of the file into an offset that I can add to the base address and get my result.</p>
How do I get all sections in a PE file using C++?
|windows|c++|executable|winapi|address|
<p>It looks like <code>CRefCountable</code> is either a base class or the first member of the bigger class/structure being initialized. By itself, it is indeed only 8 bytes (vtable pointer and a data member, most likely the reference count).</p>
29752
2021-12-20T20:40:30.093
<p>After looking at some basic examples of how C++ classes are compiled by MSVC, I tried to apply the knowledge to a DLL I'm working on. While searching for a class to start with, I came across <code>CRefCountable</code>. Its constructors are straightforward and it appears to be a base class that almost every other class extends from.</p> <p>Looking at one of the ctors, it seems like a <code>CRefCountable</code> is 8 bytes long, containing the <code>vftable</code> and a <code>DWORD</code>. I then got the impression that there are some &quot;hidden&quot; fields not initialized, as it is called with a pointer to 16 bytes of memory. Scrolling through the references to this ctor, I was surprised to see that it is also called with a pointer to 572, 500 and/or 20 bytes of memory, never with 8 bytes as I suspected.</p> <p>How can the size of this class be variable and bigger than the ctor implies? Or could this be a compiler optimization, where memory for a child class or something else is allocated together with the memory for the object, saving a call to <code>malloc</code>/<code>new</code>?</p> <p>I've decided not to include the decompilation or disassembly of the code in question, as it's either trivial or included in a way bigger function of a child class I haven't touched yet. If needed, I can provide some examples though.</p> <h3>EDIT</h3> <p>I completely forgot that the term &quot;base class&quot; was a thing, sorry about that. I'm very sure that this is a base class from the name and from looking around.</p> <p>This is the constructor that I mentioned above.</p> <pre><code>// mangled name: ??0CRefCountable@@QAE@XZ // demangled name: public: __thiscall CRefCountable::CRefCountable(void) mov eax, ecx mov dword ptr [eax], offset ??_7CRefCountable@@6B@ ; const CRefCountable::`vftable' mov dword ptr [eax+4], 0 retn </code></pre> <p>The values for the size of the object are in constructs such as this:</p> <pre><code>... push 10h call new_or_malloc mov esi, eax add esp, 4 mov [esp+18h+var_10], esi test esi, esi mov [esp+18h+var_4], 0 jz short loc_1002C12E mov ecx, esi ; this call ??0CRefCountable@@QAE@XZ ; CRefCountable::CRefCountable(void) mov dword ptr [esi], offset off_100443DC mov eax, [edi+8] mov [esi+8], eax mov [esi+0Ch], edi jmp short loc_1002C130 loc_1002C12E: xor esi, esi loc_1002C130: ... </code></pre> <p>Ghidra's decompiler turns that into constructs like this (which I used to find these more quickly, as it's more concise).</p> <pre><code> crc = (CRefCountable *)new_or_malloc(0x10); local_4 = 0; if (crc == (CRefCountable *)0x0) { crc = (CRefCountable *)0x0; } else { CRefCountable::CRefCountable(crc ); crc -&gt;vftable = &amp;PTR_AddReference_100443dc; crc[1].vftable = *(undefined ***)(param_1 + 8); crc[1].field_0x04 = param_1; } </code></pre> <p>The value I suppose is the size of the object is the arg to <code>new_or_malloc</code>. This function wasn't recognized by IDA Free or ghidra, but it made sense in the context and the function does call <code>HeapAlloc</code> in the end.</p> <p>Something that I overlooked yesterday evening was that <code>param_1</code> (or <code>edi</code> in the disassembly) sometimes is the <code>this</code> pointer to a object. In this particular case it's a plugin manager class that doesn't seem to extend <code>CRefCountable.</code></p>
One class with different sizes
|windows|x86|c++|msvc|class-reconstruction|
<p>The default assembler syntax used by IDA (<a href="https://docs.microsoft.com/en-us/cpp/assembler/masm/microsoft-macro-assembler-reference" rel="nofollow noreferrer">MASM</a> based) does not use square brackets when the dereference is unambiguous. In your case the second operand is obviously a memory address from which the value is read, and DWORD PTR is another hint that a dereference is taking place. If you prefer to always see square brackets, you can switch to the TASM assembler in <em>Options &gt; General..., Analysis</em>.</p> <p><a href="https://i.stack.imgur.com/RjMqE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RjMqE.png" alt="IDA Options" /></a></p>
29768
2021-12-23T14:15:39.607
<p>I'm reverse engineering a binary and I'm confused, because my theoretical knowledge is currently clashing with what's actually happening.</p> <p>I thought that this instruction writes the value 0xdeadbeef into edx:</p> <pre><code>mov edx, DWORD PTR ds:0xdeadbeef </code></pre> <p>And I thought that this instruction dereferences that address 0xdeadbeef and writes whatever DWORD value is stored at that address into edx:</p> <pre><code>mov edx, DWORD PTR ds:[0xdeadbeef] </code></pre> <p>However, in reality, running this instruction:</p> <pre><code>mov edx, DWORD PTR ds:0x804bdf4 </code></pre> <p>Results in the value of edx being:</p> <pre><code>edx = 0xb73fc115 </code></pre> <p><code>0xb73fc115</code> is the value that's stored at the address <code>0x804bdf4</code>:</p> <pre><code>x 0x804bdf4 0x804bdf4 &lt;gContents&gt;: 0xb73fc115 </code></pre> <p>So that means that the address was dereferenced, even though the assembly didn't contain any square brackets. I thought thatsquare brackets signified a dereferencing operation. What have I misunderstood?</p> <p>I'm using GDB</p> <hr /> <p>Update: I just tested it on radare2, and it shows the instruction in the format that I would expect</p> <pre><code>mov edx, dword [obj.gContents] </code></pre> <p>I also tested it with objdump, and the result was the same as with GDB. I assume it's some sort of syntax I don't currently understand?</p>
Why does the "MOV DWORD PTR ds:0xdeadbeef" instruction dereference the 0xdeadbeef address?
|disassembly|assembly|
<p>idc</p> <pre><code>auto func,i; func = NextFunction(0); while ( func != BADADDR ) { Message(&quot;start = %08x size = %04x &quot; , func , GetFunctionAttr(func,FUNCATTR_END )-func); for (i=0; i&lt;0x10;i++) { Message(&quot;%02x &quot;, Byte(func+i)); } Message(&quot;\n&quot;); func = NextFunction(func); } </code></pre> <p><a href="https://i.stack.imgur.com/xsFXC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xsFXC.png" alt="enter image description here" /></a></p>
29783
2021-12-28T08:19:15.353
<p>I have a x86 executable opened in IDA. In the function window you can see a list of all functions with their starting address.</p> <p><a href="https://i.stack.imgur.com/qyafN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qyafN.png" alt="enter image description here" /></a></p> <p>My goal is to programmatically export a list of all functions IDA found including the following informations:</p> <ul> <li>Their starting address</li> <li>Their instructions as a byte array</li> </ul> <p>How would i do this?</p>
Exporting all function addresses from IDA
|ida|
<p>In the future additional information like what architecture and OS is this for would help because the answer does make a difference. (e.g. a long in x86_64 Windows is 32bits, where as Linux it is 64bits).</p> <p>However lets assume this is x86_64 based on the registers used and turns out here the size of a long doesn't matter.</p> <p>The short answer is that it's not the struct. It's the pointer to the struct. That 'p' has to go someplace.</p> <p>Additionally things returned by new in MOST x86_64 operating systems are 16 byte aligned and so is the stack for performance reasons. So that's where the extra 8 bytes is likely coming from. Could also be space for a stack cookie that's being hidden from your debugger output depending on where you got that assembly output from.</p>
29785
2021-12-29T08:28:54.150
<p>I decided to ask the question on this forum because I can not figure out why struct allocation makes the additional 16 bytes space on local function stack(third line at the second snippet).</p> <p>Here is the c++ simple code and its corresponding assembly version</p> <pre><code>struct product { int weight; } ; void test() { product* p; p=new product(); p-&gt;weight=1; } </code></pre> <pre><code>push rbp mov rbp, rsp sub rsp, 16 mov edi, 4 call operator new(unsigned long) mov DWORD PTR [rax], 0 mov QWORD PTR [rbp-8], rax mov rax, QWORD PTR [rbp-8] mov DWORD PTR [rax], 1 nop leave ret </code></pre>
Why struct allocation with new operator in local function makes additional space on stack?
|stack|assembly|
<ol> <li><p>always post text instead of screen shots as much as possible .</p> </li> <li><p>always provide context .</p> </li> <li><p>the compilers , operating systems , architectures , headers everything evolve and what might have been correct yesterday might not be correct today .</p> </li> <li><p>code with all warnings and analysis enabled as much as possible .</p> </li> <li><p>provide a readily compilable code for some one to spend a few minutes trying to answer if you don't include headers most wont be bothered to look for them .</p> </li> </ol> <p><a href="https://stackoverflow.com/questions/4246514/why-does-gcc-say-named-return-values-no-longer-supported">6) do you know your return statement has a problem called NRVO some compilers will spit cant return n+n2 named returns are not supported ?</a></p> <p>use scopes with {} make it a habit .</p> <p>and not to nitpick but printf is not c++.</p> <p>i have attached a gif below that should answer your question watch it several times test and edit your question what you do not understand in that gif and whether you were able to find the answer you were looking for by watching it</p> <p><a href="https://i.stack.imgur.com/lwHJ0.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lwHJ0.gif" alt="enter image description here" /></a></p> <p>As Commented there are several kinds of Optimization<br /> you can read the docs for the compiler you use<br /> for msvc cl.exe these are the Optimizations that can be performed</p> <pre><code>C:\&gt;cl /nologo /? | grep /O /O1 maximum optimizations (favor space) /O2 maximum optimizations (favor speed) /Ob&lt;n&gt; inline expansion (default n=0) /Od disable optimizations (default) /Og enable global optimization /Oi[-] enable intrinsic functions /Os favor code space /Ot favor code speed /Ox optimizations (favor speed) </code></pre> <p>optimized code is difficult to analyze<br /> that is why there debug build are used when writing code<br /> optimized builds are used when releasing the code<br /> while releasing the symbols are also stripped away so an optimized release built binary is just bytes all over which the reverse engineer has to decipher</p>
29795
2021-12-29T23:23:47.650
<p>I have created a very simple <code>x86</code> console program that uses <code>Visual Studio 2019 compiler</code> to sum 2 numbers just to see how is the program be after disassembly but I found something unclear to me.</p> <pre><code>// C++ #include &lt;iostream&gt; int sum(int n, int n2) { return n + n2; } int main() { int result = sum(7, 3); std::cout &lt;&lt; result; } </code></pre> <p>After disassembled</p> <pre><code>; The main function from outside Push edi push esi push dword ptr ds:[eax] call &lt;consoleapplication._main&gt; add esp, C ; The main function from inside mov ecx, dword ptr ds : [&lt;&amp;? cout@std@@3V ? $basic_ostream@DU ? $char_traits@D@std@@@1@A&gt;] push A call dword ptr ds : [&lt;&amp;? ? 6 ? $basic_ostream@DU ? $char_traits@D@std@@@std@@QAEAAV01@H@Z&gt;] xor eax, eax ret </code></pre> <p>As you have seen in the second code block, the second line</p> <pre><code>push A </code></pre> <p>That is the result of the &quot;sum&quot; function but <strong>where is its body and where is the call instruction that calls it in the main function?</strong></p>
I don't find the body of a function that I called in the main function
|disassembly|functions|
<p>In the end, I found how to do it. In <kbd>Search</kbd> &gt; <kbd>Not Function</kbd>.</p>
29813
2022-01-02T14:11:05.030
<p>I don't want to get too much into detail, but a disastrous chain of events that began with a boolean of incorrect size forced the IDA analyzer to discard a lot of instruction sections of many functions.</p> <p>Here is what I mean: <a href="https://i.stack.imgur.com/19sLT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/19sLT.png" alt="enter image description here" /></a></p> <p>I'm slowly fixing everything up and so there is no problem with that. My question is: <strong>Is there a way to list every instruction not inside of a function in IDA?</strong> Just so I don't leave some of them without a fix.</p>
List instructions to fix wrong IDA analysis
|ida|disassembly|x86|
<p>Since the answer to my question in the comment moved to chat, I am going to write it here again. The OS which meets my requirements the best is <a href="https://reactos.org/" rel="nofollow noreferrer">React OS</a>.</p>
29824
2022-01-06T12:15:56.003
<p>Have read in some Discord channel, that Windows was reverse engineered. Does anybody here have knowledge about such reverse engineered Windows version? If it really exists, where can it be downloaded?</p>
Windows reverse engineered?
|windows|
<p>At a guess, the class participates in a virtual inheritance tree. When constructing a class with virtual bases, the constructor needs to know whether its virtual bases have been already constructed or not. The extra argument is used for that. If you compile a sample program with virtual inheritance and look at its <a href="https://godbolt.org/z/e6cTajqf3" rel="nofollow noreferrer">assembly output</a>, you'll see that it's called 'initVBases' (i.e. &quot;initialize virtual bases&quot;).</p> <pre><code>_this$ = -4 ; size = 4 _$initVBases$ = 8 ; size = 4 button::button(void) PROC ; button::button, COMDAT push ebp mov ebp, esp push ecx mov DWORD PTR _this$[ebp], ecx cmp DWORD PTR _$initVBases$[ebp], 0 je SHORT $LN2@button mov eax, DWORD PTR _this$[ebp] mov DWORD PTR [eax], OFFSET const button::`vbtable' mov ecx, DWORD PTR _this$[ebp] add ecx, 8 call control::control(void) $LN2@button: mov ecx, DWORD PTR _this$[ebp] mov edx, DWORD PTR [ecx] mov eax, DWORD PTR [edx+4] mov ecx, DWORD PTR _this$[ebp] mov DWORD PTR [ecx+eax], OFFSET const button::`vftable' mov eax, DWORD PTR _this$[ebp] mov esp, ebp pop ebp ret 4 button::button(void) ENDP ; button::button </code></pre> <p>In case the binary has RTTI (Run-time Type Information), you should be able to confirm it by inspecting the <a href="http://www.openrce.org/articles/full_view/23" rel="nofollow noreferrer">RTTI structures</a>.</p>
29833
2022-01-08T13:58:29.400
<p>This is something that I found in a lot of constructors that have to do with classes that inherit from other classes. I have a vague idea as to why it's done, but I'd rather have it confirmed before having to re-visit all of my classes.</p> <p>Say I have a constructor with a known signature e.g. <code>CPalette()</code>. The compiler turn this into a <code>CPalette * __thiscall CPalette::CPalette(CPalette* this)</code>, with <code>this</code> being in ecx. Hence, no values need to be retrieved from the stack. However, when the constructor is called, it looks something like this:</p> <pre><code>// with allocated memory in eax PUSH 0x01 MOV ecx, eax CALL CPalette::CPalette </code></pre> <p>Inside the constructor, this value is then used in a test:</p> <pre><code>// start of constructor PUSH -0x01 PUSH label_1 MOV eax, fs:[0x00] // question for another day PUSH eax MOV dword ptr fs:[0x00], esp SUB esp ,0x8 MOV eax, dword ptr [esp + 18] // Ghidra: ... [esp + Stack[0x04]] PUSH esi MOV esi, ecx PUSH edi TEST eax, eax MOV dword ptr [esp + 0x08], esi // Ghidra: ... [esp + local_14] MOV dword ptr [esp + 0x18], 0x00 // Ghidra: ... [esp + local_4] JZ label_2 </code></pre> <p>I'm also a bit confused about Ghidra's auto-analysis, which I've attached to the end of the respective lines. The decompilation uses the name <code>in_stack_00000004</code> for the <code>TEST</code>ed register.</p> <p>Why do we push a 1 on the stack and what is the test doing?<br /> My best guess is that this is a way to know if the constructor is called directly or by a child class constructor, since I've seen some <code>PUSH 0x00</code>s before constructor calls inside other constructors. If this is the case, why is this done?</p> <p>This is from a 32 bit windows DLL.</p>
Constructors testing for strange in-stack value
|disassembly|x86|c++|
<p>A &quot;heavy-weight&quot; answer to this question would be that you can force the decompiler to flush all decompilation caches that it maintains via <code>Edit-&gt;Other-&gt;Reset decompiler information</code>, then selecting (only) <code>All caches</code>. This does what it sounds like, and forces Hex-Rays to re-decompile every function rather than relying upon cached results the next time around. Of course, this will increase the amount of time it takes for Hex-Rays to decompile any function the next time around, since it won't be able to use cached results.</p>
29838
2022-01-09T23:23:04.250
<pre><code>; PCWSTR __stdcall RtlGetNtSystemRoot() public RtlGetNtSystemRoot RtlGetNtSystemRoot proc near ; CODE XREF: LdrpBuildSystem32FileName+1A↑p ; _IsOverlaySupportedPath+2B↓p ... ; FUNCTION CHUNK AT .text:00000001800B5A2A SIZE 00000019 BYTES sub rsp, 28h call RtlGetCurrentServiceSessionId test eax, eax jnz ReadFromPEB mov eax, offset UserSharedData.NtSystemRoot ; was 7FFE0030h instead of the offset loc_18003C806: ; CODE XREF: RtlGetNtSystemRoot+7924E↓j add rsp, 28h retn ; --------------------------------------------------------------------------- db 0CCh RtlGetNtSystemRoot endp </code></pre> <p>(NB: <code>ReadFromPEB</code> is uninteresting for this discussion.)</p> <p>When I originally decompiled this code, it looked somewhat like this (even without the cast on the second <code>return</code>):</p> <pre><code>PCWSTR __stdcall RtlGetNtSystemRoot() { if ( RtlGetCurrentServiceSessionId() ) return (NtCurrentPeb()-&gt;SharedData + 0x30); else return 0x7ffe0030i64; } </code></pre> <p>The color of the second <code>return</code> value suggested something was wrong, so I went ahead and made the address known to IDA.</p> <p>Now, <code>UserSharedData</code> is a struct (based on the imported standard struct <code>_KUSER_SHARED_DATA</code>) which resides in its own segment which I declared at 0x7FFE0000. I declared the segment with the current size of the struct (0x720) to fit it snugly.</p> <p>It looks like this:</p> <pre><code>_user_shared_data segment para public '' use64 assume cs:_user_shared_data ;org 7FFE0000h assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing UserSharedData _KUSER_SHARED_DATA &lt;?&gt; ; DATA XREF: LdrpGenSecurityCookie+4A↓r ; LdrpGenSecurityCookie+53↓r ... _user_shared_data ends </code></pre> <p>After that I changed the original disassembly line:</p> <pre><code>mov eax, 7FFE0030h </code></pre> <p>to:</p> <pre><code>mov eax, offset UserSharedData.NtSystemRoot </code></pre> <p>Alas, when I closed all the &quot;Pseudocode&quot; windows and then hit <kbd>F5</kbd> again, the output remained the same. Thinking I'd be able to adjust it through the Edit menu I found all relevant menu items disabled there.</p> <p>However, then I went ahead typing up my question here (which in the end had to be changed completely once again) just to go back to IDA and see that the Peudocode view had finally caught up to my change of the segment and the disassembly:</p> <pre><code>PCWSTR __stdcall RtlGetNtSystemRoot() { if ( RtlGetCurrentServiceSessionId() ) return (NtCurrentPeb()-&gt;SharedData + 30); else return UserSharedData.NtSystemRoot; } </code></pre> <p>I've had this lag before and found it somewhat annoying. I assume it's perhaps an expensive operation that runs in the background every now and then.</p> <p><strong>Question:</strong> But can I perhaps also <strong>force IDA to sync</strong> the knowledge the disassembler has with that of the decompiler so such changes take effect immediately in the pseudo-code?</p>
How to get IDA and Hex-Rays to forcibly sync their knowledge of the sample on-demand?
|ida|hexrays|
<p>They are not exempt from the caches being cleared; marking something as decompiled simply changes the color of the function in the <code>func_t</code>, and does not affect the caches in any way. However, this is not a big deal. The &quot;caches&quot; referred to by that menu item simply mean the saved <code>cfunc_t</code> and <code>mba_t</code> data structures for that function, which Hex-Rays uses to accelerate subsequent decompilations of functions you've already looked at. You won't lose any annotations (names, comments, types, having marked a function as decompiled, etc.) by clearing the caches. I clear the caches multiple times a day on databases that are important to me; don't worry about losing your work. If you're really paranoid, save your database or create a snapshot first before giving it a try; you'll see that you don't lose any of your work.</p> <p>The only negative effect is the slowdown on re-decompiling unrelated functions that you otherwise have no interest in clearing the cache entries for. If you don't like that slowdown, an IDAPython one-liner <code>ida_hexrays.mark_cfunc_dirty(funcEa)</code> will clear the <code>cfunc_t</code> cache entry for the function at address <code>funcEa</code> (though I'm not sure if it will also purge the <code>mba_t</code> cache entry, which is likely necessary to trigger the changes stemming from the disassembly listing).</p>
29840
2022-01-10T07:53:16.213
<p>In his answer to a question, Rolf pointed me to the <kbd>Edit</kbd> -&gt; <kbd>Other</kbd> -&gt; <kbd>Reset decompiler information</kbd> functionality, suggesting that &quot;All caches&quot; will force the decompiler to pick up <em>immediately</em> on changes I made to the disassembly.</p> <p><a href="https://i.stack.imgur.com/s2eYZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s2eYZ.png" alt="Reset decompiler information dialog" /></a></p> <p>This sounds like a sensible idea. However, he cautions that the resetting will also mean that the decompiler has more work to do on subsequent decompilations. Makes sense.</p> <p><strong>Now the question I have is:</strong> when I use the <kbd>Mark as decompiled</kbd> menu item on the pseudo code and only <em>then</em> use the <kbd>Reset decompiler information</kbd> functionality, will the functions marked decompiled be exempt from the clearing of caches?</p> <p><a href="https://i.stack.imgur.com/ARCry.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ARCry.png" alt="Mark as decompiled menu item" /></a></p>
Will "Reset decompiler information"+"All caches" invalidate functions marked as decompiled?
|hexrays|
<p>I don't know how proper this method is or<br /> what dangers lurk by using these hacks but I have sometimes used the</p> <pre><code>ida -&gt; file -&gt; load file -&gt;parse c header file (ctrl+f9) </code></pre> <p>to get the job done in free versions (5 and 7)</p> <p>suppose you have are analyzing a binary whose source is</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main (int argc,char* argv[] ){ if(argc == 2) { int res = 0; int nts = atoi(argv[1]); switch (nts) { case 1: res = 0xC000001DL; break; case 2: res = 0xC000001EL; break; case 3: res = 0xC000001FL; break; case 4: res = 0xC0000020L; break; case 5: res = 0xC0000021L; break; case 6: res = 0xC0000022L; break; default: res = 0xffffffff; break; } printf(&quot;you asked %d i give %08x\n&quot; , nts, res); return 0; } } </code></pre> <p>whose main disassembled will look like (ida free 7)</p> <pre><code>text:000000014000106C loc_14000106C: ; jumptable 000000014000106A case 1 .text:000000014000106C mov [rsp+38h+var_18], 0C000001Dh .text:0000000140001074 jmp short loc_1400010B0 .text:0000000140001076 ; --------------------------------------------------------------------------- .text:0000000140001076 .text:0000000140001076 loc_140001076: ; jumptable 000000014000106A case 2 .text:0000000140001076 mov [rsp+38h+var_18], 0C000001Eh .text:000000014000107E jmp short loc_1400010B0 .text:0000000140001080 ; --------------------------------------------------------------------------- .text:0000000140001080 .text:0000000140001080 loc_140001080: ; jumptable 000000014000106A case 3 .text:0000000140001080 mov [rsp+38h+var_18], 0C000001Fh .text:0000000140001088 jmp short loc_1400010B0 .text:000000014000108A ; --------------------------------------------------------------------------- .text:000000014000108A .text:000000014000108A loc_14000108A: ; jumptable 000000014000106A case 4 .text:000000014000108A mov [rsp+38h+var_18], 0C0000020h .text:0000000140001092 jmp short loc_1400010B0 .text:0000000140001094 ; --------------------------------------------------------------------------- .text:0000000140001094 .text:0000000140001094 loc_140001094: ; jumptable 000000014000106A case 5 .text:0000000140001094 mov [rsp+38h+var_18], 0C0000021h .text:000000014000109C jmp short loc_1400010B0 .text:000000014000109E ; --------------------------------------------------------------------------- .text:000000014000109E .text:000000014000109E loc_14000109E: ; jumptable 000000014000106A case 6 .text:000000014000109E mov [rsp+38h+var_18], 0C0000022h .text:00000001400010A6 jmp short loc_1400010B0 .text:00000001400010A8 ; --------------------------------------------------------------------------- .text:00000001400010A8 .text:00000001400010A8 def_14000106A: ; jumptable 000000014000106A default case .text:00000001400010A8 mov [rsp+38h+var_18], 0FFFFFFFFh .text:00000001400010B0 .text:00000001400010B0 loc_1400010B0: </code></pre> <p>you can simply make a dummy header file stuff them into an enum and use parse header after some notepad++ magic (column editing to remove #define regex substitute = etc)</p> <p>:&gt;cat tpass.h</p> <pre><code>enum some_crap { STATUS_ILLEGAL_WHATSIT =((NTSTATUS)0xC000001DL), STATUS_INVALID_LOCKIT =((NTSTATUS)0xC000001EL), STATUS_INVALID_VIEWIT = ((NTSTATUS)0xC000001FL), STATUS_INVALID_FILEIT =((NTSTATUS)0xC0000020L), STATUS_ALREADY_COMMITIT =((NTSTATUS)0xC0000021L), STATUS_ACCESS_DENYIT = ((NTSTATUS)0xC0000022L) }; :\&gt; </code></pre> <p>use ctrl+f9 and parse it you will get compiled successfully</p> <pre><code>\ntst\tpass.h: successfully compiled Caching 'Local Types'... ok Caching 'Names'... ok </code></pre> <p>see gif for further details</p> <p><a href="https://i.stack.imgur.com/Cd8Fx.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cd8Fx.gif" alt="enter image description here" /></a></p>
29845
2022-01-11T11:15:47.723
<p>Is there any tools can auto generate enum type by macro?</p> <p>For example, NTSTATUS in Windows defined as</p> <pre><code>#define STATUS_ILLEGAL_INSTRUCTION ((NTSTATUS)0xC000001DL) #define STATUS_INVALID_LOCK_SEQUENCE ((NTSTATUS)0xC000001EL) #define STATUS_INVALID_VIEW_SIZE ((NTSTATUS)0xC000001FL) #define STATUS_INVALID_FILE_FOR_SECTION ((NTSTATUS)0xC0000020L) #define STATUS_ALREADY_COMMITTED ((NTSTATUS)0xC0000021L) #define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022L) ... </code></pre> <p>I want to import it into IDA Pro as enum, How can I do it?</p>
How to import macro as enum into IDA Pro?
|ida|
<p>Sadly, Hex-Rays control flow structuring algorithms are a black box with exactly two knobs on the outside of it: the two options that you listed. If those two knobs don't improve the behavior you're experiencing, then there's nothing you can do as a user. Not even writing a plugin; control flow structuring is only mentioned once in the SDK, and none of the relevant data structures are defined in the headers. You're going to have to live with whatever Hex-Rays gives you, unfortunately.</p> <p>(More technically: the behavior you're seeing with combining the two if-statements into a compound is very fundamental to the way that Hex-Rays structures control flow, and there's nothing you can do to influence it short of reverse engineering the control flow structuring implementation and reimplementing it. Even if you do that (which I have), you only have very limited influence to prevent the compound from being re-created during the next phase of ctree analysis.)</p>
29847
2022-01-11T12:27:41.043
<p>Are there any good ways of splitting up a very long for loop or if statement in IDA into larger chunks to make it more readable? Disabling <code>use fast structure analysis</code> in the Hex Rays decompiler options did not help. Nor did setting the <code>Max commas</code> option to 1, as explained by Rolf Rolles in this <a href="https://twitter.com/rolfrolles/status/1345512891667992578" rel="nofollow noreferrer">Twitter post</a>.</p> <pre><code>for ( i = four - 1; file_size &gt; i + tmp + 1 &amp;&amp; match_buffer(&amp;buf[tmp], i + 1, buf_num, idx) != -1; ++i ) { ; } </code></pre> <p>What I am trying to achieve is getting this on multiple lines. For reference I am using IDA Free v7.7 for Linux.</p> <p>The equivalent in Ghidra looks like this and I was hoping to get the same result in IDA:</p> <pre><code>for (i = four - 1; tmp + i + 1 &lt; file_size; i += 1) { var1 = match_buffer(buf + tmp,i + 1,buf + num,tmp - num); // == match_buffer(buf[tmp], i + 1, buf[num], tmp - num); if (var1 == -1) break; } </code></pre>
Disable optimization of for loops in Hex Rays Decompiler
|ida|hexrays|
<p>As peter ferrie pointed out you have a relocation entry there<br /> which can be inferred by the opcode and address const</p> <p><code>BE E4732201 =&gt; mnem addr =&gt; mov esi, 012273e4</code></p> <p>if the load address changed the 0122 (HIGH_LOW) part will change<br /> according to the load address so your patch gets modified .</p> <p>i statically rebased an image from its preferred ImageBase</p> <p><a href="https://i.stack.imgur.com/NMjTr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NMjTr.png" alt="enter image description here" /></a></p> <p>after changing image base notice the relocation address starts from<br /> 0xxxxxaa while instruction address starts from 0xxxxxa9<br /> notice original bytes in the second snap (relocation table entry)</p> <p>image is from ghidra</p> <p><a href="https://i.stack.imgur.com/6gCxH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6gCxH.jpg" alt="enter image description here" /></a></p>
29850
2022-01-11T16:45:21.137
<p>I'm struggling with a patch in an x86 .exe. I replaced a MOV with a JMP but everytime I run the debugger, the address gets modified as a sort of rebasing:</p> <pre><code>BE E4732201 MOV ESI,App.012273E4 </code></pre> <p>should be replaced by</p> <pre><code>E9 9C380000 JMP App.0104EC75 </code></pre> <p>It's funny because it is anyway a relativ jump, where I literally want to jump 0x389C from execution pointer. Instructions have also same size so I suppose there is no problem with filling or alignment..? I've done other modifications in the HEX and haven't got a problem so far. But with this one, everytime it runs, it changes my 9C380000 literal to something like 9C38xx00 where &quot;xx&quot; varies depending on the execution or if running on Olly or IDA. Even funnier, the instruction right above my patch is:</p> <pre><code>E9 A1380000 JMP App.0104EC75 </code></pre> <p>Which is the exactly the same jump, to the same location (there fore plus 0x05 on the offset) and this one works. It's original code and does not get changed at all during execution but my jump does. Same OP code and same destination. Any thoughts why that is?</p>
IDA/Olly changing address bytes after patch during debugging on x86
|patching|hex|
<p>&quot;Constant&quot; in this case does not refer to the common programming term &quot;a value that should not be altered by the program during normal execution&quot;</p> <p>In this scenario &quot;constant&quot; means the memory address is directly holding the value of the variable.</p> <p>The &quot;value&quot; term means the memory address is pointing to another memory address, and that 2nd memory address is pointing to the value.</p> <p>You can see this as the memory address for the &quot;value&quot; follow is <strong>00 40 2D 30</strong> which is the value shown in the &quot;constant&quot; follow <strong>30 2D 40 00</strong> The order of numbers is reversed due numbers being stored in little endian format.</p> <p>To fully understand whether this is a &quot;constant&quot; or a &quot;value&quot; data type would need to see the complete function and how the rcx value gets used.</p> <p>For a simple example let's take this C code:</p> <pre><code>int main() { int v = 128; int i = v; int *j = &amp;i; i=i+2; *j = i+4; return 0; } </code></pre> <p>Here we can think of &quot;i&quot; as being the &quot;constant&quot; which is when the memory address representing &quot;i&quot; contains the actual value.</p> <p>However, the memory address representing &quot;j&quot; is type &quot;value&quot; pointing to another memory address that contains the actual value. In real programs these &quot;value&quot; types will often point to complicated structures, which can require a detailed analysis of how it is used to work out the original data types.</p> <p>In this simplistic example the assembly is something like this:</p> <pre><code>sub rsp, 24 mov DWORD PTR v$[rsp], 128 ; 00000080H mov eax, DWORD PTR v$[rsp] mov DWORD PTR i$[rsp], eax lea rax, QWORD PTR i$[rsp] mov QWORD PTR j$[rsp], rax mov eax, DWORD PTR i$[rsp] add eax, 2 mov DWORD PTR i$[rsp], eax mov eax, DWORD PTR i$[rsp] add eax, 4 mov rcx, QWORD PTR j$[rsp] mov DWORD PTR [rcx], eax xor eax, eax add rsp, 24 ret 0 </code></pre> <p>Here we see the example of the &quot;constant&quot;</p> <pre><code>mov eax, DWORD PTR i$[rsp] add eax, 2 mov DWORD PTR i$[rsp], eax </code></pre> <p>We can see the value at memory address $i[rsp] is loaded into eax, 2 is added to it, then the value is directly stored back in the memory address via</p> <pre><code>mov DWORD PTR $i[rsp], eax </code></pre> <p>In this case we would use the &quot;constant&quot; follow on <strong>DWORD PTR $i[rsp]</strong> to find the value.</p> <p>However, with j we are instead getting a memory address held at <strong>$j[rsp]</strong> which points to the memory location of i. Instead of updating <strong>DWORD PTR $j[rsp]</strong> this time we are instead setting the value at the memory location held there.</p> <pre><code>mov eax, DWORD PTR i$[rsp] add eax, 4 mov rcx, QWORD PTR j$[rsp] mov DWORD PTR [rcx], eax </code></pre> <p>In this scenario we would use the &quot;value&quot; follow on <strong>$j[RSP]</strong> to find the value.</p>
29854
2022-01-11T20:41:27.433
<p>in file i find</p> <pre><code>mov rcx,qword ptr ds:[404320] </code></pre> <p>when I wanted to see what is at the address 404320 i press &quot;follow in dump&quot; and i got a choice between &quot;constant: file.0000000000404320&quot; and &quot;value: [0000000000404320]&quot; and if i press constant, i see:</p> <pre><code>0000000000404320 30 2D 40 00 00 00 00 00 00 00 00 00 00 00 00 00 0-@............. </code></pre> <p>&quot;30 2D 40 00 00 00 00 00&quot; highlighted</p> <p>if i press value, i see:</p> <pre><code>0000000000402D30 FF FF FF FF FF FF FF FF D2 15 40 00 00 00 00 00 ÿÿÿÿÿÿÿÿÒ.@..... 0000000000402D40 20 2D 40 00 00 00 00 00 00 00 00 00 00 00 00 00 -@............. </code></pre> <p>&quot;D2 15 40 00 00 00 00 00 20 2D 40 00 00 00 00 00&quot; highlighted</p> <p>please can you explain the difference between a value and a constant? I am new to this topic. just in case, i know assembler. and if not enough information has been provided tell me.</p>
please explain the difference between the two types of follow
|x64dbg|
<p>Yes. If you have Hex Rays decompiler you can mouse over the decompiled version and will show RET is EAX.</p> <p><a href="https://i.stack.imgur.com/zYvNl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zYvNl.png" alt="enter image description here" /></a></p> <p>Generally in most x86 calling conventions return values are in eax.</p> <p>However need to be aware without debugging symbols available the automatically generated parameters and return value in IDA Pro in the sub name are not always correct.</p> <p>Further details are available <a href="https://hex-rays.com/products/ida/support/idadoc/1361.shtml" rel="nofollow noreferrer">here</a></p>
29859
2022-01-12T21:02:54.917
<p>I have a function with the following header sub_45BD46@eax(char a1@bl, int a2@esi, int a3), my question is: I am right that sub_45BD46@eax means the result value is in eax?</p>
IDA decompiler syntax: for function int __usercall sub_45BD46@ <eax>(char a1@<bl>, int a2@<esi>, int a3)
|ida|x86|decompilation|
<p>Type typical use of meta data in .NET assemblies is documented <a href="https://docs.microsoft.com/en-us/dotnet/standard/metadata-and-self-describing-components" rel="nofollow noreferrer">here</a></p> <p>Metadata describes every type and member defined in your code in a language-neutral manner. Metadata stores the following information:</p> <ul> <li>Description of the assembly.</li> <li>Identity (name, version, culture, public key)</li> <li>The types that are exported.</li> <li>Other assemblies that this assembly depends on</li> <li>Security permissions needed to run.</li> <li>Description of types.</li> <li>Name, visibility, base class, and interfaces implemented.</li> <li>Members (methods, fields, properties, events, nested types).</li> <li>Attributes</li> <li>Additional descriptive elements that modify types and members.</li> </ul> <p>It is common for .NET obfuscators to modify this metadata to increase the complexity of reverse engineering.</p> <p>ConfuserEx uses many different techniques for .NET obfsucation. The most basic for preventing opening with IlDasm is applying an attribute &quot;<a href="https://github.com/mkaring/ConfuserEx/wiki/Anti-IL-Dasm-Protection" rel="nofollow noreferrer">SuppressIldasmAttribute</a>&quot; to the assembly. However nearly all modern decompilers will ignore this attribute, it doesn't add meaningful protection on its own.</p> <p>In relation to metadata ConfuserEx also uses &quot;<a href="https://github.com/mkaring/ConfuserEx/wiki/Invalid-Metadata-Protection" rel="nofollow noreferrer">Invalid Metadata Protection</a>&quot; where invalid data is added to the meta data, which can prevent older decompilers opening the assembly but modern decompilers already work around this protection.</p> <p>Full list of protections ConfuserEx uses is documented <a href="https://github.com/mkaring/ConfuserEx/wiki/Protections" rel="nofollow noreferrer">here</a></p>
29860
2022-01-12T22:26:57.080
<p>hi there I hope you doing well</p> <p>lately, I have searched about ildasm and how to protect my DLLs from reverse engineering,</p> <p>so I found some great open source projects (ConfuseEx..), it works when I tried the reverse engineering my dll with ILSpy it didn't show my code and because of my curiosity I start searching how that happened,</p> <p>I found the reverse engineering depends on the metaData of the DLL to show Extract the code with ildasm.exe so this lead me to ask some questions I didn't find answers to them,</p> <p>did the ConfuseEx corrupt metaData of the assemblies to protect them from reverse Engineering?</p> <p>is metaData used to define the functions of the assembly to other assemblies to use them? (without defined functions in metaData we cant access the DLL function)</p> <p>can I protect my function content by corrupting metaData variable definitions and all these defined functions?</p>
what is metaData of assemblies and what is used for
|assembly|.net|c#|
<p>you have a string you cant load a string as is into a disassembler you may need to un-escape them into binary for example<br /> <code>&quot;\x48&quot; is &quot;H&quot;</code></p> <p>if you have a compiler compile and call it via a function pointer<br /> use a scripting language like python make a binary blob and load it as raw into disassembler</p> <p>use a disassembling framework like capstone combined with python to disassemble</p> <pre><code>&gt;&gt;&gt; list(Cs(CS_ARCH_X86, CS_MODE_32).disasm(b&quot;\x48\x83\xEC\x28\x48\x83\xE4\xF0\x48\x8D\x15\x66\x00\x00\x00&quot;,0)) [ &lt;CsInsn 0x0 [48]: dec eax&gt;, &lt;CsInsn 0x1 [83ec28]: sub esp, 0x28&gt;, &lt;CsInsn 0x4 [48]: dec eax&gt;, &lt;CsInsn 0x5 [83e4f0]: and esp, 0xfffffff0&gt;, &lt;CsInsn 0x8 [48]: dec eax&gt;, &lt;CsInsn 0x9 [8d1566000000]: lea edx, [0x66]&gt; ] </code></pre> <p><a href="http://shell-storm.org/online/Online-Assembler-and-Disassembler/" rel="nofollow noreferrer">use an online service like shell storm to simply paste and disassemble</a></p> <p><a href="https://i.stack.imgur.com/jexQB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jexQB.png" alt="enter image description here" /></a></p>
29870
2022-01-13T16:01:18.047
<p>I'm trying to learn more about reverse engineering, and I've found some shellcode embedded in a C program:</p> <pre><code> unsigned char shellcode[] = &quot;\x48\x83\xEC\x28\x48\x83\xE4\xF0\x48\x8D\x15\x66\x00\x00\x00&quot; &quot;\x48\x8D\x0D\x52\x00\x00\x00\xE8\x9E\x00\x00\x00\x4C\x8B\xF8&quot; &quot;\x48\x8D\x0D\x5D\x00\x00\x00\xFF\xD0\x48\x8D\x15\x5F\x00\x00&quot; &quot;\x00\x48\x8D\x0D\x4D\x00\x00\x00\xE8\x7F\x00\x00\x00\x4D\x33&quot; &quot;\xC9\x4C\x8D\x05\x61\x00\x00\x00\x48\x8D\x15\x4E\x00\x00\x00&quot; &quot;\x48\x33\xC9\xFF\xD0\x48\x8D\x15\x56\x00\x00\x00\x48\x8D\x0D&quot; &quot;\x0A\x00\x00\x00\xE8\x56\x00\x00\x00\x48\x33\xC9\xFF\xD0\x4B&quot; &quot;\x45\x52\x4E\x45\x4C\x33\x32\x2E\x44\x4C\x4C\x00\x4C\x6F\x61&quot; &quot;\x64\x4C\x69\x62\x72\x61\x72\x79\x41\x00\x55\x53\x45\x52\x33&quot; &quot;\x32\x2E\x44\x4C\x4C\x00\x4D\x65\x73\x73\x61\x67\x65\x42\x6F&quot; &quot;\x78\x41\x00\x48\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C\x64\x00&quot; &quot;\x4D\x65\x73\x73\x61\x67\x65\x00\x45\x78\x69\x74\x50\x72\x6F&quot; &quot;\x63\x65\x73\x73\x00\x48\x83\xEC\x28\x65\x4C\x8B\x04\x25\x60&quot; &quot;\x00\x00\x00\x4D\x8B\x40\x18\x4D\x8D\x60\x10\x4D\x8B\x04\x24&quot; &quot;\xFC\x49\x8B\x78\x60\x48\x8B\xF1\xAC\x84\xC0\x74\x26\x8A\x27&quot; &quot;\x80\xFC\x61\x7C\x03\x80\xEC\x20\x3A\xE0\x75\x08\x48\xFF\xC7&quot; &quot;\x48\xFF\xC7\xEB\xE5\x4D\x8B\x00\x4D\x3B\xC4\x75\xD6\x48\x33&quot; &quot;\xC0\xE9\xA7\x00\x00\x00\x49\x8B\x58\x30\x44\x8B\x4B\x3C\x4C&quot; &quot;\x03\xCB\x49\x81\xC1\x88\x00\x00\x00\x45\x8B\x29\x4D\x85\xED&quot; &quot;\x75\x08\x48\x33\xC0\xE9\x85\x00\x00\x00\x4E\x8D\x04\x2B\x45&quot; &quot;\x8B\x71\x04\x4D\x03\xF5\x41\x8B\x48\x18\x45\x8B\x50\x20\x4C&quot; &quot;\x03\xD3\xFF\xC9\x4D\x8D\x0C\x8A\x41\x8B\x39\x48\x03\xFB\x48&quot; &quot;\x8B\xF2\xA6\x75\x08\x8A\x06\x84\xC0\x74\x09\xEB\xF5\xE2\xE6&quot; &quot;\x48\x33\xC0\xEB\x4E\x45\x8B\x48\x24\x4C\x03\xCB\x66\x41\x8B&quot; &quot;\x0C\x49\x45\x8B\x48\x1C\x4C\x03\xCB\x41\x8B\x04\x89\x49\x3B&quot; &quot;\xC5\x7C\x2F\x49\x3B\xC6\x73\x2A\x48\x8D\x34\x18\x48\x8D\x7C&quot; &quot;\x24\x30\x4C\x8B\xE7\xA4\x80\x3E\x2E\x75\xFA\xA4\xC7\x07\x44&quot; &quot;\x4C\x4C\x00\x49\x8B\xCC\x41\xFF\xD7\x49\x8B\xCC\x48\x8B\xD6&quot; &quot;\xE9\x14\xFF\xFF\xFF\x48\x03\xC3\x48\x83\xC4\x28\xC3&quot;; </code></pre> <p>This shellcode is then written into process memory and executed.</p> <p>How do I convert the shellcode into something to where I can load it into Ghidra? Everything I read online says &quot;Open the shellcode in a disassembler&quot;, but the disassembler doesn't recognize it as a valid program if I just save the data to a file. What do I need to do to see what this shellcode actually does?</p>
How to load shellcode into Ghidra
|ghidra|shellcode|
<p>that is a negative number</p> <pre><code>C:\&gt;python -c &quot;print(hex(0xffff98b4-2**32))&quot; -0x674c </code></pre> <p>or in other words</p> <pre><code>C:\&gt;python -c &quot;print(hex(2**32 - 0x674c))&quot; 0xffff98b4 </code></pre>
29875
2022-01-14T22:10:06.613
<p>I'm currently reverse-engineering an old game from 2003 to extend its functionality. I have now found what I am looking for and since it was written in C++ I'm trying to re-create the used classes. I have found the constructor call for an important class and now need to know how large it is in memory (since Ghidra tries to set the struct size way too small so I get weird things like accessing fields at this[6]). However, before the call to the constructor is made, no memory is allocated, rather the instruction <code>LEA ECX,[EBP + 0xffff98b4]</code> is executed (where ECX will be the 'this' pointer in the constructor). I don't expect that the explanation of what adding a huge value to EBP actually does would help me in finding out how large the object is, however it has intrigued me enough to wanting to know what it actually does, I hope someone can help</p>
Understanding the meaning of EBP + 0xffff98b4
|disassembly|windows|x86|c++|ghidra|
<p>To accomplish this you first need to create or find a code cave and insert your code then jump back to where you were.</p> <p>I'm going to put an example here. I'm not familiar with PE files, but I will do an example of ARMv7 and ELF.</p> <pre><code>0xc8 movs r0, r1 0xca b 0xd8 0xcc b nowhere 0xd8 0000 empty bytes to 0xff 0x100 mov r3, r4 </code></pre> <p>From above if I write an instruction(s) from address <code>0xd8</code> all will be executed until I branch back to <code>0xcc</code>. In ELF, you will need to edit the program headers and change the flags to executable, so all can be possible or just use a code cave in which program headers are executable. Inserting bytes changes offsets, and it's possible the program won't have an entry point. Overwriting works most of the time if what you're patching is simple and needs only a few instructions.</p>
29878
2022-01-16T02:45:06.637
<p>I am learning reverse engineering tools.<br /> I notice that when you need to patch some file (at least in visual mode) you need to overwrite instructions, i.e. when using <kbd>Shift</kbd>+<kbd>A</kbd> in visual mode or <kbd>I</kbd> in visual mode.</p> <p>Is there a way to insert asm code without the need to overwrite some other?</p>
How to insert asm code in file without overwriting in Radare2
|radare2|
<p>Use <a href="https://hex-rays.com/products/ida/support/idadoc/1518.shtml" rel="nofollow noreferrer">Locals View</a> in Debugger⇾Debugger Windows⇾Locals window.</p>
29886
2022-01-18T10:57:23.863
<p>In IDA Pro, when you create a custom struct, apply it to a local variable, and try to check every member of it in the decompiler mode, when you hover your mouse on the variable, it only prints limited number of values of struct members based on the screen size, so the rest of them go out of screen:</p> <p><a href="https://i.stack.imgur.com/GewoB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GewoB.png" alt="enter image description here" /></a></p> <p>How can I view the value of every member of the struct then? When I hover to <code>field_38</code> for example, it just prints its offset and doesn't tell me its value.</p> <p>Using IDA Pro 7.6.</p>
How to print the value for every member of a custom struct in IDA Pro? (In Decompiler mode the members go off screen)
|ida|idapython|
<p>in r2 there's the concept of 'flags' which is basically a way to associate a name to a number.</p> <p>So in that case you do:</p> <pre><code>f test = 0x100 px test </code></pre>
29888
2022-01-18T12:11:37.040
<p>gdb allows setting arbitrary convenience variables:</p> <pre><code>set $a = &quot;test&quot; set $b = 3 p $a # =&gt; &quot;test&quot; p $b # =&gt; 3 </code></pre> <p>Is there a way to do something similar in radare2? I'd like to be able to e.g.:</p> <pre><code>set $len = 0x100 px `$len` # =&gt; does px 0x100 echo $len # =&gt; echos 0x100 </code></pre>
radare2 convenience variables
|radare2|
<p>You can always set it manually to the specific address from the reference dialog (available under <kbd>R</kbd>). There you can providing the correct address calculated by adding <code>base address</code> and an <code>offset</code>. If you have more than one, you can automate it via <code>python</code> script.</p> <p>I've recorded a video detailing such situation in action <a href="https://www.youtube.com/watch?v=FvH7b_qLmbU" rel="nofollow noreferrer">https://www.youtube.com/watch?v=FvH7b_qLmbU</a></p>
29914
2022-01-23T23:51:58.023
<p>A jump table I am reversing uses relative offsets to both data and functions. These relative offsets are 32-bit integers added to the address that the value is stored at. Does Ghidra support typing these as relative addresses for generating references (like how you can type a value as an absolute address by pressing <kbd>P</kbd>)?</p> <p>For example:</p> <pre><code> INT_00010f00 00010f00 49 ff ff ff int FFFFFF49h </code></pre> <p>Is actually a reference to <code>0x00010f00 + 0xffffff49 = 0x00010e49</code></p>
How to type data as a relative address in Ghidra?
|ghidra|
<p>In short, the PE loader does not explicitly load up the certificate details into the new process at run-time.</p> <p>In the binary, the certificates are referenced via the IMAGE_DIRECTORY_ENTRY_SECURITY directory; but they are not in a section that is mapped into virtual memory. The data is instead appended to the file.</p> <p>You might get lucky and find the cert data has been mapped via a memory mapped file, or if you captured a full kernel dump you might have a copy of it. Otherwise you will have to try and source the file from the computer.</p> <p>Your best bet is to manually compare the code-in-memory to a valid copy of googleupdate.</p> <p>Also keep in mind that the source binary could be completely valid, but the behavior changed at run-time (via code injection, etc.). So even if you could easily validate the integrity of the certificate, it wouldn't detect rogue threads, hooked functions, etc.</p>
29915
2022-01-24T09:30:35.477
<p>I have a <code>.dmp</code> file for <code>googleupdate.exe</code> process. I wanted to check in WinDbg this process has a certificate or not in order to detect this process has modified or not because this process has tried access <code>lsass.exe</code> multiple time.</p> <p>How can I check the integrity and also maliciousness of this process in WinDbg? I have just a memory dump from that process and nothing more. I should check it in WinDbg.</p>
Extract certificate information of a process from memory dump
|memory|memory-dump|digital-forensics|
<p>In order to &quot;extract&quot; (the specific) data from another process you need the correct memory address(es) and preferably it's datatype(s) and size of the datatype. (e.g. signed/unsigned int at location 0x[....])</p> <p>You should also consider (depending on the datatype and algorithm), that such addresses can change during runtime (and/or upon starting your program)</p> <p>Some addresses and their (context) values are fixed, and can always reside on the same location in memory. (e.g. mapping, declared constants, etc.) (However a new build/patch of the program can change such addresses)</p> <p>Be careful of possible pointers that you need to follow, until you got the final address where the value resides.</p> <p>Some addresses may also be inaccessible, invalid or restricted to read from. (Depending on OS, etc.) (e.g. this might be the case if it's a java process or differences between x86 and x86_64 processes)</p> <p>You don't need to inject a DLL in order to just read data from a foreign process.</p> <p>Injecting a DLL is primarily used to execute (your) code in that process' space, which includes handles, etc.</p> <p>Please be careful if you intent to (over)write values in foreign processes. This can be detected and might crash/damage processes/files if not careful.</p> <p>For now, without much effort and hassle, I recommend using CheatEngine to learn and get the right &quot;base address&quot; for your desired value. (Careful: CheatEngine might inject in foreign processes and might be detected)</p> <p>Infos and how to:</p> <p><a href="https://en.wikipedia.org/wiki/Cheat_Engine" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Cheat_Engine</a></p> <p><a href="https://www.wikihow.com/Use-Cheat-Engine" rel="nofollow noreferrer">https://www.wikihow.com/Use-Cheat-Engine</a></p> <p>If you keep learning memory structure, mapping, PE header, etc. you will be able find a way to automate the process of getting the right base address upon each start. (until a new build/patch has been made)</p>
29917
2022-01-24T11:23:01.497
<p>I'm totally new to this reverse engineering stuff.</p> <p>I'm working on my own project and trying to parse poker games from PokerStars application. I have already done with injecting my DLL to the app, but I don't know what to do next.</p> <p>I got module base address, created a hexdump function, and tried to go along process virtual memory, but it takes enormous amount of time. For now, I only found a region of memory where some source code is located. I've seen on GitHub project of PokerStars bot, so I know that it's possible to find in memory data I need, but I really don't know how. Can you give me advice?</p> <p>Also, the game is open in another window, so I suppose the main program creates another thread for it. So how can I find the base address of this thread?</p>
How to extract specific data from memory
|memory|dll-injection|
<p>should be some thing like this compiles fine in <a href="https://godbolt.org/z/bzEofj5n5" rel="nofollow noreferrer">godbolt.org</a></p> <pre><code>#include &lt;fcntl.h&gt; int main (void) { open( &quot;foo&quot;, //1 | 0x200 | 0x800 O_WRONLY | O_TRUNC | O_NONBLOCK, //0x100 | 0x80 | 0x40 | 0x20 | 0x4 | 0x2 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH ); } </code></pre> <p>disassembled</p> <pre><code>main: push rbp mov rbp,rsp mov edx,0x1b6 mov esi,0xa01 mov edi,0x402004 mov eax,0x0 call 401030 &lt;open@plt&gt; mov eax,0x0 pop rbp ret </code></pre>
29936
2022-01-26T15:17:36.347
<p>The arguments being passed to the open syscall at runtime in a program I'm debugging seem to be as follows:</p> <pre><code>open(&quot;SOMESTRING&quot;, 0xa01, 0x1b6); </code></pre> <p>These were retrieved using lldb on OSX 12.1 Monterey by setting a breakpoint at the open syscall and then printing out the args like this:</p> <pre><code>(lldb) x/s $rdi 0x6000022b4150: &quot;SOMESTRING&quot; (lldb) p/x $rsi (unsigned long) $5 = 0x0000000000000a01 (lldb) p/x $rdx (unsigned long) $6 = 0x00000000000001b6 </code></pre> <p>Using 'man 2 open', I'm reading a description of the arguments and then I'm going to the appropriate header files to check the hex value of each flag to try to determine what the parameters mean. The problem is, nothing seems to be matching up.</p> <p>From the open manpage:</p> <pre><code> The flags specified for the oflag argument must include exactly one of the following file access modes: O_RDONLY open for reading only O_WRONLY open for writing only O_RDWR open for reading and writing In addition any combination of the following values can be or'ed in oflag: O_NONBLOCK do not block on open or for data to become available O_APPEND append on each write O_CREAT create file if it does not exist O_TRUNC truncate size to 0 O_EXCL error if O_CREAT and the file exists O_SHLOCK atomically obtain a shared lock O_EXLOCK atomically obtain an exclusive lock O_DIRECTORY restrict open to a directory O_NOFOLLOW do not follow symlinks O_SYMLINK allow open of symlinks O_EVTONLY descriptor requested for event notifications only O_CLOEXEC mark as close-on-exec O_NOFOLLOW_ANY do not follow symlinks in the entire path. </code></pre> <p>Now when I head over to fcntl.h, and look at the value for these flags, none of them have the hex value 0xa00. I'm failing to see how OR'ing any of these flags together would ever reproduce a value of 0xa01. I'm having similar trouble with the mode arg. Could anyone help me understand what I'm doing wrong?</p>
Retrieving args from open syscall
|arguments|syscall|
<p>Apparently I was confused over the articles wording due to initially seeing deletion destructors as virtual destructors. I analyzed a small scratchpad program and realized the following:</p> <ul> <li>Deletion destructors (in PDBs referred to as &quot;scalar deleting destructor&quot;) are generated whenever I call <code>delete</code> on an object with a destructor, <strong>no matter if it is virtual or not</strong>. It's practically there to ensure to call the user destructor code and then actually free the memory.</li> <li>Only as soon as I make the destructor virtual (or declare another method virtual), MSVC <em>always</em> generates a vftable (what else?).</li> </ul> <p>There are probably exceptions to these observations but so far I haven't seen them. Feel free to expand my knowledge here!</p>
29947
2022-01-28T17:35:08.753
<p>I'm reversing the following smart pointee-like MSVC <code>class Buffer : public Referencable</code> with IDA / Hexrays:</p> <pre><code>struct Referencable { int m_refs; }; struct Buffer : Referencable { void* m_pData; }; </code></pre> <p>This class apparently has no vftable, which I deduce from its (base) constructor not storing any vftable-like structure:</p> <pre><code>Buffer *__thiscall Buffer::ctor(Buffer *this) { Referencable::ctor(this); this-&gt;m_pData = NULL; return this; } Referencable *__thiscall Referencable::ctor(Referencable *this) { // &lt;-- no vftable assignment here or anywhere --&gt; this-&gt;m_refs = 0; return this; } </code></pre> <p>When this object is being deleted, I see the following method:</p> <pre><code>Buffer *__thiscall Buffer::ddtor(Buffer *this, char flags) { Buffer::dtor(this); if ( (flags &amp; 1) != 0 ) operator delete(this); return this; } void __thiscall Buffer::dtor(Buffer *this) { free(this-&gt;m_pData); Referencable::dtor(this); } void __thiscall Referencable::dtor(Referencable *this) { ; // nop } </code></pre> <p><sup>(I can assure that this is indeed the deletion method belonging to this class due to how the capturing smart pointer calls it)</sup></p> <p>According to igorsk's <a href="http://www.openrce.org/articles/full_view/23" rel="nofollow noreferrer">Reversing Microsoft Visual C++ Part II: Classes, Methods and RTTI</a> article, <code>Buffer::ddtor</code> seems to be a deletion destructor, which however are only available to classes with <em>virtual destructors</em>:</p> <blockquote> <ol start="6"> <li>Deleting Destructors</li> </ol> <p><strong>When class has a virtual destructor, compiler generates a helper function - deleting destructor</strong>. Its purpose is to make sure that a proper _operator delete_ gets called when destructing a class. Pseudo-code for a deleting destructor looks like following:</p> <pre><code>virtual void * A::'scalar deleting destructor'(uint flags) { this-&gt;~A(); if (flags&amp;1) A::operator delete(this); }; </code></pre> </blockquote> <p>Thus my class seems to contradict another statement in that article, mentioning a virtual deletion destructor call which does not exist in my assembly (the deletion destructor above is called directly by the smart pointer logic):</p> <blockquote> <p>If A's destructor is virtual, it's invoked virtually:</p> <pre><code>mov ecx, pA push 3 mov eax, [ecx] ;fetch vtable pointer // &lt;-- what vftable? I have none! call [eax] ;call deleting destructor </code></pre> </blockquote> <p>Now I am a little confused.</p> <ul> <li>Does this class have a virtual destructor now or not?</li> <li>Is it possible for a deletion destructor to be generated even if I do not have a virtual destructor, and what are the requirements?</li> <li>Or is this what is <em>always</em> generated when I call <code>delete</code> on <em>anything</em> and I simply misunderstood the article?</li> <li>If it helps clearing my confusion, what is the exact difference between a deletion destructor and virtual destructor anyway?</li> </ul> <p>On a postscriptum note I know this assembly quite well otherwise and never noticed <em>any</em> kind of code optimizations (lucky me); I wonder how a vftable could've been optimized out anyway.</p>
Can a MSVC class have a deletion destructor without a vftable?
|c++|hexrays|msvc|virtual-functions|
<p>That function was renamed from <code>bool remove_empty_blocks(void)</code> to <code>bool remove_empty_and_unreachable_blocks(void)</code> as of Hex-Rays 7.6. Just change the name of the function you're trying to call.</p>
29959
2022-01-31T09:51:24.590
<p>i have a c++ module that removes empty block it used to work well but now I'm porting it to ida 7.7 I'm having issues.</p> <pre><code>mba_t *mba; mba-&gt;remove_empty_blocks(); </code></pre> <p><strong>It throws following error</strong></p> <pre><code>&quot;remove_empty_blocks&quot; is not a member of 'mba_t' </code></pre> <p>Even if it's deprecated what can be a possible solution to this, or i just ignore it ?</p>
Removing empty blocks ida api
|c++|hexrays|ida-plugin|idapro-sdk|
<p>Seems like i found it out. They abuse the 11-Pin Samsung MHL Adapter.</p>
29966
2022-02-01T22:46:21.547
<p>While reversing a Sena Bluetooth Headset i noticed that the programming port of the internal chip is routed out to 6 additional undocumented Pins inside of the Micro-USB connector. Whats the best method for connecting to that without opening up the headset each time?</p> <p><a href="https://i.stack.imgur.com/5YoBN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5YoBN.jpg" alt="Unknown Connector" /></a></p> <p>Added a sketch of the location of the pins <a href="https://i.stack.imgur.com/P3cO9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P3cO9.png" alt="Paint sketch of the connector" /></a></p> <p>Addendum: With some lighting around inside i noticed that the connectors are on a step at the back (upper red line shows the location of those 6 pins) <a href="https://i.stack.imgur.com/W9WNM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W9WNM.png" alt="Side view sketch" /></a></p>
Unknown proprietary Micro-USB variant
|hardware|
<blockquote> <p>Why is there 2 places for structures in IDA: Local Types and Structures?</p> </blockquote> <p>I randomly stumbled upon an answer in the product's help documentation: <a href="https://www.hex-rays.com/products/ida/support/idadoc/1042.shtml" rel="nofollow noreferrer">https://www.hex-rays.com/products/ida/support/idadoc/1042.shtml</a></p> <p>Apparently, it's assembly-level and C-level types.</p> <blockquote> <p>What are Local Types local to?</p> </blockquote> <p>The local types are types local to the current(local) type info library, which is the main and only type info library for the database, as I understand.</p> <blockquote> <p>Why do I have to synchronize a type in the Local Types window to the idb in order to edit it?</p> </blockquote> <p>Well, apparently, I don't have to, and I can edit Local Types if I press right mouse button on the type and choose <code>Edit...</code> option.</p> <blockquote> <p>Isn't it already in the database? It is certainly in the .idb database, isn't it?</p> </blockquote> <p>It is.</p> <blockquote> <p>When I dump typeinfo to the .idc file(<code>File &gt; Produce File &gt; Dump typeinfo to IDC File...</code>) and then import it in the same or another database, why instead of importing defined Local Types to the Local Types window and defined structures in the Structures window to the Structures, it imports everything to both places?</p> </blockquote> <p>Because it's doing it wrong: it takes Structures and Local Types and creates an .idc script that imports all types as assembly-level structures, instead of doing it properly: port assembly-level structures(Structures) as assembly-level structures and port C-level structures(Local Types) as C-level strutrures.</p>
29971
2022-02-02T20:36:38.717
<p>Why is there 2 places for structures in IDA: Local Types and Structures?</p> <p>What are Local Types local to?</p> <p>Why do I have to synchronize a type in the Local Types window to the idb in order to edit it? Isn't it already in the database? It is certainly in the .idb database, isn't it?</p> <p>When I dump typeinfo to the .idc file(<code>File &gt; Produce File &gt; Dump typeinfo to IDC File...</code>) and then import it in the same or another database, why instead of importing defined Local Types to the Local Types window and defined structures in the Structures window to the Structures, it imports everything to both places?</p>
What is the point to have 2 different places for structures: Local Types and Structures in IDA?
|ida|
<p><code>ObjC.classes.TestClass</code> is just a shorthand in JavaScript for <code>ObjC.classes['TestClass']</code>.</p> <p>Therefore you should be able to access an <code>Test.Class</code> instance this way:</p> <pre><code>var instance = ObjC.chooseSync(ObjC.classes['Test.Class'])[0]; </code></pre>
29978
2022-02-03T23:24:19.110
<p>I am trying to create an instance of a class of an iOS app using Frida.</p> <p>In the past I have successfully done this using a command such as:</p> <pre><code>var instance = ObjC.chooseSync(ObjC.classes.TestClass)[0]; </code></pre> <p>However, in this instance, the class that I would like to create an instance of has a <code>.</code> in the name so if I try the same command as above I understandably get an error:</p> <pre><code>var instance = ObjC.chooseSync(ObjC.classes.Test.Class)[0]; SyntaxError: expecting field name </code></pre> <p>I had identified the class from the output of:</p> <pre><code>Object.keys(ObjC.classes).filter(function(m){ return m.toLowerCase().includes(&quot;test&quot;) }); </code></pre> <p>The output of this lists a number of classes, all of which are either mangled Swift names, or have a <code>.</code> in them so I'm not sure if I simply don't understood a concept here about how Frida handles class names in a Swift and Objective-C app, or there is something I've missed in attempting to create the instance.</p>
Create instance of iOS class that contains a . with frida
|ios|frida|hooking|
<p>One way that should work is using the &quot;Capture Function Prototypes&quot; context menu action on the Project Datatype Archive while in the binary that defines those functions, then applying them in the binary that imports them.</p>
29994
2022-02-06T17:10:59.940
<p>I have imported several programs to my Ghidra project and retyped a few function parameters in one of them.</p> <p>Now I am working on a different program, which imports these functions. However, the imported functions still have their original, unmodified signatures.</p> <p>How do I tell Ghidra to propagate the changes?</p>
How do I make Ghidra propagate modified functon signatures to other programs in that project?
|ghidra|
<p>Use <code>set_database_flag(DBFL_KILL)</code></p>
30007
2022-02-08T02:49:57.530
<p>In my work, I often end up with lots of IDA windows open concurrently. Once done with analysis, I would like to close them all. It is relatively easy to issue a command to all of them simultaneously e.g. using a bridge. My problems come about when trying to close all of them without saving changes (e.g. if I ran some scripts on all of the IDA tasks and messed up).</p> <p>Unfortunately, <code>qexit</code> saves all changes made. Sending a kill command does prevent saving, but risks corruption. I'm left to close all of the processes one by one from the UI, which is tedious (click X, click don't save, click ok, repeat). Is there a better way (short of an autoclicker) to accomplish this?</p>
IDA: close without saving changes
|ida|idapython|
<p><a href="https://github.com/igogo-x86/HexRaysPyTools" rel="nofollow noreferrer">HexRaysPyTools</a> has this feature, which it calls &quot;recasting&quot; (<code>SHIFT-L</code>, <code>SHIFT-R</code>). It's generally an excellent piece of software and I recommend it.</p>
30029
2022-02-12T11:10:53.017
<p>Let's say I have this code in the decompiler of IDA pro:</p> <pre><code>var1 = var2; </code></pre> <p>And assume the type of <code>var1</code> is <code>X</code> (for example <code>X</code> could be char array with size 5). Is there anyway that I can tell IDA that whenever you see such assignments, change the type of <code>var2</code> to <code>X</code> as well?</p> <p>Considering that <code>var1</code> is type <code>X</code>, then obviously <code>var2</code> should be type <code>X</code> as well, but right now I have to manually change the type every time… The problem is this is happening inside a large function thousands of times and I can't manually change every time, I need to somehow force IDA to do it. But how?</p>
Automatically propagate types in IDA pro when variables are assigned?
|ida|idapython|
<p>Reading @peter_ferrie's answer, this sounds a lot like the proxy DLL that I made once, so I'll add some details as to how I went about it.</p> <p>I'll continue the naming scheme from peter's answer, so Z.DLL is the renamed original and A.DLL is your DLL (with Z.DLLs original name).</p> <p>First, I ran <code>dumpbin /EXPORTS</code> on the Z.DLL, resulting in a list of all exports of that DLL. I then wrote a script that took the list and generated a header file that contained one statement like this for each function Z.DLL exported:</p> <pre><code>#pragma comment(linker, &quot;/export:[mangled_func_name]=[Z.DLL_name].[mangled_func],@[func_ordinal]&quot;) </code></pre> <p>These need to be mangled names, and the field [Z.DLL_name] shouldn't contain the file extension!</p> <p>You should now be able to <code>include</code> this header in your DLL and compile it. Put your A.DLL in the program's directory and you now have an &quot;empty&quot; proxy DLL. It only forwards the function calls through your A.DLL to the original Z.DLL for now though, which is thw work of these <code>pragma</code>s.</p> <p>To do something interesting, you need to</p> <ol> <li>find the mangled name of the function you want to replace</li> <li>run it through <code>undname</code> to get the unmangled signature</li> <li>add a function with that signature to your A.DLL</li> <li>mark your function to be exported using e.g. <code>__declspec(dllexport)</code></li> <li>delete the corresponding <code>#pragma</code> in your header</li> </ol> <p>Voilà! The program now calls your custom function in A.DLL while everything else is passed to Z.DLL.</p> <p>If you need to call the original function, you should be able to do that using <code>LoadLibrary</code> and <code>GetProcAddress</code>, but I haven't done this before.</p>
30032
2022-02-12T19:23:26.287
<p>I'm working with 2 third party DLLs (let's A.dll and B.dll), which I don't have the source code, only the compiled DLL. I know A.dll uses the main function from B.dll, and they both works perfectly. However, I need to do some other stuff, so I wrote my own DLL (let's call C.dll) and added its funtions to A.dll import table.</p> <p>Now I need A.dll to call these functions, just like it does evoking B.dll function.</p> <p>I used CFF Explorer to add C.dll functions as import to A.dll, but my functions are not being executed. I need this to be done this way, since the main .exe file (which I don't have the source code aswell) will call A.dll on startup.</p> <p>Thanks for help! :)</p>
HEX code to call DLL function
|patch-reversing|hex|assembly|
<p>Right-click in the strings window, choose &quot;Setup&quot;, and ensure that, under &quot;Allowed string types&quot;, &quot;Unicode C-style (16 bits)&quot; is enabled:</p> <p><a href="https://i.stack.imgur.com/2mM6w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2mM6w.png" alt="enter image description here" /></a></p>
30040
2022-02-13T17:04:45.473
<p>I was looking for a spcific string in IDA, but there were no hits in the &quot;string view&quot;. Now after browsing the disassembly for a while I realize that not only does the string exist, IDA did in fact find this string. It was referenced by assembly code, IDA prints it as a comment next to the assembly, even the location of the string is named with the first characters of the string!</p> <p>Very annoying! How come it is not listed in the string view, then? How would I go about finding referenced text strings by string?</p> <p>edit: an example:</p> <pre><code>and [rsp+18h+var_10], 0 lea rax, aSettextfromsrc ; &quot;settextfromsrc&quot; mov [rsp+18h+var_18], rax mov r9, [rsp+18h+var_1A] ... text &quot;UTF-16LE&quot;, 'settextfromsrc',0 </code></pre> <p>maybe bc of the UTF-16LE?</p>
IDA: String referenced in Assembly, but not shown in string view
|ida|strings|
<p>They are <em>encoded character strings</em> in the form of <em>byte streams</em>.</p> <p>But before encoded, they are highly likely somehow obfuscated or <strong>encrypted</strong> – and this is the main problem.</p> <p>The <em>decoding</em> itself is not a such problem – you need to know how they are encoded, or try different encoders one after other (in spite there are <a href="https://docs.python.org/3.10/library/codecs.html#standard-encodings" rel="nofollow noreferrer">many tens of them</a> as <code>big5</code>, <code>cp273</code>, <code>iso-8859-5</code>, <code>gb18030-2000</code> – but some of them are only for specific natural language / languages).</p> <p>If you know the encoder (or at least the natural language of your game to limit the set of possible encoders), you may decode it, e.g. in Python, as I will show you:</p> <p>Preparation:<br /> I will encode a string (in Python) to receive a byte stream similar to yours:</p> <pre><code>&gt;&gt;&gt; &quot;Ľαaβ4γ•a∞&quot;.encode(&quot;utf-8&quot;) b'\xc4\xbd\xce\xb1a\xce\xb24\xce\xb3\xe2\x80\xa2a\xe2\x88\x9e' </code></pre> <p>Note the notation - the letter <code>b</code> (for byte sequence) immediately followed by the encoded string in apostrophes (quotes are good, too).</p> <p><strong>Proper decoding:</strong></p> <pre><code>&gt;&gt;&gt; b'\xc4\xbd\xce\xb1a\xce\xb24\xce\xb3\xe2\x80\xa2a\xe2\x88\x9e'.decode(&quot;utf-8&quot;) 'Ľαaβ4γ•a∞' </code></pre> <p>Particularly, for the value <code>&quot;\xE5\u007Fe\u0001\xF7\xFCC\x87\xF0xK\xF7&quot;</code> of your key <code>f05</code> (don't forget to put <code>b</code> at the beginning):</p> <pre><code>&gt;&gt;&gt; b&quot;\xE5\u007Fe\u0001\xF7\xFCC\x87\xF0xK\xF7&quot;.decode (&quot;utf-8&quot;) Traceback (most recent call last): File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt; UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position 0: invalid continuation byte </code></pre> <p>So it is definitely NOT encoded as <code>utf-8</code>.</p> <p>You may try other decoders from <a href="https://docs.python.org/3.10/library/codecs.html#standard-encodings" rel="nofollow noreferrer">this table</a>, e.g. <code>unicode_escape</code>:</p> <pre><code>&gt;&gt;&gt; b&quot;\xE5\u007Fe\u0001\xF7\xFCC\x87\xF0xK\xF7&quot;.decode (&quot;unicode_escape&quot;) 'å\x7fe\x01÷üC\x87ðxK÷' </code></pre> <p>It is better, but – as I already wrote – you will never obtain directly the string <code>&quot;serif&quot;</code>, because it is in the encrypted form. You have in addition to <strong>decrypt</strong> the result of decoding, but it is impossible without knowledge of the encryption schema and a decryption key.</p>
30043
2022-02-13T19:13:52.350
<p>I extracted a game file, which is in JSON format, it's a bit too long, so I'll omit parts of it:</p> <pre><code>{name: &quot;\xEE\xB5k~u\u03D7\x80\xF8\xE0\xE2\xC5\xCA\xEE\u04CF\x90\xBE\xD8Cs\xFE\xA5Ec\u007F\u0006\x85\xA2\xB2\xD87&quot;, f03: 2, f04: 300, f05: &quot;\xE5\u007Fe\u0001\xF7\xFCC\x87\xF0xK\xF7&quot;, desc: &quot;l8\x88\xF6\xCE\u0012\xC8-8g&gt;{\xE6&amp;\xAB\u03E4f\x8C\u0012\xDD/\x81\x91\xF7\u007F\xD2\u0019\u000E\x87\xF7\xF07Ek\xFC\xCEtU\u0002\x9F@eJ\xB0\xFA\x93\xA8&gt;5\x9BK\xAF\xE0\u001D\xA1\u0006\xE8\u001D.r\xF5\u041F\u05CB1\xF5J\u000F\&quot;\xC6\u001B4\xB7\u0000\x97o\xA4&gt;\u00158q\xE4\x9B\xE2z51N\fe{\xECV\u0011\xAE']|#X'\b\xCE\u0005\xEEg\xC3\uFE9Be\u0018\xC0\xDE\u0006&gt;;\u0002\xFB\u0002;j\xC4{\xE9\u0013P\xE8a\xC9C\x8B\xE65\x87\u063Ac(o\xB1\xD9\xF4\xAF\xC0_D\u001B\xE7\u0013n\u0306\x81\xD9W\xA8\xC9:\x96\x93\xC7\u0006\u0014\xA8\x8E\xC0\x96*q\u000E&lt;\xC1\xA1\u0005\xC6\xD9\xE5\u0007(t;\x92\x8B^\x91c\xFB=l&quot;} </code></pre> <p>I'm having trouble how to make sense of <code>name</code>, <code>f05</code> and <code>desc</code> fields, no idea how to decode them. It seems like a mix of hex and Unicode.</p> <p>The game is able to convert them into readable format, so there must be some way to decode them.</p> <p>For reference, the <code>name</code> string translates to <code>'[A Duty to Honor]' Kirito</code>, and <code>f05</code> is for <code>serif</code>.</p> <p>If anyone can tell me on how to decode this, it'll be appreciated.</p>
Making sense of an encoded JSON string
|disassembly|file-format|hex|
<p>Short story: you can't without context.</p> <p>In memory, everything is data, and your registers will always be populated with data.</p> <p>Sometime, you can <strong>guess</strong> the data type (a small integer, some characters or a string), but you don't know for sure. Is &quot;\x42\x43&quot; the string &quot;BC&quot; ? Is it a handler on something ? Is it the &quot;16963&quot; integer value ? Is it used as a single byte (so you don't care about &quot;\x43&quot;) ? Nobody known without the context where you found this value.</p> <p>You may also see that a data may be in a specific range, and you can make a guess about its type. For instance, something in the memory range of a buffer that you previously saw may be a pointer. But once again, you don't know what this pointer represents.</p> <p><strong>The goal of reverse engineering is to trace back those values from where they were instantiated</strong>, and it will become easier :)</p> <p>Maybe this register hold the address of a buffer. Maybe it holds an error code. Maybe it holds an old data that was here, and a part of the register (let's say the lower 16 bits) contains an important value.</p> <p>Opening your target binary in a disassembler (like IDA) would probably help you, as the tool may type some variables for you, saving some time.</p> <p>In your case, try to trace back where this argument is being instantiated, it will become clearer :)</p>
30077
2022-02-23T18:33:56.693
<p>I'm learning reverse engineering and I'm trying to understand what process people use to identify a variable type.</p> <p>For example, I'm looking at an argument being passed to a function and I'm trying to understand what it is. This application uses Objective-C. This parameter could be an NSString, it could be a pointer to some struct, it could be anything, right? Printing it out shows this:</p> <pre><code>(lldb) po $rsi 140732653141208 </code></pre> <p>How do I find out what it is? I understand there is probably no perfect formula to definitely know what this represents, but is there some process that a more experienced person would use to try to decipher what this represents?</p> <p>I'm currently just trying every format and hoping something catches my eye.</p> <pre><code>(lldb) p/x $rsi (lldb) p/s $rsi (lldb) x/x $rsi (lldb) x/s $rsi </code></pre> <p>Could someone walk me through what they do or point me to some resources? This is specifically for lldb.</p>
How to determine the data type of a register
|debugging|osx|lldb|arguments|
<p>KiSwapContext is not an exported function, so the mapping between its address and its name is only available either through your own manual guesswork or the PDB (which contains debug symbols).</p> <p>You may have had a transient issue loading the PDB file from Microsoft's Symbol Server (which provides symbols over the public Internet); without knowing exactly which mismatched PDB file you did have, and what choices you made on those dialog boxes, it's not 100% clear what went wrong.</p> <p>Microsoft patching Windows <em>does</em> cause the symbol table and PDB to change as updates do change the layout of functions, exact addresses, etc., but the PDB's metadata (signature and age) should catch the issue of a PDB for a different version of the binary than the one you have (as they seem to have done here).</p>
30085
2022-02-26T01:15:40.557
<p>I'm just having some fun learning <strong>IDA 7.7 Free</strong> and how context switching works both on <strong>Windows 8.1</strong>. I've loaded <code>ntoskrnl.exe</code> into IDA, but I cannot find the following two functions names or symbols: <code>KiSwapContext</code> and <code>SwapContext</code>. I've included the screenshots on loading ntoskrnl.exe and the output details as follows:</p> <p><a href="https://i.stack.imgur.com/o4PN3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o4PN3.png" alt="enter image description here" /></a> <a href="https://i.stack.imgur.com/4VdPR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4VdPR.png" alt="enter image description here" /></a> <a href="https://i.stack.imgur.com/2edXK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2edXK.png" alt="enter image description here" /></a></p> <pre><code>&gt; Possible file format: Portable executable for AMD64 (PE) (C:\Program Files\IDA Freeware 7.7\loaders\pe64.dll) &gt; &gt; bytes pages size description &gt; --------- ----- ---- -------------------------------------------- 29450240 3595 8192 allocating memory for b-tree... 29450240 3595 &gt; 8192 allocating memory for virtual array... 262144 32 8192 &gt; allocating memory for name pointers... &gt; ----------------------------------------------------------------- 59162624 total memory allocated &gt; &gt; Loading processor module C:\Program Files\IDA Freeware &gt; 7.7\procs\pc64.dll for metapc...Initializing processor module metapc...OK Autoanalysis subsystem has been initialized. Loading file &gt; 'C:\Users\AUSER\Documents\Visual Studio 2019\Reversing\ntoskrnl.exe' &gt; into database... Detected file format: Portable executable for AMD64 &gt; (PE) &gt; 0. Creating a new segment (0000000140001000-0000000140289000) ... ... OK &gt; 1. Creating a new segment (0000000140289000-000000014028C000) ... ... OK &gt; 2. Creating a new segment (000000014028C000-000000014028F000) ... ... OK &gt; 3. Creating a new segment (000000014028F000-0000000140290000) ... ... OK &gt; 4. Creating a new segment (0000000140290000-0000000140291000) ... ... OK &gt; 5. Creating a new segment (0000000140291000-0000000140305000) ... ... OK &gt; 6. Creating a new segment (0000000140305000-0000000140343000) ... ... OK &gt; 7. Creating a new segment (0000000140343000-0000000140346000) ... ... OK &gt; 8. Creating a new segment (0000000140346000-000000014034E000) ... ... OK &gt; 9. Creating a new segment (000000014034E000-0000000140361000) ... ... OK &gt; 10. Creating a new segment (0000000140361000-000000014037B000) ... ... OK &gt; 11. Creating a new segment (000000014037B000-0000000140658000) ... ... OK &gt; 12. Creating a new segment (0000000140658000-000000014065D000) ... ... OK &gt; 13. Creating a new segment (000000014065D000-0000000140685000) ... ... OK &gt; 14. Creating a new segment (0000000140685000-0000000140688000) ... ... OK &gt; 15. Creating a new segment (0000000140688000-000000014068F000) ... ... OK &gt; 16. Creating a new segment (000000014068F000-0000000140694000) ... ... OK &gt; 17. Creating a new segment (00000001406A8000-00000001406B7000) ... ... OK &gt; 18. Creating a new segment (00000001406B7000-00000001406C3000) ... ... OK &gt; 19. Creating a new segment (00000001406C3000-00000001406CE000) ... ... OK &gt; 20. Creating a new segment (00000001406CE000-0000000140747000) ... ... OK Reading exports directory... Reading imports directory... &gt; Applying fixups... &gt; 21. Creating a new segment (0000000140343728-0000000140346000) ... ... OK PDB: using PDBIDA provider Could not find PDB file &gt; 'ntkrnlmp.pdb'. Please check _NT_SYMBOL_PATH PDB: loading &gt; C:\symbols\ntkrnlmp.pdb\0E352AF38FB64A36AA56E6CC5CAD6C1A1\ntkrnlmp.pdb &gt; Assuming __fastcall calling convention by default PDB: loaded 2129 &gt; types 1400240EC: name has been deleted: NtCreateEnlistment 1400240F4: &gt; name has been deleted: NtCreateResourceManager PDB: total 21006 &gt; symbols loaded for &quot;C:\Users\AUSER\Documents\Visual Studio &gt; 2019\Reversing\ntoskrnl.exe&quot; Plan FLIRT signature: Windows Driver Kit &gt; 7/10 64bit Plugin &quot;eh_parse&quot; not found Marking typical code &gt; sequences... Flushing buffers, please wait...ok File &gt; 'C:\Users\AUSER\Documents\Visual Studio 2019\Reversing\ntoskrnl.exe' &gt; has been successfully loaded into the database. Hex-Rays Decompiler &gt; plugin has been loaded (v7.7.0.220118) License: 00-0000-0000-00 (0 &gt; user) The decompilation hotkey is F5. Please check the &gt; Edit/Plugins menu for more information. Using FLIRT signature: Windows &gt; Driver Kit 7/10 64bit Propagating type information... Function &gt; argument information has been propagated The initial autoanalysis has &gt; been finished. </code></pre> <p>[UPDATE] I did a clean install of Windows 8/8.1 on another computer installed IDA Free 7.7 and loaded ntoskrnl.exe into IDA. This time IDA was able to display both KiSwapContext and SwapContext functions very similar output as WinDbg. On the PC which is not displaying these two functions in IDA I tried uninstalling Norton Security but that didn't help. Doing a search for SwapContext in IDA displays the following two functions:</p> <p><strong>SwapContext_PatchStMxCsr and SwapContext_PatchLdt</strong></p> <p>Does anyone know why this is the case ? Could this be a windows update patch by Microsoft and the real SwapContext is hidden somewhere else ?</p>
When loading Ntoskrnl.exe in IDA Free (7.7) certain functions such as SwapContext are not displayed
|ida|
<p>argc is an argument to the function main()</p> <p>main is normally prototyped as</p> <p><code>int __cdecl main (int argc , char *argv[] )</code> when locale is not used</p> <p>argc is the number of arguments passed to main if you pass 5 arguments like<br /> <code>foo.exe 1 2 3 4 5</code></p> <p>then argc will be 6 ( 5 arguments (space delimited ) + 1 program )</p> <p>argv is a buffer that holds those arguments</p> <pre><code>argv[0]=&quot;foo.exe&quot;,argv[1]=&quot;1&quot;,argv[2]=&quot;2&quot;,argv[3]=&quot;3&quot;,argv[4]=&quot;4&quot;,argv[5]=&quot;5&quot; </code></pre> <p>each of these arguments are 8 byte long in a 64 bit program (size of pointer)</p> <p>mov [rbp+1c] , argc --&gt; saves the numebr of arguments<br /> cmp [rbp+1c] , 3 --&gt; checks if you passed 2 arguments (default progname + 2 args)<br /> if the jz jumps it reaches xxxxx6b5 to load the start of argv buffer</p> <p>skips the first member argv[0] by adding 8<br /> dereferences the second member argv<a href="https://en.wikipedia.org/wiki/X86_calling_conventions" rel="nofollow noreferrer">1</a> via mov rax , [rax]</p> <p>the next mov argc , rax is a misrepresentation by ghidra</p> <p>(you may need to split args and rename it )</p> <p>it is not argc it is rdi the default first argument that is passed by register in <a href="https://en.wikipedia.org/wiki/X86_calling_conventions" rel="nofollow noreferrer">System V AMD64 ABI</a></p> <p>you may check it by unlabelling or redefining the function prototype in Ghidra or</p> <p>disassembling <a href="http://shell-storm.org/online/Online-Assembler-and-Disassembler/?opcodes=48%2089%20c7&amp;arch=x86-64&amp;endianness=little&amp;dis_with_addr=True&amp;dis_with_raw=True&amp;dis_with_ins=True#disassembly" rel="nofollow noreferrer">48 89 c7 in an external disassembler like shell storm</a></p> <p>the atoi() takes one parameter a char * and returns an integer</p>
30100
2022-03-02T15:26:53.803
<p>While reverse enginnering a simple C program for training, I asked myself what was the point of those lines :</p> <pre><code> LAB_001006b5 XREF[1]: 0010069d(j) 001006b5 48 8b 45 e0 MOV RAX,qword ptr [RBP + local_28] 001006b9 48 83 c0 08 ADD RAX,0x8 001006bd 48 8b 00 MOV RAX,qword ptr [RAX] 001006c0 48 89 c7 MOV argc,RAX 001006c3 e8 98 fe CALL &lt;EXTERNAL&gt;::atoi int atoi(char * __nptr) ff ff </code></pre> <p>I thought that the function atoi called from the CALL instruction just pop the param from the stack (so lines from 001006b5 to 001006c0 were pointless ?) Am I getting it right or not?</p> <p>Last question : what &quot;MOV argc,RAX&quot; means ?? I mean, argc is a constant ?</p> <p><a href="https://i.stack.imgur.com/DvCMJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DvCMJ.png" alt="enter image description here" /></a></p>
What arguments are passed into a CALL instruction?
|disassembly|assembly|
<p>The way parameter pass is according x86 calling convention (32-bit program calling convention) that Robert said in the comment. You can see more detail from this answer: <a href="https://reverseengineering.stackexchange.com/a/2965">https://reverseengineering.stackexchange.com/a/2965</a>.</p> <p>The calling convention push into stack arguments value so when the function need to access those arguments it can calculate easily because it know that it was push into the stack. The ebp store the frame pointer which always point to the top of the function stack. So the argument is always before the ebp and the local variable is always after the ebp in 32-bit. That's why to get the function first argument it do ebp+8 because it is always at offset +8 from the ebp, the second argument is ebp+12, third is ebp+16 and so on (it can't be + 4 because that's the address to return after the function is called).</p> <p>So to get the function argument you first need to get the value of ebp and the plus 8 to that value to get the first argument. The command to get the first argument is as following:</p> <pre><code>idaapi.get_dword(ida_dbg.get_reg_val(&quot;EBP&quot;)+8) </code></pre> <p>The general for any argument is (change argument_position to the position you want, starting from 0):</p> <pre><code>idaapi.get_dword(ida_dbg.get_reg_val(&quot;EBP&quot;) + 8+4*&lt;argument_position&gt;) </code></pre> <p>You can also use idaapi.get_byte, it work the same as idaapi.get_dword but each argument always contains 4 byte (for <a href="https://stackoverflow.com/a/45134007">stack alignment</a>) so i use get_dword.</p>
30106
2022-03-04T21:26:09.830
<p>I'm trying to automate some of my debugging with a python script that automatically places breakpoints at the first and last instructions of the functions I want to analyze. I'm using the breakpoint's condition to call python code whenever the breakpoint is hit, so I can print a line of text on the console.</p> <p>These functions have arguments that I want to interact with in the breakpoint's condition code from Python, but I don't know how to access them. Take the following function for example:</p> <pre><code>.text:00E072A0 ; char __thiscall encryptDataLong(int this, int inData, int outData, size_t bufferSize) .text:00E072A0 encryptDataLong proc near ; CODE XREF: encryptData+D↓j .text:00E072A0 ; encryptPw+245↓p .text:00E072A0 .text:00E072A0 var_14= dword ptr -14h .text:00E072A0 var_10= dword ptr -10h .text:00E072A0 var_C= dword ptr -0Ch .text:00E072A0 var_8= dword ptr -8 .text:00E072A0 var_4= dword ptr -4 .text:00E072A0 inData= dword ptr 4 .text:00E072A0 outData= dword ptr 8 .text:00E072A0 bufferSize= dword ptr 0Ch .text:00E072A0 .text:00E072A0 sub esp, 14h ; &lt;-- Breakpoint here </code></pre> <p>The second and third arguments are pointers to a chunk of memory, and the last argument is the size of this memory. I want to access all three arguments (the two pointers and the size) from python code, but I don't know how to do it. When I hover my mouse over an argument in the pseudocode view, i get something like this on the tooltip:</p> <pre><code>int inData; // [esp+1Ch] [ebp+4h] </code></pre> <p>But I don't know how to extract the actual pointers form this in python. I assume the parameters are stored relative to one of the registers (e.g. <code>esp</code> in this case), and the number after the <code>+</code> sign is the offset in memory relative to this register's value, but when manually investigating the running program's memory, I found that this is not the case.</p> <p>What do those two register offsets mean on the tooltip, and how can I use them in together with <code>get_reg_value</code> and <code>get_bytes</code> to get the actual data in the arguments?</p> <hr /> <p>PS: I have found the <code>idaapi.get_arg_addrs(here())</code> function from the accepted answer on <a href="https://reverseengineering.stackexchange.com/questions/17593/idapython-how-to-get-function-argument-values">this</a> question, but when running it in the python console while the program is paused on the first instruction of the function, it doesn't return anything. <a href="https://reverseengineering.stackexchange.com/questions/25301/getting-function-arguments-in-ida">This</a> question also mentions <code>get_arg_addrs</code>, but it seems to be used on the <code>call</code> instruction, and not on the function itself. In my case, I want to get the arguments from within the function, when the program is paused on the first instruction.</p>
IDAPython - How can I read the value of a function argument? (IDA 7.6)
|ida|idapython|python|arguments|
<p>If your output looks like this</p> <pre><code>(gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x00005555554006c1 in main at x.c:6 breakpoint already hit 1 time 2 breakpoint keep y 0x00007ffff7a7f980 in strcpy_ifunc at ../sysdeps/x86_64/multiarch/ifunc-unaligned-ssse3.h:33 </code></pre> <p>This means that only breakpoint 1 - the one for line 6 has been hit once. Not the one for <code>strcpy</code></p>
30124
2022-03-07T18:42:14.620
<p>I'm following Erickson 2008 Hacking the art of exploitation. The program is very simple.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; int main() { char str_a[20]; strcpy(str_a, &quot;Hello, world!\n&quot;); printf(str_a); } </code></pre> <p>I set a break at line 6</p> <pre><code>(gdb)break 6 (gdb)break strcpy </code></pre> <p>...which prompts</p> <pre><code>Function &quot;strcpy&quot; not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 2 (strcpy) pending. (gdb) break 8 </code></pre> <p>Then I should be able to step through the program. With run or start and cont. However the program skips the break point 2. &quot;info breakpoints&quot; says breakpoint already hit 1 time at start. How do I make GDB stop at breakpoints even after being reached once? I thought this was the answer.</p> <pre><code>enable -- Enable all or some breakpoints. enable breakpoints -- Enable all or some breakpoints. enable breakpoints count -- Enable some breakpoints for COUNT hits. enable breakpoints delete -- Enable some breakpoints and delete when hit. enable breakpoints once -- Enable some breakpoints for one hit. enable count -- Enable some breakpoints for COUNT hits. </code></pre> <p>GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2 I'll keep digging trying to find the solution but for now it seems a mystery.</p> <p>Edit: I believe the problem lies in gdb disabling my breakpoint at start. When I start the program, it disables breakpoint 2, then I run enable 2 check info breakpoints, and it's enabled, but it never stops there. I changed the addresses and &quot;What&quot; column for formatting.</p> <pre><code>Num Type Disp Enb Address What. . . 1 breakpoint keep y 0x0005 in main at **7. breakpoint already hit 1 time. . . 2 STT_GNU_IFUNC resolver keep y 0x0007 &lt;strcpy_ifunc&gt;. . . 3 breakpoint keep y 0x0005 in main at **8. breakpoint already hit 1 time </code></pre>
breakpoint already hit 1 time
|gdb|breakpoint|
<p>Open up <code>intel.hpp</code> that ships with the SDK. The aux prefix flags are defined at the top; the one you're interested in is as follows:</p> <pre><code>#define aux_natad 0x00001000 // addressing mode is not overridden by prefix </code></pre>
30127
2022-03-09T02:51:13.903
<p>I am trying to tell apart the following two instructions:</p> <pre><code>8D 02 lea eax, [rdx] // auxfix = 0x1810 67 8D 02 lea eax, [edx] // auxfix = 0x810 </code></pre> <p>The only difference is in the insn_t.auxfix field, which seems to hold some operand size flag related to modr/m.</p> <p>As you can see bit 1 &lt;&lt; 12 seems to tell me something ... but how exactly can I interpret this field for x86 and x64?</p>
IDA API: obtain operand size prefix (x64)
|ida|assembly|idapython|x86-64|idapro-sdk|
<p>As it happens, I recently reverse engineered (<a href="https://www.msreverseengineering.com/blog/2022/1/25/an-exhaustively-analyzed-idb-for-comlook" rel="nofollow noreferrer">and published an analysis of</a>) a program that uses Curl, and I had the IDB open in the background. I decided to see if I could find the function in question. Here's how I did it.</p> <ol> <li>First, by searching for <code>CURLE_BAD_FUNCTION_ARGUMENT</code>, we <a href="https://curl.se/libcurl/c/libcurl-errors.html" rel="nofollow noreferrer">determine</a> that the value of the numeric constant is 43.</li> <li>Under <code>Search-&gt;Immediate value</code>, input the number 43.</li> </ol> <p><a href="https://i.stack.imgur.com/svPCe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/svPCe.png" alt="enter image description here" /></a></p> <ol start="3"> <li>IDA then displays a list of locations in the binary that use the immediate constant 43:</li> </ol> <p><a href="https://i.stack.imgur.com/JLHRk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JLHRk.png" alt="enter image description here" /></a></p> <ol start="4"> <li><p>Although there are 189 results in the code section, I didn't need to look at all of them. For example, in the second line of the image above, the value is being compared with an 8-bit register; I'm assuming <code>CURLcode</code> is an integer, so that's not the one we want. In the bottom three lines, we can see that one single function contains the constant three (actually, many) times; your snippet shows the number one single time, so that's not the one we want. I exclude many of the possibilities with reasoning like this; anything that is not <code>mov eax, 2Bh</code>, or anywhere that instruction appears more than once in a single function, is placed on the backburner for later analysis (if necessary).</p> </li> <li><p>I briefly look at each good-looking result to see if it has a similar control flow shape to the one from your question. Quickly, I find one that looks right (and as it happens, IDA had already named the function <code>curl_easy_setopt</code> due to its Lumina renaming feature):</p> </li> </ol> <p><a href="https://i.stack.imgur.com/guOS9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/guOS9.png" alt="enter image description here" /></a></p> <p>Note that this trick would not have worked very well if the numeric value of <code>CURLE_BAD_FUNCTION_ARGUMENT</code> had been something like <code>1</code>, <code>2</code>, <code>4</code>, <code>8</code>, <code>16</code>, <code>32</code>, etc. I exploited the fact that the number 43 does not appear extremely often in most programs in order to narrow down my search.</p>
30130
2022-03-09T20:29:17.293
<p>Apologies if this account question may sound a bit stupid but I really need help with something</p> <p>Let's say I had a function that looks something like this :</p> <pre><code>#undef curl_easy_setopt CURLcode curl_easy_setopt(struct Curl_easy *data, CURLoption tag, ...) { va_list arg; CURLcode result; if(!data) return CURLE_BAD_FUNCTION_ARGUMENT; va_start(arg, tag); result = Curl_vsetopt(data, tag, arg); va_end(arg); return result; } </code></pre> <p>How could I go about the proccess of finding this function in IDA?</p>
How to find specific function in IDA pro
|c++|
<p>The manufacturer appears to be <a href="http://sigmastarsemi.com" rel="nofollow noreferrer">http://sigmastarsemi.com</a></p> <p>Also this site might be useful: <a href="http://linux-chenxing.org/" rel="nofollow noreferrer">http://linux-chenxing.org/</a></p>
30137
2022-03-12T22:05:00.237
<p>Does anybody know the manufacturer of this ARM CPU / SoC? I cannot find any information about it. I don't even know what the character in front of “Star” means.</p> <p>“SAV500D” seems to be the model, the following lines seem to be serial numbers. I have two of them, only the first line is the same.</p> <p>Thanks a lot for any help!</p> <p><a href="https://i.stack.imgur.com/ny15b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ny15b.png" alt="soc" /></a></p>
Need help identifying this SoC
|linux|arm|
<p>Fixed it with the help of <a href="https://hex-rays.com/blog/ida-and-common-python-issues/" rel="nofollow noreferrer">this page</a></p> <p>At the end of the day it was</p> <ol> <li><p>pointing to python 3.8 installation instead of Python 2.7 although both were installed on the machine</p> </li> <li><p>python27.dll was not in the package I've used to install Python 2.7. Had to reinstall it</p> </li> <li><p>had to remove PYTHONPATH and PYTHONHOME completely and leave only PATH pointing to Python 2.7 installation</p> </li> </ol>
30143
2022-03-14T18:47:24.027
<p>I have a <code>python</code> dir within IDA 6.8 folder with <code>idaapi.py</code>, <code>idautils.py</code>, and <code>idc.py</code>. IDA doesn't seem to pick the Python scripting by default.</p> <p>How do I enable it?</p>
How do I enable Python on IDA 6.8?
|ida|idapython|
<p>Ghidra can in fact parse the <code>.debug</code> section and DWARF information in general, but the error message you posted indicates that it is refusing to do so, because of the too large number of records. It also gives you the two options to explicitly run the analysis nonetheless:</p> <ol> <li>Running the Auto Analysis Step with custom configuration</li> <li>Running a separate script.</li> </ol> <p>The first option specifically means: In the CodeBrowser view of the specific binary, click <code>Analysis</code> in the top bar, then <code>Auto Analyze '$binaryname'</code>. In the resulting list of analyzers scroll down to DWARF which should then look like this screenshot</p> <p><a href="https://i.stack.imgur.com/GogSI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GogSI.png" alt="enter image description here" /></a></p> <p>change the <code>2000000</code> highlighted to anything higher than <code>2018267</code>, hit analyze, and Ghidra should now rerun the auto analysis but properly import the DWARF information and not skip it like before.</p>
30149
2022-03-16T08:56:04.937
<p>I have an ELF64 binary that comes with <code>*.sym</code> and <code>.debug</code>. From my understanding this is something akin to PDB. While IDA loads it automatically, it fails to process it. I was wondering if Ghidra will fare better but I can't seems to find a way to do so. <a href="https://github.com/NationalSecurityAgency/ghidra/issues/3513" rel="nofollow noreferrer">This issue</a> does say it should be in but I cant figure it out:</p> <pre><code>Skipping DWARF import because a precondition was not met: TheMainBinary has more DIE records (2018267) than limit of 2000000 Manually re-run the DWARF analyzer after adjusting the options or start it via Dwarf_ExtractorScript </code></pre>
How to use linux .debug file with Ghidra
|linux|ghidra|
<p>First, some background. When a binary imports an API function, the operating system loader stores a function pointer to that function in a location specified by metadata in the binary's executable headers. In IDA, on Windows, this section generally is named <code>.idata</code> and is colored pink. You can see a typical example in the following screenshot:</p> <p><a href="https://i.stack.imgur.com/SFvts.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SFvts.png" alt="this screenshot" /></a></p> <p>There are two patterns that code in a binary uses to invoke these imported API functions. First, you might see <code>call</code> instructions that reference the function pointers in the aforementioned <code>.idata</code> section directly, as in:</p> <p><a href="https://i.stack.imgur.com/ttYXh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ttYXh.png" alt="this screenshot" /></a></p> <p>Secondly, for some API functions, the binary might include a so-called &quot;thunk&quot; function, which consists of one single <code>jmp</code> instruction to the imported function pointer.</p> <p><a href="https://i.stack.imgur.com/TXXjv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TXXjv.png" alt="this screenshot" /></a></p> <p>Now, on to your question. Only imports with associated thunk functions will end up in the functions window. This is natural, because thunk functions are actual functions, whereas function pointers are not functions (they're pointers). If you want to see the collection of functions imported by a given binary, use the Imports window (View-&gt;Open subviews-&gt;Imports) instead of the Functions window.</p>
30155
2022-03-18T04:30:59.720
<p>This is very confusing and problematic. For example, in a certain executable, the winsock2 library is imported, but only CERTAIN functions from it are listed in the functions tab. However, they are NOT the only functions that are in use. I'm not sure right now, but it may be that the other functions which ARE in use, do not have the _imp_ prefix in the code, while the ones that are listed, do. But I'm really confused because effectively what I end up with is really misleading.</p>
Why does IDA not show certain library functions in the function list?
|ida|
<p>Select the Stack panel by pressing <kbd>Tab</kbd>, then press the <kbd>I</kbd> key a couple of times (in my case two times) and you get a view like this:</p> <p><a href="https://i.stack.imgur.com/AZLu1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AZLu1.png" alt="Stack view of 8 bytes wide" /></a></p> <p>Edit: This works if your panel has the pxr command (I'm not sure if that is the default), so if it doesn't work, you can try this:</p> <p>Select the Stack panel using the <kbd>Tab</kbd> key, press the <kbd>e</kbd> key, type <code>pxr 256@r:SP</code></p> <p>then you can use the <kbd>I</kbd> key as I described before.</p>
30166
2022-03-22T05:56:03.843
<p>Currently, my stack view is 0x10 (16) bytes long.</p> <p><a href="https://i.stack.imgur.com/MRQV2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MRQV2.png" alt="Stack View" /></a></p> <p>How do I change it so that the stack view is 8 bytes long?</p> <p>Edit: I have tried tabbing into the stack window, pressing e, and then typing <code>pxr 256@r:SP</code> and it did not work. Here is my results <a href="https://i.stack.imgur.com/f2kjt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f2kjt.png" alt="enter image description here" /></a></p> <p>Edit 2: This DOES work, I just need to press <code>i</code> a few more times</p>
How do you change the stack width/offset in radare2?
|radare2|debuggers|
<p>Looks like 16bit Little endian for me. Bytes are swapped pairwise so instead of 12345678 you got 21436587. Not sure if its only on the strings or on all flash bytes. Best to test both variants out</p>
30167
2022-03-22T06:21:22.983
<p>I'm working on reverse engineering a small household weather station, and I have successfully managed to extract the contents of a SPI NOR flash chip (using a modified version of <a href="https://github.com/eblot/pyspiflash" rel="nofollow noreferrer">this Python library</a> to add the ID for the flash chip on the PCB) that I found on the circuit board, but the data appears to have some sort of shifting/jumbling.</p> <p>For example:</p> <pre><code>00070f10 20 54 52 50 4a 4f 43 45 49 54 4e 4f 41 20 54 4c | TRPJOCEITNOA TL| 00070f20 57 2f 54 49 20 48 41 46 52 48 4e 45 45 48 54 49 |W/TI HAFRHNEEHTI| 00070f30 20 20 45 43 53 4c 55 49 20 53 52 50 4a 4f 00 00 | ECSLUI SRPJO..| 00070f40 00 00 20 20 55 43 52 52 4e 45 20 54 20 20 52 20 |.. UCRRNE T R | </code></pre> <p>I can clearly tell the word FAHRENHEIT is on the second line, CELSIUS is on the third line, and CURRENT is on the fourth line, but the characters are all mixed up. Is this some sort of basic encryption, or is it a sign that I am reading the flash memory improperly?</p>
Contents of SPI NOR Flash appears scrambled
|embedded|flash|spi|
<p>IDC is closer to C than C++ but both limited in some ways and more flexible in others than C. It supports several <a href="https://www.hex-rays.com/products/ida/support/idadoc/161.shtml" rel="nofollow noreferrer">variable types</a> but arrays is not one of them:</p> <blockquote> <p>A variable can contain:</p> <ul> <li>LONG: a 32-bit signed long integer (64-bit in 64-bit version of IDA)</li> <li>INT64: a 64-bit signed long integer</li> <li>STR: a character string</li> <li>FLOAT: a floating point number (extra precision, up to 25 decimal digits)</li> <li>OBJECT: an object with attributes and methods (a concept very close to C++ class) more</li> <li>REF: a reference to another variable</li> <li>FUNC: a function reference</li> </ul> </blockquote> <p>However, you can use <a href="https://www.hex-rays.com/products/ida/support/idadoc/1578.shtml" rel="nofollow noreferrer">slice syntax</a> with objects to simulate arrays:</p> <pre><code>auto x = object(); x[0] = value1; x[1] = &quot;value2&quot;; </code></pre>
30180
2022-03-25T12:19:49.830
<p>So to cut straight to the chase - I'm lazy, IDA is mysterious, I need to use IDA arrays in my IDC code for convenience. Because IDC is like C(++) in its syntax I figured I could do:</p> <pre><code>auto lala[4] = {0,1,2,3}; </code></pre> <p>But that doesn't work. Neither do round or square brackets. Trying to do lala[0] produces this output:</p> <pre><code>Cannot use [] operator on scalars </code></pre> <p>What gives?</p>
How to have arrays in IDA's IDC
|ida|idc|
<p>These kinds of problems are related to the <code>encoding</code> of your script/program. My specific problem was related that <code>0x90</code> byte on my file was a <code>latin</code> character which <code>UTF-8</code> couldn't recognize. On top of my file I wrote <code># -- coding: latin-1 --</code> and it was fixed. For anyone curios the little pest was this character <code>È</code> at byte <code>0x90</code>.</p>
30186
2022-03-26T15:23:35.563
<p>Note: Not sure if this kind of question belongs here but as long as this won't fit anywhere else this site is the closest.</p> <p>Back to the topic, I have a python file which I obfuscated it and anytime I want to turn this into executable using <code>pyinstaller</code> there's a <code>0x90</code> byte at the beginning of file which it can't be decoded using <code>UTF-8</code>. When I run the program it shows me this error:</p> <pre><code>Traceback (most recent call last): File &quot;test.py&quot;, line 500, in &lt;module&gt; File &quot;test.py&quot;, line 481, in djxvCOWAMQFNXLmkmwHopqHMWeJWqRRfaTYhtVQhEjhYQByjCUhjZmlyRVkSKqsEcxYRXketUHcQvObBfTQifGMfTOEsxpDzumWrevMKrXWYeXWOqinkNlbvZDoeaQMo File &quot;test.py&quot;, line 236, in CjpiLgqGSPHXaLfOKvPztQfChQlzklDoKWuieQOqmnPEnVxqRophKppuTPUSrlAdiWNiSOwcKqyDZoQSJsvmVPUVLFIQvRZbwSFHZQdLkwgXSoPoFJbjsZnrLKWkjKnZ File &quot;codecs.py&quot;, line 322, in decode UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byte </code></pre> <p>Not sure how do I deal with this, I have tried different naming of variable and still the same thing. Can someone help me a bit with this? Thanks in advance!</p>
Why 0x90 byte is always at top of my file?
|debugging|ghidra|hex|byte-code|
<p>Hmm, so here's the rub. I installed IDA Freeware 7.7 in my Linux VM and tried in parallel in my named license IDA Pro 7.7.</p> <p>Turns out this seems to be a limitation of IDA Freeware, in all likelihood a conscious one. In particular I can see with the freeware version that <code>DllEntryPoint</code> was not deemed a library function (cyan color), but with the commercial license it was.</p> <p>Freeware: <a href="https://i.stack.imgur.com/3OCRU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3OCRU.png" alt="Freeware" /></a></p> <p>Commercial: <a href="https://i.stack.imgur.com/O47Lp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O47Lp.png" alt="Commercial license" /></a></p> <p>It appears that based on <code>autoload.cfg</code> my commercial IDA will load FLIRT signatures <code>vc32rtf</code> (Microsoft VisualC 2-14/net runtime), which the freeware version doesn't do on its own.</p> <p>If you do that manually through <kbd>File</kbd> -&gt; <kbd>Load file</kbd> -&gt; <kbd>FLIRT signature file</kbd> your <code>DllEntryPoint</code> function should get collapsed and its color should indicate it's a <em>library function</em> (cyan). You can toggle collapsed/expanded mode with <kbd>Ctrl</kbd>+<kbd>Num+</kbd> by default.</p> <p>Now, if you expand the function you will notice it has been recognized as a library function, but so have some of the callees called <em>from</em> this library function. What's more, if you use <kbd>View</kbd> -&gt; <kbd>Open subviews</kbd> -&gt; <kbd>Function calls</kbd> you can see the overview of calls <em>from</em> <code>DllEntryPoint</code>.</p> <p><a href="https://i.stack.imgur.com/rBZrG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rBZrG.png" alt="Function calls subview" /></a></p> <p>As you can now see, there are only two called &quot;entities&quot; which aren't themselves library functions (<code>call eax ; dword_10092E58</code> and <code>call sub_1000D02E</code>). And after a cursory look under which conditions the function pointer stored in <code>dword_10092E58</code> gets called, we can surmise that <code>sub_1000D02E</code> must be our <code>DllMain</code>.</p> <p>Knowing this, we can now jump to it and manually rename it to <code>DllMain</code>. Once done it should show up as:</p> <pre><code>.text:1000D02E ; BOOL __stdcall DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) .text:1000D02E DllMain proc near ; CODE XREF: DllEntryPoint+4B↓p .text:1000D02E ; DATA XREF: sub_100110FF+2D↓o </code></pre> <p>... in the &quot;IDA View-A&quot;.</p>
30187
2022-03-26T19:26:38.110
<p>I want to use the IDA Freeware Version 7.7 for finding the <strong>DllMain</strong> of a DLL file. The file is from the book Practical Malware Analysis. It is for Lab 05. Name of file is &quot;Lab05-01.dll&quot; and you can download that from <a href="https://practicalmalwareanalysis.com/labs/" rel="nofollow noreferrer">here</a> (use VM).</p> <p>So as Practical Malware Analysis mentioned, when I load the DLL at IDA Freeware, then, the first line of instruction at the graph view should be the start of DllMain.</p> <p>But when I load the DLL file at the IDA Freeware, the first line of graph view is NOT the <code>DllMain</code>. Because I checked from the solutions and my answer and book's answer were not the same.</p> <h2>Ways that I've Tested</h2> <ol> <li>Looking at the first line of instruction at the graph view which the book described. (Explained above that didn't worked)</li> <li>So I searched and found <a href="https://stackoverflow.com/questions/26345426/donot-know-how-to-find-the-address-of-dllmain">THIS ARTICLE</a>. One of the ways that was mentioned there was to go and find <code>DllMain</code> at the function windows. There was no function named <code>DllMain</code> (As you see in the picture) <img src="https://i.stack.imgur.com/7mvqJ.png" alt="A Picture of Functions" /> The <code>DllMain</code> does NOT exist because if it did exist, then it would be above <code>EnumProcessModules</code> and below <code>DllEntryPoint</code>. (Note that I have sorted by name)</li> <li>So next thing I did was to look at the answer and see what is the name of the function which starts at the exact same address which the book says DllMain starts. The book says the answer is <strong>1000D02E</strong>. I look at the function which had started from this location and that function had this name : <strong>sub_1000D02E</strong> , not <code>DllMain</code>.<img src="https://i.stack.imgur.com/W1mmd.png" alt="The Function Highlighted is the DllMain" /> The function highlighted is the DllMain (I know this because I have looked at the solutions and as you see the function's name is not <code>DllMain</code> and I was unable to find that by myself)</li> </ol> <hr /> <p><strong>What should I do to find the DllMain?</strong></p> <p>Thank you in advance.</p>
Find DllMain using IDA Freeware
|ida|dll|
<p>&quot;jz&quot; is a conditional jump. Explanation <a href="https://en.wikibooks.org/wiki/X86_Assembly/Control_Flow#Comparison_Instructions" rel="nofollow noreferrer">HERE</a>.</p> <p>&quot;loc&quot; stands for location.</p> <p><code>jz loc_41B37D</code> means if the zero flag was set to 1, jump to location 41B37D.</p> <p>Reading <a href="https://www.aldeid.com/wiki/X86-assembly/Instructions/jz" rel="nofollow noreferrer">HERE</a> would also help.</p>
30189
2022-03-27T11:27:22.863
<p>I have this piece of assembly:</p> <pre><code>.text:0041B322 xor eax, eax .text:0041B324 mov al, byte ptr [ebp+v13] .text:0041B327 cmp eax, 1 .text:0041B32A jz loc_41B37D .text:0041B330 xor eax, eax .text:0041B332 mov al, byte ptr [ebp+v13] </code></pre> <p>I would like to know what exactly is <strong>loc_41B37D</strong> in this context? I believe this means <strong>local piece of code</strong>. So it would be a label pointing to some address in memory. But I coudn't find any definition for this online. Can you link me some useful resource for this? Documentation maybe?</p>
IDA - What LOC means in assembly?
|ida|assembly|
<p>Hmm this probably isn't an exhaustive list, but feel free to add to it:</p> <ul> <li>C runtime (header <code>&lt;string.h&gt;</code> or <code>&lt;cstring&gt;</code>: <ul> <li><code>strcmp</code>, <code>strncmp</code>, <code>wcscmp</code>, <code>wcsncmp</code> (with <code>&lt;wchar.h&gt;</code>) <ul> <li><em>case-insensitive</em>: <code>strcasecmp</code>, <code>strncasecmp</code> <ul> <li><code>wcscasecmp</code> (with <code>&lt;wchar.h&gt;</code>)</li> </ul> </li> <li>also known as: <code>stricmp</code>, <code>strcmpi</code></li> </ul> </li> <li><code>memcmp</code>, <code>wmemcmp</code> (with <code>&lt;wchar.h&gt;</code>), <code>bcmp</code> (unlikely on Windows) <ul> <li><code>memicmp</code> (and similar)</li> </ul> </li> <li>Depending on your runtime there may also be <code>l</code> varieties such as <code>strlcmp</code> of the aforementioned functions (<code>l</code> for length)</li> </ul> </li> <li>Windows API (header <code>winbase.h</code>): <ul> <li><code>lstrcmp</code> (expands to <code>lstrcmpA</code> <em>or</em> <code>lstrcmpW</code>) <ul> <li><em>case insensitive</em>: <code>lstrcmpi</code> (expands to <code>lstrcmpiA</code> <em>or</em> <code>lstrcmpiW</code>)</li> </ul> </li> </ul> </li> <li>Windows via <code>&lt;shlwapi.h&gt;</code>, offering different comparison semantics: <ul> <li><code>StrCmp</code> (expands to <code>StrCmpA</code> <em>or</em> <code>StrCmpW</code>)</li> <li><code>StrCmpC</code> (expands to <code>StrCmpCA</code> <em>or</em> <code>StrCmpCW</code>)</li> <li><code>StrCmpI</code> (expands to <code>StrCmpIA</code> <em>or</em> <code>StrCmpIW</code>)</li> <li><code>StrCmpIC</code> (expands to <code>StrCmpICA</code> <em>or</em> <code>StrCmpICW</code>)</li> <li><code>StrCmpNC</code> (expands to <code>StrCmpNCA</code> <em>or</em> <code>StrCmpNCW</code>)</li> <li><code>StrCmpNI</code> (expands to <code>StrCmpNIA</code> <em>or</em> <code>StrCmpNIW</code>)</li> <li><code>StrCmpNIC</code> (expands to <code>StrCmpNICA</code> <em>or</em> <code>StrCmpNICW</code>)</li> <li><code>StrCmpN</code> (expands to <code>StrCmpNA</code> <em>or</em> <code>StrCmpNW</code>)</li> </ul> </li> <li>Windows kernel mode and NT native: <ul> <li><code>RtlCompareUnicodeString</code></li> <li><code>RtlEqualUnicodeString</code></li> </ul> </li> </ul> <p>But in all likelihood you are looking for the C runtime ones. The <code>n</code> variety usually is counted (<code>n</code> being the number of characters)</p> <p>Also beware that there exist a number of related functions. E.g. with Windows conventionally you can build with <code>_UNICODE</code> defined or not, using <code>&lt;tchar.h&gt;</code>. This will then alias the respective &quot;bare&quot; function names to those with trailing <code>A</code> (ANSI) or <code>W</code> (wide character, i.e. &quot;Unicode&quot;) version.</p> <p>On Windows you will also encounter instead of <code>str</code>...something (e.g. <code>strcmp</code>) <a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strcmp-wcscmp-mbscmp" rel="nofollow noreferrer">functions prefixed</a>:</p> <ul> <li><code>_tcs</code>, i.e. <code>_TCHAR</code>/<code>TCHAR</code> character string ... where the meaning toggles (via <code>&lt;tchar.h&gt;</code>) between <code>char</code> and <code>wchar_t</code> (if <code>_UNICODE</code> defined)</li> <li><code>_mbs</code>, i.e. multi-byte character string (code pages such as some Asian locales where a single byte isn't enough to represent one code point, which predates wide use of Unicode proper)</li> <li><code>wcs</code>, i.e. &quot;wide character string&quot;</li> </ul>
30192
2022-03-27T19:34:07.167
<p>I made a list of which instructions compare two strings in disassembly so that when I get to intermodular calls in x64dbg, I can simply type this instructions to see if there is a comparison have been made. Unfortunately, I lost this list. Can someone get me these instructions please. I only remember <code>lstrcmpiA</code>.</p>
Instructions to compare two strings
|disassembly|windows|debugging|x64dbg|