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>best to put the code inside the MakeLicenseValidForever into <code>#if DEBUG</code>,too. those #if things get processed at compile time and only the code of the taken path exists. Functions don't get stripped if not referenced thats why its best to empty out the function that should not exist in the release binary. They are similar to the C #ifdefs for preprocessor based stripping</p>
31058
2022-10-31T06:36:34.370
<p>I have something like this in my code that checks for user's license:</p> <pre><code>// C# code: #if DEBUG MakeLicenseValidForever(); #else CheckLicense(); #endif </code></pre> <p>Now, I need to know if these directives get saved in my released binary or not. If they do get saved, then a user can make <code>#if DEBUG</code> return <code>true</code> and bypass the checks. I need to know if <code>#if DEBUG</code> is safe.</p>
Can #if DEBUG in C# become true in the released binary?
|executable|c#|
<p>to perform inter segement branching (jump/call) cs needs to be changed</p> <p>from windbg you can observe kernel code is running in code segment 0x10 while user mode code is running in 0x33 (64 bits) or 0x23 (32 bits)</p> <pre><code>:\&gt;livekd -b -c rcs;q | findstr &quot;cs=&quot; cs=0010 :\&gt;cdb -c &quot;r cs;q&quot; cdb.exe | findstr &quot;cs=&quot; cs=0033 :\&gt;cd &quot;c:\Program Files (x86)\Windows Kits\10\Debuggers\x86&quot; :\&gt;.\cdb -c &quot;r cs;q&quot; .\cdb.exe | findstr &quot;cs=&quot; cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246 cs=00000023 </code></pre> <p>a 32 bit binary when running in a 64 bit windows uses WoW (windows on windows ) layer to run 64 bit code to perform syscalls employing inter segement calls with same privileges but different selector</p> <pre><code>ntdll!Wow64SystemServiceCall: 77cf8b40 ff252892d977 jmp dword ptr [ntdll!Wow64Transition (77d99228)] ds:002b:77d99228=77c67000 0:000&gt; t eax=0007000e ebx=00000000 ecx=ffffffff edx=77cf8b40 esi=77d95ce0 edi=77c76a78 eip=77c67000 esp=04a7f510 ebp=04a7f788 iopl=0 nv up ei pl zr na pe nc &gt;&gt;&gt;cs=0023&lt;&lt;&lt; ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246 77c67000 ea0970c6773300 jmp 0033:77C67009 &lt;&lt;&lt;&lt; calling </code></pre> <p>EDIT:</p> <p>the queries you pose in edit are probably worth a few lectures and can't be answered justifiably in Q.A site.</p> <p>you may need to look for Segment Descriptor , Segment Selector ,<br /> Global Descriptor Table , Local Descriptor Table , Segment Translation<br /> and run through AMD and Intel Manuals a few times to get a grip.</p> <p>cs , fs, ss, es ,gs ds are segment selectors a 16 bit entity</p> <p>bit 0,1 denotes Requested Privilege Level or RPL</p> <p>bit 2 denotes Which Descriptor Table (Table Indicator or TI) to use<br /> ( GDT or LDT )</p> <p>bit 3 to 15 denotes the Index</p> <p>SELECTORS Dissected</p> <pre><code>hex | bin | index | TI | RPL | 10 | 0000000000010000 | 0000000000010=0X2 | 0=GDT | 00=R0/KERNEL| 23 | 0000000000100011 | 0000000000100=0X4 | 0=GDT | 11=R3/USER | 33 | 0000000000110011 | 0000000000110=0X6 | 0=GDT | 11=R3/USER | </code></pre> <p>DUMPING First 8 Global Descriptor Table Entries</p> <pre><code>0: kd&gt; dpp @gdtr L8 fffff804`43856fb0 00000000`00000000 fffff804`43856fb8 00000000`00000000 fffff804`43856fc0 00209b00`00000000 &lt;&lt; 0X2 fffff804`43856fc8 00409300`00000000 fffff804`43856fd0 00cffb00`0000ffff &lt;&lt; 0X4 fffff804`43856fd8 00cff300`0000ffff fffff804`43856fe0 0020fb00`00000000 &lt;&lt; 0X6 fffff804`43856fe8 00000000`00000000 </code></pre> <p>using dg command to dissect the raw bytes dumped above</p> <pre><code>0: kd&gt; dg 0x10 P Si Gr Pr Lo Sel Base Limit Type l ze an es ng Flags ---- ----------------- ----------------- ---------- - -- -- -- -- -------- 0010 00000000`00000000 00000000`00000000 Code RE Ac 0 Nb By P Lo 0000029b 0: kd&gt; dg 0x20 P Si Gr Pr Lo Sel Base Limit Type l ze an es ng Flags ---- ----------------- ----------------- ---------- - -- -- -- -- -------- 0020 00000000`00000000 00000000`ffffffff Code RE Ac 3 Bg Pg P Nl 00000cfb 0: kd&gt; dg 0x30 P Si Gr Pr Lo Sel Base Limit Type l ze an es ng Flags ---- ----------------- ----------------- ---------- - -- -- -- -- -------- 0030 00000000`00000000 00000000`00000000 Code RE Ac 3 Nb By P Lo 000002fb 0: kd&gt; </code></pre> <p>so between selector <strong>4 and 6 or cs = 0x23 and cs = 0x33</strong></p> <p>difference in both cs selector is in 0x33 Long Mode or 64 bit code execution is possible<br /> whereas with cs = 0x23 executing 64 bit instruction is not possible</p> <p>a practical usage can be observed below in the disassembly of same bytes between cs changes</p> <pre><code>0:000:x86&gt; ? cs Evaluate expression: 35 = 00000023 0:000:x86&gt; $$ cs is now in 2 bit mode and disassembly will be as x86 see prompt also 0:000:x86&gt; u . l4 wow64cpu!KiFastSystemCall: 77c67000 ea0970c6773300 jmp 0033:77C67009 77c67007 0000 add byte ptr [eax],al 77c67009 41 inc ecx 77c6700a ffa7f8000000 jmp dword ptr [edi+0F8h] 0:000:x86&gt; $$ lets single step 0:000:x86&gt; t wow64cpu!KiFastSystemCall+0x9: 00000000`77c67009 41ffa7f8000000 jmp qword ptr [r15+0F8h] ds:00000000`77c64758={wow64cpu!CpupReturnFromSimulatedCode (00000000`77c61782)} 0:000&gt; $$ see the x86 garbage disassembly has now a meaningful x64 instruction 0:000&gt; $$ and prompt is not x86 anymore but x64 0:000&gt; u .-9 l6 wow64cpu!KiFastSystemCall: 00000000`77c67000 ea ??? 00000000`77c67001 0970c6 or dword ptr [rax-3Ah],esi 00000000`77c67004 7733 ja wow64cpu!KiFastSystemCall+0x39 (00000000`77c67039) 00000000`77c67006 0000 add byte ptr [rax],al 00000000`77c67008 0041ff add byte ptr [rcx-1],al 00000000`77c6700b a7 cmps dword ptr [rsi],dword ptr [rdi] 0:000&gt; disassembling x86 code as x64 results ingarbage now </code></pre>
31060
2022-10-31T08:46:06.323
<p>I do not understand the usefulness of the &quot;far call&quot; instruction in a 86 CPU.</p> <p>On a 32 bits CPU for example each process has an addressing space of 4Gb (0x00000000 to 0xFFFFFFFF).</p> <p>There can be several executable memory regions in this 4Gb address space.</p> <p>A &quot;basic CALL&quot; instruction can call any address in this space. for example:</p> <pre><code>CALL 0x12345678 </code></pre> <p>In this case, EIP register will be pushed on the stack and 0x12345678 value will be assigned to EIP.</p> <p>To me, a &quot;Far call&quot; is exactly the same thing but it also changes the CS (Code Segment) register. What is the goal of changing this register value ?</p> <p>Why changing CS register value ?</p> <p>Thanks</p>
What is a "far call" in an x86 or x86_64 cpu
|assembly|x86|x86-64|calling-conventions|
<p>The problem was that I did not induce teh resources when importing the .exe file.</p>
31063
2022-10-31T16:36:57.527
<p>I've been using IDA for some time and most of the time I can find the strings I am looking for in the String panel. In one of the recent exe files I was working on, many string are missing, or not shown in IDA. Sure, not all string are always visible in an exe files, some may reside outside but when I load the same exe file into <a href="https://suip.biz/?act=rabin2" rel="nofollow noreferrer">this site</a> for searching all strings it found all the missing string not visible in IDA.</p> <p>My question is how to make IDA show ALL the strings?</p> <p>Thanks</p>
How to use IDA pro to find ALL strings in an exe file?
|ida|strings|
<p>i wrote this to dissect the file apisetschema.dll some time back found in windows 10 system32 folder</p> <p>this code is based on <a href="https://www.geoffchappell.com/studies/windows/win32/apisetschema/index.htm" rel="nofollow noreferrer">Geoff Chappells studies on ApiSetSchema</a></p> <p>code in apisetres.cpp</p> <pre><code>#include &quot;apisetdefs.h&quot; int main(void) { FILE *infile = NULL; errno_t err = fopen_s(&amp;infile, &quot;c:\\windows\\system32\\apisetschema.dll&quot;, &quot;rb&quot;); if (err == 0 &amp;&amp; infile != NULL) { fseek(infile, 0, SEEK_SET); size_t siz = fread_s(peheadbuf, BUSIZ, 1, 0x400, infile); if (siz == 0x400) { PIMAGE_DOS_HEADER dhead = (PIMAGE_DOS_HEADER)&amp;peheadbuf; PIMAGE_NT_HEADERS64 nthead = (PIMAGE_NT_HEADERS64)(peheadbuf + dhead-&gt;e_lfanew); PIMAGE_SECTION_HEADER Section = IMAGE_FIRST_SECTION(nthead); for (WORD i = 0; i &lt; nthead-&gt;FileHeader.NumberOfSections; i++) { if ((memcmp(Section-&gt;Name, &quot;.apiset&quot;, 8)) == 0) { fseek(infile, Section-&gt;PointerToRawData, SEEK_SET); siz = fread_s(peheadbuf, BUSIZ, 1, sizeof(APISET_SCHEMA_HEADER_V6), infile); if (siz == sizeof(APISET_SCHEMA_HEADER_V6)) { apisethead = (PAPISET_SCHEMA_HEADER_V6)&amp;peheadbuf; printf(&quot;Version Number = %x\n&quot;, apisethead-&gt;VersionNumber); printf(&quot;MapSize = %x\n&quot;, apisethead-&gt;Mapsize); printf(&quot;isSealed = %x\n&quot;, apisethead-&gt;isSealed); printf(&quot;Number of Apisets = %x\n&quot;, apisethead-&gt;NumAPISets); printf(&quot;Offset to NameSpace Entries = %x\n&quot;, apisethead-&gt;OffsetNameSpaceEntries); printf(&quot;Offset To hash Entries = %x\n&quot;, apisethead-&gt;OffsetHashEntries); printf(&quot;Hash Multiplier = %x\n&quot;, apisethead-&gt;HashMultiplier); } DWORD rawdataaddr = Section-&gt;PointerToRawData; DWORD mapoff = rawdataaddr + apisethead-&gt;OffsetNameSpaceEntries; for (unsigned int j = 0; j &lt; apisethead-&gt;NumAPISets; j++) { DWORD apisetname = (mapoff + (j * sizeof(API_SET_NAMESPACE_ENTRY))); printf(&quot;%x\t&quot;, apisetname); fseek(infile, apisetname, SEEK_SET); siz = fread_s(apisetnsebuf, BUSIZ, 1, sizeof(API_SET_NAMESPACE_ENTRY), infile); apinsentry = (PAPI_SET_NAMESPACE_ENTRY)(apisetnsebuf); printf(&quot;%x\t&quot;, apinsentry-&gt;OffsetApiSetName); DWORD apivdllname = ((rawdataaddr) + (apinsentry-&gt;OffsetApiSetName)); fseek(infile, apivdllname, SEEK_SET); memset(wbuf,0,sizeof(wbuf)); siz = fread_s(wbuf, WBUSIZ , 1, apinsentry-&gt;SizeApiSetName, infile); printf(&quot;%-60.*S\t&quot;, (apinsentry-&gt;SizeApiSetName), wbuf); printf(&quot;%x\t&quot;, apinsentry-&gt;OffsetValueEntries); DWORD apildllname = ((rawdataaddr) + (apinsentry-&gt;OffsetValueEntries) ); printf(&quot;%x\t&quot;, apildllname); fseek(infile, apildllname, SEEK_SET); siz = fread_s(apisetvalentbuf, BUSIZ, 1, sizeof(API_SET_VALUE_ENTRY), infile); apivalentry = (PAPI_SET_VALUE_ENTRY)(apisetvalentbuf); printf(&quot;%x\t&quot; , apivalentry-&gt;ValueOffset); DWORD apivalentname = ((rawdataaddr) + (apivalentry-&gt;ValueOffset)); fseek(infile,apivalentname,SEEK_SET); memset(wbuf,0,sizeof(wbuf)); siz = fread_s(wbuf, WBUSIZ , 1, apivalentry-&gt;ValueLength, infile); printf(&quot;%-60.*S\n&quot;, (apivalentry-&gt;ValueLength)/2, wbuf); } }; Section++; } } } } </code></pre> <p>header file apisetres.h</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;windows.h&gt; #define BUSIZ 0x500 #define WBUSIZ BUSIZ / 2 unsigned char peheadbuf[BUSIZ]; unsigned char apisetnsebuf[BUSIZ]; unsigned char apisetvalentbuf[BUSIZ]; wchar_t wbuf[BUSIZ]; typedef struct _APISET_SCHEMA_HEADER_V6 { DWORD VersionNumber; DWORD Mapsize; DWORD isSealed; DWORD NumAPISets; DWORD OffsetNameSpaceEntries; DWORD OffsetHashEntries; DWORD HashMultiplier; } APISET_SCHEMA_HEADER_V6, *PAPISET_SCHEMA_HEADER_V6; typedef struct _API_SET_NAMESPACE_ENTRY { DWORD isSealed; DWORD OffsetApiSetName; DWORD SizeApiSetName; DWORD SizeApiSetNameNoHyphen; DWORD OffsetValueEntries; DWORD NumHosts; } API_SET_NAMESPACE_ENTRY, *PAPI_SET_NAMESPACE_ENTRY; typedef struct _API_SET_VALUE_ENTRY { DWORD Flags; DWORD NameOffset; DWORD NameLen; DWORD ValueOffset; DWORD ValueLength; } API_SET_VALUE_ENTRY, *PAPI_SET_VALUE_ENTRY; PAPISET_SCHEMA_HEADER_V6 apisethead = NULL; PAPI_SET_NAMESPACE_ENTRY apinsentry = NULL; PAPI_SET_VALUE_ENTRY apivalentry = NULL; </code></pre> <p>compiled and linked in win 10 x64 vc 2019 community as x64 binary with</p> <pre><code>cl /Zi /W4 /analyze /Ehsc /Od apisetres.cpp /link /release </code></pre> <p>executed to print both virtual dll as well as logical dll names</p> <pre><code>:\&gt;apisetres.exe &gt; output.txt :\&gt;head -n 15 output.txt Version Number = 6 MapSize = 1c6b4 isSealed = 0 Number of Apisets = 37a Offset to NameSpace Entries = 1c Offset To hash Entries = 1aae4 Hash Multiplier = 1f 61c 538c api-ms-onecoreuap-print-render-l1-1-0 53d8 59d8 53ec printrenderapihost.dll 634 5418 api-ms-win-appmodel-identity-l1-2-0 5460 5a60 5474 kernel.appcore.dll 64c 5498 api-ms-win-appmodel-runtime-internal-l1-1-7 54f0 5af0 5474 kernel.appcore.dll 664 5504 api-ms-win-appmodel-runtime-l1-1-3 5548 5b48 5474 kernel.appcore.dll 67c 555c api-ms-win-appmodel-state-l1-1-2 559c 5b9c 5474 kernel.appcore.dll 694 55b0 api-ms-win-appmodel-state-l1-2-0 55f0 5bf0 5474 kernel.appcore.dll 6ac 5604 api-ms-win-appmodel-unlock-l1-1-0 5648 5c48 5474 kernel.appcore.dll 6c4 565c api-ms-win-base-bootconfig-l1-1-0 56a0 5ca0 56b4 advapi32.dll </code></pre> <p>the hash entries ripped and pasted to a file named hashdump<br /> sorted the hashes index wise instead of default name wise<br /> independnatly confirmed first 4 names by hashing them using hash algo described in the study with a python script as below</p> <pre><code>#index wise sorting of hashkeys from apisetschema.dll raw data import numpy as np np.set_printoptions(formatter={'all':lambda x: format(x , '08X')}) a = np.fromfile('hashdump',np.dtype([('hash', '&lt;u4'), ('index', '&lt;u4')])) b = sorted(a,key = lambda x: x[1]) c = list(filter(None,b)) print( c[0],c[1],c[2],c[3] ) #hashing actual virtual dll names excluding last hyphen apn = [ &quot;api-ms-onecoreuap-print-render-l1-1&quot;, &quot;api-ms-win-appmodel-identity-l1-2&quot;, &quot;api-ms-win-appmodel-runtime-internal-l1-1&quot;, &quot;api-ms-win-appmodel-runtime-l1-1&quot; ] for j in range(0,len(apn),1): hashfactor = 0x1f hashkey = 0 for i in apn[j]: hashkey = (hashkey * hashfactor + ord(i)) &amp; 0xffffffff print(&quot;(%08X, %08x)&quot; % (hashkey,j),end =' ') </code></pre> <p>actual hashes index wise from apisetschema.dll versus algorithmic hashing of names from output.txt</p> <pre><code>:\&gt;apisethash.py (BFEC7B66, 00000000) (1079FB19, 00000001) (59E37344, 00000002) (3655E8BE, 00000003) (BFEC7B66, 00000000) (1079FB19, 00000001) (59E37344, 00000002) (3655E8BE, 00000003) :\&gt; </code></pre>
31071
2022-11-02T14:33:38.080
<p>I'm tracking a function called CreateIoCompletionPort in dns.exe. The import tab in IDA shows that it's imported from api-ms-win-core-io-l1-1-0.dll. However, it appears in .rdata section in the .dll file. How to find the assembly code of this function?</p> <pre><code>.rdata:000000018000110B aCreateiocomple db 'CreateIoCompletionPort',0 .rdata:000000018000110B ; DATA XREF: .rdata:off_1800010A4↑o .rdata:0000000180001122 ; Exported entry 2. CreateIoCompletionPort .rdata:0000000180001122 public CreateIoCompletionPort .rdata:0000000180001122 ; HANDLE __stdcall CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort, ULONG_PTR CompletionKey, DWORD NumberOfConcurrentThreads) .rdata:0000000180001122 CreateIoCompletionPort db 'kernel32.CreateIoCompletionPort',0 .rdata:0000000180001122 ; DATA XREF: .rdata:off_180001088↑o .rdata:0000000180001142 aDeviceiocontro db 'DeviceIoControl',0 ; DATA XREF: .rdata:off_1800010A4↑o .rdata:0000000180001152 ; Exported entry 3. DeviceIoControl .rdata:0000000180001152 public DeviceIoControl </code></pre>
Reverse function in .rdata field
|ida|windows|
<p>The best way to learn is really 4 things:</p> <ol> <li><p>Search up &quot;Crackme&quot; and &quot;reverseme&quot; on your favorite search engine</p> </li> <li><p>Go to CTFTime.org, <a href="https://www.picoctf.org/" rel="nofollow noreferrer">https://www.picoctf.org/</a> and similar sites, and work on the Reverse Engineering challenges there</p> </li> <li><p>Try reverse engineering actual software you are interested in learning</p> </li> <li><p>Learn about interaction between the operating system and the application you are reverse engineering interact. For example on Windows, learning the WinAPI would be useful, and on Linux the Linux programming interface. The reason is that you will know simply by a program's imported functions on those operating systems what it is likely doing in a broad sense. Like, if it imports networking and cryptography OS APIs, well, you can surmise what it might be doing, etc...</p> </li> </ol> <p>You could also look at YouTube videos. Other than that, it's basically trial and error, there aren't really many &quot;official courses&quot; on it tbh. AFAIK, there isn't an equivalent to something like leetcode or AlgoExpert aside from that I suggested.</p>
31079
2022-11-04T02:20:48.220
<p>As a developer, reverse engineering has always fascinated me. It amazes me to see what some people can figure out just from a dump of assembly code, and I would like to become better at doing the same.</p> <p>There are many websites that specialize in helping developers become better at writing code and solving problems through small challenges. An example of what I mean are websites like LeetCode, Codewars, etc. What websites are available with challenges that are specific to reverse engineering?</p>
Are there websites for reverse engineering challenges similar the programming challenges?
|decompilation|
<p>The first problem in your example is that the fields are defined as bytes, not dwords. Press <kbd>D</kbd> twice on those fields to turn them into dwords.</p> <p>The second problem is that the fields don't have proper function pointer types applied to them. Highlight the fields and press <kbd>Y</kbd> to set the type. Enter something like <code>void (__thiscall *ReadBytes)(stream_t *this, package_t *package, size_t size)</code> to create a function pointer type.</p>
31084
2022-11-04T23:16:34.290
<p>I have following function:</p> <pre><code>void __thiscall ParsePackage_v5(package_t *package, stream_t *stream) { (*(*package-&gt;stream + 8))(package-&gt;stream, package, 4); } </code></pre> <pre><code>.text:0069F5A0 ; void __thiscall ParsePackage_v5(package_t *package, _DWORD stream) .text:0069F5A0 ParsePackage_5 proc near ; CODE XREF: ParsePackageHeader+FB↓p .text:0069F5A0 .text:0069F5A0 push ebp .text:0069F5A1 mov ebp, esp .text:0069F5A3 sub esp, 134h .text:0069F5A9 push ebx .text:0069F5AA push esi .text:0069F5AB push edi .text:0069F5AC mov esi, ecx .text:0069F5AE mov ecx, [esi+4] .text:0069F5B1 mov eax, [ecx] .text:0069F5B3 push 4 .text:0069F5B5 push esi .text:0069F5B6 call dword ptr [eax+8] </code></pre> <p><code>stream_t</code> defines as:</p> <pre><code>00000000 stream_t struc ; (sizeof=0x14, align=0x4, mappedto_136) 00000000 unknown db ? 00000001 db ? ; undefined 00000002 db ? ; undefined 00000003 db ? ; undefined 00000004 hFile dd ? ; offset 00000008 ReadBytes db ? 00000009 db ? ; undefined 0000000A db ? ; undefined 0000000B db ? ; undefined 0000000C field_C db ? 0000000D db ? ; undefined 0000000E db ? ; undefined 0000000F db ? ; undefined 00000010 field_10 db ? 00000011 db ? ; undefined 00000012 db ? ; undefined 00000013 db ? ; undefined 00000014 stream_t ends </code></pre> <p><code>(*(*package-&gt;stream + 8))</code> supposed to be converted into <code>package-&gt;stream-&gt;ReadByte</code> but it wont. How can i do this properly and declare function pointer as field type of <code>ReadByte</code>?</p>
Function pointer as struct field in IDA
|ida|
<p>Update: First, you need the base address of the module where your <code>loc_...</code> or <code>sub_...</code> is. To get it, do:</p> <pre><code>var adr = Process.findModuleByName(&quot;YOURMODULENAME&quot;)[&quot;base&quot;]; </code></pre> <p>Then, get the offset of your <code>loc_...</code> or <code>sub_...</code>. It is easy since they are named from it, like so: <code>loc_342964</code>. So now, add this offset to the base of your module like so:</p> <pre><code>var n_adr = adr.add(ptr(0x342964)); </code></pre> <p>You can ensure it is the correct address by displaying the instruction at the place of the address by:</p> <pre><code>console.log(Instruction.parse(n_adr).toString();); </code></pre> <p>If it is not a procedure, use:</p> <pre><code>console.log(Memory.ReadCString(n_adr);); </code></pre> <p>The you can attach it like this:</p> <pre><code>Interceptor.attach(n_adr, function() { console.log(JSON.Stringify(this.context)); }); </code></pre> <p>To edit values, edit directly the <code>this.context</code> object. Ex:</p> <pre><code>Interceptor.attach(n_adr, function() { this.context.w0 = ptr(0x0); }); </code></pre>
31100
2022-11-07T19:18:56.947
<p>Is it possible to hook a <code>sub_...</code> object in Frida ? I disassembled an <code>arm64</code> executable, when running the app on my iPhone, I can see a lot of classes also in the disassembled executable, but I can't reach these <code>sub_...</code> objects. If this is possible, I'd like to know how can I edit them to change a certain procedure (in my case <code>b.ne</code> to <code>b.eq</code>), and also if it is possible to hook some <code>loc_...</code> objects.</p> <p>Thanks for all your answers.</p>
frida hook `loc_*` or `sub_*`
|disassemblers|ios|javascript|frida|assembler|
<p>There’s no single solution for every case but basically you need to use the decompiler’s interactive features:</p> <ul> <li>Renaming</li> <li>Retyping</li> <li>Commenting</li> <li>Navigation between different functions</li> </ul> <p>Just looking at small parts of the function and renaming a few variables to some name which makes sense can go a long way. Start small and keep making changes until things start to make sense. Sometimes you may need yo visit multiple functions to see how a specific variable is used to figure out its type.</p>
31103
2022-11-08T07:19:45.273
<p>Some codes in IDA are not clear enough. Especially when they do reference after calculation</p> <pre><code>while ( dx33[rdi24] ); if ( rax35 != &amp;WPP_GLOBAL_Control &amp;&amp; (*((_BYTE *)rax35 + 68) &amp; 2) != 0 &amp;&amp; *((_BYTE *)rax35 + 65) &gt;= 4u ) { WPP_SF_sd( (unsigned int)rax35[7], 22, (unsigned int)&amp;WPP_b7e02e4f98cc3b1bbc566e561d210229_Traceguids, (_DWORD)dx33, rdi24 - 1); dx33 = Str; } if ( (_DWORD)rdi24 != 1 &amp;&amp; dx33[(int)rdi24 - 1] == 46 &amp;&amp; dx33[(int)rdi24 - 2] == 46 ) { dx33[(int)rdi24 - 1] = 0; dx33 = Str; } </code></pre> <p>For some parts like</p> <blockquote> <p>(*((_BYTE *)rax35 + 68) &amp; 2)</p> </blockquote> <p>Can I change it to a more human-readable form? I remember changing the function argument type like int a1 to JNIEnv* can make the pointer reference more readable because it recovers some JNI function names so that</p> <blockquote> <p>...<em>(_DWORD</em>)(a1+312)(a1,v9)</p> </blockquote> <p>will become something like</p> <blockquote> <p>-&gt;func(a1,v9)</p> </blockquote> <p>But I'm not sure how to do this for other types.</p>
How to make pseudocode in IDA more human readable
|ida|
<p>Shift/rotate with an immediate byte didn't exist until the 80186. On the 8086 only shifting/rotating by 1 or CL was possible. So it is likely you have some 8086 code.</p>
31116
2022-11-09T19:32:14.913
<p>I came across the following piece of 16-bit x86 code for multiplying a value by 40, using just shifts and additions:</p> <pre><code>; BX holds the value we want to multiply. ; The result is stored in AX. MOV AX, BX ; Multiply by 4 using two shifts SHL AX, 1 SHL AX, 1 ; Add the original value, this gives us BX * 5 ADD AX, BX ; Now multiply by 8 using three shifts for the final result SHL AX, 1 SHL AX, 1 SHL AX, 1 </code></pre> <p>Now what I'd like to know is why this code uses multiple shifts in a row instead of just doing <code>SHL 2</code> and <code>SHL 3</code>. It was almost certainly written by hand, so I assume there was some speed benefit or something. Does anyone have any insights?</p> <p>The code was written in 1991 and was targeting 286 and 386 class machines.</p>
Why does this code use multiple shifts instead of one?
|disassembly|x86|
<p>the last two seems to be right <strong>x38274</strong> where x is base<br /> which would normally change during evey run because of ASLR (Address Space Layout Randomization)</p> <p>and your code as is doesnt seem to correct ? GetModuleBaseAddress doesn't seem to be a documented Windows API<br /> googling shows it return a DWORD ? NOT a HMODULE as required by GetModuleInformation()<br /> HMODULE in x64 is 8 bytes wide while a DWORD is 4 bytes<br /> there may be truncation problem (have you compiled with all warnings enabled and corrected the warnings</p> <p>anyway shown below is a sample getmba.cpp compiled and linked as getmba.exe in winx-x64-vs2019 with</p> <pre><code>cl /Zi /W4 /analyze /Od /EHsc getmba.cpp /link /release #include &lt;stdio.h&gt; #include &lt;windows.h&gt; #include &lt;Psapi.h&gt; int main(void) { MODULEINFO mi = {0}; HANDLE curproc = GetCurrentProcess(); HMODULE curmod = GetModuleHandleA(&quot;getmba.exe&quot;); if (curproc != NULL &amp;&amp; curmod != NULL) { GetModuleInformation(curproc, curmod, &amp;mi, sizeof(MODULEINFO)); printf(&quot;Entry Point = %p\nBase Of Dll = %p\n&quot;, mi.EntryPoint , mi.lpBaseOfDll ); } } </code></pre> <p>executing the compiled binary gives</p> <pre><code>Entry Point = 00007FF7EE14143C Base Of Dll = 00007FF7EE140000 </code></pre> <p>confirming with dumpbin</p> <pre><code>dumpbin /headers getmba.exe | find &quot;entry&quot; 143C entry point (000000014000143C) mainCRTStartup </code></pre>
31119
2022-11-10T15:07:47.450
<p>I am trying to get the entry point of an executable game file.<br /> I have used 3 ways, 2 programs, and 1 c++ code.</p> <p><a href="https://i.stack.imgur.com/8ZOBT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8ZOBT.png" alt="" /></a></p> <p>C++ Code:</p> <pre><code>HMODULE GetModuleHandle(CONST CHAR* ModuleName, DWORD ProcessId) { HMODULE hModule = 0; HANDLE Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcessId); MODULEENTRY32 ModuleEntry32 = { 0 }; ModuleEntry32.dwSize = sizeof(MODULEENTRY32); if (Module32First(Snapshot, &amp;ModuleEntry32)) { do { if (strcmp(ModuleEntry32.szModule, ModuleName) == 0) { hModule = ModuleEntry32.hModule; break; } } while (Module32Next(Snapshot, &amp;ModuleEntry32)); } CloseHandle(Snapshot); return hModule; } int main(int argc, char** argv) { PROCESSENTRY32 ps; MODULEINFO mi; HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); ps.dwSize = sizeof(PROCESSENTRY32); while (Process32Next(hsnap, &amp;ps)) { if (strcmp(&quot;ms.exe&quot;, ps.szExeFile) == 0) break; } CloseHandle(hsnap); HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, false, ps.th32ProcessID); if (!process) exit(0); GetModuleInformation(process, GetModuleHandle(&quot;ms.exe&quot;, ps.th32ProcessID), &amp;mi, sizeof(MODULEINFO)); std::cout &lt;&lt; std::hex &lt;&lt; mi.EntryPoint; return 0; } </code></pre> <p><strong>How do I know which one is the correct entry point?</strong><br /> Note that what I care about is the C++ code.</p>
I have gotten three different entry points which one is the correct one?
|c++|process|entry-point|
<p>I was post a answer in Stack Overflow, and this is the code:</p> <pre><code>HMODULE hMod = LoadLibrary(&quot;foo.dll&quot;); PIMAGE_NT_HEADERS NtHeaders = (PIMAGE_NT_HEADERS)(hMod + ((PIMAGE_DOS_HEADER)hMod)-&gt;e_lfanew); PIMAGE_SECTION_HEADER SectionHeaders = IMAGE_FIRST_SECTION(NtHeaders); PIMAGE_SECTION_HEADER codeSection2; for (WORD SectionIndex = 0; SectionIndex &lt; NtHeaders-&gt;FileHeader.NumberOfSections; SectionIndex++) { PIMAGE_SECTION_HEADER SectionHeader = &amp;SectionHeaders[SectionIndex]; if (SectionHeader-&gt;Characteristics &amp; IMAGE_SCN_CNT_CODE){ codeSection2 = SectionHeader; break; } } IMAGE_SECTION_HEADER codeSection = *codeSection2; FreeLibrary(hMod); </code></pre>
31126
2022-11-11T01:46:37.450
<p>I am trying to read the binary code in the text section of an executable game file (PE) programmatically but I don't know the start address and the end address of the text section. I am using C++/Win32Api to do that mission. Are there functions that can help me for that purpose?</p> <p>Notice: I have searched a lot but I didn't find anything related to that.</p>
How do I get the start address of the 'code section' and its size to know the end address?
|c++|binary|address|section|
<p>I have solved it with:</p> <pre><code>for func_node in cfg.functions.values(): for block in func_node.blocks: c = block.capstone for i in c.insns: f.write(' '.join(re.findall(r'.{1,2}', i.insn.bytes.hex())).upper() + '\t\t' + i.mnemonic.upper() + &quot; &quot; + i.op_str.upper() + '\n') </code></pre>
31137
2022-11-15T15:47:13.267
<p>I'm developing a python script for Angr that has to print as output something in the form of:</p> <pre><code>Instruction_disassembled opcode_bytes_of_instruction </code></pre> <p>This is my python script:</p> <pre><code> f = open(sys.argv[2], 'w') base_addr = 0x100000 p = angr.Project(sys.argv[1], auto_load_libs = False, load_options = {'main_opts':{'base_addr': base_addr}}) cfg = p.analyses.CFGFast() cfg.normalize() for func_node in cfg.functions.values(): for block in func_node.blocks: print(re.sub(r'.', '', str(block.disassembly), count = 10) + '\t' + block.bytes.hex()) </code></pre> <p>With my script I'm receiving an output that has two things that I don't want: addresses at the beginning of the line and the opcode bytes that are printed all at the end of the block instead at the end of each line, for example:</p> <pre><code>endbr64 0x101004: sub rsp, 8 0x101008: mov rax, qword ptr [rip + 0x2fd9] 0x10100f: test rax, rax 0x101012: je 0x101016 f30f1efa4883ec08488b05d92f00004885c07402 </code></pre> <p>Unfortunately the block is being printed as a whole and I can't either remove the addresses or print correctly the opcode bytes.</p> <p>Can you tell me another way to iterate through the functions in order to have the single instructions or how can I parse this? Thank you in advance.</p>
Clean Angr disassemble output
|disassembly|python|disassemblers|angr|
<p>Generally this would <em>not</em> be considered a vulnerability, <strong>no</strong>.</p> <p>You aren't giving details, so I cannot speak for your specific case. You don't even mention the operating system [1].</p> <h2>Why? A hypothetical scenario on Windows</h2> <p>But let's assume Windows 10/11 for a second. The <code>BUILTIN\Administrators</code> alias and also the built-in <code>Administrator</code> principal (RID == 500) has certain powers that provide pathways into the <a href="https://en.wikipedia.org/wiki/Trusted_computing_base" rel="nofollow noreferrer">TCB</a>. One such way would be a service. While still being user mode (UM), it allows an administrator to execute code as <code>NT AUTHORITY\SYSTEM</code> (aka &quot;LocalSystem&quot;) or <code>NT SERVICE\TrustedInstaller</code>. Enabling all privileges in that user context will bestow a lot of power already. But we can take it one further. The service control manager (SCM) isn't just responsible for UM services, but also for kernel mode (KM) drivers, with the exception of PnP drivers. So, an administrator could install a driver (perhaps after enabling test signing via <code>bcdedit</code>) and then simply read/write kernel memory at will by talking to that driver (<code>ReadFile</code>/<code>WriteFile</code> or <code>DeviceIoControl</code>).</p> <p>So as you can see an administrator has <em>already</em> the privileges necessary to run code that can read/write kernel memory.</p> <p>That's why it would not be considered a vulnerability.</p> <hr /> <h2>... however</h2> <p>Suppose that little precondition with already being an administrator didn't exist. Something, <a href="https://github.com/namazso/physmem_drivers" rel="nofollow noreferrer">such as a vulnerable driver</a>, would allow an <em>unprivileged user</em> to read/write kernel memory. That would be a vulnerability for sure and <a href="https://www.microsoft.com/en-us/wdsi/driversubmission" rel="nofollow noreferrer">you could report the responsible kernel mode driver here</a>.</p> <hr /> <p>[1] Consider modern Linux. <em>If</em> whatever you found would allow a rootless container (think Podman) to read/write kernel memory of the hosting kernel, that'd be a huge issue and most certainly be considered a vulnerability. Back on Windows if an app container or code in a silo could read/write kernel memory that would be comparable (these entities generally have less privileges than any administrator on the system hosting the container/silo).</p>
31138
2022-11-15T22:32:23.843
<p>Does arbitrary kernel read write from usermode count as a vulnerability if it requires admin or is it fine since it requires admin?</p>
does arbitrary kernel read write from usermode count as a vulnerability if it requires admin
|kernel|vulnerability-analysis|
<p>the first instruction is a read<br /> the second instruction is a write<br /> the third instruction is a compare</p> <p>arg0 , arg_8 are arguments provided to the function and is provided by the caller like</p> <pre><code>call xyz(arg0,arg1....argn); </code></pre> <p>normally arguments provided to a function are not modified unless the argument is a <strong>pass by reference</strong></p> <p>for understanding opcodes operation you must understand</p> <ol> <li>how an opcode works</li> <li>what are its operands ,</li> <li>how many operands does it take</li> <li>what is result of the operation</li> <li>which flags are affected</li> <li>what exceptions are raised</li> <li>what is the mode in which this opcode can be used</li> <li>are there any bitwise exceptions</li> <li>are there modifiers to the opcode</li> <li>Compatibility etc these are all described in intel / amd manuals<br /> or you can use any online reference like <a href="https://www.felixcloutier.com/x86/and" rel="nofollow noreferrer">reference for and opcode </a></li> </ol> <p>if you go through the linked reference you will understand that the operand can be an immediate (constant value , [imm8 , imm16 , imm32 )<br /> or register (al...,r8 or ax...,r16 or eax...,r32)<br /> or memory (byte,m8 or word , m16 or dword , m32)</p> <p>based on the description infer the type of your operand 0E0h</p>
31143
2022-11-17T00:06:19.357
<p>Recently I have been given a set of assembly instructions which I must learn to understand. I know an <strong>extremely</strong> basic level of x86 assembly but I'm starting to come across more nuances that are very difficult for me to 'just google'. So I have to ask you <em>lovely</em> people.</p> <p>Below are the instructions</p> <pre><code>mov ecx, [esp+10h+arg_0] ... ... mov [esp+10h+arg_8], eax ... ... and al, 0E0h </code></pre> <p>Are arg_0 and arg_8 arguments supplied to the program at runtime or arguments supplied to a function within the program? Also please help me understand what 0E0h is in the last instruction. Is that a function, memory address, or hex value? Thank you.</p>
Unable to understand x86 instruction(s)
|disassembly|assembly|x86|static-analysis|
<p>To add to Ben's great answer, I double mapped the <code>.bin</code> file to both address <code>0x0</code> and <code>0x800000</code> (first two lines): <a href="https://i.stack.imgur.com/bQwQ8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bQwQ8.png" alt="enter image description here" /></a> And it now works: <a href="https://i.stack.imgur.com/p8in0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p8in0.png" alt="enter image description here" /></a> <a href="https://i.stack.imgur.com/bstss.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bstss.png" alt="enter image description here" /></a></p> <p>I learned it from <a href="https://www.youtube.com/watch?v=q4CxE5P6RUE" rel="nofollow noreferrer">this amazing video</a>.</p>
31162
2022-11-22T10:51:33.050
<p>I have a binary firmware that I'm trying to reverse engineer. I loaded it up on Ghidra, setting the file as raw binary, ARM Cortex, little endian. I used an address offset of zero for the file. And I seem to get good results. Here is the top of the file.</p> <pre><code> // // ram // ram:00000000-ram:0005d37f // assume spsr = 0x0 (Default) MasterStackPointer 00000000 00 00 03 20 addr DAT_20030000 Reset XREF[1]: Entry Point (*) 00000004 d5 2b 03 08 addr DAT_08032bd5 NMI XREF[1]: Entry Point (*) 00000008 25 2c 03 08 addr DAT_08032c25 HardFault XREF[1]: Entry Point (*) 0000000c 25 2c 03 08 addr DAT_08032c25 MemManage XREF[1]: Entry Point (*) 00000010 25 2c 03 08 addr DAT_08032c25 BusFault XREF[1]: Entry Point (*) 00000014 25 2c 03 08 addr DAT_08032c25 UsageFault XREF[1]: Entry Point (*) 00000018 25 2c 03 08 addr DAT_08032c25 </code></pre> <p>Notice how all the pointers point to <code>DAT_08######</code>? This is consistent with the well-known <code>0x08000000</code> offset typical on this architecture. But if I analyse the whole file with this offset, then this first part isn't &quot;decoded&quot; properly.</p> <p>I guess I have to split the memory mapping of the file. Currently it's as a single block, as indicated by <code>// ram:00000000-ram:0005d37f</code>.</p> <p>My question is where should I split the file, adding the offset from that point onward? Any good ways to have an educated guess? The first function, with the file as-is, appears at address <code>0x000001f0</code>, after the IRQ block.</p>
ARM (STM32) memory mapping on Ghidra: offset only part of the firmware file
|firmware|ghidra|arm|
<p><code>_ctype</code> is a common name for an array with flags used for implementing the <code>is...</code> family of C runtime function-like macros from <code>ctype.h</code> (<code>isupper</code>, <code>islower</code>, <code>isalpha</code>, <code>isdigit</code> and so on). For example, see <a href="https://github.com/syracuse-mscs-2019/simplescalar/blob/master/glibc-1.09/locale/C-ctype_ct.c" rel="nofollow noreferrer">this file</a> from early glibc:</p> <pre><code>CONST unsigned short int __ctype_b_C[] = { 0, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl|_ISspace|_ISblank, </code></pre> <p>If we assume that __ctype_b is an array of shorts, the function seems to be equivalent to:</p> <pre><code>return (__ctype_b[myChar]&gt;&gt;6 &amp; 1)==0; </code></pre> <p>or</p> <pre><code>return (__ctype_b[myChar]&amp; (1&lt;&lt;6))==0; </code></pre> <p>If the bits in the table use <a href="https://github.com/syracuse-mscs-2019/simplescalar/blob/master/sslittle-na-sstrix/include/ctype.h" rel="nofollow noreferrer">standard values</a>, <code>1&lt;&lt;6</code> corresponds to the <code>_ISpunct</code> flag, so the function seems to return <code>!ispunct(myChar)</code>;</p>
31175
2022-11-24T20:32:03.147
<p>I am getting this simplified function from the decomplication results of Ghidra, and I am having a hard time interpreting what the predicate would evaluate to since I do not have access to <code>__ctype_b</code> structure, in other words, what is this predicate indicating (eg. no blank spaces, digits only, ect...) ?</p> <pre><code>int myFunc(char myChar) { if ((*(unsigned short*)((char)myChar * 2 + __ctype_b) &gt;&gt; 6 &amp; 1) == 0) { return true; } else { return false; } } </code></pre>
How to interpret this __ctype_b based predicate?
|disassembly|decompilation|c|ghidra|
<p>As far as I can see, you are using the <code>STEAM</code>-version of the game. And also the fact that the publisher of the game: <code>Bethesda</code>, which reliably protects its investments and likes to sue others.</p> <p>That was the preface, and now, about the case:</p> <p><code>STEAM</code> games are very often packaged. Therefore, it is not always possible to work with them in IDA Pro directly without unpacking.</p> <p>From here your first question should be: is the game packaged? yes - find unpacker or download <code>drm-free</code> image from <code>gog.com</code></p> <p>in addition, the game may have <code>anti-debugging tricks</code> and IDA Pro has a tool to bypass them:</p> <p><a href="https://reverseengineering.stackexchange.com/questions/31049/how-to-hide-remote-windows-debugger-in-ida-pro">How to hide Remote Windows Debugger in IDA Pro?</a></p> <p><code>How to determine if an executable is packaged?</code></p> <p>If you can open this file in <code>IDA Pro</code> without problems and see a bunch of functions, then most likely this file is not packaged.</p> <p>If the file is packed and there is a call to <code>STEAM-api</code> functions then, there is a solution for a long time:</p> <p><code>Steamless</code>, <a href="https://github.com/atom0s/Steamless" rel="nofollow noreferrer">active fork</a></p> <p>If your goal is to write a cheat - try using the <code>Cheat Engine</code>, as well as the specialized forums: <a href="https://unknowncheats.me" rel="nofollow noreferrer">https://unknowncheats.me</a></p>
31181
2022-11-26T16:14:52.613
<p>Basically, I have this 64 bits game.exe file which is about 400mb. It takes about 24 hours to do the analysis of the file in Ida pro 64 bits free version. Problem is i have to do it again cause there were some errors apparently. So my question is this, when i run that game.exe and i attach xdbg64 to it, it shows me the assembly code of the whole process, but when i instead run that game and try to attach Ida Pro's debugger to it i don't get the same kind of information, so is there a way to display the whole program's assembly in Ida pro and also use the decompiler on some of the function while the game.exe is running? My goal is to make a single player mod for this game by hooking a specific funtion. I attached two screenshots that show the same address for both programs:</p> <p>xdbg64:</p> <p><a href="https://i.stack.imgur.com/FghHJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FghHJ.jpg" alt="xdbg64" /></a></p> <p>idaProFree:</p> <p><a href="https://i.stack.imgur.com/VyDjw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VyDjw.jpg" alt="idaProFree" /></a></p>
Instead of doing a (long) analysis of an .exe, can i run that .exe, attach Ida Pro's debugger to it, and get the pseudo code of functions i want?
|ida|x64dbg|
<p>Interpreting the values as unsigned long 64 bit integers and comparing to your dates suggests that these are date/time stamps with 100ns resolution and with a base around January 1601.</p> <p>This would be consistent with the values returned by the windows function <code>GetSystemTimePreciseAsFileTime</code>. This returns a <code>FILETIME</code> structure containing the UTC date &amp; time with a base date of 1 January 1601.</p> <p>Treating your values as <code>FILETIME</code>s and formatting appropriately (using <code>SHFormatDateTime</code>) gives the following values -</p> <pre><code>01D24B8D39F74246 =&gt; 01 December 2016, 04:41:48 01C13A1813C15385 =&gt; 10 September 2001, 17:46:02 01C10293F18E497D =&gt; 02 July 2001, 02:11:37 01D8EF37B8D70194 =&gt; 03 November 2022, 03:52:41 </code></pre> <p>The dates are the day after you quoted. I'd surmise that this is because your dates are local time and that you are 5 or more hours behind UTC and installed the programs in the evening.</p> <p>In your 2nd example which has 2 dates, perhaps one is an initial installation date and the other is some form of update date ?</p>
31188
2022-11-27T18:05:33.690
<p>I am looking at the registry keys created for three programs from a now defunct company, one of which is trial software. One entry of interest is the REG_BINARY key InstallTime. I have an idea of what the dates are supposed to be based on program install times. Actually, more curiously, it has different values under HKLM\SOFTWARE\WOW6432Node</p> <p>First line is under HKCU\SOFTWARE, second is under HKLM\SOFTWARE\WOW6432Node</p> <p>11/30/16<br /> CBHome</p> <pre><code>46 f2 f7 39 8d 4b d2 01 46 f2 f7 39 8d 4b d2 01 </code></pre> <p>7/1/01<br /> CBPro</p> <pre><code>85 53 c1 13 18 3a c1 01 7d 49 8e f1 93 02 c1 01 </code></pre> <p>11/2/22<br /> CWViewer</p> <pre><code>94 01 d7 b8 37 ef d8 01 94 01 d7 b8 37 ef d8 01 </code></pre> <p>It wasn't until I put this together that I realized that they match except for the second one. Not sure why.</p>
Unusual datetime format
|binary|
<p>These are simple XOR checksums. Here's how they work using a short message as an example:</p> <pre><code>STX |&lt;------------- data --------------&gt;|s1 |s2 02 30 80 41 44 3b 43 57 ff 03 66 e4 </code></pre> <p>The values <code>s1</code> and <code>s2</code> are calculated separately over only the data portion; the start of text (STX) character is not used for the check bytes. Here's pseudo-code with all quantities being 8-bit values.</p> <pre><code>s1 = 0 s2 = 0 for (each b in data) s1 = s1 ^ b s2 = ror(s2) ^ b </code></pre> <p>The <code>ror</code> here stands for &quot;rotate right&quot; which rotates the 8-bit quantity to the right by one bit:</p> <pre><code> +---+---+---+---+---+---+---+---+ Before: | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ After: | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | +---+---+---+---+---+---+---+---+ </code></pre> <h2>How I figured it out</h2> <p>I noticed that, ignoring the last two bytes, each pair of messages differed by a single bit, b<sub>0</sub> (the low bit). The <code>s1</code> byte also differed by only the low bit, so I guessed something like a sum or XOR. Doing an XOR over all bytes except the first (<code>02</code>) and the last (<code>s2</code>) yielded 0 for all samples, so that was <code>s1</code> figured out.</p> <p>For <code>s2</code>, the pairs of message also differed in only a single bit, but the position was different for each pair, so I assumed it was a linear operation and I guessed that there was some rotation happening that would shift the position of the changed bit depending on the length of the message. After a few guesses, I hit upon the algorithm described above.</p> <p>Also the changing bit <code>30</code> or <code>31</code> was probably a &quot;toggle bit.&quot; Many serial protocols employ one. The idea is that for each message sent, the bit changes so that way it's possible to tell whether the message is a duplicate or a new message. Any retransmitted message would leave the bit unchanged; only new messages change the state.</p> <h2>In Java</h2> <p>I don't much like Java, but if that's what you're using, this is an implementation that works.</p> <pre><code>public class MyClass { public static byte ror(byte c) { return (byte)(((c &gt;&gt; 1) &amp; 0x7f) | (c &lt;&lt; 7)); } public static byte[] getXOR(byte[] data) { int s1 = 0; int s2 = 0; for (byte b : data) { s1 = (s1 ^ b); s2 = ror((byte)s2) ^ b; } return new byte[]{(byte)(s1), (byte)(s2)}; } public static void main(String args[]) { byte[] data = new byte[]{0x31,(byte)(0x80),0x41,0x44,0x3B,0x43,0x57,(byte)(0xFF),0x03}; byte[] x = getXOR(data); System.out.println(String.format(&quot;%x %x&quot;, x[0], x[1])); } } </code></pre>
31193
2022-11-28T15:28:07.780
<p>So, I wanted repurpose some old boarding gate scanners and I'm trying to make use of their commands.</p> <p>Now, I have a dump from an actual boarding gate PC and I've noticed that the commands only work if I send them as they are on the dump. If I change even a single byte, the scanner rejects the command. After some Googling, I came across the term 'CRC' and now I understand why that is the case.</p> <p>I played around with some CRC calculators, but the scanner seems to have its own algorithm and I have trouble figuring it out.</p> <p>For instance, the command that displays a message on the scanner's display is 'AD;MG#P#ATESTMESSAGE'.</p> <p>Here's an example from the dump:</p> <pre><code>02 30 80 41 44 3B 4D 47 23 50 23 41 4E 4F 54 20 .0.AD;MG#P#ANOT 49 4E 20 55 53 45 0D 42 0D FF 03 3A 12 IN USE.B...:. </code></pre> <p>I noticed that the same exact command is sent in one more way that's slightly different:</p> <pre><code>02 31 80 41 44 3B 4D 47 23 50 23 41 4E 4F 54 20 .1.AD;MG#P#ANOT 49 4E 20 55 53 45 0D 42 0D FF 03 3B 92 IN USE.B...;. </code></pre> <p>Although the message is the exact same, the difference in the command header seems to have an effect on the last two bytes.</p> <p>All command headers either start with '02 30 80' or '02 31 80' depending on the response header of the scanner. Kind of like 'ping-pong' (I couldn't think of a better way to describe this).</p> <p>I have tried decompiling <a href="https://pastebin.com/jdQm1zq0" rel="noreferrer">the scanner's firmware</a> but I can't seem to locate the method where it checks for the CRC.</p> <p><a href="https://pastebin.com/rGDqLuDi" rel="noreferrer">Here's a few more command pairs</a> in case they help.</p> <p>Any help is greatly appreciated!</p> <p>P.S: I'm a completely new to all this, in case you couldn't tell.</p>
Figuring out a (possibly 16-bit) CRC algorithm
|crc|
<p>There will always be research, you just have to pick the right search terms.</p> <p>For example, searching for <code>research paper binary analysis</code> led to &quot;Proceedings 2021 Workshop on Binary Analysis Research&quot;.</p> <p>You can also use the advanced search at ScienceGate to restrict the results by year - <a href="https://www.sciencegate.app/app/search" rel="nofollow noreferrer">https://www.sciencegate.app/app/search</a></p>
31198
2022-11-30T21:05:55.503
<p>I am searching research papers related to reverse engineering between 2020 and 2022 but did not found good papers with latest research in the direction of reverse engineering. So, what are the latest research or technology in direction of reverse engineering?</p>
What are latest research in reverse engineering?
|ida|windows|ollydbg|pe|
<p>After many much trial and errors i finally managed to make it work. Here is a walkthrough:</p> <p>Let's say you want to log (in the log window of x64dbg) the value of the rbx register at a specific address, but only if that value has changed since the last log.</p> <p>Right click on an address and choose Breakpoint =&gt; Set Conditional Breakpoint.</p> <p>We must now declare a variable (global i assume) that will be used to store the value of rbx, so type this in the command line at the bottom and press enter to validate (example name): var myCounter</p> <p><a href="https://i.stack.imgur.com/AtM3R.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AtM3R.jpg" alt="enter image description here" /></a></p> <p>Then fill up the pop up window like the screenshot:</p> <ul> <li>Break Condition: 0 on cause we only want the log not the breakpoint.</li> <li>log Text: ouputs some text + the value of rbx</li> <li>Log Condition: only log if the value of rbx has changed</li> <li>Command Text: using this just to update the value of myCounter for the next evaluation.</li> <li>Command Condition: 1, (afaik but i could be wrong) the command text will only be executed if the log condition is true, so we'll update the value of myCounter only if myCounter has changed which is what we want.</li> </ul> <p><a href="https://i.stack.imgur.com/03d8k.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/03d8k.jpg" alt="enter image description here" /></a></p> <p>Feel free to comment if there is a better way to achieve this as, the reason why i needed this &quot;feature&quot; was because when logging data i would sometimes get 1000 lines per second, so that's a way to counter that.</p>
31205
2022-12-01T18:28:17.167
<p>What i'm trying to achieve is to use a conditional breakpoint, that never actually breaks but logs in x64dbg's console the value of r9 only when it changes, to prevent console cluttering. But i do not understand how to set the expression for the log condition. On a higher level the pseudo code of what i want to achieve could be:</p> <pre><code>static last_r9 = 0; if(r9 != last_r9){ Log(); last_r9 = r9; } </code></pre> <p>Is is even possible to achieve something like that?</p> <p>Here's an screenshot just for reference:</p> <p><a href="https://i.stack.imgur.com/q298c.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q298c.jpg" alt="enter image description here" /></a></p>
x64dbg: Conditional breakpoint: how to log only if register value has changed?
|x64dbg|
<p>Ok, I got it... In an arbitrary place in the program I put this:</p> <pre><code>call 0x7C8731B9 // kernel32.AllocConsole() push 0x21 // '!' call _putch // this print one char '!' push 0x00553D91 // some string call _cputs // this print string </code></pre> <p>In my case no need to use <strong>GetStdHandle</strong> after <strong>AllocConsole</strong></p>
31208
2022-12-02T00:36:30.450
<p>Is there a working way to embed the windows console in disasm code? I tried <strong>AllocConsole</strong> with <strong>GetStdHandle</strong> or <strong>AttachConsole</strong> with <strong>PID</strong> of an existing console but it didn't work. I have tried <strong>printf</strong> and <strong>putchar</strong> with no success. I can make a console and be able to change the title (fancy way to get printf:))) but instead of output I get a black screen. I'm on XP and trying to get the status of I/O ports in an old MFC application. MessageBox is a good alternative, but I/O ports send thousands of messages per second. I will be happy even if x32dbg will have this function for logging registry value somehow but new versions doesn't work on my XP</p>
How to call Windows console in ASM and printf some values there?
|windows|x64dbg|patch-reversing|assembly|
<p>So, a friend figured it out for me.</p> <p>So, according to the <code>binwalk</code> in the OP, one can see that U-Boot is at offset <code>0x8000</code> on the file. But this contains a header, pushing actual U-Boot to <code>0x8040</code>.</p> <p>Now, one only needs to load this file on Ghidra with offset <code>0x8040</code> and with the usual base address of <code>0x4A00'0000</code>:</p> <p><a href="https://i.stack.imgur.com/5PVkI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5PVkI.png" alt="enter image description here" /></a></p>
31218
2022-12-03T12:07:29.613
<p>I'm trying to do some REing on a vendored U-Boot bootloader image.</p> <p>For context, the U-Boot image was extracted from the full firmware image with:</p> <pre><code>dd if=&lt;firmware&gt;.img of=uboot_sdcard.bin bs=1024 skip=8 count=512 seek=0 </code></pre> <p>Then I ran <code>binwalk</code> on the image:</p> <pre><code>$ binwalk uboot_sdcard.bin DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 16908 0x420C CRC32 polynomial table, little endian 32768 0x8000 uImage header, header size: 64 bytes, header CRC: 0x1701FCC6, created: 2022-11-10 01:20:36, image size: 407733 bytes, Data Address: 0x4A000000, Entry Point: 0x0, data CRC: 0x68F80364, OS: Firmware, CPU: ARM, image type: Firmware Image, compression type: none, image name: &quot;U-Boot 2017.11 for sunxi board&quot; 100384 0x18820 uImage header, header size: 64 bytes, header CRC: 0x207047, created: 1994-05-30 14:08:13, image size: 71753208 bytes, Data Address: 0x28809B46, Entry Point: 0xDDF82CA0, data CRC: 0x230D46, image name: &quot;&quot; 259212 0x3F48C CRC32 polynomial table, little endian 269762 0x41DC2 Android bootimg, kernel size: 1684947200 bytes, kernel addr: 0x64696F72, ramdisk size: 1763734311 bytes, ramdisk addr: 0x6567616D, product name: &quot;ddr 0x%08x size %u KiB&quot; 417648 0x65F70 Flattened device tree, size: 22917 bytes, version: 17 </code></pre> <p>My question now is, when I load this <code>uboot_sdcard.bin</code> on Ghidra, what should be the Base address? I tried the typical <code>0x4A000000</code> but some disassembly ends up with lots of warnings about not being able to resolve switch branches.</p> <p>I've had similar issues when dealing with raw binaries, and it's almost always down to sectioning the file right, or setting the base address right.</p> <p>So, I think I'm missing something here. Any pointers?</p> <p>The device uses an Allwinner SoC, which has an ARM V7 processor.</p> <p>Thanks</p>
U-boot base address on Ghidra
|binary-analysis|ghidra|arm|
<p><strong>How to change the clock-speed of a microprocessor using inline assembly language</strong></p> <p>General procedures for utilizing assembly language to overclock a microprocessor are :</p> <ul> <li><p>Ascertain the CPU and motherboard's maximum safe clock speed. It is crucial to adhere to this limit in order to protect the processor and motherboard. This will typically be stated in the documentation for your hardware.</p> </li> <li><p>Create code to read the relevant hardware registers' current clock speed. The correct registers to read from must be determined by consulting the processor's documentation.</p> </li> <li><p>Based on the maximum safe clock speed and the desired level of overclocking, choose the new clock speed you wish to set.</p> </li> <li><p>Create code to update the hardware registers with the new clock speed. Again, to find out which registers to write to, refer to the manual for your CPU.</p> </li> <li><p>Test the stability of the system using a program like LinX or Prime95 to run at the new clock speed. You can keep using the new clock speed if the system is stable. If the system is unstable, you might need to modify the BIOS or hardware settings, change the clock speed, or other factors.</p> </li> </ul> <p><em>Please keep in mind that the code i mentioned is just an example, and the specific registers and values that must be changed will depend on the microprocessor and motherboard you're using. To determine the correct values, consult the documentation for your hardware. when overclocking a microprocessor, as increasing the clock speed can also increase the power consumption and heat generation of the processor. You may need to make additional changes to the BIOS settings or hardware registers, such as increasing the voltage to the processor or adjusting the cooling settings, in order to ensure that the processor remains stable at the higher clock speed</em></p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdint.h&gt; // ハードウェアレジスタを保存する構造体 struct HardwareRegisters { uint32_t clockControl; // クロックコントロールレジスタ uint32_t voltageControl; // 電圧コントロールレジスタ uint32_t temperatureControl; // 温度コントロールレジスタ }; // ハードウェアレジスタを読み込む関数 HardwareRegisters readHardwareRegisters() { HardwareRegisters regs; // インラインアセンブリを使ってレジスタを読み込む __asm__ __volatile__ ( &quot;movl $0x0, %%eax\n\t&quot; // EAXレジスタに0を代入 &quot;rdmsr\n\t&quot; // MSRレジスタを読み込む &quot;movl %%edx, %0\n\t&quot; // 読み込んだEDXレジスタをclockControlに保存 &quot;movl %%eax, %1\n\t&quot; // 読み込んだEAXレジスタをvoltageControlに保存 &quot;movl $0x1, %%eax\n\t&quot; // EAXレジスタに1を代入 &quot;rdmsr\n\t&quot; // MSRレジスタを読み込む &quot;movl %%edx, %2\n\t&quot; // 読み込んだEDXレジスタをtemperatureControlに保存 : &quot;=m&quot;(regs.clockControl), &quot;=m&quot;(regs.voltageControl), &quot;=m&quot;(regs.temperatureControl) // 出力 : // 入力 : &quot;%eax&quot;, &quot;%edx&quot; // クリアするレジスタ ); return regs; } // ハードウェアレジスタに書き込む関数 void writeHardwareRegisters(HardwareRegisters regs) { // インラインアセンブリを使ってレジスタに書き込む __asm__ __volatile__ ( &quot;movl $0x0, %%eax\n\t&quot; // EAXレジスタに0を代入 &quot;movl %0, %%edx\n\t&quot; // clockControlをEDXレジスタに保存 &quot;movl %1, %%eax\n\t&quot; // voltageControlをEAXレジスタに保存 &quot;wrmsr\n\t&quot; // MSRレジスタに書き込む &quot;movl $0x1, %%eax\n\t&quot; // EAXレジスタに1を代入 &quot;movl %2, %%edx\n\t&quot; // temperatureControlをEDXレジスタに保存 &quot;wrmsr\n\t&quot; // MSRレジスタに書き込む : // 出力 : &quot;m&quot;(regs.clockControl), &quot;m&quot;(regs.voltageControl), &quot;m&quot;(regs.temperatureControl) // 入力 : &quot;%eax&quot;, &quot;%edx&quot; // クリアするレジスタ ); } int main() { // 現在のハードウェアレジスタを読み込む HardwareRegisters currentRegs = readHardwareRegisters(); // 最大安全クロックスピードとオーバークロックのレベルに基づいて新しいクロックスピードを決定する uint32_t newClockSpeed = currentRegs.clockControl + 1000; // クロックスピードを1000 MHz増やす // ハードウェアレジスタを新しいクロックスピードに更新する currentRegs.clockControl = newClockSpeed; writeHardwareRegisters(currentRegs); // 新しいクロックスピードでシステムの安定性をテストする // LinXやPrime95などのプログラムを使って新しいクロックスピードで実行する return 0; } </code></pre>
31246
2022-12-08T02:13:18.890
<p>new guy here. Working on Bi0S script, adding as many features as possible. It is possible to change fan speeds, advanced security, manipulate voltages, etc. <strong>How do you overclock the microprocessor using Assembly?</strong>. No not the Avengers Assembly or the UN. .. (the moderators said i have to make a clear distinction because my last post wasn't &quot;specific enough&quot; ). Preferably in Assembly (Language) or C/C++</p>
Overclock CPU in BIOS - ARM/C/C++/Py
|disassembly|assembly|hash-functions|math|
<p>The brown text is called as single instruction because the function, prologue of which we see in brown color, was not recognized by IDA as function.</p> <p>There are many possible reasons for that, for example this function may be never called directly, or there is unrecognized instruction inside. In order to make this code a function (which will make it black) by defining it as a function yourself, you can press <kbd>P</kbd> when the cursor is located on address <code>0x00405fd0</code> where the function prologue starts, or select all the functions' instructions and press <kbd>P</kbd>.</p> <p>When this code becomes function, the graphs and decompilation should start working.</p>
31251
2022-12-09T02:18:17.147
<p>Recently I got a program that has two colors of <code>.text</code> segment, one is <code>black</code> and the other is <code>brown</code>:</p> <p><a href="https://i.stack.imgur.com/pKyF3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pKyF3.png" alt="enter image description here" /></a></p> <p>While the flow chart and the decompiler work well on <code>black</code> part, they are both disabled on the <code>brown</code> part, as below:</p> <p><a href="https://i.stack.imgur.com/Q5uLZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q5uLZ.png" alt="enter image description here" /></a></p> <p>Later, I found the <code>brown</code> <code>.text</code> part is categorized as <code>Single instruction</code>, rather than <code>Regular function</code>:</p> <p><a href="https://i.stack.imgur.com/17Fed.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/17Fed.png" alt="enter image description here" /></a></p> <p>I wonder if there is a way, to make the Flow Chart and the Decompiler work for the <code>Single instruction</code> part?</p>
IDA Pro Flow Chart and Decompiler Doesn't Work on Single Instruction text
|ida|decompilation|
<p>In order to change the representation of the data to byte, word(2 bytes), dword(4 bytes) or qword(8 bytes) you can use the following shortcuts after locating the cursor at the needed adress:</p> <ul> <li><kbd>U</kbd>: undefines the data, reverts it to bytes</li> <li><kbd>D</kbd>: changes data representation (pressing it on byte makes it short, pressing it on short makes it dword, and then rolls back to byte)</li> <li><kbd>Q</kbd>: changes data representation as qword</li> <li><kbd>*</kbd>: makes data an array of the type of the element you located the cursor at, you can choose the size</li> <li><kbd>Y</kbd>: Assigns a type to an object at a specific address (for example, in your case, it may be BYTE sbox[size], choose size according to the used encryption algorithm)</li> </ul> <p>So in order to make the data at your address look like bytes, you need just to undefine the data at <code>00008004</code>, this will revert all the group of dwords to bytes. After that you can arrange the rest of the array as you want with the mentioned shortcuts.</p>
31260
2022-12-11T10:15:38.777
<p>Want to get 32 bits from 0x8000 adress as 8 bytes</p> <pre><code>MEM_EXT:00008000 db 54h MEM_EXT:00008001 db 53h, 57h, 20h MEM_EXT:00008004 dd 322E3256h, 31332030h, 30303330h, 31313320h, 43432036h MEM_EXT:00008004 dd 2F363535h, 20425345h, 865808FAh, 865808FAh, 865808FAh MEM_EXT:00008004 dd 865808FAh, 865808FAh, 865808FAh, 865808FAh, 865808FAh MEM_EXT:00008004 dd 865808FAh, 865808FAh, 865808FAh, 0FFA735A7h, 962F8E20h MEM_EXT:00008004 dd 0DF00F0h, 0DF00FFh, 0AF008Fh, 70002h, 380038h, 0FF000700h MEM_EXT:00008004 dd 0, 0, 0 </code></pre> <p>Would this be</p> <p>0x54 0x53 0x57 0x20 0x32 0x2e 0x32 0x56 ???</p> <p>How to get further 64 bits, after first 32 bits from 0x8000?</p> <p>Weird things is that 64 bits as 16 bytes should contain also 0 somwehere</p> <p>Those should be permutation and S-box key parts</p> <p>Some more info:</p> <pre><code>ROM:00000000 ; Processor : c166 [C165] ROM:00000000 ; Target assembler: Keil A166 Assembler ROM:00000000 ; Byte sex : Little endian </code></pre>
Reading memory values in IDA
|ida|disassembly|assembly|
<p>Using Chrome:</p> <ol> <li><code>More Tools -&gt; Developer Tools</code></li> <li>Within developer tools, click on the <code>Network</code> tab at the top</li> <li>Within the <code>Network</code> tab, click on <code>Media</code></li> <li>Click the play button</li> <li>An entry named <code>preview.mp3</code> should show up in the table</li> <li>Right click on <code>preview.mp3</code>, click <code>Open in New Tab</code>, then right click on the audio player and click <code>Save audio as...</code></li> </ol>
31268
2022-12-12T22:25:57.593
<p>This audio sample that I’m trying to download: <a href="https://www.audiotool.com/sample/hard_spinz_-_808" rel="nofollow noreferrer">https://www.audiotool.com/sample/hard_spinz_-_808</a> doesn’t appear to be listed when viewing the source code. I’ve looked over the whole page multiple times, tried inspect element as well, but I still can’t find a link to the embedded audio. This goes for all the other samples on the site.</p> <p>Is there a solution to this?</p>
Can’t download embedded audio
|websites|
<p>This executable format was not previously supported by Ghidra. I have written support for it and submitted a pull request:</p> <p><a href="https://github.com/NationalSecurityAgency/ghidra/pull/5004" rel="nofollow noreferrer">https://github.com/NationalSecurityAgency/ghidra/pull/5004</a></p>
31277
2022-12-14T23:26:52.510
<p>Does Ghidra 10.2.2 support loading the older <strong>a.out</strong> executable format? This format (sometimes rendered as &quot;AOUT&quot;) was used on various UNIX-like systems such as SunOS and BSD, and was the simpler predecessor to COFF. I am attempting to import and disassemble a.out files that were built for Motorola 68K / VxWorks 5.5. The Linux 'file' utility identifies them as the following, which looks correct:</p> <p><code>a.out SunOS mc68020 executable not stripped</code></p> <p>Ghidra will only import them as &quot;raw binary&quot;, but I'm not sure whether that is because the a.out format is not supported at all, or rather because the combination of target OS and architecture results in a header with magic numbers currently unknown to the loader. I looked in the <code>68000.opinion</code> file and found this section, suggesting that the AOUT format is at least partially known to Ghidra:</p> <pre><code>&lt;constraint loader=&quot;Assembler Output (AOUT)&quot; compilerSpecID=&quot;default&quot;&gt; &lt;constraint primary=&quot;1&quot; processor=&quot;68000&quot; endian=&quot;big&quot; size=&quot;32&quot; /&gt; &lt;constraint primary=&quot;2&quot; processor=&quot;68000&quot; endian=&quot;big&quot; size=&quot;32&quot; /&gt; &lt;constraint primary=&quot;200&quot; processor=&quot;68000&quot; endian=&quot;big&quot; size=&quot;32&quot; /&gt; &lt;constraint primary=&quot;300&quot; processor=&quot;68000&quot; endian=&quot;big&quot; size=&quot;32&quot; /&gt; &lt;/constraint&gt; </code></pre> <p>I'm hoping to be able to take advantage of existing Ghidra functionality for parsing the relocation tables in these binaries. Does support for this particular a.out format require a new loader class in Ghidra (or modifications to an existing class)? Or could it be done with appropriate changes to the <code>.opinion</code> file section shown above?</p>
Ghidra support for older AOUT executable format
|ghidra|motorola|
<p>Based on the <a href="https://github.com/NationalSecurityAgency/ghidra/issues/127" rel="nofollow noreferrer">link</a> provided by rce, Ghidra needs extra help to disassemble this code correctly.</p> <p>I select Language = &quot;PowerISA-VLE-64-32addr&quot; in the Ghidra project editor: Then to start the disassembly it will <strong>ONLY</strong> work by pressing the F12 key:</p> <p><a href="https://i.stack.imgur.com/71biA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/71biA.png" alt="Ghidra PowerPC VLE code" /></a></p> <p>Also with <strong>IDA pro 7.5</strong> I can disassemble my binary file. IDA pro has only two options for PowerPC: Big endian and Little endian. I selected Big Endian. When loading I chose that all the code is VLE and I get a successful disassembly:</p> <p><a href="https://i.stack.imgur.com/kiRV0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kiRV0.png" alt="IDA pro disassembly of PowerPC VLE code" /></a></p> <p>After loading the file you must press &quot;C&quot; to start the disassembly which is done very fast.</p> <p>To see also the hex bytes (blue) in the disassembly you must edit the file <strong>ida.cfg</strong> and set</p> <p>OPCODE_BYTES = 4</p> <p>because these bytes are disabled by default.</p>
31288
2022-12-19T22:29:35.460
<p>I have a binary file with code for the SPC572L64 processor from ST.</p> <p>The Datasheet can be downloaded <a href="https://www.st.com/content/ccc/resource/technical/document/reference_manual/d4/c7/37/2b/3b/f9/42/0e/DM00180298.pdf/files/DM00180298.pdf/jcr:content/translations/en.DM00180298.pdf" rel="nofollow noreferrer">here</a> and the Programmers Manual <a href="https://www.st.com/content/ccc/resource/technical/document/reference_manual/8b/6f/4e/d6/72/82/45/78/CD00164807.pdf/files/CD00164807.pdf/jcr:content/translations/en.CD00164807.pdf" rel="nofollow noreferrer">here</a>. All documents for this processor are listed <a href="https://www.st.com/content/st_com/en/search.html#q=SPC572L-t=resources-page=1" rel="nofollow noreferrer">here</a>.</p> <p>The documents say:</p> <ul> <li>One main 32-bit Power Architecture® VLE Compliant CPU core, single issue</li> <li>There is one e200z215An3 processor core on the SPC572Lx device.</li> <li>The e200z215An3 is a single-issue 32-bit PowerISA 2.06 VLE compliant design with 32-bit general-purpose registers (GPRs). The e200z215An3 core implements the VLE (variable- length encoding) ISA, providing improved code density.</li> <li>Instruction set enhancement allowing variable length encoding (VLE), encoding a mix of 16-bit and 32-bit instructions, for code size footprint reduction.</li> </ul> <p>Wikipedia says:</p> <ul> <li>Power ISA is an evolution of the PowerPC ISA, created by the mergers of the core PowerPC ISA and the optional Book E for embedded applications.</li> </ul> <p>All this confuses me more than it helps.</p> <p>I tried to disassemble the code with Ghidra trying all PowerPC options. But what comes out is garbage. Every few lines a &quot;??&quot; appears instead of valid code:</p> <pre><code> 0108003c 73 e0 e0 00 andi. r0,r31,0xe000 01080040 70 68 e0 00 andi. r8,r3,0xe000 01080044 18 ?? 18h 01080045 63 ?? 63h c 01080046 d1 a0 70 80 stfs f13,0x7080(0) 0108004a 00 ?? 00h 0108004b bf ?? BFh 0108004c 7c 89 03 a6 mtspr CTR,r4 01080050 1a ?? 1Ah 01080051 03 ?? 03h 01080052 09 00 1c 63 tdgti r0,0x1c63 01080056 00 ?? 00h 01080057 40 ?? 40h @ 01080058 7a ?? 7Ah z 01080059 20 ?? 20h 0108005a ff ?? FFh 0108005b f8 ?? F8h 0108005c 70 68 e0 00 andi. r8,r3,0xe000 01080060 70 79 c7 c0 andi. r25,r3,0xc7c0 01080064 48 c4 7c 89 bl SUB_01cc7cec </code></pre> <p>And the decompiler outputs:</p> <pre><code>void UndefinedFunction_01080000(void) { /* WARNING: Bad instruction - Truncating control flow here */ halt_baddata(); } </code></pre> <p>Can anybody give me a step by step instruction what settings I need to disassemble this processor?</p>
How to disassemble SPC572L assembler code?
|assembler|
<p>The first slot of the GOT is special. At runtime, it is patched by the dynamic loader to point to its resolver function (<code>_dl_runtime_resolve</code> or similar). That function uses information in <code>$t8</code> (symbol/relocation offset) to look up the symbol in one of the dependent shared objects and jumps to it. It also usually patches the corresponding GOT slot so that next calls go directly to the destination function and need not go through the resolver again.</p>
31297
2022-12-23T13:27:39.780
<p>I'm trying to understand this part of a MIPS binary I am reversing using IDA. I have attached screenshots of the decompilation, disassembly, and the offset passed into the <code>jalr</code> instruction.</p> <p>I am quite new to MIPS, so I think I am misunderstanding what's going on here.</p> <p>The mktime() is a stub, so I guess that must be the reason for the odd output?</p> <p>To me it looks like its just jumping to the start of the Global Offset Table, which makes no sense. Maybe it's trying to reference some function from the .got? I'm not too sure what's going on here. .GOT entry to memmove is at <code>.got:004D0D78</code>.</p> <p><code>.got:004D0D78 memmove_ptr: .word memmove</code></p> <p><a href="https://i.stack.imgur.com/BIMh1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BIMh1.png" alt="decompilation" /></a> <a href="https://i.stack.imgur.com/hF4AL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hF4AL.png" alt="disassembly" /></a> <a href="https://i.stack.imgur.com/YJIcw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YJIcw.png" alt="global offset table" /></a></p>
Confused about small MIPS disassembly snippet (jalr)
|ida|mips|
<ul> <li><p>Look for any requests to <code>document.createElement</code> or <code>document.createElementNS</code> in the code that may be creating and appending the <code>&lt;video&gt;</code> element to the DOM. You might be able to locate the <code>&lt;video&gt;</code> element by searching the child nodes of its parent element.</p> </li> <li><p>Look for any event listeners associated with the <code>&lt;video&gt;</code> element. For example, if the <code>&lt;video&gt;</code> element has a onended event listener, you could try triggering it and seeing if it produces any output in the console or other visible effects.</p> </li> <li><p>Search the code for any mentions of the <code>&lt;video&gt;</code> element. You might notice references to an attribute in the code, for instance, if the <code>src</code> attribute of the <code>&lt;video&gt;</code> element is set dynamically.</p> </li> <li><p>You might be able to locate the <code>&lt;video&gt;</code> element by looking for it in the virtual DOM or component tree if the code makes use of a JavaScript library or framework (like React or Angular).</p> </li> <li><p>If the <code>&lt;video&gt;</code> element is being used to display a video stream from a server, you may be able to locate it by inspecting the network traffic in the developer tools. For example, if the video stream is served via the HTML5 <code>MediaSource</code> API, network requests for video segments should be visible in the network panel.</p> </li> </ul>
31345
2023-01-02T14:34:45.507
<p>I am trying to debug an app which I don't own which uses HTML5 and JS, which displays a video stream. The issue is that the video stutters when viewed in high resolution.</p> <p>Note that the code is obfuscated, but has been prettyfied which helps a little. So far using Chrome developer tools and by injecting listeners I have determined that the video is being displayed in a <code>&lt;canvas&gt;</code> element. From my research, I have determined that displaying video content in <code>&lt;canvas&gt;</code> requires the use of <code>&lt;video&gt;</code>, where the data taken from the video element is manipulated and written on to the <code>&lt;canvas&gt;</code>.</p> <p>My problem is that I want to get a reference to the <code>&lt;video&gt;</code> element, which apparently is not a part of the DOM. The use of Chrome developer tools reveals no such element, nor does <code>getElementsByTagName()</code>. I find clues in the code which indicate a <code>&lt;video&gt;</code> element most likely exists, so my conclusion is that it is just used in memory as a tool and is not added to the DOM.</p> <p>Does anyone have any suggestions as to how I can get a reference to this element?</p>
HTML/JS app - getting a reference to an element which is not part of the DOM
|javascript|
<p>In this case, auto-analysis has decided that the <code>QWORDs</code> at those locations should be displayed as pointers, but the concrete data value, <code>0</code>, is not a valid pointer within the binary's address space.</p>
31347
2023-01-03T02:41:26.333
<p>I'm new to IDA.</p> <p>Refer here: <a href="https://reverseengineering.stackexchange.com/questions/21140/red-text-highlight-in-ida-pro">Red text Highlight in IDA Pro</a></p> <p>But I can't find any useful in Problem Window.</p> <p><a href="https://i.stack.imgur.com/NGvPx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NGvPx.png" alt="enter image description here" /></a></p>
What the meaning of RED dq in .data?
|ida|
<p>First of all you can attach x32dbg to the process where PE was injected. Next you must trace the address of allocated memory where the malicious PE was written to. If you got that informations you can select bytes that PE consists of from Dump Window in x32dbg, then Right-Click and select &quot;Dump to file&quot; option.</p> <p>In my opinion the whole process is even easier with Process Hacker tool, where you have to just spot the address where PE was written and then dump all pages to file.</p>
31356
2023-01-06T00:37:46.973
<p>How do I extract or dump injected executable code/payload from malware using the x32dbg trick? My malware sample is injecting an Exe PE file in a legitimate File like &quot;Explorer.exe&quot;. How do I dump the File?</p>
How to dump PE from Injected Code using x32dbg?
|malware|
<p>esp had 0x44 subtracted, then an additional three registers pushed, so esp is now -0x50. Then the access is 0x50+argv+4, which is argv[1].</p>
31365
2023-01-08T08:46:13.170
<p>I'm going through the book Practical Malware Analysis (specifically, Lab07-03) and I've been stuck on a rather simple problem. I've divided the code section of <code>main()</code> into three parts to ease my analysis. (Note: I'm assuming the stack is growing downwards here.)</p> <pre><code>Part 1) mov eax, [esp+argc] sub esp, 44h cmp eax, 2 Part 2) push ebx push ebp push esi push edi jnz ExitProgram Part 3) mov eax, [esp+54h+argv] mov esi, offset hardcodedString mov eax, [eax+4] </code></pre> <p>Part 1:</p> <p>This looks simple enough, the stack pointer (<code>esp</code>) is added with the memory location of <code>argc</code> and the value at that address is saved in the <code>eax</code> register. Then <em>44h</em> is subtracted from <code>esp</code> to make room for some local variables of the main function. Finally, <code>eax</code> is compared to 2 and the appropriate flags are set in the flag register (the value of <code>eax</code> is not modified).</p> <p>Part 2: Based on a <a href="https://stackoverflow.com/questions/12736437/why-does-gcc-push-rbx-at-the-beginning-of-main">similar</a> question on StackOverFlow, it seems that the registers are pushed in Part 2 as they are callee save registers. This seems to be true as when main exits, it is popping these <em>exact</em> registers. Is my understanding of this correct?</p> <p>Part 3: I'm adding the variables below if that helps in correcting me.</p> <pre><code>.text:00401440 var_44 = dword ptr -44h .text:00401440 var_40 = dword ptr -40h .text:00401440 var_3C = dword ptr -3Ch .text:00401440 var_38 = dword ptr -38h .text:00401440 var_34 = dword ptr -34h .text:00401440 var_30 = dword ptr -30h .text:00401440 var_2C = dword ptr -2Ch .text:00401440 var_28 = dword ptr -28h .text:00401440 var_24 = dword ptr -24h .text:00401440 var_20 = dword ptr -20h .text:00401440 var_1C = dword ptr -1Ch .text:00401440 var_18 = dword ptr -18h .text:00401440 var_14 = dword ptr -14h .text:00401440 var_10 = dword ptr -10h .text:00401440 var_C = dword ptr -0Ch .text:00401440 hObject = dword ptr -8 .text:00401440 var_4 = dword ptr -4 .text:00401440 argc = dword ptr 4 .text:00401440 argv = dword ptr 8 .text:00401440 envp = dword ptr 0Ch </code></pre> <p>I also don't understand the instruction <code>mov eax, [esp+54h+argv]</code>. It looks like the first argument that is passed to the program is being saved in <code>eax</code>, so wouldn't <code>mov eax, [esp+44h+argv]</code> make more sense? I recognize the function of the instruction <code>mov eax, [eax+4]</code> is to fetch the actual input passed to the program (i.e. <code>argv[1]</code>), which is what makes the previous instruction's indexing so confusing.</p> <p>The <code>mov esi, offset hardcodedString</code> is just moving the address of the first character of the string into <code>esi</code>, so it looks good to me.</p> <p>I'd appreciate some help here!</p>
Unable to determine what esp is pointing to
|x86|
<p>The answer from @ratchet freak is correct.</p> <p>To add a little more information, this format is known as <a href="https://en.wikipedia.org/wiki/LEB128" rel="nofollow noreferrer">LEB128</a>. It's not uncommon and pops up in various places. For example, DWARF3 debug info and android's dalvik executable files.</p>
31368
2023-01-09T04:01:10.847
<p>I'm attempting to reverse engineer a binary file format which is used to encode a list of integer values. I can't work out how this format works, as the number of bytes used to encode each value changes depending on the value itself, yet there's nothing I can see in the format which gives any indication of how many bytes each integer value contains!</p> <p>Here's a sample of binary file contents vs their expected integer list values:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>binary</th> <th>values</th> </tr> </thead> <tbody> <tr> <td><code>0a 07 0a 05 03 04 06 07 0b</code></td> <td>3, 4, 6, 7, 11</td> </tr> <tr> <td><code>0a 04 0a 02 07 0b</code></td> <td>7, 11</td> </tr> <tr> <td><code>0a 1a 0a 18 88 0b 89 0b 8a 0b 8b 0b 8c 0b 8d 0b 8e 0b 8f 0b 90 0b 91 0b 92 0b 93 0b</code></td> <td>1416, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1427</td> </tr> <tr> <td><code>0a 0e 0a 0c 01 02 03 04 05 06 07 08 09 0a 0b 0c</code></td> <td>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12</td> </tr> <tr> <td><code>0a 1e 0a 1c 01 02 03 04 05 06 07 08 09 0a 0b 0c b8 06 86 0b 8e 0b 8f 0b 91 0b 92 0b 93 0b 94 0b</code></td> <td>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 824, 1414, 1422, 1423, 1425, 1426, 1427, 1428</td> </tr> <tr> <td><code>0a 04 0a 02 94 0b</code></td> <td>1428</td> </tr> <tr> <td><code>0a 03 0a 01 01</code></td> <td>1</td> </tr> <tr> <td><code>0a 07 0a 05 d2 85 d8 cc 04</code></td> <td>1234567890</td> </tr> </tbody> </table> </div> <p>Clearly the format starts with <code>0a total_size 0a list_size</code> followed by the actual list of values, but I can't work out how the values could possibly be encoded!</p> <p>Any assistance or insights would be greatly appreciated...</p>
Decoding a list of integer values in unknown format
|binary-analysis|file-format|
<p>I should have attached disassembler listing:</p> <pre><code>.text:004486EA 02C mov eax, [ebp+arg_4] .text:004486ED 02C add eax, 10h .text:004486F0 02C cdq .text:004486F1 02C xor eax, edx .text:004486F3 02C sub eax, edx .text:004486F5 02C and eax, 3 .text:004486F8 02C xor eax, edx .text:004486FA 02C sub eax, edx .text:004486FC 02C lea ecx, ds:0[eax*4] .text:00448703 02C mov eax, [ebp+arg_0] .text:00448706 02C add eax, 10h .text:00448709 02C cdq .text:0044870A 02C xor eax, edx .text:0044870C 02C sub eax, edx .text:0044870E 02C and eax, 3 .text:00448711 02C xor eax, edx .text:00448713 02C sub ecx, edx .text:00448715 02C add ecx, eax .text:00448717 02C mov dword_524CEC, ecx </code></pre> <p>The right answer is:</p> <pre><code>(x + 16) % 4 + 4 * ((y + 16) % 4) </code></pre> <p>It gets obvious if you assume positive x and y.</p> <p>Usually IDA Pro detects such cases, but I think last two instructions were confusing for the analyzer.</p>
31376
2023-01-09T16:46:35.060
<p>I'm pretty sure that original code was much simpler:</p> <pre><code>(((x + 16) &gt;&gt; 31) ^ abs(x + 16) &amp; 3) + 4 * ((y + 16) % 4) - ((x + 16) &gt;&gt; 31) </code></pre> <p>Looks like division with remainder... Any ideas what this could be?</p> <p>The code was compiled with Visual Studio 6.0.</p>
What was the original math operation after optimizing compiler?
|ida|assembly|c|math|compiler-optimization|
<p>Turns out if you're gonna get hex strings printed to console, you have to convert them back to a binary char array before decrypting..</p>
31378
2023-01-09T22:46:07.467
<p>I'm working my way through reversing a toy challenge, and I find myself stuck. The app is pretty simple, it spits out a blob of text (e.g. &quot;3b880a90e476d66569d9d5dfb5cd755af3f...&quot;). Dumping the code, I can see that it builds an RSA public key by directly specifying <code>n</code> and <code>e</code>:</p> <pre><code>myRsa-&gt;n=v4; myRsa-&gt;e=v5; </code></pre> <p>Then it encrypts it's payload:</p> <pre><code>encodedLength = RSA_public_encrypt(flen, from, to, myRsa, 1); ... printf(&quot;%s&quot;,to); </code></pre> <p>My goal: steal the payload. Debugging tells me flen is 240, encodedLength is 100. I dumped the <code>e</code> for the public key as bytes, and wrote some code to generate my own RSA public/private key, patching <code>e</code> to be mine (<code>n</code> is the same for both, so left unpatched).</p> <pre><code>unsigned long bytes_read = fread(in, sizeof(unsigned char), size, file); fclose(file); for (size_t i = 0; i &lt; bytes_read; i++) { if (memcmp(nCharOrig, in + i, 258) == 0) { memcpy(in + i, nCharNew, 258); printf(&quot;Found and patched at %d\n&quot;, i); }; } </code></pre> <p>Patch works, I get a different blob of text, which in theory is the same payload, encrypted with my public key. So I try to decrypt it:</p> <pre><code>unsigned char output[8000]; RSA *rsa = RSA_new(); EVP_PKEY *privkey; FILE *fp; privkey = EVP_PKEY_new(); fp = fopen (&quot;private.pem&quot;, &quot;r&quot;); PEM_read_PrivateKey( fp, &amp;privkey, NULL, NULL); fclose(fp); rsa = EVP_PKEY_get1_RSA(privkey); int decryptLength = RSA_private_decrypt(256, input, output, rsa, 1); </code></pre> <p>Weirdly I get back decryptLength = -1, and an error: <code>error:0407109F:rsa routines:RSA_padding_check_PKCS1_type_2:pkcs decoding error</code></p> <p>I'm at a loss.. what am I missing here?</p>
Reversing an RSA function throws pkcs decoding error
|ida|decryption|encryption|cryptography|openssl|
<p>&quot;Simple&quot;, I want to respond, but it's somewhat involved.</p> <p>That region -- (<a href="https://msrc-blog.microsoft.com/2022/04/05/randomizing-the-kuser_shared_data-structure-on-windows/" rel="nofollow noreferrer">since newer Windows 10 versions read-only</a>) mapped into userspace of every program -- is known as <a href="https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm" rel="nofollow noreferrer">KUSER_SHARED_DATA</a>. You can find details about the offsets and there meaning <a href="http://terminus.rewolf.pl/terminus/structures/ntdll/_KUSER_SHARED_DATA_combined.html" rel="nofollow noreferrer">over here</a> (<em>beware, it's a bit dated!</em>).</p> <p>The first assignment to <code>version</code> merely reads <code>KUSER_SHARED_DATA::NtMajorVersion</code>. So to answer:</p> <blockquote> <p>Why do we find <code>0x0A</code> at <code>0x7FFE026C</code> on a 64 bit Windows install?</p> </blockquote> <p>... it's the major version of the Windows, 10 in decimal representation.</p> <p>Since we need an up-to-date view of what <code>KUSER_SHARED_DATA</code> looks we'll have a look at the official symbols from Windows 10 by starting WinDbg/WinDbgX on Windows 10, launching some 64-bit program from it (e.g. notepad.exe) and then running <code>dt nt!_KUSER_SHARED_DATA</code> to see the type definition.</p> <pre><code>0:000&gt; dt nt!_KUSER_SHARED_DATA ntdll!_KUSER_SHARED_DATA +0x000 TickCountLowDeprecated : Uint4B +0x004 TickCountMultiplier : Uint4B +0x008 InterruptTime : _KSYSTEM_TIME +0x014 SystemTime : _KSYSTEM_TIME +0x020 TimeZoneBias : _KSYSTEM_TIME +0x02c ImageNumberLow : Uint2B +0x02e ImageNumberHigh : Uint2B +0x030 NtSystemRoot : [260] Wchar +0x238 MaxStackTraceDepth : Uint4B +0x23c CryptoExponent : Uint4B +0x240 TimeZoneId : Uint4B +0x244 LargePageMinimum : Uint4B +0x248 AitSamplingValue : Uint4B +0x24c AppCompatFlag : Uint4B +0x250 RNGSeedVersion : Uint8B +0x258 GlobalValidationRunlevel : Uint4B +0x25c TimeZoneBiasStamp : Int4B +0x260 NtBuildNumber : Uint4B +0x264 NtProductType : _NT_PRODUCT_TYPE +0x268 ProductTypeIsValid : UChar +0x269 Reserved0 : [1] UChar +0x26a NativeProcessorArchitecture : Uint2B +0x26c NtMajorVersion : Uint4B +0x270 NtMinorVersion : Uint4B +0x274 ProcessorFeatures : [64] UChar +0x2b4 Reserved1 : Uint4B +0x2b8 Reserved3 : Uint4B +0x2bc TimeSlip : Uint4B +0x2c0 AlternativeArchitecture : _ALTERNATIVE_ARCHITECTURE_TYPE +0x2c4 BootId : Uint4B +0x2c8 SystemExpirationDate : _LARGE_INTEGER +0x2d0 SuiteMask : Uint4B +0x2d4 KdDebuggerEnabled : UChar +0x2d5 MitigationPolicies : UChar +0x2d5 NXSupportPolicy : Pos 0, 2 Bits +0x2d5 SEHValidationPolicy : Pos 2, 2 Bits +0x2d5 CurDirDevicesSkippedForDlls : Pos 4, 2 Bits +0x2d5 Reserved : Pos 6, 2 Bits +0x2d6 CyclesPerYield : Uint2B +0x2d8 ActiveConsoleId : Uint4B +0x2dc DismountCount : Uint4B +0x2e0 ComPlusPackage : Uint4B +0x2e4 LastSystemRITEventTickCount : Uint4B +0x2e8 NumberOfPhysicalPages : Uint4B +0x2ec SafeBootMode : UChar +0x2ed VirtualizationFlags : UChar +0x2ee Reserved12 : [2] UChar +0x2f0 SharedDataFlags : Uint4B +0x2f0 DbgErrorPortPresent : Pos 0, 1 Bit +0x2f0 DbgElevationEnabled : Pos 1, 1 Bit +0x2f0 DbgVirtEnabled : Pos 2, 1 Bit +0x2f0 DbgInstallerDetectEnabled : Pos 3, 1 Bit +0x2f0 DbgLkgEnabled : Pos 4, 1 Bit +0x2f0 DbgDynProcessorEnabled : Pos 5, 1 Bit +0x2f0 DbgConsoleBrokerEnabled : Pos 6, 1 Bit +0x2f0 DbgSecureBootEnabled : Pos 7, 1 Bit +0x2f0 DbgMultiSessionSku : Pos 8, 1 Bit +0x2f0 DbgMultiUsersInSessionSku : Pos 9, 1 Bit +0x2f0 DbgStateSeparationEnabled : Pos 10, 1 Bit +0x2f0 SpareBits : Pos 11, 21 Bits +0x2f4 DataFlagsPad : [1] Uint4B +0x2f8 TestRetInstruction : Uint8B +0x300 QpcFrequency : Int8B +0x308 SystemCall : Uint4B +0x30c Reserved2 : Uint4B +0x310 SystemCallPad : [2] Uint8B +0x320 TickCount : _KSYSTEM_TIME +0x320 TickCountQuad : Uint8B +0x320 ReservedTickCountOverlay : [3] Uint4B +0x32c TickCountPad : [1] Uint4B +0x330 Cookie : Uint4B +0x334 CookiePad : [1] Uint4B +0x338 ConsoleSessionForegroundProcessId : Int8B +0x340 TimeUpdateLock : Uint8B +0x348 BaselineSystemTimeQpc : Uint8B +0x350 BaselineInterruptTimeQpc : Uint8B +0x358 QpcSystemTimeIncrement : Uint8B +0x360 QpcInterruptTimeIncrement : Uint8B +0x368 QpcSystemTimeIncrementShift : UChar +0x369 QpcInterruptTimeIncrementShift : UChar +0x36a UnparkedProcessorCount : Uint2B +0x36c EnclaveFeatureMask : [4] Uint4B +0x37c TelemetryCoverageRound : Uint4B +0x380 UserModeGlobalLogger : [16] Uint2B +0x3a0 ImageFileExecutionOptions : Uint4B +0x3a4 LangGenerationCount : Uint4B +0x3a8 Reserved4 : Uint8B +0x3b0 InterruptTimeBias : Uint8B +0x3b8 QpcBias : Uint8B +0x3c0 ActiveProcessorCount : Uint4B +0x3c4 ActiveGroupCount : UChar +0x3c5 Reserved9 : UChar +0x3c6 QpcData : Uint2B +0x3c6 QpcBypassEnabled : UChar +0x3c7 QpcShift : UChar +0x3c8 TimeZoneBiasEffectiveStart : _LARGE_INTEGER +0x3d0 TimeZoneBiasEffectiveEnd : _LARGE_INTEGER +0x3d8 XState : _XSTATE_CONFIGURATION +0x710 FeatureConfigurationChangeStamp : _KSYSTEM_TIME +0x71c Spare : Uint4B </code></pre> <p>(if we used <code>dt -r2 nt!_KUSER_SHARED_DATA 0x000000007ffe0000</code> -- assuming we're <em>not</em> on 64-bit ARM where the <code>KUSER_SHARED_DATA</code> is no longer at a fixed address -- we can see the &quot;decoded&quot; contents of this structure)</p> <p>By comparing this output with the one from Terminus (link above) we can see that we seem to be looking for <code>KUSER_SHARED_DATA::SystemCall</code> (in newer versions <code>SystemCallPad</code> as per Terminus, but the symbols call it <code>SystemCall</code> nevertheless). When we follow the logic from the function it appears as if it tries to dereference the given address, picked based on Windows 10 or not, as a pointer. The goal seems to be to figure out (from any given process) if that value is 0 or not. And that seems to be an indicator for whether or not we're on 32-bit.</p> <p><code>KUSER_SHARED_DATA</code> has all sorts of useful applications, one is to quickly determine the <em>true</em> Windows version with resorting to NT native function calls or having to specify in a manifest that your application is compatible with the Windows version it's running on.</p> <p>That said, it's always a certain risk to reach into OS structures like that and relying on a given layout. Microsoft seems to be aware that this is being used by third parties, enough so to have kept the address fixed but making the region read-only in newer Windows versions (article linked above).</p> <ul> <li><a href="https://osm.hpi.de/wrk/2007/08/getting-os-information-the-kuser_shared_data-structure/" rel="nofollow noreferrer">Older article</a>, including details on how to query system time</li> </ul>
31379
2023-01-10T07:49:35.997
<p>Reversed this function. It works. But stepping through I can't figure out how. Why does this work?</p> <pre><code>bool _Is64BitOS(void) { unsigned int version = *(unsigned int*)0x7FFE026C; unsigned int address = version == 10 ? 0x7FFE0308 : 0x7FFE0300; ILog(&quot;Running %u-bit system\n&quot;, *(void**)address ? 32 : 64); return (*(void**)address ? false : true); }; </code></pre> <p>Why do we find <code>0x0A</code> at <code>0x7FFE026C</code> on a 64 bit Windows install?</p>
How does this Is64BitOS pointer-arithmetic-based function work?
|windows|c++|
<p>The length of 10 is simply the number of characters selected. Each hexadecimal digit requires 4 bits (<code>0</code>..<code>F</code>). So 10 hexadecimal digits take 40 bits (4 bits x 10) or 5 bytes (8 bits x 5).</p>
31383
2023-01-11T05:41:50.537
<p>I am stuck in this video. Please solve this issue.</p> <p>This video is about Encryption and Decryption using Win32 API.</p> <p><a href="https://www.youtube.com/watch?v=OQuRwpUTBpQ" rel="noreferrer">https://www.youtube.com/watch?v=OQuRwpUTBpQ</a></p> <p>In this video <strong>27:07</strong> it's saying &quot;10 IS HEX 5 bytes?&quot; But how?</p> <p>Please watch this video to understand?</p>
How 10 IS HEX 5 bytes?
|malware|
<p>I'm going to assume you have an Address object (I'll just use currentAddress) .</p> <p>With an address you can get the Instruction at that address. Then read that many bytes from Instruction object.</p> <pre><code>from ghidra.program.flatapi import FlatProgramAPI api = FlatProgramAPI(currentProgram, monitor) instruction = api.getInstructionAt(currentAddress) ibytes = insturction.getBytes() print(binascii.hexlify(ibytes)) </code></pre> <p>You can also inspect the operands with <code>instruction.getOpObjects()</code>. Or look through the GhidraAPI to see what else you do with the operands. I'm not exactly sure what you are hoping to get out it.</p>
31390
2023-01-12T06:02:41.200
<p>From disassembled code, I want to extract the hexadecimal of instruction, as boxed in the figure below</p> <p><a href="https://i.stack.imgur.com/xWpK5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xWpK5.png" alt="enter image description here" /></a></p> <p>plus, I want to get distinct value of each opcode and its operand, which means sort of</p> <p>mov =&gt; 1 bl =&gt; 57 like thing.</p> <p>I'm not sure this is the one, but I've found something like this</p> <p><a href="https://i.stack.imgur.com/1fdDu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1fdDu.png" alt="enter image description here" /></a></p> <p>in <code>Ghidra/Processors/ARM/data/manuals/ARM.idx</code></p>
How to get hexadecimal of instruction and distinct value(token) of opcode by ghidra script?
|ghidra|arm|hexadecimal|
<p>I only get the <code>HEADER</code> segment when <code>PE_LOAD_ALL_SECTIONS</code> is set to <code>YES</code> in <code>cfg\pe.cfg</code>.</p> <p>Checking <code>Load Resources</code> with <code>PE_LOAD_ALL_SECTIONS = NO</code> only adds the <code>.rsrc</code> segment for me (7.6 SP1).</p>
31393
2023-01-12T17:05:04.197
<p>As per <a href="https://hex-rays.com/blog/igors-tip-of-the-week-122-manual-load/" rel="nofollow noreferrer">this recent blog article</a> one can set the PE loader to default to loading all sections. I even knew that. So setting the following setting in <code>cfg\pe.cfg</code> does the trick:</p> <pre><code>PE_LOAD_ALL_SECTIONS = YES </code></pre> <p>I often find myself needing to load at least the file header (<a href="https://reverseengineering.stackexchange.com/q/30389/245">sometimes in hindsight</a>) but there is no explicit option for the file header on the load dialog:</p> <p><a href="https://i.stack.imgur.com/okHf5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/okHf5.png" alt="Load new file dialog" /></a></p> <p>Instead we have the &quot;Load resources&quot; checkbox, which -- if checked -- avoids having to do a full manual load, but seems to load <em>both</em> the resources (<code>.rsrc</code> &quot;segment&quot;) and the file header (<code>HEADER</code> &quot;segment&quot;).</p> <p><a href="https://i.stack.imgur.com/AXkeC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AXkeC.png" alt="List of segments" /></a></p> <p>That <em>also</em> seems to be the effect of configuring <code>PE_LOAD_ALL_SECTIONS = YES</code>. Alas, if you set the configuration inside the <code>cfg\pe.cfg</code>, the &quot;Load resources&quot; checkbox doesn't get default-checked or so.</p> <p>So my question is: are these two methods to load the file header and resources synonymous? If not, are they overlapping? What are the differences?</p> <hr /> <h3>Experiment: trying all combinations on handle46.exe from SysInternals</h3> <p>Here's the outcome of the various settings on a PE file with IDA Pro 8.2.221215:</p> <ol> <li><code>PE_LOAD_ALL_SECTIONS = NO</code> (default) and <em>no changes</em> on the load dialog:<br /> <a href="https://i.stack.imgur.com/g8YJW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g8YJW.png" alt="Just: PE_LOAD_ALL_SECTIONS = NO" /></a></li> <li><code>PE_LOAD_ALL_SECTIONS = NO</code> (default) and &quot;[✔] Load resources&quot; on the load dialog:<br /> <a href="https://i.stack.imgur.com/eusLx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eusLx.png" alt="Load resources AND PE_LOAD_ALL_SECTIONS = NO" /></a></li> <li><code>PE_LOAD_ALL_SECTIONS = YES</code> and <em>no changes</em> on the load dialog:<br /> <a href="https://i.stack.imgur.com/Yevun.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yevun.png" alt="Just: PE_LOAD_ALL_SECTIONS = YES" /></a></li> <li><code>PE_LOAD_ALL_SECTIONS = YES</code> and &quot;[✔] Load resources&quot; on the load dialog:<br /> <a href="https://i.stack.imgur.com/shg5p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/shg5p.png" alt="Load resources AND PE_LOAD_ALL_SECTIONS = YES" /></a></li> </ol> <p>The odd outcome is 3., because it loads the <code>.rsrc</code> section although it hadn't been asked for it. That's also the reason why I asked this question in the first place.</p>
Is "PE_LOAD_ALL_SECTIONS = YES" synonymous with "Load resources" from the "Load a new file" dialog?
|ida|
<p>Press <kbd>TAB</kbd> instead of <kbd>F5</kbd> to re-use the previous pseudocode tab rather than opening a new one.</p>
31408
2023-01-15T05:59:27.190
<p>When I press F5 in IDA to decompile, it always opens a new pseudocode tab, so over time many tabs open and I have to remember to close them. Can I make it so that F5 reuses an already open tab instead of opening a new one?</p>
Reuse pseudocode tab when decompiling in IDA
|ida|hexrays|
<p>Have it displayed as characters by hitting <kbd>r</kbd> (R) on the keyboard &quot;over&quot; each of those 32-bit constants.</p> <p>You should get four byte character literals for it, probably showing some ASCII values (and for Little Endian in apparent reverse order), similar to this:</p> <pre><code>mov eax, [esp+4Ch+ptr] mov dword ptr [eax], 'ea_f' ; 665F6165h mov dword ptr [eax+4], 'f_al' ; 6C615F66h mov dword ptr [eax+8], 'low:' ; 3A776F6Ch mov dword ptr [eax+0Ch], 'disa' ; 61736964h mov dword ptr [eax+10h], 'bled' ; 64656C62h mov byte ptr [eax+14h], '\n' ; 0Ah </code></pre> <p>Looks like an inlined <code>memcpy</code> (or <code>strcpy</code>) or <code>memmove</code> as a compiler would produce it during optimizations for string literals.</p> <p>Btw: this is called <a href="https://hex-rays.com/blog/igors-tip-of-the-week-88-character-operand-type-and-stack-strings/" rel="nofollow noreferrer">stack</a> <a href="https://reverseengineering.stackexchange.com/q/30463/245">strings</a> (there are further links from my Q&amp;A). At some point you will develop a sixth sense for this sort of thing and will probably automatically <em>try</em> <kbd>r</kbd> to see if it yields something if the values look like ASCII.</p>
31420
2023-01-17T05:03:14.880
<p>This might be obvious, but I'm baffled.. I opened a random .so library to poke around and learn IDA a bit better, and I hit something I've never seen. IDA has these instructions:</p> <pre><code>mov eax, [esp+4Ch+ptr] mov dword ptr [eax], 665F6165h mov dword ptr [eax+4], 6C615F66h mov dword ptr [eax+8], 3A776F6Ch mov dword ptr [eax+0Ch], 61736964h mov dword ptr [eax+10h], 64656C62h mov byte ptr [eax+14h], 0Ah </code></pre> <p>My guess is it's building some sort of struct, but it's moving dwords from addresses that don't exist in the binary (I think). When I try to jump to address 0x665F6165 for example, JumpAsk fails, which makes sense, since the hex view ends at 009636A0.. What are these weird addresses? Where are they coming from?</p>
IDA mov dword ptr with non-existent addresses
|ida|disassembly|
<p>Yes, there a marvelous tool available for your needs. Moreover it's free and open source (however earlier it was a commercial product - thanks to Google)</p> <p>Also please do check their another product BinDiff for comparison/difference in code execution.</p> <p><a href="https://www.zynamics.com/binnavi.html" rel="nofollow noreferrer">Link to software: Zynamics - Bin Navi</a></p>
31423
2023-01-17T12:52:21.843
<p>I'm a beginner in the reversing field, so apologize if the question is too dumb.</p> <p>When analyzing binaries I always had this idea of saving somehow an execution flow so I can compare with other saved flow and get the exact points where they differ so I can start analyzing from that point.</p> <p>Having a tool capable of doing that would be awesome. I can think of a lot of stuff I could do with this that with my current skill level is simply not feasible.</p> <p>Is there a tool that already does that?</p> <p>If not, how could I create such a tool?</p>
Analyzing the difference from 2 execution flows
|bin-diffing|
<p>MList seems to be an array of 8-byte structures. Observe how it contains:</p> <ol> <li>a dword (4 bytes)</li> <li>an offset (4 bytes)</li> <li>4 bytes</li> <li>an offset</li> <li>(repeat)</li> </ol> <p>So it's probably something like:</p> <pre><code>struct mlist_item { int number; int *arr; }; mlist_item MList[]; </code></pre>
31457
2023-01-23T04:18:09.927
<p>I'm playing with an ELF binary to learn IDA, and I'm not sure how to interpret what I'm seeing..</p> <p>A function calls this:</p> <pre><code>v1 = MList[2 * result]; </code></pre> <p>When I look at MList, it looks like this:</p> <pre><code>public MList MList dd 12Fh dd offset M1 db 30h ; 0 db 1 db 0 db 0 offset M2 db 31h ; 1 db 1 db 0 db 0 dd offset M3 db 32h ; 2 db 1 db 0 db 0 ... </code></pre> <p>Each of the <code>M*</code>s looks like this:</p> <pre><code>public M2 M2 db 0Ch db 0 db 0 db 0 db 1 </code></pre> <p>So what exactly is MList? I'm guessing some kind of global table or something, but I can't make heads or tails of what it is. What would this be in regular C code?</p>
Reversing rodata
|ida|c|unknown-data|
<p>If you use an TLS interception proxy and have a rooted phone it may be easier to add the used root CA certificate as system certificate (like described in <a href="https://docs.mitmproxy.org/stable/howto-install-system-trusted-ca-android/" rel="nofollow noreferrer">mitmproxy doc</a>. Afterwards the certificate verification will work unless the app uses cert/key pinning.</p> <p>Alternatively you can use anti-SSL/TLS verification/pinning scripts included in <a href="https://github.com/sensepost/objection" rel="nofollow noreferrer">Objection</a>.</p> <p>If you want to develop a script yourself it is easier to hook the <code>javax.net.ssl.X509TrustManager</code> method <code>checkServerTrusted</code> and replace it with an empty method.</p>
31470
2023-01-25T06:34:47.550
<p>I have an android application. It connects to a web socket server and uses the X509Certificate to verify the connection.</p> <pre><code> newBuilder.trustManagers(WebSocketClient.sTrustManagers); </code></pre> <p>By using Frida I was able to get <code>TrustManager[] trustManagerArr</code></p> <pre><code>trustManagerArr: [&quot;&lt;instance: javax.net.ssl.TrustManager, $className: im.sum.connections.Client$1&gt;&quot;] </code></pre> <p>How can I get certificate to use it for the purpose of establishing a connection from python?</p> <p>My Frida script</p> <pre><code>W1ebSocketClient[&quot;setTrustManagers&quot;].implementation = function (trustManagerArr) { console.log(' !setTrustManagers is called' + ', ' + 'trustManagerArr: ' + JSON.stringify(trustManagerArr)); let ret = this.setTrustManagers(trustManagerArr); console.log(' !setTrustManagers ret value is ' + ret); return ret; }; </code></pre>
Frida hook X509Certificate
|android|frida|
<p>Just to close the loop on this: I ended up successfully reverse-engineering this compression format, which turned out to be written by an extremely obscure tape backup tool from the early 90s called TXPLUS.</p> <p>Here is some <a href="https://github.com/dbrant/QICStreamReader/blob/master/txver45/TxDecompressor.cs" rel="noreferrer">code</a> and documentation for uncompressing this format. It's a variant of LZ78, but it's unnecessarily convoluted and quite inefficient, which is probably why it's now in the dustbin of history.</p>
31478
2023-01-26T16:27:04.153
<p>I'm recovering data from old tape cartridges from circa 1994, where the user had forgotten what software was used to write them, and it doesn't seem to be any format I recognize. Fortunately the file structure within the backup is fairly straightforward (it's just literally one file followed by another, aligned on a block boundary), so I was able to extract the file contents, but the files appear to be compressed using what appears to be a primitive compression scheme that I feel should be easy enough to reverse-engineer to a trained eye, so I thought I'd post it here.</p> <p>Fortunately the backup contains the user's DOS directory, with compressed versions of files from the standard DOS distribution (available on the web), so I'm able to cross-reference the compressed files against their known uncompressed versions.</p> <p>For example, here's the first few lines of the compressed version of DOSHELP.HLP, which is a simple plaintext file:</p> <pre><code>00000000 00 21 10 15 40 20 43 6F 70 79 72 69 67 68 74 20 .!..@ Copyright 00000010 28 43 29 20 31 39 39 30 2D 13 21 10 0B 39 34 20 (C) 1990-.!..94 00000020 4D 69 63 72 6F 73 6F 66 0D 51 10 02 91 72 70 2E Microsof.Q..‘rp. 00000030 20 20 41 6C 6C 20 09 B1 10 74 30 07 2E 21 10 0A All .±.t0..!.. 00000040 65 73 65 72 76 65 64 2E 0D 0A 03 41 05 68 90 06 eserved....A.h.. 00000050 32 11 14 20 40 07 68 50 06 1B 21 10 09 53 2D 44 2.. @.hP..!..S-D 00000060 4F 53 20 67 65 6E 36 11 06 2D 61 14 02 71 6C 70 OS gen6..-a..qlp 00000070 20 66 69 6C 65 28 01 02 49 D0 10 02 71 63 6F 6E file(..IÐ..qcon 00000080 74 61 69 6E 32 11 06 20 20 06 09 51 06 66 00 02 tain2.. ..Q.f.. 00000090 3C 31 10 64 40 13 1E 91 06 70 40 07 69 20 16 20 &lt;1.d@..‘.p@.i . 000000A0 20 12 02 61 20 65 61 63 68 20 61 21 10 0D 6D 6D ..a each a!..mm </code></pre> <p>and the reference uncompressed version:</p> <pre><code>00000000 40 20 43 6F 70 79 72 69 67 68 74 20 28 43 29 20 @ Copyright (C) 00000010 31 39 39 30 2D 31 39 39 34 20 4D 69 63 72 6F 73 1990-1994 Micros 00000020 6F 66 74 20 43 6F 72 70 2E 20 20 41 6C 6C 20 72 oft Corp. All r 00000030 69 67 68 74 73 20 72 65 73 65 72 76 65 64 2E 0D ights reserved.. 00000040 0A 40 20 54 68 69 73 20 69 73 20 74 68 65 20 4D .@ This is the M 00000050 53 2D 44 4F 53 20 67 65 6E 65 72 61 6C 20 68 65 S-DOS general he 00000060 6C 70 20 66 69 6C 65 2E 20 20 49 74 20 63 6F 6E lp file. It con 00000070 74 61 69 6E 73 20 61 20 62 72 69 65 66 20 0D 0A tains a brief .. 00000080 40 20 64 65 73 63 72 69 70 74 69 6F 6E 20 6F 66 @ description of 00000090 20 65 61 63 68 20 63 6F 6D 6D 61 6E 64 20 73 75 each command su 000000A0 70 70 6F 72 74 65 64 20 62 79 20 74 68 65 20 4D pported by the M </code></pre> <p>It's very clearly a tantalizingly simple algorithm, but I'm hoping someone with more experience with compression can unravel it with greater ease than I can.</p> <hr /> <p>So far I'm only able to discern basic &quot;run-length&quot; portions, for example, in the first two lines:</p> <pre><code>00000000 00 21 10 15 40 20 43 6F 70 79 72 69 67 68 74 20 .!..@ Copyright 00000010 28 43 29 20 31 39 39 30 2D 13 21 10 0B 39 34 20 (C) 1990-.!..94 </code></pre> <p>...the <code>15</code> at offset 3 clearly indicates the next 0x15 bytes are uncompressed, and we see similar run lengths throughout, but beyond that is proving a challenge.</p> <p>Here are links to download a few full example files:</p> <ul> <li><a href="https://dmitrybrant.com/files/DOSHELP_COMP.HLP" rel="noreferrer">compressed</a> / <a href="https://dmitrybrant.com/files/DOSHELP.HLP" rel="noreferrer">uncompressed</a></li> <li><a href="https://dmitrybrant.com/files/DRVSPACE_COMP.TXT" rel="noreferrer">compressed</a> / <a href="https://dmitrybrant.com/files/DRVSPACE.TXT" rel="noreferrer">uncompressed</a></li> <li><a href="https://dmitrybrant.com/files/COMMAND_COMP.COM" rel="noreferrer">compressed</a> / <a href="https://dmitrybrant.com/files/COMMAND.COM" rel="noreferrer">uncompressed</a></li> </ul>
Compression algorithm from very old tape backup?
|file-format|decompress|
<p>Works for me with strings version 2.37:</p> <pre><code>$ strings --encoding=S bin1.bin precondition failed ����invalid argument $ strings --encoding=S bin2.bin ����precondition failed invalid argument </code></pre>
31503
2023-02-02T17:08:53.557
<p>I have two binaries. Both contain the string &quot;precondition failed&quot; (without the quotes).</p> <p>The corresponding byte sequence <code>70 72 65 63 6C 65 64 00</code> is the same for both binaries. However, the bytes before and after the string are different.</p> <p>Binary 1:</p> <pre><code>00000000000006E0 00 00 00 00 2F 00 00 00 70 72 65 63 6F 6E 64 69 ..../...precondi 00000000000006F0 74 69 6F 6E 20 66 61 69 6C 65 64 00 FF FF FF FF tion failed..... 0000000000000700 69 6E 76 61 6C 69 64 20 61 72 67 75 6D 65 6E 74 invalid argument </code></pre> <p>Binary 2:</p> <pre><code>00000000000006E0 00 00 00 00 FF FF FF FF 70 72 65 63 6F 6E 64 69 ........precondi 00000000000006F0 74 69 6F 6E 20 66 61 69 6C 65 64 00 2F 00 00 00 tion failed./... 0000000000000700 69 6E 76 61 6C 69 64 20 61 72 67 75 6D 65 6E 74 invalid argument </code></pre> <p>For Binary 1, <code>strings --encoding=S</code> finds the &quot;precondition failed&quot;.</p> <p>For Binary 2, <code>strings --encoding=S</code> does <em>not</em> find the &quot;precondition failed&quot;.</p> <p>Why? Does it have to do with the enclosing bytes?</p> <p>For both binaries, IDA Pro recognises only one version of &quot;precondition failed&quot; and says it is of type &quot;C&quot;.</p> <p>EDIT: I am working with GNU strings (GNU Binutils) 2.39</p>
GNU strings with --encoding=S
|binary-analysis|encodings|strings|
<p>You can register IDC functions from IDAPython plugins. See the <code>%IDADIR%\python\examples\core\extend_idc.py</code> for the following snippet:</p> <pre><code>from __future__ import print_function import ida_expr if ida_expr.add_idc_func( &quot;pow&quot;, lambda n, e: n ** e, (ida_expr.VT_LONG, ida_expr.VT_LONG)): print(&quot;The pow() function is now available in IDC&quot;) else: print(&quot;Failed to register pow() IDC function&quot;) </code></pre> <p>Next, your C/C++ plugin code can invoke IDC functions. See <code>%IDASDK%\plugins\ex_debidc\ex_debidc.cpp</code> for an example of how to use <code>expr.hpp::exec_idc_script</code>, whose prototype is as follows:</p> <pre><code>/// Compile and execute IDC function(s) from file. /// \param result ptr to idc_value_t to hold result of the function. /// If execution fails, this variable will contain /// the exception information. /// You may pass nullptr if you are not interested in the returned /// value. /// \param path text file containing text of IDC functions /// \param func function name to execute /// \param args array of parameters /// \param argsnum number of parameters to pass to 'fname' /// This number should be equal to number of parameters /// the function expects. /// \param[out] errbuf buffer for the error message /// \retval true ok /// \retval false error, see errbuf THREAD_SAFE inline bool exec_idc_script( idc_value_t *result, const char *path, const char *func, const idc_value_t args[], size_t argsnum, qstring *errbuf=nullptr) </code></pre>
31504
2023-02-02T20:37:19.487
<p>I'm wondering whether it is possible to write a plugin for IDA and/or Hex-Rays which would use Python callbacks to perform certain tasks.</p> <p>In particular I am wondering if there is an official way to reuse the loaded Python version and IDAPython in light of the Python GIL (global interpreter lock), because obviously attempting anything like that outside of the trodden path could easily to hard-to-debug deadlock situations.</p> <p>So the question is: how would I go about to write a C/C++-based plugin for IDA, which is able to (re)use the Python interpreter used by IDA for IDAPython -- and if possible even tap into IDAPython?</p>
Is it possible to tap into IDAPython from within a (C) plugin? ... or at least use that Python instance?
|ida-plugin|idapro-sdk|
<p>If you don't want to code yourself such a script, although it looks like it might be the best, you can give a try to the <a href="https://github.com/joxeankoret/idamagicstrings" rel="nofollow noreferrer">IDA Magic Strings</a> plugin (that I wrote myself). It is often smart enough as to get function names from debugging messages.</p>
31531
2023-02-12T18:09:02.213
<p>IDA Pro 7.6</p> <p>Static disassembly of ARM executable.</p> <p>This binary has 40K functions or so, and no symbols. So all the functions are sub_49FFA etc.</p> <p>However, 90% of these functions have a call to a debug logging function, which says what the function is.</p> <p>e.g.:</p> <pre><code>sub_49FFA() { ....do stuff...... debug_message(0x9887, &quot;save_config()&quot;,&quot;Error: Cannot save config: %s&quot;,&quot;No disk space!&quot;); ....do stuff...... } </code></pre> <p>So we know sub_49FFA is really save_config()</p> <p>As this is ARM, this means arg2 is the r1 register pointing to a string. This is shown in the disassembly with LDR r1,=save_config ; &quot;save_config()&quot; immediately before BL debug_message</p> <p>Is there a way for a script to find all the code refs to debug_message(), and rename the calling function (if not already named) with the string that names the function?</p> <p>Spent an hour searching, but I'm not skilled in IDA scripting or python so any help would be appreciated.</p> <p>Up until now, I've been exporting the binary as pseudo code, parsing it to make an .idc script to name the functions, but it's pretty error prone, takes a long time and I often have to load multiple versions of the executable for analysis. Must be a better way.</p> <p>edit: Thanks to Rolf Rolles for their helpful suggestion of some script functions that might help.</p> <p>I've been able to cobble something together using the below</p> <pre><code>ref_addr=0x01D7448 args = idaapi.get_arg_addrs(ref_addr) func_name = get_func_name(ref_addr) func_addr = get_name_ea(0, func_name); print (&quot;func_name for %x is %s (%x)&quot; % (ref_addr,func_name,func_addr)) if args: arg_offset = args[2] print (&quot;arg_offset: %x &quot; % arg_offset) debug_func_dcd = idc.get_operand_value(arg_offset, 1) debug_func_addr = idaapi.get_dword(debug_func_dcd) print (&quot;debug_func_dcd: %x debug_func_addr: %x &quot; % (debug_func_dcd,debug_func_addr)) str_type = idc.get_str_type(debug_func_addr) debug_func = get_strlit_contents(debug_func_addr,-1,str_type).decode(&quot;utf-8&quot;) #print (&quot;value: %x&quot; % debug_func) print (&quot;value: %s&quot; % debug_func) set_name(func_addr, str(debug_func), 0) </code></pre> <p>(I'm sure this isn't best practice and doesn't have error checking etc - just a proof of concept).</p> <p>However, unlike my original question many of the binaries actually have the debug function string as argument 5. i.e. not held in a register at time of debug call, but rather placed on the stack.</p> <pre><code>.text:001D7414 LDR R4, =aUsbPower_0 ; &quot;usb_power_reset&quot; .text:001D7434 STR R4, [SP,#0x30+function] ; function .text:001D7448 BL debug_log </code></pre> <p>arg_offset = args[4] gives 001D7434, but idc.get_operand_value(arg_offset, 1) (i.e. [SP,#0x30+function]) gives 0</p> <p>I don't think I can read register R4 even though we know what the value always is unless we're in a live debug session.</p> <p>Can I evaluate this in a different way to get the address of R4 being set?</p> <p>Not sure about the etiquette here - so if this has to be a separate question please let me know.</p> <p>edit2:</p> <p>In the end, I decided to simply use DumpPseudoCode and parse it to find the right strings I need to name the function properly.</p> <p>That means most of the entire executable gets pseudocode generated for it, and probably isn't terribly efficient.</p> <p>Additionally, because the debug strings contain the source file name e.g. &quot;/src/network/upnp/upnp_server.c&quot; I added logic to create folders for the functions and move all functions to the correct place.</p> <p>That makes things much better. I just have an excuse to go and make a coffee while the script runs.</p>
IDAPython set name of function using string passed to debug logging subfunction
|ida|idapython|arm|
<p>With the help of Robert's comment, I explored that path and found a solution.</p> <p>IPA file is basically a form of ZIP file and likewise we can unzip it easily.</p> <blockquote> <p>macbook$:&gt; unzip -d unzipped-dir appname.ipa</p> </blockquote> <p>This will give us directory format as</p> <blockquote> <p>unzipped-dir/Payload/appname.app/Info.plist [and other contents of ipa file along with app binary]</p> </blockquote> <p>Once appropriate modifications are done in Info.plist, we can save the Info.plist file.</p> <p>Now, transfer the <code>Payload</code> directory from macbook to <code>jailbroken</code> ios device.</p> <blockquote> <p>macbook:$&gt; scp -r Payload/ root@&lt;iphone-ip&gt;:/var/root</p> </blockquote> <p>-- On Jailbroken Device --</p> <ul> <li>Install AppSync from Cydia (add source-&gt; <a href="http://cydia.akemi.ai" rel="nofollow noreferrer">http://cydia.akemi.ai</a>).</li> <li>Install Filza (should be available directly in Cydia search)</li> </ul> <p>Open Filza app and go to <code>/var/root</code>. This is the location where we sent <code>Payload</code> directory via scp.</p> <blockquote> <p>Long press <code>Payload</code> directory and click &quot;Create ZIP&quot; --&gt; This will create <code>Payload.zip</code></p> </blockquote> <blockquote> <p>Long press the newly created ZIP file <code>Payload.zip</code> and rename it to <code>new-app.ipa</code> (or whatever you want to name it, but make sure to keep the extension as <code>.ipa</code> and not <code>.zip</code> anymore) --&gt; This will create <code>new-app.ipa</code> in same directory ie /var/root/</p> </blockquote> <blockquote> <p>Click on <code>new-app.ipa</code> and click on &quot;Install&quot; on top right corner.</p> </blockquote> <p>Done. This will install the new ipa file.</p> <p>Self signing or any other type of signing is not required as (up to my limited knowledge) AppSync disables the code signing checks on jailbroken device.</p> <p>Writing self answer hoping that someone might get help from this. Thank you.</p>
31537
2023-02-13T12:46:53.637
<p>As a part of college project, I have to showcase how I can get ios app from jailbroken devices and reverse-engineer it. In the first part of slide, I am showing how we can get the IPA file from jailbroken device, also can decrypt the iOS app (either through clutch2 or ipainstaller). I am showing how attacker can use class-dump-z and enumerate classnames and method names.</p> <p>I am also trying to add a scenario, where I not only get the decrypted app from jailbroken iPhone but also can change few things in it. I am trying to change parameters in Info.plist file.</p> <p>Below are the steps I performed:</p> <blockquote> <ol> <li>Unzip the decrypted iOS app (.ipa file) into directory named <code>unzipped_app</code></li> <li>Go to Payload -&gt; Appname.app -&gt; Info.plist</li> <li>Change app name</li> </ol> </blockquote> <p>Question: Now, how do I recompile the <code>unzipped_app</code> directory back to .ipa file?</p> <p>I came across this question <a href="https://reverseengineering.stackexchange.com/questions/2814/disassemble-edit-and-re-assembly-ios-ipa-apps">Disassemble, edit and re-assembly iOS ipa apps</a> but this is not providing solution to my question.</p>
Decompile and Re-compile iOS app (.ipa file)
|ios|decompile|
<p>You do not use the <code>initial_state</code> you create with constraints for <code>buf</code> arg. From the doc</p> <blockquote> <p>If nothing is passed in, the SimulationManager is seeded with a state initialized for the program entry point, i.e. entry_state(). If a SimState is passed in, the SimulationManager is seeded with that state.</p> </blockquote> <pre><code>s = p.factory.simulation_manager(initial_state) </code></pre> <p>would just do it</p> <pre><code>[&lt;SimState @ 0x4007a3&gt;] b'hello\x00\x08\x80\x00\x00' </code></pre>
31543
2023-02-14T05:15:12.840
<p>I have made simple program to test the angr.</p> <p>My python code is here.</p> <pre><code>import angr import claripy p=angr.Project('./test2') buf=claripy.BVS('buf', 8*10) initial_state=p.factory.entry_state(args=[&quot;./test2&quot;, buf]) s=p.factory.simulation_manager() s.explore(find=0x80491ab, avoid=0x80491ba) print(s.found) if s.found: sol_state=s.found[0] sol=sol_state.solver.eval(buf, cast_to=bytes) print(sol) else: print(&quot;not found&quot;) </code></pre> <p>I expected this program print &quot;hello&quot; but It printed as follows.</p> <pre><code>WARNING | 2023-02-13 23:57:05,077 | angr.storage.memory_mixins.default_filler_mixin | The program is accessing memory with an unspecified value. This could indicate unwanted behavior. WARNING | 2023-02-13 23:57:05,077 | angr.storage.memory_mixins.default_filler_mixin | angr will cope with this by generating an unconstrained symbolic variable and continuing. You can resolve this by: WARNING | 2023-02-13 23:57:05,077 | angr.storage.memory_mixins.default_filler_mixin | 1) setting a value to the initial state WARNING | 2023-02-13 23:57:05,077 | angr.storage.memory_mixins.default_filler_mixin | 2) adding the state option ZERO_FILL_UNCONSTRAINED_{MEMORY,REGISTERS}, to make unknown regions hold null WARNING | 2023-02-13 23:57:05,078 | angr.storage.memory_mixins.default_filler_mixin | 3) adding the state option SYMBOL_FILL_UNCONSTRAINED_{MEMORY,REGISTERS}, to suppress these messages. WARNING | 2023-02-13 23:57:05,078 | angr.storage.memory_mixins.default_filler_mixin | Filling memory at 0x0 with 129 unconstrained bytes referenced from 0x819f230 (strcpy+0x0 in libc.so.6 (0x9f230)) WARNING | 2023-02-13 23:57:05,402 | angr.storage.memory_mixins.default_filler_mixin | Filling memory at 0x7ffeff6e with 10 unconstrained bytes referenced from 0x819f230 (strcpy+0x0 in libc.so.6 (0x9f230)) [&lt;SimState @ 0x80491ab&gt;] b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' </code></pre> <p>Here is my source code test2.c and assembly code</p> <p>test2.c</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; int main(int agrc, char* argv[]) { char buf[10]; strcpy(buf, argv[1]); if(!strcmp(buf, &quot;hello&quot;)) { puts(&quot;Correct!&quot;); } else { puts(&quot;Incorrect&quot;); } } </code></pre> <p>test2 assembly code</p> <pre><code>Dump of assembler code for function main: 0x08049176 &lt;+0&gt;: push ebp 0x08049177 &lt;+1&gt;: mov ebp,esp 0x08049179 &lt;+3&gt;: sub esp,0xc 0x0804917c &lt;+6&gt;: mov eax,DWORD PTR [ebp+0xc] 0x0804917f &lt;+9&gt;: add eax,0x4 0x08049182 &lt;+12&gt;: mov eax,DWORD PTR [eax] 0x08049184 &lt;+14&gt;: push eax 0x08049185 &lt;+15&gt;: lea eax,[ebp-0xa] 0x08049188 &lt;+18&gt;: push eax 0x08049189 &lt;+19&gt;: call 0x8049050 &lt;strcpy@plt&gt; 0x0804918e &lt;+24&gt;: add esp,0x8 0x08049191 &lt;+27&gt;: push 0x804a008 0x08049196 &lt;+32&gt;: lea eax,[ebp-0xa] 0x08049199 &lt;+35&gt;: push eax 0x0804919a &lt;+36&gt;: call 0x8049030 &lt;strcmp@plt&gt; 0x0804919f &lt;+41&gt;: add esp,0x8 0x080491a2 &lt;+44&gt;: test eax,eax 0x080491a4 &lt;+46&gt;: jne 0x80491b5 &lt;main+63&gt; 0x080491a6 &lt;+48&gt;: push 0x804a00e 0x080491ab &lt;+53&gt;: call 0x8049060 &lt;puts@plt&gt; 0x080491b0 &lt;+58&gt;: add esp,0x4 0x080491b3 &lt;+61&gt;: jmp 0x80491c2 &lt;main+76&gt; 0x080491b5 &lt;+63&gt;: push 0x804a017 0x080491ba &lt;+68&gt;: call 0x8049060 &lt;puts@plt&gt; 0x080491bf &lt;+73&gt;: add esp,0x4 0x080491c2 &lt;+76&gt;: mov eax,0x0 0x080491c7 &lt;+81&gt;: leave 0x080491c8 &lt;+82&gt;: ret End of assembler dump. </code></pre> <p>Why is this happening? Thank you in advance.</p>
Why did I have gotten only null bytes argv variable from angr?
|assembly|python|angr|
<p>EXCEPTION_REGISTRATION_RECORD is placed on the stack in anticipation of an exception occurring. The &quot;try&quot; will put one there. The record is part of a chain, for as many nested &quot;try&quot; statements as exist. The nesting includes one function calling another function from within a try block. Windows will also put a top-most handler there before the program starts, so there is always one on program start.</p>
31559
2023-02-17T08:52:08.440
<p>I want to understand when <code>EXCEPTION_REGISTRATION_RECORD</code>s get created on the stack.</p> <ul> <li>Are they created when the program starts?</li> <li>Are they created when we enter the function?</li> <li>Or are they created only when the exception occurs?</li> </ul> <p>Is it true that there is one <code>EXCEPTION_REGISTRATION_RECORD</code> per <code>try</code>/<code>catch</code>?</p>
When is EXCEPTION_REGISTRATION_RECORD created on the stack?
|seh|
<p>Your <code>buf</code> variable is a global variable, which most likely is located inside <code>.data</code> section.</p> <p>This section is not executable by default (it probably has RW permissions). You can check its permissions with <code>readelf</code> utility.</p> <p>Since you are putting your shell code inside a buffer located in a non executable section of memory, upon executing first instructions, program segfaults.</p> <p>Considering arguments you are passing to compile your code, I assume that you wanted your shell code to be located in the stack. Thus, to avoid segfault, your <code>buf</code> array should be a local variable (place your array inside <code>main</code> function).</p>
31598
2023-02-28T06:59:36.027
<p>I found a simple shellcode on the internet. Then, to test this shellcode, I make the simple ret overwrite code.</p> <p>test.c</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; char buf[100]; int main(void) { char x=0; strcpy(buf, &quot;\x31\xf6\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x56\x53\x54\x5f\x6a\x3b\x58\x31\xd2\x0f\x05&quot;); *(&amp;x+9)=0x40; *(&amp;x+10)=0x40; *(&amp;x+11)=0x40; *(&amp;x+12)=0x00; *(&amp;x+13)=0x00; *(&amp;x+14)=0x00; *(&amp;x+15)=0x00; *(&amp;x+16)=0x00; puts(&quot;end of program&quot;); } </code></pre> <p>I compiled this using gcc like this.</p> <pre><code>gcc -o test test.c -fno-stack-protector -mpreferred-stack-boundary=2 -no-pie -fno-pie -z execstack </code></pre> <p>and the following is the result of what I debugged with gdb.</p> <pre><code>┌──(kali㉿kali)-[~] └─$ gdb -q test Reading symbols from test... (No debugging symbols found in test) (gdb) set disassembly-flavor intel (gdb) disas main Dump of assembler code for function main: 0x0000000000401126 &lt;+0&gt;: push rbp 0x0000000000401127 &lt;+1&gt;: mov rbp,rsp 0x000000000040112a &lt;+4&gt;: sub rsp,0x10 0x000000000040112e &lt;+8&gt;: mov BYTE PTR [rbp-0x1],0x0 0x0000000000401132 &lt;+12&gt;: movabs rax,0x6e69622fbb48f631 0x000000000040113c &lt;+22&gt;: movabs rdx,0x5f54535668732f2f 0x0000000000401146 &lt;+32&gt;: mov QWORD PTR [rip+0x2ef3],rax # 0x404040 &lt;buf&gt; 0x000000000040114d &lt;+39&gt;: mov QWORD PTR [rip+0x2ef4],rdx # 0x404048 &lt;buf+8&gt; 0x0000000000401154 &lt;+46&gt;: movabs rax,0x50fd231583b6a 0x000000000040115e &lt;+56&gt;: mov QWORD PTR [rip+0x2eeb],rax # 0x404050 &lt;buf+16&gt; 0x0000000000401165 &lt;+63&gt;: lea rax,[rbp-0x1] 0x0000000000401169 &lt;+67&gt;: add rax,0x9 0x000000000040116d &lt;+71&gt;: mov BYTE PTR [rax],0x40 0x0000000000401170 &lt;+74&gt;: lea rax,[rbp-0x1] 0x0000000000401174 &lt;+78&gt;: add rax,0xa 0x0000000000401178 &lt;+82&gt;: mov BYTE PTR [rax],0x40 0x000000000040117b &lt;+85&gt;: lea rax,[rbp-0x1] 0x000000000040117f &lt;+89&gt;: add rax,0xb 0x0000000000401183 &lt;+93&gt;: mov BYTE PTR [rax],0x40 0x0000000000401186 &lt;+96&gt;: lea rax,[rbp-0x1] 0x000000000040118a &lt;+100&gt;: add rax,0xc 0x000000000040118e &lt;+104&gt;: mov BYTE PTR [rax],0x0 0x0000000000401191 &lt;+107&gt;: lea rax,[rbp-0x1] 0x0000000000401195 &lt;+111&gt;: add rax,0xd 0x0000000000401199 &lt;+115&gt;: mov BYTE PTR [rax],0x0 0x000000000040119c &lt;+118&gt;: lea rax,[rbp-0x1] 0x00000000004011a0 &lt;+122&gt;: add rax,0xe 0x00000000004011a4 &lt;+126&gt;: mov BYTE PTR [rax],0x0 0x00000000004011a7 &lt;+129&gt;: lea rax,[rbp-0x1] 0x00000000004011ab &lt;+133&gt;: add rax,0xf 0x00000000004011af &lt;+137&gt;: mov BYTE PTR [rax],0x0 0x00000000004011b2 &lt;+140&gt;: lea rax,[rbp-0x1] 0x00000000004011b6 &lt;+144&gt;: add rax,0x10 0x00000000004011ba &lt;+148&gt;: mov BYTE PTR [rax],0x0 0x00000000004011bd &lt;+151&gt;: lea rax,[rip+0xe40] # 0x402004 0x00000000004011c4 &lt;+158&gt;: mov rdi,rax 0x00000000004011c7 &lt;+161&gt;: call 0x401030 &lt;puts@plt&gt; 0x00000000004011cc &lt;+166&gt;: mov eax,0x0 0x00000000004011d1 &lt;+171&gt;: leave 0x00000000004011d2 &lt;+172&gt;: ret End of assembler dump. (gdb) b *main+172 Breakpoint 1 at 0x4011d2 (gdb) r Starting program: /home/kali/test [Thread debugging using libthread_db enabled] Using host libthread_db library &quot;/lib/x86_64-linux-gnu/libthread_db.so.1&quot;. end of program Breakpoint 1, 0x00000000004011d2 in main () (gdb) si 0x0000000000404040 in buf () (gdb) x/30i $rip =&gt; 0x404040 &lt;buf&gt;: xor esi,esi 0x404042 &lt;buf+2&gt;: movabs rbx,0x68732f2f6e69622f 0x40404c &lt;buf+12&gt;: push rsi 0x40404d &lt;buf+13&gt;: push rbx 0x40404e &lt;buf+14&gt;: push rsp 0x40404f &lt;buf+15&gt;: pop rdi 0x404050 &lt;buf+16&gt;: push 0x3b 0x404052 &lt;buf+18&gt;: pop rax 0x404053 &lt;buf+19&gt;: xor edx,edx 0x404055 &lt;buf+21&gt;: syscall 0x404057 &lt;buf+23&gt;: add BYTE PTR [rax],al 0x404059 &lt;buf+25&gt;: add BYTE PTR [rax],al 0x40405b &lt;buf+27&gt;: add BYTE PTR [rax],al 0x40405d &lt;buf+29&gt;: add BYTE PTR [rax],al 0x40405f &lt;buf+31&gt;: add BYTE PTR [rax],al 0x404061 &lt;buf+33&gt;: add BYTE PTR [rax],al 0x404063 &lt;buf+35&gt;: add BYTE PTR [rax],al 0x404065 &lt;buf+37&gt;: add BYTE PTR [rax],al 0x404067 &lt;buf+39&gt;: add BYTE PTR [rax],al 0x404069 &lt;buf+41&gt;: add BYTE PTR [rax],al 0x40406b &lt;buf+43&gt;: add BYTE PTR [rax],al 0x40406d &lt;buf+45&gt;: add BYTE PTR [rax],al 0x40406f &lt;buf+47&gt;: add BYTE PTR [rax],al 0x404071 &lt;buf+49&gt;: add BYTE PTR [rax],al 0x404073 &lt;buf+51&gt;: add BYTE PTR [rax],al 0x404075 &lt;buf+53&gt;: add BYTE PTR [rax],al 0x404077 &lt;buf+55&gt;: add BYTE PTR [rax],al 0x404079 &lt;buf+57&gt;: add BYTE PTR [rax],al 0x40407b &lt;buf+59&gt;: add BYTE PTR [rax],al 0x40407d &lt;buf+61&gt;: add BYTE PTR [rax],al (gdb) si Program received signal SIGSEGV, Segmentation fault. 0x0000000000404040 in buf () </code></pre> <p>I think that 'xor esi,esi' don't generate segmentation fault, but It generated. Why the segmentation fault occured?</p>
Why this x64 shellcode doesn't work?(segmentation fault)
|c|gdb|x86-64|shellcode|gcc|
<p>I have fixed it by using <code>flags=idaapi.FC_NOEXT</code> when calling FlowChart.</p> <p>The flag <code>idaapi.FC_NOEXT</code> tells to not compute external blocks. Using this prevents jumps leaving the function from appearing in the flow chart. Unless specified, the targets of those outgoing jumps will be present in the flow chart under the form of one-instruction blocks.</p>
31610
2023-03-02T10:28:02.017
<p>I'm developing a python script for IDA Pro and I seem to have a problem with idaapi.FlowChart because it retrieves another basic block that isn't present in the graph view of the GUI of IDA.</p> <p><a href="https://i.stack.imgur.com/Jv6Rd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jv6Rd.png" alt="enter image description here" /></a></p> <p>As you can see in the function at 0x10b4 there is only one basic block composed by a JMP instruction, but the size of the flowchart is 2, where in the second basic block there is the first instruction present at the memory location pointed by the JMP instruction of the first basic block.</p> <p>Do you know how I can deal with this problem? Thank you in advance.</p>
IDAPython's FlowChart wrong basic blocks
|ida|idapython|idapro-sdk|
<p>Without seeing the full function, I suspect what you're seeing is a result of how Ghidra identifies a stack-based variable, as described in the answer to <a href="https://reverseengineering.stackexchange.com/questions/23540/ghidra-interpreting-stack-pointers-wrongly">this question</a>.</p> <p>The <code>Stack[-0x##]</code> numbers in your screenshot are likely not relative to <code>RBP</code>, but rather the stack pointer <code>RSP</code> at the function start. Since <code>RBP</code> might have been set to the value of <code>RSP</code> <em>after</em> some pushes occurred, it could be a slightly different offset than the stack offset at the entry point of the function. This can take some getting used to as it is unintuitive.</p> <p>If you are still learning assembly, a good exercise is to follow the changes made to the stack pointer via pushes/pops in the function start, and verify that you understand why the offset of <code>RBP</code> later in the function body would be slightly different than the offset to <code>RSP</code> at the beginning of the function for the same stack address.</p>
31616
2023-03-02T22:36:56.467
<p>I am new to assembly. When I was disassembling some code, I encounter some strange instruction here. The instruction shows that (RBP + -0x40) is equal to local_48, however at the beginning of the code, we can see that (RBP + -0x48) is equal to local_48. Also, I know that this is a struct. Is there something wrong here or am I looking at it wrong?</p> <p>The instruction I was talking about:</p> <p><a href="https://i.stack.imgur.com/FXU8s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FXU8s.png" alt="Assembly Instruction" /></a></p> <p>And the beginning of the code:</p> <p><a href="https://i.stack.imgur.com/Bpedz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bpedz.png" alt="Beginning Of The Code" /></a></p>
Ghidra Shows Structure Strange
|assembly|x86|ghidra|
<p>There are innumerable paths... but for some getting started material:</p> <ul> <li><a href="https://p.ost2.fyi/" rel="nofollow noreferrer">https://p.ost2.fyi/</a> :: Open Security Training 2, Xeno has rebooted the project and has tons of great, free, in-depth courses.</li> <li><a href="https://beginners.re/" rel="nofollow noreferrer">https://beginners.re/</a> :: Denis Yurichevs on-line book (or PDF)</li> <li><a href="https://github.com/crackmes/crackmes" rel="nofollow noreferrer">https://github.com/crackmes/crackmes</a> :: a crackmes.de mirror, start at level 1, some are very easy but the variety of compilers makes it a good way to build up your tool set</li> <li><a href="http://www.binary-auditing.com/" rel="nofollow noreferrer">http://www.binary-auditing.com/</a> :: The Binary Auditor course teaches binary analysis and some C at the same time</li> </ul> <p>There is literally tons of material available, some holds it's own over the years and some doesn't... but this list is some that I remember being very accessible, enjoy the journey!</p>
31638
2023-03-07T03:56:34.087
<p>I started by reading a book on C language and then moved on to &quot;Programming From Ground Up,&quot; which teaches basic programming in x86.</p> <p>School just ended, I'm working on cracking a game called PwnAdventure Sourcery, which has been tough. I had to look up solutions and found that some involved buffer overflow and bruteforcing algorithms. It took me around 30 minutes to finally look up for a solution, and I feel like I'm so stupid :(</p> <p>If possible, can you give a rough roadmap for reverse engineering along with some great resources?</p>
What are the prerequisite knowledge needed to start solving crackmes?
|disassembly|assembly|debugging|crackme|game-hacking|
<p>Relocation tables exist to load a binary To a different Imagebase instead of the preferred Imagebase embedded in pe header</p> <p>Imagebase relocation is mostly applicable to dlls as image base conflicts have more chances to happen in dlls</p> <p>Exe is normally the first image to be loaded so it normally tends to get its preferred imagebase 0x400000 in x86</p> <p>You can compile an exe without relocation table using /Fixed /DynamicBase:no linker options</p> <p>You can rip out a relocation table and theoretically the binary should work alright at its preferred imagebase</p>
31639
2023-03-07T05:58:05.277
<p>A friend and I are poking around with some 32-bit Windows binaries and wanted to get some info about relocation tables.</p> <ol> <li><p>What is the difference between an exe that does not contain a relocation table (its base memory always starts at a specific address e.g. 0x0040000), and an exe that does contain a relocation table with a base memory that starts at different addresses?</p> </li> <li><p>What are the benefits or detriments to having a relocation table and not having one in an exe?</p> </li> <li><p>If an exe has a relocation table already inside of it, what will happen if it is removed? What are the consequences of doing so?</p> </li> </ol>
A few questions about reloc tables and base memory
|memory|relocations|
<p>I have solved my problem by using twice <code>idc.auto_wait()</code>, the first time at the start of the script and then between the snippet of code that I posted and the <code>idautils.Functions()</code>, now the function that I need to analyze gets listed.</p>
31654
2023-03-09T16:29:20.127
<p>I'm developing a python script for IDA Pro that analyzes 32 bit PE files containing an anti-disassembly technique, the problem is that the function that contains the technique isn't being listed in the list of functions using <code>idautils.Functions()</code>.</p> <p>To solve the problem I tried to add the function to the list with:</p> <pre><code>segm = idaapi.get_segm_by_name(&quot;.text&quot;) start = segm.start_ea end = segm.end_ea while start &lt; end: start = idaapi.find_not_func(start, 1) ida_funcs.add_func(start) </code></pre> <p>When the <code>start</code> value is the address of the beginning of the function the <code>ida_funcs.add_func</code> method returns false, meaning that the address can't be added as a function, despite that in the GUI of IDA the function becomes listed.</p> <p>This is the screenshot of the function containing the technique in the IDA GUI: <a href="https://i.stack.imgur.com/neXXA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/neXXA.png" alt="enter image description here" /></a></p> <p>Do you know what can I do in order to have the script working? Thank you in advance.</p>
IDAPython doesn't recognize function
|ida|disassembly|idapython|disassemblers|idapro-sdk|
<p>Got the file disassembled into the audio segments. Format is pretty simple.</p> <p>(for further analysis the separated files: <a href="https://nplusc.de/mickey.bin-splitted.zip" rel="nofollow noreferrer">https://nplusc.de/mickey.bin-splitted.zip</a> )</p> <p>File has a index list at 0x6c of 0x29 uint32 offsets, at each offset there is a length field (uint32) and then the raw file.</p> <p>File format as a 010editor binary template:</p> <pre class="lang-c prettyprint-override"><code>byte randomgarbage[0x6b]; local uint64 returnoffset = FTell(); uint32 sizes[0x29]; struct FILE{ uint32 file_size; byte content[file_size]; }; FSeek(returnoffset); local uint i = 0; for(i = 0; i&lt;0x29;i++) { FSeek(sizes[i]); FILE file; } </code></pre> <p>Used this java program to split the file:</p> <pre class="lang-java prettyprint-override"><code>import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; public class MickeyBinSplitter { public static void main(String[] args) { try (RandomAccessFile file = new RandomAccessFile(args[0],&quot;r&quot;)) { File out = new File(args[0]+&quot;out&quot;); out.mkdirs(); file.seek(0x6b); //guessed from file reading for(int i=0; i &lt; 0x29;i++) { byte[] swapMe = new byte[4]; file.read(swapMe); ByteBuffer wrapped = ByteBuffer.wrap(new byte[]{swapMe[3],swapMe[2],swapMe[1],swapMe[0]}); // big-endian by default int offsetFile = wrapped.getInt(); System.out.println(offsetFile); long retval = file.getFilePointer(); file.seek(offsetFile); file.read(swapMe); wrapped = ByteBuffer.wrap(new byte[]{swapMe[3],swapMe[2],swapMe[1],swapMe[0]}); // big-endian by default int lenFile = wrapped.getInt(); System.out.println(lenFile); byte[] innerFile = new byte[lenFile]; file.read(innerFile); file.seek(retval); try (RandomAccessFile outRandom = new RandomAccessFile(new File(out, i + &quot;.bin&quot;), &quot;rw&quot;)) { outRandom.write(innerFile); } } } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } } </code></pre>
31662
2023-03-12T17:07:31.223
<p>I am trying to reverse engineer a Mickey Mouse toy just for fun but I am stuck. The toy has several buttons that play various phrases and songs. My aim was to see if I can read those songs from the eeprom as the other chip is encased in resin. I was able to read the 2mb bin file and I have tried various softwares for reverse engineering but I didn't find very useful information.</p> <p>binwalk -A mickey.bin:</p> <pre><code> DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 1581594 0x18221A ARMEB instructions, function prologue </code></pre> <p>In imHex I was only able to identify this at the start of the file:</p> <pre><code>Date: 2009-11-09Version: V06Author: A\xAAUi\x96/\x00\xD0\xFF8# </code></pre> <p>In Ghidra I was only able to find this:</p> <pre><code> // // ram // ram:00000000-ram:001fffff // ************************************************************** * FUNCTION * ************************************************************** undefined Reset() undefined r0:1 &lt;RETURN&gt; Reset XREF[1]: Entry Point(*) 00000000 44 61 74 65 ldrbvs r6,[r4,#-0x144]! ************************************************************** * FUNCTION * ************************************************************** undefined UndefinedInstruction() undefined r0:1 &lt;RETURN&gt; UndefinedInstruction XREF[1]: Entry Point(*) 00000004 3a 20 32 30 eorccs r2,r2,r10, lsr r0 SupervisorCall XREF[1]: Entry Point(*) 00000008 30 ?? 30h 0 00000009 39 ?? 39h 9 0000000a 2d ?? 2Dh - 0000000b 31 ?? 31h 1 ************************************************************** * FUNCTION * ************************************************************** undefined PrefetchAbort() undefined r0:1 &lt;RETURN&gt; PrefetchAbort XREF[1]: Entry Point(*) 0000000c 31 2d 30 39 ldmdbcc r0!,{r0,r4,r5,r8,r10,r11,sp} DataAbort XREF[1]: Entry Point(*) 00000010 56 ?? 56h V 00000011 65 ?? 65h e 00000012 72 ?? 72h r 00000013 73 ?? 73h s 00000014 69 ?? 69h i 00000015 6f ?? 6Fh o 00000016 6e ?? 6Eh n 00000017 3a ?? 3Ah : ************************************************************** * FUNCTION * ************************************************************** undefined IRQ() undefined r0:1 &lt;RETURN&gt; IRQ XREF[1]: Entry Point(*) 00000018 20 20 20 20 eorcs r2,r0,r0, lsr #32 ************************************************************** * FUNCTION * ************************************************************** undefined FIQ() undefined r0:1 &lt;RETURN&gt; FIQ XREF[1]: Entry Point(*) 0000001c 20 56 30 36 ldrtcc r5,[r0],-r0,lsr #0xc 00000020 41 75 74 68 ldmdavs r4!,{r0,r6,r8,r10,r12,sp,lr}^ 00000024 6f 72 3a 20 eorcss r7,r10,pc, ror #0x4 00000028 20 ?? 20h </code></pre> <p>Since I am a beginer I might have not used the reverse engineering software properly.</p> <p>Here is the bin file: <a href="https://easyupload.io/3yyq4x" rel="nofollow noreferrer">https://easyupload.io/3yyq4x</a></p>
Mickey Mouse toy bin file analysis
|binary-analysis|ghidra|radare2|binwalk|
<p>Found the calculation in a newer version of the J1939 standard than I originally had access to. The manufacturer reused the following equation from SPN 4207:</p> <pre><code>Checksum = (Byte1 + Byte2 + Byte3 + Byte4 + Byte5 + Byte6 + Byte7 + message counter &amp; 0x0F + message ID low byte + message ID mid low byte + message ID mid high byte + message ID high byte) Message Checksum = (((Checksum &gt;&gt; 6) &amp; 0x03) + (Checksum &gt;&gt;3) + Checksum) &amp; 0x07 </code></pre>
31666
2023-03-13T16:37:59.500
<p>I am attempting to reverse engineer some proprietary J1939 CAN traffic so that I can remotely control some actions on a vehicle. I have collected a number of traces covering the events I want to control and have identified the controlling messages for several, but the payloads have some kind of authentication/checksum that I have not been able to figure out and was hoping someone might recognize what is going on.</p> <p>I have so far attempted some different things like summing set bits (both data and ID) and a few quick CRC calculators, but I haven't had any luck. This is outside of my normal skillset, so apologies if there is something obvious I'm missing.</p> <p>The checksums are in the last (8th) byte of the message payloads. There is appears to be a message counter used in the calculation as the value increments without any changes to the other data bytes. From what I can tell, the lower nibble increments by one each message and then resets on overflow.</p> <p>The upper nibble also increments (though with only three bits), but the value will change with the payload. The counter also skips a value each iteration. The value is different between the two iterations that complete before the lower nibble overflows, but appears to increment by one the second iterations UNLESS the number skipped is 7, in which case both 7 and 0 are skipped. Note that I am not certain that the 7/0 skip is consistent across payloads nor if it is the only time multiple digits are skipped.</p> <p>I have provided some data samples below (I have others I can provide) with specific notes immediately before them. If anyone recognizes this pattern or if there is anything to clarify or data to look for, please let me know!</p> <h3>Data Samples</h3> <p>This sample illustrates the behavior of both nibbles of the checksum byte. This pattern repeats until one of the other data bytes changes. Of note is that message 0x0CFF9<strong>7</strong>80 has the exact same checksum value and data bytes during this sample EXCEPT for byte 7, which is 0x39 instead of 0x00 (e.g., the first message is <code>0CFF9780 E8 03 E8 03 00 64 39 10</code>). This appears to be a coincidence as the checksums do differ with different payloads (see following sample).</p> <pre><code>J1939_ID Data_bytes------------- 0CFF9880 E8 03 E8 03 00 64 00 10 0CFF9880 E8 03 E8 03 00 64 00 21 0CFF9880 E8 03 E8 03 00 64 00 32 0CFF9880 E8 03 E8 03 00 64 00 53 0CFF9880 E8 03 E8 03 00 64 00 64 0CFF9880 E8 03 E8 03 00 64 00 75 0CFF9880 E8 03 E8 03 00 64 00 06 0CFF9880 E8 03 E8 03 00 64 00 17 0CFF9880 E8 03 E8 03 00 64 00 28 0CFF9880 E8 03 E8 03 00 64 00 39 0CFF9880 E8 03 E8 03 00 64 00 4A 0CFF9880 E8 03 E8 03 00 64 00 6B 0CFF9880 E8 03 E8 03 00 64 00 7C 0CFF9880 E8 03 E8 03 00 64 00 0D 0CFF9880 E8 03 E8 03 00 64 00 1E 0CFF9880 E8 03 E8 03 00 64 00 2F </code></pre> <p>This sample is the data for 0x0CFF9780 after its data bytes (bytes 3 and 4) change from the above sample. The data for 0x0Cff9880 is the same as the first sample during this time frame.</p> <pre><code>J1939_ID Data_bytes------------- 0CFF9780 E8 03 D0 07 00 64 39 30 0CFF9780 E8 03 D0 07 00 64 39 41 0CFF9780 E8 03 D0 07 00 64 39 52 0CFF9780 E8 03 D0 07 00 64 39 63 0CFF9780 E8 03 D0 07 00 64 39 74 0CFF9780 E8 03 D0 07 00 64 39 05 0CFF9780 E8 03 D0 07 00 64 39 16 0CFF9780 E8 03 D0 07 00 64 39 37 0CFF9780 E8 03 D0 07 00 64 39 48 0CFF9780 E8 03 D0 07 00 64 39 59 0CFF9780 E8 03 D0 07 00 64 39 6A 0CFF9780 E8 03 D0 07 00 64 39 7B 0CFF9780 E8 03 D0 07 00 64 39 0C 0CFF9780 E8 03 D0 07 00 64 39 1D 0CFF9780 E8 03 D0 07 00 64 39 2E 0CFF9780 E8 03 D0 07 00 64 39 4F </code></pre> <p>This sample captures the upper nibble skipping both 7 and 0 on its second iteration.</p> <pre><code>J1939_ID Data_bytes------------- 18FF9980 03 00 00 00 00 00 00 32 18FF9980 03 00 00 00 00 00 00 43 18FF9980 03 00 00 00 00 00 00 54 18FF9980 03 00 00 00 00 00 00 75 18FF9980 03 00 00 00 00 00 00 06 18FF9980 03 00 00 00 00 00 00 17 18FF9980 03 00 00 00 00 00 00 28 18FF9980 03 00 00 00 00 00 00 39 18FF9980 03 00 00 00 00 00 00 4A 18FF9980 03 00 00 00 00 00 00 5B 18FF9980 03 00 00 00 00 00 00 6C 18FF9980 03 00 00 00 00 00 00 1D 18FF9980 03 00 00 00 00 00 00 2E 18FF9980 03 00 00 00 00 00 00 3F 18FF9980 03 00 00 00 00 00 00 10 18FF9980 03 00 00 00 00 00 00 21 </code></pre> <p>These are two separate samples that are minor variations of the above sample that only have byte 1 change value.</p> <pre><code>J1939_ID Data_bytes------------- 18FF9980 11 00 00 00 00 00 00 20 18FF9980 11 00 00 00 00 00 00 31 18FF9980 11 00 00 00 00 00 00 42 18FF9980 11 00 00 00 00 00 00 53 18FF9980 11 00 00 00 00 00 00 64 18FF9980 11 00 00 00 00 00 00 75 18FF9980 11 00 00 00 00 00 00 06 18FF9980 11 00 00 00 00 00 00 27 18FF9980 11 00 00 00 00 00 00 38 18FF9980 11 00 00 00 00 00 00 49 18FF9980 11 00 00 00 00 00 00 5A 18FF9980 11 00 00 00 00 00 00 6B 18FF9980 11 00 00 00 00 00 00 7C 18FF9980 11 00 00 00 00 00 00 0D 18FF9980 11 00 00 00 00 00 00 1E 18FF9980 11 00 00 00 00 00 00 3F 18FF9980 01 00 00 00 00 00 00 70 18FF9980 01 00 00 00 00 00 00 01 18FF9980 01 00 00 00 00 00 00 12 18FF9980 01 00 00 00 00 00 00 23 18FF9980 01 00 00 00 00 00 00 34 18FF9980 01 00 00 00 00 00 00 45 18FF9980 01 00 00 00 00 00 00 56 18FF9980 01 00 00 00 00 00 00 77 18FF9980 01 00 00 00 00 00 00 08 18FF9980 01 00 00 00 00 00 00 19 18FF9980 01 00 00 00 00 00 00 2A 18FF9980 01 00 00 00 00 00 00 3B 18FF9980 01 00 00 00 00 00 00 4C 18FF9980 01 00 00 00 00 00 00 5D 18FF9980 01 00 00 00 00 00 00 6E 18FF9980 01 00 00 00 00 00 00 1F </code></pre> <p>Finally, this is one long sample that has a number of byte changes in it. Note that, unlike previous samples, this one does NOT repeat.</p> <pre><code>J1939_ID Data_bytes------------- 0CFF9880 E8 03 E8 03 00 64 00 10 0CFF9880 E8 03 E8 03 00 64 00 21 0CFF9880 E8 03 E8 03 00 64 00 32 0CFF9880 52 04 71 03 00 64 00 73 0CFF9880 52 04 71 03 00 64 00 04 0CFF9880 52 04 71 03 00 64 00 15 0CFF9880 52 04 71 03 00 64 00 26 0CFF9880 52 04 71 03 00 64 00 47 0CFF9880 52 04 71 03 00 64 00 58 0CFF9880 52 04 71 03 00 64 00 69 0CFF9880 79 05 B4 03 00 64 00 1A 0CFF9880 10 06 CF 03 00 64 00 2B 0CFF9880 10 06 CF 03 00 64 00 3C 0CFF9880 47 06 CF 03 00 64 00 3D 0CFF9880 47 06 CF 03 00 64 00 4E 0CFF9880 47 06 CF 03 00 64 00 5F 0CFF9880 47 06 CF 03 00 64 00 40 0CFF9880 47 06 CF 03 00 64 00 51 0CFF9880 47 06 CF 03 00 64 00 72 0CFF9880 6C 06 CF 03 00 64 00 23 0CFF9880 6C 06 CF 03 00 64 00 34 0CFF9880 6C 06 CF 03 00 64 00 55 0CFF9880 8B 06 CF 03 00 64 00 16 0CFF9880 8B 06 CF 03 00 64 00 27 0CFF9880 8B 06 CF 03 00 64 00 38 0CFF9880 8B 06 CF 03 00 64 00 49 0CFF9880 8B 06 CF 03 00 64 00 5A 0CFF9880 AA 06 CF 03 00 64 00 6B 0CFF9880 AA 06 CF 03 00 64 00 7C 0CFF9880 AA 06 CF 03 00 64 00 0D 0CFF9880 AA 06 CF 03 00 64 00 1E 0CFF9880 CA 06 CF 03 00 64 00 7F </code></pre>
J1939 message payload checksum
|automation|software-security|checksum|communication|
<p>It's saving registers that might be modified by the function. Notice that you can see assignments to all three of those registers throughout the function body. Also notice at the bottom of your screenshot that the values of the registers are restored by popping them right before the return statement, such that the calling function will have the same values for those registers after the call as they did before the call.</p>
31671
2023-03-14T01:05:32.547
<p>i am a <strong>newbie</strong> in the world of <strong>RE</strong> ,</p> <p>i start to explorer a <strong>main entry of a classic game</strong> from 90's and i start to see something confuse me as a newbie</p> <p>this <strong>main entry function</strong> start with <strong>pushing stuff</strong> to the stack <strong>before</strong> it's <strong>prologue</strong> <a href="https://i.stack.imgur.com/ijPXw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ijPXw.png" alt="enter image description here" /></a></p> <p>can someone explain why please .</p>
why some functions push data before the prologue
|disassembly|assembly|x86|stack|exe|
<p><strong>UPDATE: Ok, so the older glibc noncompliance I re-discovered was actually fixed back then, and it is a CVE by itself, CVE-2020-6096:</strong></p> <p><a href="https://github.com/bminor/glibc/commit/beea361050728138b82c57dda0c4810402d342b9" rel="nofollow noreferrer">https://github.com/bminor/glibc/commit/beea361050728138b82c57dda0c4810402d342b9</a></p> <p>Ok, so I resolved this. The glibc memcpy implementation in place has this code:</p> <p><a href="https://github.com/rilian-la-te/glibc/blob/master/sysdeps/arm/armv7/multiarch/memcpy_impl.S#L300" rel="nofollow noreferrer">https://github.com/rilian-la-te/glibc/blob/master/sysdeps/arm/armv7/multiarch/memcpy_impl.S#L300</a></p> <pre><code> mov dst, dstin /* Preserve dstin, we need to return it. */ cmp count, #64 bge .Lcpy_not_short </code></pre> <p>This is signed comparison, so a 0xffffffff-style wild copy is not possible, becuase it is treated as a short copy. Feels weird to perform a signed comparison of a size_t parameter in assembly without any additional comments by glibc authors, but it ends up being bit of a security measure.</p> <p>On my system, though,</p> <pre><code>CHAR_BIT = 8 MB_LEN_MAX = 16 CHAR_MIN = +0 CHAR_MAX = +255 SCHAR_MIN = -128 SCHAR_MAX = +127 UCHAR_MAX = 255 SHRT_MIN = -32768 SHRT_MAX = +32767 USHRT_MAX = 65535 INT_MIN = -2147483648 INT_MAX = +2147483647 UINT_MAX = 4294967295 LONG_MIN = -2147483648 LONG_MAX = +2147483647 ULONG_MAX = 4294967295 LLONG_MIN = -9223372036854775808 LLONG_MAX = +9223372036854775807 ULLONG_MAX = 18446744073709551615 PTRDIFF_MIN = -2147483648 PTRDIFF_MAX = +2147483647 SIZE_MAX = 4294967295 SIG_ATOMIC_MIN = -2147483648 SIG_ATOMIC_MAX = +2147483647 WCHAR_MIN = +0 WCHAR_MAX = +4294967295 WINT_MIN = 0 WINT_MAX = 4294967295 </code></pre> <p>Meaning that a memcpy of 2147483647+1 bytes is treated like this as well as a short copy that doesn't actually do much, even though that 'n' is well within SIZE_MAX. Not a practical thing to do, and this will mean that src and dst memory areas do overlap, but still feels like noncompliance.</p>
31673
2023-03-14T12:37:52.297
<p>I found a couple of interesting integer underflows leading to <code>memcpy()</code> wild copies in a TLV parser process of some random IoT firmware. It is 32-bit ARMv7.</p> <p>I'm able to emulate the userspace process using qemu and debug it, I can confirm the wild copy by inspecting register state before the <code>memcpy()</code> and memory state after it, but when I let it run, it won't crash. No page fault, no overwritten PC, it just exits.</p> <p>I tried to come up with some C code that resembles what my code in the field does:</p> <pre><code>#include &lt;string.h&gt; #include &lt;stdlib.h&gt; void parse_stuff(char*); int main(int argc, char** argv) { char buffer[128]; char c; while (1) { parse_stuff(buffer); c = getc(stdin); if (c == 'e') return 0; } } void parse_stuff(char* buf){ char* heap = malloc(0x1000); for(int i=0;i&lt;0x1000;i++) heap[i] = 0x41; memcpy(buf, heap, 0xffffffff); } </code></pre> <p><em>If I compile this and run it in qemu, it won't crash.</em></p> <p>There is a tight loop and the parser routine is called from that, so I'm guessing if the parse_stuff stack frame is a leaf, then a stack bof could only happen when the caller is the one trying to restore the PC to its caller (entry / <code>libc_start_main</code>, whatever), but I'm still puzzled by this, because on x86-64, this easily crashes so somehow the ARM binary or maybe the QEMU environment does not trigger that page violation that I'm expecting to happen due to the wild <code>memcpy()</code>, even if there is no PC control due to the cyclometric situation this way.</p> <p>Has any of you run into something like this?</p>
This code does not crash on ARM (qemu). Why?
|binary-analysis|arm|buffer-overflow|stack|firmware-analysis|
<p>1 0 251 0 201 1 67 1 62 255<br> 1 0 251 0 200 1 77 1 61 255<br> 1 0 251 0 200 1 72 1 62 255<br> 1 0 251 0 200 1 65 1 63 255<br> 2 22 3 23 12 7 28 0 252 1 219 0 200 0 0 0 49 10 36 10 1 242 1 250 0 0 1<br> 1 0 252 0 186 1 63 1 62 255<br> 1 0 252 0 214 0 212 0 0 255<br> 1 0 252 0 204 0 201 0 0 255<br> 1 0 252 0 238 1 38 0 0 255<br> 1 0 252 0 242 1 10 0 0 255<br> 1 0 252 0 253 1 1 0 0 255<br> 1 0 252 1 9 1 17 0 0 255<br>.....this type of pattern goes on for sometime<br> 1 0 251 0 202 1 65 1 67 255<br> 1 0 251 0 202 1 76 1 65 255<br> 1 0 251 0 198 1 54 1 60 255<br> 2 22 3 23 12 7 34 0 252 1 219 0 200 0 0 0 49 10 36 10 1 239 1 252 0 0 1<br> 1 0 252 0 189 1 67 1 66 255<br> 1 0 252 0 216 0 188 0 0 255<br> 1 0 252 0 210 0 234 0 0 255<br> 1 0 252 0 237 1 28 0 0 255<br> 1 0 252 0 245 0 246 0 0 255<br></p> <p>Hi Ian, thanks for your pattern suggestion that i follow &amp; convert the hex to unsigned char &amp; got result as above, the data start to make sense as portion 2 22 3 23 12 7 34 means date 22/3/23 and time 12:7:34. I just have to translate other data that are available.</p> <p>Thanks again Ian Cook</p>
31676
2023-03-15T08:11:04.077
<pre><code>000000 00 00 00 00 00 00 00 00 00 00 00 00 01 01 08 03 000010 17 10 15 27 00 00 01 00 FB 00 0A 00 00 00 38 FF 000020 01 00 FB 00 09 00 00 00 34 FF 01 00 FB 00 09 00 000030 00 00 31 FF 01 00 FB 00 08 00 00 00 2D FF 01 00 000040 FB 00 08 00 00 00 2A FF 01 00 FB 00 08 00 00 00 000050 26 FF 01 00 FB 00 06 00 00 00 24 FF 01 00 FB 00 000060 06 00 00 00 24 FF 01 00 FB 00 06 00 00 00 22 FF 000070 01 00 FB 00 06 00 00 00 24 FF 01 00 FB 00 06 00 000080 00 00 22 FF 01 00 FB 00 06 FF EB 00 22 FF 01 00 000090 FB 00 06 00 00 00 22 FF 01 00 FB 00 06 00 00 00 0000A0 22 FF 01 00 FB 00 06 00 00 00 22 FF 01 00 FB 00 0000B0 06 00 00 00 1E FF 01 00 FB 00 06 00 00 00 1E FF 0000C0 01 00 FB 00 06 00 00 00 1E FF 01 00 FB 00 06 00 0000D0 00 00 1E FF 01 00 FB 00 06 00 00 00 1E FF 01 00 0000E0 FB 00 06 00 00 00 1E FF 01 00 FB 00 05 00 00 00 0000F0 1E FF 01 00 FB 00 06 00 00 00 1C FF 01 00 FB 00 000100 06 00 00 00 1C FF 01 00 FB 00 06 00 00 00 1C FF 000110 01 00 FB 00 06 00 00 00 1C FF 01 00 FB 00 06 00 000120 00 00 1C FF 01 00 FB 00 06 00 00 00 1C FF 01 00 000130 FB 00 06 00 00 00 1C FF 01 00 FB 00 05 00 00 00 </code></pre> <p>Hi, im a noob trying to decode this binary file but to no avail, appreciate if anyone could help. The only thing that i know is that the data type is an unsigned char type. i tried standard x86 double (8 byte) representation extraction but to no avail. Please help, thanks in advance.</p>
reading data from a binary file
|binary|
<p>I've got found incredibly good plugin for IDA.</p> <p>The tools:</p> <ol> <li><p>PixtopianBook.exe (lena151's 4th tutorial).</p> </li> <li><p>IDA 7.6 x86.</p> </li> <li><p>Funcap python script for ida.</p> </li> </ol> <p>The task: Do any action and find out which function was called.</p> <p>The recipe:</p> <p><strong>1. Get the script by typing</strong> <code>git clone https://github.com/deresz/funcap.git</code></p> <p><strong>2. Run IDA and select the Local Windows debugger (Windbg froze up when launch with lots of breakpoints).</strong></p> <blockquote> <p><a href="https://i.stack.imgur.com/4DAeO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4DAeO.png" alt="enter image description here" /></a></p> </blockquote> <p><strong>3. Run process as usual, right till the exe fully loads up.</strong></p> <blockquote> <p><a href="https://i.stack.imgur.com/10l5B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/10l5B.png" alt="enter image description here" /></a></p> </blockquote> <p><strong>4. Pause process, hold ALT+F7 and select <code>funcap.py</code> script</strong></p> <blockquote> <p><a href="https://i.stack.imgur.com/T4R65.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T4R65.png" alt="enter image description here" /></a></p> </blockquote> <p><strong>5. Now type in command line <code>d.hookSeg('.text')</code> and run process.</strong></p> <blockquote> <p><a href="https://i.stack.imgur.com/Pfsqw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pfsqw.png" alt="enter image description here" /></a></p> </blockquote> <p><strong>6. Now just click the interesting button and wait till it fully drawn.</strong></p> <blockquote> <p><a href="https://i.stack.imgur.com/zyO4h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zyO4h.png" alt="enter image description here" /></a></p> </blockquote> <p><strong>7. You will see a lot of logs in the IDA output, select and copy whole text to some notepad and search for <code>MessageBox</code>. Here we go :з</strong></p> <blockquote> <p><a href="https://i.stack.imgur.com/n4ALc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n4ALc.png" alt="enter image description here" /></a></p> </blockquote>
31688
2023-03-18T19:20:45.840
<p>I'm learning lena151's materials and in 4 lesson she uses Olly's Back-to-user feature to find where the MassegeBox is creating.</p> <p><a href="https://i.stack.imgur.com/tAWbe.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tAWbe.gif" alt="enter image description here" /></a></p> <p>It works fine under x32 windows server 2003.</p> <p>But what about nowadays?!</p> <p>Is there similar option in IDA+WINDBG for x64 apps? Coz I've tried setting BP to the .text section but I faced the message of IDA 'BP set is failed coz of break point overlapping' (so you should delete all previous if some was set)</p>
Ida+Windbg alternative of Olly's "Back to user code" feature
|ida|ollydbg|windbg|
<p>I solved the issue by restarting the cape-processor.service</p> <pre><code>$ sudo systemctl restart cape-processor.service </code></pre>
31691
2023-03-19T12:33:36.503
<p>When I submit a PDF file to analyse, it triggers a signature called <code>stealth_file</code>. I just added the alerted path into the whitelist as shown, but it didn't solve the problem.</p> <p>How to resolve it? <a href="https://i.stack.imgur.com/cyMkE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cyMkE.jpg" alt="enter image description here" /></a></p> <p><a href="https://i.stack.imgur.com/B7N14.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B7N14.jpg" alt="enter image description here" /></a></p>
CAPE-sandbox signatures
|sandbox|
<p>Based on the discussion in comments and further investigation, when the class is instantiated like this:</p> <pre><code> TurretShootOrder turretShootOrder2 = new TurretShootOrder(firstFakeTarget, null, .... </code></pre> <p>then it is neccessary to decide, which type the second parameter has in this case. Is it String or IGalaxyModuleSection?</p> <p>In the above example according to C# rules it can't be a String. As then it won't be equal to null, but to &quot;&quot; (Empty.String). Which points to the type of that second parameter, which in this case is IGalaxyModuleSection.</p> <p>Thus, there is a missing variable introduction in the code where the class got instantiated. So, the (simplified) solution could look like this:</p> <pre><code> IGalaxyModuleSection targetSection = null; TurretShootOrder turretShootOrder2 = new TurretShootOrder(firstFakeTarget, targetSection, . </code></pre>
31692
2023-03-20T11:14:09.040
<p>When reversing Unity dll, the decompiler (i.e. dnSpy) sometimes would create a class with 2 constructors, which are mostly identical apart from some specific field set / not set.</p> <p>Here is an example:</p> <pre><code>public TurretShootOrder(IGalaxyTarget target, string sectionName, GalaxyWeaponDefinition galaxyWeaponDefinition, float startShootTime, Vector3 startRandomDispersion, float startImpactTime, float endShootTime, Vector3 endRandomDispersion, float endImpactTime, int shootCount, float missProportion, int flags = 0, int salvoId = 0, int salvoTotalShootCount = 0, int inSalvoFirstShootIndex = 0) { this.target = target; this.sectionName = sectionName; </code></pre> <p>AND:</p> <pre><code>public TurretShootOrder(IGalaxyTarget target, IGalaxyModuleSection targetSection, GalaxyWeaponDefinition galaxyWeaponDefinition, float startShootTime, Vector3 startRandomDispersion, float startImpactTime, float endShootTime, Vector3 endRandomDispersion, float endImpactTime, int shootCount, float missProportion, int flags = 0, int salvoId = 0, int salvoTotalShootCount = 0, int inSalvoFirstShootIndex = 0) { this.target = target; this.sectionName = string.Empty; </code></pre> <p>As you can see the second implementation doesn't set the sectionName on initialization. Otherwise these constructors are identical.</p> <p>So, how do I combine these 2 constructors together?</p>
Double constructor when reversing Unity game
|decompilation|c#|
<p>Your problem is that the name of the function you want to hook is not <code>xxtea_decrypt</code> and because of this you can not hook it:</p> <p>In your IDA scren shot the function is shown as <code>xxtea_decrypt(uchar *,uint,uchar *,uchar *)</code>.</p> <p>That the function has not only a name but also argument types displayed means it is not a plain C function but instead a C++ function which uses name mangling.</p> <p>Name mangling encodes the argument types in the function name, which means the function name displayed by IDA is not the real function name, but the demangled function name which is optimized for human readability.</p> <p>You will see the real function name if you disable name mangling in IDA. You can find the option in the context menu of the function.</p> <p>Most likely IDA will display the function name without demangling as <code>_Z13xxtea_decryptPhjS_jPj</code>. This is the real function name you have to use for hooking in Frida.</p> <p>This function name I got from a library of the same name I found on the Internet, and the xxtea_decrypt function seems to have the same argument types as the one in your library, so the function may be the same but you should better check in IDA with disabled name mangling and copy the function name from there.</p> <p>If you want to hook the xxtea_decrypt function you have to use this hook:</p> <pre><code>var nptr = Module.findExportByName(&quot;libcocos2dlua.so&quot;, &quot;_Z13xxtea_decryptPhjS_jPj&quot;); </code></pre>
31730
2023-03-30T16:25:38.753
<p>I want to hook a xxtea_decrypt but it not trigger and on other games it trigger but some games not trigger it. On ida pro its trigger the xxtea_decrypt but frida nope here is the code that i using it</p> <pre><code>var nptr = Module.findExportByName(&quot;libcocos2dlua.so&quot;, &quot;xxtea_decrypt&quot;); function fn() { nptr = Module.findExportByName(&quot;libcocos2dlua.so&quot;, &quot;xxtea_decrypt&quot;); // nptr = Module.findExportByName(&quot;libcocos2dlua.so&quot;, &quot;luaL_loadbuffer&quot;); if (!nptr) { console.log(&quot;xxtea_decrypt cannot be found!&quot;); setTimeout(fn, 900); // } else { // // console.log(&quot;xxtea_decrypt&quot;); } else { Interceptor.attach(nptr, { onEnter: function(args) { console.log(&quot;----------------BEGIN----------------&quot;); console.log(&quot;Key: &quot;); console.log(hexdump(Memory.readByteArray(args[1], 5000),{ offset: 0, length: 500, header: true, ansi: true })); console.log(&quot;sign:&quot;); console.log(hexdump(Memory.readByteArray(args[2], 12),{ offset: 0, length: 12, header: true, ansi: true })); }, onLeave: function(retval) { // console.log(&quot;Decrypt:&quot;); // console.log(hexdump(Memory.readByteArray(retval, 50),{ // offset: 0, // length: 50, // header: true, // ansi: true // })); // console.log(&quot;-----------------END-----------------&quot;); } }) } } var timeout = setTimeout(fn, 500); </code></pre> <p>The following screen shot shows the <code>xxtea_decrypt</code> function in IDA: <a href="https://i.stack.imgur.com/kPvUB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kPvUB.png" alt="enter image description here" /></a></p>
Frida not hook functions
|android|frida|
<p>The values appear to be a floating point format similar to <a href="https://en.wikipedia.org/wiki/Single-precision_floating-point_format" rel="nofollow noreferrer">single-precision floating-point format</a>.</p> <p>If I interpret the first byte as an unbiased exponent and interpret the other bytes (excluding the highest bit) as a fraction, then the value <kbd>(1 + <em>fraction</em>) × 2<sup><em>exponent</em></sup></kbd> appears to be the number of milliseconds:</p> <p><a href="https://i.stack.imgur.com/RadyM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RadyM.png" alt="table showing how the bits are assigned to exponent and fraction values" /></a></p> <p>Equivalently, in the following textual table, the first byte <em><strong>e</strong></em> is the exponent, the other bytes <em><strong>n</strong></em> form the numerator of the fraction, and the denominator of the fraction is 2<sup>23</sup>. The value <kbd>(1 + <em>n</em>/2<sup>23</sup>) × 2<sup><em>e</em></sup></kbd> is the number of milliseconds:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: right;"><em>e</em></th> <th style="text-align: right;"><em>n</em></th> <th style="text-align: right;"><em>e</em></th> <th style="text-align: right;"><em>n</em></th> <th style="text-align: right;">(1 + <em>n</em>/2<sup>23</sup>) × 2<sup><em>e</em></sup></th> </tr> </thead> <tbody> <tr> <td style="text-align: right;"><code>03</code></td> <td style="text-align: right;"><code>200000</code></td> <td style="text-align: right;">3</td> <td style="text-align: right;">2097152</td> <td style="text-align: right;">10</td> </tr> <tr> <td style="text-align: right;"><code>09</code></td> <td style="text-align: right;"><code>700000</code></td> <td style="text-align: right;">9</td> <td style="text-align: right;">7340032</td> <td style="text-align: right;">960</td> </tr> <tr> <td style="text-align: right;"><code>0A</code></td> <td style="text-align: right;"><code>1B0000</code></td> <td style="text-align: right;">10</td> <td style="text-align: right;">1769472</td> <td style="text-align: right;">1240</td> </tr> <tr> <td style="text-align: right;"><code>0A</code></td> <td style="text-align: right;"><code>160000</code></td> <td style="text-align: right;">10</td> <td style="text-align: right;">1441792</td> <td style="text-align: right;">1200</td> </tr> <tr> <td style="text-align: right;"><code>0B</code></td> <td style="text-align: right;"><code>098000</code></td> <td style="text-align: right;">11</td> <td style="text-align: right;">622592</td> <td style="text-align: right;">2200</td> </tr> <tr> <td style="text-align: right;"><code>0F</code></td> <td style="text-align: right;"><code>376600</code></td> <td style="text-align: right;">15</td> <td style="text-align: right;">3630592</td> <td style="text-align: right;">46950</td> </tr> <tr> <td style="text-align: right;"><code>0F</code></td> <td style="text-align: right;"><code>347800</code></td> <td style="text-align: right;">15</td> <td style="text-align: right;">3438592</td> <td style="text-align: right;">46200</td> </tr> <tr> <td style="text-align: right;"><code>10</code></td> <td style="text-align: right;"><code>038B00</code></td> <td style="text-align: right;">16</td> <td style="text-align: right;">232192</td> <td style="text-align: right;">67350</td> </tr> <tr> <td style="text-align: right;"><code>10</code></td> <td style="text-align: right;"><code>040800</code></td> <td style="text-align: right;">16</td> <td style="text-align: right;">264192</td> <td style="text-align: right;">67600</td> </tr> <tr> <td style="text-align: right;"><code>10</code></td> <td style="text-align: right;"><code>56A600</code></td> <td style="text-align: right;">16</td> <td style="text-align: right;">5678592</td> <td style="text-align: right;">109900</td> </tr> <tr> <td style="text-align: right;"><code>10</code></td> <td style="text-align: right;"><code>573C00</code></td> <td style="text-align: right;">16</td> <td style="text-align: right;">5716992</td> <td style="text-align: right;">110200</td> </tr> <tr> <td style="text-align: right;"><code>10</code></td> <td style="text-align: right;"><code>589A00</code></td> <td style="text-align: right;">16</td> <td style="text-align: right;">5806592</td> <td style="text-align: right;">110900</td> </tr> <tr> <td style="text-align: right;"><code>10</code></td> <td style="text-align: right;"><code>58B300</code></td> <td style="text-align: right;">16</td> <td style="text-align: right;">5812992</td> <td style="text-align: right;">110950</td> </tr> <tr> <td style="text-align: right;"><code>13</code></td> <td style="text-align: right;"><code>173240</code></td> <td style="text-align: right;">19</td> <td style="text-align: right;">1520192</td> <td style="text-align: right;">619300</td> </tr> <tr> <td style="text-align: right;"><code>13</code></td> <td style="text-align: right;"><code>173880</code></td> <td style="text-align: right;">19</td> <td style="text-align: right;">1521792</td> <td style="text-align: right;">619400</td> </tr> </tbody> </table> </div>
31737
2023-04-01T16:47:12.703
<p>I'm reverse engineering a hardware device which stores time a strange format:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>32-bit word</th> <th>H:MM:SS (rounded)</th> </tr> </thead> <tbody> <tr> <td>0x03200000</td> <td>0:00:00</td> </tr> <tr> <td>0x09700000</td> <td>0:00:00</td> </tr> <tr> <td>0x0A1B0000</td> <td>0:00:01</td> </tr> <tr> <td>0x0A160000</td> <td>0:00:01</td> </tr> <tr> <td>0x0B098000</td> <td>0:00:02</td> </tr> <tr> <td>0x0F376600</td> <td>0:00:46</td> </tr> <tr> <td>0x0F347800</td> <td>0:00:46</td> </tr> <tr> <td>0x10038B00</td> <td>0:01:07</td> </tr> <tr> <td>0x10040800</td> <td>0:01:07</td> </tr> <tr> <td>0x1056A600</td> <td>0:01:49</td> </tr> <tr> <td>0x10573C00</td> <td>0:01:50</td> </tr> <tr> <td>0x10589A00</td> <td>0:01:50</td> </tr> <tr> <td>0x1058B300</td> <td>0:01:50</td> </tr> <tr> <td>0x13173240</td> <td>0:10:19</td> </tr> <tr> <td>0x13173880</td> <td>0:10:19</td> </tr> </tbody> </table> </div> <p>I believe the time is recorded in some internal high-frequency timer ticks, but I don't see any linear correspondence between the words and time values. Any tips?</p> <p>UPD. I found out that it's Texas Instruments's custom floating-point format for TMS320 DSPs. Described <a href="http://www.ti.com/lit/pdf/spra400" rel="nofollow noreferrer">here</a>.</p>
Decoding a time format
|binary-format|
<p>As per the comment made by @blabb on his answer, I looked at the Win16 WINDOWS.H header file (from the Windows 3.1 Driver Development Kit (DDK)) to see which calling conventions were used for the Win16 API functions at the time.</p> <p>At the beginning of the file, the following macro is defined:</p> <p><code>#define WINAPI _far _pascal</code></p> <p>This macro is then appended to the beginning of most of the functions in the file, for example:</p> <p><code>int WINAPI MessageBox(HWND, LPCSTR, LPCSTR, UINT);</code></p> <p><code>UINT WINAPI GetPrivateProfileInt(LPCSTR, LPCSTR, int, LPCSTR);</code></p> <p><code>LPSTR WINAPI lstrcpy(LPSTR, LPCSTR);</code></p> <p>So it seems as though most of the Win16 API functions were defined with the Pascal calling convention, which explains why I can see the parameters being <code>PUSH</code>ed backwards onto the stack before the <code>CALL</code> instruction is utilised.</p> <p>So by implementing the function this way:</p> <p><a href="https://i.stack.imgur.com/aeR1K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aeR1K.png" alt="Ghidra implementation of the WIN16 MessageBox function with the Pascal calling convention." /></a></p> <p>The parameters are pulled in correctly and the decompilation is accurate.</p> <p><a href="https://i.stack.imgur.com/sgJbz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sgJbz.png" alt="Ghidra decompilation of the WIN16 MessageBox function using the Pascal calling convention." /></a></p> <p>Currently, I'm having to setup the parameter storage manually as Ghidra does not support the Pascal calling convention, an issue on GitHub has been opened here: <a href="https://github.com/NationalSecurityAgency/ghidra/issues/496" rel="nofollow noreferrer">https://github.com/NationalSecurityAgency/ghidra/issues/496</a></p>
31756
2023-04-06T16:02:15.920
<p>I am currently attempting to reverse engineer a simple function from within a 16-Bit Windows 3.1 (NE) DLL, which from what I can tell is used to display a message box when required.</p> <p>I would assume that the two arguments of the <code>ShowMessageBox</code> function are used to set the Title and Message (this is a DLL so I assume it doesn't bother with a HWND?). I can see that those two parameters get passed in and are pushed to the stack, but can't quite work out how they are passed into the system call.</p> <p>Ghidra seems a little confused as the C source ignores the two parameters and passes in the two other values that are added into the stack (<code>0x41</code> and <code>0x41b</code>).</p> <p>I have added the following function signature into the MessageBox system call:</p> <pre><code>int MessageBox (HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, uint uType) </code></pre> <p>An example of the message box produced by this function is:</p> <p><a href="https://i.stack.imgur.com/KAkxM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KAkxM.png" alt="Message Box Example" /></a></p> <p>Any suggestions would be greatly appreciated.</p> <p>The assembly and Ghidra generated C source are included below.</p> <pre><code>************************************************************** * FUNCTION * ************************************************************** void __cdecl16far ShowMessageBox(undefined param_1,undefined param_2) assume DS = 0x1008 void &lt;VOID&gt; &lt;RETURN&gt; undefined Stack[0x4]:1 param_1 undefined Stack[0x6]:1 param_2 1000:001c c8 00 00 00 ENTER 0x0,0x0 1000:0020 57 PUSH DI 1000:0021 56 PUSH SI 1000:0022 6a 00 PUSH 0x0 1000:0024 ff 76 08 PUSH word ptr [BP + param_2] 1000:0027 ff 76 06 PUSH word ptr [BP + param_1] 1000:002a 1e PUSH DS 1000:002b 68 1b 04 PUSH 0x41b 1000:002e 6a 41 PUSH 0x41 1000:0030 9a 5c 00 CALLF USER::MessageBox 18 10 1000:0035 e9 00 00 JMP LAB_1000_0038 </code></pre> <pre><code>void __cdecl16far ShowMessageBox(undefined param_1,undefined param_2) { HWND unaff_CS; MessageBox(unaff_CS,(LPCTSTR)0x41,(LPCTSTR)0x41b,0x1008); return; } </code></pre> <p>Thanks, James.</p>
Help disassembling a simple 16-bit NE function
|disassembly|windows|decompilation|ghidra|ne|
<p>Right-click on the operand, click &quot;Manual...&quot;, enter the string &quot;5 * 20&quot;. Note that this only works in the disassembly listing, and that there is no comparable functionality in the decompilation.</p>
31765
2023-04-11T12:52:49.573
<p>Is it possible to force <a href="https://en.wikipedia.org/wiki/Interactive_Disassembler" rel="nofollow noreferrer">IDA</a> to show &quot;5 * 20&quot; instead of &quot;100&quot; in the below disassembled and decompiled lines?</p> <pre class="lang-none prettyprint-override"><code>MOV R1, #100 -&gt; MOV R1, #(5 * 20) LDR R8, =var | LDR R8, =var STR R1, [R8] | STR R1, [R8] </code></pre> <p>Corresponding decompiled code:</p> <pre class="lang-none prettyprint-override"><code>var = 100; -&gt; var = 5 * 20; </code></pre>
How can I disassemble/decompile an immediate value to multiplication/summation of two values with IDA Pro?
|ida|disassembly|decompilation|arm|
<p>I see that there were some problems with released versions up to 1.02. With latest changes I had no problem loading your example binary. <a href="https://github.com/achan1989/ghidra-65816/commit/6df2b00cf27af4bc3c259cf499ca2ea9b6f92522" rel="nofollow noreferrer">https://github.com/achan1989/ghidra-65816/commit/6df2b00cf27af4bc3c259cf499ca2ea9b6f92522</a></p>
31788
2023-04-15T12:34:15.640
<p>I want to reverse engineer some 65816 code using Ghidra. Unfortunately the third-party 65816 language is broken. No problem, I can fix it myself. However, looking at the Ghidra error gives me no clue as to what the problem is. I've looked at the <code>.slaspec</code> and it appears to be correct so a verbose error would be helpful. The message mentions checking the log messages but I can't find anything.</p> <p>Is there a way to debug the problem with the language?</p> <p>Ghidra Error:</p> <pre><code>Errors compiling /home/rob/tools/ghidra_10.2.3_PUBLIC/Ghidra/Processors/65816/data/languages/65816.slaspec -- please check log messages for details ghidra.app.plugin.processors.sleigh.SleighException: Errors compiling /home/rob/tools/ghidra_10.2.3_PUBLIC/Ghidra/Processors/65816/data/languages/65816.slaspec -- please check log messages for details at ghidra.app.plugin.processors.sleigh.SleighLanguage.reloadLanguage(SleighLanguage.java:520) at ghidra.app.plugin.processors.sleigh.SleighLanguage.initialize(SleighLanguage.java:150) at ghidra.app.plugin.processors.sleigh.SleighLanguage.&lt;init&gt;(SleighLanguage.java:116) at ghidra.app.plugin.processors.sleigh.SleighLanguageProvider.getNewSleigh(SleighLanguageProvider.java:112) at ghidra.app.plugin.processors.sleigh.SleighLanguageProvider.getLanguage(SleighLanguageProvider.java:99) at ghidra.program.util.DefaultLanguageService$LanguageInfo.lambda$getLanguage$0(DefaultLanguageService.java:385) at ghidra.util.task.TaskBuilder$TaskBuilderTask.run(TaskBuilder.java:306) at ghidra.util.task.Task.monitoredRun(Task.java:134) at ghidra.util.task.TaskRunner.lambda$startTaskThread$0(TaskRunner.java:106) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833) </code></pre> <p><a href="https://github.com/achan1989/ghidra-65816" rel="nofollow noreferrer">65816 language support</a></p> <p><a href="http://www.zimmers.net/anonftp/pub/cbm/firmware/misc/cmd/scpu-dos-1.4.bin" rel="nofollow noreferrer">Example binary</a></p>
Debug problem with Ghidra 3rd party language
|ghidra|java|
<p>I managed to solve this one myself thanks to @Blabb's comment (thanks again!).</p> <p>The first identifiable string was <code>MS Run-Time Library - Copyright (c) 1992, Microsoft Corp</code>.</p> <p>For some reason, this managed to throw Ghidra off, and it added just this string to a memory segment of its own. This, therefore, offset all of the other strings as they were pushed down into their own memory segment, causing the incorrect offsets.</p> <p>To solve this, I used Ghidra's Memory Manager to remove the two memory segments, and then create a new one with all the strings combined.</p> <p>Before: <a href="https://i.stack.imgur.com/z51td.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z51td.png" alt="Ghidra Memory Map before changes" /></a> After: <a href="https://i.stack.imgur.com/V5mgX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V5mgX.png" alt="Ghidra Memory Map after changes" /></a></p> <p>As a result of these changes, and with the DS register set to the correct offset, the string now shows in the decompiler window.</p> <p><a href="https://i.stack.imgur.com/heyE8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/heyE8.png" alt="Strings showing in the Ghidra decompilation window" /></a></p>
31793
2023-04-17T00:05:17.033
<p>I am attempting to reverse-engineer a 16-Bit DOS MZ executable.</p> <p>The file contains many different strings, most of which are printed out to the console at various points.</p> <p>IDA seems to be able to pick up the locations from which the strings are utilised, for example:</p> <p><a href="https://i.stack.imgur.com/sMBVr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sMBVr.png" alt="IDA String Information" /></a></p> <p>Clicking on this reference shows the code that utilises the string, which I assume passes it into the function (sub 1462) which prints it out to the screen.</p> <p><a href="https://i.stack.imgur.com/49bhe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/49bhe.png" alt="Code that utilises the above string" /></a></p> <p>When I attempt to analyse the same code in Ghidra, it is unable to pickup the same strings. I have manually gone to the location shown in IDA, and setup the &quot;print&quot; (sub 1462) function in this way:</p> <p><a href="https://i.stack.imgur.com/7MPDq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7MPDq.png" alt="PrintString Function Definition" /></a></p> <p>So I would expect the decompiler to show the string, however it doesn't seem to pick it up:</p> <p><a href="https://i.stack.imgur.com/J2UPA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J2UPA.png" alt="Print String Function in Ghidra Decompiler" /></a></p> <p><a href="https://i.stack.imgur.com/i5m40.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i5m40.png" alt="Print String Function in Ghidra Decompiler" /></a></p> <p>I'm assuming that this has something to do with the stack pointer being set (or assumed to be) an incorrect value? However, Ghidra seems to locate this string at a different location to IDA:</p> <p><a href="https://i.stack.imgur.com/WXiy0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WXiy0.png" alt="IDA String Location" /></a></p> <p>Thanks, James.</p>
Ghidra 16-Bit DOS Strings
|ghidra|strings|dos|dos-exe|
<p>I found the solution for this issue, and post it here hope help someone someday...</p> <p>I undefined the &quot;arr_of_struct&quot; (Ctrl+U), undefined both the array and also the structure variable:</p> <p><a href="https://i.stack.imgur.com/cD6cv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cD6cv.jpg" alt="enter description here" /></a> <strong>====&gt;</strong> <a href="https://i.stack.imgur.com/hmaq8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hmaq8.jpg" alt="enter image description here" /></a></p> <p>The output changed to deal with the undefined variable:</p> <p><a href="https://i.stack.imgur.com/7ZkXx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ZkXx.jpg" alt="enter image description here" /></a></p> <p>Declare struct variable again (Alt+Q), and define its location as an array (Pressing *), and the output changed to the right and expected shape:</p> <p><a href="https://i.stack.imgur.com/ksHRL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ksHRL.jpg" alt="enter image description here" /></a></p> <p>Now I know how to fix it, but the first question is still remains:</p> <p><strong>What's the reason of this behavior in IDA? Is there a sequence needed to consider while defining array of structures?</strong></p>
31795
2023-04-17T08:42:47.533
<p>There is a structure with size of 16-Bytes, and an array of it is defined. The disassembly code for navigation through the array is:</p> <pre><code>MOV i, i,LSL#4 LDR R4, =arr_of_struct ADD i, i, R4 LDR var, [i] </code></pre> <p>But the decompiled code is:</p> <pre><code>var = arr_of_struct[4 * i]; </code></pre> <p>Which is wrong and should be:</p> <pre><code>var = arr_of_struct[4 * i].field_0; </code></pre> <p>I think the problem is in first line of disassembly <code>MOV i, i,LSL#4</code>. Obviously it is multiplying the array index by 16 which is the size of my struct. But IDA translated this line to <code>[4 * i]</code> !!!</p> <p>So the first question is what's the reason of this behavior in IDA? And the second is how can I fix this?</p> <p>EDIT: More information:</p> <p><a href="https://i.stack.imgur.com/ZvbuD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZvbuD.jpg" alt="enter image description here" /></a></p>
IDA Decompiler generates wrong output on array of structures!
|decompilation|hexrays|struct|array|
<p>I have answered in the github ticket. But I'm copypasting the answer for practical reasons :9 That's the oneliner you want:</p> <p><code>r2 -c “dcu main;e dbg.trace=true;dsu -1;dt” -d /bin/ls</code></p> <p>Some comments below:</p> <ul> <li>The dts+ command is used for stepback and dumps/records the state of memory in disk for every step which is not what you want</li> <li>dbg.swstep is causing an stack exhaustion if you try to run the whole program ( i need to fix this )</li> <li>dsu -1 is the only way you have to perform step until the program is gone. a helper command under <code>dc</code> would be easier to spot</li> <li>You cant pass flags after the -d</li> <li>No need to analyze the program or avoid home scripts (-NA)</li> <li>Use the dtj command to log the traces in json format if you want to post process the execution information</li> <li>I would recommend disabling ASLR if you want to do multiple traces and compare them</li> </ul> <p>Also, bear in mind that you can't use <code>dtd</code> if you run the traces until the program dies, because there will be no memory allocated and you cant disassemble . better to continue until a specific address or exit syscall or so.</p> <p>Another thing is that you are tracing EVERYTHING so you probably want to see other vars like dbg.trace.inrange or dbg.trace.libs to avoid recording instructions from libraries or from sections of the binary that you dont need.</p>
31804
2023-04-20T11:35:02.263
<p>more detailed see <a href="https://github.com/radareorg/radare2/issues/21585#issuecomment-1506947579" rel="nofollow noreferrer">this</a></p> <p>In short, I want to skip syscall when recording program, but it seems that the program would always stop after ths syscall.</p> <p>Hope someone can help me. Thanks.</p> <p>below is running results:</p> <pre class="lang-bash prettyprint-override"><code>$ git rev-parse origin/master 093d583000f9f78ec1a4d8643cb59e465a0ede7c $ git diff origin/master diff --git a/libr/main/radare2.c b/libr/main/radare2.c index 2bc1cb68f9..15ce049d9c 100644 --- a/libr/main/radare2.c +++ b/libr/main/radare2.c @@ -1706,7 +1706,7 @@ R_API int r_main_radare2(int argc, const char **argv) { debug = r_config_get_b (r-&gt;config, &quot;cfg.debug&quot;); if (ret != -1 &amp;&amp; r_cons_is_interactive ()) { char *question; - bool no_question_debug = ret &amp; 1; + bool no_question_debug = 1; $ r2 -NAd -c &quot;db main;dts+;db;dc;dr rip;pd-- 4&quot; /mnt/ubuntu/home/czg/csapp3e/asm/prog ... 0x00401060 - 0x00401061 1 --x sw break enabled valid cmd=&quot;&quot; cond=&quot;&quot; name=&quot;main&quot; module=&quot;/mnt/ubuntu/home/czg/csapp3e/asm/prog&quot; 0x7fbe6445b08b 0x7fbe6445b07e 6690 nop ; CALL XREF from map._usr_lib_ld_linux_x86_64.so.2.r_x @ +0x198ae(x) ; CALL XREFS from rip @ +0x5238(x), +0x5252(x) 0x7fbe6445b080 f30f1efa endbr64 0x7fbe6445b084 b80c000000 mov eax, 0xc ; 12 0x7fbe6445b089 0f05 syscall 0x7fbe6445b08b 488905e64101. mov qword [0x7fbe6446f278], rax ; [0x7fbe6446f278:8]=0 0x7fbe6445b092 4839f8 cmp rax, rdi ,=&lt; 0x7fbe6445b095 7209 jb 0x7fbe6445b0a0 | 0x7fbe6445b097 31c0 xor eax, eax [0x7fdcd2e4908b]&gt; ds [0x7fdcd2e4908b]&gt; dr rip 0x7fdcd2e49092 </code></pre> <p>Best regards</p>
Can radare2 skip syscall when `db main;dts+;dc`
|debugging|radare2|
<p>I don't know if it's still a problem for you, but it might be related to this:</p> <p><a href="https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices</a></p> <p>and more particularly this sentence:</p> <p>&quot;Improper synchronization within DllMain can cause an application to deadlock or access data or code in an uninitialized DLL. Calling certain functions from within DllMain causes such problems.&quot;</p> <p>So my guess is that the malware you're debugging is trying to call HttpSendRequestA before it exits DllMain ?</p>
31819
2023-04-24T16:21:55.533
<p>I'm reverse engineering a malware that at some point tries to connect to <code>http://api.ipify.org</code> in order to get the IP address of the infected PC.</p> <p>I was able to replicate this behaviour with a small Python script, but for some reason, I can't get the same result when debugging the malware (in my dynamic-analysis VM using <strong>x32dbg</strong>), due to the fact that execution hangs indefinitely inside <code>HttpSendRequestA</code>.</p> <p>I tried to trace the execution flow inside that API, and the reason of the hang is a call to <code>WaitForSingleObjectEx</code> in <strong>wininet.dll</strong> (so, nothing to do with the malware itself).</p> <p>If I try to patch the <code>dwMilliseconds</code> param of <code>WaitForSingleObjectEx</code> (causing a timeout) I can get further to the execution, but eventually I get stuck another time when the malware tries to perform another http request.</p> <p>I tried to run this sample on another dynamic-analysis VM with Fakenet-ng installed and I can't even see the attempt to perform the http requests from the log.</p> <p>In both VMs the network is online.</p> <p>Am I missing something obvious here?</p> <p><strong>EDIT:</strong></p> <p>I tried to run the malware outside the debugger (still in a VM with fakenet) and I see the http requests from the log! So the issue described here <strong>only happens when running INSIDE the debugger</strong>. Still, I don't think that this is an anti-debugging trick: I have reverse-engineered and documented EVERY function of this malware and I haven't found any anti-debugging stuff.</p> <p><strong>EDIT2:</strong></p> <p>It seems that this user had the same issue (usign a different debugger):</p> <p><a href="https://reverseengineering.stackexchange.com/questions/19431/ollydbg-runs-away-when-stepping-over-wininet-httpsendrequestw">OllyDbg &quot;runs away&quot; when stepping over wininet.HttpSendRequestW</a></p> <p><strong>EDIT3:</strong></p> <p>Found a workaround (described in the answer bellow)</p>
Malware analysis - Debugger hangs at HttpSendRequestA
|windows|debugging|malware|x64dbg|networking|
<p>Please read the tutorial carefully.</p> <p>Moreover, the pictures you provided don't say anything. As correctly noted in the comments -- without the file itself being investigated -- we have no way to help you.</p> <p>Here's another picture for you <a href="https://i.stack.imgur.com/5Sm61.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Sm61.png" alt="enter image description here" /></a></p> <hr /> <p>Gist: <a href="https://gist.github.com/isira-adithya/8ab4a2d6374708418cef7c2b10b8de56" rel="nofollow noreferrer">TryHackMe - REloaded (Writeup by Isira Adithya)</a></p> <p><a href="https://tryhackme.com/room/reloaded" rel="nofollow noreferrer">Link to the Room</a></p>
31820
2023-04-24T17:26:58.863
<p>I am doing TryHackMe REloaded room, level 3.</p> <p>When I got stuck I followed <a href="https://0xcd4.medium.com/reverse-engineering-reloaded-ctf-35558cec4b5e" rel="nofollow noreferrer">this</a> tutorial which mentions an XOR by 7 operation being performed on a string, however I cannot see it anywhere.</p> <p>Where is it happening in the below image from IDA Free?</p> <p><a href="https://i.stack.imgur.com/oBsjy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oBsjy.jpg" alt="Where is the XOR?" /></a></p> <p>The call highlighted in yellow above:</p> <p><a href="https://i.stack.imgur.com/jzvn6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jzvn6.jpg" alt="Sub function" /></a></p>
Where is the XOR operation?
|ida|assembly|breakpoint|crackme|xor|
<p>What you want exists and is known -- among other terms -- under the term &quot;time travel debugging&quot; (TTD), &quot;replay debugging&quot; and &quot;record and replay debugging&quot;. Your processor needs to support it.</p> <ul> <li>WinDbgX (the one from the MS store) <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/time-travel-debugging-overview" rel="nofollow noreferrer">has support</a> for that (i.e. <code>winget install -e --id Microsoft.WinDbg</code>).</li> <li>GDB also <a href="https://sourceware.org/gdb/onlinedocs/gdb/Process-Record-and-Replay.html" rel="nofollow noreferrer">has support</a> for it.</li> <li><a href="https://rr-project.org/" rel="nofollow noreferrer">rr</a> is even dedicated to the whole concept.</li> <li>VMware used to include the feature called &quot;replay debugging&quot; for a few major versions; unfortunately it got scrapped.</li> </ul> <p><strong>However, it's not possible to take <em>a mere memory dump</em> and &quot;revive&quot; a process based on that.</strong> The record &amp; replay method involves a whole lot more than just the memory state. Also, memory dumps often are only an excerpt of the full memory space of a process.</p>
31834
2023-05-01T15:36:30.467
<p>Are there any tools that can &quot;record&quot; the memory space of a process and then be able to restore it from a certain timestamp? As in, the process is recreated in the exact same state as if &quot;loading a saved game&quot;.</p> <p>Context is that of a game that crashes either while attempting to save/load a game or certain conditions are met (e.g. unit count &gt; 5000). There are no debug logs.</p>
Load process from memory dump
|memory|memory-dump|
<p>As I commented if the Most significant Bit (31 for x86 or 63 for x64)<br /> is set then the import is done by ordinal and no name lookup is done.</p> <p>the msdn article by matt pietrek is still gold but if you need a latest reference<br /> <a href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-lookup-table" rel="nofollow noreferrer">PE FORMAT IMPORT LOOKUP TABLE SECTION</a></p> <p>ordinals can change be added be removed or be converted to name lookup</p> <p>in an x64 win 10 machine using dumpbin from vs i can see shell32 export ordinal number 680 is the function IsUserAnAdmin()</p> <pre><code>dumpbin /exports c:\Windows\System32\shell32.dll | grep -iE &quot;ordinal hint| 680&quot; ordinal hint RVA name 680 57 002752A0 IsUserAnAdmin </code></pre>
31840
2023-05-04T12:52:26.823
<p>I am attempting to understand the PE File Format and I have come across an unexpected value in the <em>IMAGE_THUNK_DATA</em> Array.<br><br></p> <p>Here are the file details:<br> MD5: d82d3e003eb5c728d584e22ce7f36fbf<br> File Name: ChromeSetup.exe Link: hxxps://www[.]google[.]com/chrome/thank-you.html?platform=win64&amp;statcb=1&amp;installdataindex=empty&amp;defaultbrowser=0</p> <p>(After some testing, I found out that the hash changes but the issue is the same.)</p> <p>The issue I'm facing is that in one of the DLLs that is present, the <em>IMAGE_THUNK_DATA</em> structure contains an additional DWORD that is out-of-bounds. Here's the attached screenshot:<br><br><a href="https://i.stack.imgur.com/gk95c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gk95c.png" alt="Out-of-Bounds DWORD" /></a>:</p> <p>That first block i.e. (48fe 0100), resolves perfectly to &quot;SHGetFolderPathW&quot;. But that second block (a8020080) is out of bounds - adjusting for endian format, we get 0x800002a8 - but the file itself is present up till 0x14DE2A (verified via 010 Editor and xxd). The third block signifies the end of the <em>IMAGE_THUNK_DATA</em> array so no issues there.</p> <p>I've checked using 010 Editor and it shows &quot;SHGetFolderPathW&quot; as the only function imported from SHELL32.dll. I'd greatly appreciate some help understanding why that second block is present if no function name resolves to that address, which is out-of-bounds by itself?</p>
Unexpected value present in IMAGE_THUNK_DATA array
|pe|
<blockquote> <p><strong>Download <em><a href="https://drive.google.com/drive/folders/1kqwmBbktWQ4LdWT-ihotIO_inzeDE6ns" rel="noreferrer">script and config file</a></em></strong></p> </blockquote> <ul> <li>Install zcu from <a href="https://github.com/mkst/zte-config-utility" rel="noreferrer">https://github.com/mkst/zte-config-utility</a></li> </ul> <pre><code>KEY = SERIAL + MAC: CF28772Bf438d406f608 from paramtag IV = DefAESCBCIV: ZTE%FN$GponNJ025 from /etc/hardcodefile/dataprotocol </code></pre> <p>Example command: .cmd.example.cmd</p> <pre><code>ECHO decode config.bin to config.xml decode.py --key CF28772Bf438d406f608 config.bin config.xml ECHO encode config.xml to config.out.bin encode.py --key CF28772Bf438d406f608 config.xml config.out.bin --include-header --signature F660 ECHO decode db_backup_cfg.xml to db_backup_cfg.xml.xml decode.py --key CF28772Bf438d406f608 db_backup_cfg.xml db_backup_cfg.xml.xml ECHO encode db_backup_cfg.xml.xml to db_backup_cfg.out.xml without signature and header encode.py --key CF28772Bf438d406f608 db_backup_cfg.xml.xml db_backup_cfg.out.xml </code></pre> <ul> <li>Decode <code>dataprotocol</code>: <a href="https://github.com/douniwan5788/zte_modem_tools" rel="noreferrer">https://github.com/douniwan5788/zte_modem_tools</a></li> </ul> <p>command: <code>zte_hardcode_dump.py hardcode dataprotocol</code></p> <p><code>/etc/hardcodefile/dataprotocol</code> after decrypt</p> <pre><code>DefAESCBCKey=f680v9.0 DefAESCBCIV=ZTE%FN$GponNJ025 AESENCRYKey= userkey=608158c36497b00221db14afb845c9e3 </code></pre> <ul> <li><code>paramtag</code></li> </ul> <pre><code>Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000000 54 41 47 48 30 32 30 31 00 00 00 00 02 9D 5E CB TAGH0201......^Ë 00000010 DC 03 00 00 00 90 40 00 40 00 56 39 2E 30 2E 31 Ü.....@.@.V9.0.1 00000020 30 50 32 4E 32 42 00 00 00 00 00 00 00 00 00 00 0P2N2B.......... 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 01 06 00 ................ 00000060 06 00 08 F6 06 D4 38 F4 01 01 06 00 06 00 08 F6 ...ö.Ô8ô.......ö 08 F6 06 D4 38 F4 is MAC -&gt; f438d406f608 00000070 06 D4 38 F5 02 01 06 00 06 00 08 F6 06 D4 38 F6 .Ô8õ.......ö.Ô8ö 00000080 03 01 06 00 06 00 08 F6 06 D4 38 F7 04 01 06 00 .......ö.Ô8÷.... 00000090 06 00 08 F6 06 D4 38 F8 05 01 06 00 06 00 08 F6 ...ö.Ô8ø.......ö 000000A0 06 D4 38 F9 80 08 04 00 04 00 5A 54 45 47 00 00 .Ô8ù€.....ZTEG.. 000000B0 81 08 08 00 08 00 43 46 32 38 37 37 32 42 00 00 ......CF28772B.. CF28772B is SERIAL 000000C0 00 03 06 00 06 00 30 38 46 36 30 36 00 02 24 00 ......08F606..$. 000000D0 24 00 00 00 01 00 64 72 6D 2F 66 ED 6D 46 BF A2 $.....drm/fímF¿¢ 000000E0 AE FD 7D 81 E4 57 59 65 82 04 8A 78 74 6B 03 66 ®ý}.äWYe‚.Šxtk.f 000000F0 0F 99 A0 27 E2 F3 00 00 01 06 04 00 04 00 75 73 .™ 'âó........us 00000100 65 72 00 00 01 07 04 00 04 00 75 73 65 72 00 00 er........user.. 00000110 00 04 09 00 09 00 53 4C 54 5F 46 49 42 52 45 00 ......SLT_FIBRE. 00000120 10 05 09 00 09 00 53 4C 54 5F 46 49 42 52 45 00 ......SLT_FIBRE. </code></pre>
31848
2023-05-09T06:37:42.927
<p>I need support to decrypt the config file of ZTE F660 v9 router. I have telnet access to the router and the below link consists of the following files.</p> <p><a href="https://drive.google.com/drive/u/2/folders/1cYJDqzNzU14MgI8yMwobdvhmogpGjv0e" rel="nofollow noreferrer">Link</a></p> <p>config.bin, paramtag, cspd, db_user_cfg.xml, db_backup_cfg.xml</p>
Decrypt the config file of ZTE F660 v9
|decryption|router|
<p>x64dbg has the <a href="https://help.x64dbg.com/en/latest/commands/analysis/virtualmod.html" rel="nofollow noreferrer">virtualmod</a> command, which (in theory) can be used to detect modules loaded from memory, rather than via <code>LoadLibrary*</code> APIs:</p> <blockquote> <p>virtualmod<br /> <br /> Tell the debugger to treat a memory range as a virtual module.<br /> <br /> Arguments: <br /> <code>arg1</code> the user-supplied module name.<br /> <code>arg2</code> the base of the memory range.<br /> <code>[arg3]</code> the size of the memory range.</p> </blockquote> <p>However, this command seems to be broken at the time of writing this answer. I've experimented a little bit and managed to make it functional, see this <a href="https://github.com/ynwarcs/x64dbg/commit/aa0a5cd82cdb1998af2f9f020fefd86db368f2b4" rel="nofollow noreferrer">commit</a> in a forked repository for reference. This will allow you to see the module in x64dbg, as well as its symbols, exports, imports etc. For a fully native experience, though, a fix is needed in MemoryModule as well - see this <a href="https://github.com/ynwarcs/MemoryModule/commit/10250ad4b7ee464579dfb13605427bad1626cbd9" rel="nofollow noreferrer">commit</a> in a forked repository for reference.</p> <p>To use it, execute the following in x64dbg:</p> <pre><code>virtualmod some_module_name.dll, 0xsome_base_address </code></pre> <p>If you don't mind building your own x64dbg and MemoryModule and applying these fixes, this should work out-of-the-box (no promises though). I've also opened <a href="https://github.com/x64dbg/x64dbg/issues/3094" rel="nofollow noreferrer">an issue</a> in x64dbg to discuss the state of <code>virtualmod</code> and whether it can be fixed in the main branch as well.</p>
31861
2023-05-12T12:35:25.650
<p>I need to debug a DLL, which I have a PDB file for.</p> <p>The debug target is a program, that loads the DLL using MemoryModule library from <a href="https://github.com/fancycode/MemoryModule" rel="nofollow noreferrer">Github</a>.</p> <p>The loaded module isn't listed as a module in x64dbg, since it has been loaded with <code>MemoryLoadLibraryEx</code> function, but module handle is still valid and it's all been successfully loaded and initialized.</p> <p>I've tried <code>symload</code> x64dbg command with address as the argument pointing to the beginning of the memory-loaded module <code>MZ...</code>, tried pointing to <code>PE...</code> signature as well, but no success.</p> <p>How do I tell x64dbg that memory at an address is a valid module, so that I could load a PDB for that module?</p>
Load PDB for MemoryModule-loaded DLL in x64dbg
|dll|x64dbg|dynamic-linking|debugging-symbols|pdb|
<p>There's no definitive way to tell what instructions correspond to a single function, i.e. what exactly represents a function when looking only at the set of instructions. Compilers are free to optimize the high level code in any way they like. For reference, you can see the <a href="https://stackoverflow.com/a/25880860">answer</a> provided here.</p> <p>Luckily, compilers usually output predictable patterns, so Ghidra, Radare and other disassemblers first locate what they believe is a function by pattern matching and analysis of other functions, then analyze the control flow of the instructions to establish the control flow graph of the function and determine which branches the function has, where it &quot;ends&quot; etc.</p> <p>There is also some good information here: <a href="https://stackoverflow.com/questions/41622226/assembly-function-recognition">https://stackoverflow.com/questions/41622226/assembly-function-recognition</a></p>
31868
2023-05-14T21:23:56.683
<p>Finding the start of a function is sometimes obvious - for example if some part of the code has a <code>call foo</code> then <code>foo</code> must be a function.</p> <p>But what about finding the end of a function? I realize tools like Radare and Ghidra do this, but it seems like they must be using heuristics because some things that &quot;look like&quot; the end of a function aren't. For example (in pseudo-asm):</p> <pre><code>foo: sub r1,r2 jge something ret something: add r1,r2 ret </code></pre> <p>I would say this is one function that happens to have two different exit points, but how would a RE tool figure this out?</p>
How can you tell where an assembly function ends?
|assembly|static-analysis|
<p>I believe this information is not stored within the PDB files in any recent versions.</p> <p>Microsoft's <a href="https://learn.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/debug-interface-access-sdk?view=vs-2022" rel="nofollow noreferrer">DIA SDK</a> used for dumping information contained in PDB files does provide a method named <a href="https://learn.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/idiasymbol-get-virtualaddress?view=vs-2022" rel="nofollow noreferrer"><code>get_virtualAddress</code></a> (as opposed to <a href="https://learn.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/idiasymbol-get-relativevirtualaddress?view=vs-2022" rel="nofollow noreferrer"><code>get_relativeVirtualAddress</code></a>) which should, in theory, return the real virtual address of a static symbol (segment, section, frame data etc.), however both of these methods currently return the same value (RVA) in all test cases I've tried. The implementations of two methods <em>are</em> different though, suggesting that there could be some use cases where the VAs are in fact stored within the data.</p> <p>Keep in mind that the PDB format dates back to 90s, so if I had to guess I'd say that the actual VA's were contained within PDB files back before ASLR was introduced. This is, of course, only speculation on my part.</p>
31872
2023-05-15T13:21:20.287
<p>Is <code>ImageBase</code> of a PE binary present in its PDB or can it only be retrieved from the binary?</p> <p>I have studied both <a href="https://github.com/microsoft/microsoft-pdb" rel="nofollow noreferrer">Microsoft's PDB sources</a> and <a href="https://llvm.org/docs/PDB/index.html" rel="nofollow noreferrer">LLVM docs</a> without much luck finding it.</p> <p>In the <a href="https://llvm.org/docs/PDB/DbiStream.html#optional-debug-header-stream" rel="nofollow noreferrer">DBI stream</a> there exist section headers with section RVAs, but I couldn't find any trace of their corresponding VAs or the base address itself.</p>
PE ImageBase presence in PDB
|pe|address|pdb|
<p>I guess I'll copy my comment as an answer, just to close out the question:</p> <p>I re-read the error message: <code>Could not load file or assembly 'd3g_tech_managed.dll' **or one of its dependencies**</code> and it listed the file name <code>d3g_tech_managed.dll</code>, which I figured meant it couldn't find that file. Ends up <code>d3g_tech_managed.dll</code> in turn depends on <code>base.dll</code> (whose name alone should have made me think), which I didn't copy. Once I did, my test program runs and correctly reports the library version on the form. So, completely my bad.</p> <p>Thanks @ynwarcs, your comment made me recheck the obvious!</p>
31886
2023-05-20T10:38:46.597
<p>Sorry if this is a bit long; I figured it might be helpful to provide some information on why I'm trying to do what I'm doing. If not, just skip to the &quot;My Problem&quot; section.</p> <h1>Background</h1> <p>I'm writing some software to automate water billing at some apartment buildings. The water meters communicate using a proprietary protocol to a receiver, which sends the data to the computer via RS232 or serial-over-Bluetooth. The data are then <a href="https://i.stack.imgur.com/AL6Ao.png" rel="nofollow noreferrer">displayed in a .NET 4 application</a> provided by the hardware manufacturer, where they can be exported to CSV. I have all of the hardware, and using their own software, everything works as they intended (requiring manual export to CSV). I want to write my own application that can get the meter ID, current meter reading, and a few other things, to automate this process -- basically, I can just drive by the buildings with an Internet-connected laptop, and the system will grab all the meter data and can instantly generate bills for the correct customers.</p> <p>There was a 3rd-party private company doing this billing in the area, but they've since been bought by another company, and that new company refuses to add new accounts (even if the new customer is in the same building as an existing customer that they're already reading!) and has expressed interest in leaving the area entirely. There are also other issues, but they're beside the point.</p> <h1>Options</h1> <p>I figure the two most likely ways to make this happen are:</p> <ol> <li>Reverse-engineer the serial protocol, and have my own software read and interpret the data sent by the wireless reader</li> <li>Use a library that's bundled with their software, that appears to do all of the reading/interpreting already, in my application</li> </ol> <p>I've already made progress on Option 1, and <a href="https://i.stack.imgur.com/a1AH5.png" rel="nofollow noreferrer">identified the important parts</a> of the &quot;normal&quot; broadcasted packet, but I'd like to keep that as a &quot;Plan B,&quot; since it appears there is a library that can do all of this already, and they've already accounted for all the different kinds of packets that can be sent and received, and how to separate which data bytes are for which unit, especially when 25 units are broadcasting simultaneously with possibly different packet types with different structures and lengths.</p> <h1>Plan A - Using Their Library</h1> <p>Based on the objects contained in <code>d3g_tech_managed.dll</code>, it appears they have a nicely-packaged library that handles everything from opening the serial port, to receiving and decoding the broadcasted beacons, to raising events to which the main application subscribes and receives the already-decoded data.</p> <p><a href="https://i.stack.imgur.com/lb7yo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lb7yo.png" alt="Their managed library decodes the data" /></a></p> <p><a href="https://i.stack.imgur.com/zAR3k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zAR3k.png" alt="Already-decoded data used in .NET 4 application" /></a></p> <p>There's even a very helpful-sounding function in the library called &quot;ExtractValue&quot;, which is called by the main program's equally-helpful-sounding &quot;FillMeterReadData&quot; function.</p> <p><a href="https://i.stack.imgur.com/zMz2k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zMz2k.png" alt="Library also has a helpful-sounding &quot;ExtractValue&quot; function" /></a></p> <p>I can add the DLL to a new C#.NET application in VS2022, and all of the objects, functions, etc. appear to be present.</p> <p><a href="https://i.stack.imgur.com/aauIq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aauIq.png" alt="Add as reference to .NET application in VS2022" /></a></p> <h1>My Problem</h1> <p>This is my first time trying to do any kind of reverse-engineering or using a 3rd-party DLL in my own program, so sorry if this is an obvious problem.</p> <p>Initially, when I tried running the program, I got a:</p> <pre><code>System.BadImageFormatException: 'Could not load file or assembly 'd3g_tech_managed, Version=1.0.6422.19726, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.' </code></pre> <p>exception. Search results suggest that error is because I ran the application as 64-bit, but the DLL is 32-bit, which is true. Switched the application to x86, but then I get a <code>FileNotFoundException</code>:</p> <pre><code>System.IO.FileNotFoundException: 'Could not load file or assembly 'd3g_tech_managed.dll' or one of its dependencies. The specified module could not be found.' </code></pre> <p>How can it not find the file at all in 32-bit mode, when in 64-bit mode it had to have found the file for it to know it was the wrong format?</p> <p>The DLL file is in the application folder (source code and compiled <code>bin</code> folders). <a href="https://i.stack.imgur.com/tJRvj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tJRvj.png" alt="The file is in the application folder" /></a></p> <p>I found other suggestions about installing it into the GAC (Global Assembly Cache), but the command:</p> <pre><code>&quot;C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe&quot; -i d3g_tech_managed.dll </code></pre> <p>results in an error:</p> <pre><code>Failure adding assembly to the cache: Attempt to install an assembly without a strong name </code></pre> <p>The suggestions for that error seem to involve recompiling the DLL from source code, which I don't have. And, besides, since an existing .NET 4 application is able the use that DLL, it should be possible for me to write one that uses it in the same way, right?</p> <p>Some other possibly-useful information from dnSpy: clicking on the root for <code>d3g_tech_managed (1.0.6422.19726)</code> shows:</p> <pre><code>// C:\Program Files (x86)\Arad Technologies\3GTechnicianNET\d3g_tech_managed.dll // d3g_tech_managed, Version=1.0.6422.19726, Culture=neutral, PublicKeyToken=null // Native Entry point: 0x000098AD // Timestamp: 5980427D (2017-08-01 04:57:33) using System; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; [assembly: AssemblyVersion(&quot;1.0.6422.19726&quot;)] [assembly: SecurityRules(SecurityRuleSet.Level1)] [assembly: TargetFramework(&quot;.NETFramework,Version=v4.0&quot;, FrameworkDisplayName = &quot;.NET Framework 4&quot;)] [assembly: AssemblyProduct(&quot;d3g_tech_managed&quot;)] [assembly: CLSCompliant(true)] [assembly: AssemblyDescription(&quot;&quot;)] [assembly: AssemblyTrademark(&quot;&quot;)] [assembly: AssemblyCopyright(&quot;Copyright (c) Arad Technologies Ltd. 2007&quot;)] [assembly: AssemblyTitle(&quot;d3g_tech_managed&quot;)] [assembly: AssemblyCompany(&quot;Arad Technologies Ltd.&quot;)] [assembly: AssemblyConfiguration(&quot;&quot;)] [assembly: ComVisible(false)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, UnmanagedCode = true)] </code></pre> <p>And clicking on the item below that (<code>d3g_tech_managed.dll</code>) shows:</p> <pre><code>// C:\Program Files (x86)\Arad Technologies\3GTechnicianNET\d3g_tech_managed.dll // d3g_tech_managed.dll // Global type: &lt;Module&gt; // Native Entry point: 0x000098AD // Architecture: x86 // This assembly contains unmanaged code. // Runtime: .NET Framework 4 // Timestamp: 5980427D (2017-08-01 04:57:33) using System; </code></pre> <p>I can't seem to find a solution for the above errors that would work when I don't have the source code to recompile the DLL.</p> <p>Any ideas?</p> <p>Thanks!</p> <p><em>RE: the <code>This assembly contains unmanaged code</code> line; did they name a DLL &quot;...managed...&quot; even though it isn't?</em></p> <p><em>The software that I'm writing is for internal use only, and will not be used by or distributed to anyone else (so there shouldn't be any issue with unlicensed distribution of copyrighted code).</em></p> <p>Meter Brochure: www mastermeter com/wp-content/uploads/Interpreter-II-Register_v0710.20F.pdf</p> <p>Reader Brochure: www mastermeter com/wp-content/uploads/Dialog_3G_DMMR_Transceiver_v0514.20.pdf</p>
Use 3rd-party DLL in my own application
|dll|.net|c#|error|
<p>This seems to be <a href="https://modbus.org/docs/PI_MBUS_300.pdf#page=120" rel="nofollow noreferrer">CRC-16/MODBUS</a>. Parameter specification can be found on this <a href="https://reveng.sourceforge.io/crc-catalogue/16.htm" rel="nofollow noreferrer">nice list of CRC16 specifications</a>:</p> <blockquote> <p>width=16 poly=0x8005 init=0xffff refin=true refout=true xorout=0x0000 check=0x4b37 residue=0x0000 name=&quot;CRC-16/MODBUS&quot;</p> </blockquote>
31890
2023-05-21T12:01:39.250
<p>The Linux source code has a routine for calculating CRC-16s. It's described as 'standard CRC-16', but doesn't have a formal name. It seems to be using a polynomial of 8005 but is otherwise undescribed.</p> <p><a href="https://github.com/torvalds/linux/blob/master/lib/crc16.c" rel="nofollow noreferrer">https://github.com/torvalds/linux/blob/master/lib/crc16.c</a></p> <pre><code>/** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */ u16 const crc16_table[256] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, ...etc... u16 crc16_byte(u16 crc, const u8 data) { return (crc &gt;&gt; 8) ^ crc16_table[(crc ^ data) &amp; 0xff]; } u16 crc16(u16 crc, u8 const *buffer, size_t len) { while (len--) crc = crc16_byte(crc, *buffer++); return crc; } </code></pre> <p>I'm having trouble duplicating this with reveng, which doesn't have a setting for 'standard', and I can't tell whether I'm giving it the wrong data or whether I'm using the wrong CRC settings. Does anyone know precisely which CRC-16 variant this is?</p>
What is 'standard' CRC-16?
|crc|
<p>It's a far/long jump, which sets loads the code segment descriptor using the selector specified.</p> <p>A <code>jmp</code> to a code segment selector which is the same as the existing <code>CS</code> value reloads the descriptor.</p> <p>See the Intel <a href="https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html" rel="nofollow noreferrer">Software Developer's Manual</a> Section 7.3.15.2 &quot;Far Control Transfer Instructions&quot; and the description of the JMP instruction:</p> <blockquote> <p>In protected mode, the JMP instruction also allows jumps to a call gate, a task gate, and a task-state segment.</p> </blockquote> <blockquote> <p>The JMP and CALL instructions (see Section 7.3.8, “Control Transfer Instructions”) both accept a far pointer as a destination to transfer program control to a segment other than the segment currently being pointed to by the CS register.</p> </blockquote> <blockquote> <p>Far Jumps in Protected Mode. When the processor is operating in protected mode, the JMP instruction can be used to perform the following three types of far jumps:</p> <p>• A far jump to a conforming or non-conforming code segment.</p> <p>• A far jump through a call gate.</p> <p>• A task switch.</p> </blockquote>
31911
2023-05-27T14:32:09.290
<p>Consider x86 16 bit mode instruction:</p> <pre><code>$ echo 66 EA 66 55 44 33 22 11 | xxd -p -r | ndisasm -b16 - 00000000 66EA665544332211 jmp dword 0x1122:0x33445566 </code></pre> <p>I thought 16 bit code jumps work by combining two 16 bit parts, while 32 bit code just uses 32 bit offset without segment part. What's the meaning of having both segment offset and 32 bit offset?</p>
What is the meaning of 32 bit offset in x86 16 bit jump
|x86|
<h2>How-to</h2> <p>To define a valuable structure you need to find its length and memory layout first. If you're researching a C++ binary, this is easiest done by finding the constructor(s) of the structure or its parent and then following all usage of the data across the binary.</p> <h2>Static analysis</h2> <p>To define a new structure type, open <code>Local Types</code> or <code>Structures</code> view and press <code>Insert</code> to add the structure definition.</p> <p>You can also create them from pseudocode view by right-clicking the desired variable name and choosing <code>Create new struct type</code> or apply an existing type with <code>Convert to struct *</code>.</p> <p>This could be automated using <a href="https://www.hex-rays.com/products/ida/support/idapython_docs/ida_struct.html" rel="nofollow noreferrer">ida_struct</a> and/or <a href="https://www.hex-rays.com/products/ida/support/idapython_docs/ida_typeinf.html" rel="nofollow noreferrer">ida_typeinf</a> modules.</p> <h2>Debugging</h2> <p>I don't think IDA has any utilities to help you identify or create structures at runtime, but there exist 3rd party tools such as <a href="https://github.com/ajkhoury/ReClassEx" rel="nofollow noreferrer">ReClassEx</a> designed to help with raw memory dump structuring if you need it.</p>
31912
2023-05-27T20:34:12.007
<p>How to identify and define a struct in IDA pro Decompiling during reverse engineering? Please explain the easiest way to figure out the struct in IDA Pro decompilation! <strong>To make life easier are there any IDA Pro scripts to automate this task?</strong></p>
How to reverse Engineer a Struct in IDA Pro?
|disassembly|binary-analysis|malware|dynamic-analysis|
<p><a href="http://www.rohitab.com/apimonitor" rel="nofollow noreferrer">Api Monitor</a> is a great tool to hook api's, watch parameters and return values and optionally modify them before/after call.</p> <blockquote> <p>API Monitor is a free software that lets you monitor and control API calls made by applications and services. Its a powerful tool for seeing how applications and services work or for tracking down problems that you have in your own applications.</p> </blockquote> <p><a href="https://i.stack.imgur.com/Ms6Rq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ms6Rq.png" alt="Main View" /></a></p> <p><a href="https://i.stack.imgur.com/5RXX1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5RXX1.png" alt="Summary View with Syntax Highlighting" /></a></p>
31913
2023-05-28T00:23:49.883
<p>atm I'm using ida and x32dbg, when I find a function that interests me, I set a breakpoint on x32dbg, however, I'm not good enough at assembly to know everything from a function just from looking at the registers and whatnot. When I think a function may be something, I hook it, but it's an annoying process.</p> <p>So is there an easier way to debug dll functions at runtime?</p>
other than x32dbg, is there a more friendly way to check functions, their args and their return values on runtime?
|ida|assembly|dynamic-analysis|debug|
<p>For such fixup both selector and offset parts are patched so that they point to the actual location of the fixup's target.</p>
31917
2023-05-28T23:00:10.837
<p>In LX format description in section 3.13 Fixup Record Table, when describing <code>SRC = DB Source type field</code> there is such an option:</p> <p><code>06h = 16:32 Pointer fixup (48-bits).</code></p> <p><strong>1. How many bytes does this fixup change and how?</strong> I found a particular example of such fixup, it points to 2nd byte of a certain jump instruction:</p> <p><code>66EA665544332211 jmp dword 0x1122:0x33445566</code></p> <p>I assume it at least changes 4-byte offset (33445566), but does it also change 16 bit selector (1122)?</p> <p><strong>2. Where can I find more in-depth description of different fixup kinds?</strong> IBM doc seems to assume it to be common knowledge.</p>
What is patched by LX 16:32 fixup record
|x86|
<p>You could utilize debug symbols to search for the disassembled code of interest. Here's a TL;DR from <code>dumpbin</code>'s docs:</p> <ol> <li><code>dumpbin</code> <a href="https://learn.microsoft.com/en-us/cpp/build/reference/disasm?view=msvc-170#remarks" rel="nofollow noreferrer">always searches for embedded symbols</a> within the file:</li> </ol> <blockquote> <p>The /DISASM option displays disassembly of code sections in the file. It uses debug symbols if they are present in the file.</p> </blockquote> <ol start="2"> <li><code>dumpbin</code> tries to <a href="https://learn.microsoft.com/en-us/cpp/build/reference/nopdb?view=msvc-170#remarks" rel="nofollow noreferrer">load debug symbol information</a> for the disassembled binary (works with PDB, no information on support for DWARF and other formats):</li> </ol> <blockquote> <p>By default, DUMPBIN attempts to load PDB files for its target executables. DUMPBIN uses this information to match addresses to symbol names.</p> </blockquote> <p>If your <code>source.exe</code> was compiled with MSVC, simply put <code>.pdb</code> file in the same directory and use:</p> <pre><code>dumpbin /DISASM source.exe </code></pre> <p>The output will have symbol names applied - example disassembly fragment:</p> <pre><code>??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z: 0000000140011870: 48 89 54 24 10 mov qword ptr [rsp+10h],rdx 0000000140011875: 48 89 4C 24 08 mov qword ptr [rsp+8],rcx 000000014001187A: 55 push rbp 000000014001187B: 57 push rdi 000000014001187C: 48 81 EC 28 02 00 sub rsp,228h 00 0000000140011883: 48 8D 6C 24 20 lea rbp,[rsp+20h] 0000000140011888: 48 8D 7C 24 20 lea rdi,[rsp+20h] 000000014001188D: B9 52 00 00 00 mov ecx,52h 0000000140011892: B8 CC CC CC CC mov eax,0CCCCCCCCh 0000000140011897: F3 AB rep stos dword ptr [rdi] 0000000140011899: 48 8B 8C 24 48 02 mov rcx,qword ptr [rsp+248h] 00 00 00000001400118A1: 48 8B 05 58 B7 00 mov rax,qword ptr [__security_cookie] 00 00000001400118A8: 48 33 C5 xor rax,rbp 00000001400118AB: 48 89 85 F8 01 00 mov qword ptr [rbp+1F8h],rax 00 00000001400118B2: 48 8D 0D AA 17 01 lea rcx,[140023063h] 00 00000001400118B9: E8 11 FB FF FF call @ILT+970(__CheckForDebuggerJustMyCode) 00000001400118BE: C7 45 04 00 00 00 mov dword ptr [rbp+4],0 00 00000001400118C5: 48 8B 8D 28 02 00 mov rcx,qword ptr [rbp+228h] 00 00000001400118CC: E8 79 F8 FF FF call @ILT+325(?length@?$_Narrow_char_traits@DH@std@@SA_KQEBD@Z) ... </code></pre> <p>If you find decorated names confusing, you can use <a href="https://learn.microsoft.com/en-us/cpp/build/reference/decorated-names?view=msvc-170#Undecorated" rel="nofollow noreferrer"><code>undname</code></a> to decipher decorated/mangled symbol names into their signatures:</p> <pre><code>undname &lt;decorated name&gt; </code></pre>
31938
2023-06-04T17:45:16.967
<p>Is there any way I can use <code>dumpbin</code> like <code>objdump</code>, where I can just look at the functions machine instructions that I implemented in my <code>Source.c</code> file, which I compiled to <code>source.exe</code>? If I use <code>dumpbin \DISASM</code> with the section <code>.text</code> it shows me a lot of machine instructions, but it's impossible to find the machine instructions I am looking for.</p>
Dumpbin show function names
|disassembly|
<p>You can do this with IDC or IDAPython without compiling a C++ plugin, but there are a number of problems with your code snippet. For example, <code>value</code> is not an integer, and is computed the same way for every loop iteration. I wouldn't recommend just copying and pasting code from ChatGPT; you should try actually writing it yourself, according to the documentation for IDC or IDAPython.</p> <p>Here's a one-liner to do it in IDAPython:</p> <p><code>for idx,byte in enumerate([0xFF,0xFE,0xFD,0xFC,0xFB]): ida_bytes.put_byte(0x180004F76+idx,byte)</code></p> <p>Replace <code>0x180004F76</code> with the address you want to write to, and <code>[0xFF,0xFE,0xFD,0xFC,0xFB]</code> with the bytes you want to write there.</p>
31953
2023-06-09T01:50:31.997
<p>&quot;I am trying to create a simple IDC script for IDA 7.7, which takes a known memory address (in the format 0x00000000), a string of replacement bytes (either in the format ffffffff or ff ff ff ff, it doesn't matter; whatever is easiest), and a size of bytes to replace (which should match the replacement byte buffer).</p> <p>I was under the impression that it would be a simple for loop that starts at the given memory address and replaces each byte individually until it reaches the size of the 'buffer size' variable using the patchbyte function.</p> <p>Turns out, that didn't work. My next attempt was to get ChatGPT to do it because, why not? That was a little bit more fruitful, but instead of replacing the bytes I asked it to change to, it replaced the bytes with 00, and then the script wouldn't work after the first try.</p> <p>This is what I have from ChatGPT:</p> <pre><code>`static main() { auto ea = 0x00400000; auto buffer = &quot;ffffffff&quot;; auto buffer_size = 4; // Check if the specified memory address is valid if (ea == BADADDR) { Message(&quot;Invalid memory address!&quot;); return; } // Check if the buffer size is valid if (buffer_size &lt;= 0) { Message(&quot;Invalid buffer size!&quot;); return; } // Check if the buffer is valid hexadecimal format auto len = strlen(buffer); if (len % 2 != 0) { Message(&quot;Invalid buffer format!&quot;); return; } auto i = 0; for (i = 0; i &lt; buffer_size; i++) { auto value = buffer; PatchByte(ea + i, value); } Message(&quot;Successfully patched the memory address!&quot;); }` </code></pre> <p>The goal is to replace a large encryption key with one of my own, just for testing, which is why I want to patch the memory instead of the database or binary itself. But I also feel that a script or function like this may become useful for others aswell.</p> <p>Is this something I can only do by creating a plugin? (Please don't say that, I have never been able to successfully compile an IDA plugin..)</p> <p>Any help would be appreciated. Thanks!&quot;</p> <p>p.s. i am aware the buffersize check only checks for a number over 0</p>
Need Help Figuring out Multi-byte (in-memory) byte replacement using ida script (idc)
|ida|patching|script|idc|
<p>In Windows, just edit the file:</p> <p><code>\GHIDRA_DIR\support\launch.properties</code></p> <p>and add the line:</p> <p><code>VMARGS_WINDOWS=-Dsun.java2d.uiScale=2</code></p> <p>A similar command can be used for other systems.</p>
31961
2023-06-11T01:53:08.347
<p>For the record, this is a question I often see:</p> <p>Especially when using a high-resolution display, fonts and other UI elements can appear extremely small. How can they be enlarged?</p>
Increase font size in Ghidra
|ghidra|
<p>AFAIK you're not supposed to handle it and I doubt you reasonably could. The sources you cite <a href="https://en.wikipedia.org/wiki/Rest_in_peace" rel="nofollow noreferrer">are right about what RIP means in this context</a>.</p> <p>This event occurs in response to a <code>DBG_RIPEXCEPTION</code> (== <code>((NTSTATUS)0x40010007L)</code>; see <code>ntstatus.h</code>). The message for this status code is &quot;Debugger received RIP exception.&quot; (not helpful ;)) and a corresponding Win32 error code exists by the name <code>ERROR_DBG_RIPEXCEPTION</code> (== <code>695L</code>; see <code>winerror.h</code>, same message text).</p> <p>Arguably you could synthesize this event by calling <a href="https://learn.microsoft.com/windows/win32/api/errhandlingapi/nf-errhandlingapi-raiseexception" rel="nofollow noreferrer"><code>RaiseException</code></a> with the <code>DBG_RIPEXCEPTION</code> code. You could then play with passing different arguments and filling the data and seeing what carries over into the debugger.</p> <p>I, too, am not aware of anything that raises that specific code, but be it cosmic rays or anything else, it seems to signal the sudden and unexpected &quot;death&quot; of a process <strong>out of the ordinary</strong>.</p> <hr /> <blockquote> <p>Assuming a RIP_EVENT does occur when the process dies somehow, does the RIP_EVENT replace the EXIT_PROCESS_DEBUG_EVENT, or can I expect to receive both events?</p> </blockquote> <p>From what I gather, you can expect both. They signify different circumstances, however. <code>RIP_EVENT</code> seems to be purely about the <em>sudden and unexpected &quot;death&quot;</em> of a process, not other ways of the process exiting (and the OS getting to clean up after it). One guess would be that this could get synthesized on the client in remote debugging scenarios.</p> <blockquote> <p>How do popular debuggers like Visual Studio or WinDbg handle the RIP_EVENT?</p> </blockquote> <p>I think they don't. That event is supposed to be the exception to the exception, so to speak.</p> <blockquote> <p>What is the correct way to handle one? Do I even need to do anything if I receive one?</p> </blockquote> <p>As noted above, I think you're not supposed to care about it. At most log it (to notify the user).</p> <blockquote> <p>Does the &quot;RIP&quot; in RIP_EVENT refer to the instruction pointer in x64? Would that imply it is exclusive to x64 and never occurs for x86? Or perhaps it is for some other CPU architecture I don't care about?</p> </blockquote> <p>Nope it's not about the instruction pointer in x64. It predates x64.</p> <blockquote> <p>Does it occur when connection is lost while debugging a remote process? This is another scenario I thought might cause it, but it'd be difficult for me to test.</p> </blockquote> <p>Seems like we came to the same conclusion with this one.</p> <p><strong>However,</strong> I'd like to offer another option: <code>RIP_EVENT</code> could be a remnant and no longer applicable to modern Windows. NT has a long history and it could well be something that was dropped along the way ... for all we know it could originate from something that relates to OS/2 and Microsoft's/IBM's collaboration <em>before</em> they parted ways. This is just a guess, too. But it would explain the absence of information. It could also be something that was introduced from the Win32s lineage (Windows 9x/Me) and subsequently dropped. Remember that NT 4.0 took up the desktop look&amp;feel from Windows 95 at the time.</p> <p>Unless you're working for Microsoft and have access to internal documentation, source code history and some of the original developers, I don't think you'll get much more info than what you found already.</p>
31965
2023-06-12T06:57:01.757
<p>The documentation for the Windows Debugger API mentions a debug event called <a href="https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-rip_info" rel="nofollow noreferrer">RIP_EVENT.</a> It offers little explanation of what a RIP_EVENT is, only stating that the structure &quot;contains the error that caused the RIP debug event.&quot; In my own debugger, I have never encountered this event, so I am uncertain how to handle it.</p> <p>There are precious little resources online explaining what the event is. <a href="https://www.lyyyuna.com/2017/05/01/write-a-windows-debugger-02-debug-event/" rel="nofollow noreferrer">This blog</a> is as confused as I am:</p> <blockquote> <p>I find very few documents about this event, only mentioned with words like system error or internal error. So I decide to print a error message and skip it. As my project is not fully tested, I have never encountered such a situation.</p> </blockquote> <p>The <a href="https://www.codeproject.com/Articles/5275/Writing-a-Debugger-Part-2-The-Debug-Loop" rel="nofollow noreferrer">Writing A Debugger CodeProject</a> claims the event &quot;occurs if your process being debugged dies unexpectedly.&quot; Similarly, this <a href="https://youtu.be/VZtM-gQxmns" rel="nofollow noreferrer">OALabs video</a> states that the RIP_EVENT occurs if the process doesn't exit gracefully.</p> <p>This seems to be the general consensus amongst the few resources I can find. The problem is, of all the ways I can conceive of to kill a process in unexpected fashion, none of them trigger a RIP_EVENT. Last Chance Exceptions trigger a DEBUG_EVENT, eventually followed by an EXIT_PROCESS_DEBUG_EVENT, instead. If anything, I would expect that terminating the process in Task Manager wouldn't be considered a &quot;graceful exit,&quot; but it too triggers an EXIT_PROCESS_DEBUG_EVENT, not a RIP_EVENT. This makes me wonder if the event is even associated with process termination at all, or if that's just a confident assumption based on the name &quot;RIP.&quot;</p> <p>I'm left to speculate why I've never seen this event before and in what scenario it could potentially arise:</p> <ul> <li>Assuming a RIP_EVENT does occur when the process dies somehow, does the RIP_EVENT replace the EXIT_PROCESS_DEBUG_EVENT, or can I expect to receive both events?</li> <li>How do popular debuggers like Visual Studio or WinDbg handle the RIP_EVENT? What is the correct way to handle one? Do I even need to do anything if I receive one?</li> <li>Does the &quot;RIP&quot; in RIP_EVENT refer to the instruction pointer in x64? Would that imply it is exclusive to x64 and never occurs for x86? Or perhaps it is for some other CPU architecture I don't care about?</li> <li>Does it occur when connection is lost while debugging a remote process? This is another scenario I thought might cause it, but it'd be difficult for me to test.</li> </ul> <p><strong>Update:</strong> I began digging even further into this, because I wasn't satisfied with the guesses so far, and found something interesting. There is an export of USER32 called <a href="http://winapi.freetechsecrets.com/win32/WIN32SetDebugErrorLevel.htm" rel="nofollow noreferrer">SetDebugErrorLevel.</a> There is no official documentation for it that I can find, but if this source is to be believed, it would make a lot of sense.</p> <blockquote> <p>The SetDebugErrorLevel function sets the minimum error level at which Windows will generate debugging events and pass them to a debugger.</p> <p><strong>Parameters</strong></p> <p><em>dwLevel</em> Specifies the minimum error level for debugging events. If an error is equal to or above this level, Windows generates a debugging event. This parameter must be one of the following values:</p> <p><strong>Value:</strong> 0</p> <p><strong>Meaning:</strong> Does not report any errors. This value is the default error level.</p> <p><strong>Value:</strong> SLE_ERROR</p> <p><strong>Meaning:</strong> Reports only ERROR level debugging events.</p> <p><strong>Value:</strong> SLE_MINORERROR</p> <p><strong>Meaning:</strong> Reports only MINORERROR level and ERROR level debugging events.</p> <p><strong>Value:</strong> SLE_WARNING</p> <p><strong>Meaning:</strong> Reports WARNING level, MINORERROR level, and ERROR level debugging events.</p> </blockquote> <p>Particularly because the RIP_INFO structure contains a dwType field with these same values, I think it is likely that RIP_EVENT was intended to be thrown as a part of this mechanism. The thing is, SetDebugErrorLevel - although it exists in USER32 - does nothing. Looking at the disassembly reveals it simply returns immediately. Furthermore, these types were clearly intended to be specified in calls to <a href="https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setlasterrorex" rel="nofollow noreferrer">SetLastErrorEx,</a> though it too goes unused, as the documentation explains:</p> <blockquote> <p>Currently, this function is identical to the SetLastError function. The second parameter is ignored.</p> </blockquote> <p>...with the second, unused parameter being dwType, which was probably meant to take in the SLE_ERROR, SLE_MINORERROR, and SLE_WARNING types (with &quot;SLE&quot; standing for SetLastError.) From this, I infer that RIP_EVENT was probably intended to be thrown whenever SetLastErrorEx was used to set a new error level, but this feature has been abandoned. This is my best theory, but it is still only a guess, as the documentation never goes so far as to explicitly state this.</p>
What triggers RIP_EVENT?
|windows|debugging|x86|
<p>This is a bug upstream you can see it filed as <a href="https://github.com/felberj/gotools/issues/9" rel="nofollow noreferrer">issue #9 on Github</a>. According to one of the posters, there is a release that works on this fork,</p> <p><a href="https://github.com/sophieboyle/gotools/releases" rel="nofollow noreferrer">https://github.com/sophieboyle/gotools/releases</a></p>
31986
2023-06-20T17:46:09.020
<p>I'm getting the following error when I try to install the following extension <a href="https://github.com/felberj/gotools" rel="nofollow noreferrer">https://github.com/felberj/gotools</a></p> <blockquote> <p>Installation Error</p> <p>Extension version for [gotools-master.zip] is incompatible with Ghidra.</p> </blockquote> <pre><code>Build Date: 2022-Jan-25 1526 EST Ghidra Version: 10.1..2 Java Home: C:\Program Files\Microsoft\jdk-17.9.7-7-hotspot JVM Version: Microsoft 17.9.7 OS: Windows 11 10.0 amd64 Workstation: 192.168.1.128 </code></pre> <p><a href="https://i.stack.imgur.com/v1HOp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v1HOp.png" alt="screenshot of error" /></a></p> <p>I followed the instructions in the <a href="https://github.com/felberj/gotools/blob/master/README.md" rel="nofollow noreferrer">GitHub readme</a> yet the extension doesn't appear in the extensions tab, when I try to manually add it I get the message above that Ghidra doesn't support this extension. I'm using the version that is described in readme which is Ghidra 10.1.2. Can anyone assess the problem I'm encountering?</p>
Installation problem with gotools extension for Ghidra: Extension version for [gotools-master.zip] is incompatible with Ghidra
|ghidra|go|
<p>I followed this guide on PoomSmart's GitHub page (<a href="https://github.com/PoomSmart/IDAObjcTypes" rel="nofollow noreferrer">https://github.com/PoomSmart/IDAObjcTypes</a>) and it seems to have worked. PoomSmart is quite respected in the jailbreak community and I have used their tweaks for long with no issues.</p> <p>There is one additional step not explicitly mentioned in the guide, which is to select the program architecture. Since I didn't specifically know what to pick, I tried a few of the ARM processor options and it looks good.</p>
31991
2023-06-22T07:49:28.640
<p>I'm new to using Ghidra, so apologies if this has been asked before, but I couldn't find an answer.</p> <p>I'm looking at an iOS app, and I can see a function signature that looks like this:</p> <pre><code>ID Class::DoTheThing(ID param_1, SEL param_2, ID param_3) </code></pre> <p>I know that <code>param_3</code> is an <code>NSString</code>, but Ghidra doesn't seem to know what an <code>NSString</code> is.</p> <p>Is there a datatype library that I can add to Ghidra to give it support for this, or do I need to manually tell it what an <code>NSString</code> looks like?</p>
Ghidra with Swift/Objective-C datatypes (NSString)
|ghidra|
<p>So, as I understand it, it is impossible to do this at the level of an assembly language as such.</p> <p>In order to delete dead code in a normal sense, it is necessary to carry out the stages of code analysis, or rather data flow graph, it is impossible to do this in one run of the assembler code with the unicron emulator, i.e. I need to form a conditional data map (This also applies to opaque predicates) <a href="https://www.sciencedirect.com/topics/computer-science/data-flow-graph" rel="nofollow noreferrer">https://www.sciencedirect.com/topics/computer-science/data-flow-graph</a></p> <p><a href="http://bears.ece.ucsb.edu/research-info/DP/dfg.html" rel="nofollow noreferrer">http://bears.ece.ucsb.edu/research-info/DP/dfg.html</a></p> <p>Let's say I add the second phase of the run, i.e. on the first I will form a data flow graph, and on the second I will already apply this data flow graph to the code and start optimizing it all. Then I stumble upon another problem, in order to understand at the assembler level whether the command is correct even with a dfg(data flow graph), we need to delete one variable or number and compare it with the original tree and check that our calculations are not broken in any way. If I take a real case of a virus that is very well obfuscated, then you and I will sit in a puddle, because if there are more than 1000 instructions in one function, then our optimization will be extremely long.</p> <p>But many readers may object and say that the same can be done with a solver, but I will answer you that it takes about 534MC to recalculate our example with a certain solver constraint</p> <pre><code> s.add(!(*orig.rax == *opt.rax &amp;&amp; *orig.rbx == *opt.rbx &amp;&amp; *orig.rcx == *opt.rcx &amp;&amp; *orig.rdx == *opt.rdx &amp;&amp; *orig.rbp == *opt.rbp &amp;&amp; *orig.rsp == *opt.rsp &amp;&amp; *orig.rsi == *opt.rsi &amp;&amp; *orig.rdi == *opt.rdi &amp;&amp; *orig.r8 == *opt.r8 &amp;&amp; *orig.r9 == *opt.r9 &amp;&amp; *orig.r10 == *opt.r10 &amp;&amp; *orig.r11 == *opt.r11 &amp;&amp; *orig.r12 == *opt.r12 &amp;&amp; *orig.r13 == *opt.r13 &amp;&amp; *orig.r14 == *opt.r14 &amp;&amp; *orig.r15 == *opt.r15 &amp;&amp; *orig.xmm0 == *opt.xmm0 &amp;&amp; *orig.xmm1 == *opt.xmm1 &amp;&amp; *orig.xmm2 == *opt.xmm2 &amp;&amp; *orig.xmm3 == *opt.xmm3 &amp;&amp; *orig.xmm4 == *opt.xmm4 &amp;&amp; *orig.xmm5 == *opt.xmm5 &amp;&amp; *orig.xmm6 == *opt.xmm6 &amp;&amp; *orig.xmm7 == *opt.xmm7 &amp;&amp; *orig.xmm8 == *opt.xmm8 &amp;&amp; *orig.xmm9 == *opt.xmm9 &amp;&amp; *orig.xmm10 == *opt.xmm10 &amp;&amp; *orig.xmm11 == *opt.xmm11 &amp;&amp; *orig.xmm12 == *opt.xmm12 &amp;&amp; *orig.xmm13 == *opt.xmm13 &amp;&amp; *orig.xmm14 == *opt.xmm14 &amp;&amp; *orig.xmm15 == *opt.xmm15 &amp;&amp; *orig.zf == *opt.zf &amp;&amp; *orig.of == *opt.of &amp;&amp; *orig.cf == *opt.cf &amp;&amp; *orig.pf == *opt.pf &amp;&amp; *orig.sf == *opt.sf &amp;&amp; *orig.af == *opt.af &amp;&amp; *orig.df == *opt.df)); </code></pre> <p>The constraint above will take you about 534MC for one repeat, and now imagine that we have ten such repetitions, it will just be incomprehensible in terms of execution time. With opaque predicates, things are a little better, but everything is still performed for an extremely long time... Along the way, we can only optimize only those instructions that obviously fall out of our dfg at all, but there are few such cases and in real cases this will be extremely rare for us.</p> <p>Of all the cases, only one will help us: We need to collect the entire trace of the program to the place we need, despite the garbage data and dead code, etc. obfuscation. Then we will need to lift the collected instructions to llvm-ir or any other ir and after that we can proceed to normal optimization.</p> <p>In its own way, you need to develop a source to source compiler for deobfuscation(asm2asm with different optimizations): <a href="https://github.com/rose-compiler/rose" rel="nofollow noreferrer">https://github.com/rose-compiler/rose</a> <a href="https://en.wikipedia.org/wiki/Source-to-source_compiler" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Source-to-source_compiler</a></p>
31993
2023-06-22T14:05:42.080
<hr /> <p>I have the following problem on my agenda: There is an obfuscated .exe (this is a virus that I am investigating) in addition to having an MBA, etc. bullshit, he has Opaque predicates and dead code, I know there are solvers to solve this gap(z3), but they have problems with execution speed, when I delete one instruction in a graph and compare it with the original graph, it takes too much time, I also made the solver see not just one graph, but the entire function, because of this, I have big problems with the speed of execution, since there are more than 1000 instructions in the function - I delete one at a time, and it's simply unbearable to wait so long, the solver also has problems with registers, since there is no inheritance of data from variables and I have to update the lower part of the registers every time.</p> <p>Are there any elegant ways to solve opaque predicates and dead code?(my implementations of this on solver are: <a href="https://github.com/Nitr0-G/DynamicRetDec" rel="nofollow noreferrer">https://github.com/Nitr0-G/DynamicRetDec</a> and <a href="https://github.com/Nitr0-G/Z3-Dead-Code-Elemination" rel="nofollow noreferrer">https://github.com/Nitr0-G/Z3-Dead-Code-Elemination</a>). Perhaps opaque predicates and dead code elimination can be solved somehow with the help of data tracking? Are there any implementations that I could look at or maybe concepts?</p>
How can i remove dead code and opaque predicates?
|assembly|c++|deobfuscation|dynamic-analysis|
<p>This failure happens as a result of A) the intentional obfuscation, and B) what the compiler community calls a &quot;phase-ordering&quot; problem.</p> <p>When Hex-Rays decompiles a function, it begins by creating the control flow graph pictured in your second screenshot. Next, it performs a &quot;reachability analysis&quot;, a depth-first search starting from the entry block, to determine which blocks may ever be executed. Then, it removes blocks that it determines can never be executed. In particular, the reachability analysis only follows control flow references, not data flow references. If some basic block is only reachable by a data flow reference -- as in <code>loc_100025C1</code> in your example -- its code will be removed from the decompilation by this phase.</p> <p>Later on in the decompilation, Hex-Rays propagates the <code>mov eax, offset loc_100025C1</code> into the subsequent <code>jmp eax</code> instruction to determine that the <code>jmp</code> transfers control to <code>loc_100025C1</code>, and then sees whether that address is part of the code it is decompiling. Since that address was removed from the decompilation as just discussed, this fails. As a result, Hex-Rays emits the <code>JUMPOUT(0x100025C1)</code> that you see in the decompilation. If Hex-Rays had known earlier that the <code>jmp</code> would resolve to <code>loc_100025C1</code>, then it would have kept that code, so you would not see a <code>JUMPOUT</code> in the decompilation -- but it only discovers that the <code>jmp</code> resolves there after it's already removed the target, at which point it's too late.</p> <p>There is something you can do about this, although it is a bit of a weak solution that will require manual work and probably several iterations of refinement on your end. Namely, if you explicitly add a control flow reference from the <code>jmp eax</code> instruction to <code>loc_100025C1</code>, then Hex-Rays won't remove that block, and it will be able to decompile more of the code. You can add such a control flow reference as follows:</p> <p><code>ida_xref.add_cref(0x100025BE,100025C1,ida_xref.XREF_USER | ida_xref.fl_JN)</code></p> <p>Note, however, that you are going to have to do this for every occurrence of this obfuscation construct, which you might only discover after adding the first cross reference and then seeing new <code>JUMPOUT</code> statements. You'll probably also run into issues where IDA may not create function chunks for new parts of the code that you add cross references to, which will be annoying and painful.</p> <p>If I were you, I'd do this instead:</p> <ol> <li>Load the binary without performing auto-analysis.</li> <li>Search for the patterns of interest, which you appear to already be doing in the &quot;Search&quot; window in your third tab.</li> <li>Replace them with direct, unconditional jumps to the destinations. I.e. replace the <code>mov eax, offset loc_100025C1</code> / <code>jmp eax</code> with simply <code>jmp loc_100025C1</code>. You'll have more than enough space to do this; if the target is within <code>0x7F</code> bytes of the end of the <code>mov eax</code> instruction, you can simply replace it with a one-byte <code>EB XX</code> <code>jmp</code> instruction. If it's not within that many bytes, you can use the <code>E9 AA BB CC DD</code> form of the <code>jmp</code> instruction, where the distance from the end of that instruction to the destination is <code>0xDDCCBBAA</code>.</li> <li>Now let IDA perform auto-analysis.</li> </ol> <p>As long as your script can find the relevant entries, this should prevent you from having to create the cross-references manually (in an iterative fashion) like I described above; you'll be explicitly creating all of the cross-references at once. And by delaying auto-analysis until after your script runs, you'll prevent issues with IDA not identifying the function chunks.</p> <p>In response to your edit including a link to the crackme, here's an IDAPython script you can run to remove the obfuscation. When loading the binary, uncheck the &quot;Enabled&quot; checkbox under the &quot;Analysis&quot; heading. Then, run the script. Finally, go to <code>Options-&gt;General-&gt;Analysis</code> and check the &quot;Enabled&quot; checkbox. (Note that there's a bit more logic to the script than necessary; only the &quot;patched jmp to destination&quot; block ever executes.)</p> <pre><code>import idaapi import ida_bytes import ida_nalt import ida_bytes import ida_ida PATTERN_STR = &quot;B8 ? ? ? ? 3D ? ? ? ? 74 07 B8 ? ? ? ? FF E0&quot; patterns = ida_bytes.compiled_binpat_vec_t() encoding = ida_nalt.get_default_encoding_idx(ida_nalt.BPU_1B) imagebase = ida_nalt.get_imagebase() ida_bytes.parse_binpat_str(patterns,imagebase,PATTERN_STR,16,encoding) ea = imagebase while True: ea = ida_bytes.bin_search(ea,ida_ida.inf_get_max_ea(),patterns,ida_bytes.BIN_SEARCH_FORWARD | ida_bytes.BIN_SEARCH_CASE) if ea == idaapi.BADADDR: break const1 = ida_bytes.get_dword(ea+1) const2 = ida_bytes.get_dword(ea+6) offs = ida_bytes.get_dword(ea+13) if const1 != const2: if offs == ea+0x14: ida_bytes.put_byte(ea,0xEB) ida_bytes.put_byte(ea+1,0x12) for i in range(0x12): ida_bytes.put_byte(ea+2+i,0x90) print(&quot;%#x: patched jmp to destination&quot; % ea) else: print(&quot;%#x: jmp address incorrect?&quot; % ea) else: ida_bytes.put_byte(ea,0xEB) ida_bytes.put_byte(ea+1,0x11) for i in range(0x11): ida_bytes.put_byte(ea+2+i,0x90) print(&quot;%#x: patched jmp to byte after jmp eax&quot; % ea) </code></pre>
32029
2023-07-04T03:59:43.233
<p>I'm trying to reverse a crackme that is using <code>jz x; mov eax, x+1; jmp eax</code> pattern to confuse IDA. I have made a script to find all the patterns and disassemble from x+1 instead of x, but I'm running into this error. <a href="https://i.stack.imgur.com/q2pA9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q2pA9.png" alt="enter image description here" /></a></p> <p><a href="https://i.stack.imgur.com/eJmAe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eJmAe.png" alt="enter image description here" /></a></p> <p>The crackme is <a href="https://crackmes.dreamhosters.com/users/fatmike/fatmikes_crackme_3/" rel="nofollow noreferrer">https://crackmes.dreamhosters.com/users/fatmike/fatmikes_crackme_3/</a></p>
IDA Pro failed decompilation with "JUMPOUT"
|ida|
<p><a href="https://www.hex-rays.com/products/ida/support/idapython_docs/ida_dbg.html#ida_dbg.get_module_info" rel="nofollow noreferrer"><code>get_module_info</code></a> seems to be what you want, it returns <a href="https://www.hex-rays.com/products/ida/support/idapython_docs/ida_idd.html#ida_idd.modinfo_t" rel="nofollow noreferrer"><code>modinfo_t</code></a> structure with full module name.</p> <p>An untested sketch of example usage would be:</p> <pre class="lang-py prettyprint-override"><code>import idaapi, ida_idd, ida_dbg idaapi.step_into() idaapi.wait_for_next_event(2, -1) ea = ida_dbg.get_ip_val() modinfo = ida_idd.modinfo_t() ida_dbg.get_module_info(ea, modinfo) counter = GetRegValue('RDX') if counter == 666 and modinfo.name != 'ntdll.dll': break </code></pre>
32030
2023-07-04T13:21:02.510
<p>I have a script that catches say a value of 666 in the RDX register and pauses debugging. The problem is, that this value might be added to the register by other modules aside from the main application that I am debugging, for example by ntdll.dll, which is of course of no use to me.</p> <p>How do I get the name of the current module that debugger is in at any given moment so I can ignore if the RDX is changed at that module? Something like this:</p> <pre><code>idaapi.step_into() idaapi.wait_for_next_event(2, -1) counter=GetRegValue('RDX') if counter==666 and (GetCurrentModuleName()!='ntdll.dll'): break </code></pre>
IDAPython get current module name in a debugger
|idapython|
<p>There is another project available (I have no affiliation), which may also fit the bill: <a href="https://binsync.net/" rel="nofollow noreferrer">BinSync</a></p> <p>The GitHub organization <a href="https://github.com/binsync" rel="nofollow noreferrer">can be found here</a>.</p>
32035
2023-07-05T04:14:06.323
<p>I'm a <a href="https://git-scm.com/" rel="nofollow noreferrer">git</a> addict. Whenever I develop a C++, Python application, I need to version control it. For example, the csproj file managed by Visual Studio holds the compiling configurations for a C# project, and I put the file into git.</p> <p>Now, as a newbie in reverse engineering, I'm using IDA. I like IDA's abilities to rename functions and variables, add comments, etc. I find an IDA project has a database, but it's not plain text.</p> <p>How would I save my reverse engineering progress in git? How would I share my comments, notes, renamings to others so that they can pick up and continue studying the same executable?</p>
How to version control an IDA project?
|ida|
<p><code>idaapi.get_ea_name(ea, idaapi.GN_SHORT|idaapi.GN_DEMANGLED)</code> seems to return the filtered demangled name.</p>
32056
2023-07-14T15:18:15.617
<p>With idapython I would like to get demangled names with the <a href="https://hex-rays.com/blog/igors-tip-of-the-week-35-demangled-names/" rel="nofollow noreferrer">name simplification (bottom of page)</a> applied to them.</p> <p>For example, the following function:</p> <pre class="lang-shell prettyprint-override"><code>Python&gt; ida_name.demangle_name(idc.get_func_name(0x123456), 0) std::vector&lt;std::__cxx11::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;,std::allocator&lt;std::__cxx11::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;&gt;&gt;::vector(void)' </code></pre> <p>As you can see, the function name is very long with all the templates. IDA applies some rules from <code>goodname.cfg</code> to simplify this name. In its GUI the following is displayed:</p> <pre><code>std::vector&lt;std::string&gt;::vector(void) </code></pre> <p>Much better. Is there any way to achieve the same result in idapython? Other than copying and applying all the rules from <code>goodname.cfg</code> inside my script...</p>
IDA: Demangled name simplification in idapython
|ida|c++|idapython|idapro-sdk|